Projects
openEuler:Mainline
duktape
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 2
View file
_service:tar_scm:duktape.spec
Changed
@@ -1,6 +1,6 @@ Name: duktape -Version: 2.6.0 -Release: 2 +Version: 2.7.0 +Release: 1 Summary: Embeddable Javascript engine License: MIT Url: http://duktape.org/ @@ -33,9 +33,8 @@ < %{SOURCE1} > %{name}.pc.in %build -sed -e '/^INSTALL_PREFIX/s|^=*$|%{_prefix}|' \ +sed -e '/^INSTALL_PREFIX/s|^?=*$|%{_prefix}|' \ -e '/install\:/a\\tinstall -d $(DESTDIR)$(INSTALL_PREFIX)/%{_lib}\n\tinstall -d $(DESTDIR)$(INSTALL_PREFIX)/include' \ - -e 's/\(\$.INSTALL_PREFIX.\)/$(DESTDIR)\1/g' \ -e 's/\/lib\b/\/%{_lib}/g' \ < Makefile.sharedlibrary > Makefile %make_build @@ -65,6 +64,9 @@ %{_libdir}/pkgconfig/duktape.pc %changelog +* Thu Nov 3 2022 zhengxiaoxiao<zhengxiaoxiao2@huawei.com> - 2.7.0-1 +- update to 2.7.0 + * Thu Apr 28 2022 Hugel<gengqihu1@h-partners.com> - 2.6.0-2 - delete examples from devel
View file
_service
Changed
@@ -2,7 +2,7 @@ <service name="tar_scm"> <param name="scm">git</param> <param name="url">git@gitee.com:src-openeuler/duktape.git</param> - <param name="revision">d8cc4a4c374384c248e8e88db76959343e203d7c</param> + <param name="revision">master</param> <param name="exclude">*</param> <param name="extract">*</param> </service>
View file
_service:tar_scm:duktape-2.6.0.tar.xz/AUTHORS.rst -> _service:tar_scm:duktape-2.7.0.tar.xz/AUTHORS.rst
Changed
@@ -64,6 +64,12 @@ * Luis de Bethencourt (https://github.com/luisbg) * Ian Whyman (https://github.com/v00d00) * Rick Sayre (https://github.com/whorfin) +* Craig Leres (https://github.com/leres) +* Maurici Abad (https://github.com/mauriciabad) +* Nancy Li (https://github.com/NancyLi1013) +* William Parks (https://github.com/WilliamParks) +* Sam Hellawell (https://github.com/samhellawell) +* Vladislavs Sokurenko (https://github.com/sokurenko) Other contributions ===================
View file
_service:tar_scm:duktape-2.6.0.tar.xz/LICENSE.txt -> _service:tar_scm:duktape-2.7.0.tar.xz/LICENSE.txt
Changed
@@ -4,7 +4,7 @@ (http://opensource.org/licenses/MIT) -Copyright (c) 2013-2019 by Duktape authors (see AUTHORS.rst) +Copyright (c) 2013-present by Duktape authors (see AUTHORS.rst) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
View file
_service:tar_scm:duktape-2.6.0.tar.xz/Makefile.cmdline -> _service:tar_scm:duktape-2.7.0.tar.xz/Makefile.cmdline
Changed
@@ -8,7 +8,8 @@ CMDLINE_SOURCES = \ examples/cmdline/duk_cmdline.c -CC = gcc +CC ?= gcc +CC := $(CC) CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer CCOPTS += -I./examples/cmdline -I./src # duktape.h and duk_config.h must be in include path CCLIBS = -lm @@ -40,7 +41,7 @@ # http://wiki.duktape.org/Configuring.html duk: $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) - $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS) linenoise/linenoise.c: linenoise linenoise:
View file
_service:tar_scm:duktape-2.6.0.tar.xz/Makefile.codepage -> _service:tar_scm:duktape-2.7.0.tar.xz/Makefile.codepage
Changed
@@ -1,6 +1,7 @@ -CC = gcc +CC ?= gcc +CC := $(CC) codepage: - $(CC) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ src/duktape.c examples/codepage-conv/duk_codepage_conv.c \ examples/codepage-conv/test.c -lm
View file
_service:tar_scm:duktape-2.6.0.tar.xz/Makefile.dukdebug -> _service:tar_scm:duktape-2.7.0.tar.xz/Makefile.dukdebug
Changed
@@ -10,7 +10,8 @@ examples/cmdline/duk_cmdline.c \ examples/debug-trans-socket/duk_trans_socket_unix.c -CC = gcc +CC ?= gcc +CC := $(CC) CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer CCOPTS += -I./prep -I./examples/cmdline -I./examples/debug-trans-socket CCOPTS += -DDUK_CMDLINE_DEBUGGER_SUPPORT # enable --debugger in ./duk @@ -38,4 +39,4 @@ -DDUK_USE_INTERRUPT_COUNTER \ -DDUK_USE_DEBUGGER_DUMPHEAP \ -DDUK_USE_DEBUGGER_INSPECT - $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS)
View file
_service:tar_scm:duktape-2.6.0.tar.xz/Makefile.eval -> _service:tar_scm:duktape-2.7.0.tar.xz/Makefile.eval
Changed
@@ -2,8 +2,9 @@ # Example Makefile for building the eval example # -CC = gcc +CC ?= gcc +CC := $(CC) eval: - $(CC) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ src/duktape.c examples/eval/eval.c -lm
View file
_service:tar_scm:duktape-2.6.0.tar.xz/Makefile.eventloop -> _service:tar_scm:duktape-2.7.0.tar.xz/Makefile.eventloop
Changed
@@ -2,14 +2,15 @@ # Example Makefile for building the eventloop example # -CC = gcc +CC ?= gcc +CC := $(CC) evloop: @echo "NOTE: The eventloop is an example intended to be used on Linux" @echo " or other common UNIX variants. It is not fully portable." @echo "" - $(CC) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \ + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \ examples/eventloop/main.c \ examples/eventloop/c_eventloop.c \ examples/eventloop/poll.c \
View file
_service:tar_scm:duktape-2.6.0.tar.xz/Makefile.hello -> _service:tar_scm:duktape-2.7.0.tar.xz/Makefile.hello
Changed
@@ -13,7 +13,8 @@ # Compiler options are quite flexible. GCC versions have a significant impact # on the size of -Os code, e.g. gcc-4.6 is much worse than gcc-4.5. -CC = gcc +CC ?= gcc +CC := $(CC) CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer CCOPTS += -I./src # for combined sources CCLIBS = -lm @@ -29,4 +30,4 @@ # For debugging, use -O0 -g -ggdb, and don't add -fomit-frame-pointer hello: $(DUKTAPE_SOURCES) examples/hello/hello.c - $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) examples/hello/hello.c $(CCLIBS) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) examples/hello/hello.c $(CCLIBS)
View file
_service:tar_scm:duktape-2.6.0.tar.xz/Makefile.jsoncbor -> _service:tar_scm:duktape-2.7.0.tar.xz/Makefile.jsoncbor
Changed
@@ -2,9 +2,10 @@ # Example Makefile for building the jsoncbor example # -CC = gcc +CC ?= gcc +CC := $(CC) jsoncbor: - $(CC) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc -Iextras/cbor \ - src/duktape.c extras/cbor/duk_cbor.c extras/cbor/jsoncbor.c \ + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc -Iextras/cbor \ + src/duktape.c extras/cbor/jsoncbor.c \ -lm
View file
_service:tar_scm:duktape-2.6.0.tar.xz/Makefile.jxpretty -> _service:tar_scm:duktape-2.7.0.tar.xz/Makefile.jxpretty
Changed
@@ -2,9 +2,10 @@ # Example Makefile for building the jxpretty example # -CC = gcc +CC ?= gcc +CC := $(CC) jxpretty: - $(CC) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \ + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \ src/duktape.c examples/jxpretty/jxpretty.c \ -lm
View file
_service:tar_scm:duktape-2.6.0.tar.xz/Makefile.sandbox -> _service:tar_scm:duktape-2.7.0.tar.xz/Makefile.sandbox
Changed
@@ -2,8 +2,9 @@ # Example Makefile for building the sandbox example # -CC = gcc +CC ?= gcc +CC := $(CC) sandbox: - $(CC) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ src/duktape.c examples/sandbox/sandbox.c -lm
View file
_service:tar_scm:duktape-2.6.0.tar.xz/Makefile.sharedlibrary -> _service:tar_scm:duktape-2.7.0.tar.xz/Makefile.sharedlibrary
Changed
@@ -24,8 +24,10 @@ # convention is to set soname version to (100*MAJOR + MINOR), e.g. 104 for # Duktape 1.4.x, so that it gets automatically bumped for major and minor # releases (potentially binary incompatible), but not for patch releases. -DUK_VERSION = 20600 -SONAME_VERSION = 206 +# The formatted version is used for the pkg-config file. +DUK_VERSION = 20700 +DUK_VERSION_FORMATTED = 2.7.0 +SONAME_VERSION = 207 REAL_VERSION = $(SONAME_VERSION).$(DUK_VERSION) # Mac has an unusual .so naming convention @@ -45,44 +47,58 @@ endif # Change to actual path for actual distribution packaging. -INSTALL_PREFIX = /usr/local +INSTALL_PREFIX ?= /usr/local +INSTALL_PREFIX := $(INSTALL_PREFIX) +DESTDIR ?= +DESTDIR := $(DESTDIR) +LIBDIR ?= /lib +LIBDIR := $(LIBDIR) # The 'noline' variant may be more appropriate for some distributions; it # doesn't have #line directives in the combined source. DUKTAPE_SRCDIR = ./src #DUKTAPE_SRCDIR = ./src-noline -CC = gcc +CC ?= gcc +CC := $(CC) .PHONY: all -all: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX) +all: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX) duktape.pc # If the default duk_config.h is not suitable for the distribution, modify it # before compiling the shared library and copy the same, edited duk_config.h # to $INSTALL_PREFIX/include on installation. libduktape.$(SO_REALNAME_SUFFIX): - $(CC) -shared -fPIC -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktape.$(SO_SONAME_SUFFIX) \ + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fPIC -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktape.$(SO_SONAME_SUFFIX) \ -o $@ $(DUKTAPE_SRCDIR)/duktape.c libduktaped.$(SO_REALNAME_SUFFIX): - $(CC) -shared -fPIC -g -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktaped.$(SO_SONAME_SUFFIX) \ + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fPIC -g -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktaped.$(SO_SONAME_SUFFIX) \ -o $@ $(DUKTAPE_SRCDIR)/duktape.c +duktape.pc: + sed -e "s|@PREFIX@|$(INSTALL_PREFIX)|" \ + -e "s|@LIBDIR@|$(LIBDIR)|" \ + -e "s|@VERSION@|$(DUK_VERSION_FORMATTED)|" \ + duktape.pc.in \ + > duktape.pc + # Symlinks depend on platform conventions. .PHONY: install -install: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX) - mkdir -p $(INSTALL_PREFIX)/lib/ - cp $+ $(INSTALL_PREFIX)/lib/ - rm -f $(INSTALL_PREFIX)/lib/libduktape.so $(INSTALL_PREFIX)/lib/libduktape.$(SO_SONAME_SUFFIX) - ln -s libduktape.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktape.so - ln -s libduktape.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktape.$(SO_SONAME_SUFFIX) - rm -f $(INSTALL_PREFIX)/lib/libduktaped.so $(INSTALL_PREFIX)/lib/libduktaped.$(SO_SONAME_SUFFIX) - ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktaped.so - ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktaped.$(SO_SONAME_SUFFIX) - mkdir -p $(INSTALL_PREFIX)/include/ - cp $(DUKTAPE_SRCDIR)/duktape.h $(DUKTAPE_SRCDIR)/duk_config.h $(INSTALL_PREFIX)/include/ +install: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX) duktape.pc + mkdir -p $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/pkgconfig + cp $+ $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/ + rm -f $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.so $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.$(SO_SONAME_SUFFIX) + ln -s libduktape.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.so + ln -s libduktape.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.$(SO_SONAME_SUFFIX) + rm -f $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.so $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.$(SO_SONAME_SUFFIX) + ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.so + ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.$(SO_SONAME_SUFFIX) + mv $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/duktape.pc $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/pkgconfig/ + mkdir -p $(DESTDIR)$(INSTALL_PREFIX)/include/ + cp $(DUKTAPE_SRCDIR)/duktape.h $(DUKTAPE_SRCDIR)/duk_config.h $(DESTDIR)$(INSTALL_PREFIX)/include/ CCOPTS = -I./examples/cmdline duk: - $(CC) $(CCOPTS) -I$(INSTALL_PREFIX)/include -L$(INSTALL_PREFIX)/lib -Wall -Wextra -Os -o $@ ./examples/cmdline/duk_cmdline.c -lduktape -lm + $(CC) $(CCOPTS) -I$(INSTALL_PREFIX)/include -L$(INSTALL_PREFIX)$(LIBDIR) -Wall -Wextra -Os -o $@ ./examples/cmdline/duk_cmdline.c -lduktape -lm
View file
_service:tar_scm:duktape-2.6.0.tar.xz/README.rst -> _service:tar_scm:duktape-2.7.0.tar.xz/README.rst
Changed
@@ -118,11 +118,11 @@ * https://github.com/svaarala/duktape/blob/master/RELEASES.rst (summary of all versions) -* https://github.com/svaarala/duktape/blob/master/doc/release-notes-v2-6.rst +* https://github.com/svaarala/duktape/blob/master/doc/release-notes-v2-7.rst (more detailed notes for this version) -This distributable contains Duktape version 2.6.0, created from git -commit fffa346eff06a8764b02c31d4336f63a773a95c3 (v2.6.0). +This distributable contains Duktape version 2.7.0, created from git +commit 03d4d728f8365021de6955c649e6dcd05dcca99f (03d4d72-dirty). Duktape is copyrighted by its authors (see ``AUTHORS.rst``) and licensed under the MIT license (see ``LICENSE.txt``). String hashing algorithms are
View file
_service:tar_scm:duktape-2.6.0.tar.xz/duk_dist_meta.json -> _service:tar_scm:duktape-2.7.0.tar.xz/duk_dist_meta.json
Changed
@@ -1,9 +1,9 @@ { "comment": "Metadata for Duktape distributable", - "duk_version_string": "2.6.0", + "duk_version_string": "2.7.0", "type": "duk_dist_meta", - "duk_version": 20600, - "git_branch": "v2-maintenance", - "git_commit": "fffa346eff06a8764b02c31d4336f63a773a95c3", - "git_describe": "v2.6.0" + "duk_version": 20700, + "git_branch": "HEAD", + "git_commit": "03d4d728f8365021de6955c649e6dcd05dcca99f", + "git_describe": "03d4d72-dirty" } \ No newline at end of file
View file
_service:tar_scm:duktape-2.7.0.tar.xz/duktape.pc.in
Added
@@ -0,0 +1,10 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=${prefix}@LIBDIR@ +includedir=${prefix}/include + +Name: duktape +Description: Embeddable Javascript engine +Version: @VERSION@ +Libs: -L${libdir} -lduktape +Cflags: -I${includedir}
View file
_service:tar_scm:duktape-2.6.0.tar.xz/extras/alloc-pool/duk_alloc_pool.c -> _service:tar_scm:duktape-2.7.0.tar.xz/extras/alloc-pool/duk_alloc_pool.c
Changed
@@ -302,7 +302,7 @@ } else { waste_bytes += duk__alloc_pool_get_waste_estimate(curr, s->size); } - curr = curr + s->size; + curr = (void *) ((duk_uint8_t *) curr + s->size); } used_count = (size_t) (s->count - free_count);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/extras/cbor/Makefile -> _service:tar_scm:duktape-2.7.0.tar.xz/extras/cbor/Makefile
Changed
@@ -14,7 +14,7 @@ -rm -f jsoncbor -rm -f appendix_a.json -jsoncbor: jsoncbor.c duk_cbor.c duk_cbor.h +jsoncbor: jsoncbor.c -rm -rf ./prep python2 ../../tools/configure.py --quiet --output-directory ./prep \ -DDUK_USE_JSON_DECNUMBER_FASTPATH \ @@ -22,7 +22,7 @@ -DDUK_USE_JSON_EATWHITE_FASTPATH \ -DDUK_USE_JSON_QUOTESTRING_FASTPATH \ -DDUK_USE_JSON_STRINGIFY_FASTPATH - $(CC) $(CCOPTS) -o $@ -I./prep -I. ./prep/duktape.c duk_cbor.c jsoncbor.c -lm + $(CC) $(CCOPTS) -o $@ -I./prep -I. ./prep/duktape.c jsoncbor.c -lm appendix_a.json: wget -O $@ https://raw.githubusercontent.com/cbor/test-vectors/master/appendix_a.json
View file
_service:tar_scm:duktape-2.6.0.tar.xz/extras/cbor/README.rst -> _service:tar_scm:duktape-2.7.0.tar.xz/extras/cbor/README.rst
Changed
@@ -1,23 +1,11 @@ -============ -CBOR binding -============ +=================== +JSON/CBOR converter +=================== Overview ======== -C functions to encode/decode values in CBOR format, and a simple command -line utility to convert between JSON and CBOR. - -To integrate CBOR into your application: - -* Call ``duk_cbor_encode()`` and ``duk_cbor_decode()`` directly if a C API - is enough. - -* Call ``duk_cbor_init()`` to register a global ``CBOR`` object with - ECMAScript bindings ``CBOR.encode()`` and ``CBOR.decode()``, roughly - matching https://github.com/paroga/cbor-js. - -Basic usage of the ``jsoncbor`` conversion tool:: +A simple command line utility to convert between JSON and CBOR. Basic usage:: $ make jsoncbor ... @@ -26,125 +14,3 @@ CBOR objects are decoded into ECMAScript objects, with non-string keys coerced into strings. - -Direct support for CBOR is likely to be included in the Duktape API in the -future. This extra will then become unnecessary. - -CBOR -==== - -CBOR is a standard format for JSON-like binary interchange. It is -faster and smaller, and can encode more data types than JSON. In particular, -binary data can be serialized without encoding e.g. in base-64. These -properties make it useful for storing state files, IPC, etc. - -Some CBOR shortcomings for preserving information: - -* No property attribute or inheritance support. - -* No DAGs or looped graphs. - -* Array objects with properties lose their non-index properties. - -* Array objects with gaps lose their gaps as they read back as undefined. - -* Buffer objects and views lose much of their detail besides the raw data. - -* ECMAScript strings cannot be fully represented; strings must be UTF-8. - -* Functions and native objects lose most of their detail. - -* CBOR tags are useful to provide soft decoding information, but the tags - are just integers from an IANA controlled space with no space for custom - tags. So tags cannot be easily used for private, application specific tags. - IANA allows reserving custom tags with little effort however, see - https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml. - -Future work -=========== - -General: - -* Add flags to control encode/decode behavior. - -* Allow decoding with a trailer so that stream parsing is easier. - Similar change would be useful for JSON decoding. - -* Reserve CBOR tag for missing value. - -* Reserve other necessary CBOR tags. - -* Explicit support for encoding with and without side effects (e.g. - skipping Proxy traps and getters). - -* JSON encoding supports .toJSON(), maybe something like .toCBOR()? - -* Optimize encoding and decoding more. - -Encoding: - -* Tagging of typed arrays: - https://datatracker.ietf.org/doc/draft-ietf-cbor-array-tags/. - Mixed endian encode must convert to e.g. little endian because - no mixed endian tag exists. - -* Encoding typed arrays as integer arrays instead? - -* Float16Array encoding support (once/if supported by main engine). - -* Tagging of array gaps, once IANA reservation is complete: - https://github.com/svaarala/duktape/blob/master/doc/cbor-missing-tag.rst. - -* Support 64-bit integer when encoding, e.g. up to 2^53? - -* Definite-length object encoding even when object has more than 23 keys. - -* Map/Set encoding (once supported in the main engine), maybe tagged - so they decode back into Map/Set. - -* Bigint encoding (once supported in the main engine), as tagged byte - strings like in Python CBOR. - -* String encoding options: combining surrogate pairs, tagging non-UTF-8 - byte strings so they decode back to string, using U+FFFD replacement, - etc. - -* Detection of Symbols, encode them in a useful tagged form. - -* Better encoding of functions. - -* Hook for serialization, to allow caller to serialize values (especially - objects) in a context specific manner (e.g. serialize functions with - IPC metadata to allow them to be called remotely). Such a hook should - be able to emit tag(s) to mark custom values for decode processing. - -Decoding: - -* Typed array decoding support. Should decoder convert to host - endianness? - -* Float16Array decoding support (once/if supported by main engine). - -* Decoding objects with non-string keys, could be represented as a Map. - -* Use bare objects and arrays when decoding? - -* Use a Map rather than a plain object when decoding, which would allow - non-string keys. - -* Bigint decoding (once supported in the main engine). - -* Decoding of non-BMP codepoints into surrogate pairs. - -* Decoding of Symbols when call site indicates it is safe. - -* Hooking for revival, to allow caller to revive objects in a context - specific manner (e.g. revive serialized function objects into IPC - proxy functions). Such a hook should have access to encoding tags, - so that revival can depend on tags present. - -* Option to compact decoded objects and arrays. - -* Improve fastint decoding support, e.g. decode non-optimally encoded - integers as fastints, decode compatible floating point values as - fastints.
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_alloc_default.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_alloc_default.c
Changed
@@ -12,8 +12,7 @@ void *res; DUK_UNREF(udata); res = DUK_ANSI_MALLOC(size); - DUK_DDD(DUK_DDDPRINT("default alloc function: %lu -> %p", - (unsigned long) size, (void *) res)); + DUK_DDD(DUK_DDDPRINT("default alloc function: %lu -> %p", (unsigned long) size, (void *) res)); return res; } @@ -21,8 +20,7 @@ void *res; DUK_UNREF(udata); res = DUK_ANSI_REALLOC(ptr, newsize); - DUK_DDD(DUK_DDDPRINT("default realloc function: %p %lu -> %p", - (void *) ptr, (unsigned long) newsize, (void *) res)); + DUK_DDD(DUK_DDDPRINT("default realloc function: %p %lu -> %p", (void *) ptr, (unsigned long) newsize, (void *) res)); return res; } @@ -31,4 +29,4 @@ DUK_UNREF(udata); DUK_ANSI_FREE(ptr); } -#endif /* DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS */ +#endif /* DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_bytecode.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_bytecode.c
Changed
@@ -14,11 +14,11 @@ #if defined(DUK_USE_BYTECODE_DUMP_SUPPORT) -#define DUK__SER_MARKER 0xbf -#define DUK__SER_STRING 0x00 -#define DUK__SER_NUMBER 0x01 +#define DUK__SER_MARKER 0xbf +#define DUK__SER_STRING 0x00 +#define DUK__SER_NUMBER 0x01 #define DUK__BYTECODE_INITIAL_ALLOC 256 -#define DUK__NO_FORMALS 0xffffffffUL +#define DUK__NO_FORMALS 0xffffffffUL /* * Dump/load helpers, xxx_raw() helpers do no buffer checks @@ -52,12 +52,10 @@ DUK_ASSERT(h != NULL); len = DUK_HSTRING_GET_BYTELEN(h); - DUK_ASSERT(len <= 0xffffffffUL); /* string limits */ + DUK_ASSERT(len <= 0xffffffffUL); /* string limits */ tmp32 = (duk_uint32_t) len; DUK_RAW_WRITEINC_U32_BE(p, tmp32); - duk_memcpy((void *) p, - (const void *) DUK_HSTRING_GET_DATA(h), - len); + duk_memcpy((void *) p, (const void *) DUK_HSTRING_GET_DATA(h), len); p += len; return p; } @@ -71,18 +69,20 @@ DUK_UNREF(thr); len = DUK_HBUFFER_GET_SIZE(h); - DUK_ASSERT(len <= 0xffffffffUL); /* buffer limits */ + DUK_ASSERT(len <= 0xffffffffUL); /* buffer limits */ tmp32 = (duk_uint32_t) len; DUK_RAW_WRITEINC_U32_BE(p, tmp32); /* When len == 0, buffer data pointer may be NULL. */ - duk_memcpy_unsafe((void *) p, - (const void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h), - len); + duk_memcpy_unsafe((void *) p, (const void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h), len); p += len; return p; } -DUK_LOCAL duk_uint8_t *duk__dump_string_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx) { +DUK_LOCAL duk_uint8_t *duk__dump_string_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx) { duk_hstring *h_str; duk_tval *tv; @@ -94,13 +94,17 @@ h_str = DUK_HTHREAD_STRING_EMPTY_STRING(thr); DUK_ASSERT(h_str != NULL); } - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(h_str), p); p = duk__dump_hstring_raw(p, h_str); return p; } -DUK_LOCAL duk_uint8_t *duk__dump_buffer_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx) { +DUK_LOCAL duk_uint8_t *duk__dump_buffer_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx) { duk_tval *tv; tv = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, (duk_hobject *) func, stridx); @@ -108,7 +112,7 @@ duk_hbuffer *h_buf; h_buf = DUK_TVAL_GET_BUFFER(tv); DUK_ASSERT(h_buf != NULL); - DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HBUFFER_GET_SIZE(h_buf), p); p = duk__dump_hbuffer_raw(thr, p, h_buf); } else { @@ -118,7 +122,12 @@ return p; } -DUK_LOCAL duk_uint8_t *duk__dump_uint32_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx, duk_uint32_t def_value) { +DUK_LOCAL duk_uint8_t *duk__dump_uint32_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx, + duk_uint32_t def_value) { duk_tval *tv; duk_uint32_t val; @@ -151,27 +160,28 @@ duk_uint32_t val; key = DUK_HOBJECT_E_GET_KEY(thr->heap, h, i); - DUK_ASSERT(key != NULL); /* _Varmap is dense */ + DUK_ASSERT(key != NULL); /* _Varmap is dense */ DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, h, i)); tv_val = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, h, i); DUK_ASSERT(tv_val != NULL); - DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_val)); /* known to be number; in fact an integer */ + DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_val)); /* known to be number; in fact an integer */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_val)); - DUK_ASSERT(DUK_TVAL_GET_FASTINT(tv_val) == (duk_int64_t) DUK_TVAL_GET_FASTINT_U32(tv_val)); /* known to be 32-bit */ + DUK_ASSERT(DUK_TVAL_GET_FASTINT(tv_val) == + (duk_int64_t) DUK_TVAL_GET_FASTINT_U32(tv_val)); /* known to be 32-bit */ val = DUK_TVAL_GET_FASTINT_U32(tv_val); #else val = (duk_uint32_t) DUK_TVAL_GET_NUMBER(tv_val); #endif - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(key) + 4U, p); p = duk__dump_hstring_raw(p, key); DUK_RAW_WRITEINC_U32_BE(p, val); } } p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_RAW_WRITEINC_U32_BE(p, 0); /* end of _Varmap */ + DUK_RAW_WRITEINC_U32_BE(p, 0); /* end of _Varmap */ return p; } @@ -189,7 +199,7 @@ */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_ASSERT(h->length != DUK__NO_FORMALS); /* limits */ + DUK_ASSERT(h->length != DUK__NO_FORMALS); /* limits */ DUK_RAW_WRITEINC_U32_BE(p, h->length); for (i = 0; i < h->length; i++) { @@ -204,14 +214,14 @@ DUK_ASSERT(varname != NULL); DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(varname) >= 1); - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(varname), p); p = duk__dump_hstring_raw(p, varname); } } else { DUK_DD(DUK_DDPRINT("dumping function without _Formals, emit marker to indicate missing _Formals")); p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_RAW_WRITEINC_U32_BE(p, DUK__NO_FORMALS); /* marker: no formals */ + DUK_RAW_WRITEINC_U32_BE(p, DUK__NO_FORMALS); /* marker: no formals */ } return p; } @@ -245,7 +255,7 @@ (long) DUK_HCOMPFUNC_GET_CODE_SIZE(thr->heap, func), (long) DUK_HCOMPFUNC_GET_CODE_COUNT(thr->heap, func))); - DUK_ASSERT(DUK_USE_ESBC_MAX_BYTES <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_USE_ESBC_MAX_BYTES <= 0x7fffffffUL); /* ensures no overflow */ count_instr = (duk_uint32_t) DUK_HCOMPFUNC_GET_CODE_COUNT(thr->heap, func); p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 3U * 4U + 2U * 2U + 3U * 4U + count_instr * 4U, p); @@ -269,8 +279,8 @@ DUK_RAW_WRITEINC_U32_BE(p, 0); DUK_RAW_WRITEINC_U32_BE(p, 0); #endif - tmp32 = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) func); /* masks flags, only duk_hobject flags */ - tmp32 &= ~(DUK_HOBJECT_FLAG_HAVE_FINALIZER); /* finalizer flag is lost */ + tmp32 = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) func); /* masks flags, only duk_hobject flags */ + tmp32 &= ~(DUK_HOBJECT_FLAG_HAVE_FINALIZER); /* finalizer flag is lost */ DUK_RAW_WRITEINC_U32_BE(p, tmp32); /* Bytecode instructions: endian conversion needed unless @@ -280,8 +290,9 @@ ins_end = DUK_HCOMPFUNC_GET_CODE_END(thr->heap, func); DUK_ASSERT((duk_size_t) (ins_end - ins) == (duk_size_t) count_instr); #if defined(DUK_USE_INTEGER_BE) - duk_memcpy_unsafe((void *) p, (const void *) ins, (size_t) (ins_end - ins)); - p += (size_t) (ins_end - ins); + duk_memcpy_unsafe((void *) p, (const void *) ins, count_instr * sizeof(duk_instr_t)); + p += count_instr * sizeof(duk_instr_t); + DUK_UNREF(ins_end); #else while (ins != ins_end) { tmp32 = (duk_uint32_t) (*ins); @@ -295,13 +306,12 @@ tv_end = DUK_HCOMPFUNC_GET_CONSTS_END(thr->heap, func); while (tv != tv_end) { /* constants are strings or numbers now */ - DUK_ASSERT(DUK_TVAL_IS_STRING(tv) || - DUK_TVAL_IS_NUMBER(tv)); + DUK_ASSERT(DUK_TVAL_IS_STRING(tv) || DUK_TVAL_IS_NUMBER(tv)); if (DUK_TVAL_IS_STRING(tv)) { h_str = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h_str != NULL); - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 1U + 4U + DUK_HSTRING_GET_BYTELEN(h_str), p); *p++ = DUK__SER_STRING; p = duk__dump_hstring_raw(p, h_str); @@ -367,7 +377,8 @@ * are validated (which is quite complex, especially for indirect opcodes). */ -#define DUK__ASSERT_LEFT(n) do { \ +#define DUK__ASSERT_LEFT(n) \ + do { \ DUK_ASSERT((duk_size_t) (p_end - p) >= (duk_size_t) (n)); \ } while (0) @@ -402,13 +413,13 @@ count_const = DUK_RAW_READINC_U32_BE(p); count_funcs = DUK_RAW_READINC_U32_BE(p); - data_size = sizeof(duk_tval) * count_const + - sizeof(duk_hobject *) * count_funcs + - sizeof(duk_instr_t) * count_instr; + data_size = sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs + sizeof(duk_instr_t) * count_instr; DUK_DD(DUK_DDPRINT("instr=%ld, const=%ld, funcs=%ld, data_size=%ld", - (long) count_instr, (long) count_const, - (long) count_const, (long) data_size)); + (long) count_instr, + (long) count_const, + (long) count_const, + (long) data_size)); /* Value stack is used to ensure reachability of constants and * inner functions being loaded. Require enough space to handle @@ -434,12 +445,12 @@ h_fun->start_line = DUK_RAW_READINC_U32_BE(p); h_fun->end_line = DUK_RAW_READINC_U32_BE(p); #else - p += 8; /* skip line info */ + p += 8; /* skip line info */ #endif /* duk_hcompfunc flags; quite version specific */ tmp32 = DUK_RAW_READINC_U32_BE(p); - DUK_HEAPHDR_SET_FLAGS((duk_heaphdr *) h_fun, tmp32); /* masks flags to only change duk_hobject flags */ + DUK_HEAPHDR_SET_FLAGS((duk_heaphdr *) h_fun, tmp32); /* masks flags to only change duk_hobject flags */ /* standard prototype (no need to set here, already set) */ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_fun) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); @@ -467,9 +478,7 @@ DUK__ASSERT_LEFT(count_instr * sizeof(duk_instr_t)); #if defined(DUK_USE_INTEGER_BE) q = fun_data + sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs; - duk_memcpy((void *) q, - (const void *) p, - sizeof(duk_instr_t) * count_instr); + duk_memcpy((void *) q, (const void *) p, sizeof(duk_instr_t) * count_instr); p += sizeof(duk_instr_t) * count_instr; #else q = fun_data + sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs; @@ -528,13 +537,13 @@ DUK_HCOMPFUNC_SET_DATA(thr->heap, h_fun, h_data); DUK_HBUFFER_INCREF(thr, h_data); - tv1 = duk_get_tval(thr, idx_base + 2); /* may be NULL if no constants or inner funcs */ + tv1 = duk_get_tval(thr, idx_base + 2); /* may be NULL if no constants or inner funcs */ DUK_ASSERT((count_const == 0 && count_funcs == 0) || tv1 != NULL); q = fun_data; duk_memcpy_unsafe((void *) q, (const void *) tv1, sizeof(duk_tval) * count_const); for (n = count_const; n > 0; n--) { - DUK_TVAL_INCREF_FAST(thr, (duk_tval *) (void *) q); /* no side effects */ + DUK_TVAL_INCREF_FAST(thr, (duk_tval *) (void *) q); /* no side effects */ q += sizeof(duk_tval); } tv1 += count_const; @@ -567,7 +576,7 @@ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); #if defined(DUK_USE_FUNC_NAME_PROPERTY) - p = duk__load_string_raw(thr, p); /* -> func funcname */ + p = duk__load_string_raw(thr, p); /* -> func funcname */ func_env = thr->builtinsDUK_BIDX_GLOBAL_ENV; DUK_ASSERT(func_env != NULL); need_pop = 0; @@ -578,11 +587,10 @@ */ duk_hdecenv *new_env; - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); - DUK_ASSERT(new_env->thread == NULL); /* Closed. */ + DUK_ASSERT(new_env->thread == NULL); /* Closed. */ DUK_ASSERT(new_env->varmap == NULL); DUK_ASSERT(new_env->regbase_byteoff == 0); DUK_HDECENV_ASSERT_VALID(new_env); @@ -594,11 +602,11 @@ duk_push_hobject(thr, (duk_hobject *) new_env); - duk_dup_m2(thr); /* -> func funcname env funcname */ - duk_dup(thr, idx_base); /* -> func funcname env funcname func */ - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> func funcname env */ + duk_dup_m2(thr); /* -> func funcname env funcname */ + duk_dup(thr, idx_base); /* -> func funcname env funcname func */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> func funcname env */ - need_pop = 1; /* Need to pop env, but -after- updating h_fun and increfs. */ + need_pop = 1; /* Need to pop env, but -after- updating h_fun and increfs. */ } DUK_ASSERT(func_env != NULL); DUK_HCOMPFUNC_SET_LEXENV(thr->heap, h_fun, func_env); @@ -609,12 +617,12 @@ duk_pop(thr); } duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ #if defined(DUK_USE_FUNC_FILENAME_PROPERTY) p = duk__load_string_raw(thr, p); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_C); -#endif /* DUK_USE_FUNC_FILENAME_PROPERTY */ +#endif /* DUK_USE_FUNC_FILENAME_PROPERTY */ if (DUK_HOBJECT_HAS_CONSTRUCTABLE((duk_hobject *) h_fun)) { /* Restore empty external .prototype only for constructable @@ -624,7 +632,10 @@ duk_push_object(thr); DUK_ASSERT(!duk_is_bare_object(thr, -1)); duk_dup_m2(thr); - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC); /* func.prototype.constructor = func */ + duk_xdef_prop_stridx_short(thr, + -2, + DUK_STRIDX_CONSTRUCTOR, + DUK_PROPDESC_FLAGS_WC); /* func.prototype.constructor = func */ duk_compact_m1(thr); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); } @@ -632,9 +643,9 @@ #if defined(DUK_USE_PC2LINE) p = duk__load_buffer_raw(thr, p); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_WC); -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ - duk_push_bare_object(thr); /* _Varmap */ + duk_push_bare_object(thr); /* _Varmap */ for (;;) { /* XXX: awkward */ p = duk__load_string_raw(thr, p); @@ -654,7 +665,7 @@ */ arr_limit = DUK_RAW_READINC_U32_BE(p); if (arr_limit != DUK__NO_FORMALS) { - duk_push_bare_array(thr); /* _Formals */ + duk_push_bare_array(thr); /* _Formals */ for (arr_idx = 0; arr_idx < arr_limit; arr_idx++) { p = duk__load_string_raw(thr, p); duk_put_prop_index(thr, -2, arr_idx); @@ -670,7 +681,7 @@ DUK_ASSERT_TOP(thr, idx_base + 1); return p; - format_error: +format_error: return NULL; } @@ -702,7 +713,7 @@ DUK_DD(DUK_DDPRINT("serialized result: %!T", duk_get_tval(thr, -1))); - duk_remove_m2(thr); /* ... func buf -> ... buf */ + duk_remove_m2(thr); /* ... func buf -> ... buf */ } DUK_EXTERNAL void duk_load_function(duk_hthread *thr) { @@ -735,15 +746,15 @@ goto format_error; } - duk_remove_m2(thr); /* ... buf func -> ... func */ + duk_remove_m2(thr); /* ... buf func -> ... func */ return; - format_error: +format_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BYTECODE); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BYTECODE_DUMP_SUPPORT */ +#else /* DUK_USE_BYTECODE_DUMP_SUPPORT */ DUK_EXTERNAL void duk_dump_function(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); @@ -757,4 +768,4 @@ DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BYTECODE_DUMP_SUPPORT */ +#endif /* DUK_USE_BYTECODE_DUMP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_call.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_call.c
Changed
@@ -51,7 +51,7 @@ DUK_ASSERT(other >= 0); idx_func = duk_get_top(thr) - nargs - other; - if (DUK_UNLIKELY((idx_func | nargs) < 0)) { /* idx_func < 0 || nargs < 0; OR sign bits */ + if (DUK_UNLIKELY((idx_func | nargs) < 0)) { /* idx_func < 0 || nargs < 0; OR sign bits */ DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } @@ -85,12 +85,14 @@ DUK_ASSERT(nargs >= 0); DUK_DDD(DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_idx=%ld, nargs=%ld, stacktop=%ld", - (long) normalized_obj_idx, (long) nargs, (long) duk_get_top(thr))); + (long) normalized_obj_idx, + (long) nargs, + (long) duk_get_top(thr))); /* ... key arg1 ... argN */ /* duplicate key */ - duk_dup(thr, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */ + duk_dup(thr, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */ (void) duk_get_prop(thr, normalized_obj_idx); DUK_DDD(DUK_DDDPRINT("func: %!T", (duk_tval *) duk_get_tval(thr, -1))); @@ -133,7 +135,7 @@ duk_insert_undefined(thr, idx_func + 1); - call_flags = 0; /* not protected, respect reclimit, not constructor */ + call_flags = 0; /* not protected, respect reclimit, not constructor */ duk_handle_call_unprotected(thr, idx_func, call_flags); } @@ -146,7 +148,7 @@ idx_func = duk__call_get_idx_func(thr, nargs, 2); DUK_ASSERT(duk_is_valid_index(thr, idx_func)); - call_flags = 0; /* not protected, respect reclimit, not constructor */ + call_flags = 0; /* not protected, respect reclimit, not constructor */ duk_handle_call_unprotected(thr, idx_func, call_flags); } @@ -160,7 +162,7 @@ DUK_ASSERT_API_ENTRY(thr); - obj_idx = duk_require_normalize_index(thr, obj_idx); /* make absolute */ + obj_idx = duk_require_normalize_index(thr, obj_idx); /* make absolute */ if (DUK_UNLIKELY(nargs < 0)) { DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return;); @@ -258,7 +260,7 @@ args = (duk__pcall_prop_args *) udata; - obj_idx = duk_require_normalize_index(thr, args->obj_idx); /* make absolute */ + obj_idx = duk_require_normalize_index(thr, args->obj_idx); /* make absolute */ duk__call_prop_prep_stack(thr, obj_idx, args->nargs); ret = duk_handle_call_unprotected_nargs(thr, args->nargs, args->call_flags); @@ -296,30 +298,30 @@ */ /* XXX: check for any reserve? */ - if (DUK_UNLIKELY((nargs | nrets) < 0 || /* nargs < 0 || nrets < 0; OR sign bits */ - thr->valstack_top < thr->valstack_bottom + nargs || /* nargs too large compared to top */ - thr->valstack_end + nargs < thr->valstack_top + nrets)) { /* nrets too large compared to reserve */ + if (DUK_UNLIKELY((nargs | nrets) < 0 || /* nargs < 0 || nrets < 0; OR sign bits */ + thr->valstack_top < thr->valstack_bottom + nargs || /* nargs too large compared to top */ + thr->valstack_end + nargs < thr->valstack_top + nrets)) { /* nrets too large compared to reserve */ DUK_D(DUK_DPRINT("not enough stack reserve for safe call or invalid arguments: " "nargs=%ld < 0 (?), nrets=%ld < 0 (?), top=%ld < bottom=%ld + nargs=%ld (?), " "end=%ld + nargs=%ld < top=%ld + nrets=%ld (?)", - (long) nargs, - (long) nrets, - (long) (thr->valstack_top - thr->valstack), - (long) (thr->valstack_bottom - thr->valstack), - (long) nargs, - (long) (thr->valstack_end - thr->valstack), - (long) nargs, - (long) (thr->valstack_top - thr->valstack), - (long) nrets)); + (long) nargs, + (long) nrets, + (long) (thr->valstack_top - thr->valstack), + (long) (thr->valstack_bottom - thr->valstack), + (long) nargs, + (long) (thr->valstack_end - thr->valstack), + (long) nargs, + (long) (thr->valstack_top - thr->valstack), + (long) nrets)); DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return DUK_EXEC_ERROR;); } - rc = duk_handle_safe_call(thr, /* thread */ - func, /* func */ - udata, /* udata */ - nargs, /* num_stack_args */ - nrets); /* num_stack_res */ + rc = duk_handle_safe_call(thr, /* thread */ + func, /* func */ + udata, /* udata */ + nargs, /* num_stack_args */ + nrets); /* num_stack_res */ return rc; } @@ -332,7 +334,7 @@ idx_func = duk__call_get_idx_func(thr, nargs, 1); DUK_ASSERT(duk_is_valid_index(thr, idx_func)); - duk_push_object(thr); /* default instance; internal proto updated by call handling */ + duk_push_object(thr); /* default instance; internal proto updated by call handling */ duk_insert(thr, idx_func + 1); duk_handle_call_unprotected(thr, idx_func, DUK_CALL_FLAG_CONSTRUCT); @@ -460,7 +462,7 @@ } /* fall through */ - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_UNEXPECTED_TYPE); DUK_WO_NORETURN(return 0;); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_codec.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_codec.c
Changed
@@ -18,15 +18,16 @@ * is guaranteed to be non-NULL, even for zero length input. */ DUK_LOCAL const duk_uint8_t *duk__prep_codec_arg(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) { - const void *def_ptr = (const void *) out_len; /* Any non-NULL pointer will do. */ + const void *def_ptr = (const void *) out_len; /* Any non-NULL pointer will do. */ const void *ptr; duk_bool_t isbuffer; DUK_ASSERT(out_len != NULL); DUK_ASSERT(def_ptr != NULL); - DUK_ASSERT(duk_is_valid_index(thr, idx)); /* checked by caller */ + DUK_ASSERT(duk_is_valid_index(thr, idx)); /* checked by caller */ - ptr = (const void *) duk_get_buffer_data_raw(thr, idx, out_len, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, &isbuffer); + ptr = (const void *) + duk_get_buffer_data_raw(thr, idx, out_len, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, &isbuffer); if (isbuffer) { DUK_ASSERT(ptr != NULL || *out_len == 0U); if (DUK_UNLIKELY(ptr == NULL)) { @@ -51,21 +52,21 @@ #if defined(DUK_USE_BASE64_SUPPORT) /* Bytes emitted for number of padding characters in range 0,4. */ DUK_LOCAL const duk_int8_t duk__base64_decode_nequal_step5 = { - 3, /* #### -> 24 bits, emit 3 bytes */ - 2, /* ###= -> 18 bits, emit 2 bytes */ - 1, /* ##== -> 12 bits, emit 1 byte */ - -1, /* #=== -> 6 bits, error */ - 0, /* ==== -> 0 bits, emit 0 bytes */ + 3, /* #### -> 24 bits, emit 3 bytes */ + 2, /* ###= -> 18 bits, emit 2 bytes */ + 1, /* ##== -> 12 bits, emit 1 byte */ + -1, /* #=== -> 6 bits, error */ + 0, /* ==== -> 0 bits, emit 0 bytes */ }; #if defined(DUK_USE_BASE64_FASTPATH) DUK_LOCAL const duk_uint8_t duk__base64_enctab_fast64 = { - 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x50U, /* A...P */ - 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x58U, 0x59U, 0x5aU, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, /* Q...f */ - 0x67U, 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, 0x6fU, 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, /* g...v */ - 0x77U, 0x78U, 0x79U, 0x7aU, 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x2bU, 0x2fU /* w.../ */ + 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x50U, /* A...P */ + 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x58U, 0x59U, 0x5aU, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, /* Q...f */ + 0x67U, 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, 0x6fU, 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, /* g...v */ + 0x77U, 0x78U, 0x79U, 0x7aU, 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x2bU, 0x2fU /* w.../ */ }; -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) /* Decode table for one byte of input: @@ -75,24 +76,24 @@ * 0...63 decoded bytes */ DUK_LOCAL const duk_int8_t duk__base64_dectab_fast256 = { - -3, -3, -3, -3, -3, -3, -3, -3, -3, -1, -1, -3, -3, -1, -3, -3, /* 0x00...0x0f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x10...0x1f */ - -1, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 62, -3, -3, -3, 63, /* 0x20...0x2f */ - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -3, -3, -3, -2, -3, -3, /* 0x30...0x3f */ - -3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40...0x4f */ - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -3, -3, -3, -3, -3, /* 0x50...0x5f */ - -3, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60...0x6f */ - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -3, -3, -3, -3, -3, /* 0x70...0x7f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x80...0x8f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x90...0x9f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xa0...0xaf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xb0...0xbf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xc0...0xcf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xd0...0xdf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xe0...0xef */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3 /* 0xf0...0xff */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -1, -1, -3, -3, -1, -3, -3, /* 0x00...0x0f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x10...0x1f */ + -1, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 62, -3, -3, -3, 63, /* 0x20...0x2f */ + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -3, -3, -3, -2, -3, -3, /* 0x30...0x3f */ + -3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40...0x4f */ + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -3, -3, -3, -3, -3, /* 0x50...0x5f */ + -3, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60...0x6f */ + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -3, -3, -3, -3, -3, /* 0x70...0x7f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x80...0x8f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x90...0x9f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xa0...0xaf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xb0...0xbf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xc0...0xcf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xd0...0xdf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xe0...0xef */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3 /* 0xf0...0xff */ }; -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) DUK_LOCAL DUK_ALWAYS_INLINE void duk__base64_encode_fast_3(const duk_uint8_t *src, duk_uint8_t *dst) { @@ -124,9 +125,9 @@ t = (duk_uint_t) src0; t = (t << 8) + (duk_uint_t) src1; - dst0 = duk__base64_enctab_fastt >> 10; /* XXXXXX-- -------- */ - dst1 = duk__base64_enctab_fast(t >> 4) & 0x3fU; /* ------XX XXXX---- */ - dst2 = duk__base64_enctab_fast(t << 2) & 0x3fU; /* -------- ----XXXX */ + dst0 = duk__base64_enctab_fastt >> 10; /* XXXXXX-- -------- */ + dst1 = duk__base64_enctab_fast(t >> 4) & 0x3fU; /* ------XX XXXX---- */ + dst2 = duk__base64_enctab_fast(t << 2) & 0x3fU; /* -------- ----XXXX */ dst3 = DUK_ASC_EQUALS; } @@ -134,8 +135,8 @@ duk_uint_t t; t = (duk_uint_t) src0; - dst0 = duk__base64_enctab_fastt >> 2; /* XXXXXX-- */ - dst1 = duk__base64_enctab_fast(t << 4) & 0x3fU; /* ------XX */ + dst0 = duk__base64_enctab_fastt >> 2; /* XXXXXX-- */ + dst1 = duk__base64_enctab_fast(t << 4) & 0x3fU; /* ------XX */ dst2 = DUK_ASC_EQUALS; dst3 = DUK_ASC_EQUALS; } @@ -183,24 +184,24 @@ DUK_ASSERT(n == 0U || n == 1U || n == 2U); if (n == 1U) { duk__base64_encode_fast_1(p, q); -#if 0 /* Unnecessary. */ +#if 0 /* Unnecessary. */ p += 1; q += 4; n -= 1U; #endif } else if (n == 2U) { duk__base64_encode_fast_2(p, q); -#if 0 /* Unnecessary. */ +#if 0 /* Unnecessary. */ p += 2; q += 4; n -= 2U; #endif } else { - DUK_ASSERT(n == 0U); /* nothing to do */ + DUK_ASSERT(n == 0U); /* nothing to do */ ; } } -#else /* DUK_USE_BASE64_FASTPATH */ +#else /* DUK_USE_BASE64_FASTPATH */ DUK_LOCAL void duk__base64_encode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst) { duk_small_uint_t i, npad; duk_uint_t t, x, y; @@ -272,10 +273,13 @@ npad--; } } -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) -DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst, duk_uint8_t **out_dst_final) { +DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, + duk_size_t srclen, + duk_uint8_t *dst, + duk_uint8_t **out_dst_final) { duk_int_t x; duk_uint_t t; duk_small_uint_t n_equal; @@ -285,11 +289,11 @@ const duk_uint8_t *p_end_safe; duk_uint8_t *q; - DUK_ASSERT(src != NULL); /* Required by pointer arithmetic below, which fails for NULL. */ + DUK_ASSERT(src != NULL); /* Required by pointer arithmetic below, which fails for NULL. */ p = src; p_end = src + srclen; - p_end_safe = p_end - 8; /* If 'src <= src_end_safe', safe to read 8 bytes. */ + p_end_safe = p_end - 8; /* If 'src <= src_end_safe', safe to read 8 bytes. */ q = dst; /* Alternate between a fast path which processes clean groups with no @@ -319,7 +323,9 @@ * bytes to minimize aliasing. */ DUK_DDD(DUK_DDDPRINT("fast loop: p=%p, p_end_safe=%p, p_end=%p", - (const void *) p, (const void *) p_end_safe, (const void *) p_end)); + (const void *) p, + (const void *) p_end_safe, + (const void *) p_end)); t1 = (duk_int_t) duk__base64_dectab_fastp0; t1 = (duk_int_t) ((duk_uint_t) t1 << 6) | (duk_int_t) duk__base64_dectab_fastp1; @@ -344,17 +350,19 @@ p += 8; q += 6; } else if (t1 >= 0) { - DUK_DDD(DUK_DDDPRINT("fast loop first group was clean, second was not, process one slow path group")); + DUK_DDD( + DUK_DDDPRINT("fast loop first group was clean, second was not, process one slow path group")); DUK_ASSERT(t2 < 0); p += 4; q += 3; break; } else { - DUK_DDD(DUK_DDDPRINT("fast loop first group was not clean, second does not matter, process one slow path group")); + DUK_DDD(DUK_DDDPRINT( + "fast loop first group was not clean, second does not matter, process one slow path group")); DUK_ASSERT(t1 < 0); break; } - } /* fast path */ + } /* fast path */ /* Slow path step 1: try to scan a 4-character encoded group, * end-of-input, or start-of-padding. We exit with: @@ -369,7 +377,9 @@ t = 1UL; for (;;) { DUK_DDD(DUK_DDDPRINT("slow loop: p=%p, p_end=%p, t=%lu", - (const void *) p, (const void *) p_end, (unsigned long) t)); + (const void *) p, + (const void *) p_end, + (unsigned long) t)); if (DUK_LIKELY(p < p_end)) { x = duk__base64_dectab_fast*p++; @@ -380,18 +390,18 @@ break; } } else if (x == -1) { - continue; /* allowed ascii whitespace */ + continue; /* allowed ascii whitespace */ } else if (x == -2) { p--; - break; /* start of padding */ + break; /* start of padding */ } else { DUK_ASSERT(x == -3); goto decode_error; } } else { - break; /* end of input */ + break; /* end of input */ } - } /* slow path step 1 */ + } /* slow path step 1 */ /* Complete the padding by simulating pad characters, * regardless of actual input padding chars. @@ -450,28 +460,30 @@ } x = duk__base64_dectab_fast*p++; if (x == -1 || x == -2) { - ; /* padding or whitespace, keep eating */ + ; /* padding or whitespace, keep eating */ } else { p--; - break; /* backtrack and go back to fast path, even for -1 */ + break; /* backtrack and go back to fast path, even for -1 */ } - } /* slow path step 3 */ - } /* outer fast+slow path loop */ + } /* slow path step 3 */ + } /* outer fast+slow path loop */ - done: - DUK_DDD(DUK_DDDPRINT("done; p=%p, p_end=%p", - (const void *) p, (const void *) p_end)); +done: + DUK_DDD(DUK_DDDPRINT("done; p=%p, p_end=%p", (const void *) p, (const void *) p_end)); DUK_ASSERT(p == p_end); *out_dst_final = q; return 1; - decode_error: +decode_error: return 0; } -#else /* DUK_USE_BASE64_FASTPATH */ -DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst, duk_uint8_t **out_dst_final) { +#else /* DUK_USE_BASE64_FASTPATH */ +DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, + duk_size_t srclen, + duk_uint8_t *dst, + duk_uint8_t **out_dst_final) { duk_uint_t t, x; duk_int_t y; duk_int8_t step; @@ -557,7 +569,7 @@ } else { /* Valid: whitespace. */ duk_uint32_t m; - DUK_ASSERT(x < 0x20U); /* 0x00 to 0x1f */ + DUK_ASSERT(x < 0x20U); /* 0x00 to 0x1f */ m = (1U << x); if (mask_white & m) { /* Allow basic ASCII whitespace. */ @@ -574,7 +586,7 @@ } /* fall through; no padding will be added */ - simulate_padding: + simulate_padding: n_equal = 0; while (t < 0x1000000UL) { t = (t << 6) + 0U; @@ -606,10 +618,10 @@ *out_dst_final = q; return 1; - decode_error: +decode_error: return 0; } -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ DUK_EXTERNAL const char *duk_base64_encode(duk_hthread *thr, duk_idx_t idx) { const duk_uint8_t *src; @@ -638,11 +650,11 @@ duk__base64_encode_helper((const duk_uint8_t *) src, srclen, dst); - ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ + ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ duk_replace(thr, idx); return ret; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_BASE64_ENCODE_FAILED); DUK_WO_NORETURN(return NULL;); } @@ -667,7 +679,7 @@ * Similarly, 'xx' may ecause 1+3 = bytes to be emitted and then * backtracked. */ - dstlen = (srclen / 4) * 3 + 6; /* upper limit, assuming no whitespace etc */ + dstlen = (srclen / 4) * 3 + 6; /* upper limit, assuming no whitespace etc */ dst = (duk_uint8_t *) duk_push_dynamic_buffer(thr, dstlen); /* Note: for dstlen=0, dst may be NULL */ @@ -680,11 +692,11 @@ duk_replace(thr, idx); return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_BASE64_DECODE_FAILED); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BASE64_SUPPORT */ +#else /* DUK_USE_BASE64_SUPPORT */ DUK_EXTERNAL const char *duk_base64_encode(duk_hthread *thr, duk_idx_t idx) { DUK_UNREF(idx); DUK_ERROR_UNSUPPORTED(thr); @@ -696,7 +708,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BASE64_SUPPORT */ +#endif /* DUK_USE_BASE64_SUPPORT */ /* * Hex @@ -725,7 +737,7 @@ DUK_ASSERT(buf != NULL); #if defined(DUK_USE_HEX_FASTPATH) - DUK_ASSERT((((duk_size_t) buf) & 0x01U) == 0); /* pointer is aligned, guaranteed for fixed buffer */ + DUK_ASSERT((((duk_size_t) buf) & 0x01U) == 0); /* pointer is aligned, guaranteed for fixed buffer */ p16 = (duk_uint16_t *) (void *) buf; len_safe = len & ~0x03U; for (i = 0; i < len_safe; i += 4) { @@ -738,14 +750,14 @@ for (; i < len; i++) { *p16++ = duk_hex_enctabinpi; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ for (i = 0; i < len; i++) { duk_small_uint_t t; t = (duk_small_uint_t) inpi; - bufi*2 + 0 = duk_lc_digitst >> 4; - bufi*2 + 1 = duk_lc_digitst & 0x0f; + bufi * 2 + 0 = duk_lc_digitst >> 4; + bufi * 2 + 1 = duk_lc_digitst & 0x0f; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ /* XXX: Using a string return value forces a string intern which is * not always necessary. As a rough performance measure, hex encode @@ -754,7 +766,7 @@ * caller coerce to string if necessary? */ - ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ + ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ duk_replace(thr, idx); return ret; } @@ -789,20 +801,16 @@ p = buf; len_safe = len & ~0x07U; for (i = 0; i < len_safe; i += 8) { - t = ((duk_int_t) duk_hex_dectab_shift4inpi) | - ((duk_int_t) duk_hex_dectabinpi + 1); + t = ((duk_int_t) duk_hex_dectab_shift4inpi) | ((duk_int_t) duk_hex_dectabinpi + 1); chk = t; p0 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 2) | - ((duk_int_t) duk_hex_dectabinpi + 3); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 2) | ((duk_int_t) duk_hex_dectabinpi + 3); chk |= t; p1 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 4) | - ((duk_int_t) duk_hex_dectabinpi + 5); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 4) | ((duk_int_t) duk_hex_dectabinpi + 5); chk |= t; p2 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 6) | - ((duk_int_t) duk_hex_dectabinpi + 7); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 6) | ((duk_int_t) duk_hex_dectabinpi + 7); chk |= t; p3 = (duk_uint8_t) t; p += 4; @@ -824,7 +832,7 @@ } *p++ = (duk_uint8_t) t; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ for (i = 0; i < len; i += 2) { /* For invalid characters the value -1 gets extended to * at least 16 bits. If either nybble is invalid, the @@ -837,16 +845,16 @@ } bufi >> 1 = (duk_uint8_t) t; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ duk_replace(thr, idx); return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_HEX_DECODE_FAILED); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_HEX_SUPPORT */ +#else /* DUK_USE_HEX_SUPPORT */ DUK_EXTERNAL const char *duk_hex_encode(duk_hthread *thr, duk_idx_t idx) { DUK_UNREF(idx); DUK_ERROR_UNSUPPORTED(thr); @@ -857,7 +865,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_HEX_SUPPORT */ +#endif /* DUK_USE_HEX_SUPPORT */ /* * JSON @@ -901,15 +909,12 @@ #endif idx = duk_require_normalize_index(thr, idx); - duk_bi_json_parse_helper(thr, - idx /*idx_value*/, - DUK_INVALID_INDEX /*idx_reviver*/, - 0 /*flags*/); + duk_bi_json_parse_helper(thr, idx /*idx_value*/, DUK_INVALID_INDEX /*idx_reviver*/, 0 /*flags*/); duk_replace(thr, idx); DUK_ASSERT(duk_get_top(thr) == top_at_entry); } -#else /* DUK_USE_JSON_SUPPORT */ +#else /* DUK_USE_JSON_SUPPORT */ DUK_EXTERNAL const char *duk_json_encode(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx); @@ -923,4 +928,4 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_compile.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_compile.c
Changed
@@ -6,7 +6,7 @@ typedef struct duk__compile_raw_args duk__compile_raw_args; struct duk__compile_raw_args { - duk_size_t src_length; /* should be first on 64-bit platforms */ + duk_size_t src_length; /* should be first on 64-bit platforms */ const duk_uint8_t *src_buffer; duk_uint_t flags; }; @@ -26,7 +26,10 @@ /* ... source? filename? (depends on flags) */ - rc = duk_compile_raw(thr, src_buffer, src_length, flags | DUK_COMPILE_EVAL); /* may be safe, or non-safe depending on flags */ + rc = duk_compile_raw(thr, + src_buffer, + src_length, + flags | DUK_COMPILE_EVAL); /* may be safe, or non-safe depending on flags */ /* ... closure/error */ @@ -35,7 +38,7 @@ goto got_rc; } - duk_push_global_object(thr); /* explicit 'this' binding, see GH-164 */ + duk_push_global_object(thr); /* explicit 'this' binding, see GH-164 */ if (flags & DUK_COMPILE_SAFE) { rc = duk_pcall_method(thr, 0); @@ -46,7 +49,7 @@ /* ... result/error */ - got_rc: +got_rc: if (flags & DUK_COMPILE_NORESULT) { duk_pop(thr); } @@ -86,8 +89,8 @@ duk_hstring *h_sourcecode; h_sourcecode = duk_get_hstring(thr, -2); - if ((flags & DUK_COMPILE_NOSOURCE) || /* args incorrect */ - (h_sourcecode == NULL)) { /* e.g. duk_push_string_file_raw() pushed undefined */ + if ((flags & DUK_COMPILE_NOSOURCE) || /* args incorrect */ + (h_sourcecode == NULL)) { /* e.g. duk_push_string_file_raw() pushed undefined */ DUK_ERROR_TYPE(thr, DUK_STR_NO_SOURCECODE); DUK_WO_NORETURN(return 0;); } @@ -117,11 +120,11 @@ h_templ = (duk_hcompfunc *) duk_known_hobject(thr, -1); duk_js_push_closure(thr, - h_templ, - thr->builtinsDUK_BIDX_GLOBAL_ENV, - thr->builtinsDUK_BIDX_GLOBAL_ENV, - 1 /*add_auto_proto*/); - duk_remove_m2(thr); /* -> ... closure */ + h_templ, + thr->builtinsDUK_BIDX_GLOBAL_ENV, + thr->builtinsDUK_BIDX_GLOBAL_ENV, + 1 /*add_auto_proto*/); + duk_remove_m2(thr); /* -> ... closure */ /* ... closure */ @@ -157,8 +160,7 @@ * directly into flags. */ nargs = flags & 0x07; - DUK_ASSERT(nargs == ((flags & DUK_COMPILE_NOSOURCE) ? 0 : 1) + - ((flags & DUK_COMPILE_NOFILENAME) ? 0 : 1)); + DUK_ASSERT(nargs == ((flags & DUK_COMPILE_NOSOURCE) ? 0 : 1) + ((flags & DUK_COMPILE_NOFILENAME) ? 0 : 1)); rc = duk_safe_call(thr, duk__do_compile, (void *) comp_args, nargs, nrets); /* ... closure */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_debug.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_debug.c
Changed
@@ -26,25 +26,24 @@ * Perhaps values need to be coerced individually? */ duk_bi_json_stringify_helper(thr, - duk_get_top_index(thr), /*idx_value*/ - DUK_INVALID_INDEX, /*idx_replacer*/ - DUK_INVALID_INDEX, /*idx_space*/ - DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_ASCII_ONLY | - DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); + duk_get_top_index(thr), /*idx_value*/ + DUK_INVALID_INDEX, /*idx_replacer*/ + DUK_INVALID_INDEX, /*idx_space*/ + DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_ASCII_ONLY | + DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); duk_push_sprintf(thr, "ctx: top=%ld, stack=%s", (long) top, (const char *) duk_safe_to_string(thr, -1)); - duk_replace(thr, -3); /* ... arr jsonx(arr) res -> ... res jsonx(arr) */ + duk_replace(thr, -3); /* ... arr jsonx(arr) res -> ... res jsonx(arr) */ duk_pop(thr); DUK_ASSERT(duk_is_string(thr, -1)); } -#else /* DUK_USE_JSON_SUPPORT */ +#else /* DUK_USE_JSON_SUPPORT */ DUK_EXTERNAL void duk_push_context_dump(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */ #if defined(DUK_USE_DEBUGGER_SUPPORT) @@ -93,12 +92,13 @@ heap->dbg_exec_counter = 0; heap->dbg_last_counter = 0; heap->dbg_last_time = 0.0; - duk_debug_set_paused(heap); /* XXX: overlap with fields above */ + duk_debug_set_paused(heap); /* XXX: overlap with fields above */ /* Send version identification and flush right afterwards. Note that * we must write raw, unframed bytes here. */ - duk_push_sprintf(thr, "%ld %ld %s %s\n", + duk_push_sprintf(thr, + "%ld %ld %s %s\n", (long) DUK_DEBUG_PROTOCOL_VERSION, (long) DUK_VERSION, (const char *) DUK_GIT_DESCRIBE, @@ -200,7 +200,7 @@ } } -#else /* DUK_USE_DEBUGGER_SUPPORT */ +#else /* DUK_USE_DEBUGGER_SUPPORT */ DUK_EXTERNAL void duk_debugger_attach(duk_hthread *thr, duk_debug_read_function read_cb, @@ -258,4 +258,4 @@ DUK_UNREF(thr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_heap.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_heap.c
Changed
@@ -85,7 +85,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(state != NULL); /* unvalidated */ + DUK_ASSERT(state != NULL); /* unvalidated */ /* Currently not supported when called from within a finalizer. * If that is done, the finalizer will remain running indefinitely, @@ -129,7 +129,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(state != NULL); /* unvalidated */ + DUK_ASSERT(state != NULL); /* unvalidated */ /* Shouldn't be necessary if duk_suspend() is called before * duk_resume(), but assert in case API sequence is incorrect. @@ -171,7 +171,7 @@ DUK_UNREF(h_prev_glob); thr->builtinsDUK_BIDX_GLOBAL = h_glob; DUK_HOBJECT_INCREF(thr, h_glob); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_glob); /* side effects, in theory (referenced by global env) */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_glob); /* side effects, in theory (referenced by global env) */ /* * Replace lexical environment for global scope @@ -182,9 +182,7 @@ * same (initial) built-ins. */ - h_env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + h_env = duk_hobjenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(h_env != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_env) == NULL); @@ -199,8 +197,8 @@ h_prev_env = thr->builtinsDUK_BIDX_GLOBAL_ENV; thr->builtinsDUK_BIDX_GLOBAL_ENV = (duk_hobject *) h_env; DUK_HOBJECT_INCREF(thr, (duk_hobject *) h_env); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_env); /* side effects */ - DUK_UNREF(h_env); /* without refcounts */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_env); /* side effects */ + DUK_UNREF(h_env); /* without refcounts */ DUK_UNREF(h_prev_env); /* ... new_glob */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_inspect.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_inspect.c
Changed
@@ -39,20 +39,20 @@ * be security implications. */ -#define DUK__IDX_TYPE 0 -#define DUK__IDX_ITAG 1 -#define DUK__IDX_REFC 2 -#define DUK__IDX_HBYTES 3 -#define DUK__IDX_CLASS 4 -#define DUK__IDX_PBYTES 5 -#define DUK__IDX_ESIZE 6 -#define DUK__IDX_ENEXT 7 -#define DUK__IDX_ASIZE 8 -#define DUK__IDX_HSIZE 9 -#define DUK__IDX_BCBYTES 10 -#define DUK__IDX_DBYTES 11 -#define DUK__IDX_TSTATE 12 -#define DUK__IDX_VARIANT 13 +#define DUK__IDX_TYPE 0 +#define DUK__IDX_ITAG 1 +#define DUK__IDX_REFC 2 +#define DUK__IDX_HBYTES 3 +#define DUK__IDX_CLASS 4 +#define DUK__IDX_PBYTES 5 +#define DUK__IDX_ESIZE 6 +#define DUK__IDX_ENEXT 7 +#define DUK__IDX_ASIZE 8 +#define DUK__IDX_HSIZE 9 +#define DUK__IDX_BCBYTES 10 +#define DUK__IDX_DBYTES 11 +#define DUK__IDX_TSTATE 12 +#define DUK__IDX_VARIANT 13 DUK_EXTERNAL void duk_inspect_value(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; @@ -67,7 +67,7 @@ /* Assume two's complement and set everything to -1. */ duk_memset((void *) &vals, (int) 0xff, sizeof(vals)); - DUK_ASSERT(valsDUK__IDX_TYPE == -1); /* spot check one */ + DUK_ASSERT(valsDUK__IDX_TYPE == -1); /* spot check one */ tv = duk_get_tval_or_unused(thr, idx); h = (DUK_TVAL_IS_HEAP_ALLOCATED(tv) ? DUK_TVAL_GET_HEAPHDR(tv) : NULL); @@ -75,7 +75,7 @@ valsDUK__IDX_TYPE = duk_get_type_tval(tv); valsDUK__IDX_ITAG = (duk_int_t) DUK_TVAL_GET_TAG(tv); - duk_push_bare_object(thr); /* Invalidates 'tv'. */ + duk_push_bare_object(thr); /* Invalidates 'tv'. */ tv = NULL; if (h == NULL) { @@ -157,30 +157,56 @@ if (DUK_HBUFFER_HAS_DYNAMIC(h_buf)) { if (DUK_HBUFFER_HAS_EXTERNAL(h_buf)) { - valsDUK__IDX_VARIANT = 2; /* buffer variant 2: external */ + valsDUK__IDX_VARIANT = 2; /* buffer variant 2: external */ valsDUK__IDX_HBYTES = (duk_uint_t) (sizeof(duk_hbuffer_external)); } else { /* When alloc_size == 0 the second allocation may not * actually exist. */ - valsDUK__IDX_VARIANT = 1; /* buffer variant 1: dynamic */ + valsDUK__IDX_VARIANT = 1; /* buffer variant 1: dynamic */ valsDUK__IDX_HBYTES = (duk_uint_t) (sizeof(duk_hbuffer_dynamic)); } valsDUK__IDX_DBYTES = (duk_int_t) (DUK_HBUFFER_GET_SIZE(h_buf)); } else { - DUK_ASSERT(valsDUK__IDX_VARIANT == 0); /* buffer variant 0: fixed */ + DUK_ASSERT(valsDUK__IDX_VARIANT == 0); /* buffer variant 0: fixed */ valsDUK__IDX_HBYTES = (duk_int_t) (sizeof(duk_hbuffer_fixed) + DUK_HBUFFER_GET_SIZE(h_buf)); } break; } } - finish: +finish: duk__inspect_multiple_uint(thr, - "type" "\x00" "itag" "\x00" "refc" "\x00" "hbytes" "\x00" "class" "\x00" - "pbytes" "\x00" "esize" "\x00" "enext" "\x00" "asize" "\x00" "hsize" "\x00" - "bcbytes" "\x00" "dbytes" "\x00" "tstate" "\x00" "variant" "\x00" "\x00", - (duk_int_t *) &vals); + "type" + "\x00" + "itag" + "\x00" + "refc" + "\x00" + "hbytes" + "\x00" + "class" + "\x00" + "pbytes" + "\x00" + "esize" + "\x00" + "enext" + "\x00" + "asize" + "\x00" + "hsize" + "\x00" + "bcbytes" + "\x00" + "dbytes" + "\x00" + "tstate" + "\x00" + "variant" + "\x00" + "\x00", + (duk_int_t *) &vals); } DUK_EXTERNAL void duk_inspect_callstack_entry(duk_hthread *thr, duk_int_t level) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_internal.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_internal.h
Changed
@@ -12,9 +12,9 @@ #define DUK_ALWAYS_INLINE_PERF #define DUK_NOINLINE_PERF #else -#define DUK_INLINE_PERF DUK_INLINE +#define DUK_INLINE_PERF DUK_INLINE #define DUK_ALWAYS_INLINE_PERF DUK_ALWAYS_INLINE -#define DUK_NOINLINE_PERF DUK_NOINLINE +#define DUK_NOINLINE_PERF DUK_NOINLINE #endif /* Inline macro helpers, for bytecode executor. */ @@ -23,19 +23,19 @@ #define DUK_EXEC_ALWAYS_INLINE_PERF #define DUK_EXEC_NOINLINE_PERF #else -#define DUK_EXEC_INLINE_PERF DUK_INLINE +#define DUK_EXEC_INLINE_PERF DUK_INLINE #define DUK_EXEC_ALWAYS_INLINE_PERF DUK_ALWAYS_INLINE -#define DUK_EXEC_NOINLINE_PERF DUK_NOINLINE +#define DUK_EXEC_NOINLINE_PERF DUK_NOINLINE #endif /* duk_push_sprintf constants */ -#define DUK_PUSH_SPRINTF_INITIAL_SIZE 256L -#define DUK_PUSH_SPRINTF_SANITY_LIMIT (1L * 1024L * 1024L * 1024L) +#define DUK_PUSH_SPRINTF_INITIAL_SIZE 256L +#define DUK_PUSH_SPRINTF_SANITY_LIMIT (1L * 1024L * 1024L * 1024L) /* Flag ORed to err_code to indicate __FILE__ / __LINE__ is not * blamed as source of error for error fileName / lineNumber. */ -#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE (1L << 24) +#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE (1L << 24) /* Current convention is to use duk_size_t for value stack sizes and global indices, * and duk_idx_t for local frame indices. @@ -97,24 +97,17 @@ DUK_INTERNAL_DECL duk_tval *duk_get_borrowed_this_tval(duk_hthread *thr); /* XXX: add fastint support? */ -#define duk_push_u64(thr,val) \ - duk_push_number((thr), (duk_double_t) (val)) -#define duk_push_i64(thr,val) \ - duk_push_number((thr), (duk_double_t) (val)) +#define duk_push_u64(thr, val) duk_push_number((thr), (duk_double_t) (val)) +#define duk_push_i64(thr, val) duk_push_number((thr), (duk_double_t) (val)) /* duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range */ -#define duk_push_u32(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) -#define duk_push_i32(thr,val) \ - duk_push_int((thr), (duk_int_t) (val)) +#define duk_push_u32(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) +#define duk_push_i32(thr, val) duk_push_int((thr), (duk_int_t) (val)) /* sometimes stack and array indices need to go on the stack */ -#define duk_push_idx(thr,val) \ - duk_push_int((thr), (duk_int_t) (val)) -#define duk_push_uarridx(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) -#define duk_push_size_t(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) /* XXX: assumed to fit for now */ +#define duk_push_idx(thr, val) duk_push_int((thr), (duk_int_t) (val)) +#define duk_push_uarridx(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) +#define duk_push_size_t(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) /* XXX: assumed to fit for now */ DUK_INTERNAL_DECL duk_bool_t duk_is_string_notsymbol(duk_hthread *thr, duk_idx_t idx); @@ -131,19 +124,23 @@ DUK_INTERNAL_DECL duk_hcompfunc *duk_get_hcompfunc(duk_hthread *thr, duk_idx_t idx); DUK_INTERNAL_DECL duk_hnatfunc *duk_get_hnatfunc(duk_hthread *thr, duk_idx_t idx); -DUK_INTERNAL_DECL void *duk_get_buffer_data_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len, duk_bool_t throw_flag, duk_bool_t *out_isbuffer); +DUK_INTERNAL_DECL void *duk_get_buffer_data_raw(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_len, + duk_bool_t throw_flag, + duk_bool_t *out_isbuffer); DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_with_class(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t classnum); DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_accept_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); -#define duk_require_hobject_promote_lfunc(thr,idx) \ - duk_require_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) -#define duk_get_hobject_promote_lfunc(thr,idx) \ - duk_get_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) +#define duk_require_hobject_promote_lfunc(thr, idx) duk_require_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) +#define duk_get_hobject_promote_lfunc(thr, idx) duk_get_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL void *duk_get_voidptr(duk_hthread *thr, duk_idx_t idx); #endif @@ -166,12 +163,16 @@ DUK_INTERNAL_DECL duk_bool_t duk_to_boolean_top_pop(duk_hthread *thr); -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ DUK_INTERNAL_DECL duk_hstring *duk_safe_to_hstring(duk_hthread *thr, duk_idx_t idx); #endif DUK_INTERNAL_DECL void duk_push_class_string_tval(duk_hthread *thr, duk_tval *tv, duk_bool_t avoid_side_effects); -DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped); /* out_clamped=NULL, RangeError if outside range */ +DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, + duk_idx_t idx, + duk_int_t minval, + duk_int_t maxval, + duk_bool_t *out_clamped); /* out_clamped=NULL, RangeError if outside range */ DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval); DUK_INTERNAL_DECL duk_int_t duk_to_int_check_range(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -196,13 +197,15 @@ DUK_INTERNAL_DECL void duk_push_hstring_empty(duk_hthread *thr); DUK_INTERNAL_DECL void duk_push_hobject(duk_hthread *thr, duk_hobject *h); DUK_INTERNAL_DECL void duk_push_hbuffer(duk_hthread *thr, duk_hbuffer *h); -#define duk_push_hthread(thr,h) \ - duk_push_hobject((thr), (duk_hobject *) (h)) -#define duk_push_hnatfunc(thr,h) \ - duk_push_hobject((thr), (duk_hobject *) (h)) +#define duk_push_hthread(thr, h) duk_push_hobject((thr), (duk_hobject *) (h)) +#define duk_push_hnatfunc(thr, h) duk_push_hobject((thr), (duk_hobject *) (h)) DUK_INTERNAL_DECL void duk_push_hobject_bidx(duk_hthread *thr, duk_small_int_t builtin_idx); -DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx); -DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper_proto(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_hobject *proto); +DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx); +DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper_proto(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_hobject *proto); DUK_INTERNAL_DECL duk_hcompfunc *duk_push_hcompfunc(duk_hthread *thr); DUK_INTERNAL_DECL duk_hboundfunc *duk_push_hboundfunc(duk_hthread *thr); DUK_INTERNAL_DECL void duk_push_c_function_builtin(duk_hthread *thr, duk_c_function func, duk_int_t nargs); @@ -219,11 +222,13 @@ DUK_INTERNAL_DECL void duk_push_lightfunc_name_raw(duk_hthread *thr, duk_c_function func, duk_small_uint_t lf_flags); DUK_INTERNAL_DECL void duk_push_lightfunc_name(duk_hthread *thr, duk_tval *tv); DUK_INTERNAL_DECL void duk_push_lightfunc_tostring(duk_hthread *thr, duk_tval *tv); -#if 0 /* not used yet */ +#if 0 /* not used yet */ DUK_INTERNAL_DECL void duk_push_hnatfunc_name(duk_hthread *thr, duk_hnatfunc *h); #endif #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_INTERNAL_DECL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx); +DUK_INTERNAL_DECL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx); #endif DUK_INTERNAL_DECL void *duk_push_fixed_buffer_nozero(duk_hthread *thr, duk_size_t len); @@ -240,80 +245,86 @@ * arguments and such call sites are also easiest to verify to be correct. */ -DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> val */ +DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> val */ DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_get_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_get_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_get_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop); /* -> */ +DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_bool_t *out_has_prop); /* -> */ DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop(duk_hthread *thr, duk_idx_t obj_idx); DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_xget_owndataprop_stridx_short(thr,obj_idx,stridx) \ +#define duk_xget_owndataprop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_xget_owndataprop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* val -> */ +DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* val -> */ DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_put_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_put_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_put_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ -#if 0 /* Too few call sites to be useful. */ +DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +#if 0 /* Too few call sites to be useful. */ DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_del_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_del_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((obj_idx) >= -0x8000L && (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((stridx) >= 0 && (stridx) <= 0xffffL), \ duk_del_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) #endif -#define duk_del_prop_stridx_short(thr,obj_idx,stridx) \ - duk_del_prop_stridx((thr), (obj_idx), (stridx)) +#define duk_del_prop_stridx_short(thr, obj_idx, stridx) duk_del_prop_stridx((thr), (obj_idx), (stridx)) -DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ -#if 0 /* Too few call sites to be useful. */ +DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +#if 0 /* Too few call sites to be useful. */ DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_has_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_has_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((obj_idx) >= -0x8000L && (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((stridx) >= 0 && (stridx) <= 0xffffL), \ duk_has_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) #endif -#define duk_has_prop_stridx_short(thr,obj_idx,stridx) \ - duk_has_prop_stridx((thr), (obj_idx), (stridx)) +#define duk_has_prop_stridx_short(thr, obj_idx, stridx) duk_has_prop_stridx((thr), (obj_idx), (stridx)) -DUK_INTERNAL_DECL void duk_xdef_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t desc_flags); /* key val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t desc_flags); /* key val -> */ -DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags); /* val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_hthread *thr, + duk_idx_t obj_idx, + duk_uarridx_t arr_idx, + duk_small_uint_t desc_flags); /* val -> */ /* XXX: Because stridx and desc_flags have a limited range, this call could * always pack stridx and desc_flags into a single argument. */ -DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_uint_t desc_flags); /* val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_small_uint_t desc_flags); /* val -> */ DUK_INTERNAL_DECL void duk_xdef_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_xdef_prop_stridx_short(thr,obj_idx,stridx,desc_flags) \ +#define duk_xdef_prop_stridx_short(thr, obj_idx, stridx, desc_flags) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x80L && (duk_int_t) (obj_idx) <= 0x7fL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ DUK_ASSERT_EXPR((duk_int_t) (desc_flags) >= 0 && (duk_int_t) (desc_flags) <= 0xffL), \ - duk_xdef_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 24) + (((duk_uint_t) (stridx)) << 8) + (duk_uint_t) (desc_flags))) - -#define duk_xdef_prop_wec(thr,obj_idx) \ - duk_xdef_prop((thr), (obj_idx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_index_wec(thr,obj_idx,arr_idx) \ - duk_xdef_prop_index((thr), (obj_idx), (arr_idx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_stridx_wec(thr,obj_idx,stridx) \ - duk_xdef_prop_stridx((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_stridx_short_wec(thr,obj_idx,stridx) \ + duk_xdef_prop_stridx_short_raw((thr), \ + (((duk_uint_t) (obj_idx)) << 24) + (((duk_uint_t) (stridx)) << 8) + \ + (duk_uint_t) (desc_flags))) + +#define duk_xdef_prop_wec(thr, obj_idx) duk_xdef_prop((thr), (obj_idx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_index_wec(thr, obj_idx, arr_idx) duk_xdef_prop_index((thr), (obj_idx), (arr_idx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_stridx_wec(thr, obj_idx, stridx) duk_xdef_prop_stridx((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_stridx_short_wec(thr, obj_idx, stridx) \ duk_xdef_prop_stridx_short((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL void duk_xdef_prop_stridx_builtin(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags); /* -> */ #endif -DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ DUK_INTERNAL_DECL duk_bool_t duk_get_method_stridx(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t stridx); @@ -362,25 +373,21 @@ * using these macro results in faster and smaller code than duk_get_tval(). * Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts. */ -#define DUK_ASSERT_VALID_NEGIDX(thr,idx) \ +#define DUK_ASSERT_VALID_NEGIDX(thr, idx) \ (DUK_ASSERT_EXPR((duk_int_t) (idx) < 0), DUK_ASSERT_EXPR(duk_is_valid_index((thr), (idx)))) -#define DUK_ASSERT_VALID_POSIDX(thr,idx) \ +#define DUK_ASSERT_VALID_POSIDX(thr, idx) \ (DUK_ASSERT_EXPR((duk_int_t) (idx) >= 0), DUK_ASSERT_EXPR(duk_is_valid_index((thr), (idx)))) -#define DUK_GET_TVAL_NEGIDX(thr,idx) \ - (DUK_ASSERT_VALID_NEGIDX((thr),(idx)), ((duk_hthread *) (thr))->valstack_top + (idx)) -#define DUK_GET_TVAL_POSIDX(thr,idx) \ - (DUK_ASSERT_VALID_POSIDX((thr),(idx)), ((duk_hthread *) (thr))->valstack_bottom + (idx)) -#define DUK_GET_HOBJECT_NEGIDX(thr,idx) \ - (DUK_ASSERT_VALID_NEGIDX((thr),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_top + (idx))) -#define DUK_GET_HOBJECT_POSIDX(thr,idx) \ - (DUK_ASSERT_VALID_POSIDX((thr),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_bottom + (idx))) - -#define DUK_GET_THIS_TVAL_PTR(thr) \ - (DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), \ - (thr)->valstack_bottom - 1) +#define DUK_GET_TVAL_NEGIDX(thr, idx) (DUK_ASSERT_VALID_NEGIDX((thr), (idx)), ((duk_hthread *) (thr))->valstack_top + (idx)) +#define DUK_GET_TVAL_POSIDX(thr, idx) (DUK_ASSERT_VALID_POSIDX((thr), (idx)), ((duk_hthread *) (thr))->valstack_bottom + (idx)) +#define DUK_GET_HOBJECT_NEGIDX(thr, idx) \ + (DUK_ASSERT_VALID_NEGIDX((thr), (idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_top + (idx))) +#define DUK_GET_HOBJECT_POSIDX(thr, idx) \ + (DUK_ASSERT_VALID_POSIDX((thr), (idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_bottom + (idx))) + +#define DUK_GET_THIS_TVAL_PTR(thr) (DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), (thr)->valstack_bottom - 1) DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time(duk_hthread *thr); DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time_nofrac(duk_hthread *thr); DUK_INTERNAL_DECL duk_double_t duk_time_get_monotonic_time(duk_hthread *thr); -#endif /* DUK_API_INTERNAL_H_INCLUDED */ +#endif /* DUK_API_INTERNAL_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_memory.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_memory.c
Changed
@@ -74,7 +74,7 @@ DUK_ASSERT(heap != NULL); DUK_D(DUK_DPRINT("mark-and-sweep requested by application")); - DUK_ASSERT(DUK_GC_COMPACT == DUK_MS_FLAG_EMERGENCY); /* Compact flag is 1:1 with emergency flag which forces compaction. */ + DUK_ASSERT(DUK_GC_COMPACT == DUK_MS_FLAG_EMERGENCY); /* Compact flag is 1:1 with emergency flag which forces compaction. */ ms_flags = (duk_small_uint_t) flags; duk_heap_mark_and_sweep(heap, ms_flags); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_object.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_object.c
Changed
@@ -30,9 +30,9 @@ DUK_ASSERT(rc == 0 || rc == 1); /* a value is left on stack regardless of rc */ - duk_remove_m2(thr); /* remove key */ + duk_remove_m2(thr); /* remove key */ DUK_ASSERT(duk_is_undefined(thr, -1) || rc == 1); - return rc; /* 1 if property found, 0 otherwise */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_get_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) { @@ -77,7 +77,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_get_prop(thr, obj_idx); } @@ -91,11 +91,13 @@ } DUK_INTERNAL duk_bool_t duk_get_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_get_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), - (duk_small_uint_t) (packed_args & 0xffffUL)); + return duk_get_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } -DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop) { +DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_bool_t *out_has_prop) { duk_bool_t rc; DUK_ASSERT_API_ENTRY(thr); @@ -140,7 +142,7 @@ } duk_push_tval(thr, tv_val); - duk_remove_m2(thr); /* remove key */ + duk_remove_m2(thr); /* remove key */ return 1; } @@ -155,7 +157,8 @@ } DUK_INTERNAL duk_bool_t duk_xget_owndataprop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_xget_owndataprop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), + return duk_xget_owndataprop_stridx(thr, + (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } @@ -174,8 +177,7 @@ /* Key and value indices are either (-2, -1) or (-1, -2). Given idx_key, * idx_val is always (idx_key ^ 0x01). */ - DUK_ASSERT((idx_key == -2 && (idx_key ^ 1) == -1) || - (idx_key == -1 && (idx_key ^ 1) == -2)); + DUK_ASSERT((idx_key == -2 && (idx_key ^ 1) == -1) || (idx_key == -1 && (idx_key ^ 1) == -2)); /* XXX: Direct access; faster validation. */ tv_obj = duk_require_tval(thr, obj_idx); tv_key = duk_require_tval(thr, idx_key); @@ -185,8 +187,8 @@ rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, throw_flag); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop_2(thr); /* remove key and value */ - return rc; /* 1 if property found, 0 otherwise */ + duk_pop_2(thr); /* remove key and value */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_put_prop(duk_hthread *thr, duk_idx_t obj_idx) { @@ -240,11 +242,10 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk__put_prop_shared(thr, obj_idx, -1); } - DUK_INTERNAL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT_STRIDX_VALID(stridx); @@ -255,8 +256,7 @@ } DUK_INTERNAL duk_bool_t duk_put_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_put_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), - (duk_small_uint_t) (packed_args & 0xffffUL)); + return duk_put_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } DUK_EXTERNAL duk_bool_t duk_del_prop(duk_hthread *thr, duk_idx_t obj_idx) { @@ -278,7 +278,7 @@ rc = duk_hobject_delprop(thr, tv_obj, tv_key, throw_flag); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop(thr); /* remove key */ + duk_pop(thr); /* remove key */ return rc; } @@ -324,7 +324,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_del_prop(thr, obj_idx); } @@ -361,8 +361,8 @@ rc = duk_hobject_hasprop(thr, tv_obj, tv_key); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop(thr); /* remove key */ - return rc; /* 1 if property found, 0 otherwise */ + duk_pop(thr); /* remove key */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_has_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) { @@ -407,7 +407,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_has_prop(thr, obj_idx); } @@ -446,7 +446,7 @@ duk_hobject_define_property_internal(thr, obj, key, desc_flags); - duk_pop(thr); /* pop key */ + duk_pop(thr); /* pop key */ } DUK_INTERNAL void duk_xdef_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags) { @@ -479,12 +479,13 @@ } DUK_INTERNAL void duk_xdef_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - duk_xdef_prop_stridx(thr, (duk_idx_t) (duk_int8_t) (packed_args >> 24), - (duk_small_uint_t) (packed_args >> 8) & 0xffffUL, - (duk_small_uint_t) (packed_args & 0xffL)); + duk_xdef_prop_stridx(thr, + (duk_idx_t) (duk_int8_t) (packed_args >> 24), + (duk_small_uint_t) (packed_args >> 8) & 0xffffUL, + (duk_small_uint_t) (packed_args & 0xffL)); } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL void duk_xdef_prop_stridx_builtin(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags) { duk_hobject *obj; duk_hstring *key; @@ -516,15 +517,15 @@ duk_push_hstring_stridx(thr, stridx); duk_push_hobject_bidx(thr, DUK_BIDX_TYPE_ERROR_THROWER); duk_dup_top(thr); - duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE); /* attributes always 0 */ + duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE); /* attributes always 0 */ } /* Object.getOwnPropertyDescriptor() equivalent C binding. */ DUK_EXTERNAL void duk_get_prop_desc(duk_hthread *thr, duk_idx_t obj_idx, duk_uint_t flags) { DUK_ASSERT_API_ENTRY(thr); - DUK_UNREF(flags); /* no flags defined yet */ + DUK_UNREF(flags); /* no flags defined yet */ - duk_hobject_object_get_own_property_descriptor(thr, obj_idx); /* ... key -> ... desc */ + duk_hobject_object_get_own_property_descriptor(thr, obj_idx); /* ... key -> ... desc */ } /* Object.defineProperty() equivalent C binding. */ @@ -554,9 +555,7 @@ idx_base = duk_get_top_index(thr); if (flags & DUK_DEFPROP_HAVE_SETTER) { - duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC); + duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC); set = duk_get_hobject_promote_lfunc(thr, idx_base); if (set != NULL && !DUK_HOBJECT_IS_CALLABLE(set)) { goto fail_not_callable; @@ -566,9 +565,7 @@ set = NULL; } if (flags & DUK_DEFPROP_HAVE_GETTER) { - duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC); + duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC); get = duk_get_hobject_promote_lfunc(thr, idx_base); if (get != NULL && !DUK_HOBJECT_IS_CALLABLE(get)) { goto fail_not_callable; @@ -588,14 +585,7 @@ duk_require_valid_index(thr, idx_base); - duk_hobject_define_property_helper(thr, - flags /*defprop_flags*/, - obj, - key, - idx_value, - get, - set, - 1 /*throw_flag*/); + duk_hobject_define_property_helper(thr, flags /*defprop_flags*/, obj, key, idx_value, get, set, 1 /*throw_flag*/); /* Clean up stack */ @@ -605,11 +595,11 @@ return; - fail_invalid_desc: +fail_invalid_desc: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_DESCRIPTOR); DUK_WO_NORETURN(return;); - fail_not_callable: +fail_not_callable: DUK_ERROR_TYPE(thr, DUK_STR_NOT_CALLABLE); DUK_WO_NORETURN(return;); } @@ -643,7 +633,7 @@ duk_dup(thr, obj_idx); duk_require_hobject_promote_mask(thr, -1, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); - duk_hobject_enumerator_create(thr, enum_flags); /* target -> enum */ + duk_hobject_enumerator_create(thr, enum_flags); /* target -> enum */ } DUK_EXTERNAL duk_bool_t duk_next(duk_hthread *thr, duk_idx_t enum_index, duk_bool_t get_value) { @@ -704,8 +694,8 @@ } return; - fail_cannot_freeze: - DUK_ERROR_TYPE_INVALID_ARGS(thr); /* XXX: proper error message */ +fail_cannot_freeze: + DUK_ERROR_TYPE_INVALID_ARGS(thr); /* XXX: proper error message */ DUK_WO_NORETURN(return;); } @@ -750,8 +740,8 @@ if (ent != NULL) { while (ent->key != NULL) { tv = thr->valstack_top++; - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv)); /* value stack init policy */ - DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, ent->value); /* no need for decref/incref */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv)); /* value stack init policy */ + DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, ent->value); /* no need for decref/incref */ duk_put_prop_string(thr, obj_idx, ent->key); ent++; } @@ -821,7 +811,6 @@ return ret; } - DUK_EXTERNAL duk_bool_t duk_put_global_string(duk_hthread *thr, const char *key) { duk_bool_t ret; @@ -832,7 +821,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_string(thr, -2, key); /* ... global val -> ... global */ + ret = duk_put_prop_string(thr, -2, key); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -847,7 +836,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_lstring(thr, -2, key, key_len); /* ... global val -> ... global */ + ret = duk_put_prop_lstring(thr, -2, key, key_len); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -864,7 +853,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_literal_raw(thr, -2, key, key_len); /* ... global val -> ... global */ + ret = duk_put_prop_literal_raw(thr, -2, key, key_len); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -880,7 +869,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_heapptr(thr, -2, ptr); /* ... global val -> ... global */ + ret = duk_put_prop_heapptr(thr, -2, ptr); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -932,14 +921,13 @@ obj = duk_require_hobject(thr, idx); DUK_ASSERT(obj != NULL); - duk_require_type_mask(thr, -1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT); + duk_require_type_mask(thr, -1, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT); proto = duk_get_hobject(thr, -1); /* proto can also be NULL here (allowed explicitly) */ #if defined(DUK_USE_ROM_OBJECTS) if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)) { - DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ + DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ DUK_WO_NORETURN(return;); } #endif @@ -959,7 +947,7 @@ #if defined(DUK_USE_ROM_OBJECTS) if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)) { - DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ + DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ DUK_WO_NORETURN(return;); } #endif @@ -1006,7 +994,7 @@ DUK_ASSERT_API_ENTRY(thr); - h = duk_require_hobject(thr, idx); /* Get before 'put' so that 'idx' is correct. */ + h = duk_require_hobject(thr, idx); /* Get before 'put' so that 'idx' is correct. */ callable = duk_is_callable(thr, -1); /* At present finalizer is stored as a hidden Symbol, with normal @@ -1033,7 +1021,7 @@ DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h); } } -#else /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ DUK_EXTERNAL void duk_get_finalizer(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx); @@ -1047,4 +1035,4 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_random.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_random.c
Changed
@@ -5,5 +5,5 @@ #include "duk_internal.h" DUK_EXTERNAL duk_double_t duk_random(duk_hthread *thr) { - return (duk_double_t) DUK_UTIL_GET_RANDOM_DOUBLE(thr); + return (duk_double_t) duk_util_get_random_double(thr); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_stack.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_stack.c
Changed
@@ -16,7 +16,8 @@ * Forward declarations */ -DUK_LOCAL_DECL duk_idx_t duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx); +DUK_LOCAL_DECL duk_idx_t +duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx); /* * Global state for working around missing variadic macros @@ -31,41 +32,24 @@ * Misc helpers */ -DUK_LOCAL const char * const duk__symbol_type_strings4 = { - "hidden", "global", "local", "wellknown" -}; +DUK_LOCAL const char * const duk__symbol_type_strings4 = { "hidden", "global", "local", "wellknown" }; #if !defined(DUK_USE_PACKED_TVAL) DUK_LOCAL const duk_uint_t duk__type_from_tag = { - DUK_TYPE_NUMBER, - DUK_TYPE_NUMBER, /* fastint */ - DUK_TYPE_UNDEFINED, - DUK_TYPE_NULL, - DUK_TYPE_BOOLEAN, - DUK_TYPE_POINTER, - DUK_TYPE_LIGHTFUNC, - DUK_TYPE_NONE, - DUK_TYPE_STRING, - DUK_TYPE_OBJECT, - DUK_TYPE_BUFFER, + DUK_TYPE_NUMBER, DUK_TYPE_NUMBER, /* fastint */ + DUK_TYPE_UNDEFINED, DUK_TYPE_NULL, DUK_TYPE_BOOLEAN, DUK_TYPE_POINTER, DUK_TYPE_LIGHTFUNC, + DUK_TYPE_NONE, DUK_TYPE_STRING, DUK_TYPE_OBJECT, DUK_TYPE_BUFFER, }; DUK_LOCAL const duk_uint_t duk__type_mask_from_tag = { - DUK_TYPE_MASK_NUMBER, - DUK_TYPE_MASK_NUMBER, /* fastint */ - DUK_TYPE_MASK_UNDEFINED, - DUK_TYPE_MASK_NULL, - DUK_TYPE_MASK_BOOLEAN, - DUK_TYPE_MASK_POINTER, - DUK_TYPE_MASK_LIGHTFUNC, - DUK_TYPE_MASK_NONE, - DUK_TYPE_MASK_STRING, - DUK_TYPE_MASK_OBJECT, - DUK_TYPE_MASK_BUFFER, + DUK_TYPE_MASK_NUMBER, DUK_TYPE_MASK_NUMBER, /* fastint */ + DUK_TYPE_MASK_UNDEFINED, DUK_TYPE_MASK_NULL, DUK_TYPE_MASK_BOOLEAN, DUK_TYPE_MASK_POINTER, DUK_TYPE_MASK_LIGHTFUNC, + DUK_TYPE_MASK_NONE, DUK_TYPE_MASK_STRING, DUK_TYPE_MASK_OBJECT, DUK_TYPE_MASK_BUFFER, }; -#endif /* !DUK_USE_PACKED_TVAL */ +#endif /* !DUK_USE_PACKED_TVAL */ /* Assert that there's room for one value. */ -#define DUK__ASSERT_SPACE() do { \ +#define DUK__ASSERT_SPACE() \ + do { \ DUK_ASSERT(!(thr->valstack_top >= thr->valstack_end)); \ } while (0) @@ -74,7 +58,8 @@ /* Faster but value stack overruns are memory unsafe. */ #define DUK__CHECK_SPACE() DUK__ASSERT_SPACE() #else -#define DUK__CHECK_SPACE() do { \ +#define DUK__CHECK_SPACE() \ + do { \ if (DUK_UNLIKELY(thr->valstack_top >= thr->valstack_end)) { \ DUK_ERROR_RANGE_PUSH_BEYOND(thr); \ } \ @@ -87,7 +72,7 @@ DUK_ASSERT(h != NULL); DUK_ASSERT(DUK_HSTRING_HAS_SYMBOL(h)); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h) >= 1); /* always true, symbol prefix */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h) >= 1); /* always true, symbol prefix */ data = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h); len = DUK_HSTRING_GET_BYTELEN(h); @@ -254,7 +239,7 @@ /* Assume value stack sizes (in elements) fits into duk_idx_t. */ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -282,7 +267,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -310,7 +295,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -357,7 +342,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ /* Use unsigned arithmetic to optimize comparison. */ if (idx < 0) { @@ -496,7 +481,7 @@ DUK_ASSERT(count > 0); tv = thr->valstack_top; tv_end = tv - count; - DUK_ASSERT(tv > tv_end); /* Because count > 0. */ + DUK_ASSERT(tv > tv_end); /* Because count > 0. */ do { tv--; DUK_ASSERT(tv >= thr->valstack_bottom); @@ -504,7 +489,7 @@ } while (tv != tv_end); thr->valstack_top = tv_end; DUK_REFZERO_CHECK_FAST(thr); -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ duk_uidx_t count; duk_tval *tv_end; @@ -517,7 +502,7 @@ DUK_TVAL_SET_UNDEFINED(tv); } while (tv != tv_end); thr->valstack_top = tv_end; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ } } @@ -528,7 +513,7 @@ duk_set_top(thr, idx); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_set_top_unsafe(duk_hthread *thr, duk_idx_t idx) { duk_uidx_t uidx; duk_uidx_t vs_size; @@ -567,7 +552,7 @@ DUK_ASSERT(count > 0); tv = thr->valstack_top; tv_end = tv - count; - DUK_ASSERT(tv > tv_end); /* Because count > 0. */ + DUK_ASSERT(tv > tv_end); /* Because count > 0. */ do { tv--; DUK_ASSERT(tv >= thr->valstack_bottom); @@ -575,7 +560,7 @@ } while (tv != tv_end); thr->valstack_top = tv_end; DUK_REFZERO_CHECK_FAST(thr); -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ duk_uidx_t count; duk_tval *tv_end; @@ -588,10 +573,10 @@ DUK_TVAL_SET_UNDEFINED(tv); } while (tv != tv_end); thr->valstack_top = tv_end; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ } } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Internal helper: set top to 'top', and set idx_wipe_start,top to * 'undefined' (doing nothing if idx_wipe_start == top). Indices are @@ -691,9 +676,9 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); DUK_ASSERT(thr->valstack_end >= thr->valstack_top); DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end); - DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size); /* can't resize below 'top' */ - DUK_ASSERT(new_size <= DUK_USE_VALSTACK_LIMIT); /* valstack limit caller has check, prevents wrapping */ - DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval)); /* specific assert for wrapping */ + DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size); /* can't resize below 'top' */ + DUK_ASSERT(new_size <= DUK_USE_VALSTACK_LIMIT); /* valstack limit caller has check, prevents wrapping */ + DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval)); /* specific assert for wrapping */ /* Pre-realloc pointer copies for asserts and debug logs. */ pre_valstack = thr->valstack; @@ -728,7 +713,8 @@ */ DUK_ASSERT(new_size != 0); DUK_D(DUK_DPRINT("failed to resize valstack to %lu entries (%lu bytes)", - (unsigned long) new_size, (unsigned long) new_alloc_size)); + (unsigned long) new_size, + (unsigned long) new_alloc_size)); return 0; } @@ -739,23 +725,28 @@ #if defined(DUK_USE_DEBUG) if (thr->valstack != pre_valstack) { DUK_D(DUK_DPRINT("valstack base pointer changed during valstack resize: %p -> %p", - (void *) pre_valstack, (void *) thr->valstack)); + (void *) pre_valstack, + (void *) thr->valstack)); } if (thr->valstack_bottom != pre_bottom) { DUK_D(DUK_DPRINT("valstack bottom pointer changed during valstack resize: %p -> %p", - (void *) pre_bottom, (void *) thr->valstack_bottom)); + (void *) pre_bottom, + (void *) thr->valstack_bottom)); } if (thr->valstack_top != pre_top) { DUK_D(DUK_DPRINT("valstack top pointer changed during valstack resize: %p -> %p", - (void *) pre_top, (void *) thr->valstack_top)); + (void *) pre_top, + (void *) thr->valstack_top)); } if (thr->valstack_end != pre_end) { DUK_D(DUK_DPRINT("valstack end pointer changed during valstack resize: %p -> %p", - (void *) pre_end, (void *) thr->valstack_end)); + (void *) pre_end, + (void *) thr->valstack_end)); } if (thr->valstack_alloc_end != pre_alloc_end) { DUK_D(DUK_DPRINT("valstack alloc_end pointer changed during valstack resize: %p -> %p", - (void *) pre_alloc_end, (void *) thr->valstack_alloc_end)); + (void *) pre_alloc_end, + (void *) thr->valstack_alloc_end)); } #endif @@ -794,12 +785,22 @@ (unsigned long) new_size, (unsigned long) ((duk_uint8_t *) pre_alloc_end - (duk_uint8_t *) pre_valstack), (unsigned long) new_alloc_size, - (void *) pre_valstack, (void *) thr->valstack, - (void *) pre_bottom, (void *) thr->valstack_bottom, (long) (thr->valstack_bottom - thr->valstack), - (void *) pre_top, (void *) thr->valstack_top, (long) (thr->valstack_top - thr->valstack), - (void *) pre_end, (void *) thr->valstack_end, (long) (thr->valstack_end - thr->valstack), - (void *) pre_alloc_end, (void *) thr->valstack_alloc_end, (long) (thr->valstack_alloc_end - thr->valstack), - (void *) tv_prev_alloc_end, (long) (thr->valstack_alloc_end - tv_prev_alloc_end))); + (void *) pre_valstack, + (void *) thr->valstack, + (void *) pre_bottom, + (void *) thr->valstack_bottom, + (long) (thr->valstack_bottom - thr->valstack), + (void *) pre_top, + (void *) thr->valstack_top, + (long) (thr->valstack_top - thr->valstack), + (void *) pre_end, + (void *) thr->valstack_end, + (long) (thr->valstack_end - thr->valstack), + (void *) pre_alloc_end, + (void *) thr->valstack_alloc_end, + (long) (thr->valstack_alloc_end - thr->valstack), + (void *) tv_prev_alloc_end, + (long) (thr->valstack_alloc_end - tv_prev_alloc_end))); /* If allocation grew, init any new slots to 'undefined'. */ p = tv_prev_alloc_end; @@ -826,7 +827,7 @@ duk_size_t new_size; DUK_ASSERT(min_bytes / sizeof(duk_tval) * sizeof(duk_tval) == min_bytes); - min_size = min_bytes / sizeof(duk_tval); /* from bytes to slots */ + min_size = min_bytes / sizeof(duk_tval); /* from bytes to slots */ #if defined(DUK_USE_VALSTACK_GROW_SHIFT) /* New size is minimum size plus a proportional slack, e.g. shift of @@ -943,17 +944,18 @@ #else slack = 0; #endif - shrink_bytes = reserve_bytes + - slack / sizeof(duk_tval) * sizeof(duk_tval); /* multiple of duk_tval */ + shrink_bytes = reserve_bytes + slack / sizeof(duk_tval) * sizeof(duk_tval); /* multiple of duk_tval */ } -#else /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ +#else /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ /* Always snug, useful in some low memory environments. */ DUK_UNREF(snug); shrink_bytes = reserve_bytes; -#endif /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ +#endif /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ DUK_D(DUK_DPRINT("valstack shrink check: alloc_bytes=%ld, reserve_bytes=%ld, shrink_bytes=%ld (unvalidated)", - (long) alloc_bytes, (long) reserve_bytes, (long) shrink_bytes)); + (long) alloc_bytes, + (long) reserve_bytes, + (long) shrink_bytes)); DUK_ASSERT(shrink_bytes >= reserve_bytes); if (shrink_bytes >= alloc_bytes) { /* Skip if shrink target is same as current one (or higher, @@ -1100,7 +1102,7 @@ DUK_ASSERT(tv_from != NULL); DUK_ASSERT(tv_to != NULL); DUK_TVAL_SET_TVAL(tv_to, tv_from); - DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ + DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ } DUK_EXTERNAL void duk_dup_top(duk_hthread *thr) { @@ -1122,7 +1124,7 @@ DUK_ASSERT(tv_from != NULL); DUK_ASSERT(tv_to != NULL); DUK_TVAL_SET_TVAL(tv_to, tv_from); - DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ + DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ #endif } @@ -1175,7 +1177,10 @@ nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); DUK_DDD(DUK_DDDPRINT("duk_insert: to_idx=%ld, p=%p, q=%p, nbytes=%lu", - (long) to_idx, (void *) p, (void *) q, (unsigned long) nbytes)); + (long) to_idx, + (void *) p, + (void *) q, + (unsigned long) nbytes)); /* No net refcount changes. No need to special case nbytes == 0 * (p == q). @@ -1187,7 +1192,7 @@ DUK_INTERNAL void duk_insert_undefined(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(idx >= 0); /* Doesn't support negative indices. */ + DUK_ASSERT(idx >= 0); /* Doesn't support negative indices. */ duk_push_undefined(thr); duk_insert(thr, idx); @@ -1197,7 +1202,7 @@ duk_tval *tv, *tv_end; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(idx >= 0); /* Doesn't support negative indices or count. */ + DUK_ASSERT(idx >= 0); /* Doesn't support negative indices or count. */ DUK_ASSERT(count >= 0); tv = duk_reserve_gap(thr, idx, count); @@ -1232,7 +1237,10 @@ nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); DUK_DDD(DUK_DDDPRINT("duk_pull: from_idx=%ld, p=%p, q=%p, nbytes=%lu", - (long) from_idx, (void *) p, (void *) q, (unsigned long) nbytes)); + (long) from_idx, + (void *) p, + (void *) q, + (unsigned long) nbytes)); /* No net refcount changes. No need to special case nbytes == 0 * (p == q). @@ -1261,7 +1269,7 @@ DUK_TVAL_SET_TVAL(tv2, tv1); DUK_TVAL_SET_UNDEFINED(tv1); thr->valstack_top--; - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ } DUK_EXTERNAL void duk_copy(duk_hthread *thr, duk_idx_t from_idx, duk_idx_t to_idx) { @@ -1276,7 +1284,7 @@ DUK_ASSERT(tv2 != NULL); /* For tv1 == tv2, this is a no-op (no explicit check needed). */ - DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */ } DUK_EXTERNAL void duk_remove(duk_hthread *thr, duk_idx_t idx) { @@ -1307,21 +1315,21 @@ DUK_TVAL_SET_TVAL(&tv_tmp, p); #endif - nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */ + nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */ duk_memmove((void *) p, (const void *) (p + 1), (size_t) nbytes); DUK_TVAL_SET_UNDEFINED(q); thr->valstack_top--; #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ #endif } DUK_INTERNAL void duk_remove_unsafe(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - duk_remove(thr, idx); /* XXX: no optimization for now */ + duk_remove(thr, idx); /* XXX: no optimization for now */ } DUK_INTERNAL void duk_remove_m2(duk_hthread *thr) { @@ -1340,7 +1348,7 @@ while (count-- > 0) { duk_remove(thr, idx); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ duk_tval *tv_src; duk_tval *tv_dst; duk_tval *tv_newtop; @@ -1372,13 +1380,13 @@ /* When not preferring size, only NORZ macros are used; caller * is expected to DUK_REFZERO_CHECK(). */ -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } DUK_INTERNAL void duk_remove_n_unsafe(duk_hthread *thr, duk_idx_t idx, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); - duk_remove_n(thr, idx, count); /* XXX: no optimization for now */ + duk_remove_n(thr, idx, count); /* XXX: no optimization for now */ } /* @@ -1439,7 +1447,7 @@ /* Incref copies, keep originals. */ q = to_thr->valstack_top; while (p < q) { - DUK_TVAL_INCREF(to_thr, p); /* no side effects */ + DUK_TVAL_INCREF(to_thr, p); /* no side effects */ p++; } } else { @@ -1539,7 +1547,7 @@ DUK_EXTERNAL duk_bool_t duk_get_boolean(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__get_boolean_raw(thr, idx, 0); /* default: false */ + return duk__get_boolean_raw(thr, idx, 0); /* default: false */ } DUK_EXTERNAL duk_bool_t duk_get_boolean_default(duk_hthread *thr, duk_idx_t idx, duk_bool_t def_value) { @@ -1585,11 +1593,10 @@ DUK_ASSERT(tv != NULL); #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv)) { - ret.d = (duk_double_t) DUK_TVAL_GET_FASTINT(tv); /* XXX: cast trick */ - } - else + ret.d = (duk_double_t) DUK_TVAL_GET_FASTINT(tv); /* XXX: cast trick */ + } else #endif - if (DUK_TVAL_IS_DOUBLE(tv)) { + if (DUK_TVAL_IS_DOUBLE(tv)) { /* When using packed duk_tval, number must be in NaN-normalized form * for it to be a duk_tval, so no need to normalize. NOP for unpacked * duk_tval. @@ -1606,7 +1613,7 @@ DUK_EXTERNAL duk_double_t duk_get_number(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__get_number_raw(thr, idx, DUK_DOUBLE_NAN); /* default: NaN */ + return duk__get_number_raw(thr, idx, DUK_DOUBLE_NAN); /* default: NaN */ } DUK_EXTERNAL duk_double_t duk_get_number_default(duk_hthread *thr, duk_idx_t idx, duk_double_t def_value) { @@ -1762,7 +1769,11 @@ } } -DUK_EXTERNAL const char *duk_opt_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL const char *duk_opt_lstring(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_len, + const char *def_ptr, + duk_size_t def_len) { DUK_ASSERT_API_ENTRY(thr); if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) { @@ -1783,7 +1794,11 @@ return duk_require_string(thr, idx); } -DUK_EXTERNAL const char *duk_get_lstring_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL const char *duk_get_lstring_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_len, + const char *def_ptr, + duk_size_t def_len) { duk_hstring *h; const char *ret; duk_size_t len; @@ -1872,7 +1887,7 @@ return def_value; } - p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ + p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ return p; } @@ -1910,11 +1925,11 @@ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "pointer", DUK_STR_NOT_POINTER); DUK_WO_NORETURN(return NULL;); } - p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ + p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ return p; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL void *duk_get_voidptr(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; duk_heaphdr *h; @@ -1933,7 +1948,12 @@ } #endif -DUK_LOCAL void *duk__get_buffer_helper(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag) { +DUK_LOCAL void *duk__get_buffer_helper(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size, + duk_bool_t throw_flag) { duk_hbuffer *h; void *ret; duk_size_t len; @@ -1986,7 +2006,11 @@ return duk_require_buffer(thr, idx, out_size); } -DUK_EXTERNAL void *duk_get_buffer_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL void *duk_get_buffer_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_len) { DUK_ASSERT_API_ENTRY(thr); return duk__get_buffer_helper(thr, idx, out_size, def_ptr, def_len, 0 /*throw_flag*/); @@ -2003,7 +2027,13 @@ * have a NULL data pointer when its size is zero, the optional 'out_isbuffer' * argument allows caller to detect this reliably. */ -DUK_INTERNAL void *duk_get_buffer_data_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag, duk_bool_t *out_isbuffer) { +DUK_INTERNAL void *duk_get_buffer_data_raw(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size, + duk_bool_t throw_flag, + duk_bool_t *out_isbuffer) { duk_tval *tv; DUK_ASSERT_API_ENTRY(thr); @@ -2027,7 +2057,7 @@ if (out_isbuffer != NULL) { *out_isbuffer = 1; } - return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */ + return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */ } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) else if (DUK_TVAL_IS_OBJECT(tv)) { @@ -2040,8 +2070,7 @@ duk_hbufobj *h_bufobj = (duk_hbufobj *) h; DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); - if (h_bufobj->buf != NULL && - DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { + if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { duk_uint8_t *p; p = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf); @@ -2056,7 +2085,7 @@ /* if slice not fully valid, treat as error */ } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ if (throw_flag) { DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "buffer", DUK_STR_NOT_BUFFER); @@ -2070,7 +2099,11 @@ return duk_get_buffer_data_raw(thr, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, NULL); } -DUK_EXTERNAL void *duk_get_buffer_data_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size) { +DUK_EXTERNAL void *duk_get_buffer_data_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size) { DUK_ASSERT_API_ENTRY(thr); return duk_get_buffer_data_raw(thr, idx, out_size, def_ptr, def_size, 0 /*throw_flag*/, NULL); } @@ -2110,9 +2143,8 @@ } ret = DUK_TVAL_GET_HEAPHDR(tv); - DUK_ASSERT(ret != NULL); /* tagged null pointers should never occur */ + DUK_ASSERT(ret != NULL); /* tagged null pointers should never occur */ return ret; - } DUK_INTERNAL duk_hstring *duk_get_hstring(duk_hthread *thr, duk_idx_t idx) { @@ -2447,7 +2479,7 @@ DUK_CTX_ASSERT_VALID(thr); - res = duk_get_hobject(thr, idx); /* common case, not promoted */ + res = duk_get_hobject(thr, idx); /* common case, not promoted */ if (DUK_LIKELY(res != NULL)) { DUK_ASSERT(res != NULL); return res; @@ -2460,7 +2492,7 @@ DUK_ASSERT(res != NULL); return res; } else { - return NULL; /* accept without promoting */ + return NULL; /* accept without promoting */ } } @@ -2503,7 +2535,7 @@ duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX); h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT); @@ -2517,7 +2549,7 @@ duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX); h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT); @@ -2563,7 +2595,7 @@ duk_pop_unsafe(thr); return ret; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ case DUK_TAG_STRING: { duk_hstring *h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); @@ -2589,7 +2621,7 @@ duk_pop_unsafe(thr); return ret; } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ case DUK_TAG_OBJECT: { duk_hobject *h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); @@ -2686,8 +2718,8 @@ if (duk_get_prop_stridx(thr, idx, func_stridx)) { /* ... func */ if (duk_is_callable(thr, -1)) { - duk_dup(thr, idx); /* -> ... func this */ - duk_call_method(thr, 0); /* -> ... retval */ + duk_dup(thr, idx); /* -> ... func this */ + duk_call_method(thr, 0); /* -> ... retval */ if (duk_is_primitive(thr, -1)) { duk_replace(thr, idx); return 1; @@ -2695,7 +2727,7 @@ /* ... retval ; popped below */ } } - duk_pop_unsafe(thr); /* ... func/retval -> ... */ + duk_pop_unsafe(thr); /* ... func/retval -> ... */ return 0; } @@ -2706,7 +2738,7 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ } DUK_EXTERNAL void duk_to_null(duk_hthread *thr, duk_idx_t idx) { @@ -2716,13 +2748,11 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */ } /* E5 Section 9.1 */ -DUK_LOCAL const char * const duk__toprim_hint_strings3 = { - "default", "string", "number" -}; +DUK_LOCAL const char * const duk__toprim_hint_strings3 = { "default", "string", "number" }; DUK_LOCAL void duk__to_primitive_helper(duk_hthread *thr, duk_idx_t idx, duk_int_t hint, duk_bool_t check_symbol) { /* Inline initializer for coercers is not allowed by old compilers like BCC. */ duk_small_uint_t coercers2; @@ -2733,10 +2763,8 @@ idx = duk_require_normalize_index(thr, idx); /* If already primitive, return as is. */ - if (!duk_check_type_mask(thr, idx, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + if (!duk_check_type_mask(thr, idx, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } @@ -2747,10 +2775,8 @@ DUK_ASSERT(hint >= 0 && (duk_size_t) hint < sizeof(duk__toprim_hint_strings) / sizeof(const char *)); duk_dup(thr, idx); duk_push_string(thr, duk__toprim_hint_stringshint); - duk_call_method(thr, 1); /* ... method value hint -> ... res */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { + duk_call_method(thr, 1); /* ... method value hint -> ... res */ + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { goto fail; } duk_replace(thr, idx); @@ -2772,7 +2798,7 @@ if (hint == DUK_HINT_NONE) { hint = DUK_HINT_NUMBER; } -#else /* DUK_USE_SYMBOL_BUILTIN */ +#else /* DUK_USE_SYMBOL_BUILTIN */ if (hint == DUK_HINT_NONE) { duk_small_uint_t class_number; @@ -2783,7 +2809,7 @@ hint = DUK_HINT_NUMBER; } } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ coercers0 = DUK_STRIDX_VALUE_OF; coercers1 = DUK_STRIDX_TO_STRING; @@ -2793,16 +2819,16 @@ } if (duk__defaultvalue_coerce_attempt(thr, idx, coercers0)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } if (duk__defaultvalue_coerce_attempt(thr, idx, coercers1)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } - fail: +fail: DUK_ERROR_TYPE(thr, DUK_STR_TOPRIMITIVE_FAILED); DUK_WO_NORETURN(return;); } @@ -2833,7 +2859,7 @@ /* Note: no need to re-lookup tv, conversion is side effect free. */ DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val); /* side effects */ return val; } @@ -2865,11 +2891,11 @@ idx = duk_require_normalize_index(thr, idx); tv = DUK_GET_TVAL_POSIDX(thr, idx); DUK_ASSERT(tv != NULL); - d = duk_js_tonumber(thr, tv); /* XXX: fastint coercion? now result will always be a non-fastint */ + d = duk_js_tonumber(thr, tv); /* XXX: fastint coercion? now result will always be a non-fastint */ /* ToNumber() may have side effects so must relookup 'tv'. */ tv = DUK_GET_TVAL_POSIDX(thr, idx); - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ return d; } @@ -2901,13 +2927,13 @@ tv_dst = thr->valstack_top++; DUK_TVAL_SET_TVAL(tv_dst, tv); - DUK_TVAL_INCREF(thr, tv_dst); /* decref not necessary */ - res = duk_to_number_m1(thr); /* invalidates tv_dst */ + DUK_TVAL_INCREF(thr, tv_dst); /* decref not necessary */ + res = duk_to_number_m1(thr); /* invalidates tv_dst */ tv_dst = --thr->valstack_top; DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_dst)); - DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_dst)); /* plain number */ - DUK_TVAL_SET_UNDEFINED(tv_dst); /* valstack init policy */ + DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_dst)); /* plain number */ + DUK_TVAL_SET_UNDEFINED(tv_dst); /* valstack init policy */ return res; #endif @@ -2943,7 +2969,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ return d; } @@ -2977,7 +3003,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_I32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -2993,7 +3019,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -3009,7 +3035,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -3041,16 +3067,16 @@ if (duk_double_equals(t, 0.5)) { /* Exact halfway, round to even. */ ret = (duk_uint8_t) d; - ret = (ret + 1) & 0xfe; /* Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4 - * Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4 - */ + ret = (ret + 1) & 0xfe; /* Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4 + * Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4 + */ } else { /* Not halfway, round to nearest. */ ret = (duk_uint8_t) (d + 0.5); } return ret; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL const char *duk_to_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) { DUK_ASSERT_API_ENTRY(thr); @@ -3160,7 +3186,7 @@ DUK_ASSERT_API_ENTRY(thr); - duk_to_primitive(thr, idx, DUK_HINT_STRING); /* needed for e.g. Symbol objects */ + duk_to_primitive(thr, idx, DUK_HINT_STRING); /* needed for e.g. Symbol objects */ h = duk_get_hstring(thr, idx); if (h == NULL) { /* The "is string?" check may seem unnecessary, but as things @@ -3174,7 +3200,7 @@ return h; } -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ DUK_INTERNAL duk_hstring *duk_safe_to_hstring(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); @@ -3216,10 +3242,10 @@ * Object.prototype.toString() is usually not performance critical. */ - duk_push_literal(thr, "object "); /* -> ... "object" */ + duk_push_literal(thr, "object "); /* -> ... "object" */ switch (DUK_TVAL_GET_TAG(tv)) { - case DUK_TAG_UNUSED: /* Treat like 'undefined', shouldn't happen. */ + case DUK_TAG_UNUSED: /* Treat like 'undefined', shouldn't happen. */ case DUK_TAG_UNDEFINED: { duk_push_hstring_stridx(thr, DUK_STRIDX_UC_UNDEFINED); goto finish; @@ -3231,7 +3257,7 @@ } duk_push_tval(thr, tv); - tv = NULL; /* Invalidated by ToObject(). */ + tv = NULL; /* Invalidated by ToObject(). */ h_obj = duk_to_hobject(thr, -1); DUK_ASSERT(h_obj != NULL); if (duk_js_isarray_hobject(h_obj)) { @@ -3262,14 +3288,15 @@ duk_pop_unsafe(thr); duk_push_hstring_stridx(thr, stridx); - finish: +finish: /* ... "object" tag */ duk_push_literal(thr, ""); - duk_concat(thr, 3); /* ... "object" tag "" -> ... res */ + duk_concat(thr, 3); /* ... "object" tag "" -> ... res */ } /* XXX: other variants like uint, u32 etc */ -DUK_INTERNAL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) { +DUK_INTERNAL duk_int_t +duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) { duk_tval *tv; duk_tval tv_tmp; duk_double_t d, dmin, dmax; @@ -3280,7 +3307,7 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - d = duk_js_tointeger(thr, tv); /* E5 Section 9.4, ToInteger() */ + d = duk_js_tointeger(thr, tv); /* E5 Section 9.4, ToInteger() */ dmin = (duk_double_t) minval; dmax = (duk_double_t) maxval; @@ -3296,12 +3323,12 @@ } else { res = (duk_int_t) d; } - DUK_UNREF(d); /* SCANBUILD: with suitable dmin/dmax limits 'd' is unused */ + DUK_UNREF(d); /* SCANBUILD: with suitable dmin/dmax limits 'd' is unused */ /* 'd' and 'res' agree here */ /* Relookup in case duk_js_tointeger() ends up e.g. coercing an object. */ tv = duk_get_tval(thr, idx); - DUK_ASSERT(tv != NULL); /* not popped by side effect */ + DUK_ASSERT(tv != NULL); /* not popped by side effect */ DUK_TVAL_SET_TVAL(&tv_tmp, tv); #if defined(DUK_USE_FASTINT) #if (DUK_INT_MAX <= 0x7fffffffL) @@ -3315,9 +3342,9 @@ } #endif #else - DUK_TVAL_SET_NUMBER(tv, d); /* no need to incref */ + DUK_TVAL_SET_NUMBER(tv, d); /* no need to incref */ #endif - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ if (out_clamped) { *out_clamped = clamped; @@ -3342,7 +3369,7 @@ DUK_INTERNAL duk_int_t duk_to_int_check_range(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval) { DUK_ASSERT_API_ENTRY(thr); - return duk_to_int_clamped_raw(thr, idx, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */ + return duk_to_int_clamped_raw(thr, idx, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */ } DUK_EXTERNAL const char *duk_to_string(duk_hthread *thr, duk_idx_t idx) { @@ -3401,9 +3428,9 @@ * value, and duk_to_string() then causes a TypeError. */ duk_to_primitive(thr, idx, DUK_HINT_STRING); - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* ToPrimitive() must guarantee */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* ToPrimitive() must guarantee */ DUK_ASSERT(!duk_is_object(thr, idx)); - return duk_to_string(thr, idx); /* Note: recursive call */ + return duk_to_string(thr, idx); /* Note: recursive call */ } case DUK_TAG_POINTER: { void *ptr = DUK_TVAL_GET_POINTER(tv); @@ -3431,17 +3458,14 @@ DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv)); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); duk_push_tval(thr, tv); - duk_numconv_stringify(thr, - 10 /*radix*/, - 0 /*precision:shortest*/, - 0 /*force_exponential*/); + duk_numconv_stringify(thr, 10 /*radix*/, 0 /*precision:shortest*/, 0 /*force_exponential*/); break; } } duk_replace(thr, idx); - skip_replace: +skip_replace: DUK_ASSERT(duk_is_string(thr, idx)); return duk_require_string(thr, idx); } @@ -3523,8 +3547,7 @@ src_size = DUK_HBUFFER_GET_SIZE(h_buf); tmp = (DUK_HBUFFER_HAS_DYNAMIC(h_buf) ? DUK_BUF_MODE_DYNAMIC : DUK_BUF_MODE_FIXED); - if ((tmp == mode && !DUK_HBUFFER_HAS_EXTERNAL(h_buf)) || - mode == DUK_BUF_MODE_DONTCARE) { + if ((tmp == mode && !DUK_HBUFFER_HAS_EXTERNAL(h_buf)) || mode == DUK_BUF_MODE_DONTCARE) { /* Note: src_data may be NULL if input is a zero-size * dynamic buffer. */ @@ -3545,7 +3568,7 @@ duk_memcpy_unsafe((void *) dst_data, (const void *) src_data, (size_t) src_size); duk_replace(thr, idx); - skip_copy: +skip_copy: if (out_size) { *out_size = src_size; @@ -3605,7 +3628,7 @@ DUK_LOCAL void duk__push_func_from_lightfunc(duk_hthread *thr, duk_c_function func, duk_small_uint_t lf_flags) { duk_idx_t nargs; - duk_uint_t flags = 0; /* shared flags for a subset of types */ + duk_uint_t flags = 0; /* shared flags for a subset of types */ duk_small_uint_t lf_len; duk_hnatfunc *nf; @@ -3614,15 +3637,9 @@ nargs = (duk_idx_t) DUK_VARARGS; } - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_NATIVE_FUNCTION_PROTOTYPE); lf_len = DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags); @@ -3643,7 +3660,7 @@ DUK_EXTERNAL void duk_to_object(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; - duk_uint_t flags = 0; /* shared flags for a subset of types */ + duk_uint_t flags = 0; /* shared flags for a subset of types */ duk_small_int_t proto = 0; DUK_ASSERT_API_ENTRY(thr); @@ -3654,7 +3671,7 @@ switch (DUK_TVAL_GET_TAG(tv)) { #if !defined(DUK_USE_BUFFEROBJECT_SUPPORT) - case DUK_TAG_BUFFER: /* With no bufferobject support, don't object coerce. */ + case DUK_TAG_BUFFER: /* With no bufferobject support, don't object coerce. */ #endif case DUK_TAG_UNDEFINED: case DUK_TAG_NULL: { @@ -3663,9 +3680,8 @@ break; } case DUK_TAG_BOOLEAN: { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BOOLEAN); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BOOLEAN); proto = DUK_BIDX_BOOLEAN_PROTOTYPE; goto create_object; } @@ -3674,14 +3690,11 @@ h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); if (DUK_UNLIKELY(DUK_HSTRING_HAS_SYMBOL(h))) { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_SYMBOL); proto = DUK_BIDX_SYMBOL_PROTOTYPE; } else { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_STRING); proto = DUK_BIDX_STRING_PROTOTYPE; } @@ -3707,11 +3720,10 @@ duk_hbufobj_push_uint8array_from_plain(thr, h_buf); goto replace_value; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ case DUK_TAG_POINTER: { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER); proto = DUK_BIDX_POINTER_PROTOTYPE; goto create_object; } @@ -3738,9 +3750,8 @@ default: { DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv)); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_NUMBER); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_NUMBER); proto = DUK_BIDX_NUMBER_PROTOTYPE; goto create_object; } @@ -3748,7 +3759,7 @@ DUK_ASSERT(duk_is_object(thr, idx)); return; - create_object: +create_object: (void) duk_push_object_helper(thr, flags, proto); /* Note: Boolean prototype's internal value property is not writable, @@ -3761,7 +3772,7 @@ duk_dup(thr, idx); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); - replace_value: +replace_value: duk_replace(thr, idx); DUK_ASSERT(duk_is_object(thr, idx)); } @@ -3832,11 +3843,11 @@ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); return DUK_TYPE_NUMBER; } -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ DUK_ASSERT(DUK_TVAL_IS_VALID_TAG(tv)); DUK_ASSERT(sizeof(duk__type_from_tag) / sizeof(duk_uint_t) == DUK_TAG_MAX - DUK_TAG_MIN + 1); return (duk_int_t) duk__type_from_tagDUK_TVAL_GET_TAG(tv) - DUK_TAG_MIN; -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ } DUK_EXTERNAL duk_int_t duk_get_type(duk_hthread *thr, duk_idx_t idx) { @@ -3851,18 +3862,8 @@ } #if defined(DUK_USE_VERBOSE_ERRORS) && defined(DUK_USE_PARANOID_ERRORS) -DUK_LOCAL const char * const duk__type_names = { - "none", - "undefined", - "null", - "boolean", - "number", - "string", - "object", - "buffer", - "pointer", - "lightfunc" -}; +DUK_LOCAL const char * const duk__type_names = { "none", "undefined", "null", "boolean", "number", + "string", "object", "buffer", "pointer", "lightfunc" }; DUK_INTERNAL const char *duk_get_type_name(duk_hthread *thr, duk_idx_t idx) { duk_int_t type_tag; @@ -3875,7 +3876,7 @@ return duk__type_namestype_tag; } -#endif /* DUK_USE_VERBOSE_ERRORS && DUK_USE_PARANOID_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS && DUK_USE_PARANOID_ERRORS */ DUK_INTERNAL duk_small_uint_t duk_get_class_number(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; @@ -3941,11 +3942,11 @@ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); return DUK_TYPE_MASK_NUMBER; } -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ DUK_ASSERT(DUK_TVAL_IS_VALID_TAG(tv)); DUK_ASSERT(sizeof(duk__type_mask_from_tag) / sizeof(duk_uint_t) == DUK_TAG_MAX - DUK_TAG_MIN + 1); return duk__type_mask_from_tagDUK_TVAL_GET_TAG(tv) - DUK_TAG_MIN; -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ } DUK_EXTERNAL duk_uint_t duk_get_type_mask(duk_hthread *thr, duk_idx_t idx) { @@ -4064,14 +4065,14 @@ } return 0; } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); return duk_is_buffer(thr, idx); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL duk_bool_t duk_is_pointer(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); @@ -4165,23 +4166,17 @@ DUK_EXTERNAL duk_bool_t duk_is_c_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_NATFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_NATFUNC); } DUK_EXTERNAL duk_bool_t duk_is_ecmascript_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_COMPFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_COMPFUNC); } DUK_EXTERNAL duk_bool_t duk_is_bound_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_BOUNDFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_BOUNDFUNC); } DUK_EXTERNAL duk_bool_t duk_is_thread(duk_hthread *thr, duk_idx_t idx) { @@ -4298,7 +4293,7 @@ DUK__CHECK_SPACE(); tv_slot = thr->valstack_top++; DUK_TVAL_SET_TVAL(tv_slot, tv); - DUK_TVAL_INCREF(thr, tv); /* no side effects */ + DUK_TVAL_INCREF(thr, tv); /* no side effects */ } DUK_EXTERNAL void duk_push_undefined(duk_hthread *thr) { @@ -4328,7 +4323,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK__CHECK_SPACE(); - b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */ + b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */ tv_slot = thr->valstack_top++; DUK_TVAL_SET_BOOLEAN(tv_slot, b); } @@ -4381,7 +4376,7 @@ DUK_TVAL_SET_NUMBER(tv_slot, d); } #endif -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ duk_tval *tv_slot; duk_double_t d; @@ -4390,7 +4385,7 @@ d = (duk_double_t) val; tv_slot = thr->valstack_top++; DUK_TVAL_SET_NUMBER(tv_slot, d); -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ } DUK_EXTERNAL void duk_push_uint(duk_hthread *thr, duk_uint_t val) { @@ -4403,7 +4398,7 @@ #if DUK_UINT_MAX <= 0xffffffffUL DUK_TVAL_SET_U32(tv_slot, (duk_uint32_t) val); #else - if (val <= DUK_FASTINT_MAX) { /* val is unsigned so >= 0 */ + if (val <= DUK_FASTINT_MAX) { /* val is unsigned so >= 0 */ /* XXX: take advantage of val being unsigned, no need to mask */ DUK_TVAL_SET_FASTINT(tv_slot, (duk_int64_t) val); } else { @@ -4411,7 +4406,7 @@ DUK_TVAL_SET_NUMBER(tv_slot, d); } #endif -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ duk_tval *tv_slot; duk_double_t d; @@ -4420,7 +4415,7 @@ d = (duk_double_t) val; tv_slot = thr->valstack_top++; DUK_TVAL_SET_NUMBER(tv_slot, d); -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ } DUK_EXTERNAL void duk_push_nan(duk_hthread *thr) { @@ -4464,7 +4459,7 @@ tv_slot = thr->valstack_top++; DUK_TVAL_SET_STRING(tv_slot, h); - DUK_HSTRING_INCREF(thr, h); /* no side effects */ + DUK_HSTRING_INCREF(thr, h); /* no side effects */ return (const char *) DUK_HSTRING_GET_DATA(h); } @@ -4501,11 +4496,11 @@ tv_slot = thr->valstack_top++; DUK_TVAL_SET_STRING(tv_slot, h); - DUK_HSTRING_INCREF(thr, h); /* no side effects */ + DUK_HSTRING_INCREF(thr, h); /* no side effects */ return (const char *) DUK_HSTRING_GET_DATA(h); } -#else /* DUK_USE_LITCACHE_SIZE */ +#else /* DUK_USE_LITCACHE_SIZE */ DUK_EXTERNAL const char *duk_push_literal_raw(duk_hthread *thr, const char *str, duk_size_t len) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(str != NULL); @@ -4513,8 +4508,8 @@ return duk_push_lstring(thr, str, len); } -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_push_pointer(duk_hthread *thr, void *val) { duk_tval *tv_slot; @@ -4542,7 +4537,7 @@ DUK__CHECK_SPACE(); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */ tv_slot = thr->valstack_top++; if (DUK_UNLIKELY(thr->callstack_curr == NULL)) { @@ -4556,8 +4551,7 @@ /* 'this' binding is just before current activation's bottom */ DUK_ASSERT(thr->valstack_bottom > thr->valstack); tv = thr->valstack_bottom - 1; - if (check_object_coercible && - (DUK_TVAL_IS_UNDEFINED(tv) || DUK_TVAL_IS_NULL(tv))) { + if (check_object_coercible && (DUK_TVAL_IS_UNDEFINED(tv) || DUK_TVAL_IS_NULL(tv))) { /* XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv) */ goto type_error; } @@ -4567,7 +4561,7 @@ } return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_NOT_OBJECT_COERCIBLE); DUK_WO_NORETURN(return;); } @@ -4599,16 +4593,16 @@ DUK_ASSERT_API_ENTRY(thr); duk__push_this_helper(thr, 1 /*check_object_coercible*/); - return duk_to_hstring_m1(thr); /* This will reject all Symbol values; accepts Symbol objects. */ + return duk_to_hstring_m1(thr); /* This will reject all Symbol values; accepts Symbol objects. */ } DUK_INTERNAL duk_tval *duk_get_borrowed_this_tval(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */ - DUK_ASSERT(thr->callstack_curr != NULL); /* caller required to know */ - DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */ - DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */ + DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */ + DUK_ASSERT(thr->callstack_curr != NULL); /* caller required to know */ + DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */ + DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */ return thr->valstack_bottom - 1; } @@ -4689,7 +4683,10 @@ duk_pop_unsafe(thr); duk_push_bare_object(thr); duk_dup_top(thr); - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_C); /* ... parent stash stash -> ... parent stash */ + duk_xdef_prop_stridx_short(thr, + -3, + DUK_STRIDX_INT_VALUE, + DUK_PROPDESC_FLAGS_C); /* ... parent stash stash -> ... parent stash */ } duk_remove_m2(thr); } @@ -4742,7 +4739,7 @@ duk_size_t sz = DUK_PUSH_SPRINTF_INITIAL_SIZE; duk_bool_t pushed_buf = 0; void *buf; - duk_int_t len; /* XXX: duk_ssize_t */ + duk_int_t len; /* XXX: duk_ssize_t */ const char *res; DUK_ASSERT_API_ENTRY(thr); @@ -4756,7 +4753,7 @@ } /* initial estimate based on format string */ - sz = DUK_STRLEN(fmt) + 16; /* format plus something to avoid just missing */ + sz = DUK_STRLEN(fmt) + 16; /* format plus something to avoid just missing */ if (sz < DUK_PUSH_SPRINTF_INITIAL_SIZE) { sz = DUK_PUSH_SPRINTF_INITIAL_SIZE; } @@ -4766,7 +4763,7 @@ * This works 99% of the time which is quite nice. */ for (;;) { - va_list ap_copy; /* copied so that 'ap' can be reused */ + va_list ap_copy; /* copied so that 'ap' can be reused */ if (sz <= sizeof(stack_buf)) { buf = stack_buf; @@ -4796,7 +4793,7 @@ /* Cannot use duk_buffer_to_string() on the buffer because it is * usually larger than 'len'; 'buf' is also usually a stack buffer. */ - res = duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); /* buf? res */ + res = duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); /* buf? res */ if (pushed_buf) { duk_remove_m2(thr); } @@ -4817,13 +4814,14 @@ return ret; } -DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) { +DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx) { duk_tval *tv_slot; duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(prototype_bidx == -1 || - (prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS)); + DUK_ASSERT(prototype_bidx == -1 || (prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS)); DUK__CHECK_SPACE(); @@ -4834,7 +4832,7 @@ tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, h); - DUK_HOBJECT_INCREF(thr, h); /* no side effects */ + DUK_HOBJECT_INCREF(thr, h); /* no side effects */ thr->valstack_top++; /* object is now reachable */ @@ -4864,9 +4862,8 @@ DUK_ASSERT_API_ENTRY(thr); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return duk_get_top_index_unsafe(thr); } @@ -4879,11 +4876,8 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); obj = duk_harray_alloc(thr, flags); DUK_ASSERT(obj != NULL); @@ -4892,11 +4886,11 @@ tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); - DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ + DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom); thr->valstack_top++; - DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ + DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ return ret; } @@ -4908,22 +4902,19 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); obj = duk_harray_alloc(thr, flags); DUK_ASSERT(obj != NULL); tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); - DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ + DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom); thr->valstack_top++; - DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ + DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ return ret; } @@ -4950,12 +4941,7 @@ a = duk_push_harray(thr); - duk_hobject_realloc_props(thr, - (duk_hobject *) a, - 0, - size, - 0, - 0); + duk_hobject_realloc_props(thr, (duk_hobject *) a, 0, size, 0, 0); a->length = size; return a; } @@ -4979,9 +4965,7 @@ DUK__CHECK_SPACE(); - obj = duk_hthread_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); + obj = duk_hthread_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); DUK_ASSERT(obj != NULL); obj->state = DUK_HTHREAD_STATE_INACTIVE; #if defined(DUK_USE_ROM_STRINGS) @@ -5021,8 +5005,7 @@ /* Initial stack size satisfies the stack slack constraints so there * is no need to require stack here. */ - DUK_ASSERT(DUK_VALSTACK_INITIAL_SIZE >= - DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + DUK_ASSERT(DUK_VALSTACK_INITIAL_SIZE >= DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); return ret; } @@ -5041,10 +5024,8 @@ */ obj = duk_hcompfunc_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_COMPFUNC | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_COMPFUNC | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); if (DUK_UNLIKELY(obj == NULL)) { DUK_ERROR_ALLOC_FAILED(thr); DUK_WO_NORETURN(return NULL;); @@ -5072,11 +5053,8 @@ DUK__CHECK_SPACE(); obj = duk_hboundfunc_alloc(thr->heap, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BOUNDFUNC | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BOUNDFUNC | DUK_HOBJECT_FLAG_CONSTRUCTABLE | + DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); if (!obj) { DUK_ERROR_ALLOC_FAILED(thr); DUK_WO_NORETURN(return NULL;); @@ -5094,7 +5072,8 @@ return obj; } -DUK_LOCAL duk_idx_t duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx) { +DUK_LOCAL duk_idx_t +duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx) { duk_hnatfunc *obj; duk_idx_t ret; duk_tval *tv_slot; @@ -5122,7 +5101,8 @@ obj->nargs = func_nargs; DUK_DDD(DUK_DDDPRINT("created native function object with flags: 0x%08lx, nargs=%ld", - (unsigned long) obj->obj.hdr.h_flags, (long) obj->nargs)); + (unsigned long) obj->obj.hdr.h_flags, + (long) obj->nargs)); tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); @@ -5134,7 +5114,7 @@ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) obj, thr->builtinsproto_bidx); return ret; - api_error: +api_error: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } @@ -5144,15 +5124,9 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Default prototype is a Duktape specific %NativeFunctionPrototype% * which provides .length and .name getters. @@ -5165,15 +5139,9 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Must use Function.prototype for standard built-in functions. */ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_FUNCTION_PROTOTYPE); @@ -5184,20 +5152,16 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | + DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Must use Function.prototype for standard built-in functions. */ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_FUNCTION_PROTOTYPE); } -DUK_EXTERNAL duk_idx_t duk_push_c_lightfunc(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic) { +DUK_EXTERNAL duk_idx_t +duk_push_c_lightfunc(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic) { duk_small_uint_t lf_flags; duk_tval *tv_slot; @@ -5226,13 +5190,15 @@ DUK_ASSERT(tv_slot >= thr->valstack_bottom); return (duk_idx_t) (tv_slot - thr->valstack_bottom); - api_error: +api_error: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) { +DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx) { duk_hbufobj *obj; duk_tval *tv_slot; @@ -5254,34 +5220,86 @@ return obj; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* XXX: There's quite a bit of overlap with buffer creation handling in * duk_bi_buffer.c. Look for overlap and refactor. */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK__PACK_ARGS(classnum,protobidx,elemtype,elemshift,istypedarray) \ +#define DUK__PACK_ARGS(classnum, protobidx, elemtype, elemshift, istypedarray) \ (((classnum) << 24) | ((protobidx) << 16) | ((elemtype) << 8) | ((elemshift) << 4) | (istypedarray)) static const duk_uint32_t duk__bufobj_flags_lookup = { /* Node.js Buffers are Uint8Array instances which inherit from Buffer.prototype. */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_ARRAYBUFFER, DUK_BIDX_ARRAYBUFFER_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 0), /* DUK_BUFOBJ_ARRAYBUFFER */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_BIDX_NODEJS_BUFFER_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 1), /* DUK_BUFOBJ_NODEJS_BUFFER */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_DATAVIEW, DUK_BIDX_DATAVIEW_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 0), /* DUK_BUFOBJ_DATAVIEW */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT8ARRAY, DUK_BIDX_INT8ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT8, 0, 1), /* DUK_BUFOBJ_INT8ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 1), /* DUK_BUFOBJ_UINT8ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8CLAMPED, 0, 1), /* DUK_BUFOBJ_UINT8CLAMPEDARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT16ARRAY, DUK_BIDX_INT16ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT16, 1, 1), /* DUK_BUFOBJ_INT16ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT16ARRAY, DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT16, 1, 1), /* DUK_BUFOBJ_UINT16ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT32ARRAY, DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT32, 2, 1), /* DUK_BUFOBJ_INT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT32ARRAY, DUK_BIDX_UINT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT32, 2, 1), /* DUK_BUFOBJ_UINT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT32ARRAY, DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_FLOAT32, 2, 1), /* DUK_BUFOBJ_FLOAT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT64ARRAY, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_FLOAT64, 3, 1) /* DUK_BUFOBJ_FLOAT64ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_ARRAYBUFFER, + DUK_BIDX_ARRAYBUFFER_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 0), /* DUK_BUFOBJ_ARRAYBUFFER */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, + DUK_BIDX_NODEJS_BUFFER_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 1), /* DUK_BUFOBJ_NODEJS_BUFFER */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_DATAVIEW, + DUK_BIDX_DATAVIEW_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 0), /* DUK_BUFOBJ_DATAVIEW */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT8ARRAY, + DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT8, + 0, + 1), /* DUK_BUFOBJ_INT8ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, + DUK_BIDX_UINT8ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 1), /* DUK_BUFOBJ_UINT8ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, + DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8CLAMPED, + 0, + 1), /* DUK_BUFOBJ_UINT8CLAMPEDARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT16ARRAY, + DUK_BIDX_INT16ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT16, + 1, + 1), /* DUK_BUFOBJ_INT16ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT16ARRAY, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT16, + 1, + 1), /* DUK_BUFOBJ_UINT16ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT32ARRAY, + DUK_BIDX_INT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT32, + 2, + 1), /* DUK_BUFOBJ_INT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT32ARRAY, + DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT32, + 2, + 1), /* DUK_BUFOBJ_UINT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT32ARRAY, + DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_FLOAT32, + 2, + 1), /* DUK_BUFOBJ_FLOAT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT64ARRAY, + DUK_BIDX_FLOAT64ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_FLOAT64, + 3, + 1) /* DUK_BUFOBJ_FLOAT64ARRAY */ }; -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) { +DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, + duk_idx_t idx_buffer, + duk_size_t byte_offset, + duk_size_t byte_length, + duk_uint_t flags) { duk_hbufobj *h_bufobj; duk_hbuffer *h_val; duk_hobject *h_arraybuf; @@ -5304,7 +5322,7 @@ } } - DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */ + DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */ lookupidx = flags; if (DUK_UNLIKELY(lookupidx >= sizeof(duk__bufobj_flags_lookup) / sizeof(duk_uint32_t))) { goto arg_error; @@ -5314,9 +5332,9 @@ protobidx = (tmp >> 16) & 0xff; h_arraybuf = duk_get_hobject(thr, idx_buffer); - if (h_arraybuf != NULL && /* argument is an object */ - flags != DUK_BUFOBJ_ARRAYBUFFER && /* creating a view */ - DUK_HOBJECT_GET_CLASS_NUMBER(h_arraybuf) == DUK_HOBJECT_CLASS_ARRAYBUFFER /* argument is ArrayBuffer */) { + if (h_arraybuf != NULL && /* argument is an object */ + flags != DUK_BUFOBJ_ARRAYBUFFER && /* creating a view */ + DUK_HOBJECT_GET_CLASS_NUMBER(h_arraybuf) == DUK_HOBJECT_CLASS_ARRAYBUFFER /* argument is ArrayBuffer */) { duk_uint_t tmp_offset; DUK_HBUFOBJ_ASSERT_VALID((duk_hbufobj *) h_arraybuf); @@ -5353,9 +5371,7 @@ DUK_ASSERT(h_val != NULL); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(classnum), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(classnum), (duk_small_int_t) protobidx); DUK_ASSERT(h_bufobj != NULL); @@ -5378,16 +5394,20 @@ */ return; - range_error: +range_error: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); - arg_error: +arg_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ -DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) { +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, + duk_idx_t idx_buffer, + duk_size_t byte_offset, + duk_size_t byte_length, + duk_uint_t flags) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx_buffer); DUK_UNREF(byte_offset); @@ -5396,9 +5416,14 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ -DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap) { +DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + va_list ap) { duk_hobject *proto; #if defined(DUK_USE_AUGMENT_ERROR_CREATE) duk_small_uint_t augment_flags; @@ -5421,9 +5446,8 @@ /* error gets its 'name' from the prototype */ proto = duk_error_prototype_from_code(thr, err_code); (void) duk_push_object_helper_proto(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR), proto); /* ... and its 'message' from an instance property */ @@ -5446,13 +5470,14 @@ /* Creation time error augmentation */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) /* filename may be NULL in which case file/line is not recorded */ - duk_err_augment_error_create(thr, thr, filename, line, augment_flags); /* may throw an error */ + duk_err_augment_error_create(thr, thr, filename, line, augment_flags); /* may throw an error */ #endif return duk_get_top_index_unsafe(thr); } -DUK_EXTERNAL duk_idx_t duk_push_error_object_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { +DUK_EXTERNAL duk_idx_t +duk_push_error_object_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { va_list ap; duk_idx_t ret; @@ -5480,7 +5505,7 @@ va_end(ap); return ret; } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ DUK_EXTERNAL void *duk_push_buffer_raw(duk_hthread *thr, duk_size_t size, duk_small_uint_t flags) { duk_tval *tv_slot; @@ -5583,13 +5608,10 @@ /* CALLABLE and CONSTRUCTABLE flags are copied from the (initial) * target, see ES2015 Sections 9.5.15 and 9.5.13. */ - flags = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h_target) & - (DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE); - flags |= DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ; + flags = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h_target) & (DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE); + flags |= DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ; if (flags & DUK_HOBJECT_FLAG_CALLABLE) { - flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION) | - DUK_HOBJECT_FLAG_SPECIAL_CALL; + flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION) | DUK_HOBJECT_FLAG_SPECIAL_CALL; } else { flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT); } @@ -5615,25 +5637,25 @@ DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) h_proxy); DUK_HOBJECT_INCREF(thr, (duk_hobject *) h_proxy); tv_slot++; - DUK_TVAL_SET_UNDEFINED(tv_slot); /* ... target handler -> ... proxy undefined */ - thr->valstack_top = tv_slot; /* -> ... proxy */ + DUK_TVAL_SET_UNDEFINED(tv_slot); /* ... target handler -> ... proxy undefined */ + thr->valstack_top = tv_slot; /* -> ... proxy */ DUK_DD(DUK_DDPRINT("created Proxy: %!iT", duk_get_tval(thr, -1))); return (duk_idx_t) (thr->valstack_top - thr->valstack_bottom - 1); - fail_args: +fail_args: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } -#else /* DUK_USE_ES6_PROXY */ +#else /* DUK_USE_ES6_PROXY */ DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr, duk_uint_t proxy_flags) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(proxy_flags); DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ASSERTIONS) DUK_LOCAL void duk__validate_push_heapptr(duk_hthread *thr, void *ptr) { @@ -5660,9 +5682,7 @@ * the finalizer starts executing). */ #if defined(DUK_USE_FINALIZER_SUPPORT) - for (curr = thr->heap->finalize_list; - curr != NULL; - curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { + for (curr = thr->heap->finalize_list; curr != NULL; curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { /* FINALIZABLE is set for all objects on finalize_list * except for an object being finalized right now. So * can't assert here. @@ -5674,18 +5694,18 @@ if (curr == h) { if (DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) h)) { /* Object is currently being finalized. */ - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } else { /* Not being finalized but on finalize_list, * allowed since Duktape 2.1. */ - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_REFERENCE_COUNTING) /* Because refzero_list is now processed to completion inline with @@ -5711,7 +5731,7 @@ #endif while (str != NULL) { if (str == (duk_hstring *) h) { - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; break; } @@ -5720,18 +5740,16 @@ } DUK_ASSERT(found != 0); } else { - for (curr = thr->heap->heap_allocated; - curr != NULL; - curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { + for (curr = thr->heap->heap_allocated; curr != NULL; curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { if (curr == h) { - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } } DUK_ASSERT(found != 0); } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ DUK_EXTERNAL duk_idx_t duk_push_heapptr(duk_hthread *thr, void *ptr) { duk_idx_t ret; @@ -5797,7 +5815,7 @@ * heap_allocated. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); /* Preincremented on finalize_list insert. */ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); /* Preincremented on finalize_list insert. */ DUK_HEAPHDR_PREDEC_REFCOUNT(curr); #endif DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(thr->heap, curr); @@ -5829,10 +5847,9 @@ DUK_ASSERT_API_ENTRY(thr); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ return duk_get_top_index_unsafe(thr); } @@ -5941,12 +5958,12 @@ DUK_ASSERT_API_ENTRY(thr); duk_pop_n(thr, count); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_pop_n_unsafe(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); duk__pop_n_unsafe_raw(thr, count); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Pop N elements without DECREF (in effect "stealing" any actual refcounts). */ #if defined(DUK_USE_REFERENCE_COUNTING) @@ -5969,12 +5986,12 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ DUK_INTERNAL void duk_pop_n_nodecref_unsafe(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); duk_pop_n_unsafe(thr, count); } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* Popping one element is called so often that when footprint is not an issue, * compile a specialized function for it. @@ -5992,7 +6009,7 @@ DUK_ASSERT_API_ENTRY(thr); duk_pop_n_nodecref_unsafe(thr, 1); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_LOCAL DUK_ALWAYS_INLINE void duk__pop_unsafe_raw(duk_hthread *thr) { duk_tval *tv; @@ -6004,7 +6021,7 @@ tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif @@ -6040,14 +6057,14 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ #if defined(DUK_USE_PREFER_SIZE) DUK_INTERNAL void duk_pop_undefined(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); duk_pop_nodecref_unsafe(thr); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_pop_undefined(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->valstack_top != thr->valstack_bottom); @@ -6059,7 +6076,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ #if defined(DUK_USE_PREFER_SIZE) DUK_EXTERNAL void duk_pop_2(duk_hthread *thr) { @@ -6086,14 +6103,14 @@ tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif @@ -6127,7 +6144,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_pop_3(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); @@ -6174,9 +6191,9 @@ * multiplying with sizeof(duk_tval) won't wrap. */ DUK_ASSERT(count >= 0 && count <= (duk_idx_t) DUK_USE_VALSTACK_LIMIT); - DUK_ASSERT((duk_size_t) count <= DUK_SIZE_MAX / sizeof(duk_tval)); /* no wrapping */ + DUK_ASSERT((duk_size_t) count <= DUK_SIZE_MAX / sizeof(duk_tval)); /* no wrapping */ - tv_dst = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) count); /* XXX: uninitialized would be OK */ + tv_dst = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) count); /* XXX: uninitialized would be OK */ DUK_ASSERT(count == 0 || tv_dst != NULL); DUK_ASSERT(!duk_is_bare_object(thr, -1)); @@ -6190,7 +6207,7 @@ * the rest; no refcount operations needed. */ - tv_dst = tv_src; /* when count == 0, same as tv_src (OK) */ + tv_dst = tv_src; /* when count == 0, same as tv_src (OK) */ tv_src = thr->valstack_top - 1; DUK_TVAL_SET_TVAL(tv_dst, tv_src); @@ -6220,9 +6237,8 @@ DUK_ASSERT(h != NULL); DUK_UNREF(h); -#if defined(DUK_USE_ARRAY_FASTPATH) /* close enough */ - if (DUK_LIKELY(DUK_HOBJECT_IS_ARRAY(h) && - ((duk_harray *) h)->length <= DUK_HOBJECT_GET_ASIZE(h))) { +#if defined(DUK_USE_ARRAY_FASTPATH) /* close enough */ + if (DUK_LIKELY(DUK_HOBJECT_IS_ARRAY(h) && ((duk_harray *) h)->length <= DUK_HOBJECT_GET_ASIZE(h))) { duk_harray *h_arr; duk_tval *tv_src; duk_tval *tv_dst; @@ -6243,8 +6259,7 @@ * XXX: alternatively, could prevent finalizers for the * duration. */ - if (DUK_UNLIKELY(len != h_arr->length || - h_arr->length > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr))) { + if (DUK_UNLIKELY(len != h_arr->length || h_arr->length > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr))) { goto skip_fast; } @@ -6263,7 +6278,7 @@ * without an ancestor lookup (technically * not compliant). */ - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_dst)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_dst)); /* valstack policy */ } else { DUK_TVAL_SET_TVAL(tv_dst, tv_src); DUK_TVAL_INCREF(thr, tv_dst); @@ -6275,8 +6290,8 @@ thr->valstack_top = tv_dst; return (duk_idx_t) h_arr->length; } - skip_fast: -#endif /* DUK_USE_ARRAY_FASTPATH */ + skip_fast: +#endif /* DUK_USE_ARRAY_FASTPATH */ /* Slow path: actual lookups. The initial 'length' lookup * decides the output length, regardless of side effects that @@ -6285,7 +6300,7 @@ */ idx = duk_normalize_index(thr, idx); duk_get_prop_stridx(thr, idx, DUK_STRIDX_LENGTH); - len = duk_to_uint32(thr, -1); /* ToUint32() coercion required */ + len = duk_to_uint32(thr, -1); /* ToUint32() coercion required */ if (DUK_UNLIKELY(len >= 0x80000000UL)) { goto fail_over_2g; } @@ -6304,7 +6319,7 @@ DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); - fail_over_2g: +fail_over_2g: DUK_ERROR_RANGE_INVALID_LENGTH(thr); DUK_WO_NORETURN(return 0;); } @@ -6389,7 +6404,12 @@ } } -DUK_EXTERNAL void duk_error_va_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap) { +DUK_EXTERNAL void duk_error_va_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + va_list ap) { DUK_ASSERT_API_ENTRY(thr); duk_push_error_object_va_raw(thr, err_code, filename, line, fmt, ap); @@ -6397,7 +6417,12 @@ DUK_WO_NORETURN(return;); } -DUK_EXTERNAL void duk_error_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { +DUK_EXTERNAL void duk_error_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + ...) { va_list ap; DUK_ASSERT_API_ENTRY(thr); @@ -6416,7 +6441,8 @@ #endif #if !defined(DUK_USE_VARIADIC_MACROS) -DUK_NORETURN(DUK_LOCAL_DECL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap)); +DUK_NORETURN( + DUK_LOCAL_DECL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap)); DUK_LOCAL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap) { const char *filename; @@ -6434,7 +6460,8 @@ DUK_WO_NORETURN(return;); } -#define DUK__ERROR_STASH_SHARED(code) do { \ +#define DUK__ERROR_STASH_SHARED(code) \ + do { \ va_list ap; \ va_start(ap, fmt); \ duk__throw_error_from_stash(thr, (code), fmt, ap); \ @@ -6474,7 +6501,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK__ERROR_STASH_SHARED(DUK_ERR_URI_ERROR); } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ /* * Comparison @@ -6593,7 +6620,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(tv)); - DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags); /* read before 'tv' potentially invalidated */ + DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags); /* read before 'tv' potentially invalidated */ duk_push_literal(thr, "function "); duk_push_lightfunc_name_raw(thr, func, lf_flags); duk_push_literal(thr, "() { lightfunc code }"); @@ -6614,7 +6641,7 @@ duk_small_uint_t t; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(sz <= 32); /* sanity limit for function pointer size */ + DUK_ASSERT(sz <= 32); /* sanity limit for function pointer size */ p = buf; #if defined(DUK_USE_INTEGER_LE) @@ -6643,9 +6670,9 @@ */ /* String limits for summary strings. */ -#define DUK__READABLE_SUMMARY_MAXCHARS 96 /* maximum supported by helper */ -#define DUK__READABLE_STRING_MAXCHARS 32 /* for strings/symbols */ -#define DUK__READABLE_ERRMSG_MAXCHARS 96 /* for error messages */ +#define DUK__READABLE_SUMMARY_MAXCHARS 96 /* maximum supported by helper */ +#define DUK__READABLE_STRING_MAXCHARS 32 /* for strings/symbols */ +#define DUK__READABLE_ERRMSG_MAXCHARS 96 /* for error messages */ /* String sanitizer which escapes ASCII control characters and a few other * ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with @@ -6654,8 +6681,7 @@ */ DUK_LOCAL void duk__push_hstring_readable_unicode(duk_hthread *thr, duk_hstring *h_input, duk_small_uint_t maxchars) { const duk_uint8_t *p, *p_start, *p_end; - duk_uint8_t bufDUK_UNICODE_MAX_XUTF8_LENGTH * DUK__READABLE_SUMMARY_MAXCHARS + - 2 /*quotes*/ + 3 /*periods*/; + duk_uint8_t bufDUK_UNICODE_MAX_XUTF8_LENGTH * DUK__READABLE_SUMMARY_MAXCHARS + 2 /*quotes*/ + 3 /*periods*/; duk_uint8_t *q; duk_ucodepoint_t cp; duk_small_uint_t nchars; @@ -6683,7 +6709,7 @@ } if (duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp)) { if (cp < 0x20 || cp == 0x7f || cp == DUK_ASC_SINGLEQUOTE || cp == DUK_ASC_BACKSLASH) { - DUK_ASSERT(DUK_UNICODE_MAX_XUTF8_LENGTH >= 4); /* estimate is valid */ + DUK_ASSERT(DUK_UNICODE_MAX_XUTF8_LENGTH >= 4); /* estimate is valid */ DUK_ASSERT((cp >> 4) <= 0x0f); *q++ = (duk_uint8_t) DUK_ASC_BACKSLASH; *q++ = (duk_uint8_t) DUK_ASC_LC_X; @@ -6693,7 +6719,7 @@ q += duk_unicode_encode_xutf8(cp, q); } } else { - p++; /* advance manually */ + p++; /* advance manually */ *q++ = (duk_uint8_t) DUK_ASC_QUESTION; } nchars++; @@ -6732,8 +6758,10 @@ duk_hobject *h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); - if (error_aware && - duk_hobject_prototype_chain_contains(thr, h, thr->builtinsDUK_BIDX_ERROR_PROTOTYPE, 1 /*ignore_loop*/)) { + if (error_aware && duk_hobject_prototype_chain_contains(thr, + h, + thr->builtinsDUK_BIDX_ERROR_PROTOTYPE, + 1 /*ignore_loop*/)) { /* Get error message in a side effect free way if * possible; if not, summarize as a generic object. * Error message currently gets quoted. @@ -6747,7 +6775,9 @@ /* It's critical to avoid recursion so * only summarize a string .message. */ - duk__push_hstring_readable_unicode(thr, DUK_TVAL_GET_STRING(tv_msg), DUK__READABLE_ERRMSG_MAXCHARS); + duk__push_hstring_readable_unicode(thr, + DUK_TVAL_GET_STRING(tv_msg), + DUK__READABLE_ERRMSG_MAXCHARS); break; } } @@ -6830,7 +6860,7 @@ * Functions */ -#if 0 /* not used yet */ +#if 0 /* not used yet */ DUK_INTERNAL void duk_push_hnatfunc_name(duk_hthread *thr, duk_hnatfunc *h) { duk_c_function func; @@ -6857,7 +6887,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(thr); - DUK_ASSERT(count * sizeof(duk_tval) >= count); /* no wrap */ + DUK_ASSERT(count * sizeof(duk_tval) >= count); /* no wrap */ duk_memcpy_unsafe((void *) tv_dst, (const void *) tv_src, count * sizeof(duk_tval));
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_string.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_string.c
Changed
@@ -51,15 +51,14 @@ /* Impose a string maximum length, need to handle overflow * correctly. */ - if (new_len < len || /* wrapped */ + if (new_len < len || /* wrapped */ new_len > (duk_size_t) DUK_HSTRING_MAX_BYTELEN) { goto error_overflow; } len = new_len; } - DUK_DDD(DUK_DDDPRINT("join/concat %lu strings, total length %lu bytes", - (unsigned long) count, (unsigned long) len)); + DUK_DDD(DUK_DDDPRINT("join/concat %lu strings, total length %lu bytes", (unsigned long) count, (unsigned long) len)); /* Use stack allocated buffer to ensure reachability in errors * (e.g. intern error). @@ -72,11 +71,11 @@ idx = 0; for (i = count; i >= 1; i--) { if (is_join && i != count) { - h = duk_require_hstring(thr, -((duk_idx_t) count) - 2); /* extra -1 for buffer */ + h = duk_require_hstring(thr, -((duk_idx_t) count) - 2); /* extra -1 for buffer */ duk_memcpy(buf + idx, DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); idx += DUK_HSTRING_GET_BYTELEN(h); } - h = duk_require_hstring(thr, -((duk_idx_t) i) - 1); /* extra -1 for buffer */ + h = duk_require_hstring(thr, -((duk_idx_t) i) - 1); /* extra -1 for buffer */ duk_memcpy(buf + idx, DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); idx += DUK_HSTRING_GET_BYTELEN(h); } @@ -88,21 +87,21 @@ /* Get rid of the strings early to minimize memory use before intern. */ if (is_join) { - duk_replace(thr, -((duk_idx_t) count) - 2); /* overwrite sep */ + duk_replace(thr, -((duk_idx_t) count) - 2); /* overwrite sep */ duk_pop_n(thr, (duk_idx_t) count); } else { - duk_replace(thr, -((duk_idx_t) count) - 1); /* overwrite str1 */ + duk_replace(thr, -((duk_idx_t) count) - 1); /* overwrite str1 */ duk_pop_n(thr, (duk_idx_t) (count - 1)); } /* ... buf */ - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ /* ... res */ return; - error_overflow: +error_overflow: DUK_ERROR_RANGE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return;); } @@ -118,7 +117,7 @@ DUK_ASSERT_API_ENTRY(thr); duk_concat(thr, 2); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_concat_2(duk_hthread *thr) { duk_hstring *h1; duk_hstring *h2; @@ -128,14 +127,14 @@ duk_size_t len; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(duk_get_top(thr) >= 2); /* Trusted caller. */ + DUK_ASSERT(duk_get_top(thr) >= 2); /* Trusted caller. */ h1 = duk_to_hstring(thr, -2); h2 = duk_to_hstring(thr, -1); len1 = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h1); len2 = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h2); len = len1 + len2; - if (DUK_UNLIKELY(len < len1 || /* wrapped */ + if (DUK_UNLIKELY(len < len1 || /* wrapped */ len > (duk_size_t) DUK_HSTRING_MAX_BYTELEN)) { goto error_overflow; } @@ -144,7 +143,7 @@ duk_memcpy((void *) buf, (const void *) DUK_HSTRING_GET_DATA(h1), (size_t) len1); duk_memcpy((void *) (buf + len1), (const void *) DUK_HSTRING_GET_DATA(h2), (size_t) len2); - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ /* ... str1 str2 buf */ @@ -152,11 +151,11 @@ duk_pop_unsafe(thr); return; - error_overflow: +error_overflow: DUK_ERROR_RANGE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_join(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); @@ -175,7 +174,7 @@ DUK_ASSERT_API_ENTRY(thr); - h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ + h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input); @@ -202,11 +201,11 @@ idx = duk_normalize_index(thr, idx); - h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ + h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* Reasonable output estimate. */ + DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* Reasonable output estimate. */ p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); @@ -227,7 +226,7 @@ } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 encoded. */ duk_replace(thr, idx); } @@ -240,7 +239,7 @@ DUK_ASSERT_API_ENTRY(thr); - idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ + idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ h = duk_require_hstring(thr, idx); DUK_ASSERT(h != NULL); @@ -265,7 +264,7 @@ end_byte_offset = (duk_size_t) duk_heap_strcache_offset_char2byte(thr, h, (duk_uint_fast32_t) end_offset); DUK_ASSERT(end_byte_offset >= start_byte_offset); - DUK_ASSERT(end_byte_offset - start_byte_offset <= DUK_UINT32_MAX); /* Guaranteed by string limits. */ + DUK_ASSERT(end_byte_offset - start_byte_offset <= DUK_UINT32_MAX); /* Guaranteed by string limits. */ /* No size check is necessary. */ res = duk_heap_strtable_intern_checked(thr, @@ -281,13 +280,13 @@ */ DUK_EXTERNAL void duk_trim(duk_hthread *thr, duk_idx_t idx) { duk_hstring *h; - const duk_uint8_t *p, *p_start, *p_end, *p_tmp1, *p_tmp2; /* pointers for scanning */ - const duk_uint8_t *q_start, *q_end; /* start (incl) and end (excl) of trimmed part */ + const duk_uint8_t *p, *p_start, *p_end, *p_tmp1, *p_tmp2; /* pointers for scanning */ + const duk_uint8_t *q_start, *q_end; /* start (incl) and end (excl) of trimmed part */ duk_codepoint_t cp; DUK_ASSERT_API_ENTRY(thr); - idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ + idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ h = duk_require_hstring(thr, idx); DUK_ASSERT(h != NULL); @@ -329,7 +328,7 @@ } q_end = p; - scan_done: +scan_done: /* This may happen when forward and backward scanning disagree * (possible for non-extended-UTF-8 strings). */ @@ -342,8 +341,10 @@ DUK_ASSERT(q_end >= q_start); DUK_DDD(DUK_DDDPRINT("trim: p_start=%p, p_end=%p, q_start=%p, q_end=%p", - (const void *) p_start, (const void *) p_end, - (const void *) q_start, (const void *) q_end)); + (const void *) p_start, + (const void *) p_end, + (const void *) q_start, + (const void *) q_end)); if (q_start == p_start && q_end == p_end) { DUK_DDD(DUK_DDDPRINT("nothing was trimmed: avoid interning (hashing etc)")); @@ -364,15 +365,15 @@ * is handling of clamped offsets. */ - h = duk_require_hstring(thr, idx); /* Accept symbols. */ + h = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h != NULL); - DUK_ASSERT_DISABLE(char_offset >= 0); /* Always true, arg is unsigned. */ + DUK_ASSERT_DISABLE(char_offset >= 0); /* Always true, arg is unsigned. */ if (char_offset >= DUK_HSTRING_GET_CHARLEN(h)) { return 0; } - DUK_ASSERT(char_offset <= DUK_UINT_MAX); /* Guaranteed by string limits. */ + DUK_ASSERT(char_offset <= DUK_UINT_MAX); /* Guaranteed by string limits. */ cp = duk_hstring_char_code_at_raw(thr, h, (duk_uint_t) char_offset, 0 /*surrogate_aware*/); return (duk_codepoint_t) cp; }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_api_time.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_api_time.c
Changed
@@ -37,7 +37,7 @@ return duk_time_get_ecmascript_time(thr); } -#if 0 /* XXX: worth exposing? */ +#if 0 /* XXX: worth exposing? */ DUK_EXTERNAL duk_double_t duk_get_monotonic_time(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(thr); @@ -52,7 +52,7 @@ duk_uint_t flags; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(comp != NULL); /* XXX: or check? */ + DUK_ASSERT(comp != NULL); /* XXX: or check? */ DUK_UNREF(thr); /* Convert as one-based, but change month to zero-based to match the @@ -81,7 +81,7 @@ duk_uint_t flags; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(comp != NULL); /* XXX: or check? */ + DUK_ASSERT(comp != NULL); /* XXX: or check? */ DUK_UNREF(thr); /* Match Date constructor behavior (with UTC time). Month is given @@ -102,7 +102,7 @@ dpartsDUK_DATE_IDX_MINUTE = comp->minutes; dpartsDUK_DATE_IDX_SECOND = comp->seconds; dpartsDUK_DATE_IDX_MILLISECOND = comp->milliseconds; - dpartsDUK_DATE_IDX_WEEKDAY = 0; /* ignored */ + dpartsDUK_DATE_IDX_WEEKDAY = 0; /* ignored */ d = duk_bi_date_get_timeval_from_dparts(dparts, flags);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_array.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_array.c
Changed
@@ -43,7 +43,7 @@ /* Perform an intermediate join when this many elements have been pushed * on the value stack. */ -#define DUK__ARRAY_MID_JOIN_LIMIT 4096 +#define DUK__ARRAY_MID_JOIN_LIMIT 4096 #if defined(DUK_USE_ARRAY_BUILTIN) @@ -94,7 +94,7 @@ duk_hobject *h; duk_uint_t flags_mask, flags_bits, flags_value; - DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* because call in progress */ + DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* because call in progress */ tv = DUK_GET_THIS_TVAL_PTR(thr); /* Fast path requires that 'this' is a duk_harray. Read only arrays @@ -106,11 +106,8 @@ } h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); - flags_mask = DUK_HOBJECT_FLAG_ARRAY_PART | \ - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HEAPHDR_FLAG_READONLY; - flags_bits = DUK_HOBJECT_FLAG_ARRAY_PART | \ - DUK_HOBJECT_FLAG_EXOTIC_ARRAY; + flags_mask = DUK_HOBJECT_FLAG_ARRAY_PART | DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HEAPHDR_FLAG_READONLY; + flags_bits = DUK_HOBJECT_FLAG_ARRAY_PART | DUK_HOBJECT_FLAG_EXOTIC_ARRAY; flags_value = DUK_HEAPHDR_GET_FLAGS_RAW((duk_heaphdr *) h); if ((flags_value & flags_mask) != flags_bits) { DUK_DD(DUK_DDPRINT("reject array fast path: object flag check failed")); @@ -136,7 +133,7 @@ DUK_DD(DUK_DDPRINT("array fast path allowed for: %!O", (duk_heaphdr *) h)); return (duk_harray *) h; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ /* * Constructor @@ -206,7 +203,7 @@ */ DUK_DDD(DUK_DDDPRINT("this.join is not callable, fall back to (original) Object.toString")); duk_set_top(thr, 0); - return duk_bi_object_prototype_to_string(thr); /* has access to 'this' binding */ + return duk_bi_object_prototype_to_string(thr); /* has access to 'this' binding */ } /* ... this func */ @@ -215,9 +212,8 @@ /* ... func this */ - DUK_DDD(DUK_DDDPRINT("calling: func=%!iT, this=%!iT", - (duk_tval *) duk_get_tval(thr, -2), - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD( + DUK_DDDPRINT("calling: func=%!iT, this=%!iT", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_call_method(thr, 0); return 1; @@ -247,7 +243,7 @@ (void) duk_push_this_coercible_to_object(thr); duk_insert(thr, 0); n = duk_get_top(thr); - duk_push_array(thr); /* -> ToObject(this) item1 ... itemN arr */ + duk_push_array(thr); /* -> ToObject(this) item1 ... itemN arr */ /* NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index() * (which differs from the official algorithm). If no error is thrown, this @@ -298,7 +294,7 @@ } DUK_ASSERT(duk_is_object(thr, i)); - need_has_check = (DUK_HOBJECT_IS_PROXY(h) != 0); /* Always 0 w/o Proxy support. */ + need_has_check = (DUK_HOBJECT_IS_PROXY(h) != 0); /* Always 0 w/o Proxy support. */ /* ToObject(this) item1 ... itemN arr */ @@ -330,7 +326,7 @@ } } idx++; - DUK_ASSERT(idx != 0U); /* Wrap check above. */ + DUK_ASSERT(idx != 0U); /* Wrap check above. */ } } @@ -345,7 +341,7 @@ DUK_ASSERT_TOP(thr, n + 1); return 1; - fail_wrap: +fail_wrap: DUK_ERROR_RANGE_INVALID_LENGTH(thr); DUK_WO_NORETURN(return 0;); } @@ -391,8 +387,7 @@ (unsigned long) len)); /* The extra (+4) is tight. */ - valstack_required = (duk_idx_t) ((len >= DUK__ARRAY_MID_JOIN_LIMIT ? - DUK__ARRAY_MID_JOIN_LIMIT : len) + 4); + valstack_required = (duk_idx_t) ((len >= DUK__ARRAY_MID_JOIN_LIMIT ? DUK__ARRAY_MID_JOIN_LIMIT : len) + 4); duk_require_stack(thr, valstack_required); duk_dup_0(thr); @@ -403,14 +398,13 @@ idx = 0; for (;;) { DUK_DDD(DUK_DDDPRINT("join idx=%ld", (long) idx)); - if (count >= DUK__ARRAY_MID_JOIN_LIMIT || /* intermediate join to avoid valstack overflow */ + if (count >= DUK__ARRAY_MID_JOIN_LIMIT || /* intermediate join to avoid valstack overflow */ idx >= len) { /* end of loop (careful with len==0) */ /* sep ToObject(this) len sep str0 ... str(count-1) */ - DUK_DDD(DUK_DDDPRINT("mid/final join, count=%ld, idx=%ld, len=%ld", - (long) count, (long) idx, (long) len)); - duk_join(thr, (duk_idx_t) count); /* -> sep ToObject(this) len str */ - duk_dup_0(thr); /* -> sep ToObject(this) len str sep */ - duk_insert(thr, -2); /* -> sep ToObject(this) len sep str */ + DUK_DDD(DUK_DDDPRINT("mid/final join, count=%ld, idx=%ld, len=%ld", (long) count, (long) idx, (long) len)); + duk_join(thr, (duk_idx_t) count); /* -> sep ToObject(this) len str */ + duk_dup_0(thr); /* -> sep ToObject(this) len str sep */ + duk_insert(thr, -2); /* -> sep ToObject(this) len sep str */ count = 1; } if (idx >= len) { @@ -426,7 +420,7 @@ if (to_locale_string) { duk_to_object(thr, -1); duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_LOCALE_STRING); - duk_insert(thr, -2); /* -> ... toLocaleString ToObject(val) */ + duk_insert(thr, -2); /* -> ... toLocaleString ToObject(val) */ duk_call_method(thr, 0); } duk_to_string(thr, -1); @@ -484,7 +478,7 @@ return 1; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ DUK_INTERNAL duk_ret_t duk_bi_array_prototype_pop(duk_hthread *thr) { duk_uint32_t len; @@ -535,7 +529,7 @@ DUK_ASSERT((duk_uint32_t) n <= DUK_UINT32_MAX); if (DUK_UNLIKELY(len + (duk_uint32_t) n < len)) { DUK_D(DUK_DPRINT("Array.prototype.push() would go beyond 32-bit length, throw")); - DUK_DCERROR_RANGE_INVALID_LENGTH(thr); /* != 0 return value returned as is by caller */ + DUK_DCERROR_RANGE_INVALID_LENGTH(thr); /* != 0 return value returned as is by caller */ } if (len + (duk_uint32_t) n > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr)) { /* Array part would need to be extended. Rely on slow path @@ -565,7 +559,7 @@ duk_push_uint(thr, (duk_uint_t) len); return 1; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ DUK_INTERNAL duk_ret_t duk_bi_array_prototype_push(duk_hthread *thr) { /* Note: 'this' is not necessarily an Array object. The push() @@ -640,7 +634,7 @@ duk_bool_t have1, have2; duk_bool_t undef1, undef2; duk_small_int_t ret; - duk_idx_t idx_obj = 1; /* fixed offsets in valstack */ + duk_idx_t idx_obj = 1; /* fixed offsets in valstack */ duk_idx_t idx_fn = 0; duk_hstring *h1, *h2; @@ -661,7 +655,8 @@ if (idx1 == idx2) { DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%ld, idx2=%ld -> indices identical, quick exit", - (long) idx1, (long) idx2)); + (long) idx1, + (long) idx2)); return 0; } @@ -669,8 +664,12 @@ have2 = duk_get_prop_index(thr, idx_obj, (duk_uarridx_t) idx2); DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%ld, idx2=%ld, have1=%ld, have2=%ld, val1=%!T, val2=%!T", - (long) idx1, (long) idx2, (long) have1, (long) have2, - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (long) idx1, + (long) idx2, + (long) have1, + (long) have2, + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); if (have1) { if (have2) { @@ -712,9 +711,9 @@ duk_double_t d; /* No need to check callable; duk_call() will do that. */ - duk_dup(thr, idx_fn); /* -> ... x y fn */ - duk_insert(thr, -3); /* -> ... fn x y */ - duk_call(thr, 2); /* -> ... res */ + duk_dup(thr, idx_fn); /* -> ... x y fn */ + duk_insert(thr, -3); /* -> ... fn x y */ + duk_call(thr, 2); /* -> ... res */ /* ES5 is a bit vague about what to do if the return value is * not a number. ES2015 provides a concrete description: @@ -746,10 +745,10 @@ DUK_ASSERT(h1 != NULL); DUK_ASSERT(h2 != NULL); - ret = duk_js_string_compare(h1, h2); /* retval is directly usable */ + ret = duk_js_string_compare(h1, h2); /* retval is directly usable */ goto pop_ret; - pop_ret: +pop_ret: duk_pop_2_unsafe(thr); DUK_DDD(DUK_DDDPRINT("-> result %ld", (long) ret)); return ret; @@ -757,7 +756,7 @@ DUK_LOCAL void duk__array_sort_swap(duk_hthread *thr, duk_int_t l, duk_int_t r) { duk_bool_t have_l, have_r; - duk_idx_t idx_obj = 1; /* fixed offset in valstack */ + duk_idx_t idx_obj = 1; /* fixed offset in valstack */ if (l == r) { return; @@ -810,8 +809,7 @@ *ptr++ = ''; *ptr++ = '\0'; - DUK_DDD(DUK_DDDPRINT("%s (lo=%ld, hi=%ld, pivot=%ld)", - (const char *) buf, (long) lo, (long) hi, (long) pivot)); + DUK_DDD(DUK_DDDPRINT("%s (lo=%ld, hi=%ld, pivot=%ld)", (const char *) buf, (long) lo, (long) hi, (long) pivot)); } #endif @@ -820,8 +818,7 @@ /* The lo/hi indices may be crossed and hi < 0 is possible at entry. */ - DUK_DDD(DUK_DDDPRINT("duk__array_qsort: lo=%ld, hi=%ld, obj=%!T", - (long) lo, (long) hi, (duk_tval *) duk_get_tval(thr, 1))); + DUK_DDD(DUK_DDDPRINT("duk__array_qsort: lo=%ld, hi=%ld, obj=%!T", (long) lo, (long) hi, (duk_tval *) duk_get_tval(thr, 1))); DUK_ASSERT_TOP(thr, 3); @@ -839,7 +836,7 @@ DUK_ASSERT(hi - lo + 1 >= 2); /* randomized pivot selection */ - p = lo + (duk_int_t) (DUK_UTIL_GET_RANDOM_DOUBLE(thr) * (duk_double_t) (hi - lo + 1)); + p = lo + (duk_int_t) (duk_util_get_random_double(thr) * (duk_double_t) (hi - lo + 1)); DUK_ASSERT(p >= lo && p <= hi); DUK_DDD(DUK_DDDPRINT("lo=%ld, hi=%ld, chose pivot p=%ld", (long) lo, (long) hi, (long) p)); @@ -853,23 +850,21 @@ for (;;) { /* find elements to swap */ for (;;) { - DUK_DDD(DUK_DDDPRINT("left scan: l=%ld, r=%ld, p=%ld", - (long) l, (long) r, (long) p)); + DUK_DDD(DUK_DDDPRINT("left scan: l=%ld, r=%ld, p=%ld", (long) l, (long) r, (long) p)); if (l >= hi) { break; } - if (duk__array_sort_compare(thr, l, p) >= 0) { /* !(l < p) */ + if (duk__array_sort_compare(thr, l, p) >= 0) { /* !(l < p) */ break; } l++; } for (;;) { - DUK_DDD(DUK_DDDPRINT("right scan: l=%ld, r=%ld, p=%ld", - (long) l, (long) r, (long) p)); + DUK_DDD(DUK_DDDPRINT("right scan: l=%ld, r=%ld, p=%ld", (long) l, (long) r, (long) p)); if (r <= lo) { break; } - if (duk__array_sort_compare(thr, p, r) >= 0) { /* !(p < r) */ + if (duk__array_sort_compare(thr, p, r) >= 0) { /* !(p < r) */ break; } r--; @@ -887,7 +882,7 @@ l++; r--; } - done: +done: /* Note that 'l' and 'r' may cross, i.e. r < l */ DUK_ASSERT(l >= lo && l <= hi); DUK_ASSERT(r >= lo && r <= hi); @@ -931,7 +926,7 @@ DUK_ASSERT_TOP(thr, 3); duk_pop_nodecref_unsafe(thr); - return 1; /* return ToObject(this) */ + return 1; /* return ToObject(this) */ } /* @@ -1024,7 +1019,7 @@ for (i = 0; i < del_count; i++) { if (duk_get_prop_index(thr, -3, (duk_uarridx_t) (act_start + i))) { - duk_xdef_prop_index_wec(thr, -2, (duk_uarridx_t) i); /* throw flag irrelevant (false in std alg) */ + duk_xdef_prop_index_wec(thr, -2, (duk_uarridx_t) i); /* throw flag irrelevant (false in std alg) */ } else { duk_pop_undefined(thr); } @@ -1094,7 +1089,7 @@ /* Step 15: insert itemCount elements into the hole made above */ for (i = 0; i < item_count; i++) { - duk_dup(thr, i + 2); /* args start at index 2 */ + duk_dup(thr, i + 2); /* args start at index 2 */ duk_put_prop_index(thr, -4, (duk_uarridx_t) (act_start + i)); } @@ -1157,7 +1152,7 @@ } DUK_ASSERT_TOP(thr, 2); - duk_pop_unsafe(thr); /* -> ToObject(this) */ + duk_pop_unsafe(thr); /* -> ToObject(this) */ return 1; } @@ -1307,26 +1302,32 @@ if (duk_get_prop_index(thr, -2, (duk_uarridx_t) i)) { /* fromPresent = true */ /* ... ToObject(this) ToUint32(length) val */ - duk_put_prop_index(thr, -3, (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ + duk_put_prop_index( + thr, + -3, + (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ } else { /* fromPresent = false */ /* ... ToObject(this) ToUint32(length) val */ duk_pop_undefined(thr); - duk_del_prop_index(thr, -2, (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ + duk_del_prop_index( + thr, + -2, + (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ } DUK_ASSERT_TOP(thr, nargs + 2); } for (i = 0; i < (duk_uint32_t) nargs; i++) { DUK_ASSERT_TOP(thr, nargs + 2); - duk_dup(thr, (duk_idx_t) i); /* -> ... ToObject(this) ToUint32(length) argi */ + duk_dup(thr, (duk_idx_t) i); /* -> ... ToObject(this) ToUint32(length) argi */ duk_put_prop_index(thr, -3, (duk_uarridx_t) i); DUK_ASSERT_TOP(thr, nargs + 2); } DUK_ASSERT_TOP(thr, nargs + 2); duk_push_u32(thr, len + (duk_uint32_t) nargs); - duk_dup_top(thr); /* -> ... ToObject(this) ToUint32(length) final_len final_len */ + duk_dup_top(thr); /* -> ... ToObject(this) ToUint32(length) final_len final_len */ duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_LENGTH); return 1; } @@ -1339,7 +1340,7 @@ duk_idx_t nargs; duk_int_t i, len; duk_int_t from_idx; - duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for indexOf, -1 for lastIndexOf */ + duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for indexOf, -1 for lastIndexOf */ /* lastIndexOf() needs to be a vararg function because we must distinguish * between an undefined fromIndex and a "not given" fromIndex; indexOf() is @@ -1377,10 +1378,7 @@ * lastIndexOf: clamp fromIndex to -len - 1, len - 1 * (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly) */ - from_idx = duk_to_int_clamped(thr, - 1, - (idx_step > 0 ? -len : -len - 1), - (idx_step > 0 ? len : len - 1)); + from_idx = duk_to_int_clamped(thr, 1, (idx_step > 0 ? -len : -len - 1), (idx_step > 0 ? len : len - 1)); if (from_idx < 0) { /* for lastIndexOf, result may be -1 (mark immediate termination) */ from_idx = len + from_idx; @@ -1416,7 +1414,7 @@ duk_pop_unsafe(thr); } - not_found: +not_found: duk_push_int(thr, -1); return 1; } @@ -1425,11 +1423,11 @@ * every(), some(), forEach(), map(), filter() */ -#define DUK__ITER_EVERY 0 -#define DUK__ITER_SOME 1 -#define DUK__ITER_FOREACH 2 -#define DUK__ITER_MAP 3 -#define DUK__ITER_FILTER 4 +#define DUK__ITER_EVERY 0 +#define DUK__ITER_SOME 1 +#define DUK__ITER_FOREACH 2 +#define DUK__ITER_MAP 3 +#define DUK__ITER_FILTER 4 /* XXX: This helper is a bit awkward because the handling for the different iteration * callers is quite different. This now compiles to a bit less than 500 bytes, so with @@ -1464,7 +1462,7 @@ * stack4 = result array (or undefined) */ - k = 0; /* result index for filter() */ + k = 0; /* result index for filter() */ for (i = 0; i < len; i++) { DUK_ASSERT_TOP(thr, 5); @@ -1488,7 +1486,7 @@ duk_dup_1(thr); duk_dup_m3(thr); duk_push_u32(thr, i); - duk_dup_2(thr); /* ... val callback thisArg val i obj */ + duk_dup_2(thr); /* ... val callback thisArg val i obj */ duk_call_method(thr, 3); /* -> ... val retval */ switch (iter_type) { @@ -1511,13 +1509,13 @@ break; case DUK__ITER_MAP: duk_dup_top(thr); - duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) i); /* retval to resulti */ + duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) i); /* retval to resulti */ res_length = i + 1; break; case DUK__ITER_FILTER: bval = duk_to_boolean(thr, -1); if (bval) { - duk_dup_m2(thr); /* orig value */ + duk_dup_m2(thr); /* orig value */ duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) k); k++; res_length = k; @@ -1545,7 +1543,7 @@ case DUK__ITER_MAP: case DUK__ITER_FILTER: DUK_ASSERT_TOP(thr, 5); - DUK_ASSERT(duk_is_array(thr, -1)); /* topmost element is the result array already */ + DUK_ASSERT(duk_is_array(thr, -1)); /* topmost element is the result array already */ duk_push_u32(thr, res_length); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W); break; @@ -1565,7 +1563,7 @@ duk_idx_t nargs; duk_bool_t have_acc; duk_uint32_t i, len; - duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for reduce, -1 for reduceRight */ + duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for reduce, -1 for reduceRight */ /* We're a varargs function because we need to detect whether * initialValue was given or not. @@ -1589,8 +1587,7 @@ duk_dup_1(thr); have_acc = 1; } - DUK_DDD(DUK_DDDPRINT("have_acc=%ld, acc=%!T", - (long) have_acc, (duk_tval *) duk_get_tval(thr, 3))); + DUK_DDD(DUK_DDDPRINT("have_acc=%ld, acc=%!T", (long) have_acc, (duk_tval *) duk_get_tval(thr, 3))); /* For len == 0, i is initialized to len - 1 which underflows. * The condition (i < len) will then exit the for-loop on the @@ -1598,16 +1595,16 @@ * happens by i underflowing. */ - for (i = (idx_step >= 0 ? 0 : len - 1); - i < len; /* i >= 0 would always be true */ + for (i = (idx_step >= 0 ? 0 : len - 1); i < len; /* i >= 0 would always be true */ i += (duk_uint32_t) idx_step) { DUK_DDD(DUK_DDDPRINT("i=%ld, len=%ld, have_acc=%ld, top=%ld, acc=%!T", - (long) i, (long) len, (long) have_acc, + (long) i, + (long) len, + (long) have_acc, (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, 4))); - DUK_ASSERT((have_acc && duk_get_top(thr) == 5) || - (!have_acc && duk_get_top(thr) == 4)); + DUK_ASSERT((have_acc && duk_get_top(thr) == 5) || (!have_acc && duk_get_top(thr) == 4)); if (!duk_has_prop_index(thr, 2, (duk_uarridx_t) i)) { continue; @@ -1626,8 +1623,10 @@ duk_push_u32(thr, i); duk_dup_2(thr); DUK_DDD(DUK_DDDPRINT("calling reduce function: func=%!T, prev=%!T, curr=%!T, idx=%!T, obj=%!T", - (duk_tval *) duk_get_tval(thr, -5), (duk_tval *) duk_get_tval(thr, -4), - (duk_tval *) duk_get_tval(thr, -3), (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -5), + (duk_tval *) duk_get_tval(thr, -4), + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_call(thr, 4); DUK_DDD(DUK_DDDPRINT("-> result: %!T", (duk_tval *) duk_get_tval(thr, -1))); @@ -1644,4 +1643,4 @@ return 1; } -#endif /* DUK_USE_ARRAY_BUILTIN */ +#endif /* DUK_USE_ARRAY_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_boolean.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_boolean.c
Changed
@@ -39,7 +39,7 @@ DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* never here */ - type_ok: +type_ok: if (coerce_tostring) { duk_to_string(thr, -1); } @@ -59,11 +59,11 @@ DUK_HOBJECT_SET_CLASS_NUMBER(h_this, DUK_HOBJECT_CLASS_BOOLEAN); - duk_dup_0(thr); /* -> val obj val */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); /* XXX: proper flags? */ - } /* unbalanced stack */ + duk_dup_0(thr); /* -> val obj val */ + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); /* XXX: proper flags? */ + } /* unbalanced stack */ return 1; } -#endif /* DUK_USE_BOOLEAN_BUILTIN */ +#endif /* DUK_USE_BOOLEAN_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_buffer.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_buffer.c
Changed
@@ -13,57 +13,38 @@ * default internal prototype. */ static const duk_uint8_t duk__buffer_proto_from_classnum = { - DUK_BIDX_ARRAYBUFFER_PROTOTYPE, - DUK_BIDX_DATAVIEW_PROTOTYPE, - DUK_BIDX_INT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, - DUK_BIDX_INT16ARRAY_PROTOTYPE, - DUK_BIDX_UINT16ARRAY_PROTOTYPE, - DUK_BIDX_INT32ARRAY_PROTOTYPE, - DUK_BIDX_UINT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT64ARRAY_PROTOTYPE + DUK_BIDX_ARRAYBUFFER_PROTOTYPE, DUK_BIDX_DATAVIEW_PROTOTYPE, DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_BIDX_INT16ARRAY_PROTOTYPE, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE }; /* Map DUK_HBUFOBJ_ELEM_xxx to duk_hobject class number. * Sync with duk_hbufobj.h and duk_hobject.h. */ -static const duk_uint8_t duk__buffer_class_from_elemtype9 = { - DUK_HOBJECT_CLASS_UINT8ARRAY, - DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, - DUK_HOBJECT_CLASS_INT8ARRAY, - DUK_HOBJECT_CLASS_UINT16ARRAY, - DUK_HOBJECT_CLASS_INT16ARRAY, - DUK_HOBJECT_CLASS_UINT32ARRAY, - DUK_HOBJECT_CLASS_INT32ARRAY, - DUK_HOBJECT_CLASS_FLOAT32ARRAY, - DUK_HOBJECT_CLASS_FLOAT64ARRAY -}; +static const duk_uint8_t duk__buffer_class_from_elemtype9 = { DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, + DUK_HOBJECT_CLASS_INT8ARRAY, DUK_HOBJECT_CLASS_UINT16ARRAY, + DUK_HOBJECT_CLASS_INT16ARRAY, DUK_HOBJECT_CLASS_UINT32ARRAY, + DUK_HOBJECT_CLASS_INT32ARRAY, DUK_HOBJECT_CLASS_FLOAT32ARRAY, + DUK_HOBJECT_CLASS_FLOAT64ARRAY }; /* Map DUK_HBUFOBJ_ELEM_xxx to prototype object built-in index. * Sync with duk_hbufobj.h. */ static const duk_uint8_t duk__buffer_proto_from_elemtype9 = { - DUK_BIDX_UINT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, - DUK_BIDX_INT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT16ARRAY_PROTOTYPE, - DUK_BIDX_INT16ARRAY_PROTOTYPE, - DUK_BIDX_UINT32ARRAY_PROTOTYPE, - DUK_BIDX_INT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT64ARRAY_PROTOTYPE + DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_BIDX_INT16ARRAY_PROTOTYPE, DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE }; /* Map DUK__FLD_xxx to byte size. */ static const duk_uint8_t duk__buffer_nbytes_from_fldtype6 = { - 1, /* DUK__FLD_8BIT */ - 2, /* DUK__FLD_16BIT */ - 4, /* DUK__FLD_32BIT */ - 4, /* DUK__FLD_FLOAT */ - 8, /* DUK__FLD_DOUBLE */ - 0 /* DUK__FLD_VARINT; not relevant here */ + 1, /* DUK__FLD_8BIT */ + 2, /* DUK__FLD_16BIT */ + 4, /* DUK__FLD_32BIT */ + 4, /* DUK__FLD_FLOAT */ + 8, /* DUK__FLD_DOUBLE */ + 0 /* DUK__FLD_VARINT; not relevant here */ }; /* Bitfield for each DUK_HBUFOBJ_ELEM_xxx indicating which element types @@ -75,36 +56,27 @@ #if !defined(DUK_USE_PREFER_SIZE) static duk_uint16_t duk__buffer_elemtype_copy_compatible9 = { /* xxx -> DUK_HBUFOBJ_ELEM_UINT8 */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | - (1U << DUK_HBUFOBJ_ELEM_INT8), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | (1U << DUK_HBUFOBJ_ELEM_INT8), /* xxx -> DUK_HBUFOBJ_ELEM_UINT8CLAMPED * Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00. */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED), /* xxx -> DUK_HBUFOBJ_ELEM_INT8 */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | - (1U << DUK_HBUFOBJ_ELEM_INT8), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | (1U << DUK_HBUFOBJ_ELEM_INT8), /* xxx -> DUK_HBUFOBJ_ELEM_UINT16 */ - (1U << DUK_HBUFOBJ_ELEM_UINT16) | - (1U << DUK_HBUFOBJ_ELEM_INT16), + (1U << DUK_HBUFOBJ_ELEM_UINT16) | (1U << DUK_HBUFOBJ_ELEM_INT16), /* xxx -> DUK_HBUFOBJ_ELEM_INT16 */ - (1U << DUK_HBUFOBJ_ELEM_UINT16) | - (1U << DUK_HBUFOBJ_ELEM_INT16), + (1U << DUK_HBUFOBJ_ELEM_UINT16) | (1U << DUK_HBUFOBJ_ELEM_INT16), /* xxx -> DUK_HBUFOBJ_ELEM_UINT32 */ - (1U << DUK_HBUFOBJ_ELEM_UINT32) | - (1U << DUK_HBUFOBJ_ELEM_INT32), + (1U << DUK_HBUFOBJ_ELEM_UINT32) | (1U << DUK_HBUFOBJ_ELEM_INT32), /* xxx -> DUK_HBUFOBJ_ELEM_INT32 */ - (1U << DUK_HBUFOBJ_ELEM_UINT32) | - (1U << DUK_HBUFOBJ_ELEM_INT32), + (1U << DUK_HBUFOBJ_ELEM_UINT32) | (1U << DUK_HBUFOBJ_ELEM_INT32), /* xxx -> DUK_HBUFOBJ_ELEM_FLOAT32 */ (1U << DUK_HBUFOBJ_ELEM_FLOAT32), @@ -112,7 +84,7 @@ /* xxx -> DUK_HBUFOBJ_ELEM_FLOAT64 */ (1U << DUK_HBUFOBJ_ELEM_FLOAT64) }; -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_LOCAL duk_hbufobj *duk__hbufobj_promote_this(duk_hthread *thr) { duk_tval *tv_dst; @@ -131,8 +103,8 @@ return res; } -#define DUK__BUFOBJ_FLAG_THROW (1 << 0) -#define DUK__BUFOBJ_FLAG_PROMOTE (1 << 1) +#define DUK__BUFOBJ_FLAG_THROW (1 << 0) +#define DUK__BUFOBJ_FLAG_PROMOTE (1 << 1) /* Shared helper. When DUK__BUFOBJ_FLAG_PROMOTE is given, the return value is * always a duk_hbufobj *. Without the flag the return value can also be a @@ -223,7 +195,7 @@ DUK_LOCAL void duk__set_bufobj_buffer(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_hbuffer *h_val) { DUK_ASSERT(thr != NULL); DUK_ASSERT(h_bufobj != NULL); - DUK_ASSERT(h_bufobj->buf == NULL); /* no need to decref */ + DUK_ASSERT(h_bufobj->buf == NULL); /* no need to decref */ DUK_ASSERT(h_val != NULL); DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); DUK_UNREF(thr); @@ -259,12 +231,12 @@ if (offset > h_bufarg->length) { goto fail_range; } - DUK_ASSERT_DISABLE(offset >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(offset >= 0); /* unsigned */ DUK_ASSERT(offset <= h_bufarg->length); if (duk_is_undefined(thr, idx_length)) { DUK_ASSERT(h_bufarg->length >= offset); - length = h_bufarg->length - offset; /* >= 0 */ + length = h_bufarg->length - offset; /* >= 0 */ } else { length_signed = duk_to_int(thr, idx_length); if (length_signed < 0) { @@ -283,14 +255,14 @@ } } } - DUK_ASSERT_DISABLE(length >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(length >= 0); /* unsigned */ DUK_ASSERT(offset + length <= h_bufarg->length); *out_offset = offset; *out_length = length; return; - fail_range: +fail_range: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); } @@ -348,7 +320,7 @@ DUK_ASSERT(out_start_offset != NULL); DUK_ASSERT(out_end_offset != NULL); - buffer_length >>= buffer_shift; /* as (full) elements */ + buffer_length >>= buffer_shift; /* as (full) elements */ /* Resolve start/end offset as element indices first; arguments * at idx_start/idx_end are element offsets. Working with element @@ -440,7 +412,10 @@ } /* Indexed read helper for buffer objects, also called from outside this file. */ -DUK_INTERNAL void duk_hbufobj_push_validated_read(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size) { +DUK_INTERNAL void duk_hbufobj_push_validated_read(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size) { duk_double_union du; DUK_ASSERT(elem_size > 0); @@ -588,17 +563,17 @@ DUK_WO_NORETURN(return NULL;); } - done: +done: DUK_ASSERT(duk_is_buffer(thr, -1)); return duk_known_hbuffer(thr, -1); - slow_copy: +slow_copy: /* XXX: fast path for typed arrays and other buffer objects? */ (void) duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_LENGTH); len = duk_to_int_clamped(thr, -1, 0, DUK_INT_MAX); duk_pop(thr); - buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) len); /* no zeroing, all indices get initialized */ + buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) len); /* no zeroing, all indices get initialized */ for (i = 0; i < len; i++) { /* XXX: fast path for array or buffer arguments? */ duk_get_prop_index(thr, 0, (duk_uarridx_t) i); @@ -607,7 +582,7 @@ } goto done; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer constructor @@ -624,11 +599,7 @@ h_buf = duk__hbufobj_fixed_from_argvalue(thr); DUK_ASSERT(h_buf != NULL); - duk_push_buffer_object(thr, - -1, - 0, - DUK_HBUFFER_FIXED_GET_SIZE((duk_hbuffer_fixed *) (void *) h_buf), - DUK_BUFOBJ_UINT8ARRAY); + duk_push_buffer_object(thr, -1, 0, DUK_HBUFFER_FIXED_GET_SIZE((duk_hbuffer_fixed *) (void *) h_buf), DUK_BUFOBJ_UINT8ARRAY); duk_push_hobject_bidx(thr, DUK_BIDX_NODEJS_BUFFER_PROTOTYPE); duk_set_prototype(thr, -2); @@ -636,7 +607,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * ArrayBuffer, DataView, and TypedArray constructors @@ -660,9 +631,8 @@ h_val = (duk_hbuffer *) duk_known_hbuffer(thr, -1); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), DUK_BIDX_ARRAYBUFFER_PROTOTYPE); DUK_ASSERT(h_bufobj != NULL); @@ -671,11 +641,10 @@ return 1; - fail_length: +fail_length: DUK_DCERROR_RANGE_INVALID_LENGTH(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ - +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Format of magic, bits: * 0...1: elem size shift (0-3) @@ -715,8 +684,8 @@ * element type. */ magic = (duk_small_uint_t) duk_get_current_magic(thr); - shift = magic & 0x03U; /* bits 0...1: shift */ - elem_type = (magic >> 2) & 0x0fU; /* bits 2...5: type */ + shift = magic & 0x03U; /* bits 0...1: shift */ + elem_type = (magic >> 2) & 0x0fU; /* bits 2...5: type */ elem_size = 1U << shift; align_mask = elem_size - 1; DUK_ASSERT(elem_type < sizeof(duk__buffer_proto_from_elemtype) / sizeof(duk_uint8_t)); @@ -727,8 +696,12 @@ DUK_DD(DUK_DDPRINT("typedarray constructor, magic=%d, shift=%d, elem_type=%d, " "elem_size=%d, proto_bidx=%d, class_num=%d", - (int) magic, (int) shift, (int) elem_type, (int) elem_size, - (int) proto_bidx, (int) class_num)); + (int) magic, + (int) shift, + (int) elem_type, + (int) elem_size, + (int) proto_bidx, + (int) class_num)); /* Argument variants. When the argument is an ArrayBuffer a view to * the same buffer is created; otherwise a new ArrayBuffer is always @@ -742,7 +715,7 @@ duk_hbufobj_promote_plain(thr, 0); tv = duk_get_tval(thr, 0); - DUK_ASSERT(tv != NULL); /* arg count */ + DUK_ASSERT(tv != NULL); /* arg count */ if (DUK_TVAL_IS_OBJECT(tv)) { h_obj = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h_obj != NULL); @@ -762,8 +735,7 @@ goto fail_arguments; } byte_offset = (duk_uint_t) byte_offset_signed; - if (byte_offset > h_bufarg->length || - (byte_offset & align_mask) != 0) { + if (byte_offset > h_bufarg->length || (byte_offset & align_mask) != 0) { /* Must be >= 0 and multiple of element size. */ goto fail_arguments; } @@ -803,9 +775,8 @@ DUK_ASSERT((elem_length << shift) == byte_length); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(class_num), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(class_num), (duk_small_int_t) proto_bidx); h_val = h_bufarg->buf; if (h_val == NULL) { @@ -848,11 +819,13 @@ "src byte_length=%ld, src shift=%d, " "src/dst elem_length=%ld; " "dst shift=%d -> dst byte_length=%ld", - (long) h_bufarg->length, (int) h_bufarg->shift, - (long) elem_length_signed, (int) shift, + (long) h_bufarg->length, + (int) h_bufarg->shift, + (long) elem_length_signed, + (int) shift, (long) (elem_length_signed << shift))); - copy_mode = 2; /* default is explicit index read/write copy */ + copy_mode = 2; /* default is explicit index read/write copy */ #if !defined(DUK_USE_PREFER_SIZE) /* With a size optimized build copy_mode 2 is enough. * Modes 0 and 1 are faster but conceptually the same. @@ -861,14 +834,14 @@ if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { if ((duk__buffer_elemtype_copy_compatibleelem_type & (1 << h_bufarg->elem_type)) != 0) { DUK_DDD(DUK_DDDPRINT("source/target are copy compatible, memcpy")); - DUK_ASSERT(shift == h_bufarg->shift); /* byte sizes will match */ + DUK_ASSERT(shift == h_bufarg->shift); /* byte sizes will match */ copy_mode = 0; } else { DUK_DDD(DUK_DDDPRINT("source/target not copy compatible but valid, fast copy")); copy_mode = 1; } } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ } else { /* Array or Array-like */ elem_length_signed = (duk_int_t) duk_get_length(thr, 0); @@ -893,8 +866,7 @@ goto fail_arguments; } - DUK_DDD(DUK_DDDPRINT("elem_length=%ld, byte_length=%ld", - (long) elem_length, (long) byte_length)); + DUK_DDD(DUK_DDDPRINT("elem_length=%ld, byte_length=%ld", (long) elem_length, (long) byte_length)); /* ArrayBuffer argument is handled specially above; the rest of the * argument variants are handled by shared code below. @@ -909,11 +881,10 @@ h_val = duk_known_hbuffer(thr, -1); DUK_ASSERT(h_val != NULL); - h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(class_num), - (duk_small_int_t) proto_bidx); + h_bufobj = + duk_push_bufobj_raw(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(class_num), + (duk_small_int_t) proto_bidx); h_bufobj->buf = h_val; DUK_HBUFFER_INCREF(thr, h_val); @@ -953,7 +924,9 @@ p_src = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufarg); DUK_DDD(DUK_DDDPRINT("using memcpy: p_src=%p, p_dst=%p, byte_length=%ld", - (void *) p_src, (void *) p_dst, (long) byte_length)); + (void *) p_src, + (void *) p_dst, + (long) byte_length)); duk_memcpy_unsafe((void *) p_dst, (const void *) p_src, (size_t) byte_length); break; @@ -983,13 +956,18 @@ DUK_DDD(DUK_DDDPRINT("using fast copy: p_src=%p, p_src_end=%p, p_dst=%p, " "src_elem_size=%d, dst_elem_size=%d", - (void *) p_src, (void *) p_src_end, (void *) p_dst, - (int) src_elem_size, (int) dst_elem_size)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst, + (int) src_elem_size, + (int) dst_elem_size)); while (p_src != p_src_end) { DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: " "p_src=%p, p_src_end=%p, p_dst=%p", - (void *) p_src, (void *) p_src_end, (void *) p_dst)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst)); /* A validated read() is always a number, so it's write coercion * is always side effect free an won't invalidate pointers etc. */ @@ -1001,7 +979,7 @@ } break; } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ case 2: { /* Copy values by index reads and writes. Let virtual * property handling take care of coercion. @@ -1030,10 +1008,10 @@ return 1; - fail_arguments: +fail_arguments: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* When bufferobject support is disabled, new Uint8Array() could still be * supported to create a plain fixed buffer. Disabled for now. */ @@ -1060,8 +1038,8 @@ fail_arguments: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* 0 */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* 0 */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_dataview_constructor(duk_hthread *thr) { @@ -1084,9 +1062,8 @@ DUK_ASSERT(offset + length <= h_bufarg->length); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATAVIEW), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATAVIEW), DUK_BIDX_DATAVIEW_PROTOTYPE); h_val = h_bufarg->buf; @@ -1109,7 +1086,7 @@ DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * ArrayBuffer.isView() @@ -1135,7 +1112,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Uint8Array.allocPlain() @@ -1146,7 +1123,7 @@ duk__hbufobj_fixed_from_argvalue(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Uint8Array.plainOf() @@ -1175,7 +1152,7 @@ } return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer: toString(encoding, start, end) @@ -1206,12 +1183,11 @@ &end_offset); slice_length = (duk_size_t) (end_offset - start_offset); - buf_slice = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, slice_length); /* all bytes initialized below */ + buf_slice = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, slice_length); /* all bytes initialized below */ DUK_ASSERT(buf_slice != NULL); /* Neutered or uncovered, TypeError. */ - if (h_this->buf == NULL || - !DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, (duk_size_t) start_offset + slice_length)) { + if (h_this->buf == NULL || !DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, (duk_size_t) start_offset + slice_length)) { DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -1234,7 +1210,7 @@ duk_set_top(thr, 1); return duk_textdecoder_decode_utf8_nodejs(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype: toJSON() @@ -1264,19 +1240,19 @@ /* XXX: uninitialized would be OK */ DUK_ASSERT_DISABLE((duk_size_t) h_this->length <= (duk_size_t) DUK_UINT32_MAX); - tv = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) h_this->length); /* XXX: needs revision with >4G buffers */ + tv = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) h_this->length); /* XXX: needs revision with >4G buffers */ DUK_ASSERT(!duk_is_bare_object(thr, -1)); DUK_ASSERT(h_this->buf != NULL); buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); for (i = 0, n = h_this->length; i < n; i++) { - DUK_TVAL_SET_U32(tv + i, (duk_uint32_t) bufi); /* no need for decref or incref */ + DUK_TVAL_SET_U32(tv + i, (duk_uint32_t) bufi); /* no need for decref or incref */ } duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_DATA); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.equals() @@ -1311,14 +1287,14 @@ * matters is to be memory safe. */ - if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg1) && - DUK_HBUFOBJ_VALID_SLICE(h_bufarg2)) { - comp_res = duk_js_data_compare((const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg1->buf) + h_bufarg1->offset, - (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg2->buf) + h_bufarg2->offset, - (duk_size_t) h_bufarg1->length, - (duk_size_t) h_bufarg2->length); + if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg1) && DUK_HBUFOBJ_VALID_SLICE(h_bufarg2)) { + comp_res = duk_js_data_compare( + (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg1->buf) + h_bufarg1->offset, + (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg2->buf) + h_bufarg2->offset, + (duk_size_t) h_bufarg1->length, + (duk_size_t) h_bufarg2->length); } else { - comp_res = -1; /* either nonzero value is ok */ + comp_res = -1; /* either nonzero value is ok */ } if (magic & 0x01U) { @@ -1331,7 +1307,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.fill() @@ -1376,7 +1352,10 @@ &fill_end); DUK_DDD(DUK_DDDPRINT("fill: fill_value=%02x, fill_offset=%ld, fill_end=%ld, view length=%ld", - (unsigned int) fill_value, (long) fill_offset, (long) fill_end, (long) h_this->length)); + (unsigned int) fill_value, + (long) fill_offset, + (long) fill_end, + (long) h_this->length)); DUK_ASSERT(fill_end - fill_offset >= 0); DUK_ASSERT(h_this->buf != NULL); @@ -1405,7 +1384,7 @@ duk_push_this(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.write(string, offset, length, encoding) @@ -1448,7 +1427,7 @@ duk_push_uint(thr, length); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.copy() @@ -1483,8 +1462,11 @@ DUK_DDD(DUK_DDDPRINT("checking copy args: target_start=%ld, target_length=%ld, " "source_start=%ld, source_end=%ld, source_length=%ld", - (long) target_start, (long) h_bufarg->length, - (long) source_start, (long) source_end, (long) source_length)); + (long) target_start, + (long) h_bufarg->length, + (long) source_start, + (long) source_end, + (long) source_length)); /* This behavior mostly mimics Node.js now. */ @@ -1495,9 +1477,9 @@ source_ustart = (duk_uint_t) source_start; source_uend = (duk_uint_t) source_end; target_ustart = (duk_uint_t) target_start; - if (source_ustart >= source_uend || /* crossed offsets or zero size */ - source_ustart >= (duk_uint_t) source_length || /* source out-of-bounds (but positive) */ - target_ustart >= (duk_uint_t) target_length) { /* target out-of-bounds (but positive) */ + if (source_ustart >= source_uend || /* crossed offsets or zero size */ + source_ustart >= (duk_uint_t) source_length || /* source out-of-bounds (but positive) */ + target_ustart >= (duk_uint_t) target_length) { /* target out-of-bounds (but positive) */ goto silent_ignore; } if (source_uend >= (duk_uint_t) source_length) { @@ -1513,13 +1495,14 @@ * values in duk_int_t range. Adding them as duk_uint_t * values is then guaranteed not to overflow. */ - DUK_ASSERT(target_ustart + copy_size >= target_ustart); /* no overflow */ - DUK_ASSERT(target_ustart + copy_size >= copy_size); /* no overflow */ + DUK_ASSERT(target_ustart + copy_size >= target_ustart); /* no overflow */ + DUK_ASSERT(target_ustart + copy_size >= copy_size); /* no overflow */ copy_size = (duk_uint_t) target_length - target_ustart; } DUK_DDD(DUK_DDDPRINT("making copy: target_ustart=%lu source_ustart=%lu copy_size=%lu", - (unsigned long) target_ustart, (unsigned long) source_ustart, + (unsigned long) target_ustart, + (unsigned long) source_ustart, (unsigned long) copy_size)); DUK_ASSERT(copy_size >= 1); @@ -1529,8 +1512,8 @@ DUK_ASSERT(target_ustart + copy_size <= (duk_uint_t) target_length); /* Ensure copy is covered by underlying buffers. */ - DUK_ASSERT(h_bufarg->buf != NULL); /* length check */ - DUK_ASSERT(h_this->buf != NULL); /* length check */ + DUK_ASSERT(h_bufarg->buf != NULL); /* length check */ + DUK_ASSERT(h_this->buf != NULL); /* length check */ if (DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufarg, target_ustart + copy_size) && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, source_ustart + copy_size)) { /* Must use memmove() because copy area may overlap (source and target @@ -1543,18 +1526,18 @@ DUK_DDD(DUK_DDDPRINT("buffer copy not covered by underlying buffer(s), ignoring")); } - silent_ignore: +silent_ignore: /* Return value is like write(), number of bytes written. * The return value matters because of code like: * "off += buf.copy(...)". - */ + */ duk_push_uint(thr, copy_size); return 1; - fail_bounds: +fail_bounds: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * TypedArray.prototype.set() @@ -1666,16 +1649,15 @@ } /* Nominal size check. */ - src_length = h_bufarg->length; /* bytes in source */ - dst_length_elems = (src_length >> h_bufarg->shift); /* elems in source and dest */ - dst_length = dst_length_elems << h_this->shift; /* bytes in dest */ + src_length = h_bufarg->length; /* bytes in source */ + dst_length_elems = (src_length >> h_bufarg->shift); /* elems in source and dest */ + dst_length = dst_length_elems << h_this->shift; /* bytes in dest */ if ((dst_length >> h_this->shift) != dst_length_elems) { /* Byte length would overflow. */ /* XXX: easier check with less code? */ goto fail_args; } - DUK_DDD(DUK_DDDPRINT("nominal size check: src_length=%ld, dst_length=%ld", - (long) src_length, (long) dst_length)); + DUK_DDD(DUK_DDDPRINT("nominal size check: src_length=%ld, dst_length=%ld", (long) src_length, (long) dst_length)); DUK_ASSERT(offset_bytes <= h_this->length); if (dst_length > h_this->length - offset_bytes) { /* Overflow not an issue because subtraction is used on the right @@ -1696,8 +1678,7 @@ * cover the copy. No side effects are allowed after the check * so that the validity status doesn't change. */ - if (!DUK_HBUFOBJ_VALID_SLICE(h_this) || - !DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { + if (!DUK_HBUFOBJ_VALID_SLICE(h_this) || !DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { /* The condition could be more narrow and check for the * copy area only, but there's no need for fine grained * behavior when the underlying buffer is misconfigured. @@ -1728,7 +1709,7 @@ return 0; } DUK_DDD(DUK_DDDPRINT("fast path: views are not compatible with a byte copy, copy by item")); -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ /* We want to avoid making a copy to process set() but that's * not always possible: the source and the target may overlap @@ -1748,11 +1729,13 @@ DUK_DDD(DUK_DDDPRINT("overlap check: p_src_base=%p, src_length=%ld, " "p_dst_base=%p, dst_length=%ld", - (void *) p_src_base, (long) src_length, - (void *) p_dst_base, (long) dst_length)); + (void *) p_src_base, + (long) src_length, + (void *) p_dst_base, + (long) dst_length)); - if (p_src_base >= p_dst_base + dst_length || /* source starts after dest ends */ - p_src_base + src_length <= p_dst_base) { /* source ends before dest starts */ + if (p_src_base >= p_dst_base + dst_length || /* source starts after dest ends */ + p_src_base + src_length <= p_dst_base) { /* source ends before dest starts */ no_overlap = 1; } @@ -1769,14 +1752,16 @@ DUK_ASSERT(p_src_copy != NULL); duk_memcpy_unsafe((void *) p_src_copy, (const void *) p_src_base, (size_t) src_length); - p_src_base = p_src_copy; /* use p_src_base from now on */ + p_src_base = p_src_copy; /* use p_src_base from now on */ } /* Value stack intentionally mixed size here. */ DUK_DDD(DUK_DDDPRINT("after overlap check: p_src_base=%p, src_length=%ld, " "p_dst_base=%p, dst_length=%ld, valstack top=%ld", - (void *) p_src_base, (long) src_length, - (void *) p_dst_base, (long) dst_length, + (void *) p_src_base, + (long) src_length, + (void *) p_dst_base, + (long) dst_length, (long) duk_get_top(thr))); /* Ready to make the copy. We must proceed element by element @@ -1796,7 +1781,9 @@ while (p_src != p_src_end) { DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: " "p_src=%p, p_src_end=%p, p_dst=%p", - (void *) p_src, (void *) p_src_end, (void *) p_dst)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst)); /* A validated read() is always a number, so it's write coercion * is always side effect free an won't invalidate pointers etc. */ @@ -1846,10 +1833,10 @@ return 0; - fail_args: +fail_args: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.slice(start, end) @@ -1944,7 +1931,7 @@ /* fall through */ } } - tv = NULL; /* No longer valid nor needed. */ + tv = NULL; /* No longer valid nor needed. */ h_this = duk__require_bufobj_this(thr); @@ -1982,22 +1969,21 @@ * be an Uint8Array but inherit from Buffer.prototype. */ res_class_num = DUK_HOBJECT_GET_CLASS_NUMBER((duk_hobject *) h_this); - DUK_ASSERT(res_class_num >= DUK_HOBJECT_CLASS_BUFOBJ_MIN); /* type check guarantees */ + DUK_ASSERT(res_class_num >= DUK_HOBJECT_CLASS_BUFOBJ_MIN); /* type check guarantees */ DUK_ASSERT(res_class_num <= DUK_HOBJECT_CLASS_BUFOBJ_MAX); res_proto_bidx = duk__buffer_proto_from_classnumres_class_num - DUK_HOBJECT_CLASS_BUFOBJ_MIN; if (magic & 0x04) { res_proto_bidx = DUK_BIDX_NODEJS_BUFFER_PROTOTYPE; } - h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(res_class_num), - res_proto_bidx); + h_bufobj = + duk_push_bufobj_raw(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(res_class_num), + res_proto_bidx); DUK_ASSERT(h_bufobj != NULL); DUK_ASSERT(h_bufobj->length == 0); - h_bufobj->shift = h_this->shift; /* inherit */ - h_bufobj->elem_type = h_this->elem_type; /* inherit */ + h_bufobj->shift = h_this->shift; /* inherit */ + h_bufobj->elem_type = h_this->elem_type; /* inherit */ h_bufobj->is_typedarray = magic & 0x01; DUK_ASSERT(h_bufobj->is_typedarray == 0 || h_bufobj->is_typedarray == 1); @@ -2011,7 +1997,9 @@ duk_uint8_t *p_copy; duk_size_t copy_length; - p_copy = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, (duk_size_t) slice_length); /* must be zeroed, not all bytes always copied */ + p_copy = (duk_uint8_t *) duk_push_fixed_buffer_zero( + thr, + (duk_size_t) slice_length); /* must be zeroed, not all bytes always copied */ DUK_ASSERT(p_copy != NULL); /* Copy slice, respecting underlying buffer limits; remainder @@ -2029,7 +2017,7 @@ h_bufobj->length = slice_length; DUK_ASSERT(h_bufobj->offset == 0); - duk_pop(thr); /* reachable so pop OK */ + duk_pop(thr); /* reachable so pop OK */ } else { h_bufobj->buf = h_val; DUK_HBUFFER_INCREF(thr, h_val); @@ -2042,7 +2030,7 @@ */ DUK_ASSERT(h_bufobj->buf_prop == NULL); - h_bufobj->buf_prop = h_this->buf_prop; /* may be NULL */ + h_bufobj->buf_prop = h_this->buf_prop; /* may be NULL */ DUK_HOBJECT_INCREF_ALLOWNULL(thr, (duk_hobject *) h_bufobj->buf_prop); } /* unbalanced stack on purpose */ @@ -2050,7 +2038,7 @@ DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.isEncoding() @@ -2063,11 +2051,11 @@ /* only accept lowercase 'utf8' now. */ encoding = duk_to_string(thr, 0); - DUK_ASSERT(duk_is_string(thr, 0)); /* guaranteed by duk_to_string() */ + DUK_ASSERT(duk_is_string(thr, 0)); /* guaranteed by duk_to_string() */ duk_push_boolean(thr, DUK_STRCMP(encoding, "utf8") == 0); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.isBuffer() @@ -2079,7 +2067,7 @@ duk_hobject *h_proto; duk_bool_t ret = 0; - DUK_ASSERT(duk_get_top(thr) >= 1); /* nargs */ + DUK_ASSERT(duk_get_top(thr) >= 1); /* nargs */ h = duk_get_hobject(thr, 0); if (h != NULL) { h_proto = thr->builtinsDUK_BIDX_NODEJS_BUFFER_PROTOTYPE; @@ -2094,7 +2082,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.byteLength() @@ -2125,7 +2113,7 @@ duk_push_size_t(thr, len); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.concat() @@ -2156,13 +2144,13 @@ /* Neutered checks not necessary here: neutered buffers have * zero 'length' so we'll effectively skip them. */ - DUK_ASSERT_TOP(thr, 2); /* array totalLength */ - duk_get_prop_index(thr, 0, (duk_uarridx_t) i); /* -> array totalLength buf */ + DUK_ASSERT_TOP(thr, 2); /* array totalLength */ + duk_get_prop_index(thr, 0, (duk_uarridx_t) i); /* -> array totalLength buf */ h_bufobj = duk__require_bufobj_value(thr, 2); DUK_ASSERT(h_bufobj != NULL); total_length += h_bufobj->length; if (DUK_UNLIKELY(total_length < h_bufobj->length)) { - DUK_DCERROR_RANGE_INVALID_ARGS(thr); /* Wrapped. */ + DUK_DCERROR_RANGE_INVALID_ARGS(thr); /* Wrapped. */ } duk_pop(thr); } @@ -2188,18 +2176,18 @@ } h_bufres = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_UINT8ARRAY), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_UINT8ARRAY), DUK_BIDX_NODEJS_BUFFER_PROTOTYPE); DUK_ASSERT(h_bufres != NULL); - p = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, total_length); /* must be zeroed, all bytes not necessarily written over */ + p = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, + total_length); /* must be zeroed, all bytes not necessarily written over */ DUK_ASSERT(p != NULL); space_left = (duk_size_t) total_length; for (i = 0; i < n; i++) { - DUK_ASSERT_TOP(thr, 4); /* array totalLength bufres buf */ + DUK_ASSERT_TOP(thr, 4); /* array totalLength bufres buf */ duk_get_prop_index(thr, 0, (duk_uarridx_t) i); h_bufobj = duk__require_bufobj_value(thr, 4); @@ -2210,11 +2198,8 @@ copy_size = space_left; } - if (h_bufobj->buf != NULL && - DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { - duk_memcpy_unsafe((void *) p, - (const void *) DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj), - copy_size); + if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { + duk_memcpy_unsafe((void *) p, (const void *) DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj), copy_size); } else { /* Just skip, leaving zeroes in the result. */ ; @@ -2231,11 +2216,11 @@ h_bufres->is_typedarray = 1; DUK_HBUFOBJ_ASSERT_VALID(h_bufres); - duk_pop(thr); /* pop plain buffer, now reachable through h_bufres */ + duk_pop(thr); /* pop plain buffer, now reachable through h_bufres */ - return 1; /* return h_bufres */ + return 1; /* return h_bufres */ } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Shared readfield and writefield methods @@ -2251,15 +2236,15 @@ * 4: signed: 1=yes, 0=no * 5: typedarray: 1=yes, 0=no */ -#define DUK__FLD_8BIT 0 -#define DUK__FLD_16BIT 1 -#define DUK__FLD_32BIT 2 -#define DUK__FLD_FLOAT 3 -#define DUK__FLD_DOUBLE 4 -#define DUK__FLD_VARINT 5 -#define DUK__FLD_BIGENDIAN (1 << 3) -#define DUK__FLD_SIGNED (1 << 4) -#define DUK__FLD_TYPEDARRAY (1 << 5) +#define DUK__FLD_8BIT 0 +#define DUK__FLD_16BIT 1 +#define DUK__FLD_32BIT 2 +#define DUK__FLD_FLOAT 3 +#define DUK__FLD_DOUBLE 4 +#define DUK__FLD_VARINT 5 +#define DUK__FLD_BIGENDIAN (1 << 3) +#define DUK__FLD_SIGNED (1 << 4) +#define DUK__FLD_TYPEDARRAY (1 << 5) /* XXX: split into separate functions for each field type? */ DUK_INTERNAL duk_ret_t duk_bi_buffer_readfield(duk_hthread *thr) { @@ -2283,7 +2268,7 @@ magic_signed = magic & 0x0010U; magic_typedarray = magic & 0x0020U; - h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ + h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ DUK_ASSERT(h_this != NULL); buffer_length = h_this->length; @@ -2295,9 +2280,9 @@ if (magic_typedarray) { no_assert = 0; #if defined(DUK_USE_INTEGER_LE) - endswap = !duk_to_boolean(thr, 1); /* 1=little endian */ + endswap = !duk_to_boolean(thr, 1); /* 1=little endian */ #else - endswap = duk_to_boolean(thr, 1); /* 1=little endian */ + endswap = duk_to_boolean(thr, 1); /* 1=little endian */ #endif } else { no_assert = duk_to_boolean(thr, (magic_ftype == DUK__FLD_VARINT) ? 2 : 1); @@ -2321,17 +2306,21 @@ DUK_DDD(DUK_DDDPRINT("readfield, buffer_length=%ld, offset=%ld, no_assert=%d, " "magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, " "endswap=%u", - (long) buffer_length, (long) offset, (int) no_assert, - (unsigned int) magic, (int) magic_ftype, (int) (magic_bigendian >> 3), - (int) (magic_signed >> 4), (int) endswap)); + (long) buffer_length, + (long) offset, + (int) no_assert, + (unsigned int) magic, + (int) magic_ftype, + (int) (magic_bigendian >> 3), + (int) (magic_signed >> 4), + (int) endswap)); /* Update 'buffer_length' to be the effective, safe limit which * takes into account the underlying buffer. This value will be * potentially invalidated by any side effect. */ check_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, buffer_length); - DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", - (long) buffer_length, (long) check_length)); + DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", (long) buffer_length, (long) check_length)); if (h_this->buf) { buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); @@ -2433,7 +2422,7 @@ #endif const duk_uint8_t *p; - field_bytelen = duk_get_int(thr, 1); /* avoid side effects! */ + field_bytelen = duk_get_int(thr, 1); /* avoid side effects! */ if (field_bytelen < 1 || field_bytelen > 6) { goto fail_field_length; } @@ -2451,12 +2440,12 @@ /* Gather in big endian */ i = 0; i_step = 1; - i_end = field_bytelen; /* one i_step over */ + i_end = field_bytelen; /* one i_step over */ } else { /* Gather in little endian */ i = field_bytelen - 1; i_step = -1; - i_end = -1; /* one i_step over */ + i_end = -1; /* one i_step over */ } #if defined(DUK_USE_64BIT_OPS) @@ -2498,16 +2487,16 @@ #endif break; } - default: { /* should never happen but default here */ + default: { /* should never happen but default here */ goto fail_bounds; } } return 1; - fail_neutered: - fail_field_length: - fail_bounds: +fail_neutered: +fail_field_length: +fail_bounds: if (no_assert) { /* Node.js return value for noAssert out-of-bounds reads is * usually (but not always) NaN. Return NaN consistently. @@ -2517,7 +2506,7 @@ } DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) /* XXX: split into separate functions for each field type? */ @@ -2544,7 +2533,7 @@ magic_typedarray = magic & 0x0020U; DUK_UNREF(magic_signed); - h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ + h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ DUK_ASSERT(h_this != NULL); buffer_length = h_this->length; @@ -2556,11 +2545,11 @@ if (magic_typedarray) { no_assert = 0; #if defined(DUK_USE_INTEGER_LE) - endswap = !duk_to_boolean(thr, 2); /* 1=little endian */ + endswap = !duk_to_boolean(thr, 2); /* 1=little endian */ #else - endswap = duk_to_boolean(thr, 2); /* 1=little endian */ + endswap = duk_to_boolean(thr, 2); /* 1=little endian */ #endif - duk_swap(thr, 0, 1); /* offset/value order different from Node.js */ + duk_swap(thr, 0, 1); /* offset/value order different from Node.js */ } else { no_assert = duk_to_boolean(thr, (magic_ftype == DUK__FLD_VARINT) ? 3 : 2); #if defined(DUK_USE_INTEGER_LE) @@ -2599,9 +2588,15 @@ DUK_DDD(DUK_DDDPRINT("writefield, value=%!T, buffer_length=%ld, offset=%ld, no_assert=%d, " "magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, " "endswap=%u", - duk_get_tval(thr, 0), (long) buffer_length, (long) offset, (int) no_assert, - (unsigned int) magic, (int) magic_ftype, (int) (magic_bigendian >> 3), - (int) (magic_signed >> 4), (int) endswap)); + duk_get_tval(thr, 0), + (long) buffer_length, + (long) offset, + (int) no_assert, + (unsigned int) magic, + (int) magic_ftype, + (int) (magic_bigendian >> 3), + (int) (magic_signed >> 4), + (int) endswap)); /* Coerce value to a number before computing check_length, so that * the field type specific coercion below can't have side effects @@ -2614,8 +2609,7 @@ * potentially invalidated by any side effect. */ check_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, buffer_length); - DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", - (long) buffer_length, (long) check_length)); + DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", (long) buffer_length, (long) check_length)); if (h_this->buf) { buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); @@ -2718,12 +2712,12 @@ if (magic_bigendian) { /* Write in big endian */ - i = field_bytelen; /* one i_step added at top of loop */ + i = field_bytelen; /* one i_step added at top of loop */ i_step = -1; i_end = 0; } else { /* Write in little endian */ - i = -1; /* one i_step added at top of loop */ + i = -1; /* one i_step added at top of loop */ i_step = 1; i_end = field_bytelen - 1; } @@ -2741,7 +2735,7 @@ i += i_step; DUK_ASSERT(i >= 0 && i < field_bytelen); pi = (duk_uint8_t) (tmp & 0xff); - tmp = tmp >> 8; /* unnecessary shift for last byte */ + tmp = tmp >> 8; /* unnecessary shift for last byte */ } while (i != i_end); #else tmp = duk_to_number(thr, 0); @@ -2751,12 +2745,12 @@ tmp = DUK_FLOOR(tmp); DUK_ASSERT(i >= 0 && i < field_bytelen); pi = (duk_uint8_t) (DUK_FMOD(tmp, 256.0)); - tmp = tmp / 256.0; /* unnecessary div for last byte */ + tmp = tmp / 256.0; /* unnecessary div for last byte */ } while (i != i_end); #endif break; } - default: { /* should never happen but default here */ + default: { /* should never happen but default here */ goto fail_bounds; } } @@ -2773,9 +2767,9 @@ duk_push_uint(thr, offset + (duk_uint_t) nbytes); return 1; - fail_neutered: - fail_field_length: - fail_bounds: +fail_neutered: +fail_field_length: +fail_bounds: if (no_assert) { /* Node.js return value for failed writes is offset + #bytes * that would have been written. @@ -2791,7 +2785,7 @@ } DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Accessors for .buffer, .byteLength, .byteOffset @@ -2802,9 +2796,8 @@ duk_hbufobj *h_res; h_res = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), DUK_BIDX_ARRAYBUFFER_PROTOTYPE); DUK_ASSERT(h_res != NULL); DUK_UNREF(h_res); @@ -2844,13 +2837,13 @@ * matches view0. */ h_arrbuf->offset = 0; - DUK_ASSERT(h_bufobj->offset + h_bufobj->length >= h_bufobj->offset); /* Wrap check on creation. */ + DUK_ASSERT(h_bufobj->offset + h_bufobj->length >= h_bufobj->offset); /* Wrap check on creation. */ h_arrbuf->length = h_bufobj->offset + h_bufobj->length; DUK_ASSERT(h_arrbuf->buf_prop == NULL); DUK_ASSERT(h_bufobj->buf_prop == NULL); h_bufobj->buf_prop = (duk_hobject *) h_arrbuf; - DUK_HBUFOBJ_INCREF(thr, h_arrbuf); /* Now reachable and accounted for. */ + DUK_HBUFOBJ_INCREF(thr, h_arrbuf); /* Now reachable and accounted for. */ } /* Left on stack; pushed for the second time below (OK). */ @@ -2888,7 +2881,7 @@ duk_hbuffer *h_buf; h_buf = (duk_hbuffer *) h_bufobj; - DUK_ASSERT(DUK_HBUFFER_GET_SIZE(h_buf) <= DUK_UINT_MAX); /* Buffer limits. */ + DUK_ASSERT(DUK_HBUFFER_GET_SIZE(h_buf) <= DUK_UINT_MAX); /* Buffer limits. */ duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_buf)); } else { /* If neutered must return 0; length is zeroed during @@ -2898,7 +2891,7 @@ } return 1; } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* No .buffer getter without ArrayBuffer support. */ #if 0 DUK_INTERNAL duk_ret_t duk_bi_typedarray_buffer_getter(duk_hthread *thr) { @@ -2920,4 +2913,4 @@ duk_push_uint(thr, DUK_HBUFFER_GET_SIZE(h_buf)); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_cbor.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_cbor.c
Changed
@@ -194,7 +194,7 @@ p += 8; enc_ctx->ptr = p; } -#else /* DUK_CBOR_DOUBLE_AS_IS */ +#else /* DUK_CBOR_DOUBLE_AS_IS */ DUK_LOCAL void duk__cbor_encode_double_fp(duk_cbor_encode_context *enc_ctx, double d) { duk_double_union u; duk_uint16_t u16; @@ -229,8 +229,7 @@ duk_bool_t use_half_float; use_half_float = - (u.uc0 == 0 && u.uc1 == 0 && u.uc2 == 0 && u.uc3 == 0 && - u.uc4 == 0 && (u.uc5 & 0x03U) == 0); + (u.uc0 == 0 && u.uc1 == 0 && u.uc2 == 0 && u.uc3 == 0 && u.uc4 == 0 && (u.uc5 & 0x03U) == 0); if (use_half_float) { duk_uint32_t t; @@ -382,9 +381,9 @@ /* Most important path is integers. The floor() test will be true * for Inf too (but not NaN). */ - d_floor = DUK_FLOOR(d); /* identity if d is +/- 0.0, NaN, or +/- Infinity */ + d_floor = DUK_FLOOR(d); /* identity if d is +/- 0.0, NaN, or +/- Infinity */ if (DUK_LIKELY(duk_double_equals(d_floor, d) != 0)) { - DUK_ASSERT(!DUK_ISNAN(d)); /* NaN == NaN compares false. */ + DUK_ASSERT(!DUK_ISNAN(d)); /* NaN == NaN compares false. */ if (DUK_SIGNBIT(d)) { if (d >= -4294967296.0) { d = -1.0 - d; @@ -423,7 +422,7 @@ DUK_ASSERT(DUK_FPCLASSIFY(d) != DUK_FP_ZERO); duk__cbor_encode_double_fp(enc_ctx, d); } -#endif /* DUK_CBOR_DOUBLE_AS_IS */ +#endif /* DUK_CBOR_DOUBLE_AS_IS */ DUK_LOCAL void duk__cbor_encode_string_top(duk_cbor_encode_context *enc_ctx) { const duk_uint8_t *str; @@ -474,7 +473,8 @@ #elif defined(DUK_CBOR_BYTE_STRINGS) duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, 0x40U); #else - duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, + duk__cbor_encode_uint32(enc_ctx, + (duk_uint32_t) len, (DUK_LIKELY(duk_unicode_is_utf8_compatible(str, len) != 0) ? 0x60U : 0x40U)); #endif duk__cbor_encode_ensure(enc_ctx, len); @@ -534,14 +534,14 @@ * indefinite length. This works well up to 23 * properties which is practical and good enough. */ - off_ib = (duk_size_t) (enc_ctx->ptr - enc_ctx->buf); /* XXX: get_offset? */ + off_ib = (duk_size_t) (enc_ctx->ptr - enc_ctx->buf); /* XXX: get_offset? */ count = 0U; p = enc_ctx->ptr; - *p++ = 0xa0U + 0x1fU; /* indefinite length */ + *p++ = 0xa0U + 0x1fU; /* indefinite length */ enc_ctx->ptr = p; duk_enum(enc_ctx->thr, -1, DUK_ENUM_OWN_PROPERTIES_ONLY); while (duk_next(enc_ctx->thr, -1, 1 /*get_value*/)) { - duk_insert(enc_ctx->thr, -2); /* ... key value -> ... value key */ + duk_insert(enc_ctx->thr, -2); /* ... key value -> ... value key */ duk__cbor_encode_value(enc_ctx); duk__cbor_encode_value(enc_ctx); count++; @@ -556,7 +556,7 @@ } else { duk__cbor_encode_ensure(enc_ctx, 1); p = enc_ctx->ptr; - *p++ = 0xffU; /* break */ + *p++ = 0xffU; /* break */ enc_ctx->ptr = p; } } @@ -684,7 +684,7 @@ duk_pop(enc_ctx->thr); return; - fail: +fail: duk__cbor_encode_error(enc_ctx); } @@ -761,7 +761,7 @@ } DUK_LOCAL void duk__cbor_decode_rewind(duk_cbor_decode_context *dec_ctx, duk_size_t len) { - DUK_ASSERT(len <= dec_ctx->off); /* Caller must ensure. */ + DUK_ASSERT(len <= dec_ctx->off); /* Caller must ensure. */ dec_ctx->off -= len; } @@ -781,7 +781,7 @@ return res; } - duk__cbor_decode_error(dec_ctx); /* Not enough input. */ + duk__cbor_decode_error(dec_ctx); /* Not enough input. */ return NULL; } @@ -813,16 +813,16 @@ } switch (ai) { - case 0x18U: /* 1 byte */ + case 0x18U: /* 1 byte */ t = (duk_uint32_t) duk__cbor_decode_readbyte(dec_ctx); goto shared_exit; - case 0x19U: /* 2 byte */ + case 0x19U: /* 2 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u16(dec_ctx); goto shared_exit; - case 0x1aU: /* 4 byte */ + case 0x1aU: /* 4 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); goto shared_exit; - case 0x1bU: /* 8 byte */ + case 0x1bU: /* 8 byte */ /* For uint64 it's important to handle the -1.0 part before * casting to double: otherwise the adjustment might be lost * in the cast. Uses: -1.0 - d <=> -(d + 1.0). @@ -879,7 +879,7 @@ * * No fastint check for this path at present. */ - d1 = (duk_double_t) t1; /* XXX: cast helpers */ + d1 = (duk_double_t) t1; /* XXX: cast helpers */ d2 = (duk_double_t) t2 * 4294967296.0; if (negative) { d1 += 1.0; @@ -897,10 +897,10 @@ duk__cbor_decode_error(dec_ctx); return; - shared_exit: +shared_exit: if (negative) { /* XXX: a push and check for fastint API would be nice */ - if ((duk_uint_t) t <= (duk_uint_t) -(DUK_INT_MIN + 1)) { + if ((duk_uint_t) t <= (duk_uint_t) - (DUK_INT_MIN + 1)) { duk_push_int(dec_ctx->thr, -1 - ((duk_int_t) t)); } else { duk_push_number(dec_ctx->thr, -1.0 - (duk_double_t) t); @@ -911,10 +911,8 @@ } DUK_LOCAL void duk__cbor_decode_skip_aival_int(duk_cbor_decode_context *dec_ctx, duk_uint8_t ib) { - const duk_int8_t skips32 = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, -1, -1, -1, -1 - }; + const duk_int8_t skips32 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, -1, -1, -1, -1 }; duk_uint8_t ai; duk_int8_t skip; @@ -937,16 +935,16 @@ } switch (ai) { - case 0x18U: /* 1 byte */ + case 0x18U: /* 1 byte */ t = (duk_uint32_t) duk__cbor_decode_readbyte(dec_ctx); return t; - case 0x19U: /* 2 byte */ + case 0x19U: /* 2 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u16(dec_ctx); return t; - case 0x1aU: /* 4 byte */ + case 0x1aU: /* 4 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); return t; - case 0x1bU: /* 8 byte */ + case 0x1bU: /* 8 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); if (t != 0U) { break; @@ -980,7 +978,7 @@ DUK_LOCAL void duk__cbor_decode_join_buffers(duk_cbor_decode_context *dec_ctx, duk_idx_t count) { duk_size_t total_size = 0; duk_idx_t top = duk_get_top(dec_ctx->thr); - duk_idx_t base = top - count; /* count is >= 1 */ + duk_idx_t base = top - count; /* count is >= 1 */ duk_idx_t idx; duk_uint8_t *p = NULL; @@ -1001,7 +999,7 @@ p += buf_size; } else { total_size += buf_size; - if (DUK_UNLIKELY(total_size < buf_size)) { /* Wrap check. */ + if (DUK_UNLIKELY(total_size < buf_size)) { /* Wrap check. */ duk__cbor_decode_error(dec_ctx); } } @@ -1028,7 +1026,7 @@ duk_require_stack(dec_ctx->thr, 1); duk__cbor_decode_buffer(dec_ctx, expected_base); count++; - if (DUK_UNLIKELY(count <= 0)) { /* Wrap check. */ + if (DUK_UNLIKELY(count <= 0)) { /* Wrap check. */ duk__cbor_decode_error(dec_ctx); } } @@ -1076,10 +1074,10 @@ */ u.uc7 = 0x3fU; u.uc6 = 0x10U + (duk_uint8_t) ((u16 >> 6) & 0x0fU); - u.uc5 = (duk_uint8_t) ((u16 << 2) & 0xffU); /* Mask is really 0xfcU */ + u.uc5 = (duk_uint8_t) ((u16 << 2) & 0xffU); /* Mask is really 0xfcU */ duk_dblunion_little_to_host(&u); - res = u.d - 0.00006103515625; /* 2^(-14) */ + res = u.d - 0.00006103515625; /* 2^(-14) */ if (u16 & 0x8000U) { res = -res; } @@ -1178,7 +1176,7 @@ /* XXX: use bare array? */ duk_push_array(dec_ctx->thr); - for (idx = 0U; ;) { + for (idx = 0U;;) { if (len == 0xffffffffUL && duk__cbor_decode_checkbreak(dec_ctx)) { break; } @@ -1192,7 +1190,7 @@ duk_put_prop_index(dec_ctx->thr, -2, (duk_uarridx_t) idx); idx++; if (idx == 0U) { - goto failure; /* wrapped */ + goto failure; /* wrapped */ } } @@ -1202,7 +1200,7 @@ duk__cbor_decode_objarr_exit(dec_ctx); return 1; - failure: +failure: /* No need to unwind recursion checks, caller will throw. */ return 0; } @@ -1254,7 +1252,7 @@ duk__cbor_decode_objarr_exit(dec_ctx); return 1; - failure: +failure: /* No need to unwind recursion checks, caller will throw. */ return 0; } @@ -1278,7 +1276,7 @@ } #if defined(DUK_CBOR_DECODE_FASTPATH) -#define DUK__CBOR_AI (ib & 0x1fU) +#define DUK__CBOR_AI (ib & 0x1fU) DUK_LOCAL void duk__cbor_decode_value(duk_cbor_decode_context *dec_ctx) { duk_uint8_t ib; @@ -1288,7 +1286,7 @@ * here for simple paths like primitive values. */ - reread_initial_byte: +reread_initial_byte: DUK_DDD(DUK_DDDPRINT("cbor decode off=%ld len=%ld", (long) dec_ctx->off, (long) dec_ctx->len)); ib = duk__cbor_decode_readbyte(dec_ctx); @@ -1297,107 +1295,292 @@ /* XXX: Force full switch with no range check. */ switch (ib) { - case 0x00U: case 0x01U: case 0x02U: case 0x03U: case 0x04U: case 0x05U: case 0x06U: case 0x07U: - case 0x08U: case 0x09U: case 0x0aU: case 0x0bU: case 0x0cU: case 0x0dU: case 0x0eU: case 0x0fU: - case 0x10U: case 0x11U: case 0x12U: case 0x13U: case 0x14U: case 0x15U: case 0x16U: case 0x17U: + case 0x00U: + case 0x01U: + case 0x02U: + case 0x03U: + case 0x04U: + case 0x05U: + case 0x06U: + case 0x07U: + case 0x08U: + case 0x09U: + case 0x0aU: + case 0x0bU: + case 0x0cU: + case 0x0dU: + case 0x0eU: + case 0x0fU: + case 0x10U: + case 0x11U: + case 0x12U: + case 0x13U: + case 0x14U: + case 0x15U: + case 0x16U: + case 0x17U: duk_push_uint(dec_ctx->thr, ib); break; - case 0x18U: case 0x19U: case 0x1aU: case 0x1bU: + case 0x18U: + case 0x19U: + case 0x1aU: + case 0x1bU: duk__cbor_decode_push_aival_int(dec_ctx, ib, 0 /*negative*/); break; - case 0x1cU: case 0x1dU: case 0x1eU: case 0x1fU: + case 0x1cU: + case 0x1dU: + case 0x1eU: + case 0x1fU: goto format_error; - case 0x20U: case 0x21U: case 0x22U: case 0x23U: case 0x24U: case 0x25U: case 0x26U: case 0x27U: - case 0x28U: case 0x29U: case 0x2aU: case 0x2bU: case 0x2cU: case 0x2dU: case 0x2eU: case 0x2fU: - case 0x30U: case 0x31U: case 0x32U: case 0x33U: case 0x34U: case 0x35U: case 0x36U: case 0x37U: + case 0x20U: + case 0x21U: + case 0x22U: + case 0x23U: + case 0x24U: + case 0x25U: + case 0x26U: + case 0x27U: + case 0x28U: + case 0x29U: + case 0x2aU: + case 0x2bU: + case 0x2cU: + case 0x2dU: + case 0x2eU: + case 0x2fU: + case 0x30U: + case 0x31U: + case 0x32U: + case 0x33U: + case 0x34U: + case 0x35U: + case 0x36U: + case 0x37U: duk_push_int(dec_ctx->thr, -((duk_int_t) ((ib - 0x20U) + 1U))); break; - case 0x38U: case 0x39U: case 0x3aU: case 0x3bU: + case 0x38U: + case 0x39U: + case 0x3aU: + case 0x3bU: duk__cbor_decode_push_aival_int(dec_ctx, ib, 1 /*negative*/); break; - case 0x3cU: case 0x3dU: case 0x3eU: case 0x3fU: + case 0x3cU: + case 0x3dU: + case 0x3eU: + case 0x3fU: goto format_error; - case 0x40U: case 0x41U: case 0x42U: case 0x43U: case 0x44U: case 0x45U: case 0x46U: case 0x47U: - case 0x48U: case 0x49U: case 0x4aU: case 0x4bU: case 0x4cU: case 0x4dU: case 0x4eU: case 0x4fU: - case 0x50U: case 0x51U: case 0x52U: case 0x53U: case 0x54U: case 0x55U: case 0x56U: case 0x57U: + case 0x40U: + case 0x41U: + case 0x42U: + case 0x43U: + case 0x44U: + case 0x45U: + case 0x46U: + case 0x47U: + case 0x48U: + case 0x49U: + case 0x4aU: + case 0x4bU: + case 0x4cU: + case 0x4dU: + case 0x4eU: + case 0x4fU: + case 0x50U: + case 0x51U: + case 0x52U: + case 0x53U: + case 0x54U: + case 0x55U: + case 0x56U: + case 0x57U: /* XXX: Avoid rewind, we know the length already. */ DUK_ASSERT(dec_ctx->off > 0U); dec_ctx->off--; duk__cbor_decode_buffer(dec_ctx, 0x40U); break; - case 0x58U: case 0x59U: case 0x5aU: case 0x5bU: + case 0x58U: + case 0x59U: + case 0x5aU: + case 0x5bU: /* XXX: Avoid rewind, decode length inline. */ DUK_ASSERT(dec_ctx->off > 0U); dec_ctx->off--; duk__cbor_decode_buffer(dec_ctx, 0x40U); break; - case 0x5cU: case 0x5dU: case 0x5eU: + case 0x5cU: + case 0x5dU: + case 0x5eU: goto format_error; case 0x5fU: duk__cbor_decode_and_join_strbuf(dec_ctx, 0x40U); break; - case 0x60U: case 0x61U: case 0x62U: case 0x63U: case 0x64U: case 0x65U: case 0x66U: case 0x67U: - case 0x68U: case 0x69U: case 0x6aU: case 0x6bU: case 0x6cU: case 0x6dU: case 0x6eU: case 0x6fU: - case 0x70U: case 0x71U: case 0x72U: case 0x73U: case 0x74U: case 0x75U: case 0x76U: case 0x77U: + case 0x60U: + case 0x61U: + case 0x62U: + case 0x63U: + case 0x64U: + case 0x65U: + case 0x66U: + case 0x67U: + case 0x68U: + case 0x69U: + case 0x6aU: + case 0x6bU: + case 0x6cU: + case 0x6dU: + case 0x6eU: + case 0x6fU: + case 0x70U: + case 0x71U: + case 0x72U: + case 0x73U: + case 0x74U: + case 0x75U: + case 0x76U: + case 0x77U: /* XXX: Avoid double decode of length. */ duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x78U: case 0x79U: case 0x7aU: case 0x7bU: + case 0x78U: + case 0x79U: + case 0x7aU: + case 0x7bU: /* XXX: Avoid double decode of length. */ duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x7cU: case 0x7dU: case 0x7eU: + case 0x7cU: + case 0x7dU: + case 0x7eU: goto format_error; case 0x7fU: duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x80U: case 0x81U: case 0x82U: case 0x83U: case 0x84U: case 0x85U: case 0x86U: case 0x87U: - case 0x88U: case 0x89U: case 0x8aU: case 0x8bU: case 0x8cU: case 0x8dU: case 0x8eU: case 0x8fU: - case 0x90U: case 0x91U: case 0x92U: case 0x93U: case 0x94U: case 0x95U: case 0x96U: case 0x97U: + case 0x80U: + case 0x81U: + case 0x82U: + case 0x83U: + case 0x84U: + case 0x85U: + case 0x86U: + case 0x87U: + case 0x88U: + case 0x89U: + case 0x8aU: + case 0x8bU: + case 0x8cU: + case 0x8dU: + case 0x8eU: + case 0x8fU: + case 0x90U: + case 0x91U: + case 0x92U: + case 0x93U: + case 0x94U: + case 0x95U: + case 0x96U: + case 0x97U: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0x98U: case 0x99U: case 0x9aU: case 0x9bU: + case 0x98U: + case 0x99U: + case 0x9aU: + case 0x9bU: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0x9cU: case 0x9dU: case 0x9eU: + case 0x9cU: + case 0x9dU: + case 0x9eU: goto format_error; case 0x9fU: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xa0U: case 0xa1U: case 0xa2U: case 0xa3U: case 0xa4U: case 0xa5U: case 0xa6U: case 0xa7U: - case 0xa8U: case 0xa9U: case 0xaaU: case 0xabU: case 0xacU: case 0xadU: case 0xaeU: case 0xafU: - case 0xb0U: case 0xb1U: case 0xb2U: case 0xb3U: case 0xb4U: case 0xb5U: case 0xb6U: case 0xb7U: + case 0xa0U: + case 0xa1U: + case 0xa2U: + case 0xa3U: + case 0xa4U: + case 0xa5U: + case 0xa6U: + case 0xa7U: + case 0xa8U: + case 0xa9U: + case 0xaaU: + case 0xabU: + case 0xacU: + case 0xadU: + case 0xaeU: + case 0xafU: + case 0xb0U: + case 0xb1U: + case 0xb2U: + case 0xb3U: + case 0xb4U: + case 0xb5U: + case 0xb6U: + case 0xb7U: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xb8U: case 0xb9U: case 0xbaU: case 0xbbU: + case 0xb8U: + case 0xb9U: + case 0xbaU: + case 0xbbU: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xbcU: case 0xbdU: case 0xbeU: + case 0xbcU: + case 0xbdU: + case 0xbeU: goto format_error; case 0xbfU: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xc0U: case 0xc1U: case 0xc2U: case 0xc3U: case 0xc4U: case 0xc5U: case 0xc6U: case 0xc7U: - case 0xc8U: case 0xc9U: case 0xcaU: case 0xcbU: case 0xccU: case 0xcdU: case 0xceU: case 0xcfU: - case 0xd0U: case 0xd1U: case 0xd2U: case 0xd3U: case 0xd4U: case 0xd5U: case 0xd6U: case 0xd7U: + case 0xc0U: + case 0xc1U: + case 0xc2U: + case 0xc3U: + case 0xc4U: + case 0xc5U: + case 0xc6U: + case 0xc7U: + case 0xc8U: + case 0xc9U: + case 0xcaU: + case 0xcbU: + case 0xccU: + case 0xcdU: + case 0xceU: + case 0xcfU: + case 0xd0U: + case 0xd1U: + case 0xd2U: + case 0xd3U: + case 0xd4U: + case 0xd5U: + case 0xd6U: + case 0xd7U: /* Tag 0-23: drop. */ goto reread_initial_byte; - case 0xd8U: case 0xd9U: case 0xdaU: case 0xdbU: + case 0xd8U: + case 0xd9U: + case 0xdaU: + case 0xdbU: duk__cbor_decode_skip_aival_int(dec_ctx, ib); goto reread_initial_byte; - case 0xdcU: case 0xddU: case 0xdeU: case 0xdfU: + case 0xdcU: + case 0xddU: + case 0xdeU: + case 0xdfU: goto format_error; case 0xe0U: goto format_error; @@ -1477,14 +1660,14 @@ case 0xfeU: case 0xffU: goto format_error; - } /* end switch */ + } /* end switch */ return; - format_error: +format_error: duk__cbor_decode_error(dec_ctx); } -#else /* DUK_CBOR_DECODE_FASTPATH */ +#else /* DUK_CBOR_DECODE_FASTPATH */ DUK_LOCAL void duk__cbor_decode_value(duk_cbor_decode_context *dec_ctx) { duk_uint8_t ib, mt, ai; @@ -1493,7 +1676,7 @@ * here for simple paths like primitive values. */ - reread_initial_byte: +reread_initial_byte: DUK_DDD(DUK_DDDPRINT("cbor decode off=%ld len=%ld", (long) dec_ctx->off, (long) dec_ctx->len)); ib = duk__cbor_decode_readbyte(dec_ctx); @@ -1509,15 +1692,15 @@ */ switch (mt) { - case 0U: { /* unsigned integer */ + case 0U: { /* unsigned integer */ duk__cbor_decode_push_aival_int(dec_ctx, ib, 0 /*negative*/); break; } - case 1U: { /* negative integer */ + case 1U: { /* negative integer */ duk__cbor_decode_push_aival_int(dec_ctx, ib, 1 /*negative*/); break; } - case 2U: { /* byte string */ + case 2U: { /* byte string */ if (ai == 0x1fU) { duk__cbor_decode_and_join_strbuf(dec_ctx, 0x40U); } else { @@ -1526,23 +1709,23 @@ } break; } - case 3U: { /* text string */ + case 3U: { /* text string */ duk__cbor_decode_string(dec_ctx, ib, ai); break; } - case 4U: { /* array of data items */ + case 4U: { /* array of data items */ if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, ai) == 0)) { goto format_error; } break; } - case 5U: { /* map of pairs of data items */ + case 5U: { /* map of pairs of data items */ if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, ai) == 0)) { goto format_error; } break; } - case 6U: { /* semantic tagging */ + case 6U: { /* semantic tagging */ /* Tags are ignored now, re-read initial byte. A tagged * value may itself be tagged (an unlimited number of times) * so keep on peeling away tags. @@ -1550,7 +1733,7 @@ duk__cbor_decode_skip_aival_int(dec_ctx, ib); goto reread_initial_byte; } - case 7U: { /* floating point numbers, simple data types, break; other */ + case 7U: { /* floating point numbers, simple data types, break; other */ switch (ai) { case 0x14U: { duk_push_false(dec_ctx->thr); @@ -1568,7 +1751,7 @@ duk_push_undefined(dec_ctx->thr); break; } - case 0x18U: { /* more simple values (1 byte) */ + case 0x18U: { /* more simple values (1 byte) */ /* Simple value encoded in additional byte (none * are defined so far). RFC 7049 states that the * follow-up byte must be 32-255 to minimize @@ -1579,42 +1762,42 @@ */ goto format_error; } - case 0x19U: { /* half-float (2 bytes) */ + case 0x19U: { /* half-float (2 bytes) */ duk_double_t d; d = duk__cbor_decode_half_float(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0x1aU: { /* float (4 bytes) */ + case 0x1aU: { /* float (4 bytes) */ duk_double_t d; d = duk__cbor_decode_float(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0x1bU: { /* double (8 bytes) */ + case 0x1bU: { /* double (8 bytes) */ duk_double_t d; d = duk__cbor_decode_double(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0xffU: /* unexpected break */ + case 0xffU: /* unexpected break */ default: { goto format_error; } - } /* end switch */ + } /* end switch */ break; } default: { - goto format_error; /* will never actually occur */ + goto format_error; /* will never actually occur */ } - } /* end switch */ + } /* end switch */ return; - format_error: +format_error: duk__cbor_decode_error(dec_ctx); } -#endif /* DUK_CBOR_DECODE_FASTPATH */ +#endif /* DUK_CBOR_DECODE_FASTPATH */ DUK_LOCAL void duk__cbor_encode(duk_hthread *thr, duk_idx_t idx, duk_uint_t encode_flags) { duk_cbor_encode_context enc_ctx; @@ -1674,7 +1857,7 @@ duk_replace(thr, idx); } -#else /* DUK_USE_CBOR_SUPPORT */ +#else /* DUK_USE_CBOR_SUPPORT */ DUK_LOCAL void duk__cbor_encode(duk_hthread *thr, duk_idx_t idx, duk_uint_t encode_flags) { DUK_UNREF(idx); @@ -1688,7 +1871,7 @@ DUK_ERROR_UNSUPPORTED(thr); } -#endif /* DUK_USE_CBOR_SUPPORT */ +#endif /* DUK_USE_CBOR_SUPPORT */ /* * Public APIs @@ -1724,7 +1907,7 @@ duk__cbor_decode(thr, -1, 0 /*flags*/); return 1; } -#else /* DUK_USE_CBOR_SUPPORT */ +#else /* DUK_USE_CBOR_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_cbor_encode(duk_hthread *thr) { DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); @@ -1733,5 +1916,5 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_CBOR_SUPPORT */ -#endif /* DUK_USE_CBOR_BUILTIN */ +#endif /* DUK_USE_CBOR_SUPPORT */ +#endif /* DUK_USE_CBOR_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_date.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_date.c
Changed
@@ -29,30 +29,49 @@ */ /* Debug macro to print all parts and dparts (used manually because of debug level). */ -#define DUK__DPRINT_PARTS_AND_DPARTS(parts,dparts) do { \ +#define DUK__DPRINT_PARTS_AND_DPARTS(parts, dparts) \ + do { \ DUK_D(DUK_DPRINT("parts: %ld %ld %ld %ld %ld %ld %ld %ld, dparts: %lf %lf %lf %lf %lf %lf %lf %lf", \ - (long) (parts)0, (long) (parts)1, \ - (long) (parts)2, (long) (parts)3, \ - (long) (parts)4, (long) (parts)5, \ - (long) (parts)6, (long) (parts)7, \ - (double) (dparts)0, (double) (dparts)1, \ - (double) (dparts)2, (double) (dparts)3, \ - (double) (dparts)4, (double) (dparts)5, \ - (double) (dparts)6, (double) (dparts)7)); \ + (long) (parts)0, \ + (long) (parts)1, \ + (long) (parts)2, \ + (long) (parts)3, \ + (long) (parts)4, \ + (long) (parts)5, \ + (long) (parts)6, \ + (long) (parts)7, \ + (double) (dparts)0, \ + (double) (dparts)1, \ + (double) (dparts)2, \ + (double) (dparts)3, \ + (double) (dparts)4, \ + (double) (dparts)5, \ + (double) (dparts)6, \ + (double) (dparts)7)); \ } while (0) -#define DUK__DPRINT_PARTS(parts) do { \ +#define DUK__DPRINT_PARTS(parts) \ + do { \ DUK_D(DUK_DPRINT("parts: %ld %ld %ld %ld %ld %ld %ld %ld", \ - (long) (parts)0, (long) (parts)1, \ - (long) (parts)2, (long) (parts)3, \ - (long) (parts)4, (long) (parts)5, \ - (long) (parts)6, (long) (parts)7)); \ + (long) (parts)0, \ + (long) (parts)1, \ + (long) (parts)2, \ + (long) (parts)3, \ + (long) (parts)4, \ + (long) (parts)5, \ + (long) (parts)6, \ + (long) (parts)7)); \ } while (0) -#define DUK__DPRINT_DPARTS(dparts) do { \ +#define DUK__DPRINT_DPARTS(dparts) \ + do { \ DUK_D(DUK_DPRINT("dparts: %lf %lf %lf %lf %lf %lf %lf %lf", \ - (double) (dparts)0, (double) (dparts)1, \ - (double) (dparts)2, (double) (dparts)3, \ - (double) (dparts)4, (double) (dparts)5, \ - (double) (dparts)6, (double) (dparts)7)); \ + (double) (dparts)0, \ + (double) (dparts)1, \ + (double) (dparts)2, \ + (double) (dparts)3, \ + (double) (dparts)4, \ + (double) (dparts)5, \ + (double) (dparts)6, \ + (double) (dparts)7)); \ } while (0) /* Equivalent year for DST calculations outside 1970,2038 range, see @@ -60,7 +79,7 @@ * starts with the same weekday on Jan 1. * https://bugzilla.mozilla.org/show_bug.cgi?id=351066 */ -#define DUK__YEAR(x) ((duk_uint8_t) ((x) - 1970)) +#define DUK__YEAR(x) ((duk_uint8_t) ((x) -1970)) DUK_LOCAL duk_uint8_t duk__date_equivyear14 = { #if 1 /* This is based on V8 EquivalentYear() algorithm (see util/genequivyear.py): @@ -68,12 +87,22 @@ */ /* non-leap year: sunday, monday, ... */ - DUK__YEAR(2023), DUK__YEAR(2035), DUK__YEAR(2019), DUK__YEAR(2031), - DUK__YEAR(2015), DUK__YEAR(2027), DUK__YEAR(2011), + DUK__YEAR(2023), + DUK__YEAR(2035), + DUK__YEAR(2019), + DUK__YEAR(2031), + DUK__YEAR(2015), + DUK__YEAR(2027), + DUK__YEAR(2011), /* leap year: sunday, monday, ... */ - DUK__YEAR(2012), DUK__YEAR(2024), DUK__YEAR(2008), DUK__YEAR(2020), - DUK__YEAR(2032), DUK__YEAR(2016), DUK__YEAR(2028) + DUK__YEAR(2012), + DUK__YEAR(2024), + DUK__YEAR(2008), + DUK__YEAR(2020), + DUK__YEAR(2032), + DUK__YEAR(2016), + DUK__YEAR(2028) #endif #if 0 @@ -96,71 +125,70 @@ */ /* Parser part count. */ -#define DUK__NUM_ISO8601_PARSER_PARTS 9 +#define DUK__NUM_ISO8601_PARSER_PARTS 9 /* Parser part indices. */ -#define DUK__PI_YEAR 0 -#define DUK__PI_MONTH 1 -#define DUK__PI_DAY 2 -#define DUK__PI_HOUR 3 -#define DUK__PI_MINUTE 4 -#define DUK__PI_SECOND 5 -#define DUK__PI_MILLISECOND 6 -#define DUK__PI_TZHOUR 7 -#define DUK__PI_TZMINUTE 8 +#define DUK__PI_YEAR 0 +#define DUK__PI_MONTH 1 +#define DUK__PI_DAY 2 +#define DUK__PI_HOUR 3 +#define DUK__PI_MINUTE 4 +#define DUK__PI_SECOND 5 +#define DUK__PI_MILLISECOND 6 +#define DUK__PI_TZHOUR 7 +#define DUK__PI_TZMINUTE 8 /* Parser part masks. */ -#define DUK__PM_YEAR (1 << DUK__PI_YEAR) -#define DUK__PM_MONTH (1 << DUK__PI_MONTH) -#define DUK__PM_DAY (1 << DUK__PI_DAY) -#define DUK__PM_HOUR (1 << DUK__PI_HOUR) -#define DUK__PM_MINUTE (1 << DUK__PI_MINUTE) -#define DUK__PM_SECOND (1 << DUK__PI_SECOND) -#define DUK__PM_MILLISECOND (1 << DUK__PI_MILLISECOND) -#define DUK__PM_TZHOUR (1 << DUK__PI_TZHOUR) -#define DUK__PM_TZMINUTE (1 << DUK__PI_TZMINUTE) +#define DUK__PM_YEAR (1 << DUK__PI_YEAR) +#define DUK__PM_MONTH (1 << DUK__PI_MONTH) +#define DUK__PM_DAY (1 << DUK__PI_DAY) +#define DUK__PM_HOUR (1 << DUK__PI_HOUR) +#define DUK__PM_MINUTE (1 << DUK__PI_MINUTE) +#define DUK__PM_SECOND (1 << DUK__PI_SECOND) +#define DUK__PM_MILLISECOND (1 << DUK__PI_MILLISECOND) +#define DUK__PM_TZHOUR (1 << DUK__PI_TZHOUR) +#define DUK__PM_TZMINUTE (1 << DUK__PI_TZMINUTE) /* Parser separator indices. */ -#define DUK__SI_PLUS 0 -#define DUK__SI_MINUS 1 -#define DUK__SI_T 2 -#define DUK__SI_SPACE 3 -#define DUK__SI_COLON 4 -#define DUK__SI_PERIOD 5 -#define DUK__SI_Z 6 -#define DUK__SI_NUL 7 +#define DUK__SI_PLUS 0 +#define DUK__SI_MINUS 1 +#define DUK__SI_T 2 +#define DUK__SI_SPACE 3 +#define DUK__SI_COLON 4 +#define DUK__SI_PERIOD 5 +#define DUK__SI_Z 6 +#define DUK__SI_NUL 7 /* Parser separator masks. */ -#define DUK__SM_PLUS (1 << DUK__SI_PLUS) -#define DUK__SM_MINUS (1 << DUK__SI_MINUS) -#define DUK__SM_T (1 << DUK__SI_T) -#define DUK__SM_SPACE (1 << DUK__SI_SPACE) -#define DUK__SM_COLON (1 << DUK__SI_COLON) -#define DUK__SM_PERIOD (1 << DUK__SI_PERIOD) -#define DUK__SM_Z (1 << DUK__SI_Z) -#define DUK__SM_NUL (1 << DUK__SI_NUL) +#define DUK__SM_PLUS (1 << DUK__SI_PLUS) +#define DUK__SM_MINUS (1 << DUK__SI_MINUS) +#define DUK__SM_T (1 << DUK__SI_T) +#define DUK__SM_SPACE (1 << DUK__SI_SPACE) +#define DUK__SM_COLON (1 << DUK__SI_COLON) +#define DUK__SM_PERIOD (1 << DUK__SI_PERIOD) +#define DUK__SM_Z (1 << DUK__SI_Z) +#define DUK__SM_NUL (1 << DUK__SI_NUL) /* Rule control flags. */ -#define DUK__CF_NEG (1 << 0) /* continue matching, set neg_tzoffset flag */ -#define DUK__CF_ACCEPT (1 << 1) /* accept string */ -#define DUK__CF_ACCEPT_NUL (1 << 2) /* accept string if next char is NUL (otherwise reject) */ - -#define DUK__PACK_RULE(partmask,sepmask,nextpart,flags) \ - ((duk_uint32_t) (partmask) + \ - (((duk_uint32_t) (sepmask)) << 9) + \ - (((duk_uint32_t) (nextpart)) << 17) + \ +#define DUK__CF_NEG (1 << 0) /* continue matching, set neg_tzoffset flag */ +#define DUK__CF_ACCEPT (1 << 1) /* accept string */ +#define DUK__CF_ACCEPT_NUL (1 << 2) /* accept string if next char is NUL (otherwise reject) */ + +#define DUK__PACK_RULE(partmask, sepmask, nextpart, flags) \ + ((duk_uint32_t) (partmask) + (((duk_uint32_t) (sepmask)) << 9) + (((duk_uint32_t) (nextpart)) << 17) + \ (((duk_uint32_t) (flags)) << 21)) -#define DUK__UNPACK_RULE(rule,var_nextidx,var_flags) do { \ +#define DUK__UNPACK_RULE(rule, var_nextidx, var_flags) \ + do { \ (var_nextidx) = (duk_small_uint_t) (((rule) >> 17) & 0x0f); \ (var_flags) = (duk_small_uint_t) ((rule) >> 21); \ } while (0) -#define DUK__RULE_MASK_PART_SEP 0x1ffffUL +#define DUK__RULE_MASK_PART_SEP 0x1ffffUL /* Matching separator index is used in the control table */ DUK_LOCAL const duk_uint8_t duk__parse_iso8601_seps = { - DUK_ASC_PLUS /*0*/, DUK_ASC_MINUS /*1*/, DUK_ASC_UC_T /*2*/, DUK_ASC_SPACE /*3*/, + DUK_ASC_PLUS /*0*/, DUK_ASC_MINUS /*1*/, DUK_ASC_UC_T /*2*/, DUK_ASC_SPACE /*3*/, DUK_ASC_COLON /*4*/, DUK_ASC_PERIOD /*5*/, DUK_ASC_UC_Z /*6*/, DUK_ASC_NUL /*7*/ }; @@ -173,10 +201,26 @@ DUK__PACK_RULE(DUK__PM_MINUTE, DUK__SM_COLON, DUK__PI_SECOND, 0), DUK__PACK_RULE(DUK__PM_SECOND, DUK__SM_PERIOD, DUK__PI_MILLISECOND, 0), DUK__PACK_RULE(DUK__PM_TZHOUR, DUK__SM_COLON, DUK__PI_TZMINUTE, 0), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_PLUS, DUK__PI_TZHOUR, 0), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_MINUS, DUK__PI_TZHOUR, DUK__CF_NEG), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_Z, 0, DUK__CF_ACCEPT_NUL), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND | DUK__PM_TZHOUR /*Note2*/ | DUK__PM_TZMINUTE, DUK__SM_NUL, 0, DUK__CF_ACCEPT) + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_PLUS, + DUK__PI_TZHOUR, + 0), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_MINUS, + DUK__PI_TZHOUR, + DUK__CF_NEG), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_Z, + 0, + DUK__CF_ACCEPT_NUL), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND | DUK__PM_TZHOUR /*Note2*/ | DUK__PM_TZMINUTE, + DUK__SM_NUL, + 0, + DUK__CF_ACCEPT) /* Note1: the specification doesn't require matching a time form with * just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z". @@ -201,7 +245,7 @@ /* During parsing, month and day are one-based; set defaults here. */ duk_memzero(parts, sizeof(parts)); - DUK_ASSERT(partsDUK_DATE_IDX_YEAR == 0); /* don't care value, year is mandatory */ + DUK_ASSERT(partsDUK_DATE_IDX_YEAR == 0); /* don't care value, year is mandatory */ partsDUK_DATE_IDX_MONTH = 1; partsDUK_DATE_IDX_DAY = 1; @@ -218,7 +262,8 @@ for (;;) { ch = *p++; DUK_DDD(DUK_DDDPRINT("parsing, part_idx=%ld, char=%ld ('%c')", - (long) part_idx, (long) ch, + (long) part_idx, + (long) ch, (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : DUK_ASC_QUESTION))); if (ch >= DUK_ASC_0 && ch <= DUK_ASC_9) { @@ -263,7 +308,7 @@ } sep_idx = i; - match_val = (1UL << part_idx) + (1UL << (sep_idx + 9)); /* match against rule part/sep bits */ + match_val = (1UL << part_idx) + (1UL << (sep_idx + 9)); /* match against rule part/sep bits */ for (i = 0; i < (duk_small_uint_t) (sizeof(duk__parse_iso8601_control) / sizeof(duk_uint32_t)); i++) { duk_uint_fast32_t rule = duk__parse_iso8601_controli; @@ -271,8 +316,10 @@ duk_small_uint_t cflags; DUK_DDD(DUK_DDDPRINT("part_idx=%ld, sep_idx=%ld, match_val=0x%08lx, considering rule=0x%08lx", - (long) part_idx, (long) sep_idx, - (unsigned long) match_val, (unsigned long) rule)); + (long) part_idx, + (long) sep_idx, + (unsigned long) match_val, + (unsigned long) rule)); if ((rule & match_val) != match_val) { continue; @@ -282,9 +329,12 @@ DUK_DDD(DUK_DDDPRINT("rule match -> part_idx=%ld, sep_idx=%ld, match_val=0x%08lx, " "rule=0x%08lx -> nextpart=%ld, cflags=0x%02lx", - (long) part_idx, (long) sep_idx, - (unsigned long) match_val, (unsigned long) rule, - (long) nextpart, (unsigned long) cflags)); + (long) part_idx, + (long) sep_idx, + (unsigned long) match_val, + (unsigned long) rule, + (long) nextpart, + (unsigned long) cflags)); if (cflags & DUK__CF_NEG) { neg_tzoffset = 1; @@ -304,7 +354,7 @@ part_idx = nextpart; break; - } /* rule match */ + } /* rule match */ if (i == (duk_small_uint_t) (sizeof(duk__parse_iso8601_control) / sizeof(duk_uint32_t))) { DUK_DDD(DUK_DDDPRINT("no rule matches -> reject")); @@ -318,17 +368,17 @@ DUK_DDD(DUK_DDDPRINT("NUL after rule matching (should not happen) -> reject")); goto reject; } - } /* if-digit-else-ctrl */ - } /* char loop */ + } /* if-digit-else-ctrl */ + } /* char loop */ /* We should never exit the loop above. */ DUK_UNREACHABLE(); - reject: +reject: DUK_DDD(DUK_DDDPRINT("reject")); return 0; - accept: +accept: DUK_DDD(DUK_DDDPRINT("accept")); /* Apply timezone offset to get the main parts in UTC */ @@ -342,8 +392,8 @@ partsDUK__PI_HOUR -= partsDUK__PI_TZHOUR; partsDUK__PI_MINUTE -= partsDUK__PI_TZMINUTE; } - partsDUK__PI_MONTH -= 1; /* zero-based month */ - partsDUK__PI_DAY -= 1; /* zero-based day */ + partsDUK__PI_MONTH -= 1; /* zero-based month */ + partsDUK__PI_DAY -= 1; /* zero-based day */ /* Use double parts, they tolerate unnormalized time. * @@ -420,16 +470,14 @@ * out for non-finite numbers etc. */ -DUK_LOCAL duk_uint8_t duk__days_in_month12 = { - (duk_uint8_t) 31, (duk_uint8_t) 28, (duk_uint8_t) 31, (duk_uint8_t) 30, - (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 31, - (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31 -}; +DUK_LOCAL duk_uint8_t duk__days_in_month12 = { (duk_uint8_t) 31, (duk_uint8_t) 28, (duk_uint8_t) 31, (duk_uint8_t) 30, + (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 31, + (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31 }; /* Maximum iteration count for computing UTC-to-local time offset when * creating an ECMAScript time value from local parts. */ -#define DUK__LOCAL_TZOFFSET_MAXITER 4 +#define DUK__LOCAL_TZOFFSET_MAXITER 4 /* Because 'day since epoch' can be negative and is used to compute weekday * using a modulo operation, add this multiple of 7 to avoid negative values @@ -437,7 +485,7 @@ * +/- 100 million days from epoch, so this adder fits nicely into 32 bits. * Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin. */ -#define DUK__WEEKDAY_MOD_ADDER (20000000 * 7) /* 0x08583b00 */ +#define DUK__WEEKDAY_MOD_ADDER (20000000 * 7) /* 0x08583b00 */ DUK_INTERNAL duk_bool_t duk_bi_date_is_leap_year(duk_int_t year) { if ((year % 4) != 0) { @@ -498,10 +546,8 @@ /* Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative * values, but is incorrect for negative ones. */ - return 365 * (year - 1970) - + duk__div_floor(year - 1969, 4) - - duk__div_floor(year - 1901, 100) - + duk__div_floor(year - 1601, 400); + return 365 * (year - 1970) + duk__div_floor(year - 1969, 4) - duk__div_floor(year - 1901, 100) + + duk__div_floor(year - 1601, 400); } /* Given a day number, determine year and day-within-year. */ @@ -523,10 +569,9 @@ diff_days = duk__day_from_year(year) - day; DUK_DDD(DUK_DDDPRINT("year=%ld day=%ld, diff_days=%ld", (long) year, (long) day, (long) diff_days)); if (diff_days <= 0) { - DUK_ASSERT(-diff_days < 366); /* fits into duk_small_int_t */ + DUK_ASSERT(-diff_days < 366); /* fits into duk_small_int_t */ *out_day_within_year = -diff_days; - DUK_DDD(DUK_DDDPRINT("--> year=%ld, day-within-year=%ld", - (long) year, (long) *out_day_within_year)); + DUK_DDD(DUK_DDDPRINT("--> year=%ld, day-within-year=%ld", (long) year, (long) *out_day_within_year)); DUK_ASSERT(*out_day_within_year >= 0); DUK_ASSERT(*out_day_within_year < (duk_bi_date_is_leap_year(year) ? 366 : 365)); return year; @@ -535,7 +580,7 @@ /* Note: this is very tricky; we must never 'overshoot' the * correction downwards. */ - year -= 1 + (diff_days - 1) / 366; /* conservative */ + year -= 1 + (diff_days - 1) / 366; /* conservative */ } } @@ -608,7 +653,7 @@ duk_double_t d1, d2; duk_int_t t1, t2; duk_int_t day_since_epoch; - duk_int_t year; /* does not fit into 16 bits */ + duk_int_t year; /* does not fit into 16 bits */ duk_small_int_t day_in_year; duk_small_int_t month; duk_small_int_t day; @@ -620,8 +665,8 @@ duk_bool_t is_leap; duk_small_int_t arridx; - DUK_ASSERT(DUK_ISFINITE(d)); /* caller checks */ - d = DUK_FLOOR(d); /* remove fractions if present */ + DUK_ASSERT(DUK_ISFINITE(d)); /* caller checks */ + d = DUK_FLOOR(d); /* remove fractions if present */ DUK_ASSERT(duk_double_equals(DUK_FLOOR(d), d)); /* The timevalue must be in valid ECMAScript range, but since a local @@ -653,9 +698,12 @@ * t2 = day number from epoch (fits 32 bit, may be negative) */ - partsDUK_DATE_IDX_MILLISECOND = t1 % 1000; t1 /= 1000; - partsDUK_DATE_IDX_SECOND = t1 % 60; t1 /= 60; - partsDUK_DATE_IDX_MINUTE = t1 % 60; t1 /= 60; + partsDUK_DATE_IDX_MILLISECOND = t1 % 1000; + t1 /= 1000; + partsDUK_DATE_IDX_SECOND = t1 % 60; + t1 /= 60; + partsDUK_DATE_IDX_MINUTE = t1 % 60; + t1 /= 60; partsDUK_DATE_IDX_HOUR = t1; DUK_ASSERT(partsDUK_DATE_IDX_MILLISECOND >= 0 && partsDUK_DATE_IDX_MILLISECOND <= 999); DUK_ASSERT(partsDUK_DATE_IDX_SECOND >= 0 && partsDUK_DATE_IDX_SECOND <= 59); @@ -663,7 +711,11 @@ DUK_ASSERT(partsDUK_DATE_IDX_HOUR >= 0 && partsDUK_DATE_IDX_HOUR <= 23); DUK_DDD(DUK_DDDPRINT("d=%lf, d1=%lf, d2=%lf, t1=%ld, t2=%ld, parts: hour=%ld min=%ld sec=%ld msec=%ld", - (double) d, (double) d1, (double) d2, (long) t1, (long) t2, + (double) d, + (double) d1, + (double) d2, + (long) t1, + (long) t2, (long) partsDUK_DATE_IDX_HOUR, (long) partsDUK_DATE_IDX_MINUTE, (long) partsDUK_DATE_IDX_SECOND, @@ -673,7 +725,7 @@ * the ECMAScript range. */ DUK_ASSERT(t2 + DUK__WEEKDAY_MOD_ADDER >= 0); - partsDUK_DATE_IDX_WEEKDAY = (t2 + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ + partsDUK_DATE_IDX_WEEKDAY = (t2 + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ DUK_ASSERT(partsDUK_DATE_IDX_WEEKDAY >= 0 && partsDUK_DATE_IDX_WEEKDAY <= 6); year = duk__year_from_day(t2, &day_in_year); @@ -684,8 +736,7 @@ if (month == 1 && is_leap) { dim++; } - DUK_DDD(DUK_DDDPRINT("month=%ld, dim=%ld, day=%ld", - (long) month, (long) dim, (long) day)); + DUK_DDD(DUK_DDDPRINT("month=%ld, dim=%ld, day=%ld", (long) month, (long) dim, (long) day)); if (day < dim) { break; } @@ -710,9 +761,9 @@ if ((flags & DUK_DATE_FLAG_EQUIVYEAR) && (year < 1971 || year > 2037)) { DUK_ASSERT(is_leap == 0 || is_leap == 1); - jan1_since_epoch = day_since_epoch - day_in_year; /* day number for Jan 1 since epoch */ + jan1_since_epoch = day_since_epoch - day_in_year; /* day number for Jan 1 since epoch */ DUK_ASSERT(jan1_since_epoch + DUK__WEEKDAY_MOD_ADDER >= 0); - jan1_weekday = (jan1_since_epoch + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ + jan1_weekday = (jan1_since_epoch + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ DUK_ASSERT(jan1_weekday >= 0 && jan1_weekday <= 6); arridx = jan1_weekday; if (is_leap) { @@ -724,8 +775,12 @@ year = equiv_year; DUK_DDD(DUK_DDDPRINT("equiv year mapping, year=%ld, day_in_year=%ld, day_since_epoch=%ld, " "jan1_since_epoch=%ld, jan1_weekday=%ld -> equiv year %ld", - (long) year, (long) day_in_year, (long) day_since_epoch, - (long) jan1_since_epoch, (long) jan1_weekday, (long) equiv_year)); + (long) year, + (long) day_in_year, + (long) day_since_epoch, + (long) jan1_since_epoch, + (long) jan1_weekday, + (long) equiv_year)); } partsDUK_DATE_IDX_YEAR = year; @@ -733,8 +788,8 @@ partsDUK_DATE_IDX_DAY = day; if (flags & DUK_DATE_FLAG_ONEBASED) { - partsDUK_DATE_IDX_MONTH++; /* zero-based -> one-based */ - partsDUK_DATE_IDX_DAY++; /* -""- */ + partsDUK_DATE_IDX_MONTH++; /* zero-based -> one-based */ + partsDUK_DATE_IDX_DAY++; /* -""- */ } if (dparts != NULL) { @@ -814,8 +869,7 @@ /* MakeDate */ d = tmp_day * ((duk_double_t) DUK_DATE_MSEC_DAY) + tmp_time; - DUK_DDD(DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf", - (double) tmp_time, (double) tmp_day, (double) d)); + DUK_DDD(DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf", (double) tmp_time, (double) tmp_day, (double) d)); /* Optional UTC conversion. */ if (flags & DUK_DATE_FLAG_LOCALTIME) { @@ -845,16 +899,22 @@ /* Iteration solution */ tzoff = 0; - tzoffprev1 = 999999999L; /* invalid value which never matches */ + tzoffprev1 = 999999999L; /* invalid value which never matches */ for (i = 0; i < DUK__LOCAL_TZOFFSET_MAXITER; i++) { tzoffprev2 = tzoffprev1; tzoffprev1 = tzoff; tzoff = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d - tzoff * 1000L); DUK_DDD(DUK_DDDPRINT("tzoffset iteration, i=%d, tzoff=%ld, tzoffprev1=%ld tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); if (tzoff == tzoffprev1) { DUK_DDD(DUK_DDDPRINT("tzoffset iteration finished, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); break; } else if (tzoff == tzoffprev2) { /* Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js. @@ -862,8 +922,12 @@ * result which is independent of iteration count. Not sure if * this is a generically correct solution. */ - DUK_DDD(DUK_DDDPRINT("tzoffset iteration two-value cycle, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + DUK_DDD(DUK_DDDPRINT( + "tzoffset iteration two-value cycle, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); if (tzoffprev1 > tzoff) { tzoff = tzoffprev1; } @@ -894,7 +958,7 @@ duk_int_t tzoffset = 0; duk_push_this(thr); - h = duk_get_hobject(thr, -1); /* XXX: getter with class check, useful in built-ins */ + h = duk_get_hobject(thr, -1); /* XXX: getter with class check, useful in built-ins */ if (h == NULL || DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_DATE) { DUK_ERROR_TYPE(thr, "expected Date"); DUK_WO_NORETURN(return 0.0;); @@ -920,7 +984,7 @@ /* Note: DST adjustment is determined using UTC time. * If 'd' is NaN, tzoffset will be 0. */ - tzoffset = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d); /* seconds */ + tzoffset = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d); /* seconds */ d += tzoffset * 1000L; } if (out_tzoffset) { @@ -945,8 +1009,8 @@ /* ... this */ d = duk_bi_date_get_timeval_from_dparts(dparts, flags); - duk_push_number(thr, d); /* -> ... this timeval_new */ - duk_dup_top(thr); /* -> ... this timeval_new timeval_new */ + duk_push_number(thr, d); /* -> ... this timeval_new */ + duk_dup_top(thr); /* -> ... this timeval_new timeval_new */ /* Must force write because e.g. .setYear() must work even when * the Date instance is frozen. @@ -959,8 +1023,8 @@ /* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long. */ DUK_LOCAL void duk__format_parts_iso8601(duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags, duk_uint8_t *out_buf) { - char yearstr8; /* "-123456\0" */ - char tzstr8; /* "+11:22\0" */ + char yearstr8; /* "-123456\0" */ + char tzstr8; /* "+11:22\0" */ char sep = (flags & DUK_DATE_FLAG_SEP_T) ? DUK_ASC_UC_T : DUK_ASC_SPACE; DUK_ASSERT(partsDUK_DATE_IDX_MONTH >= 1 && partsDUK_DATE_IDX_MONTH <= 12); @@ -972,8 +1036,9 @@ */ DUK_SNPRINTF(yearstr, sizeof(yearstr), - (partsDUK_DATE_IDX_YEAR >= 0 && partsDUK_DATE_IDX_YEAR <= 9999) ? "%04ld" : - ((partsDUK_DATE_IDX_YEAR >= 0) ? "+%06ld" : "%07ld"), + (partsDUK_DATE_IDX_YEAR >= 0 && partsDUK_DATE_IDX_YEAR <= 9999) ? + "%04ld" : + ((partsDUK_DATE_IDX_YEAR >= 0) ? "+%06ld" : "%07ld"), (long) partsDUK_DATE_IDX_YEAR); yearstrsizeof(yearstr) - 1 = (char) 0; @@ -994,8 +1059,9 @@ tmp = tmp / 60; arg_hours = tmp / 60; arg_minutes = tmp % 60; - DUK_ASSERT(arg_hours <= 24); /* Even less is actually guaranteed for a valid tzoffset. */ - arg_hours = arg_hours & 0x3f; /* For 0,24 this is a no-op, but fixes GCC 7 warning, see https://github.com/svaarala/duktape/issues/1602. */ + DUK_ASSERT(arg_hours <= 24); /* Even less is actually guaranteed for a valid tzoffset. */ + arg_hours = arg_hours & 0x3f; /* For 0,24 this is a no-op, but fixes GCC 7 warning, see + https://github.com/svaarala/duktape/issues/1602. */ DUK_SNPRINTF(tzstr, sizeof(tzstr), fmt, (int) arg_hours, (int) arg_minutes); tzstrsizeof(tzstr) - 1 = (char) 0; @@ -1008,18 +1074,31 @@ * is portable. */ if ((flags & DUK_DATE_FLAG_TOSTRING_DATE) && (flags & DUK_DATE_FLAG_TOSTRING_TIME)) { - DUK_SPRINTF((char *) out_buf, "%s-%02d-%02d%c%02d:%02d:%02d.%03d%s", - (const char *) yearstr, (int) partsDUK_DATE_IDX_MONTH, (int) partsDUK_DATE_IDX_DAY, (int) sep, - (int) partsDUK_DATE_IDX_HOUR, (int) partsDUK_DATE_IDX_MINUTE, - (int) partsDUK_DATE_IDX_SECOND, (int) partsDUK_DATE_IDX_MILLISECOND, (const char *) tzstr); + DUK_SPRINTF((char *) out_buf, + "%s-%02d-%02d%c%02d:%02d:%02d.%03d%s", + (const char *) yearstr, + (int) partsDUK_DATE_IDX_MONTH, + (int) partsDUK_DATE_IDX_DAY, + (int) sep, + (int) partsDUK_DATE_IDX_HOUR, + (int) partsDUK_DATE_IDX_MINUTE, + (int) partsDUK_DATE_IDX_SECOND, + (int) partsDUK_DATE_IDX_MILLISECOND, + (const char *) tzstr); } else if (flags & DUK_DATE_FLAG_TOSTRING_DATE) { - DUK_SPRINTF((char *) out_buf, "%s-%02d-%02d", - (const char *) yearstr, (int) partsDUK_DATE_IDX_MONTH, (int) partsDUK_DATE_IDX_DAY); + DUK_SPRINTF((char *) out_buf, + "%s-%02d-%02d", + (const char *) yearstr, + (int) partsDUK_DATE_IDX_MONTH, + (int) partsDUK_DATE_IDX_DAY); } else { DUK_ASSERT(flags & DUK_DATE_FLAG_TOSTRING_TIME); - DUK_SPRINTF((char *) out_buf, "%02d:%02d:%02d.%03d%s", - (int) partsDUK_DATE_IDX_HOUR, (int) partsDUK_DATE_IDX_MINUTE, - (int) partsDUK_DATE_IDX_SECOND, (int) partsDUK_DATE_IDX_MILLISECOND, + DUK_SPRINTF((char *) out_buf, + "%02d:%02d:%02d.%03d%s", + (int) partsDUK_DATE_IDX_HOUR, + (int) partsDUK_DATE_IDX_MINUTE, + (int) partsDUK_DATE_IDX_SECOND, + (int) partsDUK_DATE_IDX_MILLISECOND, (const char *) tzstr); } } @@ -1031,11 +1110,11 @@ DUK_LOCAL duk_ret_t duk__to_string_helper(duk_hthread *thr, duk_small_uint_t flags) { duk_double_t d; duk_int_t partsDUK_DATE_IDX_NUM_PARTS; - duk_int_t tzoffset; /* seconds, doesn't fit into 16 bits */ + duk_int_t tzoffset; /* seconds, doesn't fit into 16 bits */ duk_bool_t rc; duk_uint8_t bufDUK_BI_DATE_ISO8601_BUFSIZE; - DUK_UNREF(rc); /* unreferenced with some options */ + DUK_UNREF(rc); /* unreferenced with some options */ d = duk__push_this_get_timeval_tzoffset(thr, flags, &tzoffset); if (DUK_ISNAN(d)) { @@ -1087,9 +1166,9 @@ DUK_LOCAL duk_ret_t duk__get_part_helper(duk_hthread *thr, duk_small_uint_t flags_and_idx) { duk_double_t d; duk_int_t partsDUK_DATE_IDX_NUM_PARTS; - duk_small_uint_t idx_part = (duk_small_uint_t) (flags_and_idx >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ + duk_small_uint_t idx_part = (duk_small_uint_t) (flags_and_idx >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ - DUK_ASSERT_DISABLE(idx_part >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx_part >= 0); /* unsigned */ DUK_ASSERT(idx_part < DUK_DATE_IDX_NUM_PARTS); d = duk__push_this_get_timeval(thr, flags_and_idx); @@ -1099,7 +1178,7 @@ } DUK_ASSERT(DUK_ISFINITE(d)); - duk_bi_date_timeval_to_parts(d, parts, NULL, flags_and_idx); /* no need to mask idx portion */ + duk_bi_date_timeval_to_parts(d, parts, NULL, flags_and_idx); /* no need to mask idx portion */ /* Setter APIs detect special year numbers (0...99) and apply a +1900 * only in certain cases. The legacy getYear() getter applies -1900 @@ -1121,7 +1200,7 @@ duk_int_t partsDUK_DATE_IDX_NUM_PARTS; duk_double_t dpartsDUK_DATE_IDX_NUM_PARTS; duk_idx_t nargs; - duk_small_uint_t maxnargs = (duk_small_uint_t) (flags_and_maxnargs >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ + duk_small_uint_t maxnargs = (duk_small_uint_t) (flags_and_maxnargs >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ duk_small_uint_t idx_first, idx; duk_small_uint_t i; @@ -1168,7 +1247,7 @@ DUK_ASSERT(maxnargs >= 1 && maxnargs <= 3); idx_first = DUK_DATE_IDX_DAY - (maxnargs - 1); } - DUK_ASSERT_DISABLE(idx_first >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx_first >= 0); /* unsigned */ DUK_ASSERT(idx_first < DUK_DATE_IDX_NUM_PARTS); for (i = 0; i < maxnargs; i++) { @@ -1177,7 +1256,7 @@ break; } idx = idx_first + i; - DUK_ASSERT_DISABLE(idx >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx >= 0); /* unsigned */ DUK_ASSERT(idx < DUK_DATE_IDX_NUM_PARTS); if (idx == DUK_DATE_IDX_YEAR && (flags_and_maxnargs & DUK_DATE_FLAG_YEAR_FIXUP)) { @@ -1229,7 +1308,7 @@ } duk_dup(thr, idx_val); duk_to_int(thr, -1); - d = duk_get_number(thr, -1); /* get as double to handle huge numbers correctly */ + d = duk_get_number(thr, -1); /* get as double to handle huge numbers correctly */ if (d >= 0.0 && d <= 99.0) { d += 1900.0; duk_push_number(thr, d); @@ -1277,10 +1356,14 @@ } DUK_DDD(DUK_DDDPRINT("parts from args -> %lf %lf %lf %lf %lf %lf %lf %lf", - (double) dparts0, (double) dparts1, - (double) dparts2, (double) dparts3, - (double) dparts4, (double) dparts5, - (double) dparts6, (double) dparts7)); + (double) dparts0, + (double) dparts1, + (double) dparts2, + (double) dparts3, + (double) dparts4, + (double) dparts5, + (double) dparts6, + (double) dparts7)); } /* @@ -1436,9 +1519,8 @@ DUK_DDD(DUK_DDDPRINT("Date constructor, nargs=%ld, is_cons=%ld", (long) nargs, (long) is_cons)); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATE), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATE), DUK_BIDX_DATE_PROTOTYPE); /* Unlike most built-ins, the internal PrimitiveValue of a Date @@ -1460,9 +1542,9 @@ str = duk_get_string_notsymbol(thr, 0); if (str) { duk__parse_string(thr, str); - duk_replace(thr, 0); /* may be NaN */ + duk_replace(thr, 0); /* may be NaN */ } - d = duk__timeclip(duk_to_number(thr, 0)); /* symbols fail here */ + d = duk__timeclip(duk_to_number(thr, 0)); /* symbols fail here */ duk_push_number(thr, d); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_W); return 1; @@ -1472,8 +1554,8 @@ /* Parts are in local time, convert when setting. */ - (void) duk__set_this_timeval_from_dparts(thr, dparts, DUK_DATE_FLAG_LOCALTIME /*flags*/); /* -> ... this timeval */ - duk_pop(thr); /* -> ... this */ + (void) duk__set_this_timeval_from_dparts(thr, dparts, DUK_DATE_FLAG_LOCALTIME /*flags*/); /* -> ... this timeval */ + duk_pop(thr); /* -> ... this */ return 1; } @@ -1504,7 +1586,7 @@ duk_double_t d; d = duk_time_get_ecmascript_time_nofrac(thr); - DUK_ASSERT(duk_double_equals(duk__timeclip(d), d)); /* TimeClip() should never be necessary */ + DUK_ASSERT(duk_double_equals(duk__timeclip(d), d)); /* TimeClip() should never be necessary */ duk_push_number(thr, d); return 1; } @@ -1553,7 +1635,7 @@ * as their behavior is identical. */ - duk_double_t d = duk__push_this_get_timeval(thr, 0 /*flags*/); /* -> this */ + duk_double_t d = duk__push_this_get_timeval(thr, 0 /*flags*/); /* -> this */ DUK_ASSERT(DUK_ISFINITE(d) || DUK_ISNAN(d)); duk_push_number(thr, d); return 1; @@ -1579,7 +1661,7 @@ duk_pop(thr); duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_ISO_STRING); - duk_dup_m2(thr); /* -> O toIsoString O */ + duk_dup_m2(thr); /* -> O toIsoString O */ duk_call_method(thr, 0); return 1; } @@ -1752,8 +1834,7 @@ DUK_ASSERT_TOP(thr, 2); hintstr = duk_require_lstring(thr, 0, &hintlen); - if ((hintlen == 6 && DUK_STRCMP(hintstr, "string") == 0) || - (hintlen == 7 && DUK_STRCMP(hintstr, "default") == 0)) { + if ((hintlen == 6 && DUK_STRCMP(hintstr, "string") == 0) || (hintlen == 7 && DUK_STRCMP(hintstr, "default") == 0)) { hint = DUK_HINT_STRING; } else if (hintlen == 6 && DUK_STRCMP(hintstr, "number") == 0) { hint = DUK_HINT_NUMBER; @@ -1764,6 +1845,6 @@ duk_to_primitive_ordinary(thr, -1, hint); return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ -#endif /* DUK_USE_DATE_BUILTIN */ +#endif /* DUK_USE_DATE_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_date_unix.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_date_unix.c
Changed
@@ -11,8 +11,8 @@ /* Buffer sizes for some UNIX calls. Larger than strictly necessary * to avoid Valgrind errors. */ -#define DUK__STRPTIME_BUF_SIZE 64 -#define DUK__STRFTIME_BUF_SIZE 64 +#define DUK__STRPTIME_BUF_SIZE 64 +#define DUK__STRFTIME_BUF_SIZE 64 #if defined(DUK_USE_DATE_NOW_GETTIMEOFDAY) /* Get current ECMAScript time (= UNIX/Posix time, but in milliseconds). */ @@ -26,12 +26,11 @@ } /* As of Duktape 2.2.0 allow fractions. */ - d = ((duk_double_t) tv.tv_sec) * 1000.0 + - ((duk_double_t) tv.tv_usec) / 1000.0; + d = ((duk_double_t) tv.tv_sec) * 1000.0 + ((duk_double_t) tv.tv_usec) / 1000.0; return d; } -#endif /* DUK_USE_DATE_NOW_GETTIMEOFDAY */ +#endif /* DUK_USE_DATE_NOW_GETTIMEOFDAY */ #if defined(DUK_USE_DATE_NOW_TIME) /* Not a very good provider: only full seconds are available. */ @@ -45,7 +44,7 @@ } return ((duk_double_t) t) * 1000.0; } -#endif /* DUK_USE_DATE_NOW_TIME */ +#endif /* DUK_USE_DATE_NOW_TIME */ #if defined(DUK_USE_DATE_TZO_GMTIME) || defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) /* Get local time offset (in seconds) for a certain (UTC) instant 'd'. */ @@ -128,7 +127,7 @@ DUK_ASSERT(partsDUK_DATE_IDX_YEAR >= 1970 && partsDUK_DATE_IDX_YEAR <= 2038); d = duk_bi_date_get_timeval_from_dparts(dparts, 0 /*flags*/); - DUK_ASSERT(d >= 0 && d < 2147483648.0 * 1000.0); /* unsigned 31-bit range */ + DUK_ASSERT(d >= 0 && d < 2147483648.0 * 1000.0); /* unsigned 31-bit range */ t = (time_t) (d / 1000.0); DUK_DDD(DUK_DDDPRINT("timeval: %lf -> time_t %ld", (double) d, (long) t)); @@ -150,14 +149,26 @@ #endif DUK_DDD(DUK_DDDPRINT("gmtime result: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tms0.tm_sec, (long) tms0.tm_min, (long) tms0.tm_hour, - (long) tms0.tm_mday, (long) tms0.tm_mon, (long) tms0.tm_year, - (long) tms0.tm_wday, (long) tms0.tm_yday, (long) tms0.tm_isdst)); + (long) tms0.tm_sec, + (long) tms0.tm_min, + (long) tms0.tm_hour, + (long) tms0.tm_mday, + (long) tms0.tm_mon, + (long) tms0.tm_year, + (long) tms0.tm_wday, + (long) tms0.tm_yday, + (long) tms0.tm_isdst)); DUK_DDD(DUK_DDDPRINT("localtime result: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tms1.tm_sec, (long) tms1.tm_min, (long) tms1.tm_hour, - (long) tms1.tm_mday, (long) tms1.tm_mon, (long) tms1.tm_year, - (long) tms1.tm_wday, (long) tms1.tm_yday, (long) tms1.tm_isdst)); + (long) tms1.tm_sec, + (long) tms1.tm_min, + (long) tms1.tm_hour, + (long) tms1.tm_mday, + (long) tms1.tm_mon, + (long) tms1.tm_year, + (long) tms1.tm_wday, + (long) tms1.tm_yday, + (long) tms1.tm_isdst)); /* tm_isdst is both an input and an output to mktime(), use 0 to * avoid DST handling in mktime(): @@ -166,8 +177,8 @@ */ tms0.tm_isdst = 0; tms1.tm_isdst = 0; - t1 = mktime(&tms0); /* UTC */ - t2 = mktime(&tms1); /* local */ + t1 = mktime(&tms0); /* UTC */ + t2 = mktime(&tms1); /* local */ if (t1 == (time_t) -1 || t2 == (time_t) -1) { /* This check used to be for (t < 0) but on some platforms * time_t is unsigned and apparently the proper way to detect @@ -190,12 +201,12 @@ #endif return (duk_int_t) difftime(t2, t1); - mktime_error: +mktime_error: /* XXX: return something more useful, so that caller can throw? */ DUK_D(DUK_DPRINT("mktime() failed, d=%lf", (double) d)); return 0; } -#endif /* DUK_USE_DATE_TZO_GMTIME */ +#endif /* DUK_USE_DATE_TZO_GMTIME */ #if defined(DUK_USE_DATE_PRS_STRPTIME) DUK_INTERNAL duk_bool_t duk_bi_date_parse_string_strptime(duk_hthread *thr, const char *str) { @@ -205,7 +216,7 @@ /* Copy to buffer with slack to avoid Valgrind gripes from strptime. */ DUK_ASSERT(str != NULL); - duk_memzero(buf, sizeof(buf)); /* valgrind whine without this */ + duk_memzero(buf, sizeof(buf)); /* valgrind whine without this */ DUK_SNPRINTF(buf, sizeof(buf), "%s", (const char *) str); bufsizeof(buf) - 1 = (char) 0; @@ -215,10 +226,16 @@ if (strptime((const char *) buf, "%c", &tm) != NULL) { DUK_DDD(DUK_DDDPRINT("before mktime: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tm.tm_sec, (long) tm.tm_min, (long) tm.tm_hour, - (long) tm.tm_mday, (long) tm.tm_mon, (long) tm.tm_year, - (long) tm.tm_wday, (long) tm.tm_yday, (long) tm.tm_isdst)); - tm.tm_isdst = -1; /* negative: dst info not available */ + (long) tm.tm_sec, + (long) tm.tm_min, + (long) tm.tm_hour, + (long) tm.tm_mday, + (long) tm.tm_mon, + (long) tm.tm_year, + (long) tm.tm_wday, + (long) tm.tm_yday, + (long) tm.tm_isdst)); + tm.tm_isdst = -1; /* negative: dst info not available */ t = mktime(&tm); DUK_DDD(DUK_DDDPRINT("mktime() -> %ld", (long) t)); @@ -230,7 +247,7 @@ return 0; } -#endif /* DUK_USE_DATE_PRS_STRPTIME */ +#endif /* DUK_USE_DATE_PRS_STRPTIME */ #if defined(DUK_USE_DATE_PRS_GETDATE) DUK_INTERNAL duk_bool_t duk_bi_date_parse_string_getdate(duk_hthread *thr, const char *str) { @@ -257,10 +274,13 @@ return 0; } -#endif /* DUK_USE_DATE_PRS_GETDATE */ +#endif /* DUK_USE_DATE_PRS_GETDATE */ #if defined(DUK_USE_DATE_FMT_STRFTIME) -DUK_INTERNAL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags) { +DUK_INTERNAL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, + duk_int_t *parts, + duk_int_t tzoffset, + duk_small_uint_t flags) { char bufDUK__STRFTIME_BUF_SIZE; struct tm tm; const char *fmt; @@ -278,8 +298,7 @@ * probably not an accurate guarantee of strftime() supporting or not * supporting a large time range (the full ECMAScript range). */ - if (sizeof(time_t) < 8 && - (partsDUK_DATE_IDX_YEAR < 1970 || partsDUK_DATE_IDX_YEAR > 2037)) { + if (sizeof(time_t) < 8 && (partsDUK_DATE_IDX_YEAR < 1970 || partsDUK_DATE_IDX_YEAR > 2037)) { /* be paranoid for 32-bit time values (even avoiding negative ones) */ return 0; } @@ -288,8 +307,8 @@ tm.tm_sec = partsDUK_DATE_IDX_SECOND; tm.tm_min = partsDUK_DATE_IDX_MINUTE; tm.tm_hour = partsDUK_DATE_IDX_HOUR; - tm.tm_mday = partsDUK_DATE_IDX_DAY; /* already one-based */ - tm.tm_mon = partsDUK_DATE_IDX_MONTH - 1; /* one-based -> zero-based */ + tm.tm_mday = partsDUK_DATE_IDX_DAY; /* already one-based */ + tm.tm_mon = partsDUK_DATE_IDX_MONTH - 1; /* one-based -> zero-based */ tm.tm_year = partsDUK_DATE_IDX_YEAR - 1900; tm.tm_wday = partsDUK_DATE_IDX_WEEKDAY; tm.tm_isdst = 0; @@ -309,7 +328,7 @@ duk_push_string(thr, buf); return 1; } -#endif /* DUK_USE_DATE_FMT_STRFTIME */ +#endif /* DUK_USE_DATE_FMT_STRFTIME */ #if defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME) DUK_INTERNAL duk_double_t duk_bi_date_get_monotonic_time_clock_gettime(void) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_date_windows.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_date_windows.c
Changed
@@ -28,20 +28,20 @@ res->LowPart = ft->dwLowDateTime; res->HighPart = ft->dwHighDateTime; } -#endif /* DUK_USE_DATE_NOW_WINDOWS_SUBMS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS_SUBMS */ DUK_LOCAL void duk__set_systime_jan1970(SYSTEMTIME *st) { duk_memzero((void *) st, sizeof(*st)); st->wYear = 1970; st->wMonth = 1; - st->wDayOfWeek = 4; /* not sure whether or not needed; Thursday */ + st->wDayOfWeek = 4; /* not sure whether or not needed; Thursday */ st->wDay = 1; DUK_ASSERT(st->wHour == 0); DUK_ASSERT(st->wMinute == 0); DUK_ASSERT(st->wSecond == 0); DUK_ASSERT(st->wMilliseconds == 0); } -#endif /* defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS) */ +#endif /* defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS) */ #if defined(DUK_USE_DATE_NOW_WINDOWS) DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows(void) { @@ -63,7 +63,7 @@ */ return (duk_double_t) ((LONGLONG) tmp1.QuadPart - (LONGLONG) tmp2.QuadPart) / 10000.0; } -#endif /* DUK_USE_DATE_NOW_WINDOWS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS */ #if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows_subms(void) { @@ -85,7 +85,7 @@ */ return (duk_double_t) ((LONGLONG) tmp1.QuadPart - (LONGLONG) tmp2.QuadPart) / 10000.0; } -#endif /* DUK_USE_DATE_NOW_WINDOWS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS */ #if defined(DUK_USE_DATE_TZO_WINDOWS) DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows(duk_double_t d) { @@ -110,8 +110,8 @@ duk__set_systime_jan1970(&st1); duk__convert_systime_to_ularge((const SYSTEMTIME *) &st1, &tmp1); - tmp2.QuadPart = (ULONGLONG) (d * 10000.0); /* millisec -> 100ns units since jan 1, 1970 */ - tmp2.QuadPart += tmp1.QuadPart; /* input 'd' in Windows UTC, 100ns units */ + tmp2.QuadPart = (ULONGLONG) (d * 10000.0); /* millisec -> 100ns units since jan 1, 1970 */ + tmp2.QuadPart += tmp1.QuadPart; /* input 'd' in Windows UTC, 100ns units */ ft1.dwLowDateTime = tmp2.LowPart; ft1.dwHighDateTime = tmp2.HighPart; @@ -126,9 +126,9 @@ duk__convert_systime_to_ularge((const SYSTEMTIME *) &st3, &tmp3); /* Positive if local time ahead of UTC. */ - return (duk_int_t) (((LONGLONG) tmp3.QuadPart - (LONGLONG) tmp2.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ + return (duk_int_t) (((LONGLONG) tmp3.QuadPart - (LONGLONG) tmp2.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ } -#endif /* DUK_USE_DATE_TZO_WINDOWS */ +#endif /* DUK_USE_DATE_TZO_WINDOWS */ #if defined(DUK_USE_DATE_TZO_WINDOWS_NO_DST) DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows_no_dst(duk_double_t d) { @@ -163,17 +163,19 @@ } duk__convert_systime_to_ularge((const SYSTEMTIME *) &st2, &tmp2); - return (duk_int_t) (((LONGLONG) tmp2.QuadPart - (LONGLONG) tmp1.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ + return (duk_int_t) (((LONGLONG) tmp2.QuadPart - (LONGLONG) tmp1.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ } -#endif /* DUK_USE_DATE_TZO_WINDOWS_NO_DST */ +#endif /* DUK_USE_DATE_TZO_WINDOWS_NO_DST */ #if defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC) DUK_INTERNAL duk_double_t duk_bi_date_get_monotonic_time_windows_qpc(void) { LARGE_INTEGER count, freq; /* There are legacy issues with QueryPerformanceCounter(): - * - Potential jumps: https://support.microsoft.com/en-us/help/274323/performance-counter-value-may-unexpectedly-leap-forward - * - Differences between cores (XP): https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions + * - Potential jumps: + * https://support.microsoft.com/en-us/help/274323/performance-counter-value-may-unexpectedly-leap-forward + * - Differences between cores (XP): + * https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions * * We avoid these by enabling QPC by default only for Vista or later. */ @@ -190,4 +192,4 @@ return 0.0; } } -#endif /* DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC */ +#endif /* DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_duktape.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_duktape.c
Changed
@@ -60,7 +60,7 @@ return 1; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_duktape_object_enc(duk_hthread *thr) { duk_hstring *h_str; @@ -70,7 +70,7 @@ * non-existent optional parameters. */ - h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons. */ + h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons. */ duk_require_valid_index(thr, 1); if (h_str == DUK_HTHREAD_STRING_HEX(thr)) { @@ -87,9 +87,8 @@ 1 /*idx_value*/, 2 /*idx_replacer*/, 3 /*idx_space*/, - DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_ASCII_ONLY | - DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); + DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_ASCII_ONLY | + DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); #endif #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JC) } else if (h_str == DUK_HTHREAD_STRING_JC(thr)) { @@ -97,8 +96,7 @@ 1 /*idx_value*/, 2 /*idx_replacer*/, 3 /*idx_space*/, - DUK_JSON_FLAG_EXT_COMPATIBLE | - DUK_JSON_FLAG_ASCII_ONLY /*flags*/); + DUK_JSON_FLAG_EXT_COMPATIBLE | DUK_JSON_FLAG_ASCII_ONLY /*flags*/); #endif } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -114,7 +112,7 @@ * non-existent optional parameters. */ - h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons */ + h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons */ duk_require_valid_index(thr, 1); if (h_str == DUK_HTHREAD_STRING_HEX(thr)) { @@ -127,17 +125,11 @@ DUK_ASSERT_TOP(thr, 2); #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JX) } else if (h_str == DUK_HTHREAD_STRING_JX(thr)) { - duk_bi_json_parse_helper(thr, - 1 /*idx_value*/, - 2 /*idx_replacer*/, - DUK_JSON_FLAG_EXT_CUSTOM /*flags*/); + duk_bi_json_parse_helper(thr, 1 /*idx_value*/, 2 /*idx_replacer*/, DUK_JSON_FLAG_EXT_CUSTOM /*flags*/); #endif #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JC) } else if (h_str == DUK_HTHREAD_STRING_JC(thr)) { - duk_bi_json_parse_helper(thr, - 1 /*idx_value*/, - 2 /*idx_replacer*/, - DUK_JSON_FLAG_EXT_COMPATIBLE /*flags*/); + duk_bi_json_parse_helper(thr, 1 /*idx_value*/, 2 /*idx_replacer*/, DUK_JSON_FLAG_EXT_COMPATIBLE /*flags*/); #endif } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -152,7 +144,7 @@ DUK_INTERNAL duk_ret_t duk_bi_duktape_object_compact(duk_hthread *thr) { DUK_ASSERT_TOP(thr, 1); duk_compact(thr, 0); - return 1; /* return the argument object */ + return 1; /* return the argument object */ } -#endif /* DUK_USE_DUKTAPE_BUILTIN */ +#endif /* DUK_USE_DUKTAPE_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_encoding.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_encoding.c
Changed
@@ -12,17 +12,17 @@ */ typedef struct { - duk_uint8_t *out; /* where to write next byte(s) */ - duk_codepoint_t lead; /* lead surrogate */ + duk_uint8_t *out; /* where to write next byte(s) */ + duk_codepoint_t lead; /* lead surrogate */ } duk__encode_context; typedef struct { /* UTF-8 decoding state */ - duk_codepoint_t codepoint; /* built up incrementally */ - duk_uint8_t upper; /* max value of next byte (decode error otherwise) */ - duk_uint8_t lower; /* min value of next byte (ditto) */ - duk_uint8_t needed; /* how many more bytes we need */ - duk_uint8_t bom_handled; /* BOM seen or no longer expected */ + duk_codepoint_t codepoint; /* built up incrementally */ + duk_uint8_t upper; /* max value of next byte (decode error otherwise) */ + duk_uint8_t lower; /* min value of next byte (ditto) */ + duk_uint8_t needed; /* how many more bytes we need */ + duk_uint8_t bom_handled; /* BOM seen or no longer expected */ /* Decoder configuration */ duk_uint8_t fatal; @@ -32,9 +32,9 @@ /* The signed duk_codepoint_t type is used to signal a decoded codepoint * (>= 0) or various other states using negative values. */ -#define DUK__CP_CONTINUE (-1) /* continue to next byte, no completed codepoint */ -#define DUK__CP_ERROR (-2) /* decoding error */ -#define DUK__CP_RETRY (-3) /* decoding error; retry last byte */ +#define DUK__CP_CONTINUE (-1) /* continue to next byte, no completed codepoint */ +#define DUK__CP_ERROR (-2) /* decoding error */ +#define DUK__CP_RETRY (-3) /* decoding error; retry last byte */ /* * Raw helpers for encoding/decoding @@ -121,7 +121,7 @@ } else { /* got a codepoint */ duk_codepoint_t ret; - DUK_ASSERT(dec_ctx->codepoint <= 0x10ffffL); /* Decoding rules guarantee. */ + DUK_ASSERT(dec_ctx->codepoint <= 0x10ffffL); /* Decoding rules guarantee. */ ret = dec_ctx->codepoint; dec_ctx->codepoint = 0x0000L; dec_ctx->needed = 0; @@ -177,7 +177,8 @@ } else { /* low surrogate */ if (enc_ctx->lead != 0x0000L) { - codepoint = (duk_codepoint_t) (0x010000L + ((enc_ctx->lead - 0xd800L) << 10) + (codepoint - 0xdc00L)); + codepoint = + (duk_codepoint_t) (0x010000L + ((enc_ctx->lead - 0xd800L) << 10) + (codepoint - 0xdc00L)); enc_ctx->lead = 0x0000L; } else { /* unpaired low surrogate */ @@ -198,7 +199,7 @@ */ enc_ctx->out += duk_unicode_encode_xutf8((duk_ucodepoint_t) codepoint, enc_ctx->out); } -#endif /* DUK_USE_ENCODING_BUILTINS */ +#endif /* DUK_USE_ENCODING_BUILTINS */ /* Shared helper for buffer-to-string using a TextDecoder() compatible UTF-8 * decoder. @@ -227,18 +228,15 @@ duk_push_fixed_buffer_nozero(thr, 0); duk_replace(thr, 0); } - (void) duk_require_buffer_data(thr, 0, &len); /* Need 'len', avoid pointer. */ + (void) duk_require_buffer_data(thr, 0, &len); /* Need 'len', avoid pointer. */ - if (duk_check_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_NONE)) { + if (duk_check_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_NONE)) { /* Use defaults, treat missing value like undefined. */ } else { - duk_require_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_OBJECT); + duk_require_type_mask(thr, + 1, + DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_LIGHTFUNC | + DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_OBJECT); if (duk_get_prop_literal(thr, 1, "stream")) { stream = duk_to_boolean(thr, -1); } @@ -256,7 +254,8 @@ DUK_ERROR_TYPE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return 0;); } - output = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, 3 + (3 * len)); /* used parts will be always manually written over */ + output = + (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, 3 + (3 * len)); /* used parts will be always manually written over */ input = (const duk_uint8_t *) duk_get_buffer_data(thr, 0, &len_tmp); DUK_ASSERT(input != NULL || len == 0); @@ -288,7 +287,7 @@ /* Decoding error with or without retry. */ DUK_ASSERT(codepoint == DUK__CP_ERROR || codepoint == DUK__CP_RETRY); if (codepoint == DUK__CP_RETRY) { - --in; /* retry last byte */ + --in; /* retry last byte */ } /* replacement mode: replace with U+FFFD */ codepoint = DUK_UNICODE_CP_REPLACEMENT_CHARACTER; @@ -321,7 +320,7 @@ DUK_ASSERT(out <= output + (3 + (3 * len))); } } - duk__utf8_decode_init(dec_ctx); /* Initialize decoding state for potential reuse. */ + duk__utf8_decode_init(dec_ctx); /* Initialize decoding state for potential reuse. */ } /* Output buffer is fixed and thus stable even if there had been @@ -330,7 +329,7 @@ duk_push_lstring(thr, (const char *) output, (duk_size_t) (out - output)); return 1; - fail_type: +fail_type: DUK_ERROR_TYPE(thr, DUK_STR_UTF8_DECODE_FAILED); DUK_WO_NORETURN(return 0;); } @@ -389,7 +388,7 @@ output = (duk_uint8_t *) duk_push_dynamic_buffer(thr, 3 * len); if (len > 0) { - DUK_ASSERT(duk_is_string(thr, 0)); /* True if len > 0. */ + DUK_ASSERT(duk_is_string(thr, 0)); /* True if len > 0. */ /* XXX: duk_decode_string() is used to process the input * string. For standard ECMAScript strings, represented @@ -465,7 +464,7 @@ dec_ctx = (duk__decode_context *) duk_push_fixed_buffer(thr, sizeof(duk__decode_context)); dec_ctx->fatal = (duk_uint8_t) fatal; dec_ctx->ignore_bom = (duk_uint8_t) ignore_bom; - duk__utf8_decode_init(dec_ctx); /* Initializes remaining fields. */ + duk__utf8_decode_init(dec_ctx); /* Initializes remaining fields. */ duk_put_prop_literal(thr, -2, DUK_INTERNAL_SYMBOL("Context")); return 0; @@ -511,7 +510,7 @@ dec_ctx = duk__get_textdecoder_context(thr); return duk__decode_helper(thr, dec_ctx); } -#endif /* DUK_USE_ENCODING_BUILTINS */ +#endif /* DUK_USE_ENCODING_BUILTINS */ /* * Internal helper for Node.js Buffer @@ -525,8 +524,8 @@ DUK_INTERNAL duk_ret_t duk_textdecoder_decode_utf8_nodejs(duk_hthread *thr) { duk__decode_context dec_ctx; - dec_ctx.fatal = 0; /* use replacement chars */ - dec_ctx.ignore_bom = 1; /* ignore BOMs (matches Node.js Buffer .toString()) */ + dec_ctx.fatal = 0; /* use replacement chars */ + dec_ctx.ignore_bom = 1; /* ignore BOMs (matches Node.js Buffer .toString()) */ duk__utf8_decode_init(&dec_ctx); return duk__decode_helper(thr, &dec_ctx);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_error.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_error.c
Changed
@@ -15,9 +15,8 @@ duk_small_int_t bidx_prototype = duk_get_current_magic(thr); /* same for both error and each subclass like TypeError */ - duk_uint_t flags_and_class = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR); + duk_uint_t flags_and_class = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR); (void) duk_push_object_helper(thr, flags_and_class, bidx_prototype); @@ -26,7 +25,7 @@ */ if (!duk_is_undefined(thr, 0)) { duk_to_string(thr, 0); - duk_dup_0(thr); /* message error message */ + duk_dup_0(thr); /* message error message */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC); } @@ -85,7 +84,7 @@ return 1; } duk_push_literal(thr, ": "); - duk_insert(thr, -2); /* ... name ': ' message */ + duk_insert(thr, -2); /* ... name ': ' message */ duk_concat(thr, 3); return 1; @@ -108,15 +107,15 @@ */ /* constants arbitrary, chosen for small loads */ -#define DUK__OUTPUT_TYPE_TRACEBACK (-1) -#define DUK__OUTPUT_TYPE_FILENAME 0 -#define DUK__OUTPUT_TYPE_LINENUMBER 1 +#define DUK__OUTPUT_TYPE_TRACEBACK (-1) +#define DUK__OUTPUT_TYPE_FILENAME 0 +#define DUK__OUTPUT_TYPE_LINENUMBER 1 DUK_LOCAL duk_ret_t duk__error_getter_helper(duk_hthread *thr, duk_small_int_t output_type) { duk_idx_t idx_td; - duk_small_int_t i; /* traceback depth fits into 16 bits */ - duk_small_int_t t; /* stack type fits into 16 bits */ - duk_small_int_t count_func = 0; /* traceback depth ensures fits into 16 bits */ + duk_small_int_t i; /* traceback depth fits into 16 bits */ + duk_small_int_t t; /* stack type fits into 16 bits */ + duk_small_int_t count_func = 0; /* traceback depth ensures fits into 16 bits */ const char *str_tailcall = " tailcall"; const char *str_strict = " strict"; const char *str_construct = " construct"; @@ -124,7 +123,7 @@ const char *str_directeval = " directeval"; const char *str_empty = ""; - DUK_ASSERT_TOP(thr, 0); /* fixed arg count */ + DUK_ASSERT_TOP(thr, 0); /* fixed arg count */ duk_push_this(thr); duk_xget_owndataprop_stridx_short(thr, -1, DUK_STRIDX_INT_TRACEDATA); @@ -139,7 +138,7 @@ if (duk_check_type(thr, idx_td, DUK_TYPE_OBJECT)) { /* Current tracedata contains 2 entries per callstack entry. */ - for (i = 0; ; i += 2) { + for (i = 0;; i += 2) { duk_int_t pc; duk_uint_t line; duk_uint_t flags; @@ -195,46 +194,53 @@ /* XXX: Change 'anon' handling here too, to use empty string for anonymous functions? */ /* XXX: Could be improved by coercing to a readable duk_tval (especially string escaping) */ - h_name = duk_get_hstring_notsymbol(thr, -2); /* may be NULL */ + h_name = duk_get_hstring_notsymbol(thr, -2); /* may be NULL */ funcname = (h_name == NULL || h_name == DUK_HTHREAD_STRING_EMPTY_STRING(thr)) ? - "anon" : (const char *) DUK_HSTRING_GET_DATA(h_name); + "anon" : + (const char *) DUK_HSTRING_GET_DATA(h_name); filename = duk_get_string_notsymbol(thr, -1); filename = filename ? filename : ""; DUK_ASSERT(funcname != NULL); DUK_ASSERT(filename != NULL); - h_func = duk_get_hobject(thr, -4); /* NULL for lightfunc */ + h_func = duk_get_hobject(thr, -4); /* NULL for lightfunc */ if (h_func == NULL) { - duk_push_sprintf(thr, "at %s light%s%s%s%s%s", - (const char *) funcname, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s light%s%s%s%s%s", + (const char *) funcname, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } else if (DUK_HOBJECT_HAS_NATFUNC(h_func)) { - duk_push_sprintf(thr, "at %s (%s) native%s%s%s%s%s", - (const char *) funcname, - (const char *) filename, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s (%s) native%s%s%s%s%s", + (const char *) funcname, + (const char *) filename, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } else { - duk_push_sprintf(thr, "at %s (%s:%lu)%s%s%s%s%s", - (const char *) funcname, - (const char *) filename, - (unsigned long) line, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s (%s:%lu)%s%s%s%s%s", + (const char *) funcname, + (const char *) filename, + (unsigned long) line, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } - duk_replace(thr, -5); /* ... v1 v2 name filename str -> ... str v2 name filename */ - duk_pop_3(thr); /* -> ... str */ + duk_replace(thr, -5); /* ... v1 v2 name filename str -> ... str v2 name filename */ + duk_pop_3(thr); /* -> ... str */ } else if (t == DUK_TYPE_STRING) { const char *str_file; @@ -265,10 +271,12 @@ * safety issues. */ str_file = (const char *) duk_get_string(thr, -2); - duk_push_sprintf(thr, "at anon (%s:%ld) internal", - (const char *) (str_file ? str_file : "null"), (long) pc); - duk_replace(thr, -3); /* ... v1 v2 str -> ... str v2 */ - duk_pop(thr); /* -> ... str */ + duk_push_sprintf(thr, + "at anon (%s:%ld) internal", + (const char *) (str_file ? str_file : "null"), + (long) pc); + duk_replace(thr, -3); /* ... v1 v2 str -> ... str v2 */ + duk_pop(thr); /* -> ... str */ } else { /* unknown, ignore */ duk_pop_2(thr); @@ -315,7 +323,7 @@ return duk__error_getter_helper(thr, DUK__OUTPUT_TYPE_LINENUMBER); } -#else /* DUK_USE_TRACEBACKS */ +#else /* DUK_USE_TRACEBACKS */ /* * Traceback handling when tracebacks disabled. @@ -346,7 +354,7 @@ return 0; } -#endif /* DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_TRACEBACKS */ DUK_LOCAL duk_ret_t duk__error_setter_helper(duk_hthread *thr, duk_small_uint_t stridx_key) { /* Attempt to write 'stack', 'fileName', 'lineNumber' works as if @@ -356,7 +364,7 @@ * See https://github.com/svaarala/duktape/issues/387. */ - DUK_ASSERT_TOP(thr, 1); /* fixed arg count: value */ + DUK_ASSERT_TOP(thr, 1); /* fixed arg count: value */ duk_push_this(thr); duk_push_hstring_stridx(thr, stridx_key); @@ -364,13 +372,13 @@ /* ... obj key value */ - DUK_DD(DUK_DDPRINT("error setter: %!T %!T %!T", - duk_get_tval(thr, -3), duk_get_tval(thr, -2), duk_get_tval(thr, -1))); + DUK_DD(DUK_DDPRINT("error setter: %!T %!T %!T", duk_get_tval(thr, -3), duk_get_tval(thr, -2), duk_get_tval(thr, -1))); - duk_def_prop(thr, -3, DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE | - DUK_DEFPROP_HAVE_ENUMERABLE | /*not enumerable*/ - DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE); + duk_def_prop(thr, + -3, + DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE | + DUK_DEFPROP_HAVE_ENUMERABLE | /*not enumerable*/ + DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE); return 0; }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_function.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_function.c
Changed
@@ -25,7 +25,7 @@ nargs = duk_get_top(thr); for (i = 0; i < nargs; i++) { - duk_to_string(thr, i); /* Rejects Symbols during coercion. */ + duk_to_string(thr, i); /* Rejects Symbols during coercion. */ } if (nargs == 0) { @@ -35,7 +35,7 @@ /* XXX: cover this with the generic >1 case? */ duk_push_hstring_empty(thr); } else { - duk_insert(thr, 0); /* arg1 ... argN-1 body -> body arg1 ... argN-1 */ + duk_insert(thr, 0); /* arg1 ... argN-1 body -> body arg1 ... argN-1 */ duk_push_literal(thr, ","); duk_insert(thr, 1); duk_join(thr, nargs - 1); @@ -52,7 +52,7 @@ duk_dup_1(thr); duk_push_literal(thr, "){"); duk_dup_0(thr); - duk_push_literal(thr, "\n}"); /* Newline is important to handle trailing // comment. */ + duk_push_literal(thr, "\n}"); /* Newline is important to handle trailing // comment. */ duk_concat(thr, 5); /* body formals source */ @@ -62,8 +62,8 @@ /* strictness is not inherited, intentional */ comp_flags = DUK_COMPILE_FUNCEXPR; - duk_push_hstring_stridx(thr, DUK_STRIDX_COMPILE); /* XXX: copy from caller? */ /* XXX: ignored now */ - h_sourcecode = duk_require_hstring(thr, -2); /* no symbol check needed; -2 is concat'd code */ + duk_push_hstring_stridx(thr, DUK_STRIDX_COMPILE); /* XXX: copy from caller? */ /* XXX: ignored now */ + h_sourcecode = duk_require_hstring(thr, -2); /* no symbol check needed; -2 is concat'd code */ duk_js_compile(thr, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_sourcecode), (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sourcecode), @@ -92,7 +92,7 @@ return 1; } -#endif /* DUK_USE_FUNCTION_BUILTIN */ +#endif /* DUK_USE_FUNCTION_BUILTIN */ #if defined(DUK_USE_FUNCTION_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_function_prototype_to_string(duk_hthread *thr) { @@ -158,7 +158,7 @@ return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } #endif @@ -200,7 +200,7 @@ */ DUK_INTERNAL duk_ret_t duk_bi_function_prototype_bind(duk_hthread *thr) { duk_hboundfunc *h_bound; - duk_idx_t nargs; /* bound args, not counting 'this' binding */ + duk_idx_t nargs; /* bound args, not counting 'this' binding */ duk_idx_t bound_nargs; duk_int_t bound_len; duk_tval *tv_prevbound; @@ -213,7 +213,7 @@ /* Vararg function, careful arg handling, e.g. thisArg may not * be present. */ - nargs = duk_get_top(thr) - 1; /* actual args, not counting 'this' binding */ + nargs = duk_get_top(thr) - 1; /* actual args, not counting 'this' binding */ if (nargs < 0) { nargs++; duk_push_undefined(thr); @@ -308,7 +308,7 @@ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) h_bound, bound_proto); } - DUK_TVAL_INCREF(thr, &h_bound->target); /* old values undefined, no decref needed */ + DUK_TVAL_INCREF(thr, &h_bound->target); /* old values undefined, no decref needed */ DUK_TVAL_INCREF(thr, &h_bound->this_binding); bound_nargs = n_prevbound + nargs; @@ -333,7 +333,7 @@ * For lightfuncs, simply read the virtual property. */ duk_get_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH); - bound_len = duk_get_int(thr, -1); /* ES2015: no coercion */ + bound_len = duk_get_int(thr, -1); /* ES2015: no coercion */ if (bound_len < nargs) { bound_len = 0; } else { @@ -347,8 +347,8 @@ tv_tmp = thr->valstack_top++; DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_tmp)); DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_tmp)); - DUK_TVAL_SET_U32(tv_tmp, (duk_uint32_t) bound_len); /* in-place update, fastint */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* attrs in E6 Section 9.2.4 */ + DUK_TVAL_SET_U32(tv_tmp, (duk_uint32_t) bound_len); /* in-place update, fastint */ + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* attrs in E6 Section 9.2.4 */ /* XXX: could these be virtual? */ /* Caller and arguments must use the same thrower, ThrowTypeError. */ @@ -356,7 +356,7 @@ duk_xdef_prop_stridx_thrower(thr, -1, DUK_STRIDX_LC_ARGUMENTS); /* Function name and fileName (non-standard). */ - duk_push_literal(thr, "bound "); /* ES2015 19.2.3.2. */ + duk_push_literal(thr, "bound "); /* ES2015 19.2.3.2. */ duk_get_prop_stridx(thr, -3, DUK_STRIDX_NAME); if (!duk_is_string_notsymbol(thr, -1)) { /* ES2015 has requirement to check that .name of target is a string @@ -377,7 +377,7 @@ return 1; } -#endif /* DUK_USE_FUNCTION_BUILTIN */ +#endif /* DUK_USE_FUNCTION_BUILTIN */ /* %NativeFunctionPrototype% .length getter. */ DUK_INTERNAL duk_ret_t duk_bi_native_function_length(duk_hthread *thr) { @@ -408,7 +408,7 @@ } return 1; - fail_type: +fail_type: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -437,7 +437,7 @@ } return 1; - fail_type: +fail_type: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -450,4 +450,4 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_global.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_global.c
Changed
@@ -16,73 +16,71 @@ /* Macros for creating and checking bitmasks for character encoding. * Bit number is a bit counterintuitive, but minimizes code size. */ -#define DUK__MKBITS(a,b,c,d,e,f,g,h) ((duk_uint8_t) ( \ - ((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | \ - ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7) \ - )) -#define DUK__CHECK_BITMASK(table,cp) ((table)(cp) >> 3 & (1 << ((cp) & 0x07))) +#define DUK__MKBITS(a, b, c, d, e, f, g, h) \ + ((duk_uint8_t) (((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7))) +#define DUK__CHECK_BITMASK(table, cp) ((table)(cp) >> 3 & (1 << ((cp) &0x07))) /* E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#' */ DUK_LOCAL const duk_uint8_t duk__encode_uriunescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 1, 0, 1, 1, 0, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 1, 0, 1, 1, 0, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.4: uriUnescaped */ DUK_LOCAL const duk_uint8_t duk__encode_uricomponent_unescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 1, 0, 0, 0, 0, 0, 1), DUK__MKBITS(1, 1, 1, 0, 0, 1, 1, 0), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 1, 0, 0, 0, 0, 0, 1), DUK__MKBITS(1, 1, 1, 0, 0, 1, 1, 0), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.1: uriReserved + '#' */ DUK_LOCAL const duk_uint8_t duk__decode_uri_reserved_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 1, 1, 0, 1, 0), DUK__MKBITS(0, 0, 0, 1, 1, 0, 0, 1), /* 0x20-0x2f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ - DUK__MKBITS(1, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 1, 1, 0, 1, 0), DUK__MKBITS(0, 0, 0, 1, 1, 0, 0, 1), /* 0x20-0x2f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ + DUK__MKBITS(1, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.2: empty */ DUK_LOCAL const duk_uint8_t duk__decode_uri_component_reserved_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x20-0x2f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x20-0x2f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ }; #if defined(DUK_USE_SECTION_B) /* E5.1 Section B.2.2, step 7. */ DUK_LOCAL const duk_uint8_t duk__escape_unescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 1, 1), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 0) /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 1, 1), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 0) /* 0x70-0x7f */ }; -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ typedef struct { duk_hthread *thr; @@ -123,7 +121,7 @@ tfm_ctx->h_str = duk_to_hstring(thr, 0); DUK_ASSERT(tfm_ctx->h_str != NULL); - DUK_BW_INIT_PUSHBUF(thr, &tfm_ctx->bw, DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str)); /* initial size guess */ + DUK_BW_INIT_PUSHBUF(thr, &tfm_ctx->bw, DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str)); /* initial size guess */ tfm_ctx->p_start = DUK_HSTRING_GET_DATA(tfm_ctx->h_str); tfm_ctx->p_end = tfm_ctx->p_start + DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str); @@ -136,7 +134,7 @@ DUK_BW_COMPACT(thr, &tfm_ctx->bw); - (void) duk_buffer_to_string(thr, -1); /* Safe if transform is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if transform is safe. */ return 1; } @@ -162,7 +160,11 @@ goto uri_error; } else if (cp >= 0xd800L && cp <= 0xdbffL) { /* Needs lookahead */ - if (duk_unicode_decode_xutf8(tfm_ctx->thr, &tfm_ctx->p, tfm_ctx->p_start, tfm_ctx->p_end, (duk_ucodepoint_t *) &cp2) == 0) { + if (duk_unicode_decode_xutf8(tfm_ctx->thr, + &tfm_ctx->p, + tfm_ctx->p_start, + tfm_ctx->p_end, + (duk_ucodepoint_t *) &cp2) == 0) { goto uri_error; } if (!(cp2 >= 0xdc00L && cp2 <= 0xdfffL)) { @@ -193,12 +195,12 @@ &tfm_ctx->bw, DUK_ASC_PERCENT, (duk_uint8_t) duk_uc_nybblest >> 4, - (duk_uint8_t) duk_uc_nybblest & 0x0f); + (duk_uint8_t) duk_uc_nybblest & 0x0f); } return; - uri_error: +uri_error: DUK_ERROR_URI(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -207,7 +209,7 @@ const duk_uint8_t *reserved_table = (const duk_uint8_t *) udata; duk_small_uint_t utf8_blen; duk_codepoint_t min_cp; - duk_small_int_t t; /* must be signed */ + duk_small_int_t t; /* must be signed */ duk_small_uint_t i; /* Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH, @@ -215,12 +217,12 @@ */ DUK_BW_ENSURE(tfm_ctx->thr, &tfm_ctx->bw, - (DUK_UNICODE_MAX_XUTF8_LENGTH >= 2 * DUK_UNICODE_MAX_CESU8_BMP_LENGTH ? - DUK_UNICODE_MAX_XUTF8_LENGTH : DUK_UNICODE_MAX_CESU8_BMP_LENGTH)); + (DUK_UNICODE_MAX_XUTF8_LENGTH >= 2 * DUK_UNICODE_MAX_CESU8_BMP_LENGTH ? DUK_UNICODE_MAX_XUTF8_LENGTH : + DUK_UNICODE_MAX_CESU8_BMP_LENGTH)); if (cp == (duk_codepoint_t) '%') { const duk_uint8_t *p = tfm_ctx->p; - duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ + duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ DUK_DDD(DUK_DDDPRINT("percent encoding, left=%ld", (long) left)); @@ -238,11 +240,7 @@ if (DUK__CHECK_BITMASK(reserved_table, t)) { /* decode '%xx' to '%xx' if decoded char in reserved set */ DUK_ASSERT(tfm_ctx->p - 1 >= tfm_ctx->p_start); - DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr, - &tfm_ctx->bw, - DUK_ASC_PERCENT, - p0, - p1); + DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr, &tfm_ctx->bw, DUK_ASC_PERCENT, p0, p1); } else { DUK_BW_WRITE_RAW_U8(tfm_ctx->thr, &tfm_ctx->bw, (duk_uint8_t) t); } @@ -293,7 +291,10 @@ /* p points to digit part ('%xy', p points to 'x') */ t = duk__decode_hex_escape(p, 2); DUK_DDD(DUK_DDDPRINT("i=%ld utf8_blen=%ld cp=%ld t=0x%02lx", - (long) i, (long) utf8_blen, (long) cp, (unsigned long) t)); + (long) i, + (long) utf8_blen, + (long) cp, + (unsigned long) t)); if (t < 0) { goto uri_error; } @@ -303,7 +304,7 @@ cp = (cp << 6) + (t & 0x3f); p += 3; } - p--; /* p overshoots */ + p--; /* p overshoots */ tfm_ctx->p = p; DUK_DDD(DUK_DDDPRINT("final cp=%ld, min_cp=%ld", (long) cp, (long) min_cp)); @@ -337,7 +338,7 @@ } return; - uri_error: +uri_error: DUK_ERROR_URI(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -378,7 +379,7 @@ return; - esc_error: +esc_error: DUK_ERROR_TYPE(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -390,14 +391,12 @@ if (cp == (duk_codepoint_t) '%') { const duk_uint8_t *p = tfm_ctx->p; - duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ + duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ - if (left >= 5 && p0 == 'u' && - ((t = duk__decode_hex_escape(p + 1, 4)) >= 0)) { + if (left >= 5 && p0 == 'u' && ((t = duk__decode_hex_escape(p + 1, 4)) >= 0)) { cp = (duk_codepoint_t) t; tfm_ctx->p += 5; - } else if (left >= 2 && - ((t = duk__decode_hex_escape(p, 2)) >= 0)) { + } else if (left >= 2 && ((t = duk__decode_hex_escape(p, 2)) >= 0)) { cp = (duk_codepoint_t) t; tfm_ctx->p += 2; } @@ -405,7 +404,7 @@ DUK_BW_WRITE_ENSURE_XUTF8(tfm_ctx->thr, &tfm_ctx->bw, cp); } -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ /* * Eval @@ -430,11 +429,11 @@ duk_int_t level = -2; duk_small_uint_t call_flags; - DUK_ASSERT(duk_get_top(thr) == 1 || duk_get_top(thr) == 2); /* 2 when called by debugger */ - DUK_ASSERT(thr->callstack_top >= 1); /* at least this function exists */ + DUK_ASSERT(duk_get_top(thr) == 1 || duk_get_top(thr) == 2); /* 2 when called by debugger */ + DUK_ASSERT(thr->callstack_top >= 1); /* at least this function exists */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT((thr->callstack_curr->flags & DUK_ACT_FLAG_DIRECT_EVAL) == 0 || /* indirect eval */ - (thr->callstack_top >= 2)); /* if direct eval, calling activation must exist */ + (thr->callstack_top >= 2)); /* if direct eval, calling activation must exist */ /* * callstack_top - 1 --> this function @@ -447,32 +446,31 @@ h = duk_get_hstring_notsymbol(thr, 0); if (!h) { /* Symbol must be returned as is, like any non-string values. */ - return 1; /* return arg as-is */ + return 1; /* return arg as-is */ } #if defined(DUK_USE_DEBUGGER_SUPPORT) /* NOTE: level is used only by the debugger and should never be present * for an ECMAScript eval(). */ - DUK_ASSERT(level == -2); /* by default, use caller's environment */ + DUK_ASSERT(level == -2); /* by default, use caller's environment */ if (duk_get_top(thr) >= 2 && duk_is_number(thr, 1)) { level = duk_get_int(thr, 1); } - DUK_ASSERT(level <= -2); /* This is guaranteed by debugger code. */ + DUK_ASSERT(level <= -2); /* This is guaranteed by debugger code. */ #endif /* source */ comp_flags = DUK_COMPILE_EVAL; - act_eval = thr->callstack_curr; /* this function */ + act_eval = thr->callstack_curr; /* this function */ DUK_ASSERT(act_eval != NULL); act_caller = duk_hthread_get_activation_for_level(thr, level); if (act_caller != NULL) { /* Have a calling activation, check for direct eval (otherwise * assume indirect eval. */ - if ((act_caller->flags & DUK_ACT_FLAG_STRICT) && - (act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL)) { + if ((act_caller->flags & DUK_ACT_FLAG_STRICT) && (act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL)) { /* Only direct eval inherits strictness from calling code * (E5.1 Section 10.1.1). */ @@ -482,11 +480,8 @@ DUK_ASSERT((act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL) == 0); } - duk_push_hstring_stridx(thr, DUK_STRIDX_INPUT); /* XXX: copy from caller? */ - duk_js_compile(thr, - (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), - (duk_size_t) DUK_HSTRING_GET_BYTELEN(h), - comp_flags); + duk_push_hstring_stridx(thr, DUK_STRIDX_INPUT); /* XXX: copy from caller? */ + duk_js_compile(thr, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), (duk_size_t) DUK_HSTRING_GET_BYTELEN(h), comp_flags); func = (duk_hcompfunc *) duk_known_hobject(thr, -1); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) func)); @@ -519,9 +514,9 @@ act_lex_env = act_caller->lex_env; - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); @@ -533,7 +528,7 @@ outer_lex_env = (duk_hobject *) new_env; outer_var_env = (duk_hobject *) new_env; - duk_insert(thr, 0); /* stash to bottom of value stack to keep new_env reachable for duration of eval */ + duk_insert(thr, 0); /* stash to bottom of value stack to keep new_env reachable for duration of eval */ /* compiler's responsibility */ DUK_ASSERT(DUK_HOBJECT_HAS_NEWENV((duk_hobject *) func)); @@ -569,7 +564,8 @@ duk_tval *tv; DUK_ASSERT(thr->callstack_top >= 2); DUK_ASSERT(act_caller != NULL); - tv = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act_caller->bottom_byteoff - sizeof(duk_tval)); /* this is just beneath bottom */ + tv = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act_caller->bottom_byteoff - + sizeof(duk_tval)); /* this is just beneath bottom */ DUK_ASSERT(tv >= thr->valstack); duk_push_tval(thr, tv); } @@ -608,19 +604,15 @@ duk_small_uint_t s2n_flags; DUK_ASSERT_TOP(thr, 2); - duk_to_string(thr, 0); /* Reject symbols. */ + duk_to_string(thr, 0); /* Reject symbols. */ radix = duk_to_int32(thr, 1); /* While parseInt() recognizes 0xdeadbeef, it doesn't recognize * ES2015 0o123 or 0b10001. */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_GARBAGE | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO | - DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_GARBAGE | DUK_S2N_FLAG_ALLOW_PLUS | DUK_S2N_FLAG_ALLOW_MINUS | + DUK_S2N_FLAG_ALLOW_LEADING_ZERO | DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT; /* Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT. * @@ -644,35 +636,28 @@ duk_numconv_parse(thr, (duk_small_int_t) radix, s2n_flags); return 1; - ret_nan: +ret_nan: duk_push_nan(thr); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ #if defined(DUK_USE_GLOBAL_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_global_object_parse_float(duk_hthread *thr) { duk_small_uint_t s2n_flags; DUK_ASSERT_TOP(thr, 1); - duk_to_string(thr, 0); /* Reject symbols. */ + duk_to_string(thr, 0); /* Reject symbols. */ /* XXX: check flags */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_GARBAGE | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_INF | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_GARBAGE | DUK_S2N_FLAG_ALLOW_PLUS | + DUK_S2N_FLAG_ALLOW_MINUS | DUK_S2N_FLAG_ALLOW_INF | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_LEADING_ZERO; duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ /* * Number checkers @@ -684,7 +669,7 @@ duk_push_boolean(thr, (duk_bool_t) DUK_ISNAN(d)); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ #if defined(DUK_USE_GLOBAL_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_global_object_is_finite(duk_hthread *thr) { @@ -692,7 +677,7 @@ duk_push_boolean(thr, (duk_bool_t) DUK_ISFINITE(d)); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ /* * URI handling @@ -704,7 +689,9 @@ } DUK_INTERNAL duk_ret_t duk_bi_global_object_decode_uri_component(duk_hthread *thr) { - return duk__transform_helper(thr, duk__transform_callback_decode_uri, (const void *) duk__decode_uri_component_reserved_table); + return duk__transform_helper(thr, + duk__transform_callback_decode_uri, + (const void *) duk__decode_uri_component_reserved_table); } DUK_INTERNAL duk_ret_t duk_bi_global_object_encode_uri(duk_hthread *thr) { @@ -712,7 +699,9 @@ } DUK_INTERNAL duk_ret_t duk_bi_global_object_encode_uri_component(duk_hthread *thr) { - return duk__transform_helper(thr, duk__transform_callback_encode_uri, (const void *) duk__encode_uricomponent_unescaped_table); + return duk__transform_helper(thr, + duk__transform_callback_encode_uri, + (const void *) duk__encode_uricomponent_unescaped_table); } #if defined(DUK_USE_SECTION_B) @@ -723,5 +712,5 @@ DUK_INTERNAL duk_ret_t duk_bi_global_object_unescape(duk_hthread *thr) { return duk__transform_helper(thr, duk__transform_callback_unescape, (const void *) NULL); } -#endif /* DUK_USE_SECTION_B */ -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_GLOBAL_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_json.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_json.c
Changed
@@ -22,11 +22,11 @@ * Local defines and forward declarations. */ -#define DUK__JSON_DECSTR_BUFSIZE 128 -#define DUK__JSON_DECSTR_CHUNKSIZE 64 -#define DUK__JSON_ENCSTR_CHUNKSIZE 64 +#define DUK__JSON_DECSTR_BUFSIZE 128 +#define DUK__JSON_DECSTR_CHUNKSIZE 64 +#define DUK__JSON_ENCSTR_CHUNKSIZE 64 #define DUK__JSON_STRINGIFY_BUFSIZE 128 -#define DUK__JSON_MAX_ESC_LEN 10 /* '\Udeadbeef' */ +#define DUK__JSON_MAX_ESC_LEN 10 /* '\Udeadbeef' */ DUK_LOCAL_DECL void duk__json_dec_syntax_error(duk_json_dec_ctx *js_ctx); DUK_LOCAL_DECL void duk__json_dec_eat_white(duk_json_dec_ctx *js_ctx); @@ -96,103 +96,88 @@ * 0xa0 ... 0xff: backslash + one char */ - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xe2, 0xf4, 0xee, 0x80, 0xe6, 0xf2, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x20, 0x21, 0xa2, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0xdc, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xe2, 0xf4, 0xee, 0x80, 0xe6, 0xf2, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x20, 0x21, 0xa2, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0xdc, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81 }; -#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ -DUK_LOCAL const duk_uint8_t duk__json_quotestr_esc14 = { - DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, - DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, - DUK_ASC_LC_B, DUK_ASC_LC_T, DUK_ASC_LC_N, DUK_ASC_NUL, - DUK_ASC_LC_F, DUK_ASC_LC_R -}; -#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +DUK_LOCAL const duk_uint8_t duk__json_quotestr_esc14 = { DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, + DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_LC_B, DUK_ASC_LC_T, + DUK_ASC_LC_N, DUK_ASC_NUL, DUK_ASC_LC_F, DUK_ASC_LC_R }; +#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ #if defined(DUK_USE_JSON_DECSTRING_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_decstr_lookup256 = { /* 0x00: slow path * other: as is */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x20, 0x21, 0x00, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x00, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x21, 0x00, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x00, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, + 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; -#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ +#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ #if defined(DUK_USE_JSON_EATWHITE_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_eatwhite_lookup256 = { /* 0x00: finish (non-white) * 0x01: continue */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ #if defined(DUK_USE_JSON_DECNUMBER_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_decnumber_lookup256 = { /* 0x00: finish (not part of number) * 0x01: continue */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ +#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ /* * Parsing implementation. @@ -212,8 +197,7 @@ * hidden, unfortunately, but we'll have an offset which * is often quite enough. */ - DUK_ERROR_FMT1(js_ctx->thr, DUK_ERR_SYNTAX_ERROR, DUK_STR_FMT_INVALID_JSON, - (long) (js_ctx->p - js_ctx->p_start)); + DUK_ERROR_FMT1(js_ctx->thr, DUK_ERR_SYNTAX_ERROR, DUK_STR_FMT_INVALID_JSON, (long) (js_ctx->p - js_ctx->p_start)); DUK_WO_NORETURN(return;); } @@ -230,18 +214,18 @@ /* This fast path is pretty marginal in practice. * XXX: candidate for removal. */ - DUK_ASSERT(duk__json_eatwhite_lookup0x00 == 0x00); /* end-of-input breaks */ + DUK_ASSERT(duk__json_eatwhite_lookup0x00 == 0x00); /* end-of-input breaks */ if (duk__json_eatwhite_lookupt == 0) { break; } -#else /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#else /* DUK_USE_JSON_EATWHITE_FASTPATH */ if (!(t == 0x20 || t == 0x0a || t == 0x0d || t == 0x09)) { /* NUL also comes here. Comparison order matters, 0x20 * is most common whitespace. */ break; } -#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ p++; } js_ctx->p = p; @@ -275,8 +259,7 @@ /* XXX: share helper from lexer; duk_lexer.c / hexval(). */ x = duk__json_dec_get(js_ctx); - DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%ld, n=%ld, res=%ld, x=%ld", - (long) i, (long) n, (long) res, (long) x)); + DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%ld, n=%ld, res=%ld, x=%ld", (long) i, (long) n, (long) res, (long) x)); /* x == 0x00 (EOF) causes syntax_error */ DUK_ASSERT(duk_hex_dectab0 == -1); @@ -292,7 +275,7 @@ DUK_DDD(DUK_DDDPRINT("final hex decoded value: %ld", (long) res)); return res; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); return 0; @@ -313,7 +296,7 @@ DUK_ASSERT(h != NULL); p = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h) + 1; - DUK_ASSERT(*(js_ctx->p - 1) == *(p - 1)); /* first character has been matched */ + DUK_ASSERT(*(js_ctx->p - 1) == *(p - 1)); /* first character has been matched */ for (;;) { x = *p; @@ -330,7 +313,7 @@ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -344,14 +327,27 @@ */ cp = (duk_uint_fast32_t) duk__json_dec_get(js_ctx); switch (cp) { - case DUK_ASC_BACKSLASH: break; - case DUK_ASC_DOUBLEQUOTE: break; - case DUK_ASC_SLASH: break; - case DUK_ASC_LC_T: cp = 0x09; break; - case DUK_ASC_LC_N: cp = 0x0a; break; - case DUK_ASC_LC_R: cp = 0x0d; break; - case DUK_ASC_LC_F: cp = 0x0c; break; - case DUK_ASC_LC_B: cp = 0x08; break; + case DUK_ASC_BACKSLASH: + break; + case DUK_ASC_DOUBLEQUOTE: + break; + case DUK_ASC_SLASH: + break; + case DUK_ASC_LC_T: + cp = 0x09; + break; + case DUK_ASC_LC_N: + cp = 0x0a; + break; + case DUK_ASC_LC_R: + cp = 0x0d; + break; + case DUK_ASC_LC_F: + cp = 0x0c; + break; + case DUK_ASC_LC_B: + cp = 0x08; + break; case DUK_ASC_LC_U: { cp = duk__json_dec_decode_hex_escape(js_ctx, 4); break; @@ -361,7 +357,7 @@ if (js_ctx->flag_ext_custom) { cp = duk__json_dec_decode_hex_escape(js_ctx, 8); } else { - return 1; /* syntax error */ + return 1; /* syntax error */ } break; } @@ -369,14 +365,14 @@ if (js_ctx->flag_ext_custom) { cp = duk__json_dec_decode_hex_escape(js_ctx, 2); } else { - return 1; /* syntax error */ + return 1; /* syntax error */ } break; } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ default: /* catches EOF (0x00) */ - return 1; /* syntax error */ + return 1; /* syntax error */ } DUK_RAW_WRITEINC_XUTF8(*ext_p, cp); @@ -418,7 +414,7 @@ /* Ensure space for 1:1 output plus one escape. */ q = DUK_BW_ENSURE_RAW(js_ctx->thr, bw, safe + DUK_UNICODE_MAX_XUTF8_LENGTH, q); - p = js_ctx->p; /* temp copy, write back for next loop */ + p = js_ctx->p; /* temp copy, write back for next loop */ for (;;) { if (safe == 0) { js_ctx->p = p; @@ -453,8 +449,8 @@ } } } - found_quote: -#else /* DUK_USE_JSON_DECSTRING_FASTPATH */ +found_quote: +#else /* DUK_USE_JSON_DECSTRING_FASTPATH */ for (;;) { duk_uint8_t x; @@ -475,16 +471,16 @@ *q++ = (duk_uint8_t) x; } } -#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ +#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ DUK_BW_SETPTR_AND_COMPACT(js_ctx->thr, bw, q); - (void) duk_buffer_to_string(thr, -1); /* Safe if input string is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if input string is safe. */ /* ... str */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -500,7 +496,7 @@ /* Caller has already eaten the first char so backtrack one byte. */ - js_ctx->p--; /* safe */ + js_ctx->p--; /* safe */ p = js_ctx->p; /* Here again we parse bytes, and non-ASCII UTF-8 will cause end of @@ -532,7 +528,7 @@ /* ... str */ } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) DUK_LOCAL void duk__json_dec_pointer(duk_json_dec_ctx *js_ctx) { @@ -575,17 +571,17 @@ voidptr = NULL; (void) DUK_SSCANF((const char *) js_ctx->p, DUK_STR_FMT_PTR, &voidptr); duk_push_pointer(thr, voidptr); - js_ctx->p = p + 1; /* skip ')' */ + js_ctx->p = p + 1; /* skip ')' */ /* ... ptr */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) DUK_LOCAL void duk__json_dec_buffer(duk_json_dec_ctx *js_ctx) { @@ -633,17 +629,17 @@ duk_memcpy((void *) buf, (const void *) js_ctx->p, src_len); duk_hex_decode(thr, -1); - js_ctx->p = p + 1; /* skip '|' */ + js_ctx->p = p + 1; /* skip '|' */ /* ... buf */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ /* Parse a number, other than NaN or +/- Infinity */ DUK_LOCAL void duk__json_dec_number(duk_json_dec_ctx *js_ctx) { @@ -666,47 +662,45 @@ x = *p; DUK_DDD(DUK_DDDPRINT("parse_number: p_start=%p, p=%p, p_end=%p, x=%ld", - (const void *) p_start, (const void *) p, - (const void *) js_ctx->p_end, (long) x)); + (const void *) p_start, + (const void *) p, + (const void *) js_ctx->p_end, + (long) x)); #if defined(DUK_USE_JSON_DECNUMBER_FASTPATH) /* This fast path is pretty marginal in practice. * XXX: candidate for removal. */ - DUK_ASSERT(duk__json_decnumber_lookup0x00 == 0x00); /* end-of-input breaks */ + DUK_ASSERT(duk__json_decnumber_lookup0x00 == 0x00); /* end-of-input breaks */ if (duk__json_decnumber_lookupx == 0) { break; } -#else /* DUK_USE_JSON_DECNUMBER_FASTPATH */ +#else /* DUK_USE_JSON_DECNUMBER_FASTPATH */ if (!((x >= DUK_ASC_0 && x <= DUK_ASC_9) || - (x == DUK_ASC_PERIOD || x == DUK_ASC_LC_E || - x == DUK_ASC_UC_E || x == DUK_ASC_MINUS || x == DUK_ASC_PLUS))) { + (x == DUK_ASC_PERIOD || x == DUK_ASC_LC_E || x == DUK_ASC_UC_E || x == DUK_ASC_MINUS || x == DUK_ASC_PLUS))) { /* Plus sign must be accepted for positive exponents * (e.g. '1.5e+2'). This clause catches NULs. */ break; } -#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ - p++; /* safe, because matched (NUL causes a break) */ +#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ + p++; /* safe, because matched (NUL causes a break) */ } js_ctx->p = p; DUK_ASSERT(js_ctx->p > p_start); duk_push_lstring(thr, (const char *) p_start, (duk_size_t) (p - p_start)); - s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_MINUS | /* but don't allow leading plus */ + s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_MINUS | /* but don't allow leading plus */ DUK_S2N_FLAG_ALLOW_FRAC; - DUK_DDD(DUK_DDDPRINT("parse_number: string before parsing: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_number: string before parsing: %!T", (duk_tval *) duk_get_tval(thr, -1))); duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); if (duk_is_nan(thr, -1)) { duk__json_dec_syntax_error(js_ctx); } DUK_ASSERT(duk_is_number(thr, -1)); - DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T", (duk_tval *) duk_get_tval(thr, -1))); /* ... num */ } @@ -719,7 +713,7 @@ duk_native_stack_check(thr); - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_ERROR_RANGE(thr, DUK_STR_DEC_RECLIMIT); @@ -738,7 +732,7 @@ DUK_LOCAL void duk__json_dec_object(duk_json_dec_ctx *js_ctx) { duk_hthread *thr = js_ctx->thr; - duk_int_t key_count; /* XXX: a "first" flag would suffice */ + duk_int_t key_count; /* XXX: a "first" flag would suffice */ duk_uint8_t x; DUK_DDD(DUK_DDDPRINT("parse_object")); @@ -755,7 +749,8 @@ DUK_DDD(DUK_DDDPRINT("parse_object: obj=%!T, x=%ld, key_count=%ld", (duk_tval *) duk_get_tval(thr, -1), - (long) x, (long) key_count)); + (long) x, + (long) key_count)); /* handle comma and closing brace */ @@ -780,8 +775,7 @@ if (x == DUK_ASC_DOUBLEQUOTE) { duk__json_dec_string(js_ctx); #if defined(DUK_USE_JX) - } else if (js_ctx->flag_ext_custom && - duk_unicode_is_identifier_start((duk_codepoint_t) x)) { + } else if (js_ctx->flag_ext_custom && duk_unicode_is_identifier_start((duk_codepoint_t) x)) { duk__json_dec_plain_string(js_ctx); #endif } else { @@ -808,13 +802,12 @@ /* ... obj */ - DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_dec_objarr_exit(js_ctx); return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -838,7 +831,8 @@ DUK_DDD(DUK_DDDPRINT("parse_array: arr=%!T, x=%ld, arr_idx=%ld", (duk_tval *) duk_get_tval(thr, -1), - (long) x, (long) arr_idx)); + (long) x, + (long) arr_idx)); /* handle comma and closing bracket */ @@ -852,7 +846,7 @@ /* accept anything, expect first value (EOF will be * caught by duk__json_dec_value() below. */ - js_ctx->p--; /* backtrack (safe) */ + js_ctx->p--; /* backtrack (safe) */ } else { /* catches EOF (NUL) and initial comma */ goto syntax_error; @@ -876,13 +870,12 @@ /* ... arr */ - DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_dec_objarr_exit(js_ctx); return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -902,14 +895,14 @@ } else if ((x >= DUK_ASC_0 && x <= DUK_ASC_9) || (x == DUK_ASC_MINUS)) { #if defined(DUK_USE_JX) if (js_ctx->flag_ext_custom && x == DUK_ASC_MINUS && duk__json_dec_peek(js_ctx) == DUK_ASC_UC_I) { - duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY); /* "-Infinity", '-' has been eaten */ + duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY); /* "-Infinity", '-' has been eaten */ duk_push_number(thr, -DUK_DOUBLE_INFINITY); } else { #else - { /* unconditional block */ + { /* unconditional block */ #endif /* We already ate 'x', so backup one byte. */ - js_ctx->p--; /* safe */ + js_ctx->p--; /* safe */ duk__json_dec_number(js_ctx); } } else if (x == DUK_ASC_LC_T) { @@ -950,7 +943,7 @@ /* ... val */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -973,7 +966,7 @@ (duk_tval *) duk_get_tval(thr, -1))); duk_dup_top(thr); - duk_get_prop(thr, -3); /* -> ... holder name val */ + duk_get_prop(thr, -3); /* -> ... holder name val */ h = duk_get_hobject(thr, -1); if (h != NULL) { @@ -983,13 +976,17 @@ /* ... holder name val */ DUK_DDD(DUK_DDDPRINT("walk: array, top=%ld, i=%ld, arr_len=%ld, holder=%!T, name=%!T, val=%!T", - (long) duk_get_top(thr), (long) i, (long) arr_len, - (duk_tval *) duk_get_tval(thr, -3), (duk_tval *) duk_get_tval(thr, -2), + (long) duk_get_top(thr), + (long) i, + (long) arr_len, + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_dup_top(thr); - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... holder name val val ToString(i) */ - duk__json_dec_reviver_walk(js_ctx); /* -> ... holder name val new_elem */ + (void) duk_push_uint_to_hstring(thr, + (duk_uint_t) i); /* -> ... holder name val val ToString(i) */ + duk__json_dec_reviver_walk(js_ctx); /* -> ... holder name val new_elem */ if (duk_is_undefined(thr, -1)) { duk_pop(thr); @@ -1007,9 +1004,12 @@ duk_enum(thr, -1, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); while (duk_next(thr, -1 /*enum_index*/, 0 /*get_value*/)) { DUK_DDD(DUK_DDDPRINT("walk: object, top=%ld, holder=%!T, name=%!T, val=%!T, enum=%!iT, obj_key=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -5), - (duk_tval *) duk_get_tval(thr, -4), (duk_tval *) duk_get_tval(thr, -3), - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, -5), + (duk_tval *) duk_get_tval(thr, -4), + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); /* ... holder name val enum obj_key */ duk_dup_m3(thr); @@ -1035,34 +1035,33 @@ duk_put_prop(thr, -4); } } - duk_pop(thr); /* pop enum */ + duk_pop(thr); /* pop enum */ } } /* ... holder name val */ duk_dup(thr, js_ctx->idx_reviver); - duk_insert(thr, -4); /* -> ... reviver holder name val */ - duk_call_method(thr, 2); /* -> ... res */ + duk_insert(thr, -4); /* -> ... reviver holder name val */ + duk_call_method(thr, 2); /* -> ... res */ duk__json_dec_objarr_exit(js_ctx); - DUK_DDD(DUK_DDDPRINT("walk: top=%ld, result=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("walk: top=%ld, result=%!T", (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -1))); } /* * Stringify implementation. */ -#define DUK__EMIT_1(js_ctx,ch) duk__emit_1((js_ctx), (duk_uint_fast8_t) (ch)) -#define DUK__EMIT_2(js_ctx,ch1,ch2) duk__emit_2((js_ctx), (duk_uint_fast8_t) (ch1), (duk_uint_fast8_t) (ch2)) -#define DUK__EMIT_HSTR(js_ctx,h) duk__emit_hstring((js_ctx), (h)) +#define DUK__EMIT_1(js_ctx, ch) duk__emit_1((js_ctx), (duk_uint_fast8_t) (ch)) +#define DUK__EMIT_2(js_ctx, ch1, ch2) duk__emit_2((js_ctx), (duk_uint_fast8_t) (ch1), (duk_uint_fast8_t) (ch2)) +#define DUK__EMIT_HSTR(js_ctx, h) duk__emit_hstring((js_ctx), (h)) #if defined(DUK_USE_FASTINT) || defined(DUK_USE_JX) || defined(DUK_USE_JC) -#define DUK__EMIT_CSTR(js_ctx,p) duk__emit_cstring((js_ctx), (p)) +#define DUK__EMIT_CSTR(js_ctx, p) duk__emit_cstring((js_ctx), (p)) #endif -#define DUK__EMIT_STRIDX(js_ctx,i) duk__emit_stridx((js_ctx), (i)) -#define DUK__UNEMIT_1(js_ctx) duk__unemit_1((js_ctx)) +#define DUK__EMIT_STRIDX(js_ctx, i) duk__emit_stridx((js_ctx), (i)) +#define DUK__UNEMIT_1(js_ctx) duk__unemit_1((js_ctx)) DUK_LOCAL void duk__emit_1(duk_json_enc_ctx *js_ctx, duk_uint_fast8_t ch) { DUK_BW_WRITE_ENSURE_U8(js_ctx->thr, &js_ctx->bw, ch); @@ -1097,10 +1096,8 @@ DUK_BW_ADD_PTR(js_ctx->thr, &js_ctx->bw, -1); } -#define DUK__MKESC(nybbles,esc1,esc2) \ - (((duk_uint_fast32_t) (nybbles)) << 16) | \ - (((duk_uint_fast32_t) (esc1)) << 8) | \ - ((duk_uint_fast32_t) (esc2)) +#define DUK__MKESC(nybbles, esc1, esc2) \ + (((duk_uint_fast32_t) (nybbles)) << 16) | (((duk_uint_fast32_t) (esc1)) << 8) | ((duk_uint_fast32_t) (esc2)) DUK_LOCAL duk_uint8_t *duk__emit_esc_auto_fast(duk_json_enc_ctx *js_ctx, duk_uint_fast32_t cp, duk_uint8_t *q) { duk_uint_fast32_t tmp; @@ -1125,7 +1122,7 @@ } } else #endif - if (DUK_LIKELY(cp < 0x10000UL)) { + if (DUK_LIKELY(cp < 0x10000UL)) { tmp = DUK__MKESC(4, DUK_ASC_BACKSLASH, DUK_ASC_LC_U); } else { #if defined(DUK_USE_JX) @@ -1157,7 +1154,7 @@ } DUK_LOCAL void duk__json_enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k) { - const duk_int8_t *p, *p_start, *p_end; /* Note: intentionally signed. */ + const duk_int8_t *p, *p_start, *p_end; /* Note: intentionally signed. */ duk_size_t k_len; duk_codepoint_t cp; @@ -1198,7 +1195,7 @@ return; } - quote_normally: +quote_normally: duk__json_enc_quote_string(js_ctx, k); } @@ -1211,7 +1208,7 @@ duk_hthread *thr = js_ctx->thr; const duk_uint8_t *p, *p_start, *p_end, *p_now, *p_tmp; duk_uint8_t *q; - duk_ucodepoint_t cp; /* typed for duk_unicode_decode_xutf8() */ + duk_ucodepoint_t cp; /* typed for duk_unicode_decode_xutf8() */ DUK_DDD(DUK_DDDPRINT("duk__json_enc_quote_string: h_str=%!O", (duk_heaphdr *) h_str)); @@ -1230,8 +1227,7 @@ duk_size_t left, now, space; left = (duk_size_t) (p_end - p); - now = (left > DUK__JSON_ENCSTR_CHUNKSIZE ? - DUK__JSON_ENCSTR_CHUNKSIZE : left); + now = (left > DUK__JSON_ENCSTR_CHUNKSIZE ? DUK__JSON_ENCSTR_CHUNKSIZE : left); /* Maximum expansion per input byte is 6: * - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6). @@ -1267,7 +1263,7 @@ p--; /* slow path is shared */ -#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ cp = *p; if (DUK_LIKELY(cp <= 0x7f)) { @@ -1298,7 +1294,7 @@ } } else { /* slow path is shared */ -#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ /* slow path decode */ @@ -1374,11 +1370,10 @@ /* Negative zero needs special handling in JX/JC because * it would otherwise serialize to '0', not '-0'. */ - if (DUK_UNLIKELY(c == DUK_FP_ZERO && s != 0 && - (js_ctx->flag_ext_custom_or_compatible))) { - duk_push_hstring_stridx(thr, DUK_STRIDX_MINUS_ZERO); /* '-0' */ + if (DUK_UNLIKELY(c == DUK_FP_ZERO && s != 0 && (js_ctx->flag_ext_custom_or_compatible))) { + duk_push_hstring_stridx(thr, DUK_STRIDX_MINUS_ZERO); /* '-0' */ } else -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ { n2s_flags = 0; /* ... number -> ... string */ @@ -1390,8 +1385,7 @@ } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (!(js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE))) { + if (!(js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE))) { stridx = DUK_STRIDX_LC_NULL; } else if (c == DUK_FP_NAN) { stridx = js_ctx->stridx_custom_nan; @@ -1490,7 +1484,7 @@ return q; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ DUK_LOCAL duk_uint8_t *duk__json_enc_buffer_data_hex(const duk_uint8_t *src, duk_size_t src_len, duk_uint8_t *dst) { const duk_uint8_t *p; const duk_uint8_t *p_end; @@ -1508,7 +1502,7 @@ return q; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ DUK_LOCAL void duk__json_enc_buffer_data(duk_json_enc_ctx *js_ctx, duk_uint8_t *buf_data, duk_size_t buf_len) { duk_hthread *thr; @@ -1517,7 +1511,7 @@ thr = js_ctx->thr; - DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ + DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ DUK_ASSERT(js_ctx->flag_ext_custom_or_compatible); /* Buffer values are encoded in (lowercase) hex to make the @@ -1533,7 +1527,7 @@ /* Note: space must cater for both JX and JC. */ space = 9 + buf_len * 2 + 2; DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7ffffffeUL); - DUK_ASSERT((space - 2) / 2 >= buf_len); /* overflow not possible, buffer limits */ + DUK_ASSERT((space - 2) / 2 >= buf_len); /* overflow not possible, buffer limits */ q = DUK_BW_ENSURE_GETPTR(thr, &js_ctx->bw, space); #if defined(DUK_USE_JX) && defined(DUK_USE_JC) @@ -1553,7 +1547,7 @@ #if defined(DUK_USE_JC) { DUK_ASSERT(js_ctx->flag_ext_compatible); - duk_memcpy((void *) q, (const void *) "{\"_buf\":\"", 9); /* len: 9 */ + duk_memcpy((void *) q, (const void *) "{\"_buf\":\"", 9); /* len: 9 */ q += 9; q = duk__json_enc_buffer_data_hex(buf_data, buf_len, q); *q++ = DUK_ASC_DOUBLEQUOTE; @@ -1566,10 +1560,10 @@ DUK_LOCAL void duk__json_enc_buffer_jx_jc(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) { duk__json_enc_buffer_data(js_ctx, - (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h), - (duk_size_t) DUK_HBUFFER_GET_SIZE(h)); + (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h), + (duk_size_t) DUK_HBUFFER_GET_SIZE(h)); } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) DUK_LOCAL void duk__json_enc_buffer_json_fastpath(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) { @@ -1609,21 +1603,21 @@ } DUK_BW_SET_PTR(js_ctx->thr, &js_ctx->bw, q); } - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth); } DUK__EMIT_1(js_ctx, DUK_ASC_RCURLY); } -#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ +#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) DUK_LOCAL void duk__json_enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr) { - char buf64; /* XXX: how to figure correct size? */ + char buf64; /* XXX: how to figure correct size? */ const char *fmt; - DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ + DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ DUK_ASSERT(js_ctx->flag_ext_custom_or_compatible); duk_memzero(buf, sizeof(buf)); @@ -1650,10 +1644,10 @@ #endif /* When ptr == NULL, the format argument is unused. */ - DUK_SNPRINTF(buf, sizeof(buf) - 1, fmt, ptr); /* must not truncate */ + DUK_SNPRINTF(buf, sizeof(buf) - 1, fmt, ptr); /* must not truncate */ DUK__EMIT_CSTR(js_ctx, buf); } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) #if defined(DUK_USE_JX) || defined(DUK_USE_JC) @@ -1665,12 +1659,12 @@ } else { /* Handle both full and partial slice (as long as covered). */ duk__json_enc_buffer_data(js_ctx, - (duk_uint8_t *) DUK_HBUFOBJ_GET_SLICE_BASE(js_ctx->thr->heap, h_bufobj), - (duk_size_t) h_bufobj->length); + (duk_uint8_t *) DUK_HBUFOBJ_GET_SLICE_BASE(js_ctx->thr->heap, h_bufobj), + (duk_size_t) h_bufobj->length); } } -#endif /* DUK_USE_JX || DUK_USE_JC */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Indent helper. Calling code relies on js_ctx->recursion_depth also being * directly related to indent depth. @@ -1678,24 +1672,24 @@ #if defined(DUK_USE_PREFER_SIZE) DUK_LOCAL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) { DUK_ASSERT(js_ctx->h_gap != NULL); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ DUK__EMIT_1(js_ctx, 0x0a); while (depth-- > 0) { DUK__EMIT_HSTR(js_ctx, js_ctx->h_gap); } } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_LOCAL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) { const duk_uint8_t *gap_data; duk_size_t gap_len; - duk_size_t avail_bytes; /* bytes of indent available for copying */ - duk_size_t need_bytes; /* bytes of indent still needed */ + duk_size_t avail_bytes; /* bytes of indent available for copying */ + duk_size_t need_bytes; /* bytes of indent still needed */ duk_uint8_t *p_start; duk_uint8_t *p; DUK_ASSERT(js_ctx->h_gap != NULL); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ DUK__EMIT_1(js_ctx, 0x0a); if (DUK_UNLIKELY(depth == 0)) { @@ -1729,14 +1723,14 @@ avail_bytes <<= 1; } - DUK_ASSERT(need_bytes < avail_bytes); /* need_bytes may be zero */ + DUK_ASSERT(need_bytes < avail_bytes); /* need_bytes may be zero */ duk_memcpy((void *) p, (const void *) p_start, (size_t) need_bytes); p += need_bytes; /*avail_bytes += need_bytes*/ DUK_BW_SET_PTR(js_ctx->thr, &js_ctx->bw, p); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Shared entry handling for object/array serialization. */ DUK_LOCAL void duk__json_enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top) { @@ -1753,7 +1747,7 @@ * with overflow in a loop check object. */ - h_target = duk_known_hobject(thr, -1); /* object or array */ + h_target = duk_known_hobject(thr, -1); /* object or array */ n = js_ctx->recursion_depth; if (DUK_UNLIKELY(n > DUK_JSON_ENC_LOOPARRAY)) { @@ -1770,18 +1764,18 @@ js_ctx->visitingjs_ctx->recursion_depth = h_target; } else { duk_push_sprintf(thr, DUK_STR_FMT_PTR, (void *) h_target); - duk_dup_top(thr); /* -> ... voidp voidp */ + duk_dup_top(thr); /* -> ... voidp voidp */ if (duk_has_prop(thr, js_ctx->idx_loop)) { DUK_ERROR_TYPE(thr, DUK_STR_CYCLIC_INPUT); DUK_WO_NORETURN(return;); } - duk_push_true(thr); /* -> ... voidp true */ - duk_put_prop(thr, js_ctx->idx_loop); /* -> ... */ + duk_push_true(thr); /* -> ... voidp true */ + duk_put_prop(thr, js_ctx->idx_loop); /* -> ... */ } /* C recursion check. */ - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_ERROR_RANGE(thr, DUK_STR_ENC_RECLIMIT); @@ -1790,7 +1784,8 @@ js_ctx->recursion_depth++; DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%ld, loop=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); } /* Shared exit handling for object/array serialization. */ @@ -1806,20 +1801,21 @@ /* Loop check. */ - h_target = duk_known_hobject(thr, *entry_top - 1); /* original target at entry_top - 1 */ + h_target = duk_known_hobject(thr, *entry_top - 1); /* original target at entry_top - 1 */ if (js_ctx->recursion_depth < DUK_JSON_ENC_LOOPARRAY) { /* Previous entry was inside visited, nothing to do. */ } else { duk_push_sprintf(thr, DUK_STR_FMT_PTR, (void *) h_target); - duk_del_prop(thr, js_ctx->idx_loop); /* -> ... */ + duk_del_prop(thr, js_ctx->idx_loop); /* -> ... */ } /* Restore stack top after unbalanced code paths. */ duk_set_top(thr, *entry_top); DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%ld, loop=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); } /* The JO(value) operation: encode object. @@ -1847,13 +1843,14 @@ } else { /* XXX: would be nice to enumerate an object at specified index */ duk_dup(thr, idx_obj); - (void) duk_hobject_get_enumerated_keys(thr, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); /* ... target -> ... target keys */ + (void) duk_hobject_get_enumerated_keys( + thr, + DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); /* ... target -> ... target keys */ idx_keys = duk_require_normalize_index(thr, -1); /* leave stack unbalanced on purpose */ } - DUK_DDD(DUK_DDDPRINT("idx_keys=%ld, h_keys=%!T", - (long) idx_keys, (duk_tval *) duk_get_tval(thr, idx_keys))); + DUK_DDD(DUK_DDDPRINT("idx_keys=%ld, h_keys=%!T", (long) idx_keys, (duk_tval *) duk_get_tval(thr, idx_keys))); /* Steps 8-10 have been merged to avoid a "partial" variable. */ @@ -1868,7 +1865,7 @@ arr_len = (duk_uarridx_t) duk_get_length(thr, idx_keys); emitted = 0; for (i = 0; i < arr_len; i++) { - duk_get_prop_index(thr, idx_keys, i); /* -> ... key */ + duk_get_prop_index(thr, idx_keys, i); /* -> ... key */ DUK_DDD(DUK_DDDPRINT("object property loop: holder=%!T, key=%!T", (duk_tval *) duk_get_tval(thr, idx_obj), @@ -1876,7 +1873,7 @@ h_key = duk_known_hstring(thr, -1); DUK_ASSERT(h_key != NULL); - DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(h_key)); /* proplist filtering; enum options */ + DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(h_key)); /* proplist filtering; enum options */ prev_size = DUK_BW_GET_SIZE(js_ctx->thr, &js_ctx->bw); if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { @@ -1905,7 +1902,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -1929,8 +1926,7 @@ duk_bool_t emitted; duk_uarridx_t i, arr_len; - DUK_DDD(DUK_DDDPRINT("duk__json_enc_array: array=%!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("duk__json_enc_array: array=%!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_enc_objarr_entry(js_ctx, &entry_top); @@ -1945,14 +1941,15 @@ for (i = 0; i < arr_len; i++) { DUK_DDD(DUK_DDDPRINT("array entry loop: array=%!T, index=%ld, arr_len=%ld", (duk_tval *) duk_get_tval(thr, idx_arr), - (long) i, (long) arr_len)); + (long) i, + (long) arr_len)); if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth); } - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... key */ + (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... key */ /* ... key */ @@ -1971,7 +1968,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -1996,14 +1993,15 @@ duk_small_int_t c; DUK_DDD(DUK_DDDPRINT("duk__json_enc_value: idx_holder=%ld, holder=%!T, key=%!T", - (long) idx_holder, (duk_tval *) duk_get_tval(thr, idx_holder), + (long) idx_holder, + (duk_tval *) duk_get_tval(thr, idx_holder), (duk_tval *) duk_get_tval(thr, -1))); tv_holder = DUK_GET_TVAL_POSIDX(thr, idx_holder); DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv_holder)); tv_key = DUK_GET_TVAL_NEGIDX(thr, -1); DUK_ASSERT(DUK_TVAL_IS_STRING(tv_key)); - DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING(tv_key))); /* Caller responsible. */ + DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING(tv_key))); /* Caller responsible. */ (void) duk_hobject_getprop(thr, tv_holder, tv_key); /* -> ... key val */ @@ -2015,19 +2013,17 @@ * number won't invoke the .toJSON() method. However, lightfuncs and * plain buffers mimic objects so we check for their .toJSON() method. */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_JSON); - if (duk_is_callable(thr, -1)) { /* toJSON() can also be a lightfunc */ + if (duk_is_callable(thr, -1)) { /* toJSON() can also be a lightfunc */ DUK_DDD(DUK_DDDPRINT("value is object, has callable toJSON() -> call it")); /* XXX: duk_dup_unvalidated(thr, -2) etc. */ - duk_dup_m2(thr); /* -> ... key val toJSON val */ - duk_dup_m4(thr); /* -> ... key val toJSON val key */ - duk_call_method(thr, 1); /* -> ... key val val' */ - duk_remove_m2(thr); /* -> ... key val' */ + duk_dup_m2(thr); /* -> ... key val toJSON val */ + duk_dup_m4(thr); /* -> ... key val toJSON val key */ + duk_call_method(thr, 1); /* -> ... key val val' */ + duk_remove_m2(thr); /* -> ... key val' */ } else { - duk_pop(thr); /* -> ... key val */ + duk_pop(thr); /* -> ... key val */ } } @@ -2038,12 +2034,12 @@ if (js_ctx->h_replacer) { /* XXX: Here a "slice copy" would be useful. */ DUK_DDD(DUK_DDDPRINT("replacer is set, call replacer")); - duk_push_hobject(thr, js_ctx->h_replacer); /* -> ... key val replacer */ - duk_dup(thr, idx_holder); /* -> ... key val replacer holder */ - duk_dup_m4(thr); /* -> ... key val replacer holder key */ - duk_dup_m4(thr); /* -> ... key val replacer holder key val */ - duk_call_method(thr, 2); /* -> ... key val val' */ - duk_remove_m2(thr); /* -> ... key val' */ + duk_push_hobject(thr, js_ctx->h_replacer); /* -> ... key val replacer */ + duk_dup(thr, idx_holder); /* -> ... key val replacer holder */ + duk_dup_m4(thr); /* -> ... key val replacer holder key */ + duk_dup_m4(thr); /* -> ... key val replacer holder key val */ + duk_call_method(thr, 2); /* -> ... key val val' */ + duk_remove_m2(thr); /* -> ... key val' */ } /* ... key val */ @@ -2059,8 +2055,7 @@ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (DUK_HOBJECT_IS_BUFOBJ(h) && - js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { + if (DUK_HOBJECT_IS_BUFOBJ(h) && js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { /* With JX/JC a bufferobject gets serialized specially. */ duk_hbufobj *h_bufobj; h_bufobj = (duk_hbufobj *) h; @@ -2069,8 +2064,8 @@ goto pop2_emitted; } /* Otherwise bufferobjects get serialized as normal objects. */ -#endif /* JX || JC */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* JX || JC */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ c = (duk_small_int_t) DUK_HOBJECT_GET_CLASS_NUMBER(h); switch (c) { case DUK_HOBJECT_CLASS_NUMBER: { @@ -2110,8 +2105,7 @@ DUK_ASSERT(h != NULL); if (DUK_HOBJECT_IS_CALLABLE(h)) { #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE)) { + if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { /* We only get here when doing non-standard JSON encoding */ DUK_DDD(DUK_DDDPRINT("-> function allowed, serialize to custom format")); DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); @@ -2121,13 +2115,13 @@ DUK_DDD(DUK_DDDPRINT("-> will result in undefined (function)")); goto pop2_undef; } -#else /* DUK_USE_JX || DUK_USE_JC */ +#else /* DUK_USE_JX || DUK_USE_JC */ DUK_DDD(DUK_DDDPRINT("-> will result in undefined (function)")); goto pop2_undef; -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ } } - } /* end switch */ + } /* end switch */ } /* ... key val */ @@ -2154,8 +2148,7 @@ break; } case DUK_TAG_BOOLEAN: { - DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? - DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); + DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); break; } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) @@ -2164,7 +2157,7 @@ duk__json_enc_pointer(js_ctx, DUK_TVAL_GET_POINTER(tv)); break; } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ case DUK_TAG_STRING: { duk_hstring *h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); @@ -2243,14 +2236,14 @@ } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - pop2_emitted: +pop2_emitted: #endif duk_pop_2(thr); /* ... key val -> ... */ - return 1; /* emitted */ + return 1; /* emitted */ - pop2_undef: - duk_pop_2(thr); /* ... key val -> ... */ - return 0; /* not emitted */ +pop2_undef: + duk_pop_2(thr); /* ... key val -> ... */ + return 0; /* not emitted */ } /* E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4. */ @@ -2326,8 +2319,7 @@ break; } case DUK_TAG_BOOLEAN: { - DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? - DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); + DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); break; } case DUK_TAG_STRING: { @@ -2344,8 +2336,7 @@ duk_hobject *obj; duk_tval *tv_val; duk_bool_t emitted = 0; - duk_uint32_t c_bit, c_all, c_array, c_unbox, c_undef, - c_func, c_bufobj, c_object, c_abort; + duk_uint32_t c_bit, c_all, c_array, c_unbox, c_undef, c_func, c_bufobj, c_object, c_abort; /* For objects JSON.stringify() only looks for own, enumerable * properties which is nice for the fast path here. @@ -2378,7 +2369,7 @@ * it (though it's OK to abort the fast path). */ - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_DD(DUK_DDPRINT("fast path recursion limit")); @@ -2430,28 +2421,23 @@ if (js_ctx->flag_ext_custom_or_compatible) { c_all = DUK_HOBJECT_CMASK_ALL; c_array = DUK_HOBJECT_CMASK_ARRAY; - c_unbox = DUK_HOBJECT_CMASK_NUMBER | - DUK_HOBJECT_CMASK_STRING | - DUK_HOBJECT_CMASK_BOOLEAN | - DUK_HOBJECT_CMASK_POINTER; /* Symbols are not unboxed. */ + c_unbox = DUK_HOBJECT_CMASK_NUMBER | DUK_HOBJECT_CMASK_STRING | DUK_HOBJECT_CMASK_BOOLEAN | + DUK_HOBJECT_CMASK_POINTER; /* Symbols are not unboxed. */ c_func = DUK_HOBJECT_CMASK_FUNCTION; c_bufobj = DUK_HOBJECT_CMASK_ALL_BUFOBJS; c_undef = 0; c_abort = 0; c_object = c_all & ~(c_array | c_unbox | c_func | c_bufobj | c_undef | c_abort); - } - else + } else #endif { c_all = DUK_HOBJECT_CMASK_ALL; c_array = DUK_HOBJECT_CMASK_ARRAY; - c_unbox = DUK_HOBJECT_CMASK_NUMBER | - DUK_HOBJECT_CMASK_STRING | - DUK_HOBJECT_CMASK_BOOLEAN; /* Symbols are not unboxed. */ + c_unbox = DUK_HOBJECT_CMASK_NUMBER | DUK_HOBJECT_CMASK_STRING | + DUK_HOBJECT_CMASK_BOOLEAN; /* Symbols are not unboxed. */ c_func = 0; c_bufobj = 0; - c_undef = DUK_HOBJECT_CMASK_FUNCTION | - DUK_HOBJECT_CMASK_POINTER; + c_undef = DUK_HOBJECT_CMASK_FUNCTION | DUK_HOBJECT_CMASK_POINTER; /* As the fast path doesn't currently properly support * duk_hbufobj virtual properties, abort fast path if * we encounter them in plain JSON mode. @@ -2533,7 +2519,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -2603,14 +2589,14 @@ #endif /* fall through */ - elem_done: + elem_done: DUK__EMIT_1(js_ctx, DUK_ASC_COMMA); emitted = 1; } if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -2622,7 +2608,7 @@ * automatic unboxing. Rely on internal value being * sane (to avoid infinite recursion). */ - DUK_ASSERT((c_bit & DUK_HOBJECT_CMASK_SYMBOL) == 0); /* Symbols are not unboxed. */ + DUK_ASSERT((c_bit & DUK_HOBJECT_CMASK_SYMBOL) == 0); /* Symbols are not unboxed. */ #if 1 /* The code below is incorrect if .toString() or .valueOf() have @@ -2632,7 +2618,7 @@ * Unimplemented for now, abort fast path for boxed values. */ goto abort_fastpath; -#else /* disabled */ +#else /* disabled */ /* Disabled until fixed, see above. */ duk_tval *tv_internal; @@ -2640,16 +2626,14 @@ tv_internal = duk_hobject_get_internal_value_tval_ptr(js_ctx->thr->heap, obj); DUK_ASSERT(tv_internal != NULL); - DUK_ASSERT(DUK_TVAL_IS_STRING(tv_internal) || - DUK_TVAL_IS_NUMBER(tv_internal) || - DUK_TVAL_IS_BOOLEAN(tv_internal) || - DUK_TVAL_IS_POINTER(tv_internal)); + DUK_ASSERT(DUK_TVAL_IS_STRING(tv_internal) || DUK_TVAL_IS_NUMBER(tv_internal) || + DUK_TVAL_IS_BOOLEAN(tv_internal) || DUK_TVAL_IS_POINTER(tv_internal)); tv = tv_internal; DUK_ASSERT(js_ctx->recursion_depth > 0); - js_ctx->recursion_depth--; /* required to keep recursion depth correct */ + js_ctx->recursion_depth--; /* required to keep recursion depth correct */ goto restart_match; -#endif /* disabled */ +#endif /* disabled */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) } else if (c_bit & c_func) { DUK__EMIT_STRIDX(js_ctx, js_ctx->stridx_custom_function); @@ -2762,12 +2746,12 @@ #endif } } - return 1; /* not undefined */ + return 1; /* not undefined */ - emit_undefined: - return 0; /* value was undefined/unsupported */ +emit_undefined: + return 0; /* value was undefined/unsupported */ - abort_fastpath: +abort_fastpath: /* Error message doesn't matter: the error is ignored anyway. */ DUK_DD(DUK_DDPRINT("aborting fast path")); DUK_ERROR_INTERNAL(js_ctx->thr); @@ -2787,22 +2771,19 @@ tv = DUK_GET_TVAL_NEGIDX(thr, -1); if (duk__json_stringify_fast_value(js_ctx, tv) == 0) { DUK_DD(DUK_DDPRINT("top level value not supported, fail fast path")); - DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* Error message is ignored, so doesn't matter. */ + DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* Error message is ignored, so doesn't matter. */ } return 0; } -#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ +#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ /* * Top level wrappers */ DUK_INTERNAL -void duk_bi_json_parse_helper(duk_hthread *thr, - duk_idx_t idx_value, - duk_idx_t idx_reviver, - duk_small_uint_t flags) { +void duk_bi_json_parse_helper(duk_hthread *thr, duk_idx_t idx_value, duk_idx_t idx_reviver, duk_small_uint_t flags) { duk_json_dec_ctx js_ctx_alloc; duk_json_dec_ctx *js_ctx = &js_ctx_alloc; duk_hstring *h_text; @@ -2843,7 +2824,7 @@ js_ctx->flag_ext_custom_or_compatible = flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE); #endif - h_text = duk_to_hstring(thr, idx_value); /* coerce in-place; rejects Symbols */ + h_text = duk_to_hstring(thr, idx_value); /* coerce in-place; rejects Symbols */ DUK_ASSERT(h_text != NULL); /* JSON parsing code is allowed to read p_start,p_end: p_end is @@ -2852,11 +2833,10 @@ */ js_ctx->p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text); js_ctx->p = js_ctx->p_start; - js_ctx->p_end = ((const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text)) + - DUK_HSTRING_GET_BYTELEN(h_text); + js_ctx->p_end = ((const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text)) + DUK_HSTRING_GET_BYTELEN(h_text); DUK_ASSERT(*(js_ctx->p_end) == 0x00); - duk__json_dec_value(js_ctx); /* -> ... value */ + duk__json_dec_value(js_ctx); /* -> ... value */ DUK_ASSERT(js_ctx->recursion_depth == 0); /* Trailing whitespace has been eaten by duk__json_dec_value(), so if @@ -2868,27 +2848,26 @@ } if (duk_is_callable(thr, idx_reviver)) { - DUK_DDD(DUK_DDDPRINT("applying reviver: %!T", - (duk_tval *) duk_get_tval(thr, idx_reviver))); + DUK_DDD(DUK_DDDPRINT("applying reviver: %!T", (duk_tval *) duk_get_tval(thr, idx_reviver))); js_ctx->idx_reviver = idx_reviver; duk_push_object(thr); - duk_dup_m2(thr); /* -> ... val root val */ - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_EMPTY_STRING); /* default attrs ok */ - duk_push_hstring_stridx(thr, DUK_STRIDX_EMPTY_STRING); /* -> ... val root "" */ + duk_dup_m2(thr); /* -> ... val root val */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_EMPTY_STRING); /* default attrs ok */ + duk_push_hstring_stridx(thr, DUK_STRIDX_EMPTY_STRING); /* -> ... val root "" */ DUK_DDD(DUK_DDDPRINT("start reviver walk, root=%!T, name=%!T", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(js_ctx->recursion_depth == 0); - duk__json_dec_reviver_walk(js_ctx); /* ... val root "" -> ... val val' */ + duk__json_dec_reviver_walk(js_ctx); /* ... val root "" -> ... val val' */ DUK_ASSERT(js_ctx->recursion_depth == 0); - duk_remove_m2(thr); /* -> ... val' */ + duk_remove_m2(thr); /* -> ... val' */ } else { - DUK_DDD(DUK_DDDPRINT("reviver does not exist or is not callable: %!T", - (duk_tval *) duk_get_tval(thr, idx_reviver))); + DUK_DDD( + DUK_DDDPRINT("reviver does not exist or is not callable: %!T", (duk_tval *) duk_get_tval(thr, idx_reviver))); } /* Final result is at stack top. */ @@ -2962,7 +2941,7 @@ * combinations properly. */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_NULL; /* standard JSON; array gaps */ + js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_NULL; /* standard JSON; array gaps */ #if defined(DUK_USE_JX) if (flags & DUK_JSON_FLAG_EXT_CUSTOM) { js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_UNDEFINED; @@ -2970,41 +2949,35 @@ js_ctx->stridx_custom_neginf = DUK_STRIDX_MINUS_INFINITY; js_ctx->stridx_custom_posinf = DUK_STRIDX_INFINITY; js_ctx->stridx_custom_function = - (flags & DUK_JSON_FLAG_AVOID_KEY_QUOTES) ? - DUK_STRIDX_JSON_EXT_FUNCTION2 : - DUK_STRIDX_JSON_EXT_FUNCTION1; + (flags & DUK_JSON_FLAG_AVOID_KEY_QUOTES) ? DUK_STRIDX_JSON_EXT_FUNCTION2 : DUK_STRIDX_JSON_EXT_FUNCTION1; } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) && defined(DUK_USE_JC) else -#endif /* DUK_USE_JX && DUK_USE_JC */ +#endif /* DUK_USE_JX && DUK_USE_JC */ #if defined(DUK_USE_JC) - if (js_ctx->flags & DUK_JSON_FLAG_EXT_COMPATIBLE) { + if (js_ctx->flags & DUK_JSON_FLAG_EXT_COMPATIBLE) { js_ctx->stridx_custom_undefined = DUK_STRIDX_JSON_EXT_UNDEFINED; js_ctx->stridx_custom_nan = DUK_STRIDX_JSON_EXT_NAN; js_ctx->stridx_custom_neginf = DUK_STRIDX_JSON_EXT_NEGINF; js_ctx->stridx_custom_posinf = DUK_STRIDX_JSON_EXT_POSINF; js_ctx->stridx_custom_function = DUK_STRIDX_JSON_EXT_FUNCTION1; } -#endif /* DUK_USE_JC */ -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE)) { - DUK_ASSERT(js_ctx->mask_for_undefined == 0); /* already zero */ - } - else -#endif /* DUK_USE_JX || DUK_USE_JC */ + if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { + DUK_ASSERT(js_ctx->mask_for_undefined == 0); /* already zero */ + } else +#endif /* DUK_USE_JX || DUK_USE_JC */ { /* Plain buffer is treated like ArrayBuffer and serialized. * Lightfuncs are treated like objects, but JSON explicitly * skips serializing Function objects so we can just reject * lightfuncs here. */ - js_ctx->mask_for_undefined = DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_POINTER | - DUK_TYPE_MASK_LIGHTFUNC; + js_ctx->mask_for_undefined = DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_POINTER | DUK_TYPE_MASK_LIGHTFUNC; } DUK_BW_INIT_PUSHBUF(thr, &js_ctx->bw, DUK__JSON_STRINGIFY_BUFSIZE); @@ -3034,8 +3007,7 @@ js_ctx->idx_proplist = duk_push_bare_array(thr); - enum_flags = DUK_ENUM_ARRAY_INDICES_ONLY | - DUK_ENUM_SORT_ARRAY_INDICES; /* expensive flag */ + enum_flags = DUK_ENUM_ARRAY_INDICES_ONLY | DUK_ENUM_SORT_ARRAY_INDICES; /* expensive flag */ duk_enum(thr, idx_replacer, enum_flags); while (duk_next(thr, -1 /*enum_index*/, 1 /*get_value*/)) { /* ... proplist enum_obj key val */ @@ -3044,8 +3016,8 @@ DUK_DDD(DUK_DDDPRINT("proplist enum: key=%!T, val=%!T --> accept", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); - duk_to_string(thr, -1); /* extra coercion of strings is OK */ - duk_put_prop_index(thr, -4, plist_idx); /* -> ... proplist enum_obj key */ + duk_to_string(thr, -1); /* extra coercion of strings is OK */ + duk_put_prop_index(thr, -4, plist_idx); /* -> ... proplist enum_obj key */ plist_idx++; duk_pop(thr); } else { @@ -3054,8 +3026,8 @@ (duk_tval *) duk_get_tval(thr, -1))); duk_pop_2(thr); } - } - duk_pop(thr); /* pop enum */ + } + duk_pop(thr); /* pop enum */ /* ... proplist */ } @@ -3081,10 +3053,9 @@ duk_small_int_t nspace; /* spaces must be static to allow initializer with old compilers like BCC */ static const char spaces10 = { - DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, - DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, - DUK_ASC_SPACE, DUK_ASC_SPACE - }; /* XXX: helper */ + DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, + DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE + }; /* XXX: helper */ /* ToInteger() coercion; NaN -> 0, infinities are clamped to 0 and 10 */ nspace = (duk_small_int_t) duk_to_int_clamped(thr, idx_space, 0 /*minval*/, 10 /*maxval*/); @@ -3095,7 +3066,7 @@ DUK_ASSERT(js_ctx->h_gap != NULL); } else if (duk_is_string_notsymbol(thr, idx_space)) { duk_dup(thr, idx_space); - duk_substring(thr, -1, 0, 10); /* clamp to 10 chars */ + duk_substring(thr, -1, 0, 10); /* clamp to 10 chars */ js_ctx->h_gap = duk_known_hstring(thr, -1); } else { /* nop */ @@ -3119,8 +3090,8 @@ */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) - if (js_ctx->h_replacer == NULL && /* replacer is a mutation risk */ - js_ctx->idx_proplist == -1) { /* proplist is very rare */ + if (js_ctx->h_replacer == NULL && /* replacer is a mutation risk */ + js_ctx->idx_proplist == -1) { /* proplist is very rare */ duk_int_t pcall_rc; duk_small_uint_t prev_ms_base_flags; @@ -3145,10 +3116,9 @@ /* Must prevent finalizers which may have arbitrary side effects. */ prev_ms_base_flags = thr->heap->ms_base_flags; - thr->heap->ms_base_flags |= - DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact any objects. */ - thr->heap->pf_prevent_count++; /* Prevent finalizers. */ - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + thr->heap->ms_base_flags |= DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact any objects. */ + thr->heap->pf_prevent_count++; /* Prevent finalizers. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ pcall_rc = duk_safe_call(thr, duk__json_stringify_fast, (void *) js_ctx /*udata*/, 1 /*nargs*/, 0 /*nret*/); @@ -3199,7 +3169,7 @@ js_ctx->recursion_limit = DUK_USE_JSON_ENC_RECLIMIT; DUK_ASSERT(js_ctx->recursion_depth == 0); - if (DUK_UNLIKELY(duk__json_enc_value(js_ctx, idx_holder) == 0)) { /* ... holder key -> ... holder */ + if (DUK_UNLIKELY(duk__json_enc_value(js_ctx, idx_holder) == 0)) { /* ... holder key -> ... holder */ /* Result is undefined. */ duk_push_undefined(thr); } else { @@ -3221,7 +3191,7 @@ */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) - replace_finished: +replace_finished: #endif duk_replace(thr, entry_top); duk_set_top(thr, entry_top + 1); @@ -3245,22 +3215,15 @@ */ DUK_INTERNAL duk_ret_t duk_bi_json_object_parse(duk_hthread *thr) { - duk_bi_json_parse_helper(thr, - 0 /*idx_value*/, - 1 /*idx_replacer*/, - 0 /*flags*/); + duk_bi_json_parse_helper(thr, 0 /*idx_value*/, 1 /*idx_replacer*/, 0 /*flags*/); return 1; } DUK_INTERNAL duk_ret_t duk_bi_json_object_stringify(duk_hthread *thr) { - duk_bi_json_stringify_helper(thr, - 0 /*idx_value*/, - 1 /*idx_replacer*/, - 2 /*idx_space*/, - 0 /*flags*/); + duk_bi_json_stringify_helper(thr, 0 /*idx_value*/, 1 /*idx_replacer*/, 2 /*idx_space*/, 0 /*flags*/); return 1; } -#endif /* DUK_USE_JSON_BUILTIN */ +#endif /* DUK_USE_JSON_BUILTIN */ -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_math.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_math.c
Changed
@@ -141,7 +141,7 @@ return x >= 0.0 ? DUK_FLOOR(x) : DUK_CEIL(x); #endif } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ DUK_LOCAL double duk__round_fixed(double x) { /* Numbers half-way between integers must be rounded towards +Infinity, @@ -256,51 +256,23 @@ return DUK_ATAN2(x, y); } -#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ +#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ /* order must match constants in genbuiltins.py */ DUK_LOCAL const duk__one_arg_func duk__one_arg_funcs = { #if defined(DUK_USE_AVOID_PLATFORM_FUNCPTRS) - duk__fabs, - duk__acos, - duk__asin, - duk__atan, - duk__ceil, - duk__cos, - duk__exp, - duk__floor, - duk__log, - duk__round_fixed, - duk__sin, - duk__sqrt, - duk__tan, + duk__fabs, duk__acos, duk__asin, duk__atan, duk__ceil, duk__cos, duk__exp, + duk__floor, duk__log, duk__round_fixed, duk__sin, duk__sqrt, duk__tan, #if defined(DUK_USE_ES6) - duk__cbrt, - duk__log2, - duk__log10, - duk__trunc + duk__cbrt, duk__log2, duk__log10, duk__trunc #endif -#else /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ - DUK_FABS, - DUK_ACOS, - DUK_ASIN, - DUK_ATAN, - DUK_CEIL, - DUK_COS, - DUK_EXP, - DUK_FLOOR, - DUK_LOG, - duk__round_fixed, - DUK_SIN, - DUK_SQRT, - DUK_TAN, +#else /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ + DUK_FABS, DUK_ACOS, DUK_ASIN, DUK_ATAN, DUK_CEIL, DUK_COS, DUK_EXP, + DUK_FLOOR, DUK_LOG, duk__round_fixed, DUK_SIN, DUK_SQRT, DUK_TAN, #if defined(DUK_USE_ES6) - duk__cbrt, - duk__log2, - duk__log10, - duk__trunc + duk__cbrt, duk__log2, duk__log10, duk__trunc #endif -#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ +#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ }; /* order must match constants in genbuiltins.py */ @@ -335,7 +307,7 @@ DUK_ASSERT(fun_idx >= 0); DUK_ASSERT(fun_idx < (duk_small_int_t) (sizeof(duk__two_arg_funcs) / sizeof(duk__two_arg_func))); - arg1 = duk_to_number(thr, 0); /* explicit ordered evaluation to match coercion semantics */ + arg1 = duk_to_number(thr, 0); /* explicit ordered evaluation to match coercion semantics */ arg2 = duk_to_number(thr, 1); fun = duk__two_arg_funcsfun_idx; duk_push_number(thr, (duk_double_t) fun((double) arg1, (double) arg2)); @@ -351,7 +323,7 @@ } DUK_INTERNAL duk_ret_t duk_bi_math_object_random(duk_hthread *thr) { - duk_push_number(thr, (duk_double_t) DUK_UTIL_GET_RANDOM_DOUBLE(thr)); + duk_push_number(thr, (duk_double_t) duk_util_get_random_double(thr)); return 1; } @@ -421,7 +393,7 @@ duk_push_number(thr, (duk_double_t) DUK_SQRT(sum) * max); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_sign(duk_hthread *thr) { @@ -430,7 +402,7 @@ d = duk_to_number(thr, 0); if (duk_double_is_nan(d)) { DUK_ASSERT(duk_is_nan(thr, -1)); - return 1; /* NaN input -> return NaN */ + return 1; /* NaN input -> return NaN */ } if (duk_double_equals(d, 0.0)) { /* Zero sign kept, i.e. -0 -> -0, +0 -> +0. */ @@ -439,7 +411,7 @@ duk_push_int(thr, (d > 0.0 ? 1 : -1)); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_clz32(duk_hthread *thr) { @@ -459,7 +431,7 @@ DUK_ASSERT(i <= 32); duk_push_uint(thr, i); return 1; -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ i = 0; x = duk_to_uint32(thr, 0); if (x & 0xffff0000UL) { @@ -495,9 +467,9 @@ DUK_ASSERT(i <= 32); duk_push_uint(thr, i); return 1; -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_imul(duk_hthread *thr) { @@ -514,6 +486,6 @@ duk_push_i32(thr, (duk_int32_t) z); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_MATH_BUILTIN */ +#endif /* DUK_USE_MATH_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_number.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_number.c
Changed
@@ -19,8 +19,7 @@ goto done; } h = duk_get_hobject(thr, -1); - if (!h || - (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_NUMBER)) { + if (!h || (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_NUMBER)) { DUK_DDD(DUK_DDDPRINT("unacceptable this value: %!T", (duk_tval *) duk_get_tval(thr, -1))); DUK_ERROR_TYPE(thr, "number expected"); DUK_WO_NORETURN(return 0.0;); @@ -28,10 +27,11 @@ duk_xget_owndataprop_stridx_short(thr, -1, DUK_STRIDX_INT_VALUE); DUK_ASSERT(duk_is_number(thr, -1)); DUK_DDD(DUK_DDDPRINT("number object: %!T, internal value: %!T", - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); duk_remove_m2(thr); - done: +done: return duk_get_number(thr, -1); } @@ -80,9 +80,9 @@ DUK_ASSERT(DUK_HOBJECT_GET_CLASS_NUMBER(h_this) == DUK_HOBJECT_CLASS_NUMBER); DUK_ASSERT(DUK_HOBJECT_HAS_EXTENSIBLE(h_this)); - duk_dup_0(thr); /* -> val obj val */ + duk_dup_0(thr); /* -> val obj val */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); - return 0; /* no return value -> don't replace created value */ + return 0; /* no return value -> don't replace created value */ } DUK_INTERNAL duk_ret_t duk_bi_number_prototype_value_of(duk_hthread *thr) { @@ -104,10 +104,7 @@ n2s_flags = 0; - duk_numconv_stringify(thr, - radix /*radix*/, - 0 /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, radix /*radix*/, 0 /*digits*/, n2s_flags /*flags*/); return 1; } @@ -145,16 +142,12 @@ goto use_to_string; } - n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | - DUK_N2S_FLAG_FRACTION_DIGITS; + n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | DUK_N2S_FLAG_FRACTION_DIGITS; - duk_numconv_stringify(thr, - 10 /*radix*/, - frac_digits /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, frac_digits /*digits*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: DUK_ASSERT_TOP(thr, 2); duk_to_string(thr, -1); return 1; @@ -170,7 +163,7 @@ d = duk__push_this_number_plain(thr); frac_undefined = duk_is_undefined(thr, 0); - duk_to_int(thr, 0); /* for side effects */ + duk_to_int(thr, 0); /* for side effects */ c = (duk_small_int_t) DUK_FPCLASSIFY(d); if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) { @@ -179,16 +172,12 @@ frac_digits = (duk_small_int_t) duk_to_int_check_range(thr, 0, 0, 20); - n2s_flags = DUK_N2S_FLAG_FORCE_EXP | - (frac_undefined ? 0 : DUK_N2S_FLAG_FIXED_FORMAT); + n2s_flags = DUK_N2S_FLAG_FORCE_EXP | (frac_undefined ? 0 : DUK_N2S_FLAG_FIXED_FORMAT); - duk_numconv_stringify(thr, - 10 /*radix*/, - frac_digits + 1 /*leading digit + fractions*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, frac_digits + 1 /*leading digit + fractions*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: DUK_ASSERT_TOP(thr, 2); duk_to_string(thr, -1); return 1; @@ -213,7 +202,7 @@ } DUK_ASSERT_TOP(thr, 2); - duk_to_int(thr, 0); /* for side effects */ + duk_to_int(thr, 0); /* for side effects */ c = (duk_small_int_t) DUK_FPCLASSIFY(d); if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) { @@ -222,16 +211,12 @@ prec = (duk_small_int_t) duk_to_int_check_range(thr, 0, 1, 21); - n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | - DUK_N2S_FLAG_NO_ZERO_PAD; + n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | DUK_N2S_FLAG_NO_ZERO_PAD; - duk_numconv_stringify(thr, - 10 /*radix*/, - prec /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, prec /*digits*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: /* Used when precision is undefined; also used for NaN (-> "NaN"), * and +/- infinity (-> "Infinity", "-Infinity"). */ @@ -257,16 +242,16 @@ d = duk_get_number(thr, 0); switch (magic) { - case 0: /* isFinite() */ + case 0: /* isFinite() */ ret = duk_double_is_finite(d); break; - case 1: /* isInteger() */ + case 1: /* isInteger() */ ret = duk_double_is_integer(d); break; - case 2: /* isNaN() */ + case 2: /* isNaN() */ ret = duk_double_is_nan(d); break; - default: /* isSafeInteger() */ + default: /* isSafeInteger() */ DUK_ASSERT(magic == 3); ret = duk_double_is_safe_integer(d); } @@ -275,6 +260,6 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_NUMBER_BUILTIN */ +#endif /* DUK_USE_NUMBER_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_object.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_object.c
Changed
@@ -19,8 +19,8 @@ arg_mask = duk_get_type_mask(thr, 0); - if (!duk_is_constructor_call(thr) && /* not a constructor call */ - ((arg_mask & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) == 0)) { /* and argument not null or undefined */ + if (!duk_is_constructor_call(thr) && /* not a constructor call */ + ((arg_mask & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) == 0)) { /* and argument not null or undefined */ duk_to_object(thr, 0); return 1; } @@ -30,13 +30,8 @@ * promote to an object value. Lightfuncs and plain buffers are * coerced with ToObject() even they could also be returned as is. */ - if (arg_mask & (DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_STRING | - DUK_TYPE_MASK_BOOLEAN | - DUK_TYPE_MASK_NUMBER | - DUK_TYPE_MASK_POINTER | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_LIGHTFUNC)) { + if (arg_mask & (DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER | + DUK_TYPE_MASK_POINTER | DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_LIGHTFUNC)) { /* For DUK_TYPE_OBJECT the coercion is a no-op and could * be checked for explicitly, but Object(obj) calls are * not very common so opt for minimal footprint. @@ -46,13 +41,12 @@ } (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) && defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_assign(duk_hthread *thr) { @@ -109,9 +103,8 @@ DUK_ASSERT(proto != NULL || duk_is_null(thr, 0)); (void) duk_push_object_helper_proto(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), proto); if (!duk_is_undefined(thr, 1)) { @@ -132,7 +125,7 @@ return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_properties(duk_hthread *thr) { @@ -147,11 +140,9 @@ obj = duk_require_hobject_promote_mask(thr, 0, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); DUK_ASSERT(obj != NULL); - duk_to_object(thr, 1); /* properties object */ + duk_to_object(thr, 1); /* properties object */ - DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT", - (duk_tval *) duk_get_tval(thr, 0), - (duk_tval *) duk_get_tval(thr, 1))); + DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT", (duk_tval *) duk_get_tval(thr, 0), (duk_tval *) duk_get_tval(thr, 1))); /* * Two pass approach to processing the property descriptors. @@ -164,7 +155,7 @@ */ for (pass = 0; pass < 2; pass++) { - duk_set_top(thr, 2); /* -> hobject props */ + duk_set_top(thr, 2); /* -> hobject props */ duk_enum(thr, 1, DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_INCLUDE_SYMBOLS /*enum_flags*/); for (;;) { @@ -184,12 +175,7 @@ /* hobject props enum(props) key desc */ - duk_hobject_prepare_property_descriptor(thr, - 4 /*idx_desc*/, - &defprop_flags, - &idx_value, - &get, - &set); + duk_hobject_prepare_property_descriptor(thr, 4 /*idx_desc*/, &defprop_flags, &idx_value, &get, &set); /* hobject props enum(props) key desc multiple values */ @@ -201,14 +187,7 @@ key = duk_known_hstring(thr, 3); DUK_ASSERT(key != NULL); - duk_hobject_define_property_helper(thr, - defprop_flags, - obj, - key, - idx_value, - get, - set, - 1 /*throw_flag*/); + duk_hobject_define_property_helper(thr, defprop_flags, obj, key, idx_value, get, set, 1 /*throw_flag*/); } } @@ -219,7 +198,7 @@ duk_dup_0(thr); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_seal_freeze_shared(duk_hthread *thr) { @@ -228,7 +207,7 @@ duk_seal_freeze_raw(thr, 0, (duk_bool_t) duk_get_current_magic(thr) /*is_freeze*/); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_is_sealed_frozen_shared(duk_hthread *thr) { @@ -240,34 +219,33 @@ mask = duk_get_type_mask(thr, 0); if (mask & (DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { DUK_ASSERT(is_frozen == 0 || is_frozen == 1); - duk_push_boolean(thr, (mask & DUK_TYPE_MASK_LIGHTFUNC) ? - 1 : /* lightfunc always frozen and sealed */ - (is_frozen ^ 1)); /* buffer sealed but not frozen (index props writable) */ + duk_push_boolean(thr, + (mask & DUK_TYPE_MASK_LIGHTFUNC) ? 1 : /* lightfunc always frozen and sealed */ + (is_frozen ^ 1)); /* buffer sealed but not frozen (index props writable) */ } else { /* ES2015 Sections 19.1.2.12, 19.1.2.13: anything other than an object * is considered to be already sealed and frozen. */ h = duk_get_hobject(thr, 0); - duk_push_boolean(thr, (h == NULL) || - duk_hobject_object_is_sealed_frozen_helper(thr, h, is_frozen /*is_frozen*/)); + duk_push_boolean(thr, (h == NULL) || duk_hobject_object_is_sealed_frozen_helper(thr, h, is_frozen /*is_frozen*/)); } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_to_locale_string(duk_hthread *thr) { DUK_ASSERT_TOP(thr, 0); (void) duk_push_this_coercible_to_object(thr); duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_TO_STRING); -#if 0 /* This is mentioned explicitly in the E5.1 spec, but duk_call_method() checks for it in practice. */ +#if 0 /* This is mentioned explicitly in the E5.1 spec, but duk_call_method() checks for it in practice. */ duk_require_callable(thr, 1); #endif - duk_dup_0(thr); /* -> O toString O */ - duk_call_method(thr, 0); /* XXX: call method tail call? */ + duk_dup_0(thr); /* -> O toString O */ + duk_call_method(thr, 0); /* XXX: call method tail call? */ return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_value_of(duk_hthread *thr) { @@ -275,7 +253,7 @@ (void) duk_push_this_coercible_to_object(thr); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_is_prototype_of(duk_hthread *thr) { @@ -286,7 +264,7 @@ h_v = duk_get_hobject(thr, 0); if (!h_v) { - duk_push_false(thr); /* XXX: tail call: return duk_push_false(thr) */ + duk_push_false(thr); /* XXX: tail call: return duk_push_false(thr) */ return 1; } @@ -296,22 +274,24 @@ /* E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare. * Prototype loops should cause an error to be thrown. */ - duk_push_boolean(thr, duk_hobject_prototype_chain_contains(thr, DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_v), h_obj, 0 /*ignore_loop*/)); + duk_push_boolean( + thr, + duk_hobject_prototype_chain_contains(thr, DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_v), h_obj, 0 /*ignore_loop*/)); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_has_own_property(duk_hthread *thr) { return (duk_ret_t) duk_hobject_object_ownprop_helper(thr, 0 /*required_desc_flags*/); } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_property_is_enumerable(duk_hthread *thr) { return (duk_ret_t) duk_hobject_object_ownprop_helper(thr, DUK_PROPDESC_FLAG_ENUMERABLE /*required_desc_flags*/); } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper to implement Object.getPrototypeOf, @@ -368,7 +348,7 @@ } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper to implement ES2015 Object.setPrototypeOf, @@ -387,7 +367,7 @@ duk_hobject *h_obj; duk_hobject *h_new_proto; duk_hobject *h_curr; - duk_ret_t ret_success = 1; /* retval for success path */ + duk_ret_t ret_success = 1; /* retval for success path */ duk_uint_t mask; duk_int_t magic; @@ -408,9 +388,7 @@ if (magic == 1) { duk_require_object_coercible(thr, 0); } else { - duk_require_hobject_accept_mask(thr, 0, - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER); + duk_require_hobject_accept_mask(thr, 0, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); } duk_require_type_mask(thr, 1, DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_OBJECT); } @@ -421,9 +399,8 @@ mask = duk_get_type_mask(thr, 0); if (mask & (DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { duk_hobject *curr_proto; - curr_proto = thr->builtins(mask & DUK_TYPE_MASK_LIGHTFUNC) ? - DUK_BIDX_FUNCTION_PROTOTYPE : - DUK_BIDX_UINT8ARRAY_PROTOTYPE; + curr_proto = + thr->builtins(mask & DUK_TYPE_MASK_LIGHTFUNC) ? DUK_BIDX_FUNCTION_PROTOTYPE : DUK_BIDX_UINT8ARRAY_PROTOTYPE; if (h_new_proto == curr_proto) { goto skip; } @@ -453,15 +430,15 @@ DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h_obj, h_new_proto); /* fall thru */ - skip: +skip: duk_set_top(thr, 1); if (magic == 2) { duk_push_true(thr); } return ret_success; - fail_nonextensible: - fail_loop: +fail_nonextensible: +fail_loop: if (magic != 2) { DUK_DCERROR_TYPE_INVALID_ARGS(thr); } else { @@ -469,7 +446,7 @@ return 1; } } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_property(duk_hthread *thr) { @@ -521,12 +498,7 @@ * Lightfunc set/get values are coerced to full Functions. */ - duk_hobject_prepare_property_descriptor(thr, - 2 /*idx_desc*/, - &defprop_flags, - &idx_value, - &get, - &set); + duk_hobject_prepare_property_descriptor(thr, 2 /*idx_desc*/, &defprop_flags, &idx_value, &get, &set); /* * Use Object.defineProperty() helper for the actual operation. @@ -534,14 +506,7 @@ DUK_ASSERT(magic == 0U || magic == 1U); throw_flag = magic ^ 1U; - ret = duk_hobject_define_property_helper(thr, - defprop_flags, - obj, - key, - idx_value, - get, - set, - throw_flag); + ret = duk_hobject_define_property_helper(thr, defprop_flags, obj, key, idx_value, get, set, throw_flag); /* Ignore the normalize/validate helper outputs on the value stack, * they're popped automatically. @@ -556,7 +521,7 @@ } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_get_own_property_descriptor(duk_hthread *thr) { @@ -572,7 +537,7 @@ duk_hobject_object_get_own_property_descriptor(thr, -2); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_is_extensible(duk_hthread *thr) { @@ -595,7 +560,7 @@ duk_push_boolean(thr, (h != NULL) && DUK_HOBJECT_HAS_EXTENSIBLE(h)); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper for various key/symbol listings, magic: @@ -606,26 +571,17 @@ */ DUK_LOCAL const duk_small_uint_t duk__object_keys_enum_flags4 = { /* Object.keys() */ - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_NO_PROXY_BEHAVIOR, + DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Object.getOwnPropertyNames() */ - DUK_ENUM_INCLUDE_NONENUMERABLE | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_NO_PROXY_BEHAVIOR, + DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Object.getOwnPropertySymbols() */ - DUK_ENUM_INCLUDE_SYMBOLS | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_EXCLUDE_STRINGS | - DUK_ENUM_INCLUDE_NONENUMERABLE | + DUK_ENUM_INCLUDE_SYMBOLS | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_EXCLUDE_STRINGS | DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Reflect.ownKeys() */ - DUK_ENUM_INCLUDE_SYMBOLS | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_INCLUDE_NONENUMERABLE | - DUK_ENUM_NO_PROXY_BEHAVIOR + DUK_ENUM_INCLUDE_SYMBOLS | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_NO_PROXY_BEHAVIOR }; DUK_INTERNAL duk_ret_t duk_bi_object_constructor_keys_shared(duk_hthread *thr) { @@ -657,9 +613,7 @@ #if defined(DUK_USE_ES6_PROXY) /* XXX: better sharing of code between proxy target call sites */ - if (DUK_LIKELY(!duk_hobject_proxy_check(obj, - &h_proxy_target, - &h_proxy_handler))) { + if (DUK_LIKELY(!duk_hobject_proxy_check(obj, &h_proxy_target, &h_proxy_handler))) { goto skip_proxy; } @@ -678,8 +632,8 @@ /* obj handler trap */ duk_insert(thr, -2); - duk_push_hobject(thr, h_proxy_target); /* -> obj trap handler target */ - duk_call_method(thr, 1 /*nargs*/); /* -> obj trap_result */ + duk_push_hobject(thr, h_proxy_target); /* -> obj trap handler target */ + duk_call_method(thr, 1 /*nargs*/); /* -> obj trap_result */ h_trap_result = duk_require_hobject(thr, -1); DUK_UNREF(h_trap_result); @@ -690,8 +644,8 @@ duk_proxy_ownkeys_postprocess(thr, h_proxy_target, enum_flags); return 1; - skip_proxy: -#endif /* DUK_USE_ES6_PROXY */ +skip_proxy: +#endif /* DUK_USE_ES6_PROXY */ DUK_ASSERT_TOP(thr, 1); magic = duk_get_current_magic(thr); @@ -699,7 +653,7 @@ enum_flags = duk__object_keys_enum_flagsmagic; return duk_hobject_get_enumerated_keys(thr, enum_flags); } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_prevent_extensions(duk_hthread *thr) { @@ -719,12 +673,8 @@ /* Object.preventExtensions() silent success for non-object. */ if (magic == 0) { - mask |= DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_BOOLEAN | - DUK_TYPE_MASK_NUMBER | - DUK_TYPE_MASK_STRING | - DUK_TYPE_MASK_POINTER; + mask |= DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER | + DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_POINTER; } if (duk_check_type_mask(thr, 0, mask)) { @@ -741,13 +691,13 @@ */ duk_hobject_compact_props(thr, h); - done: +done: if (magic == 1) { duk_push_true(thr); } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ /* * __defineGetter__, __defineSetter__, __lookupGetter__, __lookupSetter__ @@ -763,9 +713,10 @@ /* ToObject(this) key getter/setter */ /* ToPropertyKey() coercion is not needed, duk_def_prop() does it. */ - duk_def_prop(thr, 0, DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE | - (duk_get_current_magic(thr) ? DUK_DEFPROP_HAVE_SETTER : DUK_DEFPROP_HAVE_GETTER)); + duk_def_prop(thr, + 0, + DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE | + (duk_get_current_magic(thr) ? DUK_DEFPROP_HAVE_SETTER : DUK_DEFPROP_HAVE_GETTER)); return 0; } DUK_INTERNAL duk_ret_t duk_bi_object_prototype_lookupaccessor(duk_hthread *thr) { @@ -800,4 +751,4 @@ } return 1; } -#endif /* DUK_USE_ES8 */ +#endif /* DUK_USE_ES8 */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_performance.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_performance.c
Changed
@@ -18,7 +18,7 @@ return 1; } -#if 0 /* Missing until semantics decided. */ +#if 0 /* Missing until semantics decided. */ DUK_INTERNAL duk_ret_t duk_bi_performance_timeorigin_getter(duk_hthread *thr) { /* No decision yet how to handle timeOrigins, e.g. should one be * initialized per heap, or per global object set. See @@ -27,5 +27,5 @@ duk_push_uint(thr, 0); return 1; } -#endif /* 0 */ -#endif /* DUK_USE_PERFORMANCE_BUILTIN */ +#endif /* 0 */ +#endif /* DUK_USE_PERFORMANCE_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_pointer.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_pointer.c
Changed
@@ -23,9 +23,8 @@ if (duk_is_constructor_call(thr)) { (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER), DUK_BIDX_POINTER_PROTOTYPE); /* Pointer object internal value is immutable. */ @@ -70,6 +69,6 @@ } return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_promise.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_promise.c
Changed
@@ -41,4 +41,4 @@ DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_PROMISE_BUILTIN */ +#endif /* DUK_USE_PROMISE_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_protos.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_protos.h
Changed
@@ -12,7 +12,7 @@ * 32 * Include additional space to be safe. */ -#define DUK_BI_DATE_ISO8601_BUFSIZE 40 +#define DUK_BI_DATE_ISO8601_BUFSIZE 40 /* Helpers exposed for internal use */ DUK_INTERNAL_DECL void duk_bi_date_timeval_to_parts(duk_double_t d, duk_int_t *parts, duk_double_t *dparts, duk_small_uint_t flags); @@ -50,7 +50,10 @@ DUK_INTERNAL_DECL duk_bool_t duk_bi_date_parse_string_getdate(duk_hthread *thr, const char *str); #endif #if defined(DUK_USE_DATE_FMT_STRFTIME) -DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags); +DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, + duk_int_t *parts, + duk_int_t tzoffset, + duk_small_uint_t flags); #endif #if defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME) @@ -61,10 +64,7 @@ #endif DUK_INTERNAL_DECL -void duk_bi_json_parse_helper(duk_hthread *thr, - duk_idx_t idx_value, - duk_idx_t idx_reviver, - duk_small_uint_t flags); +void duk_bi_json_parse_helper(duk_hthread *thr, duk_idx_t idx_value, duk_idx_t idx_reviver, duk_small_uint_t flags); DUK_INTERNAL_DECL void duk_bi_json_stringify_helper(duk_hthread *thr, duk_idx_t idx_value, @@ -78,4 +78,4 @@ DUK_INTERNAL_DECL void duk_proxy_ownkeys_postprocess(duk_hthread *thr, duk_hobject *h_proxy_target, duk_uint_t flags); #endif -#endif /* DUK_BUILTIN_PROTOS_H_INCLUDED */ +#endif /* DUK_BUILTIN_PROTOS_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_proxy.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_proxy.c
Changed
@@ -68,7 +68,7 @@ duk_def_prop(thr, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_SET_WEC); continue; - skip_key: + skip_key: duk_pop(thr); continue; } @@ -85,14 +85,14 @@ * handled above. */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ES6_PROXY) DUK_INTERNAL duk_ret_t duk_bi_proxy_constructor(duk_hthread *thr) { - DUK_ASSERT_TOP(thr, 2); /* target handler */ + DUK_ASSERT_TOP(thr, 2); /* target handler */ duk_require_constructor_call(thr); - duk_push_proxy(thr, 0 /*flags*/); /* target handler -> proxy */ - return 1; /* replacement */ + duk_push_proxy(thr, 0 /*flags*/); /* target handler -> proxy */ + return 1; /* replacement */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_reflect.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_reflect.c
Changed
@@ -47,7 +47,7 @@ tv_obj = DUK_GET_TVAL_POSIDX(thr, 0); tv_key = DUK_GET_TVAL_POSIDX(thr, 1); - (void) duk_hobject_getprop(thr, tv_obj, tv_key); /* This could also be a duk_get_prop(). */ + (void) duk_hobject_getprop(thr, tv_obj, tv_key); /* This could also be a duk_get_prop(). */ return 1; } @@ -96,4 +96,4 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_REFLECT_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_regexp.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_regexp.c
Changed
@@ -13,7 +13,7 @@ h = duk_require_hobject_with_class(thr, -1, DUK_HOBJECT_CLASS_REGEXP); DUK_ASSERT(h != NULL); DUK_UNREF(h); - duk_insert(thr, 0); /* prepend regexp to valstack 0 index */ + duk_insert(thr, 0); /* prepend regexp to valstack 0 index */ } /* XXX: much to improve (code size) */ @@ -23,10 +23,8 @@ DUK_ASSERT_TOP(thr, 2); h_pattern = duk_get_hobject(thr, 0); - if (!duk_is_constructor_call(thr) && - h_pattern != NULL && - DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP && - duk_is_undefined(thr, 1)) { + if (!duk_is_constructor_call(thr) && h_pattern != NULL && + DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP && duk_is_undefined(thr, 1)) { /* Called as a function, pattern has Class "RegExp" and * flags is undefined -> return object as is. */ @@ -41,8 +39,7 @@ * call. */ - if (h_pattern != NULL && - DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP) { + if (h_pattern != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP) { duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_SOURCE); if (duk_is_undefined(thr, 1)) { /* In ES5 one would need to read the flags individually; @@ -58,20 +55,21 @@ duk_push_hstring_empty(thr); } else { duk_dup_0(thr); - duk_to_string(thr, -1); /* Rejects Symbols. */ + duk_to_string(thr, -1); /* Rejects Symbols. */ } if (duk_is_undefined(thr, 1)) { duk_push_hstring_empty(thr); } else { duk_dup_1(thr); - duk_to_string(thr, -1); /* Rejects Symbols. */ + duk_to_string(thr, -1); /* Rejects Symbols. */ } /* ... pattern flags */ } DUK_DDD(DUK_DDDPRINT("RegExp constructor/function call, pattern=%!T, flags=%!T", - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); /* ... pattern flags (both uncoerced) */ @@ -121,7 +119,7 @@ duk_push_this(thr); duk_push_literal(thr, "/"); duk_get_prop_stridx(thr, 0, DUK_STRIDX_SOURCE); - duk_dup_m2(thr); /* another "/" */ + duk_dup_m2(thr); /* another "/" */ duk_get_prop_stridx(thr, 0, DUK_STRIDX_FLAGS); duk_concat(thr, 4); return 1; @@ -131,7 +129,7 @@ /* .flags is ES2015 but present even when ES2015 bindings are * disabled because the constructor relies on it. */ - duk_uint8_t buf8; /* enough for all flags + NUL */ + duk_uint8_t buf8; /* enough for all flags + NUL */ duk_uint8_t *p = buf; /* .flags is generic and works on any object. */ @@ -172,7 +170,7 @@ duk_xget_owndataprop_stridx_short(thr, 0, DUK_STRIDX_INT_SOURCE); duk_xget_owndataprop_stridx_short(thr, 0, DUK_STRIDX_INT_BYTECODE); h_bc = duk_require_hstring(thr, -1); - re_flags = (duk_small_uint_t) DUK_HSTRING_GET_DATA(h_bc)0; /* Safe even if h_bc length is 0 (= NUL) */ + re_flags = (duk_small_uint_t) DUK_HSTRING_GET_DATA(h_bc)0; /* Safe even if h_bc length is 0 (= NUL) */ duk_pop(thr); } else if (h == thr->builtinsDUK_BIDX_REGEXP_PROTOTYPE) { /* In ES2015 and ES2016 a TypeError would be thrown here. @@ -183,7 +181,7 @@ if (magic != 16 /* .source */) { return 0; } - duk_push_literal(thr, "(?:)"); /* .source handled by switch-case */ + duk_push_literal(thr, "(?:)"); /* .source handled by switch-case */ re_flags = 0; } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -192,15 +190,15 @@ /* regexp source */ switch (magic) { - case 0: { /* global */ + case 0: { /* global */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_GLOBAL)); break; } - case 1: { /* ignoreCase */ + case 1: { /* ignoreCase */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_IGNORE_CASE)); break; } - case 2: { /* multiline */ + case 2: { /* multiline */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_MULTILINE)); break; } @@ -214,7 +212,7 @@ break; } #endif - default: { /* source */ + default: { /* source */ /* leave 'source' on top */ break; } @@ -223,4 +221,4 @@ return 1; } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_string.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_string.c
Changed
@@ -36,7 +36,8 @@ return h; } -DUK_LOCAL duk_int_t duk__str_search_shared(duk_hthread *thr, duk_hstring *h_this, duk_hstring *h_search, duk_int_t start_cpos, duk_bool_t backwards) { +DUK_LOCAL duk_int_t +duk__str_search_shared(duk_hthread *thr, duk_hstring *h_this, duk_hstring *h_search, duk_int_t start_cpos, duk_bool_t backwards) { duk_int_t cpos; duk_int_t bpos; const duk_uint8_t *p_start, *p_end, *p; @@ -71,7 +72,7 @@ * must be updated if 'p' is wound back (backward scanning). */ - firstbyte = q_start0; /* leading byte of match string */ + firstbyte = q_start0; /* leading byte of match string */ while (p <= p_end && p >= p_start) { t = *p; @@ -137,15 +138,13 @@ duk_replace(thr, 0); } } - duk_to_string(thr, 0); /* catches symbol argument for constructor call */ + duk_to_string(thr, 0); /* catches symbol argument for constructor call */ DUK_ASSERT(duk_is_string(thr, 0)); - duk_set_top(thr, 1); /* Top may be 1 or larger. */ + duk_set_top(thr, 1); /* Top may be 1 or larger. */ if (duk_is_constructor_call(thr)) { /* String object internal value is immutable */ - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_STRING); duk_push_object_helper(thr, flags, DUK_BIDX_STRING_PROTOTYPE); duk_dup_0(thr); @@ -171,7 +170,7 @@ n = duk_get_top(thr); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, (duk_size_t) n); /* initial estimate for ASCII only codepoints */ + DUK_BW_INIT_PUSHBUF(thr, bw, (duk_size_t) n); /* initial estimate for ASCII only codepoints */ for (i = 0; i < n; i++) { /* XXX: could improve bufwriter handling to write multiple codepoints @@ -185,8 +184,7 @@ * the same. */ duk_int32_t i32 = 0; - if (!duk_is_whole_get_int32(duk_to_number(thr, i), &i32) || - i32 < 0 || i32 > 0x10ffffL) { + if (!duk_is_whole_get_int32(duk_to_number(thr, i), &i32) || i32 < 0 || i32 > 0x10ffffL) { DUK_DCERROR_RANGE_INVALID_ARGS(thr); } DUK_ASSERT(i32 >= 0 && i32 <= 0x10ffffL); @@ -210,7 +208,7 @@ } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 or CESU-8 encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 or CESU-8 encoded. */ return 1; } @@ -252,10 +250,10 @@ goto type_error; } - (void) duk_require_hstring_notsymbol(thr, -1); /* Reject symbols (and wrapped symbols). */ + (void) duk_require_hstring_notsymbol(thr, -1); /* Reject symbols (and wrapped symbols). */ return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -391,7 +389,7 @@ * ("undefined" and "null"). */ duk_push_this(thr); - h = duk_to_hstring_m1(thr); /* Reject Symbols. */ + h = duk_to_hstring_m1(thr); /* Reject Symbols. */ DUK_ASSERT(h != NULL); len = (duk_int_t) DUK_HSTRING_GET_CHARLEN(h); @@ -423,7 +421,7 @@ duk_substring(thr, -1, (duk_size_t) start_pos, (duk_size_t) end_pos); return 1; } -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_slice(duk_hthread *thr) { duk_hstring *h; @@ -482,7 +480,7 @@ duk_hstring *h_search; duk_int_t clen_this; duk_int_t cpos; - duk_small_uint_t is_lastindexof = (duk_small_uint_t) duk_get_current_magic(thr); /* 0=indexOf, 1=lastIndexOf */ + duk_small_uint_t is_lastindexof = (duk_small_uint_t) duk_get_current_magic(thr); /* 0=indexOf, 1=lastIndexOf */ h_this = duk_push_this_coercible_to_string(thr); DUK_ASSERT(h_this != NULL); @@ -539,7 +537,7 @@ duk_int_t match_caps; #endif duk_uint32_t prev_match_end_boff; - const duk_uint8_t *r_start, *r_end, *r; /* repl string scan */ + const duk_uint8_t *r_start, *r_end, *r; /* repl string scan */ duk_size_t tmp_sz; DUK_ASSERT_TOP(thr, 2); @@ -547,7 +545,7 @@ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* input size is good output starting point */ + DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* input size is good output starting point */ DUK_ASSERT_TOP(thr, 4); @@ -568,11 +566,11 @@ duk_push_int(thr, 0); duk_put_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ DUK_DCERROR_UNSUPPORTED(thr); -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } else { - duk_to_string(thr, 0); /* rejects symbols */ + duk_to_string(thr, 0); /* rejects symbols */ #if defined(DUK_USE_REGEXP_SUPPORT) is_regexp = 0; is_global = 0; @@ -587,7 +585,7 @@ duk_hstring *h_repl; is_repl_func = 0; - h_repl = duk_to_hstring(thr, 1); /* reject symbols */ + h_repl = duk_to_hstring(thr, 1); /* reject symbols */ DUK_ASSERT(h_repl != NULL); r_start = DUK_HSTRING_GET_DATA(h_repl); r_end = r_start + DUK_HSTRING_GET_BYTELEN(h_repl); @@ -625,7 +623,7 @@ if (is_regexp) { duk_dup_0(thr); duk_dup_2(thr); - duk_regexp_match(thr); /* ... regexp input -> res_obj */ + duk_regexp_match(thr); /* ... regexp input -> res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); break; @@ -639,7 +637,7 @@ duk_get_prop_index(thr, -1, 0); DUK_ASSERT(duk_is_string(thr, -1)); h_match = duk_known_hstring(thr, -1); - duk_pop(thr); /* h_match is borrowed, remains reachable through match_obj */ + duk_pop(thr); /* h_match is borrowed, remains reachable through match_obj */ if (DUK_HSTRING_GET_BYTELEN(h_match) == 0) { /* This should be equivalent to match() algorithm step 8.f.iii.2: @@ -650,25 +648,26 @@ duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); last_index = (duk_uint32_t) duk_get_uint(thr, -1); DUK_DDD(DUK_DDDPRINT("empty match, bump lastIndex: %ld -> %ld", - (long) last_index, (long) (last_index + 1))); + (long) last_index, + (long) (last_index + 1))); duk_pop(thr); duk_push_uint(thr, (duk_uint_t) (last_index + 1)); duk_put_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); } - DUK_ASSERT(duk_get_length(thr, -1) <= DUK_INT_MAX); /* string limits */ + DUK_ASSERT(duk_get_length(thr, -1) <= DUK_INT_MAX); /* string limits */ match_caps = (duk_int_t) duk_get_length(thr, -1); } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ - const duk_uint8_t *q_start; /* match string */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ + const duk_uint8_t *q_start; /* match string */ duk_size_t p_blen; duk_size_t q_blen; #if defined(DUK_USE_REGEXP_SUPPORT) - DUK_ASSERT(!is_global); /* single match always */ + DUK_ASSERT(!is_global); /* single match always */ #endif p_start = DUK_HSTRING_GET_DATA(h_input); @@ -681,10 +680,10 @@ q_blen = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_search); if (q_blen > p_blen) { - break; /* no match */ + break; /* no match */ } - p_end -= q_blen; /* ensure full memcmp() fits in while */ + p_end -= q_blen; /* ensure full memcmp() fits in while */ DUK_ASSERT(p_end >= p); match_start_coff = 0; @@ -710,7 +709,7 @@ /* not found */ break; } - found: + found: /* stack0 = search value * stack1 = replace value @@ -744,9 +743,9 @@ duk_get_prop_index(thr, 4, (duk_uarridx_t) idx); } } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* match == search string, by definition */ duk_dup_0(thr); } @@ -756,12 +755,12 @@ /* ... replacer match captures match_char_offset input */ duk_call(thr, duk_get_top(thr) - idx_args); - h_repl = duk_to_hstring_m1(thr); /* -> ... repl_value */ + h_repl = duk_to_hstring_m1(thr); /* -> ... repl_value */ DUK_ASSERT(h_repl != NULL); DUK_BW_WRITE_ENSURE_HSTRING(thr, bw, h_repl); - duk_pop(thr); /* repl_value */ + duk_pop(thr); /* repl_value */ } else { r = r_start; @@ -808,9 +807,10 @@ * match codepoint encodings would have different lengths. */ /* XXX: charlen computed here, and also in char2byte helper. */ - match_end_boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte(thr, - h_input, - match_start_coff + (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_match)); + match_end_boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte( + thr, + h_input, + match_start_coff + (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_match)); tmp_sz = (duk_size_t) (DUK_HSTRING_GET_BYTELEN(h_input) - match_end_boff); DUK_BW_WRITE_ENSURE_BYTES(thr, bw, DUK_HSTRING_GET_DATA(h_input) + match_end_boff, tmp_sz); @@ -846,7 +846,7 @@ } if (capnum > 0 && capnum < match_caps) { - DUK_ASSERT(is_regexp != 0); /* match_caps == 0 without regexps */ + DUK_ASSERT(is_regexp != 0); /* match_caps == 0 without regexps */ /* regexp res_obj is at offset 4 */ duk_get_prop_index(thr, 4, (duk_uarridx_t) capnum); @@ -865,26 +865,26 @@ } else { goto repl_write; } -#else /* DUK_USE_REGEXP_SUPPORT */ - goto repl_write; /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - } /* default case */ - } /* switch (ch2) */ +#else /* DUK_USE_REGEXP_SUPPORT */ + goto repl_write; /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + } /* default case */ + } /* switch (ch2) */ - repl_write: + repl_write: /* ch1 = (r_increment << 8) + byte */ DUK_BW_WRITE_ENSURE_U8(thr, bw, (duk_uint8_t) (ch1 & 0xff)); r += ch1 >> 8; - } /* while repl */ - } /* if (is_repl_func) */ + } /* while repl */ + } /* if (is_repl_func) */ - duk_pop(thr); /* pop regexp res_obj or match string */ + duk_pop(thr); /* pop regexp res_obj or match string */ #if defined(DUK_USE_REGEXP_SUPPORT) if (!is_global) { #else - { /* unconditionally; is_global==0 */ + { /* unconditionally; is_global==0 */ #endif break; } @@ -896,7 +896,7 @@ DUK_ASSERT_TOP(thr, 4); DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ return 1; } @@ -916,7 +916,7 @@ #if defined(DUK_USE_REGEXP_SUPPORT) duk_bool_t is_regexp; #endif - duk_bool_t matched; /* set to 1 if any match exists (needed for empty input special case) */ + duk_bool_t matched; /* set to 1 if any match exists (needed for empty input special case) */ duk_uint32_t prev_match_end_coff, prev_match_end_boff; duk_uint32_t match_start_boff, match_start_coff; duk_uint32_t match_end_boff, match_end_coff; @@ -954,7 +954,7 @@ #if defined(DUK_USE_REGEXP_SUPPORT) duk_push_hobject_bidx(thr, DUK_BIDX_REGEXP_CONSTRUCTOR); duk_dup_0(thr); - duk_new(thr, 1); /* ... RegExp val -> ... res */ + duk_new(thr, 1); /* ... RegExp val -> ... res */ duk_replace(thr, 0); /* lastIndex is initialized to zero by new RegExp() */ is_regexp = 1; @@ -993,7 +993,7 @@ if (is_regexp) { duk_dup_0(thr); duk_dup_2(thr); - duk_regexp_match_force_global(thr); /* ... regexp input -> res_obj */ + duk_regexp_match_force_global(thr); /* ... regexp input -> res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); break; @@ -1026,23 +1026,23 @@ continue; } } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ - const duk_uint8_t *q_start; /* match string */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ + const duk_uint8_t *q_start; /* match string */ duk_size_t q_blen, q_clen; p_start = DUK_HSTRING_GET_DATA(h_input); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); p = p_start + prev_match_end_boff; - h_sep = duk_known_hstring(thr, 0); /* symbol already rejected above */ + h_sep = duk_known_hstring(thr, 0); /* symbol already rejected above */ q_start = DUK_HSTRING_GET_DATA(h_sep); q_blen = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sep); q_clen = (duk_size_t) DUK_HSTRING_GET_CHARLEN(h_sep); - p_end -= q_blen; /* ensure full memcmp() fits in while */ + p_end -= q_blen; /* ensure full memcmp() fits in while */ match_start_coff = prev_match_end_coff; @@ -1055,7 +1055,7 @@ * Don't allow an empty string to match at the end of the input. */ - matched = 1; /* empty separator can always match */ + matched = 1; /* empty separator can always match */ match_start_coff++; p++; @@ -1071,7 +1071,7 @@ DUK_ASSERT(q_blen > 0 && q_clen > 0); while (p <= p_end) { DUK_ASSERT(p + q_blen <= DUK_HSTRING_GET_DATA(h_input) + DUK_HSTRING_GET_BYTELEN(h_input)); - DUK_ASSERT(q_blen > 0); /* no issues with empty memcmp() */ + DUK_ASSERT(q_blen > 0); /* no issues with empty memcmp() */ if (duk_memcmp((const void *) p, (const void *) q_start, (size_t) q_blen) == 0) { /* never an empty match, so step 13.c.iii can't be triggered */ goto found; @@ -1084,15 +1084,15 @@ p++; } - not_found: + not_found: /* not found */ break; - found: + found: matched = 1; match_start_boff = (duk_uint32_t) (p - p_start); - match_end_coff = (duk_uint32_t) (match_start_coff + q_clen); /* constrained by string length */ - match_end_boff = (duk_uint32_t) (match_start_boff + q_blen); /* ditto */ + match_end_coff = (duk_uint32_t) (match_start_coff + q_clen); /* constrained by string length */ + match_end_boff = (duk_uint32_t) (match_start_boff + q_blen); /* ditto */ /* empty match (may happen with empty separator) -> bump and continue */ if (prev_match_end_boff == match_end_boff) { @@ -1100,7 +1100,7 @@ prev_match_end_coff++; continue; } - } /* if (is_regexp) */ + } /* if (is_regexp) */ /* stack0 = separator (string or regexp) * stack1 = limit @@ -1110,9 +1110,12 @@ */ DUK_DDD(DUK_DDDPRINT("split; match_start b=%ld,c=%ld, match_end b=%ld,c=%ld, prev_end b=%ld,c=%ld", - (long) match_start_boff, (long) match_start_coff, - (long) match_end_boff, (long) match_end_coff, - (long) prev_match_end_boff, (long) prev_match_end_coff)); + (long) match_start_boff, + (long) match_start_coff, + (long) match_end_boff, + (long) match_end_coff, + (long) prev_match_end_boff, + (long) prev_match_end_coff)); duk_push_lstring(thr, (const char *) (DUK_HSTRING_GET_DATA(h_input) + prev_match_end_boff), @@ -1129,7 +1132,7 @@ len = duk_get_length(thr, 4); for (i = 1; i < len; i++) { - DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* cannot have >4G captures */ + DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* cannot have >4G captures */ duk_get_prop_index(thr, 4, (duk_uarridx_t) i); duk_put_prop_index(thr, 3, arr_idx); arr_idx++; @@ -1141,21 +1144,21 @@ duk_pop(thr); /* lastIndex already set up for next match */ } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { + /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* no action */ } prev_match_end_boff = match_end_boff; prev_match_end_coff = match_end_coff; continue; - } /* for */ + } /* for */ /* Combined step 11 (empty string special case) and 14-15. */ - DUK_DDD(DUK_DDDPRINT("split trailer; prev_end b=%ld,c=%ld", - (long) prev_match_end_boff, (long) prev_match_end_coff)); + DUK_DDD(DUK_DDDPRINT("split trailer; prev_end b=%ld,c=%ld", (long) prev_match_end_boff, (long) prev_match_end_coff)); if (DUK_HSTRING_GET_BYTELEN(h_input) > 0 || !matched) { /* Add trailer if: @@ -1172,7 +1175,7 @@ return 1; - hit_limit: +hit_limit: #if defined(DUK_USE_REGEXP_SUPPORT) if (is_regexp) { duk_pop(thr); @@ -1204,13 +1207,13 @@ } return; - do_new: +do_new: duk_push_hobject_bidx(thr, DUK_BIDX_REGEXP_CONSTRUCTOR); duk_dup(thr, idx); - duk_new(thr, 1); /* ... RegExp val -> ... res */ + duk_new(thr, 1); /* ... RegExp val -> ... res */ duk_replace(thr, idx); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_search(duk_hthread *thr) { @@ -1225,7 +1228,7 @@ */ DUK_ASSERT_TOP(thr, 1); - (void) duk_push_this_coercible_to_string(thr); /* at index 1 */ + (void) duk_push_this_coercible_to_string(thr); /* at index 1 */ duk__to_regexp_helper(thr, 0 /*index*/, 1 /*force_new*/); /* stack0 = regexp @@ -1237,8 +1240,8 @@ */ duk_dup_0(thr); - duk_dup_1(thr); /* ... re_obj input */ - duk_regexp_match(thr); /* -> ... res_obj */ + duk_dup_1(thr); /* ... re_obj input */ + duk_regexp_match(thr); /* -> ... res_obj */ if (!duk_is_object(thr, -1)) { duk_push_int(thr, -1); @@ -1249,7 +1252,7 @@ DUK_ASSERT(duk_is_number(thr, -1)); return 1; } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_match(duk_hthread *thr) { @@ -1269,8 +1272,8 @@ */ if (!global) { - duk_regexp_match(thr); /* -> res_obj */ - return 1; /* return 'res_obj' */ + duk_regexp_match(thr); /* -> res_obj */ + return 1; /* return 'res_obj' */ } /* Global case is more complex. */ @@ -1291,7 +1294,7 @@ duk_dup_0(thr); duk_dup_1(thr); - duk_regexp_match(thr); /* -> ... regexp string -> ... res_obj */ + duk_regexp_match(thr); /* -> ... regexp string -> ... res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); @@ -1310,24 +1313,24 @@ } prev_last_index = this_index; - duk_get_prop_index(thr, -1, 0); /* match string */ + duk_get_prop_index(thr, -1, 0); /* match string */ duk_put_prop_index(thr, 2, (duk_uarridx_t) arr_idx); arr_idx++; - duk_pop(thr); /* res_obj */ + duk_pop(thr); /* res_obj */ } if (arr_idx == 0) { duk_push_null(thr); } - return 1; /* return 'res_arr' or 'null' */ + return 1; /* return 'res_arr' or 'null' */ } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_concat(duk_hthread *thr) { /* duk_concat() coerces arguments with ToString() in correct order */ (void) duk_push_this_coercible_to_string(thr); - duk_insert(thr, 0); /* this is relatively expensive */ + duk_insert(thr, 0); /* this is relatively expensive */ duk_concat(thr, duk_get_top(thr)); return 1; } @@ -1392,10 +1395,10 @@ #if defined(DUK_USE_PREFER_SIZE) p = buf; while (count-- > 0) { - duk_memcpy((void *) p, (const void *) src, input_blen); /* copy size may be zero, but pointers are valid */ + duk_memcpy((void *) p, (const void *) src, input_blen); /* copy size may be zero, but pointers are valid */ p += input_blen; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* Take advantage of already copied pieces to speed up the process * especially for small repeated strings. */ @@ -1405,7 +1408,9 @@ for (;;) { duk_size_t remain = (duk_size_t) (p_end - p); DUK_DDD(DUK_DDDPRINT("remain=%ld, copy_size=%ld, input_blen=%ld, result_len=%ld", - (long) remain, (long) copy_size, (long) input_blen, + (long) remain, + (long) copy_size, + (long) input_blen, (long) result_len)); if (remain <= copy_size) { /* If result_len is zero, this case is taken and does @@ -1418,10 +1423,10 @@ p += copy_size; } - src = (const duk_uint8_t *) buf; /* Use buf as source for larger copies. */ + src = (const duk_uint8_t *) buf; /* Use buf as source for larger copies. */ copy_size = (duk_size_t) (p - buf); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* XXX: It would be useful to be able to create a duk_hstring with * a certain byte size whose data area wasn't initialized and which @@ -1432,13 +1437,13 @@ * intern table (they are not in heap_allocated). */ - duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ + duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ return 1; - fail_range: +fail_range: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_locale_compare(duk_hthread *thr) { duk_hstring *h1; @@ -1492,7 +1497,7 @@ ret = -1; goto done; - done: +done: duk_push_int(thr, (duk_int_t) ret); return 1; } @@ -1579,11 +1584,11 @@ } } - finish: +finish: duk_push_boolean(thr, result); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_includes(duk_hthread *thr) { @@ -1606,5 +1611,5 @@ duk_push_boolean(thr, pos >= 0); return 1; } -#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_STRING_BUILTIN */ +#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_STRING_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_symbol.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_symbol.c
Changed
@@ -39,7 +39,7 @@ buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, 1 + len + 1 + 17 + 1); DUK_ASSERT(buf != NULL); p = buf + 1; - DUK_ASSERT(desc != NULL || len == 0); /* may be NULL if len is 0 */ + DUK_ASSERT(desc != NULL || len == 0); /* may be NULL if len is 0 */ duk_memcpy_unsafe((void *) p, (const void *) desc, len); p += len; if (magic == 0) { @@ -50,7 +50,9 @@ if (++thr->heap->sym_counter0 == 0) { thr->heap->sym_counter1++; } - p += DUK_SPRINTF((char *) p, "\xFF" "%lx-%lx", + p += DUK_SPRINTF((char *) p, + "\xFF" + "%lx-%lx", (unsigned long) thr->heap->sym_counter1, (unsigned long) thr->heap->sym_counter0); if (desc == NULL) { @@ -167,4 +169,4 @@ return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_bi_thread.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_bi_thread.c
Changed
@@ -31,7 +31,7 @@ */ duk_push_hobject(new_thr, func); - return 1; /* return thread */ + return 1; /* return thread */ } #endif @@ -77,14 +77,15 @@ */ if (thr->callstack_top < 2) { - DUK_DD(DUK_DDPRINT("resume state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.resume)")); + DUK_DD(DUK_DDPRINT( + "resume state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.resume)")); goto state_error; } DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr))); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ caller_func = DUK_ACT_GET_FUNC(thr->callstack_curr->parent); if (!DUK_HOBJECT_IS_COMPFUNC(caller_func)) { @@ -96,14 +97,12 @@ * like for yield. */ - if (thr_resume->state != DUK_HTHREAD_STATE_INACTIVE && - thr_resume->state != DUK_HTHREAD_STATE_YIELDED) { + if (thr_resume->state != DUK_HTHREAD_STATE_INACTIVE && thr_resume->state != DUK_HTHREAD_STATE_YIELDED) { DUK_DD(DUK_DDPRINT("resume state invalid: target thread must be INACTIVE or YIELDED")); goto state_error; } - DUK_ASSERT(thr_resume->state == DUK_HTHREAD_STATE_INACTIVE || - thr_resume->state == DUK_HTHREAD_STATE_YIELDED); + DUK_ASSERT(thr_resume->state == DUK_HTHREAD_STATE_INACTIVE || thr_resume->state == DUK_HTHREAD_STATE_YIELDED); /* Further state-dependent pre-checks */ @@ -121,14 +120,13 @@ * because an error in the RESUME handler call processing will * not be handled very cleanly. */ - if ((thr_resume->callstack_top != 0) || - (thr_resume->valstack_top - thr_resume->valstack != 1)) { + if ((thr_resume->callstack_top != 0) || (thr_resume->valstack_top - thr_resume->valstack != 1)) { goto state_error; } duk_push_tval(thr, DUK_GET_TVAL_NEGIDX(thr_resume, -1)); duk_resolve_nonbound_function(thr); - h_fun = duk_require_hobject(thr, -1); /* reject lightfuncs on purpose */ + h_fun = duk_require_hobject(thr, -1); /* reject lightfuncs on purpose */ if (!DUK_HOBJECT_IS_CALLABLE(h_fun) || !DUK_HOBJECT_IS_COMPFUNC(h_fun)) { goto state_error; } @@ -157,8 +155,8 @@ #if defined(DUK_USE_AUGMENT_ERROR_THROW) if (is_error) { - DUK_ASSERT_TOP(thr, 2); /* value (error) is at stack top */ - duk_err_augment_error_throw(thr); /* in resumer's context */ + DUK_ASSERT_TOP(thr, 2); /* value (error) is at stack top */ + duk_err_augment_error_throw(thr); /* in resumer's context */ } #endif @@ -182,21 +180,21 @@ /* lj value2: thread */ DUK_ASSERT(thr->valstack_bottom < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value2, &thr->valstack_bottom0); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value2, &thr->valstack_bottom0); /* side effects */ /* lj value1: value */ DUK_ASSERT(thr->valstack_bottom + 1 < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom1); /* side effects */ DUK_TVAL_CHKFAST_INPLACE_SLOW(&thr->heap->lj.value1); thr->heap->lj.iserror = is_error; - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ - duk_err_longjmp(thr); /* execution resumes in bytecode executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ + duk_err_longjmp(thr); /* execution resumes in bytecode executor */ DUK_UNREACHABLE(); /* Never here, fall through to error (from compiler point of view). */ - state_error: +state_error: DUK_DCERROR_TYPE_INVALID_STATE(thr); } #endif @@ -245,14 +243,15 @@ DUK_ASSERT(thr->resumer->state == DUK_HTHREAD_STATE_RESUMED); if (thr->callstack_top < 2) { - DUK_DD(DUK_DDPRINT("yield state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.yield)")); + DUK_DD(DUK_DDPRINT( + "yield state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.yield)")); goto state_error; } DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr))); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ caller_func = DUK_ACT_GET_FUNC(thr->callstack_curr->parent); if (!DUK_HOBJECT_IS_COMPFUNC(caller_func)) { @@ -260,10 +259,11 @@ goto state_error; } - DUK_ASSERT(thr->callstack_preventcount >= 1); /* should never be zero, because we (Duktape.Thread.yield) are on the stack */ + DUK_ASSERT(thr->callstack_preventcount >= 1); /* should never be zero, because we (Duktape.Thread.yield) are on the stack */ if (thr->callstack_preventcount != 1) { /* Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0 */ - DUK_DD(DUK_DDPRINT("yield state invalid: there must be no yield-preventing calls in current thread callstack (preventcount is %ld)", + DUK_DD(DUK_DDPRINT("yield state invalid: there must be no yield-preventing calls in current thread callstack " + "(preventcount is %ld)", (long) thr->callstack_preventcount)); goto state_error; } @@ -277,18 +277,16 @@ #if defined(DUK_USE_AUGMENT_ERROR_THROW) if (is_error) { - DUK_ASSERT_TOP(thr, 1); /* value (error) is at stack top */ - duk_err_augment_error_throw(thr); /* in yielder's context */ + DUK_ASSERT_TOP(thr, 1); /* value (error) is at stack top */ + duk_err_augment_error_throw(thr); /* in yielder's context */ } #endif #if defined(DUK_USE_DEBUG) if (is_error) { - DUK_DDD(DUK_DDDPRINT("YIELD ERROR: value=%!T", - (duk_tval *) duk_get_tval(thr, 0))); + DUK_DDD(DUK_DDDPRINT("YIELD ERROR: value=%!T", (duk_tval *) duk_get_tval(thr, 0))); } else { - DUK_DDD(DUK_DDDPRINT("YIELD NORMAL: value=%!T", - (duk_tval *) duk_get_tval(thr, 0))); + DUK_DDD(DUK_DDDPRINT("YIELD NORMAL: value=%!T", (duk_tval *) duk_get_tval(thr, 0))); } #endif @@ -303,17 +301,17 @@ /* lj value1: value */ DUK_ASSERT(thr->valstack_bottom < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom0); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom0); /* side effects */ DUK_TVAL_CHKFAST_INPLACE_SLOW(&thr->heap->lj.value1); thr->heap->lj.iserror = is_error; - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ - duk_err_longjmp(thr); /* execution resumes in bytecode executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ + duk_err_longjmp(thr); /* execution resumes in bytecode executor */ DUK_UNREACHABLE(); /* Never here, fall through to error (from compiler point of view). */ - state_error: +state_error: DUK_DCERROR_TYPE_INVALID_STATE(thr); } #endif
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_dblunion.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_dblunion.h
Changed
@@ -66,7 +66,7 @@ duk_uint16_t us4; duk_uint8_t uc8; #if defined(DUK_USE_PACKED_TVAL) - void *vp2; /* used by packed duk_tval, assumes sizeof(void *) == 4 */ + void *vp2; /* used by packed duk_tval, assumes sizeof(void *) == 4 */ #endif }; @@ -78,64 +78,64 @@ #if defined(DUK_USE_DOUBLE_LE) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 +#define DUK_DBL_IDX_ULL0 0 #endif -#define DUK_DBL_IDX_UI0 1 -#define DUK_DBL_IDX_UI1 0 -#define DUK_DBL_IDX_US0 3 -#define DUK_DBL_IDX_US1 2 -#define DUK_DBL_IDX_US2 1 -#define DUK_DBL_IDX_US3 0 -#define DUK_DBL_IDX_UC0 7 -#define DUK_DBL_IDX_UC1 6 -#define DUK_DBL_IDX_UC2 5 -#define DUK_DBL_IDX_UC3 4 -#define DUK_DBL_IDX_UC4 3 -#define DUK_DBL_IDX_UC5 2 -#define DUK_DBL_IDX_UC6 1 -#define DUK_DBL_IDX_UC7 0 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 1 +#define DUK_DBL_IDX_UI1 0 +#define DUK_DBL_IDX_US0 3 +#define DUK_DBL_IDX_US1 2 +#define DUK_DBL_IDX_US2 1 +#define DUK_DBL_IDX_US3 0 +#define DUK_DBL_IDX_UC0 7 +#define DUK_DBL_IDX_UC1 6 +#define DUK_DBL_IDX_UC2 5 +#define DUK_DBL_IDX_UC3 4 +#define DUK_DBL_IDX_UC4 3 +#define DUK_DBL_IDX_UC5 2 +#define DUK_DBL_IDX_UC6 1 +#define DUK_DBL_IDX_UC7 0 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #elif defined(DUK_USE_DOUBLE_BE) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 +#define DUK_DBL_IDX_ULL0 0 #endif -#define DUK_DBL_IDX_UI0 0 -#define DUK_DBL_IDX_UI1 1 -#define DUK_DBL_IDX_US0 0 -#define DUK_DBL_IDX_US1 1 -#define DUK_DBL_IDX_US2 2 -#define DUK_DBL_IDX_US3 3 -#define DUK_DBL_IDX_UC0 0 -#define DUK_DBL_IDX_UC1 1 -#define DUK_DBL_IDX_UC2 2 -#define DUK_DBL_IDX_UC3 3 -#define DUK_DBL_IDX_UC4 4 -#define DUK_DBL_IDX_UC5 5 -#define DUK_DBL_IDX_UC6 6 -#define DUK_DBL_IDX_UC7 7 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 0 +#define DUK_DBL_IDX_UI1 1 +#define DUK_DBL_IDX_US0 0 +#define DUK_DBL_IDX_US1 1 +#define DUK_DBL_IDX_US2 2 +#define DUK_DBL_IDX_US3 3 +#define DUK_DBL_IDX_UC0 0 +#define DUK_DBL_IDX_UC1 1 +#define DUK_DBL_IDX_UC2 2 +#define DUK_DBL_IDX_UC3 3 +#define DUK_DBL_IDX_UC4 4 +#define DUK_DBL_IDX_UC5 5 +#define DUK_DBL_IDX_UC6 6 +#define DUK_DBL_IDX_UC7 7 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #elif defined(DUK_USE_DOUBLE_ME) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */ +#define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */ #endif -#define DUK_DBL_IDX_UI0 0 -#define DUK_DBL_IDX_UI1 1 -#define DUK_DBL_IDX_US0 1 -#define DUK_DBL_IDX_US1 0 -#define DUK_DBL_IDX_US2 3 -#define DUK_DBL_IDX_US3 2 -#define DUK_DBL_IDX_UC0 3 -#define DUK_DBL_IDX_UC1 2 -#define DUK_DBL_IDX_UC2 1 -#define DUK_DBL_IDX_UC3 0 -#define DUK_DBL_IDX_UC4 7 -#define DUK_DBL_IDX_UC5 6 -#define DUK_DBL_IDX_UC6 5 -#define DUK_DBL_IDX_UC7 4 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 0 +#define DUK_DBL_IDX_UI1 1 +#define DUK_DBL_IDX_US0 1 +#define DUK_DBL_IDX_US1 0 +#define DUK_DBL_IDX_US2 3 +#define DUK_DBL_IDX_US3 2 +#define DUK_DBL_IDX_UC0 3 +#define DUK_DBL_IDX_UC1 2 +#define DUK_DBL_IDX_UC2 1 +#define DUK_DBL_IDX_UC3 0 +#define DUK_DBL_IDX_UC4 7 +#define DUK_DBL_IDX_UC5 6 +#define DUK_DBL_IDX_UC6 5 +#define DUK_DBL_IDX_UC7 4 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #else #error internal error #endif @@ -145,57 +145,63 @@ * by duk_numconv.c and duk_tval.h. */ -#define DUK_DBLUNION_SET_DOUBLE(u,v) do { \ +#define DUK_DBLUNION_SET_DOUBLE(u, v) \ + do { \ (u)->d = (v); \ } while (0) -#define DUK_DBLUNION_SET_HIGH32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) (v); \ } while (0) #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = (duk_uint64_t) (v); \ } while (0) #else -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = ((duk_uint64_t) (v)) << 32; \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) (v); \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) 0; \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ -#define DUK_DBLUNION_SET_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_LOW32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d) -#define DUK_DBLUNION_GET_HIGH32(u) ((u)->uiDUK_DBL_IDX_UI0) -#define DUK_DBLUNION_GET_LOW32(u) ((u)->uiDUK_DBL_IDX_UI1) +#define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d) +#define DUK_DBLUNION_GET_HIGH32(u) ((u)->uiDUK_DBL_IDX_UI0) +#define DUK_DBLUNION_GET_LOW32(u) ((u)->uiDUK_DBL_IDX_UI1) #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_SET_UINT64(u,v) do { \ +#define DUK_DBLUNION_SET_UINT64(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) ((v) >> 32); \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_UINT64(u) \ - ((((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI0) << 32) | \ - ((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI1)) +#define DUK_DBLUNION_GET_UINT64(u) ((((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI1)) #else -#define DUK_DBLUNION_SET_UINT64(u,v) do { \ +#define DUK_DBLUNION_SET_UINT64(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = (duk_uint64_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_UINT64(u) ((u)->ullDUK_DBL_IDX_ULL0) +#define DUK_DBLUNION_GET_UINT64(u) ((u)->ullDUK_DBL_IDX_ULL0) #endif -#define DUK_DBLUNION_SET_INT64(u,v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v)) -#define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u))) -#endif /* DUK_USE_64BIT_OPS */ +#define DUK_DBLUNION_SET_INT64(u, v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v)) +#define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u))) +#endif /* DUK_USE_64BIT_OPS */ /* * Double NaN manipulation macros related to NaN normalization needed when @@ -226,102 +232,85 @@ #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) /* Macros for 64-bit ops + mixed endian doubles. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = DUK_U64_CONSTANT(0x000000007ff80000); \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x000000007ff00000)) == DUK_U64_CONSTANT(0x000000007ff00000)) && \ ((((u)->ullDUK_DBL_IDX_ULL0) & DUK_U64_CONSTANT(0xffffffff000fffff)) != 0)) -#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff80000)) +#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff80000)) #define DUK__DBLUNION_IS_ANYINF(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0xffffffff7fffffff)) == DUK_U64_CONSTANT(0x000000007ff00000)) -#define DUK__DBLUNION_IS_POSINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff00000)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x00000000fff00000)) +#define DUK__DBLUNION_IS_POSINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff00000)) +#define DUK__DBLUNION_IS_NEGINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x00000000fff00000)) #define DUK__DBLUNION_IS_ANYZERO(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0xffffffff7fffffff)) == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000080000000)) +#define DUK__DBLUNION_IS_POSZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) +#define DUK__DBLUNION_IS_NEGZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000080000000)) #else /* Macros for 64-bit ops + big/little endian doubles. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = DUK_U64_CONSTANT(0x7ff8000000000000); \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7ff0000000000000)) == DUK_U64_CONSTANT(0x7ff0000000000000)) && \ ((((u)->ullDUK_DBL_IDX_ULL0) & DUK_U64_CONSTANT(0x000fffffffffffff)) != 0)) -#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff8000000000000)) +#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff8000000000000)) #define DUK__DBLUNION_IS_ANYINF(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7fffffffffffffff)) == DUK_U64_CONSTANT(0x7ff0000000000000)) -#define DUK__DBLUNION_IS_POSINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff0000000000000)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0xfff0000000000000)) +#define DUK__DBLUNION_IS_POSINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff0000000000000)) +#define DUK__DBLUNION_IS_NEGINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0xfff0000000000000)) #define DUK__DBLUNION_IS_ANYZERO(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7fffffffffffffff)) == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x8000000000000000)) +#define DUK__DBLUNION_IS_POSZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) +#define DUK__DBLUNION_IS_NEGZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x8000000000000000)) #endif -#else /* DUK_USE_64BIT_OPS */ +#else /* DUK_USE_64BIT_OPS */ /* Macros for no 64-bit ops, any endianness. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) 0x7ff80000UL; \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) 0x00000000UL; \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->uiDUK_DBL_IDX_UI0 & 0x7ff00000UL) == 0x7ff00000UL) && \ - (((u)->uiDUK_DBL_IDX_UI0 & 0x000fffffUL) != 0 || \ - (u)->uiDUK_DBL_IDX_UI1 != 0)) + (((u)->uiDUK_DBL_IDX_UI0 & 0x000fffffUL) != 0 || (u)->uiDUK_DBL_IDX_UI1 != 0)) #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff80000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) + (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff80000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) #define DUK__DBLUNION_IS_ANYINF(u) \ - ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x7ff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_POSINF(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0xfff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) + ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x7ff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_POSINF(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_NEGINF(u) (((u)->uiDUK_DBL_IDX_UI0 == 0xfff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) #define DUK__DBLUNION_IS_ANYZERO(u) \ - ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x00000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x00000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x80000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#endif /* DUK_USE_64BIT_OPS */ + ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x00000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_POSZERO(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x00000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_NEGZERO(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x80000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#endif /* DUK_USE_64BIT_OPS */ -#define DUK__DBLUNION_SET_NAN_NOTFULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_NOTFULL(u) \ + do { \ (u)->usDUK_DBL_IDX_US0 = 0x7ff8UL; \ } while (0) #define DUK__DBLUNION_IS_NAN_NOTFULL(u) \ /* E == 0x7ff, topmost four bits of F != 0 => assume NaN */ \ - ((((u)->usDUK_DBL_IDX_US0 & 0x7ff0UL) == 0x7ff0UL) && \ - (((u)->usDUK_DBL_IDX_US0 & 0x000fUL) != 0x0000UL)) + ((((u)->usDUK_DBL_IDX_US0 & 0x7ff0UL) == 0x7ff0UL) && (((u)->usDUK_DBL_IDX_US0 & 0x000fUL) != 0x0000UL)) #define DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL(u) \ /* E == 0x7ff, F == 8 => normalized NaN */ \ ((u)->usDUK_DBL_IDX_US0 == 0x7ff8UL) -#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) do { \ +#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) \ + do { \ if (DUK__DBLUNION_IS_NAN_FULL((u))) { \ DUK__DBLUNION_SET_NAN_FULL((u)); \ } \ } while (0) -#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) do { \ +#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) \ + do { \ /* Check must be full. */ \ if (DUK__DBLUNION_IS_NAN_FULL((u))) { \ DUK__DBLUNION_SET_NAN_NOTFULL((u)); \ @@ -335,29 +324,30 @@ */ #if defined(DUK_USE_PACKED_TVAL) -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u)) -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u)) -#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d)) +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u)) +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u)) +#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d)) #if 0 -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u)) -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u)) -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u)) -#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d)) +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u)) +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u)) +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u)) +#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d)) #endif #define DUK_DBLUNION_IS_NORMALIZED(u) \ - (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \ - DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */ -#else /* DUK_USE_PACKED_TVAL */ -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */ -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ -#define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */ -#define DUK_DBLUNION_SET_NAN(u) do { \ + (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \ + DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */ +#else /* DUK_USE_PACKED_TVAL */ +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */ +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ +#define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */ +#define DUK_DBLUNION_SET_NAN(u) \ + do { \ /* in non-packed representation we don't care about which NaN is used */ \ (u)->d = DUK_DOUBLE_NAN; \ } while (0) -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ #define DUK_DBLUNION_IS_ANYINF(u) DUK__DBLUNION_IS_ANYINF((u)) #define DUK_DBLUNION_IS_POSINF(u) DUK__DBLUNION_IS_POSINF((u)) @@ -370,7 +360,8 @@ /* XXX: native 64-bit byteswaps when available */ /* 64-bit byteswap, same operation independent of target endianness. */ -#define DUK_DBLUNION_BSWAP64(u) do { \ +#define DUK_DBLUNION_BSWAP64(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -384,7 +375,8 @@ * order. For a big endian target this is a no-op. */ #if defined(DUK_USE_DOUBLE_LE) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { \ +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -394,7 +386,8 @@ (u)->ui1 = duk__bswaptmp1; \ } while (0) #elif defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { \ +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -404,7 +397,9 @@ (u)->ui1 = duk__bswaptmp2; \ } while (0) #elif defined(DUK_USE_DOUBLE_BE) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { } while (0) +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ + } while (0) #else #error internal error, double endianness insane #endif @@ -421,4 +416,4 @@ #define DUK_DBLUNION_GET_SIGNBIT(u) (((u)->uiDUK_DBL_IDX_UI0 >> 31U)) #endif -#endif /* DUK_DBLUNION_H_INCLUDED */ +#endif /* DUK_DBLUNION_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_debug.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_debug.h
Changed
@@ -28,19 +28,25 @@ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) #define DUK_D(x) x #else -#define DUK_D(x) do { } while (0) /* omit */ +#define DUK_D(x) \ + do { \ + } while (0) /* omit */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) #define DUK_DD(x) x #else -#define DUK_DD(x) do { } while (0) /* omit */ +#define DUK_DD(x) \ + do { \ + } while (0) /* omit */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) #define DUK_DDD(x) x #else -#define DUK_DDD(x) do { } while (0) /* omit */ +#define DUK_DDD(x) \ + do { \ + } while (0) /* omit */ #endif /* @@ -52,35 +58,35 @@ /* Note: combining __FILE__, __LINE__, and __func__ into fmt would be * possible compile time, but waste some space with shared function names. */ -#define DUK__DEBUG_LOG(lev,...) duk_debug_log((duk_int_t) (lev), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, DUK_FUNC_MACRO, __VA_ARGS__); +#define DUK__DEBUG_LOG(lev, ...) \ + duk_debug_log((duk_int_t) (lev), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, DUK_FUNC_MACRO, __VA_ARGS__); #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) -#define DUK_DPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DEBUG, __VA_ARGS__) +#define DUK_DPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DEBUG, __VA_ARGS__) #else #define DUK_DPRINT(...) #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) -#define DUK_DDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDEBUG, __VA_ARGS__) +#define DUK_DDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDEBUG, __VA_ARGS__) #else #define DUK_DDPRINT(...) #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK_DDDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDDEBUG, __VA_ARGS__) +#define DUK_DDDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDDEBUG, __VA_ARGS__) #else #define DUK_DDDPRINT(...) #endif -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ -#define DUK__DEBUG_STASH(lev) \ +#define DUK__DEBUG_STASH(lev) \ (void) DUK_SNPRINTF(duk_debug_file_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FILE_MACRO), \ - (void) (duk_debug_file_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ - (void) (duk_debug_line_stash = (duk_int_t) DUK_LINE_MACRO), \ - (void) DUK_SNPRINTF(duk_debug_func_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FUNC_MACRO), \ - (void) (duk_debug_func_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ - (void) (duk_debug_level_stash = (lev)) + (void) (duk_debug_file_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ + (void) (duk_debug_line_stash = (duk_int_t) DUK_LINE_MACRO), \ + (void) DUK_SNPRINTF(duk_debug_func_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FUNC_MACRO), \ + (void) (duk_debug_func_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), (void) (duk_debug_level_stash = (lev)) /* Without variadic macros resort to comma expression trickery to handle debug * prints. This generates a lot of harmless warnings. These hacks are not @@ -89,34 +95,40 @@ */ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) -#define DUK_DPRINT DUK__DEBUG_STASH(DUK_LEVEL_DEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DPRINT DUK__DEBUG_STASH(DUK_LEVEL_DEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ +#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) -#define DUK_DDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DDPRINT 0 && /* args */ +#define DUK_DDPRINT 0 && /* args */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK_DDDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDDEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DDDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDDEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DDDPRINT 0 && /* args */ +#define DUK_DDDPRINT 0 && /* args */ #endif -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#else /* DUK_USE_DEBUG */ +#else /* DUK_USE_DEBUG */ /* * Exposed debug macros: debugging disabled */ -#define DUK_D(x) do { } while (0) /* omit */ -#define DUK_DD(x) do { } while (0) /* omit */ -#define DUK_DDD(x) do { } while (0) /* omit */ +#define DUK_D(x) \ + do { \ + } while (0) /* omit */ +#define DUK_DD(x) \ + do { \ + } while (0) /* omit */ +#define DUK_DDD(x) \ + do { \ + } while (0) /* omit */ #if defined(DUK_USE_VARIADIC_MACROS) @@ -124,15 +136,15 @@ #define DUK_DDPRINT(...) #define DUK_DDDPRINT(...) -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ -#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ -#define DUK_DDPRINT 0 && /* args */ -#define DUK_DDDPRINT 0 && /* args */ +#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ +#define DUK_DDPRINT 0 && /* args */ +#define DUK_DDDPRINT 0 && /* args */ -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Structs @@ -153,16 +165,16 @@ #if defined(DUK_USE_DEBUG) DUK_INTERNAL_DECL duk_int_t duk_debug_vsnprintf(char *str, duk_size_t size, const char *format, va_list ap); -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL duk_int_t duk_debug_snprintf(char *str, duk_size_t size, const char *format, ...); #endif DUK_INTERNAL_DECL void duk_debug_format_funcptr(char *buf, duk_size_t buf_size, duk_uint8_t *fptr, duk_size_t fptr_size); #if defined(DUK_USE_VARIADIC_MACROS) DUK_INTERNAL_DECL void duk_debug_log(duk_int_t level, const char *file, duk_int_t line, const char *func, const char *fmt, ...); -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ /* parameter passing, not thread safe */ -#define DUK_DEBUG_STASH_SIZE 128 +#define DUK_DEBUG_STASH_SIZE 128 #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL char duk_debug_file_stashDUK_DEBUG_STASH_SIZE; DUK_INTERNAL_DECL duk_int_t duk_debug_line_stash; @@ -170,7 +182,7 @@ DUK_INTERNAL_DECL duk_int_t duk_debug_level_stash; #endif DUK_INTERNAL_DECL void duk_debug_log(const char *fmt, ...); -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ DUK_INTERNAL_DECL void duk_fb_put_bytes(duk_fixedbuffer *fb, const duk_uint8_t *buffer, duk_size_t length); DUK_INTERNAL_DECL void duk_fb_put_byte(duk_fixedbuffer *fb, duk_uint8_t x); @@ -179,6 +191,6 @@ DUK_INTERNAL_DECL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size); DUK_INTERNAL_DECL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb); -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ -#endif /* DUK_DEBUG_H_INCLUDED */ +#endif /* DUK_DEBUG_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_debug_fixedbuffer.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_debug_fixedbuffer.c
Changed
@@ -56,7 +56,7 @@ } DUK_INTERNAL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size) { - char buf64+1; + char buf64 + 1; duk_debug_format_funcptr(buf, sizeof(buf), fptr, fptr_size); bufsizeof(buf) - 1 = (char) 0; duk_fb_put_cstring(fb, buf); @@ -66,4 +66,4 @@ return (fb->offset >= fb->length); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_debug_macros.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_debug_macros.c
Changed
@@ -18,7 +18,7 @@ #error debugging enabled (DUK_USE_DEBUG) but DUK_USE_DEBUG_WRITE not defined #endif -#define DUK__DEBUG_BUFSIZE DUK_USE_DEBUG_BUFSIZE +#define DUK__DEBUG_BUFSIZE DUK_USE_DEBUG_BUFSIZE #if defined(DUK_USE_VARIADIC_MACROS) @@ -46,7 +46,7 @@ va_end(ap); } -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ DUK_INTERNAL char duk_debug_file_stashDUK_DEBUG_STASH_SIZE; DUK_INTERNAL duk_int_t duk_debug_line_stash; @@ -77,12 +77,12 @@ va_end(ap); } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#else /* DUK_USE_DEBUG */ +#else /* DUK_USE_DEBUG */ /* * Debugging disabled */ -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_debug_vsnprintf.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_debug_vsnprintf.c
Changed
@@ -63,58 +63,58 @@ /* list of conversion specifiers that terminate a format tag; * this is unfortunately guesswork. */ -#define DUK__ALLOWED_STANDARD_SPECIFIERS "diouxXeEfFgGaAcsCSpnm" +#define DUK__ALLOWED_STANDARD_SPECIFIERS "diouxXeEfFgGaAcsCSpnm" /* maximum length of standard format tag that we support */ -#define DUK__MAX_FORMAT_TAG_LENGTH 32 +#define DUK__MAX_FORMAT_TAG_LENGTH 32 /* heapobj recursion depth when deep printing is selected */ -#define DUK__DEEP_DEPTH_LIMIT 8 +#define DUK__DEEP_DEPTH_LIMIT 8 /* maximum recursion depth for loop detection stacks */ -#define DUK__LOOP_STACK_DEPTH 256 +#define DUK__LOOP_STACK_DEPTH 256 /* must match bytecode defines now; build autogenerate? */ DUK_LOCAL const char * const duk__bc_optab256 = { - "LDREG", "STREG", "JUMP", "LDCONST", "LDINT", "LDINTX", "LDTHIS", "LDUNDEF", - "LDNULL", "LDTRUE", "LDFALSE", "GETVAR", "BNOT", "LNOT", "UNM", "UNP", - "EQ_RR", "EQ_CR", "EQ_RC", "EQ_CC", "NEQ_RR", "NEQ_CR", "NEQ_RC", "NEQ_CC", - "SEQ_RR", "SEQ_CR", "SEQ_RC", "SEQ_CC", "SNEQ_RR", "SNEQ_CR", "SNEQ_RC", "SNEQ_CC", - - "GT_RR", "GT_CR", "GT_RC", "GT_CC", "GE_RR", "GE_CR", "GE_RC", "GE_CC", - "LT_RR", "LT_CR", "LT_RC", "LT_CC", "LE_RR", "LE_CR", "LE_RC", "LE_CC", - "IFTRUE_R", "IFTRUE_C", "IFFALSE_R", "IFFALSE_C", "ADD_RR", "ADD_CR", "ADD_RC", "ADD_CC", - "SUB_RR", "SUB_CR", "SUB_RC", "SUB_CC", "MUL_RR", "MUL_CR", "MUL_RC", "MUL_CC", - - "DIV_RR", "DIV_CR", "DIV_RC", "DIV_CC", "MOD_RR", "MOD_CR", "MOD_RC", "MOD_CC", - "EXP_RR", "EXP_CR", "EXP_RC", "EXP_CC", "BAND_RR", "BAND_CR", "BAND_RC", "BAND_CC", - "BOR_RR", "BOR_CR", "BOR_RC", "BOR_CC", "BXOR_RR", "BXOR_CR", "BXOR_RC", "BXOR_CC", - "BASL_RR", "BASL_CR", "BASL_RC", "BASL_CC", "BLSR_RR", "BLSR_CR", "BLSR_RC", "BLSR_CC", - - "BASR_RR", "BASR_CR", "BASR_RC", "BASR_CC", "INSTOF_RR", "INSTOF_CR", "INSTOF_RC", "INSTOF_CC", - "IN_RR", "IN_CR", "IN_RC", "IN_CC", "GETPROP_RR", "GETPROP_CR", "GETPROP_RC", "GETPROP_CC", - "PUTPROP_RR", "PUTPROP_CR", "PUTPROP_RC", "PUTPROP_CC", "DELPROP_RR", "DELPROP_CR", "DELPROP_RC", "DELPROP_CC", - "PREINCR", "PREDECR", "POSTINCR", "POSTDECR", "PREINCV", "PREDECV", "POSTINCV", "POSTDECV", - - "PREINCP_RR", "PREINCP_CR", "PREINCP_RC", "PREINCP_CC", "PREDECP_RR", "PREDECP_CR", "PREDECP_RC", "PREDECP_CC", + "LDREG", "STREG", "JUMP", "LDCONST", "LDINT", "LDINTX", "LDTHIS", "LDUNDEF", + "LDNULL", "LDTRUE", "LDFALSE", "GETVAR", "BNOT", "LNOT", "UNM", "UNP", + "EQ_RR", "EQ_CR", "EQ_RC", "EQ_CC", "NEQ_RR", "NEQ_CR", "NEQ_RC", "NEQ_CC", + "SEQ_RR", "SEQ_CR", "SEQ_RC", "SEQ_CC", "SNEQ_RR", "SNEQ_CR", "SNEQ_RC", "SNEQ_CC", + + "GT_RR", "GT_CR", "GT_RC", "GT_CC", "GE_RR", "GE_CR", "GE_RC", "GE_CC", + "LT_RR", "LT_CR", "LT_RC", "LT_CC", "LE_RR", "LE_CR", "LE_RC", "LE_CC", + "IFTRUE_R", "IFTRUE_C", "IFFALSE_R", "IFFALSE_C", "ADD_RR", "ADD_CR", "ADD_RC", "ADD_CC", + "SUB_RR", "SUB_CR", "SUB_RC", "SUB_CC", "MUL_RR", "MUL_CR", "MUL_RC", "MUL_CC", + + "DIV_RR", "DIV_CR", "DIV_RC", "DIV_CC", "MOD_RR", "MOD_CR", "MOD_RC", "MOD_CC", + "EXP_RR", "EXP_CR", "EXP_RC", "EXP_CC", "BAND_RR", "BAND_CR", "BAND_RC", "BAND_CC", + "BOR_RR", "BOR_CR", "BOR_RC", "BOR_CC", "BXOR_RR", "BXOR_CR", "BXOR_RC", "BXOR_CC", + "BASL_RR", "BASL_CR", "BASL_RC", "BASL_CC", "BLSR_RR", "BLSR_CR", "BLSR_RC", "BLSR_CC", + + "BASR_RR", "BASR_CR", "BASR_RC", "BASR_CC", "INSTOF_RR", "INSTOF_CR", "INSTOF_RC", "INSTOF_CC", + "IN_RR", "IN_CR", "IN_RC", "IN_CC", "GETPROP_RR", "GETPROP_CR", "GETPROP_RC", "GETPROP_CC", + "PUTPROP_RR", "PUTPROP_CR", "PUTPROP_RC", "PUTPROP_CC", "DELPROP_RR", "DELPROP_CR", "DELPROP_RC", "DELPROP_CC", + "PREINCR", "PREDECR", "POSTINCR", "POSTDECR", "PREINCV", "PREDECV", "POSTINCV", "POSTDECV", + + "PREINCP_RR", "PREINCP_CR", "PREINCP_RC", "PREINCP_CC", "PREDECP_RR", "PREDECP_CR", "PREDECP_RC", "PREDECP_CC", "POSTINCP_RR", "POSTINCP_CR", "POSTINCP_RC", "POSTINCP_CC", "POSTDECP_RR", "POSTDECP_CR", "POSTDECP_RC", "POSTDECP_CC", - "DECLVAR_RR", "DECLVAR_CR", "DECLVAR_RC", "DECLVAR_CC", "REGEXP_RR", "REGEXP_RC", "REGEXP_CR", "REGEXP_CC", - "CLOSURE", "TYPEOF", "TYPEOFID", "PUTVAR", "DELVAR", "RETREG", "RETUNDEF", "RETCONST", - - "RETCONSTN", "LABEL", "ENDLABEL", "BREAK", "CONTINUE", "TRYCATCH", "ENDTRY", "ENDCATCH", - "ENDFIN", "THROW", "INVLHS", "CSREG", "CSVAR_RR", "CSVAR_CR", "CSVAR_RC", "CSVAR_CC", - "CALL0", "CALL1", "CALL2", "CALL3", "CALL4", "CALL5", "CALL6", "CALL7", - "CALL8", "CALL9", "CALL10", "CALL11", "CALL12", "CALL13", "CALL14", "CALL15", - - "NEWOBJ", "NEWARR", "MPUTOBJ", "MPUTOBJI", "INITSET", "INITGET", "MPUTARR", "MPUTARRI", - "SETALEN", "INITENUM", "NEXTENUM", "NEWTARGET", "DEBUGGER", "NOP", "INVALID", "UNUSED207", - "GETPROPC_RR", "GETPROPC_CR", "GETPROPC_RC", "GETPROPC_CC", "UNUSED212", "UNUSED213", "UNUSED214", "UNUSED215", - "UNUSED216", "UNUSED217", "UNUSED218", "UNUSED219", "UNUSED220", "UNUSED221", "UNUSED222", "UNUSED223", - - "UNUSED224", "UNUSED225", "UNUSED226", "UNUSED227", "UNUSED228", "UNUSED229", "UNUSED230", "UNUSED231", - "UNUSED232", "UNUSED233", "UNUSED234", "UNUSED235", "UNUSED236", "UNUSED237", "UNUSED238", "UNUSED239", - "UNUSED240", "UNUSED241", "UNUSED242", "UNUSED243", "UNUSED244", "UNUSED245", "UNUSED246", "UNUSED247", - "UNUSED248", "UNUSED249", "UNUSED250", "UNUSED251", "UNUSED252", "UNUSED253", "UNUSED254", "UNUSED255" + "DECLVAR_RR", "DECLVAR_CR", "DECLVAR_RC", "DECLVAR_CC", "REGEXP_RR", "REGEXP_RC", "REGEXP_CR", "REGEXP_CC", + "CLOSURE", "TYPEOF", "TYPEOFID", "PUTVAR", "DELVAR", "RETREG", "RETUNDEF", "RETCONST", + + "RETCONSTN", "LABEL", "ENDLABEL", "BREAK", "CONTINUE", "TRYCATCH", "ENDTRY", "ENDCATCH", + "ENDFIN", "THROW", "INVLHS", "CSREG", "CSVAR_RR", "CSVAR_CR", "CSVAR_RC", "CSVAR_CC", + "CALL0", "CALL1", "CALL2", "CALL3", "CALL4", "CALL5", "CALL6", "CALL7", + "CALL8", "CALL9", "CALL10", "CALL11", "CALL12", "CALL13", "CALL14", "CALL15", + + "NEWOBJ", "NEWARR", "MPUTOBJ", "MPUTOBJI", "INITSET", "INITGET", "MPUTARR", "MPUTARRI", + "SETALEN", "INITENUM", "NEXTENUM", "NEWTARGET", "DEBUGGER", "NOP", "INVALID", "UNUSED207", + "GETPROPC_RR", "GETPROPC_CR", "GETPROPC_RC", "GETPROPC_CC", "UNUSED212", "UNUSED213", "UNUSED214", "UNUSED215", + "UNUSED216", "UNUSED217", "UNUSED218", "UNUSED219", "UNUSED220", "UNUSED221", "UNUSED222", "UNUSED223", + + "UNUSED224", "UNUSED225", "UNUSED226", "UNUSED227", "UNUSED228", "UNUSED229", "UNUSED230", "UNUSED231", + "UNUSED232", "UNUSED233", "UNUSED234", "UNUSED235", "UNUSED236", "UNUSED237", "UNUSED238", "UNUSED239", + "UNUSED240", "UNUSED241", "UNUSED242", "UNUSED243", "UNUSED244", "UNUSED245", "UNUSED246", "UNUSED247", + "UNUSED248", "UNUSED249", "UNUSED250", "UNUSED251", "UNUSED252", "UNUSED253", "UNUSED254", "UNUSED255" }; typedef struct duk__dprint_state duk__dprint_state; @@ -164,14 +164,15 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*h); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)h)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) h)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } -#if defined(DUK_USE_REFERENCE_COUNTING) /* currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP */ +#if defined(DUK_USE_REFERENCE_COUNTING) /* currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP */ if (st->heavy) { - duk_fb_sprintf(fb, "h_next=%p,h_prev=%p,h_refcount=%lu,h_flags=%08lx,type=%ld," + duk_fb_sprintf(fb, + "h_next=%p,h_prev=%p,h_refcount=%lu,h_flags=%08lx,type=%ld," "reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (void *) DUK_HEAPHDR_GET_NEXT(NULL, h), (void *) DUK_HEAPHDR_GET_PREV(NULL, h), @@ -185,7 +186,8 @@ } #else if (st->heavy) { - duk_fb_sprintf(fb, "h_next=%p,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_next=%p,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (void *) DUK_HEAPHDR_GET_NEXT(NULL, h), (unsigned long) DUK_HEAPHDR_GET_FLAGS(h), (long) DUK_HEAPHDR_GET_TYPE(h), @@ -212,14 +214,15 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*h); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)h)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) h)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } #if defined(DUK_USE_REFERENCE_COUNTING) if (st->heavy) { - duk_fb_sprintf(fb, "h_refcount=%lu,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_refcount=%lu,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h), (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h), (long) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h), @@ -230,7 +233,8 @@ } #else if (st->heavy) { - duk_fb_sprintf(fb, "h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h), (long) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h), (long) (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h) ? 1 : 0), @@ -301,7 +305,8 @@ #endif } -#define DUK__COMMA() do { \ +#define DUK__COMMA() \ + do { \ if (first) { \ first = 0; \ } else { \ @@ -414,7 +419,8 @@ duk__print_hstring(st, key, 0); duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_COLON); if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(NULL, h, i)) { - duk_fb_sprintf(fb, "get:%p,set:%p", + duk_fb_sprintf(fb, + "get:%p,set:%p", (void *) DUK_HOBJECT_E_GET_VALUE(NULL, h, i).a.get, (void *) DUK_HOBJECT_E_GET_VALUE(NULL, h, i).a.set); } else { @@ -428,158 +434,238 @@ } if (st->internal) { if (DUK_HOBJECT_IS_ARRAY(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__array:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__array:true"); } if (DUK_HOBJECT_HAS_EXTENSIBLE(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__extensible:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__extensible:true"); } if (DUK_HOBJECT_HAS_CONSTRUCTABLE(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__constructable:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__constructable:true"); } if (DUK_HOBJECT_HAS_BOUNDFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__boundfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__boundfunc:true"); } if (DUK_HOBJECT_HAS_COMPFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__compfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__compfunc:true"); } if (DUK_HOBJECT_HAS_NATFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__natfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__natfunc:true"); } if (DUK_HOBJECT_HAS_BUFOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__bufobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__bufobj:true"); } if (DUK_HOBJECT_IS_THREAD(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__thread:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__thread:true"); } if (DUK_HOBJECT_HAS_ARRAY_PART(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__array_part:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__array_part:true"); } if (DUK_HOBJECT_HAS_STRICT(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__strict:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__strict:true"); } if (DUK_HOBJECT_HAS_NOTAIL(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__notail:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__notail:true"); } if (DUK_HOBJECT_HAS_NEWENV(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__newenv:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__newenv:true"); } if (DUK_HOBJECT_HAS_NAMEBINDING(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__namebinding:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__namebinding:true"); } if (DUK_HOBJECT_HAS_CREATEARGS(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__createargs:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__createargs:true"); } if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_array:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_array:true"); } if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_stringobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_stringobj:true"); } if (DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_arguments:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_arguments:true"); } if (DUK_HOBJECT_IS_BUFOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_bufobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_bufobj:true"); } if (DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_proxyobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_proxyobj:true"); } } if (st->internal && DUK_HOBJECT_IS_ARRAY(h)) { duk_harray *a = (duk_harray *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__length:%ld", (long) a->length); - DUK__COMMA(); duk_fb_sprintf(fb, "__length_nonwritable:%ld", (long) a->length_nonwritable); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length:%ld", (long) a->length); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length_nonwritable:%ld", (long) a->length_nonwritable); } else if (st->internal && DUK_HOBJECT_IS_COMPFUNC(h)) { duk_hcompfunc *f = (duk_hcompfunc *) h; - DUK__COMMA(); duk_fb_put_cstring(fb, "__data:"); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__data:"); duk__print_hbuffer(st, (duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA(NULL, f)); - DUK__COMMA(); duk_fb_put_cstring(fb, "__lexenv:"); duk__print_hobject(st, DUK_HCOMPFUNC_GET_LEXENV(NULL, f)); - DUK__COMMA(); duk_fb_put_cstring(fb, "__varenv:"); duk__print_hobject(st, DUK_HCOMPFUNC_GET_VARENV(NULL, f)); - DUK__COMMA(); duk_fb_sprintf(fb, "__nregs:%ld", (long) f->nregs); - DUK__COMMA(); duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__lexenv:"); + duk__print_hobject(st, DUK_HCOMPFUNC_GET_LEXENV(NULL, f)); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__varenv:"); + duk__print_hobject(st, DUK_HCOMPFUNC_GET_VARENV(NULL, f)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nregs:%ld", (long) f->nregs); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); #if defined(DUK_USE_DEBUGGER_SUPPORT) - DUK__COMMA(); duk_fb_sprintf(fb, "__start_line:%ld", (long) f->start_line); - DUK__COMMA(); duk_fb_sprintf(fb, "__end_line:%ld", (long) f->end_line); + DUK__COMMA(); + duk_fb_sprintf(fb, "__start_line:%ld", (long) f->start_line); + DUK__COMMA(); + duk_fb_sprintf(fb, "__end_line:%ld", (long) f->end_line); #endif - DUK__COMMA(); duk_fb_put_cstring(fb, "__data:"); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__data:"); duk__print_hbuffer(st, (duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA(NULL, f)); } else if (st->internal && DUK_HOBJECT_IS_NATFUNC(h)) { duk_hnatfunc *f = (duk_hnatfunc *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__func:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__func:"); duk_fb_put_funcptr(fb, (duk_uint8_t *) &f->func, sizeof(f->func)); - DUK__COMMA(); duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); - DUK__COMMA(); duk_fb_sprintf(fb, "__magic:%ld", (long) f->magic); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); + DUK__COMMA(); + duk_fb_sprintf(fb, "__magic:%ld", (long) f->magic); } else if (st->internal && DUK_HOBJECT_IS_DECENV(h)) { duk_hdecenv *e = (duk_hdecenv *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__thread:"); duk__print_hobject(st, (duk_hobject *) e->thread); - DUK__COMMA(); duk_fb_sprintf(fb, "__varmap:"); duk__print_hobject(st, (duk_hobject *) e->varmap); - DUK__COMMA(); duk_fb_sprintf(fb, "__regbase_byteoff:%ld", (long) e->regbase_byteoff); + DUK__COMMA(); + duk_fb_sprintf(fb, "__thread:"); + duk__print_hobject(st, (duk_hobject *) e->thread); + DUK__COMMA(); + duk_fb_sprintf(fb, "__varmap:"); + duk__print_hobject(st, (duk_hobject *) e->varmap); + DUK__COMMA(); + duk_fb_sprintf(fb, "__regbase_byteoff:%ld", (long) e->regbase_byteoff); } else if (st->internal && DUK_HOBJECT_IS_OBJENV(h)) { duk_hobjenv *e = (duk_hobjenv *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__target:"); duk__print_hobject(st, (duk_hobject *) e->target); - DUK__COMMA(); duk_fb_sprintf(fb, "__has_this:%ld", (long) e->has_this); + DUK__COMMA(); + duk_fb_sprintf(fb, "__target:"); + duk__print_hobject(st, (duk_hobject *) e->target); + DUK__COMMA(); + duk_fb_sprintf(fb, "__has_this:%ld", (long) e->has_this); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) } else if (st->internal && DUK_HOBJECT_IS_BUFOBJ(h)) { duk_hbufobj *b = (duk_hbufobj *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__buf:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__buf:"); duk__print_hbuffer(st, (duk_hbuffer *) b->buf); - DUK__COMMA(); duk_fb_sprintf(fb, "__buf_prop:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__buf_prop:"); duk__print_hobject(st, (duk_hobject *) b->buf_prop); - DUK__COMMA(); duk_fb_sprintf(fb, "__offset:%ld", (long) b->offset); - DUK__COMMA(); duk_fb_sprintf(fb, "__length:%ld", (long) b->length); - DUK__COMMA(); duk_fb_sprintf(fb, "__shift:%ld", (long) b->shift); - DUK__COMMA(); duk_fb_sprintf(fb, "__elemtype:%ld", (long) b->elem_type); + DUK__COMMA(); + duk_fb_sprintf(fb, "__offset:%ld", (long) b->offset); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length:%ld", (long) b->length); + DUK__COMMA(); + duk_fb_sprintf(fb, "__shift:%ld", (long) b->shift); + DUK__COMMA(); + duk_fb_sprintf(fb, "__elemtype:%ld", (long) b->elem_type); #endif } else if (st->internal && DUK_HOBJECT_IS_PROXY(h)) { duk_hproxy *p = (duk_hproxy *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__target:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__target:"); duk__print_hobject(st, p->target); - DUK__COMMA(); duk_fb_sprintf(fb, "__handler:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__handler:"); duk__print_hobject(st, p->handler); } else if (st->internal && DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__ptr_curr_pc:%p", (void *) t->ptr_curr_pc); - DUK__COMMA(); duk_fb_sprintf(fb, "__heap:%p", (void *) t->heap); - DUK__COMMA(); duk_fb_sprintf(fb, "__strict:%ld", (long) t->strict); - DUK__COMMA(); duk_fb_sprintf(fb, "__state:%ld", (long) t->state); - DUK__COMMA(); duk_fb_sprintf(fb, "__unused1:%ld", (long) t->unused1); - DUK__COMMA(); duk_fb_sprintf(fb, "__unused2:%ld", (long) t->unused2); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack:%p", (void *) t->valstack); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_end:%p/%ld", (void *) t->valstack_end, (long) (t->valstack_end - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_alloc_end:%p/%ld", (void *) t->valstack_alloc_end, (long) (t->valstack_alloc_end - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_bottom:%p/%ld", (void *) t->valstack_bottom, (long) (t->valstack_bottom - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_top:%p/%ld", (void *) t->valstack_top, (long) (t->valstack_top - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_curr:%p", (void *) t->callstack_curr); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_top:%ld", (long) t->callstack_top); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_preventcount:%ld", (long) t->callstack_preventcount); - DUK__COMMA(); duk_fb_sprintf(fb, "__resumer:"); duk__print_hobject(st, (duk_hobject *) t->resumer); - DUK__COMMA(); duk_fb_sprintf(fb, "__compile_ctx:%p", (void *) t->compile_ctx); + DUK__COMMA(); + duk_fb_sprintf(fb, "__ptr_curr_pc:%p", (void *) t->ptr_curr_pc); + DUK__COMMA(); + duk_fb_sprintf(fb, "__heap:%p", (void *) t->heap); + DUK__COMMA(); + duk_fb_sprintf(fb, "__strict:%ld", (long) t->strict); + DUK__COMMA(); + duk_fb_sprintf(fb, "__state:%ld", (long) t->state); + DUK__COMMA(); + duk_fb_sprintf(fb, "__unused1:%ld", (long) t->unused1); + DUK__COMMA(); + duk_fb_sprintf(fb, "__unused2:%ld", (long) t->unused2); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack:%p", (void *) t->valstack); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack_end:%p/%ld", (void *) t->valstack_end, (long) (t->valstack_end - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, + "__valstack_alloc_end:%p/%ld", + (void *) t->valstack_alloc_end, + (long) (t->valstack_alloc_end - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, + "__valstack_bottom:%p/%ld", + (void *) t->valstack_bottom, + (long) (t->valstack_bottom - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack_top:%p/%ld", (void *) t->valstack_top, (long) (t->valstack_top - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_curr:%p", (void *) t->callstack_curr); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_top:%ld", (long) t->callstack_top); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_preventcount:%ld", (long) t->callstack_preventcount); + DUK__COMMA(); + duk_fb_sprintf(fb, "__resumer:"); + duk__print_hobject(st, (duk_hobject *) t->resumer); + DUK__COMMA(); + duk_fb_sprintf(fb, "__compile_ctx:%p", (void *) t->compile_ctx); #if defined(DUK_USE_INTERRUPT_COUNTER) - DUK__COMMA(); duk_fb_sprintf(fb, "__interrupt_counter:%ld", (long) t->interrupt_counter); - DUK__COMMA(); duk_fb_sprintf(fb, "__interrupt_init:%ld", (long) t->interrupt_init); + DUK__COMMA(); + duk_fb_sprintf(fb, "__interrupt_counter:%ld", (long) t->interrupt_counter); + DUK__COMMA(); + duk_fb_sprintf(fb, "__interrupt_init:%ld", (long) t->interrupt_init); #endif /* XXX: print built-ins array? */ - } #if defined(DUK_USE_REFERENCE_COUNTING) if (st->internal) { - DUK__COMMA(); duk_fb_sprintf(fb, "__refcount:%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__refcount:%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h)); } #endif if (st->internal) { - DUK__COMMA(); duk_fb_sprintf(fb, "__class:%ld", (long) DUK_HOBJECT_GET_CLASS_NUMBER(h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__class:%ld", (long) DUK_HOBJECT_GET_CLASS_NUMBER(h)); } - DUK__COMMA(); duk_fb_sprintf(fb, "__heapptr:%p", (void *) h); /* own pointer */ + DUK__COMMA(); + duk_fb_sprintf(fb, "__heapptr:%p", (void *) h); /* own pointer */ /* prototype should be last, for readability */ if (DUK_HOBJECT_GET_PROTOTYPE(NULL, h)) { if (st->follow_proto) { - DUK__COMMA(); duk_fb_put_cstring(fb, "__prototype:"); duk__print_hobject(st, DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__prototype:"); + duk__print_hobject(st, DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); } else { - DUK__COMMA(); duk_fb_sprintf(fb, "__prototype:%p", (void *) DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__prototype:%p", (void *) DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); } } @@ -605,7 +691,7 @@ } #endif - finished: +finished: st->depth--; if (pushed_loopstack) { st->loop_stack_index--; @@ -632,12 +718,14 @@ if (DUK_HBUFFER_HAS_DYNAMIC(h)) { if (DUK_HBUFFER_HAS_EXTERNAL(h)) { duk_hbuffer_external *g = (duk_hbuffer_external *) h; - duk_fb_sprintf(fb, "buffer:external:%p:%ld", + duk_fb_sprintf(fb, + "buffer:external:%p:%ld", (void *) DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(NULL, g), (long) DUK_HBUFFER_EXTERNAL_GET_SIZE(g)); } else { duk_hbuffer_dynamic *g = (duk_hbuffer_dynamic *) h; - duk_fb_sprintf(fb, "buffer:dynamic:%p:%ld", + duk_fb_sprintf(fb, + "buffer:dynamic:%p:%ld", (void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(NULL, g), (long) DUK_HBUFFER_DYNAMIC_GET_SIZE(g)); } @@ -710,7 +798,7 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*tv); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)tv)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) tv)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } @@ -793,17 +881,22 @@ /* XXX: option to fix opcode length so it lines up nicely */ if (op == DUK_OP_JUMP) { - duk_int_t diff1 = (duk_int_t) (DUK_DEC_ABC(ins) - DUK_BC_JUMP_BIAS); /* from next pc */ - duk_int_t diff2 = diff1 + 1; /* from curr pc */ - - duk_fb_sprintf(fb, "%s %ld (to pc%c%ld)", - (const char *) op_name, (long) diff1, - (int) (diff2 >= 0 ? '+' : '-'), /* char format: use int */ + duk_int_t diff1 = (duk_int_t) (DUK_DEC_ABC(ins) - DUK_BC_JUMP_BIAS); /* from next pc */ + duk_int_t diff2 = diff1 + 1; /* from curr pc */ + + duk_fb_sprintf(fb, + "%s %ld (to pc%c%ld)", + (const char *) op_name, + (long) diff1, + (int) (diff2 >= 0 ? '+' : '-'), /* char format: use int */ (long) (diff2 >= 0 ? diff2 : -diff2)); } else { - duk_fb_sprintf(fb, "%s %ld, %ld, %ld", - (const char *) op_name, (long) DUK_DEC_A(ins), - (long) DUK_DEC_B(ins), (long) DUK_DEC_C(ins)); + duk_fb_sprintf(fb, + "%s %ld, %ld, %ld", + (const char *) op_name, + (long) DUK_DEC_A(ins), + (long) DUK_DEC_B(ins), + (long) DUK_DEC_C(ins)); } } @@ -829,13 +922,16 @@ return; } - duk_fb_sprintf(fb, "catcher ptr=%p parent=%p varname=%p pc_base=%p, idx_base=%ld, flags=0x%08lx", + duk_fb_sprintf(fb, + "catcher ptr=%p parent=%p varname=%p pc_base=%p, idx_base=%ld, flags=0x%08lx", (void *) cat, - (void *) cat->parent, (void *) cat->h_varname, (void *) cat->pc_base, - (long) cat->idx_base, (unsigned long) cat->flags); + (void *) cat->parent, + (void *) cat->h_varname, + (void *) cat->pc_base, + (long) cat->idx_base, + (unsigned long) cat->flags); } - DUK_LOCAL void duk__print_activation(duk__dprint_state *st, duk_activation *act) { duk_fixedbuffer *fb = st->fb; @@ -850,12 +946,20 @@ /* prev_caller: conditional, omitted on purpose, it's rarely used. */ /* prev_line: conditional, omitted on purpose (but would be nice). */ - duk_fb_sprintf(fb, "activation ptr=%p tv_func=<omit> func=%p parent=%p var_env=%p lex_env=%p cat=%p curr_pc=%p bottom_byteoff=%ld retval_byteoff=%ld reserve_byteoff=%ld flags=%ld", + duk_fb_sprintf(fb, + "activation ptr=%p tv_func=<omit> func=%p parent=%p var_env=%p lex_env=%p cat=%p curr_pc=%p " + "bottom_byteoff=%ld retval_byteoff=%ld reserve_byteoff=%ld flags=%ld", (void *) act, - (void *) act->func, (void *) act->parent, (void *) act->var_env, - (void *) act->lex_env, (void *) act->cat, (void *) act->curr_pc, - (long) act->bottom_byteoff, (long) act->retval_byteoff, (long) act->reserve_byteoff, - (long) act->flags); + (void *) act->func, + (void *) act->parent, + (void *) act->var_env, + (void *) act->lex_env, + (void *) act->cat, + (void *) act->curr_pc, + (long) act->bottom_byteoff, + (long) act->retval_byteoff, + (long) act->reserve_byteoff, + (long) act->flags); } DUK_INTERNAL duk_int_t duk_debug_vsnprintf(char *str, duk_size_t size, const char *format, va_list ap) { @@ -874,7 +978,7 @@ char ch = *p++; const char *p_begfmt = NULL; duk_bool_t got_exclamation = 0; - duk_bool_t got_long = 0; /* %lf, %ld etc */ + duk_bool_t got_long = 0; /* %lf, %ld etc */ duk__dprint_state st; if (ch != DUK_ASC_PERCENT) { @@ -1037,11 +1141,11 @@ } goto done; - format_error: +format_error: duk_fb_put_cstring(&fb, "FMTERR"); /* fall through */ - done: +done: retval = (duk_int_t) fb.offset; duk_fb_put_byte(&fb, (duk_uint8_t) 0); @@ -1049,7 +1153,7 @@ return retval; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_int_t duk_debug_snprintf(char *str, duk_size_t size, const char *format, ...) { duk_int_t retval; va_list ap; @@ -1090,4 +1194,4 @@ } } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_debugger.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_debugger.c
Changed
@@ -11,17 +11,23 @@ */ #if defined(DUK_USE_ASSERTIONS) -#define DUK__DBG_TPORT_ENTER() do { \ +#define DUK__DBG_TPORT_ENTER() \ + do { \ DUK_ASSERT(heap->dbg_calling_transport == 0); \ heap->dbg_calling_transport = 1; \ } while (0) -#define DUK__DBG_TPORT_EXIT() do { \ +#define DUK__DBG_TPORT_EXIT() \ + do { \ DUK_ASSERT(heap->dbg_calling_transport == 1); \ heap->dbg_calling_transport = 0; \ } while (0) #else -#define DUK__DBG_TPORT_ENTER() do {} while (0) -#define DUK__DBG_TPORT_EXIT() do {} while (0) +#define DUK__DBG_TPORT_ENTER() \ + do { \ + } while (0) +#define DUK__DBG_TPORT_EXIT() \ + do { \ + } while (0) #endif /* @@ -41,7 +47,8 @@ * Detach handling */ -#define DUK__SET_CONN_BROKEN(thr,reason) do { \ +#define DUK__SET_CONN_BROKEN(thr, reason) \ + do { \ /* For now shared handler is fine. */ \ duk__debug_do_detach1((thr)->heap, (reason)); \ } while (0) @@ -62,7 +69,7 @@ DUK_D(DUK_DPRINT("debugger transport detaching, marking transport broken")); - heap->dbg_detaching = 1; /* prevent multiple in-progress detaches */ + heap->dbg_detaching = 1; /* prevent multiple in-progress detaches */ if (heap->dbg_write_cb != NULL) { duk_hthread *thr; @@ -90,8 +97,8 @@ heap->dbg_pause_act = NULL; heap->dbg_pause_startline = 0; heap->dbg_have_next_byte = 0; - duk_debug_clear_paused(heap); /* XXX: some overlap with field inits above */ - heap->dbg_state_dirty = 0; /* XXX: clear_paused sets dirty; rework? */ + duk_debug_clear_paused(heap); /* XXX: some overlap with field inits above */ + heap->dbg_state_dirty = 0; /* XXX: clear_paused sets dirty; rework? */ /* Ensure there are no stale active breakpoint pointers. * Breakpoint list is currently kept - we could empty it @@ -151,7 +158,7 @@ heap = thr->heap; DUK_D(DUK_DPRINT("transport read/write error, NULL all callbacks expected detached")); heap->dbg_read_cb = NULL; - heap->dbg_write_cb = NULL; /* this is especially critical to avoid another write call in detach1() */ + heap->dbg_write_cb = NULL; /* this is especially critical to avoid another write call in detach1() */ heap->dbg_peek_cb = NULL; heap->dbg_read_flush_cb = NULL; heap->dbg_write_flush_cb = NULL; @@ -173,7 +180,8 @@ updated_flags = pause_flags & ~(DUK_PAUSE_FLAG_LINE_CHANGE); DUK_D(DUK_DPRINT("no line info for current activation, disable line-based pause flags: 0x%08lx -> 0x%08lx", - (long) pause_flags, (long) updated_flags)); + (long) pause_flags, + (long) updated_flags)); pause_flags = updated_flags; } @@ -183,7 +191,8 @@ heap->dbg_state_dirty = 1; DUK_D(DUK_DPRINT("set state for automatic pause triggers, flags=0x%08lx, act=%p, startline=%ld", - (long) heap->dbg_pause_flags, (void *) heap->dbg_pause_act, + (long) heap->dbg_pause_flags, + (void *) heap->dbg_pause_act, (long) heap->dbg_pause_startline)); } @@ -338,7 +347,7 @@ if (got == 0 || got > left) { DUK_D(DUK_DPRINT("connection error during read, return zero data")); - duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ + duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ DUK__SET_CONN_BROKEN(thr, 1); goto fail; } @@ -346,14 +355,14 @@ } return; - fail: +fail: duk_memzero((void *) data, (size_t) length); } DUK_INTERNAL duk_uint8_t duk_debug_read_byte(duk_hthread *thr) { duk_uint8_t x; - x = 0; /* just in case callback is broken and won't write 'x' */ + x = 0; /* just in case callback is broken and won't write 'x' */ duk_debug_read_bytes(thr, &x, 1); return x; } @@ -364,10 +373,7 @@ DUK_ASSERT(thr != NULL); duk_debug_read_bytes(thr, buf, 4); - return ((duk_uint32_t) buf0 << 24) | - ((duk_uint32_t) buf1 << 16) | - ((duk_uint32_t) buf2 << 8) | - (duk_uint32_t) buf3; + return ((duk_uint32_t) buf0 << 24) | ((duk_uint32_t) buf1 << 16) | ((duk_uint32_t) buf2 << 8) | (duk_uint32_t) buf3; } DUK_LOCAL duk_int32_t duk__debug_read_int32_raw(duk_hthread *thr) { @@ -380,8 +386,7 @@ DUK_ASSERT(thr != NULL); duk_debug_read_bytes(thr, buf, 2); - return ((duk_uint16_t) buf0 << 8) | - (duk_uint16_t) buf1; + return ((duk_uint16_t) buf0 << 8) | (duk_uint16_t) buf1; } DUK_INTERNAL duk_int32_t duk_debug_read_int(duk_hthread *thr) { @@ -413,10 +418,10 @@ duk_debug_read_bytes(thr, buf, (duk_size_t) len); duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); } else { - p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ + p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ DUK_ASSERT(p != NULL); duk_debug_read_bytes(thr, p, (duk_size_t) len); - (void) duk_buffer_to_string(thr, -1); /* Safety relies on debug client, which is OK. */ + (void) duk_buffer_to_string(thr, -1); /* Safety relies on debug client, which is OK. */ } return duk_require_hstring(thr, -1); @@ -442,17 +447,17 @@ return duk__debug_read_hstring_raw(thr, len); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode int")); DUK__SET_CONN_BROKEN(thr, 1); - duk_push_hstring_empty(thr); /* always push some string */ + duk_push_hstring_empty(thr); /* always push some string */ return duk_require_hstring(thr, -1); } DUK_LOCAL duk_hbuffer *duk__debug_read_hbuffer_raw(duk_hthread *thr, duk_uint32_t len) { duk_uint8_t *p; - p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ + p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ DUK_ASSERT(p != NULL); duk_debug_read_bytes(thr, p, (duk_size_t) len); @@ -475,7 +480,7 @@ #endif return (void *) pu.p; - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode pointer")); DUK__SET_CONN_BROKEN(thr, 1); return (void *) NULL; @@ -533,7 +538,7 @@ return (duk_heaphdr *) duk__debug_read_pointer_raw(thr); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode any pointer (object, pointer, heapptr)")); DUK__SET_CONN_BROKEN(thr, 1); return NULL; @@ -639,15 +644,15 @@ duk_push_heapptr(thr, (void *) h); break; } - case DUK_DBG_IB_UNUSED: /* unused: not accepted in inbound messages */ + case DUK_DBG_IB_UNUSED: /* unused: not accepted in inbound messages */ default: goto fail; } - return_ptr: +return_ptr: return DUK_GET_TVAL_NEGIDX(thr, -1); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode tval")); DUK__SET_CONN_BROKEN(thr, 1); return NULL; @@ -697,7 +702,7 @@ DUK__DBG_TPORT_EXIT(); if (got == 0 || got > left) { - duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ + duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ DUK_D(DUK_DPRINT("connection error during write")); DUK__SET_CONN_BROKEN(thr, 1); return; @@ -764,8 +769,7 @@ * unsigned 32-bit dvalue. */ if (x >= 0x80000000UL) { - DUK_D(DUK_DPRINT("writing unsigned integer 0x%08lx as signed integer", - (long) x)); + DUK_D(DUK_DPRINT("writing unsigned integer 0x%08lx as signed integer", (long) x)); } duk_debug_write_int(thr, (duk_int32_t) x); } @@ -806,9 +810,7 @@ DUK_INTERNAL void duk_debug_write_cstring(duk_hthread *thr, const char *data) { DUK_ASSERT(thr != NULL); - duk_debug_write_string(thr, - data, - data ? DUK_STRLEN(data) : 0); + duk_debug_write_string(thr, data, data ? DUK_STRLEN(data) : 0); } DUK_INTERNAL void duk_debug_write_hstring(duk_hthread *thr, duk_hstring *h) { @@ -862,7 +864,7 @@ DUK_INTERNAL void duk_debug_write_heapptr(duk_hthread *thr, duk_heaphdr *h) { duk__debug_write_pointer_raw(thr, (void *) h, DUK_DBG_IB_HEAPPTR); } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT */ DUK_INTERNAL void duk_debug_write_hobject(duk_hthread *thr, duk_hobject *obj) { duk_uint8_t buf3; @@ -905,8 +907,7 @@ duk_debug_write_byte(thr, DUK_DBG_IB_NULL); break; case DUK_TAG_BOOLEAN: - DUK_ASSERT(DUK_TVAL_GET_BOOLEAN(tv) == 0 || - DUK_TVAL_GET_BOOLEAN(tv) == 1); + DUK_ASSERT(DUK_TVAL_GET_BOOLEAN(tv) == 0 || DUK_TVAL_GET_BOOLEAN(tv) == 1); duk_debug_write_boolean(thr, DUK_TVAL_GET_BOOLEAN(tv)); break; case DUK_TAG_POINTER: @@ -951,14 +952,22 @@ DUK_DD(DUK_DDPRINT("i32=%ld du1=%02x%02x%02x%02x%02x%02x%02x%02x " "du2=%02x%02x%02x%02x%02x%02x%02x%02x", (long) i32, - (unsigned int) du1.uc0, (unsigned int) du1.uc1, - (unsigned int) du1.uc2, (unsigned int) du1.uc3, - (unsigned int) du1.uc4, (unsigned int) du1.uc5, - (unsigned int) du1.uc6, (unsigned int) du1.uc7, - (unsigned int) du2.uc0, (unsigned int) du2.uc1, - (unsigned int) du2.uc2, (unsigned int) du2.uc3, - (unsigned int) du2.uc4, (unsigned int) du2.uc5, - (unsigned int) du2.uc6, (unsigned int) du2.uc7)); + (unsigned int) du1.uc0, + (unsigned int) du1.uc1, + (unsigned int) du1.uc2, + (unsigned int) du1.uc3, + (unsigned int) du1.uc4, + (unsigned int) du1.uc5, + (unsigned int) du1.uc6, + (unsigned int) du1.uc7, + (unsigned int) du2.uc0, + (unsigned int) du2.uc1, + (unsigned int) du2.uc2, + (unsigned int) du2.uc3, + (unsigned int) du2.uc4, + (unsigned int) du2.uc5, + (unsigned int) du2.uc6, + (unsigned int) du2.uc7)); if (duk_memcmp((const void *) du1.uc, (const void *) du2.uc, sizeof(du1.uc)) == 0) { duk_debug_write_int(thr, i32); @@ -982,13 +991,13 @@ duk_debug_write_tval(thr, tv); } } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ /* * Debug connection message write helpers */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL void duk_debug_write_request(duk_hthread *thr, duk_small_uint_t command) { duk_debug_write_byte(thr, DUK_DBG_IB_REQUEST); duk_debug_write_int(thr, command); @@ -1091,7 +1100,7 @@ duk_activation *act; duk_uint32_t pc; - DUK_ASSERT(thr->valstack_top > thr->valstack); /* At least: ... err */ + DUK_ASSERT(thr->valstack_top > thr->valstack); /* At least: ... err */ duk_debug_write_notify(thr, DUK_DBG_CMD_THROW); duk_debug_write_int(thr, (duk_int32_t) fatal); @@ -1132,7 +1141,7 @@ duk_debug_write_eom(thr); } -#endif /* DUK_USE_DEBUGGER_THROW_NOTIFY */ +#endif /* DUK_USE_DEBUGGER_THROW_NOTIFY */ /* * Debug message processing @@ -1156,9 +1165,9 @@ duk_debug_skip_bytes(thr, (duk_size_t) (x - 0x60)); return 0; } - switch(x) { + switch (x) { case DUK_DBG_IB_EOM: - return 1; /* Return 1: got EOM */ + return 1; /* Return 1: got EOM */ case DUK_DBG_IB_REQUEST: case DUK_DBG_IB_REPLY: case DUK_DBG_IB_ERROR: @@ -1207,9 +1216,9 @@ return 0; - fail: +fail: DUK__SET_CONN_BROKEN(thr, 1); - return 1; /* Pretend like we got EOM */ + return 1; /* Pretend like we got EOM */ } /* Skip dvalues to EOM. */ @@ -1229,7 +1238,7 @@ level = duk_debug_read_int(thr); if (level >= 0 || -level > (duk_int32_t) thr->callstack_top) { duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack index"); - return 0; /* zero indicates failure */ + return 0; /* zero indicates failure */ } return level; } @@ -1298,7 +1307,7 @@ duk_debug_clear_paused(heap); pause_flags = 0; -#if 0 /* manual testing */ +#if 0 /* manual testing */ pause_flags |= DUK_PAUSE_FLAG_ONE_OPCODE; pause_flags |= DUK_PAUSE_FLAG_CAUGHT_ERROR; pause_flags |= DUK_PAUSE_FLAG_UNCAUGHT_ERROR; @@ -1319,12 +1328,9 @@ DUK_D(DUK_DPRINT("debug command StepInto/StepOver/StepOut: %d", (int) cmd)); if (cmd == DUK_DBG_CMD_STEPINTO) { - pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | - DUK_PAUSE_FLAG_FUNC_ENTRY | - DUK_PAUSE_FLAG_FUNC_EXIT; + pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | DUK_PAUSE_FLAG_FUNC_ENTRY | DUK_PAUSE_FLAG_FUNC_EXIT; } else if (cmd == DUK_DBG_CMD_STEPOVER) { - pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | - DUK_PAUSE_FLAG_FUNC_EXIT; + pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | DUK_PAUSE_FLAG_FUNC_EXIT; } else { DUK_ASSERT(cmd == DUK_DBG_CMD_STEPOUT); pause_flags = DUK_PAUSE_FLAG_FUNC_EXIT; @@ -1403,7 +1409,7 @@ if (act == NULL) { return; } - str = duk_debug_read_hstring(thr); /* push to stack */ + str = duk_debug_read_hstring(thr); /* push to stack */ DUK_ASSERT(str != NULL); rc = duk_js_getvar_activation(thr, act, str, 0); @@ -1432,7 +1438,7 @@ if (act == NULL) { return; } - str = duk_debug_read_hstring(thr); /* push to stack */ + str = duk_debug_read_hstring(thr); /* push to stack */ DUK_ASSERT(str != NULL); tv = duk_debug_read_tval(thr); if (tv == NULL) { @@ -1530,7 +1536,7 @@ /* ... func varmap enum key value this */ duk_debug_write_hstring(thr, duk_get_hstring(thr, -3)); duk_debug_write_tval(thr, duk_get_tval(thr, -2)); - duk_pop_3(thr); /* -> ... func varmap enum */ + duk_pop_3(thr); /* -> ... func varmap enum */ } } else { DUK_D(DUK_DPRINT("varmap missing in GetLocals, ignore")); @@ -1565,12 +1571,12 @@ /* nargs == 2 so we can pass a callstack index to eval(). */ idx_func = duk_get_top(thr); duk_push_c_function(thr, duk_bi_global_object_eval, 2 /*nargs*/); - duk_push_undefined(thr); /* 'this' binding shouldn't matter here */ + duk_push_undefined(thr); /* 'this' binding shouldn't matter here */ /* Read callstack index, if non-null. */ if (duk_debug_peek_byte(thr) == DUK_DBG_IB_NULL) { direct_eval = 0; - level = -1; /* Not needed, but silences warning. */ + level = -1; /* Not needed, but silences warning. */ (void) duk_debug_read_byte(thr); } else { direct_eval = 1; @@ -1580,12 +1586,11 @@ } } - DUK_ASSERT(!direct_eval || - (level < 0 && -level <= (duk_int32_t) thr->callstack_top)); + DUK_ASSERT(!direct_eval || (level < 0 && -level <= (duk_int32_t) thr->callstack_top)); (void) duk_debug_read_hstring(thr); if (direct_eval) { - duk_push_int(thr, level - 1); /* compensate for eval() call */ + duk_push_int(thr, level - 1); /* compensate for eval() call */ } /* ... eval "eval" eval_input level? */ @@ -1640,7 +1645,7 @@ duk_debug_write_eom(thr); DUK_D(DUK_DPRINT("debug connection detached, mark broken")); - DUK__SET_CONN_BROKEN(thr, 0); /* not an error */ + DUK__SET_CONN_BROKEN(thr, 0); /* not an error */ } DUK_LOCAL void duk__debug_handle_apprequest(duk_hthread *thr, duk_heap *heap) { @@ -1648,7 +1653,7 @@ DUK_D(DUK_DPRINT("debug command AppRequest")); - old_top = duk_get_top(thr); /* save stack top */ + old_top = duk_get_top(thr); /* save stack top */ if (heap->dbg_request_cb != NULL) { duk_idx_t nrets; @@ -1664,7 +1669,7 @@ DUK_D(DUK_DPRINT("failed to allocate space for request dvalue(s)")); goto fail; } - tv = duk_debug_read_tval(thr); /* push to stack */ + tv = duk_debug_read_tval(thr); /* push to stack */ if (tv == NULL) { /* detached */ return; @@ -1675,17 +1680,24 @@ /* Request callback should push values for reply to client onto valstack */ DUK_D(DUK_DPRINT("calling into AppRequest request_cb with nvalues=%ld, old_top=%ld, top=%ld", - (long) nvalues, (long) old_top, (long) duk_get_top(thr))); + (long) nvalues, + (long) old_top, + (long) duk_get_top(thr))); nrets = heap->dbg_request_cb(thr, heap->dbg_udata, nvalues); DUK_D(DUK_DPRINT("returned from AppRequest request_cb; nvalues=%ld -> nrets=%ld, old_top=%ld, top=%ld", - (long) nvalues, (long) nrets, (long) old_top, (long) duk_get_top(thr))); + (long) nvalues, + (long) nrets, + (long) old_top, + (long) duk_get_top(thr))); if (nrets >= 0) { DUK_ASSERT(duk_get_top(thr) >= old_top + nrets); if (duk_get_top(thr) < old_top + nrets) { DUK_D(DUK_DPRINT("AppRequest callback doesn't match value stack configuration, " "top=%ld < old_top=%ld + nrets=%ld; " "this might mean it's unsafe to continue!", - (long) duk_get_top(thr), (long) old_top, (long) nrets)); + (long) duk_get_top(thr), + (long) old_top, + (long) nrets)); goto fail; } @@ -1705,7 +1717,7 @@ duk_debug_write_error_eom(thr, DUK_DBG_ERR_APPLICATION, duk_get_string(thr, -1)); } - duk_set_top(thr, old_top); /* restore stack top */ + duk_set_top(thr, old_top); /* restore stack top */ } else { DUK_D(DUK_DPRINT("no request callback, treat AppRequest as unsupported")); duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNSUPPORTED, "AppRequest unsupported by target"); @@ -1713,8 +1725,8 @@ return; - fail: - duk_set_top(thr, old_top); /* restore stack top */ +fail: + duk_set_top(thr, old_top); /* restore stack top */ DUK__SET_CONN_BROKEN(thr, 1); } @@ -1765,16 +1777,16 @@ k = DUK_HOBJECT_E_GET_KEY(heap, h, i); duk_debug_write_heapptr(thr, (duk_heaphdr *) k); if (k == NULL) { - duk_debug_write_int(thr, 0); /* isAccessor */ + duk_debug_write_int(thr, 0); /* isAccessor */ duk_debug_write_unused(thr); continue; } if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap, h, i)) { - duk_debug_write_int(thr, 1); /* isAccessor */ + duk_debug_write_int(thr, 1); /* isAccessor */ duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->a.get); duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->a.set); } else { - duk_debug_write_int(thr, 0); /* isAccessor */ + duk_debug_write_int(thr, 0); /* isAccessor */ duk__debug_write_tval_heapptr(thr, &DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->v); } @@ -1836,7 +1848,7 @@ duk__debug_dump_strtab(thr, heap); duk_debug_write_eom(thr); } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ DUK_LOCAL void duk__debug_handle_get_bytecode(duk_hthread *thr, duk_heap *heap) { duk_activation *act; @@ -1905,11 +1917,11 @@ duk_debug_write_eom(thr); return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid argument"); return; - fail_index: +fail_index: duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack index"); return; } @@ -1961,53 +1973,22 @@ DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS, #endif DUK_HSTRING_FLAG_EXTDATA, - 0 /* terminator */ + 0 /* terminator */ }; DUK_LOCAL const char * const duk__debug_getinfo_hobject_keys = { - "extensible", - "constructable", - "callable", - "boundfunc", - "compfunc", - "natfunc", - "bufobj", - "fastrefs", - "array_part", - "strict", - "notail", - "newenv", - "namebinding", - "createargs", - "have_finalizer", - "exotic_array", - "exotic_stringobj", - "exotic_arguments", - "exotic_proxyobj", - "special_call" + "extensible", "constructable", "callable", "boundfunc", "compfunc", "natfunc", "bufobj", + "fastrefs", "array_part", "strict", "notail", "newenv", "namebinding", "createargs", + "have_finalizer", "exotic_array", "exotic_stringobj", "exotic_arguments", "exotic_proxyobj", "special_call" /* NULL not needed here */ }; DUK_LOCAL duk_uint_t duk__debug_getinfo_hobject_masks = { - DUK_HOBJECT_FLAG_EXTENSIBLE, - DUK_HOBJECT_FLAG_CONSTRUCTABLE, - DUK_HOBJECT_FLAG_CALLABLE, - DUK_HOBJECT_FLAG_BOUNDFUNC, - DUK_HOBJECT_FLAG_COMPFUNC, - DUK_HOBJECT_FLAG_NATFUNC, - DUK_HOBJECT_FLAG_BUFOBJ, - DUK_HOBJECT_FLAG_FASTREFS, - DUK_HOBJECT_FLAG_ARRAY_PART, - DUK_HOBJECT_FLAG_STRICT, - DUK_HOBJECT_FLAG_NOTAIL, - DUK_HOBJECT_FLAG_NEWENV, - DUK_HOBJECT_FLAG_NAMEBINDING, - DUK_HOBJECT_FLAG_CREATEARGS, - DUK_HOBJECT_FLAG_HAVE_FINALIZER, - DUK_HOBJECT_FLAG_EXOTIC_ARRAY, - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ, - DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS, - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ, - DUK_HOBJECT_FLAG_SPECIAL_CALL, - 0 /* terminator */ + DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_HOBJECT_FLAG_CONSTRUCTABLE, DUK_HOBJECT_FLAG_CALLABLE, + DUK_HOBJECT_FLAG_BOUNDFUNC, DUK_HOBJECT_FLAG_COMPFUNC, DUK_HOBJECT_FLAG_NATFUNC, + DUK_HOBJECT_FLAG_BUFOBJ, DUK_HOBJECT_FLAG_FASTREFS, DUK_HOBJECT_FLAG_ARRAY_PART, + DUK_HOBJECT_FLAG_STRICT, DUK_HOBJECT_FLAG_NOTAIL, DUK_HOBJECT_FLAG_NEWENV, + DUK_HOBJECT_FLAG_NAMEBINDING, DUK_HOBJECT_FLAG_CREATEARGS, DUK_HOBJECT_FLAG_HAVE_FINALIZER, + DUK_HOBJECT_FLAG_EXOTIC_ARRAY, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS, + DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ, DUK_HOBJECT_FLAG_SPECIAL_CALL, 0 /* terminator */ }; DUK_LOCAL const char * const duk__debug_getinfo_hbuffer_keys = { "dynamic", @@ -2017,7 +1998,7 @@ DUK_LOCAL duk_uint_t duk__debug_getinfo_hbuffer_masks = { DUK_HBUFFER_FLAG_DYNAMIC, DUK_HBUFFER_FLAG_EXTERNAL, - 0 /* terminator */ + 0 /* terminator */ }; DUK_LOCAL void duk__debug_getinfo_flags_key(duk_hthread *thr, const char *key) { @@ -2043,7 +2024,7 @@ duk_debug_write_boolean(thr, val); } -DUK_LOCAL void duk__debug_getinfo_bitmask(duk_hthread *thr, const char * const * keys, duk_uint_t *masks, duk_uint_t flags) { +DUK_LOCAL void duk__debug_getinfo_bitmask(duk_hthread *thr, const char * const *keys, duk_uint_t *masks, duk_uint_t flags) { const char *key; duk_uint_t mask; @@ -2055,7 +2036,10 @@ key = *keys++; DUK_ASSERT(key != NULL); - DUK_DD(DUK_DDPRINT("inspect bitmask: key=%s, mask=0x%08lx, flags=0x%08lx", key, (unsigned long) mask, (unsigned long) flags)); + DUK_DD(DUK_DDPRINT("inspect bitmask: key=%s, mask=0x%08lx, flags=0x%08lx", + key, + (unsigned long) mask, + (unsigned long) flags)); duk__debug_getinfo_prop_bool(thr, key, flags & mask); } } @@ -2131,9 +2115,12 @@ DUK_D(DUK_DPRINT("debug command GetHeapObjInfo")); DUK_UNREF(heap); - DUK_ASSERT(sizeof(duk__debug_getinfo_hstring_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hstring_masks) / sizeof(duk_uint_t) - 1); - DUK_ASSERT(sizeof(duk__debug_getinfo_hobject_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hobject_masks) / sizeof(duk_uint_t) - 1); - DUK_ASSERT(sizeof(duk__debug_getinfo_hbuffer_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hbuffer_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hstring_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hstring_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hobject_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hobject_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hbuffer_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hbuffer_masks) / sizeof(duk_uint_t) - 1); h = duk_debug_read_any_ptr(thr); if (!h) { @@ -2321,7 +2308,7 @@ duk_debug_write_heapptr(thr, (duk_heaphdr *) h_bufobj->buf); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ break; } case DUK_HTYPE_BUFFER: { @@ -2336,7 +2323,7 @@ duk__debug_getinfo_flags_key(thr, "dataptr"); duk_debug_write_pointer(thr, (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_buf)); duk__debug_getinfo_flags_key(thr, "data"); - duk_debug_write_hbuffer(thr, h_buf); /* tolerates NULL h_buf */ + duk_debug_write_hbuffer(thr, h_buf); /* tolerates NULL h_buf */ break; } default: { @@ -2374,8 +2361,7 @@ /* To use the shared helper need the virtual index. */ DUK_ASSERT(desc.e_idx >= 0 || desc.a_idx >= 0); - virtual_idx = (desc.a_idx >= 0 ? desc.a_idx : - (duk_int_t) DUK_HOBJECT_GET_ASIZE(h_obj) + desc.e_idx); + virtual_idx = (desc.a_idx >= 0 ? desc.a_idx : (duk_int_t) DUK_HOBJECT_GET_ASIZE(h_obj) + desc.e_idx); duk_debug_write_reply(thr); rc = duk__debug_getprop_index(thr, heap, h_obj, (duk_uint_t) virtual_idx); @@ -2387,7 +2373,7 @@ } return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid args"); } @@ -2423,11 +2409,11 @@ duk_debug_write_eom(thr); return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid args"); } -#endif /* DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_INSPECT */ /* * Process incoming debug requests @@ -2525,7 +2511,7 @@ duk__debug_handle_dump_heap(thr, heap); break; } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ case DUK_DBG_CMD_GETBYTECODE: { duk__debug_handle_get_bytecode(thr, heap); break; @@ -2547,12 +2533,12 @@ duk__debug_handle_get_obj_prop_desc_range(thr, heap); break; } -#endif /* DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_INSPECT */ default: { DUK_D(DUK_DPRINT("debug command unsupported: %d", (int) cmd)); duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNSUPPORTED, "unsupported command"); } - } /* switch cmd */ + } /* switch cmd */ break; } case DUK_DBG_IB_REPLY: { @@ -2571,14 +2557,14 @@ DUK_D(DUK_DPRINT("invalid initial byte, drop connection: %d", (int) x)); goto fail; } - } /* switch initial byte */ + } /* switch initial byte */ DUK_ASSERT(duk_get_top(thr) >= entry_top); duk_set_top(thr, entry_top); duk__debug_skip_to_eom(thr); return; - fail: +fail: DUK_ASSERT(duk_get_top(thr) >= entry_top); duk_set_top(thr, entry_top); DUK__SET_CONN_BROKEN(thr, 1); @@ -2605,8 +2591,10 @@ #endif DUK_D(DUK_DPRINT("process debug messages: read_cb=%s, no_block=%ld, detaching=%ld, processing=%ld", - thr->heap->dbg_read_cb ? "not NULL" : "NULL", (long) no_block, - (long) thr->heap->dbg_detaching, (long) thr->heap->dbg_processing)); + thr->heap->dbg_read_cb ? "not NULL" : "NULL", + (long) no_block, + (long) thr->heap->dbg_detaching, + (long) thr->heap->dbg_processing)); DUK_DD(DUK_DDPRINT("top at entry: %ld", (long) duk_get_top(thr))); /* thr->heap->dbg_detaching may be != 0 if a debugger write outside @@ -2653,13 +2641,14 @@ DUK_D(DUK_DPRINT("detach pending (dbg_read_cb == NULL, dbg_detaching != 0), call detach2")); duk__debug_do_detach2(thr->heap); - thr->heap->dbg_processing = 1; /* may be set to 0 by duk_debugger_attach() inside callback */ + thr->heap->dbg_processing = 1; /* may be set to 0 by duk_debugger_attach() inside callback */ DUK_D(DUK_DPRINT("after detach2 (and possible reattach): dbg_read_cb=%s, dbg_detaching=%ld", - thr->heap->dbg_read_cb ? "not NULL" : "NULL", (long) thr->heap->dbg_detaching)); + thr->heap->dbg_read_cb ? "not NULL" : "NULL", + (long) thr->heap->dbg_detaching)); } - DUK_ASSERT(thr->heap->dbg_detaching == 0); /* true even with reattach */ - DUK_ASSERT(thr->heap->dbg_processing == 1); /* even after a detach and possible reattach */ + DUK_ASSERT(thr->heap->dbg_detaching == 0); /* true even with reattach */ + DUK_ASSERT(thr->heap->dbg_processing == 1); /* even after a detach and possible reattach */ if (thr->heap->dbg_read_cb == NULL) { DUK_D(DUK_DPRINT("debug connection broken (and not detaching), stop processing messages")); @@ -2684,7 +2673,7 @@ duk__debug_process_message(thr); duk__check_resend_status(thr); - retval = 1; /* processed one or more messages */ + retval = 1; /* processed one or more messages */ } DUK_ASSERT(thr->heap->dbg_detaching == 0); @@ -2694,7 +2683,7 @@ /* As an initial implementation, read flush after exiting the message * loop. If transport is broken, this is a no-op (with debug logs). */ - duk_debug_read_flush(thr); /* this cannot initiate a detach */ + duk_debug_read_flush(thr); /* this cannot initiate a detach */ DUK_ASSERT(thr->heap->dbg_detaching == 0); DUK_DD(DUK_DDPRINT("top at exit: %ld", (long) duk_get_top(thr))); @@ -2745,11 +2734,8 @@ /* Short circuit if is safe: if act->curr_pc != NULL, 'fun' is * guaranteed to be a non-NULL ECMAScript function. */ - DUK_ASSERT(act->curr_pc == NULL || - (fun != NULL && DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun))); - if (use_prev_pc && - act->curr_pc != NULL && - act->curr_pc > DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, fun)) { + DUK_ASSERT(act->curr_pc == NULL || (fun != NULL && DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun))); + if (use_prev_pc && act->curr_pc != NULL && act->curr_pc > DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, fun)) { act->curr_pc--; } } @@ -2776,7 +2762,7 @@ * with PC values. */ if (act != NULL) { - act->curr_pc = old_pc; /* restore PC */ + act->curr_pc = old_pc; /* restore PC */ } } @@ -2800,7 +2786,8 @@ if (heap->dbg_breakpoint_count >= DUK_HEAP_MAX_BREAKPOINTS) { DUK_D(DUK_DPRINT("failed to add breakpoint for %O:%ld, all breakpoint slots used", - (duk_heaphdr *) filename, (long) line)); + (duk_heaphdr *) filename, + (long) line)); return -1; } heap->dbg_breakpoints_active0 = (duk_breakpoint *) NULL; @@ -2809,7 +2796,7 @@ b->line = line; DUK_HSTRING_INCREF(thr, filename); - return (duk_small_int_t) (heap->dbg_breakpoint_count - 1); /* index */ + return (duk_small_int_t) (heap->dbg_breakpoint_count - 1); /* index */ } DUK_INTERNAL duk_bool_t duk_debug_remove_breakpoint(duk_hthread *thr, duk_small_uint_t breakpoint_index) { @@ -2827,7 +2814,7 @@ heap = thr->heap; DUK_ASSERT(heap != NULL); DUK_ASSERT(duk_debug_is_attached(thr->heap)); - DUK_ASSERT_DISABLE(breakpoint_index >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(breakpoint_index >= 0); /* unsigned */ if (breakpoint_index >= heap->dbg_breakpoint_count) { DUK_D(DUK_DPRINT("invalid breakpoint index: %ld", (long) breakpoint_index)); @@ -2839,15 +2826,13 @@ DUK_ASSERT(h != NULL); move_size = sizeof(duk_breakpoint) * (heap->dbg_breakpoint_count - breakpoint_index - 1); - duk_memmove((void *) b, - (const void *) (b + 1), - (size_t) move_size); + duk_memmove((void *) b, (const void *) (b + 1), (size_t) move_size); heap->dbg_breakpoint_count--; heap->dbg_breakpoints_active0 = (duk_breakpoint *) NULL; - DUK_HSTRING_DECREF(thr, h); /* side effects */ - DUK_UNREF(h); /* w/o refcounting */ + DUK_HSTRING_DECREF(thr, h); /* side effects */ + DUK_UNREF(h); /* w/o refcounting */ /* Breakpoint entries above the used area are left as garbage. */ @@ -2873,10 +2858,10 @@ DUK_HEAP_SET_DEBUGGER_PAUSED(heap); heap->dbg_state_dirty = 1; duk_debug_clear_pause_state(heap); - DUK_ASSERT(heap->ms_running == 0); /* debugger can't be triggered within mark-and-sweep */ - heap->ms_running = 2; /* prevent mark-and-sweep, prevent refzero queueing */ + DUK_ASSERT(heap->ms_running == 0); /* debugger can't be triggered within mark-and-sweep */ + heap->ms_running = 2; /* prevent mark-and-sweep, prevent refzero queueing */ heap->ms_prevent_count++; - DUK_ASSERT(heap->ms_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(heap->ms_prevent_count != 0); /* Wrap. */ DUK_ASSERT(heap->heap_thread != NULL); } } @@ -2902,8 +2887,8 @@ heap->dbg_pause_startline = 0; } -#else /* DUK_USE_DEBUGGER_SUPPORT */ +#else /* DUK_USE_DEBUGGER_SUPPORT */ /* No debugger support. */ -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_debugger.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_debugger.h
Changed
@@ -4,77 +4,77 @@ /* Debugger protocol version is defined in the public API header. */ /* Initial bytes for markers. */ -#define DUK_DBG_IB_EOM 0x00 -#define DUK_DBG_IB_REQUEST 0x01 -#define DUK_DBG_IB_REPLY 0x02 -#define DUK_DBG_IB_ERROR 0x03 -#define DUK_DBG_IB_NOTIFY 0x04 +#define DUK_DBG_IB_EOM 0x00 +#define DUK_DBG_IB_REQUEST 0x01 +#define DUK_DBG_IB_REPLY 0x02 +#define DUK_DBG_IB_ERROR 0x03 +#define DUK_DBG_IB_NOTIFY 0x04 /* Other initial bytes. */ -#define DUK_DBG_IB_INT4 0x10 -#define DUK_DBG_IB_STR4 0x11 -#define DUK_DBG_IB_STR2 0x12 -#define DUK_DBG_IB_BUF4 0x13 -#define DUK_DBG_IB_BUF2 0x14 -#define DUK_DBG_IB_UNUSED 0x15 -#define DUK_DBG_IB_UNDEFINED 0x16 -#define DUK_DBG_IB_NULL 0x17 -#define DUK_DBG_IB_TRUE 0x18 -#define DUK_DBG_IB_FALSE 0x19 -#define DUK_DBG_IB_NUMBER 0x1a -#define DUK_DBG_IB_OBJECT 0x1b -#define DUK_DBG_IB_POINTER 0x1c -#define DUK_DBG_IB_LIGHTFUNC 0x1d -#define DUK_DBG_IB_HEAPPTR 0x1e +#define DUK_DBG_IB_INT4 0x10 +#define DUK_DBG_IB_STR4 0x11 +#define DUK_DBG_IB_STR2 0x12 +#define DUK_DBG_IB_BUF4 0x13 +#define DUK_DBG_IB_BUF2 0x14 +#define DUK_DBG_IB_UNUSED 0x15 +#define DUK_DBG_IB_UNDEFINED 0x16 +#define DUK_DBG_IB_NULL 0x17 +#define DUK_DBG_IB_TRUE 0x18 +#define DUK_DBG_IB_FALSE 0x19 +#define DUK_DBG_IB_NUMBER 0x1a +#define DUK_DBG_IB_OBJECT 0x1b +#define DUK_DBG_IB_POINTER 0x1c +#define DUK_DBG_IB_LIGHTFUNC 0x1d +#define DUK_DBG_IB_HEAPPTR 0x1e /* The short string/integer initial bytes starting from 0x60 don't have * defines now. */ /* Error codes. */ -#define DUK_DBG_ERR_UNKNOWN 0x00 -#define DUK_DBG_ERR_UNSUPPORTED 0x01 -#define DUK_DBG_ERR_TOOMANY 0x02 -#define DUK_DBG_ERR_NOTFOUND 0x03 -#define DUK_DBG_ERR_APPLICATION 0x04 +#define DUK_DBG_ERR_UNKNOWN 0x00 +#define DUK_DBG_ERR_UNSUPPORTED 0x01 +#define DUK_DBG_ERR_TOOMANY 0x02 +#define DUK_DBG_ERR_NOTFOUND 0x03 +#define DUK_DBG_ERR_APPLICATION 0x04 /* Commands and notifys initiated by Duktape. */ -#define DUK_DBG_CMD_STATUS 0x01 -#define DUK_DBG_CMD_UNUSED_2 0x02 /* Duktape 1.x: print notify */ -#define DUK_DBG_CMD_UNUSED_3 0x03 /* Duktape 1.x: alert notify */ -#define DUK_DBG_CMD_UNUSED_4 0x04 /* Duktape 1.x: log notify */ -#define DUK_DBG_CMD_THROW 0x05 -#define DUK_DBG_CMD_DETACHING 0x06 -#define DUK_DBG_CMD_APPNOTIFY 0x07 +#define DUK_DBG_CMD_STATUS 0x01 +#define DUK_DBG_CMD_UNUSED_2 0x02 /* Duktape 1.x: print notify */ +#define DUK_DBG_CMD_UNUSED_3 0x03 /* Duktape 1.x: alert notify */ +#define DUK_DBG_CMD_UNUSED_4 0x04 /* Duktape 1.x: log notify */ +#define DUK_DBG_CMD_THROW 0x05 +#define DUK_DBG_CMD_DETACHING 0x06 +#define DUK_DBG_CMD_APPNOTIFY 0x07 /* Commands initiated by debug client. */ -#define DUK_DBG_CMD_BASICINFO 0x10 -#define DUK_DBG_CMD_TRIGGERSTATUS 0x11 -#define DUK_DBG_CMD_PAUSE 0x12 -#define DUK_DBG_CMD_RESUME 0x13 -#define DUK_DBG_CMD_STEPINTO 0x14 -#define DUK_DBG_CMD_STEPOVER 0x15 -#define DUK_DBG_CMD_STEPOUT 0x16 -#define DUK_DBG_CMD_LISTBREAK 0x17 -#define DUK_DBG_CMD_ADDBREAK 0x18 -#define DUK_DBG_CMD_DELBREAK 0x19 -#define DUK_DBG_CMD_GETVAR 0x1a -#define DUK_DBG_CMD_PUTVAR 0x1b -#define DUK_DBG_CMD_GETCALLSTACK 0x1c -#define DUK_DBG_CMD_GETLOCALS 0x1d -#define DUK_DBG_CMD_EVAL 0x1e -#define DUK_DBG_CMD_DETACH 0x1f -#define DUK_DBG_CMD_DUMPHEAP 0x20 -#define DUK_DBG_CMD_GETBYTECODE 0x21 -#define DUK_DBG_CMD_APPREQUEST 0x22 -#define DUK_DBG_CMD_GETHEAPOBJINFO 0x23 -#define DUK_DBG_CMD_GETOBJPROPDESC 0x24 -#define DUK_DBG_CMD_GETOBJPROPDESCRANGE 0x25 +#define DUK_DBG_CMD_BASICINFO 0x10 +#define DUK_DBG_CMD_TRIGGERSTATUS 0x11 +#define DUK_DBG_CMD_PAUSE 0x12 +#define DUK_DBG_CMD_RESUME 0x13 +#define DUK_DBG_CMD_STEPINTO 0x14 +#define DUK_DBG_CMD_STEPOVER 0x15 +#define DUK_DBG_CMD_STEPOUT 0x16 +#define DUK_DBG_CMD_LISTBREAK 0x17 +#define DUK_DBG_CMD_ADDBREAK 0x18 +#define DUK_DBG_CMD_DELBREAK 0x19 +#define DUK_DBG_CMD_GETVAR 0x1a +#define DUK_DBG_CMD_PUTVAR 0x1b +#define DUK_DBG_CMD_GETCALLSTACK 0x1c +#define DUK_DBG_CMD_GETLOCALS 0x1d +#define DUK_DBG_CMD_EVAL 0x1e +#define DUK_DBG_CMD_DETACH 0x1f +#define DUK_DBG_CMD_DUMPHEAP 0x20 +#define DUK_DBG_CMD_GETBYTECODE 0x21 +#define DUK_DBG_CMD_APPREQUEST 0x22 +#define DUK_DBG_CMD_GETHEAPOBJINFO 0x23 +#define DUK_DBG_CMD_GETOBJPROPDESC 0x24 +#define DUK_DBG_CMD_GETOBJPROPDESCRANGE 0x25 /* The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx. * The remaining flags are specific to the debugger. */ -#define DUK_DBG_PROPFLAG_SYMBOL (1U << 8) -#define DUK_DBG_PROPFLAG_HIDDEN (1U << 9) +#define DUK_DBG_PROPFLAG_SYMBOL (1U << 8) +#define DUK_DBG_PROPFLAG_HIDDEN (1U << 9) #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_INTERNAL_DECL void duk_debug_do_detach(duk_heap *heap); @@ -121,7 +121,7 @@ #endif DUK_INTERNAL_DECL void duk_debug_write_hobject(duk_hthread *thr, duk_hobject *obj); DUK_INTERNAL_DECL void duk_debug_write_tval(duk_hthread *thr, duk_tval *tv); -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL_DECL void duk_debug_write_request(duk_hthread *thr, duk_small_uint_t command); #endif DUK_INTERNAL_DECL void duk_debug_write_reply(duk_hthread *thr); @@ -146,6 +146,6 @@ DUK_INTERNAL_DECL void duk_debug_set_paused(duk_heap *heap); DUK_INTERNAL_DECL void duk_debug_clear_paused(duk_heap *heap); DUK_INTERNAL_DECL void duk_debug_clear_pause_state(duk_heap *heap); -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ -#endif /* DUK_DEBUGGER_H_INCLUDED */ +#endif /* DUK_DEBUGGER_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_error.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_error.h
Changed
@@ -53,79 +53,153 @@ /* Because there are quite many call sites, pack error code (require at most * 8-bit) into a single argument. */ -#define DUK_ERROR(thr,err,msg) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ +#define DUK_ERROR(thr, err, msg) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ duk_err_handle_error((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (msg)); \ } while (0) -#define DUK_ERROR_RAW(thr,file,line,err,msg) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ +#define DUK_ERROR_RAW(thr, file, line, err, msg) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ duk_err_handle_error((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (msg)); \ } while (0) -#define DUK_ERROR_FMT1(thr,err,fmt,arg1) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1)); \ - } while (0) -#define DUK_ERROR_RAW_FMT1(thr,file,line,err,fmt,arg1) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1)); \ - } while (0) - -#define DUK_ERROR_FMT2(thr,err,fmt,arg1,arg2) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2)); \ - } while (0) -#define DUK_ERROR_RAW_FMT2(thr,file,line,err,fmt,arg1,arg2) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2)); \ - } while (0) - -#define DUK_ERROR_FMT3(thr,err,fmt,arg1,arg2,arg3) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3)); \ - } while (0) -#define DUK_ERROR_RAW_FMT3(thr,file,line,err,fmt,arg1,arg2,arg3) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3)); \ - } while (0) - -#define DUK_ERROR_FMT4(thr,err,fmt,arg1,arg2,arg3,arg4) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3), (arg4)); \ - } while (0) -#define DUK_ERROR_RAW_FMT4(thr,file,line,err,fmt,arg1,arg2,arg3,arg4) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3), (arg4)); \ - } while (0) - -#else /* DUK_USE_VERBOSE_ERRORS */ - -#define DUK_ERROR(thr,err,msg) duk_err_handle_error((thr), (err)) -#define DUK_ERROR_RAW(thr,file,line,err,msg) duk_err_handle_error((thr), (err)) - -#define DUK_ERROR_FMT1(thr,err,fmt,arg1) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT1(thr,file,line,err,fmt,arg1) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#define DUK_ERROR_FMT2(thr,err,fmt,arg1,arg2) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT2(thr,file,line,err,fmt,arg1,arg2) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#define DUK_ERROR_FMT3(thr,err,fmt,arg1,arg2,arg3) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT3(thr,file,line,err,fmt,arg1,arg2,arg3) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#define DUK_ERROR_FMT4(thr,err,fmt,arg1,arg2,arg3,arg4) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT4(thr,file,line,err,fmt,arg1,arg2,arg3,arg4) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#endif /* DUK_USE_VERBOSE_ERRORS */ +#define DUK_ERROR_FMT1(thr, err, fmt, arg1) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1)); \ + } while (0) +#define DUK_ERROR_RAW_FMT1(thr, file, line, err, fmt, arg1) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1)); \ + } while (0) + +#define DUK_ERROR_FMT2(thr, err, fmt, arg1, arg2) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2)); \ + } while (0) +#define DUK_ERROR_RAW_FMT2(thr, file, line, err, fmt, arg1, arg2) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2)); \ + } while (0) + +#define DUK_ERROR_FMT3(thr, err, fmt, arg1, arg2, arg3) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3)); \ + } while (0) +#define DUK_ERROR_RAW_FMT3(thr, file, line, err, fmt, arg1, arg2, arg3) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3)); \ + } while (0) + +#define DUK_ERROR_FMT4(thr, err, fmt, arg1, arg2, arg3, arg4) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3), \ + (arg4)); \ + } while (0) +#define DUK_ERROR_RAW_FMT4(thr, file, line, err, fmt, arg1, arg2, arg3, arg4) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3), \ + (arg4)); \ + } while (0) + +#else /* DUK_USE_VERBOSE_ERRORS */ + +#define DUK_ERROR(thr, err, msg) duk_err_handle_error((thr), (err)) +#define DUK_ERROR_RAW(thr, file, line, err, msg) duk_err_handle_error((thr), (err)) + +#define DUK_ERROR_FMT1(thr, err, fmt, arg1) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT1(thr, file, line, err, fmt, arg1) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) + +#define DUK_ERROR_FMT2(thr, err, fmt, arg1, arg2) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT2(thr, file, line, err, fmt, arg1, arg2) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) + +#define DUK_ERROR_FMT3(thr, err, fmt, arg1, arg2, arg3) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT3(thr, file, line, err, fmt, arg1, arg2, arg3) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) + +#define DUK_ERROR_FMT4(thr, err, fmt, arg1, arg2, arg3, arg4) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT4(thr, file, line, err, fmt, arg1, arg2, arg3, arg4) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) + +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Fatal error without context @@ -133,8 +207,7 @@ * The macro is an expression to make it compatible with DUK_ASSERT_EXPR(). */ -#define DUK_FATAL_WITHOUT_CONTEXT(msg) \ - duk_default_fatal_handler(NULL, (msg)) +#define DUK_FATAL_WITHOUT_CONTEXT(msg) duk_default_fatal_handler(NULL, (msg)) /* * Error throwing helpers @@ -159,196 +232,252 @@ * vs. non-paranoid distinction affects only a few specific errors. */ #if defined(DUK_USE_PARANOID_ERRORS) -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_require_type_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx), (expectname)); \ } while (0) -#else /* DUK_USE_PARANOID_ERRORS */ -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#else /* DUK_USE_PARANOID_ERRORS */ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_require_type_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx), (expectname)); \ } while (0) -#endif /* DUK_USE_PARANOID_ERRORS */ +#endif /* DUK_USE_PARANOID_ERRORS */ -#define DUK_ERROR_INTERNAL(thr) do { \ +#define DUK_ERROR_INTERNAL(thr) \ + do { \ duk_err_error_internal((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_INTERNAL(thr) do { \ +#define DUK_DCERROR_INTERNAL(thr) \ + do { \ DUK_ERROR_INTERNAL((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_ALLOC_FAILED(thr) do { \ +#define DUK_ERROR_ALLOC_FAILED(thr) \ + do { \ duk_err_error_alloc_failed((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_ERROR_UNSUPPORTED(thr) do { \ +#define DUK_ERROR_UNSUPPORTED(thr) \ + do { \ DUK_ERROR((thr), DUK_ERR_ERROR, DUK_STR_UNSUPPORTED); \ } while (0) -#define DUK_DCERROR_UNSUPPORTED(thr) do { \ +#define DUK_DCERROR_UNSUPPORTED(thr) \ + do { \ DUK_ERROR_UNSUPPORTED((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_ERROR(thr,msg) do { \ +#define DUK_ERROR_ERROR(thr, msg) \ + do { \ duk_err_error((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \ } while (0) -#define DUK_ERROR_RANGE_INDEX(thr,idx) do { \ +#define DUK_ERROR_RANGE_INDEX(thr, idx) \ + do { \ duk_err_range_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx)); \ } while (0) -#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) do { \ +#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) \ + do { \ duk_err_range_push_beyond((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_ERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_ARGS); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_ARGS((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_COUNT); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_COUNT((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_LENGTH); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_LENGTH((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE(thr,msg) do { \ +#define DUK_ERROR_RANGE(thr, msg) \ + do { \ duk_err_range((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \ } while (0) -#define DUK_ERROR_EVAL(thr,msg) do { \ +#define DUK_ERROR_EVAL(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_EVAL_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_REFERENCE(thr,msg) do { \ +#define DUK_ERROR_REFERENCE(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_REFERENCE_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_SYNTAX(thr,msg) do { \ +#define DUK_ERROR_SYNTAX(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_SYNTAX_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_ARGS(thr) \ + do { \ duk_err_type_invalid_args((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_TYPE_INVALID_ARGS((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type_invalid_state((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_STATE(thr) \ + do { \ DUK_ERROR_TYPE_INVALID_STATE((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type_invalid_trap_result((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ DUK_ERROR_TYPE((thr), DUK_STR_INVALID_TRAP_RESULT); \ } while (0) -#define DUK_ERROR_TYPE(thr,msg) do { \ +#define DUK_ERROR_TYPE(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_TYPE_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_URI(thr,msg) do { \ +#define DUK_ERROR_URI(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_URI_ERROR, (msg)); \ } while (0) -#else /* DUK_USE_VERBOSE_ERRORS */ +#else /* DUK_USE_VERBOSE_ERRORS */ /* Non-verbose errors for low memory targets: no file, line, or message. */ -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_INTERNAL(thr) do { \ +#define DUK_ERROR_INTERNAL(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_DCERROR_INTERNAL(thr) do { \ +#define DUK_DCERROR_INTERNAL(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_ERROR; \ } while (0) -#define DUK_ERROR_ALLOC_FAILED(thr) do { \ +#define DUK_ERROR_ALLOC_FAILED(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_ERROR_UNSUPPORTED(thr) do { \ +#define DUK_ERROR_UNSUPPORTED(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_DCERROR_UNSUPPORTED(thr) do { \ +#define DUK_DCERROR_UNSUPPORTED(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_ERROR; \ } while (0) -#define DUK_ERROR_ERROR(thr,msg) do { \ +#define DUK_ERROR_ERROR(thr, msg) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_ERROR_RANGE_INDEX(thr,idx) do { \ +#define DUK_ERROR_RANGE_INDEX(thr, idx) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) do { \ +#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_ARGS(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_COUNT(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE(thr,msg) do { \ +#define DUK_ERROR_RANGE(thr, msg) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_EVAL(thr,msg) do { \ +#define DUK_ERROR_EVAL(thr, msg) \ + do { \ duk_err_eval((thr)); \ } while (0) -#define DUK_ERROR_REFERENCE(thr,msg) do { \ +#define DUK_ERROR_REFERENCE(thr, msg) \ + do { \ duk_err_reference((thr)); \ } while (0) -#define DUK_ERROR_SYNTAX(thr,msg) do { \ +#define DUK_ERROR_SYNTAX(thr, msg) \ + do { \ duk_err_syntax((thr)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_ARGS(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_TYPE_ERROR; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_TYPE_ERROR; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_TYPE(thr,msg) do { \ +#define DUK_ERROR_TYPE(thr, msg) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_URI(thr,msg) do { \ +#define DUK_ERROR_URI(thr, msg) \ + do { \ duk_err_uri((thr)); \ } while (0) -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Assert macro: failure causes a fatal error. @@ -366,63 +495,72 @@ * we don't care about assertion text size because they're not used in production * builds. */ -#define DUK_ASSERT(x) do { \ - if (!(x)) { \ - DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x \ - " (" DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"); \ - } \ +#define DUK_ASSERT(x) \ + do { \ + if (!(x)) { \ + DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x " (" DUK_FILE_MACRO \ + ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"); \ + } \ } while (0) /* Assertion compatible inside a comma expression, evaluates to void. */ #define DUK_ASSERT_EXPR(x) \ - ((void) ((x) ? 0 : (DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x \ - " (" DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"), 0))) + ((void) ((x) ? 0 : \ + (DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x " (" DUK_FILE_MACRO \ + ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"), \ + 0))) -#else /* DUK_USE_ASSERTIONS */ +#else /* DUK_USE_ASSERTIONS */ -#define DUK_ASSERT(x) do { /* assertion omitted */ } while (0) +#define DUK_ASSERT(x) \ + do { /* assertion omitted */ \ + } while (0) -#define DUK_ASSERT_EXPR(x) ((void) 0) +#define DUK_ASSERT_EXPR(x) ((void) 0) -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* this variant is used when an assert would generate a compile warning by * being always true (e.g. >= 0 comparison for an unsigned value */ -#define DUK_ASSERT_DISABLE(x) do { /* assertion disabled */ } while (0) +#define DUK_ASSERT_DISABLE(x) \ + do { /* assertion disabled */ \ + } while (0) /* * Assertion helpers */ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) do { \ +#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) \ + do { \ DUK_ASSERT((h) == NULL || DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) (h)) > 0); \ } while (0) -#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) do { \ +#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) \ + do { \ if ((tv) != NULL && DUK_TVAL_IS_HEAP_ALLOCATED((tv))) { \ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(DUK_TVAL_GET_HEAPHDR((tv))) > 0); \ } \ } while (0) #else -#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) /* no refcount check */ -#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) /* no refcount check */ +#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) /* no refcount check */ +#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) /* no refcount check */ #endif -#define DUK_ASSERT_TOP(ctx,n) DUK_ASSERT((duk_idx_t) duk_get_top((ctx)) == (duk_idx_t) (n)) +#define DUK_ASSERT_TOP(ctx, n) DUK_ASSERT((duk_idx_t) duk_get_top((ctx)) == (duk_idx_t) (n)) #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_PACKED_TVAL) -#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) do { \ +#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) \ + do { \ duk_double_union duk__assert_tmp_du; \ duk__assert_tmp_du.d = (dval); \ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&duk__assert_tmp_du)); \ } while (0) #else -#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) /* nop */ +#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) /* nop */ #endif -#define DUK_ASSERT_VS_SPACE(thr) \ - DUK_ASSERT(thr->valstack_top < thr->valstack_end) +#define DUK_ASSERT_VS_SPACE(thr) DUK_ASSERT(thr->valstack_top < thr->valstack_end) /* * Helper to initialize a memory area (e.g. struct) with garbage when @@ -430,11 +568,14 @@ */ #if defined(DUK_USE_ASSERTIONS) -#define DUK_ASSERT_SET_GARBAGE(ptr,size) do { \ +#define DUK_ASSERT_SET_GARBAGE(ptr, size) \ + do { \ duk_memset_unsafe((void *) (ptr), 0x5a, size); \ } while (0) #else -#define DUK_ASSERT_SET_GARBAGE(ptr,size) do {} while (0) +#define DUK_ASSERT_SET_GARBAGE(ptr, size) \ + do { \ + } while (0) #endif /* @@ -445,16 +586,18 @@ * or (b) Duktape calls which involve extending the valstack (e.g. getter call). */ -#define DUK_VALSTACK_ASSERT_EXTRA 5 /* this is added to checks to allow for Duktape - * API calls in addition to function's own use - */ +#define DUK_VALSTACK_ASSERT_EXTRA \ + 5 /* this is added to checks to allow for Duktape \ + * API calls in addition to function's own use \ + */ #if defined(DUK_USE_ASSERTIONS) -#define DUK_ASSERT_VALSTACK_SPACE(thr,n) do { \ +#define DUK_ASSERT_VALSTACK_SPACE(thr, n) \ + do { \ DUK_ASSERT((thr) != NULL); \ DUK_ASSERT((thr)->valstack_end - (thr)->valstack_top >= (n) + DUK_VALSTACK_ASSERT_EXTRA); \ } while (0) #else -#define DUK_ASSERT_VALSTACK_SPACE(thr,n) /* no valstack space check */ +#define DUK_ASSERT_VALSTACK_SPACE(thr, n) /* no valstack space check */ #endif /* @@ -462,25 +605,35 @@ */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...)); -#else /* DUK_USE_VERBOSE_ERRORS */ +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg)); +DUK_NORETURN(DUK_INTERNAL_DECL void + duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...)); +#else /* DUK_USE_VERBOSE_ERRORS */ DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, duk_errcode_t code)); -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code, const char *msg, const char *filename, duk_int_t line)); +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, + duk_errcode_t code, + const char *msg, + const char *filename, + duk_int_t line)); #else DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code)); #endif DUK_NORETURN(DUK_INTERNAL_DECL void duk_error_throw_from_negative_rc(duk_hthread *thr, duk_ret_t rc)); -#define DUK_AUGMENT_FLAG_NOBLAME_FILELINE (1U << 0) /* if set, don't blame C file/line for .fileName and .lineNumber */ -#define DUK_AUGMENT_FLAG_SKIP_ONE (1U << 1) /* if set, skip topmost activation in traceback construction */ +#define DUK_AUGMENT_FLAG_NOBLAME_FILELINE (1U << 0) /* if set, don't blame C file/line for .fileName and .lineNumber */ +#define DUK_AUGMENT_FLAG_SKIP_ONE (1U << 1) /* if set, skip topmost activation in traceback construction */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *filename, duk_int_t line, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *filename, + duk_int_t line, + duk_small_uint_t flags); #endif #if defined(DUK_USE_AUGMENT_ERROR_THROW) DUK_INTERNAL_DECL void duk_err_augment_error_throw(duk_hthread *thr); @@ -488,20 +641,31 @@ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name)); +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name)); #else -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name)); +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name)); #endif DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error_alloc_failed(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_range_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range_push_beyond(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_args(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_state(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_trap_result(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -#else /* DUK_VERBOSE_ERRORS */ +#else /* DUK_VERBOSE_ERRORS */ DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_eval(duk_hthread *thr)); @@ -522,4 +686,4 @@ DUK_INTERNAL_DECL duk_hobject *duk_error_prototype_from_code(duk_hthread *thr, duk_errcode_t err_code); -#endif /* DUK_ERROR_H_INCLUDED */ +#endif /* DUK_ERROR_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_error_augment.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_error_augment.c
Changed
@@ -82,7 +82,7 @@ * when it is called and that error replaces the original one. */ - DUK_ASSERT_VALSTACK_SPACE(thr, 4); /* 3 entries actually needed below */ + DUK_ASSERT_VALSTACK_SPACE(thr, 4); /* 3 entries actually needed below */ /* ... errval */ @@ -93,23 +93,19 @@ DUK_DD(DUK_DDPRINT("error occurred when DUK_BIDX_DUKTAPE is NULL, ignoring")); return; } - tv_hnd = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, - thr->builtinsDUK_BIDX_DUKTAPE, - stridx_cb); + tv_hnd = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, thr->builtinsDUK_BIDX_DUKTAPE, stridx_cb); if (tv_hnd == NULL) { - DUK_DD(DUK_DDPRINT("error handler does not exist or is not a plain value: %!T", - (duk_tval *) tv_hnd)); + DUK_DD(DUK_DDPRINT("error handler does not exist or is not a plain value: %!T", (duk_tval *) tv_hnd)); return; } - DUK_DDD(DUK_DDDPRINT("error handler dump (callability not checked): %!T", - (duk_tval *) tv_hnd)); + DUK_DDD(DUK_DDDPRINT("error handler dump (callability not checked): %!T", (duk_tval *) tv_hnd)); duk_push_tval(thr, tv_hnd); /* ... errval errhandler */ - duk_insert(thr, -2); /* -> ... errhandler errval */ + duk_insert(thr, -2); /* -> ... errhandler errval */ duk_push_undefined(thr); - duk_insert(thr, -2); /* -> ... errhandler undefined(= this) errval */ + duk_insert(thr, -2); /* -> ... errhandler undefined(= this) errval */ /* ... errhandler undefined errval */ @@ -126,21 +122,25 @@ thr->heap->augmenting_error = 1; rc = duk_pcall_method(thr, 1); - DUK_UNREF(rc); /* no need to check now: both success and error are OK */ + DUK_UNREF(rc); /* no need to check now: both success and error are OK */ DUK_ASSERT(thr->heap->augmenting_error == 1); thr->heap->augmenting_error = 0; /* ... errval */ } -#endif /* DUK_USE_ERRTHROW || DUK_USE_ERRCREATE */ +#endif /* DUK_USE_ERRTHROW || DUK_USE_ERRCREATE */ /* * Add ._Tracedata to an error on the stack top. */ #if defined(DUK_USE_TRACEBACKS) -DUK_LOCAL void duk__add_traceback(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_LOCAL void duk__add_traceback(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { duk_activation *act; duk_int_t depth; duk_int_t arr_size; @@ -162,15 +162,14 @@ * See doc/error-objects.rst. */ - DUK_DDD(DUK_DDDPRINT("adding traceback to object: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("adding traceback to object: %!T", (duk_tval *) duk_get_tval(thr, -1))); /* Preallocate array to correct size, so that we can just write out * the _Tracedata values into the array part. */ act = thr->callstack_curr; depth = DUK_USE_TRACEBACK_DEPTH; - DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ + DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ if (depth > (duk_int_t) thr_callstack->callstack_top) { depth = (duk_int_t) thr_callstack->callstack_top; } @@ -212,7 +211,7 @@ DUK_HSTRING_INCREF(thr, s); tv++; - u32 = (duk_uint32_t) thr->compile_ctx->curr_token.start_line; /* (flags<<32) + (line), flags = 0 */ + u32 = (duk_uint32_t) thr->compile_ctx->curr_token.start_line; /* (flags<<32) + (line), flags = 0 */ DUK_TVAL_SET_U32(tv, u32); tv++; } @@ -226,13 +225,15 @@ if (c_filename) { DUK_ASSERT(DUK_TVAL_IS_STRING(thr->valstack_top - 2)); - s = DUK_TVAL_GET_STRING(thr->valstack_top - 2); /* interned c_filename */ + s = DUK_TVAL_GET_STRING(thr->valstack_top - 2); /* interned c_filename */ DUK_ASSERT(s != NULL); DUK_TVAL_SET_STRING(tv, s); DUK_HSTRING_INCREF(thr, s); tv++; - d = ((flags & DUK_AUGMENT_FLAG_NOBLAME_FILELINE) ? ((duk_double_t) DUK_TB_FLAG_NOBLAME_FILELINE) * DUK_DOUBLE_2TO32 : 0.0) + + d = ((flags & DUK_AUGMENT_FLAG_NOBLAME_FILELINE) ? + ((duk_double_t) DUK_TB_FLAG_NOBLAME_FILELINE) * DUK_DOUBLE_2TO32 : + 0.0) + (duk_double_t) c_line; DUK_TVAL_SET_DOUBLE(tv, d); tv++; @@ -247,11 +248,11 @@ /* ... arr */ - DUK_ASSERT(act != NULL); /* depth check above, assumes book-keeping is correct */ - DUK_ASSERT_DISABLE(act->pc >= 0); /* unsigned */ + DUK_ASSERT(act != NULL); /* depth check above, assumes book-keeping is correct */ + DUK_ASSERT_DISABLE(act->pc >= 0); /* unsigned */ /* Add function object. */ - tv_src = &act->tv_func; /* object (function) or lightfunc */ + tv_src = &act->tv_func; /* object (function) or lightfunc */ DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv_src) || DUK_TVAL_IS_LIGHTFUNC(tv_src)); DUK_TVAL_SET_TVAL(tv, tv_src); DUK_TVAL_INCREF(thr, tv); @@ -263,8 +264,8 @@ * PC == 0 for native code. */ pc = (duk_uint32_t) duk_hthread_get_act_prev_pc(thr_callstack, act); - DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ - DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ + DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ + DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ d = ((duk_double_t) act->flags) * DUK_DOUBLE_2TO32 + (duk_double_t) pc; DUK_TVAL_SET_DOUBLE(tv, d); tv++; @@ -289,16 +290,20 @@ /* ... error arr */ - duk_xdef_prop_stridx_short_wec(thr, -2, DUK_STRIDX_INT_TRACEDATA); /* -> ... error */ + duk_xdef_prop_stridx_short_wec(thr, -2, DUK_STRIDX_INT_TRACEDATA); /* -> ... error */ } -#endif /* DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_TRACEBACKS */ /* * Add .fileName and .lineNumber to an error on the stack top. */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) && !defined(DUK_USE_TRACEBACKS) -DUK_LOCAL void duk__add_fileline(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_LOCAL void duk__add_fileline(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { #if defined(DUK_USE_ASSERTIONS) duk_int_t entry_top; #endif @@ -336,7 +341,7 @@ duk_uint32_t ecma_line; duk_activation *act; - DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ + DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ depth = DUK_USE_TRACEBACK_DEPTH; if (depth > thr_callstack->callstack_top) { depth = thr_callstack->callstack_top; @@ -355,10 +360,12 @@ /* PC points to next instruction, find offending PC, * PC == 0 for native code. */ - pc = duk_hthread_get_act_prev_pc(thr, act); /* thr argument only used for thr->heap, so specific thread doesn't matter */ + pc = duk_hthread_get_act_prev_pc( + thr, + act); /* thr argument only used for thr->heap, so specific thread doesn't matter */ DUK_UNREF(pc); - DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ - DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ + DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ + DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ duk_push_hobject(thr, func); @@ -379,7 +386,7 @@ } else { /* Native function, no relevant lineNumber. */ } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ duk_push_u32(thr, ecma_line); /* ... error func fileName lineNumber */ @@ -398,7 +405,7 @@ duk_push_undefined(thr); } - define_props: +define_props: /* ... error lineNumber fileName */ #if defined(DUK_USE_ASSERTIONS) DUK_ASSERT(duk_get_top(thr) == entry_top + 2); @@ -406,7 +413,7 @@ duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_C | DUK_PROPDESC_FLAG_NO_OVERWRITE); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LINE_NUMBER, DUK_PROPDESC_FLAGS_C | DUK_PROPDESC_FLAG_NO_OVERWRITE); } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE && !DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE && !DUK_USE_TRACEBACKS */ /* * Add line number to a compiler error. @@ -414,7 +421,6 @@ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) DUK_LOCAL void duk__add_compiler_error_line(duk_hthread *thr) { - /* Append a "(line NNN)" to the "message" property of any error * thrown during compilation. Usually compilation errors are * SyntaxErrors but they can also be out-of-memory errors and @@ -429,8 +435,7 @@ return; } - DUK_DDD(DUK_DDDPRINT("compile error, before adding line info: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("compile error, before adding line info: %!T", (duk_tval *) duk_get_tval(thr, -1))); if (duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_MESSAGE)) { duk_bool_t at_end; @@ -452,7 +457,8 @@ (long) thr->compile_ctx->lex.window0.codepoint, (long) thr->compile_ctx->lex.window1.codepoint)); - duk_push_sprintf(thr, " (line %ld%s)", + duk_push_sprintf(thr, + " (line %ld%s)", (long) thr->compile_ctx->curr_token.start_line, at_end ? ", end of input" : ""); duk_concat(thr, 2); @@ -461,10 +467,9 @@ duk_pop(thr); } - DUK_DDD(DUK_DDDPRINT("compile error, after adding line info: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("compile error, after adding line info: %!T", (duk_tval *) duk_get_tval(thr, -1))); } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error being created using Duktape specific properties @@ -472,7 +477,12 @@ */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_LOCAL void duk__err_augment_builtin_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_hobject *obj, duk_small_uint_t flags) { +DUK_LOCAL void duk__err_augment_builtin_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_hobject *obj, + duk_small_uint_t flags) { #if defined(DUK_USE_ASSERTIONS) duk_int_t entry_top; #endif @@ -482,7 +492,7 @@ #endif DUK_ASSERT(obj != NULL); - DUK_UNREF(obj); /* unreferenced w/o tracebacks */ + DUK_UNREF(obj); /* unreferenced w/o tracebacks */ duk__add_compiler_error_line(thr); @@ -507,7 +517,7 @@ DUK_ASSERT(duk_get_top(thr) == entry_top); #endif } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error at creation time with _Tracedata/fileName/lineNumber @@ -525,7 +535,11 @@ */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_INTERNAL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_INTERNAL void duk_err_augment_error_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { duk_hobject *obj; DUK_ASSERT(thr != NULL); @@ -571,7 +585,7 @@ duk__err_augment_user(thr, DUK_STRIDX_ERR_CREATE); #endif } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error at throw time; allow a user error handler (if defined) @@ -583,6 +597,6 @@ DUK_INTERNAL void duk_err_augment_error_throw(duk_hthread *thr) { #if defined(DUK_USE_ERRTHROW) duk__err_augment_user(thr, DUK_STRIDX_ERR_THROW); -#endif /* DUK_USE_ERRTHROW */ +#endif /* DUK_USE_ERRTHROW */ } -#endif /* DUK_USE_AUGMENT_ERROR_THROW */ +#endif /* DUK_USE_AUGMENT_ERROR_THROW */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_error_longjmp.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_error_longjmp.c
Changed
@@ -47,8 +47,10 @@ DUK_ASSERT(thr->heap != NULL); DUK_DD(DUK_DDPRINT("longjmp error: type=%d iserror=%d value1=%!T value2=%!T", - (int) thr->heap->lj.type, (int) thr->heap->lj.iserror, - &thr->heap->lj.value1, &thr->heap->lj.value2)); + (int) thr->heap->lj.type, + (int) thr->heap->lj.iserror, + &thr->heap->lj.value1, + &thr->heap->lj.value2)); /* Prevent finalizer execution during error handling. All error * handling sites will process pending finalizers once error handling @@ -66,11 +68,11 @@ DUK_ASSERT_LJSTATE_SET(thr->heap); thr->heap->pf_prevent_count++; - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ #if defined(DUK_USE_ASSERTIONS) /* XXX: set this immediately when longjmp state is set */ - DUK_ASSERT(thr->heap->error_not_allowed == 0); /* Detect error within critical section. */ + DUK_ASSERT(thr->heap->error_not_allowed == 0); /* Detect error within critical section. */ thr->heap->error_not_allowed = 1; #endif @@ -82,8 +84,10 @@ */ if (!thr->heap->lj.jmpbuf_ptr) { DUK_D(DUK_DPRINT("uncaught error: type=%d iserror=%d value1=%!T value2=%!T", - (int) thr->heap->lj.type, (int) thr->heap->lj.iserror, - &thr->heap->lj.value1, &thr->heap->lj.value2)); + (int) thr->heap->lj.type, + (int) thr->heap->lj.iserror, + &thr->heap->lj.value1, + &thr->heap->lj.value2)); #if defined(DUK_USE_PREFER_SIZE) duk__uncaught_minimal(thr); @@ -94,7 +98,7 @@ } #if defined(DUK_USE_CPP_EXCEPTIONS) - throw duk_internal_exception(); /* dummy */ + throw duk_internal_exception(); /* dummy */ #else DUK_LONGJMP(thr->heap->lj.jmpbuf_ptr->jb); #endif
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_error_macros.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_error_macros.c
Changed
@@ -4,31 +4,43 @@ #include "duk_internal.h" -#define DUK__ERRFMT_BUFSIZE 256 /* size for formatting buffers */ +#define DUK__ERRFMT_BUFSIZE 256 /* size for formatting buffers */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_INTERNAL DUK_COLD void duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...) { +DUK_INTERNAL DUK_COLD void duk_err_handle_error_fmt(duk_hthread *thr, + const char *filename, + duk_uint_t line_and_code, + const char *fmt, + ...) { va_list ap; char msgDUK__ERRFMT_BUFSIZE; va_start(ap, fmt); (void) DUK_VSNPRINTF(msg, sizeof(msg), fmt, ap); msgsizeof(msg) - 1 = (char) 0; - duk_err_create_and_throw(thr, (duk_errcode_t) (line_and_code >> 24), msg, filename, (duk_int_t) (line_and_code & 0x00ffffffL)); - va_end(ap); /* dead code, but ensures portability (see Linux man page notes) */ + duk_err_create_and_throw(thr, + (duk_errcode_t) (line_and_code >> 24), + msg, + filename, + (duk_int_t) (line_and_code & 0x00ffffffL)); + va_end(ap); /* dead code, but ensures portability (see Linux man page notes) */ } DUK_INTERNAL DUK_COLD void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg) { - duk_err_create_and_throw(thr, (duk_errcode_t) (line_and_code >> 24), msg, filename, (duk_int_t) (line_and_code & 0x00ffffffL)); + duk_err_create_and_throw(thr, + (duk_errcode_t) (line_and_code >> 24), + msg, + filename, + (duk_int_t) (line_and_code & 0x00ffffffL)); } -#else /* DUK_USE_VERBOSE_ERRORS */ +#else /* DUK_USE_VERBOSE_ERRORS */ DUK_INTERNAL DUK_COLD void duk_err_handle_error(duk_hthread *thr, duk_errcode_t code) { duk_err_create_and_throw(thr, code); } -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Error throwing helpers @@ -36,14 +48,34 @@ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) -DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name) { - DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)", - expect_name, duk_get_type_name(thr, idx), (long) idx); +DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name) { + DUK_ERROR_RAW_FMT3(thr, + filename, + linenumber, + DUK_ERR_TYPE_ERROR, + "%s required, found %s (stack index %ld)", + expect_name, + duk_get_type_name(thr, idx), + (long) idx); } #else -DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name) { - DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)", - expect_name, duk_push_string_readable(thr, idx), (long) idx); +DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name) { + DUK_ERROR_RAW_FMT3(thr, + filename, + linenumber, + DUK_ERR_TYPE_ERROR, + "%s required, found %s (stack index %ld)", + expect_name, + duk_push_string_readable(thr, idx), + (long) idx); } #endif DUK_INTERNAL DUK_COLD void duk_err_error_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_error_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_error_misc.c
Changed
@@ -26,14 +26,14 @@ for (act = thr->callstack_curr; act != NULL; act = act->parent) { for (cat = act->cat; cat != NULL; cat = cat->parent) { if (DUK_CAT_HAS_CATCH_ENABLED(cat)) { - return 1; /* all we need to know */ + return 1; /* all we need to know */ } } } } return 0; } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Get prototype object for an integer error code. @@ -83,11 +83,10 @@ * config options. */ - if (!duk_debug_is_attached(thr->heap) || - thr->heap->dbg_processing || - thr->heap->lj.type != DUK_LJ_TYPE_THROW || + if (!duk_debug_is_attached(thr->heap) || thr->heap->dbg_processing || thr->heap->lj.type != DUK_LJ_TYPE_THROW || thr->heap->creating_error) { - DUK_D(DUK_DPRINT("skip debugger error integration; not attached, debugger processing, not THROW, or error thrown while creating error")); + DUK_D(DUK_DPRINT("skip debugger error integration; not attached, debugger processing, not THROW, or error thrown " + "while creating error")); return; } @@ -115,7 +114,7 @@ /* Store and reset longjmp state. */ DUK_ASSERT_LJSTATE_SET(thr->heap); DUK_TVAL_DECREF_NORZ(thr, tv_obj); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&thr->heap->lj.value2)); /* Always for THROW type. */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&thr->heap->lj.value2)); /* Always for THROW type. */ DUK_TVAL_SET_UNDEFINED(tv_obj); thr->heap->lj.type = DUK_LJ_TYPE_UNKNOWN; DUK_ASSERT_LJSTATE_UNSET(thr->heap); @@ -150,7 +149,7 @@ duk_pop(thr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Helpers for setting up heap longjmp state.
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_error_throw.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_error_throw.c
Changed
@@ -21,14 +21,20 @@ */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code, const char *msg, const char *filename, duk_int_t line) { +DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, + duk_errcode_t code, + const char *msg, + const char *filename, + duk_int_t line) { #else DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code) { #endif #if defined(DUK_USE_VERBOSE_ERRORS) DUK_DD(DUK_DDPRINT("duk_err_create_and_throw(): code=%ld, msg=%s, filename=%s, line=%ld", - (long) code, (const char *) msg, - (const char *) filename, (long) line)); + (long) code, + (const char *) msg, + (const char *) filename, + (long) line)); #else DUK_DD(DUK_DDPRINT("duk_err_create_and_throw(): code=%ld", (long) code)); #endif @@ -88,18 +94,9 @@ * use 'msg' as a format string directly. */ #if defined(DUK_USE_VERBOSE_ERRORS) - duk_push_error_object_raw(thr, - code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - filename, - line, - "%s", - (const char *) msg); + duk_push_error_object_raw(thr, code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, filename, line, "%s", (const char *) msg); #else - duk_push_error_object_raw(thr, - code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - NULL, - 0, - NULL); + duk_push_error_object_raw(thr, code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, NULL, 0, NULL); #endif /* Note that an alloc error may happen during error augmentation. @@ -109,8 +106,7 @@ * avoiding it for alloc errors (this differs from Duktape 1.x). */ #if defined(DUK_USE_AUGMENT_ERROR_THROW) - DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT (before throw augment)", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT (before throw augment)", (duk_tval *) duk_get_tval(thr, -1))); duk_err_augment_error_throw(thr); #endif @@ -133,7 +129,8 @@ */ DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT, %!iT (after throw augment)", - (duk_tval *) &thr->heap->lj.value1, (duk_tval *) &thr->heap->lj.value2)); + (duk_tval *) &thr->heap->lj.value1, + (duk_tval *) &thr->heap->lj.value2)); duk_err_longjmp(thr); DUK_UNREACHABLE();
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_exception.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_exception.h
Changed
@@ -22,9 +22,10 @@ * aware of the "unsafe to continue" semantics. */ class duk_fatal_exception : public virtual std::runtime_error { - public: - duk_fatal_exception(const char *message) : std::runtime_error(message) {} + public: + duk_fatal_exception(const char *message) : std::runtime_error(message) { + } }; #endif -#endif /* DUK_EXCEPTION_H_INCLUDED */ +#endif /* DUK_EXCEPTION_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_fltunion.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_fltunion.h
Changed
@@ -17,23 +17,23 @@ typedef union duk_float_union duk_float_union; #if defined(DUK_USE_DOUBLE_LE) || defined(DUK_USE_DOUBLE_ME) -#define DUK_FLT_IDX_UI0 0 -#define DUK_FLT_IDX_US0 1 -#define DUK_FLT_IDX_US1 0 -#define DUK_FLT_IDX_UC0 3 -#define DUK_FLT_IDX_UC1 2 -#define DUK_FLT_IDX_UC2 1 -#define DUK_FLT_IDX_UC3 0 +#define DUK_FLT_IDX_UI0 0 +#define DUK_FLT_IDX_US0 1 +#define DUK_FLT_IDX_US1 0 +#define DUK_FLT_IDX_UC0 3 +#define DUK_FLT_IDX_UC1 2 +#define DUK_FLT_IDX_UC2 1 +#define DUK_FLT_IDX_UC3 0 #elif defined(DUK_USE_DOUBLE_BE) -#define DUK_FLT_IDX_UI0 0 -#define DUK_FLT_IDX_US0 0 -#define DUK_FLT_IDX_US1 1 -#define DUK_FLT_IDX_UC0 0 -#define DUK_FLT_IDX_UC1 1 -#define DUK_FLT_IDX_UC2 2 -#define DUK_FLT_IDX_UC3 3 +#define DUK_FLT_IDX_UI0 0 +#define DUK_FLT_IDX_US0 0 +#define DUK_FLT_IDX_US1 1 +#define DUK_FLT_IDX_UC0 0 +#define DUK_FLT_IDX_UC1 1 +#define DUK_FLT_IDX_UC2 2 +#define DUK_FLT_IDX_UC3 3 #else #error internal error #endif -#endif /* DUK_FLTUNION_H_INCLUDED */ +#endif /* DUK_FLTUNION_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_forwdecl.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_forwdecl.h
Changed
@@ -131,4 +131,4 @@ typedef struct duk_re_matcher_ctx duk_re_matcher_ctx; typedef struct duk_re_compiler_ctx duk_re_compiler_ctx; -#endif /* DUK_FORWDECL_H_INCLUDED */ +#endif /* DUK_FORWDECL_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_harray.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_harray.h
Changed
@@ -11,15 +11,26 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_harray_assert_valid(duk_harray *h); -#define DUK_HARRAY_ASSERT_VALID(h) do { duk_harray_assert_valid((h)); } while (0) +#define DUK_HARRAY_ASSERT_VALID(h) \ + do { \ + duk_harray_assert_valid((h)); \ + } while (0) #else -#define DUK_HARRAY_ASSERT_VALID(h) do {} while (0) +#define DUK_HARRAY_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#define DUK_HARRAY_LENGTH_WRITABLE(h) (!(h)->length_nonwritable) -#define DUK_HARRAY_LENGTH_NONWRITABLE(h) ((h)->length_nonwritable) -#define DUK_HARRAY_SET_LENGTH_WRITABLE(h) do { (h)->length_nonwritable = 0; } while (0) -#define DUK_HARRAY_SET_LENGTH_NONWRITABLE(h) do { (h)->length_nonwritable = 1; } while (0) +#define DUK_HARRAY_LENGTH_WRITABLE(h) (!(h)->length_nonwritable) +#define DUK_HARRAY_LENGTH_NONWRITABLE(h) ((h)->length_nonwritable) +#define DUK_HARRAY_SET_LENGTH_WRITABLE(h) \ + do { \ + (h)->length_nonwritable = 0; \ + } while (0) +#define DUK_HARRAY_SET_LENGTH_NONWRITABLE(h) \ + do { \ + (h)->length_nonwritable = 1; \ + } while (0) struct duk_harray { /* Shared object part. */ @@ -45,4 +56,4 @@ duk_bool_t length_nonwritable; }; -#endif /* DUK_HARRAY_H_INCLUDED */ +#endif /* DUK_HARRAY_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hboundfunc.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hboundfunc.h
Changed
@@ -12,9 +12,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hboundfunc_assert_valid(duk_hboundfunc *h); -#define DUK_HBOUNDFUNC_ASSERT_VALID(h) do { duk_hboundfunc_assert_valid((h)); } while (0) +#define DUK_HBOUNDFUNC_ASSERT_VALID(h) \ + do { \ + duk_hboundfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HBOUNDFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HBOUNDFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hboundfunc { @@ -30,8 +35,8 @@ duk_tval this_binding; /* Arguments to prepend. */ - duk_tval *args; /* Separate allocation. */ + duk_tval *args; /* Separate allocation. */ duk_idx_t nargs; }; -#endif /* DUK_HBOUNDFUNC_H_INCLUDED */ +#endif /* DUK_HBOUNDFUNC_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hbuffer.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hbuffer.h
Changed
@@ -20,17 +20,17 @@ * External buffer: DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL */ -#define DUK_HBUFFER_FLAG_DYNAMIC DUK_HEAPHDR_USER_FLAG(0) /* buffer is behind a pointer, dynamic or external */ -#define DUK_HBUFFER_FLAG_EXTERNAL DUK_HEAPHDR_USER_FLAG(1) /* buffer pointer is to an externally allocated buffer */ +#define DUK_HBUFFER_FLAG_DYNAMIC DUK_HEAPHDR_USER_FLAG(0) /* buffer is behind a pointer, dynamic or external */ +#define DUK_HBUFFER_FLAG_EXTERNAL DUK_HEAPHDR_USER_FLAG(1) /* buffer pointer is to an externally allocated buffer */ -#define DUK_HBUFFER_HAS_DYNAMIC(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_HAS_EXTERNAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_HAS_DYNAMIC(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_HAS_EXTERNAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) -#define DUK_HBUFFER_SET_DYNAMIC(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_SET_EXTERNAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_SET_DYNAMIC(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_SET_EXTERNAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) -#define DUK_HBUFFER_CLEAR_DYNAMIC(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_CLEAR_EXTERNAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_CLEAR_DYNAMIC(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_CLEAR_EXTERNAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) /* * Misc defines @@ -43,12 +43,12 @@ */ #if defined(DUK_USE_BUFLEN16) -#define DUK_HBUFFER_MAX_BYTELEN (0x0000ffffUL) +#define DUK_HBUFFER_MAX_BYTELEN (0x0000ffffUL) #else /* Intentionally not 0x7fffffffUL; at least JSON code expects that * 2*len + 2 fits in 32 bits. */ -#define DUK_HBUFFER_MAX_BYTELEN (0x7ffffffeUL) +#define DUK_HBUFFER_MAX_BYTELEN (0x7ffffffeUL) #endif /* @@ -57,60 +57,70 @@ #if defined(DUK_USE_BUFLEN16) /* size stored in duk_heaphdr unused flag bits */ -#define DUK_HBUFFER_GET_SIZE(x) ((x)->hdr.h_flags >> 16) -#define DUK_HBUFFER_SET_SIZE(x,v) do { \ +#define DUK_HBUFFER_GET_SIZE(x) ((x)->hdr.h_flags >> 16) +#define DUK_HBUFFER_SET_SIZE(x, v) \ + do { \ duk_size_t duk__v; \ duk__v = (v); \ DUK_ASSERT(duk__v <= 0xffffUL); \ (x)->hdr.h_flags = ((x)->hdr.h_flags & 0x0000ffffUL) | (((duk_uint32_t) duk__v) << 16); \ } while (0) -#define DUK_HBUFFER_ADD_SIZE(x,dv) do { \ +#define DUK_HBUFFER_ADD_SIZE(x, dv) \ + do { \ (x)->hdr.h_flags += ((dv) << 16); \ } while (0) -#define DUK_HBUFFER_SUB_SIZE(x,dv) do { \ +#define DUK_HBUFFER_SUB_SIZE(x, dv) \ + do { \ (x)->hdr.h_flags -= ((dv) << 16); \ } while (0) #else -#define DUK_HBUFFER_GET_SIZE(x) (((duk_hbuffer *) (x))->size) -#define DUK_HBUFFER_SET_SIZE(x,v) do { \ +#define DUK_HBUFFER_GET_SIZE(x) (((duk_hbuffer *) (x))->size) +#define DUK_HBUFFER_SET_SIZE(x, v) \ + do { \ ((duk_hbuffer *) (x))->size = (v); \ } while (0) -#define DUK_HBUFFER_ADD_SIZE(x,dv) do { \ +#define DUK_HBUFFER_ADD_SIZE(x, dv) \ + do { \ (x)->size += (dv); \ } while (0) -#define DUK_HBUFFER_SUB_SIZE(x,dv) do { \ +#define DUK_HBUFFER_SUB_SIZE(x, dv) \ + do { \ (x)->size -= (dv); \ } while (0) #endif -#define DUK_HBUFFER_FIXED_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_FIXED_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x)) +#define DUK_HBUFFER_FIXED_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) +#define DUK_HBUFFER_FIXED_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x)) #define DUK_HBUFFER_DYNAMIC_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_DYNAMIC_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) -#define DUK_HBUFFER_DYNAMIC_ADD_SIZE(x,dv) DUK_HBUFFER_ADD_SIZE((duk_hbuffer *) (x), (dv)) -#define DUK_HBUFFER_DYNAMIC_SUB_SIZE(x,dv) DUK_HBUFFER_SUB_SIZE((duk_hbuffer *) (x), (dv)) +#define DUK_HBUFFER_DYNAMIC_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) +#define DUK_HBUFFER_DYNAMIC_ADD_SIZE(x, dv) DUK_HBUFFER_ADD_SIZE((duk_hbuffer *) (x), (dv)) +#define DUK_HBUFFER_DYNAMIC_SUB_SIZE(x, dv) DUK_HBUFFER_SUB_SIZE((duk_hbuffer *) (x), (dv)) #define DUK_HBUFFER_EXTERNAL_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_EXTERNAL_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) +#define DUK_HBUFFER_EXTERNAL_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) -#define DUK_HBUFFER_FIXED_GET_DATA_PTR(heap,x) ((duk_uint8_t *) (((duk_hbuffer_fixed *) (void *) (x)) + 1)) +#define DUK_HBUFFER_FIXED_GET_DATA_PTR(heap, x) ((duk_uint8_t *) (((duk_hbuffer_fixed *) (void *) (x)) + 1)) #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap,x) \ +#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, x) \ ((void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (x))->h_extra16)) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, x, v) \ + do { \ ((duk_heaphdr *) (x))->h_extra16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap,x) do { \ - ((duk_heaphdr *) (x))->h_extra16 = 0; /* assume 0 <=> NULL */ \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap, x) \ + do { \ + ((duk_heaphdr *) (x))->h_extra16 = 0; /* assume 0 <=> NULL */ \ } while (0) #else -#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap,x) ((x)->curr_alloc) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, x) ((x)->curr_alloc) +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #endif @@ -119,21 +129,23 @@ * Duktape heap. */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap,x) \ - ((void *) (x)->curr_alloc) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap, x) ((void *) (x)->curr_alloc) +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #else -#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap,x) \ - ((void *) (x)->curr_alloc) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap, x) ((void *) (x)->curr_alloc) +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #endif @@ -142,32 +154,31 @@ * size). May be NULL for zero size dynamic/external buffer. */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_GET_DATA_PTR(heap,x) ( \ - DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ - ( \ - DUK_HBUFFER_HAS_EXTERNAL((x)) ? \ - DUK_HBUFFER_EXTERNAL_GET_DATA_PTR((heap), (duk_hbuffer_external *) (x)) : \ - DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) \ - ) : \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x)) \ - ) +#define DUK_HBUFFER_GET_DATA_PTR(heap, x) \ + (DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ + (DUK_HBUFFER_HAS_EXTERNAL((x)) ? DUK_HBUFFER_EXTERNAL_GET_DATA_PTR((heap), (duk_hbuffer_external *) (x)) : \ + DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x))) : \ + DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x))) #else /* Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external * have the same layout so checking for fixed vs. dynamic (or external) is enough. */ -#define DUK_HBUFFER_GET_DATA_PTR(heap,x) ( \ - DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ - DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) : \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x)) \ - ) +#define DUK_HBUFFER_GET_DATA_PTR(heap, x) \ + (DUK_HBUFFER_HAS_DYNAMIC((x)) ? DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) : \ + DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x))) #endif /* Validity assert. */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hbuffer_assert_valid(duk_hbuffer *h); -#define DUK_HBUFFER_ASSERT_VALID(h) do { duk_hbuffer_assert_valid((h)); } while (0) +#define DUK_HBUFFER_ASSERT_VALID(h) \ + do { \ + duk_hbuffer_assert_valid((h)); \ + } while (0) #else -#define DUK_HBUFFER_ASSERT_VALID(h) do {} while (0) +#define DUK_HBUFFER_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -265,9 +276,9 @@ */ } #if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_GCC_ATTR) -__attribute__ ((aligned (8))) +__attribute__((aligned(8))) #elif (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_CLANG_ATTR) -__attribute__ ((aligned (8))) +__attribute__((aligned(8))) #endif ; #if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_MSVC_PRAGMA) @@ -290,7 +301,7 @@ #if defined(DUK_USE_HEAPPTR16) /* Stored in duk_heaphdr h_extra16. */ #else - void *curr_alloc; /* may be NULL if alloc_size == 0 */ + void *curr_alloc; /* may be NULL if alloc_size == 0 */ #endif /* @@ -319,7 +330,7 @@ /* Cannot be compressed as a heap pointer because may point to * an arbitrary address. */ - void *curr_alloc; /* may be NULL if alloc_size == 0 */ + void *curr_alloc; /* may be NULL if alloc_size == 0 */ }; /* @@ -327,10 +338,10 @@ */ DUK_INTERNAL_DECL duk_hbuffer *duk_hbuffer_alloc(duk_heap *heap, duk_size_t size, duk_small_uint_t flags, void **out_bufdata); -DUK_INTERNAL_DECL void *duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud); /* indirect allocs */ +DUK_INTERNAL_DECL void *duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud); /* indirect allocs */ /* dynamic buffer ops */ DUK_INTERNAL_DECL void duk_hbuffer_resize(duk_hthread *thr, duk_hbuffer_dynamic *buf, duk_size_t new_size); DUK_INTERNAL_DECL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *buf); -#endif /* DUK_HBUFFER_H_INCLUDED */ +#endif /* DUK_HBUFFER_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hbuffer_alloc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hbuffer_alloc.c
Changed
@@ -25,7 +25,7 @@ */ if (size > DUK_HBUFFER_MAX_BYTELEN) { DUK_D(DUK_DPRINT("hbuffer alloc failed: size too large: %ld", (long) size)); - return NULL; /* no need to write 'out_bufdata' */ + return NULL; /* no need to write 'out_bufdata' */ } if (flags & DUK_BUF_FLAG_EXTERNAL) { @@ -37,7 +37,7 @@ } else { header_size = sizeof(duk_hbuffer_fixed); alloc_size = sizeof(duk_hbuffer_fixed) + size; - DUK_ASSERT(alloc_size >= sizeof(duk_hbuffer_fixed)); /* no wrapping */ + DUK_ASSERT(alloc_size >= sizeof(duk_hbuffer_fixed)); /* no wrapping */ } res = (duk_hbuffer *) DUK_ALLOC(heap, alloc_size); @@ -47,8 +47,7 @@ /* zero everything unless requested not to do so */ #if defined(DUK_USE_ZERO_BUFFER_DATA) - duk_memzero((void *) res, - (flags & DUK_BUF_FLAG_NOZERO) ? header_size : alloc_size); + duk_memzero((void *) res, (flags & DUK_BUF_FLAG_NOZERO) ? header_size : alloc_size); #else duk_memzero((void *) res, header_size); #endif @@ -71,7 +70,7 @@ void *ptr; if (size > 0) { - DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); /* alloc external with size zero */ + DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); /* alloc external with size zero */ DUK_DDD(DUK_DDDPRINT("dynamic buffer with nonzero size, alloc actual buffer")); #if defined(DUK_USE_ZERO_BUFFER_DATA) ptr = DUK_ALLOC_ZEROED(heap, size); @@ -111,16 +110,16 @@ } else { DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); } - DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, &res->hdr); + DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, &res->hdr); DUK_DDD(DUK_DDDPRINT("allocated hbuffer: %p", (void *) res)); return res; - alloc_error: +alloc_error: DUK_DD(DUK_DDPRINT("hbuffer allocation failed")); DUK_FREE(heap, res); - return NULL; /* no need to write 'out_bufdata' */ + return NULL; /* no need to write 'out_bufdata' */ } /* For indirect allocs. */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hbuffer_assert.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hbuffer_assert.c
Changed
@@ -10,4 +10,4 @@ DUK_ASSERT(h != NULL); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hbuffer_ops.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hbuffer_ops.c
Changed
@@ -53,8 +53,7 @@ if (new_size > prev_size) { DUK_ASSERT(new_size - prev_size > 0); #if defined(DUK_USE_ZERO_BUFFER_DATA) - duk_memzero((void *) ((char *) res + prev_size), - (duk_size_t) (new_size - prev_size)); + duk_memzero((void *) ((char *) res + prev_size), (duk_size_t) (new_size - prev_size)); #endif }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hbufobj.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hbufobj.h
Changed
@@ -8,31 +8,37 @@ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) /* All element accessors are host endian now (driven by TypedArray spec). */ -#define DUK_HBUFOBJ_ELEM_UINT8 0 -#define DUK_HBUFOBJ_ELEM_UINT8CLAMPED 1 -#define DUK_HBUFOBJ_ELEM_INT8 2 -#define DUK_HBUFOBJ_ELEM_UINT16 3 -#define DUK_HBUFOBJ_ELEM_INT16 4 -#define DUK_HBUFOBJ_ELEM_UINT32 5 -#define DUK_HBUFOBJ_ELEM_INT32 6 -#define DUK_HBUFOBJ_ELEM_FLOAT32 7 -#define DUK_HBUFOBJ_ELEM_FLOAT64 8 -#define DUK_HBUFOBJ_ELEM_MAX 8 +#define DUK_HBUFOBJ_ELEM_UINT8 0 +#define DUK_HBUFOBJ_ELEM_UINT8CLAMPED 1 +#define DUK_HBUFOBJ_ELEM_INT8 2 +#define DUK_HBUFOBJ_ELEM_UINT16 3 +#define DUK_HBUFOBJ_ELEM_INT16 4 +#define DUK_HBUFOBJ_ELEM_UINT32 5 +#define DUK_HBUFOBJ_ELEM_INT32 6 +#define DUK_HBUFOBJ_ELEM_FLOAT32 7 +#define DUK_HBUFOBJ_ELEM_FLOAT64 8 +#define DUK_HBUFOBJ_ELEM_MAX 8 #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hbufobj_assert_valid(duk_hbufobj *h); -#define DUK_HBUFOBJ_ASSERT_VALID(h) do { duk_hbufobj_assert_valid((h)); } while (0) +#define DUK_HBUFOBJ_ASSERT_VALID(h) \ + do { \ + duk_hbufobj_assert_valid((h)); \ + } while (0) #else -#define DUK_HBUFOBJ_ASSERT_VALID(h) do {} while (0) +#define DUK_HBUFOBJ_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* Get the current data pointer (caller must ensure buf != NULL) as a * duk_uint8_t ptr. Note that the result may be NULL if the underlying * buffer has zero size and is not a fixed buffer. */ -#define DUK_HBUFOBJ_GET_SLICE_BASE(heap,h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - (((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR((heap), (h)->buf)) + (h)->offset)) +#define DUK_HBUFOBJ_GET_SLICE_BASE(heap, h) \ + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + (((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR((heap), (h)->buf)) + (h)->offset)) /* True if slice is full, i.e. offset is zero and length covers the entire * buffer. This status may change independently of the duk_hbufobj if @@ -40,15 +46,17 @@ * being changed. */ #define DUK_HBUFOBJ_FULL_SLICE(h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset == 0 && (h)->length == DUK_HBUFFER_GET_SIZE((h)->buf))) + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + ((h)->offset == 0 && (h)->length == DUK_HBUFFER_GET_SIZE((h)->buf))) /* Validate that the whole slice 0,length is contained in the underlying * buffer. Caller must ensure 'buf' != NULL. */ #define DUK_HBUFOBJ_VALID_SLICE(h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (h)->length <= DUK_HBUFFER_GET_SIZE((h)->buf))) + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + ((h)->offset + (h)->length <= DUK_HBUFFER_GET_SIZE((h)->buf))) /* Validate byte read/write for virtual 'offset', i.e. check that the * offset, taking into account h->offset, is within the underlying @@ -57,13 +65,11 @@ * behavior (e.g. if an underlying dynamic buffer changes after being * setup). Caller must ensure 'buf' != NULL. */ -#define DUK_HBUFOBJ_VALID_BYTEOFFSET_INCL(h,off) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf))) +#define DUK_HBUFOBJ_VALID_BYTEOFFSET_INCL(h, off) \ + (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), ((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf))) -#define DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h,off) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (off) <= DUK_HBUFFER_GET_SIZE((h)->buf))) +#define DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h, off) \ + (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), ((h)->offset + (off) <= DUK_HBUFFER_GET_SIZE((h)->buf))) /* Clamp an input byte length (already assumed to be within the nominal * duk_hbufobj 'length') to the current dynamic buffer limits to yield @@ -71,12 +77,10 @@ * be invalidated by any side effect because it may trigger a user * callback that resizes the underlying buffer. */ -#define DUK_HBUFOBJ_CLAMP_BYTELENGTH(h,len) \ - (DUK_ASSERT_EXPR((h) != NULL), \ - duk_hbufobj_clamp_bytelength((h), (len))) +#define DUK_HBUFOBJ_CLAMP_BYTELENGTH(h, len) (DUK_ASSERT_EXPR((h) != NULL), duk_hbufobj_clamp_bytelength((h), (len))) /* Typed arrays have virtual indices, ArrayBuffer and DataView do not. */ -#define DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h) ((h)->is_typedarray) +#define DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h) ((h)->is_typedarray) struct duk_hbufobj { /* Shared object part. */ @@ -101,27 +105,33 @@ * be dynamic and its pointer unstable. */ - duk_uint_t offset; /* byte offset to buf */ - duk_uint_t length; /* byte index limit for element access, exclusive */ - duk_uint8_t shift; /* element size shift: - * 0 = u8/i8 - * 1 = u16/i16 - * 2 = u32/i32/float - * 3 = double - */ - duk_uint8_t elem_type; /* element type */ + duk_uint_t offset; /* byte offset to buf */ + duk_uint_t length; /* byte index limit for element access, exclusive */ + duk_uint8_t shift; /* element size shift: + * 0 = u8/i8 + * 1 = u16/i16 + * 2 = u32/i32/float + * 3 = double + */ + duk_uint8_t elem_type; /* element type */ duk_uint8_t is_typedarray; }; DUK_INTERNAL_DECL duk_uint_t duk_hbufobj_clamp_bytelength(duk_hbufobj *h_bufobj, duk_uint_t len); DUK_INTERNAL_DECL void duk_hbufobj_push_uint8array_from_plain(duk_hthread *thr, duk_hbuffer *h_buf); -DUK_INTERNAL_DECL void duk_hbufobj_push_validated_read(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size); -DUK_INTERNAL_DECL void duk_hbufobj_validated_write(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size); +DUK_INTERNAL_DECL void duk_hbufobj_push_validated_read(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size); +DUK_INTERNAL_DECL void duk_hbufobj_validated_write(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size); DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_hthread *thr, duk_idx_t idx); -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* nothing */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ -#endif /* DUK_HBUFOBJ_H_INCLUDED */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_HBUFOBJ_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hbufobj_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hbufobj_misc.c
Changed
@@ -17,4 +17,4 @@ return buf_avail >= len ? len : buf_avail; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hcompfunc.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hcompfunc.h
Changed
@@ -15,50 +15,55 @@ /* XXX: casts could be improved, especially for GET/SET DATA */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HCOMPFUNC_GET_DATA(heap,h) \ - ((duk_hbuffer_fixed *) (void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->data16)) -#define DUK_HCOMPFUNC_SET_DATA(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_DATA(heap, h) ((duk_hbuffer_fixed *) (void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->data16)) +#define DUK_HCOMPFUNC_SET_DATA(heap, h, v) \ + do { \ (h)->data16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_FUNCS(heap,h) \ - ((duk_hobject **) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->funcs16))) -#define DUK_HCOMPFUNC_SET_FUNCS(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_FUNCS(heap, h) ((duk_hobject **) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->funcs16))) +#define DUK_HCOMPFUNC_SET_FUNCS(heap, h, v) \ + do { \ (h)->funcs16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_BYTECODE(heap,h) \ - ((duk_instr_t *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->bytecode16))) -#define DUK_HCOMPFUNC_SET_BYTECODE(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_BYTECODE(heap, h) ((duk_instr_t *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->bytecode16))) +#define DUK_HCOMPFUNC_SET_BYTECODE(heap, h, v) \ + do { \ (h)->bytecode16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_LEXENV(heap,h) \ - ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->lex_env16))) -#define DUK_HCOMPFUNC_SET_LEXENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_LEXENV(heap, h) ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->lex_env16))) +#define DUK_HCOMPFUNC_SET_LEXENV(heap, h, v) \ + do { \ (h)->lex_env16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_VARENV(heap,h) \ - ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->var_env16))) -#define DUK_HCOMPFUNC_SET_VARENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_VARENV(heap, h) ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->var_env16))) +#define DUK_HCOMPFUNC_SET_VARENV(heap, h, v) \ + do { \ (h)->var_env16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) #else -#define DUK_HCOMPFUNC_GET_DATA(heap,h) ((duk_hbuffer_fixed *) (void *) (h)->data) -#define DUK_HCOMPFUNC_SET_DATA(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_DATA(heap, h) ((duk_hbuffer_fixed *) (void *) (h)->data) +#define DUK_HCOMPFUNC_SET_DATA(heap, h, v) \ + do { \ (h)->data = (duk_hbuffer *) (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_FUNCS(heap,h) ((h)->funcs) -#define DUK_HCOMPFUNC_SET_FUNCS(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_FUNCS(heap, h) ((h)->funcs) +#define DUK_HCOMPFUNC_SET_FUNCS(heap, h, v) \ + do { \ (h)->funcs = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_BYTECODE(heap,h) ((h)->bytecode) -#define DUK_HCOMPFUNC_SET_BYTECODE(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_BYTECODE(heap, h) ((h)->bytecode) +#define DUK_HCOMPFUNC_SET_BYTECODE(heap, h, v) \ + do { \ (h)->bytecode = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_LEXENV(heap,h) ((h)->lex_env) -#define DUK_HCOMPFUNC_SET_LEXENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_LEXENV(heap, h) ((h)->lex_env) +#define DUK_HCOMPFUNC_SET_LEXENV(heap, h, v) \ + do { \ (h)->lex_env = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_VARENV(heap,h) ((h)->var_env) -#define DUK_HCOMPFUNC_SET_VARENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_VARENV(heap, h) ((h)->var_env) +#define DUK_HCOMPFUNC_SET_VARENV(heap, h, v) \ + do { \ (h)->var_env = (v); \ } while (0) #endif @@ -68,64 +73,40 @@ */ /* Note: assumes 'data' is always a fixed buffer */ -#define DUK_HCOMPFUNC_GET_BUFFER_BASE(heap,h) \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) +#define DUK_HCOMPFUNC_GET_BUFFER_BASE(heap, h) DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) -#define DUK_HCOMPFUNC_GET_CONSTS_BASE(heap,h) \ - ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_BUFFER_BASE((heap), (h))) +#define DUK_HCOMPFUNC_GET_CONSTS_BASE(heap, h) ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_BUFFER_BASE((heap), (h))) -#define DUK_HCOMPFUNC_GET_FUNCS_BASE(heap,h) \ - DUK_HCOMPFUNC_GET_FUNCS((heap), (h)) +#define DUK_HCOMPFUNC_GET_FUNCS_BASE(heap, h) DUK_HCOMPFUNC_GET_FUNCS((heap), (h)) -#define DUK_HCOMPFUNC_GET_CODE_BASE(heap,h) \ - DUK_HCOMPFUNC_GET_BYTECODE((heap), (h)) +#define DUK_HCOMPFUNC_GET_CODE_BASE(heap, h) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h)) -#define DUK_HCOMPFUNC_GET_CONSTS_END(heap,h) \ - ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_FUNCS((heap), (h))) +#define DUK_HCOMPFUNC_GET_CONSTS_END(heap, h) ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_FUNCS((heap), (h))) -#define DUK_HCOMPFUNC_GET_FUNCS_END(heap,h) \ - ((duk_hobject **) (void *) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h))) +#define DUK_HCOMPFUNC_GET_FUNCS_END(heap, h) ((duk_hobject **) (void *) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h))) /* XXX: double evaluation of DUK_HCOMPFUNC_GET_DATA() */ -#define DUK_HCOMPFUNC_GET_CODE_END(heap,h) \ +#define DUK_HCOMPFUNC_GET_CODE_END(heap, h) \ ((duk_instr_t *) (void *) (DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) + \ - DUK_HBUFFER_GET_SIZE((duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA((heap), h)))) + DUK_HBUFFER_GET_SIZE((duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA((heap), h)))) -#define DUK_HCOMPFUNC_GET_CONSTS_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_END((heap), (h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_BASE((heap), (h))) \ - ) \ - ) +#define DUK_HCOMPFUNC_GET_CONSTS_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_BASE((heap), (h))))) -#define DUK_HCOMPFUNC_GET_FUNCS_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_END((heap), (h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_BASE((heap), (h))) \ - ) \ - ) +#define DUK_HCOMPFUNC_GET_FUNCS_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_BASE((heap), (h))))) -#define DUK_HCOMPFUNC_GET_CODE_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_END((heap),(h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_BASE((heap),(h))) \ - ) \ - ) +#define DUK_HCOMPFUNC_GET_CODE_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_BASE((heap), (h))))) -#define DUK_HCOMPFUNC_GET_CONSTS_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_CONSTS_SIZE((heap), (h)) / sizeof(duk_tval))) +#define DUK_HCOMPFUNC_GET_CONSTS_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_CONSTS_SIZE((heap), (h)) / sizeof(duk_tval))) -#define DUK_HCOMPFUNC_GET_FUNCS_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_FUNCS_SIZE((heap), (h)) / sizeof(duk_hobject *))) +#define DUK_HCOMPFUNC_GET_FUNCS_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_FUNCS_SIZE((heap), (h)) / sizeof(duk_hobject *))) -#define DUK_HCOMPFUNC_GET_CODE_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_CODE_SIZE((heap), (h)) / sizeof(duk_instr_t))) +#define DUK_HCOMPFUNC_GET_CODE_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_CODE_SIZE((heap), (h)) / sizeof(duk_instr_t))) /* * Validity assert @@ -133,9 +114,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hcompfunc_assert_valid(duk_hcompfunc *h); -#define DUK_HCOMPFUNC_ASSERT_VALID(h) do { duk_hcompfunc_assert_valid((h)); } while (0) +#define DUK_HCOMPFUNC_ASSERT_VALID(h) \ + do { \ + duk_hcompfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HCOMPFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HCOMPFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -222,8 +208,8 @@ * at run time, except for debugging, so it is not maintained. */ - duk_uint16_t nregs; /* regs to allocate */ - duk_uint16_t nargs; /* number of arguments allocated to regs */ + duk_uint16_t nregs; /* regs to allocate */ + duk_uint16_t nargs; /* number of arguments allocated to regs */ /* * Additional control information is placed into the object itself @@ -270,4 +256,4 @@ #endif }; -#endif /* DUK_HCOMPFUNC_H_INCLUDED */ +#endif /* DUK_HCOMPFUNC_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heap.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heap.h
Changed
@@ -14,46 +14,50 @@ * Heap flags */ -#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED (1U << 0) /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */ -#define DUK_HEAP_FLAG_INTERRUPT_RUNNING (1U << 1) /* executor interrupt running (used to avoid nested interrupts) */ -#define DUK_HEAP_FLAG_FINALIZER_NORESCUE (1U << 2) /* heap destruction ongoing, finalizer rescue no longer possible */ -#define DUK_HEAP_FLAG_DEBUGGER_PAUSED (1U << 3) /* debugger is paused: talk with debug client until step/resume */ - -#define DUK__HEAP_HAS_FLAGS(heap,bits) ((heap)->flags & (bits)) -#define DUK__HEAP_SET_FLAGS(heap,bits) do { \ +#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED \ + (1U << 0) /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */ +#define DUK_HEAP_FLAG_INTERRUPT_RUNNING (1U << 1) /* executor interrupt running (used to avoid nested interrupts) */ +#define DUK_HEAP_FLAG_FINALIZER_NORESCUE (1U << 2) /* heap destruction ongoing, finalizer rescue no longer possible */ +#define DUK_HEAP_FLAG_DEBUGGER_PAUSED (1U << 3) /* debugger is paused: talk with debug client until step/resume */ + +#define DUK__HEAP_HAS_FLAGS(heap, bits) ((heap)->flags & (bits)) +#define DUK__HEAP_SET_FLAGS(heap, bits) \ + do { \ (heap)->flags |= (bits); \ } while (0) -#define DUK__HEAP_CLEAR_FLAGS(heap,bits) do { \ +#define DUK__HEAP_CLEAR_FLAGS(heap, bits) \ + do { \ (heap)->flags &= ~(bits); \ } while (0) -#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_HAS_INTERRUPT_RUNNING(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_HAS_DEBUGGER_PAUSED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) +#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_HAS_INTERRUPT_RUNNING(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_HAS_DEBUGGER_PAUSED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) -#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_SET_INTERRUPT_RUNNING(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_SET_DEBUGGER_PAUSED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) +#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_SET_INTERRUPT_RUNNING(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_SET_DEBUGGER_PAUSED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) -#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_CLEAR_INTERRUPT_RUNNING(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_CLEAR_FINALIZER_NORESCUE(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_CLEAR_DEBUGGER_PAUSED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) +#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap) \ + DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_CLEAR_INTERRUPT_RUNNING(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_CLEAR_FINALIZER_NORESCUE(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_CLEAR_DEBUGGER_PAUSED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) /* * Longjmp types, also double as identifying continuation type for a rethrow (in 'finally') */ -#define DUK_LJ_TYPE_UNKNOWN 0 /* unused */ -#define DUK_LJ_TYPE_THROW 1 /* value1 -> error object */ -#define DUK_LJ_TYPE_YIELD 2 /* value1 -> yield value, iserror -> error / normal */ -#define DUK_LJ_TYPE_RESUME 3 /* value1 -> resume value, value2 -> resumee thread, iserror -> error/normal */ -#define DUK_LJ_TYPE_BREAK 4 /* value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_CONTINUE 5 /* value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_RETURN 6 /* value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_NORMAL 7 /* no value, pseudo-type to indicate a normal continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_UNKNOWN 0 /* unused */ +#define DUK_LJ_TYPE_THROW 1 /* value1 -> error object */ +#define DUK_LJ_TYPE_YIELD 2 /* value1 -> yield value, iserror -> error / normal */ +#define DUK_LJ_TYPE_RESUME 3 /* value1 -> resume value, value2 -> resumee thread, iserror -> error/normal */ +#define DUK_LJ_TYPE_BREAK 4 /* value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_CONTINUE 5 /* value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_RETURN 6 /* value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_NORMAL 7 /* no value, pseudo-type to indicate a normal continuation (for ENDFIN) */ /* * Mark-and-sweep flags @@ -66,19 +70,19 @@ /* Emergency mark-and-sweep: try extra hard, even at the cost of * performance. */ -#define DUK_MS_FLAG_EMERGENCY (1U << 0) +#define DUK_MS_FLAG_EMERGENCY (1U << 0) /* Postpone rescue decisions for reachable objects with FINALIZED set. * Used during finalize_list processing to avoid incorrect rescue * decisions due to finalize_list being a reachability root. */ -#define DUK_MS_FLAG_POSTPONE_RESCUE (1U << 1) +#define DUK_MS_FLAG_POSTPONE_RESCUE (1U << 1) /* Don't compact objects; needed during object property table resize * to prevent a recursive resize. It would suffice to protect only the * current object being resized, but this is not yet implemented. */ -#define DUK_MS_FLAG_NO_OBJECT_COMPACTION (1U << 2) +#define DUK_MS_FLAG_NO_OBJECT_COMPACTION (1U << 2) /* * Thread switching @@ -89,9 +93,10 @@ */ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK_HEAP_SWITCH_THREAD(heap,newthr) duk_heap_switch_thread((heap), (newthr)) +#define DUK_HEAP_SWITCH_THREAD(heap, newthr) duk_heap_switch_thread((heap), (newthr)) #else -#define DUK_HEAP_SWITCH_THREAD(heap,newthr) do { \ +#define DUK_HEAP_SWITCH_THREAD(heap, newthr) \ + do { \ (heap)->curr_thread = (newthr); \ } while (0) #endif @@ -101,11 +106,14 @@ */ #if defined(DUK_USE_DEBUG) -#define DUK_STATS_INC(heap,fieldname) do { \ +#define DUK_STATS_INC(heap, fieldname) \ + do { \ (heap)->fieldname += 1; \ } while (0) #else -#define DUK_STATS_INC(heap,fieldname) do {} while (0) +#define DUK_STATS_INC(heap, fieldname) \ + do { \ + } while (0) #endif /* @@ -123,36 +131,41 @@ * only during init phases). */ #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 12800L /* 50x heap size */ -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 12800L /* 50x heap size */ +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L #else -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 256L /* 1x heap size */ -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 256L /* 1x heap size */ +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L #endif /* GC torture. */ #if defined(DUK_USE_GC_TORTURE) -#define DUK_GC_TORTURE(heap) do { duk_heap_mark_and_sweep((heap), 0); } while (0) +#define DUK_GC_TORTURE(heap) \ + do { \ + duk_heap_mark_and_sweep((heap), 0); \ + } while (0) #else -#define DUK_GC_TORTURE(heap) do { } while (0) +#define DUK_GC_TORTURE(heap) \ + do { \ + } while (0) #endif /* Stringcache is used for speeding up char-offset-to-byte-offset * translations for non-ASCII strings. */ -#define DUK_HEAP_STRCACHE_SIZE 4 -#define DUK_HEAP_STRINGCACHE_NOCACHE_LIMIT 16 /* strings up to the this length are not cached */ +#define DUK_HEAP_STRCACHE_SIZE 4 +#define DUK_HEAP_STRINGCACHE_NOCACHE_LIMIT 16 /* strings up to the this length are not cached */ /* Some list management macros. */ -#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap,hdr) duk_heap_insert_into_heap_allocated((heap), (hdr)) +#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, hdr) duk_heap_insert_into_heap_allocated((heap), (hdr)) #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAP_REMOVE_FROM_HEAP_ALLOCATED(heap,hdr) duk_heap_remove_from_heap_allocated((heap), (hdr)) +#define DUK_HEAP_REMOVE_FROM_HEAP_ALLOCATED(heap, hdr) duk_heap_remove_from_heap_allocated((heap), (hdr)) #endif #if defined(DUK_USE_FINALIZER_SUPPORT) -#define DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap,hdr) duk_heap_insert_into_finalize_list((heap), (hdr)) -#define DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(heap,hdr) duk_heap_remove_from_finalize_list((heap), (hdr)) +#define DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap, hdr) duk_heap_insert_into_finalize_list((heap), (hdr)) +#define DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(heap, hdr) duk_heap_remove_from_finalize_list((heap), (hdr)) #endif /* @@ -161,30 +174,24 @@ /* heap string indices are autogenerated in duk_strings.h */ #if defined(DUK_USE_ROM_STRINGS) -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) -#else /* DUK_USE_ROM_STRINGS */ +#define DUK_HEAP_GET_STRING(heap, idx) ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (heap)->strs16(idx))) +#define DUK_HEAP_GET_STRING(heap, idx) ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (heap)->strs16(idx))) #else -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((heap)->strs(idx)) +#define DUK_HEAP_GET_STRING(heap, idx) ((heap)->strs(idx)) #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ /* * Raw memory calls: relative to heap, but no GC interaction */ -#define DUK_ALLOC_RAW(heap,size) \ - ((heap)->alloc_func((heap)->heap_udata, (size))) +#define DUK_ALLOC_RAW(heap, size) ((heap)->alloc_func((heap)->heap_udata, (size))) -#define DUK_REALLOC_RAW(heap,ptr,newsize) \ - ((heap)->realloc_func((heap)->heap_udata, (void *) (ptr), (newsize))) +#define DUK_REALLOC_RAW(heap, ptr, newsize) ((heap)->realloc_func((heap)->heap_udata, (void *) (ptr), (newsize))) -#define DUK_FREE_RAW(heap,ptr) \ - ((heap)->free_func((heap)->heap_udata, (void *) (ptr))) +#define DUK_FREE_RAW(heap, ptr) ((heap)->free_func((heap)->heap_udata, (void *) (ptr))) /* * Memory calls: relative to heap, GC interaction, but no error throwing. @@ -217,11 +224,11 @@ /* callback for indirect reallocs, request for current pointer */ typedef void *(*duk_mem_getptr)(duk_heap *heap, void *ud); -#define DUK_ALLOC(heap,size) duk_heap_mem_alloc((heap), (size)) -#define DUK_ALLOC_ZEROED(heap,size) duk_heap_mem_alloc_zeroed((heap), (size)) -#define DUK_REALLOC(heap,ptr,newsize) duk_heap_mem_realloc((heap), (ptr), (newsize)) -#define DUK_REALLOC_INDIRECT(heap,cb,ud,newsize) duk_heap_mem_realloc_indirect((heap), (cb), (ud), (newsize)) -#define DUK_FREE(heap,ptr) duk_heap_mem_free((heap), (ptr)) +#define DUK_ALLOC(heap, size) duk_heap_mem_alloc((heap), (size)) +#define DUK_ALLOC_ZEROED(heap, size) duk_heap_mem_alloc_zeroed((heap), (size)) +#define DUK_REALLOC(heap, ptr, newsize) duk_heap_mem_realloc((heap), (ptr), (newsize)) +#define DUK_REALLOC_INDIRECT(heap, cb, ud, newsize) duk_heap_mem_realloc_indirect((heap), (cb), (ud), (newsize)) +#define DUK_FREE(heap, ptr) duk_heap_mem_free((heap), (ptr)) /* * Checked allocation, relative to a thread @@ -230,24 +237,26 @@ * for convenience. */ -#define DUK_ALLOC_CHECKED(thr,size) duk_heap_mem_alloc_checked((thr), (size)) -#define DUK_ALLOC_CHECKED_ZEROED(thr,size) duk_heap_mem_alloc_checked_zeroed((thr), (size)) -#define DUK_FREE_CHECKED(thr,ptr) duk_heap_mem_free((thr)->heap, (ptr)) +#define DUK_ALLOC_CHECKED(thr, size) duk_heap_mem_alloc_checked((thr), (size)) +#define DUK_ALLOC_CHECKED_ZEROED(thr, size) duk_heap_mem_alloc_checked_zeroed((thr), (size)) +#define DUK_FREE_CHECKED(thr, ptr) duk_heap_mem_free((thr)->heap, (ptr)) /* * Memory constants */ -#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_LIMIT 10 /* Retry allocation after mark-and-sweep for this - * many times. A single mark-and-sweep round is - * not guaranteed to free all unreferenced memory - * because of finalization (in fact, ANY number of - * rounds is strictly not enough). - */ +#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_LIMIT \ + 10 /* Retry allocation after mark-and-sweep for this \ + * many times. A single mark-and-sweep round is \ + * not guaranteed to free all unreferenced memory \ + * because of finalization (in fact, ANY number of \ + * rounds is strictly not enough). \ + */ -#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_EMERGENCY_LIMIT 3 /* Starting from this round, use emergency mode - * for mark-and-sweep. - */ +#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_EMERGENCY_LIMIT \ + 3 /* Starting from this round, use emergency mode \ + * for mark-and-sweep. \ + */ /* * Debugger support @@ -256,26 +265,26 @@ /* Maximum number of breakpoints. Only breakpoints that are set are * consulted so increasing this has no performance impact. */ -#define DUK_HEAP_MAX_BREAKPOINTS 16 +#define DUK_HEAP_MAX_BREAKPOINTS 16 /* Opcode interval for a Date-based status/peek rate limit check. Only * relevant when debugger is attached. Requesting a timestamp may be a * slow operation on some platforms so this shouldn't be too low. On the * other hand a high value makes Duktape react to a pause request slowly. */ -#define DUK_HEAP_DBG_RATELIMIT_OPCODES 4000 +#define DUK_HEAP_DBG_RATELIMIT_OPCODES 4000 /* Milliseconds between status notify and transport peeks. */ -#define DUK_HEAP_DBG_RATELIMIT_MILLISECS 200 +#define DUK_HEAP_DBG_RATELIMIT_MILLISECS 200 /* Debugger pause flags. */ -#define DUK_PAUSE_FLAG_ONE_OPCODE (1U << 0) /* pause when a single opcode has been executed */ -#define DUK_PAUSE_FLAG_ONE_OPCODE_ACTIVE (1U << 1) /* one opcode pause actually active; artifact of current implementation */ -#define DUK_PAUSE_FLAG_LINE_CHANGE (1U << 2) /* pause when current line number changes */ -#define DUK_PAUSE_FLAG_FUNC_ENTRY (1U << 3) /* pause when entering a function */ -#define DUK_PAUSE_FLAG_FUNC_EXIT (1U << 4) /* pause when exiting current function */ -#define DUK_PAUSE_FLAG_CAUGHT_ERROR (1U << 5) /* pause when about to throw an error that is caught */ -#define DUK_PAUSE_FLAG_UNCAUGHT_ERROR (1U << 6) /* pause when about to throw an error that won't be caught */ +#define DUK_PAUSE_FLAG_ONE_OPCODE (1U << 0) /* pause when a single opcode has been executed */ +#define DUK_PAUSE_FLAG_ONE_OPCODE_ACTIVE (1U << 1) /* one opcode pause actually active; artifact of current implementation */ +#define DUK_PAUSE_FLAG_LINE_CHANGE (1U << 2) /* pause when current line number changes */ +#define DUK_PAUSE_FLAG_FUNC_ENTRY (1U << 3) /* pause when entering a function */ +#define DUK_PAUSE_FLAG_FUNC_EXIT (1U << 4) /* pause when exiting current function */ +#define DUK_PAUSE_FLAG_CAUGHT_ERROR (1U << 5) /* pause when about to throw an error that is caught */ +#define DUK_PAUSE_FLAG_UNCAUGHT_ERROR (1U << 6) /* pause when about to throw an error that won't be caught */ struct duk_breakpoint { duk_hstring *filename; @@ -303,21 +312,23 @@ */ struct duk_ljstate { - duk_jmpbuf *jmpbuf_ptr; /* current setjmp() catchpoint */ - duk_small_uint_t type; /* longjmp type */ - duk_bool_t iserror; /* isError flag for yield */ - duk_tval value1; /* 1st related value (type specific) */ - duk_tval value2; /* 2nd related value (type specific) */ + duk_jmpbuf *jmpbuf_ptr; /* current setjmp() catchpoint */ + duk_small_uint_t type; /* longjmp type */ + duk_bool_t iserror; /* isError flag for yield */ + duk_tval value1; /* 1st related value (type specific) */ + duk_tval value2; /* 2nd related value (type specific) */ }; -#define DUK_ASSERT_LJSTATE_UNSET(heap) do { \ +#define DUK_ASSERT_LJSTATE_UNSET(heap) \ + do { \ DUK_ASSERT(heap != NULL); \ DUK_ASSERT(heap->lj.type == DUK_LJ_TYPE_UNKNOWN); \ DUK_ASSERT(heap->lj.iserror == 0); \ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&heap->lj.value1)); \ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&heap->lj.value2)); \ } while (0) -#define DUK_ASSERT_LJSTATE_SET(heap) do { \ +#define DUK_ASSERT_LJSTATE_SET(heap) \ + do { \ DUK_ASSERT(heap != NULL); \ DUK_ASSERT(heap->lj.type != DUK_LJ_TYPE_UNKNOWN); \ } while (0) @@ -337,9 +348,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_heap_assert_valid(duk_heap *heap); -#define DUK_HEAP_ASSERT_VALID(heap) do { duk_heap_assert_valid((heap)); } while (0) +#define DUK_HEAP_ASSERT_VALID(heap) \ + do { \ + duk_heap_assert_valid((heap)); \ + } while (0) #else -#define DUK_HEAP_ASSERT_VALID(heap) do {} while (0) +#define DUK_HEAP_ASSERT_VALID(heap) \ + do { \ + } while (0) #endif struct duk_heap { @@ -493,9 +509,9 @@ /* Random number state for duk_util_tinyrandom.c. */ #if !defined(DUK_USE_GET_RANDOM_DOUBLE) #if defined(DUK_USE_PREFER_SIZE) || !defined(DUK_USE_64BIT_OPS) - duk_uint32_t rnd_state; /* State for Shamir's three-op algorithm */ + duk_uint32_t rnd_state; /* State for Shamir's three-op algorithm */ #else - duk_uint64_t rnd_state2; /* State for xoroshiro128+ */ + duk_uint64_t rnd_state2; /* State for xoroshiro128+ */ #endif #endif @@ -518,8 +534,8 @@ /* Debugger state. */ #if defined(DUK_USE_DEBUGGER_SUPPORT) /* Callbacks and udata; dbg_read_cb != NULL is used to indicate attached state. */ - duk_debug_read_function dbg_read_cb; /* required, NULL implies detached */ - duk_debug_write_function dbg_write_cb; /* required */ + duk_debug_read_function dbg_read_cb; /* required, NULL implies detached */ + duk_debug_write_function dbg_write_cb; /* required */ duk_debug_peek_function dbg_peek_cb; duk_debug_read_flush_function dbg_read_flush_cb; duk_debug_write_flush_function dbg_write_flush_cb; @@ -528,29 +544,32 @@ void *dbg_udata; /* The following are only relevant when debugger is attached. */ - duk_bool_t dbg_processing; /* currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval) */ - duk_bool_t dbg_state_dirty; /* resend state next time executor is about to run */ - duk_bool_t dbg_force_restart; /* force executor restart to recheck breakpoints; used to handle function returns (see GH-303) */ - duk_bool_t dbg_detaching; /* debugger detaching; used to avoid calling detach handler recursively */ - duk_small_uint_t dbg_pause_flags; /* flags for automatic pause behavior */ - duk_activation *dbg_pause_act; /* activation related to pause behavior (pause on line change, function entry/exit) */ - duk_uint32_t dbg_pause_startline; /* starting line number for line change related pause behavior */ - duk_breakpoint dbg_breakpointsDUK_HEAP_MAX_BREAKPOINTS; /* breakpoints: 0,breakpoint_count gc reachable */ + duk_bool_t dbg_processing; /* currently processing messages or breakpoints: don't enter message processing recursively (e.g. + no breakpoints when processing debugger eval) */ + duk_bool_t dbg_state_dirty; /* resend state next time executor is about to run */ + duk_bool_t + dbg_force_restart; /* force executor restart to recheck breakpoints; used to handle function returns (see GH-303) */ + duk_bool_t dbg_detaching; /* debugger detaching; used to avoid calling detach handler recursively */ + duk_small_uint_t dbg_pause_flags; /* flags for automatic pause behavior */ + duk_activation *dbg_pause_act; /* activation related to pause behavior (pause on line change, function entry/exit) */ + duk_uint32_t dbg_pause_startline; /* starting line number for line change related pause behavior */ + duk_breakpoint dbg_breakpointsDUK_HEAP_MAX_BREAKPOINTS; /* breakpoints: 0,breakpoint_count gc reachable */ duk_small_uint_t dbg_breakpoint_count; - duk_breakpoint *dbg_breakpoints_activeDUK_HEAP_MAX_BREAKPOINTS + 1; /* currently active breakpoints: NULL term, borrowed pointers */ + duk_breakpoint + *dbg_breakpoints_activeDUK_HEAP_MAX_BREAKPOINTS + 1; /* currently active breakpoints: NULL term, borrowed pointers */ /* XXX: make active breakpoints actual copies instead of pointers? */ /* These are for rate limiting Status notifications and transport peeking. */ - duk_uint_t dbg_exec_counter; /* cumulative opcode execution count (overflows are OK) */ - duk_uint_t dbg_last_counter; /* value of dbg_exec_counter when we last did a Date-based check */ - duk_double_t dbg_last_time; /* time when status/peek was last done (Date-based rate limit) */ + duk_uint_t dbg_exec_counter; /* cumulative opcode execution count (overflows are OK) */ + duk_uint_t dbg_last_counter; /* value of dbg_exec_counter when we last did a Date-based check */ + duk_double_t dbg_last_time; /* time when status/peek was last done (Date-based rate limit) */ /* Used to support single-byte stream lookahead. */ duk_bool_t dbg_have_next_byte; duk_uint8_t dbg_next_byte; -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) - duk_bool_t dbg_calling_transport; /* transport call in progress, calling into Duktape forbidden */ + duk_bool_t dbg_calling_transport; /* transport call in progress, calling into Duktape forbidden */ #endif /* String intern table (weak refs). */ @@ -559,12 +578,12 @@ #else duk_hstring **strtable; #endif - duk_uint32_t st_mask; /* mask for lookup, st_size - 1 */ - duk_uint32_t st_size; /* stringtable size */ + duk_uint32_t st_mask; /* mask for lookup, st_size - 1 */ + duk_uint32_t st_size; /* stringtable size */ #if (DUK_USE_STRTAB_MINSIZE != DUK_USE_STRTAB_MAXSIZE) - duk_uint32_t st_count; /* string count for resize load factor checks */ + duk_uint32_t st_count; /* string count for resize load factor checks */ #endif - duk_bool_t st_resizing; /* string table is being resized; avoid recursive resize */ + duk_bool_t st_resizing; /* string table is being resized; avoid recursive resize */ /* String access cache (codepoint offset -> byte offset) for fast string * character looping; 'weak' reference which needs special handling in GC. @@ -678,7 +697,9 @@ DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen); DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_checked(duk_hthread *thr, const duk_uint8_t *str, duk_uint32_t len); #if defined(DUK_USE_LITCACHE_SIZE) -DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_literal_checked(duk_hthread *thr, const duk_uint8_t *str, duk_uint32_t blen); +DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_literal_checked(duk_hthread *thr, + const duk_uint8_t *str, + duk_uint32_t blen); #endif DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_u32(duk_heap *heap, duk_uint32_t val); DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_u32_checked(duk_hthread *thr, duk_uint32_t val); @@ -693,7 +714,9 @@ #endif DUK_INTERNAL_DECL void duk_heap_strcache_string_remove(duk_heap *heap, duk_hstring *h); -DUK_INTERNAL_DECL duk_uint_fast32_t duk_heap_strcache_offset_char2byte(duk_hthread *thr, duk_hstring *h, duk_uint_fast32_t char_offset); +DUK_INTERNAL_DECL duk_uint_fast32_t duk_heap_strcache_offset_char2byte(duk_hthread *thr, + duk_hstring *h, + duk_uint_fast32_t char_offset); #if defined(DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS) DUK_INTERNAL_DECL void *duk_default_alloc_function(void *udata, duk_size_t size); @@ -714,10 +737,10 @@ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL_DECL void duk_heap_run_finalizer(duk_heap *heap, duk_hobject *obj); DUK_INTERNAL_DECL void duk_heap_process_finalize_list(duk_heap *heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL_DECL void duk_heap_mark_and_sweep(duk_heap *heap, duk_small_uint_t flags); DUK_INTERNAL_DECL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len); -#endif /* DUK_HEAP_H_INCLUDED */ +#endif /* DUK_HEAP_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heap_alloc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heap_alloc.c
Changed
@@ -6,7 +6,7 @@ #if defined(DUK_USE_ROM_STRINGS) /* Fixed seed value used with ROM strings. */ -#define DUK__FIXED_HASH_SEED 0xabcd1234 +#define DUK__FIXED_HASH_SEED 0xabcd1234 #endif /* @@ -95,8 +95,8 @@ #if defined(DUK_USE_HSTRING_EXTDATA) && defined(DUK_USE_EXTSTR_FREE) if (DUK_HSTRING_HAS_EXTDATA(h)) { - DUK_DDD(DUK_DDDPRINT("free extstr: hstring %!O, extdata: %p", - h, DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h))); + DUK_DDD( + DUK_DDDPRINT("free extstr: hstring %!O, extdata: %p", h, DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h))); DUK_USE_EXTSTR_FREE(heap->heap_udata, (const void *) DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h)); } #endif @@ -120,7 +120,6 @@ DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(hdr) == DUK_HTYPE_BUFFER); duk_free_hbuffer(heap, (duk_hbuffer *) hdr); } - } /* @@ -150,10 +149,10 @@ count_act++; #endif } - heap->activation_free = NULL; /* needed when called from mark-and-sweep */ + heap->activation_free = NULL; /* needed when called from mark-and-sweep */ return count_act; } -#endif /* DUK_USE_CACHE_ACTIVATION */ +#endif /* DUK_USE_CACHE_ACTIVATION */ #if defined(DUK_USE_CACHE_CATCHER) DUK_LOCAL duk_size_t duk__heap_free_catcher_freelist(duk_heap *heap) { @@ -169,11 +168,11 @@ count_cat++; #endif } - heap->catcher_free = NULL; /* needed when called from mark-and-sweep */ + heap->catcher_free = NULL; /* needed when called from mark-and-sweep */ return count_cat; } -#endif /* DUK_USE_CACHE_CATCHER */ +#endif /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL void duk_heap_free_freelists(duk_heap *heap) { duk_size_t count_act = 0; @@ -189,8 +188,8 @@ DUK_UNREF(count_act); DUK_UNREF(count_cat); - DUK_D(DUK_DPRINT("freed %ld activation freelist entries, %ld catcher freelist entries", - (long) count_act, (long) count_cat)); + DUK_D( + DUK_DPRINT("freed %ld activation freelist entries, %ld catcher freelist entries", (long) count_act, (long) count_cat)); } DUK_LOCAL void duk__free_allocated(duk_heap *heap) { @@ -203,8 +202,7 @@ * because they may happen with finalizer processing. */ - DUK_DDD(DUK_DDDPRINT("FINALFREE (allocated): %!iO", - (duk_heaphdr *) curr)); + DUK_DDD(DUK_DDDPRINT("FINALFREE (allocated): %!iO", (duk_heaphdr *) curr)); next = DUK_HEAPHDR_GET_NEXT(heap, curr); duk_heap_free_heaphdr_raw(heap, curr); curr = next; @@ -218,14 +216,13 @@ curr = heap->finalize_list; while (curr) { - DUK_DDD(DUK_DDDPRINT("FINALFREE (finalize_list): %!iO", - (duk_heaphdr *) curr)); + DUK_DDD(DUK_DDDPRINT("FINALFREE (finalize_list): %!iO", (duk_heaphdr *) curr)); next = DUK_HEAPHDR_GET_NEXT(heap, curr); duk_heap_free_heaphdr_raw(heap, curr); curr = next; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_LOCAL void duk__free_stringtable(duk_heap *heap) { /* strings are only tracked by stringtable */ @@ -243,9 +240,9 @@ DUK_ASSERT(heap != NULL); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* refzero not running -> must be empty */ + DUK_ASSERT(heap->refzero_list == NULL); /* refzero not running -> must be empty */ #endif - DUK_ASSERT(heap->finalize_list == NULL); /* mark-and-sweep last pass */ + DUK_ASSERT(heap->finalize_list == NULL); /* mark-and-sweep last pass */ if (heap->heap_thread == NULL) { /* May happen when heap allocation fails right off. There @@ -268,11 +265,11 @@ DUK_ASSERT(heap->ms_running == 0); DUK_ASSERT(heap->ms_prevent_count == 0); heap->pf_prevent_count = 1; - heap->ms_running = 2; /* Use distinguishable value. */ - heap->ms_prevent_count = 1; /* Bump, because mark-and-sweep assumes it's bumped when ms_running is set. */ + heap->ms_running = 2; /* Use distinguishable value. */ + heap->ms_prevent_count = 1; /* Bump, because mark-and-sweep assumes it's bumped when ms_running is set. */ - curr_limit = 0; /* suppress warning, not used */ - for (round_no = 0; ; round_no++) { + curr_limit = 0; /* suppress warning, not used */ + for (round_no = 0;; round_no++) { curr = heap->heap_allocated; count_all = 0; count_finalized = 0; @@ -287,7 +284,8 @@ if (DUK_HOBJECT_HAS_FINALIZER_FAST(heap, (duk_hobject *) curr)) { if (!DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) curr)) { - DUK_ASSERT(DUK_HEAP_HAS_FINALIZER_NORESCUE(heap)); /* maps to finalizer 2nd argument */ + DUK_ASSERT( + DUK_HEAP_HAS_FINALIZER_NORESCUE(heap)); /* maps to finalizer 2nd argument */ duk_heap_run_finalizer(heap, (duk_hobject *) curr); count_finalized++; } @@ -314,10 +312,13 @@ */ curr_limit = count_all * 2; } else { - curr_limit = (curr_limit * 3) / 4; /* Decrease by 25% every round */ + curr_limit = (curr_limit * 3) / 4; /* Decrease by 25% every round */ } DUK_D(DUK_DPRINT("finalizer round %ld complete, %ld objects, tried to execute %ld finalizers, current limit is %ld", - (long) round_no, (long) count_all, (long) count_finalized, (long) curr_limit)); + (long) round_no, + (long) count_all, + (long) count_finalized, + (long) curr_limit)); if (count_finalized == 0) { DUK_D(DUK_DPRINT("no more finalizable objects, forced finalization finished")); @@ -334,7 +335,7 @@ heap->ms_running = 0; heap->pf_prevent_count = 0; } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL void duk_heap_free(duk_heap *heap) { DUK_D(DUK_DPRINT("free heap: %p", (void *) heap)); @@ -377,7 +378,7 @@ duk_heap_mark_and_sweep(heap, 0); DUK_D(DUK_DPRINT("forced gc #3 in heap destruction (don't run finalizers)")); heap->pf_skip_finalizers = 1; - duk_heap_mark_and_sweep(heap, 0); /* Skip finalizers; queue finalizable objects to heap_allocated. */ + duk_heap_mark_and_sweep(heap, 0); /* Skip finalizers; queue finalizable objects to heap_allocated. */ /* There are never objects in refzero_list at this point, or at any * point beyond a DECREF (even a DECREF_NORZ). Since Duktape 2.1 @@ -386,17 +387,17 @@ * refcount. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) - DUK_ASSERT(heap->finalize_list == NULL); /* Last mark-and-sweep with skip_finalizers. */ + DUK_ASSERT(heap->finalize_list == NULL); /* Last mark-and-sweep with skip_finalizers. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_D(DUK_DPRINT("run finalizers for remaining finalizable objects")); - DUK_HEAP_SET_FINALIZER_NORESCUE(heap); /* Rescue no longer supported. */ + DUK_HEAP_SET_FINALIZER_NORESCUE(heap); /* Rescue no longer supported. */ duk__free_run_finalizers(heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* Note: heap->heap_thread, heap->curr_thread, and heap->heap_object * are on the heap allocated list. @@ -409,7 +410,7 @@ duk__free_allocated(heap); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) @@ -452,7 +453,9 @@ while (h != NULL) { hash = duk_heap_hashstring(heap, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); DUK_DD(DUK_DDPRINT("duk_rom_strings_lookup%d -> hash 0x%08lx, computed 0x%08lx", - (int) i, (unsigned long) DUK_HSTRING_GET_HASH(h), (unsigned long) hash)); + (int) i, + (unsigned long) DUK_HSTRING_GET_HASH(h), + (unsigned long) hash)); DUK_ASSERT(hash == (duk_uint32_t) DUK_HSTRING_GET_HASH(h)); h = (const duk_hstring *) h->hdr.h_next; @@ -461,11 +464,11 @@ #endif return 1; } -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ DUK_LOCAL duk_bool_t duk__init_heap_strings(duk_heap *heap) { duk_bitdecoder_ctx bd_ctx; - duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ + duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ duk_small_uint_t i; duk_memzero(&bd_ctx, sizeof(bd_ctx)); @@ -521,18 +524,16 @@ return 1; - failed: +failed: return 0; } -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ DUK_LOCAL duk_bool_t duk__init_heap_thread(duk_heap *heap) { duk_hthread *thr; DUK_D(DUK_DPRINT("heap init: alloc heap thread")); - thr = duk_hthread_alloc_unchecked(heap, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); + thr = duk_hthread_alloc_unchecked(heap, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); if (thr == NULL) { DUK_D(DUK_DPRINT("failed to alloc heap_thread")); return 0; @@ -540,16 +541,16 @@ thr->state = DUK_HTHREAD_STATE_INACTIVE; #if defined(DUK_USE_ROM_STRINGS) /* No strs pointer. */ -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) thr->strs16 = heap->strs16; #else thr->strs = heap->strs; #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ heap->heap_thread = thr; - DUK_HTHREAD_INCREF(thr, thr); /* Note: first argument not really used */ + DUK_HTHREAD_INCREF(thr, thr); /* Note: first argument not really used */ /* 'thr' is now reachable */ @@ -568,7 +569,8 @@ } #if defined(DUK_USE_DEBUG) -#define DUK__DUMPSZ(t) do { \ +#define DUK__DUMPSZ(t) \ + do { \ DUK_D(DUK_DPRINT("" #t "=%ld", (long) sizeof(t))); \ } while (0) @@ -577,20 +579,20 @@ * enough; the limits will then not be printed accurately but the magnitude * will be correct. */ -#define DUK__DUMPLM_SIGNED_RAW(t,a,b) do { \ - DUK_D(DUK_DPRINT(t "=%ld,%ld=%lf,%lf", \ - (long) (a), (long) (b), \ - (double) (a), (double) (b))); \ +#define DUK__DUMPLM_SIGNED_RAW(t, a, b) \ + do { \ + DUK_D(DUK_DPRINT(t "=%ld,%ld=%lf,%lf", (long) (a), (long) (b), (double) (a), (double) (b))); \ } while (0) -#define DUK__DUMPLM_UNSIGNED_RAW(t,a,b) do { \ - DUK_D(DUK_DPRINT(t "=%lu,%lu=%lf,%lf", \ - (unsigned long) (a), (unsigned long) (b), \ - (double) (a), (double) (b))); \ +#define DUK__DUMPLM_UNSIGNED_RAW(t, a, b) \ + do { \ + DUK_D(DUK_DPRINT(t "=%lu,%lu=%lf,%lf", (unsigned long) (a), (unsigned long) (b), (double) (a), (double) (b))); \ } while (0) -#define DUK__DUMPLM_SIGNED(t) do { \ +#define DUK__DUMPLM_SIGNED(t) \ + do { \ DUK__DUMPLM_SIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \ } while (0) -#define DUK__DUMPLM_UNSIGNED(t) do { \ +#define DUK__DUMPLM_UNSIGNED(t) \ + do { \ DUK__DUMPLM_UNSIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \ } while (0) @@ -663,7 +665,7 @@ DUK__DUMPSZ(duk_tval); /* structs from duk_forwdecl.h */ - DUK__DUMPSZ(duk_jmpbuf); /* just one 'int' for C++ exceptions */ + DUK__DUMPSZ(duk_jmpbuf); /* just one 'int' for C++ exceptions */ DUK__DUMPSZ(duk_heaphdr); DUK__DUMPSZ(duk_heaphdr_string); DUK__DUMPSZ(duk_hstring); @@ -787,7 +789,7 @@ DUK_D(DUK_DPRINT("IEEE double endianness: ???")); #endif } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ DUK_INTERNAL duk_heap *duk_heap_alloc(duk_alloc_function alloc_func, @@ -808,7 +810,7 @@ DUK_ASSERT((DUK_HTYPE_STRING & 0x01U) == 0); DUK_ASSERT((DUK_HTYPE_BUFFER & 0x01U) == 0); - DUK_ASSERT((DUK_HTYPE_OBJECT & 0x01U) == 1); /* DUK_HEAPHDR_IS_OBJECT() relies ont his. */ + DUK_ASSERT((DUK_HTYPE_OBJECT & 0x01U) == 1); /* DUK_HEAPHDR_IS_OBJECT() relies ont his. */ /* * Debug dump type sizes @@ -849,7 +851,7 @@ #endif fatal_func(heap_udata, "sizeof(duk_tval) not 8 or 16, cannot use DUK_USE_EXEC_REGCONST_OPTIMIZE option"); } -#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ /* * Computed values (e.g. INFINITY) @@ -933,18 +935,18 @@ #endif #if defined(DUK_USE_ROM_STRINGS) /* no res->strs */ -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) /* res->strs16 is zeroed and zero decodes to NULL, so no NULL inits. */ #else { duk_small_uint_t i; - for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) { + for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) { res->strsi = NULL; - } + } } #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_DEBUGGER_SUPPORT) res->dbg_read_cb = NULL; res->dbg_write_cb = NULL; @@ -955,7 +957,7 @@ res->dbg_udata = NULL; res->dbg_pause_act = NULL; #endif -#endif /* DUK_USE_EXPLICIT_NULL_INIT */ +#endif /* DUK_USE_EXPLICIT_NULL_INIT */ res->alloc_func = alloc_func; res->realloc_func = realloc_func; @@ -994,17 +996,17 @@ /* XXX: make a common DUK_USE_ option, and allow custom fixed seed? */ DUK_D(DUK_DPRINT("using rom strings, force heap hash_seed to fixed value 0x%08lx", (long) DUK__FIXED_HASH_SEED)); res->hash_seed = (duk_uint32_t) DUK__FIXED_HASH_SEED; -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ res->hash_seed = (duk_uint32_t) (duk_uintptr_t) res; #if !defined(DUK_USE_STRHASH_DENSE) - res->hash_seed ^= 5381; /* Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0 */ + res->hash_seed ^= 5381; /* Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0 */ #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) res->lj.jmpbuf_ptr = NULL; #endif - DUK_ASSERT(res->lj.type == DUK_LJ_TYPE_UNKNOWN); /* zero */ + DUK_ASSERT(res->lj.type == DUK_LJ_TYPE_UNKNOWN); /* zero */ DUK_ASSERT(res->lj.iserror == 0); DUK_TVAL_SET_UNDEFINED(&res->lj.value1); DUK_TVAL_SET_UNDEFINED(&res->lj.value2); @@ -1040,14 +1042,14 @@ #if defined(DUK_USE_EXPLICIT_NULL_INIT) { duk_uint32_t i; - for (i = 0; i < st_initsize; i++) { + for (i = 0; i < st_initsize; i++) { res->strtablei = NULL; - } + } } #else duk_memzero(res->strtable, sizeof(duk_hstring *) * st_initsize); -#endif /* DUK_USE_EXPLICIT_NULL_INIT */ -#endif /* DUK_USE_STRTAB_PTRCOMP */ +#endif /* DUK_USE_EXPLICIT_NULL_INIT */ +#endif /* DUK_USE_STRTAB_PTRCOMP */ /* * Init stringcache @@ -1077,7 +1079,7 @@ } } #endif -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ /* XXX: error handling is incomplete. It would be cleanest if * there was a setjmp catchpoint, so that all init code could @@ -1118,9 +1120,9 @@ #endif DUK_D(DUK_DPRINT("heap init: initialize heap object")); DUK_ASSERT(res->heap_thread != NULL); - res->heap_object = duk_hobject_alloc_unchecked(res, DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT)); + res->heap_object = duk_hobject_alloc_unchecked(res, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT)); if (res->heap_object == NULL) { goto failed; } @@ -1136,8 +1138,8 @@ duk_util_tinyrandom_prepare_seed(res->heap_thread); #else res->rnd_state0 = (duk_uint64_t) duk_time_get_ecmascript_time(res->heap_thread); - DUK_ASSERT(res->rnd_state1 == 0); /* Not filled here, filled in by seed preparation. */ -#if 0 /* Manual test values matching misc/xoroshiro128plus_test.c. */ + DUK_ASSERT(res->rnd_state1 == 0); /* Not filled here, filled in by seed preparation. */ +#if 0 /* Manual test values matching misc/xoroshiro128plus_test.c. */ res->rnd_state0 = DUK_U64_CONSTANT(0xdeadbeef12345678); res->rnd_state1 = DUK_U64_CONSTANT(0xcafed00d12345678); #endif @@ -1189,7 +1191,7 @@ DUK_D(DUK_DPRINT("allocated heap: %p", (void *) res)); return res; - failed: +failed: DUK_D(DUK_DPRINT("heap allocation failed")); if (res != NULL) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heap_finalize.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heap_finalize.c
Changed
@@ -24,14 +24,14 @@ /* Inner function call, error throw. */ duk_eval_string_noresult(thr, - "(function dummy() {\n" - " dummy.prototype = null; /* break reference loop */\n" - " try {\n" - " throw 'fake-finalizer-dummy-error';\n" - " } catch (e) {\n" - " void e;\n" - " }\n" - "})()"); + "(function dummy() {\n" + " dummy.prototype = null; /* break reference loop */\n" + " try {\n" + " throw 'fake-finalizer-dummy-error';\n" + " } catch (e) {\n" + " void e;\n" + " }\n" + "})()"); /* The above creates garbage (e.g. a function instance). Because * the function/prototype reference loop is broken, it gets collected @@ -63,7 +63,7 @@ (void) duk_pcall(thr, 0 /*nargs*/); duk_pop(thr); } -#endif /* DUK_USE_FINALIZER_TORTURE */ +#endif /* DUK_USE_FINALIZER_TORTURE */ /* * Process the finalize_list to completion. @@ -175,12 +175,13 @@ DUK_DD(DUK_DDPRINT("processing finalize_list entry: %p -> %!iO", (void *) curr, curr)); - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* Only objects have finalizers. */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* Only objects have finalizers. */ DUK_ASSERT(!DUK_HEAPHDR_HAS_REACHABLE(curr)); DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(curr)); - DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(curr)); /* All objects on finalize_list will have this flag (except object being finalized right now). */ - DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); /* Queueing code ensures. */ - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY(curr)); /* ROM objects never get freed (or finalized). */ + DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE( + curr)); /* All objects on finalize_list will have this flag (except object being finalized right now). */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); /* Queueing code ensures. */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY(curr)); /* ROM objects never get freed (or finalized). */ #if defined(DUK_USE_ASSERTIONS) DUK_ASSERT(heap->currently_finalizing == NULL); @@ -208,11 +209,11 @@ */ #if defined(DUK_USE_REFERENCE_COUNTING) DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); - had_zero_refcount = (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1); /* Preincremented on finalize_list insert. */ + had_zero_refcount = (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1); /* Preincremented on finalize_list insert. */ #endif DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); - duk_heap_run_finalizer(heap, (duk_hobject *) curr); /* must never longjmp */ + duk_heap_run_finalizer(heap, (duk_hobject *) curr); /* must never longjmp */ DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZED(curr)); /* XXX: assert that object is still in finalize_list * when duk_push_heapptr() allows automatic rescue. @@ -220,12 +221,14 @@ #if defined(DUK_USE_REFERENCE_COUNTING) DUK_DD(DUK_DDPRINT("refcount after finalizer (includes bump): %ld", (long) DUK_HEAPHDR_GET_REFCOUNT(curr))); - if (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1) { /* Only artificial bump in refcount? */ + if (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1) { /* Only artificial bump in refcount? */ #if defined(DUK_USE_DEBUG) if (had_zero_refcount) { - DUK_DD(DUK_DDPRINT("finalized object's refcount is zero -> free immediately (refcount queued)")); + DUK_DD(DUK_DDPRINT( + "finalized object's refcount is zero -> free immediately (refcount queued)")); } else { - DUK_DD(DUK_DDPRINT("finalized object's refcount is zero -> free immediately (mark-and-sweep queued)")); + DUK_DD(DUK_DDPRINT( + "finalized object's refcount is zero -> free immediately (mark-and-sweep queued)")); } #endif queue_back = 0; @@ -275,21 +278,21 @@ * decision. */ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); - DUK_HEAPHDR_PREDEC_REFCOUNT(curr); /* Remove artificial refcount bump. */ + DUK_HEAPHDR_PREDEC_REFCOUNT(curr); /* Remove artificial refcount bump. */ DUK_HEAPHDR_CLEAR_FINALIZABLE(curr); DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, curr); } else { /* No need to remove the refcount bump here. */ - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ DUK_DD(DUK_DDPRINT("refcount finalize after finalizer call: %!O", curr)); duk_hobject_refcount_finalize_norz(heap, (duk_hobject *) curr); duk_free_hobject(heap, (duk_hobject *) curr); DUK_DD(DUK_DDPRINT("freed hobject after finalization: %p", (void *) curr)); } -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ DUK_HEAPHDR_CLEAR_FINALIZABLE(curr); DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, curr); -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_DEBUG) count++; @@ -355,11 +358,11 @@ * caller must ensure that this function is not called if the target is * a Proxy. */ - duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_INT_FINALIZER); /* -> ... obj finalizer */ + duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_INT_FINALIZER); /* -> ... obj finalizer */ duk_dup_m2(thr); duk_push_boolean(thr, DUK_HEAP_HAS_FINALIZER_NORESCUE(thr->heap)); DUK_DDD(DUK_DDDPRINT("calling finalizer")); - duk_call(thr, 2); /* ... obj finalizer obj heapDestruct -> ... obj retval */ + duk_call(thr, 2); /* ... obj finalizer obj heapDestruct -> ... obj retval */ DUK_DDD(DUK_DDDPRINT("finalizer returned successfully")); return 0; @@ -408,7 +411,7 @@ return; } #endif - DUK_HEAPHDR_SET_FINALIZED((duk_heaphdr *) obj); /* ensure never re-entered until rescue cycle complete */ + DUK_HEAPHDR_SET_FINALIZED((duk_heaphdr *) obj); /* ensure never re-entered until rescue cycle complete */ #if defined(DUK_USE_ES6_PROXY) if (DUK_HOBJECT_IS_PROXY(obj)) { @@ -420,26 +423,27 @@ DUK_D(DUK_DPRINT("object is a Proxy, skip finalizer call")); return; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ - duk_push_hobject(thr, obj); /* this also increases refcount by one */ - rc = duk_safe_call(thr, duk__finalize_helper, NULL /*udata*/, 0 /*nargs*/, 1 /*nrets*/); /* -> ... obj retval/error */ - DUK_ASSERT_TOP(thr, entry_top + 2); /* duk_safe_call discipline */ + duk_push_hobject(thr, obj); /* this also increases refcount by one */ + rc = duk_safe_call(thr, duk__finalize_helper, NULL /*udata*/, 0 /*nargs*/, 1 /*nrets*/); /* -> ... obj retval/error */ + DUK_ASSERT_TOP(thr, entry_top + 2); /* duk_safe_call discipline */ if (rc != DUK_EXEC_SUCCESS) { /* Note: we ask for one return value from duk_safe_call to get this * error debugging here. */ DUK_D(DUK_DPRINT("wrapped finalizer call failed for object %p (ignored); error: %!T", - (void *) obj, (duk_tval *) duk_get_tval(thr, -1))); + (void *) obj, + (duk_tval *) duk_get_tval(thr, -1))); } - duk_pop_2(thr); /* -> ... */ + duk_pop_2(thr); /* -> ... */ DUK_ASSERT_TOP(thr, entry_top); } -#else /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ /* nothing */ -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heap_hashstring.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heap_hashstring.c
Changed
@@ -21,9 +21,9 @@ #if defined(DUK_USE_STRHASH_DENSE) /* Constants for duk_hashstring(). */ -#define DUK__STRHASH_SHORTSTRING 4096L -#define DUK__STRHASH_MEDIUMSTRING (256L * 1024L) -#define DUK__STRHASH_BLOCKSIZE 256L +#define DUK__STRHASH_SHORTSTRING 4096L +#define DUK__STRHASH_MEDIUMSTRING (256L * 1024L) +#define DUK__STRHASH_BLOCKSIZE 256L DUK_INTERNAL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len) { duk_uint32_t hash; @@ -80,7 +80,7 @@ #endif return hash; } -#else /* DUK_USE_STRHASH_DENSE */ +#else /* DUK_USE_STRHASH_DENSE */ DUK_INTERNAL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len) { duk_uint32_t hash; duk_size_t step; @@ -98,10 +98,10 @@ * more often in the suffix than in the prefix. */ - hash = heap->hash_seed ^ ((duk_uint32_t) len); /* Bernstein hash init value is normally 5381 */ + hash = heap->hash_seed ^ ((duk_uint32_t) len); /* Bernstein hash init value is normally 5381 */ step = (len >> DUK_USE_STRHASH_SKIP_SHIFT) + 1; for (off = len; off >= step; off -= step) { - DUK_ASSERT(off >= 1); /* off >= step, and step >= 1 */ + DUK_ASSERT(off >= 1); /* off >= step, and step >= 1 */ hash = (hash * 33) + stroff - 1; } @@ -113,4 +113,4 @@ #endif return hash; } -#endif /* DUK_USE_STRHASH_DENSE */ +#endif /* DUK_USE_STRHASH_DENSE */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heap_markandsweep.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heap_markandsweep.c
Changed
@@ -114,7 +114,7 @@ DUK_HBUFOBJ_ASSERT_VALID(b); duk__mark_heaphdr(heap, (duk_heaphdr *) b->buf); duk__mark_heaphdr(heap, (duk_heaphdr *) b->buf_prop); -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ } else if (DUK_HOBJECT_IS_BOUNDFUNC(h)) { duk_hboundfunc *f = (duk_hboundfunc *) (void *) h; DUK_HBOUNDFUNC_ASSERT_VALID(f); @@ -127,7 +127,7 @@ DUK_HPROXY_ASSERT_VALID(p); duk__mark_heaphdr_nonnull(heap, (duk_heaphdr *) p->target); duk__mark_heaphdr_nonnull(heap, (duk_heaphdr *) p->handler); -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ } else if (DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; duk_activation *act; @@ -148,7 +148,7 @@ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) duk__mark_heaphdr(heap, (duk_heaphdr *) act->prev_caller); #endif -#if 0 /* nothing now */ +#if 0 /* nothing now */ for (cat = act->cat; cat != NULL; cat = cat->parent) { } #endif @@ -171,9 +171,8 @@ /* Mark any duk_heaphdr type. Recursion tracking happens only here. */ DUK_LOCAL void duk__mark_heaphdr(duk_heap *heap, duk_heaphdr *h) { - DUK_DDD(DUK_DDDPRINT("duk__mark_heaphdr %p, type %ld", - (void *) h, - (h != NULL ? (long) DUK_HEAPHDR_GET_TYPE(h) : (long) -1))); + DUK_DDD( + DUK_DDDPRINT("duk__mark_heaphdr %p, type %ld", (void *) h, (h != NULL ? (long) DUK_HEAPHDR_GET_TYPE(h) : (long) -1))); /* XXX: add non-null variant? */ if (h == NULL) { @@ -185,7 +184,7 @@ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) if (!DUK_HEAPHDR_HAS_READONLY(h)) { - h->h_assert_refcount++; /* Comparison refcount: bump even if already reachable. */ + h->h_assert_refcount++; /* Comparison refcount: bump even if already reachable. */ } #endif if (DUK_HEAPHDR_HAS_REACHABLE(h)) { @@ -209,7 +208,7 @@ } heap->ms_recursion_depth++; - DUK_ASSERT(heap->ms_recursion_depth != 0); /* Wrap. */ + DUK_ASSERT(heap->ms_recursion_depth != 0); /* Wrap. */ switch (DUK_HEAPHDR_GET_TYPE(h)) { case DUK_HTYPE_STRING: @@ -324,9 +323,7 @@ * of a _Finalizer hidden symbol. */ - if (!DUK_HEAPHDR_HAS_REACHABLE(hdr) && - DUK_HEAPHDR_IS_OBJECT(hdr) && - !DUK_HEAPHDR_HAS_FINALIZED(hdr) && + if (!DUK_HEAPHDR_HAS_REACHABLE(hdr) && DUK_HEAPHDR_IS_OBJECT(hdr) && !DUK_HEAPHDR_HAS_FINALIZED(hdr) && DUK_HOBJECT_HAS_FINALIZER_FAST(heap, (duk_hobject *) hdr)) { /* heaphdr: * - is not reachable @@ -351,8 +348,7 @@ return; } - DUK_DD(DUK_DDPRINT("marked %ld heap objects as finalizable, now mark them reachable", - (long) count_finalizable)); + DUK_DD(DUK_DDPRINT("marked %ld heap objects as finalizable, now mark them reachable", (long) count_finalizable)); hdr = heap->heap_allocated; while (hdr != NULL) { @@ -365,7 +361,7 @@ /* Caller will finish the marking process if we hit a recursion limit. */ } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Mark objects on finalize_list. @@ -396,7 +392,7 @@ } #endif } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Fallback marking handler if recursion limit is reached. @@ -429,9 +425,9 @@ DUK_DDD(DUK_DDDPRINT("found a temp root: %p", (void *) hdr)); DUK_HEAPHDR_CLEAR_TEMPROOT(hdr); - DUK_HEAPHDR_CLEAR_REACHABLE(hdr); /* Done so that duk__mark_heaphdr() works correctly. */ + DUK_HEAPHDR_CLEAR_REACHABLE(hdr); /* Done so that duk__mark_heaphdr() works correctly. */ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) - hdr->h_assert_refcount--; /* Same node visited twice. */ + hdr->h_assert_refcount--; /* Same node visited twice. */ #endif duk__mark_heaphdr_nonnull(heap, hdr); @@ -526,7 +522,7 @@ hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr); } } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Clear (reachable) flags of finalize_list. @@ -549,15 +545,14 @@ while (hdr) { DUK_HEAPHDR_CLEAR_REACHABLE(hdr); #if defined(DUK_USE_ASSERTIONS) - DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(hdr) || \ - (heap->currently_finalizing == hdr)); + DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(hdr) || (heap->currently_finalizing == hdr)); #endif /* DUK_HEAPHDR_FLAG_FINALIZED may be set. */ DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(hdr)); hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr); } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Sweep stringtable. @@ -593,8 +588,7 @@ duk_hstring *next; next = h->hdr.h_next; - if (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h)) - { + if (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h)) { DUK_HEAPHDR_CLEAR_REACHABLE((duk_heaphdr *) h); count_keep++; prev = h; @@ -621,8 +615,8 @@ * should have decreased unreachable string refcounts to zero * (even for cycles). However, pinned strings have a +1 bump. */ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) == - DUK_HSTRING_HAS_PINNED_LITERAL(h) ? 1U : 0U); + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) == DUK_HSTRING_HAS_PINNED_LITERAL(h) ? 1U : + 0U); #endif /* Deal with weak references first. */ @@ -643,10 +637,9 @@ } } - done: +done: #if defined(DUK_USE_DEBUG) - DUK_D(DUK_DPRINT("mark-and-sweep sweep stringtable: %ld freed, %ld kept", - (long) count_free, (long) count_keep)); + DUK_D(DUK_DPRINT("mark-and-sweep sweep stringtable: %ld freed, %ld kept", (long) count_free, (long) count_keep)); #endif *out_count_keep = count_keep; } @@ -656,7 +649,7 @@ */ DUK_LOCAL void duk__sweep_heap(duk_heap *heap, duk_small_uint_t flags, duk_size_t *out_count_keep) { - duk_heaphdr *prev; /* last element that was left in the heap */ + duk_heaphdr *prev; /* last element that was left in the heap */ duk_heaphdr *curr; duk_heaphdr *next; #if defined(DUK_USE_DEBUG) @@ -699,25 +692,28 @@ DUK_DD(DUK_DDPRINT("sweep; reachable, finalizable --> move to finalize_list: %p", (void *) curr)); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_HEAPHDR_PREINC_REFCOUNT(curr); /* Bump refcount so that refzero never occurs when pending a finalizer call. */ + DUK_HEAPHDR_PREINC_REFCOUNT( + curr); /* Bump refcount so that refzero never occurs when pending a finalizer call. */ #endif DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap, curr); #if defined(DUK_USE_DEBUG) count_finalize++; #endif - } - else -#endif /* DUK_USE_FINALIZER_SUPPORT */ + } else +#endif /* DUK_USE_FINALIZER_SUPPORT */ { if (DUK_UNLIKELY(DUK_HEAPHDR_HAS_FINALIZED(curr))) { DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZABLE(curr)); DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); if (flags & DUK_MS_FLAG_POSTPONE_RESCUE) { - DUK_DD(DUK_DDPRINT("sweep; reachable, finalized, but postponing rescue decisions --> keep object (with FINALIZED set): %!iO", curr)); + DUK_DD(DUK_DDPRINT("sweep; reachable, finalized, but postponing rescue decisions " + "--> keep object (with FINALIZED set): %!iO", + curr)); count_keep++; } else { - DUK_DD(DUK_DDPRINT("sweep; reachable, finalized --> rescued after finalization: %p", (void *) curr)); + DUK_DD(DUK_DDPRINT("sweep; reachable, finalized --> rescued after finalization: %p", + (void *) curr)); #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_HEAPHDR_CLEAR_FINALIZED(curr); #endif @@ -786,7 +782,8 @@ #if defined(DUK_USE_DEBUG) if (DUK_HEAPHDR_HAS_FINALIZED(curr)) { - DUK_DD(DUK_DDPRINT("sweep; unreachable, finalized --> finalized object not rescued: %p", (void *) curr)); + DUK_DD(DUK_DDPRINT("sweep; unreachable, finalized --> finalized object not rescued: %p", + (void *) curr)); } else { DUK_DD(DUK_DDPRINT("sweep; not reachable --> free: %p", (void *) curr)); } @@ -820,7 +817,10 @@ #if defined(DUK_USE_DEBUG) DUK_D(DUK_DPRINT("mark-and-sweep sweep objects (non-string): %ld freed, %ld kept, %ld rescued, %ld queued for finalization", - (long) count_free, (long) count_keep, (long) count_rescue, (long) count_finalize)); + (long) count_free, + (long) count_keep, + (long) count_rescue, + (long) count_finalize)); #endif *out_count_keep = count_keep; } @@ -843,7 +843,7 @@ e++; } } -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ /* * Object compaction. @@ -862,7 +862,12 @@ } #if defined(DUK_USE_DEBUG) -DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start, duk_size_t *p_count_check, duk_size_t *p_count_compact, duk_size_t *p_count_bytes_saved) { +DUK_LOCAL void duk__compact_object_list(duk_heap *heap, + duk_hthread *thr, + duk_heaphdr *start, + duk_size_t *p_count_check, + duk_size_t *p_count_compact, + duk_size_t *p_count_bytes_saved) { #else DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start) { #endif @@ -884,9 +889,8 @@ obj = (duk_hobject *) curr; #if defined(DUK_USE_DEBUG) - old_size = DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)); + old_size = + DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)); #endif DUK_DD(DUK_DDPRINT("compact object: %p", (void *) obj)); @@ -895,9 +899,8 @@ duk_safe_call(thr, duk__protected_compact_object, NULL, 1, 0); #if defined(DUK_USE_DEBUG) - new_size = DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)); + new_size = + DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)); #endif #if defined(DUK_USE_DEBUG) @@ -905,7 +908,7 @@ (*p_count_bytes_saved) += (duk_size_t) (old_size - new_size); #endif - next: + next: curr = DUK_HEAPHDR_GET_NEXT(heap, curr); #if defined(DUK_USE_DEBUG) (*p_count_check)++; @@ -937,12 +940,14 @@ #endif #endif #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif #if defined(DUK_USE_DEBUG) DUK_D(DUK_DPRINT("mark-and-sweep compact objects: %ld checked, %ld compaction attempts, %ld bytes saved by compaction", - (long) count_check, (long) count_compact, (long) count_bytes_saved)); + (long) count_check, + (long) count_compact, + (long) count_bytes_saved)); #endif } @@ -989,7 +994,7 @@ DUK_LOCAL void duk__assert_heaphdr_flags(duk_heap *heap) { duk__assert_walk_list(heap, heap->heap_allocated, duk__assert_heaphdr_flags_cb); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif /* XXX: Assertions for finalize_list? */ } @@ -1020,8 +1025,7 @@ /* Cannot really assert much w.r.t. refcounts now. */ DUK_UNREF(heap); - if (DUK_HEAPHDR_GET_REFCOUNT(h) == 0 && - DUK_HEAPHDR_HAS_FINALIZED(h)) { + if (DUK_HEAPHDR_GET_REFCOUNT(h) == 0 && DUK_HEAPHDR_HAS_FINALIZED(h)) { /* An object may be in heap_allocated list with a zero * refcount if it has just been finalized and is waiting * to be collected by the next cycle. @@ -1035,7 +1039,7 @@ * (presumably not reachable because refcount is 0). */ } - DUK_ASSERT_DISABLE(DUK_HEAPHDR_GET_REFCOUNT(h) >= 0); /* Unsigned. */ + DUK_ASSERT_DISABLE(DUK_HEAPHDR_GET_REFCOUNT(h) >= 0); /* Unsigned. */ } DUK_LOCAL void duk__assert_valid_refcounts(duk_heap *heap) { duk__assert_walk_list(heap, heap->heap_allocated, duk__assert_valid_refcounts_cb); @@ -1086,8 +1090,10 @@ count_ok = ((duk_size_t) DUK_HEAPHDR_GET_REFCOUNT(hdr) == expect_refc); if (!count_ok) { DUK_D(DUK_DPRINT("refcount mismatch for: %p: header=%ld counted=%ld --> %!iO", - (void *) hdr, (long) DUK_HEAPHDR_GET_REFCOUNT(hdr), - (long) hdr->h_assert_refcount, hdr)); + (void *) hdr, + (long) DUK_HEAPHDR_GET_REFCOUNT(hdr), + (long) hdr->h_assert_refcount, + hdr)); DUK_ASSERT(0); } } @@ -1108,7 +1114,7 @@ /* XXX: Assert anything for refzero_list? */ duk__assert_walk_strtable(heap, duk__check_assert_refcounts_cb2); } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_LITCACHE_SIZE) DUK_LOCAL void duk__assert_litcache_nulls(duk_heap *heap) { @@ -1124,8 +1130,8 @@ DUK_ASSERT(e->addr == NULL); } } -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_ASSERTIONS */ /* * Stats dump. @@ -1134,49 +1140,64 @@ #if defined(DUK_USE_DEBUG) DUK_LOCAL void duk__dump_stats(duk_heap *heap) { DUK_D(DUK_DPRINT("stats executor: opcodes=%ld, interrupt=%ld, throw=%ld", - (long) heap->stats_exec_opcodes, (long) heap->stats_exec_interrupt, + (long) heap->stats_exec_opcodes, + (long) heap->stats_exec_interrupt, (long) heap->stats_exec_throw)); DUK_D(DUK_DPRINT("stats call: all=%ld, tailcall=%ld, ecmatoecma=%ld", - (long) heap->stats_call_all, (long) heap->stats_call_tailcall, + (long) heap->stats_call_all, + (long) heap->stats_call_tailcall, (long) heap->stats_call_ecmatoecma)); DUK_D(DUK_DPRINT("stats safecall: all=%ld, nothrow=%ld, throw=%ld", - (long) heap->stats_safecall_all, (long) heap->stats_safecall_nothrow, + (long) heap->stats_safecall_all, + (long) heap->stats_safecall_nothrow, (long) heap->stats_safecall_throw)); DUK_D(DUK_DPRINT("stats mark-and-sweep: try_count=%ld, skip_count=%ld, emergency_count=%ld", - (long) heap->stats_ms_try_count, (long) heap->stats_ms_skip_count, + (long) heap->stats_ms_try_count, + (long) heap->stats_ms_skip_count, (long) heap->stats_ms_emergency_count)); DUK_D(DUK_DPRINT("stats stringtable: intern_hit=%ld, intern_miss=%ld, " "resize_check=%ld, resize_grow=%ld, resize_shrink=%ld, " "litcache_hit=%ld, litcache_miss=%ld, litcache_pin=%ld", - (long) heap->stats_strtab_intern_hit, (long) heap->stats_strtab_intern_miss, - (long) heap->stats_strtab_resize_check, (long) heap->stats_strtab_resize_grow, - (long) heap->stats_strtab_resize_shrink, (long) heap->stats_strtab_litcache_hit, - (long) heap->stats_strtab_litcache_miss, (long) heap->stats_strtab_litcache_pin)); + (long) heap->stats_strtab_intern_hit, + (long) heap->stats_strtab_intern_miss, + (long) heap->stats_strtab_resize_check, + (long) heap->stats_strtab_resize_grow, + (long) heap->stats_strtab_resize_shrink, + (long) heap->stats_strtab_litcache_hit, + (long) heap->stats_strtab_litcache_miss, + (long) heap->stats_strtab_litcache_pin)); DUK_D(DUK_DPRINT("stats object: realloc_props=%ld, abandon_array=%ld", - (long) heap->stats_object_realloc_props, (long) heap->stats_object_abandon_array)); + (long) heap->stats_object_realloc_props, + (long) heap->stats_object_abandon_array)); DUK_D(DUK_DPRINT("stats getownpropdesc: count=%ld, hit=%ld, miss=%ld", - (long) heap->stats_getownpropdesc_count, (long) heap->stats_getownpropdesc_hit, + (long) heap->stats_getownpropdesc_count, + (long) heap->stats_getownpropdesc_hit, (long) heap->stats_getownpropdesc_miss)); DUK_D(DUK_DPRINT("stats getpropdesc: count=%ld, hit=%ld, miss=%ld", - (long) heap->stats_getpropdesc_count, (long) heap->stats_getpropdesc_hit, + (long) heap->stats_getpropdesc_count, + (long) heap->stats_getpropdesc_hit, (long) heap->stats_getpropdesc_miss)); DUK_D(DUK_DPRINT("stats getprop: all=%ld, arrayidx=%ld, bufobjidx=%ld, " "bufferidx=%ld, bufferlen=%ld, stringidx=%ld, stringlen=%ld, " "proxy=%ld, arguments=%ld", - (long) heap->stats_getprop_all, (long) heap->stats_getprop_arrayidx, - (long) heap->stats_getprop_bufobjidx, (long) heap->stats_getprop_bufferidx, - (long) heap->stats_getprop_bufferlen, (long) heap->stats_getprop_stringidx, - (long) heap->stats_getprop_stringlen, (long) heap->stats_getprop_proxy, + (long) heap->stats_getprop_all, + (long) heap->stats_getprop_arrayidx, + (long) heap->stats_getprop_bufobjidx, + (long) heap->stats_getprop_bufferidx, + (long) heap->stats_getprop_bufferlen, + (long) heap->stats_getprop_stringidx, + (long) heap->stats_getprop_stringlen, + (long) heap->stats_getprop_proxy, (long) heap->stats_getprop_arguments)); DUK_D(DUK_DPRINT("stats putprop: all=%ld, arrayidx=%ld, bufobjidx=%ld, " "bufferidx=%ld, proxy=%ld", - (long) heap->stats_putprop_all, (long) heap->stats_putprop_arrayidx, - (long) heap->stats_putprop_bufobjidx, (long) heap->stats_putprop_bufferidx, + (long) heap->stats_putprop_all, + (long) heap->stats_putprop_arrayidx, + (long) heap->stats_putprop_bufobjidx, + (long) heap->stats_putprop_bufferidx, (long) heap->stats_putprop_proxy)); - DUK_D(DUK_DPRINT("stats getvar: all=%ld", - (long) heap->stats_getvar_all)); - DUK_D(DUK_DPRINT("stats putvar: all=%ld", - (long) heap->stats_putvar_all)); + DUK_D(DUK_DPRINT("stats getvar: all=%ld", (long) heap->stats_getvar_all)); + DUK_D(DUK_DPRINT("stats putvar: all=%ld", (long) heap->stats_putvar_all)); DUK_D(DUK_DPRINT("stats envrec: delayedcreate=%ld, create=%ld, newenv=%ld, oldenv=%ld, pushclosure=%ld", (long) heap->stats_envrec_delayedcreate, (long) heap->stats_envrec_create, @@ -1184,7 +1205,7 @@ (long) heap->stats_envrec_oldenv, (long) heap->stats_envrec_pushclosure)); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Main mark-and-sweep function. @@ -1223,7 +1244,7 @@ DUK_STATS_INC(heap, stats_ms_skip_count); return; } - DUK_ASSERT(heap->ms_running == 0); /* ms_prevent_count is bumped when ms_running is set */ + DUK_ASSERT(heap->ms_running == 0); /* ms_prevent_count is bumped when ms_running is set */ /* Heap_thread is used during mark-and-sweep for refcount finalization * (it's also used for finalizer execution once mark-and-sweep is @@ -1234,7 +1255,8 @@ DUK_ASSERT(heap->heap_thread->valstack != NULL); DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) starting, requested flags: 0x%08lx, effective flags: 0x%08lx", - (unsigned long) flags, (unsigned long) (flags | heap->ms_base_flags))); + (unsigned long) flags, + (unsigned long) (flags | heap->ms_base_flags))); flags |= heap->ms_base_flags; #if defined(DUK_USE_FINALIZER_SUPPORT) @@ -1260,8 +1282,8 @@ * finalizer may trigger a mark-and-sweep. */ duk__assert_valid_refcounts(heap); -#endif /* DUK_USE_REFERENCE_COUNTING */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_ASSERTIONS */ /* * Begin @@ -1305,17 +1327,17 @@ #if defined(DUK_USE_LITCACHE_SIZE) duk__wipe_litcache(heap); #endif - duk__mark_roots_heap(heap); /* Mark main reachability roots. */ + duk__mark_roots_heap(heap); /* Mark main reachability roots. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif - duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ + duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ #if defined(DUK_USE_FINALIZER_SUPPORT) - duk__mark_finalizable(heap); /* Mark finalizable as reachability roots. */ - duk__mark_finalize_list(heap); /* Mark finalizer work list as reachability roots. */ + duk__mark_finalizable(heap); /* Mark finalizable as reachability roots. */ + duk__mark_finalize_list(heap); /* Mark finalizer work list as reachability roots. */ #endif - duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ + duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ /* * Sweep garbage and remove marking flags, and move objects with @@ -1342,7 +1364,7 @@ duk__check_assert_refcounts(heap); #endif #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) duk__clear_finalize_list_flags(heap); @@ -1369,8 +1391,7 @@ * interfering with error state. */ - if ((flags & DUK_MS_FLAG_EMERGENCY) && - !(flags & DUK_MS_FLAG_NO_OBJECT_COMPACTION)) { + if ((flags & DUK_MS_FLAG_EMERGENCY) && !(flags & DUK_MS_FLAG_NO_OBJECT_COMPACTION)) { if (heap->lj.type != DUK_LJ_TYPE_UNKNOWN) { DUK_D(DUK_DPRINT("lj.type (%ld) not DUK_LJ_TYPE_UNKNOWN, skip object compaction", (long) heap->lj.type)); } else { @@ -1403,7 +1424,7 @@ DUK_ASSERT(heap->ms_running == 1); heap->ms_prevent_count = 0; heap->ms_running = 0; - heap->creating_error = entry_creating_error; /* for nested error handling, see GH-2278 */ + heap->creating_error = entry_creating_error; /* for nested error handling, see GH-2278 */ /* * Assertions after @@ -1420,11 +1441,11 @@ * finalizer may trigger a mark-and-sweep. */ duk__assert_valid_refcounts(heap); -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_LITCACHE_SIZE) duk__assert_litcache_nulls(heap); -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_ASSERTIONS */ /* * Reset trigger counter @@ -1432,14 +1453,15 @@ #if defined(DUK_USE_VOLUNTARY_GC) tmp = (count_keep_obj + count_keep_str) / 256; - heap->ms_trigger_counter = (duk_int_t) ( - (tmp * DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT) + - DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD); + heap->ms_trigger_counter = (duk_int_t) ((tmp * DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT) + DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD); DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) finished: %ld objects kept, %ld strings kept, trigger reset to %ld", - (long) count_keep_obj, (long) count_keep_str, (long) heap->ms_trigger_counter)); + (long) count_keep_obj, + (long) count_keep_str, + (long) heap->ms_trigger_counter)); #else DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) finished: %ld objects kept, %ld strings kept, no voluntary trigger", - (long) count_keep_obj, (long) count_keep_str)); + (long) count_keep_obj, + (long) count_keep_str)); #endif /* @@ -1482,5 +1504,5 @@ * is inside the target. */ duk_heap_process_finalize_list(heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heap_memory.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heap_memory.c
Changed
@@ -58,7 +58,8 @@ res = heap->alloc_func(heap->heap_udata, size); if (res != NULL) { DUK_D(DUK_DPRINT("duk_heap_mem_alloc() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) size)); + (long) (i + 1), + (long) size)); return res; } } @@ -102,7 +103,7 @@ return res; } - slowpath: +slowpath: if (size == 0) { DUK_D(DUK_DPRINT("first alloc attempt returned NULL for zero size alloc, use slow path to deal with it")); @@ -177,13 +178,7 @@ /* ptr may be NULL */ DUK_ASSERT_DISABLE(newsize >= 0); - /* Newsize was 0 and realloc() returned NULL, this has the semantics - * of free(oldptr), i.e. memory was successfully freed. - */ - if (newsize == 0) { - DUK_D(DUK_DPRINT("zero size realloc in slow path, return NULL")); - return NULL; - } + /* Unlike for malloc(), zero size NULL result check happens at the call site. */ DUK_D(DUK_DPRINT("first realloc attempt failed, attempt to gc and retry")); @@ -214,11 +209,11 @@ duk_heap_mark_and_sweep(heap, flags); - DUK_ASSERT(newsize > 0); res = heap->realloc_func(heap->heap_udata, ptr, newsize); - if (res || newsize == 0) { + if (res != NULL || newsize == 0) { DUK_D(DUK_DPRINT("duk_heap_mem_realloc() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) newsize)); + (long) (i + 1), + (long) newsize)); return res; } } @@ -238,7 +233,7 @@ #if defined(DUK_USE_VOLUNTARY_GC) /* Voluntary periodic GC (if enabled). */ if (DUK_UNLIKELY(--(heap)->ms_trigger_counter < 0)) { - goto slowpath; + goto gc_retry; } #endif @@ -250,22 +245,22 @@ DUK_DDD(DUK_DDDPRINT("gc torture enabled, pretend that first realloc attempt fails")); res = NULL; DUK_UNREF(res); - goto slowpath; + goto gc_retry; } #endif res = heap->realloc_func(heap->heap_udata, ptr, newsize); - if (DUK_LIKELY(res != NULL)) { + if (DUK_LIKELY(res != NULL) || newsize == 0) { + if (res != NULL && newsize == 0) { + DUK_DD(DUK_DDPRINT("first realloc attempt returned NULL for zero size realloc, accept and return NULL")); + } return res; - } - - slowpath: - - if (newsize == 0) { - DUK_D(DUK_DPRINT("first realloc attempt returned NULL for zero size realloc, use slow path to deal with it")); } else { - DUK_D(DUK_DPRINT("first realloc attempt failed, attempt to gc and retry")); + goto gc_retry; } + /* Never here. */ + +gc_retry: return duk__heap_mem_realloc_slowpath(heap, ptr, newsize); } @@ -276,7 +271,10 @@ */ /* Slow path: voluntary GC triggered, first realloc attempt failed, or zero size. */ -DUK_LOCAL DUK_NOINLINE_PERF DUK_COLD void *duk__heap_mem_realloc_indirect_slowpath(duk_heap *heap, duk_mem_getptr cb, void *ud, duk_size_t newsize) { +DUK_LOCAL DUK_NOINLINE_PERF DUK_COLD void *duk__heap_mem_realloc_indirect_slowpath(duk_heap *heap, + duk_mem_getptr cb, + void *ud, + duk_size_t newsize) { void *res; duk_small_int_t i; @@ -284,10 +282,7 @@ DUK_ASSERT(heap->realloc_func != NULL); DUK_ASSERT_DISABLE(newsize >= 0); - if (newsize == 0) { - DUK_D(DUK_DPRINT("zero size indirect realloc in slow path, return NULL")); - return NULL; - } + /* Unlike for malloc(), zero size NULL result check happens at the call site. */ DUK_D(DUK_DPRINT("first indirect realloc attempt failed, attempt to gc and retry")); @@ -329,7 +324,8 @@ ptr_post = cb(heap, ud); if (ptr_pre != ptr_post) { DUK_DD(DUK_DDPRINT("realloc base pointer changed by mark-and-sweep: %p -> %p", - (void *) ptr_pre, (void *) ptr_post)); + (void *) ptr_pre, + (void *) ptr_post)); } #endif @@ -337,11 +333,11 @@ * The pointer being reallocated may change after every mark-and-sweep. */ - DUK_ASSERT(newsize > 0); res = heap->realloc_func(heap->heap_udata, cb(heap, ud), newsize); - if (res || newsize == 0) { + if (res != NULL || newsize == 0) { DUK_D(DUK_DPRINT("duk_heap_mem_realloc_indirect() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) newsize)); + (long) (i + 1), + (long) newsize)); return res; } } @@ -350,7 +346,10 @@ return NULL; } -DUK_INTERNAL DUK_INLINE_PERF DUK_HOT void *duk_heap_mem_realloc_indirect(duk_heap *heap, duk_mem_getptr cb, void *ud, duk_size_t newsize) { +DUK_INTERNAL DUK_INLINE_PERF DUK_HOT void *duk_heap_mem_realloc_indirect(duk_heap *heap, + duk_mem_getptr cb, + void *ud, + duk_size_t newsize) { void *res; DUK_ASSERT(heap != NULL); @@ -360,7 +359,7 @@ #if defined(DUK_USE_VOLUNTARY_GC) /* Voluntary periodic GC (if enabled). */ if (DUK_UNLIKELY(--(heap)->ms_trigger_counter < 0)) { - goto slowpath; + goto gc_retry; } #endif @@ -372,22 +371,23 @@ DUK_DDD(DUK_DDDPRINT("gc torture enabled, pretend that first indirect realloc attempt fails")); res = NULL; DUK_UNREF(res); - goto slowpath; + goto gc_retry; } #endif res = heap->realloc_func(heap->heap_udata, cb(heap, ud), newsize); - if (DUK_LIKELY(res != NULL)) { + if (DUK_LIKELY(res != NULL) || newsize == 0) { + if (res != NULL && newsize == 0) { + DUK_DD(DUK_DDPRINT( + "first indirect realloc attempt returned NULL for zero size realloc, accept and return NULL")); + } return res; - } - - slowpath: - - if (newsize == 0) { - DUK_D(DUK_DPRINT("first indirect realloc attempt returned NULL for zero size realloc, use slow path to deal with it")); } else { - DUK_D(DUK_DPRINT("first indirect realloc attempt failed, attempt to gc and retry")); + goto gc_retry; } + /* Never here. */ + +gc_retry: return duk__heap_mem_realloc_indirect_slowpath(heap, cb, ud, newsize); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heap_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heap_misc.c
Changed
@@ -64,7 +64,7 @@ ; } } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL void duk_heap_insert_into_finalize_list(duk_heap *heap, duk_heaphdr *hdr) { @@ -83,7 +83,7 @@ DUK_HEAPHDR_ASSERT_LINKS(heap, root); heap->finalize_list = hdr; } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL void duk_heap_remove_from_finalize_list(duk_heap *heap, duk_heaphdr *hdr) { @@ -117,7 +117,7 @@ } else { DUK_ASSERT(hdr != heap->finalize_list); for (;;) { - DUK_ASSERT(curr != NULL); /* Caller responsibility. */ + DUK_ASSERT(curr != NULL); /* Caller responsibility. */ next = DUK_HEAPHDR_GET_NEXT(heap, curr); if (next == hdr) { @@ -129,7 +129,7 @@ } #endif } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL duk_bool_t duk_heap_in_heap_allocated(duk_heap *heap, duk_heaphdr *ptr) { @@ -143,7 +143,7 @@ } return 0; } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ #if defined(DUK_USE_INTERRUPT_COUNTER) DUK_INTERNAL void duk_heap_switch_thread(duk_heap *heap, duk_hthread *new_thr) { @@ -176,9 +176,9 @@ DUK_DD(DUK_DDPRINT("switch thread, new thread is NULL, no interrupt counter changes")); } - heap->curr_thread = new_thr; /* may be NULL */ + heap->curr_thread = new_thr; /* may be NULL */ } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL void duk_heap_assert_valid(duk_heap *heap) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heap_refcount.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heap_refcount.c
Changed
@@ -160,7 +160,7 @@ } else if (DUK_HOBJECT_IS_OBJENV(h)) { duk_hobjenv *e = (duk_hobjenv *) h; DUK_HOBJENV_ASSERT_VALID(e); - DUK_ASSERT(e->target != NULL); /* Required for object environments. */ + DUK_ASSERT(e->target != NULL); /* Required for object environments. */ DUK_HOBJECT_DECREF_NORZ(thr, e->target); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) } else if (DUK_HOBJECT_IS_BUFOBJ(h)) { @@ -168,7 +168,7 @@ DUK_HBUFOBJ_ASSERT_VALID(b); DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, (duk_hbuffer *) b->buf); DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) b->buf_prop); -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ } else if (DUK_HOBJECT_IS_BOUNDFUNC(h)) { duk_hboundfunc *f = (duk_hboundfunc *) (void *) h; DUK_HBOUNDFUNC_ASSERT_VALID(f); @@ -181,7 +181,7 @@ DUK_HPROXY_ASSERT_VALID(p); DUK_HOBJECT_DECREF_NORZ(thr, p->target); DUK_HOBJECT_DECREF_NORZ(thr, p->handler); -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ } else if (DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; duk_activation *act; @@ -202,13 +202,12 @@ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) act->prev_caller); #endif -#if 0 /* nothing now */ +#if 0 /* nothing now */ for (cat = act->cat; cat != NULL; cat = cat->parent) { } #endif } - for (i = 0; i < DUK_NUM_BUILTINS; i++) { DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) t->builtinsi); } @@ -293,7 +292,7 @@ curr = heap->refzero_list; DUK_ASSERT(curr != NULL); - DUK_ASSERT(DUK_HEAPHDR_GET_PREV(heap, curr) == NULL); /* We're called on initial insert only. */ + DUK_ASSERT(DUK_HEAPHDR_GET_PREV(heap, curr) == NULL); /* We're called on initial insert only. */ /* curr->next is GARBAGE. */ do { @@ -306,7 +305,7 @@ #endif DUK_ASSERT(curr != NULL); - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ /* FINALIZED may be set; don't care about flags here. */ /* Refcount finalize 'curr'. Refzero_list must be non-NULL @@ -316,11 +315,10 @@ duk_hobject_refcount_finalize_norz(heap, (duk_hobject *) curr); prev = DUK_HEAPHDR_GET_PREV(heap, curr); - DUK_ASSERT((prev == NULL && heap->refzero_list == curr) || \ - (prev != NULL && heap->refzero_list != curr)); + DUK_ASSERT((prev == NULL && heap->refzero_list == curr) || (prev != NULL && heap->refzero_list != curr)); /* prev->next is intentionally not updated and is garbage. */ - duk_free_hobject(heap, (duk_hobject *) curr); /* Invalidates 'curr'. */ + duk_free_hobject(heap, (duk_hobject *) curr); /* Invalidates 'curr'. */ curr = prev; } while (curr != NULL); @@ -396,7 +394,7 @@ return; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* No need to finalize, free object via refzero_list. */ @@ -440,7 +438,7 @@ DUK_INTERNAL DUK_ALWAYS_INLINE void duk_refzero_check_fast(duk_hthread *thr) { DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ + DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ if (DUK_UNLIKELY(thr->heap->finalize_list != NULL)) { duk_heap_process_finalize_list(thr->heap); @@ -450,13 +448,13 @@ DUK_INTERNAL void duk_refzero_check_slow(duk_hthread *thr) { DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ + DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ if (DUK_UNLIKELY(thr->heap->finalize_list != NULL)) { duk_heap_process_finalize_list(thr->heap); } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Refzero processing for duk_hstring. @@ -516,7 +514,8 @@ * The suppress condition is important to performance. */ -#define DUK__RZ_SUPPRESS_ASSERT1() do { \ +#define DUK__RZ_SUPPRESS_ASSERT1() \ + do { \ DUK_ASSERT(thr != NULL); \ DUK_ASSERT(thr->heap != NULL); \ /* When mark-and-sweep runs, heap_thread must exist. */ \ @@ -538,32 +537,41 @@ } while (0) #if defined(DUK_USE_DEBUGGER_SUPPORT) -#define DUK__RZ_SUPPRESS_ASSERT2() do { \ +#define DUK__RZ_SUPPRESS_ASSERT2() \ + do { \ /* When debugger is paused, ms_running is set. */ \ DUK_ASSERT(!DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || thr->heap->ms_running != 0); \ } while (0) -#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) +#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) #else -#define DUK__RZ_SUPPRESS_ASSERT2() do { } while (0) -#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#define DUK__RZ_SUPPRESS_ASSERT2() \ + do { \ + } while (0) +#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) +#endif /* DUK_USE_DEBUGGER_SUPPORT */ -#define DUK__RZ_SUPPRESS_CHECK() do { \ +#define DUK__RZ_SUPPRESS_CHECK() \ + do { \ DUK__RZ_SUPPRESS_ASSERT1(); \ DUK__RZ_SUPPRESS_ASSERT2(); \ if (DUK_UNLIKELY(DUK__RZ_SUPPRESS_COND())) { \ - DUK_DDD(DUK_DDDPRINT("refzero handling suppressed (not even queued) when mark-and-sweep running, object: %p", (void *) h)); \ + DUK_DDD( \ + DUK_DDDPRINT("refzero handling suppressed (not even queued) when mark-and-sweep running, object: %p", \ + (void *) h)); \ return; \ } \ } while (0) -#define DUK__RZ_STRING() do { \ +#define DUK__RZ_STRING() \ + do { \ duk__refcount_refzero_hstring(heap, (duk_hstring *) h); \ } while (0) -#define DUK__RZ_BUFFER() do { \ +#define DUK__RZ_BUFFER() \ + do { \ duk__refcount_refzero_hbuffer(heap, (duk_hbuffer *) h); \ } while (0) -#define DUK__RZ_OBJECT() do { \ +#define DUK__RZ_OBJECT() \ + do { \ duk__refcount_refzero_hobject(heap, (duk_hobject *) h, skip_free_pending); \ } while (0) @@ -684,7 +692,7 @@ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(h)); DUK_ASSERT_DISABLE(h->h_refcount >= 0); DUK_HEAPHDR_PREINC_REFCOUNT(h); - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(h) != 0); /* No wrapping. */ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(h) != 0); /* No wrapping. */ } } @@ -727,9 +735,10 @@ #endif } } -#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ +#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ -#define DUK__DECREF_ASSERTS() do { \ +#define DUK__DECREF_ASSERTS() \ + do { \ DUK_ASSERT(thr != NULL); \ DUK_ASSERT(thr->heap != NULL); \ DUK_ASSERT(h != NULL); \ @@ -737,14 +746,16 @@ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) >= 1); \ } while (0) #if defined(DUK_USE_ROM_OBJECTS) -#define DUK__INCREF_SHARED() do { \ +#define DUK__INCREF_SHARED() \ + do { \ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) h)) { \ return; \ } \ DUK_HEAPHDR_PREINC_REFCOUNT((duk_heaphdr *) h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ } while (0) -#define DUK__DECREF_SHARED() do { \ +#define DUK__DECREF_SHARED() \ + do { \ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) h)) { \ return; \ } \ @@ -753,11 +764,13 @@ } \ } while (0) #else -#define DUK__INCREF_SHARED() do { \ +#define DUK__INCREF_SHARED() \ + do { \ DUK_HEAPHDR_PREINC_REFCOUNT((duk_heaphdr *) h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ } while (0) -#define DUK__DECREF_SHARED() do { \ +#define DUK__DECREF_SHARED() \ + do { \ if (DUK_HEAPHDR_PREDEC_REFCOUNT((duk_heaphdr *) h) != 0) { \ return; \ } \ @@ -791,9 +804,9 @@ DUK__DECREF_SHARED(); duk_heaphdr_refzero_norz(thr, h); } -#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ +#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ -#if 0 /* Not needed. */ +#if 0 /* Not needed. */ DUK_INTERNAL void duk_hstring_decref(duk_hthread *thr, duk_hstring *h) { DUK__DECREF_ASSERTS(); DUK__DECREF_SHARED(); @@ -826,8 +839,8 @@ } #endif -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ /* no refcounting */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heap_stringcache.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heap_stringcache.c
Changed
@@ -22,8 +22,8 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; if (c->h == h) { - DUK_DD(DUK_DDPRINT("deleting weak strcache reference to hstring %p from heap %p", - (void *) h, (void *) heap)); + DUK_DD( + DUK_DDPRINT("deleting weak strcache reference to hstring %p from heap %p", (void *) h, (void *) heap)); c->h = NULL; /* XXX: the string shouldn't appear twice, but we now loop to the @@ -133,7 +133,8 @@ */ DUK_DDD(DUK_DDDPRINT("non-ascii string %p, char_offset=%ld, clen=%ld, blen=%ld", - (void *) h, (long) char_offset, + (void *) h, + (long) char_offset, (long) DUK_HSTRING_GET_CHARLEN(h), (long) DUK_HSTRING_GET_BYTELEN(h))); @@ -147,7 +148,10 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; DUK_DDD(DUK_DDDPRINT(" %ld -> h=%p, cidx=%ld, bidx=%ld", - (long) i, (void *) c->h, (long) c->cidx, (long) c->bidx)); + (long) i, + (void *) c->h, + (long) c->cidx, + (long) c->bidx)); } #endif @@ -171,7 +175,8 @@ DUK_ASSERT(DUK_HSTRING_GET_CHARLEN(h) >= char_offset); dist_start = char_offset; dist_end = char_length - char_offset; - dist_sce = 0; DUK_UNREF(dist_sce); /* initialize for debug prints, needed if sce==NULL */ + dist_sce = 0; + DUK_UNREF(dist_sce); /* initialize for debug prints, needed if sce==NULL */ p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h); p_end = (const duk_uint8_t *) (p_start + DUK_HSTRING_GET_BYTELEN(h)); @@ -184,14 +189,15 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan forwards from sce", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_forwards(p_start + sce->bidx, - p_end, - dist_sce); + p_found = duk__scan_forwards(p_start + sce->bidx, p_end, dist_sce); goto scan_done; } } else { @@ -200,14 +206,15 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan backwards from sce", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_backwards(p_start + sce->bidx, - p_start, - dist_sce); + p_found = duk__scan_backwards(p_start + sce->bidx, p_start, dist_sce); goto scan_done; } } @@ -219,29 +226,31 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan forwards from string start", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_forwards(p_start, - p_end, - dist_start); + p_found = duk__scan_forwards(p_start, p_end, dist_start); } else { DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan backwards from string end", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_backwards(p_end, - p_start, - dist_end); + p_found = duk__scan_backwards(p_end, p_start, dist_end); } - scan_done: +scan_done: if (DUK_UNLIKELY(p_found == NULL)) { /* Scan error: this shouldn't normally happen; it could happen if @@ -252,11 +261,10 @@ } DUK_ASSERT(p_found >= p_start); - DUK_ASSERT(p_found <= p_end); /* may be equal */ + DUK_ASSERT(p_found <= p_end); /* may be equal */ byte_offset = (duk_uint32_t) (p_found - p_start); - DUK_DDD(DUK_DDDPRINT("-> string %p, cidx %ld -> bidx %ld", - (void *) h, (long) char_offset, (long) byte_offset)); + DUK_DDD(DUK_DDDPRINT("-> string %p, cidx %ld -> bidx %ld", (void *) h, (long) char_offset, (long) byte_offset)); /* * Update cache entry (allocating if necessary), and move the @@ -266,7 +274,7 @@ if (use_cache) { /* update entry, allocating if necessary */ if (!sce) { - sce = heap->strcache + DUK_HEAP_STRCACHE_SIZE - 1; /* take last entry */ + sce = heap->strcache + DUK_HEAP_STRCACHE_SIZE - 1; /* take last entry */ sce->h = h; } DUK_ASSERT(sce != NULL); @@ -296,14 +304,17 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; DUK_DDD(DUK_DDDPRINT(" %ld -> h=%p, cidx=%ld, bidx=%ld", - (long) i, (void *) c->h, (long) c->cidx, (long) c->bidx)); + (long) i, + (void *) c->h, + (long) c->cidx, + (long) c->bidx)); } #endif } return byte_offset; - scan_error: +scan_error: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heap_stringtable.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heap_stringtable.c
Changed
@@ -13,16 +13,16 @@ #endif #if defined(DUK_USE_STRTAB_PTRCOMP) -#define DUK__HEAPPTR_ENC16(heap,ptr) DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (ptr)) -#define DUK__HEAPPTR_DEC16(heap,val) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (val)) -#define DUK__GET_STRTABLE(heap) ((heap)->strtable16) +#define DUK__HEAPPTR_ENC16(heap, ptr) DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (ptr)) +#define DUK__HEAPPTR_DEC16(heap, val) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (val)) +#define DUK__GET_STRTABLE(heap) ((heap)->strtable16) #else -#define DUK__HEAPPTR_ENC16(heap,ptr) (ptr) -#define DUK__HEAPPTR_DEC16(heap,val) (val) -#define DUK__GET_STRTABLE(heap) ((heap)->strtable) +#define DUK__HEAPPTR_ENC16(heap, ptr) (ptr) +#define DUK__HEAPPTR_DEC16(heap, val) (val) +#define DUK__GET_STRTABLE(heap) ((heap)->strtable) #endif -#define DUK__STRTAB_U32_MAX_STRLEN 10 /* 4'294'967'295 */ +#define DUK__STRTAB_U32_MAX_STRLEN 10 /* 4'294'967'295 */ /* * Debug dump stringtable. @@ -41,7 +41,7 @@ duk_size_t count_chain; duk_size_t count_chain_min = DUK_SIZE_MAX; duk_size_t count_chain_max = 0; - duk_size_t count_len8; /* chain lengths from 0 to 7 */ + duk_size_t count_len8; /* chain lengths from 0 to 7 */ if (heap == NULL) { DUK_D(DUK_DPRINT("string table, heap=NULL")); @@ -72,15 +72,21 @@ DUK_D(DUK_DPRINT("string table, strtab=%p, count=%lu, chain min=%lu max=%lu avg=%lf: " "counts: %lu %lu %lu %lu %lu %lu %lu %lu ...", - (void *) heap->strtable, (unsigned long) count_total, - (unsigned long) count_chain_min, (unsigned long) count_chain_max, + (void *) heap->strtable, + (unsigned long) count_total, + (unsigned long) count_chain_min, + (unsigned long) count_chain_max, (double) count_total / (double) heap->st_size, - (unsigned long) count_len0, (unsigned long) count_len1, - (unsigned long) count_len2, (unsigned long) count_len3, - (unsigned long) count_len4, (unsigned long) count_len5, - (unsigned long) count_len6, (unsigned long) count_len7)); + (unsigned long) count_len0, + (unsigned long) count_len1, + (unsigned long) count_len2, + (unsigned long) count_len3, + (unsigned long) count_len4, + (unsigned long) count_len5, + (unsigned long) count_len6, + (unsigned long) count_len7)); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Assertion helper to ensure strtable is populated correctly. @@ -121,7 +127,7 @@ DUK_ASSERT(count == (duk_size_t) heap->st_count); #endif } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Allocate and initialize a duk_hstring. @@ -172,16 +178,16 @@ #endif DUK_HEAPHDR_SET_TYPE_AND_FLAGS(&res->hdr, DUK_HTYPE_STRING, DUK_HSTRING_FLAG_EXTDATA); - DUK_ASSERT(extdatablen == 0); /* Application responsibility. */ + DUK_ASSERT(extdatablen == 0); /* Application responsibility. */ data = extdata; ((duk_hstring_external *) res)->extdata = extdata; } else -#endif /* DUK_USE_HSTRING_EXTDATA && DUK_USE_EXTSTR_INTERN_CHECK */ +#endif /* DUK_USE_HSTRING_EXTDATA && DUK_USE_EXTSTR_INTERN_CHECK */ { duk_uint8_t *data_tmp; /* NUL terminate for convenient C access */ - DUK_ASSERT(sizeof(duk_hstring) + blen + 1 > blen); /* No wrap, limits ensure. */ + DUK_ASSERT(sizeof(duk_hstring) + blen + 1 > blen); /* No wrap, limits ensure. */ res = (duk_hstring *) DUK_ALLOC(heap, sizeof(duk_hstring) + blen + 1); if (DUK_UNLIKELY(res == NULL)) { goto alloc_error; @@ -240,7 +246,7 @@ #if defined(DUK_USE_HSTRING_LAZY_CLEN) /* Charlen initialized to 0, updated on-the-fly. */ #else - duk_hstring_init_charlen(res); /* Also sets ASCII flag. */ + duk_hstring_init_charlen(res); /* Also sets ASCII flag. */ #endif } @@ -253,7 +259,7 @@ DUK_ASSERT(res != NULL); return res; - alloc_error: +alloc_error: return NULL; } @@ -282,13 +288,13 @@ DUK_ASSERT(heap != NULL); DUK_ASSERT(heap->st_resizing == 1); DUK_ASSERT(heap->st_size >= 2); - DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ + DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ DUK_ASSERT(DUK__GET_STRTABLE(heap) != NULL); DUK_STATS_INC(heap, stats_strtab_resize_grow); new_st_size = heap->st_size << 1U; - DUK_ASSERT(new_st_size > heap->st_size); /* No overflow. */ + DUK_ASSERT(new_st_size > heap->st_size); /* No overflow. */ /* Reallocate the strtable first and then work in-place to rehash * strings. We don't need an indirect allocation here: even if GC @@ -372,7 +378,7 @@ duk__strtable_assert_checks(heap); #endif } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Shrink strtable allocation in-place. @@ -400,7 +406,7 @@ DUK_ASSERT(heap != NULL); DUK_ASSERT(heap->st_resizing == 1); DUK_ASSERT(heap->st_size >= 2); - DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ + DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ DUK_ASSERT(DUK__GET_STRTABLE(heap) != NULL); DUK_STATS_INC(heap, stats_strtab_resize_shrink); @@ -458,7 +464,7 @@ duk__strtable_assert_checks(heap); #endif } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Grow/shrink check. @@ -466,7 +472,7 @@ #if defined(DUK__STRTAB_RESIZE_CHECK) DUK_LOCAL DUK_COLD DUK_NOINLINE void duk__strtable_resize_check(duk_heap *heap) { - duk_uint32_t load_factor; /* fixed point */ + duk_uint32_t load_factor; /* fixed point */ DUK_ASSERT(heap != NULL); #if defined(DUK_USE_STRTAB_PTRCOMP) @@ -490,7 +496,8 @@ load_factor = heap->st_count / (heap->st_size >> 4U); DUK_DD(DUK_DDPRINT("resize check string table: size=%lu, count=%lu, load_factor=%lu (fixed point .4; float %lf)", - (unsigned long) heap->st_size, (unsigned long) heap->st_count, + (unsigned long) heap->st_size, + (unsigned long) heap->st_count, (unsigned long) load_factor, (double) heap->st_count / (double) heap->st_size)); @@ -498,7 +505,9 @@ if (heap->st_size >= DUK_USE_STRTAB_MAXSIZE) { DUK_DD(DUK_DDPRINT("want to grow strtable (based on load factor) but already maximum size")); } else { - DUK_D(DUK_DPRINT("grow string table: %lu -> %lu", (unsigned long) heap->st_size, (unsigned long) heap->st_size * 2)); + DUK_D(DUK_DPRINT("grow string table: %lu -> %lu", + (unsigned long) heap->st_size, + (unsigned long) heap->st_size * 2)); #if defined(DUK_USE_DEBUG) duk_heap_strtable_dump(heap); #endif @@ -508,7 +517,9 @@ if (heap->st_size <= DUK_USE_STRTAB_MINSIZE) { DUK_DD(DUK_DDPRINT("want to shrink strtable (based on load factor) but already minimum size")); } else { - DUK_D(DUK_DPRINT("shrink string table: %lu -> %lu", (unsigned long) heap->st_size, (unsigned long) heap->st_size / 2)); + DUK_D(DUK_DPRINT("shrink string table: %lu -> %lu", + (unsigned long) heap->st_size, + (unsigned long) heap->st_size / 2)); #if defined(DUK_USE_DEBUG) duk_heap_strtable_dump(heap); #endif @@ -520,7 +531,7 @@ heap->st_resizing = 0; } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Torture grow/shrink: unconditionally grow and shrink back. @@ -544,7 +555,7 @@ } heap->st_resizing = 0; } -#endif /* DUK_USE_STRTAB_TORTURE && DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK_USE_STRTAB_TORTURE && DUK__STRTAB_RESIZE_CHECK */ /* * Raw intern; string already checked not to be present. @@ -560,8 +571,12 @@ #endif DUK_DDD(DUK_DDDPRINT("do_intern: heap=%p, str=%p, blen=%lu, strhash=%lx, st_size=%lu, st_count=%lu, load=%lf", - (void *) heap, (const void *) str, (unsigned long) blen, (unsigned long) strhash, - (unsigned long) heap->st_size, (unsigned long) heap->st_count, + (void *) heap, + (const void *) str, + (unsigned long) blen, + (unsigned long) strhash, + (unsigned long) heap->st_size, + (unsigned long) heap->st_count, (double) heap->st_count / (double) heap->st_size)); DUK_ASSERT(heap != NULL); @@ -577,7 +592,7 @@ */ heap->pf_prevent_count++; - DUK_ASSERT(heap->pf_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(heap->pf_prevent_count != 0); /* Wrap. */ #if defined(DUK_USE_STRTAB_TORTURE) && defined(DUK__STRTAB_RESIZE_CHECK) duk__strtable_resize_torture(heap); @@ -604,7 +619,8 @@ /* External string check (low memory optimization). */ #if defined(DUK_USE_HSTRING_EXTDATA) && defined(DUK_USE_EXTSTR_INTERN_CHECK) - extdata = (const duk_uint8_t *) DUK_USE_EXTSTR_INTERN_CHECK(heap->heap_udata, (void *) DUK_LOSE_CONST(str), (duk_size_t) blen); + extdata = + (const duk_uint8_t *) DUK_USE_EXTSTR_INTERN_CHECK(heap->heap_udata, (void *) DUK_LOSE_CONST(str), (duk_size_t) blen); #else extdata = (const duk_uint8_t *) NULL; #endif @@ -642,7 +658,7 @@ #else slot = heap->strtable + (strhash & heap->st_mask); #endif - DUK_ASSERT(res->hdr.h_next == NULL); /* This is the case now, but unnecessary zeroing/NULLing. */ + DUK_ASSERT(res->hdr.h_next == NULL); /* This is the case now, but unnecessary zeroing/NULLing. */ res->hdr.h_next = DUK__HEAPPTR_DEC16(heap, *slot); *slot = DUK__HEAPPTR_ENC16(heap, res); @@ -689,11 +705,12 @@ curr = (duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_lookuplookup_hash); while (curr != NULL) { /* Unsafe memcmp() because for zero blen, str may be NULL. */ - if (strhash == DUK_HSTRING_GET_HASH(curr) && - blen == DUK_HSTRING_GET_BYTELEN(curr) && + if (strhash == DUK_HSTRING_GET_HASH(curr) && blen == DUK_HSTRING_GET_BYTELEN(curr) && duk_memcmp_unsafe((const void *) str, (const void *) DUK_HSTRING_GET_DATA(curr), blen) == 0) { DUK_DDD(DUK_DDDPRINT("intern check: rom string: %!O, computed hash 0x%08lx, rom hash 0x%08lx", - curr, (unsigned long) strhash, (unsigned long) DUK_HSTRING_GET_HASH(curr))); + curr, + (unsigned long) strhash, + (unsigned long) DUK_HSTRING_GET_HASH(curr))); return curr; } curr = curr->hdr.h_next; @@ -701,7 +718,7 @@ return NULL; } -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ DUK_INTERNAL duk_hstring *duk_heap_strtable_intern(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen) { duk_uint32_t strhash; @@ -714,7 +731,7 @@ /* XXX: maybe just require 'str != NULL' even for zero size? */ DUK_ASSERT(heap != NULL); DUK_ASSERT(blen == 0 || str != NULL); - DUK_ASSERT(blen <= DUK_HSTRING_MAX_BYTELEN); /* Caller is responsible for ensuring this. */ + DUK_ASSERT(blen <= DUK_HSTRING_MAX_BYTELEN); /* Caller is responsible for ensuring this. */ strhash = duk_heap_hashstring(heap, str, (duk_size_t) blen); /* String table lookup. */ @@ -728,8 +745,7 @@ h = heap->strtablestrhash & heap->st_mask; #endif while (h != NULL) { - if (DUK_HSTRING_GET_HASH(h) == strhash && - DUK_HSTRING_GET_BYTELEN(h) == blen && + if (DUK_HSTRING_GET_HASH(h) == strhash && DUK_HSTRING_GET_BYTELEN(h) == blen && duk_memcmp_unsafe((const void *) str, (const void *) DUK_HSTRING_GET_DATA(h), (size_t) blen) == 0) { /* Found existing entry. */ DUK_STATS_INC(heap, stats_strtab_intern_hit); @@ -755,7 +771,7 @@ DUK_STATS_INC(heap, stats_strtab_intern_miss); h = duk__strtable_do_intern(heap, str, blen, strhash); - return h; /* may be NULL */ + return h; /* may be NULL */ } /* @@ -778,7 +794,7 @@ p--; *p = duk_lc_digitsval % 10; val = val / 10; - } while (val != 0); /* For val == 0, emit exactly one '0'. */ + } while (val != 0); /* For val == 0, emit exactly one '0'. */ DUK_ASSERT(p >= buf); return duk_heap_strtable_intern(heap, (const duk_uint8_t *) p, (duk_uint32_t) ((buf + sizeof(buf)) - p)); @@ -816,7 +832,7 @@ DUK_ASSERT(DUK_IS_POWER_OF_TWO((duk_uint_t) DUK_USE_LITCACHE_SIZE)); key = (duk_uintptr_t) blen ^ (duk_uintptr_t) str; - key &= (duk_uintptr_t) (DUK_USE_LITCACHE_SIZE - 1); /* Assumes size is power of 2. */ + key &= (duk_uintptr_t) (DUK_USE_LITCACHE_SIZE - 1); /* Assumes size is power of 2. */ /* Due to masking, cast is in 32-bit range. */ DUK_ASSERT(key <= DUK_UINT_MAX); return (duk_uint_t) key; @@ -832,7 +848,9 @@ ent = thr->heap->litcache + key; if (ent->addr == str) { DUK_DD(DUK_DDPRINT("intern check for cached, pinned literal: str=%p, blen=%ld -> duk_hstring %!O", - (const void *) str, (long) blen, (duk_heaphdr *) ent->h)); + (const void *) str, + (long) blen, + (duk_heaphdr *) ent->h)); DUK_ASSERT(ent->h != NULL); DUK_ASSERT(DUK_HSTRING_HAS_PINNED_LITERAL(ent->h)); DUK_STATS_INC(thr->heap, stats_strtab_litcache_hit); @@ -862,7 +880,7 @@ return h; } -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ DUK_INTERNAL duk_hstring *duk_heap_strtable_intern_u32_checked(duk_hthread *thr, duk_uint32_t val) { duk_hstring *res; @@ -897,7 +915,8 @@ duk_hstring *prev; DUK_DDD(DUK_DDDPRINT("remove: heap=%p, h=%p, blen=%lu, strhash=%lx", - (void *) heap, (void *) h, + (void *) heap, + (void *) h, (unsigned long) (h != NULL ? DUK_HSTRING_GET_BYTELEN(h) : 0), (unsigned long) (h != NULL ? DUK_HSTRING_GET_HASH(h) : 0))); @@ -915,13 +934,13 @@ slot = heap->strtable + (DUK_HSTRING_GET_HASH(h) & heap->st_mask); #endif other = DUK__HEAPPTR_DEC16(heap, *slot); - DUK_ASSERT(other != NULL); /* At least argument string is in the chain. */ + DUK_ASSERT(other != NULL); /* At least argument string is in the chain. */ prev = NULL; while (other != h) { prev = other; other = other->hdr.h_next; - DUK_ASSERT(other != NULL); /* We'll eventually find 'h'. */ + DUK_ASSERT(other != NULL); /* We'll eventually find 'h'. */ } if (prev != NULL) { /* Middle of list. */ @@ -935,7 +954,7 @@ * intern will do one. */ } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* Unlink with a 'prev' pointer. */ DUK_INTERNAL void duk_heap_strtable_unlink_prev(duk_heap *heap, duk_hstring *h, duk_hstring *prev) { @@ -946,7 +965,9 @@ #endif DUK_DDD(DUK_DDDPRINT("remove: heap=%p, prev=%p, h=%p, blen=%lu, strhash=%lx", - (void *) heap, (void *) prev, (void *) h, + (void *) heap, + (void *) prev, + (void *) h, (unsigned long) (h != NULL ? DUK_HSTRING_GET_BYTELEN(h) : 0), (unsigned long) (h != NULL ? DUK_HSTRING_GET_HASH(h) : 0)));
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heaphdr.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heaphdr.h
Changed
@@ -49,7 +49,7 @@ #else duk_size_t h_refcount; #endif -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_HEAPPTR16) duk_uint16_t h_next16; @@ -97,7 +97,7 @@ #endif #if defined(DUK_USE_REFCOUNT16) duk_uint16_t h_refcount; - duk_uint16_t h_strextra16; /* round out to 8 bytes */ + duk_uint16_t h_strextra16; /* round out to 8 bytes */ #elif defined(DUK_USE_REFCOUNT32) duk_uint32_t h_refcount; #else @@ -105,160 +105,169 @@ #endif #else duk_uint16_t h_strextra16; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ duk_hstring *h_next; /* No 'h_prev' pointer for strings. */ }; -#define DUK_HEAPHDR_FLAGS_TYPE_MASK 0x00000003UL -#define DUK_HEAPHDR_FLAGS_FLAG_MASK (~DUK_HEAPHDR_FLAGS_TYPE_MASK) +#define DUK_HEAPHDR_FLAGS_TYPE_MASK 0x00000003UL +#define DUK_HEAPHDR_FLAGS_FLAG_MASK (~DUK_HEAPHDR_FLAGS_TYPE_MASK) - /* 2 bits for heap type */ -#define DUK_HEAPHDR_FLAGS_HEAP_START 2 /* 5 heap flags */ -#define DUK_HEAPHDR_FLAGS_USER_START 7 /* 25 user flags */ +/* 2 bits for heap type */ +#define DUK_HEAPHDR_FLAGS_HEAP_START 2 /* 5 heap flags */ +#define DUK_HEAPHDR_FLAGS_USER_START 7 /* 25 user flags */ -#define DUK_HEAPHDR_HEAP_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_HEAP_START + (n)) -#define DUK_HEAPHDR_USER_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_USER_START + (n)) -#define DUK_HEAPHDR_HEAP_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_HEAP_START + (n))) -#define DUK_HEAPHDR_USER_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_USER_START + (n))) +#define DUK_HEAPHDR_HEAP_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_HEAP_START + (n)) +#define DUK_HEAPHDR_USER_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_USER_START + (n)) +#define DUK_HEAPHDR_HEAP_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_HEAP_START + (n))) +#define DUK_HEAPHDR_USER_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_USER_START + (n))) -#define DUK_HEAPHDR_FLAG_REACHABLE DUK_HEAPHDR_HEAP_FLAG(0) /* mark-and-sweep: reachable */ -#define DUK_HEAPHDR_FLAG_TEMPROOT DUK_HEAPHDR_HEAP_FLAG(1) /* mark-and-sweep: children not processed */ -#define DUK_HEAPHDR_FLAG_FINALIZABLE DUK_HEAPHDR_HEAP_FLAG(2) /* mark-and-sweep: finalizable (on current pass) */ -#define DUK_HEAPHDR_FLAG_FINALIZED DUK_HEAPHDR_HEAP_FLAG(3) /* mark-and-sweep: finalized (on previous pass) */ -#define DUK_HEAPHDR_FLAG_READONLY DUK_HEAPHDR_HEAP_FLAG(4) /* read-only object, in code section */ +#define DUK_HEAPHDR_FLAG_REACHABLE DUK_HEAPHDR_HEAP_FLAG(0) /* mark-and-sweep: reachable */ +#define DUK_HEAPHDR_FLAG_TEMPROOT DUK_HEAPHDR_HEAP_FLAG(1) /* mark-and-sweep: children not processed */ +#define DUK_HEAPHDR_FLAG_FINALIZABLE DUK_HEAPHDR_HEAP_FLAG(2) /* mark-and-sweep: finalizable (on current pass) */ +#define DUK_HEAPHDR_FLAG_FINALIZED DUK_HEAPHDR_HEAP_FLAG(3) /* mark-and-sweep: finalized (on previous pass) */ +#define DUK_HEAPHDR_FLAG_READONLY DUK_HEAPHDR_HEAP_FLAG(4) /* read-only object, in code section */ -#define DUK_HTYPE_MIN 0 -#define DUK_HTYPE_STRING 0 -#define DUK_HTYPE_OBJECT 1 -#define DUK_HTYPE_BUFFER 2 -#define DUK_HTYPE_MAX 2 +#define DUK_HTYPE_MIN 0 +#define DUK_HTYPE_STRING 0 +#define DUK_HTYPE_OBJECT 1 +#define DUK_HTYPE_BUFFER 2 +#define DUK_HTYPE_MAX 2 #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAPHDR_GET_NEXT(heap,h) \ - ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_next16)) -#define DUK_HEAPHDR_SET_NEXT(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_NEXT(heap, h) ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_next16)) +#define DUK_HEAPHDR_SET_NEXT(heap, h, val) \ + do { \ (h)->h_next16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) val); \ } while (0) #else -#define DUK_HEAPHDR_GET_NEXT(heap,h) ((h)->h_next) -#define DUK_HEAPHDR_SET_NEXT(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_NEXT(heap, h) ((h)->h_next) +#define DUK_HEAPHDR_SET_NEXT(heap, h, val) \ + do { \ (h)->h_next = (val); \ } while (0) #endif #if defined(DUK_USE_DOUBLE_LINKED_HEAP) #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAPHDR_GET_PREV(heap,h) \ - ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_prev16)) -#define DUK_HEAPHDR_SET_PREV(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_PREV(heap, h) ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_prev16)) +#define DUK_HEAPHDR_SET_PREV(heap, h, val) \ + do { \ (h)->h_prev16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (val)); \ } while (0) #else -#define DUK_HEAPHDR_GET_PREV(heap,h) ((h)->h_prev) -#define DUK_HEAPHDR_SET_PREV(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_PREV(heap, h) ((h)->h_prev) +#define DUK_HEAPHDR_SET_PREV(heap, h, val) \ + do { \ (h)->h_prev = (val); \ } while (0) #endif #endif #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAPHDR_GET_REFCOUNT(h) ((h)->h_refcount) -#define DUK_HEAPHDR_SET_REFCOUNT(h,val) do { \ +#define DUK_HEAPHDR_GET_REFCOUNT(h) ((h)->h_refcount) +#define DUK_HEAPHDR_SET_REFCOUNT(h, val) \ + do { \ (h)->h_refcount = (val); \ - DUK_ASSERT((h)->h_refcount == (val)); /* No truncation. */ \ + DUK_ASSERT((h)->h_refcount == (val)); /* No truncation. */ \ } while (0) -#define DUK_HEAPHDR_PREINC_REFCOUNT(h) (++(h)->h_refcount) /* result: updated refcount */ -#define DUK_HEAPHDR_PREDEC_REFCOUNT(h) (--(h)->h_refcount) /* result: updated refcount */ +#define DUK_HEAPHDR_PREINC_REFCOUNT(h) (++(h)->h_refcount) /* result: updated refcount */ +#define DUK_HEAPHDR_PREDEC_REFCOUNT(h) (--(h)->h_refcount) /* result: updated refcount */ #else /* refcount macros not defined without refcounting, caller must #if defined() now */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Note: type is treated as a field separate from flags, so some masking is * involved in the macros below. */ -#define DUK_HEAPHDR_GET_FLAGS_RAW(h) ((h)->h_flags) -#define DUK_HEAPHDR_SET_FLAGS_RAW(h,val) do { \ - (h)->h_flags = (val); } \ +#define DUK_HEAPHDR_GET_FLAGS_RAW(h) ((h)->h_flags) +#define DUK_HEAPHDR_SET_FLAGS_RAW(h, val) \ + do { \ + (h)->h_flags = (val); \ + } \ } -#define DUK_HEAPHDR_GET_FLAGS(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_FLAG_MASK) -#define DUK_HEAPHDR_SET_FLAGS(h,val) do { \ +#define DUK_HEAPHDR_GET_FLAGS(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_FLAG_MASK) +#define DUK_HEAPHDR_SET_FLAGS(h, val) \ + do { \ (h)->h_flags = ((h)->h_flags & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) | (val); \ } while (0) -#define DUK_HEAPHDR_GET_TYPE(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_TYPE_MASK) -#define DUK_HEAPHDR_SET_TYPE(h,val) do { \ +#define DUK_HEAPHDR_GET_TYPE(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_TYPE_MASK) +#define DUK_HEAPHDR_SET_TYPE(h, val) \ + do { \ (h)->h_flags = ((h)->h_flags & ~(DUK_HEAPHDR_FLAGS_TYPE_MASK)) | (val); \ } while (0) /* Comparison for type >= DUK_HTYPE_MIN skipped; because DUK_HTYPE_MIN is zero * and the comparison is unsigned, it's always true and generates warnings. */ -#define DUK_HEAPHDR_HTYPE_VALID(h) ( \ - DUK_HEAPHDR_GET_TYPE((h)) <= DUK_HTYPE_MAX \ - ) +#define DUK_HEAPHDR_HTYPE_VALID(h) (DUK_HEAPHDR_GET_TYPE((h)) <= DUK_HTYPE_MAX) -#define DUK_HEAPHDR_SET_TYPE_AND_FLAGS(h,tval,fval) do { \ - (h)->h_flags = ((tval) & DUK_HEAPHDR_FLAGS_TYPE_MASK) | \ - ((fval) & DUK_HEAPHDR_FLAGS_FLAG_MASK); \ +#define DUK_HEAPHDR_SET_TYPE_AND_FLAGS(h, tval, fval) \ + do { \ + (h)->h_flags = ((tval) &DUK_HEAPHDR_FLAGS_TYPE_MASK) | ((fval) &DUK_HEAPHDR_FLAGS_FLAG_MASK); \ } while (0) -#define DUK_HEAPHDR_SET_FLAG_BITS(h,bits) do { \ +#define DUK_HEAPHDR_SET_FLAG_BITS(h, bits) \ + do { \ DUK_ASSERT(((bits) & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) == 0); \ (h)->h_flags |= (bits); \ } while (0) -#define DUK_HEAPHDR_CLEAR_FLAG_BITS(h,bits) do { \ +#define DUK_HEAPHDR_CLEAR_FLAG_BITS(h, bits) \ + do { \ DUK_ASSERT(((bits) & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) == 0); \ (h)->h_flags &= ~((bits)); \ } while (0) -#define DUK_HEAPHDR_CHECK_FLAG_BITS(h,bits) (((h)->h_flags & (bits)) != 0) +#define DUK_HEAPHDR_CHECK_FLAG_BITS(h, bits) (((h)->h_flags & (bits)) != 0) -#define DUK_HEAPHDR_SET_REACHABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) -#define DUK_HEAPHDR_CLEAR_REACHABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) -#define DUK_HEAPHDR_HAS_REACHABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) +#define DUK_HEAPHDR_SET_REACHABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) +#define DUK_HEAPHDR_CLEAR_REACHABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) +#define DUK_HEAPHDR_HAS_REACHABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) -#define DUK_HEAPHDR_SET_TEMPROOT(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) -#define DUK_HEAPHDR_CLEAR_TEMPROOT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) -#define DUK_HEAPHDR_HAS_TEMPROOT(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) +#define DUK_HEAPHDR_SET_TEMPROOT(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) +#define DUK_HEAPHDR_CLEAR_TEMPROOT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) +#define DUK_HEAPHDR_HAS_TEMPROOT(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) -#define DUK_HEAPHDR_SET_FINALIZABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) -#define DUK_HEAPHDR_CLEAR_FINALIZABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) -#define DUK_HEAPHDR_HAS_FINALIZABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) +#define DUK_HEAPHDR_SET_FINALIZABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) +#define DUK_HEAPHDR_CLEAR_FINALIZABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) +#define DUK_HEAPHDR_HAS_FINALIZABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) -#define DUK_HEAPHDR_SET_FINALIZED(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) -#define DUK_HEAPHDR_CLEAR_FINALIZED(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) -#define DUK_HEAPHDR_HAS_FINALIZED(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) +#define DUK_HEAPHDR_SET_FINALIZED(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) +#define DUK_HEAPHDR_CLEAR_FINALIZED(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) +#define DUK_HEAPHDR_HAS_FINALIZED(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) -#define DUK_HEAPHDR_SET_READONLY(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) -#define DUK_HEAPHDR_CLEAR_READONLY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) -#define DUK_HEAPHDR_HAS_READONLY(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_SET_READONLY(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_CLEAR_READONLY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_HAS_READONLY(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) /* get or set a range of flags; m=first bit number, n=number of bits */ -#define DUK_HEAPHDR_GET_FLAG_RANGE(h,m,n) (((h)->h_flags >> (m)) & ((1UL << (n)) - 1UL)) +#define DUK_HEAPHDR_GET_FLAG_RANGE(h, m, n) (((h)->h_flags >> (m)) & ((1UL << (n)) - 1UL)) -#define DUK_HEAPHDR_SET_FLAG_RANGE(h,m,n,v) do { \ - (h)->h_flags = \ - ((h)->h_flags & (~(((1UL << (n)) - 1UL) << (m)))) \ - | ((v) << (m)); \ +#define DUK_HEAPHDR_SET_FLAG_RANGE(h, m, n, v) \ + do { \ + (h)->h_flags = ((h)->h_flags & (~(((1UL << (n)) - 1UL) << (m)))) | ((v) << (m)); \ } while (0) /* init pointer fields to null */ #if defined(DUK_USE_DOUBLE_LINKED_HEAP) -#define DUK_HEAPHDR_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_INIT_NULLS(h) \ + do { \ DUK_HEAPHDR_SET_NEXT((h), (void *) NULL); \ DUK_HEAPHDR_SET_PREV((h), (void *) NULL); \ } while (0) #else -#define DUK_HEAPHDR_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_INIT_NULLS(h) \ + do { \ DUK_HEAPHDR_SET_NEXT((h), (void *) NULL); \ } while (0) #endif -#define DUK_HEAPHDR_STRING_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_STRING_INIT_NULLS(h) \ + do { \ (h)->h_next = NULL; \ } while (0) @@ -287,11 +296,21 @@ DUK_INTERNAL_DECL void duk_heaphdr_assert_valid_subclassed(duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_assert_links(duk_heap *heap, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_assert_valid(duk_heaphdr *h); -#define DUK_HEAPHDR_ASSERT_LINKS(heap,h) do { duk_heaphdr_assert_links((heap), (h)); } while (0) -#define DUK_HEAPHDR_ASSERT_VALID(h) do { duk_heaphdr_assert_valid((h)); } while (0) +#define DUK_HEAPHDR_ASSERT_LINKS(heap, h) \ + do { \ + duk_heaphdr_assert_links((heap), (h)); \ + } while (0) +#define DUK_HEAPHDR_ASSERT_VALID(h) \ + do { \ + duk_heaphdr_assert_valid((h)); \ + } while (0) #else -#define DUK_HEAPHDR_ASSERT_LINKS(heap,h) do {} while (0) -#define DUK_HEAPHDR_ASSERT_VALID(h) do {} while (0) +#define DUK_HEAPHDR_ASSERT_LINKS(heap, h) \ + do { \ + } while (0) +#define DUK_HEAPHDR_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#endif /* DUK_HEAPHDR_H_INCLUDED */ +#endif /* DUK_HEAPHDR_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_heaphdr_assert.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_heaphdr_assert.c
Changed
@@ -75,4 +75,4 @@ } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_henv.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_henv.h
Changed
@@ -8,11 +8,21 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hdecenv_assert_valid(duk_hdecenv *h); DUK_INTERNAL_DECL void duk_hobjenv_assert_valid(duk_hobjenv *h); -#define DUK_HDECENV_ASSERT_VALID(h) do { duk_hdecenv_assert_valid((h)); } while (0) -#define DUK_HOBJENV_ASSERT_VALID(h) do { duk_hobjenv_assert_valid((h)); } while (0) +#define DUK_HDECENV_ASSERT_VALID(h) \ + do { \ + duk_hdecenv_assert_valid((h)); \ + } while (0) +#define DUK_HOBJENV_ASSERT_VALID(h) \ + do { \ + duk_hobjenv_assert_valid((h)); \ + } while (0) #else -#define DUK_HDECENV_ASSERT_VALID(h) do {} while (0) -#define DUK_HOBJENV_ASSERT_VALID(h) do {} while (0) +#define DUK_HDECENV_ASSERT_VALID(h) \ + do { \ + } while (0) +#define DUK_HOBJENV_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hdecenv { @@ -42,4 +52,4 @@ duk_bool_t has_this; }; -#endif /* DUK_HENV_H_INCLUDED */ +#endif /* DUK_HENV_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hnatfunc.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hnatfunc.h
Changed
@@ -7,13 +7,18 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hnatfunc_assert_valid(duk_hnatfunc *h); -#define DUK_HNATFUNC_ASSERT_VALID(h) do { duk_hnatfunc_assert_valid((h)); } while (0) +#define DUK_HNATFUNC_ASSERT_VALID(h) \ + do { \ + duk_hnatfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HNATFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HNATFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#define DUK_HNATFUNC_NARGS_VARARGS ((duk_int16_t) -1) -#define DUK_HNATFUNC_NARGS_MAX ((duk_int16_t) 0x7fff) +#define DUK_HNATFUNC_NARGS_VARARGS ((duk_int16_t) -1) +#define DUK_HNATFUNC_NARGS_MAX ((duk_int16_t) 0x7fff) struct duk_hnatfunc { /* shared object part */ @@ -36,4 +41,4 @@ */ }; -#endif /* DUK_HNATFUNC_H_INCLUDED */ +#endif /* DUK_HNATFUNC_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hobject.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hobject.h
Changed
@@ -39,36 +39,40 @@ /* XXX: some flags are object subtype specific (e.g. common to all function * subtypes, duk_harray, etc) and could be reused for different subtypes. */ -#define DUK_HOBJECT_FLAG_EXTENSIBLE DUK_HEAPHDR_USER_FLAG(0) /* object is extensible */ -#define DUK_HOBJECT_FLAG_CONSTRUCTABLE DUK_HEAPHDR_USER_FLAG(1) /* object is constructable */ -#define DUK_HOBJECT_FLAG_CALLABLE DUK_HEAPHDR_USER_FLAG(2) /* object is callable */ -#define DUK_HOBJECT_FLAG_BOUNDFUNC DUK_HEAPHDR_USER_FLAG(3) /* object established using Function.prototype.bind() */ -#define DUK_HOBJECT_FLAG_COMPFUNC DUK_HEAPHDR_USER_FLAG(4) /* object is a compiled function (duk_hcompfunc) */ -#define DUK_HOBJECT_FLAG_NATFUNC DUK_HEAPHDR_USER_FLAG(5) /* object is a native function (duk_hnatfunc) */ -#define DUK_HOBJECT_FLAG_BUFOBJ DUK_HEAPHDR_USER_FLAG(6) /* object is a buffer object (duk_hbufobj) (always exotic) */ -#define DUK_HOBJECT_FLAG_FASTREFS DUK_HEAPHDR_USER_FLAG(7) /* object has no fields needing DECREF/marking beyond base duk_hobject header */ -#define DUK_HOBJECT_FLAG_ARRAY_PART DUK_HEAPHDR_USER_FLAG(8) /* object has an array part (a_size may still be 0) */ -#define DUK_HOBJECT_FLAG_STRICT DUK_HEAPHDR_USER_FLAG(9) /* function: function object is strict */ -#define DUK_HOBJECT_FLAG_NOTAIL DUK_HEAPHDR_USER_FLAG(10) /* function: function must not be tail called */ -#define DUK_HOBJECT_FLAG_NEWENV DUK_HEAPHDR_USER_FLAG(11) /* function: create new environment when called (see duk_hcompfunc) */ -#define DUK_HOBJECT_FLAG_NAMEBINDING DUK_HEAPHDR_USER_FLAG(12) /* function: create binding for func name (function templates only, used for named function expressions) */ -#define DUK_HOBJECT_FLAG_CREATEARGS DUK_HEAPHDR_USER_FLAG(13) /* function: create an arguments object on function call */ -#define DUK_HOBJECT_FLAG_HAVE_FINALIZER DUK_HEAPHDR_USER_FLAG(14) /* object has a callable (own) finalizer property */ -#define DUK_HOBJECT_FLAG_EXOTIC_ARRAY DUK_HEAPHDR_USER_FLAG(15) /* 'Array' object, array length and index exotic behavior */ -#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ DUK_HEAPHDR_USER_FLAG(16) /* 'String' object, array index exotic behavior */ -#define DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS DUK_HEAPHDR_USER_FLAG(17) /* 'Arguments' object and has arguments exotic behavior (non-strict callee) */ -#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(18) /* 'Proxy' object */ -#define DUK_HOBJECT_FLAG_SPECIAL_CALL DUK_HEAPHDR_USER_FLAG(19) /* special casing in call behavior, for .call(), .apply(), etc. */ - -#define DUK_HOBJECT_FLAG_CLASS_BASE DUK_HEAPHDR_USER_FLAG_NUMBER(20) -#define DUK_HOBJECT_FLAG_CLASS_BITS 5 - -#define DUK_HOBJECT_GET_CLASS_NUMBER(h) \ +#define DUK_HOBJECT_FLAG_EXTENSIBLE DUK_HEAPHDR_USER_FLAG(0) /* object is extensible */ +#define DUK_HOBJECT_FLAG_CONSTRUCTABLE DUK_HEAPHDR_USER_FLAG(1) /* object is constructable */ +#define DUK_HOBJECT_FLAG_CALLABLE DUK_HEAPHDR_USER_FLAG(2) /* object is callable */ +#define DUK_HOBJECT_FLAG_BOUNDFUNC DUK_HEAPHDR_USER_FLAG(3) /* object established using Function.prototype.bind() */ +#define DUK_HOBJECT_FLAG_COMPFUNC DUK_HEAPHDR_USER_FLAG(4) /* object is a compiled function (duk_hcompfunc) */ +#define DUK_HOBJECT_FLAG_NATFUNC DUK_HEAPHDR_USER_FLAG(5) /* object is a native function (duk_hnatfunc) */ +#define DUK_HOBJECT_FLAG_BUFOBJ DUK_HEAPHDR_USER_FLAG(6) /* object is a buffer object (duk_hbufobj) (always exotic) */ +#define DUK_HOBJECT_FLAG_FASTREFS \ + DUK_HEAPHDR_USER_FLAG(7) /* object has no fields needing DECREF/marking beyond base duk_hobject header */ +#define DUK_HOBJECT_FLAG_ARRAY_PART DUK_HEAPHDR_USER_FLAG(8) /* object has an array part (a_size may still be 0) */ +#define DUK_HOBJECT_FLAG_STRICT DUK_HEAPHDR_USER_FLAG(9) /* function: function object is strict */ +#define DUK_HOBJECT_FLAG_NOTAIL DUK_HEAPHDR_USER_FLAG(10) /* function: function must not be tail called */ +#define DUK_HOBJECT_FLAG_NEWENV DUK_HEAPHDR_USER_FLAG(11) /* function: create new environment when called (see duk_hcompfunc) */ +#define DUK_HOBJECT_FLAG_NAMEBINDING \ + DUK_HEAPHDR_USER_FLAG( \ + 12) /* function: create binding for func name (function templates only, used for named function expressions) */ +#define DUK_HOBJECT_FLAG_CREATEARGS DUK_HEAPHDR_USER_FLAG(13) /* function: create an arguments object on function call */ +#define DUK_HOBJECT_FLAG_HAVE_FINALIZER DUK_HEAPHDR_USER_FLAG(14) /* object has a callable (own) finalizer property */ +#define DUK_HOBJECT_FLAG_EXOTIC_ARRAY DUK_HEAPHDR_USER_FLAG(15) /* 'Array' object, array length and index exotic behavior */ +#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ DUK_HEAPHDR_USER_FLAG(16) /* 'String' object, array index exotic behavior */ +#define DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS \ + DUK_HEAPHDR_USER_FLAG(17) /* 'Arguments' object and has arguments exotic behavior (non-strict callee) */ +#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(18) /* 'Proxy' object */ +#define DUK_HOBJECT_FLAG_SPECIAL_CALL DUK_HEAPHDR_USER_FLAG(19) /* special casing in call behavior, for .call(), .apply(), etc. */ + +#define DUK_HOBJECT_FLAG_CLASS_BASE DUK_HEAPHDR_USER_FLAG_NUMBER(20) +#define DUK_HOBJECT_FLAG_CLASS_BITS 5 + +#define DUK_HOBJECT_GET_CLASS_NUMBER(h) \ DUK_HEAPHDR_GET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS) -#define DUK_HOBJECT_SET_CLASS_NUMBER(h,v) \ +#define DUK_HOBJECT_SET_CLASS_NUMBER(h, v) \ DUK_HEAPHDR_SET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS, (v)) -#define DUK_HOBJECT_GET_CLASS_MASK(h) \ +#define DUK_HOBJECT_GET_CLASS_MASK(h) \ (1UL << DUK_HEAPHDR_GET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS)) /* Macro for creating flag initializer from a class number. @@ -76,256 +80,239 @@ * a signed integer to an unsigned one; the largest class values * have the highest bit (bit 31) set which causes this. */ -#define DUK_HOBJECT_CLASS_AS_FLAGS(v) (((duk_uint_t) (v)) << DUK_HOBJECT_FLAG_CLASS_BASE) +#define DUK_HOBJECT_CLASS_AS_FLAGS(v) (((duk_uint_t) (v)) << DUK_HOBJECT_FLAG_CLASS_BASE) /* E5 Section 8.6.2 + custom classes */ -#define DUK_HOBJECT_CLASS_NONE 0 -#define DUK_HOBJECT_CLASS_OBJECT 1 -#define DUK_HOBJECT_CLASS_ARRAY 2 -#define DUK_HOBJECT_CLASS_FUNCTION 3 -#define DUK_HOBJECT_CLASS_ARGUMENTS 4 -#define DUK_HOBJECT_CLASS_BOOLEAN 5 -#define DUK_HOBJECT_CLASS_DATE 6 -#define DUK_HOBJECT_CLASS_ERROR 7 -#define DUK_HOBJECT_CLASS_JSON 8 -#define DUK_HOBJECT_CLASS_MATH 9 -#define DUK_HOBJECT_CLASS_NUMBER 10 -#define DUK_HOBJECT_CLASS_REGEXP 11 -#define DUK_HOBJECT_CLASS_STRING 12 -#define DUK_HOBJECT_CLASS_GLOBAL 13 -#define DUK_HOBJECT_CLASS_SYMBOL 14 -#define DUK_HOBJECT_CLASS_OBJENV 15 /* custom */ -#define DUK_HOBJECT_CLASS_DECENV 16 /* custom */ -#define DUK_HOBJECT_CLASS_POINTER 17 /* custom */ -#define DUK_HOBJECT_CLASS_THREAD 18 /* custom; implies DUK_HOBJECT_IS_THREAD */ -#define DUK_HOBJECT_CLASS_BUFOBJ_MIN 19 -#define DUK_HOBJECT_CLASS_ARRAYBUFFER 19 /* implies DUK_HOBJECT_IS_BUFOBJ */ -#define DUK_HOBJECT_CLASS_DATAVIEW 20 -#define DUK_HOBJECT_CLASS_INT8ARRAY 21 -#define DUK_HOBJECT_CLASS_UINT8ARRAY 22 -#define DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY 23 -#define DUK_HOBJECT_CLASS_INT16ARRAY 24 -#define DUK_HOBJECT_CLASS_UINT16ARRAY 25 -#define DUK_HOBJECT_CLASS_INT32ARRAY 26 -#define DUK_HOBJECT_CLASS_UINT32ARRAY 27 -#define DUK_HOBJECT_CLASS_FLOAT32ARRAY 28 -#define DUK_HOBJECT_CLASS_FLOAT64ARRAY 29 -#define DUK_HOBJECT_CLASS_BUFOBJ_MAX 29 -#define DUK_HOBJECT_CLASS_MAX 29 +#define DUK_HOBJECT_CLASS_NONE 0 +#define DUK_HOBJECT_CLASS_OBJECT 1 +#define DUK_HOBJECT_CLASS_ARRAY 2 +#define DUK_HOBJECT_CLASS_FUNCTION 3 +#define DUK_HOBJECT_CLASS_ARGUMENTS 4 +#define DUK_HOBJECT_CLASS_BOOLEAN 5 +#define DUK_HOBJECT_CLASS_DATE 6 +#define DUK_HOBJECT_CLASS_ERROR 7 +#define DUK_HOBJECT_CLASS_JSON 8 +#define DUK_HOBJECT_CLASS_MATH 9 +#define DUK_HOBJECT_CLASS_NUMBER 10 +#define DUK_HOBJECT_CLASS_REGEXP 11 +#define DUK_HOBJECT_CLASS_STRING 12 +#define DUK_HOBJECT_CLASS_GLOBAL 13 +#define DUK_HOBJECT_CLASS_SYMBOL 14 +#define DUK_HOBJECT_CLASS_OBJENV 15 /* custom */ +#define DUK_HOBJECT_CLASS_DECENV 16 /* custom */ +#define DUK_HOBJECT_CLASS_POINTER 17 /* custom */ +#define DUK_HOBJECT_CLASS_THREAD 18 /* custom; implies DUK_HOBJECT_IS_THREAD */ +#define DUK_HOBJECT_CLASS_BUFOBJ_MIN 19 +#define DUK_HOBJECT_CLASS_ARRAYBUFFER 19 /* implies DUK_HOBJECT_IS_BUFOBJ */ +#define DUK_HOBJECT_CLASS_DATAVIEW 20 +#define DUK_HOBJECT_CLASS_INT8ARRAY 21 +#define DUK_HOBJECT_CLASS_UINT8ARRAY 22 +#define DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY 23 +#define DUK_HOBJECT_CLASS_INT16ARRAY 24 +#define DUK_HOBJECT_CLASS_UINT16ARRAY 25 +#define DUK_HOBJECT_CLASS_INT32ARRAY 26 +#define DUK_HOBJECT_CLASS_UINT32ARRAY 27 +#define DUK_HOBJECT_CLASS_FLOAT32ARRAY 28 +#define DUK_HOBJECT_CLASS_FLOAT64ARRAY 29 +#define DUK_HOBJECT_CLASS_BUFOBJ_MAX 29 +#define DUK_HOBJECT_CLASS_MAX 29 /* Class masks. */ -#define DUK_HOBJECT_CMASK_ALL ((1UL << (DUK_HOBJECT_CLASS_MAX + 1)) - 1UL) -#define DUK_HOBJECT_CMASK_NONE (1UL << DUK_HOBJECT_CLASS_NONE) -#define DUK_HOBJECT_CMASK_ARGUMENTS (1UL << DUK_HOBJECT_CLASS_ARGUMENTS) -#define DUK_HOBJECT_CMASK_ARRAY (1UL << DUK_HOBJECT_CLASS_ARRAY) -#define DUK_HOBJECT_CMASK_BOOLEAN (1UL << DUK_HOBJECT_CLASS_BOOLEAN) -#define DUK_HOBJECT_CMASK_DATE (1UL << DUK_HOBJECT_CLASS_DATE) -#define DUK_HOBJECT_CMASK_ERROR (1UL << DUK_HOBJECT_CLASS_ERROR) -#define DUK_HOBJECT_CMASK_FUNCTION (1UL << DUK_HOBJECT_CLASS_FUNCTION) -#define DUK_HOBJECT_CMASK_JSON (1UL << DUK_HOBJECT_CLASS_JSON) -#define DUK_HOBJECT_CMASK_MATH (1UL << DUK_HOBJECT_CLASS_MATH) -#define DUK_HOBJECT_CMASK_NUMBER (1UL << DUK_HOBJECT_CLASS_NUMBER) -#define DUK_HOBJECT_CMASK_OBJECT (1UL << DUK_HOBJECT_CLASS_OBJECT) -#define DUK_HOBJECT_CMASK_REGEXP (1UL << DUK_HOBJECT_CLASS_REGEXP) -#define DUK_HOBJECT_CMASK_STRING (1UL << DUK_HOBJECT_CLASS_STRING) -#define DUK_HOBJECT_CMASK_GLOBAL (1UL << DUK_HOBJECT_CLASS_GLOBAL) -#define DUK_HOBJECT_CMASK_SYMBOL (1UL << DUK_HOBJECT_CLASS_SYMBOL) -#define DUK_HOBJECT_CMASK_OBJENV (1UL << DUK_HOBJECT_CLASS_OBJENV) -#define DUK_HOBJECT_CMASK_DECENV (1UL << DUK_HOBJECT_CLASS_DECENV) -#define DUK_HOBJECT_CMASK_POINTER (1UL << DUK_HOBJECT_CLASS_POINTER) -#define DUK_HOBJECT_CMASK_ARRAYBUFFER (1UL << DUK_HOBJECT_CLASS_ARRAYBUFFER) -#define DUK_HOBJECT_CMASK_DATAVIEW (1UL << DUK_HOBJECT_CLASS_DATAVIEW) -#define DUK_HOBJECT_CMASK_INT8ARRAY (1UL << DUK_HOBJECT_CLASS_INT8ARRAY) -#define DUK_HOBJECT_CMASK_UINT8ARRAY (1UL << DUK_HOBJECT_CLASS_UINT8ARRAY) -#define DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY (1UL << DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY) -#define DUK_HOBJECT_CMASK_INT16ARRAY (1UL << DUK_HOBJECT_CLASS_INT16ARRAY) -#define DUK_HOBJECT_CMASK_UINT16ARRAY (1UL << DUK_HOBJECT_CLASS_UINT16ARRAY) -#define DUK_HOBJECT_CMASK_INT32ARRAY (1UL << DUK_HOBJECT_CLASS_INT32ARRAY) -#define DUK_HOBJECT_CMASK_UINT32ARRAY (1UL << DUK_HOBJECT_CLASS_UINT32ARRAY) -#define DUK_HOBJECT_CMASK_FLOAT32ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT32ARRAY) -#define DUK_HOBJECT_CMASK_FLOAT64ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT64ARRAY) +#define DUK_HOBJECT_CMASK_ALL ((1UL << (DUK_HOBJECT_CLASS_MAX + 1)) - 1UL) +#define DUK_HOBJECT_CMASK_NONE (1UL << DUK_HOBJECT_CLASS_NONE) +#define DUK_HOBJECT_CMASK_ARGUMENTS (1UL << DUK_HOBJECT_CLASS_ARGUMENTS) +#define DUK_HOBJECT_CMASK_ARRAY (1UL << DUK_HOBJECT_CLASS_ARRAY) +#define DUK_HOBJECT_CMASK_BOOLEAN (1UL << DUK_HOBJECT_CLASS_BOOLEAN) +#define DUK_HOBJECT_CMASK_DATE (1UL << DUK_HOBJECT_CLASS_DATE) +#define DUK_HOBJECT_CMASK_ERROR (1UL << DUK_HOBJECT_CLASS_ERROR) +#define DUK_HOBJECT_CMASK_FUNCTION (1UL << DUK_HOBJECT_CLASS_FUNCTION) +#define DUK_HOBJECT_CMASK_JSON (1UL << DUK_HOBJECT_CLASS_JSON) +#define DUK_HOBJECT_CMASK_MATH (1UL << DUK_HOBJECT_CLASS_MATH) +#define DUK_HOBJECT_CMASK_NUMBER (1UL << DUK_HOBJECT_CLASS_NUMBER) +#define DUK_HOBJECT_CMASK_OBJECT (1UL << DUK_HOBJECT_CLASS_OBJECT) +#define DUK_HOBJECT_CMASK_REGEXP (1UL << DUK_HOBJECT_CLASS_REGEXP) +#define DUK_HOBJECT_CMASK_STRING (1UL << DUK_HOBJECT_CLASS_STRING) +#define DUK_HOBJECT_CMASK_GLOBAL (1UL << DUK_HOBJECT_CLASS_GLOBAL) +#define DUK_HOBJECT_CMASK_SYMBOL (1UL << DUK_HOBJECT_CLASS_SYMBOL) +#define DUK_HOBJECT_CMASK_OBJENV (1UL << DUK_HOBJECT_CLASS_OBJENV) +#define DUK_HOBJECT_CMASK_DECENV (1UL << DUK_HOBJECT_CLASS_DECENV) +#define DUK_HOBJECT_CMASK_POINTER (1UL << DUK_HOBJECT_CLASS_POINTER) +#define DUK_HOBJECT_CMASK_ARRAYBUFFER (1UL << DUK_HOBJECT_CLASS_ARRAYBUFFER) +#define DUK_HOBJECT_CMASK_DATAVIEW (1UL << DUK_HOBJECT_CLASS_DATAVIEW) +#define DUK_HOBJECT_CMASK_INT8ARRAY (1UL << DUK_HOBJECT_CLASS_INT8ARRAY) +#define DUK_HOBJECT_CMASK_UINT8ARRAY (1UL << DUK_HOBJECT_CLASS_UINT8ARRAY) +#define DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY (1UL << DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY) +#define DUK_HOBJECT_CMASK_INT16ARRAY (1UL << DUK_HOBJECT_CLASS_INT16ARRAY) +#define DUK_HOBJECT_CMASK_UINT16ARRAY (1UL << DUK_HOBJECT_CLASS_UINT16ARRAY) +#define DUK_HOBJECT_CMASK_INT32ARRAY (1UL << DUK_HOBJECT_CLASS_INT32ARRAY) +#define DUK_HOBJECT_CMASK_UINT32ARRAY (1UL << DUK_HOBJECT_CLASS_UINT32ARRAY) +#define DUK_HOBJECT_CMASK_FLOAT32ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT32ARRAY) +#define DUK_HOBJECT_CMASK_FLOAT64ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT64ARRAY) #define DUK_HOBJECT_CMASK_ALL_BUFOBJS \ - (DUK_HOBJECT_CMASK_ARRAYBUFFER | \ - DUK_HOBJECT_CMASK_DATAVIEW | \ - DUK_HOBJECT_CMASK_INT8ARRAY | \ - DUK_HOBJECT_CMASK_UINT8ARRAY | \ - DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY | \ - DUK_HOBJECT_CMASK_INT16ARRAY | \ - DUK_HOBJECT_CMASK_UINT16ARRAY | \ - DUK_HOBJECT_CMASK_INT32ARRAY | \ - DUK_HOBJECT_CMASK_UINT32ARRAY | \ - DUK_HOBJECT_CMASK_FLOAT32ARRAY | \ + (DUK_HOBJECT_CMASK_ARRAYBUFFER | DUK_HOBJECT_CMASK_DATAVIEW | DUK_HOBJECT_CMASK_INT8ARRAY | DUK_HOBJECT_CMASK_UINT8ARRAY | \ + DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY | DUK_HOBJECT_CMASK_INT16ARRAY | DUK_HOBJECT_CMASK_UINT16ARRAY | \ + DUK_HOBJECT_CMASK_INT32ARRAY | DUK_HOBJECT_CMASK_UINT32ARRAY | DUK_HOBJECT_CMASK_FLOAT32ARRAY | \ DUK_HOBJECT_CMASK_FLOAT64ARRAY) -#define DUK_HOBJECT_IS_OBJENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_OBJENV) -#define DUK_HOBJECT_IS_DECENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_DECENV) -#define DUK_HOBJECT_IS_ENV(h) (DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_DECENV((h))) -#define DUK_HOBJECT_IS_ARRAY(h) DUK_HOBJECT_HAS_EXOTIC_ARRAY((h)) /* Rely on class Array <=> exotic Array */ -#define DUK_HOBJECT_IS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_IS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_IS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_OBJENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_OBJENV) +#define DUK_HOBJECT_IS_DECENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_DECENV) +#define DUK_HOBJECT_IS_ENV(h) (DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_DECENV((h))) +#define DUK_HOBJECT_IS_ARRAY(h) DUK_HOBJECT_HAS_EXOTIC_ARRAY((h)) /* Rely on class Array <=> exotic Array */ +#define DUK_HOBJECT_IS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_IS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_IS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_IS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_IS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #else -#define DUK_HOBJECT_IS_BUFOBJ(h) 0 +#define DUK_HOBJECT_IS_BUFOBJ(h) 0 #endif -#define DUK_HOBJECT_IS_THREAD(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_THREAD) +#define DUK_HOBJECT_IS_THREAD(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_THREAD) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_IS_PROXY(h) DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ((h)) +#define DUK_HOBJECT_IS_PROXY(h) DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ((h)) #else -#define DUK_HOBJECT_IS_PROXY(h) 0 +#define DUK_HOBJECT_IS_PROXY(h) 0 #endif -#define DUK_HOBJECT_IS_NONBOUND_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_COMPFUNC | \ - DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_NONBOUND_FUNCTION(h) \ + DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC | DUK_HOBJECT_FLAG_NATFUNC) -#define DUK_HOBJECT_IS_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_BOUNDFUNC | \ - DUK_HOBJECT_FLAG_COMPFUNC | \ - DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_FUNCTION(h) \ + DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC | DUK_HOBJECT_FLAG_COMPFUNC | DUK_HOBJECT_FLAG_NATFUNC) -#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HOBJECT_HAS_CALLABLE((h)) +#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HOBJECT_HAS_CALLABLE((h)) /* Object has any exotic behavior(s). */ -#define DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS | \ - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ - DUK_HOBJECT_FLAG_BUFOBJ | \ - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) -#define DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS) +#define DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS \ + (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ + DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS) /* Object has any virtual properties (not counting Proxy behavior). */ -#define DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ - DUK_HOBJECT_FLAG_BUFOBJ) -#define DUK_HOBJECT_HAS_VIRTUAL_PROPERTIES(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS) - -#define DUK_HOBJECT_HAS_EXTENSIBLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_HAS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_HAS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_HAS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_HAS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS \ + (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_HAS_VIRTUAL_PROPERTIES(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS) + +#define DUK_HOBJECT_HAS_EXTENSIBLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_HAS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_HAS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_HAS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_HAS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_HAS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_HAS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #else -#define DUK_HOBJECT_HAS_BUFOBJ(h) 0 +#define DUK_HOBJECT_HAS_BUFOBJ(h) 0 #endif -#define DUK_HOBJECT_HAS_FASTREFS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_HAS_ARRAY_PART(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_HAS_STRICT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_HAS_NOTAIL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_HAS_NEWENV(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_HAS_NAMEBINDING(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_HAS_CREATEARGS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_HAS_HAVE_FINALIZER(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_HAS_EXOTIC_ARRAY(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_HAS_FASTREFS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_HAS_ARRAY_PART(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_HAS_STRICT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_HAS_NOTAIL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_HAS_NEWENV(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_HAS_NAMEBINDING(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_HAS_CREATEARGS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_HAS_HAVE_FINALIZER(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_HAS_EXOTIC_ARRAY(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #else -#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) 0 +#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) 0 #endif -#define DUK_HOBJECT_HAS_SPECIAL_CALL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) - -#define DUK_HOBJECT_SET_EXTENSIBLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_SET_CONSTRUCTABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_SET_CALLABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_SET_BOUNDFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_SET_COMPFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_SET_NATFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_HAS_SPECIAL_CALL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) + +#define DUK_HOBJECT_SET_EXTENSIBLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_SET_CONSTRUCTABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_SET_CALLABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_SET_BOUNDFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_SET_COMPFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_SET_NATFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_SET_BUFOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_SET_BUFOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #endif -#define DUK_HOBJECT_SET_FASTREFS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_SET_ARRAY_PART(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_SET_STRICT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_SET_NOTAIL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_SET_NEWENV(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_SET_NAMEBINDING(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_SET_CREATEARGS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_SET_HAVE_FINALIZER(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_SET_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_SET_FASTREFS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_SET_ARRAY_PART(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_SET_STRICT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_SET_NOTAIL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_SET_NEWENV(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_SET_NAMEBINDING(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_SET_CREATEARGS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_SET_HAVE_FINALIZER(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_SET_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_SET_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_SET_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #endif -#define DUK_HOBJECT_SET_SPECIAL_CALL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) - -#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_CLEAR_CALLABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_CLEAR_BOUNDFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_CLEAR_COMPFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_CLEAR_NATFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_SET_SPECIAL_CALL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) + +#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_CLEAR_CALLABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_CLEAR_BOUNDFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_CLEAR_COMPFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_CLEAR_NATFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_CLEAR_BUFOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_CLEAR_BUFOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #endif -#define DUK_HOBJECT_CLEAR_FASTREFS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_CLEAR_ARRAY_PART(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_CLEAR_STRICT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_CLEAR_NOTAIL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_CLEAR_NEWENV(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_CLEAR_NAMEBINDING(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_CLEAR_CREATEARGS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_CLEAR_EXOTIC_ARRAY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_CLEAR_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_CLEAR_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_CLEAR_FASTREFS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_CLEAR_ARRAY_PART(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_CLEAR_STRICT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_CLEAR_NOTAIL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_CLEAR_NEWENV(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_CLEAR_NAMEBINDING(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_CLEAR_CREATEARGS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_CLEAR_EXOTIC_ARRAY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_CLEAR_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_CLEAR_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_CLEAR_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_CLEAR_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #endif -#define DUK_HOBJECT_CLEAR_SPECIAL_CALL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) +#define DUK_HOBJECT_CLEAR_SPECIAL_CALL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) /* Object can/cannot use FASTREFS, i.e. has no strong reference fields beyond * duk_hobject base header. This is used just for asserts so doesn't need to * be optimized. */ #define DUK_HOBJECT_PROHIBITS_FASTREFS(h) \ - (DUK_HOBJECT_IS_COMPFUNC((h)) || DUK_HOBJECT_IS_DECENV((h)) || DUK_HOBJECT_IS_OBJENV((h)) || \ - DUK_HOBJECT_IS_BUFOBJ((h)) || DUK_HOBJECT_IS_THREAD((h)) || DUK_HOBJECT_IS_PROXY((h)) || \ - DUK_HOBJECT_IS_BOUNDFUNC((h))) + (DUK_HOBJECT_IS_COMPFUNC((h)) || DUK_HOBJECT_IS_DECENV((h)) || DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_BUFOBJ((h)) || \ + DUK_HOBJECT_IS_THREAD((h)) || DUK_HOBJECT_IS_PROXY((h)) || DUK_HOBJECT_IS_BOUNDFUNC((h))) #define DUK_HOBJECT_ALLOWS_FASTREFS(h) (!DUK_HOBJECT_PROHIBITS_FASTREFS((h))) /* Flags used for property attributes in duk_propdesc and packed flags. * Must fit into 8 bits. */ -#define DUK_PROPDESC_FLAG_WRITABLE (1U << 0) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_ENUMERABLE (1U << 1) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_CONFIGURABLE (1U << 2) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_ACCESSOR (1U << 3) /* accessor */ -#define DUK_PROPDESC_FLAG_VIRTUAL (1U << 4) /* property is virtual: used in duk_propdesc, never stored - * (used by e.g. buffer virtual properties) - */ -#define DUK_PROPDESC_FLAGS_MASK (DUK_PROPDESC_FLAG_WRITABLE | \ - DUK_PROPDESC_FLAG_ENUMERABLE | \ - DUK_PROPDESC_FLAG_CONFIGURABLE | \ - DUK_PROPDESC_FLAG_ACCESSOR) +#define DUK_PROPDESC_FLAG_WRITABLE (1U << 0) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_ENUMERABLE (1U << 1) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_CONFIGURABLE (1U << 2) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_ACCESSOR (1U << 3) /* accessor */ +#define DUK_PROPDESC_FLAG_VIRTUAL \ + (1U << 4) /* property is virtual: used in duk_propdesc, never stored \ + * (used by e.g. buffer virtual properties) \ + */ +#define DUK_PROPDESC_FLAGS_MASK \ + (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE | DUK_PROPDESC_FLAG_ACCESSOR) /* Additional flags which are passed in the same flags argument as property * flags but are not stored in object properties. */ -#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1U << 4) /* internal define property: skip write silently if exists */ +#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1U << 4) /* internal define property: skip write silently if exists */ /* Convenience defines for property attributes. */ -#define DUK_PROPDESC_FLAGS_NONE 0 -#define DUK_PROPDESC_FLAGS_W (DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_PROPDESC_FLAGS_E (DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_PROPDESC_FLAGS_C (DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_WE (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_PROPDESC_FLAGS_WC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_EC (DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_WEC (DUK_PROPDESC_FLAG_WRITABLE | \ - DUK_PROPDESC_FLAG_ENUMERABLE | \ - DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_NONE 0 +#define DUK_PROPDESC_FLAGS_W (DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_PROPDESC_FLAGS_E (DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_PROPDESC_FLAGS_C (DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_WE (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_PROPDESC_FLAGS_WC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_EC (DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_WEC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) /* Flags for duk_hobject_get_own_propdesc() and variants. */ -#define DUK_GETDESC_FLAG_PUSH_VALUE (1U << 0) /* push value to stack */ -#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1U << 1) /* don't throw for prototype loop */ +#define DUK_GETDESC_FLAG_PUSH_VALUE (1U << 0) /* push value to stack */ +#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1U << 1) /* don't throw for prototype loop */ /* * Macro for object validity check @@ -335,9 +322,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hobject_assert_valid(duk_hobject *h); -#define DUK_HOBJECT_ASSERT_VALID(h) do { duk_hobject_assert_valid((h)); } while (0) +#define DUK_HOBJECT_ASSERT_VALID(h) \ + do { \ + duk_hobject_assert_valid((h)); \ + } while (0) #else -#define DUK_HOBJECT_ASSERT_VALID(h) do {} while (0) +#define DUK_HOBJECT_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -345,52 +337,41 @@ */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_GET_PROPS(heap,h) \ - ((duk_uint8_t *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (h))->h_extra16)) -#define DUK_HOBJECT_SET_PROPS(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROPS(heap, h) ((duk_uint8_t *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (h))->h_extra16)) +#define DUK_HOBJECT_SET_PROPS(heap, h, x) \ + do { \ ((duk_heaphdr *) (h))->h_extra16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (x)); \ } while (0) #else -#define DUK_HOBJECT_GET_PROPS(heap,h) \ - ((h)->props) -#define DUK_HOBJECT_SET_PROPS(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROPS(heap, h) ((h)->props) +#define DUK_HOBJECT_SET_PROPS(heap, h, x) \ + do { \ (h)->props = (duk_uint8_t *) (x); \ } while (0) #endif #if defined(DUK_USE_HOBJECT_LAYOUT_1) /* LAYOUT 1 */ -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_hstring *) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) \ + ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_hstring *))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + (n_arr) * sizeof(duk_tval) + \ + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_k) = (duk_hstring **) (void *) (p_base); \ (set_e_pv) = (duk_propvalue *) (void *) ((set_e_k) + (n_ent)); \ (set_e_f) = (duk_uint8_t *) (void *) ((set_e_pv) + (n_ent)); \ @@ -408,85 +389,57 @@ #else #error invalid DUK_USE_ALIGN_BY #endif -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING((n_ent)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) \ + ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + DUK_HOBJECT_E_FLAG_PADDING((n_ent)) + \ + (n_arr) * sizeof(duk_tval) + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_pv) = (duk_propvalue *) (void *) (p_base); \ (set_e_k) = (duk_hstring **) (void *) ((set_e_pv) + (n_ent)); \ (set_e_f) = (duk_uint8_t *) (void *) ((set_e_k) + (n_ent)); \ - (set_a) = (duk_tval *) (void *) (((duk_uint8_t *) (set_e_f)) + \ - sizeof(duk_uint8_t) * (n_ent) + \ + (set_a) = (duk_tval *) (void *) (((duk_uint8_t *) (set_e_f)) + sizeof(duk_uint8_t) * (n_ent) + \ DUK_HOBJECT_E_FLAG_PADDING((n_ent))); \ (set_h) = (duk_uint32_t *) (void *) ((set_a) + (n_arr)); \ } while (0) #elif defined(DUK_USE_HOBJECT_LAYOUT_3) /* LAYOUT 3 */ -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) + \ - DUK_HOBJECT_GET_HSIZE((h)) * sizeof(duk_uint32_t) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_propvalue) + sizeof(duk_hstring *) + sizeof(duk_uint8_t)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) \ + ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) + \ + DUK_HOBJECT_GET_HSIZE((h)) * sizeof(duk_uint32_t))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_propvalue) + sizeof(duk_hstring *) + sizeof(duk_uint8_t)) + (n_arr) * sizeof(duk_tval) + \ + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_pv) = (duk_propvalue *) (void *) (p_base); \ (set_a) = (duk_tval *) (void *) ((set_e_pv) + (n_ent)); \ (set_e_k) = (duk_hstring **) (void *) ((set_a) + (n_arr)); \ @@ -495,85 +448,99 @@ } while (0) #else #error invalid hobject layout defines -#endif /* hobject property layout */ +#endif /* hobject property layout */ #define DUK_HOBJECT_P_ALLOC_SIZE(h) \ DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE((h)), DUK_HOBJECT_GET_ASIZE((h)), DUK_HOBJECT_GET_HSIZE((h))) -#define DUK_HOBJECT_E_GET_KEY(heap,h,i) (DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_KEY_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE(heap,h,i) (DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE_TVAL(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) -#define DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) -#define DUK_HOBJECT_E_GET_VALUE_GETTER(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) -#define DUK_HOBJECT_E_GET_VALUE_GETTER_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) -#define DUK_HOBJECT_E_GET_VALUE_SETTER(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) -#define DUK_HOBJECT_E_GET_VALUE_SETTER_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) -#define DUK_HOBJECT_E_GET_FLAGS(heap,h,i) (DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_FLAGS_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) -#define DUK_HOBJECT_A_GET_VALUE(heap,h,i) (DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_A_GET_VALUE_PTR(heap,h,i) (&DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_H_GET_INDEX(heap,h,i) (DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_H_GET_INDEX_PTR(heap,h,i) (&DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) - -#define DUK_HOBJECT_E_SET_KEY(heap,h,i,k) do { \ +#define DUK_HOBJECT_E_GET_KEY(heap, h, i) (DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_KEY_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE(heap, h, i) (DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE_TVAL(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) +#define DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) +#define DUK_HOBJECT_E_GET_VALUE_GETTER(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) +#define DUK_HOBJECT_E_GET_VALUE_GETTER_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) +#define DUK_HOBJECT_E_GET_VALUE_SETTER(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) +#define DUK_HOBJECT_E_GET_VALUE_SETTER_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) +#define DUK_HOBJECT_E_GET_FLAGS(heap, h, i) (DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_FLAGS_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) +#define DUK_HOBJECT_A_GET_VALUE(heap, h, i) (DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_A_GET_VALUE_PTR(heap, h, i) (&DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_H_GET_INDEX(heap, h, i) (DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_H_GET_INDEX_PTR(heap, h, i) (&DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) + +#define DUK_HOBJECT_E_SET_KEY(heap, h, i, k) \ + do { \ DUK_HOBJECT_E_GET_KEY((heap), (h), (i)) = (k); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_TVAL(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_TVAL(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_GETTER(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_GETTER(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_SETTER(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_SETTER(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_FLAGS(heap,h,i,f) do { \ +#define DUK_HOBJECT_E_SET_FLAGS(heap, h, i, f) \ + do { \ DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) = (duk_uint8_t) (f); \ } while (0) -#define DUK_HOBJECT_A_SET_VALUE(heap,h,i,v) do { \ +#define DUK_HOBJECT_A_SET_VALUE(heap, h, i, v) \ + do { \ DUK_HOBJECT_A_GET_VALUE((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_A_SET_VALUE_TVAL(heap,h,i,v) \ - DUK_HOBJECT_A_SET_VALUE((heap), (h), (i), (v)) /* alias for above */ -#define DUK_HOBJECT_H_SET_INDEX(heap,h,i,v) do { \ +#define DUK_HOBJECT_A_SET_VALUE_TVAL(heap, h, i, v) DUK_HOBJECT_A_SET_VALUE((heap), (h), (i), (v)) /* alias for above */ +#define DUK_HOBJECT_H_SET_INDEX(heap, h, i, v) \ + do { \ DUK_HOBJECT_H_GET_INDEX((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_FLAG_BITS(heap,h,i,mask) do { \ +#define DUK_HOBJECT_E_SET_FLAG_BITS(heap, h, i, mask) \ + do { \ DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i) |= (mask); \ } while (0) -#define DUK_HOBJECT_E_CLEAR_FLAG_BITS(heap,h,i,mask) do { \ +#define DUK_HOBJECT_E_CLEAR_FLAG_BITS(heap, h, i, mask) \ + do { \ DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i) &= ~(mask); \ } while (0) -#define DUK_HOBJECT_E_SLOT_IS_WRITABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_WRITABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ACCESSOR) != 0) - -#define DUK_HOBJECT_E_SLOT_SET_WRITABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_HOBJECT_E_SLOT_SET_ENUMERABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_HOBJECT_E_SLOT_SET_CONFIGURABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_HOBJECT_E_SLOT_SET_ACCESSOR(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ACCESSOR) - -#define DUK_HOBJECT_E_SLOT_CLEAR_WRITABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_ENUMERABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_CONFIGURABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_ACCESSOR(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ACCESSOR) - -#define DUK_PROPDESC_IS_WRITABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_WRITABLE) != 0) -#define DUK_PROPDESC_IS_ENUMERABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) -#define DUK_PROPDESC_IS_CONFIGURABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) -#define DUK_PROPDESC_IS_ACCESSOR(p) (((p)->flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0) - -#define DUK_HOBJECT_HASHIDX_UNUSED 0xffffffffUL -#define DUK_HOBJECT_HASHIDX_DELETED 0xfffffffeUL +#define DUK_HOBJECT_E_SLOT_IS_WRITABLE(heap, h, i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_WRITABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(heap, h, i) \ + ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(heap, h, i) \ + ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap, h, i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ACCESSOR) != 0) + +#define DUK_HOBJECT_E_SLOT_SET_WRITABLE(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_HOBJECT_E_SLOT_SET_ENUMERABLE(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_HOBJECT_E_SLOT_SET_CONFIGURABLE(heap, h, i) \ + DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_HOBJECT_E_SLOT_SET_ACCESSOR(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ACCESSOR) + +#define DUK_HOBJECT_E_SLOT_CLEAR_WRITABLE(heap, h, i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_ENUMERABLE(heap, h, i) \ + DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_CONFIGURABLE(heap, h, i) \ + DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_ACCESSOR(heap, h, i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ACCESSOR) + +#define DUK_PROPDESC_IS_WRITABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_WRITABLE) != 0) +#define DUK_PROPDESC_IS_ENUMERABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) +#define DUK_PROPDESC_IS_CONFIGURABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) +#define DUK_PROPDESC_IS_ACCESSOR(p) (((p)->flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0) + +#define DUK_HOBJECT_HASHIDX_UNUSED 0xffffffffUL +#define DUK_HOBJECT_HASHIDX_DELETED 0xfffffffeUL /* * Macros for accessing size fields @@ -581,33 +548,63 @@ #if defined(DUK_USE_OBJSIZES16) #define DUK_HOBJECT_GET_ESIZE(h) ((h)->e_size16) -#define DUK_HOBJECT_SET_ESIZE(h,v) do { (h)->e_size16 = (v); } while (0) +#define DUK_HOBJECT_SET_ESIZE(h, v) \ + do { \ + (h)->e_size16 = (v); \ + } while (0) #define DUK_HOBJECT_GET_ENEXT(h) ((h)->e_next16) -#define DUK_HOBJECT_SET_ENEXT(h,v) do { (h)->e_next16 = (v); } while (0) +#define DUK_HOBJECT_SET_ENEXT(h, v) \ + do { \ + (h)->e_next16 = (v); \ + } while (0) #define DUK_HOBJECT_POSTINC_ENEXT(h) ((h)->e_next16++) -#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size16) -#define DUK_HOBJECT_SET_ASIZE(h,v) do { (h)->a_size16 = (v); } while (0) +#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size16) +#define DUK_HOBJECT_SET_ASIZE(h, v) \ + do { \ + (h)->a_size16 = (v); \ + } while (0) #if defined(DUK_USE_HOBJECT_HASH_PART) #define DUK_HOBJECT_GET_HSIZE(h) ((h)->h_size16) -#define DUK_HOBJECT_SET_HSIZE(h,v) do { (h)->h_size16 = (v); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + (h)->h_size16 = (v); \ + } while (0) #else #define DUK_HOBJECT_GET_HSIZE(h) 0 -#define DUK_HOBJECT_SET_HSIZE(h,v) do { DUK_ASSERT((v) == 0); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + DUK_ASSERT((v) == 0); \ + } while (0) #endif #else #define DUK_HOBJECT_GET_ESIZE(h) ((h)->e_size) -#define DUK_HOBJECT_SET_ESIZE(h,v) do { (h)->e_size = (v); } while (0) +#define DUK_HOBJECT_SET_ESIZE(h, v) \ + do { \ + (h)->e_size = (v); \ + } while (0) #define DUK_HOBJECT_GET_ENEXT(h) ((h)->e_next) -#define DUK_HOBJECT_SET_ENEXT(h,v) do { (h)->e_next = (v); } while (0) +#define DUK_HOBJECT_SET_ENEXT(h, v) \ + do { \ + (h)->e_next = (v); \ + } while (0) #define DUK_HOBJECT_POSTINC_ENEXT(h) ((h)->e_next++) -#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size) -#define DUK_HOBJECT_SET_ASIZE(h,v) do { (h)->a_size = (v); } while (0) +#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size) +#define DUK_HOBJECT_SET_ASIZE(h, v) \ + do { \ + (h)->a_size = (v); \ + } while (0) #if defined(DUK_USE_HOBJECT_HASH_PART) #define DUK_HOBJECT_GET_HSIZE(h) ((h)->h_size) -#define DUK_HOBJECT_SET_HSIZE(h,v) do { (h)->h_size = (v); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + (h)->h_size = (v); \ + } while (0) #else #define DUK_HOBJECT_GET_HSIZE(h) 0 -#define DUK_HOBJECT_SET_HSIZE(h,v) do { DUK_ASSERT((v) == 0); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + DUK_ASSERT((v) == 0); \ + } while (0) #endif #endif @@ -618,46 +615,44 @@ /* Maximum prototype traversal depth. Sanity limit which handles e.g. * prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4). */ -#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY 10000L +#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY 10000L /* * ECMAScript Class */ /* range check not necessary because all 4-bit values are mapped */ -#define DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(n) duk_class_number_to_stridx(n) +#define DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(n) duk_class_number_to_stridx(n) -#define DUK_HOBJECT_GET_CLASS_STRING(heap,h) \ - DUK_HEAP_GET_STRING( \ - (heap), \ - DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(DUK_HOBJECT_GET_CLASS_NUMBER((h))) \ - ) +#define DUK_HOBJECT_GET_CLASS_STRING(heap, h) \ + DUK_HEAP_GET_STRING((heap), DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(DUK_HOBJECT_GET_CLASS_NUMBER((h)))) /* * Macros for property handling */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_GET_PROTOTYPE(heap,h) \ - ((duk_hobject *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->prototype16)) -#define DUK_HOBJECT_SET_PROTOTYPE(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROTOTYPE(heap, h) ((duk_hobject *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->prototype16)) +#define DUK_HOBJECT_SET_PROTOTYPE(heap, h, x) \ + do { \ (h)->prototype16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (x)); \ } while (0) #else -#define DUK_HOBJECT_GET_PROTOTYPE(heap,h) \ - ((h)->prototype) -#define DUK_HOBJECT_SET_PROTOTYPE(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROTOTYPE(heap, h) ((h)->prototype) +#define DUK_HOBJECT_SET_PROTOTYPE(heap, h, x) \ + do { \ (h)->prototype = (x); \ } while (0) #endif /* Set prototype, DECREF earlier value, INCREF new value (tolerating NULLs). */ -#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr,h,p) duk_hobject_set_prototype_updref((thr), (h), (p)) +#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, p) duk_hobject_set_prototype_updref((thr), (h), (p)) /* Set initial prototype, assume NULL previous prototype, INCREF new value, * tolerate NULL. */ -#define DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr,h,proto) do { \ +#define DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, h, proto) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_hobject *duk__obj = (h); \ duk_hobject *duk__proto = (proto); \ @@ -672,9 +667,9 @@ */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap,h) duk_hobject_has_finalizer_fast_raw((heap), (h)) +#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap, h) duk_hobject_has_finalizer_fast_raw((heap), (h)) #else -#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap,h) duk_hobject_has_finalizer_fast_raw((h)) +#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap, h) duk_hobject_has_finalizer_fast_raw((h)) #endif /* @@ -688,18 +683,18 @@ * so anything above 0x80000000 will cause trouble now. */ #if defined(DUK_USE_OBJSIZES16) -#define DUK_HOBJECT_MAX_PROPERTIES 0x0000ffffUL +#define DUK_HOBJECT_MAX_PROPERTIES 0x0000ffffUL #else -#define DUK_HOBJECT_MAX_PROPERTIES 0x3fffffffUL /* 2**30-1 ~= 1G properties */ +#define DUK_HOBJECT_MAX_PROPERTIES 0x3fffffffUL /* 2**30-1 ~= 1G properties */ #endif /* internal align target for props allocation, must be 2*n for some n */ #if (DUK_USE_ALIGN_BY == 4) -#define DUK_HOBJECT_ALIGN_TARGET 4 +#define DUK_HOBJECT_ALIGN_TARGET 4 #elif (DUK_USE_ALIGN_BY == 8) -#define DUK_HOBJECT_ALIGN_TARGET 8 +#define DUK_HOBJECT_ALIGN_TARGET 8 #elif (DUK_USE_ALIGN_BY == 1) -#define DUK_HOBJECT_ALIGN_TARGET 1 +#define DUK_HOBJECT_ALIGN_TARGET 1 #else #error invalid DUK_USE_ALIGN_BY #endif @@ -708,10 +703,10 @@ * PC-to-line constants */ -#define DUK_PC2LINE_SKIP 64 +#define DUK_PC2LINE_SKIP 64 /* maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes */ -#define DUK_PC2LINE_MAX_DIFF_LENGTH (((DUK_PC2LINE_SKIP - 1) * 35 + 7) / 8) +#define DUK_PC2LINE_MAX_DIFF_LENGTH (((DUK_PC2LINE_SKIP - 1) * 35 + 7) / 8) /* * Struct defs @@ -738,9 +733,9 @@ duk_hobject *set; /* for updating (all are set to < 0 for virtual properties) */ - duk_int_t e_idx; /* prop index in 'entry part', < 0 if not there */ - duk_int_t h_idx; /* prop index in 'hash part', < 0 if not there */ - duk_int_t a_idx; /* prop index in 'array part', < 0 if not there */ + duk_int_t e_idx; /* prop index in 'entry part', < 0 if not there */ + duk_int_t h_idx; /* prop index in 'hash part', < 0 if not there */ + duk_int_t a_idx; /* prop index in 'array part', < 0 if not there */ }; struct duk_hobject { @@ -835,11 +830,11 @@ duk_uint16_t h_size16; #endif #else - duk_uint32_t e_size; /* entry part size */ - duk_uint32_t e_next; /* index for next new key (0,e_next are gc reachable) */ - duk_uint32_t a_size; /* array part size (entirely gc reachable) */ + duk_uint32_t e_size; /* entry part size */ + duk_uint32_t e_next; /* index for next new key (0,e_next are gc reachable) */ + duk_uint32_t a_size; /* array part size (entirely gc reachable) */ #if defined(DUK_USE_HOBJECT_HASH_PART) - duk_uint32_t h_size; /* hash part size or 0 if unused */ + duk_uint32_t h_size; /* hash part size or 0 if unused */ #endif #endif }; @@ -850,7 +845,7 @@ #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL duk_uint8_t duk_class_number_to_stridx32; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* * Prototypes @@ -879,36 +874,46 @@ duk_uint32_t new_a_size, duk_uint32_t new_h_size, duk_bool_t abandon_array); -DUK_INTERNAL_DECL void duk_hobject_resize_entrypart(duk_hthread *thr, - duk_hobject *obj, - duk_uint32_t new_e_size); -#if 0 /*unused*/ +DUK_INTERNAL_DECL void duk_hobject_resize_entrypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_e_size); +#if 0 /*unused*/ DUK_INTERNAL_DECL void duk_hobject_resize_arraypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_a_size); #endif /* low-level property functions */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_hstring *key); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_stridx(duk_heap *heap, duk_hobject *obj, duk_small_uint_t stridx); -DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_uint_t *out_attrs); +DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, + duk_hobject *obj, + duk_hstring *key, + duk_uint_t *out_attrs); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_array_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_uarridx_t i); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); /* core property functions */ DUK_INTERNAL_DECL duk_bool_t duk_hobject_getprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag); DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_bool_t throw_flag); DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key); /* internal property functions */ -#define DUK_DELPROP_FLAG_THROW (1U << 0) -#define DUK_DELPROP_FLAG_FORCE (1U << 1) +#define DUK_DELPROP_FLAG_THROW (1U << 0) +#define DUK_DELPROP_FLAG_FORCE (1U << 1) DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags); DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key); -DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags); -DUK_INTERNAL_DECL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, duk_hobject *obj, duk_uarridx_t arr_idx, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, + duk_hobject *obj, + duk_uarridx_t arr_idx, + duk_small_uint_t flags); DUK_INTERNAL_DECL duk_size_t duk_hobject_get_length(duk_hthread *thr, duk_hobject *obj); #if defined(DUK_USE_HEAPPTR16) DUK_INTERNAL_DECL duk_bool_t duk_hobject_has_finalizer_fast_raw(duk_heap *heap, duk_hobject *obj); @@ -968,7 +973,10 @@ #endif /* misc */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop); +DUK_INTERNAL_DECL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, + duk_hobject *h, + duk_hobject *p, + duk_bool_t ignore_loop); #if !defined(DUK_USE_OBJECT_BUILTIN) /* These declarations are needed when related built-in is disabled and @@ -978,4 +986,4 @@ DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype(duk_hthread *thr); #endif -#endif /* DUK_HOBJECT_H_INCLUDED */ +#endif /* DUK_HOBJECT_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hobject_alloc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hobject_alloc.c
Changed
@@ -21,7 +21,7 @@ /* Zeroed by caller. */ obj->hdr.h_flags = hobject_flags | DUK_HTYPE_OBJECT; - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(&obj->hdr) == DUK_HTYPE_OBJECT); /* Assume zero shift. */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(&obj->hdr) == DUK_HTYPE_OBJECT); /* Assume zero shift. */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) DUK_HOBJECT_SET_PROTOTYPE(heap, obj, NULL); @@ -157,7 +157,7 @@ DUK_HBUFOBJ_ASSERT_VALID(res); return res; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Allocate a new thread. *
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hobject_assert.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hobject_assert.c
Changed
@@ -8,20 +8,18 @@ DUK_INTERNAL void duk_hobject_assert_valid(duk_hobject *h) { DUK_ASSERT(h != NULL); - DUK_ASSERT(!DUK_HOBJECT_IS_CALLABLE(h) || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FUNCTION); - DUK_ASSERT(!DUK_HOBJECT_IS_BUFOBJ(h) || - (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAYBUFFER || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_DATAVIEW || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT8ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT16ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT16ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT64ARRAY)); + DUK_ASSERT(!DUK_HOBJECT_IS_CALLABLE(h) || DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FUNCTION); + DUK_ASSERT(!DUK_HOBJECT_IS_BUFOBJ(h) || (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAYBUFFER || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_DATAVIEW || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT8ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT16ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT16ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT64ARRAY)); /* Object is an Array <=> object has exotic array behavior */ DUK_ASSERT((DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAY && DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)) || (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_ARRAY && !DUK_HOBJECT_HAS_EXOTIC_ARRAY(h))); @@ -37,8 +35,7 @@ DUK_ASSERT(h != NULL); DUK_ASSERT(DUK_HOBJECT_IS_BOUNDFUNC((duk_hobject *) h)); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(&h->target) || - (DUK_TVAL_IS_OBJECT(&h->target) && - DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(&h->target)))); + (DUK_TVAL_IS_OBJECT(&h->target) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(&h->target)))); DUK_ASSERT(!DUK_TVAL_IS_UNUSED(&h->this_binding)); DUK_ASSERT(h->nargs == 0 || h->args != NULL); } @@ -70,7 +67,7 @@ DUK_ASSERT(h->offset + h->length >= h->offset); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_INTERNAL void duk_hcompfunc_assert_valid(duk_hcompfunc *h) { DUK_ASSERT(h != NULL); @@ -124,4 +121,4 @@ DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hobject_class.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hobject_class.c
Changed
@@ -94,7 +94,7 @@ /* Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that */ DUK_INTERNAL duk_uint8_t duk_class_number_to_stridx32 = { - DUK_STRIDX_EMPTY_STRING, /* NONE, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* NONE, intentionally empty */ DUK_STRIDX_UC_OBJECT, DUK_STRIDX_UC_ARRAY, DUK_STRIDX_UC_FUNCTION, @@ -124,6 +124,6 @@ DUK_STRIDX_UINT32_ARRAY, DUK_STRIDX_FLOAT32_ARRAY, DUK_STRIDX_FLOAT64_ARRAY, - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ };
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hobject_enum.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hobject_enum.c
Changed
@@ -24,7 +24,7 @@ /* First enumerated key index in enumerator object, must match exactly the * number of control properties inserted to the enumerator. */ -#define DUK__ENUM_START_INDEX 2 +#define DUK__ENUM_START_INDEX 2 /* Current implementation suffices for ES2015 for now because there's no symbol * sorting, so commented out for now. @@ -93,7 +93,7 @@ DUK_ASSERT(a != NULL); DUK_ASSERT(b != NULL); - DUK_UNREF(b); /* Not actually needed now, val_b suffices. */ + DUK_UNREF(b); /* Not actually needed now, val_b suffices. */ val_a = duk__hstring_sort_key(a); @@ -114,7 +114,7 @@ DUK_UNREF(thr); if (idx_end <= idx_start + 1) { - return; /* Zero or one element(s). */ + return; /* Zero or one element(s). */ } keys = DUK_HOBJECT_E_GET_KEY_BASE(thr->heap, h_obj); @@ -132,7 +132,7 @@ * (and optimized for) case. */ - val_curr = duk__hstring_sort_key(h_curr); /* Remains same during scanning. */ + val_curr = duk__hstring_sort_key(h_curr); /* Remains same during scanning. */ for (idx_insert = idx - 1; idx_insert >= idx_start; idx_insert--) { duk_hstring *h_insert; h_insert = keysidx_insert; @@ -205,7 +205,7 @@ duk_hobject *h_proxy_handler; duk_hobject *h_trap_result; #endif - duk_uint_fast32_t i, len; /* used for array, stack, and entry indices */ + duk_uint_fast32_t i, len; /* used for array, stack, and entry indices */ duk_uint_fast32_t sort_start_index; DUK_ASSERT(thr != NULL); @@ -224,11 +224,11 @@ * real object to check against. */ duk_push_hobject(thr, enum_target); - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ /* Initialize index so that we skip internal control keys. */ duk_push_int(thr, DUK__ENUM_START_INDEX); - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_NEXT); /* Target is bare, plain put OK. */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_NEXT); /* Target is bare, plain put OK. */ /* * Proxy object handling @@ -238,9 +238,7 @@ if (DUK_LIKELY((enum_flags & DUK_ENUM_NO_PROXY_BEHAVIOR) != 0)) { goto skip_proxy; } - if (DUK_LIKELY(!duk_hobject_proxy_check(enum_target, - &h_proxy_target, - &h_proxy_handler))) { + if (DUK_LIKELY(!duk_hobject_proxy_check(enum_target, &h_proxy_target, &h_proxy_handler))) { goto skip_proxy; } @@ -261,17 +259,17 @@ DUK_DDD(DUK_DDDPRINT("h_proxy_target=%!O", (duk_heaphdr *) h_proxy_target)); enum_target = h_proxy_target; - duk_push_hobject(thr, enum_target); /* -> ... enum_target res handler undefined target */ - duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ + duk_push_hobject(thr, enum_target); /* -> ... enum_target res handler undefined target */ + duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ - duk_pop_2(thr); /* -> ... enum_target res */ + duk_pop_2(thr); /* -> ... enum_target res */ goto skip_proxy; } /* ... enum_target res handler trap */ duk_insert(thr, -2); - duk_push_hobject(thr, h_proxy_target); /* -> ... enum_target res trap handler target */ - duk_call_method(thr, 1 /*nargs*/); /* -> ... enum_target res trap_result */ + duk_push_hobject(thr, h_proxy_target); /* -> ... enum_target res trap handler target */ + duk_call_method(thr, 1 /*nargs*/); /* -> ... enum_target res trap_result */ h_trap_result = duk_require_hobject(thr, -1); DUK_UNREF(h_trap_result); @@ -284,7 +282,7 @@ len = (duk_uint_fast32_t) duk_get_length(thr, -1); for (i = 0; i < len; i++) { (void) duk_get_prop_index(thr, -1, (duk_uarridx_t) i); - DUK_ASSERT(duk_is_string(thr, -1)); /* postprocess cleaned up */ + DUK_ASSERT(duk_is_string(thr, -1)); /* postprocess cleaned up */ /* ... enum_target res trap_result keys_array val */ duk_push_true(thr); /* ... enum_target res trap_result keys_array val true */ @@ -305,8 +303,8 @@ DUK_DDD(DUK_DDDPRINT("proxy enumeration, final res: %!O", (duk_heaphdr *) res)); goto compact_and_return; - skip_proxy: -#endif /* DUK_USE_ES6_PROXY */ +skip_proxy: +#endif /* DUK_USE_ES6_PROXY */ curr = enum_target; sort_start_index = DUK__ENUM_START_INDEX; @@ -357,7 +355,7 @@ if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(curr)) { duk_hstring *h_val; h_val = duk_hobject_get_internal_value_string(thr->heap, curr); - DUK_ASSERT(h_val != NULL); /* string objects must not created without internal value */ + DUK_ASSERT(h_val != NULL); /* string objects must not created without internal value */ len = (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_val); } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -380,7 +378,7 @@ len = (duk_uint_fast32_t) (h_bufobj->length >> h_bufobj->shift); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ for (i = 0; i < len; i++) { duk_hstring *k; @@ -420,7 +418,7 @@ if (DUK_TVAL_IS_UNUSED(tv)) { continue; } - k = duk_heap_strtable_intern_u32_checked(thr, (duk_uint32_t) i); /* Fragile reachability. */ + k = duk_heap_strtable_intern_u32_checked(thr, (duk_uint32_t) i); /* Fragile reachability. */ DUK_ASSERT(k); duk__add_enum_key(thr, k); @@ -452,8 +450,7 @@ continue; } if (DUK_UNLIKELY(DUK_HSTRING_HAS_SYMBOL(k))) { - if (!(enum_flags & DUK_ENUM_INCLUDE_HIDDEN) && - DUK_HSTRING_HAS_HIDDEN(k)) { + if (!(enum_flags & DUK_ENUM_INCLUDE_HIDDEN) && DUK_HSTRING_HAS_HIDDEN(k)) { continue; } if (!(enum_flags & DUK_ENUM_INCLUDE_SYMBOLS)) { @@ -463,7 +460,7 @@ need_sort = 1; #endif } else { - DUK_ASSERT(!DUK_HSTRING_HAS_HIDDEN(k)); /* would also have symbol flag */ + DUK_ASSERT(!DUK_HSTRING_HAS_HIDDEN(k)); /* would also have symbol flag */ if (enum_flags & DUK_ENUM_EXCLUDE_STRINGS) { continue; } @@ -512,7 +509,10 @@ #else if (need_sort) { DUK_DDD(DUK_DDDPRINT("need to sort")); - duk__sort_enum_keys_es6(thr, res, (duk_int_fast32_t) sort_start_index, (duk_int_fast32_t) sort_end_index); + duk__sort_enum_keys_es6(thr, + res, + (duk_int_fast32_t) sort_start_index, + (duk_int_fast32_t) sort_end_index); } else { DUK_DDD(DUK_DDDPRINT("no need to sort")); } @@ -545,11 +545,14 @@ /* Sort to ES2015 order which works for pure array incides but * also for mixed keys. */ - duk__sort_enum_keys_es6(thr, res, (duk_int_fast32_t) DUK__ENUM_START_INDEX, (duk_int_fast32_t) DUK_HOBJECT_GET_ENEXT(res)); + duk__sort_enum_keys_es6(thr, + res, + (duk_int_fast32_t) DUK__ENUM_START_INDEX, + (duk_int_fast32_t) DUK_HOBJECT_GET_ENEXT(res)); } #if defined(DUK_USE_ES6_PROXY) - compact_and_return: +compact_and_return: #endif /* compact; no need to seal because object is internal */ duk_hobject_compact_props(thr, res); @@ -597,10 +600,11 @@ #else check_existence = 1; #endif - duk_pop(thr); /* still reachable */ + duk_pop(thr); /* still reachable */ DUK_DDD(DUK_DDDPRINT("getting next enum value, enum_target=%!iO, enumerator=%!iT", - (duk_heaphdr *) enum_target, (duk_tval *) duk_get_tval(thr, -1))); + (duk_heaphdr *) enum_target, + (duk_tval *) duk_get_tval(thr, -1))); /* no array part */ for (;;) { @@ -641,16 +645,16 @@ duk_push_hstring(thr, res); if (get_value) { duk_push_hobject(thr, enum_target); - duk_dup_m2(thr); /* -> ... enum key enum_target key */ + duk_dup_m2(thr); /* -> ... enum key enum_target key */ duk_get_prop(thr, -2); /* -> ... enum key enum_target val */ - duk_remove_m2(thr); /* -> ... enum key val */ - duk_remove(thr, -3); /* -> ... key val */ + duk_remove_m2(thr); /* -> ... enum key val */ + duk_remove(thr, -3); /* -> ... key val */ } else { - duk_remove_m2(thr); /* -> ... key */ + duk_remove_m2(thr); /* -> ... key */ } return 1; } else { - duk_pop(thr); /* -> ... */ + duk_pop(thr); /* -> ... */ return 0; } } @@ -697,7 +701,7 @@ duk_hstring *k; k = *keys++; - DUK_ASSERT(k != NULL); /* enumerator must have no keys deleted */ + DUK_ASSERT(k != NULL); /* enumerator must have no keys deleted */ DUK_TVAL_SET_STRING(tv, k); tv++; @@ -709,5 +713,5 @@ /* enum_target res */ - return 1; /* return 1 to allow callers to tail call */ + return 1; /* return 1 to allow callers to tail call */ }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hobject_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hobject_misc.c
Changed
@@ -4,7 +4,10 @@ #include "duk_internal.h" -DUK_INTERNAL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop) { +DUK_INTERNAL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, + duk_hobject *h, + duk_hobject *p, + duk_bool_t ignore_loop) { duk_uint_t sanity; DUK_ASSERT(thr != NULL); @@ -43,7 +46,7 @@ DUK_ASSERT(h); tmp = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, h, p); - DUK_HOBJECT_INCREF_ALLOWNULL(thr, p); /* avoid problems if p == h->prototype */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, p); /* avoid problems if p == h->prototype */ DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); #else DUK_ASSERT(h);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hobject_pc2line.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hobject_pc2line.c
Changed
@@ -35,7 +35,7 @@ hdr = (duk_uint32_t *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, h_buf); DUK_ASSERT(hdr != NULL); - hdr0 = (duk_uint32_t) length; /* valid pc range is 0, length */ + hdr0 = (duk_uint32_t) length; /* valid pc range is 0, length */ curr_pc = 0U; while (curr_pc < length) { @@ -64,8 +64,8 @@ for (;;) { curr_pc++; - if ( ((curr_pc % DUK_PC2LINE_SKIP) == 0) || /* end of diff run */ - (curr_pc >= length) ) { /* end of bytecode */ + if (((curr_pc % DUK_PC2LINE_SKIP) == 0) || /* end of diff run */ + (curr_pc >= length)) { /* end of bytecode */ break; } DUK_ASSERT(curr_pc < length); @@ -112,7 +112,9 @@ (void) duk_to_fixed_buffer(thr, -1, NULL); DUK_DDD(DUK_DDDPRINT("final pc2line data: pc_limit=%ld, length=%ld, %lf bits/opcode --> %!ixT", - (long) length, (long) new_size, (double) new_size * 8.0 / (double) length, + (long) length, + (long) new_size, + (double) new_size * 8.0 / (double) length, (duk_tval *) duk_get_tval(thr, -1))); } @@ -152,8 +154,7 @@ pc_limit = hdr0; if (pc >= pc_limit) { /* Note: pc is unsigned and cannot be negative */ - DUK_DD(DUK_DDPRINT("pc2line lookup failed: pc out of bounds (pc=%ld, limit=%ld)", - (long) pc, (long) pc_limit)); + DUK_DD(DUK_DDPRINT("pc2line lookup failed: pc out of bounds (pc=%ld, limit=%ld)", (long) pc, (long) pc_limit)); goto pc2line_error; } @@ -161,7 +162,8 @@ start_offset = hdr1 + hdr_index * 2 + 1; if ((duk_size_t) start_offset > DUK_HBUFFER_FIXED_GET_SIZE(buf)) { DUK_DD(DUK_DDPRINT("pc2line lookup failed: start_offset out of bounds (start_offset=%ld, buffer_size=%ld)", - (long) start_offset, (long) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) buf))); + (long) start_offset, + (long) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) buf))); goto pc2line_error; } @@ -188,7 +190,7 @@ if (duk_bd_decode_flag(bd_ctx)) { /* 1 1 1 <32 bits> */ duk_uint_fast32_t t; - t = duk_bd_decode(bd_ctx, 16); /* workaround: max nbits = 24 now */ + t = duk_bd_decode(bd_ctx, 16); /* workaround: max nbits = 24 now */ t = (t << 16) + duk_bd_decode(bd_ctx, 16); curr_line = t; } else { @@ -213,7 +215,7 @@ DUK_DDD(DUK_DDDPRINT("pc2line lookup result: pc %ld -> line %ld", (long) pc, (long) curr_line)); return curr_line; - pc2line_error: +pc2line_error: DUK_D(DUK_DPRINT("pc2line conversion failed for pc=%ld", (long) pc)); return 0; } @@ -241,4 +243,4 @@ return line; } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hobject_props.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hobject_props.c
Changed
@@ -46,35 +46,56 @@ * Local defines */ -#define DUK__NO_ARRAY_INDEX DUK_HSTRING_NO_ARRAY_INDEX +#define DUK__NO_ARRAY_INDEX DUK_HSTRING_NO_ARRAY_INDEX /* Marker values for hash part. */ -#define DUK__HASH_UNUSED DUK_HOBJECT_HASHIDX_UNUSED -#define DUK__HASH_DELETED DUK_HOBJECT_HASHIDX_DELETED +#define DUK__HASH_UNUSED DUK_HOBJECT_HASHIDX_UNUSED +#define DUK__HASH_DELETED DUK_HOBJECT_HASHIDX_DELETED /* Valstack space that suffices for all local calls, excluding any recursion * into ECMAScript or Duktape/C calls (Proxy, getters, etc). */ -#define DUK__VALSTACK_SPACE 10 +#define DUK__VALSTACK_SPACE 10 /* Valstack space allocated especially for proxy lookup which does a * recursive property lookup. */ -#define DUK__VALSTACK_PROXY_LOOKUP 20 +#define DUK__VALSTACK_PROXY_LOOKUP 20 /* * Local prototypes */ -DUK_LOCAL_DECL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc); -DUK_LOCAL_DECL void duk__check_arguments_map_for_put(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc, duk_bool_t throw_flag); -DUK_LOCAL_DECL void duk__check_arguments_map_for_delete(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc); - -DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length_smaller(duk_hthread *thr, duk_hobject *obj, duk_uint32_t old_len, duk_uint32_t new_len, duk_bool_t force_flag, duk_uint32_t *out_result_len); +DUK_LOCAL_DECL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc); +DUK_LOCAL_DECL void duk__check_arguments_map_for_put(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc, + duk_bool_t throw_flag); +DUK_LOCAL_DECL void duk__check_arguments_map_for_delete(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc); + +DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length_smaller(duk_hthread *thr, + duk_hobject *obj, + duk_uint32_t old_len, + duk_uint32_t new_len, + duk_bool_t force_flag, + duk_uint32_t *out_result_len); DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length(duk_hthread *thr, duk_hobject *obj); -DUK_LOCAL_DECL duk_bool_t duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); -DUK_LOCAL_DECL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_uint32_t arr_idx, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_LOCAL_DECL duk_bool_t +duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_LOCAL_DECL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_uint32_t arr_idx, + duk_propdesc *out_desc, + duk_small_uint_t flags); DUK_LOCAL_DECL void duk__abandon_array_part(duk_hthread *thr, duk_hobject *obj); DUK_LOCAL_DECL void duk__grow_props_for_array_item(duk_hthread *thr, duk_hobject *obj, duk_uint32_t highest_arr_idx); @@ -103,7 +124,7 @@ dbl = DUK_TVAL_GET_NUMBER(tv); idx = (duk_uint32_t) dbl; if (duk_double_equals((duk_double_t) idx, dbl)) { - /* Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF, + /* Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF, * it's not a valid array index but will then match DUK__NO_ARRAY_INDEX. */ return idx; @@ -130,7 +151,7 @@ */ return (duk_uint32_t) t; } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* Convert a duk_tval on the value stack (in a trusted index we don't validate) * to a string or symbol using ES2015 ToPropertyKey(): @@ -155,7 +176,7 @@ * but still be compliant and share code. */ - tv_dst = DUK_GET_TVAL_NEGIDX(thr, idx); /* intentionally unvalidated */ + tv_dst = DUK_GET_TVAL_NEGIDX(thr, idx); /* intentionally unvalidated */ if (DUK_TVAL_IS_STRING(tv_dst)) { /* Most important path: strings and plain symbols are used as * is. For symbols the array index check below is unnecessary @@ -175,7 +196,7 @@ } DUK_LOCAL duk_uint32_t duk__push_tval_to_property_key(duk_hthread *thr, duk_tval *tv_key, duk_hstring **out_h) { - duk_push_tval(thr, tv_key); /* XXX: could use an unsafe push here */ + duk_push_tval(thr, tv_key); /* XXX: could use an unsafe push here */ return duk__to_property_key(thr, -1, out_h); } @@ -215,7 +236,7 @@ * is relatively sparse. */ tmp = e_size; - res = 2; /* Result will be 2 ** (N + 1). */ + res = 2; /* Result will be 2 ** (N + 1). */ while (tmp >= 0x40) { tmp >>= 6; res <<= 6; @@ -224,21 +245,21 @@ tmp >>= 1; res <<= 1; } - DUK_ASSERT((DUK_HOBJECT_MAX_PROPERTIES << 2U) > DUK_HOBJECT_MAX_PROPERTIES); /* Won't wrap, even shifted by 2. */ + DUK_ASSERT((DUK_HOBJECT_MAX_PROPERTIES << 2U) > DUK_HOBJECT_MAX_PROPERTIES); /* Won't wrap, even shifted by 2. */ DUK_ASSERT(res > e_size); return res; } else { return 0; } } -#endif /* USE_PROP_HASH_PART */ +#endif /* USE_PROP_HASH_PART */ /* Get minimum entry part growth for a certain size. */ DUK_LOCAL duk_uint32_t duk__get_min_grow_e(duk_uint32_t e_size) { duk_uint32_t res; res = (e_size + DUK_USE_HOBJECT_ENTRY_MINGROW_ADD) / DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR; - DUK_ASSERT(res >= 1); /* important for callers */ + DUK_ASSERT(res >= 1); /* important for callers */ return res; } @@ -247,7 +268,7 @@ duk_uint32_t res; res = (a_size + DUK_USE_HOBJECT_ARRAY_MINGROW_ADD) / DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR; - DUK_ASSERT(res >= 1); /* important for callers */ + DUK_ASSERT(res >= 1); /* important for callers */ return res; } @@ -277,7 +298,7 @@ DUK_LOCAL void duk__compute_a_stats(duk_hthread *thr, duk_hobject *obj, duk_uint32_t *out_used, duk_uint32_t *out_min_size) { duk_uint_fast32_t i; duk_uint_fast32_t used = 0; - duk_uint_fast32_t highest_idx = (duk_uint_fast32_t) -1; /* see below */ + duk_uint_fast32_t highest_idx = (duk_uint_fast32_t) -1; /* see below */ duk_tval *a; DUK_ASSERT(obj != NULL); @@ -300,7 +321,7 @@ */ *out_used = (duk_uint32_t) used; - *out_min_size = (duk_uint32_t) (highest_idx + 1); /* 0 if no used entries */ + *out_min_size = (duk_uint32_t) (highest_idx + 1); /* 0 if no used entries */ } /* Check array density and indicate whether or not the array part should be abandoned. */ @@ -367,7 +388,9 @@ duk__compute_a_stats(thr, obj, &old_used, &old_size); DUK_DDD(DUK_DDDPRINT("abandon check, array stats: old_used=%ld, old_size=%ld, arr_idx=%ld", - (long) old_used, (long) old_size, (long) arr_idx)); + (long) old_used, + (long) old_size, + (long) arr_idx)); min_size = arr_idx + 1; #if defined(DUK_USE_OBJSIZES16) @@ -395,7 +418,7 @@ DUK_DDD(DUK_DDDPRINT("=> decided to keep array part")); return 0; - do_abandon: +do_abandon: duk__abandon_array_part(thr, obj); DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(obj)); return 1; @@ -422,7 +445,8 @@ DUK_DDD(DUK_DDDPRINT("write to new array requires array resize, decide whether to do a " "fast resize without abandon check (arr_idx=%ld, old_size=%ld)", - (long) arr_idx, (long) DUK_HOBJECT_GET_ASIZE(obj))); + (long) arr_idx, + (long) DUK_HOBJECT_GET_ASIZE(obj))); if (DUK_UNLIKELY(duk__abandon_array_check(thr, arr_idx, obj) != 0)) { DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(obj)); @@ -481,7 +505,7 @@ return 1; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* Get Proxy target object. If the argument is not a Proxy, return it as is. * If a Proxy is revoked, an error is thrown. @@ -507,10 +531,14 @@ DUK_ASSERT(obj != NULL); return obj; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ES6_PROXY) -DUK_LOCAL duk_bool_t duk__proxy_check_prop(duk_hthread *thr, duk_hobject *obj, duk_small_uint_t stridx_trap, duk_tval *tv_key, duk_hobject **out_target) { +DUK_LOCAL duk_bool_t duk__proxy_check_prop(duk_hthread *thr, + duk_hobject *obj, + duk_small_uint_t stridx_trap, + duk_tval *tv_key, + duk_hobject **out_target) { duk_hobject *h_handler; DUK_ASSERT(thr != NULL); @@ -564,7 +592,7 @@ duk_push_hobject(thr, h_handler); if (duk_get_prop_stridx_short(thr, -1, stridx_trap)) { /* -> ... handler trap */ - duk_insert(thr, -2); /* -> ... trap handler */ + duk_insert(thr, -2); /* -> ... trap handler */ /* stack prepped for func call: ... trap handler */ return 1; @@ -573,7 +601,7 @@ return 0; } } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* * Reallocate property allocation, moving properties to the new allocation. @@ -628,11 +656,12 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(obj != NULL); - DUK_ASSERT(!abandon_array || new_a_size == 0); /* if abandon_array, new_a_size must be 0 */ - DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || (DUK_HOBJECT_GET_ESIZE(obj) == 0 && DUK_HOBJECT_GET_ASIZE(obj) == 0)); - DUK_ASSERT(new_h_size == 0 || new_h_size >= new_e_size); /* required to guarantee success of rehashing, - * intentionally use unadjusted new_e_size - */ + DUK_ASSERT(!abandon_array || new_a_size == 0); /* if abandon_array, new_a_size must be 0 */ + DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || + (DUK_HOBJECT_GET_ESIZE(obj) == 0 && DUK_HOBJECT_GET_ASIZE(obj) == 0)); + DUK_ASSERT(new_h_size == 0 || new_h_size >= new_e_size); /* required to guarantee success of rehashing, + * intentionally use unadjusted new_e_size + */ DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); @@ -662,10 +691,12 @@ DUK_DDD(DUK_DDDPRINT("using layout 1, but no need to pad e_size: %ld", (long) new_e_size)); new_e_size_adjusted = new_e_size; #elif defined(DUK_USE_HOBJECT_LAYOUT_1) && ((DUK_HOBJECT_ALIGN_TARGET == 4) || (DUK_HOBJECT_ALIGN_TARGET == 8)) - new_e_size_adjusted = (new_e_size + (duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U) & - (~((duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U)); + new_e_size_adjusted = + (new_e_size + (duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U) & (~((duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U)); DUK_DDD(DUK_DDDPRINT("using layout 1, and alignment target is %ld, adjusted e_size: %ld -> %ld", - (long) DUK_HOBJECT_ALIGN_TARGET, (long) new_e_size, (long) new_e_size_adjusted)); + (long) DUK_HOBJECT_ALIGN_TARGET, + (long) new_e_size, + (long) new_e_size_adjusted)); DUK_ASSERT(new_e_size_adjusted >= new_e_size); #else #error invalid hobject layout defines @@ -675,23 +706,22 @@ * Debug logging after adjustment. */ - DUK_DDD(DUK_DDDPRINT("attempt to resize hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " - "{e_size=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", - (void *) obj, - (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)), - (long) DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size), - (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), - (long) DUK_HOBJECT_GET_ESIZE(obj), - (long) DUK_HOBJECT_GET_ENEXT(obj), - (long) DUK_HOBJECT_GET_ASIZE(obj), - (long) DUK_HOBJECT_GET_HSIZE(obj), - (long) new_e_size_adjusted, - (long) new_a_size, - (long) new_h_size, - (long) abandon_array, - (long) new_e_size)); + DUK_DDD(DUK_DDDPRINT( + "attempt to resize hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " + "{e_size=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", + (void *) obj, + (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)), + (long) DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size), + (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), + (long) DUK_HOBJECT_GET_ESIZE(obj), + (long) DUK_HOBJECT_GET_ENEXT(obj), + (long) DUK_HOBJECT_GET_ASIZE(obj), + (long) DUK_HOBJECT_GET_HSIZE(obj), + (long) new_e_size_adjusted, + (long) new_a_size, + (long) new_h_size, + (long) abandon_array, + (long) new_e_size)); /* * Property count check. This is the only point where we ensure that @@ -734,9 +764,9 @@ #endif prev_ms_base_flags = thr->heap->ms_base_flags; thr->heap->ms_base_flags |= - DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact the current object (all objects really). */ - thr->heap->pf_prevent_count++; /* Avoid finalizers. */ - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact the current object (all objects really). */ + thr->heap->pf_prevent_count++; /* Avoid finalizers. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ new_alloc_size = DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size); DUK_DDD(DUK_DDDPRINT("new hobject allocation size is %ld", (long) new_alloc_size)); @@ -749,7 +779,7 @@ /* Alloc may trigger mark-and-sweep but no compaction, and * cannot throw. */ -#if 0 /* XXX: inject test */ +#if 0 /* XXX: inject test */ if (1) { new_p = NULL; goto alloc_failed; @@ -767,19 +797,28 @@ /* Set up pointers to the new property area: this is hidden behind a macro * because it is memory layout specific. */ - DUK_HOBJECT_P_SET_REALLOC_PTRS(new_p, new_e_k, new_e_pv, new_e_f, new_a, new_h, - new_e_size_adjusted, new_a_size, new_h_size); - DUK_UNREF(new_h); /* happens when hash part dropped */ + DUK_HOBJECT_P_SET_REALLOC_PTRS(new_p, + new_e_k, + new_e_pv, + new_e_f, + new_a, + new_h, + new_e_size_adjusted, + new_a_size, + new_h_size); + DUK_UNREF(new_h); /* happens when hash part dropped */ new_e_next = 0; /* if new_p == NULL, all of these pointers are NULL */ - DUK_ASSERT((new_p != NULL) || - (new_e_k == NULL && new_e_pv == NULL && new_e_f == NULL && - new_a == NULL && new_h == NULL)); + DUK_ASSERT((new_p != NULL) || (new_e_k == NULL && new_e_pv == NULL && new_e_f == NULL && new_a == NULL && new_h == NULL)); DUK_DDD(DUK_DDDPRINT("new alloc size %ld, new_e_k=%p, new_e_pv=%p, new_e_f=%p, new_a=%p, new_h=%p", - (long) new_alloc_size, (void *) new_e_k, (void *) new_e_pv, (void *) new_e_f, - (void *) new_a, (void *) new_h)); + (long) new_alloc_size, + (void *) new_e_k, + (void *) new_e_pv, + (void *) new_e_f, + (void *) new_a, + (void *) new_h)); /* * Migrate array part to start of entries if requested. @@ -820,8 +859,7 @@ continue; } - DUK_ASSERT(new_p != NULL && new_e_k != NULL && - new_e_pv != NULL && new_e_f != NULL); + DUK_ASSERT(new_p != NULL && new_e_k != NULL && new_e_pv != NULL && new_e_f != NULL); /* * Intern key via the valstack to ensure reachability behaves @@ -833,7 +871,7 @@ * must be careful. */ -#if 0 /* XXX: inject test */ +#if 0 /* XXX: inject test */ if (1) { goto abandon_error; } @@ -849,7 +887,7 @@ if (key == NULL) { goto abandon_error; } - duk_push_hstring(thr, key); /* keep key reachable for GC etc; guaranteed not to fail */ + duk_push_hstring(thr, key); /* keep key reachable for GC etc; guaranteed not to fail */ /* Key is now reachable in the valstack, don't INCREF * the new allocation yet (we'll steal the refcounts @@ -857,11 +895,10 @@ */ new_e_knew_e_next = key; - tv2 = &new_e_pvnew_e_next.v; /* array entries are all plain values */ + tv2 = &new_e_pvnew_e_next.v; /* array entries are all plain values */ DUK_TVAL_SET_TVAL(tv2, tv1); - new_e_fnew_e_next = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE | - DUK_PROPDESC_FLAG_CONFIGURABLE; + new_e_fnew_e_next = + DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE; new_e_next++; /* Note: new_e_next matches pushed temp key count, and nothing can @@ -888,8 +925,7 @@ continue; } - DUK_ASSERT(new_p != NULL && new_e_k != NULL && - new_e_pv != NULL && new_e_f != NULL); + DUK_ASSERT(new_p != NULL && new_e_k != NULL && new_e_pv != NULL && new_e_f != NULL); new_e_knew_e_next = key; new_e_pvnew_e_next = DUK_HOBJECT_E_GET_VALUE(thr->heap, obj, i); @@ -923,9 +959,7 @@ DUK_ASSERT(new_a != NULL || array_copy_size == 0U); DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || array_copy_size == 0U); DUK_ASSERT(DUK_HOBJECT_GET_ASIZE(obj) > 0 || array_copy_size == 0U); - duk_memcpy_unsafe((void *) new_a, - (const void *) DUK_HOBJECT_A_GET_BASE(thr->heap, obj), - array_copy_size); + duk_memcpy_unsafe((void *) new_a, (const void *) DUK_HOBJECT_A_GET_BASE(thr->heap, obj), array_copy_size); for (i = DUK_HOBJECT_GET_ASIZE(obj); i < new_a_size; i++) { duk_tval *tv = &new_ai; @@ -953,7 +987,7 @@ DUK_ASSERT(new_h_size > 0); duk_memset(new_h, 0xff, sizeof(duk_uint32_t) * new_h_size); - DUK_ASSERT(new_e_next <= new_h_size); /* equality not actually possible */ + DUK_ASSERT(new_e_next <= new_h_size); /* equality not actually possible */ mask = new_h_size - 1; for (i = 0; i < new_e_next; i++) { @@ -962,10 +996,10 @@ DUK_ASSERT(key != NULL); j = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { - DUK_ASSERT(new_hj != DUK__HASH_DELETED); /* should never happen */ + DUK_ASSERT(new_hj != DUK__HASH_DELETED); /* should never happen */ if (new_hj == DUK__HASH_UNUSED) { DUK_DDD(DUK_DDDPRINT("rebuild hit %ld -> %ld", (long) j, (long) i)); new_hj = (duk_uint32_t) i; @@ -978,37 +1012,36 @@ } } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* * Nice debug log. */ - DUK_DD(DUK_DDPRINT("resized hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " - "{p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", - (void *) obj, - (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)), - (long) new_alloc_size, - (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), - (long) DUK_HOBJECT_GET_ESIZE(obj), - (long) DUK_HOBJECT_GET_ENEXT(obj), - (long) DUK_HOBJECT_GET_ASIZE(obj), - (long) DUK_HOBJECT_GET_HSIZE(obj), - (void *) new_p, - (long) new_e_size_adjusted, - (long) new_e_next, - (long) new_a_size, - (long) new_h_size, - (long) abandon_array, - (long) new_e_size)); + DUK_DD(DUK_DDPRINT( + "resized hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " + "{p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", + (void *) obj, + (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)), + (long) new_alloc_size, + (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), + (long) DUK_HOBJECT_GET_ESIZE(obj), + (long) DUK_HOBJECT_GET_ENEXT(obj), + (long) DUK_HOBJECT_GET_ASIZE(obj), + (long) DUK_HOBJECT_GET_HSIZE(obj), + (void *) new_p, + (long) new_e_size_adjusted, + (long) new_e_next, + (long) new_a_size, + (long) new_h_size, + (long) abandon_array, + (long) new_e_size)); /* * All done, switch properties ('p') allocation to new one. */ - DUK_FREE_CHECKED(thr, DUK_HOBJECT_GET_PROPS(thr->heap, obj)); /* NULL obj->p is OK */ + DUK_FREE_CHECKED(thr, DUK_HOBJECT_GET_PROPS(thr->heap, obj)); /* NULL obj->p is OK */ DUK_HOBJECT_SET_PROPS(thr->heap, obj, new_p); DUK_HOBJECT_SET_ESIZE(obj, new_e_size_adjusted); DUK_HOBJECT_SET_ENEXT(obj, new_e_next); @@ -1047,11 +1080,11 @@ * unwind. */ - abandon_error: - alloc_failed: +abandon_error: +alloc_failed: DUK_D(DUK_DPRINT("object property table resize failed")); - DUK_FREE_CHECKED(thr, new_p); /* OK for NULL. */ + DUK_FREE_CHECKED(thr, new_p); /* OK for NULL. */ thr->heap->pf_prevent_count--; thr->heap->ms_base_flags = prev_ms_base_flags; @@ -1068,9 +1101,7 @@ * Helpers to resize properties allocation on specific needs. */ -DUK_INTERNAL void duk_hobject_resize_entrypart(duk_hthread *thr, - duk_hobject *obj, - duk_uint32_t new_e_size) { +DUK_INTERNAL void duk_hobject_resize_entrypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_e_size) { duk_uint32_t old_e_size; duk_uint32_t new_a_size; duk_uint32_t new_h_size; @@ -1094,7 +1125,7 @@ /* Grow entry part allocation for one additional entry. */ DUK_LOCAL void duk__grow_props_for_new_entry_item(duk_hthread *thr, duk_hobject *obj) { - duk_uint32_t old_e_used; /* actually used, non-NULL entries */ + duk_uint32_t old_e_used; /* actually used, non-NULL entries */ duk_uint32_t new_e_size_minimum; duk_uint32_t new_e_size; duk_uint32_t new_a_size; @@ -1156,7 +1187,7 @@ new_h_size = DUK_HOBJECT_GET_HSIZE(obj); new_a_size_minimum = highest_arr_idx + 1; new_a_size = highest_arr_idx + duk__get_min_grow_a(highest_arr_idx); - DUK_ASSERT(new_a_size >= highest_arr_idx + 1); /* duk__get_min_grow_a() is always >= 1 */ + DUK_ASSERT(new_a_size >= highest_arr_idx + 1); /* duk__get_min_grow_a() is always >= 1 */ #if defined(DUK_USE_OBJSIZES16) if (new_e_size > DUK_UINT16_MAX) { @@ -1188,7 +1219,7 @@ duk_uint32_t new_e_size; duk_uint32_t new_a_size; duk_uint32_t new_h_size; - duk_uint32_t e_used; /* actually used, non-NULL keys */ + duk_uint32_t e_used; /* actually used, non-NULL keys */ duk_uint32_t a_used; duk_uint32_t a_size; @@ -1233,8 +1264,13 @@ DUK_DD(DUK_DDPRINT("abandon array part for hobject %p, " "array stats before: e_used=%ld, a_used=%ld, a_size=%ld; " "resize to e_size=%ld, a_size=%ld, h_size=%ld", - (void *) obj, (long) e_used, (long) a_used, (long) a_size, - (long) new_e_size, (long) new_a_size, (long) new_h_size)); + (void *) obj, + (long) e_used, + (long) a_used, + (long) a_size, + (long) new_e_size, + (long) new_a_size, + (long) new_h_size)); duk_hobject_realloc_props(thr, obj, new_e_size, new_a_size, new_h_size, 1); } @@ -1252,9 +1288,9 @@ */ DUK_INTERNAL void duk_hobject_compact_props(duk_hthread *thr, duk_hobject *obj) { - duk_uint32_t e_size; /* currently used -> new size */ - duk_uint32_t a_size; /* currently required */ - duk_uint32_t a_used; /* actually used */ + duk_uint32_t e_size; /* currently used -> new size */ + duk_uint32_t a_size; /* currently required */ + duk_uint32_t a_used; /* actually used */ duk_uint32_t h_size; duk_bool_t abandon_array; @@ -1273,13 +1309,17 @@ DUK_DD(DUK_DDPRINT("compacting hobject, used e keys %ld, used a keys %ld, min a size %ld, " "resized array density would be: %ld/%ld = %lf", - (long) e_size, (long) a_used, (long) a_size, - (long) a_used, (long) a_size, + (long) e_size, + (long) a_used, + (long) a_size, + (long) a_used, + (long) a_size, (double) a_used / (double) a_size)); if (duk__abandon_array_density_check(a_used, a_size)) { DUK_DD(DUK_DDPRINT("decided to abandon array during compaction, a_used=%ld, a_size=%ld", - (long) a_used, (long) a_size)); + (long) a_used, + (long) a_size)); abandon_array = 1; e_size += a_used; a_size = 0; @@ -1299,7 +1339,10 @@ #endif DUK_DD(DUK_DDPRINT("compacting hobject -> new e_size %ld, new a_size=%ld, new h_size=%ld, abandon_array=%ld", - (long) e_size, (long) a_size, (long) h_size, (long) abandon_array)); + (long) e_size, + (long) a_size, + (long) h_size, + (long) abandon_array)); duk_hobject_realloc_props(thr, obj, e_size, a_size, h_size, abandon_array); } @@ -1314,15 +1357,15 @@ * but there is no hash part, h_idx is set to -1. */ -DUK_INTERNAL duk_bool_t duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx) { +DUK_INTERNAL duk_bool_t +duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx) { DUK_ASSERT(obj != NULL); DUK_ASSERT(key != NULL); DUK_ASSERT(e_idx != NULL); DUK_ASSERT(h_idx != NULL); DUK_UNREF(heap); - if (DUK_LIKELY(DUK_HOBJECT_GET_HSIZE(obj) == 0)) - { + if (DUK_LIKELY(DUK_HOBJECT_GET_HSIZE(obj) == 0)) { /* Linear scan: more likely because most objects are small. * This is an important fast path. * @@ -1344,8 +1387,7 @@ } } #if defined(DUK_USE_HOBJECT_HASH_PART) - else - { + else { /* hash lookup */ duk_uint32_t n; duk_uint32_t i, step; @@ -1358,40 +1400,38 @@ n = DUK_HOBJECT_GET_HSIZE(obj); mask = n - 1; i = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { duk_uint32_t t; - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HOBJECT_GET_HSIZE(obj)); t = h_basei; DUK_ASSERT(t == DUK__HASH_UNUSED || t == DUK__HASH_DELETED || - (t < DUK_HOBJECT_GET_ESIZE(obj))); /* t >= 0 always true, unsigned */ + (t < DUK_HOBJECT_GET_ESIZE(obj))); /* t >= 0 always true, unsigned */ if (t == DUK__HASH_UNUSED) { break; } else if (t == DUK__HASH_DELETED) { - DUK_DDD(DUK_DDDPRINT("lookup miss (deleted) i=%ld, t=%ld", - (long) i, (long) t)); + DUK_DDD(DUK_DDDPRINT("lookup miss (deleted) i=%ld, t=%ld", (long) i, (long) t)); } else { DUK_ASSERT(t < DUK_HOBJECT_GET_ESIZE(obj)); if (DUK_HOBJECT_E_GET_KEY(heap, obj, t) == key) { - DUK_DDD(DUK_DDDPRINT("lookup hit i=%ld, t=%ld -> key %p", - (long) i, (long) t, (void *) key)); + DUK_DDD( + DUK_DDDPRINT("lookup hit i=%ld, t=%ld -> key %p", (long) i, (long) t, (void *) key)); *e_idx = (duk_int_t) t; *h_idx = (duk_int_t) i; return 1; } - DUK_DDD(DUK_DDDPRINT("lookup miss i=%ld, t=%ld", - (long) i, (long) t)); + DUK_DDD(DUK_DDDPRINT("lookup miss i=%ld, t=%ld", (long) i, (long) t)); } i = (i + step) & mask; /* Guaranteed to finish (hash is larger than #props). */ } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* Not found, leave e_idx and h_idx unset. */ return 0; @@ -1420,7 +1460,10 @@ } /* For internal use: get non-accessor entry value and attributes */ -DUK_INTERNAL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_uint_t *out_attrs) { +DUK_INTERNAL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, + duk_hobject *obj, + duk_hstring *key, + duk_uint_t *out_attrs) { duk_int_t e_idx; duk_int_t h_idx; @@ -1505,14 +1548,15 @@ n = DUK_HOBJECT_GET_HSIZE(obj); mask = n - 1; i = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { duk_uint32_t t = h_basei; if (t == DUK__HASH_UNUSED || t == DUK__HASH_DELETED) { DUK_DDD(DUK_DDDPRINT("duk__hobject_alloc_entry_checked() inserted key into hash part, %ld -> %ld", - (long) i, (long) idx)); - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + (long) i, + (long) idx)); + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HOBJECT_GET_HSIZE(obj)); DUK_ASSERT_DISABLE(idx >= 0); DUK_ASSERT(idx < DUK_HOBJECT_GET_ESIZE(obj)); @@ -1525,7 +1569,7 @@ /* Guaranteed to finish (hash is larger than #props). */ } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* Note: we could return the hash index here too, but it's not * needed right now. @@ -1633,8 +1677,12 @@ DUK_DDD(DUK_DDDPRINT("arguments map lookup: thr=%p, obj=%p, key=%p, temp_desc=%p " "(obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) temp_desc, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) temp_desc, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); if (!duk_hobject_get_own_propdesc(thr, obj, DUK_HTHREAD_STRING_INT_MAP(thr), temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { DUK_DDD(DUK_DDDPRINT("-> no 'map'")); @@ -1643,7 +1691,7 @@ map = duk_require_hobject(thr, -1); DUK_ASSERT(map != NULL); - duk_pop_unsafe(thr); /* map is reachable through obj */ + duk_pop_unsafe(thr); /* map is reachable through obj */ if (!duk_hobject_get_own_propdesc(thr, map, key, temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { DUK_DDD(DUK_DDDPRINT("-> 'map' exists, but key not in map")); @@ -1653,29 +1701,32 @@ /* ... varname */ DUK_DDD(DUK_DDDPRINT("-> 'map' exists, and contains key, key is mapped to argument/variable binding %!T", (duk_tval *) duk_get_tval(thr, -1))); - DUK_ASSERT(duk_is_string(thr, -1)); /* guaranteed when building arguments */ + DUK_ASSERT(duk_is_string(thr, -1)); /* guaranteed when building arguments */ /* get varenv for varname (callee's declarative lexical environment) */ rc = duk_hobject_get_own_propdesc(thr, obj, DUK_HTHREAD_STRING_INT_VARENV(thr), temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); - DUK_ASSERT(rc != 0); /* arguments MUST have an initialized lexical environment reference */ + DUK_ASSERT(rc != 0); /* arguments MUST have an initialized lexical environment reference */ varenv = duk_require_hobject(thr, -1); DUK_ASSERT(varenv != NULL); - duk_pop_unsafe(thr); /* varenv remains reachable through 'obj' */ + duk_pop_unsafe(thr); /* varenv remains reachable through 'obj' */ DUK_DDD(DUK_DDDPRINT("arguments varenv is: %!dO", (duk_heaphdr *) varenv)); /* success: leave varname in stack */ *out_map = map; *out_varenv = varenv; - return 1; /* ... varname */ + return 1; /* ... varname */ } /* Lookup 'key' from arguments internal 'map', and leave replacement value * on stack top if mapped (and return non-zero). * Used in E5 Section 10.6 algorithm for GetOwnProperty (used by Get). */ -DUK_LOCAL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc) { +DUK_LOCAL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc) { duk_hobject *map; duk_hobject *varenv; duk_hstring *varname; @@ -1691,7 +1742,7 @@ varname = duk_require_hstring(thr, -1); DUK_ASSERT(varname != NULL); - duk_pop_unsafe(thr); /* varname is still reachable */ + duk_pop_unsafe(thr); /* varname is still reachable */ DUK_DDD(DUK_DDDPRINT("arguments object automatic getvar for a bound variable; " "key=%!O, varname=%!O", @@ -1712,7 +1763,11 @@ * Used in E5 Section 10.6 algorithm for DefineOwnProperty (used by Put). * Assumes stack top contains 'put' value (which is NOT popped). */ -DUK_LOCAL void duk__check_arguments_map_for_put(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc, duk_bool_t throw_flag) { +DUK_LOCAL void duk__check_arguments_map_for_put(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc, + duk_bool_t throw_flag) { duk_hobject *map; duk_hobject *varenv; duk_hstring *varname; @@ -1728,7 +1783,7 @@ varname = duk_require_hstring(thr, -1); DUK_ASSERT(varname != NULL); - duk_pop_unsafe(thr); /* varname is still reachable */ + duk_pop_unsafe(thr); /* varname is still reachable */ DUK_DDD(DUK_DDDPRINT("arguments object automatic putvar for a bound variable; " "key=%!O, varname=%!O, value=%!T", @@ -1767,15 +1822,14 @@ map = duk_require_hobject(thr, -1); DUK_ASSERT(map != NULL); - duk_pop_unsafe(thr); /* map is reachable through obj */ + duk_pop_unsafe(thr); /* map is reachable through obj */ - DUK_DDD(DUK_DDDPRINT("-> have 'map', delete key %!O from map (if exists)); ignore result", - (duk_heaphdr *) key)); + DUK_DDD(DUK_DDDPRINT("-> have 'map', delete key %!O from map (if exists)); ignore result", (duk_heaphdr *) key)); /* Note: no recursion issue, we can trust 'map' to behave */ DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(map)); DUK_DDD(DUK_DDDPRINT("map before deletion: %!O", (duk_heaphdr *) map)); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ DUK_DDD(DUK_DDDPRINT("map after deletion: %!O", (duk_heaphdr *) map)); } @@ -1818,14 +1872,24 @@ * accessor properties later, this would need to change. */ -DUK_LOCAL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_uint32_t arr_idx, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_LOCAL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_uint32_t arr_idx, + duk_propdesc *out_desc, + duk_small_uint_t flags) { duk_tval *tv; DUK_DDD(DUK_DDDPRINT("duk_hobject_get_own_propdesc: thr=%p, obj=%p, key=%p, out_desc=%p, flags=%lx, " "arr_idx=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) out_desc, - (long) flags, (long) arr_idx, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) out_desc, + (long) flags, + (long) arr_idx, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -1899,14 +1963,13 @@ duk_push_tval(thr, tv); } /* implicit attributes */ - out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_CONFIGURABLE | - DUK_PROPDESC_FLAG_ENUMERABLE; + out_desc->flags = + DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE | DUK_PROPDESC_FLAG_ENUMERABLE; out_desc->get = NULL; out_desc->set = NULL; out_desc->e_idx = -1; out_desc->h_idx = -1; - out_desc->a_idx = (duk_int_t) arr_idx; /* XXX: limit 2G due to being signed */ + out_desc->a_idx = (duk_int_t) arr_idx; /* XXX: limit 2G due to being signed */ goto prop_found; } } @@ -1927,7 +1990,8 @@ duk_harray *a; DUK_DDD(DUK_DDDPRINT("array object exotic property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + (duk_heaphdr *) key, + (long) arr_idx)); a = (duk_harray *) obj; DUK_HARRAY_ASSERT_VALID(a); @@ -1949,11 +2013,12 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } else if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj)) { DUK_DDD(DUK_DDDPRINT("string object exotic property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + (duk_heaphdr *) key, + (long) arr_idx)); /* XXX: charlen; avoid multiple lookups? */ @@ -1968,9 +2033,9 @@ DUK_DDD(DUK_DDDPRINT("-> found, array index inside string")); if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_push_hstring(thr, h_val); - duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ + duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ } - out_desc->flags = DUK_PROPDESC_FLAG_ENUMERABLE | /* E5 Section 15.5.5.2 */ + out_desc->flags = DUK_PROPDESC_FLAG_ENUMERABLE | /* E5 Section 15.5.5.2 */ DUK_PROPDESC_FLAG_VIRTUAL; out_desc->get = NULL; out_desc->set = NULL; @@ -1979,7 +2044,7 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } else { /* index is above internal string length -> property is fully normal */ DUK_DDD(DUK_DDDPRINT("array index outside string -> normal property")); @@ -1994,7 +2059,7 @@ if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h_val)); } - out_desc->flags = DUK_PROPDESC_FLAG_VIRTUAL; /* E5 Section 15.5.5.1 */ + out_desc->flags = DUK_PROPDESC_FLAG_VIRTUAL; /* E5 Section 15.5.5.1 */ out_desc->get = NULL; out_desc->set = NULL; out_desc->e_idx = -1; @@ -2002,7 +2067,7 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -2013,8 +2078,7 @@ h_bufobj = (duk_hbufobj *) obj; DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); - DUK_DDD(DUK_DDDPRINT("bufobj property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + DUK_DDD(DUK_DDDPRINT("bufobj property get for key: %!O, arr_idx: %ld", (duk_heaphdr *) key, (long) arr_idx)); if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { DUK_DDD(DUK_DDDPRINT("array index exists")); @@ -2023,21 +2087,22 @@ * length downshift won't. */ if (arr_idx < (h_bufobj->length >> h_bufobj->shift)) { - byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_uint8_t *data; - if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { - data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + h_bufobj->offset + byte_off; + if (h_bufobj->buf != NULL && + DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { + data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + + h_bufobj->offset + byte_off; duk_hbufobj_push_validated_read(thr, h_bufobj, data, elem_size); } else { DUK_D(DUK_DPRINT("bufobj access out of underlying buffer, ignoring (read zero)")); duk_push_uint(thr, 0); } } - out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_VIRTUAL; + out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_VIRTUAL; if (DUK_HOBJECT_GET_CLASS_NUMBER(obj) != DUK_HOBJECT_CLASS_ARRAYBUFFER) { /* ArrayBuffer indices are non-standard and are * non-enumerable to avoid their serialization. @@ -2051,7 +2116,8 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be e.g. arguments exotic, since exotic 'traits' are mutually exclusive */ + goto prop_found_noexotic; /* cannot be e.g. arguments exotic, since exotic 'traits' are mutually + exclusive */ } else { /* index is above internal buffer length -> property is fully normal */ DUK_DDD(DUK_DDDPRINT("array index outside buffer -> normal property")); @@ -2073,10 +2139,10 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Array properties have exotic behavior but they are concrete, * so no special handling here. @@ -2090,7 +2156,7 @@ * Not found as concrete or virtual. */ - prop_not_found: +prop_not_found: DUK_DDD(DUK_DDDPRINT("-> not found (virtual, entry part, or array part)")); DUK_STATS_INC(thr->heap, stats_getownpropdesc_miss); return 0; @@ -2102,7 +2168,7 @@ * description of GetOwnProperty variant for arguments. */ - prop_found: +prop_found: DUK_DDD(DUK_DDDPRINT("-> property found, checking for arguments exotic post-behavior")); /* Notes: @@ -2112,8 +2178,7 @@ * DUK_GETDESC_FLAG_PUSH_VALUE is not set. */ - if (DUK_UNLIKELY(DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && - arr_idx != DUK__NO_ARRAY_INDEX && + if (DUK_UNLIKELY(DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && arr_idx != DUK__NO_ARRAY_INDEX && (flags & DUK_GETDESC_FLAG_PUSH_VALUE))) { duk_propdesc temp_desc; @@ -2139,12 +2204,13 @@ } } - prop_found_noexotic: +prop_found_noexotic: DUK_STATS_INC(thr->heap, stats_getownpropdesc_hit); return 1; } -DUK_INTERNAL duk_bool_t duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_INTERNAL duk_bool_t +duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { DUK_ASSERT(thr != NULL); DUK_ASSERT(obj != NULL); DUK_ASSERT(key != NULL); @@ -2173,7 +2239,8 @@ * pointers. */ -DUK_LOCAL duk_bool_t duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_LOCAL duk_bool_t +duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { duk_hobject *curr; duk_uint32_t arr_idx; duk_uint_t sanity; @@ -2191,9 +2258,14 @@ DUK_DDD(DUK_DDDPRINT("duk__get_propdesc: thr=%p, obj=%p, key=%p, out_desc=%p, flags=%lx, " "arr_idx=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) out_desc, - (long) flags, (long) arr_idx, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) out_desc, + (long) flags, + (long) arr_idx, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); curr = obj; DUK_ASSERT(curr != NULL); @@ -2253,11 +2325,8 @@ DUK_UNREF(thr); - if (!(DUK_HOBJECT_HAS_ARRAY_PART(obj) && - !DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && - !DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj) && - !DUK_HOBJECT_IS_BUFOBJ(obj) && - !DUK_HOBJECT_IS_PROXY(obj))) { + if (!(DUK_HOBJECT_HAS_ARRAY_PART(obj) && !DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && !DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj) && + !DUK_HOBJECT_IS_BUFOBJ(obj) && !DUK_HOBJECT_IS_PROXY(obj))) { /* Must have array part and no conflicting exotic behaviors. * Doesn't need to have array special behavior, e.g. Arguments * object has array part. @@ -2275,7 +2344,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { DUK_DDD(DUK_DDDPRINT("key is not a number")); @@ -2309,18 +2378,19 @@ return NULL; } -DUK_LOCAL duk_bool_t duk__putprop_shallow_fastpath_array_tval(duk_hthread *thr, duk_hobject *obj, duk_tval *tv_key, duk_tval *tv_val) { +DUK_LOCAL duk_bool_t duk__putprop_shallow_fastpath_array_tval(duk_hthread *thr, + duk_hobject *obj, + duk_tval *tv_key, + duk_tval *tv_val) { duk_tval *tv; duk_harray *a; duk_uint32_t idx; duk_uint32_t old_len, new_len; - if (!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj) && - DUK_HOBJECT_HAS_ARRAY_PART(obj) && - DUK_HOBJECT_HAS_EXTENSIBLE(obj))) { + if (!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj) && DUK_HOBJECT_HAS_ARRAY_PART(obj) && DUK_HOBJECT_HAS_EXTENSIBLE(obj))) { return 0; } - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures */ a = (duk_harray *) obj; DUK_HARRAY_ASSERT_VALID(a); @@ -2330,7 +2400,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { DUK_DDD(DUK_DDDPRINT("key is not a number")); @@ -2342,7 +2412,7 @@ * because 0xffffffffUL will never be inside object 'a_size'. */ - if (idx >= DUK_HOBJECT_GET_ASIZE(obj)) { /* for resizing of array part, use slow path */ + if (idx >= DUK_HOBJECT_GET_ASIZE(obj)) { /* for resizing of array part, use slow path */ return 0; } DUK_ASSERT(idx != 0xffffffffUL); @@ -2353,7 +2423,8 @@ if (idx >= old_len) { DUK_DDD(DUK_DDDPRINT("write new array entry requires length update " "(arr_idx=%ld, old_len=%ld)", - (long) idx, (long) old_len)); + (long) idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a)) { /* The correct behavior here is either a silent error * or a TypeError, depending on strictness. Fall back @@ -2367,12 +2438,12 @@ } tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects */ DUK_DDD(DUK_DDDPRINT("array fast path success for index %ld", (long) idx)); return 1; } -#endif /* DUK_USE_ARRAY_PROP_FASTPATH */ +#endif /* DUK_USE_ARRAY_PROP_FASTPATH */ /* * Fast path for bufobj getprop/putprop @@ -2399,7 +2470,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { return 0; @@ -2416,7 +2487,7 @@ } DUK_ASSERT(idx != DUK__NO_ARRAY_INDEX); - byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { @@ -2429,7 +2500,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) DUK_LOCAL duk_bool_t duk__putprop_fastpath_bufobj_tval(duk_hthread *thr, duk_hobject *obj, duk_tval *tv_key, duk_tval *tv_val) { @@ -2439,11 +2510,10 @@ duk_small_uint_t elem_size; duk_uint8_t *data; - if (!(DUK_HOBJECT_IS_BUFOBJ(obj) && - DUK_TVAL_IS_NUMBER(tv_val))) { + if (!(DUK_HOBJECT_IS_BUFOBJ(obj) && DUK_TVAL_IS_NUMBER(tv_val))) { return 0; } - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures; rom objects are never bufobjs now */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures; rom objects are never bufobjs now */ h_bufobj = (duk_hbufobj *) obj; if (!DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { @@ -2455,7 +2525,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { return 0; @@ -2472,7 +2542,7 @@ } DUK_ASSERT(idx != DUK__NO_ARRAY_INDEX); - byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); /* Value is required to be a number in the fast path so there @@ -2491,7 +2561,7 @@ duk_pop_unsafe(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * GETPROP: ECMAScript property read. @@ -2507,8 +2577,11 @@ duk_uint_t sanity; DUK_DDD(DUK_DDDPRINT("getprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -2545,8 +2618,11 @@ #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot read property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot read property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); break; @@ -2576,7 +2652,7 @@ pop_count = 0; } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object string, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -2585,15 +2661,15 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object string, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { duk_pop_n_unsafe(thr, pop_count); duk_push_hstring(thr, h); - duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ + duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ DUK_STATS_INC(thr->heap, stats_getprop_stringidx); DUK_DDD(DUK_DDDPRINT("-> %!T (base is string, key is an index inside string length " @@ -2610,12 +2686,13 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object string, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { - duk_pop_unsafe(thr); /* key -> */ - duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); /* -> res */ + duk_pop_unsafe(thr); /* key -> */ + duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); /* -> res */ DUK_STATS_INC(thr->heap, stats_getprop_stringlen); DUK_DDD(DUK_DDDPRINT("-> %!T (base is string, key is 'length' after coercion -> " @@ -2626,7 +2703,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a string, start lookup from string prototype")); curr = thr->builtinsDUK_BIDX_STRING_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_OBJECT: { @@ -2671,9 +2748,9 @@ /* -> ... trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'get' for key %!T", (duk_tval *) tv_key)); DUK_STATS_INC(thr->heap, stats_getprop_proxy); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ - duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ + duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ duk_call_method(thr, 3 /*nargs*/); /* Target object must be checked for a conflicting @@ -2683,25 +2760,27 @@ DUK_ASSERT(key != NULL); if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { - duk_tval *tv_hook = duk_require_tval(thr, -3); /* value from hook */ - duk_tval *tv_targ = duk_require_tval(thr, -1); /* value from target */ + duk_tval *tv_hook = duk_require_tval(thr, -3); /* value from hook */ + duk_tval *tv_targ = duk_require_tval(thr, -1); /* value from target */ duk_bool_t datadesc_reject; duk_bool_t accdesc_reject; DUK_DDD(DUK_DDDPRINT("proxy 'get': target has matching property %!O, check for " "conflicting property; tv_hook=%!T, tv_targ=%!T, desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (duk_tval *) tv_hook, (duk_tval *) tv_targ, + (duk_heaphdr *) key, + (duk_tval *) tv_hook, + (duk_tval *) tv_targ, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (void *) desc.get, + (void *) desc.set)); datadesc_reject = !(desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && !(desc.flags & DUK_PROPDESC_FLAG_WRITABLE) && !duk_js_samevalue(tv_hook, tv_targ); accdesc_reject = (desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && - !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && - (desc.get == NULL) && + !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && (desc.get == NULL) && !DUK_TVAL_IS_UNDEFINED(tv_hook); if (datadesc_reject || accdesc_reject) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); @@ -2712,13 +2791,13 @@ } else { duk_pop_unsafe(thr); } - return 1; /* return value */ + return 1; /* return value */ } - curr = h_target; /* resume lookup from target */ + curr = h_target; /* resume lookup from target */ DUK_TVAL_SET_OBJECT(tv_obj, curr); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ if (DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(curr)) { arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); @@ -2733,11 +2812,11 @@ /* no need for 'caller' post-check, because 'key' must be an array index */ - duk_remove_m2(thr); /* key result -> result */ + duk_remove_m2(thr); /* key result -> result */ return 1; } - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } break; } @@ -2759,10 +2838,9 @@ arr_idx = duk__tval_fastint_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path fastint; arr_idx %ld", (long) arr_idx)); pop_count = 0; - } - else + } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -2771,12 +2849,12 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { duk_pop_n_unsafe(thr, pop_count); duk_push_uint(thr, ((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h))arr_idx); DUK_STATS_INC(thr->heap, stats_getprop_bufferidx); @@ -2794,12 +2872,13 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { - duk_pop_unsafe(thr); /* key -> */ - duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h)); /* -> res */ + duk_pop_unsafe(thr); /* key -> */ + duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h)); /* -> res */ DUK_STATS_INC(thr->heap, stats_getprop_bufferlen); DUK_DDD(DUK_DDDPRINT("-> %!T (base is buffer, key is 'length' " @@ -2810,7 +2889,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a buffer, start lookup from Uint8Array prototype")); curr = thr->builtinsDUK_BIDX_UINT8ARRAY_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_POINTER: { @@ -2847,7 +2926,7 @@ * Property lookup */ - lookup: +lookup: /* key (coerced) */ DUK_ASSERT(curr != NULL); DUK_ASSERT(key != NULL); @@ -2862,25 +2941,23 @@ /* accessor with defined getter */ DUK_ASSERT((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0); - duk_pop_unsafe(thr); /* key undefined -> key */ + duk_pop_unsafe(thr); /* key undefined -> key */ duk_push_hobject(thr, desc.get); - duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ + duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ #if defined(DUK_USE_NONSTD_GETTER_KEY_ARGUMENT) duk_dup_m3(thr); - duk_call_method(thr, 1); /* key getter this key -> key retval */ + duk_call_method(thr, 1); /* key getter this key -> key retval */ #else - duk_call_method(thr, 0); /* key getter this -> key retval */ + duk_call_method(thr, 0); /* key getter this -> key retval */ #endif } else { /* key value or key undefined */ /* data property or accessor without getter */ - DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || - (desc.get == NULL)); + DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || (desc.get == NULL)); /* if accessor without getter, return value is undefined */ - DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || - duk_is_undefined(thr, -1)); + DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || duk_is_undefined(thr, -1)); /* Note: for an accessor without getter, falling through to * check for "caller" exotic behavior is unnecessary as @@ -2889,9 +2966,9 @@ */ } - goto found; /* key result */ + goto found; /* key result */ - next_in_chain: + next_in_chain: /* XXX: option to pretend property doesn't exist if sanity limit is * hit might be useful. */ @@ -2906,7 +2983,7 @@ * Not found */ - duk_to_undefined(thr, -1); /* key -> undefined (default value) */ + duk_to_undefined(thr, -1); /* key -> undefined (default value) */ DUK_DDD(DUK_DDDPRINT("-> %!T (not found)", (duk_tval *) duk_get_tval(thr, -1))); return 0; @@ -2915,7 +2992,7 @@ * Found; post-processing (Function and arguments objects) */ - found: +found: /* key result */ #if !defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) @@ -2945,13 +3022,11 @@ * This exotic behavior is disabled when the non-standard 'caller' property * is enabled, as it conflicts with the free use of 'caller'. */ - if (key == DUK_HTHREAD_STRING_CALLER(thr) && - DUK_TVAL_IS_OBJECT(tv_obj)) { + if (key == DUK_HTHREAD_STRING_CALLER(thr) && DUK_TVAL_IS_OBJECT(tv_obj)) { duk_hobject *orig = DUK_TVAL_GET_OBJECT(tv_obj); DUK_ASSERT(orig != NULL); - if (DUK_HOBJECT_IS_NONBOUND_FUNCTION(orig) || - DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { + if (DUK_HOBJECT_IS_NONBOUND_FUNCTION(orig) || DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { duk_hobject *h; /* XXX: The TypeError is currently not applied to bound @@ -2962,19 +3037,17 @@ */ DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(orig)); - h = duk_get_hobject(thr, -1); /* NULL if not an object */ - if (h && - DUK_HOBJECT_IS_FUNCTION(h) && - DUK_HOBJECT_HAS_STRICT(h)) { + h = duk_get_hobject(thr, -1); /* NULL if not an object */ + if (h && DUK_HOBJECT_IS_FUNCTION(h) && DUK_HOBJECT_HAS_STRICT(h)) { /* XXX: sufficient to check 'strict', assert for 'is function' */ DUK_ERROR_TYPE(thr, DUK_STR_STRICT_CALLER_READ); DUK_WO_NORETURN(return 0;); } } } -#endif /* !DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ +#endif /* !DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ - duk_remove_m2(thr); /* key result -> result */ + duk_remove_m2(thr); /* key result -> result */ DUK_DDD(DUK_DDDPRINT("-> %!T (found)", (duk_tval *) duk_get_tval(thr, -1))); return 1; @@ -2996,8 +3069,11 @@ duk_propdesc desc; DUK_DDD(DUK_DDDPRINT("hasprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -3069,8 +3145,8 @@ if (duk__proxy_check_prop(thr, obj, DUK_STRIDX_HAS, tv_key, &h_target)) { /* ... key trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'has' for key %!T", (duk_tval *) tv_key)); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ duk_call_method(thr, 2 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { @@ -3078,39 +3154,42 @@ * non-configurable property. */ - if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push + value */ DUK_DDD(DUK_DDDPRINT("proxy 'has': target has matching property %!O, check for " "conflicting property; desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (duk_heaphdr *) key, + (unsigned long) desc.flags, + (void *) desc.get, + (void *) desc.set)); /* XXX: Extensibility check for target uses IsExtensible(). If we * implemented the isExtensible trap and didn't reject proxies as * proxy targets, it should be respected here. */ - if (!((desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && /* property is configurable and */ - DUK_HOBJECT_HAS_EXTENSIBLE(h_target))) { /* ... target is extensible */ + if (!((desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && /* property is configurable and */ + DUK_HOBJECT_HAS_EXTENSIBLE(h_target))) { /* ... target is extensible */ DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); } } } - duk_pop_unsafe(thr); /* key -> */ + duk_pop_unsafe(thr); /* key -> */ return tmp_bool; } - obj = h_target; /* resume check from proxy target */ + obj = h_target; /* resume check from proxy target */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* XXX: inline into a prototype walking loop? */ - rc = duk__get_propdesc(thr, obj, key, &desc, 0 /*flags*/); /* don't push value */ + rc = duk__get_propdesc(thr, obj, key, &desc, 0 /*flags*/); /* don't push value */ /* fall through */ - pop_and_return: - duk_pop_unsafe(thr); /* key -> */ +pop_and_return: + duk_pop_unsafe(thr); /* key -> */ return rc; } @@ -3136,7 +3215,7 @@ DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); - return duk__get_propdesc(thr, obj, key, &dummy, DUK_GETDESC_FLAG_IGNORE_PROTOLOOP); /* don't push value */ + return duk__get_propdesc(thr, obj, key, &dummy, DUK_GETDESC_FLAG_IGNORE_PROTOLOOP); /* don't push value */ } /* @@ -3168,16 +3247,16 @@ } return (duk_uint32_t) fi; } -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ /* When fastints are not enabled, the most interesting case is any * number. */ if (DUK_TVAL_IS_DOUBLE(tv)) { d = DUK_TVAL_GET_NUMBER(tv); } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ else -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ { /* In all other cases, and when doing a size optimized build, * fall back to the comprehensive handler. @@ -3195,7 +3274,7 @@ return res; - fail_range: +fail_range: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARRAY_LENGTH); DUK_WO_NORETURN(return 0;); } @@ -3223,7 +3302,8 @@ DUK_DDD(DUK_DDDPRINT("new array length smaller than old (%ld -> %ld), " "probably need to remove elements", - (long) old_len, (long) new_len)); + (long) old_len, + (long) new_len)); /* * New length is smaller than old length, need to delete properties above @@ -3269,7 +3349,7 @@ while (i > new_len) { i--; tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, i); - DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ } *out_result_len = new_len; @@ -3304,19 +3384,22 @@ continue; } - DUK_ASSERT(DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ + DUK_ASSERT( + DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); - DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ + DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ if (arr_idx < new_len) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is array index %ld, below new_len", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } if (DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is a relevant array index %ld, but configurable", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } @@ -3324,17 +3407,19 @@ if (arr_idx >= target_len) { DUK_DDD(DUK_DDDPRINT("entry at index %ld has arr_idx %ld, is not configurable, " "update target_len %ld -> %ld", - (long) i, (long) arr_idx, (long) target_len, + (long) i, + (long) arr_idx, + (long) target_len, (long) (arr_idx + 1))); target_len = arr_idx + 1; } } - skip_stage1: + skip_stage1: /* stage 2: delete configurable entries above target length */ - DUK_DDD(DUK_DDDPRINT("old_len=%ld, new_len=%ld, target_len=%ld", - (long) old_len, (long) new_len, (long) target_len)); + DUK_DDD( + DUK_DDDPRINT("old_len=%ld, new_len=%ld, target_len=%ld", (long) old_len, (long) new_len, (long) target_len)); DUK_DDD(DUK_DDDPRINT("array length write, no array part, stage 2: remove " "entries >= target_len")); @@ -3350,20 +3435,21 @@ continue; } - DUK_ASSERT(DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ + DUK_ASSERT( + DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); - DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ + DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ if (arr_idx < target_len) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is array index %ld, below target_len", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } - DUK_ASSERT(force_flag || DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)); /* stage 1 guarantees */ + DUK_ASSERT(force_flag || DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)); /* stage 1 guarantees */ - DUK_DDD(DUK_DDDPRINT("delete entry index %ld: key is array index %ld", - (long) i, (long) arr_idx)); + DUK_DDD(DUK_DDDPRINT("delete entry index %ld: key is array index %ld", (long) i, (long) arr_idx)); /* * Slow delete, but we don't care as we're already in a very slow path. @@ -3494,11 +3580,12 @@ * (We currently make a copy of all of the input values to avoid issues.) */ -DUK_INTERNAL duk_bool_t duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag) { +DUK_INTERNAL duk_bool_t +duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag) { duk_tval tv_obj_copy; duk_tval tv_key_copy; duk_tval tv_val_copy; - duk_hobject *orig = NULL; /* NULL if tv_obj is primitive */ + duk_hobject *orig = NULL; /* NULL if tv_obj is primitive */ duk_hobject *curr; duk_hstring *key = NULL; duk_propdesc desc; @@ -3507,12 +3594,18 @@ duk_bool_t rc; duk_int_t e_idx; duk_uint_t sanity; - duk_uint32_t new_array_length = 0; /* 0 = no update */ + duk_uint32_t new_array_length = 0; /* 0 = no update */ DUK_DDD(DUK_DDDPRINT("putprop: thr=%p, obj=%p, key=%p, val=%p, throw=%ld " "(obj -> %!T, key -> %!T, val -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, (void *) tv_val, - (long) throw_flag, (duk_tval *) tv_obj, (duk_tval *) tv_key, (duk_tval *) tv_val)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (void *) tv_val, + (long) throw_flag, + (duk_tval *) tv_obj, + (duk_tval *) tv_key, + (duk_tval *) tv_val)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -3547,13 +3640,15 @@ case DUK_TAG_UNDEFINED: case DUK_TAG_NULL: { /* Note: unconditional throw */ - DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject (object=%!iT)", - (duk_tval *) tv_obj)); + DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject (object=%!iT)", (duk_tval *) tv_obj)); #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot write property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot write property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); break; @@ -3587,14 +3682,13 @@ goto fail_not_writable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { goto fail_not_writable; } DUK_DDD(DUK_DDDPRINT("base object is a string, start lookup from string prototype")); curr = thr->builtinsDUK_BIDX_STRING_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_OBJECT: { @@ -3609,7 +3703,7 @@ */ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) orig)) { DUK_DD(DUK_DDPRINT("attempt to putprop on read-only target object")); - goto fail_not_writable_no_pop; /* Must avoid duk_pop() in exit path */ + goto fail_not_writable_no_pop; /* Must avoid duk_pop() in exit path */ } #endif @@ -3655,10 +3749,10 @@ /* -> ... trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'set' for key %!T", (duk_tval *) tv_key)); DUK_STATS_INC(thr->heap, stats_putprop_proxy); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ - duk_push_tval(thr, tv_val); /* V */ - duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ + duk_push_tval(thr, tv_val); /* V */ + duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ duk_call_method(thr, 4 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { @@ -3679,17 +3773,19 @@ DUK_DDD(DUK_DDDPRINT("proxy 'set': target has matching property %!O, check for " "conflicting property; tv_val=%!T, tv_targ=%!T, desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (duk_tval *) tv_val, (duk_tval *) tv_targ, + (duk_heaphdr *) key, + (duk_tval *) tv_val, + (duk_tval *) tv_targ, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (void *) desc.get, + (void *) desc.set)); datadesc_reject = !(desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && !(desc.flags & DUK_PROPDESC_FLAG_WRITABLE) && !duk_js_samevalue(tv_val, tv_targ); accdesc_reject = (desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && - !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && - (desc.set == NULL); + !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && (desc.set == NULL); if (datadesc_reject || accdesc_reject) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); @@ -3699,13 +3795,13 @@ } else { duk_pop_unsafe(thr); } - return 1; /* success */ + return 1; /* success */ } - orig = h_target; /* resume write to target */ + orig = h_target; /* resume write to target */ DUK_TVAL_SET_OBJECT(tv_obj, orig); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ curr = orig; break; @@ -3727,7 +3823,7 @@ pop_count = 0; } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -3736,12 +3832,12 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { duk_uint8_t *data; DUK_DDD(DUK_DDDPRINT("writing to buffer data at index %ld", (long) arr_idx)); data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); @@ -3753,8 +3849,7 @@ /* Buffer writes are often integers. */ if (DUK_TVAL_IS_FASTINT(tv_val)) { dataarr_idx = (duk_uint8_t) DUK_TVAL_GET_FASTINT_U32(tv_val); - } - else + } else #endif { duk_push_tval(thr, tv_val); @@ -3776,7 +3871,8 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { @@ -3785,7 +3881,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a buffer, start lookup from Uint8Array prototype")); curr = thr->builtinsDUK_BIDX_UINT8ARRAY_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_POINTER: { @@ -3820,7 +3916,7 @@ arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); DUK_ASSERT(key != NULL); - lookup: +lookup: /* * Check whether the property already exists in the prototype chain. @@ -3833,7 +3929,7 @@ DUK_ASSERT(curr != NULL); sanity = DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY; do { - if (!duk__get_own_propdesc_raw(thr, curr, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (!duk__get_own_propdesc_raw(thr, curr, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ goto next_in_chain; } @@ -3856,15 +3952,15 @@ goto fail_no_setter; } duk_push_hobject(thr, setter); - duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ - duk_push_tval(thr, tv_val); /* key setter this val */ + duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ + duk_push_tval(thr, tv_val); /* key setter this val */ #if defined(DUK_USE_NONSTD_SETTER_KEY_ARGUMENT) duk_dup_m4(thr); - duk_call_method(thr, 2); /* key setter this val key -> key retval */ + duk_call_method(thr, 2); /* key setter this val key -> key retval */ #else - duk_call_method(thr, 1); /* key setter this val -> key retval */ + duk_call_method(thr, 1); /* key setter this val -> key retval */ #endif - duk_pop_unsafe(thr); /* ignore retval -> key */ + duk_pop_unsafe(thr); /* ignore retval -> key */ goto success_no_arguments_exotic; } @@ -3884,11 +3980,13 @@ * new property to 'orig'. */ if (!DUK_HOBJECT_HAS_EXTENSIBLE(orig)) { - DUK_DD(DUK_DDPRINT("found existing inherited plain property, but original object is not extensible")); + DUK_DD( + DUK_DDPRINT("found existing inherited plain property, but original object is not extensible")); goto fail_not_extensible; } if (!(desc.flags & DUK_PROPDESC_FLAG_WRITABLE)) { - DUK_DD(DUK_DDPRINT("found existing inherited plain property, original object is extensible, but inherited property is not writable")); + DUK_DD(DUK_DDPRINT("found existing inherited plain property, original object is extensible, but " + "inherited property is not writable")); goto fail_not_writable; } DUK_DD(DUK_DDPRINT("put to new property, object extensible, inherited property found and is writable")); @@ -3900,7 +3998,8 @@ */ if (!(desc.flags & DUK_PROPDESC_FLAG_WRITABLE)) { - DUK_DD(DUK_DDPRINT("found existing own (non-inherited) plain property, but property is not writable")); + DUK_DD( + DUK_DDPRINT("found existing own (non-inherited) plain property, but property is not writable")); goto fail_not_writable; } if (desc.flags & DUK_PROPDESC_FLAG_VIRTUAL) { @@ -3917,18 +4016,19 @@ * Note: the helper has an unnecessary writability check * for 'length', we already know it is writable. */ - DUK_ASSERT(key == DUK_HTHREAD_STRING_LENGTH(thr)); /* only virtual array property */ + DUK_ASSERT(key == DUK_HTHREAD_STRING_LENGTH(thr)); /* only virtual array property */ - DUK_DDD(DUK_DDDPRINT("writing existing 'length' property to array exotic, invoke complex helper")); + DUK_DDD(DUK_DDDPRINT( + "writing existing 'length' property to array exotic, invoke complex helper")); /* XXX: the helper currently assumes stack top contains new * 'length' value and the whole calling convention is not very * compatible with what we need. */ - duk_push_tval(thr, tv_val); /* key val */ + duk_push_tval(thr, tv_val); /* key val */ rc = duk__handle_put_array_length(thr, orig); - duk_pop_unsafe(thr); /* key val -> key */ + duk_pop_unsafe(thr); /* key val -> key */ if (!rc) { goto fail_array_length_partial; } @@ -3950,12 +4050,14 @@ /* Careful with wrapping: arr_idx upshift may easily wrap, whereas * length downshift won't. */ - if (arr_idx < (h_bufobj->length >> h_bufobj->shift) && DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { + if (arr_idx < (h_bufobj->length >> h_bufobj->shift) && + DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { duk_uint8_t *data; DUK_DDD(DUK_DDDPRINT("writing to buffer data at index %ld", (long) arr_idx)); - DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); /* index/length check guarantees */ - byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); /* index/length check guarantees */ + byte_off = arr_idx + << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); /* Coerce to number before validating pointers etc so that the @@ -3966,27 +4068,30 @@ duk_push_tval(thr, tv_val); (void) duk_to_number_m1(thr); - if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { - data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + h_bufobj->offset + byte_off; + if (h_bufobj->buf != NULL && + DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { + data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + + h_bufobj->offset + byte_off; duk_hbufobj_validated_write(thr, h_bufobj, data, elem_size); } else { - DUK_D(DUK_DPRINT("bufobj access out of underlying buffer, ignoring (write skipped)")); + DUK_D(DUK_DPRINT( + "bufobj access out of underlying buffer, ignoring (write skipped)")); } duk_pop_unsafe(thr); goto success_no_arguments_exotic; } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_D(DUK_DPRINT("should not happen, key %!O", key)); - goto fail_internal; /* should not happen */ + goto fail_internal; /* should not happen */ } DUK_DD(DUK_DDPRINT("put to existing own plain property, property is writable")); goto update_old; } DUK_UNREACHABLE(); - next_in_chain: + next_in_chain: /* XXX: option to pretend property doesn't exist if sanity limit is * hit might be useful. */ @@ -4015,7 +4120,7 @@ goto create_new; - update_old: +update_old: /* * Update an existing property of the base object. @@ -4048,10 +4153,9 @@ if (desc.e_idx >= 0) { tv = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, orig, desc.e_idx); DUK_DDD(DUK_DDDPRINT("previous entry value: %!iT", (duk_tval *) tv)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; e_idx may be invalidated */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; e_idx may be invalidated */ /* don't touch property attributes or hash part */ - DUK_DD(DUK_DDPRINT("put to an existing entry at index %ld -> new value %!iT", - (long) desc.e_idx, (duk_tval *) tv)); + DUK_DD(DUK_DDPRINT("put to an existing entry at index %ld -> new value %!iT", (long) desc.e_idx, (duk_tval *) tv)); } else { /* Note: array entries are always writable, so the writability check * above is pointless for them. The check could be avoided with some @@ -4061,9 +4165,10 @@ DUK_ASSERT(desc.a_idx >= 0); tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, orig, desc.a_idx); DUK_DDD(DUK_DDDPRINT("previous array value: %!iT", (duk_tval *) tv)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; a_idx may be invalidated */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; a_idx may be invalidated */ DUK_DD(DUK_DDPRINT("put to an existing array entry at index %ld -> new value %!iT", - (long) desc.a_idx, (duk_tval *) tv)); + (long) desc.a_idx, + (duk_tval *) tv)); } /* Regardless of whether property is found in entry or array part, @@ -4072,7 +4177,7 @@ */ goto success_with_arguments_exotic; - create_new: +create_new: /* * Create a new property in the original object. @@ -4105,11 +4210,9 @@ * from its creation and cannot be deleted, and is thus * caught as an existing property above. */ - DUK_ASSERT(!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && - key == DUK_HTHREAD_STRING_LENGTH(thr))); + DUK_ASSERT(!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && key == DUK_HTHREAD_STRING_LENGTH(thr))); - if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && - arr_idx != DUK__NO_ARRAY_INDEX) { + if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && arr_idx != DUK__NO_ARRAY_INDEX) { /* automatic length update */ duk_uint32_t old_len; duk_harray *a; @@ -4122,7 +4225,8 @@ if (arr_idx >= old_len) { DUK_DDD(DUK_DDDPRINT("write new array entry requires length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a)) { DUK_DD(DUK_DDPRINT("attempt to extend array, but array 'length' is not writable")); @@ -4136,15 +4240,16 @@ */ DUK_ASSERT(arr_idx != 0xffffffffUL); - new_array_length = arr_idx + 1; /* flag for later write */ + new_array_length = arr_idx + 1; /* flag for later write */ } else { DUK_DDD(DUK_DDDPRINT("write new array entry does not require length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); } } - /* write_to_array_part: */ + /* write_to_array_part: */ /* * Write to array part? @@ -4166,8 +4271,7 @@ DUK_ASSERT(DUK_TVAL_IS_UNUSED(tv)); DUK_TVAL_SET_TVAL(tv, tv_val); DUK_TVAL_INCREF(thr, tv); - DUK_DD(DUK_DDPRINT("put to new array entry: %ld -> %!T", - (long) arr_idx, (duk_tval *) tv)); + DUK_DD(DUK_DDPRINT("put to new array entry: %ld -> %!T", (long) arr_idx, (duk_tval *) tv)); /* Note: array part values are Writable, Enumerable, * and Configurable which matches the required attributes @@ -4176,7 +4280,7 @@ goto entry_updated; } - write_to_entry_part: +write_to_entry_part: /* * Write to entry part @@ -4196,7 +4300,7 @@ DUK_HOBJECT_E_SET_FLAGS(thr->heap, orig, e_idx, DUK_PROPDESC_FLAGS_WEC); goto entry_updated; - entry_updated: +entry_updated: /* * Possible pending array length update, which must only be done @@ -4210,8 +4314,7 @@ DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig)); - DUK_DDD(DUK_DDDPRINT("write successful, pending array length update to: %ld", - (long) new_array_length)); + DUK_DDD(DUK_DDDPRINT("write successful, pending array length update to: %ld", (long) new_array_length)); ((duk_harray *) orig)->length = new_array_length; } @@ -4225,7 +4328,7 @@ goto success_no_arguments_exotic; - success_with_arguments_exotic: +success_with_arguments_exotic: /* * Arguments objects have exotic DefineOwnProperty which updates @@ -4240,8 +4343,7 @@ * we end up in step 5.b.i. */ - if (arr_idx != DUK__NO_ARRAY_INDEX && - DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { /* Note: only numbered indices are relevant, so arr_idx fast reject * is good (this is valid unless there are more than 4**32-1 arguments). */ @@ -4260,14 +4362,14 @@ } /* fall thru */ - success_no_arguments_exotic: +success_no_arguments_exotic: /* shared exit path now */ DUK_DDD(DUK_DDDPRINT("result: success")); - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 1; #if defined(DUK_USE_ES6_PROXY) - fail_proxy_rejected: +fail_proxy_rejected: DUK_DDD(DUK_DDDPRINT("result: error, proxy rejects")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); @@ -4277,40 +4379,43 @@ return 0; #endif - fail_base_primitive: +fail_base_primitive: DUK_DDD(DUK_DDDPRINT("result: error, base primitive")); if (throw_flag) { #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot write property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot write property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_not_extensible: +fail_not_extensible: DUK_DDD(DUK_DDDPRINT("result: error, not extensible")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_EXTENSIBLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_not_writable: +fail_not_writable: DUK_DDD(DUK_DDDPRINT("result: error, not writable")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_WRITABLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; #if defined(DUK_USE_ROM_OBJECTS) - fail_not_writable_no_pop: +fail_not_writable_no_pop: DUK_DDD(DUK_DDDPRINT("result: error, not writable")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_WRITABLE); @@ -4319,31 +4424,31 @@ return 0; #endif - fail_array_length_partial: +fail_array_length_partial: DUK_DD(DUK_DDPRINT("result: error, array length write only partially successful")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_no_setter: +fail_no_setter: DUK_DDD(DUK_DDDPRINT("result: error, accessor property without setter")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_SETTER_UNDEFINED); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_internal: +fail_internal: DUK_DDD(DUK_DDDPRINT("result: error, internal")); if (throw_flag) { DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; } @@ -4362,8 +4467,13 @@ force_flag = (flags & DUK_DELPROP_FLAG_FORCE); DUK_DDD(DUK_DDDPRINT("delprop_raw: thr=%p, obj=%p, key=%p, throw=%ld, force=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (long) throw_flag, (long) force_flag, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (long) throw_flag, + (long) force_flag, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -4375,7 +4485,7 @@ arr_idx = DUK_HSTRING_GET_ARRIDX_FAST(key); /* 0 = don't push current value */ - if (!duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (!duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ DUK_DDD(DUK_DDDPRINT("property not found, succeed always")); goto success; } @@ -4402,7 +4512,7 @@ DUK_ASSERT(desc.e_idx < 0); tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, desc.a_idx); - DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ goto success; } else { DUK_ASSERT(desc.a_idx < 0); @@ -4428,7 +4538,9 @@ * invalidated. */ DUK_DDD(DUK_DDDPRINT("before removing value, e_idx %ld, key %p, key at slot %p", - (long) desc.e_idx, (void *) key, (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); + (long) desc.e_idx, + (void *) key, + (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); DUK_DDD(DUK_DDDPRINT("removing value at e_idx %ld", (long) desc.e_idx)); if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, desc.e_idx)) { duk_hobject *tmp; @@ -4453,7 +4565,9 @@ /* Remove key. */ DUK_DDD(DUK_DDDPRINT("before removing key, e_idx %ld, key %p, key at slot %p", - (long) desc.e_idx, (void *) key, (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); + (long) desc.e_idx, + (void *) key, + (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); DUK_DDD(DUK_DDDPRINT("removing key at e_idx %ld", (long) desc.e_idx)); DUK_ASSERT(key == DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx)); DUK_HOBJECT_E_SET_KEY(thr->heap, obj, desc.e_idx, NULL); @@ -4469,7 +4583,7 @@ DUK_UNREACHABLE(); - success: +success: /* * Argument exotic Delete behavior (E5 Section 10.6) is * a post-check, keeping arguments internal 'map' in sync with @@ -4496,8 +4610,8 @@ DUK_DDD(DUK_DDDPRINT("delete successful")); return 1; - fail_virtual: /* just use the same "not configurable" error message */ - fail_not_configurable: +fail_virtual: /* just use the same "not configurable" error message */ +fail_not_configurable: DUK_DDD(DUK_DDDPRINT("delete failed: property found, not configurable")); if (throw_flag) { @@ -4521,8 +4635,11 @@ duk_bool_t rc; DUK_DDD(DUK_DDDPRINT("delprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -4536,8 +4653,7 @@ */ entry_top = duk_get_top(thr); - if (DUK_TVAL_IS_UNDEFINED(tv_obj) || - DUK_TVAL_IS_NULL(tv_obj)) { + if (DUK_TVAL_IS_UNDEFINED(tv_obj) || DUK_TVAL_IS_NULL(tv_obj)) { DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject")); goto fail_invalid_base_uncond; } @@ -4560,12 +4676,12 @@ if (duk__proxy_check_prop(thr, obj, DUK_STRIDX_DELETE_PROPERTY, tv_key, &h_target)) { /* -> ... obj key trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'deleteProperty' for key %!T", (duk_tval *) tv_key)); - duk_push_hobject(thr, h_target); /* target */ - duk_dup_m4(thr); /* P */ + duk_push_hobject(thr, h_target); /* target */ + duk_dup_m4(thr); /* P */ duk_call_method(thr, 2 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { - goto fail_proxy_rejected; /* retval indicates delete failed */ + goto fail_proxy_rejected; /* retval indicates delete failed */ } /* Target object must be checked for a conflicting @@ -4575,14 +4691,17 @@ arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); DUK_ASSERT(key != NULL); - if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push + value */ duk_small_int_t desc_reject; DUK_DDD(DUK_DDDPRINT("proxy 'deleteProperty': target has matching property %!O, check for " "conflicting property; desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (duk_heaphdr *) key, + (unsigned long) desc.flags, + (void *) desc.get, + (void *) desc.set)); desc_reject = !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE); if (desc_reject) { @@ -4591,13 +4710,13 @@ DUK_WO_NORETURN(return 0;); } } - rc = 1; /* success */ + rc = 1; /* success */ goto done_rc; } - obj = h_target; /* resume delete to target */ + obj = h_target; /* resume delete to target */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ arr_idx = duk__to_property_key(thr, -1, &key); DUK_ASSERT(key != NULL); @@ -4622,8 +4741,7 @@ goto fail_not_configurable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { goto fail_not_configurable; } } else if (DUK_TVAL_IS_BUFFER(tv_obj)) { @@ -4641,8 +4759,7 @@ goto fail_not_configurable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { goto fail_not_configurable; } } else if (DUK_TVAL_IS_LIGHTFUNC(tv_obj)) { @@ -4659,23 +4776,26 @@ rc = 1; goto done_rc; - done_rc: +done_rc: duk_set_top_unsafe(thr, entry_top); return rc; - fail_invalid_base_uncond: +fail_invalid_base_uncond: /* Note: unconditional throw */ DUK_ASSERT(duk_get_top(thr) == entry_top); #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot delete property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot delete property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); #if defined(DUK_USE_ES6_PROXY) - fail_proxy_rejected: +fail_proxy_rejected: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); @@ -4684,7 +4804,7 @@ return 0; #endif - fail_not_configurable: +fail_not_configurable: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); @@ -4712,17 +4832,23 @@ * operations. */ -DUK_INTERNAL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags) { +DUK_INTERNAL void duk_hobject_define_property_internal(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_small_uint_t flags) { duk_propdesc desc; duk_uint32_t arr_idx; duk_int_t e_idx; duk_tval *tv1 = NULL; duk_tval *tv2 = NULL; - duk_small_uint_t propflags = flags & DUK_PROPDESC_FLAGS_MASK; /* mask out flags not actually stored */ + duk_small_uint_t propflags = flags & DUK_PROPDESC_FLAGS_MASK; /* mask out flags not actually stored */ DUK_DDD(DUK_DDDPRINT("define new property (internal): thr=%p, obj=%!O, key=%!O, flags=0x%02lx, val=%!T", - (void *) thr, (duk_heaphdr *) obj, (duk_heaphdr *) key, - (unsigned long) flags, (duk_tval *) duk_get_tval(thr, -1))); + (void *) thr, + (duk_heaphdr *) obj, + (duk_heaphdr *) key, + (unsigned long) flags, + (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -4730,11 +4856,11 @@ DUK_ASSERT(key != NULL); DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); - DUK_ASSERT(duk_is_valid_index(thr, -1)); /* contains value */ + DUK_ASSERT(duk_is_valid_index(thr, -1)); /* contains value */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); - if (duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ if (desc.e_idx >= 0) { if (flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) { DUK_DDD(DUK_DDDPRINT("property already exists in the entry part -> skip as requested")); @@ -4775,7 +4901,8 @@ new_len = duk__to_new_array_length_checked(thr, DUK_GET_TVAL_NEGIDX(thr, -1)); ((duk_harray *) obj)->length = new_len; DUK_DD(DUK_DDPRINT("internal define property for array .length: %ld -> %ld", - (long) prev_len, (long) ((duk_harray *) obj)->length)); + (long) prev_len, + (long) ((duk_harray *) obj)->length)); goto pop_exit; } DUK_DD(DUK_DDPRINT("property already exists but is virtual -> failure")); @@ -4787,7 +4914,8 @@ if (DUK_HOBJECT_HAS_ARRAY_PART(obj)) { if (arr_idx != DUK__NO_ARRAY_INDEX) { - DUK_DDD(DUK_DDDPRINT("property does not exist, object has array part -> possibly extend array part and write value (assert attributes)")); + DUK_DDD(DUK_DDDPRINT("property does not exist, object has array part -> possibly extend array part and " + "write value (assert attributes)")); DUK_ASSERT(propflags == DUK_PROPDESC_FLAGS_WEC); tv1 = duk__obtain_arridx_slot(thr, arr_idx, obj); @@ -4801,9 +4929,10 @@ } } - write_to_entry_part: - DUK_DDD(DUK_DDDPRINT("property does not exist, object belongs in entry part -> allocate new entry and write value and attributes")); - e_idx = duk__hobject_alloc_entry_checked(thr, obj, key); /* increases key refcount */ +write_to_entry_part: + DUK_DDD(DUK_DDDPRINT( + "property does not exist, object belongs in entry part -> allocate new entry and write value and attributes")); + e_idx = duk__hobject_alloc_entry_checked(thr, obj, key); /* increases key refcount */ DUK_ASSERT(e_idx >= 0); DUK_HOBJECT_E_SET_FLAGS(thr->heap, obj, e_idx, propflags); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, e_idx); @@ -4811,22 +4940,21 @@ DUK_TVAL_SET_UNDEFINED(tv1); goto write_value; - write_value: +write_value: /* tv1 points to value storage */ - tv2 = duk_require_tval(thr, -1); /* late lookup, avoid side effects */ - DUK_DDD(DUK_DDDPRINT("writing/updating value: %!T -> %!T", - (duk_tval *) tv1, (duk_tval *) tv2)); + tv2 = duk_require_tval(thr, -1); /* late lookup, avoid side effects */ + DUK_DDD(DUK_DDDPRINT("writing/updating value: %!T -> %!T", (duk_tval *) tv1, (duk_tval *) tv2)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ goto pop_exit; - pop_exit: - duk_pop_unsafe(thr); /* remove in_val */ +pop_exit: + duk_pop_unsafe(thr); /* remove in_val */ return; - error_virtual: /* share error message */ - error_internal: +error_virtual: /* share error message */ +error_internal: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); } @@ -4837,13 +4965,19 @@ * must avoid interning. */ -DUK_INTERNAL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, duk_hobject *obj, duk_uarridx_t arr_idx, duk_small_uint_t flags) { +DUK_INTERNAL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, + duk_hobject *obj, + duk_uarridx_t arr_idx, + duk_small_uint_t flags) { duk_hstring *key; duk_tval *tv1, *tv2; DUK_DDD(DUK_DDDPRINT("define new property (internal) arr_idx fast path: thr=%p, obj=%!O, " "arr_idx=%ld, flags=0x%02lx, val=%!T", - (void *) thr, obj, (long) arr_idx, (unsigned long) flags, + (void *) thr, + obj, + (long) arr_idx, + (unsigned long) flags, (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(thr != NULL); @@ -4851,10 +4985,8 @@ DUK_ASSERT(obj != NULL); DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); - if (DUK_HOBJECT_HAS_ARRAY_PART(obj) && - arr_idx != DUK__NO_ARRAY_INDEX && - flags == DUK_PROPDESC_FLAGS_WEC) { - DUK_ASSERT((flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) == 0); /* covered by comparison */ + if (DUK_HOBJECT_HAS_ARRAY_PART(obj) && arr_idx != DUK__NO_ARRAY_INDEX && flags == DUK_PROPDESC_FLAGS_WEC) { + DUK_ASSERT((flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) == 0); /* covered by comparison */ DUK_DDD(DUK_DDDPRINT("define property to array part (property may or may not exist yet)")); @@ -4865,22 +4997,22 @@ } tv2 = duk_require_tval(thr, -1); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ - duk_pop_unsafe(thr); /* ...val -> ... */ + duk_pop_unsafe(thr); /* ...val -> ... */ return; } - write_slow: +write_slow: DUK_DDD(DUK_DDDPRINT("define property fast path didn't work, use slow path")); key = duk_push_uint_to_hstring(thr, (duk_uint_t) arr_idx); DUK_ASSERT(key != NULL); - duk_insert(thr, -2); /* ... val key -> ... key val */ + duk_insert(thr, -2); /* ... val key -> ... key val */ duk_hobject_define_property_internal(thr, obj, key, flags); - duk_pop_unsafe(thr); /* ... key -> ... */ + duk_pop_unsafe(thr); /* ... key -> ... */ } /* @@ -4901,9 +5033,7 @@ /* Slow path, .length can be e.g. accessor, obj can be a Proxy, etc. */ duk_push_hobject(thr, obj); duk_push_hstring_stridx(thr, DUK_STRIDX_LENGTH); - (void) duk_hobject_getprop(thr, - DUK_GET_TVAL_NEGIDX(thr, -2), - DUK_GET_TVAL_NEGIDX(thr, -1)); + (void) duk_hobject_getprop(thr, DUK_GET_TVAL_NEGIDX(thr, -2), DUK_GET_TVAL_NEGIDX(thr, -1)); val = duk_to_number_m1(thr); duk_pop_3_unsafe(thr); @@ -4944,7 +5074,7 @@ DUK_ASSERT(heap != NULL); obj = DUK_HOBJECT_GET_PROTOTYPE(heap, obj); #else - obj = DUK_HOBJECT_GET_PROTOTYPE(NULL, obj); /* 'heap' arg ignored */ + obj = DUK_HOBJECT_GET_PROTOTYPE(NULL, obj); /* 'heap' arg ignored */ #endif } while (obj != NULL); @@ -5011,7 +5141,7 @@ /* ... key value desc */ duk_replace(thr, -3); - duk_pop_unsafe(thr); /* -> ... desc */ + duk_pop_unsafe(thr); /* -> ... desc */ } /* @@ -5048,7 +5178,7 @@ DUK_ASSERT(out_idx_value != NULL); DUK_ASSERT(out_getter != NULL); DUK_ASSERT(out_setter != NULL); - DUK_ASSERT(idx_in <= 0x7fffL); /* short variants would be OK, but not used to avoid shifts */ + DUK_ASSERT(idx_in <= 0x7fffL); /* short variants would be OK, but not used to avoid shifts */ /* Must be an object, otherwise TypeError (E5.1 Section 8.10.5, step 1). */ idx_in = duk_require_normalize_index(thr, idx_in); @@ -5104,7 +5234,7 @@ if (DUK_TVAL_IS_UNDEFINED(tv)) { /* undefined is accepted */ DUK_ASSERT(setter == NULL); - } else { + } else { /* NOTE: lightfuncs are coerced to full functions because * lightfuncs don't fit into a property value slot. This * has some side effects, see test-dev-lightfunc-accessor.js. @@ -5147,7 +5277,7 @@ /* ... multiple values */ return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_DESCRIPTOR); DUK_WO_NORETURN(return;); } @@ -5195,7 +5325,7 @@ duk_bool_t force_flag; duk_small_uint_t new_flags; duk_propdesc curr; - duk_uint32_t arridx_new_array_length; /* != 0 => post-update for array 'length' (used when key is an array index) */ + duk_uint32_t arridx_new_array_length; /* != 0 => post-update for array 'length' (used when key is an array index) */ duk_uint32_t arrlen_old_len; duk_uint32_t arrlen_new_len; duk_bool_t pending_write_protect; @@ -5235,13 +5365,22 @@ "has_get=%ld get=%p=%!O " "has_set=%ld set=%p=%!O " "arr_idx=%ld throw_flag=!%ld", - (long) has_enumerable, (long) is_enumerable, - (long) has_configurable, (long) is_configurable, - (long) has_writable, (long) is_writable, - (long) has_value, (duk_tval *) (idx_value >= 0 ? duk_get_tval(thr, idx_value) : NULL), - (long) has_get, (void *) get, (duk_heaphdr *) get, - (long) has_set, (void *) set, (duk_heaphdr *) set, - (long) arr_idx, (long) throw_flag)); + (long) has_enumerable, + (long) is_enumerable, + (long) has_configurable, + (long) is_configurable, + (long) has_writable, + (long) is_writable, + (long) has_value, + (duk_tval *) (idx_value >= 0 ? duk_get_tval(thr, idx_value) : NULL), + (long) has_get, + (void *) get, + (duk_heaphdr *) get, + (long) has_set, + (void *) set, + (duk_heaphdr *) set, + (long) arr_idx, + (long) throw_flag)); /* * Array exotic behaviors can be implemented at this point. The local variables @@ -5275,7 +5414,7 @@ DUK_ASSERT(idx_value >= 0); arrlen_new_len = duk__to_new_array_length_checked(thr, DUK_GET_TVAL_POSIDX(thr, idx_value)); duk_push_u32(thr, arrlen_new_len); - duk_replace(thr, idx_value); /* step 3.e: replace 'Desc.Value' */ + duk_replace(thr, idx_value); /* step 3.e: replace 'Desc.Value' */ DUK_DDD(DUK_DDDPRINT("old_len=%ld, new_len=%ld", (long) arrlen_old_len, (long) arrlen_new_len)); @@ -5317,7 +5456,8 @@ if (arr_idx >= old_len) { DUK_DDD(DUK_DDDPRINT("defineProperty requires array length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a) && !force_flag) { /* Array .length is always non-configurable, so @@ -5335,10 +5475,11 @@ } else { DUK_DDD(DUK_DDDPRINT("defineProperty does not require length update " "(arr_idx=%ld, old_len=%ld) -> standard behavior", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); } } - skip_array_exotic: +skip_array_exotic: /* XXX: There is currently no support for writing buffer object * indexed elements here. Attempt to do so will succeed and @@ -5390,7 +5531,7 @@ DUK_ASSERT(!has_value); DUK_ASSERT(!has_writable); - new_flags = DUK_PROPDESC_FLAG_ACCESSOR; /* defaults, E5 Section 8.6.1, Table 7 */ + new_flags = DUK_PROPDESC_FLAG_ACCESSOR; /* defaults, E5 Section 8.6.1, Table 7 */ if (has_enumerable && is_enumerable) { new_flags |= DUK_PROPDESC_FLAG_ENUMERABLE; } @@ -5423,7 +5564,7 @@ DUK_ASSERT(!has_set); DUK_ASSERT(!has_get); - new_flags = 0; /* defaults, E5 Section 8.6.1, Table 7 */ + new_flags = 0; /* defaults, E5 Section 8.6.1, Table 7 */ if (has_writable && is_writable) { new_flags |= DUK_PROPDESC_FLAG_WRITABLE; } @@ -5437,12 +5578,13 @@ duk_tval *tv_tmp = duk_require_tval(thr, idx_value); DUK_TVAL_SET_TVAL(&tv, tv_tmp); } else { - DUK_TVAL_SET_UNDEFINED(&tv); /* default value */ + DUK_TVAL_SET_UNDEFINED(&tv); /* default value */ } if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HOBJECT_HAS_ARRAY_PART(obj)) { if (new_flags == DUK_PROPDESC_FLAGS_WEC) { - DUK_DDD(DUK_DDDPRINT("new data property attributes match array defaults, attempt to write to array part")); + DUK_DDD(DUK_DDDPRINT( + "new data property attributes match array defaults, attempt to write to array part")); tv2 = duk__obtain_arridx_slot(thr, arr_idx, obj); if (tv2 == NULL) { DUK_DDD(DUK_DDDPRINT("failed writing to array part, abandoned array")); @@ -5515,8 +5657,8 @@ goto need_check; } - tmp1 = duk_require_tval(thr, -1); /* curr value */ - tmp2 = duk_require_tval(thr, idx_value); /* new value */ + tmp1 = duk_require_tval(thr, -1); /* curr value */ + tmp2 = duk_require_tval(thr, idx_value); /* new value */ if (!duk_js_samevalue(tmp1, tmp2)) { goto need_check; } @@ -5561,7 +5703,7 @@ */ goto success_no_exotics; - need_check: +need_check: /* * Some change(s) need to be made. Steps 7-11. @@ -5633,9 +5775,10 @@ DUK_DDD(DUK_DDDPRINT("convert property to accessor property")); if (curr.a_idx >= 0) { - DUK_DDD(DUK_DDDPRINT("property to convert is stored in an array entry, abandon array and re-lookup")); + DUK_DDD( + DUK_DDDPRINT("property to convert is stored in an array entry, abandon array and re-lookup")); duk__abandon_array_part(thr, obj); - duk_pop_unsafe(thr); /* remove old value */ + duk_pop_unsafe(thr); /* remove old value */ rc = duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &curr, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); DUK_ASSERT(rc != 0); @@ -5643,14 +5786,14 @@ } if (curr.e_idx < 0) { DUK_ASSERT(curr.a_idx < 0 && curr.e_idx < 0); - goto fail_virtual; /* safeguard for virtual property */ + goto fail_virtual; /* safeguard for virtual property */ } DUK_ASSERT(curr.e_idx >= 0); DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, curr.e_idx)); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, curr.e_idx); - DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ(thr, tv1); /* XXX: just decref */ + DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ(thr, tv1); /* XXX: just decref */ DUK_HOBJECT_E_SET_VALUE_GETTER(thr->heap, obj, curr.e_idx, NULL); DUK_HOBJECT_E_SET_VALUE_SETTER(thr->heap, obj, curr.e_idx, NULL); @@ -5679,7 +5822,7 @@ /* curr is accessor -> cannot be in array part. */ DUK_ASSERT(curr.a_idx < 0); if (curr.e_idx < 0) { - goto fail_virtual; /* safeguard; no virtual accessors now */ + goto fail_virtual; /* safeguard; no virtual accessors now */ } DUK_DDD(DUK_DDDPRINT("convert property to data property")); @@ -5711,8 +5854,8 @@ } /* Note: changing from writable to non-writable is OK */ if (!(curr.flags & DUK_PROPDESC_FLAG_WRITABLE) && has_value) { - duk_tval *tmp1 = duk_require_tval(thr, -1); /* curr value */ - duk_tval *tmp2 = duk_require_tval(thr, idx_value); /* new value */ + duk_tval *tmp1 = duk_require_tval(thr, -1); /* curr value */ + duk_tval *tmp2 = duk_require_tval(thr, idx_value); /* new value */ if (!duk_js_samevalue(tmp1, tmp2)) { goto fail_not_configurable; } @@ -5761,8 +5904,7 @@ /* XXX: write protect after flag? -> any chance of handling it here? */ - DUK_DDD(DUK_DDDPRINT("new flags that we want to write: 0x%02lx", - (unsigned long) new_flags)); + DUK_DDD(DUK_DDDPRINT("new flags that we want to write: 0x%02lx", (unsigned long) new_flags)); /* * Check whether we need to abandon an array part (if it exists) @@ -5778,20 +5920,23 @@ DUK_DDD(DUK_DDDPRINT("array index, new property attributes match array defaults, update in-place")); - DUK_ASSERT(curr.flags == DUK_PROPDESC_FLAGS_WEC); /* must have been, since in array part */ + DUK_ASSERT(curr.flags == DUK_PROPDESC_FLAGS_WEC); /* must have been, since in array part */ DUK_ASSERT(!has_set); DUK_ASSERT(!has_get); - DUK_ASSERT(idx_value >= 0); /* must be: if attributes match and we get here the value must differ (otherwise no change) */ + DUK_ASSERT( + idx_value >= + 0); /* must be: if attributes match and we get here the value must differ (otherwise no change) */ tv2 = duk_require_tval(thr, idx_value); tv1 = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, curr.a_idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate a_idx */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate a_idx */ goto success_exotics; } - DUK_DDD(DUK_DDDPRINT("array index, new property attributes do not match array defaults, abandon array and re-lookup")); + DUK_DDD( + DUK_DDDPRINT("array index, new property attributes do not match array defaults, abandon array and re-lookup")); duk__abandon_array_part(thr, obj); - duk_pop_unsafe(thr); /* remove old value */ + duk_pop_unsafe(thr); /* remove old value */ rc = duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &curr, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); DUK_ASSERT(rc != 0); @@ -5815,10 +5960,12 @@ if (key == DUK_HTHREAD_STRING_LENGTH(thr) && DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)) { duk_harray *a; a = (duk_harray *) obj; - DUK_DD(DUK_DDPRINT("Object.defineProperty() attribute update for duk_harray .length -> %02lx", (unsigned long) new_flags)); + DUK_DD(DUK_DDPRINT("Object.defineProperty() attribute update for duk_harray .length -> %02lx", + (unsigned long) new_flags)); DUK_HARRAY_ASSERT_VALID(a); if ((new_flags & DUK_PROPDESC_FLAGS_EC) != (curr.flags & DUK_PROPDESC_FLAGS_EC)) { - DUK_D(DUK_DPRINT("Object.defineProperty() attempt to change virtual array .length enumerable or configurable attribute, fail")); + DUK_D(DUK_DPRINT("Object.defineProperty() attempt to change virtual array .length enumerable or " + "configurable attribute, fail")); goto fail_virtual; } if (new_flags & DUK_PROPDESC_FLAG_WRITABLE) { @@ -5846,7 +5993,7 @@ DUK_UNREF(tmp); DUK_HOBJECT_E_SET_VALUE_SETTER(thr->heap, obj, curr.e_idx, set); DUK_HOBJECT_INCREF_ALLOWNULL(thr, set); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ } if (has_get) { duk_hobject *tmp; @@ -5862,7 +6009,7 @@ DUK_UNREF(tmp); DUK_HOBJECT_E_SET_VALUE_GETTER(thr->heap, obj, curr.e_idx, get); DUK_HOBJECT_INCREF_ALLOWNULL(thr, get); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ } if (has_value) { duk_tval *tv1, *tv2; @@ -5873,9 +6020,9 @@ DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, curr.e_idx)); tv2 = duk_require_tval(thr, idx_value); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, curr.e_idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate e_idx */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate e_idx */ } else { - DUK_ASSERT(curr.a_idx < 0); /* array part case handled comprehensively previously */ + DUK_ASSERT(curr.a_idx < 0); /* array part case handled comprehensively previously */ DUK_DD(DUK_DDPRINT("Object.defineProperty(), value update for virtual property")); /* XXX: Uint8Array and other typed array virtual writes not currently @@ -5884,11 +6031,12 @@ if (key == DUK_HTHREAD_STRING_LENGTH(thr) && DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)) { duk_harray *a; a = (duk_harray *) obj; - DUK_DD(DUK_DDPRINT("Object.defineProperty() value update for duk_harray .length -> %ld", (long) arrlen_new_len)); + DUK_DD(DUK_DDPRINT("Object.defineProperty() value update for duk_harray .length -> %ld", + (long) arrlen_new_len)); DUK_HARRAY_ASSERT_VALID(a); a->length = arrlen_new_len; } else { - goto fail_virtual; /* should not happen */ + goto fail_virtual; /* should not happen */ } } } @@ -5905,7 +6053,7 @@ * - for 'length' key the element deletion and 'length' update occurs here */ - success_exotics: +success_exotics: /* curr.a_idx or curr.e_idx may have been invalidated by side effects * above. @@ -5949,7 +6097,8 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key is 'length', exotic array behavior, " "doing array element deletion and length update")); - rc = duk__handle_put_array_length_smaller(thr, obj, arrlen_old_len, arrlen_new_len, force_flag, &result_len); + rc = + duk__handle_put_array_length_smaller(thr, obj, arrlen_old_len, arrlen_new_len, force_flag, &result_len); /* update length (curr points to length, and we assume it's still valid) */ DUK_ASSERT(result_len >= arrlen_new_len && result_len <= arrlen_old_len); @@ -5972,7 +6121,7 @@ duk_hobject *varenv; DUK_ASSERT(arridx_new_array_length == 0); - DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)); /* traits are separate; in particular, arguments not an array */ + DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)); /* traits are separate; in particular, arguments not an array */ map = NULL; varenv = NULL; @@ -5989,7 +6138,7 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map' " "changed to an accessor, delete arguments binding")); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ } else { /* Note: this order matters (final value before deleting map entry must be done) */ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map', " @@ -6017,7 +6166,7 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map', " "changed to non-writable, delete arguments binding")); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ } } @@ -6026,22 +6175,22 @@ */ } - success_no_exotics: +success_no_exotics: /* Some code paths use NORZ macros for simplicity, ensure refzero * handling is completed. */ DUK_REFZERO_CHECK_SLOW(thr); return 1; - fail_not_extensible: +fail_not_extensible: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_EXTENSIBLE); DUK_WO_NORETURN(return 0;); } return 0; - fail_virtual: /* just use the same "not configurable" error message" */ - fail_not_configurable: +fail_virtual: /* just use the same "not configurable" error message" */ +fail_not_configurable: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); @@ -6066,7 +6215,7 @@ h_obj = duk_push_this_coercible_to_object(thr); DUK_ASSERT(h_obj != NULL); - ret = duk_hobject_get_own_propdesc(thr, h_obj, h_v, &desc, 0 /*flags*/); /* don't push value */ + ret = duk_hobject_get_own_propdesc(thr, h_obj, h_v, &desc, 0 /*flags*/); /* don't push value */ duk_push_boolean(thr, ret && ((desc.flags & required_desc_flags) == required_desc_flags)); return 1; @@ -6180,9 +6329,7 @@ if (flags & DUK_PROPDESC_FLAG_CONFIGURABLE) { return 0; } - if (is_frozen && - !(flags & DUK_PROPDESC_FLAG_ACCESSOR) && - (flags & DUK_PROPDESC_FLAG_WRITABLE)) { + if (is_frozen && !(flags & DUK_PROPDESC_FLAG_ACCESSOR) && (flags & DUK_PROPDESC_FLAG_WRITABLE)) { return 0; } }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hproxy.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hproxy.h
Changed
@@ -7,9 +7,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hproxy_assert_valid(duk_hproxy *h); -#define DUK_HPROXY_ASSERT_VALID(h) do { duk_hproxy_assert_valid((h)); } while (0) +#define DUK_HPROXY_ASSERT_VALID(h) \ + do { \ + duk_hproxy_assert_valid((h)); \ + } while (0) #else -#define DUK_HPROXY_ASSERT_VALID(h) do {} while (0) +#define DUK_HPROXY_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hproxy { @@ -23,4 +28,4 @@ duk_hobject *handler; }; -#endif /* DUK_HPROXY_H_INCLUDED */ +#endif /* DUK_HPROXY_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hstring.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hstring.h
Changed
@@ -27,9 +27,9 @@ */ #if defined(DUK_USE_STRLEN16) -#define DUK_HSTRING_MAX_BYTELEN (0x0000ffffUL) +#define DUK_HSTRING_MAX_BYTELEN (0x0000ffffUL) #else -#define DUK_HSTRING_MAX_BYTELEN (0x7fffffffUL) +#define DUK_HSTRING_MAX_BYTELEN (0x7fffffffUL) #endif /* XXX: could add flags for "is valid CESU-8" (ECMAScript compatible strings), @@ -41,139 +41,148 @@ /* With lowmem builds the high 16 bits of duk_heaphdr are used for other * purposes, so this leaves 7 duk_heaphdr flags and 9 duk_hstring flags. */ -#define DUK_HSTRING_FLAG_ASCII DUK_HEAPHDR_USER_FLAG(0) /* string is ASCII, clen == blen */ -#define DUK_HSTRING_FLAG_ARRIDX DUK_HEAPHDR_USER_FLAG(1) /* string is a valid array index */ -#define DUK_HSTRING_FLAG_SYMBOL DUK_HEAPHDR_USER_FLAG(2) /* string is a symbol (invalid utf-8) */ -#define DUK_HSTRING_FLAG_HIDDEN DUK_HEAPHDR_USER_FLAG(3) /* string is a hidden symbol (implies symbol, Duktape 1.x internal string) */ -#define DUK_HSTRING_FLAG_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(4) /* string is a reserved word (non-strict) */ -#define DUK_HSTRING_FLAG_STRICT_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(5) /* string is a reserved word (strict) */ -#define DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS DUK_HEAPHDR_USER_FLAG(6) /* string is 'eval' or 'arguments' */ -#define DUK_HSTRING_FLAG_EXTDATA DUK_HEAPHDR_USER_FLAG(7) /* string data is external (duk_hstring_external) */ -#define DUK_HSTRING_FLAG_PINNED_LITERAL DUK_HEAPHDR_USER_FLAG(8) /* string is a literal, and pinned */ - -#define DUK_HSTRING_HAS_ASCII(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_HAS_ARRIDX(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_HAS_SYMBOL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_HAS_HIDDEN(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_HAS_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_HAS_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_HAS_EXTDATA(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_HAS_PINNED_LITERAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#define DUK_HSTRING_SET_ASCII(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_SET_ARRIDX(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_SET_SYMBOL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_SET_HIDDEN(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_SET_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_SET_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_SET_EXTDATA(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_SET_PINNED_LITERAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#define DUK_HSTRING_CLEAR_ASCII(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_CLEAR_ARRIDX(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_CLEAR_SYMBOL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_CLEAR_HIDDEN(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_CLEAR_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_CLEAR_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_CLEAR_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_CLEAR_EXTDATA(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_CLEAR_PINNED_LITERAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#if 0 /* Slightly smaller code without explicit flag, but explicit flag - * is very useful when 'clen' is dropped. - */ -#define DUK_HSTRING_IS_ASCII(x) (DUK_HSTRING_GET_BYTELEN((x)) == DUK_HSTRING_GET_CHARLEN((x))) +#define DUK_HSTRING_FLAG_ASCII DUK_HEAPHDR_USER_FLAG(0) /* string is ASCII, clen == blen */ +#define DUK_HSTRING_FLAG_ARRIDX DUK_HEAPHDR_USER_FLAG(1) /* string is a valid array index */ +#define DUK_HSTRING_FLAG_SYMBOL DUK_HEAPHDR_USER_FLAG(2) /* string is a symbol (invalid utf-8) */ +#define DUK_HSTRING_FLAG_HIDDEN \ + DUK_HEAPHDR_USER_FLAG(3) /* string is a hidden symbol (implies symbol, Duktape 1.x internal string) */ +#define DUK_HSTRING_FLAG_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(4) /* string is a reserved word (non-strict) */ +#define DUK_HSTRING_FLAG_STRICT_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(5) /* string is a reserved word (strict) */ +#define DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS DUK_HEAPHDR_USER_FLAG(6) /* string is 'eval' or 'arguments' */ +#define DUK_HSTRING_FLAG_EXTDATA DUK_HEAPHDR_USER_FLAG(7) /* string data is external (duk_hstring_external) */ +#define DUK_HSTRING_FLAG_PINNED_LITERAL DUK_HEAPHDR_USER_FLAG(8) /* string is a literal, and pinned */ + +#define DUK_HSTRING_HAS_ASCII(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_HAS_ARRIDX(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_HAS_SYMBOL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_HAS_HIDDEN(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_HAS_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_HAS_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_HAS_EXTDATA(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_HAS_PINNED_LITERAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#define DUK_HSTRING_SET_ASCII(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_SET_ARRIDX(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_SET_SYMBOL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_SET_HIDDEN(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_SET_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_SET_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_SET_EXTDATA(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_SET_PINNED_LITERAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#define DUK_HSTRING_CLEAR_ASCII(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_CLEAR_ARRIDX(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_CLEAR_SYMBOL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_CLEAR_HIDDEN(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_CLEAR_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_CLEAR_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_CLEAR_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_CLEAR_EXTDATA(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_CLEAR_PINNED_LITERAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#if 0 /* Slightly smaller code without explicit flag, but explicit flag \ + * is very useful when 'clen' is dropped. \ + */ +#define DUK_HSTRING_IS_ASCII(x) (DUK_HSTRING_GET_BYTELEN((x)) == DUK_HSTRING_GET_CHARLEN((x))) #endif -#define DUK_HSTRING_IS_ASCII(x) DUK_HSTRING_HAS_ASCII((x)) /* lazily set! */ -#define DUK_HSTRING_IS_EMPTY(x) (DUK_HSTRING_GET_BYTELEN((x)) == 0) +#define DUK_HSTRING_IS_ASCII(x) DUK_HSTRING_HAS_ASCII((x)) /* lazily set! */ +#define DUK_HSTRING_IS_EMPTY(x) (DUK_HSTRING_GET_BYTELEN((x)) == 0) #if defined(DUK_USE_STRHASH16) -#define DUK_HSTRING_GET_HASH(x) ((x)->hdr.h_flags >> 16) -#define DUK_HSTRING_SET_HASH(x,v) do { \ +#define DUK_HSTRING_GET_HASH(x) ((x)->hdr.h_flags >> 16) +#define DUK_HSTRING_SET_HASH(x, v) \ + do { \ (x)->hdr.h_flags = ((x)->hdr.h_flags & 0x0000ffffUL) | ((v) << 16); \ } while (0) #else -#define DUK_HSTRING_GET_HASH(x) ((x)->hash) -#define DUK_HSTRING_SET_HASH(x,v) do { \ +#define DUK_HSTRING_GET_HASH(x) ((x)->hash) +#define DUK_HSTRING_SET_HASH(x, v) \ + do { \ (x)->hash = (v); \ } while (0) #endif #if defined(DUK_USE_STRLEN16) -#define DUK_HSTRING_GET_BYTELEN(x) ((x)->hdr.h_strextra16) -#define DUK_HSTRING_SET_BYTELEN(x,v) do { \ +#define DUK_HSTRING_GET_BYTELEN(x) ((x)->hdr.h_strextra16) +#define DUK_HSTRING_SET_BYTELEN(x, v) \ + do { \ (x)->hdr.h_strextra16 = (v); \ } while (0) #if defined(DUK_USE_HSTRING_CLEN) -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ (x)->clen16 = (v); \ } while (0) #else -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ - DUK_ASSERT(0); /* should never be called */ \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ + DUK_ASSERT(0); /* should never be called */ \ } while (0) #endif #else -#define DUK_HSTRING_GET_BYTELEN(x) ((x)->blen) -#define DUK_HSTRING_SET_BYTELEN(x,v) do { \ +#define DUK_HSTRING_GET_BYTELEN(x) ((x)->blen) +#define DUK_HSTRING_SET_BYTELEN(x, v) \ + do { \ (x)->blen = (v); \ } while (0) -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ (x)->clen = (v); \ } while (0) #endif #if defined(DUK_USE_HSTRING_EXTDATA) -#define DUK_HSTRING_GET_EXTDATA(x) \ - ((x)->extdata) +#define DUK_HSTRING_GET_EXTDATA(x) ((x)->extdata) #define DUK_HSTRING_GET_DATA(x) \ - (DUK_HSTRING_HAS_EXTDATA((x)) ? \ - DUK_HSTRING_GET_EXTDATA((const duk_hstring_external *) (x)) : ((const duk_uint8_t *) ((x) + 1))) + (DUK_HSTRING_HAS_EXTDATA((x)) ? DUK_HSTRING_GET_EXTDATA((const duk_hstring_external *) (x)) : \ + ((const duk_uint8_t *) ((x) + 1))) #else -#define DUK_HSTRING_GET_DATA(x) \ - ((const duk_uint8_t *) ((x) + 1)) +#define DUK_HSTRING_GET_DATA(x) ((const duk_uint8_t *) ((x) + 1)) #endif -#define DUK_HSTRING_GET_DATA_END(x) \ - (DUK_HSTRING_GET_DATA((x)) + (x)->blen) +#define DUK_HSTRING_GET_DATA_END(x) (DUK_HSTRING_GET_DATA((x)) + (x)->blen) /* Marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest * valid). */ -#define DUK_HSTRING_NO_ARRAY_INDEX (0xffffffffUL) +#define DUK_HSTRING_NO_ARRAY_INDEX (0xffffffffUL) #if defined(DUK_USE_HSTRING_ARRIDX) -#define DUK_HSTRING_GET_ARRIDX_FAST(h) ((h)->arridx) -#define DUK_HSTRING_GET_ARRIDX_SLOW(h) ((h)->arridx) +#define DUK_HSTRING_GET_ARRIDX_FAST(h) ((h)->arridx) +#define DUK_HSTRING_GET_ARRIDX_SLOW(h) ((h)->arridx) #else /* Get array index related to string (or return DUK_HSTRING_NO_ARRAY_INDEX); * avoids helper call if string has no array index value. */ -#define DUK_HSTRING_GET_ARRIDX_FAST(h) \ +#define DUK_HSTRING_GET_ARRIDX_FAST(h) \ (DUK_HSTRING_HAS_ARRIDX((h)) ? duk_js_to_arrayindex_hstring_fast_known((h)) : DUK_HSTRING_NO_ARRAY_INDEX) /* Slower but more compact variant. */ -#define DUK_HSTRING_GET_ARRIDX_SLOW(h) \ - (duk_js_to_arrayindex_hstring_fast((h))) +#define DUK_HSTRING_GET_ARRIDX_SLOW(h) (duk_js_to_arrayindex_hstring_fast((h))) #endif /* XXX: these actually fit into duk_hstring */ -#define DUK_SYMBOL_TYPE_HIDDEN 0 -#define DUK_SYMBOL_TYPE_GLOBAL 1 -#define DUK_SYMBOL_TYPE_LOCAL 2 +#define DUK_SYMBOL_TYPE_HIDDEN 0 +#define DUK_SYMBOL_TYPE_GLOBAL 1 +#define DUK_SYMBOL_TYPE_LOCAL 2 #define DUK_SYMBOL_TYPE_WELLKNOWN 3 /* Assertion for duk_hstring validity. */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hstring_assert_valid(duk_hstring *h); -#define DUK_HSTRING_ASSERT_VALID(h) do { duk_hstring_assert_valid((h)); } while (0) +#define DUK_HSTRING_ASSERT_VALID(h) \ + do { \ + duk_hstring_assert_valid((h)); \ + } while (0) #else -#define DUK_HSTRING_ASSERT_VALID(h) do {} while (0) +#define DUK_HSTRING_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -243,11 +252,14 @@ * Prototypes */ -DUK_INTERNAL_DECL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, duk_hstring *h, duk_uint_t pos, duk_bool_t surrogate_aware); +DUK_INTERNAL_DECL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, + duk_hstring *h, + duk_uint_t pos, + duk_bool_t surrogate_aware); DUK_INTERNAL_DECL duk_bool_t duk_hstring_equals_ascii_cstring(duk_hstring *h, const char *cstr); DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h); #if !defined(DUK_USE_HSTRING_LAZY_CLEN) DUK_INTERNAL_DECL void duk_hstring_init_charlen(duk_hstring *h); #endif -#endif /* DUK_HSTRING_H_INCLUDED */ +#endif /* DUK_HSTRING_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hstring_assert.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hstring_assert.c
Changed
@@ -10,4 +10,4 @@ DUK_ASSERT(h != NULL); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hstring_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hstring_misc.c
Changed
@@ -8,7 +8,10 @@ * duk_hstring charCodeAt, with and without surrogate awareness */ -DUK_INTERNAL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, duk_hstring *h, duk_uint_t pos, duk_bool_t surrogate_aware) { +DUK_INTERNAL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, + duk_hstring *h, + duk_uint_t pos, + duk_bool_t surrogate_aware) { duk_uint32_t boff; const duk_uint8_t *p, *p_start, *p_end; duk_ucodepoint_t cp1; @@ -17,21 +20,18 @@ /* Caller must check character offset to be inside the string. */ DUK_ASSERT(thr != NULL); DUK_ASSERT(h != NULL); - DUK_ASSERT_DISABLE(pos >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(pos >= 0); /* unsigned */ DUK_ASSERT(pos < (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte(thr, h, (duk_uint32_t) pos); - DUK_DDD(DUK_DDDPRINT("charCodeAt: pos=%ld -> boff=%ld, str=%!O", - (long) pos, (long) boff, (duk_heaphdr *) h)); + DUK_DDD(DUK_DDDPRINT("charCodeAt: pos=%ld -> boff=%ld, str=%!O", (long) pos, (long) boff, (duk_heaphdr *) h)); DUK_ASSERT_DISABLE(boff >= 0); DUK_ASSERT(boff < DUK_HSTRING_GET_BYTELEN(h)); p_start = DUK_HSTRING_GET_DATA(h); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h); p = p_start + boff; - DUK_DDD(DUK_DDDPRINT("p_start=%p, p_end=%p, p=%p", - (const void *) p_start, (const void *) p_end, - (const void *) p)); + DUK_DDD(DUK_DDDPRINT("p_start=%p, p_end=%p, p=%p", (const void *) p_start, (const void *) p_end, (const void *) p)); /* For invalid UTF-8 (never happens for standard ECMAScript strings) * return U+FFFD replacement character. @@ -42,7 +42,7 @@ * decoded at the end of the string and 'p' is no longer * within string memory range. */ - cp2 = 0; /* If call fails, this is left untouched and won't match cp2 check. */ + cp2 = 0; /* If call fails, this is left untouched and won't match cp2 check. */ (void) duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp2); if (cp2 >= 0xdc00UL && cp2 <= 0xdfffUL) { cp1 = (duk_ucodepoint_t) (((cp1 - 0xd800UL) << 10) + (cp2 - 0xdc00UL) + 0x10000UL); @@ -72,7 +72,7 @@ clen = duk_unicode_unvalidated_utf8_length(DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); #if defined(DUK_USE_STRLEN16) - DUK_ASSERT(clen <= 0xffffUL); /* Bytelength checked during interning. */ + DUK_ASSERT(clen <= 0xffffUL); /* Bytelength checked during interning. */ h->clen16 = (duk_uint16_t) clen; #else h->clen = (duk_uint32_t) clen; @@ -89,7 +89,7 @@ return h->clen; #endif } -#endif /* !DUK_USE_HSTRING_LAZY_CLEN */ +#endif /* !DUK_USE_HSTRING_LAZY_CLEN */ /* * duk_hstring charlen, when lazy charlen enabled @@ -100,7 +100,7 @@ DUK_LOCAL DUK_COLD duk_size_t duk__hstring_get_charlen_slowpath(duk_hstring *h) { duk_size_t res; - DUK_ASSERT(h->clen == 0); /* Checked by caller. */ + DUK_ASSERT(h->clen == 0); /* Checked by caller. */ #if defined(DUK_USE_ROM_STRINGS) /* ROM strings have precomputed clen, but if the computed clen is zero @@ -113,7 +113,7 @@ res = duk_unicode_unvalidated_utf8_length(DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); #if defined(DUK_USE_STRLEN16) - DUK_ASSERT(res <= 0xffffUL); /* Bytelength checked during interning. */ + DUK_ASSERT(res <= 0xffffUL); /* Bytelength checked during interning. */ h->clen16 = (duk_uint16_t) res; #else h->clen = (duk_uint32_t) res; @@ -123,7 +123,7 @@ } return res; } -#else /* DUK_USE_HSTRING_CLEN */ +#else /* DUK_USE_HSTRING_CLEN */ DUK_LOCAL duk_size_t duk__hstring_get_charlen_slowpath(duk_hstring *h) { if (DUK_LIKELY(DUK_HSTRING_HAS_ASCII(h))) { /* Most practical strings will go here. */ @@ -152,7 +152,7 @@ return res; } } -#endif /* DUK_USE_HSTRING_CLEN */ +#endif /* DUK_USE_HSTRING_CLEN */ #if defined(DUK_USE_HSTRING_CLEN) DUK_INTERNAL DUK_HOT duk_size_t duk_hstring_get_charlen(duk_hstring *h) { @@ -167,13 +167,13 @@ #endif return duk__hstring_get_charlen_slowpath(h); } -#else /* DUK_USE_HSTRING_CLEN */ +#else /* DUK_USE_HSTRING_CLEN */ DUK_INTERNAL DUK_HOT duk_size_t duk_hstring_get_charlen(duk_hstring *h) { /* Always use slow path. */ return duk__hstring_get_charlen_slowpath(h); } -#endif /* DUK_USE_HSTRING_CLEN */ -#endif /* DUK_USE_HSTRING_LAZY_CLEN */ +#endif /* DUK_USE_HSTRING_CLEN */ +#endif /* DUK_USE_HSTRING_LAZY_CLEN */ /* * Compare duk_hstring to an ASCII cstring.
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hthread.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hthread.h
Changed
@@ -14,38 +14,38 @@ */ /* Initial valstack size, roughly 0.7kiB. */ -#define DUK_VALSTACK_INITIAL_SIZE 96U +#define DUK_VALSTACK_INITIAL_SIZE 96U /* Internal extra elements assumed on function entry, always added to * user-defined 'extra' for e.g. the duk_check_stack() call. */ -#define DUK_VALSTACK_INTERNAL_EXTRA 32U +#define DUK_VALSTACK_INTERNAL_EXTRA 32U /* Number of elements guaranteed to be user accessible (in addition to call * arguments) on Duktape/C function entry. This is the major public API * commitment. */ -#define DUK_VALSTACK_API_ENTRY_MINIMUM DUK_API_ENTRY_STACK +#define DUK_VALSTACK_API_ENTRY_MINIMUM DUK_API_ENTRY_STACK /* * Activation defines */ -#define DUK_ACT_FLAG_STRICT (1U << 0) /* function executes in strict mode */ -#define DUK_ACT_FLAG_TAILCALLED (1U << 1) /* activation has tail called one or more times */ -#define DUK_ACT_FLAG_CONSTRUCT (1U << 2) /* function executes as a constructor (called via "new") */ -#define DUK_ACT_FLAG_PREVENT_YIELD (1U << 3) /* activation prevents yield (native call or "new") */ -#define DUK_ACT_FLAG_DIRECT_EVAL (1U << 4) /* activation is a direct eval call */ -#define DUK_ACT_FLAG_CONSTRUCT_PROXY (1U << 5) /* activation is for Proxy 'construct' call, special return value handling */ -#define DUK_ACT_FLAG_BREAKPOINT_ACTIVE (1U << 6) /* activation has active breakpoint(s) */ +#define DUK_ACT_FLAG_STRICT (1U << 0) /* function executes in strict mode */ +#define DUK_ACT_FLAG_TAILCALLED (1U << 1) /* activation has tail called one or more times */ +#define DUK_ACT_FLAG_CONSTRUCT (1U << 2) /* function executes as a constructor (called via "new") */ +#define DUK_ACT_FLAG_PREVENT_YIELD (1U << 3) /* activation prevents yield (native call or "new") */ +#define DUK_ACT_FLAG_DIRECT_EVAL (1U << 4) /* activation is a direct eval call */ +#define DUK_ACT_FLAG_CONSTRUCT_PROXY (1U << 5) /* activation is for Proxy 'construct' call, special return value handling */ +#define DUK_ACT_FLAG_BREAKPOINT_ACTIVE (1U << 6) /* activation has active breakpoint(s) */ -#define DUK_ACT_GET_FUNC(act) ((act)->func) +#define DUK_ACT_GET_FUNC(act) ((act)->func) /* * Flags for __FILE__ / __LINE__ registered into tracedata */ -#define DUK_TB_FLAG_NOBLAME_FILELINE (1U << 0) /* don't report __FILE__ / __LINE__ as fileName/lineNumber */ +#define DUK_TB_FLAG_NOBLAME_FILELINE (1U << 0) /* don't report __FILE__ / __LINE__ as fileName/lineNumber */ /* * Catcher defines @@ -54,52 +54,60 @@ /* XXX: remove catcher type entirely */ /* flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits) */ -#define DUK_CAT_TYPE_MASK 0x0000000fUL -#define DUK_CAT_TYPE_BITS 4 -#define DUK_CAT_LABEL_MASK 0xffffff00UL -#define DUK_CAT_LABEL_BITS 24 -#define DUK_CAT_LABEL_SHIFT 8 - -#define DUK_CAT_FLAG_CATCH_ENABLED (1U << 4) /* catch part will catch */ -#define DUK_CAT_FLAG_FINALLY_ENABLED (1U << 5) /* finally part will catch */ -#define DUK_CAT_FLAG_CATCH_BINDING_ENABLED (1U << 6) /* request to create catch binding */ -#define DUK_CAT_FLAG_LEXENV_ACTIVE (1U << 7) /* catch or with binding is currently active */ - -#define DUK_CAT_TYPE_UNKNOWN 0 -#define DUK_CAT_TYPE_TCF 1 -#define DUK_CAT_TYPE_LABEL 2 - -#define DUK_CAT_GET_TYPE(c) ((c)->flags & DUK_CAT_TYPE_MASK) -#define DUK_CAT_GET_LABEL(c) (((c)->flags & DUK_CAT_LABEL_MASK) >> DUK_CAT_LABEL_SHIFT) - -#define DUK_CAT_HAS_CATCH_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_ENABLED) -#define DUK_CAT_HAS_FINALLY_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_FINALLY_ENABLED) -#define DUK_CAT_HAS_CATCH_BINDING_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_BINDING_ENABLED) -#define DUK_CAT_HAS_LEXENV_ACTIVE(c) ((c)->flags & DUK_CAT_FLAG_LEXENV_ACTIVE) - -#define DUK_CAT_SET_CATCH_ENABLED(c) do { \ +#define DUK_CAT_TYPE_MASK 0x0000000fUL +#define DUK_CAT_TYPE_BITS 4 +#define DUK_CAT_LABEL_MASK 0xffffff00UL +#define DUK_CAT_LABEL_BITS 24 +#define DUK_CAT_LABEL_SHIFT 8 + +#define DUK_CAT_FLAG_CATCH_ENABLED (1U << 4) /* catch part will catch */ +#define DUK_CAT_FLAG_FINALLY_ENABLED (1U << 5) /* finally part will catch */ +#define DUK_CAT_FLAG_CATCH_BINDING_ENABLED (1U << 6) /* request to create catch binding */ +#define DUK_CAT_FLAG_LEXENV_ACTIVE (1U << 7) /* catch or with binding is currently active */ + +#define DUK_CAT_TYPE_UNKNOWN 0 +#define DUK_CAT_TYPE_TCF 1 +#define DUK_CAT_TYPE_LABEL 2 + +#define DUK_CAT_GET_TYPE(c) ((c)->flags & DUK_CAT_TYPE_MASK) +#define DUK_CAT_GET_LABEL(c) (((c)->flags & DUK_CAT_LABEL_MASK) >> DUK_CAT_LABEL_SHIFT) + +#define DUK_CAT_HAS_CATCH_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_ENABLED) +#define DUK_CAT_HAS_FINALLY_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_FINALLY_ENABLED) +#define DUK_CAT_HAS_CATCH_BINDING_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_BINDING_ENABLED) +#define DUK_CAT_HAS_LEXENV_ACTIVE(c) ((c)->flags & DUK_CAT_FLAG_LEXENV_ACTIVE) + +#define DUK_CAT_SET_CATCH_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_CATCH_ENABLED; \ } while (0) -#define DUK_CAT_SET_FINALLY_ENABLED(c) do { \ +#define DUK_CAT_SET_FINALLY_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_FINALLY_ENABLED; \ } while (0) -#define DUK_CAT_SET_CATCH_BINDING_ENABLED(c) do { \ +#define DUK_CAT_SET_CATCH_BINDING_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_CATCH_BINDING_ENABLED; \ } while (0) -#define DUK_CAT_SET_LEXENV_ACTIVE(c) do { \ +#define DUK_CAT_SET_LEXENV_ACTIVE(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_LEXENV_ACTIVE; \ } while (0) -#define DUK_CAT_CLEAR_CATCH_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_CATCH_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_CATCH_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_FINALLY_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_FINALLY_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_FINALLY_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_CATCH_BINDING_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_CATCH_BINDING_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_CATCH_BINDING_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_LEXENV_ACTIVE(c) do { \ +#define DUK_CAT_CLEAR_LEXENV_ACTIVE(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_LEXENV_ACTIVE; \ } while (0) @@ -108,24 +116,21 @@ */ #if defined(DUK_USE_ROM_STRINGS) -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) -#else /* DUK_USE_ROM_STRINGS */ +#define DUK_HTHREAD_GET_STRING(thr, idx) ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((thr)->heap->heap_udata, (thr)->strs16(idx))) +#define DUK_HTHREAD_GET_STRING(thr, idx) ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((thr)->heap->heap_udata, (thr)->strs16(idx))) #else -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((thr)->strs(idx)) +#define DUK_HTHREAD_GET_STRING(thr, idx) ((thr)->strs(idx)) #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ /* values for the state field */ -#define DUK_HTHREAD_STATE_INACTIVE 1 /* thread not currently running */ -#define DUK_HTHREAD_STATE_RUNNING 2 /* thread currently running (only one at a time) */ -#define DUK_HTHREAD_STATE_RESUMED 3 /* thread resumed another thread (active but not running) */ -#define DUK_HTHREAD_STATE_YIELDED 4 /* thread has yielded */ -#define DUK_HTHREAD_STATE_TERMINATED 5 /* thread has terminated */ +#define DUK_HTHREAD_STATE_INACTIVE 1 /* thread not currently running */ +#define DUK_HTHREAD_STATE_RUNNING 2 /* thread currently running (only one at a time) */ +#define DUK_HTHREAD_STATE_RESUMED 3 /* thread resumed another thread (active but not running) */ +#define DUK_HTHREAD_STATE_YIELDED 4 /* thread has yielded */ +#define DUK_HTHREAD_STATE_TERMINATED 5 /* thread has terminated */ /* Executor interrupt default interval when nothing else requires a * smaller value. The default interval must be small enough to allow @@ -133,7 +138,7 @@ * impact on execution performance low. */ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK_HTHREAD_INTCTR_DEFAULT (256L * 1024L) +#define DUK_HTHREAD_INTCTR_DEFAULT (256L * 1024L) #endif /* @@ -147,20 +152,31 @@ #if defined(DUK_USE_ASSERTIONS) /* Assertions for internals. */ DUK_INTERNAL_DECL void duk_hthread_assert_valid(duk_hthread *thr); -#define DUK_HTHREAD_ASSERT_VALID(thr) do { duk_hthread_assert_valid((thr)); } while (0) +#define DUK_HTHREAD_ASSERT_VALID(thr) \ + do { \ + duk_hthread_assert_valid((thr)); \ + } while (0) /* Assertions for public API calls; a bit stronger. */ DUK_INTERNAL_DECL void duk_ctx_assert_valid(duk_hthread *thr); -#define DUK_CTX_ASSERT_VALID(thr) do { duk_ctx_assert_valid((thr)); } while (0) +#define DUK_CTX_ASSERT_VALID(thr) \ + do { \ + duk_ctx_assert_valid((thr)); \ + } while (0) #else -#define DUK_HTHREAD_ASSERT_VALID(thr) do {} while (0) -#define DUK_CTX_ASSERT_VALID(thr) do {} while (0) +#define DUK_HTHREAD_ASSERT_VALID(thr) \ + do { \ + } while (0) +#define DUK_CTX_ASSERT_VALID(thr) \ + do { \ + } while (0) #endif /* Assertions for API call entry specifically. Checks 'ctx' but also may * check internal state (e.g. not in a debugger transport callback). */ -#define DUK_ASSERT_API_ENTRY(thr) do { \ +#define DUK_ASSERT_API_ENTRY(thr) \ + do { \ DUK_CTX_ASSERT_VALID((thr)); \ DUK_ASSERT((thr)->heap != NULL); \ DUK_ASSERT((thr)->heap->dbg_calling_transport == 0); \ @@ -170,11 +186,9 @@ * Assertion helpers. */ -#define DUK_ASSERT_STRIDX_VALID(val) \ - DUK_ASSERT((duk_uint_t) (val) < DUK_HEAP_NUM_STRINGS) +#define DUK_ASSERT_STRIDX_VALID(val) DUK_ASSERT((duk_uint_t) (val) < DUK_HEAP_NUM_STRINGS) -#define DUK_ASSERT_BIDX_VALID(val) \ - DUK_ASSERT((duk_uint_t) (val) < DUK_NUM_BUILTINS) +#define DUK_ASSERT_BIDX_VALID(val) DUK_ASSERT((duk_uint_t) (val) < DUK_NUM_BUILTINS) /* * Misc @@ -182,9 +196,7 @@ /* Fast access to 'this' binding. Assumes there's a call in progress. */ #define DUK_HTHREAD_THIS_PTR(thr) \ - (DUK_ASSERT_EXPR((thr) != NULL), \ - DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), \ - (thr)->valstack_bottom - 1) + (DUK_ASSERT_EXPR((thr) != NULL), DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), (thr)->valstack_bottom - 1) /* * Struct defines @@ -192,12 +204,13 @@ /* Fields are ordered for alignment/packing. */ struct duk_activation { - duk_tval tv_func; /* borrowed: full duk_tval for function being executed; for lightfuncs */ - duk_hobject *func; /* borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs */ + duk_tval tv_func; /* borrowed: full duk_tval for function being executed; for lightfuncs */ + duk_hobject *func; /* borrowed: function being executed; for bound function calls, this is the final, real function, NULL + for lightfuncs */ duk_activation *parent; /* previous (parent) activation (or NULL if none) */ - duk_hobject *var_env; /* current variable environment (may be NULL if delayed) */ - duk_hobject *lex_env; /* current lexical environment (may be NULL if delayed) */ - duk_catcher *cat; /* current catcher (or NULL) */ + duk_hobject *var_env; /* current variable environment (may be NULL if delayed) */ + duk_hobject *lex_env; /* current lexical environment (may be NULL if delayed) */ + duk_catcher *cat; /* current catcher (or NULL) */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) /* Previous value of 'func' caller, restored when unwound. Only in use @@ -206,7 +219,7 @@ duk_hobject *prev_caller; #endif - duk_instr_t *curr_pc; /* next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls */ + duk_instr_t *curr_pc; /* next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls */ /* bottom_byteoff and retval_byteoff are only used for book-keeping * of ECMAScript-initiated calls, to allow returning to an ECMAScript @@ -253,12 +266,12 @@ }; struct duk_catcher { - duk_catcher *parent; /* previous (parent) catcher (or NULL if none) */ - duk_hstring *h_varname; /* borrowed reference to catch variable name (or NULL if none) */ - /* (reference is valid as long activation exists) */ - duk_instr_t *pc_base; /* resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer) */ - duk_size_t idx_base; /* idx_base and idx_base+1 get completion value and type */ - duk_uint32_t flags; /* type and control flags, label number */ + duk_catcher *parent; /* previous (parent) catcher (or NULL if none) */ + duk_hstring *h_varname; /* borrowed reference to catch variable name (or NULL if none) */ + /* (reference is valid as long activation exists) */ + duk_instr_t *pc_base; /* resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer) */ + duk_size_t idx_base; /* idx_base and idx_base+1 get completion value and type */ + duk_uint32_t flags; /* type and control flags, label number */ /* XXX: could pack 'flags' and 'idx_base' to same value in practice, * on 32-bit targets this would make duk_catcher 16 bytes. */ @@ -316,21 +329,21 @@ * yyy = arbitrary values, inside current frame * uuu = outside active value stack, initialized to 'undefined' */ - duk_tval *valstack; /* start of valstack allocation */ - duk_tval *valstack_end; /* end of valstack reservation/guarantee (exclusive) */ - duk_tval *valstack_alloc_end; /* end of valstack allocation */ - duk_tval *valstack_bottom; /* bottom of current frame */ - duk_tval *valstack_top; /* top of current frame (exclusive) */ + duk_tval *valstack; /* start of valstack allocation */ + duk_tval *valstack_end; /* end of valstack reservation/guarantee (exclusive) */ + duk_tval *valstack_alloc_end; /* end of valstack allocation */ + duk_tval *valstack_bottom; /* bottom of current frame */ + duk_tval *valstack_top; /* top of current frame (exclusive) */ /* Call stack, represented as a linked list starting from the current * activation (or NULL if nothing is active). */ - duk_activation *callstack_curr; /* current activation (or NULL if none) */ - duk_size_t callstack_top; /* number of activation records in callstack (0 if none) */ - duk_size_t callstack_preventcount; /* number of activation records in callstack preventing a yield */ + duk_activation *callstack_curr; /* current activation (or NULL if none) */ + duk_size_t callstack_top; /* number of activation records in callstack (0 if none) */ + duk_size_t callstack_preventcount; /* number of activation records in callstack preventing a yield */ /* Yield/resume book-keeping. */ - duk_hthread *resumer; /* who resumed us (if any) */ + duk_hthread *resumer; /* who resumed us (if any) */ /* Current compiler state (if any), used for augmenting SyntaxErrors. */ duk_compiler_ctx *compile_ctx; @@ -343,8 +356,8 @@ * important for the counter to be conveniently accessible for the * bytecode executor inner loop for performance reasons. */ - duk_int_t interrupt_counter; /* countdown state */ - duk_int_t interrupt_init; /* start value for current countdown */ + duk_int_t interrupt_counter; /* countdown state */ + duk_int_t interrupt_init; /* start value for current countdown */ #endif /* Builtin-objects; may or may not be shared with other threads, @@ -396,7 +409,7 @@ DUK_INTERNAL_DECL void duk_hthread_valstack_torture_realloc(duk_hthread *thr); #endif -DUK_INTERNAL_DECL void *duk_hthread_get_valstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */ +DUK_INTERNAL_DECL void *duk_hthread_get_valstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */ #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_INTERNAL_DECL duk_uint_fast32_t duk_hthread_get_act_curr_pc(duk_hthread *thr, duk_activation *act); @@ -405,4 +418,4 @@ DUK_INTERNAL_DECL void duk_hthread_sync_currpc(duk_hthread *thr); DUK_INTERNAL_DECL void duk_hthread_sync_and_null_currpc(duk_hthread *thr); -#endif /* DUK_HTHREAD_H_INCLUDED */ +#endif /* DUK_HTHREAD_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hthread_alloc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hthread_alloc.c
Changed
@@ -42,7 +42,7 @@ return 1; - fail: +fail: DUK_FREE(heap, thr->valstack); DUK_ASSERT(thr->callstack_curr == NULL);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hthread_builtins.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hthread_builtins.c
Changed
@@ -10,21 +10,21 @@ * Encoding constants, must match genbuiltins.py */ -#define DUK__PROP_FLAGS_BITS 3 -#define DUK__LENGTH_PROP_BITS 3 -#define DUK__NARGS_BITS 3 -#define DUK__PROP_TYPE_BITS 3 - -#define DUK__NARGS_VARARGS_MARKER 0x07 - -#define DUK__PROP_TYPE_DOUBLE 0 -#define DUK__PROP_TYPE_STRING 1 -#define DUK__PROP_TYPE_STRIDX 2 -#define DUK__PROP_TYPE_BUILTIN 3 -#define DUK__PROP_TYPE_UNDEFINED 4 -#define DUK__PROP_TYPE_BOOLEAN_TRUE 5 -#define DUK__PROP_TYPE_BOOLEAN_FALSE 6 -#define DUK__PROP_TYPE_ACCESSOR 7 +#define DUK__PROP_FLAGS_BITS 3 +#define DUK__LENGTH_PROP_BITS 3 +#define DUK__NARGS_BITS 3 +#define DUK__PROP_TYPE_BITS 3 + +#define DUK__NARGS_VARARGS_MARKER 0x07 + +#define DUK__PROP_TYPE_DOUBLE 0 +#define DUK__PROP_TYPE_STRING 1 +#define DUK__PROP_TYPE_STRIDX 2 +#define DUK__PROP_TYPE_BUILTIN 3 +#define DUK__PROP_TYPE_UNDEFINED 4 +#define DUK__PROP_TYPE_BOOLEAN_TRUE 5 +#define DUK__PROP_TYPE_BOOLEAN_FALSE 6 +#define DUK__PROP_TYPE_ACCESSOR 7 /* * Create built-in objects by parsing an init bitstream generated @@ -47,9 +47,8 @@ #if defined(DUK_USE_ROM_GLOBAL_INHERIT) /* Inherit from ROM-based global object: less RAM usage, less transparent. */ h_global = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), DUK_BIDX_GLOBAL); DUK_ASSERT(h_global != NULL); #elif defined(DUK_USE_ROM_GLOBAL_CLONE) @@ -58,9 +57,8 @@ * model but more compliant. */ h_global = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), DUK_BIDX_OBJECT_PROTOTYPE); DUK_ASSERT(h_global != NULL); h_oldglobal = thr->builtinsDUK_BIDX_GLOBAL; @@ -94,7 +92,8 @@ duk_hobject_compact_props(thr, h_global); DUK_ASSERT(thr->builtinsDUK_BIDX_GLOBAL != NULL); - DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL)); /* no need to decref: ROM object */ + DUK_ASSERT( + !DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL)); /* no need to decref: ROM object */ thr->builtinsDUK_BIDX_GLOBAL = h_global; DUK_HOBJECT_INCREF(thr, h_global); DUK_D(DUK_DPRINT("duplicated global object: %!O", h_global)); @@ -103,9 +102,9 @@ * needed so that the global scope points to the newly created RAM-based * global object. */ - h_objenv = (duk_hobject *) duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + h_objenv = + (duk_hobject *) duk_hobjenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(h_objenv != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_objenv) == NULL); duk_push_hobject(thr, h_objenv); @@ -116,16 +115,17 @@ DUK_ASSERT(((duk_hobjenv *) h_objenv)->has_this == 0); DUK_ASSERT(thr->builtinsDUK_BIDX_GLOBAL_ENV != NULL); - DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL_ENV)); /* no need to decref: ROM object */ + DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE( + (duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL_ENV)); /* no need to decref: ROM object */ thr->builtinsDUK_BIDX_GLOBAL_ENV = h_objenv; DUK_HOBJECT_INCREF(thr, h_objenv); DUK_D(DUK_DPRINT("duplicated global env: %!O", h_objenv)); DUK_HOBJENV_ASSERT_VALID((duk_hobjenv *) h_objenv); - duk_pop_2(thr); /* Pop global object and global env. */ + duk_pop_2(thr); /* Pop global object and global env. */ } -#endif /* DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT */ +#endif /* DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT */ DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { /* Setup builtins from ROM objects. All heaps/threads will share @@ -149,12 +149,12 @@ duk__duplicate_ram_global_object(thr); #endif } -#else /* DUK_USE_ROM_OBJECTS */ +#else /* DUK_USE_ROM_OBJECTS */ DUK_LOCAL void duk__push_stridx(duk_hthread *thr, duk_bitdecoder_ctx *bd) { duk_small_uint_t n; n = (duk_small_uint_t) duk_bd_decode_varuint(bd); - DUK_ASSERT_DISABLE(n >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(n >= 0); /* unsigned */ DUK_ASSERT(n < DUK_HEAP_NUM_STRINGS); duk_push_hstring_stridx(thr, n); } @@ -191,16 +191,18 @@ du.uci = (duk_uint8_t) duk_bd_decode(bd, 8); } - duk_push_number(thr, du.d); /* push operation normalizes NaNs */ + duk_push_number(thr, du.d); /* push operation normalizes NaNs */ } DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { duk_bitdecoder_ctx bd_ctx; - duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ + duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ duk_hobject *h; duk_small_uint_t i, j; - DUK_D(DUK_DPRINT("INITBUILTINS BEGIN: DUK_NUM_BUILTINS=%d, DUK_NUM_BUILTINS_ALL=%d", (int) DUK_NUM_BUILTINS, (int) DUK_NUM_ALL_BUILTINS)); + DUK_D(DUK_DPRINT("INITBUILTINS BEGIN: DUK_NUM_BUILTINS=%d, DUK_NUM_BUILTINS_ALL=%d", + (int) DUK_NUM_BUILTINS, + (int) DUK_NUM_ALL_BUILTINS)); duk_memzero(&bd_ctx, sizeof(bd_ctx)); bd->data = (const duk_uint8_t *) duk_builtins_data; @@ -227,14 +229,14 @@ DUK_ASSERT_TOP(thr, 0); for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) { duk_small_uint_t class_num; - duk_small_int_t len = -1; /* must be signed */ + duk_small_int_t len = -1; /* must be signed */ class_num = (duk_small_uint_t) duk_bd_decode_varuint(bd); len = (duk_small_int_t) duk_bd_decode_flagged_signed(bd, DUK__LENGTH_PROP_BITS, (duk_int32_t) -1 /*def_value*/); if (class_num == DUK_HOBJECT_CLASS_FUNCTION) { duk_small_uint_t natidx; - duk_small_int_t c_nargs; /* must hold DUK_VARARGS */ + duk_small_int_t c_nargs; /* must hold DUK_VARARGS */ duk_c_function c_func; duk_int16_t magic; @@ -265,12 +267,9 @@ duk__push_stridx_or_string(thr, bd); #if defined(DUK_USE_FUNC_NAME_PROPERTY) - duk_xdef_prop_stridx_short(thr, - -2, - DUK_STRIDX_NAME, - DUK_PROPDESC_FLAGS_C); + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); #else - duk_pop(thr); /* Not very ideal but good enough for now. */ + duk_pop(thr); /* Not very ideal but good enough for now. */ #endif /* Almost all global level Function objects are constructable @@ -296,8 +295,7 @@ DUK_ASSERT(DUK_BIDX_GLOBAL_ENV > DUK_BIDX_GLOBAL); env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(env->target == NULL); duk_push_hobject(thr, (duk_hobject *) env); @@ -312,10 +310,8 @@ DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_DECENV); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXTENSIBLE, - -1); /* no prototype or class yet */ - + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXTENSIBLE, + -1); /* no prototype or class yet */ } h = duk_known_hobject(thr, -1); @@ -337,18 +333,15 @@ * not encoded explicitly in init data. */ - DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_ARRAY); /* .length is virtual */ + DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_ARRAY); /* .length is virtual */ duk_push_int(thr, len); - duk_xdef_prop_stridx_short(thr, - -2, - DUK_STRIDX_LENGTH, - DUK_PROPDESC_FLAGS_C); + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); } /* enable exotic behaviors last */ if (class_num == DUK_HOBJECT_CLASS_ARRAY) { - DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)); /* set by duk_push_array() */ + DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)); /* set by duk_push_array() */ } if (class_num == DUK_HOBJECT_CLASS_STRING) { DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h); @@ -365,7 +358,7 @@ DUK_ASSERT(!DUK_HOBJECT_IS_PROXY(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(h) || class_num == DUK_HOBJECT_CLASS_ARRAY); /* DUK_HOBJECT_FLAG_STRICT varies */ - DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(h) || /* all native functions have NEWENV */ + DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(h) || /* all native functions have NEWENV */ DUK_HOBJECT_HAS_NEWENV(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_NAMEBINDING(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_CREATEARGS(h)); @@ -448,11 +441,9 @@ defprop_flags = (duk_small_uint_t) duk_bd_decode_flagged(bd, DUK__PROP_FLAGS_BITS, (duk_uint32_t) DUK_PROPDESC_FLAGS_WC); - defprop_flags |= DUK_DEFPROP_FORCE | - DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | + defprop_flags |= DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE | - DUK_DEFPROP_HAVE_CONFIGURABLE; /* Defaults for data properties. */ + DUK_DEFPROP_HAVE_CONFIGURABLE; /* Defaults for data properties. */ /* The writable, enumerable, configurable flags in prop_flags * match both duk_def_prop() and internal property flags. @@ -464,7 +455,11 @@ t = (duk_small_uint_t) duk_bd_decode(bd, DUK__PROP_TYPE_BITS); DUK_DDD(DUK_DDDPRINT("built-in %ld, normal-valued property %ld, key %!T, flags 0x%02lx, type %ld", - (long) i, (long) j, duk_get_tval(thr, -1), (unsigned long) defprop_flags, (long) t)); + (long) i, + (long) j, + duk_get_tval(thr, -1), + (unsigned long) defprop_flags, + (long) t)); switch (t) { case DUK__PROP_TYPE_DOUBLE: { @@ -505,24 +500,29 @@ duk_c_function c_func_getter; duk_c_function c_func_setter; - DUK_DDD(DUK_DDDPRINT("built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx", - (long) i, duk_get_tval(thr, -1), (long) natidx_getter, (long) natidx_setter, (unsigned long) defprop_flags)); + DUK_DDD(DUK_DDDPRINT( + "built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx", + (long) i, + duk_get_tval(thr, -1), + (long) natidx_getter, + (long) natidx_setter, + (unsigned long) defprop_flags)); c_func_getter = duk_bi_native_functionsnatidx_getter; if (c_func_getter != NULL) { - duk_push_c_function_builtin_noconstruct(thr, c_func_getter, 0); /* always 0 args */ + duk_push_c_function_builtin_noconstruct(thr, c_func_getter, 0); /* always 0 args */ duk_set_magic(thr, -1, (duk_int_t) accessor_magic); defprop_flags |= DUK_DEFPROP_HAVE_GETTER; } c_func_setter = duk_bi_native_functionsnatidx_setter; if (c_func_setter != NULL) { - duk_push_c_function_builtin_noconstruct(thr, c_func_setter, 1); /* always 1 arg */ + duk_push_c_function_builtin_noconstruct(thr, c_func_setter, 1); /* always 1 arg */ duk_set_magic(thr, -1, (duk_int_t) accessor_magic); defprop_flags |= DUK_DEFPROP_HAVE_SETTER; } /* Writable flag doesn't make sense for an accessor. */ - DUK_ASSERT((defprop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */ + DUK_ASSERT((defprop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */ defprop_flags &= ~(DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE); defprop_flags |= DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE; @@ -544,7 +544,7 @@ for (j = 0; j < num; j++) { duk_hstring *h_key; duk_small_uint_t natidx; - duk_int_t c_nargs; /* must hold DUK_VARARGS */ + duk_int_t c_nargs; /* must hold DUK_VARARGS */ duk_small_uint_t c_length; duk_int16_t magic; duk_c_function c_func; @@ -567,51 +567,66 @@ c_func = duk_bi_native_functionsnatidx; - DUK_DDD(DUK_DDDPRINT("built-in %ld, function-valued property %ld, key %!O, natidx %ld, length %ld, nargs %ld", - (long) i, (long) j, (duk_heaphdr *) h_key, (long) natidx, (long) c_length, - (c_nargs == DUK_VARARGS ? (long) -1 : (long) c_nargs))); + DUK_DDD( + DUK_DDDPRINT("built-in %ld, function-valued property %ld, key %!O, natidx %ld, length %ld, nargs %ld", + (long) i, + (long) j, + (duk_heaphdr *) h_key, + (long) natidx, + (long) c_length, + (c_nargs == DUK_VARARGS ? (long) -1 : (long) c_nargs))); /* Cast converts magic to 16-bit signed value */ magic = (duk_int16_t) duk_bd_decode_varuint(bd); #if defined(DUK_USE_LIGHTFUNC_BUILTINS) lightfunc_eligible = - ((c_nargs >= DUK_LFUNC_NARGS_MIN && c_nargs <= DUK_LFUNC_NARGS_MAX) || (c_nargs == DUK_VARARGS)) && - (c_length <= DUK_LFUNC_LENGTH_MAX) && - (magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX); + ((c_nargs >= DUK_LFUNC_NARGS_MIN && c_nargs <= DUK_LFUNC_NARGS_MAX) || (c_nargs == DUK_VARARGS)) && + (c_length <= DUK_LFUNC_LENGTH_MAX) && (magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX); /* These functions have trouble working as lightfuncs. * Some of them have specific asserts and some may have - * additional properties (e.g. 'require.id' may be written). + * additional properties (e.g. 'require.id' may be written). */ if (c_func == duk_bi_global_object_eval) { lightfunc_eligible = 0; } #if defined(DUK_USE_COROUTINE_SUPPORT) - if (c_func == duk_bi_thread_yield || - c_func == duk_bi_thread_resume) { + if (c_func == duk_bi_thread_yield || c_func == duk_bi_thread_resume) { lightfunc_eligible = 0; } #endif - if (c_func == duk_bi_function_prototype_call || - c_func == duk_bi_function_prototype_apply || - c_func == duk_bi_reflect_apply || - c_func == duk_bi_reflect_construct) { + if (c_func == duk_bi_function_prototype_call || c_func == duk_bi_function_prototype_apply || + c_func == duk_bi_reflect_apply || c_func == duk_bi_reflect_construct) { lightfunc_eligible = 0; } if (lightfunc_eligible) { duk_tval tv_lfunc; - duk_small_uint_t lf_nargs = (duk_small_uint_t) (c_nargs == DUK_VARARGS ? DUK_LFUNC_NARGS_VARARGS : c_nargs); + duk_small_uint_t lf_nargs = + (duk_small_uint_t) (c_nargs == DUK_VARARGS ? DUK_LFUNC_NARGS_VARARGS : c_nargs); duk_small_uint_t lf_flags = DUK_LFUNC_FLAGS_PACK(magic, c_length, lf_nargs); DUK_TVAL_SET_LIGHTFUNC(&tv_lfunc, c_func, lf_flags); duk_push_tval(thr, &tv_lfunc); - DUK_D(DUK_DPRINT("built-in function eligible as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld -> %!iT", (int) i, (int) j, (long) c_length, (long) c_nargs, (long) magic, duk_get_tval(thr, -1))); + DUK_D(DUK_DPRINT("built-in function eligible as light function: i=%d, j=%d c_length=%ld, " + "c_nargs=%ld, magic=%ld -> %!iT", + (int) i, + (int) j, + (long) c_length, + (long) c_nargs, + (long) magic, + duk_get_tval(thr, -1))); goto lightfunc_skip; } - DUK_D(DUK_DPRINT("built-in function NOT ELIGIBLE as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld", (int) i, (int) j, (long) c_length, (long) c_nargs, (long) magic)); -#endif /* DUK_USE_LIGHTFUNC_BUILTINS */ + DUK_D(DUK_DPRINT( + "built-in function NOT ELIGIBLE as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld", + (int) i, + (int) j, + (long) c_length, + (long) c_nargs, + (long) magic)); +#endif /* DUK_USE_LIGHTFUNC_BUILTINS */ /* (builtin objects) name */ @@ -622,10 +637,8 @@ /* XXX: add into init data? */ /* Special call handling, not described in init data. */ - if (c_func == duk_bi_global_object_eval || - c_func == duk_bi_function_prototype_call || - c_func == duk_bi_function_prototype_apply || - c_func == duk_bi_reflect_apply || + if (c_func == duk_bi_global_object_eval || c_func == duk_bi_function_prototype_call || + c_func == duk_bi_function_prototype_apply || c_func == duk_bi_reflect_apply || c_func == duk_bi_reflect_construct) { DUK_HOBJECT_SET_SPECIAL_CALL((duk_hobject *) h_func); } @@ -659,7 +672,9 @@ /* XXX: other properties of function instances; 'arguments', 'caller'. */ DUK_DD(DUK_DDPRINT("built-in object %ld, function property %ld -> %!T", - (long) i, (long) j, (duk_tval *) duk_get_tval(thr, -1))); + (long) i, + (long) j, + (duk_tval *) duk_get_tval(thr, -1))); /* (builtin objects) name func */ @@ -669,17 +684,14 @@ */ #if defined(DUK_USE_LIGHTFUNC_BUILTINS) - lightfunc_skip: + lightfunc_skip: #endif defprop_flags = (duk_small_uint_t) duk_bd_decode_flagged(bd, DUK__PROP_FLAGS_BITS, (duk_uint32_t) DUK_PROPDESC_FLAGS_WC); - defprop_flags |= DUK_DEFPROP_FORCE | - DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | - DUK_DEFPROP_HAVE_ENUMERABLE | - DUK_DEFPROP_HAVE_CONFIGURABLE; + defprop_flags |= DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | + DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE; DUK_ASSERT(DUK_PROPDESC_FLAG_WRITABLE == DUK_DEFPROP_WRITABLE); DUK_ASSERT(DUK_PROPDESC_FLAG_ENUMERABLE == DUK_DEFPROP_ENUMERABLE); DUK_ASSERT(DUK_PROPDESC_FLAG_CONFIGURABLE == DUK_DEFPROP_CONFIGURABLE); @@ -717,22 +729,28 @@ #if !defined(DUK_USE_ES6_OBJECT_PROTO_PROPERTY) DUK_DD(DUK_DDPRINT("delete Object.prototype.__proto__ built-in which is not enabled in features")); - (void) duk_hobject_delprop_raw(thr, thr->builtinsDUK_BIDX_OBJECT_PROTOTYPE, DUK_HTHREAD_STRING___PROTO__(thr), DUK_DELPROP_FLAG_THROW); + (void) duk_hobject_delprop_raw(thr, + thr->builtinsDUK_BIDX_OBJECT_PROTOTYPE, + DUK_HTHREAD_STRING___PROTO__(thr), + DUK_DELPROP_FLAG_THROW); #endif #if !defined(DUK_USE_ES6_OBJECT_SETPROTOTYPEOF) DUK_DD(DUK_DDPRINT("delete Object.setPrototypeOf built-in which is not enabled in features")); - (void) duk_hobject_delprop_raw(thr, thr->builtinsDUK_BIDX_OBJECT_CONSTRUCTOR, DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr), DUK_DELPROP_FLAG_THROW); + (void) duk_hobject_delprop_raw(thr, + thr->builtinsDUK_BIDX_OBJECT_CONSTRUCTOR, + DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr), + DUK_DELPROP_FLAG_THROW); #endif /* XXX: relocate */ duk_push_string(thr, - /* Endianness indicator */ + /* Endianness indicator */ #if defined(DUK_USE_INTEGER_LE) "l" #elif defined(DUK_USE_INTEGER_BE) "b" -#elif defined(DUK_USE_INTEGER_ME) /* integer mixed endian not really used now */ +#elif defined(DUK_USE_INTEGER_ME) /* integer mixed endian not really used now */ "m" #else "?" @@ -747,89 +765,85 @@ "?" #endif " " - /* Packed or unpacked tval */ + /* Packed or unpacked tval */ #if defined(DUK_USE_PACKED_TVAL) "p" #else "u" #endif #if defined(DUK_USE_FASTINT) - "f" + "f" #endif - " " - /* Low memory/performance options */ + " " + /* Low memory/performance options */ #if defined(DUK_USE_STRTAB_PTRCOMP) - "s" + "s" #endif #if !defined(DUK_USE_HEAPPTR16) && !defined(DUK_DATAPTR16) && !defined(DUK_FUNCPTR16) - "n" + "n" #endif #if defined(DUK_USE_HEAPPTR16) - "h" + "h" #endif #if defined(DUK_USE_DATAPTR16) - "d" + "d" #endif #if defined(DUK_USE_FUNCPTR16) - "f" + "f" #endif #if defined(DUK_USE_REFCOUNT16) - "R" + "R" #endif #if defined(DUK_USE_STRHASH16) - "H" + "H" #endif #if defined(DUK_USE_STRLEN16) - "S" + "S" #endif #if defined(DUK_USE_BUFLEN16) - "B" + "B" #endif #if defined(DUK_USE_OBJSIZES16) - "O" + "O" #endif #if defined(DUK_USE_LIGHTFUNC_BUILTINS) - "L" + "L" #endif #if defined(DUK_USE_ROM_STRINGS) || defined(DUK_USE_ROM_OBJECTS) - /* XXX: This won't be shown in practice now - * because this code is not run when builtins - * are in ROM. - */ - "Z" + /* XXX: This won't be shown in practice now + * because this code is not run when builtins + * are in ROM. + */ + "Z" #endif #if defined(DUK_USE_LITCACHE_SIZE) - "l" + "l" #endif " " - /* Object property allocation layout */ + /* Object property allocation layout */ #if defined(DUK_USE_HOBJECT_LAYOUT_1) - "p1" + "p1" #elif defined(DUK_USE_HOBJECT_LAYOUT_2) - "p2" + "p2" #elif defined(DUK_USE_HOBJECT_LAYOUT_3) - "p3" + "p3" #else - "p?" + "p?" #endif - " " - /* Alignment guarantee */ + " " + /* Alignment guarantee */ #if (DUK_USE_ALIGN_BY == 4) - "a4" + "a4" #elif (DUK_USE_ALIGN_BY == 8) - "a8" + "a8" #elif (DUK_USE_ALIGN_BY == 1) - "a1" + "a1" #else #error invalid DUK_USE_ALIGN_BY #endif - " " - /* Architecture, OS, and compiler strings */ - DUK_USE_ARCH_STRING - " " - DUK_USE_OS_STRING - " " - DUK_USE_COMPILER_STRING); + " " + /* Architecture, OS, and compiler strings */ + DUK_USE_ARCH_STRING " " DUK_USE_OS_STRING " " DUK_USE_COMPILER_STRING); duk_xdef_prop_stridx_short(thr, DUK_BIDX_DUKTAPE, DUK_STRIDX_ENV, DUK_PROPDESC_FLAGS_WC); /* @@ -846,7 +860,8 @@ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) { DUK_DD(DUK_DDPRINT("built-in object %ld after initialization and compacting: %!@iO", - (long) i, (duk_heaphdr *) duk_require_hobject(thr, (duk_idx_t) i))); + (long) i, + (duk_heaphdr *) duk_require_hobject(thr, (duk_idx_t) i))); } #endif @@ -859,13 +874,13 @@ duk_set_top(thr, 0); DUK_ASSERT_TOP(thr, 0); } -#endif /* DUK_USE_ROM_OBJECTS */ +#endif /* DUK_USE_ROM_OBJECTS */ DUK_INTERNAL void duk_hthread_copy_builtin_objects(duk_hthread *thr_from, duk_hthread *thr_to) { duk_small_uint_t i; for (i = 0; i < DUK_NUM_BUILTINS; i++) { thr_to->builtinsi = thr_from->builtinsi; - DUK_HOBJECT_INCREF_ALLOWNULL(thr_to, thr_to->builtinsi); /* side effect free */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr_to, thr_to->builtinsi); /* side effect free */ } }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hthread_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hthread_misc.c
Changed
@@ -12,7 +12,7 @@ } thr->valstack_bottom = thr->valstack; - duk_set_top(thr, 0); /* unwinds valstack, updating refcounts */ + duk_set_top(thr, 0); /* unwinds valstack, updating refcounts */ thr->state = DUK_HTHREAD_STATE_TERMINATED; @@ -43,7 +43,7 @@ } return 0; } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ DUK_INTERNAL duk_uint_fast32_t duk_hthread_get_act_prev_pc(duk_hthread *thr, duk_activation *act) { duk_instr_t *bcode;
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_hthread_stacks.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_hthread_stacks.c
Changed
@@ -15,7 +15,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(act != NULL); - DUK_ASSERT(act->cat != NULL); /* caller must check */ + DUK_ASSERT(act->cat != NULL); /* caller must check */ cat = act->cat; DUK_ASSERT(cat != NULL); @@ -24,9 +24,9 @@ if (DUK_CAT_HAS_LEXENV_ACTIVE(cat)) { duk_hobject *env; - env = act->lex_env; /* current lex_env of the activation (created for catcher) */ - DUK_ASSERT(env != NULL); /* must be, since env was created when catcher was created */ - act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); /* prototype is lex_env before catcher created */ + env = act->lex_env; /* current lex_env of the activation (created for catcher) */ + DUK_ASSERT(env != NULL); /* must be, since env was created when catcher was created */ + act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); /* prototype is lex_env before catcher created */ DUK_HOBJECT_INCREF(thr, act->lex_env); DUK_HOBJECT_DECREF_NORZ(thr, env); @@ -45,7 +45,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(act != NULL); - DUK_ASSERT(act->cat != NULL); /* caller must check */ + DUK_ASSERT(act->cat != NULL); /* caller must check */ cat = act->cat; DUK_ASSERT(cat != NULL); @@ -83,11 +83,11 @@ return duk__hthread_catcher_alloc_slow(thr); } -#else /* DUK_USE_CACHE_CATCHER */ +#else /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL duk_catcher *duk_hthread_catcher_alloc(duk_hthread *thr) { return duk__hthread_catcher_alloc_slow(thr); } -#endif /* DUK_USE_CACHE_CATCHER */ +#endif /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL void duk_hthread_catcher_free(duk_hthread *thr, duk_catcher *cat) { DUK_ASSERT(thr != NULL); @@ -128,12 +128,11 @@ return duk__hthread_activation_alloc_slow(thr); } -#else /* DUK_USE_CACHE_ACTIVATION */ +#else /* DUK_USE_CACHE_ACTIVATION */ DUK_INTERNAL duk_activation *duk_hthread_activation_alloc(duk_hthread *thr) { return duk__hthread_activation_alloc_slow(thr); } -#endif /* DUK_USE_CACHE_ACTIVATION */ - +#endif /* DUK_USE_CACHE_ACTIVATION */ DUK_INTERNAL void duk_hthread_activation_free(duk_hthread *thr, duk_activation *act) { DUK_ASSERT(thr != NULL); @@ -160,7 +159,7 @@ duk_hobject *tmp; DUK_ASSERT(thr != NULL); - DUK_ASSERT(thr->callstack_curr != NULL); /* caller must check */ + DUK_ASSERT(thr->callstack_curr != NULL); /* caller must check */ DUK_ASSERT(thr->callstack_top > 0); act = thr->callstack_curr; DUK_ASSERT(act != NULL); @@ -197,7 +196,7 @@ DUK_TVAL_SET_OBJECT(tv_caller, act->prev_caller); act->prev_caller = NULL; } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref needed */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref needed */ DUK_ASSERT(act->prev_caller == NULL); } DUK_TVAL_DECREF_NORZ(thr, &tv_tmp); @@ -226,7 +225,7 @@ duk_debug_set_paused(heap); } else { DUK_D(DUK_DPRINT("unwound past dbg_pause_act, set to NULL")); - heap->dbg_pause_act = NULL; /* avoid stale pointers */ + heap->dbg_pause_act = NULL; /* avoid stale pointers */ } DUK_ASSERT(heap->dbg_pause_act == NULL); } @@ -275,12 +274,11 @@ * fixed e.g. by preallocating the scope property slots. */ if (act->var_env != NULL) { - DUK_DDD(DUK_DDDPRINT("closing var_env record %p -> %!O", - (void *) act->var_env, (duk_heaphdr *) act->var_env)); + DUK_DDD(DUK_DDDPRINT("closing var_env record %p -> %!O", (void *) act->var_env, (duk_heaphdr *) act->var_env)); duk_js_close_environment_record(thr, act->var_env); } - skip_env_close: +skip_env_close: /* * Update preventcount @@ -404,4 +402,4 @@ DUK_D(DUK_DPRINT("failed to realloc valstack for torture, ignore")); } } -#endif /* DUK_USE_FINALIZER_TORTURE */ +#endif /* DUK_USE_FINALIZER_TORTURE */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_internal.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_internal.h
Changed
@@ -40,8 +40,8 @@ #include "duk_jmpbuf.h" #include "duk_exception.h" #include "duk_forwdecl.h" -#include "duk_tval.h" /* builtins need e.g. duk_tval tag definitions */ -#include "duk_builtins.h" /* autogenerated: strings and built-in object init data */ +#include "duk_tval.h" /* builtins need e.g. duk_tval tag definitions */ +#include "duk_builtins.h" /* autogenerated: strings and built-in object init data */ #include "duk_util.h" #include "duk_strings.h" @@ -74,4 +74,4 @@ #include "duk_bi_protos.h" #include "duk_selftest.h" -#endif /* DUK_INTERNAL_H_INCLUDED */ +#endif /* DUK_INTERNAL_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_jmpbuf.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_jmpbuf.h
Changed
@@ -13,7 +13,7 @@ #if defined(DUK_USE_CPP_EXCEPTIONS) struct duk_jmpbuf { - duk_small_int_t dummy; /* unused */ + duk_small_int_t dummy; /* unused */ }; #else struct duk_jmpbuf { @@ -21,4 +21,4 @@ }; #endif -#endif /* DUK_JMPBUF_H_INCLUDED */ +#endif /* DUK_JMPBUF_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_js.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_js.h
Changed
@@ -6,21 +6,22 @@ #define DUK_JS_H_INCLUDED /* Flags for call handling. Lowest flags must match bytecode DUK_BC_CALL_FLAG_xxx 1:1. */ -#define DUK_CALL_FLAG_TAILCALL (1U << 0) /* setup for a tail call */ -#define DUK_CALL_FLAG_CONSTRUCT (1U << 1) /* constructor call (i.e. called as 'new Foo()') */ -#define DUK_CALL_FLAG_CALLED_AS_EVAL (1U << 2) /* call was made using the identifier 'eval' */ -#define DUK_CALL_FLAG_ALLOW_ECMATOECMA (1U << 3) /* ecma-to-ecma call with executor reuse is possible */ -#define DUK_CALL_FLAG_DIRECT_EVAL (1U << 4) /* call is a direct eval call */ -#define DUK_CALL_FLAG_CONSTRUCT_PROXY (1U << 5) /* handled via 'construct' proxy trap, check return value invariant(s) */ -#define DUK_CALL_FLAG_DEFAULT_INSTANCE_UPDATED (1U << 6) /* prototype of 'default instance' updated, temporary flag in call handling */ +#define DUK_CALL_FLAG_TAILCALL (1U << 0) /* setup for a tail call */ +#define DUK_CALL_FLAG_CONSTRUCT (1U << 1) /* constructor call (i.e. called as 'new Foo()') */ +#define DUK_CALL_FLAG_CALLED_AS_EVAL (1U << 2) /* call was made using the identifier 'eval' */ +#define DUK_CALL_FLAG_ALLOW_ECMATOECMA (1U << 3) /* ecma-to-ecma call with executor reuse is possible */ +#define DUK_CALL_FLAG_DIRECT_EVAL (1U << 4) /* call is a direct eval call */ +#define DUK_CALL_FLAG_CONSTRUCT_PROXY (1U << 5) /* handled via 'construct' proxy trap, check return value invariant(s) */ +#define DUK_CALL_FLAG_DEFAULT_INSTANCE_UPDATED \ + (1U << 6) /* prototype of 'default instance' updated, temporary flag in call handling */ /* Flags for duk_js_equals_helper(). */ -#define DUK_EQUALS_FLAG_SAMEVALUE (1U << 0) /* use SameValue instead of non-strict equality */ -#define DUK_EQUALS_FLAG_STRICT (1U << 1) /* use strict equality instead of non-strict equality */ +#define DUK_EQUALS_FLAG_SAMEVALUE (1U << 0) /* use SameValue instead of non-strict equality */ +#define DUK_EQUALS_FLAG_STRICT (1U << 1) /* use strict equality instead of non-strict equality */ /* Flags for duk_js_compare_helper(). */ -#define DUK_COMPARE_FLAG_NEGATE (1U << 0) /* negate result */ -#define DUK_COMPARE_FLAG_EVAL_LEFT_FIRST (1U << 1) /* eval left argument first */ +#define DUK_COMPARE_FLAG_NEGATE (1U << 0) /* negate result */ +#define DUK_COMPARE_FLAG_EVAL_LEFT_FIRST (1U << 1) /* eval left argument first */ /* conversions, coercions, comparison, etc */ DUK_INTERNAL_DECL duk_bool_t duk_js_toboolean(duk_tval *tv); @@ -36,9 +37,12 @@ DUK_INTERNAL_DECL duk_uarridx_t duk_js_to_arrayindex_hstring_fast(duk_hstring *h); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_equals_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags); -DUK_INTERNAL_DECL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, const duk_uint8_t *buf2, duk_size_t len1, duk_size_t len2); +DUK_INTERNAL_DECL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, + const duk_uint8_t *buf2, + duk_size_t len1, + duk_size_t len2); DUK_INTERNAL_DECL duk_small_int_t duk_js_string_compare(duk_hstring *h1, duk_hstring *h2); -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL_DECL duk_small_int_t duk_js_buffer_compare(duk_heap *heap, duk_hbuffer *h1, duk_hbuffer *h2); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_compare_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags); @@ -55,45 +59,57 @@ DUK_INTERNAL_DECL double duk_js_arith_pow(double x, double y); DUK_INTERNAL_DECL double duk_js_arith_mod(double x, double y); -#define duk_js_equals(thr,tv_x,tv_y) \ - duk_js_equals_helper((thr), (tv_x), (tv_y), 0) -#define duk_js_strict_equals(tv_x,tv_y) \ - duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_STRICT) -#define duk_js_samevalue(tv_x,tv_y) \ - duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_SAMEVALUE) +#define duk_js_equals(thr, tv_x, tv_y) duk_js_equals_helper((thr), (tv_x), (tv_y), 0) +#define duk_js_strict_equals(tv_x, tv_y) duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_STRICT) +#define duk_js_samevalue(tv_x, tv_y) duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_SAMEVALUE) /* E5 Sections 11.8.1, 11.8.5; x < y */ -#define duk_js_lessthan(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_x), (tv_Y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) +#define duk_js_lessthan(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_x), (tv_Y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) /* E5 Sections 11.8.2, 11.8.5; x > y --> y < x */ -#define duk_js_greaterthan(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_y), (tv_x), 0) +#define duk_js_greaterthan(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_y), (tv_x), 0) /* E5 Sections 11.8.3, 11.8.5; x <= y --> not (x > y) --> not (y < x) */ -#define duk_js_lessthanorequal(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_y), (tv_x), DUK_COMPARE_FLAG_NEGATE) +#define duk_js_lessthanorequal(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_y), (tv_x), DUK_COMPARE_FLAG_NEGATE) /* E5 Sections 11.8.4, 11.8.5; x >= y --> not (x < y) */ -#define duk_js_greaterthanorequal(thr,tv_x,tv_y) \ +#define duk_js_greaterthanorequal(thr, tv_x, tv_y) \ duk_js_compare_helper((thr), (tv_x), (tv_y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) /* identifiers and environment handling */ -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_hasvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_bool_t throw_flag); -DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag); -DUK_INTERNAL_DECL void duk_js_putvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_tval *val, duk_bool_t strict); -DUK_INTERNAL_DECL void duk_js_putvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_bool_t strict); -#if 0 /*unused*/ +DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_bool_t throw_flag); +DUK_INTERNAL_DECL void duk_js_putvar_envrec(duk_hthread *thr, + duk_hobject *env, + duk_hstring *name, + duk_tval *val, + duk_bool_t strict); +DUK_INTERNAL_DECL void duk_js_putvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_tval *val, + duk_bool_t strict); +#if 0 /*unused*/ DUK_INTERNAL_DECL duk_bool_t duk_js_delvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_delvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name); -DUK_INTERNAL_DECL duk_bool_t duk_js_declvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_small_uint_t prop_flags, duk_bool_t is_func_decl); +DUK_INTERNAL_DECL duk_bool_t duk_js_declvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_tval *val, + duk_small_uint_t prop_flags, + duk_bool_t is_func_decl); DUK_INTERNAL_DECL void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, duk_activation *act); DUK_INTERNAL_DECL void duk_js_close_environment_record(duk_hthread *thr, duk_hobject *env); -DUK_INTERNAL_DECL duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, duk_hobject *func, duk_size_t bottom_byteoff); +DUK_INTERNAL_DECL duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, + duk_hobject *func, + duk_size_t bottom_byteoff); DUK_INTERNAL_DECL void duk_js_push_closure(duk_hthread *thr, duk_hcompfunc *fun_temp, duk_hobject *outer_var_env, @@ -104,7 +120,8 @@ DUK_INTERNAL_DECL void duk_native_stack_check(duk_hthread *thr); DUK_INTERNAL_DECL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags); DUK_INTERNAL_DECL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags); -DUK_INTERNAL_DECL duk_int_t duk_handle_safe_call(duk_hthread *thr, duk_safe_call_function func, void *udata, duk_idx_t num_stack_args, duk_idx_t num_stack_res); +DUK_INTERNAL_DECL duk_int_t +duk_handle_safe_call(duk_hthread *thr, duk_safe_call_function func, void *udata, duk_idx_t num_stack_args, duk_idx_t num_stack_res); DUK_INTERNAL_DECL void duk_call_construct_postprocess(duk_hthread *thr, duk_small_uint_t proxy_invariant); #if defined(DUK_USE_VERBOSE_ERRORS) DUK_INTERNAL_DECL void duk_call_setup_propcall_error(duk_hthread *thr, duk_tval *tv_base, duk_tval *tv_key); @@ -113,4 +130,4 @@ /* bytecode execution */ DUK_INTERNAL_DECL void duk_js_execute_bytecode(duk_hthread *exec_thr); -#endif /* DUK_JS_H_INCLUDED */ +#endif /* DUK_JS_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_js_arith.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_js_arith.c
Changed
@@ -41,10 +41,14 @@ DUK_ASSERT(DUK_ISNAN(DUK_FMOD(-DUK_DOUBLE_INFINITY, -DUK_DOUBLE_INFINITY))); DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, 1.0), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, 1.0)) == 0); DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, 1.0), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, 1.0)) != 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY)) != 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, -DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY)) != 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY)) != 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, -DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY)) != 0); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(0.0, 0.0))); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(-0.0, 0.0))); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(0.0, -0.0))); @@ -132,6 +136,6 @@ return DUK_POW(x, y); - ret_nan: +ret_nan: return DUK_DOUBLE_NAN; }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_js_bytecode.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_js_bytecode.h
Changed
@@ -83,400 +83,391 @@ typedef duk_uint32_t duk_instr_t; -#define DUK_BC_SHIFT_OP 0 -#define DUK_BC_SHIFT_A 8 -#define DUK_BC_SHIFT_B 16 -#define DUK_BC_SHIFT_C 24 -#define DUK_BC_SHIFT_BC DUK_BC_SHIFT_B -#define DUK_BC_SHIFT_ABC DUK_BC_SHIFT_A +#define DUK_BC_SHIFT_OP 0 +#define DUK_BC_SHIFT_A 8 +#define DUK_BC_SHIFT_B 16 +#define DUK_BC_SHIFT_C 24 +#define DUK_BC_SHIFT_BC DUK_BC_SHIFT_B +#define DUK_BC_SHIFT_ABC DUK_BC_SHIFT_A -#define DUK_BC_UNSHIFTED_MASK_OP 0xffUL -#define DUK_BC_UNSHIFTED_MASK_A 0xffUL -#define DUK_BC_UNSHIFTED_MASK_B 0xffUL -#define DUK_BC_UNSHIFTED_MASK_C 0xffUL -#define DUK_BC_UNSHIFTED_MASK_BC 0xffffUL -#define DUK_BC_UNSHIFTED_MASK_ABC 0xffffffUL +#define DUK_BC_UNSHIFTED_MASK_OP 0xffUL +#define DUK_BC_UNSHIFTED_MASK_A 0xffUL +#define DUK_BC_UNSHIFTED_MASK_B 0xffUL +#define DUK_BC_UNSHIFTED_MASK_C 0xffUL +#define DUK_BC_UNSHIFTED_MASK_BC 0xffffUL +#define DUK_BC_UNSHIFTED_MASK_ABC 0xffffffUL -#define DUK_BC_SHIFTED_MASK_OP (DUK_BC_UNSHIFTED_MASK_OP << DUK_BC_SHIFT_OP) -#define DUK_BC_SHIFTED_MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK_BC_SHIFT_A) -#define DUK_BC_SHIFTED_MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK_BC_SHIFT_B) -#define DUK_BC_SHIFTED_MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK_BC_SHIFT_C) -#define DUK_BC_SHIFTED_MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK_BC_SHIFT_BC) -#define DUK_BC_SHIFTED_MASK_ABC (DUK_BC_UNSHIFTED_MASK_ABC << DUK_BC_SHIFT_ABC) +#define DUK_BC_SHIFTED_MASK_OP (DUK_BC_UNSHIFTED_MASK_OP << DUK_BC_SHIFT_OP) +#define DUK_BC_SHIFTED_MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK_BC_SHIFT_A) +#define DUK_BC_SHIFTED_MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK_BC_SHIFT_B) +#define DUK_BC_SHIFTED_MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK_BC_SHIFT_C) +#define DUK_BC_SHIFTED_MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK_BC_SHIFT_BC) +#define DUK_BC_SHIFTED_MASK_ABC (DUK_BC_UNSHIFTED_MASK_ABC << DUK_BC_SHIFT_ABC) -#define DUK_DEC_OP(x) ((x) & 0xffUL) -#define DUK_DEC_A(x) (((x) >> 8) & 0xffUL) -#define DUK_DEC_B(x) (((x) >> 16) & 0xffUL) -#define DUK_DEC_C(x) (((x) >> 24) & 0xffUL) -#define DUK_DEC_BC(x) (((x) >> 16) & 0xffffUL) -#define DUK_DEC_ABC(x) (((x) >> 8) & 0xffffffUL) +#define DUK_DEC_OP(x) ((x) &0xffUL) +#define DUK_DEC_A(x) (((x) >> 8) & 0xffUL) +#define DUK_DEC_B(x) (((x) >> 16) & 0xffUL) +#define DUK_DEC_C(x) (((x) >> 24) & 0xffUL) +#define DUK_DEC_BC(x) (((x) >> 16) & 0xffffUL) +#define DUK_DEC_ABC(x) (((x) >> 8) & 0xffffffUL) -#define DUK_ENC_OP(op) ((duk_instr_t) (op)) -#define DUK_ENC_OP_ABC(op,abc) ((duk_instr_t) ( \ - (((duk_instr_t) (abc)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_BC(op,a,bc) ((duk_instr_t) ( \ - (((duk_instr_t) (bc)) << 16) | \ - (((duk_instr_t) (a)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_B_C(op,a,b,c) ((duk_instr_t) ( \ - (((duk_instr_t) (c)) << 24) | \ - (((duk_instr_t) (b)) << 16) | \ - (((duk_instr_t) (a)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_B(op,a,b) DUK_ENC_OP_A_B_C((op),(a),(b),0) -#define DUK_ENC_OP_A(op,a) DUK_ENC_OP_A_B_C((op),(a),0,0) -#define DUK_ENC_OP_BC(op,bc) DUK_ENC_OP_A_BC((op),0,(bc)) +#define DUK_ENC_OP(op) ((duk_instr_t) (op)) +#define DUK_ENC_OP_ABC(op, abc) ((duk_instr_t) ((((duk_instr_t) (abc)) << 8) | ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_BC(op, a, bc) \ + ((duk_instr_t) ((((duk_instr_t) (bc)) << 16) | (((duk_instr_t) (a)) << 8) | ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_B_C(op, a, b, c) \ + ((duk_instr_t) ((((duk_instr_t) (c)) << 24) | (((duk_instr_t) (b)) << 16) | (((duk_instr_t) (a)) << 8) | \ + ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_B(op, a, b) DUK_ENC_OP_A_B_C((op), (a), (b), 0) +#define DUK_ENC_OP_A(op, a) DUK_ENC_OP_A_B_C((op), (a), 0, 0) +#define DUK_ENC_OP_BC(op, bc) DUK_ENC_OP_A_BC((op), 0, (bc)) /* Get opcode base value with B/C reg/const flags cleared. */ -#define DUK_BC_NOREGCONST_OP(op) ((op) & 0xfc) +#define DUK_BC_NOREGCONST_OP(op) ((op) &0xfc) /* Constants should be signed so that signed arithmetic involving them * won't cause values to be coerced accidentally to unsigned. */ -#define DUK_BC_OP_MIN 0 -#define DUK_BC_OP_MAX 0xffL -#define DUK_BC_A_MIN 0 -#define DUK_BC_A_MAX 0xffL -#define DUK_BC_B_MIN 0 -#define DUK_BC_B_MAX 0xffL -#define DUK_BC_C_MIN 0 -#define DUK_BC_C_MAX 0xffL -#define DUK_BC_BC_MIN 0 -#define DUK_BC_BC_MAX 0xffffL -#define DUK_BC_ABC_MIN 0 -#define DUK_BC_ABC_MAX 0xffffffL +#define DUK_BC_OP_MIN 0 +#define DUK_BC_OP_MAX 0xffL +#define DUK_BC_A_MIN 0 +#define DUK_BC_A_MAX 0xffL +#define DUK_BC_B_MIN 0 +#define DUK_BC_B_MAX 0xffL +#define DUK_BC_C_MIN 0 +#define DUK_BC_C_MAX 0xffL +#define DUK_BC_BC_MIN 0 +#define DUK_BC_BC_MAX 0xffffL +#define DUK_BC_ABC_MIN 0 +#define DUK_BC_ABC_MAX 0xffffffL /* Masks for B/C reg/const indicator in opcode field. */ -#define DUK_BC_REGCONST_B (0x01UL) -#define DUK_BC_REGCONST_C (0x02UL) +#define DUK_BC_REGCONST_B (0x01UL) +#define DUK_BC_REGCONST_C (0x02UL) /* Misc. masks for opcode field. */ -#define DUK_BC_INCDECP_FLAG_DEC (0x04UL) -#define DUK_BC_INCDECP_FLAG_POST (0x08UL) +#define DUK_BC_INCDECP_FLAG_DEC (0x04UL) +#define DUK_BC_INCDECP_FLAG_POST (0x08UL) /* Opcodes. */ -#define DUK_OP_LDREG 0 -#define DUK_OP_STREG 1 -#define DUK_OP_JUMP 2 -#define DUK_OP_LDCONST 3 -#define DUK_OP_LDINT 4 -#define DUK_OP_LDINTX 5 -#define DUK_OP_LDTHIS 6 -#define DUK_OP_LDUNDEF 7 -#define DUK_OP_LDNULL 8 -#define DUK_OP_LDTRUE 9 -#define DUK_OP_LDFALSE 10 -#define DUK_OP_GETVAR 11 -#define DUK_OP_BNOT 12 -#define DUK_OP_LNOT 13 -#define DUK_OP_UNM 14 -#define DUK_OP_UNP 15 -#define DUK_OP_EQ 16 -#define DUK_OP_EQ_RR 16 -#define DUK_OP_EQ_CR 17 -#define DUK_OP_EQ_RC 18 -#define DUK_OP_EQ_CC 19 -#define DUK_OP_NEQ 20 -#define DUK_OP_NEQ_RR 20 -#define DUK_OP_NEQ_CR 21 -#define DUK_OP_NEQ_RC 22 -#define DUK_OP_NEQ_CC 23 -#define DUK_OP_SEQ 24 -#define DUK_OP_SEQ_RR 24 -#define DUK_OP_SEQ_CR 25 -#define DUK_OP_SEQ_RC 26 -#define DUK_OP_SEQ_CC 27 -#define DUK_OP_SNEQ 28 -#define DUK_OP_SNEQ_RR 28 -#define DUK_OP_SNEQ_CR 29 -#define DUK_OP_SNEQ_RC 30 -#define DUK_OP_SNEQ_CC 31 -#define DUK_OP_GT 32 -#define DUK_OP_GT_RR 32 -#define DUK_OP_GT_CR 33 -#define DUK_OP_GT_RC 34 -#define DUK_OP_GT_CC 35 -#define DUK_OP_GE 36 -#define DUK_OP_GE_RR 36 -#define DUK_OP_GE_CR 37 -#define DUK_OP_GE_RC 38 -#define DUK_OP_GE_CC 39 -#define DUK_OP_LT 40 -#define DUK_OP_LT_RR 40 -#define DUK_OP_LT_CR 41 -#define DUK_OP_LT_RC 42 -#define DUK_OP_LT_CC 43 -#define DUK_OP_LE 44 -#define DUK_OP_LE_RR 44 -#define DUK_OP_LE_CR 45 -#define DUK_OP_LE_RC 46 -#define DUK_OP_LE_CC 47 -#define DUK_OP_IFTRUE 48 -#define DUK_OP_IFTRUE_R 48 -#define DUK_OP_IFTRUE_C 49 -#define DUK_OP_IFFALSE 50 -#define DUK_OP_IFFALSE_R 50 -#define DUK_OP_IFFALSE_C 51 -#define DUK_OP_ADD 52 -#define DUK_OP_ADD_RR 52 -#define DUK_OP_ADD_CR 53 -#define DUK_OP_ADD_RC 54 -#define DUK_OP_ADD_CC 55 -#define DUK_OP_SUB 56 -#define DUK_OP_SUB_RR 56 -#define DUK_OP_SUB_CR 57 -#define DUK_OP_SUB_RC 58 -#define DUK_OP_SUB_CC 59 -#define DUK_OP_MUL 60 -#define DUK_OP_MUL_RR 60 -#define DUK_OP_MUL_CR 61 -#define DUK_OP_MUL_RC 62 -#define DUK_OP_MUL_CC 63 -#define DUK_OP_DIV 64 -#define DUK_OP_DIV_RR 64 -#define DUK_OP_DIV_CR 65 -#define DUK_OP_DIV_RC 66 -#define DUK_OP_DIV_CC 67 -#define DUK_OP_MOD 68 -#define DUK_OP_MOD_RR 68 -#define DUK_OP_MOD_CR 69 -#define DUK_OP_MOD_RC 70 -#define DUK_OP_MOD_CC 71 -#define DUK_OP_EXP 72 -#define DUK_OP_EXP_RR 72 -#define DUK_OP_EXP_CR 73 -#define DUK_OP_EXP_RC 74 -#define DUK_OP_EXP_CC 75 -#define DUK_OP_BAND 76 -#define DUK_OP_BAND_RR 76 -#define DUK_OP_BAND_CR 77 -#define DUK_OP_BAND_RC 78 -#define DUK_OP_BAND_CC 79 -#define DUK_OP_BOR 80 -#define DUK_OP_BOR_RR 80 -#define DUK_OP_BOR_CR 81 -#define DUK_OP_BOR_RC 82 -#define DUK_OP_BOR_CC 83 -#define DUK_OP_BXOR 84 -#define DUK_OP_BXOR_RR 84 -#define DUK_OP_BXOR_CR 85 -#define DUK_OP_BXOR_RC 86 -#define DUK_OP_BXOR_CC 87 -#define DUK_OP_BASL 88 -#define DUK_OP_BASL_RR 88 -#define DUK_OP_BASL_CR 89 -#define DUK_OP_BASL_RC 90 -#define DUK_OP_BASL_CC 91 -#define DUK_OP_BLSR 92 -#define DUK_OP_BLSR_RR 92 -#define DUK_OP_BLSR_CR 93 -#define DUK_OP_BLSR_RC 94 -#define DUK_OP_BLSR_CC 95 -#define DUK_OP_BASR 96 -#define DUK_OP_BASR_RR 96 -#define DUK_OP_BASR_CR 97 -#define DUK_OP_BASR_RC 98 -#define DUK_OP_BASR_CC 99 -#define DUK_OP_INSTOF 100 -#define DUK_OP_INSTOF_RR 100 -#define DUK_OP_INSTOF_CR 101 -#define DUK_OP_INSTOF_RC 102 -#define DUK_OP_INSTOF_CC 103 -#define DUK_OP_IN 104 -#define DUK_OP_IN_RR 104 -#define DUK_OP_IN_CR 105 -#define DUK_OP_IN_RC 106 -#define DUK_OP_IN_CC 107 -#define DUK_OP_GETPROP 108 -#define DUK_OP_GETPROP_RR 108 -#define DUK_OP_GETPROP_CR 109 -#define DUK_OP_GETPROP_RC 110 -#define DUK_OP_GETPROP_CC 111 -#define DUK_OP_PUTPROP 112 -#define DUK_OP_PUTPROP_RR 112 -#define DUK_OP_PUTPROP_CR 113 -#define DUK_OP_PUTPROP_RC 114 -#define DUK_OP_PUTPROP_CC 115 -#define DUK_OP_DELPROP 116 -#define DUK_OP_DELPROP_RR 116 -#define DUK_OP_DELPROP_CR_UNUSED 117 /* unused now */ -#define DUK_OP_DELPROP_RC 118 -#define DUK_OP_DELPROP_CC_UNUSED 119 /* unused now */ -#define DUK_OP_PREINCR 120 /* pre/post opcode values have constraints, */ -#define DUK_OP_PREDECR 121 /* see duk_js_executor.c and duk_js_compiler.c. */ -#define DUK_OP_POSTINCR 122 -#define DUK_OP_POSTDECR 123 -#define DUK_OP_PREINCV 124 -#define DUK_OP_PREDECV 125 -#define DUK_OP_POSTINCV 126 -#define DUK_OP_POSTDECV 127 -#define DUK_OP_PREINCP 128 /* pre/post inc/dec prop opcodes have constraints */ -#define DUK_OP_PREINCP_RR 128 -#define DUK_OP_PREINCP_CR 129 -#define DUK_OP_PREINCP_RC 130 -#define DUK_OP_PREINCP_CC 131 -#define DUK_OP_PREDECP 132 -#define DUK_OP_PREDECP_RR 132 -#define DUK_OP_PREDECP_CR 133 -#define DUK_OP_PREDECP_RC 134 -#define DUK_OP_PREDECP_CC 135 -#define DUK_OP_POSTINCP 136 -#define DUK_OP_POSTINCP_RR 136 -#define DUK_OP_POSTINCP_CR 137 -#define DUK_OP_POSTINCP_RC 138 -#define DUK_OP_POSTINCP_CC 139 -#define DUK_OP_POSTDECP 140 -#define DUK_OP_POSTDECP_RR 140 -#define DUK_OP_POSTDECP_CR 141 -#define DUK_OP_POSTDECP_RC 142 -#define DUK_OP_POSTDECP_CC 143 -#define DUK_OP_DECLVAR 144 -#define DUK_OP_DECLVAR_RR 144 -#define DUK_OP_DECLVAR_CR 145 -#define DUK_OP_DECLVAR_RC 146 -#define DUK_OP_DECLVAR_CC 147 -#define DUK_OP_REGEXP 148 -#define DUK_OP_REGEXP_RR 148 -#define DUK_OP_REGEXP_CR 149 -#define DUK_OP_REGEXP_RC 150 -#define DUK_OP_REGEXP_CC 151 -#define DUK_OP_CLOSURE 152 -#define DUK_OP_TYPEOF 153 -#define DUK_OP_TYPEOFID 154 -#define DUK_OP_PUTVAR 155 -#define DUK_OP_DELVAR 156 -#define DUK_OP_RETREG 157 -#define DUK_OP_RETUNDEF 158 -#define DUK_OP_RETCONST 159 -#define DUK_OP_RETCONSTN 160 /* return const without incref (e.g. number) */ -#define DUK_OP_LABEL 161 -#define DUK_OP_ENDLABEL 162 -#define DUK_OP_BREAK 163 -#define DUK_OP_CONTINUE 164 -#define DUK_OP_TRYCATCH 165 -#define DUK_OP_ENDTRY 166 -#define DUK_OP_ENDCATCH 167 -#define DUK_OP_ENDFIN 168 -#define DUK_OP_THROW 169 -#define DUK_OP_INVLHS 170 -#define DUK_OP_CSREG 171 -#define DUK_OP_CSVAR 172 -#define DUK_OP_CSVAR_RR 172 -#define DUK_OP_CSVAR_CR 173 -#define DUK_OP_CSVAR_RC 174 -#define DUK_OP_CSVAR_CC 175 -#define DUK_OP_CALL0 176 /* DUK_OP_CALL0 & 0x0F must be zero. */ -#define DUK_OP_CALL1 177 -#define DUK_OP_CALL2 178 -#define DUK_OP_CALL3 179 -#define DUK_OP_CALL4 180 -#define DUK_OP_CALL5 181 -#define DUK_OP_CALL6 182 -#define DUK_OP_CALL7 183 -#define DUK_OP_CALL8 184 -#define DUK_OP_CALL9 185 -#define DUK_OP_CALL10 186 -#define DUK_OP_CALL11 187 -#define DUK_OP_CALL12 188 -#define DUK_OP_CALL13 189 -#define DUK_OP_CALL14 190 -#define DUK_OP_CALL15 191 -#define DUK_OP_NEWOBJ 192 -#define DUK_OP_NEWARR 193 -#define DUK_OP_MPUTOBJ 194 -#define DUK_OP_MPUTOBJI 195 -#define DUK_OP_INITSET 196 -#define DUK_OP_INITGET 197 -#define DUK_OP_MPUTARR 198 -#define DUK_OP_MPUTARRI 199 -#define DUK_OP_SETALEN 200 -#define DUK_OP_INITENUM 201 -#define DUK_OP_NEXTENUM 202 -#define DUK_OP_NEWTARGET 203 -#define DUK_OP_DEBUGGER 204 -#define DUK_OP_NOP 205 -#define DUK_OP_INVALID 206 -#define DUK_OP_UNUSED207 207 -#define DUK_OP_GETPROPC 208 -#define DUK_OP_GETPROPC_RR 208 -#define DUK_OP_GETPROPC_CR 209 -#define DUK_OP_GETPROPC_RC 210 -#define DUK_OP_GETPROPC_CC 211 -#define DUK_OP_UNUSED212 212 -#define DUK_OP_UNUSED213 213 -#define DUK_OP_UNUSED214 214 -#define DUK_OP_UNUSED215 215 -#define DUK_OP_UNUSED216 216 -#define DUK_OP_UNUSED217 217 -#define DUK_OP_UNUSED218 218 -#define DUK_OP_UNUSED219 219 -#define DUK_OP_UNUSED220 220 -#define DUK_OP_UNUSED221 221 -#define DUK_OP_UNUSED222 222 -#define DUK_OP_UNUSED223 223 -#define DUK_OP_UNUSED224 224 -#define DUK_OP_UNUSED225 225 -#define DUK_OP_UNUSED226 226 -#define DUK_OP_UNUSED227 227 -#define DUK_OP_UNUSED228 228 -#define DUK_OP_UNUSED229 229 -#define DUK_OP_UNUSED230 230 -#define DUK_OP_UNUSED231 231 -#define DUK_OP_UNUSED232 232 -#define DUK_OP_UNUSED233 233 -#define DUK_OP_UNUSED234 234 -#define DUK_OP_UNUSED235 235 -#define DUK_OP_UNUSED236 236 -#define DUK_OP_UNUSED237 237 -#define DUK_OP_UNUSED238 238 -#define DUK_OP_UNUSED239 239 -#define DUK_OP_UNUSED240 240 -#define DUK_OP_UNUSED241 241 -#define DUK_OP_UNUSED242 242 -#define DUK_OP_UNUSED243 243 -#define DUK_OP_UNUSED244 244 -#define DUK_OP_UNUSED245 245 -#define DUK_OP_UNUSED246 246 -#define DUK_OP_UNUSED247 247 -#define DUK_OP_UNUSED248 248 -#define DUK_OP_UNUSED249 249 -#define DUK_OP_UNUSED250 250 -#define DUK_OP_UNUSED251 251 -#define DUK_OP_UNUSED252 252 -#define DUK_OP_UNUSED253 253 -#define DUK_OP_UNUSED254 254 -#define DUK_OP_UNUSED255 255 -#define DUK_OP_NONE 256 /* dummy value used as marker (doesn't fit in 8-bit field) */ +#define DUK_OP_LDREG 0 +#define DUK_OP_STREG 1 +#define DUK_OP_JUMP 2 +#define DUK_OP_LDCONST 3 +#define DUK_OP_LDINT 4 +#define DUK_OP_LDINTX 5 +#define DUK_OP_LDTHIS 6 +#define DUK_OP_LDUNDEF 7 +#define DUK_OP_LDNULL 8 +#define DUK_OP_LDTRUE 9 +#define DUK_OP_LDFALSE 10 +#define DUK_OP_GETVAR 11 +#define DUK_OP_BNOT 12 +#define DUK_OP_LNOT 13 +#define DUK_OP_UNM 14 +#define DUK_OP_UNP 15 +#define DUK_OP_EQ 16 +#define DUK_OP_EQ_RR 16 +#define DUK_OP_EQ_CR 17 +#define DUK_OP_EQ_RC 18 +#define DUK_OP_EQ_CC 19 +#define DUK_OP_NEQ 20 +#define DUK_OP_NEQ_RR 20 +#define DUK_OP_NEQ_CR 21 +#define DUK_OP_NEQ_RC 22 +#define DUK_OP_NEQ_CC 23 +#define DUK_OP_SEQ 24 +#define DUK_OP_SEQ_RR 24 +#define DUK_OP_SEQ_CR 25 +#define DUK_OP_SEQ_RC 26 +#define DUK_OP_SEQ_CC 27 +#define DUK_OP_SNEQ 28 +#define DUK_OP_SNEQ_RR 28 +#define DUK_OP_SNEQ_CR 29 +#define DUK_OP_SNEQ_RC 30 +#define DUK_OP_SNEQ_CC 31 +#define DUK_OP_GT 32 +#define DUK_OP_GT_RR 32 +#define DUK_OP_GT_CR 33 +#define DUK_OP_GT_RC 34 +#define DUK_OP_GT_CC 35 +#define DUK_OP_GE 36 +#define DUK_OP_GE_RR 36 +#define DUK_OP_GE_CR 37 +#define DUK_OP_GE_RC 38 +#define DUK_OP_GE_CC 39 +#define DUK_OP_LT 40 +#define DUK_OP_LT_RR 40 +#define DUK_OP_LT_CR 41 +#define DUK_OP_LT_RC 42 +#define DUK_OP_LT_CC 43 +#define DUK_OP_LE 44 +#define DUK_OP_LE_RR 44 +#define DUK_OP_LE_CR 45 +#define DUK_OP_LE_RC 46 +#define DUK_OP_LE_CC 47 +#define DUK_OP_IFTRUE 48 +#define DUK_OP_IFTRUE_R 48 +#define DUK_OP_IFTRUE_C 49 +#define DUK_OP_IFFALSE 50 +#define DUK_OP_IFFALSE_R 50 +#define DUK_OP_IFFALSE_C 51 +#define DUK_OP_ADD 52 +#define DUK_OP_ADD_RR 52 +#define DUK_OP_ADD_CR 53 +#define DUK_OP_ADD_RC 54 +#define DUK_OP_ADD_CC 55 +#define DUK_OP_SUB 56 +#define DUK_OP_SUB_RR 56 +#define DUK_OP_SUB_CR 57 +#define DUK_OP_SUB_RC 58 +#define DUK_OP_SUB_CC 59 +#define DUK_OP_MUL 60 +#define DUK_OP_MUL_RR 60 +#define DUK_OP_MUL_CR 61 +#define DUK_OP_MUL_RC 62 +#define DUK_OP_MUL_CC 63 +#define DUK_OP_DIV 64 +#define DUK_OP_DIV_RR 64 +#define DUK_OP_DIV_CR 65 +#define DUK_OP_DIV_RC 66 +#define DUK_OP_DIV_CC 67 +#define DUK_OP_MOD 68 +#define DUK_OP_MOD_RR 68 +#define DUK_OP_MOD_CR 69 +#define DUK_OP_MOD_RC 70 +#define DUK_OP_MOD_CC 71 +#define DUK_OP_EXP 72 +#define DUK_OP_EXP_RR 72 +#define DUK_OP_EXP_CR 73 +#define DUK_OP_EXP_RC 74 +#define DUK_OP_EXP_CC 75 +#define DUK_OP_BAND 76 +#define DUK_OP_BAND_RR 76 +#define DUK_OP_BAND_CR 77 +#define DUK_OP_BAND_RC 78 +#define DUK_OP_BAND_CC 79 +#define DUK_OP_BOR 80 +#define DUK_OP_BOR_RR 80 +#define DUK_OP_BOR_CR 81 +#define DUK_OP_BOR_RC 82 +#define DUK_OP_BOR_CC 83 +#define DUK_OP_BXOR 84 +#define DUK_OP_BXOR_RR 84 +#define DUK_OP_BXOR_CR 85 +#define DUK_OP_BXOR_RC 86 +#define DUK_OP_BXOR_CC 87 +#define DUK_OP_BASL 88 +#define DUK_OP_BASL_RR 88 +#define DUK_OP_BASL_CR 89 +#define DUK_OP_BASL_RC 90 +#define DUK_OP_BASL_CC 91 +#define DUK_OP_BLSR 92 +#define DUK_OP_BLSR_RR 92 +#define DUK_OP_BLSR_CR 93 +#define DUK_OP_BLSR_RC 94 +#define DUK_OP_BLSR_CC 95 +#define DUK_OP_BASR 96 +#define DUK_OP_BASR_RR 96 +#define DUK_OP_BASR_CR 97 +#define DUK_OP_BASR_RC 98 +#define DUK_OP_BASR_CC 99 +#define DUK_OP_INSTOF 100 +#define DUK_OP_INSTOF_RR 100 +#define DUK_OP_INSTOF_CR 101 +#define DUK_OP_INSTOF_RC 102 +#define DUK_OP_INSTOF_CC 103 +#define DUK_OP_IN 104 +#define DUK_OP_IN_RR 104 +#define DUK_OP_IN_CR 105 +#define DUK_OP_IN_RC 106 +#define DUK_OP_IN_CC 107 +#define DUK_OP_GETPROP 108 +#define DUK_OP_GETPROP_RR 108 +#define DUK_OP_GETPROP_CR 109 +#define DUK_OP_GETPROP_RC 110 +#define DUK_OP_GETPROP_CC 111 +#define DUK_OP_PUTPROP 112 +#define DUK_OP_PUTPROP_RR 112 +#define DUK_OP_PUTPROP_CR 113 +#define DUK_OP_PUTPROP_RC 114 +#define DUK_OP_PUTPROP_CC 115 +#define DUK_OP_DELPROP 116 +#define DUK_OP_DELPROP_RR 116 +#define DUK_OP_DELPROP_CR_UNUSED 117 /* unused now */ +#define DUK_OP_DELPROP_RC 118 +#define DUK_OP_DELPROP_CC_UNUSED 119 /* unused now */ +#define DUK_OP_PREINCR 120 /* pre/post opcode values have constraints, */ +#define DUK_OP_PREDECR 121 /* see duk_js_executor.c and duk_js_compiler.c. */ +#define DUK_OP_POSTINCR 122 +#define DUK_OP_POSTDECR 123 +#define DUK_OP_PREINCV 124 +#define DUK_OP_PREDECV 125 +#define DUK_OP_POSTINCV 126 +#define DUK_OP_POSTDECV 127 +#define DUK_OP_PREINCP 128 /* pre/post inc/dec prop opcodes have constraints */ +#define DUK_OP_PREINCP_RR 128 +#define DUK_OP_PREINCP_CR 129 +#define DUK_OP_PREINCP_RC 130 +#define DUK_OP_PREINCP_CC 131 +#define DUK_OP_PREDECP 132 +#define DUK_OP_PREDECP_RR 132 +#define DUK_OP_PREDECP_CR 133 +#define DUK_OP_PREDECP_RC 134 +#define DUK_OP_PREDECP_CC 135 +#define DUK_OP_POSTINCP 136 +#define DUK_OP_POSTINCP_RR 136 +#define DUK_OP_POSTINCP_CR 137 +#define DUK_OP_POSTINCP_RC 138 +#define DUK_OP_POSTINCP_CC 139 +#define DUK_OP_POSTDECP 140 +#define DUK_OP_POSTDECP_RR 140 +#define DUK_OP_POSTDECP_CR 141 +#define DUK_OP_POSTDECP_RC 142 +#define DUK_OP_POSTDECP_CC 143 +#define DUK_OP_DECLVAR 144 +#define DUK_OP_DECLVAR_RR 144 +#define DUK_OP_DECLVAR_CR 145 +#define DUK_OP_DECLVAR_RC 146 +#define DUK_OP_DECLVAR_CC 147 +#define DUK_OP_REGEXP 148 +#define DUK_OP_REGEXP_RR 148 +#define DUK_OP_REGEXP_CR 149 +#define DUK_OP_REGEXP_RC 150 +#define DUK_OP_REGEXP_CC 151 +#define DUK_OP_CLOSURE 152 +#define DUK_OP_TYPEOF 153 +#define DUK_OP_TYPEOFID 154 +#define DUK_OP_PUTVAR 155 +#define DUK_OP_DELVAR 156 +#define DUK_OP_RETREG 157 +#define DUK_OP_RETUNDEF 158 +#define DUK_OP_RETCONST 159 +#define DUK_OP_RETCONSTN 160 /* return const without incref (e.g. number) */ +#define DUK_OP_LABEL 161 +#define DUK_OP_ENDLABEL 162 +#define DUK_OP_BREAK 163 +#define DUK_OP_CONTINUE 164 +#define DUK_OP_TRYCATCH 165 +#define DUK_OP_ENDTRY 166 +#define DUK_OP_ENDCATCH 167 +#define DUK_OP_ENDFIN 168 +#define DUK_OP_THROW 169 +#define DUK_OP_INVLHS 170 +#define DUK_OP_CSREG 171 +#define DUK_OP_CSVAR 172 +#define DUK_OP_CSVAR_RR 172 +#define DUK_OP_CSVAR_CR 173 +#define DUK_OP_CSVAR_RC 174 +#define DUK_OP_CSVAR_CC 175 +#define DUK_OP_CALL0 176 /* DUK_OP_CALL0 & 0x0F must be zero. */ +#define DUK_OP_CALL1 177 +#define DUK_OP_CALL2 178 +#define DUK_OP_CALL3 179 +#define DUK_OP_CALL4 180 +#define DUK_OP_CALL5 181 +#define DUK_OP_CALL6 182 +#define DUK_OP_CALL7 183 +#define DUK_OP_CALL8 184 +#define DUK_OP_CALL9 185 +#define DUK_OP_CALL10 186 +#define DUK_OP_CALL11 187 +#define DUK_OP_CALL12 188 +#define DUK_OP_CALL13 189 +#define DUK_OP_CALL14 190 +#define DUK_OP_CALL15 191 +#define DUK_OP_NEWOBJ 192 +#define DUK_OP_NEWARR 193 +#define DUK_OP_MPUTOBJ 194 +#define DUK_OP_MPUTOBJI 195 +#define DUK_OP_INITSET 196 +#define DUK_OP_INITGET 197 +#define DUK_OP_MPUTARR 198 +#define DUK_OP_MPUTARRI 199 +#define DUK_OP_SETALEN 200 +#define DUK_OP_INITENUM 201 +#define DUK_OP_NEXTENUM 202 +#define DUK_OP_NEWTARGET 203 +#define DUK_OP_DEBUGGER 204 +#define DUK_OP_NOP 205 +#define DUK_OP_INVALID 206 +#define DUK_OP_UNUSED207 207 +#define DUK_OP_GETPROPC 208 +#define DUK_OP_GETPROPC_RR 208 +#define DUK_OP_GETPROPC_CR 209 +#define DUK_OP_GETPROPC_RC 210 +#define DUK_OP_GETPROPC_CC 211 +#define DUK_OP_UNUSED212 212 +#define DUK_OP_UNUSED213 213 +#define DUK_OP_UNUSED214 214 +#define DUK_OP_UNUSED215 215 +#define DUK_OP_UNUSED216 216 +#define DUK_OP_UNUSED217 217 +#define DUK_OP_UNUSED218 218 +#define DUK_OP_UNUSED219 219 +#define DUK_OP_UNUSED220 220 +#define DUK_OP_UNUSED221 221 +#define DUK_OP_UNUSED222 222 +#define DUK_OP_UNUSED223 223 +#define DUK_OP_UNUSED224 224 +#define DUK_OP_UNUSED225 225 +#define DUK_OP_UNUSED226 226 +#define DUK_OP_UNUSED227 227 +#define DUK_OP_UNUSED228 228 +#define DUK_OP_UNUSED229 229 +#define DUK_OP_UNUSED230 230 +#define DUK_OP_UNUSED231 231 +#define DUK_OP_UNUSED232 232 +#define DUK_OP_UNUSED233 233 +#define DUK_OP_UNUSED234 234 +#define DUK_OP_UNUSED235 235 +#define DUK_OP_UNUSED236 236 +#define DUK_OP_UNUSED237 237 +#define DUK_OP_UNUSED238 238 +#define DUK_OP_UNUSED239 239 +#define DUK_OP_UNUSED240 240 +#define DUK_OP_UNUSED241 241 +#define DUK_OP_UNUSED242 242 +#define DUK_OP_UNUSED243 243 +#define DUK_OP_UNUSED244 244 +#define DUK_OP_UNUSED245 245 +#define DUK_OP_UNUSED246 246 +#define DUK_OP_UNUSED247 247 +#define DUK_OP_UNUSED248 248 +#define DUK_OP_UNUSED249 249 +#define DUK_OP_UNUSED250 250 +#define DUK_OP_UNUSED251 251 +#define DUK_OP_UNUSED252 252 +#define DUK_OP_UNUSED253 253 +#define DUK_OP_UNUSED254 254 +#define DUK_OP_UNUSED255 255 +#define DUK_OP_NONE 256 /* dummy value used as marker (doesn't fit in 8-bit field) */ /* XXX: Allocate flags from opcode field? Would take 16 opcode slots * but avoids shuffling in more cases. Maybe not worth it. */ /* DUK_OP_TRYCATCH flags in A. */ -#define DUK_BC_TRYCATCH_FLAG_HAVE_CATCH (1U << 0) -#define DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY (1U << 1) -#define DUK_BC_TRYCATCH_FLAG_CATCH_BINDING (1U << 2) -#define DUK_BC_TRYCATCH_FLAG_WITH_BINDING (1U << 3) +#define DUK_BC_TRYCATCH_FLAG_HAVE_CATCH (1U << 0) +#define DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY (1U << 1) +#define DUK_BC_TRYCATCH_FLAG_CATCH_BINDING (1U << 2) +#define DUK_BC_TRYCATCH_FLAG_WITH_BINDING (1U << 3) /* DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags * (DUK_PROPDESC_FLAG_XXX). */ -#define DUK_BC_DECLVAR_FLAG_FUNC_DECL (1U << 4) /* function declaration */ +#define DUK_BC_DECLVAR_FLAG_FUNC_DECL (1U << 4) /* function declaration */ /* DUK_OP_CALLn flags, part of opcode field. Three lowest bits must match * DUK_CALL_FLAG_xxx directly. */ -#define DUK_BC_CALL_FLAG_TAILCALL (1U << 0) -#define DUK_BC_CALL_FLAG_CONSTRUCT (1U << 1) -#define DUK_BC_CALL_FLAG_CALLED_AS_EVAL (1U << 2) -#define DUK_BC_CALL_FLAG_INDIRECT (1U << 3) +#define DUK_BC_CALL_FLAG_TAILCALL (1U << 0) +#define DUK_BC_CALL_FLAG_CONSTRUCT (1U << 1) +#define DUK_BC_CALL_FLAG_CALLED_AS_EVAL (1U << 2) +#define DUK_BC_CALL_FLAG_INDIRECT (1U << 3) /* Misc constants and helper macros. */ -#define DUK_BC_LDINT_BIAS (1L << 15) -#define DUK_BC_LDINTX_SHIFT 16 -#define DUK_BC_JUMP_BIAS (1L << 23) +#define DUK_BC_LDINT_BIAS (1L << 15) +#define DUK_BC_LDINTX_SHIFT 16 +#define DUK_BC_JUMP_BIAS (1L << 23) -#endif /* DUK_JS_BYTECODE_H_INCLUDED */ +#endif /* DUK_JS_BYTECODE_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_js_call.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_js_call.c
Changed
@@ -51,10 +51,10 @@ * for, e.g. a print() call at the deepest level, and an extra * +1 for protected call wrapping. */ -#define DUK__AUGMENT_CALL_RELAX_COUNT (10 + 2) +#define DUK__AUGMENT_CALL_RELAX_COUNT (10 + 2) /* Stack space required by call handling entry. */ -#define DUK__CALL_HANDLING_REQUIRE_STACK 8 +#define DUK__CALL_HANDLING_REQUIRE_STACK 8 DUK_LOCAL DUK_NOINLINE void duk__call_c_recursion_limit_check_slowpath(duk_hthread *thr) { /* When augmenting an error, the effective limit is a bit higher. @@ -148,7 +148,8 @@ thr->heap->inst_count_interrupt += thr->interrupt_init; DUK_DD(DUK_DDPRINT("debug test: updated interrupt count on exit to " "user code, instruction counts: executor=%ld, interrupt=%ld", - (long) thr->heap->inst_count_exec, (long) thr->heap->inst_count_interrupt)); + (long) thr->heap->inst_count_exec, + (long) thr->heap->inst_count_interrupt)); DUK_ASSERT(thr->heap->inst_count_exec == thr->heap->inst_count_interrupt); } #else @@ -167,12 +168,9 @@ * object flag DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS. */ -DUK_LOCAL void duk__create_arguments_object(duk_hthread *thr, - duk_hobject *func, - duk_hobject *varenv, - duk_idx_t idx_args) { - duk_hobject *arg; /* 'arguments' */ - duk_hobject *formals; /* formals for 'func' (may be NULL if func is a C function) */ +DUK_LOCAL void duk__create_arguments_object(duk_hthread *thr, duk_hobject *func, duk_hobject *varenv, duk_idx_t idx_args) { + duk_hobject *arg; /* 'arguments' */ + duk_hobject *formals; /* formals for 'func' (may be NULL if func is a C function) */ duk_idx_t i_arg; duk_idx_t i_map; duk_idx_t i_mappednames; @@ -218,9 +216,8 @@ DUK_ASSERT(n_formals >= 0); DUK_ASSERT(formals != NULL || n_formals == 0); - DUK_DDD(DUK_DDDPRINT("func=%!O, formals=%!O, n_formals=%ld", - (duk_heaphdr *) func, (duk_heaphdr *) formals, - (long) n_formals)); + DUK_DDD( + DUK_DDDPRINT("func=%!O, formals=%!O, n_formals=%ld", (duk_heaphdr *) func, (duk_heaphdr *) formals, (long) n_formals)); /* ... formals */ @@ -232,28 +229,24 @@ */ arg = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARGUMENTS), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARGUMENTS), DUK_BIDX_OBJECT_PROTOTYPE); DUK_ASSERT(arg != NULL); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ i_arg = duk_get_top(thr) - 3; i_map = i_arg + 1; i_mappednames = i_arg + 2; - DUK_ASSERT(!duk_is_bare_object(thr, -3)); /* arguments */ - DUK_ASSERT(duk_is_bare_object(thr, -2)); /* map */ - DUK_ASSERT(duk_is_bare_object(thr, -1)); /* mappedNames */ + DUK_ASSERT(!duk_is_bare_object(thr, -3)); /* arguments */ + DUK_ASSERT(duk_is_bare_object(thr, -2)); /* map */ + DUK_ASSERT(duk_is_bare_object(thr, -1)); /* mappedNames */ /* ... formals arguments map mappedNames */ @@ -261,9 +254,12 @@ "arguments at index %ld -> %!O " "map at index %ld -> %!O " "mappednames at index %ld -> %!O", - (long) i_arg, (duk_heaphdr *) duk_get_hobject(thr, i_arg), - (long) i_map, (duk_heaphdr *) duk_get_hobject(thr, i_map), - (long) i_mappednames, (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); + (long) i_arg, + (duk_heaphdr *) duk_get_hobject(thr, i_arg), + (long) i_map, + (duk_heaphdr *) duk_get_hobject(thr, i_map), + (long) i_mappednames, + (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); /* * Init arguments properties, map, etc. @@ -279,8 +275,8 @@ /* step 11 */ idx = num_stack_args - 1; while (idx >= 0) { - DUK_DDD(DUK_DDDPRINT("arg idx %ld, argbase=%ld, argidx=%ld", - (long) idx, (long) i_argbase, (long) (i_argbase + idx))); + DUK_DDD( + DUK_DDDPRINT("arg idx %ld, argbase=%ld, argidx=%ld", (long) idx, (long) i_argbase, (long) (i_argbase + idx))); DUK_DDD(DUK_DDDPRINT("define arguments%ld=arg", (long) idx)); duk_dup(thr, i_argbase + idx); @@ -291,13 +287,12 @@ if (!DUK_HOBJECT_HAS_STRICT(func) && idx < n_formals) { DUK_ASSERT(formals != NULL); - DUK_DDD(DUK_DDDPRINT("strict function, index within formals (%ld < %ld)", - (long) idx, (long) n_formals)); + DUK_DDD(DUK_DDDPRINT("strict function, index within formals (%ld < %ld)", (long) idx, (long) n_formals)); duk_get_prop_index(thr, i_formals, (duk_uarridx_t) idx); DUK_ASSERT(duk_is_string(thr, -1)); - duk_dup_top(thr); /* ... name name */ + duk_dup_top(thr); /* ... name name */ if (!duk_has_prop(thr, i_mappednames)) { /* steps 11.c.ii.1 - 11.c.ii.4, but our internal book-keeping @@ -308,24 +303,21 @@ need_map = 1; - DUK_DDD(DUK_DDDPRINT("set mappednames%s=%ld", - (const char *) duk_get_string(thr, -1), - (long) idx)); - duk_dup_top(thr); /* name */ - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) idx); /* index */ - duk_xdef_prop_wec(thr, i_mappednames); /* out of spec, must be configurable */ - - DUK_DDD(DUK_DDDPRINT("set map%ld=%s", - (long) idx, - duk_get_string(thr, -1))); - duk_dup_top(thr); /* name */ - duk_xdef_prop_index_wec(thr, i_map, (duk_uarridx_t) idx); /* out of spec, must be configurable */ + DUK_DDD( + DUK_DDDPRINT("set mappednames%s=%ld", (const char *) duk_get_string(thr, -1), (long) idx)); + duk_dup_top(thr); /* name */ + (void) duk_push_uint_to_hstring(thr, (duk_uint_t) idx); /* index */ + duk_xdef_prop_wec(thr, i_mappednames); /* out of spec, must be configurable */ + + DUK_DDD(DUK_DDDPRINT("set map%ld=%s", (long) idx, duk_get_string(thr, -1))); + duk_dup_top(thr); /* name */ + duk_xdef_prop_index_wec(thr, i_map, (duk_uarridx_t) idx); /* out of spec, must be configurable */ } else { /* duk_has_prop() popped the second 'name' */ } /* ... name */ - duk_pop(thr); /* pop 'name' */ + duk_pop(thr); /* pop 'name' */ } idx--; @@ -341,7 +333,7 @@ DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(func)); duk_dup(thr, i_map); - duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_MAP, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ + duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_MAP, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ /* The variable environment for magic variable bindings needs to be * given by the caller and recorded in the arguments object. @@ -353,7 +345,7 @@ */ duk_push_hobject(thr, varenv); - duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_VARENV, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ + duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_VARENV, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ } /* steps 13-14 */ @@ -406,9 +398,12 @@ "arguments at index %ld -> %!O " "map at index %ld -> %!O " "mappednames at index %ld -> %!O", - (long) i_arg, (duk_heaphdr *) duk_get_hobject(thr, i_arg), - (long) i_map, (duk_heaphdr *) duk_get_hobject(thr, i_map), - (long) i_mappednames, (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); + (long) i_arg, + (duk_heaphdr *) duk_get_hobject(thr, i_arg), + (long) i_map, + (duk_heaphdr *) duk_get_hobject(thr, i_map), + (long) i_mappednames, + (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); /* args(n) envobj formals arguments map mappednames */ @@ -421,10 +416,7 @@ /* Helper for creating the arguments object and adding it to the env record * on top of the value stack. */ -DUK_LOCAL void duk__handle_createargs_for_call(duk_hthread *thr, - duk_hobject *func, - duk_hobject *env, - duk_idx_t idx_args) { +DUK_LOCAL void duk__handle_createargs_for_call(duk_hthread *thr, duk_hobject *func, duk_hobject *env, duk_idx_t idx_args) { DUK_DDD(DUK_DDDPRINT("creating arguments object for function call")); DUK_ASSERT(thr != NULL); @@ -434,18 +426,15 @@ /* ... arg1 ... argN envobj */ - duk__create_arguments_object(thr, - func, - env, - idx_args); + duk__create_arguments_object(thr, func, env, idx_args); /* ... arg1 ... argN envobj argobj */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LC_ARGUMENTS, - DUK_HOBJECT_HAS_STRICT(func) ? DUK_PROPDESC_FLAGS_E : /* strict: non-deletable, non-writable */ - DUK_PROPDESC_FLAGS_WE); /* non-strict: non-deletable, writable */ + DUK_HOBJECT_HAS_STRICT(func) ? DUK_PROPDESC_FLAGS_E : /* strict: non-deletable, non-writable */ + DUK_PROPDESC_FLAGS_WE); /* non-strict: non-deletable, writable */ /* ... arg1 ... argN envobj */ } @@ -495,7 +484,8 @@ "-> leave standard Object prototype as fallback prototype")); } else { DUK_DDD(DUK_DDDPRINT("constructor has 'prototype' property with object value " - "-> set fallback prototype to that value: %!iO", (duk_heaphdr *) proto)); + "-> set fallback prototype to that value: %!iO", + (duk_heaphdr *) proto)); /* Original fallback (default instance) is untouched when * resolving bound functions etc. */ @@ -517,9 +507,7 @@ * Object (we accept object-like values like buffers and * lightfuncs too). If not, TypeError. */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_LIGHTFUNC)) { + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_LIGHTFUNC)) { DUK_DDD(DUK_DDDPRINT("replacement value")); } else { if (DUK_UNLIKELY(proxy_invariant != 0U)) { @@ -541,8 +529,7 @@ * out right; however it is always synced here so just assert for it. */ DUK_ASSERT(thr->ptr_curr_pc == NULL); - duk_err_augment_error_create(thr, thr, NULL, 0, DUK_AUGMENT_FLAG_NOBLAME_FILELINE | - DUK_AUGMENT_FLAG_SKIP_ONE); + duk_err_augment_error_create(thr, thr, NULL, 0, DUK_AUGMENT_FLAG_NOBLAME_FILELINE | DUK_AUGMENT_FLAG_SKIP_ONE); #endif } @@ -559,9 +546,7 @@ * BoundThis. */ -DUK_LOCAL void duk__handle_bound_chain_for_call(duk_hthread *thr, - duk_idx_t idx_func, - duk_bool_t is_constructor_call) { +DUK_LOCAL void duk__handle_bound_chain_for_call(duk_hthread *thr, duk_idx_t idx_func, duk_bool_t is_constructor_call) { duk_tval *tv_func; duk_hobject *func; duk_idx_t len; @@ -592,7 +577,8 @@ DUK_ASSERT(len == 0 || tv_args != NULL); DUK_DDD(DUK_DDDPRINT("bound function encountered, ptr=%p: %!T", - (void *) DUK_TVAL_GET_OBJECT(tv_func), tv_func)); + (void *) DUK_TVAL_GET_OBJECT(tv_func), + tv_func)); /* ... func this arg1 ... argN */ @@ -602,7 +588,7 @@ } else { /* XXX: duk_replace_tval */ duk_push_tval(thr, &h_bound->this_binding); - duk_replace(thr, idx_func + 1); /* idx_this = idx_func + 1 */ + duk_replace(thr, idx_func + 1); /* idx_this = idx_func + 1 */ } /* ... func this arg1 ... argN */ @@ -615,10 +601,11 @@ /* ... func this <bound args> arg1 ... argN */ duk_push_tval(thr, &h_bound->target); - duk_replace(thr, idx_func); /* replace in stack */ + duk_replace(thr, idx_func); /* replace in stack */ DUK_DDD(DUK_DDDPRINT("bound function handled, idx_func=%ld, curr func=%!T", - (long) idx_func, duk_get_tval(thr, idx_func))); + (long) idx_func, + duk_get_tval(thr, idx_func))); } } else if (DUK_TVAL_IS_LIGHTFUNC(tv_func)) { /* Lightweight function: never bound, so terminate. */ @@ -640,9 +627,7 @@ func = DUK_TVAL_GET_OBJECT(tv_func); DUK_ASSERT(func != NULL); DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func) || - DUK_HOBJECT_HAS_NATFUNC(func) || - DUK_HOBJECT_IS_PROXY(func)); + DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func) || DUK_HOBJECT_HAS_NATFUNC(func) || DUK_HOBJECT_IS_PROXY(func)); } #endif } @@ -651,14 +636,18 @@ * Helper for inline handling of .call(), .apply(), and .construct(). */ -DUK_LOCAL duk_bool_t duk__handle_specialfuncs_for_call(duk_hthread *thr, duk_idx_t idx_func, duk_hobject *func, duk_small_uint_t *call_flags, duk_bool_t first) { +DUK_LOCAL duk_bool_t duk__handle_specialfuncs_for_call(duk_hthread *thr, + duk_idx_t idx_func, + duk_hobject *func, + duk_small_uint_t *call_flags, + duk_bool_t first) { #if defined(DUK_USE_ASSERTIONS) duk_c_function natfunc; #endif duk_tval *tv_args; DUK_ASSERT(func != NULL); - DUK_ASSERT((*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0); /* Caller. */ + DUK_ASSERT((*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0); /* Caller. */ #if defined(DUK_USE_ASSERTIONS) natfunc = ((duk_hnatfunc *) func)->func; @@ -686,7 +675,7 @@ *call_flags = (*call_flags & ~DUK_CALL_FLAG_CALLED_AS_EVAL) | DUK_CALL_FLAG_DIRECT_EVAL; } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 1; /* stop resolving */ + return 1; /* stop resolving */ } /* Handle special functions based on the DUK_HOBJECT_FLAG_SPECIAL_CALL @@ -696,7 +685,7 @@ * for the result values (unlike most other value stack calls). */ switch (((duk_hnatfunc *) func)->magic) { - case 0: { /* 0=Function.prototype.call() */ + case 0: { /* 0=Function.prototype.call() */ /* Value stack: * idx_func + 0: Function.prototype.call() removed * idx_func + 1: this binding for .call (target function) @@ -715,11 +704,11 @@ tv_args = thr->valstack_bottom + idx_func + 2; if (thr->valstack_top < tv_args) { DUK_ASSERT(tv_args <= thr->valstack_end); - thr->valstack_top = tv_args; /* at least target function and 'this' binding present */ + thr->valstack_top = tv_args; /* at least target function and 'this' binding present */ } break; } - case 1: { /* 1=Function.prototype.apply() */ + case 1: { /* 1=Function.prototype.apply() */ /* Value stack: * idx_func + 0: Function.prototype.apply() removed * idx_func + 1: this binding for .apply (target function) @@ -738,7 +727,7 @@ goto apply_shared; } #if defined(DUK_USE_REFLECT_BUILTIN) - case 2: { /* 2=Reflect.apply() */ + case 2: { /* 2=Reflect.apply() */ /* Value stack: * idx_func + 0: Reflect.apply() removed * idx_func + 1: this binding for .apply (ignored, usually Reflect) removed @@ -757,7 +746,7 @@ duk_remove_n_unsafe(thr, idx_func, 2); goto apply_shared; } - case 3: { /* 3=Reflect.construct() */ + case 3: { /* 3=Reflect.construct() */ /* Value stack: * idx_func + 0: Reflect.construct() removed * idx_func + 1: this binding for .construct (ignored, usually Reflect) removed @@ -791,11 +780,11 @@ * unpacking argArray (which may cause side effects). * Just return; caller will throw the error. */ - duk_set_top_unsafe(thr, idx_func + 2); /* satisfy asserts */ + duk_set_top_unsafe(thr, idx_func + 2); /* satisfy asserts */ break; } duk_push_object(thr); - duk_insert(thr, idx_func + 1); /* default instance */ + duk_insert(thr, idx_func + 1); /* default instance */ /* ... func default_instance argArray newTarget? */ @@ -811,16 +800,17 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } - duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ + duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ } DUK_ASSERT(duk_get_top(thr) == idx_func + 3); DUK_ASSERT(duk_is_valid_index(thr, idx_func + 2)); - (void) duk_unpack_array_like(thr, idx_func + 2); /* XXX: should also remove target to be symmetric with duk_pack()? */ + (void) duk_unpack_array_like(thr, + idx_func + 2); /* XXX: should also remove target to be symmetric with duk_pack()? */ duk_remove(thr, idx_func + 2); DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); break; } -#endif /* DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_REFLECT_BUILTIN */ default: { DUK_ASSERT(0); DUK_UNREACHABLE(); @@ -828,18 +818,18 @@ } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 0; /* keep resolving */ + return 0; /* keep resolving */ - apply_shared: +apply_shared: tv_args = thr->valstack_bottom + idx_func + 2; if (thr->valstack_top <= tv_args) { DUK_ASSERT(tv_args <= thr->valstack_end); - thr->valstack_top = tv_args; /* at least target func and 'this' binding present */ + thr->valstack_top = tv_args; /* at least target func and 'this' binding present */ /* No need to check for argArray. */ } else { - DUK_ASSERT(duk_get_top(thr) >= idx_func + 3); /* idx_func + 2 covered above */ + DUK_ASSERT(duk_get_top(thr) >= idx_func + 3); /* idx_func + 2 covered above */ if (thr->valstack_top > tv_args + 1) { - duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ + duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ } DUK_ASSERT(duk_is_valid_index(thr, idx_func + 2)); if (!duk_is_callable(thr, idx_func)) { @@ -852,7 +842,7 @@ } } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 0; /* keep resolving */ + return 0; /* keep resolving */ } /* @@ -950,8 +940,8 @@ DUK_ASSERT(duk_get_top(thr) == idx_func + 6); if (*call_flags & DUK_CALL_FLAG_CONSTRUCT) { - *call_flags |= DUK_CALL_FLAG_CONSTRUCT_PROXY; /* Enable 'construct' trap return invariant check. */ - *call_flags &= ~(DUK_CALL_FLAG_CONSTRUCT); /* Resume as non-constructor call to the trap. */ + *call_flags |= DUK_CALL_FLAG_CONSTRUCT_PROXY; /* Enable 'construct' trap return invariant check. */ + *call_flags &= ~(DUK_CALL_FLAG_CONSTRUCT); /* Resume as non-constructor call to the trap. */ /* 'apply' args: target, thisArg, argArray * 'construct' args: target, argArray, newTarget @@ -962,19 +952,17 @@ /* Finalize value stack layout by removing Proxy reference. */ duk_remove(thr, idx_func); - h_proxy = NULL; /* invalidated */ + h_proxy = NULL; /* invalidated */ DUK_ASSERT(duk_get_top(thr) == idx_func + 5); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* * Helper for setting up var_env and lex_env of an activation, * assuming it does NOT have the DUK_HOBJECT_FLAG_NEWENV flag. */ -DUK_LOCAL void duk__handle_oldenv_for_call(duk_hthread *thr, - duk_hobject *func, - duk_activation *act) { +DUK_LOCAL void duk__handle_oldenv_for_call(duk_hthread *thr, duk_hobject *func, duk_activation *act) { duk_hcompfunc *f; duk_hobject *h_lex; duk_hobject *h_var; @@ -990,7 +978,7 @@ f = (duk_hcompfunc *) func; h_lex = DUK_HCOMPFUNC_GET_LEXENV(thr->heap, f); h_var = DUK_HCOMPFUNC_GET_VARENV(thr->heap, f); - DUK_ASSERT(h_lex != NULL); /* Always true for closures (not for templates) */ + DUK_ASSERT(h_lex != NULL); /* Always true for closures (not for templates) */ DUK_ASSERT(h_var != NULL); act->lex_env = h_lex; act->var_env = h_var; @@ -1011,7 +999,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(func != NULL); - DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound chain resolved */ + DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound chain resolved */ DUK_ASSERT(thr->callstack_top >= 1); if (DUK_HOBJECT_HAS_STRICT(func)) { @@ -1065,7 +1053,7 @@ DUK_TVAL_SET_OBJECT(tv_caller, act_caller->func); DUK_TVAL_INCREF(thr, tv_caller); } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref */ } } else { /* 'caller' must only take on 'null' or function value */ @@ -1078,12 +1066,12 @@ DUK_TVAL_SET_OBJECT(tv_caller, act_caller->func); DUK_TVAL_INCREF(thr, tv_caller); } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref */ } } } } -#endif /* DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ +#endif /* DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ /* * Shared helpers for resolving the final, non-bound target function of the @@ -1129,7 +1117,7 @@ obj_global = thr->builtinsDUK_BIDX_GLOBAL; /* XXX: avoid this check somehow */ if (DUK_LIKELY(obj_global != NULL)) { - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ DUK_TVAL_SET_OBJECT(tv_this, obj_global); DUK_HOBJECT_INCREF(thr, obj_global); } else { @@ -1137,8 +1125,8 @@ * This behavior is out of specification scope. */ DUK_D(DUK_DPRINT("this binding: wanted to use global object, but it is NULL -> using undefined instead")); - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ - DUK_TVAL_SET_UNDEFINED(tv_this); /* nothing to incref */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ + DUK_TVAL_SET_UNDEFINED(tv_this); /* nothing to incref */ } break; default: @@ -1149,18 +1137,21 @@ */ DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv_this)); DUK_DDD(DUK_DDDPRINT("this binding: non-strict, not object/undefined/null -> use ToObject(value)")); - duk_to_object(thr, idx_this); /* may have side effects */ + duk_to_object(thr, idx_this); /* may have side effects */ break; } } -DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__resolve_target_fastpath_check(duk_hthread *thr, duk_idx_t idx_func, duk_hobject **out_func, duk_small_uint_t call_flags) { +DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__resolve_target_fastpath_check(duk_hthread *thr, + duk_idx_t idx_func, + duk_hobject **out_func, + duk_small_uint_t call_flags) { #if defined(DUK_USE_PREFER_SIZE) DUK_UNREF(thr); DUK_UNREF(idx_func); DUK_UNREF(out_func); DUK_UNREF(call_flags); -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ duk_tval *tv_func; duk_hobject *func; @@ -1173,9 +1164,7 @@ if (DUK_LIKELY(DUK_TVAL_IS_OBJECT(tv_func))) { func = DUK_TVAL_GET_OBJECT(tv_func); - if (DUK_HOBJECT_IS_CALLABLE(func) && - !DUK_HOBJECT_HAS_BOUNDFUNC(func) && - !DUK_HOBJECT_HAS_SPECIAL_CALL(func)) { + if (DUK_HOBJECT_IS_CALLABLE(func) && !DUK_HOBJECT_HAS_BOUNDFUNC(func) && !DUK_HOBJECT_HAS_SPECIAL_CALL(func)) { *out_func = func; if (DUK_HOBJECT_HAS_STRICT(func)) { @@ -1195,8 +1184,8 @@ */ return 1; } -#endif /* DUK_USE_PREFER_SIZE */ - return 0; /* let slow path deal with it */ +#endif /* DUK_USE_PREFER_SIZE */ + return 0; /* let slow path deal with it */ } DUK_LOCAL duk_hobject *duk__resolve_target_func_and_this_binding(duk_hthread *thr, @@ -1229,8 +1218,7 @@ } } - if (DUK_LIKELY(!DUK_HOBJECT_HAS_BOUNDFUNC(func) && - !DUK_HOBJECT_HAS_SPECIAL_CALL(func) && + if (DUK_LIKELY(!DUK_HOBJECT_HAS_BOUNDFUNC(func) && !DUK_HOBJECT_HAS_SPECIAL_CALL(func) && !DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(func))) { /* Common case, so test for using a single bitfield test. * Break out to handle this coercion etc. @@ -1266,8 +1254,7 @@ * the trap may be bound. */ duk__handle_proxy_for_call(thr, idx_func, (duk_hproxy *) func, call_flags); - } - else + } else #endif { DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(func)); @@ -1314,28 +1301,25 @@ } } - finished: - +finished : #if defined(DUK_USE_ASSERTIONS) - { - duk_tval *tv_tmp; +{ + duk_tval *tv_tmp; - tv_tmp = duk_get_tval(thr, idx_func); - DUK_ASSERT(tv_tmp != NULL); + tv_tmp = duk_get_tval(thr, idx_func); + DUK_ASSERT(tv_tmp != NULL); - DUK_ASSERT((DUK_TVAL_IS_OBJECT(tv_tmp) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(tv_tmp))) || - DUK_TVAL_IS_LIGHTFUNC(tv_tmp)); - DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || - DUK_HOBJECT_IS_NATFUNC(func))); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_HAS_CONSTRUCTABLE(func) || - (*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0)); - } + DUK_ASSERT((DUK_TVAL_IS_OBJECT(tv_tmp) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(tv_tmp))) || + DUK_TVAL_IS_LIGHTFUNC(tv_tmp)); + DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || DUK_HOBJECT_IS_NATFUNC(func))); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_HAS_CONSTRUCTABLE(func) || (*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0)); +} #endif return func; - not_callable: +not_callable: DUK_ASSERT(tv_func != NULL); #if defined(DUK_USE_VERBOSE_ERRORS) @@ -1347,7 +1331,8 @@ * (which would be dangerous). */ if (DUK_TVAL_IS_OBJECT(tv_func)) { - duk_tval *tv_wrap = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, DUK_TVAL_GET_OBJECT(tv_func), DUK_STRIDX_INT_TARGET); + duk_tval *tv_wrap = + duk_hobject_find_entry_tval_ptr_stridx(thr->heap, DUK_TVAL_GET_OBJECT(tv_func), DUK_STRIDX_INT_TARGET); if (tv_wrap != NULL) { DUK_DD(DUK_DDPRINT("delayed error from GETPROPC: %!T", tv_wrap)); duk_push_tval(thr, tv_wrap); @@ -1368,7 +1353,7 @@ #endif DUK_WO_NORETURN(return NULL;); - not_constructable: +not_constructable: /* For now GETPROPC delayed error not needed for constructor calls. */ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) @@ -1392,7 +1377,10 @@ * empty (below idx_retbase). */ -DUK_LOCAL void duk__safe_call_adjust_valstack(duk_hthread *thr, duk_idx_t idx_retbase, duk_idx_t num_stack_rets, duk_idx_t num_actual_rets) { +DUK_LOCAL void duk__safe_call_adjust_valstack(duk_hthread *thr, + duk_idx_t idx_retbase, + duk_idx_t num_stack_rets, + duk_idx_t num_actual_rets) { duk_idx_t idx_rcbase; DUK_ASSERT(thr != NULL); @@ -1400,7 +1388,7 @@ DUK_ASSERT(num_stack_rets >= 0); DUK_ASSERT(num_actual_rets >= 0); - idx_rcbase = duk_get_top(thr) - num_actual_rets; /* base of known return values */ + idx_rcbase = duk_get_top(thr) - num_actual_rets; /* base of known return values */ if (DUK_UNLIKELY(idx_rcbase < 0)) { DUK_ERROR_TYPE(thr, DUK_STR_INVALID_CFUNC_RC); DUK_WO_NORETURN(return;); @@ -1408,10 +1396,13 @@ DUK_DDD(DUK_DDDPRINT("adjust valstack after func call: " "num_stack_rets=%ld, num_actual_rets=%ld, stack_top=%ld, idx_retbase=%ld, idx_rcbase=%ld", - (long) num_stack_rets, (long) num_actual_rets, (long) duk_get_top(thr), - (long) idx_retbase, (long) idx_rcbase)); + (long) num_stack_rets, + (long) num_actual_rets, + (long) duk_get_top(thr), + (long) idx_retbase, + (long) idx_rcbase)); - DUK_ASSERT(idx_rcbase >= 0); /* caller must check */ + DUK_ASSERT(idx_rcbase >= 0); /* caller must check */ /* Space for num_stack_rets was reserved before the safe call. * Because value stack reserve cannot shrink except in call returns, @@ -1426,24 +1417,28 @@ duk_idx_t count = idx_rcbase - idx_retbase; DUK_DDD(DUK_DDDPRINT("elements at/after idx_retbase have enough to cover func retvals " - "(idx_retbase=%ld, idx_rcbase=%ld)", (long) idx_retbase, (long) idx_rcbase)); + "(idx_retbase=%ld, idx_rcbase=%ld)", + (long) idx_retbase, + (long) idx_rcbase)); /* Remove values between irc_rcbase (start of intended return * values) and idx_retbase to lower return values to idx_retbase. */ DUK_ASSERT(count > 0); - duk_remove_n(thr, idx_retbase, count); /* may be NORZ */ + duk_remove_n(thr, idx_retbase, count); /* may be NORZ */ } else { duk_idx_t count = idx_retbase - idx_rcbase; DUK_DDD(DUK_DDDPRINT("not enough elements at/after idx_retbase to cover func retvals " - "(idx_retbase=%ld, idx_rcbase=%ld)", (long) idx_retbase, (long) idx_rcbase)); + "(idx_retbase=%ld, idx_rcbase=%ld)", + (long) idx_retbase, + (long) idx_rcbase)); /* Insert 'undefined' at idx_rcbase (start of intended return * values) to lift return values to idx_retbase. */ DUK_ASSERT(count >= 0); - DUK_ASSERT(thr->valstack_end - thr->valstack_top >= count); /* reserve cannot shrink */ + DUK_ASSERT(thr->valstack_end - thr->valstack_top >= count); /* reserve cannot shrink */ duk_insert_undefined_n(thr, idx_rcbase, count); } @@ -1504,12 +1499,12 @@ #if defined(DUK_USE_ES6_PROXY) | (duk_small_uint_t) ((act->flags & DUK_ACT_FLAG_CONSTRUCT_PROXY) ? 2 : 0) #endif - ; + ; flags2 = (duk_small_uint_t) ((call_flags & DUK_CALL_FLAG_CONSTRUCT) ? 1 : 0) #if defined(DUK_USE_ES6_PROXY) | (duk_small_uint_t) ((call_flags & DUK_CALL_FLAG_CONSTRUCT_PROXY) ? 2 : 0); #endif - ; + ; if (flags1 != flags2) { DUK_DDD(DUK_DDDPRINT("tail call prevented by incompatible return value handling")); return 0; @@ -1547,8 +1542,7 @@ * https://github.com/svaarala/duktape/issues/1726. */ - DUK_DDD(DUK_DDDPRINT("is tail call, reusing activation at callstack top, at index %ld", - (long) (thr->callstack_top - 1))); + DUK_DDD(DUK_DDDPRINT("is tail call, reusing activation at callstack top, at index %ld", (long) (thr->callstack_top - 1))); DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(func)); @@ -1592,7 +1586,7 @@ act->lex_env = NULL; DUK_ASSERT(func != NULL); DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func)); - act->func = func; /* don't want an intermediate exposed state with func == NULL */ + act->func = func; /* don't want an intermediate exposed state with func == NULL */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) act->prev_caller = NULL; #endif @@ -1601,7 +1595,7 @@ #if defined(DUK_USE_DEBUGGER_SUPPORT) act->prev_line = 0; #endif - DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ + DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ DUK_HOBJECT_INCREF(thr, func); act->flags = DUK_ACT_FLAG_TAILCALLED; @@ -1617,10 +1611,10 @@ } #endif - DUK_ASSERT(DUK_ACT_GET_FUNC(act) == func); /* already updated */ + DUK_ASSERT(DUK_ACT_GET_FUNC(act) == func); /* already updated */ DUK_ASSERT(act->var_env == NULL); DUK_ASSERT(act->lex_env == NULL); - act->bottom_byteoff = entry_valstack_bottom_byteoff; /* tail call -> reuse current "frame" */ + act->bottom_byteoff = entry_valstack_bottom_byteoff; /* tail call -> reuse current "frame" */ #if 0 /* Topmost activation retval_byteoff is considered garbage, no need to init. */ act->retval_byteoff = 0; @@ -1645,22 +1639,23 @@ tv1 = thr->valstack_bottom - 1; tv2 = thr->valstack_bottom + idx_func + 1; - DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); /* tv1 is -below- valstack_bottom */ + DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); /* tv1 is -below- valstack_bottom */ DUK_ASSERT(tv2 >= thr->valstack_bottom && tv2 < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ idx_args = idx_func + 2; - duk_remove_n(thr, 0, idx_args); /* may be NORZ */ + duk_remove_n(thr, 0, idx_args); /* may be NORZ */ - idx_func = 0; DUK_UNREF(idx_func); /* really 'not applicable' anymore, should not be referenced after this */ + idx_func = 0; + DUK_UNREF(idx_func); /* really 'not applicable' anymore, should not be referenced after this */ idx_args = 0; *out_nargs = ((duk_hcompfunc *) func)->nargs; *out_nregs = ((duk_hcompfunc *) func)->nregs; DUK_ASSERT(*out_nregs >= 0); DUK_ASSERT(*out_nregs >= *out_nargs); - *out_vs_min_bytes = entry_valstack_bottom_byteoff + sizeof(duk_tval) * ((duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); - + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + sizeof(duk_tval) * ((duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) #if defined(DUK_USE_TAILCALL) @@ -1677,7 +1672,7 @@ return 1; } -#endif /* DUK_USE_TAILCALL */ +#endif /* DUK_USE_TAILCALL */ DUK_LOCAL void duk__call_setup_act_not_tailcall(duk_hthread *thr, duk_small_uint_t call_flags, @@ -1694,8 +1689,7 @@ DUK_UNREF(entry_valstack_end_byteoff); - DUK_DDD(DUK_DDDPRINT("not a tail call, pushing a new activation to callstack, to index %ld", - (long) (thr->callstack_top))); + DUK_DDD(DUK_DDDPRINT("not a tail call, pushing a new activation to callstack, to index %ld", (long) (thr->callstack_top))); duk__call_callstack_limit_check(thr); new_act = duk_hthread_activation_alloc(thr); @@ -1722,7 +1716,7 @@ act = new_act; *out_act = act; - DUK_ASSERT(thr->valstack_top > thr->valstack_bottom); /* at least effective 'this' */ + DUK_ASSERT(thr->valstack_top > thr->valstack_bottom); /* at least effective 'this' */ DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); act->cat = NULL; @@ -1741,9 +1735,9 @@ } /* start of arguments: idx_func + 2. */ - act->func = func; /* NULL for lightfunc */ + act->func = func; /* NULL for lightfunc */ if (DUK_LIKELY(func != NULL)) { - DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ + DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ if (DUK_HOBJECT_HAS_STRICT(func)) { act->flags |= DUK_ACT_FLAG_STRICT; } @@ -1752,8 +1746,9 @@ *out_nregs = ((duk_hcompfunc *) func)->nregs; DUK_ASSERT(*out_nregs >= 0); DUK_ASSERT(*out_nregs >= *out_nargs); - *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); } else { /* True because of call target lookup checks. */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(func)); @@ -1761,13 +1756,16 @@ *out_nargs = ((duk_hnatfunc *) func)->nargs; *out_nregs = *out_nargs; if (*out_nargs >= 0) { - *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); } else { /* Vararg function. */ - duk_size_t valstack_top_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); - *out_vs_min_bytes = valstack_top_byteoff + - sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + duk_size_t valstack_top_byteoff = + (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); + *out_vs_min_bytes = valstack_top_byteoff + sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + + DUK_VALSTACK_INTERNAL_EXTRA); } } } else { @@ -1778,18 +1776,20 @@ tv_func = DUK_GET_TVAL_POSIDX(thr, idx_func); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(tv_func)); - DUK_TVAL_SET_TVAL(&act->tv_func, tv_func); /* borrowed, no refcount */ + DUK_TVAL_SET_TVAL(&act->tv_func, tv_func); /* borrowed, no refcount */ lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv_func); *out_nargs = DUK_LFUNC_FLAGS_GET_NARGS(lf_flags); if (*out_nargs != DUK_LFUNC_NARGS_VARARGS) { *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nargs + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nargs + + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); } else { - duk_size_t valstack_top_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); + duk_size_t valstack_top_byteoff = + (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); *out_vs_min_bytes = valstack_top_byteoff + - sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); - *out_nargs = -1; /* vararg */ + sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + *out_nargs = -1; /* vararg */ } *out_nregs = *out_nargs; } @@ -1811,13 +1811,13 @@ * even in error unwind because reserve_byteoff is only used when * returning to -this- activation. */ - act->reserve_byteoff = 0; /* filled in by caller */ + act->reserve_byteoff = 0; /* filled in by caller */ /* XXX: Is this INCREF necessary? 'func' is always a borrowed * reference reachable through the value stack? If changed, stack * unwind code also needs to be fixed to match. */ - DUK_HOBJECT_INCREF_ALLOWNULL(thr, func); /* act->func */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, func); /* act->func */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) if (func) { @@ -1833,7 +1833,7 @@ DUK_LOCAL void duk__call_env_setup(duk_hthread *thr, duk_hobject *func, duk_activation *act, duk_idx_t idx_args) { duk_hobject *env; - DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound function has already been resolved */ + DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound function has already been resolved */ if (DUK_LIKELY(func != NULL)) { if (DUK_LIKELY(DUK_HOBJECT_HAS_NEWENV(func))) { @@ -1864,7 +1864,7 @@ act->lex_env = env; act->var_env = env; DUK_HOBJECT_INCREF(thr, env); - DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (2) directly */ + DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (2) directly */ duk_pop(thr); } } else { @@ -1902,8 +1902,7 @@ goto thread_state_error; } } else { - DUK_ASSERT(thr->heap->curr_thread == NULL || - thr->heap->curr_thread->state == DUK_HTHREAD_STATE_RUNNING); + DUK_ASSERT(thr->heap->curr_thread == NULL || thr->heap->curr_thread->state == DUK_HTHREAD_STATE_RUNNING); if (DUK_UNLIKELY(thr->state != DUK_HTHREAD_STATE_INACTIVE)) { goto thread_state_error; } @@ -1918,7 +1917,7 @@ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); return; - thread_state_error: +thread_state_error: DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "invalid thread state (%ld)", (long) thr->state); DUK_WO_NORETURN(return;); } @@ -1944,9 +1943,7 @@ * place; the only guarantee is that the state is consistent for unwinding. */ -DUK_LOCAL duk_int_t duk__handle_call_raw(duk_hthread *thr, - duk_idx_t idx_func, - duk_small_uint_t call_flags) { +DUK_LOCAL duk_int_t duk__handle_call_raw(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags) { #if defined(DUK_USE_ASSERTIONS) duk_activation *entry_act; duk_size_t entry_callstack_top; @@ -1958,10 +1955,10 @@ duk_uint_fast8_t entry_thread_state; duk_instr_t **entry_ptr_curr_pc; duk_idx_t idx_args; - duk_idx_t nargs; /* # argument registers target function wants (< 0 => "as is") */ - duk_idx_t nregs; /* # total registers target function wants on entry (< 0 => "as is") */ - duk_size_t vs_min_bytes; /* minimum value stack size (bytes) for handling call */ - duk_hobject *func; /* 'func' on stack (borrowed reference) */ + duk_idx_t nargs; /* # argument registers target function wants (< 0 => "as is") */ + duk_idx_t nregs; /* # total registers target function wants on entry (< 0 => "as is") */ + duk_size_t vs_min_bytes; /* minimum value stack size (bytes) for handling call */ + duk_hobject *func; /* 'func' on stack (borrowed reference) */ duk_activation *act; duk_ret_t rc; duk_small_uint_t use_tailcall; @@ -2002,7 +1999,7 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(tmp_cat) == DUK_CAT_TYPE_LABEL); /* a non-catching entry */ } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Store entry state. @@ -2015,9 +2012,9 @@ entry_valstack_bottom_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack); entry_valstack_end_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); entry_call_recursion_depth = thr->heap->call_recursion_depth; - entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ + entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ entry_thread_state = thr->state; - entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ + entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ /* If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL * thr->ptr_curr_pc so that it's not accidentally used with an incorrect @@ -2085,11 +2082,10 @@ DUK_DDD(DUK_DDDPRINT("slow path target resolve")); func = duk__resolve_target_func_and_this_binding(thr, idx_func, &call_flags); } - DUK_ASSERT(duk_get_top(thr) - idx_func >= 2); /* at least func and this present */ + DUK_ASSERT(duk_get_top(thr) - idx_func >= 2); /* at least func and this present */ DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || - DUK_HOBJECT_IS_NATFUNC(func))); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || DUK_HOBJECT_IS_NATFUNC(func))); /* ... func this arg1 ... argN */ @@ -2124,7 +2120,7 @@ &act); } #else - DUK_ASSERT((call_flags & DUK_CALL_FLAG_TAILCALL) == 0); /* compiler ensures this */ + DUK_ASSERT((call_flags & DUK_CALL_FLAG_TAILCALL) == 0); /* compiler ensures this */ use_tailcall = 0; #endif @@ -2151,6 +2147,15 @@ /* ... func this arg1 ... argN */ /* + * Grow value stack to required size before env setup. This + * must happen before env setup to handle some corner cases + * correctly, e.g. test-bug-scope-segv-gh2448.js. + */ + + duk_valstack_grow_check_throw(thr, vs_min_bytes); + act->reserve_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); + + /* * Environment record creation and 'arguments' object creation. * Named function expression name binding is handled by the * compiler; the compiled function's parent env will contain @@ -2171,13 +2176,8 @@ * Setup value stack: clamp to 'nargs', fill up to 'nregs', * ensure value stack size matches target requirements, and * switch value stack bottom. Valstack top is kept. - * - * Value stack can only grow here. */ - duk_valstack_grow_check_throw(thr, vs_min_bytes); - act->reserve_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); - if (use_tailcall) { DUK_ASSERT(nregs >= 0); DUK_ASSERT(nregs >= nargs); @@ -2216,8 +2216,8 @@ DUK_ASSERT((act->flags & DUK_ACT_FLAG_PREVENT_YIELD) == 0); DUK_REFZERO_CHECK_FAST(thr); DUK_ASSERT(thr->ptr_curr_pc == NULL); - thr->heap->call_recursion_depth--; /* No recursion increase for this case. */ - return 1; /* 1=reuse executor */ + thr->heap->call_recursion_depth--; /* No recursion increase for this case. */ + return 1; /* 1=reuse executor */ } DUK_ASSERT(use_tailcall == 0); @@ -2341,7 +2341,7 @@ /* Explicit check for fastint downgrade. */ DUK_TVAL_CHKFAST_INPLACE_FAST(tv_funret); #endif - DUK_TVAL_SET_TVAL_UPDREF(thr, tv_ret, tv_funret); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv_ret, tv_funret); /* side effects */ } duk_set_top_unsafe(thr, idx_func + 1); @@ -2360,7 +2360,7 @@ /* Restore entry thread executor curr_pc stack frame pointer. */ thr->ptr_curr_pc = entry_ptr_curr_pc; - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; /* Disabled assert: triggered with some torture tests. */ @@ -2401,12 +2401,10 @@ DUK_REFZERO_CHECK_FAST(thr); - return 0; /* 0=call handled inline */ + return 0; /* 0=call handled inline */ } -DUK_INTERNAL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, - duk_idx_t nargs, - duk_small_uint_t call_flags) { +DUK_INTERNAL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags) { duk_idx_t idx_func; DUK_ASSERT(duk_get_top(thr) >= nargs + 2); idx_func = duk_get_top(thr) - (nargs + 2); @@ -2414,9 +2412,7 @@ return duk_handle_call_unprotected(thr, idx_func, call_flags); } -DUK_INTERNAL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, - duk_idx_t idx_func, - duk_small_uint_t call_flags) { +DUK_INTERNAL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags) { DUK_ASSERT(duk_is_valid_index(thr, idx_func)); DUK_ASSERT(idx_func >= 0); return duk__handle_call_raw(thr, idx_func, call_flags); @@ -2483,7 +2479,8 @@ /* we're running inside the caller's activation, so no change in call/catch stack or valstack bottom */ DUK_ASSERT(thr->callstack_top == entry_callstack_top); DUK_ASSERT(thr->valstack_bottom >= thr->valstack); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == entry_valstack_bottom_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == + entry_valstack_bottom_byteoff); DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); DUK_ASSERT(thr->valstack_end >= thr->valstack_top); @@ -2493,9 +2490,9 @@ } DUK_ASSERT(rc >= 0); - duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, rc); /* throws for insane rc */ + duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, rc); /* throws for insane rc */ - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; } @@ -2548,7 +2545,7 @@ /* Switch active thread before any side effects to avoid a * dangling curr_thread pointer. */ - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; DUK_ASSERT(thr->heap->curr_thread == entry_curr_thread); @@ -2564,9 +2561,9 @@ /* ... | (crud) errobj */ - DUK_ASSERT(duk_get_top(thr) >= 1); /* at least errobj must be on stack */ + DUK_ASSERT(duk_get_top(thr) >= 1); /* at least errobj must be on stack */ - duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, 1); /* 1 = num actual 'return values' */ + duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, 1); /* 1 = num actual 'return values' */ /* ... | or ... | errobj (M * undefined) where M = num_stack_rets - 1 */ @@ -2652,7 +2649,7 @@ duk_int_t retval; DUK_ASSERT(thr != NULL); - DUK_ASSERT(duk_get_top(thr) >= num_stack_args); /* Caller ensures. */ + DUK_ASSERT(duk_get_top(thr) >= num_stack_args); /* Caller ensures. */ DUK_STATS_INC(thr->heap, stats_safecall_all); @@ -2671,14 +2668,14 @@ entry_callstack_preventcount = thr->callstack_preventcount; #endif entry_call_recursion_depth = thr->heap->call_recursion_depth; - entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ + entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ entry_thread_state = thr->state; - entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ - idx_retbase = duk_get_top(thr) - num_stack_args; /* not a valid stack index if num_stack_args == 0 */ + entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ + idx_retbase = duk_get_top(thr) - num_stack_args; /* not a valid stack index if num_stack_args == 0 */ DUK_ASSERT(idx_retbase >= 0); - DUK_ASSERT((duk_idx_t) (thr->valstack_top - thr->valstack_bottom) >= num_stack_args); /* Caller ensures. */ - DUK_ASSERT((duk_idx_t) (thr->valstack_end - (thr->valstack_bottom + idx_retbase)) >= num_stack_rets); /* Caller ensures. */ + DUK_ASSERT((duk_idx_t) (thr->valstack_top - thr->valstack_bottom) >= num_stack_args); /* Caller ensures. */ + DUK_ASSERT((duk_idx_t) (thr->valstack_end - (thr->valstack_bottom + idx_retbase)) >= num_stack_rets); /* Caller ensures. */ /* Cannot portably debug print a function pointer, hence 'func' not printed! */ DUK_DD(DUK_DDPRINT("duk_handle_safe_call: thr=%p, num_stack_args=%ld, num_stack_rets=%ld, " @@ -2738,7 +2735,8 @@ * whatever calls are made. Reserve cannot decrease. */ DUK_ASSERT(thr->callstack_curr == entry_act); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); retval = DUK_EXEC_SUCCESS; #if defined(DUK_USE_CPP_EXCEPTIONS) @@ -2748,7 +2746,8 @@ } else { /* Error path. */ #endif - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); @@ -2773,14 +2772,18 @@ throw; } catch (std::exception &exc) { const char *what = exc.what(); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); if (!what) { what = "unknown"; } DUK_D(DUK_DPRINT("unexpected c++ std::exception (perhaps thrown by user code)")); try { - DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", what); + DUK_ERROR_FMT1(thr, + DUK_ERR_TYPE_ERROR, + "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", + what); DUK_WO_NORETURN(return 0;); } catch (duk_internal_exception exc) { DUK_D(DUK_DPRINT("caught api error thrown from unexpected c++ std::exception")); @@ -2800,7 +2803,8 @@ } } catch (...) { DUK_D(DUK_DPRINT("unexpected c++ exception (perhaps thrown by user code)")); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); try { DUK_ERROR_TYPE(thr, "caught invalid c++ exception (perhaps thrown by user code)"); @@ -2824,7 +2828,7 @@ } #endif - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr == old_jmpbuf_ptr); /* success/error path both do this */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr == old_jmpbuf_ptr); /* success/error path both do this */ DUK_ASSERT_LJSTATE_UNSET(thr->heap); @@ -2845,7 +2849,8 @@ /* Final asserts. */ DUK_ASSERT(thr->callstack_curr == entry_act); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == entry_valstack_bottom_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == + entry_valstack_bottom_byteoff); DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); DUK_ASSERT(thr->callstack_top == entry_callstack_top); DUK_ASSERT(thr->heap->call_recursion_depth == entry_call_recursion_depth); @@ -2906,8 +2911,11 @@ str_base = duk_get_type_name(thr, -3); duk_push_error_object(thr, DUK_ERR_TYPE_ERROR | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - "%s not callable (property %s of %s)", str_targ, str_key, str_base); - duk_xdef_prop_stridx(thr, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ + "%s not callable (property %s of %s)", + str_targ, + str_key, + str_base); + duk_xdef_prop_stridx(thr, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ /* <nargs> target base key { _Target: error } */ duk_replace(thr, entry_top - 1); #else @@ -2916,9 +2924,12 @@ str_base = duk_push_string_readable(thr, -5); duk_push_error_object(thr, DUK_ERR_TYPE_ERROR | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - "%s not callable (property %s of %s)", str_targ, str_key, str_base); + "%s not callable (property %s of %s)", + str_targ, + str_key, + str_base); /* <nargs> target base key {} str_targ str_key str_base error */ - duk_xdef_prop_stridx(thr, -5, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ + duk_xdef_prop_stridx(thr, -5, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ /* <nargs> target base key { _Target: error } str_targ str_key str_base */ duk_swap(thr, -4, entry_top - 1); /* <nargs> { _Target: error } base key target str_targ str_key str_base */ @@ -2928,6 +2939,6 @@ duk_set_top(thr, entry_top); /* <nregs> { _Target: error } */ - DUK_ASSERT(!duk_is_callable(thr, -1)); /* Critical so that call handling will throw the error. */ + DUK_ASSERT(!duk_is_callable(thr, -1)); /* Critical so that call handling will throw the error. */ } -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_js_compiler.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_js_compiler.c
Changed
@@ -34,45 +34,51 @@ * uses this approach to avoid an explicit DUK__ISREG() check (the condition is * logically "'x' is a register AND 'x' >= temp_first"). */ -#define DUK__CONST_MARKER DUK_REGCONST_CONST_MARKER -#define DUK__REMOVECONST(x) ((x) & ~DUK__CONST_MARKER) -#define DUK__ISREG(x) ((x) >= 0) -#define DUK__ISCONST(x) ((x) < 0) -#define DUK__ISREG_TEMP(comp_ctx,x) ((duk_int32_t) (x) >= (duk_int32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= temp_first && x >= 0 by comparing as signed. */ -#define DUK__ISREG_NOTTEMP(comp_ctx,x) ((duk_uint32_t) (x) < (duk_uint32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= 0 && x < temp_first by interpreting as unsigned. */ -#define DUK__GETTEMP(comp_ctx) ((comp_ctx)->curr_func.temp_next) -#define DUK__SETTEMP(comp_ctx,x) ((comp_ctx)->curr_func.temp_next = (x)) /* dangerous: must only lower (temp_max not updated) */ -#define DUK__SETTEMP_CHECKMAX(comp_ctx,x) duk__settemp_checkmax((comp_ctx),(x)) -#define DUK__ALLOCTEMP(comp_ctx) duk__alloctemp((comp_ctx)) -#define DUK__ALLOCTEMPS(comp_ctx,count) duk__alloctemps((comp_ctx),(count)) +#define DUK__CONST_MARKER DUK_REGCONST_CONST_MARKER +#define DUK__REMOVECONST(x) ((x) & ~DUK__CONST_MARKER) +#define DUK__ISREG(x) ((x) >= 0) +#define DUK__ISCONST(x) ((x) < 0) +#define DUK__ISREG_TEMP(comp_ctx, x) \ + ((duk_int32_t) (x) >= \ + (duk_int32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= temp_first && x >= 0 by comparing as signed. */ +#define DUK__ISREG_NOTTEMP(comp_ctx, x) \ + ((duk_uint32_t) (x) < \ + (duk_uint32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= 0 && x < temp_first by interpreting as unsigned. */ +#define DUK__GETTEMP(comp_ctx) ((comp_ctx)->curr_func.temp_next) +#define DUK__SETTEMP(comp_ctx, x) ((comp_ctx)->curr_func.temp_next = (x)) /* dangerous: must only lower (temp_max not updated) */ +#define DUK__SETTEMP_CHECKMAX(comp_ctx, x) duk__settemp_checkmax((comp_ctx), (x)) +#define DUK__ALLOCTEMP(comp_ctx) duk__alloctemp((comp_ctx)) +#define DUK__ALLOCTEMPS(comp_ctx, count) duk__alloctemps((comp_ctx), (count)) /* Init value set size for array and object literals. */ -#define DUK__MAX_ARRAY_INIT_VALUES 20 -#define DUK__MAX_OBJECT_INIT_PAIRS 10 +#define DUK__MAX_ARRAY_INIT_VALUES 20 +#define DUK__MAX_OBJECT_INIT_PAIRS 10 /* XXX: hack, remove when const lookup is not O(n) */ -#define DUK__GETCONST_MAX_CONSTS_CHECK 256 +#define DUK__GETCONST_MAX_CONSTS_CHECK 256 /* These limits are based on bytecode limits. Max temps is limited * by duk_hcompfunc nargs/nregs fields being 16 bits. */ -#define DUK__MAX_CONSTS DUK_BC_BC_MAX -#define DUK__MAX_FUNCS DUK_BC_BC_MAX -#define DUK__MAX_TEMPS 0xffffL +#define DUK__MAX_CONSTS DUK_BC_BC_MAX +#define DUK__MAX_FUNCS DUK_BC_BC_MAX +#define DUK__MAX_TEMPS 0xffffL /* Initial bytecode size allocation. */ #if defined(DUK_USE_PREFER_SIZE) -#define DUK__BC_INITIAL_INSTS 16 +#define DUK__BC_INITIAL_INSTS 16 #else -#define DUK__BC_INITIAL_INSTS 256 +#define DUK__BC_INITIAL_INSTS 256 #endif -#define DUK__RECURSION_INCREASE(comp_ctx,thr) do { \ +#define DUK__RECURSION_INCREASE(comp_ctx, thr) \ + do { \ DUK_DDD(DUK_DDDPRINT("RECURSION INCREASE: %s:%ld", (const char *) DUK_FILE_MACRO, (long) DUK_LINE_MACRO)); \ duk__comp_recursion_increase((comp_ctx)); \ } while (0) -#define DUK__RECURSION_DECREASE(comp_ctx,thr) do { \ +#define DUK__RECURSION_DECREASE(comp_ctx, thr) \ + do { \ DUK_DDD(DUK_DDDPRINT("RECURSION DECREASE: %s:%ld", (const char *) DUK_FILE_MACRO, (long) DUK_LINE_MACRO)); \ duk__comp_recursion_decrease((comp_ctx)); \ } while (0) @@ -80,11 +86,11 @@ /* Value stack slot limits: these are quite approximate right now, and * because they overlap in control flow, some could be eliminated. */ -#define DUK__COMPILE_ENTRY_SLOTS 8 -#define DUK__FUNCTION_INIT_REQUIRE_SLOTS 16 -#define DUK__FUNCTION_BODY_REQUIRE_SLOTS 16 -#define DUK__PARSE_STATEMENTS_SLOTS 16 -#define DUK__PARSE_EXPR_SLOTS 16 +#define DUK__COMPILE_ENTRY_SLOTS 8 +#define DUK__FUNCTION_INIT_REQUIRE_SLOTS 16 +#define DUK__FUNCTION_BODY_REQUIRE_SLOTS 16 +#define DUK__PARSE_STATEMENTS_SLOTS 16 +#define DUK__PARSE_EXPR_SLOTS 16 /* Temporary structure used to pass a stack allocated region through * duk_safe_call(). @@ -116,10 +122,14 @@ DUK_LOCAL_DECL duk_compiler_instr *duk__get_instr_ptr(duk_compiler_ctx *comp_ctx, duk_int_t pc); DUK_LOCAL_DECL void duk__emit(duk_compiler_ctx *comp_ctx, duk_instr_t ins); DUK_LOCAL_DECL void duk__emit_op_only(duk_compiler_ctx *comp_ctx, duk_small_uint_t op); -DUK_LOCAL_DECL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b, duk_regconst_t c); +DUK_LOCAL_DECL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, + duk_small_uint_t op_flags, + duk_regconst_t a, + duk_regconst_t b, + duk_regconst_t c); DUK_LOCAL_DECL void duk__emit_a_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b); DUK_LOCAL_DECL void duk__emit_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b, duk_regconst_t c); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL void duk__emit_a(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a); DUK_LOCAL_DECL void duk__emit_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b); #endif @@ -133,7 +143,12 @@ DUK_LOCAL_DECL void duk__insert_jump_entry(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc); DUK_LOCAL_DECL void duk__patch_jump(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc, duk_int_t target_pc); DUK_LOCAL_DECL void duk__patch_jump_here(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc); -DUK_LOCAL_DECL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, duk_int_t ldconst_pc, duk_int_t trycatch_pc, duk_regconst_t reg_catch, duk_regconst_t const_varname, duk_small_uint_t flags); +DUK_LOCAL_DECL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, + duk_int_t ldconst_pc, + duk_int_t trycatch_pc, + duk_regconst_t reg_catch, + duk_regconst_t const_varname, + duk_small_uint_t flags); DUK_LOCAL_DECL void duk__emit_if_false_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst); DUK_LOCAL_DECL void duk__emit_if_true_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst); DUK_LOCAL_DECL void duk__emit_invalid(duk_compiler_ctx *comp_ctx); @@ -164,7 +179,7 @@ duk_regconst_t forced_reg, duk_small_uint_t flags); DUK_LOCAL_DECL duk_regconst_t duk__ivalue_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *x); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__ivalue_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *x); #endif DUK_LOCAL_DECL void duk__ivalue_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *x, duk_int_t forced_reg); @@ -178,7 +193,13 @@ /* label handling */ DUK_LOCAL_DECL void duk__add_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_int_t pc_label, duk_int_t label_id); DUK_LOCAL_DECL void duk__update_label_flags(duk_compiler_ctx *comp_ctx, duk_int_t label_id, duk_small_uint_t flags); -DUK_LOCAL_DECL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_bool_t is_break, duk_int_t *out_label_id, duk_int_t *out_label_catch_depth, duk_int_t *out_label_pc, duk_bool_t *out_is_closest); +DUK_LOCAL_DECL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, + duk_hstring *h_label, + duk_bool_t is_break, + duk_int_t *out_label_id, + duk_int_t *out_label_catch_depth, + duk_int_t *out_label_pc, + duk_bool_t *out_is_closest); DUK_LOCAL_DECL void duk__reset_labels_to_length(duk_compiler_ctx *comp_ctx, duk_size_t len); /* top-down expression parser */ @@ -192,26 +213,32 @@ DUK_LOCAL_DECL void duk__exprtop(duk_compiler_ctx *ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); /* convenience helpers */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -DUK_LOCAL_DECL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg); +DUK_LOCAL_DECL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg); DUK_LOCAL_DECL duk_regconst_t duk__expr_toregconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_totempconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif DUK_LOCAL_DECL void duk__expr_toplain(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); DUK_LOCAL_DECL void duk__expr_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); DUK_LOCAL_DECL duk_regconst_t duk__exprtop_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__exprtop_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -DUK_LOCAL_DECL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg); +DUK_LOCAL_DECL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg); DUK_LOCAL_DECL duk_regconst_t duk__exprtop_toregconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL void duk__exprtop_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif @@ -221,7 +248,11 @@ DUK_LOCAL_DECL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res); /* statement parsing */ -DUK_LOCAL_DECL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags, duk_regconst_t *out_reg_varbind, duk_regconst_t *out_rc_varname); +DUK_LOCAL_DECL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t expr_flags, + duk_regconst_t *out_reg_varbind, + duk_regconst_t *out_rc_varname); DUK_LOCAL_DECL void duk__parse_var_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags); DUK_LOCAL_DECL void duk__parse_for_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site); DUK_LOCAL_DECL void duk__parse_switch_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site); @@ -235,18 +266,25 @@ DUK_LOCAL_DECL void duk__parse_with_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res); DUK_LOCAL_DECL void duk__parse_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_bool_t allow_source_elem); DUK_LOCAL_DECL duk_int_t duk__stmt_label_site(duk_compiler_ctx *comp_ctx, duk_int_t label_id); -DUK_LOCAL_DECL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, duk_bool_t allow_source_elem, duk_bool_t expect_eof, duk_bool_t regexp_after); - -DUK_LOCAL_DECL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, duk_bool_t expect_eof, duk_bool_t implicit_return_value, duk_bool_t regexp_after, duk_small_int_t expect_token); +DUK_LOCAL_DECL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, + duk_bool_t allow_source_elem, + duk_bool_t expect_eof, + duk_bool_t regexp_after); + +DUK_LOCAL_DECL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, + duk_bool_t expect_eof, + duk_bool_t implicit_return_value, + duk_bool_t regexp_after, + duk_small_int_t expect_token); DUK_LOCAL_DECL void duk__parse_func_formals(duk_compiler_ctx *comp_ctx); DUK_LOCAL_DECL void duk__parse_func_like_raw(duk_compiler_ctx *comp_ctx, duk_small_uint_t flags); DUK_LOCAL_DECL duk_int_t duk__parse_func_like_fnum(duk_compiler_ctx *comp_ctx, duk_small_uint_t flags); -#define DUK__FUNC_FLAG_DECL (1 << 0) /* Parsing a function declaration. */ -#define DUK__FUNC_FLAG_GETSET (1 << 1) /* Parsing an object literal getter/setter. */ -#define DUK__FUNC_FLAG_METDEF (1 << 2) /* Parsing an object literal method definition shorthand. */ -#define DUK__FUNC_FLAG_PUSHNAME_PASS1 (1 << 3) /* Push function name when creating template (first pass only). */ -#define DUK__FUNC_FLAG_USE_PREVTOKEN (1 << 4) /* Use prev_token to start function parsing (workaround for object literal). */ +#define DUK__FUNC_FLAG_DECL (1 << 0) /* Parsing a function declaration. */ +#define DUK__FUNC_FLAG_GETSET (1 << 1) /* Parsing an object literal getter/setter. */ +#define DUK__FUNC_FLAG_METDEF (1 << 2) /* Parsing an object literal method definition shorthand. */ +#define DUK__FUNC_FLAG_PUSHNAME_PASS1 (1 << 3) /* Push function name when creating template (first pass only). */ +#define DUK__FUNC_FLAG_USE_PREVTOKEN (1 << 4) /* Use prev_token to start function parsing (workaround for object literal). */ /* * Parser control values for tokens. The token table is ordered by the @@ -263,141 +301,141 @@ /* XXX: actually single step levels would work just fine, clean up */ /* binding power "levels" (see doc/compiler.rst) */ -#define DUK__BP_INVALID 0 /* always terminates led() */ -#define DUK__BP_EOF 2 -#define DUK__BP_CLOSING 4 /* token closes expression, e.g. ')', '' */ -#define DUK__BP_FOR_EXPR DUK__BP_CLOSING /* bp to use when parsing a top level Expression */ -#define DUK__BP_COMMA 6 -#define DUK__BP_ASSIGNMENT 8 -#define DUK__BP_CONDITIONAL 10 -#define DUK__BP_LOR 12 -#define DUK__BP_LAND 14 -#define DUK__BP_BOR 16 -#define DUK__BP_BXOR 18 -#define DUK__BP_BAND 20 -#define DUK__BP_EQUALITY 22 -#define DUK__BP_RELATIONAL 24 -#define DUK__BP_SHIFT 26 -#define DUK__BP_ADDITIVE 28 -#define DUK__BP_MULTIPLICATIVE 30 -#define DUK__BP_EXPONENTIATION 32 -#define DUK__BP_POSTFIX 34 -#define DUK__BP_CALL 36 -#define DUK__BP_MEMBER 38 +#define DUK__BP_INVALID 0 /* always terminates led() */ +#define DUK__BP_EOF 2 +#define DUK__BP_CLOSING 4 /* token closes expression, e.g. ')', '' */ +#define DUK__BP_FOR_EXPR DUK__BP_CLOSING /* bp to use when parsing a top level Expression */ +#define DUK__BP_COMMA 6 +#define DUK__BP_ASSIGNMENT 8 +#define DUK__BP_CONDITIONAL 10 +#define DUK__BP_LOR 12 +#define DUK__BP_LAND 14 +#define DUK__BP_BOR 16 +#define DUK__BP_BXOR 18 +#define DUK__BP_BAND 20 +#define DUK__BP_EQUALITY 22 +#define DUK__BP_RELATIONAL 24 +#define DUK__BP_SHIFT 26 +#define DUK__BP_ADDITIVE 28 +#define DUK__BP_MULTIPLICATIVE 30 +#define DUK__BP_EXPONENTIATION 32 +#define DUK__BP_POSTFIX 34 +#define DUK__BP_CALL 36 +#define DUK__BP_MEMBER 38 #define DUK__TOKEN_LBP_BP_MASK 0x1f -#define DUK__TOKEN_LBP_FLAG_NO_REGEXP (1 << 5) /* regexp literal must not follow this token */ -#define DUK__TOKEN_LBP_FLAG_TERMINATES (1 << 6) /* terminates expression; e.g. post-increment/-decrement */ -#define DUK__TOKEN_LBP_FLAG_UNUSED (1 << 7) /* unused */ +#define DUK__TOKEN_LBP_FLAG_NO_REGEXP (1 << 5) /* regexp literal must not follow this token */ +#define DUK__TOKEN_LBP_FLAG_TERMINATES (1 << 6) /* terminates expression; e.g. post-increment/-decrement */ +#define DUK__TOKEN_LBP_FLAG_UNUSED (1 << 7) /* unused */ -#define DUK__TOKEN_LBP_GET_BP(x) ((duk_small_uint_t) (((x) & DUK__TOKEN_LBP_BP_MASK) * 2)) +#define DUK__TOKEN_LBP_GET_BP(x) ((duk_small_uint_t) (((x) &DUK__TOKEN_LBP_BP_MASK) * 2)) -#define DUK__MK_LBP(bp) ((bp) >> 1) /* bp is assumed to be even */ -#define DUK__MK_LBP_FLAGS(bp,flags) (((bp) >> 1) | (flags)) +#define DUK__MK_LBP(bp) ((bp) >> 1) /* bp is assumed to be even */ +#define DUK__MK_LBP_FLAGS(bp, flags) (((bp) >> 1) | (flags)) DUK_LOCAL const duk_uint8_t duk__token_lbp = { - DUK__MK_LBP(DUK__BP_EOF), /* DUK_TOK_EOF */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_IDENTIFIER */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BREAK */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CASE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CATCH */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONTINUE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEBUGGER */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEFAULT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DELETE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DO */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ELSE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FINALLY */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FOR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FUNCTION */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IF */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_IN */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_INSTANCEOF */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_NEW */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_RETURN */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SWITCH */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_THIS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_THROW */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TRY */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TYPEOF */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VAR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONST */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VOID */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WHILE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WITH */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CLASS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ENUM */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXPORT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXTENDS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPORT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SUPER */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NULL */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_TRUE */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_FALSE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_GET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPLEMENTS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_INTERFACE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PACKAGE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PRIVATE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PROTECTED */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PUBLIC */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_STATIC */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_YIELD */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LCURLY */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RCURLY */ - DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_LBRACKET */ - DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RBRACKET */ - DUK__MK_LBP(DUK__BP_CALL), /* DUK_TOK_LPAREN */ - DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RPAREN */ - DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_PERIOD */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SEMICOLON */ - DUK__MK_LBP(DUK__BP_COMMA), /* DUK_TOK_COMMA */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LT */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GT */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LE */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GE */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_EQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_NEQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SEQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SNEQ */ - DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_ADD */ - DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_SUB */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MUL */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_DIV */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MOD */ - DUK__MK_LBP(DUK__BP_EXPONENTIATION), /* DUK_TOK_EXP */ - DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_INCREMENT */ - DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_DECREMENT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ALSHIFT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ARSHIFT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_RSHIFT */ - DUK__MK_LBP(DUK__BP_BAND), /* DUK_TOK_BAND */ - DUK__MK_LBP(DUK__BP_BOR), /* DUK_TOK_BOR */ - DUK__MK_LBP(DUK__BP_BXOR), /* DUK_TOK_BXOR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LNOT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BNOT */ - DUK__MK_LBP(DUK__BP_LAND), /* DUK_TOK_LAND */ - DUK__MK_LBP(DUK__BP_LOR), /* DUK_TOK_LOR */ - DUK__MK_LBP(DUK__BP_CONDITIONAL), /* DUK_TOK_QUESTION */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_COLON */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EQUALSIGN */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ADD_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_SUB_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MUL_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_DIV_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MOD_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EXP_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ALSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ARSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_RSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BAND_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BOR_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BXOR_EQ */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NUMBER */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_STRING */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_REGEXP */ + DUK__MK_LBP(DUK__BP_EOF), /* DUK_TOK_EOF */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_IDENTIFIER */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BREAK */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CASE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CATCH */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONTINUE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEBUGGER */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEFAULT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DELETE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DO */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ELSE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FINALLY */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FOR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FUNCTION */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IF */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_IN */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_INSTANCEOF */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_NEW */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_RETURN */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SWITCH */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_THIS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_THROW */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TRY */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TYPEOF */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VAR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONST */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VOID */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WHILE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WITH */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CLASS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ENUM */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXPORT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXTENDS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPORT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SUPER */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NULL */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_TRUE */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_FALSE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_GET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPLEMENTS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_INTERFACE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PACKAGE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PRIVATE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PROTECTED */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PUBLIC */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_STATIC */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_YIELD */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LCURLY */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RCURLY */ + DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_LBRACKET */ + DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RBRACKET */ + DUK__MK_LBP(DUK__BP_CALL), /* DUK_TOK_LPAREN */ + DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RPAREN */ + DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_PERIOD */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SEMICOLON */ + DUK__MK_LBP(DUK__BP_COMMA), /* DUK_TOK_COMMA */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LT */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GT */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LE */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GE */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_EQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_NEQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SEQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SNEQ */ + DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_ADD */ + DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_SUB */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MUL */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_DIV */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MOD */ + DUK__MK_LBP(DUK__BP_EXPONENTIATION), /* DUK_TOK_EXP */ + DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_INCREMENT */ + DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_DECREMENT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ALSHIFT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ARSHIFT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_RSHIFT */ + DUK__MK_LBP(DUK__BP_BAND), /* DUK_TOK_BAND */ + DUK__MK_LBP(DUK__BP_BOR), /* DUK_TOK_BOR */ + DUK__MK_LBP(DUK__BP_BXOR), /* DUK_TOK_BXOR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LNOT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BNOT */ + DUK__MK_LBP(DUK__BP_LAND), /* DUK_TOK_LAND */ + DUK__MK_LBP(DUK__BP_LOR), /* DUK_TOK_LOR */ + DUK__MK_LBP(DUK__BP_CONDITIONAL), /* DUK_TOK_QUESTION */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_COLON */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EQUALSIGN */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ADD_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_SUB_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MUL_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_DIV_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MOD_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EXP_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ALSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ARSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_RSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BAND_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BOR_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BXOR_EQ */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NUMBER */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_STRING */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_REGEXP */ }; /* @@ -428,8 +466,7 @@ DUK_LOCAL duk_bool_t duk__hstring_is_eval_or_arguments_in_strict_mode(duk_compiler_ctx *comp_ctx, duk_hstring *h) { DUK_ASSERT(h != NULL); - return (comp_ctx->curr_func.is_strict && - DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(h)); + return (comp_ctx->curr_func.is_strict && DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(h)); } /* @@ -444,8 +481,8 @@ duk_hthread *thr = comp_ctx->thr; duk_bool_t regexp; - DUK_ASSERT_DISABLE(comp_ctx->curr_token.t >= 0); /* unsigned */ - DUK_ASSERT(comp_ctx->curr_token.t <= DUK_TOK_MAXVAL); /* MAXVAL is inclusive */ + DUK_ASSERT_DISABLE(comp_ctx->curr_token.t >= 0); /* unsigned */ + DUK_ASSERT(comp_ctx->curr_token.t <= DUK_TOK_MAXVAL); /* MAXVAL is inclusive */ /* * Use current token to decide whether a RegExp can follow. @@ -470,8 +507,7 @@ } if (expect >= 0 && comp_ctx->curr_token.t != (duk_small_uint_t) expect) { - DUK_D(DUK_DPRINT("parse error: expect=%ld, got=%ld", - (long) expect, (long) comp_ctx->curr_token.t)); + DUK_D(DUK_DPRINT("parse error: expect=%ld, got=%ld", (long) expect, (long) comp_ctx->curr_token.t)); DUK_ERROR_SYNTAX(thr, DUK_STR_PARSE_ERROR); DUK_WO_NORETURN(return;); } @@ -482,10 +518,7 @@ duk_copy(thr, comp_ctx->tok12_idx, comp_ctx->tok22_idx); /* parse new token */ - duk_lexer_parse_js_input_element(&comp_ctx->lex, - &comp_ctx->curr_token, - comp_ctx->curr_func.is_strict, - regexp); + duk_lexer_parse_js_input_element(&comp_ctx->lex, &comp_ctx->curr_token, comp_ctx->curr_func.is_strict, regexp); DUK_DDD(DUK_DDDPRINT("advance: curr: tok=%ld/%ld,%ld,term=%ld,%!T,%!T " "prev: tok=%ld/%ld,%ld,term=%ld,%!T,%!T", @@ -525,7 +558,7 @@ entry_top = duk_get_top(thr); - duk_memzero(func, sizeof(*func)); /* intentional overlap with earlier memzero */ + duk_memzero(func, sizeof(*func)); /* intentional overlap with earlier memzero */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) func->h_name = NULL; func->h_consts = NULL; @@ -691,7 +724,7 @@ h_res = duk_push_hcompfunc(thr); DUK_ASSERT(h_res != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_res) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); - DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) h_res, NULL); /* Function templates are "bare objects". */ + DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) h_res, NULL); /* Function templates are "bare objects". */ if (func->is_function) { DUK_DDD(DUK_DDDPRINT("function -> set NEWENV")); @@ -760,16 +793,19 @@ code_count = DUK_BW_GET_SIZE(thr, &func->bw_code) / sizeof(duk_compiler_instr); code_size = code_count * sizeof(duk_instr_t); - data_size = consts_count * sizeof(duk_tval) + - funcs_count * sizeof(duk_hobject *) + - code_size; + data_size = consts_count * sizeof(duk_tval) + funcs_count * sizeof(duk_hobject *) + code_size; DUK_DDD(DUK_DDDPRINT("consts_count=%ld, funcs_count=%ld, code_size=%ld -> " "data_size=%ld*%ld + %ld*%ld + %ld = %ld", - (long) consts_count, (long) funcs_count, (long) code_size, - (long) consts_count, (long) sizeof(duk_tval), - (long) funcs_count, (long) sizeof(duk_hobject *), - (long) code_size, (long) data_size)); + (long) consts_count, + (long) funcs_count, + (long) code_size, + (long) consts_count, + (long) sizeof(duk_tval), + (long) funcs_count, + (long) sizeof(duk_hobject *), + (long) code_size, + (long) data_size)); duk_push_fixed_buffer_nozero(thr, data_size); h_data = (duk_hbuffer_fixed *) (void *) duk_known_hbuffer(thr, -1); @@ -779,12 +815,12 @@ p_const = (duk_tval *) (void *) DUK_HBUFFER_FIXED_GET_DATA_PTR(thr->heap, h_data); for (i = 0; i < consts_count; i++) { - DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* const limits */ + DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* const limits */ tv = duk_hobject_find_array_entry_tval_ptr(thr->heap, func->h_consts, (duk_uarridx_t) i); DUK_ASSERT(tv != NULL); DUK_TVAL_SET_TVAL(p_const, tv); p_const++; - DUK_TVAL_INCREF(thr, tv); /* may be a string constant */ + DUK_TVAL_INCREF(thr, tv); /* may be a string constant */ DUK_DDD(DUK_DDDPRINT("constant: %!T", (duk_tval *) tv)); } @@ -793,7 +829,7 @@ DUK_HCOMPFUNC_SET_FUNCS(thr->heap, h_res, p_func); for (i = 0; i < funcs_count; i++) { duk_hobject *h; - DUK_ASSERT(i * 3 <= DUK_UARRIDX_MAX); /* func limits */ + DUK_ASSERT(i * 3 <= DUK_UARRIDX_MAX); /* func limits */ tv = duk_hobject_find_array_entry_tval_ptr(thr->heap, func->h_funcs, (duk_uarridx_t) (i * 3)); DUK_ASSERT(tv != NULL); DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv)); @@ -803,8 +839,7 @@ *p_func++ = h; DUK_HOBJECT_INCREF(thr, h); - DUK_DDD(DUK_DDDPRINT("inner function: %p -> %!iO", - (void *) h, (duk_heaphdr *) h)); + DUK_DDD(DUK_DDDPRINT("inner function: %p -> %!iO", (void *) h, (duk_heaphdr *) h)); } p_instr = (duk_instr_t *) p_func; @@ -819,7 +854,7 @@ DUK_ASSERT((duk_uint8_t *) (p_instr + code_count) == DUK_HBUFFER_FIXED_GET_DATA_PTR(thr->heap, h_data) + data_size); - duk_pop(thr); /* 'data' (and everything in it) is reachable through h_res now */ + duk_pop(thr); /* 'data' (and everything in it) is reachable through h_res now */ /* * Init non-property result fields @@ -834,7 +869,7 @@ DUK_ASSERT(func->temp_max >= 0); h_res->nregs = (duk_uint16_t) func->temp_max; h_res->nargs = (duk_uint16_t) duk_hobject_get_length(thr, func->h_argnames); - DUK_ASSERT(h_res->nregs >= h_res->nargs); /* pass2 allocation handles this */ + DUK_ASSERT(h_res->nregs >= h_res->nargs); /* pass2 allocation handles this */ #if defined(DUK_USE_DEBUGGER_SUPPORT) h_res->start_line = (duk_uint32_t) func->min_line; h_res->end_line = (duk_uint32_t) func->max_line; @@ -862,11 +897,13 @@ DUK_DD(DUK_DDPRINT("keeping _Varmap because debugger support is enabled")); keep_varmap = 1; #else - if (func->id_access_slow_own || /* directly uses slow accesses that may match own variables */ - func->id_access_arguments || /* accesses 'arguments' directly */ - func->may_direct_eval || /* may indirectly slow access through a direct eval */ - funcs_count > 0) { /* has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions) */ - DUK_DD(DUK_DDPRINT("keeping _Varmap because of direct eval, slow path access that may match local variables, or presence of inner functions")); + if (func->id_access_slow_own || /* directly uses slow accesses that may match own variables */ + func->id_access_arguments || /* accesses 'arguments' directly */ + func->may_direct_eval || /* may indirectly slow access through a direct eval */ + funcs_count > + 0) { /* has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions) */ + DUK_DD(DUK_DDPRINT("keeping _Varmap because of direct eval, slow path access that may match local variables, or " + "presence of inner functions")); keep_varmap = 1; } else { DUK_DD(DUK_DDPRINT("dropping _Varmap")); @@ -878,8 +915,7 @@ duk_int_t num_used; duk_dup(thr, func->varmap_idx); num_used = duk__cleanup_varmap(comp_ctx); - DUK_DDD(DUK_DDDPRINT("cleaned up varmap: %!T (num_used=%ld)", - (duk_tval *) duk_get_tval(thr, -1), (long) num_used)); + DUK_DDD(DUK_DDDPRINT("cleaned up varmap: %!T (num_used=%ld)", (duk_tval *) duk_get_tval(thr, -1), (long) num_used)); if (num_used > 0) { duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VARMAP, DUK_PROPDESC_FLAGS_NONE); @@ -908,12 +944,12 @@ */ DUK_DD(DUK_DDPRINT("keeping _Formals because _Formals.length != nargs")); keep_formals = 1; - } else if ((func->id_access_arguments || func->may_direct_eval) && - (formals_length > 0)) { + } else if ((func->id_access_arguments || func->may_direct_eval) && (formals_length > 0)) { /* Direct eval (may access 'arguments') or accesses 'arguments' * explicitly: keep _Formals unless it is zero length. */ - DUK_DD(DUK_DDPRINT("keeping _Formals because of direct eval or explicit access to 'arguments', and _Formals.length != 0")); + DUK_DD(DUK_DDPRINT( + "keeping _Formals because of direct eval or explicit access to 'arguments', and _Formals.length != 0")); keep_formals = 1; } else { DUK_DD(DUK_DDPRINT("omitting _Formals, nargs matches _Formals.length, so no properties added")); @@ -933,7 +969,7 @@ DUK_DD(DUK_DDPRINT("setting function template .name to %!T", duk_get_tval(thr, -1))); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_NONE); } -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ /* _Source */ #if defined(DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY) @@ -981,7 +1017,7 @@ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_SOURCE, DUK_PROPDESC_FLAGS_NONE); #endif } -#endif /* DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY */ +#endif /* DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY */ /* _Pc2line */ #if defined(DUK_USE_PC2LINE) @@ -991,14 +1027,14 @@ */ DUK_ASSERT(code_count <= DUK_COMPILER_MAX_BYTECODE_LENGTH); - duk_hobject_pc2line_pack(thr, q_instr, (duk_uint_fast32_t) code_count); /* -> pushes fixed buffer */ + duk_hobject_pc2line_pack(thr, q_instr, (duk_uint_fast32_t) code_count); /* -> pushes fixed buffer */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_NONE); /* XXX: if assertions enabled, walk through all valid PCs * and check line mapping. */ } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ /* fileName */ #if defined(DUK_USE_FUNC_FILENAME_PROPERTY) @@ -1012,8 +1048,7 @@ } #endif - DUK_DD(DUK_DDPRINT("converted function: %!ixT", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DD(DUK_DDPRINT("converted function: %!ixT", (duk_tval *) duk_get_tval(thr, -1))); /* * Compact the function template. @@ -1085,14 +1120,14 @@ /* Code emission flags, passed in the 'opcode' field. Opcode + flags * fit into 16 bits for now, so use duk_small_uint_t. */ -#define DUK__EMIT_FLAG_NO_SHUFFLE_A (1 << 8) -#define DUK__EMIT_FLAG_NO_SHUFFLE_B (1 << 9) -#define DUK__EMIT_FLAG_NO_SHUFFLE_C (1 << 10) -#define DUK__EMIT_FLAG_A_IS_SOURCE (1 << 11) /* slot A is a source (default: target) */ -#define DUK__EMIT_FLAG_B_IS_TARGET (1 << 12) /* slot B is a target (default: source) */ -#define DUK__EMIT_FLAG_C_IS_TARGET (1 << 13) /* slot C is a target (default: source) */ -#define DUK__EMIT_FLAG_BC_REGCONST (1 << 14) /* slots B and C are reg/const */ -#define DUK__EMIT_FLAG_RESERVE_JUMPSLOT (1 << 15) /* reserve a jumpslot after instr before target spilling, used for NEXTENUM */ +#define DUK__EMIT_FLAG_NO_SHUFFLE_A (1 << 8) +#define DUK__EMIT_FLAG_NO_SHUFFLE_B (1 << 9) +#define DUK__EMIT_FLAG_NO_SHUFFLE_C (1 << 10) +#define DUK__EMIT_FLAG_A_IS_SOURCE (1 << 11) /* slot A is a source (default: target) */ +#define DUK__EMIT_FLAG_B_IS_TARGET (1 << 12) /* slot B is a target (default: source) */ +#define DUK__EMIT_FLAG_C_IS_TARGET (1 << 13) /* slot C is a target (default: source) */ +#define DUK__EMIT_FLAG_BC_REGCONST (1 << 14) /* slots B and C are reg/const */ +#define DUK__EMIT_FLAG_RESERVE_JUMPSLOT (1 << 15) /* reserve a jumpslot after instr before target spilling, used for NEXTENUM */ /* XXX: macro smaller than call? */ DUK_LOCAL duk_int_t duk__get_current_pc(duk_compiler_ctx *comp_ctx) { @@ -1103,7 +1138,8 @@ DUK_LOCAL duk_compiler_instr *duk__get_instr_ptr(duk_compiler_ctx *comp_ctx, duk_int_t pc) { DUK_ASSERT(pc >= 0); - DUK_ASSERT((duk_size_t) pc < (duk_size_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr))); + DUK_ASSERT((duk_size_t) pc < + (duk_size_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr))); return ((duk_compiler_instr *) (void *) DUK_BW_GET_BASEPTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code)) + pc; } @@ -1123,7 +1159,9 @@ (long) duk__get_current_pc(comp_ctx), (duk_instr_t) ins)); - instr = (duk_compiler_instr *) (void *) DUK_BW_ENSURE_GETPTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, sizeof(duk_compiler_instr)); + instr = (duk_compiler_instr *) (void *) DUK_BW_ENSURE_GETPTR(comp_ctx->thr, + &comp_ctx->curr_func.bw_code, + sizeof(duk_compiler_instr)); DUK_BW_ADD_PTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, sizeof(duk_compiler_instr)); #if defined(DUK_USE_PC2LINE) @@ -1174,7 +1212,7 @@ return; - fail_bc_limit: +fail_bc_limit: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_BYTECODE_LIMIT); DUK_WO_NORETURN(return;); } @@ -1208,7 +1246,11 @@ } /* Important main primitive. */ -DUK_LOCAL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b, duk_regconst_t c) { +DUK_LOCAL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, + duk_small_uint_t op_flags, + duk_regconst_t a, + duk_regconst_t b, + duk_regconst_t c) { duk_instr_t ins = 0; duk_int_t a_out = -1; duk_int_t b_out = -1; @@ -1216,8 +1258,7 @@ duk_int_t tmp; duk_small_uint_t op = op_flags & 0xffU; - DUK_DDD(DUK_DDDPRINT("emit: op_flags=%04lx, a=%ld, b=%ld, c=%ld", - (unsigned long) op_flags, (long) a, (long) b, (long) c)); + DUK_DDD(DUK_DDDPRINT("emit: op_flags=%04lx, a=%ld, b=%ld, c=%ld", (unsigned long) op_flags, (long) a, (long) b, (long) c)); /* We could rely on max temp/const checks: if they don't exceed BC * limit, nothing here can either (just asserts would be enough). @@ -1226,11 +1267,11 @@ * bugs. */ - DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT((op_flags & 0xff) <= DUK_BC_OP_MAX); DUK_ASSERT(DUK__ISREG(a)); - DUK_ASSERT(b != -1); /* Not 'none'. */ - DUK_ASSERT(c != -1); /* Not 'none'. */ + DUK_ASSERT(b != -1); /* Not 'none'. */ + DUK_ASSERT(c != -1); /* Not 'none'. */ /* Input shuffling happens before the actual operation, while output * shuffling happens afterwards. Output shuffling decisions are still @@ -1292,7 +1333,7 @@ if (op_flags & DUK__EMIT_FLAG_BC_REGCONST) { /* Opcode follows B/C reg/const convention. */ DUK_ASSERT((op & 0x01) == 0); - ins |= DUK_ENC_OP_A_B_C(0x01, 0, 0, 0); /* const flag for B */ + ins |= DUK_ENC_OP_A_B_C(0x01, 0, 0, 0); /* const flag for B */ } else { DUK_D(DUK_DPRINT("B is const, opcode is not B/C reg/const: %x", op_flags)); } @@ -1315,7 +1356,8 @@ } else if (op_flags & DUK__EMIT_FLAG_NO_SHUFFLE_B) { if (b > DUK_BC_B_MAX) { /* Note: 0xff != DUK_BC_B_MAX */ - DUK_D(DUK_DPRINT("out of regs: 'b' (reg) needs shuffling but shuffle prohibited, b: %ld", (long) b)); + DUK_D( + DUK_DPRINT("out of regs: 'b' (reg) needs shuffling but shuffle prohibited, b: %ld", (long) b)); goto error_outofregs; } } else if (b <= DUK_BC_BC_MAX) { @@ -1336,7 +1378,7 @@ duk__emit_load_int32_noshuffle(comp_ctx, tmp, b); DUK_ASSERT(DUK_OP_MPUTOBJI == DUK_OP_MPUTOBJ + 1); DUK_ASSERT(DUK_OP_MPUTARRI == DUK_OP_MPUTARR + 1); - op_flags++; /* indirect opcode follows direct */ + op_flags++; /* indirect opcode follows direct */ } else { duk__emit(comp_ctx, DUK_ENC_OP_A_BC(DUK_OP_LDREG, tmp, b)); } @@ -1362,7 +1404,7 @@ if (op_flags & DUK__EMIT_FLAG_BC_REGCONST) { /* Opcode follows B/C reg/const convention. */ DUK_ASSERT((op & 0x02) == 0); - ins |= DUK_ENC_OP_A_B_C(0x02, 0, 0, 0); /* const flag for C */ + ins |= DUK_ENC_OP_A_B_C(0x02, 0, 0, 0); /* const flag for C */ } else { DUK_D(DUK_DPRINT("C is const, opcode is not B/C reg/const: %x", op_flags)); } @@ -1385,7 +1427,8 @@ } else if (op_flags & DUK__EMIT_FLAG_NO_SHUFFLE_C) { if (c > DUK_BC_C_MAX) { /* Note: 0xff != DUK_BC_C_MAX */ - DUK_D(DUK_DPRINT("out of regs: 'c' (reg) needs shuffling but shuffle prohibited, c: %ld", (long) c)); + DUK_D( + DUK_DPRINT("out of regs: 'c' (reg) needs shuffling but shuffle prohibited, c: %ld", (long) c)); goto error_outofregs; } } else if (c <= DUK_BC_BC_MAX) { @@ -1459,7 +1502,7 @@ return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -1487,7 +1530,7 @@ duk__emit_a_b_c(comp_ctx, op_flags, 0, b, c); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__emit_a(duk_compiler_ctx *comp_ctx, int op_flags, int a) { #if defined(DUK_USE_SHUFFLE_TORTURE) op_flags |= DUK__EMIT_FLAG_NO_SHUFFLE_B | DUK__EMIT_FLAG_NO_SHUFFLE_C; @@ -1496,7 +1539,7 @@ } #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__emit_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b) { #if defined(DUK_USE_SHUFFLE_TORTURE) op_flags |= DUK__EMIT_FLAG_NO_SHUFFLE_A | DUK__EMIT_FLAG_NO_SHUFFLE_C; @@ -1510,10 +1553,10 @@ duk_int_t tmp; /* allow caller to give a const number with the DUK__CONST_MARKER */ - DUK_ASSERT(bc != -1); /* Not 'none'. */ + DUK_ASSERT(bc != -1); /* Not 'none'. */ bc = bc & (~DUK__CONST_MARKER); - DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT((op_flags & 0xff) <= DUK_BC_OP_MAX); DUK_ASSERT(bc >= DUK_BC_BC_MIN); DUK_ASSERT(bc <= DUK_BC_BC_MAX); @@ -1558,7 +1601,7 @@ } return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -1573,12 +1616,12 @@ DUK_LOCAL void duk__emit_abc(duk_compiler_ctx *comp_ctx, duk_small_uint_t op, duk_regconst_t abc) { duk_instr_t ins; - DUK_ASSERT_DISABLE(op >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE(op >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT(op <= DUK_BC_OP_MAX); - DUK_ASSERT_DISABLE(abc >= DUK_BC_ABC_MIN); /* unsigned */ + DUK_ASSERT_DISABLE(abc >= DUK_BC_ABC_MIN); /* unsigned */ DUK_ASSERT(abc <= DUK_BC_ABC_MAX); DUK_ASSERT((abc & DUK__CONST_MARKER) == 0); - DUK_ASSERT(abc != -1); /* Not 'none'. */ + DUK_ASSERT(abc != -1); /* Not 'none'. */ if (abc <= DUK_BC_ABC_MAX) { ; @@ -1587,18 +1630,25 @@ } ins = DUK_ENC_OP_ABC(op, abc); DUK_DDD(DUK_DDDPRINT("duk__emit_abc: 0x%08lx line=%ld pc=%ld op=%ld (%!X) abc=%ld (%!I)", - (unsigned long) ins, (long) comp_ctx->curr_token.start_line, - (long) duk__get_current_pc(comp_ctx), (long) op, (long) op, - (long) abc, (duk_instr_t) ins)); + (unsigned long) ins, + (long) comp_ctx->curr_token.start_line, + (long) duk__get_current_pc(comp_ctx), + (long) op, + (long) op, + (long) abc, + (duk_instr_t) ins)); duk__emit(comp_ctx, ins); return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } -DUK_LOCAL void duk__emit_load_int32_raw(duk_compiler_ctx *comp_ctx, duk_regconst_t reg, duk_int32_t val, duk_small_uint_t op_flags) { +DUK_LOCAL void duk__emit_load_int32_raw(duk_compiler_ctx *comp_ctx, + duk_regconst_t reg, + duk_int32_t val, + duk_small_uint_t op_flags) { /* XXX: Shuffling support could be implemented here so that LDINT+LDINTX * would only shuffle once (instead of twice). The current code works * though, and has a smaller compiler footprint. @@ -1613,7 +1663,10 @@ duk_int32_t lo = val & ((((duk_int32_t) 1) << DUK_BC_LDINTX_SHIFT) - 1); DUK_ASSERT(lo >= 0); DUK_DDD(DUK_DDDPRINT("emit LDINT+LDINTX to reg %ld for %ld -> hi %ld, lo %ld", - (long) reg, (long) val, (long) hi, (long) lo)); + (long) reg, + (long) val, + (long) hi, + (long) lo)); duk__emit_a_bc(comp_ctx, DUK_OP_LDINT | op_flags, reg, (duk_regconst_t) (hi + (duk_int32_t) DUK_BC_LDINT_BIAS)); duk__emit_a_bc(comp_ctx, DUK_OP_LDINTX | op_flags, reg, (duk_regconst_t) lo); } @@ -1654,7 +1707,7 @@ DUK_LOCAL duk_int_t duk__emit_jump_empty(duk_compiler_ctx *comp_ctx) { duk_int_t ret; - ret = duk__get_current_pc(comp_ctx); /* useful for patching jumps later */ + ret = duk__get_current_pc(comp_ctx); /* useful for patching jumps later */ duk__emit_op_only(comp_ctx, DUK_OP_JUMP); return ret; } @@ -1672,13 +1725,10 @@ DUK_ASSERT(jump_pc >= 0); offset = (duk_size_t) jump_pc * sizeof(duk_compiler_instr); instr = (duk_compiler_instr *) (void *) - DUK_BW_INSERT_ENSURE_AREA(comp_ctx->thr, - &comp_ctx->curr_func.bw_code, - offset, - sizeof(duk_compiler_instr)); + DUK_BW_INSERT_ENSURE_AREA(comp_ctx->thr, &comp_ctx->curr_func.bw_code, offset, sizeof(duk_compiler_instr)); #if defined(DUK_USE_PC2LINE) - line = comp_ctx->curr_token.start_line; /* approximation, close enough */ + line = comp_ctx->curr_token.start_line; /* approximation, close enough */ #endif instr->ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, 0); #if defined(DUK_USE_PC2LINE) @@ -1691,7 +1741,7 @@ } return; - fail_bc_limit: +fail_bc_limit: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_BYTECODE_LIMIT); DUK_WO_NORETURN(return;); } @@ -1705,8 +1755,8 @@ /* allow negative PCs, behave as a no-op */ if (jump_pc < 0) { - DUK_DDD(DUK_DDDPRINT("duk__patch_jump(): nop call, jump_pc=%ld (<0), target_pc=%ld", - (long) jump_pc, (long) target_pc)); + DUK_DDD( + DUK_DDDPRINT("duk__patch_jump(): nop call, jump_pc=%ld (<0), target_pc=%ld", (long) jump_pc, (long) target_pc)); return; } DUK_ASSERT(jump_pc >= 0); @@ -1720,14 +1770,21 @@ instr->ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, offset + DUK_BC_JUMP_BIAS); DUK_DDD(DUK_DDDPRINT("duk__patch_jump(): jump_pc=%ld, target_pc=%ld, offset=%ld", - (long) jump_pc, (long) target_pc, (long) offset)); + (long) jump_pc, + (long) target_pc, + (long) offset)); } DUK_LOCAL void duk__patch_jump_here(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc) { duk__patch_jump(comp_ctx, jump_pc, duk__get_current_pc(comp_ctx)); } -DUK_LOCAL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, duk_int_t ldconst_pc, duk_int_t trycatch_pc, duk_regconst_t reg_catch, duk_regconst_t const_varname, duk_small_uint_t flags) { +DUK_LOCAL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, + duk_int_t ldconst_pc, + duk_int_t trycatch_pc, + duk_regconst_t reg_catch, + duk_regconst_t const_varname, + duk_small_uint_t flags) { duk_compiler_instr *instr; DUK_ASSERT(DUK__ISREG(reg_catch)); @@ -1747,7 +1804,10 @@ * See: test-bug-trycatch-many-constants.js. */ DUK_D(DUK_DPRINT("failed to patch trycatch: flags=%ld, reg_catch=%ld, const_varname=%ld (0x%08lx)", - (long) flags, (long) reg_catch, (long) const_varname, (long) const_varname)); + (long) flags, + (long) reg_catch, + (long) const_varname, + (long) const_varname)); DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -1770,14 +1830,14 @@ duk_small_uint_t op; op = DUK__ISREG(regconst) ? DUK_OP_IFFALSE_R : DUK_OP_IFFALSE_C; - duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ + duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ } DUK_LOCAL void duk__emit_if_true_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst) { duk_small_uint_t op; op = DUK__ISREG(regconst) ? DUK_OP_IFTRUE_R : DUK_OP_IFTRUE_C; - duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ + duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ } DUK_LOCAL void duk__emit_invalid(duk_compiler_ctx *comp_ctx) { @@ -1801,7 +1861,8 @@ #if defined(DUK_USE_BUFLEN16) /* No need to assert, buffer size maximum is 0xffff. */ #else - DUK_ASSERT((duk_size_t) DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr) <= (duk_size_t) DUK_INT_MAX); /* bytecode limits */ + DUK_ASSERT((duk_size_t) DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr) <= + (duk_size_t) DUK_INT_MAX); /* bytecode limits */ #endif n = (duk_int_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr)); @@ -1836,7 +1897,9 @@ target_pc2 = target_pc1 + 1 + (duk_int_t) DUK_DEC_ABC(ins) - (duk_int_t) DUK_BC_JUMP_BIAS; DUK_DDD(DUK_DDDPRINT("optimizing jump at pc %ld; old target is %ld -> new target is %ld", - (long) i, (long) target_pc1, (long) target_pc2)); + (long) i, + (long) target_pc1, + (long) target_pc2)); bci.ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, target_pc2 - (i + 1) + DUK_BC_JUMP_BIAS); @@ -1862,15 +1925,21 @@ /* XXX: DUK__IVAL_FLAG_REQUIRE_SHORT is passed but not currently implemented * by ispec/ivalue operations. */ -#define DUK__IVAL_FLAG_ALLOW_CONST (1 << 0) /* allow a constant to be returned */ -#define DUK__IVAL_FLAG_REQUIRE_TEMP (1 << 1) /* require a (mutable) temporary as a result (or a const if allowed) */ -#define DUK__IVAL_FLAG_REQUIRE_SHORT (1 << 2) /* require a short (8-bit) reg/const which fits into bytecode B/C slot */ +#define DUK__IVAL_FLAG_ALLOW_CONST (1 << 0) /* allow a constant to be returned */ +#define DUK__IVAL_FLAG_REQUIRE_TEMP (1 << 1) /* require a (mutable) temporary as a result (or a const if allowed) */ +#define DUK__IVAL_FLAG_REQUIRE_SHORT (1 << 2) /* require a short (8-bit) reg/const which fits into bytecode B/C slot */ /* XXX: some code might benefit from DUK__SETTEMP_IFTEMP(thr,x) */ -#if 0 /* enable manually for dumping */ -#define DUK__DUMP_ISPEC(compctx,ispec) do { duk__dump_ispec((compctx), (ispec)); } while (0) -#define DUK__DUMP_IVALUE(compctx,ivalue) do { duk__dump_ivalue((compctx), (ivalue)); } while (0) +#if 0 /* enable manually for dumping */ +#define DUK__DUMP_ISPEC(compctx, ispec) \ + do { \ + duk__dump_ispec((compctx), (ispec)); \ + } while (0) +#define DUK__DUMP_IVALUE(compctx, ivalue) \ + do { \ + duk__dump_ivalue((compctx), (ivalue)); \ + } while (0) DUK_LOCAL void duk__dump_ispec(duk_compiler_ctx *comp_ctx, duk_ispec *x) { DUK_D(DUK_DPRINT("ispec dump: t=%ld regconst=0x%08lx, valstack_idx=%ld, value=%!T", @@ -1888,8 +1957,12 @@ duk_get_tval(comp_ctx->thr, x->x2.valstack_idx))); } #else -#define DUK__DUMP_ISPEC(comp_ctx,x) do {} while (0) -#define DUK__DUMP_IVALUE(comp_ctx,x) do {} while (0) +#define DUK__DUMP_ISPEC(comp_ctx, x) \ + do { \ + } while (0) +#define DUK__DUMP_IVALUE(comp_ctx, x) \ + do { \ + } while (0) #endif DUK_LOCAL void duk__ivalue_regconst(duk_ivalue *x, duk_regconst_t regconst) { @@ -1939,7 +2012,7 @@ res = comp_ctx->curr_func.temp_next; comp_ctx->curr_func.temp_next += num; - if (comp_ctx->curr_func.temp_next > DUK__MAX_TEMPS) { /* == DUK__MAX_TEMPS is OK */ + if (comp_ctx->curr_func.temp_next > DUK__MAX_TEMPS) { /* == DUK__MAX_TEMPS is OK */ DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_TEMP_LIMIT); DUK_WO_NORETURN(return 0;); } @@ -1992,8 +2065,7 @@ * constant for e.g. +0 and -0. */ if (duk_js_samevalue(tv1, tv2)) { - DUK_DDD(DUK_DDDPRINT("reused existing constant for %!T -> const index %ld", - (duk_tval *) tv1, (long) i)); + DUK_DDD(DUK_DDDPRINT("reused existing constant for %!T -> const index %ld", (duk_tval *) tv1, (long) i)); duk_pop(thr); return (duk_regconst_t) i | (duk_regconst_t) DUK__CONST_MARKER; } @@ -2004,9 +2076,8 @@ DUK_WO_NORETURN(return 0;); } - DUK_DDD(DUK_DDDPRINT("allocating new constant for %!T -> const index %ld", - (duk_tval *) tv1, (long) n)); - (void) duk_put_prop_index(thr, f->consts_idx, (duk_uarridx_t) n); /* invalidates tv1, tv2 */ + DUK_DDD(DUK_DDDPRINT("allocating new constant for %!T -> const index %ld", (duk_tval *) tv1, (long) n)); + (void) duk_put_prop_index(thr, f->consts_idx, (duk_uarridx_t) n); /* invalidates tv1, tv2 */ return (duk_regconst_t) n | (duk_regconst_t) DUK__CONST_MARKER; } @@ -2015,15 +2086,15 @@ duk_compiler_func *f = &comp_ctx->curr_func; duk_bool_t ret; - DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ + DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ (void) duk_get_prop_index(comp_ctx->thr, f->consts_idx, (duk_uarridx_t) rc); - ret = !duk_is_number(comp_ctx->thr, -1); /* now only number/string, so conservative check */ + ret = !duk_is_number(comp_ctx->thr, -1); /* now only number/string, so conservative check */ duk_pop(comp_ctx->thr); return ret; #else DUK_UNREF(comp_ctx); DUK_UNREF(rc); - DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ + DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ return 0; #endif } @@ -2086,9 +2157,7 @@ } case DUK_TAG_BOOLEAN: { duk_regconst_t dest = (forced_reg >= 0 ? forced_reg : DUK__ALLOCTEMP(comp_ctx)); - duk__emit_bc(comp_ctx, - (DUK_TVAL_GET_BOOLEAN(tv) ? DUK_OP_LDTRUE : DUK_OP_LDFALSE), - dest); + duk__emit_bc(comp_ctx, (DUK_TVAL_GET_BOOLEAN(tv) ? DUK_OP_LDTRUE : DUK_OP_LDFALSE), dest); return dest; } case DUK_TAG_POINTER: { @@ -2104,7 +2173,7 @@ DUK_UNREF(h); DUK_ASSERT(h != NULL); -#if 0 /* XXX: to be implemented? */ +#if 0 /* XXX: to be implemented? */ /* Use special opcodes to load short strings */ if (DUK_HSTRING_GET_BYTELEN(h) <= 2) { /* Encode into a single opcode (18 bits can encode 1-2 bytes + length indicator) */ @@ -2174,8 +2243,8 @@ return dest; } } - } /* end switch */ - goto fail_internal; /* never here */ + } /* end switch */ + goto fail_internal; /* never here */ } case DUK_ISPEC_REGCONST: { if (forced_reg >= 0) { @@ -2208,11 +2277,11 @@ return x->regconst; } default: { - break; /* never here */ + break; /* never here */ } } - fail_internal: +fail_internal: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); } @@ -2232,10 +2301,13 @@ DUK_DDD(DUK_DDDPRINT("duk__ivalue_toplain_raw(): x={t=%ld,op=%ld,x1={%ld:%ld:%!T},x2={%ld:%ld:%!T}}, " "forced_reg=%ld", - (long) x->t, (long) x->op, - (long) x->x1.t, (long) x->x1.regconst, + (long) x->t, + (long) x->op, + (long) x->x1.t, + (long) x->x1.regconst, (duk_tval *) duk_get_tval(thr, x->x1.valstack_idx), - (long) x->x2.t, (long) x->x2.regconst, + (long) x->x2.t, + (long) x->x2.regconst, (duk_tval *) duk_get_tval(thr, x->x2.valstack_idx), (long) forced_reg)); @@ -2261,9 +2333,7 @@ DUK_ASSERT(tv1 != NULL); DUK_ASSERT(tv2 != NULL); - DUK_DDD(DUK_DDDPRINT("arith: tv1=%!T, tv2=%!T", - (duk_tval *) tv1, - (duk_tval *) tv2)); + DUK_DDD(DUK_DDDPRINT("arith: tv1=%!T, tv2=%!T", (duk_tval *) tv1, (duk_tval *) tv2)); if (DUK_TVAL_IS_NUMBER(tv1) && DUK_TVAL_IS_NUMBER(tv2)) { duk_double_t d1 = DUK_TVAL_GET_NUMBER(tv1); @@ -2272,7 +2342,9 @@ duk_bool_t accept_fold = 1; DUK_DDD(DUK_DDDPRINT("arith inline check: d1=%lf, d2=%lf, op=%ld", - (double) d1, (double) d2, (long) x->op)); + (double) d1, + (double) d2, + (long) x->op)); switch (x->op) { case DUK_OP_ADD: { d3 = d1 + d2; @@ -2298,7 +2370,7 @@ break; } default: { - d3 = 0.0; /* Won't be used, but silence MSVC /W4 warning. */ + d3 = 0.0; /* Won't be used, but silence MSVC /W4 warning. */ accept_fold = 0; break; } @@ -2312,7 +2384,7 @@ x->t = DUK_IVAL_PLAIN; DUK_ASSERT(x->x1.t == DUK_ISPEC_VALUE); - DUK_TVAL_SET_NUMBER(tv1, d3); /* old value is number: no refcount */ + DUK_TVAL_SET_NUMBER(tv1, d3); /* old value is number: no refcount */ return; } } else if (x->op == DUK_OP_ADD && DUK_TVAL_IS_STRING(tv1) && DUK_TVAL_IS_STRING(tv2)) { @@ -2329,8 +2401,14 @@ } } - arg1 = duk__ispec_toregconst_raw(comp_ctx, &x->x1, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); - arg2 = duk__ispec_toregconst_raw(comp_ctx, &x->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg1 = duk__ispec_toregconst_raw(comp_ctx, + &x->x1, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg2 = duk__ispec_toregconst_raw(comp_ctx, + &x->x2, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); /* If forced reg, use it as destination. Otherwise try to * use either coerced ispec if it is a temporary. @@ -2358,8 +2436,14 @@ duk_regconst_t dest; /* Need a short reg/const, does not have to be a mutable temp. */ - arg1 = duk__ispec_toregconst_raw(comp_ctx, &x->x1, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); - arg2 = duk__ispec_toregconst_raw(comp_ctx, &x->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg1 = duk__ispec_toregconst_raw(comp_ctx, + &x->x1, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg2 = duk__ispec_toregconst_raw(comp_ctx, + &x->x2, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); /* Pick a destination register. If either base value or key * happens to be a temp value, reuse it as the destination. @@ -2380,11 +2464,7 @@ dest = DUK__ALLOCTEMP(comp_ctx); } - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, - dest, - arg1, - arg2); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, dest, arg1, arg2); duk__ivalue_regconst(x, dest); return; @@ -2452,10 +2532,13 @@ DUK_DDD(DUK_DDDPRINT("duk__ivalue_toregconst_raw(): x={t=%ld,op=%ld,x1={%ld:%ld:%!T},x2={%ld:%ld:%!T}}, " "forced_reg=%ld, flags 0x%08lx: allow_const=%ld require_temp=%ld require_short=%ld", - (long) x->t, (long) x->op, - (long) x->x1.t, (long) x->x1.regconst, + (long) x->t, + (long) x->op, + (long) x->x1.t, + (long) x->x1.regconst, (duk_tval *) duk_get_tval(thr, x->x1.valstack_idx), - (long) x->x2.t, (long) x->x2.regconst, + (long) x->x2.t, + (long) x->x2.regconst, (duk_tval *) duk_get_tval(thr, x->x2.valstack_idx), (long) forced_reg, (unsigned long) flags, @@ -2478,7 +2561,7 @@ return duk__ivalue_toregconst_raw(comp_ctx, x, -1, 0 /*flags*/); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__ivalue_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *x) { return duk__ivalue_toregconst_raw(comp_ctx, x, -1, DUK__IVAL_FLAG_REQUIRE_TEMP /*flags*/); } @@ -2514,8 +2597,7 @@ duk_hstring *h_varname; duk_regconst_t ret; - DUK_DDD(DUK_DDDPRINT("resolving identifier reference to '%!T'", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("resolving identifier reference to '%!T'", (duk_tval *) duk_get_tval(thr, -1))); /* * Special name handling @@ -2568,13 +2650,13 @@ DUK_DDD(DUK_DDDPRINT("identifier lookup -> reg %ld", (long) ret)); return ret; - slow_path_notown: +slow_path_notown: DUK_DDD(DUK_DDDPRINT("identifier lookup -> slow path, not own variable")); comp_ctx->curr_func.id_access_slow = 1; return (duk_regconst_t) -1; - slow_path_own: +slow_path_own: DUK_DDD(DUK_DDDPRINT("identifier lookup -> slow path, may be own variable")); comp_ctx->curr_func.id_access_slow = 1; @@ -2602,7 +2684,7 @@ if (reg_varbind >= 0) { *out_reg_varbind = reg_varbind; - *out_rc_varname = 0; /* duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller) */ + *out_rc_varname = 0; /* duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller) */ duk_pop(thr); return 1; } else { @@ -2652,7 +2734,7 @@ } duk_push_hstring(thr, h_label); - DUK_ASSERT(n <= DUK_UARRIDX_MAX); /* label limits */ + DUK_ASSERT(n <= DUK_UARRIDX_MAX); /* label limits */ (void) duk_put_prop_index(thr, comp_ctx->curr_func.labelnames_idx, (duk_uarridx_t) n); new_size = (n + 1) * sizeof(duk_labelinfo); @@ -2662,7 +2744,7 @@ /* relookup after possible realloc */ p = (duk_uint8_t *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, comp_ctx->curr_func.h_labelinfos); li_start = (duk_labelinfo *) (void *) p; - DUK_UNREF(li_start); /* silence scan-build warning */ + DUK_UNREF(li_start); /* silence scan-build warning */ li = (duk_labelinfo *) (void *) (p + DUK_HBUFFER_GET_SIZE(comp_ctx->curr_func.h_labelinfos)); li--; @@ -2676,12 +2758,15 @@ li->flags = DUK_LABEL_FLAG_ALLOW_BREAK; li->label_id = label_id; li->h_label = h_label; - li->catch_depth = comp_ctx->curr_func.catch_depth; /* catch depth from current func */ + li->catch_depth = comp_ctx->curr_func.catch_depth; /* catch depth from current func */ li->pc_label = pc_label; DUK_DDD(DUK_DDDPRINT("registered label: flags=0x%08lx, id=%ld, name=%!O, catch_depth=%ld, pc_label=%ld", - (unsigned long) li->flags, (long) li->label_id, (duk_heaphdr *) li->h_label, - (long) li->catch_depth, (long) li->pc_label)); + (unsigned long) li->flags, + (long) li->label_id, + (duk_heaphdr *) li->h_label, + (long) li->catch_depth, + (long) li->pc_label)); } /* Update all labels with matching label_id. */ @@ -2705,7 +2790,9 @@ } DUK_DDD(DUK_DDDPRINT("updating (overwriting) label flags for li=%p, label_id=%ld, flags=%ld", - (void *) li, (long) label_id, (long) flags)); + (void *) li, + (long) label_id, + (long) flags)); li->flags = flags; } @@ -2726,14 +2813,19 @@ */ /* XXX: awkward, especially the bunch of separate output values -> output struct? */ -DUK_LOCAL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_bool_t is_break, duk_int_t *out_label_id, duk_int_t *out_label_catch_depth, duk_int_t *out_label_pc, duk_bool_t *out_is_closest) { +DUK_LOCAL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, + duk_hstring *h_label, + duk_bool_t is_break, + duk_int_t *out_label_id, + duk_int_t *out_label_catch_depth, + duk_int_t *out_label_pc, + duk_bool_t *out_is_closest) { duk_hthread *thr = comp_ctx->thr; duk_uint8_t *p; duk_labelinfo *li_start, *li_end, *li; duk_bool_t match = 0; - DUK_DDD(DUK_DDDPRINT("looking up active label: label='%!O', is_break=%ld", - (duk_heaphdr *) h_label, (long) is_break)); + DUK_DDD(DUK_DDDPRINT("looking up active label: label='%!O', is_break=%ld", (duk_heaphdr *) h_label, (long) is_break)); DUK_UNREF(thr); @@ -2757,7 +2849,8 @@ } DUK_DDD(DUK_DDDPRINT("labelinfo%ld -> '%!O' label name matches (still need to check type)", - (long) (li - li_start), (duk_heaphdr *) h_label)); + (long) (li - li_start), + (duk_heaphdr *) h_label)); /* currently all labels accept a break, so no explicit check for it now */ DUK_ASSERT(li->flags & DUK_LABEL_FLAG_ALLOW_BREAK); @@ -2791,8 +2884,10 @@ } DUK_DDD(DUK_DDDPRINT("label match: %!O -> label_id %ld, catch_depth=%ld, pc_label=%ld", - (duk_heaphdr *) h_label, (long) li->label_id, - (long) li->catch_depth, (long) li->pc_label)); + (duk_heaphdr *) h_label, + (long) li->label_id, + (long) li->catch_depth, + (long) li->pc_label)); *out_label_id = li->label_id; *out_label_catch_depth = li->catch_depth; @@ -2816,21 +2911,21 @@ */ /* object literal key tracking flags */ -#define DUK__OBJ_LIT_KEY_PLAIN (1 << 0) /* key encountered as a plain property */ -#define DUK__OBJ_LIT_KEY_GET (1 << 1) /* key encountered as a getter */ -#define DUK__OBJ_LIT_KEY_SET (1 << 2) /* key encountered as a setter */ +#define DUK__OBJ_LIT_KEY_PLAIN (1 << 0) /* key encountered as a plain property */ +#define DUK__OBJ_LIT_KEY_GET (1 << 1) /* key encountered as a getter */ +#define DUK__OBJ_LIT_KEY_SET (1 << 2) /* key encountered as a setter */ DUK_LOCAL void duk__nud_array_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; - duk_regconst_t reg_obj; /* result reg */ - duk_regconst_t reg_temp; /* temp reg */ - duk_regconst_t temp_start; /* temp reg value for start of loop */ - duk_small_uint_t max_init_values; /* max # of values initialized in one MPUTARR set */ - duk_small_uint_t num_values; /* number of values in current MPUTARR set */ - duk_uarridx_t curr_idx; /* current (next) array index */ - duk_uarridx_t start_idx; /* start array index of current MPUTARR set */ - duk_uarridx_t init_idx; /* last array index explicitly initialized, +1 */ - duk_bool_t require_comma; /* next loop requires a comma */ + duk_regconst_t reg_obj; /* result reg */ + duk_regconst_t reg_temp; /* temp reg */ + duk_regconst_t temp_start; /* temp reg value for start of loop */ + duk_small_uint_t max_init_values; /* max # of values initialized in one MPUTARR set */ + duk_small_uint_t num_values; /* number of values in current MPUTARR set */ + duk_uarridx_t curr_idx; /* current (next) array index */ + duk_uarridx_t start_idx; /* start array index of current MPUTARR set */ + duk_uarridx_t init_idx; /* last array index explicitly initialized, +1 */ + duk_bool_t require_comma; /* next loop requires a comma */ #if !defined(DUK_USE_PREFER_SIZE) duk_int_t pc_newarr; duk_compiler_instr *instr; @@ -2839,13 +2934,13 @@ /* DUK_TOK_LBRACKET already eaten, current token is right after that */ DUK_ASSERT(comp_ctx->prev_token.t == DUK_TOK_LBRACKET); - max_init_values = DUK__MAX_ARRAY_INIT_VALUES; /* XXX: depend on available temps? */ + max_init_values = DUK__MAX_ARRAY_INIT_VALUES; /* XXX: depend on available temps? */ reg_obj = DUK__ALLOCTEMP(comp_ctx); #if !defined(DUK_USE_PREFER_SIZE) pc_newarr = duk__get_current_pc(comp_ctx); #endif - duk__emit_bc(comp_ctx, DUK_OP_NEWARR, reg_obj); /* XXX: patch initial size hint afterwards? */ + duk__emit_bc(comp_ctx, DUK_OP_NEWARR, reg_obj); /* XXX: patch initial size hint afterwards? */ temp_start = DUK__GETTEMP(comp_ctx); /* @@ -2861,7 +2956,7 @@ */ curr_idx = 0; - init_idx = 0; /* tracks maximum initialized index + 1 */ + init_idx = 0; /* tracks maximum initialized index + 1 */ start_idx = 0; require_comma = 0; @@ -2907,7 +3002,7 @@ duk__emit_load_int32(comp_ctx, reg_temp, (duk_int32_t) start_idx); } - reg_temp = DUK__ALLOCTEMP(comp_ctx); /* alloc temp just in case, to update max temp */ + reg_temp = DUK__ALLOCTEMP(comp_ctx); /* alloc temp just in case, to update max temp */ DUK__SETTEMP(comp_ctx, reg_temp); duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); DUK__SETTEMP(comp_ctx, reg_temp + 1); @@ -2932,9 +3027,7 @@ * never needs to be. */ duk__emit_a_b_c(comp_ctx, - DUK_OP_MPUTARR | - DUK__EMIT_FLAG_NO_SHUFFLE_C | - DUK__EMIT_FLAG_A_IS_SOURCE, + DUK_OP_MPUTARR | DUK__EMIT_FLAG_NO_SHUFFLE_C | DUK__EMIT_FLAG_A_IS_SOURCE, reg_obj, temp_start, (duk_regconst_t) (num_values + 1)); @@ -2955,8 +3048,7 @@ DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RBRACKET); duk__advance(comp_ctx); - DUK_DDD(DUK_DDDPRINT("array literal done, curridx=%ld, initidx=%ld", - (long) curr_idx, (long) init_idx)); + DUK_DDD(DUK_DDDPRINT("array literal done, curridx=%ld, initidx=%ld", (long) curr_idx, (long) init_idx)); /* trailing elisions? */ if (curr_idx > init_idx) { @@ -2964,10 +3056,7 @@ DUK_DDD(DUK_DDDPRINT("array literal has trailing elisions which affect its length")); reg_temp = DUK__ALLOCTEMP(comp_ctx); duk__emit_load_int32(comp_ctx, reg_temp, (duk_int_t) curr_idx); - duk__emit_a_bc(comp_ctx, - DUK_OP_SETALEN | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_obj, - reg_temp); + duk__emit_a_bc(comp_ctx, DUK_OP_SETALEN | DUK__EMIT_FLAG_A_IS_SOURCE, reg_obj, reg_temp); } DUK__SETTEMP(comp_ctx, temp_start); @@ -2975,7 +3064,7 @@ duk__ivalue_regconst(res, reg_obj); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_ARRAY_LITERAL); DUK_WO_NORETURN(return;); } @@ -2999,9 +3088,7 @@ */ DUK_ASSERT(st->num_pairs > 0); duk__emit_a_b_c(comp_ctx, - DUK_OP_MPUTOBJ | - DUK__EMIT_FLAG_NO_SHUFFLE_C | - DUK__EMIT_FLAG_A_IS_SOURCE, + DUK_OP_MPUTOBJ | DUK__EMIT_FLAG_NO_SHUFFLE_C | DUK__EMIT_FLAG_A_IS_SOURCE, st->reg_obj, st->temp_start, (duk_regconst_t) (st->num_pairs * 2)); @@ -3020,7 +3107,7 @@ /* numbers can be loaded as numbers and coerced on the fly */ duk_push_number(comp_ctx->thr, tok->num); } else { - return 1; /* error */ + return 1; /* error */ } duk__ivalue_plain_fromstack(comp_ctx, res); @@ -3033,10 +3120,10 @@ DUK_LOCAL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; duk__objlit_state st; - duk_regconst_t reg_temp; /* temp reg */ - duk_small_uint_t max_init_pairs; /* max # of key-value pairs initialized in one MPUTOBJ set */ - duk_bool_t first; /* first value: comma must not precede the value */ - duk_bool_t is_set, is_get; /* temps */ + duk_regconst_t reg_temp; /* temp reg */ + duk_small_uint_t max_init_pairs; /* max # of key-value pairs initialized in one MPUTOBJ set */ + duk_bool_t first; /* first value: comma must not precede the value */ + duk_bool_t is_set, is_get; /* temps */ #if !defined(DUK_USE_PREFER_SIZE) duk_int_t pc_newobj; duk_compiler_instr *instr; @@ -3044,12 +3131,12 @@ DUK_ASSERT(comp_ctx->prev_token.t == DUK_TOK_LCURLY); - max_init_pairs = DUK__MAX_OBJECT_INIT_PAIRS; /* XXX: depend on available temps? */ + max_init_pairs = DUK__MAX_OBJECT_INIT_PAIRS; /* XXX: depend on available temps? */ - st.reg_obj = DUK__ALLOCTEMP(comp_ctx); /* target object */ - st.temp_start = DUK__GETTEMP(comp_ctx); /* start of MPUTOBJ argument list */ - st.num_pairs = 0; /* number of key/value pairs emitted for current MPUTOBJ set */ - st.num_total_pairs = 0; /* number of key/value pairs emitted overall */ + st.reg_obj = DUK__ALLOCTEMP(comp_ctx); /* target object */ + st.temp_start = DUK__GETTEMP(comp_ctx); /* start of MPUTOBJ argument list */ + st.num_pairs = 0; /* number of key/value pairs emitted for current MPUTOBJ set */ + st.num_total_pairs = 0; /* number of key/value pairs emitted overall */ #if !defined(DUK_USE_PREFER_SIZE) pc_newobj = duk__get_current_pc(comp_ctx); @@ -3088,8 +3175,7 @@ * worth the effort and would increase code size. */ - DUK_DDD(DUK_DDDPRINT("object literal loop, curr_token->t = %ld", - (long) comp_ctx->curr_token.t)); + DUK_DDD(DUK_DDDPRINT("object literal loop, curr_token->t = %ld", (long) comp_ctx->curr_token.t)); if (comp_ctx->curr_token.t == DUK_TOK_RCURLY) { break; @@ -3129,16 +3215,15 @@ * identifier string content. */ - is_get = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_GET(thr)); - is_set = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_SET(thr)); + is_get = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_GET(thr)); + is_set = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_SET(thr)); if ((is_get || is_set) && comp_ctx->curr_token.t != DUK_TOK_COLON) { /* getter/setter */ duk_int_t fnum; duk__objlit_flush_keys(comp_ctx, &st); - DUK_ASSERT(DUK__GETTEMP(comp_ctx) == st.temp_start); /* 2 regs are guaranteed to be allocated w.r.t. temp_max */ + DUK_ASSERT(DUK__GETTEMP(comp_ctx) == + st.temp_start); /* 2 regs are guaranteed to be allocated w.r.t. temp_max */ reg_temp = DUK__ALLOCTEMPS(comp_ctx, 2); if (duk__objlit_load_key(comp_ctx, res, &comp_ctx->curr_token, reg_temp) != 0) { @@ -3148,21 +3233,18 @@ /* curr_token = get/set name */ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_GETSET); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - st.temp_start + 1, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, st.temp_start + 1, (duk_regconst_t) fnum); /* Slot C is used in a non-standard fashion (range of regs), * emitter code has special handling for it (must not set the * "no shuffle" flag). */ duk__emit_a_bc(comp_ctx, - (is_get ? DUK_OP_INITGET : DUK_OP_INITSET) | DUK__EMIT_FLAG_A_IS_SOURCE, - st.reg_obj, - st.temp_start); /* temp_start+0 = key, temp_start+1 = closure */ + (is_get ? DUK_OP_INITGET : DUK_OP_INITSET) | DUK__EMIT_FLAG_A_IS_SOURCE, + st.reg_obj, + st.temp_start); /* temp_start+0 = key, temp_start+1 = closure */ - DUK_ASSERT(st.num_pairs == 0); /* temp state is reset on next loop */ + DUK_ASSERT(st.num_pairs == 0); /* temp state is reset on next loop */ #if defined(DUK_USE_ES6) } else if (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && (comp_ctx->curr_token.t == DUK_TOK_COMMA || comp_ctx->curr_token.t == DUK_TOK_RCURLY)) { @@ -3170,15 +3252,14 @@ load_rc = duk__objlit_load_key(comp_ctx, res, &comp_ctx->prev_token, reg_temp); DUK_UNREF(load_rc); - DUK_ASSERT(load_rc == 0); /* always succeeds because token is identifier */ + DUK_ASSERT(load_rc == 0); /* always succeeds because token is identifier */ duk__ivalue_var_hstring(comp_ctx, res, comp_ctx->prev_token.str1); DUK_ASSERT(DUK__GETTEMP(comp_ctx) == reg_temp + 1); duk__ivalue_toforcedreg(comp_ctx, res, reg_temp + 1); st.num_pairs++; - } else if ((comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER || - comp_ctx->prev_token.t == DUK_TOK_STRING || + } else if ((comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER || comp_ctx->prev_token.t == DUK_TOK_STRING || comp_ctx->prev_token.t == DUK_TOK_NUMBER) && comp_ctx->curr_token.t == DUK_TOK_LPAREN) { duk_int_t fnum; @@ -3196,13 +3277,10 @@ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_USE_PREVTOKEN | DUK__FUNC_FLAG_METDEF); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp + 1, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp + 1, (duk_regconst_t) fnum); st.num_pairs++; -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ } else { #if defined(DUK_USE_ES6) if (comp_ctx->prev_token.t == DUK_TOK_LBRACKET) { @@ -3219,9 +3297,8 @@ * form is not yet supported and causes a * SyntaxError on the DUK_TOK_COLON check below. */ - } - else -#endif /* DUK_USE_ES6 */ + } else +#endif /* DUK_USE_ES6 */ { if (duk__objlit_load_key(comp_ctx, res, &comp_ctx->prev_token, reg_temp) != 0) { goto syntax_error; @@ -3235,7 +3312,7 @@ st.num_pairs++; } - } /* property loop */ + } /* property loop */ /* Flush remaining properties. */ duk__objlit_flush_keys(comp_ctx, &st); @@ -3254,12 +3331,12 @@ #endif DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RCURLY); - duk__advance(comp_ctx); /* No RegExp after object literal. */ + duk__advance(comp_ctx); /* No RegExp after object literal. */ duk__ivalue_regconst(res, st.reg_obj); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_OBJECT_LITERAL); DUK_WO_NORETURN(return;); } @@ -3275,7 +3352,8 @@ /* Note: expect that caller has already eaten the left paren */ DUK_DDD(DUK_DDDPRINT("start parsing arguments, prev_token.t=%ld, curr_token.t=%ld", - (long) comp_ctx->prev_token.t, (long) comp_ctx->curr_token.t)); + (long) comp_ctx->prev_token.t, + (long) comp_ctx->curr_token.t)); for (;;) { if (comp_ctx->curr_token.t == DUK_TOK_RPAREN) { @@ -3292,11 +3370,14 @@ * This is not the cleanest possible approach. */ - reg_temp = DUK__ALLOCTEMP(comp_ctx); /* bump up "allocated" reg count, just in case */ + reg_temp = DUK__ALLOCTEMP(comp_ctx); /* bump up "allocated" reg count, just in case */ DUK__SETTEMP(comp_ctx, reg_temp); /* binding power must be high enough to NOT allow comma expressions directly */ - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp); /* always allow 'in', coerce to 'tr' just in case */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp); /* always allow 'in', coerce to 'tr' just in case */ DUK__SETTEMP(comp_ctx, reg_temp + 1); nargs++; @@ -3305,7 +3386,7 @@ } /* eat the right paren */ - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ DUK_DDD(DUK_DDDPRINT("end parsing arguments")); @@ -3314,8 +3395,7 @@ DUK_LOCAL duk_bool_t duk__expr_is_empty(duk_compiler_ctx *comp_ctx) { /* empty expressions can be detected conveniently with nud/led counts */ - return (comp_ctx->curr_func.nud_count == 0) && - (comp_ctx->curr_func.led_count == 0); + return (comp_ctx->curr_func.nud_count == 0) && (comp_ctx->curr_func.led_count == 0); } DUK_LOCAL void duk__expr_nud(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { @@ -3323,7 +3403,7 @@ duk_token *tk; duk_regconst_t temp_at_entry; duk_small_uint_t tok; - duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ + duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ /* * ctx->prev_token token to process with duk__expr_nud() @@ -3341,18 +3421,17 @@ res->t = DUK_IVAL_NONE; DUK_DDD(DUK_DDDPRINT("duk__expr_nud(), prev_token.t=%ld, allow_in=%ld, paren_level=%ld", - (long) tk->t, (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); + (long) tk->t, + (long) comp_ctx->curr_func.allow_in, + (long) comp_ctx->curr_func.paren_level)); switch (tok) { - - /* PRIMARY EXPRESSIONS */ + /* PRIMARY EXPRESSIONS */ case DUK_TOK_THIS: { duk_regconst_t reg_temp; reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_bc(comp_ctx, - DUK_OP_LDTHIS, - reg_temp); + duk__emit_bc(comp_ctx, DUK_OP_LDTHIS, reg_temp); duk__ivalue_regconst(res, reg_temp); return; } @@ -3384,15 +3463,13 @@ case DUK_TOK_REGEXP: { #if defined(DUK_USE_REGEXP_SUPPORT) duk_regconst_t reg_temp; - duk_regconst_t rc_re_bytecode; /* const */ - duk_regconst_t rc_re_source; /* const */ + duk_regconst_t rc_re_bytecode; /* const */ + duk_regconst_t rc_re_source; /* const */ DUK_ASSERT(tk->str1 != NULL); DUK_ASSERT(tk->str2 != NULL); - DUK_DDD(DUK_DDDPRINT("emitting regexp op, str1=%!O, str2=%!O", - (duk_heaphdr *) tk->str1, - (duk_heaphdr *) tk->str2)); + DUK_DDD(DUK_DDDPRINT("emitting regexp op, str1=%!O, str2=%!O", (duk_heaphdr *) tk->str1, (duk_heaphdr *) tk->str2)); reg_temp = DUK__ALLOCTEMP(comp_ctx); duk_push_hstring(thr, tk->str1); @@ -3415,9 +3492,9 @@ duk__ivalue_regconst(res, reg_temp); return; -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ goto syntax_error; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } case DUK_TOK_LBRACKET: { DUK_DDD(DUK_DDDPRINT("parsing array literal")); @@ -3436,15 +3513,15 @@ prev_allow_in = comp_ctx->curr_func.allow_in; comp_ctx->curr_func.allow_in = 1; /* reset 'allow_in' for parenthesized expression */ - duk__expr(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, terminates at a ')' */ + duk__expr(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, terminates at a ')' */ - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* No RegExp after parenthesized expression. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* No RegExp after parenthesized expression. */ comp_ctx->curr_func.allow_in = prev_allow_in; comp_ctx->curr_func.paren_level--; return; } - /* MEMBER/NEW/CALL EXPRESSIONS */ + /* MEMBER/NEW/CALL EXPRESSIONS */ case DUK_TOK_NEW: { /* @@ -3481,16 +3558,14 @@ goto syntax_error_newtarget; } duk__advance(comp_ctx); - duk__emit_bc(comp_ctx, - DUK_OP_NEWTARGET, - reg_target); + duk__emit_bc(comp_ctx, DUK_OP_NEWTARGET, reg_target); duk__ivalue_regconst(res, reg_target); return; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ duk__expr_toforcedreg(comp_ctx, res, DUK__BP_CALL /*rbp_flags*/, reg_target /*forced_reg*/); - duk__emit_bc(comp_ctx, DUK_OP_NEWOBJ, reg_target + 1); /* default instance */ + duk__emit_bc(comp_ctx, DUK_OP_NEWOBJ, reg_target + 1); /* default instance */ DUK__SETTEMP(comp_ctx, reg_target + 2); /* XXX: 'new obj.noSuch()' doesn't use GETPROPC now which @@ -3501,7 +3576,7 @@ /* 'new' MemberExpression Arguments */ DUK_DDD(DUK_DDDPRINT("new expression has argument list")); duk__advance(comp_ctx); - nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp", reg_target + 1 */ + nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp", reg_target + 1 */ /* right paren eaten */ } else { /* 'new' MemberExpression */ @@ -3509,10 +3584,7 @@ nargs = 0; } - duk__emit_a_bc(comp_ctx, - DUK_OP_CALL0 | DUK_BC_CALL_FLAG_CONSTRUCT, - nargs /*num_args*/, - reg_target /*target*/); + duk__emit_a_bc(comp_ctx, DUK_OP_CALL0 | DUK_BC_CALL_FLAG_CONSTRUCT, nargs /*num_args*/, reg_target /*target*/); DUK_DDD(DUK_DDDPRINT("end parsing new expression")); @@ -3520,7 +3592,7 @@ return; } - /* FUNCTION EXPRESSIONS */ + /* FUNCTION EXPRESSIONS */ case DUK_TOK_FUNCTION: { /* Function expression. Note that any statement beginning with 'function' @@ -3543,16 +3615,13 @@ fnum = duk__parse_func_like_fnum(comp_ctx, 0 /*flags*/); DUK_DDD(DUK_DDDPRINT("parsed inner function -> fnum %ld", (long) fnum)); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp /*a*/, - (duk_regconst_t) fnum /*bc*/); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp /*a*/, (duk_regconst_t) fnum /*bc*/); duk__ivalue_regconst(res, reg_temp); return; } - /* UNARY EXPRESSIONS */ + /* UNARY EXPRESSIONS */ case DUK_TOK_DELETE: { /* Delete semantics are a bit tricky. The description in E5 specification @@ -3560,7 +3629,7 @@ * a reference (which is only known at runtime) seemingly at compile time * (= SyntaxError throwing). */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_VAR) { /* not allowed in strict mode, regardless of whether resolves; * in non-strict mode DELVAR handles both non-resolving and @@ -3582,16 +3651,11 @@ duk_dup(thr, res->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { /* register bound variables are non-configurable -> always false */ - duk__emit_bc(comp_ctx, - DUK_OP_LDFALSE, - reg_temp); + duk__emit_bc(comp_ctx, DUK_OP_LDFALSE, reg_temp); } else { duk_dup(thr, res->x1.valstack_idx); rc_varname = duk__getconst(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_DELVAR, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_DELVAR, reg_temp, rc_varname); } duk__ivalue_regconst(res, reg_temp); } else if (res->t == DUK_IVAL_PROP) { @@ -3601,13 +3665,11 @@ DUK__SETTEMP(comp_ctx, temp_at_entry); reg_temp = DUK__ALLOCTEMP(comp_ctx); - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - DUK_OP_DELPROP | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - reg_obj, - rc_key); + reg_obj = + duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = + duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, DUK_OP_DELPROP | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, reg_obj, rc_key); duk__ivalue_regconst(res, reg_temp); } else { @@ -3618,7 +3680,7 @@ return; } case DUK_TOK_VOID: { - duk__expr_toplain_ignore(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr_toplain_ignore(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ duk_push_undefined(thr); goto plain_value; } @@ -3628,7 +3690,7 @@ * will never be unresolvable so special handling is only required * when an identifier is a "slow path" one. */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_VAR) { duk_regconst_t reg_varbind; @@ -3640,10 +3702,7 @@ DUK_DDD(DUK_DDDPRINT("typeof for an identifier name which could not be resolved " "at compile time, need to use special run-time handling")); reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_TYPEOFID, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_TYPEOFID, reg_temp, rc_varname); duk__ivalue_regconst(res, reg_temp); return; } @@ -3662,9 +3721,8 @@ } case DUK_TOK_ADD: { /* unary plus */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && - duk_is_number(thr, res->x1.valstack_idx)) { + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && duk_is_number(thr, res->x1.valstack_idx)) { /* unary plus of a number is identity */ return; } @@ -3673,9 +3731,8 @@ } case DUK_TOK_SUB: { /* unary minus */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && - duk_is_number(thr, res->x1.valstack_idx)) { + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && duk_is_number(thr, res->x1.valstack_idx)) { /* this optimization is important to handle negative literals * (which are not directly provided by the lexical grammar) */ @@ -3695,12 +3752,12 @@ goto unary; } case DUK_TOK_BNOT: { - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ args = DUK_OP_BNOT; goto unary; } case DUK_TOK_LNOT: { - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE) { /* Very minimal inlining to handle common idioms '!0' and '!1', * and also boolean arguments like '!false' and '!true'. @@ -3735,117 +3792,110 @@ goto unary; } - } /* end switch */ + } /* end switch */ DUK_ERROR_SYNTAX(thr, DUK_STR_PARSE_ERROR); DUK_WO_NORETURN(return;); - unary: - { - /* Unary opcodes use just the 'BC' register source because it - * matches current shuffle limits, and maps cleanly to 16 high - * bits of the opcode. - */ - - duk_regconst_t reg_src, reg_res; - - reg_src = duk__ivalue_toregconst_raw(comp_ctx, res, -1 /*forced_reg*/, 0 /*flags*/); - if (DUK__ISREG_TEMP(comp_ctx, reg_src)) { - reg_res = reg_src; - } else { - reg_res = DUK__ALLOCTEMP(comp_ctx); - } - duk__emit_a_bc(comp_ctx, - args, - reg_res, - reg_src); - duk__ivalue_regconst(res, reg_res); - return; - } +unary : { + /* Unary opcodes use just the 'BC' register source because it + * matches current shuffle limits, and maps cleanly to 16 high + * bits of the opcode. + */ - preincdec: - { - /* preincrement and predecrement */ - duk_regconst_t reg_res; - duk_small_uint_t args_op1 = args & 0xff; /* DUK_OP_PREINCR/DUK_OP_PREDECR */ - duk_small_uint_t args_op2 = args >> 8; /* DUK_OP_PREINCP_RR/DUK_OP_PREDECP_RR */ - - /* Specific assumptions for opcode numbering. */ - DUK_ASSERT(DUK_OP_PREINCR + 4 == DUK_OP_PREINCV); - DUK_ASSERT(DUK_OP_PREDECR + 4 == DUK_OP_PREDECV); + duk_regconst_t reg_src, reg_res; + reg_src = duk__ivalue_toregconst_raw(comp_ctx, res, -1 /*forced_reg*/, 0 /*flags*/); + if (DUK__ISREG_TEMP(comp_ctx, reg_src)) { + reg_res = reg_src; + } else { reg_res = DUK__ALLOCTEMP(comp_ctx); + } + duk__emit_a_bc(comp_ctx, args, reg_res, reg_src); + duk__ivalue_regconst(res, reg_res); + return; +} - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_VAR) { - duk_hstring *h_varname; - duk_regconst_t reg_varbind; - duk_regconst_t rc_varname; - - h_varname = duk_known_hstring(thr, res->x1.valstack_idx); +preincdec : { + /* preincrement and predecrement */ + duk_regconst_t reg_res; + duk_small_uint_t args_op1 = args & 0xff; /* DUK_OP_PREINCR/DUK_OP_PREDECR */ + duk_small_uint_t args_op2 = args >> 8; /* DUK_OP_PREINCP_RR/DUK_OP_PREDECP_RR */ + + /* Specific assumptions for opcode numbering. */ + DUK_ASSERT(DUK_OP_PREINCR + 4 == DUK_OP_PREINCV); + DUK_ASSERT(DUK_OP_PREDECR + 4 == DUK_OP_PREDECV); + + reg_res = DUK__ALLOCTEMP(comp_ctx); + + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_VAR) { + duk_hstring *h_varname; + duk_regconst_t reg_varbind; + duk_regconst_t rc_varname; - if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { - goto syntax_error; - } + h_varname = duk_known_hstring(thr, res->x1.valstack_idx); - duk_dup(thr, res->x1.valstack_idx); - if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - args_op1, /* e.g. DUK_OP_PREINCR */ - reg_res, - reg_varbind); - } else { - duk__emit_a_bc(comp_ctx, - args_op1 + 4, /* e.g. DUK_OP_PREINCV */ - reg_res, - rc_varname); - } + if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { + goto syntax_error; + } - DUK_DDD(DUK_DDDPRINT("preincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); - } else if (res->t == DUK_IVAL_PROP) { - duk_regconst_t reg_obj; /* allocate to reg only (not const) */ - duk_regconst_t rc_key; - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_PREINCP */ - reg_res, - reg_obj, - rc_key); + duk_dup(thr, res->x1.valstack_idx); + if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { + duk__emit_a_bc(comp_ctx, + args_op1, /* e.g. DUK_OP_PREINCR */ + reg_res, + reg_varbind); } else { - /* Technically return value is not needed because INVLHS will - * unconditially throw a ReferenceError. Coercion is necessary - * for proper semantics (consider ToNumber() called for an object). - * Use DUK_OP_UNP with a dummy register to get ToNumber(). - */ - - duk__ivalue_toforcedreg(comp_ctx, res, reg_res); - duk__emit_bc(comp_ctx, - DUK_OP_UNP, - reg_res); /* for side effects, result ignored */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__emit_a_bc(comp_ctx, + args_op1 + 4, /* e.g. DUK_OP_PREINCV */ + reg_res, + rc_varname); } - DUK__SETTEMP(comp_ctx, reg_res + 1); - duk__ivalue_regconst(res, reg_res); - return; - } - plain_value: - { - /* Stack top contains plain value */ - duk__ivalue_plain_fromstack(comp_ctx, res); - return; + DUK_DDD(DUK_DDDPRINT("preincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); + } else if (res->t == DUK_IVAL_PROP) { + duk_regconst_t reg_obj; /* allocate to reg only (not const) */ + duk_regconst_t rc_key; + reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, + args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_PREINCP */ + reg_res, + reg_obj, + rc_key); + } else { + /* Technically return value is not needed because INVLHS will + * unconditially throw a ReferenceError. Coercion is necessary + * for proper semantics (consider ToNumber() called for an object). + * Use DUK_OP_UNP with a dummy register to get ToNumber(). + */ + + duk__ivalue_toforcedreg(comp_ctx, res, reg_res); + duk__emit_bc(comp_ctx, DUK_OP_UNP, reg_res); /* for side effects, result ignored */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } + DUK__SETTEMP(comp_ctx, reg_res + 1); + duk__ivalue_regconst(res, reg_res); + return; +} + +plain_value : { + /* Stack top contains plain value */ + duk__ivalue_plain_fromstack(comp_ctx, res); + return; +} #if defined(DUK_USE_ES6) - syntax_error_newtarget: +syntax_error_newtarget: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_NEWTARGET); DUK_WO_NORETURN(return;); #endif - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_EXPRESSION); DUK_WO_NORETURN(return;); } @@ -3858,7 +3908,7 @@ duk_hthread *thr = comp_ctx->thr; duk_token *tk; duk_small_uint_t tok; - duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ + duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ /* * ctx->prev_token token to process with duk__expr_led() @@ -3872,13 +3922,14 @@ tok = tk->t; DUK_DDD(DUK_DDDPRINT("duk__expr_led(), prev_token.t=%ld, allow_in=%ld, paren_level=%ld", - (long) tk->t, (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); + (long) tk->t, + (long) comp_ctx->curr_func.allow_in, + (long) comp_ctx->curr_func.paren_level)); /* XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here? */ switch (tok) { - - /* PRIMARY EXPRESSIONS */ + /* PRIMARY EXPRESSIONS */ case DUK_TOK_PERIOD: { /* Property access expressions are critical for correct LHS ordering, @@ -3906,7 +3957,7 @@ } res->t = DUK_IVAL_PROP; - duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ + duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); duk_push_hstring(thr, comp_ctx->curr_token.str1); duk_replace(thr, res->x2.valstack_idx); @@ -3941,12 +3992,12 @@ * See: test-bug-nested-prop-mutate.js. */ duk__ivalue_totempconst(comp_ctx, left); - duk__expr_toplain(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, '' terminates */ + duk__expr_toplain(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, '' terminates */ duk__advance_expect(comp_ctx, DUK_TOK_RBRACKET); res->t = DUK_IVAL_PROP; - duk__copy_ispec(comp_ctx, &res->x1, &res->x2); /* res.x1 -> res.x2 */ - duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ + duk__copy_ispec(comp_ctx, &res->x1, &res->x2); /* res.x1 -> res.x2 */ + duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ return; } case DUK_TOK_LPAREN: { @@ -3990,19 +4041,13 @@ duk_dup(thr, left->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - DUK_OP_CSREG | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_varbind, - reg_cs + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_CSREG | DUK__EMIT_FLAG_A_IS_SOURCE, reg_varbind, reg_cs + 0); } else { /* XXX: expand target register or constant field to * reduce shuffling. */ DUK_ASSERT(DUK__ISCONST(rc_varname)); - duk__emit_a_b(comp_ctx, - DUK_OP_CSVAR | DUK__EMIT_FLAG_BC_REGCONST, - reg_cs + 0, - rc_varname); + duk__emit_a_b(comp_ctx, DUK_OP_CSVAR | DUK__EMIT_FLAG_BC_REGCONST, reg_cs + 0, rc_varname); } } else if (left->t == DUK_IVAL_PROP) { /* Call through a property lookup, E5 Section 11.2.3, step 6.a.i, @@ -4024,16 +4069,12 @@ * and reuse, but it would still be in the wrong position * (reg_cs + 0 rather than reg_cs + 1). */ - duk__ispec_toforcedreg(comp_ctx, &left->x1, reg_cs + 1); /* base */ + duk__ispec_toforcedreg(comp_ctx, &left->x1, reg_cs + 1); /* base */ #if defined(DUK_USE_VERBOSE_ERRORS) reg_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROPC | DUK__EMIT_FLAG_BC_REGCONST, - reg_cs + 0, - reg_cs + 1, - reg_key); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROPC | DUK__EMIT_FLAG_BC_REGCONST, reg_cs + 0, reg_cs + 1, reg_key); #else - duk__ivalue_toforcedreg(comp_ctx, left, reg_cs + 0); /* basekey */ + duk__ivalue_toforcedreg(comp_ctx, left, reg_cs + 0); /* basekey */ #endif } else { DUK_DDD(DUK_DDDPRINT("function call with register base")); @@ -4052,23 +4093,20 @@ } DUK__SETTEMP(comp_ctx, reg_cs + 2); - nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp" */ + nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp" */ /* Tailcalls are handled by back-patching the already emitted opcode * later in return statement parser. */ - duk__emit_a_bc(comp_ctx, - call_op, - (duk_regconst_t) nargs /*numargs*/, - reg_cs /*basereg*/); - DUK__SETTEMP(comp_ctx, reg_cs + 1); /* result in csreg */ + duk__emit_a_bc(comp_ctx, call_op, (duk_regconst_t) nargs /*numargs*/, reg_cs /*basereg*/); + DUK__SETTEMP(comp_ctx, reg_cs + 1); /* result in csreg */ duk__ivalue_regconst(res, reg_cs); return; } - /* POSTFIX EXPRESSION */ + /* POSTFIX EXPRESSION */ case DUK_TOK_INCREMENT: { args = (DUK_OP_POSTINCP_RR << 16) + (DUK_OP_POSTINCR << 8) + 0; @@ -4083,38 +4121,38 @@ #if defined(DUK_USE_ES7_EXP_OPERATOR) case DUK_TOK_EXP: { - args = (DUK_OP_EXP << 8) + DUK__BP_EXPONENTIATION - 1; /* UnaryExpression */ + args = (DUK_OP_EXP << 8) + DUK__BP_EXPONENTIATION - 1; /* UnaryExpression */ goto binary; } #endif - /* MULTIPLICATIVE EXPRESSION */ + /* MULTIPLICATIVE EXPRESSION */ case DUK_TOK_MUL: { - args = (DUK_OP_MUL << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_MUL << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } case DUK_TOK_DIV: { - args = (DUK_OP_DIV << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_DIV << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } case DUK_TOK_MOD: { - args = (DUK_OP_MOD << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_MOD << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } - /* ADDITIVE EXPRESSION */ + /* ADDITIVE EXPRESSION */ case DUK_TOK_ADD: { - args = (DUK_OP_ADD << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ + args = (DUK_OP_ADD << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ goto binary; } case DUK_TOK_SUB: { - args = (DUK_OP_SUB << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ + args = (DUK_OP_SUB << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ goto binary; } - /* SHIFT EXPRESSION */ + /* SHIFT EXPRESSION */ case DUK_TOK_ALSHIFT: { /* << */ @@ -4132,7 +4170,7 @@ goto binary; } - /* RELATIONAL EXPRESSION */ + /* RELATIONAL EXPRESSION */ case DUK_TOK_LT: { /* < */ @@ -4160,7 +4198,7 @@ goto binary; } - /* EQUALITY EXPRESSION */ + /* EQUALITY EXPRESSION */ case DUK_TOK_EQ: { args = (DUK_OP_EQ << 8) + DUK__BP_EQUALITY; @@ -4179,7 +4217,7 @@ goto binary; } - /* BITWISE EXPRESSIONS */ + /* BITWISE EXPRESSIONS */ case DUK_TOK_BAND: { args = (DUK_OP_BAND << 8) + DUK__BP_BAND; @@ -4194,7 +4232,7 @@ goto binary; } - /* LOGICAL EXPRESSIONS */ + /* LOGICAL EXPRESSIONS */ case DUK_TOK_LAND: { /* syntactically left-associative but parsed as right-associative */ @@ -4207,7 +4245,7 @@ goto binary_logical; } - /* CONDITIONAL EXPRESSION */ + /* CONDITIONAL EXPRESSION */ case DUK_TOK_QUESTION: { /* XXX: common reg allocation need is to reuse a sub-expression's temp reg, @@ -4220,12 +4258,18 @@ reg_temp = DUK__ALLOCTEMP(comp_ctx); duk__ivalue_toforcedreg(comp_ctx, left, reg_temp); duk__emit_if_true_skip(comp_ctx, reg_temp); - pc_jump1 = duk__emit_jump_empty(comp_ctx); /* jump to false */ - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); /* AssignmentExpression */ + pc_jump1 = duk__emit_jump_empty(comp_ctx); /* jump to false */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp /*forced_reg*/); /* AssignmentExpression */ duk__advance_expect(comp_ctx, DUK_TOK_COLON); - pc_jump2 = duk__emit_jump_empty(comp_ctx); /* jump to end */ + pc_jump2 = duk__emit_jump_empty(comp_ctx); /* jump to end */ duk__patch_jump_here(comp_ctx, pc_jump1); - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); /* AssignmentExpression */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp /*forced_reg*/); /* AssignmentExpression */ duk__patch_jump_here(comp_ctx, pc_jump2); DUK__SETTEMP(comp_ctx, reg_temp + 1); @@ -4233,7 +4277,7 @@ return; } - /* ASSIGNMENT EXPRESSION */ + /* ASSIGNMENT EXPRESSION */ case DUK_TOK_EQUALSIGN: { /* @@ -4247,7 +4291,7 @@ * * XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)? */ - args = (DUK_OP_NONE << 8) + DUK__BP_ASSIGNMENT - 1; /* DUK_OP_NONE marks a 'plain' assignment */ + args = (DUK_OP_NONE << 8) + DUK__BP_ASSIGNMENT - 1; /* DUK_OP_NONE marks a 'plain' assignment */ goto assign; } case DUK_TOK_ADD_EQ: { @@ -4313,12 +4357,12 @@ goto assign; } - /* COMMA */ + /* COMMA */ case DUK_TOK_COMMA: { /* right associative */ - duk__ivalue_toplain_ignore(comp_ctx, left); /* need side effects, not value */ + duk__ivalue_toplain_ignore(comp_ctx, left); /* need side effects, not value */ duk__expr_toplain(comp_ctx, res, DUK__BP_COMMA - 1 /*rbp_flags*/); /* return 'res' (of right part) as our result */ @@ -4341,7 +4385,7 @@ } #endif - binary: +binary: /* * Shared handling of binary operations * @@ -4367,11 +4411,15 @@ duk_copy(thr, left->x1.valstack_idx, res->x1.valstack_idx); DUK_DDD(DUK_DDDPRINT("binary op, res: t=%ld, x1.t=%ld, x1.regconst=0x%08lx, x2.t=%ld, x2.regconst=0x%08lx", - (long) res->t, (long) res->x1.t, (unsigned long) res->x1.regconst, (long) res->x2.t, (unsigned long) res->x2.regconst)); + (long) res->t, + (long) res->x1.t, + (unsigned long) res->x1.regconst, + (long) res->x2.t, + (unsigned long) res->x2.regconst)); return; } - binary_logical: +binary_logical: /* * Shared handling for logical AND and logical OR. * @@ -4404,8 +4452,8 @@ duk__ivalue_toforcedreg(comp_ctx, left, reg_temp); DUK_ASSERT(DUK__ISREG(reg_temp)); duk__emit_bc(comp_ctx, - (args_truthval ? DUK_OP_IFTRUE_R : DUK_OP_IFFALSE_R), - reg_temp); /* skip jump conditionally */ + (args_truthval ? DUK_OP_IFTRUE_R : DUK_OP_IFFALSE_R), + reg_temp); /* skip jump conditionally */ pc_jump = duk__emit_jump_empty(comp_ctx); duk__expr_toforcedreg(comp_ctx, res, args_rbp /*rbp_flags*/, reg_temp /*forced_reg*/); duk__patch_jump_here(comp_ctx, pc_jump); @@ -4414,7 +4462,7 @@ return; } - assign: +assign: /* * Shared assignment expression handling * @@ -4467,7 +4515,7 @@ * is relevant for e.g. eval code. */ toplevel_assign = (comp_ctx->curr_func.nud_count == 1 && /* one token before */ - comp_ctx->curr_func.led_count == 1); /* one operator (= assign) */ + comp_ctx->curr_func.led_count == 1); /* one operator (= assign) */ DUK_DDD(DUK_DDDPRINT("assignment: nud_count=%ld, led_count=%ld, toplevel_assign=%ld", (long) comp_ctx->curr_func.nud_count, (long) comp_ctx->curr_func.led_count, @@ -4478,7 +4526,7 @@ duk_regconst_t reg_varbind; duk_regconst_t rc_varname; - DUK_ASSERT(left->x1.t == DUK_ISPEC_VALUE); /* LHS is already side effect free */ + DUK_ASSERT(left->x1.t == DUK_ISPEC_VALUE); /* LHS is already side effect free */ h_varname = duk_known_hstring(thr, left->x1.valstack_idx); if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { @@ -4495,9 +4543,10 @@ DUK_DDD(DUK_DDDPRINT("plain assignment, toplevel assign, use as is")); } else { /* 'res' must be a plain ivalue, and not register-bound variable. */ - DUK_DDD(DUK_DDDPRINT("plain assignment, not toplevel assign, ensure not a reg-bound identifier")); - if (res->t != DUK_IVAL_PLAIN || (res->x1.t == DUK_ISPEC_REGCONST && - DUK__ISREG_NOTTEMP(comp_ctx, res->x1.regconst))) { + DUK_DDD(DUK_DDDPRINT( + "plain assignment, not toplevel assign, ensure not a reg-bound identifier")); + if (res->t != DUK_IVAL_PLAIN || + (res->x1.t == DUK_ISPEC_REGCONST && DUK__ISREG_NOTTEMP(comp_ctx, res->x1.regconst))) { duk__ivalue_totempconst(comp_ctx, res); } } @@ -4530,7 +4579,7 @@ * value, so go through a temp. */ DUK_DD(DUK_DDPRINT("<op>= expression is not top level, write to reg_temp")); - reg_res = reg_temp; /* reg_res should be smallest possible */ + reg_res = reg_temp; /* reg_res should be smallest possible */ reg_temp = DUK__ALLOCTEMP(comp_ctx); } @@ -4542,10 +4591,7 @@ */ pc_temp_load = duk__get_current_pc(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_temp, - reg_varbind); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_temp, reg_varbind); pc_before_rhs = duk__get_current_pc(comp_ctx); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); @@ -4553,7 +4599,8 @@ pc_after_rhs = duk__get_current_pc(comp_ctx); DUK_DD(DUK_DDPRINT("pc_temp_load=%ld, pc_before_rhs=%ld, pc_after_rhs=%ld", - (long) pc_temp_load, (long) pc_before_rhs, + (long) pc_temp_load, + (long) pc_before_rhs, (long) pc_after_rhs)); if (pc_after_rhs == pc_before_rhs) { @@ -4561,11 +4608,16 @@ * instructions, we may need to rewind more than * one instruction, so use explicit PC computation. */ - DUK_DD(DUK_DDPRINT("rhs is side effect free, rewind and avoid unnecessary temp for reg-based <op>=")); - DUK_BW_ADD_PTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, (pc_temp_load - pc_before_rhs) * (duk_int_t) sizeof(duk_compiler_instr)); + DUK_DD(DUK_DDPRINT("rhs is side effect free, rewind and avoid unnecessary temp for " + "reg-based <op>=")); + DUK_BW_ADD_PTR(comp_ctx->thr, + &comp_ctx->curr_func.bw_code, + (pc_temp_load - pc_before_rhs) * + (duk_int_t) sizeof(duk_compiler_instr)); reg_src = reg_varbind; } else { - DUK_DD(DUK_DDPRINT("rhs evaluation emitted code, not sure if rhs is side effect free; use temp reg for LHS")); + DUK_DD(DUK_DDPRINT("rhs evaluation emitted code, not sure if rhs is side effect " + "free; use temp reg for LHS")); reg_src = reg_temp; } @@ -4586,10 +4638,7 @@ * temporary. No optimization for top level assignment. */ - duk__emit_a_bc(comp_ctx, - DUK_OP_GETVAR, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_GETVAR, reg_temp, rc_varname); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); DUK_ASSERT(res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_REGCONST); @@ -4622,7 +4671,7 @@ duk__ivalue_toforcedreg(comp_ctx, res, (duk_int_t) reg_varbind); } else { duk__ivalue_totempconst(comp_ctx, res); - duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ + duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ duk__ivalue_toforcedreg(comp_ctx, left, (duk_int_t) reg_varbind); } } else { @@ -4630,7 +4679,7 @@ * free and may be a plain value, a register, or a * constant) and write it to the LHS binding too. */ - duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ + duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ duk__ivalue_toforcedreg(comp_ctx, left, (duk_int_t) reg_varbind); } } else { @@ -4643,10 +4692,7 @@ */ duk__ivalue_toreg(comp_ctx, res); - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - res->x1.regconst, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, res->x1.regconst, rc_varname); } /* 'res' contains expression value */ @@ -4686,11 +4732,7 @@ rc_res = res->x1.regconst; } else { reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - reg_obj, - rc_key); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, reg_obj, rc_key); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); DUK_ASSERT(res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_REGCONST); @@ -4741,90 +4783,88 @@ return; } - postincdec: - { - /* - * Post-increment/decrement will return the original value as its - * result value. However, even that value will be coerced using - * ToNumber() which is quite awkward. Specific bytecode opcodes - * are used to handle these semantics. - * - * Note that post increment/decrement has a "no LineTerminator here" - * restriction. This is handled by duk__expr_lbp(), which forcibly terminates - * the previous expression if a LineTerminator occurs before '++'/'--'. - */ - - duk_regconst_t reg_res; - duk_small_uint_t args_op1 = (args >> 8) & 0xff; /* DUK_OP_POSTINCR/DUK_OP_POSTDECR */ - duk_small_uint_t args_op2 = args >> 16; /* DUK_OP_POSTINCP_RR/DUK_OP_POSTDECP_RR */ - - /* Specific assumptions for opcode numbering. */ - DUK_ASSERT(DUK_OP_POSTINCR + 4 == DUK_OP_POSTINCV); - DUK_ASSERT(DUK_OP_POSTDECR + 4 == DUK_OP_POSTDECV); +postincdec : { + /* + * Post-increment/decrement will return the original value as its + * result value. However, even that value will be coerced using + * ToNumber() which is quite awkward. Specific bytecode opcodes + * are used to handle these semantics. + * + * Note that post increment/decrement has a "no LineTerminator here" + * restriction. This is handled by duk__expr_lbp(), which forcibly terminates + * the previous expression if a LineTerminator occurs before '++'/'--'. + */ - reg_res = DUK__ALLOCTEMP(comp_ctx); + duk_regconst_t reg_res; + duk_small_uint_t args_op1 = (args >> 8) & 0xff; /* DUK_OP_POSTINCR/DUK_OP_POSTDECR */ + duk_small_uint_t args_op2 = args >> 16; /* DUK_OP_POSTINCP_RR/DUK_OP_POSTDECP_RR */ - if (left->t == DUK_IVAL_VAR) { - duk_hstring *h_varname; - duk_regconst_t reg_varbind; - duk_regconst_t rc_varname; + /* Specific assumptions for opcode numbering. */ + DUK_ASSERT(DUK_OP_POSTINCR + 4 == DUK_OP_POSTINCV); + DUK_ASSERT(DUK_OP_POSTDECR + 4 == DUK_OP_POSTDECV); - h_varname = duk_known_hstring(thr, left->x1.valstack_idx); + reg_res = DUK__ALLOCTEMP(comp_ctx); - if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { - goto syntax_error; - } + if (left->t == DUK_IVAL_VAR) { + duk_hstring *h_varname; + duk_regconst_t reg_varbind; + duk_regconst_t rc_varname; - duk_dup(thr, left->x1.valstack_idx); - if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - args_op1, /* e.g. DUK_OP_POSTINCR */ - reg_res, - reg_varbind); - } else { - duk__emit_a_bc(comp_ctx, - args_op1 + 4, /* e.g. DUK_OP_POSTINCV */ - reg_res, - rc_varname); - } + h_varname = duk_known_hstring(thr, left->x1.valstack_idx); - DUK_DDD(DUK_DDDPRINT("postincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); - } else if (left->t == DUK_IVAL_PROP) { - duk_regconst_t reg_obj; /* allocate to reg only (not const) */ - duk_regconst_t rc_key; + if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { + goto syntax_error; + } - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &left->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_POSTINCP */ - reg_res, - reg_obj, - rc_key); + duk_dup(thr, left->x1.valstack_idx); + if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { + duk__emit_a_bc(comp_ctx, + args_op1, /* e.g. DUK_OP_POSTINCR */ + reg_res, + reg_varbind); } else { - /* Technically return value is not needed because INVLHS will - * unconditially throw a ReferenceError. Coercion is necessary - * for proper semantics (consider ToNumber() called for an object). - * Use DUK_OP_UNP with a dummy register to get ToNumber(). - */ - duk__ivalue_toforcedreg(comp_ctx, left, reg_res); - duk__emit_bc(comp_ctx, - DUK_OP_UNP, - reg_res); /* for side effects, result ignored */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__emit_a_bc(comp_ctx, + args_op1 + 4, /* e.g. DUK_OP_POSTINCV */ + reg_res, + rc_varname); } - DUK__SETTEMP(comp_ctx, reg_res + 1); - duk__ivalue_regconst(res, reg_res); - return; + DUK_DDD(DUK_DDDPRINT("postincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); + } else if (left->t == DUK_IVAL_PROP) { + duk_regconst_t reg_obj; /* allocate to reg only (not const) */ + duk_regconst_t rc_key; + + reg_obj = duk__ispec_toregconst_raw(comp_ctx, &left->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, + args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_POSTINCP */ + reg_res, + reg_obj, + rc_key); + } else { + /* Technically return value is not needed because INVLHS will + * unconditially throw a ReferenceError. Coercion is necessary + * for proper semantics (consider ToNumber() called for an object). + * Use DUK_OP_UNP with a dummy register to get ToNumber(). + */ + duk__ivalue_toforcedreg(comp_ctx, left, reg_res); + duk__emit_bc(comp_ctx, DUK_OP_UNP, reg_res); /* for side effects, result ignored */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } - syntax_error: + DUK__SETTEMP(comp_ctx, reg_res + 1); + duk__ivalue_regconst(res, reg_res); + return; +} + +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_EXPRESSION); DUK_WO_NORETURN(return;); - syntax_error_lvalue: +syntax_error_lvalue: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_LVALUE); DUK_WO_NORETURN(return;); } @@ -4832,7 +4872,7 @@ DUK_LOCAL duk_small_uint_t duk__expr_lbp(duk_compiler_ctx *comp_ctx) { duk_small_uint_t tok = comp_ctx->curr_token.t; - DUK_ASSERT_DISABLE(tok >= DUK_TOK_MINVAL); /* unsigned */ + DUK_ASSERT_DISABLE(tok >= DUK_TOK_MINVAL); /* unsigned */ DUK_ASSERT(tok <= DUK_TOK_MAXVAL); DUK_ASSERT(sizeof(duk__token_lbp) == DUK_TOK_MAXVAL + 1); @@ -4845,8 +4885,7 @@ return 0; } - if ((tok == DUK_TOK_DECREMENT || tok == DUK_TOK_INCREMENT) && - (comp_ctx->curr_token.lineterm)) { + if ((tok == DUK_TOK_DECREMENT || tok == DUK_TOK_INCREMENT) && (comp_ctx->curr_token.lineterm)) { /* '++' or '--' in a post-increment/decrement position, * and a LineTerminator occurs between the operator and * the preceding expression. Force the previous expr @@ -4856,7 +4895,7 @@ return 0; } - return DUK__TOKEN_LBP_GET_BP(duk__token_lbptok); /* format is bit packed */ + return DUK__TOKEN_LBP_GET_BP(duk__token_lbptok); /* format is bit packed */ } /* @@ -4868,15 +4907,15 @@ * statement). */ -#define DUK__EXPR_RBP_MASK 0xff -#define DUK__EXPR_FLAG_REJECT_IN (1 << 8) /* reject 'in' token (used for for-in) */ -#define DUK__EXPR_FLAG_ALLOW_EMPTY (1 << 9) /* allow empty expression */ -#define DUK__EXPR_FLAG_REQUIRE_INIT (1 << 10) /* require initializer for var/const */ +#define DUK__EXPR_RBP_MASK 0xff +#define DUK__EXPR_FLAG_REJECT_IN (1 << 8) /* reject 'in' token (used for for-in) */ +#define DUK__EXPR_FLAG_ALLOW_EMPTY (1 << 9) /* allow empty expression */ +#define DUK__EXPR_FLAG_REQUIRE_INIT (1 << 10) /* require initializer for var/const */ /* main expression parser function */ DUK_LOCAL void duk__expr(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk_hthread *thr = comp_ctx->thr; - duk_ivalue tmp_alloc; /* 'res' is used for "left", and 'tmp' for "right" */ + duk_ivalue tmp_alloc; /* 'res' is used for "left", and 'tmp' for "right" */ duk_ivalue *tmp = &tmp_alloc; duk_small_uint_t rbp; @@ -4888,7 +4927,9 @@ rbp = rbp_flags & DUK__EXPR_RBP_MASK; DUK_DDD(DUK_DDDPRINT("duk__expr(), rbp_flags=%ld, rbp=%ld, allow_in=%ld, paren_level=%ld", - (long) rbp_flags, (long) rbp, (long) comp_ctx->curr_func.allow_in, + (long) rbp_flags, + (long) rbp, + (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); duk_memzero(&tmp_alloc, sizeof(tmp_alloc)); @@ -4919,14 +4960,14 @@ } duk__advance(comp_ctx); - duk__expr_nud(comp_ctx, res); /* reuse 'res' as 'left' */ + duk__expr_nud(comp_ctx, res); /* reuse 'res' as 'left' */ while (rbp < duk__expr_lbp(comp_ctx)) { duk__advance(comp_ctx); duk__expr_led(comp_ctx, res, tmp); - duk__copy_ivalue(comp_ctx, tmp, res); /* tmp -> res */ + duk__copy_ivalue(comp_ctx, tmp, res); /* tmp -> res */ } - cleanup: +cleanup: /* final result is already in 'res' */ duk_pop_2(thr); @@ -4960,21 +5001,24 @@ * Each helper needs at least 2-3 calls to make it worth while to wrap. */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_toreg(comp_ctx, res); } #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_totemp(comp_ctx, res); } #endif -DUK_LOCAL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg) { +DUK_LOCAL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg) { DUK_ASSERT(forced_reg >= 0); duk__expr(comp_ctx, res, rbp_flags); duk__ivalue_toforcedreg(comp_ctx, res, forced_reg); @@ -4985,7 +5029,7 @@ return duk__ivalue_toregconst(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_totempconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_totempconst(comp_ctx, res); @@ -5007,14 +5051,17 @@ return duk__ivalue_toreg(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__exprtop_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__exprtop(comp_ctx, res, rbp_flags); return duk__ivalue_totemp(comp_ctx, res); } #endif -DUK_LOCAL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg) { +DUK_LOCAL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg) { DUK_ASSERT(forced_reg >= 0); duk__exprtop(comp_ctx, res, rbp_flags); duk__ivalue_toforcedreg(comp_ctx, res, forced_reg); @@ -5025,7 +5072,7 @@ return duk__ivalue_toregconst(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__exprtop_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, int rbp_flags) { duk__exprtop(comp_ctx, res, rbp_flags); duk__ivalue_toplain_ignore(comp_ctx, res); @@ -5044,11 +5091,11 @@ * the token after the terminator). */ -#define DUK__HAS_VAL (1 << 0) /* stmt has non-empty value */ -#define DUK__HAS_TERM (1 << 1) /* stmt has explicit/implicit semicolon terminator */ -#define DUK__ALLOW_AUTO_SEMI_ALWAYS (1 << 2) /* allow automatic semicolon even without lineterm (compatibility) */ -#define DUK__STILL_PROLOGUE (1 << 3) /* statement does not terminate directive prologue */ -#define DUK__IS_TERMINAL (1 << 4) /* statement is guaranteed to be terminal (control doesn't flow to next statement) */ +#define DUK__HAS_VAL (1 << 0) /* stmt has non-empty value */ +#define DUK__HAS_TERM (1 << 1) /* stmt has explicit/implicit semicolon terminator */ +#define DUK__ALLOW_AUTO_SEMI_ALWAYS (1 << 2) /* allow automatic semicolon even without lineterm (compatibility) */ +#define DUK__STILL_PROLOGUE (1 << 3) /* statement does not terminate directive prologue */ +#define DUK__IS_TERMINAL (1 << 4) /* statement is guaranteed to be terminal (control doesn't flow to next statement) */ /* Parse a single variable declaration (e.g. "i" or "i=10"). A leading 'var' * has already been eaten. These is no return value in 'res', it is used only @@ -5068,7 +5115,11 @@ * as is done in 'for-in' parsing. */ -DUK_LOCAL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags, duk_regconst_t *out_reg_varbind, duk_regconst_t *out_rc_varname) { +DUK_LOCAL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t expr_flags, + duk_regconst_t *out_reg_varbind, + duk_regconst_t *out_rc_varname) { duk_hthread *thr = comp_ctx->thr; duk_hstring *h_varname; duk_regconst_t reg_varbind; @@ -5092,8 +5143,7 @@ /* register declarations in first pass */ if (comp_ctx->curr_func.in_scanning) { duk_uarridx_t n; - DUK_DDD(DUK_DDDPRINT("register variable declaration %!O in pass 1", - (duk_heaphdr *) h_varname)); + DUK_DDD(DUK_DDDPRINT("register variable declaration %!O in pass 1", (duk_heaphdr *) h_varname)); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); duk_push_hstring(thr, h_varname); duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n); @@ -5101,31 +5151,30 @@ duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n + 1); } - duk_push_hstring(thr, h_varname); /* push before advancing to keep reachable */ + duk_push_hstring(thr, h_varname); /* push before advancing to keep reachable */ /* register binding lookup is based on varmap (even in first pass) */ duk_dup_top(thr); (void) duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname); - duk__advance(comp_ctx); /* eat identifier */ + duk__advance(comp_ctx); /* eat identifier */ if (comp_ctx->curr_token.t == DUK_TOK_EQUALSIGN) { duk__advance(comp_ctx); DUK_DDD(DUK_DDDPRINT("vardecl, assign to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); - duk__exprtop(comp_ctx, res, DUK__BP_COMMA | expr_flags /*rbp_flags*/); /* AssignmentExpression */ + duk__exprtop(comp_ctx, res, DUK__BP_COMMA | expr_flags /*rbp_flags*/); /* AssignmentExpression */ if (reg_varbind >= 0) { duk__ivalue_toforcedreg(comp_ctx, res, reg_varbind); } else { duk_regconst_t reg_val; reg_val = duk__ivalue_toreg(comp_ctx, res); - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_val, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, reg_val, rc_varname); } } else { if (expr_flags & DUK__EXPR_FLAG_REQUIRE_INIT) { @@ -5134,14 +5183,14 @@ } } - duk_pop(thr); /* pop varname */ + duk_pop(thr); /* pop varname */ *out_rc_varname = rc_varname; *out_reg_varbind = reg_varbind; return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_VAR_DECLARATION); DUK_WO_NORETURN(return;); } @@ -5150,7 +5199,7 @@ duk_regconst_t reg_varbind; duk_regconst_t rc_varname; - duk__advance(comp_ctx); /* eat 'var' */ + duk__advance(comp_ctx); /* eat 'var' */ for (;;) { /* rc_varname and reg_varbind are ignored here */ @@ -5165,9 +5214,9 @@ DUK_LOCAL void duk__parse_for_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site) { duk_hthread *thr = comp_ctx->thr; - duk_int_t pc_v34_lhs; /* start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example) */ - duk_regconst_t temp_reset; /* knock back "next temp" to this whenever possible */ - duk_regconst_t reg_temps; /* preallocated temporaries (2) for variants 3 and 4 */ + duk_int_t pc_v34_lhs; /* start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example) */ + duk_regconst_t temp_reset; /* knock back "next temp" to this whenever possible */ + duk_regconst_t reg_temps; /* preallocated temporaries (2) for variants 3 and 4 */ DUK_DDD(DUK_DDDPRINT("start parsing a for/for-in statement")); @@ -5196,7 +5245,7 @@ * issues, evaluation order issues, etc. */ - duk__advance(comp_ctx); /* eat 'for' */ + duk__advance(comp_ctx); /* eat 'for' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); DUK_DDD(DUK_DDDPRINT("detecting for/for-in loop variant, pc=%ld", (long) duk__get_current_pc(comp_ctx))); @@ -5210,10 +5259,10 @@ * Variant 2 or 4 */ - duk_regconst_t reg_varbind; /* variable binding register if register-bound (otherwise < 0) */ - duk_regconst_t rc_varname; /* variable name reg/const, if variable not register-bound */ + duk_regconst_t reg_varbind; /* variable binding register if register-bound (otherwise < 0) */ + duk_regconst_t rc_varname; /* variable name reg/const, if variable not register-bound */ - duk__advance(comp_ctx); /* eat 'var' */ + duk__advance(comp_ctx); /* eat 'var' */ duk__parse_var_decl(comp_ctx, res, DUK__EXPR_FLAG_REJECT_IN, ®_varbind, &rc_varname); DUK__SETTEMP(comp_ctx, temp_reset); @@ -5223,17 +5272,11 @@ */ DUK_DDD(DUK_DDDPRINT("detected for variant 4: for (var VariableDeclarationNoIn in Expression) Statement")); - pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here */ + pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here */ if (reg_varbind >= 0) { - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_varbind, - reg_temps + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_varbind, reg_temps + 0); } else { - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_temps + 0, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, reg_temps + 0, rc_varname); } goto parse_3_or_4; } else { @@ -5241,7 +5284,8 @@ * Variant 2 */ - DUK_DDD(DUK_DDDPRINT("detected for variant 2: for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement")); + DUK_DDD(DUK_DDDPRINT( + "detected for variant 2: for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement")); for (;;) { /* more initializers */ if (comp_ctx->curr_token.t != DUK_TOK_COMMA) { @@ -5249,7 +5293,7 @@ } DUK_DDD(DUK_DDDPRINT("variant 2 has another variable initializer")); - duk__advance(comp_ctx); /* eat comma */ + duk__advance(comp_ctx); /* eat comma */ duk__parse_var_decl(comp_ctx, res, DUK__EXPR_FLAG_REJECT_IN, ®_varbind, &rc_varname); } goto parse_1_or_2; @@ -5259,14 +5303,17 @@ * Variant 1 or 3 */ - pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here (variant 3) */ + pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here (variant 3) */ /* Note that duk__exprtop() here can clobber any reg above current temp_next, * so any loop variables (e.g. enumerator) must be "preallocated". */ /* don't coerce yet to a plain value (variant 3 needs special handling) */ - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_REJECT_IN | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression */ + duk__exprtop(comp_ctx, + res, + DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_REJECT_IN | + DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression */ if (comp_ctx->curr_token.t == DUK_TOK_IN) { /* * Variant 3 @@ -5275,7 +5322,7 @@ /* XXX: need to determine LHS type, and check that it is LHS compatible */ DUK_DDD(DUK_DDDPRINT("detected for variant 3: for (LeftHandSideExpression in Expression) Statement")); if (duk__expr_is_empty(comp_ctx)) { - goto syntax_error; /* LeftHandSideExpression does not allow empty expression */ + goto syntax_error; /* LeftHandSideExpression does not allow empty expression */ } if (res->t == DUK_IVAL_VAR) { @@ -5284,10 +5331,7 @@ duk_dup(thr, res->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_varbind, - reg_temps + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_varbind, reg_temps + 0); } else { duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, @@ -5300,17 +5344,22 @@ */ duk_regconst_t reg_obj; duk_regconst_t rc_key; - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + reg_obj = duk__ispec_toregconst_raw(comp_ctx, + &res->x1, + -1 /*forced_reg*/, + 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, + &res->x2, + -1 /*forced_reg*/, + DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); duk__emit_a_b_c(comp_ctx, DUK_OP_PUTPROP | DUK__EMIT_FLAG_A_IS_SOURCE | DUK__EMIT_FLAG_BC_REGCONST, reg_obj, rc_key, reg_temps + 0); } else { - duk__ivalue_toplain_ignore(comp_ctx, res); /* just in case */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__ivalue_toplain_ignore(comp_ctx, res); /* just in case */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } goto parse_3_or_4; } else { @@ -5318,13 +5367,14 @@ * Variant 1 */ - DUK_DDD(DUK_DDDPRINT("detected for variant 1: for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement")); + DUK_DDD(DUK_DDDPRINT( + "detected for variant 1: for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement")); duk__ivalue_toplain_ignore(comp_ctx, res); goto parse_1_or_2; } } - parse_1_or_2: +parse_1_or_2: /* * Parse variant 1 or 2. The first part expression (which differs * in the variants) has already been parsed and its code emitted. @@ -5347,23 +5397,23 @@ duk__advance_expect(comp_ctx, DUK_TOK_SEMICOLON); pc_l1 = duk__get_current_pc(comp_ctx); - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ + duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ if (duk__expr_is_empty(comp_ctx)) { /* no need to coerce */ - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ - pc_jumpto_l4 = -1; /* omitted */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ + pc_jumpto_l4 = -1; /* omitted */ } else { rc_cond = duk__ivalue_toregconst(comp_ctx, res); duk__emit_if_false_skip(comp_ctx, rc_cond); - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ - pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); /* to exit */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ + pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); /* to exit */ } DUK__SETTEMP(comp_ctx, temp_reset); duk__advance_expect(comp_ctx, DUK_TOK_SEMICOLON); pc_l2 = duk__get_current_pc(comp_ctx); - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ + duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ if (duk__expr_is_empty(comp_ctx)) { /* no need to coerce */ expr_c_empty = 1; @@ -5376,7 +5426,7 @@ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_l3 = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -5391,21 +5441,23 @@ DUK_DDD(DUK_DDDPRINT("patching jumps: jumpto_l3: %ld->%ld, jumpto_l4: %ld->%ld, " "break: %ld->%ld, continue: %ld->%ld", - (long) pc_jumpto_l3, (long) pc_l3, (long) pc_jumpto_l4, (long) pc_l4, - (long) (pc_label_site + 1), (long) pc_l4, (long) (pc_label_site + 2), (long) pc_l2)); + (long) pc_jumpto_l3, + (long) pc_l3, + (long) pc_jumpto_l4, + (long) pc_l4, + (long) (pc_label_site + 1), + (long) pc_l4, + (long) (pc_label_site + 2), + (long) pc_l2)); duk__patch_jump(comp_ctx, pc_jumpto_l3, pc_l3); duk__patch_jump(comp_ctx, pc_jumpto_l4, pc_l4); - duk__patch_jump(comp_ctx, - pc_label_site + 1, - pc_l4); /* break jump */ - duk__patch_jump(comp_ctx, - pc_label_site + 2, - expr_c_empty ? pc_l1 : pc_l2); /* continue jump */ + duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l4); /* break jump */ + duk__patch_jump(comp_ctx, pc_label_site + 2, expr_c_empty ? pc_l1 : pc_l2); /* continue jump */ } goto finished; - parse_3_or_4: +parse_3_or_4: /* * Parse variant 3 or 4. * @@ -5441,16 +5493,16 @@ */ duk__insert_jump_entry(comp_ctx, pc_v34_lhs); - pc_jumpto_l2 = pc_v34_lhs; /* inserted jump */ - pc_l1 = pc_v34_lhs + 1; /* +1, right after inserted jump */ + pc_jumpto_l2 = pc_v34_lhs; /* inserted jump */ + pc_l1 = pc_v34_lhs + 1; /* +1, right after inserted jump */ /* The code for writing reg_temps + 0 to the left hand side has already * been emitted. */ - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* -> loop body */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* -> loop body */ - duk__advance(comp_ctx); /* eat 'in' */ + duk__advance(comp_ctx); /* eat 'in' */ /* Parse enumeration target and initialize enumerator. For 'null' and 'undefined', * INITENUM will creates a 'null' enumerator which works like an empty enumerator @@ -5459,16 +5511,13 @@ */ pc_l2 = duk__get_current_pc(comp_ctx); - reg_target = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression */ - duk__emit_b_c(comp_ctx, - DUK_OP_INITENUM | DUK__EMIT_FLAG_B_IS_TARGET, - reg_temps + 1, - reg_target); + reg_target = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression */ + duk__emit_b_c(comp_ctx, DUK_OP_INITENUM | DUK__EMIT_FLAG_B_IS_TARGET, reg_temps + 1, reg_target); pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_l3 = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -5485,8 +5534,8 @@ DUK_OP_NEXTENUM | DUK__EMIT_FLAG_B_IS_TARGET | DUK__EMIT_FLAG_RESERVE_JUMPSLOT, reg_temps + 0, reg_temps + 1); - pc_jumpto_l5 = comp_ctx->emit_jumpslot_pc; /* NEXTENUM jump slot: executed when enum finished */ - duk__emit_jump(comp_ctx, pc_l1); /* jump to next loop, using reg_v34_iter as iterated value */ + pc_jumpto_l5 = comp_ctx->emit_jumpslot_pc; /* NEXTENUM jump slot: executed when enum finished */ + duk__emit_jump(comp_ctx, pc_l1); /* jump to next loop, using reg_v34_iter as iterated value */ pc_l5 = duk__get_current_pc(comp_ctx); @@ -5498,24 +5547,33 @@ DUK_DDD(DUK_DDDPRINT("patching jumps: jumpto_l2: %ld->%ld, jumpto_l3: %ld->%ld, " "jumpto_l4: %ld->%ld, jumpto_l5: %ld->%ld, " "break: %ld->%ld, continue: %ld->%ld", - (long) pc_jumpto_l2, (long) pc_l2, (long) pc_jumpto_l3, (long) pc_l3, - (long) pc_jumpto_l4, (long) pc_l4, (long) pc_jumpto_l5, (long) pc_l5, - (long) (pc_label_site + 1), (long) pc_l5, (long) (pc_label_site + 2), (long) pc_l4)); + (long) pc_jumpto_l2, + (long) pc_l2, + (long) pc_jumpto_l3, + (long) pc_l3, + (long) pc_jumpto_l4, + (long) pc_l4, + (long) pc_jumpto_l5, + (long) pc_l5, + (long) (pc_label_site + 1), + (long) pc_l5, + (long) (pc_label_site + 2), + (long) pc_l4)); duk__patch_jump(comp_ctx, pc_jumpto_l2, pc_l2); duk__patch_jump(comp_ctx, pc_jumpto_l3, pc_l3); duk__patch_jump(comp_ctx, pc_jumpto_l4, pc_l4); duk__patch_jump(comp_ctx, pc_jumpto_l5, pc_l5); - duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l5); /* break jump */ - duk__patch_jump(comp_ctx, pc_label_site + 2, pc_l4); /* continue jump */ + duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l5); /* break jump */ + duk__patch_jump(comp_ctx, pc_label_site + 2, pc_l4); /* continue jump */ } goto finished; - finished: +finished: DUK_DDD(DUK_DDDPRINT("end parsing a for/for-in statement")); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_FOR); DUK_WO_NORETURN(return;); } @@ -5523,12 +5581,12 @@ DUK_LOCAL void duk__parse_switch_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site) { duk_hthread *thr = comp_ctx->thr; duk_regconst_t temp_at_loop; - duk_regconst_t rc_switch; /* reg/const for switch value */ - duk_regconst_t rc_case; /* reg/const for case value */ - duk_regconst_t reg_temp; /* general temp register */ + duk_regconst_t rc_switch; /* reg/const for switch value */ + duk_regconst_t rc_case; /* reg/const for case value */ + duk_regconst_t reg_temp; /* general temp register */ duk_int_t pc_prevcase = -1; duk_int_t pc_prevstmt = -1; - duk_int_t pc_default = -1; /* -1 == not set, -2 == pending (next statement list) */ + duk_int_t pc_default = -1; /* -1 == not set, -2 == pending (next statement list) */ /* Note: negative pc values are ignored when patching jumps, so no explicit checks needed */ @@ -5559,7 +5617,7 @@ duk__advance(comp_ctx); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); rc_switch = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); DUK_DDD(DUK_DDDPRINT("switch value in register %ld", (long) rc_switch)); @@ -5589,24 +5647,20 @@ * because it may be a constant. */ - duk__patch_jump_here(comp_ctx, pc_prevcase); /* chain jumps for case - * evaluation and checking - */ + duk__patch_jump_here(comp_ctx, pc_prevcase); /* chain jumps for case + * evaluation and checking + */ duk__advance(comp_ctx); rc_case = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__advance_expect(comp_ctx, DUK_TOK_COLON); reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_b_c(comp_ctx, - DUK_OP_SEQ | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - rc_switch, - rc_case); + duk__emit_a_b_c(comp_ctx, DUK_OP_SEQ | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, rc_switch, rc_case); duk__emit_if_true_skip(comp_ctx, reg_temp); /* jump to next case clause */ - pc_prevcase = duk__emit_jump_empty(comp_ctx); /* no match, next case */ + pc_prevcase = duk__emit_jump_empty(comp_ctx); /* no match, next case */ /* statements go here (if any) on next loop */ } else if (comp_ctx->curr_token.t == DUK_TOK_DEFAULT) { @@ -5655,14 +5709,13 @@ * they participate in 'fall-through' behavior even if the * default clause is in the middle. */ - duk__patch_jump_here(comp_ctx, pc_prevstmt); /* chain jumps for 'fall-through' - * after a case matches. - */ + duk__patch_jump_here(comp_ctx, pc_prevstmt); /* chain jumps for 'fall-through' + * after a case matches. + */ for (;;) { tok = comp_ctx->curr_token.t; - if (tok == DUK_TOK_CASE || tok == DUK_TOK_DEFAULT || - tok == DUK_TOK_RCURLY) { + if (tok == DUK_TOK_CASE || tok == DUK_TOK_DEFAULT || tok == DUK_TOK_RCURLY) { break; } num_stmts++; @@ -5685,7 +5738,7 @@ DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RCURLY); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance(comp_ctx); /* Allow RegExp as part of next stmt. */ + duk__advance(comp_ctx); /* Allow RegExp as part of next stmt. */ /* default case control flow patchup; note that if pc_prevcase < 0 * (i.e. no case clauses), control enters default case automatically. @@ -5706,7 +5759,7 @@ duk__patch_jump_here(comp_ctx, pc_prevstmt); /* continue jump not patched, an INVALID opcode remains there */ - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ /* Note: 'fast' breaks will jump to pc_label_site + 1, which will * then jump here. The double jump will be eliminated by a @@ -5716,7 +5769,7 @@ return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_SWITCH); DUK_WO_NORETURN(return;); } @@ -5730,16 +5783,16 @@ temp_reset = DUK__GETTEMP(comp_ctx); - duk__advance(comp_ctx); /* eat 'if' */ + duk__advance(comp_ctx); /* eat 'if' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); rc_cond = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__emit_if_true_skip(comp_ctx, rc_cond); - pc_jump_false = duk__emit_jump_empty(comp_ctx); /* jump to end or else part */ + pc_jump_false = duk__emit_jump_empty(comp_ctx); /* jump to end or else part */ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -5754,7 +5807,7 @@ duk__advance(comp_ctx); - pc_jump_end = duk__emit_jump_empty(comp_ctx); /* jump from true part to end */ + pc_jump_end = duk__emit_jump_empty(comp_ctx); /* jump from true part to end */ duk__patch_jump_here(comp_ctx, pc_jump_false); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -5775,11 +5828,11 @@ DUK_DDD(DUK_DDDPRINT("begin parsing do statement")); - duk__advance(comp_ctx); /* Eat 'do'; allow RegExp as part of next stmt. */ + duk__advance(comp_ctx); /* Eat 'do'; allow RegExp as part of next stmt. */ pc_start = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); - duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ duk__advance_expect(comp_ctx, DUK_TOK_WHILE); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); @@ -5789,10 +5842,10 @@ duk__emit_jump(comp_ctx, pc_start); /* no need to reset temps, as we're finished emitting code */ - comp_ctx->curr_func.allow_regexp_in_adv = 1; /* Allow RegExp as part of next stmt. */ + comp_ctx->curr_func.allow_regexp_in_adv = 1; /* Allow RegExp as part of next stmt. */ duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ DUK_DDD(DUK_DDDPRINT("end parsing do statement")); } @@ -5807,12 +5860,12 @@ temp_reset = DUK__GETTEMP(comp_ctx); - duk__advance(comp_ctx); /* eat 'while' */ + duk__advance(comp_ctx); /* eat 'while' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); pc_start = duk__get_current_pc(comp_ctx); - duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ rc_cond = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__emit_if_true_skip(comp_ctx, rc_cond); @@ -5820,13 +5873,13 @@ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); duk__emit_jump(comp_ctx, pc_start); duk__patch_jump_here(comp_ctx, pc_jump_false); - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ DUK_DDD(DUK_DDDPRINT("end parsing while statement")); } @@ -5836,23 +5889,35 @@ duk_bool_t is_break = (comp_ctx->curr_token.t == DUK_TOK_BREAK); duk_int_t label_id; duk_int_t label_catch_depth; - duk_int_t label_pc; /* points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue */ + duk_int_t label_pc; /* points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue */ duk_bool_t label_is_closest; DUK_UNREF(res); - duk__advance(comp_ctx); /* eat 'break' or 'continue' */ + duk__advance(comp_ctx); /* eat 'break' or 'continue' */ - if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ - comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ - comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ + if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ + comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ + comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ /* break/continue without label */ - duk__lookup_active_label(comp_ctx, DUK_HTHREAD_STRING_EMPTY_STRING(thr), is_break, &label_id, &label_catch_depth, &label_pc, &label_is_closest); + duk__lookup_active_label(comp_ctx, + DUK_HTHREAD_STRING_EMPTY_STRING(thr), + is_break, + &label_id, + &label_catch_depth, + &label_pc, + &label_is_closest); } else if (comp_ctx->curr_token.t == DUK_TOK_IDENTIFIER) { /* break/continue with label (label cannot be a reserved word, production is 'Identifier' */ DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); - duk__lookup_active_label(comp_ctx, comp_ctx->curr_token.str1, is_break, &label_id, &label_catch_depth, &label_pc, &label_is_closest); + duk__lookup_active_label(comp_ctx, + comp_ctx->curr_token.str1, + is_break, + &label_id, + &label_catch_depth, + &label_pc, + &label_is_closest); duk__advance(comp_ctx); } else { DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_BREAK_CONT_LABEL); @@ -5865,25 +5930,28 @@ * The peephole optimizer will optimize the jump to a direct one. */ - if (label_catch_depth == comp_ctx->curr_func.catch_depth && - label_is_closest) { + if (label_catch_depth == comp_ctx->curr_func.catch_depth && label_is_closest) { DUK_DDD(DUK_DDDPRINT("break/continue: is_break=%ld, label_id=%ld, label_is_closest=%ld, " "label_catch_depth=%ld, catch_depth=%ld " "-> use fast variant (direct jump)", - (long) is_break, (long) label_id, (long) label_is_closest, - (long) label_catch_depth, (long) comp_ctx->curr_func.catch_depth)); + (long) is_break, + (long) label_id, + (long) label_is_closest, + (long) label_catch_depth, + (long) comp_ctx->curr_func.catch_depth)); duk__emit_jump(comp_ctx, label_pc + (is_break ? 1 : 2)); } else { DUK_DDD(DUK_DDDPRINT("break/continue: is_break=%ld, label_id=%ld, label_is_closest=%ld, " "label_catch_depth=%ld, catch_depth=%ld " "-> use slow variant (longjmp)", - (long) is_break, (long) label_id, (long) label_is_closest, - (long) label_catch_depth, (long) comp_ctx->curr_func.catch_depth)); + (long) is_break, + (long) label_id, + (long) label_is_closest, + (long) label_catch_depth, + (long) comp_ctx->curr_func.catch_depth)); - duk__emit_bc(comp_ctx, - is_break ? DUK_OP_BREAK : DUK_OP_CONTINUE, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, is_break ? DUK_OP_BREAK : DUK_OP_CONTINUE, (duk_regconst_t) label_id); } } @@ -5891,7 +5959,7 @@ duk_hthread *thr = comp_ctx->thr; duk_regconst_t rc_val; - duk__advance(comp_ctx); /* eat 'return' */ + duk__advance(comp_ctx); /* eat 'return' */ /* A 'return' statement is only allowed inside an actual function body, * not as part of eval or global code. @@ -5901,9 +5969,9 @@ DUK_WO_NORETURN(return;); } - if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ - comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ - comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ + if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ + comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ + comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ DUK_DDD(DUK_DDDPRINT("empty return value -> undefined")); duk__emit_op_only(comp_ctx, DUK_OP_RETUNDEF); } else { @@ -5955,8 +6023,8 @@ */ #if defined(DUK_USE_TAILCALL) - if (comp_ctx->curr_func.catch_depth == 0 && /* no catchers */ - pc_after_expr > pc_before_expr) { /* at least one opcode emitted */ + if (comp_ctx->curr_func.catch_depth == 0 && /* no catchers */ + pc_after_expr > pc_before_expr) { /* at least one opcode emitted */ duk_compiler_instr *instr; duk_instr_t ins; duk_small_uint_t op; @@ -5966,8 +6034,7 @@ ins = instr->ins; op = (duk_small_uint_t) DUK_DEC_OP(ins); - if ((op & ~0x0fU) == DUK_OP_CALL0 && - DUK__ISREG_TEMP(comp_ctx, rc_val) /* see above */) { + if ((op & ~0x0fU) == DUK_OP_CALL0 && DUK__ISREG_TEMP(comp_ctx, rc_val) /* see above */) { DUK_DDD(DUK_DDDPRINT("return statement detected a tail call opportunity: " "catch depth is 0, duk__exprtop() emitted >= 1 instructions, " "and last instruction is a CALL " @@ -5976,7 +6043,7 @@ instr->ins = ins; } } -#endif /* DUK_USE_TAILCALL */ +#endif /* DUK_USE_TAILCALL */ if (DUK__ISREG(rc_val)) { duk__emit_bc(comp_ctx, DUK_OP_RETREG, rc_val); @@ -5994,7 +6061,7 @@ DUK_LOCAL void duk__parse_throw_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_regconst_t reg_val; - duk__advance(comp_ctx); /* eat 'throw' */ + duk__advance(comp_ctx); /* eat 'throw' */ /* Unlike break/continue, throw statement does not allow an empty value. */ @@ -6004,14 +6071,12 @@ } reg_val = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - duk__emit_bc(comp_ctx, - DUK_OP_THROW, - reg_val); + duk__emit_bc(comp_ctx, DUK_OP_THROW, reg_val); } DUK_LOCAL void duk__parse_try_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; - duk_regconst_t reg_catch; /* reg_catch+0 and reg_catch+1 are reserved for TRYCATCH */ + duk_regconst_t reg_catch; /* reg_catch+0 and reg_catch+1 are reserved for TRYCATCH */ duk_regconst_t rc_varname = 0; duk_small_uint_t trycatch_flags = 0; duk_int_t pc_ldconst = -1; @@ -6038,7 +6103,7 @@ comp_ctx->curr_func.catch_depth++; - duk__advance(comp_ctx); /* eat 'try' */ + duk__advance(comp_ctx); /* eat 'try' */ reg_catch = DUK__ALLOCTEMPS(comp_ctx, 2); @@ -6051,9 +6116,9 @@ duk__emit_a_bc(comp_ctx, DUK_OP_LDCONST, reg_catch, 0 /*patched later*/); pc_trycatch = duk__get_current_pc(comp_ctx); - duk__emit_invalid(comp_ctx); /* TRYCATCH, cannot emit now (not enough info) */ - duk__emit_invalid(comp_ctx); /* jump for 'catch' case */ - duk__emit_invalid(comp_ctx); /* jump for 'finally' case or end (if no finally) */ + duk__emit_invalid(comp_ctx); /* TRYCATCH, cannot emit now (not enough info) */ + duk__emit_invalid(comp_ctx); /* jump for 'catch' case */ + duk__emit_invalid(comp_ctx); /* jump for 'finally' case or end (if no finally) */ /* try part */ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); @@ -6082,7 +6147,7 @@ */ duk_hstring *h_var; - duk_int_t varmap_value; /* for storing/restoring the varmap binding for catch variable */ + duk_int_t varmap_value; /* for storing/restoring the varmap binding for catch variable */ DUK_DDD(DUK_DDDPRINT("stack top at start of catch clause: %ld", (long) duk_get_top(thr))); @@ -6100,19 +6165,17 @@ h_var = comp_ctx->curr_token.str1; DUK_ASSERT(h_var != NULL); - duk_push_hstring(thr, h_var); /* keep in on valstack, use borrowed ref below */ + duk_push_hstring(thr, h_var); /* keep in on valstack, use borrowed ref below */ if (comp_ctx->curr_func.is_strict && - ((h_var == DUK_HTHREAD_STRING_EVAL(thr)) || - (h_var == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr)))) { + ((h_var == DUK_HTHREAD_STRING_EVAL(thr)) || (h_var == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr)))) { DUK_DDD(DUK_DDDPRINT("catch identifier 'eval' or 'arguments' in strict mode -> SyntaxError")); goto syntax_error; } duk_dup_top(thr); rc_varname = duk__getconst(comp_ctx); - DUK_DDD(DUK_DDDPRINT("catch clause, rc_varname=0x%08lx (%ld)", - (unsigned long) rc_varname, (long) rc_varname)); + DUK_DDD(DUK_DDDPRINT("catch clause, rc_varname=0x%08lx (%ld)", (unsigned long) rc_varname, (long) rc_varname)); duk__advance(comp_ctx); duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); @@ -6175,8 +6238,7 @@ DUK_DDD(DUK_DDDPRINT("varmap after restore catch clause: %!iT", (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.varmap_idx))); - duk__emit_op_only(comp_ctx, - DUK_OP_ENDCATCH); + duk__emit_op_only(comp_ctx, DUK_OP_ENDCATCH); /* * XXX: for now, indicate that an expensive catch binding @@ -6199,13 +6261,10 @@ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); duk__parse_stmts(comp_ctx, 0 /*allow_source_elem*/, 0 /*expect_eof*/, 1 /*regexp_after*/); /* the DUK_TOK_RCURLY is eaten by duk__parse_stmts() */ - duk__emit_abc(comp_ctx, - DUK_OP_ENDFIN, - reg_catch); /* rethrow */ + duk__emit_abc(comp_ctx, DUK_OP_ENDFIN, reg_catch); /* rethrow */ } - if (!(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) && - !(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY)) { + if (!(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) && !(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY)) { /* must have catch and/or finally */ goto syntax_error; } @@ -6215,12 +6274,7 @@ * constant 0) the DUK__CONST_MARKER flag will be set in rc_varname. */ - duk__patch_trycatch(comp_ctx, - pc_ldconst, - pc_trycatch, - reg_catch, - rc_varname, - trycatch_flags); + duk__patch_trycatch(comp_ctx, pc_ldconst, pc_trycatch, reg_catch, rc_varname, trycatch_flags); if (trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) { DUK_ASSERT(pc_catch >= 0); @@ -6238,7 +6292,7 @@ comp_ctx->curr_func.catch_depth--; return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_TRY); DUK_WO_NORETURN(return;); } @@ -6256,23 +6310,23 @@ comp_ctx->curr_func.catch_depth++; - duk__advance(comp_ctx); /* eat 'with' */ + duk__advance(comp_ctx); /* eat 'with' */ reg_catch = DUK__ALLOCTEMPS(comp_ctx, 2); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); duk__exprtop_toforcedreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/, reg_catch); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_trycatch = duk__get_current_pc(comp_ctx); trycatch_flags = DUK_BC_TRYCATCH_FLAG_WITH_BINDING; duk__emit_a_bc(comp_ctx, - DUK_OP_TRYCATCH | DUK__EMIT_FLAG_NO_SHUFFLE_A, - (duk_regconst_t) trycatch_flags /*a*/, - reg_catch /*bc*/); - duk__emit_invalid(comp_ctx); /* catch jump */ - duk__emit_invalid(comp_ctx); /* finished jump */ + DUK_OP_TRYCATCH | DUK__EMIT_FLAG_NO_SHUFFLE_A, + (duk_regconst_t) trycatch_flags /*a*/, + reg_catch /*bc*/); + duk__emit_invalid(comp_ctx); /* catch jump */ + duk__emit_invalid(comp_ctx); /* finished jump */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); duk__emit_op_only(comp_ctx, DUK_OP_ENDTRY); @@ -6293,9 +6347,7 @@ label_id = comp_ctx->curr_func.label_next++; DUK_DDD(DUK_DDDPRINT("allocated new label id for label site: %ld", (long) label_id)); - duk__emit_bc(comp_ctx, - DUK_OP_LABEL, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, DUK_OP_LABEL, (duk_regconst_t) label_id); duk__emit_invalid(comp_ctx); duk__emit_invalid(comp_ctx); @@ -6309,10 +6361,10 @@ */ DUK_LOCAL void duk__parse_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_bool_t allow_source_elem) { duk_hthread *thr = comp_ctx->thr; - duk_bool_t dir_prol_at_entry; /* directive prologue status at entry */ + duk_bool_t dir_prol_at_entry; /* directive prologue status at entry */ duk_regconst_t temp_at_entry; duk_size_t labels_len_at_entry; - duk_int_t pc_at_entry; /* assumed to also be PC of "LABEL" */ + duk_int_t pc_at_entry; /* assumed to also be PC of "LABEL" */ duk_int_t stmt_id; duk_small_uint_t stmt_flags = 0; duk_int_t label_id = -1; @@ -6331,8 +6383,11 @@ DUK_DDD(DUK_DDDPRINT("parsing a statement, stmt_id=%ld, temp_at_entry=%ld, labels_len_at_entry=%ld, " "is_strict=%ld, in_directive_prologue=%ld, catch_depth=%ld", - (long) stmt_id, (long) temp_at_entry, (long) labels_len_at_entry, - (long) comp_ctx->curr_func.is_strict, (long) comp_ctx->curr_func.in_directive_prologue, + (long) stmt_id, + (long) temp_at_entry, + (long) labels_len_at_entry, + (long) comp_ctx->curr_func.is_strict, + (long) comp_ctx->curr_func.in_directive_prologue, (long) comp_ctx->curr_func.catch_depth)); /* The directive prologue flag is cleared by default so that it is @@ -6342,10 +6397,12 @@ */ comp_ctx->curr_func.in_directive_prologue = 0; - retry_parse: +retry_parse: DUK_DDD(DUK_DDDPRINT("try stmt parse, stmt_id=%ld, label_id=%ld, allow_source_elem=%ld, catch_depth=%ld", - (long) stmt_id, (long) label_id, (long) allow_source_elem, + (long) stmt_id, + (long) label_id, + (long) allow_source_elem, (long) comp_ctx->curr_func.catch_depth)); /* @@ -6354,15 +6411,11 @@ */ tok = comp_ctx->curr_token.t; - if (tok == DUK_TOK_FOR || tok == DUK_TOK_DO || tok == DUK_TOK_WHILE || - tok == DUK_TOK_SWITCH) { + if (tok == DUK_TOK_FOR || tok == DUK_TOK_DO || tok == DUK_TOK_WHILE || tok == DUK_TOK_SWITCH) { DUK_DDD(DUK_DDDPRINT("iteration/switch statement -> add empty label")); label_id = duk__stmt_label_site(comp_ctx, label_id); - duk__add_label(comp_ctx, - DUK_HTHREAD_STRING_EMPTY_STRING(thr), - pc_at_entry /*pc_label*/, - label_id); + duk__add_label(comp_ctx, DUK_HTHREAD_STRING_EMPTY_STRING(thr), pc_at_entry /*pc_label*/, label_id); } /* @@ -6389,10 +6442,8 @@ * strict and non-strict modes. However, don't allow labelled * function declarations in strict mode. */ - test_func_decl = test_func_decl || - !comp_ctx->curr_func.is_strict || - label_id < 0; -#endif /* DUK_USE_NONSTD_FUNC_STMT */ + test_func_decl = test_func_decl || !comp_ctx->curr_func.is_strict || label_id < 0; +#endif /* DUK_USE_NONSTD_FUNC_STMT */ /* Strict: never allow function declarations outside top level. */ if (test_func_decl) { /* FunctionDeclaration: not strictly a statement but handled as such. @@ -6414,7 +6465,7 @@ top_before = duk_get_top(thr); #endif - duk__advance(comp_ctx); /* eat 'function' */ + duk__advance(comp_ctx); /* eat 'function' */ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_DECL | DUK__FUNC_FLAG_PUSHNAME_PASS1); /* The value stack convention here is a bit odd: the function @@ -6428,7 +6479,8 @@ DUK_ASSERT(duk_get_top(thr) == top_before + 1); #endif DUK_DDD(DUK_DDDPRINT("register function declaration %!T in pass 1, fnum %ld", - duk_get_tval(thr, -1), (long) fnum)); + duk_get_tval(thr, -1), + (long) fnum)); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); /* funcname is at index -1 */ duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n); @@ -6455,7 +6507,7 @@ duk__parse_stmts(comp_ctx, 0 /*allow_source_elem*/, 0 /*expect_eof*/, 1 /*regexp_after*/); /* the DUK_TOK_RCURLY is eaten by duk__parse_stmts() */ if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } stmt_flags = 0; break; @@ -6482,7 +6534,7 @@ DUK_DDD(DUK_DDDPRINT("if statement")); duk__parse_if_stmt(comp_ctx, res); if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } stmt_flags = 0; break; @@ -6499,19 +6551,15 @@ */ DUK_DDD(DUK_DDDPRINT("do statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_do_stmt(comp_ctx, res, pc_at_entry); - stmt_flags = DUK__HAS_TERM | DUK__ALLOW_AUTO_SEMI_ALWAYS; /* DUK__ALLOW_AUTO_SEMI_ALWAYS workaround */ + stmt_flags = DUK__HAS_TERM | DUK__ALLOW_AUTO_SEMI_ALWAYS; /* DUK__ALLOW_AUTO_SEMI_ALWAYS workaround */ break; } case DUK_TOK_WHILE: { DUK_DDD(DUK_DDDPRINT("while statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_while_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -6526,9 +6574,7 @@ */ DUK_DDD(DUK_DDDPRINT("for/for-in statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_for_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -6551,7 +6597,7 @@ comp_ctx->curr_func.with_depth++; duk__parse_with_stmt(comp_ctx, res); if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } comp_ctx->curr_func.with_depth--; stmt_flags = 0; @@ -6564,9 +6610,7 @@ */ DUK_DDD(DUK_DDDPRINT("switch statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK); /* don't allow continue */ + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK); /* don't allow continue */ duk__parse_switch_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -6633,12 +6677,10 @@ DUK_DDD(DUK_DDDPRINT("expression statement")); duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - single_token = (comp_ctx->curr_func.nud_count == 1 && /* one token */ - comp_ctx->curr_func.led_count == 0); /* no operators */ + single_token = (comp_ctx->curr_func.nud_count == 1 && /* one token */ + comp_ctx->curr_func.led_count == 0); /* no operators */ - if (single_token && - comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->curr_token.t == DUK_TOK_COLON) { + if (single_token && comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->curr_token.t == DUK_TOK_COLON) { /* * Detected label */ @@ -6652,17 +6694,13 @@ h_lab = comp_ctx->prev_token.str1; DUK_ASSERT(h_lab != NULL); - DUK_DDD(DUK_DDDPRINT("explicit label site for label '%!O'", - (duk_heaphdr *) h_lab)); + DUK_DDD(DUK_DDDPRINT("explicit label site for label '%!O'", (duk_heaphdr *) h_lab)); - duk__advance(comp_ctx); /* eat colon */ + duk__advance(comp_ctx); /* eat colon */ label_id = duk__stmt_label_site(comp_ctx, label_id); - duk__add_label(comp_ctx, - h_lab, - pc_at_entry /*pc_label*/, - label_id); + duk__add_label(comp_ctx, h_lab, pc_at_entry /*pc_label*/, label_id); /* a statement following a label cannot be a source element * (a function declaration). @@ -6675,8 +6713,8 @@ stmt_flags = 0; - if (dir_prol_at_entry && /* still in prologue */ - single_token && /* single string token */ + if (dir_prol_at_entry && /* still in prologue */ + single_token && /* single string token */ comp_ctx->prev_token.t == DUK_TOK_STRING) { /* * Detected a directive @@ -6709,7 +6747,8 @@ DUK_STRCMP((const char *) DUK_HSTRING_GET_DATA(h_dir), "use strict") == 0) { #if defined(DUK_USE_STRICT_DECL) DUK_DDD(DUK_DDDPRINT("use strict directive detected: strict flag %ld -> %ld", - (long) comp_ctx->curr_func.is_strict, (long) 1)); + (long) comp_ctx->curr_func.is_strict, + (long) 1)); comp_ctx->curr_func.is_strict = 1; #else DUK_DDD(DUK_DDDPRINT("use strict detected but strict declarations disabled, ignoring")); @@ -6717,21 +6756,23 @@ } else if (DUK_HSTRING_GET_BYTELEN(h_dir) == 14 && DUK_STRCMP((const char *) DUK_HSTRING_GET_DATA(h_dir), "use duk notail") == 0) { DUK_DDD(DUK_DDDPRINT("use duk notail directive detected: notail flag %ld -> %ld", - (long) comp_ctx->curr_func.is_notail, (long) 1)); + (long) comp_ctx->curr_func.is_notail, + (long) 1)); comp_ctx->curr_func.is_notail = 1; } else { DUK_DD(DUK_DDPRINT("unknown directive: '%!O', ignoring but not terminating " - "directive prologue", (duk_hobject *) h_dir)); + "directive prologue", + (duk_hobject *) h_dir)); } } } else { DUK_DDD(DUK_DDDPRINT("non-directive expression statement or no longer in prologue; " "prologue terminated if still active")); - } + } stmt_flags |= DUK__HAS_VAL | DUK__HAS_TERM; } - } /* end switch (tok) */ + } /* end switch (tok) */ /* * Statement value handling. @@ -6807,9 +6848,7 @@ */ if (label_id >= 0) { - duk__emit_bc(comp_ctx, - DUK_OP_ENDLABEL, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, DUK_OP_ENDLABEL, (duk_regconst_t) label_id); } DUK__SETTEMP(comp_ctx, temp_at_entry); @@ -6832,7 +6871,10 @@ * (EOF or closing brace). */ -DUK_LOCAL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, duk_bool_t allow_source_elem, duk_bool_t expect_eof, duk_bool_t regexp_after) { +DUK_LOCAL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, + duk_bool_t allow_source_elem, + duk_bool_t expect_eof, + duk_bool_t regexp_after) { duk_hthread *thr = comp_ctx->thr; duk_ivalue res_alloc; duk_ivalue *res = &res_alloc; @@ -6998,7 +7040,7 @@ /* only functions can have arguments */ DUK_ASSERT(comp_ctx->curr_func.is_function); - duk_push_uarridx(thr, i); /* -> ... name index */ + duk_push_uarridx(thr, i); /* -> ... name index */ duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* -> ... */ /* no code needs to be emitted, the regs already have values */ @@ -7034,16 +7076,15 @@ */ num_decls = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); - DUK_DDD(DUK_DDDPRINT("num_decls=%ld -> %!T", - (long) num_decls, - (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.decls_idx))); + DUK_DDD( + DUK_DDDPRINT("num_decls=%ld -> %!T", (long) num_decls, (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.decls_idx))); for (i = 0; i < num_decls; i += 2) { duk_int_t decl_type; duk_int_t fnum; - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ decl_type = duk_to_int(thr, -1); - fnum = decl_type >> 8; /* XXX: macros */ + fnum = decl_type >> 8; /* XXX: macros */ decl_type = decl_type & 0xff; duk_pop(thr); @@ -7051,7 +7092,7 @@ continue; } - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ /* XXX: spilling */ if (comp_ctx->curr_func.is_function) { @@ -7061,18 +7102,12 @@ /* shadowed; update value */ duk_dup_top(thr); duk_get_prop(thr, comp_ctx->curr_func.varmap_idx); - reg_bind = duk_to_int(thr, -1); /* ... name reg_bind */ - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_bind, - (duk_regconst_t) fnum); + reg_bind = duk_to_int(thr, -1); /* ... name reg_bind */ + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_bind, (duk_regconst_t) fnum); } else { /* function: always register bound */ reg_bind = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_bind, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_bind, (duk_regconst_t) fnum); duk_push_int(thr, (duk_int_t) reg_bind); } } else { @@ -7089,14 +7124,9 @@ rc_name = duk__getconst(comp_ctx); duk_push_null(thr); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp, - (duk_regconst_t) fnum); - - declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE | - DUK_BC_DECLVAR_FLAG_FUNC_DECL; + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp, (duk_regconst_t) fnum); + + declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_BC_DECLVAR_FLAG_FUNC_DECL; if (configurable_bindings) { declvar_flags |= DUK_PROPDESC_FLAG_CONFIGURABLE; @@ -7108,7 +7138,7 @@ rc_name /*name*/, reg_temp /*value*/); - DUK__SETTEMP(comp_ctx, reg_temp); /* forget temp */ + DUK__SETTEMP(comp_ctx, reg_temp); /* forget temp */ } DUK_DDD(DUK_DDDPRINT("function declaration to varmap: %!T -> %!T", @@ -7118,7 +7148,7 @@ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_NULL(duk_get_tval(thr, -1)) || DUK_TVAL_IS_FASTINT(duk_get_tval(thr, -1))); #endif - duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ + duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ } /* @@ -7145,7 +7175,7 @@ for (i = 0; i < num_decls; i += 2) { duk_int_t decl_type; - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ decl_type = duk_to_int(thr, -1); decl_type = decl_type & 0xff; duk_pop(thr); @@ -7154,16 +7184,15 @@ continue; } - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ if (duk_has_prop(thr, comp_ctx->curr_func.varmap_idx)) { /* shadowed, ignore */ } else { - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ h_name = duk_known_hstring(thr, -1); - if (h_name == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr) && - !comp_ctx->curr_func.is_arguments_shadowed) { + if (h_name == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr) && !comp_ctx->curr_func.is_arguments_shadowed) { /* E5 Section steps 7-8 */ DUK_DDD(DUK_DDDPRINT("'arguments' not shadowed by a function declaration, " "but appears as a variable declaration -> treat as " @@ -7182,8 +7211,7 @@ rc_name = duk__getconst(comp_ctx); duk_push_null(thr); - declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE; + declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE; if (configurable_bindings) { declvar_flags |= DUK_PROPDESC_FLAG_CONFIGURABLE; } @@ -7195,7 +7223,7 @@ 0 /*value*/); } - duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ + duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ } } @@ -7210,11 +7238,11 @@ DUK_ASSERT_TOP(thr, entry_top); return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); - error_argname: +error_argname: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_ARG_NAME); DUK_WO_NORETURN(return;); } @@ -7253,7 +7281,11 @@ * token (EOF or closing brace). */ -DUK_LOCAL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, duk_bool_t expect_eof, duk_bool_t implicit_return_value, duk_bool_t regexp_after, duk_small_int_t expect_token) { +DUK_LOCAL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, + duk_bool_t expect_eof, + duk_bool_t implicit_return_value, + duk_bool_t regexp_after, + duk_small_int_t expect_token) { duk_compiler_func *func; duk_hthread *thr; duk_regconst_t reg_stmt_value = -1; @@ -7345,8 +7377,8 @@ DUK_DDD(DUK_DDDPRINT("begin 1st pass")); duk__parse_stmts(comp_ctx, - 1, /* allow source elements */ - expect_eof, /* expect EOF instead of } */ + 1, /* allow source elements */ + expect_eof, /* expect EOF instead of } */ regexp_after); /* regexp after */ DUK_DDD(DUK_DDDPRINT("end 1st pass")); @@ -7375,8 +7407,8 @@ DUK_DDD(DUK_DDDPRINT("rewind lexer")); DUK_LEXER_SETPOINT(&comp_ctx->lex, &lex_pt); - comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ duk__advance(comp_ctx); /* @@ -7397,8 +7429,7 @@ /* must be able to emit code, alloc consts, etc. */ - duk__init_varmap_and_prologue_for_pass2(comp_ctx, - (implicit_return_value ? ®_stmt_value : NULL)); + duk__init_varmap_and_prologue_for_pass2(comp_ctx, (implicit_return_value ? ®_stmt_value : NULL)); func->reg_stmt_value = reg_stmt_value; temp_first = DUK__GETTEMP(comp_ctx); @@ -7446,15 +7477,13 @@ if (implicit_return_value) { /* Default implicit return value. */ - duk__emit_bc(comp_ctx, - DUK_OP_LDUNDEF, - 0); + duk__emit_bc(comp_ctx, DUK_OP_LDUNDEF, 0); } DUK_DDD(DUK_DDDPRINT("begin 2nd pass")); duk__parse_stmts(comp_ctx, - 1, /* allow source elements */ - expect_eof, /* expect EOF instead of } */ + 1, /* allow source elements */ + expect_eof, /* expect EOF instead of } */ regexp_after); /* regexp after */ DUK_DDD(DUK_DDDPRINT("end 2nd pass")); @@ -7510,7 +7539,7 @@ DUK__RECURSION_DECREASE(comp_ctx, thr); return; - error_funcname: +error_funcname: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_FUNC_NAME); DUK_WO_NORETURN(return;); } @@ -7565,15 +7594,14 @@ } DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_IDENTIFIER); DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); - DUK_DDD(DUK_DDDPRINT("formal argument: %!O", - (duk_heaphdr *) comp_ctx->curr_token.str1)); + DUK_DDD(DUK_DDDPRINT("formal argument: %!O", (duk_heaphdr *) comp_ctx->curr_token.str1)); /* XXX: append primitive */ duk_push_hstring(thr, comp_ctx->curr_token.str1); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.argnames_idx); duk_put_prop_index(thr, comp_ctx->curr_func.argnames_idx, n); - duk__advance(comp_ctx); /* eat identifier */ + duk__advance(comp_ctx); /* eat identifier */ } } @@ -7621,7 +7649,7 @@ if (flags & DUK__FUNC_FLAG_GETSET) { /* PropertyName -> IdentifierName | StringLiteral | NumericLiteral */ if (tok->t_nores == DUK_TOK_IDENTIFIER || tok->t == DUK_TOK_STRING) { - duk_push_hstring(thr, tok->str1); /* keep in valstack */ + duk_push_hstring(thr, tok->str1); /* keep in valstack */ } else if (tok->t == DUK_TOK_NUMBER) { duk_push_number(thr, tok->num); duk_to_string(thr, -1); @@ -7629,15 +7657,15 @@ DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_GETSET_NAME); DUK_WO_NORETURN(return;); } - comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ + comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ } else { /* Function name is an Identifier (not IdentifierName), but we get * the raw name (not recognizing keywords) here and perform the name * checks only after pass 1. */ if (tok->t_nores == DUK_TOK_IDENTIFIER) { - duk_push_hstring(thr, tok->str1); /* keep in valstack */ - comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ + duk_push_hstring(thr, tok->str1); /* keep in valstack */ + comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ } else { /* valstack will be unbalanced, which is OK */ DUK_ASSERT((flags & DUK__FUNC_FLAG_GETSET) == 0); @@ -7650,8 +7678,7 @@ } } - DUK_DD(DUK_DDPRINT("function name: %!O", - (duk_heaphdr *) comp_ctx->curr_func.h_name)); + DUK_DD(DUK_DDPRINT("function name: %!O", (duk_heaphdr *) comp_ctx->curr_func.h_name)); if (!no_advance) { duk__advance(comp_ctx); @@ -7677,17 +7704,17 @@ */ duk__parse_func_body(comp_ctx, - 0, /* expect_eof */ - 0, /* implicit_return_value */ + 0, /* expect_eof */ + 0, /* implicit_return_value */ flags & DUK__FUNC_FLAG_DECL, /* regexp_after */ - DUK_TOK_LCURLY); /* expect_token */ + DUK_TOK_LCURLY); /* expect_token */ /* * Convert duk_compiler_func to a function template and add it * to the parent function table. */ - duk__convert_to_func_template(comp_ctx); /* -> ... func */ + duk__convert_to_func_template(comp_ctx); /* -> ... func */ } /* Parse an inner function, adding the function template to the current function's @@ -7725,12 +7752,14 @@ lex_pt.line = duk_to_int(thr, -1); duk_pop(thr); - DUK_DDD(DUK_DDDPRINT("second pass of an inner func, skip the function, reparse closing brace; lex offset=%ld, line=%ld", - (long) lex_pt.offset, (long) lex_pt.line)); + DUK_DDD( + DUK_DDDPRINT("second pass of an inner func, skip the function, reparse closing brace; lex offset=%ld, line=%ld", + (long) lex_pt.offset, + (long) lex_pt.line)); DUK_LEXER_SETPOINT(&comp_ctx->lex, &lex_pt); - comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ duk__advance(comp_ctx); /* RegExp is not allowed after a function expression, e.g. in @@ -7752,7 +7781,8 @@ entry_top = duk_get_top(thr); DUK_DDD(DUK_DDDPRINT("before func: entry_top=%ld, curr_tok.start_offset=%ld", - (long) entry_top, (long) comp_ctx->curr_token.start_offset)); + (long) entry_top, + (long) comp_ctx->curr_token.start_offset)); duk_memcpy(&old_func, &comp_ctx->curr_func, sizeof(duk_compiler_func)); @@ -7772,24 +7802,25 @@ DUK_ASSERT(comp_ctx->curr_func.is_eval == 0); DUK_ASSERT(comp_ctx->curr_func.is_global == 0); comp_ctx->curr_func.is_setget = ((flags & DUK__FUNC_FLAG_GETSET) != 0); - comp_ctx->curr_func.is_namebinding = !(flags & (DUK__FUNC_FLAG_GETSET | - DUK__FUNC_FLAG_METDEF | - DUK__FUNC_FLAG_DECL)); /* no name binding for: declarations, objlit getset, objlit method def */ - comp_ctx->curr_func.is_constructable = !(flags & (DUK__FUNC_FLAG_GETSET | - DUK__FUNC_FLAG_METDEF)); /* not constructable: objlit getset, objlit method def */ + comp_ctx->curr_func.is_namebinding = + !(flags & (DUK__FUNC_FLAG_GETSET | DUK__FUNC_FLAG_METDEF | + DUK__FUNC_FLAG_DECL)); /* no name binding for: declarations, objlit getset, objlit method def */ + comp_ctx->curr_func.is_constructable = + !(flags & (DUK__FUNC_FLAG_GETSET | DUK__FUNC_FLAG_METDEF)); /* not constructable: objlit getset, objlit method def */ /* * Parse inner function */ - duk__parse_func_like_raw(comp_ctx, flags); /* pushes function template */ + duk__parse_func_like_raw(comp_ctx, flags); /* pushes function template */ /* prev_token.start_offset points to the closing brace here; when skipping * we're going to reparse the closing brace to ensure semicolon insertion * etc work as expected. */ DUK_DDD(DUK_DDDPRINT("after func: prev_tok.start_offset=%ld, curr_tok.start_offset=%ld", - (long) comp_ctx->prev_token.start_offset, (long) comp_ctx->curr_token.start_offset)); + (long) comp_ctx->prev_token.start_offset, + (long) comp_ctx->curr_token.start_offset)); DUK_ASSERT(comp_ctx->lex.inputcomp_ctx->prev_token.start_offset == (duk_uint8_t) DUK_ASC_RCURLY); /* XXX: append primitive */ @@ -7875,7 +7906,7 @@ is_strict = (flags & DUK_COMPILE_STRICT ? 1 : 0); is_funcexpr = (flags & DUK_COMPILE_FUNCEXPR ? 1 : 0); - h_filename = duk_get_hstring(thr, -1); /* may be undefined */ + h_filename = duk_get_hstring(thr, -1); /* may be undefined */ /* * Init compiler and lexer contexts @@ -7893,11 +7924,11 @@ duk_require_stack(thr, DUK__COMPILE_ENTRY_SLOTS); - duk_push_dynamic_buffer(thr, 0); /* entry_top + 0 */ - duk_push_undefined(thr); /* entry_top + 1 */ - duk_push_undefined(thr); /* entry_top + 2 */ - duk_push_undefined(thr); /* entry_top + 3 */ - duk_push_undefined(thr); /* entry_top + 4 */ + duk_push_dynamic_buffer(thr, 0); /* entry_top + 0 */ + duk_push_undefined(thr); /* entry_top + 1 */ + duk_push_undefined(thr); /* entry_top + 2 */ + duk_push_undefined(thr); /* entry_top + 3 */ + duk_push_undefined(thr); /* entry_top + 4 */ comp_ctx->thr = thr; comp_ctx->h_filename = h_filename; @@ -7921,8 +7952,8 @@ lex_pt->offset = 0; lex_pt->line = 1; - DUK_LEXER_SETPOINT(&comp_ctx->lex, lex_pt); /* fills window */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + DUK_LEXER_SETPOINT(&comp_ctx->lex, lex_pt); /* fills window */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ /* * Initialize function state for a zero-argument function @@ -7938,8 +7969,7 @@ */ DUK_ASSERT(func->h_name == NULL); } else { - duk_push_hstring_stridx(thr, (is_eval ? DUK_STRIDX_EVAL : - DUK_STRIDX_GLOBAL)); + duk_push_hstring_stridx(thr, (is_eval ? DUK_STRIDX_EVAL : DUK_STRIDX_GLOBAL)); func->h_name = duk_get_hstring(thr, -1); } @@ -7959,7 +7989,7 @@ func->is_namebinding = 1; func->is_constructable = 1; - duk__advance(comp_ctx); /* init 'curr_token' */ + duk__advance(comp_ctx); /* init 'curr_token' */ duk__advance_expect(comp_ctx, DUK_TOK_FUNCTION); (void) duk__parse_func_like_raw(comp_ctx, 0 /*flags*/); } else { @@ -7971,10 +8001,10 @@ DUK_ASSERT(func->is_constructable == 0); duk__parse_func_body(comp_ctx, - 1, /* expect_eof */ - 1, /* implicit_return_value */ - 1, /* regexp_after (does not matter) */ - -1); /* expect_token */ + 1, /* expect_eof */ + 1, /* implicit_return_value */ + 1, /* regexp_after (does not matter) */ + -1); /* expect_token */ } /* @@ -8006,14 +8036,14 @@ DUK_LEXER_INITCTX(&comp_stk.comp_ctx_alloc.lex); comp_stk.comp_ctx_alloc.lex.input = src_buffer; comp_stk.comp_ctx_alloc.lex.input_length = src_length; - comp_stk.comp_ctx_alloc.lex.flags = flags; /* Forward flags directly for now. */ + comp_stk.comp_ctx_alloc.lex.flags = flags; /* Forward flags directly for now. */ /* ... filename */ prev_ctx = thr->compile_ctx; - thr->compile_ctx = &comp_stk.comp_ctx_alloc; /* for duk_error_augment.c */ + thr->compile_ctx = &comp_stk.comp_ctx_alloc; /* for duk_error_augment.c */ safe_rc = duk_safe_call(thr, duk__js_compile_raw, (void *) &comp_stk /*udata*/, 1 /*nargs*/, 1 /*nrets*/); - thr->compile_ctx = prev_ctx; /* must restore reliably before returning */ + thr->compile_ctx = prev_ctx; /* must restore reliably before returning */ if (safe_rc != DUK_EXEC_SUCCESS) { DUK_D(DUK_DPRINT("compilation failed: %!T", duk_get_tval(thr, -1)));
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_js_compiler.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_js_compiler.h
Changed
@@ -6,13 +6,13 @@ #define DUK_JS_COMPILER_H_INCLUDED /* ECMAScript compiler limits */ -#define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */ +#define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */ /* maximum loopcount for peephole optimization */ -#define DUK_COMPILER_PEEPHOLE_MAXITER 3 +#define DUK_COMPILER_PEEPHOLE_MAXITER 3 /* maximum bytecode length in instructions */ -#define DUK_COMPILER_MAX_BYTECODE_LENGTH (256L * 1024L * 1024L) /* 1 GB */ +#define DUK_COMPILER_MAX_BYTECODE_LENGTH (256L * 1024L * 1024L) /* 1 GB */ /* * Compiler intermediate values @@ -22,21 +22,21 @@ * either a left-hand-side or right-hand-side role (e.g. object property). */ -#define DUK_IVAL_NONE 0 /* no value */ -#define DUK_IVAL_PLAIN 1 /* register, constant, or value */ -#define DUK_IVAL_ARITH 2 /* binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops */ -#define DUK_IVAL_PROP 3 /* property access */ -#define DUK_IVAL_VAR 4 /* variable access */ +#define DUK_IVAL_NONE 0 /* no value */ +#define DUK_IVAL_PLAIN 1 /* register, constant, or value */ +#define DUK_IVAL_ARITH 2 /* binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops */ +#define DUK_IVAL_PROP 3 /* property access */ +#define DUK_IVAL_VAR 4 /* variable access */ -#define DUK_ISPEC_NONE 0 /* no value */ -#define DUK_ISPEC_VALUE 1 /* value resides in 'valstack_idx' */ -#define DUK_ISPEC_REGCONST 2 /* value resides in a register or constant */ +#define DUK_ISPEC_NONE 0 /* no value */ +#define DUK_ISPEC_VALUE 1 /* value resides in 'valstack_idx' */ +#define DUK_ISPEC_REGCONST 2 /* value resides in a register or constant */ /* Bit mask which indicates that a regconst is a constant instead of a register. * Chosen so that when a regconst is cast to duk_int32_t, all consts are * negative values. */ -#define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */ +#define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */ /* Type to represent a reg/const reference during compilation, with <0 * indicating a constant. Some call sites also use -1 to indicate 'none'. @@ -44,9 +44,9 @@ typedef duk_int32_t duk_regconst_t; typedef struct { - duk_small_uint_t t; /* DUK_ISPEC_XXX */ + duk_small_uint_t t; /* DUK_ISPEC_XXX */ duk_regconst_t regconst; - duk_idx_t valstack_idx; /* always set; points to a reserved valstack slot */ + duk_idx_t valstack_idx; /* always set; points to a reserved valstack slot */ } duk_ispec; typedef struct { @@ -58,8 +58,8 @@ */ /* XXX: can be optimized for smaller footprint esp. on 32-bit environments */ - duk_small_uint_t t; /* DUK_IVAL_XXX */ - duk_small_uint_t op; /* bytecode opcode for binary ops */ + duk_small_uint_t t; /* DUK_IVAL_XXX */ + duk_small_uint_t op; /* bytecode opcode for binary ops */ duk_ispec x1; duk_ispec x2; } duk_ivalue; @@ -81,22 +81,22 @@ * Compiler state */ -#define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0) -#define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1) +#define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0) +#define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1) -#define DUK_DECL_TYPE_VAR 0 -#define DUK_DECL_TYPE_FUNC 1 +#define DUK_DECL_TYPE_VAR 0 +#define DUK_DECL_TYPE_FUNC 1 /* XXX: optimize to 16 bytes */ typedef struct { duk_small_uint_t flags; - duk_int_t label_id; /* numeric label_id (-1 reserved as marker) */ - duk_hstring *h_label; /* borrowed label name */ - duk_int_t catch_depth; /* catch depth at point of definition */ - duk_int_t pc_label; /* pc of label statement: - * pc+1: break jump site - * pc+2: continue jump site - */ + duk_int_t label_id; /* numeric label_id (-1 reserved as marker) */ + duk_hstring *h_label; /* borrowed label name */ + duk_int_t catch_depth; /* catch depth at point of definition */ + duk_int_t pc_label; /* pc of label statement: + * pc+1: break jump site + * pc+2: continue jump site + */ /* Fast jumps (which avoid longjmp) jump directly to the jump sites * which are always known even while the iteration/switch statement @@ -112,22 +112,22 @@ * platforms (e.g. if int is 32 bits and pointers are 64 bits). */ - duk_bufwriter_ctx bw_code; /* bufwriter for code */ + duk_bufwriter_ctx bw_code; /* bufwriter for code */ - duk_hstring *h_name; /* function name (borrowed reference), ends up in _name */ + duk_hstring *h_name; /* function name (borrowed reference), ends up in _name */ /* h_code: held in bw_code */ - duk_hobject *h_consts; /* array */ - duk_hobject *h_funcs; /* array of function templates: func1, offset1, line1, func2, offset2, line2 - * offset/line points to closing brace to allow skipping on pass 2 - */ - duk_hobject *h_decls; /* array of declarations: name1, val1, name2, val2, ... - * valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars) - * record function and variable declarations in pass 1 - */ - duk_hobject *h_labelnames; /* array of active label names */ - duk_hbuffer_dynamic *h_labelinfos; /* C array of duk_labelinfo */ - duk_hobject *h_argnames; /* array of formal argument names (-> _Formals) */ - duk_hobject *h_varmap; /* variable map for pass 2 (identifier -> register number or null (unmapped)) */ + duk_hobject *h_consts; /* array */ + duk_hobject *h_funcs; /* array of function templates: func1, offset1, line1, func2, offset2, line2 + * offset/line points to closing brace to allow skipping on pass 2 + */ + duk_hobject *h_decls; /* array of declarations: name1, val1, name2, val2, ... + * valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars) + * record function and variable declarations in pass 1 + */ + duk_hobject *h_labelnames; /* array of active label names */ + duk_hbuffer_dynamic *h_labelinfos; /* C array of duk_labelinfo */ + duk_hobject *h_argnames; /* array of formal argument names (-> _Formals) */ + duk_hobject *h_varmap; /* variable map for pass 2 (identifier -> register number or null (unmapped)) */ /* Value stack indices for tracking objects. */ /* code_idx: not needed */ @@ -140,9 +140,9 @@ duk_idx_t varmap_idx; /* Temp reg handling. */ - duk_regconst_t temp_first; /* first register that is a temporary (below: variables) */ - duk_regconst_t temp_next; /* next temporary register to allocate */ - duk_regconst_t temp_max; /* highest value of temp_reg (temp_max - 1 is highest used reg) */ + duk_regconst_t temp_first; /* first register that is a temporary (below: variables) */ + duk_regconst_t temp_next; /* next temporary register to allocate */ + duk_regconst_t temp_max; /* highest value of temp_reg (temp_max - 1 is highest used reg) */ /* Shuffle registers if large number of regs/consts. */ duk_regconst_t shuffle1; @@ -152,49 +152,51 @@ /* Stats for current expression being parsed. */ duk_int_t nud_count; duk_int_t led_count; - duk_int_t paren_level; /* parenthesis count, 0 = top level */ - duk_bool_t expr_lhs; /* expression is left-hand-side compatible */ - duk_bool_t allow_in; /* current paren level allows 'in' token */ + duk_int_t paren_level; /* parenthesis count, 0 = top level */ + duk_bool_t expr_lhs; /* expression is left-hand-side compatible */ + duk_bool_t allow_in; /* current paren level allows 'in' token */ /* Misc. */ - duk_int_t stmt_next; /* statement id allocation (running counter) */ - duk_int_t label_next; /* label id allocation (running counter) */ - duk_int_t catch_depth; /* catch stack depth */ - duk_int_t with_depth; /* with stack depth (affects identifier lookups) */ - duk_int_t fnum_next; /* inner function numbering */ - duk_int_t num_formals; /* number of formal arguments */ - duk_regconst_t reg_stmt_value; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */ + duk_int_t stmt_next; /* statement id allocation (running counter) */ + duk_int_t label_next; /* label id allocation (running counter) */ + duk_int_t catch_depth; /* catch stack depth */ + duk_int_t with_depth; /* with stack depth (affects identifier lookups) */ + duk_int_t fnum_next; /* inner function numbering */ + duk_int_t num_formals; /* number of formal arguments */ + duk_regconst_t + reg_stmt_value; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */ #if defined(DUK_USE_DEBUGGER_SUPPORT) - duk_int_t min_line; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */ + duk_int_t min_line; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */ duk_int_t max_line; #endif /* Status booleans. */ - duk_uint8_t is_function; /* is an actual function (not global/eval code) */ - duk_uint8_t is_eval; /* is eval code */ - duk_uint8_t is_global; /* is global code */ - duk_uint8_t is_namebinding; /* needs a name binding */ - duk_uint8_t is_constructable; /* result is constructable */ - duk_uint8_t is_setget; /* is a setter/getter */ - duk_uint8_t is_strict; /* function is strict */ - duk_uint8_t is_notail; /* function must not be tail called */ - duk_uint8_t in_directive_prologue; /* parsing in "directive prologue", recognize directives */ - duk_uint8_t in_scanning; /* parsing in "scanning" phase (first pass) */ - duk_uint8_t may_direct_eval; /* function may call direct eval */ - duk_uint8_t id_access_arguments; /* function refers to 'arguments' identifier */ - duk_uint8_t id_access_slow; /* function makes one or more slow path accesses that won't match own static variables */ - duk_uint8_t id_access_slow_own; /* function makes one or more slow path accesses that may match own static variables */ - duk_uint8_t is_arguments_shadowed; /* argument/function declaration shadows 'arguments' */ - duk_uint8_t needs_shuffle; /* function needs shuffle registers */ - duk_uint8_t reject_regexp_in_adv; /* reject RegExp literal on next advance() call; needed for handling IdentifierName productions */ - duk_uint8_t allow_regexp_in_adv; /* allow RegExp literal on next advance() call */ + duk_uint8_t is_function; /* is an actual function (not global/eval code) */ + duk_uint8_t is_eval; /* is eval code */ + duk_uint8_t is_global; /* is global code */ + duk_uint8_t is_namebinding; /* needs a name binding */ + duk_uint8_t is_constructable; /* result is constructable */ + duk_uint8_t is_setget; /* is a setter/getter */ + duk_uint8_t is_strict; /* function is strict */ + duk_uint8_t is_notail; /* function must not be tail called */ + duk_uint8_t in_directive_prologue; /* parsing in "directive prologue", recognize directives */ + duk_uint8_t in_scanning; /* parsing in "scanning" phase (first pass) */ + duk_uint8_t may_direct_eval; /* function may call direct eval */ + duk_uint8_t id_access_arguments; /* function refers to 'arguments' identifier */ + duk_uint8_t id_access_slow; /* function makes one or more slow path accesses that won't match own static variables */ + duk_uint8_t id_access_slow_own; /* function makes one or more slow path accesses that may match own static variables */ + duk_uint8_t is_arguments_shadowed; /* argument/function declaration shadows 'arguments' */ + duk_uint8_t needs_shuffle; /* function needs shuffle registers */ + duk_uint8_t + reject_regexp_in_adv; /* reject RegExp literal on next advance() call; needed for handling IdentifierName productions */ + duk_uint8_t allow_regexp_in_adv; /* allow RegExp literal on next advance() call */ }; struct duk_compiler_ctx { duk_hthread *thr; /* filename being compiled (ends up in functions' '_filename' property) */ - duk_hstring *h_filename; /* borrowed reference */ + duk_hstring *h_filename; /* borrowed reference */ /* lexing (tokenization) state (contains two valstack slot indices) */ duk_lexer_ctx lex; @@ -202,10 +204,10 @@ /* current and previous token for parsing */ duk_token prev_token; duk_token curr_token; - duk_idx_t tok11_idx; /* curr_token slot1 (matches 'lex' slot1_idx) */ - duk_idx_t tok12_idx; /* curr_token slot2 (matches 'lex' slot2_idx) */ - duk_idx_t tok21_idx; /* prev_token slot1 */ - duk_idx_t tok22_idx; /* prev_token slot2 */ + duk_idx_t tok11_idx; /* curr_token slot1 (matches 'lex' slot1_idx) */ + duk_idx_t tok12_idx; /* curr_token slot2 (matches 'lex' slot2_idx) */ + duk_idx_t tok21_idx; /* prev_token slot1 */ + duk_idx_t tok22_idx; /* prev_token slot2 */ /* recursion limit */ duk_int_t recursion_depth; @@ -222,6 +224,9 @@ * Prototypes */ -DUK_INTERNAL_DECL void duk_js_compile(duk_hthread *thr, const duk_uint8_t *src_buffer, duk_size_t src_length, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_js_compile(duk_hthread *thr, + const duk_uint8_t *src_buffer, + duk_size_t src_length, + duk_small_uint_t flags); -#endif /* DUK_JS_COMPILER_H_INCLUDED */ +#endif /* DUK_JS_COMPILER_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_js_executor.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_js_executor.c
Changed
@@ -17,7 +17,8 @@ /* Replace value stack top to value at 'tv_ptr'. Optimize for * performance by only applying the net refcount change. */ -#define DUK__REPLACE_TO_TVPTR(thr,tv_ptr) do { \ +#define DUK__REPLACE_TO_TVPTR(thr, tv_ptr) \ + do { \ duk_hthread *duk__thr; \ duk_tval *duk__tvsrc; \ duk_tval *duk__tvdst; \ @@ -27,13 +28,13 @@ duk__tvdst = (tv_ptr); \ DUK_TVAL_SET_TVAL(&duk__tvtmp, duk__tvdst); \ DUK_TVAL_SET_TVAL(duk__tvdst, duk__tvsrc); \ - DUK_TVAL_SET_UNDEFINED(duk__tvsrc); /* value stack init policy */ \ + DUK_TVAL_SET_UNDEFINED(duk__tvsrc); /* value stack init policy */ \ duk__thr->valstack_top = duk__tvsrc; \ DUK_TVAL_DECREF(duk__thr, &duk__tvtmp); \ } while (0) /* XXX: candidate of being an internal shared API call */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__push_tvals_incref_only(duk_hthread *thr, duk_tval *tv_src, duk_small_uint_fast_t count) { duk_tval *tv_dst; duk_size_t copy_size; @@ -75,7 +76,10 @@ } #endif -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_add(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_fast_t idx_z) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_add(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_small_uint_fast_t idx_z) { /* * Addition operator is different from other arithmetic * operations in that it also provides string concatenation. @@ -95,9 +99,9 @@ duk_double_union du; DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); /* @@ -120,14 +124,14 @@ v3_hi = (duk_int32_t) (v3 >> 32); if (DUK_LIKELY(v3_hi >= DUK_I64_CONSTANT(-0x8000) && v3_hi <= DUK_I64_CONSTANT(0x7fff))) { tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ return; } else { /* overflow, fall through */ ; } } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { #if !defined(DUK_USE_EXEC_PREFER_SIZE) @@ -136,14 +140,14 @@ du.d = DUK_TVAL_GET_NUMBER(tv_x) + DUK_TVAL_GET_NUMBER(tv_y); #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ return; } @@ -153,7 +157,7 @@ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -2, DUK_HINT_NONE); /* side effects -> don't use tv_x, tv_y after */ + duk_to_primitive(thr, -2, DUK_HINT_NONE); /* side effects -> don't use tv_x, tv_y after */ duk_to_primitive(thr, -1, DUK_HINT_NONE); /* Since Duktape 2.x plain buffers are treated like ArrayBuffer. */ @@ -164,7 +168,7 @@ * in duk_concat_2() which also fails with TypeError so no * explicit check is needed. */ - duk_concat_2(thr); /* ... s1 s2 -> ... s1+s2 */ + duk_concat_2(thr); /* ... s1 s2 -> ... s1+s2 */ } else { duk_double_t d1, d2; @@ -177,12 +181,16 @@ du.d = d1 + d2; duk_pop_2_unsafe(thr); - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ } - duk_replace(thr, (duk_idx_t) idx_z); /* side effects */ + duk_replace(thr, (duk_idx_t) idx_z); /* side effects */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_binary_op(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_uint_fast_t idx_z, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_binary_op(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_uint_fast_t idx_z, + duk_small_uint_fast_t opcode) { /* * Arithmetic operations other than '+' have number-only semantics * and are implemented here. The separate switch-case here means a @@ -199,12 +207,12 @@ #endif DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); - opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ + opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y)) { @@ -271,13 +279,13 @@ v3_hi = (duk_int32_t) (v3 >> 32); if (DUK_LIKELY(v3_hi >= DUK_I64_CONSTANT(-0x8000) && v3_hi <= DUK_I64_CONSTANT(0x7fff))) { tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ return; } /* fall through if overflow etc */ } - skip_fastint: -#endif /* DUK_USE_FASTINT */ +skip_fastint: +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { /* fast path */ @@ -286,7 +294,7 @@ } else { duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - d1 = duk_to_number_m2(thr); /* side effects */ + d1 = duk_to_number_m2(thr); /* side effects */ d2 = duk_to_number_m1(thr); DUK_ASSERT(duk_is_number(thr, -2)); DUK_ASSERT(duk_is_number(thr, -1)); @@ -323,24 +331,28 @@ #endif default: { DUK_UNREACHABLE(); - du.d = DUK_DOUBLE_NAN; /* should not happen */ + du.d = DUK_DOUBLE_NAN; /* should not happen */ break; } } #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ /* important to use normalized NaN with 8-byte tagged types */ DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_bitwise_binary_op(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_fast_t idx_z, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_bitwise_binary_op(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_small_uint_fast_t idx_z, + duk_small_uint_fast_t opcode) { /* * Binary bitwise operations use different coercions (ToInt32, ToUint32) * depending on the operation. We coerce the arguments first using @@ -364,20 +376,19 @@ #endif DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); - opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ + opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y)) { i1 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv_x); i2 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv_y); - } - else -#endif /* DUK_USE_FASTINT */ + } else +#endif /* DUK_USE_FASTINT */ { duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); @@ -406,15 +417,15 @@ */ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; - i3 = (duk_int32_t) (((duk_uint32_t) i1) << (u2 & 0x1fUL)); /* E5 Section 11.7.1, steps 7 and 8 */ - i3 = i3 & ((duk_int32_t) 0xffffffffUL); /* Note: left shift, should mask */ + i3 = (duk_int32_t) (((duk_uint32_t) i1) << (u2 & 0x1fUL)); /* E5 Section 11.7.1, steps 7 and 8 */ + i3 = i3 & ((duk_int32_t) 0xffffffffUL); /* Note: left shift, should mask */ break; } case DUK_OP_BASR >> 2: { /* signed shift */ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; - i3 = i1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ + i3 = i1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ break; } case DUK_OP_BLSR >> 2: { @@ -424,7 +435,7 @@ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; /* special result value handling */ - u3 = u1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ + u3 = u1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ #if defined(DUK_USE_FASTINT) fi3 = (duk_int64_t) u3; goto fastint_result_set; @@ -435,7 +446,7 @@ } default: { DUK_UNREACHABLE(); - i3 = 0; /* should not happen */ + i3 = 0; /* should not happen */ break; } } @@ -447,28 +458,31 @@ */ fi3 = (duk_int64_t) i3; - fastint_result_set: +fastint_result_set: tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, fi3); /* side effects */ -#else /* DUK_USE_FASTINT */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, fi3); /* side effects */ +#else /* DUK_USE_FASTINT */ d3 = (duk_double_t) i3; - result_set: - DUK_ASSERT(!DUK_ISNAN(d3)); /* 'd3' is never NaN, so no need to normalize */ - DUK_ASSERT_DOUBLE_IS_NORMALIZED(d3); /* always normalized */ +result_set: + DUK_ASSERT(!DUK_ISNAN(d3)); /* 'd3' is never NaN, so no need to normalize */ + DUK_ASSERT_DOUBLE_IS_NORMALIZED(d3); /* always normalized */ #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, d3); /* would NaN normalize result, but unnecessary */ + duk_push_number(thr, d3); /* would NaN normalize result, but unnecessary */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, d3); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ -#endif /* DUK_USE_FASTINT */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, d3); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_FASTINT */ } /* In-place unary operation. */ -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_unary_op(duk_hthread *thr, duk_uint_fast_t idx_src, duk_uint_fast_t idx_dst, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_unary_op(duk_hthread *thr, + duk_uint_fast_t idx_src, + duk_uint_fast_t idx_dst, + duk_small_uint_fast_t opcode) { /* * Arithmetic operations other than '+' have number-only semantics * and are implemented here. The separate switch-case here means a @@ -514,12 +528,12 @@ } /* fall through if overflow etc */ } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv)) { d1 = DUK_TVAL_GET_NUMBER(tv); } else { - d1 = duk_to_number_tval(thr, tv); /* side effects */ + d1 = duk_to_number_tval(thr, tv); /* side effects */ } if (opcode == DUK_OP_UNP) { @@ -530,13 +544,13 @@ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); #if defined(DUK_USE_FASTINT) tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); - DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF(thr, tv, du.d); /* always 'fast', i.e. inlined */ + DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF(thr, tv, du.d); /* always 'fast', i.e. inlined */ return; #endif } else { DUK_ASSERT(opcode == DUK_OP_UNM); du.d = -d1; - DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); /* mandatory if du.d is a NaN */ + DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); /* mandatory if du.d is a NaN */ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); } @@ -564,19 +578,18 @@ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv)) { i1 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv); - } - else -#endif /* DUK_USE_FASTINT */ + } else +#endif /* DUK_USE_FASTINT */ { duk_push_tval(thr, tv); - i1 = duk_to_int32(thr, -1); /* side effects */ + i1 = duk_to_int32(thr, -1); /* side effects */ duk_pop_unsafe(thr); } /* Result is always fastint compatible. */ i2 = ~i1; tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); - DUK_TVAL_SET_I32_UPDREF(thr, tv, i2); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv, i2); /* side effects */ } DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_logical_not(duk_hthread *thr, duk_uint_fast_t idx_src, duk_uint_fast_t idx_dst) { @@ -598,16 +611,19 @@ * duk_js_toboolean() and then push+replace to the result slot. */ tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_src); - res = duk_js_toboolean(tv); /* does not modify 'tv' */ + res = duk_js_toboolean(tv); /* does not modify 'tv' */ DUK_ASSERT(res == 0 || res == 1); res ^= 1; tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); /* XXX: size optimize: push+replace? */ - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, res); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, res); /* side effects */ } /* XXX: size optimized variant */ -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_reg_helper(duk_hthread *thr, duk_tval *tv_dst, duk_tval *tv_src, duk_small_uint_t op) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_reg_helper(duk_hthread *thr, + duk_tval *tv_dst, + duk_tval *tv_src, + duk_small_uint_t op) { duk_double_t x, y, z; /* Two lowest bits of opcode are used to distinguish @@ -634,13 +650,13 @@ y_fi = x_fi + 1; } - DUK_TVAL_SET_FASTINT(tv_src, y_fi); /* no need for refcount update */ + DUK_TVAL_SET_FASTINT(tv_src, y_fi); /* no need for refcount update */ z_fi = (op & 0x02) ? x_fi : y_fi; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_dst, z_fi); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_dst, z_fi); /* side effects */ return; } - skip_fastint: +skip_fastint: #endif if (DUK_TVAL_IS_NUMBER(tv_src)) { /* Fast path for the case where the register @@ -654,7 +670,7 @@ y = x + 1.0; } - DUK_TVAL_SET_NUMBER(tv_src, y); /* no need for refcount update */ + DUK_TVAL_SET_NUMBER(tv_src, y); /* no need for refcount update */ } else { /* Preserve duk_tval pointer(s) across a potential valstack * resize by converting them into offsets temporarily. @@ -663,8 +679,8 @@ duk_size_t off_dst; off_dst = (duk_size_t) ((duk_uint8_t *) tv_dst - (duk_uint8_t *) thr->valstack_bottom); - bc = (duk_idx_t) (tv_src - thr->valstack_bottom); /* XXX: pass index explicitly? */ - tv_src = NULL; /* no longer referenced */ + bc = (duk_idx_t) (tv_src - thr->valstack_bottom); /* XXX: pass index explicitly? */ + tv_src = NULL; /* no longer referenced */ x = duk_to_number(thr, bc); if (op & 0x01) { @@ -680,10 +696,14 @@ } z = (op & 0x02) ? x : y; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_dst, z); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_dst, z); /* side effects */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_var_helper(duk_hthread *thr, duk_small_uint_t idx_dst, duk_tval *tv_id, duk_small_uint_t op, duk_small_uint_t is_strict) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_var_helper(duk_hthread *thr, + duk_small_uint_t idx_dst, + duk_tval *tv_id, + duk_small_uint_t op, + duk_small_uint_t is_strict) { duk_activation *act; duk_double_t x, y; duk_hstring *name; @@ -709,7 +729,7 @@ name = DUK_TVAL_GET_STRING(tv_id); DUK_ASSERT(name != NULL); act = thr->callstack_curr; - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ /* XXX: Fastint fast path would be useful here. Also fastints * now lose their fastint status in current handling which is @@ -726,22 +746,22 @@ /* ... x this */ if (op & 0x02) { - duk_push_number(thr, y); /* -> ... x this y */ + duk_push_number(thr, y); /* -> ... x this y */ DUK_ASSERT(act == thr->callstack_curr); duk_js_putvar_activation(thr, act, name, DUK_GET_TVAL_NEGIDX(thr, -1), is_strict); - duk_pop_2_unsafe(thr); /* -> ... x */ + duk_pop_2_unsafe(thr); /* -> ... x */ } else { - duk_pop_2_unsafe(thr); /* -> ... */ - duk_push_number(thr, y); /* -> ... y */ + duk_pop_2_unsafe(thr); /* -> ... */ + duk_push_number(thr, y); /* -> ... y */ DUK_ASSERT(act == thr->callstack_curr); duk_js_putvar_activation(thr, act, name, DUK_GET_TVAL_NEGIDX(thr, -1), is_strict); } #if defined(DUK_USE_EXEC_PREFER_SIZE) duk_replace(thr, (duk_idx_t) idx_dst); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ DUK__REPLACE_TO_TVPTR(thr, DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } /* @@ -755,11 +775,11 @@ * handled recursively. */ -#define DUK__LONGJMP_RESTART 0 /* state updated, restart bytecode execution */ -#define DUK__LONGJMP_RETHROW 1 /* exit bytecode executor by rethrowing an error to caller */ +#define DUK__LONGJMP_RESTART 0 /* state updated, restart bytecode execution */ +#define DUK__LONGJMP_RETHROW 1 /* exit bytecode executor by rethrowing an error to caller */ -#define DUK__RETHAND_RESTART 0 /* state updated, restart bytecode execution */ -#define DUK__RETHAND_FINISHED 1 /* exit bytecode execution with return value */ +#define DUK__RETHAND_RESTART 0 /* state updated, restart bytecode execution */ +#define DUK__RETHAND_FINISHED 1 /* exit bytecode execution with return value */ /* XXX: optimize reconfig valstack operations so that resize, clamp, and setting * top are combined into one pass. @@ -788,7 +808,8 @@ thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act->bottom_byteoff); DUK_ASSERT(act->retval_byteoff >= act->bottom_byteoff); - clamp_top = (duk_idx_t) ((act->retval_byteoff - act->bottom_byteoff + sizeof(duk_tval)) / sizeof(duk_tval)); /* +1 = one retval */ + clamp_top = + (duk_idx_t) ((act->retval_byteoff - act->bottom_byteoff + sizeof(duk_tval)) / sizeof(duk_tval)); /* +1 = one retval */ duk_set_top_and_wipe(thr, h_func->nregs, clamp_top); DUK_ASSERT((duk_uint8_t *) thr->valstack_end >= (duk_uint8_t *) thr->valstack + act->reserve_byteoff); @@ -818,7 +839,7 @@ thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act->bottom_byteoff); idx_bottom = (duk_size_t) (thr->valstack_bottom - thr->valstack); DUK_ASSERT(cat->idx_base >= idx_bottom); - clamp_top = (duk_idx_t) (cat->idx_base - idx_bottom + 2); /* +2 = catcher value, catcher lj_type */ + clamp_top = (duk_idx_t) (cat->idx_base - idx_bottom + 2); /* +2 = catcher value, catcher lj_type */ duk_set_top_and_wipe(thr, h_func->nregs, clamp_top); DUK_ASSERT((duk_uint8_t *) thr->valstack_end >= (duk_uint8_t *) thr->valstack + act->reserve_byteoff); @@ -846,7 +867,10 @@ DUK_TVAL_SET_U32_UPDREF_NORZ(thr, tv1, (duk_uint32_t) lj_type); } -DUK_LOCAL void duk__handle_catch_part1(duk_hthread *thr, duk_tval *tv_val_unstable, duk_small_uint_t lj_type, volatile duk_bool_t *out_delayed_catch_setup) { +DUK_LOCAL void duk__handle_catch_part1(duk_hthread *thr, + duk_tval *tv_val_unstable, + duk_small_uint_t lj_type, + volatile duk_bool_t *out_delayed_catch_setup) { duk_activation *act; duk_catcher *cat; @@ -884,7 +908,7 @@ cat = act->cat; DUK_ASSERT(cat != NULL); - act->curr_pc = cat->pc_base + 0; /* +0 = catch */ + act->curr_pc = cat->pc_base + 0; /* +0 = catch */ /* * If the catch block has an automatic catch variable binding, @@ -944,9 +968,7 @@ DUK_ASSERT(act->var_env != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(act) != NULL); - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) new_env) == NULL); @@ -964,7 +986,7 @@ duk_push_hstring(thr, cat->h_varname); DUK_ASSERT(thr->valstack + cat->idx_base < thr->valstack_top); duk_push_tval(thr, thr->valstack + cat->idx_base); - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_W); /* writable, not configurable */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_W); /* writable, not configurable */ /* ... env */ @@ -972,7 +994,7 @@ DUK_ASSERT(act != NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) new_env, act->lex_env); act->lex_env = (duk_hobject *) new_env; - DUK_HOBJECT_INCREF(thr, (duk_hobject *) new_env); /* reachable through activation */ + DUK_HOBJECT_INCREF(thr, (duk_hobject *) new_env); /* reachable through activation */ /* Net refcount change to act->lex_env is 0: incref for new_env's * prototype, decref for act->lex_env overwrite. */ @@ -1014,7 +1036,7 @@ cat = act->cat; DUK_ASSERT(cat != NULL); - act->curr_pc = cat->pc_base + 1; /* +1 = finally */ + act->curr_pc = cat->pc_base + 1; /* +1 = finally */ DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } @@ -1063,18 +1085,21 @@ act_resumer = resumer->callstack_curr; DUK_ASSERT(act_resumer != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(act_resumer) != NULL); - DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(act_resumer))); /* resume caller must be an ECMAScript func */ + DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(act_resumer))); /* resume caller must be an ECMAScript func */ - tv1 = (duk_tval *) (void *) ((duk_uint8_t *) resumer->valstack + act_resumer->retval_byteoff); /* return value from Duktape.Thread.resume() */ - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv_val_unstable); /* side effects */ /* XXX: avoid side effects */ + tv1 = (duk_tval *) (void *) ((duk_uint8_t *) resumer->valstack + + act_resumer->retval_byteoff); /* return value from Duktape.Thread.resume() */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv_val_unstable); /* side effects */ /* XXX: avoid side effects */ duk__reconfig_valstack_ecma_return(resumer); /* caller must change active thread, and set thr->resumer to NULL */ } -#endif /* DUK_USE_COROUTINE_SUPPORT */ +#endif /* DUK_USE_COROUTINE_SUPPORT */ -DUK_LOCAL duk_small_uint_t duk__handle_longjmp(duk_hthread *thr, duk_activation *entry_act, volatile duk_bool_t *out_delayed_catch_setup) { +DUK_LOCAL duk_small_uint_t duk__handle_longjmp(duk_hthread *thr, + duk_activation *entry_act, + volatile duk_bool_t *out_delayed_catch_setup) { duk_small_uint_t retval = DUK__LONGJMP_RESTART; DUK_ASSERT(thr != NULL); @@ -1095,17 +1120,16 @@ * - 'thr' must reflect the "throwing" thread */ - check_longjmp: +check_longjmp: DUK_DD(DUK_DDPRINT("handling longjmp: type=%ld, value1=%!T, value2=%!T, iserror=%ld, top=%ld", (long) thr->heap->lj.type, (duk_tval *) &thr->heap->lj.value1, (duk_tval *) &thr->heap->lj.value2, (long) thr->heap->lj.iserror, - (long) duk_get_top(thr))); + (long) duk_get_top(thr))); switch (thr->heap->lj.type) { - #if defined(DUK_USE_COROUTINE_SUPPORT) case DUK_LJ_TYPE_RESUME: { /* @@ -1119,15 +1143,15 @@ /* duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met */ - DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged by Duktape.Thread.resume() */ - DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged by Duktape.Thread.resume() */ + DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->callstack_curr))->func == duk_bi_thread_resume); - tv = &thr->heap->lj.value2; /* resumee */ + tv = &thr->heap->lj.value2; /* resumee */ DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv)); DUK_ASSERT(DUK_TVAL_GET_OBJECT(tv) != NULL); DUK_ASSERT(DUK_HOBJECT_IS_THREAD(DUK_TVAL_GET_OBJECT(tv))); @@ -1136,15 +1160,15 @@ DUK_ASSERT(resumee != NULL); DUK_ASSERT(resumee->resumer == NULL); DUK_ASSERT(resumee->state == DUK_HTHREAD_STATE_INACTIVE || - resumee->state == DUK_HTHREAD_STATE_YIELDED); /* checked by Duktape.Thread.resume() */ + resumee->state == DUK_HTHREAD_STATE_YIELDED); /* checked by Duktape.Thread.resume() */ DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_YIELDED || - resumee->callstack_top >= 2); /* YIELDED: ECMAScript activation + Duktape.Thread.yield() activation */ + resumee->callstack_top >= 2); /* YIELDED: ECMAScript activation + Duktape.Thread.yield() activation */ DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_YIELDED || (DUK_ACT_GET_FUNC(resumee->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(resumee->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(resumee->callstack_curr))->func == duk_bi_thread_yield)); DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_INACTIVE || - resumee->callstack_top == 0); /* INACTIVE: no activation, single function value on valstack */ + resumee->callstack_top == 0); /* INACTIVE: no activation, single function value on valstack */ if (thr->heap->lj.iserror) { /* @@ -1170,7 +1194,7 @@ /* thr->heap->lj.value1 is already the value to throw */ /* thr->heap->lj.value2 is 'thread', will be wiped out at the end */ - DUK_ASSERT(thr->heap->lj.iserror); /* already set */ + DUK_ASSERT(thr->heap->lj.iserror); /* already set */ DUK_DD(DUK_DDPRINT("-> resume with an error, converted to a throw in the resumee, propagate")); goto check_longjmp; @@ -1183,17 +1207,18 @@ duk_activation *act_resumee; DUK_ASSERT(resumee->callstack_top >= 2); - act_resumee = resumee->callstack_curr; /* Duktape.Thread.yield() */ + act_resumee = resumee->callstack_curr; /* Duktape.Thread.yield() */ DUK_ASSERT(act_resumee != NULL); - act_resumee = act_resumee->parent; /* ECMAScript call site for yield() */ + act_resumee = act_resumee->parent; /* ECMAScript call site for yield() */ DUK_ASSERT(act_resumee != NULL); - tv = (duk_tval *) (void *) ((duk_uint8_t *) resumee->valstack + act_resumee->retval_byteoff); /* return value from Duktape.Thread.yield() */ + tv = (duk_tval *) (void *) ((duk_uint8_t *) resumee->valstack + + act_resumee->retval_byteoff); /* return value from Duktape.Thread.yield() */ DUK_ASSERT(tv >= resumee->valstack && tv < resumee->valstack_top); tv2 = &thr->heap->lj.value1; - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv2); /* side effects */ /* XXX: avoid side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv2); /* side effects */ /* XXX: avoid side effects */ - duk_hthread_activation_unwind_norz(resumee); /* unwind to 'yield' caller */ + duk_hthread_activation_unwind_norz(resumee); /* unwind to 'yield' caller */ /* no need to unwind catch stack */ duk__reconfig_valstack_ecma_return(resumee); @@ -1223,7 +1248,7 @@ /* resumee: ... initial_func undefined(= this) resume_value */ - call_flags = DUK_CALL_FLAG_ALLOW_ECMATOECMA; /* not tailcall, ecma-to-ecma (assumed to succeed) */ + call_flags = DUK_CALL_FLAG_ALLOW_ECMATOECMA; /* not tailcall, ecma-to-ecma (assumed to succeed) */ setup_rc = duk_handle_call_unprotected_nargs(resumee, 1 /*nargs*/, call_flags); if (setup_rc == 0) { @@ -1250,7 +1275,7 @@ goto wipe_and_return; } DUK_UNREACHABLE(); - break; /* never here */ + break; /* never here */ } case DUK_LJ_TYPE_YIELD: { @@ -1268,31 +1293,31 @@ /* duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met */ -#if 0 /* entry_thread not available for assert */ +#if 0 /* entry_thread not available for assert */ DUK_ASSERT(thr != entry_thread); /* Duktape.Thread.yield() should prevent */ #endif - DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged from Duktape.Thread.yield() */ - DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.yield() activation */ + DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged from Duktape.Thread.yield() */ + DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.yield() activation */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->callstack_curr))->func == duk_bi_thread_yield); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* an ECMAScript function */ resumer = thr->resumer; DUK_ASSERT(resumer != NULL); - DUK_ASSERT(resumer->state == DUK_HTHREAD_STATE_RESUMED); /* written by a previous RESUME handling */ - DUK_ASSERT(resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(resumer->state == DUK_HTHREAD_STATE_RESUMED); /* written by a previous RESUME handling */ + DUK_ASSERT(resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(resumer->callstack_curr != NULL); DUK_ASSERT(resumer->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(resumer->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(resumer->callstack_curr))->func == duk_bi_thread_resume); DUK_ASSERT(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent))); /* an ECMAScript function */ if (thr->heap->lj.iserror) { thr->state = DUK_HTHREAD_STATE_YIELDED; @@ -1304,7 +1329,7 @@ thr->heap->lj.type = DUK_LJ_TYPE_THROW; /* lj.value1 is already set */ - DUK_ASSERT(thr->heap->lj.iserror); /* already set */ + DUK_ASSERT(thr->heap->lj.iserror); /* already set */ DUK_DD(DUK_DDPRINT("-> yield an error, converted to a throw in the resumer, propagate")); goto check_longjmp; @@ -1330,9 +1355,9 @@ goto wipe_and_return; } DUK_UNREACHABLE(); - break; /* never here */ + break; /* never here */ } -#endif /* DUK_USE_COROUTINE_SUPPORT */ +#endif /* DUK_USE_COROUTINE_SUPPORT */ case DUK_LJ_TYPE_THROW: { /* @@ -1373,11 +1398,13 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF); DUK_DDD(DUK_DDDPRINT("before catch part 1: thr=%p, act=%p, cat=%p", - (void *) thr, (void *) act, (void *) act->cat)); + (void *) thr, + (void *) act, + (void *) act->cat)); duk__handle_catch_part1(thr, &thr->heap->lj.value1, DUK_LJ_TYPE_THROW, - out_delayed_catch_setup); + out_delayed_catch_setup); DUK_DD(DUK_DDPRINT("-> throw caught by a 'catch' clause, restart execution")); retval = DUK__LONGJMP_RESTART; @@ -1388,9 +1415,7 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF); DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); - duk__handle_finally(thr, - &thr->heap->lj.value1, - DUK_LJ_TYPE_THROW); + duk__handle_finally(thr, &thr->heap->lj.value1, DUK_LJ_TYPE_THROW); DUK_DD(DUK_DDPRINT("-> throw caught by a 'finally' clause, restart execution")); retval = DUK__LONGJMP_RESTART; @@ -1420,20 +1445,21 @@ */ DUK_ASSERT(thr->resumer != NULL); - DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->resumer->callstack_curr != NULL); DUK_ASSERT(thr->resumer->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_ASSERT( + DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ resumer = thr->resumer; /* reset longjmp */ - DUK_ASSERT(thr->heap->lj.type == DUK_LJ_TYPE_THROW); /* already set */ + DUK_ASSERT(thr->heap->lj.type == DUK_LJ_TYPE_THROW); /* already set */ /* lj.value1 already set */ - duk_hthread_terminate(thr); /* updates thread state, minimizes its allocations */ + duk_hthread_terminate(thr); /* updates thread state, minimizes its allocations */ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_TERMINATED); thr->resumer = NULL; @@ -1444,7 +1470,7 @@ goto check_longjmp; } - case DUK_LJ_TYPE_BREAK: /* pseudotypes, not used in actual longjmps */ + case DUK_LJ_TYPE_BREAK: /* pseudotypes, not used in actual longjmps */ case DUK_LJ_TYPE_CONTINUE: case DUK_LJ_TYPE_RETURN: case DUK_LJ_TYPE_NORMAL: @@ -1454,25 +1480,24 @@ goto convert_to_internal_error; } - } /* end switch */ + } /* end switch */ DUK_UNREACHABLE(); - wipe_and_return: - DUK_DD(DUK_DDPRINT("handling longjmp done, wipe-and-return, top=%ld", - (long) duk_get_top(thr))); +wipe_and_return: + DUK_DD(DUK_DDPRINT("handling longjmp done, wipe-and-return, top=%ld", (long) duk_get_top(thr))); thr->heap->lj.type = DUK_LJ_TYPE_UNKNOWN; thr->heap->lj.iserror = 0; - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value1); /* side effects */ - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value2); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value2); /* side effects */ DUK_GC_TORTURE(thr->heap); - just_return: +just_return: return retval; - convert_to_internal_error: +convert_to_internal_error: /* This could also be thrown internally (set the error, goto check_longjmp), * but it's better for internal errors to bubble outwards so that we won't * infinite loop in this catchpoint. @@ -1518,8 +1543,7 @@ /* XXX: bit mask test; FINALLY <-> TCF, single bit mask would suffice? */ - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && - DUK_CAT_HAS_FINALLY_ENABLED(cat)) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && DUK_CAT_HAS_FINALLY_ENABLED(cat)) { duk_tval tv_tmp; DUK_TVAL_SET_U32(&tv_tmp, (duk_uint32_t) label_id); @@ -1528,11 +1552,11 @@ DUK_DD(DUK_DDPRINT("-> break/continue caught by 'finally', restart execution")); return; } - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_LABEL && - (duk_uint_t) DUK_CAT_GET_LABEL(cat) == label_id) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_LABEL && (duk_uint_t) DUK_CAT_GET_LABEL(cat) == label_id) { duk__handle_label(thr, lj_type); - DUK_DD(DUK_DDPRINT("-> break/continue caught by a label catcher (in the same function), restart execution")); + DUK_DD( + DUK_DDPRINT("-> break/continue caught by a label catcher (in the same function), restart execution")); return; } @@ -1540,7 +1564,8 @@ } /* Should never happen, but be robust. */ - DUK_D(DUK_DPRINT("-> break/continue not caught by anything in the current function (should never happen), throw internal error")); + DUK_D(DUK_DPRINT( + "-> break/continue not caught by anything in the current function (should never happen), throw internal error")); DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); } @@ -1564,7 +1589,7 @@ DUK_ASSERT(entry_act != NULL); DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); tv1 = thr->valstack_top - 1; - DUK_TVAL_CHKFAST_INPLACE_FAST(tv1); /* fastint downgrade check for return values */ + DUK_TVAL_CHKFAST_INPLACE_FAST(tv1); /* fastint downgrade check for return values */ /* * Four possible outcomes: @@ -1599,8 +1624,7 @@ break; } - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && - DUK_CAT_HAS_FINALLY_ENABLED(cat)) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && DUK_CAT_HAS_FINALLY_ENABLED(cat)) { DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); duk__handle_finally(thr, thr->valstack_top - 1, DUK_LJ_TYPE_RETURN); @@ -1631,22 +1655,24 @@ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* must be ECMAScript */ + DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* must be ECMAScript */ #if defined(DUK_USE_ES6_PROXY) if (thr->callstack_curr->flags & (DUK_ACT_FLAG_CONSTRUCT | DUK_ACT_FLAG_CONSTRUCT_PROXY)) { - duk_call_construct_postprocess(thr, thr->callstack_curr->flags & DUK_ACT_FLAG_CONSTRUCT_PROXY); /* side effects */ + duk_call_construct_postprocess(thr, + thr->callstack_curr->flags & + DUK_ACT_FLAG_CONSTRUCT_PROXY); /* side effects */ } #else if (thr->callstack_curr->flags & DUK_ACT_FLAG_CONSTRUCT) { - duk_call_construct_postprocess(thr, 0); /* side effects */ + duk_call_construct_postprocess(thr, 0); /* side effects */ } #endif tv1 = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + thr->callstack_curr->parent->retval_byteoff); DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); tv2 = thr->valstack_top - 1; - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ /* Catch stack unwind happens inline in callstack unwind. */ duk_hthread_activation_unwind_norz(thr); @@ -1661,14 +1687,15 @@ DUK_DD(DUK_DDPRINT("no calling activation, thread finishes (similar to yield)")); DUK_ASSERT(thr->resumer != NULL); - DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->resumer->callstack_curr != NULL); DUK_ASSERT(thr->resumer->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr) != NULL && - DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr)) && - ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->resumer->callstack_curr))->func == duk_bi_thread_resume); /* Duktape.Thread.resume() */ + DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr)) && + ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->resumer->callstack_curr))->func == + duk_bi_thread_resume); /* Duktape.Thread.resume() */ DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); DUK_ASSERT(thr->resumer->state == DUK_HTHREAD_STATE_RESUMED); @@ -1690,11 +1717,11 @@ */ DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); - duk_hthread_activation_unwind_norz(resumer); /* May remove last reference to 'thr', but is NORZ. */ - duk_push_tval(resumer, thr->valstack_top - 1); /* Capture return value, side effect free. */ - duk_push_hthread(resumer, thr); /* Make 'thr' reachable again, before side effects. */ + duk_hthread_activation_unwind_norz(resumer); /* May remove last reference to 'thr', but is NORZ. */ + duk_push_tval(resumer, thr->valstack_top - 1); /* Capture return value, side effect free. */ + duk_push_hthread(resumer, thr); /* Make 'thr' reachable again, before side effects. */ - duk_hthread_terminate(thr); /* Updates thread state, minimizes its allocations. */ + duk_hthread_terminate(thr); /* Updates thread state, minimizes its allocations. */ thr->resumer = NULL; DUK_HTHREAD_DECREF(thr, resumer); DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_TERMINATED); @@ -1704,7 +1731,7 @@ DUK_ASSERT(resumer->valstack_top - 2 >= resumer->valstack_bottom); duk__handle_yield(thr, resumer, resumer->valstack_top - 2); - thr = NULL; /* 'thr' invalidated by call */ + thr = NULL; /* 'thr' invalidated by call */ #if 0 thr = resumer; /* not needed */ @@ -1746,8 +1773,8 @@ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK__INT_NOACTION 0 /* no specific action, resume normal execution */ -#define DUK__INT_RESTART 1 /* must "goto restart_execution", e.g. breakpoints changed */ +#define DUK__INT_NOACTION 0 /* no specific action, resume normal execution */ +#define DUK__INT_RESTART 1 /* must "goto restart_execution", e.g. breakpoints changed */ #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_LOCAL void duk__interrupt_handle_debugger(duk_hthread *thr, duk_bool_t *out_immediate, duk_small_uint_t *out_interrupt_retval) { @@ -1758,7 +1785,7 @@ duk_bool_t process_messages; duk_bool_t processed_messages = 0; - DUK_ASSERT(thr->heap->dbg_processing == 0); /* don't re-enter e.g. during Eval */ + DUK_ASSERT(thr->heap->dbg_processing == 0); /* don't re-enter e.g. during Eval */ act = thr->callstack_curr; DUK_ASSERT(act != NULL); @@ -1781,17 +1808,14 @@ * Breakpoint and step state checks */ - if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || - (thr->heap->dbg_pause_act == thr->callstack_curr)) { + if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || (thr->heap->dbg_pause_act == thr->callstack_curr)) { line = duk_debug_curr_line(thr); if (act->prev_line != line) { /* Stepped? Step out is handled by callstack unwind. */ if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && - (thr->heap->dbg_pause_act == thr->callstack_curr) && - (line != thr->heap->dbg_pause_startline)) { - DUK_D(DUK_DPRINT("PAUSE TRIGGERED by line change, at line %ld", - (long) line)); + (thr->heap->dbg_pause_act == thr->callstack_curr) && (line != thr->heap->dbg_pause_startline)) { + DUK_D(DUK_DPRINT("PAUSE TRIGGERED by line change, at line %ld", (long) line)); duk_debug_set_paused(thr->heap); } @@ -1817,7 +1841,8 @@ DUK_ASSERT(bp->filename != NULL); if (act->prev_line != bp->line && line == bp->line) { DUK_D(DUK_DPRINT("PAUSE TRIGGERED by breakpoint at %!O:%ld", - (duk_heaphdr *) bp->filename, (long) bp->line)); + (duk_heaphdr *) bp->filename, + (long) bp->line)); duk_debug_set_paused(thr->heap); } } @@ -1910,11 +1935,10 @@ if (duk_debug_is_attached(thr->heap)) { DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); - if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || - (thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_ONE_OPCODE) || + if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || (thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_ONE_OPCODE) || ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && thr->heap->dbg_pause_act == thr->callstack_curr) || - DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap)) { + DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap)) { *out_immediate = 1; } @@ -1936,7 +1960,7 @@ DUK_D(DUK_DPRINT("debugger became detached, resume normal execution")); } } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ DUK_LOCAL DUK_EXEC_NOINLINE_PERF DUK_COLD duk_small_uint_t duk__executor_interrupt(duk_hthread *thr) { duk_int_t ctr; @@ -1953,8 +1977,10 @@ thr->heap->inst_count_interrupt += thr->interrupt_init; DUK_DD(DUK_DDPRINT("execution interrupt, counter=%ld, init=%ld, " "instruction counts: executor=%ld, interrupt=%ld", - (long) thr->interrupt_counter, (long) thr->interrupt_init, - (long) thr->heap->inst_count_exec, (long) thr->heap->inst_count_interrupt)); + (long) thr->interrupt_counter, + (long) thr->interrupt_init, + (long) thr->heap->inst_count_exec, + (long) thr->heap->inst_count_interrupt)); #endif retval = DUK__INT_NOACTION; @@ -2016,18 +2042,17 @@ DUK_ERROR_RANGE(thr, "execution timeout"); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_EXEC_TIMEOUT_CHECK */ +#endif /* DUK_USE_EXEC_TIMEOUT_CHECK */ #if defined(DUK_USE_DEBUGGER_SUPPORT) - if (!thr->heap->dbg_processing && - (thr->heap->dbg_read_cb != NULL || thr->heap->dbg_detaching)) { + if (!thr->heap->dbg_processing && (thr->heap->dbg_read_cb != NULL || thr->heap->dbg_detaching)) { /* Avoid recursive re-entry; enter when we're attached or * detaching (to finish off the pending detach). */ duk__interrupt_handle_debugger(thr, &immediate, &retval); DUK_ASSERT(act == thr->callstack_curr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Update the interrupt counter @@ -2050,7 +2075,7 @@ return retval; } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ /* * Debugger handling for executor restart @@ -2118,8 +2143,7 @@ duk_hcompfunc *inner_fun; duk_bool_t bp_match; - if (bp->filename == filename && - bp->line >= fun->start_line && bp->line <= fun->end_line) { + if (bp->filename == filename && bp->line >= fun->start_line && bp->line <= fun->end_line) { bp_match = 1; DUK_DD(DUK_DDPRINT("breakpoint filename and line match: " "%s:%ld vs. %s (line %ld vs. %ld-%ld)", @@ -2156,13 +2180,12 @@ } } - *bp_active = NULL; /* terminate */ + *bp_active = NULL; /* terminate */ DUK_DD(DUK_DDPRINT("ACTIVE BREAKPOINTS: %ld", (long) (bp_active - thr->heap->dbg_breakpoints_active))); /* Force pause if we were doing "step into" in another activation. */ - if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_FUNC_ENTRY) && - thr->heap->dbg_pause_act != thr->callstack_curr) { + if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_FUNC_ENTRY) && thr->heap->dbg_pause_act != thr->callstack_curr) { DUK_D(DUK_DPRINT("PAUSE TRIGGERED by function entry")); duk_debug_set_paused(thr->heap); } @@ -2170,10 +2193,8 @@ /* Force interrupt right away if we're paused or in "checked mode". * Step out is handled by callstack unwind. */ - if ((act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE) || - DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || - ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && - thr->heap->dbg_pause_act == thr->callstack_curr)) { + if ((act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE) || DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || + ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && thr->heap->dbg_pause_act == thr->callstack_curr)) { /* We'll need to interrupt early so recompute the init * counter to reflect the number of bytecode instructions * executed so that step counts for e.g. debugger rate @@ -2184,7 +2205,7 @@ thr->interrupt_counter = 0; } } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Opcode handlers for opcodes with a lot of code and which are relatively @@ -2208,18 +2229,14 @@ /* This could be made more optimal by accessing internals directly. */ idx = (duk_uint_fast_t) DUK_DEC_BC(ins); - duk_dup(thr, (duk_idx_t) (idx + 0)); /* key */ - duk_dup(thr, (duk_idx_t) (idx + 1)); /* getter/setter */ + duk_dup(thr, (duk_idx_t) (idx + 0)); /* key */ + duk_dup(thr, (duk_idx_t) (idx + 1)); /* getter/setter */ if (is_set) { - defprop_flags = DUK_DEFPROP_HAVE_SETTER | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE; + defprop_flags = + DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE; } else { - defprop_flags = DUK_DEFPROP_HAVE_GETTER | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE; + defprop_flags = + DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE; } duk_def_prop(thr, (duk_idx_t) DUK_DEC_A(ins), defprop_flags); } @@ -2284,7 +2301,7 @@ * error handling, so there's no side effect problem even if the * error value has a finalizer. */ - duk_dup(thr, (duk_idx_t) bc); /* Stabilize value. */ + duk_dup(thr, (duk_idx_t) bc); /* Stabilize value. */ duk_to_undefined(thr, (duk_idx_t) bc); duk_to_undefined(thr, (duk_idx_t) (bc + 1)); @@ -2299,7 +2316,7 @@ cat->flags = DUK_CAT_TYPE_TCF; cat->h_varname = NULL; - cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ + cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ cat->idx_base = (duk_size_t) (thr->valstack_bottom - thr->valstack) + bc; act = thr->callstack_curr; @@ -2338,7 +2355,7 @@ duk_js_init_activation_environment_records_delayed(thr, act); DUK_ASSERT(act == thr->callstack_curr); - DUK_UNREF(act); /* 'act' is no longer accessed, scanbuild fix */ + DUK_UNREF(act); /* 'act' is no longer accessed, scanbuild fix */ } DUK_ASSERT(act->lex_env != NULL); DUK_ASSERT(act->var_env != NULL); @@ -2351,12 +2368,10 @@ * so avoid side effects very carefully until it is * referenced. */ - env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + env = duk_hobjenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(env != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); - env->target = target; /* always provideThis=true */ + env->target = target; /* always provideThis=true */ DUK_HOBJECT_INCREF(thr, target); env->has_this = 1; DUK_HOBJENV_ASSERT_VALID(env); @@ -2366,7 +2381,7 @@ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); DUK_ASSERT(act->lex_env != NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) env, act->lex_env); - act->lex_env = (duk_hobject *) env; /* Now reachable. */ + act->lex_env = (duk_hobject *) env; /* Now reachable. */ DUK_HOBJECT_INCREF(thr, (duk_hobject *) env); /* Net refcount change to act->lex_env is 0: incref for env's * prototype, decref for act->lex_env overwrite. @@ -2375,7 +2390,7 @@ /* Set catcher lex_env active (affects unwind) * only when the whole setup is complete. */ - cat = act->cat; /* XXX: better to relookup? not mandatory because 'cat' is stable */ + cat = act->cat; /* XXX: better to relookup? not mandatory because 'cat' is stable */ cat->flags |= DUK_CAT_FLAG_LEXENV_ACTIVE; } else { ; @@ -2384,7 +2399,9 @@ DUK_DDD(DUK_DDDPRINT("TRYCATCH catcher: flags=0x%08lx, pc_base=%ld, " "idx_base=%ld, h_varname=%!O", (unsigned long) cat->flags, - (long) cat->pc_base, (long) cat->idx_base, (duk_heaphdr *) cat->h_varname)); + (long) cat->pc_base, + (long) cat->idx_base, + (duk_heaphdr *) cat->h_varname)); duk_pop_unsafe(thr); } @@ -2414,23 +2431,24 @@ tv1 = thr->valstack + cat->idx_base; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ tv1 = NULL; tv1 = thr->valstack + cat->idx_base + 1; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ tv1 = NULL; DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } else { - DUK_DDD(DUK_DDDPRINT("ENDTRY: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); + DUK_DDD( + DUK_DDDPRINT("ENDTRY: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); - duk_hthread_catcher_unwind_norz(thr, act); /* lexenv may be set for 'with' binding */ + duk_hthread_catcher_unwind_norz(thr, act); /* lexenv may be set for 'with' binding */ /* no need to unwind callstack */ } - return pc_base + 1; /* new curr_pc value */ + return pc_base + 1; /* new curr_pc value */ } DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_instr_t *duk__handle_op_endcatch(duk_hthread *thr, duk_uint_fast32_t ins) { @@ -2446,7 +2464,7 @@ DUK_ASSERT(act != NULL); cat = act->cat; DUK_ASSERT(cat != NULL); - DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); /* cleared before entering catch part */ + DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); /* cleared before entering catch part */ if (DUK_CAT_HAS_LEXENV_ACTIVE(cat)) { duk_hobject *prev_env; @@ -2462,7 +2480,7 @@ act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, prev_env); DUK_CAT_CLEAR_LEXENV_ACTIVE(cat); DUK_HOBJECT_INCREF(thr, act->lex_env); - DUK_HOBJECT_DECREF(thr, prev_env); /* side effects */ + DUK_HOBJECT_DECREF(thr, prev_env); /* side effects */ DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); @@ -2475,26 +2493,29 @@ tv1 = thr->valstack + cat->idx_base; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ tv1 = NULL; tv1 = thr->valstack + cat->idx_base + 1; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ tv1 = NULL; DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } else { - DUK_DDD(DUK_DDDPRINT("ENDCATCH: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); + DUK_DDD( + DUK_DDDPRINT("ENDCATCH: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); duk_hthread_catcher_unwind_norz(thr, act); /* no need to unwind callstack */ } - return pc_base + 1; /* new curr_pc value */ + return pc_base + 1; /* new curr_pc value */ } -DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_small_uint_t duk__handle_op_endfin(duk_hthread *thr, duk_uint_fast32_t ins, duk_activation *entry_act) { +DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_small_uint_t duk__handle_op_endfin(duk_hthread *thr, + duk_uint_fast32_t ins, + duk_activation *entry_act) { duk_activation *act; duk_tval *tv1; duk_uint_t reg_catch; @@ -2516,7 +2537,7 @@ (duk_tval *) (thr->valstack_bottom + reg_catch + 0), (duk_tval *) (thr->valstack_bottom + reg_catch + 1))); - tv1 = thr->valstack_bottom + reg_catch + 1; /* type */ + tv1 = thr->valstack_bottom + reg_catch + 1; /* type */ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv1)); #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv1)); @@ -2525,7 +2546,7 @@ cont_type = (duk_small_uint_t) DUK_TVAL_GET_NUMBER(tv1); #endif - tv1--; /* value */ + tv1--; /* value */ switch (cont_type) { case DUK_LJ_TYPE_NORMAL: { @@ -2534,11 +2555,12 @@ duk_hthread_catcher_unwind_norz(thr, act); /* no need to unwind callstack */ - return 0; /* restart execution */ + return 0; /* restart execution */ } case DUK_LJ_TYPE_RETURN: { DUK_DDD(DUK_DDDPRINT("ENDFIN: finally part finishing with 'return' complation -> dismantle " - "catcher, handle return, lj.value1=%!T", tv1)); + "catcher, handle return, lj.value1=%!T", + tv1)); /* Not necessary to unwind catch stack: return handling will * do it. The finally flag of 'cat' is no longer set. The @@ -2548,12 +2570,12 @@ duk_push_tval(thr, tv1); ret_result = duk__handle_return(thr, entry_act); if (ret_result == DUK__RETHAND_RESTART) { - return 0; /* restart execution */ + return 0; /* restart execution */ } DUK_ASSERT(ret_result == DUK__RETHAND_FINISHED); DUK_DDD(DUK_DDDPRINT("exiting executor after ENDFIN and RETURN (pseudo) longjmp type")); - return 1; /* exit executor */ + return 1; /* exit executor */ } case DUK_LJ_TYPE_BREAK: case DUK_LJ_TYPE_CONTINUE: { @@ -2575,7 +2597,7 @@ #endif lj_type = cont_type; duk__handle_break_or_continue(thr, label_id, lj_type); - return 0; /* restart execution */ + return 0; /* restart execution */ } default: { DUK_DDD(DUK_DDDPRINT("ENDFIN: finally part finishing with abrupt completion, lj_type=%ld -> " @@ -2585,7 +2607,7 @@ duk_err_setup_ljstate1(thr, (duk_small_uint_t) cont_type, tv1); /* No debugger Throw notify check on purpose (rethrow). */ - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ duk_err_longjmp(thr); DUK_UNREACHABLE(); } @@ -2618,7 +2640,7 @@ } else { duk_dup(thr, (duk_idx_t) c); duk_to_object(thr, -1); - duk_hobject_enumerator_create(thr, 0 /*enum_flags*/); /* ... val --> ... enum */ + duk_hobject_enumerator_create(thr, 0 /*enum_flags*/); /* ... val --> ... enum */ duk_replace(thr, (duk_idx_t) b); } } @@ -2650,13 +2672,12 @@ duk_dup(thr, (duk_idx_t) c); if (duk_hobject_enumerator_next(thr, 0 /*get_value*/)) { /* ... enum -> ... next_key */ - DUK_DDD(DUK_DDDPRINT("enum active, next key is %!T, skip jump slot ", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("enum active, next key is %!T, skip jump slot ", (duk_tval *) duk_get_tval(thr, -1))); pc_skip = 1; } else { /* ... enum -> ... */ DUK_DDD(DUK_DDDPRINT("enum finished, execute jump slot")); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } duk_replace(thr, (duk_idx_t) b); @@ -2676,7 +2697,7 @@ DUK_LOCAL duk_bool_t duk__executor_handle_call(duk_hthread *thr, duk_idx_t idx, duk_idx_t nargs, duk_small_uint_t call_flags) { duk_bool_t rc; - duk_set_top_unsafe(thr, (duk_idx_t) (idx + nargs + 2)); /* ... func this arg1 ... argN */ + duk_set_top_unsafe(thr, (duk_idx_t) (idx + nargs + 2)); /* ... func this arg1 ... argN */ /* Attempt an Ecma-to-Ecma call setup. If the call * target is (directly or indirectly) Reflect.construct(), @@ -2730,22 +2751,22 @@ * difference and the best option is architecture dependent. */ #if defined(DUK_USE_EXEC_FUN_LOCAL) -#define DUK__FUN() fun +#define DUK__FUN() fun #else -#define DUK__FUN() ((duk_hcompfunc *) DUK_ACT_GET_FUNC((thr)->callstack_curr)) +#define DUK__FUN() ((duk_hcompfunc *) DUK_ACT_GET_FUNC((thr)->callstack_curr)) #endif /* Strict flag. */ -#define DUK__STRICT() ((duk_small_uint_t) DUK_HOBJECT_HAS_STRICT((duk_hobject *) DUK__FUN())) +#define DUK__STRICT() ((duk_small_uint_t) DUK_HOBJECT_HAS_STRICT((duk_hobject *) DUK__FUN())) /* Reg/const access macros: these are very footprint and performance sensitive * so modify with care. Arguments are sometimes evaluated multiple times which * is not ideal. */ -#define DUK__REG(x) (*(thr->valstack_bottom + (x))) -#define DUK__REGP(x) (thr->valstack_bottom + (x)) -#define DUK__CONST(x) (*(consts + (x))) -#define DUK__CONSTP(x) (consts + (x)) +#define DUK__REG(x) (*(thr->valstack_bottom + (x))) +#define DUK__REGP(x) (thr->valstack_bottom + (x)) +#define DUK__CONST(x) (*(consts + (x))) +#define DUK__CONSTP(x) (consts + (x)) /* Reg/const access macros which take the 32-bit instruction and avoid an * explicit field decoding step by using shifts and masks. These must be @@ -2754,68 +2775,74 @@ * instead of a duk_tval offset which needs further shifting (which is an * issue on some, but not all, CPUs). */ -#define DUK__RCBIT_B DUK_BC_REGCONST_B -#define DUK__RCBIT_C DUK_BC_REGCONST_C +#define DUK__RCBIT_B DUK_BC_REGCONST_B +#define DUK__RCBIT_C DUK_BC_REGCONST_C #if defined(DUK_USE_EXEC_REGCONST_OPTIMIZE) #if defined(DUK_USE_PACKED_TVAL) -#define DUK__TVAL_SHIFT 3 /* sizeof(duk_tval) == 8 */ +#define DUK__TVAL_SHIFT 3 /* sizeof(duk_tval) == 8 */ #else -#define DUK__TVAL_SHIFT 4 /* sizeof(duk_tval) == 16; not always the case so also asserted for */ +#define DUK__TVAL_SHIFT 4 /* sizeof(duk_tval) == 16; not always the case so also asserted for */ #endif -#define DUK__SHIFT_A (DUK_BC_SHIFT_A - DUK__TVAL_SHIFT) -#define DUK__SHIFT_B (DUK_BC_SHIFT_B - DUK__TVAL_SHIFT) -#define DUK__SHIFT_C (DUK_BC_SHIFT_C - DUK__TVAL_SHIFT) -#define DUK__SHIFT_BC (DUK_BC_SHIFT_BC - DUK__TVAL_SHIFT) -#define DUK__MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK__TVAL_SHIFT) -#define DUK__MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK__TVAL_SHIFT) -#define DUK__MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK__TVAL_SHIFT) -#define DUK__MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK__TVAL_SHIFT) -#define DUK__BYTEOFF_A(ins) (((ins) >> DUK__SHIFT_A) & DUK__MASK_A) -#define DUK__BYTEOFF_B(ins) (((ins) >> DUK__SHIFT_B) & DUK__MASK_B) -#define DUK__BYTEOFF_C(ins) (((ins) >> DUK__SHIFT_C) & DUK__MASK_C) -#define DUK__BYTEOFF_BC(ins) (((ins) >> DUK__SHIFT_BC) & DUK__MASK_BC) - -#define DUK__REGP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_A((ins)))) -#define DUK__REGP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_B((ins)))) -#define DUK__REGP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_C((ins)))) -#define DUK__REGP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_BC((ins)))) -#define DUK__CONSTP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_A((ins)))) -#define DUK__CONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_B((ins)))) -#define DUK__CONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_C((ins)))) -#define DUK__CONSTP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_BC((ins)))) -#define DUK__REGCONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) & DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_B((ins)))) -#define DUK__REGCONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) & DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_C((ins)))) -#else /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#define DUK__SHIFT_A (DUK_BC_SHIFT_A - DUK__TVAL_SHIFT) +#define DUK__SHIFT_B (DUK_BC_SHIFT_B - DUK__TVAL_SHIFT) +#define DUK__SHIFT_C (DUK_BC_SHIFT_C - DUK__TVAL_SHIFT) +#define DUK__SHIFT_BC (DUK_BC_SHIFT_BC - DUK__TVAL_SHIFT) +#define DUK__MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK__TVAL_SHIFT) +#define DUK__MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK__TVAL_SHIFT) +#define DUK__MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK__TVAL_SHIFT) +#define DUK__MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK__TVAL_SHIFT) +#define DUK__BYTEOFF_A(ins) (((ins) >> DUK__SHIFT_A) & DUK__MASK_A) +#define DUK__BYTEOFF_B(ins) (((ins) >> DUK__SHIFT_B) & DUK__MASK_B) +#define DUK__BYTEOFF_C(ins) (((ins) >> DUK__SHIFT_C) & DUK__MASK_C) +#define DUK__BYTEOFF_BC(ins) (((ins) >> DUK__SHIFT_BC) & DUK__MASK_BC) + +#define DUK__REGP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_A((ins)))) +#define DUK__REGP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_B((ins)))) +#define DUK__REGP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_C((ins)))) +#define DUK__REGP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_BC((ins)))) +#define DUK__CONSTP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_A((ins)))) +#define DUK__CONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_B((ins)))) +#define DUK__CONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_C((ins)))) +#define DUK__CONSTP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_BC((ins)))) +#define DUK__REGCONSTP_B(ins) \ + ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) &DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_B((ins)))) +#define DUK__REGCONSTP_C(ins) \ + ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) &DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_C((ins)))) +#else /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ /* Safe alternatives, no assumption about duk_tval size. */ -#define DUK__REGP_A(ins) DUK__REGP(DUK_DEC_A((ins))) -#define DUK__REGP_B(ins) DUK__REGP(DUK_DEC_B((ins))) -#define DUK__REGP_C(ins) DUK__REGP(DUK_DEC_C((ins))) -#define DUK__REGP_BC(ins) DUK__REGP(DUK_DEC_BC((ins))) -#define DUK__CONSTP_A(ins) DUK__CONSTP(DUK_DEC_A((ins))) -#define DUK__CONSTP_B(ins) DUK__CONSTP(DUK_DEC_B((ins))) -#define DUK__CONSTP_C(ins) DUK__CONSTP(DUK_DEC_C((ins))) -#define DUK__CONSTP_BC(ins) DUK__CONSTP(DUK_DEC_BC((ins))) -#define DUK__REGCONSTP_B(ins) ((((ins) & DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK_DEC_B((ins))) -#define DUK__REGCONSTP_C(ins) ((((ins) & DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK_DEC_C((ins))) -#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#define DUK__REGP_A(ins) DUK__REGP(DUK_DEC_A((ins))) +#define DUK__REGP_B(ins) DUK__REGP(DUK_DEC_B((ins))) +#define DUK__REGP_C(ins) DUK__REGP(DUK_DEC_C((ins))) +#define DUK__REGP_BC(ins) DUK__REGP(DUK_DEC_BC((ins))) +#define DUK__CONSTP_A(ins) DUK__CONSTP(DUK_DEC_A((ins))) +#define DUK__CONSTP_B(ins) DUK__CONSTP(DUK_DEC_B((ins))) +#define DUK__CONSTP_C(ins) DUK__CONSTP(DUK_DEC_C((ins))) +#define DUK__CONSTP_BC(ins) DUK__CONSTP(DUK_DEC_BC((ins))) +#define DUK__REGCONSTP_B(ins) ((((ins) &DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK_DEC_B((ins))) +#define DUK__REGCONSTP_C(ins) ((((ins) &DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK_DEC_C((ins))) +#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ #if defined(DUK_USE_VERBOSE_EXECUTOR_ERRORS) -#define DUK__INTERNAL_ERROR(msg) do { \ +#define DUK__INTERNAL_ERROR(msg) \ + do { \ DUK_ERROR_ERROR(thr, (msg)); \ DUK_WO_NORETURN(return;); \ } while (0) #else -#define DUK__INTERNAL_ERROR(msg) do { \ +#define DUK__INTERNAL_ERROR(msg) \ + do { \ goto internal_error; \ } while (0) #endif -#define DUK__SYNC_CURR_PC() do { \ +#define DUK__SYNC_CURR_PC() \ + do { \ duk_activation *duk__act; \ duk__act = thr->callstack_curr; \ duk__act->curr_pc = curr_pc; \ } while (0) -#define DUK__SYNC_AND_NULL_CURR_PC() do { \ +#define DUK__SYNC_AND_NULL_CURR_PC() \ + do { \ duk_activation *duk__act; \ duk__act = thr->callstack_curr; \ duk__act->curr_pc = curr_pc; \ @@ -2823,19 +2850,22 @@ } while (0) #if defined(DUK_USE_EXEC_PREFER_SIZE) -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ (idx) = (duk_uint_fast_t) duk_get_uint(thr, (duk_idx_t) (idx)); \ } while (0) #elif defined(DUK_USE_FASTINT) -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ duk_tval *tv_ind; \ tv_ind = DUK__REGP((idx)); \ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_ind)); \ - DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_ind)); /* compiler guarantees */ \ + DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_ind)); /* compiler guarantees */ \ (idx) = (duk_uint_fast_t) DUK_TVAL_GET_FASTINT_U32(tv_ind); \ } while (0) #else -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ duk_tval *tv_ind; \ tv_ind = DUK__REGP(idx); \ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_ind)); \ @@ -2888,8 +2918,8 @@ * will be re-bumped by the longjmp. */ - DUK_ASSERT(lj_ret == DUK__LONGJMP_RETHROW); /* Rethrow error to calling state. */ - DUK_ASSERT(heap->lj.jmpbuf_ptr == entry_jmpbuf_ptr); /* Longjmp handling has restored jmpbuf_ptr. */ + DUK_ASSERT(lj_ret == DUK__LONGJMP_RETHROW); /* Rethrow error to calling state. */ + DUK_ASSERT(heap->lj.jmpbuf_ptr == entry_jmpbuf_ptr); /* Longjmp handling has restored jmpbuf_ptr. */ /* Thread may have changed, e.g. YIELD converted to THROW. */ duk_err_longjmp(heap->curr_thread); @@ -2912,7 +2942,7 @@ DUK_ASSERT(exec_thr->heap != NULL); DUK_ASSERT(exec_thr->heap->curr_thread != NULL); DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR((duk_heaphdr *) exec_thr); - DUK_ASSERT(exec_thr->callstack_top >= 1); /* at least one activation, ours */ + DUK_ASSERT(exec_thr->callstack_top >= 1); /* at least one activation, ours */ DUK_ASSERT(exec_thr->callstack_curr != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(exec_thr->callstack_curr) != NULL); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(exec_thr->callstack_curr))); @@ -2978,7 +3008,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } #if defined(DUK_USE_CPP_EXCEPTIONS) catch (duk_fatal_exception &exc) { @@ -2994,7 +3024,10 @@ DUK_STATS_INC(exec_thr->heap, stats_exec_throw); try { DUK_ASSERT(heap->curr_thread != NULL); - DUK_ERROR_FMT1(heap->curr_thread, DUK_ERR_TYPE_ERROR, "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", what); + DUK_ERROR_FMT1(heap->curr_thread, + DUK_ERR_TYPE_ERROR, + "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", + what); DUK_WO_NORETURN(return;); } catch (duk_internal_exception exc) { DUK_D(DUK_DPRINT("caught api error thrown from unexpected c++ std::exception")); @@ -3003,7 +3036,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } } catch (...) { DUK_D(DUK_DPRINT("unexpected c++ exception (perhaps thrown by user code)")); @@ -3019,7 +3052,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } } #endif @@ -3035,13 +3068,13 @@ * but that eliminates performance benefits; aliasing guarantees * should be enough though. */ - duk_instr_t *curr_pc; /* bytecode has a stable pointer */ + duk_instr_t *curr_pc; /* bytecode has a stable pointer */ /* Hot variables for interpretation. Critical for performance, * but must add sparingly to minimize register shuffling. */ - duk_hthread *thr; /* stable */ - duk_tval *consts; /* stable */ + duk_hthread *thr; /* stable */ + duk_tval *consts; /* stable */ duk_uint_fast32_t ins; /* 'funcs' is quite rarely used, so no local for it */ #if defined(DUK_USE_EXEC_FUN_LOCAL) @@ -3055,7 +3088,7 @@ #endif #if defined(DUK_USE_ASSERTIONS) - duk_size_t valstack_top_base; /* valstack top, should match before interpreting each op (no leftovers) */ + duk_size_t valstack_top_base; /* valstack top, should match before interpreting each op (no leftovers) */ #endif /* Optimized reg/const access macros assume sizeof(duk_tval) to be @@ -3111,7 +3144,7 @@ * See execution.rst for discussion. */ - restart_execution: +restart_execution: /* Lookup current thread; use the stable 'entry_thread' for this to * avoid clobber warnings. Any valid, reachable 'thr' value would be @@ -3152,7 +3185,7 @@ DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) valstack_top_base = (duk_size_t) (thr->valstack_top - thr->valstack); @@ -3216,7 +3249,7 @@ */ #if defined(DUK_USE_DEBUGGER_SUPPORT) if (thr->heap->dbg_force_restart) { - DUK_DD(DUK_DDPRINT("dbg_force_restart flag forced restart execution")); /* GH-303 */ + DUK_DD(DUK_DDPRINT("dbg_force_restart flag forced restart execution")); /* GH-303 */ thr->heap->dbg_force_restart = 0; goto restart_execution; } @@ -3228,7 +3261,7 @@ goto restart_execution; } } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ #if defined(DUK_USE_INTERRUPT_COUNTER) && defined(DUK_USE_DEBUG) /* For cross-checking during development: ensure dispatch count * matches cumulative interrupt counter init value sums. @@ -3242,16 +3275,17 @@ act = thr->callstack_curr; DUK_ASSERT(curr_pc >= DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())); DUK_ASSERT(curr_pc < DUK_HCOMPFUNC_GET_CODE_END(thr->heap, DUK__FUN())); - DUK_UNREF(act); /* if debugging disabled */ + DUK_UNREF(act); /* if debugging disabled */ - DUK_DDD(DUK_DDDPRINT("executing bytecode: pc=%ld, ins=0x%08lx, op=%ld, valstack_top=%ld/%ld, nregs=%ld --> %!I", - (long) (curr_pc - DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())), - (unsigned long) *curr_pc, - (long) DUK_DEC_OP(*curr_pc), - (long) (thr->valstack_top - thr->valstack), - (long) (thr->valstack_end - thr->valstack), - (long) (DUK__FUN() ? DUK__FUN()->nregs : -1), - (duk_instr_t) *curr_pc)); + DUK_DDD(DUK_DDDPRINT( + "executing bytecode: pc=%ld, ins=0x%08lx, op=%ld, valstack_top=%ld/%ld, nregs=%ld --> %!I", + (long) (curr_pc - DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())), + (unsigned long) *curr_pc, + (long) DUK_DEC_OP(*curr_pc), + (long) (thr->valstack_top - thr->valstack), + (long) (thr->valstack_end - thr->valstack), + (long) (DUK__FUN() ? DUK__FUN()->nregs : -1), + (duk_instr_t) *curr_pc)); } #endif @@ -3288,14 +3322,16 @@ */ op = (duk_uint8_t) DUK_DEC_OP(ins); switch (op) { - - /* Some useful macros. These access inner executor variables - * directly so they only apply within the executor. - */ + /* Some useful macros. These access inner executor variables + * directly so they only apply within the executor. + */ #if defined(DUK_USE_EXEC_PREFER_SIZE) -#define DUK__REPLACE_TOP_A_BREAK() { goto replace_top_a; } -#define DUK__REPLACE_TOP_BC_BREAK() { goto replace_top_bc; } -#define DUK__REPLACE_BOOL_A_BREAK(bval) { \ +#define DUK__REPLACE_TOP_A_BREAK() \ + { goto replace_top_a; } +#define DUK__REPLACE_TOP_BC_BREAK() \ + { goto replace_top_bc; } +#define DUK__REPLACE_BOOL_A_BREAK(bval) \ + { \ duk_bool_t duk__bval; \ duk__bval = (bval); \ DUK_ASSERT(duk__bval == 0 || duk__bval == 1); \ @@ -3303,9 +3339,18 @@ DUK__REPLACE_TOP_A_BREAK(); \ } #else -#define DUK__REPLACE_TOP_A_BREAK() { DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); break; } -#define DUK__REPLACE_TOP_BC_BREAK() { DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); break; } -#define DUK__REPLACE_BOOL_A_BREAK(bval) { \ +#define DUK__REPLACE_TOP_A_BREAK() \ + { \ + DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); \ + break; \ + } +#define DUK__REPLACE_TOP_BC_BREAK() \ + { \ + DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); \ + break; \ + } +#define DUK__REPLACE_BOOL_A_BREAK(bval) \ + { \ duk_bool_t duk__bval; \ duk_tval *duk__tvdst; \ duk__bval = (bval); \ @@ -3329,7 +3374,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__REGP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } @@ -3338,7 +3383,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__REGP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv2, tv1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv2, tv1); /* side effects */ break; } @@ -3347,7 +3392,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__CONSTP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } @@ -3367,18 +3412,18 @@ duk_int32_t val; val = (duk_int32_t) duk_get_int(thr, DUK_DEC_A(ins)); - val = (val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ + val = (val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ duk_push_int(thr, val); DUK__REPLACE_TOP_A_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LDINT: { duk_tval *tv1; duk_int32_t val; val = (duk_int32_t) DUK_DEC_BC(ins) - (duk_int32_t) DUK_BC_LDINT_BIAS; tv1 = DUK__REGP_A(ins); - DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ break; } case DUK_OP_LDINTX: { @@ -3394,11 +3439,12 @@ /* XXX: fast double-to-int conversion, we know number is integer in -0x80000000,0xffffffff. */ val = (duk_int32_t) DUK_TVAL_GET_NUMBER(tv1); #endif - val = (duk_int32_t) ((duk_uint32_t) val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ - DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ + val = + (duk_int32_t) ((duk_uint32_t) val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ + DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_LDTHIS: { @@ -3421,46 +3467,46 @@ duk_push_false(thr); DUK__REPLACE_TOP_BC_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LDTHIS: { /* Note: 'this' may be bound to any value, not just an object */ duk_tval *tv1, *tv2; tv1 = DUK__REGP_BC(ins); - tv2 = thr->valstack_bottom - 1; /* 'this binding' is just under bottom */ + tv2 = thr->valstack_bottom - 1; /* 'this binding' is just under bottom */ DUK_ASSERT(tv2 >= thr->valstack); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } case DUK_OP_LDUNDEF: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ break; } case DUK_OP_LDNULL: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_NULL_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_NULL_UPDREF(thr, tv1); /* side effects */ break; } case DUK_OP_LDTRUE: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 1); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 1); /* side effects */ break; } case DUK_OP_LDFALSE: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 0); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 0); /* side effects */ break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_BNOT: { duk__vm_bitwise_not(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins)); @@ -3478,7 +3524,7 @@ duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_UNM: { duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), DUK_OP_UNM); break; @@ -3487,7 +3533,7 @@ duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), DUK_OP_UNP); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_TYPEOF: { @@ -3498,7 +3544,7 @@ duk_push_hstring_stridx(thr, stridx); DUK__REPLACE_TOP_A_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_TYPEOF: { duk_tval *tv; duk_small_uint_t stridx; @@ -3512,7 +3558,7 @@ DUK_TVAL_SET_STRING_UPDREF(thr, tv, h_str); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_TYPEOFID: { duk_small_uint_t stridx; @@ -3530,13 +3576,13 @@ tv = DUK__CONSTP_BC(ins); DUK_ASSERT(DUK_TVAL_IS_STRING(tv)); name = DUK_TVAL_GET_STRING(tv); - tv = NULL; /* lookup has side effects */ + tv = NULL; /* lookup has side effects */ act = thr->callstack_curr; if (duk_js_getvar_activation(thr, act, name, 0 /*throw*/)) { /* -> ... val this */ tv = DUK_GET_TVAL_NEGIDX(thr, -2); stridx = duk_js_typeof_stridx(tv); - tv = NULL; /* no longer needed */ + tv = NULL; /* no longer needed */ duk_pop_2_unsafe(thr); } else { /* unresolvable, no stack changes */ @@ -3546,36 +3592,40 @@ #if defined(DUK_USE_EXEC_PREFER_SIZE) duk_push_hstring_stridx(thr, stridx); DUK__REPLACE_TOP_A_BREAK(); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ h_str = DUK_HTHREAD_GET_STRING(thr, stridx); tv = DUK__REGP_A(ins); DUK_TVAL_SET_STRING_UPDREF(thr, tv, h_str); break; -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } /* Equality: E5 Sections 11.9.1, 11.9.3 */ -#define DUK__EQ_BODY(barg,carg) { \ +#define DUK__EQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_equals(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__NEQ_BODY(barg,carg) { \ +#define DUK__NEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_equals(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ tmp ^= 1; \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__SEQ_BODY(barg,carg) { \ +#define DUK__SEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_strict_equals((barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__SNEQ_BODY(barg,carg) { \ +#define DUK__SNEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_strict_equals((barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ @@ -3603,7 +3653,7 @@ case DUK_OP_SNEQ_RC: case DUK_OP_SNEQ_CC: DUK__SNEQ_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_EQ_RR: DUK__EQ_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_EQ_CR: @@ -3636,18 +3686,19 @@ DUK__SNEQ_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_SNEQ_CC: DUK__SNEQ_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ -#define DUK__COMPARE_BODY(arg1,arg2,flags) { \ +#define DUK__COMPARE_BODY(arg1, arg2, flags) \ + { \ duk_bool_t tmp; \ tmp = duk_js_compare_helper(thr, (arg1), (arg2), (flags)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__GT_BODY(barg,carg) DUK__COMPARE_BODY((carg), (barg), 0) -#define DUK__GE_BODY(barg,carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) -#define DUK__LT_BODY(barg,carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) -#define DUK__LE_BODY(barg,carg) DUK__COMPARE_BODY((carg), (barg), DUK_COMPARE_FLAG_NEGATE) +#define DUK__GT_BODY(barg, carg) DUK__COMPARE_BODY((carg), (barg), 0) +#define DUK__GE_BODY(barg, carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) +#define DUK__LT_BODY(barg, carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) +#define DUK__LE_BODY(barg, carg) DUK__COMPARE_BODY((carg), (barg), DUK_COMPARE_FLAG_NEGATE) #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_GT_RR: case DUK_OP_GT_CR: @@ -3669,7 +3720,7 @@ case DUK_OP_LE_RC: case DUK_OP_LE_CC: DUK__LE_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_GT_RR: DUK__GT_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_GT_CR: @@ -3702,7 +3753,7 @@ DUK__LE_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_LE_CC: DUK__LE_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* No size optimized variant at present for IF. */ case DUK_OP_IFTRUE_R: { @@ -3739,7 +3790,7 @@ duk__vm_arith_add(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins)); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_ADD_RR: { duk__vm_arith_add(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins)); break; @@ -3756,7 +3807,7 @@ duk__vm_arith_add(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins)); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_SUB_RR: @@ -3780,13 +3831,13 @@ case DUK_OP_EXP_CR: case DUK_OP_EXP_RC: case DUK_OP_EXP_CC: -#endif /* DUK_USE_ES7_EXP_OPERATOR */ +#endif /* DUK_USE_ES7_EXP_OPERATOR */ { /* XXX: could leave value on stack top and goto replace_top_a; */ duk__vm_arith_binary_op(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_SUB_RR: { duk__vm_arith_binary_op(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins), DUK_OP_SUB); break; @@ -3868,8 +3919,8 @@ duk__vm_arith_binary_op(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins), DUK_OP_EXP); break; } -#endif /* DUK_USE_ES7_EXP_OPERATOR */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_ES7_EXP_OPERATOR */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_BAND_RR: @@ -3900,7 +3951,7 @@ duk__vm_bitwise_binary_op(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_BAND_RR: { duk__vm_bitwise_binary_op(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins), DUK_OP_BAND); break; @@ -3997,16 +4048,18 @@ duk__vm_bitwise_binary_op(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins), DUK_OP_BASR); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* For INSTOF and IN, B is always a register. */ -#define DUK__INSTOF_BODY(barg,carg) { \ +#define DUK__INSTOF_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_instanceof(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__IN_BODY(barg,carg) { \ +#define DUK__IN_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_in(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ @@ -4023,7 +4076,7 @@ case DUK_OP_IN_RC: case DUK_OP_IN_CC: DUK__IN_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_INSTOF_RR: DUK__INSTOF_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_INSTOF_CR: @@ -4040,9 +4093,9 @@ DUK__IN_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_IN_CC: DUK__IN_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ - /* Pre/post inc/dec for register variables, important for loops. */ + /* Pre/post inc/dec for register variables, important for loops. */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_PREINCR: case DUK_OP_PREDECR: @@ -4058,7 +4111,7 @@ duk__prepost_incdec_var_helper(thr, DUK_DEC_A(ins), DUK__CONSTP_BC(ins), op, DUK__STRICT()); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_PREINCR: { duk__prepost_incdec_reg_helper(thr, DUK__REGP_A(ins), DUK__REGP_BC(ins), DUK_OP_PREINCR); break; @@ -4091,7 +4144,7 @@ duk__prepost_incdec_var_helper(thr, DUK_DEC_A(ins), DUK__CONSTP_BC(ins), DUK_OP_POSTDECV, DUK__STRICT()); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* XXX: Move to separate helper, optimize for perf/size separately. */ /* Preinc/predec for object properties. */ @@ -4118,7 +4171,7 @@ duk_double_t x, y, z; #if !defined(DUK_USE_EXEC_PREFER_SIZE) duk_tval *tv_dst; -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* A -> target reg * B -> object reg/const (may be const e.g. in "'foo'1") @@ -4136,10 +4189,10 @@ tv_obj = DUK__REGCONSTP_B(ins); tv_key = DUK__REGCONSTP_C(ins); - rc = duk_hobject_getprop(thr, tv_obj, tv_key); /* -> val */ - DUK_UNREF(rc); /* ignore */ - tv_obj = NULL; /* invalidated */ - tv_key = NULL; /* invalidated */ + rc = duk_hobject_getprop(thr, tv_obj, tv_key); /* -> val */ + DUK_UNREF(rc); /* ignore */ + tv_obj = NULL; /* invalidated */ + tv_key = NULL; /* invalidated */ /* XXX: Fastint fast path would be useful here. Also fastints * now lose their fastint status in current handling which is @@ -4160,9 +4213,9 @@ tv_obj = DUK__REGCONSTP_B(ins); tv_key = DUK__REGCONSTP_C(ins); rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, DUK__STRICT()); - DUK_UNREF(rc); /* ignore */ - tv_obj = NULL; /* invalidated */ - tv_key = NULL; /* invalidated */ + DUK_UNREF(rc); /* ignore */ + tv_obj = NULL; /* invalidated */ + tv_key = NULL; /* invalidated */ duk_pop_unsafe(thr); z = (ins & DUK_BC_INCDECP_FLAG_POST) ? x : y; @@ -4180,7 +4233,8 @@ * Occurs relatively often in object oriented code. */ -#define DUK__GETPROP_BODY(barg,carg) { \ +#define DUK__GETPROP_BODY(barg, carg) \ + { \ /* A -> target reg \ * B -> object reg/const (may be const e.g. in "'foo'1") \ * C -> key reg/const \ @@ -4188,7 +4242,8 @@ (void) duk_hobject_getprop(thr, (barg), (carg)); \ DUK__REPLACE_TOP_A_BREAK(); \ } -#define DUK__GETPROPC_BODY(barg,carg) { \ +#define DUK__GETPROPC_BODY(barg, carg) \ + { \ /* Same as GETPROP but callability check for property-based calls. */ \ duk_tval *tv__targ; \ (void) duk_hobject_getprop(thr, (barg), (carg)); \ @@ -4203,7 +4258,8 @@ } \ DUK__REPLACE_TOP_A_BREAK(); \ } -#define DUK__PUTPROP_BODY(aarg,barg,carg) { \ +#define DUK__PUTPROP_BODY(aarg, barg, carg) \ + { \ /* A -> object reg \ * B -> key reg/const \ * C -> value reg/const \ @@ -4214,7 +4270,8 @@ (void) duk_hobject_putprop(thr, (aarg), (barg), (carg), DUK__STRICT()); \ break; \ } -#define DUK__DELPROP_BODY(barg,carg) { \ +#define DUK__DELPROP_BODY(barg, carg) \ + { \ /* A -> result reg \ * B -> object reg \ * C -> key reg/const \ @@ -4243,9 +4300,9 @@ case DUK_OP_PUTPROP_CC: DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); case DUK_OP_DELPROP_RR: - case DUK_OP_DELPROP_RC: /* B is always reg */ + case DUK_OP_DELPROP_RC: /* B is always reg */ DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_GETPROP_RR: DUK__GETPROP_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_GETPROP_CR: @@ -4272,11 +4329,11 @@ DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_PUTPROP_CC: DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); - case DUK_OP_DELPROP_RR: /* B is always reg */ + case DUK_OP_DELPROP_RR: /* B is always reg */ DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_DELPROP_RC: DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* No fast path for DECLVAR now, it's quite a rare instruction. */ case DUK_OP_DECLVAR_RR: @@ -4309,7 +4366,7 @@ if (is_func_decl) { duk_push_tval(thr, DUK__REGCONSTP_C(ins)); } else { - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } tv1 = DUK_GET_TVAL_NEGIDX(thr, -1); @@ -4345,11 +4402,11 @@ */ duk_push_tval(thr, DUK__REGCONSTP_C(ins)); - duk_push_tval(thr, DUK__REGCONSTP_B(ins)); /* -> ... escaped_source bytecode */ - duk_regexp_create_instance(thr); /* -> ... regexp_instance */ + duk_push_tval(thr, DUK__REGCONSTP_B(ins)); /* -> ... escaped_source bytecode */ + duk_regexp_create_instance(thr); /* -> ... regexp_instance */ DUK__REPLACE_TOP_A_BREAK(); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* XXX: 'c' is unused, use whole BC, etc. */ case DUK_OP_CSVAR_RR: @@ -4378,13 +4435,13 @@ name = DUK_TVAL_GET_STRING(tv1); DUK_ASSERT(name != NULL); act = thr->callstack_curr; - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ idx = (duk_uint_fast_t) DUK_DEC_A(ins); /* Could add direct value stack handling. */ - duk_replace(thr, (duk_idx_t) (idx + 1)); /* 'this' binding */ - duk_replace(thr, (duk_idx_t) idx); /* variable value (function, we hope, not checked here) */ + duk_replace(thr, (duk_idx_t) (idx + 1)); /* 'this' binding */ + duk_replace(thr, (duk_idx_t) idx); /* variable value (function, we hope, not checked here) */ break; } @@ -4399,7 +4456,9 @@ */ DUK_DDD(DUK_DDDPRINT("CLOSURE to target register %ld, fnum %ld (count %ld)", - (long) DUK_DEC_A(ins), (long) DUK_DEC_BC(ins), (long) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN()))); + (long) DUK_DEC_A(ins), + (long) DUK_DEC_BC(ins), + (long) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN()))); DUK_ASSERT_DISABLE(bc >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) bc < (duk_uint_t) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN())); @@ -4410,8 +4469,8 @@ DUK_ASSERT(fun_temp != NULL); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(fun_temp)); - DUK_DDD(DUK_DDDPRINT("CLOSURE: function template is: %p -> %!O", - (void *) fun_temp, (duk_heaphdr *) fun_temp)); + DUK_DDD( + DUK_DDDPRINT("CLOSURE: function template is: %p -> %!O", (void *) fun_temp, (duk_heaphdr *) fun_temp)); if (act->lex_env == NULL) { DUK_ASSERT(act->var_env == NULL); @@ -4425,11 +4484,7 @@ * new variable declaration environment, so only lex_env * matters here. */ - duk_js_push_closure(thr, - (duk_hcompfunc *) fun_temp, - act->var_env, - act->lex_env, - 1 /*add_auto_proto*/); + duk_js_push_closure(thr, (duk_hcompfunc *) fun_temp, act->var_env, act->lex_env, 1 /*add_auto_proto*/); DUK__REPLACE_TOP_A_BREAK(); } @@ -4444,8 +4499,8 @@ DUK_ASSERT(name != NULL); act = thr->callstack_curr; DUK_ASSERT(act != NULL); - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ - duk_pop_unsafe(thr); /* 'this' binding is not needed here */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + duk_pop_unsafe(thr); /* 'this' binding is not needed here */ DUK__REPLACE_TOP_A_BREAK(); } @@ -4463,7 +4518,7 @@ * should be reworked. */ - tv1 = DUK__REGP_A(ins); /* val */ + tv1 = DUK__REGP_A(ins); /* val */ act = thr->callstack_curr; duk_js_putvar_activation(thr, act, name, tv1, DUK__STRICT()); break; @@ -4493,7 +4548,8 @@ break; } -#define DUK__RETURN_SHARED() do { \ +#define DUK__RETURN_SHARED() \ + do { \ duk_small_uint_t ret_result; \ /* duk__handle_return() is guaranteed never to throw, except \ * for potential out-of-memory situations which will then \ @@ -4512,14 +4568,14 @@ case DUK_OP_RETCONST: case DUK_OP_RETCONSTN: case DUK_OP_RETUNDEF: { - /* BC -> return value reg/const */ + /* BC -> return value reg/const */ DUK__SYNC_AND_NULL_CURR_PC(); if (op == DUK_OP_RETREG) { duk_push_tval(thr, DUK__REGP_BC(ins)); } else if (op == DUK_OP_RETUNDEF) { - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } else { DUK_ASSERT(op == DUK_OP_RETCONST || op == DUK_OP_RETCONSTN); @@ -4528,7 +4584,7 @@ DUK__RETURN_SHARED(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_RETREG: { duk_tval *tv; @@ -4558,18 +4614,18 @@ DUK_TVAL_SET_TVAL(thr->valstack_top, tv); #if defined(DUK_USE_REFERENCE_COUNTING) /* Without refcounting only RETCONSTN is used. */ - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv)); /* no INCREF for this constant */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv)); /* no INCREF for this constant */ #endif thr->valstack_top++; DUK__RETURN_SHARED(); } case DUK_OP_RETUNDEF: { DUK__SYNC_AND_NULL_CURR_PC(); - thr->valstack_top++; /* value at valstack top is already undefined by valstack policy */ + thr->valstack_top++; /* value at valstack top is already undefined by valstack policy */ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); DUK__RETURN_SHARED(); } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LABEL: { duk_activation *act; @@ -4582,8 +4638,8 @@ DUK_ASSERT(cat != NULL); cat->flags = (duk_uint32_t) (DUK_CAT_TYPE_LABEL | (bc << DUK_CAT_LABEL_SHIFT)); - cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ - cat->idx_base = 0; /* unused for label */ + cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ + cat->idx_base = 0; /* unused for label */ cat->h_varname = NULL; act = thr->callstack_curr; @@ -4593,10 +4649,13 @@ DUK_DDD(DUK_DDDPRINT("LABEL catcher: flags=0x%08lx, pc_base=%ld, " "idx_base=%ld, h_varname=%!O, label_id=%ld", - (long) cat->flags, (long) cat->pc_base, - (long) cat->idx_base, (duk_heaphdr *) cat->h_varname, (long) DUK_CAT_GET_LABEL(cat))); + (long) cat->flags, + (long) cat->pc_base, + (long) cat->idx_base, + (duk_heaphdr *) cat->h_varname, + (long) DUK_CAT_GET_LABEL(cat))); - curr_pc += 2; /* skip jump slots */ + curr_pc += 2; /* skip jump slots */ break; } @@ -4638,7 +4697,7 @@ /* XXX: move to helper, too large to be inline here */ case DUK_OP_TRYCATCH: { duk__handle_op_trycatch(thr, ins, curr_pc); - curr_pc += 2; /* skip jump slots */ + curr_pc += 2; /* skip jump slots */ break; } @@ -4683,8 +4742,8 @@ (duk_tval *) duk_get_tval(thr, -1))); #if defined(DUK_USE_AUGMENT_ERROR_THROW) duk_err_augment_error_throw(thr); - DUK_DDD(DUK_DDDPRINT("THROW ERROR (BYTECODE): %!dT (after throw augment)", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD( + DUK_DDDPRINT("THROW ERROR (BYTECODE): %!dT (after throw augment)", (duk_tval *) duk_get_tval(thr, -1))); #endif duk_err_setup_ljstate1(thr, DUK_LJ_TYPE_THROW, DUK_GET_TVAL_NEGIDX(thr, -1)); @@ -4692,7 +4751,7 @@ duk_err_check_debugger_integration(thr); #endif - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ duk_err_longjmp(thr); DUK_UNREACHABLE(); break; @@ -4729,20 +4788,19 @@ DUK_TVAL_SET_TVAL(&tv_tmp2, tv2); tv3 = DUK__REGP(a); DUK_TVAL_SET_TVAL(tv1, tv3); - DUK_TVAL_INCREF(thr, tv1); /* no side effects */ - DUK_TVAL_SET_UNDEFINED(tv2); /* no need for incref */ + DUK_TVAL_INCREF(thr, tv1); /* no side effects */ + DUK_TVAL_SET_UNDEFINED(tv2); /* no need for incref */ DUK_TVAL_DECREF(thr, &tv_tmp1); DUK_TVAL_DECREF(thr, &tv_tmp2); #endif break; } - - /* XXX: in some cases it's faster NOT to reuse the value - * stack but rather copy the arguments on top of the stack - * (mainly when the calling value stack is large and the value - * stack resize would be large). - */ + /* XXX: in some cases it's faster NOT to reuse the value + * stack but rather copy the arguments on top of the stack + * (mainly when the calling value stack is large and the value + * stack resize would be large). + */ case DUK_OP_CALL0: case DUK_OP_CALL1: @@ -4903,7 +4961,7 @@ } count = (duk_small_uint_fast_t) DUK_DEC_C(ins); - DUK_ASSERT(count > 0); /* compiler guarantees */ + DUK_ASSERT(count > 0); /* compiler guarantees */ idx_end = idx + count; #if defined(DUK_USE_EXEC_INDIRECT_BOUND_CHECK) @@ -4927,11 +4985,10 @@ /* XXX: faster initialization (direct access or better primitives) */ duk_dup(thr, (duk_idx_t) idx); duk_dup(thr, (duk_idx_t) (idx + 1)); - duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_WRITABLE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE); + duk_def_prop(thr, + obj_idx, + DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_WRITABLE | + DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE); idx += 2; } while (idx < idx_end); break; @@ -4966,7 +5023,7 @@ } count = (duk_small_uint_fast_t) DUK_DEC_C(ins); - DUK_ASSERT(count > 0 + 1); /* compiler guarantees */ + DUK_ASSERT(count > 0 + 1); /* compiler guarantees */ idx_end = idx + count; #if defined(DUK_USE_EXEC_INDIRECT_BOUND_CHECK) @@ -5093,7 +5150,7 @@ duk_push_new_target(thr); DUK__REPLACE_TOP_BC_BREAK(); } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if !defined(DUK_USE_EXEC_PREFER_SIZE) #if !defined(DUK_USE_ES7_EXP_OPERATOR) @@ -5156,16 +5213,16 @@ case DUK_OP_UNUSED253: case DUK_OP_UNUSED254: case DUK_OP_UNUSED255: - /* Force all case clauses to map to an actual handler - * so that the compiler can emit a jump without a bounds - * check: the switch argument is a duk_uint8_t so that - * the compiler may be able to figure it out. This is - * a small detail and obviously compiler dependent. - */ - /* default: clause omitted on purpose */ -#else /* DUK_USE_EXEC_PREFER_SIZE */ + /* Force all case clauses to map to an actual handler + * so that the compiler can emit a jump without a bounds + * check: the switch argument is a duk_uint8_t so that + * the compiler may be able to figure it out. This is + * a small detail and obviously compiler dependent. + */ + /* default: clause omitted on purpose */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ default: -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ { /* Default case catches invalid/unsupported opcodes. */ DUK_D(DUK_DPRINT("invalid opcode: %ld - %!I", (long) op, ins)); @@ -5173,7 +5230,7 @@ break; } - } /* end switch */ + } /* end switch */ continue; @@ -5184,10 +5241,10 @@ */ #if defined(DUK_USE_EXEC_PREFER_SIZE) - replace_top_a: + replace_top_a: DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); continue; - replace_top_bc: + replace_top_bc: DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); continue; #endif @@ -5195,7 +5252,7 @@ DUK_WO_NORETURN(return;); #if !defined(DUK_USE_VERBOSE_EXECUTOR_ERRORS) - internal_error: +internal_error: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); #endif
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_js_ops.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_js_ops.c
Changed
@@ -161,19 +161,10 @@ /* Quite lenient, e.g. allow empty as zero, but don't allow trailing * garbage. */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_INF | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO | - DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT | - DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT | - DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_PLUS | DUK_S2N_FLAG_ALLOW_MINUS | + DUK_S2N_FLAG_ALLOW_INF | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO | DUK_S2N_FLAG_ALLOW_LEADING_ZERO | + DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT | DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT | DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT; duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); @@ -183,9 +174,9 @@ #else thr->valstack_top--; DUK_ASSERT(DUK_TVAL_IS_NUMBER(thr->valstack_top)); - DUK_ASSERT(DUK_TVAL_IS_DOUBLE(thr->valstack_top)); /* no fastint conversion in numconv now */ + DUK_ASSERT(DUK_TVAL_IS_DOUBLE(thr->valstack_top)); /* no fastint conversion in numconv now */ DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(thr->valstack_top)); - d = DUK_TVAL_GET_DOUBLE(thr->valstack_top); /* assumes not a fastint */ + d = DUK_TVAL_GET_DOUBLE(thr->valstack_top); /* assumes not a fastint */ DUK_TVAL_SET_UNDEFINED(thr->valstack_top); #endif @@ -224,11 +215,11 @@ duk_push_hstring(thr, h); return duk__tonumber_string_raw(thr); } - case DUK_TAG_BUFFER: /* plain buffer treated like object */ + case DUK_TAG_BUFFER: /* plain buffer treated like object */ case DUK_TAG_OBJECT: { duk_double_t d; duk_push_tval(thr, tv); - duk_to_primitive(thr, -1, DUK_HINT_NUMBER); /* 'tv' becomes invalid */ + duk_to_primitive(thr, -1, DUK_HINT_NUMBER); /* 'tv' becomes invalid */ /* recursive call for a primitive value (guaranteed not to cause second * recursion). @@ -283,7 +274,7 @@ */ return duk_double_trunc_towards_zero(x); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* NaN and Infinity have the same exponent so it's a cheap * initial check for the rare path. */ @@ -296,12 +287,12 @@ } else { return duk_double_trunc_towards_zero(x); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } DUK_INTERNAL duk_double_t duk_js_tointeger(duk_hthread *thr, duk_tval *tv) { /* XXX: fastint */ - duk_double_t d = duk_js_tonumber(thr, tv); /* invalidates tv */ + duk_double_t d = duk_js_tonumber(thr, tv); /* invalidates tv */ return duk_js_tointeger_number(d); } @@ -311,11 +302,11 @@ /* combined algorithm matching E5 Sections 9.5 and 9.6 */ DUK_LOCAL duk_double_t duk__toint32_touint32_helper(duk_double_t x, duk_bool_t is_toint32) { -#if defined (DUK_USE_PREFER_SIZE) +#if defined(DUK_USE_PREFER_SIZE) duk_small_int_t c; #endif -#if defined (DUK_USE_PREFER_SIZE) +#if defined(DUK_USE_PREFER_SIZE) c = (duk_small_int_t) DUK_FPCLASSIFY(x); if (c == DUK_FP_NAN || c == DUK_FP_ZERO || c == DUK_FP_INFINITE) { return 0.0; @@ -333,18 +324,18 @@ * differs from what Javascript wants (see Section 9.6). */ - x = DUK_FMOD(x, DUK_DOUBLE_2TO32); /* -> x in -2**32, 2**32 */ + x = DUK_FMOD(x, DUK_DOUBLE_2TO32); /* -> x in -2**32, 2**32 */ if (x < 0.0) { x += DUK_DOUBLE_2TO32; } - DUK_ASSERT(x >= 0 && x < DUK_DOUBLE_2TO32); /* -> x in 0, 2**32 */ + DUK_ASSERT(x >= 0 && x < DUK_DOUBLE_2TO32); /* -> x in 0, 2**32 */ if (is_toint32) { if (x >= DUK_DOUBLE_2TO31) { /* x in 2**31, 2**32 */ - x -= DUK_DOUBLE_2TO32; /* -> x in -2**31,2**31 */ + x -= DUK_DOUBLE_2TO32; /* -> x in -2**31,2**31 */ } } @@ -360,15 +351,14 @@ } #endif - d = duk_js_tonumber(thr, tv); /* invalidates tv */ + d = duk_js_tonumber(thr, tv); /* invalidates tv */ d = duk__toint32_touint32_helper(d, 1); DUK_ASSERT(DUK_FPCLASSIFY(d) == DUK_FP_ZERO || DUK_FPCLASSIFY(d) == DUK_FP_NORMAL); - DUK_ASSERT(d >= -2147483648.0 && d <= 2147483647.0); /* -0x80000000,0x7fffffff */ - DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_int32_t) d))); /* whole, won't clip */ + DUK_ASSERT(d >= -2147483648.0 && d <= 2147483647.0); /* -0x80000000,0x7fffffff */ + DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_int32_t) d))); /* whole, won't clip */ return (duk_int32_t) d; } - DUK_INTERNAL duk_uint32_t duk_js_touint32(duk_hthread *thr, duk_tval *tv) { duk_double_t d; @@ -378,13 +368,12 @@ } #endif - d = duk_js_tonumber(thr, tv); /* invalidates tv */ + d = duk_js_tonumber(thr, tv); /* invalidates tv */ d = duk__toint32_touint32_helper(d, 0); DUK_ASSERT(DUK_FPCLASSIFY(d) == DUK_FP_ZERO || DUK_FPCLASSIFY(d) == DUK_FP_NORMAL); - DUK_ASSERT(d >= 0.0 && d <= 4294967295.0); /* 0x00000000, 0xffffffff */ - DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_uint32_t) d))); /* whole, won't clip */ + DUK_ASSERT(d >= 0.0 && d <= 4294967295.0); /* 0x00000000, 0xffffffff */ + DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_uint32_t) d))); /* whole, won't clip */ return (duk_uint32_t) d; - } DUK_INTERNAL duk_uint16_t duk_js_touint16(duk_hthread *thr, duk_tval *tv) { @@ -434,7 +423,7 @@ return 1; } return 0; -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ /* Better equivalent algorithm. If the compiler is compliant, C and * ECMAScript semantics are identical for this particular comparison. * In particular, NaNs must never compare equal and zeroes must compare @@ -454,7 +443,7 @@ DUK_ASSERT(!(DUK_FPCLASSIFY(x) == DUK_FP_ZERO && DUK_FPCLASSIFY(y) == DUK_FP_ZERO)); return 0; } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ } DUK_LOCAL duk_bool_t duk__js_samevalue_number(duk_double_t x, duk_double_t y) { @@ -484,7 +473,7 @@ */ return (x == y); -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ duk_small_int_t cx = (duk_small_int_t) DUK_FPCLASSIFY(x); duk_small_int_t cy = (duk_small_int_t) DUK_FPCLASSIFY(y); @@ -519,7 +508,7 @@ } return 0; } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ } DUK_INTERNAL duk_bool_t duk_js_equals_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags) { @@ -545,10 +534,9 @@ } else { return 0; } - } - else + } else #endif - if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { + if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { duk_double_t d1, d2; /* Catches both doubles and cases where only one argument is @@ -622,7 +610,7 @@ return 0; } - DUK_ASSERT(flags == 0); /* non-strict equality from here on */ + DUK_ASSERT(flags == 0); /* non-strict equality from here on */ /* * Types are different; various cases for non-strict comparison @@ -679,34 +667,29 @@ } /* String-number-symbol/object -> coerce object to primitive (apparently without hint), then try again. */ - if ((type_mask_x & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER)) && - (type_mask_y & DUK_TYPE_MASK_OBJECT)) { + if ((type_mask_x & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER)) && (type_mask_y & DUK_TYPE_MASK_OBJECT)) { /* No symbol check needed because symbols and strings are accepted. */ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -1, DUK_HINT_NONE); /* apparently no hint? */ + duk_to_primitive(thr, -1, DUK_HINT_NONE); /* apparently no hint? */ goto recursive_call; } - if ((type_mask_x & DUK_TYPE_MASK_OBJECT) && - (type_mask_y & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER))) { + if ((type_mask_x & DUK_TYPE_MASK_OBJECT) && (type_mask_y & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER))) { /* No symbol check needed because symbols and strings are accepted. */ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -2, DUK_HINT_NONE); /* apparently no hint? */ + duk_to_primitive(thr, -2, DUK_HINT_NONE); /* apparently no hint? */ goto recursive_call; } /* Nothing worked -> not equal. */ return 0; - recursive_call: +recursive_call: /* Shared code path to call the helper again with arguments on stack top. */ { duk_bool_t rc; - rc = duk_js_equals_helper(thr, - DUK_GET_TVAL_NEGIDX(thr, -2), - DUK_GET_TVAL_NEGIDX(thr, -1), - 0 /*flags:nonstrict*/); + rc = duk_js_equals_helper(thr, DUK_GET_TVAL_NEGIDX(thr, -2), DUK_GET_TVAL_NEGIDX(thr, -1), 0 /*flags:nonstrict*/); duk_pop_2_unsafe(thr); return rc; } @@ -723,7 +706,10 @@ * needs to push stuff on the stack anyway... */ -DUK_INTERNAL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, const duk_uint8_t *buf2, duk_size_t len1, duk_size_t len2) { +DUK_INTERNAL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, + const duk_uint8_t *buf2, + duk_size_t len1, + duk_size_t len2) { duk_size_t prefix_len; duk_small_int_t rc; @@ -732,9 +718,7 @@ /* duk_memcmp() is guaranteed to return zero (equal) for zero length * inputs. */ - rc = duk_memcmp_unsafe((const void *) buf1, - (const void *) buf2, - (size_t) prefix_len); + rc = duk_memcmp_unsafe((const void *) buf1, (const void *) buf2, (size_t) prefix_len); if (rc < 0) { return -1; @@ -776,7 +760,7 @@ (duk_size_t) DUK_HSTRING_GET_BYTELEN(h2)); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL duk_small_int_t duk_js_buffer_compare(duk_heap *heap, duk_hbuffer *h1, duk_hbuffer *h2) { /* Similar to String comparison. */ @@ -813,47 +797,47 @@ s2 = (duk_small_int_t) DUK_SIGNBIT(d2); if (c1 == DUK_FP_NAN || c2 == DUK_FP_NAN) { - return 0; /* Always false, regardless of negation. */ + return 0; /* Always false, regardless of negation. */ } if (c1 == DUK_FP_ZERO && c2 == DUK_FP_ZERO) { /* For all combinations: +0 < +0, +0 < -0, -0 < +0, -0 < -0, * steps e, f, and g. */ - return retval; /* false */ + return retval; /* false */ } if (d1 == d2) { - return retval; /* false */ + return retval; /* false */ } if (c1 == DUK_FP_INFINITE && s1 == 0) { /* x == +Infinity */ - return retval; /* false */ + return retval; /* false */ } if (c2 == DUK_FP_INFINITE && s2 == 0) { /* y == +Infinity */ - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } if (c2 == DUK_FP_INFINITE && s2 != 0) { /* y == -Infinity */ - return retval; /* false */ + return retval; /* false */ } if (c1 == DUK_FP_INFINITE && s1 != 0) { /* x == -Infinity */ - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } if (d1 < d2) { - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } - return retval; /* false */ + return retval; /* false */ } -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ DUK_LOCAL duk_bool_t duk__compare_number(duk_bool_t retval, duk_double_t d1, duk_double_t d2) { /* This comparison tree relies doesn't match the exact steps in * E5 Section 11.8.5 but should produce the same results. The @@ -890,39 +874,35 @@ * results in false return (see e.g. Section * 11.8.3) - hence special treatment here. */ - return 0; /* zero regardless of negation */ + return 0; /* zero regardless of negation */ } else { return retval; } } } } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ DUK_INTERNAL duk_bool_t duk_js_compare_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags) { duk_double_t d1, d2; duk_small_int_t rc; duk_bool_t retval; - DUK_ASSERT(DUK_COMPARE_FLAG_NEGATE == 1); /* Rely on this flag being lowest. */ + DUK_ASSERT(DUK_COMPARE_FLAG_NEGATE == 1); /* Rely on this flag being lowest. */ retval = flags & DUK_COMPARE_FLAG_NEGATE; DUK_ASSERT(retval == 0 || retval == 1); /* Fast path for fastints */ #if defined(DUK_USE_FASTINT) if (DUK_LIKELY(DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y))) { - return duk__compare_fastint(retval, - DUK_TVAL_GET_FASTINT(tv_x), - DUK_TVAL_GET_FASTINT(tv_y)); + return duk__compare_fastint(retval, DUK_TVAL_GET_FASTINT(tv_x), DUK_TVAL_GET_FASTINT(tv_y)); } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* Fast path for numbers (one of which may be a fastint) */ #if !defined(DUK_USE_PREFER_SIZE) if (DUK_LIKELY(DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y))) { - return duk__compare_number(retval, - DUK_TVAL_GET_NUMBER(tv_x), - DUK_TVAL_GET_NUMBER(tv_y)); + return duk__compare_number(retval, DUK_TVAL_GET_NUMBER(tv_x), DUK_TVAL_GET_NUMBER(tv_y)); } #endif @@ -989,7 +969,7 @@ thr->valstack_top -= 2; tv_x = thr->valstack_top; tv_y = tv_x + 1; - DUK_TVAL_SET_UNDEFINED(tv_x); /* Value stack policy */ + DUK_TVAL_SET_UNDEFINED(tv_x); /* Value stack policy */ DUK_TVAL_SET_UNDEFINED(tv_y); #endif @@ -1043,8 +1023,8 @@ if (!skip_sym_check) { if (duk_get_method_stridx(thr, -1, DUK_STRIDX_WELLKNOWN_SYMBOL_HAS_INSTANCE)) { /* ... lhs rhs func */ - duk_insert(thr, -3); /* -> ... func lhs rhs */ - duk_swap_top(thr, -2); /* -> ... func rhs(this) lhs */ + duk_insert(thr, -3); /* -> ... func lhs rhs */ + duk_swap_top(thr, -2); /* -> ... func rhs(this) lhs */ duk_call_method(thr, 1); return duk_to_boolean_top_pop(thr); } @@ -1076,7 +1056,7 @@ if (DUK_HOBJECT_HAS_BOUNDFUNC(func)) { duk_push_tval(thr, &((duk_hboundfunc *) (void *) func)->target); duk_replace(thr, -2); - func = duk_require_hobject(thr, -1); /* lightfunc throws */ + func = duk_require_hobject(thr, -1); /* lightfunc throws */ /* Rely on Function.prototype.bind() never creating bound * functions whose target is not proper. @@ -1116,19 +1096,19 @@ DUK_ASSERT(val != NULL); break; case DUK_TAG_OBJECT: - skip_first = 1; /* Ignore object itself on first round. */ + skip_first = 1; /* Ignore object itself on first round. */ val = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(val != NULL); break; default: goto pop2_and_false; } - DUK_ASSERT(val != NULL); /* Loop doesn't actually rely on this. */ + DUK_ASSERT(val != NULL); /* Loop doesn't actually rely on this. */ /* Look up .prototype of rval. Leave it on the value stack in case it * has been virtualized (e.g. getter, Proxy trap). */ - duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_PROTOTYPE); /* -> ... lval rval rval.prototype */ + duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_PROTOTYPE); /* -> ... lval rval rval.prototype */ #if defined(DUK_USE_VERBOSE_ERRORS) proto = duk_get_hobject(thr, -1); if (proto == NULL) { @@ -1181,24 +1161,24 @@ DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); DUK_WO_NORETURN(return 0;); - pop2_and_false: +pop2_and_false: duk_pop_2_unsafe(thr); return 0; - pop3_and_false: +pop3_and_false: duk_pop_3_unsafe(thr); return 0; - pop3_and_true: +pop3_and_true: duk_pop_3_unsafe(thr); return 1; - error_invalid_rval: +error_invalid_rval: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_INSTANCEOF_RVAL); DUK_WO_NORETURN(return 0;); #if defined(DUK_USE_VERBOSE_ERRORS) - error_invalid_rval_noproto: +error_invalid_rval_noproto: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO); DUK_WO_NORETURN(return 0;); #endif @@ -1250,9 +1230,7 @@ (void) duk_to_property_key_hstring(thr, -2); - retval = duk_hobject_hasprop(thr, - DUK_GET_TVAL_NEGIDX(thr, -1), - DUK_GET_TVAL_NEGIDX(thr, -2)); + retval = duk_hobject_hasprop(thr, DUK_GET_TVAL_NEGIDX(thr, -1), DUK_GET_TVAL_NEGIDX(thr, -2)); duk_pop_2_unsafe(thr); return retval; @@ -1412,7 +1390,7 @@ } res = 0xfffffffaUL + dig; DUK_ASSERT(res >= 0xfffffffaUL); - DUK_ASSERT_DISABLE(res <= 0xffffffffUL); /* range */ + DUK_ASSERT_DISABLE(res <= 0xffffffffUL); /* range */ } else { res = res * 10U + dig; if (DUK_UNLIKELY(res == 0)) { @@ -1437,7 +1415,7 @@ return res; - parse_fail: +parse_fail: return DUK_HSTRING_NO_ARRAY_INDEX; } @@ -1475,4 +1453,4 @@ } return duk_js_to_arrayindex_hstring_fast_known(h); } -#endif /* DUK_USE_HSTRING_ARRIDX */ +#endif /* DUK_USE_HSTRING_ARRIDX */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_js_var.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_js_var.c
Changed
@@ -38,10 +38,10 @@ typedef struct { duk_hobject *env; - duk_hobject *holder; /* for object-bound identifiers */ - duk_tval *value; /* for register-bound and declarative env identifiers */ - duk_uint_t attrs; /* property attributes for identifier (relevant if value != NULL) */ - duk_bool_t has_this; /* for object-bound identifiers: provide 'this' binding */ + duk_hobject *holder; /* for object-bound identifiers */ + duk_tval *value; /* for register-bound and declarative env identifiers */ + duk_uint_t attrs; /* property attributes for identifier (relevant if value != NULL) */ + duk_bool_t has_this; /* for object-bound identifiers: provide 'this' binding */ } duk__id_lookup_result; /* @@ -145,7 +145,7 @@ DUK_ASSERT(fun_clos != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) fun_clos) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); - duk_push_hobject(thr, &fun_temp->obj); /* -> ... closure template */ + duk_push_hobject(thr, &fun_temp->obj); /* -> ... closure template */ DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun_clos)); DUK_ASSERT(DUK_HCOMPFUNC_GET_DATA(thr->heap, fun_clos) == NULL); @@ -253,9 +253,9 @@ } /* -> ... closure template env */ - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); @@ -263,7 +263,7 @@ DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) new_env, proto); DUK_HOBJECT_INCREF_ALLOWNULL(thr, proto); - DUK_ASSERT(new_env->thread == NULL); /* Closed. */ + DUK_ASSERT(new_env->thread == NULL); /* Closed. */ DUK_ASSERT(new_env->varmap == NULL); /* It's important that duk_xdef_prop() is a 'raw define' so that any @@ -277,8 +277,8 @@ */ (void) duk_get_prop_stridx_short(thr, -2, DUK_STRIDX_NAME); /* -> ... closure template env funcname */ - duk_dup_m4(thr); /* -> ... closure template env funcname closure */ - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> ... closure template env */ + duk_dup_m4(thr); /* -> ... closure template env funcname closure */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> ... closure template env */ /* envfuncname = closure */ /* ... closure template env */ @@ -290,9 +290,8 @@ duk_pop_unsafe(thr); /* ... closure template */ - } - else -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ + } else +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ { /* * Other cases (function declaration, anonymous function expression, @@ -320,7 +319,7 @@ DUK_HCOMPFUNC_SET_LEXENV(thr->heap, fun_clos, outer_lex_env); DUK_HCOMPFUNC_SET_VARENV(thr->heap, fun_clos, outer_var_env); - DUK_HOBJECT_INCREF(thr, outer_lex_env); /* NULLs not allowed; asserted on entry */ + DUK_HOBJECT_INCREF(thr, outer_lex_env); /* NULLs not allowed; asserted on entry */ DUK_HOBJECT_INCREF(thr, outer_var_env); } DUK_DDD(DUK_DDDPRINT("closure varenv -> %!ipO, lexenv -> %!ipO", @@ -379,7 +378,7 @@ DUK_DD(DUK_DDPRINT("closure length defaulted from nargs -> %ld", (long) len_value)); } - duk_push_uint(thr, len_value); /* ... closure template len_value */ + duk_push_uint(thr, len_value); /* ... closure template len_value */ duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* @@ -399,11 +398,14 @@ /* ... closure template */ if (add_auto_proto) { - duk_push_object(thr); /* -> ... closure template newobj */ - duk_dup_m3(thr); /* -> ... closure template newobj closure */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC); /* -> ... closure template newobj */ - duk_compact(thr, -1); /* compact the prototype */ - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); /* -> ... closure template */ + duk_push_object(thr); /* -> ... closure template newobj */ + duk_dup_m3(thr); /* -> ... closure template newobj closure */ + duk_xdef_prop_stridx_short(thr, + -2, + DUK_STRIDX_CONSTRUCTOR, + DUK_PROPDESC_FLAGS_WC); /* -> ... closure template newobj */ + duk_compact(thr, -1); /* compact the prototype */ + duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); /* -> ... closure template */ } /* @@ -444,7 +446,7 @@ /* ... closure template name */ DUK_ASSERT(duk_is_string(thr, -1)); DUK_DD(DUK_DDPRINT("setting function instance name to %!T", duk_get_tval(thr, -1))); - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); /* -> ... closure template */ + duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); /* -> ... closure template */ } else { /* Anonymous functions don't have a .name in ES2015, so don't set * it on the instance either. The instance will then inherit @@ -476,10 +478,8 @@ DUK_ASSERT(duk_has_prop_stridx(thr, -2, DUK_STRIDX_LENGTH) != 0); DUK_ASSERT(add_auto_proto == 0 || duk_has_prop_stridx(thr, -2, DUK_STRIDX_PROTOTYPE) != 0); /* May be missing .name */ - DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || - duk_has_prop_stridx(thr, -2, DUK_STRIDX_CALLER) != 0); - DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || - duk_has_prop_stridx(thr, -2, DUK_STRIDX_LC_ARGUMENTS) != 0); + DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || duk_has_prop_stridx(thr, -2, DUK_STRIDX_CALLER) != 0); + DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || duk_has_prop_stridx(thr, -2, DUK_STRIDX_LC_ARGUMENTS) != 0); /* * Finish @@ -510,8 +510,8 @@ duk_hstring *key; key = DUK_HOBJECT_E_GET_KEY(thr->heap, varmap, i); - DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ - DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ + DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ + DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ /* Predefine as 'undefined' to reserve a property slot. * This makes the unwind process (where register values @@ -528,9 +528,7 @@ /* shared helper */ DUK_INTERNAL -duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, - duk_hobject *func, - duk_size_t bottom_byteoff) { +duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, duk_hobject *func, duk_size_t bottom_byteoff) { duk_hdecenv *env; duk_hobject *parent; duk_hcompfunc *f; @@ -546,15 +544,13 @@ parent = thr->builtinsDUK_BIDX_GLOBAL_ENV; } - env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + env = duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(env != NULL); duk_push_hobject(thr, (duk_hobject *) env); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) env, parent); - DUK_HOBJECT_INCREF_ALLOWNULL(thr, parent); /* parent env is the prototype */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, parent); /* parent env is the prototype */ /* open scope information, for compiled functions only */ @@ -588,15 +584,14 @@ } DUK_INTERNAL -void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, - duk_activation *act) { +void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, duk_activation *act) { duk_hobject *func; duk_hobject *env; DUK_ASSERT(thr != NULL); func = DUK_ACT_GET_FUNC(act); DUK_ASSERT(func != NULL); - DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound functions are never in act 'func' */ + DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound functions are never in act 'func' */ /* * Delayed initialization only occurs for 'NEWENV' functions. @@ -625,7 +620,7 @@ act->lex_env = env; act->var_env = env; - DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (here 2 times) */ + DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (here 2 times) */ DUK_HOBJECT_INCREF(thr, env); duk_pop_unsafe(thr); @@ -695,12 +690,12 @@ duk_size_t regbase_byteoff; key = DUK_HOBJECT_E_GET_KEY(thr->heap, varmap, i); - DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ - DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ + DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ + DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ tv = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, varmap, i); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ + DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv)); regnum = (duk_uint_t) DUK_TVAL_GET_FASTINT_U32(tv); @@ -709,8 +704,10 @@ #endif regbase_byteoff = ((duk_hdecenv *) env)->regbase_byteoff; - DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum >= (duk_uint8_t *) thr->valstack); - DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum < (duk_uint8_t *) thr->valstack_top); + DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum >= + (duk_uint8_t *) thr->valstack); + DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum < + (duk_uint8_t *) thr->valstack_top); /* Write register value into env as named properties. * If property already exists, overwrites silently. @@ -724,7 +721,8 @@ * out-of-memory error should be possible. If this guarantee * is not provided, problems like GH-476 may happen. */ - duk_push_tval(thr, (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum)); + duk_push_tval(thr, + (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum)); DUK_DDD(DUK_DDDPRINT("closing identifier %!O -> reg %ld, value %!T", (duk_heaphdr *) key, (long) regnum, @@ -766,10 +764,7 @@ /* lookup name from an open declarative record's registers */ DUK_LOCAL -duk_bool_t duk__getid_open_decl_env_regs(duk_hthread *thr, - duk_hstring *name, - duk_hdecenv *env, - duk__id_lookup_result *out) { +duk_bool_t duk__getid_open_decl_env_regs(duk_hthread *thr, duk_hstring *name, duk_hdecenv *env, duk__id_lookup_result *out) { duk_tval *tv; duk_size_t reg_rel; @@ -793,20 +788,20 @@ } DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ + DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv)); reg_rel = (duk_size_t) DUK_TVAL_GET_FASTINT_U32(tv); #else reg_rel = (duk_size_t) DUK_TVAL_GET_NUMBER(tv); #endif - DUK_ASSERT_DISABLE(reg_rel >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(reg_rel >= 0); /* unsigned */ tv = (duk_tval *) (void *) ((duk_uint8_t *) env->thread->valstack + env->regbase_byteoff + sizeof(duk_tval) * reg_rel); - DUK_ASSERT(tv >= env->thread->valstack && tv < env->thread->valstack_end); /* XXX: more accurate? */ + DUK_ASSERT(tv >= env->thread->valstack && tv < env->thread->valstack_end); /* XXX: more accurate? */ out->value = tv; - out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ + out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ out->env = (duk_hobject *) env; out->holder = NULL; out->has_this = 0; @@ -815,10 +810,7 @@ /* lookup name from current activation record's functions' registers */ DUK_LOCAL -duk_bool_t duk__getid_activation_regs(duk_hthread *thr, - duk_hstring *name, - duk_activation *act, - duk__id_lookup_result *out) { +duk_bool_t duk__getid_activation_regs(duk_hthread *thr, duk_hstring *name, duk_activation *act, duk__id_lookup_result *out) { duk_tval *tv; duk_hobject *func; duk_hobject *varmap; @@ -856,7 +848,7 @@ tv += reg_rel; out->value = tv; - out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ + out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ out->env = NULL; out->holder = NULL; out->has_this = 0; @@ -912,9 +904,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(found from register bindings when env=NULL)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } @@ -951,8 +946,7 @@ env = thr->builtinsDUK_BIDX_GLOBAL_ENV; } - DUK_DDD(DUK_DDDPRINT("continue lookup from env: %!iO", - (duk_heaphdr *) env)); + DUK_DDD(DUK_DDDPRINT("continue lookup from env: %!iO", (duk_heaphdr *) env)); } /* @@ -995,9 +989,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(declarative environment record, scope open, found in regs)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } @@ -1012,9 +1009,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(declarative environment record, found in properties)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } } else { @@ -1059,7 +1059,7 @@ found = duk_hobject_hasprop(thr, &tv_target_tmp, &tv_name); } else -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ { /* XXX: duk_hobject_hasprop() would be correct for * non-Proxy objects too, but it is about ~20-25% @@ -1070,8 +1070,8 @@ } if (found) { - out->value = NULL; /* can't get value, may be accessor */ - out->attrs = 0; /* irrelevant when out->value == NULL */ + out->value = NULL; /* can't get value, may be accessor */ + out->attrs = 0; /* irrelevant when out->value == NULL */ out->env = env; out->holder = target; out->has_this = ((duk_hobjenv *) env)->has_this; @@ -1079,9 +1079,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(object environment record)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } } @@ -1092,10 +1095,10 @@ goto fail_not_found; } - if (DUK_UNLIKELY(sanity-- == 0)) { - DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); + if (DUK_UNLIKELY(sanity-- == 0)) { + DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); DUK_WO_NORETURN(return 0;); - } + } env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); } @@ -1103,7 +1106,7 @@ * Not found (even in global object) */ - fail_not_found: +fail_not_found: return 0; } @@ -1122,7 +1125,7 @@ * a 'strict' parameter. */ -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_hasvar_envrec(duk_hthread *thr, duk_hobject *env, @@ -1178,11 +1181,7 @@ */ DUK_LOCAL -duk_bool_t duk__getvar_helper(duk_hthread *thr, - duk_hobject *env, - duk_activation *act, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk__getvar_helper(duk_hthread *thr, duk_hobject *env, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag) { duk__id_lookup_result ref; duk_tval tv_tmp_obj; duk_tval tv_tmp_key; @@ -1190,8 +1189,11 @@ DUK_DDD(DUK_DDDPRINT("getvar: thr=%p, env=%p, act=%p, name=%!O " "(env -> %!dO)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); @@ -1199,10 +1201,10 @@ DUK_STATS_INC(thr->heap, stats_getvar_all); - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(env); - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(env); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value) { duk_push_tval(thr, ref.value); @@ -1217,7 +1219,7 @@ DUK_TVAL_SET_OBJECT(&tv_tmp_obj, ref.holder); DUK_TVAL_SET_STRING(&tv_tmp_key, name); - (void) duk_hobject_getprop(thr, &tv_tmp_obj, &tv_tmp_key); /* value */ + (void) duk_hobject_getprop(thr, &tv_tmp_obj, &tv_tmp_key); /* value */ if (ref.has_this) { duk_push_hobject(thr, ref.holder); @@ -1231,7 +1233,8 @@ return 1; } else { if (throw_flag) { - DUK_ERROR_FMT1(thr, DUK_ERR_REFERENCE_ERROR, + DUK_ERROR_FMT1(thr, + DUK_ERR_REFERENCE_ERROR, "identifier '%s' undefined", (const char *) DUK_HSTRING_GET_DATA(name)); DUK_WO_NORETURN(return 0;); @@ -1242,18 +1245,12 @@ } DUK_INTERNAL -duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, - duk_hobject *env, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_bool_t throw_flag) { return duk__getvar_helper(thr, env, NULL, name, throw_flag); } DUK_INTERNAL -duk_bool_t duk_js_getvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk_js_getvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag) { DUK_ASSERT(act != NULL); return duk__getvar_helper(thr, act->lex_env, act, name, throw_flag); } @@ -1290,9 +1287,14 @@ DUK_DDD(DUK_DDDPRINT("putvar: thr=%p, env=%p, act=%p, name=%!O, val=%p, strict=%ld " "(env -> %!dO, val -> %!T)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (void *) val, (long) strict, - (duk_heaphdr *) env, (duk_tval *) val)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (void *) val, + (long) strict, + (duk_heaphdr *) env, + (duk_tval *) val)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); @@ -1303,7 +1305,7 @@ DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); DUK_ASSERT_REFCOUNT_NONZERO_TVAL(val); - DUK_TVAL_SET_TVAL(&tv_tmp_val, val); /* Stabilize. */ + DUK_TVAL_SET_TVAL(&tv_tmp_val, val); /* Stabilize. */ val = NULL; /* @@ -1316,15 +1318,13 @@ * and name 'eval' or 'arguments'. */ - DUK_ASSERT(!strict || - (name != DUK_HTHREAD_STRING_EVAL(thr) && - name != DUK_HTHREAD_STRING_LC_ARGUMENTS(thr))); + DUK_ASSERT(!strict || (name != DUK_HTHREAD_STRING_EVAL(thr) && name != DUK_HTHREAD_STRING_LC_ARGUMENTS(thr))); /* * Lookup variable and update in-place if found. */ - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value && (ref.attrs & DUK_PROPDESC_FLAG_WRITABLE)) { @@ -1337,7 +1337,7 @@ tv_val = ref.value; DUK_ASSERT(tv_val != NULL); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv_val, &tv_tmp_val); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv_val, &tv_tmp_val); /* side effects */ /* ref.value invalidated here */ } else { @@ -1360,7 +1360,8 @@ if (strict) { DUK_DDD(DUK_DDDPRINT("identifier binding not found, strict => reference error")); - DUK_ERROR_FMT1(thr, DUK_ERR_REFERENCE_ERROR, + DUK_ERROR_FMT1(thr, + DUK_ERR_REFERENCE_ERROR, "identifier '%s' undefined", (const char *) DUK_HSTRING_GET_DATA(name)); DUK_WO_NORETURN(return;); @@ -1370,7 +1371,7 @@ DUK_TVAL_SET_OBJECT(&tv_tmp_obj, thr->builtinsDUK_BIDX_GLOBAL); DUK_TVAL_SET_STRING(&tv_tmp_key, name); - (void) duk_hobject_putprop(thr, &tv_tmp_obj, &tv_tmp_key, &tv_tmp_val, 0); /* 0 = no throw */ + (void) duk_hobject_putprop(thr, &tv_tmp_obj, &tv_tmp_key, &tv_tmp_val, 0); /* 0 = no throw */ /* NB: 'val' may be invalidated here because put_value may realloc valstack, * caller beware. @@ -1378,20 +1379,12 @@ } DUK_INTERNAL -void duk_js_putvar_envrec(duk_hthread *thr, - duk_hobject *env, - duk_hstring *name, - duk_tval *val, - duk_bool_t strict) { +void duk_js_putvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_tval *val, duk_bool_t strict) { duk__putvar_helper(thr, env, NULL, name, val, strict); } DUK_INTERNAL -void duk_js_putvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name, - duk_tval *val, - duk_bool_t strict) { +void duk_js_putvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_bool_t strict) { DUK_ASSERT(act != NULL); duk__putvar_helper(thr, act->lex_env, act, name, val, strict); } @@ -1416,25 +1409,25 @@ */ DUK_LOCAL -duk_bool_t duk__delvar_helper(duk_hthread *thr, - duk_hobject *env, - duk_activation *act, - duk_hstring *name) { +duk_bool_t duk__delvar_helper(duk_hthread *thr, duk_hobject *env, duk_activation *act, duk_hstring *name) { duk__id_lookup_result ref; duk_bool_t parents; DUK_DDD(DUK_DDDPRINT("delvar: thr=%p, env=%p, act=%p, name=%!O " "(env -> %!dO)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); /* env and act may be NULL */ - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value && !(ref.attrs & DUK_PROPDESC_FLAG_CONFIGURABLE)) { @@ -1462,7 +1455,7 @@ return 1; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_delvar_envrec(duk_hthread *thr, duk_hobject *env, @@ -1472,9 +1465,7 @@ #endif DUK_INTERNAL -duk_bool_t duk_js_delvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name) { +duk_bool_t duk_js_delvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name) { DUK_ASSERT(act != NULL); return duk__delvar_helper(thr, act->lex_env, act, name); } @@ -1543,9 +1534,13 @@ DUK_DDD(DUK_DDDPRINT("declvar: thr=%p, env=%p, name=%!O, val=%!T, prop_flags=0x%08lx, is_func_decl=%ld " "(env -> %!iO)", - (void *) thr, (void *) env, (duk_heaphdr *) name, - (duk_tval *) val, (unsigned long) prop_flags, - (unsigned int) is_func_decl, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (duk_heaphdr *) name, + (duk_tval *) val, + (unsigned long) prop_flags, + (unsigned int) is_func_decl, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(env != NULL); @@ -1572,7 +1567,7 @@ * environment target object. */ - parents = 0; /* just check 'env' */ + parents = 0; /* just check 'env' */ if (duk__get_identifier_reference(thr, env, name, NULL, parents, &ref)) { duk_int_t e_idx; duk_int_t h_idx; @@ -1587,7 +1582,7 @@ if (!(is_func_decl && env == thr->builtinsDUK_BIDX_GLOBAL_ENV)) { DUK_DDD(DUK_DDDPRINT("re-declare a binding, ignoring")); - return 1; /* 1 -> needs a PUTVAR */ + return 1; /* 1 -> needs a PUTVAR */ } /* @@ -1617,7 +1612,7 @@ * where the property was found (see duk__get_identifier_reference()). */ DUK_ASSERT(DUK_HOBJECT_GET_CLASS_NUMBER(holder) == DUK_HOBJECT_CLASS_GLOBAL); - DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(holder)); /* global object doesn't have array part */ + DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(holder)); /* global object doesn't have array part */ /* XXX: use a helper for prototype traversal; no loop check here */ /* must be found: was found earlier, and cannot be inherited */ @@ -1650,8 +1645,7 @@ "accessor -> reject")); goto fail_existing_attributes; } - if (!((flags & DUK_PROPDESC_FLAG_WRITABLE) && - (flags & DUK_PROPDESC_FLAG_ENUMERABLE))) { + if (!((flags & DUK_PROPDESC_FLAG_WRITABLE) && (flags & DUK_PROPDESC_FLAG_ENUMERABLE))) { DUK_DDD(DUK_DDDPRINT("existing property is a non-configurable " "plain property which is not writable and " "enumerable -> reject")); @@ -1746,13 +1740,13 @@ duk_push_hobject(thr, holder); duk_push_hstring(thr, name); duk_push_tval(thr, val); - duk_xdef_prop(thr, -3, prop_flags); /* holder name val -> holder */ + duk_xdef_prop(thr, -3, prop_flags); /* holder name val -> holder */ duk_pop_unsafe(thr); return 0; - fail_existing_attributes: - fail_not_extensible: +fail_existing_attributes: +fail_not_extensible: DUK_ERROR_TYPE(thr, "declaration failed"); DUK_WO_NORETURN(return 0;); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_json.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_json.h
Changed
@@ -6,28 +6,28 @@ #define DUK_JSON_H_INCLUDED /* Encoding/decoding flags */ -#define DUK_JSON_FLAG_ASCII_ONLY (1U << 0) /* escape any non-ASCII characters */ -#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1U << 1) /* avoid key quotes when key is an ASCII Identifier */ -#define DUK_JSON_FLAG_EXT_CUSTOM (1U << 2) /* extended types: custom encoding */ -#define DUK_JSON_FLAG_EXT_COMPATIBLE (1U << 3) /* extended types: compatible encoding */ +#define DUK_JSON_FLAG_ASCII_ONLY (1U << 0) /* escape any non-ASCII characters */ +#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1U << 1) /* avoid key quotes when key is an ASCII Identifier */ +#define DUK_JSON_FLAG_EXT_CUSTOM (1U << 2) /* extended types: custom encoding */ +#define DUK_JSON_FLAG_EXT_COMPATIBLE (1U << 3) /* extended types: compatible encoding */ /* How much stack to require on entry to object/array encode */ -#define DUK_JSON_ENC_REQSTACK 32 +#define DUK_JSON_ENC_REQSTACK 32 /* How much stack to require on entry to object/array decode */ -#define DUK_JSON_DEC_REQSTACK 32 +#define DUK_JSON_DEC_REQSTACK 32 /* How large a loop detection stack to use */ -#define DUK_JSON_ENC_LOOPARRAY 64 +#define DUK_JSON_ENC_LOOPARRAY 64 /* Encoding state. Heap object references are all borrowed. */ typedef struct { duk_hthread *thr; - duk_bufwriter_ctx bw; /* output bufwriter */ - duk_hobject *h_replacer; /* replacer function */ - duk_hstring *h_gap; /* gap (if empty string, NULL) */ - duk_idx_t idx_proplist; /* explicit PropertyList */ - duk_idx_t idx_loop; /* valstack index of loop detection object */ + duk_bufwriter_ctx bw; /* output bufwriter */ + duk_hobject *h_replacer; /* replacer function */ + duk_hstring *h_gap; /* gap (if empty string, NULL) */ + duk_idx_t idx_proplist; /* explicit PropertyList */ + duk_idx_t idx_loop; /* valstack index of loop detection object */ duk_small_uint_t flags; duk_small_uint_t flag_ascii_only; duk_small_uint_t flag_avoid_key_quotes; @@ -38,7 +38,7 @@ #endif duk_uint_t recursion_depth; duk_uint_t recursion_limit; - duk_uint_t mask_for_undefined; /* type bit mask: types which certainly produce 'undefined' */ + duk_uint_t mask_for_undefined; /* type bit mask: types which certainly produce 'undefined' */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) duk_small_uint_t stridx_custom_undefined; duk_small_uint_t stridx_custom_nan; @@ -46,7 +46,7 @@ duk_small_uint_t stridx_custom_posinf; duk_small_uint_t stridx_custom_function; #endif - duk_hobject *visitingDUK_JSON_ENC_LOOPARRAY; /* indexed by recursion_depth */ + duk_hobject *visitingDUK_JSON_ENC_LOOPARRAY; /* indexed by recursion_depth */ } duk_json_enc_ctx; typedef struct { @@ -65,4 +65,4 @@ duk_int_t recursion_limit; } duk_json_dec_ctx; -#endif /* DUK_JSON_H_INCLUDED */ +#endif /* DUK_JSON_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_lexer.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_lexer.c
Changed
@@ -76,34 +76,34 @@ * Various defines and file specific helper macros */ -#define DUK__MAX_RE_DECESC_DIGITS 9 -#define DUK__MAX_RE_QUANT_DIGITS 9 /* Does not allow e.g. 2**31-1, but one more would allow overflows of u32. */ +#define DUK__MAX_RE_DECESC_DIGITS 9 +#define DUK__MAX_RE_QUANT_DIGITS 9 /* Does not allow e.g. 2**31-1, but one more would allow overflows of u32. */ /* whether to use macros or helper function depends on call count */ -#define DUK__ISDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_9) -#define DUK__ISHEXDIGIT(x) duk__is_hex_digit((x)) -#define DUK__ISOCTDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_7) -#define DUK__ISDIGIT03(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_3) -#define DUK__ISDIGIT47(x) ((x) >= DUK_ASC_4 && (x) <= DUK_ASC_7) +#define DUK__ISDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_9) +#define DUK__ISHEXDIGIT(x) duk__is_hex_digit((x)) +#define DUK__ISOCTDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_7) +#define DUK__ISDIGIT03(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_3) +#define DUK__ISDIGIT47(x) ((x) >= DUK_ASC_4 && (x) <= DUK_ASC_7) /* lexer character window helpers */ -#define DUK__LOOKUP(lex_ctx,idx) ((lex_ctx)->window(idx).codepoint) -#define DUK__ADVANCECHARS(lex_ctx,count) duk__advance_chars((lex_ctx), (count)) -#define DUK__ADVANCEBYTES(lex_ctx,count) duk__advance_bytes((lex_ctx), (count)) +#define DUK__LOOKUP(lex_ctx, idx) ((lex_ctx)->window(idx).codepoint) +#define DUK__ADVANCECHARS(lex_ctx, count) duk__advance_chars((lex_ctx), (count)) +#define DUK__ADVANCEBYTES(lex_ctx, count) duk__advance_bytes((lex_ctx), (count)) #define DUK__INITBUFFER(lex_ctx) duk__initbuffer((lex_ctx)) -#define DUK__APPENDBUFFER(lex_ctx,x) duk__appendbuffer((lex_ctx), (duk_codepoint_t) (x)) -#define DUK__APPENDBUFFER_ASCII(lex_ctx,x) duk__appendbuffer_ascii((lex_ctx), (duk_codepoint_t) (x)) +#define DUK__APPENDBUFFER(lex_ctx, x) duk__appendbuffer((lex_ctx), (duk_codepoint_t) (x)) +#define DUK__APPENDBUFFER_ASCII(lex_ctx, x) duk__appendbuffer_ascii((lex_ctx), (duk_codepoint_t) (x)) /* lookup shorthands (note: assume context variable is named 'lex_ctx') */ -#define DUK__L0() DUK__LOOKUP(lex_ctx, 0) -#define DUK__L1() DUK__LOOKUP(lex_ctx, 1) -#define DUK__L2() DUK__LOOKUP(lex_ctx, 2) -#define DUK__L3() DUK__LOOKUP(lex_ctx, 3) -#define DUK__L4() DUK__LOOKUP(lex_ctx, 4) -#define DUK__L5() DUK__LOOKUP(lex_ctx, 5) +#define DUK__L0() DUK__LOOKUP(lex_ctx, 0) +#define DUK__L1() DUK__LOOKUP(lex_ctx, 1) +#define DUK__L2() DUK__LOOKUP(lex_ctx, 2) +#define DUK__L3() DUK__LOOKUP(lex_ctx, 3) +#define DUK__L4() DUK__LOOKUP(lex_ctx, 4) +#define DUK__L5() DUK__LOOKUP(lex_ctx, 5) /* packed advance/token number macro used by multiple functions */ -#define DUK__ADVTOK(advbytes,tok) ((((advbytes) * sizeof(duk_lexer_codepoint)) << 8) + (tok)) +#define DUK__ADVTOK(advbytes, tok) ((((advbytes) * sizeof(duk_lexer_codepoint)) << 8) + (tok)) /* * Advance lookup window by N characters, filling in new characters as @@ -213,10 +213,9 @@ /* Fast path. */ if (DUK_LIKELY(x < 0x80UL)) { - DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ + DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ if (DUK_UNLIKELY(x <= 0x000dUL)) { - if ((x == 0x000aUL) || - ((x == 0x000dUL) && (p >= p_end || *p != 0x000aUL))) { + if ((x == 0x000aUL) || ((x == 0x000dUL) && (p >= p_end || *p != 0x000aUL))) { /* lookup for 0x000a above assumes shortest encoding now */ /* E5 Section 7.3, treat the following as newlines: @@ -307,8 +306,8 @@ lex_ctx->input_line = input_line; return; - error_clipped: /* clipped codepoint */ - error_encoding: /* invalid codepoint encoding or codepoint */ +error_clipped: /* clipped codepoint */ +error_encoding: /* invalid codepoint encoding or codepoint */ lex_ctx->input_offset = (duk_size_t) (p - lex_ctx->input); lex_ctx->input_line = input_line; @@ -319,26 +318,25 @@ DUK_LOCAL void duk__advance_bytes(duk_lexer_ctx *lex_ctx, duk_small_uint_t count_bytes) { duk_small_uint_t used_bytes, avail_bytes; - DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ DUK_ASSERT(count_bytes <= (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))); DUK_ASSERT(lex_ctx->window >= lex_ctx->buffer); DUK_ASSERT(lex_ctx->window < lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE); - DUK_ASSERT((duk_uint8_t *) lex_ctx->window + count_bytes <= (duk_uint8_t *) lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint)); + DUK_ASSERT((duk_uint8_t *) lex_ctx->window + count_bytes <= + (duk_uint8_t *) lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint)); /* Zero 'count' is also allowed to make call sites easier. * Arithmetic in bytes generates better code in GCC. */ - lex_ctx->window = (duk_lexer_codepoint *) (void *) ((duk_uint8_t *) lex_ctx->window + count_bytes); /* avoid multiply */ + lex_ctx->window = (duk_lexer_codepoint *) (void *) ((duk_uint8_t *) lex_ctx->window + count_bytes); /* avoid multiply */ used_bytes = (duk_small_uint_t) ((duk_uint8_t *) lex_ctx->window - (duk_uint8_t *) lex_ctx->buffer); avail_bytes = DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint) - used_bytes; if (avail_bytes < (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))) { /* Not enough data to provide a full window, so "scroll" window to * start of buffer and fill up the rest. */ - duk_memmove((void *) lex_ctx->buffer, - (const void *) lex_ctx->window, - (size_t) avail_bytes); + duk_memmove((void *) lex_ctx->buffer, (const void *) lex_ctx->window, (size_t) avail_bytes); lex_ctx->window = lex_ctx->buffer; duk__fill_lexer_buffer(lex_ctx, avail_bytes); } @@ -348,7 +346,7 @@ lex_ctx->window = lex_ctx->buffer; duk__fill_lexer_buffer(lex_ctx, 0); } -#else /* DUK_USE_LEXER_SLIDING_WINDOW */ +#else /* DUK_USE_LEXER_SLIDING_WINDOW */ DUK_LOCAL duk_codepoint_t duk__read_char(duk_lexer_ctx *lex_ctx) { duk_ucodepoint_t x; duk_small_uint_t len; @@ -378,11 +376,10 @@ /* input offset tracking */ lex_ctx->input_offset++; - DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ + DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ if (DUK_UNLIKELY(x <= 0x000dUL)) { - if ((x == 0x000aUL) || - ((x == 0x000dUL) && (lex_ctx->input_offset >= lex_ctx->input_length || - lex_ctx->inputlex_ctx->input_offset != 0x000aUL))) { + if ((x == 0x000aUL) || ((x == 0x000dUL) && (lex_ctx->input_offset >= lex_ctx->input_length || + lex_ctx->inputlex_ctx->input_offset != 0x000aUL))) { /* lookup for 0x000a above assumes shortest encoding now */ /* E5 Section 7.3, treat the following as newlines: @@ -471,8 +468,8 @@ return (duk_codepoint_t) x; - error_clipped: /* clipped codepoint */ - error_encoding: /* invalid codepoint encoding or codepoint */ +error_clipped: /* clipped codepoint */ +error_encoding: /* invalid codepoint encoding or codepoint */ DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_SOURCE_DECODE_FAILED); DUK_WO_NORETURN(return 0;); } @@ -481,15 +478,13 @@ duk_small_uint_t keep_bytes; duk_lexer_codepoint *cp, *cp_end; - DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ DUK_ASSERT(count_bytes <= (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))); /* Zero 'count' is also allowed to make call sites easier. */ keep_bytes = DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint) - count_bytes; - duk_memmove((void *) lex_ctx->window, - (const void *) ((duk_uint8_t *) lex_ctx->window + count_bytes), - (size_t) keep_bytes); + duk_memmove((void *) lex_ctx->window, (const void *) ((duk_uint8_t *) lex_ctx->window + count_bytes), (size_t) keep_bytes); cp = (duk_lexer_codepoint *) ((duk_uint8_t *) lex_ctx->window + keep_bytes); cp_end = lex_ctx->window + DUK_LEXER_WINDOW_SIZE; @@ -502,9 +497,9 @@ DUK_LOCAL void duk__init_lexer_window(duk_lexer_ctx *lex_ctx) { /* Call with count == DUK_LEXER_WINDOW_SIZE to fill buffer initially. */ - duk__advance_bytes(lex_ctx, DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint)); /* fill window */ + duk__advance_bytes(lex_ctx, DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint)); /* fill window */ } -#endif /* DUK_USE_LEXER_SLIDING_WINDOW */ +#endif /* DUK_USE_LEXER_SLIDING_WINDOW */ DUK_LOCAL void duk__advance_chars(duk_lexer_ctx *lex_ctx, duk_small_uint_t count_chars) { duk__advance_bytes(lex_ctx, count_chars * sizeof(duk_lexer_codepoint)); @@ -597,7 +592,7 @@ } DUK_INTERNAL void duk_lexer_setpoint(duk_lexer_ctx *lex_ctx, duk_lexer_point *pt) { - DUK_ASSERT_DISABLE(pt->offset >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(pt->offset >= 0); /* unsigned */ DUK_ASSERT(pt->line >= 1); lex_ctx->input_offset = pt->offset; lex_ctx->input_line = pt->line; @@ -631,8 +626,7 @@ DUK_LOCAL duk_codepoint_t duk__hexval(duk_codepoint_t x) { duk_codepoint_t ret; - DUK_ASSERT((x >= DUK_ASC_0 && x <= DUK_ASC_9) || - (x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_F) || + DUK_ASSERT((x >= DUK_ASC_0 && x <= DUK_ASC_9) || (x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_F) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_F)); ret = duk__hexval_validate(x); DUK_ASSERT(ret >= 0 && ret <= 15); @@ -651,12 +645,12 @@ * source and RegExp parsing. */ DUK_LOCAL duk_codepoint_t duk__lexer_parse_escape(duk_lexer_ctx *lex_ctx, duk_bool_t allow_es6) { - duk_small_int_t digits; /* Initial value 2 or 4 for fixed length escapes, 0 for ES2015 \u{H+}. */ + duk_small_int_t digits; /* Initial value 2 or 4 for fixed length escapes, 0 for ES2015 \u{H+}. */ duk_codepoint_t escval; duk_codepoint_t x; duk_small_uint_t adv; - DUK_ASSERT(DUK__L0() == DUK_ASC_BACKSLASH); /* caller responsibilities */ + DUK_ASSERT(DUK__L0() == DUK_ASC_BACKSLASH); /* caller responsibilities */ DUK_ASSERT(DUK__L1() == DUK_ASC_LC_X || DUK__L1() == DUK_ASC_LC_U); DUK_UNREF(allow_es6); @@ -730,16 +724,16 @@ } else { goto fail_escape; } - digits = -1; /* Indicate we have at least one digit. */ -#else /* DUK_USE_ES6_UNICODE_ESCAPE */ - DUK_ASSERT(0); /* Never happens if \u{H+} support disabled. */ -#endif /* DUK_USE_ES6_UNICODE_ESCAPE */ + digits = -1; /* Indicate we have at least one digit. */ +#else /* DUK_USE_ES6_UNICODE_ESCAPE */ + DUK_ASSERT(0); /* Never happens if \u{H+} support disabled. */ +#endif /* DUK_USE_ES6_UNICODE_ESCAPE */ } } return escval; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return 0;); } @@ -749,7 +743,9 @@ * RegExp octal escape parsing. Window0 must be the slash '\' and the first * digit must already be validated to be in 0-9 by the caller. */ -DUK_LOCAL duk_codepoint_t duk__lexer_parse_legacy_octal(duk_lexer_ctx *lex_ctx, duk_small_uint_t *out_adv, duk_bool_t reject_annex_b) { +DUK_LOCAL duk_codepoint_t duk__lexer_parse_legacy_octal(duk_lexer_ctx *lex_ctx, + duk_small_uint_t *out_adv, + duk_bool_t reject_annex_b) { duk_codepoint_t cp; duk_small_uint_t lookup_idx; duk_small_uint_t adv; @@ -784,7 +780,7 @@ DUK_DDD(DUK_DDDPRINT("\\8 or \\9 -> treat as literal, accept in strict mode too")); DUK_ASSERT(tmp == DUK_ASC_8 || tmp == DUK_ASC_9); cp = tmp; - adv++; /* correction to above, eat offending character */ + adv++; /* correction to above, eat offending character */ } else if (lookup_idx == 2 && cp == 0) { /* Note: 'foo\0bar' is OK in strict mode, but 'foo\00bar' is not. * It won't be interpreted as 'foo\u{0}0bar' but as a SyntaxError. @@ -808,18 +804,21 @@ } /* XXX: move strict mode to lex_ctx? */ -DUK_LOCAL void duk__lexer_parse_string_literal(duk_lexer_ctx *lex_ctx, duk_token *out_token, duk_small_int_t quote, duk_bool_t strict_mode) { +DUK_LOCAL void duk__lexer_parse_string_literal(duk_lexer_ctx *lex_ctx, + duk_token *out_token, + duk_small_int_t quote, + duk_bool_t strict_mode) { duk_small_uint_t adv; - for (adv = 1 /* initial quote */ ;;) { + for (adv = 1 /* initial quote */;;) { duk_codepoint_t x; - DUK__ADVANCECHARS(lex_ctx, adv); /* eat opening quote on first loop */ + DUK__ADVANCECHARS(lex_ctx, adv); /* eat opening quote on first loop */ x = DUK__L0(); adv = 1; if (x == quote) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing quote */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing quote */ break; } else if (x == '\\') { /* DUK__L0 -> '\' char @@ -830,7 +829,7 @@ x = DUK__L1(); /* How much to advance before next loop. */ - adv = 2; /* note: long live range */ + adv = 2; /* note: long live range */ switch (x) { case '\'': @@ -873,7 +872,7 @@ /* line continuation */ if (x == 0x000d && DUK__L2() == 0x000a) { /* CR LF again a special case */ - adv = 3; /* line terminator, CR, LF */ + adv = 3; /* line terminator, CR, LF */ } } else if (DUK__ISDIGIT(x)) { /* @@ -902,8 +901,8 @@ /* escaped NonEscapeCharacter */ DUK__APPENDBUFFER(lex_ctx, x); } - } /* end default clause */ - } /* end switch */ + } /* end default clause */ + } /* end switch */ /* Shared handling for single codepoint escapes. */ if (emitcp >= 0) { @@ -936,11 +935,11 @@ return; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return;); - fail_unterminated: +fail_unterminated: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_STRING); DUK_WO_NORETURN(return;); } @@ -1027,19 +1026,19 @@ duk_token *out_token, duk_bool_t strict_mode, duk_bool_t regexp_mode) { - duk_codepoint_t x; /* temporary, must be signed and 32-bit to hold Unicode code points */ + duk_codepoint_t x; /* temporary, must be signed and 32-bit to hold Unicode code points */ duk_small_uint_t advtok = 0; /* (advance << 8) + token_type, updated at function end, * init is unnecessary but suppresses "may be used uninitialized" warnings. */ - duk_bool_t got_lineterm = 0; /* got lineterm preceding non-whitespace, non-lineterm token */ + duk_bool_t got_lineterm = 0; /* got lineterm preceding non-whitespace, non-lineterm token */ if (++lex_ctx->token_count >= lex_ctx->token_limit) { goto fail_token_limit; } out_token->t = DUK_TOK_EOF; - out_token->t_nores = DUK_TOK_INVALID; /* marker: copy t if not changed */ -#if 0 /* not necessary to init, disabled for faster parsing */ + out_token->t_nores = DUK_TOK_INVALID; /* marker: copy t if not changed */ +#if 0 /* not necessary to init, disabled for faster parsing */ out_token->num = DUK_DOUBLE_NAN; out_token->str1 = NULL; out_token->str2 = NULL; @@ -1079,35 +1078,34 @@ * in the clauses, so it's not trivial to convert to a switch. */ - restart_lineupdate: +restart_lineupdate: out_token->start_line = lex_ctx->window0.line; - restart: +restart: out_token->start_offset = lex_ctx->window0.offset; x = DUK__L0(); switch (x) { case DUK_ASC_SPACE: - case DUK_ASC_HT: /* fast paths for space and tab */ + case DUK_ASC_HT: /* fast paths for space and tab */ DUK__ADVANCECHARS(lex_ctx, 1); goto restart; - case DUK_ASC_LF: /* LF line terminator; CR LF and Unicode lineterms are handled in slow path */ + case DUK_ASC_LF: /* LF line terminator; CR LF and Unicode lineterms are handled in slow path */ DUK__ADVANCECHARS(lex_ctx, 1); got_lineterm = 1; goto restart_lineupdate; #if defined(DUK_USE_SHEBANG_COMMENTS) - case DUK_ASC_HASH: /* '#' */ - if (DUK__L1() == DUK_ASC_EXCLAMATION && lex_ctx->window0.offset == 0 && - (lex_ctx->flags & DUK_COMPILE_SHEBANG)) { + case DUK_ASC_HASH: /* '#' */ + if (DUK__L1() == DUK_ASC_EXCLAMATION && lex_ctx->window0.offset == 0 && (lex_ctx->flags & DUK_COMPILE_SHEBANG)) { /* "Shebang" comment ('#! ...') on first line. */ /* DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } goto fail_token; -#endif /* DUK_USE_SHEBANG_COMMENTS */ - case DUK_ASC_SLASH: /* '/' */ +#endif /* DUK_USE_SHEBANG_COMMENTS */ + case DUK_ASC_SLASH: /* '/' */ if (DUK__L1() == DUK_ASC_SLASH) { /* * E5 Section 7.4, allow SourceCharacter (which is any 16-bit @@ -1116,7 +1114,7 @@ /* DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } else if (DUK__L1() == DUK_ASC_STAR) { /* * E5 Section 7.4. If the multi-line comment contains a newline, @@ -1200,19 +1198,19 @@ /* first, parse regexp body roughly */ - duk_small_int_t state = 0; /* 0=base, 1=esc, 2=class, 3=class+esc */ + duk_small_int_t state = 0; /* 0=base, 1=esc, 2=class, 3=class+esc */ DUK__INITBUFFER(lex_ctx); for (;;) { - DUK__ADVANCECHARS(lex_ctx, 1); /* skip opening slash on first loop */ + DUK__ADVANCECHARS(lex_ctx, 1); /* skip opening slash on first loop */ x = DUK__L0(); if (x < 0 || duk_unicode_is_line_terminator(x)) { goto fail_unterm_regexp; } - x = DUK__L0(); /* re-read to avoid spill / fetch */ + x = DUK__L0(); /* re-read to avoid spill / fetch */ if (state == 0) { if (x == DUK_ASC_SLASH) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing slash */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing slash */ break; } else if (x == DUK_ASC_BACKSLASH) { state = 1; @@ -1242,20 +1240,20 @@ if (!duk_unicode_is_identifier_part(x)) { break; } - x = DUK__L0(); /* re-read to avoid spill / fetch */ + x = DUK__L0(); /* re-read to avoid spill / fetch */ DUK__APPENDBUFFER(lex_ctx, x); DUK__ADVANCECHARS(lex_ctx, 1); } out_token->str2 = duk__internbuffer(lex_ctx, lex_ctx->slot2_idx); - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* validation of the regexp is caller's responsibility */ advtok = DUK__ADVTOK(0, DUK_TOK_REGEXP); -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ goto fail_regexp_support; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } else if (DUK__L1() == DUK_ASC_EQUALS) { /* "/=" and not in regexp mode */ advtok = DUK__ADVTOK(2, DUK_TOK_DIV_EQ); @@ -1264,25 +1262,25 @@ advtok = DUK__ADVTOK(1, DUK_TOK_DIV); } break; - case DUK_ASC_LCURLY: /* '{' */ + case DUK_ASC_LCURLY: /* '{' */ advtok = DUK__ADVTOK(1, DUK_TOK_LCURLY); break; - case DUK_ASC_RCURLY: /* '}' */ + case DUK_ASC_RCURLY: /* '}' */ advtok = DUK__ADVTOK(1, DUK_TOK_RCURLY); break; - case DUK_ASC_LPAREN: /* '(' */ + case DUK_ASC_LPAREN: /* '(' */ advtok = DUK__ADVTOK(1, DUK_TOK_LPAREN); break; - case DUK_ASC_RPAREN: /* ')' */ + case DUK_ASC_RPAREN: /* ')' */ advtok = DUK__ADVTOK(1, DUK_TOK_RPAREN); break; - case DUK_ASC_LBRACKET: /* '' */ + case DUK_ASC_LBRACKET: /* '' */ advtok = DUK__ADVTOK(1, DUK_TOK_LBRACKET); break; - case DUK_ASC_RBRACKET: /* '' */ + case DUK_ASC_RBRACKET: /* '' */ advtok = DUK__ADVTOK(1, DUK_TOK_RBRACKET); break; - case DUK_ASC_PERIOD: /* '.' */ + case DUK_ASC_PERIOD: /* '.' */ if (DUK__ISDIGIT(DUK__L1())) { /* Period followed by a digit can only start DecimalLiteral * (handled in slow path). We could jump straight into the @@ -1293,13 +1291,13 @@ } advtok = DUK__ADVTOK(1, DUK_TOK_PERIOD); break; - case DUK_ASC_SEMICOLON: /* ';' */ + case DUK_ASC_SEMICOLON: /* ';' */ advtok = DUK__ADVTOK(1, DUK_TOK_SEMICOLON); break; - case DUK_ASC_COMMA: /* ',' */ + case DUK_ASC_COMMA: /* ',' */ advtok = DUK__ADVTOK(1, DUK_TOK_COMMA); break; - case DUK_ASC_LANGLE: /* '<' */ + case DUK_ASC_LANGLE: /* '<' */ #if defined(DUK_USE_HTML_COMMENTS) if (DUK__L1() == DUK_ASC_EXCLAMATION && DUK__L2() == DUK_ASC_MINUS && DUK__L3() == DUK_ASC_MINUS) { /* @@ -1308,11 +1306,10 @@ /* DUK__ADVANCECHARS(lex_ctx, 4) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ - } - else -#endif /* DUK_USE_HTML_COMMENTS */ - if (DUK__L1() == DUK_ASC_LANGLE && DUK__L2() == DUK_ASC_EQUALS) { + goto restart; /* line terminator will be handled on next round */ + } else +#endif /* DUK_USE_HTML_COMMENTS */ + if (DUK__L1() == DUK_ASC_LANGLE && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_ALSHIFT_EQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_LE); @@ -1322,7 +1319,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_LT); } break; - case DUK_ASC_RANGLE: /* '>' */ + case DUK_ASC_RANGLE: /* '>' */ if (DUK__L1() == DUK_ASC_RANGLE && DUK__L2() == DUK_ASC_RANGLE && DUK__L3() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(4, DUK_TOK_RSHIFT_EQ); } else if (DUK__L1() == DUK_ASC_RANGLE && DUK__L2() == DUK_ASC_RANGLE) { @@ -1337,7 +1334,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_GT); } break; - case DUK_ASC_EQUALS: /* '=' */ + case DUK_ASC_EQUALS: /* '=' */ if (DUK__L1() == DUK_ASC_EQUALS && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_SEQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -1346,7 +1343,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_EQUALSIGN); } break; - case DUK_ASC_EXCLAMATION: /* '!' */ + case DUK_ASC_EXCLAMATION: /* '!' */ if (DUK__L1() == DUK_ASC_EQUALS && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_SNEQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -1355,7 +1352,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_LNOT); } break; - case DUK_ASC_PLUS: /* '+' */ + case DUK_ASC_PLUS: /* '+' */ if (DUK__L1() == DUK_ASC_PLUS) { advtok = DUK__ADVTOK(2, DUK_TOK_INCREMENT); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -1364,7 +1361,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_ADD); } break; - case DUK_ASC_MINUS: /* '-' */ + case DUK_ASC_MINUS: /* '-' */ #if defined(DUK_USE_HTML_COMMENTS) if (got_lineterm && DUK__L1() == DUK_ASC_MINUS && DUK__L2() == DUK_ASC_RANGLE) { /* @@ -1381,10 +1378,10 @@ /* DUK__ADVANCECHARS(lex_ctx, 3) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } else -#endif /* DUK_USE_HTML_COMMENTS */ - if (DUK__L1() == DUK_ASC_MINUS) { +#endif /* DUK_USE_HTML_COMMENTS */ + if (DUK__L1() == DUK_ASC_MINUS) { advtok = DUK__ADVTOK(2, DUK_TOK_DECREMENT); } else if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_SUB_EQ); @@ -1392,7 +1389,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_SUB); } break; - case DUK_ASC_STAR: /* '*' */ + case DUK_ASC_STAR: /* '*' */ #if defined(DUK_USE_ES7_EXP_OPERATOR) if (DUK__L1() == DUK_ASC_STAR && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_EXP_EQ); @@ -1400,20 +1397,20 @@ advtok = DUK__ADVTOK(2, DUK_TOK_EXP); } else #endif - if (DUK__L1() == DUK_ASC_EQUALS) { + if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_MUL_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_MUL); } break; - case DUK_ASC_PERCENT: /* '%' */ + case DUK_ASC_PERCENT: /* '%' */ if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_MOD_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_MOD); } break; - case DUK_ASC_AMP: /* '&' */ + case DUK_ASC_AMP: /* '&' */ if (DUK__L1() == DUK_ASC_AMP) { advtok = DUK__ADVTOK(2, DUK_TOK_LAND); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -1422,7 +1419,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_BAND); } break; - case DUK_ASC_PIPE: /* '|' */ + case DUK_ASC_PIPE: /* '|' */ if (DUK__L1() == DUK_ASC_PIPE) { advtok = DUK__ADVTOK(2, DUK_TOK_LOR); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -1431,41 +1428,41 @@ advtok = DUK__ADVTOK(1, DUK_TOK_BOR); } break; - case DUK_ASC_CARET: /* '^' */ + case DUK_ASC_CARET: /* '^' */ if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_BXOR_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_BXOR); } break; - case DUK_ASC_TILDE: /* '~' */ + case DUK_ASC_TILDE: /* '~' */ advtok = DUK__ADVTOK(1, DUK_TOK_BNOT); break; - case DUK_ASC_QUESTION: /* '?' */ + case DUK_ASC_QUESTION: /* '?' */ advtok = DUK__ADVTOK(1, DUK_TOK_QUESTION); break; - case DUK_ASC_COLON: /* ':' */ + case DUK_ASC_COLON: /* ':' */ advtok = DUK__ADVTOK(1, DUK_TOK_COLON); break; - case DUK_ASC_DOUBLEQUOTE: /* '"' */ - case DUK_ASC_SINGLEQUOTE: { /* '\'' */ + case DUK_ASC_DOUBLEQUOTE: /* '"' */ + case DUK_ASC_SINGLEQUOTE: { /* '\'' */ DUK__INITBUFFER(lex_ctx); duk__lexer_parse_string_literal(lex_ctx, out_token, x /*quote*/, strict_mode); duk__internbuffer(lex_ctx, lex_ctx->slot1_idx); out_token->str1 = duk_known_hstring(lex_ctx->thr, lex_ctx->slot1_idx); - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ advtok = DUK__ADVTOK(0, DUK_TOK_STRING); break; } default: goto slow_path; - } /* switch */ + } /* switch */ goto skip_slow_path; - slow_path: +slow_path: if (duk_unicode_is_line_terminator(x)) { if (x == 0x000d && DUK__L1() == 0x000a) { /* @@ -1556,7 +1553,7 @@ str = out_token->str1; out_token->t_nores = DUK_TOK_IDENTIFIER; - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* * Interned identifier is compared against reserved words, which are @@ -1583,7 +1580,7 @@ advtok = DUK__ADVTOK(0, DUK_TOK_IDENTIFIER); if (out_token->num_escapes == 0) { for (i = DUK_STRIDX_START_RESERVED; i < i_end; i++) { - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HEAP_NUM_STRINGS); if (DUK_HTHREAD_GET_STRING(lex_ctx->thr, i) == str) { advtok = DUK__ADVTOK(0, DUK_STRIDX_TO_TOK(i)); @@ -1618,11 +1615,11 @@ duk_double_t val; duk_bool_t legacy_oct = 0; - duk_small_int_t state; /* 0=before period/exp, - * 1=after period, before exp - * 2=after exp, allow '+' or '-' - * 3=after exp and exp sign - */ + duk_small_int_t state; /* 0=before period/exp, + * 1=after period, before exp + * 2=after exp, allow '+' or '-' + * 3=after exp and exp sign + */ duk_small_uint_t s2n_flags; duk_codepoint_t y, z; duk_small_int_t s2n_radix = 10; @@ -1634,7 +1631,7 @@ if (x == DUK_ASC_0) { z = DUK_LOWERCASE_CHAR_ASCII(y); - pre_adv = 2; /* default for 0xNNN, 0oNNN, 0bNNN. */ + pre_adv = 2; /* default for 0xNNN, 0oNNN, 0bNNN. */ if (z == DUK_ASC_LC_X) { s2n_radix = 16; } else if (z == DUK_ASC_LC_O) { @@ -1657,7 +1654,7 @@ DUK__APPENDBUFFER(lex_ctx, x); pre_adv = 1; legacy_oct = 1; - s2n_radix = 8; /* tentative unless conflicting digits found */ + s2n_radix = 8; /* tentative unless conflicting digits found */ } } } @@ -1671,7 +1668,7 @@ */ state = 0; for (;;) { - x = DUK__L0(); /* re-lookup curr char on first round */ + x = DUK__L0(); /* re-lookup curr char on first round */ if (DUK__ISDIGIT(x)) { /* Note: intentionally allow leading zeroes here, as the * actual parser will check for them. @@ -1724,11 +1721,8 @@ /* For bases other than 10, integer only. */ s2n_flags = DUK_S2N_FLAG_ALLOW_LEADING_ZERO; } else { - s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO; + s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_LEADING_ZERO; } duk_dup(lex_ctx->thr, lex_ctx->slot1_idx); @@ -1737,9 +1731,9 @@ if (DUK_ISNAN(val)) { goto fail_number_literal; } - duk_replace(lex_ctx->thr, lex_ctx->slot1_idx); /* could also just pop? */ + duk_replace(lex_ctx->thr, lex_ctx->slot1_idx); /* could also just pop? */ - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* Section 7.8.3 (note): NumericLiteral must be followed by something other than * IdentifierStart or DecimalDigit. @@ -1759,7 +1753,7 @@ } else { goto fail_token; } - skip_slow_path: +skip_slow_path: /* * Shared exit path @@ -1784,32 +1778,32 @@ return; - fail_token_limit: +fail_token_limit: DUK_ERROR_RANGE(lex_ctx->thr, DUK_STR_TOKEN_LIMIT); DUK_WO_NORETURN(return;); - fail_token: +fail_token: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_TOKEN); DUK_WO_NORETURN(return;); - fail_number_literal: +fail_number_literal: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_NUMBER_LITERAL); DUK_WO_NORETURN(return;); - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return;); - fail_unterm_regexp: +fail_unterm_regexp: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_REGEXP); DUK_WO_NORETURN(return;); - fail_unterm_comment: +fail_unterm_comment: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_COMMENT); DUK_WO_NORETURN(return;); #if !defined(DUK_USE_REGEXP_SUPPORT) - fail_regexp_support: +fail_regexp_support: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_REGEXP_SUPPORT_DISABLED); DUK_WO_NORETURN(return;); #endif @@ -1827,7 +1821,7 @@ */ DUK_INTERNAL void duk_lexer_parse_re_token(duk_lexer_ctx *lex_ctx, duk_re_token *out_token) { - duk_small_uint_t advtok = 0; /* init is unnecessary but suppresses "may be used uninitialized" warnings */ + duk_small_uint_t advtok = 0; /* init is unnecessary but suppresses "may be used uninitialized" warnings */ duk_codepoint_t x, y; if (++lex_ctx->token_count >= lex_ctx->token_limit) { @@ -1905,7 +1899,7 @@ #endif for (;;) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat '{' on entry */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat '{' on entry */ x = DUK__L0(); if (DUK__ISDIGIT(x)) { digits++; @@ -1929,7 +1923,7 @@ } val2 = val1; val1 = 0; - digits = 0; /* not strictly necessary because of lookahead '}' above */ + digits = 0; /* not strictly necessary because of lookahead '}' above */ } else if (x == DUK_ASC_RCURLY) { if (digits > DUK__MAX_RE_QUANT_DIGITS) { goto invalid_quantifier; @@ -1960,7 +1954,7 @@ } advtok = DUK__ADVTOK(0, DUK_RETOK_QUANTIFIER); break; - invalid_quantifier: + invalid_quantifier: #if defined(DUK_USE_ES6_REGEXP_SYNTAX) /* Failed to match the quantifier, restore lexer and parse * opening brace as a literal. @@ -1986,7 +1980,7 @@ * ES2015 Annex B relaxes the rules to allow these (and other) real world forms. */ - advtok = DUK__ADVTOK(2, DUK_RETOK_ATOM_CHAR); /* default: char escape (two chars) */ + advtok = DUK__ADVTOK(2, DUK_RETOK_ATOM_CHAR); /* default: char escape (two chars) */ if (y == DUK_ASC_LC_B) { advtok = DUK__ADVTOK(2, DUK_RETOK_ASSERT_WORD_BOUNDARY); } else if (y == DUK_ASC_UC_B) { @@ -2003,8 +1997,7 @@ out_token->num = 0x000b; } else if (y == DUK_ASC_LC_C) { x = DUK__L2(); - if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || - (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { + if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { out_token->num = (duk_uint32_t) (x % 32); advtok = DUK__ADVTOK(3, DUK_RETOK_ATOM_CHAR); } else { @@ -2042,11 +2035,11 @@ /* XXX: shared parsing? */ duk_uint32_t val = 0; duk_small_int_t i; - for (i = 0; ; i++) { + for (i = 0;; i++) { if (i >= DUK__MAX_RE_DECESC_DIGITS) { goto fail_escape; } - DUK__ADVANCECHARS(lex_ctx, 1); /* eat backslash on entry */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat backslash on entry */ x = DUK__L0(); if (!DUK__ISDIGIT(x)) { break; @@ -2066,17 +2059,15 @@ * This is not yet full ES2015 Annex B because cases above * (like hex escape) won't backtrack. */ - DUK_ASSERT(y != DUK_ASC_LC_C); /* covered above */ -#else /* DUK_USE_ES6_REGEXP_SYNTAX */ - } else if ((y >= 0 && !duk_unicode_is_identifier_part(y)) || - y == DUK_UNICODE_CP_ZWNJ || - y == DUK_UNICODE_CP_ZWJ) { + DUK_ASSERT(y != DUK_ASC_LC_C); /* covered above */ +#else /* DUK_USE_ES6_REGEXP_SYNTAX */ + } else if ((y >= 0 && !duk_unicode_is_identifier_part(y)) || y == DUK_UNICODE_CP_ZWNJ || y == DUK_UNICODE_CP_ZWJ) { /* For ES5.1 identity escapes are not allowed for identifier * parts. This conflicts with a lot of real world code as this * doesn't e.g. allow escaping a dollar sign as /\$/, see * test-regexp-identity-escape-dollar.js. */ -#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ +#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ out_token->num = (duk_uint32_t) y; } else { goto fail_escape; @@ -2157,24 +2148,24 @@ out_token->t = advtok & 0xff; return; - fail_token_limit: +fail_token_limit: DUK_ERROR_RANGE(lex_ctx->thr, DUK_STR_TOKEN_LIMIT); DUK_WO_NORETURN(return;); - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_ESCAPE); DUK_WO_NORETURN(return;); - fail_group: +fail_group: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_GROUP); DUK_WO_NORETURN(return;); #if !defined(DUK_USE_ES6_REGEXP_SYNTAX) - fail_invalid_char: +fail_invalid_char: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_CHARACTER); DUK_WO_NORETURN(return;); - fail_quantifier: +fail_quantifier: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_QUANTIFIER); DUK_WO_NORETURN(return;); #endif @@ -2233,7 +2224,7 @@ x = DUK__L0(); - ch = -1; /* not strictly necessary, but avoids "uninitialized variable" warnings */ + ch = -1; /* not strictly necessary, but avoids "uninitialized variable" warnings */ DUK_UNREF(ch); if (x < 0) { @@ -2242,7 +2233,7 @@ if (start >= 0) { gen_range(userdata, start, start, 0); } - DUK__ADVANCECHARS(lex_ctx, 1); /* eat '' before finishing */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat '' before finishing */ break; } else if (x == DUK_ASC_MINUS) { if (start >= 0 && !dash && DUK__L1() != DUK_ASC_RBRACKET) { @@ -2287,8 +2278,7 @@ } else if (x == DUK_ASC_LC_C) { x = DUK__L2(); adv = 3; - if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || - (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { + if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { ch = (x % 32); } else { goto fail_escape; @@ -2352,7 +2342,7 @@ #if defined(DUK_USE_ES6_REGEXP_SYNTAX) ch = duk__lexer_parse_legacy_octal(lex_ctx, &adv, 0 /*reject_annex_b*/); - DUK_ASSERT(ch >= 0); /* no rejections */ + DUK_ASSERT(ch >= 0); /* no rejections */ #else if (x == DUK_ASC_0 && !DUK__ISDIGIT(DUK__L2())) { ch = 0x0000; @@ -2367,7 +2357,7 @@ * EOF here. */ ch = x; -#else /* DUK_USE_ES6_REGEXP_SYNTAX */ +#else /* DUK_USE_ES6_REGEXP_SYNTAX */ } else if (!duk_unicode_is_identifier_part(x)) { /* IdentityEscape: ES5.1 doesn't allow identity escape * for identifier part characters, which conflicts with @@ -2375,7 +2365,7 @@ * /\$/ which is awkward. */ ch = x; -#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ +#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ } else { goto fail_escape; } @@ -2423,17 +2413,17 @@ return; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_ESCAPE); DUK_WO_NORETURN(return;); - fail_range: +fail_range: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_RANGE); DUK_WO_NORETURN(return;); - fail_unterm_charclass: +fail_unterm_charclass: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_CHARCLASS); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_lexer.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_lexer.h
Changed
@@ -26,156 +26,156 @@ * in a continuous range and in a particular order. See genstrings.py. */ -#define DUK_LEXER_INITCTX(ctx) duk_lexer_initctx((ctx)) +#define DUK_LEXER_INITCTX(ctx) duk_lexer_initctx((ctx)) -#define DUK_LEXER_SETPOINT(ctx,pt) duk_lexer_setpoint((ctx), (pt)) +#define DUK_LEXER_SETPOINT(ctx, pt) duk_lexer_setpoint((ctx), (pt)) -#define DUK_LEXER_GETPOINT(ctx,pt) duk_lexer_getpoint((ctx), (pt)) +#define DUK_LEXER_GETPOINT(ctx, pt) duk_lexer_getpoint((ctx), (pt)) /* Currently 6 characters of lookup are actually needed (duk_lexer.c). */ -#define DUK_LEXER_WINDOW_SIZE 6 +#define DUK_LEXER_WINDOW_SIZE 6 #if defined(DUK_USE_LEXER_SLIDING_WINDOW) -#define DUK_LEXER_BUFFER_SIZE 64 +#define DUK_LEXER_BUFFER_SIZE 64 #endif -#define DUK_TOK_MINVAL 0 +#define DUK_TOK_MINVAL 0 /* returned after EOF (infinite amount) */ -#define DUK_TOK_EOF 0 +#define DUK_TOK_EOF 0 /* identifier names (E5 Section 7.6) */ -#define DUK_TOK_IDENTIFIER 1 +#define DUK_TOK_IDENTIFIER 1 /* reserved words: keywords */ -#define DUK_TOK_START_RESERVED 2 -#define DUK_TOK_BREAK 2 -#define DUK_TOK_CASE 3 -#define DUK_TOK_CATCH 4 -#define DUK_TOK_CONTINUE 5 -#define DUK_TOK_DEBUGGER 6 -#define DUK_TOK_DEFAULT 7 -#define DUK_TOK_DELETE 8 -#define DUK_TOK_DO 9 -#define DUK_TOK_ELSE 10 -#define DUK_TOK_FINALLY 11 -#define DUK_TOK_FOR 12 -#define DUK_TOK_FUNCTION 13 -#define DUK_TOK_IF 14 -#define DUK_TOK_IN 15 -#define DUK_TOK_INSTANCEOF 16 -#define DUK_TOK_NEW 17 -#define DUK_TOK_RETURN 18 -#define DUK_TOK_SWITCH 19 -#define DUK_TOK_THIS 20 -#define DUK_TOK_THROW 21 -#define DUK_TOK_TRY 22 -#define DUK_TOK_TYPEOF 23 -#define DUK_TOK_VAR 24 -#define DUK_TOK_CONST 25 -#define DUK_TOK_VOID 26 -#define DUK_TOK_WHILE 27 -#define DUK_TOK_WITH 28 +#define DUK_TOK_START_RESERVED 2 +#define DUK_TOK_BREAK 2 +#define DUK_TOK_CASE 3 +#define DUK_TOK_CATCH 4 +#define DUK_TOK_CONTINUE 5 +#define DUK_TOK_DEBUGGER 6 +#define DUK_TOK_DEFAULT 7 +#define DUK_TOK_DELETE 8 +#define DUK_TOK_DO 9 +#define DUK_TOK_ELSE 10 +#define DUK_TOK_FINALLY 11 +#define DUK_TOK_FOR 12 +#define DUK_TOK_FUNCTION 13 +#define DUK_TOK_IF 14 +#define DUK_TOK_IN 15 +#define DUK_TOK_INSTANCEOF 16 +#define DUK_TOK_NEW 17 +#define DUK_TOK_RETURN 18 +#define DUK_TOK_SWITCH 19 +#define DUK_TOK_THIS 20 +#define DUK_TOK_THROW 21 +#define DUK_TOK_TRY 22 +#define DUK_TOK_TYPEOF 23 +#define DUK_TOK_VAR 24 +#define DUK_TOK_CONST 25 +#define DUK_TOK_VOID 26 +#define DUK_TOK_WHILE 27 +#define DUK_TOK_WITH 28 /* reserved words: future reserved words */ -#define DUK_TOK_CLASS 29 -#define DUK_TOK_ENUM 30 -#define DUK_TOK_EXPORT 31 -#define DUK_TOK_EXTENDS 32 -#define DUK_TOK_IMPORT 33 -#define DUK_TOK_SUPER 34 +#define DUK_TOK_CLASS 29 +#define DUK_TOK_ENUM 30 +#define DUK_TOK_EXPORT 31 +#define DUK_TOK_EXTENDS 32 +#define DUK_TOK_IMPORT 33 +#define DUK_TOK_SUPER 34 /* "null", "true", and "false" are always reserved words. * Note that "get" and "set" are not! */ -#define DUK_TOK_NULL 35 -#define DUK_TOK_TRUE 36 -#define DUK_TOK_FALSE 37 +#define DUK_TOK_NULL 35 +#define DUK_TOK_TRUE 36 +#define DUK_TOK_FALSE 37 /* reserved words: additional future reserved words in strict mode */ -#define DUK_TOK_START_STRICT_RESERVED 38 /* inclusive */ -#define DUK_TOK_IMPLEMENTS 38 -#define DUK_TOK_INTERFACE 39 -#define DUK_TOK_LET 40 -#define DUK_TOK_PACKAGE 41 -#define DUK_TOK_PRIVATE 42 -#define DUK_TOK_PROTECTED 43 -#define DUK_TOK_PUBLIC 44 -#define DUK_TOK_STATIC 45 -#define DUK_TOK_YIELD 46 - -#define DUK_TOK_END_RESERVED 47 /* exclusive */ +#define DUK_TOK_START_STRICT_RESERVED 38 /* inclusive */ +#define DUK_TOK_IMPLEMENTS 38 +#define DUK_TOK_INTERFACE 39 +#define DUK_TOK_LET 40 +#define DUK_TOK_PACKAGE 41 +#define DUK_TOK_PRIVATE 42 +#define DUK_TOK_PROTECTED 43 +#define DUK_TOK_PUBLIC 44 +#define DUK_TOK_STATIC 45 +#define DUK_TOK_YIELD 46 + +#define DUK_TOK_END_RESERVED 47 /* exclusive */ /* "get" and "set" are tokens but NOT ReservedWords. They are currently * parsed and identifiers and these defines are actually now unused. */ -#define DUK_TOK_GET 47 -#define DUK_TOK_SET 48 +#define DUK_TOK_GET 47 +#define DUK_TOK_SET 48 /* punctuators (unlike the spec, also includes "/" and "/=") */ -#define DUK_TOK_LCURLY 49 -#define DUK_TOK_RCURLY 50 -#define DUK_TOK_LBRACKET 51 -#define DUK_TOK_RBRACKET 52 -#define DUK_TOK_LPAREN 53 -#define DUK_TOK_RPAREN 54 -#define DUK_TOK_PERIOD 55 -#define DUK_TOK_SEMICOLON 56 -#define DUK_TOK_COMMA 57 -#define DUK_TOK_LT 58 -#define DUK_TOK_GT 59 -#define DUK_TOK_LE 60 -#define DUK_TOK_GE 61 -#define DUK_TOK_EQ 62 -#define DUK_TOK_NEQ 63 -#define DUK_TOK_SEQ 64 -#define DUK_TOK_SNEQ 65 -#define DUK_TOK_ADD 66 -#define DUK_TOK_SUB 67 -#define DUK_TOK_MUL 68 -#define DUK_TOK_DIV 69 -#define DUK_TOK_MOD 70 -#define DUK_TOK_EXP 71 -#define DUK_TOK_INCREMENT 72 -#define DUK_TOK_DECREMENT 73 -#define DUK_TOK_ALSHIFT 74 /* named "arithmetic" because result is signed */ -#define DUK_TOK_ARSHIFT 75 -#define DUK_TOK_RSHIFT 76 -#define DUK_TOK_BAND 77 -#define DUK_TOK_BOR 78 -#define DUK_TOK_BXOR 79 -#define DUK_TOK_LNOT 80 -#define DUK_TOK_BNOT 81 -#define DUK_TOK_LAND 82 -#define DUK_TOK_LOR 83 -#define DUK_TOK_QUESTION 84 -#define DUK_TOK_COLON 85 -#define DUK_TOK_EQUALSIGN 86 -#define DUK_TOK_ADD_EQ 87 -#define DUK_TOK_SUB_EQ 88 -#define DUK_TOK_MUL_EQ 89 -#define DUK_TOK_DIV_EQ 90 -#define DUK_TOK_MOD_EQ 91 -#define DUK_TOK_EXP_EQ 92 -#define DUK_TOK_ALSHIFT_EQ 93 -#define DUK_TOK_ARSHIFT_EQ 94 -#define DUK_TOK_RSHIFT_EQ 95 -#define DUK_TOK_BAND_EQ 96 -#define DUK_TOK_BOR_EQ 97 -#define DUK_TOK_BXOR_EQ 98 +#define DUK_TOK_LCURLY 49 +#define DUK_TOK_RCURLY 50 +#define DUK_TOK_LBRACKET 51 +#define DUK_TOK_RBRACKET 52 +#define DUK_TOK_LPAREN 53 +#define DUK_TOK_RPAREN 54 +#define DUK_TOK_PERIOD 55 +#define DUK_TOK_SEMICOLON 56 +#define DUK_TOK_COMMA 57 +#define DUK_TOK_LT 58 +#define DUK_TOK_GT 59 +#define DUK_TOK_LE 60 +#define DUK_TOK_GE 61 +#define DUK_TOK_EQ 62 +#define DUK_TOK_NEQ 63 +#define DUK_TOK_SEQ 64 +#define DUK_TOK_SNEQ 65 +#define DUK_TOK_ADD 66 +#define DUK_TOK_SUB 67 +#define DUK_TOK_MUL 68 +#define DUK_TOK_DIV 69 +#define DUK_TOK_MOD 70 +#define DUK_TOK_EXP 71 +#define DUK_TOK_INCREMENT 72 +#define DUK_TOK_DECREMENT 73 +#define DUK_TOK_ALSHIFT 74 /* named "arithmetic" because result is signed */ +#define DUK_TOK_ARSHIFT 75 +#define DUK_TOK_RSHIFT 76 +#define DUK_TOK_BAND 77 +#define DUK_TOK_BOR 78 +#define DUK_TOK_BXOR 79 +#define DUK_TOK_LNOT 80 +#define DUK_TOK_BNOT 81 +#define DUK_TOK_LAND 82 +#define DUK_TOK_LOR 83 +#define DUK_TOK_QUESTION 84 +#define DUK_TOK_COLON 85 +#define DUK_TOK_EQUALSIGN 86 +#define DUK_TOK_ADD_EQ 87 +#define DUK_TOK_SUB_EQ 88 +#define DUK_TOK_MUL_EQ 89 +#define DUK_TOK_DIV_EQ 90 +#define DUK_TOK_MOD_EQ 91 +#define DUK_TOK_EXP_EQ 92 +#define DUK_TOK_ALSHIFT_EQ 93 +#define DUK_TOK_ARSHIFT_EQ 94 +#define DUK_TOK_RSHIFT_EQ 95 +#define DUK_TOK_BAND_EQ 96 +#define DUK_TOK_BOR_EQ 97 +#define DUK_TOK_BXOR_EQ 98 /* literals (E5 Section 7.8), except null, true, false, which are treated * like reserved words (above). */ -#define DUK_TOK_NUMBER 99 -#define DUK_TOK_STRING 100 -#define DUK_TOK_REGEXP 101 +#define DUK_TOK_NUMBER 99 +#define DUK_TOK_STRING 100 +#define DUK_TOK_REGEXP 101 -#define DUK_TOK_MAXVAL 101 /* inclusive */ +#define DUK_TOK_MAXVAL 101 /* inclusive */ -#define DUK_TOK_INVALID DUK_SMALL_UINT_MAX +#define DUK_TOK_INVALID DUK_SMALL_UINT_MAX /* Convert heap string index to a token (reserved words) */ -#define DUK_STRIDX_TO_TOK(x) ((x) - DUK_STRIDX_START_RESERVED + DUK_TOK_START_RESERVED) +#define DUK_STRIDX_TO_TOK(x) ((x) -DUK_STRIDX_START_RESERVED + DUK_TOK_START_RESERVED) /* Sanity check */ #if (DUK_TOK_MAXVAL > 255) @@ -320,57 +320,57 @@ #endif /* Regexp tokens */ -#define DUK_RETOK_EOF 0 -#define DUK_RETOK_DISJUNCTION 1 -#define DUK_RETOK_QUANTIFIER 2 -#define DUK_RETOK_ASSERT_START 3 -#define DUK_RETOK_ASSERT_END 4 -#define DUK_RETOK_ASSERT_WORD_BOUNDARY 5 -#define DUK_RETOK_ASSERT_NOT_WORD_BOUNDARY 6 -#define DUK_RETOK_ASSERT_START_POS_LOOKAHEAD 7 -#define DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD 8 -#define DUK_RETOK_ATOM_PERIOD 9 -#define DUK_RETOK_ATOM_CHAR 10 -#define DUK_RETOK_ATOM_DIGIT 11 /* assumptions in regexp compiler */ -#define DUK_RETOK_ATOM_NOT_DIGIT 12 /* -""- */ -#define DUK_RETOK_ATOM_WHITE 13 /* -""- */ -#define DUK_RETOK_ATOM_NOT_WHITE 14 /* -""- */ -#define DUK_RETOK_ATOM_WORD_CHAR 15 /* -""- */ -#define DUK_RETOK_ATOM_NOT_WORD_CHAR 16 /* -""- */ -#define DUK_RETOK_ATOM_BACKREFERENCE 17 -#define DUK_RETOK_ATOM_START_CAPTURE_GROUP 18 -#define DUK_RETOK_ATOM_START_NONCAPTURE_GROUP 19 -#define DUK_RETOK_ATOM_START_CHARCLASS 20 -#define DUK_RETOK_ATOM_START_CHARCLASS_INVERTED 21 -#define DUK_RETOK_ATOM_END_GROUP 22 +#define DUK_RETOK_EOF 0 +#define DUK_RETOK_DISJUNCTION 1 +#define DUK_RETOK_QUANTIFIER 2 +#define DUK_RETOK_ASSERT_START 3 +#define DUK_RETOK_ASSERT_END 4 +#define DUK_RETOK_ASSERT_WORD_BOUNDARY 5 +#define DUK_RETOK_ASSERT_NOT_WORD_BOUNDARY 6 +#define DUK_RETOK_ASSERT_START_POS_LOOKAHEAD 7 +#define DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD 8 +#define DUK_RETOK_ATOM_PERIOD 9 +#define DUK_RETOK_ATOM_CHAR 10 +#define DUK_RETOK_ATOM_DIGIT 11 /* assumptions in regexp compiler */ +#define DUK_RETOK_ATOM_NOT_DIGIT 12 /* -""- */ +#define DUK_RETOK_ATOM_WHITE 13 /* -""- */ +#define DUK_RETOK_ATOM_NOT_WHITE 14 /* -""- */ +#define DUK_RETOK_ATOM_WORD_CHAR 15 /* -""- */ +#define DUK_RETOK_ATOM_NOT_WORD_CHAR 16 /* -""- */ +#define DUK_RETOK_ATOM_BACKREFERENCE 17 +#define DUK_RETOK_ATOM_START_CAPTURE_GROUP 18 +#define DUK_RETOK_ATOM_START_NONCAPTURE_GROUP 19 +#define DUK_RETOK_ATOM_START_CHARCLASS 20 +#define DUK_RETOK_ATOM_START_CHARCLASS_INVERTED 21 +#define DUK_RETOK_ATOM_END_GROUP 22 /* Constants for duk_lexer_ctx.buf. */ -#define DUK_LEXER_TEMP_BUF_LIMIT 256 +#define DUK_LEXER_TEMP_BUF_LIMIT 256 /* A token value. Can be memcpy()'d, but note that slot1/slot2 values are on the valstack. * Some fields (like num, str1, str2) are only valid for specific token types and may have * stale values otherwise. */ struct duk_token { - duk_small_uint_t t; /* token type (with reserved word identification) */ - duk_small_uint_t t_nores; /* token type (with reserved words as DUK_TOK_IDENTIFER) */ - duk_double_t num; /* numeric value of token */ - duk_hstring *str1; /* string 1 of token (borrowed, stored to ctx->slot1_idx) */ - duk_hstring *str2; /* string 2 of token (borrowed, stored to ctx->slot2_idx) */ - duk_size_t start_offset; /* start byte offset of token in lexer input */ - duk_int_t start_line; /* start line of token (first char) */ - duk_int_t num_escapes; /* number of escapes and line continuations (for directive prologue) */ - duk_bool_t lineterm; /* token was preceded by a lineterm */ - duk_bool_t allow_auto_semi; /* token allows automatic semicolon insertion (eof or preceded by newline) */ + duk_small_uint_t t; /* token type (with reserved word identification) */ + duk_small_uint_t t_nores; /* token type (with reserved words as DUK_TOK_IDENTIFER) */ + duk_double_t num; /* numeric value of token */ + duk_hstring *str1; /* string 1 of token (borrowed, stored to ctx->slot1_idx) */ + duk_hstring *str2; /* string 2 of token (borrowed, stored to ctx->slot2_idx) */ + duk_size_t start_offset; /* start byte offset of token in lexer input */ + duk_int_t start_line; /* start line of token (first char) */ + duk_int_t num_escapes; /* number of escapes and line continuations (for directive prologue) */ + duk_bool_t lineterm; /* token was preceded by a lineterm */ + duk_bool_t allow_auto_semi; /* token allows automatic semicolon insertion (eof or preceded by newline) */ }; -#define DUK_RE_QUANTIFIER_INFINITE ((duk_uint32_t) 0xffffffffUL) +#define DUK_RE_QUANTIFIER_INFINITE ((duk_uint32_t) 0xffffffffUL) /* A regexp token value. */ struct duk_re_token { - duk_small_uint_t t; /* token type */ + duk_small_uint_t t; /* token type */ duk_small_uint_t greedy; - duk_uint32_t num; /* numeric value (character, count) */ + duk_uint32_t num; /* numeric value (character, count) */ duk_uint32_t qmin; duk_uint32_t qmax; }; @@ -397,23 +397,23 @@ duk_lexer_codepoint windowDUK_LEXER_WINDOW_SIZE; /* unicode code points, window0 is always next */ #endif - duk_hthread *thr; /* thread; minimizes argument passing */ + duk_hthread *thr; /* thread; minimizes argument passing */ - const duk_uint8_t *input; /* input string (may be a user pointer) */ - duk_size_t input_length; /* input byte length */ - duk_size_t input_offset; /* input offset for window leading edge (not window0) */ - duk_int_t input_line; /* input linenumber at input_offset (not window0), init to 1 */ + const duk_uint8_t *input; /* input string (may be a user pointer) */ + duk_size_t input_length; /* input byte length */ + duk_size_t input_offset; /* input offset for window leading edge (not window0) */ + duk_int_t input_line; /* input linenumber at input_offset (not window0), init to 1 */ - duk_idx_t slot1_idx; /* valstack slot for 1st token value */ - duk_idx_t slot2_idx; /* valstack slot for 2nd token value */ - duk_idx_t buf_idx; /* valstack slot for temp buffer */ - duk_hbuffer_dynamic *buf; /* temp accumulation buffer */ - duk_bufwriter_ctx bw; /* bufwriter for temp accumulation */ + duk_idx_t slot1_idx; /* valstack slot for 1st token value */ + duk_idx_t slot2_idx; /* valstack slot for 2nd token value */ + duk_idx_t buf_idx; /* valstack slot for temp buffer */ + duk_hbuffer_dynamic *buf; /* temp accumulation buffer */ + duk_bufwriter_ctx bw; /* bufwriter for temp accumulation */ - duk_int_t token_count; /* number of tokens parsed */ - duk_int_t token_limit; /* maximum token count before error (sanity backstop) */ + duk_int_t token_count; /* number of tokens parsed */ + duk_int_t token_limit; /* maximum token count before error (sanity backstop) */ - duk_small_uint_t flags; /* lexer flags, use compiler flag defines for now */ + duk_small_uint_t flags; /* lexer flags, use compiler flag defines for now */ }; /* @@ -426,13 +426,10 @@ DUK_INTERNAL_DECL void duk_lexer_setpoint(duk_lexer_ctx *lex_ctx, duk_lexer_point *pt); DUK_INTERNAL_DECL -void duk_lexer_parse_js_input_element(duk_lexer_ctx *lex_ctx, - duk_token *out_token, - duk_bool_t strict_mode, - duk_bool_t regexp_mode); +void duk_lexer_parse_js_input_element(duk_lexer_ctx *lex_ctx, duk_token *out_token, duk_bool_t strict_mode, duk_bool_t regexp_mode); #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL_DECL void duk_lexer_parse_re_token(duk_lexer_ctx *lex_ctx, duk_re_token *out_token); DUK_INTERNAL_DECL void duk_lexer_parse_re_ranges(duk_lexer_ctx *lex_ctx, duk_re_range_callback gen_range, void *userdata); -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ -#endif /* DUK_LEXER_H_INCLUDED */ +#endif /* DUK_LEXER_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_numconv.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_numconv.c
Changed
@@ -12,10 +12,10 @@ #include "duk_internal.h" -#define DUK__IEEE_DOUBLE_EXP_BIAS 1023 -#define DUK__IEEE_DOUBLE_EXP_MIN (-1022) /* biased exp == 0 -> denormal, exp -1022 */ +#define DUK__IEEE_DOUBLE_EXP_BIAS 1023 +#define DUK__IEEE_DOUBLE_EXP_MIN (-1022) /* biased exp == 0 -> denormal, exp -1022 */ -#define DUK__DIGITCHAR(x) duk_lc_digits(x) +#define DUK__DIGITCHAR(x) duk_lc_digits(x) /* * Tables generated with util/gennumdigits.py. @@ -33,10 +33,10 @@ */ DUK_LOCAL const duk_uint8_t duk__str2num_digits_for_radix = { - 69, 44, 35, 30, 27, 25, 23, 22, 20, 20, /* 2 to 11 */ - 20, 19, 19, 18, 18, 17, 17, 17, 16, 16, /* 12 to 21 */ - 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, /* 22 to 31 */ - 14, 14, 14, 14, 14 /* 31 to 36 */ + 69, 44, 35, 30, 27, 25, 23, 22, 20, 20, /* 2 to 11 */ + 20, 19, 19, 18, 18, 17, 17, 17, 16, 16, /* 12 to 21 */ + 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, /* 22 to 31 */ + 14, 14, 14, 14, 14 /* 31 to 36 */ }; typedef struct { @@ -45,15 +45,11 @@ } duk__exp_limits; DUK_LOCAL const duk__exp_limits duk__str2num_exp_limits = { - { 957, -1147 }, { 605, -725 }, { 479, -575 }, { 414, -496 }, - { 372, -446 }, { 342, -411 }, { 321, -384 }, { 304, -364 }, - { 291, -346 }, { 279, -334 }, { 268, -323 }, { 260, -312 }, - { 252, -304 }, { 247, -296 }, { 240, -289 }, { 236, -283 }, - { 231, -278 }, { 227, -273 }, { 223, -267 }, { 220, -263 }, - { 216, -260 }, { 213, -256 }, { 210, -253 }, { 208, -249 }, - { 205, -246 }, { 203, -244 }, { 201, -241 }, { 198, -239 }, - { 196, -237 }, { 195, -234 }, { 193, -232 }, { 191, -230 }, - { 190, -228 }, { 188, -226 }, { 187, -225 }, + { 957, -1147 }, { 605, -725 }, { 479, -575 }, { 414, -496 }, { 372, -446 }, { 342, -411 }, { 321, -384 }, + { 304, -364 }, { 291, -346 }, { 279, -334 }, { 268, -323 }, { 260, -312 }, { 252, -304 }, { 247, -296 }, + { 240, -289 }, { 236, -283 }, { 231, -278 }, { 227, -273 }, { 223, -267 }, { 220, -263 }, { 216, -260 }, + { 213, -256 }, { 210, -253 }, { 208, -249 }, { 205, -246 }, { 203, -244 }, { 201, -241 }, { 198, -239 }, + { 196, -237 }, { 195, -234 }, { 193, -232 }, { 191, -230 }, { 190, -228 }, { 188, -226 }, { 187, -225 }, }; /* @@ -71,18 +67,18 @@ /* This upper value has been experimentally determined; debug build will check * bigint size with assertions. */ -#define DUK__BI_MAX_PARTS 37 /* 37x32 = 1184 bits */ +#define DUK__BI_MAX_PARTS 37 /* 37x32 = 1184 bits */ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK__BI_PRINT(name,x) duk__bi_print((name),(x)) +#define DUK__BI_PRINT(name, x) duk__bi_print((name), (x)) #else -#define DUK__BI_PRINT(name,x) +#define DUK__BI_PRINT(name, x) #endif /* Current size is about 152 bytes. */ typedef struct { duk_small_int_t n; - duk_uint32_t vDUK__BI_MAX_PARTS; /* low to high */ + duk_uint32_t vDUK__BI_MAX_PARTS; /* low to high */ } duk__bigint; #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) @@ -107,9 +103,8 @@ #if defined(DUK_USE_ASSERTIONS) DUK_LOCAL duk_small_int_t duk__bi_is_valid(duk__bigint *x) { - return (duk_small_int_t) - ( ((x->n >= 0) && (x->n <= DUK__BI_MAX_PARTS)) /* is valid size */ && - ((x->n == 0) || (x->vx->n - 1 != 0)) /* is normalized */ ); + return (duk_small_int_t) (((x->n >= 0) && (x->n <= DUK__BI_MAX_PARTS)) /* is valid size */ && + ((x->n == 0) || (x->vx->n - 1 != 0)) /* is normalized */); } #endif @@ -180,10 +175,10 @@ return 0; - ret_gt: +ret_gt: return 1; - ret_lt: +ret_lt: return -1; } @@ -198,11 +193,14 @@ if (z->n > y->n) { duk__bigint *t; - t = y; y = z; z = t; + t = y; + y = z; + z = t; } DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; tmp = 0U; for (i = 0; i < ny; i++) { DUK_ASSERT(i < DUK__BI_MAX_PARTS); @@ -223,7 +221,7 @@ /* no need to normalize */ DUK_ASSERT(duk__bi_is_valid(x)); } -#else /* DUK_USE_64BIT_OPS */ +#else /* DUK_USE_64BIT_OPS */ DUK_LOCAL void duk__bi_add(duk__bigint *x, duk__bigint *y, duk__bigint *z) { duk_uint32_t carry, tmp1, tmp2; duk_small_int_t i, ny, nz; @@ -233,11 +231,14 @@ if (z->n > y->n) { duk__bigint *t; - t = y; y = z; z = t; + t = y; + y = z; + z = t; } DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; carry = 0U; for (i = 0; i < ny; i++) { /* Carry is detected based on wrapping which relies on exact 32-bit @@ -274,7 +275,7 @@ /* no need to normalize */ DUK_ASSERT(duk__bi_is_valid(x)); } -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ /* x <- y + z */ DUK_LOCAL void duk__bi_add_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) { @@ -289,7 +290,7 @@ DUK_ASSERT(duk__bi_is_valid(x)); } -#if 0 /* unused */ +#if 0 /* unused */ /* x <- x + y, use t as temp */ DUK_LOCAL void duk__bi_add_copy(duk__bigint *x, duk__bigint *y, duk__bigint *t) { duk__bi_add(t, x, y); @@ -309,7 +310,8 @@ DUK_ASSERT(duk__bi_compare(y, z) >= 0); DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; tmp = 0; for (i = 0; i < ny; i++) { ty = y->vi; @@ -320,12 +322,12 @@ } tmp = (duk_int64_t) ty - (duk_int64_t) tz + tmp; x->vi = (duk_uint32_t) ((duk_uint64_t) tmp & 0xffffffffUL); - tmp = tmp >> 32; /* 0 or -1 */ + tmp = tmp >> 32; /* 0 or -1 */ } DUK_ASSERT(tmp == 0); x->n = i; - duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ + duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ DUK_ASSERT(duk__bi_is_valid(x)); } #else @@ -338,7 +340,8 @@ DUK_ASSERT(duk__bi_compare(y, z) >= 0); DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; borrow = 0U; for (i = 0; i < ny; i++) { /* Borrow is detected based on wrapping which relies on exact 32-bit @@ -366,12 +369,12 @@ DUK_ASSERT(borrow == 0U); x->n = i; - duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ + duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ DUK_ASSERT(duk__bi_is_valid(x)); } #endif -#if 0 /* unused */ +#if 0 /* unused */ /* x <- y - z */ DUK_LOCAL void duk__bi_sub_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) { duk__bigint tmp; @@ -399,7 +402,7 @@ DUK_ASSERT(duk__bi_is_valid(y)); DUK_ASSERT(duk__bi_is_valid(z)); - nx = y->n + z->n; /* max possible */ + nx = y->n + z->n; /* max possible */ DUK_ASSERT(nx <= DUK__BI_MAX_PARTS); if (nx == 0) { @@ -418,15 +421,15 @@ #if defined(DUK_USE_64BIT_OPS) duk_uint64_t tmp = 0U; for (j = 0; j < nz; j++) { - tmp += (duk_uint64_t) y->vi * (duk_uint64_t) z->vj + x->vi+j; - x->vi+j = (duk_uint32_t) (tmp & 0xffffffffUL); + tmp += (duk_uint64_t) y->vi * (duk_uint64_t) z->vj + x->vi + j; + x->vi + j = (duk_uint32_t) (tmp & 0xffffffffUL); tmp = tmp >> 32; } if (tmp > 0) { DUK_ASSERT(i + j < nx); DUK_ASSERT(i + j < DUK__BI_MAX_PARTS); - DUK_ASSERT(x->vi+j == 0U); - x->vi+j = (duk_uint32_t) tmp; + DUK_ASSERT(x->vi + j == 0U); + x->vi + j = (duk_uint32_t) tmp; } #else /* @@ -446,12 +449,16 @@ duk_uint32_t a, b, c, d, e, f; duk_uint32_t r, s, t; - a = y->vi; b = a & 0xffffUL; a = a >> 16; + a = y->vi; + b = a & 0xffffUL; + a = a >> 16; f = 0; for (j = 0; j < nz; j++) { - c = z->vj; d = c & 0xffffUL; c = c >> 16; - e = x->vi+j; + c = z->vj; + d = c & 0xffffUL; + c = c >> 16; + e = x->vi + j; /* build result as: (r << 32) + s: start with (BD + E + F) */ r = 0; @@ -459,26 +466,34 @@ /* add E */ t = s + e; - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add F */ t = s + f; - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add BC*2^16 */ t = b * c; r += (t >> 16); t = s + ((t & 0xffffUL) << 16); - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add AD*2^16 */ t = a * d; r += (t >> 16); t = s + ((t & 0xffffUL) << 16); - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add AC*2^32 */ @@ -486,20 +501,22 @@ r += t; DUK_DDD(DUK_DDDPRINT("ab=%08lx cd=%08lx ef=%08lx -> rs=%08lx %08lx", - (unsigned long) y->vi, (unsigned long) z->vj, - (unsigned long) x->vi+j, (unsigned long) r, + (unsigned long) y->vi, + (unsigned long) z->vj, + (unsigned long) x->vi + j, + (unsigned long) r, (unsigned long) s)); - x->vi+j = s; + x->vi + j = s; f = r; } if (f > 0U) { DUK_ASSERT(i + j < nx); DUK_ASSERT(i + j < DUK__BI_MAX_PARTS); - DUK_ASSERT(x->vi+j == 0U); - x->vi+j = (duk_uint32_t) f; + DUK_ASSERT(x->vi + j == 0U); + x->vi + j = (duk_uint32_t) f; } -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ } duk__bi_normalize(x); @@ -538,7 +555,7 @@ DUK_LOCAL int duk__bi_is_zero(duk__bigint *x) { DUK_ASSERT(duk__bi_is_valid(x)); - return (x->n == 0); /* this is the case for normalized numbers */ + return (x->n == 0); /* this is the case for normalized numbers */ } /* Bigint is 2^52. Used to detect normalized IEEE double mantissa values @@ -549,8 +566,7 @@ */ DUK_LOCAL duk_small_int_t duk__bi_is_2to52(duk__bigint *x) { DUK_ASSERT(duk__bi_is_valid(x)); - return (duk_small_int_t) - (x->n == 2) && (x->v0 == 0U) && (x->v1 == (1U << (52-32))); + return (duk_small_int_t) (x->n == 2) && (x->v0 == 0U) && (x->v1 == (1U << (52 - 32))); } /* x <- (1<<y) */ @@ -569,7 +585,7 @@ DUK_LOCAL void duk__bi_exp_small(duk__bigint *x, duk_small_int_t b, duk_small_int_t y, duk__bigint *t1, duk__bigint *t2) { /* Fast path the binary case */ - DUK_ASSERT(x != t1 && x != t2 && t1 != t2); /* distinct bignums, easy mistake to make */ + DUK_ASSERT(x != t1 && x != t2 && t1 != t2); /* distinct bignums, easy mistake to make */ DUK_ASSERT(b >= 0); DUK_ASSERT(y >= 0); @@ -624,14 +640,14 @@ */ /* Maximum number of digits generated. */ -#define DUK__MAX_OUTPUT_DIGITS 1040 /* (Number.MAX_VALUE).toString(2).length == 1024, + slack */ +#define DUK__MAX_OUTPUT_DIGITS 1040 /* (Number.MAX_VALUE).toString(2).length == 1024, + slack */ /* Maximum number of characters in formatted value. */ -#define DUK__MAX_FORMATTED_LENGTH 1040 /* (-Number.MAX_VALUE).toString(2).length == 1025, + slack */ +#define DUK__MAX_FORMATTED_LENGTH 1040 /* (-Number.MAX_VALUE).toString(2).length == 1025, + slack */ /* Number and (minimum) size of bigints in the nc_ctx structure. */ -#define DUK__NUMCONV_CTX_NUM_BIGINTS 7 -#define DUK__NUMCONV_CTX_BIGINTS_SIZE (sizeof(duk__bigint) * DUK__NUMCONV_CTX_NUM_BIGINTS) +#define DUK__NUMCONV_CTX_NUM_BIGINTS 7 +#define DUK__NUMCONV_CTX_BIGINTS_SIZE (sizeof(duk__bigint) * DUK__NUMCONV_CTX_NUM_BIGINTS) typedef struct { /* Currently about 7*152 = 1064 bytes. The space for these @@ -641,31 +657,32 @@ */ duk__bigint f, r, s, mp, mm, t1, t2; - duk_small_int_t is_s2n; /* if 1, doing a string-to-number; else doing a number-to-string */ - duk_small_int_t is_fixed; /* if 1, doing a fixed format output (not free format) */ - duk_small_int_t req_digits; /* requested number of output digits; 0 = free-format */ - duk_small_int_t abs_pos; /* digit position is absolute, not relative */ - duk_small_int_t e; /* exponent for 'f' */ - duk_small_int_t b; /* input radix */ - duk_small_int_t B; /* output radix */ - duk_small_int_t k; /* see algorithm */ - duk_small_int_t low_ok; /* see algorithm */ - duk_small_int_t high_ok; /* see algorithm */ - duk_small_int_t unequal_gaps; /* m+ != m- (very rarely) */ + duk_small_int_t is_s2n; /* if 1, doing a string-to-number; else doing a number-to-string */ + duk_small_int_t is_fixed; /* if 1, doing a fixed format output (not free format) */ + duk_small_int_t req_digits; /* requested number of output digits; 0 = free-format */ + duk_small_int_t abs_pos; /* digit position is absolute, not relative */ + duk_small_int_t e; /* exponent for 'f' */ + duk_small_int_t b; /* input radix */ + duk_small_int_t B; /* output radix */ + duk_small_int_t k; /* see algorithm */ + duk_small_int_t low_ok; /* see algorithm */ + duk_small_int_t high_ok; /* see algorithm */ + duk_small_int_t unequal_gaps; /* m+ != m- (very rarely) */ /* Buffer used for generated digits, values are in the range 0,B-1. */ duk_uint8_t digitsDUK__MAX_OUTPUT_DIGITS; - duk_small_int_t count; /* digit count */ + duk_small_int_t count; /* digit count */ } duk__numconv_stringify_ctx; /* Note: computes with 'idx' in assertions, so caller beware. * 'idx' is preincremented, i.e. '1' on first call, because it * is more convenient for the caller. */ -#define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx,preinc_idx,x) do { \ - DUK_ASSERT((preinc_idx) - 1 >= 0); \ - DUK_ASSERT((preinc_idx) - 1 < DUK__MAX_OUTPUT_DIGITS); \ - ((nc_ctx)->digits(preinc_idx) - 1) = (duk_uint8_t) (x); \ +#define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, preinc_idx, x) \ + do { \ + DUK_ASSERT((preinc_idx) -1 >= 0); \ + DUK_ASSERT((preinc_idx) -1 < DUK__MAX_OUTPUT_DIGITS); \ + ((nc_ctx)->digits(preinc_idx) -1) = (duk_uint8_t) (x); \ } while (0) DUK_LOCAL duk_size_t duk__dragon4_format_uint32(duk_uint8_t *buf, duk_uint32_t x, duk_small_int_t radix) { @@ -764,11 +781,11 @@ "lowest mantissa value for this exponent -> " "unequal gaps")); - duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ - duk__bi_mul_small(&nc_ctx->mp, &nc_ctx->mm, (duk_uint32_t) nc_ctx->b); /* mp <- b^(e+1) */ + duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ + duk__bi_mul_small(&nc_ctx->mp, &nc_ctx->mm, (duk_uint32_t) nc_ctx->b); /* mp <- b^(e+1) */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->f, 2); - duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^(e+1) */ - duk__bi_set_small(&nc_ctx->s, (duk_uint32_t) (nc_ctx->b * 2)); /* s <- 2 * b */ + duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^(e+1) */ + duk__bi_set_small(&nc_ctx->s, (duk_uint32_t) (nc_ctx->b * 2)); /* s <- 2 * b */ nc_ctx->unequal_gaps = 1; } else { /* (>= e 0) AND (not (= f (expt b (- p 1)))) @@ -788,11 +805,11 @@ "not lowest mantissa for this exponent -> " "equal gaps")); - duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ - duk__bi_copy(&nc_ctx->mp, &nc_ctx->mm); /* mp <- b^e */ + duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ + duk__bi_copy(&nc_ctx->mp, &nc_ctx->mm); /* mp <- b^e */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->f, 2); - duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^e */ - duk__bi_set_small(&nc_ctx->s, 2); /* s <- 2 */ + duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^e */ + duk__bi_set_small(&nc_ctx->s, 2); /* s <- 2 */ } } else { /* When doing string-to-number, lowest_mantissa is always 0 so @@ -814,9 +831,13 @@ "lowest mantissa for this exponent -> " "unequal gaps")); - duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, (duk_uint32_t) (nc_ctx->b * 2)); /* r <- (2 * b) * f */ - duk__bi_exp_small(&nc_ctx->t1, nc_ctx->b, 1 - nc_ctx->e, &nc_ctx->s, &nc_ctx->t2); /* NB: use 's' as temp on purpose */ - duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(1-e) * 2 */ + duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, (duk_uint32_t) (nc_ctx->b * 2)); /* r <- (2 * b) * f */ + duk__bi_exp_small(&nc_ctx->t1, + nc_ctx->b, + 1 - nc_ctx->e, + &nc_ctx->s, + &nc_ctx->t2); /* NB: use 's' as temp on purpose */ + duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(1-e) * 2 */ duk__bi_set_small(&nc_ctx->mp, 2); duk__bi_set_small(&nc_ctx->mm, 1); nc_ctx->unequal_gaps = 1; @@ -835,9 +856,13 @@ "lowest mantissa for this exponent -> " "equal gaps")); - duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, 2); /* r <- 2 * f */ - duk__bi_exp_small(&nc_ctx->t1, nc_ctx->b, -nc_ctx->e, &nc_ctx->s, &nc_ctx->t2); /* NB: use 's' as temp on purpose */ - duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(-e) * 2 */ + duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, 2); /* r <- 2 * f */ + duk__bi_exp_small(&nc_ctx->t1, + nc_ctx->b, + -nc_ctx->e, + &nc_ctx->s, + &nc_ctx->t2); /* NB: use 's' as temp on purpose */ + duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(-e) * 2 */ duk__bi_set_small(&nc_ctx->mp, 1); duk__bi_set_small(&nc_ctx->mm, 1); } @@ -869,8 +894,8 @@ * impact for very large and very small numbers. */ - DUK_DDD(DUK_DDDPRINT("scale: B=%ld, low_ok=%ld, high_ok=%ld", - (long) nc_ctx->B, (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); + DUK_DDD( + DUK_DDDPRINT("scale: B=%ld, low_ok=%ld, high_ok=%ld", (long) nc_ctx->B, (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); DUK__BI_PRINT("r(init)", &nc_ctx->r); DUK__BI_PRINT("s(init)", &nc_ctx->s); DUK__BI_PRINT("mp(init)", &nc_ctx->mp); @@ -883,7 +908,7 @@ DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) >= (nc_ctx->high_ok ? 0 : 1)) { DUK_DDD(DUK_DDDPRINT("k is too low")); /* r <- r @@ -912,8 +937,8 @@ DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ - duk__bi_mul_small(&nc_ctx->t2, &nc_ctx->t1, (duk_uint32_t) nc_ctx->B); /* t2 = (* (+ r m+) B) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ + duk__bi_mul_small(&nc_ctx->t2, &nc_ctx->t1, (duk_uint32_t) nc_ctx->B); /* t2 = (* (+ r m+) B) */ if (duk__bi_compare(&nc_ctx->t2, &nc_ctx->s) <= (nc_ctx->high_ok ? -1 : 0)) { DUK_DDD(DUK_DDDPRINT("k is too high")); /* r <- (* r B) @@ -934,11 +959,11 @@ } } - skip_dec_k: +skip_dec_k: if (!nc_ctx->unequal_gaps) { DUK_DDD(DUK_DDDPRINT("equal gaps, copy m- from m+")); - duk__bi_copy(&nc_ctx->mm, &nc_ctx->mp); /* mm <- mp */ + duk__bi_copy(&nc_ctx->mm, &nc_ctx->mp); /* mm <- mp */ } nc_ctx->k = k; @@ -950,9 +975,9 @@ } DUK_LOCAL void duk__dragon4_generate(duk__numconv_stringify_ctx *nc_ctx) { - duk_small_int_t tc1, tc2; /* terminating conditions */ - duk_small_int_t d; /* current digit */ - duk_small_int_t count = 0; /* digit count */ + duk_small_int_t tc1, tc2; /* terminating conditions */ + duk_small_int_t d; /* current digit */ + duk_small_int_t count = 0; /* digit count */ /* * Digit generation loop. @@ -974,25 +999,28 @@ for (;;) { DUK_DDD(DUK_DDDPRINT("generate loop, count=%ld, k=%ld, B=%ld, low_ok=%ld, high_ok=%ld", - (long) count, (long) nc_ctx->k, (long) nc_ctx->B, - (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); + (long) count, + (long) nc_ctx->k, + (long) nc_ctx->B, + (long) nc_ctx->low_ok, + (long) nc_ctx->high_ok)); DUK__BI_PRINT("r", &nc_ctx->r); DUK__BI_PRINT("s", &nc_ctx->s); DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); /* (quotient-remainder (* r B) s) using a dummy subtraction loop */ - duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, (duk_uint32_t) nc_ctx->B); /* t1 <- (* r B) */ + duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, (duk_uint32_t) nc_ctx->B); /* t1 <- (* r B) */ d = 0; for (;;) { if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { break; } - duk__bi_sub_copy(&nc_ctx->t1, &nc_ctx->s, &nc_ctx->t2); /* t1 <- t1 - s */ + duk__bi_sub_copy(&nc_ctx->t1, &nc_ctx->s, &nc_ctx->t2); /* t1 <- t1 - s */ d++; } - duk__bi_copy(&nc_ctx->r, &nc_ctx->t1); /* r <- (remainder (* r B) s) */ - /* d <- (quotient (* r B) s) (in range 0...B-1) */ + duk__bi_copy(&nc_ctx->r, &nc_ctx->t1); /* r <- (remainder (* r B) s) */ + /* d <- (quotient (* r B) s) (in range 0...B-1) */ DUK_DDD(DUK_DDDPRINT("-> d(quot)=%ld", (long) d)); DUK__BI_PRINT("r(rem)", &nc_ctx->r); @@ -1011,7 +1039,7 @@ /* free-form */ tc1 = (duk__bi_compare(&nc_ctx->r, &nc_ctx->mm) <= (nc_ctx->low_ok ? 0 : -1)); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 <- (+ r m+) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 <- (+ r m+) */ tc2 = (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) >= (nc_ctx->high_ok ? 0 : 1)); DUK_DDD(DUK_DDDPRINT("tc1=%ld, tc2=%ld", (long) tc1, (long) tc2)); @@ -1030,20 +1058,21 @@ if (tc2) { /* tc1 = true, tc2 = true */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, 2); - if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { /* (< (* r 2) s) */ + if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { /* (< (* r 2) s) */ DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=true, 2r > s: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + (long) d, + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); } else { DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=true, 2r <= s: output d+1 --> %ld (k=%ld)", - (long) (d + 1), (long) nc_ctx->k)); + (long) (d + 1), + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d + 1); } break; } else { /* tc1 = true, tc2 = false */ - DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=false: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=false: output d --> %ld (k=%ld)", (long) d, (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); break; } @@ -1051,13 +1080,13 @@ if (tc2) { /* tc1 = false, tc2 = true */ DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=true: output d+1 --> %ld (k=%ld)", - (long) (d + 1), (long) nc_ctx->k)); + (long) (d + 1), + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d + 1); break; } else { /* tc1 = false, tc2 = false */ - DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=false: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=false: output d --> %ld (k=%ld)", (long) d, (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); /* r <- r (updated above: r <- (remainder (* r B) s) @@ -1074,23 +1103,28 @@ /* fixed-format termination conditions */ if (nc_ctx->is_fixed) { if (nc_ctx->abs_pos) { - int pos = nc_ctx->k - count + 1; /* count is already incremented, take into account */ + int pos = nc_ctx->k - count + 1; /* count is already incremented, take into account */ DUK_DDD(DUK_DDDPRINT("fixed format, absolute: abs pos=%ld, k=%ld, count=%ld, req=%ld", - (long) pos, (long) nc_ctx->k, (long) count, (long) nc_ctx->req_digits)); + (long) pos, + (long) nc_ctx->k, + (long) count, + (long) nc_ctx->req_digits)); if (pos <= nc_ctx->req_digits) { DUK_DDD(DUK_DDDPRINT("digit position reached req_digits, end generate loop")); break; } } else { DUK_DDD(DUK_DDDPRINT("fixed format, relative: k=%ld, count=%ld, req=%ld", - (long) nc_ctx->k, (long) count, (long) nc_ctx->req_digits)); + (long) nc_ctx->k, + (long) count, + (long) nc_ctx->req_digits)); if (count >= nc_ctx->req_digits) { DUK_DDD(DUK_DDDPRINT("digit count reached req_digits, end generate loop")); break; } } } - } /* for */ + } /* for */ nc_ctx->count = count; @@ -1109,8 +1143,7 @@ bufi = (duk_uint8_t) DUK__DIGITCHAR(t); } } - DUK_DDD(DUK_DDDPRINT("-> generated digits; k=%ld, digits='%s'", - (long) nc_ctx->k, (const char *) buf)); + DUK_DDD(DUK_DDDPRINT("-> generated digits; k=%ld, digits='%s'", (long) nc_ctx->k, (const char *) buf)); } #endif } @@ -1139,11 +1172,11 @@ if (round_idx >= nc_ctx->count) { DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld >= %ld (count)) -> no rounding", - (long) round_idx, (long) nc_ctx->count)); + (long) round_idx, + (long) nc_ctx->count)); return 0; } else if (round_idx < 0) { - DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld < 0) -> no rounding", - (long) round_idx)); + DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld < 0) -> no rounding", (long) round_idx)); return 0; } @@ -1168,15 +1201,18 @@ duk_memmove((void *) (&nc_ctx->digits1), (const void *) (&nc_ctx->digits0), (size_t) (sizeof(char) * (size_t) nc_ctx->count)); - nc_ctx->digits0 = 1; /* don't increase 'count' */ - nc_ctx->k++; /* position of highest digit changed */ - nc_ctx->count++; /* number of digits changed */ + nc_ctx->digits0 = 1; /* don't increase 'count' */ + nc_ctx->k++; /* position of highest digit changed */ + nc_ctx->count++; /* number of digits changed */ ret = 1; break; } DUK_DDD(DUK_DDDPRINT("fixed-format rounding carry: B=%ld, roundup_limit=%ld, p=%p, digits=%p", - (long) nc_ctx->B, (long) roundup_limit, (void *) p, (void *) nc_ctx->digits)); + (long) nc_ctx->B, + (long) roundup_limit, + (void *) p, + (void *) nc_ctx->digits)); p--; t = *p; DUK_DDD(DUK_DDDPRINT("digit before carry: %ld", (long) t)); @@ -1193,7 +1229,7 @@ return ret; } -#define DUK__NO_EXP (65536) /* arbitrary marker, outside valid exp range */ +#define DUK__NO_EXP (65536) /* arbitrary marker, outside valid exp range */ DUK_LOCAL void duk__dragon4_convert_and_push(duk__numconv_stringify_ctx *nc_ctx, duk_hthread *thr, @@ -1236,7 +1272,7 @@ DUK_ASSERT(nc_ctx->count >= 1); k = nc_ctx->k; - buf = (duk_uint8_t *) &nc_ctx->f; /* XXX: union would be more correct */ + buf = (duk_uint8_t *) &nc_ctx->f; /* XXX: union would be more correct */ q = buf; /* Exponent handling: if exponent format is used, record exponent value and @@ -1248,14 +1284,13 @@ expt = DUK__NO_EXP; if (!nc_ctx->abs_pos /* toFixed() */) { - if ((flags & DUK_N2S_FLAG_FORCE_EXP) || /* exponential notation forced */ - ((flags & DUK_N2S_FLAG_NO_ZERO_PAD) && /* fixed precision and zero padding would be required */ - (k - digits >= 1)) || /* (e.g. k=3, digits=2 -> "12X") */ - ((k > 21 || k <= -6) && (radix == 10))) { /* toString() conditions */ - DUK_DDD(DUK_DDDPRINT("use exponential notation: k=%ld -> expt=%ld", - (long) k, (long) (k - 1))); - expt = k - 1; /* e.g. 12.3 -> digits="123" k=2 -> 1.23e1 */ - k = 1; /* generate mantissa with a single leading whole number digit */ + if ((flags & DUK_N2S_FLAG_FORCE_EXP) || /* exponential notation forced */ + ((flags & DUK_N2S_FLAG_NO_ZERO_PAD) && /* fixed precision and zero padding would be required */ + (k - digits >= 1)) || /* (e.g. k=3, digits=2 -> "12X") */ + ((k > 21 || k <= -6) && (radix == 10))) { /* toString() conditions */ + DUK_DDD(DUK_DDDPRINT("use exponential notation: k=%ld -> expt=%ld", (long) k, (long) (k - 1))); + expt = k - 1; /* e.g. 12.3 -> digits="123" k=2 -> 1.23e1 */ + k = 1; /* generate mantissa with a single leading whole number digit */ } } @@ -1281,13 +1316,18 @@ DUK_DDD(DUK_DDDPRINT("expt=%ld, k=%ld, count=%ld, pos=%ld, pos_end=%ld, is_fixed=%ld, " "digits=%ld, abs_pos=%ld", - (long) expt, (long) k, (long) nc_ctx->count, (long) pos, (long) pos_end, - (long) nc_ctx->is_fixed, (long) digits, (long) nc_ctx->abs_pos)); + (long) expt, + (long) k, + (long) nc_ctx->count, + (long) pos, + (long) pos_end, + (long) nc_ctx->is_fixed, + (long) digits, + (long) nc_ctx->abs_pos)); /* Digit generation */ while (pos > pos_end) { - DUK_DDD(DUK_DDDPRINT("digit generation: pos=%ld, pos_end=%ld", - (long) pos, (long) pos_end)); + DUK_DDD(DUK_DDDPRINT("digit generation: pos=%ld, pos_end=%ld", (long) pos, (long) pos_end)); if (pos == 0) { *q++ = (duk_uint8_t) '.'; } @@ -1380,7 +1420,7 @@ /* normal: implicit leading 1-bit */ nc_ctx->f.v1 |= 0x00100000UL; expt = expt - DUK__IEEE_DOUBLE_EXP_BIAS - 52; - DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); /* true, because v1 has at least one bit set */ + DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); /* true, because v1 has at least one bit set */ } DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); @@ -1403,7 +1443,7 @@ /* Sometimes this assert is not true right now; it will be true after * rounding. See: test-bug-numconv-mantissa-assert.js. */ - DUK_ASSERT_DISABLE(nc_ctx->digits0 == 1); /* zero handled by caller */ + DUK_ASSERT_DISABLE(nc_ctx->digits0 == 1); /* zero handled by caller */ /* Should not be required because the code below always sets both high * and low parts, but at least gcc-4.4.5 fails to deduce this correctly @@ -1448,31 +1488,30 @@ skip_round = 0; - recheck_exp: +recheck_exp: - expt = nc_ctx->k - 1; /* IEEE exp without bias */ + expt = nc_ctx->k - 1; /* IEEE exp without bias */ if (expt > 1023) { /* Infinity */ - bitstart = -255; /* needed for inf: causes mantissa to become zero, - * and rounding to be skipped. - */ + bitstart = -255; /* needed for inf: causes mantissa to become zero, + * and rounding to be skipped. + */ expt = 2047; } else if (expt >= -1022) { /* normal */ - bitstart = 1; /* skip leading digit */ + bitstart = 1; /* skip leading digit */ expt += DUK__IEEE_DOUBLE_EXP_BIAS; DUK_ASSERT(expt >= 1 && expt <= 2046); } else { /* denormal or zero */ - bitstart = 1023 + expt; /* expt==-1023 -> bitstart=0 (leading 1); - * expt==-1024 -> bitstart=-1 (one left of leading 1), etc - */ + bitstart = 1023 + expt; /* expt==-1023 -> bitstart=0 (leading 1); + * expt==-1024 -> bitstart=-1 (one left of leading 1), etc + */ expt = 0; } bitround = bitstart + 52; - DUK_DDD(DUK_DDDPRINT("ieee expt=%ld, bitstart=%ld, bitround=%ld", - (long) expt, (long) bitstart, (long) bitround)); + DUK_DDD(DUK_DDDPRINT("ieee expt=%ld, bitstart=%ld, bitround=%ld", (long) expt, (long) bitstart, (long) bitround)); if (!skip_round) { if (duk__dragon4_fixed_format_round(nc_ctx, bitround)) { @@ -1510,13 +1549,11 @@ } /* t has high mantissa */ - DUK_DDD(DUK_DDDPRINT("mantissa is complete: %08lx %08lx", - (unsigned long) t, - (unsigned long) DUK_DBLUNION_GET_LOW32(&u))); + DUK_DDD(DUK_DDDPRINT("mantissa is complete: %08lx %08lx", (unsigned long) t, (unsigned long) DUK_DBLUNION_GET_LOW32(&u))); DUK_ASSERT(expt >= 0 && expt <= 0x7ffL); t += ((duk_uint32_t) expt) << 20; -#if 0 /* caller handles sign change */ +#if 0 /* caller handles sign change */ if (negative) { t |= 0x80000000U; } @@ -1537,12 +1574,15 @@ * Output: string */ -DUK_LOCAL DUK_NOINLINE void duk__numconv_stringify_raw(duk_hthread *thr, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags) { +DUK_LOCAL DUK_NOINLINE void duk__numconv_stringify_raw(duk_hthread *thr, + duk_small_int_t radix, + duk_small_int_t digits, + duk_small_uint_t flags) { duk_double_t x; duk_small_int_t c; duk_small_int_t neg; duk_uint32_t uval; - duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ + duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ duk__numconv_stringify_ctx *nc_ctx = &nc_ctx_alloc; x = (duk_double_t) duk_require_number(thr, -1); @@ -1594,13 +1634,13 @@ */ uval = duk_double_to_uint32_t(x); - if (duk_double_equals((double) uval, x) && /* integer number in range */ - flags == 0) { /* no special formatting */ + if (duk_double_equals((double) uval, x) && /* integer number in range */ + flags == 0) { /* no special formatting */ /* use bigint area as a temp */ duk_uint8_t *buf = (duk_uint8_t *) (&nc_ctx->f); duk_uint8_t *p = buf; - DUK_ASSERT(DUK__NUMCONV_CTX_BIGINTS_SIZE >= 32 + 1); /* max size: radix=2 + sign */ + DUK_ASSERT(DUK__NUMCONV_CTX_BIGINTS_SIZE >= 32 + 1); /* max size: radix=2 + sign */ if (neg && uval != 0) { /* no negative sign for zero */ *p++ = (duk_uint8_t) '-'; @@ -1656,9 +1696,9 @@ duk_small_int_t count; if (nc_ctx->is_fixed) { if (nc_ctx->abs_pos) { - count = digits + 2; /* lead zero + 'digits' fractions + 1 for rounding */ + count = digits + 2; /* lead zero + 'digits' fractions + 1 for rounding */ } else { - count = digits + 1; /* + 1 for rounding */ + count = digits + 1; /* + 1 for rounding */ } } else { count = 1; @@ -1667,12 +1707,12 @@ DUK_ASSERT(count >= 1); duk_memzero((void *) nc_ctx->digits, (size_t) count); nc_ctx->count = count; - nc_ctx->k = 1; /* 0.000... */ + nc_ctx->k = 1; /* 0.000... */ neg = 0; goto zero_skip; } - duk__dragon4_double_to_ctx(nc_ctx, x); /* -> sets 'f' and 'e' */ + duk__dragon4_double_to_ctx(nc_ctx, x); /* -> sets 'f' and 'e' */ DUK__BI_PRINT("f", &nc_ctx->f); DUK_DDD(DUK_DDDPRINT("e=%ld", (long) nc_ctx->e)); @@ -1680,7 +1720,7 @@ * Dragon4 slow path digit generation. */ - duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ + duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ DUK_DDD(DUK_DDDPRINT("after prepare:")); DUK__BI_PRINT("r", &nc_ctx->r); @@ -1702,7 +1742,7 @@ * Convert and push final string. */ - zero_skip: +zero_skip: if (flags & DUK_N2S_FLAG_FIXED_FORMAT) { /* Perform fixed-format rounding. */ @@ -1711,13 +1751,16 @@ /* 'roundpos' is relative to nc_ctx->k and increases to the right * (opposite of how 'k' changes). */ - roundpos = -digits; /* absolute position for digit considered for rounding */ + roundpos = -digits; /* absolute position for digit considered for rounding */ roundpos = nc_ctx->k - roundpos; } else { roundpos = digits; } DUK_DDD(DUK_DDDPRINT("rounding: k=%ld, count=%ld, digits=%ld, roundpos=%ld", - (long) nc_ctx->k, (long) nc_ctx->count, (long) digits, (long) roundpos)); + (long) nc_ctx->k, + (long) nc_ctx->count, + (long) digits, + (long) roundpos)); (void) duk__dragon4_fixed_format_round(nc_ctx, roundpos); /* Note: 'count' is currently not adjusted by rounding (i.e. the @@ -1746,7 +1789,7 @@ */ DUK_LOCAL DUK_NOINLINE void duk__numconv_parse_raw(duk_hthread *thr, duk_small_int_t radix, duk_small_uint_t flags) { - duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ + duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ duk__numconv_stringify_ctx *nc_ctx = &nc_ctx_alloc; duk_double_t res; duk_hstring *h_str; @@ -1766,7 +1809,8 @@ DUK_DDD(DUK_DDDPRINT("parse number: %!T, radix=%ld, flags=0x%08lx", (duk_tval *) duk_get_tval(thr, -1), - (long) radix, (unsigned long) flags)); + (long) radix, + (unsigned long) flags)); DUK_ASSERT(radix >= 2 && radix <= 36); DUK_ASSERT(radix - 2 < (duk_small_int_t) sizeof(duk__str2num_digits_for_radix)); @@ -1839,7 +1883,7 @@ ch = *p; if (ch == (duk_small_int_t) '0') { duk_small_int_t detect_radix = 0; - ch = DUK_LOWERCASE_CHAR_ASCII(p1); /* 'x' or 'X' -> 'x' */ + ch = DUK_LOWERCASE_CHAR_ASCII(p1); /* 'x' or 'X' -> 'x' */ if ((flags & DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT) && ch == DUK_ASC_LC_X) { DUK_DDD(DUK_DDDPRINT("detected 0x/0X hex prefix, changing radix and preventing fractions and exponent")); detect_radix = 16; @@ -1866,10 +1910,9 @@ if (detect_radix > 0) { radix = detect_radix; /* Clear empty as zero flag: interpret e.g. '0x' and '0xg' as a NaN (= parse error) */ - flags &= ~(DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO); - flags |= DUK_S2N_FLAG_ALLOW_LEADING_ZERO; /* allow e.g. '0x0009' and '0b00010001' */ + flags &= ~(DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_FRAC | + DUK_S2N_FLAG_ALLOW_NAKED_FRAC | DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO); + flags |= DUK_S2N_FLAG_ALLOW_LEADING_ZERO; /* allow e.g. '0x0009' and '0b00010001' */ p += 2; } } @@ -1927,16 +1970,23 @@ dig_frac = -1; dig_expt = -1; expt = 0; - expt_adj = 0; /* essentially tracks digit position of lowest 'f' digit */ + expt_adj = 0; /* essentially tracks digit position of lowest 'f' digit */ expt_neg = 0; for (;;) { ch = *p++; DUK_DDD(DUK_DDDPRINT("parse digits: p=%p, ch='%c' (%ld), expt=%ld, expt_adj=%ld, " "dig_whole=%ld, dig_frac=%ld, dig_expt=%ld, dig_lzero=%ld, dig_prec=%ld", - (const void *) p, (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : '?'), (long) ch, - (long) expt, (long) expt_adj, (long) dig_whole, (long) dig_frac, - (long) dig_expt, (long) dig_lzero, (long) dig_prec)); + (const void *) p, + (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : '?'), + (long) ch, + (long) expt, + (long) expt_adj, + (long) dig_whole, + (long) dig_frac, + (long) dig_expt, + (long) dig_lzero, + (long) dig_prec)); DUK__BI_PRINT("f", &nc_ctx->f); /* Most common cases first. */ @@ -1975,8 +2025,8 @@ } else if (ch == (duk_small_int_t) 0) { DUK_DDD(DUK_DDDPRINT("NUL termination")); break; - } else if ((flags & DUK_S2N_FLAG_ALLOW_EXP) && - dig_expt < 0 && (ch == (duk_small_int_t) 'e' || ch == (duk_small_int_t) 'E')) { + } else if ((flags & DUK_S2N_FLAG_ALLOW_EXP) && dig_expt < 0 && + (ch == (duk_small_int_t) 'e' || ch == (duk_small_int_t) 'E')) { /* Note: we don't parse back exponent notation for anything else * than radix 10, so this is not an ambiguous check (e.g. hex * exponent values may have 'e' either as a significand digit @@ -2006,7 +2056,7 @@ } else if (ch >= (duk_small_int_t) 'A' && ch <= (duk_small_int_t) 'Z') { dig = (duk_small_int_t) (ch - (duk_small_int_t) 'A' + 0x0a); } else { - dig = 255; /* triggers garbage digit check below */ + dig = 255; /* triggers garbage digit check below */ } DUK_ASSERT((dig >= 0 && dig <= 35) || dig == 255); @@ -2139,14 +2189,14 @@ if (expt_neg) { expt = -expt; } - DUK_DDD(DUK_DDDPRINT("expt=%ld, expt_adj=%ld, net exponent -> %ld", - (long) expt, (long) expt_adj, (long) (expt + expt_adj))); + DUK_DDD( + DUK_DDDPRINT("expt=%ld, expt_adj=%ld, net exponent -> %ld", (long) expt, (long) expt_adj, (long) (expt + expt_adj))); expt += expt_adj; /* Fast path check. */ - if (nc_ctx->f.n <= 1 && /* 32-bit value */ - expt == 0 /* no net exponent */) { + if (nc_ctx->f.n <= 1 && /* 32-bit value */ + expt == 0 /* no net exponent */) { /* Fast path is triggered for no exponent and also for balanced exponent * and fraction parts, e.g. for "1.23e2" == "123". Remember to respect * zero sign. @@ -2188,7 +2238,6 @@ goto negcheck_and_ret; } - /* Quick reject of too large or too small exponents. This check * would be incorrect for zero (e.g. "0e1000" is zero, not Infinity) * so zero check must be above. @@ -2221,7 +2270,7 @@ * An extra digit is generated for rounding. */ - duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ + duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ DUK_DDD(DUK_DDDPRINT("after prepare:")); DUK__BI_PRINT("r", &nc_ctx->r); @@ -2253,7 +2302,7 @@ duk__dragon4_ctx_to_double(nc_ctx, &res); goto negcheck_and_ret; - negcheck_and_ret: +negcheck_and_ret: if (neg) { res = -res; } @@ -2262,13 +2311,13 @@ DUK_DDD(DUK_DDDPRINT("result: %!T", (duk_tval *) duk_get_tval(thr, -1))); return; - parse_fail: +parse_fail: DUK_DDD(DUK_DDDPRINT("parse failed")); duk_pop(thr); duk_push_nan(thr); return; - parse_explimit_error: +parse_explimit_error: DUK_DDD(DUK_DDDPRINT("parse failed, internal error, can't return a value")); DUK_ERROR_RANGE(thr, "exponent too large"); DUK_WO_NORETURN(return;);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_numconv.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_numconv.h
Changed
@@ -9,23 +9,23 @@ /* Output a specified number of digits instead of using the shortest * form. Used for toPrecision() and toFixed(). */ -#define DUK_N2S_FLAG_FIXED_FORMAT (1U << 0) +#define DUK_N2S_FLAG_FIXED_FORMAT (1U << 0) /* Force exponential format. Used for toExponential(). */ -#define DUK_N2S_FLAG_FORCE_EXP (1U << 1) +#define DUK_N2S_FLAG_FORCE_EXP (1U << 1) /* If number would need zero padding (for whole number part), use * exponential format instead. E.g. if input number is 12300, 3 * digits are generated ("123"), output "1.23e+4" instead of "12300". * Used for toPrecision(). */ -#define DUK_N2S_FLAG_NO_ZERO_PAD (1U << 2) +#define DUK_N2S_FLAG_NO_ZERO_PAD (1U << 2) /* Digit count indicates number of fractions (i.e. an absolute * digit index instead of a relative one). Used together with * DUK_N2S_FLAG_FIXED_FORMAT for toFixed(). */ -#define DUK_N2S_FLAG_FRACTION_DIGITS (1U << 3) +#define DUK_N2S_FLAG_FRACTION_DIGITS (1U << 3) /* * String-to-number conversion @@ -39,66 +39,69 @@ * radix 10, but with maximum radix (36) a safe limit is: * (10000000*36).toString(16) -> '15752a00' */ -#define DUK_S2N_MAX_EXPONENT 10000000L +#define DUK_S2N_MAX_EXPONENT 10000000L /* Trim white space (= allow leading and trailing whitespace) */ -#define DUK_S2N_FLAG_TRIM_WHITE (1U << 0) +#define DUK_S2N_FLAG_TRIM_WHITE (1U << 0) /* Allow exponent */ -#define DUK_S2N_FLAG_ALLOW_EXP (1U << 1) +#define DUK_S2N_FLAG_ALLOW_EXP (1U << 1) /* Allow trailing garbage (e.g. treat "123foo" as "123) */ -#define DUK_S2N_FLAG_ALLOW_GARBAGE (1U << 2) +#define DUK_S2N_FLAG_ALLOW_GARBAGE (1U << 2) /* Allow leading plus sign */ -#define DUK_S2N_FLAG_ALLOW_PLUS (1U << 3) +#define DUK_S2N_FLAG_ALLOW_PLUS (1U << 3) /* Allow leading minus sign */ -#define DUK_S2N_FLAG_ALLOW_MINUS (1U << 4) +#define DUK_S2N_FLAG_ALLOW_MINUS (1U << 4) /* Allow 'Infinity' */ -#define DUK_S2N_FLAG_ALLOW_INF (1U << 5) +#define DUK_S2N_FLAG_ALLOW_INF (1U << 5) /* Allow fraction part */ -#define DUK_S2N_FLAG_ALLOW_FRAC (1U << 6) +#define DUK_S2N_FLAG_ALLOW_FRAC (1U << 6) /* Allow naked fraction (e.g. ".123") */ -#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1U << 7) +#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1U << 7) /* Allow empty fraction (e.g. "123.") */ -#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1U << 8) +#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1U << 8) /* Allow empty string to be interpreted as 0 */ -#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1U << 9) +#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1U << 9) /* Allow leading zeroes (e.g. "0123" -> "123") */ -#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1U << 10) +#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1U << 10) /* Allow automatic detection of hex base ("0x" or "0X" prefix), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1U << 11) +#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1U << 11) /* Allow automatic detection of legacy octal base ("0n"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_LEGACY_OCT_INT (1U << 12) +#define DUK_S2N_FLAG_ALLOW_AUTO_LEGACY_OCT_INT (1U << 12) /* Allow automatic detection of ES2015 octal base ("0o123"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1U << 13) +#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1U << 13) /* Allow automatic detection of ES2015 binary base ("0b10001"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT (1U << 14) +#define DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT (1U << 14) /* * Prototypes */ -DUK_INTERNAL_DECL void duk_numconv_stringify(duk_hthread *thr, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_numconv_stringify(duk_hthread *thr, + duk_small_int_t radix, + duk_small_int_t digits, + duk_small_uint_t flags); DUK_INTERNAL_DECL void duk_numconv_parse(duk_hthread *thr, duk_small_int_t radix, duk_small_uint_t flags); -#endif /* DUK_NUMCONV_H_INCLUDED */ +#endif /* DUK_NUMCONV_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_refcount.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_refcount.h
Changed
@@ -17,19 +17,20 @@ /* XXX: double evaluation for 'tv' argument. */ #define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) \ (DUK_TVAL_IS_HEAP_ALLOCATED((tv)) && !DUK_HEAPHDR_HAS_READONLY(DUK_TVAL_GET_HEAPHDR((tv)))) -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) (!DUK_HEAPHDR_HAS_READONLY((h))) -#else /* DUK_USE_ROM_OBJECTS */ +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) (!DUK_HEAPHDR_HAS_READONLY((h))) +#else /* DUK_USE_ROM_OBJECTS */ /* Without ROM objects "needs refcount update" == is heap allocated. */ -#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) DUK_TVAL_IS_HEAP_ALLOCATED((tv)) -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 1 -#endif /* DUK_USE_ROM_OBJECTS */ +#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) DUK_TVAL_IS_HEAP_ALLOCATED((tv)) +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 1 +#endif /* DUK_USE_ROM_OBJECTS */ /* Fast variants, inline refcount operations except for refzero handling. * Can be used explicitly when speed is always more important than size. * For a good compiler and a single file build, these are basically the * same as a forced inline. */ -#define DUK_TVAL_INCREF_FAST(thr,tv) do { \ +#define DUK_TVAL_INCREF_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -37,10 +38,11 @@ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ DUK_HEAPHDR_PREINC_REFCOUNT(duk__h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ } \ } while (0) -#define DUK_TVAL_DECREF_FAST(thr,tv) do { \ +#define DUK_TVAL_DECREF_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -53,7 +55,8 @@ } \ } \ } while (0) -#define DUK_TVAL_DECREF_NORZ_FAST(thr,tv) do { \ +#define DUK_TVAL_DECREF_NORZ_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -66,16 +69,18 @@ } \ } \ } while (0) -#define DUK_HEAPHDR_INCREF_FAST(thr,h) do { \ +#define DUK_HEAPHDR_INCREF_FAST(thr, h) \ + do { \ duk_heaphdr *duk__h = (duk_heaphdr *) (h); \ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ if (DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(duk__h)) { \ DUK_HEAPHDR_PREINC_REFCOUNT(duk__h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_FAST_RAW(thr,h,rzcall,rzcast) do { \ +#define DUK_HEAPHDR_DECREF_FAST_RAW(thr, h, rzcall, rzcast) \ + do { \ duk_heaphdr *duk__h = (duk_heaphdr *) (h); \ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ @@ -86,29 +91,72 @@ } \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_FAST(thr,h) \ - DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero,duk_heaphdr *) -#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr,h) \ - DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero_norz,duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_FAST(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero, duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero_norz, duk_heaphdr *) /* Slow variants, call to a helper to reduce code size. * Can be used explicitly when size is always more important than speed. */ -#define DUK_TVAL_INCREF_SLOW(thr,tv) do { duk_tval_incref((tv)); } while (0) -#define DUK_TVAL_DECREF_SLOW(thr,tv) do { duk_tval_decref((thr), (tv)); } while (0) -#define DUK_TVAL_DECREF_NORZ_SLOW(thr,tv) do { duk_tval_decref_norz((thr), (tv)); } while (0) -#define DUK_HEAPHDR_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HEAPHDR_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) +#define DUK_TVAL_INCREF_SLOW(thr, tv) \ + do { \ + duk_tval_incref((tv)); \ + } while (0) +#define DUK_TVAL_DECREF_SLOW(thr, tv) \ + do { \ + duk_tval_decref((thr), (tv)); \ + } while (0) +#define DUK_TVAL_DECREF_NORZ_SLOW(thr, tv) \ + do { \ + duk_tval_decref_norz((thr), (tv)); \ + } while (0) +#define DUK_HEAPHDR_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HEAPHDR_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) /* Default variants. Selection depends on speed/size preference. * Concretely: with gcc 4.8.1 -Os x64 the difference in final binary @@ -118,122 +166,136 @@ /* XXX: It would be nice to specialize for specific duk_hobject subtypes * but current refzero queue handling prevents that. */ -#define DUK_TVAL_INCREF(thr,tv) DUK_TVAL_INCREF_FAST((thr),(tv)) -#define DUK_TVAL_DECREF(thr,tv) DUK_TVAL_DECREF_FAST((thr),(tv)) -#define DUK_TVAL_DECREF_NORZ(thr,tv) DUK_TVAL_DECREF_NORZ_FAST((thr),(tv)) -#define DUK_HEAPHDR_INCREF(thr,h) DUK_HEAPHDR_INCREF_FAST((thr),(h)) -#define DUK_HEAPHDR_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero,duk_heaphdr *) -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero_norz,duk_heaphdr *) -#define DUK_HSTRING_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HSTRING_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hstring_refzero,duk_hstring *) -#define DUK_HSTRING_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hstring_refzero,duk_hstring *) /* no 'norz' variant */ -#define DUK_HOBJECT_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HOBJECT_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HOBJECT_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HBUFFER_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HBUFFER_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hbuffer_refzero,duk_hbuffer *) -#define DUK_HBUFFER_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hbuffer_refzero,duk_hbuffer *) /* no 'norz' variant */ -#define DUK_HCOMPFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HNATFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HNATFUNC_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HBUFOBJ_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HBUFOBJ_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HBUFOBJ_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HTHREAD_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HTHREAD_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HTHREAD_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) +#define DUK_TVAL_INCREF(thr, tv) DUK_TVAL_INCREF_FAST((thr), (tv)) +#define DUK_TVAL_DECREF(thr, tv) DUK_TVAL_DECREF_FAST((thr), (tv)) +#define DUK_TVAL_DECREF_NORZ(thr, tv) DUK_TVAL_DECREF_NORZ_FAST((thr), (tv)) +#define DUK_HEAPHDR_INCREF(thr, h) DUK_HEAPHDR_INCREF_FAST((thr), (h)) +#define DUK_HEAPHDR_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero, duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero_norz, duk_heaphdr *) +#define DUK_HSTRING_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HSTRING_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hstring_refzero, duk_hstring *) +#define DUK_HSTRING_DECREF_NORZ(thr, h) \ + DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hstring_refzero, duk_hstring *) /* no 'norz' variant */ +#define DUK_HOBJECT_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HOBJECT_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HOBJECT_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HBUFFER_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HBUFFER_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hbuffer_refzero, duk_hbuffer *) +#define DUK_HBUFFER_DECREF_NORZ(thr, h) \ + DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hbuffer_refzero, duk_hbuffer *) /* no 'norz' variant */ +#define DUK_HCOMPFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HNATFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HNATFUNC_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HBUFOBJ_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HBUFOBJ_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HBUFOBJ_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HTHREAD_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HTHREAD_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HTHREAD_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) #else -#define DUK_TVAL_INCREF(thr,tv) DUK_TVAL_INCREF_SLOW((thr),(tv)) -#define DUK_TVAL_DECREF(thr,tv) DUK_TVAL_DECREF_SLOW((thr),(tv)) -#define DUK_TVAL_DECREF_NORZ(thr,tv) DUK_TVAL_DECREF_NORZ_SLOW((thr),(tv)) -#define DUK_HEAPHDR_INCREF(thr,h) DUK_HEAPHDR_INCREF_SLOW((thr),(h)) -#define DUK_HEAPHDR_DECREF(thr,h) DUK_HEAPHDR_DECREF_SLOW((thr),(h)) -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HSTRING_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HSTRING_DECREF(thr,h) DUK_HSTRING_DECREF_SLOW((thr),(h)) -#define DUK_HSTRING_DECREF_NORZ(thr,h) DUK_HSTRING_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HOBJECT_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HOBJECT_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(h)) -#define DUK_HOBJECT_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HBUFFER_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HBUFFER_DECREF(thr,h) DUK_HBUFFER_DECREF_SLOW((thr),(h)) -#define DUK_HBUFFER_DECREF_NORZ(thr,h) DUK_HBUFFER_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HCOMPFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HNATFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HNATFUNC_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HBUFOBJ_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HBUFOBJ_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HBUFOB_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HTHREAD_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HTHREAD_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HTHREAD_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) +#define DUK_TVAL_INCREF(thr, tv) DUK_TVAL_INCREF_SLOW((thr), (tv)) +#define DUK_TVAL_DECREF(thr, tv) DUK_TVAL_DECREF_SLOW((thr), (tv)) +#define DUK_TVAL_DECREF_NORZ(thr, tv) DUK_TVAL_DECREF_NORZ_SLOW((thr), (tv)) +#define DUK_HEAPHDR_INCREF(thr, h) DUK_HEAPHDR_INCREF_SLOW((thr), (h)) +#define DUK_HEAPHDR_DECREF(thr, h) DUK_HEAPHDR_DECREF_SLOW((thr), (h)) +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HSTRING_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HSTRING_DECREF(thr, h) DUK_HSTRING_DECREF_SLOW((thr), (h)) +#define DUK_HSTRING_DECREF_NORZ(thr, h) DUK_HSTRING_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HOBJECT_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HOBJECT_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (h)) +#define DUK_HOBJECT_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HBUFFER_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HBUFFER_DECREF(thr, h) DUK_HBUFFER_DECREF_SLOW((thr), (h)) +#define DUK_HBUFFER_DECREF_NORZ(thr, h) DUK_HBUFFER_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HCOMPFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HNATFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HNATFUNC_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HBUFOBJ_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HBUFOBJ_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HBUFOB_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HTHREAD_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HTHREAD_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HTHREAD_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) #endif /* Convenience for some situations; the above macros don't allow NULLs * for performance reasons. Macros cover only actually needed cases. */ -#define DUK_HEAPHDR_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_DECREF((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_DECREF_NORZ((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HOBJECT_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HOBJECT_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_DECREF_NORZ((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_DECREF_NORZ((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_DECREF_NORZ((thr), (h)); \ } \ @@ -245,16 +307,22 @@ * variant is performance critical. */ #if defined(DUK_USE_FINALIZER_SUPPORT) -#define DUK_REFZERO_CHECK_FAST(thr) do { \ +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ duk_refzero_check_fast((thr)); \ } while (0) -#define DUK_REFZERO_CHECK_SLOW(thr) do { \ +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ duk_refzero_check_slow((thr)); \ } while (0) -#else /* DUK_USE_FINALIZER_SUPPORT */ -#define DUK_REFZERO_CHECK_FAST(thr) do { } while (0) -#define DUK_REFZERO_CHECK_SLOW(thr) do { } while (0) -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ + } while (0) +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ + } while (0) +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Macros to set a duk_tval and update refcount of the target (decref the @@ -262,125 +330,176 @@ * and footprint critical; any changes made should be measured for size/speed. */ -#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ DUK_TVAL_DECREF_NORZ((thr), &tv__tmp); \ } while (0) -#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNUSED(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NULL(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_BOOLEAN(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NUMBER(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_DOUBLE(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NAN(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_I48(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_I32(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_U32(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) #else -#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr,tvptr_dst,newval) \ +#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr, tvptr_dst, newval) \ DUK_TVAL_SET_DOUBLE_UPDREF((thr), (tvptr_dst), (duk_double_t) (newval)) -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr,tvptr_dst,lf_v,lf_fp,lf_flags) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr, tvptr_dst, lf_v, lf_fp, lf_flags) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_LIGHTFUNC(tv__dst, (lf_v), (lf_fp), (lf_flags)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_STRING(tv__dst, (newval)); \ DUK_HSTRING_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_OBJECT(tv__dst, (newval)); \ DUK_HOBJECT_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_BUFFER(tv__dst, (newval)); \ DUK_HBUFFER_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_POINTER(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) /* DUK_TVAL_SET_TVAL_UPDREF() is used a lot in executor, property lookups, @@ -391,281 +510,452 @@ */ /* Original idiom used, minimal code size. */ -#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr,tvptr_dst,tvptr_src) do { \ - duk_tval *tv__dst, *tv__src; duk_tval tv__tmp; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr, tvptr_dst, tvptr_src) \ + do { \ + duk_tval *tv__dst, *tv__src; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ DUK_TVAL_INCREF((thr), tv__src); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) /* Faster alternative: avoid making a temporary copy of tvptr_dst and use * fast incref/decref macros. */ -#define DUK_TVAL_SET_TVAL_UPDREF_ALT1(thr,tvptr_dst,tvptr_src) do { \ - duk_tval *tv__dst, *tv__src; duk_heaphdr *h__obj; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT1(thr, tvptr_dst, tvptr_src) \ + do { \ + duk_tval *tv__dst, *tv__src; \ + duk_heaphdr *h__obj; \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_INCREF_FAST((thr), tv__src); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv__dst)) { \ h__obj = DUK_TVAL_GET_HEAPHDR(tv__dst); \ DUK_ASSERT(h__obj != NULL); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ - DUK_HEAPHDR_DECREF_FAST((thr), h__obj); /* side effects */ \ + DUK_HEAPHDR_DECREF_FAST((thr), h__obj); /* side effects */ \ } else { \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ } \ } while (0) /* XXX: no optimized variants yet */ -#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0 -#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 -#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 -#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 -#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 -#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0 +#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 +#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 +#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 +#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 +#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 #else -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 -#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 -#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 -#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 -#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 +#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 +#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 +#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 +#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 #if defined(DUK_USE_FAST_REFCOUNT_DEFAULT) /* Optimized for speed. */ -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT1 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT1 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT1 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT1 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 #else /* Optimized for size. */ -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 #endif -#else /* DUK_USE_REFERENCE_COUNTING */ - -#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) 0 -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 0 - -#define DUK_TVAL_INCREF_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_INCREF_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_INCREF(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ(thr,v) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ(thr,h) do {} while (0) /* nop */ - -#define DUK_HCOMPFUNC_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HCOMPFUNC_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr,h) do {} while (0) /* nop */ - -#define DUK_REFZERO_CHECK_FAST(thr) do {} while (0) /* nop */ -#define DUK_REFZERO_CHECK_SLOW(thr) do {} while (0) /* nop */ - -#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#else /* DUK_USE_REFERENCE_COUNTING */ + +#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) 0 +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 0 + +#define DUK_TVAL_INCREF_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_INCREF_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_INCREF(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ + +#define DUK_HCOMPFUNC_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HCOMPFUNC_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ + +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ + } while (0) /* nop */ +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ + } while (0) /* nop */ + +#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_UNUSED(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NULL(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_BOOLEAN(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NUMBER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_DOUBLE(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NAN(tv__dst); \ DUK_UNREF((thr)); \ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_I48(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_I32(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_U32(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) #else -#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr,tvptr_dst,newval) \ +#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr, tvptr_dst, newval) \ DUK_TVAL_SET_DOUBLE_UPDREF((thr), (tvptr_dst), (duk_double_t) (newval)) -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr,tvptr_dst,lf_v,lf_fp,lf_flags) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr, tvptr_dst, lf_v, lf_fp, lf_flags) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_LIGHTFUNC(tv__dst, (lf_v), (lf_fp), (lf_flags)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_STRING(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_OBJECT(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_BUFFER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_POINTER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr,tvptr_dst,tvptr_src) do { \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr, tvptr_dst, tvptr_src) \ + do { \ duk_tval *tv__dst, *tv__src; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 -#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 -#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 -#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 -#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 +#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 +#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 +#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 +#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 #else -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast-int-to-double */ -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 -#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 -#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 -#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 -#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 - -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 - -#endif /* DUK_USE_REFERENCE_COUNTING */ +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast-int-to-double */ +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 +#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 +#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 +#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 +#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 + +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 + +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Some convenience macros that don't have optimized implementations now. */ -#define DUK_TVAL_SET_TVAL_UPDREF_NORZ(thr,tv_dst,tv_src) do { \ +#define DUK_TVAL_SET_TVAL_UPDREF_NORZ(thr, tv_dst, tv_src) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_tval *duk__dst = (tv_dst); \ duk_tval *duk__src = (tv_src); \ @@ -675,7 +965,8 @@ DUK_TVAL_INCREF(thr, duk__dst); \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_NORZ(thr,tv_dst,val) do { \ +#define DUK_TVAL_SET_U32_UPDREF_NORZ(thr, tv_dst, val) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_tval *duk__dst = (tv_dst); \ duk_uint32_t duk__val = (duk_uint32_t) (val); \ @@ -695,7 +986,7 @@ #endif DUK_INTERNAL_DECL void duk_heaphdr_refcount_finalize_norz(duk_heap *heap, duk_heaphdr *hdr); DUK_INTERNAL_DECL void duk_hobject_refcount_finalize_norz(duk_heap *heap, duk_hobject *h); -#if 0 /* Not needed: fast path handles inline; slow path uses duk_heaphdr_decref() which is needed anyway. */ +#if 0 /* Not needed: fast path handles inline; slow path uses duk_heaphdr_decref() which is needed anyway. */ DUK_INTERNAL_DECL void duk_hstring_decref(duk_hthread *thr, duk_hstring *h); DUK_INTERNAL_DECL void duk_hstring_decref_norz(duk_hthread *thr, duk_hstring *h); DUK_INTERNAL_DECL void duk_hbuffer_decref(duk_hthread *thr, duk_hbuffer *h); @@ -706,8 +997,8 @@ DUK_INTERNAL_DECL void duk_heaphdr_refzero(duk_hthread *thr, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_refzero_norz(duk_hthread *thr, duk_heaphdr *h); #if defined(DUK_USE_FAST_REFCOUNT_DEFAULT) -DUK_INTERNAL_DECL void duk_hstring_refzero(duk_hthread *thr, duk_hstring *h); /* no 'norz' variant */ -DUK_INTERNAL_DECL void duk_hbuffer_refzero(duk_hthread *thr, duk_hbuffer *h); /* no 'norz' variant */ +DUK_INTERNAL_DECL void duk_hstring_refzero(duk_hthread *thr, duk_hstring *h); /* no 'norz' variant */ +DUK_INTERNAL_DECL void duk_hbuffer_refzero(duk_hthread *thr, duk_hbuffer *h); /* no 'norz' variant */ DUK_INTERNAL_DECL void duk_hobject_refzero(duk_hthread *thr, duk_hobject *h); DUK_INTERNAL_DECL void duk_hobject_refzero_norz(duk_hthread *thr, duk_hobject *h); #else @@ -718,8 +1009,8 @@ DUK_INTERNAL_DECL void duk_heaphdr_decref(duk_hthread *thr, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_decref_norz(duk_hthread *thr, duk_heaphdr *h); #endif -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ /* no refcounting */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ -#endif /* DUK_REFCOUNT_H_INCLUDED */ +#endif /* DUK_REFCOUNT_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_regexp.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_regexp.h
Changed
@@ -6,39 +6,39 @@ #define DUK_REGEXP_H_INCLUDED /* maximum bytecode copies for {n,m} quantifiers */ -#define DUK_RE_MAX_ATOM_COPIES 1000 +#define DUK_RE_MAX_ATOM_COPIES 1000 /* regexp compilation limits */ -#define DUK_RE_COMPILE_TOKEN_LIMIT 100000000L /* 1e8 */ +#define DUK_RE_COMPILE_TOKEN_LIMIT 100000000L /* 1e8 */ /* regexp execution limits */ -#define DUK_RE_EXECUTE_STEPS_LIMIT 1000000000L /* 1e9 */ +#define DUK_RE_EXECUTE_STEPS_LIMIT 1000000000L /* 1e9 */ /* regexp opcodes */ -#define DUK_REOP_MATCH 1 -#define DUK_REOP_CHAR 2 -#define DUK_REOP_PERIOD 3 -#define DUK_REOP_RANGES 4 -#define DUK_REOP_INVRANGES 5 -#define DUK_REOP_JUMP 6 -#define DUK_REOP_SPLIT1 7 -#define DUK_REOP_SPLIT2 8 -#define DUK_REOP_SQMINIMAL 9 -#define DUK_REOP_SQGREEDY 10 -#define DUK_REOP_SAVE 11 -#define DUK_REOP_WIPERANGE 12 -#define DUK_REOP_LOOKPOS 13 -#define DUK_REOP_LOOKNEG 14 -#define DUK_REOP_BACKREFERENCE 15 -#define DUK_REOP_ASSERT_START 16 -#define DUK_REOP_ASSERT_END 17 -#define DUK_REOP_ASSERT_WORD_BOUNDARY 18 -#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY 19 +#define DUK_REOP_MATCH 1 +#define DUK_REOP_CHAR 2 +#define DUK_REOP_PERIOD 3 +#define DUK_REOP_RANGES 4 +#define DUK_REOP_INVRANGES 5 +#define DUK_REOP_JUMP 6 +#define DUK_REOP_SPLIT1 7 +#define DUK_REOP_SPLIT2 8 +#define DUK_REOP_SQMINIMAL 9 +#define DUK_REOP_SQGREEDY 10 +#define DUK_REOP_SAVE 11 +#define DUK_REOP_WIPERANGE 12 +#define DUK_REOP_LOOKPOS 13 +#define DUK_REOP_LOOKNEG 14 +#define DUK_REOP_BACKREFERENCE 15 +#define DUK_REOP_ASSERT_START 16 +#define DUK_REOP_ASSERT_END 17 +#define DUK_REOP_ASSERT_WORD_BOUNDARY 18 +#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY 19 /* flags */ -#define DUK_RE_FLAG_GLOBAL (1U << 0) -#define DUK_RE_FLAG_IGNORE_CASE (1U << 1) -#define DUK_RE_FLAG_MULTILINE (1U << 2) +#define DUK_RE_FLAG_GLOBAL (1U << 0) +#define DUK_RE_FLAG_IGNORE_CASE (1U << 1) +#define DUK_RE_FLAG_MULTILINE (1U << 2) struct duk_re_matcher_ctx { duk_hthread *thr; @@ -48,7 +48,7 @@ const duk_uint8_t *input_end; const duk_uint8_t *bytecode; const duk_uint8_t *bytecode_end; - const duk_uint8_t **saved; /* allocated from valstack (fixed buffer) */ + const duk_uint8_t **saved; /* allocated from valstack (fixed buffer) */ duk_uint32_t nsaved; duk_uint32_t recursion_depth; duk_uint32_t recursion_limit; @@ -63,11 +63,11 @@ duk_lexer_ctx lex; duk_re_token curr_token; duk_bufwriter_ctx bw; - duk_uint32_t captures; /* highest capture number emitted so far (used as: ++captures) */ + duk_uint32_t captures; /* highest capture number emitted so far (used as: ++captures) */ duk_uint32_t highest_backref; duk_uint32_t recursion_depth; duk_uint32_t recursion_limit; - duk_uint32_t nranges; /* internal temporary value, used for char classes */ + duk_uint32_t nranges; /* internal temporary value, used for char classes */ }; /* @@ -78,7 +78,7 @@ DUK_INTERNAL_DECL void duk_regexp_compile(duk_hthread *thr); DUK_INTERNAL_DECL void duk_regexp_create_instance(duk_hthread *thr); DUK_INTERNAL_DECL void duk_regexp_match(duk_hthread *thr); -DUK_INTERNAL_DECL void duk_regexp_match_force_global(duk_hthread *thr); /* hacky helper for String.prototype.split() */ +DUK_INTERNAL_DECL void duk_regexp_match_force_global(duk_hthread *thr); /* hacky helper for String.prototype.split() */ #endif -#endif /* DUK_REGEXP_H_INCLUDED */ +#endif /* DUK_REGEXP_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_regexp_compiler.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_regexp_compiler.c
Changed
@@ -28,8 +28,7 @@ #define DUK__RE_INITIAL_BUFSIZE 64 -#define DUK__RE_BUFLEN(re_ctx) \ - DUK_BW_GET_SIZE(re_ctx->thr, &re_ctx->bw) +#define DUK__RE_BUFLEN(re_ctx) DUK_BW_GET_SIZE(re_ctx->thr, &re_ctx->bw) /* * Disjunction struct: result of parsing a disjunction @@ -119,7 +118,7 @@ (void) duk__append_7bit(re_ctx, reop); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__append_i32(duk_re_compiler_ctx *re_ctx, duk_int32_t x) { duk__append_u32(re_ctx, duk__encode_i32(x)); } @@ -133,7 +132,10 @@ } } -DUK_LOCAL void duk__insert_slice(duk_re_compiler_ctx *re_ctx, duk_uint32_t offset, duk_uint32_t data_offset, duk_uint32_t data_length) { +DUK_LOCAL void duk__insert_slice(duk_re_compiler_ctx *re_ctx, + duk_uint32_t offset, + duk_uint32_t data_offset, + duk_uint32_t data_length) { DUK_BW_INSERT_ENSURE_SLICE(re_ctx->thr, &re_ctx->bw, offset, data_offset, data_length); } @@ -196,7 +198,7 @@ skip--; } } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* Closed form solution, this produces fastest code. * See re_neg_jump_offset (closed1). */ @@ -217,7 +219,7 @@ skip -= 7; } } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ return duk__insert_i32(re_ctx, offset, skip); } @@ -350,10 +352,10 @@ } } } - DUK_ASSERT(blk == end_blk + 1); /* Reached end block which is continuous. */ + DUK_ASSERT(blk == end_blk + 1); /* Reached end block which is continuous. */ return end; } -#else /* DUK_USE_REGEXP_CANON_BITMAP */ +#else /* DUK_USE_REGEXP_CANON_BITMAP */ DUK_LOCAL duk_codepoint_t duk__re_canon_next_discontinuity(duk_codepoint_t start, duk_codepoint_t end) { DUK_ASSERT(start >= 0); DUK_ASSERT(end >= 0); @@ -364,7 +366,7 @@ } return start; } -#endif /* DUK_USE_REGEXP_CANON_BITMAP */ +#endif /* DUK_USE_REGEXP_CANON_BITMAP */ DUK_LOCAL void duk__regexp_generate_ranges(void *userdata, duk_codepoint_t r1, duk_codepoint_t r2, duk_bool_t direct) { duk_re_compiler_ctx *re_ctx = (duk_re_compiler_ctx *) userdata; @@ -375,9 +377,12 @@ duk_codepoint_t r_disc; DUK_DD(DUK_DDPRINT("duk__regexp_generate_ranges(): re_ctx=%p, range=%ld,%ld direct=%ld", - (void *) re_ctx, (long) r1, (long) r2, (long) direct)); + (void *) re_ctx, + (long) r1, + (long) r2, + (long) direct)); - DUK_ASSERT(r2 >= r1); /* SyntaxError for out of order range. */ + DUK_ASSERT(r2 >= r1); /* SyntaxError for out of order range. */ if (direct || (re_ctx->re_flags & DUK_RE_FLAG_IGNORE_CASE) == 0) { DUK_DD(DUK_DDPRINT("direct or not case sensitive, emit range: %ld,%ld", (long) r1, (long) r2)); @@ -399,7 +404,7 @@ DUK_ASSERT(r_disc >= i); DUK_ASSERT(r_disc <= r2); - r_end += r_disc - i; /* May be zero. */ + r_end += r_disc - i; /* May be zero. */ t = duk_unicode_re_canonicalize_char(re_ctx->thr, r_disc); if (t == r_end + 1) { /* Not actually a discontinuity, continue range @@ -411,11 +416,11 @@ r_start = t; r_end = t; } - i = r_disc + 1; /* Guarantees progress. */ + i = r_disc + 1; /* Guarantees progress. */ } duk__regexp_emit_range(re_ctx, r_start, r_end); -#if 0 /* Exhaustive search, very slow. */ +#if 0 /* Exhaustive search, very slow. */ r_start = duk_unicode_re_canonicalize_char(re_ctx->thr, r1); r_end = r_start; for (i = r1 + 1; i <= r2; i++) { @@ -488,18 +493,17 @@ * as complex though. */ -DUK_LOCAL const duk_uint16_t * const duk__re_range_lookup13 = { - duk_unicode_re_ranges_digit, - duk_unicode_re_ranges_white, - duk_unicode_re_ranges_wordchar -}; -DUK_LOCAL const duk_uint8_t duk__re_range_lookup23 = { - sizeof(duk_unicode_re_ranges_digit) / (2 * sizeof(duk_uint16_t)), - sizeof(duk_unicode_re_ranges_white) / (2 * sizeof(duk_uint16_t)), - sizeof(duk_unicode_re_ranges_wordchar) / (2 * sizeof(duk_uint16_t)) -}; - -DUK_LOCAL void duk__append_range_atom_matcher(duk_re_compiler_ctx *re_ctx, duk_small_uint_t re_op, const duk_uint16_t *ranges, duk_small_uint_t count) { +DUK_LOCAL const duk_uint16_t * const duk__re_range_lookup13 = { duk_unicode_re_ranges_digit, + duk_unicode_re_ranges_white, + duk_unicode_re_ranges_wordchar }; +DUK_LOCAL const duk_uint8_t duk__re_range_lookup23 = { sizeof(duk_unicode_re_ranges_digit) / (2 * sizeof(duk_uint16_t)), + sizeof(duk_unicode_re_ranges_white) / (2 * sizeof(duk_uint16_t)), + sizeof(duk_unicode_re_ranges_wordchar) / (2 * sizeof(duk_uint16_t)) }; + +DUK_LOCAL void duk__append_range_atom_matcher(duk_re_compiler_ctx *re_ctx, + duk_small_uint_t re_op, + const duk_uint16_t *ranges, + duk_small_uint_t count) { #if 0 DUK_ASSERT(re_op <= 0x7fUL); DUK_ASSERT(count <= 0x7fUL); @@ -511,13 +515,13 @@ } DUK_LOCAL void duk__parse_disjunction(duk_re_compiler_ctx *re_ctx, duk_bool_t expect_eof, duk__re_disjunction_info *out_atom_info) { - duk_int32_t atom_start_offset = -1; /* negative -> no atom matched on previous round */ - duk_int32_t atom_char_length = 0; /* negative -> complex atom */ - duk_uint32_t atom_start_captures = re_ctx->captures; /* value of re_ctx->captures at start of atom */ + duk_int32_t atom_start_offset = -1; /* negative -> no atom matched on previous round */ + duk_int32_t atom_char_length = 0; /* negative -> complex atom */ + duk_uint32_t atom_start_captures = re_ctx->captures; /* value of re_ctx->captures at start of atom */ duk_int32_t unpatched_disjunction_split = -1; duk_int32_t unpatched_disjunction_jump = -1; duk_uint32_t entry_offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); - duk_int32_t res_charlen = 0; /* -1 if disjunction is complex, char length if simple */ + duk_int32_t res_charlen = 0; /* -1 if disjunction is complex, char length if simple */ duk__re_disjunction_info tmp_disj; DUK_ASSERT(out_atom_info != NULL); @@ -540,19 +544,19 @@ * new_atom_char_length etc are for the atom parsed on this round; * they're written to atom_char_length etc at the end of the round. */ - duk_int32_t new_atom_char_length; /* char length of the atom parsed in this loop */ - duk_int32_t new_atom_start_offset; /* bytecode start offset of the atom parsed in this loop - * (allows quantifiers to copy the atom bytecode) - */ - duk_uint32_t new_atom_start_captures; /* re_ctx->captures at the start of the atom parsed in this loop */ + duk_int32_t new_atom_char_length; /* char length of the atom parsed in this loop */ + duk_int32_t new_atom_start_offset; /* bytecode start offset of the atom parsed in this loop + * (allows quantifiers to copy the atom bytecode) + */ + duk_uint32_t new_atom_start_captures; /* re_ctx->captures at the start of the atom parsed in this loop */ duk_lexer_parse_re_token(&re_ctx->lex, &re_ctx->curr_token); - DUK_DD(DUK_DDPRINT("re token: %ld (num=%ld, char=%c)", - (long) re_ctx->curr_token.t, - (long) re_ctx->curr_token.num, - (re_ctx->curr_token.num >= 0x20 && re_ctx->curr_token.num <= 0x7e) ? - (int) re_ctx->curr_token.num : (int) '?')); + DUK_DD(DUK_DDPRINT( + "re token: %ld (num=%ld, char=%c)", + (long) re_ctx->curr_token.t, + (long) re_ctx->curr_token.num, + (re_ctx->curr_token.num >= 0x20 && re_ctx->curr_token.num <= 0x7e) ? (int) re_ctx->curr_token.num : (int) '?')); /* set by atom case clauses */ new_atom_start_offset = -1; @@ -573,9 +577,7 @@ DUK_ASSERT(unpatched_disjunction_split >= 0); offset = (duk_uint32_t) unpatched_disjunction_jump; - offset += duk__insert_jump_offset(re_ctx, - offset, - (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); + offset += duk__insert_jump_offset(re_ctx, offset, (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); /* offset is now target of the pending split (right after jump) */ duk__insert_jump_offset(re_ctx, (duk_uint32_t) unpatched_disjunction_split, @@ -583,10 +585,8 @@ } /* add a new pending split to the beginning of the entire disjunction */ - (void) duk__insert_u32(re_ctx, - entry_offset, - DUK_REOP_SPLIT1); /* prefer direct execution */ - unpatched_disjunction_split = (duk_int32_t) (entry_offset + 1); /* +1 for opcode */ + (void) duk__insert_u32(re_ctx, entry_offset, DUK_REOP_SPLIT1); /* prefer direct execution */ + unpatched_disjunction_split = (duk_int32_t) (entry_offset + 1); /* +1 for opcode */ /* add a new pending match jump for latest finished alternative */ duk__append_reop(re_ctx, DUK_REOP_JUMP); @@ -634,7 +634,7 @@ } } - duk__append_reop(re_ctx, DUK_REOP_MATCH); /* complete 'sub atom' */ + duk__append_reop(re_ctx, DUK_REOP_MATCH); /* complete 'sub atom' */ atom_code_length = (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (duk_size_t) atom_start_offset); offset = (duk_uint32_t) atom_start_offset; @@ -650,7 +650,7 @@ offset += duk__insert_u32(re_ctx, offset, qmax); offset += duk__insert_jump_offset(re_ctx, offset, atom_code_length); } - DUK_UNREF(offset); /* silence scan-build warning */ + DUK_UNREF(offset); /* silence scan-build warning */ } else { /* * Complex atom @@ -668,8 +668,8 @@ duk_uint32_t tmp_qmin, tmp_qmax; /* pre-check how many atom copies we're willing to make (atom_copies not needed below) */ - atom_copies = (re_ctx->curr_token.qmax == DUK_RE_QUANTIFIER_INFINITE) ? - re_ctx->curr_token.qmin : re_ctx->curr_token.qmax; + atom_copies = (re_ctx->curr_token.qmax == DUK_RE_QUANTIFIER_INFINITE) ? re_ctx->curr_token.qmin : + re_ctx->curr_token.qmax; if (atom_copies > DUK_RE_MAX_ATOM_COPIES) { DUK_ERROR_RANGE(re_ctx->thr, DUK_STR_QUANTIFIER_TOO_MANY_COPIES); DUK_WO_NORETURN(return;); @@ -680,15 +680,19 @@ if (atom_start_captures != re_ctx->captures) { DUK_ASSERT(atom_start_captures < re_ctx->captures); DUK_DDD(DUK_DDDPRINT("must wipe atom_start_captures,re_ctx->captures: %ld,%ld", - (long) atom_start_captures, (long) re_ctx->captures)); + (long) atom_start_captures, + (long) re_ctx->captures)); /* insert (DUK_REOP_WIPERANGE, start, count) in reverse order so the order ends up right */ - duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, (re_ctx->captures - atom_start_captures) * 2U); + duk__insert_u32(re_ctx, + (duk_uint32_t) atom_start_offset, + (re_ctx->captures - atom_start_captures) * 2U); duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, (atom_start_captures + 1) * 2); duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, DUK_REOP_WIPERANGE); } else { - DUK_DDD(DUK_DDDPRINT("no need to wipe captures: atom_start_captures == re_ctx->captures == %ld", - (long) atom_start_captures)); + DUK_DDD( + DUK_DDDPRINT("no need to wipe captures: atom_start_captures == re_ctx->captures == %ld", + (long) atom_start_captures)); } atom_code_length = (duk_int32_t) DUK__RE_BUFLEN(re_ctx) - atom_start_offset; @@ -697,7 +701,9 @@ tmp_qmin = re_ctx->curr_token.qmin; tmp_qmax = re_ctx->curr_token.qmax; while (tmp_qmin > 0) { - duk__append_slice(re_ctx, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__append_slice(re_ctx, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); tmp_qmin--; if (tmp_qmax != DUK_RE_QUANTIFIER_INFINITE) { tmp_qmax--; @@ -715,14 +721,16 @@ */ duk__append_reop(re_ctx, DUK_REOP_JUMP); duk__append_jump_offset(re_ctx, atom_code_length); - duk__append_slice(re_ctx, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__append_slice(re_ctx, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); } if (re_ctx->curr_token.greedy) { - duk__append_reop(re_ctx, DUK_REOP_SPLIT2); /* prefer jump */ + duk__append_reop(re_ctx, DUK_REOP_SPLIT2); /* prefer jump */ } else { - duk__append_reop(re_ctx, DUK_REOP_SPLIT1); /* prefer direct */ + duk__append_reop(re_ctx, DUK_REOP_SPLIT1); /* prefer direct */ } - duk__append_jump_offset(re_ctx, -atom_code_length - 1); /* -1 for opcode */ + duk__append_jump_offset(re_ctx, -atom_code_length - 1); /* -1 for opcode */ } else { /* * The remaining matches are emitted as sequence of SPLITs and atom @@ -742,14 +750,17 @@ */ duk_uint32_t offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); while (tmp_qmax > 0) { - duk__insert_slice(re_ctx, offset, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__insert_slice(re_ctx, + offset, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); if (re_ctx->curr_token.greedy) { - duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT1); /* prefer direct */ + duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT1); /* prefer direct */ } else { - duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT2); /* prefer jump */ + duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT2); /* prefer jump */ } duk__insert_jump_offset(re_ctx, - offset + 1, /* +1 for opcode */ + offset + 1, /* +1 for opcode */ (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (offset + 1))); tmp_qmax--; } @@ -782,8 +793,8 @@ case DUK_RETOK_ASSERT_START_POS_LOOKAHEAD: case DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD: { duk_uint32_t offset; - duk_uint32_t opcode = (re_ctx->curr_token.t == DUK_RETOK_ASSERT_START_POS_LOOKAHEAD) ? - DUK_REOP_LOOKPOS : DUK_REOP_LOOKNEG; + duk_uint32_t opcode = + (re_ctx->curr_token.t == DUK_RETOK_ASSERT_START_POS_LOOKAHEAD) ? DUK_REOP_LOOKPOS : DUK_REOP_LOOKNEG; offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); duk__parse_disjunction(re_ctx, 0, &tmp_disj); @@ -791,7 +802,7 @@ (void) duk__insert_u32(re_ctx, offset, opcode); (void) duk__insert_jump_offset(re_ctx, - offset + 1, /* +1 for opcode */ + offset + 1, /* +1 for opcode */ (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (offset + 1))); /* 'taint' result as complex -- this is conservative, @@ -852,7 +863,7 @@ DUK_ASSERT(DUK_RETOK_ATOM_WHITE == DUK_RETOK_ATOM_DIGIT + 2); DUK_ASSERT(DUK_RETOK_ATOM_WORD_CHAR == DUK_RETOK_ATOM_DIGIT + 4); idx = (duk_small_uint_t) ((re_ctx->curr_token.t - DUK_RETOK_ATOM_DIGIT) >> 1U); - DUK_ASSERT(idx <= 2U); /* Assume continuous token numbers; also checks negative underflow. */ + DUK_ASSERT(idx <= 2U); /* Assume continuous token numbers; also checks negative underflow. */ duk__append_range_atom_matcher(re_ctx, re_op, duk__re_range_lookup1idx, duk__re_range_lookup2idx); break; @@ -862,7 +873,7 @@ if (backref > re_ctx->highest_backref) { re_ctx->highest_backref = backref; } - new_atom_char_length = -1; /* mark as complex */ + new_atom_char_length = -1; /* mark as complex */ new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); duk__append_reop(re_ctx, DUK_REOP_BACKREFERENCE); duk__append_u32(re_ctx, backref); @@ -871,12 +882,14 @@ case DUK_RETOK_ATOM_START_CAPTURE_GROUP: { duk_uint32_t cap; - new_atom_char_length = -1; /* mark as complex (capture handling) */ + new_atom_char_length = -1; /* mark as complex (capture handling) */ new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); cap = ++re_ctx->captures; duk__append_reop(re_ctx, DUK_REOP_SAVE); duk__append_u32(re_ctx, cap * 2); - duk__parse_disjunction(re_ctx, 0, &tmp_disj); /* retval (sub-atom char length) unused, tainted as complex above */ + duk__parse_disjunction(re_ctx, + 0, + &tmp_disj); /* retval (sub-atom char length) unused, tainted as complex above */ duk__append_reop(re_ctx, DUK_REOP_SAVE); duk__append_u32(re_ctx, cap * 2 + 1); break; @@ -921,12 +934,12 @@ new_atom_char_length = 1; new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); duk__append_reop(re_ctx, - (re_ctx->curr_token.t == DUK_RETOK_ATOM_START_CHARCLASS) ? - DUK_REOP_RANGES : DUK_REOP_INVRANGES); - offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); /* patch in range count later */ + (re_ctx->curr_token.t == DUK_RETOK_ATOM_START_CHARCLASS) ? DUK_REOP_RANGES : + DUK_REOP_INVRANGES); + offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); /* patch in range count later */ /* parse ranges until character class ends */ - re_ctx->nranges = 0; /* note: ctx-wide temporary */ + re_ctx->nranges = 0; /* note: ctx-wide temporary */ duk_lexer_parse_re_ranges(&re_ctx->lex, duk__regexp_generate_ranges, (void *) re_ctx); /* insert range count */ @@ -969,7 +982,7 @@ atom_start_captures = new_atom_start_captures; } - done: +done: /* finish up pending jump and split for last alternative */ if (unpatched_disjunction_jump >= 0) { @@ -977,9 +990,7 @@ DUK_ASSERT(unpatched_disjunction_split >= 0); offset = (duk_uint32_t) unpatched_disjunction_jump; - offset += duk__insert_jump_offset(re_ctx, - offset, - (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); + offset += duk__insert_jump_offset(re_ctx, offset, (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); /* offset is now target of the pending split (right after jump) */ duk__insert_jump_offset(re_ctx, (duk_uint32_t) unpatched_disjunction_split, @@ -990,8 +1001,7 @@ out_atom_info->end_captures = re_ctx->captures; #endif out_atom_info->charlen = res_charlen; - DUK_DDD(DUK_DDDPRINT("parse disjunction finished: charlen=%ld", - (long) out_atom_info->charlen)); + DUK_DDD(DUK_DDDPRINT("parse disjunction finished: charlen=%ld", (long) out_atom_info->charlen)); re_ctx->recursion_depth--; } @@ -1042,7 +1052,7 @@ return flags; - flags_error: +flags_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_REGEXP_FLAGS); DUK_WO_NORETURN(return 0U;); } @@ -1108,7 +1118,7 @@ } DUK_BW_SETPTR_AND_COMPACT(thr, bw, q); - (void) duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ /* ... escaped_source */ } @@ -1162,7 +1172,7 @@ /* ... pattern flags escaped_source buffer */ duk_memzero(&re_ctx, sizeof(re_ctx)); - DUK_LEXER_INITCTX(&re_ctx.lex); /* duplicate zeroing, expect for (possible) NULL inits */ + DUK_LEXER_INITCTX(&re_ctx.lex); /* duplicate zeroing, expect for (possible) NULL inits */ re_ctx.thr = thr; re_ctx.lex.thr = thr; re_ctx.lex.input = DUK_HSTRING_GET_DATA(h_pattern); @@ -1174,13 +1184,14 @@ DUK_BW_INIT_PUSHBUF(thr, &re_ctx.bw, DUK__RE_INITIAL_BUFSIZE); DUK_DD(DUK_DDPRINT("regexp compiler ctx initialized, flags=0x%08lx, recursion_limit=%ld", - (unsigned long) re_ctx.re_flags, (long) re_ctx.recursion_limit)); + (unsigned long) re_ctx.re_flags, + (long) re_ctx.recursion_limit)); /* * Init lexer */ - lex_point.offset = 0; /* expensive init, just want to fill window */ + lex_point.offset = 0; /* expensive init, just want to fill window */ lex_point.line = 1; DUK_LEXER_SETPOINT(&re_ctx.lex, &lex_point); @@ -1222,7 +1233,7 @@ /* ... pattern flags escaped_source buffer */ DUK_BW_COMPACT(thr, &re_ctx.bw); - (void) duk_buffer_to_string(thr, -1); /* Safe because flags is at most 7 bit. */ + (void) duk_buffer_to_string(thr, -1); /* Safe because flags is at most 7 bit. */ /* ... pattern flags escaped_source bytecode */ @@ -1230,11 +1241,12 @@ * Finalize stack */ - duk_remove(thr, -4); /* -> ... flags escaped_source bytecode */ - duk_remove(thr, -3); /* -> ... escaped_source bytecode */ + duk_remove(thr, -4); /* -> ... flags escaped_source bytecode */ + duk_remove(thr, -3); /* -> ... escaped_source bytecode */ DUK_DD(DUK_DDPRINT("regexp compilation successful, bytecode: %!T, escaped source: %!T", - (duk_tval *) duk_get_tval(thr, -1), (duk_tval *) duk_get_tval(thr, -2))); + (duk_tval *) duk_get_tval(thr, -1), + (duk_tval *) duk_get_tval(thr, -2))); } /* @@ -1280,8 +1292,8 @@ /* ... regexp_object */ } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ /* regexp support disabled */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_regexp_executor.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_regexp_executor.c
Changed
@@ -41,7 +41,11 @@ } } -DUK_LOCAL const duk_uint8_t *duk__utf8_backtrack(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_uint_fast32_t count) { +DUK_LOCAL const duk_uint8_t *duk__utf8_backtrack(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_uint_fast32_t count) { const duk_uint8_t *p; /* Note: allow backtracking from p == ptr_end */ @@ -66,12 +70,16 @@ *ptr = p; return p; - fail: +fail: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return NULL;); } -DUK_LOCAL const duk_uint8_t *duk__utf8_advance(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_uint_fast32_t count) { +DUK_LOCAL const duk_uint8_t *duk__utf8_advance(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_uint_fast32_t count) { const duk_uint8_t *p; p = *ptr; @@ -97,7 +105,7 @@ *ptr = p; return p; - fail: +fail: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return NULL;); } @@ -201,7 +209,7 @@ c1 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); DUK_ASSERT(!(re_ctx->re_flags & DUK_RE_FLAG_IGNORE_CASE) || - c1 == duk_unicode_re_canonicalize_char(re_ctx->thr, c1)); /* canonicalized by compiler */ + c1 == duk_unicode_re_canonicalize_char(re_ctx->thr, c1)); /* canonicalized by compiler */ c2 = duk__inp_get_cp(re_ctx, &sp); /* No need to check for c2 < 0 (end of input): because c1 >= 0, it * will fail the match below automatically and cause goto fail. @@ -247,7 +255,10 @@ r1 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); r2 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("matching ranges/invranges, n=%ld, r1=%ld, r2=%ld, c=%ld", - (long) n, (long) r1, (long) r2, (long) c)); + (long) n, + (long) r1, + (long) r2, + (long) c)); if (c >= r1 && c <= r2) { /* Note: don't bail out early, we must read all the ranges from * bytecode. Another option is to skip them efficiently after @@ -316,16 +327,16 @@ duk_small_int_t w1, w2; if (sp <= re_ctx->input) { - w1 = 0; /* not a wordchar */ + w1 = 0; /* not a wordchar */ } else { duk_codepoint_t c; c = duk__inp_get_prev_cp(re_ctx, sp); w1 = duk_unicode_re_is_wordchar(c); } if (sp >= re_ctx->input_end) { - w2 = 0; /* not a wordchar */ + w2 = 0; /* not a wordchar */ } else { - const duk_uint8_t *tmp_sp = sp; /* dummy so sp won't get updated */ + const duk_uint8_t *tmp_sp = sp; /* dummy so sp won't get updated */ duk_codepoint_t c; c = duk__inp_get_cp(re_ctx, &tmp_sp); w2 = duk_unicode_re_is_wordchar(c); @@ -386,7 +397,9 @@ qmax = duk__bc_get_u32(re_ctx, &pc); skip = duk__bc_get_i32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("minimal quantifier, qmin=%lu, qmax=%lu, skip=%ld", - (unsigned long) qmin, (unsigned long) qmax, (long) skip)); + (unsigned long) qmin, + (unsigned long) qmax, + (long) skip)); q = 0; while (q <= qmax) { @@ -416,7 +429,10 @@ atomlen = duk__bc_get_u32(re_ctx, &pc); skip = duk__bc_get_i32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("greedy quantifier, qmin=%lu, qmax=%lu, atomlen=%lu, skip=%ld", - (unsigned long) qmin, (unsigned long) qmax, (unsigned long) atomlen, (long) skip)); + (unsigned long) qmin, + (unsigned long) qmax, + (unsigned long) atomlen, + (long) skip)); q = 0; while (q < qmax) { @@ -442,8 +458,7 @@ * do not allow captures in their atom now, so this is not an issue. */ - DUK_DDD(DUK_DDDPRINT("greedy quantifier, backtrack %ld characters (atomlen)", - (long) atomlen)); + DUK_DDD(DUK_DDDPRINT("greedy quantifier, backtrack %ld characters (atomlen)", (long) atomlen)); sp = duk__inp_backtrack(re_ctx, &sp, (duk_uint_fast32_t) atomlen); q--; } @@ -489,20 +504,23 @@ idx_start = duk__bc_get_u32(re_ctx, &pc); idx_count = duk__bc_get_u32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("wipe saved range: start=%ld, count=%ld -> %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) idx_count, - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) idx_count, + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); if (idx_start + idx_count > re_ctx->nsaved || idx_count == 0) { /* idx is unsigned, < 0 check is not necessary */ DUK_D(DUK_DPRINT("internal error, regexp wipe indices insane: idx_start=%ld, idx_count=%ld", - (long) idx_start, (long) idx_count)); + (long) idx_start, + (long) idx_count)); goto internal_error; } DUK_ASSERT(idx_count > 0); duk_require_stack(re_ctx->thr, 1); - range_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, - sizeof(duk_uint8_t *) * idx_count); + range_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, sizeof(duk_uint8_t *) * idx_count); DUK_ASSERT(range_save != NULL); duk_memcpy(range_save, re_ctx->saved + idx_start, sizeof(duk_uint8_t *) * idx_count); #if defined(DUK_USE_EXPLICIT_NULL_INIT) @@ -518,8 +536,10 @@ if (sub_sp) { /* match: keep wiped/resaved values */ DUK_DDD(DUK_DDDPRINT("match: keep wiped/resaved values %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); duk_pop_unsafe(re_ctx->thr); sp = sub_sp; goto match; @@ -527,8 +547,10 @@ /* fail: restore saves */ DUK_DDD(DUK_DDDPRINT("fail: restore wiped/resaved values %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); duk_memcpy((void *) (re_ctx->saved + idx_start), (const void *) range_save, sizeof(duk_uint8_t *) * idx_count); @@ -558,8 +580,8 @@ DUK_ASSERT(re_ctx->nsaved > 0); duk_require_stack(re_ctx->thr, 1); - full_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, - sizeof(duk_uint8_t *) * re_ctx->nsaved); + full_save = + (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, sizeof(duk_uint8_t *) * re_ctx->nsaved); DUK_ASSERT(full_save != NULL); duk_memcpy(full_save, re_ctx->saved, sizeof(duk_uint8_t *) * re_ctx->nsaved); @@ -584,11 +606,9 @@ /* fall through */ - lookahead_fail: + lookahead_fail: /* fail: restore saves */ - duk_memcpy((void *) re_ctx->saved, - (const void *) full_save, - sizeof(duk_uint8_t *) * re_ctx->nsaved); + duk_memcpy((void *) re_ctx->saved, (const void *) full_save, sizeof(duk_uint8_t *) * re_ctx->nsaved); duk_pop_unsafe(re_ctx->thr); goto fail; } @@ -611,22 +631,23 @@ const duk_uint8_t *p; idx = duk__bc_get_u32(re_ctx, &pc); - idx = idx << 1; /* backref n -> saved indices n*2, n*2+1 */ + idx = idx << 1; /* backref n -> saved indices n*2, n*2+1 */ if (idx < 2 || idx + 1 >= re_ctx->nsaved) { /* regexp compiler should catch these */ DUK_D(DUK_DPRINT("internal error, backreference index insane")); goto internal_error; } - if (!re_ctx->savedidx || !re_ctx->savedidx+1) { + if (!re_ctx->savedidx || !re_ctx->savedidx + 1) { /* capture is 'undefined', always matches! */ DUK_DDD(DUK_DDDPRINT("backreference: saved%ld,%ld not complete, always match", - (long) idx, (long) (idx + 1))); + (long) idx, + (long) (idx + 1))); break; } DUK_DDD(DUK_DDDPRINT("backreference: match saved%ld,%ld", (long) idx, (long) (idx + 1))); p = re_ctx->savedidx; - while (p < re_ctx->savedidx+1) { + while (p < re_ctx->savedidx + 1) { duk_codepoint_t c1, c2; /* Note: not necessary to check p against re_ctx->input_end: @@ -658,15 +679,15 @@ } } - match: +match: re_ctx->recursion_depth--; return sp; - fail: +fail: re_ctx->recursion_depth--; return NULL; - internal_error: +internal_error: DUK_ERROR_INTERNAL(re_ctx->thr); DUK_WO_NORETURN(return NULL;); } @@ -718,8 +739,9 @@ h_input = duk_to_hstring(thr, -1); DUK_ASSERT(h_input != NULL); - duk_xget_owndataprop_stridx_short(thr, -2, DUK_STRIDX_INT_BYTECODE); /* ... re_obj input -> ... re_obj input bc */ - h_bytecode = duk_require_hstring(thr, -1); /* no regexp instance should exist without a non-configurable bytecode property */ + duk_xget_owndataprop_stridx_short(thr, -2, DUK_STRIDX_INT_BYTECODE); /* ... re_obj input -> ... re_obj input bc */ + h_bytecode = + duk_require_hstring(thr, -1); /* no regexp instance should exist without a non-configurable bytecode property */ DUK_ASSERT(h_bytecode != NULL); /* @@ -751,13 +773,13 @@ re_ctx.nsaved = duk__bc_get_u32(&re_ctx, &pc); re_ctx.bytecode = pc; - DUK_ASSERT(DUK_RE_FLAG_GLOBAL < 0x10000UL); /* must fit into duk_small_int_t */ + DUK_ASSERT(DUK_RE_FLAG_GLOBAL < 0x10000UL); /* must fit into duk_small_int_t */ global = (duk_small_int_t) (force_global | (duk_small_int_t) (re_ctx.re_flags & DUK_RE_FLAG_GLOBAL)); DUK_ASSERT(re_ctx.nsaved >= 2); DUK_ASSERT((re_ctx.nsaved % 2) == 0); - p_buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, sizeof(duk_uint8_t *) * re_ctx.nsaved); /* rely on zeroing */ + p_buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, sizeof(duk_uint8_t *) * re_ctx.nsaved); /* rely on zeroing */ DUK_UNREF(p_buf); re_ctx.saved = (const duk_uint8_t **) duk_get_buffer(thr, -1, NULL); DUK_ASSERT(re_ctx.saved != NULL); @@ -775,7 +797,9 @@ #endif DUK_DDD(DUK_DDDPRINT("regexp ctx initialized, flags=0x%08lx, nsaved=%ld, recursion_limit=%ld, steps_limit=%ld", - (unsigned long) re_ctx.re_flags, (long) re_ctx.nsaved, (long) re_ctx.recursion_limit, + (unsigned long) re_ctx.re_flags, + (long) re_ctx.nsaved, + (long) re_ctx.recursion_limit, (long) re_ctx.steps_limit)); /* @@ -797,15 +821,15 @@ /* ... re_obj input bc saved_buf */ - duk_get_prop_stridx_short(thr, -4, DUK_STRIDX_LAST_INDEX); /* -> ... re_obj input bc saved_buf lastIndex */ - (void) duk_to_int(thr, -1); /* ToInteger(lastIndex) */ - d = duk_get_number(thr, -1); /* integer, but may be +/- Infinite, +/- zero (not NaN, though) */ + duk_get_prop_stridx_short(thr, -4, DUK_STRIDX_LAST_INDEX); /* -> ... re_obj input bc saved_buf lastIndex */ + (void) duk_to_int(thr, -1); /* ToInteger(lastIndex) */ + d = duk_get_number(thr, -1); /* integer, but may be +/- Infinite, +/- zero (not NaN, though) */ duk_pop_nodecref_unsafe(thr); if (global) { if (d < 0.0 || d > (double) DUK_HSTRING_GET_CHARLEN(h_input)) { /* match fail */ - char_offset = 0; /* not really necessary */ + char_offset = 0; /* not really necessary */ DUK_ASSERT(match == 0); goto match_over; } @@ -841,8 +865,10 @@ DUK_ASSERT(re_ctx.recursion_depth == 0); DUK_DDD(DUK_DDDPRINT("attempt match at char offset %ld; %p %p,%p", - (long) char_offset, (const void *) sp, - (const void *) re_ctx.input, (const void *) re_ctx.input_end)); + (long) char_offset, + (const void *) sp, + (const void *) re_ctx.input, + (const void *) re_ctx.input_end)); /* * Note: @@ -889,7 +915,7 @@ (void) duk__utf8_advance(thr, &sp, re_ctx.input, re_ctx.input_end, (duk_uint_fast32_t) 1); } - match_over: +match_over: /* * Matching complete, create result array or return a 'null'. Update lastIndex @@ -915,8 +941,8 @@ DUK_DDD(DUK_DDDPRINT("regexp matches at char_offset %ld", (long) char_offset)); - DUK_ASSERT(re_ctx.nsaved >= 2); /* must have start and end */ - DUK_ASSERT((re_ctx.nsaved % 2) == 0); /* and even number */ + DUK_ASSERT(re_ctx.nsaved >= 2); /* must have start and end */ + DUK_ASSERT((re_ctx.nsaved % 2) == 0); /* and even number */ /* XXX: Array size is known before and (2 * re_ctx.nsaved) but not taken * advantage of now. The array is not compacted either, as regexp match @@ -957,7 +983,7 @@ * will be zero). Also assumes clen reflects the * correct char length. */ - char_end_offset = char_offset + (duk_uint32_t) duk_get_length(thr, -1); /* add charlen */ + char_end_offset = char_offset + (duk_uint32_t) duk_get_length(thr, -1); /* add charlen */ } } else { duk_push_undefined(thr); @@ -1022,8 +1048,8 @@ duk__regexp_match_helper(thr, 1 /*force_global*/); } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ /* regexp support disabled */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_replacements.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_replacements.h
Changed
@@ -8,7 +8,7 @@ #if defined(DUK_USE_COMPUTED_NAN) DUK_INTERNAL_DECL double duk_computed_nan; #endif -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ #if defined(DUK_USE_REPL_FPCLASSIFY) DUK_INTERNAL_DECL int duk_repl_fpclassify(double x); @@ -26,4 +26,4 @@ DUK_INTERNAL_DECL int duk_repl_isinf(double x); #endif -#endif /* DUK_REPLACEMENTS_H_INCLUDED */ +#endif /* DUK_REPLACEMENTS_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_selftest.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_selftest.c
Changed
@@ -17,18 +17,21 @@ } duk__test_double_union; /* Self test failed. Expects a local variable 'error_count' to exist. */ -#define DUK__FAILED(msg) do { \ +#define DUK__FAILED(msg) \ + do { \ DUK_D(DUK_DPRINT("self test failed: " #msg " at " DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO))); \ error_count++; \ } while (0) -#define DUK__DBLUNION_CMP_TRUE(a,b) do { \ +#define DUK__DBLUNION_CMP_TRUE(a, b) \ + do { \ if (duk_memcmp((const void *) (a), (const void *) (b), sizeof(duk__test_double_union)) != 0) { \ DUK__FAILED("double union compares false (expected true)"); \ } \ } while (0) -#define DUK__DBLUNION_CMP_FALSE(a,b) do { \ +#define DUK__DBLUNION_CMP_FALSE(a, b) \ + do { \ if (duk_memcmp((const void *) (a), (const void *) (b), sizeof(duk__test_double_union)) == 0) { \ DUK__FAILED("double union compares true (expected false)"); \ } \ @@ -40,43 +43,72 @@ } duk__test_u32_union; #if defined(DUK_USE_INTEGER_LE) -#define DUK__U32_INIT(u, a, b, c, d) do { \ - (u)->x0 = (d); (u)->x1 = (c); (u)->x2 = (b); (u)->x3 = (a); \ +#define DUK__U32_INIT(u, a, b, c, d) \ + do { \ + (u)->x0 = (d); \ + (u)->x1 = (c); \ + (u)->x2 = (b); \ + (u)->x3 = (a); \ } while (0) #elif defined(DUK_USE_INTEGER_ME) #error integer mixed endian not supported now #elif defined(DUK_USE_INTEGER_BE) -#define DUK__U32_INIT(u, a, b, c, d) do { \ - (u)->x0 = (a); (u)->x1 = (b); (u)->x2 = (c); (u)->x3 = (d); \ +#define DUK__U32_INIT(u, a, b, c, d) \ + do { \ + (u)->x0 = (a); \ + (u)->x1 = (b); \ + (u)->x2 = (c); \ + (u)->x3 = (d); \ } while (0) #else #error unknown integer endianness #endif #if defined(DUK_USE_DOUBLE_LE) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (h); (u)->x1 = (g); (u)->x2 = (f); (u)->x3 = (e); \ - (u)->x4 = (d); (u)->x5 = (c); (u)->x6 = (b); (u)->x7 = (a); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (h); \ + (u)->x1 = (g); \ + (u)->x2 = (f); \ + (u)->x3 = (e); \ + (u)->x4 = (d); \ + (u)->x5 = (c); \ + (u)->x6 = (b); \ + (u)->x7 = (a); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (h) && (u)->x1 == (g) && (u)->x2 == (f) && (u)->x3 == (e) && \ - (u)->x4 == (d) && (u)->x5 == (c) && (u)->x6 == (b) && (u)->x7 == (a)) + ((u)->x0 == (h) && (u)->x1 == (g) && (u)->x2 == (f) && (u)->x3 == (e) && (u)->x4 == (d) && (u)->x5 == (c) && \ + (u)->x6 == (b) && (u)->x7 == (a)) #elif defined(DUK_USE_DOUBLE_ME) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (d); (u)->x1 = (c); (u)->x2 = (b); (u)->x3 = (a); \ - (u)->x4 = (h); (u)->x5 = (g); (u)->x6 = (f); (u)->x7 = (e); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (d); \ + (u)->x1 = (c); \ + (u)->x2 = (b); \ + (u)->x3 = (a); \ + (u)->x4 = (h); \ + (u)->x5 = (g); \ + (u)->x6 = (f); \ + (u)->x7 = (e); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (d) && (u)->x1 == (c) && (u)->x2 == (b) && (u)->x3 == (a) && \ - (u)->x4 == (h) && (u)->x5 == (g) && (u)->x6 == (f) && (u)->x7 == (e)) + ((u)->x0 == (d) && (u)->x1 == (c) && (u)->x2 == (b) && (u)->x3 == (a) && (u)->x4 == (h) && (u)->x5 == (g) && \ + (u)->x6 == (f) && (u)->x7 == (e)) #elif defined(DUK_USE_DOUBLE_BE) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (a); (u)->x1 = (b); (u)->x2 = (c); (u)->x3 = (d); \ - (u)->x4 = (e); (u)->x5 = (f); (u)->x6 = (g); (u)->x7 = (h); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (a); \ + (u)->x1 = (b); \ + (u)->x2 = (c); \ + (u)->x3 = (d); \ + (u)->x4 = (e); \ + (u)->x5 = (f); \ + (u)->x6 = (g); \ + (u)->x7 = (h); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (a) && (u)->x1 == (b) && (u)->x2 == (c) && (u)->x3 == (d) && \ - (u)->x4 == (e) && (u)->x5 == (f) && (u)->x6 == (g) && (u)->x7 == (h)) + ((u)->x0 == (a) && (u)->x1 == (b) && (u)->x2 == (c) && (u)->x3 == (d) && (u)->x4 == (e) && (u)->x5 == (f) && \ + (u)->x6 == (g) && (u)->x7 == (h)) #else #error unknown double endianness #endif @@ -88,17 +120,12 @@ DUK_LOCAL duk_uint_t duk__selftest_types(void) { duk_uint_t error_count = 0; - if (!(sizeof(duk_int8_t) == 1 && - sizeof(duk_uint8_t) == 1 && - sizeof(duk_int16_t) == 2 && - sizeof(duk_uint16_t) == 2 && - sizeof(duk_int32_t) == 4 && - sizeof(duk_uint32_t) == 4)) { + if (!(sizeof(duk_int8_t) == 1 && sizeof(duk_uint8_t) == 1 && sizeof(duk_int16_t) == 2 && sizeof(duk_uint16_t) == 2 && + sizeof(duk_int32_t) == 4 && sizeof(duk_uint32_t) == 4)) { DUK__FAILED("duk_(u)int{8,16,32}_t size"); } #if defined(DUK_USE_64BIT_OPS) - if (!(sizeof(duk_int64_t) == 8 && - sizeof(duk_uint64_t) == 8)) { + if (!(sizeof(duk_int64_t) == 8 && sizeof(duk_uint64_t) == 8)) { DUK__FAILED("duk_(u)int64_t size"); } #endif @@ -250,8 +277,14 @@ * (2.008366013071895,) */ - du.uc0 = 0x40; du.uc1 = 0x00; du.uc2 = 0x11; du.uc3 = 0x22; - du.uc4 = 0x33; du.uc5 = 0x44; du.uc6 = 0x55; du.uc7 = 0x66; + du.uc0 = 0x40; + du.uc1 = 0x00; + du.uc2 = 0x11; + du.uc3 = 0x22; + du.uc4 = 0x33; + du.uc5 = 0x44; + du.uc6 = 0x55; + du.uc7 = 0x66; DUK_DBLUNION_DOUBLE_NTOH(&du); du_diff = du.d - 2.008366013071895; #if 0 @@ -306,20 +339,38 @@ */ /* little endian */ - a.x0 = 0x11; a.x1 = 0x22; a.x2 = 0x33; a.x3 = 0x44; - a.x4 = 0x00; a.x5 = 0x00; a.x6 = 0xf1; a.x7 = 0xff; + a.x0 = 0x11; + a.x1 = 0x22; + a.x2 = 0x33; + a.x3 = 0x44; + a.x4 = 0x00; + a.x5 = 0x00; + a.x6 = 0xf1; + a.x7 = 0xff; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); /* big endian */ - a.x0 = 0xff; a.x1 = 0xf1; a.x2 = 0x00; a.x3 = 0x00; - a.x4 = 0x44; a.x5 = 0x33; a.x6 = 0x22; a.x7 = 0x11; + a.x0 = 0xff; + a.x1 = 0xf1; + a.x2 = 0x00; + a.x3 = 0x00; + a.x4 = 0x44; + a.x5 = 0x33; + a.x6 = 0x22; + a.x7 = 0x11; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); /* mixed endian */ - a.x0 = 0x00; a.x1 = 0x00; a.x2 = 0xf1; a.x3 = 0xff; - a.x4 = 0x11; a.x5 = 0x22; a.x6 = 0x33; a.x7 = 0x44; + a.x0 = 0x00; + a.x1 = 0x00; + a.x2 = 0xf1; + a.x3 = 0xff; + a.x4 = 0x11; + a.x5 = 0x22; + a.x6 = 0x33; + a.x7 = 0x44; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); @@ -384,10 +435,14 @@ c.d = a.d + b.d; if (!DUK__DOUBLE_COMPARE(&c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)) { DUK_D(DUK_DPRINT("broken result (native endiannesss): %02x %02x %02x %02x %02x %02x %02x %02x", - (unsigned int) c.x0, (unsigned int) c.x1, - (unsigned int) c.x2, (unsigned int) c.x3, - (unsigned int) c.x4, (unsigned int) c.x5, - (unsigned int) c.x6, (unsigned int) c.x7)); + (unsigned int) c.x0, + (unsigned int) c.x1, + (unsigned int) c.x2, + (unsigned int) c.x3, + (unsigned int) c.x4, + (unsigned int) c.x5, + (unsigned int) c.x6, + (unsigned int) c.x7)); DUK__FAILED("invalid result from 1.0 + 0.5ulp"); } @@ -404,10 +459,14 @@ c.d = a.d + b.d; if (!DUK__DOUBLE_COMPARE(&c, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02)) { DUK_D(DUK_DPRINT("broken result (native endiannesss): %02x %02x %02x %02x %02x %02x %02x %02x", - (unsigned int) c.x0, (unsigned int) c.x1, - (unsigned int) c.x2, (unsigned int) c.x3, - (unsigned int) c.x4, (unsigned int) c.x5, - (unsigned int) c.x6, (unsigned int) c.x7)); + (unsigned int) c.x0, + (unsigned int) c.x1, + (unsigned int) c.x2, + (unsigned int) c.x3, + (unsigned int) c.x4, + (unsigned int) c.x5, + (unsigned int) c.x6, + (unsigned int) c.x7)); DUK__FAILED("invalid result from (1.0 + ulp) + 0.5ulp"); } @@ -578,7 +637,7 @@ duk_double_t dv; duk_uint32_t uv; - dv = 3735928559.0; /* 0xdeadbeef in decimal */ + dv = 3735928559.0; /* 0xdeadbeef in decimal */ uv = (duk_uint32_t) dv; if (uv != 0xdeadbeefUL) { @@ -615,7 +674,7 @@ ptr = alloc_func(udata, (duk_size_t) i); if (ptr == NULL) { DUK_D(DUK_DPRINT("alloc failed, ignore")); - continue; /* alloc failed, ignore */ + continue; /* alloc failed, ignore */ } for (j = 0; j < i; j++) { ((unsigned char *) ptr)j = (unsigned char) (0x80 + j); @@ -624,14 +683,15 @@ if (new_ptr == NULL) { DUK_D(DUK_DPRINT("realloc failed, ignore")); free_func(udata, ptr); - continue; /* realloc failed, ignore */ + continue; /* realloc failed, ignore */ } ptr = new_ptr; for (j = 0; j < i; j++) { x = ((unsigned char *) ptr)j; if (x != (unsigned char) (0x80 + j)) { DUK_D(DUK_DPRINT("byte at index %ld doesn't match after realloc: %02lx", - (long) j, (unsigned long) x)); + (long) j, + (unsigned long) x)); DUK__FAILED("byte compare after realloc"); break; } @@ -675,4 +735,4 @@ return error_count; } -#endif /* DUK_USE_SELF_TESTS */ +#endif /* DUK_USE_SELF_TESTS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_selftest.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_selftest.h
Changed
@@ -12,4 +12,4 @@ void *udata); #endif -#endif /* DUK_SELFTEST_H_INCLUDED */ +#endif /* DUK_SELFTEST_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_strings.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_strings.h
Changed
@@ -22,148 +22,148 @@ #define DUK_ERRMSG_H_INCLUDED /* Mostly API and built-in method related */ -#define DUK_STR_INTERNAL_ERROR "internal error" -#define DUK_STR_UNSUPPORTED "unsupported" -#define DUK_STR_INVALID_COUNT "invalid count" -#define DUK_STR_INVALID_ARGS "invalid args" -#define DUK_STR_INVALID_STATE "invalid state" -#define DUK_STR_INVALID_INPUT "invalid input" -#define DUK_STR_INVALID_LENGTH "invalid length" -#define DUK_STR_NOT_CONSTRUCTABLE "not constructable" -#define DUK_STR_CONSTRUCT_ONLY "constructor requires 'new'" -#define DUK_STR_NOT_CALLABLE "not callable" -#define DUK_STR_NOT_EXTENSIBLE "not extensible" -#define DUK_STR_NOT_WRITABLE "not writable" -#define DUK_STR_NOT_CONFIGURABLE "not configurable" -#define DUK_STR_INVALID_CONTEXT "invalid context" -#define DUK_STR_INVALID_INDEX "invalid args" -#define DUK_STR_PUSH_BEYOND_ALLOC_STACK "cannot push beyond allocated stack" -#define DUK_STR_NOT_UNDEFINED "unexpected type" -#define DUK_STR_NOT_NULL "unexpected type" -#define DUK_STR_NOT_BOOLEAN "unexpected type" -#define DUK_STR_NOT_NUMBER "unexpected type" -#define DUK_STR_NOT_STRING "unexpected type" -#define DUK_STR_NOT_OBJECT "unexpected type" -#define DUK_STR_NOT_POINTER "unexpected type" -#define DUK_STR_NOT_BUFFER "not buffer" /* still in use with verbose messages */ -#define DUK_STR_UNEXPECTED_TYPE "unexpected type" -#define DUK_STR_NOT_THREAD "unexpected type" -#define DUK_STR_NOT_COMPFUNC "unexpected type" -#define DUK_STR_NOT_NATFUNC "unexpected type" -#define DUK_STR_NOT_C_FUNCTION "unexpected type" -#define DUK_STR_NOT_FUNCTION "unexpected type" -#define DUK_STR_NOT_REGEXP "unexpected type" -#define DUK_STR_TOPRIMITIVE_FAILED "coercion to primitive failed" -#define DUK_STR_NUMBER_OUTSIDE_RANGE "number outside range" -#define DUK_STR_NOT_OBJECT_COERCIBLE "not object coercible" -#define DUK_STR_CANNOT_NUMBER_COERCE_SYMBOL "cannot number coerce Symbol" -#define DUK_STR_CANNOT_STRING_COERCE_SYMBOL "cannot string coerce Symbol" -#define DUK_STR_STRING_TOO_LONG "string too long" -#define DUK_STR_BUFFER_TOO_LONG "buffer too long" -#define DUK_STR_ALLOC_FAILED "alloc failed" -#define DUK_STR_WRONG_BUFFER_TYPE "wrong buffer type" -#define DUK_STR_BASE64_ENCODE_FAILED "base64 encode failed" -#define DUK_STR_SOURCE_DECODE_FAILED "source decode failed" -#define DUK_STR_UTF8_DECODE_FAILED "utf-8 decode failed" -#define DUK_STR_BASE64_DECODE_FAILED "base64 decode failed" -#define DUK_STR_HEX_DECODE_FAILED "hex decode failed" -#define DUK_STR_INVALID_BYTECODE "invalid bytecode" -#define DUK_STR_NO_SOURCECODE "no sourcecode" -#define DUK_STR_RESULT_TOO_LONG "result too long" -#define DUK_STR_INVALID_CFUNC_RC "invalid C function rc" -#define DUK_STR_INVALID_INSTANCEOF_RVAL "invalid instanceof rval" -#define DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO "instanceof rval has no .prototype" +#define DUK_STR_INTERNAL_ERROR "internal error" +#define DUK_STR_UNSUPPORTED "unsupported" +#define DUK_STR_INVALID_COUNT "invalid count" +#define DUK_STR_INVALID_ARGS "invalid args" +#define DUK_STR_INVALID_STATE "invalid state" +#define DUK_STR_INVALID_INPUT "invalid input" +#define DUK_STR_INVALID_LENGTH "invalid length" +#define DUK_STR_NOT_CONSTRUCTABLE "not constructable" +#define DUK_STR_CONSTRUCT_ONLY "constructor requires 'new'" +#define DUK_STR_NOT_CALLABLE "not callable" +#define DUK_STR_NOT_EXTENSIBLE "not extensible" +#define DUK_STR_NOT_WRITABLE "not writable" +#define DUK_STR_NOT_CONFIGURABLE "not configurable" +#define DUK_STR_INVALID_CONTEXT "invalid context" +#define DUK_STR_INVALID_INDEX "invalid args" +#define DUK_STR_PUSH_BEYOND_ALLOC_STACK "cannot push beyond allocated stack" +#define DUK_STR_NOT_UNDEFINED "unexpected type" +#define DUK_STR_NOT_NULL "unexpected type" +#define DUK_STR_NOT_BOOLEAN "unexpected type" +#define DUK_STR_NOT_NUMBER "unexpected type" +#define DUK_STR_NOT_STRING "unexpected type" +#define DUK_STR_NOT_OBJECT "unexpected type" +#define DUK_STR_NOT_POINTER "unexpected type" +#define DUK_STR_NOT_BUFFER "not buffer" /* still in use with verbose messages */ +#define DUK_STR_UNEXPECTED_TYPE "unexpected type" +#define DUK_STR_NOT_THREAD "unexpected type" +#define DUK_STR_NOT_COMPFUNC "unexpected type" +#define DUK_STR_NOT_NATFUNC "unexpected type" +#define DUK_STR_NOT_C_FUNCTION "unexpected type" +#define DUK_STR_NOT_FUNCTION "unexpected type" +#define DUK_STR_NOT_REGEXP "unexpected type" +#define DUK_STR_TOPRIMITIVE_FAILED "coercion to primitive failed" +#define DUK_STR_NUMBER_OUTSIDE_RANGE "number outside range" +#define DUK_STR_NOT_OBJECT_COERCIBLE "not object coercible" +#define DUK_STR_CANNOT_NUMBER_COERCE_SYMBOL "cannot number coerce Symbol" +#define DUK_STR_CANNOT_STRING_COERCE_SYMBOL "cannot string coerce Symbol" +#define DUK_STR_STRING_TOO_LONG "string too long" +#define DUK_STR_BUFFER_TOO_LONG "buffer too long" +#define DUK_STR_ALLOC_FAILED "alloc failed" +#define DUK_STR_WRONG_BUFFER_TYPE "wrong buffer type" +#define DUK_STR_BASE64_ENCODE_FAILED "base64 encode failed" +#define DUK_STR_SOURCE_DECODE_FAILED "source decode failed" +#define DUK_STR_UTF8_DECODE_FAILED "utf-8 decode failed" +#define DUK_STR_BASE64_DECODE_FAILED "base64 decode failed" +#define DUK_STR_HEX_DECODE_FAILED "hex decode failed" +#define DUK_STR_INVALID_BYTECODE "invalid bytecode" +#define DUK_STR_NO_SOURCECODE "no sourcecode" +#define DUK_STR_RESULT_TOO_LONG "result too long" +#define DUK_STR_INVALID_CFUNC_RC "invalid C function rc" +#define DUK_STR_INVALID_INSTANCEOF_RVAL "invalid instanceof rval" +#define DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO "instanceof rval has no .prototype" /* JSON */ -#define DUK_STR_FMT_PTR "%p" -#define DUK_STR_FMT_INVALID_JSON "invalid json (at offset %ld)" -#define DUK_STR_CYCLIC_INPUT "cyclic input" +#define DUK_STR_FMT_PTR "%p" +#define DUK_STR_FMT_INVALID_JSON "invalid json (at offset %ld)" +#define DUK_STR_CYCLIC_INPUT "cyclic input" /* Generic codec */ -#define DUK_STR_DEC_RECLIMIT "decode recursion limit" -#define DUK_STR_ENC_RECLIMIT "encode recursion limit" +#define DUK_STR_DEC_RECLIMIT "decode recursion limit" +#define DUK_STR_ENC_RECLIMIT "encode recursion limit" /* Object property access */ -#define DUK_STR_INVALID_BASE "invalid base value" -#define DUK_STR_STRICT_CALLER_READ "cannot read strict 'caller'" -#define DUK_STR_PROXY_REJECTED "proxy rejected" -#define DUK_STR_INVALID_ARRAY_LENGTH "invalid array length" -#define DUK_STR_SETTER_UNDEFINED "setter undefined" -#define DUK_STR_INVALID_DESCRIPTOR "invalid descriptor" +#define DUK_STR_INVALID_BASE "invalid base value" +#define DUK_STR_STRICT_CALLER_READ "cannot read strict 'caller'" +#define DUK_STR_PROXY_REJECTED "proxy rejected" +#define DUK_STR_INVALID_ARRAY_LENGTH "invalid array length" +#define DUK_STR_SETTER_UNDEFINED "setter undefined" +#define DUK_STR_INVALID_DESCRIPTOR "invalid descriptor" /* Proxy */ -#define DUK_STR_PROXY_REVOKED "proxy revoked" -#define DUK_STR_INVALID_TRAP_RESULT "invalid trap result" +#define DUK_STR_PROXY_REVOKED "proxy revoked" +#define DUK_STR_INVALID_TRAP_RESULT "invalid trap result" /* Variables */ /* Lexer */ -#define DUK_STR_INVALID_ESCAPE "invalid escape" -#define DUK_STR_UNTERMINATED_STRING "unterminated string" -#define DUK_STR_UNTERMINATED_COMMENT "unterminated comment" -#define DUK_STR_UNTERMINATED_REGEXP "unterminated regexp" -#define DUK_STR_TOKEN_LIMIT "token limit" -#define DUK_STR_REGEXP_SUPPORT_DISABLED "regexp support disabled" -#define DUK_STR_INVALID_NUMBER_LITERAL "invalid number literal" -#define DUK_STR_INVALID_TOKEN "invalid token" +#define DUK_STR_INVALID_ESCAPE "invalid escape" +#define DUK_STR_UNTERMINATED_STRING "unterminated string" +#define DUK_STR_UNTERMINATED_COMMENT "unterminated comment" +#define DUK_STR_UNTERMINATED_REGEXP "unterminated regexp" +#define DUK_STR_TOKEN_LIMIT "token limit" +#define DUK_STR_REGEXP_SUPPORT_DISABLED "regexp support disabled" +#define DUK_STR_INVALID_NUMBER_LITERAL "invalid number literal" +#define DUK_STR_INVALID_TOKEN "invalid token" /* Compiler */ -#define DUK_STR_PARSE_ERROR "parse error" -#define DUK_STR_DUPLICATE_LABEL "duplicate label" -#define DUK_STR_INVALID_LABEL "invalid label" -#define DUK_STR_INVALID_ARRAY_LITERAL "invalid array literal" -#define DUK_STR_INVALID_OBJECT_LITERAL "invalid object literal" -#define DUK_STR_INVALID_VAR_DECLARATION "invalid variable declaration" -#define DUK_STR_CANNOT_DELETE_IDENTIFIER "cannot delete identifier" -#define DUK_STR_INVALID_EXPRESSION "invalid expression" -#define DUK_STR_INVALID_LVALUE "invalid lvalue" -#define DUK_STR_INVALID_NEWTARGET "invalid new.target" -#define DUK_STR_EXPECTED_IDENTIFIER "expected identifier" -#define DUK_STR_EMPTY_EXPR_NOT_ALLOWED "empty expression not allowed" -#define DUK_STR_INVALID_FOR "invalid for statement" -#define DUK_STR_INVALID_SWITCH "invalid switch statement" -#define DUK_STR_INVALID_BREAK_CONT_LABEL "invalid break/continue label" -#define DUK_STR_INVALID_RETURN "invalid return" -#define DUK_STR_INVALID_TRY "invalid try" -#define DUK_STR_INVALID_THROW "invalid throw" -#define DUK_STR_WITH_IN_STRICT_MODE "with in strict mode" -#define DUK_STR_FUNC_STMT_NOT_ALLOWED "function statement not allowed" -#define DUK_STR_UNTERMINATED_STMT "unterminated statement" -#define DUK_STR_INVALID_ARG_NAME "invalid argument name" -#define DUK_STR_INVALID_FUNC_NAME "invalid function name" -#define DUK_STR_INVALID_GETSET_NAME "invalid getter/setter name" -#define DUK_STR_FUNC_NAME_REQUIRED "function name required" +#define DUK_STR_PARSE_ERROR "parse error" +#define DUK_STR_DUPLICATE_LABEL "duplicate label" +#define DUK_STR_INVALID_LABEL "invalid label" +#define DUK_STR_INVALID_ARRAY_LITERAL "invalid array literal" +#define DUK_STR_INVALID_OBJECT_LITERAL "invalid object literal" +#define DUK_STR_INVALID_VAR_DECLARATION "invalid variable declaration" +#define DUK_STR_CANNOT_DELETE_IDENTIFIER "cannot delete identifier" +#define DUK_STR_INVALID_EXPRESSION "invalid expression" +#define DUK_STR_INVALID_LVALUE "invalid lvalue" +#define DUK_STR_INVALID_NEWTARGET "invalid new.target" +#define DUK_STR_EXPECTED_IDENTIFIER "expected identifier" +#define DUK_STR_EMPTY_EXPR_NOT_ALLOWED "empty expression not allowed" +#define DUK_STR_INVALID_FOR "invalid for statement" +#define DUK_STR_INVALID_SWITCH "invalid switch statement" +#define DUK_STR_INVALID_BREAK_CONT_LABEL "invalid break/continue label" +#define DUK_STR_INVALID_RETURN "invalid return" +#define DUK_STR_INVALID_TRY "invalid try" +#define DUK_STR_INVALID_THROW "invalid throw" +#define DUK_STR_WITH_IN_STRICT_MODE "with in strict mode" +#define DUK_STR_FUNC_STMT_NOT_ALLOWED "function statement not allowed" +#define DUK_STR_UNTERMINATED_STMT "unterminated statement" +#define DUK_STR_INVALID_ARG_NAME "invalid argument name" +#define DUK_STR_INVALID_FUNC_NAME "invalid function name" +#define DUK_STR_INVALID_GETSET_NAME "invalid getter/setter name" +#define DUK_STR_FUNC_NAME_REQUIRED "function name required" /* RegExp */ -#define DUK_STR_INVALID_QUANTIFIER "invalid regexp quantifier" -#define DUK_STR_INVALID_QUANTIFIER_NO_ATOM "quantifier without preceding atom" -#define DUK_STR_INVALID_QUANTIFIER_VALUES "quantifier values invalid (qmin > qmax)" -#define DUK_STR_QUANTIFIER_TOO_MANY_COPIES "quantifier requires too many atom copies" -#define DUK_STR_UNEXPECTED_CLOSING_PAREN "unexpected closing parenthesis" -#define DUK_STR_UNEXPECTED_END_OF_PATTERN "unexpected end of pattern" -#define DUK_STR_UNEXPECTED_REGEXP_TOKEN "unexpected token in regexp" -#define DUK_STR_INVALID_REGEXP_FLAGS "invalid regexp flags" -#define DUK_STR_INVALID_REGEXP_ESCAPE "invalid regexp escape" -#define DUK_STR_INVALID_BACKREFS "invalid backreference(s)" -#define DUK_STR_INVALID_REGEXP_CHARACTER "invalid regexp character" -#define DUK_STR_INVALID_REGEXP_GROUP "invalid regexp group" -#define DUK_STR_UNTERMINATED_CHARCLASS "unterminated character class" -#define DUK_STR_INVALID_RANGE "invalid range" +#define DUK_STR_INVALID_QUANTIFIER "invalid regexp quantifier" +#define DUK_STR_INVALID_QUANTIFIER_NO_ATOM "quantifier without preceding atom" +#define DUK_STR_INVALID_QUANTIFIER_VALUES "quantifier values invalid (qmin > qmax)" +#define DUK_STR_QUANTIFIER_TOO_MANY_COPIES "quantifier requires too many atom copies" +#define DUK_STR_UNEXPECTED_CLOSING_PAREN "unexpected closing parenthesis" +#define DUK_STR_UNEXPECTED_END_OF_PATTERN "unexpected end of pattern" +#define DUK_STR_UNEXPECTED_REGEXP_TOKEN "unexpected token in regexp" +#define DUK_STR_INVALID_REGEXP_FLAGS "invalid regexp flags" +#define DUK_STR_INVALID_REGEXP_ESCAPE "invalid regexp escape" +#define DUK_STR_INVALID_BACKREFS "invalid backreference(s)" +#define DUK_STR_INVALID_REGEXP_CHARACTER "invalid regexp character" +#define DUK_STR_INVALID_REGEXP_GROUP "invalid regexp group" +#define DUK_STR_UNTERMINATED_CHARCLASS "unterminated character class" +#define DUK_STR_INVALID_RANGE "invalid range" /* Limits */ -#define DUK_STR_VALSTACK_LIMIT "valstack limit" -#define DUK_STR_CALLSTACK_LIMIT "callstack limit" -#define DUK_STR_PROTOTYPE_CHAIN_LIMIT "prototype chain limit" -#define DUK_STR_BOUND_CHAIN_LIMIT "function call bound chain limit" -#define DUK_STR_NATIVE_STACK_LIMIT "C stack depth limit" -#define DUK_STR_COMPILER_RECURSION_LIMIT "compiler recursion limit" -#define DUK_STR_BYTECODE_LIMIT "bytecode limit" -#define DUK_STR_REG_LIMIT "register limit" -#define DUK_STR_TEMP_LIMIT "temp limit" -#define DUK_STR_CONST_LIMIT "const limit" -#define DUK_STR_FUNC_LIMIT "function limit" -#define DUK_STR_REGEXP_COMPILER_RECURSION_LIMIT "regexp compiler recursion limit" -#define DUK_STR_REGEXP_EXECUTOR_RECURSION_LIMIT "regexp executor recursion limit" -#define DUK_STR_REGEXP_EXECUTOR_STEP_LIMIT "regexp step limit" +#define DUK_STR_VALSTACK_LIMIT "valstack limit" +#define DUK_STR_CALLSTACK_LIMIT "callstack limit" +#define DUK_STR_PROTOTYPE_CHAIN_LIMIT "prototype chain limit" +#define DUK_STR_BOUND_CHAIN_LIMIT "function call bound chain limit" +#define DUK_STR_NATIVE_STACK_LIMIT "C stack depth limit" +#define DUK_STR_COMPILER_RECURSION_LIMIT "compiler recursion limit" +#define DUK_STR_BYTECODE_LIMIT "bytecode limit" +#define DUK_STR_REG_LIMIT "register limit" +#define DUK_STR_TEMP_LIMIT "temp limit" +#define DUK_STR_CONST_LIMIT "const limit" +#define DUK_STR_FUNC_LIMIT "function limit" +#define DUK_STR_REGEXP_COMPILER_RECURSION_LIMIT "regexp compiler recursion limit" +#define DUK_STR_REGEXP_EXECUTOR_RECURSION_LIMIT "regexp executor recursion limit" +#define DUK_STR_REGEXP_EXECUTOR_STEP_LIMIT "regexp step limit" -#endif /* DUK_ERRMSG_H_INCLUDED */ +#endif /* DUK_ERRMSG_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_tval.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_tval.c
Changed
@@ -32,11 +32,11 @@ expt = (duk_small_int_t) ((i >> 52) & 0x07ff); shift = expt - 1023; - if (shift >= 0 && shift <= 46) { /* exponents 1023 to 1069 */ + if (shift >= 0 && shift <= 46) { /* exponents 1023 to 1069 */ duk_int64_t t; if (((DUK_I64_CONSTANT(0x000fffffffffffff) >> shift) & i) == 0) { - t = i | DUK_I64_CONSTANT(0x0010000000000000); /* implicit leading one */ + t = i | DUK_I64_CONSTANT(0x0010000000000000); /* implicit leading one */ t = t & DUK_I64_CONSTANT(0x001fffffffffffff); t = t >> (52 - shift); if (i < 0) { @@ -45,13 +45,13 @@ DUK_TVAL_SET_FASTINT(tv, t); return; } - } else if (shift == -1023) { /* exponent 0 */ + } else if (shift == -1023) { /* exponent 0 */ if (i >= 0 && (i & DUK_I64_CONSTANT(0x000fffffffffffff)) == 0) { /* Note: reject negative zero. */ DUK_TVAL_SET_FASTINT(tv, (duk_int64_t) 0); return; } - } else if (shift == 47) { /* exponent 1070 */ + } else if (shift == 47) { /* exponent 1070 */ if (i < 0 && (i & DUK_I64_CONSTANT(0x000fffffffffffff)) == 0) { DUK_TVAL_SET_FASTINT(tv, (duk_int64_t) DUK_FASTINT_MIN); return; @@ -79,23 +79,23 @@ if ((t >> 48) != DUK_TAG_FASTINT) { return tv->d; } else if (t & DUK_U64_CONSTANT(0x0000800000000000)) { - t = (duk_uint64_t) (-((duk_int64_t) t)); /* avoid unary minus on unsigned */ - t = t & DUK_U64_CONSTANT(0x0000ffffffffffff); /* negative */ + t = (duk_uint64_t) (-((duk_int64_t) t)); /* avoid unary minus on unsigned */ + t = t & DUK_U64_CONSTANT(0x0000ffffffffffff); /* negative */ t |= DUK_U64_CONSTANT(0xc330000000000000); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d + 4503599627370496.0; /* 1 << 52 */ + return du.d + 4503599627370496.0; /* 1 << 52 */ } else if (t != 0) { - t &= DUK_U64_CONSTANT(0x0000ffffffffffff); /* positive */ + t &= DUK_U64_CONSTANT(0x0000ffffffffffff); /* positive */ t |= DUK_U64_CONSTANT(0x4330000000000000); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d - 4503599627370496.0; /* 1 << 52 */ + return du.d - 4503599627370496.0; /* 1 << 52 */ } else { - return 0.0; /* zero */ + return 0.0; /* zero */ } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#if 0 /* unused */ +#if 0 /* unused */ #if defined(DUK_USE_FASTINT) && !defined(DUK_USE_PACKED_TVAL) DUK_INTERNAL DUK_ALWAYS_INLINE duk_double_t duk_tval_get_number_unpacked(duk_tval *tv) { duk_double_union du; @@ -117,8 +117,8 @@ return tv->v.d; } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#endif /* 0 */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* 0 */ #if defined(DUK_USE_FASTINT) && !defined(DUK_USE_PACKED_TVAL) DUK_INTERNAL DUK_ALWAYS_INLINE duk_double_t duk_tval_get_number_unpacked_fastint(duk_tval *tv) { @@ -130,16 +130,16 @@ if (tv->v.fi >= 0) { t = DUK_U64_CONSTANT(0x4330000000000000) | (duk_uint64_t) tv->v.fi; DUK_DBLUNION_SET_UINT64(&du, t); - return du.d - 4503599627370496.0; /* 1 << 52 */ + return du.d - 4503599627370496.0; /* 1 << 52 */ } else { t = DUK_U64_CONSTANT(0xc330000000000000) | (duk_uint64_t) (-tv->v.fi); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d + 4503599627370496.0; /* 1 << 52 */ + return du.d + 4503599627370496.0; /* 1 << 52 */ } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* * Assertion helpers.
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_tval.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_tval.h
Changed
@@ -41,30 +41,29 @@ } duk_tval_unused; /* tags */ -#define DUK_TAG_NORMALIZED_NAN 0x7ff8UL /* the NaN variant we use */ +#define DUK_TAG_NORMALIZED_NAN 0x7ff8UL /* the NaN variant we use */ /* avoid tag 0xfff0, no risk of confusion with negative infinity */ -#define DUK_TAG_MIN 0xfff1UL +#define DUK_TAG_MIN 0xfff1UL #if defined(DUK_USE_FASTINT) -#define DUK_TAG_FASTINT 0xfff1UL /* embed: integer value */ +#define DUK_TAG_FASTINT 0xfff1UL /* embed: integer value */ #endif -#define DUK_TAG_UNUSED 0xfff2UL /* marker; not actual tagged value */ -#define DUK_TAG_UNDEFINED 0xfff3UL /* embed: nothing */ -#define DUK_TAG_NULL 0xfff4UL /* embed: nothing */ -#define DUK_TAG_BOOLEAN 0xfff5UL /* embed: 0 or 1 (false or true) */ +#define DUK_TAG_UNUSED 0xfff2UL /* marker; not actual tagged value */ +#define DUK_TAG_UNDEFINED 0xfff3UL /* embed: nothing */ +#define DUK_TAG_NULL 0xfff4UL /* embed: nothing */ +#define DUK_TAG_BOOLEAN 0xfff5UL /* embed: 0 or 1 (false or true) */ /* DUK_TAG_NUMBER would logically go here, but it has multiple 'tags' */ -#define DUK_TAG_POINTER 0xfff6UL /* embed: void ptr */ -#define DUK_TAG_LIGHTFUNC 0xfff7UL /* embed: func ptr */ -#define DUK_TAG_STRING 0xfff8UL /* embed: duk_hstring ptr */ -#define DUK_TAG_OBJECT 0xfff9UL /* embed: duk_hobject ptr */ -#define DUK_TAG_BUFFER 0xfffaUL /* embed: duk_hbuffer ptr */ -#define DUK_TAG_MAX 0xfffaUL +#define DUK_TAG_POINTER 0xfff6UL /* embed: void ptr */ +#define DUK_TAG_LIGHTFUNC 0xfff7UL /* embed: func ptr */ +#define DUK_TAG_STRING 0xfff8UL /* embed: duk_hstring ptr */ +#define DUK_TAG_OBJECT 0xfff9UL /* embed: duk_hobject ptr */ +#define DUK_TAG_BUFFER 0xfffaUL /* embed: duk_hbuffer ptr */ +#define DUK_TAG_MAX 0xfffaUL /* for convenience */ -#define DUK_XTAG_BOOLEAN_FALSE 0xfff50000UL -#define DUK_XTAG_BOOLEAN_TRUE 0xfff50001UL +#define DUK_XTAG_BOOLEAN_FALSE 0xfff50000UL +#define DUK_XTAG_BOOLEAN_TRUE 0xfff50001UL -#define DUK_TVAL_IS_VALID_TAG(tv) \ - (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) +#define DUK_TVAL_IS_VALID_TAG(tv) (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) /* DUK_TVAL_UNUSED initializer for duk_tval_unused, works for any endianness. */ #define DUK_TVAL_UNUSED_INITIALIZER() \ @@ -73,116 +72,136 @@ /* two casts to avoid gcc warning: "warning: cast from pointer to integer of different size -Wpointer-to-int-cast" */ #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) (tag)) << 16) | (((duk_uint64_t) (duk_uint32_t) (h)) << 32); \ } while (0) #else -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) (tag)) << 48) | ((duk_uint64_t) (duk_uint32_t) (h)); \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) (tag)) << 16; \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (h); \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ #if defined(DUK_USE_64BIT_OPS) /* Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size) */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 16) | \ - ((duk_uint64_t) (flags)) | \ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 16) | ((duk_uint64_t) (flags)) | \ (((duk_uint64_t) (duk_uint32_t) (fp)) << 32); \ } while (0) #else -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 48) | \ - (((duk_uint64_t) (flags)) << 32) | \ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 48) | (((duk_uint64_t) (flags)) << 32) | \ ((duk_uint64_t) (duk_uint32_t) (fp)); \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = (((duk_uint32_t) DUK_TAG_LIGHTFUNC) << 16) | ((duk_uint32_t) (flags)); \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (fp); \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ #if defined(DUK_USE_FASTINT) /* Note: masking is done for 'i' to deal with negative numbers correctly */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_I48(tv,i) do { \ +#define DUK__TVAL_SET_I48(tv, i) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ - duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) DUK_TAG_FASTINT) << 16 | (((duk_uint32_t) ((i) >> 32)) & 0x0000ffffUL); \ + duk__tv->uiDUK_DBL_IDX_UI0 = \ + ((duk_uint32_t) DUK_TAG_FASTINT) << 16 | (((duk_uint32_t) ((i) >> 32)) & 0x0000ffffUL); \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (i); \ } while (0) -#define DUK__TVAL_SET_U32(tv,i) do { \ +#define DUK__TVAL_SET_U32(tv, i) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) DUK_TAG_FASTINT) << 16; \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (i); \ } while (0) #else -#define DUK__TVAL_SET_I48(tv,i) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & DUK_U64_CONSTANT(0x0000ffffffffffff)); \ +#define DUK__TVAL_SET_I48(tv, i) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = \ + (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & DUK_U64_CONSTANT(0x0000ffffffffffff)); \ } while (0) -#define DUK__TVAL_SET_U32(tv,i) do { \ +#define DUK__TVAL_SET_U32(tv, i) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (duk_uint64_t) (i); \ } while (0) #endif /* This needs to go through a cast because sign extension is needed. */ -#define DUK__TVAL_SET_I32(tv,i) do { \ +#define DUK__TVAL_SET_I32(tv, i) \ + do { \ duk_int64_t duk__tmp = (duk_int64_t) (i); \ DUK_TVAL_SET_I48((tv), duk__tmp); \ } while (0) /* XXX: Clumsy sign extend and masking of 16 topmost bits. */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_GET_FASTINT(tv) (((duk_int64_t) ((((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI1))) << 16 >> 16) +#define DUK__TVAL_GET_FASTINT(tv) \ + (((duk_int64_t) ((((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI1))) \ + << 16 >> \ + 16) #else -#define DUK__TVAL_GET_FASTINT(tv) ((((duk_int64_t) (tv)->ullDUK_DBL_IDX_ULL0) << 16) >> 16) +#define DUK__TVAL_GET_FASTINT(tv) ((((duk_int64_t) (tv)->ullDUK_DBL_IDX_ULL0) << 16) >> 16) #endif -#define DUK__TVAL_GET_FASTINT_U32(tv) ((tv)->uiDUK_DBL_IDX_UI1) -#define DUK__TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) (tv)->uiDUK_DBL_IDX_UI1) -#endif /* DUK_USE_FASTINT */ +#define DUK__TVAL_GET_FASTINT_U32(tv) ((tv)->uiDUK_DBL_IDX_UI1) +#define DUK__TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) (tv)->uiDUK_DBL_IDX_UI1) +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_UNDEFINED(tv) do { \ +#define DUK_TVAL_SET_UNDEFINED(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_UNDEFINED; \ } while (0) -#define DUK_TVAL_SET_UNUSED(tv) do { \ +#define DUK_TVAL_SET_UNUSED(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_UNUSED; \ } while (0) -#define DUK_TVAL_SET_NULL(tv) do { \ +#define DUK_TVAL_SET_NULL(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_NULL; \ } while (0) -#define DUK_TVAL_SET_BOOLEAN(tv,val) DUK_DBLUNION_SET_HIGH32((tv), (((duk_uint32_t) DUK_TAG_BOOLEAN) << 16) | ((duk_uint32_t) (val))) +#define DUK_TVAL_SET_BOOLEAN(tv, val) \ + DUK_DBLUNION_SET_HIGH32((tv), (((duk_uint32_t) DUK_TAG_BOOLEAN) << 16) | ((duk_uint32_t) (val))) -#define DUK_TVAL_SET_NAN(tv) DUK_DBLUNION_SET_NAN_FULL((tv)) +#define DUK_TVAL_SET_NAN(tv) DUK_DBLUNION_SET_NAN_FULL((tv)) /* Assumes that caller has normalized NaNs, otherwise trouble ahead. */ #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_DOUBLE(tv,d) do { \ +#define DUK_TVAL_SET_DOUBLE(tv, d) \ + do { \ duk_double_t duk__dblval; \ duk__dblval = (d); \ DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \ DUK_DBLUNION_SET_DOUBLE((tv), duk__dblval); \ } while (0) -#define DUK_TVAL_SET_I48(tv,i) DUK__TVAL_SET_I48((tv), (i)) -#define DUK_TVAL_SET_I32(tv,i) DUK__TVAL_SET_I32((tv), (i)) -#define DUK_TVAL_SET_U32(tv,i) DUK__TVAL_SET_U32((tv), (i)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) duk_tval_set_number_chkfast_fast((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) duk_tval_set_number_chkfast_slow((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { \ +#define DUK_TVAL_SET_I48(tv, i) DUK__TVAL_SET_I48((tv), (i)) +#define DUK_TVAL_SET_I32(tv, i) DUK__TVAL_SET_I32((tv), (i)) +#define DUK_TVAL_SET_U32(tv, i) DUK__TVAL_SET_U32((tv), (i)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) duk_tval_set_number_chkfast_fast((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) duk_tval_set_number_chkfast_slow((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -191,7 +210,8 @@ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(duk__tv, duk__d); \ } \ } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { \ +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -200,89 +220,98 @@ DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(duk__tv, duk__d); \ } \ } while (0) -#else /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_DOUBLE(tv,d) do { \ +#else /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_DOUBLE(tv, d) \ + do { \ duk_double_t duk__dblval; \ duk__dblval = (d); \ DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \ DUK_DBLUNION_SET_DOUBLE((tv), duk__dblval); \ } while (0) -#define DUK_TVAL_SET_I48(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_I32(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) -#define DUK_TVAL_SET_U32(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { } while (0) -#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_I48(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_I32(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) +#define DUK_TVAL_SET_U32(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ + } while (0) +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ + } while (0) +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT(tv,i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ +#define DUK_TVAL_SET_FASTINT(tv, i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ -#define DUK_TVAL_SET_LIGHTFUNC(tv,fp,flags) DUK__TVAL_SET_LIGHTFUNC((tv), (fp), (flags)) -#define DUK_TVAL_SET_STRING(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_STRING) -#define DUK_TVAL_SET_OBJECT(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_OBJECT) -#define DUK_TVAL_SET_BUFFER(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_BUFFER) -#define DUK_TVAL_SET_POINTER(tv,p) DUK__TVAL_SET_TAGGEDPOINTER((tv), (p), DUK_TAG_POINTER) +#define DUK_TVAL_SET_LIGHTFUNC(tv, fp, flags) DUK__TVAL_SET_LIGHTFUNC((tv), (fp), (flags)) +#define DUK_TVAL_SET_STRING(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_STRING) +#define DUK_TVAL_SET_OBJECT(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_OBJECT) +#define DUK_TVAL_SET_BUFFER(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_BUFFER) +#define DUK_TVAL_SET_POINTER(tv, p) DUK__TVAL_SET_TAGGEDPOINTER((tv), (p), DUK_TAG_POINTER) -#define DUK_TVAL_SET_TVAL(tv,x) do { *(tv) = *(x); } while (0) +#define DUK_TVAL_SET_TVAL(tv, x) \ + do { \ + *(tv) = *(x); \ + } while (0) /* getters */ -#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US1) +#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US1) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) -#define DUK_TVAL_GET_FASTINT(tv) DUK__TVAL_GET_FASTINT((tv)) -#define DUK_TVAL_GET_FASTINT_U32(tv) DUK__TVAL_GET_FASTINT_U32((tv)) -#define DUK_TVAL_GET_FASTINT_I32(tv) DUK__TVAL_GET_FASTINT_I32((tv)) -#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_packed((tv)) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) +#define DUK_TVAL_GET_FASTINT(tv) DUK__TVAL_GET_FASTINT((tv)) +#define DUK_TVAL_GET_FASTINT_U32(tv) DUK__TVAL_GET_FASTINT_U32((tv)) +#define DUK_TVAL_GET_FASTINT_I32(tv) DUK__TVAL_GET_FASTINT_I32((tv)) +#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_packed((tv)) #else -#define DUK_TVAL_GET_NUMBER(tv) ((tv)->d) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) +#define DUK_TVAL_GET_NUMBER(tv) ((tv)->d) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) #endif -#define DUK_TVAL_GET_LIGHTFUNC(tv,out_fp,out_flags) do { \ +#define DUK_TVAL_GET_LIGHTFUNC(tv, out_fp, out_flags) \ + do { \ (out_flags) = (tv)->uiDUK_DBL_IDX_UI0 & 0xffffUL; \ (out_fp) = (duk_c_function) (tv)->uiDUK_DBL_IDX_UI1; \ } while (0) -#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((duk_c_function) ((tv)->uiDUK_DBL_IDX_UI1)) -#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) (((duk_small_uint_t) (tv)->uiDUK_DBL_IDX_UI0) & 0xffffUL) -#define DUK_TVAL_GET_STRING(tv) ((duk_hstring *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_OBJECT(tv) ((duk_hobject *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_BUFFER(tv) ((duk_hbuffer *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_POINTER(tv) ((void *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_HEAPHDR(tv) ((duk_heaphdr *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((duk_c_function) ((tv)->uiDUK_DBL_IDX_UI1)) +#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) (((duk_small_uint_t) (tv)->uiDUK_DBL_IDX_UI0) & 0xffffUL) +#define DUK_TVAL_GET_STRING(tv) ((duk_hstring *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_OBJECT(tv) ((duk_hobject *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_BUFFER(tv) ((duk_hbuffer *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_POINTER(tv) ((void *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_HEAPHDR(tv) ((duk_heaphdr *) (tv)->vpDUK_DBL_IDX_VP1) /* decoding */ -#define DUK_TVAL_GET_TAG(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US0) - -#define DUK_TVAL_IS_UNDEFINED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNDEFINED) -#define DUK_TVAL_IS_UNUSED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNUSED) -#define DUK_TVAL_IS_NULL(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_NULL) -#define DUK_TVAL_IS_BOOLEAN(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BOOLEAN) -#define DUK_TVAL_IS_BOOLEAN_TRUE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_TRUE) -#define DUK_TVAL_IS_BOOLEAN_FALSE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_FALSE) -#define DUK_TVAL_IS_LIGHTFUNC(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_LIGHTFUNC) -#define DUK_TVAL_IS_STRING(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_STRING) -#define DUK_TVAL_IS_OBJECT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_OBJECT) -#define DUK_TVAL_IS_BUFFER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BUFFER) -#define DUK_TVAL_IS_POINTER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_POINTER) +#define DUK_TVAL_GET_TAG(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US0) + +#define DUK_TVAL_IS_UNDEFINED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNDEFINED) +#define DUK_TVAL_IS_UNUSED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNUSED) +#define DUK_TVAL_IS_NULL(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_NULL) +#define DUK_TVAL_IS_BOOLEAN(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BOOLEAN) +#define DUK_TVAL_IS_BOOLEAN_TRUE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_TRUE) +#define DUK_TVAL_IS_BOOLEAN_FALSE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_FALSE) +#define DUK_TVAL_IS_LIGHTFUNC(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_LIGHTFUNC) +#define DUK_TVAL_IS_STRING(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_STRING) +#define DUK_TVAL_IS_OBJECT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_OBJECT) +#define DUK_TVAL_IS_BUFFER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BUFFER) +#define DUK_TVAL_IS_POINTER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_POINTER) #if defined(DUK_USE_FASTINT) /* 0xfff0 is -Infinity */ -#define DUK_TVAL_IS_DOUBLE(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) -#define DUK_TVAL_IS_FASTINT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_FASTINT) -#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff1UL) +#define DUK_TVAL_IS_DOUBLE(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) +#define DUK_TVAL_IS_FASTINT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_FASTINT) +#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff1UL) #else -#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) -#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) +#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) +#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) #endif /* This is performance critical because it appears in every DECREF. */ -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) (DUK_TVAL_GET_TAG((tv)) >= DUK_TAG_STRING) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) (DUK_TVAL_GET_TAG((tv)) >= DUK_TAG_STRING) #if defined(DUK_USE_FASTINT) DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_packed(duk_tval *tv); #endif -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ /* ======================================================================== */ /* @@ -306,7 +335,7 @@ duk_double_t d; duk_small_int_t i; #if defined(DUK_USE_FASTINT) - duk_int64_t fi; /* if present, forces 16-byte duk_tval */ + duk_int64_t fi; /* if present, forces 16-byte duk_tval */ #endif void *voidptr; duk_hstring *hstring; @@ -334,24 +363,23 @@ #define DUK_TVAL_UNUSED_INITIALIZER() \ { DUK_TAG_UNUSED, 0, 0.0 } -#define DUK_TAG_MIN 0 -#define DUK_TAG_NUMBER 0 /* DUK_TAG_NUMBER only defined for non-packed duk_tval */ +#define DUK_TAG_MIN 0 +#define DUK_TAG_NUMBER 0 /* DUK_TAG_NUMBER only defined for non-packed duk_tval */ #if defined(DUK_USE_FASTINT) -#define DUK_TAG_FASTINT 1 +#define DUK_TAG_FASTINT 1 #endif -#define DUK_TAG_UNDEFINED 2 -#define DUK_TAG_NULL 3 -#define DUK_TAG_BOOLEAN 4 -#define DUK_TAG_POINTER 5 -#define DUK_TAG_LIGHTFUNC 6 -#define DUK_TAG_UNUSED 7 /* marker; not actual tagged type */ -#define DUK_TAG_STRING 8 /* first heap allocated, match bit boundary */ -#define DUK_TAG_OBJECT 9 -#define DUK_TAG_BUFFER 10 -#define DUK_TAG_MAX 10 - -#define DUK_TVAL_IS_VALID_TAG(tv) \ - (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) +#define DUK_TAG_UNDEFINED 2 +#define DUK_TAG_NULL 3 +#define DUK_TAG_BOOLEAN 4 +#define DUK_TAG_POINTER 5 +#define DUK_TAG_LIGHTFUNC 6 +#define DUK_TAG_UNUSED 7 /* marker; not actual tagged type */ +#define DUK_TAG_STRING 8 /* first heap allocated, match bit boundary */ +#define DUK_TAG_OBJECT 9 +#define DUK_TAG_BUFFER 10 +#define DUK_TAG_MAX 10 + +#define DUK_TVAL_IS_VALID_TAG(tv) (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) /* DUK_TAG_NUMBER is intentionally first, as it is the default clause in code * to support the 8-byte representation. Further, it is a non-heap-allocated @@ -360,25 +388,29 @@ */ /* setters */ -#define DUK_TVAL_SET_UNDEFINED(tv) do { \ +#define DUK_TVAL_SET_UNDEFINED(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_UNDEFINED; \ } while (0) -#define DUK_TVAL_SET_UNUSED(tv) do { \ +#define DUK_TVAL_SET_UNUSED(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_UNUSED; \ } while (0) -#define DUK_TVAL_SET_NULL(tv) do { \ +#define DUK_TVAL_SET_NULL(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_NULL; \ } while (0) -#define DUK_TVAL_SET_BOOLEAN(tv,val) do { \ +#define DUK_TVAL_SET_BOOLEAN(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_BOOLEAN; \ @@ -386,7 +418,8 @@ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_DOUBLE(tv,val) do { \ +#define DUK_TVAL_SET_DOUBLE(tv, val) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__dblval; \ duk__dblval = (val); \ @@ -395,31 +428,32 @@ duk__tv->t = DUK_TAG_NUMBER; \ duk__tv->v.d = duk__dblval; \ } while (0) -#define DUK_TVAL_SET_I48(tv,val) do { \ +#define DUK_TVAL_SET_I48(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (val); \ } while (0) -#define DUK_TVAL_SET_U32(tv,val) do { \ +#define DUK_TVAL_SET_U32(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (duk_int64_t) (val); \ } while (0) -#define DUK_TVAL_SET_I32(tv,val) do { \ +#define DUK_TVAL_SET_I32(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (duk_int64_t) (val); \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) \ - duk_tval_set_number_chkfast_fast((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) \ - duk_tval_set_number_chkfast_slow((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,val) \ - DUK_TVAL_SET_DOUBLE((tv), (val)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) duk_tval_set_number_chkfast_fast((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) duk_tval_set_number_chkfast_slow((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, val) DUK_TVAL_SET_DOUBLE((tv), (val)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -428,7 +462,8 @@ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(duk__tv, duk__d); \ } \ } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { \ +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -437,16 +472,13 @@ DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(duk__tv, duk__d); \ } \ } while (0) -#else /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_DOUBLE(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_SET_I48(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_U32(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) -#define DUK_TVAL_SET_I32(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) -#define DUK_TVAL_SET_NUMBER(tv,val) do { \ +#else /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_DOUBLE(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_SET_I48(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_U32(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) +#define DUK_TVAL_SET_I32(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) +#define DUK_TVAL_SET_NUMBER(tv, val) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__dblval; \ duk__dblval = (val); \ @@ -455,25 +487,28 @@ duk__tv->t = DUK_TAG_NUMBER; \ duk__tv->v.d = duk__dblval; \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { } while (0) -#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ + } while (0) +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ + } while (0) +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT(tv,i) \ - DUK_TVAL_SET_I48((tv), (i)) /* alias */ +#define DUK_TVAL_SET_FASTINT(tv, i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ -#define DUK_TVAL_SET_POINTER(tv,hptr) do { \ +#define DUK_TVAL_SET_POINTER(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_POINTER; \ duk__tv->v.voidptr = (hptr); \ } while (0) -#define DUK_TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ +#define DUK_TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_LIGHTFUNC; \ @@ -481,28 +516,32 @@ duk__tv->v.lightfunc = (duk_c_function) (fp); \ } while (0) -#define DUK_TVAL_SET_STRING(tv,hptr) do { \ +#define DUK_TVAL_SET_STRING(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_STRING; \ duk__tv->v.hstring = (hptr); \ } while (0) -#define DUK_TVAL_SET_OBJECT(tv,hptr) do { \ +#define DUK_TVAL_SET_OBJECT(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_OBJECT; \ duk__tv->v.hobject = (hptr); \ } while (0) -#define DUK_TVAL_SET_BUFFER(tv,hptr) do { \ +#define DUK_TVAL_SET_BUFFER(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_BUFFER; \ duk__tv->v.hbuffer = (hptr); \ } while (0) -#define DUK_TVAL_SET_NAN(tv) do { \ +#define DUK_TVAL_SET_NAN(tv) \ + do { \ /* in non-packed representation we don't care about which NaN is used */ \ duk_tval *duk__tv; \ duk__tv = (tv); \ @@ -510,32 +549,32 @@ duk__tv->v.d = DUK_DOUBLE_NAN; \ } while (0) -#define DUK_TVAL_SET_TVAL(tv,x) do { *(tv) = *(x); } while (0) +#define DUK_TVAL_SET_TVAL(tv, x) \ + do { \ + *(tv) = *(x); \ + } while (0) /* getters */ -#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->v.i) +#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->v.i) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) -#define DUK_TVAL_GET_FASTINT(tv) ((tv)->v.fi) -#define DUK_TVAL_GET_FASTINT_U32(tv) ((duk_uint32_t) ((tv)->v.fi)) -#define DUK_TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) ((tv)->v.fi)) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) +#define DUK_TVAL_GET_FASTINT(tv) ((tv)->v.fi) +#define DUK_TVAL_GET_FASTINT_U32(tv) ((duk_uint32_t) ((tv)->v.fi)) +#define DUK_TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) ((tv)->v.fi)) #if 0 -#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? \ - (duk_double_t) DUK_TVAL_GET_FASTINT((tv)) : \ - DUK_TVAL_GET_DOUBLE((tv))) -#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_unpacked((tv)) +#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? (duk_double_t) DUK_TVAL_GET_FASTINT((tv)) : DUK_TVAL_GET_DOUBLE((tv))) +#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_unpacked((tv)) #else /* This seems reasonable overall. */ -#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? \ - duk_tval_get_number_unpacked_fastint((tv)) : \ - DUK_TVAL_GET_DOUBLE((tv))) +#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? duk_tval_get_number_unpacked_fastint((tv)) : DUK_TVAL_GET_DOUBLE((tv))) #endif #else -#define DUK_TVAL_GET_NUMBER(tv) ((tv)->v.d) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_GET_POINTER(tv) ((tv)->v.voidptr) -#define DUK_TVAL_GET_LIGHTFUNC(tv,out_fp,out_flags) do { \ +#define DUK_TVAL_GET_NUMBER(tv) ((tv)->v.d) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_GET_POINTER(tv) ((tv)->v.voidptr) +#define DUK_TVAL_GET_LIGHTFUNC(tv, out_fp, out_flags) \ + do { \ (out_flags) = (duk_uint32_t) (tv)->v_extra; \ (out_fp) = (tv)->v.lightfunc; \ } while (0) @@ -555,19 +594,18 @@ #define DUK_TVAL_IS_BOOLEAN_TRUE(tv) (((tv)->t == DUK_TAG_BOOLEAN) && ((tv)->v.i != 0)) #define DUK_TVAL_IS_BOOLEAN_FALSE(tv) (((tv)->t == DUK_TAG_BOOLEAN) && ((tv)->v.i == 0)) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_IS_DOUBLE(tv) ((tv)->t == DUK_TAG_NUMBER) -#define DUK_TVAL_IS_FASTINT(tv) ((tv)->t == DUK_TAG_FASTINT) -#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER || \ - (tv)->t == DUK_TAG_FASTINT) +#define DUK_TVAL_IS_DOUBLE(tv) ((tv)->t == DUK_TAG_NUMBER) +#define DUK_TVAL_IS_FASTINT(tv) ((tv)->t == DUK_TAG_FASTINT) +#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER || (tv)->t == DUK_TAG_FASTINT) #else -#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER) -#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_IS_POINTER(tv) ((tv)->t == DUK_TAG_POINTER) -#define DUK_TVAL_IS_LIGHTFUNC(tv) ((tv)->t == DUK_TAG_LIGHTFUNC) -#define DUK_TVAL_IS_STRING(tv) ((tv)->t == DUK_TAG_STRING) -#define DUK_TVAL_IS_OBJECT(tv) ((tv)->t == DUK_TAG_OBJECT) -#define DUK_TVAL_IS_BUFFER(tv) ((tv)->t == DUK_TAG_BUFFER) +#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER) +#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_IS_POINTER(tv) ((tv)->t == DUK_TAG_POINTER) +#define DUK_TVAL_IS_LIGHTFUNC(tv) ((tv)->t == DUK_TAG_LIGHTFUNC) +#define DUK_TVAL_IS_STRING(tv) ((tv)->t == DUK_TAG_STRING) +#define DUK_TVAL_IS_OBJECT(tv) ((tv)->t == DUK_TAG_OBJECT) +#define DUK_TVAL_IS_BUFFER(tv) ((tv)->t == DUK_TAG_BUFFER) /* This is performance critical because it's needed for every DECREF. * Take advantage of the fact that the first heap allocated tag is 8, @@ -575,9 +613,9 @@ * non-heap-allocated tags). */ #if 0 -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t >= DUK_TAG_STRING) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t >= DUK_TAG_STRING) #endif -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t & 0x08) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t & 0x08) #if defined(DUK_USE_FASTINT) #if 0 @@ -586,44 +624,39 @@ DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_unpacked_fastint(duk_tval *tv); #endif -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ /* * Convenience (independent of representation) */ -#define DUK_TVAL_SET_BOOLEAN_TRUE(tv) DUK_TVAL_SET_BOOLEAN((tv), 1) -#define DUK_TVAL_SET_BOOLEAN_FALSE(tv) DUK_TVAL_SET_BOOLEAN((tv), 0) +#define DUK_TVAL_SET_BOOLEAN_TRUE(tv) DUK_TVAL_SET_BOOLEAN((tv), 1) +#define DUK_TVAL_SET_BOOLEAN_FALSE(tv) DUK_TVAL_SET_BOOLEAN((tv), 0) -#define DUK_TVAL_STRING_IS_SYMBOL(tv) \ - DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING((tv))) +#define DUK_TVAL_STRING_IS_SYMBOL(tv) DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING((tv))) /* Lightfunc flags packing and unpacking. */ /* Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss##. * Avoid signed shifts due to portability limitations. */ -#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags) \ - ((duk_int32_t) (duk_int8_t) (((duk_uint16_t) (lf_flags)) >> 8)) -#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags) \ - (((lf_flags) >> 4) & 0x0fU) -#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags) \ - ((lf_flags) & 0x0fU) -#define DUK_LFUNC_FLAGS_PACK(magic,length,nargs) \ - ((((duk_small_uint_t) (magic)) & 0xffU) << 8) | ((length) << 4) | (nargs) - -#define DUK_LFUNC_NARGS_VARARGS 0x0f /* varargs marker */ -#define DUK_LFUNC_NARGS_MIN 0x00 -#define DUK_LFUNC_NARGS_MAX 0x0e /* max, excl. varargs marker */ -#define DUK_LFUNC_LENGTH_MIN 0x00 -#define DUK_LFUNC_LENGTH_MAX 0x0f -#define DUK_LFUNC_MAGIC_MIN (-0x80) -#define DUK_LFUNC_MAGIC_MAX 0x7f +#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags) ((duk_int32_t) (duk_int8_t) (((duk_uint16_t) (lf_flags)) >> 8)) +#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags) (((lf_flags) >> 4) & 0x0fU) +#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags) ((lf_flags) &0x0fU) +#define DUK_LFUNC_FLAGS_PACK(magic, length, nargs) ((((duk_small_uint_t) (magic)) & 0xffU) << 8) | ((length) << 4) | (nargs) + +#define DUK_LFUNC_NARGS_VARARGS 0x0f /* varargs marker */ +#define DUK_LFUNC_NARGS_MIN 0x00 +#define DUK_LFUNC_NARGS_MAX 0x0e /* max, excl. varargs marker */ +#define DUK_LFUNC_LENGTH_MIN 0x00 +#define DUK_LFUNC_LENGTH_MAX 0x0f +#define DUK_LFUNC_MAGIC_MIN (-0x80) +#define DUK_LFUNC_MAGIC_MAX 0x7f /* fastint constants etc */ #if defined(DUK_USE_FASTINT) -#define DUK_FASTINT_MIN (DUK_I64_CONSTANT(-0x800000000000)) -#define DUK_FASTINT_MAX (DUK_I64_CONSTANT(0x7fffffffffff)) -#define DUK_FASTINT_BITS 48 +#define DUK_FASTINT_MIN (DUK_I64_CONSTANT(-0x800000000000)) +#define DUK_FASTINT_MAX (DUK_I64_CONSTANT(0x7fffffffffff)) +#define DUK_FASTINT_BITS 48 DUK_INTERNAL_DECL void duk_tval_set_number_chkfast_fast(duk_tval *tv, duk_double_t x); DUK_INTERNAL_DECL void duk_tval_set_number_chkfast_slow(duk_tval *tv, duk_double_t x); @@ -631,9 +664,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_tval_assert_valid(duk_tval *tv); -#define DUK_TVAL_ASSERT_VALID(tv) do { duk_tval_assert_valid((tv)); } while (0) +#define DUK_TVAL_ASSERT_VALID(tv) \ + do { \ + duk_tval_assert_valid((tv)); \ + } while (0) #else -#define DUK_TVAL_ASSERT_VALID(tv) do {} while (0) +#define DUK_TVAL_ASSERT_VALID(tv) \ + do { \ + } while (0) #endif -#endif /* DUK_TVAL_H_INCLUDED */ +#endif /* DUK_TVAL_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_unicode.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_unicode.h
Changed
@@ -9,10 +9,10 @@ * UTF-8 / XUTF-8 / CESU-8 constants */ -#define DUK_UNICODE_MAX_XUTF8_LENGTH 7 /* up to 36 bit codepoints */ -#define DUK_UNICODE_MAX_XUTF8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ -#define DUK_UNICODE_MAX_CESU8_LENGTH 6 /* all codepoints up to U+10FFFF */ -#define DUK_UNICODE_MAX_CESU8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ +#define DUK_UNICODE_MAX_XUTF8_LENGTH 7 /* up to 36 bit codepoints */ +#define DUK_UNICODE_MAX_XUTF8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ +#define DUK_UNICODE_MAX_CESU8_LENGTH 6 /* all codepoints up to U+10FFFF */ +#define DUK_UNICODE_MAX_CESU8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ /* * Useful Unicode codepoints @@ -21,9 +21,11 @@ * in comparisons. */ -#define DUK_UNICODE_CP_ZWNJ 0x200cL /* zero-width non-joiner */ -#define DUK_UNICODE_CP_ZWJ 0x200dL /* zero-width joiner */ -#define DUK_UNICODE_CP_REPLACEMENT_CHARACTER 0xfffdL /* http://en.wikipedia.org/wiki/Replacement_character#Replacement_character */ +#define DUK_UNICODE_CP_ZWNJ 0x200cL /* zero-width non-joiner */ +#define DUK_UNICODE_CP_ZWJ 0x200dL /* zero-width joiner */ +#define DUK_UNICODE_CP_REPLACEMENT_CHARACTER \ + 0xfffdL /* http://en.wikipedia.org/wiki/Replacement_character#Replacement_character \ + */ /* * ASCII character constants @@ -36,134 +38,134 @@ * http://en.wikipedia.org/wiki/ASCII */ -#define DUK_ASC_NUL 0x00 -#define DUK_ASC_SOH 0x01 -#define DUK_ASC_STX 0x02 -#define DUK_ASC_ETX 0x03 -#define DUK_ASC_EOT 0x04 -#define DUK_ASC_ENQ 0x05 -#define DUK_ASC_ACK 0x06 -#define DUK_ASC_BEL 0x07 -#define DUK_ASC_BS 0x08 -#define DUK_ASC_HT 0x09 -#define DUK_ASC_LF 0x0a -#define DUK_ASC_VT 0x0b -#define DUK_ASC_FF 0x0c -#define DUK_ASC_CR 0x0d -#define DUK_ASC_SO 0x0e -#define DUK_ASC_SI 0x0f -#define DUK_ASC_DLE 0x10 -#define DUK_ASC_DC1 0x11 -#define DUK_ASC_DC2 0x12 -#define DUK_ASC_DC3 0x13 -#define DUK_ASC_DC4 0x14 -#define DUK_ASC_NAK 0x15 -#define DUK_ASC_SYN 0x16 -#define DUK_ASC_ETB 0x17 -#define DUK_ASC_CAN 0x18 -#define DUK_ASC_EM 0x19 -#define DUK_ASC_SUB 0x1a -#define DUK_ASC_ESC 0x1b -#define DUK_ASC_FS 0x1c -#define DUK_ASC_GS 0x1d -#define DUK_ASC_RS 0x1e -#define DUK_ASC_US 0x1f -#define DUK_ASC_SPACE 0x20 -#define DUK_ASC_EXCLAMATION 0x21 -#define DUK_ASC_DOUBLEQUOTE 0x22 -#define DUK_ASC_HASH 0x23 -#define DUK_ASC_DOLLAR 0x24 -#define DUK_ASC_PERCENT 0x25 -#define DUK_ASC_AMP 0x26 -#define DUK_ASC_SINGLEQUOTE 0x27 -#define DUK_ASC_LPAREN 0x28 -#define DUK_ASC_RPAREN 0x29 -#define DUK_ASC_STAR 0x2a -#define DUK_ASC_PLUS 0x2b -#define DUK_ASC_COMMA 0x2c -#define DUK_ASC_MINUS 0x2d -#define DUK_ASC_PERIOD 0x2e -#define DUK_ASC_SLASH 0x2f -#define DUK_ASC_0 0x30 -#define DUK_ASC_1 0x31 -#define DUK_ASC_2 0x32 -#define DUK_ASC_3 0x33 -#define DUK_ASC_4 0x34 -#define DUK_ASC_5 0x35 -#define DUK_ASC_6 0x36 -#define DUK_ASC_7 0x37 -#define DUK_ASC_8 0x38 -#define DUK_ASC_9 0x39 -#define DUK_ASC_COLON 0x3a -#define DUK_ASC_SEMICOLON 0x3b -#define DUK_ASC_LANGLE 0x3c -#define DUK_ASC_EQUALS 0x3d -#define DUK_ASC_RANGLE 0x3e -#define DUK_ASC_QUESTION 0x3f -#define DUK_ASC_ATSIGN 0x40 -#define DUK_ASC_UC_A 0x41 -#define DUK_ASC_UC_B 0x42 -#define DUK_ASC_UC_C 0x43 -#define DUK_ASC_UC_D 0x44 -#define DUK_ASC_UC_E 0x45 -#define DUK_ASC_UC_F 0x46 -#define DUK_ASC_UC_G 0x47 -#define DUK_ASC_UC_H 0x48 -#define DUK_ASC_UC_I 0x49 -#define DUK_ASC_UC_J 0x4a -#define DUK_ASC_UC_K 0x4b -#define DUK_ASC_UC_L 0x4c -#define DUK_ASC_UC_M 0x4d -#define DUK_ASC_UC_N 0x4e -#define DUK_ASC_UC_O 0x4f -#define DUK_ASC_UC_P 0x50 -#define DUK_ASC_UC_Q 0x51 -#define DUK_ASC_UC_R 0x52 -#define DUK_ASC_UC_S 0x53 -#define DUK_ASC_UC_T 0x54 -#define DUK_ASC_UC_U 0x55 -#define DUK_ASC_UC_V 0x56 -#define DUK_ASC_UC_W 0x57 -#define DUK_ASC_UC_X 0x58 -#define DUK_ASC_UC_Y 0x59 -#define DUK_ASC_UC_Z 0x5a -#define DUK_ASC_LBRACKET 0x5b -#define DUK_ASC_BACKSLASH 0x5c -#define DUK_ASC_RBRACKET 0x5d -#define DUK_ASC_CARET 0x5e -#define DUK_ASC_UNDERSCORE 0x5f -#define DUK_ASC_GRAVE 0x60 -#define DUK_ASC_LC_A 0x61 -#define DUK_ASC_LC_B 0x62 -#define DUK_ASC_LC_C 0x63 -#define DUK_ASC_LC_D 0x64 -#define DUK_ASC_LC_E 0x65 -#define DUK_ASC_LC_F 0x66 -#define DUK_ASC_LC_G 0x67 -#define DUK_ASC_LC_H 0x68 -#define DUK_ASC_LC_I 0x69 -#define DUK_ASC_LC_J 0x6a -#define DUK_ASC_LC_K 0x6b -#define DUK_ASC_LC_L 0x6c -#define DUK_ASC_LC_M 0x6d -#define DUK_ASC_LC_N 0x6e -#define DUK_ASC_LC_O 0x6f -#define DUK_ASC_LC_P 0x70 -#define DUK_ASC_LC_Q 0x71 -#define DUK_ASC_LC_R 0x72 -#define DUK_ASC_LC_S 0x73 -#define DUK_ASC_LC_T 0x74 -#define DUK_ASC_LC_U 0x75 -#define DUK_ASC_LC_V 0x76 -#define DUK_ASC_LC_W 0x77 -#define DUK_ASC_LC_X 0x78 -#define DUK_ASC_LC_Y 0x79 -#define DUK_ASC_LC_Z 0x7a -#define DUK_ASC_LCURLY 0x7b -#define DUK_ASC_PIPE 0x7c -#define DUK_ASC_RCURLY 0x7d -#define DUK_ASC_TILDE 0x7e -#define DUK_ASC_DEL 0x7f +#define DUK_ASC_NUL 0x00 +#define DUK_ASC_SOH 0x01 +#define DUK_ASC_STX 0x02 +#define DUK_ASC_ETX 0x03 +#define DUK_ASC_EOT 0x04 +#define DUK_ASC_ENQ 0x05 +#define DUK_ASC_ACK 0x06 +#define DUK_ASC_BEL 0x07 +#define DUK_ASC_BS 0x08 +#define DUK_ASC_HT 0x09 +#define DUK_ASC_LF 0x0a +#define DUK_ASC_VT 0x0b +#define DUK_ASC_FF 0x0c +#define DUK_ASC_CR 0x0d +#define DUK_ASC_SO 0x0e +#define DUK_ASC_SI 0x0f +#define DUK_ASC_DLE 0x10 +#define DUK_ASC_DC1 0x11 +#define DUK_ASC_DC2 0x12 +#define DUK_ASC_DC3 0x13 +#define DUK_ASC_DC4 0x14 +#define DUK_ASC_NAK 0x15 +#define DUK_ASC_SYN 0x16 +#define DUK_ASC_ETB 0x17 +#define DUK_ASC_CAN 0x18 +#define DUK_ASC_EM 0x19 +#define DUK_ASC_SUB 0x1a +#define DUK_ASC_ESC 0x1b +#define DUK_ASC_FS 0x1c +#define DUK_ASC_GS 0x1d +#define DUK_ASC_RS 0x1e +#define DUK_ASC_US 0x1f +#define DUK_ASC_SPACE 0x20 +#define DUK_ASC_EXCLAMATION 0x21 +#define DUK_ASC_DOUBLEQUOTE 0x22 +#define DUK_ASC_HASH 0x23 +#define DUK_ASC_DOLLAR 0x24 +#define DUK_ASC_PERCENT 0x25 +#define DUK_ASC_AMP 0x26 +#define DUK_ASC_SINGLEQUOTE 0x27 +#define DUK_ASC_LPAREN 0x28 +#define DUK_ASC_RPAREN 0x29 +#define DUK_ASC_STAR 0x2a +#define DUK_ASC_PLUS 0x2b +#define DUK_ASC_COMMA 0x2c +#define DUK_ASC_MINUS 0x2d +#define DUK_ASC_PERIOD 0x2e +#define DUK_ASC_SLASH 0x2f +#define DUK_ASC_0 0x30 +#define DUK_ASC_1 0x31 +#define DUK_ASC_2 0x32 +#define DUK_ASC_3 0x33 +#define DUK_ASC_4 0x34 +#define DUK_ASC_5 0x35 +#define DUK_ASC_6 0x36 +#define DUK_ASC_7 0x37 +#define DUK_ASC_8 0x38 +#define DUK_ASC_9 0x39 +#define DUK_ASC_COLON 0x3a +#define DUK_ASC_SEMICOLON 0x3b +#define DUK_ASC_LANGLE 0x3c +#define DUK_ASC_EQUALS 0x3d +#define DUK_ASC_RANGLE 0x3e +#define DUK_ASC_QUESTION 0x3f +#define DUK_ASC_ATSIGN 0x40 +#define DUK_ASC_UC_A 0x41 +#define DUK_ASC_UC_B 0x42 +#define DUK_ASC_UC_C 0x43 +#define DUK_ASC_UC_D 0x44 +#define DUK_ASC_UC_E 0x45 +#define DUK_ASC_UC_F 0x46 +#define DUK_ASC_UC_G 0x47 +#define DUK_ASC_UC_H 0x48 +#define DUK_ASC_UC_I 0x49 +#define DUK_ASC_UC_J 0x4a +#define DUK_ASC_UC_K 0x4b +#define DUK_ASC_UC_L 0x4c +#define DUK_ASC_UC_M 0x4d +#define DUK_ASC_UC_N 0x4e +#define DUK_ASC_UC_O 0x4f +#define DUK_ASC_UC_P 0x50 +#define DUK_ASC_UC_Q 0x51 +#define DUK_ASC_UC_R 0x52 +#define DUK_ASC_UC_S 0x53 +#define DUK_ASC_UC_T 0x54 +#define DUK_ASC_UC_U 0x55 +#define DUK_ASC_UC_V 0x56 +#define DUK_ASC_UC_W 0x57 +#define DUK_ASC_UC_X 0x58 +#define DUK_ASC_UC_Y 0x59 +#define DUK_ASC_UC_Z 0x5a +#define DUK_ASC_LBRACKET 0x5b +#define DUK_ASC_BACKSLASH 0x5c +#define DUK_ASC_RBRACKET 0x5d +#define DUK_ASC_CARET 0x5e +#define DUK_ASC_UNDERSCORE 0x5f +#define DUK_ASC_GRAVE 0x60 +#define DUK_ASC_LC_A 0x61 +#define DUK_ASC_LC_B 0x62 +#define DUK_ASC_LC_C 0x63 +#define DUK_ASC_LC_D 0x64 +#define DUK_ASC_LC_E 0x65 +#define DUK_ASC_LC_F 0x66 +#define DUK_ASC_LC_G 0x67 +#define DUK_ASC_LC_H 0x68 +#define DUK_ASC_LC_I 0x69 +#define DUK_ASC_LC_J 0x6a +#define DUK_ASC_LC_K 0x6b +#define DUK_ASC_LC_L 0x6c +#define DUK_ASC_LC_M 0x6d +#define DUK_ASC_LC_N 0x6e +#define DUK_ASC_LC_O 0x6f +#define DUK_ASC_LC_P 0x70 +#define DUK_ASC_LC_Q 0x71 +#define DUK_ASC_LC_R 0x72 +#define DUK_ASC_LC_S 0x73 +#define DUK_ASC_LC_T 0x74 +#define DUK_ASC_LC_U 0x75 +#define DUK_ASC_LC_V 0x76 +#define DUK_ASC_LC_W 0x77 +#define DUK_ASC_LC_X 0x78 +#define DUK_ASC_LC_Y 0x79 +#define DUK_ASC_LC_Z 0x7a +#define DUK_ASC_LCURLY 0x7b +#define DUK_ASC_PIPE 0x7c +#define DUK_ASC_RCURLY 0x7d +#define DUK_ASC_TILDE 0x7e +#define DUK_ASC_DEL 0x7f /* * Miscellaneous @@ -172,7 +174,7 @@ /* Uppercase A is 0x41, lowercase a is 0x61; OR 0x20 to convert uppercase * to lowercase. */ -#define DUK_LOWERCASE_CHAR_ASCII(x) ((x) | 0x20) +#define DUK_LOWERCASE_CHAR_ASCII(x) ((x) | 0x20) /* * Unicode tables @@ -220,7 +222,7 @@ DUK_INTERNAL_DECL const duk_uint16_t duk_unicode_re_ranges_not_white24; DUK_INTERNAL_DECL const duk_uint16_t duk_unicode_re_ranges_not_wordchar10; DUK_INTERNAL_DECL const duk_int8_t duk_is_idchar_tab128; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* * Prototypes @@ -232,8 +234,15 @@ #endif DUK_INTERNAL_DECL duk_small_int_t duk_unicode_encode_xutf8(duk_ucodepoint_t cp, duk_uint8_t *out); DUK_INTERNAL_DECL duk_small_int_t duk_unicode_encode_cesu8(duk_ucodepoint_t cp, duk_uint8_t *out); -DUK_INTERNAL_DECL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_ucodepoint_t *out_cp); -DUK_INTERNAL_DECL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end); +DUK_INTERNAL_DECL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_ucodepoint_t *out_cp); +DUK_INTERNAL_DECL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end); DUK_INTERNAL_DECL duk_size_t duk_unicode_unvalidated_utf8_length(const duk_uint8_t *data, duk_size_t blen); DUK_INTERNAL_DECL duk_bool_t duk_unicode_is_utf8_compatible(const duk_uint8_t *buf, duk_size_t len); DUK_INTERNAL_DECL duk_small_int_t duk_unicode_is_whitespace(duk_codepoint_t cp); @@ -247,4 +256,4 @@ DUK_INTERNAL_DECL duk_small_int_t duk_unicode_re_is_wordchar(duk_codepoint_t cp); #endif -#endif /* DUK_UNICODE_H_INCLUDED */ +#endif /* DUK_UNICODE_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_unicode_support.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_unicode_support.c
Changed
@@ -15,14 +15,14 @@ * 1: IdentifierStart and IdentifierPart * -1: IdentifierPart only */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00...0x0f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10...0x1f */ - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20...0x2f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, /* 0x30...0x3f */ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40...0x4f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50...0x5f */ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60...0x6f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70...0x7f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00...0x0f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10...0x1f */ + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20...0x2f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, /* 0x30...0x3f */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40...0x4f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50...0x5f */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60...0x6f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70...0x7f */ }; #endif @@ -72,15 +72,13 @@ /* Encoded as surrogate pair, each encoding to 3 bytes for * 6 bytes total. Codepoints above U+10FFFF encode as 6 bytes * too, see duk_unicode_encode_cesu8(). - */ + */ return 3 + 3; } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ -DUK_INTERNAL const duk_uint8_t duk_unicode_xutf8_markers7 = { - 0x00, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe -}; +DUK_INTERNAL const duk_uint8_t duk_unicode_xutf8_markers7 = { 0x00, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe }; /* Encode to extended UTF-8; 'out' must have space for at least * DUK_UNICODE_MAX_XUTF8_LENGTH bytes. Allows encoding of any @@ -95,7 +93,7 @@ len = duk_unicode_get_xutf8_length(cp); DUK_ASSERT(len > 0); - marker = duk_unicode_xutf8_markerslen - 1; /* 64-bit OK because always >= 0 */ + marker = duk_unicode_xutf8_markerslen - 1; /* 64-bit OK because always >= 0 */ i = len; DUK_ASSERT(i > 0); @@ -180,7 +178,11 @@ } /* Decode helper. Return zero on error. */ -DUK_INTERNAL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_ucodepoint_t *out_cp) { +DUK_INTERNAL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_ucodepoint_t *out_cp) { const duk_uint8_t *p; duk_uint32_t res; duk_uint_fast8_t ch; @@ -242,7 +244,7 @@ goto fail; } - DUK_ASSERT(p >= ptr_start); /* verified at beginning */ + DUK_ASSERT(p >= ptr_start); /* verified at beginning */ if (p + n > ptr_end) { /* check pointer at end */ goto fail; @@ -268,12 +270,15 @@ *out_cp = res; return 1; - fail: +fail: return 0; } /* used by e.g. duk_regexp_executor.c, string built-ins */ -DUK_INTERNAL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end) { +DUK_INTERNAL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end) { duk_ucodepoint_t cp; if (duk_unicode_decode_xutf8(thr, ptr, ptr_start, ptr_end, &cp)) { @@ -320,7 +325,7 @@ DUK_ASSERT(clen <= blen); return clen; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* This seems like a good overall approach. Fast path for ASCII in 4 byte * blocks. */ @@ -332,7 +337,7 @@ duk_size_t ncont; duk_size_t clen; - ncont = 0; /* number of continuation (non-initial) bytes in 0x80,0xbf */ + ncont = 0; /* number of continuation (non-initial) bytes in 0x80,0xbf */ p = data; p_end = data + blen; if (blen < 16) { @@ -357,7 +362,7 @@ duk_uint32_t x; x = *p32++; if (DUK_LIKELY((x & 0x80808080UL) == 0)) { - ; /* ASCII fast path */ + ; /* ASCII fast path */ } else { /* Flip highest bit of each byte which changes * the bit pattern 10xxxxxx into 00xxxxxx which @@ -381,7 +386,7 @@ p = (const duk_uint8_t *) p32; /* Fall through to handle the rest. */ - skip_fastpath: +skip_fastpath: while (p != p_end) { duk_uint8_t x; x = *p++; @@ -395,7 +400,7 @@ DUK_ASSERT(clen <= blen); return clen; } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Check whether a string is UTF-8 compatible or not. */ DUK_INTERNAL duk_bool_t duk_unicode_is_utf8_compatible(const duk_uint8_t *buf, duk_size_t len) { @@ -444,18 +449,18 @@ * 1111 0xxx + 3*CONT -> 0x10000, 0x10ffff */ left = len - i; - if (t <= 0xdfU) { /* 1101 1111 = 0xdf */ - if (t <= 0xbfU) { /* 1011 1111 = 0xbf */ + if (t <= 0xdfU) { /* 1101 1111 = 0xdf */ + if (t <= 0xbfU) { /* 1011 1111 = 0xbf */ return 0; } ncont = 1; mincp = 0x80UL; cp = t & 0x1fU; - } else if (t <= 0xefU) { /* 1110 1111 = 0xef */ + } else if (t <= 0xefU) { /* 1110 1111 = 0xef */ ncont = 2; mincp = 0x800UL; cp = t & 0x0fU; - } else if (t <= 0xf7U) { /* 1111 0111 = 0xf7 */ + } else if (t <= 0xf7U) { /* 1111 0111 = 0xf7 */ ncont = 3; mincp = 0x10000UL; cp = t & 0x07U; @@ -467,7 +472,7 @@ } while (ncont > 0U) { t = bufi++; - if ((t & 0xc0U) != 0x80U) { /* 10xx xxxx */ + if ((t & 0xc0U) != 0x80U) { /* 10xx xxxx */ return 0; } cp = (cp << 6) + (t & 0x3fU); @@ -533,7 +538,9 @@ /* r1,r2 is the range */ DUK_DDD(DUK_DDDPRINT("duk__uni_range_match: cp=%06lx range=0x%06lx,0x%06lx", - (unsigned long) cp, (unsigned long) r1, (unsigned long) r2)); + (unsigned long) cp, + (unsigned long) r1, + (unsigned long) r2)); if (cp >= r1 && cp <= r2) { return 1; } @@ -603,19 +610,17 @@ /* cp == -1 (EOF) never matches and causes return value 0 */ lo = (duk_uint_fast8_t) (cp & 0xff); - hi = (duk_uint_fast32_t) (cp >> 8); /* does not fit into an uchar */ + hi = (duk_uint_fast32_t) (cp >> 8); /* does not fit into an uchar */ if (hi == 0x0000UL) { - if (lo == 0x09U || lo == 0x0bU || lo == 0x0cU || - lo == 0x20U || lo == 0xa0U) { + if (lo == 0x09U || lo == 0x0bU || lo == 0x0cU || lo == 0x20U || lo == 0xa0U) { return 1; } } else if (hi == 0x0020UL) { if (lo <= 0x0aU || lo == 0x2fU || lo == 0x5fU) { return 1; } - } else if (cp == 0x1680L || cp == 0x180eL || cp == 0x3000L || - cp == 0xfeffL) { + } else if (cp == 0x1680L || cp == 0x180eL || cp == 0x3000L || cp == 0xfeffL) { return 1; } @@ -634,8 +639,7 @@ * into a single line terminator. This must be handled by the caller. */ - if (cp == 0x000aL || cp == 0x000dL || cp == 0x2028L || - cp == 0x2029L) { + if (cp == 0x000aL || cp == 0x000dL || cp == 0x2028L || cp == 0x2029L) { return 1; } @@ -686,9 +690,7 @@ #if defined(DUK_USE_IDCHAR_FASTPATH) return (cp >= 0) && (duk_is_idchar_tabcp > 0); #else - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z') || - cp == '_' || cp == '$') { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || cp == '_' || cp == '$') { return 1; } return 0; @@ -698,17 +700,13 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - (duk_size_t) sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, (duk_size_t) sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp)) { return 1; } return 0; @@ -775,10 +773,7 @@ #if defined(DUK_USE_IDCHAR_FASTPATH) return (cp >= 0) && (duk_is_idchar_tabcp != 0); #else - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z') || - (cp >= '0' && cp <= '9') || - cp == '_' || cp == '$') { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || (cp >= '0' && cp <= '9') || cp == '_' || cp == '$') { return 1; } return 0; @@ -788,20 +783,14 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp) || - duk__uni_range_match(duk_unicode_idp_m_ids_noa, - sizeof(duk_unicode_idp_m_ids_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp) || + duk__uni_range_match(duk_unicode_idp_m_ids_noa, sizeof(duk_unicode_idp_m_ids_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp) || + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp) || duk__uni_range_match(duk_unicode_idp_m_ids_noabmp, sizeof(duk_unicode_idp_m_ids_noabmp), (duk_codepoint_t) cp)) { @@ -837,8 +826,7 @@ /* ASCII (and EOF) fast path -- quick accept and reject */ if (cp <= 0x7fL) { - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z')) { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z')) { return 1; } return 0; @@ -847,20 +835,14 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp) && - !duk__uni_range_match(duk_unicode_ids_m_let_noa, - sizeof(duk_unicode_ids_m_let_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp) && + !duk__uni_range_match(duk_unicode_ids_m_let_noa, sizeof(duk_unicode_ids_m_let_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp) && + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp) && !duk__uni_range_match(duk_unicode_ids_m_let_noabmp, sizeof(duk_unicode_ids_m_let_noabmp), (duk_codepoint_t) cp)) { @@ -897,10 +879,7 @@ */ DUK_LOCAL -duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr, - duk_bufwriter_ctx *bw, - duk_codepoint_t cp, - duk_bitdecoder_ctx *bd_ctx) { +duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_codepoint_t cp, duk_bitdecoder_ctx *bd_ctx) { duk_small_int_t skip = 0; duk_small_int_t n; duk_small_int_t t; @@ -930,10 +909,13 @@ start_o = (duk_codepoint_t) duk_bd_decode(bd_ctx, 16); count = (duk_small_int_t) duk_bd_decode(bd_ctx, 7); DUK_DDD(DUK_DDDPRINT("range: start_i=%ld, start_o=%ld, count=%ld, skip=%ld", - (long) start_i, (long) start_o, (long) count, (long) skip)); + (long) start_i, + (long) start_o, + (long) count, + (long) skip)); if (cp >= start_i) { - tmp_cp = cp - start_i; /* always >= 0 */ + tmp_cp = cp - start_i; /* always >= 0 */ if (tmp_cp < (duk_codepoint_t) count * (duk_codepoint_t) skip && (tmp_cp % (duk_codepoint_t) skip) == 0) { DUK_DDD(DUK_DDDPRINT("range matches input codepoint")); @@ -985,7 +967,7 @@ DUK_DDD(DUK_DDDPRINT("no rule matches, output is same as input")); /* fall through */ - single: +single: if (bw != NULL) { DUK_BW_WRITE_RAW_XUTF8(thr, bw, (duk_ucodepoint_t) cp); } @@ -1047,9 +1029,9 @@ * The rule is not locale/language specific so it is supported. */ - if (cp == 0x03a3L && /* U+03A3 = GREEK CAPITAL LETTER SIGMA */ - duk_unicode_is_letter(prev) && /* prev exists and is not a letter */ - !duk_unicode_is_letter(next)) { /* next does not exist or next is not a letter */ + if (cp == 0x03a3L && /* U+03A3 = GREEK CAPITAL LETTER SIGMA */ + duk_unicode_is_letter(prev) && /* prev exists and is not a letter */ + !duk_unicode_is_letter(next)) { /* next does not exist or next is not a letter */ /* Capital sigma occurred at "end of word", lowercase to * U+03C2 = GREEK SMALL LETTER FINAL SIGMA. Otherwise * fall through and let the normal rules lowercase it to @@ -1075,13 +1057,13 @@ } return duk__slow_case_conversion(thr, bw, cp, &bd_ctx); - singlechar: +singlechar: if (bw != NULL) { DUK_BW_WRITE_RAW_XUTF8(thr, bw, (duk_ucodepoint_t) cp); } return cp; - /* unused now, not needed until Turkish/Azeri */ + /* unused now, not needed until Turkish/Azeri */ #if 0 nochar: return -1; @@ -1099,7 +1081,7 @@ const duk_uint8_t *p, *p_start, *p_end; duk_codepoint_t prev, curr, next; - h_input = duk_require_hstring(thr, -1); /* Accept symbols. */ + h_input = duk_require_hstring(thr, -1); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; @@ -1111,7 +1093,8 @@ p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); p = p_start; - prev = -1; DUK_UNREF(prev); + prev = -1; + DUK_UNREF(prev); curr = -1; next = -1; for (;;) { @@ -1136,17 +1119,12 @@ /* Ensure space for maximum multi-character result; estimate is overkill. */ DUK_BW_ENSURE(thr, bw, 8 * DUK_UNICODE_MAX_XUTF8_LENGTH); - duk__case_transform_helper(thr, - bw, - (duk_codepoint_t) curr, - prev, - next, - uppercase); + duk__case_transform_helper(thr, bw, (duk_codepoint_t) curr, prev, next, uppercase); } } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, output is encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, output is encoded. */ /* invalidates h_buf pointer */ duk_remove_m2(thr); } @@ -1169,15 +1147,15 @@ return (duk_codepoint_t) duk_unicode_re_canon_lookupcp; } return cp; -#else /* DUK_USE_REGEXP_CANON_WORKAROUND */ +#else /* DUK_USE_REGEXP_CANON_WORKAROUND */ duk_codepoint_t y; y = duk__case_transform_helper(thr, - NULL, /* NULL is allowed, no output */ - cp, /* curr char */ - -1, /* prev char */ - -1, /* next char */ - 1); /* uppercase */ + NULL, /* NULL is allowed, no output */ + cp, /* curr char */ + -1, /* prev char */ + -1, /* next char */ + 1); /* uppercase */ if ((y < 0) || (cp >= 0x80 && y < 0x80)) { /* multiple codepoint conversion or non-ASCII mapped to ASCII @@ -1187,7 +1165,7 @@ } return y; -#endif /* DUK_USE_REGEXP_CANON_WORKAROUND */ +#endif /* DUK_USE_REGEXP_CANON_WORKAROUND */ } /* @@ -1200,10 +1178,7 @@ * Note: the description in E5 Section 15.10.2.6 has a typo, it * contains 'A' twice and lacks 'a'; the intent is 0-9a-zA-Z_. */ - if ((x >= '0' && x <= '9') || - (x >= 'a' && x <= 'z') || - (x >= 'A' && x <= 'Z') || - (x == '_')) { + if ((x >= '0' && x <= '9') || (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z') || (x == '_')) { return 1; } return 0; @@ -1215,51 +1190,36 @@ /* exposed because lexer needs these too */ DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_digit2 = { - (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, + (duk_uint16_t) 0x0030UL, + (duk_uint16_t) 0x0039UL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_white22 = { - (duk_uint16_t) 0x0009UL, (duk_uint16_t) 0x000DUL, - (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x0020UL, - (duk_uint16_t) 0x00A0UL, (duk_uint16_t) 0x00A0UL, - (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x1680UL, - (duk_uint16_t) 0x180EUL, (duk_uint16_t) 0x180EUL, - (duk_uint16_t) 0x2000UL, (duk_uint16_t) 0x200AUL, - (duk_uint16_t) 0x2028UL, (duk_uint16_t) 0x2029UL, - (duk_uint16_t) 0x202FUL, (duk_uint16_t) 0x202FUL, - (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x205FUL, - (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0x3000UL, + (duk_uint16_t) 0x0009UL, (duk_uint16_t) 0x000DUL, (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x00A0UL, + (duk_uint16_t) 0x00A0UL, (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x180EUL, (duk_uint16_t) 0x180EUL, + (duk_uint16_t) 0x2000UL, (duk_uint16_t) 0x200AUL, (duk_uint16_t) 0x2028UL, (duk_uint16_t) 0x2029UL, (duk_uint16_t) 0x202FUL, + (duk_uint16_t) 0x202FUL, (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0xFEFFUL, (duk_uint16_t) 0xFEFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_wordchar8 = { - (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, - (duk_uint16_t) 0x0041UL, (duk_uint16_t) 0x005AUL, - (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x005FUL, - (duk_uint16_t) 0x0061UL, (duk_uint16_t) 0x007AUL, + (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, (duk_uint16_t) 0x0041UL, (duk_uint16_t) 0x005AUL, + (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x0061UL, (duk_uint16_t) 0x007AUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_digit4 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, - (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, + (duk_uint16_t) 0x002FUL, + (duk_uint16_t) 0x003AUL, + (duk_uint16_t) 0xFFFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_white24 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x0008UL, - (duk_uint16_t) 0x000EUL, (duk_uint16_t) 0x001FUL, - (duk_uint16_t) 0x0021UL, (duk_uint16_t) 0x009FUL, - (duk_uint16_t) 0x00A1UL, (duk_uint16_t) 0x167FUL, - (duk_uint16_t) 0x1681UL, (duk_uint16_t) 0x180DUL, - (duk_uint16_t) 0x180FUL, (duk_uint16_t) 0x1FFFUL, - (duk_uint16_t) 0x200BUL, (duk_uint16_t) 0x2027UL, - (duk_uint16_t) 0x202AUL, (duk_uint16_t) 0x202EUL, - (duk_uint16_t) 0x2030UL, (duk_uint16_t) 0x205EUL, - (duk_uint16_t) 0x2060UL, (duk_uint16_t) 0x2FFFUL, - (duk_uint16_t) 0x3001UL, (duk_uint16_t) 0xFEFEUL, - (duk_uint16_t) 0xFF00UL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x0008UL, (duk_uint16_t) 0x000EUL, (duk_uint16_t) 0x001FUL, (duk_uint16_t) 0x0021UL, + (duk_uint16_t) 0x009FUL, (duk_uint16_t) 0x00A1UL, (duk_uint16_t) 0x167FUL, (duk_uint16_t) 0x1681UL, (duk_uint16_t) 0x180DUL, + (duk_uint16_t) 0x180FUL, (duk_uint16_t) 0x1FFFUL, (duk_uint16_t) 0x200BUL, (duk_uint16_t) 0x2027UL, (duk_uint16_t) 0x202AUL, + (duk_uint16_t) 0x202EUL, (duk_uint16_t) 0x2030UL, (duk_uint16_t) 0x205EUL, (duk_uint16_t) 0x2060UL, (duk_uint16_t) 0x2FFFUL, + (duk_uint16_t) 0x3001UL, (duk_uint16_t) 0xFEFEUL, (duk_uint16_t) 0xFF00UL, (duk_uint16_t) 0xFFFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_wordchar10 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, - (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0x0040UL, - (duk_uint16_t) 0x005BUL, (duk_uint16_t) 0x005EUL, - (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x0060UL, - (duk_uint16_t) 0x007BUL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0x0040UL, (duk_uint16_t) 0x005BUL, + (duk_uint16_t) 0x005EUL, (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x007BUL, (duk_uint16_t) 0xFFFFUL, }; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_util.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_util.h
Changed
@@ -5,20 +5,14 @@ #if !defined(DUK_UTIL_H_INCLUDED) #define DUK_UTIL_H_INCLUDED -#if defined(DUK_USE_GET_RANDOM_DOUBLE) -#define DUK_UTIL_GET_RANDOM_DOUBLE(thr) DUK_USE_GET_RANDOM_DOUBLE((thr)->heap_udata) -#else -#define DUK_UTIL_GET_RANDOM_DOUBLE(thr) duk_util_tinyrandom_get_double(thr) -#endif - /* * Some useful constants */ -#define DUK_DOUBLE_2TO32 4294967296.0 -#define DUK_DOUBLE_2TO31 2147483648.0 -#define DUK_DOUBLE_LOG2E 1.4426950408889634 -#define DUK_DOUBLE_LOG10E 0.4342944819032518 +#define DUK_DOUBLE_2TO32 4294967296.0 +#define DUK_DOUBLE_2TO31 2147483648.0 +#define DUK_DOUBLE_LOG2E 1.4426950408889634 +#define DUK_DOUBLE_LOG10E 0.4342944819032518 /* * Endian conversion @@ -71,33 +65,35 @@ * update the pointer argument automatically. */ -#define DUK_RAW_WRITE_U8(ptr,val) do { \ +#define DUK_RAW_WRITE_U8(ptr, val) \ + do { \ *(ptr) = (duk_uint8_t) (val); \ } while (0) -#define DUK_RAW_WRITE_U16_BE(ptr,val) duk_raw_write_u16_be((ptr), (duk_uint16_t) (val)) -#define DUK_RAW_WRITE_U32_BE(ptr,val) duk_raw_write_u32_be((ptr), (duk_uint32_t) (val)) -#define DUK_RAW_WRITE_FLOAT_BE(ptr,val) duk_raw_write_float_be((ptr), (duk_float_t) (val)) -#define DUK_RAW_WRITE_DOUBLE_BE(ptr,val) duk_raw_write_double_be((ptr), (duk_double_t) (val)) -#define DUK_RAW_WRITE_XUTF8(ptr,val) duk_raw_write_xutf8((ptr), (duk_ucodepoint_t) (val)) +#define DUK_RAW_WRITE_U16_BE(ptr, val) duk_raw_write_u16_be((ptr), (duk_uint16_t) (val)) +#define DUK_RAW_WRITE_U32_BE(ptr, val) duk_raw_write_u32_be((ptr), (duk_uint32_t) (val)) +#define DUK_RAW_WRITE_FLOAT_BE(ptr, val) duk_raw_write_float_be((ptr), (duk_float_t) (val)) +#define DUK_RAW_WRITE_DOUBLE_BE(ptr, val) duk_raw_write_double_be((ptr), (duk_double_t) (val)) +#define DUK_RAW_WRITE_XUTF8(ptr, val) duk_raw_write_xutf8((ptr), (duk_ucodepoint_t) (val)) -#define DUK_RAW_WRITEINC_U8(ptr,val) do { \ +#define DUK_RAW_WRITEINC_U8(ptr, val) \ + do { \ *(ptr)++ = (duk_uint8_t) (val); \ } while (0) -#define DUK_RAW_WRITEINC_U16_BE(ptr,val) duk_raw_writeinc_u16_be(&(ptr), (duk_uint16_t) (val)) -#define DUK_RAW_WRITEINC_U32_BE(ptr,val) duk_raw_writeinc_u32_be(&(ptr), (duk_uint32_t) (val)) -#define DUK_RAW_WRITEINC_FLOAT_BE(ptr,val) duk_raw_writeinc_float_be(&(ptr), (duk_float_t) (val)) -#define DUK_RAW_WRITEINC_DOUBLE_BE(ptr,val) duk_raw_writeinc_double_be(&(ptr), (duk_double_t) (val)) -#define DUK_RAW_WRITEINC_XUTF8(ptr,val) duk_raw_writeinc_xutf8(&(ptr), (duk_ucodepoint_t) (val)) -#define DUK_RAW_WRITEINC_CESU8(ptr,val) duk_raw_writeinc_cesu8(&(ptr), (duk_ucodepoint_t) (val)) +#define DUK_RAW_WRITEINC_U16_BE(ptr, val) duk_raw_writeinc_u16_be(&(ptr), (duk_uint16_t) (val)) +#define DUK_RAW_WRITEINC_U32_BE(ptr, val) duk_raw_writeinc_u32_be(&(ptr), (duk_uint32_t) (val)) +#define DUK_RAW_WRITEINC_FLOAT_BE(ptr, val) duk_raw_writeinc_float_be(&(ptr), (duk_float_t) (val)) +#define DUK_RAW_WRITEINC_DOUBLE_BE(ptr, val) duk_raw_writeinc_double_be(&(ptr), (duk_double_t) (val)) +#define DUK_RAW_WRITEINC_XUTF8(ptr, val) duk_raw_writeinc_xutf8(&(ptr), (duk_ucodepoint_t) (val)) +#define DUK_RAW_WRITEINC_CESU8(ptr, val) duk_raw_writeinc_cesu8(&(ptr), (duk_ucodepoint_t) (val)) -#define DUK_RAW_READ_U8(ptr) ((duk_uint8_t) (*(ptr))) -#define DUK_RAW_READ_U16_BE(ptr) duk_raw_read_u16_be((ptr)); -#define DUK_RAW_READ_U32_BE(ptr) duk_raw_read_u32_be((ptr)); +#define DUK_RAW_READ_U8(ptr) ((duk_uint8_t) (*(ptr))) +#define DUK_RAW_READ_U16_BE(ptr) duk_raw_read_u16_be((ptr)); +#define DUK_RAW_READ_U32_BE(ptr) duk_raw_read_u32_be((ptr)); #define DUK_RAW_READ_DOUBLE_BE(ptr) duk_raw_read_double_be((ptr)); -#define DUK_RAW_READINC_U8(ptr) ((duk_uint8_t) (*(ptr)++)) -#define DUK_RAW_READINC_U16_BE(ptr) duk_raw_readinc_u16_be(&(ptr)); -#define DUK_RAW_READINC_U32_BE(ptr) duk_raw_readinc_u32_be(&(ptr)); +#define DUK_RAW_READINC_U8(ptr) ((duk_uint8_t) (*(ptr)++)) +#define DUK_RAW_READINC_U16_BE(ptr) duk_raw_readinc_u16_be(&(ptr)); +#define DUK_RAW_READINC_U32_BE(ptr) duk_raw_readinc_u32_be(&(ptr)); #define DUK_RAW_READINC_DOUBLE_BE(ptr) duk_raw_readinc_double_be(&(ptr)); /* @@ -144,29 +140,31 @@ }; #if defined(DUK_USE_PREFER_SIZE) -#define DUK_BW_SLACK_ADD 64 -#define DUK_BW_SLACK_SHIFT 4 /* 2^4 -> 1/16 = 6.25% slack */ +#define DUK_BW_SLACK_ADD 64 +#define DUK_BW_SLACK_SHIFT 4 /* 2^4 -> 1/16 = 6.25% slack */ #else -#define DUK_BW_SLACK_ADD 64 -#define DUK_BW_SLACK_SHIFT 2 /* 2^2 -> 1/4 = 25% slack */ +#define DUK_BW_SLACK_ADD 64 +#define DUK_BW_SLACK_SHIFT 2 /* 2^2 -> 1/4 = 25% slack */ #endif /* Initialization and finalization (compaction), converting to other types. */ -#define DUK_BW_INIT_PUSHBUF(thr,bw_ctx,sz) do { \ +#define DUK_BW_INIT_PUSHBUF(thr, bw_ctx, sz) \ + do { \ duk_bw_init_pushbuf((thr), (bw_ctx), (sz)); \ } while (0) -#define DUK_BW_INIT_WITHBUF(thr,bw_ctx,buf) do { \ +#define DUK_BW_INIT_WITHBUF(thr, bw_ctx, buf) \ + do { \ duk_bw_init((thr), (bw_ctx), (buf)); \ } while (0) -#define DUK_BW_COMPACT(thr,bw_ctx) do { \ +#define DUK_BW_COMPACT(thr, bw_ctx) \ + do { \ /* Make underlying buffer compact to match DUK_BW_GET_SIZE(). */ \ duk_bw_compact((thr), (bw_ctx)); \ } while (0) -#define DUK_BW_PUSH_AS_STRING(thr,bw_ctx) do { \ - duk_push_lstring((thr), \ - (const char *) (bw_ctx)->p_base, \ - (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ +#define DUK_BW_PUSH_AS_STRING(thr, bw_ctx) \ + do { \ + duk_push_lstring((thr), (const char *) (bw_ctx)->p_base, (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ } while (0) /* Pointers may be NULL for a while when 'buf' size is zero and before any @@ -176,43 +174,48 @@ */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_bw_assert_valid(duk_hthread *thr, duk_bufwriter_ctx *bw_ctx); -#define DUK_BW_ASSERT_VALID_EXPR(thr,bw_ctx) (duk_bw_assert_valid((thr), (bw_ctx))) -#define DUK_BW_ASSERT_VALID(thr,bw_ctx) do { duk_bw_assert_valid((thr), (bw_ctx)); } while (0) +#define DUK_BW_ASSERT_VALID_EXPR(thr, bw_ctx) (duk_bw_assert_valid((thr), (bw_ctx))) +#define DUK_BW_ASSERT_VALID(thr, bw_ctx) \ + do { \ + duk_bw_assert_valid((thr), (bw_ctx)); \ + } while (0) #else -#define DUK_BW_ASSERT_VALID_EXPR(thr,bw_ctx) DUK_ASSERT_EXPR(1) -#define DUK_BW_ASSERT_VALID(thr,bw_ctx) do {} while (0) +#define DUK_BW_ASSERT_VALID_EXPR(thr, bw_ctx) DUK_ASSERT_EXPR(1) +#define DUK_BW_ASSERT_VALID(thr, bw_ctx) \ + do { \ + } while (0) #endif /* Working with the pointer and current size. */ -#define DUK_BW_GET_PTR(thr,bw_ctx) \ - ((bw_ctx)->p) -#define DUK_BW_SET_PTR(thr,bw_ctx,ptr) do { \ +#define DUK_BW_GET_PTR(thr, bw_ctx) ((bw_ctx)->p) +#define DUK_BW_SET_PTR(thr, bw_ctx, ptr) \ + do { \ (bw_ctx)->p = (ptr); \ } while (0) -#define DUK_BW_ADD_PTR(thr,bw_ctx,delta) do { \ +#define DUK_BW_ADD_PTR(thr, bw_ctx, delta) \ + do { \ (bw_ctx)->p += (delta); \ } while (0) -#define DUK_BW_GET_BASEPTR(thr,bw_ctx) \ - ((bw_ctx)->p_base) -#define DUK_BW_GET_LIMITPTR(thr,bw_ctx) \ - ((bw_ctx)->p_limit) -#define DUK_BW_GET_SIZE(thr,bw_ctx) \ - ((duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)) -#define DUK_BW_SET_SIZE(thr,bw_ctx,sz) do { \ +#define DUK_BW_GET_BASEPTR(thr, bw_ctx) ((bw_ctx)->p_base) +#define DUK_BW_GET_LIMITPTR(thr, bw_ctx) ((bw_ctx)->p_limit) +#define DUK_BW_GET_SIZE(thr, bw_ctx) ((duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)) +#define DUK_BW_SET_SIZE(thr, bw_ctx, sz) \ + do { \ DUK_ASSERT((duk_size_t) (sz) <= (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ (bw_ctx)->p = (bw_ctx)->p_base + (sz); \ } while (0) -#define DUK_BW_RESET_SIZE(thr,bw_ctx) do { \ +#define DUK_BW_RESET_SIZE(thr, bw_ctx) \ + do { \ /* Reset to zero size, keep current limit. */ \ (bw_ctx)->p = (bw_ctx)->p_base; \ } while (0) -#define DUK_BW_GET_BUFFER(thr,bw_ctx) \ - ((bw_ctx)->buf) +#define DUK_BW_GET_BUFFER(thr, bw_ctx) ((bw_ctx)->buf) /* Ensuring (reserving) space. */ -#define DUK_BW_ENSURE(thr,bw_ctx,sz) do { \ +#define DUK_BW_ENSURE(thr, bw_ctx, sz) \ + do { \ duk_size_t duk__sz, duk__space; \ DUK_BW_ASSERT_VALID((thr), (bw_ctx)); \ duk__sz = (sz); \ @@ -223,22 +226,21 @@ } while (0) /* NOTE: Multiple evaluation of 'ptr' in this macro. */ /* XXX: Rework to use an always-inline function? */ -#define DUK_BW_ENSURE_RAW(thr,bw_ctx,sz,ptr) \ - (((duk_size_t) ((bw_ctx)->p_limit - (ptr)) >= (sz)) ? \ - (ptr) : \ - ((bw_ctx)->p = (ptr), duk_bw_resize((thr),(bw_ctx),(sz)))) -#define DUK_BW_ENSURE_GETPTR(thr,bw_ctx,sz) \ - DUK_BW_ENSURE_RAW((thr), (bw_ctx), (sz), (bw_ctx)->p) -#define DUK_BW_ASSERT_SPACE_EXPR(thr,bw_ctx,sz) \ +#define DUK_BW_ENSURE_RAW(thr, bw_ctx, sz, ptr) \ + (((duk_size_t) ((bw_ctx)->p_limit - (ptr)) >= (sz)) ? (ptr) : ((bw_ctx)->p = (ptr), duk_bw_resize((thr), (bw_ctx), (sz)))) +#define DUK_BW_ENSURE_GETPTR(thr, bw_ctx, sz) DUK_BW_ENSURE_RAW((thr), (bw_ctx), (sz), (bw_ctx)->p) +#define DUK_BW_ASSERT_SPACE_EXPR(thr, bw_ctx, sz) \ (DUK_BW_ASSERT_VALID_EXPR((thr), (bw_ctx)), \ DUK_ASSERT_EXPR((duk_size_t) ((bw_ctx)->p_limit - (bw_ctx)->p) >= (duk_size_t) (sz))) -#define DUK_BW_ASSERT_SPACE(thr,bw_ctx,sz) do { \ +#define DUK_BW_ASSERT_SPACE(thr, bw_ctx, sz) \ + do { \ DUK_BW_ASSERT_SPACE_EXPR((thr), (bw_ctx), (sz)); \ } while (0) /* Miscellaneous. */ -#define DUK_BW_SETPTR_AND_COMPACT(thr,bw_ctx,ptr) do { \ +#define DUK_BW_SETPTR_AND_COMPACT(thr, bw_ctx, ptr) \ + do { \ (bw_ctx)->p = (ptr); \ duk_bw_compact((thr), (bw_ctx)); \ } while (0) @@ -249,11 +251,13 @@ * explicit pointer load/stores get generated (e.g. gcc -Os). */ -#define DUK_BW_WRITE_RAW_U8(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_U8(thr, bw_ctx, val) \ + do { \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 1); \ *(bw_ctx)->p++ = (duk_uint8_t) (val); \ } while (0) -#define DUK_BW_WRITE_RAW_U8_2(thr,bw_ctx,val1,val2) do { \ +#define DUK_BW_WRITE_RAW_U8_2(thr, bw_ctx, val1, val2) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 2); \ duk__p = (bw_ctx)->p; \ @@ -261,7 +265,8 @@ *duk__p++ = (duk_uint8_t) (val2); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_3(thr,bw_ctx,val1,val2,val3) do { \ +#define DUK_BW_WRITE_RAW_U8_3(thr, bw_ctx, val1, val2, val3) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 3); \ duk__p = (bw_ctx)->p; \ @@ -270,7 +275,8 @@ *duk__p++ = (duk_uint8_t) (val3); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_4(thr,bw_ctx,val1,val2,val3,val4) do { \ +#define DUK_BW_WRITE_RAW_U8_4(thr, bw_ctx, val1, val2, val3, val4) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 4); \ duk__p = (bw_ctx)->p; \ @@ -280,7 +286,8 @@ *duk__p++ = (duk_uint8_t) (val4); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_5(thr,bw_ctx,val1,val2,val3,val4,val5) do { \ +#define DUK_BW_WRITE_RAW_U8_5(thr, bw_ctx, val1, val2, val3, val4, val5) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 5); \ duk__p = (bw_ctx)->p; \ @@ -291,7 +298,8 @@ *duk__p++ = (duk_uint8_t) (val5); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_6(thr,bw_ctx,val1,val2,val3,val4,val5,val6) do { \ +#define DUK_BW_WRITE_RAW_U8_6(thr, bw_ctx, val1, val2, val3, val4, val5, val6) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 6); \ duk__p = (bw_ctx)->p; \ @@ -303,7 +311,8 @@ *duk__p++ = (duk_uint8_t) (val6); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_XUTF8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_RAW_XUTF8(thr, bw_ctx, cp) \ + do { \ duk_ucodepoint_t duk__cp; \ duk_small_int_t duk__enc_len; \ duk__cp = (duk_ucodepoint_t) (cp); \ @@ -311,7 +320,8 @@ duk__enc_len = duk_unicode_encode_xutf8(duk__cp, (bw_ctx)->p); \ (bw_ctx)->p += duk__enc_len; \ } while (0) -#define DUK_BW_WRITE_RAW_CESU8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_RAW_CESU8(thr, bw_ctx, cp) \ + do { \ duk_ucodepoint_t duk__cp; \ duk_small_int_t duk__enc_len; \ duk__cp = (duk_ucodepoint_t) (cp); \ @@ -321,7 +331,8 @@ } while (0) /* XXX: add temporary duk__p pointer here too; sharing */ /* XXX: avoid unsafe variants */ -#define DUK_BW_WRITE_RAW_BYTES(thr,bw_ctx,valptr,valsz) do { \ +#define DUK_BW_WRITE_RAW_BYTES(thr, bw_ctx, valptr, valsz) \ + do { \ const void *duk__valptr; \ duk_size_t duk__valsz; \ duk__valptr = (const void *) (valptr); \ @@ -329,7 +340,8 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), duk__valptr, duk__valsz); \ (bw_ctx)->p += duk__valsz; \ } while (0) -#define DUK_BW_WRITE_RAW_CSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_CSTRING(thr, bw_ctx, val) \ + do { \ const duk_uint8_t *duk__val; \ duk_size_t duk__val_len; \ duk__val = (const duk_uint8_t *) (val); \ @@ -337,93 +349,107 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) duk__val, duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HSTRING(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HSTRING_GET_BYTELEN((val)); \ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HSTRING_GET_DATA((val)), duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER_FIXED(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER_FIXED(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_FIXED_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER_DYNAMIC(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER_DYNAMIC(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_DYNAMIC_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) /* Append bytes from a slice already in the buffer. */ -#define DUK_BW_WRITE_RAW_SLICE(thr,bw,dst_off,dst_len) \ - duk_bw_write_raw_slice((thr), (bw), (dst_off), (dst_len)) +#define DUK_BW_WRITE_RAW_SLICE(thr, bw, dst_off, dst_len) duk_bw_write_raw_slice((thr), (bw), (dst_off), (dst_len)) /* Insert bytes in the middle of the buffer from an external buffer. */ -#define DUK_BW_INSERT_RAW_BYTES(thr,bw,dst_off,buf,len) \ - duk_bw_insert_raw_bytes((thr), (bw), (dst_off), (buf), (len)) +#define DUK_BW_INSERT_RAW_BYTES(thr, bw, dst_off, buf, len) duk_bw_insert_raw_bytes((thr), (bw), (dst_off), (buf), (len)) /* Insert bytes in the middle of the buffer from a slice already * in the buffer. Source offset is interpreted "before" the operation. */ -#define DUK_BW_INSERT_RAW_SLICE(thr,bw,dst_off,src_off,len) \ - duk_bw_insert_raw_slice((thr), (bw), (dst_off), (src_off), (len)) +#define DUK_BW_INSERT_RAW_SLICE(thr, bw, dst_off, src_off, len) duk_bw_insert_raw_slice((thr), (bw), (dst_off), (src_off), (len)) /* Insert a reserved area somewhere in the buffer; caller fills it. * Evaluates to a (duk_uint_t *) pointing to the start of the reserved * area for convenience. */ -#define DUK_BW_INSERT_RAW_AREA(thr,bw,off,len) \ - duk_bw_insert_raw_area((thr), (bw), (off), (len)) +#define DUK_BW_INSERT_RAW_AREA(thr, bw, off, len) duk_bw_insert_raw_area((thr), (bw), (off), (len)) /* Remove a slice from inside buffer. */ -#define DUK_BW_REMOVE_RAW_SLICE(thr,bw,off,len) \ - duk_bw_remove_raw_slice((thr), (bw), (off), (len)) +#define DUK_BW_REMOVE_RAW_SLICE(thr, bw, off, len) duk_bw_remove_raw_slice((thr), (bw), (off), (len)) /* Safe write calls which will ensure space first. */ -#define DUK_BW_WRITE_ENSURE_U8(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_U8(thr, bw_ctx, val) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 1); \ DUK_BW_WRITE_RAW_U8((thr), (bw_ctx), (val)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_2(thr,bw_ctx,val1,val2) do { \ +#define DUK_BW_WRITE_ENSURE_U8_2(thr, bw_ctx, val1, val2) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 2); \ DUK_BW_WRITE_RAW_U8_2((thr), (bw_ctx), (val1), (val2)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_3(thr,bw_ctx,val1,val2,val3) do { \ +#define DUK_BW_WRITE_ENSURE_U8_3(thr, bw_ctx, val1, val2, val3) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 3); \ DUK_BW_WRITE_RAW_U8_3((thr), (bw_ctx), (val1), (val2), (val3)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_4(thr,bw_ctx,val1,val2,val3,val4) do { \ +#define DUK_BW_WRITE_ENSURE_U8_4(thr, bw_ctx, val1, val2, val3, val4) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 4); \ DUK_BW_WRITE_RAW_U8_4((thr), (bw_ctx), (val1), (val2), (val3), (val4)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_5(thr,bw_ctx,val1,val2,val3,val4,val5) do { \ +#define DUK_BW_WRITE_ENSURE_U8_5(thr, bw_ctx, val1, val2, val3, val4, val5) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 5); \ DUK_BW_WRITE_RAW_U8_5((thr), (bw_ctx), (val1), (val2), (val3), (val4), (val5)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_6(thr,bw_ctx,val1,val2,val3,val4,val5,val6) do { \ +#define DUK_BW_WRITE_ENSURE_U8_6(thr, bw_ctx, val1, val2, val3, val4, val5, val6) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 6); \ DUK_BW_WRITE_RAW_U8_6((thr), (bw_ctx), (val1), (val2), (val3), (val4), (val5), (val6)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_XUTF8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_ENSURE_XUTF8(thr, bw_ctx, cp) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), DUK_UNICODE_MAX_XUTF8_LENGTH); \ DUK_BW_WRITE_RAW_XUTF8((thr), (bw_ctx), (cp)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_CESU8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_ENSURE_CESU8(thr, bw_ctx, cp) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), DUK_UNICODE_MAX_CESU8_LENGTH); \ DUK_BW_WRITE_RAW_CESU8((thr), (bw_ctx), (cp)); \ } while (0) /* XXX: add temporary duk__p pointer here too; sharing */ /* XXX: avoid unsafe */ -#define DUK_BW_WRITE_ENSURE_BYTES(thr,bw_ctx,valptr,valsz) do { \ +#define DUK_BW_WRITE_ENSURE_BYTES(thr, bw_ctx, valptr, valsz) \ + do { \ const void *duk__valptr; \ duk_size_t duk__valsz; \ duk__valptr = (const void *) (valptr); \ @@ -432,7 +458,8 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), duk__valptr, duk__valsz); \ (bw_ctx)->p += duk__valsz; \ } while (0) -#define DUK_BW_WRITE_ENSURE_CSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_CSTRING(thr, bw_ctx, val) \ + do { \ const duk_uint8_t *duk__val; \ duk_size_t duk__val_len; \ duk__val = (const duk_uint8_t *) (val); \ @@ -441,45 +468,53 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) duk__val, duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HSTRING(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HSTRING_GET_BYTELEN((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HSTRING_GET_DATA((val)), duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER_FIXED(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER_FIXED(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_FIXED_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER_DYNAMIC(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER_DYNAMIC(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_DYNAMIC_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_SLICE(thr,bw,dst_off,dst_len) \ - duk_bw_write_ensure_slice((thr), (bw), (dst_off), (dst_len)) -#define DUK_BW_INSERT_ENSURE_BYTES(thr,bw,dst_off,buf,len) \ - duk_bw_insert_ensure_bytes((thr), (bw), (dst_off), (buf), (len)) -#define DUK_BW_INSERT_ENSURE_SLICE(thr,bw,dst_off,src_off,len) \ +#define DUK_BW_WRITE_ENSURE_SLICE(thr, bw, dst_off, dst_len) duk_bw_write_ensure_slice((thr), (bw), (dst_off), (dst_len)) +#define DUK_BW_INSERT_ENSURE_BYTES(thr, bw, dst_off, buf, len) duk_bw_insert_ensure_bytes((thr), (bw), (dst_off), (buf), (len)) +#define DUK_BW_INSERT_ENSURE_SLICE(thr, bw, dst_off, src_off, len) \ duk_bw_insert_ensure_slice((thr), (bw), (dst_off), (src_off), (len)) -#define DUK_BW_INSERT_ENSURE_AREA(thr,bw,off,len) \ +#define DUK_BW_INSERT_ENSURE_AREA(thr, bw, off, len) \ /* Evaluates to (duk_uint8_t *) pointing to start of area. */ \ duk_bw_insert_ensure_area((thr), (bw), (off), (len)) -#define DUK_BW_REMOVE_ENSURE_SLICE(thr,bw,off,len) \ +#define DUK_BW_REMOVE_ENSURE_SLICE(thr, bw, off, len) \ /* No difference between raw/ensure because the buffer shrinks. */ \ DUK_BW_REMOVE_RAW_SLICE((thr), (bw), (off), (len)) @@ -495,13 +530,13 @@ DUK_INTERNAL_DECL const duk_int16_t duk_hex_dectab_shift4256; DUK_INTERNAL_DECL const duk_uint16_t duk_hex_enctab256; #endif -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* Note: assumes that duk_util_probe_steps size is 32 */ #if defined(DUK_USE_HOBJECT_HASH_PART) #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL duk_uint8_t duk_util_probe_steps32; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ #endif #if defined(DUK_USE_STRHASH_DENSE) @@ -529,10 +564,26 @@ DUK_INTERNAL_DECL void duk_bw_compact(duk_hthread *thr, duk_bufwriter_ctx *bw_ctx); DUK_INTERNAL_DECL void duk_bw_write_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t src_off, duk_size_t len); DUK_INTERNAL_DECL void duk_bw_write_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t src_off, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_raw_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_ensure_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_raw_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_ensure_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_raw_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_ensure_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len); DUK_INTERNAL_DECL duk_uint8_t *duk_bw_insert_raw_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); DUK_INTERNAL_DECL duk_uint8_t *duk_bw_insert_ensure_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); DUK_INTERNAL_DECL void duk_bw_remove_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); @@ -559,10 +610,12 @@ DUK_INTERNAL_DECL void duk_raw_writeinc_xutf8(duk_uint8_t **p, duk_ucodepoint_t val); DUK_INTERNAL_DECL void duk_raw_writeinc_cesu8(duk_uint8_t **p, duk_ucodepoint_t val); -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ DUK_INTERNAL_DECL void duk_byteswap_bytes(duk_uint8_t *p, duk_small_uint_t len); #endif +DUK_INTERNAL_DECL duk_double_t duk_util_get_random_double(duk_hthread *thr); + /* memcpy(), memmove() etc wrappers. The plain variants like duk_memcpy() * assume C99+ and 'src' and 'dst' pointers must be non-NULL even when the * operation size is zero. The unsafe variants like duk_memcpy_safe() deal @@ -573,7 +626,8 @@ * few extra bytes per call site adds up to ~1kB footprint. */ #if defined(DUK_USE_ALLOW_UNDEFINED_BEHAVIOR) -#define duk_memcpy(dst,src,len) do { \ +#define duk_memcpy(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -581,8 +635,9 @@ DUK_ASSERT(duk__src != NULL || duk__len == 0U); \ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memcpy_unsafe(dst,src,len) duk_memcpy((dst), (src), (len)) -#define duk_memmove(dst,src,len) do { \ +#define duk_memcpy_unsafe(dst, src, len) duk_memcpy((dst), (src), (len)) +#define duk_memmove(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -590,24 +645,27 @@ DUK_ASSERT(duk__src != NULL || duk__len == 0U); \ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memmove_unsafe(dst,src,len) duk_memmove((dst), (src), (len)) -#define duk_memset(dst,val,len) do { \ +#define duk_memmove_unsafe(dst, src, len) duk_memmove((dst), (src), (len)) +#define duk_memset(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } while (0) -#define duk_memset_unsafe(dst,val,len) duk_memset((dst), (val), (len)) -#define duk_memzero(dst,len) do { \ +#define duk_memset_unsafe(dst, val, len) duk_memset((dst), (val), (len)) +#define duk_memzero(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } while (0) -#define duk_memzero_unsafe(dst,len) duk_memzero((dst), (len)) -#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ -#define duk_memcpy(dst,src,len) do { \ +#define duk_memzero_unsafe(dst, len) duk_memzero((dst), (len)) +#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#define duk_memcpy(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -615,7 +673,8 @@ DUK_ASSERT(duk__src != NULL); \ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memcpy_unsafe(dst,src,len) do { \ +#define duk_memcpy_unsafe(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -627,7 +686,8 @@ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } \ } while (0) -#define duk_memmove(dst,src,len) do { \ +#define duk_memmove(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -635,7 +695,8 @@ DUK_ASSERT(duk__src != NULL); \ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memmove_unsafe(dst,src,len) do { \ +#define duk_memmove_unsafe(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -647,14 +708,16 @@ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } \ } while (0) -#define duk_memset(dst,val,len) do { \ +#define duk_memset(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL); \ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } while (0) -#define duk_memset_unsafe(dst,val,len) do { \ +#define duk_memset_unsafe(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ @@ -664,13 +727,15 @@ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } \ } while (0) -#define duk_memzero(dst,len) do { \ +#define duk_memzero(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL); \ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } while (0) -#define duk_memzero_unsafe(dst,len) do { \ +#define duk_memzero_unsafe(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ @@ -679,7 +744,7 @@ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } \ } while (0) -#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ DUK_INTERNAL_DECL duk_small_int_t duk_memcmp(const void *s1, const void *s2, duk_size_t len); DUK_INTERNAL_DECL duk_small_int_t duk_memcmp_unsafe(const void *s1, const void *s2, duk_size_t len); @@ -725,7 +790,6 @@ * * However, incorrectly true for x == 0 so check for that explicitly. */ -#define DUK_IS_POWER_OF_TWO(x) \ - ((x) != 0U && ((x) & ((x) - 1U)) == 0U) +#define DUK_IS_POWER_OF_TWO(x) ((x) != 0U && ((x) & ((x) -1U)) == 0U) -#endif /* DUK_UTIL_H_INCLUDED */ +#endif /* DUK_UTIL_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_util_bitdecoder.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_util_bitdecoder.c
Changed
@@ -43,7 +43,7 @@ shift = ctx->currbits - bits; mask = (((duk_uint32_t) 1U) << bits) - 1U; tmp = (ctx->currval >> shift) & mask; - ctx->currbits = shift; /* remaining */ + ctx->currbits = shift; /* remaining */ #if 0 DUK_DDD(DUK_DDDPRINT("decode_bits: %ld bits -> 0x%08lx (%ld), currbits=%ld, currval=0x%08lx", @@ -82,17 +82,17 @@ */ switch (duk_bd_decode(ctx, 2)) { case 0: - return 0; /* 0,0 */ + return 0; /* 0,0 */ case 1: - return duk_bd_decode(ctx, 2) + 1; /* 1,4 */ + return duk_bd_decode(ctx, 2) + 1; /* 1,4 */ case 2: - return duk_bd_decode(ctx, 5) + 5; /* 5,36 */ + return duk_bd_decode(ctx, 5) + 5; /* 5,36 */ default: t = duk_bd_decode(ctx, 7); if (t == 0) { return duk_bd_decode(ctx, 20); } - return (t - 1) + 37; /* 37,163 */ + return (t - 1) + 37; /* 37,163 */ } } @@ -101,20 +101,18 @@ * Caller must supply the output buffer whose size is NOT checked! */ -#define DUK__BITPACK_LETTER_LIMIT 26 -#define DUK__BITPACK_LOOKUP1 26 -#define DUK__BITPACK_LOOKUP2 27 -#define DUK__BITPACK_SWITCH1 28 -#define DUK__BITPACK_SWITCH 29 -#define DUK__BITPACK_UNUSED1 30 -#define DUK__BITPACK_EIGHTBIT 31 - -DUK_LOCAL const duk_uint8_t duk__bitpacked_lookup16 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_UNDERSCORE, DUK_ASC_SPACE, - 0x82, 0x80, DUK_ASC_DOUBLEQUOTE, DUK_ASC_LCURLY -}; +#define DUK__BITPACK_LETTER_LIMIT 26 +#define DUK__BITPACK_LOOKUP1 26 +#define DUK__BITPACK_LOOKUP2 27 +#define DUK__BITPACK_SWITCH1 28 +#define DUK__BITPACK_SWITCH 29 +#define DUK__BITPACK_UNUSED1 30 +#define DUK__BITPACK_EIGHTBIT 31 + +DUK_LOCAL const duk_uint8_t duk__bitpacked_lookup16 = { DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, + DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_UNDERSCORE, DUK_ASC_SPACE, + 0x82, 0x80, DUK_ASC_DOUBLEQUOTE, DUK_ASC_LCURLY }; DUK_INTERNAL duk_small_uint_t duk_bd_decode_bitpacked_string(duk_bitdecoder_ctx *bd, duk_uint8_t *out) { duk_small_uint_t len; @@ -124,10 +122,10 @@ len = duk_bd_decode(bd, 5); if (len == 31) { - len = duk_bd_decode(bd, 8); /* Support up to 256 bytes; rare. */ + len = duk_bd_decode(bd, 8); /* Support up to 256 bytes; rare. */ } - mode = 32; /* 0 = uppercase, 32 = lowercase (= 'a' - 'A') */ + mode = 32; /* 0 = uppercase, 32 = lowercase (= 'a' - 'A') */ for (i = 0; i < len; i++) { t = duk_bd_decode(bd, 5); if (t < DUK__BITPACK_LETTER_LIMIT) { @@ -138,7 +136,7 @@ t = duk__bitpacked_lookup8 + duk_bd_decode(bd, 3); } else if (t == DUK__BITPACK_SWITCH1) { t = duk_bd_decode(bd, 5); - DUK_ASSERT_DISABLE(t >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(t >= 0); /* unsigned */ DUK_ASSERT(t <= 25); t = t + DUK_ASC_UC_A + (mode ^ 32); } else if (t == DUK__BITPACK_SWITCH) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_util_bufwriter.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_util_bufwriter.c
Changed
@@ -71,7 +71,7 @@ DUK_ERROR_RANGE(thr, DUK_STR_BUFFER_TOO_LONG); DUK_WO_NORETURN(return NULL;); } -#if 0 /* for manual torture testing: tight allocation, useful with valgrind */ +#if 0 /* for manual torture testing: tight allocation, useful with valgrind */ new_sz = curr_off + sz; #endif @@ -112,9 +112,7 @@ DUK_UNREF(thr); p_base = bw->p_base; - duk_memcpy_unsafe((void *) bw->p, - (const void *) (p_base + src_off), - (size_t) len); + duk_memcpy_unsafe((void *) bw->p, (const void *) (p_base + src_off), (size_t) len); bw->p += len; } @@ -129,7 +127,11 @@ duk_bw_write_raw_slice(thr, bw, src_off, len); } -DUK_INTERNAL void duk_bw_insert_raw_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_raw_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len) { duk_uint8_t *p_base; duk_size_t buf_sz, move_sz; @@ -140,20 +142,20 @@ DUK_UNREF(thr); p_base = bw->p_base; - buf_sz = (duk_size_t) (bw->p - p_base); /* constrained by maximum buffer size */ + buf_sz = (duk_size_t) (bw->p - p_base); /* constrained by maximum buffer size */ move_sz = buf_sz - dst_off; - DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ - duk_memmove_unsafe((void *) (p_base + dst_off + len), - (const void *) (p_base + dst_off), - (size_t) move_sz); - duk_memcpy_unsafe((void *) (p_base + dst_off), - (const void *) buf, - (size_t) len); + DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ + duk_memmove_unsafe((void *) (p_base + dst_off + len), (const void *) (p_base + dst_off), (size_t) move_sz); + duk_memcpy_unsafe((void *) (p_base + dst_off), (const void *) buf, (size_t) len); bw->p += len; } -DUK_INTERNAL void duk_bw_insert_ensure_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_ensure_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len) { DUK_ASSERT(thr != NULL); DUK_ASSERT(bw != NULL); DUK_ASSERT(dst_off <= DUK_BW_GET_SIZE(thr, bw)); @@ -163,7 +165,11 @@ duk_bw_insert_raw_bytes(thr, bw, dst_off, buf, len); } -DUK_INTERNAL void duk_bw_insert_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_raw_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len) { duk_uint8_t *p_base; duk_size_t buf_sz, move_sz; @@ -190,17 +196,17 @@ buf_sz = (duk_size_t) (bw->p - p_base); move_sz = buf_sz - dst_off; - DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ - duk_memmove_unsafe((void *) (p_base + dst_off + len), - (const void *) (p_base + dst_off), - (size_t) move_sz); - duk_memcpy_unsafe((void *) (p_base + dst_off), - (const void *) (p_base + src_off), - (size_t) len); + DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ + duk_memmove_unsafe((void *) (p_base + dst_off + len), (const void *) (p_base + dst_off), (size_t) move_sz); + duk_memcpy_unsafe((void *) (p_base + dst_off), (const void *) (p_base + src_off), (size_t) len); bw->p += len; } -DUK_INTERNAL void duk_bw_insert_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_ensure_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len) { DUK_ASSERT(thr != NULL); DUK_ASSERT(bw != NULL); DUK_ASSERT(dst_off <= DUK_BW_GET_SIZE(thr, bw)); @@ -230,7 +236,7 @@ p_dst = p_base + off + len; p_src = p_base + off; duk_memmove_unsafe((void *) p_dst, (const void *) p_src, (size_t) move_sz); - return p_src; /* point to start of 'reserved area' */ + return p_src; /* point to start of 'reserved area' */ } DUK_INTERNAL duk_uint8_t *duk_bw_insert_ensure_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len) { @@ -260,9 +266,7 @@ p_dst = p_base + off; p_src = p_dst + len; move_sz = (duk_size_t) (bw->p - p_src); - duk_memmove_unsafe((void *) p_dst, - (const void *) p_src, - (size_t) move_sz); + duk_memmove_unsafe((void *) p_dst, (const void *) p_src, (size_t) move_sz); bw->p -= len; } @@ -276,11 +280,7 @@ DUK_ASSERT(bw_ctx != NULL); DUK_ASSERT(bw_ctx->buf != NULL); DUK_ASSERT((DUK_HBUFFER_DYNAMIC_GET_SIZE(bw_ctx->buf) == 0) || - (bw_ctx->p != NULL && - bw_ctx->p_base != NULL && - bw_ctx->p_limit != NULL && - bw_ctx->p_limit >= bw_ctx->p_base && - bw_ctx->p >= bw_ctx->p_base && - bw_ctx->p <= bw_ctx->p_limit)); + (bw_ctx->p != NULL && bw_ctx->p_base != NULL && bw_ctx->p_limit != NULL && bw_ctx->p_limit >= bw_ctx->p_base && + bw_ctx->p >= bw_ctx->p_base && bw_ctx->p <= bw_ctx->p_limit)); } #endif
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_util_cast.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_util_cast.c
Changed
@@ -17,7 +17,8 @@ * relying on fmin(), fmax(), or other intrinsics. Out-of-range results are * not assumed by caller, but here value is clamped, NaN converts to minval. */ -#define DUK__DOUBLE_INT_CAST1(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST1(tname, minval, maxval) \ + do { \ if (DUK_LIKELY(x >= (duk_double_t) (minval))) { \ DUK_ASSERT(!DUK_ISNAN(x)); \ if (DUK_LIKELY(x <= (duk_double_t) (maxval))) { \ @@ -38,19 +39,22 @@ * argument is a NaN, return the second argument. This avoids a * NaN-to-integer cast which is undefined behavior. */ -#define DUK__DOUBLE_INT_CAST2(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST2(tname, minval, maxval) \ + do { \ return (tname) duk_double_fmin(duk_double_fmax(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ } while (0) /* Another solution which doesn't need C99+ behavior for fmin() and fmax(). */ -#define DUK__DOUBLE_INT_CAST3(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST3(tname, minval, maxval) \ + do { \ if (DUK_ISNAN(x)) { \ /* 0 or any other value is fine. */ \ return (tname) 0; \ } else \ return (tname) DUK_FMIN(DUK_FMAX(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ - } \ - } while (0) + } \ + } \ + while (0) /* C99+ solution: relies on specific fmin() and fmax() behavior in C99: if * one argument is NaN but the other isn't, the non-NaN argument is returned. @@ -59,7 +63,8 @@ * the fmin() and fmax() calls (unless one uses -ffast-math which we don't * support). */ -#define DUK__DOUBLE_INT_CAST4(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST4(tname, minval, maxval) \ + do { \ return (tname) DUK_FMIN(DUK_FMAX(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ } while (0) @@ -103,12 +108,12 @@ * infinity, at least on x64. This number is one double unit below that * midpoint. See misc/float_cast.c. */ -#define DUK__FLOAT_ROUND_LIMIT 340282356779733623858607532500980858880.0 +#define DUK__FLOAT_ROUND_LIMIT 340282356779733623858607532500980858880.0 /* Maximum IEEE float. Double-to-float conversion above this would be out of * range and thus technically undefined behavior. */ -#define DUK__FLOAT_MAX 340282346638528859811704183484516925440.0 +#define DUK__FLOAT_MAX 340282346638528859811704183484516925440.0 DUK_INTERNAL duk_float_t duk_double_to_float_t(duk_double_t x) { /* Even a double-to-float cast is technically undefined behavior if @@ -127,8 +132,7 @@ duk_double_t t; t = DUK_FABS(x); - DUK_ASSERT((DUK_ISNAN(x) && DUK_ISNAN(t)) || - (!DUK_ISNAN(x) && !DUK_ISNAN(t))); + DUK_ASSERT((DUK_ISNAN(x) && DUK_ISNAN(t)) || (!DUK_ISNAN(x) && !DUK_ISNAN(t))); if (DUK_LIKELY(t <= DUK__FLOAT_MAX)) { /* Standard in-range case, try to get here with a minimum
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_util_double.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_util_double.c
Changed
@@ -108,7 +108,7 @@ DUK_INTERNAL duk_double_t duk_double_trunc_towards_zero(duk_double_t x) { /* XXX: optimize */ duk_small_uint_t s = duk_double_signbit(x); - x = DUK_FLOOR(DUK_FABS(x)); /* truncate towards zero */ + x = DUK_FLOOR(DUK_FABS(x)); /* truncate towards zero */ if (s) { x = -x; }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_util_hashbytes.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_util_hashbytes.c
Changed
@@ -11,8 +11,8 @@ #if defined(DUK_USE_STRHASH_DENSE) /* 'magic' constants for Murmurhash2 */ -#define DUK__MAGIC_M ((duk_uint32_t) 0x5bd1e995UL) -#define DUK__MAGIC_R 24 +#define DUK__MAGIC_M ((duk_uint32_t) 0x5bd1e995UL) +#define DUK__MAGIC_R 24 DUK_INTERNAL duk_uint32_t duk_util_hashbytes(const duk_uint8_t *data, duk_size_t len, duk_uint32_t seed) { duk_uint32_t h = seed ^ ((duk_uint32_t) len); @@ -26,9 +26,7 @@ #if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS) duk_uint32_t k = *((const duk_uint32_t *) (const void *) data); #else - duk_uint32_t k = ((duk_uint32_t) data0) | - (((duk_uint32_t) data1) << 8) | - (((duk_uint32_t) data2) << 16) | + duk_uint32_t k = ((duk_uint32_t) data0) | (((duk_uint32_t) data1) << 8) | (((duk_uint32_t) data2) << 16) | (((duk_uint32_t) data3) << 24); #endif @@ -42,11 +40,14 @@ } switch (len) { - case 3: h ^= data2 << 16; - case 2: h ^= data1 << 8; - case 1: h ^= data0; - h *= DUK__MAGIC_M; - } + case 3: + h ^= data2 << 16; + case 2: + h ^= data1 << 8; + case 1: + h ^= data0; + h *= DUK__MAGIC_M; + } h ^= h >> 13; h *= DUK__MAGIC_M; @@ -54,4 +55,4 @@ return h; } -#endif /* DUK_USE_STRHASH_DENSE */ +#endif /* DUK_USE_STRHASH_DENSE */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_util_memory.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_util_memory.c
Changed
@@ -16,7 +16,7 @@ DUK_ASSERT(s2 != NULL); return DUK_MEMCMP(s1, s2, (size_t) len); } -#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ DUK_INTERNAL DUK_INLINE duk_small_int_t duk_memcmp_unsafe(const void *s1, const void *s2, duk_size_t len) { DUK_ASSERT(s1 != NULL || len == 0U); DUK_ASSERT(s2 != NULL || len == 0U); @@ -33,4 +33,4 @@ DUK_ASSERT(s2 != NULL); return DUK_MEMCMP(s1, s2, (size_t) len); } -#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_util_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_util_misc.c
Changed
@@ -10,23 +10,17 @@ */ DUK_INTERNAL const duk_uint8_t duk_lc_digits36 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_LC_A, DUK_ASC_LC_B, - DUK_ASC_LC_C, DUK_ASC_LC_D, DUK_ASC_LC_E, DUK_ASC_LC_F, - DUK_ASC_LC_G, DUK_ASC_LC_H, DUK_ASC_LC_I, DUK_ASC_LC_J, - DUK_ASC_LC_K, DUK_ASC_LC_L, DUK_ASC_LC_M, DUK_ASC_LC_N, - DUK_ASC_LC_O, DUK_ASC_LC_P, DUK_ASC_LC_Q, DUK_ASC_LC_R, - DUK_ASC_LC_S, DUK_ASC_LC_T, DUK_ASC_LC_U, DUK_ASC_LC_V, + DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_LC_A, DUK_ASC_LC_B, DUK_ASC_LC_C, DUK_ASC_LC_D, DUK_ASC_LC_E, DUK_ASC_LC_F, + DUK_ASC_LC_G, DUK_ASC_LC_H, DUK_ASC_LC_I, DUK_ASC_LC_J, DUK_ASC_LC_K, DUK_ASC_LC_L, DUK_ASC_LC_M, DUK_ASC_LC_N, + DUK_ASC_LC_O, DUK_ASC_LC_P, DUK_ASC_LC_Q, DUK_ASC_LC_R, DUK_ASC_LC_S, DUK_ASC_LC_T, DUK_ASC_LC_U, DUK_ASC_LC_V, DUK_ASC_LC_W, DUK_ASC_LC_X, DUK_ASC_LC_Y, DUK_ASC_LC_Z }; -DUK_INTERNAL const duk_uint8_t duk_uc_nybbles16 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_UC_A, DUK_ASC_UC_B, - DUK_ASC_UC_C, DUK_ASC_UC_D, DUK_ASC_UC_E, DUK_ASC_UC_F -}; +DUK_INTERNAL const duk_uint8_t duk_uc_nybbles16 = { DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, + DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_UC_A, DUK_ASC_UC_B, + DUK_ASC_UC_C, DUK_ASC_UC_D, DUK_ASC_UC_E, DUK_ASC_UC_F }; /* * Table for hex decoding ASCII hex digits @@ -34,43 +28,43 @@ DUK_INTERNAL const duk_int8_t duk_hex_dectab256 = { /* -1 if invalid */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ }; #if defined(DUK_USE_HEX_FASTPATH) /* Preshifted << 4. Must use 16-bit entry to allow negative value signaling. */ DUK_INTERNAL const duk_int16_t duk_hex_dectab_shift4256 = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ - 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ - -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ - -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ + 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ + -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ + -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ }; #endif @@ -89,77 +83,53 @@ * print('0x' + t.encode('hex') + 'U') * print('big endian'); genhextab(False) * print('little endian'); genhextab(True) -*/ + */ DUK_INTERNAL const duk_uint16_t duk_hex_enctab256 = { #if defined(DUK_USE_INTEGER_BE) - 0x3030U, 0x3031U, 0x3032U, 0x3033U, 0x3034U, 0x3035U, 0x3036U, 0x3037U, - 0x3038U, 0x3039U, 0x3061U, 0x3062U, 0x3063U, 0x3064U, 0x3065U, 0x3066U, - 0x3130U, 0x3131U, 0x3132U, 0x3133U, 0x3134U, 0x3135U, 0x3136U, 0x3137U, - 0x3138U, 0x3139U, 0x3161U, 0x3162U, 0x3163U, 0x3164U, 0x3165U, 0x3166U, - 0x3230U, 0x3231U, 0x3232U, 0x3233U, 0x3234U, 0x3235U, 0x3236U, 0x3237U, - 0x3238U, 0x3239U, 0x3261U, 0x3262U, 0x3263U, 0x3264U, 0x3265U, 0x3266U, - 0x3330U, 0x3331U, 0x3332U, 0x3333U, 0x3334U, 0x3335U, 0x3336U, 0x3337U, - 0x3338U, 0x3339U, 0x3361U, 0x3362U, 0x3363U, 0x3364U, 0x3365U, 0x3366U, - 0x3430U, 0x3431U, 0x3432U, 0x3433U, 0x3434U, 0x3435U, 0x3436U, 0x3437U, - 0x3438U, 0x3439U, 0x3461U, 0x3462U, 0x3463U, 0x3464U, 0x3465U, 0x3466U, - 0x3530U, 0x3531U, 0x3532U, 0x3533U, 0x3534U, 0x3535U, 0x3536U, 0x3537U, - 0x3538U, 0x3539U, 0x3561U, 0x3562U, 0x3563U, 0x3564U, 0x3565U, 0x3566U, - 0x3630U, 0x3631U, 0x3632U, 0x3633U, 0x3634U, 0x3635U, 0x3636U, 0x3637U, - 0x3638U, 0x3639U, 0x3661U, 0x3662U, 0x3663U, 0x3664U, 0x3665U, 0x3666U, - 0x3730U, 0x3731U, 0x3732U, 0x3733U, 0x3734U, 0x3735U, 0x3736U, 0x3737U, - 0x3738U, 0x3739U, 0x3761U, 0x3762U, 0x3763U, 0x3764U, 0x3765U, 0x3766U, - 0x3830U, 0x3831U, 0x3832U, 0x3833U, 0x3834U, 0x3835U, 0x3836U, 0x3837U, - 0x3838U, 0x3839U, 0x3861U, 0x3862U, 0x3863U, 0x3864U, 0x3865U, 0x3866U, - 0x3930U, 0x3931U, 0x3932U, 0x3933U, 0x3934U, 0x3935U, 0x3936U, 0x3937U, - 0x3938U, 0x3939U, 0x3961U, 0x3962U, 0x3963U, 0x3964U, 0x3965U, 0x3966U, - 0x6130U, 0x6131U, 0x6132U, 0x6133U, 0x6134U, 0x6135U, 0x6136U, 0x6137U, - 0x6138U, 0x6139U, 0x6161U, 0x6162U, 0x6163U, 0x6164U, 0x6165U, 0x6166U, - 0x6230U, 0x6231U, 0x6232U, 0x6233U, 0x6234U, 0x6235U, 0x6236U, 0x6237U, - 0x6238U, 0x6239U, 0x6261U, 0x6262U, 0x6263U, 0x6264U, 0x6265U, 0x6266U, - 0x6330U, 0x6331U, 0x6332U, 0x6333U, 0x6334U, 0x6335U, 0x6336U, 0x6337U, - 0x6338U, 0x6339U, 0x6361U, 0x6362U, 0x6363U, 0x6364U, 0x6365U, 0x6366U, - 0x6430U, 0x6431U, 0x6432U, 0x6433U, 0x6434U, 0x6435U, 0x6436U, 0x6437U, - 0x6438U, 0x6439U, 0x6461U, 0x6462U, 0x6463U, 0x6464U, 0x6465U, 0x6466U, - 0x6530U, 0x6531U, 0x6532U, 0x6533U, 0x6534U, 0x6535U, 0x6536U, 0x6537U, - 0x6538U, 0x6539U, 0x6561U, 0x6562U, 0x6563U, 0x6564U, 0x6565U, 0x6566U, - 0x6630U, 0x6631U, 0x6632U, 0x6633U, 0x6634U, 0x6635U, 0x6636U, 0x6637U, - 0x6638U, 0x6639U, 0x6661U, 0x6662U, 0x6663U, 0x6664U, 0x6665U, 0x6666U -#else /* DUK_USE_INTEGER_BE */ - 0x3030U, 0x3130U, 0x3230U, 0x3330U, 0x3430U, 0x3530U, 0x3630U, 0x3730U, - 0x3830U, 0x3930U, 0x6130U, 0x6230U, 0x6330U, 0x6430U, 0x6530U, 0x6630U, - 0x3031U, 0x3131U, 0x3231U, 0x3331U, 0x3431U, 0x3531U, 0x3631U, 0x3731U, - 0x3831U, 0x3931U, 0x6131U, 0x6231U, 0x6331U, 0x6431U, 0x6531U, 0x6631U, - 0x3032U, 0x3132U, 0x3232U, 0x3332U, 0x3432U, 0x3532U, 0x3632U, 0x3732U, - 0x3832U, 0x3932U, 0x6132U, 0x6232U, 0x6332U, 0x6432U, 0x6532U, 0x6632U, - 0x3033U, 0x3133U, 0x3233U, 0x3333U, 0x3433U, 0x3533U, 0x3633U, 0x3733U, - 0x3833U, 0x3933U, 0x6133U, 0x6233U, 0x6333U, 0x6433U, 0x6533U, 0x6633U, - 0x3034U, 0x3134U, 0x3234U, 0x3334U, 0x3434U, 0x3534U, 0x3634U, 0x3734U, - 0x3834U, 0x3934U, 0x6134U, 0x6234U, 0x6334U, 0x6434U, 0x6534U, 0x6634U, - 0x3035U, 0x3135U, 0x3235U, 0x3335U, 0x3435U, 0x3535U, 0x3635U, 0x3735U, - 0x3835U, 0x3935U, 0x6135U, 0x6235U, 0x6335U, 0x6435U, 0x6535U, 0x6635U, - 0x3036U, 0x3136U, 0x3236U, 0x3336U, 0x3436U, 0x3536U, 0x3636U, 0x3736U, - 0x3836U, 0x3936U, 0x6136U, 0x6236U, 0x6336U, 0x6436U, 0x6536U, 0x6636U, - 0x3037U, 0x3137U, 0x3237U, 0x3337U, 0x3437U, 0x3537U, 0x3637U, 0x3737U, - 0x3837U, 0x3937U, 0x6137U, 0x6237U, 0x6337U, 0x6437U, 0x6537U, 0x6637U, - 0x3038U, 0x3138U, 0x3238U, 0x3338U, 0x3438U, 0x3538U, 0x3638U, 0x3738U, - 0x3838U, 0x3938U, 0x6138U, 0x6238U, 0x6338U, 0x6438U, 0x6538U, 0x6638U, - 0x3039U, 0x3139U, 0x3239U, 0x3339U, 0x3439U, 0x3539U, 0x3639U, 0x3739U, - 0x3839U, 0x3939U, 0x6139U, 0x6239U, 0x6339U, 0x6439U, 0x6539U, 0x6639U, - 0x3061U, 0x3161U, 0x3261U, 0x3361U, 0x3461U, 0x3561U, 0x3661U, 0x3761U, - 0x3861U, 0x3961U, 0x6161U, 0x6261U, 0x6361U, 0x6461U, 0x6561U, 0x6661U, - 0x3062U, 0x3162U, 0x3262U, 0x3362U, 0x3462U, 0x3562U, 0x3662U, 0x3762U, - 0x3862U, 0x3962U, 0x6162U, 0x6262U, 0x6362U, 0x6462U, 0x6562U, 0x6662U, - 0x3063U, 0x3163U, 0x3263U, 0x3363U, 0x3463U, 0x3563U, 0x3663U, 0x3763U, - 0x3863U, 0x3963U, 0x6163U, 0x6263U, 0x6363U, 0x6463U, 0x6563U, 0x6663U, - 0x3064U, 0x3164U, 0x3264U, 0x3364U, 0x3464U, 0x3564U, 0x3664U, 0x3764U, - 0x3864U, 0x3964U, 0x6164U, 0x6264U, 0x6364U, 0x6464U, 0x6564U, 0x6664U, - 0x3065U, 0x3165U, 0x3265U, 0x3365U, 0x3465U, 0x3565U, 0x3665U, 0x3765U, - 0x3865U, 0x3965U, 0x6165U, 0x6265U, 0x6365U, 0x6465U, 0x6565U, 0x6665U, - 0x3066U, 0x3166U, 0x3266U, 0x3366U, 0x3466U, 0x3566U, 0x3666U, 0x3766U, - 0x3866U, 0x3966U, 0x6166U, 0x6266U, 0x6366U, 0x6466U, 0x6566U, 0x6666U -#endif /* DUK_USE_INTEGER_BE */ + 0x3030U, 0x3031U, 0x3032U, 0x3033U, 0x3034U, 0x3035U, 0x3036U, 0x3037U, 0x3038U, 0x3039U, 0x3061U, 0x3062U, 0x3063U, + 0x3064U, 0x3065U, 0x3066U, 0x3130U, 0x3131U, 0x3132U, 0x3133U, 0x3134U, 0x3135U, 0x3136U, 0x3137U, 0x3138U, 0x3139U, + 0x3161U, 0x3162U, 0x3163U, 0x3164U, 0x3165U, 0x3166U, 0x3230U, 0x3231U, 0x3232U, 0x3233U, 0x3234U, 0x3235U, 0x3236U, + 0x3237U, 0x3238U, 0x3239U, 0x3261U, 0x3262U, 0x3263U, 0x3264U, 0x3265U, 0x3266U, 0x3330U, 0x3331U, 0x3332U, 0x3333U, + 0x3334U, 0x3335U, 0x3336U, 0x3337U, 0x3338U, 0x3339U, 0x3361U, 0x3362U, 0x3363U, 0x3364U, 0x3365U, 0x3366U, 0x3430U, + 0x3431U, 0x3432U, 0x3433U, 0x3434U, 0x3435U, 0x3436U, 0x3437U, 0x3438U, 0x3439U, 0x3461U, 0x3462U, 0x3463U, 0x3464U, + 0x3465U, 0x3466U, 0x3530U, 0x3531U, 0x3532U, 0x3533U, 0x3534U, 0x3535U, 0x3536U, 0x3537U, 0x3538U, 0x3539U, 0x3561U, + 0x3562U, 0x3563U, 0x3564U, 0x3565U, 0x3566U, 0x3630U, 0x3631U, 0x3632U, 0x3633U, 0x3634U, 0x3635U, 0x3636U, 0x3637U, + 0x3638U, 0x3639U, 0x3661U, 0x3662U, 0x3663U, 0x3664U, 0x3665U, 0x3666U, 0x3730U, 0x3731U, 0x3732U, 0x3733U, 0x3734U, + 0x3735U, 0x3736U, 0x3737U, 0x3738U, 0x3739U, 0x3761U, 0x3762U, 0x3763U, 0x3764U, 0x3765U, 0x3766U, 0x3830U, 0x3831U, + 0x3832U, 0x3833U, 0x3834U, 0x3835U, 0x3836U, 0x3837U, 0x3838U, 0x3839U, 0x3861U, 0x3862U, 0x3863U, 0x3864U, 0x3865U, + 0x3866U, 0x3930U, 0x3931U, 0x3932U, 0x3933U, 0x3934U, 0x3935U, 0x3936U, 0x3937U, 0x3938U, 0x3939U, 0x3961U, 0x3962U, + 0x3963U, 0x3964U, 0x3965U, 0x3966U, 0x6130U, 0x6131U, 0x6132U, 0x6133U, 0x6134U, 0x6135U, 0x6136U, 0x6137U, 0x6138U, + 0x6139U, 0x6161U, 0x6162U, 0x6163U, 0x6164U, 0x6165U, 0x6166U, 0x6230U, 0x6231U, 0x6232U, 0x6233U, 0x6234U, 0x6235U, + 0x6236U, 0x6237U, 0x6238U, 0x6239U, 0x6261U, 0x6262U, 0x6263U, 0x6264U, 0x6265U, 0x6266U, 0x6330U, 0x6331U, 0x6332U, + 0x6333U, 0x6334U, 0x6335U, 0x6336U, 0x6337U, 0x6338U, 0x6339U, 0x6361U, 0x6362U, 0x6363U, 0x6364U, 0x6365U, 0x6366U, + 0x6430U, 0x6431U, 0x6432U, 0x6433U, 0x6434U, 0x6435U, 0x6436U, 0x6437U, 0x6438U, 0x6439U, 0x6461U, 0x6462U, 0x6463U, + 0x6464U, 0x6465U, 0x6466U, 0x6530U, 0x6531U, 0x6532U, 0x6533U, 0x6534U, 0x6535U, 0x6536U, 0x6537U, 0x6538U, 0x6539U, + 0x6561U, 0x6562U, 0x6563U, 0x6564U, 0x6565U, 0x6566U, 0x6630U, 0x6631U, 0x6632U, 0x6633U, 0x6634U, 0x6635U, 0x6636U, + 0x6637U, 0x6638U, 0x6639U, 0x6661U, 0x6662U, 0x6663U, 0x6664U, 0x6665U, 0x6666U +#else /* DUK_USE_INTEGER_BE */ + 0x3030U, 0x3130U, 0x3230U, 0x3330U, 0x3430U, 0x3530U, 0x3630U, 0x3730U, 0x3830U, 0x3930U, 0x6130U, 0x6230U, 0x6330U, + 0x6430U, 0x6530U, 0x6630U, 0x3031U, 0x3131U, 0x3231U, 0x3331U, 0x3431U, 0x3531U, 0x3631U, 0x3731U, 0x3831U, 0x3931U, + 0x6131U, 0x6231U, 0x6331U, 0x6431U, 0x6531U, 0x6631U, 0x3032U, 0x3132U, 0x3232U, 0x3332U, 0x3432U, 0x3532U, 0x3632U, + 0x3732U, 0x3832U, 0x3932U, 0x6132U, 0x6232U, 0x6332U, 0x6432U, 0x6532U, 0x6632U, 0x3033U, 0x3133U, 0x3233U, 0x3333U, + 0x3433U, 0x3533U, 0x3633U, 0x3733U, 0x3833U, 0x3933U, 0x6133U, 0x6233U, 0x6333U, 0x6433U, 0x6533U, 0x6633U, 0x3034U, + 0x3134U, 0x3234U, 0x3334U, 0x3434U, 0x3534U, 0x3634U, 0x3734U, 0x3834U, 0x3934U, 0x6134U, 0x6234U, 0x6334U, 0x6434U, + 0x6534U, 0x6634U, 0x3035U, 0x3135U, 0x3235U, 0x3335U, 0x3435U, 0x3535U, 0x3635U, 0x3735U, 0x3835U, 0x3935U, 0x6135U, + 0x6235U, 0x6335U, 0x6435U, 0x6535U, 0x6635U, 0x3036U, 0x3136U, 0x3236U, 0x3336U, 0x3436U, 0x3536U, 0x3636U, 0x3736U, + 0x3836U, 0x3936U, 0x6136U, 0x6236U, 0x6336U, 0x6436U, 0x6536U, 0x6636U, 0x3037U, 0x3137U, 0x3237U, 0x3337U, 0x3437U, + 0x3537U, 0x3637U, 0x3737U, 0x3837U, 0x3937U, 0x6137U, 0x6237U, 0x6337U, 0x6437U, 0x6537U, 0x6637U, 0x3038U, 0x3138U, + 0x3238U, 0x3338U, 0x3438U, 0x3538U, 0x3638U, 0x3738U, 0x3838U, 0x3938U, 0x6138U, 0x6238U, 0x6338U, 0x6438U, 0x6538U, + 0x6638U, 0x3039U, 0x3139U, 0x3239U, 0x3339U, 0x3439U, 0x3539U, 0x3639U, 0x3739U, 0x3839U, 0x3939U, 0x6139U, 0x6239U, + 0x6339U, 0x6439U, 0x6539U, 0x6639U, 0x3061U, 0x3161U, 0x3261U, 0x3361U, 0x3461U, 0x3561U, 0x3661U, 0x3761U, 0x3861U, + 0x3961U, 0x6161U, 0x6261U, 0x6361U, 0x6461U, 0x6561U, 0x6661U, 0x3062U, 0x3162U, 0x3262U, 0x3362U, 0x3462U, 0x3562U, + 0x3662U, 0x3762U, 0x3862U, 0x3962U, 0x6162U, 0x6262U, 0x6362U, 0x6462U, 0x6562U, 0x6662U, 0x3063U, 0x3163U, 0x3263U, + 0x3363U, 0x3463U, 0x3563U, 0x3663U, 0x3763U, 0x3863U, 0x3963U, 0x6163U, 0x6263U, 0x6363U, 0x6463U, 0x6563U, 0x6663U, + 0x3064U, 0x3164U, 0x3264U, 0x3364U, 0x3464U, 0x3564U, 0x3664U, 0x3764U, 0x3864U, 0x3964U, 0x6164U, 0x6264U, 0x6364U, + 0x6464U, 0x6564U, 0x6664U, 0x3065U, 0x3165U, 0x3265U, 0x3365U, 0x3465U, 0x3565U, 0x3665U, 0x3765U, 0x3865U, 0x3965U, + 0x6165U, 0x6265U, 0x6365U, 0x6465U, 0x6565U, 0x6665U, 0x3066U, 0x3166U, 0x3266U, 0x3366U, 0x3466U, 0x3566U, 0x3666U, + 0x3766U, 0x3866U, 0x3966U, 0x6166U, 0x6266U, 0x6366U, 0x6466U, 0x6566U, 0x6666U +#endif /* DUK_USE_INTEGER_BE */ }; -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ /* * Arbitrary byteswap for potentially unaligned values @@ -167,7 +137,7 @@ * Used to byteswap pointers e.g. in debugger code. */ -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ DUK_INTERNAL void duk_byteswap_bytes(duk_uint8_t *p, duk_small_uint_t len) { duk_uint8_t tmp; duk_uint8_t *q = p + len - 1; @@ -181,3 +151,15 @@ } } #endif + +/* + * Random + */ + +DUK_INTERNAL duk_double_t duk_util_get_random_double(duk_hthread *thr) { +#if defined(DUK_USE_GET_RANDOM_DOUBLE) + return DUK_USE_GET_RANDOM_DOUBLE(thr->heap->heap_udata); +#else + return duk_util_tinyrandom_get_double(thr); +#endif +}
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duk_util_tinyrandom.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duk_util_tinyrandom.c
Changed
@@ -21,15 +21,16 @@ #endif #if defined(DUK__RANDOM_SHAMIR3OP) -#define DUK__UPDATE_RND(rnd) do { \ +#define DUK__UPDATE_RND(rnd) \ + do { \ (rnd) += ((rnd) * (rnd)) | 0x05UL; \ - (rnd) = ((rnd) & 0xffffffffUL); /* if duk_uint32_t is exactly 32 bits, this is a NOP */ \ + (rnd) = ((rnd) &0xffffffffUL); /* if duk_uint32_t is exactly 32 bits, this is a NOP */ \ } while (0) -#define DUK__RND_BIT(rnd) ((rnd) >> 31) /* only use the highest bit */ +#define DUK__RND_BIT(rnd) ((rnd) >> 31) /* only use the highest bit */ DUK_INTERNAL void duk_util_tinyrandom_prepare_seed(duk_hthread *thr) { - DUK_UNREF(thr); /* Nothing now. */ + DUK_UNREF(thr); /* Nothing now. */ } DUK_INTERNAL duk_double_t duk_util_tinyrandom_get_double(duk_hthread *thr) { @@ -39,7 +40,7 @@ rnd = thr->heap->rnd_state; - n = 53; /* enough to cover the whole mantissa */ + n = 53; /* enough to cover the whole mantissa */ t = 0.0; do { @@ -55,7 +56,7 @@ return t; } -#endif /* DUK__RANDOM_SHAMIR3OP */ +#endif /* DUK__RANDOM_SHAMIR3OP */ #if defined(DUK__RANDOM_XOROSHIRO128PLUS) DUK_LOCAL DUK_ALWAYS_INLINE duk_uint64_t duk__rnd_splitmix64(duk_uint64_t *x) { @@ -94,9 +95,9 @@ * because current seed is Date.now()) result in different xoroshiro128+ * seeds. */ - x = thr->heap->rnd_state0; /* Only 0 is used as input here. */ + x = thr->heap->rnd_state0; /* Only 0 is used as input here. */ for (i = 0; i < 64; i++) { - thr->heap->rnd_statei & 0x01 = duk__rnd_splitmix64(&x); /* Keep last 2 values. */ + thr->heap->rnd_statei & 0x01 = duk__rnd_splitmix64(&x); /* Keep last 2 values. */ } } @@ -120,6 +121,6 @@ #endif return du.d - 1.0; } -#endif /* DUK__RANDOM_XOROSHIRO128PLUS */ +#endif /* DUK__RANDOM_XOROSHIRO128PLUS */ -#endif /* !DUK_USE_GET_RANDOM_DOUBLE */ +#endif /* !DUK_USE_GET_RANDOM_DOUBLE */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-input/duktape.h.in -> _service:tar_scm:duktape-2.7.0.tar.xz/src-input/duktape.h.in
Changed
@@ -38,7 +38,7 @@ * development snapshots have 99 for patch level (e.g. 0.10.99 would be a * development version after 0.10.0 but before the next official release). */ -#define DUK_VERSION 20600L +#define DUK_VERSION 20700L /* Git commit, describe, and branch for Duktape build. Useful for * non-official snapshot builds so that application code can easily log
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-noline/duk_config.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-noline/duk_config.h
Changed
@@ -1,9 +1,9 @@ /* * duk_config.h configuration header generated by genconfig.py. * - * Git commit: fffa346eff06a8764b02c31d4336f63a773a95c3 - * Git describe: v2.6.0 - * Git branch: v2-maintenance + * Git commit: 03d4d728f8365021de6955c649e6dcd05dcca99f + * Git describe: 03d4d72-dirty + * Git branch: HEAD * * Supported platforms: * - Mac OSX, iPhone, Darwin
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-noline/duk_source_meta.json -> _service:tar_scm:duktape-2.7.0.tar.xz/src-noline/duk_source_meta.json
Changed
@@ -1,737 +1,737 @@ { "comment": "Metadata for Duktape sources", - "duk_version_string": "2.6.0", + "duk_version_string": "2.7.0", "type": "duk_source_meta", "line_map": { "original_line": 1, - "combined_line": 155, + "combined_line": 161, "original_file": "duk_replacements.c" }, { "original_line": 1, - "combined_line": 164, + "combined_line": 170, "original_file": "duk_internal.h" }, { "original_line": 1, - "combined_line": 201, + "combined_line": 207, "original_file": "duk_dblunion.h" }, { "original_line": 1, - "combined_line": 626, + "combined_line": 627, "original_file": "duk_fltunion.h" }, { "original_line": 1, - "combined_line": 666, + "combined_line": 667, "original_file": "duk_replacements.h" }, { "original_line": 1, - "combined_line": 696, + "combined_line": 697, "original_file": "duk_jmpbuf.h" }, { "original_line": 1, - "combined_line": 721, + "combined_line": 722, "original_file": "duk_exception.h" }, { "original_line": 1, - "combined_line": 752, + "combined_line": 754, "original_file": "duk_forwdecl.h" }, { "original_line": 1, - "combined_line": 887, + "combined_line": 889, "original_file": "duk_tval.h" }, { "original_line": 1, - "combined_line": 1527, + "combined_line": 1567, "original_file": "duk_builtins.h" }, { "original_line": 45, - "combined_line": 2318, + "combined_line": 2358, "original_file": "duk_internal.h" }, { "original_line": 1, - "combined_line": 2320, + "combined_line": 2360, "original_file": "duk_util.h" }, { "original_line": 1, - "combined_line": 3052, + "combined_line": 3156, "original_file": "duk_strings.h" }, { "original_line": 1, - "combined_line": 3222, + "combined_line": 3326, "original_file": "duk_js_bytecode.h" }, { "original_line": 1, - "combined_line": 3705, + "combined_line": 3800, "original_file": "duk_lexer.h" }, { "original_line": 1, - "combined_line": 4144, + "combined_line": 4236, "original_file": "duk_js_compiler.h" }, { "original_line": 1, - "combined_line": 4372, + "combined_line": 4469, "original_file": "duk_regexp.h" }, { "original_line": 1, - "combined_line": 4457, + "combined_line": 4554, "original_file": "duk_heaphdr.h" }, { "original_line": 1, - "combined_line": 4755, + "combined_line": 4871, "original_file": "duk_refcount.h" }, { "original_line": 1, - "combined_line": 5481, + "combined_line": 5888, "original_file": "duk_api_internal.h" }, { "original_line": 1, - "combined_line": 5868, + "combined_line": 6282, "original_file": "duk_hstring.h" }, { "original_line": 1, - "combined_line": 6122, + "combined_line": 6548, "original_file": "duk_hobject.h" }, { "original_line": 1, - "combined_line": 7104, + "combined_line": 7538, "original_file": "duk_hcompfunc.h" }, { "original_line": 1, - "combined_line": 7378, + "combined_line": 7798, "original_file": "duk_hnatfunc.h" }, { "original_line": 1, - "combined_line": 7418, + "combined_line": 7843, "original_file": "duk_hboundfunc.h" }, { "original_line": 1, - "combined_line": 7456, + "combined_line": 7886, "original_file": "duk_hbufobj.h" }, { "original_line": 1, - "combined_line": 7584, + "combined_line": 8024, "original_file": "duk_hthread.h" }, { "original_line": 1, - "combined_line": 7993, + "combined_line": 8446, "original_file": "duk_harray.h" }, { "original_line": 1, - "combined_line": 8042, + "combined_line": 8506, "original_file": "duk_henv.h" }, { "original_line": 1, - "combined_line": 8088, + "combined_line": 8562, "original_file": "duk_hbuffer.h" }, { "original_line": 1, - "combined_line": 8425, + "combined_line": 8910, "original_file": "duk_hproxy.h" }, { "original_line": 1, - "combined_line": 8452, + "combined_line": 8942, "original_file": "duk_heap.h" }, { "original_line": 1, - "combined_line": 9176, + "combined_line": 9689, "original_file": "duk_debugger.h" }, { "original_line": 1, - "combined_line": 9328, + "combined_line": 9841, "original_file": "duk_debug.h" }, { "original_line": 1, - "combined_line": 9513, + "combined_line": 10038, "original_file": "duk_error.h" }, { "original_line": 1, - "combined_line": 10039, + "combined_line": 10728, "original_file": "duk_unicode.h" }, { "original_line": 1, - "combined_line": 10330, + "combined_line": 11028, "original_file": "duk_json.h" }, { "original_line": 1, - "combined_line": 10399, + "combined_line": 11097, "original_file": "duk_js.h" }, { "original_line": 1, - "combined_line": 10516, + "combined_line": 11231, "original_file": "duk_numconv.h" }, { "original_line": 1, - "combined_line": 10621, + "combined_line": 11339, "original_file": "duk_bi_protos.h" }, { "original_line": 1, - "combined_line": 10703, + "combined_line": 11421, "original_file": "duk_selftest.h" }, { "original_line": 76, - "combined_line": 10718, + "combined_line": 11436, "original_file": "duk_internal.h" }, { "original_line": 10, - "combined_line": 10720, + "combined_line": 11438, "original_file": "duk_replacements.c" }, { "original_line": 1, - "combined_line": 10793, + "combined_line": 11511, "original_file": "duk_debug_macros.c" }, { "original_line": 1, - "combined_line": 10884, + "combined_line": 11602, "original_file": "duk_builtins.c" }, { "original_line": 1, - "combined_line": 11748, + "combined_line": 12466, "original_file": "duk_error_macros.c" }, { "original_line": 1, - "combined_line": 11903, + "combined_line": 12653, "original_file": "duk_unicode_support.c" }, { "original_line": 1, - "combined_line": 13168, + "combined_line": 13878, "original_file": "duk_util_memrw.c" }, { "original_line": 1, - "combined_line": 13316, + "combined_line": 14026, "original_file": "duk_util_misc.c" }, { "original_line": 1, - "combined_line": 13499, + "combined_line": 14191, "original_file": "duk_hobject_class.c" }, { "original_line": 1, - "combined_line": 13628, + "combined_line": 14320, "original_file": "duk_alloc_default.c" }, { "original_line": 1, - "combined_line": 13662, + "combined_line": 14352, "original_file": "duk_api_buffer.c" }, { "original_line": 1, - "combined_line": 13735, + "combined_line": 14425, "original_file": "duk_api_bytecode.c" }, { "original_line": 1, - "combined_line": 14503, + "combined_line": 15204, "original_file": "duk_api_call.c" }, { "original_line": 1, - "combined_line": 15019, + "combined_line": 15722, "original_file": "duk_api_codec.c" }, { "original_line": 1, - "combined_line": 15945, + "combined_line": 16653, "original_file": "duk_api_compile.c" }, { "original_line": 1, - "combined_line": 16117, + "combined_line": 16827, "original_file": "duk_api_debug.c" }, { "original_line": 1, - "combined_line": 16378, + "combined_line": 17088, "original_file": "duk_api_heap.c" }, { "original_line": 1, - "combined_line": 16589, + "combined_line": 17297, "original_file": "duk_api_inspect.c" }, { "original_line": 1, - "combined_line": 16834, + "combined_line": 17568, "original_file": "duk_api_memory.c" }, { "original_line": 1, - "combined_line": 16914, + "combined_line": 17648, "original_file": "duk_api_object.c" }, { "original_line": 1, - "combined_line": 17964, + "combined_line": 18686, "original_file": "duk_api_random.c" }, { "original_line": 1, - "combined_line": 17973, + "combined_line": 18695, "original_file": "duk_api_stack.c" }, { "original_line": 1, - "combined_line": 24851, + "combined_line": 25603, "original_file": "duk_api_string.c" }, { "original_line": 1, - "combined_line": 25229, + "combined_line": 25982, "original_file": "duk_api_time.c" }, { "original_line": 1, - "combined_line": 25339, + "combined_line": 26092, "original_file": "duk_bi_array.c" }, { "original_line": 1, - "combined_line": 26994, + "combined_line": 27746, "original_file": "duk_bi_boolean.c" }, { "original_line": 1, - "combined_line": 27063, + "combined_line": 27815, "original_file": "duk_bi_buffer.c" }, { "original_line": 1, - "combined_line": 29999, + "combined_line": 30744, "original_file": "duk_bi_cbor.c" }, { "original_line": 1, - "combined_line": 31739, + "combined_line": 32667, "original_file": "duk_bi_date.c" }, { "original_line": 1, - "combined_line": 33557, + "combined_line": 34566, "original_file": "duk_bi_date_unix.c" }, { "original_line": 1, - "combined_line": 33886, + "combined_line": 34914, "original_file": "duk_bi_date_windows.c" }, { "original_line": 1, - "combined_line": 34079, + "combined_line": 35109, "original_file": "duk_bi_duktape.c" }, { "original_line": 1, - "combined_line": 34237, + "combined_line": 35259, "original_file": "duk_bi_encoding.c" }, { "original_line": 1, - "combined_line": 34775, + "combined_line": 35796, "original_file": "duk_bi_error.c" }, { "original_line": 1, - "combined_line": 35167, + "combined_line": 36196, "original_file": "duk_bi_function.c" }, { "original_line": 1, - "combined_line": 35620, + "combined_line": 36649, "original_file": "duk_bi_global.c" }, { "original_line": 1, - "combined_line": 36351, + "combined_line": 37369, "original_file": "duk_bi_json.c" }, { "original_line": 1, - "combined_line": 39631, + "combined_line": 40612, "original_file": "duk_bi_math.c" }, { "original_line": 1, - "combined_line": 40150, + "combined_line": 41103, "original_file": "duk_bi_number.c" }, { "original_line": 1, - "combined_line": 40430, + "combined_line": 41368, "original_file": "duk_bi_object.c" }, { "original_line": 1, - "combined_line": 41233, + "combined_line": 42122, "original_file": "duk_bi_performance.c" }, { "original_line": 1, - "combined_line": 41264, + "combined_line": 42153, "original_file": "duk_bi_pointer.c" }, { "original_line": 1, - "combined_line": 41339, + "combined_line": 42227, "original_file": "duk_bi_promise.c" }, { "original_line": 1, - "combined_line": 41383, + "combined_line": 42271, "original_file": "duk_bi_proxy.c" }, { "original_line": 1, - "combined_line": 41481, + "combined_line": 42369, "original_file": "duk_bi_reflect.c" }, { "original_line": 1, - "combined_line": 41580, + "combined_line": 42468, "original_file": "duk_bi_regexp.c" }, { "original_line": 1, - "combined_line": 41806, + "combined_line": 42692, "original_file": "duk_bi_string.c" }, { "original_line": 1, - "combined_line": 43416, + "combined_line": 44307, "original_file": "duk_bi_symbol.c" }, { "original_line": 1, - "combined_line": 43586, + "combined_line": 44479, "original_file": "duk_bi_thread.c" }, { "original_line": 1, - "combined_line": 43912, + "combined_line": 44803, "original_file": "duk_bi_thrower.c" }, { "original_line": 1, - "combined_line": 43921, + "combined_line": 44812, "original_file": "duk_debug_fixedbuffer.c" }, { "original_line": 1, - "combined_line": 43990, + "combined_line": 44881, "original_file": "duk_debug_vsnprintf.c" }, { "original_line": 1, - "combined_line": 45090, + "combined_line": 46085, "original_file": "duk_debugger.c" }, { "original_line": 1, - "combined_line": 48004, + "combined_line": 48984, "original_file": "duk_error_augment.c" }, { "original_line": 1, - "combined_line": 48592, + "combined_line": 49586, "original_file": "duk_error_longjmp.c" }, { "original_line": 1, - "combined_line": 48695, + "combined_line": 49693, "original_file": "duk_error_misc.c" }, { "original_line": 1, - "combined_line": 48869, + "combined_line": 49866, "original_file": "duk_error_throw.c" }, { "original_line": 1, - "combined_line": 49031, + "combined_line": 50025, "original_file": "duk_hbuffer_alloc.c" }, { "original_line": 1, - "combined_line": 49163, + "combined_line": 50156, "original_file": "duk_hbuffer_assert.c" }, { "original_line": 1, - "combined_line": 49176, + "combined_line": 50169, "original_file": "duk_hbuffer_ops.c" }, { "original_line": 2, - "combined_line": 49255, + "combined_line": 50247, "original_file": "duk_hbufobj_misc.c" }, { "original_line": 1, - "combined_line": 49274, + "combined_line": 50266, "original_file": "duk_heap_alloc.c" }, { "original_line": 1, - "combined_line": 50499, + "combined_line": 51493, "original_file": "duk_heap_finalize.c" }, { "original_line": 1, - "combined_line": 50944, + "combined_line": 51942, "original_file": "duk_heap_hashstring.c" }, { "original_line": 1, - "combined_line": 51065, + "combined_line": 52063, "original_file": "duk_heap_markandsweep.c" }, { "original_line": 1, - "combined_line": 52551, + "combined_line": 53571, "original_file": "duk_heap_memory.c" }, { "original_line": 1, - "combined_line": 52963, + "combined_line": 53983, "original_file": "duk_heap_misc.c" }, { "original_line": 1, - "combined_line": 53150, + "combined_line": 54170, "original_file": "duk_heap_refcount.c" }, { "original_line": 1, - "combined_line": 53996, + "combined_line": 55029, "original_file": "duk_heap_stringcache.c" }, { "original_line": 1, - "combined_line": 54305, + "combined_line": 55349, "original_file": "duk_heap_stringtable.c" }, { "original_line": 1, - "combined_line": 55354, + "combined_line": 56419, "original_file": "duk_heaphdr_assert.c" }, { "original_line": 1, - "combined_line": 55432, + "combined_line": 56497, "original_file": "duk_hobject_alloc.c" }, { "original_line": 1, - "combined_line": 55703, + "combined_line": 56768, "original_file": "duk_hobject_assert.c" }, { "original_line": 1, - "combined_line": 55830, + "combined_line": 56892, "original_file": "duk_hobject_enum.c" }, { "original_line": 1, - "combined_line": 56546, + "combined_line": 57612, "original_file": "duk_hobject_misc.c" }, { "original_line": 1, - "combined_line": 56599, + "combined_line": 57668, "original_file": "duk_hobject_pc2line.c" }, { "original_line": 1, - "combined_line": 56843, + "combined_line": 57914, "original_file": "duk_hobject_props.c" }, { "original_line": 1, - "combined_line": 63058, + "combined_line": 64276, "original_file": "duk_hstring_assert.c" }, { "original_line": 1, - "combined_line": 63071, + "combined_line": 64289, "original_file": "duk_hstring_misc.c" }, { "original_line": 1, - "combined_line": 63267, + "combined_line": 64485, "original_file": "duk_hthread_alloc.c" }, { "original_line": 1, - "combined_line": 63326, + "combined_line": 64544, "original_file": "duk_hthread_builtins.c" }, { "original_line": 1, - "combined_line": 64212, + "combined_line": 65445, "original_file": "duk_hthread_misc.c" }, { "original_line": 1, - "combined_line": 64309, + "combined_line": 65542, "original_file": "duk_hthread_stacks.c" }, { "original_line": 1, - "combined_line": 64716, + "combined_line": 65947, "original_file": "duk_js_arith.c" }, { "original_line": 1, - "combined_line": 64853, + "combined_line": 66088, "original_file": "duk_js_call.c" }, { "original_line": 1, - "combined_line": 67790, + "combined_line": 69036, "original_file": "duk_js_compiler.c" }, { "original_line": 1, - "combined_line": 75900, + "combined_line": 77176, "original_file": "duk_js_executor.c" }, { "original_line": 1, - "combined_line": 81165, + "combined_line": 82498, "original_file": "duk_js_ops.c" }, { "original_line": 1, - "combined_line": 82643, + "combined_line": 83954, "original_file": "duk_js_var.c" }, { "original_line": 1, - "combined_line": 84440, + "combined_line": 85745, "original_file": "duk_lexer.c" }, { "original_line": 1, - "combined_line": 86901, + "combined_line": 88196, "original_file": "duk_numconv.c" }, { "original_line": 1, - "combined_line": 89194, + "combined_line": 90538, "original_file": "duk_regexp_compiler.c" }, { "original_line": 1, - "combined_line": 90485, + "combined_line": 91841, "original_file": "duk_regexp_executor.c" }, { "original_line": 1, - "combined_line": 91514, + "combined_line": 92896, "original_file": "duk_selftest.c" }, { "original_line": 2, - "combined_line": 92201, + "combined_line": 93643, "original_file": "duk_tval.c" }, { "original_line": 1, - "combined_line": 92352, + "combined_line": 93794, "original_file": "duk_unicode_tables.c" }, { "original_line": 1, - "combined_line": 98527, + "combined_line": 99969, "original_file": "duk_util_bitdecoder.c" }, { "original_line": 1, - "combined_line": 98693, + "combined_line": 100133, "original_file": "duk_util_bitencoder.c" }, { "original_line": 1, - "combined_line": 98736, + "combined_line": 100176, "original_file": "duk_util_bufwriter.c" }, { "original_line": 1, - "combined_line": 99022, + "combined_line": 100462, "original_file": "duk_util_cast.c" }, { "original_line": 1, - "combined_line": 99190, + "combined_line": 100634, "original_file": "duk_util_double.c" }, { "original_line": 1, - "combined_line": 99533, + "combined_line": 100977, "original_file": "duk_util_hashbytes.c" }, { "original_line": 1, - "combined_line": 99594, + "combined_line": 101039, "original_file": "duk_util_memory.c" }, { "original_line": 1, - "combined_line": 99630, + "combined_line": 101075, "original_file": "duk_util_tinyrandom.c" } , - "duk_version": 20600, - "git_branch": "v2-maintenance", - "git_commit": "fffa346eff06a8764b02c31d4336f63a773a95c3", + "duk_version": 20700, + "git_branch": "HEAD", + "git_commit": "03d4d728f8365021de6955c649e6dcd05dcca99f", "builtin_strings_info": { "plain": "Undefined", @@ -1738,7 +1738,7 @@ "c3RhdGlj", "eWllbGQ=" , - "git_describe": "v2.6.0", + "git_describe": "03d4d72-dirty", "builtin_strings": "Undefined", "Null",
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-noline/duktape.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-noline/duktape.c
Changed
@@ -1,8 +1,8 @@ /* - * Single source autogenerated distributable for Duktape 2.6.0. + * Single source autogenerated distributable for Duktape 2.7.0. * - * Git commit fffa346eff06a8764b02c31d4336f63a773a95c3 (v2.6.0). - * Git branch v2-maintenance. + * Git commit 03d4d728f8365021de6955c649e6dcd05dcca99f (03d4d72-dirty). + * Git branch HEAD. * * See Duktape AUTHORS.rst and LICENSE.txt for copyright and * licensing information. @@ -16,7 +16,7 @@ * * (http://opensource.org/licenses/MIT) * -* Copyright (c) 2013-2019 by Duktape authors (see AUTHORS.rst) +* Copyright (c) 2013-present by Duktape authors (see AUTHORS.rst) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -105,6 +105,12 @@ * * Luis de Bethencourt (https://github.com/luisbg) * * Ian Whyman (https://github.com/v00d00) * * Rick Sayre (https://github.com/whorfin) +* * Craig Leres (https://github.com/leres) +* * Maurici Abad (https://github.com/mauriciabad) +* * Nancy Li (https://github.com/NancyLi1013) +* * William Parks (https://github.com/WilliamParks) +* * Sam Hellawell (https://github.com/samhellawell) +* * Vladislavs Sokurenko (https://github.com/sokurenko) * * Other contributions * =================== @@ -266,7 +272,7 @@ duk_uint16_t us4; duk_uint8_t uc8; #if defined(DUK_USE_PACKED_TVAL) - void *vp2; /* used by packed duk_tval, assumes sizeof(void *) == 4 */ + void *vp2; /* used by packed duk_tval, assumes sizeof(void *) == 4 */ #endif }; @@ -278,64 +284,64 @@ #if defined(DUK_USE_DOUBLE_LE) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 +#define DUK_DBL_IDX_ULL0 0 #endif -#define DUK_DBL_IDX_UI0 1 -#define DUK_DBL_IDX_UI1 0 -#define DUK_DBL_IDX_US0 3 -#define DUK_DBL_IDX_US1 2 -#define DUK_DBL_IDX_US2 1 -#define DUK_DBL_IDX_US3 0 -#define DUK_DBL_IDX_UC0 7 -#define DUK_DBL_IDX_UC1 6 -#define DUK_DBL_IDX_UC2 5 -#define DUK_DBL_IDX_UC3 4 -#define DUK_DBL_IDX_UC4 3 -#define DUK_DBL_IDX_UC5 2 -#define DUK_DBL_IDX_UC6 1 -#define DUK_DBL_IDX_UC7 0 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 1 +#define DUK_DBL_IDX_UI1 0 +#define DUK_DBL_IDX_US0 3 +#define DUK_DBL_IDX_US1 2 +#define DUK_DBL_IDX_US2 1 +#define DUK_DBL_IDX_US3 0 +#define DUK_DBL_IDX_UC0 7 +#define DUK_DBL_IDX_UC1 6 +#define DUK_DBL_IDX_UC2 5 +#define DUK_DBL_IDX_UC3 4 +#define DUK_DBL_IDX_UC4 3 +#define DUK_DBL_IDX_UC5 2 +#define DUK_DBL_IDX_UC6 1 +#define DUK_DBL_IDX_UC7 0 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #elif defined(DUK_USE_DOUBLE_BE) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 +#define DUK_DBL_IDX_ULL0 0 #endif -#define DUK_DBL_IDX_UI0 0 -#define DUK_DBL_IDX_UI1 1 -#define DUK_DBL_IDX_US0 0 -#define DUK_DBL_IDX_US1 1 -#define DUK_DBL_IDX_US2 2 -#define DUK_DBL_IDX_US3 3 -#define DUK_DBL_IDX_UC0 0 -#define DUK_DBL_IDX_UC1 1 -#define DUK_DBL_IDX_UC2 2 -#define DUK_DBL_IDX_UC3 3 -#define DUK_DBL_IDX_UC4 4 -#define DUK_DBL_IDX_UC5 5 -#define DUK_DBL_IDX_UC6 6 -#define DUK_DBL_IDX_UC7 7 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 0 +#define DUK_DBL_IDX_UI1 1 +#define DUK_DBL_IDX_US0 0 +#define DUK_DBL_IDX_US1 1 +#define DUK_DBL_IDX_US2 2 +#define DUK_DBL_IDX_US3 3 +#define DUK_DBL_IDX_UC0 0 +#define DUK_DBL_IDX_UC1 1 +#define DUK_DBL_IDX_UC2 2 +#define DUK_DBL_IDX_UC3 3 +#define DUK_DBL_IDX_UC4 4 +#define DUK_DBL_IDX_UC5 5 +#define DUK_DBL_IDX_UC6 6 +#define DUK_DBL_IDX_UC7 7 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #elif defined(DUK_USE_DOUBLE_ME) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */ +#define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */ #endif -#define DUK_DBL_IDX_UI0 0 -#define DUK_DBL_IDX_UI1 1 -#define DUK_DBL_IDX_US0 1 -#define DUK_DBL_IDX_US1 0 -#define DUK_DBL_IDX_US2 3 -#define DUK_DBL_IDX_US3 2 -#define DUK_DBL_IDX_UC0 3 -#define DUK_DBL_IDX_UC1 2 -#define DUK_DBL_IDX_UC2 1 -#define DUK_DBL_IDX_UC3 0 -#define DUK_DBL_IDX_UC4 7 -#define DUK_DBL_IDX_UC5 6 -#define DUK_DBL_IDX_UC6 5 -#define DUK_DBL_IDX_UC7 4 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 0 +#define DUK_DBL_IDX_UI1 1 +#define DUK_DBL_IDX_US0 1 +#define DUK_DBL_IDX_US1 0 +#define DUK_DBL_IDX_US2 3 +#define DUK_DBL_IDX_US3 2 +#define DUK_DBL_IDX_UC0 3 +#define DUK_DBL_IDX_UC1 2 +#define DUK_DBL_IDX_UC2 1 +#define DUK_DBL_IDX_UC3 0 +#define DUK_DBL_IDX_UC4 7 +#define DUK_DBL_IDX_UC5 6 +#define DUK_DBL_IDX_UC6 5 +#define DUK_DBL_IDX_UC7 4 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #else #error internal error #endif @@ -345,57 +351,63 @@ * by duk_numconv.c and duk_tval.h. */ -#define DUK_DBLUNION_SET_DOUBLE(u,v) do { \ +#define DUK_DBLUNION_SET_DOUBLE(u, v) \ + do { \ (u)->d = (v); \ } while (0) -#define DUK_DBLUNION_SET_HIGH32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) (v); \ } while (0) #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = (duk_uint64_t) (v); \ } while (0) #else -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = ((duk_uint64_t) (v)) << 32; \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) (v); \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) 0; \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ -#define DUK_DBLUNION_SET_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_LOW32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d) -#define DUK_DBLUNION_GET_HIGH32(u) ((u)->uiDUK_DBL_IDX_UI0) -#define DUK_DBLUNION_GET_LOW32(u) ((u)->uiDUK_DBL_IDX_UI1) +#define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d) +#define DUK_DBLUNION_GET_HIGH32(u) ((u)->uiDUK_DBL_IDX_UI0) +#define DUK_DBLUNION_GET_LOW32(u) ((u)->uiDUK_DBL_IDX_UI1) #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_SET_UINT64(u,v) do { \ +#define DUK_DBLUNION_SET_UINT64(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) ((v) >> 32); \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_UINT64(u) \ - ((((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI0) << 32) | \ - ((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI1)) +#define DUK_DBLUNION_GET_UINT64(u) ((((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI1)) #else -#define DUK_DBLUNION_SET_UINT64(u,v) do { \ +#define DUK_DBLUNION_SET_UINT64(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = (duk_uint64_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_UINT64(u) ((u)->ullDUK_DBL_IDX_ULL0) +#define DUK_DBLUNION_GET_UINT64(u) ((u)->ullDUK_DBL_IDX_ULL0) #endif -#define DUK_DBLUNION_SET_INT64(u,v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v)) -#define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u))) -#endif /* DUK_USE_64BIT_OPS */ +#define DUK_DBLUNION_SET_INT64(u, v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v)) +#define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u))) +#endif /* DUK_USE_64BIT_OPS */ /* * Double NaN manipulation macros related to NaN normalization needed when @@ -426,102 +438,85 @@ #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) /* Macros for 64-bit ops + mixed endian doubles. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = DUK_U64_CONSTANT(0x000000007ff80000); \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x000000007ff00000)) == DUK_U64_CONSTANT(0x000000007ff00000)) && \ ((((u)->ullDUK_DBL_IDX_ULL0) & DUK_U64_CONSTANT(0xffffffff000fffff)) != 0)) -#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff80000)) +#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff80000)) #define DUK__DBLUNION_IS_ANYINF(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0xffffffff7fffffff)) == DUK_U64_CONSTANT(0x000000007ff00000)) -#define DUK__DBLUNION_IS_POSINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff00000)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x00000000fff00000)) +#define DUK__DBLUNION_IS_POSINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff00000)) +#define DUK__DBLUNION_IS_NEGINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x00000000fff00000)) #define DUK__DBLUNION_IS_ANYZERO(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0xffffffff7fffffff)) == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000080000000)) +#define DUK__DBLUNION_IS_POSZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) +#define DUK__DBLUNION_IS_NEGZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000080000000)) #else /* Macros for 64-bit ops + big/little endian doubles. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = DUK_U64_CONSTANT(0x7ff8000000000000); \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7ff0000000000000)) == DUK_U64_CONSTANT(0x7ff0000000000000)) && \ ((((u)->ullDUK_DBL_IDX_ULL0) & DUK_U64_CONSTANT(0x000fffffffffffff)) != 0)) -#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff8000000000000)) +#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff8000000000000)) #define DUK__DBLUNION_IS_ANYINF(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7fffffffffffffff)) == DUK_U64_CONSTANT(0x7ff0000000000000)) -#define DUK__DBLUNION_IS_POSINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff0000000000000)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0xfff0000000000000)) +#define DUK__DBLUNION_IS_POSINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff0000000000000)) +#define DUK__DBLUNION_IS_NEGINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0xfff0000000000000)) #define DUK__DBLUNION_IS_ANYZERO(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7fffffffffffffff)) == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x8000000000000000)) +#define DUK__DBLUNION_IS_POSZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) +#define DUK__DBLUNION_IS_NEGZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x8000000000000000)) #endif -#else /* DUK_USE_64BIT_OPS */ +#else /* DUK_USE_64BIT_OPS */ /* Macros for no 64-bit ops, any endianness. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) 0x7ff80000UL; \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) 0x00000000UL; \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->uiDUK_DBL_IDX_UI0 & 0x7ff00000UL) == 0x7ff00000UL) && \ - (((u)->uiDUK_DBL_IDX_UI0 & 0x000fffffUL) != 0 || \ - (u)->uiDUK_DBL_IDX_UI1 != 0)) + (((u)->uiDUK_DBL_IDX_UI0 & 0x000fffffUL) != 0 || (u)->uiDUK_DBL_IDX_UI1 != 0)) #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff80000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) + (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff80000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) #define DUK__DBLUNION_IS_ANYINF(u) \ - ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x7ff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_POSINF(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0xfff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) + ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x7ff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_POSINF(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_NEGINF(u) (((u)->uiDUK_DBL_IDX_UI0 == 0xfff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) #define DUK__DBLUNION_IS_ANYZERO(u) \ - ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x00000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x00000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x80000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#endif /* DUK_USE_64BIT_OPS */ + ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x00000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_POSZERO(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x00000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_NEGZERO(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x80000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#endif /* DUK_USE_64BIT_OPS */ -#define DUK__DBLUNION_SET_NAN_NOTFULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_NOTFULL(u) \ + do { \ (u)->usDUK_DBL_IDX_US0 = 0x7ff8UL; \ } while (0) #define DUK__DBLUNION_IS_NAN_NOTFULL(u) \ /* E == 0x7ff, topmost four bits of F != 0 => assume NaN */ \ - ((((u)->usDUK_DBL_IDX_US0 & 0x7ff0UL) == 0x7ff0UL) && \ - (((u)->usDUK_DBL_IDX_US0 & 0x000fUL) != 0x0000UL)) + ((((u)->usDUK_DBL_IDX_US0 & 0x7ff0UL) == 0x7ff0UL) && (((u)->usDUK_DBL_IDX_US0 & 0x000fUL) != 0x0000UL)) #define DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL(u) \ /* E == 0x7ff, F == 8 => normalized NaN */ \ ((u)->usDUK_DBL_IDX_US0 == 0x7ff8UL) -#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) do { \ +#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) \ + do { \ if (DUK__DBLUNION_IS_NAN_FULL((u))) { \ DUK__DBLUNION_SET_NAN_FULL((u)); \ } \ } while (0) -#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) do { \ +#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) \ + do { \ /* Check must be full. */ \ if (DUK__DBLUNION_IS_NAN_FULL((u))) { \ DUK__DBLUNION_SET_NAN_NOTFULL((u)); \ @@ -535,29 +530,30 @@ */ #if defined(DUK_USE_PACKED_TVAL) -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u)) -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u)) -#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d)) +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u)) +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u)) +#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d)) #if 0 -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u)) -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u)) -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u)) -#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d)) +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u)) +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u)) +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u)) +#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d)) #endif #define DUK_DBLUNION_IS_NORMALIZED(u) \ - (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \ - DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */ -#else /* DUK_USE_PACKED_TVAL */ -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */ -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ -#define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */ -#define DUK_DBLUNION_SET_NAN(u) do { \ + (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \ + DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */ +#else /* DUK_USE_PACKED_TVAL */ +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */ +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ +#define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */ +#define DUK_DBLUNION_SET_NAN(u) \ + do { \ /* in non-packed representation we don't care about which NaN is used */ \ (u)->d = DUK_DOUBLE_NAN; \ } while (0) -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ #define DUK_DBLUNION_IS_ANYINF(u) DUK__DBLUNION_IS_ANYINF((u)) #define DUK_DBLUNION_IS_POSINF(u) DUK__DBLUNION_IS_POSINF((u)) @@ -570,7 +566,8 @@ /* XXX: native 64-bit byteswaps when available */ /* 64-bit byteswap, same operation independent of target endianness. */ -#define DUK_DBLUNION_BSWAP64(u) do { \ +#define DUK_DBLUNION_BSWAP64(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -584,7 +581,8 @@ * order. For a big endian target this is a no-op. */ #if defined(DUK_USE_DOUBLE_LE) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { \ +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -594,7 +592,8 @@ (u)->ui1 = duk__bswaptmp1; \ } while (0) #elif defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { \ +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -604,7 +603,9 @@ (u)->ui1 = duk__bswaptmp2; \ } while (0) #elif defined(DUK_USE_DOUBLE_BE) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { } while (0) +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ + } while (0) #else #error internal error, double endianness insane #endif @@ -621,7 +622,7 @@ #define DUK_DBLUNION_GET_SIGNBIT(u) (((u)->uiDUK_DBL_IDX_UI0 >> 31U)) #endif -#endif /* DUK_DBLUNION_H_INCLUDED */ +#endif /* DUK_DBLUNION_H_INCLUDED */ /* #include duk_fltunion.h */ /* * Union to access IEEE float memory representation. @@ -642,26 +643,26 @@ typedef union duk_float_union duk_float_union; #if defined(DUK_USE_DOUBLE_LE) || defined(DUK_USE_DOUBLE_ME) -#define DUK_FLT_IDX_UI0 0 -#define DUK_FLT_IDX_US0 1 -#define DUK_FLT_IDX_US1 0 -#define DUK_FLT_IDX_UC0 3 -#define DUK_FLT_IDX_UC1 2 -#define DUK_FLT_IDX_UC2 1 -#define DUK_FLT_IDX_UC3 0 +#define DUK_FLT_IDX_UI0 0 +#define DUK_FLT_IDX_US0 1 +#define DUK_FLT_IDX_US1 0 +#define DUK_FLT_IDX_UC0 3 +#define DUK_FLT_IDX_UC1 2 +#define DUK_FLT_IDX_UC2 1 +#define DUK_FLT_IDX_UC3 0 #elif defined(DUK_USE_DOUBLE_BE) -#define DUK_FLT_IDX_UI0 0 -#define DUK_FLT_IDX_US0 0 -#define DUK_FLT_IDX_US1 1 -#define DUK_FLT_IDX_UC0 0 -#define DUK_FLT_IDX_UC1 1 -#define DUK_FLT_IDX_UC2 2 -#define DUK_FLT_IDX_UC3 3 +#define DUK_FLT_IDX_UI0 0 +#define DUK_FLT_IDX_US0 0 +#define DUK_FLT_IDX_US1 1 +#define DUK_FLT_IDX_UC0 0 +#define DUK_FLT_IDX_UC1 1 +#define DUK_FLT_IDX_UC2 2 +#define DUK_FLT_IDX_UC3 3 #else #error internal error #endif -#endif /* DUK_FLTUNION_H_INCLUDED */ +#endif /* DUK_FLTUNION_H_INCLUDED */ /* #include duk_replacements.h */ #if !defined(DUK_REPLACEMENTS_H_INCLUDED) #define DUK_REPLACEMENTS_H_INCLUDED @@ -673,7 +674,7 @@ #if defined(DUK_USE_COMPUTED_NAN) DUK_INTERNAL_DECL double duk_computed_nan; #endif -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ #if defined(DUK_USE_REPL_FPCLASSIFY) DUK_INTERNAL_DECL int duk_repl_fpclassify(double x); @@ -691,7 +692,7 @@ DUK_INTERNAL_DECL int duk_repl_isinf(double x); #endif -#endif /* DUK_REPLACEMENTS_H_INCLUDED */ +#endif /* DUK_REPLACEMENTS_H_INCLUDED */ /* #include duk_jmpbuf.h */ /* * Wrapper for jmp_buf. @@ -708,7 +709,7 @@ #if defined(DUK_USE_CPP_EXCEPTIONS) struct duk_jmpbuf { - duk_small_int_t dummy; /* unused */ + duk_small_int_t dummy; /* unused */ }; #else struct duk_jmpbuf { @@ -716,7 +717,7 @@ }; #endif -#endif /* DUK_JMPBUF_H_INCLUDED */ +#endif /* DUK_JMPBUF_H_INCLUDED */ /* #include duk_exception.h */ /* * Exceptions for Duktape internal throws when C++ exceptions are used @@ -742,12 +743,13 @@ * aware of the "unsafe to continue" semantics. */ class duk_fatal_exception : public virtual std::runtime_error { - public: - duk_fatal_exception(const char *message) : std::runtime_error(message) {} + public: + duk_fatal_exception(const char *message) : std::runtime_error(message) { + } }; #endif -#endif /* DUK_EXCEPTION_H_INCLUDED */ +#endif /* DUK_EXCEPTION_H_INCLUDED */ /* #include duk_forwdecl.h */ /* * Forward declarations for all Duktape structures. @@ -882,7 +884,7 @@ typedef struct duk_re_matcher_ctx duk_re_matcher_ctx; typedef struct duk_re_compiler_ctx duk_re_compiler_ctx; -#endif /* DUK_FORWDECL_H_INCLUDED */ +#endif /* DUK_FORWDECL_H_INCLUDED */ /* #include duk_tval.h */ /* * Tagged type definition (duk_tval) and accessor macros. @@ -927,30 +929,29 @@ } duk_tval_unused; /* tags */ -#define DUK_TAG_NORMALIZED_NAN 0x7ff8UL /* the NaN variant we use */ +#define DUK_TAG_NORMALIZED_NAN 0x7ff8UL /* the NaN variant we use */ /* avoid tag 0xfff0, no risk of confusion with negative infinity */ -#define DUK_TAG_MIN 0xfff1UL +#define DUK_TAG_MIN 0xfff1UL #if defined(DUK_USE_FASTINT) -#define DUK_TAG_FASTINT 0xfff1UL /* embed: integer value */ +#define DUK_TAG_FASTINT 0xfff1UL /* embed: integer value */ #endif -#define DUK_TAG_UNUSED 0xfff2UL /* marker; not actual tagged value */ -#define DUK_TAG_UNDEFINED 0xfff3UL /* embed: nothing */ -#define DUK_TAG_NULL 0xfff4UL /* embed: nothing */ -#define DUK_TAG_BOOLEAN 0xfff5UL /* embed: 0 or 1 (false or true) */ +#define DUK_TAG_UNUSED 0xfff2UL /* marker; not actual tagged value */ +#define DUK_TAG_UNDEFINED 0xfff3UL /* embed: nothing */ +#define DUK_TAG_NULL 0xfff4UL /* embed: nothing */ +#define DUK_TAG_BOOLEAN 0xfff5UL /* embed: 0 or 1 (false or true) */ /* DUK_TAG_NUMBER would logically go here, but it has multiple 'tags' */ -#define DUK_TAG_POINTER 0xfff6UL /* embed: void ptr */ -#define DUK_TAG_LIGHTFUNC 0xfff7UL /* embed: func ptr */ -#define DUK_TAG_STRING 0xfff8UL /* embed: duk_hstring ptr */ -#define DUK_TAG_OBJECT 0xfff9UL /* embed: duk_hobject ptr */ -#define DUK_TAG_BUFFER 0xfffaUL /* embed: duk_hbuffer ptr */ -#define DUK_TAG_MAX 0xfffaUL +#define DUK_TAG_POINTER 0xfff6UL /* embed: void ptr */ +#define DUK_TAG_LIGHTFUNC 0xfff7UL /* embed: func ptr */ +#define DUK_TAG_STRING 0xfff8UL /* embed: duk_hstring ptr */ +#define DUK_TAG_OBJECT 0xfff9UL /* embed: duk_hobject ptr */ +#define DUK_TAG_BUFFER 0xfffaUL /* embed: duk_hbuffer ptr */ +#define DUK_TAG_MAX 0xfffaUL /* for convenience */ -#define DUK_XTAG_BOOLEAN_FALSE 0xfff50000UL -#define DUK_XTAG_BOOLEAN_TRUE 0xfff50001UL +#define DUK_XTAG_BOOLEAN_FALSE 0xfff50000UL +#define DUK_XTAG_BOOLEAN_TRUE 0xfff50001UL -#define DUK_TVAL_IS_VALID_TAG(tv) \ - (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) +#define DUK_TVAL_IS_VALID_TAG(tv) (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) /* DUK_TVAL_UNUSED initializer for duk_tval_unused, works for any endianness. */ #define DUK_TVAL_UNUSED_INITIALIZER() \ @@ -959,116 +960,136 @@ /* two casts to avoid gcc warning: "warning: cast from pointer to integer of different size -Wpointer-to-int-cast" */ #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) (tag)) << 16) | (((duk_uint64_t) (duk_uint32_t) (h)) << 32); \ } while (0) #else -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) (tag)) << 48) | ((duk_uint64_t) (duk_uint32_t) (h)); \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) (tag)) << 16; \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (h); \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ #if defined(DUK_USE_64BIT_OPS) /* Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size) */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 16) | \ - ((duk_uint64_t) (flags)) | \ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 16) | ((duk_uint64_t) (flags)) | \ (((duk_uint64_t) (duk_uint32_t) (fp)) << 32); \ } while (0) #else -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 48) | \ - (((duk_uint64_t) (flags)) << 32) | \ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 48) | (((duk_uint64_t) (flags)) << 32) | \ ((duk_uint64_t) (duk_uint32_t) (fp)); \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = (((duk_uint32_t) DUK_TAG_LIGHTFUNC) << 16) | ((duk_uint32_t) (flags)); \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (fp); \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ #if defined(DUK_USE_FASTINT) /* Note: masking is done for 'i' to deal with negative numbers correctly */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_I48(tv,i) do { \ +#define DUK__TVAL_SET_I48(tv, i) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ - duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) DUK_TAG_FASTINT) << 16 | (((duk_uint32_t) ((i) >> 32)) & 0x0000ffffUL); \ + duk__tv->uiDUK_DBL_IDX_UI0 = \ + ((duk_uint32_t) DUK_TAG_FASTINT) << 16 | (((duk_uint32_t) ((i) >> 32)) & 0x0000ffffUL); \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (i); \ } while (0) -#define DUK__TVAL_SET_U32(tv,i) do { \ +#define DUK__TVAL_SET_U32(tv, i) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) DUK_TAG_FASTINT) << 16; \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (i); \ } while (0) #else -#define DUK__TVAL_SET_I48(tv,i) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & DUK_U64_CONSTANT(0x0000ffffffffffff)); \ +#define DUK__TVAL_SET_I48(tv, i) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = \ + (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & DUK_U64_CONSTANT(0x0000ffffffffffff)); \ } while (0) -#define DUK__TVAL_SET_U32(tv,i) do { \ +#define DUK__TVAL_SET_U32(tv, i) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (duk_uint64_t) (i); \ } while (0) #endif /* This needs to go through a cast because sign extension is needed. */ -#define DUK__TVAL_SET_I32(tv,i) do { \ +#define DUK__TVAL_SET_I32(tv, i) \ + do { \ duk_int64_t duk__tmp = (duk_int64_t) (i); \ DUK_TVAL_SET_I48((tv), duk__tmp); \ } while (0) /* XXX: Clumsy sign extend and masking of 16 topmost bits. */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_GET_FASTINT(tv) (((duk_int64_t) ((((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI1))) << 16 >> 16) -#else -#define DUK__TVAL_GET_FASTINT(tv) ((((duk_int64_t) (tv)->ullDUK_DBL_IDX_ULL0) << 16) >> 16) -#endif -#define DUK__TVAL_GET_FASTINT_U32(tv) ((tv)->uiDUK_DBL_IDX_UI1) -#define DUK__TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) (tv)->uiDUK_DBL_IDX_UI1) -#endif /* DUK_USE_FASTINT */ +#define DUK__TVAL_GET_FASTINT(tv) \ + (((duk_int64_t) ((((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI1))) \ + << 16 >> \ + 16) +#else +#define DUK__TVAL_GET_FASTINT(tv) ((((duk_int64_t) (tv)->ullDUK_DBL_IDX_ULL0) << 16) >> 16) +#endif +#define DUK__TVAL_GET_FASTINT_U32(tv) ((tv)->uiDUK_DBL_IDX_UI1) +#define DUK__TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) (tv)->uiDUK_DBL_IDX_UI1) +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_UNDEFINED(tv) do { \ +#define DUK_TVAL_SET_UNDEFINED(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_UNDEFINED; \ } while (0) -#define DUK_TVAL_SET_UNUSED(tv) do { \ +#define DUK_TVAL_SET_UNUSED(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_UNUSED; \ } while (0) -#define DUK_TVAL_SET_NULL(tv) do { \ +#define DUK_TVAL_SET_NULL(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_NULL; \ } while (0) -#define DUK_TVAL_SET_BOOLEAN(tv,val) DUK_DBLUNION_SET_HIGH32((tv), (((duk_uint32_t) DUK_TAG_BOOLEAN) << 16) | ((duk_uint32_t) (val))) +#define DUK_TVAL_SET_BOOLEAN(tv, val) \ + DUK_DBLUNION_SET_HIGH32((tv), (((duk_uint32_t) DUK_TAG_BOOLEAN) << 16) | ((duk_uint32_t) (val))) -#define DUK_TVAL_SET_NAN(tv) DUK_DBLUNION_SET_NAN_FULL((tv)) +#define DUK_TVAL_SET_NAN(tv) DUK_DBLUNION_SET_NAN_FULL((tv)) /* Assumes that caller has normalized NaNs, otherwise trouble ahead. */ #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_DOUBLE(tv,d) do { \ +#define DUK_TVAL_SET_DOUBLE(tv, d) \ + do { \ duk_double_t duk__dblval; \ duk__dblval = (d); \ DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \ DUK_DBLUNION_SET_DOUBLE((tv), duk__dblval); \ } while (0) -#define DUK_TVAL_SET_I48(tv,i) DUK__TVAL_SET_I48((tv), (i)) -#define DUK_TVAL_SET_I32(tv,i) DUK__TVAL_SET_I32((tv), (i)) -#define DUK_TVAL_SET_U32(tv,i) DUK__TVAL_SET_U32((tv), (i)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) duk_tval_set_number_chkfast_fast((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) duk_tval_set_number_chkfast_slow((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { \ +#define DUK_TVAL_SET_I48(tv, i) DUK__TVAL_SET_I48((tv), (i)) +#define DUK_TVAL_SET_I32(tv, i) DUK__TVAL_SET_I32((tv), (i)) +#define DUK_TVAL_SET_U32(tv, i) DUK__TVAL_SET_U32((tv), (i)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) duk_tval_set_number_chkfast_fast((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) duk_tval_set_number_chkfast_slow((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -1077,7 +1098,8 @@ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(duk__tv, duk__d); \ } \ } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { \ +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -1086,89 +1108,98 @@ DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(duk__tv, duk__d); \ } \ } while (0) -#else /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_DOUBLE(tv,d) do { \ +#else /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_DOUBLE(tv, d) \ + do { \ duk_double_t duk__dblval; \ duk__dblval = (d); \ DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \ DUK_DBLUNION_SET_DOUBLE((tv), duk__dblval); \ } while (0) -#define DUK_TVAL_SET_I48(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_I32(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) -#define DUK_TVAL_SET_U32(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { } while (0) -#endif /* DUK_USE_FASTINT */ - -#define DUK_TVAL_SET_FASTINT(tv,i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ - -#define DUK_TVAL_SET_LIGHTFUNC(tv,fp,flags) DUK__TVAL_SET_LIGHTFUNC((tv), (fp), (flags)) -#define DUK_TVAL_SET_STRING(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_STRING) -#define DUK_TVAL_SET_OBJECT(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_OBJECT) -#define DUK_TVAL_SET_BUFFER(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_BUFFER) -#define DUK_TVAL_SET_POINTER(tv,p) DUK__TVAL_SET_TAGGEDPOINTER((tv), (p), DUK_TAG_POINTER) - -#define DUK_TVAL_SET_TVAL(tv,x) do { *(tv) = *(x); } while (0) +#define DUK_TVAL_SET_I48(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_I32(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) +#define DUK_TVAL_SET_U32(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ + } while (0) +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ + } while (0) +#endif /* DUK_USE_FASTINT */ + +#define DUK_TVAL_SET_FASTINT(tv, i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ + +#define DUK_TVAL_SET_LIGHTFUNC(tv, fp, flags) DUK__TVAL_SET_LIGHTFUNC((tv), (fp), (flags)) +#define DUK_TVAL_SET_STRING(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_STRING) +#define DUK_TVAL_SET_OBJECT(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_OBJECT) +#define DUK_TVAL_SET_BUFFER(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_BUFFER) +#define DUK_TVAL_SET_POINTER(tv, p) DUK__TVAL_SET_TAGGEDPOINTER((tv), (p), DUK_TAG_POINTER) + +#define DUK_TVAL_SET_TVAL(tv, x) \ + do { \ + *(tv) = *(x); \ + } while (0) /* getters */ -#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US1) +#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US1) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) -#define DUK_TVAL_GET_FASTINT(tv) DUK__TVAL_GET_FASTINT((tv)) -#define DUK_TVAL_GET_FASTINT_U32(tv) DUK__TVAL_GET_FASTINT_U32((tv)) -#define DUK_TVAL_GET_FASTINT_I32(tv) DUK__TVAL_GET_FASTINT_I32((tv)) -#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_packed((tv)) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) +#define DUK_TVAL_GET_FASTINT(tv) DUK__TVAL_GET_FASTINT((tv)) +#define DUK_TVAL_GET_FASTINT_U32(tv) DUK__TVAL_GET_FASTINT_U32((tv)) +#define DUK_TVAL_GET_FASTINT_I32(tv) DUK__TVAL_GET_FASTINT_I32((tv)) +#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_packed((tv)) #else -#define DUK_TVAL_GET_NUMBER(tv) ((tv)->d) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) +#define DUK_TVAL_GET_NUMBER(tv) ((tv)->d) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) #endif -#define DUK_TVAL_GET_LIGHTFUNC(tv,out_fp,out_flags) do { \ +#define DUK_TVAL_GET_LIGHTFUNC(tv, out_fp, out_flags) \ + do { \ (out_flags) = (tv)->uiDUK_DBL_IDX_UI0 & 0xffffUL; \ (out_fp) = (duk_c_function) (tv)->uiDUK_DBL_IDX_UI1; \ } while (0) -#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((duk_c_function) ((tv)->uiDUK_DBL_IDX_UI1)) -#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) (((duk_small_uint_t) (tv)->uiDUK_DBL_IDX_UI0) & 0xffffUL) -#define DUK_TVAL_GET_STRING(tv) ((duk_hstring *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_OBJECT(tv) ((duk_hobject *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_BUFFER(tv) ((duk_hbuffer *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_POINTER(tv) ((void *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_HEAPHDR(tv) ((duk_heaphdr *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((duk_c_function) ((tv)->uiDUK_DBL_IDX_UI1)) +#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) (((duk_small_uint_t) (tv)->uiDUK_DBL_IDX_UI0) & 0xffffUL) +#define DUK_TVAL_GET_STRING(tv) ((duk_hstring *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_OBJECT(tv) ((duk_hobject *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_BUFFER(tv) ((duk_hbuffer *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_POINTER(tv) ((void *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_HEAPHDR(tv) ((duk_heaphdr *) (tv)->vpDUK_DBL_IDX_VP1) /* decoding */ -#define DUK_TVAL_GET_TAG(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US0) +#define DUK_TVAL_GET_TAG(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US0) -#define DUK_TVAL_IS_UNDEFINED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNDEFINED) -#define DUK_TVAL_IS_UNUSED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNUSED) -#define DUK_TVAL_IS_NULL(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_NULL) -#define DUK_TVAL_IS_BOOLEAN(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BOOLEAN) -#define DUK_TVAL_IS_BOOLEAN_TRUE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_TRUE) -#define DUK_TVAL_IS_BOOLEAN_FALSE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_FALSE) -#define DUK_TVAL_IS_LIGHTFUNC(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_LIGHTFUNC) -#define DUK_TVAL_IS_STRING(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_STRING) -#define DUK_TVAL_IS_OBJECT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_OBJECT) -#define DUK_TVAL_IS_BUFFER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BUFFER) -#define DUK_TVAL_IS_POINTER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_POINTER) +#define DUK_TVAL_IS_UNDEFINED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNDEFINED) +#define DUK_TVAL_IS_UNUSED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNUSED) +#define DUK_TVAL_IS_NULL(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_NULL) +#define DUK_TVAL_IS_BOOLEAN(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BOOLEAN) +#define DUK_TVAL_IS_BOOLEAN_TRUE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_TRUE) +#define DUK_TVAL_IS_BOOLEAN_FALSE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_FALSE) +#define DUK_TVAL_IS_LIGHTFUNC(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_LIGHTFUNC) +#define DUK_TVAL_IS_STRING(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_STRING) +#define DUK_TVAL_IS_OBJECT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_OBJECT) +#define DUK_TVAL_IS_BUFFER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BUFFER) +#define DUK_TVAL_IS_POINTER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_POINTER) #if defined(DUK_USE_FASTINT) /* 0xfff0 is -Infinity */ -#define DUK_TVAL_IS_DOUBLE(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) -#define DUK_TVAL_IS_FASTINT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_FASTINT) -#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff1UL) +#define DUK_TVAL_IS_DOUBLE(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) +#define DUK_TVAL_IS_FASTINT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_FASTINT) +#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff1UL) #else -#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) -#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) +#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) +#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) #endif /* This is performance critical because it appears in every DECREF. */ -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) (DUK_TVAL_GET_TAG((tv)) >= DUK_TAG_STRING) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) (DUK_TVAL_GET_TAG((tv)) >= DUK_TAG_STRING) #if defined(DUK_USE_FASTINT) DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_packed(duk_tval *tv); #endif -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ /* ======================================================================== */ /* @@ -1192,7 +1223,7 @@ duk_double_t d; duk_small_int_t i; #if defined(DUK_USE_FASTINT) - duk_int64_t fi; /* if present, forces 16-byte duk_tval */ + duk_int64_t fi; /* if present, forces 16-byte duk_tval */ #endif void *voidptr; duk_hstring *hstring; @@ -1220,24 +1251,23 @@ #define DUK_TVAL_UNUSED_INITIALIZER() \ { DUK_TAG_UNUSED, 0, 0.0 } -#define DUK_TAG_MIN 0 -#define DUK_TAG_NUMBER 0 /* DUK_TAG_NUMBER only defined for non-packed duk_tval */ +#define DUK_TAG_MIN 0 +#define DUK_TAG_NUMBER 0 /* DUK_TAG_NUMBER only defined for non-packed duk_tval */ #if defined(DUK_USE_FASTINT) -#define DUK_TAG_FASTINT 1 +#define DUK_TAG_FASTINT 1 #endif -#define DUK_TAG_UNDEFINED 2 -#define DUK_TAG_NULL 3 -#define DUK_TAG_BOOLEAN 4 -#define DUK_TAG_POINTER 5 -#define DUK_TAG_LIGHTFUNC 6 -#define DUK_TAG_UNUSED 7 /* marker; not actual tagged type */ -#define DUK_TAG_STRING 8 /* first heap allocated, match bit boundary */ -#define DUK_TAG_OBJECT 9 -#define DUK_TAG_BUFFER 10 -#define DUK_TAG_MAX 10 +#define DUK_TAG_UNDEFINED 2 +#define DUK_TAG_NULL 3 +#define DUK_TAG_BOOLEAN 4 +#define DUK_TAG_POINTER 5 +#define DUK_TAG_LIGHTFUNC 6 +#define DUK_TAG_UNUSED 7 /* marker; not actual tagged type */ +#define DUK_TAG_STRING 8 /* first heap allocated, match bit boundary */ +#define DUK_TAG_OBJECT 9 +#define DUK_TAG_BUFFER 10 +#define DUK_TAG_MAX 10 -#define DUK_TVAL_IS_VALID_TAG(tv) \ - (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) +#define DUK_TVAL_IS_VALID_TAG(tv) (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) /* DUK_TAG_NUMBER is intentionally first, as it is the default clause in code * to support the 8-byte representation. Further, it is a non-heap-allocated @@ -1246,25 +1276,29 @@ */ /* setters */ -#define DUK_TVAL_SET_UNDEFINED(tv) do { \ +#define DUK_TVAL_SET_UNDEFINED(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_UNDEFINED; \ } while (0) -#define DUK_TVAL_SET_UNUSED(tv) do { \ +#define DUK_TVAL_SET_UNUSED(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_UNUSED; \ } while (0) -#define DUK_TVAL_SET_NULL(tv) do { \ +#define DUK_TVAL_SET_NULL(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_NULL; \ } while (0) -#define DUK_TVAL_SET_BOOLEAN(tv,val) do { \ +#define DUK_TVAL_SET_BOOLEAN(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_BOOLEAN; \ @@ -1272,7 +1306,8 @@ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_DOUBLE(tv,val) do { \ +#define DUK_TVAL_SET_DOUBLE(tv, val) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__dblval; \ duk__dblval = (val); \ @@ -1281,31 +1316,32 @@ duk__tv->t = DUK_TAG_NUMBER; \ duk__tv->v.d = duk__dblval; \ } while (0) -#define DUK_TVAL_SET_I48(tv,val) do { \ +#define DUK_TVAL_SET_I48(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (val); \ } while (0) -#define DUK_TVAL_SET_U32(tv,val) do { \ +#define DUK_TVAL_SET_U32(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (duk_int64_t) (val); \ } while (0) -#define DUK_TVAL_SET_I32(tv,val) do { \ +#define DUK_TVAL_SET_I32(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (duk_int64_t) (val); \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) \ - duk_tval_set_number_chkfast_fast((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) \ - duk_tval_set_number_chkfast_slow((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,val) \ - DUK_TVAL_SET_DOUBLE((tv), (val)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) duk_tval_set_number_chkfast_fast((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) duk_tval_set_number_chkfast_slow((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, val) DUK_TVAL_SET_DOUBLE((tv), (val)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -1314,7 +1350,8 @@ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(duk__tv, duk__d); \ } \ } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { \ +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -1323,16 +1360,13 @@ DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(duk__tv, duk__d); \ } \ } while (0) -#else /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_DOUBLE(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_SET_I48(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_U32(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) -#define DUK_TVAL_SET_I32(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) -#define DUK_TVAL_SET_NUMBER(tv,val) do { \ +#else /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_DOUBLE(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_SET_I48(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_U32(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) +#define DUK_TVAL_SET_I32(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) +#define DUK_TVAL_SET_NUMBER(tv, val) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__dblval; \ duk__dblval = (val); \ @@ -1341,25 +1375,28 @@ duk__tv->t = DUK_TAG_NUMBER; \ duk__tv->v.d = duk__dblval; \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { } while (0) -#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ + } while (0) +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ + } while (0) +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT(tv,i) \ - DUK_TVAL_SET_I48((tv), (i)) /* alias */ +#define DUK_TVAL_SET_FASTINT(tv, i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ -#define DUK_TVAL_SET_POINTER(tv,hptr) do { \ +#define DUK_TVAL_SET_POINTER(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_POINTER; \ duk__tv->v.voidptr = (hptr); \ } while (0) -#define DUK_TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ +#define DUK_TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_LIGHTFUNC; \ @@ -1367,28 +1404,32 @@ duk__tv->v.lightfunc = (duk_c_function) (fp); \ } while (0) -#define DUK_TVAL_SET_STRING(tv,hptr) do { \ +#define DUK_TVAL_SET_STRING(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_STRING; \ duk__tv->v.hstring = (hptr); \ } while (0) -#define DUK_TVAL_SET_OBJECT(tv,hptr) do { \ +#define DUK_TVAL_SET_OBJECT(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_OBJECT; \ duk__tv->v.hobject = (hptr); \ } while (0) -#define DUK_TVAL_SET_BUFFER(tv,hptr) do { \ +#define DUK_TVAL_SET_BUFFER(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_BUFFER; \ duk__tv->v.hbuffer = (hptr); \ } while (0) -#define DUK_TVAL_SET_NAN(tv) do { \ +#define DUK_TVAL_SET_NAN(tv) \ + do { \ /* in non-packed representation we don't care about which NaN is used */ \ duk_tval *duk__tv; \ duk__tv = (tv); \ @@ -1396,32 +1437,32 @@ duk__tv->v.d = DUK_DOUBLE_NAN; \ } while (0) -#define DUK_TVAL_SET_TVAL(tv,x) do { *(tv) = *(x); } while (0) +#define DUK_TVAL_SET_TVAL(tv, x) \ + do { \ + *(tv) = *(x); \ + } while (0) /* getters */ -#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->v.i) +#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->v.i) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) -#define DUK_TVAL_GET_FASTINT(tv) ((tv)->v.fi) -#define DUK_TVAL_GET_FASTINT_U32(tv) ((duk_uint32_t) ((tv)->v.fi)) -#define DUK_TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) ((tv)->v.fi)) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) +#define DUK_TVAL_GET_FASTINT(tv) ((tv)->v.fi) +#define DUK_TVAL_GET_FASTINT_U32(tv) ((duk_uint32_t) ((tv)->v.fi)) +#define DUK_TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) ((tv)->v.fi)) #if 0 -#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? \ - (duk_double_t) DUK_TVAL_GET_FASTINT((tv)) : \ - DUK_TVAL_GET_DOUBLE((tv))) -#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_unpacked((tv)) +#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? (duk_double_t) DUK_TVAL_GET_FASTINT((tv)) : DUK_TVAL_GET_DOUBLE((tv))) +#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_unpacked((tv)) #else /* This seems reasonable overall. */ -#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? \ - duk_tval_get_number_unpacked_fastint((tv)) : \ - DUK_TVAL_GET_DOUBLE((tv))) +#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? duk_tval_get_number_unpacked_fastint((tv)) : DUK_TVAL_GET_DOUBLE((tv))) #endif #else -#define DUK_TVAL_GET_NUMBER(tv) ((tv)->v.d) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_GET_POINTER(tv) ((tv)->v.voidptr) -#define DUK_TVAL_GET_LIGHTFUNC(tv,out_fp,out_flags) do { \ +#define DUK_TVAL_GET_NUMBER(tv) ((tv)->v.d) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_GET_POINTER(tv) ((tv)->v.voidptr) +#define DUK_TVAL_GET_LIGHTFUNC(tv, out_fp, out_flags) \ + do { \ (out_flags) = (duk_uint32_t) (tv)->v_extra; \ (out_fp) = (tv)->v.lightfunc; \ } while (0) @@ -1441,19 +1482,18 @@ #define DUK_TVAL_IS_BOOLEAN_TRUE(tv) (((tv)->t == DUK_TAG_BOOLEAN) && ((tv)->v.i != 0)) #define DUK_TVAL_IS_BOOLEAN_FALSE(tv) (((tv)->t == DUK_TAG_BOOLEAN) && ((tv)->v.i == 0)) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_IS_DOUBLE(tv) ((tv)->t == DUK_TAG_NUMBER) -#define DUK_TVAL_IS_FASTINT(tv) ((tv)->t == DUK_TAG_FASTINT) -#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER || \ - (tv)->t == DUK_TAG_FASTINT) -#else -#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER) -#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_IS_POINTER(tv) ((tv)->t == DUK_TAG_POINTER) -#define DUK_TVAL_IS_LIGHTFUNC(tv) ((tv)->t == DUK_TAG_LIGHTFUNC) -#define DUK_TVAL_IS_STRING(tv) ((tv)->t == DUK_TAG_STRING) -#define DUK_TVAL_IS_OBJECT(tv) ((tv)->t == DUK_TAG_OBJECT) -#define DUK_TVAL_IS_BUFFER(tv) ((tv)->t == DUK_TAG_BUFFER) +#define DUK_TVAL_IS_DOUBLE(tv) ((tv)->t == DUK_TAG_NUMBER) +#define DUK_TVAL_IS_FASTINT(tv) ((tv)->t == DUK_TAG_FASTINT) +#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER || (tv)->t == DUK_TAG_FASTINT) +#else +#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER) +#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_IS_POINTER(tv) ((tv)->t == DUK_TAG_POINTER) +#define DUK_TVAL_IS_LIGHTFUNC(tv) ((tv)->t == DUK_TAG_LIGHTFUNC) +#define DUK_TVAL_IS_STRING(tv) ((tv)->t == DUK_TAG_STRING) +#define DUK_TVAL_IS_OBJECT(tv) ((tv)->t == DUK_TAG_OBJECT) +#define DUK_TVAL_IS_BUFFER(tv) ((tv)->t == DUK_TAG_BUFFER) /* This is performance critical because it's needed for every DECREF. * Take advantage of the fact that the first heap allocated tag is 8, @@ -1461,9 +1501,9 @@ * non-heap-allocated tags). */ #if 0 -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t >= DUK_TAG_STRING) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t >= DUK_TAG_STRING) #endif -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t & 0x08) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t & 0x08) #if defined(DUK_USE_FASTINT) #if 0 @@ -1472,44 +1512,39 @@ DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_unpacked_fastint(duk_tval *tv); #endif -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ /* * Convenience (independent of representation) */ -#define DUK_TVAL_SET_BOOLEAN_TRUE(tv) DUK_TVAL_SET_BOOLEAN((tv), 1) -#define DUK_TVAL_SET_BOOLEAN_FALSE(tv) DUK_TVAL_SET_BOOLEAN((tv), 0) +#define DUK_TVAL_SET_BOOLEAN_TRUE(tv) DUK_TVAL_SET_BOOLEAN((tv), 1) +#define DUK_TVAL_SET_BOOLEAN_FALSE(tv) DUK_TVAL_SET_BOOLEAN((tv), 0) -#define DUK_TVAL_STRING_IS_SYMBOL(tv) \ - DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING((tv))) +#define DUK_TVAL_STRING_IS_SYMBOL(tv) DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING((tv))) /* Lightfunc flags packing and unpacking. */ /* Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss##. * Avoid signed shifts due to portability limitations. */ -#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags) \ - ((duk_int32_t) (duk_int8_t) (((duk_uint16_t) (lf_flags)) >> 8)) -#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags) \ - (((lf_flags) >> 4) & 0x0fU) -#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags) \ - ((lf_flags) & 0x0fU) -#define DUK_LFUNC_FLAGS_PACK(magic,length,nargs) \ - ((((duk_small_uint_t) (magic)) & 0xffU) << 8) | ((length) << 4) | (nargs) - -#define DUK_LFUNC_NARGS_VARARGS 0x0f /* varargs marker */ -#define DUK_LFUNC_NARGS_MIN 0x00 -#define DUK_LFUNC_NARGS_MAX 0x0e /* max, excl. varargs marker */ -#define DUK_LFUNC_LENGTH_MIN 0x00 -#define DUK_LFUNC_LENGTH_MAX 0x0f -#define DUK_LFUNC_MAGIC_MIN (-0x80) -#define DUK_LFUNC_MAGIC_MAX 0x7f +#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags) ((duk_int32_t) (duk_int8_t) (((duk_uint16_t) (lf_flags)) >> 8)) +#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags) (((lf_flags) >> 4) & 0x0fU) +#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags) ((lf_flags) &0x0fU) +#define DUK_LFUNC_FLAGS_PACK(magic, length, nargs) ((((duk_small_uint_t) (magic)) & 0xffU) << 8) | ((length) << 4) | (nargs) + +#define DUK_LFUNC_NARGS_VARARGS 0x0f /* varargs marker */ +#define DUK_LFUNC_NARGS_MIN 0x00 +#define DUK_LFUNC_NARGS_MAX 0x0e /* max, excl. varargs marker */ +#define DUK_LFUNC_LENGTH_MIN 0x00 +#define DUK_LFUNC_LENGTH_MAX 0x0f +#define DUK_LFUNC_MAGIC_MIN (-0x80) +#define DUK_LFUNC_MAGIC_MAX 0x7f /* fastint constants etc */ #if defined(DUK_USE_FASTINT) -#define DUK_FASTINT_MIN (DUK_I64_CONSTANT(-0x800000000000)) -#define DUK_FASTINT_MAX (DUK_I64_CONSTANT(0x7fffffffffff)) -#define DUK_FASTINT_BITS 48 +#define DUK_FASTINT_MIN (DUK_I64_CONSTANT(-0x800000000000)) +#define DUK_FASTINT_MAX (DUK_I64_CONSTANT(0x7fffffffffff)) +#define DUK_FASTINT_BITS 48 DUK_INTERNAL_DECL void duk_tval_set_number_chkfast_fast(duk_tval *tv, duk_double_t x); DUK_INTERNAL_DECL void duk_tval_set_number_chkfast_slow(duk_tval *tv, duk_double_t x); @@ -1517,12 +1552,17 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_tval_assert_valid(duk_tval *tv); -#define DUK_TVAL_ASSERT_VALID(tv) do { duk_tval_assert_valid((tv)); } while (0) +#define DUK_TVAL_ASSERT_VALID(tv) \ + do { \ + duk_tval_assert_valid((tv)); \ + } while (0) #else -#define DUK_TVAL_ASSERT_VALID(tv) do {} while (0) +#define DUK_TVAL_ASSERT_VALID(tv) \ + do { \ + } while (0) #endif -#endif /* DUK_TVAL_H_INCLUDED */ +#endif /* DUK_TVAL_H_INCLUDED */ /* #include duk_builtins.h */ /* * Automatically generated by genbuiltins.py, do not edit! @@ -2324,20 +2364,14 @@ #if !defined(DUK_UTIL_H_INCLUDED) #define DUK_UTIL_H_INCLUDED -#if defined(DUK_USE_GET_RANDOM_DOUBLE) -#define DUK_UTIL_GET_RANDOM_DOUBLE(thr) DUK_USE_GET_RANDOM_DOUBLE((thr)->heap_udata) -#else -#define DUK_UTIL_GET_RANDOM_DOUBLE(thr) duk_util_tinyrandom_get_double(thr) -#endif - /* * Some useful constants */ -#define DUK_DOUBLE_2TO32 4294967296.0 -#define DUK_DOUBLE_2TO31 2147483648.0 -#define DUK_DOUBLE_LOG2E 1.4426950408889634 -#define DUK_DOUBLE_LOG10E 0.4342944819032518 +#define DUK_DOUBLE_2TO32 4294967296.0 +#define DUK_DOUBLE_2TO31 2147483648.0 +#define DUK_DOUBLE_LOG2E 1.4426950408889634 +#define DUK_DOUBLE_LOG10E 0.4342944819032518 /* * Endian conversion @@ -2390,33 +2424,35 @@ * update the pointer argument automatically. */ -#define DUK_RAW_WRITE_U8(ptr,val) do { \ +#define DUK_RAW_WRITE_U8(ptr, val) \ + do { \ *(ptr) = (duk_uint8_t) (val); \ } while (0) -#define DUK_RAW_WRITE_U16_BE(ptr,val) duk_raw_write_u16_be((ptr), (duk_uint16_t) (val)) -#define DUK_RAW_WRITE_U32_BE(ptr,val) duk_raw_write_u32_be((ptr), (duk_uint32_t) (val)) -#define DUK_RAW_WRITE_FLOAT_BE(ptr,val) duk_raw_write_float_be((ptr), (duk_float_t) (val)) -#define DUK_RAW_WRITE_DOUBLE_BE(ptr,val) duk_raw_write_double_be((ptr), (duk_double_t) (val)) -#define DUK_RAW_WRITE_XUTF8(ptr,val) duk_raw_write_xutf8((ptr), (duk_ucodepoint_t) (val)) +#define DUK_RAW_WRITE_U16_BE(ptr, val) duk_raw_write_u16_be((ptr), (duk_uint16_t) (val)) +#define DUK_RAW_WRITE_U32_BE(ptr, val) duk_raw_write_u32_be((ptr), (duk_uint32_t) (val)) +#define DUK_RAW_WRITE_FLOAT_BE(ptr, val) duk_raw_write_float_be((ptr), (duk_float_t) (val)) +#define DUK_RAW_WRITE_DOUBLE_BE(ptr, val) duk_raw_write_double_be((ptr), (duk_double_t) (val)) +#define DUK_RAW_WRITE_XUTF8(ptr, val) duk_raw_write_xutf8((ptr), (duk_ucodepoint_t) (val)) -#define DUK_RAW_WRITEINC_U8(ptr,val) do { \ +#define DUK_RAW_WRITEINC_U8(ptr, val) \ + do { \ *(ptr)++ = (duk_uint8_t) (val); \ } while (0) -#define DUK_RAW_WRITEINC_U16_BE(ptr,val) duk_raw_writeinc_u16_be(&(ptr), (duk_uint16_t) (val)) -#define DUK_RAW_WRITEINC_U32_BE(ptr,val) duk_raw_writeinc_u32_be(&(ptr), (duk_uint32_t) (val)) -#define DUK_RAW_WRITEINC_FLOAT_BE(ptr,val) duk_raw_writeinc_float_be(&(ptr), (duk_float_t) (val)) -#define DUK_RAW_WRITEINC_DOUBLE_BE(ptr,val) duk_raw_writeinc_double_be(&(ptr), (duk_double_t) (val)) -#define DUK_RAW_WRITEINC_XUTF8(ptr,val) duk_raw_writeinc_xutf8(&(ptr), (duk_ucodepoint_t) (val)) -#define DUK_RAW_WRITEINC_CESU8(ptr,val) duk_raw_writeinc_cesu8(&(ptr), (duk_ucodepoint_t) (val)) - -#define DUK_RAW_READ_U8(ptr) ((duk_uint8_t) (*(ptr))) -#define DUK_RAW_READ_U16_BE(ptr) duk_raw_read_u16_be((ptr)); -#define DUK_RAW_READ_U32_BE(ptr) duk_raw_read_u32_be((ptr)); +#define DUK_RAW_WRITEINC_U16_BE(ptr, val) duk_raw_writeinc_u16_be(&(ptr), (duk_uint16_t) (val)) +#define DUK_RAW_WRITEINC_U32_BE(ptr, val) duk_raw_writeinc_u32_be(&(ptr), (duk_uint32_t) (val)) +#define DUK_RAW_WRITEINC_FLOAT_BE(ptr, val) duk_raw_writeinc_float_be(&(ptr), (duk_float_t) (val)) +#define DUK_RAW_WRITEINC_DOUBLE_BE(ptr, val) duk_raw_writeinc_double_be(&(ptr), (duk_double_t) (val)) +#define DUK_RAW_WRITEINC_XUTF8(ptr, val) duk_raw_writeinc_xutf8(&(ptr), (duk_ucodepoint_t) (val)) +#define DUK_RAW_WRITEINC_CESU8(ptr, val) duk_raw_writeinc_cesu8(&(ptr), (duk_ucodepoint_t) (val)) + +#define DUK_RAW_READ_U8(ptr) ((duk_uint8_t) (*(ptr))) +#define DUK_RAW_READ_U16_BE(ptr) duk_raw_read_u16_be((ptr)); +#define DUK_RAW_READ_U32_BE(ptr) duk_raw_read_u32_be((ptr)); #define DUK_RAW_READ_DOUBLE_BE(ptr) duk_raw_read_double_be((ptr)); -#define DUK_RAW_READINC_U8(ptr) ((duk_uint8_t) (*(ptr)++)) -#define DUK_RAW_READINC_U16_BE(ptr) duk_raw_readinc_u16_be(&(ptr)); -#define DUK_RAW_READINC_U32_BE(ptr) duk_raw_readinc_u32_be(&(ptr)); +#define DUK_RAW_READINC_U8(ptr) ((duk_uint8_t) (*(ptr)++)) +#define DUK_RAW_READINC_U16_BE(ptr) duk_raw_readinc_u16_be(&(ptr)); +#define DUK_RAW_READINC_U32_BE(ptr) duk_raw_readinc_u32_be(&(ptr)); #define DUK_RAW_READINC_DOUBLE_BE(ptr) duk_raw_readinc_double_be(&(ptr)); /* @@ -2463,29 +2499,31 @@ }; #if defined(DUK_USE_PREFER_SIZE) -#define DUK_BW_SLACK_ADD 64 -#define DUK_BW_SLACK_SHIFT 4 /* 2^4 -> 1/16 = 6.25% slack */ +#define DUK_BW_SLACK_ADD 64 +#define DUK_BW_SLACK_SHIFT 4 /* 2^4 -> 1/16 = 6.25% slack */ #else -#define DUK_BW_SLACK_ADD 64 -#define DUK_BW_SLACK_SHIFT 2 /* 2^2 -> 1/4 = 25% slack */ +#define DUK_BW_SLACK_ADD 64 +#define DUK_BW_SLACK_SHIFT 2 /* 2^2 -> 1/4 = 25% slack */ #endif /* Initialization and finalization (compaction), converting to other types. */ -#define DUK_BW_INIT_PUSHBUF(thr,bw_ctx,sz) do { \ +#define DUK_BW_INIT_PUSHBUF(thr, bw_ctx, sz) \ + do { \ duk_bw_init_pushbuf((thr), (bw_ctx), (sz)); \ } while (0) -#define DUK_BW_INIT_WITHBUF(thr,bw_ctx,buf) do { \ +#define DUK_BW_INIT_WITHBUF(thr, bw_ctx, buf) \ + do { \ duk_bw_init((thr), (bw_ctx), (buf)); \ } while (0) -#define DUK_BW_COMPACT(thr,bw_ctx) do { \ +#define DUK_BW_COMPACT(thr, bw_ctx) \ + do { \ /* Make underlying buffer compact to match DUK_BW_GET_SIZE(). */ \ duk_bw_compact((thr), (bw_ctx)); \ } while (0) -#define DUK_BW_PUSH_AS_STRING(thr,bw_ctx) do { \ - duk_push_lstring((thr), \ - (const char *) (bw_ctx)->p_base, \ - (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ +#define DUK_BW_PUSH_AS_STRING(thr, bw_ctx) \ + do { \ + duk_push_lstring((thr), (const char *) (bw_ctx)->p_base, (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ } while (0) /* Pointers may be NULL for a while when 'buf' size is zero and before any @@ -2495,43 +2533,48 @@ */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_bw_assert_valid(duk_hthread *thr, duk_bufwriter_ctx *bw_ctx); -#define DUK_BW_ASSERT_VALID_EXPR(thr,bw_ctx) (duk_bw_assert_valid((thr), (bw_ctx))) -#define DUK_BW_ASSERT_VALID(thr,bw_ctx) do { duk_bw_assert_valid((thr), (bw_ctx)); } while (0) +#define DUK_BW_ASSERT_VALID_EXPR(thr, bw_ctx) (duk_bw_assert_valid((thr), (bw_ctx))) +#define DUK_BW_ASSERT_VALID(thr, bw_ctx) \ + do { \ + duk_bw_assert_valid((thr), (bw_ctx)); \ + } while (0) #else -#define DUK_BW_ASSERT_VALID_EXPR(thr,bw_ctx) DUK_ASSERT_EXPR(1) -#define DUK_BW_ASSERT_VALID(thr,bw_ctx) do {} while (0) +#define DUK_BW_ASSERT_VALID_EXPR(thr, bw_ctx) DUK_ASSERT_EXPR(1) +#define DUK_BW_ASSERT_VALID(thr, bw_ctx) \ + do { \ + } while (0) #endif /* Working with the pointer and current size. */ -#define DUK_BW_GET_PTR(thr,bw_ctx) \ - ((bw_ctx)->p) -#define DUK_BW_SET_PTR(thr,bw_ctx,ptr) do { \ +#define DUK_BW_GET_PTR(thr, bw_ctx) ((bw_ctx)->p) +#define DUK_BW_SET_PTR(thr, bw_ctx, ptr) \ + do { \ (bw_ctx)->p = (ptr); \ } while (0) -#define DUK_BW_ADD_PTR(thr,bw_ctx,delta) do { \ +#define DUK_BW_ADD_PTR(thr, bw_ctx, delta) \ + do { \ (bw_ctx)->p += (delta); \ } while (0) -#define DUK_BW_GET_BASEPTR(thr,bw_ctx) \ - ((bw_ctx)->p_base) -#define DUK_BW_GET_LIMITPTR(thr,bw_ctx) \ - ((bw_ctx)->p_limit) -#define DUK_BW_GET_SIZE(thr,bw_ctx) \ - ((duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)) -#define DUK_BW_SET_SIZE(thr,bw_ctx,sz) do { \ +#define DUK_BW_GET_BASEPTR(thr, bw_ctx) ((bw_ctx)->p_base) +#define DUK_BW_GET_LIMITPTR(thr, bw_ctx) ((bw_ctx)->p_limit) +#define DUK_BW_GET_SIZE(thr, bw_ctx) ((duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)) +#define DUK_BW_SET_SIZE(thr, bw_ctx, sz) \ + do { \ DUK_ASSERT((duk_size_t) (sz) <= (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ (bw_ctx)->p = (bw_ctx)->p_base + (sz); \ } while (0) -#define DUK_BW_RESET_SIZE(thr,bw_ctx) do { \ +#define DUK_BW_RESET_SIZE(thr, bw_ctx) \ + do { \ /* Reset to zero size, keep current limit. */ \ (bw_ctx)->p = (bw_ctx)->p_base; \ } while (0) -#define DUK_BW_GET_BUFFER(thr,bw_ctx) \ - ((bw_ctx)->buf) +#define DUK_BW_GET_BUFFER(thr, bw_ctx) ((bw_ctx)->buf) /* Ensuring (reserving) space. */ -#define DUK_BW_ENSURE(thr,bw_ctx,sz) do { \ +#define DUK_BW_ENSURE(thr, bw_ctx, sz) \ + do { \ duk_size_t duk__sz, duk__space; \ DUK_BW_ASSERT_VALID((thr), (bw_ctx)); \ duk__sz = (sz); \ @@ -2542,22 +2585,21 @@ } while (0) /* NOTE: Multiple evaluation of 'ptr' in this macro. */ /* XXX: Rework to use an always-inline function? */ -#define DUK_BW_ENSURE_RAW(thr,bw_ctx,sz,ptr) \ - (((duk_size_t) ((bw_ctx)->p_limit - (ptr)) >= (sz)) ? \ - (ptr) : \ - ((bw_ctx)->p = (ptr), duk_bw_resize((thr),(bw_ctx),(sz)))) -#define DUK_BW_ENSURE_GETPTR(thr,bw_ctx,sz) \ - DUK_BW_ENSURE_RAW((thr), (bw_ctx), (sz), (bw_ctx)->p) -#define DUK_BW_ASSERT_SPACE_EXPR(thr,bw_ctx,sz) \ +#define DUK_BW_ENSURE_RAW(thr, bw_ctx, sz, ptr) \ + (((duk_size_t) ((bw_ctx)->p_limit - (ptr)) >= (sz)) ? (ptr) : ((bw_ctx)->p = (ptr), duk_bw_resize((thr), (bw_ctx), (sz)))) +#define DUK_BW_ENSURE_GETPTR(thr, bw_ctx, sz) DUK_BW_ENSURE_RAW((thr), (bw_ctx), (sz), (bw_ctx)->p) +#define DUK_BW_ASSERT_SPACE_EXPR(thr, bw_ctx, sz) \ (DUK_BW_ASSERT_VALID_EXPR((thr), (bw_ctx)), \ DUK_ASSERT_EXPR((duk_size_t) ((bw_ctx)->p_limit - (bw_ctx)->p) >= (duk_size_t) (sz))) -#define DUK_BW_ASSERT_SPACE(thr,bw_ctx,sz) do { \ +#define DUK_BW_ASSERT_SPACE(thr, bw_ctx, sz) \ + do { \ DUK_BW_ASSERT_SPACE_EXPR((thr), (bw_ctx), (sz)); \ } while (0) /* Miscellaneous. */ -#define DUK_BW_SETPTR_AND_COMPACT(thr,bw_ctx,ptr) do { \ +#define DUK_BW_SETPTR_AND_COMPACT(thr, bw_ctx, ptr) \ + do { \ (bw_ctx)->p = (ptr); \ duk_bw_compact((thr), (bw_ctx)); \ } while (0) @@ -2568,11 +2610,13 @@ * explicit pointer load/stores get generated (e.g. gcc -Os). */ -#define DUK_BW_WRITE_RAW_U8(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_U8(thr, bw_ctx, val) \ + do { \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 1); \ *(bw_ctx)->p++ = (duk_uint8_t) (val); \ } while (0) -#define DUK_BW_WRITE_RAW_U8_2(thr,bw_ctx,val1,val2) do { \ +#define DUK_BW_WRITE_RAW_U8_2(thr, bw_ctx, val1, val2) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 2); \ duk__p = (bw_ctx)->p; \ @@ -2580,7 +2624,8 @@ *duk__p++ = (duk_uint8_t) (val2); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_3(thr,bw_ctx,val1,val2,val3) do { \ +#define DUK_BW_WRITE_RAW_U8_3(thr, bw_ctx, val1, val2, val3) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 3); \ duk__p = (bw_ctx)->p; \ @@ -2589,7 +2634,8 @@ *duk__p++ = (duk_uint8_t) (val3); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_4(thr,bw_ctx,val1,val2,val3,val4) do { \ +#define DUK_BW_WRITE_RAW_U8_4(thr, bw_ctx, val1, val2, val3, val4) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 4); \ duk__p = (bw_ctx)->p; \ @@ -2599,7 +2645,8 @@ *duk__p++ = (duk_uint8_t) (val4); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_5(thr,bw_ctx,val1,val2,val3,val4,val5) do { \ +#define DUK_BW_WRITE_RAW_U8_5(thr, bw_ctx, val1, val2, val3, val4, val5) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 5); \ duk__p = (bw_ctx)->p; \ @@ -2610,7 +2657,8 @@ *duk__p++ = (duk_uint8_t) (val5); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_6(thr,bw_ctx,val1,val2,val3,val4,val5,val6) do { \ +#define DUK_BW_WRITE_RAW_U8_6(thr, bw_ctx, val1, val2, val3, val4, val5, val6) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 6); \ duk__p = (bw_ctx)->p; \ @@ -2622,7 +2670,8 @@ *duk__p++ = (duk_uint8_t) (val6); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_XUTF8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_RAW_XUTF8(thr, bw_ctx, cp) \ + do { \ duk_ucodepoint_t duk__cp; \ duk_small_int_t duk__enc_len; \ duk__cp = (duk_ucodepoint_t) (cp); \ @@ -2630,7 +2679,8 @@ duk__enc_len = duk_unicode_encode_xutf8(duk__cp, (bw_ctx)->p); \ (bw_ctx)->p += duk__enc_len; \ } while (0) -#define DUK_BW_WRITE_RAW_CESU8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_RAW_CESU8(thr, bw_ctx, cp) \ + do { \ duk_ucodepoint_t duk__cp; \ duk_small_int_t duk__enc_len; \ duk__cp = (duk_ucodepoint_t) (cp); \ @@ -2640,7 +2690,8 @@ } while (0) /* XXX: add temporary duk__p pointer here too; sharing */ /* XXX: avoid unsafe variants */ -#define DUK_BW_WRITE_RAW_BYTES(thr,bw_ctx,valptr,valsz) do { \ +#define DUK_BW_WRITE_RAW_BYTES(thr, bw_ctx, valptr, valsz) \ + do { \ const void *duk__valptr; \ duk_size_t duk__valsz; \ duk__valptr = (const void *) (valptr); \ @@ -2648,7 +2699,8 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), duk__valptr, duk__valsz); \ (bw_ctx)->p += duk__valsz; \ } while (0) -#define DUK_BW_WRITE_RAW_CSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_CSTRING(thr, bw_ctx, val) \ + do { \ const duk_uint8_t *duk__val; \ duk_size_t duk__val_len; \ duk__val = (const duk_uint8_t *) (val); \ @@ -2656,93 +2708,107 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) duk__val, duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HSTRING(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HSTRING_GET_BYTELEN((val)); \ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HSTRING_GET_DATA((val)), duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER_FIXED(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER_FIXED(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_FIXED_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER_DYNAMIC(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER_DYNAMIC(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_DYNAMIC_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) /* Append bytes from a slice already in the buffer. */ -#define DUK_BW_WRITE_RAW_SLICE(thr,bw,dst_off,dst_len) \ - duk_bw_write_raw_slice((thr), (bw), (dst_off), (dst_len)) +#define DUK_BW_WRITE_RAW_SLICE(thr, bw, dst_off, dst_len) duk_bw_write_raw_slice((thr), (bw), (dst_off), (dst_len)) /* Insert bytes in the middle of the buffer from an external buffer. */ -#define DUK_BW_INSERT_RAW_BYTES(thr,bw,dst_off,buf,len) \ - duk_bw_insert_raw_bytes((thr), (bw), (dst_off), (buf), (len)) +#define DUK_BW_INSERT_RAW_BYTES(thr, bw, dst_off, buf, len) duk_bw_insert_raw_bytes((thr), (bw), (dst_off), (buf), (len)) /* Insert bytes in the middle of the buffer from a slice already * in the buffer. Source offset is interpreted "before" the operation. */ -#define DUK_BW_INSERT_RAW_SLICE(thr,bw,dst_off,src_off,len) \ - duk_bw_insert_raw_slice((thr), (bw), (dst_off), (src_off), (len)) +#define DUK_BW_INSERT_RAW_SLICE(thr, bw, dst_off, src_off, len) duk_bw_insert_raw_slice((thr), (bw), (dst_off), (src_off), (len)) /* Insert a reserved area somewhere in the buffer; caller fills it. * Evaluates to a (duk_uint_t *) pointing to the start of the reserved * area for convenience. */ -#define DUK_BW_INSERT_RAW_AREA(thr,bw,off,len) \ - duk_bw_insert_raw_area((thr), (bw), (off), (len)) +#define DUK_BW_INSERT_RAW_AREA(thr, bw, off, len) duk_bw_insert_raw_area((thr), (bw), (off), (len)) /* Remove a slice from inside buffer. */ -#define DUK_BW_REMOVE_RAW_SLICE(thr,bw,off,len) \ - duk_bw_remove_raw_slice((thr), (bw), (off), (len)) +#define DUK_BW_REMOVE_RAW_SLICE(thr, bw, off, len) duk_bw_remove_raw_slice((thr), (bw), (off), (len)) /* Safe write calls which will ensure space first. */ -#define DUK_BW_WRITE_ENSURE_U8(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_U8(thr, bw_ctx, val) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 1); \ DUK_BW_WRITE_RAW_U8((thr), (bw_ctx), (val)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_2(thr,bw_ctx,val1,val2) do { \ +#define DUK_BW_WRITE_ENSURE_U8_2(thr, bw_ctx, val1, val2) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 2); \ DUK_BW_WRITE_RAW_U8_2((thr), (bw_ctx), (val1), (val2)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_3(thr,bw_ctx,val1,val2,val3) do { \ +#define DUK_BW_WRITE_ENSURE_U8_3(thr, bw_ctx, val1, val2, val3) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 3); \ DUK_BW_WRITE_RAW_U8_3((thr), (bw_ctx), (val1), (val2), (val3)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_4(thr,bw_ctx,val1,val2,val3,val4) do { \ +#define DUK_BW_WRITE_ENSURE_U8_4(thr, bw_ctx, val1, val2, val3, val4) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 4); \ DUK_BW_WRITE_RAW_U8_4((thr), (bw_ctx), (val1), (val2), (val3), (val4)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_5(thr,bw_ctx,val1,val2,val3,val4,val5) do { \ +#define DUK_BW_WRITE_ENSURE_U8_5(thr, bw_ctx, val1, val2, val3, val4, val5) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 5); \ DUK_BW_WRITE_RAW_U8_5((thr), (bw_ctx), (val1), (val2), (val3), (val4), (val5)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_6(thr,bw_ctx,val1,val2,val3,val4,val5,val6) do { \ +#define DUK_BW_WRITE_ENSURE_U8_6(thr, bw_ctx, val1, val2, val3, val4, val5, val6) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 6); \ DUK_BW_WRITE_RAW_U8_6((thr), (bw_ctx), (val1), (val2), (val3), (val4), (val5), (val6)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_XUTF8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_ENSURE_XUTF8(thr, bw_ctx, cp) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), DUK_UNICODE_MAX_XUTF8_LENGTH); \ DUK_BW_WRITE_RAW_XUTF8((thr), (bw_ctx), (cp)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_CESU8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_ENSURE_CESU8(thr, bw_ctx, cp) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), DUK_UNICODE_MAX_CESU8_LENGTH); \ DUK_BW_WRITE_RAW_CESU8((thr), (bw_ctx), (cp)); \ } while (0) /* XXX: add temporary duk__p pointer here too; sharing */ /* XXX: avoid unsafe */ -#define DUK_BW_WRITE_ENSURE_BYTES(thr,bw_ctx,valptr,valsz) do { \ +#define DUK_BW_WRITE_ENSURE_BYTES(thr, bw_ctx, valptr, valsz) \ + do { \ const void *duk__valptr; \ duk_size_t duk__valsz; \ duk__valptr = (const void *) (valptr); \ @@ -2751,7 +2817,8 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), duk__valptr, duk__valsz); \ (bw_ctx)->p += duk__valsz; \ } while (0) -#define DUK_BW_WRITE_ENSURE_CSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_CSTRING(thr, bw_ctx, val) \ + do { \ const duk_uint8_t *duk__val; \ duk_size_t duk__val_len; \ duk__val = (const duk_uint8_t *) (val); \ @@ -2760,45 +2827,53 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) duk__val, duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HSTRING(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HSTRING_GET_BYTELEN((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HSTRING_GET_DATA((val)), duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER_FIXED(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER_FIXED(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_FIXED_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER_DYNAMIC(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER_DYNAMIC(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_DYNAMIC_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_SLICE(thr,bw,dst_off,dst_len) \ - duk_bw_write_ensure_slice((thr), (bw), (dst_off), (dst_len)) -#define DUK_BW_INSERT_ENSURE_BYTES(thr,bw,dst_off,buf,len) \ - duk_bw_insert_ensure_bytes((thr), (bw), (dst_off), (buf), (len)) -#define DUK_BW_INSERT_ENSURE_SLICE(thr,bw,dst_off,src_off,len) \ +#define DUK_BW_WRITE_ENSURE_SLICE(thr, bw, dst_off, dst_len) duk_bw_write_ensure_slice((thr), (bw), (dst_off), (dst_len)) +#define DUK_BW_INSERT_ENSURE_BYTES(thr, bw, dst_off, buf, len) duk_bw_insert_ensure_bytes((thr), (bw), (dst_off), (buf), (len)) +#define DUK_BW_INSERT_ENSURE_SLICE(thr, bw, dst_off, src_off, len) \ duk_bw_insert_ensure_slice((thr), (bw), (dst_off), (src_off), (len)) -#define DUK_BW_INSERT_ENSURE_AREA(thr,bw,off,len) \ +#define DUK_BW_INSERT_ENSURE_AREA(thr, bw, off, len) \ /* Evaluates to (duk_uint8_t *) pointing to start of area. */ \ duk_bw_insert_ensure_area((thr), (bw), (off), (len)) -#define DUK_BW_REMOVE_ENSURE_SLICE(thr,bw,off,len) \ +#define DUK_BW_REMOVE_ENSURE_SLICE(thr, bw, off, len) \ /* No difference between raw/ensure because the buffer shrinks. */ \ DUK_BW_REMOVE_RAW_SLICE((thr), (bw), (off), (len)) @@ -2814,13 +2889,13 @@ DUK_INTERNAL_DECL const duk_int16_t duk_hex_dectab_shift4256; DUK_INTERNAL_DECL const duk_uint16_t duk_hex_enctab256; #endif -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* Note: assumes that duk_util_probe_steps size is 32 */ #if defined(DUK_USE_HOBJECT_HASH_PART) #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL duk_uint8_t duk_util_probe_steps32; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ #endif #if defined(DUK_USE_STRHASH_DENSE) @@ -2848,10 +2923,26 @@ DUK_INTERNAL_DECL void duk_bw_compact(duk_hthread *thr, duk_bufwriter_ctx *bw_ctx); DUK_INTERNAL_DECL void duk_bw_write_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t src_off, duk_size_t len); DUK_INTERNAL_DECL void duk_bw_write_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t src_off, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_raw_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_ensure_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_raw_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_ensure_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_raw_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_ensure_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len); DUK_INTERNAL_DECL duk_uint8_t *duk_bw_insert_raw_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); DUK_INTERNAL_DECL duk_uint8_t *duk_bw_insert_ensure_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); DUK_INTERNAL_DECL void duk_bw_remove_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); @@ -2878,10 +2969,12 @@ DUK_INTERNAL_DECL void duk_raw_writeinc_xutf8(duk_uint8_t **p, duk_ucodepoint_t val); DUK_INTERNAL_DECL void duk_raw_writeinc_cesu8(duk_uint8_t **p, duk_ucodepoint_t val); -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ DUK_INTERNAL_DECL void duk_byteswap_bytes(duk_uint8_t *p, duk_small_uint_t len); #endif +DUK_INTERNAL_DECL duk_double_t duk_util_get_random_double(duk_hthread *thr); + /* memcpy(), memmove() etc wrappers. The plain variants like duk_memcpy() * assume C99+ and 'src' and 'dst' pointers must be non-NULL even when the * operation size is zero. The unsafe variants like duk_memcpy_safe() deal @@ -2892,7 +2985,8 @@ * few extra bytes per call site adds up to ~1kB footprint. */ #if defined(DUK_USE_ALLOW_UNDEFINED_BEHAVIOR) -#define duk_memcpy(dst,src,len) do { \ +#define duk_memcpy(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2900,8 +2994,9 @@ DUK_ASSERT(duk__src != NULL || duk__len == 0U); \ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memcpy_unsafe(dst,src,len) duk_memcpy((dst), (src), (len)) -#define duk_memmove(dst,src,len) do { \ +#define duk_memcpy_unsafe(dst, src, len) duk_memcpy((dst), (src), (len)) +#define duk_memmove(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2909,24 +3004,27 @@ DUK_ASSERT(duk__src != NULL || duk__len == 0U); \ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memmove_unsafe(dst,src,len) duk_memmove((dst), (src), (len)) -#define duk_memset(dst,val,len) do { \ +#define duk_memmove_unsafe(dst, src, len) duk_memmove((dst), (src), (len)) +#define duk_memset(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } while (0) -#define duk_memset_unsafe(dst,val,len) duk_memset((dst), (val), (len)) -#define duk_memzero(dst,len) do { \ +#define duk_memset_unsafe(dst, val, len) duk_memset((dst), (val), (len)) +#define duk_memzero(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } while (0) -#define duk_memzero_unsafe(dst,len) duk_memzero((dst), (len)) -#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ -#define duk_memcpy(dst,src,len) do { \ +#define duk_memzero_unsafe(dst, len) duk_memzero((dst), (len)) +#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#define duk_memcpy(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2934,7 +3032,8 @@ DUK_ASSERT(duk__src != NULL); \ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memcpy_unsafe(dst,src,len) do { \ +#define duk_memcpy_unsafe(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2946,7 +3045,8 @@ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } \ } while (0) -#define duk_memmove(dst,src,len) do { \ +#define duk_memmove(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2954,7 +3054,8 @@ DUK_ASSERT(duk__src != NULL); \ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memmove_unsafe(dst,src,len) do { \ +#define duk_memmove_unsafe(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2966,14 +3067,16 @@ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } \ } while (0) -#define duk_memset(dst,val,len) do { \ +#define duk_memset(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL); \ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } while (0) -#define duk_memset_unsafe(dst,val,len) do { \ +#define duk_memset_unsafe(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ @@ -2983,13 +3086,15 @@ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } \ } while (0) -#define duk_memzero(dst,len) do { \ +#define duk_memzero(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL); \ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } while (0) -#define duk_memzero_unsafe(dst,len) do { \ +#define duk_memzero_unsafe(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ @@ -2998,7 +3103,7 @@ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } \ } while (0) -#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ DUK_INTERNAL_DECL duk_small_int_t duk_memcmp(const void *s1, const void *s2, duk_size_t len); DUK_INTERNAL_DECL duk_small_int_t duk_memcmp_unsafe(const void *s1, const void *s2, duk_size_t len); @@ -3044,10 +3149,9 @@ * * However, incorrectly true for x == 0 so check for that explicitly. */ -#define DUK_IS_POWER_OF_TWO(x) \ - ((x) != 0U && ((x) & ((x) - 1U)) == 0U) +#define DUK_IS_POWER_OF_TWO(x) ((x) != 0U && ((x) & ((x) -1U)) == 0U) -#endif /* DUK_UTIL_H_INCLUDED */ +#endif /* DUK_UTIL_H_INCLUDED */ /* #include duk_strings.h */ /* * Shared string macros. @@ -3073,151 +3177,151 @@ #define DUK_ERRMSG_H_INCLUDED /* Mostly API and built-in method related */ -#define DUK_STR_INTERNAL_ERROR "internal error" -#define DUK_STR_UNSUPPORTED "unsupported" -#define DUK_STR_INVALID_COUNT "invalid count" -#define DUK_STR_INVALID_ARGS "invalid args" -#define DUK_STR_INVALID_STATE "invalid state" -#define DUK_STR_INVALID_INPUT "invalid input" -#define DUK_STR_INVALID_LENGTH "invalid length" -#define DUK_STR_NOT_CONSTRUCTABLE "not constructable" -#define DUK_STR_CONSTRUCT_ONLY "constructor requires 'new'" -#define DUK_STR_NOT_CALLABLE "not callable" -#define DUK_STR_NOT_EXTENSIBLE "not extensible" -#define DUK_STR_NOT_WRITABLE "not writable" -#define DUK_STR_NOT_CONFIGURABLE "not configurable" -#define DUK_STR_INVALID_CONTEXT "invalid context" -#define DUK_STR_INVALID_INDEX "invalid args" -#define DUK_STR_PUSH_BEYOND_ALLOC_STACK "cannot push beyond allocated stack" -#define DUK_STR_NOT_UNDEFINED "unexpected type" -#define DUK_STR_NOT_NULL "unexpected type" -#define DUK_STR_NOT_BOOLEAN "unexpected type" -#define DUK_STR_NOT_NUMBER "unexpected type" -#define DUK_STR_NOT_STRING "unexpected type" -#define DUK_STR_NOT_OBJECT "unexpected type" -#define DUK_STR_NOT_POINTER "unexpected type" -#define DUK_STR_NOT_BUFFER "not buffer" /* still in use with verbose messages */ -#define DUK_STR_UNEXPECTED_TYPE "unexpected type" -#define DUK_STR_NOT_THREAD "unexpected type" -#define DUK_STR_NOT_COMPFUNC "unexpected type" -#define DUK_STR_NOT_NATFUNC "unexpected type" -#define DUK_STR_NOT_C_FUNCTION "unexpected type" -#define DUK_STR_NOT_FUNCTION "unexpected type" -#define DUK_STR_NOT_REGEXP "unexpected type" -#define DUK_STR_TOPRIMITIVE_FAILED "coercion to primitive failed" -#define DUK_STR_NUMBER_OUTSIDE_RANGE "number outside range" -#define DUK_STR_NOT_OBJECT_COERCIBLE "not object coercible" -#define DUK_STR_CANNOT_NUMBER_COERCE_SYMBOL "cannot number coerce Symbol" -#define DUK_STR_CANNOT_STRING_COERCE_SYMBOL "cannot string coerce Symbol" -#define DUK_STR_STRING_TOO_LONG "string too long" -#define DUK_STR_BUFFER_TOO_LONG "buffer too long" -#define DUK_STR_ALLOC_FAILED "alloc failed" -#define DUK_STR_WRONG_BUFFER_TYPE "wrong buffer type" -#define DUK_STR_BASE64_ENCODE_FAILED "base64 encode failed" -#define DUK_STR_SOURCE_DECODE_FAILED "source decode failed" -#define DUK_STR_UTF8_DECODE_FAILED "utf-8 decode failed" -#define DUK_STR_BASE64_DECODE_FAILED "base64 decode failed" -#define DUK_STR_HEX_DECODE_FAILED "hex decode failed" -#define DUK_STR_INVALID_BYTECODE "invalid bytecode" -#define DUK_STR_NO_SOURCECODE "no sourcecode" -#define DUK_STR_RESULT_TOO_LONG "result too long" -#define DUK_STR_INVALID_CFUNC_RC "invalid C function rc" -#define DUK_STR_INVALID_INSTANCEOF_RVAL "invalid instanceof rval" -#define DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO "instanceof rval has no .prototype" +#define DUK_STR_INTERNAL_ERROR "internal error" +#define DUK_STR_UNSUPPORTED "unsupported" +#define DUK_STR_INVALID_COUNT "invalid count" +#define DUK_STR_INVALID_ARGS "invalid args" +#define DUK_STR_INVALID_STATE "invalid state" +#define DUK_STR_INVALID_INPUT "invalid input" +#define DUK_STR_INVALID_LENGTH "invalid length" +#define DUK_STR_NOT_CONSTRUCTABLE "not constructable" +#define DUK_STR_CONSTRUCT_ONLY "constructor requires 'new'" +#define DUK_STR_NOT_CALLABLE "not callable" +#define DUK_STR_NOT_EXTENSIBLE "not extensible" +#define DUK_STR_NOT_WRITABLE "not writable" +#define DUK_STR_NOT_CONFIGURABLE "not configurable" +#define DUK_STR_INVALID_CONTEXT "invalid context" +#define DUK_STR_INVALID_INDEX "invalid args" +#define DUK_STR_PUSH_BEYOND_ALLOC_STACK "cannot push beyond allocated stack" +#define DUK_STR_NOT_UNDEFINED "unexpected type" +#define DUK_STR_NOT_NULL "unexpected type" +#define DUK_STR_NOT_BOOLEAN "unexpected type" +#define DUK_STR_NOT_NUMBER "unexpected type" +#define DUK_STR_NOT_STRING "unexpected type" +#define DUK_STR_NOT_OBJECT "unexpected type" +#define DUK_STR_NOT_POINTER "unexpected type" +#define DUK_STR_NOT_BUFFER "not buffer" /* still in use with verbose messages */ +#define DUK_STR_UNEXPECTED_TYPE "unexpected type" +#define DUK_STR_NOT_THREAD "unexpected type" +#define DUK_STR_NOT_COMPFUNC "unexpected type" +#define DUK_STR_NOT_NATFUNC "unexpected type" +#define DUK_STR_NOT_C_FUNCTION "unexpected type" +#define DUK_STR_NOT_FUNCTION "unexpected type" +#define DUK_STR_NOT_REGEXP "unexpected type" +#define DUK_STR_TOPRIMITIVE_FAILED "coercion to primitive failed" +#define DUK_STR_NUMBER_OUTSIDE_RANGE "number outside range" +#define DUK_STR_NOT_OBJECT_COERCIBLE "not object coercible" +#define DUK_STR_CANNOT_NUMBER_COERCE_SYMBOL "cannot number coerce Symbol" +#define DUK_STR_CANNOT_STRING_COERCE_SYMBOL "cannot string coerce Symbol" +#define DUK_STR_STRING_TOO_LONG "string too long" +#define DUK_STR_BUFFER_TOO_LONG "buffer too long" +#define DUK_STR_ALLOC_FAILED "alloc failed" +#define DUK_STR_WRONG_BUFFER_TYPE "wrong buffer type" +#define DUK_STR_BASE64_ENCODE_FAILED "base64 encode failed" +#define DUK_STR_SOURCE_DECODE_FAILED "source decode failed" +#define DUK_STR_UTF8_DECODE_FAILED "utf-8 decode failed" +#define DUK_STR_BASE64_DECODE_FAILED "base64 decode failed" +#define DUK_STR_HEX_DECODE_FAILED "hex decode failed" +#define DUK_STR_INVALID_BYTECODE "invalid bytecode" +#define DUK_STR_NO_SOURCECODE "no sourcecode" +#define DUK_STR_RESULT_TOO_LONG "result too long" +#define DUK_STR_INVALID_CFUNC_RC "invalid C function rc" +#define DUK_STR_INVALID_INSTANCEOF_RVAL "invalid instanceof rval" +#define DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO "instanceof rval has no .prototype" /* JSON */ -#define DUK_STR_FMT_PTR "%p" -#define DUK_STR_FMT_INVALID_JSON "invalid json (at offset %ld)" -#define DUK_STR_CYCLIC_INPUT "cyclic input" +#define DUK_STR_FMT_PTR "%p" +#define DUK_STR_FMT_INVALID_JSON "invalid json (at offset %ld)" +#define DUK_STR_CYCLIC_INPUT "cyclic input" /* Generic codec */ -#define DUK_STR_DEC_RECLIMIT "decode recursion limit" -#define DUK_STR_ENC_RECLIMIT "encode recursion limit" +#define DUK_STR_DEC_RECLIMIT "decode recursion limit" +#define DUK_STR_ENC_RECLIMIT "encode recursion limit" /* Object property access */ -#define DUK_STR_INVALID_BASE "invalid base value" -#define DUK_STR_STRICT_CALLER_READ "cannot read strict 'caller'" -#define DUK_STR_PROXY_REJECTED "proxy rejected" -#define DUK_STR_INVALID_ARRAY_LENGTH "invalid array length" -#define DUK_STR_SETTER_UNDEFINED "setter undefined" -#define DUK_STR_INVALID_DESCRIPTOR "invalid descriptor" +#define DUK_STR_INVALID_BASE "invalid base value" +#define DUK_STR_STRICT_CALLER_READ "cannot read strict 'caller'" +#define DUK_STR_PROXY_REJECTED "proxy rejected" +#define DUK_STR_INVALID_ARRAY_LENGTH "invalid array length" +#define DUK_STR_SETTER_UNDEFINED "setter undefined" +#define DUK_STR_INVALID_DESCRIPTOR "invalid descriptor" /* Proxy */ -#define DUK_STR_PROXY_REVOKED "proxy revoked" -#define DUK_STR_INVALID_TRAP_RESULT "invalid trap result" +#define DUK_STR_PROXY_REVOKED "proxy revoked" +#define DUK_STR_INVALID_TRAP_RESULT "invalid trap result" /* Variables */ /* Lexer */ -#define DUK_STR_INVALID_ESCAPE "invalid escape" -#define DUK_STR_UNTERMINATED_STRING "unterminated string" -#define DUK_STR_UNTERMINATED_COMMENT "unterminated comment" -#define DUK_STR_UNTERMINATED_REGEXP "unterminated regexp" -#define DUK_STR_TOKEN_LIMIT "token limit" -#define DUK_STR_REGEXP_SUPPORT_DISABLED "regexp support disabled" -#define DUK_STR_INVALID_NUMBER_LITERAL "invalid number literal" -#define DUK_STR_INVALID_TOKEN "invalid token" +#define DUK_STR_INVALID_ESCAPE "invalid escape" +#define DUK_STR_UNTERMINATED_STRING "unterminated string" +#define DUK_STR_UNTERMINATED_COMMENT "unterminated comment" +#define DUK_STR_UNTERMINATED_REGEXP "unterminated regexp" +#define DUK_STR_TOKEN_LIMIT "token limit" +#define DUK_STR_REGEXP_SUPPORT_DISABLED "regexp support disabled" +#define DUK_STR_INVALID_NUMBER_LITERAL "invalid number literal" +#define DUK_STR_INVALID_TOKEN "invalid token" /* Compiler */ -#define DUK_STR_PARSE_ERROR "parse error" -#define DUK_STR_DUPLICATE_LABEL "duplicate label" -#define DUK_STR_INVALID_LABEL "invalid label" -#define DUK_STR_INVALID_ARRAY_LITERAL "invalid array literal" -#define DUK_STR_INVALID_OBJECT_LITERAL "invalid object literal" -#define DUK_STR_INVALID_VAR_DECLARATION "invalid variable declaration" -#define DUK_STR_CANNOT_DELETE_IDENTIFIER "cannot delete identifier" -#define DUK_STR_INVALID_EXPRESSION "invalid expression" -#define DUK_STR_INVALID_LVALUE "invalid lvalue" -#define DUK_STR_INVALID_NEWTARGET "invalid new.target" -#define DUK_STR_EXPECTED_IDENTIFIER "expected identifier" -#define DUK_STR_EMPTY_EXPR_NOT_ALLOWED "empty expression not allowed" -#define DUK_STR_INVALID_FOR "invalid for statement" -#define DUK_STR_INVALID_SWITCH "invalid switch statement" -#define DUK_STR_INVALID_BREAK_CONT_LABEL "invalid break/continue label" -#define DUK_STR_INVALID_RETURN "invalid return" -#define DUK_STR_INVALID_TRY "invalid try" -#define DUK_STR_INVALID_THROW "invalid throw" -#define DUK_STR_WITH_IN_STRICT_MODE "with in strict mode" -#define DUK_STR_FUNC_STMT_NOT_ALLOWED "function statement not allowed" -#define DUK_STR_UNTERMINATED_STMT "unterminated statement" -#define DUK_STR_INVALID_ARG_NAME "invalid argument name" -#define DUK_STR_INVALID_FUNC_NAME "invalid function name" -#define DUK_STR_INVALID_GETSET_NAME "invalid getter/setter name" -#define DUK_STR_FUNC_NAME_REQUIRED "function name required" +#define DUK_STR_PARSE_ERROR "parse error" +#define DUK_STR_DUPLICATE_LABEL "duplicate label" +#define DUK_STR_INVALID_LABEL "invalid label" +#define DUK_STR_INVALID_ARRAY_LITERAL "invalid array literal" +#define DUK_STR_INVALID_OBJECT_LITERAL "invalid object literal" +#define DUK_STR_INVALID_VAR_DECLARATION "invalid variable declaration" +#define DUK_STR_CANNOT_DELETE_IDENTIFIER "cannot delete identifier" +#define DUK_STR_INVALID_EXPRESSION "invalid expression" +#define DUK_STR_INVALID_LVALUE "invalid lvalue" +#define DUK_STR_INVALID_NEWTARGET "invalid new.target" +#define DUK_STR_EXPECTED_IDENTIFIER "expected identifier" +#define DUK_STR_EMPTY_EXPR_NOT_ALLOWED "empty expression not allowed" +#define DUK_STR_INVALID_FOR "invalid for statement" +#define DUK_STR_INVALID_SWITCH "invalid switch statement" +#define DUK_STR_INVALID_BREAK_CONT_LABEL "invalid break/continue label" +#define DUK_STR_INVALID_RETURN "invalid return" +#define DUK_STR_INVALID_TRY "invalid try" +#define DUK_STR_INVALID_THROW "invalid throw" +#define DUK_STR_WITH_IN_STRICT_MODE "with in strict mode" +#define DUK_STR_FUNC_STMT_NOT_ALLOWED "function statement not allowed" +#define DUK_STR_UNTERMINATED_STMT "unterminated statement" +#define DUK_STR_INVALID_ARG_NAME "invalid argument name" +#define DUK_STR_INVALID_FUNC_NAME "invalid function name" +#define DUK_STR_INVALID_GETSET_NAME "invalid getter/setter name" +#define DUK_STR_FUNC_NAME_REQUIRED "function name required" /* RegExp */ -#define DUK_STR_INVALID_QUANTIFIER "invalid regexp quantifier" -#define DUK_STR_INVALID_QUANTIFIER_NO_ATOM "quantifier without preceding atom" -#define DUK_STR_INVALID_QUANTIFIER_VALUES "quantifier values invalid (qmin > qmax)" -#define DUK_STR_QUANTIFIER_TOO_MANY_COPIES "quantifier requires too many atom copies" -#define DUK_STR_UNEXPECTED_CLOSING_PAREN "unexpected closing parenthesis" -#define DUK_STR_UNEXPECTED_END_OF_PATTERN "unexpected end of pattern" -#define DUK_STR_UNEXPECTED_REGEXP_TOKEN "unexpected token in regexp" -#define DUK_STR_INVALID_REGEXP_FLAGS "invalid regexp flags" -#define DUK_STR_INVALID_REGEXP_ESCAPE "invalid regexp escape" -#define DUK_STR_INVALID_BACKREFS "invalid backreference(s)" -#define DUK_STR_INVALID_REGEXP_CHARACTER "invalid regexp character" -#define DUK_STR_INVALID_REGEXP_GROUP "invalid regexp group" -#define DUK_STR_UNTERMINATED_CHARCLASS "unterminated character class" -#define DUK_STR_INVALID_RANGE "invalid range" +#define DUK_STR_INVALID_QUANTIFIER "invalid regexp quantifier" +#define DUK_STR_INVALID_QUANTIFIER_NO_ATOM "quantifier without preceding atom" +#define DUK_STR_INVALID_QUANTIFIER_VALUES "quantifier values invalid (qmin > qmax)" +#define DUK_STR_QUANTIFIER_TOO_MANY_COPIES "quantifier requires too many atom copies" +#define DUK_STR_UNEXPECTED_CLOSING_PAREN "unexpected closing parenthesis" +#define DUK_STR_UNEXPECTED_END_OF_PATTERN "unexpected end of pattern" +#define DUK_STR_UNEXPECTED_REGEXP_TOKEN "unexpected token in regexp" +#define DUK_STR_INVALID_REGEXP_FLAGS "invalid regexp flags" +#define DUK_STR_INVALID_REGEXP_ESCAPE "invalid regexp escape" +#define DUK_STR_INVALID_BACKREFS "invalid backreference(s)" +#define DUK_STR_INVALID_REGEXP_CHARACTER "invalid regexp character" +#define DUK_STR_INVALID_REGEXP_GROUP "invalid regexp group" +#define DUK_STR_UNTERMINATED_CHARCLASS "unterminated character class" +#define DUK_STR_INVALID_RANGE "invalid range" /* Limits */ -#define DUK_STR_VALSTACK_LIMIT "valstack limit" -#define DUK_STR_CALLSTACK_LIMIT "callstack limit" -#define DUK_STR_PROTOTYPE_CHAIN_LIMIT "prototype chain limit" -#define DUK_STR_BOUND_CHAIN_LIMIT "function call bound chain limit" -#define DUK_STR_NATIVE_STACK_LIMIT "C stack depth limit" -#define DUK_STR_COMPILER_RECURSION_LIMIT "compiler recursion limit" -#define DUK_STR_BYTECODE_LIMIT "bytecode limit" -#define DUK_STR_REG_LIMIT "register limit" -#define DUK_STR_TEMP_LIMIT "temp limit" -#define DUK_STR_CONST_LIMIT "const limit" -#define DUK_STR_FUNC_LIMIT "function limit" -#define DUK_STR_REGEXP_COMPILER_RECURSION_LIMIT "regexp compiler recursion limit" -#define DUK_STR_REGEXP_EXECUTOR_RECURSION_LIMIT "regexp executor recursion limit" -#define DUK_STR_REGEXP_EXECUTOR_STEP_LIMIT "regexp step limit" +#define DUK_STR_VALSTACK_LIMIT "valstack limit" +#define DUK_STR_CALLSTACK_LIMIT "callstack limit" +#define DUK_STR_PROTOTYPE_CHAIN_LIMIT "prototype chain limit" +#define DUK_STR_BOUND_CHAIN_LIMIT "function call bound chain limit" +#define DUK_STR_NATIVE_STACK_LIMIT "C stack depth limit" +#define DUK_STR_COMPILER_RECURSION_LIMIT "compiler recursion limit" +#define DUK_STR_BYTECODE_LIMIT "bytecode limit" +#define DUK_STR_REG_LIMIT "register limit" +#define DUK_STR_TEMP_LIMIT "temp limit" +#define DUK_STR_CONST_LIMIT "const limit" +#define DUK_STR_FUNC_LIMIT "function limit" +#define DUK_STR_REGEXP_COMPILER_RECURSION_LIMIT "regexp compiler recursion limit" +#define DUK_STR_REGEXP_EXECUTOR_RECURSION_LIMIT "regexp executor recursion limit" +#define DUK_STR_REGEXP_EXECUTOR_STEP_LIMIT "regexp step limit" -#endif /* DUK_ERRMSG_H_INCLUDED */ +#endif /* DUK_ERRMSG_H_INCLUDED */ /* #include duk_js_bytecode.h */ /* * ECMAScript bytecode @@ -3304,403 +3408,394 @@ typedef duk_uint32_t duk_instr_t; -#define DUK_BC_SHIFT_OP 0 -#define DUK_BC_SHIFT_A 8 -#define DUK_BC_SHIFT_B 16 -#define DUK_BC_SHIFT_C 24 -#define DUK_BC_SHIFT_BC DUK_BC_SHIFT_B -#define DUK_BC_SHIFT_ABC DUK_BC_SHIFT_A - -#define DUK_BC_UNSHIFTED_MASK_OP 0xffUL -#define DUK_BC_UNSHIFTED_MASK_A 0xffUL -#define DUK_BC_UNSHIFTED_MASK_B 0xffUL -#define DUK_BC_UNSHIFTED_MASK_C 0xffUL -#define DUK_BC_UNSHIFTED_MASK_BC 0xffffUL -#define DUK_BC_UNSHIFTED_MASK_ABC 0xffffffUL - -#define DUK_BC_SHIFTED_MASK_OP (DUK_BC_UNSHIFTED_MASK_OP << DUK_BC_SHIFT_OP) -#define DUK_BC_SHIFTED_MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK_BC_SHIFT_A) -#define DUK_BC_SHIFTED_MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK_BC_SHIFT_B) -#define DUK_BC_SHIFTED_MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK_BC_SHIFT_C) -#define DUK_BC_SHIFTED_MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK_BC_SHIFT_BC) -#define DUK_BC_SHIFTED_MASK_ABC (DUK_BC_UNSHIFTED_MASK_ABC << DUK_BC_SHIFT_ABC) - -#define DUK_DEC_OP(x) ((x) & 0xffUL) -#define DUK_DEC_A(x) (((x) >> 8) & 0xffUL) -#define DUK_DEC_B(x) (((x) >> 16) & 0xffUL) -#define DUK_DEC_C(x) (((x) >> 24) & 0xffUL) -#define DUK_DEC_BC(x) (((x) >> 16) & 0xffffUL) -#define DUK_DEC_ABC(x) (((x) >> 8) & 0xffffffUL) - -#define DUK_ENC_OP(op) ((duk_instr_t) (op)) -#define DUK_ENC_OP_ABC(op,abc) ((duk_instr_t) ( \ - (((duk_instr_t) (abc)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_BC(op,a,bc) ((duk_instr_t) ( \ - (((duk_instr_t) (bc)) << 16) | \ - (((duk_instr_t) (a)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_B_C(op,a,b,c) ((duk_instr_t) ( \ - (((duk_instr_t) (c)) << 24) | \ - (((duk_instr_t) (b)) << 16) | \ - (((duk_instr_t) (a)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_B(op,a,b) DUK_ENC_OP_A_B_C((op),(a),(b),0) -#define DUK_ENC_OP_A(op,a) DUK_ENC_OP_A_B_C((op),(a),0,0) -#define DUK_ENC_OP_BC(op,bc) DUK_ENC_OP_A_BC((op),0,(bc)) +#define DUK_BC_SHIFT_OP 0 +#define DUK_BC_SHIFT_A 8 +#define DUK_BC_SHIFT_B 16 +#define DUK_BC_SHIFT_C 24 +#define DUK_BC_SHIFT_BC DUK_BC_SHIFT_B +#define DUK_BC_SHIFT_ABC DUK_BC_SHIFT_A + +#define DUK_BC_UNSHIFTED_MASK_OP 0xffUL +#define DUK_BC_UNSHIFTED_MASK_A 0xffUL +#define DUK_BC_UNSHIFTED_MASK_B 0xffUL +#define DUK_BC_UNSHIFTED_MASK_C 0xffUL +#define DUK_BC_UNSHIFTED_MASK_BC 0xffffUL +#define DUK_BC_UNSHIFTED_MASK_ABC 0xffffffUL + +#define DUK_BC_SHIFTED_MASK_OP (DUK_BC_UNSHIFTED_MASK_OP << DUK_BC_SHIFT_OP) +#define DUK_BC_SHIFTED_MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK_BC_SHIFT_A) +#define DUK_BC_SHIFTED_MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK_BC_SHIFT_B) +#define DUK_BC_SHIFTED_MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK_BC_SHIFT_C) +#define DUK_BC_SHIFTED_MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK_BC_SHIFT_BC) +#define DUK_BC_SHIFTED_MASK_ABC (DUK_BC_UNSHIFTED_MASK_ABC << DUK_BC_SHIFT_ABC) + +#define DUK_DEC_OP(x) ((x) &0xffUL) +#define DUK_DEC_A(x) (((x) >> 8) & 0xffUL) +#define DUK_DEC_B(x) (((x) >> 16) & 0xffUL) +#define DUK_DEC_C(x) (((x) >> 24) & 0xffUL) +#define DUK_DEC_BC(x) (((x) >> 16) & 0xffffUL) +#define DUK_DEC_ABC(x) (((x) >> 8) & 0xffffffUL) + +#define DUK_ENC_OP(op) ((duk_instr_t) (op)) +#define DUK_ENC_OP_ABC(op, abc) ((duk_instr_t) ((((duk_instr_t) (abc)) << 8) | ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_BC(op, a, bc) \ + ((duk_instr_t) ((((duk_instr_t) (bc)) << 16) | (((duk_instr_t) (a)) << 8) | ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_B_C(op, a, b, c) \ + ((duk_instr_t) ((((duk_instr_t) (c)) << 24) | (((duk_instr_t) (b)) << 16) | (((duk_instr_t) (a)) << 8) | \ + ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_B(op, a, b) DUK_ENC_OP_A_B_C((op), (a), (b), 0) +#define DUK_ENC_OP_A(op, a) DUK_ENC_OP_A_B_C((op), (a), 0, 0) +#define DUK_ENC_OP_BC(op, bc) DUK_ENC_OP_A_BC((op), 0, (bc)) /* Get opcode base value with B/C reg/const flags cleared. */ -#define DUK_BC_NOREGCONST_OP(op) ((op) & 0xfc) +#define DUK_BC_NOREGCONST_OP(op) ((op) &0xfc) /* Constants should be signed so that signed arithmetic involving them * won't cause values to be coerced accidentally to unsigned. */ -#define DUK_BC_OP_MIN 0 -#define DUK_BC_OP_MAX 0xffL -#define DUK_BC_A_MIN 0 -#define DUK_BC_A_MAX 0xffL -#define DUK_BC_B_MIN 0 -#define DUK_BC_B_MAX 0xffL -#define DUK_BC_C_MIN 0 -#define DUK_BC_C_MAX 0xffL -#define DUK_BC_BC_MIN 0 -#define DUK_BC_BC_MAX 0xffffL -#define DUK_BC_ABC_MIN 0 -#define DUK_BC_ABC_MAX 0xffffffL +#define DUK_BC_OP_MIN 0 +#define DUK_BC_OP_MAX 0xffL +#define DUK_BC_A_MIN 0 +#define DUK_BC_A_MAX 0xffL +#define DUK_BC_B_MIN 0 +#define DUK_BC_B_MAX 0xffL +#define DUK_BC_C_MIN 0 +#define DUK_BC_C_MAX 0xffL +#define DUK_BC_BC_MIN 0 +#define DUK_BC_BC_MAX 0xffffL +#define DUK_BC_ABC_MIN 0 +#define DUK_BC_ABC_MAX 0xffffffL /* Masks for B/C reg/const indicator in opcode field. */ -#define DUK_BC_REGCONST_B (0x01UL) -#define DUK_BC_REGCONST_C (0x02UL) +#define DUK_BC_REGCONST_B (0x01UL) +#define DUK_BC_REGCONST_C (0x02UL) /* Misc. masks for opcode field. */ -#define DUK_BC_INCDECP_FLAG_DEC (0x04UL) -#define DUK_BC_INCDECP_FLAG_POST (0x08UL) +#define DUK_BC_INCDECP_FLAG_DEC (0x04UL) +#define DUK_BC_INCDECP_FLAG_POST (0x08UL) /* Opcodes. */ -#define DUK_OP_LDREG 0 -#define DUK_OP_STREG 1 -#define DUK_OP_JUMP 2 -#define DUK_OP_LDCONST 3 -#define DUK_OP_LDINT 4 -#define DUK_OP_LDINTX 5 -#define DUK_OP_LDTHIS 6 -#define DUK_OP_LDUNDEF 7 -#define DUK_OP_LDNULL 8 -#define DUK_OP_LDTRUE 9 -#define DUK_OP_LDFALSE 10 -#define DUK_OP_GETVAR 11 -#define DUK_OP_BNOT 12 -#define DUK_OP_LNOT 13 -#define DUK_OP_UNM 14 -#define DUK_OP_UNP 15 -#define DUK_OP_EQ 16 -#define DUK_OP_EQ_RR 16 -#define DUK_OP_EQ_CR 17 -#define DUK_OP_EQ_RC 18 -#define DUK_OP_EQ_CC 19 -#define DUK_OP_NEQ 20 -#define DUK_OP_NEQ_RR 20 -#define DUK_OP_NEQ_CR 21 -#define DUK_OP_NEQ_RC 22 -#define DUK_OP_NEQ_CC 23 -#define DUK_OP_SEQ 24 -#define DUK_OP_SEQ_RR 24 -#define DUK_OP_SEQ_CR 25 -#define DUK_OP_SEQ_RC 26 -#define DUK_OP_SEQ_CC 27 -#define DUK_OP_SNEQ 28 -#define DUK_OP_SNEQ_RR 28 -#define DUK_OP_SNEQ_CR 29 -#define DUK_OP_SNEQ_RC 30 -#define DUK_OP_SNEQ_CC 31 -#define DUK_OP_GT 32 -#define DUK_OP_GT_RR 32 -#define DUK_OP_GT_CR 33 -#define DUK_OP_GT_RC 34 -#define DUK_OP_GT_CC 35 -#define DUK_OP_GE 36 -#define DUK_OP_GE_RR 36 -#define DUK_OP_GE_CR 37 -#define DUK_OP_GE_RC 38 -#define DUK_OP_GE_CC 39 -#define DUK_OP_LT 40 -#define DUK_OP_LT_RR 40 -#define DUK_OP_LT_CR 41 -#define DUK_OP_LT_RC 42 -#define DUK_OP_LT_CC 43 -#define DUK_OP_LE 44 -#define DUK_OP_LE_RR 44 -#define DUK_OP_LE_CR 45 -#define DUK_OP_LE_RC 46 -#define DUK_OP_LE_CC 47 -#define DUK_OP_IFTRUE 48 -#define DUK_OP_IFTRUE_R 48 -#define DUK_OP_IFTRUE_C 49 -#define DUK_OP_IFFALSE 50 -#define DUK_OP_IFFALSE_R 50 -#define DUK_OP_IFFALSE_C 51 -#define DUK_OP_ADD 52 -#define DUK_OP_ADD_RR 52 -#define DUK_OP_ADD_CR 53 -#define DUK_OP_ADD_RC 54 -#define DUK_OP_ADD_CC 55 -#define DUK_OP_SUB 56 -#define DUK_OP_SUB_RR 56 -#define DUK_OP_SUB_CR 57 -#define DUK_OP_SUB_RC 58 -#define DUK_OP_SUB_CC 59 -#define DUK_OP_MUL 60 -#define DUK_OP_MUL_RR 60 -#define DUK_OP_MUL_CR 61 -#define DUK_OP_MUL_RC 62 -#define DUK_OP_MUL_CC 63 -#define DUK_OP_DIV 64 -#define DUK_OP_DIV_RR 64 -#define DUK_OP_DIV_CR 65 -#define DUK_OP_DIV_RC 66 -#define DUK_OP_DIV_CC 67 -#define DUK_OP_MOD 68 -#define DUK_OP_MOD_RR 68 -#define DUK_OP_MOD_CR 69 -#define DUK_OP_MOD_RC 70 -#define DUK_OP_MOD_CC 71 -#define DUK_OP_EXP 72 -#define DUK_OP_EXP_RR 72 -#define DUK_OP_EXP_CR 73 -#define DUK_OP_EXP_RC 74 -#define DUK_OP_EXP_CC 75 -#define DUK_OP_BAND 76 -#define DUK_OP_BAND_RR 76 -#define DUK_OP_BAND_CR 77 -#define DUK_OP_BAND_RC 78 -#define DUK_OP_BAND_CC 79 -#define DUK_OP_BOR 80 -#define DUK_OP_BOR_RR 80 -#define DUK_OP_BOR_CR 81 -#define DUK_OP_BOR_RC 82 -#define DUK_OP_BOR_CC 83 -#define DUK_OP_BXOR 84 -#define DUK_OP_BXOR_RR 84 -#define DUK_OP_BXOR_CR 85 -#define DUK_OP_BXOR_RC 86 -#define DUK_OP_BXOR_CC 87 -#define DUK_OP_BASL 88 -#define DUK_OP_BASL_RR 88 -#define DUK_OP_BASL_CR 89 -#define DUK_OP_BASL_RC 90 -#define DUK_OP_BASL_CC 91 -#define DUK_OP_BLSR 92 -#define DUK_OP_BLSR_RR 92 -#define DUK_OP_BLSR_CR 93 -#define DUK_OP_BLSR_RC 94 -#define DUK_OP_BLSR_CC 95 -#define DUK_OP_BASR 96 -#define DUK_OP_BASR_RR 96 -#define DUK_OP_BASR_CR 97 -#define DUK_OP_BASR_RC 98 -#define DUK_OP_BASR_CC 99 -#define DUK_OP_INSTOF 100 -#define DUK_OP_INSTOF_RR 100 -#define DUK_OP_INSTOF_CR 101 -#define DUK_OP_INSTOF_RC 102 -#define DUK_OP_INSTOF_CC 103 -#define DUK_OP_IN 104 -#define DUK_OP_IN_RR 104 -#define DUK_OP_IN_CR 105 -#define DUK_OP_IN_RC 106 -#define DUK_OP_IN_CC 107 -#define DUK_OP_GETPROP 108 -#define DUK_OP_GETPROP_RR 108 -#define DUK_OP_GETPROP_CR 109 -#define DUK_OP_GETPROP_RC 110 -#define DUK_OP_GETPROP_CC 111 -#define DUK_OP_PUTPROP 112 -#define DUK_OP_PUTPROP_RR 112 -#define DUK_OP_PUTPROP_CR 113 -#define DUK_OP_PUTPROP_RC 114 -#define DUK_OP_PUTPROP_CC 115 -#define DUK_OP_DELPROP 116 -#define DUK_OP_DELPROP_RR 116 -#define DUK_OP_DELPROP_CR_UNUSED 117 /* unused now */ -#define DUK_OP_DELPROP_RC 118 -#define DUK_OP_DELPROP_CC_UNUSED 119 /* unused now */ -#define DUK_OP_PREINCR 120 /* pre/post opcode values have constraints, */ -#define DUK_OP_PREDECR 121 /* see duk_js_executor.c and duk_js_compiler.c. */ -#define DUK_OP_POSTINCR 122 -#define DUK_OP_POSTDECR 123 -#define DUK_OP_PREINCV 124 -#define DUK_OP_PREDECV 125 -#define DUK_OP_POSTINCV 126 -#define DUK_OP_POSTDECV 127 -#define DUK_OP_PREINCP 128 /* pre/post inc/dec prop opcodes have constraints */ -#define DUK_OP_PREINCP_RR 128 -#define DUK_OP_PREINCP_CR 129 -#define DUK_OP_PREINCP_RC 130 -#define DUK_OP_PREINCP_CC 131 -#define DUK_OP_PREDECP 132 -#define DUK_OP_PREDECP_RR 132 -#define DUK_OP_PREDECP_CR 133 -#define DUK_OP_PREDECP_RC 134 -#define DUK_OP_PREDECP_CC 135 -#define DUK_OP_POSTINCP 136 -#define DUK_OP_POSTINCP_RR 136 -#define DUK_OP_POSTINCP_CR 137 -#define DUK_OP_POSTINCP_RC 138 -#define DUK_OP_POSTINCP_CC 139 -#define DUK_OP_POSTDECP 140 -#define DUK_OP_POSTDECP_RR 140 -#define DUK_OP_POSTDECP_CR 141 -#define DUK_OP_POSTDECP_RC 142 -#define DUK_OP_POSTDECP_CC 143 -#define DUK_OP_DECLVAR 144 -#define DUK_OP_DECLVAR_RR 144 -#define DUK_OP_DECLVAR_CR 145 -#define DUK_OP_DECLVAR_RC 146 -#define DUK_OP_DECLVAR_CC 147 -#define DUK_OP_REGEXP 148 -#define DUK_OP_REGEXP_RR 148 -#define DUK_OP_REGEXP_CR 149 -#define DUK_OP_REGEXP_RC 150 -#define DUK_OP_REGEXP_CC 151 -#define DUK_OP_CLOSURE 152 -#define DUK_OP_TYPEOF 153 -#define DUK_OP_TYPEOFID 154 -#define DUK_OP_PUTVAR 155 -#define DUK_OP_DELVAR 156 -#define DUK_OP_RETREG 157 -#define DUK_OP_RETUNDEF 158 -#define DUK_OP_RETCONST 159 -#define DUK_OP_RETCONSTN 160 /* return const without incref (e.g. number) */ -#define DUK_OP_LABEL 161 -#define DUK_OP_ENDLABEL 162 -#define DUK_OP_BREAK 163 -#define DUK_OP_CONTINUE 164 -#define DUK_OP_TRYCATCH 165 -#define DUK_OP_ENDTRY 166 -#define DUK_OP_ENDCATCH 167 -#define DUK_OP_ENDFIN 168 -#define DUK_OP_THROW 169 -#define DUK_OP_INVLHS 170 -#define DUK_OP_CSREG 171 -#define DUK_OP_CSVAR 172 -#define DUK_OP_CSVAR_RR 172 -#define DUK_OP_CSVAR_CR 173 -#define DUK_OP_CSVAR_RC 174 -#define DUK_OP_CSVAR_CC 175 -#define DUK_OP_CALL0 176 /* DUK_OP_CALL0 & 0x0F must be zero. */ -#define DUK_OP_CALL1 177 -#define DUK_OP_CALL2 178 -#define DUK_OP_CALL3 179 -#define DUK_OP_CALL4 180 -#define DUK_OP_CALL5 181 -#define DUK_OP_CALL6 182 -#define DUK_OP_CALL7 183 -#define DUK_OP_CALL8 184 -#define DUK_OP_CALL9 185 -#define DUK_OP_CALL10 186 -#define DUK_OP_CALL11 187 -#define DUK_OP_CALL12 188 -#define DUK_OP_CALL13 189 -#define DUK_OP_CALL14 190 -#define DUK_OP_CALL15 191 -#define DUK_OP_NEWOBJ 192 -#define DUK_OP_NEWARR 193 -#define DUK_OP_MPUTOBJ 194 -#define DUK_OP_MPUTOBJI 195 -#define DUK_OP_INITSET 196 -#define DUK_OP_INITGET 197 -#define DUK_OP_MPUTARR 198 -#define DUK_OP_MPUTARRI 199 -#define DUK_OP_SETALEN 200 -#define DUK_OP_INITENUM 201 -#define DUK_OP_NEXTENUM 202 -#define DUK_OP_NEWTARGET 203 -#define DUK_OP_DEBUGGER 204 -#define DUK_OP_NOP 205 -#define DUK_OP_INVALID 206 -#define DUK_OP_UNUSED207 207 -#define DUK_OP_GETPROPC 208 -#define DUK_OP_GETPROPC_RR 208 -#define DUK_OP_GETPROPC_CR 209 -#define DUK_OP_GETPROPC_RC 210 -#define DUK_OP_GETPROPC_CC 211 -#define DUK_OP_UNUSED212 212 -#define DUK_OP_UNUSED213 213 -#define DUK_OP_UNUSED214 214 -#define DUK_OP_UNUSED215 215 -#define DUK_OP_UNUSED216 216 -#define DUK_OP_UNUSED217 217 -#define DUK_OP_UNUSED218 218 -#define DUK_OP_UNUSED219 219 -#define DUK_OP_UNUSED220 220 -#define DUK_OP_UNUSED221 221 -#define DUK_OP_UNUSED222 222 -#define DUK_OP_UNUSED223 223 -#define DUK_OP_UNUSED224 224 -#define DUK_OP_UNUSED225 225 -#define DUK_OP_UNUSED226 226 -#define DUK_OP_UNUSED227 227 -#define DUK_OP_UNUSED228 228 -#define DUK_OP_UNUSED229 229 -#define DUK_OP_UNUSED230 230 -#define DUK_OP_UNUSED231 231 -#define DUK_OP_UNUSED232 232 -#define DUK_OP_UNUSED233 233 -#define DUK_OP_UNUSED234 234 -#define DUK_OP_UNUSED235 235 -#define DUK_OP_UNUSED236 236 -#define DUK_OP_UNUSED237 237 -#define DUK_OP_UNUSED238 238 -#define DUK_OP_UNUSED239 239 -#define DUK_OP_UNUSED240 240 -#define DUK_OP_UNUSED241 241 -#define DUK_OP_UNUSED242 242 -#define DUK_OP_UNUSED243 243 -#define DUK_OP_UNUSED244 244 -#define DUK_OP_UNUSED245 245 -#define DUK_OP_UNUSED246 246 -#define DUK_OP_UNUSED247 247 -#define DUK_OP_UNUSED248 248 -#define DUK_OP_UNUSED249 249 -#define DUK_OP_UNUSED250 250 -#define DUK_OP_UNUSED251 251 -#define DUK_OP_UNUSED252 252 -#define DUK_OP_UNUSED253 253 -#define DUK_OP_UNUSED254 254 -#define DUK_OP_UNUSED255 255 -#define DUK_OP_NONE 256 /* dummy value used as marker (doesn't fit in 8-bit field) */ +#define DUK_OP_LDREG 0 +#define DUK_OP_STREG 1 +#define DUK_OP_JUMP 2 +#define DUK_OP_LDCONST 3 +#define DUK_OP_LDINT 4 +#define DUK_OP_LDINTX 5 +#define DUK_OP_LDTHIS 6 +#define DUK_OP_LDUNDEF 7 +#define DUK_OP_LDNULL 8 +#define DUK_OP_LDTRUE 9 +#define DUK_OP_LDFALSE 10 +#define DUK_OP_GETVAR 11 +#define DUK_OP_BNOT 12 +#define DUK_OP_LNOT 13 +#define DUK_OP_UNM 14 +#define DUK_OP_UNP 15 +#define DUK_OP_EQ 16 +#define DUK_OP_EQ_RR 16 +#define DUK_OP_EQ_CR 17 +#define DUK_OP_EQ_RC 18 +#define DUK_OP_EQ_CC 19 +#define DUK_OP_NEQ 20 +#define DUK_OP_NEQ_RR 20 +#define DUK_OP_NEQ_CR 21 +#define DUK_OP_NEQ_RC 22 +#define DUK_OP_NEQ_CC 23 +#define DUK_OP_SEQ 24 +#define DUK_OP_SEQ_RR 24 +#define DUK_OP_SEQ_CR 25 +#define DUK_OP_SEQ_RC 26 +#define DUK_OP_SEQ_CC 27 +#define DUK_OP_SNEQ 28 +#define DUK_OP_SNEQ_RR 28 +#define DUK_OP_SNEQ_CR 29 +#define DUK_OP_SNEQ_RC 30 +#define DUK_OP_SNEQ_CC 31 +#define DUK_OP_GT 32 +#define DUK_OP_GT_RR 32 +#define DUK_OP_GT_CR 33 +#define DUK_OP_GT_RC 34 +#define DUK_OP_GT_CC 35 +#define DUK_OP_GE 36 +#define DUK_OP_GE_RR 36 +#define DUK_OP_GE_CR 37 +#define DUK_OP_GE_RC 38 +#define DUK_OP_GE_CC 39 +#define DUK_OP_LT 40 +#define DUK_OP_LT_RR 40 +#define DUK_OP_LT_CR 41 +#define DUK_OP_LT_RC 42 +#define DUK_OP_LT_CC 43 +#define DUK_OP_LE 44 +#define DUK_OP_LE_RR 44 +#define DUK_OP_LE_CR 45 +#define DUK_OP_LE_RC 46 +#define DUK_OP_LE_CC 47 +#define DUK_OP_IFTRUE 48 +#define DUK_OP_IFTRUE_R 48 +#define DUK_OP_IFTRUE_C 49 +#define DUK_OP_IFFALSE 50 +#define DUK_OP_IFFALSE_R 50 +#define DUK_OP_IFFALSE_C 51 +#define DUK_OP_ADD 52 +#define DUK_OP_ADD_RR 52 +#define DUK_OP_ADD_CR 53 +#define DUK_OP_ADD_RC 54 +#define DUK_OP_ADD_CC 55 +#define DUK_OP_SUB 56 +#define DUK_OP_SUB_RR 56 +#define DUK_OP_SUB_CR 57 +#define DUK_OP_SUB_RC 58 +#define DUK_OP_SUB_CC 59 +#define DUK_OP_MUL 60 +#define DUK_OP_MUL_RR 60 +#define DUK_OP_MUL_CR 61 +#define DUK_OP_MUL_RC 62 +#define DUK_OP_MUL_CC 63 +#define DUK_OP_DIV 64 +#define DUK_OP_DIV_RR 64 +#define DUK_OP_DIV_CR 65 +#define DUK_OP_DIV_RC 66 +#define DUK_OP_DIV_CC 67 +#define DUK_OP_MOD 68 +#define DUK_OP_MOD_RR 68 +#define DUK_OP_MOD_CR 69 +#define DUK_OP_MOD_RC 70 +#define DUK_OP_MOD_CC 71 +#define DUK_OP_EXP 72 +#define DUK_OP_EXP_RR 72 +#define DUK_OP_EXP_CR 73 +#define DUK_OP_EXP_RC 74 +#define DUK_OP_EXP_CC 75 +#define DUK_OP_BAND 76 +#define DUK_OP_BAND_RR 76 +#define DUK_OP_BAND_CR 77 +#define DUK_OP_BAND_RC 78 +#define DUK_OP_BAND_CC 79 +#define DUK_OP_BOR 80 +#define DUK_OP_BOR_RR 80 +#define DUK_OP_BOR_CR 81 +#define DUK_OP_BOR_RC 82 +#define DUK_OP_BOR_CC 83 +#define DUK_OP_BXOR 84 +#define DUK_OP_BXOR_RR 84 +#define DUK_OP_BXOR_CR 85 +#define DUK_OP_BXOR_RC 86 +#define DUK_OP_BXOR_CC 87 +#define DUK_OP_BASL 88 +#define DUK_OP_BASL_RR 88 +#define DUK_OP_BASL_CR 89 +#define DUK_OP_BASL_RC 90 +#define DUK_OP_BASL_CC 91 +#define DUK_OP_BLSR 92 +#define DUK_OP_BLSR_RR 92 +#define DUK_OP_BLSR_CR 93 +#define DUK_OP_BLSR_RC 94 +#define DUK_OP_BLSR_CC 95 +#define DUK_OP_BASR 96 +#define DUK_OP_BASR_RR 96 +#define DUK_OP_BASR_CR 97 +#define DUK_OP_BASR_RC 98 +#define DUK_OP_BASR_CC 99 +#define DUK_OP_INSTOF 100 +#define DUK_OP_INSTOF_RR 100 +#define DUK_OP_INSTOF_CR 101 +#define DUK_OP_INSTOF_RC 102 +#define DUK_OP_INSTOF_CC 103 +#define DUK_OP_IN 104 +#define DUK_OP_IN_RR 104 +#define DUK_OP_IN_CR 105 +#define DUK_OP_IN_RC 106 +#define DUK_OP_IN_CC 107 +#define DUK_OP_GETPROP 108 +#define DUK_OP_GETPROP_RR 108 +#define DUK_OP_GETPROP_CR 109 +#define DUK_OP_GETPROP_RC 110 +#define DUK_OP_GETPROP_CC 111 +#define DUK_OP_PUTPROP 112 +#define DUK_OP_PUTPROP_RR 112 +#define DUK_OP_PUTPROP_CR 113 +#define DUK_OP_PUTPROP_RC 114 +#define DUK_OP_PUTPROP_CC 115 +#define DUK_OP_DELPROP 116 +#define DUK_OP_DELPROP_RR 116 +#define DUK_OP_DELPROP_CR_UNUSED 117 /* unused now */ +#define DUK_OP_DELPROP_RC 118 +#define DUK_OP_DELPROP_CC_UNUSED 119 /* unused now */ +#define DUK_OP_PREINCR 120 /* pre/post opcode values have constraints, */ +#define DUK_OP_PREDECR 121 /* see duk_js_executor.c and duk_js_compiler.c. */ +#define DUK_OP_POSTINCR 122 +#define DUK_OP_POSTDECR 123 +#define DUK_OP_PREINCV 124 +#define DUK_OP_PREDECV 125 +#define DUK_OP_POSTINCV 126 +#define DUK_OP_POSTDECV 127 +#define DUK_OP_PREINCP 128 /* pre/post inc/dec prop opcodes have constraints */ +#define DUK_OP_PREINCP_RR 128 +#define DUK_OP_PREINCP_CR 129 +#define DUK_OP_PREINCP_RC 130 +#define DUK_OP_PREINCP_CC 131 +#define DUK_OP_PREDECP 132 +#define DUK_OP_PREDECP_RR 132 +#define DUK_OP_PREDECP_CR 133 +#define DUK_OP_PREDECP_RC 134 +#define DUK_OP_PREDECP_CC 135 +#define DUK_OP_POSTINCP 136 +#define DUK_OP_POSTINCP_RR 136 +#define DUK_OP_POSTINCP_CR 137 +#define DUK_OP_POSTINCP_RC 138 +#define DUK_OP_POSTINCP_CC 139 +#define DUK_OP_POSTDECP 140 +#define DUK_OP_POSTDECP_RR 140 +#define DUK_OP_POSTDECP_CR 141 +#define DUK_OP_POSTDECP_RC 142 +#define DUK_OP_POSTDECP_CC 143 +#define DUK_OP_DECLVAR 144 +#define DUK_OP_DECLVAR_RR 144 +#define DUK_OP_DECLVAR_CR 145 +#define DUK_OP_DECLVAR_RC 146 +#define DUK_OP_DECLVAR_CC 147 +#define DUK_OP_REGEXP 148 +#define DUK_OP_REGEXP_RR 148 +#define DUK_OP_REGEXP_CR 149 +#define DUK_OP_REGEXP_RC 150 +#define DUK_OP_REGEXP_CC 151 +#define DUK_OP_CLOSURE 152 +#define DUK_OP_TYPEOF 153 +#define DUK_OP_TYPEOFID 154 +#define DUK_OP_PUTVAR 155 +#define DUK_OP_DELVAR 156 +#define DUK_OP_RETREG 157 +#define DUK_OP_RETUNDEF 158 +#define DUK_OP_RETCONST 159 +#define DUK_OP_RETCONSTN 160 /* return const without incref (e.g. number) */ +#define DUK_OP_LABEL 161 +#define DUK_OP_ENDLABEL 162 +#define DUK_OP_BREAK 163 +#define DUK_OP_CONTINUE 164 +#define DUK_OP_TRYCATCH 165 +#define DUK_OP_ENDTRY 166 +#define DUK_OP_ENDCATCH 167 +#define DUK_OP_ENDFIN 168 +#define DUK_OP_THROW 169 +#define DUK_OP_INVLHS 170 +#define DUK_OP_CSREG 171 +#define DUK_OP_CSVAR 172 +#define DUK_OP_CSVAR_RR 172 +#define DUK_OP_CSVAR_CR 173 +#define DUK_OP_CSVAR_RC 174 +#define DUK_OP_CSVAR_CC 175 +#define DUK_OP_CALL0 176 /* DUK_OP_CALL0 & 0x0F must be zero. */ +#define DUK_OP_CALL1 177 +#define DUK_OP_CALL2 178 +#define DUK_OP_CALL3 179 +#define DUK_OP_CALL4 180 +#define DUK_OP_CALL5 181 +#define DUK_OP_CALL6 182 +#define DUK_OP_CALL7 183 +#define DUK_OP_CALL8 184 +#define DUK_OP_CALL9 185 +#define DUK_OP_CALL10 186 +#define DUK_OP_CALL11 187 +#define DUK_OP_CALL12 188 +#define DUK_OP_CALL13 189 +#define DUK_OP_CALL14 190 +#define DUK_OP_CALL15 191 +#define DUK_OP_NEWOBJ 192 +#define DUK_OP_NEWARR 193 +#define DUK_OP_MPUTOBJ 194 +#define DUK_OP_MPUTOBJI 195 +#define DUK_OP_INITSET 196 +#define DUK_OP_INITGET 197 +#define DUK_OP_MPUTARR 198 +#define DUK_OP_MPUTARRI 199 +#define DUK_OP_SETALEN 200 +#define DUK_OP_INITENUM 201 +#define DUK_OP_NEXTENUM 202 +#define DUK_OP_NEWTARGET 203 +#define DUK_OP_DEBUGGER 204 +#define DUK_OP_NOP 205 +#define DUK_OP_INVALID 206 +#define DUK_OP_UNUSED207 207 +#define DUK_OP_GETPROPC 208 +#define DUK_OP_GETPROPC_RR 208 +#define DUK_OP_GETPROPC_CR 209 +#define DUK_OP_GETPROPC_RC 210 +#define DUK_OP_GETPROPC_CC 211 +#define DUK_OP_UNUSED212 212 +#define DUK_OP_UNUSED213 213 +#define DUK_OP_UNUSED214 214 +#define DUK_OP_UNUSED215 215 +#define DUK_OP_UNUSED216 216 +#define DUK_OP_UNUSED217 217 +#define DUK_OP_UNUSED218 218 +#define DUK_OP_UNUSED219 219 +#define DUK_OP_UNUSED220 220 +#define DUK_OP_UNUSED221 221 +#define DUK_OP_UNUSED222 222 +#define DUK_OP_UNUSED223 223 +#define DUK_OP_UNUSED224 224 +#define DUK_OP_UNUSED225 225 +#define DUK_OP_UNUSED226 226 +#define DUK_OP_UNUSED227 227 +#define DUK_OP_UNUSED228 228 +#define DUK_OP_UNUSED229 229 +#define DUK_OP_UNUSED230 230 +#define DUK_OP_UNUSED231 231 +#define DUK_OP_UNUSED232 232 +#define DUK_OP_UNUSED233 233 +#define DUK_OP_UNUSED234 234 +#define DUK_OP_UNUSED235 235 +#define DUK_OP_UNUSED236 236 +#define DUK_OP_UNUSED237 237 +#define DUK_OP_UNUSED238 238 +#define DUK_OP_UNUSED239 239 +#define DUK_OP_UNUSED240 240 +#define DUK_OP_UNUSED241 241 +#define DUK_OP_UNUSED242 242 +#define DUK_OP_UNUSED243 243 +#define DUK_OP_UNUSED244 244 +#define DUK_OP_UNUSED245 245 +#define DUK_OP_UNUSED246 246 +#define DUK_OP_UNUSED247 247 +#define DUK_OP_UNUSED248 248 +#define DUK_OP_UNUSED249 249 +#define DUK_OP_UNUSED250 250 +#define DUK_OP_UNUSED251 251 +#define DUK_OP_UNUSED252 252 +#define DUK_OP_UNUSED253 253 +#define DUK_OP_UNUSED254 254 +#define DUK_OP_UNUSED255 255 +#define DUK_OP_NONE 256 /* dummy value used as marker (doesn't fit in 8-bit field) */ /* XXX: Allocate flags from opcode field? Would take 16 opcode slots * but avoids shuffling in more cases. Maybe not worth it. */ /* DUK_OP_TRYCATCH flags in A. */ -#define DUK_BC_TRYCATCH_FLAG_HAVE_CATCH (1U << 0) -#define DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY (1U << 1) -#define DUK_BC_TRYCATCH_FLAG_CATCH_BINDING (1U << 2) -#define DUK_BC_TRYCATCH_FLAG_WITH_BINDING (1U << 3) +#define DUK_BC_TRYCATCH_FLAG_HAVE_CATCH (1U << 0) +#define DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY (1U << 1) +#define DUK_BC_TRYCATCH_FLAG_CATCH_BINDING (1U << 2) +#define DUK_BC_TRYCATCH_FLAG_WITH_BINDING (1U << 3) /* DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags * (DUK_PROPDESC_FLAG_XXX). */ -#define DUK_BC_DECLVAR_FLAG_FUNC_DECL (1U << 4) /* function declaration */ +#define DUK_BC_DECLVAR_FLAG_FUNC_DECL (1U << 4) /* function declaration */ /* DUK_OP_CALLn flags, part of opcode field. Three lowest bits must match * DUK_CALL_FLAG_xxx directly. */ -#define DUK_BC_CALL_FLAG_TAILCALL (1U << 0) -#define DUK_BC_CALL_FLAG_CONSTRUCT (1U << 1) -#define DUK_BC_CALL_FLAG_CALLED_AS_EVAL (1U << 2) -#define DUK_BC_CALL_FLAG_INDIRECT (1U << 3) +#define DUK_BC_CALL_FLAG_TAILCALL (1U << 0) +#define DUK_BC_CALL_FLAG_CONSTRUCT (1U << 1) +#define DUK_BC_CALL_FLAG_CALLED_AS_EVAL (1U << 2) +#define DUK_BC_CALL_FLAG_INDIRECT (1U << 3) /* Misc constants and helper macros. */ -#define DUK_BC_LDINT_BIAS (1L << 15) -#define DUK_BC_LDINTX_SHIFT 16 -#define DUK_BC_JUMP_BIAS (1L << 23) +#define DUK_BC_LDINT_BIAS (1L << 15) +#define DUK_BC_LDINTX_SHIFT 16 +#define DUK_BC_JUMP_BIAS (1L << 23) -#endif /* DUK_JS_BYTECODE_H_INCLUDED */ +#endif /* DUK_JS_BYTECODE_H_INCLUDED */ /* #include duk_lexer.h */ /* * Lexer defines. @@ -3730,156 +3825,156 @@ * in a continuous range and in a particular order. See genstrings.py. */ -#define DUK_LEXER_INITCTX(ctx) duk_lexer_initctx((ctx)) +#define DUK_LEXER_INITCTX(ctx) duk_lexer_initctx((ctx)) -#define DUK_LEXER_SETPOINT(ctx,pt) duk_lexer_setpoint((ctx), (pt)) +#define DUK_LEXER_SETPOINT(ctx, pt) duk_lexer_setpoint((ctx), (pt)) -#define DUK_LEXER_GETPOINT(ctx,pt) duk_lexer_getpoint((ctx), (pt)) +#define DUK_LEXER_GETPOINT(ctx, pt) duk_lexer_getpoint((ctx), (pt)) /* Currently 6 characters of lookup are actually needed (duk_lexer.c). */ -#define DUK_LEXER_WINDOW_SIZE 6 +#define DUK_LEXER_WINDOW_SIZE 6 #if defined(DUK_USE_LEXER_SLIDING_WINDOW) -#define DUK_LEXER_BUFFER_SIZE 64 +#define DUK_LEXER_BUFFER_SIZE 64 #endif -#define DUK_TOK_MINVAL 0 +#define DUK_TOK_MINVAL 0 /* returned after EOF (infinite amount) */ -#define DUK_TOK_EOF 0 +#define DUK_TOK_EOF 0 /* identifier names (E5 Section 7.6) */ -#define DUK_TOK_IDENTIFIER 1 +#define DUK_TOK_IDENTIFIER 1 /* reserved words: keywords */ -#define DUK_TOK_START_RESERVED 2 -#define DUK_TOK_BREAK 2 -#define DUK_TOK_CASE 3 -#define DUK_TOK_CATCH 4 -#define DUK_TOK_CONTINUE 5 -#define DUK_TOK_DEBUGGER 6 -#define DUK_TOK_DEFAULT 7 -#define DUK_TOK_DELETE 8 -#define DUK_TOK_DO 9 -#define DUK_TOK_ELSE 10 -#define DUK_TOK_FINALLY 11 -#define DUK_TOK_FOR 12 -#define DUK_TOK_FUNCTION 13 -#define DUK_TOK_IF 14 -#define DUK_TOK_IN 15 -#define DUK_TOK_INSTANCEOF 16 -#define DUK_TOK_NEW 17 -#define DUK_TOK_RETURN 18 -#define DUK_TOK_SWITCH 19 -#define DUK_TOK_THIS 20 -#define DUK_TOK_THROW 21 -#define DUK_TOK_TRY 22 -#define DUK_TOK_TYPEOF 23 -#define DUK_TOK_VAR 24 -#define DUK_TOK_CONST 25 -#define DUK_TOK_VOID 26 -#define DUK_TOK_WHILE 27 -#define DUK_TOK_WITH 28 +#define DUK_TOK_START_RESERVED 2 +#define DUK_TOK_BREAK 2 +#define DUK_TOK_CASE 3 +#define DUK_TOK_CATCH 4 +#define DUK_TOK_CONTINUE 5 +#define DUK_TOK_DEBUGGER 6 +#define DUK_TOK_DEFAULT 7 +#define DUK_TOK_DELETE 8 +#define DUK_TOK_DO 9 +#define DUK_TOK_ELSE 10 +#define DUK_TOK_FINALLY 11 +#define DUK_TOK_FOR 12 +#define DUK_TOK_FUNCTION 13 +#define DUK_TOK_IF 14 +#define DUK_TOK_IN 15 +#define DUK_TOK_INSTANCEOF 16 +#define DUK_TOK_NEW 17 +#define DUK_TOK_RETURN 18 +#define DUK_TOK_SWITCH 19 +#define DUK_TOK_THIS 20 +#define DUK_TOK_THROW 21 +#define DUK_TOK_TRY 22 +#define DUK_TOK_TYPEOF 23 +#define DUK_TOK_VAR 24 +#define DUK_TOK_CONST 25 +#define DUK_TOK_VOID 26 +#define DUK_TOK_WHILE 27 +#define DUK_TOK_WITH 28 /* reserved words: future reserved words */ -#define DUK_TOK_CLASS 29 -#define DUK_TOK_ENUM 30 -#define DUK_TOK_EXPORT 31 -#define DUK_TOK_EXTENDS 32 -#define DUK_TOK_IMPORT 33 -#define DUK_TOK_SUPER 34 +#define DUK_TOK_CLASS 29 +#define DUK_TOK_ENUM 30 +#define DUK_TOK_EXPORT 31 +#define DUK_TOK_EXTENDS 32 +#define DUK_TOK_IMPORT 33 +#define DUK_TOK_SUPER 34 /* "null", "true", and "false" are always reserved words. * Note that "get" and "set" are not! */ -#define DUK_TOK_NULL 35 -#define DUK_TOK_TRUE 36 -#define DUK_TOK_FALSE 37 +#define DUK_TOK_NULL 35 +#define DUK_TOK_TRUE 36 +#define DUK_TOK_FALSE 37 /* reserved words: additional future reserved words in strict mode */ -#define DUK_TOK_START_STRICT_RESERVED 38 /* inclusive */ -#define DUK_TOK_IMPLEMENTS 38 -#define DUK_TOK_INTERFACE 39 -#define DUK_TOK_LET 40 -#define DUK_TOK_PACKAGE 41 -#define DUK_TOK_PRIVATE 42 -#define DUK_TOK_PROTECTED 43 -#define DUK_TOK_PUBLIC 44 -#define DUK_TOK_STATIC 45 -#define DUK_TOK_YIELD 46 +#define DUK_TOK_START_STRICT_RESERVED 38 /* inclusive */ +#define DUK_TOK_IMPLEMENTS 38 +#define DUK_TOK_INTERFACE 39 +#define DUK_TOK_LET 40 +#define DUK_TOK_PACKAGE 41 +#define DUK_TOK_PRIVATE 42 +#define DUK_TOK_PROTECTED 43 +#define DUK_TOK_PUBLIC 44 +#define DUK_TOK_STATIC 45 +#define DUK_TOK_YIELD 46 -#define DUK_TOK_END_RESERVED 47 /* exclusive */ +#define DUK_TOK_END_RESERVED 47 /* exclusive */ /* "get" and "set" are tokens but NOT ReservedWords. They are currently * parsed and identifiers and these defines are actually now unused. */ -#define DUK_TOK_GET 47 -#define DUK_TOK_SET 48 +#define DUK_TOK_GET 47 +#define DUK_TOK_SET 48 /* punctuators (unlike the spec, also includes "/" and "/=") */ -#define DUK_TOK_LCURLY 49 -#define DUK_TOK_RCURLY 50 -#define DUK_TOK_LBRACKET 51 -#define DUK_TOK_RBRACKET 52 -#define DUK_TOK_LPAREN 53 -#define DUK_TOK_RPAREN 54 -#define DUK_TOK_PERIOD 55 -#define DUK_TOK_SEMICOLON 56 -#define DUK_TOK_COMMA 57 -#define DUK_TOK_LT 58 -#define DUK_TOK_GT 59 -#define DUK_TOK_LE 60 -#define DUK_TOK_GE 61 -#define DUK_TOK_EQ 62 -#define DUK_TOK_NEQ 63 -#define DUK_TOK_SEQ 64 -#define DUK_TOK_SNEQ 65 -#define DUK_TOK_ADD 66 -#define DUK_TOK_SUB 67 -#define DUK_TOK_MUL 68 -#define DUK_TOK_DIV 69 -#define DUK_TOK_MOD 70 -#define DUK_TOK_EXP 71 -#define DUK_TOK_INCREMENT 72 -#define DUK_TOK_DECREMENT 73 -#define DUK_TOK_ALSHIFT 74 /* named "arithmetic" because result is signed */ -#define DUK_TOK_ARSHIFT 75 -#define DUK_TOK_RSHIFT 76 -#define DUK_TOK_BAND 77 -#define DUK_TOK_BOR 78 -#define DUK_TOK_BXOR 79 -#define DUK_TOK_LNOT 80 -#define DUK_TOK_BNOT 81 -#define DUK_TOK_LAND 82 -#define DUK_TOK_LOR 83 -#define DUK_TOK_QUESTION 84 -#define DUK_TOK_COLON 85 -#define DUK_TOK_EQUALSIGN 86 -#define DUK_TOK_ADD_EQ 87 -#define DUK_TOK_SUB_EQ 88 -#define DUK_TOK_MUL_EQ 89 -#define DUK_TOK_DIV_EQ 90 -#define DUK_TOK_MOD_EQ 91 -#define DUK_TOK_EXP_EQ 92 -#define DUK_TOK_ALSHIFT_EQ 93 -#define DUK_TOK_ARSHIFT_EQ 94 -#define DUK_TOK_RSHIFT_EQ 95 -#define DUK_TOK_BAND_EQ 96 -#define DUK_TOK_BOR_EQ 97 -#define DUK_TOK_BXOR_EQ 98 +#define DUK_TOK_LCURLY 49 +#define DUK_TOK_RCURLY 50 +#define DUK_TOK_LBRACKET 51 +#define DUK_TOK_RBRACKET 52 +#define DUK_TOK_LPAREN 53 +#define DUK_TOK_RPAREN 54 +#define DUK_TOK_PERIOD 55 +#define DUK_TOK_SEMICOLON 56 +#define DUK_TOK_COMMA 57 +#define DUK_TOK_LT 58 +#define DUK_TOK_GT 59 +#define DUK_TOK_LE 60 +#define DUK_TOK_GE 61 +#define DUK_TOK_EQ 62 +#define DUK_TOK_NEQ 63 +#define DUK_TOK_SEQ 64 +#define DUK_TOK_SNEQ 65 +#define DUK_TOK_ADD 66 +#define DUK_TOK_SUB 67 +#define DUK_TOK_MUL 68 +#define DUK_TOK_DIV 69 +#define DUK_TOK_MOD 70 +#define DUK_TOK_EXP 71 +#define DUK_TOK_INCREMENT 72 +#define DUK_TOK_DECREMENT 73 +#define DUK_TOK_ALSHIFT 74 /* named "arithmetic" because result is signed */ +#define DUK_TOK_ARSHIFT 75 +#define DUK_TOK_RSHIFT 76 +#define DUK_TOK_BAND 77 +#define DUK_TOK_BOR 78 +#define DUK_TOK_BXOR 79 +#define DUK_TOK_LNOT 80 +#define DUK_TOK_BNOT 81 +#define DUK_TOK_LAND 82 +#define DUK_TOK_LOR 83 +#define DUK_TOK_QUESTION 84 +#define DUK_TOK_COLON 85 +#define DUK_TOK_EQUALSIGN 86 +#define DUK_TOK_ADD_EQ 87 +#define DUK_TOK_SUB_EQ 88 +#define DUK_TOK_MUL_EQ 89 +#define DUK_TOK_DIV_EQ 90 +#define DUK_TOK_MOD_EQ 91 +#define DUK_TOK_EXP_EQ 92 +#define DUK_TOK_ALSHIFT_EQ 93 +#define DUK_TOK_ARSHIFT_EQ 94 +#define DUK_TOK_RSHIFT_EQ 95 +#define DUK_TOK_BAND_EQ 96 +#define DUK_TOK_BOR_EQ 97 +#define DUK_TOK_BXOR_EQ 98 /* literals (E5 Section 7.8), except null, true, false, which are treated * like reserved words (above). */ -#define DUK_TOK_NUMBER 99 -#define DUK_TOK_STRING 100 -#define DUK_TOK_REGEXP 101 +#define DUK_TOK_NUMBER 99 +#define DUK_TOK_STRING 100 +#define DUK_TOK_REGEXP 101 -#define DUK_TOK_MAXVAL 101 /* inclusive */ +#define DUK_TOK_MAXVAL 101 /* inclusive */ -#define DUK_TOK_INVALID DUK_SMALL_UINT_MAX +#define DUK_TOK_INVALID DUK_SMALL_UINT_MAX /* Convert heap string index to a token (reserved words) */ -#define DUK_STRIDX_TO_TOK(x) ((x) - DUK_STRIDX_START_RESERVED + DUK_TOK_START_RESERVED) +#define DUK_STRIDX_TO_TOK(x) ((x) -DUK_STRIDX_START_RESERVED + DUK_TOK_START_RESERVED) /* Sanity check */ #if (DUK_TOK_MAXVAL > 255) @@ -4024,57 +4119,57 @@ #endif /* Regexp tokens */ -#define DUK_RETOK_EOF 0 -#define DUK_RETOK_DISJUNCTION 1 -#define DUK_RETOK_QUANTIFIER 2 -#define DUK_RETOK_ASSERT_START 3 -#define DUK_RETOK_ASSERT_END 4 -#define DUK_RETOK_ASSERT_WORD_BOUNDARY 5 -#define DUK_RETOK_ASSERT_NOT_WORD_BOUNDARY 6 -#define DUK_RETOK_ASSERT_START_POS_LOOKAHEAD 7 -#define DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD 8 -#define DUK_RETOK_ATOM_PERIOD 9 -#define DUK_RETOK_ATOM_CHAR 10 -#define DUK_RETOK_ATOM_DIGIT 11 /* assumptions in regexp compiler */ -#define DUK_RETOK_ATOM_NOT_DIGIT 12 /* -""- */ -#define DUK_RETOK_ATOM_WHITE 13 /* -""- */ -#define DUK_RETOK_ATOM_NOT_WHITE 14 /* -""- */ -#define DUK_RETOK_ATOM_WORD_CHAR 15 /* -""- */ -#define DUK_RETOK_ATOM_NOT_WORD_CHAR 16 /* -""- */ -#define DUK_RETOK_ATOM_BACKREFERENCE 17 -#define DUK_RETOK_ATOM_START_CAPTURE_GROUP 18 -#define DUK_RETOK_ATOM_START_NONCAPTURE_GROUP 19 -#define DUK_RETOK_ATOM_START_CHARCLASS 20 -#define DUK_RETOK_ATOM_START_CHARCLASS_INVERTED 21 -#define DUK_RETOK_ATOM_END_GROUP 22 +#define DUK_RETOK_EOF 0 +#define DUK_RETOK_DISJUNCTION 1 +#define DUK_RETOK_QUANTIFIER 2 +#define DUK_RETOK_ASSERT_START 3 +#define DUK_RETOK_ASSERT_END 4 +#define DUK_RETOK_ASSERT_WORD_BOUNDARY 5 +#define DUK_RETOK_ASSERT_NOT_WORD_BOUNDARY 6 +#define DUK_RETOK_ASSERT_START_POS_LOOKAHEAD 7 +#define DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD 8 +#define DUK_RETOK_ATOM_PERIOD 9 +#define DUK_RETOK_ATOM_CHAR 10 +#define DUK_RETOK_ATOM_DIGIT 11 /* assumptions in regexp compiler */ +#define DUK_RETOK_ATOM_NOT_DIGIT 12 /* -""- */ +#define DUK_RETOK_ATOM_WHITE 13 /* -""- */ +#define DUK_RETOK_ATOM_NOT_WHITE 14 /* -""- */ +#define DUK_RETOK_ATOM_WORD_CHAR 15 /* -""- */ +#define DUK_RETOK_ATOM_NOT_WORD_CHAR 16 /* -""- */ +#define DUK_RETOK_ATOM_BACKREFERENCE 17 +#define DUK_RETOK_ATOM_START_CAPTURE_GROUP 18 +#define DUK_RETOK_ATOM_START_NONCAPTURE_GROUP 19 +#define DUK_RETOK_ATOM_START_CHARCLASS 20 +#define DUK_RETOK_ATOM_START_CHARCLASS_INVERTED 21 +#define DUK_RETOK_ATOM_END_GROUP 22 /* Constants for duk_lexer_ctx.buf. */ -#define DUK_LEXER_TEMP_BUF_LIMIT 256 +#define DUK_LEXER_TEMP_BUF_LIMIT 256 /* A token value. Can be memcpy()'d, but note that slot1/slot2 values are on the valstack. * Some fields (like num, str1, str2) are only valid for specific token types and may have * stale values otherwise. */ struct duk_token { - duk_small_uint_t t; /* token type (with reserved word identification) */ - duk_small_uint_t t_nores; /* token type (with reserved words as DUK_TOK_IDENTIFER) */ - duk_double_t num; /* numeric value of token */ - duk_hstring *str1; /* string 1 of token (borrowed, stored to ctx->slot1_idx) */ - duk_hstring *str2; /* string 2 of token (borrowed, stored to ctx->slot2_idx) */ - duk_size_t start_offset; /* start byte offset of token in lexer input */ - duk_int_t start_line; /* start line of token (first char) */ - duk_int_t num_escapes; /* number of escapes and line continuations (for directive prologue) */ - duk_bool_t lineterm; /* token was preceded by a lineterm */ - duk_bool_t allow_auto_semi; /* token allows automatic semicolon insertion (eof or preceded by newline) */ + duk_small_uint_t t; /* token type (with reserved word identification) */ + duk_small_uint_t t_nores; /* token type (with reserved words as DUK_TOK_IDENTIFER) */ + duk_double_t num; /* numeric value of token */ + duk_hstring *str1; /* string 1 of token (borrowed, stored to ctx->slot1_idx) */ + duk_hstring *str2; /* string 2 of token (borrowed, stored to ctx->slot2_idx) */ + duk_size_t start_offset; /* start byte offset of token in lexer input */ + duk_int_t start_line; /* start line of token (first char) */ + duk_int_t num_escapes; /* number of escapes and line continuations (for directive prologue) */ + duk_bool_t lineterm; /* token was preceded by a lineterm */ + duk_bool_t allow_auto_semi; /* token allows automatic semicolon insertion (eof or preceded by newline) */ }; -#define DUK_RE_QUANTIFIER_INFINITE ((duk_uint32_t) 0xffffffffUL) +#define DUK_RE_QUANTIFIER_INFINITE ((duk_uint32_t) 0xffffffffUL) /* A regexp token value. */ struct duk_re_token { - duk_small_uint_t t; /* token type */ + duk_small_uint_t t; /* token type */ duk_small_uint_t greedy; - duk_uint32_t num; /* numeric value (character, count) */ + duk_uint32_t num; /* numeric value (character, count) */ duk_uint32_t qmin; duk_uint32_t qmax; }; @@ -4101,23 +4196,23 @@ duk_lexer_codepoint windowDUK_LEXER_WINDOW_SIZE; /* unicode code points, window0 is always next */ #endif - duk_hthread *thr; /* thread; minimizes argument passing */ + duk_hthread *thr; /* thread; minimizes argument passing */ - const duk_uint8_t *input; /* input string (may be a user pointer) */ - duk_size_t input_length; /* input byte length */ - duk_size_t input_offset; /* input offset for window leading edge (not window0) */ - duk_int_t input_line; /* input linenumber at input_offset (not window0), init to 1 */ - - duk_idx_t slot1_idx; /* valstack slot for 1st token value */ - duk_idx_t slot2_idx; /* valstack slot for 2nd token value */ - duk_idx_t buf_idx; /* valstack slot for temp buffer */ - duk_hbuffer_dynamic *buf; /* temp accumulation buffer */ - duk_bufwriter_ctx bw; /* bufwriter for temp accumulation */ + const duk_uint8_t *input; /* input string (may be a user pointer) */ + duk_size_t input_length; /* input byte length */ + duk_size_t input_offset; /* input offset for window leading edge (not window0) */ + duk_int_t input_line; /* input linenumber at input_offset (not window0), init to 1 */ + + duk_idx_t slot1_idx; /* valstack slot for 1st token value */ + duk_idx_t slot2_idx; /* valstack slot for 2nd token value */ + duk_idx_t buf_idx; /* valstack slot for temp buffer */ + duk_hbuffer_dynamic *buf; /* temp accumulation buffer */ + duk_bufwriter_ctx bw; /* bufwriter for temp accumulation */ - duk_int_t token_count; /* number of tokens parsed */ - duk_int_t token_limit; /* maximum token count before error (sanity backstop) */ + duk_int_t token_count; /* number of tokens parsed */ + duk_int_t token_limit; /* maximum token count before error (sanity backstop) */ - duk_small_uint_t flags; /* lexer flags, use compiler flag defines for now */ + duk_small_uint_t flags; /* lexer flags, use compiler flag defines for now */ }; /* @@ -4130,16 +4225,13 @@ DUK_INTERNAL_DECL void duk_lexer_setpoint(duk_lexer_ctx *lex_ctx, duk_lexer_point *pt); DUK_INTERNAL_DECL -void duk_lexer_parse_js_input_element(duk_lexer_ctx *lex_ctx, - duk_token *out_token, - duk_bool_t strict_mode, - duk_bool_t regexp_mode); +void duk_lexer_parse_js_input_element(duk_lexer_ctx *lex_ctx, duk_token *out_token, duk_bool_t strict_mode, duk_bool_t regexp_mode); #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL_DECL void duk_lexer_parse_re_token(duk_lexer_ctx *lex_ctx, duk_re_token *out_token); DUK_INTERNAL_DECL void duk_lexer_parse_re_ranges(duk_lexer_ctx *lex_ctx, duk_re_range_callback gen_range, void *userdata); -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ -#endif /* DUK_LEXER_H_INCLUDED */ +#endif /* DUK_LEXER_H_INCLUDED */ /* #include duk_js_compiler.h */ /* * ECMAScript compiler. @@ -4149,13 +4241,13 @@ #define DUK_JS_COMPILER_H_INCLUDED /* ECMAScript compiler limits */ -#define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */ +#define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */ /* maximum loopcount for peephole optimization */ -#define DUK_COMPILER_PEEPHOLE_MAXITER 3 +#define DUK_COMPILER_PEEPHOLE_MAXITER 3 /* maximum bytecode length in instructions */ -#define DUK_COMPILER_MAX_BYTECODE_LENGTH (256L * 1024L * 1024L) /* 1 GB */ +#define DUK_COMPILER_MAX_BYTECODE_LENGTH (256L * 1024L * 1024L) /* 1 GB */ /* * Compiler intermediate values @@ -4165,21 +4257,21 @@ * either a left-hand-side or right-hand-side role (e.g. object property). */ -#define DUK_IVAL_NONE 0 /* no value */ -#define DUK_IVAL_PLAIN 1 /* register, constant, or value */ -#define DUK_IVAL_ARITH 2 /* binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops */ -#define DUK_IVAL_PROP 3 /* property access */ -#define DUK_IVAL_VAR 4 /* variable access */ - -#define DUK_ISPEC_NONE 0 /* no value */ -#define DUK_ISPEC_VALUE 1 /* value resides in 'valstack_idx' */ -#define DUK_ISPEC_REGCONST 2 /* value resides in a register or constant */ +#define DUK_IVAL_NONE 0 /* no value */ +#define DUK_IVAL_PLAIN 1 /* register, constant, or value */ +#define DUK_IVAL_ARITH 2 /* binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops */ +#define DUK_IVAL_PROP 3 /* property access */ +#define DUK_IVAL_VAR 4 /* variable access */ + +#define DUK_ISPEC_NONE 0 /* no value */ +#define DUK_ISPEC_VALUE 1 /* value resides in 'valstack_idx' */ +#define DUK_ISPEC_REGCONST 2 /* value resides in a register or constant */ /* Bit mask which indicates that a regconst is a constant instead of a register. * Chosen so that when a regconst is cast to duk_int32_t, all consts are * negative values. */ -#define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */ +#define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */ /* Type to represent a reg/const reference during compilation, with <0 * indicating a constant. Some call sites also use -1 to indicate 'none'. @@ -4187,9 +4279,9 @@ typedef duk_int32_t duk_regconst_t; typedef struct { - duk_small_uint_t t; /* DUK_ISPEC_XXX */ + duk_small_uint_t t; /* DUK_ISPEC_XXX */ duk_regconst_t regconst; - duk_idx_t valstack_idx; /* always set; points to a reserved valstack slot */ + duk_idx_t valstack_idx; /* always set; points to a reserved valstack slot */ } duk_ispec; typedef struct { @@ -4201,8 +4293,8 @@ */ /* XXX: can be optimized for smaller footprint esp. on 32-bit environments */ - duk_small_uint_t t; /* DUK_IVAL_XXX */ - duk_small_uint_t op; /* bytecode opcode for binary ops */ + duk_small_uint_t t; /* DUK_IVAL_XXX */ + duk_small_uint_t op; /* bytecode opcode for binary ops */ duk_ispec x1; duk_ispec x2; } duk_ivalue; @@ -4224,22 +4316,22 @@ * Compiler state */ -#define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0) -#define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1) +#define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0) +#define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1) -#define DUK_DECL_TYPE_VAR 0 -#define DUK_DECL_TYPE_FUNC 1 +#define DUK_DECL_TYPE_VAR 0 +#define DUK_DECL_TYPE_FUNC 1 /* XXX: optimize to 16 bytes */ typedef struct { duk_small_uint_t flags; - duk_int_t label_id; /* numeric label_id (-1 reserved as marker) */ - duk_hstring *h_label; /* borrowed label name */ - duk_int_t catch_depth; /* catch depth at point of definition */ - duk_int_t pc_label; /* pc of label statement: - * pc+1: break jump site - * pc+2: continue jump site - */ + duk_int_t label_id; /* numeric label_id (-1 reserved as marker) */ + duk_hstring *h_label; /* borrowed label name */ + duk_int_t catch_depth; /* catch depth at point of definition */ + duk_int_t pc_label; /* pc of label statement: + * pc+1: break jump site + * pc+2: continue jump site + */ /* Fast jumps (which avoid longjmp) jump directly to the jump sites * which are always known even while the iteration/switch statement @@ -4255,22 +4347,22 @@ * platforms (e.g. if int is 32 bits and pointers are 64 bits). */ - duk_bufwriter_ctx bw_code; /* bufwriter for code */ + duk_bufwriter_ctx bw_code; /* bufwriter for code */ - duk_hstring *h_name; /* function name (borrowed reference), ends up in _name */ + duk_hstring *h_name; /* function name (borrowed reference), ends up in _name */ /* h_code: held in bw_code */ - duk_hobject *h_consts; /* array */ - duk_hobject *h_funcs; /* array of function templates: func1, offset1, line1, func2, offset2, line2 - * offset/line points to closing brace to allow skipping on pass 2 - */ - duk_hobject *h_decls; /* array of declarations: name1, val1, name2, val2, ... - * valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars) - * record function and variable declarations in pass 1 - */ - duk_hobject *h_labelnames; /* array of active label names */ - duk_hbuffer_dynamic *h_labelinfos; /* C array of duk_labelinfo */ - duk_hobject *h_argnames; /* array of formal argument names (-> _Formals) */ - duk_hobject *h_varmap; /* variable map for pass 2 (identifier -> register number or null (unmapped)) */ + duk_hobject *h_consts; /* array */ + duk_hobject *h_funcs; /* array of function templates: func1, offset1, line1, func2, offset2, line2 + * offset/line points to closing brace to allow skipping on pass 2 + */ + duk_hobject *h_decls; /* array of declarations: name1, val1, name2, val2, ... + * valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars) + * record function and variable declarations in pass 1 + */ + duk_hobject *h_labelnames; /* array of active label names */ + duk_hbuffer_dynamic *h_labelinfos; /* C array of duk_labelinfo */ + duk_hobject *h_argnames; /* array of formal argument names (-> _Formals) */ + duk_hobject *h_varmap; /* variable map for pass 2 (identifier -> register number or null (unmapped)) */ /* Value stack indices for tracking objects. */ /* code_idx: not needed */ @@ -4283,9 +4375,9 @@ duk_idx_t varmap_idx; /* Temp reg handling. */ - duk_regconst_t temp_first; /* first register that is a temporary (below: variables) */ - duk_regconst_t temp_next; /* next temporary register to allocate */ - duk_regconst_t temp_max; /* highest value of temp_reg (temp_max - 1 is highest used reg) */ + duk_regconst_t temp_first; /* first register that is a temporary (below: variables) */ + duk_regconst_t temp_next; /* next temporary register to allocate */ + duk_regconst_t temp_max; /* highest value of temp_reg (temp_max - 1 is highest used reg) */ /* Shuffle registers if large number of regs/consts. */ duk_regconst_t shuffle1; @@ -4295,49 +4387,51 @@ /* Stats for current expression being parsed. */ duk_int_t nud_count; duk_int_t led_count; - duk_int_t paren_level; /* parenthesis count, 0 = top level */ - duk_bool_t expr_lhs; /* expression is left-hand-side compatible */ - duk_bool_t allow_in; /* current paren level allows 'in' token */ + duk_int_t paren_level; /* parenthesis count, 0 = top level */ + duk_bool_t expr_lhs; /* expression is left-hand-side compatible */ + duk_bool_t allow_in; /* current paren level allows 'in' token */ /* Misc. */ - duk_int_t stmt_next; /* statement id allocation (running counter) */ - duk_int_t label_next; /* label id allocation (running counter) */ - duk_int_t catch_depth; /* catch stack depth */ - duk_int_t with_depth; /* with stack depth (affects identifier lookups) */ - duk_int_t fnum_next; /* inner function numbering */ - duk_int_t num_formals; /* number of formal arguments */ - duk_regconst_t reg_stmt_value; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */ + duk_int_t stmt_next; /* statement id allocation (running counter) */ + duk_int_t label_next; /* label id allocation (running counter) */ + duk_int_t catch_depth; /* catch stack depth */ + duk_int_t with_depth; /* with stack depth (affects identifier lookups) */ + duk_int_t fnum_next; /* inner function numbering */ + duk_int_t num_formals; /* number of formal arguments */ + duk_regconst_t + reg_stmt_value; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */ #if defined(DUK_USE_DEBUGGER_SUPPORT) - duk_int_t min_line; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */ + duk_int_t min_line; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */ duk_int_t max_line; #endif /* Status booleans. */ - duk_uint8_t is_function; /* is an actual function (not global/eval code) */ - duk_uint8_t is_eval; /* is eval code */ - duk_uint8_t is_global; /* is global code */ - duk_uint8_t is_namebinding; /* needs a name binding */ - duk_uint8_t is_constructable; /* result is constructable */ - duk_uint8_t is_setget; /* is a setter/getter */ - duk_uint8_t is_strict; /* function is strict */ - duk_uint8_t is_notail; /* function must not be tail called */ - duk_uint8_t in_directive_prologue; /* parsing in "directive prologue", recognize directives */ - duk_uint8_t in_scanning; /* parsing in "scanning" phase (first pass) */ - duk_uint8_t may_direct_eval; /* function may call direct eval */ - duk_uint8_t id_access_arguments; /* function refers to 'arguments' identifier */ - duk_uint8_t id_access_slow; /* function makes one or more slow path accesses that won't match own static variables */ - duk_uint8_t id_access_slow_own; /* function makes one or more slow path accesses that may match own static variables */ - duk_uint8_t is_arguments_shadowed; /* argument/function declaration shadows 'arguments' */ - duk_uint8_t needs_shuffle; /* function needs shuffle registers */ - duk_uint8_t reject_regexp_in_adv; /* reject RegExp literal on next advance() call; needed for handling IdentifierName productions */ - duk_uint8_t allow_regexp_in_adv; /* allow RegExp literal on next advance() call */ + duk_uint8_t is_function; /* is an actual function (not global/eval code) */ + duk_uint8_t is_eval; /* is eval code */ + duk_uint8_t is_global; /* is global code */ + duk_uint8_t is_namebinding; /* needs a name binding */ + duk_uint8_t is_constructable; /* result is constructable */ + duk_uint8_t is_setget; /* is a setter/getter */ + duk_uint8_t is_strict; /* function is strict */ + duk_uint8_t is_notail; /* function must not be tail called */ + duk_uint8_t in_directive_prologue; /* parsing in "directive prologue", recognize directives */ + duk_uint8_t in_scanning; /* parsing in "scanning" phase (first pass) */ + duk_uint8_t may_direct_eval; /* function may call direct eval */ + duk_uint8_t id_access_arguments; /* function refers to 'arguments' identifier */ + duk_uint8_t id_access_slow; /* function makes one or more slow path accesses that won't match own static variables */ + duk_uint8_t id_access_slow_own; /* function makes one or more slow path accesses that may match own static variables */ + duk_uint8_t is_arguments_shadowed; /* argument/function declaration shadows 'arguments' */ + duk_uint8_t needs_shuffle; /* function needs shuffle registers */ + duk_uint8_t + reject_regexp_in_adv; /* reject RegExp literal on next advance() call; needed for handling IdentifierName productions */ + duk_uint8_t allow_regexp_in_adv; /* allow RegExp literal on next advance() call */ }; struct duk_compiler_ctx { duk_hthread *thr; /* filename being compiled (ends up in functions' '_filename' property) */ - duk_hstring *h_filename; /* borrowed reference */ + duk_hstring *h_filename; /* borrowed reference */ /* lexing (tokenization) state (contains two valstack slot indices) */ duk_lexer_ctx lex; @@ -4345,10 +4439,10 @@ /* current and previous token for parsing */ duk_token prev_token; duk_token curr_token; - duk_idx_t tok11_idx; /* curr_token slot1 (matches 'lex' slot1_idx) */ - duk_idx_t tok12_idx; /* curr_token slot2 (matches 'lex' slot2_idx) */ - duk_idx_t tok21_idx; /* prev_token slot1 */ - duk_idx_t tok22_idx; /* prev_token slot2 */ + duk_idx_t tok11_idx; /* curr_token slot1 (matches 'lex' slot1_idx) */ + duk_idx_t tok12_idx; /* curr_token slot2 (matches 'lex' slot2_idx) */ + duk_idx_t tok21_idx; /* prev_token slot1 */ + duk_idx_t tok22_idx; /* prev_token slot2 */ /* recursion limit */ duk_int_t recursion_depth; @@ -4365,9 +4459,12 @@ * Prototypes */ -DUK_INTERNAL_DECL void duk_js_compile(duk_hthread *thr, const duk_uint8_t *src_buffer, duk_size_t src_length, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_js_compile(duk_hthread *thr, + const duk_uint8_t *src_buffer, + duk_size_t src_length, + duk_small_uint_t flags); -#endif /* DUK_JS_COMPILER_H_INCLUDED */ +#endif /* DUK_JS_COMPILER_H_INCLUDED */ /* #include duk_regexp.h */ /* * Regular expression structs, constants, and bytecode defines. @@ -4377,39 +4474,39 @@ #define DUK_REGEXP_H_INCLUDED /* maximum bytecode copies for {n,m} quantifiers */ -#define DUK_RE_MAX_ATOM_COPIES 1000 +#define DUK_RE_MAX_ATOM_COPIES 1000 /* regexp compilation limits */ -#define DUK_RE_COMPILE_TOKEN_LIMIT 100000000L /* 1e8 */ +#define DUK_RE_COMPILE_TOKEN_LIMIT 100000000L /* 1e8 */ /* regexp execution limits */ -#define DUK_RE_EXECUTE_STEPS_LIMIT 1000000000L /* 1e9 */ +#define DUK_RE_EXECUTE_STEPS_LIMIT 1000000000L /* 1e9 */ /* regexp opcodes */ -#define DUK_REOP_MATCH 1 -#define DUK_REOP_CHAR 2 -#define DUK_REOP_PERIOD 3 -#define DUK_REOP_RANGES 4 -#define DUK_REOP_INVRANGES 5 -#define DUK_REOP_JUMP 6 -#define DUK_REOP_SPLIT1 7 -#define DUK_REOP_SPLIT2 8 -#define DUK_REOP_SQMINIMAL 9 -#define DUK_REOP_SQGREEDY 10 -#define DUK_REOP_SAVE 11 -#define DUK_REOP_WIPERANGE 12 -#define DUK_REOP_LOOKPOS 13 -#define DUK_REOP_LOOKNEG 14 -#define DUK_REOP_BACKREFERENCE 15 -#define DUK_REOP_ASSERT_START 16 -#define DUK_REOP_ASSERT_END 17 -#define DUK_REOP_ASSERT_WORD_BOUNDARY 18 -#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY 19 +#define DUK_REOP_MATCH 1 +#define DUK_REOP_CHAR 2 +#define DUK_REOP_PERIOD 3 +#define DUK_REOP_RANGES 4 +#define DUK_REOP_INVRANGES 5 +#define DUK_REOP_JUMP 6 +#define DUK_REOP_SPLIT1 7 +#define DUK_REOP_SPLIT2 8 +#define DUK_REOP_SQMINIMAL 9 +#define DUK_REOP_SQGREEDY 10 +#define DUK_REOP_SAVE 11 +#define DUK_REOP_WIPERANGE 12 +#define DUK_REOP_LOOKPOS 13 +#define DUK_REOP_LOOKNEG 14 +#define DUK_REOP_BACKREFERENCE 15 +#define DUK_REOP_ASSERT_START 16 +#define DUK_REOP_ASSERT_END 17 +#define DUK_REOP_ASSERT_WORD_BOUNDARY 18 +#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY 19 /* flags */ -#define DUK_RE_FLAG_GLOBAL (1U << 0) -#define DUK_RE_FLAG_IGNORE_CASE (1U << 1) -#define DUK_RE_FLAG_MULTILINE (1U << 2) +#define DUK_RE_FLAG_GLOBAL (1U << 0) +#define DUK_RE_FLAG_IGNORE_CASE (1U << 1) +#define DUK_RE_FLAG_MULTILINE (1U << 2) struct duk_re_matcher_ctx { duk_hthread *thr; @@ -4419,7 +4516,7 @@ const duk_uint8_t *input_end; const duk_uint8_t *bytecode; const duk_uint8_t *bytecode_end; - const duk_uint8_t **saved; /* allocated from valstack (fixed buffer) */ + const duk_uint8_t **saved; /* allocated from valstack (fixed buffer) */ duk_uint32_t nsaved; duk_uint32_t recursion_depth; duk_uint32_t recursion_limit; @@ -4434,11 +4531,11 @@ duk_lexer_ctx lex; duk_re_token curr_token; duk_bufwriter_ctx bw; - duk_uint32_t captures; /* highest capture number emitted so far (used as: ++captures) */ + duk_uint32_t captures; /* highest capture number emitted so far (used as: ++captures) */ duk_uint32_t highest_backref; duk_uint32_t recursion_depth; duk_uint32_t recursion_limit; - duk_uint32_t nranges; /* internal temporary value, used for char classes */ + duk_uint32_t nranges; /* internal temporary value, used for char classes */ }; /* @@ -4449,10 +4546,10 @@ DUK_INTERNAL_DECL void duk_regexp_compile(duk_hthread *thr); DUK_INTERNAL_DECL void duk_regexp_create_instance(duk_hthread *thr); DUK_INTERNAL_DECL void duk_regexp_match(duk_hthread *thr); -DUK_INTERNAL_DECL void duk_regexp_match_force_global(duk_hthread *thr); /* hacky helper for String.prototype.split() */ +DUK_INTERNAL_DECL void duk_regexp_match_force_global(duk_hthread *thr); /* hacky helper for String.prototype.split() */ #endif -#endif /* DUK_REGEXP_H_INCLUDED */ +#endif /* DUK_REGEXP_H_INCLUDED */ /* #include duk_heaphdr.h */ /* * Heap header definition and assorted macros, including ref counting. @@ -4505,7 +4602,7 @@ #else duk_size_t h_refcount; #endif -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_HEAPPTR16) duk_uint16_t h_next16; @@ -4553,7 +4650,7 @@ #endif #if defined(DUK_USE_REFCOUNT16) duk_uint16_t h_refcount; - duk_uint16_t h_strextra16; /* round out to 8 bytes */ + duk_uint16_t h_strextra16; /* round out to 8 bytes */ #elif defined(DUK_USE_REFCOUNT32) duk_uint32_t h_refcount; #else @@ -4561,160 +4658,169 @@ #endif #else duk_uint16_t h_strextra16; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ duk_hstring *h_next; /* No 'h_prev' pointer for strings. */ }; -#define DUK_HEAPHDR_FLAGS_TYPE_MASK 0x00000003UL -#define DUK_HEAPHDR_FLAGS_FLAG_MASK (~DUK_HEAPHDR_FLAGS_TYPE_MASK) +#define DUK_HEAPHDR_FLAGS_TYPE_MASK 0x00000003UL +#define DUK_HEAPHDR_FLAGS_FLAG_MASK (~DUK_HEAPHDR_FLAGS_TYPE_MASK) - /* 2 bits for heap type */ -#define DUK_HEAPHDR_FLAGS_HEAP_START 2 /* 5 heap flags */ -#define DUK_HEAPHDR_FLAGS_USER_START 7 /* 25 user flags */ - -#define DUK_HEAPHDR_HEAP_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_HEAP_START + (n)) -#define DUK_HEAPHDR_USER_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_USER_START + (n)) -#define DUK_HEAPHDR_HEAP_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_HEAP_START + (n))) -#define DUK_HEAPHDR_USER_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_USER_START + (n))) - -#define DUK_HEAPHDR_FLAG_REACHABLE DUK_HEAPHDR_HEAP_FLAG(0) /* mark-and-sweep: reachable */ -#define DUK_HEAPHDR_FLAG_TEMPROOT DUK_HEAPHDR_HEAP_FLAG(1) /* mark-and-sweep: children not processed */ -#define DUK_HEAPHDR_FLAG_FINALIZABLE DUK_HEAPHDR_HEAP_FLAG(2) /* mark-and-sweep: finalizable (on current pass) */ -#define DUK_HEAPHDR_FLAG_FINALIZED DUK_HEAPHDR_HEAP_FLAG(3) /* mark-and-sweep: finalized (on previous pass) */ -#define DUK_HEAPHDR_FLAG_READONLY DUK_HEAPHDR_HEAP_FLAG(4) /* read-only object, in code section */ - -#define DUK_HTYPE_MIN 0 -#define DUK_HTYPE_STRING 0 -#define DUK_HTYPE_OBJECT 1 -#define DUK_HTYPE_BUFFER 2 -#define DUK_HTYPE_MAX 2 +/* 2 bits for heap type */ +#define DUK_HEAPHDR_FLAGS_HEAP_START 2 /* 5 heap flags */ +#define DUK_HEAPHDR_FLAGS_USER_START 7 /* 25 user flags */ + +#define DUK_HEAPHDR_HEAP_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_HEAP_START + (n)) +#define DUK_HEAPHDR_USER_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_USER_START + (n)) +#define DUK_HEAPHDR_HEAP_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_HEAP_START + (n))) +#define DUK_HEAPHDR_USER_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_USER_START + (n))) + +#define DUK_HEAPHDR_FLAG_REACHABLE DUK_HEAPHDR_HEAP_FLAG(0) /* mark-and-sweep: reachable */ +#define DUK_HEAPHDR_FLAG_TEMPROOT DUK_HEAPHDR_HEAP_FLAG(1) /* mark-and-sweep: children not processed */ +#define DUK_HEAPHDR_FLAG_FINALIZABLE DUK_HEAPHDR_HEAP_FLAG(2) /* mark-and-sweep: finalizable (on current pass) */ +#define DUK_HEAPHDR_FLAG_FINALIZED DUK_HEAPHDR_HEAP_FLAG(3) /* mark-and-sweep: finalized (on previous pass) */ +#define DUK_HEAPHDR_FLAG_READONLY DUK_HEAPHDR_HEAP_FLAG(4) /* read-only object, in code section */ + +#define DUK_HTYPE_MIN 0 +#define DUK_HTYPE_STRING 0 +#define DUK_HTYPE_OBJECT 1 +#define DUK_HTYPE_BUFFER 2 +#define DUK_HTYPE_MAX 2 #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAPHDR_GET_NEXT(heap,h) \ - ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_next16)) -#define DUK_HEAPHDR_SET_NEXT(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_NEXT(heap, h) ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_next16)) +#define DUK_HEAPHDR_SET_NEXT(heap, h, val) \ + do { \ (h)->h_next16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) val); \ } while (0) #else -#define DUK_HEAPHDR_GET_NEXT(heap,h) ((h)->h_next) -#define DUK_HEAPHDR_SET_NEXT(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_NEXT(heap, h) ((h)->h_next) +#define DUK_HEAPHDR_SET_NEXT(heap, h, val) \ + do { \ (h)->h_next = (val); \ } while (0) #endif #if defined(DUK_USE_DOUBLE_LINKED_HEAP) #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAPHDR_GET_PREV(heap,h) \ - ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_prev16)) -#define DUK_HEAPHDR_SET_PREV(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_PREV(heap, h) ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_prev16)) +#define DUK_HEAPHDR_SET_PREV(heap, h, val) \ + do { \ (h)->h_prev16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (val)); \ } while (0) #else -#define DUK_HEAPHDR_GET_PREV(heap,h) ((h)->h_prev) -#define DUK_HEAPHDR_SET_PREV(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_PREV(heap, h) ((h)->h_prev) +#define DUK_HEAPHDR_SET_PREV(heap, h, val) \ + do { \ (h)->h_prev = (val); \ } while (0) #endif #endif #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAPHDR_GET_REFCOUNT(h) ((h)->h_refcount) -#define DUK_HEAPHDR_SET_REFCOUNT(h,val) do { \ +#define DUK_HEAPHDR_GET_REFCOUNT(h) ((h)->h_refcount) +#define DUK_HEAPHDR_SET_REFCOUNT(h, val) \ + do { \ (h)->h_refcount = (val); \ - DUK_ASSERT((h)->h_refcount == (val)); /* No truncation. */ \ + DUK_ASSERT((h)->h_refcount == (val)); /* No truncation. */ \ } while (0) -#define DUK_HEAPHDR_PREINC_REFCOUNT(h) (++(h)->h_refcount) /* result: updated refcount */ -#define DUK_HEAPHDR_PREDEC_REFCOUNT(h) (--(h)->h_refcount) /* result: updated refcount */ +#define DUK_HEAPHDR_PREINC_REFCOUNT(h) (++(h)->h_refcount) /* result: updated refcount */ +#define DUK_HEAPHDR_PREDEC_REFCOUNT(h) (--(h)->h_refcount) /* result: updated refcount */ #else /* refcount macros not defined without refcounting, caller must #if defined() now */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Note: type is treated as a field separate from flags, so some masking is * involved in the macros below. */ -#define DUK_HEAPHDR_GET_FLAGS_RAW(h) ((h)->h_flags) -#define DUK_HEAPHDR_SET_FLAGS_RAW(h,val) do { \ - (h)->h_flags = (val); } \ +#define DUK_HEAPHDR_GET_FLAGS_RAW(h) ((h)->h_flags) +#define DUK_HEAPHDR_SET_FLAGS_RAW(h, val) \ + do { \ + (h)->h_flags = (val); \ + } \ } -#define DUK_HEAPHDR_GET_FLAGS(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_FLAG_MASK) -#define DUK_HEAPHDR_SET_FLAGS(h,val) do { \ +#define DUK_HEAPHDR_GET_FLAGS(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_FLAG_MASK) +#define DUK_HEAPHDR_SET_FLAGS(h, val) \ + do { \ (h)->h_flags = ((h)->h_flags & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) | (val); \ } while (0) -#define DUK_HEAPHDR_GET_TYPE(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_TYPE_MASK) -#define DUK_HEAPHDR_SET_TYPE(h,val) do { \ +#define DUK_HEAPHDR_GET_TYPE(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_TYPE_MASK) +#define DUK_HEAPHDR_SET_TYPE(h, val) \ + do { \ (h)->h_flags = ((h)->h_flags & ~(DUK_HEAPHDR_FLAGS_TYPE_MASK)) | (val); \ } while (0) /* Comparison for type >= DUK_HTYPE_MIN skipped; because DUK_HTYPE_MIN is zero * and the comparison is unsigned, it's always true and generates warnings. */ -#define DUK_HEAPHDR_HTYPE_VALID(h) ( \ - DUK_HEAPHDR_GET_TYPE((h)) <= DUK_HTYPE_MAX \ - ) +#define DUK_HEAPHDR_HTYPE_VALID(h) (DUK_HEAPHDR_GET_TYPE((h)) <= DUK_HTYPE_MAX) -#define DUK_HEAPHDR_SET_TYPE_AND_FLAGS(h,tval,fval) do { \ - (h)->h_flags = ((tval) & DUK_HEAPHDR_FLAGS_TYPE_MASK) | \ - ((fval) & DUK_HEAPHDR_FLAGS_FLAG_MASK); \ +#define DUK_HEAPHDR_SET_TYPE_AND_FLAGS(h, tval, fval) \ + do { \ + (h)->h_flags = ((tval) &DUK_HEAPHDR_FLAGS_TYPE_MASK) | ((fval) &DUK_HEAPHDR_FLAGS_FLAG_MASK); \ } while (0) -#define DUK_HEAPHDR_SET_FLAG_BITS(h,bits) do { \ +#define DUK_HEAPHDR_SET_FLAG_BITS(h, bits) \ + do { \ DUK_ASSERT(((bits) & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) == 0); \ (h)->h_flags |= (bits); \ } while (0) -#define DUK_HEAPHDR_CLEAR_FLAG_BITS(h,bits) do { \ +#define DUK_HEAPHDR_CLEAR_FLAG_BITS(h, bits) \ + do { \ DUK_ASSERT(((bits) & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) == 0); \ (h)->h_flags &= ~((bits)); \ } while (0) -#define DUK_HEAPHDR_CHECK_FLAG_BITS(h,bits) (((h)->h_flags & (bits)) != 0) +#define DUK_HEAPHDR_CHECK_FLAG_BITS(h, bits) (((h)->h_flags & (bits)) != 0) -#define DUK_HEAPHDR_SET_REACHABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) -#define DUK_HEAPHDR_CLEAR_REACHABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) -#define DUK_HEAPHDR_HAS_REACHABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) - -#define DUK_HEAPHDR_SET_TEMPROOT(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) -#define DUK_HEAPHDR_CLEAR_TEMPROOT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) -#define DUK_HEAPHDR_HAS_TEMPROOT(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) - -#define DUK_HEAPHDR_SET_FINALIZABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) -#define DUK_HEAPHDR_CLEAR_FINALIZABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) -#define DUK_HEAPHDR_HAS_FINALIZABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) - -#define DUK_HEAPHDR_SET_FINALIZED(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) -#define DUK_HEAPHDR_CLEAR_FINALIZED(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) -#define DUK_HEAPHDR_HAS_FINALIZED(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) - -#define DUK_HEAPHDR_SET_READONLY(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) -#define DUK_HEAPHDR_CLEAR_READONLY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) -#define DUK_HEAPHDR_HAS_READONLY(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_SET_REACHABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) +#define DUK_HEAPHDR_CLEAR_REACHABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) +#define DUK_HEAPHDR_HAS_REACHABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) + +#define DUK_HEAPHDR_SET_TEMPROOT(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) +#define DUK_HEAPHDR_CLEAR_TEMPROOT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) +#define DUK_HEAPHDR_HAS_TEMPROOT(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) + +#define DUK_HEAPHDR_SET_FINALIZABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) +#define DUK_HEAPHDR_CLEAR_FINALIZABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) +#define DUK_HEAPHDR_HAS_FINALIZABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) + +#define DUK_HEAPHDR_SET_FINALIZED(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) +#define DUK_HEAPHDR_CLEAR_FINALIZED(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) +#define DUK_HEAPHDR_HAS_FINALIZED(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) + +#define DUK_HEAPHDR_SET_READONLY(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_CLEAR_READONLY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_HAS_READONLY(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) /* get or set a range of flags; m=first bit number, n=number of bits */ -#define DUK_HEAPHDR_GET_FLAG_RANGE(h,m,n) (((h)->h_flags >> (m)) & ((1UL << (n)) - 1UL)) +#define DUK_HEAPHDR_GET_FLAG_RANGE(h, m, n) (((h)->h_flags >> (m)) & ((1UL << (n)) - 1UL)) -#define DUK_HEAPHDR_SET_FLAG_RANGE(h,m,n,v) do { \ - (h)->h_flags = \ - ((h)->h_flags & (~(((1UL << (n)) - 1UL) << (m)))) \ - | ((v) << (m)); \ +#define DUK_HEAPHDR_SET_FLAG_RANGE(h, m, n, v) \ + do { \ + (h)->h_flags = ((h)->h_flags & (~(((1UL << (n)) - 1UL) << (m)))) | ((v) << (m)); \ } while (0) /* init pointer fields to null */ #if defined(DUK_USE_DOUBLE_LINKED_HEAP) -#define DUK_HEAPHDR_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_INIT_NULLS(h) \ + do { \ DUK_HEAPHDR_SET_NEXT((h), (void *) NULL); \ DUK_HEAPHDR_SET_PREV((h), (void *) NULL); \ } while (0) #else -#define DUK_HEAPHDR_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_INIT_NULLS(h) \ + do { \ DUK_HEAPHDR_SET_NEXT((h), (void *) NULL); \ } while (0) #endif -#define DUK_HEAPHDR_STRING_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_STRING_INIT_NULLS(h) \ + do { \ (h)->h_next = NULL; \ } while (0) @@ -4743,14 +4849,24 @@ DUK_INTERNAL_DECL void duk_heaphdr_assert_valid_subclassed(duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_assert_links(duk_heap *heap, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_assert_valid(duk_heaphdr *h); -#define DUK_HEAPHDR_ASSERT_LINKS(heap,h) do { duk_heaphdr_assert_links((heap), (h)); } while (0) -#define DUK_HEAPHDR_ASSERT_VALID(h) do { duk_heaphdr_assert_valid((h)); } while (0) +#define DUK_HEAPHDR_ASSERT_LINKS(heap, h) \ + do { \ + duk_heaphdr_assert_links((heap), (h)); \ + } while (0) +#define DUK_HEAPHDR_ASSERT_VALID(h) \ + do { \ + duk_heaphdr_assert_valid((h)); \ + } while (0) #else -#define DUK_HEAPHDR_ASSERT_LINKS(heap,h) do {} while (0) -#define DUK_HEAPHDR_ASSERT_VALID(h) do {} while (0) +#define DUK_HEAPHDR_ASSERT_LINKS(heap, h) \ + do { \ + } while (0) +#define DUK_HEAPHDR_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#endif /* DUK_HEAPHDR_H_INCLUDED */ +#endif /* DUK_HEAPHDR_H_INCLUDED */ /* #include duk_refcount.h */ /* * Reference counting helper macros. The macros take a thread argument @@ -4771,19 +4887,20 @@ /* XXX: double evaluation for 'tv' argument. */ #define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) \ (DUK_TVAL_IS_HEAP_ALLOCATED((tv)) && !DUK_HEAPHDR_HAS_READONLY(DUK_TVAL_GET_HEAPHDR((tv)))) -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) (!DUK_HEAPHDR_HAS_READONLY((h))) -#else /* DUK_USE_ROM_OBJECTS */ +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) (!DUK_HEAPHDR_HAS_READONLY((h))) +#else /* DUK_USE_ROM_OBJECTS */ /* Without ROM objects "needs refcount update" == is heap allocated. */ -#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) DUK_TVAL_IS_HEAP_ALLOCATED((tv)) -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 1 -#endif /* DUK_USE_ROM_OBJECTS */ +#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) DUK_TVAL_IS_HEAP_ALLOCATED((tv)) +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 1 +#endif /* DUK_USE_ROM_OBJECTS */ /* Fast variants, inline refcount operations except for refzero handling. * Can be used explicitly when speed is always more important than size. * For a good compiler and a single file build, these are basically the * same as a forced inline. */ -#define DUK_TVAL_INCREF_FAST(thr,tv) do { \ +#define DUK_TVAL_INCREF_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -4791,10 +4908,11 @@ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ DUK_HEAPHDR_PREINC_REFCOUNT(duk__h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ } \ } while (0) -#define DUK_TVAL_DECREF_FAST(thr,tv) do { \ +#define DUK_TVAL_DECREF_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -4807,7 +4925,8 @@ } \ } \ } while (0) -#define DUK_TVAL_DECREF_NORZ_FAST(thr,tv) do { \ +#define DUK_TVAL_DECREF_NORZ_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -4820,16 +4939,18 @@ } \ } \ } while (0) -#define DUK_HEAPHDR_INCREF_FAST(thr,h) do { \ +#define DUK_HEAPHDR_INCREF_FAST(thr, h) \ + do { \ duk_heaphdr *duk__h = (duk_heaphdr *) (h); \ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ if (DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(duk__h)) { \ DUK_HEAPHDR_PREINC_REFCOUNT(duk__h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_FAST_RAW(thr,h,rzcall,rzcast) do { \ +#define DUK_HEAPHDR_DECREF_FAST_RAW(thr, h, rzcall, rzcast) \ + do { \ duk_heaphdr *duk__h = (duk_heaphdr *) (h); \ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ @@ -4840,29 +4961,72 @@ } \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_FAST(thr,h) \ - DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero,duk_heaphdr *) -#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr,h) \ - DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero_norz,duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_FAST(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero, duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero_norz, duk_heaphdr *) /* Slow variants, call to a helper to reduce code size. * Can be used explicitly when size is always more important than speed. */ -#define DUK_TVAL_INCREF_SLOW(thr,tv) do { duk_tval_incref((tv)); } while (0) -#define DUK_TVAL_DECREF_SLOW(thr,tv) do { duk_tval_decref((thr), (tv)); } while (0) -#define DUK_TVAL_DECREF_NORZ_SLOW(thr,tv) do { duk_tval_decref_norz((thr), (tv)); } while (0) -#define DUK_HEAPHDR_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HEAPHDR_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) +#define DUK_TVAL_INCREF_SLOW(thr, tv) \ + do { \ + duk_tval_incref((tv)); \ + } while (0) +#define DUK_TVAL_DECREF_SLOW(thr, tv) \ + do { \ + duk_tval_decref((thr), (tv)); \ + } while (0) +#define DUK_TVAL_DECREF_NORZ_SLOW(thr, tv) \ + do { \ + duk_tval_decref_norz((thr), (tv)); \ + } while (0) +#define DUK_HEAPHDR_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HEAPHDR_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) /* Default variants. Selection depends on speed/size preference. * Concretely: with gcc 4.8.1 -Os x64 the difference in final binary @@ -4872,122 +5036,136 @@ /* XXX: It would be nice to specialize for specific duk_hobject subtypes * but current refzero queue handling prevents that. */ -#define DUK_TVAL_INCREF(thr,tv) DUK_TVAL_INCREF_FAST((thr),(tv)) -#define DUK_TVAL_DECREF(thr,tv) DUK_TVAL_DECREF_FAST((thr),(tv)) -#define DUK_TVAL_DECREF_NORZ(thr,tv) DUK_TVAL_DECREF_NORZ_FAST((thr),(tv)) -#define DUK_HEAPHDR_INCREF(thr,h) DUK_HEAPHDR_INCREF_FAST((thr),(h)) -#define DUK_HEAPHDR_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero,duk_heaphdr *) -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero_norz,duk_heaphdr *) -#define DUK_HSTRING_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HSTRING_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hstring_refzero,duk_hstring *) -#define DUK_HSTRING_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hstring_refzero,duk_hstring *) /* no 'norz' variant */ -#define DUK_HOBJECT_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HOBJECT_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HOBJECT_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HBUFFER_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HBUFFER_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hbuffer_refzero,duk_hbuffer *) -#define DUK_HBUFFER_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hbuffer_refzero,duk_hbuffer *) /* no 'norz' variant */ -#define DUK_HCOMPFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HNATFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HNATFUNC_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HBUFOBJ_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HBUFOBJ_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HBUFOBJ_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HTHREAD_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HTHREAD_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HTHREAD_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#else -#define DUK_TVAL_INCREF(thr,tv) DUK_TVAL_INCREF_SLOW((thr),(tv)) -#define DUK_TVAL_DECREF(thr,tv) DUK_TVAL_DECREF_SLOW((thr),(tv)) -#define DUK_TVAL_DECREF_NORZ(thr,tv) DUK_TVAL_DECREF_NORZ_SLOW((thr),(tv)) -#define DUK_HEAPHDR_INCREF(thr,h) DUK_HEAPHDR_INCREF_SLOW((thr),(h)) -#define DUK_HEAPHDR_DECREF(thr,h) DUK_HEAPHDR_DECREF_SLOW((thr),(h)) -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HSTRING_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HSTRING_DECREF(thr,h) DUK_HSTRING_DECREF_SLOW((thr),(h)) -#define DUK_HSTRING_DECREF_NORZ(thr,h) DUK_HSTRING_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HOBJECT_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HOBJECT_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(h)) -#define DUK_HOBJECT_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HBUFFER_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HBUFFER_DECREF(thr,h) DUK_HBUFFER_DECREF_SLOW((thr),(h)) -#define DUK_HBUFFER_DECREF_NORZ(thr,h) DUK_HBUFFER_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HCOMPFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HNATFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HNATFUNC_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HBUFOBJ_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HBUFOBJ_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HBUFOB_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HTHREAD_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HTHREAD_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HTHREAD_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) +#define DUK_TVAL_INCREF(thr, tv) DUK_TVAL_INCREF_FAST((thr), (tv)) +#define DUK_TVAL_DECREF(thr, tv) DUK_TVAL_DECREF_FAST((thr), (tv)) +#define DUK_TVAL_DECREF_NORZ(thr, tv) DUK_TVAL_DECREF_NORZ_FAST((thr), (tv)) +#define DUK_HEAPHDR_INCREF(thr, h) DUK_HEAPHDR_INCREF_FAST((thr), (h)) +#define DUK_HEAPHDR_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero, duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero_norz, duk_heaphdr *) +#define DUK_HSTRING_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HSTRING_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hstring_refzero, duk_hstring *) +#define DUK_HSTRING_DECREF_NORZ(thr, h) \ + DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hstring_refzero, duk_hstring *) /* no 'norz' variant */ +#define DUK_HOBJECT_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HOBJECT_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HOBJECT_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HBUFFER_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HBUFFER_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hbuffer_refzero, duk_hbuffer *) +#define DUK_HBUFFER_DECREF_NORZ(thr, h) \ + DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hbuffer_refzero, duk_hbuffer *) /* no 'norz' variant */ +#define DUK_HCOMPFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HNATFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HNATFUNC_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HBUFOBJ_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HBUFOBJ_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HBUFOBJ_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HTHREAD_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HTHREAD_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HTHREAD_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#else +#define DUK_TVAL_INCREF(thr, tv) DUK_TVAL_INCREF_SLOW((thr), (tv)) +#define DUK_TVAL_DECREF(thr, tv) DUK_TVAL_DECREF_SLOW((thr), (tv)) +#define DUK_TVAL_DECREF_NORZ(thr, tv) DUK_TVAL_DECREF_NORZ_SLOW((thr), (tv)) +#define DUK_HEAPHDR_INCREF(thr, h) DUK_HEAPHDR_INCREF_SLOW((thr), (h)) +#define DUK_HEAPHDR_DECREF(thr, h) DUK_HEAPHDR_DECREF_SLOW((thr), (h)) +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HSTRING_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HSTRING_DECREF(thr, h) DUK_HSTRING_DECREF_SLOW((thr), (h)) +#define DUK_HSTRING_DECREF_NORZ(thr, h) DUK_HSTRING_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HOBJECT_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HOBJECT_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (h)) +#define DUK_HOBJECT_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HBUFFER_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HBUFFER_DECREF(thr, h) DUK_HBUFFER_DECREF_SLOW((thr), (h)) +#define DUK_HBUFFER_DECREF_NORZ(thr, h) DUK_HBUFFER_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HCOMPFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HNATFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HNATFUNC_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HBUFOBJ_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HBUFOBJ_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HBUFOB_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HTHREAD_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HTHREAD_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HTHREAD_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) #endif /* Convenience for some situations; the above macros don't allow NULLs * for performance reasons. Macros cover only actually needed cases. */ -#define DUK_HEAPHDR_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_DECREF((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_DECREF_NORZ((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HOBJECT_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HOBJECT_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_DECREF_NORZ((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_DECREF_NORZ((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_DECREF_NORZ((thr), (h)); \ } \ @@ -4999,16 +5177,22 @@ * variant is performance critical. */ #if defined(DUK_USE_FINALIZER_SUPPORT) -#define DUK_REFZERO_CHECK_FAST(thr) do { \ +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ duk_refzero_check_fast((thr)); \ } while (0) -#define DUK_REFZERO_CHECK_SLOW(thr) do { \ +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ duk_refzero_check_slow((thr)); \ } while (0) -#else /* DUK_USE_FINALIZER_SUPPORT */ -#define DUK_REFZERO_CHECK_FAST(thr) do { } while (0) -#define DUK_REFZERO_CHECK_SLOW(thr) do { } while (0) -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ + } while (0) +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ + } while (0) +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Macros to set a duk_tval and update refcount of the target (decref the @@ -5016,125 +5200,176 @@ * and footprint critical; any changes made should be measured for size/speed. */ -#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ DUK_TVAL_DECREF_NORZ((thr), &tv__tmp); \ } while (0) -#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNUSED(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NULL(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_BOOLEAN(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NUMBER(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_DOUBLE(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NAN(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_I48(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_I32(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_U32(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) #else -#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr,tvptr_dst,newval) \ +#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr, tvptr_dst, newval) \ DUK_TVAL_SET_DOUBLE_UPDREF((thr), (tvptr_dst), (duk_double_t) (newval)) -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr,tvptr_dst,lf_v,lf_fp,lf_flags) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr, tvptr_dst, lf_v, lf_fp, lf_flags) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_LIGHTFUNC(tv__dst, (lf_v), (lf_fp), (lf_flags)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_STRING(tv__dst, (newval)); \ DUK_HSTRING_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_OBJECT(tv__dst, (newval)); \ DUK_HOBJECT_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_BUFFER(tv__dst, (newval)); \ DUK_HBUFFER_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_POINTER(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) /* DUK_TVAL_SET_TVAL_UPDREF() is used a lot in executor, property lookups, @@ -5145,281 +5380,452 @@ */ /* Original idiom used, minimal code size. */ -#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr,tvptr_dst,tvptr_src) do { \ - duk_tval *tv__dst, *tv__src; duk_tval tv__tmp; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr, tvptr_dst, tvptr_src) \ + do { \ + duk_tval *tv__dst, *tv__src; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ DUK_TVAL_INCREF((thr), tv__src); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) /* Faster alternative: avoid making a temporary copy of tvptr_dst and use * fast incref/decref macros. */ -#define DUK_TVAL_SET_TVAL_UPDREF_ALT1(thr,tvptr_dst,tvptr_src) do { \ - duk_tval *tv__dst, *tv__src; duk_heaphdr *h__obj; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT1(thr, tvptr_dst, tvptr_src) \ + do { \ + duk_tval *tv__dst, *tv__src; \ + duk_heaphdr *h__obj; \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_INCREF_FAST((thr), tv__src); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv__dst)) { \ h__obj = DUK_TVAL_GET_HEAPHDR(tv__dst); \ DUK_ASSERT(h__obj != NULL); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ - DUK_HEAPHDR_DECREF_FAST((thr), h__obj); /* side effects */ \ + DUK_HEAPHDR_DECREF_FAST((thr), h__obj); /* side effects */ \ } else { \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ } \ } while (0) /* XXX: no optimized variants yet */ -#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0 -#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 -#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 -#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 -#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 -#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0 +#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 +#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 +#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 +#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 +#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 -#else -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 -#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 -#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 -#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 -#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 +#else +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 +#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 +#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 +#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 +#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 #if defined(DUK_USE_FAST_REFCOUNT_DEFAULT) /* Optimized for speed. */ -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT1 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT1 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT1 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT1 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 #else /* Optimized for size. */ -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#endif - -#else /* DUK_USE_REFERENCE_COUNTING */ - -#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) 0 -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 0 - -#define DUK_TVAL_INCREF_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_INCREF_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_INCREF(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ(thr,v) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ(thr,h) do {} while (0) /* nop */ - -#define DUK_HCOMPFUNC_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HCOMPFUNC_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr,h) do {} while (0) /* nop */ - -#define DUK_REFZERO_CHECK_FAST(thr) do {} while (0) /* nop */ -#define DUK_REFZERO_CHECK_SLOW(thr) do {} while (0) /* nop */ - -#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#endif + +#else /* DUK_USE_REFERENCE_COUNTING */ + +#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) 0 +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 0 + +#define DUK_TVAL_INCREF_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_INCREF_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_INCREF(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ + +#define DUK_HCOMPFUNC_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HCOMPFUNC_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ + +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ + } while (0) /* nop */ +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ + } while (0) /* nop */ + +#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_UNUSED(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NULL(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_BOOLEAN(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NUMBER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_DOUBLE(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NAN(tv__dst); \ DUK_UNREF((thr)); \ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_I48(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_I32(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_U32(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) #else -#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr,tvptr_dst,newval) \ +#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr, tvptr_dst, newval) \ DUK_TVAL_SET_DOUBLE_UPDREF((thr), (tvptr_dst), (duk_double_t) (newval)) -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr,tvptr_dst,lf_v,lf_fp,lf_flags) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr, tvptr_dst, lf_v, lf_fp, lf_flags) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_LIGHTFUNC(tv__dst, (lf_v), (lf_fp), (lf_flags)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_STRING(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_OBJECT(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_BUFFER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_POINTER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr,tvptr_dst,tvptr_src) do { \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr, tvptr_dst, tvptr_src) \ + do { \ duk_tval *tv__dst, *tv__src; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 -#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 -#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 -#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 -#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 +#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 +#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 +#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 +#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 -#else -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast-int-to-double */ -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 -#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 -#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 -#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 -#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 - -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 +#else +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast-int-to-double */ +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 +#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 +#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 +#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 +#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 + +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Some convenience macros that don't have optimized implementations now. */ -#define DUK_TVAL_SET_TVAL_UPDREF_NORZ(thr,tv_dst,tv_src) do { \ +#define DUK_TVAL_SET_TVAL_UPDREF_NORZ(thr, tv_dst, tv_src) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_tval *duk__dst = (tv_dst); \ duk_tval *duk__src = (tv_src); \ @@ -5429,7 +5835,8 @@ DUK_TVAL_INCREF(thr, duk__dst); \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_NORZ(thr,tv_dst,val) do { \ +#define DUK_TVAL_SET_U32_UPDREF_NORZ(thr, tv_dst, val) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_tval *duk__dst = (tv_dst); \ duk_uint32_t duk__val = (duk_uint32_t) (val); \ @@ -5449,7 +5856,7 @@ #endif DUK_INTERNAL_DECL void duk_heaphdr_refcount_finalize_norz(duk_heap *heap, duk_heaphdr *hdr); DUK_INTERNAL_DECL void duk_hobject_refcount_finalize_norz(duk_heap *heap, duk_hobject *h); -#if 0 /* Not needed: fast path handles inline; slow path uses duk_heaphdr_decref() which is needed anyway. */ +#if 0 /* Not needed: fast path handles inline; slow path uses duk_heaphdr_decref() which is needed anyway. */ DUK_INTERNAL_DECL void duk_hstring_decref(duk_hthread *thr, duk_hstring *h); DUK_INTERNAL_DECL void duk_hstring_decref_norz(duk_hthread *thr, duk_hstring *h); DUK_INTERNAL_DECL void duk_hbuffer_decref(duk_hthread *thr, duk_hbuffer *h); @@ -5460,8 +5867,8 @@ DUK_INTERNAL_DECL void duk_heaphdr_refzero(duk_hthread *thr, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_refzero_norz(duk_hthread *thr, duk_heaphdr *h); #if defined(DUK_USE_FAST_REFCOUNT_DEFAULT) -DUK_INTERNAL_DECL void duk_hstring_refzero(duk_hthread *thr, duk_hstring *h); /* no 'norz' variant */ -DUK_INTERNAL_DECL void duk_hbuffer_refzero(duk_hthread *thr, duk_hbuffer *h); /* no 'norz' variant */ +DUK_INTERNAL_DECL void duk_hstring_refzero(duk_hthread *thr, duk_hstring *h); /* no 'norz' variant */ +DUK_INTERNAL_DECL void duk_hbuffer_refzero(duk_hthread *thr, duk_hbuffer *h); /* no 'norz' variant */ DUK_INTERNAL_DECL void duk_hobject_refzero(duk_hthread *thr, duk_hobject *h); DUK_INTERNAL_DECL void duk_hobject_refzero_norz(duk_hthread *thr, duk_hobject *h); #else @@ -5472,11 +5879,11 @@ DUK_INTERNAL_DECL void duk_heaphdr_decref(duk_hthread *thr, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_decref_norz(duk_hthread *thr, duk_heaphdr *h); #endif -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ /* no refcounting */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ -#endif /* DUK_REFCOUNT_H_INCLUDED */ +#endif /* DUK_REFCOUNT_H_INCLUDED */ /* #include duk_api_internal.h */ /* * Internal API calls which have (stack and other) semantics similar @@ -5492,9 +5899,9 @@ #define DUK_ALWAYS_INLINE_PERF #define DUK_NOINLINE_PERF #else -#define DUK_INLINE_PERF DUK_INLINE +#define DUK_INLINE_PERF DUK_INLINE #define DUK_ALWAYS_INLINE_PERF DUK_ALWAYS_INLINE -#define DUK_NOINLINE_PERF DUK_NOINLINE +#define DUK_NOINLINE_PERF DUK_NOINLINE #endif /* Inline macro helpers, for bytecode executor. */ @@ -5503,19 +5910,19 @@ #define DUK_EXEC_ALWAYS_INLINE_PERF #define DUK_EXEC_NOINLINE_PERF #else -#define DUK_EXEC_INLINE_PERF DUK_INLINE +#define DUK_EXEC_INLINE_PERF DUK_INLINE #define DUK_EXEC_ALWAYS_INLINE_PERF DUK_ALWAYS_INLINE -#define DUK_EXEC_NOINLINE_PERF DUK_NOINLINE +#define DUK_EXEC_NOINLINE_PERF DUK_NOINLINE #endif /* duk_push_sprintf constants */ -#define DUK_PUSH_SPRINTF_INITIAL_SIZE 256L -#define DUK_PUSH_SPRINTF_SANITY_LIMIT (1L * 1024L * 1024L * 1024L) +#define DUK_PUSH_SPRINTF_INITIAL_SIZE 256L +#define DUK_PUSH_SPRINTF_SANITY_LIMIT (1L * 1024L * 1024L * 1024L) /* Flag ORed to err_code to indicate __FILE__ / __LINE__ is not * blamed as source of error for error fileName / lineNumber. */ -#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE (1L << 24) +#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE (1L << 24) /* Current convention is to use duk_size_t for value stack sizes and global indices, * and duk_idx_t for local frame indices. @@ -5577,24 +5984,17 @@ DUK_INTERNAL_DECL duk_tval *duk_get_borrowed_this_tval(duk_hthread *thr); /* XXX: add fastint support? */ -#define duk_push_u64(thr,val) \ - duk_push_number((thr), (duk_double_t) (val)) -#define duk_push_i64(thr,val) \ - duk_push_number((thr), (duk_double_t) (val)) +#define duk_push_u64(thr, val) duk_push_number((thr), (duk_double_t) (val)) +#define duk_push_i64(thr, val) duk_push_number((thr), (duk_double_t) (val)) /* duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range */ -#define duk_push_u32(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) -#define duk_push_i32(thr,val) \ - duk_push_int((thr), (duk_int_t) (val)) +#define duk_push_u32(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) +#define duk_push_i32(thr, val) duk_push_int((thr), (duk_int_t) (val)) /* sometimes stack and array indices need to go on the stack */ -#define duk_push_idx(thr,val) \ - duk_push_int((thr), (duk_int_t) (val)) -#define duk_push_uarridx(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) -#define duk_push_size_t(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) /* XXX: assumed to fit for now */ +#define duk_push_idx(thr, val) duk_push_int((thr), (duk_int_t) (val)) +#define duk_push_uarridx(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) +#define duk_push_size_t(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) /* XXX: assumed to fit for now */ DUK_INTERNAL_DECL duk_bool_t duk_is_string_notsymbol(duk_hthread *thr, duk_idx_t idx); @@ -5611,19 +6011,23 @@ DUK_INTERNAL_DECL duk_hcompfunc *duk_get_hcompfunc(duk_hthread *thr, duk_idx_t idx); DUK_INTERNAL_DECL duk_hnatfunc *duk_get_hnatfunc(duk_hthread *thr, duk_idx_t idx); -DUK_INTERNAL_DECL void *duk_get_buffer_data_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len, duk_bool_t throw_flag, duk_bool_t *out_isbuffer); +DUK_INTERNAL_DECL void *duk_get_buffer_data_raw(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_len, + duk_bool_t throw_flag, + duk_bool_t *out_isbuffer); DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_with_class(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t classnum); DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_accept_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); -#define duk_require_hobject_promote_lfunc(thr,idx) \ - duk_require_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) -#define duk_get_hobject_promote_lfunc(thr,idx) \ - duk_get_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) +#define duk_require_hobject_promote_lfunc(thr, idx) duk_require_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) +#define duk_get_hobject_promote_lfunc(thr, idx) duk_get_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL void *duk_get_voidptr(duk_hthread *thr, duk_idx_t idx); #endif @@ -5646,12 +6050,16 @@ DUK_INTERNAL_DECL duk_bool_t duk_to_boolean_top_pop(duk_hthread *thr); -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ DUK_INTERNAL_DECL duk_hstring *duk_safe_to_hstring(duk_hthread *thr, duk_idx_t idx); #endif DUK_INTERNAL_DECL void duk_push_class_string_tval(duk_hthread *thr, duk_tval *tv, duk_bool_t avoid_side_effects); -DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped); /* out_clamped=NULL, RangeError if outside range */ +DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, + duk_idx_t idx, + duk_int_t minval, + duk_int_t maxval, + duk_bool_t *out_clamped); /* out_clamped=NULL, RangeError if outside range */ DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval); DUK_INTERNAL_DECL duk_int_t duk_to_int_check_range(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -5676,13 +6084,15 @@ DUK_INTERNAL_DECL void duk_push_hstring_empty(duk_hthread *thr); DUK_INTERNAL_DECL void duk_push_hobject(duk_hthread *thr, duk_hobject *h); DUK_INTERNAL_DECL void duk_push_hbuffer(duk_hthread *thr, duk_hbuffer *h); -#define duk_push_hthread(thr,h) \ - duk_push_hobject((thr), (duk_hobject *) (h)) -#define duk_push_hnatfunc(thr,h) \ - duk_push_hobject((thr), (duk_hobject *) (h)) +#define duk_push_hthread(thr, h) duk_push_hobject((thr), (duk_hobject *) (h)) +#define duk_push_hnatfunc(thr, h) duk_push_hobject((thr), (duk_hobject *) (h)) DUK_INTERNAL_DECL void duk_push_hobject_bidx(duk_hthread *thr, duk_small_int_t builtin_idx); -DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx); -DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper_proto(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_hobject *proto); +DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx); +DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper_proto(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_hobject *proto); DUK_INTERNAL_DECL duk_hcompfunc *duk_push_hcompfunc(duk_hthread *thr); DUK_INTERNAL_DECL duk_hboundfunc *duk_push_hboundfunc(duk_hthread *thr); DUK_INTERNAL_DECL void duk_push_c_function_builtin(duk_hthread *thr, duk_c_function func, duk_int_t nargs); @@ -5699,11 +6109,13 @@ DUK_INTERNAL_DECL void duk_push_lightfunc_name_raw(duk_hthread *thr, duk_c_function func, duk_small_uint_t lf_flags); DUK_INTERNAL_DECL void duk_push_lightfunc_name(duk_hthread *thr, duk_tval *tv); DUK_INTERNAL_DECL void duk_push_lightfunc_tostring(duk_hthread *thr, duk_tval *tv); -#if 0 /* not used yet */ +#if 0 /* not used yet */ DUK_INTERNAL_DECL void duk_push_hnatfunc_name(duk_hthread *thr, duk_hnatfunc *h); #endif #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_INTERNAL_DECL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx); +DUK_INTERNAL_DECL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx); #endif DUK_INTERNAL_DECL void *duk_push_fixed_buffer_nozero(duk_hthread *thr, duk_size_t len); @@ -5720,80 +6132,86 @@ * arguments and such call sites are also easiest to verify to be correct. */ -DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> val */ +DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> val */ DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_get_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_get_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_get_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop); /* -> */ +DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_bool_t *out_has_prop); /* -> */ DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop(duk_hthread *thr, duk_idx_t obj_idx); DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_xget_owndataprop_stridx_short(thr,obj_idx,stridx) \ +#define duk_xget_owndataprop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_xget_owndataprop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* val -> */ +DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* val -> */ DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_put_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_put_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_put_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ -#if 0 /* Too few call sites to be useful. */ +DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +#if 0 /* Too few call sites to be useful. */ DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_del_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_del_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((obj_idx) >= -0x8000L && (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((stridx) >= 0 && (stridx) <= 0xffffL), \ duk_del_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) #endif -#define duk_del_prop_stridx_short(thr,obj_idx,stridx) \ - duk_del_prop_stridx((thr), (obj_idx), (stridx)) +#define duk_del_prop_stridx_short(thr, obj_idx, stridx) duk_del_prop_stridx((thr), (obj_idx), (stridx)) -DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ -#if 0 /* Too few call sites to be useful. */ +DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +#if 0 /* Too few call sites to be useful. */ DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_has_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_has_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((obj_idx) >= -0x8000L && (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((stridx) >= 0 && (stridx) <= 0xffffL), \ duk_has_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) #endif -#define duk_has_prop_stridx_short(thr,obj_idx,stridx) \ - duk_has_prop_stridx((thr), (obj_idx), (stridx)) +#define duk_has_prop_stridx_short(thr, obj_idx, stridx) duk_has_prop_stridx((thr), (obj_idx), (stridx)) -DUK_INTERNAL_DECL void duk_xdef_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t desc_flags); /* key val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t desc_flags); /* key val -> */ -DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags); /* val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_hthread *thr, + duk_idx_t obj_idx, + duk_uarridx_t arr_idx, + duk_small_uint_t desc_flags); /* val -> */ /* XXX: Because stridx and desc_flags have a limited range, this call could * always pack stridx and desc_flags into a single argument. */ -DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_uint_t desc_flags); /* val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_small_uint_t desc_flags); /* val -> */ DUK_INTERNAL_DECL void duk_xdef_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_xdef_prop_stridx_short(thr,obj_idx,stridx,desc_flags) \ +#define duk_xdef_prop_stridx_short(thr, obj_idx, stridx, desc_flags) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x80L && (duk_int_t) (obj_idx) <= 0x7fL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ DUK_ASSERT_EXPR((duk_int_t) (desc_flags) >= 0 && (duk_int_t) (desc_flags) <= 0xffL), \ - duk_xdef_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 24) + (((duk_uint_t) (stridx)) << 8) + (duk_uint_t) (desc_flags))) - -#define duk_xdef_prop_wec(thr,obj_idx) \ - duk_xdef_prop((thr), (obj_idx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_index_wec(thr,obj_idx,arr_idx) \ - duk_xdef_prop_index((thr), (obj_idx), (arr_idx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_stridx_wec(thr,obj_idx,stridx) \ - duk_xdef_prop_stridx((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_stridx_short_wec(thr,obj_idx,stridx) \ + duk_xdef_prop_stridx_short_raw((thr), \ + (((duk_uint_t) (obj_idx)) << 24) + (((duk_uint_t) (stridx)) << 8) + \ + (duk_uint_t) (desc_flags))) + +#define duk_xdef_prop_wec(thr, obj_idx) duk_xdef_prop((thr), (obj_idx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_index_wec(thr, obj_idx, arr_idx) duk_xdef_prop_index((thr), (obj_idx), (arr_idx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_stridx_wec(thr, obj_idx, stridx) duk_xdef_prop_stridx((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_stridx_short_wec(thr, obj_idx, stridx) \ duk_xdef_prop_stridx_short((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL void duk_xdef_prop_stridx_builtin(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags); /* -> */ #endif -DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ DUK_INTERNAL_DECL duk_bool_t duk_get_method_stridx(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t stridx); @@ -5842,28 +6260,24 @@ * using these macro results in faster and smaller code than duk_get_tval(). * Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts. */ -#define DUK_ASSERT_VALID_NEGIDX(thr,idx) \ +#define DUK_ASSERT_VALID_NEGIDX(thr, idx) \ (DUK_ASSERT_EXPR((duk_int_t) (idx) < 0), DUK_ASSERT_EXPR(duk_is_valid_index((thr), (idx)))) -#define DUK_ASSERT_VALID_POSIDX(thr,idx) \ +#define DUK_ASSERT_VALID_POSIDX(thr, idx) \ (DUK_ASSERT_EXPR((duk_int_t) (idx) >= 0), DUK_ASSERT_EXPR(duk_is_valid_index((thr), (idx)))) -#define DUK_GET_TVAL_NEGIDX(thr,idx) \ - (DUK_ASSERT_VALID_NEGIDX((thr),(idx)), ((duk_hthread *) (thr))->valstack_top + (idx)) -#define DUK_GET_TVAL_POSIDX(thr,idx) \ - (DUK_ASSERT_VALID_POSIDX((thr),(idx)), ((duk_hthread *) (thr))->valstack_bottom + (idx)) -#define DUK_GET_HOBJECT_NEGIDX(thr,idx) \ - (DUK_ASSERT_VALID_NEGIDX((thr),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_top + (idx))) -#define DUK_GET_HOBJECT_POSIDX(thr,idx) \ - (DUK_ASSERT_VALID_POSIDX((thr),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_bottom + (idx))) - -#define DUK_GET_THIS_TVAL_PTR(thr) \ - (DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), \ - (thr)->valstack_bottom - 1) +#define DUK_GET_TVAL_NEGIDX(thr, idx) (DUK_ASSERT_VALID_NEGIDX((thr), (idx)), ((duk_hthread *) (thr))->valstack_top + (idx)) +#define DUK_GET_TVAL_POSIDX(thr, idx) (DUK_ASSERT_VALID_POSIDX((thr), (idx)), ((duk_hthread *) (thr))->valstack_bottom + (idx)) +#define DUK_GET_HOBJECT_NEGIDX(thr, idx) \ + (DUK_ASSERT_VALID_NEGIDX((thr), (idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_top + (idx))) +#define DUK_GET_HOBJECT_POSIDX(thr, idx) \ + (DUK_ASSERT_VALID_POSIDX((thr), (idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_bottom + (idx))) + +#define DUK_GET_THIS_TVAL_PTR(thr) (DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), (thr)->valstack_bottom - 1) DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time(duk_hthread *thr); DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time_nofrac(duk_hthread *thr); DUK_INTERNAL_DECL duk_double_t duk_time_get_monotonic_time(duk_hthread *thr); -#endif /* DUK_API_INTERNAL_H_INCLUDED */ +#endif /* DUK_API_INTERNAL_H_INCLUDED */ /* #include duk_hstring.h */ /* * Heap string representation. @@ -5894,9 +6308,9 @@ */ #if defined(DUK_USE_STRLEN16) -#define DUK_HSTRING_MAX_BYTELEN (0x0000ffffUL) +#define DUK_HSTRING_MAX_BYTELEN (0x0000ffffUL) #else -#define DUK_HSTRING_MAX_BYTELEN (0x7fffffffUL) +#define DUK_HSTRING_MAX_BYTELEN (0x7fffffffUL) #endif /* XXX: could add flags for "is valid CESU-8" (ECMAScript compatible strings), @@ -5908,139 +6322,148 @@ /* With lowmem builds the high 16 bits of duk_heaphdr are used for other * purposes, so this leaves 7 duk_heaphdr flags and 9 duk_hstring flags. */ -#define DUK_HSTRING_FLAG_ASCII DUK_HEAPHDR_USER_FLAG(0) /* string is ASCII, clen == blen */ -#define DUK_HSTRING_FLAG_ARRIDX DUK_HEAPHDR_USER_FLAG(1) /* string is a valid array index */ -#define DUK_HSTRING_FLAG_SYMBOL DUK_HEAPHDR_USER_FLAG(2) /* string is a symbol (invalid utf-8) */ -#define DUK_HSTRING_FLAG_HIDDEN DUK_HEAPHDR_USER_FLAG(3) /* string is a hidden symbol (implies symbol, Duktape 1.x internal string) */ -#define DUK_HSTRING_FLAG_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(4) /* string is a reserved word (non-strict) */ -#define DUK_HSTRING_FLAG_STRICT_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(5) /* string is a reserved word (strict) */ -#define DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS DUK_HEAPHDR_USER_FLAG(6) /* string is 'eval' or 'arguments' */ -#define DUK_HSTRING_FLAG_EXTDATA DUK_HEAPHDR_USER_FLAG(7) /* string data is external (duk_hstring_external) */ -#define DUK_HSTRING_FLAG_PINNED_LITERAL DUK_HEAPHDR_USER_FLAG(8) /* string is a literal, and pinned */ - -#define DUK_HSTRING_HAS_ASCII(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_HAS_ARRIDX(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_HAS_SYMBOL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_HAS_HIDDEN(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_HAS_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_HAS_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_HAS_EXTDATA(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_HAS_PINNED_LITERAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#define DUK_HSTRING_SET_ASCII(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_SET_ARRIDX(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_SET_SYMBOL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_SET_HIDDEN(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_SET_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_SET_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_SET_EXTDATA(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_SET_PINNED_LITERAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#define DUK_HSTRING_CLEAR_ASCII(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_CLEAR_ARRIDX(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_CLEAR_SYMBOL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_CLEAR_HIDDEN(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_CLEAR_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_CLEAR_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_CLEAR_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_CLEAR_EXTDATA(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_CLEAR_PINNED_LITERAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#if 0 /* Slightly smaller code without explicit flag, but explicit flag - * is very useful when 'clen' is dropped. - */ -#define DUK_HSTRING_IS_ASCII(x) (DUK_HSTRING_GET_BYTELEN((x)) == DUK_HSTRING_GET_CHARLEN((x))) +#define DUK_HSTRING_FLAG_ASCII DUK_HEAPHDR_USER_FLAG(0) /* string is ASCII, clen == blen */ +#define DUK_HSTRING_FLAG_ARRIDX DUK_HEAPHDR_USER_FLAG(1) /* string is a valid array index */ +#define DUK_HSTRING_FLAG_SYMBOL DUK_HEAPHDR_USER_FLAG(2) /* string is a symbol (invalid utf-8) */ +#define DUK_HSTRING_FLAG_HIDDEN \ + DUK_HEAPHDR_USER_FLAG(3) /* string is a hidden symbol (implies symbol, Duktape 1.x internal string) */ +#define DUK_HSTRING_FLAG_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(4) /* string is a reserved word (non-strict) */ +#define DUK_HSTRING_FLAG_STRICT_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(5) /* string is a reserved word (strict) */ +#define DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS DUK_HEAPHDR_USER_FLAG(6) /* string is 'eval' or 'arguments' */ +#define DUK_HSTRING_FLAG_EXTDATA DUK_HEAPHDR_USER_FLAG(7) /* string data is external (duk_hstring_external) */ +#define DUK_HSTRING_FLAG_PINNED_LITERAL DUK_HEAPHDR_USER_FLAG(8) /* string is a literal, and pinned */ + +#define DUK_HSTRING_HAS_ASCII(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_HAS_ARRIDX(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_HAS_SYMBOL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_HAS_HIDDEN(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_HAS_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_HAS_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_HAS_EXTDATA(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_HAS_PINNED_LITERAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#define DUK_HSTRING_SET_ASCII(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_SET_ARRIDX(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_SET_SYMBOL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_SET_HIDDEN(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_SET_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_SET_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_SET_EXTDATA(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_SET_PINNED_LITERAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#define DUK_HSTRING_CLEAR_ASCII(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_CLEAR_ARRIDX(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_CLEAR_SYMBOL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_CLEAR_HIDDEN(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_CLEAR_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_CLEAR_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_CLEAR_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_CLEAR_EXTDATA(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_CLEAR_PINNED_LITERAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#if 0 /* Slightly smaller code without explicit flag, but explicit flag \ + * is very useful when 'clen' is dropped. \ + */ +#define DUK_HSTRING_IS_ASCII(x) (DUK_HSTRING_GET_BYTELEN((x)) == DUK_HSTRING_GET_CHARLEN((x))) #endif -#define DUK_HSTRING_IS_ASCII(x) DUK_HSTRING_HAS_ASCII((x)) /* lazily set! */ -#define DUK_HSTRING_IS_EMPTY(x) (DUK_HSTRING_GET_BYTELEN((x)) == 0) +#define DUK_HSTRING_IS_ASCII(x) DUK_HSTRING_HAS_ASCII((x)) /* lazily set! */ +#define DUK_HSTRING_IS_EMPTY(x) (DUK_HSTRING_GET_BYTELEN((x)) == 0) #if defined(DUK_USE_STRHASH16) -#define DUK_HSTRING_GET_HASH(x) ((x)->hdr.h_flags >> 16) -#define DUK_HSTRING_SET_HASH(x,v) do { \ +#define DUK_HSTRING_GET_HASH(x) ((x)->hdr.h_flags >> 16) +#define DUK_HSTRING_SET_HASH(x, v) \ + do { \ (x)->hdr.h_flags = ((x)->hdr.h_flags & 0x0000ffffUL) | ((v) << 16); \ } while (0) #else -#define DUK_HSTRING_GET_HASH(x) ((x)->hash) -#define DUK_HSTRING_SET_HASH(x,v) do { \ +#define DUK_HSTRING_GET_HASH(x) ((x)->hash) +#define DUK_HSTRING_SET_HASH(x, v) \ + do { \ (x)->hash = (v); \ } while (0) #endif #if defined(DUK_USE_STRLEN16) -#define DUK_HSTRING_GET_BYTELEN(x) ((x)->hdr.h_strextra16) -#define DUK_HSTRING_SET_BYTELEN(x,v) do { \ +#define DUK_HSTRING_GET_BYTELEN(x) ((x)->hdr.h_strextra16) +#define DUK_HSTRING_SET_BYTELEN(x, v) \ + do { \ (x)->hdr.h_strextra16 = (v); \ } while (0) #if defined(DUK_USE_HSTRING_CLEN) -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ (x)->clen16 = (v); \ } while (0) #else -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ - DUK_ASSERT(0); /* should never be called */ \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ + DUK_ASSERT(0); /* should never be called */ \ } while (0) #endif #else -#define DUK_HSTRING_GET_BYTELEN(x) ((x)->blen) -#define DUK_HSTRING_SET_BYTELEN(x,v) do { \ +#define DUK_HSTRING_GET_BYTELEN(x) ((x)->blen) +#define DUK_HSTRING_SET_BYTELEN(x, v) \ + do { \ (x)->blen = (v); \ } while (0) -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ (x)->clen = (v); \ } while (0) #endif #if defined(DUK_USE_HSTRING_EXTDATA) -#define DUK_HSTRING_GET_EXTDATA(x) \ - ((x)->extdata) +#define DUK_HSTRING_GET_EXTDATA(x) ((x)->extdata) #define DUK_HSTRING_GET_DATA(x) \ - (DUK_HSTRING_HAS_EXTDATA((x)) ? \ - DUK_HSTRING_GET_EXTDATA((const duk_hstring_external *) (x)) : ((const duk_uint8_t *) ((x) + 1))) + (DUK_HSTRING_HAS_EXTDATA((x)) ? DUK_HSTRING_GET_EXTDATA((const duk_hstring_external *) (x)) : \ + ((const duk_uint8_t *) ((x) + 1))) #else -#define DUK_HSTRING_GET_DATA(x) \ - ((const duk_uint8_t *) ((x) + 1)) +#define DUK_HSTRING_GET_DATA(x) ((const duk_uint8_t *) ((x) + 1)) #endif -#define DUK_HSTRING_GET_DATA_END(x) \ - (DUK_HSTRING_GET_DATA((x)) + (x)->blen) +#define DUK_HSTRING_GET_DATA_END(x) (DUK_HSTRING_GET_DATA((x)) + (x)->blen) /* Marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest * valid). */ -#define DUK_HSTRING_NO_ARRAY_INDEX (0xffffffffUL) +#define DUK_HSTRING_NO_ARRAY_INDEX (0xffffffffUL) #if defined(DUK_USE_HSTRING_ARRIDX) -#define DUK_HSTRING_GET_ARRIDX_FAST(h) ((h)->arridx) -#define DUK_HSTRING_GET_ARRIDX_SLOW(h) ((h)->arridx) +#define DUK_HSTRING_GET_ARRIDX_FAST(h) ((h)->arridx) +#define DUK_HSTRING_GET_ARRIDX_SLOW(h) ((h)->arridx) #else /* Get array index related to string (or return DUK_HSTRING_NO_ARRAY_INDEX); * avoids helper call if string has no array index value. */ -#define DUK_HSTRING_GET_ARRIDX_FAST(h) \ +#define DUK_HSTRING_GET_ARRIDX_FAST(h) \ (DUK_HSTRING_HAS_ARRIDX((h)) ? duk_js_to_arrayindex_hstring_fast_known((h)) : DUK_HSTRING_NO_ARRAY_INDEX) /* Slower but more compact variant. */ -#define DUK_HSTRING_GET_ARRIDX_SLOW(h) \ - (duk_js_to_arrayindex_hstring_fast((h))) +#define DUK_HSTRING_GET_ARRIDX_SLOW(h) (duk_js_to_arrayindex_hstring_fast((h))) #endif /* XXX: these actually fit into duk_hstring */ -#define DUK_SYMBOL_TYPE_HIDDEN 0 -#define DUK_SYMBOL_TYPE_GLOBAL 1 -#define DUK_SYMBOL_TYPE_LOCAL 2 +#define DUK_SYMBOL_TYPE_HIDDEN 0 +#define DUK_SYMBOL_TYPE_GLOBAL 1 +#define DUK_SYMBOL_TYPE_LOCAL 2 #define DUK_SYMBOL_TYPE_WELLKNOWN 3 /* Assertion for duk_hstring validity. */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hstring_assert_valid(duk_hstring *h); -#define DUK_HSTRING_ASSERT_VALID(h) do { duk_hstring_assert_valid((h)); } while (0) +#define DUK_HSTRING_ASSERT_VALID(h) \ + do { \ + duk_hstring_assert_valid((h)); \ + } while (0) #else -#define DUK_HSTRING_ASSERT_VALID(h) do {} while (0) +#define DUK_HSTRING_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -6110,14 +6533,17 @@ * Prototypes */ -DUK_INTERNAL_DECL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, duk_hstring *h, duk_uint_t pos, duk_bool_t surrogate_aware); +DUK_INTERNAL_DECL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, + duk_hstring *h, + duk_uint_t pos, + duk_bool_t surrogate_aware); DUK_INTERNAL_DECL duk_bool_t duk_hstring_equals_ascii_cstring(duk_hstring *h, const char *cstr); DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h); #if !defined(DUK_USE_HSTRING_LAZY_CLEN) DUK_INTERNAL_DECL void duk_hstring_init_charlen(duk_hstring *h); #endif -#endif /* DUK_HSTRING_H_INCLUDED */ +#endif /* DUK_HSTRING_H_INCLUDED */ /* #include duk_hobject.h */ /* * Heap object representation. @@ -6160,36 +6586,40 @@ /* XXX: some flags are object subtype specific (e.g. common to all function * subtypes, duk_harray, etc) and could be reused for different subtypes. */ -#define DUK_HOBJECT_FLAG_EXTENSIBLE DUK_HEAPHDR_USER_FLAG(0) /* object is extensible */ -#define DUK_HOBJECT_FLAG_CONSTRUCTABLE DUK_HEAPHDR_USER_FLAG(1) /* object is constructable */ -#define DUK_HOBJECT_FLAG_CALLABLE DUK_HEAPHDR_USER_FLAG(2) /* object is callable */ -#define DUK_HOBJECT_FLAG_BOUNDFUNC DUK_HEAPHDR_USER_FLAG(3) /* object established using Function.prototype.bind() */ -#define DUK_HOBJECT_FLAG_COMPFUNC DUK_HEAPHDR_USER_FLAG(4) /* object is a compiled function (duk_hcompfunc) */ -#define DUK_HOBJECT_FLAG_NATFUNC DUK_HEAPHDR_USER_FLAG(5) /* object is a native function (duk_hnatfunc) */ -#define DUK_HOBJECT_FLAG_BUFOBJ DUK_HEAPHDR_USER_FLAG(6) /* object is a buffer object (duk_hbufobj) (always exotic) */ -#define DUK_HOBJECT_FLAG_FASTREFS DUK_HEAPHDR_USER_FLAG(7) /* object has no fields needing DECREF/marking beyond base duk_hobject header */ -#define DUK_HOBJECT_FLAG_ARRAY_PART DUK_HEAPHDR_USER_FLAG(8) /* object has an array part (a_size may still be 0) */ -#define DUK_HOBJECT_FLAG_STRICT DUK_HEAPHDR_USER_FLAG(9) /* function: function object is strict */ -#define DUK_HOBJECT_FLAG_NOTAIL DUK_HEAPHDR_USER_FLAG(10) /* function: function must not be tail called */ -#define DUK_HOBJECT_FLAG_NEWENV DUK_HEAPHDR_USER_FLAG(11) /* function: create new environment when called (see duk_hcompfunc) */ -#define DUK_HOBJECT_FLAG_NAMEBINDING DUK_HEAPHDR_USER_FLAG(12) /* function: create binding for func name (function templates only, used for named function expressions) */ -#define DUK_HOBJECT_FLAG_CREATEARGS DUK_HEAPHDR_USER_FLAG(13) /* function: create an arguments object on function call */ -#define DUK_HOBJECT_FLAG_HAVE_FINALIZER DUK_HEAPHDR_USER_FLAG(14) /* object has a callable (own) finalizer property */ -#define DUK_HOBJECT_FLAG_EXOTIC_ARRAY DUK_HEAPHDR_USER_FLAG(15) /* 'Array' object, array length and index exotic behavior */ -#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ DUK_HEAPHDR_USER_FLAG(16) /* 'String' object, array index exotic behavior */ -#define DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS DUK_HEAPHDR_USER_FLAG(17) /* 'Arguments' object and has arguments exotic behavior (non-strict callee) */ -#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(18) /* 'Proxy' object */ -#define DUK_HOBJECT_FLAG_SPECIAL_CALL DUK_HEAPHDR_USER_FLAG(19) /* special casing in call behavior, for .call(), .apply(), etc. */ +#define DUK_HOBJECT_FLAG_EXTENSIBLE DUK_HEAPHDR_USER_FLAG(0) /* object is extensible */ +#define DUK_HOBJECT_FLAG_CONSTRUCTABLE DUK_HEAPHDR_USER_FLAG(1) /* object is constructable */ +#define DUK_HOBJECT_FLAG_CALLABLE DUK_HEAPHDR_USER_FLAG(2) /* object is callable */ +#define DUK_HOBJECT_FLAG_BOUNDFUNC DUK_HEAPHDR_USER_FLAG(3) /* object established using Function.prototype.bind() */ +#define DUK_HOBJECT_FLAG_COMPFUNC DUK_HEAPHDR_USER_FLAG(4) /* object is a compiled function (duk_hcompfunc) */ +#define DUK_HOBJECT_FLAG_NATFUNC DUK_HEAPHDR_USER_FLAG(5) /* object is a native function (duk_hnatfunc) */ +#define DUK_HOBJECT_FLAG_BUFOBJ DUK_HEAPHDR_USER_FLAG(6) /* object is a buffer object (duk_hbufobj) (always exotic) */ +#define DUK_HOBJECT_FLAG_FASTREFS \ + DUK_HEAPHDR_USER_FLAG(7) /* object has no fields needing DECREF/marking beyond base duk_hobject header */ +#define DUK_HOBJECT_FLAG_ARRAY_PART DUK_HEAPHDR_USER_FLAG(8) /* object has an array part (a_size may still be 0) */ +#define DUK_HOBJECT_FLAG_STRICT DUK_HEAPHDR_USER_FLAG(9) /* function: function object is strict */ +#define DUK_HOBJECT_FLAG_NOTAIL DUK_HEAPHDR_USER_FLAG(10) /* function: function must not be tail called */ +#define DUK_HOBJECT_FLAG_NEWENV DUK_HEAPHDR_USER_FLAG(11) /* function: create new environment when called (see duk_hcompfunc) */ +#define DUK_HOBJECT_FLAG_NAMEBINDING \ + DUK_HEAPHDR_USER_FLAG( \ + 12) /* function: create binding for func name (function templates only, used for named function expressions) */ +#define DUK_HOBJECT_FLAG_CREATEARGS DUK_HEAPHDR_USER_FLAG(13) /* function: create an arguments object on function call */ +#define DUK_HOBJECT_FLAG_HAVE_FINALIZER DUK_HEAPHDR_USER_FLAG(14) /* object has a callable (own) finalizer property */ +#define DUK_HOBJECT_FLAG_EXOTIC_ARRAY DUK_HEAPHDR_USER_FLAG(15) /* 'Array' object, array length and index exotic behavior */ +#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ DUK_HEAPHDR_USER_FLAG(16) /* 'String' object, array index exotic behavior */ +#define DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS \ + DUK_HEAPHDR_USER_FLAG(17) /* 'Arguments' object and has arguments exotic behavior (non-strict callee) */ +#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(18) /* 'Proxy' object */ +#define DUK_HOBJECT_FLAG_SPECIAL_CALL DUK_HEAPHDR_USER_FLAG(19) /* special casing in call behavior, for .call(), .apply(), etc. */ -#define DUK_HOBJECT_FLAG_CLASS_BASE DUK_HEAPHDR_USER_FLAG_NUMBER(20) -#define DUK_HOBJECT_FLAG_CLASS_BITS 5 +#define DUK_HOBJECT_FLAG_CLASS_BASE DUK_HEAPHDR_USER_FLAG_NUMBER(20) +#define DUK_HOBJECT_FLAG_CLASS_BITS 5 -#define DUK_HOBJECT_GET_CLASS_NUMBER(h) \ +#define DUK_HOBJECT_GET_CLASS_NUMBER(h) \ DUK_HEAPHDR_GET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS) -#define DUK_HOBJECT_SET_CLASS_NUMBER(h,v) \ +#define DUK_HOBJECT_SET_CLASS_NUMBER(h, v) \ DUK_HEAPHDR_SET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS, (v)) -#define DUK_HOBJECT_GET_CLASS_MASK(h) \ +#define DUK_HOBJECT_GET_CLASS_MASK(h) \ (1UL << DUK_HEAPHDR_GET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS)) /* Macro for creating flag initializer from a class number. @@ -6197,256 +6627,239 @@ * a signed integer to an unsigned one; the largest class values * have the highest bit (bit 31) set which causes this. */ -#define DUK_HOBJECT_CLASS_AS_FLAGS(v) (((duk_uint_t) (v)) << DUK_HOBJECT_FLAG_CLASS_BASE) +#define DUK_HOBJECT_CLASS_AS_FLAGS(v) (((duk_uint_t) (v)) << DUK_HOBJECT_FLAG_CLASS_BASE) /* E5 Section 8.6.2 + custom classes */ -#define DUK_HOBJECT_CLASS_NONE 0 -#define DUK_HOBJECT_CLASS_OBJECT 1 -#define DUK_HOBJECT_CLASS_ARRAY 2 -#define DUK_HOBJECT_CLASS_FUNCTION 3 -#define DUK_HOBJECT_CLASS_ARGUMENTS 4 -#define DUK_HOBJECT_CLASS_BOOLEAN 5 -#define DUK_HOBJECT_CLASS_DATE 6 -#define DUK_HOBJECT_CLASS_ERROR 7 -#define DUK_HOBJECT_CLASS_JSON 8 -#define DUK_HOBJECT_CLASS_MATH 9 -#define DUK_HOBJECT_CLASS_NUMBER 10 -#define DUK_HOBJECT_CLASS_REGEXP 11 -#define DUK_HOBJECT_CLASS_STRING 12 -#define DUK_HOBJECT_CLASS_GLOBAL 13 -#define DUK_HOBJECT_CLASS_SYMBOL 14 -#define DUK_HOBJECT_CLASS_OBJENV 15 /* custom */ -#define DUK_HOBJECT_CLASS_DECENV 16 /* custom */ -#define DUK_HOBJECT_CLASS_POINTER 17 /* custom */ -#define DUK_HOBJECT_CLASS_THREAD 18 /* custom; implies DUK_HOBJECT_IS_THREAD */ -#define DUK_HOBJECT_CLASS_BUFOBJ_MIN 19 -#define DUK_HOBJECT_CLASS_ARRAYBUFFER 19 /* implies DUK_HOBJECT_IS_BUFOBJ */ -#define DUK_HOBJECT_CLASS_DATAVIEW 20 -#define DUK_HOBJECT_CLASS_INT8ARRAY 21 -#define DUK_HOBJECT_CLASS_UINT8ARRAY 22 -#define DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY 23 -#define DUK_HOBJECT_CLASS_INT16ARRAY 24 -#define DUK_HOBJECT_CLASS_UINT16ARRAY 25 -#define DUK_HOBJECT_CLASS_INT32ARRAY 26 -#define DUK_HOBJECT_CLASS_UINT32ARRAY 27 -#define DUK_HOBJECT_CLASS_FLOAT32ARRAY 28 -#define DUK_HOBJECT_CLASS_FLOAT64ARRAY 29 -#define DUK_HOBJECT_CLASS_BUFOBJ_MAX 29 -#define DUK_HOBJECT_CLASS_MAX 29 +#define DUK_HOBJECT_CLASS_NONE 0 +#define DUK_HOBJECT_CLASS_OBJECT 1 +#define DUK_HOBJECT_CLASS_ARRAY 2 +#define DUK_HOBJECT_CLASS_FUNCTION 3 +#define DUK_HOBJECT_CLASS_ARGUMENTS 4 +#define DUK_HOBJECT_CLASS_BOOLEAN 5 +#define DUK_HOBJECT_CLASS_DATE 6 +#define DUK_HOBJECT_CLASS_ERROR 7 +#define DUK_HOBJECT_CLASS_JSON 8 +#define DUK_HOBJECT_CLASS_MATH 9 +#define DUK_HOBJECT_CLASS_NUMBER 10 +#define DUK_HOBJECT_CLASS_REGEXP 11 +#define DUK_HOBJECT_CLASS_STRING 12 +#define DUK_HOBJECT_CLASS_GLOBAL 13 +#define DUK_HOBJECT_CLASS_SYMBOL 14 +#define DUK_HOBJECT_CLASS_OBJENV 15 /* custom */ +#define DUK_HOBJECT_CLASS_DECENV 16 /* custom */ +#define DUK_HOBJECT_CLASS_POINTER 17 /* custom */ +#define DUK_HOBJECT_CLASS_THREAD 18 /* custom; implies DUK_HOBJECT_IS_THREAD */ +#define DUK_HOBJECT_CLASS_BUFOBJ_MIN 19 +#define DUK_HOBJECT_CLASS_ARRAYBUFFER 19 /* implies DUK_HOBJECT_IS_BUFOBJ */ +#define DUK_HOBJECT_CLASS_DATAVIEW 20 +#define DUK_HOBJECT_CLASS_INT8ARRAY 21 +#define DUK_HOBJECT_CLASS_UINT8ARRAY 22 +#define DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY 23 +#define DUK_HOBJECT_CLASS_INT16ARRAY 24 +#define DUK_HOBJECT_CLASS_UINT16ARRAY 25 +#define DUK_HOBJECT_CLASS_INT32ARRAY 26 +#define DUK_HOBJECT_CLASS_UINT32ARRAY 27 +#define DUK_HOBJECT_CLASS_FLOAT32ARRAY 28 +#define DUK_HOBJECT_CLASS_FLOAT64ARRAY 29 +#define DUK_HOBJECT_CLASS_BUFOBJ_MAX 29 +#define DUK_HOBJECT_CLASS_MAX 29 /* Class masks. */ -#define DUK_HOBJECT_CMASK_ALL ((1UL << (DUK_HOBJECT_CLASS_MAX + 1)) - 1UL) -#define DUK_HOBJECT_CMASK_NONE (1UL << DUK_HOBJECT_CLASS_NONE) -#define DUK_HOBJECT_CMASK_ARGUMENTS (1UL << DUK_HOBJECT_CLASS_ARGUMENTS) -#define DUK_HOBJECT_CMASK_ARRAY (1UL << DUK_HOBJECT_CLASS_ARRAY) -#define DUK_HOBJECT_CMASK_BOOLEAN (1UL << DUK_HOBJECT_CLASS_BOOLEAN) -#define DUK_HOBJECT_CMASK_DATE (1UL << DUK_HOBJECT_CLASS_DATE) -#define DUK_HOBJECT_CMASK_ERROR (1UL << DUK_HOBJECT_CLASS_ERROR) -#define DUK_HOBJECT_CMASK_FUNCTION (1UL << DUK_HOBJECT_CLASS_FUNCTION) -#define DUK_HOBJECT_CMASK_JSON (1UL << DUK_HOBJECT_CLASS_JSON) -#define DUK_HOBJECT_CMASK_MATH (1UL << DUK_HOBJECT_CLASS_MATH) -#define DUK_HOBJECT_CMASK_NUMBER (1UL << DUK_HOBJECT_CLASS_NUMBER) -#define DUK_HOBJECT_CMASK_OBJECT (1UL << DUK_HOBJECT_CLASS_OBJECT) -#define DUK_HOBJECT_CMASK_REGEXP (1UL << DUK_HOBJECT_CLASS_REGEXP) -#define DUK_HOBJECT_CMASK_STRING (1UL << DUK_HOBJECT_CLASS_STRING) -#define DUK_HOBJECT_CMASK_GLOBAL (1UL << DUK_HOBJECT_CLASS_GLOBAL) -#define DUK_HOBJECT_CMASK_SYMBOL (1UL << DUK_HOBJECT_CLASS_SYMBOL) -#define DUK_HOBJECT_CMASK_OBJENV (1UL << DUK_HOBJECT_CLASS_OBJENV) -#define DUK_HOBJECT_CMASK_DECENV (1UL << DUK_HOBJECT_CLASS_DECENV) -#define DUK_HOBJECT_CMASK_POINTER (1UL << DUK_HOBJECT_CLASS_POINTER) -#define DUK_HOBJECT_CMASK_ARRAYBUFFER (1UL << DUK_HOBJECT_CLASS_ARRAYBUFFER) -#define DUK_HOBJECT_CMASK_DATAVIEW (1UL << DUK_HOBJECT_CLASS_DATAVIEW) -#define DUK_HOBJECT_CMASK_INT8ARRAY (1UL << DUK_HOBJECT_CLASS_INT8ARRAY) -#define DUK_HOBJECT_CMASK_UINT8ARRAY (1UL << DUK_HOBJECT_CLASS_UINT8ARRAY) -#define DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY (1UL << DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY) -#define DUK_HOBJECT_CMASK_INT16ARRAY (1UL << DUK_HOBJECT_CLASS_INT16ARRAY) -#define DUK_HOBJECT_CMASK_UINT16ARRAY (1UL << DUK_HOBJECT_CLASS_UINT16ARRAY) -#define DUK_HOBJECT_CMASK_INT32ARRAY (1UL << DUK_HOBJECT_CLASS_INT32ARRAY) -#define DUK_HOBJECT_CMASK_UINT32ARRAY (1UL << DUK_HOBJECT_CLASS_UINT32ARRAY) -#define DUK_HOBJECT_CMASK_FLOAT32ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT32ARRAY) -#define DUK_HOBJECT_CMASK_FLOAT64ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT64ARRAY) +#define DUK_HOBJECT_CMASK_ALL ((1UL << (DUK_HOBJECT_CLASS_MAX + 1)) - 1UL) +#define DUK_HOBJECT_CMASK_NONE (1UL << DUK_HOBJECT_CLASS_NONE) +#define DUK_HOBJECT_CMASK_ARGUMENTS (1UL << DUK_HOBJECT_CLASS_ARGUMENTS) +#define DUK_HOBJECT_CMASK_ARRAY (1UL << DUK_HOBJECT_CLASS_ARRAY) +#define DUK_HOBJECT_CMASK_BOOLEAN (1UL << DUK_HOBJECT_CLASS_BOOLEAN) +#define DUK_HOBJECT_CMASK_DATE (1UL << DUK_HOBJECT_CLASS_DATE) +#define DUK_HOBJECT_CMASK_ERROR (1UL << DUK_HOBJECT_CLASS_ERROR) +#define DUK_HOBJECT_CMASK_FUNCTION (1UL << DUK_HOBJECT_CLASS_FUNCTION) +#define DUK_HOBJECT_CMASK_JSON (1UL << DUK_HOBJECT_CLASS_JSON) +#define DUK_HOBJECT_CMASK_MATH (1UL << DUK_HOBJECT_CLASS_MATH) +#define DUK_HOBJECT_CMASK_NUMBER (1UL << DUK_HOBJECT_CLASS_NUMBER) +#define DUK_HOBJECT_CMASK_OBJECT (1UL << DUK_HOBJECT_CLASS_OBJECT) +#define DUK_HOBJECT_CMASK_REGEXP (1UL << DUK_HOBJECT_CLASS_REGEXP) +#define DUK_HOBJECT_CMASK_STRING (1UL << DUK_HOBJECT_CLASS_STRING) +#define DUK_HOBJECT_CMASK_GLOBAL (1UL << DUK_HOBJECT_CLASS_GLOBAL) +#define DUK_HOBJECT_CMASK_SYMBOL (1UL << DUK_HOBJECT_CLASS_SYMBOL) +#define DUK_HOBJECT_CMASK_OBJENV (1UL << DUK_HOBJECT_CLASS_OBJENV) +#define DUK_HOBJECT_CMASK_DECENV (1UL << DUK_HOBJECT_CLASS_DECENV) +#define DUK_HOBJECT_CMASK_POINTER (1UL << DUK_HOBJECT_CLASS_POINTER) +#define DUK_HOBJECT_CMASK_ARRAYBUFFER (1UL << DUK_HOBJECT_CLASS_ARRAYBUFFER) +#define DUK_HOBJECT_CMASK_DATAVIEW (1UL << DUK_HOBJECT_CLASS_DATAVIEW) +#define DUK_HOBJECT_CMASK_INT8ARRAY (1UL << DUK_HOBJECT_CLASS_INT8ARRAY) +#define DUK_HOBJECT_CMASK_UINT8ARRAY (1UL << DUK_HOBJECT_CLASS_UINT8ARRAY) +#define DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY (1UL << DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY) +#define DUK_HOBJECT_CMASK_INT16ARRAY (1UL << DUK_HOBJECT_CLASS_INT16ARRAY) +#define DUK_HOBJECT_CMASK_UINT16ARRAY (1UL << DUK_HOBJECT_CLASS_UINT16ARRAY) +#define DUK_HOBJECT_CMASK_INT32ARRAY (1UL << DUK_HOBJECT_CLASS_INT32ARRAY) +#define DUK_HOBJECT_CMASK_UINT32ARRAY (1UL << DUK_HOBJECT_CLASS_UINT32ARRAY) +#define DUK_HOBJECT_CMASK_FLOAT32ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT32ARRAY) +#define DUK_HOBJECT_CMASK_FLOAT64ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT64ARRAY) #define DUK_HOBJECT_CMASK_ALL_BUFOBJS \ - (DUK_HOBJECT_CMASK_ARRAYBUFFER | \ - DUK_HOBJECT_CMASK_DATAVIEW | \ - DUK_HOBJECT_CMASK_INT8ARRAY | \ - DUK_HOBJECT_CMASK_UINT8ARRAY | \ - DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY | \ - DUK_HOBJECT_CMASK_INT16ARRAY | \ - DUK_HOBJECT_CMASK_UINT16ARRAY | \ - DUK_HOBJECT_CMASK_INT32ARRAY | \ - DUK_HOBJECT_CMASK_UINT32ARRAY | \ - DUK_HOBJECT_CMASK_FLOAT32ARRAY | \ + (DUK_HOBJECT_CMASK_ARRAYBUFFER | DUK_HOBJECT_CMASK_DATAVIEW | DUK_HOBJECT_CMASK_INT8ARRAY | DUK_HOBJECT_CMASK_UINT8ARRAY | \ + DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY | DUK_HOBJECT_CMASK_INT16ARRAY | DUK_HOBJECT_CMASK_UINT16ARRAY | \ + DUK_HOBJECT_CMASK_INT32ARRAY | DUK_HOBJECT_CMASK_UINT32ARRAY | DUK_HOBJECT_CMASK_FLOAT32ARRAY | \ DUK_HOBJECT_CMASK_FLOAT64ARRAY) -#define DUK_HOBJECT_IS_OBJENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_OBJENV) -#define DUK_HOBJECT_IS_DECENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_DECENV) -#define DUK_HOBJECT_IS_ENV(h) (DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_DECENV((h))) -#define DUK_HOBJECT_IS_ARRAY(h) DUK_HOBJECT_HAS_EXOTIC_ARRAY((h)) /* Rely on class Array <=> exotic Array */ -#define DUK_HOBJECT_IS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_IS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_IS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_OBJENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_OBJENV) +#define DUK_HOBJECT_IS_DECENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_DECENV) +#define DUK_HOBJECT_IS_ENV(h) (DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_DECENV((h))) +#define DUK_HOBJECT_IS_ARRAY(h) DUK_HOBJECT_HAS_EXOTIC_ARRAY((h)) /* Rely on class Array <=> exotic Array */ +#define DUK_HOBJECT_IS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_IS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_IS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_IS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_IS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #else -#define DUK_HOBJECT_IS_BUFOBJ(h) 0 +#define DUK_HOBJECT_IS_BUFOBJ(h) 0 #endif -#define DUK_HOBJECT_IS_THREAD(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_THREAD) +#define DUK_HOBJECT_IS_THREAD(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_THREAD) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_IS_PROXY(h) DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ((h)) +#define DUK_HOBJECT_IS_PROXY(h) DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ((h)) #else -#define DUK_HOBJECT_IS_PROXY(h) 0 +#define DUK_HOBJECT_IS_PROXY(h) 0 #endif -#define DUK_HOBJECT_IS_NONBOUND_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_COMPFUNC | \ - DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_NONBOUND_FUNCTION(h) \ + DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC | DUK_HOBJECT_FLAG_NATFUNC) -#define DUK_HOBJECT_IS_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_BOUNDFUNC | \ - DUK_HOBJECT_FLAG_COMPFUNC | \ - DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_FUNCTION(h) \ + DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC | DUK_HOBJECT_FLAG_COMPFUNC | DUK_HOBJECT_FLAG_NATFUNC) -#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HOBJECT_HAS_CALLABLE((h)) +#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HOBJECT_HAS_CALLABLE((h)) /* Object has any exotic behavior(s). */ -#define DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS | \ - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ - DUK_HOBJECT_FLAG_BUFOBJ | \ - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) -#define DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS) +#define DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS \ + (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ + DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS) /* Object has any virtual properties (not counting Proxy behavior). */ -#define DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ - DUK_HOBJECT_FLAG_BUFOBJ) -#define DUK_HOBJECT_HAS_VIRTUAL_PROPERTIES(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS) - -#define DUK_HOBJECT_HAS_EXTENSIBLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_HAS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_HAS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_HAS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_HAS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS \ + (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_HAS_VIRTUAL_PROPERTIES(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS) + +#define DUK_HOBJECT_HAS_EXTENSIBLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_HAS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_HAS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_HAS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_HAS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_HAS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_HAS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #else -#define DUK_HOBJECT_HAS_BUFOBJ(h) 0 +#define DUK_HOBJECT_HAS_BUFOBJ(h) 0 #endif -#define DUK_HOBJECT_HAS_FASTREFS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_HAS_ARRAY_PART(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_HAS_STRICT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_HAS_NOTAIL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_HAS_NEWENV(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_HAS_NAMEBINDING(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_HAS_CREATEARGS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_HAS_HAVE_FINALIZER(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_HAS_EXOTIC_ARRAY(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_HAS_FASTREFS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_HAS_ARRAY_PART(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_HAS_STRICT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_HAS_NOTAIL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_HAS_NEWENV(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_HAS_NAMEBINDING(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_HAS_CREATEARGS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_HAS_HAVE_FINALIZER(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_HAS_EXOTIC_ARRAY(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #else -#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) 0 +#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) 0 #endif -#define DUK_HOBJECT_HAS_SPECIAL_CALL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) +#define DUK_HOBJECT_HAS_SPECIAL_CALL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) -#define DUK_HOBJECT_SET_EXTENSIBLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_SET_CONSTRUCTABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_SET_CALLABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_SET_BOUNDFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_SET_COMPFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_SET_NATFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_SET_EXTENSIBLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_SET_CONSTRUCTABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_SET_CALLABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_SET_BOUNDFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_SET_COMPFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_SET_NATFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_SET_BUFOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_SET_BUFOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #endif -#define DUK_HOBJECT_SET_FASTREFS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_SET_ARRAY_PART(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_SET_STRICT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_SET_NOTAIL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_SET_NEWENV(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_SET_NAMEBINDING(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_SET_CREATEARGS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_SET_HAVE_FINALIZER(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_SET_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_SET_FASTREFS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_SET_ARRAY_PART(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_SET_STRICT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_SET_NOTAIL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_SET_NEWENV(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_SET_NAMEBINDING(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_SET_CREATEARGS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_SET_HAVE_FINALIZER(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_SET_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_SET_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_SET_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #endif -#define DUK_HOBJECT_SET_SPECIAL_CALL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) +#define DUK_HOBJECT_SET_SPECIAL_CALL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) -#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_CLEAR_CALLABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_CLEAR_BOUNDFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_CLEAR_COMPFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_CLEAR_NATFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_CLEAR_CALLABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_CLEAR_BOUNDFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_CLEAR_COMPFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_CLEAR_NATFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_CLEAR_BUFOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_CLEAR_BUFOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #endif -#define DUK_HOBJECT_CLEAR_FASTREFS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_CLEAR_ARRAY_PART(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_CLEAR_STRICT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_CLEAR_NOTAIL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_CLEAR_NEWENV(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_CLEAR_NAMEBINDING(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_CLEAR_CREATEARGS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_CLEAR_EXOTIC_ARRAY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_CLEAR_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_CLEAR_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_CLEAR_FASTREFS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_CLEAR_ARRAY_PART(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_CLEAR_STRICT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_CLEAR_NOTAIL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_CLEAR_NEWENV(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_CLEAR_NAMEBINDING(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_CLEAR_CREATEARGS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_CLEAR_EXOTIC_ARRAY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_CLEAR_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_CLEAR_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_CLEAR_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_CLEAR_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #endif -#define DUK_HOBJECT_CLEAR_SPECIAL_CALL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) +#define DUK_HOBJECT_CLEAR_SPECIAL_CALL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) /* Object can/cannot use FASTREFS, i.e. has no strong reference fields beyond * duk_hobject base header. This is used just for asserts so doesn't need to * be optimized. */ #define DUK_HOBJECT_PROHIBITS_FASTREFS(h) \ - (DUK_HOBJECT_IS_COMPFUNC((h)) || DUK_HOBJECT_IS_DECENV((h)) || DUK_HOBJECT_IS_OBJENV((h)) || \ - DUK_HOBJECT_IS_BUFOBJ((h)) || DUK_HOBJECT_IS_THREAD((h)) || DUK_HOBJECT_IS_PROXY((h)) || \ - DUK_HOBJECT_IS_BOUNDFUNC((h))) + (DUK_HOBJECT_IS_COMPFUNC((h)) || DUK_HOBJECT_IS_DECENV((h)) || DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_BUFOBJ((h)) || \ + DUK_HOBJECT_IS_THREAD((h)) || DUK_HOBJECT_IS_PROXY((h)) || DUK_HOBJECT_IS_BOUNDFUNC((h))) #define DUK_HOBJECT_ALLOWS_FASTREFS(h) (!DUK_HOBJECT_PROHIBITS_FASTREFS((h))) /* Flags used for property attributes in duk_propdesc and packed flags. * Must fit into 8 bits. */ -#define DUK_PROPDESC_FLAG_WRITABLE (1U << 0) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_ENUMERABLE (1U << 1) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_CONFIGURABLE (1U << 2) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_ACCESSOR (1U << 3) /* accessor */ -#define DUK_PROPDESC_FLAG_VIRTUAL (1U << 4) /* property is virtual: used in duk_propdesc, never stored - * (used by e.g. buffer virtual properties) - */ -#define DUK_PROPDESC_FLAGS_MASK (DUK_PROPDESC_FLAG_WRITABLE | \ - DUK_PROPDESC_FLAG_ENUMERABLE | \ - DUK_PROPDESC_FLAG_CONFIGURABLE | \ - DUK_PROPDESC_FLAG_ACCESSOR) +#define DUK_PROPDESC_FLAG_WRITABLE (1U << 0) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_ENUMERABLE (1U << 1) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_CONFIGURABLE (1U << 2) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_ACCESSOR (1U << 3) /* accessor */ +#define DUK_PROPDESC_FLAG_VIRTUAL \ + (1U << 4) /* property is virtual: used in duk_propdesc, never stored \ + * (used by e.g. buffer virtual properties) \ + */ +#define DUK_PROPDESC_FLAGS_MASK \ + (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE | DUK_PROPDESC_FLAG_ACCESSOR) /* Additional flags which are passed in the same flags argument as property * flags but are not stored in object properties. */ -#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1U << 4) /* internal define property: skip write silently if exists */ +#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1U << 4) /* internal define property: skip write silently if exists */ /* Convenience defines for property attributes. */ -#define DUK_PROPDESC_FLAGS_NONE 0 -#define DUK_PROPDESC_FLAGS_W (DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_PROPDESC_FLAGS_E (DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_PROPDESC_FLAGS_C (DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_WE (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_PROPDESC_FLAGS_WC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_EC (DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_WEC (DUK_PROPDESC_FLAG_WRITABLE | \ - DUK_PROPDESC_FLAG_ENUMERABLE | \ - DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_NONE 0 +#define DUK_PROPDESC_FLAGS_W (DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_PROPDESC_FLAGS_E (DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_PROPDESC_FLAGS_C (DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_WE (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_PROPDESC_FLAGS_WC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_EC (DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_WEC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) /* Flags for duk_hobject_get_own_propdesc() and variants. */ -#define DUK_GETDESC_FLAG_PUSH_VALUE (1U << 0) /* push value to stack */ -#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1U << 1) /* don't throw for prototype loop */ +#define DUK_GETDESC_FLAG_PUSH_VALUE (1U << 0) /* push value to stack */ +#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1U << 1) /* don't throw for prototype loop */ /* * Macro for object validity check @@ -6456,9 +6869,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hobject_assert_valid(duk_hobject *h); -#define DUK_HOBJECT_ASSERT_VALID(h) do { duk_hobject_assert_valid((h)); } while (0) +#define DUK_HOBJECT_ASSERT_VALID(h) \ + do { \ + duk_hobject_assert_valid((h)); \ + } while (0) #else -#define DUK_HOBJECT_ASSERT_VALID(h) do {} while (0) +#define DUK_HOBJECT_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -6466,52 +6884,41 @@ */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_GET_PROPS(heap,h) \ - ((duk_uint8_t *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (h))->h_extra16)) -#define DUK_HOBJECT_SET_PROPS(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROPS(heap, h) ((duk_uint8_t *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (h))->h_extra16)) +#define DUK_HOBJECT_SET_PROPS(heap, h, x) \ + do { \ ((duk_heaphdr *) (h))->h_extra16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (x)); \ } while (0) #else -#define DUK_HOBJECT_GET_PROPS(heap,h) \ - ((h)->props) -#define DUK_HOBJECT_SET_PROPS(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROPS(heap, h) ((h)->props) +#define DUK_HOBJECT_SET_PROPS(heap, h, x) \ + do { \ (h)->props = (duk_uint8_t *) (x); \ } while (0) #endif #if defined(DUK_USE_HOBJECT_LAYOUT_1) /* LAYOUT 1 */ -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_hstring *) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) \ + ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_hstring *))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + (n_arr) * sizeof(duk_tval) + \ + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_k) = (duk_hstring **) (void *) (p_base); \ (set_e_pv) = (duk_propvalue *) (void *) ((set_e_k) + (n_ent)); \ (set_e_f) = (duk_uint8_t *) (void *) ((set_e_pv) + (n_ent)); \ @@ -6529,85 +6936,57 @@ #else #error invalid DUK_USE_ALIGN_BY #endif -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING((n_ent)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) \ + ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + DUK_HOBJECT_E_FLAG_PADDING((n_ent)) + \ + (n_arr) * sizeof(duk_tval) + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_pv) = (duk_propvalue *) (void *) (p_base); \ (set_e_k) = (duk_hstring **) (void *) ((set_e_pv) + (n_ent)); \ (set_e_f) = (duk_uint8_t *) (void *) ((set_e_k) + (n_ent)); \ - (set_a) = (duk_tval *) (void *) (((duk_uint8_t *) (set_e_f)) + \ - sizeof(duk_uint8_t) * (n_ent) + \ + (set_a) = (duk_tval *) (void *) (((duk_uint8_t *) (set_e_f)) + sizeof(duk_uint8_t) * (n_ent) + \ DUK_HOBJECT_E_FLAG_PADDING((n_ent))); \ (set_h) = (duk_uint32_t *) (void *) ((set_a) + (n_arr)); \ } while (0) #elif defined(DUK_USE_HOBJECT_LAYOUT_3) /* LAYOUT 3 */ -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) + \ - DUK_HOBJECT_GET_HSIZE((h)) * sizeof(duk_uint32_t) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_propvalue) + sizeof(duk_hstring *) + sizeof(duk_uint8_t)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) \ + ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) + \ + DUK_HOBJECT_GET_HSIZE((h)) * sizeof(duk_uint32_t))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_propvalue) + sizeof(duk_hstring *) + sizeof(duk_uint8_t)) + (n_arr) * sizeof(duk_tval) + \ + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_pv) = (duk_propvalue *) (void *) (p_base); \ (set_a) = (duk_tval *) (void *) ((set_e_pv) + (n_ent)); \ (set_e_k) = (duk_hstring **) (void *) ((set_a) + (n_arr)); \ @@ -6616,85 +6995,99 @@ } while (0) #else #error invalid hobject layout defines -#endif /* hobject property layout */ +#endif /* hobject property layout */ #define DUK_HOBJECT_P_ALLOC_SIZE(h) \ DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE((h)), DUK_HOBJECT_GET_ASIZE((h)), DUK_HOBJECT_GET_HSIZE((h))) -#define DUK_HOBJECT_E_GET_KEY(heap,h,i) (DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_KEY_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE(heap,h,i) (DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE_TVAL(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) -#define DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) -#define DUK_HOBJECT_E_GET_VALUE_GETTER(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) -#define DUK_HOBJECT_E_GET_VALUE_GETTER_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) -#define DUK_HOBJECT_E_GET_VALUE_SETTER(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) -#define DUK_HOBJECT_E_GET_VALUE_SETTER_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) -#define DUK_HOBJECT_E_GET_FLAGS(heap,h,i) (DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_FLAGS_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) -#define DUK_HOBJECT_A_GET_VALUE(heap,h,i) (DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_A_GET_VALUE_PTR(heap,h,i) (&DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_H_GET_INDEX(heap,h,i) (DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_H_GET_INDEX_PTR(heap,h,i) (&DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_KEY(heap, h, i) (DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_KEY_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE(heap, h, i) (DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE_TVAL(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) +#define DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) +#define DUK_HOBJECT_E_GET_VALUE_GETTER(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) +#define DUK_HOBJECT_E_GET_VALUE_GETTER_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) +#define DUK_HOBJECT_E_GET_VALUE_SETTER(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) +#define DUK_HOBJECT_E_GET_VALUE_SETTER_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) +#define DUK_HOBJECT_E_GET_FLAGS(heap, h, i) (DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_FLAGS_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) +#define DUK_HOBJECT_A_GET_VALUE(heap, h, i) (DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_A_GET_VALUE_PTR(heap, h, i) (&DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_H_GET_INDEX(heap, h, i) (DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_H_GET_INDEX_PTR(heap, h, i) (&DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_SET_KEY(heap,h,i,k) do { \ +#define DUK_HOBJECT_E_SET_KEY(heap, h, i, k) \ + do { \ DUK_HOBJECT_E_GET_KEY((heap), (h), (i)) = (k); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_TVAL(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_TVAL(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_GETTER(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_GETTER(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_SETTER(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_SETTER(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_FLAGS(heap,h,i,f) do { \ +#define DUK_HOBJECT_E_SET_FLAGS(heap, h, i, f) \ + do { \ DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) = (duk_uint8_t) (f); \ } while (0) -#define DUK_HOBJECT_A_SET_VALUE(heap,h,i,v) do { \ +#define DUK_HOBJECT_A_SET_VALUE(heap, h, i, v) \ + do { \ DUK_HOBJECT_A_GET_VALUE((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_A_SET_VALUE_TVAL(heap,h,i,v) \ - DUK_HOBJECT_A_SET_VALUE((heap), (h), (i), (v)) /* alias for above */ -#define DUK_HOBJECT_H_SET_INDEX(heap,h,i,v) do { \ +#define DUK_HOBJECT_A_SET_VALUE_TVAL(heap, h, i, v) DUK_HOBJECT_A_SET_VALUE((heap), (h), (i), (v)) /* alias for above */ +#define DUK_HOBJECT_H_SET_INDEX(heap, h, i, v) \ + do { \ DUK_HOBJECT_H_GET_INDEX((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_FLAG_BITS(heap,h,i,mask) do { \ +#define DUK_HOBJECT_E_SET_FLAG_BITS(heap, h, i, mask) \ + do { \ DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i) |= (mask); \ } while (0) -#define DUK_HOBJECT_E_CLEAR_FLAG_BITS(heap,h,i,mask) do { \ +#define DUK_HOBJECT_E_CLEAR_FLAG_BITS(heap, h, i, mask) \ + do { \ DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i) &= ~(mask); \ } while (0) -#define DUK_HOBJECT_E_SLOT_IS_WRITABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_WRITABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ACCESSOR) != 0) - -#define DUK_HOBJECT_E_SLOT_SET_WRITABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_HOBJECT_E_SLOT_SET_ENUMERABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_HOBJECT_E_SLOT_SET_CONFIGURABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_HOBJECT_E_SLOT_SET_ACCESSOR(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ACCESSOR) - -#define DUK_HOBJECT_E_SLOT_CLEAR_WRITABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_ENUMERABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_CONFIGURABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_ACCESSOR(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ACCESSOR) - -#define DUK_PROPDESC_IS_WRITABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_WRITABLE) != 0) -#define DUK_PROPDESC_IS_ENUMERABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) -#define DUK_PROPDESC_IS_CONFIGURABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) -#define DUK_PROPDESC_IS_ACCESSOR(p) (((p)->flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0) +#define DUK_HOBJECT_E_SLOT_IS_WRITABLE(heap, h, i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_WRITABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(heap, h, i) \ + ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(heap, h, i) \ + ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap, h, i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ACCESSOR) != 0) + +#define DUK_HOBJECT_E_SLOT_SET_WRITABLE(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_HOBJECT_E_SLOT_SET_ENUMERABLE(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_HOBJECT_E_SLOT_SET_CONFIGURABLE(heap, h, i) \ + DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_HOBJECT_E_SLOT_SET_ACCESSOR(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ACCESSOR) + +#define DUK_HOBJECT_E_SLOT_CLEAR_WRITABLE(heap, h, i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_ENUMERABLE(heap, h, i) \ + DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_CONFIGURABLE(heap, h, i) \ + DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_ACCESSOR(heap, h, i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ACCESSOR) + +#define DUK_PROPDESC_IS_WRITABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_WRITABLE) != 0) +#define DUK_PROPDESC_IS_ENUMERABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) +#define DUK_PROPDESC_IS_CONFIGURABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) +#define DUK_PROPDESC_IS_ACCESSOR(p) (((p)->flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0) -#define DUK_HOBJECT_HASHIDX_UNUSED 0xffffffffUL -#define DUK_HOBJECT_HASHIDX_DELETED 0xfffffffeUL +#define DUK_HOBJECT_HASHIDX_UNUSED 0xffffffffUL +#define DUK_HOBJECT_HASHIDX_DELETED 0xfffffffeUL /* * Macros for accessing size fields @@ -6702,33 +7095,63 @@ #if defined(DUK_USE_OBJSIZES16) #define DUK_HOBJECT_GET_ESIZE(h) ((h)->e_size16) -#define DUK_HOBJECT_SET_ESIZE(h,v) do { (h)->e_size16 = (v); } while (0) +#define DUK_HOBJECT_SET_ESIZE(h, v) \ + do { \ + (h)->e_size16 = (v); \ + } while (0) #define DUK_HOBJECT_GET_ENEXT(h) ((h)->e_next16) -#define DUK_HOBJECT_SET_ENEXT(h,v) do { (h)->e_next16 = (v); } while (0) +#define DUK_HOBJECT_SET_ENEXT(h, v) \ + do { \ + (h)->e_next16 = (v); \ + } while (0) #define DUK_HOBJECT_POSTINC_ENEXT(h) ((h)->e_next16++) -#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size16) -#define DUK_HOBJECT_SET_ASIZE(h,v) do { (h)->a_size16 = (v); } while (0) +#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size16) +#define DUK_HOBJECT_SET_ASIZE(h, v) \ + do { \ + (h)->a_size16 = (v); \ + } while (0) #if defined(DUK_USE_HOBJECT_HASH_PART) #define DUK_HOBJECT_GET_HSIZE(h) ((h)->h_size16) -#define DUK_HOBJECT_SET_HSIZE(h,v) do { (h)->h_size16 = (v); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + (h)->h_size16 = (v); \ + } while (0) #else #define DUK_HOBJECT_GET_HSIZE(h) 0 -#define DUK_HOBJECT_SET_HSIZE(h,v) do { DUK_ASSERT((v) == 0); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + DUK_ASSERT((v) == 0); \ + } while (0) #endif #else #define DUK_HOBJECT_GET_ESIZE(h) ((h)->e_size) -#define DUK_HOBJECT_SET_ESIZE(h,v) do { (h)->e_size = (v); } while (0) +#define DUK_HOBJECT_SET_ESIZE(h, v) \ + do { \ + (h)->e_size = (v); \ + } while (0) #define DUK_HOBJECT_GET_ENEXT(h) ((h)->e_next) -#define DUK_HOBJECT_SET_ENEXT(h,v) do { (h)->e_next = (v); } while (0) +#define DUK_HOBJECT_SET_ENEXT(h, v) \ + do { \ + (h)->e_next = (v); \ + } while (0) #define DUK_HOBJECT_POSTINC_ENEXT(h) ((h)->e_next++) -#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size) -#define DUK_HOBJECT_SET_ASIZE(h,v) do { (h)->a_size = (v); } while (0) +#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size) +#define DUK_HOBJECT_SET_ASIZE(h, v) \ + do { \ + (h)->a_size = (v); \ + } while (0) #if defined(DUK_USE_HOBJECT_HASH_PART) #define DUK_HOBJECT_GET_HSIZE(h) ((h)->h_size) -#define DUK_HOBJECT_SET_HSIZE(h,v) do { (h)->h_size = (v); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + (h)->h_size = (v); \ + } while (0) #else #define DUK_HOBJECT_GET_HSIZE(h) 0 -#define DUK_HOBJECT_SET_HSIZE(h,v) do { DUK_ASSERT((v) == 0); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + DUK_ASSERT((v) == 0); \ + } while (0) #endif #endif @@ -6739,46 +7162,44 @@ /* Maximum prototype traversal depth. Sanity limit which handles e.g. * prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4). */ -#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY 10000L +#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY 10000L /* * ECMAScript Class */ /* range check not necessary because all 4-bit values are mapped */ -#define DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(n) duk_class_number_to_stridx(n) +#define DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(n) duk_class_number_to_stridx(n) -#define DUK_HOBJECT_GET_CLASS_STRING(heap,h) \ - DUK_HEAP_GET_STRING( \ - (heap), \ - DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(DUK_HOBJECT_GET_CLASS_NUMBER((h))) \ - ) +#define DUK_HOBJECT_GET_CLASS_STRING(heap, h) \ + DUK_HEAP_GET_STRING((heap), DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(DUK_HOBJECT_GET_CLASS_NUMBER((h)))) /* * Macros for property handling */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_GET_PROTOTYPE(heap,h) \ - ((duk_hobject *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->prototype16)) -#define DUK_HOBJECT_SET_PROTOTYPE(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROTOTYPE(heap, h) ((duk_hobject *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->prototype16)) +#define DUK_HOBJECT_SET_PROTOTYPE(heap, h, x) \ + do { \ (h)->prototype16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (x)); \ } while (0) #else -#define DUK_HOBJECT_GET_PROTOTYPE(heap,h) \ - ((h)->prototype) -#define DUK_HOBJECT_SET_PROTOTYPE(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROTOTYPE(heap, h) ((h)->prototype) +#define DUK_HOBJECT_SET_PROTOTYPE(heap, h, x) \ + do { \ (h)->prototype = (x); \ } while (0) #endif /* Set prototype, DECREF earlier value, INCREF new value (tolerating NULLs). */ -#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr,h,p) duk_hobject_set_prototype_updref((thr), (h), (p)) +#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, p) duk_hobject_set_prototype_updref((thr), (h), (p)) /* Set initial prototype, assume NULL previous prototype, INCREF new value, * tolerate NULL. */ -#define DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr,h,proto) do { \ +#define DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, h, proto) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_hobject *duk__obj = (h); \ duk_hobject *duk__proto = (proto); \ @@ -6793,9 +7214,9 @@ */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap,h) duk_hobject_has_finalizer_fast_raw((heap), (h)) +#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap, h) duk_hobject_has_finalizer_fast_raw((heap), (h)) #else -#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap,h) duk_hobject_has_finalizer_fast_raw((h)) +#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap, h) duk_hobject_has_finalizer_fast_raw((h)) #endif /* @@ -6809,18 +7230,18 @@ * so anything above 0x80000000 will cause trouble now. */ #if defined(DUK_USE_OBJSIZES16) -#define DUK_HOBJECT_MAX_PROPERTIES 0x0000ffffUL +#define DUK_HOBJECT_MAX_PROPERTIES 0x0000ffffUL #else -#define DUK_HOBJECT_MAX_PROPERTIES 0x3fffffffUL /* 2**30-1 ~= 1G properties */ +#define DUK_HOBJECT_MAX_PROPERTIES 0x3fffffffUL /* 2**30-1 ~= 1G properties */ #endif /* internal align target for props allocation, must be 2*n for some n */ #if (DUK_USE_ALIGN_BY == 4) -#define DUK_HOBJECT_ALIGN_TARGET 4 +#define DUK_HOBJECT_ALIGN_TARGET 4 #elif (DUK_USE_ALIGN_BY == 8) -#define DUK_HOBJECT_ALIGN_TARGET 8 +#define DUK_HOBJECT_ALIGN_TARGET 8 #elif (DUK_USE_ALIGN_BY == 1) -#define DUK_HOBJECT_ALIGN_TARGET 1 +#define DUK_HOBJECT_ALIGN_TARGET 1 #else #error invalid DUK_USE_ALIGN_BY #endif @@ -6829,10 +7250,10 @@ * PC-to-line constants */ -#define DUK_PC2LINE_SKIP 64 +#define DUK_PC2LINE_SKIP 64 /* maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes */ -#define DUK_PC2LINE_MAX_DIFF_LENGTH (((DUK_PC2LINE_SKIP - 1) * 35 + 7) / 8) +#define DUK_PC2LINE_MAX_DIFF_LENGTH (((DUK_PC2LINE_SKIP - 1) * 35 + 7) / 8) /* * Struct defs @@ -6859,9 +7280,9 @@ duk_hobject *set; /* for updating (all are set to < 0 for virtual properties) */ - duk_int_t e_idx; /* prop index in 'entry part', < 0 if not there */ - duk_int_t h_idx; /* prop index in 'hash part', < 0 if not there */ - duk_int_t a_idx; /* prop index in 'array part', < 0 if not there */ + duk_int_t e_idx; /* prop index in 'entry part', < 0 if not there */ + duk_int_t h_idx; /* prop index in 'hash part', < 0 if not there */ + duk_int_t a_idx; /* prop index in 'array part', < 0 if not there */ }; struct duk_hobject { @@ -6956,11 +7377,11 @@ duk_uint16_t h_size16; #endif #else - duk_uint32_t e_size; /* entry part size */ - duk_uint32_t e_next; /* index for next new key (0,e_next are gc reachable) */ - duk_uint32_t a_size; /* array part size (entirely gc reachable) */ + duk_uint32_t e_size; /* entry part size */ + duk_uint32_t e_next; /* index for next new key (0,e_next are gc reachable) */ + duk_uint32_t a_size; /* array part size (entirely gc reachable) */ #if defined(DUK_USE_HOBJECT_HASH_PART) - duk_uint32_t h_size; /* hash part size or 0 if unused */ + duk_uint32_t h_size; /* hash part size or 0 if unused */ #endif #endif }; @@ -6971,7 +7392,7 @@ #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL duk_uint8_t duk_class_number_to_stridx32; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* * Prototypes @@ -7000,36 +7421,46 @@ duk_uint32_t new_a_size, duk_uint32_t new_h_size, duk_bool_t abandon_array); -DUK_INTERNAL_DECL void duk_hobject_resize_entrypart(duk_hthread *thr, - duk_hobject *obj, - duk_uint32_t new_e_size); -#if 0 /*unused*/ +DUK_INTERNAL_DECL void duk_hobject_resize_entrypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_e_size); +#if 0 /*unused*/ DUK_INTERNAL_DECL void duk_hobject_resize_arraypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_a_size); #endif /* low-level property functions */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_hstring *key); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_stridx(duk_heap *heap, duk_hobject *obj, duk_small_uint_t stridx); -DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_uint_t *out_attrs); +DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, + duk_hobject *obj, + duk_hstring *key, + duk_uint_t *out_attrs); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_array_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_uarridx_t i); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); /* core property functions */ DUK_INTERNAL_DECL duk_bool_t duk_hobject_getprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag); DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_bool_t throw_flag); DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key); /* internal property functions */ -#define DUK_DELPROP_FLAG_THROW (1U << 0) -#define DUK_DELPROP_FLAG_FORCE (1U << 1) +#define DUK_DELPROP_FLAG_THROW (1U << 0) +#define DUK_DELPROP_FLAG_FORCE (1U << 1) DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags); DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key); -DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags); -DUK_INTERNAL_DECL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, duk_hobject *obj, duk_uarridx_t arr_idx, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, + duk_hobject *obj, + duk_uarridx_t arr_idx, + duk_small_uint_t flags); DUK_INTERNAL_DECL duk_size_t duk_hobject_get_length(duk_hthread *thr, duk_hobject *obj); #if defined(DUK_USE_HEAPPTR16) DUK_INTERNAL_DECL duk_bool_t duk_hobject_has_finalizer_fast_raw(duk_heap *heap, duk_hobject *obj); @@ -7089,7 +7520,10 @@ #endif /* misc */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop); +DUK_INTERNAL_DECL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, + duk_hobject *h, + duk_hobject *p, + duk_bool_t ignore_loop); #if !defined(DUK_USE_OBJECT_BUILTIN) /* These declarations are needed when related built-in is disabled and @@ -7099,7 +7533,7 @@ DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype(duk_hthread *thr); #endif -#endif /* DUK_HOBJECT_H_INCLUDED */ +#endif /* DUK_HOBJECT_H_INCLUDED */ /* #include duk_hcompfunc.h */ /* * Heap compiled function (ECMAScript function) representation. @@ -7118,50 +7552,55 @@ /* XXX: casts could be improved, especially for GET/SET DATA */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HCOMPFUNC_GET_DATA(heap,h) \ - ((duk_hbuffer_fixed *) (void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->data16)) -#define DUK_HCOMPFUNC_SET_DATA(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_DATA(heap, h) ((duk_hbuffer_fixed *) (void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->data16)) +#define DUK_HCOMPFUNC_SET_DATA(heap, h, v) \ + do { \ (h)->data16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_FUNCS(heap,h) \ - ((duk_hobject **) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->funcs16))) -#define DUK_HCOMPFUNC_SET_FUNCS(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_FUNCS(heap, h) ((duk_hobject **) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->funcs16))) +#define DUK_HCOMPFUNC_SET_FUNCS(heap, h, v) \ + do { \ (h)->funcs16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_BYTECODE(heap,h) \ - ((duk_instr_t *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->bytecode16))) -#define DUK_HCOMPFUNC_SET_BYTECODE(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_BYTECODE(heap, h) ((duk_instr_t *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->bytecode16))) +#define DUK_HCOMPFUNC_SET_BYTECODE(heap, h, v) \ + do { \ (h)->bytecode16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_LEXENV(heap,h) \ - ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->lex_env16))) -#define DUK_HCOMPFUNC_SET_LEXENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_LEXENV(heap, h) ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->lex_env16))) +#define DUK_HCOMPFUNC_SET_LEXENV(heap, h, v) \ + do { \ (h)->lex_env16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_VARENV(heap,h) \ - ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->var_env16))) -#define DUK_HCOMPFUNC_SET_VARENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_VARENV(heap, h) ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->var_env16))) +#define DUK_HCOMPFUNC_SET_VARENV(heap, h, v) \ + do { \ (h)->var_env16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) #else -#define DUK_HCOMPFUNC_GET_DATA(heap,h) ((duk_hbuffer_fixed *) (void *) (h)->data) -#define DUK_HCOMPFUNC_SET_DATA(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_DATA(heap, h) ((duk_hbuffer_fixed *) (void *) (h)->data) +#define DUK_HCOMPFUNC_SET_DATA(heap, h, v) \ + do { \ (h)->data = (duk_hbuffer *) (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_FUNCS(heap,h) ((h)->funcs) -#define DUK_HCOMPFUNC_SET_FUNCS(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_FUNCS(heap, h) ((h)->funcs) +#define DUK_HCOMPFUNC_SET_FUNCS(heap, h, v) \ + do { \ (h)->funcs = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_BYTECODE(heap,h) ((h)->bytecode) -#define DUK_HCOMPFUNC_SET_BYTECODE(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_BYTECODE(heap, h) ((h)->bytecode) +#define DUK_HCOMPFUNC_SET_BYTECODE(heap, h, v) \ + do { \ (h)->bytecode = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_LEXENV(heap,h) ((h)->lex_env) -#define DUK_HCOMPFUNC_SET_LEXENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_LEXENV(heap, h) ((h)->lex_env) +#define DUK_HCOMPFUNC_SET_LEXENV(heap, h, v) \ + do { \ (h)->lex_env = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_VARENV(heap,h) ((h)->var_env) -#define DUK_HCOMPFUNC_SET_VARENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_VARENV(heap, h) ((h)->var_env) +#define DUK_HCOMPFUNC_SET_VARENV(heap, h, v) \ + do { \ (h)->var_env = (v); \ } while (0) #endif @@ -7171,64 +7610,40 @@ */ /* Note: assumes 'data' is always a fixed buffer */ -#define DUK_HCOMPFUNC_GET_BUFFER_BASE(heap,h) \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) +#define DUK_HCOMPFUNC_GET_BUFFER_BASE(heap, h) DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) -#define DUK_HCOMPFUNC_GET_CONSTS_BASE(heap,h) \ - ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_BUFFER_BASE((heap), (h))) +#define DUK_HCOMPFUNC_GET_CONSTS_BASE(heap, h) ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_BUFFER_BASE((heap), (h))) -#define DUK_HCOMPFUNC_GET_FUNCS_BASE(heap,h) \ - DUK_HCOMPFUNC_GET_FUNCS((heap), (h)) +#define DUK_HCOMPFUNC_GET_FUNCS_BASE(heap, h) DUK_HCOMPFUNC_GET_FUNCS((heap), (h)) -#define DUK_HCOMPFUNC_GET_CODE_BASE(heap,h) \ - DUK_HCOMPFUNC_GET_BYTECODE((heap), (h)) +#define DUK_HCOMPFUNC_GET_CODE_BASE(heap, h) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h)) -#define DUK_HCOMPFUNC_GET_CONSTS_END(heap,h) \ - ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_FUNCS((heap), (h))) +#define DUK_HCOMPFUNC_GET_CONSTS_END(heap, h) ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_FUNCS((heap), (h))) -#define DUK_HCOMPFUNC_GET_FUNCS_END(heap,h) \ - ((duk_hobject **) (void *) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h))) +#define DUK_HCOMPFUNC_GET_FUNCS_END(heap, h) ((duk_hobject **) (void *) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h))) /* XXX: double evaluation of DUK_HCOMPFUNC_GET_DATA() */ -#define DUK_HCOMPFUNC_GET_CODE_END(heap,h) \ +#define DUK_HCOMPFUNC_GET_CODE_END(heap, h) \ ((duk_instr_t *) (void *) (DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) + \ - DUK_HBUFFER_GET_SIZE((duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA((heap), h)))) + DUK_HBUFFER_GET_SIZE((duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA((heap), h)))) + +#define DUK_HCOMPFUNC_GET_CONSTS_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_BASE((heap), (h))))) + +#define DUK_HCOMPFUNC_GET_FUNCS_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_BASE((heap), (h))))) -#define DUK_HCOMPFUNC_GET_CONSTS_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_END((heap), (h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_BASE((heap), (h))) \ - ) \ - ) - -#define DUK_HCOMPFUNC_GET_FUNCS_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_END((heap), (h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_BASE((heap), (h))) \ - ) \ - ) - -#define DUK_HCOMPFUNC_GET_CODE_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_END((heap),(h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_BASE((heap),(h))) \ - ) \ - ) +#define DUK_HCOMPFUNC_GET_CODE_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_BASE((heap), (h))))) -#define DUK_HCOMPFUNC_GET_CONSTS_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_CONSTS_SIZE((heap), (h)) / sizeof(duk_tval))) +#define DUK_HCOMPFUNC_GET_CONSTS_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_CONSTS_SIZE((heap), (h)) / sizeof(duk_tval))) -#define DUK_HCOMPFUNC_GET_FUNCS_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_FUNCS_SIZE((heap), (h)) / sizeof(duk_hobject *))) +#define DUK_HCOMPFUNC_GET_FUNCS_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_FUNCS_SIZE((heap), (h)) / sizeof(duk_hobject *))) -#define DUK_HCOMPFUNC_GET_CODE_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_CODE_SIZE((heap), (h)) / sizeof(duk_instr_t))) +#define DUK_HCOMPFUNC_GET_CODE_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_CODE_SIZE((heap), (h)) / sizeof(duk_instr_t))) /* * Validity assert @@ -7236,9 +7651,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hcompfunc_assert_valid(duk_hcompfunc *h); -#define DUK_HCOMPFUNC_ASSERT_VALID(h) do { duk_hcompfunc_assert_valid((h)); } while (0) +#define DUK_HCOMPFUNC_ASSERT_VALID(h) \ + do { \ + duk_hcompfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HCOMPFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HCOMPFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -7325,8 +7745,8 @@ * at run time, except for debugging, so it is not maintained. */ - duk_uint16_t nregs; /* regs to allocate */ - duk_uint16_t nargs; /* number of arguments allocated to regs */ + duk_uint16_t nregs; /* regs to allocate */ + duk_uint16_t nargs; /* number of arguments allocated to regs */ /* * Additional control information is placed into the object itself @@ -7373,7 +7793,7 @@ #endif }; -#endif /* DUK_HCOMPFUNC_H_INCLUDED */ +#endif /* DUK_HCOMPFUNC_H_INCLUDED */ /* #include duk_hnatfunc.h */ /* * Heap native function representation. @@ -7384,13 +7804,18 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hnatfunc_assert_valid(duk_hnatfunc *h); -#define DUK_HNATFUNC_ASSERT_VALID(h) do { duk_hnatfunc_assert_valid((h)); } while (0) +#define DUK_HNATFUNC_ASSERT_VALID(h) \ + do { \ + duk_hnatfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HNATFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HNATFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#define DUK_HNATFUNC_NARGS_VARARGS ((duk_int16_t) -1) -#define DUK_HNATFUNC_NARGS_MAX ((duk_int16_t) 0x7fff) +#define DUK_HNATFUNC_NARGS_VARARGS ((duk_int16_t) -1) +#define DUK_HNATFUNC_NARGS_MAX ((duk_int16_t) 0x7fff) struct duk_hnatfunc { /* shared object part */ @@ -7413,7 +7838,7 @@ */ }; -#endif /* DUK_HNATFUNC_H_INCLUDED */ +#endif /* DUK_HNATFUNC_H_INCLUDED */ /* #include duk_hboundfunc.h */ /* * Bound function representation. @@ -7429,9 +7854,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hboundfunc_assert_valid(duk_hboundfunc *h); -#define DUK_HBOUNDFUNC_ASSERT_VALID(h) do { duk_hboundfunc_assert_valid((h)); } while (0) +#define DUK_HBOUNDFUNC_ASSERT_VALID(h) \ + do { \ + duk_hboundfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HBOUNDFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HBOUNDFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hboundfunc { @@ -7447,11 +7877,11 @@ duk_tval this_binding; /* Arguments to prepend. */ - duk_tval *args; /* Separate allocation. */ + duk_tval *args; /* Separate allocation. */ duk_idx_t nargs; }; -#endif /* DUK_HBOUNDFUNC_H_INCLUDED */ +#endif /* DUK_HBOUNDFUNC_H_INCLUDED */ /* #include duk_hbufobj.h */ /* * Heap Buffer object representation. Used for all Buffer variants. @@ -7463,31 +7893,37 @@ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) /* All element accessors are host endian now (driven by TypedArray spec). */ -#define DUK_HBUFOBJ_ELEM_UINT8 0 -#define DUK_HBUFOBJ_ELEM_UINT8CLAMPED 1 -#define DUK_HBUFOBJ_ELEM_INT8 2 -#define DUK_HBUFOBJ_ELEM_UINT16 3 -#define DUK_HBUFOBJ_ELEM_INT16 4 -#define DUK_HBUFOBJ_ELEM_UINT32 5 -#define DUK_HBUFOBJ_ELEM_INT32 6 -#define DUK_HBUFOBJ_ELEM_FLOAT32 7 -#define DUK_HBUFOBJ_ELEM_FLOAT64 8 -#define DUK_HBUFOBJ_ELEM_MAX 8 +#define DUK_HBUFOBJ_ELEM_UINT8 0 +#define DUK_HBUFOBJ_ELEM_UINT8CLAMPED 1 +#define DUK_HBUFOBJ_ELEM_INT8 2 +#define DUK_HBUFOBJ_ELEM_UINT16 3 +#define DUK_HBUFOBJ_ELEM_INT16 4 +#define DUK_HBUFOBJ_ELEM_UINT32 5 +#define DUK_HBUFOBJ_ELEM_INT32 6 +#define DUK_HBUFOBJ_ELEM_FLOAT32 7 +#define DUK_HBUFOBJ_ELEM_FLOAT64 8 +#define DUK_HBUFOBJ_ELEM_MAX 8 #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hbufobj_assert_valid(duk_hbufobj *h); -#define DUK_HBUFOBJ_ASSERT_VALID(h) do { duk_hbufobj_assert_valid((h)); } while (0) +#define DUK_HBUFOBJ_ASSERT_VALID(h) \ + do { \ + duk_hbufobj_assert_valid((h)); \ + } while (0) #else -#define DUK_HBUFOBJ_ASSERT_VALID(h) do {} while (0) +#define DUK_HBUFOBJ_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* Get the current data pointer (caller must ensure buf != NULL) as a * duk_uint8_t ptr. Note that the result may be NULL if the underlying * buffer has zero size and is not a fixed buffer. */ -#define DUK_HBUFOBJ_GET_SLICE_BASE(heap,h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - (((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR((heap), (h)->buf)) + (h)->offset)) +#define DUK_HBUFOBJ_GET_SLICE_BASE(heap, h) \ + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + (((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR((heap), (h)->buf)) + (h)->offset)) /* True if slice is full, i.e. offset is zero and length covers the entire * buffer. This status may change independently of the duk_hbufobj if @@ -7495,15 +7931,17 @@ * being changed. */ #define DUK_HBUFOBJ_FULL_SLICE(h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset == 0 && (h)->length == DUK_HBUFFER_GET_SIZE((h)->buf))) + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + ((h)->offset == 0 && (h)->length == DUK_HBUFFER_GET_SIZE((h)->buf))) /* Validate that the whole slice 0,length is contained in the underlying * buffer. Caller must ensure 'buf' != NULL. */ #define DUK_HBUFOBJ_VALID_SLICE(h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (h)->length <= DUK_HBUFFER_GET_SIZE((h)->buf))) + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + ((h)->offset + (h)->length <= DUK_HBUFFER_GET_SIZE((h)->buf))) /* Validate byte read/write for virtual 'offset', i.e. check that the * offset, taking into account h->offset, is within the underlying @@ -7512,13 +7950,11 @@ * behavior (e.g. if an underlying dynamic buffer changes after being * setup). Caller must ensure 'buf' != NULL. */ -#define DUK_HBUFOBJ_VALID_BYTEOFFSET_INCL(h,off) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf))) - -#define DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h,off) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (off) <= DUK_HBUFFER_GET_SIZE((h)->buf))) +#define DUK_HBUFOBJ_VALID_BYTEOFFSET_INCL(h, off) \ + (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), ((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf))) + +#define DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h, off) \ + (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), ((h)->offset + (off) <= DUK_HBUFFER_GET_SIZE((h)->buf))) /* Clamp an input byte length (already assumed to be within the nominal * duk_hbufobj 'length') to the current dynamic buffer limits to yield @@ -7526,12 +7962,10 @@ * be invalidated by any side effect because it may trigger a user * callback that resizes the underlying buffer. */ -#define DUK_HBUFOBJ_CLAMP_BYTELENGTH(h,len) \ - (DUK_ASSERT_EXPR((h) != NULL), \ - duk_hbufobj_clamp_bytelength((h), (len))) +#define DUK_HBUFOBJ_CLAMP_BYTELENGTH(h, len) (DUK_ASSERT_EXPR((h) != NULL), duk_hbufobj_clamp_bytelength((h), (len))) /* Typed arrays have virtual indices, ArrayBuffer and DataView do not. */ -#define DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h) ((h)->is_typedarray) +#define DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h) ((h)->is_typedarray) struct duk_hbufobj { /* Shared object part. */ @@ -7556,30 +7990,36 @@ * be dynamic and its pointer unstable. */ - duk_uint_t offset; /* byte offset to buf */ - duk_uint_t length; /* byte index limit for element access, exclusive */ - duk_uint8_t shift; /* element size shift: - * 0 = u8/i8 - * 1 = u16/i16 - * 2 = u32/i32/float - * 3 = double - */ - duk_uint8_t elem_type; /* element type */ + duk_uint_t offset; /* byte offset to buf */ + duk_uint_t length; /* byte index limit for element access, exclusive */ + duk_uint8_t shift; /* element size shift: + * 0 = u8/i8 + * 1 = u16/i16 + * 2 = u32/i32/float + * 3 = double + */ + duk_uint8_t elem_type; /* element type */ duk_uint8_t is_typedarray; }; DUK_INTERNAL_DECL duk_uint_t duk_hbufobj_clamp_bytelength(duk_hbufobj *h_bufobj, duk_uint_t len); DUK_INTERNAL_DECL void duk_hbufobj_push_uint8array_from_plain(duk_hthread *thr, duk_hbuffer *h_buf); -DUK_INTERNAL_DECL void duk_hbufobj_push_validated_read(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size); -DUK_INTERNAL_DECL void duk_hbufobj_validated_write(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size); +DUK_INTERNAL_DECL void duk_hbufobj_push_validated_read(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size); +DUK_INTERNAL_DECL void duk_hbufobj_validated_write(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size); DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_hthread *thr, duk_idx_t idx); -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* nothing */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ -#endif /* DUK_HBUFOBJ_H_INCLUDED */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_HBUFOBJ_H_INCLUDED */ /* #include duk_hthread.h */ /* * Heap thread object representation. @@ -7597,38 +8037,38 @@ */ /* Initial valstack size, roughly 0.7kiB. */ -#define DUK_VALSTACK_INITIAL_SIZE 96U +#define DUK_VALSTACK_INITIAL_SIZE 96U /* Internal extra elements assumed on function entry, always added to * user-defined 'extra' for e.g. the duk_check_stack() call. */ -#define DUK_VALSTACK_INTERNAL_EXTRA 32U +#define DUK_VALSTACK_INTERNAL_EXTRA 32U /* Number of elements guaranteed to be user accessible (in addition to call * arguments) on Duktape/C function entry. This is the major public API * commitment. */ -#define DUK_VALSTACK_API_ENTRY_MINIMUM DUK_API_ENTRY_STACK +#define DUK_VALSTACK_API_ENTRY_MINIMUM DUK_API_ENTRY_STACK /* * Activation defines */ -#define DUK_ACT_FLAG_STRICT (1U << 0) /* function executes in strict mode */ -#define DUK_ACT_FLAG_TAILCALLED (1U << 1) /* activation has tail called one or more times */ -#define DUK_ACT_FLAG_CONSTRUCT (1U << 2) /* function executes as a constructor (called via "new") */ -#define DUK_ACT_FLAG_PREVENT_YIELD (1U << 3) /* activation prevents yield (native call or "new") */ -#define DUK_ACT_FLAG_DIRECT_EVAL (1U << 4) /* activation is a direct eval call */ -#define DUK_ACT_FLAG_CONSTRUCT_PROXY (1U << 5) /* activation is for Proxy 'construct' call, special return value handling */ -#define DUK_ACT_FLAG_BREAKPOINT_ACTIVE (1U << 6) /* activation has active breakpoint(s) */ +#define DUK_ACT_FLAG_STRICT (1U << 0) /* function executes in strict mode */ +#define DUK_ACT_FLAG_TAILCALLED (1U << 1) /* activation has tail called one or more times */ +#define DUK_ACT_FLAG_CONSTRUCT (1U << 2) /* function executes as a constructor (called via "new") */ +#define DUK_ACT_FLAG_PREVENT_YIELD (1U << 3) /* activation prevents yield (native call or "new") */ +#define DUK_ACT_FLAG_DIRECT_EVAL (1U << 4) /* activation is a direct eval call */ +#define DUK_ACT_FLAG_CONSTRUCT_PROXY (1U << 5) /* activation is for Proxy 'construct' call, special return value handling */ +#define DUK_ACT_FLAG_BREAKPOINT_ACTIVE (1U << 6) /* activation has active breakpoint(s) */ -#define DUK_ACT_GET_FUNC(act) ((act)->func) +#define DUK_ACT_GET_FUNC(act) ((act)->func) /* * Flags for __FILE__ / __LINE__ registered into tracedata */ -#define DUK_TB_FLAG_NOBLAME_FILELINE (1U << 0) /* don't report __FILE__ / __LINE__ as fileName/lineNumber */ +#define DUK_TB_FLAG_NOBLAME_FILELINE (1U << 0) /* don't report __FILE__ / __LINE__ as fileName/lineNumber */ /* * Catcher defines @@ -7637,52 +8077,60 @@ /* XXX: remove catcher type entirely */ /* flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits) */ -#define DUK_CAT_TYPE_MASK 0x0000000fUL -#define DUK_CAT_TYPE_BITS 4 -#define DUK_CAT_LABEL_MASK 0xffffff00UL -#define DUK_CAT_LABEL_BITS 24 -#define DUK_CAT_LABEL_SHIFT 8 - -#define DUK_CAT_FLAG_CATCH_ENABLED (1U << 4) /* catch part will catch */ -#define DUK_CAT_FLAG_FINALLY_ENABLED (1U << 5) /* finally part will catch */ -#define DUK_CAT_FLAG_CATCH_BINDING_ENABLED (1U << 6) /* request to create catch binding */ -#define DUK_CAT_FLAG_LEXENV_ACTIVE (1U << 7) /* catch or with binding is currently active */ - -#define DUK_CAT_TYPE_UNKNOWN 0 -#define DUK_CAT_TYPE_TCF 1 -#define DUK_CAT_TYPE_LABEL 2 - -#define DUK_CAT_GET_TYPE(c) ((c)->flags & DUK_CAT_TYPE_MASK) -#define DUK_CAT_GET_LABEL(c) (((c)->flags & DUK_CAT_LABEL_MASK) >> DUK_CAT_LABEL_SHIFT) - -#define DUK_CAT_HAS_CATCH_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_ENABLED) -#define DUK_CAT_HAS_FINALLY_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_FINALLY_ENABLED) -#define DUK_CAT_HAS_CATCH_BINDING_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_BINDING_ENABLED) -#define DUK_CAT_HAS_LEXENV_ACTIVE(c) ((c)->flags & DUK_CAT_FLAG_LEXENV_ACTIVE) +#define DUK_CAT_TYPE_MASK 0x0000000fUL +#define DUK_CAT_TYPE_BITS 4 +#define DUK_CAT_LABEL_MASK 0xffffff00UL +#define DUK_CAT_LABEL_BITS 24 +#define DUK_CAT_LABEL_SHIFT 8 + +#define DUK_CAT_FLAG_CATCH_ENABLED (1U << 4) /* catch part will catch */ +#define DUK_CAT_FLAG_FINALLY_ENABLED (1U << 5) /* finally part will catch */ +#define DUK_CAT_FLAG_CATCH_BINDING_ENABLED (1U << 6) /* request to create catch binding */ +#define DUK_CAT_FLAG_LEXENV_ACTIVE (1U << 7) /* catch or with binding is currently active */ + +#define DUK_CAT_TYPE_UNKNOWN 0 +#define DUK_CAT_TYPE_TCF 1 +#define DUK_CAT_TYPE_LABEL 2 + +#define DUK_CAT_GET_TYPE(c) ((c)->flags & DUK_CAT_TYPE_MASK) +#define DUK_CAT_GET_LABEL(c) (((c)->flags & DUK_CAT_LABEL_MASK) >> DUK_CAT_LABEL_SHIFT) + +#define DUK_CAT_HAS_CATCH_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_ENABLED) +#define DUK_CAT_HAS_FINALLY_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_FINALLY_ENABLED) +#define DUK_CAT_HAS_CATCH_BINDING_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_BINDING_ENABLED) +#define DUK_CAT_HAS_LEXENV_ACTIVE(c) ((c)->flags & DUK_CAT_FLAG_LEXENV_ACTIVE) -#define DUK_CAT_SET_CATCH_ENABLED(c) do { \ +#define DUK_CAT_SET_CATCH_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_CATCH_ENABLED; \ } while (0) -#define DUK_CAT_SET_FINALLY_ENABLED(c) do { \ +#define DUK_CAT_SET_FINALLY_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_FINALLY_ENABLED; \ } while (0) -#define DUK_CAT_SET_CATCH_BINDING_ENABLED(c) do { \ +#define DUK_CAT_SET_CATCH_BINDING_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_CATCH_BINDING_ENABLED; \ } while (0) -#define DUK_CAT_SET_LEXENV_ACTIVE(c) do { \ +#define DUK_CAT_SET_LEXENV_ACTIVE(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_LEXENV_ACTIVE; \ } while (0) -#define DUK_CAT_CLEAR_CATCH_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_CATCH_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_CATCH_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_FINALLY_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_FINALLY_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_FINALLY_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_CATCH_BINDING_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_CATCH_BINDING_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_CATCH_BINDING_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_LEXENV_ACTIVE(c) do { \ +#define DUK_CAT_CLEAR_LEXENV_ACTIVE(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_LEXENV_ACTIVE; \ } while (0) @@ -7691,24 +8139,21 @@ */ #if defined(DUK_USE_ROM_STRINGS) -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) -#else /* DUK_USE_ROM_STRINGS */ +#define DUK_HTHREAD_GET_STRING(thr, idx) ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((thr)->heap->heap_udata, (thr)->strs16(idx))) +#define DUK_HTHREAD_GET_STRING(thr, idx) ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((thr)->heap->heap_udata, (thr)->strs16(idx))) #else -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((thr)->strs(idx)) +#define DUK_HTHREAD_GET_STRING(thr, idx) ((thr)->strs(idx)) #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ /* values for the state field */ -#define DUK_HTHREAD_STATE_INACTIVE 1 /* thread not currently running */ -#define DUK_HTHREAD_STATE_RUNNING 2 /* thread currently running (only one at a time) */ -#define DUK_HTHREAD_STATE_RESUMED 3 /* thread resumed another thread (active but not running) */ -#define DUK_HTHREAD_STATE_YIELDED 4 /* thread has yielded */ -#define DUK_HTHREAD_STATE_TERMINATED 5 /* thread has terminated */ +#define DUK_HTHREAD_STATE_INACTIVE 1 /* thread not currently running */ +#define DUK_HTHREAD_STATE_RUNNING 2 /* thread currently running (only one at a time) */ +#define DUK_HTHREAD_STATE_RESUMED 3 /* thread resumed another thread (active but not running) */ +#define DUK_HTHREAD_STATE_YIELDED 4 /* thread has yielded */ +#define DUK_HTHREAD_STATE_TERMINATED 5 /* thread has terminated */ /* Executor interrupt default interval when nothing else requires a * smaller value. The default interval must be small enough to allow @@ -7716,7 +8161,7 @@ * impact on execution performance low. */ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK_HTHREAD_INTCTR_DEFAULT (256L * 1024L) +#define DUK_HTHREAD_INTCTR_DEFAULT (256L * 1024L) #endif /* @@ -7730,20 +8175,31 @@ #if defined(DUK_USE_ASSERTIONS) /* Assertions for internals. */ DUK_INTERNAL_DECL void duk_hthread_assert_valid(duk_hthread *thr); -#define DUK_HTHREAD_ASSERT_VALID(thr) do { duk_hthread_assert_valid((thr)); } while (0) +#define DUK_HTHREAD_ASSERT_VALID(thr) \ + do { \ + duk_hthread_assert_valid((thr)); \ + } while (0) /* Assertions for public API calls; a bit stronger. */ DUK_INTERNAL_DECL void duk_ctx_assert_valid(duk_hthread *thr); -#define DUK_CTX_ASSERT_VALID(thr) do { duk_ctx_assert_valid((thr)); } while (0) +#define DUK_CTX_ASSERT_VALID(thr) \ + do { \ + duk_ctx_assert_valid((thr)); \ + } while (0) #else -#define DUK_HTHREAD_ASSERT_VALID(thr) do {} while (0) -#define DUK_CTX_ASSERT_VALID(thr) do {} while (0) +#define DUK_HTHREAD_ASSERT_VALID(thr) \ + do { \ + } while (0) +#define DUK_CTX_ASSERT_VALID(thr) \ + do { \ + } while (0) #endif /* Assertions for API call entry specifically. Checks 'ctx' but also may * check internal state (e.g. not in a debugger transport callback). */ -#define DUK_ASSERT_API_ENTRY(thr) do { \ +#define DUK_ASSERT_API_ENTRY(thr) \ + do { \ DUK_CTX_ASSERT_VALID((thr)); \ DUK_ASSERT((thr)->heap != NULL); \ DUK_ASSERT((thr)->heap->dbg_calling_transport == 0); \ @@ -7753,11 +8209,9 @@ * Assertion helpers. */ -#define DUK_ASSERT_STRIDX_VALID(val) \ - DUK_ASSERT((duk_uint_t) (val) < DUK_HEAP_NUM_STRINGS) +#define DUK_ASSERT_STRIDX_VALID(val) DUK_ASSERT((duk_uint_t) (val) < DUK_HEAP_NUM_STRINGS) -#define DUK_ASSERT_BIDX_VALID(val) \ - DUK_ASSERT((duk_uint_t) (val) < DUK_NUM_BUILTINS) +#define DUK_ASSERT_BIDX_VALID(val) DUK_ASSERT((duk_uint_t) (val) < DUK_NUM_BUILTINS) /* * Misc @@ -7765,9 +8219,7 @@ /* Fast access to 'this' binding. Assumes there's a call in progress. */ #define DUK_HTHREAD_THIS_PTR(thr) \ - (DUK_ASSERT_EXPR((thr) != NULL), \ - DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), \ - (thr)->valstack_bottom - 1) + (DUK_ASSERT_EXPR((thr) != NULL), DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), (thr)->valstack_bottom - 1) /* * Struct defines @@ -7775,12 +8227,13 @@ /* Fields are ordered for alignment/packing. */ struct duk_activation { - duk_tval tv_func; /* borrowed: full duk_tval for function being executed; for lightfuncs */ - duk_hobject *func; /* borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs */ + duk_tval tv_func; /* borrowed: full duk_tval for function being executed; for lightfuncs */ + duk_hobject *func; /* borrowed: function being executed; for bound function calls, this is the final, real function, NULL + for lightfuncs */ duk_activation *parent; /* previous (parent) activation (or NULL if none) */ - duk_hobject *var_env; /* current variable environment (may be NULL if delayed) */ - duk_hobject *lex_env; /* current lexical environment (may be NULL if delayed) */ - duk_catcher *cat; /* current catcher (or NULL) */ + duk_hobject *var_env; /* current variable environment (may be NULL if delayed) */ + duk_hobject *lex_env; /* current lexical environment (may be NULL if delayed) */ + duk_catcher *cat; /* current catcher (or NULL) */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) /* Previous value of 'func' caller, restored when unwound. Only in use @@ -7789,7 +8242,7 @@ duk_hobject *prev_caller; #endif - duk_instr_t *curr_pc; /* next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls */ + duk_instr_t *curr_pc; /* next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls */ /* bottom_byteoff and retval_byteoff are only used for book-keeping * of ECMAScript-initiated calls, to allow returning to an ECMAScript @@ -7836,12 +8289,12 @@ }; struct duk_catcher { - duk_catcher *parent; /* previous (parent) catcher (or NULL if none) */ - duk_hstring *h_varname; /* borrowed reference to catch variable name (or NULL if none) */ - /* (reference is valid as long activation exists) */ - duk_instr_t *pc_base; /* resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer) */ - duk_size_t idx_base; /* idx_base and idx_base+1 get completion value and type */ - duk_uint32_t flags; /* type and control flags, label number */ + duk_catcher *parent; /* previous (parent) catcher (or NULL if none) */ + duk_hstring *h_varname; /* borrowed reference to catch variable name (or NULL if none) */ + /* (reference is valid as long activation exists) */ + duk_instr_t *pc_base; /* resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer) */ + duk_size_t idx_base; /* idx_base and idx_base+1 get completion value and type */ + duk_uint32_t flags; /* type and control flags, label number */ /* XXX: could pack 'flags' and 'idx_base' to same value in practice, * on 32-bit targets this would make duk_catcher 16 bytes. */ @@ -7899,21 +8352,21 @@ * yyy = arbitrary values, inside current frame * uuu = outside active value stack, initialized to 'undefined' */ - duk_tval *valstack; /* start of valstack allocation */ - duk_tval *valstack_end; /* end of valstack reservation/guarantee (exclusive) */ - duk_tval *valstack_alloc_end; /* end of valstack allocation */ - duk_tval *valstack_bottom; /* bottom of current frame */ - duk_tval *valstack_top; /* top of current frame (exclusive) */ + duk_tval *valstack; /* start of valstack allocation */ + duk_tval *valstack_end; /* end of valstack reservation/guarantee (exclusive) */ + duk_tval *valstack_alloc_end; /* end of valstack allocation */ + duk_tval *valstack_bottom; /* bottom of current frame */ + duk_tval *valstack_top; /* top of current frame (exclusive) */ /* Call stack, represented as a linked list starting from the current * activation (or NULL if nothing is active). */ - duk_activation *callstack_curr; /* current activation (or NULL if none) */ - duk_size_t callstack_top; /* number of activation records in callstack (0 if none) */ - duk_size_t callstack_preventcount; /* number of activation records in callstack preventing a yield */ + duk_activation *callstack_curr; /* current activation (or NULL if none) */ + duk_size_t callstack_top; /* number of activation records in callstack (0 if none) */ + duk_size_t callstack_preventcount; /* number of activation records in callstack preventing a yield */ /* Yield/resume book-keeping. */ - duk_hthread *resumer; /* who resumed us (if any) */ + duk_hthread *resumer; /* who resumed us (if any) */ /* Current compiler state (if any), used for augmenting SyntaxErrors. */ duk_compiler_ctx *compile_ctx; @@ -7926,8 +8379,8 @@ * important for the counter to be conveniently accessible for the * bytecode executor inner loop for performance reasons. */ - duk_int_t interrupt_counter; /* countdown state */ - duk_int_t interrupt_init; /* start value for current countdown */ + duk_int_t interrupt_counter; /* countdown state */ + duk_int_t interrupt_init; /* start value for current countdown */ #endif /* Builtin-objects; may or may not be shared with other threads, @@ -7979,7 +8432,7 @@ DUK_INTERNAL_DECL void duk_hthread_valstack_torture_realloc(duk_hthread *thr); #endif -DUK_INTERNAL_DECL void *duk_hthread_get_valstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */ +DUK_INTERNAL_DECL void *duk_hthread_get_valstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */ #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_INTERNAL_DECL duk_uint_fast32_t duk_hthread_get_act_curr_pc(duk_hthread *thr, duk_activation *act); @@ -7988,7 +8441,7 @@ DUK_INTERNAL_DECL void duk_hthread_sync_currpc(duk_hthread *thr); DUK_INTERNAL_DECL void duk_hthread_sync_and_null_currpc(duk_hthread *thr); -#endif /* DUK_HTHREAD_H_INCLUDED */ +#endif /* DUK_HTHREAD_H_INCLUDED */ /* #include duk_harray.h */ /* * Array object representation, used for actual Array instances. @@ -8003,15 +8456,26 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_harray_assert_valid(duk_harray *h); -#define DUK_HARRAY_ASSERT_VALID(h) do { duk_harray_assert_valid((h)); } while (0) +#define DUK_HARRAY_ASSERT_VALID(h) \ + do { \ + duk_harray_assert_valid((h)); \ + } while (0) #else -#define DUK_HARRAY_ASSERT_VALID(h) do {} while (0) +#define DUK_HARRAY_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#define DUK_HARRAY_LENGTH_WRITABLE(h) (!(h)->length_nonwritable) -#define DUK_HARRAY_LENGTH_NONWRITABLE(h) ((h)->length_nonwritable) -#define DUK_HARRAY_SET_LENGTH_WRITABLE(h) do { (h)->length_nonwritable = 0; } while (0) -#define DUK_HARRAY_SET_LENGTH_NONWRITABLE(h) do { (h)->length_nonwritable = 1; } while (0) +#define DUK_HARRAY_LENGTH_WRITABLE(h) (!(h)->length_nonwritable) +#define DUK_HARRAY_LENGTH_NONWRITABLE(h) ((h)->length_nonwritable) +#define DUK_HARRAY_SET_LENGTH_WRITABLE(h) \ + do { \ + (h)->length_nonwritable = 0; \ + } while (0) +#define DUK_HARRAY_SET_LENGTH_NONWRITABLE(h) \ + do { \ + (h)->length_nonwritable = 1; \ + } while (0) struct duk_harray { /* Shared object part. */ @@ -8037,7 +8501,7 @@ duk_bool_t length_nonwritable; }; -#endif /* DUK_HARRAY_H_INCLUDED */ +#endif /* DUK_HARRAY_H_INCLUDED */ /* #include duk_henv.h */ /* * Environment object representation. @@ -8049,11 +8513,21 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hdecenv_assert_valid(duk_hdecenv *h); DUK_INTERNAL_DECL void duk_hobjenv_assert_valid(duk_hobjenv *h); -#define DUK_HDECENV_ASSERT_VALID(h) do { duk_hdecenv_assert_valid((h)); } while (0) -#define DUK_HOBJENV_ASSERT_VALID(h) do { duk_hobjenv_assert_valid((h)); } while (0) +#define DUK_HDECENV_ASSERT_VALID(h) \ + do { \ + duk_hdecenv_assert_valid((h)); \ + } while (0) +#define DUK_HOBJENV_ASSERT_VALID(h) \ + do { \ + duk_hobjenv_assert_valid((h)); \ + } while (0) #else -#define DUK_HDECENV_ASSERT_VALID(h) do {} while (0) -#define DUK_HOBJENV_ASSERT_VALID(h) do {} while (0) +#define DUK_HDECENV_ASSERT_VALID(h) \ + do { \ + } while (0) +#define DUK_HOBJENV_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hdecenv { @@ -8083,7 +8557,7 @@ duk_bool_t has_this; }; -#endif /* DUK_HENV_H_INCLUDED */ +#endif /* DUK_HENV_H_INCLUDED */ /* #include duk_hbuffer.h */ /* * Heap buffer representation. @@ -8107,17 +8581,17 @@ * External buffer: DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL */ -#define DUK_HBUFFER_FLAG_DYNAMIC DUK_HEAPHDR_USER_FLAG(0) /* buffer is behind a pointer, dynamic or external */ -#define DUK_HBUFFER_FLAG_EXTERNAL DUK_HEAPHDR_USER_FLAG(1) /* buffer pointer is to an externally allocated buffer */ +#define DUK_HBUFFER_FLAG_DYNAMIC DUK_HEAPHDR_USER_FLAG(0) /* buffer is behind a pointer, dynamic or external */ +#define DUK_HBUFFER_FLAG_EXTERNAL DUK_HEAPHDR_USER_FLAG(1) /* buffer pointer is to an externally allocated buffer */ -#define DUK_HBUFFER_HAS_DYNAMIC(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_HAS_EXTERNAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_HAS_DYNAMIC(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_HAS_EXTERNAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) -#define DUK_HBUFFER_SET_DYNAMIC(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_SET_EXTERNAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_SET_DYNAMIC(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_SET_EXTERNAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) -#define DUK_HBUFFER_CLEAR_DYNAMIC(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_CLEAR_EXTERNAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_CLEAR_DYNAMIC(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_CLEAR_EXTERNAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) /* * Misc defines @@ -8130,12 +8604,12 @@ */ #if defined(DUK_USE_BUFLEN16) -#define DUK_HBUFFER_MAX_BYTELEN (0x0000ffffUL) +#define DUK_HBUFFER_MAX_BYTELEN (0x0000ffffUL) #else /* Intentionally not 0x7fffffffUL; at least JSON code expects that * 2*len + 2 fits in 32 bits. */ -#define DUK_HBUFFER_MAX_BYTELEN (0x7ffffffeUL) +#define DUK_HBUFFER_MAX_BYTELEN (0x7ffffffeUL) #endif /* @@ -8144,60 +8618,70 @@ #if defined(DUK_USE_BUFLEN16) /* size stored in duk_heaphdr unused flag bits */ -#define DUK_HBUFFER_GET_SIZE(x) ((x)->hdr.h_flags >> 16) -#define DUK_HBUFFER_SET_SIZE(x,v) do { \ +#define DUK_HBUFFER_GET_SIZE(x) ((x)->hdr.h_flags >> 16) +#define DUK_HBUFFER_SET_SIZE(x, v) \ + do { \ duk_size_t duk__v; \ duk__v = (v); \ DUK_ASSERT(duk__v <= 0xffffUL); \ (x)->hdr.h_flags = ((x)->hdr.h_flags & 0x0000ffffUL) | (((duk_uint32_t) duk__v) << 16); \ } while (0) -#define DUK_HBUFFER_ADD_SIZE(x,dv) do { \ +#define DUK_HBUFFER_ADD_SIZE(x, dv) \ + do { \ (x)->hdr.h_flags += ((dv) << 16); \ } while (0) -#define DUK_HBUFFER_SUB_SIZE(x,dv) do { \ +#define DUK_HBUFFER_SUB_SIZE(x, dv) \ + do { \ (x)->hdr.h_flags -= ((dv) << 16); \ } while (0) #else -#define DUK_HBUFFER_GET_SIZE(x) (((duk_hbuffer *) (x))->size) -#define DUK_HBUFFER_SET_SIZE(x,v) do { \ +#define DUK_HBUFFER_GET_SIZE(x) (((duk_hbuffer *) (x))->size) +#define DUK_HBUFFER_SET_SIZE(x, v) \ + do { \ ((duk_hbuffer *) (x))->size = (v); \ } while (0) -#define DUK_HBUFFER_ADD_SIZE(x,dv) do { \ +#define DUK_HBUFFER_ADD_SIZE(x, dv) \ + do { \ (x)->size += (dv); \ } while (0) -#define DUK_HBUFFER_SUB_SIZE(x,dv) do { \ +#define DUK_HBUFFER_SUB_SIZE(x, dv) \ + do { \ (x)->size -= (dv); \ } while (0) #endif -#define DUK_HBUFFER_FIXED_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_FIXED_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x)) +#define DUK_HBUFFER_FIXED_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) +#define DUK_HBUFFER_FIXED_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x)) #define DUK_HBUFFER_DYNAMIC_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_DYNAMIC_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) -#define DUK_HBUFFER_DYNAMIC_ADD_SIZE(x,dv) DUK_HBUFFER_ADD_SIZE((duk_hbuffer *) (x), (dv)) -#define DUK_HBUFFER_DYNAMIC_SUB_SIZE(x,dv) DUK_HBUFFER_SUB_SIZE((duk_hbuffer *) (x), (dv)) +#define DUK_HBUFFER_DYNAMIC_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) +#define DUK_HBUFFER_DYNAMIC_ADD_SIZE(x, dv) DUK_HBUFFER_ADD_SIZE((duk_hbuffer *) (x), (dv)) +#define DUK_HBUFFER_DYNAMIC_SUB_SIZE(x, dv) DUK_HBUFFER_SUB_SIZE((duk_hbuffer *) (x), (dv)) #define DUK_HBUFFER_EXTERNAL_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_EXTERNAL_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) +#define DUK_HBUFFER_EXTERNAL_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) -#define DUK_HBUFFER_FIXED_GET_DATA_PTR(heap,x) ((duk_uint8_t *) (((duk_hbuffer_fixed *) (void *) (x)) + 1)) +#define DUK_HBUFFER_FIXED_GET_DATA_PTR(heap, x) ((duk_uint8_t *) (((duk_hbuffer_fixed *) (void *) (x)) + 1)) #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap,x) \ +#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, x) \ ((void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (x))->h_extra16)) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, x, v) \ + do { \ ((duk_heaphdr *) (x))->h_extra16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap,x) do { \ - ((duk_heaphdr *) (x))->h_extra16 = 0; /* assume 0 <=> NULL */ \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap, x) \ + do { \ + ((duk_heaphdr *) (x))->h_extra16 = 0; /* assume 0 <=> NULL */ \ } while (0) #else -#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap,x) ((x)->curr_alloc) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, x) ((x)->curr_alloc) +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #endif @@ -8206,21 +8690,23 @@ * Duktape heap. */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap,x) \ - ((void *) (x)->curr_alloc) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap, x) ((void *) (x)->curr_alloc) +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #else -#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap,x) \ - ((void *) (x)->curr_alloc) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap, x) ((void *) (x)->curr_alloc) +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #endif @@ -8229,32 +8715,31 @@ * size). May be NULL for zero size dynamic/external buffer. */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_GET_DATA_PTR(heap,x) ( \ - DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ - ( \ - DUK_HBUFFER_HAS_EXTERNAL((x)) ? \ - DUK_HBUFFER_EXTERNAL_GET_DATA_PTR((heap), (duk_hbuffer_external *) (x)) : \ - DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) \ - ) : \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x)) \ - ) +#define DUK_HBUFFER_GET_DATA_PTR(heap, x) \ + (DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ + (DUK_HBUFFER_HAS_EXTERNAL((x)) ? DUK_HBUFFER_EXTERNAL_GET_DATA_PTR((heap), (duk_hbuffer_external *) (x)) : \ + DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x))) : \ + DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x))) #else /* Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external * have the same layout so checking for fixed vs. dynamic (or external) is enough. */ -#define DUK_HBUFFER_GET_DATA_PTR(heap,x) ( \ - DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ - DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) : \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x)) \ - ) +#define DUK_HBUFFER_GET_DATA_PTR(heap, x) \ + (DUK_HBUFFER_HAS_DYNAMIC((x)) ? DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) : \ + DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x))) #endif /* Validity assert. */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hbuffer_assert_valid(duk_hbuffer *h); -#define DUK_HBUFFER_ASSERT_VALID(h) do { duk_hbuffer_assert_valid((h)); } while (0) +#define DUK_HBUFFER_ASSERT_VALID(h) \ + do { \ + duk_hbuffer_assert_valid((h)); \ + } while (0) #else -#define DUK_HBUFFER_ASSERT_VALID(h) do {} while (0) +#define DUK_HBUFFER_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -8352,9 +8837,9 @@ */ } #if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_GCC_ATTR) -__attribute__ ((aligned (8))) +__attribute__((aligned(8))) #elif (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_CLANG_ATTR) -__attribute__ ((aligned (8))) +__attribute__((aligned(8))) #endif ; #if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_MSVC_PRAGMA) @@ -8377,7 +8862,7 @@ #if defined(DUK_USE_HEAPPTR16) /* Stored in duk_heaphdr h_extra16. */ #else - void *curr_alloc; /* may be NULL if alloc_size == 0 */ + void *curr_alloc; /* may be NULL if alloc_size == 0 */ #endif /* @@ -8406,7 +8891,7 @@ /* Cannot be compressed as a heap pointer because may point to * an arbitrary address. */ - void *curr_alloc; /* may be NULL if alloc_size == 0 */ + void *curr_alloc; /* may be NULL if alloc_size == 0 */ }; /* @@ -8414,13 +8899,13 @@ */ DUK_INTERNAL_DECL duk_hbuffer *duk_hbuffer_alloc(duk_heap *heap, duk_size_t size, duk_small_uint_t flags, void **out_bufdata); -DUK_INTERNAL_DECL void *duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud); /* indirect allocs */ +DUK_INTERNAL_DECL void *duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud); /* indirect allocs */ /* dynamic buffer ops */ DUK_INTERNAL_DECL void duk_hbuffer_resize(duk_hthread *thr, duk_hbuffer_dynamic *buf, duk_size_t new_size); DUK_INTERNAL_DECL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *buf); -#endif /* DUK_HBUFFER_H_INCLUDED */ +#endif /* DUK_HBUFFER_H_INCLUDED */ /* #include duk_hproxy.h */ /* * Proxy object representation. @@ -8431,9 +8916,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hproxy_assert_valid(duk_hproxy *h); -#define DUK_HPROXY_ASSERT_VALID(h) do { duk_hproxy_assert_valid((h)); } while (0) +#define DUK_HPROXY_ASSERT_VALID(h) \ + do { \ + duk_hproxy_assert_valid((h)); \ + } while (0) #else -#define DUK_HPROXY_ASSERT_VALID(h) do {} while (0) +#define DUK_HPROXY_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hproxy { @@ -8447,7 +8937,7 @@ duk_hobject *handler; }; -#endif /* DUK_HPROXY_H_INCLUDED */ +#endif /* DUK_HPROXY_H_INCLUDED */ /* #include duk_heap.h */ /* * Heap structure. @@ -8465,46 +8955,50 @@ * Heap flags */ -#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED (1U << 0) /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */ -#define DUK_HEAP_FLAG_INTERRUPT_RUNNING (1U << 1) /* executor interrupt running (used to avoid nested interrupts) */ -#define DUK_HEAP_FLAG_FINALIZER_NORESCUE (1U << 2) /* heap destruction ongoing, finalizer rescue no longer possible */ -#define DUK_HEAP_FLAG_DEBUGGER_PAUSED (1U << 3) /* debugger is paused: talk with debug client until step/resume */ - -#define DUK__HEAP_HAS_FLAGS(heap,bits) ((heap)->flags & (bits)) -#define DUK__HEAP_SET_FLAGS(heap,bits) do { \ +#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED \ + (1U << 0) /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */ +#define DUK_HEAP_FLAG_INTERRUPT_RUNNING (1U << 1) /* executor interrupt running (used to avoid nested interrupts) */ +#define DUK_HEAP_FLAG_FINALIZER_NORESCUE (1U << 2) /* heap destruction ongoing, finalizer rescue no longer possible */ +#define DUK_HEAP_FLAG_DEBUGGER_PAUSED (1U << 3) /* debugger is paused: talk with debug client until step/resume */ + +#define DUK__HEAP_HAS_FLAGS(heap, bits) ((heap)->flags & (bits)) +#define DUK__HEAP_SET_FLAGS(heap, bits) \ + do { \ (heap)->flags |= (bits); \ } while (0) -#define DUK__HEAP_CLEAR_FLAGS(heap,bits) do { \ +#define DUK__HEAP_CLEAR_FLAGS(heap, bits) \ + do { \ (heap)->flags &= ~(bits); \ } while (0) -#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_HAS_INTERRUPT_RUNNING(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_HAS_DEBUGGER_PAUSED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) - -#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_SET_INTERRUPT_RUNNING(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_SET_DEBUGGER_PAUSED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) - -#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_CLEAR_INTERRUPT_RUNNING(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_CLEAR_FINALIZER_NORESCUE(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_CLEAR_DEBUGGER_PAUSED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) +#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_HAS_INTERRUPT_RUNNING(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_HAS_DEBUGGER_PAUSED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) + +#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_SET_INTERRUPT_RUNNING(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_SET_DEBUGGER_PAUSED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) + +#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap) \ + DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_CLEAR_INTERRUPT_RUNNING(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_CLEAR_FINALIZER_NORESCUE(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_CLEAR_DEBUGGER_PAUSED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) /* * Longjmp types, also double as identifying continuation type for a rethrow (in 'finally') */ -#define DUK_LJ_TYPE_UNKNOWN 0 /* unused */ -#define DUK_LJ_TYPE_THROW 1 /* value1 -> error object */ -#define DUK_LJ_TYPE_YIELD 2 /* value1 -> yield value, iserror -> error / normal */ -#define DUK_LJ_TYPE_RESUME 3 /* value1 -> resume value, value2 -> resumee thread, iserror -> error/normal */ -#define DUK_LJ_TYPE_BREAK 4 /* value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_CONTINUE 5 /* value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_RETURN 6 /* value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_NORMAL 7 /* no value, pseudo-type to indicate a normal continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_UNKNOWN 0 /* unused */ +#define DUK_LJ_TYPE_THROW 1 /* value1 -> error object */ +#define DUK_LJ_TYPE_YIELD 2 /* value1 -> yield value, iserror -> error / normal */ +#define DUK_LJ_TYPE_RESUME 3 /* value1 -> resume value, value2 -> resumee thread, iserror -> error/normal */ +#define DUK_LJ_TYPE_BREAK 4 /* value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_CONTINUE 5 /* value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_RETURN 6 /* value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_NORMAL 7 /* no value, pseudo-type to indicate a normal continuation (for ENDFIN) */ /* * Mark-and-sweep flags @@ -8517,19 +9011,19 @@ /* Emergency mark-and-sweep: try extra hard, even at the cost of * performance. */ -#define DUK_MS_FLAG_EMERGENCY (1U << 0) +#define DUK_MS_FLAG_EMERGENCY (1U << 0) /* Postpone rescue decisions for reachable objects with FINALIZED set. * Used during finalize_list processing to avoid incorrect rescue * decisions due to finalize_list being a reachability root. */ -#define DUK_MS_FLAG_POSTPONE_RESCUE (1U << 1) +#define DUK_MS_FLAG_POSTPONE_RESCUE (1U << 1) /* Don't compact objects; needed during object property table resize * to prevent a recursive resize. It would suffice to protect only the * current object being resized, but this is not yet implemented. */ -#define DUK_MS_FLAG_NO_OBJECT_COMPACTION (1U << 2) +#define DUK_MS_FLAG_NO_OBJECT_COMPACTION (1U << 2) /* * Thread switching @@ -8540,9 +9034,10 @@ */ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK_HEAP_SWITCH_THREAD(heap,newthr) duk_heap_switch_thread((heap), (newthr)) +#define DUK_HEAP_SWITCH_THREAD(heap, newthr) duk_heap_switch_thread((heap), (newthr)) #else -#define DUK_HEAP_SWITCH_THREAD(heap,newthr) do { \ +#define DUK_HEAP_SWITCH_THREAD(heap, newthr) \ + do { \ (heap)->curr_thread = (newthr); \ } while (0) #endif @@ -8552,11 +9047,14 @@ */ #if defined(DUK_USE_DEBUG) -#define DUK_STATS_INC(heap,fieldname) do { \ +#define DUK_STATS_INC(heap, fieldname) \ + do { \ (heap)->fieldname += 1; \ } while (0) #else -#define DUK_STATS_INC(heap,fieldname) do {} while (0) +#define DUK_STATS_INC(heap, fieldname) \ + do { \ + } while (0) #endif /* @@ -8574,36 +9072,41 @@ * only during init phases). */ #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 12800L /* 50x heap size */ -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L -#else -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 256L /* 1x heap size */ -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 12800L /* 50x heap size */ +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L +#else +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 256L /* 1x heap size */ +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L #endif /* GC torture. */ #if defined(DUK_USE_GC_TORTURE) -#define DUK_GC_TORTURE(heap) do { duk_heap_mark_and_sweep((heap), 0); } while (0) +#define DUK_GC_TORTURE(heap) \ + do { \ + duk_heap_mark_and_sweep((heap), 0); \ + } while (0) #else -#define DUK_GC_TORTURE(heap) do { } while (0) +#define DUK_GC_TORTURE(heap) \ + do { \ + } while (0) #endif /* Stringcache is used for speeding up char-offset-to-byte-offset * translations for non-ASCII strings. */ -#define DUK_HEAP_STRCACHE_SIZE 4 -#define DUK_HEAP_STRINGCACHE_NOCACHE_LIMIT 16 /* strings up to the this length are not cached */ +#define DUK_HEAP_STRCACHE_SIZE 4 +#define DUK_HEAP_STRINGCACHE_NOCACHE_LIMIT 16 /* strings up to the this length are not cached */ /* Some list management macros. */ -#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap,hdr) duk_heap_insert_into_heap_allocated((heap), (hdr)) +#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, hdr) duk_heap_insert_into_heap_allocated((heap), (hdr)) #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAP_REMOVE_FROM_HEAP_ALLOCATED(heap,hdr) duk_heap_remove_from_heap_allocated((heap), (hdr)) +#define DUK_HEAP_REMOVE_FROM_HEAP_ALLOCATED(heap, hdr) duk_heap_remove_from_heap_allocated((heap), (hdr)) #endif #if defined(DUK_USE_FINALIZER_SUPPORT) -#define DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap,hdr) duk_heap_insert_into_finalize_list((heap), (hdr)) -#define DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(heap,hdr) duk_heap_remove_from_finalize_list((heap), (hdr)) +#define DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap, hdr) duk_heap_insert_into_finalize_list((heap), (hdr)) +#define DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(heap, hdr) duk_heap_remove_from_finalize_list((heap), (hdr)) #endif /* @@ -8612,30 +9115,24 @@ /* heap string indices are autogenerated in duk_strings.h */ #if defined(DUK_USE_ROM_STRINGS) -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) -#else /* DUK_USE_ROM_STRINGS */ +#define DUK_HEAP_GET_STRING(heap, idx) ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (heap)->strs16(idx))) +#define DUK_HEAP_GET_STRING(heap, idx) ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (heap)->strs16(idx))) #else -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((heap)->strs(idx)) +#define DUK_HEAP_GET_STRING(heap, idx) ((heap)->strs(idx)) #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ /* * Raw memory calls: relative to heap, but no GC interaction */ -#define DUK_ALLOC_RAW(heap,size) \ - ((heap)->alloc_func((heap)->heap_udata, (size))) +#define DUK_ALLOC_RAW(heap, size) ((heap)->alloc_func((heap)->heap_udata, (size))) -#define DUK_REALLOC_RAW(heap,ptr,newsize) \ - ((heap)->realloc_func((heap)->heap_udata, (void *) (ptr), (newsize))) +#define DUK_REALLOC_RAW(heap, ptr, newsize) ((heap)->realloc_func((heap)->heap_udata, (void *) (ptr), (newsize))) -#define DUK_FREE_RAW(heap,ptr) \ - ((heap)->free_func((heap)->heap_udata, (void *) (ptr))) +#define DUK_FREE_RAW(heap, ptr) ((heap)->free_func((heap)->heap_udata, (void *) (ptr))) /* * Memory calls: relative to heap, GC interaction, but no error throwing. @@ -8668,11 +9165,11 @@ /* callback for indirect reallocs, request for current pointer */ typedef void *(*duk_mem_getptr)(duk_heap *heap, void *ud); -#define DUK_ALLOC(heap,size) duk_heap_mem_alloc((heap), (size)) -#define DUK_ALLOC_ZEROED(heap,size) duk_heap_mem_alloc_zeroed((heap), (size)) -#define DUK_REALLOC(heap,ptr,newsize) duk_heap_mem_realloc((heap), (ptr), (newsize)) -#define DUK_REALLOC_INDIRECT(heap,cb,ud,newsize) duk_heap_mem_realloc_indirect((heap), (cb), (ud), (newsize)) -#define DUK_FREE(heap,ptr) duk_heap_mem_free((heap), (ptr)) +#define DUK_ALLOC(heap, size) duk_heap_mem_alloc((heap), (size)) +#define DUK_ALLOC_ZEROED(heap, size) duk_heap_mem_alloc_zeroed((heap), (size)) +#define DUK_REALLOC(heap, ptr, newsize) duk_heap_mem_realloc((heap), (ptr), (newsize)) +#define DUK_REALLOC_INDIRECT(heap, cb, ud, newsize) duk_heap_mem_realloc_indirect((heap), (cb), (ud), (newsize)) +#define DUK_FREE(heap, ptr) duk_heap_mem_free((heap), (ptr)) /* * Checked allocation, relative to a thread @@ -8681,24 +9178,26 @@ * for convenience. */ -#define DUK_ALLOC_CHECKED(thr,size) duk_heap_mem_alloc_checked((thr), (size)) -#define DUK_ALLOC_CHECKED_ZEROED(thr,size) duk_heap_mem_alloc_checked_zeroed((thr), (size)) -#define DUK_FREE_CHECKED(thr,ptr) duk_heap_mem_free((thr)->heap, (ptr)) +#define DUK_ALLOC_CHECKED(thr, size) duk_heap_mem_alloc_checked((thr), (size)) +#define DUK_ALLOC_CHECKED_ZEROED(thr, size) duk_heap_mem_alloc_checked_zeroed((thr), (size)) +#define DUK_FREE_CHECKED(thr, ptr) duk_heap_mem_free((thr)->heap, (ptr)) /* * Memory constants */ -#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_LIMIT 10 /* Retry allocation after mark-and-sweep for this - * many times. A single mark-and-sweep round is - * not guaranteed to free all unreferenced memory - * because of finalization (in fact, ANY number of - * rounds is strictly not enough). - */ - -#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_EMERGENCY_LIMIT 3 /* Starting from this round, use emergency mode - * for mark-and-sweep. - */ +#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_LIMIT \ + 10 /* Retry allocation after mark-and-sweep for this \ + * many times. A single mark-and-sweep round is \ + * not guaranteed to free all unreferenced memory \ + * because of finalization (in fact, ANY number of \ + * rounds is strictly not enough). \ + */ + +#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_EMERGENCY_LIMIT \ + 3 /* Starting from this round, use emergency mode \ + * for mark-and-sweep. \ + */ /* * Debugger support @@ -8707,26 +9206,26 @@ /* Maximum number of breakpoints. Only breakpoints that are set are * consulted so increasing this has no performance impact. */ -#define DUK_HEAP_MAX_BREAKPOINTS 16 +#define DUK_HEAP_MAX_BREAKPOINTS 16 /* Opcode interval for a Date-based status/peek rate limit check. Only * relevant when debugger is attached. Requesting a timestamp may be a * slow operation on some platforms so this shouldn't be too low. On the * other hand a high value makes Duktape react to a pause request slowly. */ -#define DUK_HEAP_DBG_RATELIMIT_OPCODES 4000 +#define DUK_HEAP_DBG_RATELIMIT_OPCODES 4000 /* Milliseconds between status notify and transport peeks. */ -#define DUK_HEAP_DBG_RATELIMIT_MILLISECS 200 +#define DUK_HEAP_DBG_RATELIMIT_MILLISECS 200 /* Debugger pause flags. */ -#define DUK_PAUSE_FLAG_ONE_OPCODE (1U << 0) /* pause when a single opcode has been executed */ -#define DUK_PAUSE_FLAG_ONE_OPCODE_ACTIVE (1U << 1) /* one opcode pause actually active; artifact of current implementation */ -#define DUK_PAUSE_FLAG_LINE_CHANGE (1U << 2) /* pause when current line number changes */ -#define DUK_PAUSE_FLAG_FUNC_ENTRY (1U << 3) /* pause when entering a function */ -#define DUK_PAUSE_FLAG_FUNC_EXIT (1U << 4) /* pause when exiting current function */ -#define DUK_PAUSE_FLAG_CAUGHT_ERROR (1U << 5) /* pause when about to throw an error that is caught */ -#define DUK_PAUSE_FLAG_UNCAUGHT_ERROR (1U << 6) /* pause when about to throw an error that won't be caught */ +#define DUK_PAUSE_FLAG_ONE_OPCODE (1U << 0) /* pause when a single opcode has been executed */ +#define DUK_PAUSE_FLAG_ONE_OPCODE_ACTIVE (1U << 1) /* one opcode pause actually active; artifact of current implementation */ +#define DUK_PAUSE_FLAG_LINE_CHANGE (1U << 2) /* pause when current line number changes */ +#define DUK_PAUSE_FLAG_FUNC_ENTRY (1U << 3) /* pause when entering a function */ +#define DUK_PAUSE_FLAG_FUNC_EXIT (1U << 4) /* pause when exiting current function */ +#define DUK_PAUSE_FLAG_CAUGHT_ERROR (1U << 5) /* pause when about to throw an error that is caught */ +#define DUK_PAUSE_FLAG_UNCAUGHT_ERROR (1U << 6) /* pause when about to throw an error that won't be caught */ struct duk_breakpoint { duk_hstring *filename; @@ -8754,21 +9253,23 @@ */ struct duk_ljstate { - duk_jmpbuf *jmpbuf_ptr; /* current setjmp() catchpoint */ - duk_small_uint_t type; /* longjmp type */ - duk_bool_t iserror; /* isError flag for yield */ - duk_tval value1; /* 1st related value (type specific) */ - duk_tval value2; /* 2nd related value (type specific) */ + duk_jmpbuf *jmpbuf_ptr; /* current setjmp() catchpoint */ + duk_small_uint_t type; /* longjmp type */ + duk_bool_t iserror; /* isError flag for yield */ + duk_tval value1; /* 1st related value (type specific) */ + duk_tval value2; /* 2nd related value (type specific) */ }; -#define DUK_ASSERT_LJSTATE_UNSET(heap) do { \ +#define DUK_ASSERT_LJSTATE_UNSET(heap) \ + do { \ DUK_ASSERT(heap != NULL); \ DUK_ASSERT(heap->lj.type == DUK_LJ_TYPE_UNKNOWN); \ DUK_ASSERT(heap->lj.iserror == 0); \ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&heap->lj.value1)); \ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&heap->lj.value2)); \ } while (0) -#define DUK_ASSERT_LJSTATE_SET(heap) do { \ +#define DUK_ASSERT_LJSTATE_SET(heap) \ + do { \ DUK_ASSERT(heap != NULL); \ DUK_ASSERT(heap->lj.type != DUK_LJ_TYPE_UNKNOWN); \ } while (0) @@ -8788,9 +9289,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_heap_assert_valid(duk_heap *heap); -#define DUK_HEAP_ASSERT_VALID(heap) do { duk_heap_assert_valid((heap)); } while (0) +#define DUK_HEAP_ASSERT_VALID(heap) \ + do { \ + duk_heap_assert_valid((heap)); \ + } while (0) #else -#define DUK_HEAP_ASSERT_VALID(heap) do {} while (0) +#define DUK_HEAP_ASSERT_VALID(heap) \ + do { \ + } while (0) #endif struct duk_heap { @@ -8944,9 +9450,9 @@ /* Random number state for duk_util_tinyrandom.c. */ #if !defined(DUK_USE_GET_RANDOM_DOUBLE) #if defined(DUK_USE_PREFER_SIZE) || !defined(DUK_USE_64BIT_OPS) - duk_uint32_t rnd_state; /* State for Shamir's three-op algorithm */ + duk_uint32_t rnd_state; /* State for Shamir's three-op algorithm */ #else - duk_uint64_t rnd_state2; /* State for xoroshiro128+ */ + duk_uint64_t rnd_state2; /* State for xoroshiro128+ */ #endif #endif @@ -8969,8 +9475,8 @@ /* Debugger state. */ #if defined(DUK_USE_DEBUGGER_SUPPORT) /* Callbacks and udata; dbg_read_cb != NULL is used to indicate attached state. */ - duk_debug_read_function dbg_read_cb; /* required, NULL implies detached */ - duk_debug_write_function dbg_write_cb; /* required */ + duk_debug_read_function dbg_read_cb; /* required, NULL implies detached */ + duk_debug_write_function dbg_write_cb; /* required */ duk_debug_peek_function dbg_peek_cb; duk_debug_read_flush_function dbg_read_flush_cb; duk_debug_write_flush_function dbg_write_flush_cb; @@ -8979,29 +9485,32 @@ void *dbg_udata; /* The following are only relevant when debugger is attached. */ - duk_bool_t dbg_processing; /* currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval) */ - duk_bool_t dbg_state_dirty; /* resend state next time executor is about to run */ - duk_bool_t dbg_force_restart; /* force executor restart to recheck breakpoints; used to handle function returns (see GH-303) */ - duk_bool_t dbg_detaching; /* debugger detaching; used to avoid calling detach handler recursively */ - duk_small_uint_t dbg_pause_flags; /* flags for automatic pause behavior */ - duk_activation *dbg_pause_act; /* activation related to pause behavior (pause on line change, function entry/exit) */ - duk_uint32_t dbg_pause_startline; /* starting line number for line change related pause behavior */ - duk_breakpoint dbg_breakpointsDUK_HEAP_MAX_BREAKPOINTS; /* breakpoints: 0,breakpoint_count gc reachable */ + duk_bool_t dbg_processing; /* currently processing messages or breakpoints: don't enter message processing recursively (e.g. + no breakpoints when processing debugger eval) */ + duk_bool_t dbg_state_dirty; /* resend state next time executor is about to run */ + duk_bool_t + dbg_force_restart; /* force executor restart to recheck breakpoints; used to handle function returns (see GH-303) */ + duk_bool_t dbg_detaching; /* debugger detaching; used to avoid calling detach handler recursively */ + duk_small_uint_t dbg_pause_flags; /* flags for automatic pause behavior */ + duk_activation *dbg_pause_act; /* activation related to pause behavior (pause on line change, function entry/exit) */ + duk_uint32_t dbg_pause_startline; /* starting line number for line change related pause behavior */ + duk_breakpoint dbg_breakpointsDUK_HEAP_MAX_BREAKPOINTS; /* breakpoints: 0,breakpoint_count gc reachable */ duk_small_uint_t dbg_breakpoint_count; - duk_breakpoint *dbg_breakpoints_activeDUK_HEAP_MAX_BREAKPOINTS + 1; /* currently active breakpoints: NULL term, borrowed pointers */ + duk_breakpoint + *dbg_breakpoints_activeDUK_HEAP_MAX_BREAKPOINTS + 1; /* currently active breakpoints: NULL term, borrowed pointers */ /* XXX: make active breakpoints actual copies instead of pointers? */ /* These are for rate limiting Status notifications and transport peeking. */ - duk_uint_t dbg_exec_counter; /* cumulative opcode execution count (overflows are OK) */ - duk_uint_t dbg_last_counter; /* value of dbg_exec_counter when we last did a Date-based check */ - duk_double_t dbg_last_time; /* time when status/peek was last done (Date-based rate limit) */ + duk_uint_t dbg_exec_counter; /* cumulative opcode execution count (overflows are OK) */ + duk_uint_t dbg_last_counter; /* value of dbg_exec_counter when we last did a Date-based check */ + duk_double_t dbg_last_time; /* time when status/peek was last done (Date-based rate limit) */ /* Used to support single-byte stream lookahead. */ duk_bool_t dbg_have_next_byte; duk_uint8_t dbg_next_byte; -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) - duk_bool_t dbg_calling_transport; /* transport call in progress, calling into Duktape forbidden */ + duk_bool_t dbg_calling_transport; /* transport call in progress, calling into Duktape forbidden */ #endif /* String intern table (weak refs). */ @@ -9010,12 +9519,12 @@ #else duk_hstring **strtable; #endif - duk_uint32_t st_mask; /* mask for lookup, st_size - 1 */ - duk_uint32_t st_size; /* stringtable size */ + duk_uint32_t st_mask; /* mask for lookup, st_size - 1 */ + duk_uint32_t st_size; /* stringtable size */ #if (DUK_USE_STRTAB_MINSIZE != DUK_USE_STRTAB_MAXSIZE) - duk_uint32_t st_count; /* string count for resize load factor checks */ + duk_uint32_t st_count; /* string count for resize load factor checks */ #endif - duk_bool_t st_resizing; /* string table is being resized; avoid recursive resize */ + duk_bool_t st_resizing; /* string table is being resized; avoid recursive resize */ /* String access cache (codepoint offset -> byte offset) for fast string * character looping; 'weak' reference which needs special handling in GC. @@ -9129,7 +9638,9 @@ DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen); DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_checked(duk_hthread *thr, const duk_uint8_t *str, duk_uint32_t len); #if defined(DUK_USE_LITCACHE_SIZE) -DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_literal_checked(duk_hthread *thr, const duk_uint8_t *str, duk_uint32_t blen); +DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_literal_checked(duk_hthread *thr, + const duk_uint8_t *str, + duk_uint32_t blen); #endif DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_u32(duk_heap *heap, duk_uint32_t val); DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_u32_checked(duk_hthread *thr, duk_uint32_t val); @@ -9144,7 +9655,9 @@ #endif DUK_INTERNAL_DECL void duk_heap_strcache_string_remove(duk_heap *heap, duk_hstring *h); -DUK_INTERNAL_DECL duk_uint_fast32_t duk_heap_strcache_offset_char2byte(duk_hthread *thr, duk_hstring *h, duk_uint_fast32_t char_offset); +DUK_INTERNAL_DECL duk_uint_fast32_t duk_heap_strcache_offset_char2byte(duk_hthread *thr, + duk_hstring *h, + duk_uint_fast32_t char_offset); #if defined(DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS) DUK_INTERNAL_DECL void *duk_default_alloc_function(void *udata, duk_size_t size); @@ -9165,13 +9678,13 @@ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL_DECL void duk_heap_run_finalizer(duk_heap *heap, duk_hobject *obj); DUK_INTERNAL_DECL void duk_heap_process_finalize_list(duk_heap *heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL_DECL void duk_heap_mark_and_sweep(duk_heap *heap, duk_small_uint_t flags); DUK_INTERNAL_DECL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len); -#endif /* DUK_HEAP_H_INCLUDED */ +#endif /* DUK_HEAP_H_INCLUDED */ /* #include duk_debugger.h */ #if !defined(DUK_DEBUGGER_H_INCLUDED) #define DUK_DEBUGGER_H_INCLUDED @@ -9179,77 +9692,77 @@ /* Debugger protocol version is defined in the public API header. */ /* Initial bytes for markers. */ -#define DUK_DBG_IB_EOM 0x00 -#define DUK_DBG_IB_REQUEST 0x01 -#define DUK_DBG_IB_REPLY 0x02 -#define DUK_DBG_IB_ERROR 0x03 -#define DUK_DBG_IB_NOTIFY 0x04 +#define DUK_DBG_IB_EOM 0x00 +#define DUK_DBG_IB_REQUEST 0x01 +#define DUK_DBG_IB_REPLY 0x02 +#define DUK_DBG_IB_ERROR 0x03 +#define DUK_DBG_IB_NOTIFY 0x04 /* Other initial bytes. */ -#define DUK_DBG_IB_INT4 0x10 -#define DUK_DBG_IB_STR4 0x11 -#define DUK_DBG_IB_STR2 0x12 -#define DUK_DBG_IB_BUF4 0x13 -#define DUK_DBG_IB_BUF2 0x14 -#define DUK_DBG_IB_UNUSED 0x15 -#define DUK_DBG_IB_UNDEFINED 0x16 -#define DUK_DBG_IB_NULL 0x17 -#define DUK_DBG_IB_TRUE 0x18 -#define DUK_DBG_IB_FALSE 0x19 -#define DUK_DBG_IB_NUMBER 0x1a -#define DUK_DBG_IB_OBJECT 0x1b -#define DUK_DBG_IB_POINTER 0x1c -#define DUK_DBG_IB_LIGHTFUNC 0x1d -#define DUK_DBG_IB_HEAPPTR 0x1e +#define DUK_DBG_IB_INT4 0x10 +#define DUK_DBG_IB_STR4 0x11 +#define DUK_DBG_IB_STR2 0x12 +#define DUK_DBG_IB_BUF4 0x13 +#define DUK_DBG_IB_BUF2 0x14 +#define DUK_DBG_IB_UNUSED 0x15 +#define DUK_DBG_IB_UNDEFINED 0x16 +#define DUK_DBG_IB_NULL 0x17 +#define DUK_DBG_IB_TRUE 0x18 +#define DUK_DBG_IB_FALSE 0x19 +#define DUK_DBG_IB_NUMBER 0x1a +#define DUK_DBG_IB_OBJECT 0x1b +#define DUK_DBG_IB_POINTER 0x1c +#define DUK_DBG_IB_LIGHTFUNC 0x1d +#define DUK_DBG_IB_HEAPPTR 0x1e /* The short string/integer initial bytes starting from 0x60 don't have * defines now. */ /* Error codes. */ -#define DUK_DBG_ERR_UNKNOWN 0x00 -#define DUK_DBG_ERR_UNSUPPORTED 0x01 -#define DUK_DBG_ERR_TOOMANY 0x02 -#define DUK_DBG_ERR_NOTFOUND 0x03 -#define DUK_DBG_ERR_APPLICATION 0x04 +#define DUK_DBG_ERR_UNKNOWN 0x00 +#define DUK_DBG_ERR_UNSUPPORTED 0x01 +#define DUK_DBG_ERR_TOOMANY 0x02 +#define DUK_DBG_ERR_NOTFOUND 0x03 +#define DUK_DBG_ERR_APPLICATION 0x04 /* Commands and notifys initiated by Duktape. */ -#define DUK_DBG_CMD_STATUS 0x01 -#define DUK_DBG_CMD_UNUSED_2 0x02 /* Duktape 1.x: print notify */ -#define DUK_DBG_CMD_UNUSED_3 0x03 /* Duktape 1.x: alert notify */ -#define DUK_DBG_CMD_UNUSED_4 0x04 /* Duktape 1.x: log notify */ -#define DUK_DBG_CMD_THROW 0x05 -#define DUK_DBG_CMD_DETACHING 0x06 -#define DUK_DBG_CMD_APPNOTIFY 0x07 +#define DUK_DBG_CMD_STATUS 0x01 +#define DUK_DBG_CMD_UNUSED_2 0x02 /* Duktape 1.x: print notify */ +#define DUK_DBG_CMD_UNUSED_3 0x03 /* Duktape 1.x: alert notify */ +#define DUK_DBG_CMD_UNUSED_4 0x04 /* Duktape 1.x: log notify */ +#define DUK_DBG_CMD_THROW 0x05 +#define DUK_DBG_CMD_DETACHING 0x06 +#define DUK_DBG_CMD_APPNOTIFY 0x07 /* Commands initiated by debug client. */ -#define DUK_DBG_CMD_BASICINFO 0x10 -#define DUK_DBG_CMD_TRIGGERSTATUS 0x11 -#define DUK_DBG_CMD_PAUSE 0x12 -#define DUK_DBG_CMD_RESUME 0x13 -#define DUK_DBG_CMD_STEPINTO 0x14 -#define DUK_DBG_CMD_STEPOVER 0x15 -#define DUK_DBG_CMD_STEPOUT 0x16 -#define DUK_DBG_CMD_LISTBREAK 0x17 -#define DUK_DBG_CMD_ADDBREAK 0x18 -#define DUK_DBG_CMD_DELBREAK 0x19 -#define DUK_DBG_CMD_GETVAR 0x1a -#define DUK_DBG_CMD_PUTVAR 0x1b -#define DUK_DBG_CMD_GETCALLSTACK 0x1c -#define DUK_DBG_CMD_GETLOCALS 0x1d -#define DUK_DBG_CMD_EVAL 0x1e -#define DUK_DBG_CMD_DETACH 0x1f -#define DUK_DBG_CMD_DUMPHEAP 0x20 -#define DUK_DBG_CMD_GETBYTECODE 0x21 -#define DUK_DBG_CMD_APPREQUEST 0x22 -#define DUK_DBG_CMD_GETHEAPOBJINFO 0x23 -#define DUK_DBG_CMD_GETOBJPROPDESC 0x24 -#define DUK_DBG_CMD_GETOBJPROPDESCRANGE 0x25 +#define DUK_DBG_CMD_BASICINFO 0x10 +#define DUK_DBG_CMD_TRIGGERSTATUS 0x11 +#define DUK_DBG_CMD_PAUSE 0x12 +#define DUK_DBG_CMD_RESUME 0x13 +#define DUK_DBG_CMD_STEPINTO 0x14 +#define DUK_DBG_CMD_STEPOVER 0x15 +#define DUK_DBG_CMD_STEPOUT 0x16 +#define DUK_DBG_CMD_LISTBREAK 0x17 +#define DUK_DBG_CMD_ADDBREAK 0x18 +#define DUK_DBG_CMD_DELBREAK 0x19 +#define DUK_DBG_CMD_GETVAR 0x1a +#define DUK_DBG_CMD_PUTVAR 0x1b +#define DUK_DBG_CMD_GETCALLSTACK 0x1c +#define DUK_DBG_CMD_GETLOCALS 0x1d +#define DUK_DBG_CMD_EVAL 0x1e +#define DUK_DBG_CMD_DETACH 0x1f +#define DUK_DBG_CMD_DUMPHEAP 0x20 +#define DUK_DBG_CMD_GETBYTECODE 0x21 +#define DUK_DBG_CMD_APPREQUEST 0x22 +#define DUK_DBG_CMD_GETHEAPOBJINFO 0x23 +#define DUK_DBG_CMD_GETOBJPROPDESC 0x24 +#define DUK_DBG_CMD_GETOBJPROPDESCRANGE 0x25 /* The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx. * The remaining flags are specific to the debugger. */ -#define DUK_DBG_PROPFLAG_SYMBOL (1U << 8) -#define DUK_DBG_PROPFLAG_HIDDEN (1U << 9) +#define DUK_DBG_PROPFLAG_SYMBOL (1U << 8) +#define DUK_DBG_PROPFLAG_HIDDEN (1U << 9) #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_INTERNAL_DECL void duk_debug_do_detach(duk_heap *heap); @@ -9296,7 +9809,7 @@ #endif DUK_INTERNAL_DECL void duk_debug_write_hobject(duk_hthread *thr, duk_hobject *obj); DUK_INTERNAL_DECL void duk_debug_write_tval(duk_hthread *thr, duk_tval *tv); -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL_DECL void duk_debug_write_request(duk_hthread *thr, duk_small_uint_t command); #endif DUK_INTERNAL_DECL void duk_debug_write_reply(duk_hthread *thr); @@ -9321,9 +9834,9 @@ DUK_INTERNAL_DECL void duk_debug_set_paused(duk_heap *heap); DUK_INTERNAL_DECL void duk_debug_clear_paused(duk_heap *heap); DUK_INTERNAL_DECL void duk_debug_clear_pause_state(duk_heap *heap); -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ -#endif /* DUK_DEBUGGER_H_INCLUDED */ +#endif /* DUK_DEBUGGER_H_INCLUDED */ /* #include duk_debug.h */ /* * Debugging macros, DUK_DPRINT() and its variants in particular. @@ -9355,19 +9868,25 @@ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) #define DUK_D(x) x #else -#define DUK_D(x) do { } while (0) /* omit */ +#define DUK_D(x) \ + do { \ + } while (0) /* omit */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) #define DUK_DD(x) x #else -#define DUK_DD(x) do { } while (0) /* omit */ +#define DUK_DD(x) \ + do { \ + } while (0) /* omit */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) #define DUK_DDD(x) x #else -#define DUK_DDD(x) do { } while (0) /* omit */ +#define DUK_DDD(x) \ + do { \ + } while (0) /* omit */ #endif /* @@ -9379,35 +9898,35 @@ /* Note: combining __FILE__, __LINE__, and __func__ into fmt would be * possible compile time, but waste some space with shared function names. */ -#define DUK__DEBUG_LOG(lev,...) duk_debug_log((duk_int_t) (lev), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, DUK_FUNC_MACRO, __VA_ARGS__); +#define DUK__DEBUG_LOG(lev, ...) \ + duk_debug_log((duk_int_t) (lev), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, DUK_FUNC_MACRO, __VA_ARGS__); #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) -#define DUK_DPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DEBUG, __VA_ARGS__) +#define DUK_DPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DEBUG, __VA_ARGS__) #else #define DUK_DPRINT(...) #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) -#define DUK_DDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDEBUG, __VA_ARGS__) +#define DUK_DDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDEBUG, __VA_ARGS__) #else #define DUK_DDPRINT(...) #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK_DDDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDDEBUG, __VA_ARGS__) +#define DUK_DDDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDDEBUG, __VA_ARGS__) #else #define DUK_DDDPRINT(...) #endif -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ -#define DUK__DEBUG_STASH(lev) \ +#define DUK__DEBUG_STASH(lev) \ (void) DUK_SNPRINTF(duk_debug_file_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FILE_MACRO), \ - (void) (duk_debug_file_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ - (void) (duk_debug_line_stash = (duk_int_t) DUK_LINE_MACRO), \ - (void) DUK_SNPRINTF(duk_debug_func_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FUNC_MACRO), \ - (void) (duk_debug_func_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ - (void) (duk_debug_level_stash = (lev)) + (void) (duk_debug_file_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ + (void) (duk_debug_line_stash = (duk_int_t) DUK_LINE_MACRO), \ + (void) DUK_SNPRINTF(duk_debug_func_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FUNC_MACRO), \ + (void) (duk_debug_func_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), (void) (duk_debug_level_stash = (lev)) /* Without variadic macros resort to comma expression trickery to handle debug * prints. This generates a lot of harmless warnings. These hacks are not @@ -9416,34 +9935,40 @@ */ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) -#define DUK_DPRINT DUK__DEBUG_STASH(DUK_LEVEL_DEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DPRINT DUK__DEBUG_STASH(DUK_LEVEL_DEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ +#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) -#define DUK_DDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DDPRINT 0 && /* args */ +#define DUK_DDPRINT 0 && /* args */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK_DDDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDDEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DDDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDDEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DDDPRINT 0 && /* args */ +#define DUK_DDDPRINT 0 && /* args */ #endif -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#else /* DUK_USE_DEBUG */ +#else /* DUK_USE_DEBUG */ /* * Exposed debug macros: debugging disabled */ -#define DUK_D(x) do { } while (0) /* omit */ -#define DUK_DD(x) do { } while (0) /* omit */ -#define DUK_DDD(x) do { } while (0) /* omit */ +#define DUK_D(x) \ + do { \ + } while (0) /* omit */ +#define DUK_DD(x) \ + do { \ + } while (0) /* omit */ +#define DUK_DDD(x) \ + do { \ + } while (0) /* omit */ #if defined(DUK_USE_VARIADIC_MACROS) @@ -9451,15 +9976,15 @@ #define DUK_DDPRINT(...) #define DUK_DDDPRINT(...) -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ -#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ -#define DUK_DDPRINT 0 && /* args */ -#define DUK_DDDPRINT 0 && /* args */ +#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ +#define DUK_DDPRINT 0 && /* args */ +#define DUK_DDDPRINT 0 && /* args */ -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Structs @@ -9480,16 +10005,16 @@ #if defined(DUK_USE_DEBUG) DUK_INTERNAL_DECL duk_int_t duk_debug_vsnprintf(char *str, duk_size_t size, const char *format, va_list ap); -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL duk_int_t duk_debug_snprintf(char *str, duk_size_t size, const char *format, ...); #endif DUK_INTERNAL_DECL void duk_debug_format_funcptr(char *buf, duk_size_t buf_size, duk_uint8_t *fptr, duk_size_t fptr_size); #if defined(DUK_USE_VARIADIC_MACROS) DUK_INTERNAL_DECL void duk_debug_log(duk_int_t level, const char *file, duk_int_t line, const char *func, const char *fmt, ...); -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ /* parameter passing, not thread safe */ -#define DUK_DEBUG_STASH_SIZE 128 +#define DUK_DEBUG_STASH_SIZE 128 #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL char duk_debug_file_stashDUK_DEBUG_STASH_SIZE; DUK_INTERNAL_DECL duk_int_t duk_debug_line_stash; @@ -9497,7 +10022,7 @@ DUK_INTERNAL_DECL duk_int_t duk_debug_level_stash; #endif DUK_INTERNAL_DECL void duk_debug_log(const char *fmt, ...); -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ DUK_INTERNAL_DECL void duk_fb_put_bytes(duk_fixedbuffer *fb, const duk_uint8_t *buffer, duk_size_t length); DUK_INTERNAL_DECL void duk_fb_put_byte(duk_fixedbuffer *fb, duk_uint8_t x); @@ -9506,9 +10031,9 @@ DUK_INTERNAL_DECL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size); DUK_INTERNAL_DECL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb); -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ -#endif /* DUK_DEBUG_H_INCLUDED */ +#endif /* DUK_DEBUG_H_INCLUDED */ /* #include duk_error.h */ /* * Error handling macros, assertion macro, error codes. @@ -9565,79 +10090,153 @@ /* Because there are quite many call sites, pack error code (require at most * 8-bit) into a single argument. */ -#define DUK_ERROR(thr,err,msg) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ +#define DUK_ERROR(thr, err, msg) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ duk_err_handle_error((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (msg)); \ } while (0) -#define DUK_ERROR_RAW(thr,file,line,err,msg) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ +#define DUK_ERROR_RAW(thr, file, line, err, msg) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ duk_err_handle_error((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (msg)); \ } while (0) -#define DUK_ERROR_FMT1(thr,err,fmt,arg1) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1)); \ - } while (0) -#define DUK_ERROR_RAW_FMT1(thr,file,line,err,fmt,arg1) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1)); \ - } while (0) - -#define DUK_ERROR_FMT2(thr,err,fmt,arg1,arg2) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2)); \ - } while (0) -#define DUK_ERROR_RAW_FMT2(thr,file,line,err,fmt,arg1,arg2) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2)); \ - } while (0) - -#define DUK_ERROR_FMT3(thr,err,fmt,arg1,arg2,arg3) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3)); \ - } while (0) -#define DUK_ERROR_RAW_FMT3(thr,file,line,err,fmt,arg1,arg2,arg3) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3)); \ - } while (0) - -#define DUK_ERROR_FMT4(thr,err,fmt,arg1,arg2,arg3,arg4) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3), (arg4)); \ - } while (0) -#define DUK_ERROR_RAW_FMT4(thr,file,line,err,fmt,arg1,arg2,arg3,arg4) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3), (arg4)); \ - } while (0) - -#else /* DUK_USE_VERBOSE_ERRORS */ - -#define DUK_ERROR(thr,err,msg) duk_err_handle_error((thr), (err)) -#define DUK_ERROR_RAW(thr,file,line,err,msg) duk_err_handle_error((thr), (err)) +#define DUK_ERROR_FMT1(thr, err, fmt, arg1) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1)); \ + } while (0) +#define DUK_ERROR_RAW_FMT1(thr, file, line, err, fmt, arg1) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1)); \ + } while (0) + +#define DUK_ERROR_FMT2(thr, err, fmt, arg1, arg2) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2)); \ + } while (0) +#define DUK_ERROR_RAW_FMT2(thr, file, line, err, fmt, arg1, arg2) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2)); \ + } while (0) + +#define DUK_ERROR_FMT3(thr, err, fmt, arg1, arg2, arg3) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3)); \ + } while (0) +#define DUK_ERROR_RAW_FMT3(thr, file, line, err, fmt, arg1, arg2, arg3) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3)); \ + } while (0) + +#define DUK_ERROR_FMT4(thr, err, fmt, arg1, arg2, arg3, arg4) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3), \ + (arg4)); \ + } while (0) +#define DUK_ERROR_RAW_FMT4(thr, file, line, err, fmt, arg1, arg2, arg3, arg4) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3), \ + (arg4)); \ + } while (0) + +#else /* DUK_USE_VERBOSE_ERRORS */ + +#define DUK_ERROR(thr, err, msg) duk_err_handle_error((thr), (err)) +#define DUK_ERROR_RAW(thr, file, line, err, msg) duk_err_handle_error((thr), (err)) + +#define DUK_ERROR_FMT1(thr, err, fmt, arg1) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT1(thr, file, line, err, fmt, arg1) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) + +#define DUK_ERROR_FMT2(thr, err, fmt, arg1, arg2) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT2(thr, file, line, err, fmt, arg1, arg2) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) -#define DUK_ERROR_FMT1(thr,err,fmt,arg1) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT1(thr,file,line,err,fmt,arg1) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) +#define DUK_ERROR_FMT3(thr, err, fmt, arg1, arg2, arg3) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT3(thr, file, line, err, fmt, arg1, arg2, arg3) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) -#define DUK_ERROR_FMT2(thr,err,fmt,arg1,arg2) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT2(thr,file,line,err,fmt,arg1,arg2) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) +#define DUK_ERROR_FMT4(thr, err, fmt, arg1, arg2, arg3, arg4) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT4(thr, file, line, err, fmt, arg1, arg2, arg3, arg4) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) -#define DUK_ERROR_FMT3(thr,err,fmt,arg1,arg2,arg3) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT3(thr,file,line,err,fmt,arg1,arg2,arg3) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#define DUK_ERROR_FMT4(thr,err,fmt,arg1,arg2,arg3,arg4) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT4(thr,file,line,err,fmt,arg1,arg2,arg3,arg4) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Fatal error without context @@ -9645,8 +10244,7 @@ * The macro is an expression to make it compatible with DUK_ASSERT_EXPR(). */ -#define DUK_FATAL_WITHOUT_CONTEXT(msg) \ - duk_default_fatal_handler(NULL, (msg)) +#define DUK_FATAL_WITHOUT_CONTEXT(msg) duk_default_fatal_handler(NULL, (msg)) /* * Error throwing helpers @@ -9671,196 +10269,252 @@ * vs. non-paranoid distinction affects only a few specific errors. */ #if defined(DUK_USE_PARANOID_ERRORS) -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_require_type_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx), (expectname)); \ } while (0) -#else /* DUK_USE_PARANOID_ERRORS */ -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#else /* DUK_USE_PARANOID_ERRORS */ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_require_type_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx), (expectname)); \ } while (0) -#endif /* DUK_USE_PARANOID_ERRORS */ +#endif /* DUK_USE_PARANOID_ERRORS */ -#define DUK_ERROR_INTERNAL(thr) do { \ +#define DUK_ERROR_INTERNAL(thr) \ + do { \ duk_err_error_internal((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_INTERNAL(thr) do { \ +#define DUK_DCERROR_INTERNAL(thr) \ + do { \ DUK_ERROR_INTERNAL((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_ALLOC_FAILED(thr) do { \ +#define DUK_ERROR_ALLOC_FAILED(thr) \ + do { \ duk_err_error_alloc_failed((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_ERROR_UNSUPPORTED(thr) do { \ +#define DUK_ERROR_UNSUPPORTED(thr) \ + do { \ DUK_ERROR((thr), DUK_ERR_ERROR, DUK_STR_UNSUPPORTED); \ } while (0) -#define DUK_DCERROR_UNSUPPORTED(thr) do { \ +#define DUK_DCERROR_UNSUPPORTED(thr) \ + do { \ DUK_ERROR_UNSUPPORTED((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_ERROR(thr,msg) do { \ +#define DUK_ERROR_ERROR(thr, msg) \ + do { \ duk_err_error((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \ } while (0) -#define DUK_ERROR_RANGE_INDEX(thr,idx) do { \ +#define DUK_ERROR_RANGE_INDEX(thr, idx) \ + do { \ duk_err_range_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx)); \ } while (0) -#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) do { \ +#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) \ + do { \ duk_err_range_push_beyond((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_ERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_ARGS); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_ARGS((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_COUNT); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_COUNT((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_LENGTH); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_LENGTH((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE(thr,msg) do { \ +#define DUK_ERROR_RANGE(thr, msg) \ + do { \ duk_err_range((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \ } while (0) -#define DUK_ERROR_EVAL(thr,msg) do { \ +#define DUK_ERROR_EVAL(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_EVAL_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_REFERENCE(thr,msg) do { \ +#define DUK_ERROR_REFERENCE(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_REFERENCE_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_SYNTAX(thr,msg) do { \ +#define DUK_ERROR_SYNTAX(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_SYNTAX_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_ARGS(thr) \ + do { \ duk_err_type_invalid_args((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_TYPE_INVALID_ARGS((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type_invalid_state((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_STATE(thr) \ + do { \ DUK_ERROR_TYPE_INVALID_STATE((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type_invalid_trap_result((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ DUK_ERROR_TYPE((thr), DUK_STR_INVALID_TRAP_RESULT); \ } while (0) -#define DUK_ERROR_TYPE(thr,msg) do { \ +#define DUK_ERROR_TYPE(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_TYPE_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_URI(thr,msg) do { \ +#define DUK_ERROR_URI(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_URI_ERROR, (msg)); \ } while (0) -#else /* DUK_USE_VERBOSE_ERRORS */ +#else /* DUK_USE_VERBOSE_ERRORS */ /* Non-verbose errors for low memory targets: no file, line, or message. */ -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_INTERNAL(thr) do { \ +#define DUK_ERROR_INTERNAL(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_DCERROR_INTERNAL(thr) do { \ +#define DUK_DCERROR_INTERNAL(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_ERROR; \ } while (0) -#define DUK_ERROR_ALLOC_FAILED(thr) do { \ +#define DUK_ERROR_ALLOC_FAILED(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_ERROR_UNSUPPORTED(thr) do { \ +#define DUK_ERROR_UNSUPPORTED(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_DCERROR_UNSUPPORTED(thr) do { \ +#define DUK_DCERROR_UNSUPPORTED(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_ERROR; \ } while (0) -#define DUK_ERROR_ERROR(thr,msg) do { \ +#define DUK_ERROR_ERROR(thr, msg) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_ERROR_RANGE_INDEX(thr,idx) do { \ +#define DUK_ERROR_RANGE_INDEX(thr, idx) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) do { \ +#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_ARGS(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_COUNT(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE(thr,msg) do { \ +#define DUK_ERROR_RANGE(thr, msg) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_EVAL(thr,msg) do { \ +#define DUK_ERROR_EVAL(thr, msg) \ + do { \ duk_err_eval((thr)); \ } while (0) -#define DUK_ERROR_REFERENCE(thr,msg) do { \ +#define DUK_ERROR_REFERENCE(thr, msg) \ + do { \ duk_err_reference((thr)); \ } while (0) -#define DUK_ERROR_SYNTAX(thr,msg) do { \ +#define DUK_ERROR_SYNTAX(thr, msg) \ + do { \ duk_err_syntax((thr)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_ARGS(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_TYPE_ERROR; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_TYPE_ERROR; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_TYPE(thr,msg) do { \ +#define DUK_ERROR_TYPE(thr, msg) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_URI(thr,msg) do { \ +#define DUK_ERROR_URI(thr, msg) \ + do { \ duk_err_uri((thr)); \ } while (0) -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Assert macro: failure causes a fatal error. @@ -9878,63 +10532,72 @@ * we don't care about assertion text size because they're not used in production * builds. */ -#define DUK_ASSERT(x) do { \ - if (!(x)) { \ - DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x \ - " (" DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"); \ - } \ +#define DUK_ASSERT(x) \ + do { \ + if (!(x)) { \ + DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x " (" DUK_FILE_MACRO \ + ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"); \ + } \ } while (0) /* Assertion compatible inside a comma expression, evaluates to void. */ #define DUK_ASSERT_EXPR(x) \ - ((void) ((x) ? 0 : (DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x \ - " (" DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"), 0))) + ((void) ((x) ? 0 : \ + (DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x " (" DUK_FILE_MACRO \ + ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"), \ + 0))) -#else /* DUK_USE_ASSERTIONS */ +#else /* DUK_USE_ASSERTIONS */ -#define DUK_ASSERT(x) do { /* assertion omitted */ } while (0) +#define DUK_ASSERT(x) \ + do { /* assertion omitted */ \ + } while (0) -#define DUK_ASSERT_EXPR(x) ((void) 0) +#define DUK_ASSERT_EXPR(x) ((void) 0) -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* this variant is used when an assert would generate a compile warning by * being always true (e.g. >= 0 comparison for an unsigned value */ -#define DUK_ASSERT_DISABLE(x) do { /* assertion disabled */ } while (0) +#define DUK_ASSERT_DISABLE(x) \ + do { /* assertion disabled */ \ + } while (0) /* * Assertion helpers */ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) do { \ +#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) \ + do { \ DUK_ASSERT((h) == NULL || DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) (h)) > 0); \ } while (0) -#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) do { \ +#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) \ + do { \ if ((tv) != NULL && DUK_TVAL_IS_HEAP_ALLOCATED((tv))) { \ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(DUK_TVAL_GET_HEAPHDR((tv))) > 0); \ } \ } while (0) #else -#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) /* no refcount check */ -#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) /* no refcount check */ +#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) /* no refcount check */ +#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) /* no refcount check */ #endif -#define DUK_ASSERT_TOP(ctx,n) DUK_ASSERT((duk_idx_t) duk_get_top((ctx)) == (duk_idx_t) (n)) +#define DUK_ASSERT_TOP(ctx, n) DUK_ASSERT((duk_idx_t) duk_get_top((ctx)) == (duk_idx_t) (n)) #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_PACKED_TVAL) -#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) do { \ +#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) \ + do { \ duk_double_union duk__assert_tmp_du; \ duk__assert_tmp_du.d = (dval); \ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&duk__assert_tmp_du)); \ } while (0) #else -#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) /* nop */ +#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) /* nop */ #endif -#define DUK_ASSERT_VS_SPACE(thr) \ - DUK_ASSERT(thr->valstack_top < thr->valstack_end) +#define DUK_ASSERT_VS_SPACE(thr) DUK_ASSERT(thr->valstack_top < thr->valstack_end) /* * Helper to initialize a memory area (e.g. struct) with garbage when @@ -9942,11 +10605,14 @@ */ #if defined(DUK_USE_ASSERTIONS) -#define DUK_ASSERT_SET_GARBAGE(ptr,size) do { \ +#define DUK_ASSERT_SET_GARBAGE(ptr, size) \ + do { \ duk_memset_unsafe((void *) (ptr), 0x5a, size); \ } while (0) #else -#define DUK_ASSERT_SET_GARBAGE(ptr,size) do {} while (0) +#define DUK_ASSERT_SET_GARBAGE(ptr, size) \ + do { \ + } while (0) #endif /* @@ -9957,16 +10623,18 @@ * or (b) Duktape calls which involve extending the valstack (e.g. getter call). */ -#define DUK_VALSTACK_ASSERT_EXTRA 5 /* this is added to checks to allow for Duktape - * API calls in addition to function's own use - */ +#define DUK_VALSTACK_ASSERT_EXTRA \ + 5 /* this is added to checks to allow for Duktape \ + * API calls in addition to function's own use \ + */ #if defined(DUK_USE_ASSERTIONS) -#define DUK_ASSERT_VALSTACK_SPACE(thr,n) do { \ +#define DUK_ASSERT_VALSTACK_SPACE(thr, n) \ + do { \ DUK_ASSERT((thr) != NULL); \ DUK_ASSERT((thr)->valstack_end - (thr)->valstack_top >= (n) + DUK_VALSTACK_ASSERT_EXTRA); \ } while (0) #else -#define DUK_ASSERT_VALSTACK_SPACE(thr,n) /* no valstack space check */ +#define DUK_ASSERT_VALSTACK_SPACE(thr, n) /* no valstack space check */ #endif /* @@ -9974,25 +10642,35 @@ */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...)); -#else /* DUK_USE_VERBOSE_ERRORS */ +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg)); +DUK_NORETURN(DUK_INTERNAL_DECL void + duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...)); +#else /* DUK_USE_VERBOSE_ERRORS */ DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, duk_errcode_t code)); -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code, const char *msg, const char *filename, duk_int_t line)); +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, + duk_errcode_t code, + const char *msg, + const char *filename, + duk_int_t line)); #else DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code)); #endif DUK_NORETURN(DUK_INTERNAL_DECL void duk_error_throw_from_negative_rc(duk_hthread *thr, duk_ret_t rc)); -#define DUK_AUGMENT_FLAG_NOBLAME_FILELINE (1U << 0) /* if set, don't blame C file/line for .fileName and .lineNumber */ -#define DUK_AUGMENT_FLAG_SKIP_ONE (1U << 1) /* if set, skip topmost activation in traceback construction */ +#define DUK_AUGMENT_FLAG_NOBLAME_FILELINE (1U << 0) /* if set, don't blame C file/line for .fileName and .lineNumber */ +#define DUK_AUGMENT_FLAG_SKIP_ONE (1U << 1) /* if set, skip topmost activation in traceback construction */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *filename, duk_int_t line, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *filename, + duk_int_t line, + duk_small_uint_t flags); #endif #if defined(DUK_USE_AUGMENT_ERROR_THROW) DUK_INTERNAL_DECL void duk_err_augment_error_throw(duk_hthread *thr); @@ -10000,20 +10678,31 @@ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name)); -#else -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name)); +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name)); +#else +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name)); #endif DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error_alloc_failed(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_range_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range_push_beyond(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_args(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_state(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_trap_result(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -#else /* DUK_VERBOSE_ERRORS */ +#else /* DUK_VERBOSE_ERRORS */ DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_eval(duk_hthread *thr)); @@ -10034,7 +10723,7 @@ DUK_INTERNAL_DECL duk_hobject *duk_error_prototype_from_code(duk_hthread *thr, duk_errcode_t err_code); -#endif /* DUK_ERROR_H_INCLUDED */ +#endif /* DUK_ERROR_H_INCLUDED */ /* #include duk_unicode.h */ /* * Unicode helpers @@ -10047,10 +10736,10 @@ * UTF-8 / XUTF-8 / CESU-8 constants */ -#define DUK_UNICODE_MAX_XUTF8_LENGTH 7 /* up to 36 bit codepoints */ -#define DUK_UNICODE_MAX_XUTF8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ -#define DUK_UNICODE_MAX_CESU8_LENGTH 6 /* all codepoints up to U+10FFFF */ -#define DUK_UNICODE_MAX_CESU8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ +#define DUK_UNICODE_MAX_XUTF8_LENGTH 7 /* up to 36 bit codepoints */ +#define DUK_UNICODE_MAX_XUTF8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ +#define DUK_UNICODE_MAX_CESU8_LENGTH 6 /* all codepoints up to U+10FFFF */ +#define DUK_UNICODE_MAX_CESU8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ /* * Useful Unicode codepoints @@ -10059,9 +10748,11 @@ * in comparisons. */ -#define DUK_UNICODE_CP_ZWNJ 0x200cL /* zero-width non-joiner */ -#define DUK_UNICODE_CP_ZWJ 0x200dL /* zero-width joiner */ -#define DUK_UNICODE_CP_REPLACEMENT_CHARACTER 0xfffdL /* http://en.wikipedia.org/wiki/Replacement_character#Replacement_character */ +#define DUK_UNICODE_CP_ZWNJ 0x200cL /* zero-width non-joiner */ +#define DUK_UNICODE_CP_ZWJ 0x200dL /* zero-width joiner */ +#define DUK_UNICODE_CP_REPLACEMENT_CHARACTER \ + 0xfffdL /* http://en.wikipedia.org/wiki/Replacement_character#Replacement_character \ + */ /* * ASCII character constants @@ -10074,134 +10765,134 @@ * http://en.wikipedia.org/wiki/ASCII */ -#define DUK_ASC_NUL 0x00 -#define DUK_ASC_SOH 0x01 -#define DUK_ASC_STX 0x02 -#define DUK_ASC_ETX 0x03 -#define DUK_ASC_EOT 0x04 -#define DUK_ASC_ENQ 0x05 -#define DUK_ASC_ACK 0x06 -#define DUK_ASC_BEL 0x07 -#define DUK_ASC_BS 0x08 -#define DUK_ASC_HT 0x09 -#define DUK_ASC_LF 0x0a -#define DUK_ASC_VT 0x0b -#define DUK_ASC_FF 0x0c -#define DUK_ASC_CR 0x0d -#define DUK_ASC_SO 0x0e -#define DUK_ASC_SI 0x0f -#define DUK_ASC_DLE 0x10 -#define DUK_ASC_DC1 0x11 -#define DUK_ASC_DC2 0x12 -#define DUK_ASC_DC3 0x13 -#define DUK_ASC_DC4 0x14 -#define DUK_ASC_NAK 0x15 -#define DUK_ASC_SYN 0x16 -#define DUK_ASC_ETB 0x17 -#define DUK_ASC_CAN 0x18 -#define DUK_ASC_EM 0x19 -#define DUK_ASC_SUB 0x1a -#define DUK_ASC_ESC 0x1b -#define DUK_ASC_FS 0x1c -#define DUK_ASC_GS 0x1d -#define DUK_ASC_RS 0x1e -#define DUK_ASC_US 0x1f -#define DUK_ASC_SPACE 0x20 -#define DUK_ASC_EXCLAMATION 0x21 -#define DUK_ASC_DOUBLEQUOTE 0x22 -#define DUK_ASC_HASH 0x23 -#define DUK_ASC_DOLLAR 0x24 -#define DUK_ASC_PERCENT 0x25 -#define DUK_ASC_AMP 0x26 -#define DUK_ASC_SINGLEQUOTE 0x27 -#define DUK_ASC_LPAREN 0x28 -#define DUK_ASC_RPAREN 0x29 -#define DUK_ASC_STAR 0x2a -#define DUK_ASC_PLUS 0x2b -#define DUK_ASC_COMMA 0x2c -#define DUK_ASC_MINUS 0x2d -#define DUK_ASC_PERIOD 0x2e -#define DUK_ASC_SLASH 0x2f -#define DUK_ASC_0 0x30 -#define DUK_ASC_1 0x31 -#define DUK_ASC_2 0x32 -#define DUK_ASC_3 0x33 -#define DUK_ASC_4 0x34 -#define DUK_ASC_5 0x35 -#define DUK_ASC_6 0x36 -#define DUK_ASC_7 0x37 -#define DUK_ASC_8 0x38 -#define DUK_ASC_9 0x39 -#define DUK_ASC_COLON 0x3a -#define DUK_ASC_SEMICOLON 0x3b -#define DUK_ASC_LANGLE 0x3c -#define DUK_ASC_EQUALS 0x3d -#define DUK_ASC_RANGLE 0x3e -#define DUK_ASC_QUESTION 0x3f -#define DUK_ASC_ATSIGN 0x40 -#define DUK_ASC_UC_A 0x41 -#define DUK_ASC_UC_B 0x42 -#define DUK_ASC_UC_C 0x43 -#define DUK_ASC_UC_D 0x44 -#define DUK_ASC_UC_E 0x45 -#define DUK_ASC_UC_F 0x46 -#define DUK_ASC_UC_G 0x47 -#define DUK_ASC_UC_H 0x48 -#define DUK_ASC_UC_I 0x49 -#define DUK_ASC_UC_J 0x4a -#define DUK_ASC_UC_K 0x4b -#define DUK_ASC_UC_L 0x4c -#define DUK_ASC_UC_M 0x4d -#define DUK_ASC_UC_N 0x4e -#define DUK_ASC_UC_O 0x4f -#define DUK_ASC_UC_P 0x50 -#define DUK_ASC_UC_Q 0x51 -#define DUK_ASC_UC_R 0x52 -#define DUK_ASC_UC_S 0x53 -#define DUK_ASC_UC_T 0x54 -#define DUK_ASC_UC_U 0x55 -#define DUK_ASC_UC_V 0x56 -#define DUK_ASC_UC_W 0x57 -#define DUK_ASC_UC_X 0x58 -#define DUK_ASC_UC_Y 0x59 -#define DUK_ASC_UC_Z 0x5a -#define DUK_ASC_LBRACKET 0x5b -#define DUK_ASC_BACKSLASH 0x5c -#define DUK_ASC_RBRACKET 0x5d -#define DUK_ASC_CARET 0x5e -#define DUK_ASC_UNDERSCORE 0x5f -#define DUK_ASC_GRAVE 0x60 -#define DUK_ASC_LC_A 0x61 -#define DUK_ASC_LC_B 0x62 -#define DUK_ASC_LC_C 0x63 -#define DUK_ASC_LC_D 0x64 -#define DUK_ASC_LC_E 0x65 -#define DUK_ASC_LC_F 0x66 -#define DUK_ASC_LC_G 0x67 -#define DUK_ASC_LC_H 0x68 -#define DUK_ASC_LC_I 0x69 -#define DUK_ASC_LC_J 0x6a -#define DUK_ASC_LC_K 0x6b -#define DUK_ASC_LC_L 0x6c -#define DUK_ASC_LC_M 0x6d -#define DUK_ASC_LC_N 0x6e -#define DUK_ASC_LC_O 0x6f -#define DUK_ASC_LC_P 0x70 -#define DUK_ASC_LC_Q 0x71 -#define DUK_ASC_LC_R 0x72 -#define DUK_ASC_LC_S 0x73 -#define DUK_ASC_LC_T 0x74 -#define DUK_ASC_LC_U 0x75 -#define DUK_ASC_LC_V 0x76 -#define DUK_ASC_LC_W 0x77 -#define DUK_ASC_LC_X 0x78 -#define DUK_ASC_LC_Y 0x79 -#define DUK_ASC_LC_Z 0x7a -#define DUK_ASC_LCURLY 0x7b -#define DUK_ASC_PIPE 0x7c -#define DUK_ASC_RCURLY 0x7d -#define DUK_ASC_TILDE 0x7e -#define DUK_ASC_DEL 0x7f +#define DUK_ASC_NUL 0x00 +#define DUK_ASC_SOH 0x01 +#define DUK_ASC_STX 0x02 +#define DUK_ASC_ETX 0x03 +#define DUK_ASC_EOT 0x04 +#define DUK_ASC_ENQ 0x05 +#define DUK_ASC_ACK 0x06 +#define DUK_ASC_BEL 0x07 +#define DUK_ASC_BS 0x08 +#define DUK_ASC_HT 0x09 +#define DUK_ASC_LF 0x0a +#define DUK_ASC_VT 0x0b +#define DUK_ASC_FF 0x0c +#define DUK_ASC_CR 0x0d +#define DUK_ASC_SO 0x0e +#define DUK_ASC_SI 0x0f +#define DUK_ASC_DLE 0x10 +#define DUK_ASC_DC1 0x11 +#define DUK_ASC_DC2 0x12 +#define DUK_ASC_DC3 0x13 +#define DUK_ASC_DC4 0x14 +#define DUK_ASC_NAK 0x15 +#define DUK_ASC_SYN 0x16 +#define DUK_ASC_ETB 0x17 +#define DUK_ASC_CAN 0x18 +#define DUK_ASC_EM 0x19 +#define DUK_ASC_SUB 0x1a +#define DUK_ASC_ESC 0x1b +#define DUK_ASC_FS 0x1c +#define DUK_ASC_GS 0x1d +#define DUK_ASC_RS 0x1e +#define DUK_ASC_US 0x1f +#define DUK_ASC_SPACE 0x20 +#define DUK_ASC_EXCLAMATION 0x21 +#define DUK_ASC_DOUBLEQUOTE 0x22 +#define DUK_ASC_HASH 0x23 +#define DUK_ASC_DOLLAR 0x24 +#define DUK_ASC_PERCENT 0x25 +#define DUK_ASC_AMP 0x26 +#define DUK_ASC_SINGLEQUOTE 0x27 +#define DUK_ASC_LPAREN 0x28 +#define DUK_ASC_RPAREN 0x29 +#define DUK_ASC_STAR 0x2a +#define DUK_ASC_PLUS 0x2b +#define DUK_ASC_COMMA 0x2c +#define DUK_ASC_MINUS 0x2d +#define DUK_ASC_PERIOD 0x2e +#define DUK_ASC_SLASH 0x2f +#define DUK_ASC_0 0x30 +#define DUK_ASC_1 0x31 +#define DUK_ASC_2 0x32 +#define DUK_ASC_3 0x33 +#define DUK_ASC_4 0x34 +#define DUK_ASC_5 0x35 +#define DUK_ASC_6 0x36 +#define DUK_ASC_7 0x37 +#define DUK_ASC_8 0x38 +#define DUK_ASC_9 0x39 +#define DUK_ASC_COLON 0x3a +#define DUK_ASC_SEMICOLON 0x3b +#define DUK_ASC_LANGLE 0x3c +#define DUK_ASC_EQUALS 0x3d +#define DUK_ASC_RANGLE 0x3e +#define DUK_ASC_QUESTION 0x3f +#define DUK_ASC_ATSIGN 0x40 +#define DUK_ASC_UC_A 0x41 +#define DUK_ASC_UC_B 0x42 +#define DUK_ASC_UC_C 0x43 +#define DUK_ASC_UC_D 0x44 +#define DUK_ASC_UC_E 0x45 +#define DUK_ASC_UC_F 0x46 +#define DUK_ASC_UC_G 0x47 +#define DUK_ASC_UC_H 0x48 +#define DUK_ASC_UC_I 0x49 +#define DUK_ASC_UC_J 0x4a +#define DUK_ASC_UC_K 0x4b +#define DUK_ASC_UC_L 0x4c +#define DUK_ASC_UC_M 0x4d +#define DUK_ASC_UC_N 0x4e +#define DUK_ASC_UC_O 0x4f +#define DUK_ASC_UC_P 0x50 +#define DUK_ASC_UC_Q 0x51 +#define DUK_ASC_UC_R 0x52 +#define DUK_ASC_UC_S 0x53 +#define DUK_ASC_UC_T 0x54 +#define DUK_ASC_UC_U 0x55 +#define DUK_ASC_UC_V 0x56 +#define DUK_ASC_UC_W 0x57 +#define DUK_ASC_UC_X 0x58 +#define DUK_ASC_UC_Y 0x59 +#define DUK_ASC_UC_Z 0x5a +#define DUK_ASC_LBRACKET 0x5b +#define DUK_ASC_BACKSLASH 0x5c +#define DUK_ASC_RBRACKET 0x5d +#define DUK_ASC_CARET 0x5e +#define DUK_ASC_UNDERSCORE 0x5f +#define DUK_ASC_GRAVE 0x60 +#define DUK_ASC_LC_A 0x61 +#define DUK_ASC_LC_B 0x62 +#define DUK_ASC_LC_C 0x63 +#define DUK_ASC_LC_D 0x64 +#define DUK_ASC_LC_E 0x65 +#define DUK_ASC_LC_F 0x66 +#define DUK_ASC_LC_G 0x67 +#define DUK_ASC_LC_H 0x68 +#define DUK_ASC_LC_I 0x69 +#define DUK_ASC_LC_J 0x6a +#define DUK_ASC_LC_K 0x6b +#define DUK_ASC_LC_L 0x6c +#define DUK_ASC_LC_M 0x6d +#define DUK_ASC_LC_N 0x6e +#define DUK_ASC_LC_O 0x6f +#define DUK_ASC_LC_P 0x70 +#define DUK_ASC_LC_Q 0x71 +#define DUK_ASC_LC_R 0x72 +#define DUK_ASC_LC_S 0x73 +#define DUK_ASC_LC_T 0x74 +#define DUK_ASC_LC_U 0x75 +#define DUK_ASC_LC_V 0x76 +#define DUK_ASC_LC_W 0x77 +#define DUK_ASC_LC_X 0x78 +#define DUK_ASC_LC_Y 0x79 +#define DUK_ASC_LC_Z 0x7a +#define DUK_ASC_LCURLY 0x7b +#define DUK_ASC_PIPE 0x7c +#define DUK_ASC_RCURLY 0x7d +#define DUK_ASC_TILDE 0x7e +#define DUK_ASC_DEL 0x7f /* * Miscellaneous @@ -10210,7 +10901,7 @@ /* Uppercase A is 0x41, lowercase a is 0x61; OR 0x20 to convert uppercase * to lowercase. */ -#define DUK_LOWERCASE_CHAR_ASCII(x) ((x) | 0x20) +#define DUK_LOWERCASE_CHAR_ASCII(x) ((x) | 0x20) /* * Unicode tables @@ -10298,7 +10989,7 @@ DUK_INTERNAL_DECL const duk_uint16_t duk_unicode_re_ranges_not_white24; DUK_INTERNAL_DECL const duk_uint16_t duk_unicode_re_ranges_not_wordchar10; DUK_INTERNAL_DECL const duk_int8_t duk_is_idchar_tab128; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* * Prototypes @@ -10310,8 +11001,15 @@ #endif DUK_INTERNAL_DECL duk_small_int_t duk_unicode_encode_xutf8(duk_ucodepoint_t cp, duk_uint8_t *out); DUK_INTERNAL_DECL duk_small_int_t duk_unicode_encode_cesu8(duk_ucodepoint_t cp, duk_uint8_t *out); -DUK_INTERNAL_DECL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_ucodepoint_t *out_cp); -DUK_INTERNAL_DECL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end); +DUK_INTERNAL_DECL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_ucodepoint_t *out_cp); +DUK_INTERNAL_DECL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end); DUK_INTERNAL_DECL duk_size_t duk_unicode_unvalidated_utf8_length(const duk_uint8_t *data, duk_size_t blen); DUK_INTERNAL_DECL duk_bool_t duk_unicode_is_utf8_compatible(const duk_uint8_t *buf, duk_size_t len); DUK_INTERNAL_DECL duk_small_int_t duk_unicode_is_whitespace(duk_codepoint_t cp); @@ -10325,7 +11023,7 @@ DUK_INTERNAL_DECL duk_small_int_t duk_unicode_re_is_wordchar(duk_codepoint_t cp); #endif -#endif /* DUK_UNICODE_H_INCLUDED */ +#endif /* DUK_UNICODE_H_INCLUDED */ /* #include duk_json.h */ /* * Defines for JSON, especially duk_bi_json.c. @@ -10335,28 +11033,28 @@ #define DUK_JSON_H_INCLUDED /* Encoding/decoding flags */ -#define DUK_JSON_FLAG_ASCII_ONLY (1U << 0) /* escape any non-ASCII characters */ -#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1U << 1) /* avoid key quotes when key is an ASCII Identifier */ -#define DUK_JSON_FLAG_EXT_CUSTOM (1U << 2) /* extended types: custom encoding */ -#define DUK_JSON_FLAG_EXT_COMPATIBLE (1U << 3) /* extended types: compatible encoding */ +#define DUK_JSON_FLAG_ASCII_ONLY (1U << 0) /* escape any non-ASCII characters */ +#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1U << 1) /* avoid key quotes when key is an ASCII Identifier */ +#define DUK_JSON_FLAG_EXT_CUSTOM (1U << 2) /* extended types: custom encoding */ +#define DUK_JSON_FLAG_EXT_COMPATIBLE (1U << 3) /* extended types: compatible encoding */ /* How much stack to require on entry to object/array encode */ -#define DUK_JSON_ENC_REQSTACK 32 +#define DUK_JSON_ENC_REQSTACK 32 /* How much stack to require on entry to object/array decode */ -#define DUK_JSON_DEC_REQSTACK 32 +#define DUK_JSON_DEC_REQSTACK 32 /* How large a loop detection stack to use */ -#define DUK_JSON_ENC_LOOPARRAY 64 +#define DUK_JSON_ENC_LOOPARRAY 64 /* Encoding state. Heap object references are all borrowed. */ typedef struct { duk_hthread *thr; - duk_bufwriter_ctx bw; /* output bufwriter */ - duk_hobject *h_replacer; /* replacer function */ - duk_hstring *h_gap; /* gap (if empty string, NULL) */ - duk_idx_t idx_proplist; /* explicit PropertyList */ - duk_idx_t idx_loop; /* valstack index of loop detection object */ + duk_bufwriter_ctx bw; /* output bufwriter */ + duk_hobject *h_replacer; /* replacer function */ + duk_hstring *h_gap; /* gap (if empty string, NULL) */ + duk_idx_t idx_proplist; /* explicit PropertyList */ + duk_idx_t idx_loop; /* valstack index of loop detection object */ duk_small_uint_t flags; duk_small_uint_t flag_ascii_only; duk_small_uint_t flag_avoid_key_quotes; @@ -10367,7 +11065,7 @@ #endif duk_uint_t recursion_depth; duk_uint_t recursion_limit; - duk_uint_t mask_for_undefined; /* type bit mask: types which certainly produce 'undefined' */ + duk_uint_t mask_for_undefined; /* type bit mask: types which certainly produce 'undefined' */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) duk_small_uint_t stridx_custom_undefined; duk_small_uint_t stridx_custom_nan; @@ -10375,7 +11073,7 @@ duk_small_uint_t stridx_custom_posinf; duk_small_uint_t stridx_custom_function; #endif - duk_hobject *visitingDUK_JSON_ENC_LOOPARRAY; /* indexed by recursion_depth */ + duk_hobject *visitingDUK_JSON_ENC_LOOPARRAY; /* indexed by recursion_depth */ } duk_json_enc_ctx; typedef struct { @@ -10394,7 +11092,7 @@ duk_int_t recursion_limit; } duk_json_dec_ctx; -#endif /* DUK_JSON_H_INCLUDED */ +#endif /* DUK_JSON_H_INCLUDED */ /* #include duk_js.h */ /* * ECMAScript execution, support primitives. @@ -10404,21 +11102,22 @@ #define DUK_JS_H_INCLUDED /* Flags for call handling. Lowest flags must match bytecode DUK_BC_CALL_FLAG_xxx 1:1. */ -#define DUK_CALL_FLAG_TAILCALL (1U << 0) /* setup for a tail call */ -#define DUK_CALL_FLAG_CONSTRUCT (1U << 1) /* constructor call (i.e. called as 'new Foo()') */ -#define DUK_CALL_FLAG_CALLED_AS_EVAL (1U << 2) /* call was made using the identifier 'eval' */ -#define DUK_CALL_FLAG_ALLOW_ECMATOECMA (1U << 3) /* ecma-to-ecma call with executor reuse is possible */ -#define DUK_CALL_FLAG_DIRECT_EVAL (1U << 4) /* call is a direct eval call */ -#define DUK_CALL_FLAG_CONSTRUCT_PROXY (1U << 5) /* handled via 'construct' proxy trap, check return value invariant(s) */ -#define DUK_CALL_FLAG_DEFAULT_INSTANCE_UPDATED (1U << 6) /* prototype of 'default instance' updated, temporary flag in call handling */ +#define DUK_CALL_FLAG_TAILCALL (1U << 0) /* setup for a tail call */ +#define DUK_CALL_FLAG_CONSTRUCT (1U << 1) /* constructor call (i.e. called as 'new Foo()') */ +#define DUK_CALL_FLAG_CALLED_AS_EVAL (1U << 2) /* call was made using the identifier 'eval' */ +#define DUK_CALL_FLAG_ALLOW_ECMATOECMA (1U << 3) /* ecma-to-ecma call with executor reuse is possible */ +#define DUK_CALL_FLAG_DIRECT_EVAL (1U << 4) /* call is a direct eval call */ +#define DUK_CALL_FLAG_CONSTRUCT_PROXY (1U << 5) /* handled via 'construct' proxy trap, check return value invariant(s) */ +#define DUK_CALL_FLAG_DEFAULT_INSTANCE_UPDATED \ + (1U << 6) /* prototype of 'default instance' updated, temporary flag in call handling */ /* Flags for duk_js_equals_helper(). */ -#define DUK_EQUALS_FLAG_SAMEVALUE (1U << 0) /* use SameValue instead of non-strict equality */ -#define DUK_EQUALS_FLAG_STRICT (1U << 1) /* use strict equality instead of non-strict equality */ +#define DUK_EQUALS_FLAG_SAMEVALUE (1U << 0) /* use SameValue instead of non-strict equality */ +#define DUK_EQUALS_FLAG_STRICT (1U << 1) /* use strict equality instead of non-strict equality */ /* Flags for duk_js_compare_helper(). */ -#define DUK_COMPARE_FLAG_NEGATE (1U << 0) /* negate result */ -#define DUK_COMPARE_FLAG_EVAL_LEFT_FIRST (1U << 1) /* eval left argument first */ +#define DUK_COMPARE_FLAG_NEGATE (1U << 0) /* negate result */ +#define DUK_COMPARE_FLAG_EVAL_LEFT_FIRST (1U << 1) /* eval left argument first */ /* conversions, coercions, comparison, etc */ DUK_INTERNAL_DECL duk_bool_t duk_js_toboolean(duk_tval *tv); @@ -10434,9 +11133,12 @@ DUK_INTERNAL_DECL duk_uarridx_t duk_js_to_arrayindex_hstring_fast(duk_hstring *h); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_equals_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags); -DUK_INTERNAL_DECL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, const duk_uint8_t *buf2, duk_size_t len1, duk_size_t len2); +DUK_INTERNAL_DECL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, + const duk_uint8_t *buf2, + duk_size_t len1, + duk_size_t len2); DUK_INTERNAL_DECL duk_small_int_t duk_js_string_compare(duk_hstring *h1, duk_hstring *h2); -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL_DECL duk_small_int_t duk_js_buffer_compare(duk_heap *heap, duk_hbuffer *h1, duk_hbuffer *h2); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_compare_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags); @@ -10453,45 +11155,57 @@ DUK_INTERNAL_DECL double duk_js_arith_pow(double x, double y); DUK_INTERNAL_DECL double duk_js_arith_mod(double x, double y); -#define duk_js_equals(thr,tv_x,tv_y) \ - duk_js_equals_helper((thr), (tv_x), (tv_y), 0) -#define duk_js_strict_equals(tv_x,tv_y) \ - duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_STRICT) -#define duk_js_samevalue(tv_x,tv_y) \ - duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_SAMEVALUE) +#define duk_js_equals(thr, tv_x, tv_y) duk_js_equals_helper((thr), (tv_x), (tv_y), 0) +#define duk_js_strict_equals(tv_x, tv_y) duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_STRICT) +#define duk_js_samevalue(tv_x, tv_y) duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_SAMEVALUE) /* E5 Sections 11.8.1, 11.8.5; x < y */ -#define duk_js_lessthan(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_x), (tv_Y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) +#define duk_js_lessthan(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_x), (tv_Y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) /* E5 Sections 11.8.2, 11.8.5; x > y --> y < x */ -#define duk_js_greaterthan(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_y), (tv_x), 0) +#define duk_js_greaterthan(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_y), (tv_x), 0) /* E5 Sections 11.8.3, 11.8.5; x <= y --> not (x > y) --> not (y < x) */ -#define duk_js_lessthanorequal(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_y), (tv_x), DUK_COMPARE_FLAG_NEGATE) +#define duk_js_lessthanorequal(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_y), (tv_x), DUK_COMPARE_FLAG_NEGATE) /* E5 Sections 11.8.4, 11.8.5; x >= y --> not (x < y) */ -#define duk_js_greaterthanorequal(thr,tv_x,tv_y) \ +#define duk_js_greaterthanorequal(thr, tv_x, tv_y) \ duk_js_compare_helper((thr), (tv_x), (tv_y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) /* identifiers and environment handling */ -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_hasvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_bool_t throw_flag); -DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag); -DUK_INTERNAL_DECL void duk_js_putvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_tval *val, duk_bool_t strict); -DUK_INTERNAL_DECL void duk_js_putvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_bool_t strict); -#if 0 /*unused*/ +DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_bool_t throw_flag); +DUK_INTERNAL_DECL void duk_js_putvar_envrec(duk_hthread *thr, + duk_hobject *env, + duk_hstring *name, + duk_tval *val, + duk_bool_t strict); +DUK_INTERNAL_DECL void duk_js_putvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_tval *val, + duk_bool_t strict); +#if 0 /*unused*/ DUK_INTERNAL_DECL duk_bool_t duk_js_delvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_delvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name); -DUK_INTERNAL_DECL duk_bool_t duk_js_declvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_small_uint_t prop_flags, duk_bool_t is_func_decl); +DUK_INTERNAL_DECL duk_bool_t duk_js_declvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_tval *val, + duk_small_uint_t prop_flags, + duk_bool_t is_func_decl); DUK_INTERNAL_DECL void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, duk_activation *act); DUK_INTERNAL_DECL void duk_js_close_environment_record(duk_hthread *thr, duk_hobject *env); -DUK_INTERNAL_DECL duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, duk_hobject *func, duk_size_t bottom_byteoff); +DUK_INTERNAL_DECL duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, + duk_hobject *func, + duk_size_t bottom_byteoff); DUK_INTERNAL_DECL void duk_js_push_closure(duk_hthread *thr, duk_hcompfunc *fun_temp, duk_hobject *outer_var_env, @@ -10502,7 +11216,8 @@ DUK_INTERNAL_DECL void duk_native_stack_check(duk_hthread *thr); DUK_INTERNAL_DECL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags); DUK_INTERNAL_DECL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags); -DUK_INTERNAL_DECL duk_int_t duk_handle_safe_call(duk_hthread *thr, duk_safe_call_function func, void *udata, duk_idx_t num_stack_args, duk_idx_t num_stack_res); +DUK_INTERNAL_DECL duk_int_t +duk_handle_safe_call(duk_hthread *thr, duk_safe_call_function func, void *udata, duk_idx_t num_stack_args, duk_idx_t num_stack_res); DUK_INTERNAL_DECL void duk_call_construct_postprocess(duk_hthread *thr, duk_small_uint_t proxy_invariant); #if defined(DUK_USE_VERBOSE_ERRORS) DUK_INTERNAL_DECL void duk_call_setup_propcall_error(duk_hthread *thr, duk_tval *tv_base, duk_tval *tv_key); @@ -10511,7 +11226,7 @@ /* bytecode execution */ DUK_INTERNAL_DECL void duk_js_execute_bytecode(duk_hthread *exec_thr); -#endif /* DUK_JS_H_INCLUDED */ +#endif /* DUK_JS_H_INCLUDED */ /* #include duk_numconv.h */ /* * Number-to-string conversion. The semantics of these is very tightly @@ -10524,23 +11239,23 @@ /* Output a specified number of digits instead of using the shortest * form. Used for toPrecision() and toFixed(). */ -#define DUK_N2S_FLAG_FIXED_FORMAT (1U << 0) +#define DUK_N2S_FLAG_FIXED_FORMAT (1U << 0) /* Force exponential format. Used for toExponential(). */ -#define DUK_N2S_FLAG_FORCE_EXP (1U << 1) +#define DUK_N2S_FLAG_FORCE_EXP (1U << 1) /* If number would need zero padding (for whole number part), use * exponential format instead. E.g. if input number is 12300, 3 * digits are generated ("123"), output "1.23e+4" instead of "12300". * Used for toPrecision(). */ -#define DUK_N2S_FLAG_NO_ZERO_PAD (1U << 2) +#define DUK_N2S_FLAG_NO_ZERO_PAD (1U << 2) /* Digit count indicates number of fractions (i.e. an absolute * digit index instead of a relative one). Used together with * DUK_N2S_FLAG_FIXED_FORMAT for toFixed(). */ -#define DUK_N2S_FLAG_FRACTION_DIGITS (1U << 3) +#define DUK_N2S_FLAG_FRACTION_DIGITS (1U << 3) /* * String-to-number conversion @@ -10554,69 +11269,72 @@ * radix 10, but with maximum radix (36) a safe limit is: * (10000000*36).toString(16) -> '15752a00' */ -#define DUK_S2N_MAX_EXPONENT 10000000L +#define DUK_S2N_MAX_EXPONENT 10000000L /* Trim white space (= allow leading and trailing whitespace) */ -#define DUK_S2N_FLAG_TRIM_WHITE (1U << 0) +#define DUK_S2N_FLAG_TRIM_WHITE (1U << 0) /* Allow exponent */ -#define DUK_S2N_FLAG_ALLOW_EXP (1U << 1) +#define DUK_S2N_FLAG_ALLOW_EXP (1U << 1) /* Allow trailing garbage (e.g. treat "123foo" as "123) */ -#define DUK_S2N_FLAG_ALLOW_GARBAGE (1U << 2) +#define DUK_S2N_FLAG_ALLOW_GARBAGE (1U << 2) /* Allow leading plus sign */ -#define DUK_S2N_FLAG_ALLOW_PLUS (1U << 3) +#define DUK_S2N_FLAG_ALLOW_PLUS (1U << 3) /* Allow leading minus sign */ -#define DUK_S2N_FLAG_ALLOW_MINUS (1U << 4) +#define DUK_S2N_FLAG_ALLOW_MINUS (1U << 4) /* Allow 'Infinity' */ -#define DUK_S2N_FLAG_ALLOW_INF (1U << 5) +#define DUK_S2N_FLAG_ALLOW_INF (1U << 5) /* Allow fraction part */ -#define DUK_S2N_FLAG_ALLOW_FRAC (1U << 6) +#define DUK_S2N_FLAG_ALLOW_FRAC (1U << 6) /* Allow naked fraction (e.g. ".123") */ -#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1U << 7) +#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1U << 7) /* Allow empty fraction (e.g. "123.") */ -#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1U << 8) +#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1U << 8) /* Allow empty string to be interpreted as 0 */ -#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1U << 9) +#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1U << 9) /* Allow leading zeroes (e.g. "0123" -> "123") */ -#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1U << 10) +#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1U << 10) /* Allow automatic detection of hex base ("0x" or "0X" prefix), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1U << 11) +#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1U << 11) /* Allow automatic detection of legacy octal base ("0n"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_LEGACY_OCT_INT (1U << 12) +#define DUK_S2N_FLAG_ALLOW_AUTO_LEGACY_OCT_INT (1U << 12) /* Allow automatic detection of ES2015 octal base ("0o123"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1U << 13) +#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1U << 13) /* Allow automatic detection of ES2015 binary base ("0b10001"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT (1U << 14) +#define DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT (1U << 14) /* * Prototypes */ -DUK_INTERNAL_DECL void duk_numconv_stringify(duk_hthread *thr, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_numconv_stringify(duk_hthread *thr, + duk_small_int_t radix, + duk_small_int_t digits, + duk_small_uint_t flags); DUK_INTERNAL_DECL void duk_numconv_parse(duk_hthread *thr, duk_small_int_t radix, duk_small_uint_t flags); -#endif /* DUK_NUMCONV_H_INCLUDED */ +#endif /* DUK_NUMCONV_H_INCLUDED */ /* #include duk_bi_protos.h */ /* * Prototypes for built-in functions not automatically covered by the @@ -10632,7 +11350,7 @@ * 32 * Include additional space to be safe. */ -#define DUK_BI_DATE_ISO8601_BUFSIZE 40 +#define DUK_BI_DATE_ISO8601_BUFSIZE 40 /* Helpers exposed for internal use */ DUK_INTERNAL_DECL void duk_bi_date_timeval_to_parts(duk_double_t d, duk_int_t *parts, duk_double_t *dparts, duk_small_uint_t flags); @@ -10670,7 +11388,10 @@ DUK_INTERNAL_DECL duk_bool_t duk_bi_date_parse_string_getdate(duk_hthread *thr, const char *str); #endif #if defined(DUK_USE_DATE_FMT_STRFTIME) -DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags); +DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, + duk_int_t *parts, + duk_int_t tzoffset, + duk_small_uint_t flags); #endif #if defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME) @@ -10681,10 +11402,7 @@ #endif DUK_INTERNAL_DECL -void duk_bi_json_parse_helper(duk_hthread *thr, - duk_idx_t idx_value, - duk_idx_t idx_reviver, - duk_small_uint_t flags); +void duk_bi_json_parse_helper(duk_hthread *thr, duk_idx_t idx_value, duk_idx_t idx_reviver, duk_small_uint_t flags); DUK_INTERNAL_DECL void duk_bi_json_stringify_helper(duk_hthread *thr, duk_idx_t idx_value, @@ -10698,7 +11416,7 @@ DUK_INTERNAL_DECL void duk_proxy_ownkeys_postprocess(duk_hthread *thr, duk_hobject *h_proxy_target, duk_uint_t flags); #endif -#endif /* DUK_BUILTIN_PROTOS_H_INCLUDED */ +#endif /* DUK_BUILTIN_PROTOS_H_INCLUDED */ /* #include duk_selftest.h */ /* * Selftest code @@ -10714,9 +11432,9 @@ void *udata); #endif -#endif /* DUK_SELFTEST_H_INCLUDED */ +#endif /* DUK_SELFTEST_H_INCLUDED */ -#endif /* DUK_INTERNAL_H_INCLUDED */ +#endif /* DUK_INTERNAL_H_INCLUDED */ #if defined(DUK_USE_COMPUTED_NAN) DUK_INTERNAL double duk_computed_nan; @@ -10810,7 +11528,7 @@ #error debugging enabled (DUK_USE_DEBUG) but DUK_USE_DEBUG_WRITE not defined #endif -#define DUK__DEBUG_BUFSIZE DUK_USE_DEBUG_BUFSIZE +#define DUK__DEBUG_BUFSIZE DUK_USE_DEBUG_BUFSIZE #if defined(DUK_USE_VARIADIC_MACROS) @@ -10838,7 +11556,7 @@ va_end(ap); } -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ DUK_INTERNAL char duk_debug_file_stashDUK_DEBUG_STASH_SIZE; DUK_INTERNAL duk_int_t duk_debug_line_stash; @@ -10869,15 +11587,15 @@ va_end(ap); } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#else /* DUK_USE_DEBUG */ +#else /* DUK_USE_DEBUG */ /* * Debugging disabled */ -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* automatic undefs */ #undef DUK__DEBUG_BUFSIZE @@ -11246,7 +11964,7 @@ 137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35, 23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165, 19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70, -72,115,96,0,0,0,0,0,15,106,32,91,60,165,195,201,194,8,134,149,216,162,0, +72,115,96,0,0,0,0,0,27,234,32,91,60,165,195,201,194,8,134,149,216,162,0, 192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176, 195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20, 1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219, @@ -11446,7 +12164,7 @@ 137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35, 23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165, 19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70, -72,115,96,32,106,15,0,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, +72,115,96,32,106,27,128,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, 192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176, 195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20, 1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219, @@ -11646,7 +12364,7 @@ 137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35, 23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165, 19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70, -72,115,96,0,15,106,32,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, +72,115,96,0,27,234,32,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, 192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176, 195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20, 1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219, @@ -11751,31 +12469,43 @@ /* #include duk_internal.h -> already included */ -#define DUK__ERRFMT_BUFSIZE 256 /* size for formatting buffers */ +#define DUK__ERRFMT_BUFSIZE 256 /* size for formatting buffers */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_INTERNAL DUK_COLD void duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...) { +DUK_INTERNAL DUK_COLD void duk_err_handle_error_fmt(duk_hthread *thr, + const char *filename, + duk_uint_t line_and_code, + const char *fmt, + ...) { va_list ap; char msgDUK__ERRFMT_BUFSIZE; va_start(ap, fmt); (void) DUK_VSNPRINTF(msg, sizeof(msg), fmt, ap); msgsizeof(msg) - 1 = (char) 0; - duk_err_create_and_throw(thr, (duk_errcode_t) (line_and_code >> 24), msg, filename, (duk_int_t) (line_and_code & 0x00ffffffL)); - va_end(ap); /* dead code, but ensures portability (see Linux man page notes) */ + duk_err_create_and_throw(thr, + (duk_errcode_t) (line_and_code >> 24), + msg, + filename, + (duk_int_t) (line_and_code & 0x00ffffffL)); + va_end(ap); /* dead code, but ensures portability (see Linux man page notes) */ } DUK_INTERNAL DUK_COLD void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg) { - duk_err_create_and_throw(thr, (duk_errcode_t) (line_and_code >> 24), msg, filename, (duk_int_t) (line_and_code & 0x00ffffffL)); + duk_err_create_and_throw(thr, + (duk_errcode_t) (line_and_code >> 24), + msg, + filename, + (duk_int_t) (line_and_code & 0x00ffffffL)); } -#else /* DUK_USE_VERBOSE_ERRORS */ +#else /* DUK_USE_VERBOSE_ERRORS */ DUK_INTERNAL DUK_COLD void duk_err_handle_error(duk_hthread *thr, duk_errcode_t code) { duk_err_create_and_throw(thr, code); } -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Error throwing helpers @@ -11783,14 +12513,34 @@ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) -DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name) { - DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)", - expect_name, duk_get_type_name(thr, idx), (long) idx); -} -#else -DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name) { - DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)", - expect_name, duk_push_string_readable(thr, idx), (long) idx); +DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name) { + DUK_ERROR_RAW_FMT3(thr, + filename, + linenumber, + DUK_ERR_TYPE_ERROR, + "%s required, found %s (stack index %ld)", + expect_name, + duk_get_type_name(thr, idx), + (long) idx); +} +#else +DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name) { + DUK_ERROR_RAW_FMT3(thr, + filename, + linenumber, + DUK_ERR_TYPE_ERROR, + "%s required, found %s (stack index %ld)", + expect_name, + duk_push_string_readable(thr, idx), + (long) idx); } #endif DUK_INTERNAL DUK_COLD void duk_err_error_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber) { @@ -11917,14 +12667,14 @@ * 1: IdentifierStart and IdentifierPart * -1: IdentifierPart only */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00...0x0f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10...0x1f */ - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20...0x2f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, /* 0x30...0x3f */ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40...0x4f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50...0x5f */ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60...0x6f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70...0x7f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00...0x0f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10...0x1f */ + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20...0x2f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, /* 0x30...0x3f */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40...0x4f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50...0x5f */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60...0x6f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70...0x7f */ }; #endif @@ -11974,15 +12724,13 @@ /* Encoded as surrogate pair, each encoding to 3 bytes for * 6 bytes total. Codepoints above U+10FFFF encode as 6 bytes * too, see duk_unicode_encode_cesu8(). - */ + */ return 3 + 3; } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ -DUK_INTERNAL const duk_uint8_t duk_unicode_xutf8_markers7 = { - 0x00, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe -}; +DUK_INTERNAL const duk_uint8_t duk_unicode_xutf8_markers7 = { 0x00, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe }; /* Encode to extended UTF-8; 'out' must have space for at least * DUK_UNICODE_MAX_XUTF8_LENGTH bytes. Allows encoding of any @@ -11997,7 +12745,7 @@ len = duk_unicode_get_xutf8_length(cp); DUK_ASSERT(len > 0); - marker = duk_unicode_xutf8_markerslen - 1; /* 64-bit OK because always >= 0 */ + marker = duk_unicode_xutf8_markerslen - 1; /* 64-bit OK because always >= 0 */ i = len; DUK_ASSERT(i > 0); @@ -12082,7 +12830,11 @@ } /* Decode helper. Return zero on error. */ -DUK_INTERNAL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_ucodepoint_t *out_cp) { +DUK_INTERNAL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_ucodepoint_t *out_cp) { const duk_uint8_t *p; duk_uint32_t res; duk_uint_fast8_t ch; @@ -12144,7 +12896,7 @@ goto fail; } - DUK_ASSERT(p >= ptr_start); /* verified at beginning */ + DUK_ASSERT(p >= ptr_start); /* verified at beginning */ if (p + n > ptr_end) { /* check pointer at end */ goto fail; @@ -12170,12 +12922,15 @@ *out_cp = res; return 1; - fail: +fail: return 0; } /* used by e.g. duk_regexp_executor.c, string built-ins */ -DUK_INTERNAL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end) { +DUK_INTERNAL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end) { duk_ucodepoint_t cp; if (duk_unicode_decode_xutf8(thr, ptr, ptr_start, ptr_end, &cp)) { @@ -12222,7 +12977,7 @@ DUK_ASSERT(clen <= blen); return clen; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* This seems like a good overall approach. Fast path for ASCII in 4 byte * blocks. */ @@ -12234,7 +12989,7 @@ duk_size_t ncont; duk_size_t clen; - ncont = 0; /* number of continuation (non-initial) bytes in 0x80,0xbf */ + ncont = 0; /* number of continuation (non-initial) bytes in 0x80,0xbf */ p = data; p_end = data + blen; if (blen < 16) { @@ -12259,7 +13014,7 @@ duk_uint32_t x; x = *p32++; if (DUK_LIKELY((x & 0x80808080UL) == 0)) { - ; /* ASCII fast path */ + ; /* ASCII fast path */ } else { /* Flip highest bit of each byte which changes * the bit pattern 10xxxxxx into 00xxxxxx which @@ -12283,7 +13038,7 @@ p = (const duk_uint8_t *) p32; /* Fall through to handle the rest. */ - skip_fastpath: +skip_fastpath: while (p != p_end) { duk_uint8_t x; x = *p++; @@ -12297,7 +13052,7 @@ DUK_ASSERT(clen <= blen); return clen; } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Check whether a string is UTF-8 compatible or not. */ DUK_INTERNAL duk_bool_t duk_unicode_is_utf8_compatible(const duk_uint8_t *buf, duk_size_t len) { @@ -12346,18 +13101,18 @@ * 1111 0xxx + 3*CONT -> 0x10000, 0x10ffff */ left = len - i; - if (t <= 0xdfU) { /* 1101 1111 = 0xdf */ - if (t <= 0xbfU) { /* 1011 1111 = 0xbf */ + if (t <= 0xdfU) { /* 1101 1111 = 0xdf */ + if (t <= 0xbfU) { /* 1011 1111 = 0xbf */ return 0; } ncont = 1; mincp = 0x80UL; cp = t & 0x1fU; - } else if (t <= 0xefU) { /* 1110 1111 = 0xef */ + } else if (t <= 0xefU) { /* 1110 1111 = 0xef */ ncont = 2; mincp = 0x800UL; cp = t & 0x0fU; - } else if (t <= 0xf7U) { /* 1111 0111 = 0xf7 */ + } else if (t <= 0xf7U) { /* 1111 0111 = 0xf7 */ ncont = 3; mincp = 0x10000UL; cp = t & 0x07U; @@ -12369,7 +13124,7 @@ } while (ncont > 0U) { t = bufi++; - if ((t & 0xc0U) != 0x80U) { /* 10xx xxxx */ + if ((t & 0xc0U) != 0x80U) { /* 10xx xxxx */ return 0; } cp = (cp << 6) + (t & 0x3fU); @@ -12435,7 +13190,9 @@ /* r1,r2 is the range */ DUK_DDD(DUK_DDDPRINT("duk__uni_range_match: cp=%06lx range=0x%06lx,0x%06lx", - (unsigned long) cp, (unsigned long) r1, (unsigned long) r2)); + (unsigned long) cp, + (unsigned long) r1, + (unsigned long) r2)); if (cp >= r1 && cp <= r2) { return 1; } @@ -12505,19 +13262,17 @@ /* cp == -1 (EOF) never matches and causes return value 0 */ lo = (duk_uint_fast8_t) (cp & 0xff); - hi = (duk_uint_fast32_t) (cp >> 8); /* does not fit into an uchar */ + hi = (duk_uint_fast32_t) (cp >> 8); /* does not fit into an uchar */ if (hi == 0x0000UL) { - if (lo == 0x09U || lo == 0x0bU || lo == 0x0cU || - lo == 0x20U || lo == 0xa0U) { + if (lo == 0x09U || lo == 0x0bU || lo == 0x0cU || lo == 0x20U || lo == 0xa0U) { return 1; } } else if (hi == 0x0020UL) { if (lo <= 0x0aU || lo == 0x2fU || lo == 0x5fU) { return 1; } - } else if (cp == 0x1680L || cp == 0x180eL || cp == 0x3000L || - cp == 0xfeffL) { + } else if (cp == 0x1680L || cp == 0x180eL || cp == 0x3000L || cp == 0xfeffL) { return 1; } @@ -12536,8 +13291,7 @@ * into a single line terminator. This must be handled by the caller. */ - if (cp == 0x000aL || cp == 0x000dL || cp == 0x2028L || - cp == 0x2029L) { + if (cp == 0x000aL || cp == 0x000dL || cp == 0x2028L || cp == 0x2029L) { return 1; } @@ -12588,9 +13342,7 @@ #if defined(DUK_USE_IDCHAR_FASTPATH) return (cp >= 0) && (duk_is_idchar_tabcp > 0); #else - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z') || - cp == '_' || cp == '$') { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || cp == '_' || cp == '$') { return 1; } return 0; @@ -12600,17 +13352,13 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - (duk_size_t) sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, (duk_size_t) sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp)) { return 1; } return 0; @@ -12677,10 +13425,7 @@ #if defined(DUK_USE_IDCHAR_FASTPATH) return (cp >= 0) && (duk_is_idchar_tabcp != 0); #else - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z') || - (cp >= '0' && cp <= '9') || - cp == '_' || cp == '$') { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || (cp >= '0' && cp <= '9') || cp == '_' || cp == '$') { return 1; } return 0; @@ -12690,20 +13435,14 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp) || - duk__uni_range_match(duk_unicode_idp_m_ids_noa, - sizeof(duk_unicode_idp_m_ids_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp) || + duk__uni_range_match(duk_unicode_idp_m_ids_noa, sizeof(duk_unicode_idp_m_ids_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp) || + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp) || duk__uni_range_match(duk_unicode_idp_m_ids_noabmp, sizeof(duk_unicode_idp_m_ids_noabmp), (duk_codepoint_t) cp)) { @@ -12739,8 +13478,7 @@ /* ASCII (and EOF) fast path -- quick accept and reject */ if (cp <= 0x7fL) { - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z')) { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z')) { return 1; } return 0; @@ -12749,20 +13487,14 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp) && - !duk__uni_range_match(duk_unicode_ids_m_let_noa, - sizeof(duk_unicode_ids_m_let_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp) && + !duk__uni_range_match(duk_unicode_ids_m_let_noa, sizeof(duk_unicode_ids_m_let_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp) && + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp) && !duk__uni_range_match(duk_unicode_ids_m_let_noabmp, sizeof(duk_unicode_ids_m_let_noabmp), (duk_codepoint_t) cp)) { @@ -12799,10 +13531,7 @@ */ DUK_LOCAL -duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr, - duk_bufwriter_ctx *bw, - duk_codepoint_t cp, - duk_bitdecoder_ctx *bd_ctx) { +duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_codepoint_t cp, duk_bitdecoder_ctx *bd_ctx) { duk_small_int_t skip = 0; duk_small_int_t n; duk_small_int_t t; @@ -12832,10 +13561,13 @@ start_o = (duk_codepoint_t) duk_bd_decode(bd_ctx, 16); count = (duk_small_int_t) duk_bd_decode(bd_ctx, 7); DUK_DDD(DUK_DDDPRINT("range: start_i=%ld, start_o=%ld, count=%ld, skip=%ld", - (long) start_i, (long) start_o, (long) count, (long) skip)); + (long) start_i, + (long) start_o, + (long) count, + (long) skip)); if (cp >= start_i) { - tmp_cp = cp - start_i; /* always >= 0 */ + tmp_cp = cp - start_i; /* always >= 0 */ if (tmp_cp < (duk_codepoint_t) count * (duk_codepoint_t) skip && (tmp_cp % (duk_codepoint_t) skip) == 0) { DUK_DDD(DUK_DDDPRINT("range matches input codepoint")); @@ -12887,7 +13619,7 @@ DUK_DDD(DUK_DDDPRINT("no rule matches, output is same as input")); /* fall through */ - single: +single: if (bw != NULL) { DUK_BW_WRITE_RAW_XUTF8(thr, bw, (duk_ucodepoint_t) cp); } @@ -12949,9 +13681,9 @@ * The rule is not locale/language specific so it is supported. */ - if (cp == 0x03a3L && /* U+03A3 = GREEK CAPITAL LETTER SIGMA */ - duk_unicode_is_letter(prev) && /* prev exists and is not a letter */ - !duk_unicode_is_letter(next)) { /* next does not exist or next is not a letter */ + if (cp == 0x03a3L && /* U+03A3 = GREEK CAPITAL LETTER SIGMA */ + duk_unicode_is_letter(prev) && /* prev exists and is not a letter */ + !duk_unicode_is_letter(next)) { /* next does not exist or next is not a letter */ /* Capital sigma occurred at "end of word", lowercase to * U+03C2 = GREEK SMALL LETTER FINAL SIGMA. Otherwise * fall through and let the normal rules lowercase it to @@ -12977,13 +13709,13 @@ } return duk__slow_case_conversion(thr, bw, cp, &bd_ctx); - singlechar: +singlechar: if (bw != NULL) { DUK_BW_WRITE_RAW_XUTF8(thr, bw, (duk_ucodepoint_t) cp); } return cp; - /* unused now, not needed until Turkish/Azeri */ + /* unused now, not needed until Turkish/Azeri */ #if 0 nochar: return -1; @@ -13001,7 +13733,7 @@ const duk_uint8_t *p, *p_start, *p_end; duk_codepoint_t prev, curr, next; - h_input = duk_require_hstring(thr, -1); /* Accept symbols. */ + h_input = duk_require_hstring(thr, -1); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; @@ -13013,7 +13745,8 @@ p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); p = p_start; - prev = -1; DUK_UNREF(prev); + prev = -1; + DUK_UNREF(prev); curr = -1; next = -1; for (;;) { @@ -13038,17 +13771,12 @@ /* Ensure space for maximum multi-character result; estimate is overkill. */ DUK_BW_ENSURE(thr, bw, 8 * DUK_UNICODE_MAX_XUTF8_LENGTH); - duk__case_transform_helper(thr, - bw, - (duk_codepoint_t) curr, - prev, - next, - uppercase); + duk__case_transform_helper(thr, bw, (duk_codepoint_t) curr, prev, next, uppercase); } } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, output is encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, output is encoded. */ /* invalidates h_buf pointer */ duk_remove_m2(thr); } @@ -13071,15 +13799,15 @@ return (duk_codepoint_t) duk_unicode_re_canon_lookupcp; } return cp; -#else /* DUK_USE_REGEXP_CANON_WORKAROUND */ +#else /* DUK_USE_REGEXP_CANON_WORKAROUND */ duk_codepoint_t y; y = duk__case_transform_helper(thr, - NULL, /* NULL is allowed, no output */ - cp, /* curr char */ - -1, /* prev char */ - -1, /* next char */ - 1); /* uppercase */ + NULL, /* NULL is allowed, no output */ + cp, /* curr char */ + -1, /* prev char */ + -1, /* next char */ + 1); /* uppercase */ if ((y < 0) || (cp >= 0x80 && y < 0x80)) { /* multiple codepoint conversion or non-ASCII mapped to ASCII @@ -13089,7 +13817,7 @@ } return y; -#endif /* DUK_USE_REGEXP_CANON_WORKAROUND */ +#endif /* DUK_USE_REGEXP_CANON_WORKAROUND */ } /* @@ -13102,10 +13830,7 @@ * Note: the description in E5 Section 15.10.2.6 has a typo, it * contains 'A' twice and lacks 'a'; the intent is 0-9a-zA-Z_. */ - if ((x >= '0' && x <= '9') || - (x >= 'a' && x <= 'z') || - (x >= 'A' && x <= 'Z') || - (x == '_')) { + if ((x >= '0' && x <= '9') || (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z') || (x == '_')) { return 1; } return 0; @@ -13117,54 +13842,39 @@ /* exposed because lexer needs these too */ DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_digit2 = { - (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, + (duk_uint16_t) 0x0030UL, + (duk_uint16_t) 0x0039UL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_white22 = { - (duk_uint16_t) 0x0009UL, (duk_uint16_t) 0x000DUL, - (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x0020UL, - (duk_uint16_t) 0x00A0UL, (duk_uint16_t) 0x00A0UL, - (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x1680UL, - (duk_uint16_t) 0x180EUL, (duk_uint16_t) 0x180EUL, - (duk_uint16_t) 0x2000UL, (duk_uint16_t) 0x200AUL, - (duk_uint16_t) 0x2028UL, (duk_uint16_t) 0x2029UL, - (duk_uint16_t) 0x202FUL, (duk_uint16_t) 0x202FUL, - (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x205FUL, - (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0x3000UL, + (duk_uint16_t) 0x0009UL, (duk_uint16_t) 0x000DUL, (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x00A0UL, + (duk_uint16_t) 0x00A0UL, (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x180EUL, (duk_uint16_t) 0x180EUL, + (duk_uint16_t) 0x2000UL, (duk_uint16_t) 0x200AUL, (duk_uint16_t) 0x2028UL, (duk_uint16_t) 0x2029UL, (duk_uint16_t) 0x202FUL, + (duk_uint16_t) 0x202FUL, (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0xFEFFUL, (duk_uint16_t) 0xFEFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_wordchar8 = { - (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, - (duk_uint16_t) 0x0041UL, (duk_uint16_t) 0x005AUL, - (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x005FUL, - (duk_uint16_t) 0x0061UL, (duk_uint16_t) 0x007AUL, + (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, (duk_uint16_t) 0x0041UL, (duk_uint16_t) 0x005AUL, + (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x0061UL, (duk_uint16_t) 0x007AUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_digit4 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, - (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, + (duk_uint16_t) 0x002FUL, + (duk_uint16_t) 0x003AUL, + (duk_uint16_t) 0xFFFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_white24 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x0008UL, - (duk_uint16_t) 0x000EUL, (duk_uint16_t) 0x001FUL, - (duk_uint16_t) 0x0021UL, (duk_uint16_t) 0x009FUL, - (duk_uint16_t) 0x00A1UL, (duk_uint16_t) 0x167FUL, - (duk_uint16_t) 0x1681UL, (duk_uint16_t) 0x180DUL, - (duk_uint16_t) 0x180FUL, (duk_uint16_t) 0x1FFFUL, - (duk_uint16_t) 0x200BUL, (duk_uint16_t) 0x2027UL, - (duk_uint16_t) 0x202AUL, (duk_uint16_t) 0x202EUL, - (duk_uint16_t) 0x2030UL, (duk_uint16_t) 0x205EUL, - (duk_uint16_t) 0x2060UL, (duk_uint16_t) 0x2FFFUL, - (duk_uint16_t) 0x3001UL, (duk_uint16_t) 0xFEFEUL, - (duk_uint16_t) 0xFF00UL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x0008UL, (duk_uint16_t) 0x000EUL, (duk_uint16_t) 0x001FUL, (duk_uint16_t) 0x0021UL, + (duk_uint16_t) 0x009FUL, (duk_uint16_t) 0x00A1UL, (duk_uint16_t) 0x167FUL, (duk_uint16_t) 0x1681UL, (duk_uint16_t) 0x180DUL, + (duk_uint16_t) 0x180FUL, (duk_uint16_t) 0x1FFFUL, (duk_uint16_t) 0x200BUL, (duk_uint16_t) 0x2027UL, (duk_uint16_t) 0x202AUL, + (duk_uint16_t) 0x202EUL, (duk_uint16_t) 0x2030UL, (duk_uint16_t) 0x205EUL, (duk_uint16_t) 0x2060UL, (duk_uint16_t) 0x2FFFUL, + (duk_uint16_t) 0x3001UL, (duk_uint16_t) 0xFEFEUL, (duk_uint16_t) 0xFF00UL, (duk_uint16_t) 0xFFFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_wordchar10 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, - (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0x0040UL, - (duk_uint16_t) 0x005BUL, (duk_uint16_t) 0x005EUL, - (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x0060UL, - (duk_uint16_t) 0x007BUL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0x0040UL, (duk_uint16_t) 0x005BUL, + (duk_uint16_t) 0x005EUL, (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x007BUL, (duk_uint16_t) 0xFFFFUL, }; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* * Macro support functions for reading/writing raw data. * @@ -13325,23 +14035,17 @@ */ DUK_INTERNAL const duk_uint8_t duk_lc_digits36 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_LC_A, DUK_ASC_LC_B, - DUK_ASC_LC_C, DUK_ASC_LC_D, DUK_ASC_LC_E, DUK_ASC_LC_F, - DUK_ASC_LC_G, DUK_ASC_LC_H, DUK_ASC_LC_I, DUK_ASC_LC_J, - DUK_ASC_LC_K, DUK_ASC_LC_L, DUK_ASC_LC_M, DUK_ASC_LC_N, - DUK_ASC_LC_O, DUK_ASC_LC_P, DUK_ASC_LC_Q, DUK_ASC_LC_R, - DUK_ASC_LC_S, DUK_ASC_LC_T, DUK_ASC_LC_U, DUK_ASC_LC_V, + DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_LC_A, DUK_ASC_LC_B, DUK_ASC_LC_C, DUK_ASC_LC_D, DUK_ASC_LC_E, DUK_ASC_LC_F, + DUK_ASC_LC_G, DUK_ASC_LC_H, DUK_ASC_LC_I, DUK_ASC_LC_J, DUK_ASC_LC_K, DUK_ASC_LC_L, DUK_ASC_LC_M, DUK_ASC_LC_N, + DUK_ASC_LC_O, DUK_ASC_LC_P, DUK_ASC_LC_Q, DUK_ASC_LC_R, DUK_ASC_LC_S, DUK_ASC_LC_T, DUK_ASC_LC_U, DUK_ASC_LC_V, DUK_ASC_LC_W, DUK_ASC_LC_X, DUK_ASC_LC_Y, DUK_ASC_LC_Z }; -DUK_INTERNAL const duk_uint8_t duk_uc_nybbles16 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_UC_A, DUK_ASC_UC_B, - DUK_ASC_UC_C, DUK_ASC_UC_D, DUK_ASC_UC_E, DUK_ASC_UC_F -}; +DUK_INTERNAL const duk_uint8_t duk_uc_nybbles16 = { DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, + DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_UC_A, DUK_ASC_UC_B, + DUK_ASC_UC_C, DUK_ASC_UC_D, DUK_ASC_UC_E, DUK_ASC_UC_F }; /* * Table for hex decoding ASCII hex digits @@ -13349,43 +14053,43 @@ DUK_INTERNAL const duk_int8_t duk_hex_dectab256 = { /* -1 if invalid */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ }; #if defined(DUK_USE_HEX_FASTPATH) /* Preshifted << 4. Must use 16-bit entry to allow negative value signaling. */ DUK_INTERNAL const duk_int16_t duk_hex_dectab_shift4256 = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ - 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ - -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ - -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ + 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ + -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ + -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ }; #endif @@ -13404,77 +14108,53 @@ * print('0x' + t.encode('hex') + 'U') * print('big endian'); genhextab(False) * print('little endian'); genhextab(True) -*/ + */ DUK_INTERNAL const duk_uint16_t duk_hex_enctab256 = { #if defined(DUK_USE_INTEGER_BE) - 0x3030U, 0x3031U, 0x3032U, 0x3033U, 0x3034U, 0x3035U, 0x3036U, 0x3037U, - 0x3038U, 0x3039U, 0x3061U, 0x3062U, 0x3063U, 0x3064U, 0x3065U, 0x3066U, - 0x3130U, 0x3131U, 0x3132U, 0x3133U, 0x3134U, 0x3135U, 0x3136U, 0x3137U, - 0x3138U, 0x3139U, 0x3161U, 0x3162U, 0x3163U, 0x3164U, 0x3165U, 0x3166U, - 0x3230U, 0x3231U, 0x3232U, 0x3233U, 0x3234U, 0x3235U, 0x3236U, 0x3237U, - 0x3238U, 0x3239U, 0x3261U, 0x3262U, 0x3263U, 0x3264U, 0x3265U, 0x3266U, - 0x3330U, 0x3331U, 0x3332U, 0x3333U, 0x3334U, 0x3335U, 0x3336U, 0x3337U, - 0x3338U, 0x3339U, 0x3361U, 0x3362U, 0x3363U, 0x3364U, 0x3365U, 0x3366U, - 0x3430U, 0x3431U, 0x3432U, 0x3433U, 0x3434U, 0x3435U, 0x3436U, 0x3437U, - 0x3438U, 0x3439U, 0x3461U, 0x3462U, 0x3463U, 0x3464U, 0x3465U, 0x3466U, - 0x3530U, 0x3531U, 0x3532U, 0x3533U, 0x3534U, 0x3535U, 0x3536U, 0x3537U, - 0x3538U, 0x3539U, 0x3561U, 0x3562U, 0x3563U, 0x3564U, 0x3565U, 0x3566U, - 0x3630U, 0x3631U, 0x3632U, 0x3633U, 0x3634U, 0x3635U, 0x3636U, 0x3637U, - 0x3638U, 0x3639U, 0x3661U, 0x3662U, 0x3663U, 0x3664U, 0x3665U, 0x3666U, - 0x3730U, 0x3731U, 0x3732U, 0x3733U, 0x3734U, 0x3735U, 0x3736U, 0x3737U, - 0x3738U, 0x3739U, 0x3761U, 0x3762U, 0x3763U, 0x3764U, 0x3765U, 0x3766U, - 0x3830U, 0x3831U, 0x3832U, 0x3833U, 0x3834U, 0x3835U, 0x3836U, 0x3837U, - 0x3838U, 0x3839U, 0x3861U, 0x3862U, 0x3863U, 0x3864U, 0x3865U, 0x3866U, - 0x3930U, 0x3931U, 0x3932U, 0x3933U, 0x3934U, 0x3935U, 0x3936U, 0x3937U, - 0x3938U, 0x3939U, 0x3961U, 0x3962U, 0x3963U, 0x3964U, 0x3965U, 0x3966U, - 0x6130U, 0x6131U, 0x6132U, 0x6133U, 0x6134U, 0x6135U, 0x6136U, 0x6137U, - 0x6138U, 0x6139U, 0x6161U, 0x6162U, 0x6163U, 0x6164U, 0x6165U, 0x6166U, - 0x6230U, 0x6231U, 0x6232U, 0x6233U, 0x6234U, 0x6235U, 0x6236U, 0x6237U, - 0x6238U, 0x6239U, 0x6261U, 0x6262U, 0x6263U, 0x6264U, 0x6265U, 0x6266U, - 0x6330U, 0x6331U, 0x6332U, 0x6333U, 0x6334U, 0x6335U, 0x6336U, 0x6337U, - 0x6338U, 0x6339U, 0x6361U, 0x6362U, 0x6363U, 0x6364U, 0x6365U, 0x6366U, - 0x6430U, 0x6431U, 0x6432U, 0x6433U, 0x6434U, 0x6435U, 0x6436U, 0x6437U, - 0x6438U, 0x6439U, 0x6461U, 0x6462U, 0x6463U, 0x6464U, 0x6465U, 0x6466U, - 0x6530U, 0x6531U, 0x6532U, 0x6533U, 0x6534U, 0x6535U, 0x6536U, 0x6537U, - 0x6538U, 0x6539U, 0x6561U, 0x6562U, 0x6563U, 0x6564U, 0x6565U, 0x6566U, - 0x6630U, 0x6631U, 0x6632U, 0x6633U, 0x6634U, 0x6635U, 0x6636U, 0x6637U, - 0x6638U, 0x6639U, 0x6661U, 0x6662U, 0x6663U, 0x6664U, 0x6665U, 0x6666U -#else /* DUK_USE_INTEGER_BE */ - 0x3030U, 0x3130U, 0x3230U, 0x3330U, 0x3430U, 0x3530U, 0x3630U, 0x3730U, - 0x3830U, 0x3930U, 0x6130U, 0x6230U, 0x6330U, 0x6430U, 0x6530U, 0x6630U, - 0x3031U, 0x3131U, 0x3231U, 0x3331U, 0x3431U, 0x3531U, 0x3631U, 0x3731U, - 0x3831U, 0x3931U, 0x6131U, 0x6231U, 0x6331U, 0x6431U, 0x6531U, 0x6631U, - 0x3032U, 0x3132U, 0x3232U, 0x3332U, 0x3432U, 0x3532U, 0x3632U, 0x3732U, - 0x3832U, 0x3932U, 0x6132U, 0x6232U, 0x6332U, 0x6432U, 0x6532U, 0x6632U, - 0x3033U, 0x3133U, 0x3233U, 0x3333U, 0x3433U, 0x3533U, 0x3633U, 0x3733U, - 0x3833U, 0x3933U, 0x6133U, 0x6233U, 0x6333U, 0x6433U, 0x6533U, 0x6633U, - 0x3034U, 0x3134U, 0x3234U, 0x3334U, 0x3434U, 0x3534U, 0x3634U, 0x3734U, - 0x3834U, 0x3934U, 0x6134U, 0x6234U, 0x6334U, 0x6434U, 0x6534U, 0x6634U, - 0x3035U, 0x3135U, 0x3235U, 0x3335U, 0x3435U, 0x3535U, 0x3635U, 0x3735U, - 0x3835U, 0x3935U, 0x6135U, 0x6235U, 0x6335U, 0x6435U, 0x6535U, 0x6635U, - 0x3036U, 0x3136U, 0x3236U, 0x3336U, 0x3436U, 0x3536U, 0x3636U, 0x3736U, - 0x3836U, 0x3936U, 0x6136U, 0x6236U, 0x6336U, 0x6436U, 0x6536U, 0x6636U, - 0x3037U, 0x3137U, 0x3237U, 0x3337U, 0x3437U, 0x3537U, 0x3637U, 0x3737U, - 0x3837U, 0x3937U, 0x6137U, 0x6237U, 0x6337U, 0x6437U, 0x6537U, 0x6637U, - 0x3038U, 0x3138U, 0x3238U, 0x3338U, 0x3438U, 0x3538U, 0x3638U, 0x3738U, - 0x3838U, 0x3938U, 0x6138U, 0x6238U, 0x6338U, 0x6438U, 0x6538U, 0x6638U, - 0x3039U, 0x3139U, 0x3239U, 0x3339U, 0x3439U, 0x3539U, 0x3639U, 0x3739U, - 0x3839U, 0x3939U, 0x6139U, 0x6239U, 0x6339U, 0x6439U, 0x6539U, 0x6639U, - 0x3061U, 0x3161U, 0x3261U, 0x3361U, 0x3461U, 0x3561U, 0x3661U, 0x3761U, - 0x3861U, 0x3961U, 0x6161U, 0x6261U, 0x6361U, 0x6461U, 0x6561U, 0x6661U, - 0x3062U, 0x3162U, 0x3262U, 0x3362U, 0x3462U, 0x3562U, 0x3662U, 0x3762U, - 0x3862U, 0x3962U, 0x6162U, 0x6262U, 0x6362U, 0x6462U, 0x6562U, 0x6662U, - 0x3063U, 0x3163U, 0x3263U, 0x3363U, 0x3463U, 0x3563U, 0x3663U, 0x3763U, - 0x3863U, 0x3963U, 0x6163U, 0x6263U, 0x6363U, 0x6463U, 0x6563U, 0x6663U, - 0x3064U, 0x3164U, 0x3264U, 0x3364U, 0x3464U, 0x3564U, 0x3664U, 0x3764U, - 0x3864U, 0x3964U, 0x6164U, 0x6264U, 0x6364U, 0x6464U, 0x6564U, 0x6664U, - 0x3065U, 0x3165U, 0x3265U, 0x3365U, 0x3465U, 0x3565U, 0x3665U, 0x3765U, - 0x3865U, 0x3965U, 0x6165U, 0x6265U, 0x6365U, 0x6465U, 0x6565U, 0x6665U, - 0x3066U, 0x3166U, 0x3266U, 0x3366U, 0x3466U, 0x3566U, 0x3666U, 0x3766U, - 0x3866U, 0x3966U, 0x6166U, 0x6266U, 0x6366U, 0x6466U, 0x6566U, 0x6666U -#endif /* DUK_USE_INTEGER_BE */ + 0x3030U, 0x3031U, 0x3032U, 0x3033U, 0x3034U, 0x3035U, 0x3036U, 0x3037U, 0x3038U, 0x3039U, 0x3061U, 0x3062U, 0x3063U, + 0x3064U, 0x3065U, 0x3066U, 0x3130U, 0x3131U, 0x3132U, 0x3133U, 0x3134U, 0x3135U, 0x3136U, 0x3137U, 0x3138U, 0x3139U, + 0x3161U, 0x3162U, 0x3163U, 0x3164U, 0x3165U, 0x3166U, 0x3230U, 0x3231U, 0x3232U, 0x3233U, 0x3234U, 0x3235U, 0x3236U, + 0x3237U, 0x3238U, 0x3239U, 0x3261U, 0x3262U, 0x3263U, 0x3264U, 0x3265U, 0x3266U, 0x3330U, 0x3331U, 0x3332U, 0x3333U, + 0x3334U, 0x3335U, 0x3336U, 0x3337U, 0x3338U, 0x3339U, 0x3361U, 0x3362U, 0x3363U, 0x3364U, 0x3365U, 0x3366U, 0x3430U, + 0x3431U, 0x3432U, 0x3433U, 0x3434U, 0x3435U, 0x3436U, 0x3437U, 0x3438U, 0x3439U, 0x3461U, 0x3462U, 0x3463U, 0x3464U, + 0x3465U, 0x3466U, 0x3530U, 0x3531U, 0x3532U, 0x3533U, 0x3534U, 0x3535U, 0x3536U, 0x3537U, 0x3538U, 0x3539U, 0x3561U, + 0x3562U, 0x3563U, 0x3564U, 0x3565U, 0x3566U, 0x3630U, 0x3631U, 0x3632U, 0x3633U, 0x3634U, 0x3635U, 0x3636U, 0x3637U, + 0x3638U, 0x3639U, 0x3661U, 0x3662U, 0x3663U, 0x3664U, 0x3665U, 0x3666U, 0x3730U, 0x3731U, 0x3732U, 0x3733U, 0x3734U, + 0x3735U, 0x3736U, 0x3737U, 0x3738U, 0x3739U, 0x3761U, 0x3762U, 0x3763U, 0x3764U, 0x3765U, 0x3766U, 0x3830U, 0x3831U, + 0x3832U, 0x3833U, 0x3834U, 0x3835U, 0x3836U, 0x3837U, 0x3838U, 0x3839U, 0x3861U, 0x3862U, 0x3863U, 0x3864U, 0x3865U, + 0x3866U, 0x3930U, 0x3931U, 0x3932U, 0x3933U, 0x3934U, 0x3935U, 0x3936U, 0x3937U, 0x3938U, 0x3939U, 0x3961U, 0x3962U, + 0x3963U, 0x3964U, 0x3965U, 0x3966U, 0x6130U, 0x6131U, 0x6132U, 0x6133U, 0x6134U, 0x6135U, 0x6136U, 0x6137U, 0x6138U, + 0x6139U, 0x6161U, 0x6162U, 0x6163U, 0x6164U, 0x6165U, 0x6166U, 0x6230U, 0x6231U, 0x6232U, 0x6233U, 0x6234U, 0x6235U, + 0x6236U, 0x6237U, 0x6238U, 0x6239U, 0x6261U, 0x6262U, 0x6263U, 0x6264U, 0x6265U, 0x6266U, 0x6330U, 0x6331U, 0x6332U, + 0x6333U, 0x6334U, 0x6335U, 0x6336U, 0x6337U, 0x6338U, 0x6339U, 0x6361U, 0x6362U, 0x6363U, 0x6364U, 0x6365U, 0x6366U, + 0x6430U, 0x6431U, 0x6432U, 0x6433U, 0x6434U, 0x6435U, 0x6436U, 0x6437U, 0x6438U, 0x6439U, 0x6461U, 0x6462U, 0x6463U, + 0x6464U, 0x6465U, 0x6466U, 0x6530U, 0x6531U, 0x6532U, 0x6533U, 0x6534U, 0x6535U, 0x6536U, 0x6537U, 0x6538U, 0x6539U, + 0x6561U, 0x6562U, 0x6563U, 0x6564U, 0x6565U, 0x6566U, 0x6630U, 0x6631U, 0x6632U, 0x6633U, 0x6634U, 0x6635U, 0x6636U, + 0x6637U, 0x6638U, 0x6639U, 0x6661U, 0x6662U, 0x6663U, 0x6664U, 0x6665U, 0x6666U +#else /* DUK_USE_INTEGER_BE */ + 0x3030U, 0x3130U, 0x3230U, 0x3330U, 0x3430U, 0x3530U, 0x3630U, 0x3730U, 0x3830U, 0x3930U, 0x6130U, 0x6230U, 0x6330U, + 0x6430U, 0x6530U, 0x6630U, 0x3031U, 0x3131U, 0x3231U, 0x3331U, 0x3431U, 0x3531U, 0x3631U, 0x3731U, 0x3831U, 0x3931U, + 0x6131U, 0x6231U, 0x6331U, 0x6431U, 0x6531U, 0x6631U, 0x3032U, 0x3132U, 0x3232U, 0x3332U, 0x3432U, 0x3532U, 0x3632U, + 0x3732U, 0x3832U, 0x3932U, 0x6132U, 0x6232U, 0x6332U, 0x6432U, 0x6532U, 0x6632U, 0x3033U, 0x3133U, 0x3233U, 0x3333U, + 0x3433U, 0x3533U, 0x3633U, 0x3733U, 0x3833U, 0x3933U, 0x6133U, 0x6233U, 0x6333U, 0x6433U, 0x6533U, 0x6633U, 0x3034U, + 0x3134U, 0x3234U, 0x3334U, 0x3434U, 0x3534U, 0x3634U, 0x3734U, 0x3834U, 0x3934U, 0x6134U, 0x6234U, 0x6334U, 0x6434U, + 0x6534U, 0x6634U, 0x3035U, 0x3135U, 0x3235U, 0x3335U, 0x3435U, 0x3535U, 0x3635U, 0x3735U, 0x3835U, 0x3935U, 0x6135U, + 0x6235U, 0x6335U, 0x6435U, 0x6535U, 0x6635U, 0x3036U, 0x3136U, 0x3236U, 0x3336U, 0x3436U, 0x3536U, 0x3636U, 0x3736U, + 0x3836U, 0x3936U, 0x6136U, 0x6236U, 0x6336U, 0x6436U, 0x6536U, 0x6636U, 0x3037U, 0x3137U, 0x3237U, 0x3337U, 0x3437U, + 0x3537U, 0x3637U, 0x3737U, 0x3837U, 0x3937U, 0x6137U, 0x6237U, 0x6337U, 0x6437U, 0x6537U, 0x6637U, 0x3038U, 0x3138U, + 0x3238U, 0x3338U, 0x3438U, 0x3538U, 0x3638U, 0x3738U, 0x3838U, 0x3938U, 0x6138U, 0x6238U, 0x6338U, 0x6438U, 0x6538U, + 0x6638U, 0x3039U, 0x3139U, 0x3239U, 0x3339U, 0x3439U, 0x3539U, 0x3639U, 0x3739U, 0x3839U, 0x3939U, 0x6139U, 0x6239U, + 0x6339U, 0x6439U, 0x6539U, 0x6639U, 0x3061U, 0x3161U, 0x3261U, 0x3361U, 0x3461U, 0x3561U, 0x3661U, 0x3761U, 0x3861U, + 0x3961U, 0x6161U, 0x6261U, 0x6361U, 0x6461U, 0x6561U, 0x6661U, 0x3062U, 0x3162U, 0x3262U, 0x3362U, 0x3462U, 0x3562U, + 0x3662U, 0x3762U, 0x3862U, 0x3962U, 0x6162U, 0x6262U, 0x6362U, 0x6462U, 0x6562U, 0x6662U, 0x3063U, 0x3163U, 0x3263U, + 0x3363U, 0x3463U, 0x3563U, 0x3663U, 0x3763U, 0x3863U, 0x3963U, 0x6163U, 0x6263U, 0x6363U, 0x6463U, 0x6563U, 0x6663U, + 0x3064U, 0x3164U, 0x3264U, 0x3364U, 0x3464U, 0x3564U, 0x3664U, 0x3764U, 0x3864U, 0x3964U, 0x6164U, 0x6264U, 0x6364U, + 0x6464U, 0x6564U, 0x6664U, 0x3065U, 0x3165U, 0x3265U, 0x3365U, 0x3465U, 0x3565U, 0x3665U, 0x3765U, 0x3865U, 0x3965U, + 0x6165U, 0x6265U, 0x6365U, 0x6465U, 0x6565U, 0x6665U, 0x3066U, 0x3166U, 0x3266U, 0x3366U, 0x3466U, 0x3566U, 0x3666U, + 0x3766U, 0x3866U, 0x3966U, 0x6166U, 0x6266U, 0x6366U, 0x6466U, 0x6566U, 0x6666U +#endif /* DUK_USE_INTEGER_BE */ }; -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ /* * Arbitrary byteswap for potentially unaligned values @@ -13482,7 +14162,7 @@ * Used to byteswap pointers e.g. in debugger code. */ -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ DUK_INTERNAL void duk_byteswap_bytes(duk_uint8_t *p, duk_small_uint_t len) { duk_uint8_t tmp; duk_uint8_t *q = p + len - 1; @@ -13496,6 +14176,18 @@ } } #endif + +/* + * Random + */ + +DUK_INTERNAL duk_double_t duk_util_get_random_double(duk_hthread *thr) { +#if defined(DUK_USE_GET_RANDOM_DOUBLE) + return DUK_USE_GET_RANDOM_DOUBLE(thr->heap->heap_udata); +#else + return duk_util_tinyrandom_get_double(thr); +#endif +} /* * Hobject ECMAScript Class. */ @@ -13592,7 +14284,7 @@ /* Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that */ DUK_INTERNAL duk_uint8_t duk_class_number_to_stridx32 = { - DUK_STRIDX_EMPTY_STRING, /* NONE, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* NONE, intentionally empty */ DUK_STRIDX_UC_OBJECT, DUK_STRIDX_UC_ARRAY, DUK_STRIDX_UC_FUNCTION, @@ -13622,8 +14314,8 @@ DUK_STRIDX_UINT32_ARRAY, DUK_STRIDX_FLOAT32_ARRAY, DUK_STRIDX_FLOAT64_ARRAY, - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ }; /* * Default allocation functions. @@ -13639,8 +14331,7 @@ void *res; DUK_UNREF(udata); res = DUK_ANSI_MALLOC(size); - DUK_DDD(DUK_DDDPRINT("default alloc function: %lu -> %p", - (unsigned long) size, (void *) res)); + DUK_DDD(DUK_DDDPRINT("default alloc function: %lu -> %p", (unsigned long) size, (void *) res)); return res; } @@ -13648,8 +14339,7 @@ void *res; DUK_UNREF(udata); res = DUK_ANSI_REALLOC(ptr, newsize); - DUK_DDD(DUK_DDDPRINT("default realloc function: %p %lu -> %p", - (void *) ptr, (unsigned long) newsize, (void *) res)); + DUK_DDD(DUK_DDDPRINT("default realloc function: %p %lu -> %p", (void *) ptr, (unsigned long) newsize, (void *) res)); return res; } @@ -13658,7 +14348,7 @@ DUK_UNREF(udata); DUK_ANSI_FREE(ptr); } -#endif /* DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS */ +#endif /* DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS */ /* * Buffer */ @@ -13748,11 +14438,11 @@ #if defined(DUK_USE_BYTECODE_DUMP_SUPPORT) -#define DUK__SER_MARKER 0xbf -#define DUK__SER_STRING 0x00 -#define DUK__SER_NUMBER 0x01 +#define DUK__SER_MARKER 0xbf +#define DUK__SER_STRING 0x00 +#define DUK__SER_NUMBER 0x01 #define DUK__BYTECODE_INITIAL_ALLOC 256 -#define DUK__NO_FORMALS 0xffffffffUL +#define DUK__NO_FORMALS 0xffffffffUL /* * Dump/load helpers, xxx_raw() helpers do no buffer checks @@ -13786,12 +14476,10 @@ DUK_ASSERT(h != NULL); len = DUK_HSTRING_GET_BYTELEN(h); - DUK_ASSERT(len <= 0xffffffffUL); /* string limits */ + DUK_ASSERT(len <= 0xffffffffUL); /* string limits */ tmp32 = (duk_uint32_t) len; DUK_RAW_WRITEINC_U32_BE(p, tmp32); - duk_memcpy((void *) p, - (const void *) DUK_HSTRING_GET_DATA(h), - len); + duk_memcpy((void *) p, (const void *) DUK_HSTRING_GET_DATA(h), len); p += len; return p; } @@ -13805,18 +14493,20 @@ DUK_UNREF(thr); len = DUK_HBUFFER_GET_SIZE(h); - DUK_ASSERT(len <= 0xffffffffUL); /* buffer limits */ + DUK_ASSERT(len <= 0xffffffffUL); /* buffer limits */ tmp32 = (duk_uint32_t) len; DUK_RAW_WRITEINC_U32_BE(p, tmp32); /* When len == 0, buffer data pointer may be NULL. */ - duk_memcpy_unsafe((void *) p, - (const void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h), - len); + duk_memcpy_unsafe((void *) p, (const void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h), len); p += len; return p; } -DUK_LOCAL duk_uint8_t *duk__dump_string_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx) { +DUK_LOCAL duk_uint8_t *duk__dump_string_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx) { duk_hstring *h_str; duk_tval *tv; @@ -13828,13 +14518,17 @@ h_str = DUK_HTHREAD_STRING_EMPTY_STRING(thr); DUK_ASSERT(h_str != NULL); } - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(h_str), p); p = duk__dump_hstring_raw(p, h_str); return p; } -DUK_LOCAL duk_uint8_t *duk__dump_buffer_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx) { +DUK_LOCAL duk_uint8_t *duk__dump_buffer_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx) { duk_tval *tv; tv = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, (duk_hobject *) func, stridx); @@ -13842,7 +14536,7 @@ duk_hbuffer *h_buf; h_buf = DUK_TVAL_GET_BUFFER(tv); DUK_ASSERT(h_buf != NULL); - DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HBUFFER_GET_SIZE(h_buf), p); p = duk__dump_hbuffer_raw(thr, p, h_buf); } else { @@ -13852,7 +14546,12 @@ return p; } -DUK_LOCAL duk_uint8_t *duk__dump_uint32_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx, duk_uint32_t def_value) { +DUK_LOCAL duk_uint8_t *duk__dump_uint32_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx, + duk_uint32_t def_value) { duk_tval *tv; duk_uint32_t val; @@ -13885,27 +14584,28 @@ duk_uint32_t val; key = DUK_HOBJECT_E_GET_KEY(thr->heap, h, i); - DUK_ASSERT(key != NULL); /* _Varmap is dense */ + DUK_ASSERT(key != NULL); /* _Varmap is dense */ DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, h, i)); tv_val = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, h, i); DUK_ASSERT(tv_val != NULL); - DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_val)); /* known to be number; in fact an integer */ + DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_val)); /* known to be number; in fact an integer */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_val)); - DUK_ASSERT(DUK_TVAL_GET_FASTINT(tv_val) == (duk_int64_t) DUK_TVAL_GET_FASTINT_U32(tv_val)); /* known to be 32-bit */ + DUK_ASSERT(DUK_TVAL_GET_FASTINT(tv_val) == + (duk_int64_t) DUK_TVAL_GET_FASTINT_U32(tv_val)); /* known to be 32-bit */ val = DUK_TVAL_GET_FASTINT_U32(tv_val); #else val = (duk_uint32_t) DUK_TVAL_GET_NUMBER(tv_val); #endif - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(key) + 4U, p); p = duk__dump_hstring_raw(p, key); DUK_RAW_WRITEINC_U32_BE(p, val); } } p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_RAW_WRITEINC_U32_BE(p, 0); /* end of _Varmap */ + DUK_RAW_WRITEINC_U32_BE(p, 0); /* end of _Varmap */ return p; } @@ -13923,7 +14623,7 @@ */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_ASSERT(h->length != DUK__NO_FORMALS); /* limits */ + DUK_ASSERT(h->length != DUK__NO_FORMALS); /* limits */ DUK_RAW_WRITEINC_U32_BE(p, h->length); for (i = 0; i < h->length; i++) { @@ -13938,14 +14638,14 @@ DUK_ASSERT(varname != NULL); DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(varname) >= 1); - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(varname), p); p = duk__dump_hstring_raw(p, varname); } } else { DUK_DD(DUK_DDPRINT("dumping function without _Formals, emit marker to indicate missing _Formals")); p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_RAW_WRITEINC_U32_BE(p, DUK__NO_FORMALS); /* marker: no formals */ + DUK_RAW_WRITEINC_U32_BE(p, DUK__NO_FORMALS); /* marker: no formals */ } return p; } @@ -13979,7 +14679,7 @@ (long) DUK_HCOMPFUNC_GET_CODE_SIZE(thr->heap, func), (long) DUK_HCOMPFUNC_GET_CODE_COUNT(thr->heap, func))); - DUK_ASSERT(DUK_USE_ESBC_MAX_BYTES <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_USE_ESBC_MAX_BYTES <= 0x7fffffffUL); /* ensures no overflow */ count_instr = (duk_uint32_t) DUK_HCOMPFUNC_GET_CODE_COUNT(thr->heap, func); p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 3U * 4U + 2U * 2U + 3U * 4U + count_instr * 4U, p); @@ -14003,8 +14703,8 @@ DUK_RAW_WRITEINC_U32_BE(p, 0); DUK_RAW_WRITEINC_U32_BE(p, 0); #endif - tmp32 = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) func); /* masks flags, only duk_hobject flags */ - tmp32 &= ~(DUK_HOBJECT_FLAG_HAVE_FINALIZER); /* finalizer flag is lost */ + tmp32 = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) func); /* masks flags, only duk_hobject flags */ + tmp32 &= ~(DUK_HOBJECT_FLAG_HAVE_FINALIZER); /* finalizer flag is lost */ DUK_RAW_WRITEINC_U32_BE(p, tmp32); /* Bytecode instructions: endian conversion needed unless @@ -14014,8 +14714,9 @@ ins_end = DUK_HCOMPFUNC_GET_CODE_END(thr->heap, func); DUK_ASSERT((duk_size_t) (ins_end - ins) == (duk_size_t) count_instr); #if defined(DUK_USE_INTEGER_BE) - duk_memcpy_unsafe((void *) p, (const void *) ins, (size_t) (ins_end - ins)); - p += (size_t) (ins_end - ins); + duk_memcpy_unsafe((void *) p, (const void *) ins, count_instr * sizeof(duk_instr_t)); + p += count_instr * sizeof(duk_instr_t); + DUK_UNREF(ins_end); #else while (ins != ins_end) { tmp32 = (duk_uint32_t) (*ins); @@ -14029,13 +14730,12 @@ tv_end = DUK_HCOMPFUNC_GET_CONSTS_END(thr->heap, func); while (tv != tv_end) { /* constants are strings or numbers now */ - DUK_ASSERT(DUK_TVAL_IS_STRING(tv) || - DUK_TVAL_IS_NUMBER(tv)); + DUK_ASSERT(DUK_TVAL_IS_STRING(tv) || DUK_TVAL_IS_NUMBER(tv)); if (DUK_TVAL_IS_STRING(tv)) { h_str = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h_str != NULL); - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 1U + 4U + DUK_HSTRING_GET_BYTELEN(h_str), p); *p++ = DUK__SER_STRING; p = duk__dump_hstring_raw(p, h_str); @@ -14101,7 +14801,8 @@ * are validated (which is quite complex, especially for indirect opcodes). */ -#define DUK__ASSERT_LEFT(n) do { \ +#define DUK__ASSERT_LEFT(n) \ + do { \ DUK_ASSERT((duk_size_t) (p_end - p) >= (duk_size_t) (n)); \ } while (0) @@ -14136,13 +14837,13 @@ count_const = DUK_RAW_READINC_U32_BE(p); count_funcs = DUK_RAW_READINC_U32_BE(p); - data_size = sizeof(duk_tval) * count_const + - sizeof(duk_hobject *) * count_funcs + - sizeof(duk_instr_t) * count_instr; + data_size = sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs + sizeof(duk_instr_t) * count_instr; DUK_DD(DUK_DDPRINT("instr=%ld, const=%ld, funcs=%ld, data_size=%ld", - (long) count_instr, (long) count_const, - (long) count_const, (long) data_size)); + (long) count_instr, + (long) count_const, + (long) count_const, + (long) data_size)); /* Value stack is used to ensure reachability of constants and * inner functions being loaded. Require enough space to handle @@ -14168,12 +14869,12 @@ h_fun->start_line = DUK_RAW_READINC_U32_BE(p); h_fun->end_line = DUK_RAW_READINC_U32_BE(p); #else - p += 8; /* skip line info */ + p += 8; /* skip line info */ #endif /* duk_hcompfunc flags; quite version specific */ tmp32 = DUK_RAW_READINC_U32_BE(p); - DUK_HEAPHDR_SET_FLAGS((duk_heaphdr *) h_fun, tmp32); /* masks flags to only change duk_hobject flags */ + DUK_HEAPHDR_SET_FLAGS((duk_heaphdr *) h_fun, tmp32); /* masks flags to only change duk_hobject flags */ /* standard prototype (no need to set here, already set) */ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_fun) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); @@ -14201,9 +14902,7 @@ DUK__ASSERT_LEFT(count_instr * sizeof(duk_instr_t)); #if defined(DUK_USE_INTEGER_BE) q = fun_data + sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs; - duk_memcpy((void *) q, - (const void *) p, - sizeof(duk_instr_t) * count_instr); + duk_memcpy((void *) q, (const void *) p, sizeof(duk_instr_t) * count_instr); p += sizeof(duk_instr_t) * count_instr; #else q = fun_data + sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs; @@ -14262,13 +14961,13 @@ DUK_HCOMPFUNC_SET_DATA(thr->heap, h_fun, h_data); DUK_HBUFFER_INCREF(thr, h_data); - tv1 = duk_get_tval(thr, idx_base + 2); /* may be NULL if no constants or inner funcs */ + tv1 = duk_get_tval(thr, idx_base + 2); /* may be NULL if no constants or inner funcs */ DUK_ASSERT((count_const == 0 && count_funcs == 0) || tv1 != NULL); q = fun_data; duk_memcpy_unsafe((void *) q, (const void *) tv1, sizeof(duk_tval) * count_const); for (n = count_const; n > 0; n--) { - DUK_TVAL_INCREF_FAST(thr, (duk_tval *) (void *) q); /* no side effects */ + DUK_TVAL_INCREF_FAST(thr, (duk_tval *) (void *) q); /* no side effects */ q += sizeof(duk_tval); } tv1 += count_const; @@ -14301,7 +15000,7 @@ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); #if defined(DUK_USE_FUNC_NAME_PROPERTY) - p = duk__load_string_raw(thr, p); /* -> func funcname */ + p = duk__load_string_raw(thr, p); /* -> func funcname */ func_env = thr->builtinsDUK_BIDX_GLOBAL_ENV; DUK_ASSERT(func_env != NULL); need_pop = 0; @@ -14312,11 +15011,10 @@ */ duk_hdecenv *new_env; - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); - DUK_ASSERT(new_env->thread == NULL); /* Closed. */ + DUK_ASSERT(new_env->thread == NULL); /* Closed. */ DUK_ASSERT(new_env->varmap == NULL); DUK_ASSERT(new_env->regbase_byteoff == 0); DUK_HDECENV_ASSERT_VALID(new_env); @@ -14328,11 +15026,11 @@ duk_push_hobject(thr, (duk_hobject *) new_env); - duk_dup_m2(thr); /* -> func funcname env funcname */ - duk_dup(thr, idx_base); /* -> func funcname env funcname func */ - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> func funcname env */ + duk_dup_m2(thr); /* -> func funcname env funcname */ + duk_dup(thr, idx_base); /* -> func funcname env funcname func */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> func funcname env */ - need_pop = 1; /* Need to pop env, but -after- updating h_fun and increfs. */ + need_pop = 1; /* Need to pop env, but -after- updating h_fun and increfs. */ } DUK_ASSERT(func_env != NULL); DUK_HCOMPFUNC_SET_LEXENV(thr->heap, h_fun, func_env); @@ -14343,12 +15041,12 @@ duk_pop(thr); } duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ #if defined(DUK_USE_FUNC_FILENAME_PROPERTY) p = duk__load_string_raw(thr, p); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_C); -#endif /* DUK_USE_FUNC_FILENAME_PROPERTY */ +#endif /* DUK_USE_FUNC_FILENAME_PROPERTY */ if (DUK_HOBJECT_HAS_CONSTRUCTABLE((duk_hobject *) h_fun)) { /* Restore empty external .prototype only for constructable @@ -14358,7 +15056,10 @@ duk_push_object(thr); DUK_ASSERT(!duk_is_bare_object(thr, -1)); duk_dup_m2(thr); - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC); /* func.prototype.constructor = func */ + duk_xdef_prop_stridx_short(thr, + -2, + DUK_STRIDX_CONSTRUCTOR, + DUK_PROPDESC_FLAGS_WC); /* func.prototype.constructor = func */ duk_compact_m1(thr); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); } @@ -14366,9 +15067,9 @@ #if defined(DUK_USE_PC2LINE) p = duk__load_buffer_raw(thr, p); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_WC); -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ - duk_push_bare_object(thr); /* _Varmap */ + duk_push_bare_object(thr); /* _Varmap */ for (;;) { /* XXX: awkward */ p = duk__load_string_raw(thr, p); @@ -14388,7 +15089,7 @@ */ arr_limit = DUK_RAW_READINC_U32_BE(p); if (arr_limit != DUK__NO_FORMALS) { - duk_push_bare_array(thr); /* _Formals */ + duk_push_bare_array(thr); /* _Formals */ for (arr_idx = 0; arr_idx < arr_limit; arr_idx++) { p = duk__load_string_raw(thr, p); duk_put_prop_index(thr, -2, arr_idx); @@ -14404,7 +15105,7 @@ DUK_ASSERT_TOP(thr, idx_base + 1); return p; - format_error: +format_error: return NULL; } @@ -14436,7 +15137,7 @@ DUK_DD(DUK_DDPRINT("serialized result: %!T", duk_get_tval(thr, -1))); - duk_remove_m2(thr); /* ... func buf -> ... buf */ + duk_remove_m2(thr); /* ... func buf -> ... buf */ } DUK_EXTERNAL void duk_load_function(duk_hthread *thr) { @@ -14469,15 +15170,15 @@ goto format_error; } - duk_remove_m2(thr); /* ... buf func -> ... func */ + duk_remove_m2(thr); /* ... buf func -> ... func */ return; - format_error: +format_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BYTECODE); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BYTECODE_DUMP_SUPPORT */ +#else /* DUK_USE_BYTECODE_DUMP_SUPPORT */ DUK_EXTERNAL void duk_dump_function(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); @@ -14491,7 +15192,7 @@ DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BYTECODE_DUMP_SUPPORT */ +#endif /* DUK_USE_BYTECODE_DUMP_SUPPORT */ /* automatic undefs */ #undef DUK__ASSERT_LEFT @@ -14553,7 +15254,7 @@ DUK_ASSERT(other >= 0); idx_func = duk_get_top(thr) - nargs - other; - if (DUK_UNLIKELY((idx_func | nargs) < 0)) { /* idx_func < 0 || nargs < 0; OR sign bits */ + if (DUK_UNLIKELY((idx_func | nargs) < 0)) { /* idx_func < 0 || nargs < 0; OR sign bits */ DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } @@ -14587,12 +15288,14 @@ DUK_ASSERT(nargs >= 0); DUK_DDD(DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_idx=%ld, nargs=%ld, stacktop=%ld", - (long) normalized_obj_idx, (long) nargs, (long) duk_get_top(thr))); + (long) normalized_obj_idx, + (long) nargs, + (long) duk_get_top(thr))); /* ... key arg1 ... argN */ /* duplicate key */ - duk_dup(thr, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */ + duk_dup(thr, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */ (void) duk_get_prop(thr, normalized_obj_idx); DUK_DDD(DUK_DDDPRINT("func: %!T", (duk_tval *) duk_get_tval(thr, -1))); @@ -14635,7 +15338,7 @@ duk_insert_undefined(thr, idx_func + 1); - call_flags = 0; /* not protected, respect reclimit, not constructor */ + call_flags = 0; /* not protected, respect reclimit, not constructor */ duk_handle_call_unprotected(thr, idx_func, call_flags); } @@ -14648,7 +15351,7 @@ idx_func = duk__call_get_idx_func(thr, nargs, 2); DUK_ASSERT(duk_is_valid_index(thr, idx_func)); - call_flags = 0; /* not protected, respect reclimit, not constructor */ + call_flags = 0; /* not protected, respect reclimit, not constructor */ duk_handle_call_unprotected(thr, idx_func, call_flags); } @@ -14662,7 +15365,7 @@ DUK_ASSERT_API_ENTRY(thr); - obj_idx = duk_require_normalize_index(thr, obj_idx); /* make absolute */ + obj_idx = duk_require_normalize_index(thr, obj_idx); /* make absolute */ if (DUK_UNLIKELY(nargs < 0)) { DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return;); @@ -14760,7 +15463,7 @@ args = (duk__pcall_prop_args *) udata; - obj_idx = duk_require_normalize_index(thr, args->obj_idx); /* make absolute */ + obj_idx = duk_require_normalize_index(thr, args->obj_idx); /* make absolute */ duk__call_prop_prep_stack(thr, obj_idx, args->nargs); ret = duk_handle_call_unprotected_nargs(thr, args->nargs, args->call_flags); @@ -14798,30 +15501,30 @@ */ /* XXX: check for any reserve? */ - if (DUK_UNLIKELY((nargs | nrets) < 0 || /* nargs < 0 || nrets < 0; OR sign bits */ - thr->valstack_top < thr->valstack_bottom + nargs || /* nargs too large compared to top */ - thr->valstack_end + nargs < thr->valstack_top + nrets)) { /* nrets too large compared to reserve */ + if (DUK_UNLIKELY((nargs | nrets) < 0 || /* nargs < 0 || nrets < 0; OR sign bits */ + thr->valstack_top < thr->valstack_bottom + nargs || /* nargs too large compared to top */ + thr->valstack_end + nargs < thr->valstack_top + nrets)) { /* nrets too large compared to reserve */ DUK_D(DUK_DPRINT("not enough stack reserve for safe call or invalid arguments: " "nargs=%ld < 0 (?), nrets=%ld < 0 (?), top=%ld < bottom=%ld + nargs=%ld (?), " "end=%ld + nargs=%ld < top=%ld + nrets=%ld (?)", - (long) nargs, - (long) nrets, - (long) (thr->valstack_top - thr->valstack), - (long) (thr->valstack_bottom - thr->valstack), - (long) nargs, - (long) (thr->valstack_end - thr->valstack), - (long) nargs, - (long) (thr->valstack_top - thr->valstack), - (long) nrets)); + (long) nargs, + (long) nrets, + (long) (thr->valstack_top - thr->valstack), + (long) (thr->valstack_bottom - thr->valstack), + (long) nargs, + (long) (thr->valstack_end - thr->valstack), + (long) nargs, + (long) (thr->valstack_top - thr->valstack), + (long) nrets)); DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return DUK_EXEC_ERROR;); } - rc = duk_handle_safe_call(thr, /* thread */ - func, /* func */ - udata, /* udata */ - nargs, /* num_stack_args */ - nrets); /* num_stack_res */ + rc = duk_handle_safe_call(thr, /* thread */ + func, /* func */ + udata, /* udata */ + nargs, /* num_stack_args */ + nrets); /* num_stack_res */ return rc; } @@ -14834,7 +15537,7 @@ idx_func = duk__call_get_idx_func(thr, nargs, 1); DUK_ASSERT(duk_is_valid_index(thr, idx_func)); - duk_push_object(thr); /* default instance; internal proto updated by call handling */ + duk_push_object(thr); /* default instance; internal proto updated by call handling */ duk_insert(thr, idx_func + 1); duk_handle_call_unprotected(thr, idx_func, DUK_CALL_FLAG_CONSTRUCT); @@ -14962,7 +15665,7 @@ } /* fall through */ - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_UNEXPECTED_TYPE); DUK_WO_NORETURN(return 0;); } @@ -15036,15 +15739,16 @@ * is guaranteed to be non-NULL, even for zero length input. */ DUK_LOCAL const duk_uint8_t *duk__prep_codec_arg(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) { - const void *def_ptr = (const void *) out_len; /* Any non-NULL pointer will do. */ + const void *def_ptr = (const void *) out_len; /* Any non-NULL pointer will do. */ const void *ptr; duk_bool_t isbuffer; DUK_ASSERT(out_len != NULL); DUK_ASSERT(def_ptr != NULL); - DUK_ASSERT(duk_is_valid_index(thr, idx)); /* checked by caller */ + DUK_ASSERT(duk_is_valid_index(thr, idx)); /* checked by caller */ - ptr = (const void *) duk_get_buffer_data_raw(thr, idx, out_len, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, &isbuffer); + ptr = (const void *) + duk_get_buffer_data_raw(thr, idx, out_len, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, &isbuffer); if (isbuffer) { DUK_ASSERT(ptr != NULL || *out_len == 0U); if (DUK_UNLIKELY(ptr == NULL)) { @@ -15069,21 +15773,21 @@ #if defined(DUK_USE_BASE64_SUPPORT) /* Bytes emitted for number of padding characters in range 0,4. */ DUK_LOCAL const duk_int8_t duk__base64_decode_nequal_step5 = { - 3, /* #### -> 24 bits, emit 3 bytes */ - 2, /* ###= -> 18 bits, emit 2 bytes */ - 1, /* ##== -> 12 bits, emit 1 byte */ - -1, /* #=== -> 6 bits, error */ - 0, /* ==== -> 0 bits, emit 0 bytes */ + 3, /* #### -> 24 bits, emit 3 bytes */ + 2, /* ###= -> 18 bits, emit 2 bytes */ + 1, /* ##== -> 12 bits, emit 1 byte */ + -1, /* #=== -> 6 bits, error */ + 0, /* ==== -> 0 bits, emit 0 bytes */ }; #if defined(DUK_USE_BASE64_FASTPATH) DUK_LOCAL const duk_uint8_t duk__base64_enctab_fast64 = { - 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x50U, /* A...P */ - 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x58U, 0x59U, 0x5aU, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, /* Q...f */ - 0x67U, 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, 0x6fU, 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, /* g...v */ - 0x77U, 0x78U, 0x79U, 0x7aU, 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x2bU, 0x2fU /* w.../ */ + 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x50U, /* A...P */ + 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x58U, 0x59U, 0x5aU, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, /* Q...f */ + 0x67U, 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, 0x6fU, 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, /* g...v */ + 0x77U, 0x78U, 0x79U, 0x7aU, 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x2bU, 0x2fU /* w.../ */ }; -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) /* Decode table for one byte of input: @@ -15093,24 +15797,24 @@ * 0...63 decoded bytes */ DUK_LOCAL const duk_int8_t duk__base64_dectab_fast256 = { - -3, -3, -3, -3, -3, -3, -3, -3, -3, -1, -1, -3, -3, -1, -3, -3, /* 0x00...0x0f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x10...0x1f */ - -1, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 62, -3, -3, -3, 63, /* 0x20...0x2f */ - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -3, -3, -3, -2, -3, -3, /* 0x30...0x3f */ - -3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40...0x4f */ - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -3, -3, -3, -3, -3, /* 0x50...0x5f */ - -3, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60...0x6f */ - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -3, -3, -3, -3, -3, /* 0x70...0x7f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x80...0x8f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x90...0x9f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xa0...0xaf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xb0...0xbf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xc0...0xcf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xd0...0xdf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xe0...0xef */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3 /* 0xf0...0xff */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -1, -1, -3, -3, -1, -3, -3, /* 0x00...0x0f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x10...0x1f */ + -1, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 62, -3, -3, -3, 63, /* 0x20...0x2f */ + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -3, -3, -3, -2, -3, -3, /* 0x30...0x3f */ + -3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40...0x4f */ + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -3, -3, -3, -3, -3, /* 0x50...0x5f */ + -3, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60...0x6f */ + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -3, -3, -3, -3, -3, /* 0x70...0x7f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x80...0x8f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x90...0x9f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xa0...0xaf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xb0...0xbf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xc0...0xcf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xd0...0xdf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xe0...0xef */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3 /* 0xf0...0xff */ }; -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) DUK_LOCAL DUK_ALWAYS_INLINE void duk__base64_encode_fast_3(const duk_uint8_t *src, duk_uint8_t *dst) { @@ -15142,9 +15846,9 @@ t = (duk_uint_t) src0; t = (t << 8) + (duk_uint_t) src1; - dst0 = duk__base64_enctab_fastt >> 10; /* XXXXXX-- -------- */ - dst1 = duk__base64_enctab_fast(t >> 4) & 0x3fU; /* ------XX XXXX---- */ - dst2 = duk__base64_enctab_fast(t << 2) & 0x3fU; /* -------- ----XXXX */ + dst0 = duk__base64_enctab_fastt >> 10; /* XXXXXX-- -------- */ + dst1 = duk__base64_enctab_fast(t >> 4) & 0x3fU; /* ------XX XXXX---- */ + dst2 = duk__base64_enctab_fast(t << 2) & 0x3fU; /* -------- ----XXXX */ dst3 = DUK_ASC_EQUALS; } @@ -15152,8 +15856,8 @@ duk_uint_t t; t = (duk_uint_t) src0; - dst0 = duk__base64_enctab_fastt >> 2; /* XXXXXX-- */ - dst1 = duk__base64_enctab_fast(t << 4) & 0x3fU; /* ------XX */ + dst0 = duk__base64_enctab_fastt >> 2; /* XXXXXX-- */ + dst1 = duk__base64_enctab_fast(t << 4) & 0x3fU; /* ------XX */ dst2 = DUK_ASC_EQUALS; dst3 = DUK_ASC_EQUALS; } @@ -15201,24 +15905,24 @@ DUK_ASSERT(n == 0U || n == 1U || n == 2U); if (n == 1U) { duk__base64_encode_fast_1(p, q); -#if 0 /* Unnecessary. */ +#if 0 /* Unnecessary. */ p += 1; q += 4; n -= 1U; #endif } else if (n == 2U) { duk__base64_encode_fast_2(p, q); -#if 0 /* Unnecessary. */ +#if 0 /* Unnecessary. */ p += 2; q += 4; n -= 2U; #endif } else { - DUK_ASSERT(n == 0U); /* nothing to do */ + DUK_ASSERT(n == 0U); /* nothing to do */ ; } } -#else /* DUK_USE_BASE64_FASTPATH */ +#else /* DUK_USE_BASE64_FASTPATH */ DUK_LOCAL void duk__base64_encode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst) { duk_small_uint_t i, npad; duk_uint_t t, x, y; @@ -15290,10 +15994,13 @@ npad--; } } -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) -DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst, duk_uint8_t **out_dst_final) { +DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, + duk_size_t srclen, + duk_uint8_t *dst, + duk_uint8_t **out_dst_final) { duk_int_t x; duk_uint_t t; duk_small_uint_t n_equal; @@ -15303,11 +16010,11 @@ const duk_uint8_t *p_end_safe; duk_uint8_t *q; - DUK_ASSERT(src != NULL); /* Required by pointer arithmetic below, which fails for NULL. */ + DUK_ASSERT(src != NULL); /* Required by pointer arithmetic below, which fails for NULL. */ p = src; p_end = src + srclen; - p_end_safe = p_end - 8; /* If 'src <= src_end_safe', safe to read 8 bytes. */ + p_end_safe = p_end - 8; /* If 'src <= src_end_safe', safe to read 8 bytes. */ q = dst; /* Alternate between a fast path which processes clean groups with no @@ -15337,7 +16044,9 @@ * bytes to minimize aliasing. */ DUK_DDD(DUK_DDDPRINT("fast loop: p=%p, p_end_safe=%p, p_end=%p", - (const void *) p, (const void *) p_end_safe, (const void *) p_end)); + (const void *) p, + (const void *) p_end_safe, + (const void *) p_end)); t1 = (duk_int_t) duk__base64_dectab_fastp0; t1 = (duk_int_t) ((duk_uint_t) t1 << 6) | (duk_int_t) duk__base64_dectab_fastp1; @@ -15362,17 +16071,19 @@ p += 8; q += 6; } else if (t1 >= 0) { - DUK_DDD(DUK_DDDPRINT("fast loop first group was clean, second was not, process one slow path group")); + DUK_DDD( + DUK_DDDPRINT("fast loop first group was clean, second was not, process one slow path group")); DUK_ASSERT(t2 < 0); p += 4; q += 3; break; } else { - DUK_DDD(DUK_DDDPRINT("fast loop first group was not clean, second does not matter, process one slow path group")); + DUK_DDD(DUK_DDDPRINT( + "fast loop first group was not clean, second does not matter, process one slow path group")); DUK_ASSERT(t1 < 0); break; } - } /* fast path */ + } /* fast path */ /* Slow path step 1: try to scan a 4-character encoded group, * end-of-input, or start-of-padding. We exit with: @@ -15387,7 +16098,9 @@ t = 1UL; for (;;) { DUK_DDD(DUK_DDDPRINT("slow loop: p=%p, p_end=%p, t=%lu", - (const void *) p, (const void *) p_end, (unsigned long) t)); + (const void *) p, + (const void *) p_end, + (unsigned long) t)); if (DUK_LIKELY(p < p_end)) { x = duk__base64_dectab_fast*p++; @@ -15398,18 +16111,18 @@ break; } } else if (x == -1) { - continue; /* allowed ascii whitespace */ + continue; /* allowed ascii whitespace */ } else if (x == -2) { p--; - break; /* start of padding */ + break; /* start of padding */ } else { DUK_ASSERT(x == -3); goto decode_error; } } else { - break; /* end of input */ + break; /* end of input */ } - } /* slow path step 1 */ + } /* slow path step 1 */ /* Complete the padding by simulating pad characters, * regardless of actual input padding chars. @@ -15468,28 +16181,30 @@ } x = duk__base64_dectab_fast*p++; if (x == -1 || x == -2) { - ; /* padding or whitespace, keep eating */ + ; /* padding or whitespace, keep eating */ } else { p--; - break; /* backtrack and go back to fast path, even for -1 */ + break; /* backtrack and go back to fast path, even for -1 */ } - } /* slow path step 3 */ - } /* outer fast+slow path loop */ + } /* slow path step 3 */ + } /* outer fast+slow path loop */ - done: - DUK_DDD(DUK_DDDPRINT("done; p=%p, p_end=%p", - (const void *) p, (const void *) p_end)); +done: + DUK_DDD(DUK_DDDPRINT("done; p=%p, p_end=%p", (const void *) p, (const void *) p_end)); DUK_ASSERT(p == p_end); *out_dst_final = q; return 1; - decode_error: +decode_error: return 0; } -#else /* DUK_USE_BASE64_FASTPATH */ -DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst, duk_uint8_t **out_dst_final) { +#else /* DUK_USE_BASE64_FASTPATH */ +DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, + duk_size_t srclen, + duk_uint8_t *dst, + duk_uint8_t **out_dst_final) { duk_uint_t t, x; duk_int_t y; duk_int8_t step; @@ -15575,7 +16290,7 @@ } else { /* Valid: whitespace. */ duk_uint32_t m; - DUK_ASSERT(x < 0x20U); /* 0x00 to 0x1f */ + DUK_ASSERT(x < 0x20U); /* 0x00 to 0x1f */ m = (1U << x); if (mask_white & m) { /* Allow basic ASCII whitespace. */ @@ -15592,7 +16307,7 @@ } /* fall through; no padding will be added */ - simulate_padding: + simulate_padding: n_equal = 0; while (t < 0x1000000UL) { t = (t << 6) + 0U; @@ -15624,10 +16339,10 @@ *out_dst_final = q; return 1; - decode_error: +decode_error: return 0; } -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ DUK_EXTERNAL const char *duk_base64_encode(duk_hthread *thr, duk_idx_t idx) { const duk_uint8_t *src; @@ -15656,11 +16371,11 @@ duk__base64_encode_helper((const duk_uint8_t *) src, srclen, dst); - ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ + ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ duk_replace(thr, idx); return ret; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_BASE64_ENCODE_FAILED); DUK_WO_NORETURN(return NULL;); } @@ -15685,7 +16400,7 @@ * Similarly, 'xx' may ecause 1+3 = bytes to be emitted and then * backtracked. */ - dstlen = (srclen / 4) * 3 + 6; /* upper limit, assuming no whitespace etc */ + dstlen = (srclen / 4) * 3 + 6; /* upper limit, assuming no whitespace etc */ dst = (duk_uint8_t *) duk_push_dynamic_buffer(thr, dstlen); /* Note: for dstlen=0, dst may be NULL */ @@ -15698,11 +16413,11 @@ duk_replace(thr, idx); return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_BASE64_DECODE_FAILED); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BASE64_SUPPORT */ +#else /* DUK_USE_BASE64_SUPPORT */ DUK_EXTERNAL const char *duk_base64_encode(duk_hthread *thr, duk_idx_t idx) { DUK_UNREF(idx); DUK_ERROR_UNSUPPORTED(thr); @@ -15714,7 +16429,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BASE64_SUPPORT */ +#endif /* DUK_USE_BASE64_SUPPORT */ /* * Hex @@ -15743,7 +16458,7 @@ DUK_ASSERT(buf != NULL); #if defined(DUK_USE_HEX_FASTPATH) - DUK_ASSERT((((duk_size_t) buf) & 0x01U) == 0); /* pointer is aligned, guaranteed for fixed buffer */ + DUK_ASSERT((((duk_size_t) buf) & 0x01U) == 0); /* pointer is aligned, guaranteed for fixed buffer */ p16 = (duk_uint16_t *) (void *) buf; len_safe = len & ~0x03U; for (i = 0; i < len_safe; i += 4) { @@ -15756,14 +16471,14 @@ for (; i < len; i++) { *p16++ = duk_hex_enctabinpi; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ for (i = 0; i < len; i++) { duk_small_uint_t t; t = (duk_small_uint_t) inpi; - bufi*2 + 0 = duk_lc_digitst >> 4; - bufi*2 + 1 = duk_lc_digitst & 0x0f; + bufi * 2 + 0 = duk_lc_digitst >> 4; + bufi * 2 + 1 = duk_lc_digitst & 0x0f; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ /* XXX: Using a string return value forces a string intern which is * not always necessary. As a rough performance measure, hex encode @@ -15772,7 +16487,7 @@ * caller coerce to string if necessary? */ - ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ + ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ duk_replace(thr, idx); return ret; } @@ -15807,20 +16522,16 @@ p = buf; len_safe = len & ~0x07U; for (i = 0; i < len_safe; i += 8) { - t = ((duk_int_t) duk_hex_dectab_shift4inpi) | - ((duk_int_t) duk_hex_dectabinpi + 1); + t = ((duk_int_t) duk_hex_dectab_shift4inpi) | ((duk_int_t) duk_hex_dectabinpi + 1); chk = t; p0 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 2) | - ((duk_int_t) duk_hex_dectabinpi + 3); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 2) | ((duk_int_t) duk_hex_dectabinpi + 3); chk |= t; p1 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 4) | - ((duk_int_t) duk_hex_dectabinpi + 5); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 4) | ((duk_int_t) duk_hex_dectabinpi + 5); chk |= t; p2 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 6) | - ((duk_int_t) duk_hex_dectabinpi + 7); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 6) | ((duk_int_t) duk_hex_dectabinpi + 7); chk |= t; p3 = (duk_uint8_t) t; p += 4; @@ -15842,7 +16553,7 @@ } *p++ = (duk_uint8_t) t; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ for (i = 0; i < len; i += 2) { /* For invalid characters the value -1 gets extended to * at least 16 bits. If either nybble is invalid, the @@ -15855,16 +16566,16 @@ } bufi >> 1 = (duk_uint8_t) t; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ duk_replace(thr, idx); return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_HEX_DECODE_FAILED); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_HEX_SUPPORT */ +#else /* DUK_USE_HEX_SUPPORT */ DUK_EXTERNAL const char *duk_hex_encode(duk_hthread *thr, duk_idx_t idx) { DUK_UNREF(idx); DUK_ERROR_UNSUPPORTED(thr); @@ -15875,7 +16586,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_HEX_SUPPORT */ +#endif /* DUK_USE_HEX_SUPPORT */ /* * JSON @@ -15919,15 +16630,12 @@ #endif idx = duk_require_normalize_index(thr, idx); - duk_bi_json_parse_helper(thr, - idx /*idx_value*/, - DUK_INVALID_INDEX /*idx_reviver*/, - 0 /*flags*/); + duk_bi_json_parse_helper(thr, idx /*idx_value*/, DUK_INVALID_INDEX /*idx_reviver*/, 0 /*flags*/); duk_replace(thr, idx); DUK_ASSERT(duk_get_top(thr) == top_at_entry); } -#else /* DUK_USE_JSON_SUPPORT */ +#else /* DUK_USE_JSON_SUPPORT */ DUK_EXTERNAL const char *duk_json_encode(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx); @@ -15941,7 +16649,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */ /* * Compilation and evaluation */ @@ -15950,7 +16658,7 @@ typedef struct duk__compile_raw_args duk__compile_raw_args; struct duk__compile_raw_args { - duk_size_t src_length; /* should be first on 64-bit platforms */ + duk_size_t src_length; /* should be first on 64-bit platforms */ const duk_uint8_t *src_buffer; duk_uint_t flags; }; @@ -15970,7 +16678,10 @@ /* ... source? filename? (depends on flags) */ - rc = duk_compile_raw(thr, src_buffer, src_length, flags | DUK_COMPILE_EVAL); /* may be safe, or non-safe depending on flags */ + rc = duk_compile_raw(thr, + src_buffer, + src_length, + flags | DUK_COMPILE_EVAL); /* may be safe, or non-safe depending on flags */ /* ... closure/error */ @@ -15979,7 +16690,7 @@ goto got_rc; } - duk_push_global_object(thr); /* explicit 'this' binding, see GH-164 */ + duk_push_global_object(thr); /* explicit 'this' binding, see GH-164 */ if (flags & DUK_COMPILE_SAFE) { rc = duk_pcall_method(thr, 0); @@ -15990,7 +16701,7 @@ /* ... result/error */ - got_rc: +got_rc: if (flags & DUK_COMPILE_NORESULT) { duk_pop(thr); } @@ -16030,8 +16741,8 @@ duk_hstring *h_sourcecode; h_sourcecode = duk_get_hstring(thr, -2); - if ((flags & DUK_COMPILE_NOSOURCE) || /* args incorrect */ - (h_sourcecode == NULL)) { /* e.g. duk_push_string_file_raw() pushed undefined */ + if ((flags & DUK_COMPILE_NOSOURCE) || /* args incorrect */ + (h_sourcecode == NULL)) { /* e.g. duk_push_string_file_raw() pushed undefined */ DUK_ERROR_TYPE(thr, DUK_STR_NO_SOURCECODE); DUK_WO_NORETURN(return 0;); } @@ -16061,11 +16772,11 @@ h_templ = (duk_hcompfunc *) duk_known_hobject(thr, -1); duk_js_push_closure(thr, - h_templ, - thr->builtinsDUK_BIDX_GLOBAL_ENV, - thr->builtinsDUK_BIDX_GLOBAL_ENV, - 1 /*add_auto_proto*/); - duk_remove_m2(thr); /* -> ... closure */ + h_templ, + thr->builtinsDUK_BIDX_GLOBAL_ENV, + thr->builtinsDUK_BIDX_GLOBAL_ENV, + 1 /*add_auto_proto*/); + duk_remove_m2(thr); /* -> ... closure */ /* ... closure */ @@ -16101,8 +16812,7 @@ * directly into flags. */ nargs = flags & 0x07; - DUK_ASSERT(nargs == ((flags & DUK_COMPILE_NOSOURCE) ? 0 : 1) + - ((flags & DUK_COMPILE_NOFILENAME) ? 0 : 1)); + DUK_ASSERT(nargs == ((flags & DUK_COMPILE_NOSOURCE) ? 0 : 1) + ((flags & DUK_COMPILE_NOFILENAME) ? 0 : 1)); rc = duk_safe_call(thr, duk__do_compile, (void *) comp_args, nargs, nrets); /* ... closure */ @@ -16142,25 +16852,24 @@ * Perhaps values need to be coerced individually? */ duk_bi_json_stringify_helper(thr, - duk_get_top_index(thr), /*idx_value*/ - DUK_INVALID_INDEX, /*idx_replacer*/ - DUK_INVALID_INDEX, /*idx_space*/ - DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_ASCII_ONLY | - DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); + duk_get_top_index(thr), /*idx_value*/ + DUK_INVALID_INDEX, /*idx_replacer*/ + DUK_INVALID_INDEX, /*idx_space*/ + DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_ASCII_ONLY | + DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); duk_push_sprintf(thr, "ctx: top=%ld, stack=%s", (long) top, (const char *) duk_safe_to_string(thr, -1)); - duk_replace(thr, -3); /* ... arr jsonx(arr) res -> ... res jsonx(arr) */ + duk_replace(thr, -3); /* ... arr jsonx(arr) res -> ... res jsonx(arr) */ duk_pop(thr); DUK_ASSERT(duk_is_string(thr, -1)); } -#else /* DUK_USE_JSON_SUPPORT */ +#else /* DUK_USE_JSON_SUPPORT */ DUK_EXTERNAL void duk_push_context_dump(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */ #if defined(DUK_USE_DEBUGGER_SUPPORT) @@ -16209,12 +16918,13 @@ heap->dbg_exec_counter = 0; heap->dbg_last_counter = 0; heap->dbg_last_time = 0.0; - duk_debug_set_paused(heap); /* XXX: overlap with fields above */ + duk_debug_set_paused(heap); /* XXX: overlap with fields above */ /* Send version identification and flush right afterwards. Note that * we must write raw, unframed bytes here. */ - duk_push_sprintf(thr, "%ld %ld %s %s\n", + duk_push_sprintf(thr, + "%ld %ld %s %s\n", (long) DUK_DEBUG_PROTOCOL_VERSION, (long) DUK_VERSION, (const char *) DUK_GIT_DESCRIBE, @@ -16316,7 +17026,7 @@ } } -#else /* DUK_USE_DEBUGGER_SUPPORT */ +#else /* DUK_USE_DEBUGGER_SUPPORT */ DUK_EXTERNAL void duk_debugger_attach(duk_hthread *thr, duk_debug_read_function read_cb, @@ -16374,7 +17084,7 @@ DUK_UNREF(thr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Heap creation and destruction */ @@ -16462,7 +17172,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(state != NULL); /* unvalidated */ + DUK_ASSERT(state != NULL); /* unvalidated */ /* Currently not supported when called from within a finalizer. * If that is done, the finalizer will remain running indefinitely, @@ -16506,7 +17216,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(state != NULL); /* unvalidated */ + DUK_ASSERT(state != NULL); /* unvalidated */ /* Shouldn't be necessary if duk_suspend() is called before * duk_resume(), but assert in case API sequence is incorrect. @@ -16548,7 +17258,7 @@ DUK_UNREF(h_prev_glob); thr->builtinsDUK_BIDX_GLOBAL = h_glob; DUK_HOBJECT_INCREF(thr, h_glob); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_glob); /* side effects, in theory (referenced by global env) */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_glob); /* side effects, in theory (referenced by global env) */ /* * Replace lexical environment for global scope @@ -16559,9 +17269,7 @@ * same (initial) built-ins. */ - h_env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + h_env = duk_hobjenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(h_env != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_env) == NULL); @@ -16576,8 +17284,8 @@ h_prev_env = thr->builtinsDUK_BIDX_GLOBAL_ENV; thr->builtinsDUK_BIDX_GLOBAL_ENV = (duk_hobject *) h_env; DUK_HOBJECT_INCREF(thr, (duk_hobject *) h_env); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_env); /* side effects */ - DUK_UNREF(h_env); /* without refcounts */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_env); /* side effects */ + DUK_UNREF(h_env); /* without refcounts */ DUK_UNREF(h_prev_env); /* ... new_glob */ @@ -16627,20 +17335,20 @@ * be security implications. */ -#define DUK__IDX_TYPE 0 -#define DUK__IDX_ITAG 1 -#define DUK__IDX_REFC 2 -#define DUK__IDX_HBYTES 3 -#define DUK__IDX_CLASS 4 -#define DUK__IDX_PBYTES 5 -#define DUK__IDX_ESIZE 6 -#define DUK__IDX_ENEXT 7 -#define DUK__IDX_ASIZE 8 -#define DUK__IDX_HSIZE 9 -#define DUK__IDX_BCBYTES 10 -#define DUK__IDX_DBYTES 11 -#define DUK__IDX_TSTATE 12 -#define DUK__IDX_VARIANT 13 +#define DUK__IDX_TYPE 0 +#define DUK__IDX_ITAG 1 +#define DUK__IDX_REFC 2 +#define DUK__IDX_HBYTES 3 +#define DUK__IDX_CLASS 4 +#define DUK__IDX_PBYTES 5 +#define DUK__IDX_ESIZE 6 +#define DUK__IDX_ENEXT 7 +#define DUK__IDX_ASIZE 8 +#define DUK__IDX_HSIZE 9 +#define DUK__IDX_BCBYTES 10 +#define DUK__IDX_DBYTES 11 +#define DUK__IDX_TSTATE 12 +#define DUK__IDX_VARIANT 13 DUK_EXTERNAL void duk_inspect_value(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; @@ -16655,7 +17363,7 @@ /* Assume two's complement and set everything to -1. */ duk_memset((void *) &vals, (int) 0xff, sizeof(vals)); - DUK_ASSERT(valsDUK__IDX_TYPE == -1); /* spot check one */ + DUK_ASSERT(valsDUK__IDX_TYPE == -1); /* spot check one */ tv = duk_get_tval_or_unused(thr, idx); h = (DUK_TVAL_IS_HEAP_ALLOCATED(tv) ? DUK_TVAL_GET_HEAPHDR(tv) : NULL); @@ -16663,7 +17371,7 @@ valsDUK__IDX_TYPE = duk_get_type_tval(tv); valsDUK__IDX_ITAG = (duk_int_t) DUK_TVAL_GET_TAG(tv); - duk_push_bare_object(thr); /* Invalidates 'tv'. */ + duk_push_bare_object(thr); /* Invalidates 'tv'. */ tv = NULL; if (h == NULL) { @@ -16745,30 +17453,56 @@ if (DUK_HBUFFER_HAS_DYNAMIC(h_buf)) { if (DUK_HBUFFER_HAS_EXTERNAL(h_buf)) { - valsDUK__IDX_VARIANT = 2; /* buffer variant 2: external */ + valsDUK__IDX_VARIANT = 2; /* buffer variant 2: external */ valsDUK__IDX_HBYTES = (duk_uint_t) (sizeof(duk_hbuffer_external)); } else { /* When alloc_size == 0 the second allocation may not * actually exist. */ - valsDUK__IDX_VARIANT = 1; /* buffer variant 1: dynamic */ + valsDUK__IDX_VARIANT = 1; /* buffer variant 1: dynamic */ valsDUK__IDX_HBYTES = (duk_uint_t) (sizeof(duk_hbuffer_dynamic)); } valsDUK__IDX_DBYTES = (duk_int_t) (DUK_HBUFFER_GET_SIZE(h_buf)); } else { - DUK_ASSERT(valsDUK__IDX_VARIANT == 0); /* buffer variant 0: fixed */ + DUK_ASSERT(valsDUK__IDX_VARIANT == 0); /* buffer variant 0: fixed */ valsDUK__IDX_HBYTES = (duk_int_t) (sizeof(duk_hbuffer_fixed) + DUK_HBUFFER_GET_SIZE(h_buf)); } break; } } - finish: +finish: duk__inspect_multiple_uint(thr, - "type" "\x00" "itag" "\x00" "refc" "\x00" "hbytes" "\x00" "class" "\x00" - "pbytes" "\x00" "esize" "\x00" "enext" "\x00" "asize" "\x00" "hsize" "\x00" - "bcbytes" "\x00" "dbytes" "\x00" "tstate" "\x00" "variant" "\x00" "\x00", - (duk_int_t *) &vals); + "type" + "\x00" + "itag" + "\x00" + "refc" + "\x00" + "hbytes" + "\x00" + "class" + "\x00" + "pbytes" + "\x00" + "esize" + "\x00" + "enext" + "\x00" + "asize" + "\x00" + "hsize" + "\x00" + "bcbytes" + "\x00" + "dbytes" + "\x00" + "tstate" + "\x00" + "variant" + "\x00" + "\x00", + (duk_int_t *) &vals); } DUK_EXTERNAL void duk_inspect_callstack_entry(duk_hthread *thr, duk_int_t level) { @@ -16907,7 +17641,7 @@ DUK_ASSERT(heap != NULL); DUK_D(DUK_DPRINT("mark-and-sweep requested by application")); - DUK_ASSERT(DUK_GC_COMPACT == DUK_MS_FLAG_EMERGENCY); /* Compact flag is 1:1 with emergency flag which forces compaction. */ + DUK_ASSERT(DUK_GC_COMPACT == DUK_MS_FLAG_EMERGENCY); /* Compact flag is 1:1 with emergency flag which forces compaction. */ ms_flags = (duk_small_uint_t) flags; duk_heap_mark_and_sweep(heap, ms_flags); } @@ -16943,9 +17677,9 @@ DUK_ASSERT(rc == 0 || rc == 1); /* a value is left on stack regardless of rc */ - duk_remove_m2(thr); /* remove key */ + duk_remove_m2(thr); /* remove key */ DUK_ASSERT(duk_is_undefined(thr, -1) || rc == 1); - return rc; /* 1 if property found, 0 otherwise */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_get_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) { @@ -16990,7 +17724,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_get_prop(thr, obj_idx); } @@ -17004,11 +17738,13 @@ } DUK_INTERNAL duk_bool_t duk_get_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_get_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), - (duk_small_uint_t) (packed_args & 0xffffUL)); + return duk_get_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } -DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop) { +DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_bool_t *out_has_prop) { duk_bool_t rc; DUK_ASSERT_API_ENTRY(thr); @@ -17053,7 +17789,7 @@ } duk_push_tval(thr, tv_val); - duk_remove_m2(thr); /* remove key */ + duk_remove_m2(thr); /* remove key */ return 1; } @@ -17068,7 +17804,8 @@ } DUK_INTERNAL duk_bool_t duk_xget_owndataprop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_xget_owndataprop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), + return duk_xget_owndataprop_stridx(thr, + (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } @@ -17087,8 +17824,7 @@ /* Key and value indices are either (-2, -1) or (-1, -2). Given idx_key, * idx_val is always (idx_key ^ 0x01). */ - DUK_ASSERT((idx_key == -2 && (idx_key ^ 1) == -1) || - (idx_key == -1 && (idx_key ^ 1) == -2)); + DUK_ASSERT((idx_key == -2 && (idx_key ^ 1) == -1) || (idx_key == -1 && (idx_key ^ 1) == -2)); /* XXX: Direct access; faster validation. */ tv_obj = duk_require_tval(thr, obj_idx); tv_key = duk_require_tval(thr, idx_key); @@ -17098,8 +17834,8 @@ rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, throw_flag); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop_2(thr); /* remove key and value */ - return rc; /* 1 if property found, 0 otherwise */ + duk_pop_2(thr); /* remove key and value */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_put_prop(duk_hthread *thr, duk_idx_t obj_idx) { @@ -17153,11 +17889,10 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk__put_prop_shared(thr, obj_idx, -1); } - DUK_INTERNAL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT_STRIDX_VALID(stridx); @@ -17168,8 +17903,7 @@ } DUK_INTERNAL duk_bool_t duk_put_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_put_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), - (duk_small_uint_t) (packed_args & 0xffffUL)); + return duk_put_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } DUK_EXTERNAL duk_bool_t duk_del_prop(duk_hthread *thr, duk_idx_t obj_idx) { @@ -17191,7 +17925,7 @@ rc = duk_hobject_delprop(thr, tv_obj, tv_key, throw_flag); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop(thr); /* remove key */ + duk_pop(thr); /* remove key */ return rc; } @@ -17237,7 +17971,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_del_prop(thr, obj_idx); } @@ -17274,8 +18008,8 @@ rc = duk_hobject_hasprop(thr, tv_obj, tv_key); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop(thr); /* remove key */ - return rc; /* 1 if property found, 0 otherwise */ + duk_pop(thr); /* remove key */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_has_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) { @@ -17320,7 +18054,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_has_prop(thr, obj_idx); } @@ -17359,7 +18093,7 @@ duk_hobject_define_property_internal(thr, obj, key, desc_flags); - duk_pop(thr); /* pop key */ + duk_pop(thr); /* pop key */ } DUK_INTERNAL void duk_xdef_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags) { @@ -17392,12 +18126,13 @@ } DUK_INTERNAL void duk_xdef_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - duk_xdef_prop_stridx(thr, (duk_idx_t) (duk_int8_t) (packed_args >> 24), - (duk_small_uint_t) (packed_args >> 8) & 0xffffUL, - (duk_small_uint_t) (packed_args & 0xffL)); + duk_xdef_prop_stridx(thr, + (duk_idx_t) (duk_int8_t) (packed_args >> 24), + (duk_small_uint_t) (packed_args >> 8) & 0xffffUL, + (duk_small_uint_t) (packed_args & 0xffL)); } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL void duk_xdef_prop_stridx_builtin(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags) { duk_hobject *obj; duk_hstring *key; @@ -17429,15 +18164,15 @@ duk_push_hstring_stridx(thr, stridx); duk_push_hobject_bidx(thr, DUK_BIDX_TYPE_ERROR_THROWER); duk_dup_top(thr); - duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE); /* attributes always 0 */ + duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE); /* attributes always 0 */ } /* Object.getOwnPropertyDescriptor() equivalent C binding. */ DUK_EXTERNAL void duk_get_prop_desc(duk_hthread *thr, duk_idx_t obj_idx, duk_uint_t flags) { DUK_ASSERT_API_ENTRY(thr); - DUK_UNREF(flags); /* no flags defined yet */ + DUK_UNREF(flags); /* no flags defined yet */ - duk_hobject_object_get_own_property_descriptor(thr, obj_idx); /* ... key -> ... desc */ + duk_hobject_object_get_own_property_descriptor(thr, obj_idx); /* ... key -> ... desc */ } /* Object.defineProperty() equivalent C binding. */ @@ -17467,9 +18202,7 @@ idx_base = duk_get_top_index(thr); if (flags & DUK_DEFPROP_HAVE_SETTER) { - duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC); + duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC); set = duk_get_hobject_promote_lfunc(thr, idx_base); if (set != NULL && !DUK_HOBJECT_IS_CALLABLE(set)) { goto fail_not_callable; @@ -17479,9 +18212,7 @@ set = NULL; } if (flags & DUK_DEFPROP_HAVE_GETTER) { - duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC); + duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC); get = duk_get_hobject_promote_lfunc(thr, idx_base); if (get != NULL && !DUK_HOBJECT_IS_CALLABLE(get)) { goto fail_not_callable; @@ -17501,14 +18232,7 @@ duk_require_valid_index(thr, idx_base); - duk_hobject_define_property_helper(thr, - flags /*defprop_flags*/, - obj, - key, - idx_value, - get, - set, - 1 /*throw_flag*/); + duk_hobject_define_property_helper(thr, flags /*defprop_flags*/, obj, key, idx_value, get, set, 1 /*throw_flag*/); /* Clean up stack */ @@ -17518,11 +18242,11 @@ return; - fail_invalid_desc: +fail_invalid_desc: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_DESCRIPTOR); DUK_WO_NORETURN(return;); - fail_not_callable: +fail_not_callable: DUK_ERROR_TYPE(thr, DUK_STR_NOT_CALLABLE); DUK_WO_NORETURN(return;); } @@ -17556,7 +18280,7 @@ duk_dup(thr, obj_idx); duk_require_hobject_promote_mask(thr, -1, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); - duk_hobject_enumerator_create(thr, enum_flags); /* target -> enum */ + duk_hobject_enumerator_create(thr, enum_flags); /* target -> enum */ } DUK_EXTERNAL duk_bool_t duk_next(duk_hthread *thr, duk_idx_t enum_index, duk_bool_t get_value) { @@ -17617,8 +18341,8 @@ } return; - fail_cannot_freeze: - DUK_ERROR_TYPE_INVALID_ARGS(thr); /* XXX: proper error message */ +fail_cannot_freeze: + DUK_ERROR_TYPE_INVALID_ARGS(thr); /* XXX: proper error message */ DUK_WO_NORETURN(return;); } @@ -17663,8 +18387,8 @@ if (ent != NULL) { while (ent->key != NULL) { tv = thr->valstack_top++; - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv)); /* value stack init policy */ - DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, ent->value); /* no need for decref/incref */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv)); /* value stack init policy */ + DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, ent->value); /* no need for decref/incref */ duk_put_prop_string(thr, obj_idx, ent->key); ent++; } @@ -17734,7 +18458,6 @@ return ret; } - DUK_EXTERNAL duk_bool_t duk_put_global_string(duk_hthread *thr, const char *key) { duk_bool_t ret; @@ -17745,7 +18468,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_string(thr, -2, key); /* ... global val -> ... global */ + ret = duk_put_prop_string(thr, -2, key); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -17760,7 +18483,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_lstring(thr, -2, key, key_len); /* ... global val -> ... global */ + ret = duk_put_prop_lstring(thr, -2, key, key_len); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -17777,7 +18500,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_literal_raw(thr, -2, key, key_len); /* ... global val -> ... global */ + ret = duk_put_prop_literal_raw(thr, -2, key, key_len); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -17793,7 +18516,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_heapptr(thr, -2, ptr); /* ... global val -> ... global */ + ret = duk_put_prop_heapptr(thr, -2, ptr); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -17845,14 +18568,13 @@ obj = duk_require_hobject(thr, idx); DUK_ASSERT(obj != NULL); - duk_require_type_mask(thr, -1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT); + duk_require_type_mask(thr, -1, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT); proto = duk_get_hobject(thr, -1); /* proto can also be NULL here (allowed explicitly) */ #if defined(DUK_USE_ROM_OBJECTS) if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)) { - DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ + DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ DUK_WO_NORETURN(return;); } #endif @@ -17872,7 +18594,7 @@ #if defined(DUK_USE_ROM_OBJECTS) if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)) { - DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ + DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ DUK_WO_NORETURN(return;); } #endif @@ -17919,7 +18641,7 @@ DUK_ASSERT_API_ENTRY(thr); - h = duk_require_hobject(thr, idx); /* Get before 'put' so that 'idx' is correct. */ + h = duk_require_hobject(thr, idx); /* Get before 'put' so that 'idx' is correct. */ callable = duk_is_callable(thr, -1); /* At present finalizer is stored as a hidden Symbol, with normal @@ -17946,7 +18668,7 @@ DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h); } } -#else /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ DUK_EXTERNAL void duk_get_finalizer(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx); @@ -17960,7 +18682,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Random numbers */ @@ -17968,7 +18690,7 @@ /* #include duk_internal.h -> already included */ DUK_EXTERNAL duk_double_t duk_random(duk_hthread *thr) { - return (duk_double_t) DUK_UTIL_GET_RANDOM_DOUBLE(thr); + return (duk_double_t) duk_util_get_random_double(thr); } /* * API calls related to general value stack manipulation: resizing the value @@ -17988,7 +18710,8 @@ * Forward declarations */ -DUK_LOCAL_DECL duk_idx_t duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx); +DUK_LOCAL_DECL duk_idx_t +duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx); /* * Global state for working around missing variadic macros @@ -18003,41 +18726,24 @@ * Misc helpers */ -DUK_LOCAL const char * const duk__symbol_type_strings4 = { - "hidden", "global", "local", "wellknown" -}; +DUK_LOCAL const char * const duk__symbol_type_strings4 = { "hidden", "global", "local", "wellknown" }; #if !defined(DUK_USE_PACKED_TVAL) DUK_LOCAL const duk_uint_t duk__type_from_tag = { - DUK_TYPE_NUMBER, - DUK_TYPE_NUMBER, /* fastint */ - DUK_TYPE_UNDEFINED, - DUK_TYPE_NULL, - DUK_TYPE_BOOLEAN, - DUK_TYPE_POINTER, - DUK_TYPE_LIGHTFUNC, - DUK_TYPE_NONE, - DUK_TYPE_STRING, - DUK_TYPE_OBJECT, - DUK_TYPE_BUFFER, + DUK_TYPE_NUMBER, DUK_TYPE_NUMBER, /* fastint */ + DUK_TYPE_UNDEFINED, DUK_TYPE_NULL, DUK_TYPE_BOOLEAN, DUK_TYPE_POINTER, DUK_TYPE_LIGHTFUNC, + DUK_TYPE_NONE, DUK_TYPE_STRING, DUK_TYPE_OBJECT, DUK_TYPE_BUFFER, }; DUK_LOCAL const duk_uint_t duk__type_mask_from_tag = { - DUK_TYPE_MASK_NUMBER, - DUK_TYPE_MASK_NUMBER, /* fastint */ - DUK_TYPE_MASK_UNDEFINED, - DUK_TYPE_MASK_NULL, - DUK_TYPE_MASK_BOOLEAN, - DUK_TYPE_MASK_POINTER, - DUK_TYPE_MASK_LIGHTFUNC, - DUK_TYPE_MASK_NONE, - DUK_TYPE_MASK_STRING, - DUK_TYPE_MASK_OBJECT, - DUK_TYPE_MASK_BUFFER, + DUK_TYPE_MASK_NUMBER, DUK_TYPE_MASK_NUMBER, /* fastint */ + DUK_TYPE_MASK_UNDEFINED, DUK_TYPE_MASK_NULL, DUK_TYPE_MASK_BOOLEAN, DUK_TYPE_MASK_POINTER, DUK_TYPE_MASK_LIGHTFUNC, + DUK_TYPE_MASK_NONE, DUK_TYPE_MASK_STRING, DUK_TYPE_MASK_OBJECT, DUK_TYPE_MASK_BUFFER, }; -#endif /* !DUK_USE_PACKED_TVAL */ +#endif /* !DUK_USE_PACKED_TVAL */ /* Assert that there's room for one value. */ -#define DUK__ASSERT_SPACE() do { \ +#define DUK__ASSERT_SPACE() \ + do { \ DUK_ASSERT(!(thr->valstack_top >= thr->valstack_end)); \ } while (0) @@ -18046,7 +18752,8 @@ /* Faster but value stack overruns are memory unsafe. */ #define DUK__CHECK_SPACE() DUK__ASSERT_SPACE() #else -#define DUK__CHECK_SPACE() do { \ +#define DUK__CHECK_SPACE() \ + do { \ if (DUK_UNLIKELY(thr->valstack_top >= thr->valstack_end)) { \ DUK_ERROR_RANGE_PUSH_BEYOND(thr); \ } \ @@ -18059,7 +18766,7 @@ DUK_ASSERT(h != NULL); DUK_ASSERT(DUK_HSTRING_HAS_SYMBOL(h)); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h) >= 1); /* always true, symbol prefix */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h) >= 1); /* always true, symbol prefix */ data = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h); len = DUK_HSTRING_GET_BYTELEN(h); @@ -18226,7 +18933,7 @@ /* Assume value stack sizes (in elements) fits into duk_idx_t. */ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -18254,7 +18961,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -18282,7 +18989,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -18329,7 +19036,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ /* Use unsigned arithmetic to optimize comparison. */ if (idx < 0) { @@ -18468,7 +19175,7 @@ DUK_ASSERT(count > 0); tv = thr->valstack_top; tv_end = tv - count; - DUK_ASSERT(tv > tv_end); /* Because count > 0. */ + DUK_ASSERT(tv > tv_end); /* Because count > 0. */ do { tv--; DUK_ASSERT(tv >= thr->valstack_bottom); @@ -18476,7 +19183,7 @@ } while (tv != tv_end); thr->valstack_top = tv_end; DUK_REFZERO_CHECK_FAST(thr); -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ duk_uidx_t count; duk_tval *tv_end; @@ -18489,7 +19196,7 @@ DUK_TVAL_SET_UNDEFINED(tv); } while (tv != tv_end); thr->valstack_top = tv_end; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ } } @@ -18500,7 +19207,7 @@ duk_set_top(thr, idx); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_set_top_unsafe(duk_hthread *thr, duk_idx_t idx) { duk_uidx_t uidx; duk_uidx_t vs_size; @@ -18539,7 +19246,7 @@ DUK_ASSERT(count > 0); tv = thr->valstack_top; tv_end = tv - count; - DUK_ASSERT(tv > tv_end); /* Because count > 0. */ + DUK_ASSERT(tv > tv_end); /* Because count > 0. */ do { tv--; DUK_ASSERT(tv >= thr->valstack_bottom); @@ -18547,7 +19254,7 @@ } while (tv != tv_end); thr->valstack_top = tv_end; DUK_REFZERO_CHECK_FAST(thr); -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ duk_uidx_t count; duk_tval *tv_end; @@ -18560,10 +19267,10 @@ DUK_TVAL_SET_UNDEFINED(tv); } while (tv != tv_end); thr->valstack_top = tv_end; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ } } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Internal helper: set top to 'top', and set idx_wipe_start,top to * 'undefined' (doing nothing if idx_wipe_start == top). Indices are @@ -18663,9 +19370,9 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); DUK_ASSERT(thr->valstack_end >= thr->valstack_top); DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end); - DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size); /* can't resize below 'top' */ - DUK_ASSERT(new_size <= DUK_USE_VALSTACK_LIMIT); /* valstack limit caller has check, prevents wrapping */ - DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval)); /* specific assert for wrapping */ + DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size); /* can't resize below 'top' */ + DUK_ASSERT(new_size <= DUK_USE_VALSTACK_LIMIT); /* valstack limit caller has check, prevents wrapping */ + DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval)); /* specific assert for wrapping */ /* Pre-realloc pointer copies for asserts and debug logs. */ pre_valstack = thr->valstack; @@ -18700,7 +19407,8 @@ */ DUK_ASSERT(new_size != 0); DUK_D(DUK_DPRINT("failed to resize valstack to %lu entries (%lu bytes)", - (unsigned long) new_size, (unsigned long) new_alloc_size)); + (unsigned long) new_size, + (unsigned long) new_alloc_size)); return 0; } @@ -18711,23 +19419,28 @@ #if defined(DUK_USE_DEBUG) if (thr->valstack != pre_valstack) { DUK_D(DUK_DPRINT("valstack base pointer changed during valstack resize: %p -> %p", - (void *) pre_valstack, (void *) thr->valstack)); + (void *) pre_valstack, + (void *) thr->valstack)); } if (thr->valstack_bottom != pre_bottom) { DUK_D(DUK_DPRINT("valstack bottom pointer changed during valstack resize: %p -> %p", - (void *) pre_bottom, (void *) thr->valstack_bottom)); + (void *) pre_bottom, + (void *) thr->valstack_bottom)); } if (thr->valstack_top != pre_top) { DUK_D(DUK_DPRINT("valstack top pointer changed during valstack resize: %p -> %p", - (void *) pre_top, (void *) thr->valstack_top)); + (void *) pre_top, + (void *) thr->valstack_top)); } if (thr->valstack_end != pre_end) { DUK_D(DUK_DPRINT("valstack end pointer changed during valstack resize: %p -> %p", - (void *) pre_end, (void *) thr->valstack_end)); + (void *) pre_end, + (void *) thr->valstack_end)); } if (thr->valstack_alloc_end != pre_alloc_end) { DUK_D(DUK_DPRINT("valstack alloc_end pointer changed during valstack resize: %p -> %p", - (void *) pre_alloc_end, (void *) thr->valstack_alloc_end)); + (void *) pre_alloc_end, + (void *) thr->valstack_alloc_end)); } #endif @@ -18766,12 +19479,22 @@ (unsigned long) new_size, (unsigned long) ((duk_uint8_t *) pre_alloc_end - (duk_uint8_t *) pre_valstack), (unsigned long) new_alloc_size, - (void *) pre_valstack, (void *) thr->valstack, - (void *) pre_bottom, (void *) thr->valstack_bottom, (long) (thr->valstack_bottom - thr->valstack), - (void *) pre_top, (void *) thr->valstack_top, (long) (thr->valstack_top - thr->valstack), - (void *) pre_end, (void *) thr->valstack_end, (long) (thr->valstack_end - thr->valstack), - (void *) pre_alloc_end, (void *) thr->valstack_alloc_end, (long) (thr->valstack_alloc_end - thr->valstack), - (void *) tv_prev_alloc_end, (long) (thr->valstack_alloc_end - tv_prev_alloc_end))); + (void *) pre_valstack, + (void *) thr->valstack, + (void *) pre_bottom, + (void *) thr->valstack_bottom, + (long) (thr->valstack_bottom - thr->valstack), + (void *) pre_top, + (void *) thr->valstack_top, + (long) (thr->valstack_top - thr->valstack), + (void *) pre_end, + (void *) thr->valstack_end, + (long) (thr->valstack_end - thr->valstack), + (void *) pre_alloc_end, + (void *) thr->valstack_alloc_end, + (long) (thr->valstack_alloc_end - thr->valstack), + (void *) tv_prev_alloc_end, + (long) (thr->valstack_alloc_end - tv_prev_alloc_end))); /* If allocation grew, init any new slots to 'undefined'. */ p = tv_prev_alloc_end; @@ -18798,7 +19521,7 @@ duk_size_t new_size; DUK_ASSERT(min_bytes / sizeof(duk_tval) * sizeof(duk_tval) == min_bytes); - min_size = min_bytes / sizeof(duk_tval); /* from bytes to slots */ + min_size = min_bytes / sizeof(duk_tval); /* from bytes to slots */ #if defined(DUK_USE_VALSTACK_GROW_SHIFT) /* New size is minimum size plus a proportional slack, e.g. shift of @@ -18915,17 +19638,18 @@ #else slack = 0; #endif - shrink_bytes = reserve_bytes + - slack / sizeof(duk_tval) * sizeof(duk_tval); /* multiple of duk_tval */ + shrink_bytes = reserve_bytes + slack / sizeof(duk_tval) * sizeof(duk_tval); /* multiple of duk_tval */ } -#else /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ +#else /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ /* Always snug, useful in some low memory environments. */ DUK_UNREF(snug); shrink_bytes = reserve_bytes; -#endif /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ +#endif /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ DUK_D(DUK_DPRINT("valstack shrink check: alloc_bytes=%ld, reserve_bytes=%ld, shrink_bytes=%ld (unvalidated)", - (long) alloc_bytes, (long) reserve_bytes, (long) shrink_bytes)); + (long) alloc_bytes, + (long) reserve_bytes, + (long) shrink_bytes)); DUK_ASSERT(shrink_bytes >= reserve_bytes); if (shrink_bytes >= alloc_bytes) { /* Skip if shrink target is same as current one (or higher, @@ -19072,7 +19796,7 @@ DUK_ASSERT(tv_from != NULL); DUK_ASSERT(tv_to != NULL); DUK_TVAL_SET_TVAL(tv_to, tv_from); - DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ + DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ } DUK_EXTERNAL void duk_dup_top(duk_hthread *thr) { @@ -19094,7 +19818,7 @@ DUK_ASSERT(tv_from != NULL); DUK_ASSERT(tv_to != NULL); DUK_TVAL_SET_TVAL(tv_to, tv_from); - DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ + DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ #endif } @@ -19147,7 +19871,10 @@ nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); DUK_DDD(DUK_DDDPRINT("duk_insert: to_idx=%ld, p=%p, q=%p, nbytes=%lu", - (long) to_idx, (void *) p, (void *) q, (unsigned long) nbytes)); + (long) to_idx, + (void *) p, + (void *) q, + (unsigned long) nbytes)); /* No net refcount changes. No need to special case nbytes == 0 * (p == q). @@ -19159,7 +19886,7 @@ DUK_INTERNAL void duk_insert_undefined(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(idx >= 0); /* Doesn't support negative indices. */ + DUK_ASSERT(idx >= 0); /* Doesn't support negative indices. */ duk_push_undefined(thr); duk_insert(thr, idx); @@ -19169,7 +19896,7 @@ duk_tval *tv, *tv_end; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(idx >= 0); /* Doesn't support negative indices or count. */ + DUK_ASSERT(idx >= 0); /* Doesn't support negative indices or count. */ DUK_ASSERT(count >= 0); tv = duk_reserve_gap(thr, idx, count); @@ -19204,7 +19931,10 @@ nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); DUK_DDD(DUK_DDDPRINT("duk_pull: from_idx=%ld, p=%p, q=%p, nbytes=%lu", - (long) from_idx, (void *) p, (void *) q, (unsigned long) nbytes)); + (long) from_idx, + (void *) p, + (void *) q, + (unsigned long) nbytes)); /* No net refcount changes. No need to special case nbytes == 0 * (p == q). @@ -19233,7 +19963,7 @@ DUK_TVAL_SET_TVAL(tv2, tv1); DUK_TVAL_SET_UNDEFINED(tv1); thr->valstack_top--; - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ } DUK_EXTERNAL void duk_copy(duk_hthread *thr, duk_idx_t from_idx, duk_idx_t to_idx) { @@ -19248,7 +19978,7 @@ DUK_ASSERT(tv2 != NULL); /* For tv1 == tv2, this is a no-op (no explicit check needed). */ - DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */ } DUK_EXTERNAL void duk_remove(duk_hthread *thr, duk_idx_t idx) { @@ -19279,21 +20009,21 @@ DUK_TVAL_SET_TVAL(&tv_tmp, p); #endif - nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */ + nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */ duk_memmove((void *) p, (const void *) (p + 1), (size_t) nbytes); DUK_TVAL_SET_UNDEFINED(q); thr->valstack_top--; #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ #endif } DUK_INTERNAL void duk_remove_unsafe(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - duk_remove(thr, idx); /* XXX: no optimization for now */ + duk_remove(thr, idx); /* XXX: no optimization for now */ } DUK_INTERNAL void duk_remove_m2(duk_hthread *thr) { @@ -19312,7 +20042,7 @@ while (count-- > 0) { duk_remove(thr, idx); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ duk_tval *tv_src; duk_tval *tv_dst; duk_tval *tv_newtop; @@ -19344,13 +20074,13 @@ /* When not preferring size, only NORZ macros are used; caller * is expected to DUK_REFZERO_CHECK(). */ -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } DUK_INTERNAL void duk_remove_n_unsafe(duk_hthread *thr, duk_idx_t idx, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); - duk_remove_n(thr, idx, count); /* XXX: no optimization for now */ + duk_remove_n(thr, idx, count); /* XXX: no optimization for now */ } /* @@ -19411,7 +20141,7 @@ /* Incref copies, keep originals. */ q = to_thr->valstack_top; while (p < q) { - DUK_TVAL_INCREF(to_thr, p); /* no side effects */ + DUK_TVAL_INCREF(to_thr, p); /* no side effects */ p++; } } else { @@ -19511,7 +20241,7 @@ DUK_EXTERNAL duk_bool_t duk_get_boolean(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__get_boolean_raw(thr, idx, 0); /* default: false */ + return duk__get_boolean_raw(thr, idx, 0); /* default: false */ } DUK_EXTERNAL duk_bool_t duk_get_boolean_default(duk_hthread *thr, duk_idx_t idx, duk_bool_t def_value) { @@ -19557,11 +20287,10 @@ DUK_ASSERT(tv != NULL); #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv)) { - ret.d = (duk_double_t) DUK_TVAL_GET_FASTINT(tv); /* XXX: cast trick */ - } - else + ret.d = (duk_double_t) DUK_TVAL_GET_FASTINT(tv); /* XXX: cast trick */ + } else #endif - if (DUK_TVAL_IS_DOUBLE(tv)) { + if (DUK_TVAL_IS_DOUBLE(tv)) { /* When using packed duk_tval, number must be in NaN-normalized form * for it to be a duk_tval, so no need to normalize. NOP for unpacked * duk_tval. @@ -19578,7 +20307,7 @@ DUK_EXTERNAL duk_double_t duk_get_number(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__get_number_raw(thr, idx, DUK_DOUBLE_NAN); /* default: NaN */ + return duk__get_number_raw(thr, idx, DUK_DOUBLE_NAN); /* default: NaN */ } DUK_EXTERNAL duk_double_t duk_get_number_default(duk_hthread *thr, duk_idx_t idx, duk_double_t def_value) { @@ -19734,7 +20463,11 @@ } } -DUK_EXTERNAL const char *duk_opt_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL const char *duk_opt_lstring(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_len, + const char *def_ptr, + duk_size_t def_len) { DUK_ASSERT_API_ENTRY(thr); if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) { @@ -19755,7 +20488,11 @@ return duk_require_string(thr, idx); } -DUK_EXTERNAL const char *duk_get_lstring_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL const char *duk_get_lstring_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_len, + const char *def_ptr, + duk_size_t def_len) { duk_hstring *h; const char *ret; duk_size_t len; @@ -19844,7 +20581,7 @@ return def_value; } - p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ + p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ return p; } @@ -19882,11 +20619,11 @@ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "pointer", DUK_STR_NOT_POINTER); DUK_WO_NORETURN(return NULL;); } - p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ + p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ return p; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL void *duk_get_voidptr(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; duk_heaphdr *h; @@ -19905,7 +20642,12 @@ } #endif -DUK_LOCAL void *duk__get_buffer_helper(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag) { +DUK_LOCAL void *duk__get_buffer_helper(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size, + duk_bool_t throw_flag) { duk_hbuffer *h; void *ret; duk_size_t len; @@ -19958,7 +20700,11 @@ return duk_require_buffer(thr, idx, out_size); } -DUK_EXTERNAL void *duk_get_buffer_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL void *duk_get_buffer_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_len) { DUK_ASSERT_API_ENTRY(thr); return duk__get_buffer_helper(thr, idx, out_size, def_ptr, def_len, 0 /*throw_flag*/); @@ -19975,7 +20721,13 @@ * have a NULL data pointer when its size is zero, the optional 'out_isbuffer' * argument allows caller to detect this reliably. */ -DUK_INTERNAL void *duk_get_buffer_data_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag, duk_bool_t *out_isbuffer) { +DUK_INTERNAL void *duk_get_buffer_data_raw(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size, + duk_bool_t throw_flag, + duk_bool_t *out_isbuffer) { duk_tval *tv; DUK_ASSERT_API_ENTRY(thr); @@ -19999,7 +20751,7 @@ if (out_isbuffer != NULL) { *out_isbuffer = 1; } - return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */ + return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */ } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) else if (DUK_TVAL_IS_OBJECT(tv)) { @@ -20012,8 +20764,7 @@ duk_hbufobj *h_bufobj = (duk_hbufobj *) h; DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); - if (h_bufobj->buf != NULL && - DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { + if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { duk_uint8_t *p; p = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf); @@ -20028,7 +20779,7 @@ /* if slice not fully valid, treat as error */ } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ if (throw_flag) { DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "buffer", DUK_STR_NOT_BUFFER); @@ -20042,7 +20793,11 @@ return duk_get_buffer_data_raw(thr, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, NULL); } -DUK_EXTERNAL void *duk_get_buffer_data_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size) { +DUK_EXTERNAL void *duk_get_buffer_data_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size) { DUK_ASSERT_API_ENTRY(thr); return duk_get_buffer_data_raw(thr, idx, out_size, def_ptr, def_size, 0 /*throw_flag*/, NULL); } @@ -20082,9 +20837,8 @@ } ret = DUK_TVAL_GET_HEAPHDR(tv); - DUK_ASSERT(ret != NULL); /* tagged null pointers should never occur */ + DUK_ASSERT(ret != NULL); /* tagged null pointers should never occur */ return ret; - } DUK_INTERNAL duk_hstring *duk_get_hstring(duk_hthread *thr, duk_idx_t idx) { @@ -20419,7 +21173,7 @@ DUK_CTX_ASSERT_VALID(thr); - res = duk_get_hobject(thr, idx); /* common case, not promoted */ + res = duk_get_hobject(thr, idx); /* common case, not promoted */ if (DUK_LIKELY(res != NULL)) { DUK_ASSERT(res != NULL); return res; @@ -20432,7 +21186,7 @@ DUK_ASSERT(res != NULL); return res; } else { - return NULL; /* accept without promoting */ + return NULL; /* accept without promoting */ } } @@ -20475,7 +21229,7 @@ duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX); h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT); @@ -20489,7 +21243,7 @@ duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX); h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT); @@ -20535,7 +21289,7 @@ duk_pop_unsafe(thr); return ret; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ case DUK_TAG_STRING: { duk_hstring *h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); @@ -20561,7 +21315,7 @@ duk_pop_unsafe(thr); return ret; } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ case DUK_TAG_OBJECT: { duk_hobject *h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); @@ -20658,8 +21412,8 @@ if (duk_get_prop_stridx(thr, idx, func_stridx)) { /* ... func */ if (duk_is_callable(thr, -1)) { - duk_dup(thr, idx); /* -> ... func this */ - duk_call_method(thr, 0); /* -> ... retval */ + duk_dup(thr, idx); /* -> ... func this */ + duk_call_method(thr, 0); /* -> ... retval */ if (duk_is_primitive(thr, -1)) { duk_replace(thr, idx); return 1; @@ -20667,7 +21421,7 @@ /* ... retval ; popped below */ } } - duk_pop_unsafe(thr); /* ... func/retval -> ... */ + duk_pop_unsafe(thr); /* ... func/retval -> ... */ return 0; } @@ -20678,7 +21432,7 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ } DUK_EXTERNAL void duk_to_null(duk_hthread *thr, duk_idx_t idx) { @@ -20688,13 +21442,11 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */ } /* E5 Section 9.1 */ -DUK_LOCAL const char * const duk__toprim_hint_strings3 = { - "default", "string", "number" -}; +DUK_LOCAL const char * const duk__toprim_hint_strings3 = { "default", "string", "number" }; DUK_LOCAL void duk__to_primitive_helper(duk_hthread *thr, duk_idx_t idx, duk_int_t hint, duk_bool_t check_symbol) { /* Inline initializer for coercers is not allowed by old compilers like BCC. */ duk_small_uint_t coercers2; @@ -20705,10 +21457,8 @@ idx = duk_require_normalize_index(thr, idx); /* If already primitive, return as is. */ - if (!duk_check_type_mask(thr, idx, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + if (!duk_check_type_mask(thr, idx, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } @@ -20719,10 +21469,8 @@ DUK_ASSERT(hint >= 0 && (duk_size_t) hint < sizeof(duk__toprim_hint_strings) / sizeof(const char *)); duk_dup(thr, idx); duk_push_string(thr, duk__toprim_hint_stringshint); - duk_call_method(thr, 1); /* ... method value hint -> ... res */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { + duk_call_method(thr, 1); /* ... method value hint -> ... res */ + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { goto fail; } duk_replace(thr, idx); @@ -20744,7 +21492,7 @@ if (hint == DUK_HINT_NONE) { hint = DUK_HINT_NUMBER; } -#else /* DUK_USE_SYMBOL_BUILTIN */ +#else /* DUK_USE_SYMBOL_BUILTIN */ if (hint == DUK_HINT_NONE) { duk_small_uint_t class_number; @@ -20755,7 +21503,7 @@ hint = DUK_HINT_NUMBER; } } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ coercers0 = DUK_STRIDX_VALUE_OF; coercers1 = DUK_STRIDX_TO_STRING; @@ -20765,16 +21513,16 @@ } if (duk__defaultvalue_coerce_attempt(thr, idx, coercers0)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } if (duk__defaultvalue_coerce_attempt(thr, idx, coercers1)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } - fail: +fail: DUK_ERROR_TYPE(thr, DUK_STR_TOPRIMITIVE_FAILED); DUK_WO_NORETURN(return;); } @@ -20805,7 +21553,7 @@ /* Note: no need to re-lookup tv, conversion is side effect free. */ DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val); /* side effects */ return val; } @@ -20837,11 +21585,11 @@ idx = duk_require_normalize_index(thr, idx); tv = DUK_GET_TVAL_POSIDX(thr, idx); DUK_ASSERT(tv != NULL); - d = duk_js_tonumber(thr, tv); /* XXX: fastint coercion? now result will always be a non-fastint */ + d = duk_js_tonumber(thr, tv); /* XXX: fastint coercion? now result will always be a non-fastint */ /* ToNumber() may have side effects so must relookup 'tv'. */ tv = DUK_GET_TVAL_POSIDX(thr, idx); - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ return d; } @@ -20873,13 +21621,13 @@ tv_dst = thr->valstack_top++; DUK_TVAL_SET_TVAL(tv_dst, tv); - DUK_TVAL_INCREF(thr, tv_dst); /* decref not necessary */ - res = duk_to_number_m1(thr); /* invalidates tv_dst */ + DUK_TVAL_INCREF(thr, tv_dst); /* decref not necessary */ + res = duk_to_number_m1(thr); /* invalidates tv_dst */ tv_dst = --thr->valstack_top; DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_dst)); - DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_dst)); /* plain number */ - DUK_TVAL_SET_UNDEFINED(tv_dst); /* valstack init policy */ + DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_dst)); /* plain number */ + DUK_TVAL_SET_UNDEFINED(tv_dst); /* valstack init policy */ return res; #endif @@ -20915,7 +21663,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ return d; } @@ -20949,7 +21697,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_I32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -20965,7 +21713,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -20981,7 +21729,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -21013,16 +21761,16 @@ if (duk_double_equals(t, 0.5)) { /* Exact halfway, round to even. */ ret = (duk_uint8_t) d; - ret = (ret + 1) & 0xfe; /* Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4 - * Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4 - */ + ret = (ret + 1) & 0xfe; /* Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4 + * Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4 + */ } else { /* Not halfway, round to nearest. */ ret = (duk_uint8_t) (d + 0.5); } return ret; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL const char *duk_to_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) { DUK_ASSERT_API_ENTRY(thr); @@ -21132,7 +21880,7 @@ DUK_ASSERT_API_ENTRY(thr); - duk_to_primitive(thr, idx, DUK_HINT_STRING); /* needed for e.g. Symbol objects */ + duk_to_primitive(thr, idx, DUK_HINT_STRING); /* needed for e.g. Symbol objects */ h = duk_get_hstring(thr, idx); if (h == NULL) { /* The "is string?" check may seem unnecessary, but as things @@ -21146,7 +21894,7 @@ return h; } -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ DUK_INTERNAL duk_hstring *duk_safe_to_hstring(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); @@ -21188,10 +21936,10 @@ * Object.prototype.toString() is usually not performance critical. */ - duk_push_literal(thr, "object "); /* -> ... "object" */ + duk_push_literal(thr, "object "); /* -> ... "object" */ switch (DUK_TVAL_GET_TAG(tv)) { - case DUK_TAG_UNUSED: /* Treat like 'undefined', shouldn't happen. */ + case DUK_TAG_UNUSED: /* Treat like 'undefined', shouldn't happen. */ case DUK_TAG_UNDEFINED: { duk_push_hstring_stridx(thr, DUK_STRIDX_UC_UNDEFINED); goto finish; @@ -21203,7 +21951,7 @@ } duk_push_tval(thr, tv); - tv = NULL; /* Invalidated by ToObject(). */ + tv = NULL; /* Invalidated by ToObject(). */ h_obj = duk_to_hobject(thr, -1); DUK_ASSERT(h_obj != NULL); if (duk_js_isarray_hobject(h_obj)) { @@ -21234,14 +21982,15 @@ duk_pop_unsafe(thr); duk_push_hstring_stridx(thr, stridx); - finish: +finish: /* ... "object" tag */ duk_push_literal(thr, ""); - duk_concat(thr, 3); /* ... "object" tag "" -> ... res */ + duk_concat(thr, 3); /* ... "object" tag "" -> ... res */ } /* XXX: other variants like uint, u32 etc */ -DUK_INTERNAL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) { +DUK_INTERNAL duk_int_t +duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) { duk_tval *tv; duk_tval tv_tmp; duk_double_t d, dmin, dmax; @@ -21252,7 +22001,7 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - d = duk_js_tointeger(thr, tv); /* E5 Section 9.4, ToInteger() */ + d = duk_js_tointeger(thr, tv); /* E5 Section 9.4, ToInteger() */ dmin = (duk_double_t) minval; dmax = (duk_double_t) maxval; @@ -21268,12 +22017,12 @@ } else { res = (duk_int_t) d; } - DUK_UNREF(d); /* SCANBUILD: with suitable dmin/dmax limits 'd' is unused */ + DUK_UNREF(d); /* SCANBUILD: with suitable dmin/dmax limits 'd' is unused */ /* 'd' and 'res' agree here */ /* Relookup in case duk_js_tointeger() ends up e.g. coercing an object. */ tv = duk_get_tval(thr, idx); - DUK_ASSERT(tv != NULL); /* not popped by side effect */ + DUK_ASSERT(tv != NULL); /* not popped by side effect */ DUK_TVAL_SET_TVAL(&tv_tmp, tv); #if defined(DUK_USE_FASTINT) #if (DUK_INT_MAX <= 0x7fffffffL) @@ -21287,9 +22036,9 @@ } #endif #else - DUK_TVAL_SET_NUMBER(tv, d); /* no need to incref */ + DUK_TVAL_SET_NUMBER(tv, d); /* no need to incref */ #endif - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ if (out_clamped) { *out_clamped = clamped; @@ -21314,7 +22063,7 @@ DUK_INTERNAL duk_int_t duk_to_int_check_range(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval) { DUK_ASSERT_API_ENTRY(thr); - return duk_to_int_clamped_raw(thr, idx, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */ + return duk_to_int_clamped_raw(thr, idx, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */ } DUK_EXTERNAL const char *duk_to_string(duk_hthread *thr, duk_idx_t idx) { @@ -21373,9 +22122,9 @@ * value, and duk_to_string() then causes a TypeError. */ duk_to_primitive(thr, idx, DUK_HINT_STRING); - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* ToPrimitive() must guarantee */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* ToPrimitive() must guarantee */ DUK_ASSERT(!duk_is_object(thr, idx)); - return duk_to_string(thr, idx); /* Note: recursive call */ + return duk_to_string(thr, idx); /* Note: recursive call */ } case DUK_TAG_POINTER: { void *ptr = DUK_TVAL_GET_POINTER(tv); @@ -21403,17 +22152,14 @@ DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv)); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); duk_push_tval(thr, tv); - duk_numconv_stringify(thr, - 10 /*radix*/, - 0 /*precision:shortest*/, - 0 /*force_exponential*/); + duk_numconv_stringify(thr, 10 /*radix*/, 0 /*precision:shortest*/, 0 /*force_exponential*/); break; } } duk_replace(thr, idx); - skip_replace: +skip_replace: DUK_ASSERT(duk_is_string(thr, idx)); return duk_require_string(thr, idx); } @@ -21495,8 +22241,7 @@ src_size = DUK_HBUFFER_GET_SIZE(h_buf); tmp = (DUK_HBUFFER_HAS_DYNAMIC(h_buf) ? DUK_BUF_MODE_DYNAMIC : DUK_BUF_MODE_FIXED); - if ((tmp == mode && !DUK_HBUFFER_HAS_EXTERNAL(h_buf)) || - mode == DUK_BUF_MODE_DONTCARE) { + if ((tmp == mode && !DUK_HBUFFER_HAS_EXTERNAL(h_buf)) || mode == DUK_BUF_MODE_DONTCARE) { /* Note: src_data may be NULL if input is a zero-size * dynamic buffer. */ @@ -21517,7 +22262,7 @@ duk_memcpy_unsafe((void *) dst_data, (const void *) src_data, (size_t) src_size); duk_replace(thr, idx); - skip_copy: +skip_copy: if (out_size) { *out_size = src_size; @@ -21577,7 +22322,7 @@ DUK_LOCAL void duk__push_func_from_lightfunc(duk_hthread *thr, duk_c_function func, duk_small_uint_t lf_flags) { duk_idx_t nargs; - duk_uint_t flags = 0; /* shared flags for a subset of types */ + duk_uint_t flags = 0; /* shared flags for a subset of types */ duk_small_uint_t lf_len; duk_hnatfunc *nf; @@ -21586,15 +22331,9 @@ nargs = (duk_idx_t) DUK_VARARGS; } - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_NATIVE_FUNCTION_PROTOTYPE); lf_len = DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags); @@ -21615,7 +22354,7 @@ DUK_EXTERNAL void duk_to_object(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; - duk_uint_t flags = 0; /* shared flags for a subset of types */ + duk_uint_t flags = 0; /* shared flags for a subset of types */ duk_small_int_t proto = 0; DUK_ASSERT_API_ENTRY(thr); @@ -21626,7 +22365,7 @@ switch (DUK_TVAL_GET_TAG(tv)) { #if !defined(DUK_USE_BUFFEROBJECT_SUPPORT) - case DUK_TAG_BUFFER: /* With no bufferobject support, don't object coerce. */ + case DUK_TAG_BUFFER: /* With no bufferobject support, don't object coerce. */ #endif case DUK_TAG_UNDEFINED: case DUK_TAG_NULL: { @@ -21635,9 +22374,8 @@ break; } case DUK_TAG_BOOLEAN: { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BOOLEAN); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BOOLEAN); proto = DUK_BIDX_BOOLEAN_PROTOTYPE; goto create_object; } @@ -21646,14 +22384,11 @@ h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); if (DUK_UNLIKELY(DUK_HSTRING_HAS_SYMBOL(h))) { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_SYMBOL); proto = DUK_BIDX_SYMBOL_PROTOTYPE; } else { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_STRING); proto = DUK_BIDX_STRING_PROTOTYPE; } @@ -21679,11 +22414,10 @@ duk_hbufobj_push_uint8array_from_plain(thr, h_buf); goto replace_value; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ case DUK_TAG_POINTER: { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER); proto = DUK_BIDX_POINTER_PROTOTYPE; goto create_object; } @@ -21710,9 +22444,8 @@ default: { DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv)); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_NUMBER); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_NUMBER); proto = DUK_BIDX_NUMBER_PROTOTYPE; goto create_object; } @@ -21720,7 +22453,7 @@ DUK_ASSERT(duk_is_object(thr, idx)); return; - create_object: +create_object: (void) duk_push_object_helper(thr, flags, proto); /* Note: Boolean prototype's internal value property is not writable, @@ -21733,7 +22466,7 @@ duk_dup(thr, idx); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); - replace_value: +replace_value: duk_replace(thr, idx); DUK_ASSERT(duk_is_object(thr, idx)); } @@ -21804,11 +22537,11 @@ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); return DUK_TYPE_NUMBER; } -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ DUK_ASSERT(DUK_TVAL_IS_VALID_TAG(tv)); DUK_ASSERT(sizeof(duk__type_from_tag) / sizeof(duk_uint_t) == DUK_TAG_MAX - DUK_TAG_MIN + 1); return (duk_int_t) duk__type_from_tagDUK_TVAL_GET_TAG(tv) - DUK_TAG_MIN; -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ } DUK_EXTERNAL duk_int_t duk_get_type(duk_hthread *thr, duk_idx_t idx) { @@ -21823,18 +22556,8 @@ } #if defined(DUK_USE_VERBOSE_ERRORS) && defined(DUK_USE_PARANOID_ERRORS) -DUK_LOCAL const char * const duk__type_names = { - "none", - "undefined", - "null", - "boolean", - "number", - "string", - "object", - "buffer", - "pointer", - "lightfunc" -}; +DUK_LOCAL const char * const duk__type_names = { "none", "undefined", "null", "boolean", "number", + "string", "object", "buffer", "pointer", "lightfunc" }; DUK_INTERNAL const char *duk_get_type_name(duk_hthread *thr, duk_idx_t idx) { duk_int_t type_tag; @@ -21847,7 +22570,7 @@ return duk__type_namestype_tag; } -#endif /* DUK_USE_VERBOSE_ERRORS && DUK_USE_PARANOID_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS && DUK_USE_PARANOID_ERRORS */ DUK_INTERNAL duk_small_uint_t duk_get_class_number(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; @@ -21913,11 +22636,11 @@ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); return DUK_TYPE_MASK_NUMBER; } -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ DUK_ASSERT(DUK_TVAL_IS_VALID_TAG(tv)); DUK_ASSERT(sizeof(duk__type_mask_from_tag) / sizeof(duk_uint_t) == DUK_TAG_MAX - DUK_TAG_MIN + 1); return duk__type_mask_from_tagDUK_TVAL_GET_TAG(tv) - DUK_TAG_MIN; -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ } DUK_EXTERNAL duk_uint_t duk_get_type_mask(duk_hthread *thr, duk_idx_t idx) { @@ -22036,14 +22759,14 @@ } return 0; } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); return duk_is_buffer(thr, idx); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL duk_bool_t duk_is_pointer(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); @@ -22137,23 +22860,17 @@ DUK_EXTERNAL duk_bool_t duk_is_c_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_NATFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_NATFUNC); } DUK_EXTERNAL duk_bool_t duk_is_ecmascript_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_COMPFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_COMPFUNC); } DUK_EXTERNAL duk_bool_t duk_is_bound_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_BOUNDFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_BOUNDFUNC); } DUK_EXTERNAL duk_bool_t duk_is_thread(duk_hthread *thr, duk_idx_t idx) { @@ -22270,7 +22987,7 @@ DUK__CHECK_SPACE(); tv_slot = thr->valstack_top++; DUK_TVAL_SET_TVAL(tv_slot, tv); - DUK_TVAL_INCREF(thr, tv); /* no side effects */ + DUK_TVAL_INCREF(thr, tv); /* no side effects */ } DUK_EXTERNAL void duk_push_undefined(duk_hthread *thr) { @@ -22300,7 +23017,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK__CHECK_SPACE(); - b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */ + b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */ tv_slot = thr->valstack_top++; DUK_TVAL_SET_BOOLEAN(tv_slot, b); } @@ -22353,7 +23070,7 @@ DUK_TVAL_SET_NUMBER(tv_slot, d); } #endif -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ duk_tval *tv_slot; duk_double_t d; @@ -22362,7 +23079,7 @@ d = (duk_double_t) val; tv_slot = thr->valstack_top++; DUK_TVAL_SET_NUMBER(tv_slot, d); -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ } DUK_EXTERNAL void duk_push_uint(duk_hthread *thr, duk_uint_t val) { @@ -22375,7 +23092,7 @@ #if DUK_UINT_MAX <= 0xffffffffUL DUK_TVAL_SET_U32(tv_slot, (duk_uint32_t) val); #else - if (val <= DUK_FASTINT_MAX) { /* val is unsigned so >= 0 */ + if (val <= DUK_FASTINT_MAX) { /* val is unsigned so >= 0 */ /* XXX: take advantage of val being unsigned, no need to mask */ DUK_TVAL_SET_FASTINT(tv_slot, (duk_int64_t) val); } else { @@ -22383,7 +23100,7 @@ DUK_TVAL_SET_NUMBER(tv_slot, d); } #endif -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ duk_tval *tv_slot; duk_double_t d; @@ -22392,7 +23109,7 @@ d = (duk_double_t) val; tv_slot = thr->valstack_top++; DUK_TVAL_SET_NUMBER(tv_slot, d); -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ } DUK_EXTERNAL void duk_push_nan(duk_hthread *thr) { @@ -22436,7 +23153,7 @@ tv_slot = thr->valstack_top++; DUK_TVAL_SET_STRING(tv_slot, h); - DUK_HSTRING_INCREF(thr, h); /* no side effects */ + DUK_HSTRING_INCREF(thr, h); /* no side effects */ return (const char *) DUK_HSTRING_GET_DATA(h); } @@ -22473,11 +23190,11 @@ tv_slot = thr->valstack_top++; DUK_TVAL_SET_STRING(tv_slot, h); - DUK_HSTRING_INCREF(thr, h); /* no side effects */ + DUK_HSTRING_INCREF(thr, h); /* no side effects */ return (const char *) DUK_HSTRING_GET_DATA(h); } -#else /* DUK_USE_LITCACHE_SIZE */ +#else /* DUK_USE_LITCACHE_SIZE */ DUK_EXTERNAL const char *duk_push_literal_raw(duk_hthread *thr, const char *str, duk_size_t len) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(str != NULL); @@ -22485,8 +23202,8 @@ return duk_push_lstring(thr, str, len); } -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_push_pointer(duk_hthread *thr, void *val) { duk_tval *tv_slot; @@ -22514,7 +23231,7 @@ DUK__CHECK_SPACE(); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */ tv_slot = thr->valstack_top++; if (DUK_UNLIKELY(thr->callstack_curr == NULL)) { @@ -22528,8 +23245,7 @@ /* 'this' binding is just before current activation's bottom */ DUK_ASSERT(thr->valstack_bottom > thr->valstack); tv = thr->valstack_bottom - 1; - if (check_object_coercible && - (DUK_TVAL_IS_UNDEFINED(tv) || DUK_TVAL_IS_NULL(tv))) { + if (check_object_coercible && (DUK_TVAL_IS_UNDEFINED(tv) || DUK_TVAL_IS_NULL(tv))) { /* XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv) */ goto type_error; } @@ -22539,7 +23255,7 @@ } return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_NOT_OBJECT_COERCIBLE); DUK_WO_NORETURN(return;); } @@ -22571,16 +23287,16 @@ DUK_ASSERT_API_ENTRY(thr); duk__push_this_helper(thr, 1 /*check_object_coercible*/); - return duk_to_hstring_m1(thr); /* This will reject all Symbol values; accepts Symbol objects. */ + return duk_to_hstring_m1(thr); /* This will reject all Symbol values; accepts Symbol objects. */ } DUK_INTERNAL duk_tval *duk_get_borrowed_this_tval(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */ - DUK_ASSERT(thr->callstack_curr != NULL); /* caller required to know */ - DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */ - DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */ + DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */ + DUK_ASSERT(thr->callstack_curr != NULL); /* caller required to know */ + DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */ + DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */ return thr->valstack_bottom - 1; } @@ -22661,7 +23377,10 @@ duk_pop_unsafe(thr); duk_push_bare_object(thr); duk_dup_top(thr); - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_C); /* ... parent stash stash -> ... parent stash */ + duk_xdef_prop_stridx_short(thr, + -3, + DUK_STRIDX_INT_VALUE, + DUK_PROPDESC_FLAGS_C); /* ... parent stash stash -> ... parent stash */ } duk_remove_m2(thr); } @@ -22714,7 +23433,7 @@ duk_size_t sz = DUK_PUSH_SPRINTF_INITIAL_SIZE; duk_bool_t pushed_buf = 0; void *buf; - duk_int_t len; /* XXX: duk_ssize_t */ + duk_int_t len; /* XXX: duk_ssize_t */ const char *res; DUK_ASSERT_API_ENTRY(thr); @@ -22728,7 +23447,7 @@ } /* initial estimate based on format string */ - sz = DUK_STRLEN(fmt) + 16; /* format plus something to avoid just missing */ + sz = DUK_STRLEN(fmt) + 16; /* format plus something to avoid just missing */ if (sz < DUK_PUSH_SPRINTF_INITIAL_SIZE) { sz = DUK_PUSH_SPRINTF_INITIAL_SIZE; } @@ -22738,7 +23457,7 @@ * This works 99% of the time which is quite nice. */ for (;;) { - va_list ap_copy; /* copied so that 'ap' can be reused */ + va_list ap_copy; /* copied so that 'ap' can be reused */ if (sz <= sizeof(stack_buf)) { buf = stack_buf; @@ -22768,7 +23487,7 @@ /* Cannot use duk_buffer_to_string() on the buffer because it is * usually larger than 'len'; 'buf' is also usually a stack buffer. */ - res = duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); /* buf? res */ + res = duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); /* buf? res */ if (pushed_buf) { duk_remove_m2(thr); } @@ -22789,13 +23508,14 @@ return ret; } -DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) { +DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx) { duk_tval *tv_slot; duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(prototype_bidx == -1 || - (prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS)); + DUK_ASSERT(prototype_bidx == -1 || (prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS)); DUK__CHECK_SPACE(); @@ -22806,7 +23526,7 @@ tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, h); - DUK_HOBJECT_INCREF(thr, h); /* no side effects */ + DUK_HOBJECT_INCREF(thr, h); /* no side effects */ thr->valstack_top++; /* object is now reachable */ @@ -22836,9 +23556,8 @@ DUK_ASSERT_API_ENTRY(thr); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return duk_get_top_index_unsafe(thr); } @@ -22851,11 +23570,8 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); obj = duk_harray_alloc(thr, flags); DUK_ASSERT(obj != NULL); @@ -22864,11 +23580,11 @@ tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); - DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ + DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom); thr->valstack_top++; - DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ + DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ return ret; } @@ -22880,22 +23596,19 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); obj = duk_harray_alloc(thr, flags); DUK_ASSERT(obj != NULL); tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); - DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ + DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom); thr->valstack_top++; - DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ + DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ return ret; } @@ -22922,12 +23635,7 @@ a = duk_push_harray(thr); - duk_hobject_realloc_props(thr, - (duk_hobject *) a, - 0, - size, - 0, - 0); + duk_hobject_realloc_props(thr, (duk_hobject *) a, 0, size, 0, 0); a->length = size; return a; } @@ -22951,9 +23659,7 @@ DUK__CHECK_SPACE(); - obj = duk_hthread_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); + obj = duk_hthread_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); DUK_ASSERT(obj != NULL); obj->state = DUK_HTHREAD_STATE_INACTIVE; #if defined(DUK_USE_ROM_STRINGS) @@ -22993,8 +23699,7 @@ /* Initial stack size satisfies the stack slack constraints so there * is no need to require stack here. */ - DUK_ASSERT(DUK_VALSTACK_INITIAL_SIZE >= - DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + DUK_ASSERT(DUK_VALSTACK_INITIAL_SIZE >= DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); return ret; } @@ -23013,10 +23718,8 @@ */ obj = duk_hcompfunc_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_COMPFUNC | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_COMPFUNC | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); if (DUK_UNLIKELY(obj == NULL)) { DUK_ERROR_ALLOC_FAILED(thr); DUK_WO_NORETURN(return NULL;); @@ -23044,11 +23747,8 @@ DUK__CHECK_SPACE(); obj = duk_hboundfunc_alloc(thr->heap, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BOUNDFUNC | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BOUNDFUNC | DUK_HOBJECT_FLAG_CONSTRUCTABLE | + DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); if (!obj) { DUK_ERROR_ALLOC_FAILED(thr); DUK_WO_NORETURN(return NULL;); @@ -23066,7 +23766,8 @@ return obj; } -DUK_LOCAL duk_idx_t duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx) { +DUK_LOCAL duk_idx_t +duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx) { duk_hnatfunc *obj; duk_idx_t ret; duk_tval *tv_slot; @@ -23094,7 +23795,8 @@ obj->nargs = func_nargs; DUK_DDD(DUK_DDDPRINT("created native function object with flags: 0x%08lx, nargs=%ld", - (unsigned long) obj->obj.hdr.h_flags, (long) obj->nargs)); + (unsigned long) obj->obj.hdr.h_flags, + (long) obj->nargs)); tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); @@ -23106,7 +23808,7 @@ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) obj, thr->builtinsproto_bidx); return ret; - api_error: +api_error: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } @@ -23116,15 +23818,9 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Default prototype is a Duktape specific %NativeFunctionPrototype% * which provides .length and .name getters. @@ -23137,15 +23833,9 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Must use Function.prototype for standard built-in functions. */ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_FUNCTION_PROTOTYPE); @@ -23156,20 +23846,16 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | + DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Must use Function.prototype for standard built-in functions. */ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_FUNCTION_PROTOTYPE); } -DUK_EXTERNAL duk_idx_t duk_push_c_lightfunc(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic) { +DUK_EXTERNAL duk_idx_t +duk_push_c_lightfunc(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic) { duk_small_uint_t lf_flags; duk_tval *tv_slot; @@ -23198,13 +23884,15 @@ DUK_ASSERT(tv_slot >= thr->valstack_bottom); return (duk_idx_t) (tv_slot - thr->valstack_bottom); - api_error: +api_error: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) { +DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx) { duk_hbufobj *obj; duk_tval *tv_slot; @@ -23226,34 +23914,86 @@ return obj; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* XXX: There's quite a bit of overlap with buffer creation handling in * duk_bi_buffer.c. Look for overlap and refactor. */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK__PACK_ARGS(classnum,protobidx,elemtype,elemshift,istypedarray) \ +#define DUK__PACK_ARGS(classnum, protobidx, elemtype, elemshift, istypedarray) \ (((classnum) << 24) | ((protobidx) << 16) | ((elemtype) << 8) | ((elemshift) << 4) | (istypedarray)) static const duk_uint32_t duk__bufobj_flags_lookup = { /* Node.js Buffers are Uint8Array instances which inherit from Buffer.prototype. */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_ARRAYBUFFER, DUK_BIDX_ARRAYBUFFER_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 0), /* DUK_BUFOBJ_ARRAYBUFFER */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_BIDX_NODEJS_BUFFER_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 1), /* DUK_BUFOBJ_NODEJS_BUFFER */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_DATAVIEW, DUK_BIDX_DATAVIEW_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 0), /* DUK_BUFOBJ_DATAVIEW */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT8ARRAY, DUK_BIDX_INT8ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT8, 0, 1), /* DUK_BUFOBJ_INT8ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 1), /* DUK_BUFOBJ_UINT8ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8CLAMPED, 0, 1), /* DUK_BUFOBJ_UINT8CLAMPEDARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT16ARRAY, DUK_BIDX_INT16ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT16, 1, 1), /* DUK_BUFOBJ_INT16ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT16ARRAY, DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT16, 1, 1), /* DUK_BUFOBJ_UINT16ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT32ARRAY, DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT32, 2, 1), /* DUK_BUFOBJ_INT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT32ARRAY, DUK_BIDX_UINT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT32, 2, 1), /* DUK_BUFOBJ_UINT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT32ARRAY, DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_FLOAT32, 2, 1), /* DUK_BUFOBJ_FLOAT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT64ARRAY, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_FLOAT64, 3, 1) /* DUK_BUFOBJ_FLOAT64ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_ARRAYBUFFER, + DUK_BIDX_ARRAYBUFFER_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 0), /* DUK_BUFOBJ_ARRAYBUFFER */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, + DUK_BIDX_NODEJS_BUFFER_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 1), /* DUK_BUFOBJ_NODEJS_BUFFER */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_DATAVIEW, + DUK_BIDX_DATAVIEW_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 0), /* DUK_BUFOBJ_DATAVIEW */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT8ARRAY, + DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT8, + 0, + 1), /* DUK_BUFOBJ_INT8ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, + DUK_BIDX_UINT8ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 1), /* DUK_BUFOBJ_UINT8ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, + DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8CLAMPED, + 0, + 1), /* DUK_BUFOBJ_UINT8CLAMPEDARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT16ARRAY, + DUK_BIDX_INT16ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT16, + 1, + 1), /* DUK_BUFOBJ_INT16ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT16ARRAY, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT16, + 1, + 1), /* DUK_BUFOBJ_UINT16ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT32ARRAY, + DUK_BIDX_INT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT32, + 2, + 1), /* DUK_BUFOBJ_INT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT32ARRAY, + DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT32, + 2, + 1), /* DUK_BUFOBJ_UINT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT32ARRAY, + DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_FLOAT32, + 2, + 1), /* DUK_BUFOBJ_FLOAT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT64ARRAY, + DUK_BIDX_FLOAT64ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_FLOAT64, + 3, + 1) /* DUK_BUFOBJ_FLOAT64ARRAY */ }; -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) { +DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, + duk_idx_t idx_buffer, + duk_size_t byte_offset, + duk_size_t byte_length, + duk_uint_t flags) { duk_hbufobj *h_bufobj; duk_hbuffer *h_val; duk_hobject *h_arraybuf; @@ -23276,7 +24016,7 @@ } } - DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */ + DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */ lookupidx = flags; if (DUK_UNLIKELY(lookupidx >= sizeof(duk__bufobj_flags_lookup) / sizeof(duk_uint32_t))) { goto arg_error; @@ -23286,9 +24026,9 @@ protobidx = (tmp >> 16) & 0xff; h_arraybuf = duk_get_hobject(thr, idx_buffer); - if (h_arraybuf != NULL && /* argument is an object */ - flags != DUK_BUFOBJ_ARRAYBUFFER && /* creating a view */ - DUK_HOBJECT_GET_CLASS_NUMBER(h_arraybuf) == DUK_HOBJECT_CLASS_ARRAYBUFFER /* argument is ArrayBuffer */) { + if (h_arraybuf != NULL && /* argument is an object */ + flags != DUK_BUFOBJ_ARRAYBUFFER && /* creating a view */ + DUK_HOBJECT_GET_CLASS_NUMBER(h_arraybuf) == DUK_HOBJECT_CLASS_ARRAYBUFFER /* argument is ArrayBuffer */) { duk_uint_t tmp_offset; DUK_HBUFOBJ_ASSERT_VALID((duk_hbufobj *) h_arraybuf); @@ -23325,9 +24065,7 @@ DUK_ASSERT(h_val != NULL); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(classnum), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(classnum), (duk_small_int_t) protobidx); DUK_ASSERT(h_bufobj != NULL); @@ -23350,16 +24088,20 @@ */ return; - range_error: +range_error: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); - arg_error: +arg_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ -DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) { +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, + duk_idx_t idx_buffer, + duk_size_t byte_offset, + duk_size_t byte_length, + duk_uint_t flags) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx_buffer); DUK_UNREF(byte_offset); @@ -23368,9 +24110,14 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ -DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap) { +DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + va_list ap) { duk_hobject *proto; #if defined(DUK_USE_AUGMENT_ERROR_CREATE) duk_small_uint_t augment_flags; @@ -23393,9 +24140,8 @@ /* error gets its 'name' from the prototype */ proto = duk_error_prototype_from_code(thr, err_code); (void) duk_push_object_helper_proto(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR), proto); /* ... and its 'message' from an instance property */ @@ -23418,13 +24164,14 @@ /* Creation time error augmentation */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) /* filename may be NULL in which case file/line is not recorded */ - duk_err_augment_error_create(thr, thr, filename, line, augment_flags); /* may throw an error */ + duk_err_augment_error_create(thr, thr, filename, line, augment_flags); /* may throw an error */ #endif return duk_get_top_index_unsafe(thr); } -DUK_EXTERNAL duk_idx_t duk_push_error_object_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { +DUK_EXTERNAL duk_idx_t +duk_push_error_object_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { va_list ap; duk_idx_t ret; @@ -23452,7 +24199,7 @@ va_end(ap); return ret; } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ DUK_EXTERNAL void *duk_push_buffer_raw(duk_hthread *thr, duk_size_t size, duk_small_uint_t flags) { duk_tval *tv_slot; @@ -23555,13 +24302,10 @@ /* CALLABLE and CONSTRUCTABLE flags are copied from the (initial) * target, see ES2015 Sections 9.5.15 and 9.5.13. */ - flags = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h_target) & - (DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE); - flags |= DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ; + flags = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h_target) & (DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE); + flags |= DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ; if (flags & DUK_HOBJECT_FLAG_CALLABLE) { - flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION) | - DUK_HOBJECT_FLAG_SPECIAL_CALL; + flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION) | DUK_HOBJECT_FLAG_SPECIAL_CALL; } else { flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT); } @@ -23587,25 +24331,25 @@ DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) h_proxy); DUK_HOBJECT_INCREF(thr, (duk_hobject *) h_proxy); tv_slot++; - DUK_TVAL_SET_UNDEFINED(tv_slot); /* ... target handler -> ... proxy undefined */ - thr->valstack_top = tv_slot; /* -> ... proxy */ + DUK_TVAL_SET_UNDEFINED(tv_slot); /* ... target handler -> ... proxy undefined */ + thr->valstack_top = tv_slot; /* -> ... proxy */ DUK_DD(DUK_DDPRINT("created Proxy: %!iT", duk_get_tval(thr, -1))); return (duk_idx_t) (thr->valstack_top - thr->valstack_bottom - 1); - fail_args: +fail_args: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } -#else /* DUK_USE_ES6_PROXY */ +#else /* DUK_USE_ES6_PROXY */ DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr, duk_uint_t proxy_flags) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(proxy_flags); DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ASSERTIONS) DUK_LOCAL void duk__validate_push_heapptr(duk_hthread *thr, void *ptr) { @@ -23632,9 +24376,7 @@ * the finalizer starts executing). */ #if defined(DUK_USE_FINALIZER_SUPPORT) - for (curr = thr->heap->finalize_list; - curr != NULL; - curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { + for (curr = thr->heap->finalize_list; curr != NULL; curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { /* FINALIZABLE is set for all objects on finalize_list * except for an object being finalized right now. So * can't assert here. @@ -23646,18 +24388,18 @@ if (curr == h) { if (DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) h)) { /* Object is currently being finalized. */ - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } else { /* Not being finalized but on finalize_list, * allowed since Duktape 2.1. */ - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_REFERENCE_COUNTING) /* Because refzero_list is now processed to completion inline with @@ -23683,7 +24425,7 @@ #endif while (str != NULL) { if (str == (duk_hstring *) h) { - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; break; } @@ -23692,18 +24434,16 @@ } DUK_ASSERT(found != 0); } else { - for (curr = thr->heap->heap_allocated; - curr != NULL; - curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { + for (curr = thr->heap->heap_allocated; curr != NULL; curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { if (curr == h) { - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } } DUK_ASSERT(found != 0); } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ DUK_EXTERNAL duk_idx_t duk_push_heapptr(duk_hthread *thr, void *ptr) { duk_idx_t ret; @@ -23769,7 +24509,7 @@ * heap_allocated. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); /* Preincremented on finalize_list insert. */ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); /* Preincremented on finalize_list insert. */ DUK_HEAPHDR_PREDEC_REFCOUNT(curr); #endif DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(thr->heap, curr); @@ -23801,10 +24541,9 @@ DUK_ASSERT_API_ENTRY(thr); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ return duk_get_top_index_unsafe(thr); } @@ -23913,12 +24652,12 @@ DUK_ASSERT_API_ENTRY(thr); duk_pop_n(thr, count); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_pop_n_unsafe(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); duk__pop_n_unsafe_raw(thr, count); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Pop N elements without DECREF (in effect "stealing" any actual refcounts). */ #if defined(DUK_USE_REFERENCE_COUNTING) @@ -23941,12 +24680,12 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ DUK_INTERNAL void duk_pop_n_nodecref_unsafe(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); duk_pop_n_unsafe(thr, count); } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* Popping one element is called so often that when footprint is not an issue, * compile a specialized function for it. @@ -23964,7 +24703,7 @@ DUK_ASSERT_API_ENTRY(thr); duk_pop_n_nodecref_unsafe(thr, 1); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_LOCAL DUK_ALWAYS_INLINE void duk__pop_unsafe_raw(duk_hthread *thr) { duk_tval *tv; @@ -23976,7 +24715,7 @@ tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif @@ -24012,14 +24751,14 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ #if defined(DUK_USE_PREFER_SIZE) DUK_INTERNAL void duk_pop_undefined(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); duk_pop_nodecref_unsafe(thr); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_pop_undefined(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->valstack_top != thr->valstack_bottom); @@ -24031,7 +24770,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ #if defined(DUK_USE_PREFER_SIZE) DUK_EXTERNAL void duk_pop_2(duk_hthread *thr) { @@ -24058,14 +24797,14 @@ tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif @@ -24099,7 +24838,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_pop_3(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); @@ -24146,9 +24885,9 @@ * multiplying with sizeof(duk_tval) won't wrap. */ DUK_ASSERT(count >= 0 && count <= (duk_idx_t) DUK_USE_VALSTACK_LIMIT); - DUK_ASSERT((duk_size_t) count <= DUK_SIZE_MAX / sizeof(duk_tval)); /* no wrapping */ + DUK_ASSERT((duk_size_t) count <= DUK_SIZE_MAX / sizeof(duk_tval)); /* no wrapping */ - tv_dst = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) count); /* XXX: uninitialized would be OK */ + tv_dst = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) count); /* XXX: uninitialized would be OK */ DUK_ASSERT(count == 0 || tv_dst != NULL); DUK_ASSERT(!duk_is_bare_object(thr, -1)); @@ -24162,7 +24901,7 @@ * the rest; no refcount operations needed. */ - tv_dst = tv_src; /* when count == 0, same as tv_src (OK) */ + tv_dst = tv_src; /* when count == 0, same as tv_src (OK) */ tv_src = thr->valstack_top - 1; DUK_TVAL_SET_TVAL(tv_dst, tv_src); @@ -24192,9 +24931,8 @@ DUK_ASSERT(h != NULL); DUK_UNREF(h); -#if defined(DUK_USE_ARRAY_FASTPATH) /* close enough */ - if (DUK_LIKELY(DUK_HOBJECT_IS_ARRAY(h) && - ((duk_harray *) h)->length <= DUK_HOBJECT_GET_ASIZE(h))) { +#if defined(DUK_USE_ARRAY_FASTPATH) /* close enough */ + if (DUK_LIKELY(DUK_HOBJECT_IS_ARRAY(h) && ((duk_harray *) h)->length <= DUK_HOBJECT_GET_ASIZE(h))) { duk_harray *h_arr; duk_tval *tv_src; duk_tval *tv_dst; @@ -24215,8 +24953,7 @@ * XXX: alternatively, could prevent finalizers for the * duration. */ - if (DUK_UNLIKELY(len != h_arr->length || - h_arr->length > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr))) { + if (DUK_UNLIKELY(len != h_arr->length || h_arr->length > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr))) { goto skip_fast; } @@ -24235,7 +24972,7 @@ * without an ancestor lookup (technically * not compliant). */ - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_dst)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_dst)); /* valstack policy */ } else { DUK_TVAL_SET_TVAL(tv_dst, tv_src); DUK_TVAL_INCREF(thr, tv_dst); @@ -24247,8 +24984,8 @@ thr->valstack_top = tv_dst; return (duk_idx_t) h_arr->length; } - skip_fast: -#endif /* DUK_USE_ARRAY_FASTPATH */ + skip_fast: +#endif /* DUK_USE_ARRAY_FASTPATH */ /* Slow path: actual lookups. The initial 'length' lookup * decides the output length, regardless of side effects that @@ -24257,7 +24994,7 @@ */ idx = duk_normalize_index(thr, idx); duk_get_prop_stridx(thr, idx, DUK_STRIDX_LENGTH); - len = duk_to_uint32(thr, -1); /* ToUint32() coercion required */ + len = duk_to_uint32(thr, -1); /* ToUint32() coercion required */ if (DUK_UNLIKELY(len >= 0x80000000UL)) { goto fail_over_2g; } @@ -24276,7 +25013,7 @@ DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); - fail_over_2g: +fail_over_2g: DUK_ERROR_RANGE_INVALID_LENGTH(thr); DUK_WO_NORETURN(return 0;); } @@ -24361,7 +25098,12 @@ } } -DUK_EXTERNAL void duk_error_va_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap) { +DUK_EXTERNAL void duk_error_va_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + va_list ap) { DUK_ASSERT_API_ENTRY(thr); duk_push_error_object_va_raw(thr, err_code, filename, line, fmt, ap); @@ -24369,7 +25111,12 @@ DUK_WO_NORETURN(return;); } -DUK_EXTERNAL void duk_error_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { +DUK_EXTERNAL void duk_error_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + ...) { va_list ap; DUK_ASSERT_API_ENTRY(thr); @@ -24388,7 +25135,8 @@ #endif #if !defined(DUK_USE_VARIADIC_MACROS) -DUK_NORETURN(DUK_LOCAL_DECL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap)); +DUK_NORETURN( + DUK_LOCAL_DECL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap)); DUK_LOCAL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap) { const char *filename; @@ -24406,7 +25154,8 @@ DUK_WO_NORETURN(return;); } -#define DUK__ERROR_STASH_SHARED(code) do { \ +#define DUK__ERROR_STASH_SHARED(code) \ + do { \ va_list ap; \ va_start(ap, fmt); \ duk__throw_error_from_stash(thr, (code), fmt, ap); \ @@ -24446,7 +25195,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK__ERROR_STASH_SHARED(DUK_ERR_URI_ERROR); } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ /* * Comparison @@ -24565,7 +25314,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(tv)); - DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags); /* read before 'tv' potentially invalidated */ + DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags); /* read before 'tv' potentially invalidated */ duk_push_literal(thr, "function "); duk_push_lightfunc_name_raw(thr, func, lf_flags); duk_push_literal(thr, "() { lightfunc code }"); @@ -24586,7 +25335,7 @@ duk_small_uint_t t; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(sz <= 32); /* sanity limit for function pointer size */ + DUK_ASSERT(sz <= 32); /* sanity limit for function pointer size */ p = buf; #if defined(DUK_USE_INTEGER_LE) @@ -24615,9 +25364,9 @@ */ /* String limits for summary strings. */ -#define DUK__READABLE_SUMMARY_MAXCHARS 96 /* maximum supported by helper */ -#define DUK__READABLE_STRING_MAXCHARS 32 /* for strings/symbols */ -#define DUK__READABLE_ERRMSG_MAXCHARS 96 /* for error messages */ +#define DUK__READABLE_SUMMARY_MAXCHARS 96 /* maximum supported by helper */ +#define DUK__READABLE_STRING_MAXCHARS 32 /* for strings/symbols */ +#define DUK__READABLE_ERRMSG_MAXCHARS 96 /* for error messages */ /* String sanitizer which escapes ASCII control characters and a few other * ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with @@ -24626,8 +25375,7 @@ */ DUK_LOCAL void duk__push_hstring_readable_unicode(duk_hthread *thr, duk_hstring *h_input, duk_small_uint_t maxchars) { const duk_uint8_t *p, *p_start, *p_end; - duk_uint8_t bufDUK_UNICODE_MAX_XUTF8_LENGTH * DUK__READABLE_SUMMARY_MAXCHARS + - 2 /*quotes*/ + 3 /*periods*/; + duk_uint8_t bufDUK_UNICODE_MAX_XUTF8_LENGTH * DUK__READABLE_SUMMARY_MAXCHARS + 2 /*quotes*/ + 3 /*periods*/; duk_uint8_t *q; duk_ucodepoint_t cp; duk_small_uint_t nchars; @@ -24655,7 +25403,7 @@ } if (duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp)) { if (cp < 0x20 || cp == 0x7f || cp == DUK_ASC_SINGLEQUOTE || cp == DUK_ASC_BACKSLASH) { - DUK_ASSERT(DUK_UNICODE_MAX_XUTF8_LENGTH >= 4); /* estimate is valid */ + DUK_ASSERT(DUK_UNICODE_MAX_XUTF8_LENGTH >= 4); /* estimate is valid */ DUK_ASSERT((cp >> 4) <= 0x0f); *q++ = (duk_uint8_t) DUK_ASC_BACKSLASH; *q++ = (duk_uint8_t) DUK_ASC_LC_X; @@ -24665,7 +25413,7 @@ q += duk_unicode_encode_xutf8(cp, q); } } else { - p++; /* advance manually */ + p++; /* advance manually */ *q++ = (duk_uint8_t) DUK_ASC_QUESTION; } nchars++; @@ -24704,8 +25452,10 @@ duk_hobject *h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); - if (error_aware && - duk_hobject_prototype_chain_contains(thr, h, thr->builtinsDUK_BIDX_ERROR_PROTOTYPE, 1 /*ignore_loop*/)) { + if (error_aware && duk_hobject_prototype_chain_contains(thr, + h, + thr->builtinsDUK_BIDX_ERROR_PROTOTYPE, + 1 /*ignore_loop*/)) { /* Get error message in a side effect free way if * possible; if not, summarize as a generic object. * Error message currently gets quoted. @@ -24719,7 +25469,9 @@ /* It's critical to avoid recursion so * only summarize a string .message. */ - duk__push_hstring_readable_unicode(thr, DUK_TVAL_GET_STRING(tv_msg), DUK__READABLE_ERRMSG_MAXCHARS); + duk__push_hstring_readable_unicode(thr, + DUK_TVAL_GET_STRING(tv_msg), + DUK__READABLE_ERRMSG_MAXCHARS); break; } } @@ -24802,7 +25554,7 @@ * Functions */ -#if 0 /* not used yet */ +#if 0 /* not used yet */ DUK_INTERNAL void duk_push_hnatfunc_name(duk_hthread *thr, duk_hnatfunc *h) { duk_c_function func; @@ -24829,7 +25581,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(thr); - DUK_ASSERT(count * sizeof(duk_tval) >= count); /* no wrap */ + DUK_ASSERT(count * sizeof(duk_tval) >= count); /* no wrap */ duk_memcpy_unsafe((void *) tv_dst, (const void *) tv_src, count * sizeof(duk_tval)); @@ -24901,15 +25653,14 @@ /* Impose a string maximum length, need to handle overflow * correctly. */ - if (new_len < len || /* wrapped */ + if (new_len < len || /* wrapped */ new_len > (duk_size_t) DUK_HSTRING_MAX_BYTELEN) { goto error_overflow; } len = new_len; } - DUK_DDD(DUK_DDDPRINT("join/concat %lu strings, total length %lu bytes", - (unsigned long) count, (unsigned long) len)); + DUK_DDD(DUK_DDDPRINT("join/concat %lu strings, total length %lu bytes", (unsigned long) count, (unsigned long) len)); /* Use stack allocated buffer to ensure reachability in errors * (e.g. intern error). @@ -24922,11 +25673,11 @@ idx = 0; for (i = count; i >= 1; i--) { if (is_join && i != count) { - h = duk_require_hstring(thr, -((duk_idx_t) count) - 2); /* extra -1 for buffer */ + h = duk_require_hstring(thr, -((duk_idx_t) count) - 2); /* extra -1 for buffer */ duk_memcpy(buf + idx, DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); idx += DUK_HSTRING_GET_BYTELEN(h); } - h = duk_require_hstring(thr, -((duk_idx_t) i) - 1); /* extra -1 for buffer */ + h = duk_require_hstring(thr, -((duk_idx_t) i) - 1); /* extra -1 for buffer */ duk_memcpy(buf + idx, DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); idx += DUK_HSTRING_GET_BYTELEN(h); } @@ -24938,21 +25689,21 @@ /* Get rid of the strings early to minimize memory use before intern. */ if (is_join) { - duk_replace(thr, -((duk_idx_t) count) - 2); /* overwrite sep */ + duk_replace(thr, -((duk_idx_t) count) - 2); /* overwrite sep */ duk_pop_n(thr, (duk_idx_t) count); } else { - duk_replace(thr, -((duk_idx_t) count) - 1); /* overwrite str1 */ + duk_replace(thr, -((duk_idx_t) count) - 1); /* overwrite str1 */ duk_pop_n(thr, (duk_idx_t) (count - 1)); } /* ... buf */ - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ /* ... res */ return; - error_overflow: +error_overflow: DUK_ERROR_RANGE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return;); } @@ -24968,7 +25719,7 @@ DUK_ASSERT_API_ENTRY(thr); duk_concat(thr, 2); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_concat_2(duk_hthread *thr) { duk_hstring *h1; duk_hstring *h2; @@ -24978,14 +25729,14 @@ duk_size_t len; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(duk_get_top(thr) >= 2); /* Trusted caller. */ + DUK_ASSERT(duk_get_top(thr) >= 2); /* Trusted caller. */ h1 = duk_to_hstring(thr, -2); h2 = duk_to_hstring(thr, -1); len1 = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h1); len2 = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h2); len = len1 + len2; - if (DUK_UNLIKELY(len < len1 || /* wrapped */ + if (DUK_UNLIKELY(len < len1 || /* wrapped */ len > (duk_size_t) DUK_HSTRING_MAX_BYTELEN)) { goto error_overflow; } @@ -24994,7 +25745,7 @@ duk_memcpy((void *) buf, (const void *) DUK_HSTRING_GET_DATA(h1), (size_t) len1); duk_memcpy((void *) (buf + len1), (const void *) DUK_HSTRING_GET_DATA(h2), (size_t) len2); - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ /* ... str1 str2 buf */ @@ -25002,11 +25753,11 @@ duk_pop_unsafe(thr); return; - error_overflow: +error_overflow: DUK_ERROR_RANGE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_join(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); @@ -25025,7 +25776,7 @@ DUK_ASSERT_API_ENTRY(thr); - h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ + h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input); @@ -25052,11 +25803,11 @@ idx = duk_normalize_index(thr, idx); - h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ + h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* Reasonable output estimate. */ + DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* Reasonable output estimate. */ p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); @@ -25077,7 +25828,7 @@ } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 encoded. */ duk_replace(thr, idx); } @@ -25090,7 +25841,7 @@ DUK_ASSERT_API_ENTRY(thr); - idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ + idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ h = duk_require_hstring(thr, idx); DUK_ASSERT(h != NULL); @@ -25115,7 +25866,7 @@ end_byte_offset = (duk_size_t) duk_heap_strcache_offset_char2byte(thr, h, (duk_uint_fast32_t) end_offset); DUK_ASSERT(end_byte_offset >= start_byte_offset); - DUK_ASSERT(end_byte_offset - start_byte_offset <= DUK_UINT32_MAX); /* Guaranteed by string limits. */ + DUK_ASSERT(end_byte_offset - start_byte_offset <= DUK_UINT32_MAX); /* Guaranteed by string limits. */ /* No size check is necessary. */ res = duk_heap_strtable_intern_checked(thr, @@ -25131,13 +25882,13 @@ */ DUK_EXTERNAL void duk_trim(duk_hthread *thr, duk_idx_t idx) { duk_hstring *h; - const duk_uint8_t *p, *p_start, *p_end, *p_tmp1, *p_tmp2; /* pointers for scanning */ - const duk_uint8_t *q_start, *q_end; /* start (incl) and end (excl) of trimmed part */ + const duk_uint8_t *p, *p_start, *p_end, *p_tmp1, *p_tmp2; /* pointers for scanning */ + const duk_uint8_t *q_start, *q_end; /* start (incl) and end (excl) of trimmed part */ duk_codepoint_t cp; DUK_ASSERT_API_ENTRY(thr); - idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ + idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ h = duk_require_hstring(thr, idx); DUK_ASSERT(h != NULL); @@ -25179,7 +25930,7 @@ } q_end = p; - scan_done: +scan_done: /* This may happen when forward and backward scanning disagree * (possible for non-extended-UTF-8 strings). */ @@ -25192,8 +25943,10 @@ DUK_ASSERT(q_end >= q_start); DUK_DDD(DUK_DDDPRINT("trim: p_start=%p, p_end=%p, q_start=%p, q_end=%p", - (const void *) p_start, (const void *) p_end, - (const void *) q_start, (const void *) q_end)); + (const void *) p_start, + (const void *) p_end, + (const void *) q_start, + (const void *) q_end)); if (q_start == p_start && q_end == p_end) { DUK_DDD(DUK_DDDPRINT("nothing was trimmed: avoid interning (hashing etc)")); @@ -25214,15 +25967,15 @@ * is handling of clamped offsets. */ - h = duk_require_hstring(thr, idx); /* Accept symbols. */ + h = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h != NULL); - DUK_ASSERT_DISABLE(char_offset >= 0); /* Always true, arg is unsigned. */ + DUK_ASSERT_DISABLE(char_offset >= 0); /* Always true, arg is unsigned. */ if (char_offset >= DUK_HSTRING_GET_CHARLEN(h)) { return 0; } - DUK_ASSERT(char_offset <= DUK_UINT_MAX); /* Guaranteed by string limits. */ + DUK_ASSERT(char_offset <= DUK_UINT_MAX); /* Guaranteed by string limits. */ cp = duk_hstring_char_code_at_raw(thr, h, (duk_uint_t) char_offset, 0 /*surrogate_aware*/); return (duk_codepoint_t) cp; } @@ -25265,7 +26018,7 @@ return duk_time_get_ecmascript_time(thr); } -#if 0 /* XXX: worth exposing? */ +#if 0 /* XXX: worth exposing? */ DUK_EXTERNAL duk_double_t duk_get_monotonic_time(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(thr); @@ -25280,7 +26033,7 @@ duk_uint_t flags; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(comp != NULL); /* XXX: or check? */ + DUK_ASSERT(comp != NULL); /* XXX: or check? */ DUK_UNREF(thr); /* Convert as one-based, but change month to zero-based to match the @@ -25309,7 +26062,7 @@ duk_uint_t flags; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(comp != NULL); /* XXX: or check? */ + DUK_ASSERT(comp != NULL); /* XXX: or check? */ DUK_UNREF(thr); /* Match Date constructor behavior (with UTC time). Month is given @@ -25330,7 +26083,7 @@ dpartsDUK_DATE_IDX_MINUTE = comp->minutes; dpartsDUK_DATE_IDX_SECOND = comp->seconds; dpartsDUK_DATE_IDX_MILLISECOND = comp->milliseconds; - dpartsDUK_DATE_IDX_WEEKDAY = 0; /* ignored */ + dpartsDUK_DATE_IDX_WEEKDAY = 0; /* ignored */ d = duk_bi_date_get_timeval_from_dparts(dparts, flags); @@ -25381,7 +26134,7 @@ /* Perform an intermediate join when this many elements have been pushed * on the value stack. */ -#define DUK__ARRAY_MID_JOIN_LIMIT 4096 +#define DUK__ARRAY_MID_JOIN_LIMIT 4096 #if defined(DUK_USE_ARRAY_BUILTIN) @@ -25432,7 +26185,7 @@ duk_hobject *h; duk_uint_t flags_mask, flags_bits, flags_value; - DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* because call in progress */ + DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* because call in progress */ tv = DUK_GET_THIS_TVAL_PTR(thr); /* Fast path requires that 'this' is a duk_harray. Read only arrays @@ -25444,11 +26197,8 @@ } h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); - flags_mask = DUK_HOBJECT_FLAG_ARRAY_PART | \ - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HEAPHDR_FLAG_READONLY; - flags_bits = DUK_HOBJECT_FLAG_ARRAY_PART | \ - DUK_HOBJECT_FLAG_EXOTIC_ARRAY; + flags_mask = DUK_HOBJECT_FLAG_ARRAY_PART | DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HEAPHDR_FLAG_READONLY; + flags_bits = DUK_HOBJECT_FLAG_ARRAY_PART | DUK_HOBJECT_FLAG_EXOTIC_ARRAY; flags_value = DUK_HEAPHDR_GET_FLAGS_RAW((duk_heaphdr *) h); if ((flags_value & flags_mask) != flags_bits) { DUK_DD(DUK_DDPRINT("reject array fast path: object flag check failed")); @@ -25474,7 +26224,7 @@ DUK_DD(DUK_DDPRINT("array fast path allowed for: %!O", (duk_heaphdr *) h)); return (duk_harray *) h; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ /* * Constructor @@ -25544,7 +26294,7 @@ */ DUK_DDD(DUK_DDDPRINT("this.join is not callable, fall back to (original) Object.toString")); duk_set_top(thr, 0); - return duk_bi_object_prototype_to_string(thr); /* has access to 'this' binding */ + return duk_bi_object_prototype_to_string(thr); /* has access to 'this' binding */ } /* ... this func */ @@ -25553,9 +26303,8 @@ /* ... func this */ - DUK_DDD(DUK_DDDPRINT("calling: func=%!iT, this=%!iT", - (duk_tval *) duk_get_tval(thr, -2), - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD( + DUK_DDDPRINT("calling: func=%!iT, this=%!iT", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_call_method(thr, 0); return 1; @@ -25585,7 +26334,7 @@ (void) duk_push_this_coercible_to_object(thr); duk_insert(thr, 0); n = duk_get_top(thr); - duk_push_array(thr); /* -> ToObject(this) item1 ... itemN arr */ + duk_push_array(thr); /* -> ToObject(this) item1 ... itemN arr */ /* NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index() * (which differs from the official algorithm). If no error is thrown, this @@ -25636,7 +26385,7 @@ } DUK_ASSERT(duk_is_object(thr, i)); - need_has_check = (DUK_HOBJECT_IS_PROXY(h) != 0); /* Always 0 w/o Proxy support. */ + need_has_check = (DUK_HOBJECT_IS_PROXY(h) != 0); /* Always 0 w/o Proxy support. */ /* ToObject(this) item1 ... itemN arr */ @@ -25668,7 +26417,7 @@ } } idx++; - DUK_ASSERT(idx != 0U); /* Wrap check above. */ + DUK_ASSERT(idx != 0U); /* Wrap check above. */ } } @@ -25683,7 +26432,7 @@ DUK_ASSERT_TOP(thr, n + 1); return 1; - fail_wrap: +fail_wrap: DUK_ERROR_RANGE_INVALID_LENGTH(thr); DUK_WO_NORETURN(return 0;); } @@ -25729,8 +26478,7 @@ (unsigned long) len)); /* The extra (+4) is tight. */ - valstack_required = (duk_idx_t) ((len >= DUK__ARRAY_MID_JOIN_LIMIT ? - DUK__ARRAY_MID_JOIN_LIMIT : len) + 4); + valstack_required = (duk_idx_t) ((len >= DUK__ARRAY_MID_JOIN_LIMIT ? DUK__ARRAY_MID_JOIN_LIMIT : len) + 4); duk_require_stack(thr, valstack_required); duk_dup_0(thr); @@ -25741,14 +26489,13 @@ idx = 0; for (;;) { DUK_DDD(DUK_DDDPRINT("join idx=%ld", (long) idx)); - if (count >= DUK__ARRAY_MID_JOIN_LIMIT || /* intermediate join to avoid valstack overflow */ + if (count >= DUK__ARRAY_MID_JOIN_LIMIT || /* intermediate join to avoid valstack overflow */ idx >= len) { /* end of loop (careful with len==0) */ /* sep ToObject(this) len sep str0 ... str(count-1) */ - DUK_DDD(DUK_DDDPRINT("mid/final join, count=%ld, idx=%ld, len=%ld", - (long) count, (long) idx, (long) len)); - duk_join(thr, (duk_idx_t) count); /* -> sep ToObject(this) len str */ - duk_dup_0(thr); /* -> sep ToObject(this) len str sep */ - duk_insert(thr, -2); /* -> sep ToObject(this) len sep str */ + DUK_DDD(DUK_DDDPRINT("mid/final join, count=%ld, idx=%ld, len=%ld", (long) count, (long) idx, (long) len)); + duk_join(thr, (duk_idx_t) count); /* -> sep ToObject(this) len str */ + duk_dup_0(thr); /* -> sep ToObject(this) len str sep */ + duk_insert(thr, -2); /* -> sep ToObject(this) len sep str */ count = 1; } if (idx >= len) { @@ -25764,7 +26511,7 @@ if (to_locale_string) { duk_to_object(thr, -1); duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_LOCALE_STRING); - duk_insert(thr, -2); /* -> ... toLocaleString ToObject(val) */ + duk_insert(thr, -2); /* -> ... toLocaleString ToObject(val) */ duk_call_method(thr, 0); } duk_to_string(thr, -1); @@ -25822,7 +26569,7 @@ return 1; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ DUK_INTERNAL duk_ret_t duk_bi_array_prototype_pop(duk_hthread *thr) { duk_uint32_t len; @@ -25873,7 +26620,7 @@ DUK_ASSERT((duk_uint32_t) n <= DUK_UINT32_MAX); if (DUK_UNLIKELY(len + (duk_uint32_t) n < len)) { DUK_D(DUK_DPRINT("Array.prototype.push() would go beyond 32-bit length, throw")); - DUK_DCERROR_RANGE_INVALID_LENGTH(thr); /* != 0 return value returned as is by caller */ + DUK_DCERROR_RANGE_INVALID_LENGTH(thr); /* != 0 return value returned as is by caller */ } if (len + (duk_uint32_t) n > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr)) { /* Array part would need to be extended. Rely on slow path @@ -25903,7 +26650,7 @@ duk_push_uint(thr, (duk_uint_t) len); return 1; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ DUK_INTERNAL duk_ret_t duk_bi_array_prototype_push(duk_hthread *thr) { /* Note: 'this' is not necessarily an Array object. The push() @@ -25978,7 +26725,7 @@ duk_bool_t have1, have2; duk_bool_t undef1, undef2; duk_small_int_t ret; - duk_idx_t idx_obj = 1; /* fixed offsets in valstack */ + duk_idx_t idx_obj = 1; /* fixed offsets in valstack */ duk_idx_t idx_fn = 0; duk_hstring *h1, *h2; @@ -25999,7 +26746,8 @@ if (idx1 == idx2) { DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%ld, idx2=%ld -> indices identical, quick exit", - (long) idx1, (long) idx2)); + (long) idx1, + (long) idx2)); return 0; } @@ -26007,8 +26755,12 @@ have2 = duk_get_prop_index(thr, idx_obj, (duk_uarridx_t) idx2); DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%ld, idx2=%ld, have1=%ld, have2=%ld, val1=%!T, val2=%!T", - (long) idx1, (long) idx2, (long) have1, (long) have2, - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (long) idx1, + (long) idx2, + (long) have1, + (long) have2, + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); if (have1) { if (have2) { @@ -26050,9 +26802,9 @@ duk_double_t d; /* No need to check callable; duk_call() will do that. */ - duk_dup(thr, idx_fn); /* -> ... x y fn */ - duk_insert(thr, -3); /* -> ... fn x y */ - duk_call(thr, 2); /* -> ... res */ + duk_dup(thr, idx_fn); /* -> ... x y fn */ + duk_insert(thr, -3); /* -> ... fn x y */ + duk_call(thr, 2); /* -> ... res */ /* ES5 is a bit vague about what to do if the return value is * not a number. ES2015 provides a concrete description: @@ -26084,10 +26836,10 @@ DUK_ASSERT(h1 != NULL); DUK_ASSERT(h2 != NULL); - ret = duk_js_string_compare(h1, h2); /* retval is directly usable */ + ret = duk_js_string_compare(h1, h2); /* retval is directly usable */ goto pop_ret; - pop_ret: +pop_ret: duk_pop_2_unsafe(thr); DUK_DDD(DUK_DDDPRINT("-> result %ld", (long) ret)); return ret; @@ -26095,7 +26847,7 @@ DUK_LOCAL void duk__array_sort_swap(duk_hthread *thr, duk_int_t l, duk_int_t r) { duk_bool_t have_l, have_r; - duk_idx_t idx_obj = 1; /* fixed offset in valstack */ + duk_idx_t idx_obj = 1; /* fixed offset in valstack */ if (l == r) { return; @@ -26148,8 +26900,7 @@ *ptr++ = ''; *ptr++ = '\0'; - DUK_DDD(DUK_DDDPRINT("%s (lo=%ld, hi=%ld, pivot=%ld)", - (const char *) buf, (long) lo, (long) hi, (long) pivot)); + DUK_DDD(DUK_DDDPRINT("%s (lo=%ld, hi=%ld, pivot=%ld)", (const char *) buf, (long) lo, (long) hi, (long) pivot)); } #endif @@ -26158,8 +26909,7 @@ /* The lo/hi indices may be crossed and hi < 0 is possible at entry. */ - DUK_DDD(DUK_DDDPRINT("duk__array_qsort: lo=%ld, hi=%ld, obj=%!T", - (long) lo, (long) hi, (duk_tval *) duk_get_tval(thr, 1))); + DUK_DDD(DUK_DDDPRINT("duk__array_qsort: lo=%ld, hi=%ld, obj=%!T", (long) lo, (long) hi, (duk_tval *) duk_get_tval(thr, 1))); DUK_ASSERT_TOP(thr, 3); @@ -26177,7 +26927,7 @@ DUK_ASSERT(hi - lo + 1 >= 2); /* randomized pivot selection */ - p = lo + (duk_int_t) (DUK_UTIL_GET_RANDOM_DOUBLE(thr) * (duk_double_t) (hi - lo + 1)); + p = lo + (duk_int_t) (duk_util_get_random_double(thr) * (duk_double_t) (hi - lo + 1)); DUK_ASSERT(p >= lo && p <= hi); DUK_DDD(DUK_DDDPRINT("lo=%ld, hi=%ld, chose pivot p=%ld", (long) lo, (long) hi, (long) p)); @@ -26191,23 +26941,21 @@ for (;;) { /* find elements to swap */ for (;;) { - DUK_DDD(DUK_DDDPRINT("left scan: l=%ld, r=%ld, p=%ld", - (long) l, (long) r, (long) p)); + DUK_DDD(DUK_DDDPRINT("left scan: l=%ld, r=%ld, p=%ld", (long) l, (long) r, (long) p)); if (l >= hi) { break; } - if (duk__array_sort_compare(thr, l, p) >= 0) { /* !(l < p) */ + if (duk__array_sort_compare(thr, l, p) >= 0) { /* !(l < p) */ break; } l++; } for (;;) { - DUK_DDD(DUK_DDDPRINT("right scan: l=%ld, r=%ld, p=%ld", - (long) l, (long) r, (long) p)); + DUK_DDD(DUK_DDDPRINT("right scan: l=%ld, r=%ld, p=%ld", (long) l, (long) r, (long) p)); if (r <= lo) { break; } - if (duk__array_sort_compare(thr, p, r) >= 0) { /* !(p < r) */ + if (duk__array_sort_compare(thr, p, r) >= 0) { /* !(p < r) */ break; } r--; @@ -26225,7 +26973,7 @@ l++; r--; } - done: +done: /* Note that 'l' and 'r' may cross, i.e. r < l */ DUK_ASSERT(l >= lo && l <= hi); DUK_ASSERT(r >= lo && r <= hi); @@ -26269,7 +27017,7 @@ DUK_ASSERT_TOP(thr, 3); duk_pop_nodecref_unsafe(thr); - return 1; /* return ToObject(this) */ + return 1; /* return ToObject(this) */ } /* @@ -26362,7 +27110,7 @@ for (i = 0; i < del_count; i++) { if (duk_get_prop_index(thr, -3, (duk_uarridx_t) (act_start + i))) { - duk_xdef_prop_index_wec(thr, -2, (duk_uarridx_t) i); /* throw flag irrelevant (false in std alg) */ + duk_xdef_prop_index_wec(thr, -2, (duk_uarridx_t) i); /* throw flag irrelevant (false in std alg) */ } else { duk_pop_undefined(thr); } @@ -26432,7 +27180,7 @@ /* Step 15: insert itemCount elements into the hole made above */ for (i = 0; i < item_count; i++) { - duk_dup(thr, i + 2); /* args start at index 2 */ + duk_dup(thr, i + 2); /* args start at index 2 */ duk_put_prop_index(thr, -4, (duk_uarridx_t) (act_start + i)); } @@ -26495,7 +27243,7 @@ } DUK_ASSERT_TOP(thr, 2); - duk_pop_unsafe(thr); /* -> ToObject(this) */ + duk_pop_unsafe(thr); /* -> ToObject(this) */ return 1; } @@ -26645,26 +27393,32 @@ if (duk_get_prop_index(thr, -2, (duk_uarridx_t) i)) { /* fromPresent = true */ /* ... ToObject(this) ToUint32(length) val */ - duk_put_prop_index(thr, -3, (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ + duk_put_prop_index( + thr, + -3, + (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ } else { /* fromPresent = false */ /* ... ToObject(this) ToUint32(length) val */ duk_pop_undefined(thr); - duk_del_prop_index(thr, -2, (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ + duk_del_prop_index( + thr, + -2, + (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ } DUK_ASSERT_TOP(thr, nargs + 2); } for (i = 0; i < (duk_uint32_t) nargs; i++) { DUK_ASSERT_TOP(thr, nargs + 2); - duk_dup(thr, (duk_idx_t) i); /* -> ... ToObject(this) ToUint32(length) argi */ + duk_dup(thr, (duk_idx_t) i); /* -> ... ToObject(this) ToUint32(length) argi */ duk_put_prop_index(thr, -3, (duk_uarridx_t) i); DUK_ASSERT_TOP(thr, nargs + 2); } DUK_ASSERT_TOP(thr, nargs + 2); duk_push_u32(thr, len + (duk_uint32_t) nargs); - duk_dup_top(thr); /* -> ... ToObject(this) ToUint32(length) final_len final_len */ + duk_dup_top(thr); /* -> ... ToObject(this) ToUint32(length) final_len final_len */ duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_LENGTH); return 1; } @@ -26677,7 +27431,7 @@ duk_idx_t nargs; duk_int_t i, len; duk_int_t from_idx; - duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for indexOf, -1 for lastIndexOf */ + duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for indexOf, -1 for lastIndexOf */ /* lastIndexOf() needs to be a vararg function because we must distinguish * between an undefined fromIndex and a "not given" fromIndex; indexOf() is @@ -26715,10 +27469,7 @@ * lastIndexOf: clamp fromIndex to -len - 1, len - 1 * (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly) */ - from_idx = duk_to_int_clamped(thr, - 1, - (idx_step > 0 ? -len : -len - 1), - (idx_step > 0 ? len : len - 1)); + from_idx = duk_to_int_clamped(thr, 1, (idx_step > 0 ? -len : -len - 1), (idx_step > 0 ? len : len - 1)); if (from_idx < 0) { /* for lastIndexOf, result may be -1 (mark immediate termination) */ from_idx = len + from_idx; @@ -26754,7 +27505,7 @@ duk_pop_unsafe(thr); } - not_found: +not_found: duk_push_int(thr, -1); return 1; } @@ -26763,11 +27514,11 @@ * every(), some(), forEach(), map(), filter() */ -#define DUK__ITER_EVERY 0 -#define DUK__ITER_SOME 1 -#define DUK__ITER_FOREACH 2 -#define DUK__ITER_MAP 3 -#define DUK__ITER_FILTER 4 +#define DUK__ITER_EVERY 0 +#define DUK__ITER_SOME 1 +#define DUK__ITER_FOREACH 2 +#define DUK__ITER_MAP 3 +#define DUK__ITER_FILTER 4 /* XXX: This helper is a bit awkward because the handling for the different iteration * callers is quite different. This now compiles to a bit less than 500 bytes, so with @@ -26802,7 +27553,7 @@ * stack4 = result array (or undefined) */ - k = 0; /* result index for filter() */ + k = 0; /* result index for filter() */ for (i = 0; i < len; i++) { DUK_ASSERT_TOP(thr, 5); @@ -26826,7 +27577,7 @@ duk_dup_1(thr); duk_dup_m3(thr); duk_push_u32(thr, i); - duk_dup_2(thr); /* ... val callback thisArg val i obj */ + duk_dup_2(thr); /* ... val callback thisArg val i obj */ duk_call_method(thr, 3); /* -> ... val retval */ switch (iter_type) { @@ -26849,13 +27600,13 @@ break; case DUK__ITER_MAP: duk_dup_top(thr); - duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) i); /* retval to resulti */ + duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) i); /* retval to resulti */ res_length = i + 1; break; case DUK__ITER_FILTER: bval = duk_to_boolean(thr, -1); if (bval) { - duk_dup_m2(thr); /* orig value */ + duk_dup_m2(thr); /* orig value */ duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) k); k++; res_length = k; @@ -26883,7 +27634,7 @@ case DUK__ITER_MAP: case DUK__ITER_FILTER: DUK_ASSERT_TOP(thr, 5); - DUK_ASSERT(duk_is_array(thr, -1)); /* topmost element is the result array already */ + DUK_ASSERT(duk_is_array(thr, -1)); /* topmost element is the result array already */ duk_push_u32(thr, res_length); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W); break; @@ -26903,7 +27654,7 @@ duk_idx_t nargs; duk_bool_t have_acc; duk_uint32_t i, len; - duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for reduce, -1 for reduceRight */ + duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for reduce, -1 for reduceRight */ /* We're a varargs function because we need to detect whether * initialValue was given or not. @@ -26927,8 +27678,7 @@ duk_dup_1(thr); have_acc = 1; } - DUK_DDD(DUK_DDDPRINT("have_acc=%ld, acc=%!T", - (long) have_acc, (duk_tval *) duk_get_tval(thr, 3))); + DUK_DDD(DUK_DDDPRINT("have_acc=%ld, acc=%!T", (long) have_acc, (duk_tval *) duk_get_tval(thr, 3))); /* For len == 0, i is initialized to len - 1 which underflows. * The condition (i < len) will then exit the for-loop on the @@ -26936,16 +27686,16 @@ * happens by i underflowing. */ - for (i = (idx_step >= 0 ? 0 : len - 1); - i < len; /* i >= 0 would always be true */ + for (i = (idx_step >= 0 ? 0 : len - 1); i < len; /* i >= 0 would always be true */ i += (duk_uint32_t) idx_step) { DUK_DDD(DUK_DDDPRINT("i=%ld, len=%ld, have_acc=%ld, top=%ld, acc=%!T", - (long) i, (long) len, (long) have_acc, + (long) i, + (long) len, + (long) have_acc, (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, 4))); - DUK_ASSERT((have_acc && duk_get_top(thr) == 5) || - (!have_acc && duk_get_top(thr) == 4)); + DUK_ASSERT((have_acc && duk_get_top(thr) == 5) || (!have_acc && duk_get_top(thr) == 4)); if (!duk_has_prop_index(thr, 2, (duk_uarridx_t) i)) { continue; @@ -26964,8 +27714,10 @@ duk_push_u32(thr, i); duk_dup_2(thr); DUK_DDD(DUK_DDDPRINT("calling reduce function: func=%!T, prev=%!T, curr=%!T, idx=%!T, obj=%!T", - (duk_tval *) duk_get_tval(thr, -5), (duk_tval *) duk_get_tval(thr, -4), - (duk_tval *) duk_get_tval(thr, -3), (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -5), + (duk_tval *) duk_get_tval(thr, -4), + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_call(thr, 4); DUK_DDD(DUK_DDDPRINT("-> result: %!T", (duk_tval *) duk_get_tval(thr, -1))); @@ -26982,7 +27734,7 @@ return 1; } -#endif /* DUK_USE_ARRAY_BUILTIN */ +#endif /* DUK_USE_ARRAY_BUILTIN */ /* automatic undefs */ #undef DUK__ARRAY_MID_JOIN_LIMIT @@ -27032,7 +27784,7 @@ DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* never here */ - type_ok: +type_ok: if (coerce_tostring) { duk_to_string(thr, -1); } @@ -27052,14 +27804,14 @@ DUK_HOBJECT_SET_CLASS_NUMBER(h_this, DUK_HOBJECT_CLASS_BOOLEAN); - duk_dup_0(thr); /* -> val obj val */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); /* XXX: proper flags? */ - } /* unbalanced stack */ + duk_dup_0(thr); /* -> val obj val */ + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); /* XXX: proper flags? */ + } /* unbalanced stack */ return 1; } -#endif /* DUK_USE_BOOLEAN_BUILTIN */ +#endif /* DUK_USE_BOOLEAN_BUILTIN */ /* * ES2015 TypedArray and Node.js Buffer built-ins */ @@ -27075,57 +27827,38 @@ * default internal prototype. */ static const duk_uint8_t duk__buffer_proto_from_classnum = { - DUK_BIDX_ARRAYBUFFER_PROTOTYPE, - DUK_BIDX_DATAVIEW_PROTOTYPE, - DUK_BIDX_INT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, - DUK_BIDX_INT16ARRAY_PROTOTYPE, - DUK_BIDX_UINT16ARRAY_PROTOTYPE, - DUK_BIDX_INT32ARRAY_PROTOTYPE, - DUK_BIDX_UINT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT64ARRAY_PROTOTYPE + DUK_BIDX_ARRAYBUFFER_PROTOTYPE, DUK_BIDX_DATAVIEW_PROTOTYPE, DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_BIDX_INT16ARRAY_PROTOTYPE, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE }; /* Map DUK_HBUFOBJ_ELEM_xxx to duk_hobject class number. * Sync with duk_hbufobj.h and duk_hobject.h. */ -static const duk_uint8_t duk__buffer_class_from_elemtype9 = { - DUK_HOBJECT_CLASS_UINT8ARRAY, - DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, - DUK_HOBJECT_CLASS_INT8ARRAY, - DUK_HOBJECT_CLASS_UINT16ARRAY, - DUK_HOBJECT_CLASS_INT16ARRAY, - DUK_HOBJECT_CLASS_UINT32ARRAY, - DUK_HOBJECT_CLASS_INT32ARRAY, - DUK_HOBJECT_CLASS_FLOAT32ARRAY, - DUK_HOBJECT_CLASS_FLOAT64ARRAY -}; +static const duk_uint8_t duk__buffer_class_from_elemtype9 = { DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, + DUK_HOBJECT_CLASS_INT8ARRAY, DUK_HOBJECT_CLASS_UINT16ARRAY, + DUK_HOBJECT_CLASS_INT16ARRAY, DUK_HOBJECT_CLASS_UINT32ARRAY, + DUK_HOBJECT_CLASS_INT32ARRAY, DUK_HOBJECT_CLASS_FLOAT32ARRAY, + DUK_HOBJECT_CLASS_FLOAT64ARRAY }; /* Map DUK_HBUFOBJ_ELEM_xxx to prototype object built-in index. * Sync with duk_hbufobj.h. */ static const duk_uint8_t duk__buffer_proto_from_elemtype9 = { - DUK_BIDX_UINT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, - DUK_BIDX_INT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT16ARRAY_PROTOTYPE, - DUK_BIDX_INT16ARRAY_PROTOTYPE, - DUK_BIDX_UINT32ARRAY_PROTOTYPE, - DUK_BIDX_INT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT64ARRAY_PROTOTYPE + DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_BIDX_INT16ARRAY_PROTOTYPE, DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE }; /* Map DUK__FLD_xxx to byte size. */ static const duk_uint8_t duk__buffer_nbytes_from_fldtype6 = { - 1, /* DUK__FLD_8BIT */ - 2, /* DUK__FLD_16BIT */ - 4, /* DUK__FLD_32BIT */ - 4, /* DUK__FLD_FLOAT */ - 8, /* DUK__FLD_DOUBLE */ - 0 /* DUK__FLD_VARINT; not relevant here */ + 1, /* DUK__FLD_8BIT */ + 2, /* DUK__FLD_16BIT */ + 4, /* DUK__FLD_32BIT */ + 4, /* DUK__FLD_FLOAT */ + 8, /* DUK__FLD_DOUBLE */ + 0 /* DUK__FLD_VARINT; not relevant here */ }; /* Bitfield for each DUK_HBUFOBJ_ELEM_xxx indicating which element types @@ -27137,36 +27870,27 @@ #if !defined(DUK_USE_PREFER_SIZE) static duk_uint16_t duk__buffer_elemtype_copy_compatible9 = { /* xxx -> DUK_HBUFOBJ_ELEM_UINT8 */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | - (1U << DUK_HBUFOBJ_ELEM_INT8), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | (1U << DUK_HBUFOBJ_ELEM_INT8), /* xxx -> DUK_HBUFOBJ_ELEM_UINT8CLAMPED * Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00. */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED), /* xxx -> DUK_HBUFOBJ_ELEM_INT8 */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | - (1U << DUK_HBUFOBJ_ELEM_INT8), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | (1U << DUK_HBUFOBJ_ELEM_INT8), /* xxx -> DUK_HBUFOBJ_ELEM_UINT16 */ - (1U << DUK_HBUFOBJ_ELEM_UINT16) | - (1U << DUK_HBUFOBJ_ELEM_INT16), + (1U << DUK_HBUFOBJ_ELEM_UINT16) | (1U << DUK_HBUFOBJ_ELEM_INT16), /* xxx -> DUK_HBUFOBJ_ELEM_INT16 */ - (1U << DUK_HBUFOBJ_ELEM_UINT16) | - (1U << DUK_HBUFOBJ_ELEM_INT16), + (1U << DUK_HBUFOBJ_ELEM_UINT16) | (1U << DUK_HBUFOBJ_ELEM_INT16), /* xxx -> DUK_HBUFOBJ_ELEM_UINT32 */ - (1U << DUK_HBUFOBJ_ELEM_UINT32) | - (1U << DUK_HBUFOBJ_ELEM_INT32), + (1U << DUK_HBUFOBJ_ELEM_UINT32) | (1U << DUK_HBUFOBJ_ELEM_INT32), /* xxx -> DUK_HBUFOBJ_ELEM_INT32 */ - (1U << DUK_HBUFOBJ_ELEM_UINT32) | - (1U << DUK_HBUFOBJ_ELEM_INT32), + (1U << DUK_HBUFOBJ_ELEM_UINT32) | (1U << DUK_HBUFOBJ_ELEM_INT32), /* xxx -> DUK_HBUFOBJ_ELEM_FLOAT32 */ (1U << DUK_HBUFOBJ_ELEM_FLOAT32), @@ -27174,7 +27898,7 @@ /* xxx -> DUK_HBUFOBJ_ELEM_FLOAT64 */ (1U << DUK_HBUFOBJ_ELEM_FLOAT64) }; -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_LOCAL duk_hbufobj *duk__hbufobj_promote_this(duk_hthread *thr) { duk_tval *tv_dst; @@ -27193,8 +27917,8 @@ return res; } -#define DUK__BUFOBJ_FLAG_THROW (1 << 0) -#define DUK__BUFOBJ_FLAG_PROMOTE (1 << 1) +#define DUK__BUFOBJ_FLAG_THROW (1 << 0) +#define DUK__BUFOBJ_FLAG_PROMOTE (1 << 1) /* Shared helper. When DUK__BUFOBJ_FLAG_PROMOTE is given, the return value is * always a duk_hbufobj *. Without the flag the return value can also be a @@ -27285,7 +28009,7 @@ DUK_LOCAL void duk__set_bufobj_buffer(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_hbuffer *h_val) { DUK_ASSERT(thr != NULL); DUK_ASSERT(h_bufobj != NULL); - DUK_ASSERT(h_bufobj->buf == NULL); /* no need to decref */ + DUK_ASSERT(h_bufobj->buf == NULL); /* no need to decref */ DUK_ASSERT(h_val != NULL); DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); DUK_UNREF(thr); @@ -27321,12 +28045,12 @@ if (offset > h_bufarg->length) { goto fail_range; } - DUK_ASSERT_DISABLE(offset >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(offset >= 0); /* unsigned */ DUK_ASSERT(offset <= h_bufarg->length); if (duk_is_undefined(thr, idx_length)) { DUK_ASSERT(h_bufarg->length >= offset); - length = h_bufarg->length - offset; /* >= 0 */ + length = h_bufarg->length - offset; /* >= 0 */ } else { length_signed = duk_to_int(thr, idx_length); if (length_signed < 0) { @@ -27345,14 +28069,14 @@ } } } - DUK_ASSERT_DISABLE(length >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(length >= 0); /* unsigned */ DUK_ASSERT(offset + length <= h_bufarg->length); *out_offset = offset; *out_length = length; return; - fail_range: +fail_range: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); } @@ -27410,7 +28134,7 @@ DUK_ASSERT(out_start_offset != NULL); DUK_ASSERT(out_end_offset != NULL); - buffer_length >>= buffer_shift; /* as (full) elements */ + buffer_length >>= buffer_shift; /* as (full) elements */ /* Resolve start/end offset as element indices first; arguments * at idx_start/idx_end are element offsets. Working with element @@ -27502,7 +28226,10 @@ } /* Indexed read helper for buffer objects, also called from outside this file. */ -DUK_INTERNAL void duk_hbufobj_push_validated_read(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size) { +DUK_INTERNAL void duk_hbufobj_push_validated_read(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size) { duk_double_union du; DUK_ASSERT(elem_size > 0); @@ -27650,17 +28377,17 @@ DUK_WO_NORETURN(return NULL;); } - done: +done: DUK_ASSERT(duk_is_buffer(thr, -1)); return duk_known_hbuffer(thr, -1); - slow_copy: +slow_copy: /* XXX: fast path for typed arrays and other buffer objects? */ (void) duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_LENGTH); len = duk_to_int_clamped(thr, -1, 0, DUK_INT_MAX); duk_pop(thr); - buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) len); /* no zeroing, all indices get initialized */ + buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) len); /* no zeroing, all indices get initialized */ for (i = 0; i < len; i++) { /* XXX: fast path for array or buffer arguments? */ duk_get_prop_index(thr, 0, (duk_uarridx_t) i); @@ -27669,7 +28396,7 @@ } goto done; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer constructor @@ -27686,11 +28413,7 @@ h_buf = duk__hbufobj_fixed_from_argvalue(thr); DUK_ASSERT(h_buf != NULL); - duk_push_buffer_object(thr, - -1, - 0, - DUK_HBUFFER_FIXED_GET_SIZE((duk_hbuffer_fixed *) (void *) h_buf), - DUK_BUFOBJ_UINT8ARRAY); + duk_push_buffer_object(thr, -1, 0, DUK_HBUFFER_FIXED_GET_SIZE((duk_hbuffer_fixed *) (void *) h_buf), DUK_BUFOBJ_UINT8ARRAY); duk_push_hobject_bidx(thr, DUK_BIDX_NODEJS_BUFFER_PROTOTYPE); duk_set_prototype(thr, -2); @@ -27698,7 +28421,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * ArrayBuffer, DataView, and TypedArray constructors @@ -27722,9 +28445,8 @@ h_val = (duk_hbuffer *) duk_known_hbuffer(thr, -1); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), DUK_BIDX_ARRAYBUFFER_PROTOTYPE); DUK_ASSERT(h_bufobj != NULL); @@ -27733,11 +28455,10 @@ return 1; - fail_length: +fail_length: DUK_DCERROR_RANGE_INVALID_LENGTH(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ - +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Format of magic, bits: * 0...1: elem size shift (0-3) @@ -27777,8 +28498,8 @@ * element type. */ magic = (duk_small_uint_t) duk_get_current_magic(thr); - shift = magic & 0x03U; /* bits 0...1: shift */ - elem_type = (magic >> 2) & 0x0fU; /* bits 2...5: type */ + shift = magic & 0x03U; /* bits 0...1: shift */ + elem_type = (magic >> 2) & 0x0fU; /* bits 2...5: type */ elem_size = 1U << shift; align_mask = elem_size - 1; DUK_ASSERT(elem_type < sizeof(duk__buffer_proto_from_elemtype) / sizeof(duk_uint8_t)); @@ -27789,8 +28510,12 @@ DUK_DD(DUK_DDPRINT("typedarray constructor, magic=%d, shift=%d, elem_type=%d, " "elem_size=%d, proto_bidx=%d, class_num=%d", - (int) magic, (int) shift, (int) elem_type, (int) elem_size, - (int) proto_bidx, (int) class_num)); + (int) magic, + (int) shift, + (int) elem_type, + (int) elem_size, + (int) proto_bidx, + (int) class_num)); /* Argument variants. When the argument is an ArrayBuffer a view to * the same buffer is created; otherwise a new ArrayBuffer is always @@ -27804,7 +28529,7 @@ duk_hbufobj_promote_plain(thr, 0); tv = duk_get_tval(thr, 0); - DUK_ASSERT(tv != NULL); /* arg count */ + DUK_ASSERT(tv != NULL); /* arg count */ if (DUK_TVAL_IS_OBJECT(tv)) { h_obj = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h_obj != NULL); @@ -27824,8 +28549,7 @@ goto fail_arguments; } byte_offset = (duk_uint_t) byte_offset_signed; - if (byte_offset > h_bufarg->length || - (byte_offset & align_mask) != 0) { + if (byte_offset > h_bufarg->length || (byte_offset & align_mask) != 0) { /* Must be >= 0 and multiple of element size. */ goto fail_arguments; } @@ -27865,9 +28589,8 @@ DUK_ASSERT((elem_length << shift) == byte_length); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(class_num), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(class_num), (duk_small_int_t) proto_bidx); h_val = h_bufarg->buf; if (h_val == NULL) { @@ -27910,11 +28633,13 @@ "src byte_length=%ld, src shift=%d, " "src/dst elem_length=%ld; " "dst shift=%d -> dst byte_length=%ld", - (long) h_bufarg->length, (int) h_bufarg->shift, - (long) elem_length_signed, (int) shift, + (long) h_bufarg->length, + (int) h_bufarg->shift, + (long) elem_length_signed, + (int) shift, (long) (elem_length_signed << shift))); - copy_mode = 2; /* default is explicit index read/write copy */ + copy_mode = 2; /* default is explicit index read/write copy */ #if !defined(DUK_USE_PREFER_SIZE) /* With a size optimized build copy_mode 2 is enough. * Modes 0 and 1 are faster but conceptually the same. @@ -27923,14 +28648,14 @@ if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { if ((duk__buffer_elemtype_copy_compatibleelem_type & (1 << h_bufarg->elem_type)) != 0) { DUK_DDD(DUK_DDDPRINT("source/target are copy compatible, memcpy")); - DUK_ASSERT(shift == h_bufarg->shift); /* byte sizes will match */ + DUK_ASSERT(shift == h_bufarg->shift); /* byte sizes will match */ copy_mode = 0; } else { DUK_DDD(DUK_DDDPRINT("source/target not copy compatible but valid, fast copy")); copy_mode = 1; } } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ } else { /* Array or Array-like */ elem_length_signed = (duk_int_t) duk_get_length(thr, 0); @@ -27955,8 +28680,7 @@ goto fail_arguments; } - DUK_DDD(DUK_DDDPRINT("elem_length=%ld, byte_length=%ld", - (long) elem_length, (long) byte_length)); + DUK_DDD(DUK_DDDPRINT("elem_length=%ld, byte_length=%ld", (long) elem_length, (long) byte_length)); /* ArrayBuffer argument is handled specially above; the rest of the * argument variants are handled by shared code below. @@ -27971,11 +28695,10 @@ h_val = duk_known_hbuffer(thr, -1); DUK_ASSERT(h_val != NULL); - h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(class_num), - (duk_small_int_t) proto_bidx); + h_bufobj = + duk_push_bufobj_raw(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(class_num), + (duk_small_int_t) proto_bidx); h_bufobj->buf = h_val; DUK_HBUFFER_INCREF(thr, h_val); @@ -28015,7 +28738,9 @@ p_src = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufarg); DUK_DDD(DUK_DDDPRINT("using memcpy: p_src=%p, p_dst=%p, byte_length=%ld", - (void *) p_src, (void *) p_dst, (long) byte_length)); + (void *) p_src, + (void *) p_dst, + (long) byte_length)); duk_memcpy_unsafe((void *) p_dst, (const void *) p_src, (size_t) byte_length); break; @@ -28045,13 +28770,18 @@ DUK_DDD(DUK_DDDPRINT("using fast copy: p_src=%p, p_src_end=%p, p_dst=%p, " "src_elem_size=%d, dst_elem_size=%d", - (void *) p_src, (void *) p_src_end, (void *) p_dst, - (int) src_elem_size, (int) dst_elem_size)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst, + (int) src_elem_size, + (int) dst_elem_size)); while (p_src != p_src_end) { DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: " "p_src=%p, p_src_end=%p, p_dst=%p", - (void *) p_src, (void *) p_src_end, (void *) p_dst)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst)); /* A validated read() is always a number, so it's write coercion * is always side effect free an won't invalidate pointers etc. */ @@ -28063,7 +28793,7 @@ } break; } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ case 2: { /* Copy values by index reads and writes. Let virtual * property handling take care of coercion. @@ -28092,10 +28822,10 @@ return 1; - fail_arguments: +fail_arguments: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* When bufferobject support is disabled, new Uint8Array() could still be * supported to create a plain fixed buffer. Disabled for now. */ @@ -28122,8 +28852,8 @@ fail_arguments: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* 0 */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* 0 */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_dataview_constructor(duk_hthread *thr) { @@ -28146,9 +28876,8 @@ DUK_ASSERT(offset + length <= h_bufarg->length); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATAVIEW), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATAVIEW), DUK_BIDX_DATAVIEW_PROTOTYPE); h_val = h_bufarg->buf; @@ -28171,7 +28900,7 @@ DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * ArrayBuffer.isView() @@ -28197,7 +28926,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Uint8Array.allocPlain() @@ -28208,7 +28937,7 @@ duk__hbufobj_fixed_from_argvalue(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Uint8Array.plainOf() @@ -28237,7 +28966,7 @@ } return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer: toString(encoding, start, end) @@ -28268,12 +28997,11 @@ &end_offset); slice_length = (duk_size_t) (end_offset - start_offset); - buf_slice = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, slice_length); /* all bytes initialized below */ + buf_slice = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, slice_length); /* all bytes initialized below */ DUK_ASSERT(buf_slice != NULL); /* Neutered or uncovered, TypeError. */ - if (h_this->buf == NULL || - !DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, (duk_size_t) start_offset + slice_length)) { + if (h_this->buf == NULL || !DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, (duk_size_t) start_offset + slice_length)) { DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -28296,7 +29024,7 @@ duk_set_top(thr, 1); return duk_textdecoder_decode_utf8_nodejs(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype: toJSON() @@ -28326,19 +29054,19 @@ /* XXX: uninitialized would be OK */ DUK_ASSERT_DISABLE((duk_size_t) h_this->length <= (duk_size_t) DUK_UINT32_MAX); - tv = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) h_this->length); /* XXX: needs revision with >4G buffers */ + tv = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) h_this->length); /* XXX: needs revision with >4G buffers */ DUK_ASSERT(!duk_is_bare_object(thr, -1)); DUK_ASSERT(h_this->buf != NULL); buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); for (i = 0, n = h_this->length; i < n; i++) { - DUK_TVAL_SET_U32(tv + i, (duk_uint32_t) bufi); /* no need for decref or incref */ + DUK_TVAL_SET_U32(tv + i, (duk_uint32_t) bufi); /* no need for decref or incref */ } duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_DATA); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.equals() @@ -28373,14 +29101,14 @@ * matters is to be memory safe. */ - if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg1) && - DUK_HBUFOBJ_VALID_SLICE(h_bufarg2)) { - comp_res = duk_js_data_compare((const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg1->buf) + h_bufarg1->offset, - (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg2->buf) + h_bufarg2->offset, - (duk_size_t) h_bufarg1->length, - (duk_size_t) h_bufarg2->length); + if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg1) && DUK_HBUFOBJ_VALID_SLICE(h_bufarg2)) { + comp_res = duk_js_data_compare( + (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg1->buf) + h_bufarg1->offset, + (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg2->buf) + h_bufarg2->offset, + (duk_size_t) h_bufarg1->length, + (duk_size_t) h_bufarg2->length); } else { - comp_res = -1; /* either nonzero value is ok */ + comp_res = -1; /* either nonzero value is ok */ } if (magic & 0x01U) { @@ -28393,7 +29121,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.fill() @@ -28438,7 +29166,10 @@ &fill_end); DUK_DDD(DUK_DDDPRINT("fill: fill_value=%02x, fill_offset=%ld, fill_end=%ld, view length=%ld", - (unsigned int) fill_value, (long) fill_offset, (long) fill_end, (long) h_this->length)); + (unsigned int) fill_value, + (long) fill_offset, + (long) fill_end, + (long) h_this->length)); DUK_ASSERT(fill_end - fill_offset >= 0); DUK_ASSERT(h_this->buf != NULL); @@ -28467,7 +29198,7 @@ duk_push_this(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.write(string, offset, length, encoding) @@ -28510,7 +29241,7 @@ duk_push_uint(thr, length); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.copy() @@ -28545,8 +29276,11 @@ DUK_DDD(DUK_DDDPRINT("checking copy args: target_start=%ld, target_length=%ld, " "source_start=%ld, source_end=%ld, source_length=%ld", - (long) target_start, (long) h_bufarg->length, - (long) source_start, (long) source_end, (long) source_length)); + (long) target_start, + (long) h_bufarg->length, + (long) source_start, + (long) source_end, + (long) source_length)); /* This behavior mostly mimics Node.js now. */ @@ -28557,9 +29291,9 @@ source_ustart = (duk_uint_t) source_start; source_uend = (duk_uint_t) source_end; target_ustart = (duk_uint_t) target_start; - if (source_ustart >= source_uend || /* crossed offsets or zero size */ - source_ustart >= (duk_uint_t) source_length || /* source out-of-bounds (but positive) */ - target_ustart >= (duk_uint_t) target_length) { /* target out-of-bounds (but positive) */ + if (source_ustart >= source_uend || /* crossed offsets or zero size */ + source_ustart >= (duk_uint_t) source_length || /* source out-of-bounds (but positive) */ + target_ustart >= (duk_uint_t) target_length) { /* target out-of-bounds (but positive) */ goto silent_ignore; } if (source_uend >= (duk_uint_t) source_length) { @@ -28575,13 +29309,14 @@ * values in duk_int_t range. Adding them as duk_uint_t * values is then guaranteed not to overflow. */ - DUK_ASSERT(target_ustart + copy_size >= target_ustart); /* no overflow */ - DUK_ASSERT(target_ustart + copy_size >= copy_size); /* no overflow */ + DUK_ASSERT(target_ustart + copy_size >= target_ustart); /* no overflow */ + DUK_ASSERT(target_ustart + copy_size >= copy_size); /* no overflow */ copy_size = (duk_uint_t) target_length - target_ustart; } DUK_DDD(DUK_DDDPRINT("making copy: target_ustart=%lu source_ustart=%lu copy_size=%lu", - (unsigned long) target_ustart, (unsigned long) source_ustart, + (unsigned long) target_ustart, + (unsigned long) source_ustart, (unsigned long) copy_size)); DUK_ASSERT(copy_size >= 1); @@ -28591,8 +29326,8 @@ DUK_ASSERT(target_ustart + copy_size <= (duk_uint_t) target_length); /* Ensure copy is covered by underlying buffers. */ - DUK_ASSERT(h_bufarg->buf != NULL); /* length check */ - DUK_ASSERT(h_this->buf != NULL); /* length check */ + DUK_ASSERT(h_bufarg->buf != NULL); /* length check */ + DUK_ASSERT(h_this->buf != NULL); /* length check */ if (DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufarg, target_ustart + copy_size) && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, source_ustart + copy_size)) { /* Must use memmove() because copy area may overlap (source and target @@ -28605,18 +29340,18 @@ DUK_DDD(DUK_DDDPRINT("buffer copy not covered by underlying buffer(s), ignoring")); } - silent_ignore: +silent_ignore: /* Return value is like write(), number of bytes written. * The return value matters because of code like: * "off += buf.copy(...)". - */ + */ duk_push_uint(thr, copy_size); return 1; - fail_bounds: +fail_bounds: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * TypedArray.prototype.set() @@ -28728,16 +29463,15 @@ } /* Nominal size check. */ - src_length = h_bufarg->length; /* bytes in source */ - dst_length_elems = (src_length >> h_bufarg->shift); /* elems in source and dest */ - dst_length = dst_length_elems << h_this->shift; /* bytes in dest */ + src_length = h_bufarg->length; /* bytes in source */ + dst_length_elems = (src_length >> h_bufarg->shift); /* elems in source and dest */ + dst_length = dst_length_elems << h_this->shift; /* bytes in dest */ if ((dst_length >> h_this->shift) != dst_length_elems) { /* Byte length would overflow. */ /* XXX: easier check with less code? */ goto fail_args; } - DUK_DDD(DUK_DDDPRINT("nominal size check: src_length=%ld, dst_length=%ld", - (long) src_length, (long) dst_length)); + DUK_DDD(DUK_DDDPRINT("nominal size check: src_length=%ld, dst_length=%ld", (long) src_length, (long) dst_length)); DUK_ASSERT(offset_bytes <= h_this->length); if (dst_length > h_this->length - offset_bytes) { /* Overflow not an issue because subtraction is used on the right @@ -28758,8 +29492,7 @@ * cover the copy. No side effects are allowed after the check * so that the validity status doesn't change. */ - if (!DUK_HBUFOBJ_VALID_SLICE(h_this) || - !DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { + if (!DUK_HBUFOBJ_VALID_SLICE(h_this) || !DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { /* The condition could be more narrow and check for the * copy area only, but there's no need for fine grained * behavior when the underlying buffer is misconfigured. @@ -28790,7 +29523,7 @@ return 0; } DUK_DDD(DUK_DDDPRINT("fast path: views are not compatible with a byte copy, copy by item")); -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ /* We want to avoid making a copy to process set() but that's * not always possible: the source and the target may overlap @@ -28810,11 +29543,13 @@ DUK_DDD(DUK_DDDPRINT("overlap check: p_src_base=%p, src_length=%ld, " "p_dst_base=%p, dst_length=%ld", - (void *) p_src_base, (long) src_length, - (void *) p_dst_base, (long) dst_length)); + (void *) p_src_base, + (long) src_length, + (void *) p_dst_base, + (long) dst_length)); - if (p_src_base >= p_dst_base + dst_length || /* source starts after dest ends */ - p_src_base + src_length <= p_dst_base) { /* source ends before dest starts */ + if (p_src_base >= p_dst_base + dst_length || /* source starts after dest ends */ + p_src_base + src_length <= p_dst_base) { /* source ends before dest starts */ no_overlap = 1; } @@ -28831,14 +29566,16 @@ DUK_ASSERT(p_src_copy != NULL); duk_memcpy_unsafe((void *) p_src_copy, (const void *) p_src_base, (size_t) src_length); - p_src_base = p_src_copy; /* use p_src_base from now on */ + p_src_base = p_src_copy; /* use p_src_base from now on */ } /* Value stack intentionally mixed size here. */ DUK_DDD(DUK_DDDPRINT("after overlap check: p_src_base=%p, src_length=%ld, " "p_dst_base=%p, dst_length=%ld, valstack top=%ld", - (void *) p_src_base, (long) src_length, - (void *) p_dst_base, (long) dst_length, + (void *) p_src_base, + (long) src_length, + (void *) p_dst_base, + (long) dst_length, (long) duk_get_top(thr))); /* Ready to make the copy. We must proceed element by element @@ -28858,7 +29595,9 @@ while (p_src != p_src_end) { DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: " "p_src=%p, p_src_end=%p, p_dst=%p", - (void *) p_src, (void *) p_src_end, (void *) p_dst)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst)); /* A validated read() is always a number, so it's write coercion * is always side effect free an won't invalidate pointers etc. */ @@ -28908,10 +29647,10 @@ return 0; - fail_args: +fail_args: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.slice(start, end) @@ -29006,7 +29745,7 @@ /* fall through */ } } - tv = NULL; /* No longer valid nor needed. */ + tv = NULL; /* No longer valid nor needed. */ h_this = duk__require_bufobj_this(thr); @@ -29044,22 +29783,21 @@ * be an Uint8Array but inherit from Buffer.prototype. */ res_class_num = DUK_HOBJECT_GET_CLASS_NUMBER((duk_hobject *) h_this); - DUK_ASSERT(res_class_num >= DUK_HOBJECT_CLASS_BUFOBJ_MIN); /* type check guarantees */ + DUK_ASSERT(res_class_num >= DUK_HOBJECT_CLASS_BUFOBJ_MIN); /* type check guarantees */ DUK_ASSERT(res_class_num <= DUK_HOBJECT_CLASS_BUFOBJ_MAX); res_proto_bidx = duk__buffer_proto_from_classnumres_class_num - DUK_HOBJECT_CLASS_BUFOBJ_MIN; if (magic & 0x04) { res_proto_bidx = DUK_BIDX_NODEJS_BUFFER_PROTOTYPE; } - h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(res_class_num), - res_proto_bidx); + h_bufobj = + duk_push_bufobj_raw(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(res_class_num), + res_proto_bidx); DUK_ASSERT(h_bufobj != NULL); DUK_ASSERT(h_bufobj->length == 0); - h_bufobj->shift = h_this->shift; /* inherit */ - h_bufobj->elem_type = h_this->elem_type; /* inherit */ + h_bufobj->shift = h_this->shift; /* inherit */ + h_bufobj->elem_type = h_this->elem_type; /* inherit */ h_bufobj->is_typedarray = magic & 0x01; DUK_ASSERT(h_bufobj->is_typedarray == 0 || h_bufobj->is_typedarray == 1); @@ -29073,7 +29811,9 @@ duk_uint8_t *p_copy; duk_size_t copy_length; - p_copy = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, (duk_size_t) slice_length); /* must be zeroed, not all bytes always copied */ + p_copy = (duk_uint8_t *) duk_push_fixed_buffer_zero( + thr, + (duk_size_t) slice_length); /* must be zeroed, not all bytes always copied */ DUK_ASSERT(p_copy != NULL); /* Copy slice, respecting underlying buffer limits; remainder @@ -29091,7 +29831,7 @@ h_bufobj->length = slice_length; DUK_ASSERT(h_bufobj->offset == 0); - duk_pop(thr); /* reachable so pop OK */ + duk_pop(thr); /* reachable so pop OK */ } else { h_bufobj->buf = h_val; DUK_HBUFFER_INCREF(thr, h_val); @@ -29104,7 +29844,7 @@ */ DUK_ASSERT(h_bufobj->buf_prop == NULL); - h_bufobj->buf_prop = h_this->buf_prop; /* may be NULL */ + h_bufobj->buf_prop = h_this->buf_prop; /* may be NULL */ DUK_HOBJECT_INCREF_ALLOWNULL(thr, (duk_hobject *) h_bufobj->buf_prop); } /* unbalanced stack on purpose */ @@ -29112,7 +29852,7 @@ DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.isEncoding() @@ -29125,11 +29865,11 @@ /* only accept lowercase 'utf8' now. */ encoding = duk_to_string(thr, 0); - DUK_ASSERT(duk_is_string(thr, 0)); /* guaranteed by duk_to_string() */ + DUK_ASSERT(duk_is_string(thr, 0)); /* guaranteed by duk_to_string() */ duk_push_boolean(thr, DUK_STRCMP(encoding, "utf8") == 0); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.isBuffer() @@ -29141,7 +29881,7 @@ duk_hobject *h_proto; duk_bool_t ret = 0; - DUK_ASSERT(duk_get_top(thr) >= 1); /* nargs */ + DUK_ASSERT(duk_get_top(thr) >= 1); /* nargs */ h = duk_get_hobject(thr, 0); if (h != NULL) { h_proto = thr->builtinsDUK_BIDX_NODEJS_BUFFER_PROTOTYPE; @@ -29156,7 +29896,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.byteLength() @@ -29187,7 +29927,7 @@ duk_push_size_t(thr, len); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.concat() @@ -29218,13 +29958,13 @@ /* Neutered checks not necessary here: neutered buffers have * zero 'length' so we'll effectively skip them. */ - DUK_ASSERT_TOP(thr, 2); /* array totalLength */ - duk_get_prop_index(thr, 0, (duk_uarridx_t) i); /* -> array totalLength buf */ + DUK_ASSERT_TOP(thr, 2); /* array totalLength */ + duk_get_prop_index(thr, 0, (duk_uarridx_t) i); /* -> array totalLength buf */ h_bufobj = duk__require_bufobj_value(thr, 2); DUK_ASSERT(h_bufobj != NULL); total_length += h_bufobj->length; if (DUK_UNLIKELY(total_length < h_bufobj->length)) { - DUK_DCERROR_RANGE_INVALID_ARGS(thr); /* Wrapped. */ + DUK_DCERROR_RANGE_INVALID_ARGS(thr); /* Wrapped. */ } duk_pop(thr); } @@ -29250,18 +29990,18 @@ } h_bufres = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_UINT8ARRAY), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_UINT8ARRAY), DUK_BIDX_NODEJS_BUFFER_PROTOTYPE); DUK_ASSERT(h_bufres != NULL); - p = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, total_length); /* must be zeroed, all bytes not necessarily written over */ + p = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, + total_length); /* must be zeroed, all bytes not necessarily written over */ DUK_ASSERT(p != NULL); space_left = (duk_size_t) total_length; for (i = 0; i < n; i++) { - DUK_ASSERT_TOP(thr, 4); /* array totalLength bufres buf */ + DUK_ASSERT_TOP(thr, 4); /* array totalLength bufres buf */ duk_get_prop_index(thr, 0, (duk_uarridx_t) i); h_bufobj = duk__require_bufobj_value(thr, 4); @@ -29272,11 +30012,8 @@ copy_size = space_left; } - if (h_bufobj->buf != NULL && - DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { - duk_memcpy_unsafe((void *) p, - (const void *) DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj), - copy_size); + if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { + duk_memcpy_unsafe((void *) p, (const void *) DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj), copy_size); } else { /* Just skip, leaving zeroes in the result. */ ; @@ -29293,11 +30030,11 @@ h_bufres->is_typedarray = 1; DUK_HBUFOBJ_ASSERT_VALID(h_bufres); - duk_pop(thr); /* pop plain buffer, now reachable through h_bufres */ + duk_pop(thr); /* pop plain buffer, now reachable through h_bufres */ - return 1; /* return h_bufres */ + return 1; /* return h_bufres */ } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Shared readfield and writefield methods @@ -29313,15 +30050,15 @@ * 4: signed: 1=yes, 0=no * 5: typedarray: 1=yes, 0=no */ -#define DUK__FLD_8BIT 0 -#define DUK__FLD_16BIT 1 -#define DUK__FLD_32BIT 2 -#define DUK__FLD_FLOAT 3 -#define DUK__FLD_DOUBLE 4 -#define DUK__FLD_VARINT 5 -#define DUK__FLD_BIGENDIAN (1 << 3) -#define DUK__FLD_SIGNED (1 << 4) -#define DUK__FLD_TYPEDARRAY (1 << 5) +#define DUK__FLD_8BIT 0 +#define DUK__FLD_16BIT 1 +#define DUK__FLD_32BIT 2 +#define DUK__FLD_FLOAT 3 +#define DUK__FLD_DOUBLE 4 +#define DUK__FLD_VARINT 5 +#define DUK__FLD_BIGENDIAN (1 << 3) +#define DUK__FLD_SIGNED (1 << 4) +#define DUK__FLD_TYPEDARRAY (1 << 5) /* XXX: split into separate functions for each field type? */ DUK_INTERNAL duk_ret_t duk_bi_buffer_readfield(duk_hthread *thr) { @@ -29345,7 +30082,7 @@ magic_signed = magic & 0x0010U; magic_typedarray = magic & 0x0020U; - h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ + h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ DUK_ASSERT(h_this != NULL); buffer_length = h_this->length; @@ -29357,9 +30094,9 @@ if (magic_typedarray) { no_assert = 0; #if defined(DUK_USE_INTEGER_LE) - endswap = !duk_to_boolean(thr, 1); /* 1=little endian */ + endswap = !duk_to_boolean(thr, 1); /* 1=little endian */ #else - endswap = duk_to_boolean(thr, 1); /* 1=little endian */ + endswap = duk_to_boolean(thr, 1); /* 1=little endian */ #endif } else { no_assert = duk_to_boolean(thr, (magic_ftype == DUK__FLD_VARINT) ? 2 : 1); @@ -29383,17 +30120,21 @@ DUK_DDD(DUK_DDDPRINT("readfield, buffer_length=%ld, offset=%ld, no_assert=%d, " "magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, " "endswap=%u", - (long) buffer_length, (long) offset, (int) no_assert, - (unsigned int) magic, (int) magic_ftype, (int) (magic_bigendian >> 3), - (int) (magic_signed >> 4), (int) endswap)); + (long) buffer_length, + (long) offset, + (int) no_assert, + (unsigned int) magic, + (int) magic_ftype, + (int) (magic_bigendian >> 3), + (int) (magic_signed >> 4), + (int) endswap)); /* Update 'buffer_length' to be the effective, safe limit which * takes into account the underlying buffer. This value will be * potentially invalidated by any side effect. */ check_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, buffer_length); - DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", - (long) buffer_length, (long) check_length)); + DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", (long) buffer_length, (long) check_length)); if (h_this->buf) { buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); @@ -29495,7 +30236,7 @@ #endif const duk_uint8_t *p; - field_bytelen = duk_get_int(thr, 1); /* avoid side effects! */ + field_bytelen = duk_get_int(thr, 1); /* avoid side effects! */ if (field_bytelen < 1 || field_bytelen > 6) { goto fail_field_length; } @@ -29513,12 +30254,12 @@ /* Gather in big endian */ i = 0; i_step = 1; - i_end = field_bytelen; /* one i_step over */ + i_end = field_bytelen; /* one i_step over */ } else { /* Gather in little endian */ i = field_bytelen - 1; i_step = -1; - i_end = -1; /* one i_step over */ + i_end = -1; /* one i_step over */ } #if defined(DUK_USE_64BIT_OPS) @@ -29560,16 +30301,16 @@ #endif break; } - default: { /* should never happen but default here */ + default: { /* should never happen but default here */ goto fail_bounds; } } return 1; - fail_neutered: - fail_field_length: - fail_bounds: +fail_neutered: +fail_field_length: +fail_bounds: if (no_assert) { /* Node.js return value for noAssert out-of-bounds reads is * usually (but not always) NaN. Return NaN consistently. @@ -29579,7 +30320,7 @@ } DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) /* XXX: split into separate functions for each field type? */ @@ -29606,7 +30347,7 @@ magic_typedarray = magic & 0x0020U; DUK_UNREF(magic_signed); - h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ + h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ DUK_ASSERT(h_this != NULL); buffer_length = h_this->length; @@ -29618,11 +30359,11 @@ if (magic_typedarray) { no_assert = 0; #if defined(DUK_USE_INTEGER_LE) - endswap = !duk_to_boolean(thr, 2); /* 1=little endian */ + endswap = !duk_to_boolean(thr, 2); /* 1=little endian */ #else - endswap = duk_to_boolean(thr, 2); /* 1=little endian */ + endswap = duk_to_boolean(thr, 2); /* 1=little endian */ #endif - duk_swap(thr, 0, 1); /* offset/value order different from Node.js */ + duk_swap(thr, 0, 1); /* offset/value order different from Node.js */ } else { no_assert = duk_to_boolean(thr, (magic_ftype == DUK__FLD_VARINT) ? 3 : 2); #if defined(DUK_USE_INTEGER_LE) @@ -29661,9 +30402,15 @@ DUK_DDD(DUK_DDDPRINT("writefield, value=%!T, buffer_length=%ld, offset=%ld, no_assert=%d, " "magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, " "endswap=%u", - duk_get_tval(thr, 0), (long) buffer_length, (long) offset, (int) no_assert, - (unsigned int) magic, (int) magic_ftype, (int) (magic_bigendian >> 3), - (int) (magic_signed >> 4), (int) endswap)); + duk_get_tval(thr, 0), + (long) buffer_length, + (long) offset, + (int) no_assert, + (unsigned int) magic, + (int) magic_ftype, + (int) (magic_bigendian >> 3), + (int) (magic_signed >> 4), + (int) endswap)); /* Coerce value to a number before computing check_length, so that * the field type specific coercion below can't have side effects @@ -29676,8 +30423,7 @@ * potentially invalidated by any side effect. */ check_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, buffer_length); - DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", - (long) buffer_length, (long) check_length)); + DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", (long) buffer_length, (long) check_length)); if (h_this->buf) { buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); @@ -29780,12 +30526,12 @@ if (magic_bigendian) { /* Write in big endian */ - i = field_bytelen; /* one i_step added at top of loop */ + i = field_bytelen; /* one i_step added at top of loop */ i_step = -1; i_end = 0; } else { /* Write in little endian */ - i = -1; /* one i_step added at top of loop */ + i = -1; /* one i_step added at top of loop */ i_step = 1; i_end = field_bytelen - 1; } @@ -29803,7 +30549,7 @@ i += i_step; DUK_ASSERT(i >= 0 && i < field_bytelen); pi = (duk_uint8_t) (tmp & 0xff); - tmp = tmp >> 8; /* unnecessary shift for last byte */ + tmp = tmp >> 8; /* unnecessary shift for last byte */ } while (i != i_end); #else tmp = duk_to_number(thr, 0); @@ -29813,12 +30559,12 @@ tmp = DUK_FLOOR(tmp); DUK_ASSERT(i >= 0 && i < field_bytelen); pi = (duk_uint8_t) (DUK_FMOD(tmp, 256.0)); - tmp = tmp / 256.0; /* unnecessary div for last byte */ + tmp = tmp / 256.0; /* unnecessary div for last byte */ } while (i != i_end); #endif break; } - default: { /* should never happen but default here */ + default: { /* should never happen but default here */ goto fail_bounds; } } @@ -29835,9 +30581,9 @@ duk_push_uint(thr, offset + (duk_uint_t) nbytes); return 1; - fail_neutered: - fail_field_length: - fail_bounds: +fail_neutered: +fail_field_length: +fail_bounds: if (no_assert) { /* Node.js return value for failed writes is offset + #bytes * that would have been written. @@ -29853,7 +30599,7 @@ } DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Accessors for .buffer, .byteLength, .byteOffset @@ -29864,9 +30610,8 @@ duk_hbufobj *h_res; h_res = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), DUK_BIDX_ARRAYBUFFER_PROTOTYPE); DUK_ASSERT(h_res != NULL); DUK_UNREF(h_res); @@ -29906,13 +30651,13 @@ * matches view0. */ h_arrbuf->offset = 0; - DUK_ASSERT(h_bufobj->offset + h_bufobj->length >= h_bufobj->offset); /* Wrap check on creation. */ + DUK_ASSERT(h_bufobj->offset + h_bufobj->length >= h_bufobj->offset); /* Wrap check on creation. */ h_arrbuf->length = h_bufobj->offset + h_bufobj->length; DUK_ASSERT(h_arrbuf->buf_prop == NULL); DUK_ASSERT(h_bufobj->buf_prop == NULL); h_bufobj->buf_prop = (duk_hobject *) h_arrbuf; - DUK_HBUFOBJ_INCREF(thr, h_arrbuf); /* Now reachable and accounted for. */ + DUK_HBUFOBJ_INCREF(thr, h_arrbuf); /* Now reachable and accounted for. */ } /* Left on stack; pushed for the second time below (OK). */ @@ -29950,7 +30695,7 @@ duk_hbuffer *h_buf; h_buf = (duk_hbuffer *) h_bufobj; - DUK_ASSERT(DUK_HBUFFER_GET_SIZE(h_buf) <= DUK_UINT_MAX); /* Buffer limits. */ + DUK_ASSERT(DUK_HBUFFER_GET_SIZE(h_buf) <= DUK_UINT_MAX); /* Buffer limits. */ duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_buf)); } else { /* If neutered must return 0; length is zeroed during @@ -29960,7 +30705,7 @@ } return 1; } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* No .buffer getter without ArrayBuffer support. */ #if 0 DUK_INTERNAL duk_ret_t duk_bi_typedarray_buffer_getter(duk_hthread *thr) { @@ -29982,7 +30727,7 @@ duk_push_uint(thr, DUK_HBUFFER_GET_SIZE(h_buf)); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* automatic undefs */ #undef DUK__BUFOBJ_FLAG_PROMOTE @@ -30192,7 +30937,7 @@ p += 8; enc_ctx->ptr = p; } -#else /* DUK_CBOR_DOUBLE_AS_IS */ +#else /* DUK_CBOR_DOUBLE_AS_IS */ DUK_LOCAL void duk__cbor_encode_double_fp(duk_cbor_encode_context *enc_ctx, double d) { duk_double_union u; duk_uint16_t u16; @@ -30227,8 +30972,7 @@ duk_bool_t use_half_float; use_half_float = - (u.uc0 == 0 && u.uc1 == 0 && u.uc2 == 0 && u.uc3 == 0 && - u.uc4 == 0 && (u.uc5 & 0x03U) == 0); + (u.uc0 == 0 && u.uc1 == 0 && u.uc2 == 0 && u.uc3 == 0 && u.uc4 == 0 && (u.uc5 & 0x03U) == 0); if (use_half_float) { duk_uint32_t t; @@ -30380,9 +31124,9 @@ /* Most important path is integers. The floor() test will be true * for Inf too (but not NaN). */ - d_floor = DUK_FLOOR(d); /* identity if d is +/- 0.0, NaN, or +/- Infinity */ + d_floor = DUK_FLOOR(d); /* identity if d is +/- 0.0, NaN, or +/- Infinity */ if (DUK_LIKELY(duk_double_equals(d_floor, d) != 0)) { - DUK_ASSERT(!DUK_ISNAN(d)); /* NaN == NaN compares false. */ + DUK_ASSERT(!DUK_ISNAN(d)); /* NaN == NaN compares false. */ if (DUK_SIGNBIT(d)) { if (d >= -4294967296.0) { d = -1.0 - d; @@ -30421,7 +31165,7 @@ DUK_ASSERT(DUK_FPCLASSIFY(d) != DUK_FP_ZERO); duk__cbor_encode_double_fp(enc_ctx, d); } -#endif /* DUK_CBOR_DOUBLE_AS_IS */ +#endif /* DUK_CBOR_DOUBLE_AS_IS */ DUK_LOCAL void duk__cbor_encode_string_top(duk_cbor_encode_context *enc_ctx) { const duk_uint8_t *str; @@ -30472,7 +31216,8 @@ #elif defined(DUK_CBOR_BYTE_STRINGS) duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, 0x40U); #else - duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, + duk__cbor_encode_uint32(enc_ctx, + (duk_uint32_t) len, (DUK_LIKELY(duk_unicode_is_utf8_compatible(str, len) != 0) ? 0x60U : 0x40U)); #endif duk__cbor_encode_ensure(enc_ctx, len); @@ -30532,14 +31277,14 @@ * indefinite length. This works well up to 23 * properties which is practical and good enough. */ - off_ib = (duk_size_t) (enc_ctx->ptr - enc_ctx->buf); /* XXX: get_offset? */ + off_ib = (duk_size_t) (enc_ctx->ptr - enc_ctx->buf); /* XXX: get_offset? */ count = 0U; p = enc_ctx->ptr; - *p++ = 0xa0U + 0x1fU; /* indefinite length */ + *p++ = 0xa0U + 0x1fU; /* indefinite length */ enc_ctx->ptr = p; duk_enum(enc_ctx->thr, -1, DUK_ENUM_OWN_PROPERTIES_ONLY); while (duk_next(enc_ctx->thr, -1, 1 /*get_value*/)) { - duk_insert(enc_ctx->thr, -2); /* ... key value -> ... value key */ + duk_insert(enc_ctx->thr, -2); /* ... key value -> ... value key */ duk__cbor_encode_value(enc_ctx); duk__cbor_encode_value(enc_ctx); count++; @@ -30554,7 +31299,7 @@ } else { duk__cbor_encode_ensure(enc_ctx, 1); p = enc_ctx->ptr; - *p++ = 0xffU; /* break */ + *p++ = 0xffU; /* break */ enc_ctx->ptr = p; } } @@ -30682,7 +31427,7 @@ duk_pop(enc_ctx->thr); return; - fail: +fail: duk__cbor_encode_error(enc_ctx); } @@ -30759,7 +31504,7 @@ } DUK_LOCAL void duk__cbor_decode_rewind(duk_cbor_decode_context *dec_ctx, duk_size_t len) { - DUK_ASSERT(len <= dec_ctx->off); /* Caller must ensure. */ + DUK_ASSERT(len <= dec_ctx->off); /* Caller must ensure. */ dec_ctx->off -= len; } @@ -30779,7 +31524,7 @@ return res; } - duk__cbor_decode_error(dec_ctx); /* Not enough input. */ + duk__cbor_decode_error(dec_ctx); /* Not enough input. */ return NULL; } @@ -30811,16 +31556,16 @@ } switch (ai) { - case 0x18U: /* 1 byte */ + case 0x18U: /* 1 byte */ t = (duk_uint32_t) duk__cbor_decode_readbyte(dec_ctx); goto shared_exit; - case 0x19U: /* 2 byte */ + case 0x19U: /* 2 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u16(dec_ctx); goto shared_exit; - case 0x1aU: /* 4 byte */ + case 0x1aU: /* 4 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); goto shared_exit; - case 0x1bU: /* 8 byte */ + case 0x1bU: /* 8 byte */ /* For uint64 it's important to handle the -1.0 part before * casting to double: otherwise the adjustment might be lost * in the cast. Uses: -1.0 - d <=> -(d + 1.0). @@ -30877,7 +31622,7 @@ * * No fastint check for this path at present. */ - d1 = (duk_double_t) t1; /* XXX: cast helpers */ + d1 = (duk_double_t) t1; /* XXX: cast helpers */ d2 = (duk_double_t) t2 * 4294967296.0; if (negative) { d1 += 1.0; @@ -30895,10 +31640,10 @@ duk__cbor_decode_error(dec_ctx); return; - shared_exit: +shared_exit: if (negative) { /* XXX: a push and check for fastint API would be nice */ - if ((duk_uint_t) t <= (duk_uint_t) -(DUK_INT_MIN + 1)) { + if ((duk_uint_t) t <= (duk_uint_t) - (DUK_INT_MIN + 1)) { duk_push_int(dec_ctx->thr, -1 - ((duk_int_t) t)); } else { duk_push_number(dec_ctx->thr, -1.0 - (duk_double_t) t); @@ -30909,10 +31654,8 @@ } DUK_LOCAL void duk__cbor_decode_skip_aival_int(duk_cbor_decode_context *dec_ctx, duk_uint8_t ib) { - const duk_int8_t skips32 = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, -1, -1, -1, -1 - }; + const duk_int8_t skips32 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, -1, -1, -1, -1 }; duk_uint8_t ai; duk_int8_t skip; @@ -30935,16 +31678,16 @@ } switch (ai) { - case 0x18U: /* 1 byte */ + case 0x18U: /* 1 byte */ t = (duk_uint32_t) duk__cbor_decode_readbyte(dec_ctx); return t; - case 0x19U: /* 2 byte */ + case 0x19U: /* 2 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u16(dec_ctx); return t; - case 0x1aU: /* 4 byte */ + case 0x1aU: /* 4 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); return t; - case 0x1bU: /* 8 byte */ + case 0x1bU: /* 8 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); if (t != 0U) { break; @@ -30978,7 +31721,7 @@ DUK_LOCAL void duk__cbor_decode_join_buffers(duk_cbor_decode_context *dec_ctx, duk_idx_t count) { duk_size_t total_size = 0; duk_idx_t top = duk_get_top(dec_ctx->thr); - duk_idx_t base = top - count; /* count is >= 1 */ + duk_idx_t base = top - count; /* count is >= 1 */ duk_idx_t idx; duk_uint8_t *p = NULL; @@ -30999,7 +31742,7 @@ p += buf_size; } else { total_size += buf_size; - if (DUK_UNLIKELY(total_size < buf_size)) { /* Wrap check. */ + if (DUK_UNLIKELY(total_size < buf_size)) { /* Wrap check. */ duk__cbor_decode_error(dec_ctx); } } @@ -31026,7 +31769,7 @@ duk_require_stack(dec_ctx->thr, 1); duk__cbor_decode_buffer(dec_ctx, expected_base); count++; - if (DUK_UNLIKELY(count <= 0)) { /* Wrap check. */ + if (DUK_UNLIKELY(count <= 0)) { /* Wrap check. */ duk__cbor_decode_error(dec_ctx); } } @@ -31074,10 +31817,10 @@ */ u.uc7 = 0x3fU; u.uc6 = 0x10U + (duk_uint8_t) ((u16 >> 6) & 0x0fU); - u.uc5 = (duk_uint8_t) ((u16 << 2) & 0xffU); /* Mask is really 0xfcU */ + u.uc5 = (duk_uint8_t) ((u16 << 2) & 0xffU); /* Mask is really 0xfcU */ duk_dblunion_little_to_host(&u); - res = u.d - 0.00006103515625; /* 2^(-14) */ + res = u.d - 0.00006103515625; /* 2^(-14) */ if (u16 & 0x8000U) { res = -res; } @@ -31176,7 +31919,7 @@ /* XXX: use bare array? */ duk_push_array(dec_ctx->thr); - for (idx = 0U; ;) { + for (idx = 0U;;) { if (len == 0xffffffffUL && duk__cbor_decode_checkbreak(dec_ctx)) { break; } @@ -31190,7 +31933,7 @@ duk_put_prop_index(dec_ctx->thr, -2, (duk_uarridx_t) idx); idx++; if (idx == 0U) { - goto failure; /* wrapped */ + goto failure; /* wrapped */ } } @@ -31200,7 +31943,7 @@ duk__cbor_decode_objarr_exit(dec_ctx); return 1; - failure: +failure: /* No need to unwind recursion checks, caller will throw. */ return 0; } @@ -31252,7 +31995,7 @@ duk__cbor_decode_objarr_exit(dec_ctx); return 1; - failure: +failure: /* No need to unwind recursion checks, caller will throw. */ return 0; } @@ -31276,7 +32019,7 @@ } #if defined(DUK_CBOR_DECODE_FASTPATH) -#define DUK__CBOR_AI (ib & 0x1fU) +#define DUK__CBOR_AI (ib & 0x1fU) DUK_LOCAL void duk__cbor_decode_value(duk_cbor_decode_context *dec_ctx) { duk_uint8_t ib; @@ -31286,7 +32029,7 @@ * here for simple paths like primitive values. */ - reread_initial_byte: +reread_initial_byte: DUK_DDD(DUK_DDDPRINT("cbor decode off=%ld len=%ld", (long) dec_ctx->off, (long) dec_ctx->len)); ib = duk__cbor_decode_readbyte(dec_ctx); @@ -31295,107 +32038,292 @@ /* XXX: Force full switch with no range check. */ switch (ib) { - case 0x00U: case 0x01U: case 0x02U: case 0x03U: case 0x04U: case 0x05U: case 0x06U: case 0x07U: - case 0x08U: case 0x09U: case 0x0aU: case 0x0bU: case 0x0cU: case 0x0dU: case 0x0eU: case 0x0fU: - case 0x10U: case 0x11U: case 0x12U: case 0x13U: case 0x14U: case 0x15U: case 0x16U: case 0x17U: + case 0x00U: + case 0x01U: + case 0x02U: + case 0x03U: + case 0x04U: + case 0x05U: + case 0x06U: + case 0x07U: + case 0x08U: + case 0x09U: + case 0x0aU: + case 0x0bU: + case 0x0cU: + case 0x0dU: + case 0x0eU: + case 0x0fU: + case 0x10U: + case 0x11U: + case 0x12U: + case 0x13U: + case 0x14U: + case 0x15U: + case 0x16U: + case 0x17U: duk_push_uint(dec_ctx->thr, ib); break; - case 0x18U: case 0x19U: case 0x1aU: case 0x1bU: + case 0x18U: + case 0x19U: + case 0x1aU: + case 0x1bU: duk__cbor_decode_push_aival_int(dec_ctx, ib, 0 /*negative*/); break; - case 0x1cU: case 0x1dU: case 0x1eU: case 0x1fU: + case 0x1cU: + case 0x1dU: + case 0x1eU: + case 0x1fU: goto format_error; - case 0x20U: case 0x21U: case 0x22U: case 0x23U: case 0x24U: case 0x25U: case 0x26U: case 0x27U: - case 0x28U: case 0x29U: case 0x2aU: case 0x2bU: case 0x2cU: case 0x2dU: case 0x2eU: case 0x2fU: - case 0x30U: case 0x31U: case 0x32U: case 0x33U: case 0x34U: case 0x35U: case 0x36U: case 0x37U: + case 0x20U: + case 0x21U: + case 0x22U: + case 0x23U: + case 0x24U: + case 0x25U: + case 0x26U: + case 0x27U: + case 0x28U: + case 0x29U: + case 0x2aU: + case 0x2bU: + case 0x2cU: + case 0x2dU: + case 0x2eU: + case 0x2fU: + case 0x30U: + case 0x31U: + case 0x32U: + case 0x33U: + case 0x34U: + case 0x35U: + case 0x36U: + case 0x37U: duk_push_int(dec_ctx->thr, -((duk_int_t) ((ib - 0x20U) + 1U))); break; - case 0x38U: case 0x39U: case 0x3aU: case 0x3bU: + case 0x38U: + case 0x39U: + case 0x3aU: + case 0x3bU: duk__cbor_decode_push_aival_int(dec_ctx, ib, 1 /*negative*/); break; - case 0x3cU: case 0x3dU: case 0x3eU: case 0x3fU: + case 0x3cU: + case 0x3dU: + case 0x3eU: + case 0x3fU: goto format_error; - case 0x40U: case 0x41U: case 0x42U: case 0x43U: case 0x44U: case 0x45U: case 0x46U: case 0x47U: - case 0x48U: case 0x49U: case 0x4aU: case 0x4bU: case 0x4cU: case 0x4dU: case 0x4eU: case 0x4fU: - case 0x50U: case 0x51U: case 0x52U: case 0x53U: case 0x54U: case 0x55U: case 0x56U: case 0x57U: + case 0x40U: + case 0x41U: + case 0x42U: + case 0x43U: + case 0x44U: + case 0x45U: + case 0x46U: + case 0x47U: + case 0x48U: + case 0x49U: + case 0x4aU: + case 0x4bU: + case 0x4cU: + case 0x4dU: + case 0x4eU: + case 0x4fU: + case 0x50U: + case 0x51U: + case 0x52U: + case 0x53U: + case 0x54U: + case 0x55U: + case 0x56U: + case 0x57U: /* XXX: Avoid rewind, we know the length already. */ DUK_ASSERT(dec_ctx->off > 0U); dec_ctx->off--; duk__cbor_decode_buffer(dec_ctx, 0x40U); break; - case 0x58U: case 0x59U: case 0x5aU: case 0x5bU: + case 0x58U: + case 0x59U: + case 0x5aU: + case 0x5bU: /* XXX: Avoid rewind, decode length inline. */ DUK_ASSERT(dec_ctx->off > 0U); dec_ctx->off--; duk__cbor_decode_buffer(dec_ctx, 0x40U); break; - case 0x5cU: case 0x5dU: case 0x5eU: + case 0x5cU: + case 0x5dU: + case 0x5eU: goto format_error; case 0x5fU: duk__cbor_decode_and_join_strbuf(dec_ctx, 0x40U); break; - case 0x60U: case 0x61U: case 0x62U: case 0x63U: case 0x64U: case 0x65U: case 0x66U: case 0x67U: - case 0x68U: case 0x69U: case 0x6aU: case 0x6bU: case 0x6cU: case 0x6dU: case 0x6eU: case 0x6fU: - case 0x70U: case 0x71U: case 0x72U: case 0x73U: case 0x74U: case 0x75U: case 0x76U: case 0x77U: + case 0x60U: + case 0x61U: + case 0x62U: + case 0x63U: + case 0x64U: + case 0x65U: + case 0x66U: + case 0x67U: + case 0x68U: + case 0x69U: + case 0x6aU: + case 0x6bU: + case 0x6cU: + case 0x6dU: + case 0x6eU: + case 0x6fU: + case 0x70U: + case 0x71U: + case 0x72U: + case 0x73U: + case 0x74U: + case 0x75U: + case 0x76U: + case 0x77U: /* XXX: Avoid double decode of length. */ duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x78U: case 0x79U: case 0x7aU: case 0x7bU: + case 0x78U: + case 0x79U: + case 0x7aU: + case 0x7bU: /* XXX: Avoid double decode of length. */ duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x7cU: case 0x7dU: case 0x7eU: + case 0x7cU: + case 0x7dU: + case 0x7eU: goto format_error; case 0x7fU: duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x80U: case 0x81U: case 0x82U: case 0x83U: case 0x84U: case 0x85U: case 0x86U: case 0x87U: - case 0x88U: case 0x89U: case 0x8aU: case 0x8bU: case 0x8cU: case 0x8dU: case 0x8eU: case 0x8fU: - case 0x90U: case 0x91U: case 0x92U: case 0x93U: case 0x94U: case 0x95U: case 0x96U: case 0x97U: + case 0x80U: + case 0x81U: + case 0x82U: + case 0x83U: + case 0x84U: + case 0x85U: + case 0x86U: + case 0x87U: + case 0x88U: + case 0x89U: + case 0x8aU: + case 0x8bU: + case 0x8cU: + case 0x8dU: + case 0x8eU: + case 0x8fU: + case 0x90U: + case 0x91U: + case 0x92U: + case 0x93U: + case 0x94U: + case 0x95U: + case 0x96U: + case 0x97U: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0x98U: case 0x99U: case 0x9aU: case 0x9bU: + case 0x98U: + case 0x99U: + case 0x9aU: + case 0x9bU: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0x9cU: case 0x9dU: case 0x9eU: + case 0x9cU: + case 0x9dU: + case 0x9eU: goto format_error; case 0x9fU: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xa0U: case 0xa1U: case 0xa2U: case 0xa3U: case 0xa4U: case 0xa5U: case 0xa6U: case 0xa7U: - case 0xa8U: case 0xa9U: case 0xaaU: case 0xabU: case 0xacU: case 0xadU: case 0xaeU: case 0xafU: - case 0xb0U: case 0xb1U: case 0xb2U: case 0xb3U: case 0xb4U: case 0xb5U: case 0xb6U: case 0xb7U: + case 0xa0U: + case 0xa1U: + case 0xa2U: + case 0xa3U: + case 0xa4U: + case 0xa5U: + case 0xa6U: + case 0xa7U: + case 0xa8U: + case 0xa9U: + case 0xaaU: + case 0xabU: + case 0xacU: + case 0xadU: + case 0xaeU: + case 0xafU: + case 0xb0U: + case 0xb1U: + case 0xb2U: + case 0xb3U: + case 0xb4U: + case 0xb5U: + case 0xb6U: + case 0xb7U: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xb8U: case 0xb9U: case 0xbaU: case 0xbbU: + case 0xb8U: + case 0xb9U: + case 0xbaU: + case 0xbbU: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xbcU: case 0xbdU: case 0xbeU: + case 0xbcU: + case 0xbdU: + case 0xbeU: goto format_error; case 0xbfU: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xc0U: case 0xc1U: case 0xc2U: case 0xc3U: case 0xc4U: case 0xc5U: case 0xc6U: case 0xc7U: - case 0xc8U: case 0xc9U: case 0xcaU: case 0xcbU: case 0xccU: case 0xcdU: case 0xceU: case 0xcfU: - case 0xd0U: case 0xd1U: case 0xd2U: case 0xd3U: case 0xd4U: case 0xd5U: case 0xd6U: case 0xd7U: + case 0xc0U: + case 0xc1U: + case 0xc2U: + case 0xc3U: + case 0xc4U: + case 0xc5U: + case 0xc6U: + case 0xc7U: + case 0xc8U: + case 0xc9U: + case 0xcaU: + case 0xcbU: + case 0xccU: + case 0xcdU: + case 0xceU: + case 0xcfU: + case 0xd0U: + case 0xd1U: + case 0xd2U: + case 0xd3U: + case 0xd4U: + case 0xd5U: + case 0xd6U: + case 0xd7U: /* Tag 0-23: drop. */ goto reread_initial_byte; - case 0xd8U: case 0xd9U: case 0xdaU: case 0xdbU: + case 0xd8U: + case 0xd9U: + case 0xdaU: + case 0xdbU: duk__cbor_decode_skip_aival_int(dec_ctx, ib); goto reread_initial_byte; - case 0xdcU: case 0xddU: case 0xdeU: case 0xdfU: + case 0xdcU: + case 0xddU: + case 0xdeU: + case 0xdfU: goto format_error; case 0xe0U: goto format_error; @@ -31475,14 +32403,14 @@ case 0xfeU: case 0xffU: goto format_error; - } /* end switch */ + } /* end switch */ return; - format_error: +format_error: duk__cbor_decode_error(dec_ctx); } -#else /* DUK_CBOR_DECODE_FASTPATH */ +#else /* DUK_CBOR_DECODE_FASTPATH */ DUK_LOCAL void duk__cbor_decode_value(duk_cbor_decode_context *dec_ctx) { duk_uint8_t ib, mt, ai; @@ -31491,7 +32419,7 @@ * here for simple paths like primitive values. */ - reread_initial_byte: +reread_initial_byte: DUK_DDD(DUK_DDDPRINT("cbor decode off=%ld len=%ld", (long) dec_ctx->off, (long) dec_ctx->len)); ib = duk__cbor_decode_readbyte(dec_ctx); @@ -31507,15 +32435,15 @@ */ switch (mt) { - case 0U: { /* unsigned integer */ + case 0U: { /* unsigned integer */ duk__cbor_decode_push_aival_int(dec_ctx, ib, 0 /*negative*/); break; } - case 1U: { /* negative integer */ + case 1U: { /* negative integer */ duk__cbor_decode_push_aival_int(dec_ctx, ib, 1 /*negative*/); break; } - case 2U: { /* byte string */ + case 2U: { /* byte string */ if (ai == 0x1fU) { duk__cbor_decode_and_join_strbuf(dec_ctx, 0x40U); } else { @@ -31524,23 +32452,23 @@ } break; } - case 3U: { /* text string */ + case 3U: { /* text string */ duk__cbor_decode_string(dec_ctx, ib, ai); break; } - case 4U: { /* array of data items */ + case 4U: { /* array of data items */ if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, ai) == 0)) { goto format_error; } break; } - case 5U: { /* map of pairs of data items */ + case 5U: { /* map of pairs of data items */ if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, ai) == 0)) { goto format_error; } break; } - case 6U: { /* semantic tagging */ + case 6U: { /* semantic tagging */ /* Tags are ignored now, re-read initial byte. A tagged * value may itself be tagged (an unlimited number of times) * so keep on peeling away tags. @@ -31548,7 +32476,7 @@ duk__cbor_decode_skip_aival_int(dec_ctx, ib); goto reread_initial_byte; } - case 7U: { /* floating point numbers, simple data types, break; other */ + case 7U: { /* floating point numbers, simple data types, break; other */ switch (ai) { case 0x14U: { duk_push_false(dec_ctx->thr); @@ -31566,7 +32494,7 @@ duk_push_undefined(dec_ctx->thr); break; } - case 0x18U: { /* more simple values (1 byte) */ + case 0x18U: { /* more simple values (1 byte) */ /* Simple value encoded in additional byte (none * are defined so far). RFC 7049 states that the * follow-up byte must be 32-255 to minimize @@ -31577,42 +32505,42 @@ */ goto format_error; } - case 0x19U: { /* half-float (2 bytes) */ + case 0x19U: { /* half-float (2 bytes) */ duk_double_t d; d = duk__cbor_decode_half_float(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0x1aU: { /* float (4 bytes) */ + case 0x1aU: { /* float (4 bytes) */ duk_double_t d; d = duk__cbor_decode_float(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0x1bU: { /* double (8 bytes) */ + case 0x1bU: { /* double (8 bytes) */ duk_double_t d; d = duk__cbor_decode_double(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0xffU: /* unexpected break */ + case 0xffU: /* unexpected break */ default: { goto format_error; } - } /* end switch */ + } /* end switch */ break; } default: { - goto format_error; /* will never actually occur */ + goto format_error; /* will never actually occur */ } - } /* end switch */ + } /* end switch */ return; - format_error: +format_error: duk__cbor_decode_error(dec_ctx); } -#endif /* DUK_CBOR_DECODE_FASTPATH */ +#endif /* DUK_CBOR_DECODE_FASTPATH */ DUK_LOCAL void duk__cbor_encode(duk_hthread *thr, duk_idx_t idx, duk_uint_t encode_flags) { duk_cbor_encode_context enc_ctx; @@ -31672,7 +32600,7 @@ duk_replace(thr, idx); } -#else /* DUK_USE_CBOR_SUPPORT */ +#else /* DUK_USE_CBOR_SUPPORT */ DUK_LOCAL void duk__cbor_encode(duk_hthread *thr, duk_idx_t idx, duk_uint_t encode_flags) { DUK_UNREF(idx); @@ -31686,7 +32614,7 @@ DUK_ERROR_UNSUPPORTED(thr); } -#endif /* DUK_USE_CBOR_SUPPORT */ +#endif /* DUK_USE_CBOR_SUPPORT */ /* * Public APIs @@ -31722,7 +32650,7 @@ duk__cbor_decode(thr, -1, 0 /*flags*/); return 1; } -#else /* DUK_USE_CBOR_SUPPORT */ +#else /* DUK_USE_CBOR_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_cbor_encode(duk_hthread *thr) { DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); @@ -31731,8 +32659,8 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_CBOR_SUPPORT */ -#endif /* DUK_USE_CBOR_BUILTIN */ +#endif /* DUK_USE_CBOR_SUPPORT */ +#endif /* DUK_USE_CBOR_BUILTIN */ /* automatic undefs */ #undef DUK__CBOR_AI @@ -31767,30 +32695,49 @@ */ /* Debug macro to print all parts and dparts (used manually because of debug level). */ -#define DUK__DPRINT_PARTS_AND_DPARTS(parts,dparts) do { \ +#define DUK__DPRINT_PARTS_AND_DPARTS(parts, dparts) \ + do { \ DUK_D(DUK_DPRINT("parts: %ld %ld %ld %ld %ld %ld %ld %ld, dparts: %lf %lf %lf %lf %lf %lf %lf %lf", \ - (long) (parts)0, (long) (parts)1, \ - (long) (parts)2, (long) (parts)3, \ - (long) (parts)4, (long) (parts)5, \ - (long) (parts)6, (long) (parts)7, \ - (double) (dparts)0, (double) (dparts)1, \ - (double) (dparts)2, (double) (dparts)3, \ - (double) (dparts)4, (double) (dparts)5, \ - (double) (dparts)6, (double) (dparts)7)); \ + (long) (parts)0, \ + (long) (parts)1, \ + (long) (parts)2, \ + (long) (parts)3, \ + (long) (parts)4, \ + (long) (parts)5, \ + (long) (parts)6, \ + (long) (parts)7, \ + (double) (dparts)0, \ + (double) (dparts)1, \ + (double) (dparts)2, \ + (double) (dparts)3, \ + (double) (dparts)4, \ + (double) (dparts)5, \ + (double) (dparts)6, \ + (double) (dparts)7)); \ } while (0) -#define DUK__DPRINT_PARTS(parts) do { \ +#define DUK__DPRINT_PARTS(parts) \ + do { \ DUK_D(DUK_DPRINT("parts: %ld %ld %ld %ld %ld %ld %ld %ld", \ - (long) (parts)0, (long) (parts)1, \ - (long) (parts)2, (long) (parts)3, \ - (long) (parts)4, (long) (parts)5, \ - (long) (parts)6, (long) (parts)7)); \ + (long) (parts)0, \ + (long) (parts)1, \ + (long) (parts)2, \ + (long) (parts)3, \ + (long) (parts)4, \ + (long) (parts)5, \ + (long) (parts)6, \ + (long) (parts)7)); \ } while (0) -#define DUK__DPRINT_DPARTS(dparts) do { \ +#define DUK__DPRINT_DPARTS(dparts) \ + do { \ DUK_D(DUK_DPRINT("dparts: %lf %lf %lf %lf %lf %lf %lf %lf", \ - (double) (dparts)0, (double) (dparts)1, \ - (double) (dparts)2, (double) (dparts)3, \ - (double) (dparts)4, (double) (dparts)5, \ - (double) (dparts)6, (double) (dparts)7)); \ + (double) (dparts)0, \ + (double) (dparts)1, \ + (double) (dparts)2, \ + (double) (dparts)3, \ + (double) (dparts)4, \ + (double) (dparts)5, \ + (double) (dparts)6, \ + (double) (dparts)7)); \ } while (0) /* Equivalent year for DST calculations outside 1970,2038 range, see @@ -31798,7 +32745,7 @@ * starts with the same weekday on Jan 1. * https://bugzilla.mozilla.org/show_bug.cgi?id=351066 */ -#define DUK__YEAR(x) ((duk_uint8_t) ((x) - 1970)) +#define DUK__YEAR(x) ((duk_uint8_t) ((x) -1970)) DUK_LOCAL duk_uint8_t duk__date_equivyear14 = { #if 1 /* This is based on V8 EquivalentYear() algorithm (see util/genequivyear.py): @@ -31806,12 +32753,22 @@ */ /* non-leap year: sunday, monday, ... */ - DUK__YEAR(2023), DUK__YEAR(2035), DUK__YEAR(2019), DUK__YEAR(2031), - DUK__YEAR(2015), DUK__YEAR(2027), DUK__YEAR(2011), + DUK__YEAR(2023), + DUK__YEAR(2035), + DUK__YEAR(2019), + DUK__YEAR(2031), + DUK__YEAR(2015), + DUK__YEAR(2027), + DUK__YEAR(2011), /* leap year: sunday, monday, ... */ - DUK__YEAR(2012), DUK__YEAR(2024), DUK__YEAR(2008), DUK__YEAR(2020), - DUK__YEAR(2032), DUK__YEAR(2016), DUK__YEAR(2028) + DUK__YEAR(2012), + DUK__YEAR(2024), + DUK__YEAR(2008), + DUK__YEAR(2020), + DUK__YEAR(2032), + DUK__YEAR(2016), + DUK__YEAR(2028) #endif #if 0 @@ -31834,71 +32791,70 @@ */ /* Parser part count. */ -#define DUK__NUM_ISO8601_PARSER_PARTS 9 +#define DUK__NUM_ISO8601_PARSER_PARTS 9 /* Parser part indices. */ -#define DUK__PI_YEAR 0 -#define DUK__PI_MONTH 1 -#define DUK__PI_DAY 2 -#define DUK__PI_HOUR 3 -#define DUK__PI_MINUTE 4 -#define DUK__PI_SECOND 5 -#define DUK__PI_MILLISECOND 6 -#define DUK__PI_TZHOUR 7 -#define DUK__PI_TZMINUTE 8 +#define DUK__PI_YEAR 0 +#define DUK__PI_MONTH 1 +#define DUK__PI_DAY 2 +#define DUK__PI_HOUR 3 +#define DUK__PI_MINUTE 4 +#define DUK__PI_SECOND 5 +#define DUK__PI_MILLISECOND 6 +#define DUK__PI_TZHOUR 7 +#define DUK__PI_TZMINUTE 8 /* Parser part masks. */ -#define DUK__PM_YEAR (1 << DUK__PI_YEAR) -#define DUK__PM_MONTH (1 << DUK__PI_MONTH) -#define DUK__PM_DAY (1 << DUK__PI_DAY) -#define DUK__PM_HOUR (1 << DUK__PI_HOUR) -#define DUK__PM_MINUTE (1 << DUK__PI_MINUTE) -#define DUK__PM_SECOND (1 << DUK__PI_SECOND) -#define DUK__PM_MILLISECOND (1 << DUK__PI_MILLISECOND) -#define DUK__PM_TZHOUR (1 << DUK__PI_TZHOUR) -#define DUK__PM_TZMINUTE (1 << DUK__PI_TZMINUTE) +#define DUK__PM_YEAR (1 << DUK__PI_YEAR) +#define DUK__PM_MONTH (1 << DUK__PI_MONTH) +#define DUK__PM_DAY (1 << DUK__PI_DAY) +#define DUK__PM_HOUR (1 << DUK__PI_HOUR) +#define DUK__PM_MINUTE (1 << DUK__PI_MINUTE) +#define DUK__PM_SECOND (1 << DUK__PI_SECOND) +#define DUK__PM_MILLISECOND (1 << DUK__PI_MILLISECOND) +#define DUK__PM_TZHOUR (1 << DUK__PI_TZHOUR) +#define DUK__PM_TZMINUTE (1 << DUK__PI_TZMINUTE) /* Parser separator indices. */ -#define DUK__SI_PLUS 0 -#define DUK__SI_MINUS 1 -#define DUK__SI_T 2 -#define DUK__SI_SPACE 3 -#define DUK__SI_COLON 4 -#define DUK__SI_PERIOD 5 -#define DUK__SI_Z 6 -#define DUK__SI_NUL 7 +#define DUK__SI_PLUS 0 +#define DUK__SI_MINUS 1 +#define DUK__SI_T 2 +#define DUK__SI_SPACE 3 +#define DUK__SI_COLON 4 +#define DUK__SI_PERIOD 5 +#define DUK__SI_Z 6 +#define DUK__SI_NUL 7 /* Parser separator masks. */ -#define DUK__SM_PLUS (1 << DUK__SI_PLUS) -#define DUK__SM_MINUS (1 << DUK__SI_MINUS) -#define DUK__SM_T (1 << DUK__SI_T) -#define DUK__SM_SPACE (1 << DUK__SI_SPACE) -#define DUK__SM_COLON (1 << DUK__SI_COLON) -#define DUK__SM_PERIOD (1 << DUK__SI_PERIOD) -#define DUK__SM_Z (1 << DUK__SI_Z) -#define DUK__SM_NUL (1 << DUK__SI_NUL) +#define DUK__SM_PLUS (1 << DUK__SI_PLUS) +#define DUK__SM_MINUS (1 << DUK__SI_MINUS) +#define DUK__SM_T (1 << DUK__SI_T) +#define DUK__SM_SPACE (1 << DUK__SI_SPACE) +#define DUK__SM_COLON (1 << DUK__SI_COLON) +#define DUK__SM_PERIOD (1 << DUK__SI_PERIOD) +#define DUK__SM_Z (1 << DUK__SI_Z) +#define DUK__SM_NUL (1 << DUK__SI_NUL) /* Rule control flags. */ -#define DUK__CF_NEG (1 << 0) /* continue matching, set neg_tzoffset flag */ -#define DUK__CF_ACCEPT (1 << 1) /* accept string */ -#define DUK__CF_ACCEPT_NUL (1 << 2) /* accept string if next char is NUL (otherwise reject) */ - -#define DUK__PACK_RULE(partmask,sepmask,nextpart,flags) \ - ((duk_uint32_t) (partmask) + \ - (((duk_uint32_t) (sepmask)) << 9) + \ - (((duk_uint32_t) (nextpart)) << 17) + \ +#define DUK__CF_NEG (1 << 0) /* continue matching, set neg_tzoffset flag */ +#define DUK__CF_ACCEPT (1 << 1) /* accept string */ +#define DUK__CF_ACCEPT_NUL (1 << 2) /* accept string if next char is NUL (otherwise reject) */ + +#define DUK__PACK_RULE(partmask, sepmask, nextpart, flags) \ + ((duk_uint32_t) (partmask) + (((duk_uint32_t) (sepmask)) << 9) + (((duk_uint32_t) (nextpart)) << 17) + \ (((duk_uint32_t) (flags)) << 21)) -#define DUK__UNPACK_RULE(rule,var_nextidx,var_flags) do { \ +#define DUK__UNPACK_RULE(rule, var_nextidx, var_flags) \ + do { \ (var_nextidx) = (duk_small_uint_t) (((rule) >> 17) & 0x0f); \ (var_flags) = (duk_small_uint_t) ((rule) >> 21); \ } while (0) -#define DUK__RULE_MASK_PART_SEP 0x1ffffUL +#define DUK__RULE_MASK_PART_SEP 0x1ffffUL /* Matching separator index is used in the control table */ DUK_LOCAL const duk_uint8_t duk__parse_iso8601_seps = { - DUK_ASC_PLUS /*0*/, DUK_ASC_MINUS /*1*/, DUK_ASC_UC_T /*2*/, DUK_ASC_SPACE /*3*/, + DUK_ASC_PLUS /*0*/, DUK_ASC_MINUS /*1*/, DUK_ASC_UC_T /*2*/, DUK_ASC_SPACE /*3*/, DUK_ASC_COLON /*4*/, DUK_ASC_PERIOD /*5*/, DUK_ASC_UC_Z /*6*/, DUK_ASC_NUL /*7*/ }; @@ -31911,10 +32867,26 @@ DUK__PACK_RULE(DUK__PM_MINUTE, DUK__SM_COLON, DUK__PI_SECOND, 0), DUK__PACK_RULE(DUK__PM_SECOND, DUK__SM_PERIOD, DUK__PI_MILLISECOND, 0), DUK__PACK_RULE(DUK__PM_TZHOUR, DUK__SM_COLON, DUK__PI_TZMINUTE, 0), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_PLUS, DUK__PI_TZHOUR, 0), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_MINUS, DUK__PI_TZHOUR, DUK__CF_NEG), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_Z, 0, DUK__CF_ACCEPT_NUL), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND | DUK__PM_TZHOUR /*Note2*/ | DUK__PM_TZMINUTE, DUK__SM_NUL, 0, DUK__CF_ACCEPT) + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_PLUS, + DUK__PI_TZHOUR, + 0), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_MINUS, + DUK__PI_TZHOUR, + DUK__CF_NEG), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_Z, + 0, + DUK__CF_ACCEPT_NUL), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND | DUK__PM_TZHOUR /*Note2*/ | DUK__PM_TZMINUTE, + DUK__SM_NUL, + 0, + DUK__CF_ACCEPT) /* Note1: the specification doesn't require matching a time form with * just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z". @@ -31939,7 +32911,7 @@ /* During parsing, month and day are one-based; set defaults here. */ duk_memzero(parts, sizeof(parts)); - DUK_ASSERT(partsDUK_DATE_IDX_YEAR == 0); /* don't care value, year is mandatory */ + DUK_ASSERT(partsDUK_DATE_IDX_YEAR == 0); /* don't care value, year is mandatory */ partsDUK_DATE_IDX_MONTH = 1; partsDUK_DATE_IDX_DAY = 1; @@ -31956,7 +32928,8 @@ for (;;) { ch = *p++; DUK_DDD(DUK_DDDPRINT("parsing, part_idx=%ld, char=%ld ('%c')", - (long) part_idx, (long) ch, + (long) part_idx, + (long) ch, (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : DUK_ASC_QUESTION))); if (ch >= DUK_ASC_0 && ch <= DUK_ASC_9) { @@ -32001,7 +32974,7 @@ } sep_idx = i; - match_val = (1UL << part_idx) + (1UL << (sep_idx + 9)); /* match against rule part/sep bits */ + match_val = (1UL << part_idx) + (1UL << (sep_idx + 9)); /* match against rule part/sep bits */ for (i = 0; i < (duk_small_uint_t) (sizeof(duk__parse_iso8601_control) / sizeof(duk_uint32_t)); i++) { duk_uint_fast32_t rule = duk__parse_iso8601_controli; @@ -32009,8 +32982,10 @@ duk_small_uint_t cflags; DUK_DDD(DUK_DDDPRINT("part_idx=%ld, sep_idx=%ld, match_val=0x%08lx, considering rule=0x%08lx", - (long) part_idx, (long) sep_idx, - (unsigned long) match_val, (unsigned long) rule)); + (long) part_idx, + (long) sep_idx, + (unsigned long) match_val, + (unsigned long) rule)); if ((rule & match_val) != match_val) { continue; @@ -32020,9 +32995,12 @@ DUK_DDD(DUK_DDDPRINT("rule match -> part_idx=%ld, sep_idx=%ld, match_val=0x%08lx, " "rule=0x%08lx -> nextpart=%ld, cflags=0x%02lx", - (long) part_idx, (long) sep_idx, - (unsigned long) match_val, (unsigned long) rule, - (long) nextpart, (unsigned long) cflags)); + (long) part_idx, + (long) sep_idx, + (unsigned long) match_val, + (unsigned long) rule, + (long) nextpart, + (unsigned long) cflags)); if (cflags & DUK__CF_NEG) { neg_tzoffset = 1; @@ -32042,7 +33020,7 @@ part_idx = nextpart; break; - } /* rule match */ + } /* rule match */ if (i == (duk_small_uint_t) (sizeof(duk__parse_iso8601_control) / sizeof(duk_uint32_t))) { DUK_DDD(DUK_DDDPRINT("no rule matches -> reject")); @@ -32056,17 +33034,17 @@ DUK_DDD(DUK_DDDPRINT("NUL after rule matching (should not happen) -> reject")); goto reject; } - } /* if-digit-else-ctrl */ - } /* char loop */ + } /* if-digit-else-ctrl */ + } /* char loop */ /* We should never exit the loop above. */ DUK_UNREACHABLE(); - reject: +reject: DUK_DDD(DUK_DDDPRINT("reject")); return 0; - accept: +accept: DUK_DDD(DUK_DDDPRINT("accept")); /* Apply timezone offset to get the main parts in UTC */ @@ -32080,8 +33058,8 @@ partsDUK__PI_HOUR -= partsDUK__PI_TZHOUR; partsDUK__PI_MINUTE -= partsDUK__PI_TZMINUTE; } - partsDUK__PI_MONTH -= 1; /* zero-based month */ - partsDUK__PI_DAY -= 1; /* zero-based day */ + partsDUK__PI_MONTH -= 1; /* zero-based month */ + partsDUK__PI_DAY -= 1; /* zero-based day */ /* Use double parts, they tolerate unnormalized time. * @@ -32158,16 +33136,14 @@ * out for non-finite numbers etc. */ -DUK_LOCAL duk_uint8_t duk__days_in_month12 = { - (duk_uint8_t) 31, (duk_uint8_t) 28, (duk_uint8_t) 31, (duk_uint8_t) 30, - (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 31, - (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31 -}; +DUK_LOCAL duk_uint8_t duk__days_in_month12 = { (duk_uint8_t) 31, (duk_uint8_t) 28, (duk_uint8_t) 31, (duk_uint8_t) 30, + (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 31, + (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31 }; /* Maximum iteration count for computing UTC-to-local time offset when * creating an ECMAScript time value from local parts. */ -#define DUK__LOCAL_TZOFFSET_MAXITER 4 +#define DUK__LOCAL_TZOFFSET_MAXITER 4 /* Because 'day since epoch' can be negative and is used to compute weekday * using a modulo operation, add this multiple of 7 to avoid negative values @@ -32175,7 +33151,7 @@ * +/- 100 million days from epoch, so this adder fits nicely into 32 bits. * Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin. */ -#define DUK__WEEKDAY_MOD_ADDER (20000000 * 7) /* 0x08583b00 */ +#define DUK__WEEKDAY_MOD_ADDER (20000000 * 7) /* 0x08583b00 */ DUK_INTERNAL duk_bool_t duk_bi_date_is_leap_year(duk_int_t year) { if ((year % 4) != 0) { @@ -32236,10 +33212,8 @@ /* Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative * values, but is incorrect for negative ones. */ - return 365 * (year - 1970) - + duk__div_floor(year - 1969, 4) - - duk__div_floor(year - 1901, 100) - + duk__div_floor(year - 1601, 400); + return 365 * (year - 1970) + duk__div_floor(year - 1969, 4) - duk__div_floor(year - 1901, 100) + + duk__div_floor(year - 1601, 400); } /* Given a day number, determine year and day-within-year. */ @@ -32261,10 +33235,9 @@ diff_days = duk__day_from_year(year) - day; DUK_DDD(DUK_DDDPRINT("year=%ld day=%ld, diff_days=%ld", (long) year, (long) day, (long) diff_days)); if (diff_days <= 0) { - DUK_ASSERT(-diff_days < 366); /* fits into duk_small_int_t */ + DUK_ASSERT(-diff_days < 366); /* fits into duk_small_int_t */ *out_day_within_year = -diff_days; - DUK_DDD(DUK_DDDPRINT("--> year=%ld, day-within-year=%ld", - (long) year, (long) *out_day_within_year)); + DUK_DDD(DUK_DDDPRINT("--> year=%ld, day-within-year=%ld", (long) year, (long) *out_day_within_year)); DUK_ASSERT(*out_day_within_year >= 0); DUK_ASSERT(*out_day_within_year < (duk_bi_date_is_leap_year(year) ? 366 : 365)); return year; @@ -32273,7 +33246,7 @@ /* Note: this is very tricky; we must never 'overshoot' the * correction downwards. */ - year -= 1 + (diff_days - 1) / 366; /* conservative */ + year -= 1 + (diff_days - 1) / 366; /* conservative */ } } @@ -32346,7 +33319,7 @@ duk_double_t d1, d2; duk_int_t t1, t2; duk_int_t day_since_epoch; - duk_int_t year; /* does not fit into 16 bits */ + duk_int_t year; /* does not fit into 16 bits */ duk_small_int_t day_in_year; duk_small_int_t month; duk_small_int_t day; @@ -32358,8 +33331,8 @@ duk_bool_t is_leap; duk_small_int_t arridx; - DUK_ASSERT(DUK_ISFINITE(d)); /* caller checks */ - d = DUK_FLOOR(d); /* remove fractions if present */ + DUK_ASSERT(DUK_ISFINITE(d)); /* caller checks */ + d = DUK_FLOOR(d); /* remove fractions if present */ DUK_ASSERT(duk_double_equals(DUK_FLOOR(d), d)); /* The timevalue must be in valid ECMAScript range, but since a local @@ -32391,9 +33364,12 @@ * t2 = day number from epoch (fits 32 bit, may be negative) */ - partsDUK_DATE_IDX_MILLISECOND = t1 % 1000; t1 /= 1000; - partsDUK_DATE_IDX_SECOND = t1 % 60; t1 /= 60; - partsDUK_DATE_IDX_MINUTE = t1 % 60; t1 /= 60; + partsDUK_DATE_IDX_MILLISECOND = t1 % 1000; + t1 /= 1000; + partsDUK_DATE_IDX_SECOND = t1 % 60; + t1 /= 60; + partsDUK_DATE_IDX_MINUTE = t1 % 60; + t1 /= 60; partsDUK_DATE_IDX_HOUR = t1; DUK_ASSERT(partsDUK_DATE_IDX_MILLISECOND >= 0 && partsDUK_DATE_IDX_MILLISECOND <= 999); DUK_ASSERT(partsDUK_DATE_IDX_SECOND >= 0 && partsDUK_DATE_IDX_SECOND <= 59); @@ -32401,7 +33377,11 @@ DUK_ASSERT(partsDUK_DATE_IDX_HOUR >= 0 && partsDUK_DATE_IDX_HOUR <= 23); DUK_DDD(DUK_DDDPRINT("d=%lf, d1=%lf, d2=%lf, t1=%ld, t2=%ld, parts: hour=%ld min=%ld sec=%ld msec=%ld", - (double) d, (double) d1, (double) d2, (long) t1, (long) t2, + (double) d, + (double) d1, + (double) d2, + (long) t1, + (long) t2, (long) partsDUK_DATE_IDX_HOUR, (long) partsDUK_DATE_IDX_MINUTE, (long) partsDUK_DATE_IDX_SECOND, @@ -32411,7 +33391,7 @@ * the ECMAScript range. */ DUK_ASSERT(t2 + DUK__WEEKDAY_MOD_ADDER >= 0); - partsDUK_DATE_IDX_WEEKDAY = (t2 + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ + partsDUK_DATE_IDX_WEEKDAY = (t2 + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ DUK_ASSERT(partsDUK_DATE_IDX_WEEKDAY >= 0 && partsDUK_DATE_IDX_WEEKDAY <= 6); year = duk__year_from_day(t2, &day_in_year); @@ -32422,8 +33402,7 @@ if (month == 1 && is_leap) { dim++; } - DUK_DDD(DUK_DDDPRINT("month=%ld, dim=%ld, day=%ld", - (long) month, (long) dim, (long) day)); + DUK_DDD(DUK_DDDPRINT("month=%ld, dim=%ld, day=%ld", (long) month, (long) dim, (long) day)); if (day < dim) { break; } @@ -32448,9 +33427,9 @@ if ((flags & DUK_DATE_FLAG_EQUIVYEAR) && (year < 1971 || year > 2037)) { DUK_ASSERT(is_leap == 0 || is_leap == 1); - jan1_since_epoch = day_since_epoch - day_in_year; /* day number for Jan 1 since epoch */ + jan1_since_epoch = day_since_epoch - day_in_year; /* day number for Jan 1 since epoch */ DUK_ASSERT(jan1_since_epoch + DUK__WEEKDAY_MOD_ADDER >= 0); - jan1_weekday = (jan1_since_epoch + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ + jan1_weekday = (jan1_since_epoch + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ DUK_ASSERT(jan1_weekday >= 0 && jan1_weekday <= 6); arridx = jan1_weekday; if (is_leap) { @@ -32462,8 +33441,12 @@ year = equiv_year; DUK_DDD(DUK_DDDPRINT("equiv year mapping, year=%ld, day_in_year=%ld, day_since_epoch=%ld, " "jan1_since_epoch=%ld, jan1_weekday=%ld -> equiv year %ld", - (long) year, (long) day_in_year, (long) day_since_epoch, - (long) jan1_since_epoch, (long) jan1_weekday, (long) equiv_year)); + (long) year, + (long) day_in_year, + (long) day_since_epoch, + (long) jan1_since_epoch, + (long) jan1_weekday, + (long) equiv_year)); } partsDUK_DATE_IDX_YEAR = year; @@ -32471,8 +33454,8 @@ partsDUK_DATE_IDX_DAY = day; if (flags & DUK_DATE_FLAG_ONEBASED) { - partsDUK_DATE_IDX_MONTH++; /* zero-based -> one-based */ - partsDUK_DATE_IDX_DAY++; /* -""- */ + partsDUK_DATE_IDX_MONTH++; /* zero-based -> one-based */ + partsDUK_DATE_IDX_DAY++; /* -""- */ } if (dparts != NULL) { @@ -32552,8 +33535,7 @@ /* MakeDate */ d = tmp_day * ((duk_double_t) DUK_DATE_MSEC_DAY) + tmp_time; - DUK_DDD(DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf", - (double) tmp_time, (double) tmp_day, (double) d)); + DUK_DDD(DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf", (double) tmp_time, (double) tmp_day, (double) d)); /* Optional UTC conversion. */ if (flags & DUK_DATE_FLAG_LOCALTIME) { @@ -32583,16 +33565,22 @@ /* Iteration solution */ tzoff = 0; - tzoffprev1 = 999999999L; /* invalid value which never matches */ + tzoffprev1 = 999999999L; /* invalid value which never matches */ for (i = 0; i < DUK__LOCAL_TZOFFSET_MAXITER; i++) { tzoffprev2 = tzoffprev1; tzoffprev1 = tzoff; tzoff = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d - tzoff * 1000L); DUK_DDD(DUK_DDDPRINT("tzoffset iteration, i=%d, tzoff=%ld, tzoffprev1=%ld tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); if (tzoff == tzoffprev1) { DUK_DDD(DUK_DDDPRINT("tzoffset iteration finished, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); break; } else if (tzoff == tzoffprev2) { /* Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js. @@ -32600,8 +33588,12 @@ * result which is independent of iteration count. Not sure if * this is a generically correct solution. */ - DUK_DDD(DUK_DDDPRINT("tzoffset iteration two-value cycle, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + DUK_DDD(DUK_DDDPRINT( + "tzoffset iteration two-value cycle, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); if (tzoffprev1 > tzoff) { tzoff = tzoffprev1; } @@ -32632,7 +33624,7 @@ duk_int_t tzoffset = 0; duk_push_this(thr); - h = duk_get_hobject(thr, -1); /* XXX: getter with class check, useful in built-ins */ + h = duk_get_hobject(thr, -1); /* XXX: getter with class check, useful in built-ins */ if (h == NULL || DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_DATE) { DUK_ERROR_TYPE(thr, "expected Date"); DUK_WO_NORETURN(return 0.0;); @@ -32658,7 +33650,7 @@ /* Note: DST adjustment is determined using UTC time. * If 'd' is NaN, tzoffset will be 0. */ - tzoffset = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d); /* seconds */ + tzoffset = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d); /* seconds */ d += tzoffset * 1000L; } if (out_tzoffset) { @@ -32683,8 +33675,8 @@ /* ... this */ d = duk_bi_date_get_timeval_from_dparts(dparts, flags); - duk_push_number(thr, d); /* -> ... this timeval_new */ - duk_dup_top(thr); /* -> ... this timeval_new timeval_new */ + duk_push_number(thr, d); /* -> ... this timeval_new */ + duk_dup_top(thr); /* -> ... this timeval_new timeval_new */ /* Must force write because e.g. .setYear() must work even when * the Date instance is frozen. @@ -32697,8 +33689,8 @@ /* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long. */ DUK_LOCAL void duk__format_parts_iso8601(duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags, duk_uint8_t *out_buf) { - char yearstr8; /* "-123456\0" */ - char tzstr8; /* "+11:22\0" */ + char yearstr8; /* "-123456\0" */ + char tzstr8; /* "+11:22\0" */ char sep = (flags & DUK_DATE_FLAG_SEP_T) ? DUK_ASC_UC_T : DUK_ASC_SPACE; DUK_ASSERT(partsDUK_DATE_IDX_MONTH >= 1 && partsDUK_DATE_IDX_MONTH <= 12); @@ -32710,8 +33702,9 @@ */ DUK_SNPRINTF(yearstr, sizeof(yearstr), - (partsDUK_DATE_IDX_YEAR >= 0 && partsDUK_DATE_IDX_YEAR <= 9999) ? "%04ld" : - ((partsDUK_DATE_IDX_YEAR >= 0) ? "+%06ld" : "%07ld"), + (partsDUK_DATE_IDX_YEAR >= 0 && partsDUK_DATE_IDX_YEAR <= 9999) ? + "%04ld" : + ((partsDUK_DATE_IDX_YEAR >= 0) ? "+%06ld" : "%07ld"), (long) partsDUK_DATE_IDX_YEAR); yearstrsizeof(yearstr) - 1 = (char) 0; @@ -32732,8 +33725,9 @@ tmp = tmp / 60; arg_hours = tmp / 60; arg_minutes = tmp % 60; - DUK_ASSERT(arg_hours <= 24); /* Even less is actually guaranteed for a valid tzoffset. */ - arg_hours = arg_hours & 0x3f; /* For 0,24 this is a no-op, but fixes GCC 7 warning, see https://github.com/svaarala/duktape/issues/1602. */ + DUK_ASSERT(arg_hours <= 24); /* Even less is actually guaranteed for a valid tzoffset. */ + arg_hours = arg_hours & 0x3f; /* For 0,24 this is a no-op, but fixes GCC 7 warning, see + https://github.com/svaarala/duktape/issues/1602. */ DUK_SNPRINTF(tzstr, sizeof(tzstr), fmt, (int) arg_hours, (int) arg_minutes); tzstrsizeof(tzstr) - 1 = (char) 0; @@ -32746,18 +33740,31 @@ * is portable. */ if ((flags & DUK_DATE_FLAG_TOSTRING_DATE) && (flags & DUK_DATE_FLAG_TOSTRING_TIME)) { - DUK_SPRINTF((char *) out_buf, "%s-%02d-%02d%c%02d:%02d:%02d.%03d%s", - (const char *) yearstr, (int) partsDUK_DATE_IDX_MONTH, (int) partsDUK_DATE_IDX_DAY, (int) sep, - (int) partsDUK_DATE_IDX_HOUR, (int) partsDUK_DATE_IDX_MINUTE, - (int) partsDUK_DATE_IDX_SECOND, (int) partsDUK_DATE_IDX_MILLISECOND, (const char *) tzstr); + DUK_SPRINTF((char *) out_buf, + "%s-%02d-%02d%c%02d:%02d:%02d.%03d%s", + (const char *) yearstr, + (int) partsDUK_DATE_IDX_MONTH, + (int) partsDUK_DATE_IDX_DAY, + (int) sep, + (int) partsDUK_DATE_IDX_HOUR, + (int) partsDUK_DATE_IDX_MINUTE, + (int) partsDUK_DATE_IDX_SECOND, + (int) partsDUK_DATE_IDX_MILLISECOND, + (const char *) tzstr); } else if (flags & DUK_DATE_FLAG_TOSTRING_DATE) { - DUK_SPRINTF((char *) out_buf, "%s-%02d-%02d", - (const char *) yearstr, (int) partsDUK_DATE_IDX_MONTH, (int) partsDUK_DATE_IDX_DAY); + DUK_SPRINTF((char *) out_buf, + "%s-%02d-%02d", + (const char *) yearstr, + (int) partsDUK_DATE_IDX_MONTH, + (int) partsDUK_DATE_IDX_DAY); } else { DUK_ASSERT(flags & DUK_DATE_FLAG_TOSTRING_TIME); - DUK_SPRINTF((char *) out_buf, "%02d:%02d:%02d.%03d%s", - (int) partsDUK_DATE_IDX_HOUR, (int) partsDUK_DATE_IDX_MINUTE, - (int) partsDUK_DATE_IDX_SECOND, (int) partsDUK_DATE_IDX_MILLISECOND, + DUK_SPRINTF((char *) out_buf, + "%02d:%02d:%02d.%03d%s", + (int) partsDUK_DATE_IDX_HOUR, + (int) partsDUK_DATE_IDX_MINUTE, + (int) partsDUK_DATE_IDX_SECOND, + (int) partsDUK_DATE_IDX_MILLISECOND, (const char *) tzstr); } } @@ -32769,11 +33776,11 @@ DUK_LOCAL duk_ret_t duk__to_string_helper(duk_hthread *thr, duk_small_uint_t flags) { duk_double_t d; duk_int_t partsDUK_DATE_IDX_NUM_PARTS; - duk_int_t tzoffset; /* seconds, doesn't fit into 16 bits */ + duk_int_t tzoffset; /* seconds, doesn't fit into 16 bits */ duk_bool_t rc; duk_uint8_t bufDUK_BI_DATE_ISO8601_BUFSIZE; - DUK_UNREF(rc); /* unreferenced with some options */ + DUK_UNREF(rc); /* unreferenced with some options */ d = duk__push_this_get_timeval_tzoffset(thr, flags, &tzoffset); if (DUK_ISNAN(d)) { @@ -32825,9 +33832,9 @@ DUK_LOCAL duk_ret_t duk__get_part_helper(duk_hthread *thr, duk_small_uint_t flags_and_idx) { duk_double_t d; duk_int_t partsDUK_DATE_IDX_NUM_PARTS; - duk_small_uint_t idx_part = (duk_small_uint_t) (flags_and_idx >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ + duk_small_uint_t idx_part = (duk_small_uint_t) (flags_and_idx >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ - DUK_ASSERT_DISABLE(idx_part >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx_part >= 0); /* unsigned */ DUK_ASSERT(idx_part < DUK_DATE_IDX_NUM_PARTS); d = duk__push_this_get_timeval(thr, flags_and_idx); @@ -32837,7 +33844,7 @@ } DUK_ASSERT(DUK_ISFINITE(d)); - duk_bi_date_timeval_to_parts(d, parts, NULL, flags_and_idx); /* no need to mask idx portion */ + duk_bi_date_timeval_to_parts(d, parts, NULL, flags_and_idx); /* no need to mask idx portion */ /* Setter APIs detect special year numbers (0...99) and apply a +1900 * only in certain cases. The legacy getYear() getter applies -1900 @@ -32859,7 +33866,7 @@ duk_int_t partsDUK_DATE_IDX_NUM_PARTS; duk_double_t dpartsDUK_DATE_IDX_NUM_PARTS; duk_idx_t nargs; - duk_small_uint_t maxnargs = (duk_small_uint_t) (flags_and_maxnargs >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ + duk_small_uint_t maxnargs = (duk_small_uint_t) (flags_and_maxnargs >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ duk_small_uint_t idx_first, idx; duk_small_uint_t i; @@ -32906,7 +33913,7 @@ DUK_ASSERT(maxnargs >= 1 && maxnargs <= 3); idx_first = DUK_DATE_IDX_DAY - (maxnargs - 1); } - DUK_ASSERT_DISABLE(idx_first >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx_first >= 0); /* unsigned */ DUK_ASSERT(idx_first < DUK_DATE_IDX_NUM_PARTS); for (i = 0; i < maxnargs; i++) { @@ -32915,7 +33922,7 @@ break; } idx = idx_first + i; - DUK_ASSERT_DISABLE(idx >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx >= 0); /* unsigned */ DUK_ASSERT(idx < DUK_DATE_IDX_NUM_PARTS); if (idx == DUK_DATE_IDX_YEAR && (flags_and_maxnargs & DUK_DATE_FLAG_YEAR_FIXUP)) { @@ -32967,7 +33974,7 @@ } duk_dup(thr, idx_val); duk_to_int(thr, -1); - d = duk_get_number(thr, -1); /* get as double to handle huge numbers correctly */ + d = duk_get_number(thr, -1); /* get as double to handle huge numbers correctly */ if (d >= 0.0 && d <= 99.0) { d += 1900.0; duk_push_number(thr, d); @@ -33015,10 +34022,14 @@ } DUK_DDD(DUK_DDDPRINT("parts from args -> %lf %lf %lf %lf %lf %lf %lf %lf", - (double) dparts0, (double) dparts1, - (double) dparts2, (double) dparts3, - (double) dparts4, (double) dparts5, - (double) dparts6, (double) dparts7)); + (double) dparts0, + (double) dparts1, + (double) dparts2, + (double) dparts3, + (double) dparts4, + (double) dparts5, + (double) dparts6, + (double) dparts7)); } /* @@ -33174,9 +34185,8 @@ DUK_DDD(DUK_DDDPRINT("Date constructor, nargs=%ld, is_cons=%ld", (long) nargs, (long) is_cons)); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATE), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATE), DUK_BIDX_DATE_PROTOTYPE); /* Unlike most built-ins, the internal PrimitiveValue of a Date @@ -33198,9 +34208,9 @@ str = duk_get_string_notsymbol(thr, 0); if (str) { duk__parse_string(thr, str); - duk_replace(thr, 0); /* may be NaN */ + duk_replace(thr, 0); /* may be NaN */ } - d = duk__timeclip(duk_to_number(thr, 0)); /* symbols fail here */ + d = duk__timeclip(duk_to_number(thr, 0)); /* symbols fail here */ duk_push_number(thr, d); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_W); return 1; @@ -33210,8 +34220,8 @@ /* Parts are in local time, convert when setting. */ - (void) duk__set_this_timeval_from_dparts(thr, dparts, DUK_DATE_FLAG_LOCALTIME /*flags*/); /* -> ... this timeval */ - duk_pop(thr); /* -> ... this */ + (void) duk__set_this_timeval_from_dparts(thr, dparts, DUK_DATE_FLAG_LOCALTIME /*flags*/); /* -> ... this timeval */ + duk_pop(thr); /* -> ... this */ return 1; } @@ -33242,7 +34252,7 @@ duk_double_t d; d = duk_time_get_ecmascript_time_nofrac(thr); - DUK_ASSERT(duk_double_equals(duk__timeclip(d), d)); /* TimeClip() should never be necessary */ + DUK_ASSERT(duk_double_equals(duk__timeclip(d), d)); /* TimeClip() should never be necessary */ duk_push_number(thr, d); return 1; } @@ -33291,7 +34301,7 @@ * as their behavior is identical. */ - duk_double_t d = duk__push_this_get_timeval(thr, 0 /*flags*/); /* -> this */ + duk_double_t d = duk__push_this_get_timeval(thr, 0 /*flags*/); /* -> this */ DUK_ASSERT(DUK_ISFINITE(d) || DUK_ISNAN(d)); duk_push_number(thr, d); return 1; @@ -33317,7 +34327,7 @@ duk_pop(thr); duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_ISO_STRING); - duk_dup_m2(thr); /* -> O toIsoString O */ + duk_dup_m2(thr); /* -> O toIsoString O */ duk_call_method(thr, 0); return 1; } @@ -33490,8 +34500,7 @@ DUK_ASSERT_TOP(thr, 2); hintstr = duk_require_lstring(thr, 0, &hintlen); - if ((hintlen == 6 && DUK_STRCMP(hintstr, "string") == 0) || - (hintlen == 7 && DUK_STRCMP(hintstr, "default") == 0)) { + if ((hintlen == 6 && DUK_STRCMP(hintstr, "string") == 0) || (hintlen == 7 && DUK_STRCMP(hintstr, "default") == 0)) { hint = DUK_HINT_STRING; } else if (hintlen == 6 && DUK_STRCMP(hintstr, "number") == 0) { hint = DUK_HINT_NUMBER; @@ -33502,9 +34511,9 @@ duk_to_primitive_ordinary(thr, -1, hint); return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ -#endif /* DUK_USE_DATE_BUILTIN */ +#endif /* DUK_USE_DATE_BUILTIN */ /* automatic undefs */ #undef DUK__CF_ACCEPT @@ -33567,8 +34576,8 @@ /* Buffer sizes for some UNIX calls. Larger than strictly necessary * to avoid Valgrind errors. */ -#define DUK__STRPTIME_BUF_SIZE 64 -#define DUK__STRFTIME_BUF_SIZE 64 +#define DUK__STRPTIME_BUF_SIZE 64 +#define DUK__STRFTIME_BUF_SIZE 64 #if defined(DUK_USE_DATE_NOW_GETTIMEOFDAY) /* Get current ECMAScript time (= UNIX/Posix time, but in milliseconds). */ @@ -33582,12 +34591,11 @@ } /* As of Duktape 2.2.0 allow fractions. */ - d = ((duk_double_t) tv.tv_sec) * 1000.0 + - ((duk_double_t) tv.tv_usec) / 1000.0; + d = ((duk_double_t) tv.tv_sec) * 1000.0 + ((duk_double_t) tv.tv_usec) / 1000.0; return d; } -#endif /* DUK_USE_DATE_NOW_GETTIMEOFDAY */ +#endif /* DUK_USE_DATE_NOW_GETTIMEOFDAY */ #if defined(DUK_USE_DATE_NOW_TIME) /* Not a very good provider: only full seconds are available. */ @@ -33601,7 +34609,7 @@ } return ((duk_double_t) t) * 1000.0; } -#endif /* DUK_USE_DATE_NOW_TIME */ +#endif /* DUK_USE_DATE_NOW_TIME */ #if defined(DUK_USE_DATE_TZO_GMTIME) || defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) /* Get local time offset (in seconds) for a certain (UTC) instant 'd'. */ @@ -33684,7 +34692,7 @@ DUK_ASSERT(partsDUK_DATE_IDX_YEAR >= 1970 && partsDUK_DATE_IDX_YEAR <= 2038); d = duk_bi_date_get_timeval_from_dparts(dparts, 0 /*flags*/); - DUK_ASSERT(d >= 0 && d < 2147483648.0 * 1000.0); /* unsigned 31-bit range */ + DUK_ASSERT(d >= 0 && d < 2147483648.0 * 1000.0); /* unsigned 31-bit range */ t = (time_t) (d / 1000.0); DUK_DDD(DUK_DDDPRINT("timeval: %lf -> time_t %ld", (double) d, (long) t)); @@ -33706,14 +34714,26 @@ #endif DUK_DDD(DUK_DDDPRINT("gmtime result: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tms0.tm_sec, (long) tms0.tm_min, (long) tms0.tm_hour, - (long) tms0.tm_mday, (long) tms0.tm_mon, (long) tms0.tm_year, - (long) tms0.tm_wday, (long) tms0.tm_yday, (long) tms0.tm_isdst)); + (long) tms0.tm_sec, + (long) tms0.tm_min, + (long) tms0.tm_hour, + (long) tms0.tm_mday, + (long) tms0.tm_mon, + (long) tms0.tm_year, + (long) tms0.tm_wday, + (long) tms0.tm_yday, + (long) tms0.tm_isdst)); DUK_DDD(DUK_DDDPRINT("localtime result: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tms1.tm_sec, (long) tms1.tm_min, (long) tms1.tm_hour, - (long) tms1.tm_mday, (long) tms1.tm_mon, (long) tms1.tm_year, - (long) tms1.tm_wday, (long) tms1.tm_yday, (long) tms1.tm_isdst)); + (long) tms1.tm_sec, + (long) tms1.tm_min, + (long) tms1.tm_hour, + (long) tms1.tm_mday, + (long) tms1.tm_mon, + (long) tms1.tm_year, + (long) tms1.tm_wday, + (long) tms1.tm_yday, + (long) tms1.tm_isdst)); /* tm_isdst is both an input and an output to mktime(), use 0 to * avoid DST handling in mktime(): @@ -33722,8 +34742,8 @@ */ tms0.tm_isdst = 0; tms1.tm_isdst = 0; - t1 = mktime(&tms0); /* UTC */ - t2 = mktime(&tms1); /* local */ + t1 = mktime(&tms0); /* UTC */ + t2 = mktime(&tms1); /* local */ if (t1 == (time_t) -1 || t2 == (time_t) -1) { /* This check used to be for (t < 0) but on some platforms * time_t is unsigned and apparently the proper way to detect @@ -33746,12 +34766,12 @@ #endif return (duk_int_t) difftime(t2, t1); - mktime_error: +mktime_error: /* XXX: return something more useful, so that caller can throw? */ DUK_D(DUK_DPRINT("mktime() failed, d=%lf", (double) d)); return 0; } -#endif /* DUK_USE_DATE_TZO_GMTIME */ +#endif /* DUK_USE_DATE_TZO_GMTIME */ #if defined(DUK_USE_DATE_PRS_STRPTIME) DUK_INTERNAL duk_bool_t duk_bi_date_parse_string_strptime(duk_hthread *thr, const char *str) { @@ -33761,7 +34781,7 @@ /* Copy to buffer with slack to avoid Valgrind gripes from strptime. */ DUK_ASSERT(str != NULL); - duk_memzero(buf, sizeof(buf)); /* valgrind whine without this */ + duk_memzero(buf, sizeof(buf)); /* valgrind whine without this */ DUK_SNPRINTF(buf, sizeof(buf), "%s", (const char *) str); bufsizeof(buf) - 1 = (char) 0; @@ -33771,10 +34791,16 @@ if (strptime((const char *) buf, "%c", &tm) != NULL) { DUK_DDD(DUK_DDDPRINT("before mktime: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tm.tm_sec, (long) tm.tm_min, (long) tm.tm_hour, - (long) tm.tm_mday, (long) tm.tm_mon, (long) tm.tm_year, - (long) tm.tm_wday, (long) tm.tm_yday, (long) tm.tm_isdst)); - tm.tm_isdst = -1; /* negative: dst info not available */ + (long) tm.tm_sec, + (long) tm.tm_min, + (long) tm.tm_hour, + (long) tm.tm_mday, + (long) tm.tm_mon, + (long) tm.tm_year, + (long) tm.tm_wday, + (long) tm.tm_yday, + (long) tm.tm_isdst)); + tm.tm_isdst = -1; /* negative: dst info not available */ t = mktime(&tm); DUK_DDD(DUK_DDDPRINT("mktime() -> %ld", (long) t)); @@ -33786,7 +34812,7 @@ return 0; } -#endif /* DUK_USE_DATE_PRS_STRPTIME */ +#endif /* DUK_USE_DATE_PRS_STRPTIME */ #if defined(DUK_USE_DATE_PRS_GETDATE) DUK_INTERNAL duk_bool_t duk_bi_date_parse_string_getdate(duk_hthread *thr, const char *str) { @@ -33813,10 +34839,13 @@ return 0; } -#endif /* DUK_USE_DATE_PRS_GETDATE */ +#endif /* DUK_USE_DATE_PRS_GETDATE */ #if defined(DUK_USE_DATE_FMT_STRFTIME) -DUK_INTERNAL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags) { +DUK_INTERNAL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, + duk_int_t *parts, + duk_int_t tzoffset, + duk_small_uint_t flags) { char bufDUK__STRFTIME_BUF_SIZE; struct tm tm; const char *fmt; @@ -33834,8 +34863,7 @@ * probably not an accurate guarantee of strftime() supporting or not * supporting a large time range (the full ECMAScript range). */ - if (sizeof(time_t) < 8 && - (partsDUK_DATE_IDX_YEAR < 1970 || partsDUK_DATE_IDX_YEAR > 2037)) { + if (sizeof(time_t) < 8 && (partsDUK_DATE_IDX_YEAR < 1970 || partsDUK_DATE_IDX_YEAR > 2037)) { /* be paranoid for 32-bit time values (even avoiding negative ones) */ return 0; } @@ -33844,8 +34872,8 @@ tm.tm_sec = partsDUK_DATE_IDX_SECOND; tm.tm_min = partsDUK_DATE_IDX_MINUTE; tm.tm_hour = partsDUK_DATE_IDX_HOUR; - tm.tm_mday = partsDUK_DATE_IDX_DAY; /* already one-based */ - tm.tm_mon = partsDUK_DATE_IDX_MONTH - 1; /* one-based -> zero-based */ + tm.tm_mday = partsDUK_DATE_IDX_DAY; /* already one-based */ + tm.tm_mon = partsDUK_DATE_IDX_MONTH - 1; /* one-based -> zero-based */ tm.tm_year = partsDUK_DATE_IDX_YEAR - 1900; tm.tm_wday = partsDUK_DATE_IDX_WEEKDAY; tm.tm_isdst = 0; @@ -33865,7 +34893,7 @@ duk_push_string(thr, buf); return 1; } -#endif /* DUK_USE_DATE_FMT_STRFTIME */ +#endif /* DUK_USE_DATE_FMT_STRFTIME */ #if defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME) DUK_INTERNAL duk_double_t duk_bi_date_get_monotonic_time_clock_gettime(void) { @@ -33913,20 +34941,20 @@ res->LowPart = ft->dwLowDateTime; res->HighPart = ft->dwHighDateTime; } -#endif /* DUK_USE_DATE_NOW_WINDOWS_SUBMS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS_SUBMS */ DUK_LOCAL void duk__set_systime_jan1970(SYSTEMTIME *st) { duk_memzero((void *) st, sizeof(*st)); st->wYear = 1970; st->wMonth = 1; - st->wDayOfWeek = 4; /* not sure whether or not needed; Thursday */ + st->wDayOfWeek = 4; /* not sure whether or not needed; Thursday */ st->wDay = 1; DUK_ASSERT(st->wHour == 0); DUK_ASSERT(st->wMinute == 0); DUK_ASSERT(st->wSecond == 0); DUK_ASSERT(st->wMilliseconds == 0); } -#endif /* defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS) */ +#endif /* defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS) */ #if defined(DUK_USE_DATE_NOW_WINDOWS) DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows(void) { @@ -33948,7 +34976,7 @@ */ return (duk_double_t) ((LONGLONG) tmp1.QuadPart - (LONGLONG) tmp2.QuadPart) / 10000.0; } -#endif /* DUK_USE_DATE_NOW_WINDOWS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS */ #if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows_subms(void) { @@ -33970,7 +34998,7 @@ */ return (duk_double_t) ((LONGLONG) tmp1.QuadPart - (LONGLONG) tmp2.QuadPart) / 10000.0; } -#endif /* DUK_USE_DATE_NOW_WINDOWS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS */ #if defined(DUK_USE_DATE_TZO_WINDOWS) DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows(duk_double_t d) { @@ -33995,8 +35023,8 @@ duk__set_systime_jan1970(&st1); duk__convert_systime_to_ularge((const SYSTEMTIME *) &st1, &tmp1); - tmp2.QuadPart = (ULONGLONG) (d * 10000.0); /* millisec -> 100ns units since jan 1, 1970 */ - tmp2.QuadPart += tmp1.QuadPart; /* input 'd' in Windows UTC, 100ns units */ + tmp2.QuadPart = (ULONGLONG) (d * 10000.0); /* millisec -> 100ns units since jan 1, 1970 */ + tmp2.QuadPart += tmp1.QuadPart; /* input 'd' in Windows UTC, 100ns units */ ft1.dwLowDateTime = tmp2.LowPart; ft1.dwHighDateTime = tmp2.HighPart; @@ -34011,9 +35039,9 @@ duk__convert_systime_to_ularge((const SYSTEMTIME *) &st3, &tmp3); /* Positive if local time ahead of UTC. */ - return (duk_int_t) (((LONGLONG) tmp3.QuadPart - (LONGLONG) tmp2.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ + return (duk_int_t) (((LONGLONG) tmp3.QuadPart - (LONGLONG) tmp2.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ } -#endif /* DUK_USE_DATE_TZO_WINDOWS */ +#endif /* DUK_USE_DATE_TZO_WINDOWS */ #if defined(DUK_USE_DATE_TZO_WINDOWS_NO_DST) DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows_no_dst(duk_double_t d) { @@ -34048,17 +35076,19 @@ } duk__convert_systime_to_ularge((const SYSTEMTIME *) &st2, &tmp2); - return (duk_int_t) (((LONGLONG) tmp2.QuadPart - (LONGLONG) tmp1.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ + return (duk_int_t) (((LONGLONG) tmp2.QuadPart - (LONGLONG) tmp1.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ } -#endif /* DUK_USE_DATE_TZO_WINDOWS_NO_DST */ +#endif /* DUK_USE_DATE_TZO_WINDOWS_NO_DST */ #if defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC) DUK_INTERNAL duk_double_t duk_bi_date_get_monotonic_time_windows_qpc(void) { LARGE_INTEGER count, freq; /* There are legacy issues with QueryPerformanceCounter(): - * - Potential jumps: https://support.microsoft.com/en-us/help/274323/performance-counter-value-may-unexpectedly-leap-forward - * - Differences between cores (XP): https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions + * - Potential jumps: + * https://support.microsoft.com/en-us/help/274323/performance-counter-value-may-unexpectedly-leap-forward + * - Differences between cores (XP): + * https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions * * We avoid these by enabling QPC by default only for Vista or later. */ @@ -34075,7 +35105,7 @@ return 0.0; } } -#endif /* DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC */ +#endif /* DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC */ /* * Duktape built-ins * @@ -34138,7 +35168,7 @@ return 1; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_duktape_object_enc(duk_hthread *thr) { duk_hstring *h_str; @@ -34148,7 +35178,7 @@ * non-existent optional parameters. */ - h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons. */ + h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons. */ duk_require_valid_index(thr, 1); if (h_str == DUK_HTHREAD_STRING_HEX(thr)) { @@ -34165,9 +35195,8 @@ 1 /*idx_value*/, 2 /*idx_replacer*/, 3 /*idx_space*/, - DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_ASCII_ONLY | - DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); + DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_ASCII_ONLY | + DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); #endif #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JC) } else if (h_str == DUK_HTHREAD_STRING_JC(thr)) { @@ -34175,8 +35204,7 @@ 1 /*idx_value*/, 2 /*idx_replacer*/, 3 /*idx_space*/, - DUK_JSON_FLAG_EXT_COMPATIBLE | - DUK_JSON_FLAG_ASCII_ONLY /*flags*/); + DUK_JSON_FLAG_EXT_COMPATIBLE | DUK_JSON_FLAG_ASCII_ONLY /*flags*/); #endif } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -34192,7 +35220,7 @@ * non-existent optional parameters. */ - h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons */ + h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons */ duk_require_valid_index(thr, 1); if (h_str == DUK_HTHREAD_STRING_HEX(thr)) { @@ -34205,17 +35233,11 @@ DUK_ASSERT_TOP(thr, 2); #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JX) } else if (h_str == DUK_HTHREAD_STRING_JX(thr)) { - duk_bi_json_parse_helper(thr, - 1 /*idx_value*/, - 2 /*idx_replacer*/, - DUK_JSON_FLAG_EXT_CUSTOM /*flags*/); + duk_bi_json_parse_helper(thr, 1 /*idx_value*/, 2 /*idx_replacer*/, DUK_JSON_FLAG_EXT_CUSTOM /*flags*/); #endif #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JC) } else if (h_str == DUK_HTHREAD_STRING_JC(thr)) { - duk_bi_json_parse_helper(thr, - 1 /*idx_value*/, - 2 /*idx_replacer*/, - DUK_JSON_FLAG_EXT_COMPATIBLE /*flags*/); + duk_bi_json_parse_helper(thr, 1 /*idx_value*/, 2 /*idx_replacer*/, DUK_JSON_FLAG_EXT_COMPATIBLE /*flags*/); #endif } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -34230,10 +35252,10 @@ DUK_INTERNAL duk_ret_t duk_bi_duktape_object_compact(duk_hthread *thr) { DUK_ASSERT_TOP(thr, 1); duk_compact(thr, 0); - return 1; /* return the argument object */ + return 1; /* return the argument object */ } -#endif /* DUK_USE_DUKTAPE_BUILTIN */ +#endif /* DUK_USE_DUKTAPE_BUILTIN */ /* * WHATWG Encoding API built-ins * @@ -34248,17 +35270,17 @@ */ typedef struct { - duk_uint8_t *out; /* where to write next byte(s) */ - duk_codepoint_t lead; /* lead surrogate */ + duk_uint8_t *out; /* where to write next byte(s) */ + duk_codepoint_t lead; /* lead surrogate */ } duk__encode_context; typedef struct { /* UTF-8 decoding state */ - duk_codepoint_t codepoint; /* built up incrementally */ - duk_uint8_t upper; /* max value of next byte (decode error otherwise) */ - duk_uint8_t lower; /* min value of next byte (ditto) */ - duk_uint8_t needed; /* how many more bytes we need */ - duk_uint8_t bom_handled; /* BOM seen or no longer expected */ + duk_codepoint_t codepoint; /* built up incrementally */ + duk_uint8_t upper; /* max value of next byte (decode error otherwise) */ + duk_uint8_t lower; /* min value of next byte (ditto) */ + duk_uint8_t needed; /* how many more bytes we need */ + duk_uint8_t bom_handled; /* BOM seen or no longer expected */ /* Decoder configuration */ duk_uint8_t fatal; @@ -34268,9 +35290,9 @@ /* The signed duk_codepoint_t type is used to signal a decoded codepoint * (>= 0) or various other states using negative values. */ -#define DUK__CP_CONTINUE (-1) /* continue to next byte, no completed codepoint */ -#define DUK__CP_ERROR (-2) /* decoding error */ -#define DUK__CP_RETRY (-3) /* decoding error; retry last byte */ +#define DUK__CP_CONTINUE (-1) /* continue to next byte, no completed codepoint */ +#define DUK__CP_ERROR (-2) /* decoding error */ +#define DUK__CP_RETRY (-3) /* decoding error; retry last byte */ /* * Raw helpers for encoding/decoding @@ -34357,7 +35379,7 @@ } else { /* got a codepoint */ duk_codepoint_t ret; - DUK_ASSERT(dec_ctx->codepoint <= 0x10ffffL); /* Decoding rules guarantee. */ + DUK_ASSERT(dec_ctx->codepoint <= 0x10ffffL); /* Decoding rules guarantee. */ ret = dec_ctx->codepoint; dec_ctx->codepoint = 0x0000L; dec_ctx->needed = 0; @@ -34413,7 +35435,8 @@ } else { /* low surrogate */ if (enc_ctx->lead != 0x0000L) { - codepoint = (duk_codepoint_t) (0x010000L + ((enc_ctx->lead - 0xd800L) << 10) + (codepoint - 0xdc00L)); + codepoint = + (duk_codepoint_t) (0x010000L + ((enc_ctx->lead - 0xd800L) << 10) + (codepoint - 0xdc00L)); enc_ctx->lead = 0x0000L; } else { /* unpaired low surrogate */ @@ -34434,7 +35457,7 @@ */ enc_ctx->out += duk_unicode_encode_xutf8((duk_ucodepoint_t) codepoint, enc_ctx->out); } -#endif /* DUK_USE_ENCODING_BUILTINS */ +#endif /* DUK_USE_ENCODING_BUILTINS */ /* Shared helper for buffer-to-string using a TextDecoder() compatible UTF-8 * decoder. @@ -34463,18 +35486,15 @@ duk_push_fixed_buffer_nozero(thr, 0); duk_replace(thr, 0); } - (void) duk_require_buffer_data(thr, 0, &len); /* Need 'len', avoid pointer. */ + (void) duk_require_buffer_data(thr, 0, &len); /* Need 'len', avoid pointer. */ - if (duk_check_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_NONE)) { + if (duk_check_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_NONE)) { /* Use defaults, treat missing value like undefined. */ } else { - duk_require_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_OBJECT); + duk_require_type_mask(thr, + 1, + DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_LIGHTFUNC | + DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_OBJECT); if (duk_get_prop_literal(thr, 1, "stream")) { stream = duk_to_boolean(thr, -1); } @@ -34492,7 +35512,8 @@ DUK_ERROR_TYPE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return 0;); } - output = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, 3 + (3 * len)); /* used parts will be always manually written over */ + output = + (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, 3 + (3 * len)); /* used parts will be always manually written over */ input = (const duk_uint8_t *) duk_get_buffer_data(thr, 0, &len_tmp); DUK_ASSERT(input != NULL || len == 0); @@ -34524,7 +35545,7 @@ /* Decoding error with or without retry. */ DUK_ASSERT(codepoint == DUK__CP_ERROR || codepoint == DUK__CP_RETRY); if (codepoint == DUK__CP_RETRY) { - --in; /* retry last byte */ + --in; /* retry last byte */ } /* replacement mode: replace with U+FFFD */ codepoint = DUK_UNICODE_CP_REPLACEMENT_CHARACTER; @@ -34557,7 +35578,7 @@ DUK_ASSERT(out <= output + (3 + (3 * len))); } } - duk__utf8_decode_init(dec_ctx); /* Initialize decoding state for potential reuse. */ + duk__utf8_decode_init(dec_ctx); /* Initialize decoding state for potential reuse. */ } /* Output buffer is fixed and thus stable even if there had been @@ -34566,7 +35587,7 @@ duk_push_lstring(thr, (const char *) output, (duk_size_t) (out - output)); return 1; - fail_type: +fail_type: DUK_ERROR_TYPE(thr, DUK_STR_UTF8_DECODE_FAILED); DUK_WO_NORETURN(return 0;); } @@ -34625,7 +35646,7 @@ output = (duk_uint8_t *) duk_push_dynamic_buffer(thr, 3 * len); if (len > 0) { - DUK_ASSERT(duk_is_string(thr, 0)); /* True if len > 0. */ + DUK_ASSERT(duk_is_string(thr, 0)); /* True if len > 0. */ /* XXX: duk_decode_string() is used to process the input * string. For standard ECMAScript strings, represented @@ -34701,7 +35722,7 @@ dec_ctx = (duk__decode_context *) duk_push_fixed_buffer(thr, sizeof(duk__decode_context)); dec_ctx->fatal = (duk_uint8_t) fatal; dec_ctx->ignore_bom = (duk_uint8_t) ignore_bom; - duk__utf8_decode_init(dec_ctx); /* Initializes remaining fields. */ + duk__utf8_decode_init(dec_ctx); /* Initializes remaining fields. */ duk_put_prop_literal(thr, -2, DUK_INTERNAL_SYMBOL("Context")); return 0; @@ -34747,7 +35768,7 @@ dec_ctx = duk__get_textdecoder_context(thr); return duk__decode_helper(thr, dec_ctx); } -#endif /* DUK_USE_ENCODING_BUILTINS */ +#endif /* DUK_USE_ENCODING_BUILTINS */ /* * Internal helper for Node.js Buffer @@ -34761,8 +35782,8 @@ DUK_INTERNAL duk_ret_t duk_textdecoder_decode_utf8_nodejs(duk_hthread *thr) { duk__decode_context dec_ctx; - dec_ctx.fatal = 0; /* use replacement chars */ - dec_ctx.ignore_bom = 1; /* ignore BOMs (matches Node.js Buffer .toString()) */ + dec_ctx.fatal = 0; /* use replacement chars */ + dec_ctx.ignore_bom = 1; /* ignore BOMs (matches Node.js Buffer .toString()) */ duk__utf8_decode_init(&dec_ctx); return duk__decode_helper(thr, &dec_ctx); @@ -34789,9 +35810,8 @@ duk_small_int_t bidx_prototype = duk_get_current_magic(thr); /* same for both error and each subclass like TypeError */ - duk_uint_t flags_and_class = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR); + duk_uint_t flags_and_class = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR); (void) duk_push_object_helper(thr, flags_and_class, bidx_prototype); @@ -34800,7 +35820,7 @@ */ if (!duk_is_undefined(thr, 0)) { duk_to_string(thr, 0); - duk_dup_0(thr); /* message error message */ + duk_dup_0(thr); /* message error message */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC); } @@ -34859,7 +35879,7 @@ return 1; } duk_push_literal(thr, ": "); - duk_insert(thr, -2); /* ... name ': ' message */ + duk_insert(thr, -2); /* ... name ': ' message */ duk_concat(thr, 3); return 1; @@ -34882,15 +35902,15 @@ */ /* constants arbitrary, chosen for small loads */ -#define DUK__OUTPUT_TYPE_TRACEBACK (-1) -#define DUK__OUTPUT_TYPE_FILENAME 0 -#define DUK__OUTPUT_TYPE_LINENUMBER 1 +#define DUK__OUTPUT_TYPE_TRACEBACK (-1) +#define DUK__OUTPUT_TYPE_FILENAME 0 +#define DUK__OUTPUT_TYPE_LINENUMBER 1 DUK_LOCAL duk_ret_t duk__error_getter_helper(duk_hthread *thr, duk_small_int_t output_type) { duk_idx_t idx_td; - duk_small_int_t i; /* traceback depth fits into 16 bits */ - duk_small_int_t t; /* stack type fits into 16 bits */ - duk_small_int_t count_func = 0; /* traceback depth ensures fits into 16 bits */ + duk_small_int_t i; /* traceback depth fits into 16 bits */ + duk_small_int_t t; /* stack type fits into 16 bits */ + duk_small_int_t count_func = 0; /* traceback depth ensures fits into 16 bits */ const char *str_tailcall = " tailcall"; const char *str_strict = " strict"; const char *str_construct = " construct"; @@ -34898,7 +35918,7 @@ const char *str_directeval = " directeval"; const char *str_empty = ""; - DUK_ASSERT_TOP(thr, 0); /* fixed arg count */ + DUK_ASSERT_TOP(thr, 0); /* fixed arg count */ duk_push_this(thr); duk_xget_owndataprop_stridx_short(thr, -1, DUK_STRIDX_INT_TRACEDATA); @@ -34913,7 +35933,7 @@ if (duk_check_type(thr, idx_td, DUK_TYPE_OBJECT)) { /* Current tracedata contains 2 entries per callstack entry. */ - for (i = 0; ; i += 2) { + for (i = 0;; i += 2) { duk_int_t pc; duk_uint_t line; duk_uint_t flags; @@ -34969,46 +35989,53 @@ /* XXX: Change 'anon' handling here too, to use empty string for anonymous functions? */ /* XXX: Could be improved by coercing to a readable duk_tval (especially string escaping) */ - h_name = duk_get_hstring_notsymbol(thr, -2); /* may be NULL */ + h_name = duk_get_hstring_notsymbol(thr, -2); /* may be NULL */ funcname = (h_name == NULL || h_name == DUK_HTHREAD_STRING_EMPTY_STRING(thr)) ? - "anon" : (const char *) DUK_HSTRING_GET_DATA(h_name); + "anon" : + (const char *) DUK_HSTRING_GET_DATA(h_name); filename = duk_get_string_notsymbol(thr, -1); filename = filename ? filename : ""; DUK_ASSERT(funcname != NULL); DUK_ASSERT(filename != NULL); - h_func = duk_get_hobject(thr, -4); /* NULL for lightfunc */ + h_func = duk_get_hobject(thr, -4); /* NULL for lightfunc */ if (h_func == NULL) { - duk_push_sprintf(thr, "at %s light%s%s%s%s%s", - (const char *) funcname, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s light%s%s%s%s%s", + (const char *) funcname, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } else if (DUK_HOBJECT_HAS_NATFUNC(h_func)) { - duk_push_sprintf(thr, "at %s (%s) native%s%s%s%s%s", - (const char *) funcname, - (const char *) filename, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s (%s) native%s%s%s%s%s", + (const char *) funcname, + (const char *) filename, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } else { - duk_push_sprintf(thr, "at %s (%s:%lu)%s%s%s%s%s", - (const char *) funcname, - (const char *) filename, - (unsigned long) line, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s (%s:%lu)%s%s%s%s%s", + (const char *) funcname, + (const char *) filename, + (unsigned long) line, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } - duk_replace(thr, -5); /* ... v1 v2 name filename str -> ... str v2 name filename */ - duk_pop_3(thr); /* -> ... str */ + duk_replace(thr, -5); /* ... v1 v2 name filename str -> ... str v2 name filename */ + duk_pop_3(thr); /* -> ... str */ } else if (t == DUK_TYPE_STRING) { const char *str_file; @@ -35039,10 +36066,12 @@ * safety issues. */ str_file = (const char *) duk_get_string(thr, -2); - duk_push_sprintf(thr, "at anon (%s:%ld) internal", - (const char *) (str_file ? str_file : "null"), (long) pc); - duk_replace(thr, -3); /* ... v1 v2 str -> ... str v2 */ - duk_pop(thr); /* -> ... str */ + duk_push_sprintf(thr, + "at anon (%s:%ld) internal", + (const char *) (str_file ? str_file : "null"), + (long) pc); + duk_replace(thr, -3); /* ... v1 v2 str -> ... str v2 */ + duk_pop(thr); /* -> ... str */ } else { /* unknown, ignore */ duk_pop_2(thr); @@ -35089,7 +36118,7 @@ return duk__error_getter_helper(thr, DUK__OUTPUT_TYPE_LINENUMBER); } -#else /* DUK_USE_TRACEBACKS */ +#else /* DUK_USE_TRACEBACKS */ /* * Traceback handling when tracebacks disabled. @@ -35120,7 +36149,7 @@ return 0; } -#endif /* DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_TRACEBACKS */ DUK_LOCAL duk_ret_t duk__error_setter_helper(duk_hthread *thr, duk_small_uint_t stridx_key) { /* Attempt to write 'stack', 'fileName', 'lineNumber' works as if @@ -35130,7 +36159,7 @@ * See https://github.com/svaarala/duktape/issues/387. */ - DUK_ASSERT_TOP(thr, 1); /* fixed arg count: value */ + DUK_ASSERT_TOP(thr, 1); /* fixed arg count: value */ duk_push_this(thr); duk_push_hstring_stridx(thr, stridx_key); @@ -35138,13 +36167,13 @@ /* ... obj key value */ - DUK_DD(DUK_DDPRINT("error setter: %!T %!T %!T", - duk_get_tval(thr, -3), duk_get_tval(thr, -2), duk_get_tval(thr, -1))); + DUK_DD(DUK_DDPRINT("error setter: %!T %!T %!T", duk_get_tval(thr, -3), duk_get_tval(thr, -2), duk_get_tval(thr, -1))); - duk_def_prop(thr, -3, DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE | - DUK_DEFPROP_HAVE_ENUMERABLE | /*not enumerable*/ - DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE); + duk_def_prop(thr, + -3, + DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE | + DUK_DEFPROP_HAVE_ENUMERABLE | /*not enumerable*/ + DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE); return 0; } @@ -35191,7 +36220,7 @@ nargs = duk_get_top(thr); for (i = 0; i < nargs; i++) { - duk_to_string(thr, i); /* Rejects Symbols during coercion. */ + duk_to_string(thr, i); /* Rejects Symbols during coercion. */ } if (nargs == 0) { @@ -35201,7 +36230,7 @@ /* XXX: cover this with the generic >1 case? */ duk_push_hstring_empty(thr); } else { - duk_insert(thr, 0); /* arg1 ... argN-1 body -> body arg1 ... argN-1 */ + duk_insert(thr, 0); /* arg1 ... argN-1 body -> body arg1 ... argN-1 */ duk_push_literal(thr, ","); duk_insert(thr, 1); duk_join(thr, nargs - 1); @@ -35218,7 +36247,7 @@ duk_dup_1(thr); duk_push_literal(thr, "){"); duk_dup_0(thr); - duk_push_literal(thr, "\n}"); /* Newline is important to handle trailing // comment. */ + duk_push_literal(thr, "\n}"); /* Newline is important to handle trailing // comment. */ duk_concat(thr, 5); /* body formals source */ @@ -35228,8 +36257,8 @@ /* strictness is not inherited, intentional */ comp_flags = DUK_COMPILE_FUNCEXPR; - duk_push_hstring_stridx(thr, DUK_STRIDX_COMPILE); /* XXX: copy from caller? */ /* XXX: ignored now */ - h_sourcecode = duk_require_hstring(thr, -2); /* no symbol check needed; -2 is concat'd code */ + duk_push_hstring_stridx(thr, DUK_STRIDX_COMPILE); /* XXX: copy from caller? */ /* XXX: ignored now */ + h_sourcecode = duk_require_hstring(thr, -2); /* no symbol check needed; -2 is concat'd code */ duk_js_compile(thr, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_sourcecode), (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sourcecode), @@ -35258,7 +36287,7 @@ return 1; } -#endif /* DUK_USE_FUNCTION_BUILTIN */ +#endif /* DUK_USE_FUNCTION_BUILTIN */ #if defined(DUK_USE_FUNCTION_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_function_prototype_to_string(duk_hthread *thr) { @@ -35324,7 +36353,7 @@ return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } #endif @@ -35366,7 +36395,7 @@ */ DUK_INTERNAL duk_ret_t duk_bi_function_prototype_bind(duk_hthread *thr) { duk_hboundfunc *h_bound; - duk_idx_t nargs; /* bound args, not counting 'this' binding */ + duk_idx_t nargs; /* bound args, not counting 'this' binding */ duk_idx_t bound_nargs; duk_int_t bound_len; duk_tval *tv_prevbound; @@ -35379,7 +36408,7 @@ /* Vararg function, careful arg handling, e.g. thisArg may not * be present. */ - nargs = duk_get_top(thr) - 1; /* actual args, not counting 'this' binding */ + nargs = duk_get_top(thr) - 1; /* actual args, not counting 'this' binding */ if (nargs < 0) { nargs++; duk_push_undefined(thr); @@ -35474,7 +36503,7 @@ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) h_bound, bound_proto); } - DUK_TVAL_INCREF(thr, &h_bound->target); /* old values undefined, no decref needed */ + DUK_TVAL_INCREF(thr, &h_bound->target); /* old values undefined, no decref needed */ DUK_TVAL_INCREF(thr, &h_bound->this_binding); bound_nargs = n_prevbound + nargs; @@ -35499,7 +36528,7 @@ * For lightfuncs, simply read the virtual property. */ duk_get_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH); - bound_len = duk_get_int(thr, -1); /* ES2015: no coercion */ + bound_len = duk_get_int(thr, -1); /* ES2015: no coercion */ if (bound_len < nargs) { bound_len = 0; } else { @@ -35513,8 +36542,8 @@ tv_tmp = thr->valstack_top++; DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_tmp)); DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_tmp)); - DUK_TVAL_SET_U32(tv_tmp, (duk_uint32_t) bound_len); /* in-place update, fastint */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* attrs in E6 Section 9.2.4 */ + DUK_TVAL_SET_U32(tv_tmp, (duk_uint32_t) bound_len); /* in-place update, fastint */ + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* attrs in E6 Section 9.2.4 */ /* XXX: could these be virtual? */ /* Caller and arguments must use the same thrower, ThrowTypeError. */ @@ -35522,7 +36551,7 @@ duk_xdef_prop_stridx_thrower(thr, -1, DUK_STRIDX_LC_ARGUMENTS); /* Function name and fileName (non-standard). */ - duk_push_literal(thr, "bound "); /* ES2015 19.2.3.2. */ + duk_push_literal(thr, "bound "); /* ES2015 19.2.3.2. */ duk_get_prop_stridx(thr, -3, DUK_STRIDX_NAME); if (!duk_is_string_notsymbol(thr, -1)) { /* ES2015 has requirement to check that .name of target is a string @@ -35543,7 +36572,7 @@ return 1; } -#endif /* DUK_USE_FUNCTION_BUILTIN */ +#endif /* DUK_USE_FUNCTION_BUILTIN */ /* %NativeFunctionPrototype% .length getter. */ DUK_INTERNAL duk_ret_t duk_bi_native_function_length(duk_hthread *thr) { @@ -35574,7 +36603,7 @@ } return 1; - fail_type: +fail_type: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -35603,7 +36632,7 @@ } return 1; - fail_type: +fail_type: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -35616,7 +36645,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ /* * Global object built-ins */ @@ -35635,73 +36664,71 @@ /* Macros for creating and checking bitmasks for character encoding. * Bit number is a bit counterintuitive, but minimizes code size. */ -#define DUK__MKBITS(a,b,c,d,e,f,g,h) ((duk_uint8_t) ( \ - ((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | \ - ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7) \ - )) -#define DUK__CHECK_BITMASK(table,cp) ((table)(cp) >> 3 & (1 << ((cp) & 0x07))) +#define DUK__MKBITS(a, b, c, d, e, f, g, h) \ + ((duk_uint8_t) (((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7))) +#define DUK__CHECK_BITMASK(table, cp) ((table)(cp) >> 3 & (1 << ((cp) &0x07))) /* E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#' */ DUK_LOCAL const duk_uint8_t duk__encode_uriunescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 1, 0, 1, 1, 0, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 1, 0, 1, 1, 0, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.4: uriUnescaped */ DUK_LOCAL const duk_uint8_t duk__encode_uricomponent_unescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 1, 0, 0, 0, 0, 0, 1), DUK__MKBITS(1, 1, 1, 0, 0, 1, 1, 0), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 1, 0, 0, 0, 0, 0, 1), DUK__MKBITS(1, 1, 1, 0, 0, 1, 1, 0), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.1: uriReserved + '#' */ DUK_LOCAL const duk_uint8_t duk__decode_uri_reserved_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 1, 1, 0, 1, 0), DUK__MKBITS(0, 0, 0, 1, 1, 0, 0, 1), /* 0x20-0x2f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ - DUK__MKBITS(1, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 1, 1, 0, 1, 0), DUK__MKBITS(0, 0, 0, 1, 1, 0, 0, 1), /* 0x20-0x2f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ + DUK__MKBITS(1, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.2: empty */ DUK_LOCAL const duk_uint8_t duk__decode_uri_component_reserved_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x20-0x2f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x20-0x2f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ }; #if defined(DUK_USE_SECTION_B) /* E5.1 Section B.2.2, step 7. */ DUK_LOCAL const duk_uint8_t duk__escape_unescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 1, 1), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 0) /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 1, 1), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 0) /* 0x70-0x7f */ }; -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ typedef struct { duk_hthread *thr; @@ -35742,7 +36769,7 @@ tfm_ctx->h_str = duk_to_hstring(thr, 0); DUK_ASSERT(tfm_ctx->h_str != NULL); - DUK_BW_INIT_PUSHBUF(thr, &tfm_ctx->bw, DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str)); /* initial size guess */ + DUK_BW_INIT_PUSHBUF(thr, &tfm_ctx->bw, DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str)); /* initial size guess */ tfm_ctx->p_start = DUK_HSTRING_GET_DATA(tfm_ctx->h_str); tfm_ctx->p_end = tfm_ctx->p_start + DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str); @@ -35755,7 +36782,7 @@ DUK_BW_COMPACT(thr, &tfm_ctx->bw); - (void) duk_buffer_to_string(thr, -1); /* Safe if transform is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if transform is safe. */ return 1; } @@ -35781,7 +36808,11 @@ goto uri_error; } else if (cp >= 0xd800L && cp <= 0xdbffL) { /* Needs lookahead */ - if (duk_unicode_decode_xutf8(tfm_ctx->thr, &tfm_ctx->p, tfm_ctx->p_start, tfm_ctx->p_end, (duk_ucodepoint_t *) &cp2) == 0) { + if (duk_unicode_decode_xutf8(tfm_ctx->thr, + &tfm_ctx->p, + tfm_ctx->p_start, + tfm_ctx->p_end, + (duk_ucodepoint_t *) &cp2) == 0) { goto uri_error; } if (!(cp2 >= 0xdc00L && cp2 <= 0xdfffL)) { @@ -35812,12 +36843,12 @@ &tfm_ctx->bw, DUK_ASC_PERCENT, (duk_uint8_t) duk_uc_nybblest >> 4, - (duk_uint8_t) duk_uc_nybblest & 0x0f); + (duk_uint8_t) duk_uc_nybblest & 0x0f); } return; - uri_error: +uri_error: DUK_ERROR_URI(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -35826,7 +36857,7 @@ const duk_uint8_t *reserved_table = (const duk_uint8_t *) udata; duk_small_uint_t utf8_blen; duk_codepoint_t min_cp; - duk_small_int_t t; /* must be signed */ + duk_small_int_t t; /* must be signed */ duk_small_uint_t i; /* Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH, @@ -35834,12 +36865,12 @@ */ DUK_BW_ENSURE(tfm_ctx->thr, &tfm_ctx->bw, - (DUK_UNICODE_MAX_XUTF8_LENGTH >= 2 * DUK_UNICODE_MAX_CESU8_BMP_LENGTH ? - DUK_UNICODE_MAX_XUTF8_LENGTH : DUK_UNICODE_MAX_CESU8_BMP_LENGTH)); + (DUK_UNICODE_MAX_XUTF8_LENGTH >= 2 * DUK_UNICODE_MAX_CESU8_BMP_LENGTH ? DUK_UNICODE_MAX_XUTF8_LENGTH : + DUK_UNICODE_MAX_CESU8_BMP_LENGTH)); if (cp == (duk_codepoint_t) '%') { const duk_uint8_t *p = tfm_ctx->p; - duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ + duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ DUK_DDD(DUK_DDDPRINT("percent encoding, left=%ld", (long) left)); @@ -35857,11 +36888,7 @@ if (DUK__CHECK_BITMASK(reserved_table, t)) { /* decode '%xx' to '%xx' if decoded char in reserved set */ DUK_ASSERT(tfm_ctx->p - 1 >= tfm_ctx->p_start); - DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr, - &tfm_ctx->bw, - DUK_ASC_PERCENT, - p0, - p1); + DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr, &tfm_ctx->bw, DUK_ASC_PERCENT, p0, p1); } else { DUK_BW_WRITE_RAW_U8(tfm_ctx->thr, &tfm_ctx->bw, (duk_uint8_t) t); } @@ -35912,7 +36939,10 @@ /* p points to digit part ('%xy', p points to 'x') */ t = duk__decode_hex_escape(p, 2); DUK_DDD(DUK_DDDPRINT("i=%ld utf8_blen=%ld cp=%ld t=0x%02lx", - (long) i, (long) utf8_blen, (long) cp, (unsigned long) t)); + (long) i, + (long) utf8_blen, + (long) cp, + (unsigned long) t)); if (t < 0) { goto uri_error; } @@ -35922,7 +36952,7 @@ cp = (cp << 6) + (t & 0x3f); p += 3; } - p--; /* p overshoots */ + p--; /* p overshoots */ tfm_ctx->p = p; DUK_DDD(DUK_DDDPRINT("final cp=%ld, min_cp=%ld", (long) cp, (long) min_cp)); @@ -35956,7 +36986,7 @@ } return; - uri_error: +uri_error: DUK_ERROR_URI(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -35997,7 +37027,7 @@ return; - esc_error: +esc_error: DUK_ERROR_TYPE(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -36009,14 +37039,12 @@ if (cp == (duk_codepoint_t) '%') { const duk_uint8_t *p = tfm_ctx->p; - duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ + duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ - if (left >= 5 && p0 == 'u' && - ((t = duk__decode_hex_escape(p + 1, 4)) >= 0)) { + if (left >= 5 && p0 == 'u' && ((t = duk__decode_hex_escape(p + 1, 4)) >= 0)) { cp = (duk_codepoint_t) t; tfm_ctx->p += 5; - } else if (left >= 2 && - ((t = duk__decode_hex_escape(p, 2)) >= 0)) { + } else if (left >= 2 && ((t = duk__decode_hex_escape(p, 2)) >= 0)) { cp = (duk_codepoint_t) t; tfm_ctx->p += 2; } @@ -36024,7 +37052,7 @@ DUK_BW_WRITE_ENSURE_XUTF8(tfm_ctx->thr, &tfm_ctx->bw, cp); } -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ /* * Eval @@ -36049,11 +37077,11 @@ duk_int_t level = -2; duk_small_uint_t call_flags; - DUK_ASSERT(duk_get_top(thr) == 1 || duk_get_top(thr) == 2); /* 2 when called by debugger */ - DUK_ASSERT(thr->callstack_top >= 1); /* at least this function exists */ + DUK_ASSERT(duk_get_top(thr) == 1 || duk_get_top(thr) == 2); /* 2 when called by debugger */ + DUK_ASSERT(thr->callstack_top >= 1); /* at least this function exists */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT((thr->callstack_curr->flags & DUK_ACT_FLAG_DIRECT_EVAL) == 0 || /* indirect eval */ - (thr->callstack_top >= 2)); /* if direct eval, calling activation must exist */ + (thr->callstack_top >= 2)); /* if direct eval, calling activation must exist */ /* * callstack_top - 1 --> this function @@ -36066,32 +37094,31 @@ h = duk_get_hstring_notsymbol(thr, 0); if (!h) { /* Symbol must be returned as is, like any non-string values. */ - return 1; /* return arg as-is */ + return 1; /* return arg as-is */ } #if defined(DUK_USE_DEBUGGER_SUPPORT) /* NOTE: level is used only by the debugger and should never be present * for an ECMAScript eval(). */ - DUK_ASSERT(level == -2); /* by default, use caller's environment */ + DUK_ASSERT(level == -2); /* by default, use caller's environment */ if (duk_get_top(thr) >= 2 && duk_is_number(thr, 1)) { level = duk_get_int(thr, 1); } - DUK_ASSERT(level <= -2); /* This is guaranteed by debugger code. */ + DUK_ASSERT(level <= -2); /* This is guaranteed by debugger code. */ #endif /* source */ comp_flags = DUK_COMPILE_EVAL; - act_eval = thr->callstack_curr; /* this function */ + act_eval = thr->callstack_curr; /* this function */ DUK_ASSERT(act_eval != NULL); act_caller = duk_hthread_get_activation_for_level(thr, level); if (act_caller != NULL) { /* Have a calling activation, check for direct eval (otherwise * assume indirect eval. */ - if ((act_caller->flags & DUK_ACT_FLAG_STRICT) && - (act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL)) { + if ((act_caller->flags & DUK_ACT_FLAG_STRICT) && (act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL)) { /* Only direct eval inherits strictness from calling code * (E5.1 Section 10.1.1). */ @@ -36101,11 +37128,8 @@ DUK_ASSERT((act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL) == 0); } - duk_push_hstring_stridx(thr, DUK_STRIDX_INPUT); /* XXX: copy from caller? */ - duk_js_compile(thr, - (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), - (duk_size_t) DUK_HSTRING_GET_BYTELEN(h), - comp_flags); + duk_push_hstring_stridx(thr, DUK_STRIDX_INPUT); /* XXX: copy from caller? */ + duk_js_compile(thr, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), (duk_size_t) DUK_HSTRING_GET_BYTELEN(h), comp_flags); func = (duk_hcompfunc *) duk_known_hobject(thr, -1); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) func)); @@ -36138,9 +37162,9 @@ act_lex_env = act_caller->lex_env; - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); @@ -36152,7 +37176,7 @@ outer_lex_env = (duk_hobject *) new_env; outer_var_env = (duk_hobject *) new_env; - duk_insert(thr, 0); /* stash to bottom of value stack to keep new_env reachable for duration of eval */ + duk_insert(thr, 0); /* stash to bottom of value stack to keep new_env reachable for duration of eval */ /* compiler's responsibility */ DUK_ASSERT(DUK_HOBJECT_HAS_NEWENV((duk_hobject *) func)); @@ -36188,7 +37212,8 @@ duk_tval *tv; DUK_ASSERT(thr->callstack_top >= 2); DUK_ASSERT(act_caller != NULL); - tv = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act_caller->bottom_byteoff - sizeof(duk_tval)); /* this is just beneath bottom */ + tv = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act_caller->bottom_byteoff - + sizeof(duk_tval)); /* this is just beneath bottom */ DUK_ASSERT(tv >= thr->valstack); duk_push_tval(thr, tv); } @@ -36227,19 +37252,15 @@ duk_small_uint_t s2n_flags; DUK_ASSERT_TOP(thr, 2); - duk_to_string(thr, 0); /* Reject symbols. */ + duk_to_string(thr, 0); /* Reject symbols. */ radix = duk_to_int32(thr, 1); /* While parseInt() recognizes 0xdeadbeef, it doesn't recognize * ES2015 0o123 or 0b10001. */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_GARBAGE | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO | - DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_GARBAGE | DUK_S2N_FLAG_ALLOW_PLUS | DUK_S2N_FLAG_ALLOW_MINUS | + DUK_S2N_FLAG_ALLOW_LEADING_ZERO | DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT; /* Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT. * @@ -36263,35 +37284,28 @@ duk_numconv_parse(thr, (duk_small_int_t) radix, s2n_flags); return 1; - ret_nan: +ret_nan: duk_push_nan(thr); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ #if defined(DUK_USE_GLOBAL_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_global_object_parse_float(duk_hthread *thr) { duk_small_uint_t s2n_flags; DUK_ASSERT_TOP(thr, 1); - duk_to_string(thr, 0); /* Reject symbols. */ + duk_to_string(thr, 0); /* Reject symbols. */ /* XXX: check flags */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_GARBAGE | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_INF | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_GARBAGE | DUK_S2N_FLAG_ALLOW_PLUS | + DUK_S2N_FLAG_ALLOW_MINUS | DUK_S2N_FLAG_ALLOW_INF | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_LEADING_ZERO; duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ /* * Number checkers @@ -36303,7 +37317,7 @@ duk_push_boolean(thr, (duk_bool_t) DUK_ISNAN(d)); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ #if defined(DUK_USE_GLOBAL_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_global_object_is_finite(duk_hthread *thr) { @@ -36311,7 +37325,7 @@ duk_push_boolean(thr, (duk_bool_t) DUK_ISFINITE(d)); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ /* * URI handling @@ -36323,7 +37337,9 @@ } DUK_INTERNAL duk_ret_t duk_bi_global_object_decode_uri_component(duk_hthread *thr) { - return duk__transform_helper(thr, duk__transform_callback_decode_uri, (const void *) duk__decode_uri_component_reserved_table); + return duk__transform_helper(thr, + duk__transform_callback_decode_uri, + (const void *) duk__decode_uri_component_reserved_table); } DUK_INTERNAL duk_ret_t duk_bi_global_object_encode_uri(duk_hthread *thr) { @@ -36331,7 +37347,9 @@ } DUK_INTERNAL duk_ret_t duk_bi_global_object_encode_uri_component(duk_hthread *thr) { - return duk__transform_helper(thr, duk__transform_callback_encode_uri, (const void *) duk__encode_uricomponent_unescaped_table); + return duk__transform_helper(thr, + duk__transform_callback_encode_uri, + (const void *) duk__encode_uricomponent_unescaped_table); } #if defined(DUK_USE_SECTION_B) @@ -36342,8 +37360,8 @@ DUK_INTERNAL duk_ret_t duk_bi_global_object_unescape(duk_hthread *thr) { return duk__transform_helper(thr, duk__transform_callback_unescape, (const void *) NULL); } -#endif /* DUK_USE_SECTION_B */ -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ /* automatic undefs */ #undef DUK__CHECK_BITMASK @@ -36372,11 +37390,11 @@ * Local defines and forward declarations. */ -#define DUK__JSON_DECSTR_BUFSIZE 128 -#define DUK__JSON_DECSTR_CHUNKSIZE 64 -#define DUK__JSON_ENCSTR_CHUNKSIZE 64 +#define DUK__JSON_DECSTR_BUFSIZE 128 +#define DUK__JSON_DECSTR_CHUNKSIZE 64 +#define DUK__JSON_ENCSTR_CHUNKSIZE 64 #define DUK__JSON_STRINGIFY_BUFSIZE 128 -#define DUK__JSON_MAX_ESC_LEN 10 /* '\Udeadbeef' */ +#define DUK__JSON_MAX_ESC_LEN 10 /* '\Udeadbeef' */ DUK_LOCAL_DECL void duk__json_dec_syntax_error(duk_json_dec_ctx *js_ctx); DUK_LOCAL_DECL void duk__json_dec_eat_white(duk_json_dec_ctx *js_ctx); @@ -36446,103 +37464,88 @@ * 0xa0 ... 0xff: backslash + one char */ - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xe2, 0xf4, 0xee, 0x80, 0xe6, 0xf2, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x20, 0x21, 0xa2, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0xdc, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xe2, 0xf4, 0xee, 0x80, 0xe6, 0xf2, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x20, 0x21, 0xa2, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0xdc, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81 }; -#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ -DUK_LOCAL const duk_uint8_t duk__json_quotestr_esc14 = { - DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, - DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, - DUK_ASC_LC_B, DUK_ASC_LC_T, DUK_ASC_LC_N, DUK_ASC_NUL, - DUK_ASC_LC_F, DUK_ASC_LC_R -}; -#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +DUK_LOCAL const duk_uint8_t duk__json_quotestr_esc14 = { DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, + DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_LC_B, DUK_ASC_LC_T, + DUK_ASC_LC_N, DUK_ASC_NUL, DUK_ASC_LC_F, DUK_ASC_LC_R }; +#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ #if defined(DUK_USE_JSON_DECSTRING_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_decstr_lookup256 = { /* 0x00: slow path * other: as is */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x20, 0x21, 0x00, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x00, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x21, 0x00, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x00, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, + 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; -#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ +#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ #if defined(DUK_USE_JSON_EATWHITE_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_eatwhite_lookup256 = { /* 0x00: finish (non-white) * 0x01: continue */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ #if defined(DUK_USE_JSON_DECNUMBER_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_decnumber_lookup256 = { /* 0x00: finish (not part of number) * 0x01: continue */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ +#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ /* * Parsing implementation. @@ -36562,8 +37565,7 @@ * hidden, unfortunately, but we'll have an offset which * is often quite enough. */ - DUK_ERROR_FMT1(js_ctx->thr, DUK_ERR_SYNTAX_ERROR, DUK_STR_FMT_INVALID_JSON, - (long) (js_ctx->p - js_ctx->p_start)); + DUK_ERROR_FMT1(js_ctx->thr, DUK_ERR_SYNTAX_ERROR, DUK_STR_FMT_INVALID_JSON, (long) (js_ctx->p - js_ctx->p_start)); DUK_WO_NORETURN(return;); } @@ -36580,18 +37582,18 @@ /* This fast path is pretty marginal in practice. * XXX: candidate for removal. */ - DUK_ASSERT(duk__json_eatwhite_lookup0x00 == 0x00); /* end-of-input breaks */ + DUK_ASSERT(duk__json_eatwhite_lookup0x00 == 0x00); /* end-of-input breaks */ if (duk__json_eatwhite_lookupt == 0) { break; } -#else /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#else /* DUK_USE_JSON_EATWHITE_FASTPATH */ if (!(t == 0x20 || t == 0x0a || t == 0x0d || t == 0x09)) { /* NUL also comes here. Comparison order matters, 0x20 * is most common whitespace. */ break; } -#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ p++; } js_ctx->p = p; @@ -36625,8 +37627,7 @@ /* XXX: share helper from lexer; duk_lexer.c / hexval(). */ x = duk__json_dec_get(js_ctx); - DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%ld, n=%ld, res=%ld, x=%ld", - (long) i, (long) n, (long) res, (long) x)); + DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%ld, n=%ld, res=%ld, x=%ld", (long) i, (long) n, (long) res, (long) x)); /* x == 0x00 (EOF) causes syntax_error */ DUK_ASSERT(duk_hex_dectab0 == -1); @@ -36642,7 +37643,7 @@ DUK_DDD(DUK_DDDPRINT("final hex decoded value: %ld", (long) res)); return res; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); return 0; @@ -36663,7 +37664,7 @@ DUK_ASSERT(h != NULL); p = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h) + 1; - DUK_ASSERT(*(js_ctx->p - 1) == *(p - 1)); /* first character has been matched */ + DUK_ASSERT(*(js_ctx->p - 1) == *(p - 1)); /* first character has been matched */ for (;;) { x = *p; @@ -36680,7 +37681,7 @@ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -36694,14 +37695,27 @@ */ cp = (duk_uint_fast32_t) duk__json_dec_get(js_ctx); switch (cp) { - case DUK_ASC_BACKSLASH: break; - case DUK_ASC_DOUBLEQUOTE: break; - case DUK_ASC_SLASH: break; - case DUK_ASC_LC_T: cp = 0x09; break; - case DUK_ASC_LC_N: cp = 0x0a; break; - case DUK_ASC_LC_R: cp = 0x0d; break; - case DUK_ASC_LC_F: cp = 0x0c; break; - case DUK_ASC_LC_B: cp = 0x08; break; + case DUK_ASC_BACKSLASH: + break; + case DUK_ASC_DOUBLEQUOTE: + break; + case DUK_ASC_SLASH: + break; + case DUK_ASC_LC_T: + cp = 0x09; + break; + case DUK_ASC_LC_N: + cp = 0x0a; + break; + case DUK_ASC_LC_R: + cp = 0x0d; + break; + case DUK_ASC_LC_F: + cp = 0x0c; + break; + case DUK_ASC_LC_B: + cp = 0x08; + break; case DUK_ASC_LC_U: { cp = duk__json_dec_decode_hex_escape(js_ctx, 4); break; @@ -36711,7 +37725,7 @@ if (js_ctx->flag_ext_custom) { cp = duk__json_dec_decode_hex_escape(js_ctx, 8); } else { - return 1; /* syntax error */ + return 1; /* syntax error */ } break; } @@ -36719,14 +37733,14 @@ if (js_ctx->flag_ext_custom) { cp = duk__json_dec_decode_hex_escape(js_ctx, 2); } else { - return 1; /* syntax error */ + return 1; /* syntax error */ } break; } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ default: /* catches EOF (0x00) */ - return 1; /* syntax error */ + return 1; /* syntax error */ } DUK_RAW_WRITEINC_XUTF8(*ext_p, cp); @@ -36768,7 +37782,7 @@ /* Ensure space for 1:1 output plus one escape. */ q = DUK_BW_ENSURE_RAW(js_ctx->thr, bw, safe + DUK_UNICODE_MAX_XUTF8_LENGTH, q); - p = js_ctx->p; /* temp copy, write back for next loop */ + p = js_ctx->p; /* temp copy, write back for next loop */ for (;;) { if (safe == 0) { js_ctx->p = p; @@ -36803,8 +37817,8 @@ } } } - found_quote: -#else /* DUK_USE_JSON_DECSTRING_FASTPATH */ +found_quote: +#else /* DUK_USE_JSON_DECSTRING_FASTPATH */ for (;;) { duk_uint8_t x; @@ -36825,16 +37839,16 @@ *q++ = (duk_uint8_t) x; } } -#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ +#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ DUK_BW_SETPTR_AND_COMPACT(js_ctx->thr, bw, q); - (void) duk_buffer_to_string(thr, -1); /* Safe if input string is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if input string is safe. */ /* ... str */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -36850,7 +37864,7 @@ /* Caller has already eaten the first char so backtrack one byte. */ - js_ctx->p--; /* safe */ + js_ctx->p--; /* safe */ p = js_ctx->p; /* Here again we parse bytes, and non-ASCII UTF-8 will cause end of @@ -36882,7 +37896,7 @@ /* ... str */ } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) DUK_LOCAL void duk__json_dec_pointer(duk_json_dec_ctx *js_ctx) { @@ -36925,17 +37939,17 @@ voidptr = NULL; (void) DUK_SSCANF((const char *) js_ctx->p, DUK_STR_FMT_PTR, &voidptr); duk_push_pointer(thr, voidptr); - js_ctx->p = p + 1; /* skip ')' */ + js_ctx->p = p + 1; /* skip ')' */ /* ... ptr */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) DUK_LOCAL void duk__json_dec_buffer(duk_json_dec_ctx *js_ctx) { @@ -36983,17 +37997,17 @@ duk_memcpy((void *) buf, (const void *) js_ctx->p, src_len); duk_hex_decode(thr, -1); - js_ctx->p = p + 1; /* skip '|' */ + js_ctx->p = p + 1; /* skip '|' */ /* ... buf */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ /* Parse a number, other than NaN or +/- Infinity */ DUK_LOCAL void duk__json_dec_number(duk_json_dec_ctx *js_ctx) { @@ -37016,47 +38030,45 @@ x = *p; DUK_DDD(DUK_DDDPRINT("parse_number: p_start=%p, p=%p, p_end=%p, x=%ld", - (const void *) p_start, (const void *) p, - (const void *) js_ctx->p_end, (long) x)); + (const void *) p_start, + (const void *) p, + (const void *) js_ctx->p_end, + (long) x)); #if defined(DUK_USE_JSON_DECNUMBER_FASTPATH) /* This fast path is pretty marginal in practice. * XXX: candidate for removal. */ - DUK_ASSERT(duk__json_decnumber_lookup0x00 == 0x00); /* end-of-input breaks */ + DUK_ASSERT(duk__json_decnumber_lookup0x00 == 0x00); /* end-of-input breaks */ if (duk__json_decnumber_lookupx == 0) { break; } -#else /* DUK_USE_JSON_DECNUMBER_FASTPATH */ +#else /* DUK_USE_JSON_DECNUMBER_FASTPATH */ if (!((x >= DUK_ASC_0 && x <= DUK_ASC_9) || - (x == DUK_ASC_PERIOD || x == DUK_ASC_LC_E || - x == DUK_ASC_UC_E || x == DUK_ASC_MINUS || x == DUK_ASC_PLUS))) { + (x == DUK_ASC_PERIOD || x == DUK_ASC_LC_E || x == DUK_ASC_UC_E || x == DUK_ASC_MINUS || x == DUK_ASC_PLUS))) { /* Plus sign must be accepted for positive exponents * (e.g. '1.5e+2'). This clause catches NULs. */ break; } -#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ - p++; /* safe, because matched (NUL causes a break) */ +#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ + p++; /* safe, because matched (NUL causes a break) */ } js_ctx->p = p; DUK_ASSERT(js_ctx->p > p_start); duk_push_lstring(thr, (const char *) p_start, (duk_size_t) (p - p_start)); - s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_MINUS | /* but don't allow leading plus */ + s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_MINUS | /* but don't allow leading plus */ DUK_S2N_FLAG_ALLOW_FRAC; - DUK_DDD(DUK_DDDPRINT("parse_number: string before parsing: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_number: string before parsing: %!T", (duk_tval *) duk_get_tval(thr, -1))); duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); if (duk_is_nan(thr, -1)) { duk__json_dec_syntax_error(js_ctx); } DUK_ASSERT(duk_is_number(thr, -1)); - DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T", (duk_tval *) duk_get_tval(thr, -1))); /* ... num */ } @@ -37069,7 +38081,7 @@ duk_native_stack_check(thr); - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_ERROR_RANGE(thr, DUK_STR_DEC_RECLIMIT); @@ -37088,7 +38100,7 @@ DUK_LOCAL void duk__json_dec_object(duk_json_dec_ctx *js_ctx) { duk_hthread *thr = js_ctx->thr; - duk_int_t key_count; /* XXX: a "first" flag would suffice */ + duk_int_t key_count; /* XXX: a "first" flag would suffice */ duk_uint8_t x; DUK_DDD(DUK_DDDPRINT("parse_object")); @@ -37105,7 +38117,8 @@ DUK_DDD(DUK_DDDPRINT("parse_object: obj=%!T, x=%ld, key_count=%ld", (duk_tval *) duk_get_tval(thr, -1), - (long) x, (long) key_count)); + (long) x, + (long) key_count)); /* handle comma and closing brace */ @@ -37130,8 +38143,7 @@ if (x == DUK_ASC_DOUBLEQUOTE) { duk__json_dec_string(js_ctx); #if defined(DUK_USE_JX) - } else if (js_ctx->flag_ext_custom && - duk_unicode_is_identifier_start((duk_codepoint_t) x)) { + } else if (js_ctx->flag_ext_custom && duk_unicode_is_identifier_start((duk_codepoint_t) x)) { duk__json_dec_plain_string(js_ctx); #endif } else { @@ -37158,13 +38170,12 @@ /* ... obj */ - DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_dec_objarr_exit(js_ctx); return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -37188,7 +38199,8 @@ DUK_DDD(DUK_DDDPRINT("parse_array: arr=%!T, x=%ld, arr_idx=%ld", (duk_tval *) duk_get_tval(thr, -1), - (long) x, (long) arr_idx)); + (long) x, + (long) arr_idx)); /* handle comma and closing bracket */ @@ -37202,7 +38214,7 @@ /* accept anything, expect first value (EOF will be * caught by duk__json_dec_value() below. */ - js_ctx->p--; /* backtrack (safe) */ + js_ctx->p--; /* backtrack (safe) */ } else { /* catches EOF (NUL) and initial comma */ goto syntax_error; @@ -37226,13 +38238,12 @@ /* ... arr */ - DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_dec_objarr_exit(js_ctx); return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -37252,14 +38263,14 @@ } else if ((x >= DUK_ASC_0 && x <= DUK_ASC_9) || (x == DUK_ASC_MINUS)) { #if defined(DUK_USE_JX) if (js_ctx->flag_ext_custom && x == DUK_ASC_MINUS && duk__json_dec_peek(js_ctx) == DUK_ASC_UC_I) { - duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY); /* "-Infinity", '-' has been eaten */ + duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY); /* "-Infinity", '-' has been eaten */ duk_push_number(thr, -DUK_DOUBLE_INFINITY); } else { #else - { /* unconditional block */ + { /* unconditional block */ #endif /* We already ate 'x', so backup one byte. */ - js_ctx->p--; /* safe */ + js_ctx->p--; /* safe */ duk__json_dec_number(js_ctx); } } else if (x == DUK_ASC_LC_T) { @@ -37300,7 +38311,7 @@ /* ... val */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -37323,7 +38334,7 @@ (duk_tval *) duk_get_tval(thr, -1))); duk_dup_top(thr); - duk_get_prop(thr, -3); /* -> ... holder name val */ + duk_get_prop(thr, -3); /* -> ... holder name val */ h = duk_get_hobject(thr, -1); if (h != NULL) { @@ -37333,13 +38344,17 @@ /* ... holder name val */ DUK_DDD(DUK_DDDPRINT("walk: array, top=%ld, i=%ld, arr_len=%ld, holder=%!T, name=%!T, val=%!T", - (long) duk_get_top(thr), (long) i, (long) arr_len, - (duk_tval *) duk_get_tval(thr, -3), (duk_tval *) duk_get_tval(thr, -2), + (long) duk_get_top(thr), + (long) i, + (long) arr_len, + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_dup_top(thr); - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... holder name val val ToString(i) */ - duk__json_dec_reviver_walk(js_ctx); /* -> ... holder name val new_elem */ + (void) duk_push_uint_to_hstring(thr, + (duk_uint_t) i); /* -> ... holder name val val ToString(i) */ + duk__json_dec_reviver_walk(js_ctx); /* -> ... holder name val new_elem */ if (duk_is_undefined(thr, -1)) { duk_pop(thr); @@ -37357,9 +38372,12 @@ duk_enum(thr, -1, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); while (duk_next(thr, -1 /*enum_index*/, 0 /*get_value*/)) { DUK_DDD(DUK_DDDPRINT("walk: object, top=%ld, holder=%!T, name=%!T, val=%!T, enum=%!iT, obj_key=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -5), - (duk_tval *) duk_get_tval(thr, -4), (duk_tval *) duk_get_tval(thr, -3), - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, -5), + (duk_tval *) duk_get_tval(thr, -4), + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); /* ... holder name val enum obj_key */ duk_dup_m3(thr); @@ -37385,34 +38403,33 @@ duk_put_prop(thr, -4); } } - duk_pop(thr); /* pop enum */ + duk_pop(thr); /* pop enum */ } } /* ... holder name val */ duk_dup(thr, js_ctx->idx_reviver); - duk_insert(thr, -4); /* -> ... reviver holder name val */ - duk_call_method(thr, 2); /* -> ... res */ + duk_insert(thr, -4); /* -> ... reviver holder name val */ + duk_call_method(thr, 2); /* -> ... res */ duk__json_dec_objarr_exit(js_ctx); - DUK_DDD(DUK_DDDPRINT("walk: top=%ld, result=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("walk: top=%ld, result=%!T", (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -1))); } /* * Stringify implementation. */ -#define DUK__EMIT_1(js_ctx,ch) duk__emit_1((js_ctx), (duk_uint_fast8_t) (ch)) -#define DUK__EMIT_2(js_ctx,ch1,ch2) duk__emit_2((js_ctx), (duk_uint_fast8_t) (ch1), (duk_uint_fast8_t) (ch2)) -#define DUK__EMIT_HSTR(js_ctx,h) duk__emit_hstring((js_ctx), (h)) +#define DUK__EMIT_1(js_ctx, ch) duk__emit_1((js_ctx), (duk_uint_fast8_t) (ch)) +#define DUK__EMIT_2(js_ctx, ch1, ch2) duk__emit_2((js_ctx), (duk_uint_fast8_t) (ch1), (duk_uint_fast8_t) (ch2)) +#define DUK__EMIT_HSTR(js_ctx, h) duk__emit_hstring((js_ctx), (h)) #if defined(DUK_USE_FASTINT) || defined(DUK_USE_JX) || defined(DUK_USE_JC) -#define DUK__EMIT_CSTR(js_ctx,p) duk__emit_cstring((js_ctx), (p)) +#define DUK__EMIT_CSTR(js_ctx, p) duk__emit_cstring((js_ctx), (p)) #endif -#define DUK__EMIT_STRIDX(js_ctx,i) duk__emit_stridx((js_ctx), (i)) -#define DUK__UNEMIT_1(js_ctx) duk__unemit_1((js_ctx)) +#define DUK__EMIT_STRIDX(js_ctx, i) duk__emit_stridx((js_ctx), (i)) +#define DUK__UNEMIT_1(js_ctx) duk__unemit_1((js_ctx)) DUK_LOCAL void duk__emit_1(duk_json_enc_ctx *js_ctx, duk_uint_fast8_t ch) { DUK_BW_WRITE_ENSURE_U8(js_ctx->thr, &js_ctx->bw, ch); @@ -37447,10 +38464,8 @@ DUK_BW_ADD_PTR(js_ctx->thr, &js_ctx->bw, -1); } -#define DUK__MKESC(nybbles,esc1,esc2) \ - (((duk_uint_fast32_t) (nybbles)) << 16) | \ - (((duk_uint_fast32_t) (esc1)) << 8) | \ - ((duk_uint_fast32_t) (esc2)) +#define DUK__MKESC(nybbles, esc1, esc2) \ + (((duk_uint_fast32_t) (nybbles)) << 16) | (((duk_uint_fast32_t) (esc1)) << 8) | ((duk_uint_fast32_t) (esc2)) DUK_LOCAL duk_uint8_t *duk__emit_esc_auto_fast(duk_json_enc_ctx *js_ctx, duk_uint_fast32_t cp, duk_uint8_t *q) { duk_uint_fast32_t tmp; @@ -37475,7 +38490,7 @@ } } else #endif - if (DUK_LIKELY(cp < 0x10000UL)) { + if (DUK_LIKELY(cp < 0x10000UL)) { tmp = DUK__MKESC(4, DUK_ASC_BACKSLASH, DUK_ASC_LC_U); } else { #if defined(DUK_USE_JX) @@ -37507,7 +38522,7 @@ } DUK_LOCAL void duk__json_enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k) { - const duk_int8_t *p, *p_start, *p_end; /* Note: intentionally signed. */ + const duk_int8_t *p, *p_start, *p_end; /* Note: intentionally signed. */ duk_size_t k_len; duk_codepoint_t cp; @@ -37548,7 +38563,7 @@ return; } - quote_normally: +quote_normally: duk__json_enc_quote_string(js_ctx, k); } @@ -37561,7 +38576,7 @@ duk_hthread *thr = js_ctx->thr; const duk_uint8_t *p, *p_start, *p_end, *p_now, *p_tmp; duk_uint8_t *q; - duk_ucodepoint_t cp; /* typed for duk_unicode_decode_xutf8() */ + duk_ucodepoint_t cp; /* typed for duk_unicode_decode_xutf8() */ DUK_DDD(DUK_DDDPRINT("duk__json_enc_quote_string: h_str=%!O", (duk_heaphdr *) h_str)); @@ -37580,8 +38595,7 @@ duk_size_t left, now, space; left = (duk_size_t) (p_end - p); - now = (left > DUK__JSON_ENCSTR_CHUNKSIZE ? - DUK__JSON_ENCSTR_CHUNKSIZE : left); + now = (left > DUK__JSON_ENCSTR_CHUNKSIZE ? DUK__JSON_ENCSTR_CHUNKSIZE : left); /* Maximum expansion per input byte is 6: * - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6). @@ -37617,7 +38631,7 @@ p--; /* slow path is shared */ -#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ cp = *p; if (DUK_LIKELY(cp <= 0x7f)) { @@ -37648,7 +38662,7 @@ } } else { /* slow path is shared */ -#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ /* slow path decode */ @@ -37724,11 +38738,10 @@ /* Negative zero needs special handling in JX/JC because * it would otherwise serialize to '0', not '-0'. */ - if (DUK_UNLIKELY(c == DUK_FP_ZERO && s != 0 && - (js_ctx->flag_ext_custom_or_compatible))) { - duk_push_hstring_stridx(thr, DUK_STRIDX_MINUS_ZERO); /* '-0' */ + if (DUK_UNLIKELY(c == DUK_FP_ZERO && s != 0 && (js_ctx->flag_ext_custom_or_compatible))) { + duk_push_hstring_stridx(thr, DUK_STRIDX_MINUS_ZERO); /* '-0' */ } else -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ { n2s_flags = 0; /* ... number -> ... string */ @@ -37740,8 +38753,7 @@ } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (!(js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE))) { + if (!(js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE))) { stridx = DUK_STRIDX_LC_NULL; } else if (c == DUK_FP_NAN) { stridx = js_ctx->stridx_custom_nan; @@ -37840,7 +38852,7 @@ return q; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ DUK_LOCAL duk_uint8_t *duk__json_enc_buffer_data_hex(const duk_uint8_t *src, duk_size_t src_len, duk_uint8_t *dst) { const duk_uint8_t *p; const duk_uint8_t *p_end; @@ -37858,7 +38870,7 @@ return q; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ DUK_LOCAL void duk__json_enc_buffer_data(duk_json_enc_ctx *js_ctx, duk_uint8_t *buf_data, duk_size_t buf_len) { duk_hthread *thr; @@ -37867,7 +38879,7 @@ thr = js_ctx->thr; - DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ + DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ DUK_ASSERT(js_ctx->flag_ext_custom_or_compatible); /* Buffer values are encoded in (lowercase) hex to make the @@ -37883,7 +38895,7 @@ /* Note: space must cater for both JX and JC. */ space = 9 + buf_len * 2 + 2; DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7ffffffeUL); - DUK_ASSERT((space - 2) / 2 >= buf_len); /* overflow not possible, buffer limits */ + DUK_ASSERT((space - 2) / 2 >= buf_len); /* overflow not possible, buffer limits */ q = DUK_BW_ENSURE_GETPTR(thr, &js_ctx->bw, space); #if defined(DUK_USE_JX) && defined(DUK_USE_JC) @@ -37903,7 +38915,7 @@ #if defined(DUK_USE_JC) { DUK_ASSERT(js_ctx->flag_ext_compatible); - duk_memcpy((void *) q, (const void *) "{\"_buf\":\"", 9); /* len: 9 */ + duk_memcpy((void *) q, (const void *) "{\"_buf\":\"", 9); /* len: 9 */ q += 9; q = duk__json_enc_buffer_data_hex(buf_data, buf_len, q); *q++ = DUK_ASC_DOUBLEQUOTE; @@ -37916,10 +38928,10 @@ DUK_LOCAL void duk__json_enc_buffer_jx_jc(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) { duk__json_enc_buffer_data(js_ctx, - (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h), - (duk_size_t) DUK_HBUFFER_GET_SIZE(h)); + (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h), + (duk_size_t) DUK_HBUFFER_GET_SIZE(h)); } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) DUK_LOCAL void duk__json_enc_buffer_json_fastpath(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) { @@ -37959,21 +38971,21 @@ } DUK_BW_SET_PTR(js_ctx->thr, &js_ctx->bw, q); } - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth); } DUK__EMIT_1(js_ctx, DUK_ASC_RCURLY); } -#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ +#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) DUK_LOCAL void duk__json_enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr) { - char buf64; /* XXX: how to figure correct size? */ + char buf64; /* XXX: how to figure correct size? */ const char *fmt; - DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ + DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ DUK_ASSERT(js_ctx->flag_ext_custom_or_compatible); duk_memzero(buf, sizeof(buf)); @@ -38000,10 +39012,10 @@ #endif /* When ptr == NULL, the format argument is unused. */ - DUK_SNPRINTF(buf, sizeof(buf) - 1, fmt, ptr); /* must not truncate */ + DUK_SNPRINTF(buf, sizeof(buf) - 1, fmt, ptr); /* must not truncate */ DUK__EMIT_CSTR(js_ctx, buf); } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) #if defined(DUK_USE_JX) || defined(DUK_USE_JC) @@ -38015,12 +39027,12 @@ } else { /* Handle both full and partial slice (as long as covered). */ duk__json_enc_buffer_data(js_ctx, - (duk_uint8_t *) DUK_HBUFOBJ_GET_SLICE_BASE(js_ctx->thr->heap, h_bufobj), - (duk_size_t) h_bufobj->length); + (duk_uint8_t *) DUK_HBUFOBJ_GET_SLICE_BASE(js_ctx->thr->heap, h_bufobj), + (duk_size_t) h_bufobj->length); } } -#endif /* DUK_USE_JX || DUK_USE_JC */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Indent helper. Calling code relies on js_ctx->recursion_depth also being * directly related to indent depth. @@ -38028,24 +39040,24 @@ #if defined(DUK_USE_PREFER_SIZE) DUK_LOCAL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) { DUK_ASSERT(js_ctx->h_gap != NULL); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ DUK__EMIT_1(js_ctx, 0x0a); while (depth-- > 0) { DUK__EMIT_HSTR(js_ctx, js_ctx->h_gap); } } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_LOCAL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) { const duk_uint8_t *gap_data; duk_size_t gap_len; - duk_size_t avail_bytes; /* bytes of indent available for copying */ - duk_size_t need_bytes; /* bytes of indent still needed */ + duk_size_t avail_bytes; /* bytes of indent available for copying */ + duk_size_t need_bytes; /* bytes of indent still needed */ duk_uint8_t *p_start; duk_uint8_t *p; DUK_ASSERT(js_ctx->h_gap != NULL); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ DUK__EMIT_1(js_ctx, 0x0a); if (DUK_UNLIKELY(depth == 0)) { @@ -38079,14 +39091,14 @@ avail_bytes <<= 1; } - DUK_ASSERT(need_bytes < avail_bytes); /* need_bytes may be zero */ + DUK_ASSERT(need_bytes < avail_bytes); /* need_bytes may be zero */ duk_memcpy((void *) p, (const void *) p_start, (size_t) need_bytes); p += need_bytes; /*avail_bytes += need_bytes*/ DUK_BW_SET_PTR(js_ctx->thr, &js_ctx->bw, p); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Shared entry handling for object/array serialization. */ DUK_LOCAL void duk__json_enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top) { @@ -38103,7 +39115,7 @@ * with overflow in a loop check object. */ - h_target = duk_known_hobject(thr, -1); /* object or array */ + h_target = duk_known_hobject(thr, -1); /* object or array */ n = js_ctx->recursion_depth; if (DUK_UNLIKELY(n > DUK_JSON_ENC_LOOPARRAY)) { @@ -38120,18 +39132,18 @@ js_ctx->visitingjs_ctx->recursion_depth = h_target; } else { duk_push_sprintf(thr, DUK_STR_FMT_PTR, (void *) h_target); - duk_dup_top(thr); /* -> ... voidp voidp */ + duk_dup_top(thr); /* -> ... voidp voidp */ if (duk_has_prop(thr, js_ctx->idx_loop)) { DUK_ERROR_TYPE(thr, DUK_STR_CYCLIC_INPUT); DUK_WO_NORETURN(return;); } - duk_push_true(thr); /* -> ... voidp true */ - duk_put_prop(thr, js_ctx->idx_loop); /* -> ... */ + duk_push_true(thr); /* -> ... voidp true */ + duk_put_prop(thr, js_ctx->idx_loop); /* -> ... */ } /* C recursion check. */ - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_ERROR_RANGE(thr, DUK_STR_ENC_RECLIMIT); @@ -38140,7 +39152,8 @@ js_ctx->recursion_depth++; DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%ld, loop=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); } /* Shared exit handling for object/array serialization. */ @@ -38156,20 +39169,21 @@ /* Loop check. */ - h_target = duk_known_hobject(thr, *entry_top - 1); /* original target at entry_top - 1 */ + h_target = duk_known_hobject(thr, *entry_top - 1); /* original target at entry_top - 1 */ if (js_ctx->recursion_depth < DUK_JSON_ENC_LOOPARRAY) { /* Previous entry was inside visited, nothing to do. */ } else { duk_push_sprintf(thr, DUK_STR_FMT_PTR, (void *) h_target); - duk_del_prop(thr, js_ctx->idx_loop); /* -> ... */ + duk_del_prop(thr, js_ctx->idx_loop); /* -> ... */ } /* Restore stack top after unbalanced code paths. */ duk_set_top(thr, *entry_top); DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%ld, loop=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); } /* The JO(value) operation: encode object. @@ -38197,13 +39211,14 @@ } else { /* XXX: would be nice to enumerate an object at specified index */ duk_dup(thr, idx_obj); - (void) duk_hobject_get_enumerated_keys(thr, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); /* ... target -> ... target keys */ + (void) duk_hobject_get_enumerated_keys( + thr, + DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); /* ... target -> ... target keys */ idx_keys = duk_require_normalize_index(thr, -1); /* leave stack unbalanced on purpose */ } - DUK_DDD(DUK_DDDPRINT("idx_keys=%ld, h_keys=%!T", - (long) idx_keys, (duk_tval *) duk_get_tval(thr, idx_keys))); + DUK_DDD(DUK_DDDPRINT("idx_keys=%ld, h_keys=%!T", (long) idx_keys, (duk_tval *) duk_get_tval(thr, idx_keys))); /* Steps 8-10 have been merged to avoid a "partial" variable. */ @@ -38218,7 +39233,7 @@ arr_len = (duk_uarridx_t) duk_get_length(thr, idx_keys); emitted = 0; for (i = 0; i < arr_len; i++) { - duk_get_prop_index(thr, idx_keys, i); /* -> ... key */ + duk_get_prop_index(thr, idx_keys, i); /* -> ... key */ DUK_DDD(DUK_DDDPRINT("object property loop: holder=%!T, key=%!T", (duk_tval *) duk_get_tval(thr, idx_obj), @@ -38226,7 +39241,7 @@ h_key = duk_known_hstring(thr, -1); DUK_ASSERT(h_key != NULL); - DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(h_key)); /* proplist filtering; enum options */ + DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(h_key)); /* proplist filtering; enum options */ prev_size = DUK_BW_GET_SIZE(js_ctx->thr, &js_ctx->bw); if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { @@ -38255,7 +39270,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -38279,8 +39294,7 @@ duk_bool_t emitted; duk_uarridx_t i, arr_len; - DUK_DDD(DUK_DDDPRINT("duk__json_enc_array: array=%!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("duk__json_enc_array: array=%!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_enc_objarr_entry(js_ctx, &entry_top); @@ -38295,14 +39309,15 @@ for (i = 0; i < arr_len; i++) { DUK_DDD(DUK_DDDPRINT("array entry loop: array=%!T, index=%ld, arr_len=%ld", (duk_tval *) duk_get_tval(thr, idx_arr), - (long) i, (long) arr_len)); + (long) i, + (long) arr_len)); if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth); } - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... key */ + (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... key */ /* ... key */ @@ -38321,7 +39336,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -38346,14 +39361,15 @@ duk_small_int_t c; DUK_DDD(DUK_DDDPRINT("duk__json_enc_value: idx_holder=%ld, holder=%!T, key=%!T", - (long) idx_holder, (duk_tval *) duk_get_tval(thr, idx_holder), + (long) idx_holder, + (duk_tval *) duk_get_tval(thr, idx_holder), (duk_tval *) duk_get_tval(thr, -1))); tv_holder = DUK_GET_TVAL_POSIDX(thr, idx_holder); DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv_holder)); tv_key = DUK_GET_TVAL_NEGIDX(thr, -1); DUK_ASSERT(DUK_TVAL_IS_STRING(tv_key)); - DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING(tv_key))); /* Caller responsible. */ + DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING(tv_key))); /* Caller responsible. */ (void) duk_hobject_getprop(thr, tv_holder, tv_key); /* -> ... key val */ @@ -38365,19 +39381,17 @@ * number won't invoke the .toJSON() method. However, lightfuncs and * plain buffers mimic objects so we check for their .toJSON() method. */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_JSON); - if (duk_is_callable(thr, -1)) { /* toJSON() can also be a lightfunc */ + if (duk_is_callable(thr, -1)) { /* toJSON() can also be a lightfunc */ DUK_DDD(DUK_DDDPRINT("value is object, has callable toJSON() -> call it")); /* XXX: duk_dup_unvalidated(thr, -2) etc. */ - duk_dup_m2(thr); /* -> ... key val toJSON val */ - duk_dup_m4(thr); /* -> ... key val toJSON val key */ - duk_call_method(thr, 1); /* -> ... key val val' */ - duk_remove_m2(thr); /* -> ... key val' */ + duk_dup_m2(thr); /* -> ... key val toJSON val */ + duk_dup_m4(thr); /* -> ... key val toJSON val key */ + duk_call_method(thr, 1); /* -> ... key val val' */ + duk_remove_m2(thr); /* -> ... key val' */ } else { - duk_pop(thr); /* -> ... key val */ + duk_pop(thr); /* -> ... key val */ } } @@ -38388,12 +39402,12 @@ if (js_ctx->h_replacer) { /* XXX: Here a "slice copy" would be useful. */ DUK_DDD(DUK_DDDPRINT("replacer is set, call replacer")); - duk_push_hobject(thr, js_ctx->h_replacer); /* -> ... key val replacer */ - duk_dup(thr, idx_holder); /* -> ... key val replacer holder */ - duk_dup_m4(thr); /* -> ... key val replacer holder key */ - duk_dup_m4(thr); /* -> ... key val replacer holder key val */ - duk_call_method(thr, 2); /* -> ... key val val' */ - duk_remove_m2(thr); /* -> ... key val' */ + duk_push_hobject(thr, js_ctx->h_replacer); /* -> ... key val replacer */ + duk_dup(thr, idx_holder); /* -> ... key val replacer holder */ + duk_dup_m4(thr); /* -> ... key val replacer holder key */ + duk_dup_m4(thr); /* -> ... key val replacer holder key val */ + duk_call_method(thr, 2); /* -> ... key val val' */ + duk_remove_m2(thr); /* -> ... key val' */ } /* ... key val */ @@ -38409,8 +39423,7 @@ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (DUK_HOBJECT_IS_BUFOBJ(h) && - js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { + if (DUK_HOBJECT_IS_BUFOBJ(h) && js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { /* With JX/JC a bufferobject gets serialized specially. */ duk_hbufobj *h_bufobj; h_bufobj = (duk_hbufobj *) h; @@ -38419,8 +39432,8 @@ goto pop2_emitted; } /* Otherwise bufferobjects get serialized as normal objects. */ -#endif /* JX || JC */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* JX || JC */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ c = (duk_small_int_t) DUK_HOBJECT_GET_CLASS_NUMBER(h); switch (c) { case DUK_HOBJECT_CLASS_NUMBER: { @@ -38460,8 +39473,7 @@ DUK_ASSERT(h != NULL); if (DUK_HOBJECT_IS_CALLABLE(h)) { #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE)) { + if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { /* We only get here when doing non-standard JSON encoding */ DUK_DDD(DUK_DDDPRINT("-> function allowed, serialize to custom format")); DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); @@ -38471,13 +39483,13 @@ DUK_DDD(DUK_DDDPRINT("-> will result in undefined (function)")); goto pop2_undef; } -#else /* DUK_USE_JX || DUK_USE_JC */ +#else /* DUK_USE_JX || DUK_USE_JC */ DUK_DDD(DUK_DDDPRINT("-> will result in undefined (function)")); goto pop2_undef; -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ } } - } /* end switch */ + } /* end switch */ } /* ... key val */ @@ -38504,8 +39516,7 @@ break; } case DUK_TAG_BOOLEAN: { - DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? - DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); + DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); break; } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) @@ -38514,7 +39525,7 @@ duk__json_enc_pointer(js_ctx, DUK_TVAL_GET_POINTER(tv)); break; } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ case DUK_TAG_STRING: { duk_hstring *h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); @@ -38593,14 +39604,14 @@ } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - pop2_emitted: +pop2_emitted: #endif duk_pop_2(thr); /* ... key val -> ... */ - return 1; /* emitted */ + return 1; /* emitted */ - pop2_undef: - duk_pop_2(thr); /* ... key val -> ... */ - return 0; /* not emitted */ +pop2_undef: + duk_pop_2(thr); /* ... key val -> ... */ + return 0; /* not emitted */ } /* E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4. */ @@ -38676,8 +39687,7 @@ break; } case DUK_TAG_BOOLEAN: { - DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? - DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); + DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); break; } case DUK_TAG_STRING: { @@ -38694,8 +39704,7 @@ duk_hobject *obj; duk_tval *tv_val; duk_bool_t emitted = 0; - duk_uint32_t c_bit, c_all, c_array, c_unbox, c_undef, - c_func, c_bufobj, c_object, c_abort; + duk_uint32_t c_bit, c_all, c_array, c_unbox, c_undef, c_func, c_bufobj, c_object, c_abort; /* For objects JSON.stringify() only looks for own, enumerable * properties which is nice for the fast path here. @@ -38728,7 +39737,7 @@ * it (though it's OK to abort the fast path). */ - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_DD(DUK_DDPRINT("fast path recursion limit")); @@ -38780,28 +39789,23 @@ if (js_ctx->flag_ext_custom_or_compatible) { c_all = DUK_HOBJECT_CMASK_ALL; c_array = DUK_HOBJECT_CMASK_ARRAY; - c_unbox = DUK_HOBJECT_CMASK_NUMBER | - DUK_HOBJECT_CMASK_STRING | - DUK_HOBJECT_CMASK_BOOLEAN | - DUK_HOBJECT_CMASK_POINTER; /* Symbols are not unboxed. */ + c_unbox = DUK_HOBJECT_CMASK_NUMBER | DUK_HOBJECT_CMASK_STRING | DUK_HOBJECT_CMASK_BOOLEAN | + DUK_HOBJECT_CMASK_POINTER; /* Symbols are not unboxed. */ c_func = DUK_HOBJECT_CMASK_FUNCTION; c_bufobj = DUK_HOBJECT_CMASK_ALL_BUFOBJS; c_undef = 0; c_abort = 0; c_object = c_all & ~(c_array | c_unbox | c_func | c_bufobj | c_undef | c_abort); - } - else + } else #endif { c_all = DUK_HOBJECT_CMASK_ALL; c_array = DUK_HOBJECT_CMASK_ARRAY; - c_unbox = DUK_HOBJECT_CMASK_NUMBER | - DUK_HOBJECT_CMASK_STRING | - DUK_HOBJECT_CMASK_BOOLEAN; /* Symbols are not unboxed. */ + c_unbox = DUK_HOBJECT_CMASK_NUMBER | DUK_HOBJECT_CMASK_STRING | + DUK_HOBJECT_CMASK_BOOLEAN; /* Symbols are not unboxed. */ c_func = 0; c_bufobj = 0; - c_undef = DUK_HOBJECT_CMASK_FUNCTION | - DUK_HOBJECT_CMASK_POINTER; + c_undef = DUK_HOBJECT_CMASK_FUNCTION | DUK_HOBJECT_CMASK_POINTER; /* As the fast path doesn't currently properly support * duk_hbufobj virtual properties, abort fast path if * we encounter them in plain JSON mode. @@ -38883,7 +39887,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -38953,14 +39957,14 @@ #endif /* fall through */ - elem_done: + elem_done: DUK__EMIT_1(js_ctx, DUK_ASC_COMMA); emitted = 1; } if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -38972,7 +39976,7 @@ * automatic unboxing. Rely on internal value being * sane (to avoid infinite recursion). */ - DUK_ASSERT((c_bit & DUK_HOBJECT_CMASK_SYMBOL) == 0); /* Symbols are not unboxed. */ + DUK_ASSERT((c_bit & DUK_HOBJECT_CMASK_SYMBOL) == 0); /* Symbols are not unboxed. */ #if 1 /* The code below is incorrect if .toString() or .valueOf() have @@ -38982,7 +39986,7 @@ * Unimplemented for now, abort fast path for boxed values. */ goto abort_fastpath; -#else /* disabled */ +#else /* disabled */ /* Disabled until fixed, see above. */ duk_tval *tv_internal; @@ -38990,16 +39994,14 @@ tv_internal = duk_hobject_get_internal_value_tval_ptr(js_ctx->thr->heap, obj); DUK_ASSERT(tv_internal != NULL); - DUK_ASSERT(DUK_TVAL_IS_STRING(tv_internal) || - DUK_TVAL_IS_NUMBER(tv_internal) || - DUK_TVAL_IS_BOOLEAN(tv_internal) || - DUK_TVAL_IS_POINTER(tv_internal)); + DUK_ASSERT(DUK_TVAL_IS_STRING(tv_internal) || DUK_TVAL_IS_NUMBER(tv_internal) || + DUK_TVAL_IS_BOOLEAN(tv_internal) || DUK_TVAL_IS_POINTER(tv_internal)); tv = tv_internal; DUK_ASSERT(js_ctx->recursion_depth > 0); - js_ctx->recursion_depth--; /* required to keep recursion depth correct */ + js_ctx->recursion_depth--; /* required to keep recursion depth correct */ goto restart_match; -#endif /* disabled */ +#endif /* disabled */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) } else if (c_bit & c_func) { DUK__EMIT_STRIDX(js_ctx, js_ctx->stridx_custom_function); @@ -39112,12 +40114,12 @@ #endif } } - return 1; /* not undefined */ + return 1; /* not undefined */ - emit_undefined: - return 0; /* value was undefined/unsupported */ +emit_undefined: + return 0; /* value was undefined/unsupported */ - abort_fastpath: +abort_fastpath: /* Error message doesn't matter: the error is ignored anyway. */ DUK_DD(DUK_DDPRINT("aborting fast path")); DUK_ERROR_INTERNAL(js_ctx->thr); @@ -39137,22 +40139,19 @@ tv = DUK_GET_TVAL_NEGIDX(thr, -1); if (duk__json_stringify_fast_value(js_ctx, tv) == 0) { DUK_DD(DUK_DDPRINT("top level value not supported, fail fast path")); - DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* Error message is ignored, so doesn't matter. */ + DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* Error message is ignored, so doesn't matter. */ } return 0; } -#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ +#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ /* * Top level wrappers */ DUK_INTERNAL -void duk_bi_json_parse_helper(duk_hthread *thr, - duk_idx_t idx_value, - duk_idx_t idx_reviver, - duk_small_uint_t flags) { +void duk_bi_json_parse_helper(duk_hthread *thr, duk_idx_t idx_value, duk_idx_t idx_reviver, duk_small_uint_t flags) { duk_json_dec_ctx js_ctx_alloc; duk_json_dec_ctx *js_ctx = &js_ctx_alloc; duk_hstring *h_text; @@ -39193,7 +40192,7 @@ js_ctx->flag_ext_custom_or_compatible = flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE); #endif - h_text = duk_to_hstring(thr, idx_value); /* coerce in-place; rejects Symbols */ + h_text = duk_to_hstring(thr, idx_value); /* coerce in-place; rejects Symbols */ DUK_ASSERT(h_text != NULL); /* JSON parsing code is allowed to read p_start,p_end: p_end is @@ -39202,11 +40201,10 @@ */ js_ctx->p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text); js_ctx->p = js_ctx->p_start; - js_ctx->p_end = ((const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text)) + - DUK_HSTRING_GET_BYTELEN(h_text); + js_ctx->p_end = ((const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text)) + DUK_HSTRING_GET_BYTELEN(h_text); DUK_ASSERT(*(js_ctx->p_end) == 0x00); - duk__json_dec_value(js_ctx); /* -> ... value */ + duk__json_dec_value(js_ctx); /* -> ... value */ DUK_ASSERT(js_ctx->recursion_depth == 0); /* Trailing whitespace has been eaten by duk__json_dec_value(), so if @@ -39218,27 +40216,26 @@ } if (duk_is_callable(thr, idx_reviver)) { - DUK_DDD(DUK_DDDPRINT("applying reviver: %!T", - (duk_tval *) duk_get_tval(thr, idx_reviver))); + DUK_DDD(DUK_DDDPRINT("applying reviver: %!T", (duk_tval *) duk_get_tval(thr, idx_reviver))); js_ctx->idx_reviver = idx_reviver; duk_push_object(thr); - duk_dup_m2(thr); /* -> ... val root val */ - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_EMPTY_STRING); /* default attrs ok */ - duk_push_hstring_stridx(thr, DUK_STRIDX_EMPTY_STRING); /* -> ... val root "" */ + duk_dup_m2(thr); /* -> ... val root val */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_EMPTY_STRING); /* default attrs ok */ + duk_push_hstring_stridx(thr, DUK_STRIDX_EMPTY_STRING); /* -> ... val root "" */ DUK_DDD(DUK_DDDPRINT("start reviver walk, root=%!T, name=%!T", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(js_ctx->recursion_depth == 0); - duk__json_dec_reviver_walk(js_ctx); /* ... val root "" -> ... val val' */ + duk__json_dec_reviver_walk(js_ctx); /* ... val root "" -> ... val val' */ DUK_ASSERT(js_ctx->recursion_depth == 0); - duk_remove_m2(thr); /* -> ... val' */ + duk_remove_m2(thr); /* -> ... val' */ } else { - DUK_DDD(DUK_DDDPRINT("reviver does not exist or is not callable: %!T", - (duk_tval *) duk_get_tval(thr, idx_reviver))); + DUK_DDD( + DUK_DDDPRINT("reviver does not exist or is not callable: %!T", (duk_tval *) duk_get_tval(thr, idx_reviver))); } /* Final result is at stack top. */ @@ -39312,7 +40309,7 @@ * combinations properly. */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_NULL; /* standard JSON; array gaps */ + js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_NULL; /* standard JSON; array gaps */ #if defined(DUK_USE_JX) if (flags & DUK_JSON_FLAG_EXT_CUSTOM) { js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_UNDEFINED; @@ -39320,41 +40317,35 @@ js_ctx->stridx_custom_neginf = DUK_STRIDX_MINUS_INFINITY; js_ctx->stridx_custom_posinf = DUK_STRIDX_INFINITY; js_ctx->stridx_custom_function = - (flags & DUK_JSON_FLAG_AVOID_KEY_QUOTES) ? - DUK_STRIDX_JSON_EXT_FUNCTION2 : - DUK_STRIDX_JSON_EXT_FUNCTION1; + (flags & DUK_JSON_FLAG_AVOID_KEY_QUOTES) ? DUK_STRIDX_JSON_EXT_FUNCTION2 : DUK_STRIDX_JSON_EXT_FUNCTION1; } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) && defined(DUK_USE_JC) else -#endif /* DUK_USE_JX && DUK_USE_JC */ +#endif /* DUK_USE_JX && DUK_USE_JC */ #if defined(DUK_USE_JC) - if (js_ctx->flags & DUK_JSON_FLAG_EXT_COMPATIBLE) { + if (js_ctx->flags & DUK_JSON_FLAG_EXT_COMPATIBLE) { js_ctx->stridx_custom_undefined = DUK_STRIDX_JSON_EXT_UNDEFINED; js_ctx->stridx_custom_nan = DUK_STRIDX_JSON_EXT_NAN; js_ctx->stridx_custom_neginf = DUK_STRIDX_JSON_EXT_NEGINF; js_ctx->stridx_custom_posinf = DUK_STRIDX_JSON_EXT_POSINF; js_ctx->stridx_custom_function = DUK_STRIDX_JSON_EXT_FUNCTION1; } -#endif /* DUK_USE_JC */ -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE)) { - DUK_ASSERT(js_ctx->mask_for_undefined == 0); /* already zero */ - } - else -#endif /* DUK_USE_JX || DUK_USE_JC */ + if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { + DUK_ASSERT(js_ctx->mask_for_undefined == 0); /* already zero */ + } else +#endif /* DUK_USE_JX || DUK_USE_JC */ { /* Plain buffer is treated like ArrayBuffer and serialized. * Lightfuncs are treated like objects, but JSON explicitly * skips serializing Function objects so we can just reject * lightfuncs here. */ - js_ctx->mask_for_undefined = DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_POINTER | - DUK_TYPE_MASK_LIGHTFUNC; + js_ctx->mask_for_undefined = DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_POINTER | DUK_TYPE_MASK_LIGHTFUNC; } DUK_BW_INIT_PUSHBUF(thr, &js_ctx->bw, DUK__JSON_STRINGIFY_BUFSIZE); @@ -39384,8 +40375,7 @@ js_ctx->idx_proplist = duk_push_bare_array(thr); - enum_flags = DUK_ENUM_ARRAY_INDICES_ONLY | - DUK_ENUM_SORT_ARRAY_INDICES; /* expensive flag */ + enum_flags = DUK_ENUM_ARRAY_INDICES_ONLY | DUK_ENUM_SORT_ARRAY_INDICES; /* expensive flag */ duk_enum(thr, idx_replacer, enum_flags); while (duk_next(thr, -1 /*enum_index*/, 1 /*get_value*/)) { /* ... proplist enum_obj key val */ @@ -39394,8 +40384,8 @@ DUK_DDD(DUK_DDDPRINT("proplist enum: key=%!T, val=%!T --> accept", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); - duk_to_string(thr, -1); /* extra coercion of strings is OK */ - duk_put_prop_index(thr, -4, plist_idx); /* -> ... proplist enum_obj key */ + duk_to_string(thr, -1); /* extra coercion of strings is OK */ + duk_put_prop_index(thr, -4, plist_idx); /* -> ... proplist enum_obj key */ plist_idx++; duk_pop(thr); } else { @@ -39404,8 +40394,8 @@ (duk_tval *) duk_get_tval(thr, -1))); duk_pop_2(thr); } - } - duk_pop(thr); /* pop enum */ + } + duk_pop(thr); /* pop enum */ /* ... proplist */ } @@ -39431,10 +40421,9 @@ duk_small_int_t nspace; /* spaces must be static to allow initializer with old compilers like BCC */ static const char spaces10 = { - DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, - DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, - DUK_ASC_SPACE, DUK_ASC_SPACE - }; /* XXX: helper */ + DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, + DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE + }; /* XXX: helper */ /* ToInteger() coercion; NaN -> 0, infinities are clamped to 0 and 10 */ nspace = (duk_small_int_t) duk_to_int_clamped(thr, idx_space, 0 /*minval*/, 10 /*maxval*/); @@ -39445,7 +40434,7 @@ DUK_ASSERT(js_ctx->h_gap != NULL); } else if (duk_is_string_notsymbol(thr, idx_space)) { duk_dup(thr, idx_space); - duk_substring(thr, -1, 0, 10); /* clamp to 10 chars */ + duk_substring(thr, -1, 0, 10); /* clamp to 10 chars */ js_ctx->h_gap = duk_known_hstring(thr, -1); } else { /* nop */ @@ -39469,8 +40458,8 @@ */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) - if (js_ctx->h_replacer == NULL && /* replacer is a mutation risk */ - js_ctx->idx_proplist == -1) { /* proplist is very rare */ + if (js_ctx->h_replacer == NULL && /* replacer is a mutation risk */ + js_ctx->idx_proplist == -1) { /* proplist is very rare */ duk_int_t pcall_rc; duk_small_uint_t prev_ms_base_flags; @@ -39495,10 +40484,9 @@ /* Must prevent finalizers which may have arbitrary side effects. */ prev_ms_base_flags = thr->heap->ms_base_flags; - thr->heap->ms_base_flags |= - DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact any objects. */ - thr->heap->pf_prevent_count++; /* Prevent finalizers. */ - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + thr->heap->ms_base_flags |= DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact any objects. */ + thr->heap->pf_prevent_count++; /* Prevent finalizers. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ pcall_rc = duk_safe_call(thr, duk__json_stringify_fast, (void *) js_ctx /*udata*/, 1 /*nargs*/, 0 /*nret*/); @@ -39549,7 +40537,7 @@ js_ctx->recursion_limit = DUK_USE_JSON_ENC_RECLIMIT; DUK_ASSERT(js_ctx->recursion_depth == 0); - if (DUK_UNLIKELY(duk__json_enc_value(js_ctx, idx_holder) == 0)) { /* ... holder key -> ... holder */ + if (DUK_UNLIKELY(duk__json_enc_value(js_ctx, idx_holder) == 0)) { /* ... holder key -> ... holder */ /* Result is undefined. */ duk_push_undefined(thr); } else { @@ -39571,7 +40559,7 @@ */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) - replace_finished: +replace_finished: #endif duk_replace(thr, entry_top); duk_set_top(thr, entry_top + 1); @@ -39595,25 +40583,18 @@ */ DUK_INTERNAL duk_ret_t duk_bi_json_object_parse(duk_hthread *thr) { - duk_bi_json_parse_helper(thr, - 0 /*idx_value*/, - 1 /*idx_replacer*/, - 0 /*flags*/); + duk_bi_json_parse_helper(thr, 0 /*idx_value*/, 1 /*idx_replacer*/, 0 /*flags*/); return 1; } DUK_INTERNAL duk_ret_t duk_bi_json_object_stringify(duk_hthread *thr) { - duk_bi_json_stringify_helper(thr, - 0 /*idx_value*/, - 1 /*idx_replacer*/, - 2 /*idx_space*/, - 0 /*flags*/); + duk_bi_json_stringify_helper(thr, 0 /*idx_value*/, 1 /*idx_replacer*/, 2 /*idx_space*/, 0 /*flags*/); return 1; } -#endif /* DUK_USE_JSON_BUILTIN */ +#endif /* DUK_USE_JSON_BUILTIN */ -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */ /* automatic undefs */ #undef DUK__EMIT_1 @@ -39771,7 +40752,7 @@ return x >= 0.0 ? DUK_FLOOR(x) : DUK_CEIL(x); #endif } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ DUK_LOCAL double duk__round_fixed(double x) { /* Numbers half-way between integers must be rounded towards +Infinity, @@ -39886,51 +40867,23 @@ return DUK_ATAN2(x, y); } -#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ +#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ /* order must match constants in genbuiltins.py */ DUK_LOCAL const duk__one_arg_func duk__one_arg_funcs = { #if defined(DUK_USE_AVOID_PLATFORM_FUNCPTRS) - duk__fabs, - duk__acos, - duk__asin, - duk__atan, - duk__ceil, - duk__cos, - duk__exp, - duk__floor, - duk__log, - duk__round_fixed, - duk__sin, - duk__sqrt, - duk__tan, + duk__fabs, duk__acos, duk__asin, duk__atan, duk__ceil, duk__cos, duk__exp, + duk__floor, duk__log, duk__round_fixed, duk__sin, duk__sqrt, duk__tan, #if defined(DUK_USE_ES6) - duk__cbrt, - duk__log2, - duk__log10, - duk__trunc -#endif -#else /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ - DUK_FABS, - DUK_ACOS, - DUK_ASIN, - DUK_ATAN, - DUK_CEIL, - DUK_COS, - DUK_EXP, - DUK_FLOOR, - DUK_LOG, - duk__round_fixed, - DUK_SIN, - DUK_SQRT, - DUK_TAN, + duk__cbrt, duk__log2, duk__log10, duk__trunc +#endif +#else /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ + DUK_FABS, DUK_ACOS, DUK_ASIN, DUK_ATAN, DUK_CEIL, DUK_COS, DUK_EXP, + DUK_FLOOR, DUK_LOG, duk__round_fixed, DUK_SIN, DUK_SQRT, DUK_TAN, #if defined(DUK_USE_ES6) - duk__cbrt, - duk__log2, - duk__log10, - duk__trunc + duk__cbrt, duk__log2, duk__log10, duk__trunc #endif -#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ +#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ }; /* order must match constants in genbuiltins.py */ @@ -39965,7 +40918,7 @@ DUK_ASSERT(fun_idx >= 0); DUK_ASSERT(fun_idx < (duk_small_int_t) (sizeof(duk__two_arg_funcs) / sizeof(duk__two_arg_func))); - arg1 = duk_to_number(thr, 0); /* explicit ordered evaluation to match coercion semantics */ + arg1 = duk_to_number(thr, 0); /* explicit ordered evaluation to match coercion semantics */ arg2 = duk_to_number(thr, 1); fun = duk__two_arg_funcsfun_idx; duk_push_number(thr, (duk_double_t) fun((double) arg1, (double) arg2)); @@ -39981,7 +40934,7 @@ } DUK_INTERNAL duk_ret_t duk_bi_math_object_random(duk_hthread *thr) { - duk_push_number(thr, (duk_double_t) DUK_UTIL_GET_RANDOM_DOUBLE(thr)); + duk_push_number(thr, (duk_double_t) duk_util_get_random_double(thr)); return 1; } @@ -40051,7 +41004,7 @@ duk_push_number(thr, (duk_double_t) DUK_SQRT(sum) * max); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_sign(duk_hthread *thr) { @@ -40060,7 +41013,7 @@ d = duk_to_number(thr, 0); if (duk_double_is_nan(d)) { DUK_ASSERT(duk_is_nan(thr, -1)); - return 1; /* NaN input -> return NaN */ + return 1; /* NaN input -> return NaN */ } if (duk_double_equals(d, 0.0)) { /* Zero sign kept, i.e. -0 -> -0, +0 -> +0. */ @@ -40069,7 +41022,7 @@ duk_push_int(thr, (d > 0.0 ? 1 : -1)); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_clz32(duk_hthread *thr) { @@ -40089,7 +41042,7 @@ DUK_ASSERT(i <= 32); duk_push_uint(thr, i); return 1; -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ i = 0; x = duk_to_uint32(thr, 0); if (x & 0xffff0000UL) { @@ -40125,9 +41078,9 @@ DUK_ASSERT(i <= 32); duk_push_uint(thr, i); return 1; -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_imul(duk_hthread *thr) { @@ -40144,9 +41097,9 @@ duk_push_i32(thr, (duk_int32_t) z); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_MATH_BUILTIN */ +#endif /* DUK_USE_MATH_BUILTIN */ /* * Number built-ins */ @@ -40168,8 +41121,7 @@ goto done; } h = duk_get_hobject(thr, -1); - if (!h || - (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_NUMBER)) { + if (!h || (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_NUMBER)) { DUK_DDD(DUK_DDDPRINT("unacceptable this value: %!T", (duk_tval *) duk_get_tval(thr, -1))); DUK_ERROR_TYPE(thr, "number expected"); DUK_WO_NORETURN(return 0.0;); @@ -40177,10 +41129,11 @@ duk_xget_owndataprop_stridx_short(thr, -1, DUK_STRIDX_INT_VALUE); DUK_ASSERT(duk_is_number(thr, -1)); DUK_DDD(DUK_DDDPRINT("number object: %!T, internal value: %!T", - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); duk_remove_m2(thr); - done: +done: return duk_get_number(thr, -1); } @@ -40229,9 +41182,9 @@ DUK_ASSERT(DUK_HOBJECT_GET_CLASS_NUMBER(h_this) == DUK_HOBJECT_CLASS_NUMBER); DUK_ASSERT(DUK_HOBJECT_HAS_EXTENSIBLE(h_this)); - duk_dup_0(thr); /* -> val obj val */ + duk_dup_0(thr); /* -> val obj val */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); - return 0; /* no return value -> don't replace created value */ + return 0; /* no return value -> don't replace created value */ } DUK_INTERNAL duk_ret_t duk_bi_number_prototype_value_of(duk_hthread *thr) { @@ -40253,10 +41206,7 @@ n2s_flags = 0; - duk_numconv_stringify(thr, - radix /*radix*/, - 0 /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, radix /*radix*/, 0 /*digits*/, n2s_flags /*flags*/); return 1; } @@ -40294,16 +41244,12 @@ goto use_to_string; } - n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | - DUK_N2S_FLAG_FRACTION_DIGITS; + n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | DUK_N2S_FLAG_FRACTION_DIGITS; - duk_numconv_stringify(thr, - 10 /*radix*/, - frac_digits /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, frac_digits /*digits*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: DUK_ASSERT_TOP(thr, 2); duk_to_string(thr, -1); return 1; @@ -40319,7 +41265,7 @@ d = duk__push_this_number_plain(thr); frac_undefined = duk_is_undefined(thr, 0); - duk_to_int(thr, 0); /* for side effects */ + duk_to_int(thr, 0); /* for side effects */ c = (duk_small_int_t) DUK_FPCLASSIFY(d); if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) { @@ -40328,16 +41274,12 @@ frac_digits = (duk_small_int_t) duk_to_int_check_range(thr, 0, 0, 20); - n2s_flags = DUK_N2S_FLAG_FORCE_EXP | - (frac_undefined ? 0 : DUK_N2S_FLAG_FIXED_FORMAT); + n2s_flags = DUK_N2S_FLAG_FORCE_EXP | (frac_undefined ? 0 : DUK_N2S_FLAG_FIXED_FORMAT); - duk_numconv_stringify(thr, - 10 /*radix*/, - frac_digits + 1 /*leading digit + fractions*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, frac_digits + 1 /*leading digit + fractions*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: DUK_ASSERT_TOP(thr, 2); duk_to_string(thr, -1); return 1; @@ -40362,7 +41304,7 @@ } DUK_ASSERT_TOP(thr, 2); - duk_to_int(thr, 0); /* for side effects */ + duk_to_int(thr, 0); /* for side effects */ c = (duk_small_int_t) DUK_FPCLASSIFY(d); if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) { @@ -40371,16 +41313,12 @@ prec = (duk_small_int_t) duk_to_int_check_range(thr, 0, 1, 21); - n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | - DUK_N2S_FLAG_NO_ZERO_PAD; + n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | DUK_N2S_FLAG_NO_ZERO_PAD; - duk_numconv_stringify(thr, - 10 /*radix*/, - prec /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, prec /*digits*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: /* Used when precision is undefined; also used for NaN (-> "NaN"), * and +/- infinity (-> "Infinity", "-Infinity"). */ @@ -40406,16 +41344,16 @@ d = duk_get_number(thr, 0); switch (magic) { - case 0: /* isFinite() */ + case 0: /* isFinite() */ ret = duk_double_is_finite(d); break; - case 1: /* isInteger() */ + case 1: /* isInteger() */ ret = duk_double_is_integer(d); break; - case 2: /* isNaN() */ + case 2: /* isNaN() */ ret = duk_double_is_nan(d); break; - default: /* isSafeInteger() */ + default: /* isSafeInteger() */ DUK_ASSERT(magic == 3); ret = duk_double_is_safe_integer(d); } @@ -40424,9 +41362,9 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_NUMBER_BUILTIN */ +#endif /* DUK_USE_NUMBER_BUILTIN */ /* * Object built-ins */ @@ -40448,8 +41386,8 @@ arg_mask = duk_get_type_mask(thr, 0); - if (!duk_is_constructor_call(thr) && /* not a constructor call */ - ((arg_mask & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) == 0)) { /* and argument not null or undefined */ + if (!duk_is_constructor_call(thr) && /* not a constructor call */ + ((arg_mask & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) == 0)) { /* and argument not null or undefined */ duk_to_object(thr, 0); return 1; } @@ -40459,13 +41397,8 @@ * promote to an object value. Lightfuncs and plain buffers are * coerced with ToObject() even they could also be returned as is. */ - if (arg_mask & (DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_STRING | - DUK_TYPE_MASK_BOOLEAN | - DUK_TYPE_MASK_NUMBER | - DUK_TYPE_MASK_POINTER | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_LIGHTFUNC)) { + if (arg_mask & (DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER | + DUK_TYPE_MASK_POINTER | DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_LIGHTFUNC)) { /* For DUK_TYPE_OBJECT the coercion is a no-op and could * be checked for explicitly, but Object(obj) calls are * not very common so opt for minimal footprint. @@ -40475,13 +41408,12 @@ } (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) && defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_assign(duk_hthread *thr) { @@ -40538,9 +41470,8 @@ DUK_ASSERT(proto != NULL || duk_is_null(thr, 0)); (void) duk_push_object_helper_proto(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), proto); if (!duk_is_undefined(thr, 1)) { @@ -40561,7 +41492,7 @@ return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_properties(duk_hthread *thr) { @@ -40576,11 +41507,9 @@ obj = duk_require_hobject_promote_mask(thr, 0, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); DUK_ASSERT(obj != NULL); - duk_to_object(thr, 1); /* properties object */ + duk_to_object(thr, 1); /* properties object */ - DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT", - (duk_tval *) duk_get_tval(thr, 0), - (duk_tval *) duk_get_tval(thr, 1))); + DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT", (duk_tval *) duk_get_tval(thr, 0), (duk_tval *) duk_get_tval(thr, 1))); /* * Two pass approach to processing the property descriptors. @@ -40593,7 +41522,7 @@ */ for (pass = 0; pass < 2; pass++) { - duk_set_top(thr, 2); /* -> hobject props */ + duk_set_top(thr, 2); /* -> hobject props */ duk_enum(thr, 1, DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_INCLUDE_SYMBOLS /*enum_flags*/); for (;;) { @@ -40613,12 +41542,7 @@ /* hobject props enum(props) key desc */ - duk_hobject_prepare_property_descriptor(thr, - 4 /*idx_desc*/, - &defprop_flags, - &idx_value, - &get, - &set); + duk_hobject_prepare_property_descriptor(thr, 4 /*idx_desc*/, &defprop_flags, &idx_value, &get, &set); /* hobject props enum(props) key desc multiple values */ @@ -40630,14 +41554,7 @@ key = duk_known_hstring(thr, 3); DUK_ASSERT(key != NULL); - duk_hobject_define_property_helper(thr, - defprop_flags, - obj, - key, - idx_value, - get, - set, - 1 /*throw_flag*/); + duk_hobject_define_property_helper(thr, defprop_flags, obj, key, idx_value, get, set, 1 /*throw_flag*/); } } @@ -40648,7 +41565,7 @@ duk_dup_0(thr); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_seal_freeze_shared(duk_hthread *thr) { @@ -40657,7 +41574,7 @@ duk_seal_freeze_raw(thr, 0, (duk_bool_t) duk_get_current_magic(thr) /*is_freeze*/); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_is_sealed_frozen_shared(duk_hthread *thr) { @@ -40669,34 +41586,33 @@ mask = duk_get_type_mask(thr, 0); if (mask & (DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { DUK_ASSERT(is_frozen == 0 || is_frozen == 1); - duk_push_boolean(thr, (mask & DUK_TYPE_MASK_LIGHTFUNC) ? - 1 : /* lightfunc always frozen and sealed */ - (is_frozen ^ 1)); /* buffer sealed but not frozen (index props writable) */ + duk_push_boolean(thr, + (mask & DUK_TYPE_MASK_LIGHTFUNC) ? 1 : /* lightfunc always frozen and sealed */ + (is_frozen ^ 1)); /* buffer sealed but not frozen (index props writable) */ } else { /* ES2015 Sections 19.1.2.12, 19.1.2.13: anything other than an object * is considered to be already sealed and frozen. */ h = duk_get_hobject(thr, 0); - duk_push_boolean(thr, (h == NULL) || - duk_hobject_object_is_sealed_frozen_helper(thr, h, is_frozen /*is_frozen*/)); + duk_push_boolean(thr, (h == NULL) || duk_hobject_object_is_sealed_frozen_helper(thr, h, is_frozen /*is_frozen*/)); } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_to_locale_string(duk_hthread *thr) { DUK_ASSERT_TOP(thr, 0); (void) duk_push_this_coercible_to_object(thr); duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_TO_STRING); -#if 0 /* This is mentioned explicitly in the E5.1 spec, but duk_call_method() checks for it in practice. */ +#if 0 /* This is mentioned explicitly in the E5.1 spec, but duk_call_method() checks for it in practice. */ duk_require_callable(thr, 1); #endif - duk_dup_0(thr); /* -> O toString O */ - duk_call_method(thr, 0); /* XXX: call method tail call? */ + duk_dup_0(thr); /* -> O toString O */ + duk_call_method(thr, 0); /* XXX: call method tail call? */ return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_value_of(duk_hthread *thr) { @@ -40704,7 +41620,7 @@ (void) duk_push_this_coercible_to_object(thr); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_is_prototype_of(duk_hthread *thr) { @@ -40715,7 +41631,7 @@ h_v = duk_get_hobject(thr, 0); if (!h_v) { - duk_push_false(thr); /* XXX: tail call: return duk_push_false(thr) */ + duk_push_false(thr); /* XXX: tail call: return duk_push_false(thr) */ return 1; } @@ -40725,22 +41641,24 @@ /* E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare. * Prototype loops should cause an error to be thrown. */ - duk_push_boolean(thr, duk_hobject_prototype_chain_contains(thr, DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_v), h_obj, 0 /*ignore_loop*/)); + duk_push_boolean( + thr, + duk_hobject_prototype_chain_contains(thr, DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_v), h_obj, 0 /*ignore_loop*/)); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_has_own_property(duk_hthread *thr) { return (duk_ret_t) duk_hobject_object_ownprop_helper(thr, 0 /*required_desc_flags*/); } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_property_is_enumerable(duk_hthread *thr) { return (duk_ret_t) duk_hobject_object_ownprop_helper(thr, DUK_PROPDESC_FLAG_ENUMERABLE /*required_desc_flags*/); } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper to implement Object.getPrototypeOf, @@ -40797,7 +41715,7 @@ } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper to implement ES2015 Object.setPrototypeOf, @@ -40816,7 +41734,7 @@ duk_hobject *h_obj; duk_hobject *h_new_proto; duk_hobject *h_curr; - duk_ret_t ret_success = 1; /* retval for success path */ + duk_ret_t ret_success = 1; /* retval for success path */ duk_uint_t mask; duk_int_t magic; @@ -40837,9 +41755,7 @@ if (magic == 1) { duk_require_object_coercible(thr, 0); } else { - duk_require_hobject_accept_mask(thr, 0, - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER); + duk_require_hobject_accept_mask(thr, 0, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); } duk_require_type_mask(thr, 1, DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_OBJECT); } @@ -40850,9 +41766,8 @@ mask = duk_get_type_mask(thr, 0); if (mask & (DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { duk_hobject *curr_proto; - curr_proto = thr->builtins(mask & DUK_TYPE_MASK_LIGHTFUNC) ? - DUK_BIDX_FUNCTION_PROTOTYPE : - DUK_BIDX_UINT8ARRAY_PROTOTYPE; + curr_proto = + thr->builtins(mask & DUK_TYPE_MASK_LIGHTFUNC) ? DUK_BIDX_FUNCTION_PROTOTYPE : DUK_BIDX_UINT8ARRAY_PROTOTYPE; if (h_new_proto == curr_proto) { goto skip; } @@ -40882,15 +41797,15 @@ DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h_obj, h_new_proto); /* fall thru */ - skip: +skip: duk_set_top(thr, 1); if (magic == 2) { duk_push_true(thr); } return ret_success; - fail_nonextensible: - fail_loop: +fail_nonextensible: +fail_loop: if (magic != 2) { DUK_DCERROR_TYPE_INVALID_ARGS(thr); } else { @@ -40898,7 +41813,7 @@ return 1; } } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_property(duk_hthread *thr) { @@ -40950,12 +41865,7 @@ * Lightfunc set/get values are coerced to full Functions. */ - duk_hobject_prepare_property_descriptor(thr, - 2 /*idx_desc*/, - &defprop_flags, - &idx_value, - &get, - &set); + duk_hobject_prepare_property_descriptor(thr, 2 /*idx_desc*/, &defprop_flags, &idx_value, &get, &set); /* * Use Object.defineProperty() helper for the actual operation. @@ -40963,14 +41873,7 @@ DUK_ASSERT(magic == 0U || magic == 1U); throw_flag = magic ^ 1U; - ret = duk_hobject_define_property_helper(thr, - defprop_flags, - obj, - key, - idx_value, - get, - set, - throw_flag); + ret = duk_hobject_define_property_helper(thr, defprop_flags, obj, key, idx_value, get, set, throw_flag); /* Ignore the normalize/validate helper outputs on the value stack, * they're popped automatically. @@ -40985,7 +41888,7 @@ } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_get_own_property_descriptor(duk_hthread *thr) { @@ -41001,7 +41904,7 @@ duk_hobject_object_get_own_property_descriptor(thr, -2); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_is_extensible(duk_hthread *thr) { @@ -41024,7 +41927,7 @@ duk_push_boolean(thr, (h != NULL) && DUK_HOBJECT_HAS_EXTENSIBLE(h)); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper for various key/symbol listings, magic: @@ -41035,26 +41938,17 @@ */ DUK_LOCAL const duk_small_uint_t duk__object_keys_enum_flags4 = { /* Object.keys() */ - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_NO_PROXY_BEHAVIOR, + DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Object.getOwnPropertyNames() */ - DUK_ENUM_INCLUDE_NONENUMERABLE | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_NO_PROXY_BEHAVIOR, + DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Object.getOwnPropertySymbols() */ - DUK_ENUM_INCLUDE_SYMBOLS | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_EXCLUDE_STRINGS | - DUK_ENUM_INCLUDE_NONENUMERABLE | + DUK_ENUM_INCLUDE_SYMBOLS | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_EXCLUDE_STRINGS | DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Reflect.ownKeys() */ - DUK_ENUM_INCLUDE_SYMBOLS | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_INCLUDE_NONENUMERABLE | - DUK_ENUM_NO_PROXY_BEHAVIOR + DUK_ENUM_INCLUDE_SYMBOLS | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_NO_PROXY_BEHAVIOR }; DUK_INTERNAL duk_ret_t duk_bi_object_constructor_keys_shared(duk_hthread *thr) { @@ -41086,9 +41980,7 @@ #if defined(DUK_USE_ES6_PROXY) /* XXX: better sharing of code between proxy target call sites */ - if (DUK_LIKELY(!duk_hobject_proxy_check(obj, - &h_proxy_target, - &h_proxy_handler))) { + if (DUK_LIKELY(!duk_hobject_proxy_check(obj, &h_proxy_target, &h_proxy_handler))) { goto skip_proxy; } @@ -41107,8 +41999,8 @@ /* obj handler trap */ duk_insert(thr, -2); - duk_push_hobject(thr, h_proxy_target); /* -> obj trap handler target */ - duk_call_method(thr, 1 /*nargs*/); /* -> obj trap_result */ + duk_push_hobject(thr, h_proxy_target); /* -> obj trap handler target */ + duk_call_method(thr, 1 /*nargs*/); /* -> obj trap_result */ h_trap_result = duk_require_hobject(thr, -1); DUK_UNREF(h_trap_result); @@ -41119,8 +42011,8 @@ duk_proxy_ownkeys_postprocess(thr, h_proxy_target, enum_flags); return 1; - skip_proxy: -#endif /* DUK_USE_ES6_PROXY */ +skip_proxy: +#endif /* DUK_USE_ES6_PROXY */ DUK_ASSERT_TOP(thr, 1); magic = duk_get_current_magic(thr); @@ -41128,7 +42020,7 @@ enum_flags = duk__object_keys_enum_flagsmagic; return duk_hobject_get_enumerated_keys(thr, enum_flags); } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_prevent_extensions(duk_hthread *thr) { @@ -41148,12 +42040,8 @@ /* Object.preventExtensions() silent success for non-object. */ if (magic == 0) { - mask |= DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_BOOLEAN | - DUK_TYPE_MASK_NUMBER | - DUK_TYPE_MASK_STRING | - DUK_TYPE_MASK_POINTER; + mask |= DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER | + DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_POINTER; } if (duk_check_type_mask(thr, 0, mask)) { @@ -41170,13 +42058,13 @@ */ duk_hobject_compact_props(thr, h); - done: +done: if (magic == 1) { duk_push_true(thr); } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ /* * __defineGetter__, __defineSetter__, __lookupGetter__, __lookupSetter__ @@ -41192,9 +42080,10 @@ /* ToObject(this) key getter/setter */ /* ToPropertyKey() coercion is not needed, duk_def_prop() does it. */ - duk_def_prop(thr, 0, DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE | - (duk_get_current_magic(thr) ? DUK_DEFPROP_HAVE_SETTER : DUK_DEFPROP_HAVE_GETTER)); + duk_def_prop(thr, + 0, + DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE | + (duk_get_current_magic(thr) ? DUK_DEFPROP_HAVE_SETTER : DUK_DEFPROP_HAVE_GETTER)); return 0; } DUK_INTERNAL duk_ret_t duk_bi_object_prototype_lookupaccessor(duk_hthread *thr) { @@ -41229,7 +42118,7 @@ } return 1; } -#endif /* DUK_USE_ES8 */ +#endif /* DUK_USE_ES8 */ /* * High resolution time API (performance.now() et al) * @@ -41250,7 +42139,7 @@ return 1; } -#if 0 /* Missing until semantics decided. */ +#if 0 /* Missing until semantics decided. */ DUK_INTERNAL duk_ret_t duk_bi_performance_timeorigin_getter(duk_hthread *thr) { /* No decision yet how to handle timeOrigins, e.g. should one be * initialized per heap, or per global object set. See @@ -41259,8 +42148,8 @@ duk_push_uint(thr, 0); return 1; } -#endif /* 0 */ -#endif /* DUK_USE_PERFORMANCE_BUILTIN */ +#endif /* 0 */ +#endif /* DUK_USE_PERFORMANCE_BUILTIN */ /* * Pointer built-ins */ @@ -41286,9 +42175,8 @@ if (duk_is_constructor_call(thr)) { (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER), DUK_BIDX_POINTER_PROTOTYPE); /* Pointer object internal value is immutable. */ @@ -41333,7 +42221,7 @@ } return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } /* @@ -41379,7 +42267,7 @@ DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_PROMISE_BUILTIN */ +#endif /* DUK_USE_PROMISE_BUILTIN */ /* * Proxy built-in (ES2015) */ @@ -41450,7 +42338,7 @@ duk_def_prop(thr, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_SET_WEC); continue; - skip_key: + skip_key: duk_pop(thr); continue; } @@ -41467,17 +42355,17 @@ * handled above. */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ES6_PROXY) DUK_INTERNAL duk_ret_t duk_bi_proxy_constructor(duk_hthread *thr) { - DUK_ASSERT_TOP(thr, 2); /* target handler */ + DUK_ASSERT_TOP(thr, 2); /* target handler */ duk_require_constructor_call(thr); - duk_push_proxy(thr, 0 /*flags*/); /* target handler -> proxy */ - return 1; /* replacement */ + duk_push_proxy(thr, 0 /*flags*/); /* target handler -> proxy */ + return 1; /* replacement */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* * 'Reflect' built-in (ES2016 Section 26.1) * http://www.ecma-international.org/ecma-262/7.0/#sec-reflect-object @@ -41527,7 +42415,7 @@ tv_obj = DUK_GET_TVAL_POSIDX(thr, 0); tv_key = DUK_GET_TVAL_POSIDX(thr, 1); - (void) duk_hobject_getprop(thr, tv_obj, tv_key); /* This could also be a duk_get_prop(). */ + (void) duk_hobject_getprop(thr, tv_obj, tv_key); /* This could also be a duk_get_prop(). */ return 1; } @@ -41576,7 +42464,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_REFLECT_BUILTIN */ /* * RegExp built-ins */ @@ -41592,7 +42480,7 @@ h = duk_require_hobject_with_class(thr, -1, DUK_HOBJECT_CLASS_REGEXP); DUK_ASSERT(h != NULL); DUK_UNREF(h); - duk_insert(thr, 0); /* prepend regexp to valstack 0 index */ + duk_insert(thr, 0); /* prepend regexp to valstack 0 index */ } /* XXX: much to improve (code size) */ @@ -41602,10 +42490,8 @@ DUK_ASSERT_TOP(thr, 2); h_pattern = duk_get_hobject(thr, 0); - if (!duk_is_constructor_call(thr) && - h_pattern != NULL && - DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP && - duk_is_undefined(thr, 1)) { + if (!duk_is_constructor_call(thr) && h_pattern != NULL && + DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP && duk_is_undefined(thr, 1)) { /* Called as a function, pattern has Class "RegExp" and * flags is undefined -> return object as is. */ @@ -41620,8 +42506,7 @@ * call. */ - if (h_pattern != NULL && - DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP) { + if (h_pattern != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP) { duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_SOURCE); if (duk_is_undefined(thr, 1)) { /* In ES5 one would need to read the flags individually; @@ -41637,20 +42522,21 @@ duk_push_hstring_empty(thr); } else { duk_dup_0(thr); - duk_to_string(thr, -1); /* Rejects Symbols. */ + duk_to_string(thr, -1); /* Rejects Symbols. */ } if (duk_is_undefined(thr, 1)) { duk_push_hstring_empty(thr); } else { duk_dup_1(thr); - duk_to_string(thr, -1); /* Rejects Symbols. */ + duk_to_string(thr, -1); /* Rejects Symbols. */ } /* ... pattern flags */ } DUK_DDD(DUK_DDDPRINT("RegExp constructor/function call, pattern=%!T, flags=%!T", - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); /* ... pattern flags (both uncoerced) */ @@ -41700,7 +42586,7 @@ duk_push_this(thr); duk_push_literal(thr, "/"); duk_get_prop_stridx(thr, 0, DUK_STRIDX_SOURCE); - duk_dup_m2(thr); /* another "/" */ + duk_dup_m2(thr); /* another "/" */ duk_get_prop_stridx(thr, 0, DUK_STRIDX_FLAGS); duk_concat(thr, 4); return 1; @@ -41710,7 +42596,7 @@ /* .flags is ES2015 but present even when ES2015 bindings are * disabled because the constructor relies on it. */ - duk_uint8_t buf8; /* enough for all flags + NUL */ + duk_uint8_t buf8; /* enough for all flags + NUL */ duk_uint8_t *p = buf; /* .flags is generic and works on any object. */ @@ -41751,7 +42637,7 @@ duk_xget_owndataprop_stridx_short(thr, 0, DUK_STRIDX_INT_SOURCE); duk_xget_owndataprop_stridx_short(thr, 0, DUK_STRIDX_INT_BYTECODE); h_bc = duk_require_hstring(thr, -1); - re_flags = (duk_small_uint_t) DUK_HSTRING_GET_DATA(h_bc)0; /* Safe even if h_bc length is 0 (= NUL) */ + re_flags = (duk_small_uint_t) DUK_HSTRING_GET_DATA(h_bc)0; /* Safe even if h_bc length is 0 (= NUL) */ duk_pop(thr); } else if (h == thr->builtinsDUK_BIDX_REGEXP_PROTOTYPE) { /* In ES2015 and ES2016 a TypeError would be thrown here. @@ -41762,7 +42648,7 @@ if (magic != 16 /* .source */) { return 0; } - duk_push_literal(thr, "(?:)"); /* .source handled by switch-case */ + duk_push_literal(thr, "(?:)"); /* .source handled by switch-case */ re_flags = 0; } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -41771,15 +42657,15 @@ /* regexp source */ switch (magic) { - case 0: { /* global */ + case 0: { /* global */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_GLOBAL)); break; } - case 1: { /* ignoreCase */ + case 1: { /* ignoreCase */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_IGNORE_CASE)); break; } - case 2: { /* multiline */ + case 2: { /* multiline */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_MULTILINE)); break; } @@ -41793,7 +42679,7 @@ break; } #endif - default: { /* source */ + default: { /* source */ /* leave 'source' on top */ break; } @@ -41802,7 +42688,7 @@ return 1; } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* * String built-ins * @@ -41841,7 +42727,8 @@ return h; } -DUK_LOCAL duk_int_t duk__str_search_shared(duk_hthread *thr, duk_hstring *h_this, duk_hstring *h_search, duk_int_t start_cpos, duk_bool_t backwards) { +DUK_LOCAL duk_int_t +duk__str_search_shared(duk_hthread *thr, duk_hstring *h_this, duk_hstring *h_search, duk_int_t start_cpos, duk_bool_t backwards) { duk_int_t cpos; duk_int_t bpos; const duk_uint8_t *p_start, *p_end, *p; @@ -41876,7 +42763,7 @@ * must be updated if 'p' is wound back (backward scanning). */ - firstbyte = q_start0; /* leading byte of match string */ + firstbyte = q_start0; /* leading byte of match string */ while (p <= p_end && p >= p_start) { t = *p; @@ -41942,15 +42829,13 @@ duk_replace(thr, 0); } } - duk_to_string(thr, 0); /* catches symbol argument for constructor call */ + duk_to_string(thr, 0); /* catches symbol argument for constructor call */ DUK_ASSERT(duk_is_string(thr, 0)); - duk_set_top(thr, 1); /* Top may be 1 or larger. */ + duk_set_top(thr, 1); /* Top may be 1 or larger. */ if (duk_is_constructor_call(thr)) { /* String object internal value is immutable */ - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_STRING); duk_push_object_helper(thr, flags, DUK_BIDX_STRING_PROTOTYPE); duk_dup_0(thr); @@ -41976,7 +42861,7 @@ n = duk_get_top(thr); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, (duk_size_t) n); /* initial estimate for ASCII only codepoints */ + DUK_BW_INIT_PUSHBUF(thr, bw, (duk_size_t) n); /* initial estimate for ASCII only codepoints */ for (i = 0; i < n; i++) { /* XXX: could improve bufwriter handling to write multiple codepoints @@ -41990,8 +42875,7 @@ * the same. */ duk_int32_t i32 = 0; - if (!duk_is_whole_get_int32(duk_to_number(thr, i), &i32) || - i32 < 0 || i32 > 0x10ffffL) { + if (!duk_is_whole_get_int32(duk_to_number(thr, i), &i32) || i32 < 0 || i32 > 0x10ffffL) { DUK_DCERROR_RANGE_INVALID_ARGS(thr); } DUK_ASSERT(i32 >= 0 && i32 <= 0x10ffffL); @@ -42015,7 +42899,7 @@ } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 or CESU-8 encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 or CESU-8 encoded. */ return 1; } @@ -42057,10 +42941,10 @@ goto type_error; } - (void) duk_require_hstring_notsymbol(thr, -1); /* Reject symbols (and wrapped symbols). */ + (void) duk_require_hstring_notsymbol(thr, -1); /* Reject symbols (and wrapped symbols). */ return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -42196,7 +43080,7 @@ * ("undefined" and "null"). */ duk_push_this(thr); - h = duk_to_hstring_m1(thr); /* Reject Symbols. */ + h = duk_to_hstring_m1(thr); /* Reject Symbols. */ DUK_ASSERT(h != NULL); len = (duk_int_t) DUK_HSTRING_GET_CHARLEN(h); @@ -42228,7 +43112,7 @@ duk_substring(thr, -1, (duk_size_t) start_pos, (duk_size_t) end_pos); return 1; } -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_slice(duk_hthread *thr) { duk_hstring *h; @@ -42287,7 +43171,7 @@ duk_hstring *h_search; duk_int_t clen_this; duk_int_t cpos; - duk_small_uint_t is_lastindexof = (duk_small_uint_t) duk_get_current_magic(thr); /* 0=indexOf, 1=lastIndexOf */ + duk_small_uint_t is_lastindexof = (duk_small_uint_t) duk_get_current_magic(thr); /* 0=indexOf, 1=lastIndexOf */ h_this = duk_push_this_coercible_to_string(thr); DUK_ASSERT(h_this != NULL); @@ -42344,7 +43228,7 @@ duk_int_t match_caps; #endif duk_uint32_t prev_match_end_boff; - const duk_uint8_t *r_start, *r_end, *r; /* repl string scan */ + const duk_uint8_t *r_start, *r_end, *r; /* repl string scan */ duk_size_t tmp_sz; DUK_ASSERT_TOP(thr, 2); @@ -42352,7 +43236,7 @@ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* input size is good output starting point */ + DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* input size is good output starting point */ DUK_ASSERT_TOP(thr, 4); @@ -42373,11 +43257,11 @@ duk_push_int(thr, 0); duk_put_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ DUK_DCERROR_UNSUPPORTED(thr); -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } else { - duk_to_string(thr, 0); /* rejects symbols */ + duk_to_string(thr, 0); /* rejects symbols */ #if defined(DUK_USE_REGEXP_SUPPORT) is_regexp = 0; is_global = 0; @@ -42392,7 +43276,7 @@ duk_hstring *h_repl; is_repl_func = 0; - h_repl = duk_to_hstring(thr, 1); /* reject symbols */ + h_repl = duk_to_hstring(thr, 1); /* reject symbols */ DUK_ASSERT(h_repl != NULL); r_start = DUK_HSTRING_GET_DATA(h_repl); r_end = r_start + DUK_HSTRING_GET_BYTELEN(h_repl); @@ -42430,7 +43314,7 @@ if (is_regexp) { duk_dup_0(thr); duk_dup_2(thr); - duk_regexp_match(thr); /* ... regexp input -> res_obj */ + duk_regexp_match(thr); /* ... regexp input -> res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); break; @@ -42444,7 +43328,7 @@ duk_get_prop_index(thr, -1, 0); DUK_ASSERT(duk_is_string(thr, -1)); h_match = duk_known_hstring(thr, -1); - duk_pop(thr); /* h_match is borrowed, remains reachable through match_obj */ + duk_pop(thr); /* h_match is borrowed, remains reachable through match_obj */ if (DUK_HSTRING_GET_BYTELEN(h_match) == 0) { /* This should be equivalent to match() algorithm step 8.f.iii.2: @@ -42455,25 +43339,26 @@ duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); last_index = (duk_uint32_t) duk_get_uint(thr, -1); DUK_DDD(DUK_DDDPRINT("empty match, bump lastIndex: %ld -> %ld", - (long) last_index, (long) (last_index + 1))); + (long) last_index, + (long) (last_index + 1))); duk_pop(thr); duk_push_uint(thr, (duk_uint_t) (last_index + 1)); duk_put_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); } - DUK_ASSERT(duk_get_length(thr, -1) <= DUK_INT_MAX); /* string limits */ + DUK_ASSERT(duk_get_length(thr, -1) <= DUK_INT_MAX); /* string limits */ match_caps = (duk_int_t) duk_get_length(thr, -1); } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ - const duk_uint8_t *q_start; /* match string */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ + const duk_uint8_t *q_start; /* match string */ duk_size_t p_blen; duk_size_t q_blen; #if defined(DUK_USE_REGEXP_SUPPORT) - DUK_ASSERT(!is_global); /* single match always */ + DUK_ASSERT(!is_global); /* single match always */ #endif p_start = DUK_HSTRING_GET_DATA(h_input); @@ -42486,10 +43371,10 @@ q_blen = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_search); if (q_blen > p_blen) { - break; /* no match */ + break; /* no match */ } - p_end -= q_blen; /* ensure full memcmp() fits in while */ + p_end -= q_blen; /* ensure full memcmp() fits in while */ DUK_ASSERT(p_end >= p); match_start_coff = 0; @@ -42515,7 +43400,7 @@ /* not found */ break; } - found: + found: /* stack0 = search value * stack1 = replace value @@ -42549,9 +43434,9 @@ duk_get_prop_index(thr, 4, (duk_uarridx_t) idx); } } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* match == search string, by definition */ duk_dup_0(thr); } @@ -42561,12 +43446,12 @@ /* ... replacer match captures match_char_offset input */ duk_call(thr, duk_get_top(thr) - idx_args); - h_repl = duk_to_hstring_m1(thr); /* -> ... repl_value */ + h_repl = duk_to_hstring_m1(thr); /* -> ... repl_value */ DUK_ASSERT(h_repl != NULL); DUK_BW_WRITE_ENSURE_HSTRING(thr, bw, h_repl); - duk_pop(thr); /* repl_value */ + duk_pop(thr); /* repl_value */ } else { r = r_start; @@ -42613,9 +43498,10 @@ * match codepoint encodings would have different lengths. */ /* XXX: charlen computed here, and also in char2byte helper. */ - match_end_boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte(thr, - h_input, - match_start_coff + (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_match)); + match_end_boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte( + thr, + h_input, + match_start_coff + (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_match)); tmp_sz = (duk_size_t) (DUK_HSTRING_GET_BYTELEN(h_input) - match_end_boff); DUK_BW_WRITE_ENSURE_BYTES(thr, bw, DUK_HSTRING_GET_DATA(h_input) + match_end_boff, tmp_sz); @@ -42651,7 +43537,7 @@ } if (capnum > 0 && capnum < match_caps) { - DUK_ASSERT(is_regexp != 0); /* match_caps == 0 without regexps */ + DUK_ASSERT(is_regexp != 0); /* match_caps == 0 without regexps */ /* regexp res_obj is at offset 4 */ duk_get_prop_index(thr, 4, (duk_uarridx_t) capnum); @@ -42670,26 +43556,26 @@ } else { goto repl_write; } -#else /* DUK_USE_REGEXP_SUPPORT */ - goto repl_write; /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - } /* default case */ - } /* switch (ch2) */ +#else /* DUK_USE_REGEXP_SUPPORT */ + goto repl_write; /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + } /* default case */ + } /* switch (ch2) */ - repl_write: + repl_write: /* ch1 = (r_increment << 8) + byte */ DUK_BW_WRITE_ENSURE_U8(thr, bw, (duk_uint8_t) (ch1 & 0xff)); r += ch1 >> 8; - } /* while repl */ - } /* if (is_repl_func) */ + } /* while repl */ + } /* if (is_repl_func) */ - duk_pop(thr); /* pop regexp res_obj or match string */ + duk_pop(thr); /* pop regexp res_obj or match string */ #if defined(DUK_USE_REGEXP_SUPPORT) if (!is_global) { #else - { /* unconditionally; is_global==0 */ + { /* unconditionally; is_global==0 */ #endif break; } @@ -42701,7 +43587,7 @@ DUK_ASSERT_TOP(thr, 4); DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ return 1; } @@ -42721,7 +43607,7 @@ #if defined(DUK_USE_REGEXP_SUPPORT) duk_bool_t is_regexp; #endif - duk_bool_t matched; /* set to 1 if any match exists (needed for empty input special case) */ + duk_bool_t matched; /* set to 1 if any match exists (needed for empty input special case) */ duk_uint32_t prev_match_end_coff, prev_match_end_boff; duk_uint32_t match_start_boff, match_start_coff; duk_uint32_t match_end_boff, match_end_coff; @@ -42759,7 +43645,7 @@ #if defined(DUK_USE_REGEXP_SUPPORT) duk_push_hobject_bidx(thr, DUK_BIDX_REGEXP_CONSTRUCTOR); duk_dup_0(thr); - duk_new(thr, 1); /* ... RegExp val -> ... res */ + duk_new(thr, 1); /* ... RegExp val -> ... res */ duk_replace(thr, 0); /* lastIndex is initialized to zero by new RegExp() */ is_regexp = 1; @@ -42798,7 +43684,7 @@ if (is_regexp) { duk_dup_0(thr); duk_dup_2(thr); - duk_regexp_match_force_global(thr); /* ... regexp input -> res_obj */ + duk_regexp_match_force_global(thr); /* ... regexp input -> res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); break; @@ -42831,23 +43717,23 @@ continue; } } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ - const duk_uint8_t *q_start; /* match string */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ + const duk_uint8_t *q_start; /* match string */ duk_size_t q_blen, q_clen; p_start = DUK_HSTRING_GET_DATA(h_input); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); p = p_start + prev_match_end_boff; - h_sep = duk_known_hstring(thr, 0); /* symbol already rejected above */ + h_sep = duk_known_hstring(thr, 0); /* symbol already rejected above */ q_start = DUK_HSTRING_GET_DATA(h_sep); q_blen = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sep); q_clen = (duk_size_t) DUK_HSTRING_GET_CHARLEN(h_sep); - p_end -= q_blen; /* ensure full memcmp() fits in while */ + p_end -= q_blen; /* ensure full memcmp() fits in while */ match_start_coff = prev_match_end_coff; @@ -42860,7 +43746,7 @@ * Don't allow an empty string to match at the end of the input. */ - matched = 1; /* empty separator can always match */ + matched = 1; /* empty separator can always match */ match_start_coff++; p++; @@ -42876,7 +43762,7 @@ DUK_ASSERT(q_blen > 0 && q_clen > 0); while (p <= p_end) { DUK_ASSERT(p + q_blen <= DUK_HSTRING_GET_DATA(h_input) + DUK_HSTRING_GET_BYTELEN(h_input)); - DUK_ASSERT(q_blen > 0); /* no issues with empty memcmp() */ + DUK_ASSERT(q_blen > 0); /* no issues with empty memcmp() */ if (duk_memcmp((const void *) p, (const void *) q_start, (size_t) q_blen) == 0) { /* never an empty match, so step 13.c.iii can't be triggered */ goto found; @@ -42889,15 +43775,15 @@ p++; } - not_found: + not_found: /* not found */ break; - found: + found: matched = 1; match_start_boff = (duk_uint32_t) (p - p_start); - match_end_coff = (duk_uint32_t) (match_start_coff + q_clen); /* constrained by string length */ - match_end_boff = (duk_uint32_t) (match_start_boff + q_blen); /* ditto */ + match_end_coff = (duk_uint32_t) (match_start_coff + q_clen); /* constrained by string length */ + match_end_boff = (duk_uint32_t) (match_start_boff + q_blen); /* ditto */ /* empty match (may happen with empty separator) -> bump and continue */ if (prev_match_end_boff == match_end_boff) { @@ -42905,7 +43791,7 @@ prev_match_end_coff++; continue; } - } /* if (is_regexp) */ + } /* if (is_regexp) */ /* stack0 = separator (string or regexp) * stack1 = limit @@ -42915,9 +43801,12 @@ */ DUK_DDD(DUK_DDDPRINT("split; match_start b=%ld,c=%ld, match_end b=%ld,c=%ld, prev_end b=%ld,c=%ld", - (long) match_start_boff, (long) match_start_coff, - (long) match_end_boff, (long) match_end_coff, - (long) prev_match_end_boff, (long) prev_match_end_coff)); + (long) match_start_boff, + (long) match_start_coff, + (long) match_end_boff, + (long) match_end_coff, + (long) prev_match_end_boff, + (long) prev_match_end_coff)); duk_push_lstring(thr, (const char *) (DUK_HSTRING_GET_DATA(h_input) + prev_match_end_boff), @@ -42934,7 +43823,7 @@ len = duk_get_length(thr, 4); for (i = 1; i < len; i++) { - DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* cannot have >4G captures */ + DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* cannot have >4G captures */ duk_get_prop_index(thr, 4, (duk_uarridx_t) i); duk_put_prop_index(thr, 3, arr_idx); arr_idx++; @@ -42946,21 +43835,21 @@ duk_pop(thr); /* lastIndex already set up for next match */ } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { + /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* no action */ } prev_match_end_boff = match_end_boff; prev_match_end_coff = match_end_coff; continue; - } /* for */ + } /* for */ /* Combined step 11 (empty string special case) and 14-15. */ - DUK_DDD(DUK_DDDPRINT("split trailer; prev_end b=%ld,c=%ld", - (long) prev_match_end_boff, (long) prev_match_end_coff)); + DUK_DDD(DUK_DDDPRINT("split trailer; prev_end b=%ld,c=%ld", (long) prev_match_end_boff, (long) prev_match_end_coff)); if (DUK_HSTRING_GET_BYTELEN(h_input) > 0 || !matched) { /* Add trailer if: @@ -42977,7 +43866,7 @@ return 1; - hit_limit: +hit_limit: #if defined(DUK_USE_REGEXP_SUPPORT) if (is_regexp) { duk_pop(thr); @@ -43009,13 +43898,13 @@ } return; - do_new: +do_new: duk_push_hobject_bidx(thr, DUK_BIDX_REGEXP_CONSTRUCTOR); duk_dup(thr, idx); - duk_new(thr, 1); /* ... RegExp val -> ... res */ + duk_new(thr, 1); /* ... RegExp val -> ... res */ duk_replace(thr, idx); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_search(duk_hthread *thr) { @@ -43030,7 +43919,7 @@ */ DUK_ASSERT_TOP(thr, 1); - (void) duk_push_this_coercible_to_string(thr); /* at index 1 */ + (void) duk_push_this_coercible_to_string(thr); /* at index 1 */ duk__to_regexp_helper(thr, 0 /*index*/, 1 /*force_new*/); /* stack0 = regexp @@ -43042,8 +43931,8 @@ */ duk_dup_0(thr); - duk_dup_1(thr); /* ... re_obj input */ - duk_regexp_match(thr); /* -> ... res_obj */ + duk_dup_1(thr); /* ... re_obj input */ + duk_regexp_match(thr); /* -> ... res_obj */ if (!duk_is_object(thr, -1)) { duk_push_int(thr, -1); @@ -43054,7 +43943,7 @@ DUK_ASSERT(duk_is_number(thr, -1)); return 1; } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_match(duk_hthread *thr) { @@ -43074,8 +43963,8 @@ */ if (!global) { - duk_regexp_match(thr); /* -> res_obj */ - return 1; /* return 'res_obj' */ + duk_regexp_match(thr); /* -> res_obj */ + return 1; /* return 'res_obj' */ } /* Global case is more complex. */ @@ -43096,7 +43985,7 @@ duk_dup_0(thr); duk_dup_1(thr); - duk_regexp_match(thr); /* -> ... regexp string -> ... res_obj */ + duk_regexp_match(thr); /* -> ... regexp string -> ... res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); @@ -43115,24 +44004,24 @@ } prev_last_index = this_index; - duk_get_prop_index(thr, -1, 0); /* match string */ + duk_get_prop_index(thr, -1, 0); /* match string */ duk_put_prop_index(thr, 2, (duk_uarridx_t) arr_idx); arr_idx++; - duk_pop(thr); /* res_obj */ + duk_pop(thr); /* res_obj */ } if (arr_idx == 0) { duk_push_null(thr); } - return 1; /* return 'res_arr' or 'null' */ + return 1; /* return 'res_arr' or 'null' */ } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_concat(duk_hthread *thr) { /* duk_concat() coerces arguments with ToString() in correct order */ (void) duk_push_this_coercible_to_string(thr); - duk_insert(thr, 0); /* this is relatively expensive */ + duk_insert(thr, 0); /* this is relatively expensive */ duk_concat(thr, duk_get_top(thr)); return 1; } @@ -43197,10 +44086,10 @@ #if defined(DUK_USE_PREFER_SIZE) p = buf; while (count-- > 0) { - duk_memcpy((void *) p, (const void *) src, input_blen); /* copy size may be zero, but pointers are valid */ + duk_memcpy((void *) p, (const void *) src, input_blen); /* copy size may be zero, but pointers are valid */ p += input_blen; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* Take advantage of already copied pieces to speed up the process * especially for small repeated strings. */ @@ -43210,7 +44099,9 @@ for (;;) { duk_size_t remain = (duk_size_t) (p_end - p); DUK_DDD(DUK_DDDPRINT("remain=%ld, copy_size=%ld, input_blen=%ld, result_len=%ld", - (long) remain, (long) copy_size, (long) input_blen, + (long) remain, + (long) copy_size, + (long) input_blen, (long) result_len)); if (remain <= copy_size) { /* If result_len is zero, this case is taken and does @@ -43223,10 +44114,10 @@ p += copy_size; } - src = (const duk_uint8_t *) buf; /* Use buf as source for larger copies. */ + src = (const duk_uint8_t *) buf; /* Use buf as source for larger copies. */ copy_size = (duk_size_t) (p - buf); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* XXX: It would be useful to be able to create a duk_hstring with * a certain byte size whose data area wasn't initialized and which @@ -43237,13 +44128,13 @@ * intern table (they are not in heap_allocated). */ - duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ + duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ return 1; - fail_range: +fail_range: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_locale_compare(duk_hthread *thr) { duk_hstring *h1; @@ -43297,7 +44188,7 @@ ret = -1; goto done; - done: +done: duk_push_int(thr, (duk_int_t) ret); return 1; } @@ -43384,11 +44275,11 @@ } } - finish: +finish: duk_push_boolean(thr, result); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_includes(duk_hthread *thr) { @@ -43411,8 +44302,8 @@ duk_push_boolean(thr, pos >= 0); return 1; } -#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_STRING_BUILTIN */ +#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_STRING_BUILTIN */ /* * Symbol built-in */ @@ -43454,7 +44345,7 @@ buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, 1 + len + 1 + 17 + 1); DUK_ASSERT(buf != NULL); p = buf + 1; - DUK_ASSERT(desc != NULL || len == 0); /* may be NULL if len is 0 */ + DUK_ASSERT(desc != NULL || len == 0); /* may be NULL if len is 0 */ duk_memcpy_unsafe((void *) p, (const void *) desc, len); p += len; if (magic == 0) { @@ -43465,7 +44356,9 @@ if (++thr->heap->sym_counter0 == 0) { thr->heap->sym_counter1++; } - p += DUK_SPRINTF((char *) p, "\xFF" "%lx-%lx", + p += DUK_SPRINTF((char *) p, + "\xFF" + "%lx-%lx", (unsigned long) thr->heap->sym_counter1, (unsigned long) thr->heap->sym_counter0); if (desc == NULL) { @@ -43582,7 +44475,7 @@ return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ /* * Thread builtins */ @@ -43616,7 +44509,7 @@ */ duk_push_hobject(new_thr, func); - return 1; /* return thread */ + return 1; /* return thread */ } #endif @@ -43662,14 +44555,15 @@ */ if (thr->callstack_top < 2) { - DUK_DD(DUK_DDPRINT("resume state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.resume)")); + DUK_DD(DUK_DDPRINT( + "resume state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.resume)")); goto state_error; } DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr))); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ caller_func = DUK_ACT_GET_FUNC(thr->callstack_curr->parent); if (!DUK_HOBJECT_IS_COMPFUNC(caller_func)) { @@ -43681,14 +44575,12 @@ * like for yield. */ - if (thr_resume->state != DUK_HTHREAD_STATE_INACTIVE && - thr_resume->state != DUK_HTHREAD_STATE_YIELDED) { + if (thr_resume->state != DUK_HTHREAD_STATE_INACTIVE && thr_resume->state != DUK_HTHREAD_STATE_YIELDED) { DUK_DD(DUK_DDPRINT("resume state invalid: target thread must be INACTIVE or YIELDED")); goto state_error; } - DUK_ASSERT(thr_resume->state == DUK_HTHREAD_STATE_INACTIVE || - thr_resume->state == DUK_HTHREAD_STATE_YIELDED); + DUK_ASSERT(thr_resume->state == DUK_HTHREAD_STATE_INACTIVE || thr_resume->state == DUK_HTHREAD_STATE_YIELDED); /* Further state-dependent pre-checks */ @@ -43706,14 +44598,13 @@ * because an error in the RESUME handler call processing will * not be handled very cleanly. */ - if ((thr_resume->callstack_top != 0) || - (thr_resume->valstack_top - thr_resume->valstack != 1)) { + if ((thr_resume->callstack_top != 0) || (thr_resume->valstack_top - thr_resume->valstack != 1)) { goto state_error; } duk_push_tval(thr, DUK_GET_TVAL_NEGIDX(thr_resume, -1)); duk_resolve_nonbound_function(thr); - h_fun = duk_require_hobject(thr, -1); /* reject lightfuncs on purpose */ + h_fun = duk_require_hobject(thr, -1); /* reject lightfuncs on purpose */ if (!DUK_HOBJECT_IS_CALLABLE(h_fun) || !DUK_HOBJECT_IS_COMPFUNC(h_fun)) { goto state_error; } @@ -43742,8 +44633,8 @@ #if defined(DUK_USE_AUGMENT_ERROR_THROW) if (is_error) { - DUK_ASSERT_TOP(thr, 2); /* value (error) is at stack top */ - duk_err_augment_error_throw(thr); /* in resumer's context */ + DUK_ASSERT_TOP(thr, 2); /* value (error) is at stack top */ + duk_err_augment_error_throw(thr); /* in resumer's context */ } #endif @@ -43767,21 +44658,21 @@ /* lj value2: thread */ DUK_ASSERT(thr->valstack_bottom < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value2, &thr->valstack_bottom0); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value2, &thr->valstack_bottom0); /* side effects */ /* lj value1: value */ DUK_ASSERT(thr->valstack_bottom + 1 < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom1); /* side effects */ DUK_TVAL_CHKFAST_INPLACE_SLOW(&thr->heap->lj.value1); thr->heap->lj.iserror = is_error; - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ - duk_err_longjmp(thr); /* execution resumes in bytecode executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ + duk_err_longjmp(thr); /* execution resumes in bytecode executor */ DUK_UNREACHABLE(); /* Never here, fall through to error (from compiler point of view). */ - state_error: +state_error: DUK_DCERROR_TYPE_INVALID_STATE(thr); } #endif @@ -43830,14 +44721,15 @@ DUK_ASSERT(thr->resumer->state == DUK_HTHREAD_STATE_RESUMED); if (thr->callstack_top < 2) { - DUK_DD(DUK_DDPRINT("yield state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.yield)")); + DUK_DD(DUK_DDPRINT( + "yield state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.yield)")); goto state_error; } DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr))); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ caller_func = DUK_ACT_GET_FUNC(thr->callstack_curr->parent); if (!DUK_HOBJECT_IS_COMPFUNC(caller_func)) { @@ -43845,10 +44737,11 @@ goto state_error; } - DUK_ASSERT(thr->callstack_preventcount >= 1); /* should never be zero, because we (Duktape.Thread.yield) are on the stack */ + DUK_ASSERT(thr->callstack_preventcount >= 1); /* should never be zero, because we (Duktape.Thread.yield) are on the stack */ if (thr->callstack_preventcount != 1) { /* Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0 */ - DUK_DD(DUK_DDPRINT("yield state invalid: there must be no yield-preventing calls in current thread callstack (preventcount is %ld)", + DUK_DD(DUK_DDPRINT("yield state invalid: there must be no yield-preventing calls in current thread callstack " + "(preventcount is %ld)", (long) thr->callstack_preventcount)); goto state_error; } @@ -43862,18 +44755,16 @@ #if defined(DUK_USE_AUGMENT_ERROR_THROW) if (is_error) { - DUK_ASSERT_TOP(thr, 1); /* value (error) is at stack top */ - duk_err_augment_error_throw(thr); /* in yielder's context */ + DUK_ASSERT_TOP(thr, 1); /* value (error) is at stack top */ + duk_err_augment_error_throw(thr); /* in yielder's context */ } #endif #if defined(DUK_USE_DEBUG) if (is_error) { - DUK_DDD(DUK_DDDPRINT("YIELD ERROR: value=%!T", - (duk_tval *) duk_get_tval(thr, 0))); + DUK_DDD(DUK_DDDPRINT("YIELD ERROR: value=%!T", (duk_tval *) duk_get_tval(thr, 0))); } else { - DUK_DDD(DUK_DDDPRINT("YIELD NORMAL: value=%!T", - (duk_tval *) duk_get_tval(thr, 0))); + DUK_DDD(DUK_DDDPRINT("YIELD NORMAL: value=%!T", (duk_tval *) duk_get_tval(thr, 0))); } #endif @@ -43888,17 +44779,17 @@ /* lj value1: value */ DUK_ASSERT(thr->valstack_bottom < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom0); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom0); /* side effects */ DUK_TVAL_CHKFAST_INPLACE_SLOW(&thr->heap->lj.value1); thr->heap->lj.iserror = is_error; - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ - duk_err_longjmp(thr); /* execution resumes in bytecode executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ + duk_err_longjmp(thr); /* execution resumes in bytecode executor */ DUK_UNREACHABLE(); /* Never here, fall through to error (from compiler point of view). */ - state_error: +state_error: DUK_DCERROR_TYPE_INVALID_STATE(thr); } #endif @@ -43976,7 +44867,7 @@ } DUK_INTERNAL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size) { - char buf64+1; + char buf64 + 1; duk_debug_format_funcptr(buf, sizeof(buf), fptr, fptr_size); bufsizeof(buf) - 1 = (char) 0; duk_fb_put_cstring(fb, buf); @@ -43986,7 +44877,7 @@ return (fb->offset >= fb->length); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Custom formatter for debug printing, allowing Duktape specific data * structures (such as tagged values and heap objects) to be printed with @@ -44052,58 +44943,58 @@ /* list of conversion specifiers that terminate a format tag; * this is unfortunately guesswork. */ -#define DUK__ALLOWED_STANDARD_SPECIFIERS "diouxXeEfFgGaAcsCSpnm" +#define DUK__ALLOWED_STANDARD_SPECIFIERS "diouxXeEfFgGaAcsCSpnm" /* maximum length of standard format tag that we support */ -#define DUK__MAX_FORMAT_TAG_LENGTH 32 +#define DUK__MAX_FORMAT_TAG_LENGTH 32 /* heapobj recursion depth when deep printing is selected */ -#define DUK__DEEP_DEPTH_LIMIT 8 +#define DUK__DEEP_DEPTH_LIMIT 8 /* maximum recursion depth for loop detection stacks */ -#define DUK__LOOP_STACK_DEPTH 256 +#define DUK__LOOP_STACK_DEPTH 256 /* must match bytecode defines now; build autogenerate? */ DUK_LOCAL const char * const duk__bc_optab256 = { - "LDREG", "STREG", "JUMP", "LDCONST", "LDINT", "LDINTX", "LDTHIS", "LDUNDEF", - "LDNULL", "LDTRUE", "LDFALSE", "GETVAR", "BNOT", "LNOT", "UNM", "UNP", - "EQ_RR", "EQ_CR", "EQ_RC", "EQ_CC", "NEQ_RR", "NEQ_CR", "NEQ_RC", "NEQ_CC", - "SEQ_RR", "SEQ_CR", "SEQ_RC", "SEQ_CC", "SNEQ_RR", "SNEQ_CR", "SNEQ_RC", "SNEQ_CC", - - "GT_RR", "GT_CR", "GT_RC", "GT_CC", "GE_RR", "GE_CR", "GE_RC", "GE_CC", - "LT_RR", "LT_CR", "LT_RC", "LT_CC", "LE_RR", "LE_CR", "LE_RC", "LE_CC", - "IFTRUE_R", "IFTRUE_C", "IFFALSE_R", "IFFALSE_C", "ADD_RR", "ADD_CR", "ADD_RC", "ADD_CC", - "SUB_RR", "SUB_CR", "SUB_RC", "SUB_CC", "MUL_RR", "MUL_CR", "MUL_RC", "MUL_CC", - - "DIV_RR", "DIV_CR", "DIV_RC", "DIV_CC", "MOD_RR", "MOD_CR", "MOD_RC", "MOD_CC", - "EXP_RR", "EXP_CR", "EXP_RC", "EXP_CC", "BAND_RR", "BAND_CR", "BAND_RC", "BAND_CC", - "BOR_RR", "BOR_CR", "BOR_RC", "BOR_CC", "BXOR_RR", "BXOR_CR", "BXOR_RC", "BXOR_CC", - "BASL_RR", "BASL_CR", "BASL_RC", "BASL_CC", "BLSR_RR", "BLSR_CR", "BLSR_RC", "BLSR_CC", - - "BASR_RR", "BASR_CR", "BASR_RC", "BASR_CC", "INSTOF_RR", "INSTOF_CR", "INSTOF_RC", "INSTOF_CC", - "IN_RR", "IN_CR", "IN_RC", "IN_CC", "GETPROP_RR", "GETPROP_CR", "GETPROP_RC", "GETPROP_CC", - "PUTPROP_RR", "PUTPROP_CR", "PUTPROP_RC", "PUTPROP_CC", "DELPROP_RR", "DELPROP_CR", "DELPROP_RC", "DELPROP_CC", - "PREINCR", "PREDECR", "POSTINCR", "POSTDECR", "PREINCV", "PREDECV", "POSTINCV", "POSTDECV", + "LDREG", "STREG", "JUMP", "LDCONST", "LDINT", "LDINTX", "LDTHIS", "LDUNDEF", + "LDNULL", "LDTRUE", "LDFALSE", "GETVAR", "BNOT", "LNOT", "UNM", "UNP", + "EQ_RR", "EQ_CR", "EQ_RC", "EQ_CC", "NEQ_RR", "NEQ_CR", "NEQ_RC", "NEQ_CC", + "SEQ_RR", "SEQ_CR", "SEQ_RC", "SEQ_CC", "SNEQ_RR", "SNEQ_CR", "SNEQ_RC", "SNEQ_CC", + + "GT_RR", "GT_CR", "GT_RC", "GT_CC", "GE_RR", "GE_CR", "GE_RC", "GE_CC", + "LT_RR", "LT_CR", "LT_RC", "LT_CC", "LE_RR", "LE_CR", "LE_RC", "LE_CC", + "IFTRUE_R", "IFTRUE_C", "IFFALSE_R", "IFFALSE_C", "ADD_RR", "ADD_CR", "ADD_RC", "ADD_CC", + "SUB_RR", "SUB_CR", "SUB_RC", "SUB_CC", "MUL_RR", "MUL_CR", "MUL_RC", "MUL_CC", + + "DIV_RR", "DIV_CR", "DIV_RC", "DIV_CC", "MOD_RR", "MOD_CR", "MOD_RC", "MOD_CC", + "EXP_RR", "EXP_CR", "EXP_RC", "EXP_CC", "BAND_RR", "BAND_CR", "BAND_RC", "BAND_CC", + "BOR_RR", "BOR_CR", "BOR_RC", "BOR_CC", "BXOR_RR", "BXOR_CR", "BXOR_RC", "BXOR_CC", + "BASL_RR", "BASL_CR", "BASL_RC", "BASL_CC", "BLSR_RR", "BLSR_CR", "BLSR_RC", "BLSR_CC", + + "BASR_RR", "BASR_CR", "BASR_RC", "BASR_CC", "INSTOF_RR", "INSTOF_CR", "INSTOF_RC", "INSTOF_CC", + "IN_RR", "IN_CR", "IN_RC", "IN_CC", "GETPROP_RR", "GETPROP_CR", "GETPROP_RC", "GETPROP_CC", + "PUTPROP_RR", "PUTPROP_CR", "PUTPROP_RC", "PUTPROP_CC", "DELPROP_RR", "DELPROP_CR", "DELPROP_RC", "DELPROP_CC", + "PREINCR", "PREDECR", "POSTINCR", "POSTDECR", "PREINCV", "PREDECV", "POSTINCV", "POSTDECV", - "PREINCP_RR", "PREINCP_CR", "PREINCP_RC", "PREINCP_CC", "PREDECP_RR", "PREDECP_CR", "PREDECP_RC", "PREDECP_CC", + "PREINCP_RR", "PREINCP_CR", "PREINCP_RC", "PREINCP_CC", "PREDECP_RR", "PREDECP_CR", "PREDECP_RC", "PREDECP_CC", "POSTINCP_RR", "POSTINCP_CR", "POSTINCP_RC", "POSTINCP_CC", "POSTDECP_RR", "POSTDECP_CR", "POSTDECP_RC", "POSTDECP_CC", - "DECLVAR_RR", "DECLVAR_CR", "DECLVAR_RC", "DECLVAR_CC", "REGEXP_RR", "REGEXP_RC", "REGEXP_CR", "REGEXP_CC", - "CLOSURE", "TYPEOF", "TYPEOFID", "PUTVAR", "DELVAR", "RETREG", "RETUNDEF", "RETCONST", + "DECLVAR_RR", "DECLVAR_CR", "DECLVAR_RC", "DECLVAR_CC", "REGEXP_RR", "REGEXP_RC", "REGEXP_CR", "REGEXP_CC", + "CLOSURE", "TYPEOF", "TYPEOFID", "PUTVAR", "DELVAR", "RETREG", "RETUNDEF", "RETCONST", - "RETCONSTN", "LABEL", "ENDLABEL", "BREAK", "CONTINUE", "TRYCATCH", "ENDTRY", "ENDCATCH", - "ENDFIN", "THROW", "INVLHS", "CSREG", "CSVAR_RR", "CSVAR_CR", "CSVAR_RC", "CSVAR_CC", - "CALL0", "CALL1", "CALL2", "CALL3", "CALL4", "CALL5", "CALL6", "CALL7", - "CALL8", "CALL9", "CALL10", "CALL11", "CALL12", "CALL13", "CALL14", "CALL15", - - "NEWOBJ", "NEWARR", "MPUTOBJ", "MPUTOBJI", "INITSET", "INITGET", "MPUTARR", "MPUTARRI", - "SETALEN", "INITENUM", "NEXTENUM", "NEWTARGET", "DEBUGGER", "NOP", "INVALID", "UNUSED207", - "GETPROPC_RR", "GETPROPC_CR", "GETPROPC_RC", "GETPROPC_CC", "UNUSED212", "UNUSED213", "UNUSED214", "UNUSED215", - "UNUSED216", "UNUSED217", "UNUSED218", "UNUSED219", "UNUSED220", "UNUSED221", "UNUSED222", "UNUSED223", - - "UNUSED224", "UNUSED225", "UNUSED226", "UNUSED227", "UNUSED228", "UNUSED229", "UNUSED230", "UNUSED231", - "UNUSED232", "UNUSED233", "UNUSED234", "UNUSED235", "UNUSED236", "UNUSED237", "UNUSED238", "UNUSED239", - "UNUSED240", "UNUSED241", "UNUSED242", "UNUSED243", "UNUSED244", "UNUSED245", "UNUSED246", "UNUSED247", - "UNUSED248", "UNUSED249", "UNUSED250", "UNUSED251", "UNUSED252", "UNUSED253", "UNUSED254", "UNUSED255" + "RETCONSTN", "LABEL", "ENDLABEL", "BREAK", "CONTINUE", "TRYCATCH", "ENDTRY", "ENDCATCH", + "ENDFIN", "THROW", "INVLHS", "CSREG", "CSVAR_RR", "CSVAR_CR", "CSVAR_RC", "CSVAR_CC", + "CALL0", "CALL1", "CALL2", "CALL3", "CALL4", "CALL5", "CALL6", "CALL7", + "CALL8", "CALL9", "CALL10", "CALL11", "CALL12", "CALL13", "CALL14", "CALL15", + + "NEWOBJ", "NEWARR", "MPUTOBJ", "MPUTOBJI", "INITSET", "INITGET", "MPUTARR", "MPUTARRI", + "SETALEN", "INITENUM", "NEXTENUM", "NEWTARGET", "DEBUGGER", "NOP", "INVALID", "UNUSED207", + "GETPROPC_RR", "GETPROPC_CR", "GETPROPC_RC", "GETPROPC_CC", "UNUSED212", "UNUSED213", "UNUSED214", "UNUSED215", + "UNUSED216", "UNUSED217", "UNUSED218", "UNUSED219", "UNUSED220", "UNUSED221", "UNUSED222", "UNUSED223", + + "UNUSED224", "UNUSED225", "UNUSED226", "UNUSED227", "UNUSED228", "UNUSED229", "UNUSED230", "UNUSED231", + "UNUSED232", "UNUSED233", "UNUSED234", "UNUSED235", "UNUSED236", "UNUSED237", "UNUSED238", "UNUSED239", + "UNUSED240", "UNUSED241", "UNUSED242", "UNUSED243", "UNUSED244", "UNUSED245", "UNUSED246", "UNUSED247", + "UNUSED248", "UNUSED249", "UNUSED250", "UNUSED251", "UNUSED252", "UNUSED253", "UNUSED254", "UNUSED255" }; typedef struct duk__dprint_state duk__dprint_state; @@ -44153,14 +45044,15 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*h); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)h)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) h)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } -#if defined(DUK_USE_REFERENCE_COUNTING) /* currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP */ +#if defined(DUK_USE_REFERENCE_COUNTING) /* currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP */ if (st->heavy) { - duk_fb_sprintf(fb, "h_next=%p,h_prev=%p,h_refcount=%lu,h_flags=%08lx,type=%ld," + duk_fb_sprintf(fb, + "h_next=%p,h_prev=%p,h_refcount=%lu,h_flags=%08lx,type=%ld," "reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (void *) DUK_HEAPHDR_GET_NEXT(NULL, h), (void *) DUK_HEAPHDR_GET_PREV(NULL, h), @@ -44174,7 +45066,8 @@ } #else if (st->heavy) { - duk_fb_sprintf(fb, "h_next=%p,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_next=%p,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (void *) DUK_HEAPHDR_GET_NEXT(NULL, h), (unsigned long) DUK_HEAPHDR_GET_FLAGS(h), (long) DUK_HEAPHDR_GET_TYPE(h), @@ -44201,14 +45094,15 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*h); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)h)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) h)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } #if defined(DUK_USE_REFERENCE_COUNTING) if (st->heavy) { - duk_fb_sprintf(fb, "h_refcount=%lu,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_refcount=%lu,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h), (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h), (long) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h), @@ -44219,7 +45113,8 @@ } #else if (st->heavy) { - duk_fb_sprintf(fb, "h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h), (long) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h), (long) (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h) ? 1 : 0), @@ -44290,7 +45185,8 @@ #endif } -#define DUK__COMMA() do { \ +#define DUK__COMMA() \ + do { \ if (first) { \ first = 0; \ } else { \ @@ -44403,7 +45299,8 @@ duk__print_hstring(st, key, 0); duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_COLON); if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(NULL, h, i)) { - duk_fb_sprintf(fb, "get:%p,set:%p", + duk_fb_sprintf(fb, + "get:%p,set:%p", (void *) DUK_HOBJECT_E_GET_VALUE(NULL, h, i).a.get, (void *) DUK_HOBJECT_E_GET_VALUE(NULL, h, i).a.set); } else { @@ -44417,158 +45314,238 @@ } if (st->internal) { if (DUK_HOBJECT_IS_ARRAY(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__array:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__array:true"); } if (DUK_HOBJECT_HAS_EXTENSIBLE(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__extensible:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__extensible:true"); } if (DUK_HOBJECT_HAS_CONSTRUCTABLE(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__constructable:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__constructable:true"); } if (DUK_HOBJECT_HAS_BOUNDFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__boundfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__boundfunc:true"); } if (DUK_HOBJECT_HAS_COMPFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__compfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__compfunc:true"); } if (DUK_HOBJECT_HAS_NATFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__natfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__natfunc:true"); } if (DUK_HOBJECT_HAS_BUFOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__bufobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__bufobj:true"); } if (DUK_HOBJECT_IS_THREAD(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__thread:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__thread:true"); } if (DUK_HOBJECT_HAS_ARRAY_PART(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__array_part:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__array_part:true"); } if (DUK_HOBJECT_HAS_STRICT(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__strict:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__strict:true"); } if (DUK_HOBJECT_HAS_NOTAIL(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__notail:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__notail:true"); } if (DUK_HOBJECT_HAS_NEWENV(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__newenv:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__newenv:true"); } if (DUK_HOBJECT_HAS_NAMEBINDING(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__namebinding:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__namebinding:true"); } if (DUK_HOBJECT_HAS_CREATEARGS(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__createargs:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__createargs:true"); } if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_array:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_array:true"); } if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_stringobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_stringobj:true"); } if (DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_arguments:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_arguments:true"); } if (DUK_HOBJECT_IS_BUFOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_bufobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_bufobj:true"); } if (DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_proxyobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_proxyobj:true"); } } if (st->internal && DUK_HOBJECT_IS_ARRAY(h)) { duk_harray *a = (duk_harray *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__length:%ld", (long) a->length); - DUK__COMMA(); duk_fb_sprintf(fb, "__length_nonwritable:%ld", (long) a->length_nonwritable); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length:%ld", (long) a->length); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length_nonwritable:%ld", (long) a->length_nonwritable); } else if (st->internal && DUK_HOBJECT_IS_COMPFUNC(h)) { duk_hcompfunc *f = (duk_hcompfunc *) h; - DUK__COMMA(); duk_fb_put_cstring(fb, "__data:"); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__data:"); duk__print_hbuffer(st, (duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA(NULL, f)); - DUK__COMMA(); duk_fb_put_cstring(fb, "__lexenv:"); duk__print_hobject(st, DUK_HCOMPFUNC_GET_LEXENV(NULL, f)); - DUK__COMMA(); duk_fb_put_cstring(fb, "__varenv:"); duk__print_hobject(st, DUK_HCOMPFUNC_GET_VARENV(NULL, f)); - DUK__COMMA(); duk_fb_sprintf(fb, "__nregs:%ld", (long) f->nregs); - DUK__COMMA(); duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__lexenv:"); + duk__print_hobject(st, DUK_HCOMPFUNC_GET_LEXENV(NULL, f)); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__varenv:"); + duk__print_hobject(st, DUK_HCOMPFUNC_GET_VARENV(NULL, f)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nregs:%ld", (long) f->nregs); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); #if defined(DUK_USE_DEBUGGER_SUPPORT) - DUK__COMMA(); duk_fb_sprintf(fb, "__start_line:%ld", (long) f->start_line); - DUK__COMMA(); duk_fb_sprintf(fb, "__end_line:%ld", (long) f->end_line); + DUK__COMMA(); + duk_fb_sprintf(fb, "__start_line:%ld", (long) f->start_line); + DUK__COMMA(); + duk_fb_sprintf(fb, "__end_line:%ld", (long) f->end_line); #endif - DUK__COMMA(); duk_fb_put_cstring(fb, "__data:"); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__data:"); duk__print_hbuffer(st, (duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA(NULL, f)); } else if (st->internal && DUK_HOBJECT_IS_NATFUNC(h)) { duk_hnatfunc *f = (duk_hnatfunc *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__func:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__func:"); duk_fb_put_funcptr(fb, (duk_uint8_t *) &f->func, sizeof(f->func)); - DUK__COMMA(); duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); - DUK__COMMA(); duk_fb_sprintf(fb, "__magic:%ld", (long) f->magic); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); + DUK__COMMA(); + duk_fb_sprintf(fb, "__magic:%ld", (long) f->magic); } else if (st->internal && DUK_HOBJECT_IS_DECENV(h)) { duk_hdecenv *e = (duk_hdecenv *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__thread:"); duk__print_hobject(st, (duk_hobject *) e->thread); - DUK__COMMA(); duk_fb_sprintf(fb, "__varmap:"); duk__print_hobject(st, (duk_hobject *) e->varmap); - DUK__COMMA(); duk_fb_sprintf(fb, "__regbase_byteoff:%ld", (long) e->regbase_byteoff); + DUK__COMMA(); + duk_fb_sprintf(fb, "__thread:"); + duk__print_hobject(st, (duk_hobject *) e->thread); + DUK__COMMA(); + duk_fb_sprintf(fb, "__varmap:"); + duk__print_hobject(st, (duk_hobject *) e->varmap); + DUK__COMMA(); + duk_fb_sprintf(fb, "__regbase_byteoff:%ld", (long) e->regbase_byteoff); } else if (st->internal && DUK_HOBJECT_IS_OBJENV(h)) { duk_hobjenv *e = (duk_hobjenv *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__target:"); duk__print_hobject(st, (duk_hobject *) e->target); - DUK__COMMA(); duk_fb_sprintf(fb, "__has_this:%ld", (long) e->has_this); + DUK__COMMA(); + duk_fb_sprintf(fb, "__target:"); + duk__print_hobject(st, (duk_hobject *) e->target); + DUK__COMMA(); + duk_fb_sprintf(fb, "__has_this:%ld", (long) e->has_this); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) } else if (st->internal && DUK_HOBJECT_IS_BUFOBJ(h)) { duk_hbufobj *b = (duk_hbufobj *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__buf:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__buf:"); duk__print_hbuffer(st, (duk_hbuffer *) b->buf); - DUK__COMMA(); duk_fb_sprintf(fb, "__buf_prop:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__buf_prop:"); duk__print_hobject(st, (duk_hobject *) b->buf_prop); - DUK__COMMA(); duk_fb_sprintf(fb, "__offset:%ld", (long) b->offset); - DUK__COMMA(); duk_fb_sprintf(fb, "__length:%ld", (long) b->length); - DUK__COMMA(); duk_fb_sprintf(fb, "__shift:%ld", (long) b->shift); - DUK__COMMA(); duk_fb_sprintf(fb, "__elemtype:%ld", (long) b->elem_type); + DUK__COMMA(); + duk_fb_sprintf(fb, "__offset:%ld", (long) b->offset); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length:%ld", (long) b->length); + DUK__COMMA(); + duk_fb_sprintf(fb, "__shift:%ld", (long) b->shift); + DUK__COMMA(); + duk_fb_sprintf(fb, "__elemtype:%ld", (long) b->elem_type); #endif } else if (st->internal && DUK_HOBJECT_IS_PROXY(h)) { duk_hproxy *p = (duk_hproxy *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__target:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__target:"); duk__print_hobject(st, p->target); - DUK__COMMA(); duk_fb_sprintf(fb, "__handler:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__handler:"); duk__print_hobject(st, p->handler); } else if (st->internal && DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__ptr_curr_pc:%p", (void *) t->ptr_curr_pc); - DUK__COMMA(); duk_fb_sprintf(fb, "__heap:%p", (void *) t->heap); - DUK__COMMA(); duk_fb_sprintf(fb, "__strict:%ld", (long) t->strict); - DUK__COMMA(); duk_fb_sprintf(fb, "__state:%ld", (long) t->state); - DUK__COMMA(); duk_fb_sprintf(fb, "__unused1:%ld", (long) t->unused1); - DUK__COMMA(); duk_fb_sprintf(fb, "__unused2:%ld", (long) t->unused2); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack:%p", (void *) t->valstack); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_end:%p/%ld", (void *) t->valstack_end, (long) (t->valstack_end - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_alloc_end:%p/%ld", (void *) t->valstack_alloc_end, (long) (t->valstack_alloc_end - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_bottom:%p/%ld", (void *) t->valstack_bottom, (long) (t->valstack_bottom - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_top:%p/%ld", (void *) t->valstack_top, (long) (t->valstack_top - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_curr:%p", (void *) t->callstack_curr); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_top:%ld", (long) t->callstack_top); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_preventcount:%ld", (long) t->callstack_preventcount); - DUK__COMMA(); duk_fb_sprintf(fb, "__resumer:"); duk__print_hobject(st, (duk_hobject *) t->resumer); - DUK__COMMA(); duk_fb_sprintf(fb, "__compile_ctx:%p", (void *) t->compile_ctx); + DUK__COMMA(); + duk_fb_sprintf(fb, "__ptr_curr_pc:%p", (void *) t->ptr_curr_pc); + DUK__COMMA(); + duk_fb_sprintf(fb, "__heap:%p", (void *) t->heap); + DUK__COMMA(); + duk_fb_sprintf(fb, "__strict:%ld", (long) t->strict); + DUK__COMMA(); + duk_fb_sprintf(fb, "__state:%ld", (long) t->state); + DUK__COMMA(); + duk_fb_sprintf(fb, "__unused1:%ld", (long) t->unused1); + DUK__COMMA(); + duk_fb_sprintf(fb, "__unused2:%ld", (long) t->unused2); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack:%p", (void *) t->valstack); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack_end:%p/%ld", (void *) t->valstack_end, (long) (t->valstack_end - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, + "__valstack_alloc_end:%p/%ld", + (void *) t->valstack_alloc_end, + (long) (t->valstack_alloc_end - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, + "__valstack_bottom:%p/%ld", + (void *) t->valstack_bottom, + (long) (t->valstack_bottom - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack_top:%p/%ld", (void *) t->valstack_top, (long) (t->valstack_top - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_curr:%p", (void *) t->callstack_curr); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_top:%ld", (long) t->callstack_top); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_preventcount:%ld", (long) t->callstack_preventcount); + DUK__COMMA(); + duk_fb_sprintf(fb, "__resumer:"); + duk__print_hobject(st, (duk_hobject *) t->resumer); + DUK__COMMA(); + duk_fb_sprintf(fb, "__compile_ctx:%p", (void *) t->compile_ctx); #if defined(DUK_USE_INTERRUPT_COUNTER) - DUK__COMMA(); duk_fb_sprintf(fb, "__interrupt_counter:%ld", (long) t->interrupt_counter); - DUK__COMMA(); duk_fb_sprintf(fb, "__interrupt_init:%ld", (long) t->interrupt_init); + DUK__COMMA(); + duk_fb_sprintf(fb, "__interrupt_counter:%ld", (long) t->interrupt_counter); + DUK__COMMA(); + duk_fb_sprintf(fb, "__interrupt_init:%ld", (long) t->interrupt_init); #endif /* XXX: print built-ins array? */ - } #if defined(DUK_USE_REFERENCE_COUNTING) if (st->internal) { - DUK__COMMA(); duk_fb_sprintf(fb, "__refcount:%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__refcount:%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h)); } #endif if (st->internal) { - DUK__COMMA(); duk_fb_sprintf(fb, "__class:%ld", (long) DUK_HOBJECT_GET_CLASS_NUMBER(h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__class:%ld", (long) DUK_HOBJECT_GET_CLASS_NUMBER(h)); } - DUK__COMMA(); duk_fb_sprintf(fb, "__heapptr:%p", (void *) h); /* own pointer */ + DUK__COMMA(); + duk_fb_sprintf(fb, "__heapptr:%p", (void *) h); /* own pointer */ /* prototype should be last, for readability */ if (DUK_HOBJECT_GET_PROTOTYPE(NULL, h)) { if (st->follow_proto) { - DUK__COMMA(); duk_fb_put_cstring(fb, "__prototype:"); duk__print_hobject(st, DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__prototype:"); + duk__print_hobject(st, DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); } else { - DUK__COMMA(); duk_fb_sprintf(fb, "__prototype:%p", (void *) DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__prototype:%p", (void *) DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); } } @@ -44594,7 +45571,7 @@ } #endif - finished: +finished: st->depth--; if (pushed_loopstack) { st->loop_stack_index--; @@ -44621,12 +45598,14 @@ if (DUK_HBUFFER_HAS_DYNAMIC(h)) { if (DUK_HBUFFER_HAS_EXTERNAL(h)) { duk_hbuffer_external *g = (duk_hbuffer_external *) h; - duk_fb_sprintf(fb, "buffer:external:%p:%ld", + duk_fb_sprintf(fb, + "buffer:external:%p:%ld", (void *) DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(NULL, g), (long) DUK_HBUFFER_EXTERNAL_GET_SIZE(g)); } else { duk_hbuffer_dynamic *g = (duk_hbuffer_dynamic *) h; - duk_fb_sprintf(fb, "buffer:dynamic:%p:%ld", + duk_fb_sprintf(fb, + "buffer:dynamic:%p:%ld", (void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(NULL, g), (long) DUK_HBUFFER_DYNAMIC_GET_SIZE(g)); } @@ -44699,7 +45678,7 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*tv); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)tv)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) tv)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } @@ -44782,17 +45761,22 @@ /* XXX: option to fix opcode length so it lines up nicely */ if (op == DUK_OP_JUMP) { - duk_int_t diff1 = (duk_int_t) (DUK_DEC_ABC(ins) - DUK_BC_JUMP_BIAS); /* from next pc */ - duk_int_t diff2 = diff1 + 1; /* from curr pc */ + duk_int_t diff1 = (duk_int_t) (DUK_DEC_ABC(ins) - DUK_BC_JUMP_BIAS); /* from next pc */ + duk_int_t diff2 = diff1 + 1; /* from curr pc */ - duk_fb_sprintf(fb, "%s %ld (to pc%c%ld)", - (const char *) op_name, (long) diff1, - (int) (diff2 >= 0 ? '+' : '-'), /* char format: use int */ + duk_fb_sprintf(fb, + "%s %ld (to pc%c%ld)", + (const char *) op_name, + (long) diff1, + (int) (diff2 >= 0 ? '+' : '-'), /* char format: use int */ (long) (diff2 >= 0 ? diff2 : -diff2)); } else { - duk_fb_sprintf(fb, "%s %ld, %ld, %ld", - (const char *) op_name, (long) DUK_DEC_A(ins), - (long) DUK_DEC_B(ins), (long) DUK_DEC_C(ins)); + duk_fb_sprintf(fb, + "%s %ld, %ld, %ld", + (const char *) op_name, + (long) DUK_DEC_A(ins), + (long) DUK_DEC_B(ins), + (long) DUK_DEC_C(ins)); } } @@ -44818,13 +45802,16 @@ return; } - duk_fb_sprintf(fb, "catcher ptr=%p parent=%p varname=%p pc_base=%p, idx_base=%ld, flags=0x%08lx", + duk_fb_sprintf(fb, + "catcher ptr=%p parent=%p varname=%p pc_base=%p, idx_base=%ld, flags=0x%08lx", (void *) cat, - (void *) cat->parent, (void *) cat->h_varname, (void *) cat->pc_base, - (long) cat->idx_base, (unsigned long) cat->flags); + (void *) cat->parent, + (void *) cat->h_varname, + (void *) cat->pc_base, + (long) cat->idx_base, + (unsigned long) cat->flags); } - DUK_LOCAL void duk__print_activation(duk__dprint_state *st, duk_activation *act) { duk_fixedbuffer *fb = st->fb; @@ -44839,12 +45826,20 @@ /* prev_caller: conditional, omitted on purpose, it's rarely used. */ /* prev_line: conditional, omitted on purpose (but would be nice). */ - duk_fb_sprintf(fb, "activation ptr=%p tv_func=<omit> func=%p parent=%p var_env=%p lex_env=%p cat=%p curr_pc=%p bottom_byteoff=%ld retval_byteoff=%ld reserve_byteoff=%ld flags=%ld", + duk_fb_sprintf(fb, + "activation ptr=%p tv_func=<omit> func=%p parent=%p var_env=%p lex_env=%p cat=%p curr_pc=%p " + "bottom_byteoff=%ld retval_byteoff=%ld reserve_byteoff=%ld flags=%ld", (void *) act, - (void *) act->func, (void *) act->parent, (void *) act->var_env, - (void *) act->lex_env, (void *) act->cat, (void *) act->curr_pc, - (long) act->bottom_byteoff, (long) act->retval_byteoff, (long) act->reserve_byteoff, - (long) act->flags); + (void *) act->func, + (void *) act->parent, + (void *) act->var_env, + (void *) act->lex_env, + (void *) act->cat, + (void *) act->curr_pc, + (long) act->bottom_byteoff, + (long) act->retval_byteoff, + (long) act->reserve_byteoff, + (long) act->flags); } DUK_INTERNAL duk_int_t duk_debug_vsnprintf(char *str, duk_size_t size, const char *format, va_list ap) { @@ -44863,7 +45858,7 @@ char ch = *p++; const char *p_begfmt = NULL; duk_bool_t got_exclamation = 0; - duk_bool_t got_long = 0; /* %lf, %ld etc */ + duk_bool_t got_long = 0; /* %lf, %ld etc */ duk__dprint_state st; if (ch != DUK_ASC_PERCENT) { @@ -45026,11 +46021,11 @@ } goto done; - format_error: +format_error: duk_fb_put_cstring(&fb, "FMTERR"); /* fall through */ - done: +done: retval = (duk_int_t) fb.offset; duk_fb_put_byte(&fb, (duk_uint8_t) 0); @@ -45038,7 +46033,7 @@ return retval; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_int_t duk_debug_snprintf(char *str, duk_size_t size, const char *format, ...) { duk_int_t retval; va_list ap; @@ -45079,7 +46074,7 @@ } } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* automatic undefs */ #undef DUK__ALLOWED_STANDARD_SPECIFIERS @@ -45100,17 +46095,23 @@ */ #if defined(DUK_USE_ASSERTIONS) -#define DUK__DBG_TPORT_ENTER() do { \ +#define DUK__DBG_TPORT_ENTER() \ + do { \ DUK_ASSERT(heap->dbg_calling_transport == 0); \ heap->dbg_calling_transport = 1; \ } while (0) -#define DUK__DBG_TPORT_EXIT() do { \ +#define DUK__DBG_TPORT_EXIT() \ + do { \ DUK_ASSERT(heap->dbg_calling_transport == 1); \ heap->dbg_calling_transport = 0; \ } while (0) #else -#define DUK__DBG_TPORT_ENTER() do {} while (0) -#define DUK__DBG_TPORT_EXIT() do {} while (0) +#define DUK__DBG_TPORT_ENTER() \ + do { \ + } while (0) +#define DUK__DBG_TPORT_EXIT() \ + do { \ + } while (0) #endif /* @@ -45130,7 +46131,8 @@ * Detach handling */ -#define DUK__SET_CONN_BROKEN(thr,reason) do { \ +#define DUK__SET_CONN_BROKEN(thr, reason) \ + do { \ /* For now shared handler is fine. */ \ duk__debug_do_detach1((thr)->heap, (reason)); \ } while (0) @@ -45151,7 +46153,7 @@ DUK_D(DUK_DPRINT("debugger transport detaching, marking transport broken")); - heap->dbg_detaching = 1; /* prevent multiple in-progress detaches */ + heap->dbg_detaching = 1; /* prevent multiple in-progress detaches */ if (heap->dbg_write_cb != NULL) { duk_hthread *thr; @@ -45179,8 +46181,8 @@ heap->dbg_pause_act = NULL; heap->dbg_pause_startline = 0; heap->dbg_have_next_byte = 0; - duk_debug_clear_paused(heap); /* XXX: some overlap with field inits above */ - heap->dbg_state_dirty = 0; /* XXX: clear_paused sets dirty; rework? */ + duk_debug_clear_paused(heap); /* XXX: some overlap with field inits above */ + heap->dbg_state_dirty = 0; /* XXX: clear_paused sets dirty; rework? */ /* Ensure there are no stale active breakpoint pointers. * Breakpoint list is currently kept - we could empty it @@ -45240,7 +46242,7 @@ heap = thr->heap; DUK_D(DUK_DPRINT("transport read/write error, NULL all callbacks expected detached")); heap->dbg_read_cb = NULL; - heap->dbg_write_cb = NULL; /* this is especially critical to avoid another write call in detach1() */ + heap->dbg_write_cb = NULL; /* this is especially critical to avoid another write call in detach1() */ heap->dbg_peek_cb = NULL; heap->dbg_read_flush_cb = NULL; heap->dbg_write_flush_cb = NULL; @@ -45262,7 +46264,8 @@ updated_flags = pause_flags & ~(DUK_PAUSE_FLAG_LINE_CHANGE); DUK_D(DUK_DPRINT("no line info for current activation, disable line-based pause flags: 0x%08lx -> 0x%08lx", - (long) pause_flags, (long) updated_flags)); + (long) pause_flags, + (long) updated_flags)); pause_flags = updated_flags; } @@ -45272,7 +46275,8 @@ heap->dbg_state_dirty = 1; DUK_D(DUK_DPRINT("set state for automatic pause triggers, flags=0x%08lx, act=%p, startline=%ld", - (long) heap->dbg_pause_flags, (void *) heap->dbg_pause_act, + (long) heap->dbg_pause_flags, + (void *) heap->dbg_pause_act, (long) heap->dbg_pause_startline)); } @@ -45427,7 +46431,7 @@ if (got == 0 || got > left) { DUK_D(DUK_DPRINT("connection error during read, return zero data")); - duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ + duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ DUK__SET_CONN_BROKEN(thr, 1); goto fail; } @@ -45435,14 +46439,14 @@ } return; - fail: +fail: duk_memzero((void *) data, (size_t) length); } DUK_INTERNAL duk_uint8_t duk_debug_read_byte(duk_hthread *thr) { duk_uint8_t x; - x = 0; /* just in case callback is broken and won't write 'x' */ + x = 0; /* just in case callback is broken and won't write 'x' */ duk_debug_read_bytes(thr, &x, 1); return x; } @@ -45453,10 +46457,7 @@ DUK_ASSERT(thr != NULL); duk_debug_read_bytes(thr, buf, 4); - return ((duk_uint32_t) buf0 << 24) | - ((duk_uint32_t) buf1 << 16) | - ((duk_uint32_t) buf2 << 8) | - (duk_uint32_t) buf3; + return ((duk_uint32_t) buf0 << 24) | ((duk_uint32_t) buf1 << 16) | ((duk_uint32_t) buf2 << 8) | (duk_uint32_t) buf3; } DUK_LOCAL duk_int32_t duk__debug_read_int32_raw(duk_hthread *thr) { @@ -45469,8 +46470,7 @@ DUK_ASSERT(thr != NULL); duk_debug_read_bytes(thr, buf, 2); - return ((duk_uint16_t) buf0 << 8) | - (duk_uint16_t) buf1; + return ((duk_uint16_t) buf0 << 8) | (duk_uint16_t) buf1; } DUK_INTERNAL duk_int32_t duk_debug_read_int(duk_hthread *thr) { @@ -45502,10 +46502,10 @@ duk_debug_read_bytes(thr, buf, (duk_size_t) len); duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); } else { - p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ + p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ DUK_ASSERT(p != NULL); duk_debug_read_bytes(thr, p, (duk_size_t) len); - (void) duk_buffer_to_string(thr, -1); /* Safety relies on debug client, which is OK. */ + (void) duk_buffer_to_string(thr, -1); /* Safety relies on debug client, which is OK. */ } return duk_require_hstring(thr, -1); @@ -45531,17 +46531,17 @@ return duk__debug_read_hstring_raw(thr, len); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode int")); DUK__SET_CONN_BROKEN(thr, 1); - duk_push_hstring_empty(thr); /* always push some string */ + duk_push_hstring_empty(thr); /* always push some string */ return duk_require_hstring(thr, -1); } DUK_LOCAL duk_hbuffer *duk__debug_read_hbuffer_raw(duk_hthread *thr, duk_uint32_t len) { duk_uint8_t *p; - p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ + p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ DUK_ASSERT(p != NULL); duk_debug_read_bytes(thr, p, (duk_size_t) len); @@ -45564,7 +46564,7 @@ #endif return (void *) pu.p; - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode pointer")); DUK__SET_CONN_BROKEN(thr, 1); return (void *) NULL; @@ -45622,7 +46622,7 @@ return (duk_heaphdr *) duk__debug_read_pointer_raw(thr); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode any pointer (object, pointer, heapptr)")); DUK__SET_CONN_BROKEN(thr, 1); return NULL; @@ -45728,15 +46728,15 @@ duk_push_heapptr(thr, (void *) h); break; } - case DUK_DBG_IB_UNUSED: /* unused: not accepted in inbound messages */ + case DUK_DBG_IB_UNUSED: /* unused: not accepted in inbound messages */ default: goto fail; } - return_ptr: +return_ptr: return DUK_GET_TVAL_NEGIDX(thr, -1); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode tval")); DUK__SET_CONN_BROKEN(thr, 1); return NULL; @@ -45786,7 +46786,7 @@ DUK__DBG_TPORT_EXIT(); if (got == 0 || got > left) { - duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ + duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ DUK_D(DUK_DPRINT("connection error during write")); DUK__SET_CONN_BROKEN(thr, 1); return; @@ -45853,8 +46853,7 @@ * unsigned 32-bit dvalue. */ if (x >= 0x80000000UL) { - DUK_D(DUK_DPRINT("writing unsigned integer 0x%08lx as signed integer", - (long) x)); + DUK_D(DUK_DPRINT("writing unsigned integer 0x%08lx as signed integer", (long) x)); } duk_debug_write_int(thr, (duk_int32_t) x); } @@ -45895,9 +46894,7 @@ DUK_INTERNAL void duk_debug_write_cstring(duk_hthread *thr, const char *data) { DUK_ASSERT(thr != NULL); - duk_debug_write_string(thr, - data, - data ? DUK_STRLEN(data) : 0); + duk_debug_write_string(thr, data, data ? DUK_STRLEN(data) : 0); } DUK_INTERNAL void duk_debug_write_hstring(duk_hthread *thr, duk_hstring *h) { @@ -45951,7 +46948,7 @@ DUK_INTERNAL void duk_debug_write_heapptr(duk_hthread *thr, duk_heaphdr *h) { duk__debug_write_pointer_raw(thr, (void *) h, DUK_DBG_IB_HEAPPTR); } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT */ DUK_INTERNAL void duk_debug_write_hobject(duk_hthread *thr, duk_hobject *obj) { duk_uint8_t buf3; @@ -45994,8 +46991,7 @@ duk_debug_write_byte(thr, DUK_DBG_IB_NULL); break; case DUK_TAG_BOOLEAN: - DUK_ASSERT(DUK_TVAL_GET_BOOLEAN(tv) == 0 || - DUK_TVAL_GET_BOOLEAN(tv) == 1); + DUK_ASSERT(DUK_TVAL_GET_BOOLEAN(tv) == 0 || DUK_TVAL_GET_BOOLEAN(tv) == 1); duk_debug_write_boolean(thr, DUK_TVAL_GET_BOOLEAN(tv)); break; case DUK_TAG_POINTER: @@ -46040,14 +47036,22 @@ DUK_DD(DUK_DDPRINT("i32=%ld du1=%02x%02x%02x%02x%02x%02x%02x%02x " "du2=%02x%02x%02x%02x%02x%02x%02x%02x", (long) i32, - (unsigned int) du1.uc0, (unsigned int) du1.uc1, - (unsigned int) du1.uc2, (unsigned int) du1.uc3, - (unsigned int) du1.uc4, (unsigned int) du1.uc5, - (unsigned int) du1.uc6, (unsigned int) du1.uc7, - (unsigned int) du2.uc0, (unsigned int) du2.uc1, - (unsigned int) du2.uc2, (unsigned int) du2.uc3, - (unsigned int) du2.uc4, (unsigned int) du2.uc5, - (unsigned int) du2.uc6, (unsigned int) du2.uc7)); + (unsigned int) du1.uc0, + (unsigned int) du1.uc1, + (unsigned int) du1.uc2, + (unsigned int) du1.uc3, + (unsigned int) du1.uc4, + (unsigned int) du1.uc5, + (unsigned int) du1.uc6, + (unsigned int) du1.uc7, + (unsigned int) du2.uc0, + (unsigned int) du2.uc1, + (unsigned int) du2.uc2, + (unsigned int) du2.uc3, + (unsigned int) du2.uc4, + (unsigned int) du2.uc5, + (unsigned int) du2.uc6, + (unsigned int) du2.uc7)); if (duk_memcmp((const void *) du1.uc, (const void *) du2.uc, sizeof(du1.uc)) == 0) { duk_debug_write_int(thr, i32); @@ -46071,13 +47075,13 @@ duk_debug_write_tval(thr, tv); } } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ /* * Debug connection message write helpers */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL void duk_debug_write_request(duk_hthread *thr, duk_small_uint_t command) { duk_debug_write_byte(thr, DUK_DBG_IB_REQUEST); duk_debug_write_int(thr, command); @@ -46180,7 +47184,7 @@ duk_activation *act; duk_uint32_t pc; - DUK_ASSERT(thr->valstack_top > thr->valstack); /* At least: ... err */ + DUK_ASSERT(thr->valstack_top > thr->valstack); /* At least: ... err */ duk_debug_write_notify(thr, DUK_DBG_CMD_THROW); duk_debug_write_int(thr, (duk_int32_t) fatal); @@ -46221,7 +47225,7 @@ duk_debug_write_eom(thr); } -#endif /* DUK_USE_DEBUGGER_THROW_NOTIFY */ +#endif /* DUK_USE_DEBUGGER_THROW_NOTIFY */ /* * Debug message processing @@ -46245,9 +47249,9 @@ duk_debug_skip_bytes(thr, (duk_size_t) (x - 0x60)); return 0; } - switch(x) { + switch (x) { case DUK_DBG_IB_EOM: - return 1; /* Return 1: got EOM */ + return 1; /* Return 1: got EOM */ case DUK_DBG_IB_REQUEST: case DUK_DBG_IB_REPLY: case DUK_DBG_IB_ERROR: @@ -46296,9 +47300,9 @@ return 0; - fail: +fail: DUK__SET_CONN_BROKEN(thr, 1); - return 1; /* Pretend like we got EOM */ + return 1; /* Pretend like we got EOM */ } /* Skip dvalues to EOM. */ @@ -46318,7 +47322,7 @@ level = duk_debug_read_int(thr); if (level >= 0 || -level > (duk_int32_t) thr->callstack_top) { duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack index"); - return 0; /* zero indicates failure */ + return 0; /* zero indicates failure */ } return level; } @@ -46387,7 +47391,7 @@ duk_debug_clear_paused(heap); pause_flags = 0; -#if 0 /* manual testing */ +#if 0 /* manual testing */ pause_flags |= DUK_PAUSE_FLAG_ONE_OPCODE; pause_flags |= DUK_PAUSE_FLAG_CAUGHT_ERROR; pause_flags |= DUK_PAUSE_FLAG_UNCAUGHT_ERROR; @@ -46408,12 +47412,9 @@ DUK_D(DUK_DPRINT("debug command StepInto/StepOver/StepOut: %d", (int) cmd)); if (cmd == DUK_DBG_CMD_STEPINTO) { - pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | - DUK_PAUSE_FLAG_FUNC_ENTRY | - DUK_PAUSE_FLAG_FUNC_EXIT; + pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | DUK_PAUSE_FLAG_FUNC_ENTRY | DUK_PAUSE_FLAG_FUNC_EXIT; } else if (cmd == DUK_DBG_CMD_STEPOVER) { - pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | - DUK_PAUSE_FLAG_FUNC_EXIT; + pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | DUK_PAUSE_FLAG_FUNC_EXIT; } else { DUK_ASSERT(cmd == DUK_DBG_CMD_STEPOUT); pause_flags = DUK_PAUSE_FLAG_FUNC_EXIT; @@ -46492,7 +47493,7 @@ if (act == NULL) { return; } - str = duk_debug_read_hstring(thr); /* push to stack */ + str = duk_debug_read_hstring(thr); /* push to stack */ DUK_ASSERT(str != NULL); rc = duk_js_getvar_activation(thr, act, str, 0); @@ -46521,7 +47522,7 @@ if (act == NULL) { return; } - str = duk_debug_read_hstring(thr); /* push to stack */ + str = duk_debug_read_hstring(thr); /* push to stack */ DUK_ASSERT(str != NULL); tv = duk_debug_read_tval(thr); if (tv == NULL) { @@ -46619,7 +47620,7 @@ /* ... func varmap enum key value this */ duk_debug_write_hstring(thr, duk_get_hstring(thr, -3)); duk_debug_write_tval(thr, duk_get_tval(thr, -2)); - duk_pop_3(thr); /* -> ... func varmap enum */ + duk_pop_3(thr); /* -> ... func varmap enum */ } } else { DUK_D(DUK_DPRINT("varmap missing in GetLocals, ignore")); @@ -46654,12 +47655,12 @@ /* nargs == 2 so we can pass a callstack index to eval(). */ idx_func = duk_get_top(thr); duk_push_c_function(thr, duk_bi_global_object_eval, 2 /*nargs*/); - duk_push_undefined(thr); /* 'this' binding shouldn't matter here */ + duk_push_undefined(thr); /* 'this' binding shouldn't matter here */ /* Read callstack index, if non-null. */ if (duk_debug_peek_byte(thr) == DUK_DBG_IB_NULL) { direct_eval = 0; - level = -1; /* Not needed, but silences warning. */ + level = -1; /* Not needed, but silences warning. */ (void) duk_debug_read_byte(thr); } else { direct_eval = 1; @@ -46669,12 +47670,11 @@ } } - DUK_ASSERT(!direct_eval || - (level < 0 && -level <= (duk_int32_t) thr->callstack_top)); + DUK_ASSERT(!direct_eval || (level < 0 && -level <= (duk_int32_t) thr->callstack_top)); (void) duk_debug_read_hstring(thr); if (direct_eval) { - duk_push_int(thr, level - 1); /* compensate for eval() call */ + duk_push_int(thr, level - 1); /* compensate for eval() call */ } /* ... eval "eval" eval_input level? */ @@ -46729,7 +47729,7 @@ duk_debug_write_eom(thr); DUK_D(DUK_DPRINT("debug connection detached, mark broken")); - DUK__SET_CONN_BROKEN(thr, 0); /* not an error */ + DUK__SET_CONN_BROKEN(thr, 0); /* not an error */ } DUK_LOCAL void duk__debug_handle_apprequest(duk_hthread *thr, duk_heap *heap) { @@ -46737,7 +47737,7 @@ DUK_D(DUK_DPRINT("debug command AppRequest")); - old_top = duk_get_top(thr); /* save stack top */ + old_top = duk_get_top(thr); /* save stack top */ if (heap->dbg_request_cb != NULL) { duk_idx_t nrets; @@ -46753,7 +47753,7 @@ DUK_D(DUK_DPRINT("failed to allocate space for request dvalue(s)")); goto fail; } - tv = duk_debug_read_tval(thr); /* push to stack */ + tv = duk_debug_read_tval(thr); /* push to stack */ if (tv == NULL) { /* detached */ return; @@ -46764,17 +47764,24 @@ /* Request callback should push values for reply to client onto valstack */ DUK_D(DUK_DPRINT("calling into AppRequest request_cb with nvalues=%ld, old_top=%ld, top=%ld", - (long) nvalues, (long) old_top, (long) duk_get_top(thr))); + (long) nvalues, + (long) old_top, + (long) duk_get_top(thr))); nrets = heap->dbg_request_cb(thr, heap->dbg_udata, nvalues); DUK_D(DUK_DPRINT("returned from AppRequest request_cb; nvalues=%ld -> nrets=%ld, old_top=%ld, top=%ld", - (long) nvalues, (long) nrets, (long) old_top, (long) duk_get_top(thr))); + (long) nvalues, + (long) nrets, + (long) old_top, + (long) duk_get_top(thr))); if (nrets >= 0) { DUK_ASSERT(duk_get_top(thr) >= old_top + nrets); if (duk_get_top(thr) < old_top + nrets) { DUK_D(DUK_DPRINT("AppRequest callback doesn't match value stack configuration, " "top=%ld < old_top=%ld + nrets=%ld; " "this might mean it's unsafe to continue!", - (long) duk_get_top(thr), (long) old_top, (long) nrets)); + (long) duk_get_top(thr), + (long) old_top, + (long) nrets)); goto fail; } @@ -46794,7 +47801,7 @@ duk_debug_write_error_eom(thr, DUK_DBG_ERR_APPLICATION, duk_get_string(thr, -1)); } - duk_set_top(thr, old_top); /* restore stack top */ + duk_set_top(thr, old_top); /* restore stack top */ } else { DUK_D(DUK_DPRINT("no request callback, treat AppRequest as unsupported")); duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNSUPPORTED, "AppRequest unsupported by target"); @@ -46802,8 +47809,8 @@ return; - fail: - duk_set_top(thr, old_top); /* restore stack top */ +fail: + duk_set_top(thr, old_top); /* restore stack top */ DUK__SET_CONN_BROKEN(thr, 1); } @@ -46854,16 +47861,16 @@ k = DUK_HOBJECT_E_GET_KEY(heap, h, i); duk_debug_write_heapptr(thr, (duk_heaphdr *) k); if (k == NULL) { - duk_debug_write_int(thr, 0); /* isAccessor */ + duk_debug_write_int(thr, 0); /* isAccessor */ duk_debug_write_unused(thr); continue; } if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap, h, i)) { - duk_debug_write_int(thr, 1); /* isAccessor */ + duk_debug_write_int(thr, 1); /* isAccessor */ duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->a.get); duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->a.set); } else { - duk_debug_write_int(thr, 0); /* isAccessor */ + duk_debug_write_int(thr, 0); /* isAccessor */ duk__debug_write_tval_heapptr(thr, &DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->v); } @@ -46925,7 +47932,7 @@ duk__debug_dump_strtab(thr, heap); duk_debug_write_eom(thr); } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ DUK_LOCAL void duk__debug_handle_get_bytecode(duk_hthread *thr, duk_heap *heap) { duk_activation *act; @@ -46994,11 +48001,11 @@ duk_debug_write_eom(thr); return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid argument"); return; - fail_index: +fail_index: duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack index"); return; } @@ -47050,53 +48057,22 @@ DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS, #endif DUK_HSTRING_FLAG_EXTDATA, - 0 /* terminator */ + 0 /* terminator */ }; DUK_LOCAL const char * const duk__debug_getinfo_hobject_keys = { - "extensible", - "constructable", - "callable", - "boundfunc", - "compfunc", - "natfunc", - "bufobj", - "fastrefs", - "array_part", - "strict", - "notail", - "newenv", - "namebinding", - "createargs", - "have_finalizer", - "exotic_array", - "exotic_stringobj", - "exotic_arguments", - "exotic_proxyobj", - "special_call" + "extensible", "constructable", "callable", "boundfunc", "compfunc", "natfunc", "bufobj", + "fastrefs", "array_part", "strict", "notail", "newenv", "namebinding", "createargs", + "have_finalizer", "exotic_array", "exotic_stringobj", "exotic_arguments", "exotic_proxyobj", "special_call" /* NULL not needed here */ }; DUK_LOCAL duk_uint_t duk__debug_getinfo_hobject_masks = { - DUK_HOBJECT_FLAG_EXTENSIBLE, - DUK_HOBJECT_FLAG_CONSTRUCTABLE, - DUK_HOBJECT_FLAG_CALLABLE, - DUK_HOBJECT_FLAG_BOUNDFUNC, - DUK_HOBJECT_FLAG_COMPFUNC, - DUK_HOBJECT_FLAG_NATFUNC, - DUK_HOBJECT_FLAG_BUFOBJ, - DUK_HOBJECT_FLAG_FASTREFS, - DUK_HOBJECT_FLAG_ARRAY_PART, - DUK_HOBJECT_FLAG_STRICT, - DUK_HOBJECT_FLAG_NOTAIL, - DUK_HOBJECT_FLAG_NEWENV, - DUK_HOBJECT_FLAG_NAMEBINDING, - DUK_HOBJECT_FLAG_CREATEARGS, - DUK_HOBJECT_FLAG_HAVE_FINALIZER, - DUK_HOBJECT_FLAG_EXOTIC_ARRAY, - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ, - DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS, - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ, - DUK_HOBJECT_FLAG_SPECIAL_CALL, - 0 /* terminator */ + DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_HOBJECT_FLAG_CONSTRUCTABLE, DUK_HOBJECT_FLAG_CALLABLE, + DUK_HOBJECT_FLAG_BOUNDFUNC, DUK_HOBJECT_FLAG_COMPFUNC, DUK_HOBJECT_FLAG_NATFUNC, + DUK_HOBJECT_FLAG_BUFOBJ, DUK_HOBJECT_FLAG_FASTREFS, DUK_HOBJECT_FLAG_ARRAY_PART, + DUK_HOBJECT_FLAG_STRICT, DUK_HOBJECT_FLAG_NOTAIL, DUK_HOBJECT_FLAG_NEWENV, + DUK_HOBJECT_FLAG_NAMEBINDING, DUK_HOBJECT_FLAG_CREATEARGS, DUK_HOBJECT_FLAG_HAVE_FINALIZER, + DUK_HOBJECT_FLAG_EXOTIC_ARRAY, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS, + DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ, DUK_HOBJECT_FLAG_SPECIAL_CALL, 0 /* terminator */ }; DUK_LOCAL const char * const duk__debug_getinfo_hbuffer_keys = { "dynamic", @@ -47106,7 +48082,7 @@ DUK_LOCAL duk_uint_t duk__debug_getinfo_hbuffer_masks = { DUK_HBUFFER_FLAG_DYNAMIC, DUK_HBUFFER_FLAG_EXTERNAL, - 0 /* terminator */ + 0 /* terminator */ }; DUK_LOCAL void duk__debug_getinfo_flags_key(duk_hthread *thr, const char *key) { @@ -47132,7 +48108,7 @@ duk_debug_write_boolean(thr, val); } -DUK_LOCAL void duk__debug_getinfo_bitmask(duk_hthread *thr, const char * const * keys, duk_uint_t *masks, duk_uint_t flags) { +DUK_LOCAL void duk__debug_getinfo_bitmask(duk_hthread *thr, const char * const *keys, duk_uint_t *masks, duk_uint_t flags) { const char *key; duk_uint_t mask; @@ -47144,7 +48120,10 @@ key = *keys++; DUK_ASSERT(key != NULL); - DUK_DD(DUK_DDPRINT("inspect bitmask: key=%s, mask=0x%08lx, flags=0x%08lx", key, (unsigned long) mask, (unsigned long) flags)); + DUK_DD(DUK_DDPRINT("inspect bitmask: key=%s, mask=0x%08lx, flags=0x%08lx", + key, + (unsigned long) mask, + (unsigned long) flags)); duk__debug_getinfo_prop_bool(thr, key, flags & mask); } } @@ -47220,9 +48199,12 @@ DUK_D(DUK_DPRINT("debug command GetHeapObjInfo")); DUK_UNREF(heap); - DUK_ASSERT(sizeof(duk__debug_getinfo_hstring_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hstring_masks) / sizeof(duk_uint_t) - 1); - DUK_ASSERT(sizeof(duk__debug_getinfo_hobject_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hobject_masks) / sizeof(duk_uint_t) - 1); - DUK_ASSERT(sizeof(duk__debug_getinfo_hbuffer_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hbuffer_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hstring_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hstring_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hobject_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hobject_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hbuffer_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hbuffer_masks) / sizeof(duk_uint_t) - 1); h = duk_debug_read_any_ptr(thr); if (!h) { @@ -47410,7 +48392,7 @@ duk_debug_write_heapptr(thr, (duk_heaphdr *) h_bufobj->buf); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ break; } case DUK_HTYPE_BUFFER: { @@ -47425,7 +48407,7 @@ duk__debug_getinfo_flags_key(thr, "dataptr"); duk_debug_write_pointer(thr, (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_buf)); duk__debug_getinfo_flags_key(thr, "data"); - duk_debug_write_hbuffer(thr, h_buf); /* tolerates NULL h_buf */ + duk_debug_write_hbuffer(thr, h_buf); /* tolerates NULL h_buf */ break; } default: { @@ -47463,8 +48445,7 @@ /* To use the shared helper need the virtual index. */ DUK_ASSERT(desc.e_idx >= 0 || desc.a_idx >= 0); - virtual_idx = (desc.a_idx >= 0 ? desc.a_idx : - (duk_int_t) DUK_HOBJECT_GET_ASIZE(h_obj) + desc.e_idx); + virtual_idx = (desc.a_idx >= 0 ? desc.a_idx : (duk_int_t) DUK_HOBJECT_GET_ASIZE(h_obj) + desc.e_idx); duk_debug_write_reply(thr); rc = duk__debug_getprop_index(thr, heap, h_obj, (duk_uint_t) virtual_idx); @@ -47476,7 +48457,7 @@ } return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid args"); } @@ -47512,11 +48493,11 @@ duk_debug_write_eom(thr); return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid args"); } -#endif /* DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_INSPECT */ /* * Process incoming debug requests @@ -47614,7 +48595,7 @@ duk__debug_handle_dump_heap(thr, heap); break; } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ case DUK_DBG_CMD_GETBYTECODE: { duk__debug_handle_get_bytecode(thr, heap); break; @@ -47636,12 +48617,12 @@ duk__debug_handle_get_obj_prop_desc_range(thr, heap); break; } -#endif /* DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_INSPECT */ default: { DUK_D(DUK_DPRINT("debug command unsupported: %d", (int) cmd)); duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNSUPPORTED, "unsupported command"); } - } /* switch cmd */ + } /* switch cmd */ break; } case DUK_DBG_IB_REPLY: { @@ -47660,14 +48641,14 @@ DUK_D(DUK_DPRINT("invalid initial byte, drop connection: %d", (int) x)); goto fail; } - } /* switch initial byte */ + } /* switch initial byte */ DUK_ASSERT(duk_get_top(thr) >= entry_top); duk_set_top(thr, entry_top); duk__debug_skip_to_eom(thr); return; - fail: +fail: DUK_ASSERT(duk_get_top(thr) >= entry_top); duk_set_top(thr, entry_top); DUK__SET_CONN_BROKEN(thr, 1); @@ -47694,8 +48675,10 @@ #endif DUK_D(DUK_DPRINT("process debug messages: read_cb=%s, no_block=%ld, detaching=%ld, processing=%ld", - thr->heap->dbg_read_cb ? "not NULL" : "NULL", (long) no_block, - (long) thr->heap->dbg_detaching, (long) thr->heap->dbg_processing)); + thr->heap->dbg_read_cb ? "not NULL" : "NULL", + (long) no_block, + (long) thr->heap->dbg_detaching, + (long) thr->heap->dbg_processing)); DUK_DD(DUK_DDPRINT("top at entry: %ld", (long) duk_get_top(thr))); /* thr->heap->dbg_detaching may be != 0 if a debugger write outside @@ -47742,13 +48725,14 @@ DUK_D(DUK_DPRINT("detach pending (dbg_read_cb == NULL, dbg_detaching != 0), call detach2")); duk__debug_do_detach2(thr->heap); - thr->heap->dbg_processing = 1; /* may be set to 0 by duk_debugger_attach() inside callback */ + thr->heap->dbg_processing = 1; /* may be set to 0 by duk_debugger_attach() inside callback */ DUK_D(DUK_DPRINT("after detach2 (and possible reattach): dbg_read_cb=%s, dbg_detaching=%ld", - thr->heap->dbg_read_cb ? "not NULL" : "NULL", (long) thr->heap->dbg_detaching)); + thr->heap->dbg_read_cb ? "not NULL" : "NULL", + (long) thr->heap->dbg_detaching)); } - DUK_ASSERT(thr->heap->dbg_detaching == 0); /* true even with reattach */ - DUK_ASSERT(thr->heap->dbg_processing == 1); /* even after a detach and possible reattach */ + DUK_ASSERT(thr->heap->dbg_detaching == 0); /* true even with reattach */ + DUK_ASSERT(thr->heap->dbg_processing == 1); /* even after a detach and possible reattach */ if (thr->heap->dbg_read_cb == NULL) { DUK_D(DUK_DPRINT("debug connection broken (and not detaching), stop processing messages")); @@ -47773,7 +48757,7 @@ duk__debug_process_message(thr); duk__check_resend_status(thr); - retval = 1; /* processed one or more messages */ + retval = 1; /* processed one or more messages */ } DUK_ASSERT(thr->heap->dbg_detaching == 0); @@ -47783,7 +48767,7 @@ /* As an initial implementation, read flush after exiting the message * loop. If transport is broken, this is a no-op (with debug logs). */ - duk_debug_read_flush(thr); /* this cannot initiate a detach */ + duk_debug_read_flush(thr); /* this cannot initiate a detach */ DUK_ASSERT(thr->heap->dbg_detaching == 0); DUK_DD(DUK_DDPRINT("top at exit: %ld", (long) duk_get_top(thr))); @@ -47834,11 +48818,8 @@ /* Short circuit if is safe: if act->curr_pc != NULL, 'fun' is * guaranteed to be a non-NULL ECMAScript function. */ - DUK_ASSERT(act->curr_pc == NULL || - (fun != NULL && DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun))); - if (use_prev_pc && - act->curr_pc != NULL && - act->curr_pc > DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, fun)) { + DUK_ASSERT(act->curr_pc == NULL || (fun != NULL && DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun))); + if (use_prev_pc && act->curr_pc != NULL && act->curr_pc > DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, fun)) { act->curr_pc--; } } @@ -47865,7 +48846,7 @@ * with PC values. */ if (act != NULL) { - act->curr_pc = old_pc; /* restore PC */ + act->curr_pc = old_pc; /* restore PC */ } } @@ -47889,7 +48870,8 @@ if (heap->dbg_breakpoint_count >= DUK_HEAP_MAX_BREAKPOINTS) { DUK_D(DUK_DPRINT("failed to add breakpoint for %O:%ld, all breakpoint slots used", - (duk_heaphdr *) filename, (long) line)); + (duk_heaphdr *) filename, + (long) line)); return -1; } heap->dbg_breakpoints_active0 = (duk_breakpoint *) NULL; @@ -47898,7 +48880,7 @@ b->line = line; DUK_HSTRING_INCREF(thr, filename); - return (duk_small_int_t) (heap->dbg_breakpoint_count - 1); /* index */ + return (duk_small_int_t) (heap->dbg_breakpoint_count - 1); /* index */ } DUK_INTERNAL duk_bool_t duk_debug_remove_breakpoint(duk_hthread *thr, duk_small_uint_t breakpoint_index) { @@ -47916,7 +48898,7 @@ heap = thr->heap; DUK_ASSERT(heap != NULL); DUK_ASSERT(duk_debug_is_attached(thr->heap)); - DUK_ASSERT_DISABLE(breakpoint_index >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(breakpoint_index >= 0); /* unsigned */ if (breakpoint_index >= heap->dbg_breakpoint_count) { DUK_D(DUK_DPRINT("invalid breakpoint index: %ld", (long) breakpoint_index)); @@ -47928,15 +48910,13 @@ DUK_ASSERT(h != NULL); move_size = sizeof(duk_breakpoint) * (heap->dbg_breakpoint_count - breakpoint_index - 1); - duk_memmove((void *) b, - (const void *) (b + 1), - (size_t) move_size); + duk_memmove((void *) b, (const void *) (b + 1), (size_t) move_size); heap->dbg_breakpoint_count--; heap->dbg_breakpoints_active0 = (duk_breakpoint *) NULL; - DUK_HSTRING_DECREF(thr, h); /* side effects */ - DUK_UNREF(h); /* w/o refcounting */ + DUK_HSTRING_DECREF(thr, h); /* side effects */ + DUK_UNREF(h); /* w/o refcounting */ /* Breakpoint entries above the used area are left as garbage. */ @@ -47962,10 +48942,10 @@ DUK_HEAP_SET_DEBUGGER_PAUSED(heap); heap->dbg_state_dirty = 1; duk_debug_clear_pause_state(heap); - DUK_ASSERT(heap->ms_running == 0); /* debugger can't be triggered within mark-and-sweep */ - heap->ms_running = 2; /* prevent mark-and-sweep, prevent refzero queueing */ + DUK_ASSERT(heap->ms_running == 0); /* debugger can't be triggered within mark-and-sweep */ + heap->ms_running = 2; /* prevent mark-and-sweep, prevent refzero queueing */ heap->ms_prevent_count++; - DUK_ASSERT(heap->ms_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(heap->ms_prevent_count != 0); /* Wrap. */ DUK_ASSERT(heap->heap_thread != NULL); } } @@ -47991,11 +48971,11 @@ heap->dbg_pause_startline = 0; } -#else /* DUK_USE_DEBUGGER_SUPPORT */ +#else /* DUK_USE_DEBUGGER_SUPPORT */ /* No debugger support. */ -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* automatic undefs */ #undef DUK__DBG_TPORT_ENTER @@ -48085,7 +49065,7 @@ * when it is called and that error replaces the original one. */ - DUK_ASSERT_VALSTACK_SPACE(thr, 4); /* 3 entries actually needed below */ + DUK_ASSERT_VALSTACK_SPACE(thr, 4); /* 3 entries actually needed below */ /* ... errval */ @@ -48096,23 +49076,19 @@ DUK_DD(DUK_DDPRINT("error occurred when DUK_BIDX_DUKTAPE is NULL, ignoring")); return; } - tv_hnd = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, - thr->builtinsDUK_BIDX_DUKTAPE, - stridx_cb); + tv_hnd = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, thr->builtinsDUK_BIDX_DUKTAPE, stridx_cb); if (tv_hnd == NULL) { - DUK_DD(DUK_DDPRINT("error handler does not exist or is not a plain value: %!T", - (duk_tval *) tv_hnd)); + DUK_DD(DUK_DDPRINT("error handler does not exist or is not a plain value: %!T", (duk_tval *) tv_hnd)); return; } - DUK_DDD(DUK_DDDPRINT("error handler dump (callability not checked): %!T", - (duk_tval *) tv_hnd)); + DUK_DDD(DUK_DDDPRINT("error handler dump (callability not checked): %!T", (duk_tval *) tv_hnd)); duk_push_tval(thr, tv_hnd); /* ... errval errhandler */ - duk_insert(thr, -2); /* -> ... errhandler errval */ + duk_insert(thr, -2); /* -> ... errhandler errval */ duk_push_undefined(thr); - duk_insert(thr, -2); /* -> ... errhandler undefined(= this) errval */ + duk_insert(thr, -2); /* -> ... errhandler undefined(= this) errval */ /* ... errhandler undefined errval */ @@ -48129,21 +49105,25 @@ thr->heap->augmenting_error = 1; rc = duk_pcall_method(thr, 1); - DUK_UNREF(rc); /* no need to check now: both success and error are OK */ + DUK_UNREF(rc); /* no need to check now: both success and error are OK */ DUK_ASSERT(thr->heap->augmenting_error == 1); thr->heap->augmenting_error = 0; /* ... errval */ } -#endif /* DUK_USE_ERRTHROW || DUK_USE_ERRCREATE */ +#endif /* DUK_USE_ERRTHROW || DUK_USE_ERRCREATE */ /* * Add ._Tracedata to an error on the stack top. */ #if defined(DUK_USE_TRACEBACKS) -DUK_LOCAL void duk__add_traceback(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_LOCAL void duk__add_traceback(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { duk_activation *act; duk_int_t depth; duk_int_t arr_size; @@ -48165,15 +49145,14 @@ * See doc/error-objects.rst. */ - DUK_DDD(DUK_DDDPRINT("adding traceback to object: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("adding traceback to object: %!T", (duk_tval *) duk_get_tval(thr, -1))); /* Preallocate array to correct size, so that we can just write out * the _Tracedata values into the array part. */ act = thr->callstack_curr; depth = DUK_USE_TRACEBACK_DEPTH; - DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ + DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ if (depth > (duk_int_t) thr_callstack->callstack_top) { depth = (duk_int_t) thr_callstack->callstack_top; } @@ -48215,7 +49194,7 @@ DUK_HSTRING_INCREF(thr, s); tv++; - u32 = (duk_uint32_t) thr->compile_ctx->curr_token.start_line; /* (flags<<32) + (line), flags = 0 */ + u32 = (duk_uint32_t) thr->compile_ctx->curr_token.start_line; /* (flags<<32) + (line), flags = 0 */ DUK_TVAL_SET_U32(tv, u32); tv++; } @@ -48229,13 +49208,15 @@ if (c_filename) { DUK_ASSERT(DUK_TVAL_IS_STRING(thr->valstack_top - 2)); - s = DUK_TVAL_GET_STRING(thr->valstack_top - 2); /* interned c_filename */ + s = DUK_TVAL_GET_STRING(thr->valstack_top - 2); /* interned c_filename */ DUK_ASSERT(s != NULL); DUK_TVAL_SET_STRING(tv, s); DUK_HSTRING_INCREF(thr, s); tv++; - d = ((flags & DUK_AUGMENT_FLAG_NOBLAME_FILELINE) ? ((duk_double_t) DUK_TB_FLAG_NOBLAME_FILELINE) * DUK_DOUBLE_2TO32 : 0.0) + + d = ((flags & DUK_AUGMENT_FLAG_NOBLAME_FILELINE) ? + ((duk_double_t) DUK_TB_FLAG_NOBLAME_FILELINE) * DUK_DOUBLE_2TO32 : + 0.0) + (duk_double_t) c_line; DUK_TVAL_SET_DOUBLE(tv, d); tv++; @@ -48250,11 +49231,11 @@ /* ... arr */ - DUK_ASSERT(act != NULL); /* depth check above, assumes book-keeping is correct */ - DUK_ASSERT_DISABLE(act->pc >= 0); /* unsigned */ + DUK_ASSERT(act != NULL); /* depth check above, assumes book-keeping is correct */ + DUK_ASSERT_DISABLE(act->pc >= 0); /* unsigned */ /* Add function object. */ - tv_src = &act->tv_func; /* object (function) or lightfunc */ + tv_src = &act->tv_func; /* object (function) or lightfunc */ DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv_src) || DUK_TVAL_IS_LIGHTFUNC(tv_src)); DUK_TVAL_SET_TVAL(tv, tv_src); DUK_TVAL_INCREF(thr, tv); @@ -48266,8 +49247,8 @@ * PC == 0 for native code. */ pc = (duk_uint32_t) duk_hthread_get_act_prev_pc(thr_callstack, act); - DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ - DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ + DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ + DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ d = ((duk_double_t) act->flags) * DUK_DOUBLE_2TO32 + (duk_double_t) pc; DUK_TVAL_SET_DOUBLE(tv, d); tv++; @@ -48292,16 +49273,20 @@ /* ... error arr */ - duk_xdef_prop_stridx_short_wec(thr, -2, DUK_STRIDX_INT_TRACEDATA); /* -> ... error */ + duk_xdef_prop_stridx_short_wec(thr, -2, DUK_STRIDX_INT_TRACEDATA); /* -> ... error */ } -#endif /* DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_TRACEBACKS */ /* * Add .fileName and .lineNumber to an error on the stack top. */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) && !defined(DUK_USE_TRACEBACKS) -DUK_LOCAL void duk__add_fileline(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_LOCAL void duk__add_fileline(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { #if defined(DUK_USE_ASSERTIONS) duk_int_t entry_top; #endif @@ -48339,7 +49324,7 @@ duk_uint32_t ecma_line; duk_activation *act; - DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ + DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ depth = DUK_USE_TRACEBACK_DEPTH; if (depth > thr_callstack->callstack_top) { depth = thr_callstack->callstack_top; @@ -48358,10 +49343,12 @@ /* PC points to next instruction, find offending PC, * PC == 0 for native code. */ - pc = duk_hthread_get_act_prev_pc(thr, act); /* thr argument only used for thr->heap, so specific thread doesn't matter */ + pc = duk_hthread_get_act_prev_pc( + thr, + act); /* thr argument only used for thr->heap, so specific thread doesn't matter */ DUK_UNREF(pc); - DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ - DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ + DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ + DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ duk_push_hobject(thr, func); @@ -48382,7 +49369,7 @@ } else { /* Native function, no relevant lineNumber. */ } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ duk_push_u32(thr, ecma_line); /* ... error func fileName lineNumber */ @@ -48401,7 +49388,7 @@ duk_push_undefined(thr); } - define_props: +define_props: /* ... error lineNumber fileName */ #if defined(DUK_USE_ASSERTIONS) DUK_ASSERT(duk_get_top(thr) == entry_top + 2); @@ -48409,7 +49396,7 @@ duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_C | DUK_PROPDESC_FLAG_NO_OVERWRITE); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LINE_NUMBER, DUK_PROPDESC_FLAGS_C | DUK_PROPDESC_FLAG_NO_OVERWRITE); } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE && !DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE && !DUK_USE_TRACEBACKS */ /* * Add line number to a compiler error. @@ -48417,7 +49404,6 @@ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) DUK_LOCAL void duk__add_compiler_error_line(duk_hthread *thr) { - /* Append a "(line NNN)" to the "message" property of any error * thrown during compilation. Usually compilation errors are * SyntaxErrors but they can also be out-of-memory errors and @@ -48432,8 +49418,7 @@ return; } - DUK_DDD(DUK_DDDPRINT("compile error, before adding line info: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("compile error, before adding line info: %!T", (duk_tval *) duk_get_tval(thr, -1))); if (duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_MESSAGE)) { duk_bool_t at_end; @@ -48455,7 +49440,8 @@ (long) thr->compile_ctx->lex.window0.codepoint, (long) thr->compile_ctx->lex.window1.codepoint)); - duk_push_sprintf(thr, " (line %ld%s)", + duk_push_sprintf(thr, + " (line %ld%s)", (long) thr->compile_ctx->curr_token.start_line, at_end ? ", end of input" : ""); duk_concat(thr, 2); @@ -48464,10 +49450,9 @@ duk_pop(thr); } - DUK_DDD(DUK_DDDPRINT("compile error, after adding line info: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("compile error, after adding line info: %!T", (duk_tval *) duk_get_tval(thr, -1))); } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error being created using Duktape specific properties @@ -48475,7 +49460,12 @@ */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_LOCAL void duk__err_augment_builtin_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_hobject *obj, duk_small_uint_t flags) { +DUK_LOCAL void duk__err_augment_builtin_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_hobject *obj, + duk_small_uint_t flags) { #if defined(DUK_USE_ASSERTIONS) duk_int_t entry_top; #endif @@ -48485,7 +49475,7 @@ #endif DUK_ASSERT(obj != NULL); - DUK_UNREF(obj); /* unreferenced w/o tracebacks */ + DUK_UNREF(obj); /* unreferenced w/o tracebacks */ duk__add_compiler_error_line(thr); @@ -48510,7 +49500,7 @@ DUK_ASSERT(duk_get_top(thr) == entry_top); #endif } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error at creation time with _Tracedata/fileName/lineNumber @@ -48528,7 +49518,11 @@ */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_INTERNAL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_INTERNAL void duk_err_augment_error_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { duk_hobject *obj; DUK_ASSERT(thr != NULL); @@ -48574,7 +49568,7 @@ duk__err_augment_user(thr, DUK_STRIDX_ERR_CREATE); #endif } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error at throw time; allow a user error handler (if defined) @@ -48586,9 +49580,9 @@ DUK_INTERNAL void duk_err_augment_error_throw(duk_hthread *thr) { #if defined(DUK_USE_ERRTHROW) duk__err_augment_user(thr, DUK_STRIDX_ERR_THROW); -#endif /* DUK_USE_ERRTHROW */ +#endif /* DUK_USE_ERRTHROW */ } -#endif /* DUK_USE_AUGMENT_ERROR_THROW */ +#endif /* DUK_USE_AUGMENT_ERROR_THROW */ /* * Do a longjmp call, calling the fatal error handler if no * catchpoint exists. @@ -48638,8 +49632,10 @@ DUK_ASSERT(thr->heap != NULL); DUK_DD(DUK_DDPRINT("longjmp error: type=%d iserror=%d value1=%!T value2=%!T", - (int) thr->heap->lj.type, (int) thr->heap->lj.iserror, - &thr->heap->lj.value1, &thr->heap->lj.value2)); + (int) thr->heap->lj.type, + (int) thr->heap->lj.iserror, + &thr->heap->lj.value1, + &thr->heap->lj.value2)); /* Prevent finalizer execution during error handling. All error * handling sites will process pending finalizers once error handling @@ -48657,11 +49653,11 @@ DUK_ASSERT_LJSTATE_SET(thr->heap); thr->heap->pf_prevent_count++; - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ #if defined(DUK_USE_ASSERTIONS) /* XXX: set this immediately when longjmp state is set */ - DUK_ASSERT(thr->heap->error_not_allowed == 0); /* Detect error within critical section. */ + DUK_ASSERT(thr->heap->error_not_allowed == 0); /* Detect error within critical section. */ thr->heap->error_not_allowed = 1; #endif @@ -48673,8 +49669,10 @@ */ if (!thr->heap->lj.jmpbuf_ptr) { DUK_D(DUK_DPRINT("uncaught error: type=%d iserror=%d value1=%!T value2=%!T", - (int) thr->heap->lj.type, (int) thr->heap->lj.iserror, - &thr->heap->lj.value1, &thr->heap->lj.value2)); + (int) thr->heap->lj.type, + (int) thr->heap->lj.iserror, + &thr->heap->lj.value1, + &thr->heap->lj.value2)); #if defined(DUK_USE_PREFER_SIZE) duk__uncaught_minimal(thr); @@ -48685,7 +49683,7 @@ } #if defined(DUK_USE_CPP_EXCEPTIONS) - throw duk_internal_exception(); /* dummy */ + throw duk_internal_exception(); /* dummy */ #else DUK_LONGJMP(thr->heap->lj.jmpbuf_ptr->jb); #endif @@ -48720,14 +49718,14 @@ for (act = thr->callstack_curr; act != NULL; act = act->parent) { for (cat = act->cat; cat != NULL; cat = cat->parent) { if (DUK_CAT_HAS_CATCH_ENABLED(cat)) { - return 1; /* all we need to know */ + return 1; /* all we need to know */ } } } } return 0; } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Get prototype object for an integer error code. @@ -48777,11 +49775,10 @@ * config options. */ - if (!duk_debug_is_attached(thr->heap) || - thr->heap->dbg_processing || - thr->heap->lj.type != DUK_LJ_TYPE_THROW || + if (!duk_debug_is_attached(thr->heap) || thr->heap->dbg_processing || thr->heap->lj.type != DUK_LJ_TYPE_THROW || thr->heap->creating_error) { - DUK_D(DUK_DPRINT("skip debugger error integration; not attached, debugger processing, not THROW, or error thrown while creating error")); + DUK_D(DUK_DPRINT("skip debugger error integration; not attached, debugger processing, not THROW, or error thrown " + "while creating error")); return; } @@ -48809,7 +49806,7 @@ /* Store and reset longjmp state. */ DUK_ASSERT_LJSTATE_SET(thr->heap); DUK_TVAL_DECREF_NORZ(thr, tv_obj); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&thr->heap->lj.value2)); /* Always for THROW type. */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&thr->heap->lj.value2)); /* Always for THROW type. */ DUK_TVAL_SET_UNDEFINED(tv_obj); thr->heap->lj.type = DUK_LJ_TYPE_UNKNOWN; DUK_ASSERT_LJSTATE_UNSET(thr->heap); @@ -48844,7 +49841,7 @@ duk_pop(thr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Helpers for setting up heap longjmp state. @@ -48889,14 +49886,20 @@ */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code, const char *msg, const char *filename, duk_int_t line) { +DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, + duk_errcode_t code, + const char *msg, + const char *filename, + duk_int_t line) { #else DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code) { #endif #if defined(DUK_USE_VERBOSE_ERRORS) DUK_DD(DUK_DDPRINT("duk_err_create_and_throw(): code=%ld, msg=%s, filename=%s, line=%ld", - (long) code, (const char *) msg, - (const char *) filename, (long) line)); + (long) code, + (const char *) msg, + (const char *) filename, + (long) line)); #else DUK_DD(DUK_DDPRINT("duk_err_create_and_throw(): code=%ld", (long) code)); #endif @@ -48956,18 +49959,9 @@ * use 'msg' as a format string directly. */ #if defined(DUK_USE_VERBOSE_ERRORS) - duk_push_error_object_raw(thr, - code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - filename, - line, - "%s", - (const char *) msg); -#else - duk_push_error_object_raw(thr, - code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - NULL, - 0, - NULL); + duk_push_error_object_raw(thr, code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, filename, line, "%s", (const char *) msg); +#else + duk_push_error_object_raw(thr, code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, NULL, 0, NULL); #endif /* Note that an alloc error may happen during error augmentation. @@ -48977,8 +49971,7 @@ * avoiding it for alloc errors (this differs from Duktape 1.x). */ #if defined(DUK_USE_AUGMENT_ERROR_THROW) - DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT (before throw augment)", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT (before throw augment)", (duk_tval *) duk_get_tval(thr, -1))); duk_err_augment_error_throw(thr); #endif @@ -49001,7 +49994,8 @@ */ DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT, %!iT (after throw augment)", - (duk_tval *) &thr->heap->lj.value1, (duk_tval *) &thr->heap->lj.value2)); + (duk_tval *) &thr->heap->lj.value1, + (duk_tval *) &thr->heap->lj.value2)); duk_err_longjmp(thr); DUK_UNREACHABLE(); @@ -49055,7 +50049,7 @@ */ if (size > DUK_HBUFFER_MAX_BYTELEN) { DUK_D(DUK_DPRINT("hbuffer alloc failed: size too large: %ld", (long) size)); - return NULL; /* no need to write 'out_bufdata' */ + return NULL; /* no need to write 'out_bufdata' */ } if (flags & DUK_BUF_FLAG_EXTERNAL) { @@ -49067,7 +50061,7 @@ } else { header_size = sizeof(duk_hbuffer_fixed); alloc_size = sizeof(duk_hbuffer_fixed) + size; - DUK_ASSERT(alloc_size >= sizeof(duk_hbuffer_fixed)); /* no wrapping */ + DUK_ASSERT(alloc_size >= sizeof(duk_hbuffer_fixed)); /* no wrapping */ } res = (duk_hbuffer *) DUK_ALLOC(heap, alloc_size); @@ -49077,8 +50071,7 @@ /* zero everything unless requested not to do so */ #if defined(DUK_USE_ZERO_BUFFER_DATA) - duk_memzero((void *) res, - (flags & DUK_BUF_FLAG_NOZERO) ? header_size : alloc_size); + duk_memzero((void *) res, (flags & DUK_BUF_FLAG_NOZERO) ? header_size : alloc_size); #else duk_memzero((void *) res, header_size); #endif @@ -49101,7 +50094,7 @@ void *ptr; if (size > 0) { - DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); /* alloc external with size zero */ + DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); /* alloc external with size zero */ DUK_DDD(DUK_DDDPRINT("dynamic buffer with nonzero size, alloc actual buffer")); #if defined(DUK_USE_ZERO_BUFFER_DATA) ptr = DUK_ALLOC_ZEROED(heap, size); @@ -49141,16 +50134,16 @@ } else { DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); } - DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, &res->hdr); + DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, &res->hdr); DUK_DDD(DUK_DDDPRINT("allocated hbuffer: %p", (void *) res)); return res; - alloc_error: +alloc_error: DUK_DD(DUK_DDPRINT("hbuffer allocation failed")); DUK_FREE(heap, res); - return NULL; /* no need to write 'out_bufdata' */ + return NULL; /* no need to write 'out_bufdata' */ } /* For indirect allocs. */ @@ -49172,7 +50165,7 @@ DUK_ASSERT(h != NULL); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * duk_hbuffer operations such as resizing and inserting/appending data to * a dynamic buffer. @@ -49228,8 +50221,7 @@ if (new_size > prev_size) { DUK_ASSERT(new_size - prev_size > 0); #if defined(DUK_USE_ZERO_BUFFER_DATA) - duk_memzero((void *) ((char *) res + prev_size), - (duk_size_t) (new_size - prev_size)); + duk_memzero((void *) ((char *) res + prev_size), (duk_size_t) (new_size - prev_size)); #endif } @@ -49270,7 +50262,7 @@ return buf_avail >= len ? len : buf_avail; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * duk_heap allocation and freeing. */ @@ -49279,7 +50271,7 @@ #if defined(DUK_USE_ROM_STRINGS) /* Fixed seed value used with ROM strings. */ -#define DUK__FIXED_HASH_SEED 0xabcd1234 +#define DUK__FIXED_HASH_SEED 0xabcd1234 #endif /* @@ -49368,8 +50360,8 @@ #if defined(DUK_USE_HSTRING_EXTDATA) && defined(DUK_USE_EXTSTR_FREE) if (DUK_HSTRING_HAS_EXTDATA(h)) { - DUK_DDD(DUK_DDDPRINT("free extstr: hstring %!O, extdata: %p", - h, DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h))); + DUK_DDD( + DUK_DDDPRINT("free extstr: hstring %!O, extdata: %p", h, DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h))); DUK_USE_EXTSTR_FREE(heap->heap_udata, (const void *) DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h)); } #endif @@ -49393,7 +50385,6 @@ DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(hdr) == DUK_HTYPE_BUFFER); duk_free_hbuffer(heap, (duk_hbuffer *) hdr); } - } /* @@ -49423,10 +50414,10 @@ count_act++; #endif } - heap->activation_free = NULL; /* needed when called from mark-and-sweep */ + heap->activation_free = NULL; /* needed when called from mark-and-sweep */ return count_act; } -#endif /* DUK_USE_CACHE_ACTIVATION */ +#endif /* DUK_USE_CACHE_ACTIVATION */ #if defined(DUK_USE_CACHE_CATCHER) DUK_LOCAL duk_size_t duk__heap_free_catcher_freelist(duk_heap *heap) { @@ -49442,11 +50433,11 @@ count_cat++; #endif } - heap->catcher_free = NULL; /* needed when called from mark-and-sweep */ + heap->catcher_free = NULL; /* needed when called from mark-and-sweep */ return count_cat; } -#endif /* DUK_USE_CACHE_CATCHER */ +#endif /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL void duk_heap_free_freelists(duk_heap *heap) { duk_size_t count_act = 0; @@ -49462,8 +50453,8 @@ DUK_UNREF(count_act); DUK_UNREF(count_cat); - DUK_D(DUK_DPRINT("freed %ld activation freelist entries, %ld catcher freelist entries", - (long) count_act, (long) count_cat)); + DUK_D( + DUK_DPRINT("freed %ld activation freelist entries, %ld catcher freelist entries", (long) count_act, (long) count_cat)); } DUK_LOCAL void duk__free_allocated(duk_heap *heap) { @@ -49476,8 +50467,7 @@ * because they may happen with finalizer processing. */ - DUK_DDD(DUK_DDDPRINT("FINALFREE (allocated): %!iO", - (duk_heaphdr *) curr)); + DUK_DDD(DUK_DDDPRINT("FINALFREE (allocated): %!iO", (duk_heaphdr *) curr)); next = DUK_HEAPHDR_GET_NEXT(heap, curr); duk_heap_free_heaphdr_raw(heap, curr); curr = next; @@ -49491,14 +50481,13 @@ curr = heap->finalize_list; while (curr) { - DUK_DDD(DUK_DDDPRINT("FINALFREE (finalize_list): %!iO", - (duk_heaphdr *) curr)); + DUK_DDD(DUK_DDDPRINT("FINALFREE (finalize_list): %!iO", (duk_heaphdr *) curr)); next = DUK_HEAPHDR_GET_NEXT(heap, curr); duk_heap_free_heaphdr_raw(heap, curr); curr = next; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_LOCAL void duk__free_stringtable(duk_heap *heap) { /* strings are only tracked by stringtable */ @@ -49516,9 +50505,9 @@ DUK_ASSERT(heap != NULL); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* refzero not running -> must be empty */ + DUK_ASSERT(heap->refzero_list == NULL); /* refzero not running -> must be empty */ #endif - DUK_ASSERT(heap->finalize_list == NULL); /* mark-and-sweep last pass */ + DUK_ASSERT(heap->finalize_list == NULL); /* mark-and-sweep last pass */ if (heap->heap_thread == NULL) { /* May happen when heap allocation fails right off. There @@ -49541,11 +50530,11 @@ DUK_ASSERT(heap->ms_running == 0); DUK_ASSERT(heap->ms_prevent_count == 0); heap->pf_prevent_count = 1; - heap->ms_running = 2; /* Use distinguishable value. */ - heap->ms_prevent_count = 1; /* Bump, because mark-and-sweep assumes it's bumped when ms_running is set. */ + heap->ms_running = 2; /* Use distinguishable value. */ + heap->ms_prevent_count = 1; /* Bump, because mark-and-sweep assumes it's bumped when ms_running is set. */ - curr_limit = 0; /* suppress warning, not used */ - for (round_no = 0; ; round_no++) { + curr_limit = 0; /* suppress warning, not used */ + for (round_no = 0;; round_no++) { curr = heap->heap_allocated; count_all = 0; count_finalized = 0; @@ -49560,7 +50549,8 @@ if (DUK_HOBJECT_HAS_FINALIZER_FAST(heap, (duk_hobject *) curr)) { if (!DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) curr)) { - DUK_ASSERT(DUK_HEAP_HAS_FINALIZER_NORESCUE(heap)); /* maps to finalizer 2nd argument */ + DUK_ASSERT( + DUK_HEAP_HAS_FINALIZER_NORESCUE(heap)); /* maps to finalizer 2nd argument */ duk_heap_run_finalizer(heap, (duk_hobject *) curr); count_finalized++; } @@ -49587,10 +50577,13 @@ */ curr_limit = count_all * 2; } else { - curr_limit = (curr_limit * 3) / 4; /* Decrease by 25% every round */ + curr_limit = (curr_limit * 3) / 4; /* Decrease by 25% every round */ } DUK_D(DUK_DPRINT("finalizer round %ld complete, %ld objects, tried to execute %ld finalizers, current limit is %ld", - (long) round_no, (long) count_all, (long) count_finalized, (long) curr_limit)); + (long) round_no, + (long) count_all, + (long) count_finalized, + (long) curr_limit)); if (count_finalized == 0) { DUK_D(DUK_DPRINT("no more finalizable objects, forced finalization finished")); @@ -49607,7 +50600,7 @@ heap->ms_running = 0; heap->pf_prevent_count = 0; } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL void duk_heap_free(duk_heap *heap) { DUK_D(DUK_DPRINT("free heap: %p", (void *) heap)); @@ -49650,7 +50643,7 @@ duk_heap_mark_and_sweep(heap, 0); DUK_D(DUK_DPRINT("forced gc #3 in heap destruction (don't run finalizers)")); heap->pf_skip_finalizers = 1; - duk_heap_mark_and_sweep(heap, 0); /* Skip finalizers; queue finalizable objects to heap_allocated. */ + duk_heap_mark_and_sweep(heap, 0); /* Skip finalizers; queue finalizable objects to heap_allocated. */ /* There are never objects in refzero_list at this point, or at any * point beyond a DECREF (even a DECREF_NORZ). Since Duktape 2.1 @@ -49659,17 +50652,17 @@ * refcount. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) - DUK_ASSERT(heap->finalize_list == NULL); /* Last mark-and-sweep with skip_finalizers. */ + DUK_ASSERT(heap->finalize_list == NULL); /* Last mark-and-sweep with skip_finalizers. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_D(DUK_DPRINT("run finalizers for remaining finalizable objects")); - DUK_HEAP_SET_FINALIZER_NORESCUE(heap); /* Rescue no longer supported. */ + DUK_HEAP_SET_FINALIZER_NORESCUE(heap); /* Rescue no longer supported. */ duk__free_run_finalizers(heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* Note: heap->heap_thread, heap->curr_thread, and heap->heap_object * are on the heap allocated list. @@ -49682,7 +50675,7 @@ duk__free_allocated(heap); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) @@ -49725,7 +50718,9 @@ while (h != NULL) { hash = duk_heap_hashstring(heap, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); DUK_DD(DUK_DDPRINT("duk_rom_strings_lookup%d -> hash 0x%08lx, computed 0x%08lx", - (int) i, (unsigned long) DUK_HSTRING_GET_HASH(h), (unsigned long) hash)); + (int) i, + (unsigned long) DUK_HSTRING_GET_HASH(h), + (unsigned long) hash)); DUK_ASSERT(hash == (duk_uint32_t) DUK_HSTRING_GET_HASH(h)); h = (const duk_hstring *) h->hdr.h_next; @@ -49734,11 +50729,11 @@ #endif return 1; } -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ DUK_LOCAL duk_bool_t duk__init_heap_strings(duk_heap *heap) { duk_bitdecoder_ctx bd_ctx; - duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ + duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ duk_small_uint_t i; duk_memzero(&bd_ctx, sizeof(bd_ctx)); @@ -49794,18 +50789,16 @@ return 1; - failed: +failed: return 0; } -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ DUK_LOCAL duk_bool_t duk__init_heap_thread(duk_heap *heap) { duk_hthread *thr; DUK_D(DUK_DPRINT("heap init: alloc heap thread")); - thr = duk_hthread_alloc_unchecked(heap, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); + thr = duk_hthread_alloc_unchecked(heap, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); if (thr == NULL) { DUK_D(DUK_DPRINT("failed to alloc heap_thread")); return 0; @@ -49813,16 +50806,16 @@ thr->state = DUK_HTHREAD_STATE_INACTIVE; #if defined(DUK_USE_ROM_STRINGS) /* No strs pointer. */ -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) thr->strs16 = heap->strs16; #else thr->strs = heap->strs; #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ heap->heap_thread = thr; - DUK_HTHREAD_INCREF(thr, thr); /* Note: first argument not really used */ + DUK_HTHREAD_INCREF(thr, thr); /* Note: first argument not really used */ /* 'thr' is now reachable */ @@ -49841,7 +50834,8 @@ } #if defined(DUK_USE_DEBUG) -#define DUK__DUMPSZ(t) do { \ +#define DUK__DUMPSZ(t) \ + do { \ DUK_D(DUK_DPRINT("" #t "=%ld", (long) sizeof(t))); \ } while (0) @@ -49850,20 +50844,20 @@ * enough; the limits will then not be printed accurately but the magnitude * will be correct. */ -#define DUK__DUMPLM_SIGNED_RAW(t,a,b) do { \ - DUK_D(DUK_DPRINT(t "=%ld,%ld=%lf,%lf", \ - (long) (a), (long) (b), \ - (double) (a), (double) (b))); \ - } while (0) -#define DUK__DUMPLM_UNSIGNED_RAW(t,a,b) do { \ - DUK_D(DUK_DPRINT(t "=%lu,%lu=%lf,%lf", \ - (unsigned long) (a), (unsigned long) (b), \ - (double) (a), (double) (b))); \ +#define DUK__DUMPLM_SIGNED_RAW(t, a, b) \ + do { \ + DUK_D(DUK_DPRINT(t "=%ld,%ld=%lf,%lf", (long) (a), (long) (b), (double) (a), (double) (b))); \ + } while (0) +#define DUK__DUMPLM_UNSIGNED_RAW(t, a, b) \ + do { \ + DUK_D(DUK_DPRINT(t "=%lu,%lu=%lf,%lf", (unsigned long) (a), (unsigned long) (b), (double) (a), (double) (b))); \ } while (0) -#define DUK__DUMPLM_SIGNED(t) do { \ +#define DUK__DUMPLM_SIGNED(t) \ + do { \ DUK__DUMPLM_SIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \ } while (0) -#define DUK__DUMPLM_UNSIGNED(t) do { \ +#define DUK__DUMPLM_UNSIGNED(t) \ + do { \ DUK__DUMPLM_UNSIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \ } while (0) @@ -49936,7 +50930,7 @@ DUK__DUMPSZ(duk_tval); /* structs from duk_forwdecl.h */ - DUK__DUMPSZ(duk_jmpbuf); /* just one 'int' for C++ exceptions */ + DUK__DUMPSZ(duk_jmpbuf); /* just one 'int' for C++ exceptions */ DUK__DUMPSZ(duk_heaphdr); DUK__DUMPSZ(duk_heaphdr_string); DUK__DUMPSZ(duk_hstring); @@ -50060,7 +51054,7 @@ DUK_D(DUK_DPRINT("IEEE double endianness: ???")); #endif } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ DUK_INTERNAL duk_heap *duk_heap_alloc(duk_alloc_function alloc_func, @@ -50081,7 +51075,7 @@ DUK_ASSERT((DUK_HTYPE_STRING & 0x01U) == 0); DUK_ASSERT((DUK_HTYPE_BUFFER & 0x01U) == 0); - DUK_ASSERT((DUK_HTYPE_OBJECT & 0x01U) == 1); /* DUK_HEAPHDR_IS_OBJECT() relies ont his. */ + DUK_ASSERT((DUK_HTYPE_OBJECT & 0x01U) == 1); /* DUK_HEAPHDR_IS_OBJECT() relies ont his. */ /* * Debug dump type sizes @@ -50122,7 +51116,7 @@ #endif fatal_func(heap_udata, "sizeof(duk_tval) not 8 or 16, cannot use DUK_USE_EXEC_REGCONST_OPTIMIZE option"); } -#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ /* * Computed values (e.g. INFINITY) @@ -50206,18 +51200,18 @@ #endif #if defined(DUK_USE_ROM_STRINGS) /* no res->strs */ -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) /* res->strs16 is zeroed and zero decodes to NULL, so no NULL inits. */ #else { duk_small_uint_t i; - for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) { + for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) { res->strsi = NULL; - } + } } #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_DEBUGGER_SUPPORT) res->dbg_read_cb = NULL; res->dbg_write_cb = NULL; @@ -50228,7 +51222,7 @@ res->dbg_udata = NULL; res->dbg_pause_act = NULL; #endif -#endif /* DUK_USE_EXPLICIT_NULL_INIT */ +#endif /* DUK_USE_EXPLICIT_NULL_INIT */ res->alloc_func = alloc_func; res->realloc_func = realloc_func; @@ -50267,17 +51261,17 @@ /* XXX: make a common DUK_USE_ option, and allow custom fixed seed? */ DUK_D(DUK_DPRINT("using rom strings, force heap hash_seed to fixed value 0x%08lx", (long) DUK__FIXED_HASH_SEED)); res->hash_seed = (duk_uint32_t) DUK__FIXED_HASH_SEED; -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ res->hash_seed = (duk_uint32_t) (duk_uintptr_t) res; #if !defined(DUK_USE_STRHASH_DENSE) - res->hash_seed ^= 5381; /* Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0 */ + res->hash_seed ^= 5381; /* Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0 */ #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) res->lj.jmpbuf_ptr = NULL; #endif - DUK_ASSERT(res->lj.type == DUK_LJ_TYPE_UNKNOWN); /* zero */ + DUK_ASSERT(res->lj.type == DUK_LJ_TYPE_UNKNOWN); /* zero */ DUK_ASSERT(res->lj.iserror == 0); DUK_TVAL_SET_UNDEFINED(&res->lj.value1); DUK_TVAL_SET_UNDEFINED(&res->lj.value2); @@ -50313,14 +51307,14 @@ #if defined(DUK_USE_EXPLICIT_NULL_INIT) { duk_uint32_t i; - for (i = 0; i < st_initsize; i++) { + for (i = 0; i < st_initsize; i++) { res->strtablei = NULL; - } + } } #else duk_memzero(res->strtable, sizeof(duk_hstring *) * st_initsize); -#endif /* DUK_USE_EXPLICIT_NULL_INIT */ -#endif /* DUK_USE_STRTAB_PTRCOMP */ +#endif /* DUK_USE_EXPLICIT_NULL_INIT */ +#endif /* DUK_USE_STRTAB_PTRCOMP */ /* * Init stringcache @@ -50350,7 +51344,7 @@ } } #endif -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ /* XXX: error handling is incomplete. It would be cleanest if * there was a setjmp catchpoint, so that all init code could @@ -50391,9 +51385,9 @@ #endif DUK_D(DUK_DPRINT("heap init: initialize heap object")); DUK_ASSERT(res->heap_thread != NULL); - res->heap_object = duk_hobject_alloc_unchecked(res, DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT)); + res->heap_object = duk_hobject_alloc_unchecked(res, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT)); if (res->heap_object == NULL) { goto failed; } @@ -50409,8 +51403,8 @@ duk_util_tinyrandom_prepare_seed(res->heap_thread); #else res->rnd_state0 = (duk_uint64_t) duk_time_get_ecmascript_time(res->heap_thread); - DUK_ASSERT(res->rnd_state1 == 0); /* Not filled here, filled in by seed preparation. */ -#if 0 /* Manual test values matching misc/xoroshiro128plus_test.c. */ + DUK_ASSERT(res->rnd_state1 == 0); /* Not filled here, filled in by seed preparation. */ +#if 0 /* Manual test values matching misc/xoroshiro128plus_test.c. */ res->rnd_state0 = DUK_U64_CONSTANT(0xdeadbeef12345678); res->rnd_state1 = DUK_U64_CONSTANT(0xcafed00d12345678); #endif @@ -50462,7 +51456,7 @@ DUK_D(DUK_DPRINT("allocated heap: %p", (void *) res)); return res; - failed: +failed: DUK_D(DUK_DPRINT("heap allocation failed")); if (res != NULL) { @@ -50522,14 +51516,14 @@ /* Inner function call, error throw. */ duk_eval_string_noresult(thr, - "(function dummy() {\n" - " dummy.prototype = null; /* break reference loop */\n" - " try {\n" - " throw 'fake-finalizer-dummy-error';\n" - " } catch (e) {\n" - " void e;\n" - " }\n" - "})()"); + "(function dummy() {\n" + " dummy.prototype = null; /* break reference loop */\n" + " try {\n" + " throw 'fake-finalizer-dummy-error';\n" + " } catch (e) {\n" + " void e;\n" + " }\n" + "})()"); /* The above creates garbage (e.g. a function instance). Because * the function/prototype reference loop is broken, it gets collected @@ -50561,7 +51555,7 @@ (void) duk_pcall(thr, 0 /*nargs*/); duk_pop(thr); } -#endif /* DUK_USE_FINALIZER_TORTURE */ +#endif /* DUK_USE_FINALIZER_TORTURE */ /* * Process the finalize_list to completion. @@ -50673,12 +51667,13 @@ DUK_DD(DUK_DDPRINT("processing finalize_list entry: %p -> %!iO", (void *) curr, curr)); - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* Only objects have finalizers. */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* Only objects have finalizers. */ DUK_ASSERT(!DUK_HEAPHDR_HAS_REACHABLE(curr)); DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(curr)); - DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(curr)); /* All objects on finalize_list will have this flag (except object being finalized right now). */ - DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); /* Queueing code ensures. */ - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY(curr)); /* ROM objects never get freed (or finalized). */ + DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE( + curr)); /* All objects on finalize_list will have this flag (except object being finalized right now). */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); /* Queueing code ensures. */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY(curr)); /* ROM objects never get freed (or finalized). */ #if defined(DUK_USE_ASSERTIONS) DUK_ASSERT(heap->currently_finalizing == NULL); @@ -50706,11 +51701,11 @@ */ #if defined(DUK_USE_REFERENCE_COUNTING) DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); - had_zero_refcount = (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1); /* Preincremented on finalize_list insert. */ + had_zero_refcount = (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1); /* Preincremented on finalize_list insert. */ #endif DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); - duk_heap_run_finalizer(heap, (duk_hobject *) curr); /* must never longjmp */ + duk_heap_run_finalizer(heap, (duk_hobject *) curr); /* must never longjmp */ DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZED(curr)); /* XXX: assert that object is still in finalize_list * when duk_push_heapptr() allows automatic rescue. @@ -50718,12 +51713,14 @@ #if defined(DUK_USE_REFERENCE_COUNTING) DUK_DD(DUK_DDPRINT("refcount after finalizer (includes bump): %ld", (long) DUK_HEAPHDR_GET_REFCOUNT(curr))); - if (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1) { /* Only artificial bump in refcount? */ + if (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1) { /* Only artificial bump in refcount? */ #if defined(DUK_USE_DEBUG) if (had_zero_refcount) { - DUK_DD(DUK_DDPRINT("finalized object's refcount is zero -> free immediately (refcount queued)")); + DUK_DD(DUK_DDPRINT( + "finalized object's refcount is zero -> free immediately (refcount queued)")); } else { - DUK_DD(DUK_DDPRINT("finalized object's refcount is zero -> free immediately (mark-and-sweep queued)")); + DUK_DD(DUK_DDPRINT( + "finalized object's refcount is zero -> free immediately (mark-and-sweep queued)")); } #endif queue_back = 0; @@ -50773,21 +51770,21 @@ * decision. */ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); - DUK_HEAPHDR_PREDEC_REFCOUNT(curr); /* Remove artificial refcount bump. */ + DUK_HEAPHDR_PREDEC_REFCOUNT(curr); /* Remove artificial refcount bump. */ DUK_HEAPHDR_CLEAR_FINALIZABLE(curr); DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, curr); } else { /* No need to remove the refcount bump here. */ - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ DUK_DD(DUK_DDPRINT("refcount finalize after finalizer call: %!O", curr)); duk_hobject_refcount_finalize_norz(heap, (duk_hobject *) curr); duk_free_hobject(heap, (duk_hobject *) curr); DUK_DD(DUK_DDPRINT("freed hobject after finalization: %p", (void *) curr)); } -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ DUK_HEAPHDR_CLEAR_FINALIZABLE(curr); DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, curr); -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_DEBUG) count++; @@ -50853,11 +51850,11 @@ * caller must ensure that this function is not called if the target is * a Proxy. */ - duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_INT_FINALIZER); /* -> ... obj finalizer */ + duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_INT_FINALIZER); /* -> ... obj finalizer */ duk_dup_m2(thr); duk_push_boolean(thr, DUK_HEAP_HAS_FINALIZER_NORESCUE(thr->heap)); DUK_DDD(DUK_DDDPRINT("calling finalizer")); - duk_call(thr, 2); /* ... obj finalizer obj heapDestruct -> ... obj retval */ + duk_call(thr, 2); /* ... obj finalizer obj heapDestruct -> ... obj retval */ DUK_DDD(DUK_DDDPRINT("finalizer returned successfully")); return 0; @@ -50906,7 +51903,7 @@ return; } #endif - DUK_HEAPHDR_SET_FINALIZED((duk_heaphdr *) obj); /* ensure never re-entered until rescue cycle complete */ + DUK_HEAPHDR_SET_FINALIZED((duk_heaphdr *) obj); /* ensure never re-entered until rescue cycle complete */ #if defined(DUK_USE_ES6_PROXY) if (DUK_HOBJECT_IS_PROXY(obj)) { @@ -50918,29 +51915,30 @@ DUK_D(DUK_DPRINT("object is a Proxy, skip finalizer call")); return; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ - duk_push_hobject(thr, obj); /* this also increases refcount by one */ - rc = duk_safe_call(thr, duk__finalize_helper, NULL /*udata*/, 0 /*nargs*/, 1 /*nrets*/); /* -> ... obj retval/error */ - DUK_ASSERT_TOP(thr, entry_top + 2); /* duk_safe_call discipline */ + duk_push_hobject(thr, obj); /* this also increases refcount by one */ + rc = duk_safe_call(thr, duk__finalize_helper, NULL /*udata*/, 0 /*nargs*/, 1 /*nrets*/); /* -> ... obj retval/error */ + DUK_ASSERT_TOP(thr, entry_top + 2); /* duk_safe_call discipline */ if (rc != DUK_EXEC_SUCCESS) { /* Note: we ask for one return value from duk_safe_call to get this * error debugging here. */ DUK_D(DUK_DPRINT("wrapped finalizer call failed for object %p (ignored); error: %!T", - (void *) obj, (duk_tval *) duk_get_tval(thr, -1))); + (void *) obj, + (duk_tval *) duk_get_tval(thr, -1))); } - duk_pop_2(thr); /* -> ... */ + duk_pop_2(thr); /* -> ... */ DUK_ASSERT_TOP(thr, entry_top); } -#else /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ /* nothing */ -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * String hash computation (interning). * @@ -50964,9 +51962,9 @@ #if defined(DUK_USE_STRHASH_DENSE) /* Constants for duk_hashstring(). */ -#define DUK__STRHASH_SHORTSTRING 4096L -#define DUK__STRHASH_MEDIUMSTRING (256L * 1024L) -#define DUK__STRHASH_BLOCKSIZE 256L +#define DUK__STRHASH_SHORTSTRING 4096L +#define DUK__STRHASH_MEDIUMSTRING (256L * 1024L) +#define DUK__STRHASH_BLOCKSIZE 256L DUK_INTERNAL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len) { duk_uint32_t hash; @@ -51023,7 +52021,7 @@ #endif return hash; } -#else /* DUK_USE_STRHASH_DENSE */ +#else /* DUK_USE_STRHASH_DENSE */ DUK_INTERNAL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len) { duk_uint32_t hash; duk_size_t step; @@ -51041,10 +52039,10 @@ * more often in the suffix than in the prefix. */ - hash = heap->hash_seed ^ ((duk_uint32_t) len); /* Bernstein hash init value is normally 5381 */ + hash = heap->hash_seed ^ ((duk_uint32_t) len); /* Bernstein hash init value is normally 5381 */ step = (len >> DUK_USE_STRHASH_SKIP_SHIFT) + 1; for (off = len; off >= step; off -= step) { - DUK_ASSERT(off >= 1); /* off >= step, and step >= 1 */ + DUK_ASSERT(off >= 1); /* off >= step, and step >= 1 */ hash = (hash * 33) + stroff - 1; } @@ -51056,7 +52054,7 @@ #endif return hash; } -#endif /* DUK_USE_STRHASH_DENSE */ +#endif /* DUK_USE_STRHASH_DENSE */ /* automatic undefs */ #undef DUK__STRHASH_BLOCKSIZE @@ -51178,7 +52176,7 @@ DUK_HBUFOBJ_ASSERT_VALID(b); duk__mark_heaphdr(heap, (duk_heaphdr *) b->buf); duk__mark_heaphdr(heap, (duk_heaphdr *) b->buf_prop); -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ } else if (DUK_HOBJECT_IS_BOUNDFUNC(h)) { duk_hboundfunc *f = (duk_hboundfunc *) (void *) h; DUK_HBOUNDFUNC_ASSERT_VALID(f); @@ -51191,7 +52189,7 @@ DUK_HPROXY_ASSERT_VALID(p); duk__mark_heaphdr_nonnull(heap, (duk_heaphdr *) p->target); duk__mark_heaphdr_nonnull(heap, (duk_heaphdr *) p->handler); -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ } else if (DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; duk_activation *act; @@ -51212,7 +52210,7 @@ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) duk__mark_heaphdr(heap, (duk_heaphdr *) act->prev_caller); #endif -#if 0 /* nothing now */ +#if 0 /* nothing now */ for (cat = act->cat; cat != NULL; cat = cat->parent) { } #endif @@ -51235,9 +52233,8 @@ /* Mark any duk_heaphdr type. Recursion tracking happens only here. */ DUK_LOCAL void duk__mark_heaphdr(duk_heap *heap, duk_heaphdr *h) { - DUK_DDD(DUK_DDDPRINT("duk__mark_heaphdr %p, type %ld", - (void *) h, - (h != NULL ? (long) DUK_HEAPHDR_GET_TYPE(h) : (long) -1))); + DUK_DDD( + DUK_DDDPRINT("duk__mark_heaphdr %p, type %ld", (void *) h, (h != NULL ? (long) DUK_HEAPHDR_GET_TYPE(h) : (long) -1))); /* XXX: add non-null variant? */ if (h == NULL) { @@ -51249,7 +52246,7 @@ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) if (!DUK_HEAPHDR_HAS_READONLY(h)) { - h->h_assert_refcount++; /* Comparison refcount: bump even if already reachable. */ + h->h_assert_refcount++; /* Comparison refcount: bump even if already reachable. */ } #endif if (DUK_HEAPHDR_HAS_REACHABLE(h)) { @@ -51273,7 +52270,7 @@ } heap->ms_recursion_depth++; - DUK_ASSERT(heap->ms_recursion_depth != 0); /* Wrap. */ + DUK_ASSERT(heap->ms_recursion_depth != 0); /* Wrap. */ switch (DUK_HEAPHDR_GET_TYPE(h)) { case DUK_HTYPE_STRING: @@ -51388,9 +52385,7 @@ * of a _Finalizer hidden symbol. */ - if (!DUK_HEAPHDR_HAS_REACHABLE(hdr) && - DUK_HEAPHDR_IS_OBJECT(hdr) && - !DUK_HEAPHDR_HAS_FINALIZED(hdr) && + if (!DUK_HEAPHDR_HAS_REACHABLE(hdr) && DUK_HEAPHDR_IS_OBJECT(hdr) && !DUK_HEAPHDR_HAS_FINALIZED(hdr) && DUK_HOBJECT_HAS_FINALIZER_FAST(heap, (duk_hobject *) hdr)) { /* heaphdr: * - is not reachable @@ -51415,8 +52410,7 @@ return; } - DUK_DD(DUK_DDPRINT("marked %ld heap objects as finalizable, now mark them reachable", - (long) count_finalizable)); + DUK_DD(DUK_DDPRINT("marked %ld heap objects as finalizable, now mark them reachable", (long) count_finalizable)); hdr = heap->heap_allocated; while (hdr != NULL) { @@ -51429,7 +52423,7 @@ /* Caller will finish the marking process if we hit a recursion limit. */ } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Mark objects on finalize_list. @@ -51460,7 +52454,7 @@ } #endif } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Fallback marking handler if recursion limit is reached. @@ -51493,9 +52487,9 @@ DUK_DDD(DUK_DDDPRINT("found a temp root: %p", (void *) hdr)); DUK_HEAPHDR_CLEAR_TEMPROOT(hdr); - DUK_HEAPHDR_CLEAR_REACHABLE(hdr); /* Done so that duk__mark_heaphdr() works correctly. */ + DUK_HEAPHDR_CLEAR_REACHABLE(hdr); /* Done so that duk__mark_heaphdr() works correctly. */ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) - hdr->h_assert_refcount--; /* Same node visited twice. */ + hdr->h_assert_refcount--; /* Same node visited twice. */ #endif duk__mark_heaphdr_nonnull(heap, hdr); @@ -51590,7 +52584,7 @@ hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr); } } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Clear (reachable) flags of finalize_list. @@ -51613,15 +52607,14 @@ while (hdr) { DUK_HEAPHDR_CLEAR_REACHABLE(hdr); #if defined(DUK_USE_ASSERTIONS) - DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(hdr) || \ - (heap->currently_finalizing == hdr)); + DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(hdr) || (heap->currently_finalizing == hdr)); #endif /* DUK_HEAPHDR_FLAG_FINALIZED may be set. */ DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(hdr)); hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr); } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Sweep stringtable. @@ -51657,8 +52650,7 @@ duk_hstring *next; next = h->hdr.h_next; - if (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h)) - { + if (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h)) { DUK_HEAPHDR_CLEAR_REACHABLE((duk_heaphdr *) h); count_keep++; prev = h; @@ -51685,8 +52677,8 @@ * should have decreased unreachable string refcounts to zero * (even for cycles). However, pinned strings have a +1 bump. */ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) == - DUK_HSTRING_HAS_PINNED_LITERAL(h) ? 1U : 0U); + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) == DUK_HSTRING_HAS_PINNED_LITERAL(h) ? 1U : + 0U); #endif /* Deal with weak references first. */ @@ -51707,10 +52699,9 @@ } } - done: +done: #if defined(DUK_USE_DEBUG) - DUK_D(DUK_DPRINT("mark-and-sweep sweep stringtable: %ld freed, %ld kept", - (long) count_free, (long) count_keep)); + DUK_D(DUK_DPRINT("mark-and-sweep sweep stringtable: %ld freed, %ld kept", (long) count_free, (long) count_keep)); #endif *out_count_keep = count_keep; } @@ -51720,7 +52711,7 @@ */ DUK_LOCAL void duk__sweep_heap(duk_heap *heap, duk_small_uint_t flags, duk_size_t *out_count_keep) { - duk_heaphdr *prev; /* last element that was left in the heap */ + duk_heaphdr *prev; /* last element that was left in the heap */ duk_heaphdr *curr; duk_heaphdr *next; #if defined(DUK_USE_DEBUG) @@ -51763,25 +52754,28 @@ DUK_DD(DUK_DDPRINT("sweep; reachable, finalizable --> move to finalize_list: %p", (void *) curr)); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_HEAPHDR_PREINC_REFCOUNT(curr); /* Bump refcount so that refzero never occurs when pending a finalizer call. */ + DUK_HEAPHDR_PREINC_REFCOUNT( + curr); /* Bump refcount so that refzero never occurs when pending a finalizer call. */ #endif DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap, curr); #if defined(DUK_USE_DEBUG) count_finalize++; #endif - } - else -#endif /* DUK_USE_FINALIZER_SUPPORT */ + } else +#endif /* DUK_USE_FINALIZER_SUPPORT */ { if (DUK_UNLIKELY(DUK_HEAPHDR_HAS_FINALIZED(curr))) { DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZABLE(curr)); DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); if (flags & DUK_MS_FLAG_POSTPONE_RESCUE) { - DUK_DD(DUK_DDPRINT("sweep; reachable, finalized, but postponing rescue decisions --> keep object (with FINALIZED set): %!iO", curr)); + DUK_DD(DUK_DDPRINT("sweep; reachable, finalized, but postponing rescue decisions " + "--> keep object (with FINALIZED set): %!iO", + curr)); count_keep++; } else { - DUK_DD(DUK_DDPRINT("sweep; reachable, finalized --> rescued after finalization: %p", (void *) curr)); + DUK_DD(DUK_DDPRINT("sweep; reachable, finalized --> rescued after finalization: %p", + (void *) curr)); #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_HEAPHDR_CLEAR_FINALIZED(curr); #endif @@ -51850,7 +52844,8 @@ #if defined(DUK_USE_DEBUG) if (DUK_HEAPHDR_HAS_FINALIZED(curr)) { - DUK_DD(DUK_DDPRINT("sweep; unreachable, finalized --> finalized object not rescued: %p", (void *) curr)); + DUK_DD(DUK_DDPRINT("sweep; unreachable, finalized --> finalized object not rescued: %p", + (void *) curr)); } else { DUK_DD(DUK_DDPRINT("sweep; not reachable --> free: %p", (void *) curr)); } @@ -51884,7 +52879,10 @@ #if defined(DUK_USE_DEBUG) DUK_D(DUK_DPRINT("mark-and-sweep sweep objects (non-string): %ld freed, %ld kept, %ld rescued, %ld queued for finalization", - (long) count_free, (long) count_keep, (long) count_rescue, (long) count_finalize)); + (long) count_free, + (long) count_keep, + (long) count_rescue, + (long) count_finalize)); #endif *out_count_keep = count_keep; } @@ -51907,7 +52905,7 @@ e++; } } -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ /* * Object compaction. @@ -51926,7 +52924,12 @@ } #if defined(DUK_USE_DEBUG) -DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start, duk_size_t *p_count_check, duk_size_t *p_count_compact, duk_size_t *p_count_bytes_saved) { +DUK_LOCAL void duk__compact_object_list(duk_heap *heap, + duk_hthread *thr, + duk_heaphdr *start, + duk_size_t *p_count_check, + duk_size_t *p_count_compact, + duk_size_t *p_count_bytes_saved) { #else DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start) { #endif @@ -51948,9 +52951,8 @@ obj = (duk_hobject *) curr; #if defined(DUK_USE_DEBUG) - old_size = DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)); + old_size = + DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)); #endif DUK_DD(DUK_DDPRINT("compact object: %p", (void *) obj)); @@ -51959,9 +52961,8 @@ duk_safe_call(thr, duk__protected_compact_object, NULL, 1, 0); #if defined(DUK_USE_DEBUG) - new_size = DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)); + new_size = + DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)); #endif #if defined(DUK_USE_DEBUG) @@ -51969,7 +52970,7 @@ (*p_count_bytes_saved) += (duk_size_t) (old_size - new_size); #endif - next: + next: curr = DUK_HEAPHDR_GET_NEXT(heap, curr); #if defined(DUK_USE_DEBUG) (*p_count_check)++; @@ -52001,12 +53002,14 @@ #endif #endif #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif #if defined(DUK_USE_DEBUG) DUK_D(DUK_DPRINT("mark-and-sweep compact objects: %ld checked, %ld compaction attempts, %ld bytes saved by compaction", - (long) count_check, (long) count_compact, (long) count_bytes_saved)); + (long) count_check, + (long) count_compact, + (long) count_bytes_saved)); #endif } @@ -52053,7 +53056,7 @@ DUK_LOCAL void duk__assert_heaphdr_flags(duk_heap *heap) { duk__assert_walk_list(heap, heap->heap_allocated, duk__assert_heaphdr_flags_cb); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif /* XXX: Assertions for finalize_list? */ } @@ -52084,8 +53087,7 @@ /* Cannot really assert much w.r.t. refcounts now. */ DUK_UNREF(heap); - if (DUK_HEAPHDR_GET_REFCOUNT(h) == 0 && - DUK_HEAPHDR_HAS_FINALIZED(h)) { + if (DUK_HEAPHDR_GET_REFCOUNT(h) == 0 && DUK_HEAPHDR_HAS_FINALIZED(h)) { /* An object may be in heap_allocated list with a zero * refcount if it has just been finalized and is waiting * to be collected by the next cycle. @@ -52099,7 +53101,7 @@ * (presumably not reachable because refcount is 0). */ } - DUK_ASSERT_DISABLE(DUK_HEAPHDR_GET_REFCOUNT(h) >= 0); /* Unsigned. */ + DUK_ASSERT_DISABLE(DUK_HEAPHDR_GET_REFCOUNT(h) >= 0); /* Unsigned. */ } DUK_LOCAL void duk__assert_valid_refcounts(duk_heap *heap) { duk__assert_walk_list(heap, heap->heap_allocated, duk__assert_valid_refcounts_cb); @@ -52150,8 +53152,10 @@ count_ok = ((duk_size_t) DUK_HEAPHDR_GET_REFCOUNT(hdr) == expect_refc); if (!count_ok) { DUK_D(DUK_DPRINT("refcount mismatch for: %p: header=%ld counted=%ld --> %!iO", - (void *) hdr, (long) DUK_HEAPHDR_GET_REFCOUNT(hdr), - (long) hdr->h_assert_refcount, hdr)); + (void *) hdr, + (long) DUK_HEAPHDR_GET_REFCOUNT(hdr), + (long) hdr->h_assert_refcount, + hdr)); DUK_ASSERT(0); } } @@ -52172,7 +53176,7 @@ /* XXX: Assert anything for refzero_list? */ duk__assert_walk_strtable(heap, duk__check_assert_refcounts_cb2); } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_LITCACHE_SIZE) DUK_LOCAL void duk__assert_litcache_nulls(duk_heap *heap) { @@ -52188,8 +53192,8 @@ DUK_ASSERT(e->addr == NULL); } } -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_ASSERTIONS */ /* * Stats dump. @@ -52198,49 +53202,64 @@ #if defined(DUK_USE_DEBUG) DUK_LOCAL void duk__dump_stats(duk_heap *heap) { DUK_D(DUK_DPRINT("stats executor: opcodes=%ld, interrupt=%ld, throw=%ld", - (long) heap->stats_exec_opcodes, (long) heap->stats_exec_interrupt, + (long) heap->stats_exec_opcodes, + (long) heap->stats_exec_interrupt, (long) heap->stats_exec_throw)); DUK_D(DUK_DPRINT("stats call: all=%ld, tailcall=%ld, ecmatoecma=%ld", - (long) heap->stats_call_all, (long) heap->stats_call_tailcall, + (long) heap->stats_call_all, + (long) heap->stats_call_tailcall, (long) heap->stats_call_ecmatoecma)); DUK_D(DUK_DPRINT("stats safecall: all=%ld, nothrow=%ld, throw=%ld", - (long) heap->stats_safecall_all, (long) heap->stats_safecall_nothrow, + (long) heap->stats_safecall_all, + (long) heap->stats_safecall_nothrow, (long) heap->stats_safecall_throw)); DUK_D(DUK_DPRINT("stats mark-and-sweep: try_count=%ld, skip_count=%ld, emergency_count=%ld", - (long) heap->stats_ms_try_count, (long) heap->stats_ms_skip_count, + (long) heap->stats_ms_try_count, + (long) heap->stats_ms_skip_count, (long) heap->stats_ms_emergency_count)); DUK_D(DUK_DPRINT("stats stringtable: intern_hit=%ld, intern_miss=%ld, " "resize_check=%ld, resize_grow=%ld, resize_shrink=%ld, " "litcache_hit=%ld, litcache_miss=%ld, litcache_pin=%ld", - (long) heap->stats_strtab_intern_hit, (long) heap->stats_strtab_intern_miss, - (long) heap->stats_strtab_resize_check, (long) heap->stats_strtab_resize_grow, - (long) heap->stats_strtab_resize_shrink, (long) heap->stats_strtab_litcache_hit, - (long) heap->stats_strtab_litcache_miss, (long) heap->stats_strtab_litcache_pin)); + (long) heap->stats_strtab_intern_hit, + (long) heap->stats_strtab_intern_miss, + (long) heap->stats_strtab_resize_check, + (long) heap->stats_strtab_resize_grow, + (long) heap->stats_strtab_resize_shrink, + (long) heap->stats_strtab_litcache_hit, + (long) heap->stats_strtab_litcache_miss, + (long) heap->stats_strtab_litcache_pin)); DUK_D(DUK_DPRINT("stats object: realloc_props=%ld, abandon_array=%ld", - (long) heap->stats_object_realloc_props, (long) heap->stats_object_abandon_array)); + (long) heap->stats_object_realloc_props, + (long) heap->stats_object_abandon_array)); DUK_D(DUK_DPRINT("stats getownpropdesc: count=%ld, hit=%ld, miss=%ld", - (long) heap->stats_getownpropdesc_count, (long) heap->stats_getownpropdesc_hit, + (long) heap->stats_getownpropdesc_count, + (long) heap->stats_getownpropdesc_hit, (long) heap->stats_getownpropdesc_miss)); DUK_D(DUK_DPRINT("stats getpropdesc: count=%ld, hit=%ld, miss=%ld", - (long) heap->stats_getpropdesc_count, (long) heap->stats_getpropdesc_hit, + (long) heap->stats_getpropdesc_count, + (long) heap->stats_getpropdesc_hit, (long) heap->stats_getpropdesc_miss)); DUK_D(DUK_DPRINT("stats getprop: all=%ld, arrayidx=%ld, bufobjidx=%ld, " "bufferidx=%ld, bufferlen=%ld, stringidx=%ld, stringlen=%ld, " "proxy=%ld, arguments=%ld", - (long) heap->stats_getprop_all, (long) heap->stats_getprop_arrayidx, - (long) heap->stats_getprop_bufobjidx, (long) heap->stats_getprop_bufferidx, - (long) heap->stats_getprop_bufferlen, (long) heap->stats_getprop_stringidx, - (long) heap->stats_getprop_stringlen, (long) heap->stats_getprop_proxy, + (long) heap->stats_getprop_all, + (long) heap->stats_getprop_arrayidx, + (long) heap->stats_getprop_bufobjidx, + (long) heap->stats_getprop_bufferidx, + (long) heap->stats_getprop_bufferlen, + (long) heap->stats_getprop_stringidx, + (long) heap->stats_getprop_stringlen, + (long) heap->stats_getprop_proxy, (long) heap->stats_getprop_arguments)); DUK_D(DUK_DPRINT("stats putprop: all=%ld, arrayidx=%ld, bufobjidx=%ld, " "bufferidx=%ld, proxy=%ld", - (long) heap->stats_putprop_all, (long) heap->stats_putprop_arrayidx, - (long) heap->stats_putprop_bufobjidx, (long) heap->stats_putprop_bufferidx, + (long) heap->stats_putprop_all, + (long) heap->stats_putprop_arrayidx, + (long) heap->stats_putprop_bufobjidx, + (long) heap->stats_putprop_bufferidx, (long) heap->stats_putprop_proxy)); - DUK_D(DUK_DPRINT("stats getvar: all=%ld", - (long) heap->stats_getvar_all)); - DUK_D(DUK_DPRINT("stats putvar: all=%ld", - (long) heap->stats_putvar_all)); + DUK_D(DUK_DPRINT("stats getvar: all=%ld", (long) heap->stats_getvar_all)); + DUK_D(DUK_DPRINT("stats putvar: all=%ld", (long) heap->stats_putvar_all)); DUK_D(DUK_DPRINT("stats envrec: delayedcreate=%ld, create=%ld, newenv=%ld, oldenv=%ld, pushclosure=%ld", (long) heap->stats_envrec_delayedcreate, (long) heap->stats_envrec_create, @@ -52248,7 +53267,7 @@ (long) heap->stats_envrec_oldenv, (long) heap->stats_envrec_pushclosure)); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Main mark-and-sweep function. @@ -52287,7 +53306,7 @@ DUK_STATS_INC(heap, stats_ms_skip_count); return; } - DUK_ASSERT(heap->ms_running == 0); /* ms_prevent_count is bumped when ms_running is set */ + DUK_ASSERT(heap->ms_running == 0); /* ms_prevent_count is bumped when ms_running is set */ /* Heap_thread is used during mark-and-sweep for refcount finalization * (it's also used for finalizer execution once mark-and-sweep is @@ -52298,7 +53317,8 @@ DUK_ASSERT(heap->heap_thread->valstack != NULL); DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) starting, requested flags: 0x%08lx, effective flags: 0x%08lx", - (unsigned long) flags, (unsigned long) (flags | heap->ms_base_flags))); + (unsigned long) flags, + (unsigned long) (flags | heap->ms_base_flags))); flags |= heap->ms_base_flags; #if defined(DUK_USE_FINALIZER_SUPPORT) @@ -52324,8 +53344,8 @@ * finalizer may trigger a mark-and-sweep. */ duk__assert_valid_refcounts(heap); -#endif /* DUK_USE_REFERENCE_COUNTING */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_ASSERTIONS */ /* * Begin @@ -52369,17 +53389,17 @@ #if defined(DUK_USE_LITCACHE_SIZE) duk__wipe_litcache(heap); #endif - duk__mark_roots_heap(heap); /* Mark main reachability roots. */ + duk__mark_roots_heap(heap); /* Mark main reachability roots. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif - duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ + duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ #if defined(DUK_USE_FINALIZER_SUPPORT) - duk__mark_finalizable(heap); /* Mark finalizable as reachability roots. */ - duk__mark_finalize_list(heap); /* Mark finalizer work list as reachability roots. */ + duk__mark_finalizable(heap); /* Mark finalizable as reachability roots. */ + duk__mark_finalize_list(heap); /* Mark finalizer work list as reachability roots. */ #endif - duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ + duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ /* * Sweep garbage and remove marking flags, and move objects with @@ -52406,7 +53426,7 @@ duk__check_assert_refcounts(heap); #endif #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) duk__clear_finalize_list_flags(heap); @@ -52433,8 +53453,7 @@ * interfering with error state. */ - if ((flags & DUK_MS_FLAG_EMERGENCY) && - !(flags & DUK_MS_FLAG_NO_OBJECT_COMPACTION)) { + if ((flags & DUK_MS_FLAG_EMERGENCY) && !(flags & DUK_MS_FLAG_NO_OBJECT_COMPACTION)) { if (heap->lj.type != DUK_LJ_TYPE_UNKNOWN) { DUK_D(DUK_DPRINT("lj.type (%ld) not DUK_LJ_TYPE_UNKNOWN, skip object compaction", (long) heap->lj.type)); } else { @@ -52467,7 +53486,7 @@ DUK_ASSERT(heap->ms_running == 1); heap->ms_prevent_count = 0; heap->ms_running = 0; - heap->creating_error = entry_creating_error; /* for nested error handling, see GH-2278 */ + heap->creating_error = entry_creating_error; /* for nested error handling, see GH-2278 */ /* * Assertions after @@ -52484,11 +53503,11 @@ * finalizer may trigger a mark-and-sweep. */ duk__assert_valid_refcounts(heap); -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_LITCACHE_SIZE) duk__assert_litcache_nulls(heap); -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_ASSERTIONS */ /* * Reset trigger counter @@ -52496,14 +53515,15 @@ #if defined(DUK_USE_VOLUNTARY_GC) tmp = (count_keep_obj + count_keep_str) / 256; - heap->ms_trigger_counter = (duk_int_t) ( - (tmp * DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT) + - DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD); + heap->ms_trigger_counter = (duk_int_t) ((tmp * DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT) + DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD); DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) finished: %ld objects kept, %ld strings kept, trigger reset to %ld", - (long) count_keep_obj, (long) count_keep_str, (long) heap->ms_trigger_counter)); + (long) count_keep_obj, + (long) count_keep_str, + (long) heap->ms_trigger_counter)); #else DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) finished: %ld objects kept, %ld strings kept, no voluntary trigger", - (long) count_keep_obj, (long) count_keep_str)); + (long) count_keep_obj, + (long) count_keep_str)); #endif /* @@ -52546,7 +53566,7 @@ * is inside the target. */ duk_heap_process_finalize_list(heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ } /* * Memory allocation handling. @@ -52608,7 +53628,8 @@ res = heap->alloc_func(heap->heap_udata, size); if (res != NULL) { DUK_D(DUK_DPRINT("duk_heap_mem_alloc() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) size)); + (long) (i + 1), + (long) size)); return res; } } @@ -52652,7 +53673,7 @@ return res; } - slowpath: +slowpath: if (size == 0) { DUK_D(DUK_DPRINT("first alloc attempt returned NULL for zero size alloc, use slow path to deal with it")); @@ -52727,13 +53748,7 @@ /* ptr may be NULL */ DUK_ASSERT_DISABLE(newsize >= 0); - /* Newsize was 0 and realloc() returned NULL, this has the semantics - * of free(oldptr), i.e. memory was successfully freed. - */ - if (newsize == 0) { - DUK_D(DUK_DPRINT("zero size realloc in slow path, return NULL")); - return NULL; - } + /* Unlike for malloc(), zero size NULL result check happens at the call site. */ DUK_D(DUK_DPRINT("first realloc attempt failed, attempt to gc and retry")); @@ -52764,11 +53779,11 @@ duk_heap_mark_and_sweep(heap, flags); - DUK_ASSERT(newsize > 0); res = heap->realloc_func(heap->heap_udata, ptr, newsize); - if (res || newsize == 0) { + if (res != NULL || newsize == 0) { DUK_D(DUK_DPRINT("duk_heap_mem_realloc() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) newsize)); + (long) (i + 1), + (long) newsize)); return res; } } @@ -52788,7 +53803,7 @@ #if defined(DUK_USE_VOLUNTARY_GC) /* Voluntary periodic GC (if enabled). */ if (DUK_UNLIKELY(--(heap)->ms_trigger_counter < 0)) { - goto slowpath; + goto gc_retry; } #endif @@ -52800,22 +53815,22 @@ DUK_DDD(DUK_DDDPRINT("gc torture enabled, pretend that first realloc attempt fails")); res = NULL; DUK_UNREF(res); - goto slowpath; + goto gc_retry; } #endif res = heap->realloc_func(heap->heap_udata, ptr, newsize); - if (DUK_LIKELY(res != NULL)) { + if (DUK_LIKELY(res != NULL) || newsize == 0) { + if (res != NULL && newsize == 0) { + DUK_DD(DUK_DDPRINT("first realloc attempt returned NULL for zero size realloc, accept and return NULL")); + } return res; - } - - slowpath: - - if (newsize == 0) { - DUK_D(DUK_DPRINT("first realloc attempt returned NULL for zero size realloc, use slow path to deal with it")); } else { - DUK_D(DUK_DPRINT("first realloc attempt failed, attempt to gc and retry")); + goto gc_retry; } + /* Never here. */ + +gc_retry: return duk__heap_mem_realloc_slowpath(heap, ptr, newsize); } @@ -52826,7 +53841,10 @@ */ /* Slow path: voluntary GC triggered, first realloc attempt failed, or zero size. */ -DUK_LOCAL DUK_NOINLINE_PERF DUK_COLD void *duk__heap_mem_realloc_indirect_slowpath(duk_heap *heap, duk_mem_getptr cb, void *ud, duk_size_t newsize) { +DUK_LOCAL DUK_NOINLINE_PERF DUK_COLD void *duk__heap_mem_realloc_indirect_slowpath(duk_heap *heap, + duk_mem_getptr cb, + void *ud, + duk_size_t newsize) { void *res; duk_small_int_t i; @@ -52834,10 +53852,7 @@ DUK_ASSERT(heap->realloc_func != NULL); DUK_ASSERT_DISABLE(newsize >= 0); - if (newsize == 0) { - DUK_D(DUK_DPRINT("zero size indirect realloc in slow path, return NULL")); - return NULL; - } + /* Unlike for malloc(), zero size NULL result check happens at the call site. */ DUK_D(DUK_DPRINT("first indirect realloc attempt failed, attempt to gc and retry")); @@ -52879,7 +53894,8 @@ ptr_post = cb(heap, ud); if (ptr_pre != ptr_post) { DUK_DD(DUK_DDPRINT("realloc base pointer changed by mark-and-sweep: %p -> %p", - (void *) ptr_pre, (void *) ptr_post)); + (void *) ptr_pre, + (void *) ptr_post)); } #endif @@ -52887,11 +53903,11 @@ * The pointer being reallocated may change after every mark-and-sweep. */ - DUK_ASSERT(newsize > 0); res = heap->realloc_func(heap->heap_udata, cb(heap, ud), newsize); - if (res || newsize == 0) { + if (res != NULL || newsize == 0) { DUK_D(DUK_DPRINT("duk_heap_mem_realloc_indirect() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) newsize)); + (long) (i + 1), + (long) newsize)); return res; } } @@ -52900,7 +53916,10 @@ return NULL; } -DUK_INTERNAL DUK_INLINE_PERF DUK_HOT void *duk_heap_mem_realloc_indirect(duk_heap *heap, duk_mem_getptr cb, void *ud, duk_size_t newsize) { +DUK_INTERNAL DUK_INLINE_PERF DUK_HOT void *duk_heap_mem_realloc_indirect(duk_heap *heap, + duk_mem_getptr cb, + void *ud, + duk_size_t newsize) { void *res; DUK_ASSERT(heap != NULL); @@ -52910,7 +53929,7 @@ #if defined(DUK_USE_VOLUNTARY_GC) /* Voluntary periodic GC (if enabled). */ if (DUK_UNLIKELY(--(heap)->ms_trigger_counter < 0)) { - goto slowpath; + goto gc_retry; } #endif @@ -52922,22 +53941,23 @@ DUK_DDD(DUK_DDDPRINT("gc torture enabled, pretend that first indirect realloc attempt fails")); res = NULL; DUK_UNREF(res); - goto slowpath; + goto gc_retry; } #endif res = heap->realloc_func(heap->heap_udata, cb(heap, ud), newsize); - if (DUK_LIKELY(res != NULL)) { + if (DUK_LIKELY(res != NULL) || newsize == 0) { + if (res != NULL && newsize == 0) { + DUK_DD(DUK_DDPRINT( + "first indirect realloc attempt returned NULL for zero size realloc, accept and return NULL")); + } return res; - } - - slowpath: - - if (newsize == 0) { - DUK_D(DUK_DPRINT("first indirect realloc attempt returned NULL for zero size realloc, use slow path to deal with it")); } else { - DUK_D(DUK_DPRINT("first indirect realloc attempt failed, attempt to gc and retry")); + goto gc_retry; } + /* Never here. */ + +gc_retry: return duk__heap_mem_realloc_indirect_slowpath(heap, cb, ud, newsize); } @@ -53026,7 +54046,7 @@ ; } } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL void duk_heap_insert_into_finalize_list(duk_heap *heap, duk_heaphdr *hdr) { @@ -53045,7 +54065,7 @@ DUK_HEAPHDR_ASSERT_LINKS(heap, root); heap->finalize_list = hdr; } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL void duk_heap_remove_from_finalize_list(duk_heap *heap, duk_heaphdr *hdr) { @@ -53079,7 +54099,7 @@ } else { DUK_ASSERT(hdr != heap->finalize_list); for (;;) { - DUK_ASSERT(curr != NULL); /* Caller responsibility. */ + DUK_ASSERT(curr != NULL); /* Caller responsibility. */ next = DUK_HEAPHDR_GET_NEXT(heap, curr); if (next == hdr) { @@ -53091,7 +54111,7 @@ } #endif } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL duk_bool_t duk_heap_in_heap_allocated(duk_heap *heap, duk_heaphdr *ptr) { @@ -53105,7 +54125,7 @@ } return 0; } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ #if defined(DUK_USE_INTERRUPT_COUNTER) DUK_INTERNAL void duk_heap_switch_thread(duk_heap *heap, duk_hthread *new_thr) { @@ -53138,9 +54158,9 @@ DUK_DD(DUK_DDPRINT("switch thread, new thread is NULL, no interrupt counter changes")); } - heap->curr_thread = new_thr; /* may be NULL */ + heap->curr_thread = new_thr; /* may be NULL */ } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL void duk_heap_assert_valid(duk_heap *heap) { @@ -53309,7 +54329,7 @@ } else if (DUK_HOBJECT_IS_OBJENV(h)) { duk_hobjenv *e = (duk_hobjenv *) h; DUK_HOBJENV_ASSERT_VALID(e); - DUK_ASSERT(e->target != NULL); /* Required for object environments. */ + DUK_ASSERT(e->target != NULL); /* Required for object environments. */ DUK_HOBJECT_DECREF_NORZ(thr, e->target); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) } else if (DUK_HOBJECT_IS_BUFOBJ(h)) { @@ -53317,7 +54337,7 @@ DUK_HBUFOBJ_ASSERT_VALID(b); DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, (duk_hbuffer *) b->buf); DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) b->buf_prop); -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ } else if (DUK_HOBJECT_IS_BOUNDFUNC(h)) { duk_hboundfunc *f = (duk_hboundfunc *) (void *) h; DUK_HBOUNDFUNC_ASSERT_VALID(f); @@ -53330,7 +54350,7 @@ DUK_HPROXY_ASSERT_VALID(p); DUK_HOBJECT_DECREF_NORZ(thr, p->target); DUK_HOBJECT_DECREF_NORZ(thr, p->handler); -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ } else if (DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; duk_activation *act; @@ -53351,13 +54371,12 @@ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) act->prev_caller); #endif -#if 0 /* nothing now */ +#if 0 /* nothing now */ for (cat = act->cat; cat != NULL; cat = cat->parent) { } #endif } - for (i = 0; i < DUK_NUM_BUILTINS; i++) { DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) t->builtinsi); } @@ -53442,7 +54461,7 @@ curr = heap->refzero_list; DUK_ASSERT(curr != NULL); - DUK_ASSERT(DUK_HEAPHDR_GET_PREV(heap, curr) == NULL); /* We're called on initial insert only. */ + DUK_ASSERT(DUK_HEAPHDR_GET_PREV(heap, curr) == NULL); /* We're called on initial insert only. */ /* curr->next is GARBAGE. */ do { @@ -53455,7 +54474,7 @@ #endif DUK_ASSERT(curr != NULL); - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ /* FINALIZED may be set; don't care about flags here. */ /* Refcount finalize 'curr'. Refzero_list must be non-NULL @@ -53465,11 +54484,10 @@ duk_hobject_refcount_finalize_norz(heap, (duk_hobject *) curr); prev = DUK_HEAPHDR_GET_PREV(heap, curr); - DUK_ASSERT((prev == NULL && heap->refzero_list == curr) || \ - (prev != NULL && heap->refzero_list != curr)); + DUK_ASSERT((prev == NULL && heap->refzero_list == curr) || (prev != NULL && heap->refzero_list != curr)); /* prev->next is intentionally not updated and is garbage. */ - duk_free_hobject(heap, (duk_hobject *) curr); /* Invalidates 'curr'. */ + duk_free_hobject(heap, (duk_hobject *) curr); /* Invalidates 'curr'. */ curr = prev; } while (curr != NULL); @@ -53545,7 +54563,7 @@ return; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* No need to finalize, free object via refzero_list. */ @@ -53589,7 +54607,7 @@ DUK_INTERNAL DUK_ALWAYS_INLINE void duk_refzero_check_fast(duk_hthread *thr) { DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ + DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ if (DUK_UNLIKELY(thr->heap->finalize_list != NULL)) { duk_heap_process_finalize_list(thr->heap); @@ -53599,13 +54617,13 @@ DUK_INTERNAL void duk_refzero_check_slow(duk_hthread *thr) { DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ + DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ if (DUK_UNLIKELY(thr->heap->finalize_list != NULL)) { duk_heap_process_finalize_list(thr->heap); } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Refzero processing for duk_hstring. @@ -53665,7 +54683,8 @@ * The suppress condition is important to performance. */ -#define DUK__RZ_SUPPRESS_ASSERT1() do { \ +#define DUK__RZ_SUPPRESS_ASSERT1() \ + do { \ DUK_ASSERT(thr != NULL); \ DUK_ASSERT(thr->heap != NULL); \ /* When mark-and-sweep runs, heap_thread must exist. */ \ @@ -53687,32 +54706,41 @@ } while (0) #if defined(DUK_USE_DEBUGGER_SUPPORT) -#define DUK__RZ_SUPPRESS_ASSERT2() do { \ +#define DUK__RZ_SUPPRESS_ASSERT2() \ + do { \ /* When debugger is paused, ms_running is set. */ \ DUK_ASSERT(!DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || thr->heap->ms_running != 0); \ } while (0) -#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) +#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) #else -#define DUK__RZ_SUPPRESS_ASSERT2() do { } while (0) -#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#define DUK__RZ_SUPPRESS_ASSERT2() \ + do { \ + } while (0) +#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) +#endif /* DUK_USE_DEBUGGER_SUPPORT */ -#define DUK__RZ_SUPPRESS_CHECK() do { \ +#define DUK__RZ_SUPPRESS_CHECK() \ + do { \ DUK__RZ_SUPPRESS_ASSERT1(); \ DUK__RZ_SUPPRESS_ASSERT2(); \ if (DUK_UNLIKELY(DUK__RZ_SUPPRESS_COND())) { \ - DUK_DDD(DUK_DDDPRINT("refzero handling suppressed (not even queued) when mark-and-sweep running, object: %p", (void *) h)); \ + DUK_DDD( \ + DUK_DDDPRINT("refzero handling suppressed (not even queued) when mark-and-sweep running, object: %p", \ + (void *) h)); \ return; \ } \ } while (0) -#define DUK__RZ_STRING() do { \ +#define DUK__RZ_STRING() \ + do { \ duk__refcount_refzero_hstring(heap, (duk_hstring *) h); \ } while (0) -#define DUK__RZ_BUFFER() do { \ +#define DUK__RZ_BUFFER() \ + do { \ duk__refcount_refzero_hbuffer(heap, (duk_hbuffer *) h); \ } while (0) -#define DUK__RZ_OBJECT() do { \ +#define DUK__RZ_OBJECT() \ + do { \ duk__refcount_refzero_hobject(heap, (duk_hobject *) h, skip_free_pending); \ } while (0) @@ -53833,7 +54861,7 @@ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(h)); DUK_ASSERT_DISABLE(h->h_refcount >= 0); DUK_HEAPHDR_PREINC_REFCOUNT(h); - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(h) != 0); /* No wrapping. */ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(h) != 0); /* No wrapping. */ } } @@ -53876,9 +54904,10 @@ #endif } } -#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ +#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ -#define DUK__DECREF_ASSERTS() do { \ +#define DUK__DECREF_ASSERTS() \ + do { \ DUK_ASSERT(thr != NULL); \ DUK_ASSERT(thr->heap != NULL); \ DUK_ASSERT(h != NULL); \ @@ -53886,14 +54915,16 @@ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) >= 1); \ } while (0) #if defined(DUK_USE_ROM_OBJECTS) -#define DUK__INCREF_SHARED() do { \ +#define DUK__INCREF_SHARED() \ + do { \ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) h)) { \ return; \ } \ DUK_HEAPHDR_PREINC_REFCOUNT((duk_heaphdr *) h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ } while (0) -#define DUK__DECREF_SHARED() do { \ +#define DUK__DECREF_SHARED() \ + do { \ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) h)) { \ return; \ } \ @@ -53902,11 +54933,13 @@ } \ } while (0) #else -#define DUK__INCREF_SHARED() do { \ +#define DUK__INCREF_SHARED() \ + do { \ DUK_HEAPHDR_PREINC_REFCOUNT((duk_heaphdr *) h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ } while (0) -#define DUK__DECREF_SHARED() do { \ +#define DUK__DECREF_SHARED() \ + do { \ if (DUK_HEAPHDR_PREDEC_REFCOUNT((duk_heaphdr *) h) != 0) { \ return; \ } \ @@ -53940,9 +54973,9 @@ DUK__DECREF_SHARED(); duk_heaphdr_refzero_norz(thr, h); } -#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ +#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ -#if 0 /* Not needed. */ +#if 0 /* Not needed. */ DUK_INTERNAL void duk_hstring_decref(duk_hthread *thr, duk_hstring *h) { DUK__DECREF_ASSERTS(); DUK__DECREF_SHARED(); @@ -53975,11 +55008,11 @@ } #endif -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ /* no refcounting */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* automatic undefs */ #undef DUK__DECREF_ASSERTS @@ -54017,8 +55050,8 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; if (c->h == h) { - DUK_DD(DUK_DDPRINT("deleting weak strcache reference to hstring %p from heap %p", - (void *) h, (void *) heap)); + DUK_DD( + DUK_DDPRINT("deleting weak strcache reference to hstring %p from heap %p", (void *) h, (void *) heap)); c->h = NULL; /* XXX: the string shouldn't appear twice, but we now loop to the @@ -54128,7 +55161,8 @@ */ DUK_DDD(DUK_DDDPRINT("non-ascii string %p, char_offset=%ld, clen=%ld, blen=%ld", - (void *) h, (long) char_offset, + (void *) h, + (long) char_offset, (long) DUK_HSTRING_GET_CHARLEN(h), (long) DUK_HSTRING_GET_BYTELEN(h))); @@ -54142,7 +55176,10 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; DUK_DDD(DUK_DDDPRINT(" %ld -> h=%p, cidx=%ld, bidx=%ld", - (long) i, (void *) c->h, (long) c->cidx, (long) c->bidx)); + (long) i, + (void *) c->h, + (long) c->cidx, + (long) c->bidx)); } #endif @@ -54166,7 +55203,8 @@ DUK_ASSERT(DUK_HSTRING_GET_CHARLEN(h) >= char_offset); dist_start = char_offset; dist_end = char_length - char_offset; - dist_sce = 0; DUK_UNREF(dist_sce); /* initialize for debug prints, needed if sce==NULL */ + dist_sce = 0; + DUK_UNREF(dist_sce); /* initialize for debug prints, needed if sce==NULL */ p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h); p_end = (const duk_uint8_t *) (p_start + DUK_HSTRING_GET_BYTELEN(h)); @@ -54179,14 +55217,15 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan forwards from sce", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_forwards(p_start + sce->bidx, - p_end, - dist_sce); + p_found = duk__scan_forwards(p_start + sce->bidx, p_end, dist_sce); goto scan_done; } } else { @@ -54195,14 +55234,15 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan backwards from sce", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_backwards(p_start + sce->bidx, - p_start, - dist_sce); + p_found = duk__scan_backwards(p_start + sce->bidx, p_start, dist_sce); goto scan_done; } } @@ -54214,29 +55254,31 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan forwards from string start", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_forwards(p_start, - p_end, - dist_start); + p_found = duk__scan_forwards(p_start, p_end, dist_start); } else { DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan backwards from string end", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_backwards(p_end, - p_start, - dist_end); + p_found = duk__scan_backwards(p_end, p_start, dist_end); } - scan_done: +scan_done: if (DUK_UNLIKELY(p_found == NULL)) { /* Scan error: this shouldn't normally happen; it could happen if @@ -54247,11 +55289,10 @@ } DUK_ASSERT(p_found >= p_start); - DUK_ASSERT(p_found <= p_end); /* may be equal */ + DUK_ASSERT(p_found <= p_end); /* may be equal */ byte_offset = (duk_uint32_t) (p_found - p_start); - DUK_DDD(DUK_DDDPRINT("-> string %p, cidx %ld -> bidx %ld", - (void *) h, (long) char_offset, (long) byte_offset)); + DUK_DDD(DUK_DDDPRINT("-> string %p, cidx %ld -> bidx %ld", (void *) h, (long) char_offset, (long) byte_offset)); /* * Update cache entry (allocating if necessary), and move the @@ -54261,7 +55302,7 @@ if (use_cache) { /* update entry, allocating if necessary */ if (!sce) { - sce = heap->strcache + DUK_HEAP_STRCACHE_SIZE - 1; /* take last entry */ + sce = heap->strcache + DUK_HEAP_STRCACHE_SIZE - 1; /* take last entry */ sce->h = h; } DUK_ASSERT(sce != NULL); @@ -54291,14 +55332,17 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; DUK_DDD(DUK_DDDPRINT(" %ld -> h=%p, cidx=%ld, bidx=%ld", - (long) i, (void *) c->h, (long) c->cidx, (long) c->bidx)); + (long) i, + (void *) c->h, + (long) c->cidx, + (long) c->bidx)); } #endif } return byte_offset; - scan_error: +scan_error: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); } @@ -54317,16 +55361,16 @@ #endif #if defined(DUK_USE_STRTAB_PTRCOMP) -#define DUK__HEAPPTR_ENC16(heap,ptr) DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (ptr)) -#define DUK__HEAPPTR_DEC16(heap,val) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (val)) -#define DUK__GET_STRTABLE(heap) ((heap)->strtable16) +#define DUK__HEAPPTR_ENC16(heap, ptr) DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (ptr)) +#define DUK__HEAPPTR_DEC16(heap, val) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (val)) +#define DUK__GET_STRTABLE(heap) ((heap)->strtable16) #else -#define DUK__HEAPPTR_ENC16(heap,ptr) (ptr) -#define DUK__HEAPPTR_DEC16(heap,val) (val) -#define DUK__GET_STRTABLE(heap) ((heap)->strtable) +#define DUK__HEAPPTR_ENC16(heap, ptr) (ptr) +#define DUK__HEAPPTR_DEC16(heap, val) (val) +#define DUK__GET_STRTABLE(heap) ((heap)->strtable) #endif -#define DUK__STRTAB_U32_MAX_STRLEN 10 /* 4'294'967'295 */ +#define DUK__STRTAB_U32_MAX_STRLEN 10 /* 4'294'967'295 */ /* * Debug dump stringtable. @@ -54345,7 +55389,7 @@ duk_size_t count_chain; duk_size_t count_chain_min = DUK_SIZE_MAX; duk_size_t count_chain_max = 0; - duk_size_t count_len8; /* chain lengths from 0 to 7 */ + duk_size_t count_len8; /* chain lengths from 0 to 7 */ if (heap == NULL) { DUK_D(DUK_DPRINT("string table, heap=NULL")); @@ -54376,15 +55420,21 @@ DUK_D(DUK_DPRINT("string table, strtab=%p, count=%lu, chain min=%lu max=%lu avg=%lf: " "counts: %lu %lu %lu %lu %lu %lu %lu %lu ...", - (void *) heap->strtable, (unsigned long) count_total, - (unsigned long) count_chain_min, (unsigned long) count_chain_max, + (void *) heap->strtable, + (unsigned long) count_total, + (unsigned long) count_chain_min, + (unsigned long) count_chain_max, (double) count_total / (double) heap->st_size, - (unsigned long) count_len0, (unsigned long) count_len1, - (unsigned long) count_len2, (unsigned long) count_len3, - (unsigned long) count_len4, (unsigned long) count_len5, - (unsigned long) count_len6, (unsigned long) count_len7)); + (unsigned long) count_len0, + (unsigned long) count_len1, + (unsigned long) count_len2, + (unsigned long) count_len3, + (unsigned long) count_len4, + (unsigned long) count_len5, + (unsigned long) count_len6, + (unsigned long) count_len7)); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Assertion helper to ensure strtable is populated correctly. @@ -54425,7 +55475,7 @@ DUK_ASSERT(count == (duk_size_t) heap->st_count); #endif } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Allocate and initialize a duk_hstring. @@ -54476,16 +55526,16 @@ #endif DUK_HEAPHDR_SET_TYPE_AND_FLAGS(&res->hdr, DUK_HTYPE_STRING, DUK_HSTRING_FLAG_EXTDATA); - DUK_ASSERT(extdatablen == 0); /* Application responsibility. */ + DUK_ASSERT(extdatablen == 0); /* Application responsibility. */ data = extdata; ((duk_hstring_external *) res)->extdata = extdata; } else -#endif /* DUK_USE_HSTRING_EXTDATA && DUK_USE_EXTSTR_INTERN_CHECK */ +#endif /* DUK_USE_HSTRING_EXTDATA && DUK_USE_EXTSTR_INTERN_CHECK */ { duk_uint8_t *data_tmp; /* NUL terminate for convenient C access */ - DUK_ASSERT(sizeof(duk_hstring) + blen + 1 > blen); /* No wrap, limits ensure. */ + DUK_ASSERT(sizeof(duk_hstring) + blen + 1 > blen); /* No wrap, limits ensure. */ res = (duk_hstring *) DUK_ALLOC(heap, sizeof(duk_hstring) + blen + 1); if (DUK_UNLIKELY(res == NULL)) { goto alloc_error; @@ -54544,7 +55594,7 @@ #if defined(DUK_USE_HSTRING_LAZY_CLEN) /* Charlen initialized to 0, updated on-the-fly. */ #else - duk_hstring_init_charlen(res); /* Also sets ASCII flag. */ + duk_hstring_init_charlen(res); /* Also sets ASCII flag. */ #endif } @@ -54557,7 +55607,7 @@ DUK_ASSERT(res != NULL); return res; - alloc_error: +alloc_error: return NULL; } @@ -54586,13 +55636,13 @@ DUK_ASSERT(heap != NULL); DUK_ASSERT(heap->st_resizing == 1); DUK_ASSERT(heap->st_size >= 2); - DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ + DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ DUK_ASSERT(DUK__GET_STRTABLE(heap) != NULL); DUK_STATS_INC(heap, stats_strtab_resize_grow); new_st_size = heap->st_size << 1U; - DUK_ASSERT(new_st_size > heap->st_size); /* No overflow. */ + DUK_ASSERT(new_st_size > heap->st_size); /* No overflow. */ /* Reallocate the strtable first and then work in-place to rehash * strings. We don't need an indirect allocation here: even if GC @@ -54676,7 +55726,7 @@ duk__strtable_assert_checks(heap); #endif } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Shrink strtable allocation in-place. @@ -54704,7 +55754,7 @@ DUK_ASSERT(heap != NULL); DUK_ASSERT(heap->st_resizing == 1); DUK_ASSERT(heap->st_size >= 2); - DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ + DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ DUK_ASSERT(DUK__GET_STRTABLE(heap) != NULL); DUK_STATS_INC(heap, stats_strtab_resize_shrink); @@ -54762,7 +55812,7 @@ duk__strtable_assert_checks(heap); #endif } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Grow/shrink check. @@ -54770,7 +55820,7 @@ #if defined(DUK__STRTAB_RESIZE_CHECK) DUK_LOCAL DUK_COLD DUK_NOINLINE void duk__strtable_resize_check(duk_heap *heap) { - duk_uint32_t load_factor; /* fixed point */ + duk_uint32_t load_factor; /* fixed point */ DUK_ASSERT(heap != NULL); #if defined(DUK_USE_STRTAB_PTRCOMP) @@ -54794,7 +55844,8 @@ load_factor = heap->st_count / (heap->st_size >> 4U); DUK_DD(DUK_DDPRINT("resize check string table: size=%lu, count=%lu, load_factor=%lu (fixed point .4; float %lf)", - (unsigned long) heap->st_size, (unsigned long) heap->st_count, + (unsigned long) heap->st_size, + (unsigned long) heap->st_count, (unsigned long) load_factor, (double) heap->st_count / (double) heap->st_size)); @@ -54802,7 +55853,9 @@ if (heap->st_size >= DUK_USE_STRTAB_MAXSIZE) { DUK_DD(DUK_DDPRINT("want to grow strtable (based on load factor) but already maximum size")); } else { - DUK_D(DUK_DPRINT("grow string table: %lu -> %lu", (unsigned long) heap->st_size, (unsigned long) heap->st_size * 2)); + DUK_D(DUK_DPRINT("grow string table: %lu -> %lu", + (unsigned long) heap->st_size, + (unsigned long) heap->st_size * 2)); #if defined(DUK_USE_DEBUG) duk_heap_strtable_dump(heap); #endif @@ -54812,7 +55865,9 @@ if (heap->st_size <= DUK_USE_STRTAB_MINSIZE) { DUK_DD(DUK_DDPRINT("want to shrink strtable (based on load factor) but already minimum size")); } else { - DUK_D(DUK_DPRINT("shrink string table: %lu -> %lu", (unsigned long) heap->st_size, (unsigned long) heap->st_size / 2)); + DUK_D(DUK_DPRINT("shrink string table: %lu -> %lu", + (unsigned long) heap->st_size, + (unsigned long) heap->st_size / 2)); #if defined(DUK_USE_DEBUG) duk_heap_strtable_dump(heap); #endif @@ -54824,7 +55879,7 @@ heap->st_resizing = 0; } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Torture grow/shrink: unconditionally grow and shrink back. @@ -54848,7 +55903,7 @@ } heap->st_resizing = 0; } -#endif /* DUK_USE_STRTAB_TORTURE && DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK_USE_STRTAB_TORTURE && DUK__STRTAB_RESIZE_CHECK */ /* * Raw intern; string already checked not to be present. @@ -54864,8 +55919,12 @@ #endif DUK_DDD(DUK_DDDPRINT("do_intern: heap=%p, str=%p, blen=%lu, strhash=%lx, st_size=%lu, st_count=%lu, load=%lf", - (void *) heap, (const void *) str, (unsigned long) blen, (unsigned long) strhash, - (unsigned long) heap->st_size, (unsigned long) heap->st_count, + (void *) heap, + (const void *) str, + (unsigned long) blen, + (unsigned long) strhash, + (unsigned long) heap->st_size, + (unsigned long) heap->st_count, (double) heap->st_count / (double) heap->st_size)); DUK_ASSERT(heap != NULL); @@ -54881,7 +55940,7 @@ */ heap->pf_prevent_count++; - DUK_ASSERT(heap->pf_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(heap->pf_prevent_count != 0); /* Wrap. */ #if defined(DUK_USE_STRTAB_TORTURE) && defined(DUK__STRTAB_RESIZE_CHECK) duk__strtable_resize_torture(heap); @@ -54908,7 +55967,8 @@ /* External string check (low memory optimization). */ #if defined(DUK_USE_HSTRING_EXTDATA) && defined(DUK_USE_EXTSTR_INTERN_CHECK) - extdata = (const duk_uint8_t *) DUK_USE_EXTSTR_INTERN_CHECK(heap->heap_udata, (void *) DUK_LOSE_CONST(str), (duk_size_t) blen); + extdata = + (const duk_uint8_t *) DUK_USE_EXTSTR_INTERN_CHECK(heap->heap_udata, (void *) DUK_LOSE_CONST(str), (duk_size_t) blen); #else extdata = (const duk_uint8_t *) NULL; #endif @@ -54946,7 +56006,7 @@ #else slot = heap->strtable + (strhash & heap->st_mask); #endif - DUK_ASSERT(res->hdr.h_next == NULL); /* This is the case now, but unnecessary zeroing/NULLing. */ + DUK_ASSERT(res->hdr.h_next == NULL); /* This is the case now, but unnecessary zeroing/NULLing. */ res->hdr.h_next = DUK__HEAPPTR_DEC16(heap, *slot); *slot = DUK__HEAPPTR_ENC16(heap, res); @@ -54993,11 +56053,12 @@ curr = (duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_lookuplookup_hash); while (curr != NULL) { /* Unsafe memcmp() because for zero blen, str may be NULL. */ - if (strhash == DUK_HSTRING_GET_HASH(curr) && - blen == DUK_HSTRING_GET_BYTELEN(curr) && + if (strhash == DUK_HSTRING_GET_HASH(curr) && blen == DUK_HSTRING_GET_BYTELEN(curr) && duk_memcmp_unsafe((const void *) str, (const void *) DUK_HSTRING_GET_DATA(curr), blen) == 0) { DUK_DDD(DUK_DDDPRINT("intern check: rom string: %!O, computed hash 0x%08lx, rom hash 0x%08lx", - curr, (unsigned long) strhash, (unsigned long) DUK_HSTRING_GET_HASH(curr))); + curr, + (unsigned long) strhash, + (unsigned long) DUK_HSTRING_GET_HASH(curr))); return curr; } curr = curr->hdr.h_next; @@ -55005,7 +56066,7 @@ return NULL; } -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ DUK_INTERNAL duk_hstring *duk_heap_strtable_intern(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen) { duk_uint32_t strhash; @@ -55018,7 +56079,7 @@ /* XXX: maybe just require 'str != NULL' even for zero size? */ DUK_ASSERT(heap != NULL); DUK_ASSERT(blen == 0 || str != NULL); - DUK_ASSERT(blen <= DUK_HSTRING_MAX_BYTELEN); /* Caller is responsible for ensuring this. */ + DUK_ASSERT(blen <= DUK_HSTRING_MAX_BYTELEN); /* Caller is responsible for ensuring this. */ strhash = duk_heap_hashstring(heap, str, (duk_size_t) blen); /* String table lookup. */ @@ -55032,8 +56093,7 @@ h = heap->strtablestrhash & heap->st_mask; #endif while (h != NULL) { - if (DUK_HSTRING_GET_HASH(h) == strhash && - DUK_HSTRING_GET_BYTELEN(h) == blen && + if (DUK_HSTRING_GET_HASH(h) == strhash && DUK_HSTRING_GET_BYTELEN(h) == blen && duk_memcmp_unsafe((const void *) str, (const void *) DUK_HSTRING_GET_DATA(h), (size_t) blen) == 0) { /* Found existing entry. */ DUK_STATS_INC(heap, stats_strtab_intern_hit); @@ -55059,7 +56119,7 @@ DUK_STATS_INC(heap, stats_strtab_intern_miss); h = duk__strtable_do_intern(heap, str, blen, strhash); - return h; /* may be NULL */ + return h; /* may be NULL */ } /* @@ -55082,7 +56142,7 @@ p--; *p = duk_lc_digitsval % 10; val = val / 10; - } while (val != 0); /* For val == 0, emit exactly one '0'. */ + } while (val != 0); /* For val == 0, emit exactly one '0'. */ DUK_ASSERT(p >= buf); return duk_heap_strtable_intern(heap, (const duk_uint8_t *) p, (duk_uint32_t) ((buf + sizeof(buf)) - p)); @@ -55120,7 +56180,7 @@ DUK_ASSERT(DUK_IS_POWER_OF_TWO((duk_uint_t) DUK_USE_LITCACHE_SIZE)); key = (duk_uintptr_t) blen ^ (duk_uintptr_t) str; - key &= (duk_uintptr_t) (DUK_USE_LITCACHE_SIZE - 1); /* Assumes size is power of 2. */ + key &= (duk_uintptr_t) (DUK_USE_LITCACHE_SIZE - 1); /* Assumes size is power of 2. */ /* Due to masking, cast is in 32-bit range. */ DUK_ASSERT(key <= DUK_UINT_MAX); return (duk_uint_t) key; @@ -55136,7 +56196,9 @@ ent = thr->heap->litcache + key; if (ent->addr == str) { DUK_DD(DUK_DDPRINT("intern check for cached, pinned literal: str=%p, blen=%ld -> duk_hstring %!O", - (const void *) str, (long) blen, (duk_heaphdr *) ent->h)); + (const void *) str, + (long) blen, + (duk_heaphdr *) ent->h)); DUK_ASSERT(ent->h != NULL); DUK_ASSERT(DUK_HSTRING_HAS_PINNED_LITERAL(ent->h)); DUK_STATS_INC(thr->heap, stats_strtab_litcache_hit); @@ -55166,7 +56228,7 @@ return h; } -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ DUK_INTERNAL duk_hstring *duk_heap_strtable_intern_u32_checked(duk_hthread *thr, duk_uint32_t val) { duk_hstring *res; @@ -55201,7 +56263,8 @@ duk_hstring *prev; DUK_DDD(DUK_DDDPRINT("remove: heap=%p, h=%p, blen=%lu, strhash=%lx", - (void *) heap, (void *) h, + (void *) heap, + (void *) h, (unsigned long) (h != NULL ? DUK_HSTRING_GET_BYTELEN(h) : 0), (unsigned long) (h != NULL ? DUK_HSTRING_GET_HASH(h) : 0))); @@ -55219,13 +56282,13 @@ slot = heap->strtable + (DUK_HSTRING_GET_HASH(h) & heap->st_mask); #endif other = DUK__HEAPPTR_DEC16(heap, *slot); - DUK_ASSERT(other != NULL); /* At least argument string is in the chain. */ + DUK_ASSERT(other != NULL); /* At least argument string is in the chain. */ prev = NULL; while (other != h) { prev = other; other = other->hdr.h_next; - DUK_ASSERT(other != NULL); /* We'll eventually find 'h'. */ + DUK_ASSERT(other != NULL); /* We'll eventually find 'h'. */ } if (prev != NULL) { /* Middle of list. */ @@ -55239,7 +56302,7 @@ * intern will do one. */ } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* Unlink with a 'prev' pointer. */ DUK_INTERNAL void duk_heap_strtable_unlink_prev(duk_heap *heap, duk_hstring *h, duk_hstring *prev) { @@ -55250,7 +56313,9 @@ #endif DUK_DDD(DUK_DDDPRINT("remove: heap=%p, prev=%p, h=%p, blen=%lu, strhash=%lx", - (void *) heap, (void *) prev, (void *) h, + (void *) heap, + (void *) prev, + (void *) h, (unsigned long) (h != NULL ? DUK_HSTRING_GET_BYTELEN(h) : 0), (unsigned long) (h != NULL ? DUK_HSTRING_GET_HASH(h) : 0))); @@ -55428,7 +56493,7 @@ } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Hobject allocation. * @@ -55452,7 +56517,7 @@ /* Zeroed by caller. */ obj->hdr.h_flags = hobject_flags | DUK_HTYPE_OBJECT; - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(&obj->hdr) == DUK_HTYPE_OBJECT); /* Assume zero shift. */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(&obj->hdr) == DUK_HTYPE_OBJECT); /* Assume zero shift. */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) DUK_HOBJECT_SET_PROTOTYPE(heap, obj, NULL); @@ -55588,7 +56653,7 @@ DUK_HBUFOBJ_ASSERT_VALID(res); return res; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Allocate a new thread. * @@ -55710,20 +56775,18 @@ DUK_INTERNAL void duk_hobject_assert_valid(duk_hobject *h) { DUK_ASSERT(h != NULL); - DUK_ASSERT(!DUK_HOBJECT_IS_CALLABLE(h) || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FUNCTION); - DUK_ASSERT(!DUK_HOBJECT_IS_BUFOBJ(h) || - (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAYBUFFER || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_DATAVIEW || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT8ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT16ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT16ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT64ARRAY)); + DUK_ASSERT(!DUK_HOBJECT_IS_CALLABLE(h) || DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FUNCTION); + DUK_ASSERT(!DUK_HOBJECT_IS_BUFOBJ(h) || (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAYBUFFER || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_DATAVIEW || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT8ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT16ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT16ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT64ARRAY)); /* Object is an Array <=> object has exotic array behavior */ DUK_ASSERT((DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAY && DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)) || (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_ARRAY && !DUK_HOBJECT_HAS_EXOTIC_ARRAY(h))); @@ -55739,8 +56802,7 @@ DUK_ASSERT(h != NULL); DUK_ASSERT(DUK_HOBJECT_IS_BOUNDFUNC((duk_hobject *) h)); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(&h->target) || - (DUK_TVAL_IS_OBJECT(&h->target) && - DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(&h->target)))); + (DUK_TVAL_IS_OBJECT(&h->target) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(&h->target)))); DUK_ASSERT(!DUK_TVAL_IS_UNUSED(&h->this_binding)); DUK_ASSERT(h->nargs == 0 || h->args != NULL); } @@ -55772,7 +56834,7 @@ DUK_ASSERT(h->offset + h->length >= h->offset); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_INTERNAL void duk_hcompfunc_assert_valid(duk_hcompfunc *h) { DUK_ASSERT(h != NULL); @@ -55826,7 +56888,7 @@ DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Object enumeration support. * @@ -55853,7 +56915,7 @@ /* First enumerated key index in enumerator object, must match exactly the * number of control properties inserted to the enumerator. */ -#define DUK__ENUM_START_INDEX 2 +#define DUK__ENUM_START_INDEX 2 /* Current implementation suffices for ES2015 for now because there's no symbol * sorting, so commented out for now. @@ -55922,7 +56984,7 @@ DUK_ASSERT(a != NULL); DUK_ASSERT(b != NULL); - DUK_UNREF(b); /* Not actually needed now, val_b suffices. */ + DUK_UNREF(b); /* Not actually needed now, val_b suffices. */ val_a = duk__hstring_sort_key(a); @@ -55943,7 +57005,7 @@ DUK_UNREF(thr); if (idx_end <= idx_start + 1) { - return; /* Zero or one element(s). */ + return; /* Zero or one element(s). */ } keys = DUK_HOBJECT_E_GET_KEY_BASE(thr->heap, h_obj); @@ -55961,7 +57023,7 @@ * (and optimized for) case. */ - val_curr = duk__hstring_sort_key(h_curr); /* Remains same during scanning. */ + val_curr = duk__hstring_sort_key(h_curr); /* Remains same during scanning. */ for (idx_insert = idx - 1; idx_insert >= idx_start; idx_insert--) { duk_hstring *h_insert; h_insert = keysidx_insert; @@ -56034,7 +57096,7 @@ duk_hobject *h_proxy_handler; duk_hobject *h_trap_result; #endif - duk_uint_fast32_t i, len; /* used for array, stack, and entry indices */ + duk_uint_fast32_t i, len; /* used for array, stack, and entry indices */ duk_uint_fast32_t sort_start_index; DUK_ASSERT(thr != NULL); @@ -56053,11 +57115,11 @@ * real object to check against. */ duk_push_hobject(thr, enum_target); - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ /* Initialize index so that we skip internal control keys. */ duk_push_int(thr, DUK__ENUM_START_INDEX); - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_NEXT); /* Target is bare, plain put OK. */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_NEXT); /* Target is bare, plain put OK. */ /* * Proxy object handling @@ -56067,9 +57129,7 @@ if (DUK_LIKELY((enum_flags & DUK_ENUM_NO_PROXY_BEHAVIOR) != 0)) { goto skip_proxy; } - if (DUK_LIKELY(!duk_hobject_proxy_check(enum_target, - &h_proxy_target, - &h_proxy_handler))) { + if (DUK_LIKELY(!duk_hobject_proxy_check(enum_target, &h_proxy_target, &h_proxy_handler))) { goto skip_proxy; } @@ -56090,17 +57150,17 @@ DUK_DDD(DUK_DDDPRINT("h_proxy_target=%!O", (duk_heaphdr *) h_proxy_target)); enum_target = h_proxy_target; - duk_push_hobject(thr, enum_target); /* -> ... enum_target res handler undefined target */ - duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ + duk_push_hobject(thr, enum_target); /* -> ... enum_target res handler undefined target */ + duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ - duk_pop_2(thr); /* -> ... enum_target res */ + duk_pop_2(thr); /* -> ... enum_target res */ goto skip_proxy; } /* ... enum_target res handler trap */ duk_insert(thr, -2); - duk_push_hobject(thr, h_proxy_target); /* -> ... enum_target res trap handler target */ - duk_call_method(thr, 1 /*nargs*/); /* -> ... enum_target res trap_result */ + duk_push_hobject(thr, h_proxy_target); /* -> ... enum_target res trap handler target */ + duk_call_method(thr, 1 /*nargs*/); /* -> ... enum_target res trap_result */ h_trap_result = duk_require_hobject(thr, -1); DUK_UNREF(h_trap_result); @@ -56113,7 +57173,7 @@ len = (duk_uint_fast32_t) duk_get_length(thr, -1); for (i = 0; i < len; i++) { (void) duk_get_prop_index(thr, -1, (duk_uarridx_t) i); - DUK_ASSERT(duk_is_string(thr, -1)); /* postprocess cleaned up */ + DUK_ASSERT(duk_is_string(thr, -1)); /* postprocess cleaned up */ /* ... enum_target res trap_result keys_array val */ duk_push_true(thr); /* ... enum_target res trap_result keys_array val true */ @@ -56134,8 +57194,8 @@ DUK_DDD(DUK_DDDPRINT("proxy enumeration, final res: %!O", (duk_heaphdr *) res)); goto compact_and_return; - skip_proxy: -#endif /* DUK_USE_ES6_PROXY */ +skip_proxy: +#endif /* DUK_USE_ES6_PROXY */ curr = enum_target; sort_start_index = DUK__ENUM_START_INDEX; @@ -56186,7 +57246,7 @@ if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(curr)) { duk_hstring *h_val; h_val = duk_hobject_get_internal_value_string(thr->heap, curr); - DUK_ASSERT(h_val != NULL); /* string objects must not created without internal value */ + DUK_ASSERT(h_val != NULL); /* string objects must not created without internal value */ len = (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_val); } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -56209,7 +57269,7 @@ len = (duk_uint_fast32_t) (h_bufobj->length >> h_bufobj->shift); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ for (i = 0; i < len; i++) { duk_hstring *k; @@ -56249,7 +57309,7 @@ if (DUK_TVAL_IS_UNUSED(tv)) { continue; } - k = duk_heap_strtable_intern_u32_checked(thr, (duk_uint32_t) i); /* Fragile reachability. */ + k = duk_heap_strtable_intern_u32_checked(thr, (duk_uint32_t) i); /* Fragile reachability. */ DUK_ASSERT(k); duk__add_enum_key(thr, k); @@ -56281,8 +57341,7 @@ continue; } if (DUK_UNLIKELY(DUK_HSTRING_HAS_SYMBOL(k))) { - if (!(enum_flags & DUK_ENUM_INCLUDE_HIDDEN) && - DUK_HSTRING_HAS_HIDDEN(k)) { + if (!(enum_flags & DUK_ENUM_INCLUDE_HIDDEN) && DUK_HSTRING_HAS_HIDDEN(k)) { continue; } if (!(enum_flags & DUK_ENUM_INCLUDE_SYMBOLS)) { @@ -56292,7 +57351,7 @@ need_sort = 1; #endif } else { - DUK_ASSERT(!DUK_HSTRING_HAS_HIDDEN(k)); /* would also have symbol flag */ + DUK_ASSERT(!DUK_HSTRING_HAS_HIDDEN(k)); /* would also have symbol flag */ if (enum_flags & DUK_ENUM_EXCLUDE_STRINGS) { continue; } @@ -56341,7 +57400,10 @@ #else if (need_sort) { DUK_DDD(DUK_DDDPRINT("need to sort")); - duk__sort_enum_keys_es6(thr, res, (duk_int_fast32_t) sort_start_index, (duk_int_fast32_t) sort_end_index); + duk__sort_enum_keys_es6(thr, + res, + (duk_int_fast32_t) sort_start_index, + (duk_int_fast32_t) sort_end_index); } else { DUK_DDD(DUK_DDDPRINT("no need to sort")); } @@ -56374,11 +57436,14 @@ /* Sort to ES2015 order which works for pure array incides but * also for mixed keys. */ - duk__sort_enum_keys_es6(thr, res, (duk_int_fast32_t) DUK__ENUM_START_INDEX, (duk_int_fast32_t) DUK_HOBJECT_GET_ENEXT(res)); + duk__sort_enum_keys_es6(thr, + res, + (duk_int_fast32_t) DUK__ENUM_START_INDEX, + (duk_int_fast32_t) DUK_HOBJECT_GET_ENEXT(res)); } #if defined(DUK_USE_ES6_PROXY) - compact_and_return: +compact_and_return: #endif /* compact; no need to seal because object is internal */ duk_hobject_compact_props(thr, res); @@ -56426,10 +57491,11 @@ #else check_existence = 1; #endif - duk_pop(thr); /* still reachable */ + duk_pop(thr); /* still reachable */ DUK_DDD(DUK_DDDPRINT("getting next enum value, enum_target=%!iO, enumerator=%!iT", - (duk_heaphdr *) enum_target, (duk_tval *) duk_get_tval(thr, -1))); + (duk_heaphdr *) enum_target, + (duk_tval *) duk_get_tval(thr, -1))); /* no array part */ for (;;) { @@ -56470,16 +57536,16 @@ duk_push_hstring(thr, res); if (get_value) { duk_push_hobject(thr, enum_target); - duk_dup_m2(thr); /* -> ... enum key enum_target key */ + duk_dup_m2(thr); /* -> ... enum key enum_target key */ duk_get_prop(thr, -2); /* -> ... enum key enum_target val */ - duk_remove_m2(thr); /* -> ... enum key val */ - duk_remove(thr, -3); /* -> ... key val */ + duk_remove_m2(thr); /* -> ... enum key val */ + duk_remove(thr, -3); /* -> ... key val */ } else { - duk_remove_m2(thr); /* -> ... key */ + duk_remove_m2(thr); /* -> ... key */ } return 1; } else { - duk_pop(thr); /* -> ... */ + duk_pop(thr); /* -> ... */ return 0; } } @@ -56526,7 +57592,7 @@ duk_hstring *k; k = *keys++; - DUK_ASSERT(k != NULL); /* enumerator must have no keys deleted */ + DUK_ASSERT(k != NULL); /* enumerator must have no keys deleted */ DUK_TVAL_SET_STRING(tv, k); tv++; @@ -56538,7 +57604,7 @@ /* enum_target res */ - return 1; /* return 1 to allow callers to tail call */ + return 1; /* return 1 to allow callers to tail call */ } /* automatic undefs */ @@ -56549,7 +57615,10 @@ /* #include duk_internal.h -> already included */ -DUK_INTERNAL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop) { +DUK_INTERNAL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, + duk_hobject *h, + duk_hobject *p, + duk_bool_t ignore_loop) { duk_uint_t sanity; DUK_ASSERT(thr != NULL); @@ -56588,7 +57657,7 @@ DUK_ASSERT(h); tmp = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, h, p); - DUK_HOBJECT_INCREF_ALLOWNULL(thr, p); /* avoid problems if p == h->prototype */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, p); /* avoid problems if p == h->prototype */ DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); #else DUK_ASSERT(h); @@ -56633,7 +57702,7 @@ hdr = (duk_uint32_t *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, h_buf); DUK_ASSERT(hdr != NULL); - hdr0 = (duk_uint32_t) length; /* valid pc range is 0, length */ + hdr0 = (duk_uint32_t) length; /* valid pc range is 0, length */ curr_pc = 0U; while (curr_pc < length) { @@ -56662,8 +57731,8 @@ for (;;) { curr_pc++; - if ( ((curr_pc % DUK_PC2LINE_SKIP) == 0) || /* end of diff run */ - (curr_pc >= length) ) { /* end of bytecode */ + if (((curr_pc % DUK_PC2LINE_SKIP) == 0) || /* end of diff run */ + (curr_pc >= length)) { /* end of bytecode */ break; } DUK_ASSERT(curr_pc < length); @@ -56710,7 +57779,9 @@ (void) duk_to_fixed_buffer(thr, -1, NULL); DUK_DDD(DUK_DDDPRINT("final pc2line data: pc_limit=%ld, length=%ld, %lf bits/opcode --> %!ixT", - (long) length, (long) new_size, (double) new_size * 8.0 / (double) length, + (long) length, + (long) new_size, + (double) new_size * 8.0 / (double) length, (duk_tval *) duk_get_tval(thr, -1))); } @@ -56750,8 +57821,7 @@ pc_limit = hdr0; if (pc >= pc_limit) { /* Note: pc is unsigned and cannot be negative */ - DUK_DD(DUK_DDPRINT("pc2line lookup failed: pc out of bounds (pc=%ld, limit=%ld)", - (long) pc, (long) pc_limit)); + DUK_DD(DUK_DDPRINT("pc2line lookup failed: pc out of bounds (pc=%ld, limit=%ld)", (long) pc, (long) pc_limit)); goto pc2line_error; } @@ -56759,7 +57829,8 @@ start_offset = hdr1 + hdr_index * 2 + 1; if ((duk_size_t) start_offset > DUK_HBUFFER_FIXED_GET_SIZE(buf)) { DUK_DD(DUK_DDPRINT("pc2line lookup failed: start_offset out of bounds (start_offset=%ld, buffer_size=%ld)", - (long) start_offset, (long) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) buf))); + (long) start_offset, + (long) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) buf))); goto pc2line_error; } @@ -56786,7 +57857,7 @@ if (duk_bd_decode_flag(bd_ctx)) { /* 1 1 1 <32 bits> */ duk_uint_fast32_t t; - t = duk_bd_decode(bd_ctx, 16); /* workaround: max nbits = 24 now */ + t = duk_bd_decode(bd_ctx, 16); /* workaround: max nbits = 24 now */ t = (t << 16) + duk_bd_decode(bd_ctx, 16); curr_line = t; } else { @@ -56811,7 +57882,7 @@ DUK_DDD(DUK_DDDPRINT("pc2line lookup result: pc %ld -> line %ld", (long) pc, (long) curr_line)); return curr_line; - pc2line_error: +pc2line_error: DUK_D(DUK_DPRINT("pc2line conversion failed for pc=%ld", (long) pc)); return 0; } @@ -56839,7 +57910,7 @@ return line; } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ /* * duk_hobject property access functionality. * @@ -56888,35 +57959,56 @@ * Local defines */ -#define DUK__NO_ARRAY_INDEX DUK_HSTRING_NO_ARRAY_INDEX +#define DUK__NO_ARRAY_INDEX DUK_HSTRING_NO_ARRAY_INDEX /* Marker values for hash part. */ -#define DUK__HASH_UNUSED DUK_HOBJECT_HASHIDX_UNUSED -#define DUK__HASH_DELETED DUK_HOBJECT_HASHIDX_DELETED +#define DUK__HASH_UNUSED DUK_HOBJECT_HASHIDX_UNUSED +#define DUK__HASH_DELETED DUK_HOBJECT_HASHIDX_DELETED /* Valstack space that suffices for all local calls, excluding any recursion * into ECMAScript or Duktape/C calls (Proxy, getters, etc). */ -#define DUK__VALSTACK_SPACE 10 +#define DUK__VALSTACK_SPACE 10 /* Valstack space allocated especially for proxy lookup which does a * recursive property lookup. */ -#define DUK__VALSTACK_PROXY_LOOKUP 20 +#define DUK__VALSTACK_PROXY_LOOKUP 20 /* * Local prototypes */ -DUK_LOCAL_DECL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc); -DUK_LOCAL_DECL void duk__check_arguments_map_for_put(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc, duk_bool_t throw_flag); -DUK_LOCAL_DECL void duk__check_arguments_map_for_delete(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc); - -DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length_smaller(duk_hthread *thr, duk_hobject *obj, duk_uint32_t old_len, duk_uint32_t new_len, duk_bool_t force_flag, duk_uint32_t *out_result_len); +DUK_LOCAL_DECL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc); +DUK_LOCAL_DECL void duk__check_arguments_map_for_put(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc, + duk_bool_t throw_flag); +DUK_LOCAL_DECL void duk__check_arguments_map_for_delete(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc); + +DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length_smaller(duk_hthread *thr, + duk_hobject *obj, + duk_uint32_t old_len, + duk_uint32_t new_len, + duk_bool_t force_flag, + duk_uint32_t *out_result_len); DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length(duk_hthread *thr, duk_hobject *obj); -DUK_LOCAL_DECL duk_bool_t duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); -DUK_LOCAL_DECL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_uint32_t arr_idx, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_LOCAL_DECL duk_bool_t +duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_LOCAL_DECL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_uint32_t arr_idx, + duk_propdesc *out_desc, + duk_small_uint_t flags); DUK_LOCAL_DECL void duk__abandon_array_part(duk_hthread *thr, duk_hobject *obj); DUK_LOCAL_DECL void duk__grow_props_for_array_item(duk_hthread *thr, duk_hobject *obj, duk_uint32_t highest_arr_idx); @@ -56945,7 +58037,7 @@ dbl = DUK_TVAL_GET_NUMBER(tv); idx = (duk_uint32_t) dbl; if (duk_double_equals((duk_double_t) idx, dbl)) { - /* Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF, + /* Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF, * it's not a valid array index but will then match DUK__NO_ARRAY_INDEX. */ return idx; @@ -56972,7 +58064,7 @@ */ return (duk_uint32_t) t; } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* Convert a duk_tval on the value stack (in a trusted index we don't validate) * to a string or symbol using ES2015 ToPropertyKey(): @@ -56997,7 +58089,7 @@ * but still be compliant and share code. */ - tv_dst = DUK_GET_TVAL_NEGIDX(thr, idx); /* intentionally unvalidated */ + tv_dst = DUK_GET_TVAL_NEGIDX(thr, idx); /* intentionally unvalidated */ if (DUK_TVAL_IS_STRING(tv_dst)) { /* Most important path: strings and plain symbols are used as * is. For symbols the array index check below is unnecessary @@ -57017,7 +58109,7 @@ } DUK_LOCAL duk_uint32_t duk__push_tval_to_property_key(duk_hthread *thr, duk_tval *tv_key, duk_hstring **out_h) { - duk_push_tval(thr, tv_key); /* XXX: could use an unsafe push here */ + duk_push_tval(thr, tv_key); /* XXX: could use an unsafe push here */ return duk__to_property_key(thr, -1, out_h); } @@ -57057,7 +58149,7 @@ * is relatively sparse. */ tmp = e_size; - res = 2; /* Result will be 2 ** (N + 1). */ + res = 2; /* Result will be 2 ** (N + 1). */ while (tmp >= 0x40) { tmp >>= 6; res <<= 6; @@ -57066,21 +58158,21 @@ tmp >>= 1; res <<= 1; } - DUK_ASSERT((DUK_HOBJECT_MAX_PROPERTIES << 2U) > DUK_HOBJECT_MAX_PROPERTIES); /* Won't wrap, even shifted by 2. */ + DUK_ASSERT((DUK_HOBJECT_MAX_PROPERTIES << 2U) > DUK_HOBJECT_MAX_PROPERTIES); /* Won't wrap, even shifted by 2. */ DUK_ASSERT(res > e_size); return res; } else { return 0; } } -#endif /* USE_PROP_HASH_PART */ +#endif /* USE_PROP_HASH_PART */ /* Get minimum entry part growth for a certain size. */ DUK_LOCAL duk_uint32_t duk__get_min_grow_e(duk_uint32_t e_size) { duk_uint32_t res; res = (e_size + DUK_USE_HOBJECT_ENTRY_MINGROW_ADD) / DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR; - DUK_ASSERT(res >= 1); /* important for callers */ + DUK_ASSERT(res >= 1); /* important for callers */ return res; } @@ -57089,7 +58181,7 @@ duk_uint32_t res; res = (a_size + DUK_USE_HOBJECT_ARRAY_MINGROW_ADD) / DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR; - DUK_ASSERT(res >= 1); /* important for callers */ + DUK_ASSERT(res >= 1); /* important for callers */ return res; } @@ -57119,7 +58211,7 @@ DUK_LOCAL void duk__compute_a_stats(duk_hthread *thr, duk_hobject *obj, duk_uint32_t *out_used, duk_uint32_t *out_min_size) { duk_uint_fast32_t i; duk_uint_fast32_t used = 0; - duk_uint_fast32_t highest_idx = (duk_uint_fast32_t) -1; /* see below */ + duk_uint_fast32_t highest_idx = (duk_uint_fast32_t) -1; /* see below */ duk_tval *a; DUK_ASSERT(obj != NULL); @@ -57142,7 +58234,7 @@ */ *out_used = (duk_uint32_t) used; - *out_min_size = (duk_uint32_t) (highest_idx + 1); /* 0 if no used entries */ + *out_min_size = (duk_uint32_t) (highest_idx + 1); /* 0 if no used entries */ } /* Check array density and indicate whether or not the array part should be abandoned. */ @@ -57209,7 +58301,9 @@ duk__compute_a_stats(thr, obj, &old_used, &old_size); DUK_DDD(DUK_DDDPRINT("abandon check, array stats: old_used=%ld, old_size=%ld, arr_idx=%ld", - (long) old_used, (long) old_size, (long) arr_idx)); + (long) old_used, + (long) old_size, + (long) arr_idx)); min_size = arr_idx + 1; #if defined(DUK_USE_OBJSIZES16) @@ -57237,7 +58331,7 @@ DUK_DDD(DUK_DDDPRINT("=> decided to keep array part")); return 0; - do_abandon: +do_abandon: duk__abandon_array_part(thr, obj); DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(obj)); return 1; @@ -57264,7 +58358,8 @@ DUK_DDD(DUK_DDDPRINT("write to new array requires array resize, decide whether to do a " "fast resize without abandon check (arr_idx=%ld, old_size=%ld)", - (long) arr_idx, (long) DUK_HOBJECT_GET_ASIZE(obj))); + (long) arr_idx, + (long) DUK_HOBJECT_GET_ASIZE(obj))); if (DUK_UNLIKELY(duk__abandon_array_check(thr, arr_idx, obj) != 0)) { DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(obj)); @@ -57323,7 +58418,7 @@ return 1; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* Get Proxy target object. If the argument is not a Proxy, return it as is. * If a Proxy is revoked, an error is thrown. @@ -57349,10 +58444,14 @@ DUK_ASSERT(obj != NULL); return obj; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ES6_PROXY) -DUK_LOCAL duk_bool_t duk__proxy_check_prop(duk_hthread *thr, duk_hobject *obj, duk_small_uint_t stridx_trap, duk_tval *tv_key, duk_hobject **out_target) { +DUK_LOCAL duk_bool_t duk__proxy_check_prop(duk_hthread *thr, + duk_hobject *obj, + duk_small_uint_t stridx_trap, + duk_tval *tv_key, + duk_hobject **out_target) { duk_hobject *h_handler; DUK_ASSERT(thr != NULL); @@ -57406,7 +58505,7 @@ duk_push_hobject(thr, h_handler); if (duk_get_prop_stridx_short(thr, -1, stridx_trap)) { /* -> ... handler trap */ - duk_insert(thr, -2); /* -> ... trap handler */ + duk_insert(thr, -2); /* -> ... trap handler */ /* stack prepped for func call: ... trap handler */ return 1; @@ -57415,7 +58514,7 @@ return 0; } } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* * Reallocate property allocation, moving properties to the new allocation. @@ -57470,11 +58569,12 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(obj != NULL); - DUK_ASSERT(!abandon_array || new_a_size == 0); /* if abandon_array, new_a_size must be 0 */ - DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || (DUK_HOBJECT_GET_ESIZE(obj) == 0 && DUK_HOBJECT_GET_ASIZE(obj) == 0)); - DUK_ASSERT(new_h_size == 0 || new_h_size >= new_e_size); /* required to guarantee success of rehashing, - * intentionally use unadjusted new_e_size - */ + DUK_ASSERT(!abandon_array || new_a_size == 0); /* if abandon_array, new_a_size must be 0 */ + DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || + (DUK_HOBJECT_GET_ESIZE(obj) == 0 && DUK_HOBJECT_GET_ASIZE(obj) == 0)); + DUK_ASSERT(new_h_size == 0 || new_h_size >= new_e_size); /* required to guarantee success of rehashing, + * intentionally use unadjusted new_e_size + */ DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); @@ -57504,10 +58604,12 @@ DUK_DDD(DUK_DDDPRINT("using layout 1, but no need to pad e_size: %ld", (long) new_e_size)); new_e_size_adjusted = new_e_size; #elif defined(DUK_USE_HOBJECT_LAYOUT_1) && ((DUK_HOBJECT_ALIGN_TARGET == 4) || (DUK_HOBJECT_ALIGN_TARGET == 8)) - new_e_size_adjusted = (new_e_size + (duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U) & - (~((duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U)); + new_e_size_adjusted = + (new_e_size + (duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U) & (~((duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U)); DUK_DDD(DUK_DDDPRINT("using layout 1, and alignment target is %ld, adjusted e_size: %ld -> %ld", - (long) DUK_HOBJECT_ALIGN_TARGET, (long) new_e_size, (long) new_e_size_adjusted)); + (long) DUK_HOBJECT_ALIGN_TARGET, + (long) new_e_size, + (long) new_e_size_adjusted)); DUK_ASSERT(new_e_size_adjusted >= new_e_size); #else #error invalid hobject layout defines @@ -57517,23 +58619,22 @@ * Debug logging after adjustment. */ - DUK_DDD(DUK_DDDPRINT("attempt to resize hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " - "{e_size=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", - (void *) obj, - (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)), - (long) DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size), - (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), - (long) DUK_HOBJECT_GET_ESIZE(obj), - (long) DUK_HOBJECT_GET_ENEXT(obj), - (long) DUK_HOBJECT_GET_ASIZE(obj), - (long) DUK_HOBJECT_GET_HSIZE(obj), - (long) new_e_size_adjusted, - (long) new_a_size, - (long) new_h_size, - (long) abandon_array, - (long) new_e_size)); + DUK_DDD(DUK_DDDPRINT( + "attempt to resize hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " + "{e_size=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", + (void *) obj, + (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)), + (long) DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size), + (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), + (long) DUK_HOBJECT_GET_ESIZE(obj), + (long) DUK_HOBJECT_GET_ENEXT(obj), + (long) DUK_HOBJECT_GET_ASIZE(obj), + (long) DUK_HOBJECT_GET_HSIZE(obj), + (long) new_e_size_adjusted, + (long) new_a_size, + (long) new_h_size, + (long) abandon_array, + (long) new_e_size)); /* * Property count check. This is the only point where we ensure that @@ -57576,9 +58677,9 @@ #endif prev_ms_base_flags = thr->heap->ms_base_flags; thr->heap->ms_base_flags |= - DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact the current object (all objects really). */ - thr->heap->pf_prevent_count++; /* Avoid finalizers. */ - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact the current object (all objects really). */ + thr->heap->pf_prevent_count++; /* Avoid finalizers. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ new_alloc_size = DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size); DUK_DDD(DUK_DDDPRINT("new hobject allocation size is %ld", (long) new_alloc_size)); @@ -57591,7 +58692,7 @@ /* Alloc may trigger mark-and-sweep but no compaction, and * cannot throw. */ -#if 0 /* XXX: inject test */ +#if 0 /* XXX: inject test */ if (1) { new_p = NULL; goto alloc_failed; @@ -57609,19 +58710,28 @@ /* Set up pointers to the new property area: this is hidden behind a macro * because it is memory layout specific. */ - DUK_HOBJECT_P_SET_REALLOC_PTRS(new_p, new_e_k, new_e_pv, new_e_f, new_a, new_h, - new_e_size_adjusted, new_a_size, new_h_size); - DUK_UNREF(new_h); /* happens when hash part dropped */ + DUK_HOBJECT_P_SET_REALLOC_PTRS(new_p, + new_e_k, + new_e_pv, + new_e_f, + new_a, + new_h, + new_e_size_adjusted, + new_a_size, + new_h_size); + DUK_UNREF(new_h); /* happens when hash part dropped */ new_e_next = 0; /* if new_p == NULL, all of these pointers are NULL */ - DUK_ASSERT((new_p != NULL) || - (new_e_k == NULL && new_e_pv == NULL && new_e_f == NULL && - new_a == NULL && new_h == NULL)); + DUK_ASSERT((new_p != NULL) || (new_e_k == NULL && new_e_pv == NULL && new_e_f == NULL && new_a == NULL && new_h == NULL)); DUK_DDD(DUK_DDDPRINT("new alloc size %ld, new_e_k=%p, new_e_pv=%p, new_e_f=%p, new_a=%p, new_h=%p", - (long) new_alloc_size, (void *) new_e_k, (void *) new_e_pv, (void *) new_e_f, - (void *) new_a, (void *) new_h)); + (long) new_alloc_size, + (void *) new_e_k, + (void *) new_e_pv, + (void *) new_e_f, + (void *) new_a, + (void *) new_h)); /* * Migrate array part to start of entries if requested. @@ -57662,8 +58772,7 @@ continue; } - DUK_ASSERT(new_p != NULL && new_e_k != NULL && - new_e_pv != NULL && new_e_f != NULL); + DUK_ASSERT(new_p != NULL && new_e_k != NULL && new_e_pv != NULL && new_e_f != NULL); /* * Intern key via the valstack to ensure reachability behaves @@ -57675,7 +58784,7 @@ * must be careful. */ -#if 0 /* XXX: inject test */ +#if 0 /* XXX: inject test */ if (1) { goto abandon_error; } @@ -57691,7 +58800,7 @@ if (key == NULL) { goto abandon_error; } - duk_push_hstring(thr, key); /* keep key reachable for GC etc; guaranteed not to fail */ + duk_push_hstring(thr, key); /* keep key reachable for GC etc; guaranteed not to fail */ /* Key is now reachable in the valstack, don't INCREF * the new allocation yet (we'll steal the refcounts @@ -57699,11 +58808,10 @@ */ new_e_knew_e_next = key; - tv2 = &new_e_pvnew_e_next.v; /* array entries are all plain values */ + tv2 = &new_e_pvnew_e_next.v; /* array entries are all plain values */ DUK_TVAL_SET_TVAL(tv2, tv1); - new_e_fnew_e_next = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE | - DUK_PROPDESC_FLAG_CONFIGURABLE; + new_e_fnew_e_next = + DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE; new_e_next++; /* Note: new_e_next matches pushed temp key count, and nothing can @@ -57730,8 +58838,7 @@ continue; } - DUK_ASSERT(new_p != NULL && new_e_k != NULL && - new_e_pv != NULL && new_e_f != NULL); + DUK_ASSERT(new_p != NULL && new_e_k != NULL && new_e_pv != NULL && new_e_f != NULL); new_e_knew_e_next = key; new_e_pvnew_e_next = DUK_HOBJECT_E_GET_VALUE(thr->heap, obj, i); @@ -57765,9 +58872,7 @@ DUK_ASSERT(new_a != NULL || array_copy_size == 0U); DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || array_copy_size == 0U); DUK_ASSERT(DUK_HOBJECT_GET_ASIZE(obj) > 0 || array_copy_size == 0U); - duk_memcpy_unsafe((void *) new_a, - (const void *) DUK_HOBJECT_A_GET_BASE(thr->heap, obj), - array_copy_size); + duk_memcpy_unsafe((void *) new_a, (const void *) DUK_HOBJECT_A_GET_BASE(thr->heap, obj), array_copy_size); for (i = DUK_HOBJECT_GET_ASIZE(obj); i < new_a_size; i++) { duk_tval *tv = &new_ai; @@ -57795,7 +58900,7 @@ DUK_ASSERT(new_h_size > 0); duk_memset(new_h, 0xff, sizeof(duk_uint32_t) * new_h_size); - DUK_ASSERT(new_e_next <= new_h_size); /* equality not actually possible */ + DUK_ASSERT(new_e_next <= new_h_size); /* equality not actually possible */ mask = new_h_size - 1; for (i = 0; i < new_e_next; i++) { @@ -57804,10 +58909,10 @@ DUK_ASSERT(key != NULL); j = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { - DUK_ASSERT(new_hj != DUK__HASH_DELETED); /* should never happen */ + DUK_ASSERT(new_hj != DUK__HASH_DELETED); /* should never happen */ if (new_hj == DUK__HASH_UNUSED) { DUK_DDD(DUK_DDDPRINT("rebuild hit %ld -> %ld", (long) j, (long) i)); new_hj = (duk_uint32_t) i; @@ -57820,37 +58925,36 @@ } } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* * Nice debug log. */ - DUK_DD(DUK_DDPRINT("resized hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " - "{p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", - (void *) obj, - (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)), - (long) new_alloc_size, - (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), - (long) DUK_HOBJECT_GET_ESIZE(obj), - (long) DUK_HOBJECT_GET_ENEXT(obj), - (long) DUK_HOBJECT_GET_ASIZE(obj), - (long) DUK_HOBJECT_GET_HSIZE(obj), - (void *) new_p, - (long) new_e_size_adjusted, - (long) new_e_next, - (long) new_a_size, - (long) new_h_size, - (long) abandon_array, - (long) new_e_size)); + DUK_DD(DUK_DDPRINT( + "resized hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " + "{p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", + (void *) obj, + (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)), + (long) new_alloc_size, + (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), + (long) DUK_HOBJECT_GET_ESIZE(obj), + (long) DUK_HOBJECT_GET_ENEXT(obj), + (long) DUK_HOBJECT_GET_ASIZE(obj), + (long) DUK_HOBJECT_GET_HSIZE(obj), + (void *) new_p, + (long) new_e_size_adjusted, + (long) new_e_next, + (long) new_a_size, + (long) new_h_size, + (long) abandon_array, + (long) new_e_size)); /* * All done, switch properties ('p') allocation to new one. */ - DUK_FREE_CHECKED(thr, DUK_HOBJECT_GET_PROPS(thr->heap, obj)); /* NULL obj->p is OK */ + DUK_FREE_CHECKED(thr, DUK_HOBJECT_GET_PROPS(thr->heap, obj)); /* NULL obj->p is OK */ DUK_HOBJECT_SET_PROPS(thr->heap, obj, new_p); DUK_HOBJECT_SET_ESIZE(obj, new_e_size_adjusted); DUK_HOBJECT_SET_ENEXT(obj, new_e_next); @@ -57889,11 +58993,11 @@ * unwind. */ - abandon_error: - alloc_failed: +abandon_error: +alloc_failed: DUK_D(DUK_DPRINT("object property table resize failed")); - DUK_FREE_CHECKED(thr, new_p); /* OK for NULL. */ + DUK_FREE_CHECKED(thr, new_p); /* OK for NULL. */ thr->heap->pf_prevent_count--; thr->heap->ms_base_flags = prev_ms_base_flags; @@ -57910,9 +59014,7 @@ * Helpers to resize properties allocation on specific needs. */ -DUK_INTERNAL void duk_hobject_resize_entrypart(duk_hthread *thr, - duk_hobject *obj, - duk_uint32_t new_e_size) { +DUK_INTERNAL void duk_hobject_resize_entrypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_e_size) { duk_uint32_t old_e_size; duk_uint32_t new_a_size; duk_uint32_t new_h_size; @@ -57936,7 +59038,7 @@ /* Grow entry part allocation for one additional entry. */ DUK_LOCAL void duk__grow_props_for_new_entry_item(duk_hthread *thr, duk_hobject *obj) { - duk_uint32_t old_e_used; /* actually used, non-NULL entries */ + duk_uint32_t old_e_used; /* actually used, non-NULL entries */ duk_uint32_t new_e_size_minimum; duk_uint32_t new_e_size; duk_uint32_t new_a_size; @@ -57998,7 +59100,7 @@ new_h_size = DUK_HOBJECT_GET_HSIZE(obj); new_a_size_minimum = highest_arr_idx + 1; new_a_size = highest_arr_idx + duk__get_min_grow_a(highest_arr_idx); - DUK_ASSERT(new_a_size >= highest_arr_idx + 1); /* duk__get_min_grow_a() is always >= 1 */ + DUK_ASSERT(new_a_size >= highest_arr_idx + 1); /* duk__get_min_grow_a() is always >= 1 */ #if defined(DUK_USE_OBJSIZES16) if (new_e_size > DUK_UINT16_MAX) { @@ -58030,7 +59132,7 @@ duk_uint32_t new_e_size; duk_uint32_t new_a_size; duk_uint32_t new_h_size; - duk_uint32_t e_used; /* actually used, non-NULL keys */ + duk_uint32_t e_used; /* actually used, non-NULL keys */ duk_uint32_t a_used; duk_uint32_t a_size; @@ -58075,8 +59177,13 @@ DUK_DD(DUK_DDPRINT("abandon array part for hobject %p, " "array stats before: e_used=%ld, a_used=%ld, a_size=%ld; " "resize to e_size=%ld, a_size=%ld, h_size=%ld", - (void *) obj, (long) e_used, (long) a_used, (long) a_size, - (long) new_e_size, (long) new_a_size, (long) new_h_size)); + (void *) obj, + (long) e_used, + (long) a_used, + (long) a_size, + (long) new_e_size, + (long) new_a_size, + (long) new_h_size)); duk_hobject_realloc_props(thr, obj, new_e_size, new_a_size, new_h_size, 1); } @@ -58094,9 +59201,9 @@ */ DUK_INTERNAL void duk_hobject_compact_props(duk_hthread *thr, duk_hobject *obj) { - duk_uint32_t e_size; /* currently used -> new size */ - duk_uint32_t a_size; /* currently required */ - duk_uint32_t a_used; /* actually used */ + duk_uint32_t e_size; /* currently used -> new size */ + duk_uint32_t a_size; /* currently required */ + duk_uint32_t a_used; /* actually used */ duk_uint32_t h_size; duk_bool_t abandon_array; @@ -58115,13 +59222,17 @@ DUK_DD(DUK_DDPRINT("compacting hobject, used e keys %ld, used a keys %ld, min a size %ld, " "resized array density would be: %ld/%ld = %lf", - (long) e_size, (long) a_used, (long) a_size, - (long) a_used, (long) a_size, + (long) e_size, + (long) a_used, + (long) a_size, + (long) a_used, + (long) a_size, (double) a_used / (double) a_size)); if (duk__abandon_array_density_check(a_used, a_size)) { DUK_DD(DUK_DDPRINT("decided to abandon array during compaction, a_used=%ld, a_size=%ld", - (long) a_used, (long) a_size)); + (long) a_used, + (long) a_size)); abandon_array = 1; e_size += a_used; a_size = 0; @@ -58141,7 +59252,10 @@ #endif DUK_DD(DUK_DDPRINT("compacting hobject -> new e_size %ld, new a_size=%ld, new h_size=%ld, abandon_array=%ld", - (long) e_size, (long) a_size, (long) h_size, (long) abandon_array)); + (long) e_size, + (long) a_size, + (long) h_size, + (long) abandon_array)); duk_hobject_realloc_props(thr, obj, e_size, a_size, h_size, abandon_array); } @@ -58156,15 +59270,15 @@ * but there is no hash part, h_idx is set to -1. */ -DUK_INTERNAL duk_bool_t duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx) { +DUK_INTERNAL duk_bool_t +duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx) { DUK_ASSERT(obj != NULL); DUK_ASSERT(key != NULL); DUK_ASSERT(e_idx != NULL); DUK_ASSERT(h_idx != NULL); DUK_UNREF(heap); - if (DUK_LIKELY(DUK_HOBJECT_GET_HSIZE(obj) == 0)) - { + if (DUK_LIKELY(DUK_HOBJECT_GET_HSIZE(obj) == 0)) { /* Linear scan: more likely because most objects are small. * This is an important fast path. * @@ -58186,8 +59300,7 @@ } } #if defined(DUK_USE_HOBJECT_HASH_PART) - else - { + else { /* hash lookup */ duk_uint32_t n; duk_uint32_t i, step; @@ -58200,40 +59313,38 @@ n = DUK_HOBJECT_GET_HSIZE(obj); mask = n - 1; i = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { duk_uint32_t t; - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HOBJECT_GET_HSIZE(obj)); t = h_basei; DUK_ASSERT(t == DUK__HASH_UNUSED || t == DUK__HASH_DELETED || - (t < DUK_HOBJECT_GET_ESIZE(obj))); /* t >= 0 always true, unsigned */ + (t < DUK_HOBJECT_GET_ESIZE(obj))); /* t >= 0 always true, unsigned */ if (t == DUK__HASH_UNUSED) { break; } else if (t == DUK__HASH_DELETED) { - DUK_DDD(DUK_DDDPRINT("lookup miss (deleted) i=%ld, t=%ld", - (long) i, (long) t)); + DUK_DDD(DUK_DDDPRINT("lookup miss (deleted) i=%ld, t=%ld", (long) i, (long) t)); } else { DUK_ASSERT(t < DUK_HOBJECT_GET_ESIZE(obj)); if (DUK_HOBJECT_E_GET_KEY(heap, obj, t) == key) { - DUK_DDD(DUK_DDDPRINT("lookup hit i=%ld, t=%ld -> key %p", - (long) i, (long) t, (void *) key)); + DUK_DDD( + DUK_DDDPRINT("lookup hit i=%ld, t=%ld -> key %p", (long) i, (long) t, (void *) key)); *e_idx = (duk_int_t) t; *h_idx = (duk_int_t) i; return 1; } - DUK_DDD(DUK_DDDPRINT("lookup miss i=%ld, t=%ld", - (long) i, (long) t)); + DUK_DDD(DUK_DDDPRINT("lookup miss i=%ld, t=%ld", (long) i, (long) t)); } i = (i + step) & mask; /* Guaranteed to finish (hash is larger than #props). */ } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* Not found, leave e_idx and h_idx unset. */ return 0; @@ -58262,7 +59373,10 @@ } /* For internal use: get non-accessor entry value and attributes */ -DUK_INTERNAL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_uint_t *out_attrs) { +DUK_INTERNAL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, + duk_hobject *obj, + duk_hstring *key, + duk_uint_t *out_attrs) { duk_int_t e_idx; duk_int_t h_idx; @@ -58347,14 +59461,15 @@ n = DUK_HOBJECT_GET_HSIZE(obj); mask = n - 1; i = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { duk_uint32_t t = h_basei; if (t == DUK__HASH_UNUSED || t == DUK__HASH_DELETED) { DUK_DDD(DUK_DDDPRINT("duk__hobject_alloc_entry_checked() inserted key into hash part, %ld -> %ld", - (long) i, (long) idx)); - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + (long) i, + (long) idx)); + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HOBJECT_GET_HSIZE(obj)); DUK_ASSERT_DISABLE(idx >= 0); DUK_ASSERT(idx < DUK_HOBJECT_GET_ESIZE(obj)); @@ -58367,7 +59482,7 @@ /* Guaranteed to finish (hash is larger than #props). */ } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* Note: we could return the hash index here too, but it's not * needed right now. @@ -58475,8 +59590,12 @@ DUK_DDD(DUK_DDDPRINT("arguments map lookup: thr=%p, obj=%p, key=%p, temp_desc=%p " "(obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) temp_desc, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) temp_desc, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); if (!duk_hobject_get_own_propdesc(thr, obj, DUK_HTHREAD_STRING_INT_MAP(thr), temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { DUK_DDD(DUK_DDDPRINT("-> no 'map'")); @@ -58485,7 +59604,7 @@ map = duk_require_hobject(thr, -1); DUK_ASSERT(map != NULL); - duk_pop_unsafe(thr); /* map is reachable through obj */ + duk_pop_unsafe(thr); /* map is reachable through obj */ if (!duk_hobject_get_own_propdesc(thr, map, key, temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { DUK_DDD(DUK_DDDPRINT("-> 'map' exists, but key not in map")); @@ -58495,29 +59614,32 @@ /* ... varname */ DUK_DDD(DUK_DDDPRINT("-> 'map' exists, and contains key, key is mapped to argument/variable binding %!T", (duk_tval *) duk_get_tval(thr, -1))); - DUK_ASSERT(duk_is_string(thr, -1)); /* guaranteed when building arguments */ + DUK_ASSERT(duk_is_string(thr, -1)); /* guaranteed when building arguments */ /* get varenv for varname (callee's declarative lexical environment) */ rc = duk_hobject_get_own_propdesc(thr, obj, DUK_HTHREAD_STRING_INT_VARENV(thr), temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); - DUK_ASSERT(rc != 0); /* arguments MUST have an initialized lexical environment reference */ + DUK_ASSERT(rc != 0); /* arguments MUST have an initialized lexical environment reference */ varenv = duk_require_hobject(thr, -1); DUK_ASSERT(varenv != NULL); - duk_pop_unsafe(thr); /* varenv remains reachable through 'obj' */ + duk_pop_unsafe(thr); /* varenv remains reachable through 'obj' */ DUK_DDD(DUK_DDDPRINT("arguments varenv is: %!dO", (duk_heaphdr *) varenv)); /* success: leave varname in stack */ *out_map = map; *out_varenv = varenv; - return 1; /* ... varname */ + return 1; /* ... varname */ } /* Lookup 'key' from arguments internal 'map', and leave replacement value * on stack top if mapped (and return non-zero). * Used in E5 Section 10.6 algorithm for GetOwnProperty (used by Get). */ -DUK_LOCAL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc) { +DUK_LOCAL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc) { duk_hobject *map; duk_hobject *varenv; duk_hstring *varname; @@ -58533,7 +59655,7 @@ varname = duk_require_hstring(thr, -1); DUK_ASSERT(varname != NULL); - duk_pop_unsafe(thr); /* varname is still reachable */ + duk_pop_unsafe(thr); /* varname is still reachable */ DUK_DDD(DUK_DDDPRINT("arguments object automatic getvar for a bound variable; " "key=%!O, varname=%!O", @@ -58554,7 +59676,11 @@ * Used in E5 Section 10.6 algorithm for DefineOwnProperty (used by Put). * Assumes stack top contains 'put' value (which is NOT popped). */ -DUK_LOCAL void duk__check_arguments_map_for_put(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc, duk_bool_t throw_flag) { +DUK_LOCAL void duk__check_arguments_map_for_put(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc, + duk_bool_t throw_flag) { duk_hobject *map; duk_hobject *varenv; duk_hstring *varname; @@ -58570,7 +59696,7 @@ varname = duk_require_hstring(thr, -1); DUK_ASSERT(varname != NULL); - duk_pop_unsafe(thr); /* varname is still reachable */ + duk_pop_unsafe(thr); /* varname is still reachable */ DUK_DDD(DUK_DDDPRINT("arguments object automatic putvar for a bound variable; " "key=%!O, varname=%!O, value=%!T", @@ -58609,15 +59735,14 @@ map = duk_require_hobject(thr, -1); DUK_ASSERT(map != NULL); - duk_pop_unsafe(thr); /* map is reachable through obj */ + duk_pop_unsafe(thr); /* map is reachable through obj */ - DUK_DDD(DUK_DDDPRINT("-> have 'map', delete key %!O from map (if exists)); ignore result", - (duk_heaphdr *) key)); + DUK_DDD(DUK_DDDPRINT("-> have 'map', delete key %!O from map (if exists)); ignore result", (duk_heaphdr *) key)); /* Note: no recursion issue, we can trust 'map' to behave */ DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(map)); DUK_DDD(DUK_DDDPRINT("map before deletion: %!O", (duk_heaphdr *) map)); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ DUK_DDD(DUK_DDDPRINT("map after deletion: %!O", (duk_heaphdr *) map)); } @@ -58660,14 +59785,24 @@ * accessor properties later, this would need to change. */ -DUK_LOCAL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_uint32_t arr_idx, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_LOCAL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_uint32_t arr_idx, + duk_propdesc *out_desc, + duk_small_uint_t flags) { duk_tval *tv; DUK_DDD(DUK_DDDPRINT("duk_hobject_get_own_propdesc: thr=%p, obj=%p, key=%p, out_desc=%p, flags=%lx, " "arr_idx=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) out_desc, - (long) flags, (long) arr_idx, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) out_desc, + (long) flags, + (long) arr_idx, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -58741,14 +59876,13 @@ duk_push_tval(thr, tv); } /* implicit attributes */ - out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_CONFIGURABLE | - DUK_PROPDESC_FLAG_ENUMERABLE; + out_desc->flags = + DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE | DUK_PROPDESC_FLAG_ENUMERABLE; out_desc->get = NULL; out_desc->set = NULL; out_desc->e_idx = -1; out_desc->h_idx = -1; - out_desc->a_idx = (duk_int_t) arr_idx; /* XXX: limit 2G due to being signed */ + out_desc->a_idx = (duk_int_t) arr_idx; /* XXX: limit 2G due to being signed */ goto prop_found; } } @@ -58769,7 +59903,8 @@ duk_harray *a; DUK_DDD(DUK_DDDPRINT("array object exotic property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + (duk_heaphdr *) key, + (long) arr_idx)); a = (duk_harray *) obj; DUK_HARRAY_ASSERT_VALID(a); @@ -58791,11 +59926,12 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } else if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj)) { DUK_DDD(DUK_DDDPRINT("string object exotic property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + (duk_heaphdr *) key, + (long) arr_idx)); /* XXX: charlen; avoid multiple lookups? */ @@ -58810,9 +59946,9 @@ DUK_DDD(DUK_DDDPRINT("-> found, array index inside string")); if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_push_hstring(thr, h_val); - duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ + duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ } - out_desc->flags = DUK_PROPDESC_FLAG_ENUMERABLE | /* E5 Section 15.5.5.2 */ + out_desc->flags = DUK_PROPDESC_FLAG_ENUMERABLE | /* E5 Section 15.5.5.2 */ DUK_PROPDESC_FLAG_VIRTUAL; out_desc->get = NULL; out_desc->set = NULL; @@ -58821,7 +59957,7 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } else { /* index is above internal string length -> property is fully normal */ DUK_DDD(DUK_DDDPRINT("array index outside string -> normal property")); @@ -58836,7 +59972,7 @@ if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h_val)); } - out_desc->flags = DUK_PROPDESC_FLAG_VIRTUAL; /* E5 Section 15.5.5.1 */ + out_desc->flags = DUK_PROPDESC_FLAG_VIRTUAL; /* E5 Section 15.5.5.1 */ out_desc->get = NULL; out_desc->set = NULL; out_desc->e_idx = -1; @@ -58844,7 +59980,7 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -58855,8 +59991,7 @@ h_bufobj = (duk_hbufobj *) obj; DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); - DUK_DDD(DUK_DDDPRINT("bufobj property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + DUK_DDD(DUK_DDDPRINT("bufobj property get for key: %!O, arr_idx: %ld", (duk_heaphdr *) key, (long) arr_idx)); if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { DUK_DDD(DUK_DDDPRINT("array index exists")); @@ -58865,21 +60000,22 @@ * length downshift won't. */ if (arr_idx < (h_bufobj->length >> h_bufobj->shift)) { - byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_uint8_t *data; - if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { - data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + h_bufobj->offset + byte_off; + if (h_bufobj->buf != NULL && + DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { + data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + + h_bufobj->offset + byte_off; duk_hbufobj_push_validated_read(thr, h_bufobj, data, elem_size); } else { DUK_D(DUK_DPRINT("bufobj access out of underlying buffer, ignoring (read zero)")); duk_push_uint(thr, 0); } } - out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_VIRTUAL; + out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_VIRTUAL; if (DUK_HOBJECT_GET_CLASS_NUMBER(obj) != DUK_HOBJECT_CLASS_ARRAYBUFFER) { /* ArrayBuffer indices are non-standard and are * non-enumerable to avoid their serialization. @@ -58893,7 +60029,8 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be e.g. arguments exotic, since exotic 'traits' are mutually exclusive */ + goto prop_found_noexotic; /* cannot be e.g. arguments exotic, since exotic 'traits' are mutually + exclusive */ } else { /* index is above internal buffer length -> property is fully normal */ DUK_DDD(DUK_DDDPRINT("array index outside buffer -> normal property")); @@ -58915,10 +60052,10 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Array properties have exotic behavior but they are concrete, * so no special handling here. @@ -58932,7 +60069,7 @@ * Not found as concrete or virtual. */ - prop_not_found: +prop_not_found: DUK_DDD(DUK_DDDPRINT("-> not found (virtual, entry part, or array part)")); DUK_STATS_INC(thr->heap, stats_getownpropdesc_miss); return 0; @@ -58944,7 +60081,7 @@ * description of GetOwnProperty variant for arguments. */ - prop_found: +prop_found: DUK_DDD(DUK_DDDPRINT("-> property found, checking for arguments exotic post-behavior")); /* Notes: @@ -58954,8 +60091,7 @@ * DUK_GETDESC_FLAG_PUSH_VALUE is not set. */ - if (DUK_UNLIKELY(DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && - arr_idx != DUK__NO_ARRAY_INDEX && + if (DUK_UNLIKELY(DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && arr_idx != DUK__NO_ARRAY_INDEX && (flags & DUK_GETDESC_FLAG_PUSH_VALUE))) { duk_propdesc temp_desc; @@ -58981,12 +60117,13 @@ } } - prop_found_noexotic: +prop_found_noexotic: DUK_STATS_INC(thr->heap, stats_getownpropdesc_hit); return 1; } -DUK_INTERNAL duk_bool_t duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_INTERNAL duk_bool_t +duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { DUK_ASSERT(thr != NULL); DUK_ASSERT(obj != NULL); DUK_ASSERT(key != NULL); @@ -59015,7 +60152,8 @@ * pointers. */ -DUK_LOCAL duk_bool_t duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_LOCAL duk_bool_t +duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { duk_hobject *curr; duk_uint32_t arr_idx; duk_uint_t sanity; @@ -59033,9 +60171,14 @@ DUK_DDD(DUK_DDDPRINT("duk__get_propdesc: thr=%p, obj=%p, key=%p, out_desc=%p, flags=%lx, " "arr_idx=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) out_desc, - (long) flags, (long) arr_idx, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) out_desc, + (long) flags, + (long) arr_idx, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); curr = obj; DUK_ASSERT(curr != NULL); @@ -59095,11 +60238,8 @@ DUK_UNREF(thr); - if (!(DUK_HOBJECT_HAS_ARRAY_PART(obj) && - !DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && - !DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj) && - !DUK_HOBJECT_IS_BUFOBJ(obj) && - !DUK_HOBJECT_IS_PROXY(obj))) { + if (!(DUK_HOBJECT_HAS_ARRAY_PART(obj) && !DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && !DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj) && + !DUK_HOBJECT_IS_BUFOBJ(obj) && !DUK_HOBJECT_IS_PROXY(obj))) { /* Must have array part and no conflicting exotic behaviors. * Doesn't need to have array special behavior, e.g. Arguments * object has array part. @@ -59117,7 +60257,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { DUK_DDD(DUK_DDDPRINT("key is not a number")); @@ -59151,18 +60291,19 @@ return NULL; } -DUK_LOCAL duk_bool_t duk__putprop_shallow_fastpath_array_tval(duk_hthread *thr, duk_hobject *obj, duk_tval *tv_key, duk_tval *tv_val) { +DUK_LOCAL duk_bool_t duk__putprop_shallow_fastpath_array_tval(duk_hthread *thr, + duk_hobject *obj, + duk_tval *tv_key, + duk_tval *tv_val) { duk_tval *tv; duk_harray *a; duk_uint32_t idx; duk_uint32_t old_len, new_len; - if (!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj) && - DUK_HOBJECT_HAS_ARRAY_PART(obj) && - DUK_HOBJECT_HAS_EXTENSIBLE(obj))) { + if (!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj) && DUK_HOBJECT_HAS_ARRAY_PART(obj) && DUK_HOBJECT_HAS_EXTENSIBLE(obj))) { return 0; } - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures */ a = (duk_harray *) obj; DUK_HARRAY_ASSERT_VALID(a); @@ -59172,7 +60313,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { DUK_DDD(DUK_DDDPRINT("key is not a number")); @@ -59184,7 +60325,7 @@ * because 0xffffffffUL will never be inside object 'a_size'. */ - if (idx >= DUK_HOBJECT_GET_ASIZE(obj)) { /* for resizing of array part, use slow path */ + if (idx >= DUK_HOBJECT_GET_ASIZE(obj)) { /* for resizing of array part, use slow path */ return 0; } DUK_ASSERT(idx != 0xffffffffUL); @@ -59195,7 +60336,8 @@ if (idx >= old_len) { DUK_DDD(DUK_DDDPRINT("write new array entry requires length update " "(arr_idx=%ld, old_len=%ld)", - (long) idx, (long) old_len)); + (long) idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a)) { /* The correct behavior here is either a silent error * or a TypeError, depending on strictness. Fall back @@ -59209,12 +60351,12 @@ } tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects */ DUK_DDD(DUK_DDDPRINT("array fast path success for index %ld", (long) idx)); return 1; } -#endif /* DUK_USE_ARRAY_PROP_FASTPATH */ +#endif /* DUK_USE_ARRAY_PROP_FASTPATH */ /* * Fast path for bufobj getprop/putprop @@ -59241,7 +60383,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { return 0; @@ -59258,7 +60400,7 @@ } DUK_ASSERT(idx != DUK__NO_ARRAY_INDEX); - byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { @@ -59271,7 +60413,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) DUK_LOCAL duk_bool_t duk__putprop_fastpath_bufobj_tval(duk_hthread *thr, duk_hobject *obj, duk_tval *tv_key, duk_tval *tv_val) { @@ -59281,11 +60423,10 @@ duk_small_uint_t elem_size; duk_uint8_t *data; - if (!(DUK_HOBJECT_IS_BUFOBJ(obj) && - DUK_TVAL_IS_NUMBER(tv_val))) { + if (!(DUK_HOBJECT_IS_BUFOBJ(obj) && DUK_TVAL_IS_NUMBER(tv_val))) { return 0; } - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures; rom objects are never bufobjs now */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures; rom objects are never bufobjs now */ h_bufobj = (duk_hbufobj *) obj; if (!DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { @@ -59297,7 +60438,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { return 0; @@ -59314,7 +60455,7 @@ } DUK_ASSERT(idx != DUK__NO_ARRAY_INDEX); - byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); /* Value is required to be a number in the fast path so there @@ -59333,7 +60474,7 @@ duk_pop_unsafe(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * GETPROP: ECMAScript property read. @@ -59349,8 +60490,11 @@ duk_uint_t sanity; DUK_DDD(DUK_DDDPRINT("getprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -59387,8 +60531,11 @@ #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot read property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot read property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); break; @@ -59418,7 +60565,7 @@ pop_count = 0; } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object string, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -59427,15 +60574,15 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object string, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { duk_pop_n_unsafe(thr, pop_count); duk_push_hstring(thr, h); - duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ + duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ DUK_STATS_INC(thr->heap, stats_getprop_stringidx); DUK_DDD(DUK_DDDPRINT("-> %!T (base is string, key is an index inside string length " @@ -59452,12 +60599,13 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object string, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { - duk_pop_unsafe(thr); /* key -> */ - duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); /* -> res */ + duk_pop_unsafe(thr); /* key -> */ + duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); /* -> res */ DUK_STATS_INC(thr->heap, stats_getprop_stringlen); DUK_DDD(DUK_DDDPRINT("-> %!T (base is string, key is 'length' after coercion -> " @@ -59468,7 +60616,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a string, start lookup from string prototype")); curr = thr->builtinsDUK_BIDX_STRING_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_OBJECT: { @@ -59513,9 +60661,9 @@ /* -> ... trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'get' for key %!T", (duk_tval *) tv_key)); DUK_STATS_INC(thr->heap, stats_getprop_proxy); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ - duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ + duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ duk_call_method(thr, 3 /*nargs*/); /* Target object must be checked for a conflicting @@ -59525,25 +60673,27 @@ DUK_ASSERT(key != NULL); if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { - duk_tval *tv_hook = duk_require_tval(thr, -3); /* value from hook */ - duk_tval *tv_targ = duk_require_tval(thr, -1); /* value from target */ + duk_tval *tv_hook = duk_require_tval(thr, -3); /* value from hook */ + duk_tval *tv_targ = duk_require_tval(thr, -1); /* value from target */ duk_bool_t datadesc_reject; duk_bool_t accdesc_reject; DUK_DDD(DUK_DDDPRINT("proxy 'get': target has matching property %!O, check for " "conflicting property; tv_hook=%!T, tv_targ=%!T, desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (duk_tval *) tv_hook, (duk_tval *) tv_targ, + (duk_heaphdr *) key, + (duk_tval *) tv_hook, + (duk_tval *) tv_targ, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (void *) desc.get, + (void *) desc.set)); datadesc_reject = !(desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && !(desc.flags & DUK_PROPDESC_FLAG_WRITABLE) && !duk_js_samevalue(tv_hook, tv_targ); accdesc_reject = (desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && - !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && - (desc.get == NULL) && + !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && (desc.get == NULL) && !DUK_TVAL_IS_UNDEFINED(tv_hook); if (datadesc_reject || accdesc_reject) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); @@ -59554,13 +60704,13 @@ } else { duk_pop_unsafe(thr); } - return 1; /* return value */ + return 1; /* return value */ } - curr = h_target; /* resume lookup from target */ + curr = h_target; /* resume lookup from target */ DUK_TVAL_SET_OBJECT(tv_obj, curr); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ if (DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(curr)) { arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); @@ -59575,11 +60725,11 @@ /* no need for 'caller' post-check, because 'key' must be an array index */ - duk_remove_m2(thr); /* key result -> result */ + duk_remove_m2(thr); /* key result -> result */ return 1; } - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } break; } @@ -59601,10 +60751,9 @@ arr_idx = duk__tval_fastint_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path fastint; arr_idx %ld", (long) arr_idx)); pop_count = 0; - } - else + } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -59613,12 +60762,12 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { duk_pop_n_unsafe(thr, pop_count); duk_push_uint(thr, ((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h))arr_idx); DUK_STATS_INC(thr->heap, stats_getprop_bufferidx); @@ -59636,12 +60785,13 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { - duk_pop_unsafe(thr); /* key -> */ - duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h)); /* -> res */ + duk_pop_unsafe(thr); /* key -> */ + duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h)); /* -> res */ DUK_STATS_INC(thr->heap, stats_getprop_bufferlen); DUK_DDD(DUK_DDDPRINT("-> %!T (base is buffer, key is 'length' " @@ -59652,7 +60802,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a buffer, start lookup from Uint8Array prototype")); curr = thr->builtinsDUK_BIDX_UINT8ARRAY_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_POINTER: { @@ -59689,7 +60839,7 @@ * Property lookup */ - lookup: +lookup: /* key (coerced) */ DUK_ASSERT(curr != NULL); DUK_ASSERT(key != NULL); @@ -59704,25 +60854,23 @@ /* accessor with defined getter */ DUK_ASSERT((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0); - duk_pop_unsafe(thr); /* key undefined -> key */ + duk_pop_unsafe(thr); /* key undefined -> key */ duk_push_hobject(thr, desc.get); - duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ + duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ #if defined(DUK_USE_NONSTD_GETTER_KEY_ARGUMENT) duk_dup_m3(thr); - duk_call_method(thr, 1); /* key getter this key -> key retval */ + duk_call_method(thr, 1); /* key getter this key -> key retval */ #else - duk_call_method(thr, 0); /* key getter this -> key retval */ + duk_call_method(thr, 0); /* key getter this -> key retval */ #endif } else { /* key value or key undefined */ /* data property or accessor without getter */ - DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || - (desc.get == NULL)); + DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || (desc.get == NULL)); /* if accessor without getter, return value is undefined */ - DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || - duk_is_undefined(thr, -1)); + DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || duk_is_undefined(thr, -1)); /* Note: for an accessor without getter, falling through to * check for "caller" exotic behavior is unnecessary as @@ -59731,9 +60879,9 @@ */ } - goto found; /* key result */ + goto found; /* key result */ - next_in_chain: + next_in_chain: /* XXX: option to pretend property doesn't exist if sanity limit is * hit might be useful. */ @@ -59748,7 +60896,7 @@ * Not found */ - duk_to_undefined(thr, -1); /* key -> undefined (default value) */ + duk_to_undefined(thr, -1); /* key -> undefined (default value) */ DUK_DDD(DUK_DDDPRINT("-> %!T (not found)", (duk_tval *) duk_get_tval(thr, -1))); return 0; @@ -59757,7 +60905,7 @@ * Found; post-processing (Function and arguments objects) */ - found: +found: /* key result */ #if !defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) @@ -59787,13 +60935,11 @@ * This exotic behavior is disabled when the non-standard 'caller' property * is enabled, as it conflicts with the free use of 'caller'. */ - if (key == DUK_HTHREAD_STRING_CALLER(thr) && - DUK_TVAL_IS_OBJECT(tv_obj)) { + if (key == DUK_HTHREAD_STRING_CALLER(thr) && DUK_TVAL_IS_OBJECT(tv_obj)) { duk_hobject *orig = DUK_TVAL_GET_OBJECT(tv_obj); DUK_ASSERT(orig != NULL); - if (DUK_HOBJECT_IS_NONBOUND_FUNCTION(orig) || - DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { + if (DUK_HOBJECT_IS_NONBOUND_FUNCTION(orig) || DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { duk_hobject *h; /* XXX: The TypeError is currently not applied to bound @@ -59804,19 +60950,17 @@ */ DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(orig)); - h = duk_get_hobject(thr, -1); /* NULL if not an object */ - if (h && - DUK_HOBJECT_IS_FUNCTION(h) && - DUK_HOBJECT_HAS_STRICT(h)) { + h = duk_get_hobject(thr, -1); /* NULL if not an object */ + if (h && DUK_HOBJECT_IS_FUNCTION(h) && DUK_HOBJECT_HAS_STRICT(h)) { /* XXX: sufficient to check 'strict', assert for 'is function' */ DUK_ERROR_TYPE(thr, DUK_STR_STRICT_CALLER_READ); DUK_WO_NORETURN(return 0;); } } } -#endif /* !DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ +#endif /* !DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ - duk_remove_m2(thr); /* key result -> result */ + duk_remove_m2(thr); /* key result -> result */ DUK_DDD(DUK_DDDPRINT("-> %!T (found)", (duk_tval *) duk_get_tval(thr, -1))); return 1; @@ -59838,8 +60982,11 @@ duk_propdesc desc; DUK_DDD(DUK_DDDPRINT("hasprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -59911,8 +61058,8 @@ if (duk__proxy_check_prop(thr, obj, DUK_STRIDX_HAS, tv_key, &h_target)) { /* ... key trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'has' for key %!T", (duk_tval *) tv_key)); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ duk_call_method(thr, 2 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { @@ -59920,39 +61067,42 @@ * non-configurable property. */ - if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push + value */ DUK_DDD(DUK_DDDPRINT("proxy 'has': target has matching property %!O, check for " "conflicting property; desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (duk_heaphdr *) key, + (unsigned long) desc.flags, + (void *) desc.get, + (void *) desc.set)); /* XXX: Extensibility check for target uses IsExtensible(). If we * implemented the isExtensible trap and didn't reject proxies as * proxy targets, it should be respected here. */ - if (!((desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && /* property is configurable and */ - DUK_HOBJECT_HAS_EXTENSIBLE(h_target))) { /* ... target is extensible */ + if (!((desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && /* property is configurable and */ + DUK_HOBJECT_HAS_EXTENSIBLE(h_target))) { /* ... target is extensible */ DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); } } } - duk_pop_unsafe(thr); /* key -> */ + duk_pop_unsafe(thr); /* key -> */ return tmp_bool; } - obj = h_target; /* resume check from proxy target */ + obj = h_target; /* resume check from proxy target */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* XXX: inline into a prototype walking loop? */ - rc = duk__get_propdesc(thr, obj, key, &desc, 0 /*flags*/); /* don't push value */ + rc = duk__get_propdesc(thr, obj, key, &desc, 0 /*flags*/); /* don't push value */ /* fall through */ - pop_and_return: - duk_pop_unsafe(thr); /* key -> */ +pop_and_return: + duk_pop_unsafe(thr); /* key -> */ return rc; } @@ -59978,7 +61128,7 @@ DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); - return duk__get_propdesc(thr, obj, key, &dummy, DUK_GETDESC_FLAG_IGNORE_PROTOLOOP); /* don't push value */ + return duk__get_propdesc(thr, obj, key, &dummy, DUK_GETDESC_FLAG_IGNORE_PROTOLOOP); /* don't push value */ } /* @@ -60010,16 +61160,16 @@ } return (duk_uint32_t) fi; } -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ /* When fastints are not enabled, the most interesting case is any * number. */ if (DUK_TVAL_IS_DOUBLE(tv)) { d = DUK_TVAL_GET_NUMBER(tv); } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ else -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ { /* In all other cases, and when doing a size optimized build, * fall back to the comprehensive handler. @@ -60037,7 +61187,7 @@ return res; - fail_range: +fail_range: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARRAY_LENGTH); DUK_WO_NORETURN(return 0;); } @@ -60065,7 +61215,8 @@ DUK_DDD(DUK_DDDPRINT("new array length smaller than old (%ld -> %ld), " "probably need to remove elements", - (long) old_len, (long) new_len)); + (long) old_len, + (long) new_len)); /* * New length is smaller than old length, need to delete properties above @@ -60111,7 +61262,7 @@ while (i > new_len) { i--; tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, i); - DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ } *out_result_len = new_len; @@ -60146,19 +61297,22 @@ continue; } - DUK_ASSERT(DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ + DUK_ASSERT( + DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); - DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ + DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ if (arr_idx < new_len) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is array index %ld, below new_len", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } if (DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is a relevant array index %ld, but configurable", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } @@ -60166,17 +61320,19 @@ if (arr_idx >= target_len) { DUK_DDD(DUK_DDDPRINT("entry at index %ld has arr_idx %ld, is not configurable, " "update target_len %ld -> %ld", - (long) i, (long) arr_idx, (long) target_len, + (long) i, + (long) arr_idx, + (long) target_len, (long) (arr_idx + 1))); target_len = arr_idx + 1; } } - skip_stage1: + skip_stage1: /* stage 2: delete configurable entries above target length */ - DUK_DDD(DUK_DDDPRINT("old_len=%ld, new_len=%ld, target_len=%ld", - (long) old_len, (long) new_len, (long) target_len)); + DUK_DDD( + DUK_DDDPRINT("old_len=%ld, new_len=%ld, target_len=%ld", (long) old_len, (long) new_len, (long) target_len)); DUK_DDD(DUK_DDDPRINT("array length write, no array part, stage 2: remove " "entries >= target_len")); @@ -60192,20 +61348,21 @@ continue; } - DUK_ASSERT(DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ + DUK_ASSERT( + DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); - DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ + DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ if (arr_idx < target_len) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is array index %ld, below target_len", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } - DUK_ASSERT(force_flag || DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)); /* stage 1 guarantees */ + DUK_ASSERT(force_flag || DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)); /* stage 1 guarantees */ - DUK_DDD(DUK_DDDPRINT("delete entry index %ld: key is array index %ld", - (long) i, (long) arr_idx)); + DUK_DDD(DUK_DDDPRINT("delete entry index %ld: key is array index %ld", (long) i, (long) arr_idx)); /* * Slow delete, but we don't care as we're already in a very slow path. @@ -60336,11 +61493,12 @@ * (We currently make a copy of all of the input values to avoid issues.) */ -DUK_INTERNAL duk_bool_t duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag) { +DUK_INTERNAL duk_bool_t +duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag) { duk_tval tv_obj_copy; duk_tval tv_key_copy; duk_tval tv_val_copy; - duk_hobject *orig = NULL; /* NULL if tv_obj is primitive */ + duk_hobject *orig = NULL; /* NULL if tv_obj is primitive */ duk_hobject *curr; duk_hstring *key = NULL; duk_propdesc desc; @@ -60349,12 +61507,18 @@ duk_bool_t rc; duk_int_t e_idx; duk_uint_t sanity; - duk_uint32_t new_array_length = 0; /* 0 = no update */ + duk_uint32_t new_array_length = 0; /* 0 = no update */ DUK_DDD(DUK_DDDPRINT("putprop: thr=%p, obj=%p, key=%p, val=%p, throw=%ld " "(obj -> %!T, key -> %!T, val -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, (void *) tv_val, - (long) throw_flag, (duk_tval *) tv_obj, (duk_tval *) tv_key, (duk_tval *) tv_val)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (void *) tv_val, + (long) throw_flag, + (duk_tval *) tv_obj, + (duk_tval *) tv_key, + (duk_tval *) tv_val)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -60389,13 +61553,15 @@ case DUK_TAG_UNDEFINED: case DUK_TAG_NULL: { /* Note: unconditional throw */ - DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject (object=%!iT)", - (duk_tval *) tv_obj)); + DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject (object=%!iT)", (duk_tval *) tv_obj)); #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot write property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot write property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); break; @@ -60429,14 +61595,13 @@ goto fail_not_writable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { goto fail_not_writable; } DUK_DDD(DUK_DDDPRINT("base object is a string, start lookup from string prototype")); curr = thr->builtinsDUK_BIDX_STRING_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_OBJECT: { @@ -60451,7 +61616,7 @@ */ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) orig)) { DUK_DD(DUK_DDPRINT("attempt to putprop on read-only target object")); - goto fail_not_writable_no_pop; /* Must avoid duk_pop() in exit path */ + goto fail_not_writable_no_pop; /* Must avoid duk_pop() in exit path */ } #endif @@ -60497,10 +61662,10 @@ /* -> ... trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'set' for key %!T", (duk_tval *) tv_key)); DUK_STATS_INC(thr->heap, stats_putprop_proxy); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ - duk_push_tval(thr, tv_val); /* V */ - duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ + duk_push_tval(thr, tv_val); /* V */ + duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ duk_call_method(thr, 4 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { @@ -60521,17 +61686,19 @@ DUK_DDD(DUK_DDDPRINT("proxy 'set': target has matching property %!O, check for " "conflicting property; tv_val=%!T, tv_targ=%!T, desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (duk_tval *) tv_val, (duk_tval *) tv_targ, + (duk_heaphdr *) key, + (duk_tval *) tv_val, + (duk_tval *) tv_targ, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (void *) desc.get, + (void *) desc.set)); datadesc_reject = !(desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && !(desc.flags & DUK_PROPDESC_FLAG_WRITABLE) && !duk_js_samevalue(tv_val, tv_targ); accdesc_reject = (desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && - !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && - (desc.set == NULL); + !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && (desc.set == NULL); if (datadesc_reject || accdesc_reject) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); @@ -60541,13 +61708,13 @@ } else { duk_pop_unsafe(thr); } - return 1; /* success */ + return 1; /* success */ } - orig = h_target; /* resume write to target */ + orig = h_target; /* resume write to target */ DUK_TVAL_SET_OBJECT(tv_obj, orig); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ curr = orig; break; @@ -60569,7 +61736,7 @@ pop_count = 0; } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -60578,12 +61745,12 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { duk_uint8_t *data; DUK_DDD(DUK_DDDPRINT("writing to buffer data at index %ld", (long) arr_idx)); data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); @@ -60595,8 +61762,7 @@ /* Buffer writes are often integers. */ if (DUK_TVAL_IS_FASTINT(tv_val)) { dataarr_idx = (duk_uint8_t) DUK_TVAL_GET_FASTINT_U32(tv_val); - } - else + } else #endif { duk_push_tval(thr, tv_val); @@ -60618,7 +61784,8 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { @@ -60627,7 +61794,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a buffer, start lookup from Uint8Array prototype")); curr = thr->builtinsDUK_BIDX_UINT8ARRAY_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_POINTER: { @@ -60662,7 +61829,7 @@ arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); DUK_ASSERT(key != NULL); - lookup: +lookup: /* * Check whether the property already exists in the prototype chain. @@ -60675,7 +61842,7 @@ DUK_ASSERT(curr != NULL); sanity = DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY; do { - if (!duk__get_own_propdesc_raw(thr, curr, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (!duk__get_own_propdesc_raw(thr, curr, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ goto next_in_chain; } @@ -60698,15 +61865,15 @@ goto fail_no_setter; } duk_push_hobject(thr, setter); - duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ - duk_push_tval(thr, tv_val); /* key setter this val */ + duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ + duk_push_tval(thr, tv_val); /* key setter this val */ #if defined(DUK_USE_NONSTD_SETTER_KEY_ARGUMENT) duk_dup_m4(thr); - duk_call_method(thr, 2); /* key setter this val key -> key retval */ + duk_call_method(thr, 2); /* key setter this val key -> key retval */ #else - duk_call_method(thr, 1); /* key setter this val -> key retval */ + duk_call_method(thr, 1); /* key setter this val -> key retval */ #endif - duk_pop_unsafe(thr); /* ignore retval -> key */ + duk_pop_unsafe(thr); /* ignore retval -> key */ goto success_no_arguments_exotic; } @@ -60726,11 +61893,13 @@ * new property to 'orig'. */ if (!DUK_HOBJECT_HAS_EXTENSIBLE(orig)) { - DUK_DD(DUK_DDPRINT("found existing inherited plain property, but original object is not extensible")); + DUK_DD( + DUK_DDPRINT("found existing inherited plain property, but original object is not extensible")); goto fail_not_extensible; } if (!(desc.flags & DUK_PROPDESC_FLAG_WRITABLE)) { - DUK_DD(DUK_DDPRINT("found existing inherited plain property, original object is extensible, but inherited property is not writable")); + DUK_DD(DUK_DDPRINT("found existing inherited plain property, original object is extensible, but " + "inherited property is not writable")); goto fail_not_writable; } DUK_DD(DUK_DDPRINT("put to new property, object extensible, inherited property found and is writable")); @@ -60742,7 +61911,8 @@ */ if (!(desc.flags & DUK_PROPDESC_FLAG_WRITABLE)) { - DUK_DD(DUK_DDPRINT("found existing own (non-inherited) plain property, but property is not writable")); + DUK_DD( + DUK_DDPRINT("found existing own (non-inherited) plain property, but property is not writable")); goto fail_not_writable; } if (desc.flags & DUK_PROPDESC_FLAG_VIRTUAL) { @@ -60759,18 +61929,19 @@ * Note: the helper has an unnecessary writability check * for 'length', we already know it is writable. */ - DUK_ASSERT(key == DUK_HTHREAD_STRING_LENGTH(thr)); /* only virtual array property */ + DUK_ASSERT(key == DUK_HTHREAD_STRING_LENGTH(thr)); /* only virtual array property */ - DUK_DDD(DUK_DDDPRINT("writing existing 'length' property to array exotic, invoke complex helper")); + DUK_DDD(DUK_DDDPRINT( + "writing existing 'length' property to array exotic, invoke complex helper")); /* XXX: the helper currently assumes stack top contains new * 'length' value and the whole calling convention is not very * compatible with what we need. */ - duk_push_tval(thr, tv_val); /* key val */ + duk_push_tval(thr, tv_val); /* key val */ rc = duk__handle_put_array_length(thr, orig); - duk_pop_unsafe(thr); /* key val -> key */ + duk_pop_unsafe(thr); /* key val -> key */ if (!rc) { goto fail_array_length_partial; } @@ -60792,12 +61963,14 @@ /* Careful with wrapping: arr_idx upshift may easily wrap, whereas * length downshift won't. */ - if (arr_idx < (h_bufobj->length >> h_bufobj->shift) && DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { + if (arr_idx < (h_bufobj->length >> h_bufobj->shift) && + DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { duk_uint8_t *data; DUK_DDD(DUK_DDDPRINT("writing to buffer data at index %ld", (long) arr_idx)); - DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); /* index/length check guarantees */ - byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); /* index/length check guarantees */ + byte_off = arr_idx + << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); /* Coerce to number before validating pointers etc so that the @@ -60808,27 +61981,30 @@ duk_push_tval(thr, tv_val); (void) duk_to_number_m1(thr); - if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { - data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + h_bufobj->offset + byte_off; + if (h_bufobj->buf != NULL && + DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { + data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + + h_bufobj->offset + byte_off; duk_hbufobj_validated_write(thr, h_bufobj, data, elem_size); } else { - DUK_D(DUK_DPRINT("bufobj access out of underlying buffer, ignoring (write skipped)")); + DUK_D(DUK_DPRINT( + "bufobj access out of underlying buffer, ignoring (write skipped)")); } duk_pop_unsafe(thr); goto success_no_arguments_exotic; } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_D(DUK_DPRINT("should not happen, key %!O", key)); - goto fail_internal; /* should not happen */ + goto fail_internal; /* should not happen */ } DUK_DD(DUK_DDPRINT("put to existing own plain property, property is writable")); goto update_old; } DUK_UNREACHABLE(); - next_in_chain: + next_in_chain: /* XXX: option to pretend property doesn't exist if sanity limit is * hit might be useful. */ @@ -60857,7 +62033,7 @@ goto create_new; - update_old: +update_old: /* * Update an existing property of the base object. @@ -60890,10 +62066,9 @@ if (desc.e_idx >= 0) { tv = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, orig, desc.e_idx); DUK_DDD(DUK_DDDPRINT("previous entry value: %!iT", (duk_tval *) tv)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; e_idx may be invalidated */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; e_idx may be invalidated */ /* don't touch property attributes or hash part */ - DUK_DD(DUK_DDPRINT("put to an existing entry at index %ld -> new value %!iT", - (long) desc.e_idx, (duk_tval *) tv)); + DUK_DD(DUK_DDPRINT("put to an existing entry at index %ld -> new value %!iT", (long) desc.e_idx, (duk_tval *) tv)); } else { /* Note: array entries are always writable, so the writability check * above is pointless for them. The check could be avoided with some @@ -60903,9 +62078,10 @@ DUK_ASSERT(desc.a_idx >= 0); tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, orig, desc.a_idx); DUK_DDD(DUK_DDDPRINT("previous array value: %!iT", (duk_tval *) tv)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; a_idx may be invalidated */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; a_idx may be invalidated */ DUK_DD(DUK_DDPRINT("put to an existing array entry at index %ld -> new value %!iT", - (long) desc.a_idx, (duk_tval *) tv)); + (long) desc.a_idx, + (duk_tval *) tv)); } /* Regardless of whether property is found in entry or array part, @@ -60914,7 +62090,7 @@ */ goto success_with_arguments_exotic; - create_new: +create_new: /* * Create a new property in the original object. @@ -60947,11 +62123,9 @@ * from its creation and cannot be deleted, and is thus * caught as an existing property above. */ - DUK_ASSERT(!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && - key == DUK_HTHREAD_STRING_LENGTH(thr))); + DUK_ASSERT(!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && key == DUK_HTHREAD_STRING_LENGTH(thr))); - if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && - arr_idx != DUK__NO_ARRAY_INDEX) { + if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && arr_idx != DUK__NO_ARRAY_INDEX) { /* automatic length update */ duk_uint32_t old_len; duk_harray *a; @@ -60964,7 +62138,8 @@ if (arr_idx >= old_len) { DUK_DDD(DUK_DDDPRINT("write new array entry requires length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a)) { DUK_DD(DUK_DDPRINT("attempt to extend array, but array 'length' is not writable")); @@ -60978,15 +62153,16 @@ */ DUK_ASSERT(arr_idx != 0xffffffffUL); - new_array_length = arr_idx + 1; /* flag for later write */ + new_array_length = arr_idx + 1; /* flag for later write */ } else { DUK_DDD(DUK_DDDPRINT("write new array entry does not require length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); } } - /* write_to_array_part: */ + /* write_to_array_part: */ /* * Write to array part? @@ -61008,8 +62184,7 @@ DUK_ASSERT(DUK_TVAL_IS_UNUSED(tv)); DUK_TVAL_SET_TVAL(tv, tv_val); DUK_TVAL_INCREF(thr, tv); - DUK_DD(DUK_DDPRINT("put to new array entry: %ld -> %!T", - (long) arr_idx, (duk_tval *) tv)); + DUK_DD(DUK_DDPRINT("put to new array entry: %ld -> %!T", (long) arr_idx, (duk_tval *) tv)); /* Note: array part values are Writable, Enumerable, * and Configurable which matches the required attributes @@ -61018,7 +62193,7 @@ goto entry_updated; } - write_to_entry_part: +write_to_entry_part: /* * Write to entry part @@ -61038,7 +62213,7 @@ DUK_HOBJECT_E_SET_FLAGS(thr->heap, orig, e_idx, DUK_PROPDESC_FLAGS_WEC); goto entry_updated; - entry_updated: +entry_updated: /* * Possible pending array length update, which must only be done @@ -61052,8 +62227,7 @@ DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig)); - DUK_DDD(DUK_DDDPRINT("write successful, pending array length update to: %ld", - (long) new_array_length)); + DUK_DDD(DUK_DDDPRINT("write successful, pending array length update to: %ld", (long) new_array_length)); ((duk_harray *) orig)->length = new_array_length; } @@ -61067,7 +62241,7 @@ goto success_no_arguments_exotic; - success_with_arguments_exotic: +success_with_arguments_exotic: /* * Arguments objects have exotic DefineOwnProperty which updates @@ -61082,8 +62256,7 @@ * we end up in step 5.b.i. */ - if (arr_idx != DUK__NO_ARRAY_INDEX && - DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { /* Note: only numbered indices are relevant, so arr_idx fast reject * is good (this is valid unless there are more than 4**32-1 arguments). */ @@ -61102,14 +62275,14 @@ } /* fall thru */ - success_no_arguments_exotic: +success_no_arguments_exotic: /* shared exit path now */ DUK_DDD(DUK_DDDPRINT("result: success")); - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 1; #if defined(DUK_USE_ES6_PROXY) - fail_proxy_rejected: +fail_proxy_rejected: DUK_DDD(DUK_DDDPRINT("result: error, proxy rejects")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); @@ -61119,40 +62292,43 @@ return 0; #endif - fail_base_primitive: +fail_base_primitive: DUK_DDD(DUK_DDDPRINT("result: error, base primitive")); if (throw_flag) { #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot write property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot write property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_not_extensible: +fail_not_extensible: DUK_DDD(DUK_DDDPRINT("result: error, not extensible")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_EXTENSIBLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_not_writable: +fail_not_writable: DUK_DDD(DUK_DDDPRINT("result: error, not writable")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_WRITABLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; #if defined(DUK_USE_ROM_OBJECTS) - fail_not_writable_no_pop: +fail_not_writable_no_pop: DUK_DDD(DUK_DDDPRINT("result: error, not writable")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_WRITABLE); @@ -61161,31 +62337,31 @@ return 0; #endif - fail_array_length_partial: +fail_array_length_partial: DUK_DD(DUK_DDPRINT("result: error, array length write only partially successful")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_no_setter: +fail_no_setter: DUK_DDD(DUK_DDDPRINT("result: error, accessor property without setter")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_SETTER_UNDEFINED); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_internal: +fail_internal: DUK_DDD(DUK_DDDPRINT("result: error, internal")); if (throw_flag) { DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; } @@ -61204,8 +62380,13 @@ force_flag = (flags & DUK_DELPROP_FLAG_FORCE); DUK_DDD(DUK_DDDPRINT("delprop_raw: thr=%p, obj=%p, key=%p, throw=%ld, force=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (long) throw_flag, (long) force_flag, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (long) throw_flag, + (long) force_flag, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -61217,7 +62398,7 @@ arr_idx = DUK_HSTRING_GET_ARRIDX_FAST(key); /* 0 = don't push current value */ - if (!duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (!duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ DUK_DDD(DUK_DDDPRINT("property not found, succeed always")); goto success; } @@ -61244,7 +62425,7 @@ DUK_ASSERT(desc.e_idx < 0); tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, desc.a_idx); - DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ goto success; } else { DUK_ASSERT(desc.a_idx < 0); @@ -61270,7 +62451,9 @@ * invalidated. */ DUK_DDD(DUK_DDDPRINT("before removing value, e_idx %ld, key %p, key at slot %p", - (long) desc.e_idx, (void *) key, (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); + (long) desc.e_idx, + (void *) key, + (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); DUK_DDD(DUK_DDDPRINT("removing value at e_idx %ld", (long) desc.e_idx)); if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, desc.e_idx)) { duk_hobject *tmp; @@ -61295,7 +62478,9 @@ /* Remove key. */ DUK_DDD(DUK_DDDPRINT("before removing key, e_idx %ld, key %p, key at slot %p", - (long) desc.e_idx, (void *) key, (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); + (long) desc.e_idx, + (void *) key, + (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); DUK_DDD(DUK_DDDPRINT("removing key at e_idx %ld", (long) desc.e_idx)); DUK_ASSERT(key == DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx)); DUK_HOBJECT_E_SET_KEY(thr->heap, obj, desc.e_idx, NULL); @@ -61311,7 +62496,7 @@ DUK_UNREACHABLE(); - success: +success: /* * Argument exotic Delete behavior (E5 Section 10.6) is * a post-check, keeping arguments internal 'map' in sync with @@ -61338,8 +62523,8 @@ DUK_DDD(DUK_DDDPRINT("delete successful")); return 1; - fail_virtual: /* just use the same "not configurable" error message */ - fail_not_configurable: +fail_virtual: /* just use the same "not configurable" error message */ +fail_not_configurable: DUK_DDD(DUK_DDDPRINT("delete failed: property found, not configurable")); if (throw_flag) { @@ -61363,8 +62548,11 @@ duk_bool_t rc; DUK_DDD(DUK_DDDPRINT("delprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -61378,8 +62566,7 @@ */ entry_top = duk_get_top(thr); - if (DUK_TVAL_IS_UNDEFINED(tv_obj) || - DUK_TVAL_IS_NULL(tv_obj)) { + if (DUK_TVAL_IS_UNDEFINED(tv_obj) || DUK_TVAL_IS_NULL(tv_obj)) { DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject")); goto fail_invalid_base_uncond; } @@ -61402,12 +62589,12 @@ if (duk__proxy_check_prop(thr, obj, DUK_STRIDX_DELETE_PROPERTY, tv_key, &h_target)) { /* -> ... obj key trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'deleteProperty' for key %!T", (duk_tval *) tv_key)); - duk_push_hobject(thr, h_target); /* target */ - duk_dup_m4(thr); /* P */ + duk_push_hobject(thr, h_target); /* target */ + duk_dup_m4(thr); /* P */ duk_call_method(thr, 2 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { - goto fail_proxy_rejected; /* retval indicates delete failed */ + goto fail_proxy_rejected; /* retval indicates delete failed */ } /* Target object must be checked for a conflicting @@ -61417,14 +62604,17 @@ arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); DUK_ASSERT(key != NULL); - if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push + value */ duk_small_int_t desc_reject; DUK_DDD(DUK_DDDPRINT("proxy 'deleteProperty': target has matching property %!O, check for " "conflicting property; desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (duk_heaphdr *) key, + (unsigned long) desc.flags, + (void *) desc.get, + (void *) desc.set)); desc_reject = !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE); if (desc_reject) { @@ -61433,13 +62623,13 @@ DUK_WO_NORETURN(return 0;); } } - rc = 1; /* success */ + rc = 1; /* success */ goto done_rc; } - obj = h_target; /* resume delete to target */ + obj = h_target; /* resume delete to target */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ arr_idx = duk__to_property_key(thr, -1, &key); DUK_ASSERT(key != NULL); @@ -61464,8 +62654,7 @@ goto fail_not_configurable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { goto fail_not_configurable; } } else if (DUK_TVAL_IS_BUFFER(tv_obj)) { @@ -61483,8 +62672,7 @@ goto fail_not_configurable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { goto fail_not_configurable; } } else if (DUK_TVAL_IS_LIGHTFUNC(tv_obj)) { @@ -61501,23 +62689,26 @@ rc = 1; goto done_rc; - done_rc: +done_rc: duk_set_top_unsafe(thr, entry_top); return rc; - fail_invalid_base_uncond: +fail_invalid_base_uncond: /* Note: unconditional throw */ DUK_ASSERT(duk_get_top(thr) == entry_top); #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot delete property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot delete property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); #if defined(DUK_USE_ES6_PROXY) - fail_proxy_rejected: +fail_proxy_rejected: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); @@ -61526,7 +62717,7 @@ return 0; #endif - fail_not_configurable: +fail_not_configurable: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); @@ -61554,17 +62745,23 @@ * operations. */ -DUK_INTERNAL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags) { +DUK_INTERNAL void duk_hobject_define_property_internal(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_small_uint_t flags) { duk_propdesc desc; duk_uint32_t arr_idx; duk_int_t e_idx; duk_tval *tv1 = NULL; duk_tval *tv2 = NULL; - duk_small_uint_t propflags = flags & DUK_PROPDESC_FLAGS_MASK; /* mask out flags not actually stored */ + duk_small_uint_t propflags = flags & DUK_PROPDESC_FLAGS_MASK; /* mask out flags not actually stored */ DUK_DDD(DUK_DDDPRINT("define new property (internal): thr=%p, obj=%!O, key=%!O, flags=0x%02lx, val=%!T", - (void *) thr, (duk_heaphdr *) obj, (duk_heaphdr *) key, - (unsigned long) flags, (duk_tval *) duk_get_tval(thr, -1))); + (void *) thr, + (duk_heaphdr *) obj, + (duk_heaphdr *) key, + (unsigned long) flags, + (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -61572,11 +62769,11 @@ DUK_ASSERT(key != NULL); DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); - DUK_ASSERT(duk_is_valid_index(thr, -1)); /* contains value */ + DUK_ASSERT(duk_is_valid_index(thr, -1)); /* contains value */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); - if (duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ if (desc.e_idx >= 0) { if (flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) { DUK_DDD(DUK_DDDPRINT("property already exists in the entry part -> skip as requested")); @@ -61617,7 +62814,8 @@ new_len = duk__to_new_array_length_checked(thr, DUK_GET_TVAL_NEGIDX(thr, -1)); ((duk_harray *) obj)->length = new_len; DUK_DD(DUK_DDPRINT("internal define property for array .length: %ld -> %ld", - (long) prev_len, (long) ((duk_harray *) obj)->length)); + (long) prev_len, + (long) ((duk_harray *) obj)->length)); goto pop_exit; } DUK_DD(DUK_DDPRINT("property already exists but is virtual -> failure")); @@ -61629,7 +62827,8 @@ if (DUK_HOBJECT_HAS_ARRAY_PART(obj)) { if (arr_idx != DUK__NO_ARRAY_INDEX) { - DUK_DDD(DUK_DDDPRINT("property does not exist, object has array part -> possibly extend array part and write value (assert attributes)")); + DUK_DDD(DUK_DDDPRINT("property does not exist, object has array part -> possibly extend array part and " + "write value (assert attributes)")); DUK_ASSERT(propflags == DUK_PROPDESC_FLAGS_WEC); tv1 = duk__obtain_arridx_slot(thr, arr_idx, obj); @@ -61643,9 +62842,10 @@ } } - write_to_entry_part: - DUK_DDD(DUK_DDDPRINT("property does not exist, object belongs in entry part -> allocate new entry and write value and attributes")); - e_idx = duk__hobject_alloc_entry_checked(thr, obj, key); /* increases key refcount */ +write_to_entry_part: + DUK_DDD(DUK_DDDPRINT( + "property does not exist, object belongs in entry part -> allocate new entry and write value and attributes")); + e_idx = duk__hobject_alloc_entry_checked(thr, obj, key); /* increases key refcount */ DUK_ASSERT(e_idx >= 0); DUK_HOBJECT_E_SET_FLAGS(thr->heap, obj, e_idx, propflags); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, e_idx); @@ -61653,22 +62853,21 @@ DUK_TVAL_SET_UNDEFINED(tv1); goto write_value; - write_value: +write_value: /* tv1 points to value storage */ - tv2 = duk_require_tval(thr, -1); /* late lookup, avoid side effects */ - DUK_DDD(DUK_DDDPRINT("writing/updating value: %!T -> %!T", - (duk_tval *) tv1, (duk_tval *) tv2)); + tv2 = duk_require_tval(thr, -1); /* late lookup, avoid side effects */ + DUK_DDD(DUK_DDDPRINT("writing/updating value: %!T -> %!T", (duk_tval *) tv1, (duk_tval *) tv2)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ goto pop_exit; - pop_exit: - duk_pop_unsafe(thr); /* remove in_val */ +pop_exit: + duk_pop_unsafe(thr); /* remove in_val */ return; - error_virtual: /* share error message */ - error_internal: +error_virtual: /* share error message */ +error_internal: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); } @@ -61679,13 +62878,19 @@ * must avoid interning. */ -DUK_INTERNAL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, duk_hobject *obj, duk_uarridx_t arr_idx, duk_small_uint_t flags) { +DUK_INTERNAL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, + duk_hobject *obj, + duk_uarridx_t arr_idx, + duk_small_uint_t flags) { duk_hstring *key; duk_tval *tv1, *tv2; DUK_DDD(DUK_DDDPRINT("define new property (internal) arr_idx fast path: thr=%p, obj=%!O, " "arr_idx=%ld, flags=0x%02lx, val=%!T", - (void *) thr, obj, (long) arr_idx, (unsigned long) flags, + (void *) thr, + obj, + (long) arr_idx, + (unsigned long) flags, (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(thr != NULL); @@ -61693,10 +62898,8 @@ DUK_ASSERT(obj != NULL); DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); - if (DUK_HOBJECT_HAS_ARRAY_PART(obj) && - arr_idx != DUK__NO_ARRAY_INDEX && - flags == DUK_PROPDESC_FLAGS_WEC) { - DUK_ASSERT((flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) == 0); /* covered by comparison */ + if (DUK_HOBJECT_HAS_ARRAY_PART(obj) && arr_idx != DUK__NO_ARRAY_INDEX && flags == DUK_PROPDESC_FLAGS_WEC) { + DUK_ASSERT((flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) == 0); /* covered by comparison */ DUK_DDD(DUK_DDDPRINT("define property to array part (property may or may not exist yet)")); @@ -61707,22 +62910,22 @@ } tv2 = duk_require_tval(thr, -1); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ - duk_pop_unsafe(thr); /* ...val -> ... */ + duk_pop_unsafe(thr); /* ...val -> ... */ return; } - write_slow: +write_slow: DUK_DDD(DUK_DDDPRINT("define property fast path didn't work, use slow path")); key = duk_push_uint_to_hstring(thr, (duk_uint_t) arr_idx); DUK_ASSERT(key != NULL); - duk_insert(thr, -2); /* ... val key -> ... key val */ + duk_insert(thr, -2); /* ... val key -> ... key val */ duk_hobject_define_property_internal(thr, obj, key, flags); - duk_pop_unsafe(thr); /* ... key -> ... */ + duk_pop_unsafe(thr); /* ... key -> ... */ } /* @@ -61743,9 +62946,7 @@ /* Slow path, .length can be e.g. accessor, obj can be a Proxy, etc. */ duk_push_hobject(thr, obj); duk_push_hstring_stridx(thr, DUK_STRIDX_LENGTH); - (void) duk_hobject_getprop(thr, - DUK_GET_TVAL_NEGIDX(thr, -2), - DUK_GET_TVAL_NEGIDX(thr, -1)); + (void) duk_hobject_getprop(thr, DUK_GET_TVAL_NEGIDX(thr, -2), DUK_GET_TVAL_NEGIDX(thr, -1)); val = duk_to_number_m1(thr); duk_pop_3_unsafe(thr); @@ -61786,7 +62987,7 @@ DUK_ASSERT(heap != NULL); obj = DUK_HOBJECT_GET_PROTOTYPE(heap, obj); #else - obj = DUK_HOBJECT_GET_PROTOTYPE(NULL, obj); /* 'heap' arg ignored */ + obj = DUK_HOBJECT_GET_PROTOTYPE(NULL, obj); /* 'heap' arg ignored */ #endif } while (obj != NULL); @@ -61853,7 +63054,7 @@ /* ... key value desc */ duk_replace(thr, -3); - duk_pop_unsafe(thr); /* -> ... desc */ + duk_pop_unsafe(thr); /* -> ... desc */ } /* @@ -61890,7 +63091,7 @@ DUK_ASSERT(out_idx_value != NULL); DUK_ASSERT(out_getter != NULL); DUK_ASSERT(out_setter != NULL); - DUK_ASSERT(idx_in <= 0x7fffL); /* short variants would be OK, but not used to avoid shifts */ + DUK_ASSERT(idx_in <= 0x7fffL); /* short variants would be OK, but not used to avoid shifts */ /* Must be an object, otherwise TypeError (E5.1 Section 8.10.5, step 1). */ idx_in = duk_require_normalize_index(thr, idx_in); @@ -61946,7 +63147,7 @@ if (DUK_TVAL_IS_UNDEFINED(tv)) { /* undefined is accepted */ DUK_ASSERT(setter == NULL); - } else { + } else { /* NOTE: lightfuncs are coerced to full functions because * lightfuncs don't fit into a property value slot. This * has some side effects, see test-dev-lightfunc-accessor.js. @@ -61989,7 +63190,7 @@ /* ... multiple values */ return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_DESCRIPTOR); DUK_WO_NORETURN(return;); } @@ -62037,7 +63238,7 @@ duk_bool_t force_flag; duk_small_uint_t new_flags; duk_propdesc curr; - duk_uint32_t arridx_new_array_length; /* != 0 => post-update for array 'length' (used when key is an array index) */ + duk_uint32_t arridx_new_array_length; /* != 0 => post-update for array 'length' (used when key is an array index) */ duk_uint32_t arrlen_old_len; duk_uint32_t arrlen_new_len; duk_bool_t pending_write_protect; @@ -62077,13 +63278,22 @@ "has_get=%ld get=%p=%!O " "has_set=%ld set=%p=%!O " "arr_idx=%ld throw_flag=!%ld", - (long) has_enumerable, (long) is_enumerable, - (long) has_configurable, (long) is_configurable, - (long) has_writable, (long) is_writable, - (long) has_value, (duk_tval *) (idx_value >= 0 ? duk_get_tval(thr, idx_value) : NULL), - (long) has_get, (void *) get, (duk_heaphdr *) get, - (long) has_set, (void *) set, (duk_heaphdr *) set, - (long) arr_idx, (long) throw_flag)); + (long) has_enumerable, + (long) is_enumerable, + (long) has_configurable, + (long) is_configurable, + (long) has_writable, + (long) is_writable, + (long) has_value, + (duk_tval *) (idx_value >= 0 ? duk_get_tval(thr, idx_value) : NULL), + (long) has_get, + (void *) get, + (duk_heaphdr *) get, + (long) has_set, + (void *) set, + (duk_heaphdr *) set, + (long) arr_idx, + (long) throw_flag)); /* * Array exotic behaviors can be implemented at this point. The local variables @@ -62117,7 +63327,7 @@ DUK_ASSERT(idx_value >= 0); arrlen_new_len = duk__to_new_array_length_checked(thr, DUK_GET_TVAL_POSIDX(thr, idx_value)); duk_push_u32(thr, arrlen_new_len); - duk_replace(thr, idx_value); /* step 3.e: replace 'Desc.Value' */ + duk_replace(thr, idx_value); /* step 3.e: replace 'Desc.Value' */ DUK_DDD(DUK_DDDPRINT("old_len=%ld, new_len=%ld", (long) arrlen_old_len, (long) arrlen_new_len)); @@ -62159,7 +63369,8 @@ if (arr_idx >= old_len) { DUK_DDD(DUK_DDDPRINT("defineProperty requires array length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a) && !force_flag) { /* Array .length is always non-configurable, so @@ -62177,10 +63388,11 @@ } else { DUK_DDD(DUK_DDDPRINT("defineProperty does not require length update " "(arr_idx=%ld, old_len=%ld) -> standard behavior", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); } } - skip_array_exotic: +skip_array_exotic: /* XXX: There is currently no support for writing buffer object * indexed elements here. Attempt to do so will succeed and @@ -62232,7 +63444,7 @@ DUK_ASSERT(!has_value); DUK_ASSERT(!has_writable); - new_flags = DUK_PROPDESC_FLAG_ACCESSOR; /* defaults, E5 Section 8.6.1, Table 7 */ + new_flags = DUK_PROPDESC_FLAG_ACCESSOR; /* defaults, E5 Section 8.6.1, Table 7 */ if (has_enumerable && is_enumerable) { new_flags |= DUK_PROPDESC_FLAG_ENUMERABLE; } @@ -62265,7 +63477,7 @@ DUK_ASSERT(!has_set); DUK_ASSERT(!has_get); - new_flags = 0; /* defaults, E5 Section 8.6.1, Table 7 */ + new_flags = 0; /* defaults, E5 Section 8.6.1, Table 7 */ if (has_writable && is_writable) { new_flags |= DUK_PROPDESC_FLAG_WRITABLE; } @@ -62279,12 +63491,13 @@ duk_tval *tv_tmp = duk_require_tval(thr, idx_value); DUK_TVAL_SET_TVAL(&tv, tv_tmp); } else { - DUK_TVAL_SET_UNDEFINED(&tv); /* default value */ + DUK_TVAL_SET_UNDEFINED(&tv); /* default value */ } if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HOBJECT_HAS_ARRAY_PART(obj)) { if (new_flags == DUK_PROPDESC_FLAGS_WEC) { - DUK_DDD(DUK_DDDPRINT("new data property attributes match array defaults, attempt to write to array part")); + DUK_DDD(DUK_DDDPRINT( + "new data property attributes match array defaults, attempt to write to array part")); tv2 = duk__obtain_arridx_slot(thr, arr_idx, obj); if (tv2 == NULL) { DUK_DDD(DUK_DDDPRINT("failed writing to array part, abandoned array")); @@ -62357,8 +63570,8 @@ goto need_check; } - tmp1 = duk_require_tval(thr, -1); /* curr value */ - tmp2 = duk_require_tval(thr, idx_value); /* new value */ + tmp1 = duk_require_tval(thr, -1); /* curr value */ + tmp2 = duk_require_tval(thr, idx_value); /* new value */ if (!duk_js_samevalue(tmp1, tmp2)) { goto need_check; } @@ -62403,7 +63616,7 @@ */ goto success_no_exotics; - need_check: +need_check: /* * Some change(s) need to be made. Steps 7-11. @@ -62475,9 +63688,10 @@ DUK_DDD(DUK_DDDPRINT("convert property to accessor property")); if (curr.a_idx >= 0) { - DUK_DDD(DUK_DDDPRINT("property to convert is stored in an array entry, abandon array and re-lookup")); + DUK_DDD( + DUK_DDDPRINT("property to convert is stored in an array entry, abandon array and re-lookup")); duk__abandon_array_part(thr, obj); - duk_pop_unsafe(thr); /* remove old value */ + duk_pop_unsafe(thr); /* remove old value */ rc = duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &curr, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); DUK_ASSERT(rc != 0); @@ -62485,14 +63699,14 @@ } if (curr.e_idx < 0) { DUK_ASSERT(curr.a_idx < 0 && curr.e_idx < 0); - goto fail_virtual; /* safeguard for virtual property */ + goto fail_virtual; /* safeguard for virtual property */ } DUK_ASSERT(curr.e_idx >= 0); DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, curr.e_idx)); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, curr.e_idx); - DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ(thr, tv1); /* XXX: just decref */ + DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ(thr, tv1); /* XXX: just decref */ DUK_HOBJECT_E_SET_VALUE_GETTER(thr->heap, obj, curr.e_idx, NULL); DUK_HOBJECT_E_SET_VALUE_SETTER(thr->heap, obj, curr.e_idx, NULL); @@ -62521,7 +63735,7 @@ /* curr is accessor -> cannot be in array part. */ DUK_ASSERT(curr.a_idx < 0); if (curr.e_idx < 0) { - goto fail_virtual; /* safeguard; no virtual accessors now */ + goto fail_virtual; /* safeguard; no virtual accessors now */ } DUK_DDD(DUK_DDDPRINT("convert property to data property")); @@ -62553,8 +63767,8 @@ } /* Note: changing from writable to non-writable is OK */ if (!(curr.flags & DUK_PROPDESC_FLAG_WRITABLE) && has_value) { - duk_tval *tmp1 = duk_require_tval(thr, -1); /* curr value */ - duk_tval *tmp2 = duk_require_tval(thr, idx_value); /* new value */ + duk_tval *tmp1 = duk_require_tval(thr, -1); /* curr value */ + duk_tval *tmp2 = duk_require_tval(thr, idx_value); /* new value */ if (!duk_js_samevalue(tmp1, tmp2)) { goto fail_not_configurable; } @@ -62603,8 +63817,7 @@ /* XXX: write protect after flag? -> any chance of handling it here? */ - DUK_DDD(DUK_DDDPRINT("new flags that we want to write: 0x%02lx", - (unsigned long) new_flags)); + DUK_DDD(DUK_DDDPRINT("new flags that we want to write: 0x%02lx", (unsigned long) new_flags)); /* * Check whether we need to abandon an array part (if it exists) @@ -62620,20 +63833,23 @@ DUK_DDD(DUK_DDDPRINT("array index, new property attributes match array defaults, update in-place")); - DUK_ASSERT(curr.flags == DUK_PROPDESC_FLAGS_WEC); /* must have been, since in array part */ + DUK_ASSERT(curr.flags == DUK_PROPDESC_FLAGS_WEC); /* must have been, since in array part */ DUK_ASSERT(!has_set); DUK_ASSERT(!has_get); - DUK_ASSERT(idx_value >= 0); /* must be: if attributes match and we get here the value must differ (otherwise no change) */ + DUK_ASSERT( + idx_value >= + 0); /* must be: if attributes match and we get here the value must differ (otherwise no change) */ tv2 = duk_require_tval(thr, idx_value); tv1 = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, curr.a_idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate a_idx */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate a_idx */ goto success_exotics; } - DUK_DDD(DUK_DDDPRINT("array index, new property attributes do not match array defaults, abandon array and re-lookup")); + DUK_DDD( + DUK_DDDPRINT("array index, new property attributes do not match array defaults, abandon array and re-lookup")); duk__abandon_array_part(thr, obj); - duk_pop_unsafe(thr); /* remove old value */ + duk_pop_unsafe(thr); /* remove old value */ rc = duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &curr, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); DUK_ASSERT(rc != 0); @@ -62657,10 +63873,12 @@ if (key == DUK_HTHREAD_STRING_LENGTH(thr) && DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)) { duk_harray *a; a = (duk_harray *) obj; - DUK_DD(DUK_DDPRINT("Object.defineProperty() attribute update for duk_harray .length -> %02lx", (unsigned long) new_flags)); + DUK_DD(DUK_DDPRINT("Object.defineProperty() attribute update for duk_harray .length -> %02lx", + (unsigned long) new_flags)); DUK_HARRAY_ASSERT_VALID(a); if ((new_flags & DUK_PROPDESC_FLAGS_EC) != (curr.flags & DUK_PROPDESC_FLAGS_EC)) { - DUK_D(DUK_DPRINT("Object.defineProperty() attempt to change virtual array .length enumerable or configurable attribute, fail")); + DUK_D(DUK_DPRINT("Object.defineProperty() attempt to change virtual array .length enumerable or " + "configurable attribute, fail")); goto fail_virtual; } if (new_flags & DUK_PROPDESC_FLAG_WRITABLE) { @@ -62688,7 +63906,7 @@ DUK_UNREF(tmp); DUK_HOBJECT_E_SET_VALUE_SETTER(thr->heap, obj, curr.e_idx, set); DUK_HOBJECT_INCREF_ALLOWNULL(thr, set); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ } if (has_get) { duk_hobject *tmp; @@ -62704,7 +63922,7 @@ DUK_UNREF(tmp); DUK_HOBJECT_E_SET_VALUE_GETTER(thr->heap, obj, curr.e_idx, get); DUK_HOBJECT_INCREF_ALLOWNULL(thr, get); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ } if (has_value) { duk_tval *tv1, *tv2; @@ -62715,9 +63933,9 @@ DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, curr.e_idx)); tv2 = duk_require_tval(thr, idx_value); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, curr.e_idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate e_idx */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate e_idx */ } else { - DUK_ASSERT(curr.a_idx < 0); /* array part case handled comprehensively previously */ + DUK_ASSERT(curr.a_idx < 0); /* array part case handled comprehensively previously */ DUK_DD(DUK_DDPRINT("Object.defineProperty(), value update for virtual property")); /* XXX: Uint8Array and other typed array virtual writes not currently @@ -62726,11 +63944,12 @@ if (key == DUK_HTHREAD_STRING_LENGTH(thr) && DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)) { duk_harray *a; a = (duk_harray *) obj; - DUK_DD(DUK_DDPRINT("Object.defineProperty() value update for duk_harray .length -> %ld", (long) arrlen_new_len)); + DUK_DD(DUK_DDPRINT("Object.defineProperty() value update for duk_harray .length -> %ld", + (long) arrlen_new_len)); DUK_HARRAY_ASSERT_VALID(a); a->length = arrlen_new_len; } else { - goto fail_virtual; /* should not happen */ + goto fail_virtual; /* should not happen */ } } } @@ -62747,7 +63966,7 @@ * - for 'length' key the element deletion and 'length' update occurs here */ - success_exotics: +success_exotics: /* curr.a_idx or curr.e_idx may have been invalidated by side effects * above. @@ -62791,7 +64010,8 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key is 'length', exotic array behavior, " "doing array element deletion and length update")); - rc = duk__handle_put_array_length_smaller(thr, obj, arrlen_old_len, arrlen_new_len, force_flag, &result_len); + rc = + duk__handle_put_array_length_smaller(thr, obj, arrlen_old_len, arrlen_new_len, force_flag, &result_len); /* update length (curr points to length, and we assume it's still valid) */ DUK_ASSERT(result_len >= arrlen_new_len && result_len <= arrlen_old_len); @@ -62814,7 +64034,7 @@ duk_hobject *varenv; DUK_ASSERT(arridx_new_array_length == 0); - DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)); /* traits are separate; in particular, arguments not an array */ + DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)); /* traits are separate; in particular, arguments not an array */ map = NULL; varenv = NULL; @@ -62831,7 +64051,7 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map' " "changed to an accessor, delete arguments binding")); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ } else { /* Note: this order matters (final value before deleting map entry must be done) */ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map', " @@ -62859,7 +64079,7 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map', " "changed to non-writable, delete arguments binding")); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ } } @@ -62868,22 +64088,22 @@ */ } - success_no_exotics: +success_no_exotics: /* Some code paths use NORZ macros for simplicity, ensure refzero * handling is completed. */ DUK_REFZERO_CHECK_SLOW(thr); return 1; - fail_not_extensible: +fail_not_extensible: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_EXTENSIBLE); DUK_WO_NORETURN(return 0;); } return 0; - fail_virtual: /* just use the same "not configurable" error message" */ - fail_not_configurable: +fail_virtual: /* just use the same "not configurable" error message" */ +fail_not_configurable: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); @@ -62908,7 +64128,7 @@ h_obj = duk_push_this_coercible_to_object(thr); DUK_ASSERT(h_obj != NULL); - ret = duk_hobject_get_own_propdesc(thr, h_obj, h_v, &desc, 0 /*flags*/); /* don't push value */ + ret = duk_hobject_get_own_propdesc(thr, h_obj, h_v, &desc, 0 /*flags*/); /* don't push value */ duk_push_boolean(thr, ret && ((desc.flags & required_desc_flags) == required_desc_flags)); return 1; @@ -63022,9 +64242,7 @@ if (flags & DUK_PROPDESC_FLAG_CONFIGURABLE) { return 0; } - if (is_frozen && - !(flags & DUK_PROPDESC_FLAG_ACCESSOR) && - (flags & DUK_PROPDESC_FLAG_WRITABLE)) { + if (is_frozen && !(flags & DUK_PROPDESC_FLAG_ACCESSOR) && (flags & DUK_PROPDESC_FLAG_WRITABLE)) { return 0; } } @@ -63067,7 +64285,7 @@ DUK_ASSERT(h != NULL); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Misc support functions */ @@ -63078,7 +64296,10 @@ * duk_hstring charCodeAt, with and without surrogate awareness */ -DUK_INTERNAL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, duk_hstring *h, duk_uint_t pos, duk_bool_t surrogate_aware) { +DUK_INTERNAL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, + duk_hstring *h, + duk_uint_t pos, + duk_bool_t surrogate_aware) { duk_uint32_t boff; const duk_uint8_t *p, *p_start, *p_end; duk_ucodepoint_t cp1; @@ -63087,21 +64308,18 @@ /* Caller must check character offset to be inside the string. */ DUK_ASSERT(thr != NULL); DUK_ASSERT(h != NULL); - DUK_ASSERT_DISABLE(pos >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(pos >= 0); /* unsigned */ DUK_ASSERT(pos < (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte(thr, h, (duk_uint32_t) pos); - DUK_DDD(DUK_DDDPRINT("charCodeAt: pos=%ld -> boff=%ld, str=%!O", - (long) pos, (long) boff, (duk_heaphdr *) h)); + DUK_DDD(DUK_DDDPRINT("charCodeAt: pos=%ld -> boff=%ld, str=%!O", (long) pos, (long) boff, (duk_heaphdr *) h)); DUK_ASSERT_DISABLE(boff >= 0); DUK_ASSERT(boff < DUK_HSTRING_GET_BYTELEN(h)); p_start = DUK_HSTRING_GET_DATA(h); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h); p = p_start + boff; - DUK_DDD(DUK_DDDPRINT("p_start=%p, p_end=%p, p=%p", - (const void *) p_start, (const void *) p_end, - (const void *) p)); + DUK_DDD(DUK_DDDPRINT("p_start=%p, p_end=%p, p=%p", (const void *) p_start, (const void *) p_end, (const void *) p)); /* For invalid UTF-8 (never happens for standard ECMAScript strings) * return U+FFFD replacement character. @@ -63112,7 +64330,7 @@ * decoded at the end of the string and 'p' is no longer * within string memory range. */ - cp2 = 0; /* If call fails, this is left untouched and won't match cp2 check. */ + cp2 = 0; /* If call fails, this is left untouched and won't match cp2 check. */ (void) duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp2); if (cp2 >= 0xdc00UL && cp2 <= 0xdfffUL) { cp1 = (duk_ucodepoint_t) (((cp1 - 0xd800UL) << 10) + (cp2 - 0xdc00UL) + 0x10000UL); @@ -63142,7 +64360,7 @@ clen = duk_unicode_unvalidated_utf8_length(DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); #if defined(DUK_USE_STRLEN16) - DUK_ASSERT(clen <= 0xffffUL); /* Bytelength checked during interning. */ + DUK_ASSERT(clen <= 0xffffUL); /* Bytelength checked during interning. */ h->clen16 = (duk_uint16_t) clen; #else h->clen = (duk_uint32_t) clen; @@ -63159,7 +64377,7 @@ return h->clen; #endif } -#endif /* !DUK_USE_HSTRING_LAZY_CLEN */ +#endif /* !DUK_USE_HSTRING_LAZY_CLEN */ /* * duk_hstring charlen, when lazy charlen enabled @@ -63170,7 +64388,7 @@ DUK_LOCAL DUK_COLD duk_size_t duk__hstring_get_charlen_slowpath(duk_hstring *h) { duk_size_t res; - DUK_ASSERT(h->clen == 0); /* Checked by caller. */ + DUK_ASSERT(h->clen == 0); /* Checked by caller. */ #if defined(DUK_USE_ROM_STRINGS) /* ROM strings have precomputed clen, but if the computed clen is zero @@ -63183,7 +64401,7 @@ res = duk_unicode_unvalidated_utf8_length(DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); #if defined(DUK_USE_STRLEN16) - DUK_ASSERT(res <= 0xffffUL); /* Bytelength checked during interning. */ + DUK_ASSERT(res <= 0xffffUL); /* Bytelength checked during interning. */ h->clen16 = (duk_uint16_t) res; #else h->clen = (duk_uint32_t) res; @@ -63193,7 +64411,7 @@ } return res; } -#else /* DUK_USE_HSTRING_CLEN */ +#else /* DUK_USE_HSTRING_CLEN */ DUK_LOCAL duk_size_t duk__hstring_get_charlen_slowpath(duk_hstring *h) { if (DUK_LIKELY(DUK_HSTRING_HAS_ASCII(h))) { /* Most practical strings will go here. */ @@ -63222,7 +64440,7 @@ return res; } } -#endif /* DUK_USE_HSTRING_CLEN */ +#endif /* DUK_USE_HSTRING_CLEN */ #if defined(DUK_USE_HSTRING_CLEN) DUK_INTERNAL DUK_HOT duk_size_t duk_hstring_get_charlen(duk_hstring *h) { @@ -63237,13 +64455,13 @@ #endif return duk__hstring_get_charlen_slowpath(h); } -#else /* DUK_USE_HSTRING_CLEN */ +#else /* DUK_USE_HSTRING_CLEN */ DUK_INTERNAL DUK_HOT duk_size_t duk_hstring_get_charlen(duk_hstring *h) { /* Always use slow path. */ return duk__hstring_get_charlen_slowpath(h); } -#endif /* DUK_USE_HSTRING_CLEN */ -#endif /* DUK_USE_HSTRING_LAZY_CLEN */ +#endif /* DUK_USE_HSTRING_CLEN */ +#endif /* DUK_USE_HSTRING_LAZY_CLEN */ /* * Compare duk_hstring to an ASCII cstring. @@ -63308,7 +64526,7 @@ return 1; - fail: +fail: DUK_FREE(heap, thr->valstack); DUK_ASSERT(thr->callstack_curr == NULL); @@ -63335,21 +64553,21 @@ * Encoding constants, must match genbuiltins.py */ -#define DUK__PROP_FLAGS_BITS 3 -#define DUK__LENGTH_PROP_BITS 3 -#define DUK__NARGS_BITS 3 -#define DUK__PROP_TYPE_BITS 3 - -#define DUK__NARGS_VARARGS_MARKER 0x07 - -#define DUK__PROP_TYPE_DOUBLE 0 -#define DUK__PROP_TYPE_STRING 1 -#define DUK__PROP_TYPE_STRIDX 2 -#define DUK__PROP_TYPE_BUILTIN 3 -#define DUK__PROP_TYPE_UNDEFINED 4 -#define DUK__PROP_TYPE_BOOLEAN_TRUE 5 -#define DUK__PROP_TYPE_BOOLEAN_FALSE 6 -#define DUK__PROP_TYPE_ACCESSOR 7 +#define DUK__PROP_FLAGS_BITS 3 +#define DUK__LENGTH_PROP_BITS 3 +#define DUK__NARGS_BITS 3 +#define DUK__PROP_TYPE_BITS 3 + +#define DUK__NARGS_VARARGS_MARKER 0x07 + +#define DUK__PROP_TYPE_DOUBLE 0 +#define DUK__PROP_TYPE_STRING 1 +#define DUK__PROP_TYPE_STRIDX 2 +#define DUK__PROP_TYPE_BUILTIN 3 +#define DUK__PROP_TYPE_UNDEFINED 4 +#define DUK__PROP_TYPE_BOOLEAN_TRUE 5 +#define DUK__PROP_TYPE_BOOLEAN_FALSE 6 +#define DUK__PROP_TYPE_ACCESSOR 7 /* * Create built-in objects by parsing an init bitstream generated @@ -63372,9 +64590,8 @@ #if defined(DUK_USE_ROM_GLOBAL_INHERIT) /* Inherit from ROM-based global object: less RAM usage, less transparent. */ h_global = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), DUK_BIDX_GLOBAL); DUK_ASSERT(h_global != NULL); #elif defined(DUK_USE_ROM_GLOBAL_CLONE) @@ -63383,9 +64600,8 @@ * model but more compliant. */ h_global = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), DUK_BIDX_OBJECT_PROTOTYPE); DUK_ASSERT(h_global != NULL); h_oldglobal = thr->builtinsDUK_BIDX_GLOBAL; @@ -63419,7 +64635,8 @@ duk_hobject_compact_props(thr, h_global); DUK_ASSERT(thr->builtinsDUK_BIDX_GLOBAL != NULL); - DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL)); /* no need to decref: ROM object */ + DUK_ASSERT( + !DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL)); /* no need to decref: ROM object */ thr->builtinsDUK_BIDX_GLOBAL = h_global; DUK_HOBJECT_INCREF(thr, h_global); DUK_D(DUK_DPRINT("duplicated global object: %!O", h_global)); @@ -63428,9 +64645,9 @@ * needed so that the global scope points to the newly created RAM-based * global object. */ - h_objenv = (duk_hobject *) duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + h_objenv = + (duk_hobject *) duk_hobjenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(h_objenv != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_objenv) == NULL); duk_push_hobject(thr, h_objenv); @@ -63441,16 +64658,17 @@ DUK_ASSERT(((duk_hobjenv *) h_objenv)->has_this == 0); DUK_ASSERT(thr->builtinsDUK_BIDX_GLOBAL_ENV != NULL); - DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL_ENV)); /* no need to decref: ROM object */ + DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE( + (duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL_ENV)); /* no need to decref: ROM object */ thr->builtinsDUK_BIDX_GLOBAL_ENV = h_objenv; DUK_HOBJECT_INCREF(thr, h_objenv); DUK_D(DUK_DPRINT("duplicated global env: %!O", h_objenv)); DUK_HOBJENV_ASSERT_VALID((duk_hobjenv *) h_objenv); - duk_pop_2(thr); /* Pop global object and global env. */ + duk_pop_2(thr); /* Pop global object and global env. */ } -#endif /* DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT */ +#endif /* DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT */ DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { /* Setup builtins from ROM objects. All heaps/threads will share @@ -63474,12 +64692,12 @@ duk__duplicate_ram_global_object(thr); #endif } -#else /* DUK_USE_ROM_OBJECTS */ +#else /* DUK_USE_ROM_OBJECTS */ DUK_LOCAL void duk__push_stridx(duk_hthread *thr, duk_bitdecoder_ctx *bd) { duk_small_uint_t n; n = (duk_small_uint_t) duk_bd_decode_varuint(bd); - DUK_ASSERT_DISABLE(n >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(n >= 0); /* unsigned */ DUK_ASSERT(n < DUK_HEAP_NUM_STRINGS); duk_push_hstring_stridx(thr, n); } @@ -63516,16 +64734,18 @@ du.uci = (duk_uint8_t) duk_bd_decode(bd, 8); } - duk_push_number(thr, du.d); /* push operation normalizes NaNs */ + duk_push_number(thr, du.d); /* push operation normalizes NaNs */ } DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { duk_bitdecoder_ctx bd_ctx; - duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ + duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ duk_hobject *h; duk_small_uint_t i, j; - DUK_D(DUK_DPRINT("INITBUILTINS BEGIN: DUK_NUM_BUILTINS=%d, DUK_NUM_BUILTINS_ALL=%d", (int) DUK_NUM_BUILTINS, (int) DUK_NUM_ALL_BUILTINS)); + DUK_D(DUK_DPRINT("INITBUILTINS BEGIN: DUK_NUM_BUILTINS=%d, DUK_NUM_BUILTINS_ALL=%d", + (int) DUK_NUM_BUILTINS, + (int) DUK_NUM_ALL_BUILTINS)); duk_memzero(&bd_ctx, sizeof(bd_ctx)); bd->data = (const duk_uint8_t *) duk_builtins_data; @@ -63552,14 +64772,14 @@ DUK_ASSERT_TOP(thr, 0); for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) { duk_small_uint_t class_num; - duk_small_int_t len = -1; /* must be signed */ + duk_small_int_t len = -1; /* must be signed */ class_num = (duk_small_uint_t) duk_bd_decode_varuint(bd); len = (duk_small_int_t) duk_bd_decode_flagged_signed(bd, DUK__LENGTH_PROP_BITS, (duk_int32_t) -1 /*def_value*/); if (class_num == DUK_HOBJECT_CLASS_FUNCTION) { duk_small_uint_t natidx; - duk_small_int_t c_nargs; /* must hold DUK_VARARGS */ + duk_small_int_t c_nargs; /* must hold DUK_VARARGS */ duk_c_function c_func; duk_int16_t magic; @@ -63590,12 +64810,9 @@ duk__push_stridx_or_string(thr, bd); #if defined(DUK_USE_FUNC_NAME_PROPERTY) - duk_xdef_prop_stridx_short(thr, - -2, - DUK_STRIDX_NAME, - DUK_PROPDESC_FLAGS_C); + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); #else - duk_pop(thr); /* Not very ideal but good enough for now. */ + duk_pop(thr); /* Not very ideal but good enough for now. */ #endif /* Almost all global level Function objects are constructable @@ -63621,8 +64838,7 @@ DUK_ASSERT(DUK_BIDX_GLOBAL_ENV > DUK_BIDX_GLOBAL); env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(env->target == NULL); duk_push_hobject(thr, (duk_hobject *) env); @@ -63637,10 +64853,8 @@ DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_DECENV); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXTENSIBLE, - -1); /* no prototype or class yet */ - + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXTENSIBLE, + -1); /* no prototype or class yet */ } h = duk_known_hobject(thr, -1); @@ -63662,18 +64876,15 @@ * not encoded explicitly in init data. */ - DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_ARRAY); /* .length is virtual */ + DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_ARRAY); /* .length is virtual */ duk_push_int(thr, len); - duk_xdef_prop_stridx_short(thr, - -2, - DUK_STRIDX_LENGTH, - DUK_PROPDESC_FLAGS_C); + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); } /* enable exotic behaviors last */ if (class_num == DUK_HOBJECT_CLASS_ARRAY) { - DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)); /* set by duk_push_array() */ + DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)); /* set by duk_push_array() */ } if (class_num == DUK_HOBJECT_CLASS_STRING) { DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h); @@ -63690,7 +64901,7 @@ DUK_ASSERT(!DUK_HOBJECT_IS_PROXY(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(h) || class_num == DUK_HOBJECT_CLASS_ARRAY); /* DUK_HOBJECT_FLAG_STRICT varies */ - DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(h) || /* all native functions have NEWENV */ + DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(h) || /* all native functions have NEWENV */ DUK_HOBJECT_HAS_NEWENV(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_NAMEBINDING(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_CREATEARGS(h)); @@ -63773,11 +64984,9 @@ defprop_flags = (duk_small_uint_t) duk_bd_decode_flagged(bd, DUK__PROP_FLAGS_BITS, (duk_uint32_t) DUK_PROPDESC_FLAGS_WC); - defprop_flags |= DUK_DEFPROP_FORCE | - DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | + defprop_flags |= DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE | - DUK_DEFPROP_HAVE_CONFIGURABLE; /* Defaults for data properties. */ + DUK_DEFPROP_HAVE_CONFIGURABLE; /* Defaults for data properties. */ /* The writable, enumerable, configurable flags in prop_flags * match both duk_def_prop() and internal property flags. @@ -63789,7 +64998,11 @@ t = (duk_small_uint_t) duk_bd_decode(bd, DUK__PROP_TYPE_BITS); DUK_DDD(DUK_DDDPRINT("built-in %ld, normal-valued property %ld, key %!T, flags 0x%02lx, type %ld", - (long) i, (long) j, duk_get_tval(thr, -1), (unsigned long) defprop_flags, (long) t)); + (long) i, + (long) j, + duk_get_tval(thr, -1), + (unsigned long) defprop_flags, + (long) t)); switch (t) { case DUK__PROP_TYPE_DOUBLE: { @@ -63830,24 +65043,29 @@ duk_c_function c_func_getter; duk_c_function c_func_setter; - DUK_DDD(DUK_DDDPRINT("built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx", - (long) i, duk_get_tval(thr, -1), (long) natidx_getter, (long) natidx_setter, (unsigned long) defprop_flags)); + DUK_DDD(DUK_DDDPRINT( + "built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx", + (long) i, + duk_get_tval(thr, -1), + (long) natidx_getter, + (long) natidx_setter, + (unsigned long) defprop_flags)); c_func_getter = duk_bi_native_functionsnatidx_getter; if (c_func_getter != NULL) { - duk_push_c_function_builtin_noconstruct(thr, c_func_getter, 0); /* always 0 args */ + duk_push_c_function_builtin_noconstruct(thr, c_func_getter, 0); /* always 0 args */ duk_set_magic(thr, -1, (duk_int_t) accessor_magic); defprop_flags |= DUK_DEFPROP_HAVE_GETTER; } c_func_setter = duk_bi_native_functionsnatidx_setter; if (c_func_setter != NULL) { - duk_push_c_function_builtin_noconstruct(thr, c_func_setter, 1); /* always 1 arg */ + duk_push_c_function_builtin_noconstruct(thr, c_func_setter, 1); /* always 1 arg */ duk_set_magic(thr, -1, (duk_int_t) accessor_magic); defprop_flags |= DUK_DEFPROP_HAVE_SETTER; } /* Writable flag doesn't make sense for an accessor. */ - DUK_ASSERT((defprop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */ + DUK_ASSERT((defprop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */ defprop_flags &= ~(DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE); defprop_flags |= DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE; @@ -63869,7 +65087,7 @@ for (j = 0; j < num; j++) { duk_hstring *h_key; duk_small_uint_t natidx; - duk_int_t c_nargs; /* must hold DUK_VARARGS */ + duk_int_t c_nargs; /* must hold DUK_VARARGS */ duk_small_uint_t c_length; duk_int16_t magic; duk_c_function c_func; @@ -63892,51 +65110,66 @@ c_func = duk_bi_native_functionsnatidx; - DUK_DDD(DUK_DDDPRINT("built-in %ld, function-valued property %ld, key %!O, natidx %ld, length %ld, nargs %ld", - (long) i, (long) j, (duk_heaphdr *) h_key, (long) natidx, (long) c_length, - (c_nargs == DUK_VARARGS ? (long) -1 : (long) c_nargs))); + DUK_DDD( + DUK_DDDPRINT("built-in %ld, function-valued property %ld, key %!O, natidx %ld, length %ld, nargs %ld", + (long) i, + (long) j, + (duk_heaphdr *) h_key, + (long) natidx, + (long) c_length, + (c_nargs == DUK_VARARGS ? (long) -1 : (long) c_nargs))); /* Cast converts magic to 16-bit signed value */ magic = (duk_int16_t) duk_bd_decode_varuint(bd); #if defined(DUK_USE_LIGHTFUNC_BUILTINS) lightfunc_eligible = - ((c_nargs >= DUK_LFUNC_NARGS_MIN && c_nargs <= DUK_LFUNC_NARGS_MAX) || (c_nargs == DUK_VARARGS)) && - (c_length <= DUK_LFUNC_LENGTH_MAX) && - (magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX); + ((c_nargs >= DUK_LFUNC_NARGS_MIN && c_nargs <= DUK_LFUNC_NARGS_MAX) || (c_nargs == DUK_VARARGS)) && + (c_length <= DUK_LFUNC_LENGTH_MAX) && (magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX); /* These functions have trouble working as lightfuncs. * Some of them have specific asserts and some may have - * additional properties (e.g. 'require.id' may be written). + * additional properties (e.g. 'require.id' may be written). */ if (c_func == duk_bi_global_object_eval) { lightfunc_eligible = 0; } #if defined(DUK_USE_COROUTINE_SUPPORT) - if (c_func == duk_bi_thread_yield || - c_func == duk_bi_thread_resume) { + if (c_func == duk_bi_thread_yield || c_func == duk_bi_thread_resume) { lightfunc_eligible = 0; } #endif - if (c_func == duk_bi_function_prototype_call || - c_func == duk_bi_function_prototype_apply || - c_func == duk_bi_reflect_apply || - c_func == duk_bi_reflect_construct) { + if (c_func == duk_bi_function_prototype_call || c_func == duk_bi_function_prototype_apply || + c_func == duk_bi_reflect_apply || c_func == duk_bi_reflect_construct) { lightfunc_eligible = 0; } if (lightfunc_eligible) { duk_tval tv_lfunc; - duk_small_uint_t lf_nargs = (duk_small_uint_t) (c_nargs == DUK_VARARGS ? DUK_LFUNC_NARGS_VARARGS : c_nargs); + duk_small_uint_t lf_nargs = + (duk_small_uint_t) (c_nargs == DUK_VARARGS ? DUK_LFUNC_NARGS_VARARGS : c_nargs); duk_small_uint_t lf_flags = DUK_LFUNC_FLAGS_PACK(magic, c_length, lf_nargs); DUK_TVAL_SET_LIGHTFUNC(&tv_lfunc, c_func, lf_flags); duk_push_tval(thr, &tv_lfunc); - DUK_D(DUK_DPRINT("built-in function eligible as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld -> %!iT", (int) i, (int) j, (long) c_length, (long) c_nargs, (long) magic, duk_get_tval(thr, -1))); + DUK_D(DUK_DPRINT("built-in function eligible as light function: i=%d, j=%d c_length=%ld, " + "c_nargs=%ld, magic=%ld -> %!iT", + (int) i, + (int) j, + (long) c_length, + (long) c_nargs, + (long) magic, + duk_get_tval(thr, -1))); goto lightfunc_skip; } - DUK_D(DUK_DPRINT("built-in function NOT ELIGIBLE as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld", (int) i, (int) j, (long) c_length, (long) c_nargs, (long) magic)); -#endif /* DUK_USE_LIGHTFUNC_BUILTINS */ + DUK_D(DUK_DPRINT( + "built-in function NOT ELIGIBLE as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld", + (int) i, + (int) j, + (long) c_length, + (long) c_nargs, + (long) magic)); +#endif /* DUK_USE_LIGHTFUNC_BUILTINS */ /* (builtin objects) name */ @@ -63947,10 +65180,8 @@ /* XXX: add into init data? */ /* Special call handling, not described in init data. */ - if (c_func == duk_bi_global_object_eval || - c_func == duk_bi_function_prototype_call || - c_func == duk_bi_function_prototype_apply || - c_func == duk_bi_reflect_apply || + if (c_func == duk_bi_global_object_eval || c_func == duk_bi_function_prototype_call || + c_func == duk_bi_function_prototype_apply || c_func == duk_bi_reflect_apply || c_func == duk_bi_reflect_construct) { DUK_HOBJECT_SET_SPECIAL_CALL((duk_hobject *) h_func); } @@ -63984,7 +65215,9 @@ /* XXX: other properties of function instances; 'arguments', 'caller'. */ DUK_DD(DUK_DDPRINT("built-in object %ld, function property %ld -> %!T", - (long) i, (long) j, (duk_tval *) duk_get_tval(thr, -1))); + (long) i, + (long) j, + (duk_tval *) duk_get_tval(thr, -1))); /* (builtin objects) name func */ @@ -63994,17 +65227,14 @@ */ #if defined(DUK_USE_LIGHTFUNC_BUILTINS) - lightfunc_skip: + lightfunc_skip: #endif defprop_flags = (duk_small_uint_t) duk_bd_decode_flagged(bd, DUK__PROP_FLAGS_BITS, (duk_uint32_t) DUK_PROPDESC_FLAGS_WC); - defprop_flags |= DUK_DEFPROP_FORCE | - DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | - DUK_DEFPROP_HAVE_ENUMERABLE | - DUK_DEFPROP_HAVE_CONFIGURABLE; + defprop_flags |= DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | + DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE; DUK_ASSERT(DUK_PROPDESC_FLAG_WRITABLE == DUK_DEFPROP_WRITABLE); DUK_ASSERT(DUK_PROPDESC_FLAG_ENUMERABLE == DUK_DEFPROP_ENUMERABLE); DUK_ASSERT(DUK_PROPDESC_FLAG_CONFIGURABLE == DUK_DEFPROP_CONFIGURABLE); @@ -64042,22 +65272,28 @@ #if !defined(DUK_USE_ES6_OBJECT_PROTO_PROPERTY) DUK_DD(DUK_DDPRINT("delete Object.prototype.__proto__ built-in which is not enabled in features")); - (void) duk_hobject_delprop_raw(thr, thr->builtinsDUK_BIDX_OBJECT_PROTOTYPE, DUK_HTHREAD_STRING___PROTO__(thr), DUK_DELPROP_FLAG_THROW); + (void) duk_hobject_delprop_raw(thr, + thr->builtinsDUK_BIDX_OBJECT_PROTOTYPE, + DUK_HTHREAD_STRING___PROTO__(thr), + DUK_DELPROP_FLAG_THROW); #endif #if !defined(DUK_USE_ES6_OBJECT_SETPROTOTYPEOF) DUK_DD(DUK_DDPRINT("delete Object.setPrototypeOf built-in which is not enabled in features")); - (void) duk_hobject_delprop_raw(thr, thr->builtinsDUK_BIDX_OBJECT_CONSTRUCTOR, DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr), DUK_DELPROP_FLAG_THROW); + (void) duk_hobject_delprop_raw(thr, + thr->builtinsDUK_BIDX_OBJECT_CONSTRUCTOR, + DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr), + DUK_DELPROP_FLAG_THROW); #endif /* XXX: relocate */ duk_push_string(thr, - /* Endianness indicator */ + /* Endianness indicator */ #if defined(DUK_USE_INTEGER_LE) "l" #elif defined(DUK_USE_INTEGER_BE) "b" -#elif defined(DUK_USE_INTEGER_ME) /* integer mixed endian not really used now */ +#elif defined(DUK_USE_INTEGER_ME) /* integer mixed endian not really used now */ "m" #else "?" @@ -64072,89 +65308,85 @@ "?" #endif " " - /* Packed or unpacked tval */ + /* Packed or unpacked tval */ #if defined(DUK_USE_PACKED_TVAL) "p" #else "u" #endif #if defined(DUK_USE_FASTINT) - "f" + "f" #endif - " " - /* Low memory/performance options */ + " " + /* Low memory/performance options */ #if defined(DUK_USE_STRTAB_PTRCOMP) - "s" + "s" #endif #if !defined(DUK_USE_HEAPPTR16) && !defined(DUK_DATAPTR16) && !defined(DUK_FUNCPTR16) - "n" + "n" #endif #if defined(DUK_USE_HEAPPTR16) - "h" + "h" #endif #if defined(DUK_USE_DATAPTR16) - "d" + "d" #endif #if defined(DUK_USE_FUNCPTR16) - "f" + "f" #endif #if defined(DUK_USE_REFCOUNT16) - "R" + "R" #endif #if defined(DUK_USE_STRHASH16) - "H" + "H" #endif #if defined(DUK_USE_STRLEN16) - "S" + "S" #endif #if defined(DUK_USE_BUFLEN16) - "B" + "B" #endif #if defined(DUK_USE_OBJSIZES16) - "O" + "O" #endif #if defined(DUK_USE_LIGHTFUNC_BUILTINS) - "L" + "L" #endif #if defined(DUK_USE_ROM_STRINGS) || defined(DUK_USE_ROM_OBJECTS) - /* XXX: This won't be shown in practice now - * because this code is not run when builtins - * are in ROM. - */ - "Z" + /* XXX: This won't be shown in practice now + * because this code is not run when builtins + * are in ROM. + */ + "Z" #endif #if defined(DUK_USE_LITCACHE_SIZE) - "l" + "l" #endif " " - /* Object property allocation layout */ + /* Object property allocation layout */ #if defined(DUK_USE_HOBJECT_LAYOUT_1) - "p1" + "p1" #elif defined(DUK_USE_HOBJECT_LAYOUT_2) - "p2" + "p2" #elif defined(DUK_USE_HOBJECT_LAYOUT_3) - "p3" + "p3" #else - "p?" + "p?" #endif - " " - /* Alignment guarantee */ + " " + /* Alignment guarantee */ #if (DUK_USE_ALIGN_BY == 4) - "a4" + "a4" #elif (DUK_USE_ALIGN_BY == 8) - "a8" + "a8" #elif (DUK_USE_ALIGN_BY == 1) - "a1" + "a1" #else #error invalid DUK_USE_ALIGN_BY #endif - " " - /* Architecture, OS, and compiler strings */ - DUK_USE_ARCH_STRING - " " - DUK_USE_OS_STRING - " " - DUK_USE_COMPILER_STRING); + " " + /* Architecture, OS, and compiler strings */ + DUK_USE_ARCH_STRING " " DUK_USE_OS_STRING " " DUK_USE_COMPILER_STRING); duk_xdef_prop_stridx_short(thr, DUK_BIDX_DUKTAPE, DUK_STRIDX_ENV, DUK_PROPDESC_FLAGS_WC); /* @@ -64171,7 +65403,8 @@ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) { DUK_DD(DUK_DDPRINT("built-in object %ld after initialization and compacting: %!@iO", - (long) i, (duk_heaphdr *) duk_require_hobject(thr, (duk_idx_t) i))); + (long) i, + (duk_heaphdr *) duk_require_hobject(thr, (duk_idx_t) i))); } #endif @@ -64184,14 +65417,14 @@ duk_set_top(thr, 0); DUK_ASSERT_TOP(thr, 0); } -#endif /* DUK_USE_ROM_OBJECTS */ +#endif /* DUK_USE_ROM_OBJECTS */ DUK_INTERNAL void duk_hthread_copy_builtin_objects(duk_hthread *thr_from, duk_hthread *thr_to) { duk_small_uint_t i; for (i = 0; i < DUK_NUM_BUILTINS; i++) { thr_to->builtinsi = thr_from->builtinsi; - DUK_HOBJECT_INCREF_ALLOWNULL(thr_to, thr_to->builtinsi); /* side effect free */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr_to, thr_to->builtinsi); /* side effect free */ } } @@ -64223,7 +65456,7 @@ } thr->valstack_bottom = thr->valstack; - duk_set_top(thr, 0); /* unwinds valstack, updating refcounts */ + duk_set_top(thr, 0); /* unwinds valstack, updating refcounts */ thr->state = DUK_HTHREAD_STATE_TERMINATED; @@ -64254,7 +65487,7 @@ } return 0; } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ DUK_INTERNAL duk_uint_fast32_t duk_hthread_get_act_prev_pc(duk_hthread *thr, duk_activation *act) { duk_instr_t *bcode; @@ -64323,7 +65556,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(act != NULL); - DUK_ASSERT(act->cat != NULL); /* caller must check */ + DUK_ASSERT(act->cat != NULL); /* caller must check */ cat = act->cat; DUK_ASSERT(cat != NULL); @@ -64332,9 +65565,9 @@ if (DUK_CAT_HAS_LEXENV_ACTIVE(cat)) { duk_hobject *env; - env = act->lex_env; /* current lex_env of the activation (created for catcher) */ - DUK_ASSERT(env != NULL); /* must be, since env was created when catcher was created */ - act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); /* prototype is lex_env before catcher created */ + env = act->lex_env; /* current lex_env of the activation (created for catcher) */ + DUK_ASSERT(env != NULL); /* must be, since env was created when catcher was created */ + act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); /* prototype is lex_env before catcher created */ DUK_HOBJECT_INCREF(thr, act->lex_env); DUK_HOBJECT_DECREF_NORZ(thr, env); @@ -64353,7 +65586,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(act != NULL); - DUK_ASSERT(act->cat != NULL); /* caller must check */ + DUK_ASSERT(act->cat != NULL); /* caller must check */ cat = act->cat; DUK_ASSERT(cat != NULL); @@ -64391,11 +65624,11 @@ return duk__hthread_catcher_alloc_slow(thr); } -#else /* DUK_USE_CACHE_CATCHER */ +#else /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL duk_catcher *duk_hthread_catcher_alloc(duk_hthread *thr) { return duk__hthread_catcher_alloc_slow(thr); } -#endif /* DUK_USE_CACHE_CATCHER */ +#endif /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL void duk_hthread_catcher_free(duk_hthread *thr, duk_catcher *cat) { DUK_ASSERT(thr != NULL); @@ -64436,12 +65669,11 @@ return duk__hthread_activation_alloc_slow(thr); } -#else /* DUK_USE_CACHE_ACTIVATION */ +#else /* DUK_USE_CACHE_ACTIVATION */ DUK_INTERNAL duk_activation *duk_hthread_activation_alloc(duk_hthread *thr) { return duk__hthread_activation_alloc_slow(thr); } -#endif /* DUK_USE_CACHE_ACTIVATION */ - +#endif /* DUK_USE_CACHE_ACTIVATION */ DUK_INTERNAL void duk_hthread_activation_free(duk_hthread *thr, duk_activation *act) { DUK_ASSERT(thr != NULL); @@ -64468,7 +65700,7 @@ duk_hobject *tmp; DUK_ASSERT(thr != NULL); - DUK_ASSERT(thr->callstack_curr != NULL); /* caller must check */ + DUK_ASSERT(thr->callstack_curr != NULL); /* caller must check */ DUK_ASSERT(thr->callstack_top > 0); act = thr->callstack_curr; DUK_ASSERT(act != NULL); @@ -64505,7 +65737,7 @@ DUK_TVAL_SET_OBJECT(tv_caller, act->prev_caller); act->prev_caller = NULL; } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref needed */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref needed */ DUK_ASSERT(act->prev_caller == NULL); } DUK_TVAL_DECREF_NORZ(thr, &tv_tmp); @@ -64534,7 +65766,7 @@ duk_debug_set_paused(heap); } else { DUK_D(DUK_DPRINT("unwound past dbg_pause_act, set to NULL")); - heap->dbg_pause_act = NULL; /* avoid stale pointers */ + heap->dbg_pause_act = NULL; /* avoid stale pointers */ } DUK_ASSERT(heap->dbg_pause_act == NULL); } @@ -64583,12 +65815,11 @@ * fixed e.g. by preallocating the scope property slots. */ if (act->var_env != NULL) { - DUK_DDD(DUK_DDDPRINT("closing var_env record %p -> %!O", - (void *) act->var_env, (duk_heaphdr *) act->var_env)); + DUK_DDD(DUK_DDDPRINT("closing var_env record %p -> %!O", (void *) act->var_env, (duk_heaphdr *) act->var_env)); duk_js_close_environment_record(thr, act->var_env); } - skip_env_close: +skip_env_close: /* * Update preventcount @@ -64712,7 +65943,7 @@ DUK_D(DUK_DPRINT("failed to realloc valstack for torture, ignore")); } } -#endif /* DUK_USE_FINALIZER_TORTURE */ +#endif /* DUK_USE_FINALIZER_TORTURE */ /* * Shared helpers for arithmetic operations */ @@ -64756,10 +65987,14 @@ DUK_ASSERT(DUK_ISNAN(DUK_FMOD(-DUK_DOUBLE_INFINITY, -DUK_DOUBLE_INFINITY))); DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, 1.0), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, 1.0)) == 0); DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, 1.0), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, 1.0)) != 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY)) != 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, -DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY)) != 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY)) != 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, -DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY)) != 0); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(0.0, 0.0))); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(-0.0, 0.0))); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(0.0, -0.0))); @@ -64847,7 +66082,7 @@ return DUK_POW(x, y); - ret_nan: +ret_nan: return DUK_DOUBLE_NAN; } /* @@ -64903,10 +66138,10 @@ * for, e.g. a print() call at the deepest level, and an extra * +1 for protected call wrapping. */ -#define DUK__AUGMENT_CALL_RELAX_COUNT (10 + 2) +#define DUK__AUGMENT_CALL_RELAX_COUNT (10 + 2) /* Stack space required by call handling entry. */ -#define DUK__CALL_HANDLING_REQUIRE_STACK 8 +#define DUK__CALL_HANDLING_REQUIRE_STACK 8 DUK_LOCAL DUK_NOINLINE void duk__call_c_recursion_limit_check_slowpath(duk_hthread *thr) { /* When augmenting an error, the effective limit is a bit higher. @@ -65000,7 +66235,8 @@ thr->heap->inst_count_interrupt += thr->interrupt_init; DUK_DD(DUK_DDPRINT("debug test: updated interrupt count on exit to " "user code, instruction counts: executor=%ld, interrupt=%ld", - (long) thr->heap->inst_count_exec, (long) thr->heap->inst_count_interrupt)); + (long) thr->heap->inst_count_exec, + (long) thr->heap->inst_count_interrupt)); DUK_ASSERT(thr->heap->inst_count_exec == thr->heap->inst_count_interrupt); } #else @@ -65019,12 +66255,9 @@ * object flag DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS. */ -DUK_LOCAL void duk__create_arguments_object(duk_hthread *thr, - duk_hobject *func, - duk_hobject *varenv, - duk_idx_t idx_args) { - duk_hobject *arg; /* 'arguments' */ - duk_hobject *formals; /* formals for 'func' (may be NULL if func is a C function) */ +DUK_LOCAL void duk__create_arguments_object(duk_hthread *thr, duk_hobject *func, duk_hobject *varenv, duk_idx_t idx_args) { + duk_hobject *arg; /* 'arguments' */ + duk_hobject *formals; /* formals for 'func' (may be NULL if func is a C function) */ duk_idx_t i_arg; duk_idx_t i_map; duk_idx_t i_mappednames; @@ -65070,9 +66303,8 @@ DUK_ASSERT(n_formals >= 0); DUK_ASSERT(formals != NULL || n_formals == 0); - DUK_DDD(DUK_DDDPRINT("func=%!O, formals=%!O, n_formals=%ld", - (duk_heaphdr *) func, (duk_heaphdr *) formals, - (long) n_formals)); + DUK_DDD( + DUK_DDDPRINT("func=%!O, formals=%!O, n_formals=%ld", (duk_heaphdr *) func, (duk_heaphdr *) formals, (long) n_formals)); /* ... formals */ @@ -65084,28 +66316,24 @@ */ arg = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARGUMENTS), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARGUMENTS), DUK_BIDX_OBJECT_PROTOTYPE); DUK_ASSERT(arg != NULL); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ i_arg = duk_get_top(thr) - 3; i_map = i_arg + 1; i_mappednames = i_arg + 2; - DUK_ASSERT(!duk_is_bare_object(thr, -3)); /* arguments */ - DUK_ASSERT(duk_is_bare_object(thr, -2)); /* map */ - DUK_ASSERT(duk_is_bare_object(thr, -1)); /* mappedNames */ + DUK_ASSERT(!duk_is_bare_object(thr, -3)); /* arguments */ + DUK_ASSERT(duk_is_bare_object(thr, -2)); /* map */ + DUK_ASSERT(duk_is_bare_object(thr, -1)); /* mappedNames */ /* ... formals arguments map mappedNames */ @@ -65113,9 +66341,12 @@ "arguments at index %ld -> %!O " "map at index %ld -> %!O " "mappednames at index %ld -> %!O", - (long) i_arg, (duk_heaphdr *) duk_get_hobject(thr, i_arg), - (long) i_map, (duk_heaphdr *) duk_get_hobject(thr, i_map), - (long) i_mappednames, (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); + (long) i_arg, + (duk_heaphdr *) duk_get_hobject(thr, i_arg), + (long) i_map, + (duk_heaphdr *) duk_get_hobject(thr, i_map), + (long) i_mappednames, + (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); /* * Init arguments properties, map, etc. @@ -65131,8 +66362,8 @@ /* step 11 */ idx = num_stack_args - 1; while (idx >= 0) { - DUK_DDD(DUK_DDDPRINT("arg idx %ld, argbase=%ld, argidx=%ld", - (long) idx, (long) i_argbase, (long) (i_argbase + idx))); + DUK_DDD( + DUK_DDDPRINT("arg idx %ld, argbase=%ld, argidx=%ld", (long) idx, (long) i_argbase, (long) (i_argbase + idx))); DUK_DDD(DUK_DDDPRINT("define arguments%ld=arg", (long) idx)); duk_dup(thr, i_argbase + idx); @@ -65143,13 +66374,12 @@ if (!DUK_HOBJECT_HAS_STRICT(func) && idx < n_formals) { DUK_ASSERT(formals != NULL); - DUK_DDD(DUK_DDDPRINT("strict function, index within formals (%ld < %ld)", - (long) idx, (long) n_formals)); + DUK_DDD(DUK_DDDPRINT("strict function, index within formals (%ld < %ld)", (long) idx, (long) n_formals)); duk_get_prop_index(thr, i_formals, (duk_uarridx_t) idx); DUK_ASSERT(duk_is_string(thr, -1)); - duk_dup_top(thr); /* ... name name */ + duk_dup_top(thr); /* ... name name */ if (!duk_has_prop(thr, i_mappednames)) { /* steps 11.c.ii.1 - 11.c.ii.4, but our internal book-keeping @@ -65160,24 +66390,21 @@ need_map = 1; - DUK_DDD(DUK_DDDPRINT("set mappednames%s=%ld", - (const char *) duk_get_string(thr, -1), - (long) idx)); - duk_dup_top(thr); /* name */ - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) idx); /* index */ - duk_xdef_prop_wec(thr, i_mappednames); /* out of spec, must be configurable */ - - DUK_DDD(DUK_DDDPRINT("set map%ld=%s", - (long) idx, - duk_get_string(thr, -1))); - duk_dup_top(thr); /* name */ - duk_xdef_prop_index_wec(thr, i_map, (duk_uarridx_t) idx); /* out of spec, must be configurable */ + DUK_DDD( + DUK_DDDPRINT("set mappednames%s=%ld", (const char *) duk_get_string(thr, -1), (long) idx)); + duk_dup_top(thr); /* name */ + (void) duk_push_uint_to_hstring(thr, (duk_uint_t) idx); /* index */ + duk_xdef_prop_wec(thr, i_mappednames); /* out of spec, must be configurable */ + + DUK_DDD(DUK_DDDPRINT("set map%ld=%s", (long) idx, duk_get_string(thr, -1))); + duk_dup_top(thr); /* name */ + duk_xdef_prop_index_wec(thr, i_map, (duk_uarridx_t) idx); /* out of spec, must be configurable */ } else { /* duk_has_prop() popped the second 'name' */ } /* ... name */ - duk_pop(thr); /* pop 'name' */ + duk_pop(thr); /* pop 'name' */ } idx--; @@ -65193,7 +66420,7 @@ DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(func)); duk_dup(thr, i_map); - duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_MAP, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ + duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_MAP, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ /* The variable environment for magic variable bindings needs to be * given by the caller and recorded in the arguments object. @@ -65205,7 +66432,7 @@ */ duk_push_hobject(thr, varenv); - duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_VARENV, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ + duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_VARENV, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ } /* steps 13-14 */ @@ -65258,9 +66485,12 @@ "arguments at index %ld -> %!O " "map at index %ld -> %!O " "mappednames at index %ld -> %!O", - (long) i_arg, (duk_heaphdr *) duk_get_hobject(thr, i_arg), - (long) i_map, (duk_heaphdr *) duk_get_hobject(thr, i_map), - (long) i_mappednames, (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); + (long) i_arg, + (duk_heaphdr *) duk_get_hobject(thr, i_arg), + (long) i_map, + (duk_heaphdr *) duk_get_hobject(thr, i_map), + (long) i_mappednames, + (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); /* args(n) envobj formals arguments map mappednames */ @@ -65273,10 +66503,7 @@ /* Helper for creating the arguments object and adding it to the env record * on top of the value stack. */ -DUK_LOCAL void duk__handle_createargs_for_call(duk_hthread *thr, - duk_hobject *func, - duk_hobject *env, - duk_idx_t idx_args) { +DUK_LOCAL void duk__handle_createargs_for_call(duk_hthread *thr, duk_hobject *func, duk_hobject *env, duk_idx_t idx_args) { DUK_DDD(DUK_DDDPRINT("creating arguments object for function call")); DUK_ASSERT(thr != NULL); @@ -65286,18 +66513,15 @@ /* ... arg1 ... argN envobj */ - duk__create_arguments_object(thr, - func, - env, - idx_args); + duk__create_arguments_object(thr, func, env, idx_args); /* ... arg1 ... argN envobj argobj */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LC_ARGUMENTS, - DUK_HOBJECT_HAS_STRICT(func) ? DUK_PROPDESC_FLAGS_E : /* strict: non-deletable, non-writable */ - DUK_PROPDESC_FLAGS_WE); /* non-strict: non-deletable, writable */ + DUK_HOBJECT_HAS_STRICT(func) ? DUK_PROPDESC_FLAGS_E : /* strict: non-deletable, non-writable */ + DUK_PROPDESC_FLAGS_WE); /* non-strict: non-deletable, writable */ /* ... arg1 ... argN envobj */ } @@ -65347,7 +66571,8 @@ "-> leave standard Object prototype as fallback prototype")); } else { DUK_DDD(DUK_DDDPRINT("constructor has 'prototype' property with object value " - "-> set fallback prototype to that value: %!iO", (duk_heaphdr *) proto)); + "-> set fallback prototype to that value: %!iO", + (duk_heaphdr *) proto)); /* Original fallback (default instance) is untouched when * resolving bound functions etc. */ @@ -65369,9 +66594,7 @@ * Object (we accept object-like values like buffers and * lightfuncs too). If not, TypeError. */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_LIGHTFUNC)) { + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_LIGHTFUNC)) { DUK_DDD(DUK_DDDPRINT("replacement value")); } else { if (DUK_UNLIKELY(proxy_invariant != 0U)) { @@ -65393,8 +66616,7 @@ * out right; however it is always synced here so just assert for it. */ DUK_ASSERT(thr->ptr_curr_pc == NULL); - duk_err_augment_error_create(thr, thr, NULL, 0, DUK_AUGMENT_FLAG_NOBLAME_FILELINE | - DUK_AUGMENT_FLAG_SKIP_ONE); + duk_err_augment_error_create(thr, thr, NULL, 0, DUK_AUGMENT_FLAG_NOBLAME_FILELINE | DUK_AUGMENT_FLAG_SKIP_ONE); #endif } @@ -65411,9 +66633,7 @@ * BoundThis. */ -DUK_LOCAL void duk__handle_bound_chain_for_call(duk_hthread *thr, - duk_idx_t idx_func, - duk_bool_t is_constructor_call) { +DUK_LOCAL void duk__handle_bound_chain_for_call(duk_hthread *thr, duk_idx_t idx_func, duk_bool_t is_constructor_call) { duk_tval *tv_func; duk_hobject *func; duk_idx_t len; @@ -65444,7 +66664,8 @@ DUK_ASSERT(len == 0 || tv_args != NULL); DUK_DDD(DUK_DDDPRINT("bound function encountered, ptr=%p: %!T", - (void *) DUK_TVAL_GET_OBJECT(tv_func), tv_func)); + (void *) DUK_TVAL_GET_OBJECT(tv_func), + tv_func)); /* ... func this arg1 ... argN */ @@ -65454,7 +66675,7 @@ } else { /* XXX: duk_replace_tval */ duk_push_tval(thr, &h_bound->this_binding); - duk_replace(thr, idx_func + 1); /* idx_this = idx_func + 1 */ + duk_replace(thr, idx_func + 1); /* idx_this = idx_func + 1 */ } /* ... func this arg1 ... argN */ @@ -65467,10 +66688,11 @@ /* ... func this <bound args> arg1 ... argN */ duk_push_tval(thr, &h_bound->target); - duk_replace(thr, idx_func); /* replace in stack */ + duk_replace(thr, idx_func); /* replace in stack */ DUK_DDD(DUK_DDDPRINT("bound function handled, idx_func=%ld, curr func=%!T", - (long) idx_func, duk_get_tval(thr, idx_func))); + (long) idx_func, + duk_get_tval(thr, idx_func))); } } else if (DUK_TVAL_IS_LIGHTFUNC(tv_func)) { /* Lightweight function: never bound, so terminate. */ @@ -65492,9 +66714,7 @@ func = DUK_TVAL_GET_OBJECT(tv_func); DUK_ASSERT(func != NULL); DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func) || - DUK_HOBJECT_HAS_NATFUNC(func) || - DUK_HOBJECT_IS_PROXY(func)); + DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func) || DUK_HOBJECT_HAS_NATFUNC(func) || DUK_HOBJECT_IS_PROXY(func)); } #endif } @@ -65503,14 +66723,18 @@ * Helper for inline handling of .call(), .apply(), and .construct(). */ -DUK_LOCAL duk_bool_t duk__handle_specialfuncs_for_call(duk_hthread *thr, duk_idx_t idx_func, duk_hobject *func, duk_small_uint_t *call_flags, duk_bool_t first) { +DUK_LOCAL duk_bool_t duk__handle_specialfuncs_for_call(duk_hthread *thr, + duk_idx_t idx_func, + duk_hobject *func, + duk_small_uint_t *call_flags, + duk_bool_t first) { #if defined(DUK_USE_ASSERTIONS) duk_c_function natfunc; #endif duk_tval *tv_args; DUK_ASSERT(func != NULL); - DUK_ASSERT((*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0); /* Caller. */ + DUK_ASSERT((*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0); /* Caller. */ #if defined(DUK_USE_ASSERTIONS) natfunc = ((duk_hnatfunc *) func)->func; @@ -65538,7 +66762,7 @@ *call_flags = (*call_flags & ~DUK_CALL_FLAG_CALLED_AS_EVAL) | DUK_CALL_FLAG_DIRECT_EVAL; } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 1; /* stop resolving */ + return 1; /* stop resolving */ } /* Handle special functions based on the DUK_HOBJECT_FLAG_SPECIAL_CALL @@ -65548,7 +66772,7 @@ * for the result values (unlike most other value stack calls). */ switch (((duk_hnatfunc *) func)->magic) { - case 0: { /* 0=Function.prototype.call() */ + case 0: { /* 0=Function.prototype.call() */ /* Value stack: * idx_func + 0: Function.prototype.call() removed * idx_func + 1: this binding for .call (target function) @@ -65567,11 +66791,11 @@ tv_args = thr->valstack_bottom + idx_func + 2; if (thr->valstack_top < tv_args) { DUK_ASSERT(tv_args <= thr->valstack_end); - thr->valstack_top = tv_args; /* at least target function and 'this' binding present */ + thr->valstack_top = tv_args; /* at least target function and 'this' binding present */ } break; } - case 1: { /* 1=Function.prototype.apply() */ + case 1: { /* 1=Function.prototype.apply() */ /* Value stack: * idx_func + 0: Function.prototype.apply() removed * idx_func + 1: this binding for .apply (target function) @@ -65590,7 +66814,7 @@ goto apply_shared; } #if defined(DUK_USE_REFLECT_BUILTIN) - case 2: { /* 2=Reflect.apply() */ + case 2: { /* 2=Reflect.apply() */ /* Value stack: * idx_func + 0: Reflect.apply() removed * idx_func + 1: this binding for .apply (ignored, usually Reflect) removed @@ -65609,7 +66833,7 @@ duk_remove_n_unsafe(thr, idx_func, 2); goto apply_shared; } - case 3: { /* 3=Reflect.construct() */ + case 3: { /* 3=Reflect.construct() */ /* Value stack: * idx_func + 0: Reflect.construct() removed * idx_func + 1: this binding for .construct (ignored, usually Reflect) removed @@ -65643,11 +66867,11 @@ * unpacking argArray (which may cause side effects). * Just return; caller will throw the error. */ - duk_set_top_unsafe(thr, idx_func + 2); /* satisfy asserts */ + duk_set_top_unsafe(thr, idx_func + 2); /* satisfy asserts */ break; } duk_push_object(thr); - duk_insert(thr, idx_func + 1); /* default instance */ + duk_insert(thr, idx_func + 1); /* default instance */ /* ... func default_instance argArray newTarget? */ @@ -65663,16 +66887,17 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } - duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ + duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ } DUK_ASSERT(duk_get_top(thr) == idx_func + 3); DUK_ASSERT(duk_is_valid_index(thr, idx_func + 2)); - (void) duk_unpack_array_like(thr, idx_func + 2); /* XXX: should also remove target to be symmetric with duk_pack()? */ + (void) duk_unpack_array_like(thr, + idx_func + 2); /* XXX: should also remove target to be symmetric with duk_pack()? */ duk_remove(thr, idx_func + 2); DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); break; } -#endif /* DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_REFLECT_BUILTIN */ default: { DUK_ASSERT(0); DUK_UNREACHABLE(); @@ -65680,18 +66905,18 @@ } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 0; /* keep resolving */ + return 0; /* keep resolving */ - apply_shared: +apply_shared: tv_args = thr->valstack_bottom + idx_func + 2; if (thr->valstack_top <= tv_args) { DUK_ASSERT(tv_args <= thr->valstack_end); - thr->valstack_top = tv_args; /* at least target func and 'this' binding present */ + thr->valstack_top = tv_args; /* at least target func and 'this' binding present */ /* No need to check for argArray. */ } else { - DUK_ASSERT(duk_get_top(thr) >= idx_func + 3); /* idx_func + 2 covered above */ + DUK_ASSERT(duk_get_top(thr) >= idx_func + 3); /* idx_func + 2 covered above */ if (thr->valstack_top > tv_args + 1) { - duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ + duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ } DUK_ASSERT(duk_is_valid_index(thr, idx_func + 2)); if (!duk_is_callable(thr, idx_func)) { @@ -65704,7 +66929,7 @@ } } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 0; /* keep resolving */ + return 0; /* keep resolving */ } /* @@ -65802,8 +67027,8 @@ DUK_ASSERT(duk_get_top(thr) == idx_func + 6); if (*call_flags & DUK_CALL_FLAG_CONSTRUCT) { - *call_flags |= DUK_CALL_FLAG_CONSTRUCT_PROXY; /* Enable 'construct' trap return invariant check. */ - *call_flags &= ~(DUK_CALL_FLAG_CONSTRUCT); /* Resume as non-constructor call to the trap. */ + *call_flags |= DUK_CALL_FLAG_CONSTRUCT_PROXY; /* Enable 'construct' trap return invariant check. */ + *call_flags &= ~(DUK_CALL_FLAG_CONSTRUCT); /* Resume as non-constructor call to the trap. */ /* 'apply' args: target, thisArg, argArray * 'construct' args: target, argArray, newTarget @@ -65814,19 +67039,17 @@ /* Finalize value stack layout by removing Proxy reference. */ duk_remove(thr, idx_func); - h_proxy = NULL; /* invalidated */ + h_proxy = NULL; /* invalidated */ DUK_ASSERT(duk_get_top(thr) == idx_func + 5); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* * Helper for setting up var_env and lex_env of an activation, * assuming it does NOT have the DUK_HOBJECT_FLAG_NEWENV flag. */ -DUK_LOCAL void duk__handle_oldenv_for_call(duk_hthread *thr, - duk_hobject *func, - duk_activation *act) { +DUK_LOCAL void duk__handle_oldenv_for_call(duk_hthread *thr, duk_hobject *func, duk_activation *act) { duk_hcompfunc *f; duk_hobject *h_lex; duk_hobject *h_var; @@ -65842,7 +67065,7 @@ f = (duk_hcompfunc *) func; h_lex = DUK_HCOMPFUNC_GET_LEXENV(thr->heap, f); h_var = DUK_HCOMPFUNC_GET_VARENV(thr->heap, f); - DUK_ASSERT(h_lex != NULL); /* Always true for closures (not for templates) */ + DUK_ASSERT(h_lex != NULL); /* Always true for closures (not for templates) */ DUK_ASSERT(h_var != NULL); act->lex_env = h_lex; act->var_env = h_var; @@ -65863,7 +67086,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(func != NULL); - DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound chain resolved */ + DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound chain resolved */ DUK_ASSERT(thr->callstack_top >= 1); if (DUK_HOBJECT_HAS_STRICT(func)) { @@ -65917,7 +67140,7 @@ DUK_TVAL_SET_OBJECT(tv_caller, act_caller->func); DUK_TVAL_INCREF(thr, tv_caller); } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref */ } } else { /* 'caller' must only take on 'null' or function value */ @@ -65930,12 +67153,12 @@ DUK_TVAL_SET_OBJECT(tv_caller, act_caller->func); DUK_TVAL_INCREF(thr, tv_caller); } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref */ } } } } -#endif /* DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ +#endif /* DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ /* * Shared helpers for resolving the final, non-bound target function of the @@ -65981,7 +67204,7 @@ obj_global = thr->builtinsDUK_BIDX_GLOBAL; /* XXX: avoid this check somehow */ if (DUK_LIKELY(obj_global != NULL)) { - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ DUK_TVAL_SET_OBJECT(tv_this, obj_global); DUK_HOBJECT_INCREF(thr, obj_global); } else { @@ -65989,8 +67212,8 @@ * This behavior is out of specification scope. */ DUK_D(DUK_DPRINT("this binding: wanted to use global object, but it is NULL -> using undefined instead")); - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ - DUK_TVAL_SET_UNDEFINED(tv_this); /* nothing to incref */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ + DUK_TVAL_SET_UNDEFINED(tv_this); /* nothing to incref */ } break; default: @@ -66001,18 +67224,21 @@ */ DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv_this)); DUK_DDD(DUK_DDDPRINT("this binding: non-strict, not object/undefined/null -> use ToObject(value)")); - duk_to_object(thr, idx_this); /* may have side effects */ + duk_to_object(thr, idx_this); /* may have side effects */ break; } } -DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__resolve_target_fastpath_check(duk_hthread *thr, duk_idx_t idx_func, duk_hobject **out_func, duk_small_uint_t call_flags) { +DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__resolve_target_fastpath_check(duk_hthread *thr, + duk_idx_t idx_func, + duk_hobject **out_func, + duk_small_uint_t call_flags) { #if defined(DUK_USE_PREFER_SIZE) DUK_UNREF(thr); DUK_UNREF(idx_func); DUK_UNREF(out_func); DUK_UNREF(call_flags); -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ duk_tval *tv_func; duk_hobject *func; @@ -66025,9 +67251,7 @@ if (DUK_LIKELY(DUK_TVAL_IS_OBJECT(tv_func))) { func = DUK_TVAL_GET_OBJECT(tv_func); - if (DUK_HOBJECT_IS_CALLABLE(func) && - !DUK_HOBJECT_HAS_BOUNDFUNC(func) && - !DUK_HOBJECT_HAS_SPECIAL_CALL(func)) { + if (DUK_HOBJECT_IS_CALLABLE(func) && !DUK_HOBJECT_HAS_BOUNDFUNC(func) && !DUK_HOBJECT_HAS_SPECIAL_CALL(func)) { *out_func = func; if (DUK_HOBJECT_HAS_STRICT(func)) { @@ -66047,8 +67271,8 @@ */ return 1; } -#endif /* DUK_USE_PREFER_SIZE */ - return 0; /* let slow path deal with it */ +#endif /* DUK_USE_PREFER_SIZE */ + return 0; /* let slow path deal with it */ } DUK_LOCAL duk_hobject *duk__resolve_target_func_and_this_binding(duk_hthread *thr, @@ -66081,8 +67305,7 @@ } } - if (DUK_LIKELY(!DUK_HOBJECT_HAS_BOUNDFUNC(func) && - !DUK_HOBJECT_HAS_SPECIAL_CALL(func) && + if (DUK_LIKELY(!DUK_HOBJECT_HAS_BOUNDFUNC(func) && !DUK_HOBJECT_HAS_SPECIAL_CALL(func) && !DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(func))) { /* Common case, so test for using a single bitfield test. * Break out to handle this coercion etc. @@ -66118,8 +67341,7 @@ * the trap may be bound. */ duk__handle_proxy_for_call(thr, idx_func, (duk_hproxy *) func, call_flags); - } - else + } else #endif { DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(func)); @@ -66166,28 +67388,25 @@ } } - finished: - +finished : #if defined(DUK_USE_ASSERTIONS) - { - duk_tval *tv_tmp; +{ + duk_tval *tv_tmp; - tv_tmp = duk_get_tval(thr, idx_func); - DUK_ASSERT(tv_tmp != NULL); + tv_tmp = duk_get_tval(thr, idx_func); + DUK_ASSERT(tv_tmp != NULL); - DUK_ASSERT((DUK_TVAL_IS_OBJECT(tv_tmp) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(tv_tmp))) || - DUK_TVAL_IS_LIGHTFUNC(tv_tmp)); - DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || - DUK_HOBJECT_IS_NATFUNC(func))); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_HAS_CONSTRUCTABLE(func) || - (*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0)); - } + DUK_ASSERT((DUK_TVAL_IS_OBJECT(tv_tmp) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(tv_tmp))) || + DUK_TVAL_IS_LIGHTFUNC(tv_tmp)); + DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || DUK_HOBJECT_IS_NATFUNC(func))); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_HAS_CONSTRUCTABLE(func) || (*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0)); +} #endif return func; - not_callable: +not_callable: DUK_ASSERT(tv_func != NULL); #if defined(DUK_USE_VERBOSE_ERRORS) @@ -66199,7 +67418,8 @@ * (which would be dangerous). */ if (DUK_TVAL_IS_OBJECT(tv_func)) { - duk_tval *tv_wrap = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, DUK_TVAL_GET_OBJECT(tv_func), DUK_STRIDX_INT_TARGET); + duk_tval *tv_wrap = + duk_hobject_find_entry_tval_ptr_stridx(thr->heap, DUK_TVAL_GET_OBJECT(tv_func), DUK_STRIDX_INT_TARGET); if (tv_wrap != NULL) { DUK_DD(DUK_DDPRINT("delayed error from GETPROPC: %!T", tv_wrap)); duk_push_tval(thr, tv_wrap); @@ -66220,7 +67440,7 @@ #endif DUK_WO_NORETURN(return NULL;); - not_constructable: +not_constructable: /* For now GETPROPC delayed error not needed for constructor calls. */ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) @@ -66244,7 +67464,10 @@ * empty (below idx_retbase). */ -DUK_LOCAL void duk__safe_call_adjust_valstack(duk_hthread *thr, duk_idx_t idx_retbase, duk_idx_t num_stack_rets, duk_idx_t num_actual_rets) { +DUK_LOCAL void duk__safe_call_adjust_valstack(duk_hthread *thr, + duk_idx_t idx_retbase, + duk_idx_t num_stack_rets, + duk_idx_t num_actual_rets) { duk_idx_t idx_rcbase; DUK_ASSERT(thr != NULL); @@ -66252,7 +67475,7 @@ DUK_ASSERT(num_stack_rets >= 0); DUK_ASSERT(num_actual_rets >= 0); - idx_rcbase = duk_get_top(thr) - num_actual_rets; /* base of known return values */ + idx_rcbase = duk_get_top(thr) - num_actual_rets; /* base of known return values */ if (DUK_UNLIKELY(idx_rcbase < 0)) { DUK_ERROR_TYPE(thr, DUK_STR_INVALID_CFUNC_RC); DUK_WO_NORETURN(return;); @@ -66260,10 +67483,13 @@ DUK_DDD(DUK_DDDPRINT("adjust valstack after func call: " "num_stack_rets=%ld, num_actual_rets=%ld, stack_top=%ld, idx_retbase=%ld, idx_rcbase=%ld", - (long) num_stack_rets, (long) num_actual_rets, (long) duk_get_top(thr), - (long) idx_retbase, (long) idx_rcbase)); + (long) num_stack_rets, + (long) num_actual_rets, + (long) duk_get_top(thr), + (long) idx_retbase, + (long) idx_rcbase)); - DUK_ASSERT(idx_rcbase >= 0); /* caller must check */ + DUK_ASSERT(idx_rcbase >= 0); /* caller must check */ /* Space for num_stack_rets was reserved before the safe call. * Because value stack reserve cannot shrink except in call returns, @@ -66278,24 +67504,28 @@ duk_idx_t count = idx_rcbase - idx_retbase; DUK_DDD(DUK_DDDPRINT("elements at/after idx_retbase have enough to cover func retvals " - "(idx_retbase=%ld, idx_rcbase=%ld)", (long) idx_retbase, (long) idx_rcbase)); + "(idx_retbase=%ld, idx_rcbase=%ld)", + (long) idx_retbase, + (long) idx_rcbase)); /* Remove values between irc_rcbase (start of intended return * values) and idx_retbase to lower return values to idx_retbase. */ DUK_ASSERT(count > 0); - duk_remove_n(thr, idx_retbase, count); /* may be NORZ */ + duk_remove_n(thr, idx_retbase, count); /* may be NORZ */ } else { duk_idx_t count = idx_retbase - idx_rcbase; DUK_DDD(DUK_DDDPRINT("not enough elements at/after idx_retbase to cover func retvals " - "(idx_retbase=%ld, idx_rcbase=%ld)", (long) idx_retbase, (long) idx_rcbase)); + "(idx_retbase=%ld, idx_rcbase=%ld)", + (long) idx_retbase, + (long) idx_rcbase)); /* Insert 'undefined' at idx_rcbase (start of intended return * values) to lift return values to idx_retbase. */ DUK_ASSERT(count >= 0); - DUK_ASSERT(thr->valstack_end - thr->valstack_top >= count); /* reserve cannot shrink */ + DUK_ASSERT(thr->valstack_end - thr->valstack_top >= count); /* reserve cannot shrink */ duk_insert_undefined_n(thr, idx_rcbase, count); } @@ -66356,12 +67586,12 @@ #if defined(DUK_USE_ES6_PROXY) | (duk_small_uint_t) ((act->flags & DUK_ACT_FLAG_CONSTRUCT_PROXY) ? 2 : 0) #endif - ; + ; flags2 = (duk_small_uint_t) ((call_flags & DUK_CALL_FLAG_CONSTRUCT) ? 1 : 0) #if defined(DUK_USE_ES6_PROXY) | (duk_small_uint_t) ((call_flags & DUK_CALL_FLAG_CONSTRUCT_PROXY) ? 2 : 0); #endif - ; + ; if (flags1 != flags2) { DUK_DDD(DUK_DDDPRINT("tail call prevented by incompatible return value handling")); return 0; @@ -66399,8 +67629,7 @@ * https://github.com/svaarala/duktape/issues/1726. */ - DUK_DDD(DUK_DDDPRINT("is tail call, reusing activation at callstack top, at index %ld", - (long) (thr->callstack_top - 1))); + DUK_DDD(DUK_DDDPRINT("is tail call, reusing activation at callstack top, at index %ld", (long) (thr->callstack_top - 1))); DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(func)); @@ -66444,7 +67673,7 @@ act->lex_env = NULL; DUK_ASSERT(func != NULL); DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func)); - act->func = func; /* don't want an intermediate exposed state with func == NULL */ + act->func = func; /* don't want an intermediate exposed state with func == NULL */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) act->prev_caller = NULL; #endif @@ -66453,7 +67682,7 @@ #if defined(DUK_USE_DEBUGGER_SUPPORT) act->prev_line = 0; #endif - DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ + DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ DUK_HOBJECT_INCREF(thr, func); act->flags = DUK_ACT_FLAG_TAILCALLED; @@ -66469,10 +67698,10 @@ } #endif - DUK_ASSERT(DUK_ACT_GET_FUNC(act) == func); /* already updated */ + DUK_ASSERT(DUK_ACT_GET_FUNC(act) == func); /* already updated */ DUK_ASSERT(act->var_env == NULL); DUK_ASSERT(act->lex_env == NULL); - act->bottom_byteoff = entry_valstack_bottom_byteoff; /* tail call -> reuse current "frame" */ + act->bottom_byteoff = entry_valstack_bottom_byteoff; /* tail call -> reuse current "frame" */ #if 0 /* Topmost activation retval_byteoff is considered garbage, no need to init. */ act->retval_byteoff = 0; @@ -66497,22 +67726,23 @@ tv1 = thr->valstack_bottom - 1; tv2 = thr->valstack_bottom + idx_func + 1; - DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); /* tv1 is -below- valstack_bottom */ + DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); /* tv1 is -below- valstack_bottom */ DUK_ASSERT(tv2 >= thr->valstack_bottom && tv2 < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ idx_args = idx_func + 2; - duk_remove_n(thr, 0, idx_args); /* may be NORZ */ + duk_remove_n(thr, 0, idx_args); /* may be NORZ */ - idx_func = 0; DUK_UNREF(idx_func); /* really 'not applicable' anymore, should not be referenced after this */ + idx_func = 0; + DUK_UNREF(idx_func); /* really 'not applicable' anymore, should not be referenced after this */ idx_args = 0; *out_nargs = ((duk_hcompfunc *) func)->nargs; *out_nregs = ((duk_hcompfunc *) func)->nregs; DUK_ASSERT(*out_nregs >= 0); DUK_ASSERT(*out_nregs >= *out_nargs); - *out_vs_min_bytes = entry_valstack_bottom_byteoff + sizeof(duk_tval) * ((duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); - + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + sizeof(duk_tval) * ((duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) #if defined(DUK_USE_TAILCALL) @@ -66529,7 +67759,7 @@ return 1; } -#endif /* DUK_USE_TAILCALL */ +#endif /* DUK_USE_TAILCALL */ DUK_LOCAL void duk__call_setup_act_not_tailcall(duk_hthread *thr, duk_small_uint_t call_flags, @@ -66546,8 +67776,7 @@ DUK_UNREF(entry_valstack_end_byteoff); - DUK_DDD(DUK_DDDPRINT("not a tail call, pushing a new activation to callstack, to index %ld", - (long) (thr->callstack_top))); + DUK_DDD(DUK_DDDPRINT("not a tail call, pushing a new activation to callstack, to index %ld", (long) (thr->callstack_top))); duk__call_callstack_limit_check(thr); new_act = duk_hthread_activation_alloc(thr); @@ -66574,7 +67803,7 @@ act = new_act; *out_act = act; - DUK_ASSERT(thr->valstack_top > thr->valstack_bottom); /* at least effective 'this' */ + DUK_ASSERT(thr->valstack_top > thr->valstack_bottom); /* at least effective 'this' */ DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); act->cat = NULL; @@ -66593,9 +67822,9 @@ } /* start of arguments: idx_func + 2. */ - act->func = func; /* NULL for lightfunc */ + act->func = func; /* NULL for lightfunc */ if (DUK_LIKELY(func != NULL)) { - DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ + DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ if (DUK_HOBJECT_HAS_STRICT(func)) { act->flags |= DUK_ACT_FLAG_STRICT; } @@ -66604,8 +67833,9 @@ *out_nregs = ((duk_hcompfunc *) func)->nregs; DUK_ASSERT(*out_nregs >= 0); DUK_ASSERT(*out_nregs >= *out_nargs); - *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); } else { /* True because of call target lookup checks. */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(func)); @@ -66613,13 +67843,16 @@ *out_nargs = ((duk_hnatfunc *) func)->nargs; *out_nregs = *out_nargs; if (*out_nargs >= 0) { - *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); } else { /* Vararg function. */ - duk_size_t valstack_top_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); - *out_vs_min_bytes = valstack_top_byteoff + - sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + duk_size_t valstack_top_byteoff = + (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); + *out_vs_min_bytes = valstack_top_byteoff + sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + + DUK_VALSTACK_INTERNAL_EXTRA); } } } else { @@ -66630,18 +67863,20 @@ tv_func = DUK_GET_TVAL_POSIDX(thr, idx_func); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(tv_func)); - DUK_TVAL_SET_TVAL(&act->tv_func, tv_func); /* borrowed, no refcount */ + DUK_TVAL_SET_TVAL(&act->tv_func, tv_func); /* borrowed, no refcount */ lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv_func); *out_nargs = DUK_LFUNC_FLAGS_GET_NARGS(lf_flags); if (*out_nargs != DUK_LFUNC_NARGS_VARARGS) { *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nargs + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nargs + + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); } else { - duk_size_t valstack_top_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); + duk_size_t valstack_top_byteoff = + (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); *out_vs_min_bytes = valstack_top_byteoff + - sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); - *out_nargs = -1; /* vararg */ + sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + *out_nargs = -1; /* vararg */ } *out_nregs = *out_nargs; } @@ -66663,13 +67898,13 @@ * even in error unwind because reserve_byteoff is only used when * returning to -this- activation. */ - act->reserve_byteoff = 0; /* filled in by caller */ + act->reserve_byteoff = 0; /* filled in by caller */ /* XXX: Is this INCREF necessary? 'func' is always a borrowed * reference reachable through the value stack? If changed, stack * unwind code also needs to be fixed to match. */ - DUK_HOBJECT_INCREF_ALLOWNULL(thr, func); /* act->func */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, func); /* act->func */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) if (func) { @@ -66685,7 +67920,7 @@ DUK_LOCAL void duk__call_env_setup(duk_hthread *thr, duk_hobject *func, duk_activation *act, duk_idx_t idx_args) { duk_hobject *env; - DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound function has already been resolved */ + DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound function has already been resolved */ if (DUK_LIKELY(func != NULL)) { if (DUK_LIKELY(DUK_HOBJECT_HAS_NEWENV(func))) { @@ -66716,7 +67951,7 @@ act->lex_env = env; act->var_env = env; DUK_HOBJECT_INCREF(thr, env); - DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (2) directly */ + DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (2) directly */ duk_pop(thr); } } else { @@ -66754,8 +67989,7 @@ goto thread_state_error; } } else { - DUK_ASSERT(thr->heap->curr_thread == NULL || - thr->heap->curr_thread->state == DUK_HTHREAD_STATE_RUNNING); + DUK_ASSERT(thr->heap->curr_thread == NULL || thr->heap->curr_thread->state == DUK_HTHREAD_STATE_RUNNING); if (DUK_UNLIKELY(thr->state != DUK_HTHREAD_STATE_INACTIVE)) { goto thread_state_error; } @@ -66770,7 +68004,7 @@ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); return; - thread_state_error: +thread_state_error: DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "invalid thread state (%ld)", (long) thr->state); DUK_WO_NORETURN(return;); } @@ -66796,9 +68030,7 @@ * place; the only guarantee is that the state is consistent for unwinding. */ -DUK_LOCAL duk_int_t duk__handle_call_raw(duk_hthread *thr, - duk_idx_t idx_func, - duk_small_uint_t call_flags) { +DUK_LOCAL duk_int_t duk__handle_call_raw(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags) { #if defined(DUK_USE_ASSERTIONS) duk_activation *entry_act; duk_size_t entry_callstack_top; @@ -66810,10 +68042,10 @@ duk_uint_fast8_t entry_thread_state; duk_instr_t **entry_ptr_curr_pc; duk_idx_t idx_args; - duk_idx_t nargs; /* # argument registers target function wants (< 0 => "as is") */ - duk_idx_t nregs; /* # total registers target function wants on entry (< 0 => "as is") */ - duk_size_t vs_min_bytes; /* minimum value stack size (bytes) for handling call */ - duk_hobject *func; /* 'func' on stack (borrowed reference) */ + duk_idx_t nargs; /* # argument registers target function wants (< 0 => "as is") */ + duk_idx_t nregs; /* # total registers target function wants on entry (< 0 => "as is") */ + duk_size_t vs_min_bytes; /* minimum value stack size (bytes) for handling call */ + duk_hobject *func; /* 'func' on stack (borrowed reference) */ duk_activation *act; duk_ret_t rc; duk_small_uint_t use_tailcall; @@ -66854,7 +68086,7 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(tmp_cat) == DUK_CAT_TYPE_LABEL); /* a non-catching entry */ } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Store entry state. @@ -66867,9 +68099,9 @@ entry_valstack_bottom_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack); entry_valstack_end_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); entry_call_recursion_depth = thr->heap->call_recursion_depth; - entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ + entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ entry_thread_state = thr->state; - entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ + entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ /* If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL * thr->ptr_curr_pc so that it's not accidentally used with an incorrect @@ -66937,11 +68169,10 @@ DUK_DDD(DUK_DDDPRINT("slow path target resolve")); func = duk__resolve_target_func_and_this_binding(thr, idx_func, &call_flags); } - DUK_ASSERT(duk_get_top(thr) - idx_func >= 2); /* at least func and this present */ + DUK_ASSERT(duk_get_top(thr) - idx_func >= 2); /* at least func and this present */ DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || - DUK_HOBJECT_IS_NATFUNC(func))); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || DUK_HOBJECT_IS_NATFUNC(func))); /* ... func this arg1 ... argN */ @@ -66976,7 +68207,7 @@ &act); } #else - DUK_ASSERT((call_flags & DUK_CALL_FLAG_TAILCALL) == 0); /* compiler ensures this */ + DUK_ASSERT((call_flags & DUK_CALL_FLAG_TAILCALL) == 0); /* compiler ensures this */ use_tailcall = 0; #endif @@ -67003,6 +68234,15 @@ /* ... func this arg1 ... argN */ /* + * Grow value stack to required size before env setup. This + * must happen before env setup to handle some corner cases + * correctly, e.g. test-bug-scope-segv-gh2448.js. + */ + + duk_valstack_grow_check_throw(thr, vs_min_bytes); + act->reserve_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); + + /* * Environment record creation and 'arguments' object creation. * Named function expression name binding is handled by the * compiler; the compiled function's parent env will contain @@ -67023,13 +68263,8 @@ * Setup value stack: clamp to 'nargs', fill up to 'nregs', * ensure value stack size matches target requirements, and * switch value stack bottom. Valstack top is kept. - * - * Value stack can only grow here. */ - duk_valstack_grow_check_throw(thr, vs_min_bytes); - act->reserve_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); - if (use_tailcall) { DUK_ASSERT(nregs >= 0); DUK_ASSERT(nregs >= nargs); @@ -67068,8 +68303,8 @@ DUK_ASSERT((act->flags & DUK_ACT_FLAG_PREVENT_YIELD) == 0); DUK_REFZERO_CHECK_FAST(thr); DUK_ASSERT(thr->ptr_curr_pc == NULL); - thr->heap->call_recursion_depth--; /* No recursion increase for this case. */ - return 1; /* 1=reuse executor */ + thr->heap->call_recursion_depth--; /* No recursion increase for this case. */ + return 1; /* 1=reuse executor */ } DUK_ASSERT(use_tailcall == 0); @@ -67193,7 +68428,7 @@ /* Explicit check for fastint downgrade. */ DUK_TVAL_CHKFAST_INPLACE_FAST(tv_funret); #endif - DUK_TVAL_SET_TVAL_UPDREF(thr, tv_ret, tv_funret); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv_ret, tv_funret); /* side effects */ } duk_set_top_unsafe(thr, idx_func + 1); @@ -67212,7 +68447,7 @@ /* Restore entry thread executor curr_pc stack frame pointer. */ thr->ptr_curr_pc = entry_ptr_curr_pc; - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; /* Disabled assert: triggered with some torture tests. */ @@ -67253,12 +68488,10 @@ DUK_REFZERO_CHECK_FAST(thr); - return 0; /* 0=call handled inline */ + return 0; /* 0=call handled inline */ } -DUK_INTERNAL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, - duk_idx_t nargs, - duk_small_uint_t call_flags) { +DUK_INTERNAL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags) { duk_idx_t idx_func; DUK_ASSERT(duk_get_top(thr) >= nargs + 2); idx_func = duk_get_top(thr) - (nargs + 2); @@ -67266,9 +68499,7 @@ return duk_handle_call_unprotected(thr, idx_func, call_flags); } -DUK_INTERNAL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, - duk_idx_t idx_func, - duk_small_uint_t call_flags) { +DUK_INTERNAL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags) { DUK_ASSERT(duk_is_valid_index(thr, idx_func)); DUK_ASSERT(idx_func >= 0); return duk__handle_call_raw(thr, idx_func, call_flags); @@ -67335,7 +68566,8 @@ /* we're running inside the caller's activation, so no change in call/catch stack or valstack bottom */ DUK_ASSERT(thr->callstack_top == entry_callstack_top); DUK_ASSERT(thr->valstack_bottom >= thr->valstack); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == entry_valstack_bottom_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == + entry_valstack_bottom_byteoff); DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); DUK_ASSERT(thr->valstack_end >= thr->valstack_top); @@ -67345,9 +68577,9 @@ } DUK_ASSERT(rc >= 0); - duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, rc); /* throws for insane rc */ + duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, rc); /* throws for insane rc */ - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; } @@ -67400,7 +68632,7 @@ /* Switch active thread before any side effects to avoid a * dangling curr_thread pointer. */ - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; DUK_ASSERT(thr->heap->curr_thread == entry_curr_thread); @@ -67416,9 +68648,9 @@ /* ... | (crud) errobj */ - DUK_ASSERT(duk_get_top(thr) >= 1); /* at least errobj must be on stack */ + DUK_ASSERT(duk_get_top(thr) >= 1); /* at least errobj must be on stack */ - duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, 1); /* 1 = num actual 'return values' */ + duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, 1); /* 1 = num actual 'return values' */ /* ... | or ... | errobj (M * undefined) where M = num_stack_rets - 1 */ @@ -67504,7 +68736,7 @@ duk_int_t retval; DUK_ASSERT(thr != NULL); - DUK_ASSERT(duk_get_top(thr) >= num_stack_args); /* Caller ensures. */ + DUK_ASSERT(duk_get_top(thr) >= num_stack_args); /* Caller ensures. */ DUK_STATS_INC(thr->heap, stats_safecall_all); @@ -67523,14 +68755,14 @@ entry_callstack_preventcount = thr->callstack_preventcount; #endif entry_call_recursion_depth = thr->heap->call_recursion_depth; - entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ + entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ entry_thread_state = thr->state; - entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ - idx_retbase = duk_get_top(thr) - num_stack_args; /* not a valid stack index if num_stack_args == 0 */ + entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ + idx_retbase = duk_get_top(thr) - num_stack_args; /* not a valid stack index if num_stack_args == 0 */ DUK_ASSERT(idx_retbase >= 0); - DUK_ASSERT((duk_idx_t) (thr->valstack_top - thr->valstack_bottom) >= num_stack_args); /* Caller ensures. */ - DUK_ASSERT((duk_idx_t) (thr->valstack_end - (thr->valstack_bottom + idx_retbase)) >= num_stack_rets); /* Caller ensures. */ + DUK_ASSERT((duk_idx_t) (thr->valstack_top - thr->valstack_bottom) >= num_stack_args); /* Caller ensures. */ + DUK_ASSERT((duk_idx_t) (thr->valstack_end - (thr->valstack_bottom + idx_retbase)) >= num_stack_rets); /* Caller ensures. */ /* Cannot portably debug print a function pointer, hence 'func' not printed! */ DUK_DD(DUK_DDPRINT("duk_handle_safe_call: thr=%p, num_stack_args=%ld, num_stack_rets=%ld, " @@ -67590,7 +68822,8 @@ * whatever calls are made. Reserve cannot decrease. */ DUK_ASSERT(thr->callstack_curr == entry_act); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); retval = DUK_EXEC_SUCCESS; #if defined(DUK_USE_CPP_EXCEPTIONS) @@ -67600,7 +68833,8 @@ } else { /* Error path. */ #endif - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); @@ -67625,14 +68859,18 @@ throw; } catch (std::exception &exc) { const char *what = exc.what(); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); if (!what) { what = "unknown"; } DUK_D(DUK_DPRINT("unexpected c++ std::exception (perhaps thrown by user code)")); try { - DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", what); + DUK_ERROR_FMT1(thr, + DUK_ERR_TYPE_ERROR, + "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", + what); DUK_WO_NORETURN(return 0;); } catch (duk_internal_exception exc) { DUK_D(DUK_DPRINT("caught api error thrown from unexpected c++ std::exception")); @@ -67652,7 +68890,8 @@ } } catch (...) { DUK_D(DUK_DPRINT("unexpected c++ exception (perhaps thrown by user code)")); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); try { DUK_ERROR_TYPE(thr, "caught invalid c++ exception (perhaps thrown by user code)"); @@ -67676,7 +68915,7 @@ } #endif - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr == old_jmpbuf_ptr); /* success/error path both do this */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr == old_jmpbuf_ptr); /* success/error path both do this */ DUK_ASSERT_LJSTATE_UNSET(thr->heap); @@ -67697,7 +68936,8 @@ /* Final asserts. */ DUK_ASSERT(thr->callstack_curr == entry_act); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == entry_valstack_bottom_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == + entry_valstack_bottom_byteoff); DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); DUK_ASSERT(thr->callstack_top == entry_callstack_top); DUK_ASSERT(thr->heap->call_recursion_depth == entry_call_recursion_depth); @@ -67758,8 +68998,11 @@ str_base = duk_get_type_name(thr, -3); duk_push_error_object(thr, DUK_ERR_TYPE_ERROR | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - "%s not callable (property %s of %s)", str_targ, str_key, str_base); - duk_xdef_prop_stridx(thr, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ + "%s not callable (property %s of %s)", + str_targ, + str_key, + str_base); + duk_xdef_prop_stridx(thr, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ /* <nargs> target base key { _Target: error } */ duk_replace(thr, entry_top - 1); #else @@ -67768,9 +69011,12 @@ str_base = duk_push_string_readable(thr, -5); duk_push_error_object(thr, DUK_ERR_TYPE_ERROR | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - "%s not callable (property %s of %s)", str_targ, str_key, str_base); + "%s not callable (property %s of %s)", + str_targ, + str_key, + str_base); /* <nargs> target base key {} str_targ str_key str_base error */ - duk_xdef_prop_stridx(thr, -5, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ + duk_xdef_prop_stridx(thr, -5, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ /* <nargs> target base key { _Target: error } str_targ str_key str_base */ duk_swap(thr, -4, entry_top - 1); /* <nargs> { _Target: error } base key target str_targ str_key str_base */ @@ -67780,9 +69026,9 @@ duk_set_top(thr, entry_top); /* <nregs> { _Target: error } */ - DUK_ASSERT(!duk_is_callable(thr, -1)); /* Critical so that call handling will throw the error. */ + DUK_ASSERT(!duk_is_callable(thr, -1)); /* Critical so that call handling will throw the error. */ } -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* automatic undefs */ #undef DUK__AUGMENT_CALL_RELAX_COUNT @@ -67823,45 +69069,51 @@ * uses this approach to avoid an explicit DUK__ISREG() check (the condition is * logically "'x' is a register AND 'x' >= temp_first"). */ -#define DUK__CONST_MARKER DUK_REGCONST_CONST_MARKER -#define DUK__REMOVECONST(x) ((x) & ~DUK__CONST_MARKER) -#define DUK__ISREG(x) ((x) >= 0) -#define DUK__ISCONST(x) ((x) < 0) -#define DUK__ISREG_TEMP(comp_ctx,x) ((duk_int32_t) (x) >= (duk_int32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= temp_first && x >= 0 by comparing as signed. */ -#define DUK__ISREG_NOTTEMP(comp_ctx,x) ((duk_uint32_t) (x) < (duk_uint32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= 0 && x < temp_first by interpreting as unsigned. */ -#define DUK__GETTEMP(comp_ctx) ((comp_ctx)->curr_func.temp_next) -#define DUK__SETTEMP(comp_ctx,x) ((comp_ctx)->curr_func.temp_next = (x)) /* dangerous: must only lower (temp_max not updated) */ -#define DUK__SETTEMP_CHECKMAX(comp_ctx,x) duk__settemp_checkmax((comp_ctx),(x)) -#define DUK__ALLOCTEMP(comp_ctx) duk__alloctemp((comp_ctx)) -#define DUK__ALLOCTEMPS(comp_ctx,count) duk__alloctemps((comp_ctx),(count)) +#define DUK__CONST_MARKER DUK_REGCONST_CONST_MARKER +#define DUK__REMOVECONST(x) ((x) & ~DUK__CONST_MARKER) +#define DUK__ISREG(x) ((x) >= 0) +#define DUK__ISCONST(x) ((x) < 0) +#define DUK__ISREG_TEMP(comp_ctx, x) \ + ((duk_int32_t) (x) >= \ + (duk_int32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= temp_first && x >= 0 by comparing as signed. */ +#define DUK__ISREG_NOTTEMP(comp_ctx, x) \ + ((duk_uint32_t) (x) < \ + (duk_uint32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= 0 && x < temp_first by interpreting as unsigned. */ +#define DUK__GETTEMP(comp_ctx) ((comp_ctx)->curr_func.temp_next) +#define DUK__SETTEMP(comp_ctx, x) ((comp_ctx)->curr_func.temp_next = (x)) /* dangerous: must only lower (temp_max not updated) */ +#define DUK__SETTEMP_CHECKMAX(comp_ctx, x) duk__settemp_checkmax((comp_ctx), (x)) +#define DUK__ALLOCTEMP(comp_ctx) duk__alloctemp((comp_ctx)) +#define DUK__ALLOCTEMPS(comp_ctx, count) duk__alloctemps((comp_ctx), (count)) /* Init value set size for array and object literals. */ -#define DUK__MAX_ARRAY_INIT_VALUES 20 -#define DUK__MAX_OBJECT_INIT_PAIRS 10 +#define DUK__MAX_ARRAY_INIT_VALUES 20 +#define DUK__MAX_OBJECT_INIT_PAIRS 10 /* XXX: hack, remove when const lookup is not O(n) */ -#define DUK__GETCONST_MAX_CONSTS_CHECK 256 +#define DUK__GETCONST_MAX_CONSTS_CHECK 256 /* These limits are based on bytecode limits. Max temps is limited * by duk_hcompfunc nargs/nregs fields being 16 bits. */ -#define DUK__MAX_CONSTS DUK_BC_BC_MAX -#define DUK__MAX_FUNCS DUK_BC_BC_MAX -#define DUK__MAX_TEMPS 0xffffL +#define DUK__MAX_CONSTS DUK_BC_BC_MAX +#define DUK__MAX_FUNCS DUK_BC_BC_MAX +#define DUK__MAX_TEMPS 0xffffL /* Initial bytecode size allocation. */ #if defined(DUK_USE_PREFER_SIZE) -#define DUK__BC_INITIAL_INSTS 16 +#define DUK__BC_INITIAL_INSTS 16 #else -#define DUK__BC_INITIAL_INSTS 256 +#define DUK__BC_INITIAL_INSTS 256 #endif -#define DUK__RECURSION_INCREASE(comp_ctx,thr) do { \ +#define DUK__RECURSION_INCREASE(comp_ctx, thr) \ + do { \ DUK_DDD(DUK_DDDPRINT("RECURSION INCREASE: %s:%ld", (const char *) DUK_FILE_MACRO, (long) DUK_LINE_MACRO)); \ duk__comp_recursion_increase((comp_ctx)); \ } while (0) -#define DUK__RECURSION_DECREASE(comp_ctx,thr) do { \ +#define DUK__RECURSION_DECREASE(comp_ctx, thr) \ + do { \ DUK_DDD(DUK_DDDPRINT("RECURSION DECREASE: %s:%ld", (const char *) DUK_FILE_MACRO, (long) DUK_LINE_MACRO)); \ duk__comp_recursion_decrease((comp_ctx)); \ } while (0) @@ -67869,11 +69121,11 @@ /* Value stack slot limits: these are quite approximate right now, and * because they overlap in control flow, some could be eliminated. */ -#define DUK__COMPILE_ENTRY_SLOTS 8 -#define DUK__FUNCTION_INIT_REQUIRE_SLOTS 16 -#define DUK__FUNCTION_BODY_REQUIRE_SLOTS 16 -#define DUK__PARSE_STATEMENTS_SLOTS 16 -#define DUK__PARSE_EXPR_SLOTS 16 +#define DUK__COMPILE_ENTRY_SLOTS 8 +#define DUK__FUNCTION_INIT_REQUIRE_SLOTS 16 +#define DUK__FUNCTION_BODY_REQUIRE_SLOTS 16 +#define DUK__PARSE_STATEMENTS_SLOTS 16 +#define DUK__PARSE_EXPR_SLOTS 16 /* Temporary structure used to pass a stack allocated region through * duk_safe_call(). @@ -67905,10 +69157,14 @@ DUK_LOCAL_DECL duk_compiler_instr *duk__get_instr_ptr(duk_compiler_ctx *comp_ctx, duk_int_t pc); DUK_LOCAL_DECL void duk__emit(duk_compiler_ctx *comp_ctx, duk_instr_t ins); DUK_LOCAL_DECL void duk__emit_op_only(duk_compiler_ctx *comp_ctx, duk_small_uint_t op); -DUK_LOCAL_DECL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b, duk_regconst_t c); +DUK_LOCAL_DECL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, + duk_small_uint_t op_flags, + duk_regconst_t a, + duk_regconst_t b, + duk_regconst_t c); DUK_LOCAL_DECL void duk__emit_a_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b); DUK_LOCAL_DECL void duk__emit_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b, duk_regconst_t c); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL void duk__emit_a(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a); DUK_LOCAL_DECL void duk__emit_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b); #endif @@ -67922,7 +69178,12 @@ DUK_LOCAL_DECL void duk__insert_jump_entry(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc); DUK_LOCAL_DECL void duk__patch_jump(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc, duk_int_t target_pc); DUK_LOCAL_DECL void duk__patch_jump_here(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc); -DUK_LOCAL_DECL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, duk_int_t ldconst_pc, duk_int_t trycatch_pc, duk_regconst_t reg_catch, duk_regconst_t const_varname, duk_small_uint_t flags); +DUK_LOCAL_DECL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, + duk_int_t ldconst_pc, + duk_int_t trycatch_pc, + duk_regconst_t reg_catch, + duk_regconst_t const_varname, + duk_small_uint_t flags); DUK_LOCAL_DECL void duk__emit_if_false_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst); DUK_LOCAL_DECL void duk__emit_if_true_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst); DUK_LOCAL_DECL void duk__emit_invalid(duk_compiler_ctx *comp_ctx); @@ -67953,7 +69214,7 @@ duk_regconst_t forced_reg, duk_small_uint_t flags); DUK_LOCAL_DECL duk_regconst_t duk__ivalue_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *x); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__ivalue_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *x); #endif DUK_LOCAL_DECL void duk__ivalue_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *x, duk_int_t forced_reg); @@ -67967,7 +69228,13 @@ /* label handling */ DUK_LOCAL_DECL void duk__add_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_int_t pc_label, duk_int_t label_id); DUK_LOCAL_DECL void duk__update_label_flags(duk_compiler_ctx *comp_ctx, duk_int_t label_id, duk_small_uint_t flags); -DUK_LOCAL_DECL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_bool_t is_break, duk_int_t *out_label_id, duk_int_t *out_label_catch_depth, duk_int_t *out_label_pc, duk_bool_t *out_is_closest); +DUK_LOCAL_DECL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, + duk_hstring *h_label, + duk_bool_t is_break, + duk_int_t *out_label_id, + duk_int_t *out_label_catch_depth, + duk_int_t *out_label_pc, + duk_bool_t *out_is_closest); DUK_LOCAL_DECL void duk__reset_labels_to_length(duk_compiler_ctx *comp_ctx, duk_size_t len); /* top-down expression parser */ @@ -67981,26 +69248,32 @@ DUK_LOCAL_DECL void duk__exprtop(duk_compiler_ctx *ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); /* convenience helpers */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -DUK_LOCAL_DECL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg); +DUK_LOCAL_DECL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg); DUK_LOCAL_DECL duk_regconst_t duk__expr_toregconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_totempconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif DUK_LOCAL_DECL void duk__expr_toplain(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); DUK_LOCAL_DECL void duk__expr_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); DUK_LOCAL_DECL duk_regconst_t duk__exprtop_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__exprtop_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -DUK_LOCAL_DECL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg); +DUK_LOCAL_DECL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg); DUK_LOCAL_DECL duk_regconst_t duk__exprtop_toregconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL void duk__exprtop_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif @@ -68010,7 +69283,11 @@ DUK_LOCAL_DECL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res); /* statement parsing */ -DUK_LOCAL_DECL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags, duk_regconst_t *out_reg_varbind, duk_regconst_t *out_rc_varname); +DUK_LOCAL_DECL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t expr_flags, + duk_regconst_t *out_reg_varbind, + duk_regconst_t *out_rc_varname); DUK_LOCAL_DECL void duk__parse_var_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags); DUK_LOCAL_DECL void duk__parse_for_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site); DUK_LOCAL_DECL void duk__parse_switch_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site); @@ -68024,18 +69301,25 @@ DUK_LOCAL_DECL void duk__parse_with_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res); DUK_LOCAL_DECL void duk__parse_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_bool_t allow_source_elem); DUK_LOCAL_DECL duk_int_t duk__stmt_label_site(duk_compiler_ctx *comp_ctx, duk_int_t label_id); -DUK_LOCAL_DECL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, duk_bool_t allow_source_elem, duk_bool_t expect_eof, duk_bool_t regexp_after); - -DUK_LOCAL_DECL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, duk_bool_t expect_eof, duk_bool_t implicit_return_value, duk_bool_t regexp_after, duk_small_int_t expect_token); +DUK_LOCAL_DECL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, + duk_bool_t allow_source_elem, + duk_bool_t expect_eof, + duk_bool_t regexp_after); + +DUK_LOCAL_DECL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, + duk_bool_t expect_eof, + duk_bool_t implicit_return_value, + duk_bool_t regexp_after, + duk_small_int_t expect_token); DUK_LOCAL_DECL void duk__parse_func_formals(duk_compiler_ctx *comp_ctx); DUK_LOCAL_DECL void duk__parse_func_like_raw(duk_compiler_ctx *comp_ctx, duk_small_uint_t flags); DUK_LOCAL_DECL duk_int_t duk__parse_func_like_fnum(duk_compiler_ctx *comp_ctx, duk_small_uint_t flags); -#define DUK__FUNC_FLAG_DECL (1 << 0) /* Parsing a function declaration. */ -#define DUK__FUNC_FLAG_GETSET (1 << 1) /* Parsing an object literal getter/setter. */ -#define DUK__FUNC_FLAG_METDEF (1 << 2) /* Parsing an object literal method definition shorthand. */ -#define DUK__FUNC_FLAG_PUSHNAME_PASS1 (1 << 3) /* Push function name when creating template (first pass only). */ -#define DUK__FUNC_FLAG_USE_PREVTOKEN (1 << 4) /* Use prev_token to start function parsing (workaround for object literal). */ +#define DUK__FUNC_FLAG_DECL (1 << 0) /* Parsing a function declaration. */ +#define DUK__FUNC_FLAG_GETSET (1 << 1) /* Parsing an object literal getter/setter. */ +#define DUK__FUNC_FLAG_METDEF (1 << 2) /* Parsing an object literal method definition shorthand. */ +#define DUK__FUNC_FLAG_PUSHNAME_PASS1 (1 << 3) /* Push function name when creating template (first pass only). */ +#define DUK__FUNC_FLAG_USE_PREVTOKEN (1 << 4) /* Use prev_token to start function parsing (workaround for object literal). */ /* * Parser control values for tokens. The token table is ordered by the @@ -68052,141 +69336,141 @@ /* XXX: actually single step levels would work just fine, clean up */ /* binding power "levels" (see doc/compiler.rst) */ -#define DUK__BP_INVALID 0 /* always terminates led() */ -#define DUK__BP_EOF 2 -#define DUK__BP_CLOSING 4 /* token closes expression, e.g. ')', '' */ -#define DUK__BP_FOR_EXPR DUK__BP_CLOSING /* bp to use when parsing a top level Expression */ -#define DUK__BP_COMMA 6 -#define DUK__BP_ASSIGNMENT 8 -#define DUK__BP_CONDITIONAL 10 -#define DUK__BP_LOR 12 -#define DUK__BP_LAND 14 -#define DUK__BP_BOR 16 -#define DUK__BP_BXOR 18 -#define DUK__BP_BAND 20 -#define DUK__BP_EQUALITY 22 -#define DUK__BP_RELATIONAL 24 -#define DUK__BP_SHIFT 26 -#define DUK__BP_ADDITIVE 28 -#define DUK__BP_MULTIPLICATIVE 30 -#define DUK__BP_EXPONENTIATION 32 -#define DUK__BP_POSTFIX 34 -#define DUK__BP_CALL 36 -#define DUK__BP_MEMBER 38 +#define DUK__BP_INVALID 0 /* always terminates led() */ +#define DUK__BP_EOF 2 +#define DUK__BP_CLOSING 4 /* token closes expression, e.g. ')', '' */ +#define DUK__BP_FOR_EXPR DUK__BP_CLOSING /* bp to use when parsing a top level Expression */ +#define DUK__BP_COMMA 6 +#define DUK__BP_ASSIGNMENT 8 +#define DUK__BP_CONDITIONAL 10 +#define DUK__BP_LOR 12 +#define DUK__BP_LAND 14 +#define DUK__BP_BOR 16 +#define DUK__BP_BXOR 18 +#define DUK__BP_BAND 20 +#define DUK__BP_EQUALITY 22 +#define DUK__BP_RELATIONAL 24 +#define DUK__BP_SHIFT 26 +#define DUK__BP_ADDITIVE 28 +#define DUK__BP_MULTIPLICATIVE 30 +#define DUK__BP_EXPONENTIATION 32 +#define DUK__BP_POSTFIX 34 +#define DUK__BP_CALL 36 +#define DUK__BP_MEMBER 38 #define DUK__TOKEN_LBP_BP_MASK 0x1f -#define DUK__TOKEN_LBP_FLAG_NO_REGEXP (1 << 5) /* regexp literal must not follow this token */ -#define DUK__TOKEN_LBP_FLAG_TERMINATES (1 << 6) /* terminates expression; e.g. post-increment/-decrement */ -#define DUK__TOKEN_LBP_FLAG_UNUSED (1 << 7) /* unused */ +#define DUK__TOKEN_LBP_FLAG_NO_REGEXP (1 << 5) /* regexp literal must not follow this token */ +#define DUK__TOKEN_LBP_FLAG_TERMINATES (1 << 6) /* terminates expression; e.g. post-increment/-decrement */ +#define DUK__TOKEN_LBP_FLAG_UNUSED (1 << 7) /* unused */ -#define DUK__TOKEN_LBP_GET_BP(x) ((duk_small_uint_t) (((x) & DUK__TOKEN_LBP_BP_MASK) * 2)) +#define DUK__TOKEN_LBP_GET_BP(x) ((duk_small_uint_t) (((x) &DUK__TOKEN_LBP_BP_MASK) * 2)) -#define DUK__MK_LBP(bp) ((bp) >> 1) /* bp is assumed to be even */ -#define DUK__MK_LBP_FLAGS(bp,flags) (((bp) >> 1) | (flags)) +#define DUK__MK_LBP(bp) ((bp) >> 1) /* bp is assumed to be even */ +#define DUK__MK_LBP_FLAGS(bp, flags) (((bp) >> 1) | (flags)) DUK_LOCAL const duk_uint8_t duk__token_lbp = { - DUK__MK_LBP(DUK__BP_EOF), /* DUK_TOK_EOF */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_IDENTIFIER */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BREAK */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CASE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CATCH */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONTINUE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEBUGGER */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEFAULT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DELETE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DO */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ELSE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FINALLY */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FOR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FUNCTION */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IF */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_IN */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_INSTANCEOF */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_NEW */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_RETURN */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SWITCH */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_THIS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_THROW */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TRY */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TYPEOF */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VAR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONST */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VOID */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WHILE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WITH */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CLASS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ENUM */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXPORT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXTENDS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPORT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SUPER */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NULL */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_TRUE */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_FALSE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_GET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPLEMENTS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_INTERFACE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PACKAGE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PRIVATE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PROTECTED */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PUBLIC */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_STATIC */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_YIELD */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LCURLY */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RCURLY */ - DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_LBRACKET */ - DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RBRACKET */ - DUK__MK_LBP(DUK__BP_CALL), /* DUK_TOK_LPAREN */ - DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RPAREN */ - DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_PERIOD */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SEMICOLON */ - DUK__MK_LBP(DUK__BP_COMMA), /* DUK_TOK_COMMA */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LT */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GT */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LE */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GE */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_EQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_NEQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SEQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SNEQ */ - DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_ADD */ - DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_SUB */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MUL */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_DIV */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MOD */ - DUK__MK_LBP(DUK__BP_EXPONENTIATION), /* DUK_TOK_EXP */ - DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_INCREMENT */ - DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_DECREMENT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ALSHIFT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ARSHIFT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_RSHIFT */ - DUK__MK_LBP(DUK__BP_BAND), /* DUK_TOK_BAND */ - DUK__MK_LBP(DUK__BP_BOR), /* DUK_TOK_BOR */ - DUK__MK_LBP(DUK__BP_BXOR), /* DUK_TOK_BXOR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LNOT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BNOT */ - DUK__MK_LBP(DUK__BP_LAND), /* DUK_TOK_LAND */ - DUK__MK_LBP(DUK__BP_LOR), /* DUK_TOK_LOR */ - DUK__MK_LBP(DUK__BP_CONDITIONAL), /* DUK_TOK_QUESTION */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_COLON */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EQUALSIGN */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ADD_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_SUB_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MUL_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_DIV_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MOD_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EXP_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ALSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ARSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_RSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BAND_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BOR_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BXOR_EQ */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NUMBER */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_STRING */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_REGEXP */ + DUK__MK_LBP(DUK__BP_EOF), /* DUK_TOK_EOF */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_IDENTIFIER */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BREAK */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CASE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CATCH */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONTINUE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEBUGGER */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEFAULT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DELETE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DO */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ELSE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FINALLY */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FOR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FUNCTION */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IF */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_IN */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_INSTANCEOF */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_NEW */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_RETURN */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SWITCH */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_THIS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_THROW */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TRY */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TYPEOF */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VAR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONST */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VOID */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WHILE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WITH */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CLASS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ENUM */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXPORT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXTENDS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPORT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SUPER */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NULL */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_TRUE */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_FALSE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_GET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPLEMENTS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_INTERFACE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PACKAGE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PRIVATE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PROTECTED */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PUBLIC */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_STATIC */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_YIELD */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LCURLY */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RCURLY */ + DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_LBRACKET */ + DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RBRACKET */ + DUK__MK_LBP(DUK__BP_CALL), /* DUK_TOK_LPAREN */ + DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RPAREN */ + DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_PERIOD */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SEMICOLON */ + DUK__MK_LBP(DUK__BP_COMMA), /* DUK_TOK_COMMA */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LT */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GT */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LE */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GE */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_EQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_NEQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SEQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SNEQ */ + DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_ADD */ + DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_SUB */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MUL */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_DIV */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MOD */ + DUK__MK_LBP(DUK__BP_EXPONENTIATION), /* DUK_TOK_EXP */ + DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_INCREMENT */ + DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_DECREMENT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ALSHIFT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ARSHIFT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_RSHIFT */ + DUK__MK_LBP(DUK__BP_BAND), /* DUK_TOK_BAND */ + DUK__MK_LBP(DUK__BP_BOR), /* DUK_TOK_BOR */ + DUK__MK_LBP(DUK__BP_BXOR), /* DUK_TOK_BXOR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LNOT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BNOT */ + DUK__MK_LBP(DUK__BP_LAND), /* DUK_TOK_LAND */ + DUK__MK_LBP(DUK__BP_LOR), /* DUK_TOK_LOR */ + DUK__MK_LBP(DUK__BP_CONDITIONAL), /* DUK_TOK_QUESTION */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_COLON */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EQUALSIGN */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ADD_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_SUB_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MUL_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_DIV_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MOD_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EXP_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ALSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ARSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_RSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BAND_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BOR_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BXOR_EQ */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NUMBER */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_STRING */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_REGEXP */ }; /* @@ -68217,8 +69501,7 @@ DUK_LOCAL duk_bool_t duk__hstring_is_eval_or_arguments_in_strict_mode(duk_compiler_ctx *comp_ctx, duk_hstring *h) { DUK_ASSERT(h != NULL); - return (comp_ctx->curr_func.is_strict && - DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(h)); + return (comp_ctx->curr_func.is_strict && DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(h)); } /* @@ -68233,8 +69516,8 @@ duk_hthread *thr = comp_ctx->thr; duk_bool_t regexp; - DUK_ASSERT_DISABLE(comp_ctx->curr_token.t >= 0); /* unsigned */ - DUK_ASSERT(comp_ctx->curr_token.t <= DUK_TOK_MAXVAL); /* MAXVAL is inclusive */ + DUK_ASSERT_DISABLE(comp_ctx->curr_token.t >= 0); /* unsigned */ + DUK_ASSERT(comp_ctx->curr_token.t <= DUK_TOK_MAXVAL); /* MAXVAL is inclusive */ /* * Use current token to decide whether a RegExp can follow. @@ -68259,8 +69542,7 @@ } if (expect >= 0 && comp_ctx->curr_token.t != (duk_small_uint_t) expect) { - DUK_D(DUK_DPRINT("parse error: expect=%ld, got=%ld", - (long) expect, (long) comp_ctx->curr_token.t)); + DUK_D(DUK_DPRINT("parse error: expect=%ld, got=%ld", (long) expect, (long) comp_ctx->curr_token.t)); DUK_ERROR_SYNTAX(thr, DUK_STR_PARSE_ERROR); DUK_WO_NORETURN(return;); } @@ -68271,10 +69553,7 @@ duk_copy(thr, comp_ctx->tok12_idx, comp_ctx->tok22_idx); /* parse new token */ - duk_lexer_parse_js_input_element(&comp_ctx->lex, - &comp_ctx->curr_token, - comp_ctx->curr_func.is_strict, - regexp); + duk_lexer_parse_js_input_element(&comp_ctx->lex, &comp_ctx->curr_token, comp_ctx->curr_func.is_strict, regexp); DUK_DDD(DUK_DDDPRINT("advance: curr: tok=%ld/%ld,%ld,term=%ld,%!T,%!T " "prev: tok=%ld/%ld,%ld,term=%ld,%!T,%!T", @@ -68314,7 +69593,7 @@ entry_top = duk_get_top(thr); - duk_memzero(func, sizeof(*func)); /* intentional overlap with earlier memzero */ + duk_memzero(func, sizeof(*func)); /* intentional overlap with earlier memzero */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) func->h_name = NULL; func->h_consts = NULL; @@ -68480,7 +69759,7 @@ h_res = duk_push_hcompfunc(thr); DUK_ASSERT(h_res != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_res) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); - DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) h_res, NULL); /* Function templates are "bare objects". */ + DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) h_res, NULL); /* Function templates are "bare objects". */ if (func->is_function) { DUK_DDD(DUK_DDDPRINT("function -> set NEWENV")); @@ -68549,16 +69828,19 @@ code_count = DUK_BW_GET_SIZE(thr, &func->bw_code) / sizeof(duk_compiler_instr); code_size = code_count * sizeof(duk_instr_t); - data_size = consts_count * sizeof(duk_tval) + - funcs_count * sizeof(duk_hobject *) + - code_size; + data_size = consts_count * sizeof(duk_tval) + funcs_count * sizeof(duk_hobject *) + code_size; DUK_DDD(DUK_DDDPRINT("consts_count=%ld, funcs_count=%ld, code_size=%ld -> " "data_size=%ld*%ld + %ld*%ld + %ld = %ld", - (long) consts_count, (long) funcs_count, (long) code_size, - (long) consts_count, (long) sizeof(duk_tval), - (long) funcs_count, (long) sizeof(duk_hobject *), - (long) code_size, (long) data_size)); + (long) consts_count, + (long) funcs_count, + (long) code_size, + (long) consts_count, + (long) sizeof(duk_tval), + (long) funcs_count, + (long) sizeof(duk_hobject *), + (long) code_size, + (long) data_size)); duk_push_fixed_buffer_nozero(thr, data_size); h_data = (duk_hbuffer_fixed *) (void *) duk_known_hbuffer(thr, -1); @@ -68568,12 +69850,12 @@ p_const = (duk_tval *) (void *) DUK_HBUFFER_FIXED_GET_DATA_PTR(thr->heap, h_data); for (i = 0; i < consts_count; i++) { - DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* const limits */ + DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* const limits */ tv = duk_hobject_find_array_entry_tval_ptr(thr->heap, func->h_consts, (duk_uarridx_t) i); DUK_ASSERT(tv != NULL); DUK_TVAL_SET_TVAL(p_const, tv); p_const++; - DUK_TVAL_INCREF(thr, tv); /* may be a string constant */ + DUK_TVAL_INCREF(thr, tv); /* may be a string constant */ DUK_DDD(DUK_DDDPRINT("constant: %!T", (duk_tval *) tv)); } @@ -68582,7 +69864,7 @@ DUK_HCOMPFUNC_SET_FUNCS(thr->heap, h_res, p_func); for (i = 0; i < funcs_count; i++) { duk_hobject *h; - DUK_ASSERT(i * 3 <= DUK_UARRIDX_MAX); /* func limits */ + DUK_ASSERT(i * 3 <= DUK_UARRIDX_MAX); /* func limits */ tv = duk_hobject_find_array_entry_tval_ptr(thr->heap, func->h_funcs, (duk_uarridx_t) (i * 3)); DUK_ASSERT(tv != NULL); DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv)); @@ -68592,8 +69874,7 @@ *p_func++ = h; DUK_HOBJECT_INCREF(thr, h); - DUK_DDD(DUK_DDDPRINT("inner function: %p -> %!iO", - (void *) h, (duk_heaphdr *) h)); + DUK_DDD(DUK_DDDPRINT("inner function: %p -> %!iO", (void *) h, (duk_heaphdr *) h)); } p_instr = (duk_instr_t *) p_func; @@ -68608,7 +69889,7 @@ DUK_ASSERT((duk_uint8_t *) (p_instr + code_count) == DUK_HBUFFER_FIXED_GET_DATA_PTR(thr->heap, h_data) + data_size); - duk_pop(thr); /* 'data' (and everything in it) is reachable through h_res now */ + duk_pop(thr); /* 'data' (and everything in it) is reachable through h_res now */ /* * Init non-property result fields @@ -68623,7 +69904,7 @@ DUK_ASSERT(func->temp_max >= 0); h_res->nregs = (duk_uint16_t) func->temp_max; h_res->nargs = (duk_uint16_t) duk_hobject_get_length(thr, func->h_argnames); - DUK_ASSERT(h_res->nregs >= h_res->nargs); /* pass2 allocation handles this */ + DUK_ASSERT(h_res->nregs >= h_res->nargs); /* pass2 allocation handles this */ #if defined(DUK_USE_DEBUGGER_SUPPORT) h_res->start_line = (duk_uint32_t) func->min_line; h_res->end_line = (duk_uint32_t) func->max_line; @@ -68651,11 +69932,13 @@ DUK_DD(DUK_DDPRINT("keeping _Varmap because debugger support is enabled")); keep_varmap = 1; #else - if (func->id_access_slow_own || /* directly uses slow accesses that may match own variables */ - func->id_access_arguments || /* accesses 'arguments' directly */ - func->may_direct_eval || /* may indirectly slow access through a direct eval */ - funcs_count > 0) { /* has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions) */ - DUK_DD(DUK_DDPRINT("keeping _Varmap because of direct eval, slow path access that may match local variables, or presence of inner functions")); + if (func->id_access_slow_own || /* directly uses slow accesses that may match own variables */ + func->id_access_arguments || /* accesses 'arguments' directly */ + func->may_direct_eval || /* may indirectly slow access through a direct eval */ + funcs_count > + 0) { /* has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions) */ + DUK_DD(DUK_DDPRINT("keeping _Varmap because of direct eval, slow path access that may match local variables, or " + "presence of inner functions")); keep_varmap = 1; } else { DUK_DD(DUK_DDPRINT("dropping _Varmap")); @@ -68667,8 +69950,7 @@ duk_int_t num_used; duk_dup(thr, func->varmap_idx); num_used = duk__cleanup_varmap(comp_ctx); - DUK_DDD(DUK_DDDPRINT("cleaned up varmap: %!T (num_used=%ld)", - (duk_tval *) duk_get_tval(thr, -1), (long) num_used)); + DUK_DDD(DUK_DDDPRINT("cleaned up varmap: %!T (num_used=%ld)", (duk_tval *) duk_get_tval(thr, -1), (long) num_used)); if (num_used > 0) { duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VARMAP, DUK_PROPDESC_FLAGS_NONE); @@ -68697,12 +69979,12 @@ */ DUK_DD(DUK_DDPRINT("keeping _Formals because _Formals.length != nargs")); keep_formals = 1; - } else if ((func->id_access_arguments || func->may_direct_eval) && - (formals_length > 0)) { + } else if ((func->id_access_arguments || func->may_direct_eval) && (formals_length > 0)) { /* Direct eval (may access 'arguments') or accesses 'arguments' * explicitly: keep _Formals unless it is zero length. */ - DUK_DD(DUK_DDPRINT("keeping _Formals because of direct eval or explicit access to 'arguments', and _Formals.length != 0")); + DUK_DD(DUK_DDPRINT( + "keeping _Formals because of direct eval or explicit access to 'arguments', and _Formals.length != 0")); keep_formals = 1; } else { DUK_DD(DUK_DDPRINT("omitting _Formals, nargs matches _Formals.length, so no properties added")); @@ -68722,7 +70004,7 @@ DUK_DD(DUK_DDPRINT("setting function template .name to %!T", duk_get_tval(thr, -1))); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_NONE); } -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ /* _Source */ #if defined(DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY) @@ -68770,7 +70052,7 @@ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_SOURCE, DUK_PROPDESC_FLAGS_NONE); #endif } -#endif /* DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY */ +#endif /* DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY */ /* _Pc2line */ #if defined(DUK_USE_PC2LINE) @@ -68780,14 +70062,14 @@ */ DUK_ASSERT(code_count <= DUK_COMPILER_MAX_BYTECODE_LENGTH); - duk_hobject_pc2line_pack(thr, q_instr, (duk_uint_fast32_t) code_count); /* -> pushes fixed buffer */ + duk_hobject_pc2line_pack(thr, q_instr, (duk_uint_fast32_t) code_count); /* -> pushes fixed buffer */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_NONE); /* XXX: if assertions enabled, walk through all valid PCs * and check line mapping. */ } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ /* fileName */ #if defined(DUK_USE_FUNC_FILENAME_PROPERTY) @@ -68801,8 +70083,7 @@ } #endif - DUK_DD(DUK_DDPRINT("converted function: %!ixT", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DD(DUK_DDPRINT("converted function: %!ixT", (duk_tval *) duk_get_tval(thr, -1))); /* * Compact the function template. @@ -68874,14 +70155,14 @@ /* Code emission flags, passed in the 'opcode' field. Opcode + flags * fit into 16 bits for now, so use duk_small_uint_t. */ -#define DUK__EMIT_FLAG_NO_SHUFFLE_A (1 << 8) -#define DUK__EMIT_FLAG_NO_SHUFFLE_B (1 << 9) -#define DUK__EMIT_FLAG_NO_SHUFFLE_C (1 << 10) -#define DUK__EMIT_FLAG_A_IS_SOURCE (1 << 11) /* slot A is a source (default: target) */ -#define DUK__EMIT_FLAG_B_IS_TARGET (1 << 12) /* slot B is a target (default: source) */ -#define DUK__EMIT_FLAG_C_IS_TARGET (1 << 13) /* slot C is a target (default: source) */ -#define DUK__EMIT_FLAG_BC_REGCONST (1 << 14) /* slots B and C are reg/const */ -#define DUK__EMIT_FLAG_RESERVE_JUMPSLOT (1 << 15) /* reserve a jumpslot after instr before target spilling, used for NEXTENUM */ +#define DUK__EMIT_FLAG_NO_SHUFFLE_A (1 << 8) +#define DUK__EMIT_FLAG_NO_SHUFFLE_B (1 << 9) +#define DUK__EMIT_FLAG_NO_SHUFFLE_C (1 << 10) +#define DUK__EMIT_FLAG_A_IS_SOURCE (1 << 11) /* slot A is a source (default: target) */ +#define DUK__EMIT_FLAG_B_IS_TARGET (1 << 12) /* slot B is a target (default: source) */ +#define DUK__EMIT_FLAG_C_IS_TARGET (1 << 13) /* slot C is a target (default: source) */ +#define DUK__EMIT_FLAG_BC_REGCONST (1 << 14) /* slots B and C are reg/const */ +#define DUK__EMIT_FLAG_RESERVE_JUMPSLOT (1 << 15) /* reserve a jumpslot after instr before target spilling, used for NEXTENUM */ /* XXX: macro smaller than call? */ DUK_LOCAL duk_int_t duk__get_current_pc(duk_compiler_ctx *comp_ctx) { @@ -68892,7 +70173,8 @@ DUK_LOCAL duk_compiler_instr *duk__get_instr_ptr(duk_compiler_ctx *comp_ctx, duk_int_t pc) { DUK_ASSERT(pc >= 0); - DUK_ASSERT((duk_size_t) pc < (duk_size_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr))); + DUK_ASSERT((duk_size_t) pc < + (duk_size_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr))); return ((duk_compiler_instr *) (void *) DUK_BW_GET_BASEPTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code)) + pc; } @@ -68912,7 +70194,9 @@ (long) duk__get_current_pc(comp_ctx), (duk_instr_t) ins)); - instr = (duk_compiler_instr *) (void *) DUK_BW_ENSURE_GETPTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, sizeof(duk_compiler_instr)); + instr = (duk_compiler_instr *) (void *) DUK_BW_ENSURE_GETPTR(comp_ctx->thr, + &comp_ctx->curr_func.bw_code, + sizeof(duk_compiler_instr)); DUK_BW_ADD_PTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, sizeof(duk_compiler_instr)); #if defined(DUK_USE_PC2LINE) @@ -68963,7 +70247,7 @@ return; - fail_bc_limit: +fail_bc_limit: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_BYTECODE_LIMIT); DUK_WO_NORETURN(return;); } @@ -68997,7 +70281,11 @@ } /* Important main primitive. */ -DUK_LOCAL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b, duk_regconst_t c) { +DUK_LOCAL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, + duk_small_uint_t op_flags, + duk_regconst_t a, + duk_regconst_t b, + duk_regconst_t c) { duk_instr_t ins = 0; duk_int_t a_out = -1; duk_int_t b_out = -1; @@ -69005,8 +70293,7 @@ duk_int_t tmp; duk_small_uint_t op = op_flags & 0xffU; - DUK_DDD(DUK_DDDPRINT("emit: op_flags=%04lx, a=%ld, b=%ld, c=%ld", - (unsigned long) op_flags, (long) a, (long) b, (long) c)); + DUK_DDD(DUK_DDDPRINT("emit: op_flags=%04lx, a=%ld, b=%ld, c=%ld", (unsigned long) op_flags, (long) a, (long) b, (long) c)); /* We could rely on max temp/const checks: if they don't exceed BC * limit, nothing here can either (just asserts would be enough). @@ -69015,11 +70302,11 @@ * bugs. */ - DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT((op_flags & 0xff) <= DUK_BC_OP_MAX); DUK_ASSERT(DUK__ISREG(a)); - DUK_ASSERT(b != -1); /* Not 'none'. */ - DUK_ASSERT(c != -1); /* Not 'none'. */ + DUK_ASSERT(b != -1); /* Not 'none'. */ + DUK_ASSERT(c != -1); /* Not 'none'. */ /* Input shuffling happens before the actual operation, while output * shuffling happens afterwards. Output shuffling decisions are still @@ -69081,7 +70368,7 @@ if (op_flags & DUK__EMIT_FLAG_BC_REGCONST) { /* Opcode follows B/C reg/const convention. */ DUK_ASSERT((op & 0x01) == 0); - ins |= DUK_ENC_OP_A_B_C(0x01, 0, 0, 0); /* const flag for B */ + ins |= DUK_ENC_OP_A_B_C(0x01, 0, 0, 0); /* const flag for B */ } else { DUK_D(DUK_DPRINT("B is const, opcode is not B/C reg/const: %x", op_flags)); } @@ -69104,7 +70391,8 @@ } else if (op_flags & DUK__EMIT_FLAG_NO_SHUFFLE_B) { if (b > DUK_BC_B_MAX) { /* Note: 0xff != DUK_BC_B_MAX */ - DUK_D(DUK_DPRINT("out of regs: 'b' (reg) needs shuffling but shuffle prohibited, b: %ld", (long) b)); + DUK_D( + DUK_DPRINT("out of regs: 'b' (reg) needs shuffling but shuffle prohibited, b: %ld", (long) b)); goto error_outofregs; } } else if (b <= DUK_BC_BC_MAX) { @@ -69125,7 +70413,7 @@ duk__emit_load_int32_noshuffle(comp_ctx, tmp, b); DUK_ASSERT(DUK_OP_MPUTOBJI == DUK_OP_MPUTOBJ + 1); DUK_ASSERT(DUK_OP_MPUTARRI == DUK_OP_MPUTARR + 1); - op_flags++; /* indirect opcode follows direct */ + op_flags++; /* indirect opcode follows direct */ } else { duk__emit(comp_ctx, DUK_ENC_OP_A_BC(DUK_OP_LDREG, tmp, b)); } @@ -69151,7 +70439,7 @@ if (op_flags & DUK__EMIT_FLAG_BC_REGCONST) { /* Opcode follows B/C reg/const convention. */ DUK_ASSERT((op & 0x02) == 0); - ins |= DUK_ENC_OP_A_B_C(0x02, 0, 0, 0); /* const flag for C */ + ins |= DUK_ENC_OP_A_B_C(0x02, 0, 0, 0); /* const flag for C */ } else { DUK_D(DUK_DPRINT("C is const, opcode is not B/C reg/const: %x", op_flags)); } @@ -69174,7 +70462,8 @@ } else if (op_flags & DUK__EMIT_FLAG_NO_SHUFFLE_C) { if (c > DUK_BC_C_MAX) { /* Note: 0xff != DUK_BC_C_MAX */ - DUK_D(DUK_DPRINT("out of regs: 'c' (reg) needs shuffling but shuffle prohibited, c: %ld", (long) c)); + DUK_D( + DUK_DPRINT("out of regs: 'c' (reg) needs shuffling but shuffle prohibited, c: %ld", (long) c)); goto error_outofregs; } } else if (c <= DUK_BC_BC_MAX) { @@ -69248,7 +70537,7 @@ return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -69276,7 +70565,7 @@ duk__emit_a_b_c(comp_ctx, op_flags, 0, b, c); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__emit_a(duk_compiler_ctx *comp_ctx, int op_flags, int a) { #if defined(DUK_USE_SHUFFLE_TORTURE) op_flags |= DUK__EMIT_FLAG_NO_SHUFFLE_B | DUK__EMIT_FLAG_NO_SHUFFLE_C; @@ -69285,7 +70574,7 @@ } #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__emit_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b) { #if defined(DUK_USE_SHUFFLE_TORTURE) op_flags |= DUK__EMIT_FLAG_NO_SHUFFLE_A | DUK__EMIT_FLAG_NO_SHUFFLE_C; @@ -69299,10 +70588,10 @@ duk_int_t tmp; /* allow caller to give a const number with the DUK__CONST_MARKER */ - DUK_ASSERT(bc != -1); /* Not 'none'. */ + DUK_ASSERT(bc != -1); /* Not 'none'. */ bc = bc & (~DUK__CONST_MARKER); - DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT((op_flags & 0xff) <= DUK_BC_OP_MAX); DUK_ASSERT(bc >= DUK_BC_BC_MIN); DUK_ASSERT(bc <= DUK_BC_BC_MAX); @@ -69347,7 +70636,7 @@ } return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -69362,12 +70651,12 @@ DUK_LOCAL void duk__emit_abc(duk_compiler_ctx *comp_ctx, duk_small_uint_t op, duk_regconst_t abc) { duk_instr_t ins; - DUK_ASSERT_DISABLE(op >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE(op >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT(op <= DUK_BC_OP_MAX); - DUK_ASSERT_DISABLE(abc >= DUK_BC_ABC_MIN); /* unsigned */ + DUK_ASSERT_DISABLE(abc >= DUK_BC_ABC_MIN); /* unsigned */ DUK_ASSERT(abc <= DUK_BC_ABC_MAX); DUK_ASSERT((abc & DUK__CONST_MARKER) == 0); - DUK_ASSERT(abc != -1); /* Not 'none'. */ + DUK_ASSERT(abc != -1); /* Not 'none'. */ if (abc <= DUK_BC_ABC_MAX) { ; @@ -69376,18 +70665,25 @@ } ins = DUK_ENC_OP_ABC(op, abc); DUK_DDD(DUK_DDDPRINT("duk__emit_abc: 0x%08lx line=%ld pc=%ld op=%ld (%!X) abc=%ld (%!I)", - (unsigned long) ins, (long) comp_ctx->curr_token.start_line, - (long) duk__get_current_pc(comp_ctx), (long) op, (long) op, - (long) abc, (duk_instr_t) ins)); + (unsigned long) ins, + (long) comp_ctx->curr_token.start_line, + (long) duk__get_current_pc(comp_ctx), + (long) op, + (long) op, + (long) abc, + (duk_instr_t) ins)); duk__emit(comp_ctx, ins); return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } -DUK_LOCAL void duk__emit_load_int32_raw(duk_compiler_ctx *comp_ctx, duk_regconst_t reg, duk_int32_t val, duk_small_uint_t op_flags) { +DUK_LOCAL void duk__emit_load_int32_raw(duk_compiler_ctx *comp_ctx, + duk_regconst_t reg, + duk_int32_t val, + duk_small_uint_t op_flags) { /* XXX: Shuffling support could be implemented here so that LDINT+LDINTX * would only shuffle once (instead of twice). The current code works * though, and has a smaller compiler footprint. @@ -69402,7 +70698,10 @@ duk_int32_t lo = val & ((((duk_int32_t) 1) << DUK_BC_LDINTX_SHIFT) - 1); DUK_ASSERT(lo >= 0); DUK_DDD(DUK_DDDPRINT("emit LDINT+LDINTX to reg %ld for %ld -> hi %ld, lo %ld", - (long) reg, (long) val, (long) hi, (long) lo)); + (long) reg, + (long) val, + (long) hi, + (long) lo)); duk__emit_a_bc(comp_ctx, DUK_OP_LDINT | op_flags, reg, (duk_regconst_t) (hi + (duk_int32_t) DUK_BC_LDINT_BIAS)); duk__emit_a_bc(comp_ctx, DUK_OP_LDINTX | op_flags, reg, (duk_regconst_t) lo); } @@ -69443,7 +70742,7 @@ DUK_LOCAL duk_int_t duk__emit_jump_empty(duk_compiler_ctx *comp_ctx) { duk_int_t ret; - ret = duk__get_current_pc(comp_ctx); /* useful for patching jumps later */ + ret = duk__get_current_pc(comp_ctx); /* useful for patching jumps later */ duk__emit_op_only(comp_ctx, DUK_OP_JUMP); return ret; } @@ -69461,13 +70760,10 @@ DUK_ASSERT(jump_pc >= 0); offset = (duk_size_t) jump_pc * sizeof(duk_compiler_instr); instr = (duk_compiler_instr *) (void *) - DUK_BW_INSERT_ENSURE_AREA(comp_ctx->thr, - &comp_ctx->curr_func.bw_code, - offset, - sizeof(duk_compiler_instr)); + DUK_BW_INSERT_ENSURE_AREA(comp_ctx->thr, &comp_ctx->curr_func.bw_code, offset, sizeof(duk_compiler_instr)); #if defined(DUK_USE_PC2LINE) - line = comp_ctx->curr_token.start_line; /* approximation, close enough */ + line = comp_ctx->curr_token.start_line; /* approximation, close enough */ #endif instr->ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, 0); #if defined(DUK_USE_PC2LINE) @@ -69480,7 +70776,7 @@ } return; - fail_bc_limit: +fail_bc_limit: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_BYTECODE_LIMIT); DUK_WO_NORETURN(return;); } @@ -69494,8 +70790,8 @@ /* allow negative PCs, behave as a no-op */ if (jump_pc < 0) { - DUK_DDD(DUK_DDDPRINT("duk__patch_jump(): nop call, jump_pc=%ld (<0), target_pc=%ld", - (long) jump_pc, (long) target_pc)); + DUK_DDD( + DUK_DDDPRINT("duk__patch_jump(): nop call, jump_pc=%ld (<0), target_pc=%ld", (long) jump_pc, (long) target_pc)); return; } DUK_ASSERT(jump_pc >= 0); @@ -69509,14 +70805,21 @@ instr->ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, offset + DUK_BC_JUMP_BIAS); DUK_DDD(DUK_DDDPRINT("duk__patch_jump(): jump_pc=%ld, target_pc=%ld, offset=%ld", - (long) jump_pc, (long) target_pc, (long) offset)); + (long) jump_pc, + (long) target_pc, + (long) offset)); } DUK_LOCAL void duk__patch_jump_here(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc) { duk__patch_jump(comp_ctx, jump_pc, duk__get_current_pc(comp_ctx)); } -DUK_LOCAL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, duk_int_t ldconst_pc, duk_int_t trycatch_pc, duk_regconst_t reg_catch, duk_regconst_t const_varname, duk_small_uint_t flags) { +DUK_LOCAL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, + duk_int_t ldconst_pc, + duk_int_t trycatch_pc, + duk_regconst_t reg_catch, + duk_regconst_t const_varname, + duk_small_uint_t flags) { duk_compiler_instr *instr; DUK_ASSERT(DUK__ISREG(reg_catch)); @@ -69536,7 +70839,10 @@ * See: test-bug-trycatch-many-constants.js. */ DUK_D(DUK_DPRINT("failed to patch trycatch: flags=%ld, reg_catch=%ld, const_varname=%ld (0x%08lx)", - (long) flags, (long) reg_catch, (long) const_varname, (long) const_varname)); + (long) flags, + (long) reg_catch, + (long) const_varname, + (long) const_varname)); DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -69559,14 +70865,14 @@ duk_small_uint_t op; op = DUK__ISREG(regconst) ? DUK_OP_IFFALSE_R : DUK_OP_IFFALSE_C; - duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ + duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ } DUK_LOCAL void duk__emit_if_true_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst) { duk_small_uint_t op; op = DUK__ISREG(regconst) ? DUK_OP_IFTRUE_R : DUK_OP_IFTRUE_C; - duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ + duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ } DUK_LOCAL void duk__emit_invalid(duk_compiler_ctx *comp_ctx) { @@ -69590,7 +70896,8 @@ #if defined(DUK_USE_BUFLEN16) /* No need to assert, buffer size maximum is 0xffff. */ #else - DUK_ASSERT((duk_size_t) DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr) <= (duk_size_t) DUK_INT_MAX); /* bytecode limits */ + DUK_ASSERT((duk_size_t) DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr) <= + (duk_size_t) DUK_INT_MAX); /* bytecode limits */ #endif n = (duk_int_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr)); @@ -69625,7 +70932,9 @@ target_pc2 = target_pc1 + 1 + (duk_int_t) DUK_DEC_ABC(ins) - (duk_int_t) DUK_BC_JUMP_BIAS; DUK_DDD(DUK_DDDPRINT("optimizing jump at pc %ld; old target is %ld -> new target is %ld", - (long) i, (long) target_pc1, (long) target_pc2)); + (long) i, + (long) target_pc1, + (long) target_pc2)); bci.ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, target_pc2 - (i + 1) + DUK_BC_JUMP_BIAS); @@ -69651,15 +70960,21 @@ /* XXX: DUK__IVAL_FLAG_REQUIRE_SHORT is passed but not currently implemented * by ispec/ivalue operations. */ -#define DUK__IVAL_FLAG_ALLOW_CONST (1 << 0) /* allow a constant to be returned */ -#define DUK__IVAL_FLAG_REQUIRE_TEMP (1 << 1) /* require a (mutable) temporary as a result (or a const if allowed) */ -#define DUK__IVAL_FLAG_REQUIRE_SHORT (1 << 2) /* require a short (8-bit) reg/const which fits into bytecode B/C slot */ +#define DUK__IVAL_FLAG_ALLOW_CONST (1 << 0) /* allow a constant to be returned */ +#define DUK__IVAL_FLAG_REQUIRE_TEMP (1 << 1) /* require a (mutable) temporary as a result (or a const if allowed) */ +#define DUK__IVAL_FLAG_REQUIRE_SHORT (1 << 2) /* require a short (8-bit) reg/const which fits into bytecode B/C slot */ /* XXX: some code might benefit from DUK__SETTEMP_IFTEMP(thr,x) */ -#if 0 /* enable manually for dumping */ -#define DUK__DUMP_ISPEC(compctx,ispec) do { duk__dump_ispec((compctx), (ispec)); } while (0) -#define DUK__DUMP_IVALUE(compctx,ivalue) do { duk__dump_ivalue((compctx), (ivalue)); } while (0) +#if 0 /* enable manually for dumping */ +#define DUK__DUMP_ISPEC(compctx, ispec) \ + do { \ + duk__dump_ispec((compctx), (ispec)); \ + } while (0) +#define DUK__DUMP_IVALUE(compctx, ivalue) \ + do { \ + duk__dump_ivalue((compctx), (ivalue)); \ + } while (0) DUK_LOCAL void duk__dump_ispec(duk_compiler_ctx *comp_ctx, duk_ispec *x) { DUK_D(DUK_DPRINT("ispec dump: t=%ld regconst=0x%08lx, valstack_idx=%ld, value=%!T", @@ -69677,8 +70992,12 @@ duk_get_tval(comp_ctx->thr, x->x2.valstack_idx))); } #else -#define DUK__DUMP_ISPEC(comp_ctx,x) do {} while (0) -#define DUK__DUMP_IVALUE(comp_ctx,x) do {} while (0) +#define DUK__DUMP_ISPEC(comp_ctx, x) \ + do { \ + } while (0) +#define DUK__DUMP_IVALUE(comp_ctx, x) \ + do { \ + } while (0) #endif DUK_LOCAL void duk__ivalue_regconst(duk_ivalue *x, duk_regconst_t regconst) { @@ -69728,7 +71047,7 @@ res = comp_ctx->curr_func.temp_next; comp_ctx->curr_func.temp_next += num; - if (comp_ctx->curr_func.temp_next > DUK__MAX_TEMPS) { /* == DUK__MAX_TEMPS is OK */ + if (comp_ctx->curr_func.temp_next > DUK__MAX_TEMPS) { /* == DUK__MAX_TEMPS is OK */ DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_TEMP_LIMIT); DUK_WO_NORETURN(return 0;); } @@ -69781,8 +71100,7 @@ * constant for e.g. +0 and -0. */ if (duk_js_samevalue(tv1, tv2)) { - DUK_DDD(DUK_DDDPRINT("reused existing constant for %!T -> const index %ld", - (duk_tval *) tv1, (long) i)); + DUK_DDD(DUK_DDDPRINT("reused existing constant for %!T -> const index %ld", (duk_tval *) tv1, (long) i)); duk_pop(thr); return (duk_regconst_t) i | (duk_regconst_t) DUK__CONST_MARKER; } @@ -69793,9 +71111,8 @@ DUK_WO_NORETURN(return 0;); } - DUK_DDD(DUK_DDDPRINT("allocating new constant for %!T -> const index %ld", - (duk_tval *) tv1, (long) n)); - (void) duk_put_prop_index(thr, f->consts_idx, (duk_uarridx_t) n); /* invalidates tv1, tv2 */ + DUK_DDD(DUK_DDDPRINT("allocating new constant for %!T -> const index %ld", (duk_tval *) tv1, (long) n)); + (void) duk_put_prop_index(thr, f->consts_idx, (duk_uarridx_t) n); /* invalidates tv1, tv2 */ return (duk_regconst_t) n | (duk_regconst_t) DUK__CONST_MARKER; } @@ -69804,15 +71121,15 @@ duk_compiler_func *f = &comp_ctx->curr_func; duk_bool_t ret; - DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ + DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ (void) duk_get_prop_index(comp_ctx->thr, f->consts_idx, (duk_uarridx_t) rc); - ret = !duk_is_number(comp_ctx->thr, -1); /* now only number/string, so conservative check */ + ret = !duk_is_number(comp_ctx->thr, -1); /* now only number/string, so conservative check */ duk_pop(comp_ctx->thr); return ret; #else DUK_UNREF(comp_ctx); DUK_UNREF(rc); - DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ + DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ return 0; #endif } @@ -69875,9 +71192,7 @@ } case DUK_TAG_BOOLEAN: { duk_regconst_t dest = (forced_reg >= 0 ? forced_reg : DUK__ALLOCTEMP(comp_ctx)); - duk__emit_bc(comp_ctx, - (DUK_TVAL_GET_BOOLEAN(tv) ? DUK_OP_LDTRUE : DUK_OP_LDFALSE), - dest); + duk__emit_bc(comp_ctx, (DUK_TVAL_GET_BOOLEAN(tv) ? DUK_OP_LDTRUE : DUK_OP_LDFALSE), dest); return dest; } case DUK_TAG_POINTER: { @@ -69893,7 +71208,7 @@ DUK_UNREF(h); DUK_ASSERT(h != NULL); -#if 0 /* XXX: to be implemented? */ +#if 0 /* XXX: to be implemented? */ /* Use special opcodes to load short strings */ if (DUK_HSTRING_GET_BYTELEN(h) <= 2) { /* Encode into a single opcode (18 bits can encode 1-2 bytes + length indicator) */ @@ -69963,8 +71278,8 @@ return dest; } } - } /* end switch */ - goto fail_internal; /* never here */ + } /* end switch */ + goto fail_internal; /* never here */ } case DUK_ISPEC_REGCONST: { if (forced_reg >= 0) { @@ -69997,11 +71312,11 @@ return x->regconst; } default: { - break; /* never here */ + break; /* never here */ } } - fail_internal: +fail_internal: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); } @@ -70021,10 +71336,13 @@ DUK_DDD(DUK_DDDPRINT("duk__ivalue_toplain_raw(): x={t=%ld,op=%ld,x1={%ld:%ld:%!T},x2={%ld:%ld:%!T}}, " "forced_reg=%ld", - (long) x->t, (long) x->op, - (long) x->x1.t, (long) x->x1.regconst, + (long) x->t, + (long) x->op, + (long) x->x1.t, + (long) x->x1.regconst, (duk_tval *) duk_get_tval(thr, x->x1.valstack_idx), - (long) x->x2.t, (long) x->x2.regconst, + (long) x->x2.t, + (long) x->x2.regconst, (duk_tval *) duk_get_tval(thr, x->x2.valstack_idx), (long) forced_reg)); @@ -70050,9 +71368,7 @@ DUK_ASSERT(tv1 != NULL); DUK_ASSERT(tv2 != NULL); - DUK_DDD(DUK_DDDPRINT("arith: tv1=%!T, tv2=%!T", - (duk_tval *) tv1, - (duk_tval *) tv2)); + DUK_DDD(DUK_DDDPRINT("arith: tv1=%!T, tv2=%!T", (duk_tval *) tv1, (duk_tval *) tv2)); if (DUK_TVAL_IS_NUMBER(tv1) && DUK_TVAL_IS_NUMBER(tv2)) { duk_double_t d1 = DUK_TVAL_GET_NUMBER(tv1); @@ -70061,7 +71377,9 @@ duk_bool_t accept_fold = 1; DUK_DDD(DUK_DDDPRINT("arith inline check: d1=%lf, d2=%lf, op=%ld", - (double) d1, (double) d2, (long) x->op)); + (double) d1, + (double) d2, + (long) x->op)); switch (x->op) { case DUK_OP_ADD: { d3 = d1 + d2; @@ -70087,7 +71405,7 @@ break; } default: { - d3 = 0.0; /* Won't be used, but silence MSVC /W4 warning. */ + d3 = 0.0; /* Won't be used, but silence MSVC /W4 warning. */ accept_fold = 0; break; } @@ -70101,7 +71419,7 @@ x->t = DUK_IVAL_PLAIN; DUK_ASSERT(x->x1.t == DUK_ISPEC_VALUE); - DUK_TVAL_SET_NUMBER(tv1, d3); /* old value is number: no refcount */ + DUK_TVAL_SET_NUMBER(tv1, d3); /* old value is number: no refcount */ return; } } else if (x->op == DUK_OP_ADD && DUK_TVAL_IS_STRING(tv1) && DUK_TVAL_IS_STRING(tv2)) { @@ -70118,8 +71436,14 @@ } } - arg1 = duk__ispec_toregconst_raw(comp_ctx, &x->x1, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); - arg2 = duk__ispec_toregconst_raw(comp_ctx, &x->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg1 = duk__ispec_toregconst_raw(comp_ctx, + &x->x1, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg2 = duk__ispec_toregconst_raw(comp_ctx, + &x->x2, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); /* If forced reg, use it as destination. Otherwise try to * use either coerced ispec if it is a temporary. @@ -70147,8 +71471,14 @@ duk_regconst_t dest; /* Need a short reg/const, does not have to be a mutable temp. */ - arg1 = duk__ispec_toregconst_raw(comp_ctx, &x->x1, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); - arg2 = duk__ispec_toregconst_raw(comp_ctx, &x->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg1 = duk__ispec_toregconst_raw(comp_ctx, + &x->x1, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg2 = duk__ispec_toregconst_raw(comp_ctx, + &x->x2, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); /* Pick a destination register. If either base value or key * happens to be a temp value, reuse it as the destination. @@ -70169,11 +71499,7 @@ dest = DUK__ALLOCTEMP(comp_ctx); } - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, - dest, - arg1, - arg2); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, dest, arg1, arg2); duk__ivalue_regconst(x, dest); return; @@ -70241,10 +71567,13 @@ DUK_DDD(DUK_DDDPRINT("duk__ivalue_toregconst_raw(): x={t=%ld,op=%ld,x1={%ld:%ld:%!T},x2={%ld:%ld:%!T}}, " "forced_reg=%ld, flags 0x%08lx: allow_const=%ld require_temp=%ld require_short=%ld", - (long) x->t, (long) x->op, - (long) x->x1.t, (long) x->x1.regconst, + (long) x->t, + (long) x->op, + (long) x->x1.t, + (long) x->x1.regconst, (duk_tval *) duk_get_tval(thr, x->x1.valstack_idx), - (long) x->x2.t, (long) x->x2.regconst, + (long) x->x2.t, + (long) x->x2.regconst, (duk_tval *) duk_get_tval(thr, x->x2.valstack_idx), (long) forced_reg, (unsigned long) flags, @@ -70267,7 +71596,7 @@ return duk__ivalue_toregconst_raw(comp_ctx, x, -1, 0 /*flags*/); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__ivalue_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *x) { return duk__ivalue_toregconst_raw(comp_ctx, x, -1, DUK__IVAL_FLAG_REQUIRE_TEMP /*flags*/); } @@ -70303,8 +71632,7 @@ duk_hstring *h_varname; duk_regconst_t ret; - DUK_DDD(DUK_DDDPRINT("resolving identifier reference to '%!T'", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("resolving identifier reference to '%!T'", (duk_tval *) duk_get_tval(thr, -1))); /* * Special name handling @@ -70357,13 +71685,13 @@ DUK_DDD(DUK_DDDPRINT("identifier lookup -> reg %ld", (long) ret)); return ret; - slow_path_notown: +slow_path_notown: DUK_DDD(DUK_DDDPRINT("identifier lookup -> slow path, not own variable")); comp_ctx->curr_func.id_access_slow = 1; return (duk_regconst_t) -1; - slow_path_own: +slow_path_own: DUK_DDD(DUK_DDDPRINT("identifier lookup -> slow path, may be own variable")); comp_ctx->curr_func.id_access_slow = 1; @@ -70391,7 +71719,7 @@ if (reg_varbind >= 0) { *out_reg_varbind = reg_varbind; - *out_rc_varname = 0; /* duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller) */ + *out_rc_varname = 0; /* duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller) */ duk_pop(thr); return 1; } else { @@ -70441,7 +71769,7 @@ } duk_push_hstring(thr, h_label); - DUK_ASSERT(n <= DUK_UARRIDX_MAX); /* label limits */ + DUK_ASSERT(n <= DUK_UARRIDX_MAX); /* label limits */ (void) duk_put_prop_index(thr, comp_ctx->curr_func.labelnames_idx, (duk_uarridx_t) n); new_size = (n + 1) * sizeof(duk_labelinfo); @@ -70451,7 +71779,7 @@ /* relookup after possible realloc */ p = (duk_uint8_t *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, comp_ctx->curr_func.h_labelinfos); li_start = (duk_labelinfo *) (void *) p; - DUK_UNREF(li_start); /* silence scan-build warning */ + DUK_UNREF(li_start); /* silence scan-build warning */ li = (duk_labelinfo *) (void *) (p + DUK_HBUFFER_GET_SIZE(comp_ctx->curr_func.h_labelinfos)); li--; @@ -70465,12 +71793,15 @@ li->flags = DUK_LABEL_FLAG_ALLOW_BREAK; li->label_id = label_id; li->h_label = h_label; - li->catch_depth = comp_ctx->curr_func.catch_depth; /* catch depth from current func */ + li->catch_depth = comp_ctx->curr_func.catch_depth; /* catch depth from current func */ li->pc_label = pc_label; DUK_DDD(DUK_DDDPRINT("registered label: flags=0x%08lx, id=%ld, name=%!O, catch_depth=%ld, pc_label=%ld", - (unsigned long) li->flags, (long) li->label_id, (duk_heaphdr *) li->h_label, - (long) li->catch_depth, (long) li->pc_label)); + (unsigned long) li->flags, + (long) li->label_id, + (duk_heaphdr *) li->h_label, + (long) li->catch_depth, + (long) li->pc_label)); } /* Update all labels with matching label_id. */ @@ -70494,7 +71825,9 @@ } DUK_DDD(DUK_DDDPRINT("updating (overwriting) label flags for li=%p, label_id=%ld, flags=%ld", - (void *) li, (long) label_id, (long) flags)); + (void *) li, + (long) label_id, + (long) flags)); li->flags = flags; } @@ -70515,14 +71848,19 @@ */ /* XXX: awkward, especially the bunch of separate output values -> output struct? */ -DUK_LOCAL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_bool_t is_break, duk_int_t *out_label_id, duk_int_t *out_label_catch_depth, duk_int_t *out_label_pc, duk_bool_t *out_is_closest) { +DUK_LOCAL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, + duk_hstring *h_label, + duk_bool_t is_break, + duk_int_t *out_label_id, + duk_int_t *out_label_catch_depth, + duk_int_t *out_label_pc, + duk_bool_t *out_is_closest) { duk_hthread *thr = comp_ctx->thr; duk_uint8_t *p; duk_labelinfo *li_start, *li_end, *li; duk_bool_t match = 0; - DUK_DDD(DUK_DDDPRINT("looking up active label: label='%!O', is_break=%ld", - (duk_heaphdr *) h_label, (long) is_break)); + DUK_DDD(DUK_DDDPRINT("looking up active label: label='%!O', is_break=%ld", (duk_heaphdr *) h_label, (long) is_break)); DUK_UNREF(thr); @@ -70546,7 +71884,8 @@ } DUK_DDD(DUK_DDDPRINT("labelinfo%ld -> '%!O' label name matches (still need to check type)", - (long) (li - li_start), (duk_heaphdr *) h_label)); + (long) (li - li_start), + (duk_heaphdr *) h_label)); /* currently all labels accept a break, so no explicit check for it now */ DUK_ASSERT(li->flags & DUK_LABEL_FLAG_ALLOW_BREAK); @@ -70580,8 +71919,10 @@ } DUK_DDD(DUK_DDDPRINT("label match: %!O -> label_id %ld, catch_depth=%ld, pc_label=%ld", - (duk_heaphdr *) h_label, (long) li->label_id, - (long) li->catch_depth, (long) li->pc_label)); + (duk_heaphdr *) h_label, + (long) li->label_id, + (long) li->catch_depth, + (long) li->pc_label)); *out_label_id = li->label_id; *out_label_catch_depth = li->catch_depth; @@ -70605,21 +71946,21 @@ */ /* object literal key tracking flags */ -#define DUK__OBJ_LIT_KEY_PLAIN (1 << 0) /* key encountered as a plain property */ -#define DUK__OBJ_LIT_KEY_GET (1 << 1) /* key encountered as a getter */ -#define DUK__OBJ_LIT_KEY_SET (1 << 2) /* key encountered as a setter */ +#define DUK__OBJ_LIT_KEY_PLAIN (1 << 0) /* key encountered as a plain property */ +#define DUK__OBJ_LIT_KEY_GET (1 << 1) /* key encountered as a getter */ +#define DUK__OBJ_LIT_KEY_SET (1 << 2) /* key encountered as a setter */ DUK_LOCAL void duk__nud_array_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; - duk_regconst_t reg_obj; /* result reg */ - duk_regconst_t reg_temp; /* temp reg */ - duk_regconst_t temp_start; /* temp reg value for start of loop */ - duk_small_uint_t max_init_values; /* max # of values initialized in one MPUTARR set */ - duk_small_uint_t num_values; /* number of values in current MPUTARR set */ - duk_uarridx_t curr_idx; /* current (next) array index */ - duk_uarridx_t start_idx; /* start array index of current MPUTARR set */ - duk_uarridx_t init_idx; /* last array index explicitly initialized, +1 */ - duk_bool_t require_comma; /* next loop requires a comma */ + duk_regconst_t reg_obj; /* result reg */ + duk_regconst_t reg_temp; /* temp reg */ + duk_regconst_t temp_start; /* temp reg value for start of loop */ + duk_small_uint_t max_init_values; /* max # of values initialized in one MPUTARR set */ + duk_small_uint_t num_values; /* number of values in current MPUTARR set */ + duk_uarridx_t curr_idx; /* current (next) array index */ + duk_uarridx_t start_idx; /* start array index of current MPUTARR set */ + duk_uarridx_t init_idx; /* last array index explicitly initialized, +1 */ + duk_bool_t require_comma; /* next loop requires a comma */ #if !defined(DUK_USE_PREFER_SIZE) duk_int_t pc_newarr; duk_compiler_instr *instr; @@ -70628,13 +71969,13 @@ /* DUK_TOK_LBRACKET already eaten, current token is right after that */ DUK_ASSERT(comp_ctx->prev_token.t == DUK_TOK_LBRACKET); - max_init_values = DUK__MAX_ARRAY_INIT_VALUES; /* XXX: depend on available temps? */ + max_init_values = DUK__MAX_ARRAY_INIT_VALUES; /* XXX: depend on available temps? */ reg_obj = DUK__ALLOCTEMP(comp_ctx); #if !defined(DUK_USE_PREFER_SIZE) pc_newarr = duk__get_current_pc(comp_ctx); #endif - duk__emit_bc(comp_ctx, DUK_OP_NEWARR, reg_obj); /* XXX: patch initial size hint afterwards? */ + duk__emit_bc(comp_ctx, DUK_OP_NEWARR, reg_obj); /* XXX: patch initial size hint afterwards? */ temp_start = DUK__GETTEMP(comp_ctx); /* @@ -70650,7 +71991,7 @@ */ curr_idx = 0; - init_idx = 0; /* tracks maximum initialized index + 1 */ + init_idx = 0; /* tracks maximum initialized index + 1 */ start_idx = 0; require_comma = 0; @@ -70696,7 +72037,7 @@ duk__emit_load_int32(comp_ctx, reg_temp, (duk_int32_t) start_idx); } - reg_temp = DUK__ALLOCTEMP(comp_ctx); /* alloc temp just in case, to update max temp */ + reg_temp = DUK__ALLOCTEMP(comp_ctx); /* alloc temp just in case, to update max temp */ DUK__SETTEMP(comp_ctx, reg_temp); duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); DUK__SETTEMP(comp_ctx, reg_temp + 1); @@ -70721,9 +72062,7 @@ * never needs to be. */ duk__emit_a_b_c(comp_ctx, - DUK_OP_MPUTARR | - DUK__EMIT_FLAG_NO_SHUFFLE_C | - DUK__EMIT_FLAG_A_IS_SOURCE, + DUK_OP_MPUTARR | DUK__EMIT_FLAG_NO_SHUFFLE_C | DUK__EMIT_FLAG_A_IS_SOURCE, reg_obj, temp_start, (duk_regconst_t) (num_values + 1)); @@ -70744,8 +72083,7 @@ DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RBRACKET); duk__advance(comp_ctx); - DUK_DDD(DUK_DDDPRINT("array literal done, curridx=%ld, initidx=%ld", - (long) curr_idx, (long) init_idx)); + DUK_DDD(DUK_DDDPRINT("array literal done, curridx=%ld, initidx=%ld", (long) curr_idx, (long) init_idx)); /* trailing elisions? */ if (curr_idx > init_idx) { @@ -70753,10 +72091,7 @@ DUK_DDD(DUK_DDDPRINT("array literal has trailing elisions which affect its length")); reg_temp = DUK__ALLOCTEMP(comp_ctx); duk__emit_load_int32(comp_ctx, reg_temp, (duk_int_t) curr_idx); - duk__emit_a_bc(comp_ctx, - DUK_OP_SETALEN | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_obj, - reg_temp); + duk__emit_a_bc(comp_ctx, DUK_OP_SETALEN | DUK__EMIT_FLAG_A_IS_SOURCE, reg_obj, reg_temp); } DUK__SETTEMP(comp_ctx, temp_start); @@ -70764,7 +72099,7 @@ duk__ivalue_regconst(res, reg_obj); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_ARRAY_LITERAL); DUK_WO_NORETURN(return;); } @@ -70788,9 +72123,7 @@ */ DUK_ASSERT(st->num_pairs > 0); duk__emit_a_b_c(comp_ctx, - DUK_OP_MPUTOBJ | - DUK__EMIT_FLAG_NO_SHUFFLE_C | - DUK__EMIT_FLAG_A_IS_SOURCE, + DUK_OP_MPUTOBJ | DUK__EMIT_FLAG_NO_SHUFFLE_C | DUK__EMIT_FLAG_A_IS_SOURCE, st->reg_obj, st->temp_start, (duk_regconst_t) (st->num_pairs * 2)); @@ -70809,7 +72142,7 @@ /* numbers can be loaded as numbers and coerced on the fly */ duk_push_number(comp_ctx->thr, tok->num); } else { - return 1; /* error */ + return 1; /* error */ } duk__ivalue_plain_fromstack(comp_ctx, res); @@ -70822,10 +72155,10 @@ DUK_LOCAL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; duk__objlit_state st; - duk_regconst_t reg_temp; /* temp reg */ - duk_small_uint_t max_init_pairs; /* max # of key-value pairs initialized in one MPUTOBJ set */ - duk_bool_t first; /* first value: comma must not precede the value */ - duk_bool_t is_set, is_get; /* temps */ + duk_regconst_t reg_temp; /* temp reg */ + duk_small_uint_t max_init_pairs; /* max # of key-value pairs initialized in one MPUTOBJ set */ + duk_bool_t first; /* first value: comma must not precede the value */ + duk_bool_t is_set, is_get; /* temps */ #if !defined(DUK_USE_PREFER_SIZE) duk_int_t pc_newobj; duk_compiler_instr *instr; @@ -70833,12 +72166,12 @@ DUK_ASSERT(comp_ctx->prev_token.t == DUK_TOK_LCURLY); - max_init_pairs = DUK__MAX_OBJECT_INIT_PAIRS; /* XXX: depend on available temps? */ + max_init_pairs = DUK__MAX_OBJECT_INIT_PAIRS; /* XXX: depend on available temps? */ - st.reg_obj = DUK__ALLOCTEMP(comp_ctx); /* target object */ - st.temp_start = DUK__GETTEMP(comp_ctx); /* start of MPUTOBJ argument list */ - st.num_pairs = 0; /* number of key/value pairs emitted for current MPUTOBJ set */ - st.num_total_pairs = 0; /* number of key/value pairs emitted overall */ + st.reg_obj = DUK__ALLOCTEMP(comp_ctx); /* target object */ + st.temp_start = DUK__GETTEMP(comp_ctx); /* start of MPUTOBJ argument list */ + st.num_pairs = 0; /* number of key/value pairs emitted for current MPUTOBJ set */ + st.num_total_pairs = 0; /* number of key/value pairs emitted overall */ #if !defined(DUK_USE_PREFER_SIZE) pc_newobj = duk__get_current_pc(comp_ctx); @@ -70877,8 +72210,7 @@ * worth the effort and would increase code size. */ - DUK_DDD(DUK_DDDPRINT("object literal loop, curr_token->t = %ld", - (long) comp_ctx->curr_token.t)); + DUK_DDD(DUK_DDDPRINT("object literal loop, curr_token->t = %ld", (long) comp_ctx->curr_token.t)); if (comp_ctx->curr_token.t == DUK_TOK_RCURLY) { break; @@ -70918,16 +72250,15 @@ * identifier string content. */ - is_get = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_GET(thr)); - is_set = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_SET(thr)); + is_get = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_GET(thr)); + is_set = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_SET(thr)); if ((is_get || is_set) && comp_ctx->curr_token.t != DUK_TOK_COLON) { /* getter/setter */ duk_int_t fnum; duk__objlit_flush_keys(comp_ctx, &st); - DUK_ASSERT(DUK__GETTEMP(comp_ctx) == st.temp_start); /* 2 regs are guaranteed to be allocated w.r.t. temp_max */ + DUK_ASSERT(DUK__GETTEMP(comp_ctx) == + st.temp_start); /* 2 regs are guaranteed to be allocated w.r.t. temp_max */ reg_temp = DUK__ALLOCTEMPS(comp_ctx, 2); if (duk__objlit_load_key(comp_ctx, res, &comp_ctx->curr_token, reg_temp) != 0) { @@ -70937,21 +72268,18 @@ /* curr_token = get/set name */ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_GETSET); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - st.temp_start + 1, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, st.temp_start + 1, (duk_regconst_t) fnum); /* Slot C is used in a non-standard fashion (range of regs), * emitter code has special handling for it (must not set the * "no shuffle" flag). */ duk__emit_a_bc(comp_ctx, - (is_get ? DUK_OP_INITGET : DUK_OP_INITSET) | DUK__EMIT_FLAG_A_IS_SOURCE, - st.reg_obj, - st.temp_start); /* temp_start+0 = key, temp_start+1 = closure */ + (is_get ? DUK_OP_INITGET : DUK_OP_INITSET) | DUK__EMIT_FLAG_A_IS_SOURCE, + st.reg_obj, + st.temp_start); /* temp_start+0 = key, temp_start+1 = closure */ - DUK_ASSERT(st.num_pairs == 0); /* temp state is reset on next loop */ + DUK_ASSERT(st.num_pairs == 0); /* temp state is reset on next loop */ #if defined(DUK_USE_ES6) } else if (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && (comp_ctx->curr_token.t == DUK_TOK_COMMA || comp_ctx->curr_token.t == DUK_TOK_RCURLY)) { @@ -70959,15 +72287,14 @@ load_rc = duk__objlit_load_key(comp_ctx, res, &comp_ctx->prev_token, reg_temp); DUK_UNREF(load_rc); - DUK_ASSERT(load_rc == 0); /* always succeeds because token is identifier */ + DUK_ASSERT(load_rc == 0); /* always succeeds because token is identifier */ duk__ivalue_var_hstring(comp_ctx, res, comp_ctx->prev_token.str1); DUK_ASSERT(DUK__GETTEMP(comp_ctx) == reg_temp + 1); duk__ivalue_toforcedreg(comp_ctx, res, reg_temp + 1); st.num_pairs++; - } else if ((comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER || - comp_ctx->prev_token.t == DUK_TOK_STRING || + } else if ((comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER || comp_ctx->prev_token.t == DUK_TOK_STRING || comp_ctx->prev_token.t == DUK_TOK_NUMBER) && comp_ctx->curr_token.t == DUK_TOK_LPAREN) { duk_int_t fnum; @@ -70985,13 +72312,10 @@ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_USE_PREVTOKEN | DUK__FUNC_FLAG_METDEF); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp + 1, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp + 1, (duk_regconst_t) fnum); st.num_pairs++; -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ } else { #if defined(DUK_USE_ES6) if (comp_ctx->prev_token.t == DUK_TOK_LBRACKET) { @@ -71008,9 +72332,8 @@ * form is not yet supported and causes a * SyntaxError on the DUK_TOK_COLON check below. */ - } - else -#endif /* DUK_USE_ES6 */ + } else +#endif /* DUK_USE_ES6 */ { if (duk__objlit_load_key(comp_ctx, res, &comp_ctx->prev_token, reg_temp) != 0) { goto syntax_error; @@ -71024,7 +72347,7 @@ st.num_pairs++; } - } /* property loop */ + } /* property loop */ /* Flush remaining properties. */ duk__objlit_flush_keys(comp_ctx, &st); @@ -71043,12 +72366,12 @@ #endif DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RCURLY); - duk__advance(comp_ctx); /* No RegExp after object literal. */ + duk__advance(comp_ctx); /* No RegExp after object literal. */ duk__ivalue_regconst(res, st.reg_obj); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_OBJECT_LITERAL); DUK_WO_NORETURN(return;); } @@ -71064,7 +72387,8 @@ /* Note: expect that caller has already eaten the left paren */ DUK_DDD(DUK_DDDPRINT("start parsing arguments, prev_token.t=%ld, curr_token.t=%ld", - (long) comp_ctx->prev_token.t, (long) comp_ctx->curr_token.t)); + (long) comp_ctx->prev_token.t, + (long) comp_ctx->curr_token.t)); for (;;) { if (comp_ctx->curr_token.t == DUK_TOK_RPAREN) { @@ -71081,11 +72405,14 @@ * This is not the cleanest possible approach. */ - reg_temp = DUK__ALLOCTEMP(comp_ctx); /* bump up "allocated" reg count, just in case */ + reg_temp = DUK__ALLOCTEMP(comp_ctx); /* bump up "allocated" reg count, just in case */ DUK__SETTEMP(comp_ctx, reg_temp); /* binding power must be high enough to NOT allow comma expressions directly */ - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp); /* always allow 'in', coerce to 'tr' just in case */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp); /* always allow 'in', coerce to 'tr' just in case */ DUK__SETTEMP(comp_ctx, reg_temp + 1); nargs++; @@ -71094,7 +72421,7 @@ } /* eat the right paren */ - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ DUK_DDD(DUK_DDDPRINT("end parsing arguments")); @@ -71103,8 +72430,7 @@ DUK_LOCAL duk_bool_t duk__expr_is_empty(duk_compiler_ctx *comp_ctx) { /* empty expressions can be detected conveniently with nud/led counts */ - return (comp_ctx->curr_func.nud_count == 0) && - (comp_ctx->curr_func.led_count == 0); + return (comp_ctx->curr_func.nud_count == 0) && (comp_ctx->curr_func.led_count == 0); } DUK_LOCAL void duk__expr_nud(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { @@ -71112,7 +72438,7 @@ duk_token *tk; duk_regconst_t temp_at_entry; duk_small_uint_t tok; - duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ + duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ /* * ctx->prev_token token to process with duk__expr_nud() @@ -71130,18 +72456,17 @@ res->t = DUK_IVAL_NONE; DUK_DDD(DUK_DDDPRINT("duk__expr_nud(), prev_token.t=%ld, allow_in=%ld, paren_level=%ld", - (long) tk->t, (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); + (long) tk->t, + (long) comp_ctx->curr_func.allow_in, + (long) comp_ctx->curr_func.paren_level)); switch (tok) { - - /* PRIMARY EXPRESSIONS */ + /* PRIMARY EXPRESSIONS */ case DUK_TOK_THIS: { duk_regconst_t reg_temp; reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_bc(comp_ctx, - DUK_OP_LDTHIS, - reg_temp); + duk__emit_bc(comp_ctx, DUK_OP_LDTHIS, reg_temp); duk__ivalue_regconst(res, reg_temp); return; } @@ -71173,15 +72498,13 @@ case DUK_TOK_REGEXP: { #if defined(DUK_USE_REGEXP_SUPPORT) duk_regconst_t reg_temp; - duk_regconst_t rc_re_bytecode; /* const */ - duk_regconst_t rc_re_source; /* const */ + duk_regconst_t rc_re_bytecode; /* const */ + duk_regconst_t rc_re_source; /* const */ DUK_ASSERT(tk->str1 != NULL); DUK_ASSERT(tk->str2 != NULL); - DUK_DDD(DUK_DDDPRINT("emitting regexp op, str1=%!O, str2=%!O", - (duk_heaphdr *) tk->str1, - (duk_heaphdr *) tk->str2)); + DUK_DDD(DUK_DDDPRINT("emitting regexp op, str1=%!O, str2=%!O", (duk_heaphdr *) tk->str1, (duk_heaphdr *) tk->str2)); reg_temp = DUK__ALLOCTEMP(comp_ctx); duk_push_hstring(thr, tk->str1); @@ -71204,9 +72527,9 @@ duk__ivalue_regconst(res, reg_temp); return; -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ goto syntax_error; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } case DUK_TOK_LBRACKET: { DUK_DDD(DUK_DDDPRINT("parsing array literal")); @@ -71225,15 +72548,15 @@ prev_allow_in = comp_ctx->curr_func.allow_in; comp_ctx->curr_func.allow_in = 1; /* reset 'allow_in' for parenthesized expression */ - duk__expr(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, terminates at a ')' */ + duk__expr(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, terminates at a ')' */ - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* No RegExp after parenthesized expression. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* No RegExp after parenthesized expression. */ comp_ctx->curr_func.allow_in = prev_allow_in; comp_ctx->curr_func.paren_level--; return; } - /* MEMBER/NEW/CALL EXPRESSIONS */ + /* MEMBER/NEW/CALL EXPRESSIONS */ case DUK_TOK_NEW: { /* @@ -71270,16 +72593,14 @@ goto syntax_error_newtarget; } duk__advance(comp_ctx); - duk__emit_bc(comp_ctx, - DUK_OP_NEWTARGET, - reg_target); + duk__emit_bc(comp_ctx, DUK_OP_NEWTARGET, reg_target); duk__ivalue_regconst(res, reg_target); return; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ duk__expr_toforcedreg(comp_ctx, res, DUK__BP_CALL /*rbp_flags*/, reg_target /*forced_reg*/); - duk__emit_bc(comp_ctx, DUK_OP_NEWOBJ, reg_target + 1); /* default instance */ + duk__emit_bc(comp_ctx, DUK_OP_NEWOBJ, reg_target + 1); /* default instance */ DUK__SETTEMP(comp_ctx, reg_target + 2); /* XXX: 'new obj.noSuch()' doesn't use GETPROPC now which @@ -71290,7 +72611,7 @@ /* 'new' MemberExpression Arguments */ DUK_DDD(DUK_DDDPRINT("new expression has argument list")); duk__advance(comp_ctx); - nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp", reg_target + 1 */ + nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp", reg_target + 1 */ /* right paren eaten */ } else { /* 'new' MemberExpression */ @@ -71298,10 +72619,7 @@ nargs = 0; } - duk__emit_a_bc(comp_ctx, - DUK_OP_CALL0 | DUK_BC_CALL_FLAG_CONSTRUCT, - nargs /*num_args*/, - reg_target /*target*/); + duk__emit_a_bc(comp_ctx, DUK_OP_CALL0 | DUK_BC_CALL_FLAG_CONSTRUCT, nargs /*num_args*/, reg_target /*target*/); DUK_DDD(DUK_DDDPRINT("end parsing new expression")); @@ -71309,7 +72627,7 @@ return; } - /* FUNCTION EXPRESSIONS */ + /* FUNCTION EXPRESSIONS */ case DUK_TOK_FUNCTION: { /* Function expression. Note that any statement beginning with 'function' @@ -71332,16 +72650,13 @@ fnum = duk__parse_func_like_fnum(comp_ctx, 0 /*flags*/); DUK_DDD(DUK_DDDPRINT("parsed inner function -> fnum %ld", (long) fnum)); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp /*a*/, - (duk_regconst_t) fnum /*bc*/); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp /*a*/, (duk_regconst_t) fnum /*bc*/); duk__ivalue_regconst(res, reg_temp); return; } - /* UNARY EXPRESSIONS */ + /* UNARY EXPRESSIONS */ case DUK_TOK_DELETE: { /* Delete semantics are a bit tricky. The description in E5 specification @@ -71349,7 +72664,7 @@ * a reference (which is only known at runtime) seemingly at compile time * (= SyntaxError throwing). */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_VAR) { /* not allowed in strict mode, regardless of whether resolves; * in non-strict mode DELVAR handles both non-resolving and @@ -71371,16 +72686,11 @@ duk_dup(thr, res->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { /* register bound variables are non-configurable -> always false */ - duk__emit_bc(comp_ctx, - DUK_OP_LDFALSE, - reg_temp); + duk__emit_bc(comp_ctx, DUK_OP_LDFALSE, reg_temp); } else { duk_dup(thr, res->x1.valstack_idx); rc_varname = duk__getconst(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_DELVAR, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_DELVAR, reg_temp, rc_varname); } duk__ivalue_regconst(res, reg_temp); } else if (res->t == DUK_IVAL_PROP) { @@ -71390,13 +72700,11 @@ DUK__SETTEMP(comp_ctx, temp_at_entry); reg_temp = DUK__ALLOCTEMP(comp_ctx); - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - DUK_OP_DELPROP | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - reg_obj, - rc_key); + reg_obj = + duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = + duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, DUK_OP_DELPROP | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, reg_obj, rc_key); duk__ivalue_regconst(res, reg_temp); } else { @@ -71407,7 +72715,7 @@ return; } case DUK_TOK_VOID: { - duk__expr_toplain_ignore(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr_toplain_ignore(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ duk_push_undefined(thr); goto plain_value; } @@ -71417,7 +72725,7 @@ * will never be unresolvable so special handling is only required * when an identifier is a "slow path" one. */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_VAR) { duk_regconst_t reg_varbind; @@ -71429,10 +72737,7 @@ DUK_DDD(DUK_DDDPRINT("typeof for an identifier name which could not be resolved " "at compile time, need to use special run-time handling")); reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_TYPEOFID, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_TYPEOFID, reg_temp, rc_varname); duk__ivalue_regconst(res, reg_temp); return; } @@ -71451,9 +72756,8 @@ } case DUK_TOK_ADD: { /* unary plus */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && - duk_is_number(thr, res->x1.valstack_idx)) { + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && duk_is_number(thr, res->x1.valstack_idx)) { /* unary plus of a number is identity */ return; } @@ -71462,9 +72766,8 @@ } case DUK_TOK_SUB: { /* unary minus */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && - duk_is_number(thr, res->x1.valstack_idx)) { + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && duk_is_number(thr, res->x1.valstack_idx)) { /* this optimization is important to handle negative literals * (which are not directly provided by the lexical grammar) */ @@ -71484,12 +72787,12 @@ goto unary; } case DUK_TOK_BNOT: { - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ args = DUK_OP_BNOT; goto unary; } case DUK_TOK_LNOT: { - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE) { /* Very minimal inlining to handle common idioms '!0' and '!1', * and also boolean arguments like '!false' and '!true'. @@ -71524,117 +72827,110 @@ goto unary; } - } /* end switch */ + } /* end switch */ DUK_ERROR_SYNTAX(thr, DUK_STR_PARSE_ERROR); DUK_WO_NORETURN(return;); - unary: - { - /* Unary opcodes use just the 'BC' register source because it - * matches current shuffle limits, and maps cleanly to 16 high - * bits of the opcode. - */ - - duk_regconst_t reg_src, reg_res; - - reg_src = duk__ivalue_toregconst_raw(comp_ctx, res, -1 /*forced_reg*/, 0 /*flags*/); - if (DUK__ISREG_TEMP(comp_ctx, reg_src)) { - reg_res = reg_src; - } else { - reg_res = DUK__ALLOCTEMP(comp_ctx); - } - duk__emit_a_bc(comp_ctx, - args, - reg_res, - reg_src); - duk__ivalue_regconst(res, reg_res); - return; - } +unary : { + /* Unary opcodes use just the 'BC' register source because it + * matches current shuffle limits, and maps cleanly to 16 high + * bits of the opcode. + */ - preincdec: - { - /* preincrement and predecrement */ - duk_regconst_t reg_res; - duk_small_uint_t args_op1 = args & 0xff; /* DUK_OP_PREINCR/DUK_OP_PREDECR */ - duk_small_uint_t args_op2 = args >> 8; /* DUK_OP_PREINCP_RR/DUK_OP_PREDECP_RR */ - - /* Specific assumptions for opcode numbering. */ - DUK_ASSERT(DUK_OP_PREINCR + 4 == DUK_OP_PREINCV); - DUK_ASSERT(DUK_OP_PREDECR + 4 == DUK_OP_PREDECV); + duk_regconst_t reg_src, reg_res; + reg_src = duk__ivalue_toregconst_raw(comp_ctx, res, -1 /*forced_reg*/, 0 /*flags*/); + if (DUK__ISREG_TEMP(comp_ctx, reg_src)) { + reg_res = reg_src; + } else { reg_res = DUK__ALLOCTEMP(comp_ctx); + } + duk__emit_a_bc(comp_ctx, args, reg_res, reg_src); + duk__ivalue_regconst(res, reg_res); + return; +} - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_VAR) { - duk_hstring *h_varname; - duk_regconst_t reg_varbind; - duk_regconst_t rc_varname; - - h_varname = duk_known_hstring(thr, res->x1.valstack_idx); +preincdec : { + /* preincrement and predecrement */ + duk_regconst_t reg_res; + duk_small_uint_t args_op1 = args & 0xff; /* DUK_OP_PREINCR/DUK_OP_PREDECR */ + duk_small_uint_t args_op2 = args >> 8; /* DUK_OP_PREINCP_RR/DUK_OP_PREDECP_RR */ + + /* Specific assumptions for opcode numbering. */ + DUK_ASSERT(DUK_OP_PREINCR + 4 == DUK_OP_PREINCV); + DUK_ASSERT(DUK_OP_PREDECR + 4 == DUK_OP_PREDECV); + + reg_res = DUK__ALLOCTEMP(comp_ctx); + + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_VAR) { + duk_hstring *h_varname; + duk_regconst_t reg_varbind; + duk_regconst_t rc_varname; - if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { - goto syntax_error; - } + h_varname = duk_known_hstring(thr, res->x1.valstack_idx); - duk_dup(thr, res->x1.valstack_idx); - if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - args_op1, /* e.g. DUK_OP_PREINCR */ - reg_res, - reg_varbind); - } else { - duk__emit_a_bc(comp_ctx, - args_op1 + 4, /* e.g. DUK_OP_PREINCV */ - reg_res, - rc_varname); - } + if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { + goto syntax_error; + } - DUK_DDD(DUK_DDDPRINT("preincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); - } else if (res->t == DUK_IVAL_PROP) { - duk_regconst_t reg_obj; /* allocate to reg only (not const) */ - duk_regconst_t rc_key; - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_PREINCP */ - reg_res, - reg_obj, - rc_key); + duk_dup(thr, res->x1.valstack_idx); + if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { + duk__emit_a_bc(comp_ctx, + args_op1, /* e.g. DUK_OP_PREINCR */ + reg_res, + reg_varbind); } else { - /* Technically return value is not needed because INVLHS will - * unconditially throw a ReferenceError. Coercion is necessary - * for proper semantics (consider ToNumber() called for an object). - * Use DUK_OP_UNP with a dummy register to get ToNumber(). - */ - - duk__ivalue_toforcedreg(comp_ctx, res, reg_res); - duk__emit_bc(comp_ctx, - DUK_OP_UNP, - reg_res); /* for side effects, result ignored */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__emit_a_bc(comp_ctx, + args_op1 + 4, /* e.g. DUK_OP_PREINCV */ + reg_res, + rc_varname); } - DUK__SETTEMP(comp_ctx, reg_res + 1); - duk__ivalue_regconst(res, reg_res); - return; - } - plain_value: - { - /* Stack top contains plain value */ - duk__ivalue_plain_fromstack(comp_ctx, res); - return; + DUK_DDD(DUK_DDDPRINT("preincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); + } else if (res->t == DUK_IVAL_PROP) { + duk_regconst_t reg_obj; /* allocate to reg only (not const) */ + duk_regconst_t rc_key; + reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, + args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_PREINCP */ + reg_res, + reg_obj, + rc_key); + } else { + /* Technically return value is not needed because INVLHS will + * unconditially throw a ReferenceError. Coercion is necessary + * for proper semantics (consider ToNumber() called for an object). + * Use DUK_OP_UNP with a dummy register to get ToNumber(). + */ + + duk__ivalue_toforcedreg(comp_ctx, res, reg_res); + duk__emit_bc(comp_ctx, DUK_OP_UNP, reg_res); /* for side effects, result ignored */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } + DUK__SETTEMP(comp_ctx, reg_res + 1); + duk__ivalue_regconst(res, reg_res); + return; +} + +plain_value : { + /* Stack top contains plain value */ + duk__ivalue_plain_fromstack(comp_ctx, res); + return; +} #if defined(DUK_USE_ES6) - syntax_error_newtarget: +syntax_error_newtarget: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_NEWTARGET); DUK_WO_NORETURN(return;); #endif - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_EXPRESSION); DUK_WO_NORETURN(return;); } @@ -71647,7 +72943,7 @@ duk_hthread *thr = comp_ctx->thr; duk_token *tk; duk_small_uint_t tok; - duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ + duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ /* * ctx->prev_token token to process with duk__expr_led() @@ -71661,13 +72957,14 @@ tok = tk->t; DUK_DDD(DUK_DDDPRINT("duk__expr_led(), prev_token.t=%ld, allow_in=%ld, paren_level=%ld", - (long) tk->t, (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); + (long) tk->t, + (long) comp_ctx->curr_func.allow_in, + (long) comp_ctx->curr_func.paren_level)); /* XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here? */ switch (tok) { - - /* PRIMARY EXPRESSIONS */ + /* PRIMARY EXPRESSIONS */ case DUK_TOK_PERIOD: { /* Property access expressions are critical for correct LHS ordering, @@ -71695,7 +72992,7 @@ } res->t = DUK_IVAL_PROP; - duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ + duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); duk_push_hstring(thr, comp_ctx->curr_token.str1); duk_replace(thr, res->x2.valstack_idx); @@ -71730,12 +73027,12 @@ * See: test-bug-nested-prop-mutate.js. */ duk__ivalue_totempconst(comp_ctx, left); - duk__expr_toplain(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, '' terminates */ + duk__expr_toplain(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, '' terminates */ duk__advance_expect(comp_ctx, DUK_TOK_RBRACKET); res->t = DUK_IVAL_PROP; - duk__copy_ispec(comp_ctx, &res->x1, &res->x2); /* res.x1 -> res.x2 */ - duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ + duk__copy_ispec(comp_ctx, &res->x1, &res->x2); /* res.x1 -> res.x2 */ + duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ return; } case DUK_TOK_LPAREN: { @@ -71779,19 +73076,13 @@ duk_dup(thr, left->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - DUK_OP_CSREG | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_varbind, - reg_cs + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_CSREG | DUK__EMIT_FLAG_A_IS_SOURCE, reg_varbind, reg_cs + 0); } else { /* XXX: expand target register or constant field to * reduce shuffling. */ DUK_ASSERT(DUK__ISCONST(rc_varname)); - duk__emit_a_b(comp_ctx, - DUK_OP_CSVAR | DUK__EMIT_FLAG_BC_REGCONST, - reg_cs + 0, - rc_varname); + duk__emit_a_b(comp_ctx, DUK_OP_CSVAR | DUK__EMIT_FLAG_BC_REGCONST, reg_cs + 0, rc_varname); } } else if (left->t == DUK_IVAL_PROP) { /* Call through a property lookup, E5 Section 11.2.3, step 6.a.i, @@ -71813,16 +73104,12 @@ * and reuse, but it would still be in the wrong position * (reg_cs + 0 rather than reg_cs + 1). */ - duk__ispec_toforcedreg(comp_ctx, &left->x1, reg_cs + 1); /* base */ + duk__ispec_toforcedreg(comp_ctx, &left->x1, reg_cs + 1); /* base */ #if defined(DUK_USE_VERBOSE_ERRORS) reg_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROPC | DUK__EMIT_FLAG_BC_REGCONST, - reg_cs + 0, - reg_cs + 1, - reg_key); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROPC | DUK__EMIT_FLAG_BC_REGCONST, reg_cs + 0, reg_cs + 1, reg_key); #else - duk__ivalue_toforcedreg(comp_ctx, left, reg_cs + 0); /* basekey */ + duk__ivalue_toforcedreg(comp_ctx, left, reg_cs + 0); /* basekey */ #endif } else { DUK_DDD(DUK_DDDPRINT("function call with register base")); @@ -71841,23 +73128,20 @@ } DUK__SETTEMP(comp_ctx, reg_cs + 2); - nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp" */ + nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp" */ /* Tailcalls are handled by back-patching the already emitted opcode * later in return statement parser. */ - duk__emit_a_bc(comp_ctx, - call_op, - (duk_regconst_t) nargs /*numargs*/, - reg_cs /*basereg*/); - DUK__SETTEMP(comp_ctx, reg_cs + 1); /* result in csreg */ + duk__emit_a_bc(comp_ctx, call_op, (duk_regconst_t) nargs /*numargs*/, reg_cs /*basereg*/); + DUK__SETTEMP(comp_ctx, reg_cs + 1); /* result in csreg */ duk__ivalue_regconst(res, reg_cs); return; } - /* POSTFIX EXPRESSION */ + /* POSTFIX EXPRESSION */ case DUK_TOK_INCREMENT: { args = (DUK_OP_POSTINCP_RR << 16) + (DUK_OP_POSTINCR << 8) + 0; @@ -71872,38 +73156,38 @@ #if defined(DUK_USE_ES7_EXP_OPERATOR) case DUK_TOK_EXP: { - args = (DUK_OP_EXP << 8) + DUK__BP_EXPONENTIATION - 1; /* UnaryExpression */ + args = (DUK_OP_EXP << 8) + DUK__BP_EXPONENTIATION - 1; /* UnaryExpression */ goto binary; } #endif - /* MULTIPLICATIVE EXPRESSION */ + /* MULTIPLICATIVE EXPRESSION */ case DUK_TOK_MUL: { - args = (DUK_OP_MUL << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_MUL << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } case DUK_TOK_DIV: { - args = (DUK_OP_DIV << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_DIV << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } case DUK_TOK_MOD: { - args = (DUK_OP_MOD << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_MOD << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } - /* ADDITIVE EXPRESSION */ + /* ADDITIVE EXPRESSION */ case DUK_TOK_ADD: { - args = (DUK_OP_ADD << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ + args = (DUK_OP_ADD << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ goto binary; } case DUK_TOK_SUB: { - args = (DUK_OP_SUB << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ + args = (DUK_OP_SUB << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ goto binary; } - /* SHIFT EXPRESSION */ + /* SHIFT EXPRESSION */ case DUK_TOK_ALSHIFT: { /* << */ @@ -71921,7 +73205,7 @@ goto binary; } - /* RELATIONAL EXPRESSION */ + /* RELATIONAL EXPRESSION */ case DUK_TOK_LT: { /* < */ @@ -71949,7 +73233,7 @@ goto binary; } - /* EQUALITY EXPRESSION */ + /* EQUALITY EXPRESSION */ case DUK_TOK_EQ: { args = (DUK_OP_EQ << 8) + DUK__BP_EQUALITY; @@ -71968,7 +73252,7 @@ goto binary; } - /* BITWISE EXPRESSIONS */ + /* BITWISE EXPRESSIONS */ case DUK_TOK_BAND: { args = (DUK_OP_BAND << 8) + DUK__BP_BAND; @@ -71983,7 +73267,7 @@ goto binary; } - /* LOGICAL EXPRESSIONS */ + /* LOGICAL EXPRESSIONS */ case DUK_TOK_LAND: { /* syntactically left-associative but parsed as right-associative */ @@ -71996,7 +73280,7 @@ goto binary_logical; } - /* CONDITIONAL EXPRESSION */ + /* CONDITIONAL EXPRESSION */ case DUK_TOK_QUESTION: { /* XXX: common reg allocation need is to reuse a sub-expression's temp reg, @@ -72009,12 +73293,18 @@ reg_temp = DUK__ALLOCTEMP(comp_ctx); duk__ivalue_toforcedreg(comp_ctx, left, reg_temp); duk__emit_if_true_skip(comp_ctx, reg_temp); - pc_jump1 = duk__emit_jump_empty(comp_ctx); /* jump to false */ - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); /* AssignmentExpression */ + pc_jump1 = duk__emit_jump_empty(comp_ctx); /* jump to false */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp /*forced_reg*/); /* AssignmentExpression */ duk__advance_expect(comp_ctx, DUK_TOK_COLON); - pc_jump2 = duk__emit_jump_empty(comp_ctx); /* jump to end */ + pc_jump2 = duk__emit_jump_empty(comp_ctx); /* jump to end */ duk__patch_jump_here(comp_ctx, pc_jump1); - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); /* AssignmentExpression */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp /*forced_reg*/); /* AssignmentExpression */ duk__patch_jump_here(comp_ctx, pc_jump2); DUK__SETTEMP(comp_ctx, reg_temp + 1); @@ -72022,7 +73312,7 @@ return; } - /* ASSIGNMENT EXPRESSION */ + /* ASSIGNMENT EXPRESSION */ case DUK_TOK_EQUALSIGN: { /* @@ -72036,7 +73326,7 @@ * * XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)? */ - args = (DUK_OP_NONE << 8) + DUK__BP_ASSIGNMENT - 1; /* DUK_OP_NONE marks a 'plain' assignment */ + args = (DUK_OP_NONE << 8) + DUK__BP_ASSIGNMENT - 1; /* DUK_OP_NONE marks a 'plain' assignment */ goto assign; } case DUK_TOK_ADD_EQ: { @@ -72102,12 +73392,12 @@ goto assign; } - /* COMMA */ + /* COMMA */ case DUK_TOK_COMMA: { /* right associative */ - duk__ivalue_toplain_ignore(comp_ctx, left); /* need side effects, not value */ + duk__ivalue_toplain_ignore(comp_ctx, left); /* need side effects, not value */ duk__expr_toplain(comp_ctx, res, DUK__BP_COMMA - 1 /*rbp_flags*/); /* return 'res' (of right part) as our result */ @@ -72130,7 +73420,7 @@ } #endif - binary: +binary: /* * Shared handling of binary operations * @@ -72156,11 +73446,15 @@ duk_copy(thr, left->x1.valstack_idx, res->x1.valstack_idx); DUK_DDD(DUK_DDDPRINT("binary op, res: t=%ld, x1.t=%ld, x1.regconst=0x%08lx, x2.t=%ld, x2.regconst=0x%08lx", - (long) res->t, (long) res->x1.t, (unsigned long) res->x1.regconst, (long) res->x2.t, (unsigned long) res->x2.regconst)); + (long) res->t, + (long) res->x1.t, + (unsigned long) res->x1.regconst, + (long) res->x2.t, + (unsigned long) res->x2.regconst)); return; } - binary_logical: +binary_logical: /* * Shared handling for logical AND and logical OR. * @@ -72193,8 +73487,8 @@ duk__ivalue_toforcedreg(comp_ctx, left, reg_temp); DUK_ASSERT(DUK__ISREG(reg_temp)); duk__emit_bc(comp_ctx, - (args_truthval ? DUK_OP_IFTRUE_R : DUK_OP_IFFALSE_R), - reg_temp); /* skip jump conditionally */ + (args_truthval ? DUK_OP_IFTRUE_R : DUK_OP_IFFALSE_R), + reg_temp); /* skip jump conditionally */ pc_jump = duk__emit_jump_empty(comp_ctx); duk__expr_toforcedreg(comp_ctx, res, args_rbp /*rbp_flags*/, reg_temp /*forced_reg*/); duk__patch_jump_here(comp_ctx, pc_jump); @@ -72203,7 +73497,7 @@ return; } - assign: +assign: /* * Shared assignment expression handling * @@ -72256,7 +73550,7 @@ * is relevant for e.g. eval code. */ toplevel_assign = (comp_ctx->curr_func.nud_count == 1 && /* one token before */ - comp_ctx->curr_func.led_count == 1); /* one operator (= assign) */ + comp_ctx->curr_func.led_count == 1); /* one operator (= assign) */ DUK_DDD(DUK_DDDPRINT("assignment: nud_count=%ld, led_count=%ld, toplevel_assign=%ld", (long) comp_ctx->curr_func.nud_count, (long) comp_ctx->curr_func.led_count, @@ -72267,7 +73561,7 @@ duk_regconst_t reg_varbind; duk_regconst_t rc_varname; - DUK_ASSERT(left->x1.t == DUK_ISPEC_VALUE); /* LHS is already side effect free */ + DUK_ASSERT(left->x1.t == DUK_ISPEC_VALUE); /* LHS is already side effect free */ h_varname = duk_known_hstring(thr, left->x1.valstack_idx); if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { @@ -72284,9 +73578,10 @@ DUK_DDD(DUK_DDDPRINT("plain assignment, toplevel assign, use as is")); } else { /* 'res' must be a plain ivalue, and not register-bound variable. */ - DUK_DDD(DUK_DDDPRINT("plain assignment, not toplevel assign, ensure not a reg-bound identifier")); - if (res->t != DUK_IVAL_PLAIN || (res->x1.t == DUK_ISPEC_REGCONST && - DUK__ISREG_NOTTEMP(comp_ctx, res->x1.regconst))) { + DUK_DDD(DUK_DDDPRINT( + "plain assignment, not toplevel assign, ensure not a reg-bound identifier")); + if (res->t != DUK_IVAL_PLAIN || + (res->x1.t == DUK_ISPEC_REGCONST && DUK__ISREG_NOTTEMP(comp_ctx, res->x1.regconst))) { duk__ivalue_totempconst(comp_ctx, res); } } @@ -72319,7 +73614,7 @@ * value, so go through a temp. */ DUK_DD(DUK_DDPRINT("<op>= expression is not top level, write to reg_temp")); - reg_res = reg_temp; /* reg_res should be smallest possible */ + reg_res = reg_temp; /* reg_res should be smallest possible */ reg_temp = DUK__ALLOCTEMP(comp_ctx); } @@ -72331,10 +73626,7 @@ */ pc_temp_load = duk__get_current_pc(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_temp, - reg_varbind); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_temp, reg_varbind); pc_before_rhs = duk__get_current_pc(comp_ctx); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); @@ -72342,7 +73634,8 @@ pc_after_rhs = duk__get_current_pc(comp_ctx); DUK_DD(DUK_DDPRINT("pc_temp_load=%ld, pc_before_rhs=%ld, pc_after_rhs=%ld", - (long) pc_temp_load, (long) pc_before_rhs, + (long) pc_temp_load, + (long) pc_before_rhs, (long) pc_after_rhs)); if (pc_after_rhs == pc_before_rhs) { @@ -72350,11 +73643,16 @@ * instructions, we may need to rewind more than * one instruction, so use explicit PC computation. */ - DUK_DD(DUK_DDPRINT("rhs is side effect free, rewind and avoid unnecessary temp for reg-based <op>=")); - DUK_BW_ADD_PTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, (pc_temp_load - pc_before_rhs) * (duk_int_t) sizeof(duk_compiler_instr)); + DUK_DD(DUK_DDPRINT("rhs is side effect free, rewind and avoid unnecessary temp for " + "reg-based <op>=")); + DUK_BW_ADD_PTR(comp_ctx->thr, + &comp_ctx->curr_func.bw_code, + (pc_temp_load - pc_before_rhs) * + (duk_int_t) sizeof(duk_compiler_instr)); reg_src = reg_varbind; } else { - DUK_DD(DUK_DDPRINT("rhs evaluation emitted code, not sure if rhs is side effect free; use temp reg for LHS")); + DUK_DD(DUK_DDPRINT("rhs evaluation emitted code, not sure if rhs is side effect " + "free; use temp reg for LHS")); reg_src = reg_temp; } @@ -72375,10 +73673,7 @@ * temporary. No optimization for top level assignment. */ - duk__emit_a_bc(comp_ctx, - DUK_OP_GETVAR, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_GETVAR, reg_temp, rc_varname); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); DUK_ASSERT(res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_REGCONST); @@ -72411,7 +73706,7 @@ duk__ivalue_toforcedreg(comp_ctx, res, (duk_int_t) reg_varbind); } else { duk__ivalue_totempconst(comp_ctx, res); - duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ + duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ duk__ivalue_toforcedreg(comp_ctx, left, (duk_int_t) reg_varbind); } } else { @@ -72419,7 +73714,7 @@ * free and may be a plain value, a register, or a * constant) and write it to the LHS binding too. */ - duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ + duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ duk__ivalue_toforcedreg(comp_ctx, left, (duk_int_t) reg_varbind); } } else { @@ -72432,10 +73727,7 @@ */ duk__ivalue_toreg(comp_ctx, res); - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - res->x1.regconst, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, res->x1.regconst, rc_varname); } /* 'res' contains expression value */ @@ -72475,11 +73767,7 @@ rc_res = res->x1.regconst; } else { reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - reg_obj, - rc_key); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, reg_obj, rc_key); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); DUK_ASSERT(res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_REGCONST); @@ -72530,90 +73818,88 @@ return; } - postincdec: - { - /* - * Post-increment/decrement will return the original value as its - * result value. However, even that value will be coerced using - * ToNumber() which is quite awkward. Specific bytecode opcodes - * are used to handle these semantics. - * - * Note that post increment/decrement has a "no LineTerminator here" - * restriction. This is handled by duk__expr_lbp(), which forcibly terminates - * the previous expression if a LineTerminator occurs before '++'/'--'. - */ - - duk_regconst_t reg_res; - duk_small_uint_t args_op1 = (args >> 8) & 0xff; /* DUK_OP_POSTINCR/DUK_OP_POSTDECR */ - duk_small_uint_t args_op2 = args >> 16; /* DUK_OP_POSTINCP_RR/DUK_OP_POSTDECP_RR */ - - /* Specific assumptions for opcode numbering. */ - DUK_ASSERT(DUK_OP_POSTINCR + 4 == DUK_OP_POSTINCV); - DUK_ASSERT(DUK_OP_POSTDECR + 4 == DUK_OP_POSTDECV); +postincdec : { + /* + * Post-increment/decrement will return the original value as its + * result value. However, even that value will be coerced using + * ToNumber() which is quite awkward. Specific bytecode opcodes + * are used to handle these semantics. + * + * Note that post increment/decrement has a "no LineTerminator here" + * restriction. This is handled by duk__expr_lbp(), which forcibly terminates + * the previous expression if a LineTerminator occurs before '++'/'--'. + */ - reg_res = DUK__ALLOCTEMP(comp_ctx); + duk_regconst_t reg_res; + duk_small_uint_t args_op1 = (args >> 8) & 0xff; /* DUK_OP_POSTINCR/DUK_OP_POSTDECR */ + duk_small_uint_t args_op2 = args >> 16; /* DUK_OP_POSTINCP_RR/DUK_OP_POSTDECP_RR */ - if (left->t == DUK_IVAL_VAR) { - duk_hstring *h_varname; - duk_regconst_t reg_varbind; - duk_regconst_t rc_varname; + /* Specific assumptions for opcode numbering. */ + DUK_ASSERT(DUK_OP_POSTINCR + 4 == DUK_OP_POSTINCV); + DUK_ASSERT(DUK_OP_POSTDECR + 4 == DUK_OP_POSTDECV); - h_varname = duk_known_hstring(thr, left->x1.valstack_idx); + reg_res = DUK__ALLOCTEMP(comp_ctx); - if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { - goto syntax_error; - } + if (left->t == DUK_IVAL_VAR) { + duk_hstring *h_varname; + duk_regconst_t reg_varbind; + duk_regconst_t rc_varname; - duk_dup(thr, left->x1.valstack_idx); - if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - args_op1, /* e.g. DUK_OP_POSTINCR */ - reg_res, - reg_varbind); - } else { - duk__emit_a_bc(comp_ctx, - args_op1 + 4, /* e.g. DUK_OP_POSTINCV */ - reg_res, - rc_varname); - } + h_varname = duk_known_hstring(thr, left->x1.valstack_idx); - DUK_DDD(DUK_DDDPRINT("postincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); - } else if (left->t == DUK_IVAL_PROP) { - duk_regconst_t reg_obj; /* allocate to reg only (not const) */ - duk_regconst_t rc_key; + if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { + goto syntax_error; + } - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &left->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_POSTINCP */ - reg_res, - reg_obj, - rc_key); + duk_dup(thr, left->x1.valstack_idx); + if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { + duk__emit_a_bc(comp_ctx, + args_op1, /* e.g. DUK_OP_POSTINCR */ + reg_res, + reg_varbind); } else { - /* Technically return value is not needed because INVLHS will - * unconditially throw a ReferenceError. Coercion is necessary - * for proper semantics (consider ToNumber() called for an object). - * Use DUK_OP_UNP with a dummy register to get ToNumber(). - */ - duk__ivalue_toforcedreg(comp_ctx, left, reg_res); - duk__emit_bc(comp_ctx, - DUK_OP_UNP, - reg_res); /* for side effects, result ignored */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__emit_a_bc(comp_ctx, + args_op1 + 4, /* e.g. DUK_OP_POSTINCV */ + reg_res, + rc_varname); } - DUK__SETTEMP(comp_ctx, reg_res + 1); - duk__ivalue_regconst(res, reg_res); - return; + DUK_DDD(DUK_DDDPRINT("postincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); + } else if (left->t == DUK_IVAL_PROP) { + duk_regconst_t reg_obj; /* allocate to reg only (not const) */ + duk_regconst_t rc_key; + + reg_obj = duk__ispec_toregconst_raw(comp_ctx, &left->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, + args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_POSTINCP */ + reg_res, + reg_obj, + rc_key); + } else { + /* Technically return value is not needed because INVLHS will + * unconditially throw a ReferenceError. Coercion is necessary + * for proper semantics (consider ToNumber() called for an object). + * Use DUK_OP_UNP with a dummy register to get ToNumber(). + */ + duk__ivalue_toforcedreg(comp_ctx, left, reg_res); + duk__emit_bc(comp_ctx, DUK_OP_UNP, reg_res); /* for side effects, result ignored */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } - syntax_error: + DUK__SETTEMP(comp_ctx, reg_res + 1); + duk__ivalue_regconst(res, reg_res); + return; +} + +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_EXPRESSION); DUK_WO_NORETURN(return;); - syntax_error_lvalue: +syntax_error_lvalue: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_LVALUE); DUK_WO_NORETURN(return;); } @@ -72621,7 +73907,7 @@ DUK_LOCAL duk_small_uint_t duk__expr_lbp(duk_compiler_ctx *comp_ctx) { duk_small_uint_t tok = comp_ctx->curr_token.t; - DUK_ASSERT_DISABLE(tok >= DUK_TOK_MINVAL); /* unsigned */ + DUK_ASSERT_DISABLE(tok >= DUK_TOK_MINVAL); /* unsigned */ DUK_ASSERT(tok <= DUK_TOK_MAXVAL); DUK_ASSERT(sizeof(duk__token_lbp) == DUK_TOK_MAXVAL + 1); @@ -72634,8 +73920,7 @@ return 0; } - if ((tok == DUK_TOK_DECREMENT || tok == DUK_TOK_INCREMENT) && - (comp_ctx->curr_token.lineterm)) { + if ((tok == DUK_TOK_DECREMENT || tok == DUK_TOK_INCREMENT) && (comp_ctx->curr_token.lineterm)) { /* '++' or '--' in a post-increment/decrement position, * and a LineTerminator occurs between the operator and * the preceding expression. Force the previous expr @@ -72645,7 +73930,7 @@ return 0; } - return DUK__TOKEN_LBP_GET_BP(duk__token_lbptok); /* format is bit packed */ + return DUK__TOKEN_LBP_GET_BP(duk__token_lbptok); /* format is bit packed */ } /* @@ -72657,15 +73942,15 @@ * statement). */ -#define DUK__EXPR_RBP_MASK 0xff -#define DUK__EXPR_FLAG_REJECT_IN (1 << 8) /* reject 'in' token (used for for-in) */ -#define DUK__EXPR_FLAG_ALLOW_EMPTY (1 << 9) /* allow empty expression */ -#define DUK__EXPR_FLAG_REQUIRE_INIT (1 << 10) /* require initializer for var/const */ +#define DUK__EXPR_RBP_MASK 0xff +#define DUK__EXPR_FLAG_REJECT_IN (1 << 8) /* reject 'in' token (used for for-in) */ +#define DUK__EXPR_FLAG_ALLOW_EMPTY (1 << 9) /* allow empty expression */ +#define DUK__EXPR_FLAG_REQUIRE_INIT (1 << 10) /* require initializer for var/const */ /* main expression parser function */ DUK_LOCAL void duk__expr(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk_hthread *thr = comp_ctx->thr; - duk_ivalue tmp_alloc; /* 'res' is used for "left", and 'tmp' for "right" */ + duk_ivalue tmp_alloc; /* 'res' is used for "left", and 'tmp' for "right" */ duk_ivalue *tmp = &tmp_alloc; duk_small_uint_t rbp; @@ -72677,7 +73962,9 @@ rbp = rbp_flags & DUK__EXPR_RBP_MASK; DUK_DDD(DUK_DDDPRINT("duk__expr(), rbp_flags=%ld, rbp=%ld, allow_in=%ld, paren_level=%ld", - (long) rbp_flags, (long) rbp, (long) comp_ctx->curr_func.allow_in, + (long) rbp_flags, + (long) rbp, + (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); duk_memzero(&tmp_alloc, sizeof(tmp_alloc)); @@ -72708,14 +73995,14 @@ } duk__advance(comp_ctx); - duk__expr_nud(comp_ctx, res); /* reuse 'res' as 'left' */ + duk__expr_nud(comp_ctx, res); /* reuse 'res' as 'left' */ while (rbp < duk__expr_lbp(comp_ctx)) { duk__advance(comp_ctx); duk__expr_led(comp_ctx, res, tmp); - duk__copy_ivalue(comp_ctx, tmp, res); /* tmp -> res */ + duk__copy_ivalue(comp_ctx, tmp, res); /* tmp -> res */ } - cleanup: +cleanup: /* final result is already in 'res' */ duk_pop_2(thr); @@ -72749,21 +74036,24 @@ * Each helper needs at least 2-3 calls to make it worth while to wrap. */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_toreg(comp_ctx, res); } #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_totemp(comp_ctx, res); } #endif -DUK_LOCAL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg) { +DUK_LOCAL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg) { DUK_ASSERT(forced_reg >= 0); duk__expr(comp_ctx, res, rbp_flags); duk__ivalue_toforcedreg(comp_ctx, res, forced_reg); @@ -72774,7 +74064,7 @@ return duk__ivalue_toregconst(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_totempconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_totempconst(comp_ctx, res); @@ -72796,14 +74086,17 @@ return duk__ivalue_toreg(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__exprtop_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__exprtop(comp_ctx, res, rbp_flags); return duk__ivalue_totemp(comp_ctx, res); } #endif -DUK_LOCAL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg) { +DUK_LOCAL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg) { DUK_ASSERT(forced_reg >= 0); duk__exprtop(comp_ctx, res, rbp_flags); duk__ivalue_toforcedreg(comp_ctx, res, forced_reg); @@ -72814,7 +74107,7 @@ return duk__ivalue_toregconst(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__exprtop_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, int rbp_flags) { duk__exprtop(comp_ctx, res, rbp_flags); duk__ivalue_toplain_ignore(comp_ctx, res); @@ -72833,11 +74126,11 @@ * the token after the terminator). */ -#define DUK__HAS_VAL (1 << 0) /* stmt has non-empty value */ -#define DUK__HAS_TERM (1 << 1) /* stmt has explicit/implicit semicolon terminator */ -#define DUK__ALLOW_AUTO_SEMI_ALWAYS (1 << 2) /* allow automatic semicolon even without lineterm (compatibility) */ -#define DUK__STILL_PROLOGUE (1 << 3) /* statement does not terminate directive prologue */ -#define DUK__IS_TERMINAL (1 << 4) /* statement is guaranteed to be terminal (control doesn't flow to next statement) */ +#define DUK__HAS_VAL (1 << 0) /* stmt has non-empty value */ +#define DUK__HAS_TERM (1 << 1) /* stmt has explicit/implicit semicolon terminator */ +#define DUK__ALLOW_AUTO_SEMI_ALWAYS (1 << 2) /* allow automatic semicolon even without lineterm (compatibility) */ +#define DUK__STILL_PROLOGUE (1 << 3) /* statement does not terminate directive prologue */ +#define DUK__IS_TERMINAL (1 << 4) /* statement is guaranteed to be terminal (control doesn't flow to next statement) */ /* Parse a single variable declaration (e.g. "i" or "i=10"). A leading 'var' * has already been eaten. These is no return value in 'res', it is used only @@ -72857,7 +74150,11 @@ * as is done in 'for-in' parsing. */ -DUK_LOCAL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags, duk_regconst_t *out_reg_varbind, duk_regconst_t *out_rc_varname) { +DUK_LOCAL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t expr_flags, + duk_regconst_t *out_reg_varbind, + duk_regconst_t *out_rc_varname) { duk_hthread *thr = comp_ctx->thr; duk_hstring *h_varname; duk_regconst_t reg_varbind; @@ -72881,8 +74178,7 @@ /* register declarations in first pass */ if (comp_ctx->curr_func.in_scanning) { duk_uarridx_t n; - DUK_DDD(DUK_DDDPRINT("register variable declaration %!O in pass 1", - (duk_heaphdr *) h_varname)); + DUK_DDD(DUK_DDDPRINT("register variable declaration %!O in pass 1", (duk_heaphdr *) h_varname)); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); duk_push_hstring(thr, h_varname); duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n); @@ -72890,31 +74186,30 @@ duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n + 1); } - duk_push_hstring(thr, h_varname); /* push before advancing to keep reachable */ + duk_push_hstring(thr, h_varname); /* push before advancing to keep reachable */ /* register binding lookup is based on varmap (even in first pass) */ duk_dup_top(thr); (void) duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname); - duk__advance(comp_ctx); /* eat identifier */ + duk__advance(comp_ctx); /* eat identifier */ if (comp_ctx->curr_token.t == DUK_TOK_EQUALSIGN) { duk__advance(comp_ctx); DUK_DDD(DUK_DDDPRINT("vardecl, assign to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); - duk__exprtop(comp_ctx, res, DUK__BP_COMMA | expr_flags /*rbp_flags*/); /* AssignmentExpression */ + duk__exprtop(comp_ctx, res, DUK__BP_COMMA | expr_flags /*rbp_flags*/); /* AssignmentExpression */ if (reg_varbind >= 0) { duk__ivalue_toforcedreg(comp_ctx, res, reg_varbind); } else { duk_regconst_t reg_val; reg_val = duk__ivalue_toreg(comp_ctx, res); - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_val, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, reg_val, rc_varname); } } else { if (expr_flags & DUK__EXPR_FLAG_REQUIRE_INIT) { @@ -72923,14 +74218,14 @@ } } - duk_pop(thr); /* pop varname */ + duk_pop(thr); /* pop varname */ *out_rc_varname = rc_varname; *out_reg_varbind = reg_varbind; return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_VAR_DECLARATION); DUK_WO_NORETURN(return;); } @@ -72939,7 +74234,7 @@ duk_regconst_t reg_varbind; duk_regconst_t rc_varname; - duk__advance(comp_ctx); /* eat 'var' */ + duk__advance(comp_ctx); /* eat 'var' */ for (;;) { /* rc_varname and reg_varbind are ignored here */ @@ -72954,9 +74249,9 @@ DUK_LOCAL void duk__parse_for_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site) { duk_hthread *thr = comp_ctx->thr; - duk_int_t pc_v34_lhs; /* start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example) */ - duk_regconst_t temp_reset; /* knock back "next temp" to this whenever possible */ - duk_regconst_t reg_temps; /* preallocated temporaries (2) for variants 3 and 4 */ + duk_int_t pc_v34_lhs; /* start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example) */ + duk_regconst_t temp_reset; /* knock back "next temp" to this whenever possible */ + duk_regconst_t reg_temps; /* preallocated temporaries (2) for variants 3 and 4 */ DUK_DDD(DUK_DDDPRINT("start parsing a for/for-in statement")); @@ -72985,7 +74280,7 @@ * issues, evaluation order issues, etc. */ - duk__advance(comp_ctx); /* eat 'for' */ + duk__advance(comp_ctx); /* eat 'for' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); DUK_DDD(DUK_DDDPRINT("detecting for/for-in loop variant, pc=%ld", (long) duk__get_current_pc(comp_ctx))); @@ -72999,10 +74294,10 @@ * Variant 2 or 4 */ - duk_regconst_t reg_varbind; /* variable binding register if register-bound (otherwise < 0) */ - duk_regconst_t rc_varname; /* variable name reg/const, if variable not register-bound */ + duk_regconst_t reg_varbind; /* variable binding register if register-bound (otherwise < 0) */ + duk_regconst_t rc_varname; /* variable name reg/const, if variable not register-bound */ - duk__advance(comp_ctx); /* eat 'var' */ + duk__advance(comp_ctx); /* eat 'var' */ duk__parse_var_decl(comp_ctx, res, DUK__EXPR_FLAG_REJECT_IN, ®_varbind, &rc_varname); DUK__SETTEMP(comp_ctx, temp_reset); @@ -73012,17 +74307,11 @@ */ DUK_DDD(DUK_DDDPRINT("detected for variant 4: for (var VariableDeclarationNoIn in Expression) Statement")); - pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here */ + pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here */ if (reg_varbind >= 0) { - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_varbind, - reg_temps + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_varbind, reg_temps + 0); } else { - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_temps + 0, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, reg_temps + 0, rc_varname); } goto parse_3_or_4; } else { @@ -73030,7 +74319,8 @@ * Variant 2 */ - DUK_DDD(DUK_DDDPRINT("detected for variant 2: for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement")); + DUK_DDD(DUK_DDDPRINT( + "detected for variant 2: for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement")); for (;;) { /* more initializers */ if (comp_ctx->curr_token.t != DUK_TOK_COMMA) { @@ -73038,7 +74328,7 @@ } DUK_DDD(DUK_DDDPRINT("variant 2 has another variable initializer")); - duk__advance(comp_ctx); /* eat comma */ + duk__advance(comp_ctx); /* eat comma */ duk__parse_var_decl(comp_ctx, res, DUK__EXPR_FLAG_REJECT_IN, ®_varbind, &rc_varname); } goto parse_1_or_2; @@ -73048,14 +74338,17 @@ * Variant 1 or 3 */ - pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here (variant 3) */ + pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here (variant 3) */ /* Note that duk__exprtop() here can clobber any reg above current temp_next, * so any loop variables (e.g. enumerator) must be "preallocated". */ /* don't coerce yet to a plain value (variant 3 needs special handling) */ - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_REJECT_IN | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression */ + duk__exprtop(comp_ctx, + res, + DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_REJECT_IN | + DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression */ if (comp_ctx->curr_token.t == DUK_TOK_IN) { /* * Variant 3 @@ -73064,7 +74357,7 @@ /* XXX: need to determine LHS type, and check that it is LHS compatible */ DUK_DDD(DUK_DDDPRINT("detected for variant 3: for (LeftHandSideExpression in Expression) Statement")); if (duk__expr_is_empty(comp_ctx)) { - goto syntax_error; /* LeftHandSideExpression does not allow empty expression */ + goto syntax_error; /* LeftHandSideExpression does not allow empty expression */ } if (res->t == DUK_IVAL_VAR) { @@ -73073,10 +74366,7 @@ duk_dup(thr, res->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_varbind, - reg_temps + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_varbind, reg_temps + 0); } else { duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, @@ -73089,17 +74379,22 @@ */ duk_regconst_t reg_obj; duk_regconst_t rc_key; - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + reg_obj = duk__ispec_toregconst_raw(comp_ctx, + &res->x1, + -1 /*forced_reg*/, + 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, + &res->x2, + -1 /*forced_reg*/, + DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); duk__emit_a_b_c(comp_ctx, DUK_OP_PUTPROP | DUK__EMIT_FLAG_A_IS_SOURCE | DUK__EMIT_FLAG_BC_REGCONST, reg_obj, rc_key, reg_temps + 0); } else { - duk__ivalue_toplain_ignore(comp_ctx, res); /* just in case */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__ivalue_toplain_ignore(comp_ctx, res); /* just in case */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } goto parse_3_or_4; } else { @@ -73107,13 +74402,14 @@ * Variant 1 */ - DUK_DDD(DUK_DDDPRINT("detected for variant 1: for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement")); + DUK_DDD(DUK_DDDPRINT( + "detected for variant 1: for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement")); duk__ivalue_toplain_ignore(comp_ctx, res); goto parse_1_or_2; } } - parse_1_or_2: +parse_1_or_2: /* * Parse variant 1 or 2. The first part expression (which differs * in the variants) has already been parsed and its code emitted. @@ -73136,23 +74432,23 @@ duk__advance_expect(comp_ctx, DUK_TOK_SEMICOLON); pc_l1 = duk__get_current_pc(comp_ctx); - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ + duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ if (duk__expr_is_empty(comp_ctx)) { /* no need to coerce */ - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ - pc_jumpto_l4 = -1; /* omitted */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ + pc_jumpto_l4 = -1; /* omitted */ } else { rc_cond = duk__ivalue_toregconst(comp_ctx, res); duk__emit_if_false_skip(comp_ctx, rc_cond); - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ - pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); /* to exit */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ + pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); /* to exit */ } DUK__SETTEMP(comp_ctx, temp_reset); duk__advance_expect(comp_ctx, DUK_TOK_SEMICOLON); pc_l2 = duk__get_current_pc(comp_ctx); - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ + duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ if (duk__expr_is_empty(comp_ctx)) { /* no need to coerce */ expr_c_empty = 1; @@ -73165,7 +74461,7 @@ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_l3 = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -73180,21 +74476,23 @@ DUK_DDD(DUK_DDDPRINT("patching jumps: jumpto_l3: %ld->%ld, jumpto_l4: %ld->%ld, " "break: %ld->%ld, continue: %ld->%ld", - (long) pc_jumpto_l3, (long) pc_l3, (long) pc_jumpto_l4, (long) pc_l4, - (long) (pc_label_site + 1), (long) pc_l4, (long) (pc_label_site + 2), (long) pc_l2)); + (long) pc_jumpto_l3, + (long) pc_l3, + (long) pc_jumpto_l4, + (long) pc_l4, + (long) (pc_label_site + 1), + (long) pc_l4, + (long) (pc_label_site + 2), + (long) pc_l2)); duk__patch_jump(comp_ctx, pc_jumpto_l3, pc_l3); duk__patch_jump(comp_ctx, pc_jumpto_l4, pc_l4); - duk__patch_jump(comp_ctx, - pc_label_site + 1, - pc_l4); /* break jump */ - duk__patch_jump(comp_ctx, - pc_label_site + 2, - expr_c_empty ? pc_l1 : pc_l2); /* continue jump */ + duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l4); /* break jump */ + duk__patch_jump(comp_ctx, pc_label_site + 2, expr_c_empty ? pc_l1 : pc_l2); /* continue jump */ } goto finished; - parse_3_or_4: +parse_3_or_4: /* * Parse variant 3 or 4. * @@ -73230,16 +74528,16 @@ */ duk__insert_jump_entry(comp_ctx, pc_v34_lhs); - pc_jumpto_l2 = pc_v34_lhs; /* inserted jump */ - pc_l1 = pc_v34_lhs + 1; /* +1, right after inserted jump */ + pc_jumpto_l2 = pc_v34_lhs; /* inserted jump */ + pc_l1 = pc_v34_lhs + 1; /* +1, right after inserted jump */ /* The code for writing reg_temps + 0 to the left hand side has already * been emitted. */ - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* -> loop body */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* -> loop body */ - duk__advance(comp_ctx); /* eat 'in' */ + duk__advance(comp_ctx); /* eat 'in' */ /* Parse enumeration target and initialize enumerator. For 'null' and 'undefined', * INITENUM will creates a 'null' enumerator which works like an empty enumerator @@ -73248,16 +74546,13 @@ */ pc_l2 = duk__get_current_pc(comp_ctx); - reg_target = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression */ - duk__emit_b_c(comp_ctx, - DUK_OP_INITENUM | DUK__EMIT_FLAG_B_IS_TARGET, - reg_temps + 1, - reg_target); + reg_target = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression */ + duk__emit_b_c(comp_ctx, DUK_OP_INITENUM | DUK__EMIT_FLAG_B_IS_TARGET, reg_temps + 1, reg_target); pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_l3 = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -73274,8 +74569,8 @@ DUK_OP_NEXTENUM | DUK__EMIT_FLAG_B_IS_TARGET | DUK__EMIT_FLAG_RESERVE_JUMPSLOT, reg_temps + 0, reg_temps + 1); - pc_jumpto_l5 = comp_ctx->emit_jumpslot_pc; /* NEXTENUM jump slot: executed when enum finished */ - duk__emit_jump(comp_ctx, pc_l1); /* jump to next loop, using reg_v34_iter as iterated value */ + pc_jumpto_l5 = comp_ctx->emit_jumpslot_pc; /* NEXTENUM jump slot: executed when enum finished */ + duk__emit_jump(comp_ctx, pc_l1); /* jump to next loop, using reg_v34_iter as iterated value */ pc_l5 = duk__get_current_pc(comp_ctx); @@ -73287,24 +74582,33 @@ DUK_DDD(DUK_DDDPRINT("patching jumps: jumpto_l2: %ld->%ld, jumpto_l3: %ld->%ld, " "jumpto_l4: %ld->%ld, jumpto_l5: %ld->%ld, " "break: %ld->%ld, continue: %ld->%ld", - (long) pc_jumpto_l2, (long) pc_l2, (long) pc_jumpto_l3, (long) pc_l3, - (long) pc_jumpto_l4, (long) pc_l4, (long) pc_jumpto_l5, (long) pc_l5, - (long) (pc_label_site + 1), (long) pc_l5, (long) (pc_label_site + 2), (long) pc_l4)); + (long) pc_jumpto_l2, + (long) pc_l2, + (long) pc_jumpto_l3, + (long) pc_l3, + (long) pc_jumpto_l4, + (long) pc_l4, + (long) pc_jumpto_l5, + (long) pc_l5, + (long) (pc_label_site + 1), + (long) pc_l5, + (long) (pc_label_site + 2), + (long) pc_l4)); duk__patch_jump(comp_ctx, pc_jumpto_l2, pc_l2); duk__patch_jump(comp_ctx, pc_jumpto_l3, pc_l3); duk__patch_jump(comp_ctx, pc_jumpto_l4, pc_l4); duk__patch_jump(comp_ctx, pc_jumpto_l5, pc_l5); - duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l5); /* break jump */ - duk__patch_jump(comp_ctx, pc_label_site + 2, pc_l4); /* continue jump */ + duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l5); /* break jump */ + duk__patch_jump(comp_ctx, pc_label_site + 2, pc_l4); /* continue jump */ } goto finished; - finished: +finished: DUK_DDD(DUK_DDDPRINT("end parsing a for/for-in statement")); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_FOR); DUK_WO_NORETURN(return;); } @@ -73312,12 +74616,12 @@ DUK_LOCAL void duk__parse_switch_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site) { duk_hthread *thr = comp_ctx->thr; duk_regconst_t temp_at_loop; - duk_regconst_t rc_switch; /* reg/const for switch value */ - duk_regconst_t rc_case; /* reg/const for case value */ - duk_regconst_t reg_temp; /* general temp register */ + duk_regconst_t rc_switch; /* reg/const for switch value */ + duk_regconst_t rc_case; /* reg/const for case value */ + duk_regconst_t reg_temp; /* general temp register */ duk_int_t pc_prevcase = -1; duk_int_t pc_prevstmt = -1; - duk_int_t pc_default = -1; /* -1 == not set, -2 == pending (next statement list) */ + duk_int_t pc_default = -1; /* -1 == not set, -2 == pending (next statement list) */ /* Note: negative pc values are ignored when patching jumps, so no explicit checks needed */ @@ -73348,7 +74652,7 @@ duk__advance(comp_ctx); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); rc_switch = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); DUK_DDD(DUK_DDDPRINT("switch value in register %ld", (long) rc_switch)); @@ -73378,24 +74682,20 @@ * because it may be a constant. */ - duk__patch_jump_here(comp_ctx, pc_prevcase); /* chain jumps for case - * evaluation and checking - */ + duk__patch_jump_here(comp_ctx, pc_prevcase); /* chain jumps for case + * evaluation and checking + */ duk__advance(comp_ctx); rc_case = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__advance_expect(comp_ctx, DUK_TOK_COLON); reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_b_c(comp_ctx, - DUK_OP_SEQ | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - rc_switch, - rc_case); + duk__emit_a_b_c(comp_ctx, DUK_OP_SEQ | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, rc_switch, rc_case); duk__emit_if_true_skip(comp_ctx, reg_temp); /* jump to next case clause */ - pc_prevcase = duk__emit_jump_empty(comp_ctx); /* no match, next case */ + pc_prevcase = duk__emit_jump_empty(comp_ctx); /* no match, next case */ /* statements go here (if any) on next loop */ } else if (comp_ctx->curr_token.t == DUK_TOK_DEFAULT) { @@ -73444,14 +74744,13 @@ * they participate in 'fall-through' behavior even if the * default clause is in the middle. */ - duk__patch_jump_here(comp_ctx, pc_prevstmt); /* chain jumps for 'fall-through' - * after a case matches. - */ + duk__patch_jump_here(comp_ctx, pc_prevstmt); /* chain jumps for 'fall-through' + * after a case matches. + */ for (;;) { tok = comp_ctx->curr_token.t; - if (tok == DUK_TOK_CASE || tok == DUK_TOK_DEFAULT || - tok == DUK_TOK_RCURLY) { + if (tok == DUK_TOK_CASE || tok == DUK_TOK_DEFAULT || tok == DUK_TOK_RCURLY) { break; } num_stmts++; @@ -73474,7 +74773,7 @@ DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RCURLY); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance(comp_ctx); /* Allow RegExp as part of next stmt. */ + duk__advance(comp_ctx); /* Allow RegExp as part of next stmt. */ /* default case control flow patchup; note that if pc_prevcase < 0 * (i.e. no case clauses), control enters default case automatically. @@ -73495,7 +74794,7 @@ duk__patch_jump_here(comp_ctx, pc_prevstmt); /* continue jump not patched, an INVALID opcode remains there */ - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ /* Note: 'fast' breaks will jump to pc_label_site + 1, which will * then jump here. The double jump will be eliminated by a @@ -73505,7 +74804,7 @@ return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_SWITCH); DUK_WO_NORETURN(return;); } @@ -73519,16 +74818,16 @@ temp_reset = DUK__GETTEMP(comp_ctx); - duk__advance(comp_ctx); /* eat 'if' */ + duk__advance(comp_ctx); /* eat 'if' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); rc_cond = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__emit_if_true_skip(comp_ctx, rc_cond); - pc_jump_false = duk__emit_jump_empty(comp_ctx); /* jump to end or else part */ + pc_jump_false = duk__emit_jump_empty(comp_ctx); /* jump to end or else part */ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -73543,7 +74842,7 @@ duk__advance(comp_ctx); - pc_jump_end = duk__emit_jump_empty(comp_ctx); /* jump from true part to end */ + pc_jump_end = duk__emit_jump_empty(comp_ctx); /* jump from true part to end */ duk__patch_jump_here(comp_ctx, pc_jump_false); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -73564,11 +74863,11 @@ DUK_DDD(DUK_DDDPRINT("begin parsing do statement")); - duk__advance(comp_ctx); /* Eat 'do'; allow RegExp as part of next stmt. */ + duk__advance(comp_ctx); /* Eat 'do'; allow RegExp as part of next stmt. */ pc_start = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); - duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ duk__advance_expect(comp_ctx, DUK_TOK_WHILE); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); @@ -73578,10 +74877,10 @@ duk__emit_jump(comp_ctx, pc_start); /* no need to reset temps, as we're finished emitting code */ - comp_ctx->curr_func.allow_regexp_in_adv = 1; /* Allow RegExp as part of next stmt. */ + comp_ctx->curr_func.allow_regexp_in_adv = 1; /* Allow RegExp as part of next stmt. */ duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ DUK_DDD(DUK_DDDPRINT("end parsing do statement")); } @@ -73596,12 +74895,12 @@ temp_reset = DUK__GETTEMP(comp_ctx); - duk__advance(comp_ctx); /* eat 'while' */ + duk__advance(comp_ctx); /* eat 'while' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); pc_start = duk__get_current_pc(comp_ctx); - duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ rc_cond = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__emit_if_true_skip(comp_ctx, rc_cond); @@ -73609,13 +74908,13 @@ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); duk__emit_jump(comp_ctx, pc_start); duk__patch_jump_here(comp_ctx, pc_jump_false); - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ DUK_DDD(DUK_DDDPRINT("end parsing while statement")); } @@ -73625,23 +74924,35 @@ duk_bool_t is_break = (comp_ctx->curr_token.t == DUK_TOK_BREAK); duk_int_t label_id; duk_int_t label_catch_depth; - duk_int_t label_pc; /* points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue */ + duk_int_t label_pc; /* points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue */ duk_bool_t label_is_closest; DUK_UNREF(res); - duk__advance(comp_ctx); /* eat 'break' or 'continue' */ + duk__advance(comp_ctx); /* eat 'break' or 'continue' */ - if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ - comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ - comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ + if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ + comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ + comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ /* break/continue without label */ - duk__lookup_active_label(comp_ctx, DUK_HTHREAD_STRING_EMPTY_STRING(thr), is_break, &label_id, &label_catch_depth, &label_pc, &label_is_closest); + duk__lookup_active_label(comp_ctx, + DUK_HTHREAD_STRING_EMPTY_STRING(thr), + is_break, + &label_id, + &label_catch_depth, + &label_pc, + &label_is_closest); } else if (comp_ctx->curr_token.t == DUK_TOK_IDENTIFIER) { /* break/continue with label (label cannot be a reserved word, production is 'Identifier' */ DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); - duk__lookup_active_label(comp_ctx, comp_ctx->curr_token.str1, is_break, &label_id, &label_catch_depth, &label_pc, &label_is_closest); + duk__lookup_active_label(comp_ctx, + comp_ctx->curr_token.str1, + is_break, + &label_id, + &label_catch_depth, + &label_pc, + &label_is_closest); duk__advance(comp_ctx); } else { DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_BREAK_CONT_LABEL); @@ -73654,25 +74965,28 @@ * The peephole optimizer will optimize the jump to a direct one. */ - if (label_catch_depth == comp_ctx->curr_func.catch_depth && - label_is_closest) { + if (label_catch_depth == comp_ctx->curr_func.catch_depth && label_is_closest) { DUK_DDD(DUK_DDDPRINT("break/continue: is_break=%ld, label_id=%ld, label_is_closest=%ld, " "label_catch_depth=%ld, catch_depth=%ld " "-> use fast variant (direct jump)", - (long) is_break, (long) label_id, (long) label_is_closest, - (long) label_catch_depth, (long) comp_ctx->curr_func.catch_depth)); + (long) is_break, + (long) label_id, + (long) label_is_closest, + (long) label_catch_depth, + (long) comp_ctx->curr_func.catch_depth)); duk__emit_jump(comp_ctx, label_pc + (is_break ? 1 : 2)); } else { DUK_DDD(DUK_DDDPRINT("break/continue: is_break=%ld, label_id=%ld, label_is_closest=%ld, " "label_catch_depth=%ld, catch_depth=%ld " "-> use slow variant (longjmp)", - (long) is_break, (long) label_id, (long) label_is_closest, - (long) label_catch_depth, (long) comp_ctx->curr_func.catch_depth)); + (long) is_break, + (long) label_id, + (long) label_is_closest, + (long) label_catch_depth, + (long) comp_ctx->curr_func.catch_depth)); - duk__emit_bc(comp_ctx, - is_break ? DUK_OP_BREAK : DUK_OP_CONTINUE, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, is_break ? DUK_OP_BREAK : DUK_OP_CONTINUE, (duk_regconst_t) label_id); } } @@ -73680,7 +74994,7 @@ duk_hthread *thr = comp_ctx->thr; duk_regconst_t rc_val; - duk__advance(comp_ctx); /* eat 'return' */ + duk__advance(comp_ctx); /* eat 'return' */ /* A 'return' statement is only allowed inside an actual function body, * not as part of eval or global code. @@ -73690,9 +75004,9 @@ DUK_WO_NORETURN(return;); } - if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ - comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ - comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ + if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ + comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ + comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ DUK_DDD(DUK_DDDPRINT("empty return value -> undefined")); duk__emit_op_only(comp_ctx, DUK_OP_RETUNDEF); } else { @@ -73744,8 +75058,8 @@ */ #if defined(DUK_USE_TAILCALL) - if (comp_ctx->curr_func.catch_depth == 0 && /* no catchers */ - pc_after_expr > pc_before_expr) { /* at least one opcode emitted */ + if (comp_ctx->curr_func.catch_depth == 0 && /* no catchers */ + pc_after_expr > pc_before_expr) { /* at least one opcode emitted */ duk_compiler_instr *instr; duk_instr_t ins; duk_small_uint_t op; @@ -73755,8 +75069,7 @@ ins = instr->ins; op = (duk_small_uint_t) DUK_DEC_OP(ins); - if ((op & ~0x0fU) == DUK_OP_CALL0 && - DUK__ISREG_TEMP(comp_ctx, rc_val) /* see above */) { + if ((op & ~0x0fU) == DUK_OP_CALL0 && DUK__ISREG_TEMP(comp_ctx, rc_val) /* see above */) { DUK_DDD(DUK_DDDPRINT("return statement detected a tail call opportunity: " "catch depth is 0, duk__exprtop() emitted >= 1 instructions, " "and last instruction is a CALL " @@ -73765,7 +75078,7 @@ instr->ins = ins; } } -#endif /* DUK_USE_TAILCALL */ +#endif /* DUK_USE_TAILCALL */ if (DUK__ISREG(rc_val)) { duk__emit_bc(comp_ctx, DUK_OP_RETREG, rc_val); @@ -73783,7 +75096,7 @@ DUK_LOCAL void duk__parse_throw_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_regconst_t reg_val; - duk__advance(comp_ctx); /* eat 'throw' */ + duk__advance(comp_ctx); /* eat 'throw' */ /* Unlike break/continue, throw statement does not allow an empty value. */ @@ -73793,14 +75106,12 @@ } reg_val = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - duk__emit_bc(comp_ctx, - DUK_OP_THROW, - reg_val); + duk__emit_bc(comp_ctx, DUK_OP_THROW, reg_val); } DUK_LOCAL void duk__parse_try_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; - duk_regconst_t reg_catch; /* reg_catch+0 and reg_catch+1 are reserved for TRYCATCH */ + duk_regconst_t reg_catch; /* reg_catch+0 and reg_catch+1 are reserved for TRYCATCH */ duk_regconst_t rc_varname = 0; duk_small_uint_t trycatch_flags = 0; duk_int_t pc_ldconst = -1; @@ -73827,7 +75138,7 @@ comp_ctx->curr_func.catch_depth++; - duk__advance(comp_ctx); /* eat 'try' */ + duk__advance(comp_ctx); /* eat 'try' */ reg_catch = DUK__ALLOCTEMPS(comp_ctx, 2); @@ -73840,9 +75151,9 @@ duk__emit_a_bc(comp_ctx, DUK_OP_LDCONST, reg_catch, 0 /*patched later*/); pc_trycatch = duk__get_current_pc(comp_ctx); - duk__emit_invalid(comp_ctx); /* TRYCATCH, cannot emit now (not enough info) */ - duk__emit_invalid(comp_ctx); /* jump for 'catch' case */ - duk__emit_invalid(comp_ctx); /* jump for 'finally' case or end (if no finally) */ + duk__emit_invalid(comp_ctx); /* TRYCATCH, cannot emit now (not enough info) */ + duk__emit_invalid(comp_ctx); /* jump for 'catch' case */ + duk__emit_invalid(comp_ctx); /* jump for 'finally' case or end (if no finally) */ /* try part */ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); @@ -73871,7 +75182,7 @@ */ duk_hstring *h_var; - duk_int_t varmap_value; /* for storing/restoring the varmap binding for catch variable */ + duk_int_t varmap_value; /* for storing/restoring the varmap binding for catch variable */ DUK_DDD(DUK_DDDPRINT("stack top at start of catch clause: %ld", (long) duk_get_top(thr))); @@ -73889,19 +75200,17 @@ h_var = comp_ctx->curr_token.str1; DUK_ASSERT(h_var != NULL); - duk_push_hstring(thr, h_var); /* keep in on valstack, use borrowed ref below */ + duk_push_hstring(thr, h_var); /* keep in on valstack, use borrowed ref below */ if (comp_ctx->curr_func.is_strict && - ((h_var == DUK_HTHREAD_STRING_EVAL(thr)) || - (h_var == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr)))) { + ((h_var == DUK_HTHREAD_STRING_EVAL(thr)) || (h_var == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr)))) { DUK_DDD(DUK_DDDPRINT("catch identifier 'eval' or 'arguments' in strict mode -> SyntaxError")); goto syntax_error; } duk_dup_top(thr); rc_varname = duk__getconst(comp_ctx); - DUK_DDD(DUK_DDDPRINT("catch clause, rc_varname=0x%08lx (%ld)", - (unsigned long) rc_varname, (long) rc_varname)); + DUK_DDD(DUK_DDDPRINT("catch clause, rc_varname=0x%08lx (%ld)", (unsigned long) rc_varname, (long) rc_varname)); duk__advance(comp_ctx); duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); @@ -73964,8 +75273,7 @@ DUK_DDD(DUK_DDDPRINT("varmap after restore catch clause: %!iT", (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.varmap_idx))); - duk__emit_op_only(comp_ctx, - DUK_OP_ENDCATCH); + duk__emit_op_only(comp_ctx, DUK_OP_ENDCATCH); /* * XXX: for now, indicate that an expensive catch binding @@ -73988,13 +75296,10 @@ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); duk__parse_stmts(comp_ctx, 0 /*allow_source_elem*/, 0 /*expect_eof*/, 1 /*regexp_after*/); /* the DUK_TOK_RCURLY is eaten by duk__parse_stmts() */ - duk__emit_abc(comp_ctx, - DUK_OP_ENDFIN, - reg_catch); /* rethrow */ + duk__emit_abc(comp_ctx, DUK_OP_ENDFIN, reg_catch); /* rethrow */ } - if (!(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) && - !(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY)) { + if (!(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) && !(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY)) { /* must have catch and/or finally */ goto syntax_error; } @@ -74004,12 +75309,7 @@ * constant 0) the DUK__CONST_MARKER flag will be set in rc_varname. */ - duk__patch_trycatch(comp_ctx, - pc_ldconst, - pc_trycatch, - reg_catch, - rc_varname, - trycatch_flags); + duk__patch_trycatch(comp_ctx, pc_ldconst, pc_trycatch, reg_catch, rc_varname, trycatch_flags); if (trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) { DUK_ASSERT(pc_catch >= 0); @@ -74027,7 +75327,7 @@ comp_ctx->curr_func.catch_depth--; return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_TRY); DUK_WO_NORETURN(return;); } @@ -74045,23 +75345,23 @@ comp_ctx->curr_func.catch_depth++; - duk__advance(comp_ctx); /* eat 'with' */ + duk__advance(comp_ctx); /* eat 'with' */ reg_catch = DUK__ALLOCTEMPS(comp_ctx, 2); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); duk__exprtop_toforcedreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/, reg_catch); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_trycatch = duk__get_current_pc(comp_ctx); trycatch_flags = DUK_BC_TRYCATCH_FLAG_WITH_BINDING; duk__emit_a_bc(comp_ctx, - DUK_OP_TRYCATCH | DUK__EMIT_FLAG_NO_SHUFFLE_A, - (duk_regconst_t) trycatch_flags /*a*/, - reg_catch /*bc*/); - duk__emit_invalid(comp_ctx); /* catch jump */ - duk__emit_invalid(comp_ctx); /* finished jump */ + DUK_OP_TRYCATCH | DUK__EMIT_FLAG_NO_SHUFFLE_A, + (duk_regconst_t) trycatch_flags /*a*/, + reg_catch /*bc*/); + duk__emit_invalid(comp_ctx); /* catch jump */ + duk__emit_invalid(comp_ctx); /* finished jump */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); duk__emit_op_only(comp_ctx, DUK_OP_ENDTRY); @@ -74082,9 +75382,7 @@ label_id = comp_ctx->curr_func.label_next++; DUK_DDD(DUK_DDDPRINT("allocated new label id for label site: %ld", (long) label_id)); - duk__emit_bc(comp_ctx, - DUK_OP_LABEL, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, DUK_OP_LABEL, (duk_regconst_t) label_id); duk__emit_invalid(comp_ctx); duk__emit_invalid(comp_ctx); @@ -74098,10 +75396,10 @@ */ DUK_LOCAL void duk__parse_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_bool_t allow_source_elem) { duk_hthread *thr = comp_ctx->thr; - duk_bool_t dir_prol_at_entry; /* directive prologue status at entry */ + duk_bool_t dir_prol_at_entry; /* directive prologue status at entry */ duk_regconst_t temp_at_entry; duk_size_t labels_len_at_entry; - duk_int_t pc_at_entry; /* assumed to also be PC of "LABEL" */ + duk_int_t pc_at_entry; /* assumed to also be PC of "LABEL" */ duk_int_t stmt_id; duk_small_uint_t stmt_flags = 0; duk_int_t label_id = -1; @@ -74120,8 +75418,11 @@ DUK_DDD(DUK_DDDPRINT("parsing a statement, stmt_id=%ld, temp_at_entry=%ld, labels_len_at_entry=%ld, " "is_strict=%ld, in_directive_prologue=%ld, catch_depth=%ld", - (long) stmt_id, (long) temp_at_entry, (long) labels_len_at_entry, - (long) comp_ctx->curr_func.is_strict, (long) comp_ctx->curr_func.in_directive_prologue, + (long) stmt_id, + (long) temp_at_entry, + (long) labels_len_at_entry, + (long) comp_ctx->curr_func.is_strict, + (long) comp_ctx->curr_func.in_directive_prologue, (long) comp_ctx->curr_func.catch_depth)); /* The directive prologue flag is cleared by default so that it is @@ -74131,10 +75432,12 @@ */ comp_ctx->curr_func.in_directive_prologue = 0; - retry_parse: +retry_parse: DUK_DDD(DUK_DDDPRINT("try stmt parse, stmt_id=%ld, label_id=%ld, allow_source_elem=%ld, catch_depth=%ld", - (long) stmt_id, (long) label_id, (long) allow_source_elem, + (long) stmt_id, + (long) label_id, + (long) allow_source_elem, (long) comp_ctx->curr_func.catch_depth)); /* @@ -74143,15 +75446,11 @@ */ tok = comp_ctx->curr_token.t; - if (tok == DUK_TOK_FOR || tok == DUK_TOK_DO || tok == DUK_TOK_WHILE || - tok == DUK_TOK_SWITCH) { + if (tok == DUK_TOK_FOR || tok == DUK_TOK_DO || tok == DUK_TOK_WHILE || tok == DUK_TOK_SWITCH) { DUK_DDD(DUK_DDDPRINT("iteration/switch statement -> add empty label")); label_id = duk__stmt_label_site(comp_ctx, label_id); - duk__add_label(comp_ctx, - DUK_HTHREAD_STRING_EMPTY_STRING(thr), - pc_at_entry /*pc_label*/, - label_id); + duk__add_label(comp_ctx, DUK_HTHREAD_STRING_EMPTY_STRING(thr), pc_at_entry /*pc_label*/, label_id); } /* @@ -74178,10 +75477,8 @@ * strict and non-strict modes. However, don't allow labelled * function declarations in strict mode. */ - test_func_decl = test_func_decl || - !comp_ctx->curr_func.is_strict || - label_id < 0; -#endif /* DUK_USE_NONSTD_FUNC_STMT */ + test_func_decl = test_func_decl || !comp_ctx->curr_func.is_strict || label_id < 0; +#endif /* DUK_USE_NONSTD_FUNC_STMT */ /* Strict: never allow function declarations outside top level. */ if (test_func_decl) { /* FunctionDeclaration: not strictly a statement but handled as such. @@ -74203,7 +75500,7 @@ top_before = duk_get_top(thr); #endif - duk__advance(comp_ctx); /* eat 'function' */ + duk__advance(comp_ctx); /* eat 'function' */ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_DECL | DUK__FUNC_FLAG_PUSHNAME_PASS1); /* The value stack convention here is a bit odd: the function @@ -74217,7 +75514,8 @@ DUK_ASSERT(duk_get_top(thr) == top_before + 1); #endif DUK_DDD(DUK_DDDPRINT("register function declaration %!T in pass 1, fnum %ld", - duk_get_tval(thr, -1), (long) fnum)); + duk_get_tval(thr, -1), + (long) fnum)); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); /* funcname is at index -1 */ duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n); @@ -74244,7 +75542,7 @@ duk__parse_stmts(comp_ctx, 0 /*allow_source_elem*/, 0 /*expect_eof*/, 1 /*regexp_after*/); /* the DUK_TOK_RCURLY is eaten by duk__parse_stmts() */ if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } stmt_flags = 0; break; @@ -74271,7 +75569,7 @@ DUK_DDD(DUK_DDDPRINT("if statement")); duk__parse_if_stmt(comp_ctx, res); if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } stmt_flags = 0; break; @@ -74288,19 +75586,15 @@ */ DUK_DDD(DUK_DDDPRINT("do statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_do_stmt(comp_ctx, res, pc_at_entry); - stmt_flags = DUK__HAS_TERM | DUK__ALLOW_AUTO_SEMI_ALWAYS; /* DUK__ALLOW_AUTO_SEMI_ALWAYS workaround */ + stmt_flags = DUK__HAS_TERM | DUK__ALLOW_AUTO_SEMI_ALWAYS; /* DUK__ALLOW_AUTO_SEMI_ALWAYS workaround */ break; } case DUK_TOK_WHILE: { DUK_DDD(DUK_DDDPRINT("while statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_while_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -74315,9 +75609,7 @@ */ DUK_DDD(DUK_DDDPRINT("for/for-in statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_for_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -74340,7 +75632,7 @@ comp_ctx->curr_func.with_depth++; duk__parse_with_stmt(comp_ctx, res); if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } comp_ctx->curr_func.with_depth--; stmt_flags = 0; @@ -74353,9 +75645,7 @@ */ DUK_DDD(DUK_DDDPRINT("switch statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK); /* don't allow continue */ + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK); /* don't allow continue */ duk__parse_switch_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -74422,12 +75712,10 @@ DUK_DDD(DUK_DDDPRINT("expression statement")); duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - single_token = (comp_ctx->curr_func.nud_count == 1 && /* one token */ - comp_ctx->curr_func.led_count == 0); /* no operators */ + single_token = (comp_ctx->curr_func.nud_count == 1 && /* one token */ + comp_ctx->curr_func.led_count == 0); /* no operators */ - if (single_token && - comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->curr_token.t == DUK_TOK_COLON) { + if (single_token && comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->curr_token.t == DUK_TOK_COLON) { /* * Detected label */ @@ -74441,17 +75729,13 @@ h_lab = comp_ctx->prev_token.str1; DUK_ASSERT(h_lab != NULL); - DUK_DDD(DUK_DDDPRINT("explicit label site for label '%!O'", - (duk_heaphdr *) h_lab)); + DUK_DDD(DUK_DDDPRINT("explicit label site for label '%!O'", (duk_heaphdr *) h_lab)); - duk__advance(comp_ctx); /* eat colon */ + duk__advance(comp_ctx); /* eat colon */ label_id = duk__stmt_label_site(comp_ctx, label_id); - duk__add_label(comp_ctx, - h_lab, - pc_at_entry /*pc_label*/, - label_id); + duk__add_label(comp_ctx, h_lab, pc_at_entry /*pc_label*/, label_id); /* a statement following a label cannot be a source element * (a function declaration). @@ -74464,8 +75748,8 @@ stmt_flags = 0; - if (dir_prol_at_entry && /* still in prologue */ - single_token && /* single string token */ + if (dir_prol_at_entry && /* still in prologue */ + single_token && /* single string token */ comp_ctx->prev_token.t == DUK_TOK_STRING) { /* * Detected a directive @@ -74498,7 +75782,8 @@ DUK_STRCMP((const char *) DUK_HSTRING_GET_DATA(h_dir), "use strict") == 0) { #if defined(DUK_USE_STRICT_DECL) DUK_DDD(DUK_DDDPRINT("use strict directive detected: strict flag %ld -> %ld", - (long) comp_ctx->curr_func.is_strict, (long) 1)); + (long) comp_ctx->curr_func.is_strict, + (long) 1)); comp_ctx->curr_func.is_strict = 1; #else DUK_DDD(DUK_DDDPRINT("use strict detected but strict declarations disabled, ignoring")); @@ -74506,21 +75791,23 @@ } else if (DUK_HSTRING_GET_BYTELEN(h_dir) == 14 && DUK_STRCMP((const char *) DUK_HSTRING_GET_DATA(h_dir), "use duk notail") == 0) { DUK_DDD(DUK_DDDPRINT("use duk notail directive detected: notail flag %ld -> %ld", - (long) comp_ctx->curr_func.is_notail, (long) 1)); + (long) comp_ctx->curr_func.is_notail, + (long) 1)); comp_ctx->curr_func.is_notail = 1; } else { DUK_DD(DUK_DDPRINT("unknown directive: '%!O', ignoring but not terminating " - "directive prologue", (duk_hobject *) h_dir)); + "directive prologue", + (duk_hobject *) h_dir)); } } } else { DUK_DDD(DUK_DDDPRINT("non-directive expression statement or no longer in prologue; " "prologue terminated if still active")); - } + } stmt_flags |= DUK__HAS_VAL | DUK__HAS_TERM; } - } /* end switch (tok) */ + } /* end switch (tok) */ /* * Statement value handling. @@ -74596,9 +75883,7 @@ */ if (label_id >= 0) { - duk__emit_bc(comp_ctx, - DUK_OP_ENDLABEL, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, DUK_OP_ENDLABEL, (duk_regconst_t) label_id); } DUK__SETTEMP(comp_ctx, temp_at_entry); @@ -74621,7 +75906,10 @@ * (EOF or closing brace). */ -DUK_LOCAL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, duk_bool_t allow_source_elem, duk_bool_t expect_eof, duk_bool_t regexp_after) { +DUK_LOCAL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, + duk_bool_t allow_source_elem, + duk_bool_t expect_eof, + duk_bool_t regexp_after) { duk_hthread *thr = comp_ctx->thr; duk_ivalue res_alloc; duk_ivalue *res = &res_alloc; @@ -74787,7 +76075,7 @@ /* only functions can have arguments */ DUK_ASSERT(comp_ctx->curr_func.is_function); - duk_push_uarridx(thr, i); /* -> ... name index */ + duk_push_uarridx(thr, i); /* -> ... name index */ duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* -> ... */ /* no code needs to be emitted, the regs already have values */ @@ -74823,16 +76111,15 @@ */ num_decls = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); - DUK_DDD(DUK_DDDPRINT("num_decls=%ld -> %!T", - (long) num_decls, - (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.decls_idx))); + DUK_DDD( + DUK_DDDPRINT("num_decls=%ld -> %!T", (long) num_decls, (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.decls_idx))); for (i = 0; i < num_decls; i += 2) { duk_int_t decl_type; duk_int_t fnum; - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ decl_type = duk_to_int(thr, -1); - fnum = decl_type >> 8; /* XXX: macros */ + fnum = decl_type >> 8; /* XXX: macros */ decl_type = decl_type & 0xff; duk_pop(thr); @@ -74840,7 +76127,7 @@ continue; } - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ /* XXX: spilling */ if (comp_ctx->curr_func.is_function) { @@ -74850,18 +76137,12 @@ /* shadowed; update value */ duk_dup_top(thr); duk_get_prop(thr, comp_ctx->curr_func.varmap_idx); - reg_bind = duk_to_int(thr, -1); /* ... name reg_bind */ - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_bind, - (duk_regconst_t) fnum); + reg_bind = duk_to_int(thr, -1); /* ... name reg_bind */ + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_bind, (duk_regconst_t) fnum); } else { /* function: always register bound */ reg_bind = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_bind, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_bind, (duk_regconst_t) fnum); duk_push_int(thr, (duk_int_t) reg_bind); } } else { @@ -74878,14 +76159,9 @@ rc_name = duk__getconst(comp_ctx); duk_push_null(thr); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp, - (duk_regconst_t) fnum); - - declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE | - DUK_BC_DECLVAR_FLAG_FUNC_DECL; + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp, (duk_regconst_t) fnum); + + declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_BC_DECLVAR_FLAG_FUNC_DECL; if (configurable_bindings) { declvar_flags |= DUK_PROPDESC_FLAG_CONFIGURABLE; @@ -74897,7 +76173,7 @@ rc_name /*name*/, reg_temp /*value*/); - DUK__SETTEMP(comp_ctx, reg_temp); /* forget temp */ + DUK__SETTEMP(comp_ctx, reg_temp); /* forget temp */ } DUK_DDD(DUK_DDDPRINT("function declaration to varmap: %!T -> %!T", @@ -74907,7 +76183,7 @@ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_NULL(duk_get_tval(thr, -1)) || DUK_TVAL_IS_FASTINT(duk_get_tval(thr, -1))); #endif - duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ + duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ } /* @@ -74934,7 +76210,7 @@ for (i = 0; i < num_decls; i += 2) { duk_int_t decl_type; - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ decl_type = duk_to_int(thr, -1); decl_type = decl_type & 0xff; duk_pop(thr); @@ -74943,16 +76219,15 @@ continue; } - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ if (duk_has_prop(thr, comp_ctx->curr_func.varmap_idx)) { /* shadowed, ignore */ } else { - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ h_name = duk_known_hstring(thr, -1); - if (h_name == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr) && - !comp_ctx->curr_func.is_arguments_shadowed) { + if (h_name == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr) && !comp_ctx->curr_func.is_arguments_shadowed) { /* E5 Section steps 7-8 */ DUK_DDD(DUK_DDDPRINT("'arguments' not shadowed by a function declaration, " "but appears as a variable declaration -> treat as " @@ -74971,8 +76246,7 @@ rc_name = duk__getconst(comp_ctx); duk_push_null(thr); - declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE; + declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE; if (configurable_bindings) { declvar_flags |= DUK_PROPDESC_FLAG_CONFIGURABLE; } @@ -74984,7 +76258,7 @@ 0 /*value*/); } - duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ + duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ } } @@ -74999,11 +76273,11 @@ DUK_ASSERT_TOP(thr, entry_top); return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); - error_argname: +error_argname: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_ARG_NAME); DUK_WO_NORETURN(return;); } @@ -75042,7 +76316,11 @@ * token (EOF or closing brace). */ -DUK_LOCAL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, duk_bool_t expect_eof, duk_bool_t implicit_return_value, duk_bool_t regexp_after, duk_small_int_t expect_token) { +DUK_LOCAL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, + duk_bool_t expect_eof, + duk_bool_t implicit_return_value, + duk_bool_t regexp_after, + duk_small_int_t expect_token) { duk_compiler_func *func; duk_hthread *thr; duk_regconst_t reg_stmt_value = -1; @@ -75134,8 +76412,8 @@ DUK_DDD(DUK_DDDPRINT("begin 1st pass")); duk__parse_stmts(comp_ctx, - 1, /* allow source elements */ - expect_eof, /* expect EOF instead of } */ + 1, /* allow source elements */ + expect_eof, /* expect EOF instead of } */ regexp_after); /* regexp after */ DUK_DDD(DUK_DDDPRINT("end 1st pass")); @@ -75164,8 +76442,8 @@ DUK_DDD(DUK_DDDPRINT("rewind lexer")); DUK_LEXER_SETPOINT(&comp_ctx->lex, &lex_pt); - comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ duk__advance(comp_ctx); /* @@ -75186,8 +76464,7 @@ /* must be able to emit code, alloc consts, etc. */ - duk__init_varmap_and_prologue_for_pass2(comp_ctx, - (implicit_return_value ? ®_stmt_value : NULL)); + duk__init_varmap_and_prologue_for_pass2(comp_ctx, (implicit_return_value ? ®_stmt_value : NULL)); func->reg_stmt_value = reg_stmt_value; temp_first = DUK__GETTEMP(comp_ctx); @@ -75235,15 +76512,13 @@ if (implicit_return_value) { /* Default implicit return value. */ - duk__emit_bc(comp_ctx, - DUK_OP_LDUNDEF, - 0); + duk__emit_bc(comp_ctx, DUK_OP_LDUNDEF, 0); } DUK_DDD(DUK_DDDPRINT("begin 2nd pass")); duk__parse_stmts(comp_ctx, - 1, /* allow source elements */ - expect_eof, /* expect EOF instead of } */ + 1, /* allow source elements */ + expect_eof, /* expect EOF instead of } */ regexp_after); /* regexp after */ DUK_DDD(DUK_DDDPRINT("end 2nd pass")); @@ -75299,7 +76574,7 @@ DUK__RECURSION_DECREASE(comp_ctx, thr); return; - error_funcname: +error_funcname: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_FUNC_NAME); DUK_WO_NORETURN(return;); } @@ -75354,15 +76629,14 @@ } DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_IDENTIFIER); DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); - DUK_DDD(DUK_DDDPRINT("formal argument: %!O", - (duk_heaphdr *) comp_ctx->curr_token.str1)); + DUK_DDD(DUK_DDDPRINT("formal argument: %!O", (duk_heaphdr *) comp_ctx->curr_token.str1)); /* XXX: append primitive */ duk_push_hstring(thr, comp_ctx->curr_token.str1); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.argnames_idx); duk_put_prop_index(thr, comp_ctx->curr_func.argnames_idx, n); - duk__advance(comp_ctx); /* eat identifier */ + duk__advance(comp_ctx); /* eat identifier */ } } @@ -75410,7 +76684,7 @@ if (flags & DUK__FUNC_FLAG_GETSET) { /* PropertyName -> IdentifierName | StringLiteral | NumericLiteral */ if (tok->t_nores == DUK_TOK_IDENTIFIER || tok->t == DUK_TOK_STRING) { - duk_push_hstring(thr, tok->str1); /* keep in valstack */ + duk_push_hstring(thr, tok->str1); /* keep in valstack */ } else if (tok->t == DUK_TOK_NUMBER) { duk_push_number(thr, tok->num); duk_to_string(thr, -1); @@ -75418,15 +76692,15 @@ DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_GETSET_NAME); DUK_WO_NORETURN(return;); } - comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ + comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ } else { /* Function name is an Identifier (not IdentifierName), but we get * the raw name (not recognizing keywords) here and perform the name * checks only after pass 1. */ if (tok->t_nores == DUK_TOK_IDENTIFIER) { - duk_push_hstring(thr, tok->str1); /* keep in valstack */ - comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ + duk_push_hstring(thr, tok->str1); /* keep in valstack */ + comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ } else { /* valstack will be unbalanced, which is OK */ DUK_ASSERT((flags & DUK__FUNC_FLAG_GETSET) == 0); @@ -75439,8 +76713,7 @@ } } - DUK_DD(DUK_DDPRINT("function name: %!O", - (duk_heaphdr *) comp_ctx->curr_func.h_name)); + DUK_DD(DUK_DDPRINT("function name: %!O", (duk_heaphdr *) comp_ctx->curr_func.h_name)); if (!no_advance) { duk__advance(comp_ctx); @@ -75466,17 +76739,17 @@ */ duk__parse_func_body(comp_ctx, - 0, /* expect_eof */ - 0, /* implicit_return_value */ + 0, /* expect_eof */ + 0, /* implicit_return_value */ flags & DUK__FUNC_FLAG_DECL, /* regexp_after */ - DUK_TOK_LCURLY); /* expect_token */ + DUK_TOK_LCURLY); /* expect_token */ /* * Convert duk_compiler_func to a function template and add it * to the parent function table. */ - duk__convert_to_func_template(comp_ctx); /* -> ... func */ + duk__convert_to_func_template(comp_ctx); /* -> ... func */ } /* Parse an inner function, adding the function template to the current function's @@ -75514,12 +76787,14 @@ lex_pt.line = duk_to_int(thr, -1); duk_pop(thr); - DUK_DDD(DUK_DDDPRINT("second pass of an inner func, skip the function, reparse closing brace; lex offset=%ld, line=%ld", - (long) lex_pt.offset, (long) lex_pt.line)); + DUK_DDD( + DUK_DDDPRINT("second pass of an inner func, skip the function, reparse closing brace; lex offset=%ld, line=%ld", + (long) lex_pt.offset, + (long) lex_pt.line)); DUK_LEXER_SETPOINT(&comp_ctx->lex, &lex_pt); - comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ duk__advance(comp_ctx); /* RegExp is not allowed after a function expression, e.g. in @@ -75541,7 +76816,8 @@ entry_top = duk_get_top(thr); DUK_DDD(DUK_DDDPRINT("before func: entry_top=%ld, curr_tok.start_offset=%ld", - (long) entry_top, (long) comp_ctx->curr_token.start_offset)); + (long) entry_top, + (long) comp_ctx->curr_token.start_offset)); duk_memcpy(&old_func, &comp_ctx->curr_func, sizeof(duk_compiler_func)); @@ -75561,24 +76837,25 @@ DUK_ASSERT(comp_ctx->curr_func.is_eval == 0); DUK_ASSERT(comp_ctx->curr_func.is_global == 0); comp_ctx->curr_func.is_setget = ((flags & DUK__FUNC_FLAG_GETSET) != 0); - comp_ctx->curr_func.is_namebinding = !(flags & (DUK__FUNC_FLAG_GETSET | - DUK__FUNC_FLAG_METDEF | - DUK__FUNC_FLAG_DECL)); /* no name binding for: declarations, objlit getset, objlit method def */ - comp_ctx->curr_func.is_constructable = !(flags & (DUK__FUNC_FLAG_GETSET | - DUK__FUNC_FLAG_METDEF)); /* not constructable: objlit getset, objlit method def */ + comp_ctx->curr_func.is_namebinding = + !(flags & (DUK__FUNC_FLAG_GETSET | DUK__FUNC_FLAG_METDEF | + DUK__FUNC_FLAG_DECL)); /* no name binding for: declarations, objlit getset, objlit method def */ + comp_ctx->curr_func.is_constructable = + !(flags & (DUK__FUNC_FLAG_GETSET | DUK__FUNC_FLAG_METDEF)); /* not constructable: objlit getset, objlit method def */ /* * Parse inner function */ - duk__parse_func_like_raw(comp_ctx, flags); /* pushes function template */ + duk__parse_func_like_raw(comp_ctx, flags); /* pushes function template */ /* prev_token.start_offset points to the closing brace here; when skipping * we're going to reparse the closing brace to ensure semicolon insertion * etc work as expected. */ DUK_DDD(DUK_DDDPRINT("after func: prev_tok.start_offset=%ld, curr_tok.start_offset=%ld", - (long) comp_ctx->prev_token.start_offset, (long) comp_ctx->curr_token.start_offset)); + (long) comp_ctx->prev_token.start_offset, + (long) comp_ctx->curr_token.start_offset)); DUK_ASSERT(comp_ctx->lex.inputcomp_ctx->prev_token.start_offset == (duk_uint8_t) DUK_ASC_RCURLY); /* XXX: append primitive */ @@ -75664,7 +76941,7 @@ is_strict = (flags & DUK_COMPILE_STRICT ? 1 : 0); is_funcexpr = (flags & DUK_COMPILE_FUNCEXPR ? 1 : 0); - h_filename = duk_get_hstring(thr, -1); /* may be undefined */ + h_filename = duk_get_hstring(thr, -1); /* may be undefined */ /* * Init compiler and lexer contexts @@ -75682,11 +76959,11 @@ duk_require_stack(thr, DUK__COMPILE_ENTRY_SLOTS); - duk_push_dynamic_buffer(thr, 0); /* entry_top + 0 */ - duk_push_undefined(thr); /* entry_top + 1 */ - duk_push_undefined(thr); /* entry_top + 2 */ - duk_push_undefined(thr); /* entry_top + 3 */ - duk_push_undefined(thr); /* entry_top + 4 */ + duk_push_dynamic_buffer(thr, 0); /* entry_top + 0 */ + duk_push_undefined(thr); /* entry_top + 1 */ + duk_push_undefined(thr); /* entry_top + 2 */ + duk_push_undefined(thr); /* entry_top + 3 */ + duk_push_undefined(thr); /* entry_top + 4 */ comp_ctx->thr = thr; comp_ctx->h_filename = h_filename; @@ -75710,8 +76987,8 @@ lex_pt->offset = 0; lex_pt->line = 1; - DUK_LEXER_SETPOINT(&comp_ctx->lex, lex_pt); /* fills window */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + DUK_LEXER_SETPOINT(&comp_ctx->lex, lex_pt); /* fills window */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ /* * Initialize function state for a zero-argument function @@ -75727,8 +77004,7 @@ */ DUK_ASSERT(func->h_name == NULL); } else { - duk_push_hstring_stridx(thr, (is_eval ? DUK_STRIDX_EVAL : - DUK_STRIDX_GLOBAL)); + duk_push_hstring_stridx(thr, (is_eval ? DUK_STRIDX_EVAL : DUK_STRIDX_GLOBAL)); func->h_name = duk_get_hstring(thr, -1); } @@ -75748,7 +77024,7 @@ func->is_namebinding = 1; func->is_constructable = 1; - duk__advance(comp_ctx); /* init 'curr_token' */ + duk__advance(comp_ctx); /* init 'curr_token' */ duk__advance_expect(comp_ctx, DUK_TOK_FUNCTION); (void) duk__parse_func_like_raw(comp_ctx, 0 /*flags*/); } else { @@ -75760,10 +77036,10 @@ DUK_ASSERT(func->is_constructable == 0); duk__parse_func_body(comp_ctx, - 1, /* expect_eof */ - 1, /* implicit_return_value */ - 1, /* regexp_after (does not matter) */ - -1); /* expect_token */ + 1, /* expect_eof */ + 1, /* implicit_return_value */ + 1, /* regexp_after (does not matter) */ + -1); /* expect_token */ } /* @@ -75795,14 +77071,14 @@ DUK_LEXER_INITCTX(&comp_stk.comp_ctx_alloc.lex); comp_stk.comp_ctx_alloc.lex.input = src_buffer; comp_stk.comp_ctx_alloc.lex.input_length = src_length; - comp_stk.comp_ctx_alloc.lex.flags = flags; /* Forward flags directly for now. */ + comp_stk.comp_ctx_alloc.lex.flags = flags; /* Forward flags directly for now. */ /* ... filename */ prev_ctx = thr->compile_ctx; - thr->compile_ctx = &comp_stk.comp_ctx_alloc; /* for duk_error_augment.c */ + thr->compile_ctx = &comp_stk.comp_ctx_alloc; /* for duk_error_augment.c */ safe_rc = duk_safe_call(thr, duk__js_compile_raw, (void *) &comp_stk /*udata*/, 1 /*nargs*/, 1 /*nrets*/); - thr->compile_ctx = prev_ctx; /* must restore reliably before returning */ + thr->compile_ctx = prev_ctx; /* must restore reliably before returning */ if (safe_rc != DUK_EXEC_SUCCESS) { DUK_D(DUK_DPRINT("compilation failed: %!T", duk_get_tval(thr, -1))); @@ -75916,7 +77192,8 @@ /* Replace value stack top to value at 'tv_ptr'. Optimize for * performance by only applying the net refcount change. */ -#define DUK__REPLACE_TO_TVPTR(thr,tv_ptr) do { \ +#define DUK__REPLACE_TO_TVPTR(thr, tv_ptr) \ + do { \ duk_hthread *duk__thr; \ duk_tval *duk__tvsrc; \ duk_tval *duk__tvdst; \ @@ -75926,13 +77203,13 @@ duk__tvdst = (tv_ptr); \ DUK_TVAL_SET_TVAL(&duk__tvtmp, duk__tvdst); \ DUK_TVAL_SET_TVAL(duk__tvdst, duk__tvsrc); \ - DUK_TVAL_SET_UNDEFINED(duk__tvsrc); /* value stack init policy */ \ + DUK_TVAL_SET_UNDEFINED(duk__tvsrc); /* value stack init policy */ \ duk__thr->valstack_top = duk__tvsrc; \ DUK_TVAL_DECREF(duk__thr, &duk__tvtmp); \ } while (0) /* XXX: candidate of being an internal shared API call */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__push_tvals_incref_only(duk_hthread *thr, duk_tval *tv_src, duk_small_uint_fast_t count) { duk_tval *tv_dst; duk_size_t copy_size; @@ -75974,7 +77251,10 @@ } #endif -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_add(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_fast_t idx_z) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_add(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_small_uint_fast_t idx_z) { /* * Addition operator is different from other arithmetic * operations in that it also provides string concatenation. @@ -75994,9 +77274,9 @@ duk_double_union du; DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); /* @@ -76019,14 +77299,14 @@ v3_hi = (duk_int32_t) (v3 >> 32); if (DUK_LIKELY(v3_hi >= DUK_I64_CONSTANT(-0x8000) && v3_hi <= DUK_I64_CONSTANT(0x7fff))) { tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ return; } else { /* overflow, fall through */ ; } } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { #if !defined(DUK_USE_EXEC_PREFER_SIZE) @@ -76035,14 +77315,14 @@ du.d = DUK_TVAL_GET_NUMBER(tv_x) + DUK_TVAL_GET_NUMBER(tv_y); #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ return; } @@ -76052,7 +77332,7 @@ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -2, DUK_HINT_NONE); /* side effects -> don't use tv_x, tv_y after */ + duk_to_primitive(thr, -2, DUK_HINT_NONE); /* side effects -> don't use tv_x, tv_y after */ duk_to_primitive(thr, -1, DUK_HINT_NONE); /* Since Duktape 2.x plain buffers are treated like ArrayBuffer. */ @@ -76063,7 +77343,7 @@ * in duk_concat_2() which also fails with TypeError so no * explicit check is needed. */ - duk_concat_2(thr); /* ... s1 s2 -> ... s1+s2 */ + duk_concat_2(thr); /* ... s1 s2 -> ... s1+s2 */ } else { duk_double_t d1, d2; @@ -76076,12 +77356,16 @@ du.d = d1 + d2; duk_pop_2_unsafe(thr); - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ } - duk_replace(thr, (duk_idx_t) idx_z); /* side effects */ + duk_replace(thr, (duk_idx_t) idx_z); /* side effects */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_binary_op(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_uint_fast_t idx_z, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_binary_op(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_uint_fast_t idx_z, + duk_small_uint_fast_t opcode) { /* * Arithmetic operations other than '+' have number-only semantics * and are implemented here. The separate switch-case here means a @@ -76098,12 +77382,12 @@ #endif DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); - opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ + opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y)) { @@ -76170,13 +77454,13 @@ v3_hi = (duk_int32_t) (v3 >> 32); if (DUK_LIKELY(v3_hi >= DUK_I64_CONSTANT(-0x8000) && v3_hi <= DUK_I64_CONSTANT(0x7fff))) { tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ return; } /* fall through if overflow etc */ } - skip_fastint: -#endif /* DUK_USE_FASTINT */ +skip_fastint: +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { /* fast path */ @@ -76185,7 +77469,7 @@ } else { duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - d1 = duk_to_number_m2(thr); /* side effects */ + d1 = duk_to_number_m2(thr); /* side effects */ d2 = duk_to_number_m1(thr); DUK_ASSERT(duk_is_number(thr, -2)); DUK_ASSERT(duk_is_number(thr, -1)); @@ -76222,24 +77506,28 @@ #endif default: { DUK_UNREACHABLE(); - du.d = DUK_DOUBLE_NAN; /* should not happen */ + du.d = DUK_DOUBLE_NAN; /* should not happen */ break; } } #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ /* important to use normalized NaN with 8-byte tagged types */ DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_bitwise_binary_op(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_fast_t idx_z, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_bitwise_binary_op(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_small_uint_fast_t idx_z, + duk_small_uint_fast_t opcode) { /* * Binary bitwise operations use different coercions (ToInt32, ToUint32) * depending on the operation. We coerce the arguments first using @@ -76263,20 +77551,19 @@ #endif DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); - opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ + opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y)) { i1 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv_x); i2 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv_y); - } - else -#endif /* DUK_USE_FASTINT */ + } else +#endif /* DUK_USE_FASTINT */ { duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); @@ -76305,15 +77592,15 @@ */ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; - i3 = (duk_int32_t) (((duk_uint32_t) i1) << (u2 & 0x1fUL)); /* E5 Section 11.7.1, steps 7 and 8 */ - i3 = i3 & ((duk_int32_t) 0xffffffffUL); /* Note: left shift, should mask */ + i3 = (duk_int32_t) (((duk_uint32_t) i1) << (u2 & 0x1fUL)); /* E5 Section 11.7.1, steps 7 and 8 */ + i3 = i3 & ((duk_int32_t) 0xffffffffUL); /* Note: left shift, should mask */ break; } case DUK_OP_BASR >> 2: { /* signed shift */ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; - i3 = i1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ + i3 = i1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ break; } case DUK_OP_BLSR >> 2: { @@ -76323,7 +77610,7 @@ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; /* special result value handling */ - u3 = u1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ + u3 = u1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ #if defined(DUK_USE_FASTINT) fi3 = (duk_int64_t) u3; goto fastint_result_set; @@ -76334,7 +77621,7 @@ } default: { DUK_UNREACHABLE(); - i3 = 0; /* should not happen */ + i3 = 0; /* should not happen */ break; } } @@ -76346,28 +77633,31 @@ */ fi3 = (duk_int64_t) i3; - fastint_result_set: +fastint_result_set: tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, fi3); /* side effects */ -#else /* DUK_USE_FASTINT */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, fi3); /* side effects */ +#else /* DUK_USE_FASTINT */ d3 = (duk_double_t) i3; - result_set: - DUK_ASSERT(!DUK_ISNAN(d3)); /* 'd3' is never NaN, so no need to normalize */ - DUK_ASSERT_DOUBLE_IS_NORMALIZED(d3); /* always normalized */ +result_set: + DUK_ASSERT(!DUK_ISNAN(d3)); /* 'd3' is never NaN, so no need to normalize */ + DUK_ASSERT_DOUBLE_IS_NORMALIZED(d3); /* always normalized */ #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, d3); /* would NaN normalize result, but unnecessary */ + duk_push_number(thr, d3); /* would NaN normalize result, but unnecessary */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, d3); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ -#endif /* DUK_USE_FASTINT */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, d3); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_FASTINT */ } /* In-place unary operation. */ -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_unary_op(duk_hthread *thr, duk_uint_fast_t idx_src, duk_uint_fast_t idx_dst, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_unary_op(duk_hthread *thr, + duk_uint_fast_t idx_src, + duk_uint_fast_t idx_dst, + duk_small_uint_fast_t opcode) { /* * Arithmetic operations other than '+' have number-only semantics * and are implemented here. The separate switch-case here means a @@ -76413,12 +77703,12 @@ } /* fall through if overflow etc */ } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv)) { d1 = DUK_TVAL_GET_NUMBER(tv); } else { - d1 = duk_to_number_tval(thr, tv); /* side effects */ + d1 = duk_to_number_tval(thr, tv); /* side effects */ } if (opcode == DUK_OP_UNP) { @@ -76429,13 +77719,13 @@ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); #if defined(DUK_USE_FASTINT) tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); - DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF(thr, tv, du.d); /* always 'fast', i.e. inlined */ + DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF(thr, tv, du.d); /* always 'fast', i.e. inlined */ return; #endif } else { DUK_ASSERT(opcode == DUK_OP_UNM); du.d = -d1; - DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); /* mandatory if du.d is a NaN */ + DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); /* mandatory if du.d is a NaN */ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); } @@ -76463,19 +77753,18 @@ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv)) { i1 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv); - } - else -#endif /* DUK_USE_FASTINT */ + } else +#endif /* DUK_USE_FASTINT */ { duk_push_tval(thr, tv); - i1 = duk_to_int32(thr, -1); /* side effects */ + i1 = duk_to_int32(thr, -1); /* side effects */ duk_pop_unsafe(thr); } /* Result is always fastint compatible. */ i2 = ~i1; tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); - DUK_TVAL_SET_I32_UPDREF(thr, tv, i2); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv, i2); /* side effects */ } DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_logical_not(duk_hthread *thr, duk_uint_fast_t idx_src, duk_uint_fast_t idx_dst) { @@ -76497,16 +77786,19 @@ * duk_js_toboolean() and then push+replace to the result slot. */ tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_src); - res = duk_js_toboolean(tv); /* does not modify 'tv' */ + res = duk_js_toboolean(tv); /* does not modify 'tv' */ DUK_ASSERT(res == 0 || res == 1); res ^= 1; tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); /* XXX: size optimize: push+replace? */ - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, res); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, res); /* side effects */ } /* XXX: size optimized variant */ -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_reg_helper(duk_hthread *thr, duk_tval *tv_dst, duk_tval *tv_src, duk_small_uint_t op) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_reg_helper(duk_hthread *thr, + duk_tval *tv_dst, + duk_tval *tv_src, + duk_small_uint_t op) { duk_double_t x, y, z; /* Two lowest bits of opcode are used to distinguish @@ -76533,13 +77825,13 @@ y_fi = x_fi + 1; } - DUK_TVAL_SET_FASTINT(tv_src, y_fi); /* no need for refcount update */ + DUK_TVAL_SET_FASTINT(tv_src, y_fi); /* no need for refcount update */ z_fi = (op & 0x02) ? x_fi : y_fi; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_dst, z_fi); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_dst, z_fi); /* side effects */ return; } - skip_fastint: +skip_fastint: #endif if (DUK_TVAL_IS_NUMBER(tv_src)) { /* Fast path for the case where the register @@ -76553,7 +77845,7 @@ y = x + 1.0; } - DUK_TVAL_SET_NUMBER(tv_src, y); /* no need for refcount update */ + DUK_TVAL_SET_NUMBER(tv_src, y); /* no need for refcount update */ } else { /* Preserve duk_tval pointer(s) across a potential valstack * resize by converting them into offsets temporarily. @@ -76562,8 +77854,8 @@ duk_size_t off_dst; off_dst = (duk_size_t) ((duk_uint8_t *) tv_dst - (duk_uint8_t *) thr->valstack_bottom); - bc = (duk_idx_t) (tv_src - thr->valstack_bottom); /* XXX: pass index explicitly? */ - tv_src = NULL; /* no longer referenced */ + bc = (duk_idx_t) (tv_src - thr->valstack_bottom); /* XXX: pass index explicitly? */ + tv_src = NULL; /* no longer referenced */ x = duk_to_number(thr, bc); if (op & 0x01) { @@ -76579,10 +77871,14 @@ } z = (op & 0x02) ? x : y; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_dst, z); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_dst, z); /* side effects */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_var_helper(duk_hthread *thr, duk_small_uint_t idx_dst, duk_tval *tv_id, duk_small_uint_t op, duk_small_uint_t is_strict) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_var_helper(duk_hthread *thr, + duk_small_uint_t idx_dst, + duk_tval *tv_id, + duk_small_uint_t op, + duk_small_uint_t is_strict) { duk_activation *act; duk_double_t x, y; duk_hstring *name; @@ -76608,7 +77904,7 @@ name = DUK_TVAL_GET_STRING(tv_id); DUK_ASSERT(name != NULL); act = thr->callstack_curr; - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ /* XXX: Fastint fast path would be useful here. Also fastints * now lose their fastint status in current handling which is @@ -76625,22 +77921,22 @@ /* ... x this */ if (op & 0x02) { - duk_push_number(thr, y); /* -> ... x this y */ + duk_push_number(thr, y); /* -> ... x this y */ DUK_ASSERT(act == thr->callstack_curr); duk_js_putvar_activation(thr, act, name, DUK_GET_TVAL_NEGIDX(thr, -1), is_strict); - duk_pop_2_unsafe(thr); /* -> ... x */ + duk_pop_2_unsafe(thr); /* -> ... x */ } else { - duk_pop_2_unsafe(thr); /* -> ... */ - duk_push_number(thr, y); /* -> ... y */ + duk_pop_2_unsafe(thr); /* -> ... */ + duk_push_number(thr, y); /* -> ... y */ DUK_ASSERT(act == thr->callstack_curr); duk_js_putvar_activation(thr, act, name, DUK_GET_TVAL_NEGIDX(thr, -1), is_strict); } #if defined(DUK_USE_EXEC_PREFER_SIZE) duk_replace(thr, (duk_idx_t) idx_dst); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ DUK__REPLACE_TO_TVPTR(thr, DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } /* @@ -76654,11 +77950,11 @@ * handled recursively. */ -#define DUK__LONGJMP_RESTART 0 /* state updated, restart bytecode execution */ -#define DUK__LONGJMP_RETHROW 1 /* exit bytecode executor by rethrowing an error to caller */ +#define DUK__LONGJMP_RESTART 0 /* state updated, restart bytecode execution */ +#define DUK__LONGJMP_RETHROW 1 /* exit bytecode executor by rethrowing an error to caller */ -#define DUK__RETHAND_RESTART 0 /* state updated, restart bytecode execution */ -#define DUK__RETHAND_FINISHED 1 /* exit bytecode execution with return value */ +#define DUK__RETHAND_RESTART 0 /* state updated, restart bytecode execution */ +#define DUK__RETHAND_FINISHED 1 /* exit bytecode execution with return value */ /* XXX: optimize reconfig valstack operations so that resize, clamp, and setting * top are combined into one pass. @@ -76687,7 +77983,8 @@ thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act->bottom_byteoff); DUK_ASSERT(act->retval_byteoff >= act->bottom_byteoff); - clamp_top = (duk_idx_t) ((act->retval_byteoff - act->bottom_byteoff + sizeof(duk_tval)) / sizeof(duk_tval)); /* +1 = one retval */ + clamp_top = + (duk_idx_t) ((act->retval_byteoff - act->bottom_byteoff + sizeof(duk_tval)) / sizeof(duk_tval)); /* +1 = one retval */ duk_set_top_and_wipe(thr, h_func->nregs, clamp_top); DUK_ASSERT((duk_uint8_t *) thr->valstack_end >= (duk_uint8_t *) thr->valstack + act->reserve_byteoff); @@ -76717,7 +78014,7 @@ thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act->bottom_byteoff); idx_bottom = (duk_size_t) (thr->valstack_bottom - thr->valstack); DUK_ASSERT(cat->idx_base >= idx_bottom); - clamp_top = (duk_idx_t) (cat->idx_base - idx_bottom + 2); /* +2 = catcher value, catcher lj_type */ + clamp_top = (duk_idx_t) (cat->idx_base - idx_bottom + 2); /* +2 = catcher value, catcher lj_type */ duk_set_top_and_wipe(thr, h_func->nregs, clamp_top); DUK_ASSERT((duk_uint8_t *) thr->valstack_end >= (duk_uint8_t *) thr->valstack + act->reserve_byteoff); @@ -76745,7 +78042,10 @@ DUK_TVAL_SET_U32_UPDREF_NORZ(thr, tv1, (duk_uint32_t) lj_type); } -DUK_LOCAL void duk__handle_catch_part1(duk_hthread *thr, duk_tval *tv_val_unstable, duk_small_uint_t lj_type, volatile duk_bool_t *out_delayed_catch_setup) { +DUK_LOCAL void duk__handle_catch_part1(duk_hthread *thr, + duk_tval *tv_val_unstable, + duk_small_uint_t lj_type, + volatile duk_bool_t *out_delayed_catch_setup) { duk_activation *act; duk_catcher *cat; @@ -76783,7 +78083,7 @@ cat = act->cat; DUK_ASSERT(cat != NULL); - act->curr_pc = cat->pc_base + 0; /* +0 = catch */ + act->curr_pc = cat->pc_base + 0; /* +0 = catch */ /* * If the catch block has an automatic catch variable binding, @@ -76843,9 +78143,7 @@ DUK_ASSERT(act->var_env != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(act) != NULL); - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) new_env) == NULL); @@ -76863,7 +78161,7 @@ duk_push_hstring(thr, cat->h_varname); DUK_ASSERT(thr->valstack + cat->idx_base < thr->valstack_top); duk_push_tval(thr, thr->valstack + cat->idx_base); - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_W); /* writable, not configurable */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_W); /* writable, not configurable */ /* ... env */ @@ -76871,7 +78169,7 @@ DUK_ASSERT(act != NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) new_env, act->lex_env); act->lex_env = (duk_hobject *) new_env; - DUK_HOBJECT_INCREF(thr, (duk_hobject *) new_env); /* reachable through activation */ + DUK_HOBJECT_INCREF(thr, (duk_hobject *) new_env); /* reachable through activation */ /* Net refcount change to act->lex_env is 0: incref for new_env's * prototype, decref for act->lex_env overwrite. */ @@ -76913,7 +78211,7 @@ cat = act->cat; DUK_ASSERT(cat != NULL); - act->curr_pc = cat->pc_base + 1; /* +1 = finally */ + act->curr_pc = cat->pc_base + 1; /* +1 = finally */ DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } @@ -76962,18 +78260,21 @@ act_resumer = resumer->callstack_curr; DUK_ASSERT(act_resumer != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(act_resumer) != NULL); - DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(act_resumer))); /* resume caller must be an ECMAScript func */ + DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(act_resumer))); /* resume caller must be an ECMAScript func */ - tv1 = (duk_tval *) (void *) ((duk_uint8_t *) resumer->valstack + act_resumer->retval_byteoff); /* return value from Duktape.Thread.resume() */ - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv_val_unstable); /* side effects */ /* XXX: avoid side effects */ + tv1 = (duk_tval *) (void *) ((duk_uint8_t *) resumer->valstack + + act_resumer->retval_byteoff); /* return value from Duktape.Thread.resume() */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv_val_unstable); /* side effects */ /* XXX: avoid side effects */ duk__reconfig_valstack_ecma_return(resumer); /* caller must change active thread, and set thr->resumer to NULL */ } -#endif /* DUK_USE_COROUTINE_SUPPORT */ +#endif /* DUK_USE_COROUTINE_SUPPORT */ -DUK_LOCAL duk_small_uint_t duk__handle_longjmp(duk_hthread *thr, duk_activation *entry_act, volatile duk_bool_t *out_delayed_catch_setup) { +DUK_LOCAL duk_small_uint_t duk__handle_longjmp(duk_hthread *thr, + duk_activation *entry_act, + volatile duk_bool_t *out_delayed_catch_setup) { duk_small_uint_t retval = DUK__LONGJMP_RESTART; DUK_ASSERT(thr != NULL); @@ -76994,17 +78295,16 @@ * - 'thr' must reflect the "throwing" thread */ - check_longjmp: +check_longjmp: DUK_DD(DUK_DDPRINT("handling longjmp: type=%ld, value1=%!T, value2=%!T, iserror=%ld, top=%ld", (long) thr->heap->lj.type, (duk_tval *) &thr->heap->lj.value1, (duk_tval *) &thr->heap->lj.value2, (long) thr->heap->lj.iserror, - (long) duk_get_top(thr))); + (long) duk_get_top(thr))); switch (thr->heap->lj.type) { - #if defined(DUK_USE_COROUTINE_SUPPORT) case DUK_LJ_TYPE_RESUME: { /* @@ -77018,15 +78318,15 @@ /* duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met */ - DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged by Duktape.Thread.resume() */ - DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged by Duktape.Thread.resume() */ + DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->callstack_curr))->func == duk_bi_thread_resume); - tv = &thr->heap->lj.value2; /* resumee */ + tv = &thr->heap->lj.value2; /* resumee */ DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv)); DUK_ASSERT(DUK_TVAL_GET_OBJECT(tv) != NULL); DUK_ASSERT(DUK_HOBJECT_IS_THREAD(DUK_TVAL_GET_OBJECT(tv))); @@ -77035,15 +78335,15 @@ DUK_ASSERT(resumee != NULL); DUK_ASSERT(resumee->resumer == NULL); DUK_ASSERT(resumee->state == DUK_HTHREAD_STATE_INACTIVE || - resumee->state == DUK_HTHREAD_STATE_YIELDED); /* checked by Duktape.Thread.resume() */ + resumee->state == DUK_HTHREAD_STATE_YIELDED); /* checked by Duktape.Thread.resume() */ DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_YIELDED || - resumee->callstack_top >= 2); /* YIELDED: ECMAScript activation + Duktape.Thread.yield() activation */ + resumee->callstack_top >= 2); /* YIELDED: ECMAScript activation + Duktape.Thread.yield() activation */ DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_YIELDED || (DUK_ACT_GET_FUNC(resumee->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(resumee->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(resumee->callstack_curr))->func == duk_bi_thread_yield)); DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_INACTIVE || - resumee->callstack_top == 0); /* INACTIVE: no activation, single function value on valstack */ + resumee->callstack_top == 0); /* INACTIVE: no activation, single function value on valstack */ if (thr->heap->lj.iserror) { /* @@ -77069,7 +78369,7 @@ /* thr->heap->lj.value1 is already the value to throw */ /* thr->heap->lj.value2 is 'thread', will be wiped out at the end */ - DUK_ASSERT(thr->heap->lj.iserror); /* already set */ + DUK_ASSERT(thr->heap->lj.iserror); /* already set */ DUK_DD(DUK_DDPRINT("-> resume with an error, converted to a throw in the resumee, propagate")); goto check_longjmp; @@ -77082,17 +78382,18 @@ duk_activation *act_resumee; DUK_ASSERT(resumee->callstack_top >= 2); - act_resumee = resumee->callstack_curr; /* Duktape.Thread.yield() */ + act_resumee = resumee->callstack_curr; /* Duktape.Thread.yield() */ DUK_ASSERT(act_resumee != NULL); - act_resumee = act_resumee->parent; /* ECMAScript call site for yield() */ + act_resumee = act_resumee->parent; /* ECMAScript call site for yield() */ DUK_ASSERT(act_resumee != NULL); - tv = (duk_tval *) (void *) ((duk_uint8_t *) resumee->valstack + act_resumee->retval_byteoff); /* return value from Duktape.Thread.yield() */ + tv = (duk_tval *) (void *) ((duk_uint8_t *) resumee->valstack + + act_resumee->retval_byteoff); /* return value from Duktape.Thread.yield() */ DUK_ASSERT(tv >= resumee->valstack && tv < resumee->valstack_top); tv2 = &thr->heap->lj.value1; - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv2); /* side effects */ /* XXX: avoid side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv2); /* side effects */ /* XXX: avoid side effects */ - duk_hthread_activation_unwind_norz(resumee); /* unwind to 'yield' caller */ + duk_hthread_activation_unwind_norz(resumee); /* unwind to 'yield' caller */ /* no need to unwind catch stack */ duk__reconfig_valstack_ecma_return(resumee); @@ -77122,7 +78423,7 @@ /* resumee: ... initial_func undefined(= this) resume_value */ - call_flags = DUK_CALL_FLAG_ALLOW_ECMATOECMA; /* not tailcall, ecma-to-ecma (assumed to succeed) */ + call_flags = DUK_CALL_FLAG_ALLOW_ECMATOECMA; /* not tailcall, ecma-to-ecma (assumed to succeed) */ setup_rc = duk_handle_call_unprotected_nargs(resumee, 1 /*nargs*/, call_flags); if (setup_rc == 0) { @@ -77149,7 +78450,7 @@ goto wipe_and_return; } DUK_UNREACHABLE(); - break; /* never here */ + break; /* never here */ } case DUK_LJ_TYPE_YIELD: { @@ -77167,31 +78468,31 @@ /* duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met */ -#if 0 /* entry_thread not available for assert */ +#if 0 /* entry_thread not available for assert */ DUK_ASSERT(thr != entry_thread); /* Duktape.Thread.yield() should prevent */ #endif - DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged from Duktape.Thread.yield() */ - DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.yield() activation */ + DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged from Duktape.Thread.yield() */ + DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.yield() activation */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->callstack_curr))->func == duk_bi_thread_yield); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* an ECMAScript function */ resumer = thr->resumer; DUK_ASSERT(resumer != NULL); - DUK_ASSERT(resumer->state == DUK_HTHREAD_STATE_RESUMED); /* written by a previous RESUME handling */ - DUK_ASSERT(resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(resumer->state == DUK_HTHREAD_STATE_RESUMED); /* written by a previous RESUME handling */ + DUK_ASSERT(resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(resumer->callstack_curr != NULL); DUK_ASSERT(resumer->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(resumer->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(resumer->callstack_curr))->func == duk_bi_thread_resume); DUK_ASSERT(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent))); /* an ECMAScript function */ if (thr->heap->lj.iserror) { thr->state = DUK_HTHREAD_STATE_YIELDED; @@ -77203,7 +78504,7 @@ thr->heap->lj.type = DUK_LJ_TYPE_THROW; /* lj.value1 is already set */ - DUK_ASSERT(thr->heap->lj.iserror); /* already set */ + DUK_ASSERT(thr->heap->lj.iserror); /* already set */ DUK_DD(DUK_DDPRINT("-> yield an error, converted to a throw in the resumer, propagate")); goto check_longjmp; @@ -77229,9 +78530,9 @@ goto wipe_and_return; } DUK_UNREACHABLE(); - break; /* never here */ + break; /* never here */ } -#endif /* DUK_USE_COROUTINE_SUPPORT */ +#endif /* DUK_USE_COROUTINE_SUPPORT */ case DUK_LJ_TYPE_THROW: { /* @@ -77272,11 +78573,13 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF); DUK_DDD(DUK_DDDPRINT("before catch part 1: thr=%p, act=%p, cat=%p", - (void *) thr, (void *) act, (void *) act->cat)); + (void *) thr, + (void *) act, + (void *) act->cat)); duk__handle_catch_part1(thr, &thr->heap->lj.value1, DUK_LJ_TYPE_THROW, - out_delayed_catch_setup); + out_delayed_catch_setup); DUK_DD(DUK_DDPRINT("-> throw caught by a 'catch' clause, restart execution")); retval = DUK__LONGJMP_RESTART; @@ -77287,9 +78590,7 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF); DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); - duk__handle_finally(thr, - &thr->heap->lj.value1, - DUK_LJ_TYPE_THROW); + duk__handle_finally(thr, &thr->heap->lj.value1, DUK_LJ_TYPE_THROW); DUK_DD(DUK_DDPRINT("-> throw caught by a 'finally' clause, restart execution")); retval = DUK__LONGJMP_RESTART; @@ -77319,20 +78620,21 @@ */ DUK_ASSERT(thr->resumer != NULL); - DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->resumer->callstack_curr != NULL); DUK_ASSERT(thr->resumer->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_ASSERT( + DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ resumer = thr->resumer; /* reset longjmp */ - DUK_ASSERT(thr->heap->lj.type == DUK_LJ_TYPE_THROW); /* already set */ + DUK_ASSERT(thr->heap->lj.type == DUK_LJ_TYPE_THROW); /* already set */ /* lj.value1 already set */ - duk_hthread_terminate(thr); /* updates thread state, minimizes its allocations */ + duk_hthread_terminate(thr); /* updates thread state, minimizes its allocations */ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_TERMINATED); thr->resumer = NULL; @@ -77343,7 +78645,7 @@ goto check_longjmp; } - case DUK_LJ_TYPE_BREAK: /* pseudotypes, not used in actual longjmps */ + case DUK_LJ_TYPE_BREAK: /* pseudotypes, not used in actual longjmps */ case DUK_LJ_TYPE_CONTINUE: case DUK_LJ_TYPE_RETURN: case DUK_LJ_TYPE_NORMAL: @@ -77353,25 +78655,24 @@ goto convert_to_internal_error; } - } /* end switch */ + } /* end switch */ DUK_UNREACHABLE(); - wipe_and_return: - DUK_DD(DUK_DDPRINT("handling longjmp done, wipe-and-return, top=%ld", - (long) duk_get_top(thr))); +wipe_and_return: + DUK_DD(DUK_DDPRINT("handling longjmp done, wipe-and-return, top=%ld", (long) duk_get_top(thr))); thr->heap->lj.type = DUK_LJ_TYPE_UNKNOWN; thr->heap->lj.iserror = 0; - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value1); /* side effects */ - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value2); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value2); /* side effects */ DUK_GC_TORTURE(thr->heap); - just_return: +just_return: return retval; - convert_to_internal_error: +convert_to_internal_error: /* This could also be thrown internally (set the error, goto check_longjmp), * but it's better for internal errors to bubble outwards so that we won't * infinite loop in this catchpoint. @@ -77417,8 +78718,7 @@ /* XXX: bit mask test; FINALLY <-> TCF, single bit mask would suffice? */ - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && - DUK_CAT_HAS_FINALLY_ENABLED(cat)) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && DUK_CAT_HAS_FINALLY_ENABLED(cat)) { duk_tval tv_tmp; DUK_TVAL_SET_U32(&tv_tmp, (duk_uint32_t) label_id); @@ -77427,11 +78727,11 @@ DUK_DD(DUK_DDPRINT("-> break/continue caught by 'finally', restart execution")); return; } - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_LABEL && - (duk_uint_t) DUK_CAT_GET_LABEL(cat) == label_id) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_LABEL && (duk_uint_t) DUK_CAT_GET_LABEL(cat) == label_id) { duk__handle_label(thr, lj_type); - DUK_DD(DUK_DDPRINT("-> break/continue caught by a label catcher (in the same function), restart execution")); + DUK_DD( + DUK_DDPRINT("-> break/continue caught by a label catcher (in the same function), restart execution")); return; } @@ -77439,7 +78739,8 @@ } /* Should never happen, but be robust. */ - DUK_D(DUK_DPRINT("-> break/continue not caught by anything in the current function (should never happen), throw internal error")); + DUK_D(DUK_DPRINT( + "-> break/continue not caught by anything in the current function (should never happen), throw internal error")); DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); } @@ -77463,7 +78764,7 @@ DUK_ASSERT(entry_act != NULL); DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); tv1 = thr->valstack_top - 1; - DUK_TVAL_CHKFAST_INPLACE_FAST(tv1); /* fastint downgrade check for return values */ + DUK_TVAL_CHKFAST_INPLACE_FAST(tv1); /* fastint downgrade check for return values */ /* * Four possible outcomes: @@ -77498,8 +78799,7 @@ break; } - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && - DUK_CAT_HAS_FINALLY_ENABLED(cat)) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && DUK_CAT_HAS_FINALLY_ENABLED(cat)) { DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); duk__handle_finally(thr, thr->valstack_top - 1, DUK_LJ_TYPE_RETURN); @@ -77530,22 +78830,24 @@ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* must be ECMAScript */ + DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* must be ECMAScript */ #if defined(DUK_USE_ES6_PROXY) if (thr->callstack_curr->flags & (DUK_ACT_FLAG_CONSTRUCT | DUK_ACT_FLAG_CONSTRUCT_PROXY)) { - duk_call_construct_postprocess(thr, thr->callstack_curr->flags & DUK_ACT_FLAG_CONSTRUCT_PROXY); /* side effects */ + duk_call_construct_postprocess(thr, + thr->callstack_curr->flags & + DUK_ACT_FLAG_CONSTRUCT_PROXY); /* side effects */ } #else if (thr->callstack_curr->flags & DUK_ACT_FLAG_CONSTRUCT) { - duk_call_construct_postprocess(thr, 0); /* side effects */ + duk_call_construct_postprocess(thr, 0); /* side effects */ } #endif tv1 = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + thr->callstack_curr->parent->retval_byteoff); DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); tv2 = thr->valstack_top - 1; - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ /* Catch stack unwind happens inline in callstack unwind. */ duk_hthread_activation_unwind_norz(thr); @@ -77560,14 +78862,15 @@ DUK_DD(DUK_DDPRINT("no calling activation, thread finishes (similar to yield)")); DUK_ASSERT(thr->resumer != NULL); - DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->resumer->callstack_curr != NULL); DUK_ASSERT(thr->resumer->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr) != NULL && - DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr)) && - ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->resumer->callstack_curr))->func == duk_bi_thread_resume); /* Duktape.Thread.resume() */ + DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr)) && + ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->resumer->callstack_curr))->func == + duk_bi_thread_resume); /* Duktape.Thread.resume() */ DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); DUK_ASSERT(thr->resumer->state == DUK_HTHREAD_STATE_RESUMED); @@ -77589,11 +78892,11 @@ */ DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); - duk_hthread_activation_unwind_norz(resumer); /* May remove last reference to 'thr', but is NORZ. */ - duk_push_tval(resumer, thr->valstack_top - 1); /* Capture return value, side effect free. */ - duk_push_hthread(resumer, thr); /* Make 'thr' reachable again, before side effects. */ + duk_hthread_activation_unwind_norz(resumer); /* May remove last reference to 'thr', but is NORZ. */ + duk_push_tval(resumer, thr->valstack_top - 1); /* Capture return value, side effect free. */ + duk_push_hthread(resumer, thr); /* Make 'thr' reachable again, before side effects. */ - duk_hthread_terminate(thr); /* Updates thread state, minimizes its allocations. */ + duk_hthread_terminate(thr); /* Updates thread state, minimizes its allocations. */ thr->resumer = NULL; DUK_HTHREAD_DECREF(thr, resumer); DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_TERMINATED); @@ -77603,7 +78906,7 @@ DUK_ASSERT(resumer->valstack_top - 2 >= resumer->valstack_bottom); duk__handle_yield(thr, resumer, resumer->valstack_top - 2); - thr = NULL; /* 'thr' invalidated by call */ + thr = NULL; /* 'thr' invalidated by call */ #if 0 thr = resumer; /* not needed */ @@ -77645,8 +78948,8 @@ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK__INT_NOACTION 0 /* no specific action, resume normal execution */ -#define DUK__INT_RESTART 1 /* must "goto restart_execution", e.g. breakpoints changed */ +#define DUK__INT_NOACTION 0 /* no specific action, resume normal execution */ +#define DUK__INT_RESTART 1 /* must "goto restart_execution", e.g. breakpoints changed */ #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_LOCAL void duk__interrupt_handle_debugger(duk_hthread *thr, duk_bool_t *out_immediate, duk_small_uint_t *out_interrupt_retval) { @@ -77657,7 +78960,7 @@ duk_bool_t process_messages; duk_bool_t processed_messages = 0; - DUK_ASSERT(thr->heap->dbg_processing == 0); /* don't re-enter e.g. during Eval */ + DUK_ASSERT(thr->heap->dbg_processing == 0); /* don't re-enter e.g. during Eval */ act = thr->callstack_curr; DUK_ASSERT(act != NULL); @@ -77680,17 +78983,14 @@ * Breakpoint and step state checks */ - if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || - (thr->heap->dbg_pause_act == thr->callstack_curr)) { + if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || (thr->heap->dbg_pause_act == thr->callstack_curr)) { line = duk_debug_curr_line(thr); if (act->prev_line != line) { /* Stepped? Step out is handled by callstack unwind. */ if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && - (thr->heap->dbg_pause_act == thr->callstack_curr) && - (line != thr->heap->dbg_pause_startline)) { - DUK_D(DUK_DPRINT("PAUSE TRIGGERED by line change, at line %ld", - (long) line)); + (thr->heap->dbg_pause_act == thr->callstack_curr) && (line != thr->heap->dbg_pause_startline)) { + DUK_D(DUK_DPRINT("PAUSE TRIGGERED by line change, at line %ld", (long) line)); duk_debug_set_paused(thr->heap); } @@ -77716,7 +79016,8 @@ DUK_ASSERT(bp->filename != NULL); if (act->prev_line != bp->line && line == bp->line) { DUK_D(DUK_DPRINT("PAUSE TRIGGERED by breakpoint at %!O:%ld", - (duk_heaphdr *) bp->filename, (long) bp->line)); + (duk_heaphdr *) bp->filename, + (long) bp->line)); duk_debug_set_paused(thr->heap); } } @@ -77809,11 +79110,10 @@ if (duk_debug_is_attached(thr->heap)) { DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); - if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || - (thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_ONE_OPCODE) || + if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || (thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_ONE_OPCODE) || ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && thr->heap->dbg_pause_act == thr->callstack_curr) || - DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap)) { + DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap)) { *out_immediate = 1; } @@ -77835,7 +79135,7 @@ DUK_D(DUK_DPRINT("debugger became detached, resume normal execution")); } } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ DUK_LOCAL DUK_EXEC_NOINLINE_PERF DUK_COLD duk_small_uint_t duk__executor_interrupt(duk_hthread *thr) { duk_int_t ctr; @@ -77852,8 +79152,10 @@ thr->heap->inst_count_interrupt += thr->interrupt_init; DUK_DD(DUK_DDPRINT("execution interrupt, counter=%ld, init=%ld, " "instruction counts: executor=%ld, interrupt=%ld", - (long) thr->interrupt_counter, (long) thr->interrupt_init, - (long) thr->heap->inst_count_exec, (long) thr->heap->inst_count_interrupt)); + (long) thr->interrupt_counter, + (long) thr->interrupt_init, + (long) thr->heap->inst_count_exec, + (long) thr->heap->inst_count_interrupt)); #endif retval = DUK__INT_NOACTION; @@ -77915,18 +79217,17 @@ DUK_ERROR_RANGE(thr, "execution timeout"); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_EXEC_TIMEOUT_CHECK */ +#endif /* DUK_USE_EXEC_TIMEOUT_CHECK */ #if defined(DUK_USE_DEBUGGER_SUPPORT) - if (!thr->heap->dbg_processing && - (thr->heap->dbg_read_cb != NULL || thr->heap->dbg_detaching)) { + if (!thr->heap->dbg_processing && (thr->heap->dbg_read_cb != NULL || thr->heap->dbg_detaching)) { /* Avoid recursive re-entry; enter when we're attached or * detaching (to finish off the pending detach). */ duk__interrupt_handle_debugger(thr, &immediate, &retval); DUK_ASSERT(act == thr->callstack_curr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Update the interrupt counter @@ -77949,7 +79250,7 @@ return retval; } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ /* * Debugger handling for executor restart @@ -78017,8 +79318,7 @@ duk_hcompfunc *inner_fun; duk_bool_t bp_match; - if (bp->filename == filename && - bp->line >= fun->start_line && bp->line <= fun->end_line) { + if (bp->filename == filename && bp->line >= fun->start_line && bp->line <= fun->end_line) { bp_match = 1; DUK_DD(DUK_DDPRINT("breakpoint filename and line match: " "%s:%ld vs. %s (line %ld vs. %ld-%ld)", @@ -78055,13 +79355,12 @@ } } - *bp_active = NULL; /* terminate */ + *bp_active = NULL; /* terminate */ DUK_DD(DUK_DDPRINT("ACTIVE BREAKPOINTS: %ld", (long) (bp_active - thr->heap->dbg_breakpoints_active))); /* Force pause if we were doing "step into" in another activation. */ - if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_FUNC_ENTRY) && - thr->heap->dbg_pause_act != thr->callstack_curr) { + if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_FUNC_ENTRY) && thr->heap->dbg_pause_act != thr->callstack_curr) { DUK_D(DUK_DPRINT("PAUSE TRIGGERED by function entry")); duk_debug_set_paused(thr->heap); } @@ -78069,10 +79368,8 @@ /* Force interrupt right away if we're paused or in "checked mode". * Step out is handled by callstack unwind. */ - if ((act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE) || - DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || - ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && - thr->heap->dbg_pause_act == thr->callstack_curr)) { + if ((act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE) || DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || + ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && thr->heap->dbg_pause_act == thr->callstack_curr)) { /* We'll need to interrupt early so recompute the init * counter to reflect the number of bytecode instructions * executed so that step counts for e.g. debugger rate @@ -78083,7 +79380,7 @@ thr->interrupt_counter = 0; } } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Opcode handlers for opcodes with a lot of code and which are relatively @@ -78107,18 +79404,14 @@ /* This could be made more optimal by accessing internals directly. */ idx = (duk_uint_fast_t) DUK_DEC_BC(ins); - duk_dup(thr, (duk_idx_t) (idx + 0)); /* key */ - duk_dup(thr, (duk_idx_t) (idx + 1)); /* getter/setter */ + duk_dup(thr, (duk_idx_t) (idx + 0)); /* key */ + duk_dup(thr, (duk_idx_t) (idx + 1)); /* getter/setter */ if (is_set) { - defprop_flags = DUK_DEFPROP_HAVE_SETTER | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE; - } else { - defprop_flags = DUK_DEFPROP_HAVE_GETTER | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE; + defprop_flags = + DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE; + } else { + defprop_flags = + DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE; } duk_def_prop(thr, (duk_idx_t) DUK_DEC_A(ins), defprop_flags); } @@ -78183,7 +79476,7 @@ * error handling, so there's no side effect problem even if the * error value has a finalizer. */ - duk_dup(thr, (duk_idx_t) bc); /* Stabilize value. */ + duk_dup(thr, (duk_idx_t) bc); /* Stabilize value. */ duk_to_undefined(thr, (duk_idx_t) bc); duk_to_undefined(thr, (duk_idx_t) (bc + 1)); @@ -78198,7 +79491,7 @@ cat->flags = DUK_CAT_TYPE_TCF; cat->h_varname = NULL; - cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ + cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ cat->idx_base = (duk_size_t) (thr->valstack_bottom - thr->valstack) + bc; act = thr->callstack_curr; @@ -78237,7 +79530,7 @@ duk_js_init_activation_environment_records_delayed(thr, act); DUK_ASSERT(act == thr->callstack_curr); - DUK_UNREF(act); /* 'act' is no longer accessed, scanbuild fix */ + DUK_UNREF(act); /* 'act' is no longer accessed, scanbuild fix */ } DUK_ASSERT(act->lex_env != NULL); DUK_ASSERT(act->var_env != NULL); @@ -78250,12 +79543,10 @@ * so avoid side effects very carefully until it is * referenced. */ - env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + env = duk_hobjenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(env != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); - env->target = target; /* always provideThis=true */ + env->target = target; /* always provideThis=true */ DUK_HOBJECT_INCREF(thr, target); env->has_this = 1; DUK_HOBJENV_ASSERT_VALID(env); @@ -78265,7 +79556,7 @@ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); DUK_ASSERT(act->lex_env != NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) env, act->lex_env); - act->lex_env = (duk_hobject *) env; /* Now reachable. */ + act->lex_env = (duk_hobject *) env; /* Now reachable. */ DUK_HOBJECT_INCREF(thr, (duk_hobject *) env); /* Net refcount change to act->lex_env is 0: incref for env's * prototype, decref for act->lex_env overwrite. @@ -78274,7 +79565,7 @@ /* Set catcher lex_env active (affects unwind) * only when the whole setup is complete. */ - cat = act->cat; /* XXX: better to relookup? not mandatory because 'cat' is stable */ + cat = act->cat; /* XXX: better to relookup? not mandatory because 'cat' is stable */ cat->flags |= DUK_CAT_FLAG_LEXENV_ACTIVE; } else { ; @@ -78283,7 +79574,9 @@ DUK_DDD(DUK_DDDPRINT("TRYCATCH catcher: flags=0x%08lx, pc_base=%ld, " "idx_base=%ld, h_varname=%!O", (unsigned long) cat->flags, - (long) cat->pc_base, (long) cat->idx_base, (duk_heaphdr *) cat->h_varname)); + (long) cat->pc_base, + (long) cat->idx_base, + (duk_heaphdr *) cat->h_varname)); duk_pop_unsafe(thr); } @@ -78313,23 +79606,24 @@ tv1 = thr->valstack + cat->idx_base; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ tv1 = NULL; tv1 = thr->valstack + cat->idx_base + 1; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ tv1 = NULL; DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } else { - DUK_DDD(DUK_DDDPRINT("ENDTRY: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); + DUK_DDD( + DUK_DDDPRINT("ENDTRY: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); - duk_hthread_catcher_unwind_norz(thr, act); /* lexenv may be set for 'with' binding */ + duk_hthread_catcher_unwind_norz(thr, act); /* lexenv may be set for 'with' binding */ /* no need to unwind callstack */ } - return pc_base + 1; /* new curr_pc value */ + return pc_base + 1; /* new curr_pc value */ } DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_instr_t *duk__handle_op_endcatch(duk_hthread *thr, duk_uint_fast32_t ins) { @@ -78345,7 +79639,7 @@ DUK_ASSERT(act != NULL); cat = act->cat; DUK_ASSERT(cat != NULL); - DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); /* cleared before entering catch part */ + DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); /* cleared before entering catch part */ if (DUK_CAT_HAS_LEXENV_ACTIVE(cat)) { duk_hobject *prev_env; @@ -78361,7 +79655,7 @@ act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, prev_env); DUK_CAT_CLEAR_LEXENV_ACTIVE(cat); DUK_HOBJECT_INCREF(thr, act->lex_env); - DUK_HOBJECT_DECREF(thr, prev_env); /* side effects */ + DUK_HOBJECT_DECREF(thr, prev_env); /* side effects */ DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); @@ -78374,26 +79668,29 @@ tv1 = thr->valstack + cat->idx_base; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ tv1 = NULL; tv1 = thr->valstack + cat->idx_base + 1; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ tv1 = NULL; DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } else { - DUK_DDD(DUK_DDDPRINT("ENDCATCH: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); + DUK_DDD( + DUK_DDDPRINT("ENDCATCH: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); duk_hthread_catcher_unwind_norz(thr, act); /* no need to unwind callstack */ } - return pc_base + 1; /* new curr_pc value */ + return pc_base + 1; /* new curr_pc value */ } -DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_small_uint_t duk__handle_op_endfin(duk_hthread *thr, duk_uint_fast32_t ins, duk_activation *entry_act) { +DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_small_uint_t duk__handle_op_endfin(duk_hthread *thr, + duk_uint_fast32_t ins, + duk_activation *entry_act) { duk_activation *act; duk_tval *tv1; duk_uint_t reg_catch; @@ -78415,7 +79712,7 @@ (duk_tval *) (thr->valstack_bottom + reg_catch + 0), (duk_tval *) (thr->valstack_bottom + reg_catch + 1))); - tv1 = thr->valstack_bottom + reg_catch + 1; /* type */ + tv1 = thr->valstack_bottom + reg_catch + 1; /* type */ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv1)); #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv1)); @@ -78424,7 +79721,7 @@ cont_type = (duk_small_uint_t) DUK_TVAL_GET_NUMBER(tv1); #endif - tv1--; /* value */ + tv1--; /* value */ switch (cont_type) { case DUK_LJ_TYPE_NORMAL: { @@ -78433,11 +79730,12 @@ duk_hthread_catcher_unwind_norz(thr, act); /* no need to unwind callstack */ - return 0; /* restart execution */ + return 0; /* restart execution */ } case DUK_LJ_TYPE_RETURN: { DUK_DDD(DUK_DDDPRINT("ENDFIN: finally part finishing with 'return' complation -> dismantle " - "catcher, handle return, lj.value1=%!T", tv1)); + "catcher, handle return, lj.value1=%!T", + tv1)); /* Not necessary to unwind catch stack: return handling will * do it. The finally flag of 'cat' is no longer set. The @@ -78447,12 +79745,12 @@ duk_push_tval(thr, tv1); ret_result = duk__handle_return(thr, entry_act); if (ret_result == DUK__RETHAND_RESTART) { - return 0; /* restart execution */ + return 0; /* restart execution */ } DUK_ASSERT(ret_result == DUK__RETHAND_FINISHED); DUK_DDD(DUK_DDDPRINT("exiting executor after ENDFIN and RETURN (pseudo) longjmp type")); - return 1; /* exit executor */ + return 1; /* exit executor */ } case DUK_LJ_TYPE_BREAK: case DUK_LJ_TYPE_CONTINUE: { @@ -78474,7 +79772,7 @@ #endif lj_type = cont_type; duk__handle_break_or_continue(thr, label_id, lj_type); - return 0; /* restart execution */ + return 0; /* restart execution */ } default: { DUK_DDD(DUK_DDDPRINT("ENDFIN: finally part finishing with abrupt completion, lj_type=%ld -> " @@ -78484,7 +79782,7 @@ duk_err_setup_ljstate1(thr, (duk_small_uint_t) cont_type, tv1); /* No debugger Throw notify check on purpose (rethrow). */ - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ duk_err_longjmp(thr); DUK_UNREACHABLE(); } @@ -78517,7 +79815,7 @@ } else { duk_dup(thr, (duk_idx_t) c); duk_to_object(thr, -1); - duk_hobject_enumerator_create(thr, 0 /*enum_flags*/); /* ... val --> ... enum */ + duk_hobject_enumerator_create(thr, 0 /*enum_flags*/); /* ... val --> ... enum */ duk_replace(thr, (duk_idx_t) b); } } @@ -78549,13 +79847,12 @@ duk_dup(thr, (duk_idx_t) c); if (duk_hobject_enumerator_next(thr, 0 /*get_value*/)) { /* ... enum -> ... next_key */ - DUK_DDD(DUK_DDDPRINT("enum active, next key is %!T, skip jump slot ", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("enum active, next key is %!T, skip jump slot ", (duk_tval *) duk_get_tval(thr, -1))); pc_skip = 1; } else { /* ... enum -> ... */ DUK_DDD(DUK_DDDPRINT("enum finished, execute jump slot")); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } duk_replace(thr, (duk_idx_t) b); @@ -78575,7 +79872,7 @@ DUK_LOCAL duk_bool_t duk__executor_handle_call(duk_hthread *thr, duk_idx_t idx, duk_idx_t nargs, duk_small_uint_t call_flags) { duk_bool_t rc; - duk_set_top_unsafe(thr, (duk_idx_t) (idx + nargs + 2)); /* ... func this arg1 ... argN */ + duk_set_top_unsafe(thr, (duk_idx_t) (idx + nargs + 2)); /* ... func this arg1 ... argN */ /* Attempt an Ecma-to-Ecma call setup. If the call * target is (directly or indirectly) Reflect.construct(), @@ -78629,22 +79926,22 @@ * difference and the best option is architecture dependent. */ #if defined(DUK_USE_EXEC_FUN_LOCAL) -#define DUK__FUN() fun +#define DUK__FUN() fun #else -#define DUK__FUN() ((duk_hcompfunc *) DUK_ACT_GET_FUNC((thr)->callstack_curr)) +#define DUK__FUN() ((duk_hcompfunc *) DUK_ACT_GET_FUNC((thr)->callstack_curr)) #endif /* Strict flag. */ -#define DUK__STRICT() ((duk_small_uint_t) DUK_HOBJECT_HAS_STRICT((duk_hobject *) DUK__FUN())) +#define DUK__STRICT() ((duk_small_uint_t) DUK_HOBJECT_HAS_STRICT((duk_hobject *) DUK__FUN())) /* Reg/const access macros: these are very footprint and performance sensitive * so modify with care. Arguments are sometimes evaluated multiple times which * is not ideal. */ -#define DUK__REG(x) (*(thr->valstack_bottom + (x))) -#define DUK__REGP(x) (thr->valstack_bottom + (x)) -#define DUK__CONST(x) (*(consts + (x))) -#define DUK__CONSTP(x) (consts + (x)) +#define DUK__REG(x) (*(thr->valstack_bottom + (x))) +#define DUK__REGP(x) (thr->valstack_bottom + (x)) +#define DUK__CONST(x) (*(consts + (x))) +#define DUK__CONSTP(x) (consts + (x)) /* Reg/const access macros which take the 32-bit instruction and avoid an * explicit field decoding step by using shifts and masks. These must be @@ -78653,68 +79950,74 @@ * instead of a duk_tval offset which needs further shifting (which is an * issue on some, but not all, CPUs). */ -#define DUK__RCBIT_B DUK_BC_REGCONST_B -#define DUK__RCBIT_C DUK_BC_REGCONST_C +#define DUK__RCBIT_B DUK_BC_REGCONST_B +#define DUK__RCBIT_C DUK_BC_REGCONST_C #if defined(DUK_USE_EXEC_REGCONST_OPTIMIZE) #if defined(DUK_USE_PACKED_TVAL) -#define DUK__TVAL_SHIFT 3 /* sizeof(duk_tval) == 8 */ +#define DUK__TVAL_SHIFT 3 /* sizeof(duk_tval) == 8 */ #else -#define DUK__TVAL_SHIFT 4 /* sizeof(duk_tval) == 16; not always the case so also asserted for */ +#define DUK__TVAL_SHIFT 4 /* sizeof(duk_tval) == 16; not always the case so also asserted for */ #endif -#define DUK__SHIFT_A (DUK_BC_SHIFT_A - DUK__TVAL_SHIFT) -#define DUK__SHIFT_B (DUK_BC_SHIFT_B - DUK__TVAL_SHIFT) -#define DUK__SHIFT_C (DUK_BC_SHIFT_C - DUK__TVAL_SHIFT) -#define DUK__SHIFT_BC (DUK_BC_SHIFT_BC - DUK__TVAL_SHIFT) -#define DUK__MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK__TVAL_SHIFT) -#define DUK__MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK__TVAL_SHIFT) -#define DUK__MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK__TVAL_SHIFT) -#define DUK__MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK__TVAL_SHIFT) -#define DUK__BYTEOFF_A(ins) (((ins) >> DUK__SHIFT_A) & DUK__MASK_A) -#define DUK__BYTEOFF_B(ins) (((ins) >> DUK__SHIFT_B) & DUK__MASK_B) -#define DUK__BYTEOFF_C(ins) (((ins) >> DUK__SHIFT_C) & DUK__MASK_C) -#define DUK__BYTEOFF_BC(ins) (((ins) >> DUK__SHIFT_BC) & DUK__MASK_BC) - -#define DUK__REGP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_A((ins)))) -#define DUK__REGP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_B((ins)))) -#define DUK__REGP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_C((ins)))) -#define DUK__REGP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_BC((ins)))) -#define DUK__CONSTP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_A((ins)))) -#define DUK__CONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_B((ins)))) -#define DUK__CONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_C((ins)))) -#define DUK__CONSTP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_BC((ins)))) -#define DUK__REGCONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) & DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_B((ins)))) -#define DUK__REGCONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) & DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_C((ins)))) -#else /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#define DUK__SHIFT_A (DUK_BC_SHIFT_A - DUK__TVAL_SHIFT) +#define DUK__SHIFT_B (DUK_BC_SHIFT_B - DUK__TVAL_SHIFT) +#define DUK__SHIFT_C (DUK_BC_SHIFT_C - DUK__TVAL_SHIFT) +#define DUK__SHIFT_BC (DUK_BC_SHIFT_BC - DUK__TVAL_SHIFT) +#define DUK__MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK__TVAL_SHIFT) +#define DUK__MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK__TVAL_SHIFT) +#define DUK__MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK__TVAL_SHIFT) +#define DUK__MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK__TVAL_SHIFT) +#define DUK__BYTEOFF_A(ins) (((ins) >> DUK__SHIFT_A) & DUK__MASK_A) +#define DUK__BYTEOFF_B(ins) (((ins) >> DUK__SHIFT_B) & DUK__MASK_B) +#define DUK__BYTEOFF_C(ins) (((ins) >> DUK__SHIFT_C) & DUK__MASK_C) +#define DUK__BYTEOFF_BC(ins) (((ins) >> DUK__SHIFT_BC) & DUK__MASK_BC) + +#define DUK__REGP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_A((ins)))) +#define DUK__REGP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_B((ins)))) +#define DUK__REGP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_C((ins)))) +#define DUK__REGP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_BC((ins)))) +#define DUK__CONSTP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_A((ins)))) +#define DUK__CONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_B((ins)))) +#define DUK__CONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_C((ins)))) +#define DUK__CONSTP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_BC((ins)))) +#define DUK__REGCONSTP_B(ins) \ + ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) &DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_B((ins)))) +#define DUK__REGCONSTP_C(ins) \ + ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) &DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_C((ins)))) +#else /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ /* Safe alternatives, no assumption about duk_tval size. */ -#define DUK__REGP_A(ins) DUK__REGP(DUK_DEC_A((ins))) -#define DUK__REGP_B(ins) DUK__REGP(DUK_DEC_B((ins))) -#define DUK__REGP_C(ins) DUK__REGP(DUK_DEC_C((ins))) -#define DUK__REGP_BC(ins) DUK__REGP(DUK_DEC_BC((ins))) -#define DUK__CONSTP_A(ins) DUK__CONSTP(DUK_DEC_A((ins))) -#define DUK__CONSTP_B(ins) DUK__CONSTP(DUK_DEC_B((ins))) -#define DUK__CONSTP_C(ins) DUK__CONSTP(DUK_DEC_C((ins))) -#define DUK__CONSTP_BC(ins) DUK__CONSTP(DUK_DEC_BC((ins))) -#define DUK__REGCONSTP_B(ins) ((((ins) & DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK_DEC_B((ins))) -#define DUK__REGCONSTP_C(ins) ((((ins) & DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK_DEC_C((ins))) -#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#define DUK__REGP_A(ins) DUK__REGP(DUK_DEC_A((ins))) +#define DUK__REGP_B(ins) DUK__REGP(DUK_DEC_B((ins))) +#define DUK__REGP_C(ins) DUK__REGP(DUK_DEC_C((ins))) +#define DUK__REGP_BC(ins) DUK__REGP(DUK_DEC_BC((ins))) +#define DUK__CONSTP_A(ins) DUK__CONSTP(DUK_DEC_A((ins))) +#define DUK__CONSTP_B(ins) DUK__CONSTP(DUK_DEC_B((ins))) +#define DUK__CONSTP_C(ins) DUK__CONSTP(DUK_DEC_C((ins))) +#define DUK__CONSTP_BC(ins) DUK__CONSTP(DUK_DEC_BC((ins))) +#define DUK__REGCONSTP_B(ins) ((((ins) &DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK_DEC_B((ins))) +#define DUK__REGCONSTP_C(ins) ((((ins) &DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK_DEC_C((ins))) +#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ #if defined(DUK_USE_VERBOSE_EXECUTOR_ERRORS) -#define DUK__INTERNAL_ERROR(msg) do { \ +#define DUK__INTERNAL_ERROR(msg) \ + do { \ DUK_ERROR_ERROR(thr, (msg)); \ DUK_WO_NORETURN(return;); \ } while (0) #else -#define DUK__INTERNAL_ERROR(msg) do { \ +#define DUK__INTERNAL_ERROR(msg) \ + do { \ goto internal_error; \ } while (0) #endif -#define DUK__SYNC_CURR_PC() do { \ +#define DUK__SYNC_CURR_PC() \ + do { \ duk_activation *duk__act; \ duk__act = thr->callstack_curr; \ duk__act->curr_pc = curr_pc; \ } while (0) -#define DUK__SYNC_AND_NULL_CURR_PC() do { \ +#define DUK__SYNC_AND_NULL_CURR_PC() \ + do { \ duk_activation *duk__act; \ duk__act = thr->callstack_curr; \ duk__act->curr_pc = curr_pc; \ @@ -78722,19 +80025,22 @@ } while (0) #if defined(DUK_USE_EXEC_PREFER_SIZE) -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ (idx) = (duk_uint_fast_t) duk_get_uint(thr, (duk_idx_t) (idx)); \ } while (0) #elif defined(DUK_USE_FASTINT) -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ duk_tval *tv_ind; \ tv_ind = DUK__REGP((idx)); \ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_ind)); \ - DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_ind)); /* compiler guarantees */ \ + DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_ind)); /* compiler guarantees */ \ (idx) = (duk_uint_fast_t) DUK_TVAL_GET_FASTINT_U32(tv_ind); \ } while (0) #else -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ duk_tval *tv_ind; \ tv_ind = DUK__REGP(idx); \ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_ind)); \ @@ -78787,8 +80093,8 @@ * will be re-bumped by the longjmp. */ - DUK_ASSERT(lj_ret == DUK__LONGJMP_RETHROW); /* Rethrow error to calling state. */ - DUK_ASSERT(heap->lj.jmpbuf_ptr == entry_jmpbuf_ptr); /* Longjmp handling has restored jmpbuf_ptr. */ + DUK_ASSERT(lj_ret == DUK__LONGJMP_RETHROW); /* Rethrow error to calling state. */ + DUK_ASSERT(heap->lj.jmpbuf_ptr == entry_jmpbuf_ptr); /* Longjmp handling has restored jmpbuf_ptr. */ /* Thread may have changed, e.g. YIELD converted to THROW. */ duk_err_longjmp(heap->curr_thread); @@ -78811,7 +80117,7 @@ DUK_ASSERT(exec_thr->heap != NULL); DUK_ASSERT(exec_thr->heap->curr_thread != NULL); DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR((duk_heaphdr *) exec_thr); - DUK_ASSERT(exec_thr->callstack_top >= 1); /* at least one activation, ours */ + DUK_ASSERT(exec_thr->callstack_top >= 1); /* at least one activation, ours */ DUK_ASSERT(exec_thr->callstack_curr != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(exec_thr->callstack_curr) != NULL); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(exec_thr->callstack_curr))); @@ -78877,7 +80183,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } #if defined(DUK_USE_CPP_EXCEPTIONS) catch (duk_fatal_exception &exc) { @@ -78893,7 +80199,10 @@ DUK_STATS_INC(exec_thr->heap, stats_exec_throw); try { DUK_ASSERT(heap->curr_thread != NULL); - DUK_ERROR_FMT1(heap->curr_thread, DUK_ERR_TYPE_ERROR, "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", what); + DUK_ERROR_FMT1(heap->curr_thread, + DUK_ERR_TYPE_ERROR, + "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", + what); DUK_WO_NORETURN(return;); } catch (duk_internal_exception exc) { DUK_D(DUK_DPRINT("caught api error thrown from unexpected c++ std::exception")); @@ -78902,7 +80211,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } } catch (...) { DUK_D(DUK_DPRINT("unexpected c++ exception (perhaps thrown by user code)")); @@ -78918,7 +80227,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } } #endif @@ -78934,13 +80243,13 @@ * but that eliminates performance benefits; aliasing guarantees * should be enough though. */ - duk_instr_t *curr_pc; /* bytecode has a stable pointer */ + duk_instr_t *curr_pc; /* bytecode has a stable pointer */ /* Hot variables for interpretation. Critical for performance, * but must add sparingly to minimize register shuffling. */ - duk_hthread *thr; /* stable */ - duk_tval *consts; /* stable */ + duk_hthread *thr; /* stable */ + duk_tval *consts; /* stable */ duk_uint_fast32_t ins; /* 'funcs' is quite rarely used, so no local for it */ #if defined(DUK_USE_EXEC_FUN_LOCAL) @@ -78954,7 +80263,7 @@ #endif #if defined(DUK_USE_ASSERTIONS) - duk_size_t valstack_top_base; /* valstack top, should match before interpreting each op (no leftovers) */ + duk_size_t valstack_top_base; /* valstack top, should match before interpreting each op (no leftovers) */ #endif /* Optimized reg/const access macros assume sizeof(duk_tval) to be @@ -79010,7 +80319,7 @@ * See execution.rst for discussion. */ - restart_execution: +restart_execution: /* Lookup current thread; use the stable 'entry_thread' for this to * avoid clobber warnings. Any valid, reachable 'thr' value would be @@ -79051,7 +80360,7 @@ DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) valstack_top_base = (duk_size_t) (thr->valstack_top - thr->valstack); @@ -79115,7 +80424,7 @@ */ #if defined(DUK_USE_DEBUGGER_SUPPORT) if (thr->heap->dbg_force_restart) { - DUK_DD(DUK_DDPRINT("dbg_force_restart flag forced restart execution")); /* GH-303 */ + DUK_DD(DUK_DDPRINT("dbg_force_restart flag forced restart execution")); /* GH-303 */ thr->heap->dbg_force_restart = 0; goto restart_execution; } @@ -79127,7 +80436,7 @@ goto restart_execution; } } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ #if defined(DUK_USE_INTERRUPT_COUNTER) && defined(DUK_USE_DEBUG) /* For cross-checking during development: ensure dispatch count * matches cumulative interrupt counter init value sums. @@ -79141,16 +80450,17 @@ act = thr->callstack_curr; DUK_ASSERT(curr_pc >= DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())); DUK_ASSERT(curr_pc < DUK_HCOMPFUNC_GET_CODE_END(thr->heap, DUK__FUN())); - DUK_UNREF(act); /* if debugging disabled */ + DUK_UNREF(act); /* if debugging disabled */ - DUK_DDD(DUK_DDDPRINT("executing bytecode: pc=%ld, ins=0x%08lx, op=%ld, valstack_top=%ld/%ld, nregs=%ld --> %!I", - (long) (curr_pc - DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())), - (unsigned long) *curr_pc, - (long) DUK_DEC_OP(*curr_pc), - (long) (thr->valstack_top - thr->valstack), - (long) (thr->valstack_end - thr->valstack), - (long) (DUK__FUN() ? DUK__FUN()->nregs : -1), - (duk_instr_t) *curr_pc)); + DUK_DDD(DUK_DDDPRINT( + "executing bytecode: pc=%ld, ins=0x%08lx, op=%ld, valstack_top=%ld/%ld, nregs=%ld --> %!I", + (long) (curr_pc - DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())), + (unsigned long) *curr_pc, + (long) DUK_DEC_OP(*curr_pc), + (long) (thr->valstack_top - thr->valstack), + (long) (thr->valstack_end - thr->valstack), + (long) (DUK__FUN() ? DUK__FUN()->nregs : -1), + (duk_instr_t) *curr_pc)); } #endif @@ -79187,14 +80497,16 @@ */ op = (duk_uint8_t) DUK_DEC_OP(ins); switch (op) { - - /* Some useful macros. These access inner executor variables - * directly so they only apply within the executor. - */ + /* Some useful macros. These access inner executor variables + * directly so they only apply within the executor. + */ #if defined(DUK_USE_EXEC_PREFER_SIZE) -#define DUK__REPLACE_TOP_A_BREAK() { goto replace_top_a; } -#define DUK__REPLACE_TOP_BC_BREAK() { goto replace_top_bc; } -#define DUK__REPLACE_BOOL_A_BREAK(bval) { \ +#define DUK__REPLACE_TOP_A_BREAK() \ + { goto replace_top_a; } +#define DUK__REPLACE_TOP_BC_BREAK() \ + { goto replace_top_bc; } +#define DUK__REPLACE_BOOL_A_BREAK(bval) \ + { \ duk_bool_t duk__bval; \ duk__bval = (bval); \ DUK_ASSERT(duk__bval == 0 || duk__bval == 1); \ @@ -79202,9 +80514,18 @@ DUK__REPLACE_TOP_A_BREAK(); \ } #else -#define DUK__REPLACE_TOP_A_BREAK() { DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); break; } -#define DUK__REPLACE_TOP_BC_BREAK() { DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); break; } -#define DUK__REPLACE_BOOL_A_BREAK(bval) { \ +#define DUK__REPLACE_TOP_A_BREAK() \ + { \ + DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); \ + break; \ + } +#define DUK__REPLACE_TOP_BC_BREAK() \ + { \ + DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); \ + break; \ + } +#define DUK__REPLACE_BOOL_A_BREAK(bval) \ + { \ duk_bool_t duk__bval; \ duk_tval *duk__tvdst; \ duk__bval = (bval); \ @@ -79228,7 +80549,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__REGP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } @@ -79237,7 +80558,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__REGP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv2, tv1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv2, tv1); /* side effects */ break; } @@ -79246,7 +80567,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__CONSTP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } @@ -79266,18 +80587,18 @@ duk_int32_t val; val = (duk_int32_t) duk_get_int(thr, DUK_DEC_A(ins)); - val = (val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ + val = (val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ duk_push_int(thr, val); DUK__REPLACE_TOP_A_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LDINT: { duk_tval *tv1; duk_int32_t val; val = (duk_int32_t) DUK_DEC_BC(ins) - (duk_int32_t) DUK_BC_LDINT_BIAS; tv1 = DUK__REGP_A(ins); - DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ break; } case DUK_OP_LDINTX: { @@ -79293,11 +80614,12 @@ /* XXX: fast double-to-int conversion, we know number is integer in -0x80000000,0xffffffff. */ val = (duk_int32_t) DUK_TVAL_GET_NUMBER(tv1); #endif - val = (duk_int32_t) ((duk_uint32_t) val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ - DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ + val = + (duk_int32_t) ((duk_uint32_t) val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ + DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_LDTHIS: { @@ -79320,46 +80642,46 @@ duk_push_false(thr); DUK__REPLACE_TOP_BC_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LDTHIS: { /* Note: 'this' may be bound to any value, not just an object */ duk_tval *tv1, *tv2; tv1 = DUK__REGP_BC(ins); - tv2 = thr->valstack_bottom - 1; /* 'this binding' is just under bottom */ + tv2 = thr->valstack_bottom - 1; /* 'this binding' is just under bottom */ DUK_ASSERT(tv2 >= thr->valstack); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } case DUK_OP_LDUNDEF: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ break; } case DUK_OP_LDNULL: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_NULL_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_NULL_UPDREF(thr, tv1); /* side effects */ break; } case DUK_OP_LDTRUE: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 1); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 1); /* side effects */ break; } case DUK_OP_LDFALSE: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 0); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 0); /* side effects */ break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_BNOT: { duk__vm_bitwise_not(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins)); @@ -79377,7 +80699,7 @@ duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_UNM: { duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), DUK_OP_UNM); break; @@ -79386,7 +80708,7 @@ duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), DUK_OP_UNP); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_TYPEOF: { @@ -79397,7 +80719,7 @@ duk_push_hstring_stridx(thr, stridx); DUK__REPLACE_TOP_A_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_TYPEOF: { duk_tval *tv; duk_small_uint_t stridx; @@ -79411,7 +80733,7 @@ DUK_TVAL_SET_STRING_UPDREF(thr, tv, h_str); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_TYPEOFID: { duk_small_uint_t stridx; @@ -79429,13 +80751,13 @@ tv = DUK__CONSTP_BC(ins); DUK_ASSERT(DUK_TVAL_IS_STRING(tv)); name = DUK_TVAL_GET_STRING(tv); - tv = NULL; /* lookup has side effects */ + tv = NULL; /* lookup has side effects */ act = thr->callstack_curr; if (duk_js_getvar_activation(thr, act, name, 0 /*throw*/)) { /* -> ... val this */ tv = DUK_GET_TVAL_NEGIDX(thr, -2); stridx = duk_js_typeof_stridx(tv); - tv = NULL; /* no longer needed */ + tv = NULL; /* no longer needed */ duk_pop_2_unsafe(thr); } else { /* unresolvable, no stack changes */ @@ -79445,36 +80767,40 @@ #if defined(DUK_USE_EXEC_PREFER_SIZE) duk_push_hstring_stridx(thr, stridx); DUK__REPLACE_TOP_A_BREAK(); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ h_str = DUK_HTHREAD_GET_STRING(thr, stridx); tv = DUK__REGP_A(ins); DUK_TVAL_SET_STRING_UPDREF(thr, tv, h_str); break; -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } /* Equality: E5 Sections 11.9.1, 11.9.3 */ -#define DUK__EQ_BODY(barg,carg) { \ +#define DUK__EQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_equals(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__NEQ_BODY(barg,carg) { \ +#define DUK__NEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_equals(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ tmp ^= 1; \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__SEQ_BODY(barg,carg) { \ +#define DUK__SEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_strict_equals((barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__SNEQ_BODY(barg,carg) { \ +#define DUK__SNEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_strict_equals((barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ @@ -79502,7 +80828,7 @@ case DUK_OP_SNEQ_RC: case DUK_OP_SNEQ_CC: DUK__SNEQ_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_EQ_RR: DUK__EQ_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_EQ_CR: @@ -79535,18 +80861,19 @@ DUK__SNEQ_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_SNEQ_CC: DUK__SNEQ_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ -#define DUK__COMPARE_BODY(arg1,arg2,flags) { \ +#define DUK__COMPARE_BODY(arg1, arg2, flags) \ + { \ duk_bool_t tmp; \ tmp = duk_js_compare_helper(thr, (arg1), (arg2), (flags)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__GT_BODY(barg,carg) DUK__COMPARE_BODY((carg), (barg), 0) -#define DUK__GE_BODY(barg,carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) -#define DUK__LT_BODY(barg,carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) -#define DUK__LE_BODY(barg,carg) DUK__COMPARE_BODY((carg), (barg), DUK_COMPARE_FLAG_NEGATE) +#define DUK__GT_BODY(barg, carg) DUK__COMPARE_BODY((carg), (barg), 0) +#define DUK__GE_BODY(barg, carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) +#define DUK__LT_BODY(barg, carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) +#define DUK__LE_BODY(barg, carg) DUK__COMPARE_BODY((carg), (barg), DUK_COMPARE_FLAG_NEGATE) #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_GT_RR: case DUK_OP_GT_CR: @@ -79568,7 +80895,7 @@ case DUK_OP_LE_RC: case DUK_OP_LE_CC: DUK__LE_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_GT_RR: DUK__GT_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_GT_CR: @@ -79601,7 +80928,7 @@ DUK__LE_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_LE_CC: DUK__LE_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* No size optimized variant at present for IF. */ case DUK_OP_IFTRUE_R: { @@ -79638,7 +80965,7 @@ duk__vm_arith_add(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins)); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_ADD_RR: { duk__vm_arith_add(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins)); break; @@ -79655,7 +80982,7 @@ duk__vm_arith_add(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins)); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_SUB_RR: @@ -79679,13 +81006,13 @@ case DUK_OP_EXP_CR: case DUK_OP_EXP_RC: case DUK_OP_EXP_CC: -#endif /* DUK_USE_ES7_EXP_OPERATOR */ +#endif /* DUK_USE_ES7_EXP_OPERATOR */ { /* XXX: could leave value on stack top and goto replace_top_a; */ duk__vm_arith_binary_op(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_SUB_RR: { duk__vm_arith_binary_op(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins), DUK_OP_SUB); break; @@ -79767,8 +81094,8 @@ duk__vm_arith_binary_op(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins), DUK_OP_EXP); break; } -#endif /* DUK_USE_ES7_EXP_OPERATOR */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_ES7_EXP_OPERATOR */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_BAND_RR: @@ -79799,7 +81126,7 @@ duk__vm_bitwise_binary_op(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_BAND_RR: { duk__vm_bitwise_binary_op(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins), DUK_OP_BAND); break; @@ -79896,16 +81223,18 @@ duk__vm_bitwise_binary_op(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins), DUK_OP_BASR); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* For INSTOF and IN, B is always a register. */ -#define DUK__INSTOF_BODY(barg,carg) { \ +#define DUK__INSTOF_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_instanceof(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__IN_BODY(barg,carg) { \ +#define DUK__IN_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_in(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ @@ -79922,7 +81251,7 @@ case DUK_OP_IN_RC: case DUK_OP_IN_CC: DUK__IN_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_INSTOF_RR: DUK__INSTOF_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_INSTOF_CR: @@ -79939,9 +81268,9 @@ DUK__IN_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_IN_CC: DUK__IN_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ - /* Pre/post inc/dec for register variables, important for loops. */ + /* Pre/post inc/dec for register variables, important for loops. */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_PREINCR: case DUK_OP_PREDECR: @@ -79957,7 +81286,7 @@ duk__prepost_incdec_var_helper(thr, DUK_DEC_A(ins), DUK__CONSTP_BC(ins), op, DUK__STRICT()); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_PREINCR: { duk__prepost_incdec_reg_helper(thr, DUK__REGP_A(ins), DUK__REGP_BC(ins), DUK_OP_PREINCR); break; @@ -79990,7 +81319,7 @@ duk__prepost_incdec_var_helper(thr, DUK_DEC_A(ins), DUK__CONSTP_BC(ins), DUK_OP_POSTDECV, DUK__STRICT()); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* XXX: Move to separate helper, optimize for perf/size separately. */ /* Preinc/predec for object properties. */ @@ -80017,7 +81346,7 @@ duk_double_t x, y, z; #if !defined(DUK_USE_EXEC_PREFER_SIZE) duk_tval *tv_dst; -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* A -> target reg * B -> object reg/const (may be const e.g. in "'foo'1") @@ -80035,10 +81364,10 @@ tv_obj = DUK__REGCONSTP_B(ins); tv_key = DUK__REGCONSTP_C(ins); - rc = duk_hobject_getprop(thr, tv_obj, tv_key); /* -> val */ - DUK_UNREF(rc); /* ignore */ - tv_obj = NULL; /* invalidated */ - tv_key = NULL; /* invalidated */ + rc = duk_hobject_getprop(thr, tv_obj, tv_key); /* -> val */ + DUK_UNREF(rc); /* ignore */ + tv_obj = NULL; /* invalidated */ + tv_key = NULL; /* invalidated */ /* XXX: Fastint fast path would be useful here. Also fastints * now lose their fastint status in current handling which is @@ -80059,9 +81388,9 @@ tv_obj = DUK__REGCONSTP_B(ins); tv_key = DUK__REGCONSTP_C(ins); rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, DUK__STRICT()); - DUK_UNREF(rc); /* ignore */ - tv_obj = NULL; /* invalidated */ - tv_key = NULL; /* invalidated */ + DUK_UNREF(rc); /* ignore */ + tv_obj = NULL; /* invalidated */ + tv_key = NULL; /* invalidated */ duk_pop_unsafe(thr); z = (ins & DUK_BC_INCDECP_FLAG_POST) ? x : y; @@ -80079,7 +81408,8 @@ * Occurs relatively often in object oriented code. */ -#define DUK__GETPROP_BODY(barg,carg) { \ +#define DUK__GETPROP_BODY(barg, carg) \ + { \ /* A -> target reg \ * B -> object reg/const (may be const e.g. in "'foo'1") \ * C -> key reg/const \ @@ -80087,7 +81417,8 @@ (void) duk_hobject_getprop(thr, (barg), (carg)); \ DUK__REPLACE_TOP_A_BREAK(); \ } -#define DUK__GETPROPC_BODY(barg,carg) { \ +#define DUK__GETPROPC_BODY(barg, carg) \ + { \ /* Same as GETPROP but callability check for property-based calls. */ \ duk_tval *tv__targ; \ (void) duk_hobject_getprop(thr, (barg), (carg)); \ @@ -80102,7 +81433,8 @@ } \ DUK__REPLACE_TOP_A_BREAK(); \ } -#define DUK__PUTPROP_BODY(aarg,barg,carg) { \ +#define DUK__PUTPROP_BODY(aarg, barg, carg) \ + { \ /* A -> object reg \ * B -> key reg/const \ * C -> value reg/const \ @@ -80113,7 +81445,8 @@ (void) duk_hobject_putprop(thr, (aarg), (barg), (carg), DUK__STRICT()); \ break; \ } -#define DUK__DELPROP_BODY(barg,carg) { \ +#define DUK__DELPROP_BODY(barg, carg) \ + { \ /* A -> result reg \ * B -> object reg \ * C -> key reg/const \ @@ -80142,9 +81475,9 @@ case DUK_OP_PUTPROP_CC: DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); case DUK_OP_DELPROP_RR: - case DUK_OP_DELPROP_RC: /* B is always reg */ + case DUK_OP_DELPROP_RC: /* B is always reg */ DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_GETPROP_RR: DUK__GETPROP_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_GETPROP_CR: @@ -80171,11 +81504,11 @@ DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_PUTPROP_CC: DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); - case DUK_OP_DELPROP_RR: /* B is always reg */ + case DUK_OP_DELPROP_RR: /* B is always reg */ DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_DELPROP_RC: DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* No fast path for DECLVAR now, it's quite a rare instruction. */ case DUK_OP_DECLVAR_RR: @@ -80208,7 +81541,7 @@ if (is_func_decl) { duk_push_tval(thr, DUK__REGCONSTP_C(ins)); } else { - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } tv1 = DUK_GET_TVAL_NEGIDX(thr, -1); @@ -80244,11 +81577,11 @@ */ duk_push_tval(thr, DUK__REGCONSTP_C(ins)); - duk_push_tval(thr, DUK__REGCONSTP_B(ins)); /* -> ... escaped_source bytecode */ - duk_regexp_create_instance(thr); /* -> ... regexp_instance */ + duk_push_tval(thr, DUK__REGCONSTP_B(ins)); /* -> ... escaped_source bytecode */ + duk_regexp_create_instance(thr); /* -> ... regexp_instance */ DUK__REPLACE_TOP_A_BREAK(); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* XXX: 'c' is unused, use whole BC, etc. */ case DUK_OP_CSVAR_RR: @@ -80277,13 +81610,13 @@ name = DUK_TVAL_GET_STRING(tv1); DUK_ASSERT(name != NULL); act = thr->callstack_curr; - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ idx = (duk_uint_fast_t) DUK_DEC_A(ins); /* Could add direct value stack handling. */ - duk_replace(thr, (duk_idx_t) (idx + 1)); /* 'this' binding */ - duk_replace(thr, (duk_idx_t) idx); /* variable value (function, we hope, not checked here) */ + duk_replace(thr, (duk_idx_t) (idx + 1)); /* 'this' binding */ + duk_replace(thr, (duk_idx_t) idx); /* variable value (function, we hope, not checked here) */ break; } @@ -80298,7 +81631,9 @@ */ DUK_DDD(DUK_DDDPRINT("CLOSURE to target register %ld, fnum %ld (count %ld)", - (long) DUK_DEC_A(ins), (long) DUK_DEC_BC(ins), (long) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN()))); + (long) DUK_DEC_A(ins), + (long) DUK_DEC_BC(ins), + (long) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN()))); DUK_ASSERT_DISABLE(bc >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) bc < (duk_uint_t) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN())); @@ -80309,8 +81644,8 @@ DUK_ASSERT(fun_temp != NULL); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(fun_temp)); - DUK_DDD(DUK_DDDPRINT("CLOSURE: function template is: %p -> %!O", - (void *) fun_temp, (duk_heaphdr *) fun_temp)); + DUK_DDD( + DUK_DDDPRINT("CLOSURE: function template is: %p -> %!O", (void *) fun_temp, (duk_heaphdr *) fun_temp)); if (act->lex_env == NULL) { DUK_ASSERT(act->var_env == NULL); @@ -80324,11 +81659,7 @@ * new variable declaration environment, so only lex_env * matters here. */ - duk_js_push_closure(thr, - (duk_hcompfunc *) fun_temp, - act->var_env, - act->lex_env, - 1 /*add_auto_proto*/); + duk_js_push_closure(thr, (duk_hcompfunc *) fun_temp, act->var_env, act->lex_env, 1 /*add_auto_proto*/); DUK__REPLACE_TOP_A_BREAK(); } @@ -80343,8 +81674,8 @@ DUK_ASSERT(name != NULL); act = thr->callstack_curr; DUK_ASSERT(act != NULL); - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ - duk_pop_unsafe(thr); /* 'this' binding is not needed here */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + duk_pop_unsafe(thr); /* 'this' binding is not needed here */ DUK__REPLACE_TOP_A_BREAK(); } @@ -80362,7 +81693,7 @@ * should be reworked. */ - tv1 = DUK__REGP_A(ins); /* val */ + tv1 = DUK__REGP_A(ins); /* val */ act = thr->callstack_curr; duk_js_putvar_activation(thr, act, name, tv1, DUK__STRICT()); break; @@ -80392,7 +81723,8 @@ break; } -#define DUK__RETURN_SHARED() do { \ +#define DUK__RETURN_SHARED() \ + do { \ duk_small_uint_t ret_result; \ /* duk__handle_return() is guaranteed never to throw, except \ * for potential out-of-memory situations which will then \ @@ -80411,14 +81743,14 @@ case DUK_OP_RETCONST: case DUK_OP_RETCONSTN: case DUK_OP_RETUNDEF: { - /* BC -> return value reg/const */ + /* BC -> return value reg/const */ DUK__SYNC_AND_NULL_CURR_PC(); if (op == DUK_OP_RETREG) { duk_push_tval(thr, DUK__REGP_BC(ins)); } else if (op == DUK_OP_RETUNDEF) { - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } else { DUK_ASSERT(op == DUK_OP_RETCONST || op == DUK_OP_RETCONSTN); @@ -80427,7 +81759,7 @@ DUK__RETURN_SHARED(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_RETREG: { duk_tval *tv; @@ -80457,18 +81789,18 @@ DUK_TVAL_SET_TVAL(thr->valstack_top, tv); #if defined(DUK_USE_REFERENCE_COUNTING) /* Without refcounting only RETCONSTN is used. */ - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv)); /* no INCREF for this constant */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv)); /* no INCREF for this constant */ #endif thr->valstack_top++; DUK__RETURN_SHARED(); } case DUK_OP_RETUNDEF: { DUK__SYNC_AND_NULL_CURR_PC(); - thr->valstack_top++; /* value at valstack top is already undefined by valstack policy */ + thr->valstack_top++; /* value at valstack top is already undefined by valstack policy */ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); DUK__RETURN_SHARED(); } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LABEL: { duk_activation *act; @@ -80481,8 +81813,8 @@ DUK_ASSERT(cat != NULL); cat->flags = (duk_uint32_t) (DUK_CAT_TYPE_LABEL | (bc << DUK_CAT_LABEL_SHIFT)); - cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ - cat->idx_base = 0; /* unused for label */ + cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ + cat->idx_base = 0; /* unused for label */ cat->h_varname = NULL; act = thr->callstack_curr; @@ -80492,10 +81824,13 @@ DUK_DDD(DUK_DDDPRINT("LABEL catcher: flags=0x%08lx, pc_base=%ld, " "idx_base=%ld, h_varname=%!O, label_id=%ld", - (long) cat->flags, (long) cat->pc_base, - (long) cat->idx_base, (duk_heaphdr *) cat->h_varname, (long) DUK_CAT_GET_LABEL(cat))); + (long) cat->flags, + (long) cat->pc_base, + (long) cat->idx_base, + (duk_heaphdr *) cat->h_varname, + (long) DUK_CAT_GET_LABEL(cat))); - curr_pc += 2; /* skip jump slots */ + curr_pc += 2; /* skip jump slots */ break; } @@ -80537,7 +81872,7 @@ /* XXX: move to helper, too large to be inline here */ case DUK_OP_TRYCATCH: { duk__handle_op_trycatch(thr, ins, curr_pc); - curr_pc += 2; /* skip jump slots */ + curr_pc += 2; /* skip jump slots */ break; } @@ -80582,8 +81917,8 @@ (duk_tval *) duk_get_tval(thr, -1))); #if defined(DUK_USE_AUGMENT_ERROR_THROW) duk_err_augment_error_throw(thr); - DUK_DDD(DUK_DDDPRINT("THROW ERROR (BYTECODE): %!dT (after throw augment)", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD( + DUK_DDDPRINT("THROW ERROR (BYTECODE): %!dT (after throw augment)", (duk_tval *) duk_get_tval(thr, -1))); #endif duk_err_setup_ljstate1(thr, DUK_LJ_TYPE_THROW, DUK_GET_TVAL_NEGIDX(thr, -1)); @@ -80591,7 +81926,7 @@ duk_err_check_debugger_integration(thr); #endif - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ duk_err_longjmp(thr); DUK_UNREACHABLE(); break; @@ -80628,20 +81963,19 @@ DUK_TVAL_SET_TVAL(&tv_tmp2, tv2); tv3 = DUK__REGP(a); DUK_TVAL_SET_TVAL(tv1, tv3); - DUK_TVAL_INCREF(thr, tv1); /* no side effects */ - DUK_TVAL_SET_UNDEFINED(tv2); /* no need for incref */ + DUK_TVAL_INCREF(thr, tv1); /* no side effects */ + DUK_TVAL_SET_UNDEFINED(tv2); /* no need for incref */ DUK_TVAL_DECREF(thr, &tv_tmp1); DUK_TVAL_DECREF(thr, &tv_tmp2); #endif break; } - - /* XXX: in some cases it's faster NOT to reuse the value - * stack but rather copy the arguments on top of the stack - * (mainly when the calling value stack is large and the value - * stack resize would be large). - */ + /* XXX: in some cases it's faster NOT to reuse the value + * stack but rather copy the arguments on top of the stack + * (mainly when the calling value stack is large and the value + * stack resize would be large). + */ case DUK_OP_CALL0: case DUK_OP_CALL1: @@ -80802,7 +82136,7 @@ } count = (duk_small_uint_fast_t) DUK_DEC_C(ins); - DUK_ASSERT(count > 0); /* compiler guarantees */ + DUK_ASSERT(count > 0); /* compiler guarantees */ idx_end = idx + count; #if defined(DUK_USE_EXEC_INDIRECT_BOUND_CHECK) @@ -80826,11 +82160,10 @@ /* XXX: faster initialization (direct access or better primitives) */ duk_dup(thr, (duk_idx_t) idx); duk_dup(thr, (duk_idx_t) (idx + 1)); - duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_WRITABLE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE); + duk_def_prop(thr, + obj_idx, + DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_WRITABLE | + DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE); idx += 2; } while (idx < idx_end); break; @@ -80865,7 +82198,7 @@ } count = (duk_small_uint_fast_t) DUK_DEC_C(ins); - DUK_ASSERT(count > 0 + 1); /* compiler guarantees */ + DUK_ASSERT(count > 0 + 1); /* compiler guarantees */ idx_end = idx + count; #if defined(DUK_USE_EXEC_INDIRECT_BOUND_CHECK) @@ -80992,7 +82325,7 @@ duk_push_new_target(thr); DUK__REPLACE_TOP_BC_BREAK(); } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if !defined(DUK_USE_EXEC_PREFER_SIZE) #if !defined(DUK_USE_ES7_EXP_OPERATOR) @@ -81055,16 +82388,16 @@ case DUK_OP_UNUSED253: case DUK_OP_UNUSED254: case DUK_OP_UNUSED255: - /* Force all case clauses to map to an actual handler - * so that the compiler can emit a jump without a bounds - * check: the switch argument is a duk_uint8_t so that - * the compiler may be able to figure it out. This is - * a small detail and obviously compiler dependent. - */ - /* default: clause omitted on purpose */ -#else /* DUK_USE_EXEC_PREFER_SIZE */ + /* Force all case clauses to map to an actual handler + * so that the compiler can emit a jump without a bounds + * check: the switch argument is a duk_uint8_t so that + * the compiler may be able to figure it out. This is + * a small detail and obviously compiler dependent. + */ + /* default: clause omitted on purpose */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ default: -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ { /* Default case catches invalid/unsupported opcodes. */ DUK_D(DUK_DPRINT("invalid opcode: %ld - %!I", (long) op, ins)); @@ -81072,7 +82405,7 @@ break; } - } /* end switch */ + } /* end switch */ continue; @@ -81083,10 +82416,10 @@ */ #if defined(DUK_USE_EXEC_PREFER_SIZE) - replace_top_a: + replace_top_a: DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); continue; - replace_top_bc: + replace_top_bc: DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); continue; #endif @@ -81094,7 +82427,7 @@ DUK_WO_NORETURN(return;); #if !defined(DUK_USE_VERBOSE_EXECUTOR_ERRORS) - internal_error: +internal_error: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); #endif @@ -81325,19 +82658,10 @@ /* Quite lenient, e.g. allow empty as zero, but don't allow trailing * garbage. */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_INF | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO | - DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT | - DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT | - DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_PLUS | DUK_S2N_FLAG_ALLOW_MINUS | + DUK_S2N_FLAG_ALLOW_INF | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO | DUK_S2N_FLAG_ALLOW_LEADING_ZERO | + DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT | DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT | DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT; duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); @@ -81347,9 +82671,9 @@ #else thr->valstack_top--; DUK_ASSERT(DUK_TVAL_IS_NUMBER(thr->valstack_top)); - DUK_ASSERT(DUK_TVAL_IS_DOUBLE(thr->valstack_top)); /* no fastint conversion in numconv now */ + DUK_ASSERT(DUK_TVAL_IS_DOUBLE(thr->valstack_top)); /* no fastint conversion in numconv now */ DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(thr->valstack_top)); - d = DUK_TVAL_GET_DOUBLE(thr->valstack_top); /* assumes not a fastint */ + d = DUK_TVAL_GET_DOUBLE(thr->valstack_top); /* assumes not a fastint */ DUK_TVAL_SET_UNDEFINED(thr->valstack_top); #endif @@ -81388,11 +82712,11 @@ duk_push_hstring(thr, h); return duk__tonumber_string_raw(thr); } - case DUK_TAG_BUFFER: /* plain buffer treated like object */ + case DUK_TAG_BUFFER: /* plain buffer treated like object */ case DUK_TAG_OBJECT: { duk_double_t d; duk_push_tval(thr, tv); - duk_to_primitive(thr, -1, DUK_HINT_NUMBER); /* 'tv' becomes invalid */ + duk_to_primitive(thr, -1, DUK_HINT_NUMBER); /* 'tv' becomes invalid */ /* recursive call for a primitive value (guaranteed not to cause second * recursion). @@ -81447,7 +82771,7 @@ */ return duk_double_trunc_towards_zero(x); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* NaN and Infinity have the same exponent so it's a cheap * initial check for the rare path. */ @@ -81460,12 +82784,12 @@ } else { return duk_double_trunc_towards_zero(x); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } DUK_INTERNAL duk_double_t duk_js_tointeger(duk_hthread *thr, duk_tval *tv) { /* XXX: fastint */ - duk_double_t d = duk_js_tonumber(thr, tv); /* invalidates tv */ + duk_double_t d = duk_js_tonumber(thr, tv); /* invalidates tv */ return duk_js_tointeger_number(d); } @@ -81475,11 +82799,11 @@ /* combined algorithm matching E5 Sections 9.5 and 9.6 */ DUK_LOCAL duk_double_t duk__toint32_touint32_helper(duk_double_t x, duk_bool_t is_toint32) { -#if defined (DUK_USE_PREFER_SIZE) +#if defined(DUK_USE_PREFER_SIZE) duk_small_int_t c; #endif -#if defined (DUK_USE_PREFER_SIZE) +#if defined(DUK_USE_PREFER_SIZE) c = (duk_small_int_t) DUK_FPCLASSIFY(x); if (c == DUK_FP_NAN || c == DUK_FP_ZERO || c == DUK_FP_INFINITE) { return 0.0; @@ -81497,18 +82821,18 @@ * differs from what Javascript wants (see Section 9.6). */ - x = DUK_FMOD(x, DUK_DOUBLE_2TO32); /* -> x in -2**32, 2**32 */ + x = DUK_FMOD(x, DUK_DOUBLE_2TO32); /* -> x in -2**32, 2**32 */ if (x < 0.0) { x += DUK_DOUBLE_2TO32; } - DUK_ASSERT(x >= 0 && x < DUK_DOUBLE_2TO32); /* -> x in 0, 2**32 */ + DUK_ASSERT(x >= 0 && x < DUK_DOUBLE_2TO32); /* -> x in 0, 2**32 */ if (is_toint32) { if (x >= DUK_DOUBLE_2TO31) { /* x in 2**31, 2**32 */ - x -= DUK_DOUBLE_2TO32; /* -> x in -2**31,2**31 */ + x -= DUK_DOUBLE_2TO32; /* -> x in -2**31,2**31 */ } } @@ -81524,15 +82848,14 @@ } #endif - d = duk_js_tonumber(thr, tv); /* invalidates tv */ + d = duk_js_tonumber(thr, tv); /* invalidates tv */ d = duk__toint32_touint32_helper(d, 1); DUK_ASSERT(DUK_FPCLASSIFY(d) == DUK_FP_ZERO || DUK_FPCLASSIFY(d) == DUK_FP_NORMAL); - DUK_ASSERT(d >= -2147483648.0 && d <= 2147483647.0); /* -0x80000000,0x7fffffff */ - DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_int32_t) d))); /* whole, won't clip */ + DUK_ASSERT(d >= -2147483648.0 && d <= 2147483647.0); /* -0x80000000,0x7fffffff */ + DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_int32_t) d))); /* whole, won't clip */ return (duk_int32_t) d; } - DUK_INTERNAL duk_uint32_t duk_js_touint32(duk_hthread *thr, duk_tval *tv) { duk_double_t d; @@ -81542,13 +82865,12 @@ } #endif - d = duk_js_tonumber(thr, tv); /* invalidates tv */ + d = duk_js_tonumber(thr, tv); /* invalidates tv */ d = duk__toint32_touint32_helper(d, 0); DUK_ASSERT(DUK_FPCLASSIFY(d) == DUK_FP_ZERO || DUK_FPCLASSIFY(d) == DUK_FP_NORMAL); - DUK_ASSERT(d >= 0.0 && d <= 4294967295.0); /* 0x00000000, 0xffffffff */ - DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_uint32_t) d))); /* whole, won't clip */ + DUK_ASSERT(d >= 0.0 && d <= 4294967295.0); /* 0x00000000, 0xffffffff */ + DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_uint32_t) d))); /* whole, won't clip */ return (duk_uint32_t) d; - } DUK_INTERNAL duk_uint16_t duk_js_touint16(duk_hthread *thr, duk_tval *tv) { @@ -81598,7 +82920,7 @@ return 1; } return 0; -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ /* Better equivalent algorithm. If the compiler is compliant, C and * ECMAScript semantics are identical for this particular comparison. * In particular, NaNs must never compare equal and zeroes must compare @@ -81618,7 +82940,7 @@ DUK_ASSERT(!(DUK_FPCLASSIFY(x) == DUK_FP_ZERO && DUK_FPCLASSIFY(y) == DUK_FP_ZERO)); return 0; } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ } DUK_LOCAL duk_bool_t duk__js_samevalue_number(duk_double_t x, duk_double_t y) { @@ -81648,7 +82970,7 @@ */ return (x == y); -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ duk_small_int_t cx = (duk_small_int_t) DUK_FPCLASSIFY(x); duk_small_int_t cy = (duk_small_int_t) DUK_FPCLASSIFY(y); @@ -81683,7 +83005,7 @@ } return 0; } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ } DUK_INTERNAL duk_bool_t duk_js_equals_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags) { @@ -81709,10 +83031,9 @@ } else { return 0; } - } - else + } else #endif - if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { + if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { duk_double_t d1, d2; /* Catches both doubles and cases where only one argument is @@ -81786,7 +83107,7 @@ return 0; } - DUK_ASSERT(flags == 0); /* non-strict equality from here on */ + DUK_ASSERT(flags == 0); /* non-strict equality from here on */ /* * Types are different; various cases for non-strict comparison @@ -81843,34 +83164,29 @@ } /* String-number-symbol/object -> coerce object to primitive (apparently without hint), then try again. */ - if ((type_mask_x & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER)) && - (type_mask_y & DUK_TYPE_MASK_OBJECT)) { + if ((type_mask_x & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER)) && (type_mask_y & DUK_TYPE_MASK_OBJECT)) { /* No symbol check needed because symbols and strings are accepted. */ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -1, DUK_HINT_NONE); /* apparently no hint? */ + duk_to_primitive(thr, -1, DUK_HINT_NONE); /* apparently no hint? */ goto recursive_call; } - if ((type_mask_x & DUK_TYPE_MASK_OBJECT) && - (type_mask_y & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER))) { + if ((type_mask_x & DUK_TYPE_MASK_OBJECT) && (type_mask_y & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER))) { /* No symbol check needed because symbols and strings are accepted. */ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -2, DUK_HINT_NONE); /* apparently no hint? */ + duk_to_primitive(thr, -2, DUK_HINT_NONE); /* apparently no hint? */ goto recursive_call; } /* Nothing worked -> not equal. */ return 0; - recursive_call: +recursive_call: /* Shared code path to call the helper again with arguments on stack top. */ { duk_bool_t rc; - rc = duk_js_equals_helper(thr, - DUK_GET_TVAL_NEGIDX(thr, -2), - DUK_GET_TVAL_NEGIDX(thr, -1), - 0 /*flags:nonstrict*/); + rc = duk_js_equals_helper(thr, DUK_GET_TVAL_NEGIDX(thr, -2), DUK_GET_TVAL_NEGIDX(thr, -1), 0 /*flags:nonstrict*/); duk_pop_2_unsafe(thr); return rc; } @@ -81887,7 +83203,10 @@ * needs to push stuff on the stack anyway... */ -DUK_INTERNAL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, const duk_uint8_t *buf2, duk_size_t len1, duk_size_t len2) { +DUK_INTERNAL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, + const duk_uint8_t *buf2, + duk_size_t len1, + duk_size_t len2) { duk_size_t prefix_len; duk_small_int_t rc; @@ -81896,9 +83215,7 @@ /* duk_memcmp() is guaranteed to return zero (equal) for zero length * inputs. */ - rc = duk_memcmp_unsafe((const void *) buf1, - (const void *) buf2, - (size_t) prefix_len); + rc = duk_memcmp_unsafe((const void *) buf1, (const void *) buf2, (size_t) prefix_len); if (rc < 0) { return -1; @@ -81940,7 +83257,7 @@ (duk_size_t) DUK_HSTRING_GET_BYTELEN(h2)); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL duk_small_int_t duk_js_buffer_compare(duk_heap *heap, duk_hbuffer *h1, duk_hbuffer *h2) { /* Similar to String comparison. */ @@ -81977,47 +83294,47 @@ s2 = (duk_small_int_t) DUK_SIGNBIT(d2); if (c1 == DUK_FP_NAN || c2 == DUK_FP_NAN) { - return 0; /* Always false, regardless of negation. */ + return 0; /* Always false, regardless of negation. */ } if (c1 == DUK_FP_ZERO && c2 == DUK_FP_ZERO) { /* For all combinations: +0 < +0, +0 < -0, -0 < +0, -0 < -0, * steps e, f, and g. */ - return retval; /* false */ + return retval; /* false */ } if (d1 == d2) { - return retval; /* false */ + return retval; /* false */ } if (c1 == DUK_FP_INFINITE && s1 == 0) { /* x == +Infinity */ - return retval; /* false */ + return retval; /* false */ } if (c2 == DUK_FP_INFINITE && s2 == 0) { /* y == +Infinity */ - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } if (c2 == DUK_FP_INFINITE && s2 != 0) { /* y == -Infinity */ - return retval; /* false */ + return retval; /* false */ } if (c1 == DUK_FP_INFINITE && s1 != 0) { /* x == -Infinity */ - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } if (d1 < d2) { - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } - return retval; /* false */ + return retval; /* false */ } -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ DUK_LOCAL duk_bool_t duk__compare_number(duk_bool_t retval, duk_double_t d1, duk_double_t d2) { /* This comparison tree relies doesn't match the exact steps in * E5 Section 11.8.5 but should produce the same results. The @@ -82054,39 +83371,35 @@ * results in false return (see e.g. Section * 11.8.3) - hence special treatment here. */ - return 0; /* zero regardless of negation */ + return 0; /* zero regardless of negation */ } else { return retval; } } } } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ DUK_INTERNAL duk_bool_t duk_js_compare_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags) { duk_double_t d1, d2; duk_small_int_t rc; duk_bool_t retval; - DUK_ASSERT(DUK_COMPARE_FLAG_NEGATE == 1); /* Rely on this flag being lowest. */ + DUK_ASSERT(DUK_COMPARE_FLAG_NEGATE == 1); /* Rely on this flag being lowest. */ retval = flags & DUK_COMPARE_FLAG_NEGATE; DUK_ASSERT(retval == 0 || retval == 1); /* Fast path for fastints */ #if defined(DUK_USE_FASTINT) if (DUK_LIKELY(DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y))) { - return duk__compare_fastint(retval, - DUK_TVAL_GET_FASTINT(tv_x), - DUK_TVAL_GET_FASTINT(tv_y)); + return duk__compare_fastint(retval, DUK_TVAL_GET_FASTINT(tv_x), DUK_TVAL_GET_FASTINT(tv_y)); } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* Fast path for numbers (one of which may be a fastint) */ #if !defined(DUK_USE_PREFER_SIZE) if (DUK_LIKELY(DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y))) { - return duk__compare_number(retval, - DUK_TVAL_GET_NUMBER(tv_x), - DUK_TVAL_GET_NUMBER(tv_y)); + return duk__compare_number(retval, DUK_TVAL_GET_NUMBER(tv_x), DUK_TVAL_GET_NUMBER(tv_y)); } #endif @@ -82153,7 +83466,7 @@ thr->valstack_top -= 2; tv_x = thr->valstack_top; tv_y = tv_x + 1; - DUK_TVAL_SET_UNDEFINED(tv_x); /* Value stack policy */ + DUK_TVAL_SET_UNDEFINED(tv_x); /* Value stack policy */ DUK_TVAL_SET_UNDEFINED(tv_y); #endif @@ -82207,8 +83520,8 @@ if (!skip_sym_check) { if (duk_get_method_stridx(thr, -1, DUK_STRIDX_WELLKNOWN_SYMBOL_HAS_INSTANCE)) { /* ... lhs rhs func */ - duk_insert(thr, -3); /* -> ... func lhs rhs */ - duk_swap_top(thr, -2); /* -> ... func rhs(this) lhs */ + duk_insert(thr, -3); /* -> ... func lhs rhs */ + duk_swap_top(thr, -2); /* -> ... func rhs(this) lhs */ duk_call_method(thr, 1); return duk_to_boolean_top_pop(thr); } @@ -82240,7 +83553,7 @@ if (DUK_HOBJECT_HAS_BOUNDFUNC(func)) { duk_push_tval(thr, &((duk_hboundfunc *) (void *) func)->target); duk_replace(thr, -2); - func = duk_require_hobject(thr, -1); /* lightfunc throws */ + func = duk_require_hobject(thr, -1); /* lightfunc throws */ /* Rely on Function.prototype.bind() never creating bound * functions whose target is not proper. @@ -82280,19 +83593,19 @@ DUK_ASSERT(val != NULL); break; case DUK_TAG_OBJECT: - skip_first = 1; /* Ignore object itself on first round. */ + skip_first = 1; /* Ignore object itself on first round. */ val = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(val != NULL); break; default: goto pop2_and_false; } - DUK_ASSERT(val != NULL); /* Loop doesn't actually rely on this. */ + DUK_ASSERT(val != NULL); /* Loop doesn't actually rely on this. */ /* Look up .prototype of rval. Leave it on the value stack in case it * has been virtualized (e.g. getter, Proxy trap). */ - duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_PROTOTYPE); /* -> ... lval rval rval.prototype */ + duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_PROTOTYPE); /* -> ... lval rval rval.prototype */ #if defined(DUK_USE_VERBOSE_ERRORS) proto = duk_get_hobject(thr, -1); if (proto == NULL) { @@ -82345,24 +83658,24 @@ DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); DUK_WO_NORETURN(return 0;); - pop2_and_false: +pop2_and_false: duk_pop_2_unsafe(thr); return 0; - pop3_and_false: +pop3_and_false: duk_pop_3_unsafe(thr); return 0; - pop3_and_true: +pop3_and_true: duk_pop_3_unsafe(thr); return 1; - error_invalid_rval: +error_invalid_rval: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_INSTANCEOF_RVAL); DUK_WO_NORETURN(return 0;); #if defined(DUK_USE_VERBOSE_ERRORS) - error_invalid_rval_noproto: +error_invalid_rval_noproto: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO); DUK_WO_NORETURN(return 0;); #endif @@ -82414,9 +83727,7 @@ (void) duk_to_property_key_hstring(thr, -2); - retval = duk_hobject_hasprop(thr, - DUK_GET_TVAL_NEGIDX(thr, -1), - DUK_GET_TVAL_NEGIDX(thr, -2)); + retval = duk_hobject_hasprop(thr, DUK_GET_TVAL_NEGIDX(thr, -1), DUK_GET_TVAL_NEGIDX(thr, -2)); duk_pop_2_unsafe(thr); return retval; @@ -82576,7 +83887,7 @@ } res = 0xfffffffaUL + dig; DUK_ASSERT(res >= 0xfffffffaUL); - DUK_ASSERT_DISABLE(res <= 0xffffffffUL); /* range */ + DUK_ASSERT_DISABLE(res <= 0xffffffffUL); /* range */ } else { res = res * 10U + dig; if (DUK_UNLIKELY(res == 0)) { @@ -82601,7 +83912,7 @@ return res; - parse_fail: +parse_fail: return DUK_HSTRING_NO_ARRAY_INDEX; } @@ -82639,7 +83950,7 @@ } return duk_js_to_arrayindex_hstring_fast_known(h); } -#endif /* DUK_USE_HSTRING_ARRIDX */ +#endif /* DUK_USE_HSTRING_ARRIDX */ /* * Identifier access and function closure handling. * @@ -82680,10 +83991,10 @@ typedef struct { duk_hobject *env; - duk_hobject *holder; /* for object-bound identifiers */ - duk_tval *value; /* for register-bound and declarative env identifiers */ - duk_uint_t attrs; /* property attributes for identifier (relevant if value != NULL) */ - duk_bool_t has_this; /* for object-bound identifiers: provide 'this' binding */ + duk_hobject *holder; /* for object-bound identifiers */ + duk_tval *value; /* for register-bound and declarative env identifiers */ + duk_uint_t attrs; /* property attributes for identifier (relevant if value != NULL) */ + duk_bool_t has_this; /* for object-bound identifiers: provide 'this' binding */ } duk__id_lookup_result; /* @@ -82787,7 +84098,7 @@ DUK_ASSERT(fun_clos != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) fun_clos) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); - duk_push_hobject(thr, &fun_temp->obj); /* -> ... closure template */ + duk_push_hobject(thr, &fun_temp->obj); /* -> ... closure template */ DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun_clos)); DUK_ASSERT(DUK_HCOMPFUNC_GET_DATA(thr->heap, fun_clos) == NULL); @@ -82895,9 +84206,9 @@ } /* -> ... closure template env */ - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); @@ -82905,7 +84216,7 @@ DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) new_env, proto); DUK_HOBJECT_INCREF_ALLOWNULL(thr, proto); - DUK_ASSERT(new_env->thread == NULL); /* Closed. */ + DUK_ASSERT(new_env->thread == NULL); /* Closed. */ DUK_ASSERT(new_env->varmap == NULL); /* It's important that duk_xdef_prop() is a 'raw define' so that any @@ -82919,8 +84230,8 @@ */ (void) duk_get_prop_stridx_short(thr, -2, DUK_STRIDX_NAME); /* -> ... closure template env funcname */ - duk_dup_m4(thr); /* -> ... closure template env funcname closure */ - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> ... closure template env */ + duk_dup_m4(thr); /* -> ... closure template env funcname closure */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> ... closure template env */ /* envfuncname = closure */ /* ... closure template env */ @@ -82932,9 +84243,8 @@ duk_pop_unsafe(thr); /* ... closure template */ - } - else -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ + } else +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ { /* * Other cases (function declaration, anonymous function expression, @@ -82962,7 +84272,7 @@ DUK_HCOMPFUNC_SET_LEXENV(thr->heap, fun_clos, outer_lex_env); DUK_HCOMPFUNC_SET_VARENV(thr->heap, fun_clos, outer_var_env); - DUK_HOBJECT_INCREF(thr, outer_lex_env); /* NULLs not allowed; asserted on entry */ + DUK_HOBJECT_INCREF(thr, outer_lex_env); /* NULLs not allowed; asserted on entry */ DUK_HOBJECT_INCREF(thr, outer_var_env); } DUK_DDD(DUK_DDDPRINT("closure varenv -> %!ipO, lexenv -> %!ipO", @@ -83021,7 +84331,7 @@ DUK_DD(DUK_DDPRINT("closure length defaulted from nargs -> %ld", (long) len_value)); } - duk_push_uint(thr, len_value); /* ... closure template len_value */ + duk_push_uint(thr, len_value); /* ... closure template len_value */ duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* @@ -83041,11 +84351,14 @@ /* ... closure template */ if (add_auto_proto) { - duk_push_object(thr); /* -> ... closure template newobj */ - duk_dup_m3(thr); /* -> ... closure template newobj closure */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC); /* -> ... closure template newobj */ - duk_compact(thr, -1); /* compact the prototype */ - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); /* -> ... closure template */ + duk_push_object(thr); /* -> ... closure template newobj */ + duk_dup_m3(thr); /* -> ... closure template newobj closure */ + duk_xdef_prop_stridx_short(thr, + -2, + DUK_STRIDX_CONSTRUCTOR, + DUK_PROPDESC_FLAGS_WC); /* -> ... closure template newobj */ + duk_compact(thr, -1); /* compact the prototype */ + duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); /* -> ... closure template */ } /* @@ -83086,7 +84399,7 @@ /* ... closure template name */ DUK_ASSERT(duk_is_string(thr, -1)); DUK_DD(DUK_DDPRINT("setting function instance name to %!T", duk_get_tval(thr, -1))); - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); /* -> ... closure template */ + duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); /* -> ... closure template */ } else { /* Anonymous functions don't have a .name in ES2015, so don't set * it on the instance either. The instance will then inherit @@ -83118,10 +84431,8 @@ DUK_ASSERT(duk_has_prop_stridx(thr, -2, DUK_STRIDX_LENGTH) != 0); DUK_ASSERT(add_auto_proto == 0 || duk_has_prop_stridx(thr, -2, DUK_STRIDX_PROTOTYPE) != 0); /* May be missing .name */ - DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || - duk_has_prop_stridx(thr, -2, DUK_STRIDX_CALLER) != 0); - DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || - duk_has_prop_stridx(thr, -2, DUK_STRIDX_LC_ARGUMENTS) != 0); + DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || duk_has_prop_stridx(thr, -2, DUK_STRIDX_CALLER) != 0); + DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || duk_has_prop_stridx(thr, -2, DUK_STRIDX_LC_ARGUMENTS) != 0); /* * Finish @@ -83152,8 +84463,8 @@ duk_hstring *key; key = DUK_HOBJECT_E_GET_KEY(thr->heap, varmap, i); - DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ - DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ + DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ + DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ /* Predefine as 'undefined' to reserve a property slot. * This makes the unwind process (where register values @@ -83170,9 +84481,7 @@ /* shared helper */ DUK_INTERNAL -duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, - duk_hobject *func, - duk_size_t bottom_byteoff) { +duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, duk_hobject *func, duk_size_t bottom_byteoff) { duk_hdecenv *env; duk_hobject *parent; duk_hcompfunc *f; @@ -83188,15 +84497,13 @@ parent = thr->builtinsDUK_BIDX_GLOBAL_ENV; } - env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + env = duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(env != NULL); duk_push_hobject(thr, (duk_hobject *) env); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) env, parent); - DUK_HOBJECT_INCREF_ALLOWNULL(thr, parent); /* parent env is the prototype */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, parent); /* parent env is the prototype */ /* open scope information, for compiled functions only */ @@ -83230,15 +84537,14 @@ } DUK_INTERNAL -void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, - duk_activation *act) { +void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, duk_activation *act) { duk_hobject *func; duk_hobject *env; DUK_ASSERT(thr != NULL); func = DUK_ACT_GET_FUNC(act); DUK_ASSERT(func != NULL); - DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound functions are never in act 'func' */ + DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound functions are never in act 'func' */ /* * Delayed initialization only occurs for 'NEWENV' functions. @@ -83267,7 +84573,7 @@ act->lex_env = env; act->var_env = env; - DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (here 2 times) */ + DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (here 2 times) */ DUK_HOBJECT_INCREF(thr, env); duk_pop_unsafe(thr); @@ -83337,12 +84643,12 @@ duk_size_t regbase_byteoff; key = DUK_HOBJECT_E_GET_KEY(thr->heap, varmap, i); - DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ - DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ + DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ + DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ tv = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, varmap, i); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ + DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv)); regnum = (duk_uint_t) DUK_TVAL_GET_FASTINT_U32(tv); @@ -83351,8 +84657,10 @@ #endif regbase_byteoff = ((duk_hdecenv *) env)->regbase_byteoff; - DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum >= (duk_uint8_t *) thr->valstack); - DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum < (duk_uint8_t *) thr->valstack_top); + DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum >= + (duk_uint8_t *) thr->valstack); + DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum < + (duk_uint8_t *) thr->valstack_top); /* Write register value into env as named properties. * If property already exists, overwrites silently. @@ -83366,7 +84674,8 @@ * out-of-memory error should be possible. If this guarantee * is not provided, problems like GH-476 may happen. */ - duk_push_tval(thr, (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum)); + duk_push_tval(thr, + (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum)); DUK_DDD(DUK_DDDPRINT("closing identifier %!O -> reg %ld, value %!T", (duk_heaphdr *) key, (long) regnum, @@ -83408,10 +84717,7 @@ /* lookup name from an open declarative record's registers */ DUK_LOCAL -duk_bool_t duk__getid_open_decl_env_regs(duk_hthread *thr, - duk_hstring *name, - duk_hdecenv *env, - duk__id_lookup_result *out) { +duk_bool_t duk__getid_open_decl_env_regs(duk_hthread *thr, duk_hstring *name, duk_hdecenv *env, duk__id_lookup_result *out) { duk_tval *tv; duk_size_t reg_rel; @@ -83435,20 +84741,20 @@ } DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ + DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv)); reg_rel = (duk_size_t) DUK_TVAL_GET_FASTINT_U32(tv); #else reg_rel = (duk_size_t) DUK_TVAL_GET_NUMBER(tv); #endif - DUK_ASSERT_DISABLE(reg_rel >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(reg_rel >= 0); /* unsigned */ tv = (duk_tval *) (void *) ((duk_uint8_t *) env->thread->valstack + env->regbase_byteoff + sizeof(duk_tval) * reg_rel); - DUK_ASSERT(tv >= env->thread->valstack && tv < env->thread->valstack_end); /* XXX: more accurate? */ + DUK_ASSERT(tv >= env->thread->valstack && tv < env->thread->valstack_end); /* XXX: more accurate? */ out->value = tv; - out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ + out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ out->env = (duk_hobject *) env; out->holder = NULL; out->has_this = 0; @@ -83457,10 +84763,7 @@ /* lookup name from current activation record's functions' registers */ DUK_LOCAL -duk_bool_t duk__getid_activation_regs(duk_hthread *thr, - duk_hstring *name, - duk_activation *act, - duk__id_lookup_result *out) { +duk_bool_t duk__getid_activation_regs(duk_hthread *thr, duk_hstring *name, duk_activation *act, duk__id_lookup_result *out) { duk_tval *tv; duk_hobject *func; duk_hobject *varmap; @@ -83498,7 +84801,7 @@ tv += reg_rel; out->value = tv; - out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ + out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ out->env = NULL; out->holder = NULL; out->has_this = 0; @@ -83554,9 +84857,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(found from register bindings when env=NULL)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } @@ -83593,8 +84899,7 @@ env = thr->builtinsDUK_BIDX_GLOBAL_ENV; } - DUK_DDD(DUK_DDDPRINT("continue lookup from env: %!iO", - (duk_heaphdr *) env)); + DUK_DDD(DUK_DDDPRINT("continue lookup from env: %!iO", (duk_heaphdr *) env)); } /* @@ -83637,9 +84942,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(declarative environment record, scope open, found in regs)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } @@ -83654,9 +84962,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(declarative environment record, found in properties)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } } else { @@ -83701,7 +85012,7 @@ found = duk_hobject_hasprop(thr, &tv_target_tmp, &tv_name); } else -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ { /* XXX: duk_hobject_hasprop() would be correct for * non-Proxy objects too, but it is about ~20-25% @@ -83712,8 +85023,8 @@ } if (found) { - out->value = NULL; /* can't get value, may be accessor */ - out->attrs = 0; /* irrelevant when out->value == NULL */ + out->value = NULL; /* can't get value, may be accessor */ + out->attrs = 0; /* irrelevant when out->value == NULL */ out->env = env; out->holder = target; out->has_this = ((duk_hobjenv *) env)->has_this; @@ -83721,9 +85032,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(object environment record)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } } @@ -83734,10 +85048,10 @@ goto fail_not_found; } - if (DUK_UNLIKELY(sanity-- == 0)) { - DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); + if (DUK_UNLIKELY(sanity-- == 0)) { + DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); DUK_WO_NORETURN(return 0;); - } + } env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); } @@ -83745,7 +85059,7 @@ * Not found (even in global object) */ - fail_not_found: +fail_not_found: return 0; } @@ -83764,7 +85078,7 @@ * a 'strict' parameter. */ -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_hasvar_envrec(duk_hthread *thr, duk_hobject *env, @@ -83820,11 +85134,7 @@ */ DUK_LOCAL -duk_bool_t duk__getvar_helper(duk_hthread *thr, - duk_hobject *env, - duk_activation *act, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk__getvar_helper(duk_hthread *thr, duk_hobject *env, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag) { duk__id_lookup_result ref; duk_tval tv_tmp_obj; duk_tval tv_tmp_key; @@ -83832,8 +85142,11 @@ DUK_DDD(DUK_DDDPRINT("getvar: thr=%p, env=%p, act=%p, name=%!O " "(env -> %!dO)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); @@ -83841,10 +85154,10 @@ DUK_STATS_INC(thr->heap, stats_getvar_all); - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(env); - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(env); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value) { duk_push_tval(thr, ref.value); @@ -83859,7 +85172,7 @@ DUK_TVAL_SET_OBJECT(&tv_tmp_obj, ref.holder); DUK_TVAL_SET_STRING(&tv_tmp_key, name); - (void) duk_hobject_getprop(thr, &tv_tmp_obj, &tv_tmp_key); /* value */ + (void) duk_hobject_getprop(thr, &tv_tmp_obj, &tv_tmp_key); /* value */ if (ref.has_this) { duk_push_hobject(thr, ref.holder); @@ -83873,7 +85186,8 @@ return 1; } else { if (throw_flag) { - DUK_ERROR_FMT1(thr, DUK_ERR_REFERENCE_ERROR, + DUK_ERROR_FMT1(thr, + DUK_ERR_REFERENCE_ERROR, "identifier '%s' undefined", (const char *) DUK_HSTRING_GET_DATA(name)); DUK_WO_NORETURN(return 0;); @@ -83884,18 +85198,12 @@ } DUK_INTERNAL -duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, - duk_hobject *env, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_bool_t throw_flag) { return duk__getvar_helper(thr, env, NULL, name, throw_flag); } DUK_INTERNAL -duk_bool_t duk_js_getvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk_js_getvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag) { DUK_ASSERT(act != NULL); return duk__getvar_helper(thr, act->lex_env, act, name, throw_flag); } @@ -83932,9 +85240,14 @@ DUK_DDD(DUK_DDDPRINT("putvar: thr=%p, env=%p, act=%p, name=%!O, val=%p, strict=%ld " "(env -> %!dO, val -> %!T)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (void *) val, (long) strict, - (duk_heaphdr *) env, (duk_tval *) val)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (void *) val, + (long) strict, + (duk_heaphdr *) env, + (duk_tval *) val)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); @@ -83945,7 +85258,7 @@ DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); DUK_ASSERT_REFCOUNT_NONZERO_TVAL(val); - DUK_TVAL_SET_TVAL(&tv_tmp_val, val); /* Stabilize. */ + DUK_TVAL_SET_TVAL(&tv_tmp_val, val); /* Stabilize. */ val = NULL; /* @@ -83958,15 +85271,13 @@ * and name 'eval' or 'arguments'. */ - DUK_ASSERT(!strict || - (name != DUK_HTHREAD_STRING_EVAL(thr) && - name != DUK_HTHREAD_STRING_LC_ARGUMENTS(thr))); + DUK_ASSERT(!strict || (name != DUK_HTHREAD_STRING_EVAL(thr) && name != DUK_HTHREAD_STRING_LC_ARGUMENTS(thr))); /* * Lookup variable and update in-place if found. */ - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value && (ref.attrs & DUK_PROPDESC_FLAG_WRITABLE)) { @@ -83979,7 +85290,7 @@ tv_val = ref.value; DUK_ASSERT(tv_val != NULL); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv_val, &tv_tmp_val); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv_val, &tv_tmp_val); /* side effects */ /* ref.value invalidated here */ } else { @@ -84002,7 +85313,8 @@ if (strict) { DUK_DDD(DUK_DDDPRINT("identifier binding not found, strict => reference error")); - DUK_ERROR_FMT1(thr, DUK_ERR_REFERENCE_ERROR, + DUK_ERROR_FMT1(thr, + DUK_ERR_REFERENCE_ERROR, "identifier '%s' undefined", (const char *) DUK_HSTRING_GET_DATA(name)); DUK_WO_NORETURN(return;); @@ -84012,7 +85324,7 @@ DUK_TVAL_SET_OBJECT(&tv_tmp_obj, thr->builtinsDUK_BIDX_GLOBAL); DUK_TVAL_SET_STRING(&tv_tmp_key, name); - (void) duk_hobject_putprop(thr, &tv_tmp_obj, &tv_tmp_key, &tv_tmp_val, 0); /* 0 = no throw */ + (void) duk_hobject_putprop(thr, &tv_tmp_obj, &tv_tmp_key, &tv_tmp_val, 0); /* 0 = no throw */ /* NB: 'val' may be invalidated here because put_value may realloc valstack, * caller beware. @@ -84020,20 +85332,12 @@ } DUK_INTERNAL -void duk_js_putvar_envrec(duk_hthread *thr, - duk_hobject *env, - duk_hstring *name, - duk_tval *val, - duk_bool_t strict) { +void duk_js_putvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_tval *val, duk_bool_t strict) { duk__putvar_helper(thr, env, NULL, name, val, strict); } DUK_INTERNAL -void duk_js_putvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name, - duk_tval *val, - duk_bool_t strict) { +void duk_js_putvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_bool_t strict) { DUK_ASSERT(act != NULL); duk__putvar_helper(thr, act->lex_env, act, name, val, strict); } @@ -84058,25 +85362,25 @@ */ DUK_LOCAL -duk_bool_t duk__delvar_helper(duk_hthread *thr, - duk_hobject *env, - duk_activation *act, - duk_hstring *name) { +duk_bool_t duk__delvar_helper(duk_hthread *thr, duk_hobject *env, duk_activation *act, duk_hstring *name) { duk__id_lookup_result ref; duk_bool_t parents; DUK_DDD(DUK_DDDPRINT("delvar: thr=%p, env=%p, act=%p, name=%!O " "(env -> %!dO)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); /* env and act may be NULL */ - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value && !(ref.attrs & DUK_PROPDESC_FLAG_CONFIGURABLE)) { @@ -84104,7 +85408,7 @@ return 1; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_delvar_envrec(duk_hthread *thr, duk_hobject *env, @@ -84114,9 +85418,7 @@ #endif DUK_INTERNAL -duk_bool_t duk_js_delvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name) { +duk_bool_t duk_js_delvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name) { DUK_ASSERT(act != NULL); return duk__delvar_helper(thr, act->lex_env, act, name); } @@ -84185,9 +85487,13 @@ DUK_DDD(DUK_DDDPRINT("declvar: thr=%p, env=%p, name=%!O, val=%!T, prop_flags=0x%08lx, is_func_decl=%ld " "(env -> %!iO)", - (void *) thr, (void *) env, (duk_heaphdr *) name, - (duk_tval *) val, (unsigned long) prop_flags, - (unsigned int) is_func_decl, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (duk_heaphdr *) name, + (duk_tval *) val, + (unsigned long) prop_flags, + (unsigned int) is_func_decl, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(env != NULL); @@ -84214,7 +85520,7 @@ * environment target object. */ - parents = 0; /* just check 'env' */ + parents = 0; /* just check 'env' */ if (duk__get_identifier_reference(thr, env, name, NULL, parents, &ref)) { duk_int_t e_idx; duk_int_t h_idx; @@ -84229,7 +85535,7 @@ if (!(is_func_decl && env == thr->builtinsDUK_BIDX_GLOBAL_ENV)) { DUK_DDD(DUK_DDDPRINT("re-declare a binding, ignoring")); - return 1; /* 1 -> needs a PUTVAR */ + return 1; /* 1 -> needs a PUTVAR */ } /* @@ -84259,7 +85565,7 @@ * where the property was found (see duk__get_identifier_reference()). */ DUK_ASSERT(DUK_HOBJECT_GET_CLASS_NUMBER(holder) == DUK_HOBJECT_CLASS_GLOBAL); - DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(holder)); /* global object doesn't have array part */ + DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(holder)); /* global object doesn't have array part */ /* XXX: use a helper for prototype traversal; no loop check here */ /* must be found: was found earlier, and cannot be inherited */ @@ -84292,8 +85598,7 @@ "accessor -> reject")); goto fail_existing_attributes; } - if (!((flags & DUK_PROPDESC_FLAG_WRITABLE) && - (flags & DUK_PROPDESC_FLAG_ENUMERABLE))) { + if (!((flags & DUK_PROPDESC_FLAG_WRITABLE) && (flags & DUK_PROPDESC_FLAG_ENUMERABLE))) { DUK_DDD(DUK_DDDPRINT("existing property is a non-configurable " "plain property which is not writable and " "enumerable -> reject")); @@ -84388,13 +85693,13 @@ duk_push_hobject(thr, holder); duk_push_hstring(thr, name); duk_push_tval(thr, val); - duk_xdef_prop(thr, -3, prop_flags); /* holder name val -> holder */ + duk_xdef_prop(thr, -3, prop_flags); /* holder name val -> holder */ duk_pop_unsafe(thr); return 0; - fail_existing_attributes: - fail_not_extensible: +fail_existing_attributes: +fail_not_extensible: DUK_ERROR_TYPE(thr, "declaration failed"); DUK_WO_NORETURN(return 0;); } @@ -84515,34 +85820,34 @@ * Various defines and file specific helper macros */ -#define DUK__MAX_RE_DECESC_DIGITS 9 -#define DUK__MAX_RE_QUANT_DIGITS 9 /* Does not allow e.g. 2**31-1, but one more would allow overflows of u32. */ +#define DUK__MAX_RE_DECESC_DIGITS 9 +#define DUK__MAX_RE_QUANT_DIGITS 9 /* Does not allow e.g. 2**31-1, but one more would allow overflows of u32. */ /* whether to use macros or helper function depends on call count */ -#define DUK__ISDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_9) -#define DUK__ISHEXDIGIT(x) duk__is_hex_digit((x)) -#define DUK__ISOCTDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_7) -#define DUK__ISDIGIT03(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_3) -#define DUK__ISDIGIT47(x) ((x) >= DUK_ASC_4 && (x) <= DUK_ASC_7) +#define DUK__ISDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_9) +#define DUK__ISHEXDIGIT(x) duk__is_hex_digit((x)) +#define DUK__ISOCTDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_7) +#define DUK__ISDIGIT03(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_3) +#define DUK__ISDIGIT47(x) ((x) >= DUK_ASC_4 && (x) <= DUK_ASC_7) /* lexer character window helpers */ -#define DUK__LOOKUP(lex_ctx,idx) ((lex_ctx)->window(idx).codepoint) -#define DUK__ADVANCECHARS(lex_ctx,count) duk__advance_chars((lex_ctx), (count)) -#define DUK__ADVANCEBYTES(lex_ctx,count) duk__advance_bytes((lex_ctx), (count)) +#define DUK__LOOKUP(lex_ctx, idx) ((lex_ctx)->window(idx).codepoint) +#define DUK__ADVANCECHARS(lex_ctx, count) duk__advance_chars((lex_ctx), (count)) +#define DUK__ADVANCEBYTES(lex_ctx, count) duk__advance_bytes((lex_ctx), (count)) #define DUK__INITBUFFER(lex_ctx) duk__initbuffer((lex_ctx)) -#define DUK__APPENDBUFFER(lex_ctx,x) duk__appendbuffer((lex_ctx), (duk_codepoint_t) (x)) -#define DUK__APPENDBUFFER_ASCII(lex_ctx,x) duk__appendbuffer_ascii((lex_ctx), (duk_codepoint_t) (x)) +#define DUK__APPENDBUFFER(lex_ctx, x) duk__appendbuffer((lex_ctx), (duk_codepoint_t) (x)) +#define DUK__APPENDBUFFER_ASCII(lex_ctx, x) duk__appendbuffer_ascii((lex_ctx), (duk_codepoint_t) (x)) /* lookup shorthands (note: assume context variable is named 'lex_ctx') */ -#define DUK__L0() DUK__LOOKUP(lex_ctx, 0) -#define DUK__L1() DUK__LOOKUP(lex_ctx, 1) -#define DUK__L2() DUK__LOOKUP(lex_ctx, 2) -#define DUK__L3() DUK__LOOKUP(lex_ctx, 3) -#define DUK__L4() DUK__LOOKUP(lex_ctx, 4) -#define DUK__L5() DUK__LOOKUP(lex_ctx, 5) +#define DUK__L0() DUK__LOOKUP(lex_ctx, 0) +#define DUK__L1() DUK__LOOKUP(lex_ctx, 1) +#define DUK__L2() DUK__LOOKUP(lex_ctx, 2) +#define DUK__L3() DUK__LOOKUP(lex_ctx, 3) +#define DUK__L4() DUK__LOOKUP(lex_ctx, 4) +#define DUK__L5() DUK__LOOKUP(lex_ctx, 5) /* packed advance/token number macro used by multiple functions */ -#define DUK__ADVTOK(advbytes,tok) ((((advbytes) * sizeof(duk_lexer_codepoint)) << 8) + (tok)) +#define DUK__ADVTOK(advbytes, tok) ((((advbytes) * sizeof(duk_lexer_codepoint)) << 8) + (tok)) /* * Advance lookup window by N characters, filling in new characters as @@ -84652,10 +85957,9 @@ /* Fast path. */ if (DUK_LIKELY(x < 0x80UL)) { - DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ + DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ if (DUK_UNLIKELY(x <= 0x000dUL)) { - if ((x == 0x000aUL) || - ((x == 0x000dUL) && (p >= p_end || *p != 0x000aUL))) { + if ((x == 0x000aUL) || ((x == 0x000dUL) && (p >= p_end || *p != 0x000aUL))) { /* lookup for 0x000a above assumes shortest encoding now */ /* E5 Section 7.3, treat the following as newlines: @@ -84746,8 +86050,8 @@ lex_ctx->input_line = input_line; return; - error_clipped: /* clipped codepoint */ - error_encoding: /* invalid codepoint encoding or codepoint */ +error_clipped: /* clipped codepoint */ +error_encoding: /* invalid codepoint encoding or codepoint */ lex_ctx->input_offset = (duk_size_t) (p - lex_ctx->input); lex_ctx->input_line = input_line; @@ -84758,26 +86062,25 @@ DUK_LOCAL void duk__advance_bytes(duk_lexer_ctx *lex_ctx, duk_small_uint_t count_bytes) { duk_small_uint_t used_bytes, avail_bytes; - DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ DUK_ASSERT(count_bytes <= (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))); DUK_ASSERT(lex_ctx->window >= lex_ctx->buffer); DUK_ASSERT(lex_ctx->window < lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE); - DUK_ASSERT((duk_uint8_t *) lex_ctx->window + count_bytes <= (duk_uint8_t *) lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint)); + DUK_ASSERT((duk_uint8_t *) lex_ctx->window + count_bytes <= + (duk_uint8_t *) lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint)); /* Zero 'count' is also allowed to make call sites easier. * Arithmetic in bytes generates better code in GCC. */ - lex_ctx->window = (duk_lexer_codepoint *) (void *) ((duk_uint8_t *) lex_ctx->window + count_bytes); /* avoid multiply */ + lex_ctx->window = (duk_lexer_codepoint *) (void *) ((duk_uint8_t *) lex_ctx->window + count_bytes); /* avoid multiply */ used_bytes = (duk_small_uint_t) ((duk_uint8_t *) lex_ctx->window - (duk_uint8_t *) lex_ctx->buffer); avail_bytes = DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint) - used_bytes; if (avail_bytes < (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))) { /* Not enough data to provide a full window, so "scroll" window to * start of buffer and fill up the rest. */ - duk_memmove((void *) lex_ctx->buffer, - (const void *) lex_ctx->window, - (size_t) avail_bytes); + duk_memmove((void *) lex_ctx->buffer, (const void *) lex_ctx->window, (size_t) avail_bytes); lex_ctx->window = lex_ctx->buffer; duk__fill_lexer_buffer(lex_ctx, avail_bytes); } @@ -84787,7 +86090,7 @@ lex_ctx->window = lex_ctx->buffer; duk__fill_lexer_buffer(lex_ctx, 0); } -#else /* DUK_USE_LEXER_SLIDING_WINDOW */ +#else /* DUK_USE_LEXER_SLIDING_WINDOW */ DUK_LOCAL duk_codepoint_t duk__read_char(duk_lexer_ctx *lex_ctx) { duk_ucodepoint_t x; duk_small_uint_t len; @@ -84817,11 +86120,10 @@ /* input offset tracking */ lex_ctx->input_offset++; - DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ + DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ if (DUK_UNLIKELY(x <= 0x000dUL)) { - if ((x == 0x000aUL) || - ((x == 0x000dUL) && (lex_ctx->input_offset >= lex_ctx->input_length || - lex_ctx->inputlex_ctx->input_offset != 0x000aUL))) { + if ((x == 0x000aUL) || ((x == 0x000dUL) && (lex_ctx->input_offset >= lex_ctx->input_length || + lex_ctx->inputlex_ctx->input_offset != 0x000aUL))) { /* lookup for 0x000a above assumes shortest encoding now */ /* E5 Section 7.3, treat the following as newlines: @@ -84910,8 +86212,8 @@ return (duk_codepoint_t) x; - error_clipped: /* clipped codepoint */ - error_encoding: /* invalid codepoint encoding or codepoint */ +error_clipped: /* clipped codepoint */ +error_encoding: /* invalid codepoint encoding or codepoint */ DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_SOURCE_DECODE_FAILED); DUK_WO_NORETURN(return 0;); } @@ -84920,15 +86222,13 @@ duk_small_uint_t keep_bytes; duk_lexer_codepoint *cp, *cp_end; - DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ DUK_ASSERT(count_bytes <= (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))); /* Zero 'count' is also allowed to make call sites easier. */ keep_bytes = DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint) - count_bytes; - duk_memmove((void *) lex_ctx->window, - (const void *) ((duk_uint8_t *) lex_ctx->window + count_bytes), - (size_t) keep_bytes); + duk_memmove((void *) lex_ctx->window, (const void *) ((duk_uint8_t *) lex_ctx->window + count_bytes), (size_t) keep_bytes); cp = (duk_lexer_codepoint *) ((duk_uint8_t *) lex_ctx->window + keep_bytes); cp_end = lex_ctx->window + DUK_LEXER_WINDOW_SIZE; @@ -84941,9 +86241,9 @@ DUK_LOCAL void duk__init_lexer_window(duk_lexer_ctx *lex_ctx) { /* Call with count == DUK_LEXER_WINDOW_SIZE to fill buffer initially. */ - duk__advance_bytes(lex_ctx, DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint)); /* fill window */ + duk__advance_bytes(lex_ctx, DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint)); /* fill window */ } -#endif /* DUK_USE_LEXER_SLIDING_WINDOW */ +#endif /* DUK_USE_LEXER_SLIDING_WINDOW */ DUK_LOCAL void duk__advance_chars(duk_lexer_ctx *lex_ctx, duk_small_uint_t count_chars) { duk__advance_bytes(lex_ctx, count_chars * sizeof(duk_lexer_codepoint)); @@ -85036,7 +86336,7 @@ } DUK_INTERNAL void duk_lexer_setpoint(duk_lexer_ctx *lex_ctx, duk_lexer_point *pt) { - DUK_ASSERT_DISABLE(pt->offset >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(pt->offset >= 0); /* unsigned */ DUK_ASSERT(pt->line >= 1); lex_ctx->input_offset = pt->offset; lex_ctx->input_line = pt->line; @@ -85070,8 +86370,7 @@ DUK_LOCAL duk_codepoint_t duk__hexval(duk_codepoint_t x) { duk_codepoint_t ret; - DUK_ASSERT((x >= DUK_ASC_0 && x <= DUK_ASC_9) || - (x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_F) || + DUK_ASSERT((x >= DUK_ASC_0 && x <= DUK_ASC_9) || (x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_F) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_F)); ret = duk__hexval_validate(x); DUK_ASSERT(ret >= 0 && ret <= 15); @@ -85090,12 +86389,12 @@ * source and RegExp parsing. */ DUK_LOCAL duk_codepoint_t duk__lexer_parse_escape(duk_lexer_ctx *lex_ctx, duk_bool_t allow_es6) { - duk_small_int_t digits; /* Initial value 2 or 4 for fixed length escapes, 0 for ES2015 \u{H+}. */ + duk_small_int_t digits; /* Initial value 2 or 4 for fixed length escapes, 0 for ES2015 \u{H+}. */ duk_codepoint_t escval; duk_codepoint_t x; duk_small_uint_t adv; - DUK_ASSERT(DUK__L0() == DUK_ASC_BACKSLASH); /* caller responsibilities */ + DUK_ASSERT(DUK__L0() == DUK_ASC_BACKSLASH); /* caller responsibilities */ DUK_ASSERT(DUK__L1() == DUK_ASC_LC_X || DUK__L1() == DUK_ASC_LC_U); DUK_UNREF(allow_es6); @@ -85169,16 +86468,16 @@ } else { goto fail_escape; } - digits = -1; /* Indicate we have at least one digit. */ -#else /* DUK_USE_ES6_UNICODE_ESCAPE */ - DUK_ASSERT(0); /* Never happens if \u{H+} support disabled. */ -#endif /* DUK_USE_ES6_UNICODE_ESCAPE */ + digits = -1; /* Indicate we have at least one digit. */ +#else /* DUK_USE_ES6_UNICODE_ESCAPE */ + DUK_ASSERT(0); /* Never happens if \u{H+} support disabled. */ +#endif /* DUK_USE_ES6_UNICODE_ESCAPE */ } } return escval; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return 0;); } @@ -85188,7 +86487,9 @@ * RegExp octal escape parsing. Window0 must be the slash '\' and the first * digit must already be validated to be in 0-9 by the caller. */ -DUK_LOCAL duk_codepoint_t duk__lexer_parse_legacy_octal(duk_lexer_ctx *lex_ctx, duk_small_uint_t *out_adv, duk_bool_t reject_annex_b) { +DUK_LOCAL duk_codepoint_t duk__lexer_parse_legacy_octal(duk_lexer_ctx *lex_ctx, + duk_small_uint_t *out_adv, + duk_bool_t reject_annex_b) { duk_codepoint_t cp; duk_small_uint_t lookup_idx; duk_small_uint_t adv; @@ -85223,7 +86524,7 @@ DUK_DDD(DUK_DDDPRINT("\\8 or \\9 -> treat as literal, accept in strict mode too")); DUK_ASSERT(tmp == DUK_ASC_8 || tmp == DUK_ASC_9); cp = tmp; - adv++; /* correction to above, eat offending character */ + adv++; /* correction to above, eat offending character */ } else if (lookup_idx == 2 && cp == 0) { /* Note: 'foo\0bar' is OK in strict mode, but 'foo\00bar' is not. * It won't be interpreted as 'foo\u{0}0bar' but as a SyntaxError. @@ -85247,18 +86548,21 @@ } /* XXX: move strict mode to lex_ctx? */ -DUK_LOCAL void duk__lexer_parse_string_literal(duk_lexer_ctx *lex_ctx, duk_token *out_token, duk_small_int_t quote, duk_bool_t strict_mode) { +DUK_LOCAL void duk__lexer_parse_string_literal(duk_lexer_ctx *lex_ctx, + duk_token *out_token, + duk_small_int_t quote, + duk_bool_t strict_mode) { duk_small_uint_t adv; - for (adv = 1 /* initial quote */ ;;) { + for (adv = 1 /* initial quote */;;) { duk_codepoint_t x; - DUK__ADVANCECHARS(lex_ctx, adv); /* eat opening quote on first loop */ + DUK__ADVANCECHARS(lex_ctx, adv); /* eat opening quote on first loop */ x = DUK__L0(); adv = 1; if (x == quote) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing quote */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing quote */ break; } else if (x == '\\') { /* DUK__L0 -> '\' char @@ -85269,7 +86573,7 @@ x = DUK__L1(); /* How much to advance before next loop. */ - adv = 2; /* note: long live range */ + adv = 2; /* note: long live range */ switch (x) { case '\'': @@ -85312,7 +86616,7 @@ /* line continuation */ if (x == 0x000d && DUK__L2() == 0x000a) { /* CR LF again a special case */ - adv = 3; /* line terminator, CR, LF */ + adv = 3; /* line terminator, CR, LF */ } } else if (DUK__ISDIGIT(x)) { /* @@ -85341,8 +86645,8 @@ /* escaped NonEscapeCharacter */ DUK__APPENDBUFFER(lex_ctx, x); } - } /* end default clause */ - } /* end switch */ + } /* end default clause */ + } /* end switch */ /* Shared handling for single codepoint escapes. */ if (emitcp >= 0) { @@ -85375,11 +86679,11 @@ return; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return;); - fail_unterminated: +fail_unterminated: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_STRING); DUK_WO_NORETURN(return;); } @@ -85466,19 +86770,19 @@ duk_token *out_token, duk_bool_t strict_mode, duk_bool_t regexp_mode) { - duk_codepoint_t x; /* temporary, must be signed and 32-bit to hold Unicode code points */ + duk_codepoint_t x; /* temporary, must be signed and 32-bit to hold Unicode code points */ duk_small_uint_t advtok = 0; /* (advance << 8) + token_type, updated at function end, * init is unnecessary but suppresses "may be used uninitialized" warnings. */ - duk_bool_t got_lineterm = 0; /* got lineterm preceding non-whitespace, non-lineterm token */ + duk_bool_t got_lineterm = 0; /* got lineterm preceding non-whitespace, non-lineterm token */ if (++lex_ctx->token_count >= lex_ctx->token_limit) { goto fail_token_limit; } out_token->t = DUK_TOK_EOF; - out_token->t_nores = DUK_TOK_INVALID; /* marker: copy t if not changed */ -#if 0 /* not necessary to init, disabled for faster parsing */ + out_token->t_nores = DUK_TOK_INVALID; /* marker: copy t if not changed */ +#if 0 /* not necessary to init, disabled for faster parsing */ out_token->num = DUK_DOUBLE_NAN; out_token->str1 = NULL; out_token->str2 = NULL; @@ -85518,35 +86822,34 @@ * in the clauses, so it's not trivial to convert to a switch. */ - restart_lineupdate: +restart_lineupdate: out_token->start_line = lex_ctx->window0.line; - restart: +restart: out_token->start_offset = lex_ctx->window0.offset; x = DUK__L0(); switch (x) { case DUK_ASC_SPACE: - case DUK_ASC_HT: /* fast paths for space and tab */ + case DUK_ASC_HT: /* fast paths for space and tab */ DUK__ADVANCECHARS(lex_ctx, 1); goto restart; - case DUK_ASC_LF: /* LF line terminator; CR LF and Unicode lineterms are handled in slow path */ + case DUK_ASC_LF: /* LF line terminator; CR LF and Unicode lineterms are handled in slow path */ DUK__ADVANCECHARS(lex_ctx, 1); got_lineterm = 1; goto restart_lineupdate; #if defined(DUK_USE_SHEBANG_COMMENTS) - case DUK_ASC_HASH: /* '#' */ - if (DUK__L1() == DUK_ASC_EXCLAMATION && lex_ctx->window0.offset == 0 && - (lex_ctx->flags & DUK_COMPILE_SHEBANG)) { + case DUK_ASC_HASH: /* '#' */ + if (DUK__L1() == DUK_ASC_EXCLAMATION && lex_ctx->window0.offset == 0 && (lex_ctx->flags & DUK_COMPILE_SHEBANG)) { /* "Shebang" comment ('#! ...') on first line. */ /* DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } goto fail_token; -#endif /* DUK_USE_SHEBANG_COMMENTS */ - case DUK_ASC_SLASH: /* '/' */ +#endif /* DUK_USE_SHEBANG_COMMENTS */ + case DUK_ASC_SLASH: /* '/' */ if (DUK__L1() == DUK_ASC_SLASH) { /* * E5 Section 7.4, allow SourceCharacter (which is any 16-bit @@ -85555,7 +86858,7 @@ /* DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } else if (DUK__L1() == DUK_ASC_STAR) { /* * E5 Section 7.4. If the multi-line comment contains a newline, @@ -85639,19 +86942,19 @@ /* first, parse regexp body roughly */ - duk_small_int_t state = 0; /* 0=base, 1=esc, 2=class, 3=class+esc */ + duk_small_int_t state = 0; /* 0=base, 1=esc, 2=class, 3=class+esc */ DUK__INITBUFFER(lex_ctx); for (;;) { - DUK__ADVANCECHARS(lex_ctx, 1); /* skip opening slash on first loop */ + DUK__ADVANCECHARS(lex_ctx, 1); /* skip opening slash on first loop */ x = DUK__L0(); if (x < 0 || duk_unicode_is_line_terminator(x)) { goto fail_unterm_regexp; } - x = DUK__L0(); /* re-read to avoid spill / fetch */ + x = DUK__L0(); /* re-read to avoid spill / fetch */ if (state == 0) { if (x == DUK_ASC_SLASH) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing slash */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing slash */ break; } else if (x == DUK_ASC_BACKSLASH) { state = 1; @@ -85681,20 +86984,20 @@ if (!duk_unicode_is_identifier_part(x)) { break; } - x = DUK__L0(); /* re-read to avoid spill / fetch */ + x = DUK__L0(); /* re-read to avoid spill / fetch */ DUK__APPENDBUFFER(lex_ctx, x); DUK__ADVANCECHARS(lex_ctx, 1); } out_token->str2 = duk__internbuffer(lex_ctx, lex_ctx->slot2_idx); - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* validation of the regexp is caller's responsibility */ advtok = DUK__ADVTOK(0, DUK_TOK_REGEXP); -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ goto fail_regexp_support; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } else if (DUK__L1() == DUK_ASC_EQUALS) { /* "/=" and not in regexp mode */ advtok = DUK__ADVTOK(2, DUK_TOK_DIV_EQ); @@ -85703,25 +87006,25 @@ advtok = DUK__ADVTOK(1, DUK_TOK_DIV); } break; - case DUK_ASC_LCURLY: /* '{' */ + case DUK_ASC_LCURLY: /* '{' */ advtok = DUK__ADVTOK(1, DUK_TOK_LCURLY); break; - case DUK_ASC_RCURLY: /* '}' */ + case DUK_ASC_RCURLY: /* '}' */ advtok = DUK__ADVTOK(1, DUK_TOK_RCURLY); break; - case DUK_ASC_LPAREN: /* '(' */ + case DUK_ASC_LPAREN: /* '(' */ advtok = DUK__ADVTOK(1, DUK_TOK_LPAREN); break; - case DUK_ASC_RPAREN: /* ')' */ + case DUK_ASC_RPAREN: /* ')' */ advtok = DUK__ADVTOK(1, DUK_TOK_RPAREN); break; - case DUK_ASC_LBRACKET: /* '' */ + case DUK_ASC_LBRACKET: /* '' */ advtok = DUK__ADVTOK(1, DUK_TOK_LBRACKET); break; - case DUK_ASC_RBRACKET: /* '' */ + case DUK_ASC_RBRACKET: /* '' */ advtok = DUK__ADVTOK(1, DUK_TOK_RBRACKET); break; - case DUK_ASC_PERIOD: /* '.' */ + case DUK_ASC_PERIOD: /* '.' */ if (DUK__ISDIGIT(DUK__L1())) { /* Period followed by a digit can only start DecimalLiteral * (handled in slow path). We could jump straight into the @@ -85732,13 +87035,13 @@ } advtok = DUK__ADVTOK(1, DUK_TOK_PERIOD); break; - case DUK_ASC_SEMICOLON: /* ';' */ + case DUK_ASC_SEMICOLON: /* ';' */ advtok = DUK__ADVTOK(1, DUK_TOK_SEMICOLON); break; - case DUK_ASC_COMMA: /* ',' */ + case DUK_ASC_COMMA: /* ',' */ advtok = DUK__ADVTOK(1, DUK_TOK_COMMA); break; - case DUK_ASC_LANGLE: /* '<' */ + case DUK_ASC_LANGLE: /* '<' */ #if defined(DUK_USE_HTML_COMMENTS) if (DUK__L1() == DUK_ASC_EXCLAMATION && DUK__L2() == DUK_ASC_MINUS && DUK__L3() == DUK_ASC_MINUS) { /* @@ -85747,11 +87050,10 @@ /* DUK__ADVANCECHARS(lex_ctx, 4) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ - } - else -#endif /* DUK_USE_HTML_COMMENTS */ - if (DUK__L1() == DUK_ASC_LANGLE && DUK__L2() == DUK_ASC_EQUALS) { + goto restart; /* line terminator will be handled on next round */ + } else +#endif /* DUK_USE_HTML_COMMENTS */ + if (DUK__L1() == DUK_ASC_LANGLE && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_ALSHIFT_EQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_LE); @@ -85761,7 +87063,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_LT); } break; - case DUK_ASC_RANGLE: /* '>' */ + case DUK_ASC_RANGLE: /* '>' */ if (DUK__L1() == DUK_ASC_RANGLE && DUK__L2() == DUK_ASC_RANGLE && DUK__L3() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(4, DUK_TOK_RSHIFT_EQ); } else if (DUK__L1() == DUK_ASC_RANGLE && DUK__L2() == DUK_ASC_RANGLE) { @@ -85776,7 +87078,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_GT); } break; - case DUK_ASC_EQUALS: /* '=' */ + case DUK_ASC_EQUALS: /* '=' */ if (DUK__L1() == DUK_ASC_EQUALS && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_SEQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -85785,7 +87087,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_EQUALSIGN); } break; - case DUK_ASC_EXCLAMATION: /* '!' */ + case DUK_ASC_EXCLAMATION: /* '!' */ if (DUK__L1() == DUK_ASC_EQUALS && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_SNEQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -85794,7 +87096,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_LNOT); } break; - case DUK_ASC_PLUS: /* '+' */ + case DUK_ASC_PLUS: /* '+' */ if (DUK__L1() == DUK_ASC_PLUS) { advtok = DUK__ADVTOK(2, DUK_TOK_INCREMENT); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -85803,7 +87105,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_ADD); } break; - case DUK_ASC_MINUS: /* '-' */ + case DUK_ASC_MINUS: /* '-' */ #if defined(DUK_USE_HTML_COMMENTS) if (got_lineterm && DUK__L1() == DUK_ASC_MINUS && DUK__L2() == DUK_ASC_RANGLE) { /* @@ -85820,10 +87122,10 @@ /* DUK__ADVANCECHARS(lex_ctx, 3) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } else -#endif /* DUK_USE_HTML_COMMENTS */ - if (DUK__L1() == DUK_ASC_MINUS) { +#endif /* DUK_USE_HTML_COMMENTS */ + if (DUK__L1() == DUK_ASC_MINUS) { advtok = DUK__ADVTOK(2, DUK_TOK_DECREMENT); } else if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_SUB_EQ); @@ -85831,7 +87133,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_SUB); } break; - case DUK_ASC_STAR: /* '*' */ + case DUK_ASC_STAR: /* '*' */ #if defined(DUK_USE_ES7_EXP_OPERATOR) if (DUK__L1() == DUK_ASC_STAR && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_EXP_EQ); @@ -85839,20 +87141,20 @@ advtok = DUK__ADVTOK(2, DUK_TOK_EXP); } else #endif - if (DUK__L1() == DUK_ASC_EQUALS) { + if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_MUL_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_MUL); } break; - case DUK_ASC_PERCENT: /* '%' */ + case DUK_ASC_PERCENT: /* '%' */ if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_MOD_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_MOD); } break; - case DUK_ASC_AMP: /* '&' */ + case DUK_ASC_AMP: /* '&' */ if (DUK__L1() == DUK_ASC_AMP) { advtok = DUK__ADVTOK(2, DUK_TOK_LAND); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -85861,7 +87163,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_BAND); } break; - case DUK_ASC_PIPE: /* '|' */ + case DUK_ASC_PIPE: /* '|' */ if (DUK__L1() == DUK_ASC_PIPE) { advtok = DUK__ADVTOK(2, DUK_TOK_LOR); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -85870,41 +87172,41 @@ advtok = DUK__ADVTOK(1, DUK_TOK_BOR); } break; - case DUK_ASC_CARET: /* '^' */ + case DUK_ASC_CARET: /* '^' */ if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_BXOR_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_BXOR); } break; - case DUK_ASC_TILDE: /* '~' */ + case DUK_ASC_TILDE: /* '~' */ advtok = DUK__ADVTOK(1, DUK_TOK_BNOT); break; - case DUK_ASC_QUESTION: /* '?' */ + case DUK_ASC_QUESTION: /* '?' */ advtok = DUK__ADVTOK(1, DUK_TOK_QUESTION); break; - case DUK_ASC_COLON: /* ':' */ + case DUK_ASC_COLON: /* ':' */ advtok = DUK__ADVTOK(1, DUK_TOK_COLON); break; - case DUK_ASC_DOUBLEQUOTE: /* '"' */ - case DUK_ASC_SINGLEQUOTE: { /* '\'' */ + case DUK_ASC_DOUBLEQUOTE: /* '"' */ + case DUK_ASC_SINGLEQUOTE: { /* '\'' */ DUK__INITBUFFER(lex_ctx); duk__lexer_parse_string_literal(lex_ctx, out_token, x /*quote*/, strict_mode); duk__internbuffer(lex_ctx, lex_ctx->slot1_idx); out_token->str1 = duk_known_hstring(lex_ctx->thr, lex_ctx->slot1_idx); - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ advtok = DUK__ADVTOK(0, DUK_TOK_STRING); break; } default: goto slow_path; - } /* switch */ + } /* switch */ goto skip_slow_path; - slow_path: +slow_path: if (duk_unicode_is_line_terminator(x)) { if (x == 0x000d && DUK__L1() == 0x000a) { /* @@ -85995,7 +87297,7 @@ str = out_token->str1; out_token->t_nores = DUK_TOK_IDENTIFIER; - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* * Interned identifier is compared against reserved words, which are @@ -86022,7 +87324,7 @@ advtok = DUK__ADVTOK(0, DUK_TOK_IDENTIFIER); if (out_token->num_escapes == 0) { for (i = DUK_STRIDX_START_RESERVED; i < i_end; i++) { - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HEAP_NUM_STRINGS); if (DUK_HTHREAD_GET_STRING(lex_ctx->thr, i) == str) { advtok = DUK__ADVTOK(0, DUK_STRIDX_TO_TOK(i)); @@ -86057,11 +87359,11 @@ duk_double_t val; duk_bool_t legacy_oct = 0; - duk_small_int_t state; /* 0=before period/exp, - * 1=after period, before exp - * 2=after exp, allow '+' or '-' - * 3=after exp and exp sign - */ + duk_small_int_t state; /* 0=before period/exp, + * 1=after period, before exp + * 2=after exp, allow '+' or '-' + * 3=after exp and exp sign + */ duk_small_uint_t s2n_flags; duk_codepoint_t y, z; duk_small_int_t s2n_radix = 10; @@ -86073,7 +87375,7 @@ if (x == DUK_ASC_0) { z = DUK_LOWERCASE_CHAR_ASCII(y); - pre_adv = 2; /* default for 0xNNN, 0oNNN, 0bNNN. */ + pre_adv = 2; /* default for 0xNNN, 0oNNN, 0bNNN. */ if (z == DUK_ASC_LC_X) { s2n_radix = 16; } else if (z == DUK_ASC_LC_O) { @@ -86096,7 +87398,7 @@ DUK__APPENDBUFFER(lex_ctx, x); pre_adv = 1; legacy_oct = 1; - s2n_radix = 8; /* tentative unless conflicting digits found */ + s2n_radix = 8; /* tentative unless conflicting digits found */ } } } @@ -86110,7 +87412,7 @@ */ state = 0; for (;;) { - x = DUK__L0(); /* re-lookup curr char on first round */ + x = DUK__L0(); /* re-lookup curr char on first round */ if (DUK__ISDIGIT(x)) { /* Note: intentionally allow leading zeroes here, as the * actual parser will check for them. @@ -86163,11 +87465,8 @@ /* For bases other than 10, integer only. */ s2n_flags = DUK_S2N_FLAG_ALLOW_LEADING_ZERO; } else { - s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO; + s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_LEADING_ZERO; } duk_dup(lex_ctx->thr, lex_ctx->slot1_idx); @@ -86176,9 +87475,9 @@ if (DUK_ISNAN(val)) { goto fail_number_literal; } - duk_replace(lex_ctx->thr, lex_ctx->slot1_idx); /* could also just pop? */ + duk_replace(lex_ctx->thr, lex_ctx->slot1_idx); /* could also just pop? */ - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* Section 7.8.3 (note): NumericLiteral must be followed by something other than * IdentifierStart or DecimalDigit. @@ -86198,7 +87497,7 @@ } else { goto fail_token; } - skip_slow_path: +skip_slow_path: /* * Shared exit path @@ -86223,32 +87522,32 @@ return; - fail_token_limit: +fail_token_limit: DUK_ERROR_RANGE(lex_ctx->thr, DUK_STR_TOKEN_LIMIT); DUK_WO_NORETURN(return;); - fail_token: +fail_token: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_TOKEN); DUK_WO_NORETURN(return;); - fail_number_literal: +fail_number_literal: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_NUMBER_LITERAL); DUK_WO_NORETURN(return;); - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return;); - fail_unterm_regexp: +fail_unterm_regexp: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_REGEXP); DUK_WO_NORETURN(return;); - fail_unterm_comment: +fail_unterm_comment: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_COMMENT); DUK_WO_NORETURN(return;); #if !defined(DUK_USE_REGEXP_SUPPORT) - fail_regexp_support: +fail_regexp_support: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_REGEXP_SUPPORT_DISABLED); DUK_WO_NORETURN(return;); #endif @@ -86266,7 +87565,7 @@ */ DUK_INTERNAL void duk_lexer_parse_re_token(duk_lexer_ctx *lex_ctx, duk_re_token *out_token) { - duk_small_uint_t advtok = 0; /* init is unnecessary but suppresses "may be used uninitialized" warnings */ + duk_small_uint_t advtok = 0; /* init is unnecessary but suppresses "may be used uninitialized" warnings */ duk_codepoint_t x, y; if (++lex_ctx->token_count >= lex_ctx->token_limit) { @@ -86344,7 +87643,7 @@ #endif for (;;) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat '{' on entry */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat '{' on entry */ x = DUK__L0(); if (DUK__ISDIGIT(x)) { digits++; @@ -86368,7 +87667,7 @@ } val2 = val1; val1 = 0; - digits = 0; /* not strictly necessary because of lookahead '}' above */ + digits = 0; /* not strictly necessary because of lookahead '}' above */ } else if (x == DUK_ASC_RCURLY) { if (digits > DUK__MAX_RE_QUANT_DIGITS) { goto invalid_quantifier; @@ -86399,7 +87698,7 @@ } advtok = DUK__ADVTOK(0, DUK_RETOK_QUANTIFIER); break; - invalid_quantifier: + invalid_quantifier: #if defined(DUK_USE_ES6_REGEXP_SYNTAX) /* Failed to match the quantifier, restore lexer and parse * opening brace as a literal. @@ -86425,7 +87724,7 @@ * ES2015 Annex B relaxes the rules to allow these (and other) real world forms. */ - advtok = DUK__ADVTOK(2, DUK_RETOK_ATOM_CHAR); /* default: char escape (two chars) */ + advtok = DUK__ADVTOK(2, DUK_RETOK_ATOM_CHAR); /* default: char escape (two chars) */ if (y == DUK_ASC_LC_B) { advtok = DUK__ADVTOK(2, DUK_RETOK_ASSERT_WORD_BOUNDARY); } else if (y == DUK_ASC_UC_B) { @@ -86442,8 +87741,7 @@ out_token->num = 0x000b; } else if (y == DUK_ASC_LC_C) { x = DUK__L2(); - if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || - (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { + if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { out_token->num = (duk_uint32_t) (x % 32); advtok = DUK__ADVTOK(3, DUK_RETOK_ATOM_CHAR); } else { @@ -86481,11 +87779,11 @@ /* XXX: shared parsing? */ duk_uint32_t val = 0; duk_small_int_t i; - for (i = 0; ; i++) { + for (i = 0;; i++) { if (i >= DUK__MAX_RE_DECESC_DIGITS) { goto fail_escape; } - DUK__ADVANCECHARS(lex_ctx, 1); /* eat backslash on entry */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat backslash on entry */ x = DUK__L0(); if (!DUK__ISDIGIT(x)) { break; @@ -86505,17 +87803,15 @@ * This is not yet full ES2015 Annex B because cases above * (like hex escape) won't backtrack. */ - DUK_ASSERT(y != DUK_ASC_LC_C); /* covered above */ -#else /* DUK_USE_ES6_REGEXP_SYNTAX */ - } else if ((y >= 0 && !duk_unicode_is_identifier_part(y)) || - y == DUK_UNICODE_CP_ZWNJ || - y == DUK_UNICODE_CP_ZWJ) { + DUK_ASSERT(y != DUK_ASC_LC_C); /* covered above */ +#else /* DUK_USE_ES6_REGEXP_SYNTAX */ + } else if ((y >= 0 && !duk_unicode_is_identifier_part(y)) || y == DUK_UNICODE_CP_ZWNJ || y == DUK_UNICODE_CP_ZWJ) { /* For ES5.1 identity escapes are not allowed for identifier * parts. This conflicts with a lot of real world code as this * doesn't e.g. allow escaping a dollar sign as /\$/, see * test-regexp-identity-escape-dollar.js. */ -#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ +#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ out_token->num = (duk_uint32_t) y; } else { goto fail_escape; @@ -86596,24 +87892,24 @@ out_token->t = advtok & 0xff; return; - fail_token_limit: +fail_token_limit: DUK_ERROR_RANGE(lex_ctx->thr, DUK_STR_TOKEN_LIMIT); DUK_WO_NORETURN(return;); - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_ESCAPE); DUK_WO_NORETURN(return;); - fail_group: +fail_group: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_GROUP); DUK_WO_NORETURN(return;); #if !defined(DUK_USE_ES6_REGEXP_SYNTAX) - fail_invalid_char: +fail_invalid_char: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_CHARACTER); DUK_WO_NORETURN(return;); - fail_quantifier: +fail_quantifier: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_QUANTIFIER); DUK_WO_NORETURN(return;); #endif @@ -86672,7 +87968,7 @@ x = DUK__L0(); - ch = -1; /* not strictly necessary, but avoids "uninitialized variable" warnings */ + ch = -1; /* not strictly necessary, but avoids "uninitialized variable" warnings */ DUK_UNREF(ch); if (x < 0) { @@ -86681,7 +87977,7 @@ if (start >= 0) { gen_range(userdata, start, start, 0); } - DUK__ADVANCECHARS(lex_ctx, 1); /* eat '' before finishing */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat '' before finishing */ break; } else if (x == DUK_ASC_MINUS) { if (start >= 0 && !dash && DUK__L1() != DUK_ASC_RBRACKET) { @@ -86726,8 +88022,7 @@ } else if (x == DUK_ASC_LC_C) { x = DUK__L2(); adv = 3; - if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || - (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { + if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { ch = (x % 32); } else { goto fail_escape; @@ -86791,7 +88086,7 @@ #if defined(DUK_USE_ES6_REGEXP_SYNTAX) ch = duk__lexer_parse_legacy_octal(lex_ctx, &adv, 0 /*reject_annex_b*/); - DUK_ASSERT(ch >= 0); /* no rejections */ + DUK_ASSERT(ch >= 0); /* no rejections */ #else if (x == DUK_ASC_0 && !DUK__ISDIGIT(DUK__L2())) { ch = 0x0000; @@ -86806,7 +88101,7 @@ * EOF here. */ ch = x; -#else /* DUK_USE_ES6_REGEXP_SYNTAX */ +#else /* DUK_USE_ES6_REGEXP_SYNTAX */ } else if (!duk_unicode_is_identifier_part(x)) { /* IdentityEscape: ES5.1 doesn't allow identity escape * for identifier part characters, which conflicts with @@ -86814,7 +88109,7 @@ * /\$/ which is awkward. */ ch = x; -#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ +#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ } else { goto fail_escape; } @@ -86862,20 +88157,20 @@ return; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_ESCAPE); DUK_WO_NORETURN(return;); - fail_range: +fail_range: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_RANGE); DUK_WO_NORETURN(return;); - fail_unterm_charclass: +fail_unterm_charclass: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_CHARCLASS); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* automatic undefs */ #undef DUK__ADVANCEBYTES @@ -86912,10 +88207,10 @@ /* #include duk_internal.h -> already included */ -#define DUK__IEEE_DOUBLE_EXP_BIAS 1023 -#define DUK__IEEE_DOUBLE_EXP_MIN (-1022) /* biased exp == 0 -> denormal, exp -1022 */ +#define DUK__IEEE_DOUBLE_EXP_BIAS 1023 +#define DUK__IEEE_DOUBLE_EXP_MIN (-1022) /* biased exp == 0 -> denormal, exp -1022 */ -#define DUK__DIGITCHAR(x) duk_lc_digits(x) +#define DUK__DIGITCHAR(x) duk_lc_digits(x) /* * Tables generated with util/gennumdigits.py. @@ -86933,10 +88228,10 @@ */ DUK_LOCAL const duk_uint8_t duk__str2num_digits_for_radix = { - 69, 44, 35, 30, 27, 25, 23, 22, 20, 20, /* 2 to 11 */ - 20, 19, 19, 18, 18, 17, 17, 17, 16, 16, /* 12 to 21 */ - 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, /* 22 to 31 */ - 14, 14, 14, 14, 14 /* 31 to 36 */ + 69, 44, 35, 30, 27, 25, 23, 22, 20, 20, /* 2 to 11 */ + 20, 19, 19, 18, 18, 17, 17, 17, 16, 16, /* 12 to 21 */ + 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, /* 22 to 31 */ + 14, 14, 14, 14, 14 /* 31 to 36 */ }; typedef struct { @@ -86945,15 +88240,11 @@ } duk__exp_limits; DUK_LOCAL const duk__exp_limits duk__str2num_exp_limits = { - { 957, -1147 }, { 605, -725 }, { 479, -575 }, { 414, -496 }, - { 372, -446 }, { 342, -411 }, { 321, -384 }, { 304, -364 }, - { 291, -346 }, { 279, -334 }, { 268, -323 }, { 260, -312 }, - { 252, -304 }, { 247, -296 }, { 240, -289 }, { 236, -283 }, - { 231, -278 }, { 227, -273 }, { 223, -267 }, { 220, -263 }, - { 216, -260 }, { 213, -256 }, { 210, -253 }, { 208, -249 }, - { 205, -246 }, { 203, -244 }, { 201, -241 }, { 198, -239 }, - { 196, -237 }, { 195, -234 }, { 193, -232 }, { 191, -230 }, - { 190, -228 }, { 188, -226 }, { 187, -225 }, + { 957, -1147 }, { 605, -725 }, { 479, -575 }, { 414, -496 }, { 372, -446 }, { 342, -411 }, { 321, -384 }, + { 304, -364 }, { 291, -346 }, { 279, -334 }, { 268, -323 }, { 260, -312 }, { 252, -304 }, { 247, -296 }, + { 240, -289 }, { 236, -283 }, { 231, -278 }, { 227, -273 }, { 223, -267 }, { 220, -263 }, { 216, -260 }, + { 213, -256 }, { 210, -253 }, { 208, -249 }, { 205, -246 }, { 203, -244 }, { 201, -241 }, { 198, -239 }, + { 196, -237 }, { 195, -234 }, { 193, -232 }, { 191, -230 }, { 190, -228 }, { 188, -226 }, { 187, -225 }, }; /* @@ -86971,18 +88262,18 @@ /* This upper value has been experimentally determined; debug build will check * bigint size with assertions. */ -#define DUK__BI_MAX_PARTS 37 /* 37x32 = 1184 bits */ +#define DUK__BI_MAX_PARTS 37 /* 37x32 = 1184 bits */ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK__BI_PRINT(name,x) duk__bi_print((name),(x)) +#define DUK__BI_PRINT(name, x) duk__bi_print((name), (x)) #else -#define DUK__BI_PRINT(name,x) +#define DUK__BI_PRINT(name, x) #endif /* Current size is about 152 bytes. */ typedef struct { duk_small_int_t n; - duk_uint32_t vDUK__BI_MAX_PARTS; /* low to high */ + duk_uint32_t vDUK__BI_MAX_PARTS; /* low to high */ } duk__bigint; #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) @@ -87007,9 +88298,8 @@ #if defined(DUK_USE_ASSERTIONS) DUK_LOCAL duk_small_int_t duk__bi_is_valid(duk__bigint *x) { - return (duk_small_int_t) - ( ((x->n >= 0) && (x->n <= DUK__BI_MAX_PARTS)) /* is valid size */ && - ((x->n == 0) || (x->vx->n - 1 != 0)) /* is normalized */ ); + return (duk_small_int_t) (((x->n >= 0) && (x->n <= DUK__BI_MAX_PARTS)) /* is valid size */ && + ((x->n == 0) || (x->vx->n - 1 != 0)) /* is normalized */); } #endif @@ -87080,10 +88370,10 @@ return 0; - ret_gt: +ret_gt: return 1; - ret_lt: +ret_lt: return -1; } @@ -87098,11 +88388,14 @@ if (z->n > y->n) { duk__bigint *t; - t = y; y = z; z = t; + t = y; + y = z; + z = t; } DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; tmp = 0U; for (i = 0; i < ny; i++) { DUK_ASSERT(i < DUK__BI_MAX_PARTS); @@ -87123,7 +88416,7 @@ /* no need to normalize */ DUK_ASSERT(duk__bi_is_valid(x)); } -#else /* DUK_USE_64BIT_OPS */ +#else /* DUK_USE_64BIT_OPS */ DUK_LOCAL void duk__bi_add(duk__bigint *x, duk__bigint *y, duk__bigint *z) { duk_uint32_t carry, tmp1, tmp2; duk_small_int_t i, ny, nz; @@ -87133,11 +88426,14 @@ if (z->n > y->n) { duk__bigint *t; - t = y; y = z; z = t; + t = y; + y = z; + z = t; } DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; carry = 0U; for (i = 0; i < ny; i++) { /* Carry is detected based on wrapping which relies on exact 32-bit @@ -87174,7 +88470,7 @@ /* no need to normalize */ DUK_ASSERT(duk__bi_is_valid(x)); } -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ /* x <- y + z */ DUK_LOCAL void duk__bi_add_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) { @@ -87189,7 +88485,7 @@ DUK_ASSERT(duk__bi_is_valid(x)); } -#if 0 /* unused */ +#if 0 /* unused */ /* x <- x + y, use t as temp */ DUK_LOCAL void duk__bi_add_copy(duk__bigint *x, duk__bigint *y, duk__bigint *t) { duk__bi_add(t, x, y); @@ -87209,7 +88505,8 @@ DUK_ASSERT(duk__bi_compare(y, z) >= 0); DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; tmp = 0; for (i = 0; i < ny; i++) { ty = y->vi; @@ -87220,12 +88517,12 @@ } tmp = (duk_int64_t) ty - (duk_int64_t) tz + tmp; x->vi = (duk_uint32_t) ((duk_uint64_t) tmp & 0xffffffffUL); - tmp = tmp >> 32; /* 0 or -1 */ + tmp = tmp >> 32; /* 0 or -1 */ } DUK_ASSERT(tmp == 0); x->n = i; - duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ + duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ DUK_ASSERT(duk__bi_is_valid(x)); } #else @@ -87238,7 +88535,8 @@ DUK_ASSERT(duk__bi_compare(y, z) >= 0); DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; borrow = 0U; for (i = 0; i < ny; i++) { /* Borrow is detected based on wrapping which relies on exact 32-bit @@ -87266,12 +88564,12 @@ DUK_ASSERT(borrow == 0U); x->n = i; - duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ + duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ DUK_ASSERT(duk__bi_is_valid(x)); } #endif -#if 0 /* unused */ +#if 0 /* unused */ /* x <- y - z */ DUK_LOCAL void duk__bi_sub_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) { duk__bigint tmp; @@ -87299,7 +88597,7 @@ DUK_ASSERT(duk__bi_is_valid(y)); DUK_ASSERT(duk__bi_is_valid(z)); - nx = y->n + z->n; /* max possible */ + nx = y->n + z->n; /* max possible */ DUK_ASSERT(nx <= DUK__BI_MAX_PARTS); if (nx == 0) { @@ -87318,15 +88616,15 @@ #if defined(DUK_USE_64BIT_OPS) duk_uint64_t tmp = 0U; for (j = 0; j < nz; j++) { - tmp += (duk_uint64_t) y->vi * (duk_uint64_t) z->vj + x->vi+j; - x->vi+j = (duk_uint32_t) (tmp & 0xffffffffUL); + tmp += (duk_uint64_t) y->vi * (duk_uint64_t) z->vj + x->vi + j; + x->vi + j = (duk_uint32_t) (tmp & 0xffffffffUL); tmp = tmp >> 32; } if (tmp > 0) { DUK_ASSERT(i + j < nx); DUK_ASSERT(i + j < DUK__BI_MAX_PARTS); - DUK_ASSERT(x->vi+j == 0U); - x->vi+j = (duk_uint32_t) tmp; + DUK_ASSERT(x->vi + j == 0U); + x->vi + j = (duk_uint32_t) tmp; } #else /* @@ -87346,12 +88644,16 @@ duk_uint32_t a, b, c, d, e, f; duk_uint32_t r, s, t; - a = y->vi; b = a & 0xffffUL; a = a >> 16; + a = y->vi; + b = a & 0xffffUL; + a = a >> 16; f = 0; for (j = 0; j < nz; j++) { - c = z->vj; d = c & 0xffffUL; c = c >> 16; - e = x->vi+j; + c = z->vj; + d = c & 0xffffUL; + c = c >> 16; + e = x->vi + j; /* build result as: (r << 32) + s: start with (BD + E + F) */ r = 0; @@ -87359,26 +88661,34 @@ /* add E */ t = s + e; - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add F */ t = s + f; - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add BC*2^16 */ t = b * c; r += (t >> 16); t = s + ((t & 0xffffUL) << 16); - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add AD*2^16 */ t = a * d; r += (t >> 16); t = s + ((t & 0xffffUL) << 16); - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add AC*2^32 */ @@ -87386,20 +88696,22 @@ r += t; DUK_DDD(DUK_DDDPRINT("ab=%08lx cd=%08lx ef=%08lx -> rs=%08lx %08lx", - (unsigned long) y->vi, (unsigned long) z->vj, - (unsigned long) x->vi+j, (unsigned long) r, + (unsigned long) y->vi, + (unsigned long) z->vj, + (unsigned long) x->vi + j, + (unsigned long) r, (unsigned long) s)); - x->vi+j = s; + x->vi + j = s; f = r; } if (f > 0U) { DUK_ASSERT(i + j < nx); DUK_ASSERT(i + j < DUK__BI_MAX_PARTS); - DUK_ASSERT(x->vi+j == 0U); - x->vi+j = (duk_uint32_t) f; + DUK_ASSERT(x->vi + j == 0U); + x->vi + j = (duk_uint32_t) f; } -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ } duk__bi_normalize(x); @@ -87438,7 +88750,7 @@ DUK_LOCAL int duk__bi_is_zero(duk__bigint *x) { DUK_ASSERT(duk__bi_is_valid(x)); - return (x->n == 0); /* this is the case for normalized numbers */ + return (x->n == 0); /* this is the case for normalized numbers */ } /* Bigint is 2^52. Used to detect normalized IEEE double mantissa values @@ -87449,8 +88761,7 @@ */ DUK_LOCAL duk_small_int_t duk__bi_is_2to52(duk__bigint *x) { DUK_ASSERT(duk__bi_is_valid(x)); - return (duk_small_int_t) - (x->n == 2) && (x->v0 == 0U) && (x->v1 == (1U << (52-32))); + return (duk_small_int_t) (x->n == 2) && (x->v0 == 0U) && (x->v1 == (1U << (52 - 32))); } /* x <- (1<<y) */ @@ -87469,7 +88780,7 @@ DUK_LOCAL void duk__bi_exp_small(duk__bigint *x, duk_small_int_t b, duk_small_int_t y, duk__bigint *t1, duk__bigint *t2) { /* Fast path the binary case */ - DUK_ASSERT(x != t1 && x != t2 && t1 != t2); /* distinct bignums, easy mistake to make */ + DUK_ASSERT(x != t1 && x != t2 && t1 != t2); /* distinct bignums, easy mistake to make */ DUK_ASSERT(b >= 0); DUK_ASSERT(y >= 0); @@ -87524,14 +88835,14 @@ */ /* Maximum number of digits generated. */ -#define DUK__MAX_OUTPUT_DIGITS 1040 /* (Number.MAX_VALUE).toString(2).length == 1024, + slack */ +#define DUK__MAX_OUTPUT_DIGITS 1040 /* (Number.MAX_VALUE).toString(2).length == 1024, + slack */ /* Maximum number of characters in formatted value. */ -#define DUK__MAX_FORMATTED_LENGTH 1040 /* (-Number.MAX_VALUE).toString(2).length == 1025, + slack */ +#define DUK__MAX_FORMATTED_LENGTH 1040 /* (-Number.MAX_VALUE).toString(2).length == 1025, + slack */ /* Number and (minimum) size of bigints in the nc_ctx structure. */ -#define DUK__NUMCONV_CTX_NUM_BIGINTS 7 -#define DUK__NUMCONV_CTX_BIGINTS_SIZE (sizeof(duk__bigint) * DUK__NUMCONV_CTX_NUM_BIGINTS) +#define DUK__NUMCONV_CTX_NUM_BIGINTS 7 +#define DUK__NUMCONV_CTX_BIGINTS_SIZE (sizeof(duk__bigint) * DUK__NUMCONV_CTX_NUM_BIGINTS) typedef struct { /* Currently about 7*152 = 1064 bytes. The space for these @@ -87541,31 +88852,32 @@ */ duk__bigint f, r, s, mp, mm, t1, t2; - duk_small_int_t is_s2n; /* if 1, doing a string-to-number; else doing a number-to-string */ - duk_small_int_t is_fixed; /* if 1, doing a fixed format output (not free format) */ - duk_small_int_t req_digits; /* requested number of output digits; 0 = free-format */ - duk_small_int_t abs_pos; /* digit position is absolute, not relative */ - duk_small_int_t e; /* exponent for 'f' */ - duk_small_int_t b; /* input radix */ - duk_small_int_t B; /* output radix */ - duk_small_int_t k; /* see algorithm */ - duk_small_int_t low_ok; /* see algorithm */ - duk_small_int_t high_ok; /* see algorithm */ - duk_small_int_t unequal_gaps; /* m+ != m- (very rarely) */ + duk_small_int_t is_s2n; /* if 1, doing a string-to-number; else doing a number-to-string */ + duk_small_int_t is_fixed; /* if 1, doing a fixed format output (not free format) */ + duk_small_int_t req_digits; /* requested number of output digits; 0 = free-format */ + duk_small_int_t abs_pos; /* digit position is absolute, not relative */ + duk_small_int_t e; /* exponent for 'f' */ + duk_small_int_t b; /* input radix */ + duk_small_int_t B; /* output radix */ + duk_small_int_t k; /* see algorithm */ + duk_small_int_t low_ok; /* see algorithm */ + duk_small_int_t high_ok; /* see algorithm */ + duk_small_int_t unequal_gaps; /* m+ != m- (very rarely) */ /* Buffer used for generated digits, values are in the range 0,B-1. */ duk_uint8_t digitsDUK__MAX_OUTPUT_DIGITS; - duk_small_int_t count; /* digit count */ + duk_small_int_t count; /* digit count */ } duk__numconv_stringify_ctx; /* Note: computes with 'idx' in assertions, so caller beware. * 'idx' is preincremented, i.e. '1' on first call, because it * is more convenient for the caller. */ -#define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx,preinc_idx,x) do { \ - DUK_ASSERT((preinc_idx) - 1 >= 0); \ - DUK_ASSERT((preinc_idx) - 1 < DUK__MAX_OUTPUT_DIGITS); \ - ((nc_ctx)->digits(preinc_idx) - 1) = (duk_uint8_t) (x); \ +#define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, preinc_idx, x) \ + do { \ + DUK_ASSERT((preinc_idx) -1 >= 0); \ + DUK_ASSERT((preinc_idx) -1 < DUK__MAX_OUTPUT_DIGITS); \ + ((nc_ctx)->digits(preinc_idx) -1) = (duk_uint8_t) (x); \ } while (0) DUK_LOCAL duk_size_t duk__dragon4_format_uint32(duk_uint8_t *buf, duk_uint32_t x, duk_small_int_t radix) { @@ -87664,11 +88976,11 @@ "lowest mantissa value for this exponent -> " "unequal gaps")); - duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ - duk__bi_mul_small(&nc_ctx->mp, &nc_ctx->mm, (duk_uint32_t) nc_ctx->b); /* mp <- b^(e+1) */ + duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ + duk__bi_mul_small(&nc_ctx->mp, &nc_ctx->mm, (duk_uint32_t) nc_ctx->b); /* mp <- b^(e+1) */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->f, 2); - duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^(e+1) */ - duk__bi_set_small(&nc_ctx->s, (duk_uint32_t) (nc_ctx->b * 2)); /* s <- 2 * b */ + duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^(e+1) */ + duk__bi_set_small(&nc_ctx->s, (duk_uint32_t) (nc_ctx->b * 2)); /* s <- 2 * b */ nc_ctx->unequal_gaps = 1; } else { /* (>= e 0) AND (not (= f (expt b (- p 1)))) @@ -87688,11 +89000,11 @@ "not lowest mantissa for this exponent -> " "equal gaps")); - duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ - duk__bi_copy(&nc_ctx->mp, &nc_ctx->mm); /* mp <- b^e */ + duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ + duk__bi_copy(&nc_ctx->mp, &nc_ctx->mm); /* mp <- b^e */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->f, 2); - duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^e */ - duk__bi_set_small(&nc_ctx->s, 2); /* s <- 2 */ + duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^e */ + duk__bi_set_small(&nc_ctx->s, 2); /* s <- 2 */ } } else { /* When doing string-to-number, lowest_mantissa is always 0 so @@ -87714,9 +89026,13 @@ "lowest mantissa for this exponent -> " "unequal gaps")); - duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, (duk_uint32_t) (nc_ctx->b * 2)); /* r <- (2 * b) * f */ - duk__bi_exp_small(&nc_ctx->t1, nc_ctx->b, 1 - nc_ctx->e, &nc_ctx->s, &nc_ctx->t2); /* NB: use 's' as temp on purpose */ - duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(1-e) * 2 */ + duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, (duk_uint32_t) (nc_ctx->b * 2)); /* r <- (2 * b) * f */ + duk__bi_exp_small(&nc_ctx->t1, + nc_ctx->b, + 1 - nc_ctx->e, + &nc_ctx->s, + &nc_ctx->t2); /* NB: use 's' as temp on purpose */ + duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(1-e) * 2 */ duk__bi_set_small(&nc_ctx->mp, 2); duk__bi_set_small(&nc_ctx->mm, 1); nc_ctx->unequal_gaps = 1; @@ -87735,9 +89051,13 @@ "lowest mantissa for this exponent -> " "equal gaps")); - duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, 2); /* r <- 2 * f */ - duk__bi_exp_small(&nc_ctx->t1, nc_ctx->b, -nc_ctx->e, &nc_ctx->s, &nc_ctx->t2); /* NB: use 's' as temp on purpose */ - duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(-e) * 2 */ + duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, 2); /* r <- 2 * f */ + duk__bi_exp_small(&nc_ctx->t1, + nc_ctx->b, + -nc_ctx->e, + &nc_ctx->s, + &nc_ctx->t2); /* NB: use 's' as temp on purpose */ + duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(-e) * 2 */ duk__bi_set_small(&nc_ctx->mp, 1); duk__bi_set_small(&nc_ctx->mm, 1); } @@ -87769,8 +89089,8 @@ * impact for very large and very small numbers. */ - DUK_DDD(DUK_DDDPRINT("scale: B=%ld, low_ok=%ld, high_ok=%ld", - (long) nc_ctx->B, (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); + DUK_DDD( + DUK_DDDPRINT("scale: B=%ld, low_ok=%ld, high_ok=%ld", (long) nc_ctx->B, (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); DUK__BI_PRINT("r(init)", &nc_ctx->r); DUK__BI_PRINT("s(init)", &nc_ctx->s); DUK__BI_PRINT("mp(init)", &nc_ctx->mp); @@ -87783,7 +89103,7 @@ DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) >= (nc_ctx->high_ok ? 0 : 1)) { DUK_DDD(DUK_DDDPRINT("k is too low")); /* r <- r @@ -87812,8 +89132,8 @@ DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ - duk__bi_mul_small(&nc_ctx->t2, &nc_ctx->t1, (duk_uint32_t) nc_ctx->B); /* t2 = (* (+ r m+) B) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ + duk__bi_mul_small(&nc_ctx->t2, &nc_ctx->t1, (duk_uint32_t) nc_ctx->B); /* t2 = (* (+ r m+) B) */ if (duk__bi_compare(&nc_ctx->t2, &nc_ctx->s) <= (nc_ctx->high_ok ? -1 : 0)) { DUK_DDD(DUK_DDDPRINT("k is too high")); /* r <- (* r B) @@ -87834,11 +89154,11 @@ } } - skip_dec_k: +skip_dec_k: if (!nc_ctx->unequal_gaps) { DUK_DDD(DUK_DDDPRINT("equal gaps, copy m- from m+")); - duk__bi_copy(&nc_ctx->mm, &nc_ctx->mp); /* mm <- mp */ + duk__bi_copy(&nc_ctx->mm, &nc_ctx->mp); /* mm <- mp */ } nc_ctx->k = k; @@ -87850,9 +89170,9 @@ } DUK_LOCAL void duk__dragon4_generate(duk__numconv_stringify_ctx *nc_ctx) { - duk_small_int_t tc1, tc2; /* terminating conditions */ - duk_small_int_t d; /* current digit */ - duk_small_int_t count = 0; /* digit count */ + duk_small_int_t tc1, tc2; /* terminating conditions */ + duk_small_int_t d; /* current digit */ + duk_small_int_t count = 0; /* digit count */ /* * Digit generation loop. @@ -87874,25 +89194,28 @@ for (;;) { DUK_DDD(DUK_DDDPRINT("generate loop, count=%ld, k=%ld, B=%ld, low_ok=%ld, high_ok=%ld", - (long) count, (long) nc_ctx->k, (long) nc_ctx->B, - (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); + (long) count, + (long) nc_ctx->k, + (long) nc_ctx->B, + (long) nc_ctx->low_ok, + (long) nc_ctx->high_ok)); DUK__BI_PRINT("r", &nc_ctx->r); DUK__BI_PRINT("s", &nc_ctx->s); DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); /* (quotient-remainder (* r B) s) using a dummy subtraction loop */ - duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, (duk_uint32_t) nc_ctx->B); /* t1 <- (* r B) */ + duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, (duk_uint32_t) nc_ctx->B); /* t1 <- (* r B) */ d = 0; for (;;) { if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { break; } - duk__bi_sub_copy(&nc_ctx->t1, &nc_ctx->s, &nc_ctx->t2); /* t1 <- t1 - s */ + duk__bi_sub_copy(&nc_ctx->t1, &nc_ctx->s, &nc_ctx->t2); /* t1 <- t1 - s */ d++; } - duk__bi_copy(&nc_ctx->r, &nc_ctx->t1); /* r <- (remainder (* r B) s) */ - /* d <- (quotient (* r B) s) (in range 0...B-1) */ + duk__bi_copy(&nc_ctx->r, &nc_ctx->t1); /* r <- (remainder (* r B) s) */ + /* d <- (quotient (* r B) s) (in range 0...B-1) */ DUK_DDD(DUK_DDDPRINT("-> d(quot)=%ld", (long) d)); DUK__BI_PRINT("r(rem)", &nc_ctx->r); @@ -87911,7 +89234,7 @@ /* free-form */ tc1 = (duk__bi_compare(&nc_ctx->r, &nc_ctx->mm) <= (nc_ctx->low_ok ? 0 : -1)); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 <- (+ r m+) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 <- (+ r m+) */ tc2 = (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) >= (nc_ctx->high_ok ? 0 : 1)); DUK_DDD(DUK_DDDPRINT("tc1=%ld, tc2=%ld", (long) tc1, (long) tc2)); @@ -87930,20 +89253,21 @@ if (tc2) { /* tc1 = true, tc2 = true */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, 2); - if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { /* (< (* r 2) s) */ + if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { /* (< (* r 2) s) */ DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=true, 2r > s: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + (long) d, + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); } else { DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=true, 2r <= s: output d+1 --> %ld (k=%ld)", - (long) (d + 1), (long) nc_ctx->k)); + (long) (d + 1), + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d + 1); } break; } else { /* tc1 = true, tc2 = false */ - DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=false: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=false: output d --> %ld (k=%ld)", (long) d, (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); break; } @@ -87951,13 +89275,13 @@ if (tc2) { /* tc1 = false, tc2 = true */ DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=true: output d+1 --> %ld (k=%ld)", - (long) (d + 1), (long) nc_ctx->k)); + (long) (d + 1), + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d + 1); break; } else { /* tc1 = false, tc2 = false */ - DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=false: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=false: output d --> %ld (k=%ld)", (long) d, (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); /* r <- r (updated above: r <- (remainder (* r B) s) @@ -87974,23 +89298,28 @@ /* fixed-format termination conditions */ if (nc_ctx->is_fixed) { if (nc_ctx->abs_pos) { - int pos = nc_ctx->k - count + 1; /* count is already incremented, take into account */ + int pos = nc_ctx->k - count + 1; /* count is already incremented, take into account */ DUK_DDD(DUK_DDDPRINT("fixed format, absolute: abs pos=%ld, k=%ld, count=%ld, req=%ld", - (long) pos, (long) nc_ctx->k, (long) count, (long) nc_ctx->req_digits)); + (long) pos, + (long) nc_ctx->k, + (long) count, + (long) nc_ctx->req_digits)); if (pos <= nc_ctx->req_digits) { DUK_DDD(DUK_DDDPRINT("digit position reached req_digits, end generate loop")); break; } } else { DUK_DDD(DUK_DDDPRINT("fixed format, relative: k=%ld, count=%ld, req=%ld", - (long) nc_ctx->k, (long) count, (long) nc_ctx->req_digits)); + (long) nc_ctx->k, + (long) count, + (long) nc_ctx->req_digits)); if (count >= nc_ctx->req_digits) { DUK_DDD(DUK_DDDPRINT("digit count reached req_digits, end generate loop")); break; } } } - } /* for */ + } /* for */ nc_ctx->count = count; @@ -88009,8 +89338,7 @@ bufi = (duk_uint8_t) DUK__DIGITCHAR(t); } } - DUK_DDD(DUK_DDDPRINT("-> generated digits; k=%ld, digits='%s'", - (long) nc_ctx->k, (const char *) buf)); + DUK_DDD(DUK_DDDPRINT("-> generated digits; k=%ld, digits='%s'", (long) nc_ctx->k, (const char *) buf)); } #endif } @@ -88039,11 +89367,11 @@ if (round_idx >= nc_ctx->count) { DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld >= %ld (count)) -> no rounding", - (long) round_idx, (long) nc_ctx->count)); + (long) round_idx, + (long) nc_ctx->count)); return 0; } else if (round_idx < 0) { - DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld < 0) -> no rounding", - (long) round_idx)); + DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld < 0) -> no rounding", (long) round_idx)); return 0; } @@ -88068,15 +89396,18 @@ duk_memmove((void *) (&nc_ctx->digits1), (const void *) (&nc_ctx->digits0), (size_t) (sizeof(char) * (size_t) nc_ctx->count)); - nc_ctx->digits0 = 1; /* don't increase 'count' */ - nc_ctx->k++; /* position of highest digit changed */ - nc_ctx->count++; /* number of digits changed */ + nc_ctx->digits0 = 1; /* don't increase 'count' */ + nc_ctx->k++; /* position of highest digit changed */ + nc_ctx->count++; /* number of digits changed */ ret = 1; break; } DUK_DDD(DUK_DDDPRINT("fixed-format rounding carry: B=%ld, roundup_limit=%ld, p=%p, digits=%p", - (long) nc_ctx->B, (long) roundup_limit, (void *) p, (void *) nc_ctx->digits)); + (long) nc_ctx->B, + (long) roundup_limit, + (void *) p, + (void *) nc_ctx->digits)); p--; t = *p; DUK_DDD(DUK_DDDPRINT("digit before carry: %ld", (long) t)); @@ -88093,7 +89424,7 @@ return ret; } -#define DUK__NO_EXP (65536) /* arbitrary marker, outside valid exp range */ +#define DUK__NO_EXP (65536) /* arbitrary marker, outside valid exp range */ DUK_LOCAL void duk__dragon4_convert_and_push(duk__numconv_stringify_ctx *nc_ctx, duk_hthread *thr, @@ -88136,7 +89467,7 @@ DUK_ASSERT(nc_ctx->count >= 1); k = nc_ctx->k; - buf = (duk_uint8_t *) &nc_ctx->f; /* XXX: union would be more correct */ + buf = (duk_uint8_t *) &nc_ctx->f; /* XXX: union would be more correct */ q = buf; /* Exponent handling: if exponent format is used, record exponent value and @@ -88148,14 +89479,13 @@ expt = DUK__NO_EXP; if (!nc_ctx->abs_pos /* toFixed() */) { - if ((flags & DUK_N2S_FLAG_FORCE_EXP) || /* exponential notation forced */ - ((flags & DUK_N2S_FLAG_NO_ZERO_PAD) && /* fixed precision and zero padding would be required */ - (k - digits >= 1)) || /* (e.g. k=3, digits=2 -> "12X") */ - ((k > 21 || k <= -6) && (radix == 10))) { /* toString() conditions */ - DUK_DDD(DUK_DDDPRINT("use exponential notation: k=%ld -> expt=%ld", - (long) k, (long) (k - 1))); - expt = k - 1; /* e.g. 12.3 -> digits="123" k=2 -> 1.23e1 */ - k = 1; /* generate mantissa with a single leading whole number digit */ + if ((flags & DUK_N2S_FLAG_FORCE_EXP) || /* exponential notation forced */ + ((flags & DUK_N2S_FLAG_NO_ZERO_PAD) && /* fixed precision and zero padding would be required */ + (k - digits >= 1)) || /* (e.g. k=3, digits=2 -> "12X") */ + ((k > 21 || k <= -6) && (radix == 10))) { /* toString() conditions */ + DUK_DDD(DUK_DDDPRINT("use exponential notation: k=%ld -> expt=%ld", (long) k, (long) (k - 1))); + expt = k - 1; /* e.g. 12.3 -> digits="123" k=2 -> 1.23e1 */ + k = 1; /* generate mantissa with a single leading whole number digit */ } } @@ -88181,13 +89511,18 @@ DUK_DDD(DUK_DDDPRINT("expt=%ld, k=%ld, count=%ld, pos=%ld, pos_end=%ld, is_fixed=%ld, " "digits=%ld, abs_pos=%ld", - (long) expt, (long) k, (long) nc_ctx->count, (long) pos, (long) pos_end, - (long) nc_ctx->is_fixed, (long) digits, (long) nc_ctx->abs_pos)); + (long) expt, + (long) k, + (long) nc_ctx->count, + (long) pos, + (long) pos_end, + (long) nc_ctx->is_fixed, + (long) digits, + (long) nc_ctx->abs_pos)); /* Digit generation */ while (pos > pos_end) { - DUK_DDD(DUK_DDDPRINT("digit generation: pos=%ld, pos_end=%ld", - (long) pos, (long) pos_end)); + DUK_DDD(DUK_DDDPRINT("digit generation: pos=%ld, pos_end=%ld", (long) pos, (long) pos_end)); if (pos == 0) { *q++ = (duk_uint8_t) '.'; } @@ -88280,7 +89615,7 @@ /* normal: implicit leading 1-bit */ nc_ctx->f.v1 |= 0x00100000UL; expt = expt - DUK__IEEE_DOUBLE_EXP_BIAS - 52; - DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); /* true, because v1 has at least one bit set */ + DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); /* true, because v1 has at least one bit set */ } DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); @@ -88303,7 +89638,7 @@ /* Sometimes this assert is not true right now; it will be true after * rounding. See: test-bug-numconv-mantissa-assert.js. */ - DUK_ASSERT_DISABLE(nc_ctx->digits0 == 1); /* zero handled by caller */ + DUK_ASSERT_DISABLE(nc_ctx->digits0 == 1); /* zero handled by caller */ /* Should not be required because the code below always sets both high * and low parts, but at least gcc-4.4.5 fails to deduce this correctly @@ -88348,31 +89683,30 @@ skip_round = 0; - recheck_exp: +recheck_exp: - expt = nc_ctx->k - 1; /* IEEE exp without bias */ + expt = nc_ctx->k - 1; /* IEEE exp without bias */ if (expt > 1023) { /* Infinity */ - bitstart = -255; /* needed for inf: causes mantissa to become zero, - * and rounding to be skipped. - */ + bitstart = -255; /* needed for inf: causes mantissa to become zero, + * and rounding to be skipped. + */ expt = 2047; } else if (expt >= -1022) { /* normal */ - bitstart = 1; /* skip leading digit */ + bitstart = 1; /* skip leading digit */ expt += DUK__IEEE_DOUBLE_EXP_BIAS; DUK_ASSERT(expt >= 1 && expt <= 2046); } else { /* denormal or zero */ - bitstart = 1023 + expt; /* expt==-1023 -> bitstart=0 (leading 1); - * expt==-1024 -> bitstart=-1 (one left of leading 1), etc - */ + bitstart = 1023 + expt; /* expt==-1023 -> bitstart=0 (leading 1); + * expt==-1024 -> bitstart=-1 (one left of leading 1), etc + */ expt = 0; } bitround = bitstart + 52; - DUK_DDD(DUK_DDDPRINT("ieee expt=%ld, bitstart=%ld, bitround=%ld", - (long) expt, (long) bitstart, (long) bitround)); + DUK_DDD(DUK_DDDPRINT("ieee expt=%ld, bitstart=%ld, bitround=%ld", (long) expt, (long) bitstart, (long) bitround)); if (!skip_round) { if (duk__dragon4_fixed_format_round(nc_ctx, bitround)) { @@ -88410,13 +89744,11 @@ } /* t has high mantissa */ - DUK_DDD(DUK_DDDPRINT("mantissa is complete: %08lx %08lx", - (unsigned long) t, - (unsigned long) DUK_DBLUNION_GET_LOW32(&u))); + DUK_DDD(DUK_DDDPRINT("mantissa is complete: %08lx %08lx", (unsigned long) t, (unsigned long) DUK_DBLUNION_GET_LOW32(&u))); DUK_ASSERT(expt >= 0 && expt <= 0x7ffL); t += ((duk_uint32_t) expt) << 20; -#if 0 /* caller handles sign change */ +#if 0 /* caller handles sign change */ if (negative) { t |= 0x80000000U; } @@ -88437,12 +89769,15 @@ * Output: string */ -DUK_LOCAL DUK_NOINLINE void duk__numconv_stringify_raw(duk_hthread *thr, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags) { +DUK_LOCAL DUK_NOINLINE void duk__numconv_stringify_raw(duk_hthread *thr, + duk_small_int_t radix, + duk_small_int_t digits, + duk_small_uint_t flags) { duk_double_t x; duk_small_int_t c; duk_small_int_t neg; duk_uint32_t uval; - duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ + duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ duk__numconv_stringify_ctx *nc_ctx = &nc_ctx_alloc; x = (duk_double_t) duk_require_number(thr, -1); @@ -88494,13 +89829,13 @@ */ uval = duk_double_to_uint32_t(x); - if (duk_double_equals((double) uval, x) && /* integer number in range */ - flags == 0) { /* no special formatting */ + if (duk_double_equals((double) uval, x) && /* integer number in range */ + flags == 0) { /* no special formatting */ /* use bigint area as a temp */ duk_uint8_t *buf = (duk_uint8_t *) (&nc_ctx->f); duk_uint8_t *p = buf; - DUK_ASSERT(DUK__NUMCONV_CTX_BIGINTS_SIZE >= 32 + 1); /* max size: radix=2 + sign */ + DUK_ASSERT(DUK__NUMCONV_CTX_BIGINTS_SIZE >= 32 + 1); /* max size: radix=2 + sign */ if (neg && uval != 0) { /* no negative sign for zero */ *p++ = (duk_uint8_t) '-'; @@ -88556,9 +89891,9 @@ duk_small_int_t count; if (nc_ctx->is_fixed) { if (nc_ctx->abs_pos) { - count = digits + 2; /* lead zero + 'digits' fractions + 1 for rounding */ + count = digits + 2; /* lead zero + 'digits' fractions + 1 for rounding */ } else { - count = digits + 1; /* + 1 for rounding */ + count = digits + 1; /* + 1 for rounding */ } } else { count = 1; @@ -88567,12 +89902,12 @@ DUK_ASSERT(count >= 1); duk_memzero((void *) nc_ctx->digits, (size_t) count); nc_ctx->count = count; - nc_ctx->k = 1; /* 0.000... */ + nc_ctx->k = 1; /* 0.000... */ neg = 0; goto zero_skip; } - duk__dragon4_double_to_ctx(nc_ctx, x); /* -> sets 'f' and 'e' */ + duk__dragon4_double_to_ctx(nc_ctx, x); /* -> sets 'f' and 'e' */ DUK__BI_PRINT("f", &nc_ctx->f); DUK_DDD(DUK_DDDPRINT("e=%ld", (long) nc_ctx->e)); @@ -88580,7 +89915,7 @@ * Dragon4 slow path digit generation. */ - duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ + duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ DUK_DDD(DUK_DDDPRINT("after prepare:")); DUK__BI_PRINT("r", &nc_ctx->r); @@ -88602,7 +89937,7 @@ * Convert and push final string. */ - zero_skip: +zero_skip: if (flags & DUK_N2S_FLAG_FIXED_FORMAT) { /* Perform fixed-format rounding. */ @@ -88611,13 +89946,16 @@ /* 'roundpos' is relative to nc_ctx->k and increases to the right * (opposite of how 'k' changes). */ - roundpos = -digits; /* absolute position for digit considered for rounding */ + roundpos = -digits; /* absolute position for digit considered for rounding */ roundpos = nc_ctx->k - roundpos; } else { roundpos = digits; } DUK_DDD(DUK_DDDPRINT("rounding: k=%ld, count=%ld, digits=%ld, roundpos=%ld", - (long) nc_ctx->k, (long) nc_ctx->count, (long) digits, (long) roundpos)); + (long) nc_ctx->k, + (long) nc_ctx->count, + (long) digits, + (long) roundpos)); (void) duk__dragon4_fixed_format_round(nc_ctx, roundpos); /* Note: 'count' is currently not adjusted by rounding (i.e. the @@ -88646,7 +89984,7 @@ */ DUK_LOCAL DUK_NOINLINE void duk__numconv_parse_raw(duk_hthread *thr, duk_small_int_t radix, duk_small_uint_t flags) { - duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ + duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ duk__numconv_stringify_ctx *nc_ctx = &nc_ctx_alloc; duk_double_t res; duk_hstring *h_str; @@ -88666,7 +90004,8 @@ DUK_DDD(DUK_DDDPRINT("parse number: %!T, radix=%ld, flags=0x%08lx", (duk_tval *) duk_get_tval(thr, -1), - (long) radix, (unsigned long) flags)); + (long) radix, + (unsigned long) flags)); DUK_ASSERT(radix >= 2 && radix <= 36); DUK_ASSERT(radix - 2 < (duk_small_int_t) sizeof(duk__str2num_digits_for_radix)); @@ -88739,7 +90078,7 @@ ch = *p; if (ch == (duk_small_int_t) '0') { duk_small_int_t detect_radix = 0; - ch = DUK_LOWERCASE_CHAR_ASCII(p1); /* 'x' or 'X' -> 'x' */ + ch = DUK_LOWERCASE_CHAR_ASCII(p1); /* 'x' or 'X' -> 'x' */ if ((flags & DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT) && ch == DUK_ASC_LC_X) { DUK_DDD(DUK_DDDPRINT("detected 0x/0X hex prefix, changing radix and preventing fractions and exponent")); detect_radix = 16; @@ -88766,10 +90105,9 @@ if (detect_radix > 0) { radix = detect_radix; /* Clear empty as zero flag: interpret e.g. '0x' and '0xg' as a NaN (= parse error) */ - flags &= ~(DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO); - flags |= DUK_S2N_FLAG_ALLOW_LEADING_ZERO; /* allow e.g. '0x0009' and '0b00010001' */ + flags &= ~(DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_FRAC | + DUK_S2N_FLAG_ALLOW_NAKED_FRAC | DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO); + flags |= DUK_S2N_FLAG_ALLOW_LEADING_ZERO; /* allow e.g. '0x0009' and '0b00010001' */ p += 2; } } @@ -88827,16 +90165,23 @@ dig_frac = -1; dig_expt = -1; expt = 0; - expt_adj = 0; /* essentially tracks digit position of lowest 'f' digit */ + expt_adj = 0; /* essentially tracks digit position of lowest 'f' digit */ expt_neg = 0; for (;;) { ch = *p++; DUK_DDD(DUK_DDDPRINT("parse digits: p=%p, ch='%c' (%ld), expt=%ld, expt_adj=%ld, " "dig_whole=%ld, dig_frac=%ld, dig_expt=%ld, dig_lzero=%ld, dig_prec=%ld", - (const void *) p, (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : '?'), (long) ch, - (long) expt, (long) expt_adj, (long) dig_whole, (long) dig_frac, - (long) dig_expt, (long) dig_lzero, (long) dig_prec)); + (const void *) p, + (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : '?'), + (long) ch, + (long) expt, + (long) expt_adj, + (long) dig_whole, + (long) dig_frac, + (long) dig_expt, + (long) dig_lzero, + (long) dig_prec)); DUK__BI_PRINT("f", &nc_ctx->f); /* Most common cases first. */ @@ -88875,8 +90220,8 @@ } else if (ch == (duk_small_int_t) 0) { DUK_DDD(DUK_DDDPRINT("NUL termination")); break; - } else if ((flags & DUK_S2N_FLAG_ALLOW_EXP) && - dig_expt < 0 && (ch == (duk_small_int_t) 'e' || ch == (duk_small_int_t) 'E')) { + } else if ((flags & DUK_S2N_FLAG_ALLOW_EXP) && dig_expt < 0 && + (ch == (duk_small_int_t) 'e' || ch == (duk_small_int_t) 'E')) { /* Note: we don't parse back exponent notation for anything else * than radix 10, so this is not an ambiguous check (e.g. hex * exponent values may have 'e' either as a significand digit @@ -88906,7 +90251,7 @@ } else if (ch >= (duk_small_int_t) 'A' && ch <= (duk_small_int_t) 'Z') { dig = (duk_small_int_t) (ch - (duk_small_int_t) 'A' + 0x0a); } else { - dig = 255; /* triggers garbage digit check below */ + dig = 255; /* triggers garbage digit check below */ } DUK_ASSERT((dig >= 0 && dig <= 35) || dig == 255); @@ -89039,14 +90384,14 @@ if (expt_neg) { expt = -expt; } - DUK_DDD(DUK_DDDPRINT("expt=%ld, expt_adj=%ld, net exponent -> %ld", - (long) expt, (long) expt_adj, (long) (expt + expt_adj))); + DUK_DDD( + DUK_DDDPRINT("expt=%ld, expt_adj=%ld, net exponent -> %ld", (long) expt, (long) expt_adj, (long) (expt + expt_adj))); expt += expt_adj; /* Fast path check. */ - if (nc_ctx->f.n <= 1 && /* 32-bit value */ - expt == 0 /* no net exponent */) { + if (nc_ctx->f.n <= 1 && /* 32-bit value */ + expt == 0 /* no net exponent */) { /* Fast path is triggered for no exponent and also for balanced exponent * and fraction parts, e.g. for "1.23e2" == "123". Remember to respect * zero sign. @@ -89088,7 +90433,6 @@ goto negcheck_and_ret; } - /* Quick reject of too large or too small exponents. This check * would be incorrect for zero (e.g. "0e1000" is zero, not Infinity) * so zero check must be above. @@ -89121,7 +90465,7 @@ * An extra digit is generated for rounding. */ - duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ + duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ DUK_DDD(DUK_DDDPRINT("after prepare:")); DUK__BI_PRINT("r", &nc_ctx->r); @@ -89153,7 +90497,7 @@ duk__dragon4_ctx_to_double(nc_ctx, &res); goto negcheck_and_ret; - negcheck_and_ret: +negcheck_and_ret: if (neg) { res = -res; } @@ -89162,13 +90506,13 @@ DUK_DDD(DUK_DDDPRINT("result: %!T", (duk_tval *) duk_get_tval(thr, -1))); return; - parse_fail: +parse_fail: DUK_DDD(DUK_DDDPRINT("parse failed")); duk_pop(thr); duk_push_nan(thr); return; - parse_explimit_error: +parse_explimit_error: DUK_DDD(DUK_DDDPRINT("parse failed, internal error, can't return a value")); DUK_ERROR_RANGE(thr, "exponent too large"); DUK_WO_NORETURN(return;); @@ -89221,8 +90565,7 @@ #define DUK__RE_INITIAL_BUFSIZE 64 -#define DUK__RE_BUFLEN(re_ctx) \ - DUK_BW_GET_SIZE(re_ctx->thr, &re_ctx->bw) +#define DUK__RE_BUFLEN(re_ctx) DUK_BW_GET_SIZE(re_ctx->thr, &re_ctx->bw) /* * Disjunction struct: result of parsing a disjunction @@ -89312,7 +90655,7 @@ (void) duk__append_7bit(re_ctx, reop); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__append_i32(duk_re_compiler_ctx *re_ctx, duk_int32_t x) { duk__append_u32(re_ctx, duk__encode_i32(x)); } @@ -89326,7 +90669,10 @@ } } -DUK_LOCAL void duk__insert_slice(duk_re_compiler_ctx *re_ctx, duk_uint32_t offset, duk_uint32_t data_offset, duk_uint32_t data_length) { +DUK_LOCAL void duk__insert_slice(duk_re_compiler_ctx *re_ctx, + duk_uint32_t offset, + duk_uint32_t data_offset, + duk_uint32_t data_length) { DUK_BW_INSERT_ENSURE_SLICE(re_ctx->thr, &re_ctx->bw, offset, data_offset, data_length); } @@ -89389,7 +90735,7 @@ skip--; } } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* Closed form solution, this produces fastest code. * See re_neg_jump_offset (closed1). */ @@ -89410,7 +90756,7 @@ skip -= 7; } } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ return duk__insert_i32(re_ctx, offset, skip); } @@ -89543,10 +90889,10 @@ } } } - DUK_ASSERT(blk == end_blk + 1); /* Reached end block which is continuous. */ + DUK_ASSERT(blk == end_blk + 1); /* Reached end block which is continuous. */ return end; } -#else /* DUK_USE_REGEXP_CANON_BITMAP */ +#else /* DUK_USE_REGEXP_CANON_BITMAP */ DUK_LOCAL duk_codepoint_t duk__re_canon_next_discontinuity(duk_codepoint_t start, duk_codepoint_t end) { DUK_ASSERT(start >= 0); DUK_ASSERT(end >= 0); @@ -89557,7 +90903,7 @@ } return start; } -#endif /* DUK_USE_REGEXP_CANON_BITMAP */ +#endif /* DUK_USE_REGEXP_CANON_BITMAP */ DUK_LOCAL void duk__regexp_generate_ranges(void *userdata, duk_codepoint_t r1, duk_codepoint_t r2, duk_bool_t direct) { duk_re_compiler_ctx *re_ctx = (duk_re_compiler_ctx *) userdata; @@ -89568,9 +90914,12 @@ duk_codepoint_t r_disc; DUK_DD(DUK_DDPRINT("duk__regexp_generate_ranges(): re_ctx=%p, range=%ld,%ld direct=%ld", - (void *) re_ctx, (long) r1, (long) r2, (long) direct)); + (void *) re_ctx, + (long) r1, + (long) r2, + (long) direct)); - DUK_ASSERT(r2 >= r1); /* SyntaxError for out of order range. */ + DUK_ASSERT(r2 >= r1); /* SyntaxError for out of order range. */ if (direct || (re_ctx->re_flags & DUK_RE_FLAG_IGNORE_CASE) == 0) { DUK_DD(DUK_DDPRINT("direct or not case sensitive, emit range: %ld,%ld", (long) r1, (long) r2)); @@ -89592,7 +90941,7 @@ DUK_ASSERT(r_disc >= i); DUK_ASSERT(r_disc <= r2); - r_end += r_disc - i; /* May be zero. */ + r_end += r_disc - i; /* May be zero. */ t = duk_unicode_re_canonicalize_char(re_ctx->thr, r_disc); if (t == r_end + 1) { /* Not actually a discontinuity, continue range @@ -89604,11 +90953,11 @@ r_start = t; r_end = t; } - i = r_disc + 1; /* Guarantees progress. */ + i = r_disc + 1; /* Guarantees progress. */ } duk__regexp_emit_range(re_ctx, r_start, r_end); -#if 0 /* Exhaustive search, very slow. */ +#if 0 /* Exhaustive search, very slow. */ r_start = duk_unicode_re_canonicalize_char(re_ctx->thr, r1); r_end = r_start; for (i = r1 + 1; i <= r2; i++) { @@ -89681,18 +91030,17 @@ * as complex though. */ -DUK_LOCAL const duk_uint16_t * const duk__re_range_lookup13 = { - duk_unicode_re_ranges_digit, - duk_unicode_re_ranges_white, - duk_unicode_re_ranges_wordchar -}; -DUK_LOCAL const duk_uint8_t duk__re_range_lookup23 = { - sizeof(duk_unicode_re_ranges_digit) / (2 * sizeof(duk_uint16_t)), - sizeof(duk_unicode_re_ranges_white) / (2 * sizeof(duk_uint16_t)), - sizeof(duk_unicode_re_ranges_wordchar) / (2 * sizeof(duk_uint16_t)) -}; - -DUK_LOCAL void duk__append_range_atom_matcher(duk_re_compiler_ctx *re_ctx, duk_small_uint_t re_op, const duk_uint16_t *ranges, duk_small_uint_t count) { +DUK_LOCAL const duk_uint16_t * const duk__re_range_lookup13 = { duk_unicode_re_ranges_digit, + duk_unicode_re_ranges_white, + duk_unicode_re_ranges_wordchar }; +DUK_LOCAL const duk_uint8_t duk__re_range_lookup23 = { sizeof(duk_unicode_re_ranges_digit) / (2 * sizeof(duk_uint16_t)), + sizeof(duk_unicode_re_ranges_white) / (2 * sizeof(duk_uint16_t)), + sizeof(duk_unicode_re_ranges_wordchar) / (2 * sizeof(duk_uint16_t)) }; + +DUK_LOCAL void duk__append_range_atom_matcher(duk_re_compiler_ctx *re_ctx, + duk_small_uint_t re_op, + const duk_uint16_t *ranges, + duk_small_uint_t count) { #if 0 DUK_ASSERT(re_op <= 0x7fUL); DUK_ASSERT(count <= 0x7fUL); @@ -89704,13 +91052,13 @@ } DUK_LOCAL void duk__parse_disjunction(duk_re_compiler_ctx *re_ctx, duk_bool_t expect_eof, duk__re_disjunction_info *out_atom_info) { - duk_int32_t atom_start_offset = -1; /* negative -> no atom matched on previous round */ - duk_int32_t atom_char_length = 0; /* negative -> complex atom */ - duk_uint32_t atom_start_captures = re_ctx->captures; /* value of re_ctx->captures at start of atom */ + duk_int32_t atom_start_offset = -1; /* negative -> no atom matched on previous round */ + duk_int32_t atom_char_length = 0; /* negative -> complex atom */ + duk_uint32_t atom_start_captures = re_ctx->captures; /* value of re_ctx->captures at start of atom */ duk_int32_t unpatched_disjunction_split = -1; duk_int32_t unpatched_disjunction_jump = -1; duk_uint32_t entry_offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); - duk_int32_t res_charlen = 0; /* -1 if disjunction is complex, char length if simple */ + duk_int32_t res_charlen = 0; /* -1 if disjunction is complex, char length if simple */ duk__re_disjunction_info tmp_disj; DUK_ASSERT(out_atom_info != NULL); @@ -89733,19 +91081,19 @@ * new_atom_char_length etc are for the atom parsed on this round; * they're written to atom_char_length etc at the end of the round. */ - duk_int32_t new_atom_char_length; /* char length of the atom parsed in this loop */ - duk_int32_t new_atom_start_offset; /* bytecode start offset of the atom parsed in this loop - * (allows quantifiers to copy the atom bytecode) - */ - duk_uint32_t new_atom_start_captures; /* re_ctx->captures at the start of the atom parsed in this loop */ + duk_int32_t new_atom_char_length; /* char length of the atom parsed in this loop */ + duk_int32_t new_atom_start_offset; /* bytecode start offset of the atom parsed in this loop + * (allows quantifiers to copy the atom bytecode) + */ + duk_uint32_t new_atom_start_captures; /* re_ctx->captures at the start of the atom parsed in this loop */ duk_lexer_parse_re_token(&re_ctx->lex, &re_ctx->curr_token); - DUK_DD(DUK_DDPRINT("re token: %ld (num=%ld, char=%c)", - (long) re_ctx->curr_token.t, - (long) re_ctx->curr_token.num, - (re_ctx->curr_token.num >= 0x20 && re_ctx->curr_token.num <= 0x7e) ? - (int) re_ctx->curr_token.num : (int) '?')); + DUK_DD(DUK_DDPRINT( + "re token: %ld (num=%ld, char=%c)", + (long) re_ctx->curr_token.t, + (long) re_ctx->curr_token.num, + (re_ctx->curr_token.num >= 0x20 && re_ctx->curr_token.num <= 0x7e) ? (int) re_ctx->curr_token.num : (int) '?')); /* set by atom case clauses */ new_atom_start_offset = -1; @@ -89766,9 +91114,7 @@ DUK_ASSERT(unpatched_disjunction_split >= 0); offset = (duk_uint32_t) unpatched_disjunction_jump; - offset += duk__insert_jump_offset(re_ctx, - offset, - (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); + offset += duk__insert_jump_offset(re_ctx, offset, (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); /* offset is now target of the pending split (right after jump) */ duk__insert_jump_offset(re_ctx, (duk_uint32_t) unpatched_disjunction_split, @@ -89776,10 +91122,8 @@ } /* add a new pending split to the beginning of the entire disjunction */ - (void) duk__insert_u32(re_ctx, - entry_offset, - DUK_REOP_SPLIT1); /* prefer direct execution */ - unpatched_disjunction_split = (duk_int32_t) (entry_offset + 1); /* +1 for opcode */ + (void) duk__insert_u32(re_ctx, entry_offset, DUK_REOP_SPLIT1); /* prefer direct execution */ + unpatched_disjunction_split = (duk_int32_t) (entry_offset + 1); /* +1 for opcode */ /* add a new pending match jump for latest finished alternative */ duk__append_reop(re_ctx, DUK_REOP_JUMP); @@ -89827,7 +91171,7 @@ } } - duk__append_reop(re_ctx, DUK_REOP_MATCH); /* complete 'sub atom' */ + duk__append_reop(re_ctx, DUK_REOP_MATCH); /* complete 'sub atom' */ atom_code_length = (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (duk_size_t) atom_start_offset); offset = (duk_uint32_t) atom_start_offset; @@ -89843,7 +91187,7 @@ offset += duk__insert_u32(re_ctx, offset, qmax); offset += duk__insert_jump_offset(re_ctx, offset, atom_code_length); } - DUK_UNREF(offset); /* silence scan-build warning */ + DUK_UNREF(offset); /* silence scan-build warning */ } else { /* * Complex atom @@ -89861,8 +91205,8 @@ duk_uint32_t tmp_qmin, tmp_qmax; /* pre-check how many atom copies we're willing to make (atom_copies not needed below) */ - atom_copies = (re_ctx->curr_token.qmax == DUK_RE_QUANTIFIER_INFINITE) ? - re_ctx->curr_token.qmin : re_ctx->curr_token.qmax; + atom_copies = (re_ctx->curr_token.qmax == DUK_RE_QUANTIFIER_INFINITE) ? re_ctx->curr_token.qmin : + re_ctx->curr_token.qmax; if (atom_copies > DUK_RE_MAX_ATOM_COPIES) { DUK_ERROR_RANGE(re_ctx->thr, DUK_STR_QUANTIFIER_TOO_MANY_COPIES); DUK_WO_NORETURN(return;); @@ -89873,15 +91217,19 @@ if (atom_start_captures != re_ctx->captures) { DUK_ASSERT(atom_start_captures < re_ctx->captures); DUK_DDD(DUK_DDDPRINT("must wipe atom_start_captures,re_ctx->captures: %ld,%ld", - (long) atom_start_captures, (long) re_ctx->captures)); + (long) atom_start_captures, + (long) re_ctx->captures)); /* insert (DUK_REOP_WIPERANGE, start, count) in reverse order so the order ends up right */ - duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, (re_ctx->captures - atom_start_captures) * 2U); + duk__insert_u32(re_ctx, + (duk_uint32_t) atom_start_offset, + (re_ctx->captures - atom_start_captures) * 2U); duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, (atom_start_captures + 1) * 2); duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, DUK_REOP_WIPERANGE); } else { - DUK_DDD(DUK_DDDPRINT("no need to wipe captures: atom_start_captures == re_ctx->captures == %ld", - (long) atom_start_captures)); + DUK_DDD( + DUK_DDDPRINT("no need to wipe captures: atom_start_captures == re_ctx->captures == %ld", + (long) atom_start_captures)); } atom_code_length = (duk_int32_t) DUK__RE_BUFLEN(re_ctx) - atom_start_offset; @@ -89890,7 +91238,9 @@ tmp_qmin = re_ctx->curr_token.qmin; tmp_qmax = re_ctx->curr_token.qmax; while (tmp_qmin > 0) { - duk__append_slice(re_ctx, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__append_slice(re_ctx, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); tmp_qmin--; if (tmp_qmax != DUK_RE_QUANTIFIER_INFINITE) { tmp_qmax--; @@ -89908,14 +91258,16 @@ */ duk__append_reop(re_ctx, DUK_REOP_JUMP); duk__append_jump_offset(re_ctx, atom_code_length); - duk__append_slice(re_ctx, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__append_slice(re_ctx, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); } if (re_ctx->curr_token.greedy) { - duk__append_reop(re_ctx, DUK_REOP_SPLIT2); /* prefer jump */ + duk__append_reop(re_ctx, DUK_REOP_SPLIT2); /* prefer jump */ } else { - duk__append_reop(re_ctx, DUK_REOP_SPLIT1); /* prefer direct */ + duk__append_reop(re_ctx, DUK_REOP_SPLIT1); /* prefer direct */ } - duk__append_jump_offset(re_ctx, -atom_code_length - 1); /* -1 for opcode */ + duk__append_jump_offset(re_ctx, -atom_code_length - 1); /* -1 for opcode */ } else { /* * The remaining matches are emitted as sequence of SPLITs and atom @@ -89935,14 +91287,17 @@ */ duk_uint32_t offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); while (tmp_qmax > 0) { - duk__insert_slice(re_ctx, offset, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__insert_slice(re_ctx, + offset, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); if (re_ctx->curr_token.greedy) { - duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT1); /* prefer direct */ + duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT1); /* prefer direct */ } else { - duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT2); /* prefer jump */ + duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT2); /* prefer jump */ } duk__insert_jump_offset(re_ctx, - offset + 1, /* +1 for opcode */ + offset + 1, /* +1 for opcode */ (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (offset + 1))); tmp_qmax--; } @@ -89975,8 +91330,8 @@ case DUK_RETOK_ASSERT_START_POS_LOOKAHEAD: case DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD: { duk_uint32_t offset; - duk_uint32_t opcode = (re_ctx->curr_token.t == DUK_RETOK_ASSERT_START_POS_LOOKAHEAD) ? - DUK_REOP_LOOKPOS : DUK_REOP_LOOKNEG; + duk_uint32_t opcode = + (re_ctx->curr_token.t == DUK_RETOK_ASSERT_START_POS_LOOKAHEAD) ? DUK_REOP_LOOKPOS : DUK_REOP_LOOKNEG; offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); duk__parse_disjunction(re_ctx, 0, &tmp_disj); @@ -89984,7 +91339,7 @@ (void) duk__insert_u32(re_ctx, offset, opcode); (void) duk__insert_jump_offset(re_ctx, - offset + 1, /* +1 for opcode */ + offset + 1, /* +1 for opcode */ (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (offset + 1))); /* 'taint' result as complex -- this is conservative, @@ -90045,7 +91400,7 @@ DUK_ASSERT(DUK_RETOK_ATOM_WHITE == DUK_RETOK_ATOM_DIGIT + 2); DUK_ASSERT(DUK_RETOK_ATOM_WORD_CHAR == DUK_RETOK_ATOM_DIGIT + 4); idx = (duk_small_uint_t) ((re_ctx->curr_token.t - DUK_RETOK_ATOM_DIGIT) >> 1U); - DUK_ASSERT(idx <= 2U); /* Assume continuous token numbers; also checks negative underflow. */ + DUK_ASSERT(idx <= 2U); /* Assume continuous token numbers; also checks negative underflow. */ duk__append_range_atom_matcher(re_ctx, re_op, duk__re_range_lookup1idx, duk__re_range_lookup2idx); break; @@ -90055,7 +91410,7 @@ if (backref > re_ctx->highest_backref) { re_ctx->highest_backref = backref; } - new_atom_char_length = -1; /* mark as complex */ + new_atom_char_length = -1; /* mark as complex */ new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); duk__append_reop(re_ctx, DUK_REOP_BACKREFERENCE); duk__append_u32(re_ctx, backref); @@ -90064,12 +91419,14 @@ case DUK_RETOK_ATOM_START_CAPTURE_GROUP: { duk_uint32_t cap; - new_atom_char_length = -1; /* mark as complex (capture handling) */ + new_atom_char_length = -1; /* mark as complex (capture handling) */ new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); cap = ++re_ctx->captures; duk__append_reop(re_ctx, DUK_REOP_SAVE); duk__append_u32(re_ctx, cap * 2); - duk__parse_disjunction(re_ctx, 0, &tmp_disj); /* retval (sub-atom char length) unused, tainted as complex above */ + duk__parse_disjunction(re_ctx, + 0, + &tmp_disj); /* retval (sub-atom char length) unused, tainted as complex above */ duk__append_reop(re_ctx, DUK_REOP_SAVE); duk__append_u32(re_ctx, cap * 2 + 1); break; @@ -90114,12 +91471,12 @@ new_atom_char_length = 1; new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); duk__append_reop(re_ctx, - (re_ctx->curr_token.t == DUK_RETOK_ATOM_START_CHARCLASS) ? - DUK_REOP_RANGES : DUK_REOP_INVRANGES); - offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); /* patch in range count later */ + (re_ctx->curr_token.t == DUK_RETOK_ATOM_START_CHARCLASS) ? DUK_REOP_RANGES : + DUK_REOP_INVRANGES); + offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); /* patch in range count later */ /* parse ranges until character class ends */ - re_ctx->nranges = 0; /* note: ctx-wide temporary */ + re_ctx->nranges = 0; /* note: ctx-wide temporary */ duk_lexer_parse_re_ranges(&re_ctx->lex, duk__regexp_generate_ranges, (void *) re_ctx); /* insert range count */ @@ -90162,7 +91519,7 @@ atom_start_captures = new_atom_start_captures; } - done: +done: /* finish up pending jump and split for last alternative */ if (unpatched_disjunction_jump >= 0) { @@ -90170,9 +91527,7 @@ DUK_ASSERT(unpatched_disjunction_split >= 0); offset = (duk_uint32_t) unpatched_disjunction_jump; - offset += duk__insert_jump_offset(re_ctx, - offset, - (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); + offset += duk__insert_jump_offset(re_ctx, offset, (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); /* offset is now target of the pending split (right after jump) */ duk__insert_jump_offset(re_ctx, (duk_uint32_t) unpatched_disjunction_split, @@ -90183,8 +91538,7 @@ out_atom_info->end_captures = re_ctx->captures; #endif out_atom_info->charlen = res_charlen; - DUK_DDD(DUK_DDDPRINT("parse disjunction finished: charlen=%ld", - (long) out_atom_info->charlen)); + DUK_DDD(DUK_DDDPRINT("parse disjunction finished: charlen=%ld", (long) out_atom_info->charlen)); re_ctx->recursion_depth--; } @@ -90235,7 +91589,7 @@ return flags; - flags_error: +flags_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_REGEXP_FLAGS); DUK_WO_NORETURN(return 0U;); } @@ -90301,7 +91655,7 @@ } DUK_BW_SETPTR_AND_COMPACT(thr, bw, q); - (void) duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ /* ... escaped_source */ } @@ -90355,7 +91709,7 @@ /* ... pattern flags escaped_source buffer */ duk_memzero(&re_ctx, sizeof(re_ctx)); - DUK_LEXER_INITCTX(&re_ctx.lex); /* duplicate zeroing, expect for (possible) NULL inits */ + DUK_LEXER_INITCTX(&re_ctx.lex); /* duplicate zeroing, expect for (possible) NULL inits */ re_ctx.thr = thr; re_ctx.lex.thr = thr; re_ctx.lex.input = DUK_HSTRING_GET_DATA(h_pattern); @@ -90367,13 +91721,14 @@ DUK_BW_INIT_PUSHBUF(thr, &re_ctx.bw, DUK__RE_INITIAL_BUFSIZE); DUK_DD(DUK_DDPRINT("regexp compiler ctx initialized, flags=0x%08lx, recursion_limit=%ld", - (unsigned long) re_ctx.re_flags, (long) re_ctx.recursion_limit)); + (unsigned long) re_ctx.re_flags, + (long) re_ctx.recursion_limit)); /* * Init lexer */ - lex_point.offset = 0; /* expensive init, just want to fill window */ + lex_point.offset = 0; /* expensive init, just want to fill window */ lex_point.line = 1; DUK_LEXER_SETPOINT(&re_ctx.lex, &lex_point); @@ -90415,7 +91770,7 @@ /* ... pattern flags escaped_source buffer */ DUK_BW_COMPACT(thr, &re_ctx.bw); - (void) duk_buffer_to_string(thr, -1); /* Safe because flags is at most 7 bit. */ + (void) duk_buffer_to_string(thr, -1); /* Safe because flags is at most 7 bit. */ /* ... pattern flags escaped_source bytecode */ @@ -90423,11 +91778,12 @@ * Finalize stack */ - duk_remove(thr, -4); /* -> ... flags escaped_source bytecode */ - duk_remove(thr, -3); /* -> ... escaped_source bytecode */ + duk_remove(thr, -4); /* -> ... flags escaped_source bytecode */ + duk_remove(thr, -3); /* -> ... escaped_source bytecode */ DUK_DD(DUK_DDPRINT("regexp compilation successful, bytecode: %!T, escaped source: %!T", - (duk_tval *) duk_get_tval(thr, -1), (duk_tval *) duk_get_tval(thr, -2))); + (duk_tval *) duk_get_tval(thr, -1), + (duk_tval *) duk_get_tval(thr, -2))); } /* @@ -90473,11 +91829,11 @@ /* ... regexp_object */ } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ /* regexp support disabled */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* automatic undefs */ #undef DUK__RE_BUFLEN @@ -90525,7 +91881,11 @@ } } -DUK_LOCAL const duk_uint8_t *duk__utf8_backtrack(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_uint_fast32_t count) { +DUK_LOCAL const duk_uint8_t *duk__utf8_backtrack(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_uint_fast32_t count) { const duk_uint8_t *p; /* Note: allow backtracking from p == ptr_end */ @@ -90550,12 +91910,16 @@ *ptr = p; return p; - fail: +fail: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return NULL;); } -DUK_LOCAL const duk_uint8_t *duk__utf8_advance(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_uint_fast32_t count) { +DUK_LOCAL const duk_uint8_t *duk__utf8_advance(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_uint_fast32_t count) { const duk_uint8_t *p; p = *ptr; @@ -90581,7 +91945,7 @@ *ptr = p; return p; - fail: +fail: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return NULL;); } @@ -90685,7 +92049,7 @@ c1 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); DUK_ASSERT(!(re_ctx->re_flags & DUK_RE_FLAG_IGNORE_CASE) || - c1 == duk_unicode_re_canonicalize_char(re_ctx->thr, c1)); /* canonicalized by compiler */ + c1 == duk_unicode_re_canonicalize_char(re_ctx->thr, c1)); /* canonicalized by compiler */ c2 = duk__inp_get_cp(re_ctx, &sp); /* No need to check for c2 < 0 (end of input): because c1 >= 0, it * will fail the match below automatically and cause goto fail. @@ -90731,7 +92095,10 @@ r1 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); r2 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("matching ranges/invranges, n=%ld, r1=%ld, r2=%ld, c=%ld", - (long) n, (long) r1, (long) r2, (long) c)); + (long) n, + (long) r1, + (long) r2, + (long) c)); if (c >= r1 && c <= r2) { /* Note: don't bail out early, we must read all the ranges from * bytecode. Another option is to skip them efficiently after @@ -90800,16 +92167,16 @@ duk_small_int_t w1, w2; if (sp <= re_ctx->input) { - w1 = 0; /* not a wordchar */ + w1 = 0; /* not a wordchar */ } else { duk_codepoint_t c; c = duk__inp_get_prev_cp(re_ctx, sp); w1 = duk_unicode_re_is_wordchar(c); } if (sp >= re_ctx->input_end) { - w2 = 0; /* not a wordchar */ + w2 = 0; /* not a wordchar */ } else { - const duk_uint8_t *tmp_sp = sp; /* dummy so sp won't get updated */ + const duk_uint8_t *tmp_sp = sp; /* dummy so sp won't get updated */ duk_codepoint_t c; c = duk__inp_get_cp(re_ctx, &tmp_sp); w2 = duk_unicode_re_is_wordchar(c); @@ -90870,7 +92237,9 @@ qmax = duk__bc_get_u32(re_ctx, &pc); skip = duk__bc_get_i32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("minimal quantifier, qmin=%lu, qmax=%lu, skip=%ld", - (unsigned long) qmin, (unsigned long) qmax, (long) skip)); + (unsigned long) qmin, + (unsigned long) qmax, + (long) skip)); q = 0; while (q <= qmax) { @@ -90900,7 +92269,10 @@ atomlen = duk__bc_get_u32(re_ctx, &pc); skip = duk__bc_get_i32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("greedy quantifier, qmin=%lu, qmax=%lu, atomlen=%lu, skip=%ld", - (unsigned long) qmin, (unsigned long) qmax, (unsigned long) atomlen, (long) skip)); + (unsigned long) qmin, + (unsigned long) qmax, + (unsigned long) atomlen, + (long) skip)); q = 0; while (q < qmax) { @@ -90926,8 +92298,7 @@ * do not allow captures in their atom now, so this is not an issue. */ - DUK_DDD(DUK_DDDPRINT("greedy quantifier, backtrack %ld characters (atomlen)", - (long) atomlen)); + DUK_DDD(DUK_DDDPRINT("greedy quantifier, backtrack %ld characters (atomlen)", (long) atomlen)); sp = duk__inp_backtrack(re_ctx, &sp, (duk_uint_fast32_t) atomlen); q--; } @@ -90973,20 +92344,23 @@ idx_start = duk__bc_get_u32(re_ctx, &pc); idx_count = duk__bc_get_u32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("wipe saved range: start=%ld, count=%ld -> %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) idx_count, - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) idx_count, + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); if (idx_start + idx_count > re_ctx->nsaved || idx_count == 0) { /* idx is unsigned, < 0 check is not necessary */ DUK_D(DUK_DPRINT("internal error, regexp wipe indices insane: idx_start=%ld, idx_count=%ld", - (long) idx_start, (long) idx_count)); + (long) idx_start, + (long) idx_count)); goto internal_error; } DUK_ASSERT(idx_count > 0); duk_require_stack(re_ctx->thr, 1); - range_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, - sizeof(duk_uint8_t *) * idx_count); + range_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, sizeof(duk_uint8_t *) * idx_count); DUK_ASSERT(range_save != NULL); duk_memcpy(range_save, re_ctx->saved + idx_start, sizeof(duk_uint8_t *) * idx_count); #if defined(DUK_USE_EXPLICIT_NULL_INIT) @@ -91002,8 +92376,10 @@ if (sub_sp) { /* match: keep wiped/resaved values */ DUK_DDD(DUK_DDDPRINT("match: keep wiped/resaved values %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); duk_pop_unsafe(re_ctx->thr); sp = sub_sp; goto match; @@ -91011,8 +92387,10 @@ /* fail: restore saves */ DUK_DDD(DUK_DDDPRINT("fail: restore wiped/resaved values %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); duk_memcpy((void *) (re_ctx->saved + idx_start), (const void *) range_save, sizeof(duk_uint8_t *) * idx_count); @@ -91042,8 +92420,8 @@ DUK_ASSERT(re_ctx->nsaved > 0); duk_require_stack(re_ctx->thr, 1); - full_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, - sizeof(duk_uint8_t *) * re_ctx->nsaved); + full_save = + (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, sizeof(duk_uint8_t *) * re_ctx->nsaved); DUK_ASSERT(full_save != NULL); duk_memcpy(full_save, re_ctx->saved, sizeof(duk_uint8_t *) * re_ctx->nsaved); @@ -91068,11 +92446,9 @@ /* fall through */ - lookahead_fail: + lookahead_fail: /* fail: restore saves */ - duk_memcpy((void *) re_ctx->saved, - (const void *) full_save, - sizeof(duk_uint8_t *) * re_ctx->nsaved); + duk_memcpy((void *) re_ctx->saved, (const void *) full_save, sizeof(duk_uint8_t *) * re_ctx->nsaved); duk_pop_unsafe(re_ctx->thr); goto fail; } @@ -91095,22 +92471,23 @@ const duk_uint8_t *p; idx = duk__bc_get_u32(re_ctx, &pc); - idx = idx << 1; /* backref n -> saved indices n*2, n*2+1 */ + idx = idx << 1; /* backref n -> saved indices n*2, n*2+1 */ if (idx < 2 || idx + 1 >= re_ctx->nsaved) { /* regexp compiler should catch these */ DUK_D(DUK_DPRINT("internal error, backreference index insane")); goto internal_error; } - if (!re_ctx->savedidx || !re_ctx->savedidx+1) { + if (!re_ctx->savedidx || !re_ctx->savedidx + 1) { /* capture is 'undefined', always matches! */ DUK_DDD(DUK_DDDPRINT("backreference: saved%ld,%ld not complete, always match", - (long) idx, (long) (idx + 1))); + (long) idx, + (long) (idx + 1))); break; } DUK_DDD(DUK_DDDPRINT("backreference: match saved%ld,%ld", (long) idx, (long) (idx + 1))); p = re_ctx->savedidx; - while (p < re_ctx->savedidx+1) { + while (p < re_ctx->savedidx + 1) { duk_codepoint_t c1, c2; /* Note: not necessary to check p against re_ctx->input_end: @@ -91142,15 +92519,15 @@ } } - match: +match: re_ctx->recursion_depth--; return sp; - fail: +fail: re_ctx->recursion_depth--; return NULL; - internal_error: +internal_error: DUK_ERROR_INTERNAL(re_ctx->thr); DUK_WO_NORETURN(return NULL;); } @@ -91202,8 +92579,9 @@ h_input = duk_to_hstring(thr, -1); DUK_ASSERT(h_input != NULL); - duk_xget_owndataprop_stridx_short(thr, -2, DUK_STRIDX_INT_BYTECODE); /* ... re_obj input -> ... re_obj input bc */ - h_bytecode = duk_require_hstring(thr, -1); /* no regexp instance should exist without a non-configurable bytecode property */ + duk_xget_owndataprop_stridx_short(thr, -2, DUK_STRIDX_INT_BYTECODE); /* ... re_obj input -> ... re_obj input bc */ + h_bytecode = + duk_require_hstring(thr, -1); /* no regexp instance should exist without a non-configurable bytecode property */ DUK_ASSERT(h_bytecode != NULL); /* @@ -91235,13 +92613,13 @@ re_ctx.nsaved = duk__bc_get_u32(&re_ctx, &pc); re_ctx.bytecode = pc; - DUK_ASSERT(DUK_RE_FLAG_GLOBAL < 0x10000UL); /* must fit into duk_small_int_t */ + DUK_ASSERT(DUK_RE_FLAG_GLOBAL < 0x10000UL); /* must fit into duk_small_int_t */ global = (duk_small_int_t) (force_global | (duk_small_int_t) (re_ctx.re_flags & DUK_RE_FLAG_GLOBAL)); DUK_ASSERT(re_ctx.nsaved >= 2); DUK_ASSERT((re_ctx.nsaved % 2) == 0); - p_buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, sizeof(duk_uint8_t *) * re_ctx.nsaved); /* rely on zeroing */ + p_buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, sizeof(duk_uint8_t *) * re_ctx.nsaved); /* rely on zeroing */ DUK_UNREF(p_buf); re_ctx.saved = (const duk_uint8_t **) duk_get_buffer(thr, -1, NULL); DUK_ASSERT(re_ctx.saved != NULL); @@ -91259,7 +92637,9 @@ #endif DUK_DDD(DUK_DDDPRINT("regexp ctx initialized, flags=0x%08lx, nsaved=%ld, recursion_limit=%ld, steps_limit=%ld", - (unsigned long) re_ctx.re_flags, (long) re_ctx.nsaved, (long) re_ctx.recursion_limit, + (unsigned long) re_ctx.re_flags, + (long) re_ctx.nsaved, + (long) re_ctx.recursion_limit, (long) re_ctx.steps_limit)); /* @@ -91281,15 +92661,15 @@ /* ... re_obj input bc saved_buf */ - duk_get_prop_stridx_short(thr, -4, DUK_STRIDX_LAST_INDEX); /* -> ... re_obj input bc saved_buf lastIndex */ - (void) duk_to_int(thr, -1); /* ToInteger(lastIndex) */ - d = duk_get_number(thr, -1); /* integer, but may be +/- Infinite, +/- zero (not NaN, though) */ + duk_get_prop_stridx_short(thr, -4, DUK_STRIDX_LAST_INDEX); /* -> ... re_obj input bc saved_buf lastIndex */ + (void) duk_to_int(thr, -1); /* ToInteger(lastIndex) */ + d = duk_get_number(thr, -1); /* integer, but may be +/- Infinite, +/- zero (not NaN, though) */ duk_pop_nodecref_unsafe(thr); if (global) { if (d < 0.0 || d > (double) DUK_HSTRING_GET_CHARLEN(h_input)) { /* match fail */ - char_offset = 0; /* not really necessary */ + char_offset = 0; /* not really necessary */ DUK_ASSERT(match == 0); goto match_over; } @@ -91325,8 +92705,10 @@ DUK_ASSERT(re_ctx.recursion_depth == 0); DUK_DDD(DUK_DDDPRINT("attempt match at char offset %ld; %p %p,%p", - (long) char_offset, (const void *) sp, - (const void *) re_ctx.input, (const void *) re_ctx.input_end)); + (long) char_offset, + (const void *) sp, + (const void *) re_ctx.input, + (const void *) re_ctx.input_end)); /* * Note: @@ -91373,7 +92755,7 @@ (void) duk__utf8_advance(thr, &sp, re_ctx.input, re_ctx.input_end, (duk_uint_fast32_t) 1); } - match_over: +match_over: /* * Matching complete, create result array or return a 'null'. Update lastIndex @@ -91399,8 +92781,8 @@ DUK_DDD(DUK_DDDPRINT("regexp matches at char_offset %ld", (long) char_offset)); - DUK_ASSERT(re_ctx.nsaved >= 2); /* must have start and end */ - DUK_ASSERT((re_ctx.nsaved % 2) == 0); /* and even number */ + DUK_ASSERT(re_ctx.nsaved >= 2); /* must have start and end */ + DUK_ASSERT((re_ctx.nsaved % 2) == 0); /* and even number */ /* XXX: Array size is known before and (2 * re_ctx.nsaved) but not taken * advantage of now. The array is not compacted either, as regexp match @@ -91441,7 +92823,7 @@ * will be zero). Also assumes clen reflects the * correct char length. */ - char_end_offset = char_offset + (duk_uint32_t) duk_get_length(thr, -1); /* add charlen */ + char_end_offset = char_offset + (duk_uint32_t) duk_get_length(thr, -1); /* add charlen */ } } else { duk_push_undefined(thr); @@ -91506,11 +92888,11 @@ duk__regexp_match_helper(thr, 1 /*force_global*/); } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ /* regexp support disabled */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* * Self tests to ensure execution environment is sane. Intended to catch * compiler/platform problems which cannot be detected at compile time. @@ -91530,18 +92912,21 @@ } duk__test_double_union; /* Self test failed. Expects a local variable 'error_count' to exist. */ -#define DUK__FAILED(msg) do { \ +#define DUK__FAILED(msg) \ + do { \ DUK_D(DUK_DPRINT("self test failed: " #msg " at " DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO))); \ error_count++; \ } while (0) -#define DUK__DBLUNION_CMP_TRUE(a,b) do { \ +#define DUK__DBLUNION_CMP_TRUE(a, b) \ + do { \ if (duk_memcmp((const void *) (a), (const void *) (b), sizeof(duk__test_double_union)) != 0) { \ DUK__FAILED("double union compares false (expected true)"); \ } \ } while (0) -#define DUK__DBLUNION_CMP_FALSE(a,b) do { \ +#define DUK__DBLUNION_CMP_FALSE(a, b) \ + do { \ if (duk_memcmp((const void *) (a), (const void *) (b), sizeof(duk__test_double_union)) == 0) { \ DUK__FAILED("double union compares true (expected false)"); \ } \ @@ -91553,43 +92938,72 @@ } duk__test_u32_union; #if defined(DUK_USE_INTEGER_LE) -#define DUK__U32_INIT(u, a, b, c, d) do { \ - (u)->x0 = (d); (u)->x1 = (c); (u)->x2 = (b); (u)->x3 = (a); \ +#define DUK__U32_INIT(u, a, b, c, d) \ + do { \ + (u)->x0 = (d); \ + (u)->x1 = (c); \ + (u)->x2 = (b); \ + (u)->x3 = (a); \ } while (0) #elif defined(DUK_USE_INTEGER_ME) #error integer mixed endian not supported now #elif defined(DUK_USE_INTEGER_BE) -#define DUK__U32_INIT(u, a, b, c, d) do { \ - (u)->x0 = (a); (u)->x1 = (b); (u)->x2 = (c); (u)->x3 = (d); \ +#define DUK__U32_INIT(u, a, b, c, d) \ + do { \ + (u)->x0 = (a); \ + (u)->x1 = (b); \ + (u)->x2 = (c); \ + (u)->x3 = (d); \ } while (0) #else #error unknown integer endianness #endif #if defined(DUK_USE_DOUBLE_LE) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (h); (u)->x1 = (g); (u)->x2 = (f); (u)->x3 = (e); \ - (u)->x4 = (d); (u)->x5 = (c); (u)->x6 = (b); (u)->x7 = (a); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (h); \ + (u)->x1 = (g); \ + (u)->x2 = (f); \ + (u)->x3 = (e); \ + (u)->x4 = (d); \ + (u)->x5 = (c); \ + (u)->x6 = (b); \ + (u)->x7 = (a); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (h) && (u)->x1 == (g) && (u)->x2 == (f) && (u)->x3 == (e) && \ - (u)->x4 == (d) && (u)->x5 == (c) && (u)->x6 == (b) && (u)->x7 == (a)) + ((u)->x0 == (h) && (u)->x1 == (g) && (u)->x2 == (f) && (u)->x3 == (e) && (u)->x4 == (d) && (u)->x5 == (c) && \ + (u)->x6 == (b) && (u)->x7 == (a)) #elif defined(DUK_USE_DOUBLE_ME) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (d); (u)->x1 = (c); (u)->x2 = (b); (u)->x3 = (a); \ - (u)->x4 = (h); (u)->x5 = (g); (u)->x6 = (f); (u)->x7 = (e); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (d); \ + (u)->x1 = (c); \ + (u)->x2 = (b); \ + (u)->x3 = (a); \ + (u)->x4 = (h); \ + (u)->x5 = (g); \ + (u)->x6 = (f); \ + (u)->x7 = (e); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (d) && (u)->x1 == (c) && (u)->x2 == (b) && (u)->x3 == (a) && \ - (u)->x4 == (h) && (u)->x5 == (g) && (u)->x6 == (f) && (u)->x7 == (e)) + ((u)->x0 == (d) && (u)->x1 == (c) && (u)->x2 == (b) && (u)->x3 == (a) && (u)->x4 == (h) && (u)->x5 == (g) && \ + (u)->x6 == (f) && (u)->x7 == (e)) #elif defined(DUK_USE_DOUBLE_BE) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (a); (u)->x1 = (b); (u)->x2 = (c); (u)->x3 = (d); \ - (u)->x4 = (e); (u)->x5 = (f); (u)->x6 = (g); (u)->x7 = (h); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (a); \ + (u)->x1 = (b); \ + (u)->x2 = (c); \ + (u)->x3 = (d); \ + (u)->x4 = (e); \ + (u)->x5 = (f); \ + (u)->x6 = (g); \ + (u)->x7 = (h); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (a) && (u)->x1 == (b) && (u)->x2 == (c) && (u)->x3 == (d) && \ - (u)->x4 == (e) && (u)->x5 == (f) && (u)->x6 == (g) && (u)->x7 == (h)) + ((u)->x0 == (a) && (u)->x1 == (b) && (u)->x2 == (c) && (u)->x3 == (d) && (u)->x4 == (e) && (u)->x5 == (f) && \ + (u)->x6 == (g) && (u)->x7 == (h)) #else #error unknown double endianness #endif @@ -91601,17 +93015,12 @@ DUK_LOCAL duk_uint_t duk__selftest_types(void) { duk_uint_t error_count = 0; - if (!(sizeof(duk_int8_t) == 1 && - sizeof(duk_uint8_t) == 1 && - sizeof(duk_int16_t) == 2 && - sizeof(duk_uint16_t) == 2 && - sizeof(duk_int32_t) == 4 && - sizeof(duk_uint32_t) == 4)) { + if (!(sizeof(duk_int8_t) == 1 && sizeof(duk_uint8_t) == 1 && sizeof(duk_int16_t) == 2 && sizeof(duk_uint16_t) == 2 && + sizeof(duk_int32_t) == 4 && sizeof(duk_uint32_t) == 4)) { DUK__FAILED("duk_(u)int{8,16,32}_t size"); } #if defined(DUK_USE_64BIT_OPS) - if (!(sizeof(duk_int64_t) == 8 && - sizeof(duk_uint64_t) == 8)) { + if (!(sizeof(duk_int64_t) == 8 && sizeof(duk_uint64_t) == 8)) { DUK__FAILED("duk_(u)int64_t size"); } #endif @@ -91763,8 +93172,14 @@ * (2.008366013071895,) */ - du.uc0 = 0x40; du.uc1 = 0x00; du.uc2 = 0x11; du.uc3 = 0x22; - du.uc4 = 0x33; du.uc5 = 0x44; du.uc6 = 0x55; du.uc7 = 0x66; + du.uc0 = 0x40; + du.uc1 = 0x00; + du.uc2 = 0x11; + du.uc3 = 0x22; + du.uc4 = 0x33; + du.uc5 = 0x44; + du.uc6 = 0x55; + du.uc7 = 0x66; DUK_DBLUNION_DOUBLE_NTOH(&du); du_diff = du.d - 2.008366013071895; #if 0 @@ -91819,20 +93234,38 @@ */ /* little endian */ - a.x0 = 0x11; a.x1 = 0x22; a.x2 = 0x33; a.x3 = 0x44; - a.x4 = 0x00; a.x5 = 0x00; a.x6 = 0xf1; a.x7 = 0xff; + a.x0 = 0x11; + a.x1 = 0x22; + a.x2 = 0x33; + a.x3 = 0x44; + a.x4 = 0x00; + a.x5 = 0x00; + a.x6 = 0xf1; + a.x7 = 0xff; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); /* big endian */ - a.x0 = 0xff; a.x1 = 0xf1; a.x2 = 0x00; a.x3 = 0x00; - a.x4 = 0x44; a.x5 = 0x33; a.x6 = 0x22; a.x7 = 0x11; + a.x0 = 0xff; + a.x1 = 0xf1; + a.x2 = 0x00; + a.x3 = 0x00; + a.x4 = 0x44; + a.x5 = 0x33; + a.x6 = 0x22; + a.x7 = 0x11; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); /* mixed endian */ - a.x0 = 0x00; a.x1 = 0x00; a.x2 = 0xf1; a.x3 = 0xff; - a.x4 = 0x11; a.x5 = 0x22; a.x6 = 0x33; a.x7 = 0x44; + a.x0 = 0x00; + a.x1 = 0x00; + a.x2 = 0xf1; + a.x3 = 0xff; + a.x4 = 0x11; + a.x5 = 0x22; + a.x6 = 0x33; + a.x7 = 0x44; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); @@ -91897,10 +93330,14 @@ c.d = a.d + b.d; if (!DUK__DOUBLE_COMPARE(&c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)) { DUK_D(DUK_DPRINT("broken result (native endiannesss): %02x %02x %02x %02x %02x %02x %02x %02x", - (unsigned int) c.x0, (unsigned int) c.x1, - (unsigned int) c.x2, (unsigned int) c.x3, - (unsigned int) c.x4, (unsigned int) c.x5, - (unsigned int) c.x6, (unsigned int) c.x7)); + (unsigned int) c.x0, + (unsigned int) c.x1, + (unsigned int) c.x2, + (unsigned int) c.x3, + (unsigned int) c.x4, + (unsigned int) c.x5, + (unsigned int) c.x6, + (unsigned int) c.x7)); DUK__FAILED("invalid result from 1.0 + 0.5ulp"); } @@ -91917,10 +93354,14 @@ c.d = a.d + b.d; if (!DUK__DOUBLE_COMPARE(&c, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02)) { DUK_D(DUK_DPRINT("broken result (native endiannesss): %02x %02x %02x %02x %02x %02x %02x %02x", - (unsigned int) c.x0, (unsigned int) c.x1, - (unsigned int) c.x2, (unsigned int) c.x3, - (unsigned int) c.x4, (unsigned int) c.x5, - (unsigned int) c.x6, (unsigned int) c.x7)); + (unsigned int) c.x0, + (unsigned int) c.x1, + (unsigned int) c.x2, + (unsigned int) c.x3, + (unsigned int) c.x4, + (unsigned int) c.x5, + (unsigned int) c.x6, + (unsigned int) c.x7)); DUK__FAILED("invalid result from (1.0 + ulp) + 0.5ulp"); } @@ -92091,7 +93532,7 @@ duk_double_t dv; duk_uint32_t uv; - dv = 3735928559.0; /* 0xdeadbeef in decimal */ + dv = 3735928559.0; /* 0xdeadbeef in decimal */ uv = (duk_uint32_t) dv; if (uv != 0xdeadbeefUL) { @@ -92128,7 +93569,7 @@ ptr = alloc_func(udata, (duk_size_t) i); if (ptr == NULL) { DUK_D(DUK_DPRINT("alloc failed, ignore")); - continue; /* alloc failed, ignore */ + continue; /* alloc failed, ignore */ } for (j = 0; j < i; j++) { ((unsigned char *) ptr)j = (unsigned char) (0x80 + j); @@ -92137,14 +93578,15 @@ if (new_ptr == NULL) { DUK_D(DUK_DPRINT("realloc failed, ignore")); free_func(udata, ptr); - continue; /* realloc failed, ignore */ + continue; /* realloc failed, ignore */ } ptr = new_ptr; for (j = 0; j < i; j++) { x = ((unsigned char *) ptr)j; if (x != (unsigned char) (0x80 + j)) { DUK_D(DUK_DPRINT("byte at index %ld doesn't match after realloc: %02lx", - (long) j, (unsigned long) x)); + (long) j, + (unsigned long) x)); DUK__FAILED("byte compare after realloc"); break; } @@ -92188,7 +93630,7 @@ return error_count; } -#endif /* DUK_USE_SELF_TESTS */ +#endif /* DUK_USE_SELF_TESTS */ /* automatic undefs */ #undef DUK__DBLUNION_CMP_FALSE @@ -92231,11 +93673,11 @@ expt = (duk_small_int_t) ((i >> 52) & 0x07ff); shift = expt - 1023; - if (shift >= 0 && shift <= 46) { /* exponents 1023 to 1069 */ + if (shift >= 0 && shift <= 46) { /* exponents 1023 to 1069 */ duk_int64_t t; if (((DUK_I64_CONSTANT(0x000fffffffffffff) >> shift) & i) == 0) { - t = i | DUK_I64_CONSTANT(0x0010000000000000); /* implicit leading one */ + t = i | DUK_I64_CONSTANT(0x0010000000000000); /* implicit leading one */ t = t & DUK_I64_CONSTANT(0x001fffffffffffff); t = t >> (52 - shift); if (i < 0) { @@ -92244,13 +93686,13 @@ DUK_TVAL_SET_FASTINT(tv, t); return; } - } else if (shift == -1023) { /* exponent 0 */ + } else if (shift == -1023) { /* exponent 0 */ if (i >= 0 && (i & DUK_I64_CONSTANT(0x000fffffffffffff)) == 0) { /* Note: reject negative zero. */ DUK_TVAL_SET_FASTINT(tv, (duk_int64_t) 0); return; } - } else if (shift == 47) { /* exponent 1070 */ + } else if (shift == 47) { /* exponent 1070 */ if (i < 0 && (i & DUK_I64_CONSTANT(0x000fffffffffffff)) == 0) { DUK_TVAL_SET_FASTINT(tv, (duk_int64_t) DUK_FASTINT_MIN); return; @@ -92278,23 +93720,23 @@ if ((t >> 48) != DUK_TAG_FASTINT) { return tv->d; } else if (t & DUK_U64_CONSTANT(0x0000800000000000)) { - t = (duk_uint64_t) (-((duk_int64_t) t)); /* avoid unary minus on unsigned */ - t = t & DUK_U64_CONSTANT(0x0000ffffffffffff); /* negative */ + t = (duk_uint64_t) (-((duk_int64_t) t)); /* avoid unary minus on unsigned */ + t = t & DUK_U64_CONSTANT(0x0000ffffffffffff); /* negative */ t |= DUK_U64_CONSTANT(0xc330000000000000); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d + 4503599627370496.0; /* 1 << 52 */ + return du.d + 4503599627370496.0; /* 1 << 52 */ } else if (t != 0) { - t &= DUK_U64_CONSTANT(0x0000ffffffffffff); /* positive */ + t &= DUK_U64_CONSTANT(0x0000ffffffffffff); /* positive */ t |= DUK_U64_CONSTANT(0x4330000000000000); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d - 4503599627370496.0; /* 1 << 52 */ + return du.d - 4503599627370496.0; /* 1 << 52 */ } else { - return 0.0; /* zero */ + return 0.0; /* zero */ } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#if 0 /* unused */ +#if 0 /* unused */ #if defined(DUK_USE_FASTINT) && !defined(DUK_USE_PACKED_TVAL) DUK_INTERNAL DUK_ALWAYS_INLINE duk_double_t duk_tval_get_number_unpacked(duk_tval *tv) { duk_double_union du; @@ -92316,8 +93758,8 @@ return tv->v.d; } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#endif /* 0 */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* 0 */ #if defined(DUK_USE_FASTINT) && !defined(DUK_USE_PACKED_TVAL) DUK_INTERNAL DUK_ALWAYS_INLINE duk_double_t duk_tval_get_number_unpacked_fastint(duk_tval *tv) { @@ -92329,16 +93771,16 @@ if (tv->v.fi >= 0) { t = DUK_U64_CONSTANT(0x4330000000000000) | (duk_uint64_t) tv->v.fi; DUK_DBLUNION_SET_UINT64(&du, t); - return du.d - 4503599627370496.0; /* 1 << 52 */ + return du.d - 4503599627370496.0; /* 1 << 52 */ } else { t = DUK_U64_CONSTANT(0xc330000000000000) | (duk_uint64_t) (-tv->v.fi); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d + 4503599627370496.0; /* 1 << 52 */ + return du.d + 4503599627370496.0; /* 1 << 52 */ } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* * Assertion helpers. @@ -98569,7 +100011,7 @@ shift = ctx->currbits - bits; mask = (((duk_uint32_t) 1U) << bits) - 1U; tmp = (ctx->currval >> shift) & mask; - ctx->currbits = shift; /* remaining */ + ctx->currbits = shift; /* remaining */ #if 0 DUK_DDD(DUK_DDDPRINT("decode_bits: %ld bits -> 0x%08lx (%ld), currbits=%ld, currval=0x%08lx", @@ -98608,17 +100050,17 @@ */ switch (duk_bd_decode(ctx, 2)) { case 0: - return 0; /* 0,0 */ + return 0; /* 0,0 */ case 1: - return duk_bd_decode(ctx, 2) + 1; /* 1,4 */ + return duk_bd_decode(ctx, 2) + 1; /* 1,4 */ case 2: - return duk_bd_decode(ctx, 5) + 5; /* 5,36 */ + return duk_bd_decode(ctx, 5) + 5; /* 5,36 */ default: t = duk_bd_decode(ctx, 7); if (t == 0) { return duk_bd_decode(ctx, 20); } - return (t - 1) + 37; /* 37,163 */ + return (t - 1) + 37; /* 37,163 */ } } @@ -98627,20 +100069,18 @@ * Caller must supply the output buffer whose size is NOT checked! */ -#define DUK__BITPACK_LETTER_LIMIT 26 -#define DUK__BITPACK_LOOKUP1 26 -#define DUK__BITPACK_LOOKUP2 27 -#define DUK__BITPACK_SWITCH1 28 -#define DUK__BITPACK_SWITCH 29 -#define DUK__BITPACK_UNUSED1 30 -#define DUK__BITPACK_EIGHTBIT 31 - -DUK_LOCAL const duk_uint8_t duk__bitpacked_lookup16 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_UNDERSCORE, DUK_ASC_SPACE, - 0x82, 0x80, DUK_ASC_DOUBLEQUOTE, DUK_ASC_LCURLY -}; +#define DUK__BITPACK_LETTER_LIMIT 26 +#define DUK__BITPACK_LOOKUP1 26 +#define DUK__BITPACK_LOOKUP2 27 +#define DUK__BITPACK_SWITCH1 28 +#define DUK__BITPACK_SWITCH 29 +#define DUK__BITPACK_UNUSED1 30 +#define DUK__BITPACK_EIGHTBIT 31 + +DUK_LOCAL const duk_uint8_t duk__bitpacked_lookup16 = { DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, + DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_UNDERSCORE, DUK_ASC_SPACE, + 0x82, 0x80, DUK_ASC_DOUBLEQUOTE, DUK_ASC_LCURLY }; DUK_INTERNAL duk_small_uint_t duk_bd_decode_bitpacked_string(duk_bitdecoder_ctx *bd, duk_uint8_t *out) { duk_small_uint_t len; @@ -98650,10 +100090,10 @@ len = duk_bd_decode(bd, 5); if (len == 31) { - len = duk_bd_decode(bd, 8); /* Support up to 256 bytes; rare. */ + len = duk_bd_decode(bd, 8); /* Support up to 256 bytes; rare. */ } - mode = 32; /* 0 = uppercase, 32 = lowercase (= 'a' - 'A') */ + mode = 32; /* 0 = uppercase, 32 = lowercase (= 'a' - 'A') */ for (i = 0; i < len; i++) { t = duk_bd_decode(bd, 5); if (t < DUK__BITPACK_LETTER_LIMIT) { @@ -98664,7 +100104,7 @@ t = duk__bitpacked_lookup8 + duk_bd_decode(bd, 3); } else if (t == DUK__BITPACK_SWITCH1) { t = duk_bd_decode(bd, 5); - DUK_ASSERT_DISABLE(t >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(t >= 0); /* unsigned */ DUK_ASSERT(t <= 25); t = t + DUK_ASC_UC_A + (mode ^ 32); } else if (t == DUK__BITPACK_SWITCH) { @@ -98806,7 +100246,7 @@ DUK_ERROR_RANGE(thr, DUK_STR_BUFFER_TOO_LONG); DUK_WO_NORETURN(return NULL;); } -#if 0 /* for manual torture testing: tight allocation, useful with valgrind */ +#if 0 /* for manual torture testing: tight allocation, useful with valgrind */ new_sz = curr_off + sz; #endif @@ -98847,9 +100287,7 @@ DUK_UNREF(thr); p_base = bw->p_base; - duk_memcpy_unsafe((void *) bw->p, - (const void *) (p_base + src_off), - (size_t) len); + duk_memcpy_unsafe((void *) bw->p, (const void *) (p_base + src_off), (size_t) len); bw->p += len; } @@ -98864,7 +100302,11 @@ duk_bw_write_raw_slice(thr, bw, src_off, len); } -DUK_INTERNAL void duk_bw_insert_raw_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_raw_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len) { duk_uint8_t *p_base; duk_size_t buf_sz, move_sz; @@ -98875,20 +100317,20 @@ DUK_UNREF(thr); p_base = bw->p_base; - buf_sz = (duk_size_t) (bw->p - p_base); /* constrained by maximum buffer size */ + buf_sz = (duk_size_t) (bw->p - p_base); /* constrained by maximum buffer size */ move_sz = buf_sz - dst_off; - DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ - duk_memmove_unsafe((void *) (p_base + dst_off + len), - (const void *) (p_base + dst_off), - (size_t) move_sz); - duk_memcpy_unsafe((void *) (p_base + dst_off), - (const void *) buf, - (size_t) len); + DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ + duk_memmove_unsafe((void *) (p_base + dst_off + len), (const void *) (p_base + dst_off), (size_t) move_sz); + duk_memcpy_unsafe((void *) (p_base + dst_off), (const void *) buf, (size_t) len); bw->p += len; } -DUK_INTERNAL void duk_bw_insert_ensure_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_ensure_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len) { DUK_ASSERT(thr != NULL); DUK_ASSERT(bw != NULL); DUK_ASSERT(dst_off <= DUK_BW_GET_SIZE(thr, bw)); @@ -98898,7 +100340,11 @@ duk_bw_insert_raw_bytes(thr, bw, dst_off, buf, len); } -DUK_INTERNAL void duk_bw_insert_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_raw_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len) { duk_uint8_t *p_base; duk_size_t buf_sz, move_sz; @@ -98925,17 +100371,17 @@ buf_sz = (duk_size_t) (bw->p - p_base); move_sz = buf_sz - dst_off; - DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ - duk_memmove_unsafe((void *) (p_base + dst_off + len), - (const void *) (p_base + dst_off), - (size_t) move_sz); - duk_memcpy_unsafe((void *) (p_base + dst_off), - (const void *) (p_base + src_off), - (size_t) len); + DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ + duk_memmove_unsafe((void *) (p_base + dst_off + len), (const void *) (p_base + dst_off), (size_t) move_sz); + duk_memcpy_unsafe((void *) (p_base + dst_off), (const void *) (p_base + src_off), (size_t) len); bw->p += len; } -DUK_INTERNAL void duk_bw_insert_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_ensure_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len) { DUK_ASSERT(thr != NULL); DUK_ASSERT(bw != NULL); DUK_ASSERT(dst_off <= DUK_BW_GET_SIZE(thr, bw)); @@ -98965,7 +100411,7 @@ p_dst = p_base + off + len; p_src = p_base + off; duk_memmove_unsafe((void *) p_dst, (const void *) p_src, (size_t) move_sz); - return p_src; /* point to start of 'reserved area' */ + return p_src; /* point to start of 'reserved area' */ } DUK_INTERNAL duk_uint8_t *duk_bw_insert_ensure_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len) { @@ -98995,9 +100441,7 @@ p_dst = p_base + off; p_src = p_dst + len; move_sz = (duk_size_t) (bw->p - p_src); - duk_memmove_unsafe((void *) p_dst, - (const void *) p_src, - (size_t) move_sz); + duk_memmove_unsafe((void *) p_dst, (const void *) p_src, (size_t) move_sz); bw->p -= len; } @@ -99011,12 +100455,8 @@ DUK_ASSERT(bw_ctx != NULL); DUK_ASSERT(bw_ctx->buf != NULL); DUK_ASSERT((DUK_HBUFFER_DYNAMIC_GET_SIZE(bw_ctx->buf) == 0) || - (bw_ctx->p != NULL && - bw_ctx->p_base != NULL && - bw_ctx->p_limit != NULL && - bw_ctx->p_limit >= bw_ctx->p_base && - bw_ctx->p >= bw_ctx->p_base && - bw_ctx->p <= bw_ctx->p_limit)); + (bw_ctx->p != NULL && bw_ctx->p_base != NULL && bw_ctx->p_limit != NULL && bw_ctx->p_limit >= bw_ctx->p_base && + bw_ctx->p >= bw_ctx->p_base && bw_ctx->p <= bw_ctx->p_limit)); } #endif /* @@ -99038,7 +100478,8 @@ * relying on fmin(), fmax(), or other intrinsics. Out-of-range results are * not assumed by caller, but here value is clamped, NaN converts to minval. */ -#define DUK__DOUBLE_INT_CAST1(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST1(tname, minval, maxval) \ + do { \ if (DUK_LIKELY(x >= (duk_double_t) (minval))) { \ DUK_ASSERT(!DUK_ISNAN(x)); \ if (DUK_LIKELY(x <= (duk_double_t) (maxval))) { \ @@ -99059,19 +100500,22 @@ * argument is a NaN, return the second argument. This avoids a * NaN-to-integer cast which is undefined behavior. */ -#define DUK__DOUBLE_INT_CAST2(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST2(tname, minval, maxval) \ + do { \ return (tname) duk_double_fmin(duk_double_fmax(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ } while (0) /* Another solution which doesn't need C99+ behavior for fmin() and fmax(). */ -#define DUK__DOUBLE_INT_CAST3(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST3(tname, minval, maxval) \ + do { \ if (DUK_ISNAN(x)) { \ /* 0 or any other value is fine. */ \ return (tname) 0; \ } else \ return (tname) DUK_FMIN(DUK_FMAX(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ - } \ - } while (0) + } \ + } \ + while (0) /* C99+ solution: relies on specific fmin() and fmax() behavior in C99: if * one argument is NaN but the other isn't, the non-NaN argument is returned. @@ -99080,7 +100524,8 @@ * the fmin() and fmax() calls (unless one uses -ffast-math which we don't * support). */ -#define DUK__DOUBLE_INT_CAST4(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST4(tname, minval, maxval) \ + do { \ return (tname) DUK_FMIN(DUK_FMAX(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ } while (0) @@ -99124,12 +100569,12 @@ * infinity, at least on x64. This number is one double unit below that * midpoint. See misc/float_cast.c. */ -#define DUK__FLOAT_ROUND_LIMIT 340282356779733623858607532500980858880.0 +#define DUK__FLOAT_ROUND_LIMIT 340282356779733623858607532500980858880.0 /* Maximum IEEE float. Double-to-float conversion above this would be out of * range and thus technically undefined behavior. */ -#define DUK__FLOAT_MAX 340282346638528859811704183484516925440.0 +#define DUK__FLOAT_MAX 340282346638528859811704183484516925440.0 DUK_INTERNAL duk_float_t duk_double_to_float_t(duk_double_t x) { /* Even a double-to-float cast is technically undefined behavior if @@ -99148,8 +100593,7 @@ duk_double_t t; t = DUK_FABS(x); - DUK_ASSERT((DUK_ISNAN(x) && DUK_ISNAN(t)) || - (!DUK_ISNAN(x) && !DUK_ISNAN(t))); + DUK_ASSERT((DUK_ISNAN(x) && DUK_ISNAN(t)) || (!DUK_ISNAN(x) && !DUK_ISNAN(t))); if (DUK_LIKELY(t <= DUK__FLOAT_MAX)) { /* Standard in-range case, try to get here with a minimum @@ -99297,7 +100741,7 @@ DUK_INTERNAL duk_double_t duk_double_trunc_towards_zero(duk_double_t x) { /* XXX: optimize */ duk_small_uint_t s = duk_double_signbit(x); - x = DUK_FLOOR(DUK_FABS(x)); /* truncate towards zero */ + x = DUK_FLOOR(DUK_FABS(x)); /* truncate towards zero */ if (s) { x = -x; } @@ -99543,8 +100987,8 @@ #if defined(DUK_USE_STRHASH_DENSE) /* 'magic' constants for Murmurhash2 */ -#define DUK__MAGIC_M ((duk_uint32_t) 0x5bd1e995UL) -#define DUK__MAGIC_R 24 +#define DUK__MAGIC_M ((duk_uint32_t) 0x5bd1e995UL) +#define DUK__MAGIC_R 24 DUK_INTERNAL duk_uint32_t duk_util_hashbytes(const duk_uint8_t *data, duk_size_t len, duk_uint32_t seed) { duk_uint32_t h = seed ^ ((duk_uint32_t) len); @@ -99558,9 +101002,7 @@ #if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS) duk_uint32_t k = *((const duk_uint32_t *) (const void *) data); #else - duk_uint32_t k = ((duk_uint32_t) data0) | - (((duk_uint32_t) data1) << 8) | - (((duk_uint32_t) data2) << 16) | + duk_uint32_t k = ((duk_uint32_t) data0) | (((duk_uint32_t) data1) << 8) | (((duk_uint32_t) data2) << 16) | (((duk_uint32_t) data3) << 24); #endif @@ -99574,11 +101016,14 @@ } switch (len) { - case 3: h ^= data2 << 16; - case 2: h ^= data1 << 8; - case 1: h ^= data0; - h *= DUK__MAGIC_M; - } + case 3: + h ^= data2 << 16; + case 2: + h ^= data1 << 8; + case 1: + h ^= data0; + h *= DUK__MAGIC_M; + } h ^= h >> 13; h *= DUK__MAGIC_M; @@ -99586,7 +101031,7 @@ return h; } -#endif /* DUK_USE_STRHASH_DENSE */ +#endif /* DUK_USE_STRHASH_DENSE */ /* automatic undefs */ #undef DUK__MAGIC_M @@ -99609,7 +101054,7 @@ DUK_ASSERT(s2 != NULL); return DUK_MEMCMP(s1, s2, (size_t) len); } -#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ DUK_INTERNAL DUK_INLINE duk_small_int_t duk_memcmp_unsafe(const void *s1, const void *s2, duk_size_t len) { DUK_ASSERT(s1 != NULL || len == 0U); DUK_ASSERT(s2 != NULL || len == 0U); @@ -99626,7 +101071,7 @@ DUK_ASSERT(s2 != NULL); return DUK_MEMCMP(s1, s2, (size_t) len); } -#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ /* * A tiny random number generator used for Math.random() and other internals. * @@ -99650,15 +101095,16 @@ #endif #if defined(DUK__RANDOM_SHAMIR3OP) -#define DUK__UPDATE_RND(rnd) do { \ +#define DUK__UPDATE_RND(rnd) \ + do { \ (rnd) += ((rnd) * (rnd)) | 0x05UL; \ - (rnd) = ((rnd) & 0xffffffffUL); /* if duk_uint32_t is exactly 32 bits, this is a NOP */ \ + (rnd) = ((rnd) &0xffffffffUL); /* if duk_uint32_t is exactly 32 bits, this is a NOP */ \ } while (0) -#define DUK__RND_BIT(rnd) ((rnd) >> 31) /* only use the highest bit */ +#define DUK__RND_BIT(rnd) ((rnd) >> 31) /* only use the highest bit */ DUK_INTERNAL void duk_util_tinyrandom_prepare_seed(duk_hthread *thr) { - DUK_UNREF(thr); /* Nothing now. */ + DUK_UNREF(thr); /* Nothing now. */ } DUK_INTERNAL duk_double_t duk_util_tinyrandom_get_double(duk_hthread *thr) { @@ -99668,7 +101114,7 @@ rnd = thr->heap->rnd_state; - n = 53; /* enough to cover the whole mantissa */ + n = 53; /* enough to cover the whole mantissa */ t = 0.0; do { @@ -99684,7 +101130,7 @@ return t; } -#endif /* DUK__RANDOM_SHAMIR3OP */ +#endif /* DUK__RANDOM_SHAMIR3OP */ #if defined(DUK__RANDOM_XOROSHIRO128PLUS) DUK_LOCAL DUK_ALWAYS_INLINE duk_uint64_t duk__rnd_splitmix64(duk_uint64_t *x) { @@ -99723,9 +101169,9 @@ * because current seed is Date.now()) result in different xoroshiro128+ * seeds. */ - x = thr->heap->rnd_state0; /* Only 0 is used as input here. */ + x = thr->heap->rnd_state0; /* Only 0 is used as input here. */ for (i = 0; i < 64; i++) { - thr->heap->rnd_statei & 0x01 = duk__rnd_splitmix64(&x); /* Keep last 2 values. */ + thr->heap->rnd_statei & 0x01 = duk__rnd_splitmix64(&x); /* Keep last 2 values. */ } } @@ -99749,9 +101195,9 @@ #endif return du.d - 1.0; } -#endif /* DUK__RANDOM_XOROSHIRO128PLUS */ +#endif /* DUK__RANDOM_XOROSHIRO128PLUS */ -#endif /* !DUK_USE_GET_RANDOM_DOUBLE */ +#endif /* !DUK_USE_GET_RANDOM_DOUBLE */ /* automatic undefs */ #undef DUK__RANDOM_SHAMIR3OP
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-noline/duktape.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-noline/duktape.h
Changed
@@ -1,13 +1,13 @@ /* - * Duktape public API for Duktape 2.6.0. + * Duktape public API for Duktape 2.7.0. * * See the API reference for documentation on call semantics. The exposed, * supported API is between the "BEGIN PUBLIC API" and "END PUBLIC API" * comments. Other parts of the header are Duktape internal and related to * e.g. platform/compiler/feature detection. * - * Git commit fffa346eff06a8764b02c31d4336f63a773a95c3 (v2.6.0). - * Git branch v2-maintenance. + * Git commit 03d4d728f8365021de6955c649e6dcd05dcca99f (03d4d72-dirty). + * Git branch HEAD. * * See Duktape AUTHORS.rst and LICENSE.txt for copyright and * licensing information. @@ -21,7 +21,7 @@ * * (http://opensource.org/licenses/MIT) * - * Copyright (c) 2013-2019 by Duktape authors (see AUTHORS.rst) + * Copyright (c) 2013-present by Duktape authors (see AUTHORS.rst) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -110,6 +110,12 @@ * * Luis de Bethencourt (https://github.com/luisbg) * * Ian Whyman (https://github.com/v00d00) * * Rick Sayre (https://github.com/whorfin) + * * Craig Leres (https://github.com/leres) + * * Maurici Abad (https://github.com/mauriciabad) + * * Nancy Li (https://github.com/NancyLi1013) + * * William Parks (https://github.com/WilliamParks) + * * Sam Hellawell (https://github.com/samhellawell) + * * Vladislavs Sokurenko (https://github.com/sokurenko) * * Other contributions * =================== @@ -176,16 +182,16 @@ * development snapshots have 99 for patch level (e.g. 0.10.99 would be a * development version after 0.10.0 but before the next official release). */ -#define DUK_VERSION 20600L +#define DUK_VERSION 20700L /* Git commit, describe, and branch for Duktape build. Useful for * non-official snapshot builds so that application code can easily log * which Duktape snapshot was used. Not available in the ECMAScript * environment. */ -#define DUK_GIT_COMMIT "fffa346eff06a8764b02c31d4336f63a773a95c3" -#define DUK_GIT_DESCRIBE "v2.6.0" -#define DUK_GIT_BRANCH "v2-maintenance" +#define DUK_GIT_COMMIT "03d4d728f8365021de6955c649e6dcd05dcca99f" +#define DUK_GIT_DESCRIBE "03d4d72-dirty" +#define DUK_GIT_BRANCH "HEAD" /* External duk_config.h provides platform/compiler/OS dependent * typedefs and macros, and DUK_USE_xxx config options so that
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_alloc_default.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_alloc_default.c
Changed
@@ -12,8 +12,7 @@ void *res; DUK_UNREF(udata); res = DUK_ANSI_MALLOC(size); - DUK_DDD(DUK_DDDPRINT("default alloc function: %lu -> %p", - (unsigned long) size, (void *) res)); + DUK_DDD(DUK_DDDPRINT("default alloc function: %lu -> %p", (unsigned long) size, (void *) res)); return res; } @@ -21,8 +20,7 @@ void *res; DUK_UNREF(udata); res = DUK_ANSI_REALLOC(ptr, newsize); - DUK_DDD(DUK_DDDPRINT("default realloc function: %p %lu -> %p", - (void *) ptr, (unsigned long) newsize, (void *) res)); + DUK_DDD(DUK_DDDPRINT("default realloc function: %p %lu -> %p", (void *) ptr, (unsigned long) newsize, (void *) res)); return res; } @@ -31,4 +29,4 @@ DUK_UNREF(udata); DUK_ANSI_FREE(ptr); } -#endif /* DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS */ +#endif /* DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_bytecode.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_bytecode.c
Changed
@@ -14,11 +14,11 @@ #if defined(DUK_USE_BYTECODE_DUMP_SUPPORT) -#define DUK__SER_MARKER 0xbf -#define DUK__SER_STRING 0x00 -#define DUK__SER_NUMBER 0x01 +#define DUK__SER_MARKER 0xbf +#define DUK__SER_STRING 0x00 +#define DUK__SER_NUMBER 0x01 #define DUK__BYTECODE_INITIAL_ALLOC 256 -#define DUK__NO_FORMALS 0xffffffffUL +#define DUK__NO_FORMALS 0xffffffffUL /* * Dump/load helpers, xxx_raw() helpers do no buffer checks @@ -52,12 +52,10 @@ DUK_ASSERT(h != NULL); len = DUK_HSTRING_GET_BYTELEN(h); - DUK_ASSERT(len <= 0xffffffffUL); /* string limits */ + DUK_ASSERT(len <= 0xffffffffUL); /* string limits */ tmp32 = (duk_uint32_t) len; DUK_RAW_WRITEINC_U32_BE(p, tmp32); - duk_memcpy((void *) p, - (const void *) DUK_HSTRING_GET_DATA(h), - len); + duk_memcpy((void *) p, (const void *) DUK_HSTRING_GET_DATA(h), len); p += len; return p; } @@ -71,18 +69,20 @@ DUK_UNREF(thr); len = DUK_HBUFFER_GET_SIZE(h); - DUK_ASSERT(len <= 0xffffffffUL); /* buffer limits */ + DUK_ASSERT(len <= 0xffffffffUL); /* buffer limits */ tmp32 = (duk_uint32_t) len; DUK_RAW_WRITEINC_U32_BE(p, tmp32); /* When len == 0, buffer data pointer may be NULL. */ - duk_memcpy_unsafe((void *) p, - (const void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h), - len); + duk_memcpy_unsafe((void *) p, (const void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h), len); p += len; return p; } -DUK_LOCAL duk_uint8_t *duk__dump_string_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx) { +DUK_LOCAL duk_uint8_t *duk__dump_string_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx) { duk_hstring *h_str; duk_tval *tv; @@ -94,13 +94,17 @@ h_str = DUK_HTHREAD_STRING_EMPTY_STRING(thr); DUK_ASSERT(h_str != NULL); } - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(h_str), p); p = duk__dump_hstring_raw(p, h_str); return p; } -DUK_LOCAL duk_uint8_t *duk__dump_buffer_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx) { +DUK_LOCAL duk_uint8_t *duk__dump_buffer_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx) { duk_tval *tv; tv = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, (duk_hobject *) func, stridx); @@ -108,7 +112,7 @@ duk_hbuffer *h_buf; h_buf = DUK_TVAL_GET_BUFFER(tv); DUK_ASSERT(h_buf != NULL); - DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HBUFFER_GET_SIZE(h_buf), p); p = duk__dump_hbuffer_raw(thr, p, h_buf); } else { @@ -118,7 +122,12 @@ return p; } -DUK_LOCAL duk_uint8_t *duk__dump_uint32_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx, duk_uint32_t def_value) { +DUK_LOCAL duk_uint8_t *duk__dump_uint32_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx, + duk_uint32_t def_value) { duk_tval *tv; duk_uint32_t val; @@ -151,27 +160,28 @@ duk_uint32_t val; key = DUK_HOBJECT_E_GET_KEY(thr->heap, h, i); - DUK_ASSERT(key != NULL); /* _Varmap is dense */ + DUK_ASSERT(key != NULL); /* _Varmap is dense */ DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, h, i)); tv_val = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, h, i); DUK_ASSERT(tv_val != NULL); - DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_val)); /* known to be number; in fact an integer */ + DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_val)); /* known to be number; in fact an integer */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_val)); - DUK_ASSERT(DUK_TVAL_GET_FASTINT(tv_val) == (duk_int64_t) DUK_TVAL_GET_FASTINT_U32(tv_val)); /* known to be 32-bit */ + DUK_ASSERT(DUK_TVAL_GET_FASTINT(tv_val) == + (duk_int64_t) DUK_TVAL_GET_FASTINT_U32(tv_val)); /* known to be 32-bit */ val = DUK_TVAL_GET_FASTINT_U32(tv_val); #else val = (duk_uint32_t) DUK_TVAL_GET_NUMBER(tv_val); #endif - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(key) + 4U, p); p = duk__dump_hstring_raw(p, key); DUK_RAW_WRITEINC_U32_BE(p, val); } } p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_RAW_WRITEINC_U32_BE(p, 0); /* end of _Varmap */ + DUK_RAW_WRITEINC_U32_BE(p, 0); /* end of _Varmap */ return p; } @@ -189,7 +199,7 @@ */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_ASSERT(h->length != DUK__NO_FORMALS); /* limits */ + DUK_ASSERT(h->length != DUK__NO_FORMALS); /* limits */ DUK_RAW_WRITEINC_U32_BE(p, h->length); for (i = 0; i < h->length; i++) { @@ -204,14 +214,14 @@ DUK_ASSERT(varname != NULL); DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(varname) >= 1); - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(varname), p); p = duk__dump_hstring_raw(p, varname); } } else { DUK_DD(DUK_DDPRINT("dumping function without _Formals, emit marker to indicate missing _Formals")); p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_RAW_WRITEINC_U32_BE(p, DUK__NO_FORMALS); /* marker: no formals */ + DUK_RAW_WRITEINC_U32_BE(p, DUK__NO_FORMALS); /* marker: no formals */ } return p; } @@ -245,7 +255,7 @@ (long) DUK_HCOMPFUNC_GET_CODE_SIZE(thr->heap, func), (long) DUK_HCOMPFUNC_GET_CODE_COUNT(thr->heap, func))); - DUK_ASSERT(DUK_USE_ESBC_MAX_BYTES <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_USE_ESBC_MAX_BYTES <= 0x7fffffffUL); /* ensures no overflow */ count_instr = (duk_uint32_t) DUK_HCOMPFUNC_GET_CODE_COUNT(thr->heap, func); p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 3U * 4U + 2U * 2U + 3U * 4U + count_instr * 4U, p); @@ -269,8 +279,8 @@ DUK_RAW_WRITEINC_U32_BE(p, 0); DUK_RAW_WRITEINC_U32_BE(p, 0); #endif - tmp32 = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) func); /* masks flags, only duk_hobject flags */ - tmp32 &= ~(DUK_HOBJECT_FLAG_HAVE_FINALIZER); /* finalizer flag is lost */ + tmp32 = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) func); /* masks flags, only duk_hobject flags */ + tmp32 &= ~(DUK_HOBJECT_FLAG_HAVE_FINALIZER); /* finalizer flag is lost */ DUK_RAW_WRITEINC_U32_BE(p, tmp32); /* Bytecode instructions: endian conversion needed unless @@ -280,8 +290,9 @@ ins_end = DUK_HCOMPFUNC_GET_CODE_END(thr->heap, func); DUK_ASSERT((duk_size_t) (ins_end - ins) == (duk_size_t) count_instr); #if defined(DUK_USE_INTEGER_BE) - duk_memcpy_unsafe((void *) p, (const void *) ins, (size_t) (ins_end - ins)); - p += (size_t) (ins_end - ins); + duk_memcpy_unsafe((void *) p, (const void *) ins, count_instr * sizeof(duk_instr_t)); + p += count_instr * sizeof(duk_instr_t); + DUK_UNREF(ins_end); #else while (ins != ins_end) { tmp32 = (duk_uint32_t) (*ins); @@ -295,13 +306,12 @@ tv_end = DUK_HCOMPFUNC_GET_CONSTS_END(thr->heap, func); while (tv != tv_end) { /* constants are strings or numbers now */ - DUK_ASSERT(DUK_TVAL_IS_STRING(tv) || - DUK_TVAL_IS_NUMBER(tv)); + DUK_ASSERT(DUK_TVAL_IS_STRING(tv) || DUK_TVAL_IS_NUMBER(tv)); if (DUK_TVAL_IS_STRING(tv)) { h_str = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h_str != NULL); - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 1U + 4U + DUK_HSTRING_GET_BYTELEN(h_str), p); *p++ = DUK__SER_STRING; p = duk__dump_hstring_raw(p, h_str); @@ -367,7 +377,8 @@ * are validated (which is quite complex, especially for indirect opcodes). */ -#define DUK__ASSERT_LEFT(n) do { \ +#define DUK__ASSERT_LEFT(n) \ + do { \ DUK_ASSERT((duk_size_t) (p_end - p) >= (duk_size_t) (n)); \ } while (0) @@ -402,13 +413,13 @@ count_const = DUK_RAW_READINC_U32_BE(p); count_funcs = DUK_RAW_READINC_U32_BE(p); - data_size = sizeof(duk_tval) * count_const + - sizeof(duk_hobject *) * count_funcs + - sizeof(duk_instr_t) * count_instr; + data_size = sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs + sizeof(duk_instr_t) * count_instr; DUK_DD(DUK_DDPRINT("instr=%ld, const=%ld, funcs=%ld, data_size=%ld", - (long) count_instr, (long) count_const, - (long) count_const, (long) data_size)); + (long) count_instr, + (long) count_const, + (long) count_const, + (long) data_size)); /* Value stack is used to ensure reachability of constants and * inner functions being loaded. Require enough space to handle @@ -434,12 +445,12 @@ h_fun->start_line = DUK_RAW_READINC_U32_BE(p); h_fun->end_line = DUK_RAW_READINC_U32_BE(p); #else - p += 8; /* skip line info */ + p += 8; /* skip line info */ #endif /* duk_hcompfunc flags; quite version specific */ tmp32 = DUK_RAW_READINC_U32_BE(p); - DUK_HEAPHDR_SET_FLAGS((duk_heaphdr *) h_fun, tmp32); /* masks flags to only change duk_hobject flags */ + DUK_HEAPHDR_SET_FLAGS((duk_heaphdr *) h_fun, tmp32); /* masks flags to only change duk_hobject flags */ /* standard prototype (no need to set here, already set) */ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_fun) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); @@ -467,9 +478,7 @@ DUK__ASSERT_LEFT(count_instr * sizeof(duk_instr_t)); #if defined(DUK_USE_INTEGER_BE) q = fun_data + sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs; - duk_memcpy((void *) q, - (const void *) p, - sizeof(duk_instr_t) * count_instr); + duk_memcpy((void *) q, (const void *) p, sizeof(duk_instr_t) * count_instr); p += sizeof(duk_instr_t) * count_instr; #else q = fun_data + sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs; @@ -528,13 +537,13 @@ DUK_HCOMPFUNC_SET_DATA(thr->heap, h_fun, h_data); DUK_HBUFFER_INCREF(thr, h_data); - tv1 = duk_get_tval(thr, idx_base + 2); /* may be NULL if no constants or inner funcs */ + tv1 = duk_get_tval(thr, idx_base + 2); /* may be NULL if no constants or inner funcs */ DUK_ASSERT((count_const == 0 && count_funcs == 0) || tv1 != NULL); q = fun_data; duk_memcpy_unsafe((void *) q, (const void *) tv1, sizeof(duk_tval) * count_const); for (n = count_const; n > 0; n--) { - DUK_TVAL_INCREF_FAST(thr, (duk_tval *) (void *) q); /* no side effects */ + DUK_TVAL_INCREF_FAST(thr, (duk_tval *) (void *) q); /* no side effects */ q += sizeof(duk_tval); } tv1 += count_const; @@ -567,7 +576,7 @@ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); #if defined(DUK_USE_FUNC_NAME_PROPERTY) - p = duk__load_string_raw(thr, p); /* -> func funcname */ + p = duk__load_string_raw(thr, p); /* -> func funcname */ func_env = thr->builtinsDUK_BIDX_GLOBAL_ENV; DUK_ASSERT(func_env != NULL); need_pop = 0; @@ -578,11 +587,10 @@ */ duk_hdecenv *new_env; - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); - DUK_ASSERT(new_env->thread == NULL); /* Closed. */ + DUK_ASSERT(new_env->thread == NULL); /* Closed. */ DUK_ASSERT(new_env->varmap == NULL); DUK_ASSERT(new_env->regbase_byteoff == 0); DUK_HDECENV_ASSERT_VALID(new_env); @@ -594,11 +602,11 @@ duk_push_hobject(thr, (duk_hobject *) new_env); - duk_dup_m2(thr); /* -> func funcname env funcname */ - duk_dup(thr, idx_base); /* -> func funcname env funcname func */ - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> func funcname env */ + duk_dup_m2(thr); /* -> func funcname env funcname */ + duk_dup(thr, idx_base); /* -> func funcname env funcname func */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> func funcname env */ - need_pop = 1; /* Need to pop env, but -after- updating h_fun and increfs. */ + need_pop = 1; /* Need to pop env, but -after- updating h_fun and increfs. */ } DUK_ASSERT(func_env != NULL); DUK_HCOMPFUNC_SET_LEXENV(thr->heap, h_fun, func_env); @@ -609,12 +617,12 @@ duk_pop(thr); } duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ #if defined(DUK_USE_FUNC_FILENAME_PROPERTY) p = duk__load_string_raw(thr, p); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_C); -#endif /* DUK_USE_FUNC_FILENAME_PROPERTY */ +#endif /* DUK_USE_FUNC_FILENAME_PROPERTY */ if (DUK_HOBJECT_HAS_CONSTRUCTABLE((duk_hobject *) h_fun)) { /* Restore empty external .prototype only for constructable @@ -624,7 +632,10 @@ duk_push_object(thr); DUK_ASSERT(!duk_is_bare_object(thr, -1)); duk_dup_m2(thr); - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC); /* func.prototype.constructor = func */ + duk_xdef_prop_stridx_short(thr, + -2, + DUK_STRIDX_CONSTRUCTOR, + DUK_PROPDESC_FLAGS_WC); /* func.prototype.constructor = func */ duk_compact_m1(thr); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); } @@ -632,9 +643,9 @@ #if defined(DUK_USE_PC2LINE) p = duk__load_buffer_raw(thr, p); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_WC); -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ - duk_push_bare_object(thr); /* _Varmap */ + duk_push_bare_object(thr); /* _Varmap */ for (;;) { /* XXX: awkward */ p = duk__load_string_raw(thr, p); @@ -654,7 +665,7 @@ */ arr_limit = DUK_RAW_READINC_U32_BE(p); if (arr_limit != DUK__NO_FORMALS) { - duk_push_bare_array(thr); /* _Formals */ + duk_push_bare_array(thr); /* _Formals */ for (arr_idx = 0; arr_idx < arr_limit; arr_idx++) { p = duk__load_string_raw(thr, p); duk_put_prop_index(thr, -2, arr_idx); @@ -670,7 +681,7 @@ DUK_ASSERT_TOP(thr, idx_base + 1); return p; - format_error: +format_error: return NULL; } @@ -702,7 +713,7 @@ DUK_DD(DUK_DDPRINT("serialized result: %!T", duk_get_tval(thr, -1))); - duk_remove_m2(thr); /* ... func buf -> ... buf */ + duk_remove_m2(thr); /* ... func buf -> ... buf */ } DUK_EXTERNAL void duk_load_function(duk_hthread *thr) { @@ -735,15 +746,15 @@ goto format_error; } - duk_remove_m2(thr); /* ... buf func -> ... func */ + duk_remove_m2(thr); /* ... buf func -> ... func */ return; - format_error: +format_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BYTECODE); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BYTECODE_DUMP_SUPPORT */ +#else /* DUK_USE_BYTECODE_DUMP_SUPPORT */ DUK_EXTERNAL void duk_dump_function(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); @@ -757,4 +768,4 @@ DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BYTECODE_DUMP_SUPPORT */ +#endif /* DUK_USE_BYTECODE_DUMP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_call.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_call.c
Changed
@@ -51,7 +51,7 @@ DUK_ASSERT(other >= 0); idx_func = duk_get_top(thr) - nargs - other; - if (DUK_UNLIKELY((idx_func | nargs) < 0)) { /* idx_func < 0 || nargs < 0; OR sign bits */ + if (DUK_UNLIKELY((idx_func | nargs) < 0)) { /* idx_func < 0 || nargs < 0; OR sign bits */ DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } @@ -85,12 +85,14 @@ DUK_ASSERT(nargs >= 0); DUK_DDD(DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_idx=%ld, nargs=%ld, stacktop=%ld", - (long) normalized_obj_idx, (long) nargs, (long) duk_get_top(thr))); + (long) normalized_obj_idx, + (long) nargs, + (long) duk_get_top(thr))); /* ... key arg1 ... argN */ /* duplicate key */ - duk_dup(thr, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */ + duk_dup(thr, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */ (void) duk_get_prop(thr, normalized_obj_idx); DUK_DDD(DUK_DDDPRINT("func: %!T", (duk_tval *) duk_get_tval(thr, -1))); @@ -133,7 +135,7 @@ duk_insert_undefined(thr, idx_func + 1); - call_flags = 0; /* not protected, respect reclimit, not constructor */ + call_flags = 0; /* not protected, respect reclimit, not constructor */ duk_handle_call_unprotected(thr, idx_func, call_flags); } @@ -146,7 +148,7 @@ idx_func = duk__call_get_idx_func(thr, nargs, 2); DUK_ASSERT(duk_is_valid_index(thr, idx_func)); - call_flags = 0; /* not protected, respect reclimit, not constructor */ + call_flags = 0; /* not protected, respect reclimit, not constructor */ duk_handle_call_unprotected(thr, idx_func, call_flags); } @@ -160,7 +162,7 @@ DUK_ASSERT_API_ENTRY(thr); - obj_idx = duk_require_normalize_index(thr, obj_idx); /* make absolute */ + obj_idx = duk_require_normalize_index(thr, obj_idx); /* make absolute */ if (DUK_UNLIKELY(nargs < 0)) { DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return;); @@ -258,7 +260,7 @@ args = (duk__pcall_prop_args *) udata; - obj_idx = duk_require_normalize_index(thr, args->obj_idx); /* make absolute */ + obj_idx = duk_require_normalize_index(thr, args->obj_idx); /* make absolute */ duk__call_prop_prep_stack(thr, obj_idx, args->nargs); ret = duk_handle_call_unprotected_nargs(thr, args->nargs, args->call_flags); @@ -296,30 +298,30 @@ */ /* XXX: check for any reserve? */ - if (DUK_UNLIKELY((nargs | nrets) < 0 || /* nargs < 0 || nrets < 0; OR sign bits */ - thr->valstack_top < thr->valstack_bottom + nargs || /* nargs too large compared to top */ - thr->valstack_end + nargs < thr->valstack_top + nrets)) { /* nrets too large compared to reserve */ + if (DUK_UNLIKELY((nargs | nrets) < 0 || /* nargs < 0 || nrets < 0; OR sign bits */ + thr->valstack_top < thr->valstack_bottom + nargs || /* nargs too large compared to top */ + thr->valstack_end + nargs < thr->valstack_top + nrets)) { /* nrets too large compared to reserve */ DUK_D(DUK_DPRINT("not enough stack reserve for safe call or invalid arguments: " "nargs=%ld < 0 (?), nrets=%ld < 0 (?), top=%ld < bottom=%ld + nargs=%ld (?), " "end=%ld + nargs=%ld < top=%ld + nrets=%ld (?)", - (long) nargs, - (long) nrets, - (long) (thr->valstack_top - thr->valstack), - (long) (thr->valstack_bottom - thr->valstack), - (long) nargs, - (long) (thr->valstack_end - thr->valstack), - (long) nargs, - (long) (thr->valstack_top - thr->valstack), - (long) nrets)); + (long) nargs, + (long) nrets, + (long) (thr->valstack_top - thr->valstack), + (long) (thr->valstack_bottom - thr->valstack), + (long) nargs, + (long) (thr->valstack_end - thr->valstack), + (long) nargs, + (long) (thr->valstack_top - thr->valstack), + (long) nrets)); DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return DUK_EXEC_ERROR;); } - rc = duk_handle_safe_call(thr, /* thread */ - func, /* func */ - udata, /* udata */ - nargs, /* num_stack_args */ - nrets); /* num_stack_res */ + rc = duk_handle_safe_call(thr, /* thread */ + func, /* func */ + udata, /* udata */ + nargs, /* num_stack_args */ + nrets); /* num_stack_res */ return rc; } @@ -332,7 +334,7 @@ idx_func = duk__call_get_idx_func(thr, nargs, 1); DUK_ASSERT(duk_is_valid_index(thr, idx_func)); - duk_push_object(thr); /* default instance; internal proto updated by call handling */ + duk_push_object(thr); /* default instance; internal proto updated by call handling */ duk_insert(thr, idx_func + 1); duk_handle_call_unprotected(thr, idx_func, DUK_CALL_FLAG_CONSTRUCT); @@ -460,7 +462,7 @@ } /* fall through */ - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_UNEXPECTED_TYPE); DUK_WO_NORETURN(return 0;); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_codec.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_codec.c
Changed
@@ -18,15 +18,16 @@ * is guaranteed to be non-NULL, even for zero length input. */ DUK_LOCAL const duk_uint8_t *duk__prep_codec_arg(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) { - const void *def_ptr = (const void *) out_len; /* Any non-NULL pointer will do. */ + const void *def_ptr = (const void *) out_len; /* Any non-NULL pointer will do. */ const void *ptr; duk_bool_t isbuffer; DUK_ASSERT(out_len != NULL); DUK_ASSERT(def_ptr != NULL); - DUK_ASSERT(duk_is_valid_index(thr, idx)); /* checked by caller */ + DUK_ASSERT(duk_is_valid_index(thr, idx)); /* checked by caller */ - ptr = (const void *) duk_get_buffer_data_raw(thr, idx, out_len, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, &isbuffer); + ptr = (const void *) + duk_get_buffer_data_raw(thr, idx, out_len, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, &isbuffer); if (isbuffer) { DUK_ASSERT(ptr != NULL || *out_len == 0U); if (DUK_UNLIKELY(ptr == NULL)) { @@ -51,21 +52,21 @@ #if defined(DUK_USE_BASE64_SUPPORT) /* Bytes emitted for number of padding characters in range 0,4. */ DUK_LOCAL const duk_int8_t duk__base64_decode_nequal_step5 = { - 3, /* #### -> 24 bits, emit 3 bytes */ - 2, /* ###= -> 18 bits, emit 2 bytes */ - 1, /* ##== -> 12 bits, emit 1 byte */ - -1, /* #=== -> 6 bits, error */ - 0, /* ==== -> 0 bits, emit 0 bytes */ + 3, /* #### -> 24 bits, emit 3 bytes */ + 2, /* ###= -> 18 bits, emit 2 bytes */ + 1, /* ##== -> 12 bits, emit 1 byte */ + -1, /* #=== -> 6 bits, error */ + 0, /* ==== -> 0 bits, emit 0 bytes */ }; #if defined(DUK_USE_BASE64_FASTPATH) DUK_LOCAL const duk_uint8_t duk__base64_enctab_fast64 = { - 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x50U, /* A...P */ - 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x58U, 0x59U, 0x5aU, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, /* Q...f */ - 0x67U, 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, 0x6fU, 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, /* g...v */ - 0x77U, 0x78U, 0x79U, 0x7aU, 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x2bU, 0x2fU /* w.../ */ + 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x50U, /* A...P */ + 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x58U, 0x59U, 0x5aU, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, /* Q...f */ + 0x67U, 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, 0x6fU, 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, /* g...v */ + 0x77U, 0x78U, 0x79U, 0x7aU, 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x2bU, 0x2fU /* w.../ */ }; -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) /* Decode table for one byte of input: @@ -75,24 +76,24 @@ * 0...63 decoded bytes */ DUK_LOCAL const duk_int8_t duk__base64_dectab_fast256 = { - -3, -3, -3, -3, -3, -3, -3, -3, -3, -1, -1, -3, -3, -1, -3, -3, /* 0x00...0x0f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x10...0x1f */ - -1, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 62, -3, -3, -3, 63, /* 0x20...0x2f */ - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -3, -3, -3, -2, -3, -3, /* 0x30...0x3f */ - -3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40...0x4f */ - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -3, -3, -3, -3, -3, /* 0x50...0x5f */ - -3, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60...0x6f */ - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -3, -3, -3, -3, -3, /* 0x70...0x7f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x80...0x8f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x90...0x9f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xa0...0xaf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xb0...0xbf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xc0...0xcf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xd0...0xdf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xe0...0xef */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3 /* 0xf0...0xff */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -1, -1, -3, -3, -1, -3, -3, /* 0x00...0x0f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x10...0x1f */ + -1, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 62, -3, -3, -3, 63, /* 0x20...0x2f */ + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -3, -3, -3, -2, -3, -3, /* 0x30...0x3f */ + -3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40...0x4f */ + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -3, -3, -3, -3, -3, /* 0x50...0x5f */ + -3, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60...0x6f */ + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -3, -3, -3, -3, -3, /* 0x70...0x7f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x80...0x8f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x90...0x9f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xa0...0xaf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xb0...0xbf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xc0...0xcf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xd0...0xdf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xe0...0xef */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3 /* 0xf0...0xff */ }; -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) DUK_LOCAL DUK_ALWAYS_INLINE void duk__base64_encode_fast_3(const duk_uint8_t *src, duk_uint8_t *dst) { @@ -124,9 +125,9 @@ t = (duk_uint_t) src0; t = (t << 8) + (duk_uint_t) src1; - dst0 = duk__base64_enctab_fastt >> 10; /* XXXXXX-- -------- */ - dst1 = duk__base64_enctab_fast(t >> 4) & 0x3fU; /* ------XX XXXX---- */ - dst2 = duk__base64_enctab_fast(t << 2) & 0x3fU; /* -------- ----XXXX */ + dst0 = duk__base64_enctab_fastt >> 10; /* XXXXXX-- -------- */ + dst1 = duk__base64_enctab_fast(t >> 4) & 0x3fU; /* ------XX XXXX---- */ + dst2 = duk__base64_enctab_fast(t << 2) & 0x3fU; /* -------- ----XXXX */ dst3 = DUK_ASC_EQUALS; } @@ -134,8 +135,8 @@ duk_uint_t t; t = (duk_uint_t) src0; - dst0 = duk__base64_enctab_fastt >> 2; /* XXXXXX-- */ - dst1 = duk__base64_enctab_fast(t << 4) & 0x3fU; /* ------XX */ + dst0 = duk__base64_enctab_fastt >> 2; /* XXXXXX-- */ + dst1 = duk__base64_enctab_fast(t << 4) & 0x3fU; /* ------XX */ dst2 = DUK_ASC_EQUALS; dst3 = DUK_ASC_EQUALS; } @@ -183,24 +184,24 @@ DUK_ASSERT(n == 0U || n == 1U || n == 2U); if (n == 1U) { duk__base64_encode_fast_1(p, q); -#if 0 /* Unnecessary. */ +#if 0 /* Unnecessary. */ p += 1; q += 4; n -= 1U; #endif } else if (n == 2U) { duk__base64_encode_fast_2(p, q); -#if 0 /* Unnecessary. */ +#if 0 /* Unnecessary. */ p += 2; q += 4; n -= 2U; #endif } else { - DUK_ASSERT(n == 0U); /* nothing to do */ + DUK_ASSERT(n == 0U); /* nothing to do */ ; } } -#else /* DUK_USE_BASE64_FASTPATH */ +#else /* DUK_USE_BASE64_FASTPATH */ DUK_LOCAL void duk__base64_encode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst) { duk_small_uint_t i, npad; duk_uint_t t, x, y; @@ -272,10 +273,13 @@ npad--; } } -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) -DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst, duk_uint8_t **out_dst_final) { +DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, + duk_size_t srclen, + duk_uint8_t *dst, + duk_uint8_t **out_dst_final) { duk_int_t x; duk_uint_t t; duk_small_uint_t n_equal; @@ -285,11 +289,11 @@ const duk_uint8_t *p_end_safe; duk_uint8_t *q; - DUK_ASSERT(src != NULL); /* Required by pointer arithmetic below, which fails for NULL. */ + DUK_ASSERT(src != NULL); /* Required by pointer arithmetic below, which fails for NULL. */ p = src; p_end = src + srclen; - p_end_safe = p_end - 8; /* If 'src <= src_end_safe', safe to read 8 bytes. */ + p_end_safe = p_end - 8; /* If 'src <= src_end_safe', safe to read 8 bytes. */ q = dst; /* Alternate between a fast path which processes clean groups with no @@ -319,7 +323,9 @@ * bytes to minimize aliasing. */ DUK_DDD(DUK_DDDPRINT("fast loop: p=%p, p_end_safe=%p, p_end=%p", - (const void *) p, (const void *) p_end_safe, (const void *) p_end)); + (const void *) p, + (const void *) p_end_safe, + (const void *) p_end)); t1 = (duk_int_t) duk__base64_dectab_fastp0; t1 = (duk_int_t) ((duk_uint_t) t1 << 6) | (duk_int_t) duk__base64_dectab_fastp1; @@ -344,17 +350,19 @@ p += 8; q += 6; } else if (t1 >= 0) { - DUK_DDD(DUK_DDDPRINT("fast loop first group was clean, second was not, process one slow path group")); + DUK_DDD( + DUK_DDDPRINT("fast loop first group was clean, second was not, process one slow path group")); DUK_ASSERT(t2 < 0); p += 4; q += 3; break; } else { - DUK_DDD(DUK_DDDPRINT("fast loop first group was not clean, second does not matter, process one slow path group")); + DUK_DDD(DUK_DDDPRINT( + "fast loop first group was not clean, second does not matter, process one slow path group")); DUK_ASSERT(t1 < 0); break; } - } /* fast path */ + } /* fast path */ /* Slow path step 1: try to scan a 4-character encoded group, * end-of-input, or start-of-padding. We exit with: @@ -369,7 +377,9 @@ t = 1UL; for (;;) { DUK_DDD(DUK_DDDPRINT("slow loop: p=%p, p_end=%p, t=%lu", - (const void *) p, (const void *) p_end, (unsigned long) t)); + (const void *) p, + (const void *) p_end, + (unsigned long) t)); if (DUK_LIKELY(p < p_end)) { x = duk__base64_dectab_fast*p++; @@ -380,18 +390,18 @@ break; } } else if (x == -1) { - continue; /* allowed ascii whitespace */ + continue; /* allowed ascii whitespace */ } else if (x == -2) { p--; - break; /* start of padding */ + break; /* start of padding */ } else { DUK_ASSERT(x == -3); goto decode_error; } } else { - break; /* end of input */ + break; /* end of input */ } - } /* slow path step 1 */ + } /* slow path step 1 */ /* Complete the padding by simulating pad characters, * regardless of actual input padding chars. @@ -450,28 +460,30 @@ } x = duk__base64_dectab_fast*p++; if (x == -1 || x == -2) { - ; /* padding or whitespace, keep eating */ + ; /* padding or whitespace, keep eating */ } else { p--; - break; /* backtrack and go back to fast path, even for -1 */ + break; /* backtrack and go back to fast path, even for -1 */ } - } /* slow path step 3 */ - } /* outer fast+slow path loop */ + } /* slow path step 3 */ + } /* outer fast+slow path loop */ - done: - DUK_DDD(DUK_DDDPRINT("done; p=%p, p_end=%p", - (const void *) p, (const void *) p_end)); +done: + DUK_DDD(DUK_DDDPRINT("done; p=%p, p_end=%p", (const void *) p, (const void *) p_end)); DUK_ASSERT(p == p_end); *out_dst_final = q; return 1; - decode_error: +decode_error: return 0; } -#else /* DUK_USE_BASE64_FASTPATH */ -DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst, duk_uint8_t **out_dst_final) { +#else /* DUK_USE_BASE64_FASTPATH */ +DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, + duk_size_t srclen, + duk_uint8_t *dst, + duk_uint8_t **out_dst_final) { duk_uint_t t, x; duk_int_t y; duk_int8_t step; @@ -557,7 +569,7 @@ } else { /* Valid: whitespace. */ duk_uint32_t m; - DUK_ASSERT(x < 0x20U); /* 0x00 to 0x1f */ + DUK_ASSERT(x < 0x20U); /* 0x00 to 0x1f */ m = (1U << x); if (mask_white & m) { /* Allow basic ASCII whitespace. */ @@ -574,7 +586,7 @@ } /* fall through; no padding will be added */ - simulate_padding: + simulate_padding: n_equal = 0; while (t < 0x1000000UL) { t = (t << 6) + 0U; @@ -606,10 +618,10 @@ *out_dst_final = q; return 1; - decode_error: +decode_error: return 0; } -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ DUK_EXTERNAL const char *duk_base64_encode(duk_hthread *thr, duk_idx_t idx) { const duk_uint8_t *src; @@ -638,11 +650,11 @@ duk__base64_encode_helper((const duk_uint8_t *) src, srclen, dst); - ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ + ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ duk_replace(thr, idx); return ret; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_BASE64_ENCODE_FAILED); DUK_WO_NORETURN(return NULL;); } @@ -667,7 +679,7 @@ * Similarly, 'xx' may ecause 1+3 = bytes to be emitted and then * backtracked. */ - dstlen = (srclen / 4) * 3 + 6; /* upper limit, assuming no whitespace etc */ + dstlen = (srclen / 4) * 3 + 6; /* upper limit, assuming no whitespace etc */ dst = (duk_uint8_t *) duk_push_dynamic_buffer(thr, dstlen); /* Note: for dstlen=0, dst may be NULL */ @@ -680,11 +692,11 @@ duk_replace(thr, idx); return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_BASE64_DECODE_FAILED); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BASE64_SUPPORT */ +#else /* DUK_USE_BASE64_SUPPORT */ DUK_EXTERNAL const char *duk_base64_encode(duk_hthread *thr, duk_idx_t idx) { DUK_UNREF(idx); DUK_ERROR_UNSUPPORTED(thr); @@ -696,7 +708,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BASE64_SUPPORT */ +#endif /* DUK_USE_BASE64_SUPPORT */ /* * Hex @@ -725,7 +737,7 @@ DUK_ASSERT(buf != NULL); #if defined(DUK_USE_HEX_FASTPATH) - DUK_ASSERT((((duk_size_t) buf) & 0x01U) == 0); /* pointer is aligned, guaranteed for fixed buffer */ + DUK_ASSERT((((duk_size_t) buf) & 0x01U) == 0); /* pointer is aligned, guaranteed for fixed buffer */ p16 = (duk_uint16_t *) (void *) buf; len_safe = len & ~0x03U; for (i = 0; i < len_safe; i += 4) { @@ -738,14 +750,14 @@ for (; i < len; i++) { *p16++ = duk_hex_enctabinpi; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ for (i = 0; i < len; i++) { duk_small_uint_t t; t = (duk_small_uint_t) inpi; - bufi*2 + 0 = duk_lc_digitst >> 4; - bufi*2 + 1 = duk_lc_digitst & 0x0f; + bufi * 2 + 0 = duk_lc_digitst >> 4; + bufi * 2 + 1 = duk_lc_digitst & 0x0f; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ /* XXX: Using a string return value forces a string intern which is * not always necessary. As a rough performance measure, hex encode @@ -754,7 +766,7 @@ * caller coerce to string if necessary? */ - ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ + ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ duk_replace(thr, idx); return ret; } @@ -789,20 +801,16 @@ p = buf; len_safe = len & ~0x07U; for (i = 0; i < len_safe; i += 8) { - t = ((duk_int_t) duk_hex_dectab_shift4inpi) | - ((duk_int_t) duk_hex_dectabinpi + 1); + t = ((duk_int_t) duk_hex_dectab_shift4inpi) | ((duk_int_t) duk_hex_dectabinpi + 1); chk = t; p0 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 2) | - ((duk_int_t) duk_hex_dectabinpi + 3); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 2) | ((duk_int_t) duk_hex_dectabinpi + 3); chk |= t; p1 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 4) | - ((duk_int_t) duk_hex_dectabinpi + 5); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 4) | ((duk_int_t) duk_hex_dectabinpi + 5); chk |= t; p2 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 6) | - ((duk_int_t) duk_hex_dectabinpi + 7); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 6) | ((duk_int_t) duk_hex_dectabinpi + 7); chk |= t; p3 = (duk_uint8_t) t; p += 4; @@ -824,7 +832,7 @@ } *p++ = (duk_uint8_t) t; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ for (i = 0; i < len; i += 2) { /* For invalid characters the value -1 gets extended to * at least 16 bits. If either nybble is invalid, the @@ -837,16 +845,16 @@ } bufi >> 1 = (duk_uint8_t) t; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ duk_replace(thr, idx); return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_HEX_DECODE_FAILED); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_HEX_SUPPORT */ +#else /* DUK_USE_HEX_SUPPORT */ DUK_EXTERNAL const char *duk_hex_encode(duk_hthread *thr, duk_idx_t idx) { DUK_UNREF(idx); DUK_ERROR_UNSUPPORTED(thr); @@ -857,7 +865,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_HEX_SUPPORT */ +#endif /* DUK_USE_HEX_SUPPORT */ /* * JSON @@ -901,15 +909,12 @@ #endif idx = duk_require_normalize_index(thr, idx); - duk_bi_json_parse_helper(thr, - idx /*idx_value*/, - DUK_INVALID_INDEX /*idx_reviver*/, - 0 /*flags*/); + duk_bi_json_parse_helper(thr, idx /*idx_value*/, DUK_INVALID_INDEX /*idx_reviver*/, 0 /*flags*/); duk_replace(thr, idx); DUK_ASSERT(duk_get_top(thr) == top_at_entry); } -#else /* DUK_USE_JSON_SUPPORT */ +#else /* DUK_USE_JSON_SUPPORT */ DUK_EXTERNAL const char *duk_json_encode(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx); @@ -923,4 +928,4 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_compile.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_compile.c
Changed
@@ -6,7 +6,7 @@ typedef struct duk__compile_raw_args duk__compile_raw_args; struct duk__compile_raw_args { - duk_size_t src_length; /* should be first on 64-bit platforms */ + duk_size_t src_length; /* should be first on 64-bit platforms */ const duk_uint8_t *src_buffer; duk_uint_t flags; }; @@ -26,7 +26,10 @@ /* ... source? filename? (depends on flags) */ - rc = duk_compile_raw(thr, src_buffer, src_length, flags | DUK_COMPILE_EVAL); /* may be safe, or non-safe depending on flags */ + rc = duk_compile_raw(thr, + src_buffer, + src_length, + flags | DUK_COMPILE_EVAL); /* may be safe, or non-safe depending on flags */ /* ... closure/error */ @@ -35,7 +38,7 @@ goto got_rc; } - duk_push_global_object(thr); /* explicit 'this' binding, see GH-164 */ + duk_push_global_object(thr); /* explicit 'this' binding, see GH-164 */ if (flags & DUK_COMPILE_SAFE) { rc = duk_pcall_method(thr, 0); @@ -46,7 +49,7 @@ /* ... result/error */ - got_rc: +got_rc: if (flags & DUK_COMPILE_NORESULT) { duk_pop(thr); } @@ -86,8 +89,8 @@ duk_hstring *h_sourcecode; h_sourcecode = duk_get_hstring(thr, -2); - if ((flags & DUK_COMPILE_NOSOURCE) || /* args incorrect */ - (h_sourcecode == NULL)) { /* e.g. duk_push_string_file_raw() pushed undefined */ + if ((flags & DUK_COMPILE_NOSOURCE) || /* args incorrect */ + (h_sourcecode == NULL)) { /* e.g. duk_push_string_file_raw() pushed undefined */ DUK_ERROR_TYPE(thr, DUK_STR_NO_SOURCECODE); DUK_WO_NORETURN(return 0;); } @@ -117,11 +120,11 @@ h_templ = (duk_hcompfunc *) duk_known_hobject(thr, -1); duk_js_push_closure(thr, - h_templ, - thr->builtinsDUK_BIDX_GLOBAL_ENV, - thr->builtinsDUK_BIDX_GLOBAL_ENV, - 1 /*add_auto_proto*/); - duk_remove_m2(thr); /* -> ... closure */ + h_templ, + thr->builtinsDUK_BIDX_GLOBAL_ENV, + thr->builtinsDUK_BIDX_GLOBAL_ENV, + 1 /*add_auto_proto*/); + duk_remove_m2(thr); /* -> ... closure */ /* ... closure */ @@ -157,8 +160,7 @@ * directly into flags. */ nargs = flags & 0x07; - DUK_ASSERT(nargs == ((flags & DUK_COMPILE_NOSOURCE) ? 0 : 1) + - ((flags & DUK_COMPILE_NOFILENAME) ? 0 : 1)); + DUK_ASSERT(nargs == ((flags & DUK_COMPILE_NOSOURCE) ? 0 : 1) + ((flags & DUK_COMPILE_NOFILENAME) ? 0 : 1)); rc = duk_safe_call(thr, duk__do_compile, (void *) comp_args, nargs, nrets); /* ... closure */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_debug.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_debug.c
Changed
@@ -26,25 +26,24 @@ * Perhaps values need to be coerced individually? */ duk_bi_json_stringify_helper(thr, - duk_get_top_index(thr), /*idx_value*/ - DUK_INVALID_INDEX, /*idx_replacer*/ - DUK_INVALID_INDEX, /*idx_space*/ - DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_ASCII_ONLY | - DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); + duk_get_top_index(thr), /*idx_value*/ + DUK_INVALID_INDEX, /*idx_replacer*/ + DUK_INVALID_INDEX, /*idx_space*/ + DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_ASCII_ONLY | + DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); duk_push_sprintf(thr, "ctx: top=%ld, stack=%s", (long) top, (const char *) duk_safe_to_string(thr, -1)); - duk_replace(thr, -3); /* ... arr jsonx(arr) res -> ... res jsonx(arr) */ + duk_replace(thr, -3); /* ... arr jsonx(arr) res -> ... res jsonx(arr) */ duk_pop(thr); DUK_ASSERT(duk_is_string(thr, -1)); } -#else /* DUK_USE_JSON_SUPPORT */ +#else /* DUK_USE_JSON_SUPPORT */ DUK_EXTERNAL void duk_push_context_dump(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */ #if defined(DUK_USE_DEBUGGER_SUPPORT) @@ -93,12 +92,13 @@ heap->dbg_exec_counter = 0; heap->dbg_last_counter = 0; heap->dbg_last_time = 0.0; - duk_debug_set_paused(heap); /* XXX: overlap with fields above */ + duk_debug_set_paused(heap); /* XXX: overlap with fields above */ /* Send version identification and flush right afterwards. Note that * we must write raw, unframed bytes here. */ - duk_push_sprintf(thr, "%ld %ld %s %s\n", + duk_push_sprintf(thr, + "%ld %ld %s %s\n", (long) DUK_DEBUG_PROTOCOL_VERSION, (long) DUK_VERSION, (const char *) DUK_GIT_DESCRIBE, @@ -200,7 +200,7 @@ } } -#else /* DUK_USE_DEBUGGER_SUPPORT */ +#else /* DUK_USE_DEBUGGER_SUPPORT */ DUK_EXTERNAL void duk_debugger_attach(duk_hthread *thr, duk_debug_read_function read_cb, @@ -258,4 +258,4 @@ DUK_UNREF(thr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_heap.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_heap.c
Changed
@@ -85,7 +85,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(state != NULL); /* unvalidated */ + DUK_ASSERT(state != NULL); /* unvalidated */ /* Currently not supported when called from within a finalizer. * If that is done, the finalizer will remain running indefinitely, @@ -129,7 +129,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(state != NULL); /* unvalidated */ + DUK_ASSERT(state != NULL); /* unvalidated */ /* Shouldn't be necessary if duk_suspend() is called before * duk_resume(), but assert in case API sequence is incorrect. @@ -171,7 +171,7 @@ DUK_UNREF(h_prev_glob); thr->builtinsDUK_BIDX_GLOBAL = h_glob; DUK_HOBJECT_INCREF(thr, h_glob); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_glob); /* side effects, in theory (referenced by global env) */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_glob); /* side effects, in theory (referenced by global env) */ /* * Replace lexical environment for global scope @@ -182,9 +182,7 @@ * same (initial) built-ins. */ - h_env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + h_env = duk_hobjenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(h_env != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_env) == NULL); @@ -199,8 +197,8 @@ h_prev_env = thr->builtinsDUK_BIDX_GLOBAL_ENV; thr->builtinsDUK_BIDX_GLOBAL_ENV = (duk_hobject *) h_env; DUK_HOBJECT_INCREF(thr, (duk_hobject *) h_env); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_env); /* side effects */ - DUK_UNREF(h_env); /* without refcounts */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_env); /* side effects */ + DUK_UNREF(h_env); /* without refcounts */ DUK_UNREF(h_prev_env); /* ... new_glob */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_inspect.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_inspect.c
Changed
@@ -39,20 +39,20 @@ * be security implications. */ -#define DUK__IDX_TYPE 0 -#define DUK__IDX_ITAG 1 -#define DUK__IDX_REFC 2 -#define DUK__IDX_HBYTES 3 -#define DUK__IDX_CLASS 4 -#define DUK__IDX_PBYTES 5 -#define DUK__IDX_ESIZE 6 -#define DUK__IDX_ENEXT 7 -#define DUK__IDX_ASIZE 8 -#define DUK__IDX_HSIZE 9 -#define DUK__IDX_BCBYTES 10 -#define DUK__IDX_DBYTES 11 -#define DUK__IDX_TSTATE 12 -#define DUK__IDX_VARIANT 13 +#define DUK__IDX_TYPE 0 +#define DUK__IDX_ITAG 1 +#define DUK__IDX_REFC 2 +#define DUK__IDX_HBYTES 3 +#define DUK__IDX_CLASS 4 +#define DUK__IDX_PBYTES 5 +#define DUK__IDX_ESIZE 6 +#define DUK__IDX_ENEXT 7 +#define DUK__IDX_ASIZE 8 +#define DUK__IDX_HSIZE 9 +#define DUK__IDX_BCBYTES 10 +#define DUK__IDX_DBYTES 11 +#define DUK__IDX_TSTATE 12 +#define DUK__IDX_VARIANT 13 DUK_EXTERNAL void duk_inspect_value(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; @@ -67,7 +67,7 @@ /* Assume two's complement and set everything to -1. */ duk_memset((void *) &vals, (int) 0xff, sizeof(vals)); - DUK_ASSERT(valsDUK__IDX_TYPE == -1); /* spot check one */ + DUK_ASSERT(valsDUK__IDX_TYPE == -1); /* spot check one */ tv = duk_get_tval_or_unused(thr, idx); h = (DUK_TVAL_IS_HEAP_ALLOCATED(tv) ? DUK_TVAL_GET_HEAPHDR(tv) : NULL); @@ -75,7 +75,7 @@ valsDUK__IDX_TYPE = duk_get_type_tval(tv); valsDUK__IDX_ITAG = (duk_int_t) DUK_TVAL_GET_TAG(tv); - duk_push_bare_object(thr); /* Invalidates 'tv'. */ + duk_push_bare_object(thr); /* Invalidates 'tv'. */ tv = NULL; if (h == NULL) { @@ -157,30 +157,56 @@ if (DUK_HBUFFER_HAS_DYNAMIC(h_buf)) { if (DUK_HBUFFER_HAS_EXTERNAL(h_buf)) { - valsDUK__IDX_VARIANT = 2; /* buffer variant 2: external */ + valsDUK__IDX_VARIANT = 2; /* buffer variant 2: external */ valsDUK__IDX_HBYTES = (duk_uint_t) (sizeof(duk_hbuffer_external)); } else { /* When alloc_size == 0 the second allocation may not * actually exist. */ - valsDUK__IDX_VARIANT = 1; /* buffer variant 1: dynamic */ + valsDUK__IDX_VARIANT = 1; /* buffer variant 1: dynamic */ valsDUK__IDX_HBYTES = (duk_uint_t) (sizeof(duk_hbuffer_dynamic)); } valsDUK__IDX_DBYTES = (duk_int_t) (DUK_HBUFFER_GET_SIZE(h_buf)); } else { - DUK_ASSERT(valsDUK__IDX_VARIANT == 0); /* buffer variant 0: fixed */ + DUK_ASSERT(valsDUK__IDX_VARIANT == 0); /* buffer variant 0: fixed */ valsDUK__IDX_HBYTES = (duk_int_t) (sizeof(duk_hbuffer_fixed) + DUK_HBUFFER_GET_SIZE(h_buf)); } break; } } - finish: +finish: duk__inspect_multiple_uint(thr, - "type" "\x00" "itag" "\x00" "refc" "\x00" "hbytes" "\x00" "class" "\x00" - "pbytes" "\x00" "esize" "\x00" "enext" "\x00" "asize" "\x00" "hsize" "\x00" - "bcbytes" "\x00" "dbytes" "\x00" "tstate" "\x00" "variant" "\x00" "\x00", - (duk_int_t *) &vals); + "type" + "\x00" + "itag" + "\x00" + "refc" + "\x00" + "hbytes" + "\x00" + "class" + "\x00" + "pbytes" + "\x00" + "esize" + "\x00" + "enext" + "\x00" + "asize" + "\x00" + "hsize" + "\x00" + "bcbytes" + "\x00" + "dbytes" + "\x00" + "tstate" + "\x00" + "variant" + "\x00" + "\x00", + (duk_int_t *) &vals); } DUK_EXTERNAL void duk_inspect_callstack_entry(duk_hthread *thr, duk_int_t level) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_internal.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_internal.h
Changed
@@ -12,9 +12,9 @@ #define DUK_ALWAYS_INLINE_PERF #define DUK_NOINLINE_PERF #else -#define DUK_INLINE_PERF DUK_INLINE +#define DUK_INLINE_PERF DUK_INLINE #define DUK_ALWAYS_INLINE_PERF DUK_ALWAYS_INLINE -#define DUK_NOINLINE_PERF DUK_NOINLINE +#define DUK_NOINLINE_PERF DUK_NOINLINE #endif /* Inline macro helpers, for bytecode executor. */ @@ -23,19 +23,19 @@ #define DUK_EXEC_ALWAYS_INLINE_PERF #define DUK_EXEC_NOINLINE_PERF #else -#define DUK_EXEC_INLINE_PERF DUK_INLINE +#define DUK_EXEC_INLINE_PERF DUK_INLINE #define DUK_EXEC_ALWAYS_INLINE_PERF DUK_ALWAYS_INLINE -#define DUK_EXEC_NOINLINE_PERF DUK_NOINLINE +#define DUK_EXEC_NOINLINE_PERF DUK_NOINLINE #endif /* duk_push_sprintf constants */ -#define DUK_PUSH_SPRINTF_INITIAL_SIZE 256L -#define DUK_PUSH_SPRINTF_SANITY_LIMIT (1L * 1024L * 1024L * 1024L) +#define DUK_PUSH_SPRINTF_INITIAL_SIZE 256L +#define DUK_PUSH_SPRINTF_SANITY_LIMIT (1L * 1024L * 1024L * 1024L) /* Flag ORed to err_code to indicate __FILE__ / __LINE__ is not * blamed as source of error for error fileName / lineNumber. */ -#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE (1L << 24) +#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE (1L << 24) /* Current convention is to use duk_size_t for value stack sizes and global indices, * and duk_idx_t for local frame indices. @@ -97,24 +97,17 @@ DUK_INTERNAL_DECL duk_tval *duk_get_borrowed_this_tval(duk_hthread *thr); /* XXX: add fastint support? */ -#define duk_push_u64(thr,val) \ - duk_push_number((thr), (duk_double_t) (val)) -#define duk_push_i64(thr,val) \ - duk_push_number((thr), (duk_double_t) (val)) +#define duk_push_u64(thr, val) duk_push_number((thr), (duk_double_t) (val)) +#define duk_push_i64(thr, val) duk_push_number((thr), (duk_double_t) (val)) /* duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range */ -#define duk_push_u32(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) -#define duk_push_i32(thr,val) \ - duk_push_int((thr), (duk_int_t) (val)) +#define duk_push_u32(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) +#define duk_push_i32(thr, val) duk_push_int((thr), (duk_int_t) (val)) /* sometimes stack and array indices need to go on the stack */ -#define duk_push_idx(thr,val) \ - duk_push_int((thr), (duk_int_t) (val)) -#define duk_push_uarridx(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) -#define duk_push_size_t(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) /* XXX: assumed to fit for now */ +#define duk_push_idx(thr, val) duk_push_int((thr), (duk_int_t) (val)) +#define duk_push_uarridx(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) +#define duk_push_size_t(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) /* XXX: assumed to fit for now */ DUK_INTERNAL_DECL duk_bool_t duk_is_string_notsymbol(duk_hthread *thr, duk_idx_t idx); @@ -131,19 +124,23 @@ DUK_INTERNAL_DECL duk_hcompfunc *duk_get_hcompfunc(duk_hthread *thr, duk_idx_t idx); DUK_INTERNAL_DECL duk_hnatfunc *duk_get_hnatfunc(duk_hthread *thr, duk_idx_t idx); -DUK_INTERNAL_DECL void *duk_get_buffer_data_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len, duk_bool_t throw_flag, duk_bool_t *out_isbuffer); +DUK_INTERNAL_DECL void *duk_get_buffer_data_raw(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_len, + duk_bool_t throw_flag, + duk_bool_t *out_isbuffer); DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_with_class(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t classnum); DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_accept_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); -#define duk_require_hobject_promote_lfunc(thr,idx) \ - duk_require_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) -#define duk_get_hobject_promote_lfunc(thr,idx) \ - duk_get_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) +#define duk_require_hobject_promote_lfunc(thr, idx) duk_require_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) +#define duk_get_hobject_promote_lfunc(thr, idx) duk_get_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL void *duk_get_voidptr(duk_hthread *thr, duk_idx_t idx); #endif @@ -166,12 +163,16 @@ DUK_INTERNAL_DECL duk_bool_t duk_to_boolean_top_pop(duk_hthread *thr); -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ DUK_INTERNAL_DECL duk_hstring *duk_safe_to_hstring(duk_hthread *thr, duk_idx_t idx); #endif DUK_INTERNAL_DECL void duk_push_class_string_tval(duk_hthread *thr, duk_tval *tv, duk_bool_t avoid_side_effects); -DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped); /* out_clamped=NULL, RangeError if outside range */ +DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, + duk_idx_t idx, + duk_int_t minval, + duk_int_t maxval, + duk_bool_t *out_clamped); /* out_clamped=NULL, RangeError if outside range */ DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval); DUK_INTERNAL_DECL duk_int_t duk_to_int_check_range(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -196,13 +197,15 @@ DUK_INTERNAL_DECL void duk_push_hstring_empty(duk_hthread *thr); DUK_INTERNAL_DECL void duk_push_hobject(duk_hthread *thr, duk_hobject *h); DUK_INTERNAL_DECL void duk_push_hbuffer(duk_hthread *thr, duk_hbuffer *h); -#define duk_push_hthread(thr,h) \ - duk_push_hobject((thr), (duk_hobject *) (h)) -#define duk_push_hnatfunc(thr,h) \ - duk_push_hobject((thr), (duk_hobject *) (h)) +#define duk_push_hthread(thr, h) duk_push_hobject((thr), (duk_hobject *) (h)) +#define duk_push_hnatfunc(thr, h) duk_push_hobject((thr), (duk_hobject *) (h)) DUK_INTERNAL_DECL void duk_push_hobject_bidx(duk_hthread *thr, duk_small_int_t builtin_idx); -DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx); -DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper_proto(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_hobject *proto); +DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx); +DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper_proto(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_hobject *proto); DUK_INTERNAL_DECL duk_hcompfunc *duk_push_hcompfunc(duk_hthread *thr); DUK_INTERNAL_DECL duk_hboundfunc *duk_push_hboundfunc(duk_hthread *thr); DUK_INTERNAL_DECL void duk_push_c_function_builtin(duk_hthread *thr, duk_c_function func, duk_int_t nargs); @@ -219,11 +222,13 @@ DUK_INTERNAL_DECL void duk_push_lightfunc_name_raw(duk_hthread *thr, duk_c_function func, duk_small_uint_t lf_flags); DUK_INTERNAL_DECL void duk_push_lightfunc_name(duk_hthread *thr, duk_tval *tv); DUK_INTERNAL_DECL void duk_push_lightfunc_tostring(duk_hthread *thr, duk_tval *tv); -#if 0 /* not used yet */ +#if 0 /* not used yet */ DUK_INTERNAL_DECL void duk_push_hnatfunc_name(duk_hthread *thr, duk_hnatfunc *h); #endif #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_INTERNAL_DECL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx); +DUK_INTERNAL_DECL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx); #endif DUK_INTERNAL_DECL void *duk_push_fixed_buffer_nozero(duk_hthread *thr, duk_size_t len); @@ -240,80 +245,86 @@ * arguments and such call sites are also easiest to verify to be correct. */ -DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> val */ +DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> val */ DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_get_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_get_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_get_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop); /* -> */ +DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_bool_t *out_has_prop); /* -> */ DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop(duk_hthread *thr, duk_idx_t obj_idx); DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_xget_owndataprop_stridx_short(thr,obj_idx,stridx) \ +#define duk_xget_owndataprop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_xget_owndataprop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* val -> */ +DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* val -> */ DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_put_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_put_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_put_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ -#if 0 /* Too few call sites to be useful. */ +DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +#if 0 /* Too few call sites to be useful. */ DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_del_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_del_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((obj_idx) >= -0x8000L && (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((stridx) >= 0 && (stridx) <= 0xffffL), \ duk_del_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) #endif -#define duk_del_prop_stridx_short(thr,obj_idx,stridx) \ - duk_del_prop_stridx((thr), (obj_idx), (stridx)) +#define duk_del_prop_stridx_short(thr, obj_idx, stridx) duk_del_prop_stridx((thr), (obj_idx), (stridx)) -DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ -#if 0 /* Too few call sites to be useful. */ +DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +#if 0 /* Too few call sites to be useful. */ DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_has_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_has_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((obj_idx) >= -0x8000L && (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((stridx) >= 0 && (stridx) <= 0xffffL), \ duk_has_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) #endif -#define duk_has_prop_stridx_short(thr,obj_idx,stridx) \ - duk_has_prop_stridx((thr), (obj_idx), (stridx)) +#define duk_has_prop_stridx_short(thr, obj_idx, stridx) duk_has_prop_stridx((thr), (obj_idx), (stridx)) -DUK_INTERNAL_DECL void duk_xdef_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t desc_flags); /* key val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t desc_flags); /* key val -> */ -DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags); /* val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_hthread *thr, + duk_idx_t obj_idx, + duk_uarridx_t arr_idx, + duk_small_uint_t desc_flags); /* val -> */ /* XXX: Because stridx and desc_flags have a limited range, this call could * always pack stridx and desc_flags into a single argument. */ -DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_uint_t desc_flags); /* val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_small_uint_t desc_flags); /* val -> */ DUK_INTERNAL_DECL void duk_xdef_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_xdef_prop_stridx_short(thr,obj_idx,stridx,desc_flags) \ +#define duk_xdef_prop_stridx_short(thr, obj_idx, stridx, desc_flags) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x80L && (duk_int_t) (obj_idx) <= 0x7fL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ DUK_ASSERT_EXPR((duk_int_t) (desc_flags) >= 0 && (duk_int_t) (desc_flags) <= 0xffL), \ - duk_xdef_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 24) + (((duk_uint_t) (stridx)) << 8) + (duk_uint_t) (desc_flags))) - -#define duk_xdef_prop_wec(thr,obj_idx) \ - duk_xdef_prop((thr), (obj_idx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_index_wec(thr,obj_idx,arr_idx) \ - duk_xdef_prop_index((thr), (obj_idx), (arr_idx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_stridx_wec(thr,obj_idx,stridx) \ - duk_xdef_prop_stridx((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_stridx_short_wec(thr,obj_idx,stridx) \ + duk_xdef_prop_stridx_short_raw((thr), \ + (((duk_uint_t) (obj_idx)) << 24) + (((duk_uint_t) (stridx)) << 8) + \ + (duk_uint_t) (desc_flags))) + +#define duk_xdef_prop_wec(thr, obj_idx) duk_xdef_prop((thr), (obj_idx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_index_wec(thr, obj_idx, arr_idx) duk_xdef_prop_index((thr), (obj_idx), (arr_idx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_stridx_wec(thr, obj_idx, stridx) duk_xdef_prop_stridx((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_stridx_short_wec(thr, obj_idx, stridx) \ duk_xdef_prop_stridx_short((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL void duk_xdef_prop_stridx_builtin(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags); /* -> */ #endif -DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ DUK_INTERNAL_DECL duk_bool_t duk_get_method_stridx(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t stridx); @@ -362,25 +373,21 @@ * using these macro results in faster and smaller code than duk_get_tval(). * Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts. */ -#define DUK_ASSERT_VALID_NEGIDX(thr,idx) \ +#define DUK_ASSERT_VALID_NEGIDX(thr, idx) \ (DUK_ASSERT_EXPR((duk_int_t) (idx) < 0), DUK_ASSERT_EXPR(duk_is_valid_index((thr), (idx)))) -#define DUK_ASSERT_VALID_POSIDX(thr,idx) \ +#define DUK_ASSERT_VALID_POSIDX(thr, idx) \ (DUK_ASSERT_EXPR((duk_int_t) (idx) >= 0), DUK_ASSERT_EXPR(duk_is_valid_index((thr), (idx)))) -#define DUK_GET_TVAL_NEGIDX(thr,idx) \ - (DUK_ASSERT_VALID_NEGIDX((thr),(idx)), ((duk_hthread *) (thr))->valstack_top + (idx)) -#define DUK_GET_TVAL_POSIDX(thr,idx) \ - (DUK_ASSERT_VALID_POSIDX((thr),(idx)), ((duk_hthread *) (thr))->valstack_bottom + (idx)) -#define DUK_GET_HOBJECT_NEGIDX(thr,idx) \ - (DUK_ASSERT_VALID_NEGIDX((thr),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_top + (idx))) -#define DUK_GET_HOBJECT_POSIDX(thr,idx) \ - (DUK_ASSERT_VALID_POSIDX((thr),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_bottom + (idx))) - -#define DUK_GET_THIS_TVAL_PTR(thr) \ - (DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), \ - (thr)->valstack_bottom - 1) +#define DUK_GET_TVAL_NEGIDX(thr, idx) (DUK_ASSERT_VALID_NEGIDX((thr), (idx)), ((duk_hthread *) (thr))->valstack_top + (idx)) +#define DUK_GET_TVAL_POSIDX(thr, idx) (DUK_ASSERT_VALID_POSIDX((thr), (idx)), ((duk_hthread *) (thr))->valstack_bottom + (idx)) +#define DUK_GET_HOBJECT_NEGIDX(thr, idx) \ + (DUK_ASSERT_VALID_NEGIDX((thr), (idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_top + (idx))) +#define DUK_GET_HOBJECT_POSIDX(thr, idx) \ + (DUK_ASSERT_VALID_POSIDX((thr), (idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_bottom + (idx))) + +#define DUK_GET_THIS_TVAL_PTR(thr) (DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), (thr)->valstack_bottom - 1) DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time(duk_hthread *thr); DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time_nofrac(duk_hthread *thr); DUK_INTERNAL_DECL duk_double_t duk_time_get_monotonic_time(duk_hthread *thr); -#endif /* DUK_API_INTERNAL_H_INCLUDED */ +#endif /* DUK_API_INTERNAL_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_memory.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_memory.c
Changed
@@ -74,7 +74,7 @@ DUK_ASSERT(heap != NULL); DUK_D(DUK_DPRINT("mark-and-sweep requested by application")); - DUK_ASSERT(DUK_GC_COMPACT == DUK_MS_FLAG_EMERGENCY); /* Compact flag is 1:1 with emergency flag which forces compaction. */ + DUK_ASSERT(DUK_GC_COMPACT == DUK_MS_FLAG_EMERGENCY); /* Compact flag is 1:1 with emergency flag which forces compaction. */ ms_flags = (duk_small_uint_t) flags; duk_heap_mark_and_sweep(heap, ms_flags); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_object.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_object.c
Changed
@@ -30,9 +30,9 @@ DUK_ASSERT(rc == 0 || rc == 1); /* a value is left on stack regardless of rc */ - duk_remove_m2(thr); /* remove key */ + duk_remove_m2(thr); /* remove key */ DUK_ASSERT(duk_is_undefined(thr, -1) || rc == 1); - return rc; /* 1 if property found, 0 otherwise */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_get_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) { @@ -77,7 +77,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_get_prop(thr, obj_idx); } @@ -91,11 +91,13 @@ } DUK_INTERNAL duk_bool_t duk_get_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_get_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), - (duk_small_uint_t) (packed_args & 0xffffUL)); + return duk_get_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } -DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop) { +DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_bool_t *out_has_prop) { duk_bool_t rc; DUK_ASSERT_API_ENTRY(thr); @@ -140,7 +142,7 @@ } duk_push_tval(thr, tv_val); - duk_remove_m2(thr); /* remove key */ + duk_remove_m2(thr); /* remove key */ return 1; } @@ -155,7 +157,8 @@ } DUK_INTERNAL duk_bool_t duk_xget_owndataprop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_xget_owndataprop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), + return duk_xget_owndataprop_stridx(thr, + (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } @@ -174,8 +177,7 @@ /* Key and value indices are either (-2, -1) or (-1, -2). Given idx_key, * idx_val is always (idx_key ^ 0x01). */ - DUK_ASSERT((idx_key == -2 && (idx_key ^ 1) == -1) || - (idx_key == -1 && (idx_key ^ 1) == -2)); + DUK_ASSERT((idx_key == -2 && (idx_key ^ 1) == -1) || (idx_key == -1 && (idx_key ^ 1) == -2)); /* XXX: Direct access; faster validation. */ tv_obj = duk_require_tval(thr, obj_idx); tv_key = duk_require_tval(thr, idx_key); @@ -185,8 +187,8 @@ rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, throw_flag); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop_2(thr); /* remove key and value */ - return rc; /* 1 if property found, 0 otherwise */ + duk_pop_2(thr); /* remove key and value */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_put_prop(duk_hthread *thr, duk_idx_t obj_idx) { @@ -240,11 +242,10 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk__put_prop_shared(thr, obj_idx, -1); } - DUK_INTERNAL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT_STRIDX_VALID(stridx); @@ -255,8 +256,7 @@ } DUK_INTERNAL duk_bool_t duk_put_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_put_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), - (duk_small_uint_t) (packed_args & 0xffffUL)); + return duk_put_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } DUK_EXTERNAL duk_bool_t duk_del_prop(duk_hthread *thr, duk_idx_t obj_idx) { @@ -278,7 +278,7 @@ rc = duk_hobject_delprop(thr, tv_obj, tv_key, throw_flag); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop(thr); /* remove key */ + duk_pop(thr); /* remove key */ return rc; } @@ -324,7 +324,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_del_prop(thr, obj_idx); } @@ -361,8 +361,8 @@ rc = duk_hobject_hasprop(thr, tv_obj, tv_key); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop(thr); /* remove key */ - return rc; /* 1 if property found, 0 otherwise */ + duk_pop(thr); /* remove key */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_has_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) { @@ -407,7 +407,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_has_prop(thr, obj_idx); } @@ -446,7 +446,7 @@ duk_hobject_define_property_internal(thr, obj, key, desc_flags); - duk_pop(thr); /* pop key */ + duk_pop(thr); /* pop key */ } DUK_INTERNAL void duk_xdef_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags) { @@ -479,12 +479,13 @@ } DUK_INTERNAL void duk_xdef_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - duk_xdef_prop_stridx(thr, (duk_idx_t) (duk_int8_t) (packed_args >> 24), - (duk_small_uint_t) (packed_args >> 8) & 0xffffUL, - (duk_small_uint_t) (packed_args & 0xffL)); + duk_xdef_prop_stridx(thr, + (duk_idx_t) (duk_int8_t) (packed_args >> 24), + (duk_small_uint_t) (packed_args >> 8) & 0xffffUL, + (duk_small_uint_t) (packed_args & 0xffL)); } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL void duk_xdef_prop_stridx_builtin(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags) { duk_hobject *obj; duk_hstring *key; @@ -516,15 +517,15 @@ duk_push_hstring_stridx(thr, stridx); duk_push_hobject_bidx(thr, DUK_BIDX_TYPE_ERROR_THROWER); duk_dup_top(thr); - duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE); /* attributes always 0 */ + duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE); /* attributes always 0 */ } /* Object.getOwnPropertyDescriptor() equivalent C binding. */ DUK_EXTERNAL void duk_get_prop_desc(duk_hthread *thr, duk_idx_t obj_idx, duk_uint_t flags) { DUK_ASSERT_API_ENTRY(thr); - DUK_UNREF(flags); /* no flags defined yet */ + DUK_UNREF(flags); /* no flags defined yet */ - duk_hobject_object_get_own_property_descriptor(thr, obj_idx); /* ... key -> ... desc */ + duk_hobject_object_get_own_property_descriptor(thr, obj_idx); /* ... key -> ... desc */ } /* Object.defineProperty() equivalent C binding. */ @@ -554,9 +555,7 @@ idx_base = duk_get_top_index(thr); if (flags & DUK_DEFPROP_HAVE_SETTER) { - duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC); + duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC); set = duk_get_hobject_promote_lfunc(thr, idx_base); if (set != NULL && !DUK_HOBJECT_IS_CALLABLE(set)) { goto fail_not_callable; @@ -566,9 +565,7 @@ set = NULL; } if (flags & DUK_DEFPROP_HAVE_GETTER) { - duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC); + duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC); get = duk_get_hobject_promote_lfunc(thr, idx_base); if (get != NULL && !DUK_HOBJECT_IS_CALLABLE(get)) { goto fail_not_callable; @@ -588,14 +585,7 @@ duk_require_valid_index(thr, idx_base); - duk_hobject_define_property_helper(thr, - flags /*defprop_flags*/, - obj, - key, - idx_value, - get, - set, - 1 /*throw_flag*/); + duk_hobject_define_property_helper(thr, flags /*defprop_flags*/, obj, key, idx_value, get, set, 1 /*throw_flag*/); /* Clean up stack */ @@ -605,11 +595,11 @@ return; - fail_invalid_desc: +fail_invalid_desc: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_DESCRIPTOR); DUK_WO_NORETURN(return;); - fail_not_callable: +fail_not_callable: DUK_ERROR_TYPE(thr, DUK_STR_NOT_CALLABLE); DUK_WO_NORETURN(return;); } @@ -643,7 +633,7 @@ duk_dup(thr, obj_idx); duk_require_hobject_promote_mask(thr, -1, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); - duk_hobject_enumerator_create(thr, enum_flags); /* target -> enum */ + duk_hobject_enumerator_create(thr, enum_flags); /* target -> enum */ } DUK_EXTERNAL duk_bool_t duk_next(duk_hthread *thr, duk_idx_t enum_index, duk_bool_t get_value) { @@ -704,8 +694,8 @@ } return; - fail_cannot_freeze: - DUK_ERROR_TYPE_INVALID_ARGS(thr); /* XXX: proper error message */ +fail_cannot_freeze: + DUK_ERROR_TYPE_INVALID_ARGS(thr); /* XXX: proper error message */ DUK_WO_NORETURN(return;); } @@ -750,8 +740,8 @@ if (ent != NULL) { while (ent->key != NULL) { tv = thr->valstack_top++; - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv)); /* value stack init policy */ - DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, ent->value); /* no need for decref/incref */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv)); /* value stack init policy */ + DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, ent->value); /* no need for decref/incref */ duk_put_prop_string(thr, obj_idx, ent->key); ent++; } @@ -821,7 +811,6 @@ return ret; } - DUK_EXTERNAL duk_bool_t duk_put_global_string(duk_hthread *thr, const char *key) { duk_bool_t ret; @@ -832,7 +821,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_string(thr, -2, key); /* ... global val -> ... global */ + ret = duk_put_prop_string(thr, -2, key); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -847,7 +836,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_lstring(thr, -2, key, key_len); /* ... global val -> ... global */ + ret = duk_put_prop_lstring(thr, -2, key, key_len); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -864,7 +853,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_literal_raw(thr, -2, key, key_len); /* ... global val -> ... global */ + ret = duk_put_prop_literal_raw(thr, -2, key, key_len); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -880,7 +869,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_heapptr(thr, -2, ptr); /* ... global val -> ... global */ + ret = duk_put_prop_heapptr(thr, -2, ptr); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -932,14 +921,13 @@ obj = duk_require_hobject(thr, idx); DUK_ASSERT(obj != NULL); - duk_require_type_mask(thr, -1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT); + duk_require_type_mask(thr, -1, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT); proto = duk_get_hobject(thr, -1); /* proto can also be NULL here (allowed explicitly) */ #if defined(DUK_USE_ROM_OBJECTS) if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)) { - DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ + DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ DUK_WO_NORETURN(return;); } #endif @@ -959,7 +947,7 @@ #if defined(DUK_USE_ROM_OBJECTS) if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)) { - DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ + DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ DUK_WO_NORETURN(return;); } #endif @@ -1006,7 +994,7 @@ DUK_ASSERT_API_ENTRY(thr); - h = duk_require_hobject(thr, idx); /* Get before 'put' so that 'idx' is correct. */ + h = duk_require_hobject(thr, idx); /* Get before 'put' so that 'idx' is correct. */ callable = duk_is_callable(thr, -1); /* At present finalizer is stored as a hidden Symbol, with normal @@ -1033,7 +1021,7 @@ DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h); } } -#else /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ DUK_EXTERNAL void duk_get_finalizer(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx); @@ -1047,4 +1035,4 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_random.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_random.c
Changed
@@ -5,5 +5,5 @@ #include "duk_internal.h" DUK_EXTERNAL duk_double_t duk_random(duk_hthread *thr) { - return (duk_double_t) DUK_UTIL_GET_RANDOM_DOUBLE(thr); + return (duk_double_t) duk_util_get_random_double(thr); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_stack.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_stack.c
Changed
@@ -16,7 +16,8 @@ * Forward declarations */ -DUK_LOCAL_DECL duk_idx_t duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx); +DUK_LOCAL_DECL duk_idx_t +duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx); /* * Global state for working around missing variadic macros @@ -31,41 +32,24 @@ * Misc helpers */ -DUK_LOCAL const char * const duk__symbol_type_strings4 = { - "hidden", "global", "local", "wellknown" -}; +DUK_LOCAL const char * const duk__symbol_type_strings4 = { "hidden", "global", "local", "wellknown" }; #if !defined(DUK_USE_PACKED_TVAL) DUK_LOCAL const duk_uint_t duk__type_from_tag = { - DUK_TYPE_NUMBER, - DUK_TYPE_NUMBER, /* fastint */ - DUK_TYPE_UNDEFINED, - DUK_TYPE_NULL, - DUK_TYPE_BOOLEAN, - DUK_TYPE_POINTER, - DUK_TYPE_LIGHTFUNC, - DUK_TYPE_NONE, - DUK_TYPE_STRING, - DUK_TYPE_OBJECT, - DUK_TYPE_BUFFER, + DUK_TYPE_NUMBER, DUK_TYPE_NUMBER, /* fastint */ + DUK_TYPE_UNDEFINED, DUK_TYPE_NULL, DUK_TYPE_BOOLEAN, DUK_TYPE_POINTER, DUK_TYPE_LIGHTFUNC, + DUK_TYPE_NONE, DUK_TYPE_STRING, DUK_TYPE_OBJECT, DUK_TYPE_BUFFER, }; DUK_LOCAL const duk_uint_t duk__type_mask_from_tag = { - DUK_TYPE_MASK_NUMBER, - DUK_TYPE_MASK_NUMBER, /* fastint */ - DUK_TYPE_MASK_UNDEFINED, - DUK_TYPE_MASK_NULL, - DUK_TYPE_MASK_BOOLEAN, - DUK_TYPE_MASK_POINTER, - DUK_TYPE_MASK_LIGHTFUNC, - DUK_TYPE_MASK_NONE, - DUK_TYPE_MASK_STRING, - DUK_TYPE_MASK_OBJECT, - DUK_TYPE_MASK_BUFFER, + DUK_TYPE_MASK_NUMBER, DUK_TYPE_MASK_NUMBER, /* fastint */ + DUK_TYPE_MASK_UNDEFINED, DUK_TYPE_MASK_NULL, DUK_TYPE_MASK_BOOLEAN, DUK_TYPE_MASK_POINTER, DUK_TYPE_MASK_LIGHTFUNC, + DUK_TYPE_MASK_NONE, DUK_TYPE_MASK_STRING, DUK_TYPE_MASK_OBJECT, DUK_TYPE_MASK_BUFFER, }; -#endif /* !DUK_USE_PACKED_TVAL */ +#endif /* !DUK_USE_PACKED_TVAL */ /* Assert that there's room for one value. */ -#define DUK__ASSERT_SPACE() do { \ +#define DUK__ASSERT_SPACE() \ + do { \ DUK_ASSERT(!(thr->valstack_top >= thr->valstack_end)); \ } while (0) @@ -74,7 +58,8 @@ /* Faster but value stack overruns are memory unsafe. */ #define DUK__CHECK_SPACE() DUK__ASSERT_SPACE() #else -#define DUK__CHECK_SPACE() do { \ +#define DUK__CHECK_SPACE() \ + do { \ if (DUK_UNLIKELY(thr->valstack_top >= thr->valstack_end)) { \ DUK_ERROR_RANGE_PUSH_BEYOND(thr); \ } \ @@ -87,7 +72,7 @@ DUK_ASSERT(h != NULL); DUK_ASSERT(DUK_HSTRING_HAS_SYMBOL(h)); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h) >= 1); /* always true, symbol prefix */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h) >= 1); /* always true, symbol prefix */ data = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h); len = DUK_HSTRING_GET_BYTELEN(h); @@ -254,7 +239,7 @@ /* Assume value stack sizes (in elements) fits into duk_idx_t. */ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -282,7 +267,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -310,7 +295,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -357,7 +342,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ /* Use unsigned arithmetic to optimize comparison. */ if (idx < 0) { @@ -496,7 +481,7 @@ DUK_ASSERT(count > 0); tv = thr->valstack_top; tv_end = tv - count; - DUK_ASSERT(tv > tv_end); /* Because count > 0. */ + DUK_ASSERT(tv > tv_end); /* Because count > 0. */ do { tv--; DUK_ASSERT(tv >= thr->valstack_bottom); @@ -504,7 +489,7 @@ } while (tv != tv_end); thr->valstack_top = tv_end; DUK_REFZERO_CHECK_FAST(thr); -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ duk_uidx_t count; duk_tval *tv_end; @@ -517,7 +502,7 @@ DUK_TVAL_SET_UNDEFINED(tv); } while (tv != tv_end); thr->valstack_top = tv_end; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ } } @@ -528,7 +513,7 @@ duk_set_top(thr, idx); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_set_top_unsafe(duk_hthread *thr, duk_idx_t idx) { duk_uidx_t uidx; duk_uidx_t vs_size; @@ -567,7 +552,7 @@ DUK_ASSERT(count > 0); tv = thr->valstack_top; tv_end = tv - count; - DUK_ASSERT(tv > tv_end); /* Because count > 0. */ + DUK_ASSERT(tv > tv_end); /* Because count > 0. */ do { tv--; DUK_ASSERT(tv >= thr->valstack_bottom); @@ -575,7 +560,7 @@ } while (tv != tv_end); thr->valstack_top = tv_end; DUK_REFZERO_CHECK_FAST(thr); -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ duk_uidx_t count; duk_tval *tv_end; @@ -588,10 +573,10 @@ DUK_TVAL_SET_UNDEFINED(tv); } while (tv != tv_end); thr->valstack_top = tv_end; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ } } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Internal helper: set top to 'top', and set idx_wipe_start,top to * 'undefined' (doing nothing if idx_wipe_start == top). Indices are @@ -691,9 +676,9 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); DUK_ASSERT(thr->valstack_end >= thr->valstack_top); DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end); - DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size); /* can't resize below 'top' */ - DUK_ASSERT(new_size <= DUK_USE_VALSTACK_LIMIT); /* valstack limit caller has check, prevents wrapping */ - DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval)); /* specific assert for wrapping */ + DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size); /* can't resize below 'top' */ + DUK_ASSERT(new_size <= DUK_USE_VALSTACK_LIMIT); /* valstack limit caller has check, prevents wrapping */ + DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval)); /* specific assert for wrapping */ /* Pre-realloc pointer copies for asserts and debug logs. */ pre_valstack = thr->valstack; @@ -728,7 +713,8 @@ */ DUK_ASSERT(new_size != 0); DUK_D(DUK_DPRINT("failed to resize valstack to %lu entries (%lu bytes)", - (unsigned long) new_size, (unsigned long) new_alloc_size)); + (unsigned long) new_size, + (unsigned long) new_alloc_size)); return 0; } @@ -739,23 +725,28 @@ #if defined(DUK_USE_DEBUG) if (thr->valstack != pre_valstack) { DUK_D(DUK_DPRINT("valstack base pointer changed during valstack resize: %p -> %p", - (void *) pre_valstack, (void *) thr->valstack)); + (void *) pre_valstack, + (void *) thr->valstack)); } if (thr->valstack_bottom != pre_bottom) { DUK_D(DUK_DPRINT("valstack bottom pointer changed during valstack resize: %p -> %p", - (void *) pre_bottom, (void *) thr->valstack_bottom)); + (void *) pre_bottom, + (void *) thr->valstack_bottom)); } if (thr->valstack_top != pre_top) { DUK_D(DUK_DPRINT("valstack top pointer changed during valstack resize: %p -> %p", - (void *) pre_top, (void *) thr->valstack_top)); + (void *) pre_top, + (void *) thr->valstack_top)); } if (thr->valstack_end != pre_end) { DUK_D(DUK_DPRINT("valstack end pointer changed during valstack resize: %p -> %p", - (void *) pre_end, (void *) thr->valstack_end)); + (void *) pre_end, + (void *) thr->valstack_end)); } if (thr->valstack_alloc_end != pre_alloc_end) { DUK_D(DUK_DPRINT("valstack alloc_end pointer changed during valstack resize: %p -> %p", - (void *) pre_alloc_end, (void *) thr->valstack_alloc_end)); + (void *) pre_alloc_end, + (void *) thr->valstack_alloc_end)); } #endif @@ -794,12 +785,22 @@ (unsigned long) new_size, (unsigned long) ((duk_uint8_t *) pre_alloc_end - (duk_uint8_t *) pre_valstack), (unsigned long) new_alloc_size, - (void *) pre_valstack, (void *) thr->valstack, - (void *) pre_bottom, (void *) thr->valstack_bottom, (long) (thr->valstack_bottom - thr->valstack), - (void *) pre_top, (void *) thr->valstack_top, (long) (thr->valstack_top - thr->valstack), - (void *) pre_end, (void *) thr->valstack_end, (long) (thr->valstack_end - thr->valstack), - (void *) pre_alloc_end, (void *) thr->valstack_alloc_end, (long) (thr->valstack_alloc_end - thr->valstack), - (void *) tv_prev_alloc_end, (long) (thr->valstack_alloc_end - tv_prev_alloc_end))); + (void *) pre_valstack, + (void *) thr->valstack, + (void *) pre_bottom, + (void *) thr->valstack_bottom, + (long) (thr->valstack_bottom - thr->valstack), + (void *) pre_top, + (void *) thr->valstack_top, + (long) (thr->valstack_top - thr->valstack), + (void *) pre_end, + (void *) thr->valstack_end, + (long) (thr->valstack_end - thr->valstack), + (void *) pre_alloc_end, + (void *) thr->valstack_alloc_end, + (long) (thr->valstack_alloc_end - thr->valstack), + (void *) tv_prev_alloc_end, + (long) (thr->valstack_alloc_end - tv_prev_alloc_end))); /* If allocation grew, init any new slots to 'undefined'. */ p = tv_prev_alloc_end; @@ -826,7 +827,7 @@ duk_size_t new_size; DUK_ASSERT(min_bytes / sizeof(duk_tval) * sizeof(duk_tval) == min_bytes); - min_size = min_bytes / sizeof(duk_tval); /* from bytes to slots */ + min_size = min_bytes / sizeof(duk_tval); /* from bytes to slots */ #if defined(DUK_USE_VALSTACK_GROW_SHIFT) /* New size is minimum size plus a proportional slack, e.g. shift of @@ -943,17 +944,18 @@ #else slack = 0; #endif - shrink_bytes = reserve_bytes + - slack / sizeof(duk_tval) * sizeof(duk_tval); /* multiple of duk_tval */ + shrink_bytes = reserve_bytes + slack / sizeof(duk_tval) * sizeof(duk_tval); /* multiple of duk_tval */ } -#else /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ +#else /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ /* Always snug, useful in some low memory environments. */ DUK_UNREF(snug); shrink_bytes = reserve_bytes; -#endif /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ +#endif /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ DUK_D(DUK_DPRINT("valstack shrink check: alloc_bytes=%ld, reserve_bytes=%ld, shrink_bytes=%ld (unvalidated)", - (long) alloc_bytes, (long) reserve_bytes, (long) shrink_bytes)); + (long) alloc_bytes, + (long) reserve_bytes, + (long) shrink_bytes)); DUK_ASSERT(shrink_bytes >= reserve_bytes); if (shrink_bytes >= alloc_bytes) { /* Skip if shrink target is same as current one (or higher, @@ -1100,7 +1102,7 @@ DUK_ASSERT(tv_from != NULL); DUK_ASSERT(tv_to != NULL); DUK_TVAL_SET_TVAL(tv_to, tv_from); - DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ + DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ } DUK_EXTERNAL void duk_dup_top(duk_hthread *thr) { @@ -1122,7 +1124,7 @@ DUK_ASSERT(tv_from != NULL); DUK_ASSERT(tv_to != NULL); DUK_TVAL_SET_TVAL(tv_to, tv_from); - DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ + DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ #endif } @@ -1175,7 +1177,10 @@ nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); DUK_DDD(DUK_DDDPRINT("duk_insert: to_idx=%ld, p=%p, q=%p, nbytes=%lu", - (long) to_idx, (void *) p, (void *) q, (unsigned long) nbytes)); + (long) to_idx, + (void *) p, + (void *) q, + (unsigned long) nbytes)); /* No net refcount changes. No need to special case nbytes == 0 * (p == q). @@ -1187,7 +1192,7 @@ DUK_INTERNAL void duk_insert_undefined(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(idx >= 0); /* Doesn't support negative indices. */ + DUK_ASSERT(idx >= 0); /* Doesn't support negative indices. */ duk_push_undefined(thr); duk_insert(thr, idx); @@ -1197,7 +1202,7 @@ duk_tval *tv, *tv_end; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(idx >= 0); /* Doesn't support negative indices or count. */ + DUK_ASSERT(idx >= 0); /* Doesn't support negative indices or count. */ DUK_ASSERT(count >= 0); tv = duk_reserve_gap(thr, idx, count); @@ -1232,7 +1237,10 @@ nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); DUK_DDD(DUK_DDDPRINT("duk_pull: from_idx=%ld, p=%p, q=%p, nbytes=%lu", - (long) from_idx, (void *) p, (void *) q, (unsigned long) nbytes)); + (long) from_idx, + (void *) p, + (void *) q, + (unsigned long) nbytes)); /* No net refcount changes. No need to special case nbytes == 0 * (p == q). @@ -1261,7 +1269,7 @@ DUK_TVAL_SET_TVAL(tv2, tv1); DUK_TVAL_SET_UNDEFINED(tv1); thr->valstack_top--; - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ } DUK_EXTERNAL void duk_copy(duk_hthread *thr, duk_idx_t from_idx, duk_idx_t to_idx) { @@ -1276,7 +1284,7 @@ DUK_ASSERT(tv2 != NULL); /* For tv1 == tv2, this is a no-op (no explicit check needed). */ - DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */ } DUK_EXTERNAL void duk_remove(duk_hthread *thr, duk_idx_t idx) { @@ -1307,21 +1315,21 @@ DUK_TVAL_SET_TVAL(&tv_tmp, p); #endif - nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */ + nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */ duk_memmove((void *) p, (const void *) (p + 1), (size_t) nbytes); DUK_TVAL_SET_UNDEFINED(q); thr->valstack_top--; #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ #endif } DUK_INTERNAL void duk_remove_unsafe(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - duk_remove(thr, idx); /* XXX: no optimization for now */ + duk_remove(thr, idx); /* XXX: no optimization for now */ } DUK_INTERNAL void duk_remove_m2(duk_hthread *thr) { @@ -1340,7 +1348,7 @@ while (count-- > 0) { duk_remove(thr, idx); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ duk_tval *tv_src; duk_tval *tv_dst; duk_tval *tv_newtop; @@ -1372,13 +1380,13 @@ /* When not preferring size, only NORZ macros are used; caller * is expected to DUK_REFZERO_CHECK(). */ -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } DUK_INTERNAL void duk_remove_n_unsafe(duk_hthread *thr, duk_idx_t idx, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); - duk_remove_n(thr, idx, count); /* XXX: no optimization for now */ + duk_remove_n(thr, idx, count); /* XXX: no optimization for now */ } /* @@ -1439,7 +1447,7 @@ /* Incref copies, keep originals. */ q = to_thr->valstack_top; while (p < q) { - DUK_TVAL_INCREF(to_thr, p); /* no side effects */ + DUK_TVAL_INCREF(to_thr, p); /* no side effects */ p++; } } else { @@ -1539,7 +1547,7 @@ DUK_EXTERNAL duk_bool_t duk_get_boolean(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__get_boolean_raw(thr, idx, 0); /* default: false */ + return duk__get_boolean_raw(thr, idx, 0); /* default: false */ } DUK_EXTERNAL duk_bool_t duk_get_boolean_default(duk_hthread *thr, duk_idx_t idx, duk_bool_t def_value) { @@ -1585,11 +1593,10 @@ DUK_ASSERT(tv != NULL); #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv)) { - ret.d = (duk_double_t) DUK_TVAL_GET_FASTINT(tv); /* XXX: cast trick */ - } - else + ret.d = (duk_double_t) DUK_TVAL_GET_FASTINT(tv); /* XXX: cast trick */ + } else #endif - if (DUK_TVAL_IS_DOUBLE(tv)) { + if (DUK_TVAL_IS_DOUBLE(tv)) { /* When using packed duk_tval, number must be in NaN-normalized form * for it to be a duk_tval, so no need to normalize. NOP for unpacked * duk_tval. @@ -1606,7 +1613,7 @@ DUK_EXTERNAL duk_double_t duk_get_number(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__get_number_raw(thr, idx, DUK_DOUBLE_NAN); /* default: NaN */ + return duk__get_number_raw(thr, idx, DUK_DOUBLE_NAN); /* default: NaN */ } DUK_EXTERNAL duk_double_t duk_get_number_default(duk_hthread *thr, duk_idx_t idx, duk_double_t def_value) { @@ -1762,7 +1769,11 @@ } } -DUK_EXTERNAL const char *duk_opt_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL const char *duk_opt_lstring(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_len, + const char *def_ptr, + duk_size_t def_len) { DUK_ASSERT_API_ENTRY(thr); if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) { @@ -1783,7 +1794,11 @@ return duk_require_string(thr, idx); } -DUK_EXTERNAL const char *duk_get_lstring_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL const char *duk_get_lstring_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_len, + const char *def_ptr, + duk_size_t def_len) { duk_hstring *h; const char *ret; duk_size_t len; @@ -1872,7 +1887,7 @@ return def_value; } - p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ + p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ return p; } @@ -1910,11 +1925,11 @@ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "pointer", DUK_STR_NOT_POINTER); DUK_WO_NORETURN(return NULL;); } - p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ + p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ return p; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL void *duk_get_voidptr(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; duk_heaphdr *h; @@ -1933,7 +1948,12 @@ } #endif -DUK_LOCAL void *duk__get_buffer_helper(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag) { +DUK_LOCAL void *duk__get_buffer_helper(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size, + duk_bool_t throw_flag) { duk_hbuffer *h; void *ret; duk_size_t len; @@ -1986,7 +2006,11 @@ return duk_require_buffer(thr, idx, out_size); } -DUK_EXTERNAL void *duk_get_buffer_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL void *duk_get_buffer_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_len) { DUK_ASSERT_API_ENTRY(thr); return duk__get_buffer_helper(thr, idx, out_size, def_ptr, def_len, 0 /*throw_flag*/); @@ -2003,7 +2027,13 @@ * have a NULL data pointer when its size is zero, the optional 'out_isbuffer' * argument allows caller to detect this reliably. */ -DUK_INTERNAL void *duk_get_buffer_data_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag, duk_bool_t *out_isbuffer) { +DUK_INTERNAL void *duk_get_buffer_data_raw(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size, + duk_bool_t throw_flag, + duk_bool_t *out_isbuffer) { duk_tval *tv; DUK_ASSERT_API_ENTRY(thr); @@ -2027,7 +2057,7 @@ if (out_isbuffer != NULL) { *out_isbuffer = 1; } - return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */ + return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */ } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) else if (DUK_TVAL_IS_OBJECT(tv)) { @@ -2040,8 +2070,7 @@ duk_hbufobj *h_bufobj = (duk_hbufobj *) h; DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); - if (h_bufobj->buf != NULL && - DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { + if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { duk_uint8_t *p; p = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf); @@ -2056,7 +2085,7 @@ /* if slice not fully valid, treat as error */ } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ if (throw_flag) { DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "buffer", DUK_STR_NOT_BUFFER); @@ -2070,7 +2099,11 @@ return duk_get_buffer_data_raw(thr, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, NULL); } -DUK_EXTERNAL void *duk_get_buffer_data_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size) { +DUK_EXTERNAL void *duk_get_buffer_data_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size) { DUK_ASSERT_API_ENTRY(thr); return duk_get_buffer_data_raw(thr, idx, out_size, def_ptr, def_size, 0 /*throw_flag*/, NULL); } @@ -2110,9 +2143,8 @@ } ret = DUK_TVAL_GET_HEAPHDR(tv); - DUK_ASSERT(ret != NULL); /* tagged null pointers should never occur */ + DUK_ASSERT(ret != NULL); /* tagged null pointers should never occur */ return ret; - } DUK_INTERNAL duk_hstring *duk_get_hstring(duk_hthread *thr, duk_idx_t idx) { @@ -2447,7 +2479,7 @@ DUK_CTX_ASSERT_VALID(thr); - res = duk_get_hobject(thr, idx); /* common case, not promoted */ + res = duk_get_hobject(thr, idx); /* common case, not promoted */ if (DUK_LIKELY(res != NULL)) { DUK_ASSERT(res != NULL); return res; @@ -2460,7 +2492,7 @@ DUK_ASSERT(res != NULL); return res; } else { - return NULL; /* accept without promoting */ + return NULL; /* accept without promoting */ } } @@ -2503,7 +2535,7 @@ duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX); h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT); @@ -2517,7 +2549,7 @@ duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX); h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT); @@ -2563,7 +2595,7 @@ duk_pop_unsafe(thr); return ret; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ case DUK_TAG_STRING: { duk_hstring *h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); @@ -2589,7 +2621,7 @@ duk_pop_unsafe(thr); return ret; } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ case DUK_TAG_OBJECT: { duk_hobject *h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); @@ -2686,8 +2718,8 @@ if (duk_get_prop_stridx(thr, idx, func_stridx)) { /* ... func */ if (duk_is_callable(thr, -1)) { - duk_dup(thr, idx); /* -> ... func this */ - duk_call_method(thr, 0); /* -> ... retval */ + duk_dup(thr, idx); /* -> ... func this */ + duk_call_method(thr, 0); /* -> ... retval */ if (duk_is_primitive(thr, -1)) { duk_replace(thr, idx); return 1; @@ -2695,7 +2727,7 @@ /* ... retval ; popped below */ } } - duk_pop_unsafe(thr); /* ... func/retval -> ... */ + duk_pop_unsafe(thr); /* ... func/retval -> ... */ return 0; } @@ -2706,7 +2738,7 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ } DUK_EXTERNAL void duk_to_null(duk_hthread *thr, duk_idx_t idx) { @@ -2716,13 +2748,11 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */ } /* E5 Section 9.1 */ -DUK_LOCAL const char * const duk__toprim_hint_strings3 = { - "default", "string", "number" -}; +DUK_LOCAL const char * const duk__toprim_hint_strings3 = { "default", "string", "number" }; DUK_LOCAL void duk__to_primitive_helper(duk_hthread *thr, duk_idx_t idx, duk_int_t hint, duk_bool_t check_symbol) { /* Inline initializer for coercers is not allowed by old compilers like BCC. */ duk_small_uint_t coercers2; @@ -2733,10 +2763,8 @@ idx = duk_require_normalize_index(thr, idx); /* If already primitive, return as is. */ - if (!duk_check_type_mask(thr, idx, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + if (!duk_check_type_mask(thr, idx, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } @@ -2747,10 +2775,8 @@ DUK_ASSERT(hint >= 0 && (duk_size_t) hint < sizeof(duk__toprim_hint_strings) / sizeof(const char *)); duk_dup(thr, idx); duk_push_string(thr, duk__toprim_hint_stringshint); - duk_call_method(thr, 1); /* ... method value hint -> ... res */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { + duk_call_method(thr, 1); /* ... method value hint -> ... res */ + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { goto fail; } duk_replace(thr, idx); @@ -2772,7 +2798,7 @@ if (hint == DUK_HINT_NONE) { hint = DUK_HINT_NUMBER; } -#else /* DUK_USE_SYMBOL_BUILTIN */ +#else /* DUK_USE_SYMBOL_BUILTIN */ if (hint == DUK_HINT_NONE) { duk_small_uint_t class_number; @@ -2783,7 +2809,7 @@ hint = DUK_HINT_NUMBER; } } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ coercers0 = DUK_STRIDX_VALUE_OF; coercers1 = DUK_STRIDX_TO_STRING; @@ -2793,16 +2819,16 @@ } if (duk__defaultvalue_coerce_attempt(thr, idx, coercers0)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } if (duk__defaultvalue_coerce_attempt(thr, idx, coercers1)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } - fail: +fail: DUK_ERROR_TYPE(thr, DUK_STR_TOPRIMITIVE_FAILED); DUK_WO_NORETURN(return;); } @@ -2833,7 +2859,7 @@ /* Note: no need to re-lookup tv, conversion is side effect free. */ DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val); /* side effects */ return val; } @@ -2865,11 +2891,11 @@ idx = duk_require_normalize_index(thr, idx); tv = DUK_GET_TVAL_POSIDX(thr, idx); DUK_ASSERT(tv != NULL); - d = duk_js_tonumber(thr, tv); /* XXX: fastint coercion? now result will always be a non-fastint */ + d = duk_js_tonumber(thr, tv); /* XXX: fastint coercion? now result will always be a non-fastint */ /* ToNumber() may have side effects so must relookup 'tv'. */ tv = DUK_GET_TVAL_POSIDX(thr, idx); - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ return d; } @@ -2901,13 +2927,13 @@ tv_dst = thr->valstack_top++; DUK_TVAL_SET_TVAL(tv_dst, tv); - DUK_TVAL_INCREF(thr, tv_dst); /* decref not necessary */ - res = duk_to_number_m1(thr); /* invalidates tv_dst */ + DUK_TVAL_INCREF(thr, tv_dst); /* decref not necessary */ + res = duk_to_number_m1(thr); /* invalidates tv_dst */ tv_dst = --thr->valstack_top; DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_dst)); - DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_dst)); /* plain number */ - DUK_TVAL_SET_UNDEFINED(tv_dst); /* valstack init policy */ + DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_dst)); /* plain number */ + DUK_TVAL_SET_UNDEFINED(tv_dst); /* valstack init policy */ return res; #endif @@ -2943,7 +2969,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ return d; } @@ -2977,7 +3003,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_I32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -2993,7 +3019,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -3009,7 +3035,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -3041,16 +3067,16 @@ if (duk_double_equals(t, 0.5)) { /* Exact halfway, round to even. */ ret = (duk_uint8_t) d; - ret = (ret + 1) & 0xfe; /* Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4 - * Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4 - */ + ret = (ret + 1) & 0xfe; /* Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4 + * Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4 + */ } else { /* Not halfway, round to nearest. */ ret = (duk_uint8_t) (d + 0.5); } return ret; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL const char *duk_to_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) { DUK_ASSERT_API_ENTRY(thr); @@ -3160,7 +3186,7 @@ DUK_ASSERT_API_ENTRY(thr); - duk_to_primitive(thr, idx, DUK_HINT_STRING); /* needed for e.g. Symbol objects */ + duk_to_primitive(thr, idx, DUK_HINT_STRING); /* needed for e.g. Symbol objects */ h = duk_get_hstring(thr, idx); if (h == NULL) { /* The "is string?" check may seem unnecessary, but as things @@ -3174,7 +3200,7 @@ return h; } -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ DUK_INTERNAL duk_hstring *duk_safe_to_hstring(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); @@ -3216,10 +3242,10 @@ * Object.prototype.toString() is usually not performance critical. */ - duk_push_literal(thr, "object "); /* -> ... "object" */ + duk_push_literal(thr, "object "); /* -> ... "object" */ switch (DUK_TVAL_GET_TAG(tv)) { - case DUK_TAG_UNUSED: /* Treat like 'undefined', shouldn't happen. */ + case DUK_TAG_UNUSED: /* Treat like 'undefined', shouldn't happen. */ case DUK_TAG_UNDEFINED: { duk_push_hstring_stridx(thr, DUK_STRIDX_UC_UNDEFINED); goto finish; @@ -3231,7 +3257,7 @@ } duk_push_tval(thr, tv); - tv = NULL; /* Invalidated by ToObject(). */ + tv = NULL; /* Invalidated by ToObject(). */ h_obj = duk_to_hobject(thr, -1); DUK_ASSERT(h_obj != NULL); if (duk_js_isarray_hobject(h_obj)) { @@ -3262,14 +3288,15 @@ duk_pop_unsafe(thr); duk_push_hstring_stridx(thr, stridx); - finish: +finish: /* ... "object" tag */ duk_push_literal(thr, ""); - duk_concat(thr, 3); /* ... "object" tag "" -> ... res */ + duk_concat(thr, 3); /* ... "object" tag "" -> ... res */ } /* XXX: other variants like uint, u32 etc */ -DUK_INTERNAL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) { +DUK_INTERNAL duk_int_t +duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) { duk_tval *tv; duk_tval tv_tmp; duk_double_t d, dmin, dmax; @@ -3280,7 +3307,7 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - d = duk_js_tointeger(thr, tv); /* E5 Section 9.4, ToInteger() */ + d = duk_js_tointeger(thr, tv); /* E5 Section 9.4, ToInteger() */ dmin = (duk_double_t) minval; dmax = (duk_double_t) maxval; @@ -3296,12 +3323,12 @@ } else { res = (duk_int_t) d; } - DUK_UNREF(d); /* SCANBUILD: with suitable dmin/dmax limits 'd' is unused */ + DUK_UNREF(d); /* SCANBUILD: with suitable dmin/dmax limits 'd' is unused */ /* 'd' and 'res' agree here */ /* Relookup in case duk_js_tointeger() ends up e.g. coercing an object. */ tv = duk_get_tval(thr, idx); - DUK_ASSERT(tv != NULL); /* not popped by side effect */ + DUK_ASSERT(tv != NULL); /* not popped by side effect */ DUK_TVAL_SET_TVAL(&tv_tmp, tv); #if defined(DUK_USE_FASTINT) #if (DUK_INT_MAX <= 0x7fffffffL) @@ -3315,9 +3342,9 @@ } #endif #else - DUK_TVAL_SET_NUMBER(tv, d); /* no need to incref */ + DUK_TVAL_SET_NUMBER(tv, d); /* no need to incref */ #endif - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ if (out_clamped) { *out_clamped = clamped; @@ -3342,7 +3369,7 @@ DUK_INTERNAL duk_int_t duk_to_int_check_range(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval) { DUK_ASSERT_API_ENTRY(thr); - return duk_to_int_clamped_raw(thr, idx, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */ + return duk_to_int_clamped_raw(thr, idx, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */ } DUK_EXTERNAL const char *duk_to_string(duk_hthread *thr, duk_idx_t idx) { @@ -3401,9 +3428,9 @@ * value, and duk_to_string() then causes a TypeError. */ duk_to_primitive(thr, idx, DUK_HINT_STRING); - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* ToPrimitive() must guarantee */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* ToPrimitive() must guarantee */ DUK_ASSERT(!duk_is_object(thr, idx)); - return duk_to_string(thr, idx); /* Note: recursive call */ + return duk_to_string(thr, idx); /* Note: recursive call */ } case DUK_TAG_POINTER: { void *ptr = DUK_TVAL_GET_POINTER(tv); @@ -3431,17 +3458,14 @@ DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv)); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); duk_push_tval(thr, tv); - duk_numconv_stringify(thr, - 10 /*radix*/, - 0 /*precision:shortest*/, - 0 /*force_exponential*/); + duk_numconv_stringify(thr, 10 /*radix*/, 0 /*precision:shortest*/, 0 /*force_exponential*/); break; } } duk_replace(thr, idx); - skip_replace: +skip_replace: DUK_ASSERT(duk_is_string(thr, idx)); return duk_require_string(thr, idx); } @@ -3523,8 +3547,7 @@ src_size = DUK_HBUFFER_GET_SIZE(h_buf); tmp = (DUK_HBUFFER_HAS_DYNAMIC(h_buf) ? DUK_BUF_MODE_DYNAMIC : DUK_BUF_MODE_FIXED); - if ((tmp == mode && !DUK_HBUFFER_HAS_EXTERNAL(h_buf)) || - mode == DUK_BUF_MODE_DONTCARE) { + if ((tmp == mode && !DUK_HBUFFER_HAS_EXTERNAL(h_buf)) || mode == DUK_BUF_MODE_DONTCARE) { /* Note: src_data may be NULL if input is a zero-size * dynamic buffer. */ @@ -3545,7 +3568,7 @@ duk_memcpy_unsafe((void *) dst_data, (const void *) src_data, (size_t) src_size); duk_replace(thr, idx); - skip_copy: +skip_copy: if (out_size) { *out_size = src_size; @@ -3605,7 +3628,7 @@ DUK_LOCAL void duk__push_func_from_lightfunc(duk_hthread *thr, duk_c_function func, duk_small_uint_t lf_flags) { duk_idx_t nargs; - duk_uint_t flags = 0; /* shared flags for a subset of types */ + duk_uint_t flags = 0; /* shared flags for a subset of types */ duk_small_uint_t lf_len; duk_hnatfunc *nf; @@ -3614,15 +3637,9 @@ nargs = (duk_idx_t) DUK_VARARGS; } - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_NATIVE_FUNCTION_PROTOTYPE); lf_len = DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags); @@ -3643,7 +3660,7 @@ DUK_EXTERNAL void duk_to_object(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; - duk_uint_t flags = 0; /* shared flags for a subset of types */ + duk_uint_t flags = 0; /* shared flags for a subset of types */ duk_small_int_t proto = 0; DUK_ASSERT_API_ENTRY(thr); @@ -3654,7 +3671,7 @@ switch (DUK_TVAL_GET_TAG(tv)) { #if !defined(DUK_USE_BUFFEROBJECT_SUPPORT) - case DUK_TAG_BUFFER: /* With no bufferobject support, don't object coerce. */ + case DUK_TAG_BUFFER: /* With no bufferobject support, don't object coerce. */ #endif case DUK_TAG_UNDEFINED: case DUK_TAG_NULL: { @@ -3663,9 +3680,8 @@ break; } case DUK_TAG_BOOLEAN: { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BOOLEAN); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BOOLEAN); proto = DUK_BIDX_BOOLEAN_PROTOTYPE; goto create_object; } @@ -3674,14 +3690,11 @@ h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); if (DUK_UNLIKELY(DUK_HSTRING_HAS_SYMBOL(h))) { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_SYMBOL); proto = DUK_BIDX_SYMBOL_PROTOTYPE; } else { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_STRING); proto = DUK_BIDX_STRING_PROTOTYPE; } @@ -3707,11 +3720,10 @@ duk_hbufobj_push_uint8array_from_plain(thr, h_buf); goto replace_value; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ case DUK_TAG_POINTER: { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER); proto = DUK_BIDX_POINTER_PROTOTYPE; goto create_object; } @@ -3738,9 +3750,8 @@ default: { DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv)); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_NUMBER); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_NUMBER); proto = DUK_BIDX_NUMBER_PROTOTYPE; goto create_object; } @@ -3748,7 +3759,7 @@ DUK_ASSERT(duk_is_object(thr, idx)); return; - create_object: +create_object: (void) duk_push_object_helper(thr, flags, proto); /* Note: Boolean prototype's internal value property is not writable, @@ -3761,7 +3772,7 @@ duk_dup(thr, idx); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); - replace_value: +replace_value: duk_replace(thr, idx); DUK_ASSERT(duk_is_object(thr, idx)); } @@ -3832,11 +3843,11 @@ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); return DUK_TYPE_NUMBER; } -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ DUK_ASSERT(DUK_TVAL_IS_VALID_TAG(tv)); DUK_ASSERT(sizeof(duk__type_from_tag) / sizeof(duk_uint_t) == DUK_TAG_MAX - DUK_TAG_MIN + 1); return (duk_int_t) duk__type_from_tagDUK_TVAL_GET_TAG(tv) - DUK_TAG_MIN; -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ } DUK_EXTERNAL duk_int_t duk_get_type(duk_hthread *thr, duk_idx_t idx) { @@ -3851,18 +3862,8 @@ } #if defined(DUK_USE_VERBOSE_ERRORS) && defined(DUK_USE_PARANOID_ERRORS) -DUK_LOCAL const char * const duk__type_names = { - "none", - "undefined", - "null", - "boolean", - "number", - "string", - "object", - "buffer", - "pointer", - "lightfunc" -}; +DUK_LOCAL const char * const duk__type_names = { "none", "undefined", "null", "boolean", "number", + "string", "object", "buffer", "pointer", "lightfunc" }; DUK_INTERNAL const char *duk_get_type_name(duk_hthread *thr, duk_idx_t idx) { duk_int_t type_tag; @@ -3875,7 +3876,7 @@ return duk__type_namestype_tag; } -#endif /* DUK_USE_VERBOSE_ERRORS && DUK_USE_PARANOID_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS && DUK_USE_PARANOID_ERRORS */ DUK_INTERNAL duk_small_uint_t duk_get_class_number(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; @@ -3941,11 +3942,11 @@ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); return DUK_TYPE_MASK_NUMBER; } -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ DUK_ASSERT(DUK_TVAL_IS_VALID_TAG(tv)); DUK_ASSERT(sizeof(duk__type_mask_from_tag) / sizeof(duk_uint_t) == DUK_TAG_MAX - DUK_TAG_MIN + 1); return duk__type_mask_from_tagDUK_TVAL_GET_TAG(tv) - DUK_TAG_MIN; -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ } DUK_EXTERNAL duk_uint_t duk_get_type_mask(duk_hthread *thr, duk_idx_t idx) { @@ -4064,14 +4065,14 @@ } return 0; } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); return duk_is_buffer(thr, idx); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL duk_bool_t duk_is_pointer(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); @@ -4165,23 +4166,17 @@ DUK_EXTERNAL duk_bool_t duk_is_c_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_NATFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_NATFUNC); } DUK_EXTERNAL duk_bool_t duk_is_ecmascript_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_COMPFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_COMPFUNC); } DUK_EXTERNAL duk_bool_t duk_is_bound_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_BOUNDFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_BOUNDFUNC); } DUK_EXTERNAL duk_bool_t duk_is_thread(duk_hthread *thr, duk_idx_t idx) { @@ -4298,7 +4293,7 @@ DUK__CHECK_SPACE(); tv_slot = thr->valstack_top++; DUK_TVAL_SET_TVAL(tv_slot, tv); - DUK_TVAL_INCREF(thr, tv); /* no side effects */ + DUK_TVAL_INCREF(thr, tv); /* no side effects */ } DUK_EXTERNAL void duk_push_undefined(duk_hthread *thr) { @@ -4328,7 +4323,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK__CHECK_SPACE(); - b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */ + b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */ tv_slot = thr->valstack_top++; DUK_TVAL_SET_BOOLEAN(tv_slot, b); } @@ -4381,7 +4376,7 @@ DUK_TVAL_SET_NUMBER(tv_slot, d); } #endif -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ duk_tval *tv_slot; duk_double_t d; @@ -4390,7 +4385,7 @@ d = (duk_double_t) val; tv_slot = thr->valstack_top++; DUK_TVAL_SET_NUMBER(tv_slot, d); -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ } DUK_EXTERNAL void duk_push_uint(duk_hthread *thr, duk_uint_t val) { @@ -4403,7 +4398,7 @@ #if DUK_UINT_MAX <= 0xffffffffUL DUK_TVAL_SET_U32(tv_slot, (duk_uint32_t) val); #else - if (val <= DUK_FASTINT_MAX) { /* val is unsigned so >= 0 */ + if (val <= DUK_FASTINT_MAX) { /* val is unsigned so >= 0 */ /* XXX: take advantage of val being unsigned, no need to mask */ DUK_TVAL_SET_FASTINT(tv_slot, (duk_int64_t) val); } else { @@ -4411,7 +4406,7 @@ DUK_TVAL_SET_NUMBER(tv_slot, d); } #endif -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ duk_tval *tv_slot; duk_double_t d; @@ -4420,7 +4415,7 @@ d = (duk_double_t) val; tv_slot = thr->valstack_top++; DUK_TVAL_SET_NUMBER(tv_slot, d); -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ } DUK_EXTERNAL void duk_push_nan(duk_hthread *thr) { @@ -4464,7 +4459,7 @@ tv_slot = thr->valstack_top++; DUK_TVAL_SET_STRING(tv_slot, h); - DUK_HSTRING_INCREF(thr, h); /* no side effects */ + DUK_HSTRING_INCREF(thr, h); /* no side effects */ return (const char *) DUK_HSTRING_GET_DATA(h); } @@ -4501,11 +4496,11 @@ tv_slot = thr->valstack_top++; DUK_TVAL_SET_STRING(tv_slot, h); - DUK_HSTRING_INCREF(thr, h); /* no side effects */ + DUK_HSTRING_INCREF(thr, h); /* no side effects */ return (const char *) DUK_HSTRING_GET_DATA(h); } -#else /* DUK_USE_LITCACHE_SIZE */ +#else /* DUK_USE_LITCACHE_SIZE */ DUK_EXTERNAL const char *duk_push_literal_raw(duk_hthread *thr, const char *str, duk_size_t len) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(str != NULL); @@ -4513,8 +4508,8 @@ return duk_push_lstring(thr, str, len); } -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_push_pointer(duk_hthread *thr, void *val) { duk_tval *tv_slot; @@ -4542,7 +4537,7 @@ DUK__CHECK_SPACE(); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */ tv_slot = thr->valstack_top++; if (DUK_UNLIKELY(thr->callstack_curr == NULL)) { @@ -4556,8 +4551,7 @@ /* 'this' binding is just before current activation's bottom */ DUK_ASSERT(thr->valstack_bottom > thr->valstack); tv = thr->valstack_bottom - 1; - if (check_object_coercible && - (DUK_TVAL_IS_UNDEFINED(tv) || DUK_TVAL_IS_NULL(tv))) { + if (check_object_coercible && (DUK_TVAL_IS_UNDEFINED(tv) || DUK_TVAL_IS_NULL(tv))) { /* XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv) */ goto type_error; } @@ -4567,7 +4561,7 @@ } return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_NOT_OBJECT_COERCIBLE); DUK_WO_NORETURN(return;); } @@ -4599,16 +4593,16 @@ DUK_ASSERT_API_ENTRY(thr); duk__push_this_helper(thr, 1 /*check_object_coercible*/); - return duk_to_hstring_m1(thr); /* This will reject all Symbol values; accepts Symbol objects. */ + return duk_to_hstring_m1(thr); /* This will reject all Symbol values; accepts Symbol objects. */ } DUK_INTERNAL duk_tval *duk_get_borrowed_this_tval(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */ - DUK_ASSERT(thr->callstack_curr != NULL); /* caller required to know */ - DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */ - DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */ + DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */ + DUK_ASSERT(thr->callstack_curr != NULL); /* caller required to know */ + DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */ + DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */ return thr->valstack_bottom - 1; } @@ -4689,7 +4683,10 @@ duk_pop_unsafe(thr); duk_push_bare_object(thr); duk_dup_top(thr); - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_C); /* ... parent stash stash -> ... parent stash */ + duk_xdef_prop_stridx_short(thr, + -3, + DUK_STRIDX_INT_VALUE, + DUK_PROPDESC_FLAGS_C); /* ... parent stash stash -> ... parent stash */ } duk_remove_m2(thr); } @@ -4742,7 +4739,7 @@ duk_size_t sz = DUK_PUSH_SPRINTF_INITIAL_SIZE; duk_bool_t pushed_buf = 0; void *buf; - duk_int_t len; /* XXX: duk_ssize_t */ + duk_int_t len; /* XXX: duk_ssize_t */ const char *res; DUK_ASSERT_API_ENTRY(thr); @@ -4756,7 +4753,7 @@ } /* initial estimate based on format string */ - sz = DUK_STRLEN(fmt) + 16; /* format plus something to avoid just missing */ + sz = DUK_STRLEN(fmt) + 16; /* format plus something to avoid just missing */ if (sz < DUK_PUSH_SPRINTF_INITIAL_SIZE) { sz = DUK_PUSH_SPRINTF_INITIAL_SIZE; } @@ -4766,7 +4763,7 @@ * This works 99% of the time which is quite nice. */ for (;;) { - va_list ap_copy; /* copied so that 'ap' can be reused */ + va_list ap_copy; /* copied so that 'ap' can be reused */ if (sz <= sizeof(stack_buf)) { buf = stack_buf; @@ -4796,7 +4793,7 @@ /* Cannot use duk_buffer_to_string() on the buffer because it is * usually larger than 'len'; 'buf' is also usually a stack buffer. */ - res = duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); /* buf? res */ + res = duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); /* buf? res */ if (pushed_buf) { duk_remove_m2(thr); } @@ -4817,13 +4814,14 @@ return ret; } -DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) { +DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx) { duk_tval *tv_slot; duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(prototype_bidx == -1 || - (prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS)); + DUK_ASSERT(prototype_bidx == -1 || (prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS)); DUK__CHECK_SPACE(); @@ -4834,7 +4832,7 @@ tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, h); - DUK_HOBJECT_INCREF(thr, h); /* no side effects */ + DUK_HOBJECT_INCREF(thr, h); /* no side effects */ thr->valstack_top++; /* object is now reachable */ @@ -4864,9 +4862,8 @@ DUK_ASSERT_API_ENTRY(thr); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return duk_get_top_index_unsafe(thr); } @@ -4879,11 +4876,8 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); obj = duk_harray_alloc(thr, flags); DUK_ASSERT(obj != NULL); @@ -4892,11 +4886,11 @@ tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); - DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ + DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom); thr->valstack_top++; - DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ + DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ return ret; } @@ -4908,22 +4902,19 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); obj = duk_harray_alloc(thr, flags); DUK_ASSERT(obj != NULL); tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); - DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ + DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom); thr->valstack_top++; - DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ + DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ return ret; } @@ -4950,12 +4941,7 @@ a = duk_push_harray(thr); - duk_hobject_realloc_props(thr, - (duk_hobject *) a, - 0, - size, - 0, - 0); + duk_hobject_realloc_props(thr, (duk_hobject *) a, 0, size, 0, 0); a->length = size; return a; } @@ -4979,9 +4965,7 @@ DUK__CHECK_SPACE(); - obj = duk_hthread_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); + obj = duk_hthread_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); DUK_ASSERT(obj != NULL); obj->state = DUK_HTHREAD_STATE_INACTIVE; #if defined(DUK_USE_ROM_STRINGS) @@ -5021,8 +5005,7 @@ /* Initial stack size satisfies the stack slack constraints so there * is no need to require stack here. */ - DUK_ASSERT(DUK_VALSTACK_INITIAL_SIZE >= - DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + DUK_ASSERT(DUK_VALSTACK_INITIAL_SIZE >= DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); return ret; } @@ -5041,10 +5024,8 @@ */ obj = duk_hcompfunc_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_COMPFUNC | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_COMPFUNC | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); if (DUK_UNLIKELY(obj == NULL)) { DUK_ERROR_ALLOC_FAILED(thr); DUK_WO_NORETURN(return NULL;); @@ -5072,11 +5053,8 @@ DUK__CHECK_SPACE(); obj = duk_hboundfunc_alloc(thr->heap, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BOUNDFUNC | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BOUNDFUNC | DUK_HOBJECT_FLAG_CONSTRUCTABLE | + DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); if (!obj) { DUK_ERROR_ALLOC_FAILED(thr); DUK_WO_NORETURN(return NULL;); @@ -5094,7 +5072,8 @@ return obj; } -DUK_LOCAL duk_idx_t duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx) { +DUK_LOCAL duk_idx_t +duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx) { duk_hnatfunc *obj; duk_idx_t ret; duk_tval *tv_slot; @@ -5122,7 +5101,8 @@ obj->nargs = func_nargs; DUK_DDD(DUK_DDDPRINT("created native function object with flags: 0x%08lx, nargs=%ld", - (unsigned long) obj->obj.hdr.h_flags, (long) obj->nargs)); + (unsigned long) obj->obj.hdr.h_flags, + (long) obj->nargs)); tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); @@ -5134,7 +5114,7 @@ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) obj, thr->builtinsproto_bidx); return ret; - api_error: +api_error: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } @@ -5144,15 +5124,9 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Default prototype is a Duktape specific %NativeFunctionPrototype% * which provides .length and .name getters. @@ -5165,15 +5139,9 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Must use Function.prototype for standard built-in functions. */ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_FUNCTION_PROTOTYPE); @@ -5184,20 +5152,16 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | + DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Must use Function.prototype for standard built-in functions. */ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_FUNCTION_PROTOTYPE); } -DUK_EXTERNAL duk_idx_t duk_push_c_lightfunc(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic) { +DUK_EXTERNAL duk_idx_t +duk_push_c_lightfunc(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic) { duk_small_uint_t lf_flags; duk_tval *tv_slot; @@ -5226,13 +5190,15 @@ DUK_ASSERT(tv_slot >= thr->valstack_bottom); return (duk_idx_t) (tv_slot - thr->valstack_bottom); - api_error: +api_error: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) { +DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx) { duk_hbufobj *obj; duk_tval *tv_slot; @@ -5254,34 +5220,86 @@ return obj; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* XXX: There's quite a bit of overlap with buffer creation handling in * duk_bi_buffer.c. Look for overlap and refactor. */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK__PACK_ARGS(classnum,protobidx,elemtype,elemshift,istypedarray) \ +#define DUK__PACK_ARGS(classnum, protobidx, elemtype, elemshift, istypedarray) \ (((classnum) << 24) | ((protobidx) << 16) | ((elemtype) << 8) | ((elemshift) << 4) | (istypedarray)) static const duk_uint32_t duk__bufobj_flags_lookup = { /* Node.js Buffers are Uint8Array instances which inherit from Buffer.prototype. */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_ARRAYBUFFER, DUK_BIDX_ARRAYBUFFER_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 0), /* DUK_BUFOBJ_ARRAYBUFFER */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_BIDX_NODEJS_BUFFER_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 1), /* DUK_BUFOBJ_NODEJS_BUFFER */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_DATAVIEW, DUK_BIDX_DATAVIEW_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 0), /* DUK_BUFOBJ_DATAVIEW */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT8ARRAY, DUK_BIDX_INT8ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT8, 0, 1), /* DUK_BUFOBJ_INT8ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 1), /* DUK_BUFOBJ_UINT8ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8CLAMPED, 0, 1), /* DUK_BUFOBJ_UINT8CLAMPEDARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT16ARRAY, DUK_BIDX_INT16ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT16, 1, 1), /* DUK_BUFOBJ_INT16ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT16ARRAY, DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT16, 1, 1), /* DUK_BUFOBJ_UINT16ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT32ARRAY, DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT32, 2, 1), /* DUK_BUFOBJ_INT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT32ARRAY, DUK_BIDX_UINT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT32, 2, 1), /* DUK_BUFOBJ_UINT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT32ARRAY, DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_FLOAT32, 2, 1), /* DUK_BUFOBJ_FLOAT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT64ARRAY, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_FLOAT64, 3, 1) /* DUK_BUFOBJ_FLOAT64ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_ARRAYBUFFER, + DUK_BIDX_ARRAYBUFFER_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 0), /* DUK_BUFOBJ_ARRAYBUFFER */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, + DUK_BIDX_NODEJS_BUFFER_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 1), /* DUK_BUFOBJ_NODEJS_BUFFER */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_DATAVIEW, + DUK_BIDX_DATAVIEW_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 0), /* DUK_BUFOBJ_DATAVIEW */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT8ARRAY, + DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT8, + 0, + 1), /* DUK_BUFOBJ_INT8ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, + DUK_BIDX_UINT8ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 1), /* DUK_BUFOBJ_UINT8ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, + DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8CLAMPED, + 0, + 1), /* DUK_BUFOBJ_UINT8CLAMPEDARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT16ARRAY, + DUK_BIDX_INT16ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT16, + 1, + 1), /* DUK_BUFOBJ_INT16ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT16ARRAY, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT16, + 1, + 1), /* DUK_BUFOBJ_UINT16ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT32ARRAY, + DUK_BIDX_INT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT32, + 2, + 1), /* DUK_BUFOBJ_INT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT32ARRAY, + DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT32, + 2, + 1), /* DUK_BUFOBJ_UINT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT32ARRAY, + DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_FLOAT32, + 2, + 1), /* DUK_BUFOBJ_FLOAT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT64ARRAY, + DUK_BIDX_FLOAT64ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_FLOAT64, + 3, + 1) /* DUK_BUFOBJ_FLOAT64ARRAY */ }; -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) { +DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, + duk_idx_t idx_buffer, + duk_size_t byte_offset, + duk_size_t byte_length, + duk_uint_t flags) { duk_hbufobj *h_bufobj; duk_hbuffer *h_val; duk_hobject *h_arraybuf; @@ -5304,7 +5322,7 @@ } } - DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */ + DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */ lookupidx = flags; if (DUK_UNLIKELY(lookupidx >= sizeof(duk__bufobj_flags_lookup) / sizeof(duk_uint32_t))) { goto arg_error; @@ -5314,9 +5332,9 @@ protobidx = (tmp >> 16) & 0xff; h_arraybuf = duk_get_hobject(thr, idx_buffer); - if (h_arraybuf != NULL && /* argument is an object */ - flags != DUK_BUFOBJ_ARRAYBUFFER && /* creating a view */ - DUK_HOBJECT_GET_CLASS_NUMBER(h_arraybuf) == DUK_HOBJECT_CLASS_ARRAYBUFFER /* argument is ArrayBuffer */) { + if (h_arraybuf != NULL && /* argument is an object */ + flags != DUK_BUFOBJ_ARRAYBUFFER && /* creating a view */ + DUK_HOBJECT_GET_CLASS_NUMBER(h_arraybuf) == DUK_HOBJECT_CLASS_ARRAYBUFFER /* argument is ArrayBuffer */) { duk_uint_t tmp_offset; DUK_HBUFOBJ_ASSERT_VALID((duk_hbufobj *) h_arraybuf); @@ -5353,9 +5371,7 @@ DUK_ASSERT(h_val != NULL); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(classnum), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(classnum), (duk_small_int_t) protobidx); DUK_ASSERT(h_bufobj != NULL); @@ -5378,16 +5394,20 @@ */ return; - range_error: +range_error: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); - arg_error: +arg_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ -DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) { +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, + duk_idx_t idx_buffer, + duk_size_t byte_offset, + duk_size_t byte_length, + duk_uint_t flags) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx_buffer); DUK_UNREF(byte_offset); @@ -5396,9 +5416,14 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ -DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap) { +DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + va_list ap) { duk_hobject *proto; #if defined(DUK_USE_AUGMENT_ERROR_CREATE) duk_small_uint_t augment_flags; @@ -5421,9 +5446,8 @@ /* error gets its 'name' from the prototype */ proto = duk_error_prototype_from_code(thr, err_code); (void) duk_push_object_helper_proto(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR), proto); /* ... and its 'message' from an instance property */ @@ -5446,13 +5470,14 @@ /* Creation time error augmentation */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) /* filename may be NULL in which case file/line is not recorded */ - duk_err_augment_error_create(thr, thr, filename, line, augment_flags); /* may throw an error */ + duk_err_augment_error_create(thr, thr, filename, line, augment_flags); /* may throw an error */ #endif return duk_get_top_index_unsafe(thr); } -DUK_EXTERNAL duk_idx_t duk_push_error_object_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { +DUK_EXTERNAL duk_idx_t +duk_push_error_object_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { va_list ap; duk_idx_t ret; @@ -5480,7 +5505,7 @@ va_end(ap); return ret; } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ DUK_EXTERNAL void *duk_push_buffer_raw(duk_hthread *thr, duk_size_t size, duk_small_uint_t flags) { duk_tval *tv_slot; @@ -5583,13 +5608,10 @@ /* CALLABLE and CONSTRUCTABLE flags are copied from the (initial) * target, see ES2015 Sections 9.5.15 and 9.5.13. */ - flags = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h_target) & - (DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE); - flags |= DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ; + flags = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h_target) & (DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE); + flags |= DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ; if (flags & DUK_HOBJECT_FLAG_CALLABLE) { - flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION) | - DUK_HOBJECT_FLAG_SPECIAL_CALL; + flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION) | DUK_HOBJECT_FLAG_SPECIAL_CALL; } else { flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT); } @@ -5615,25 +5637,25 @@ DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) h_proxy); DUK_HOBJECT_INCREF(thr, (duk_hobject *) h_proxy); tv_slot++; - DUK_TVAL_SET_UNDEFINED(tv_slot); /* ... target handler -> ... proxy undefined */ - thr->valstack_top = tv_slot; /* -> ... proxy */ + DUK_TVAL_SET_UNDEFINED(tv_slot); /* ... target handler -> ... proxy undefined */ + thr->valstack_top = tv_slot; /* -> ... proxy */ DUK_DD(DUK_DDPRINT("created Proxy: %!iT", duk_get_tval(thr, -1))); return (duk_idx_t) (thr->valstack_top - thr->valstack_bottom - 1); - fail_args: +fail_args: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } -#else /* DUK_USE_ES6_PROXY */ +#else /* DUK_USE_ES6_PROXY */ DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr, duk_uint_t proxy_flags) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(proxy_flags); DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ASSERTIONS) DUK_LOCAL void duk__validate_push_heapptr(duk_hthread *thr, void *ptr) { @@ -5660,9 +5682,7 @@ * the finalizer starts executing). */ #if defined(DUK_USE_FINALIZER_SUPPORT) - for (curr = thr->heap->finalize_list; - curr != NULL; - curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { + for (curr = thr->heap->finalize_list; curr != NULL; curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { /* FINALIZABLE is set for all objects on finalize_list * except for an object being finalized right now. So * can't assert here. @@ -5674,18 +5694,18 @@ if (curr == h) { if (DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) h)) { /* Object is currently being finalized. */ - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } else { /* Not being finalized but on finalize_list, * allowed since Duktape 2.1. */ - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_REFERENCE_COUNTING) /* Because refzero_list is now processed to completion inline with @@ -5711,7 +5731,7 @@ #endif while (str != NULL) { if (str == (duk_hstring *) h) { - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; break; } @@ -5720,18 +5740,16 @@ } DUK_ASSERT(found != 0); } else { - for (curr = thr->heap->heap_allocated; - curr != NULL; - curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { + for (curr = thr->heap->heap_allocated; curr != NULL; curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { if (curr == h) { - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } } DUK_ASSERT(found != 0); } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ DUK_EXTERNAL duk_idx_t duk_push_heapptr(duk_hthread *thr, void *ptr) { duk_idx_t ret; @@ -5797,7 +5815,7 @@ * heap_allocated. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); /* Preincremented on finalize_list insert. */ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); /* Preincremented on finalize_list insert. */ DUK_HEAPHDR_PREDEC_REFCOUNT(curr); #endif DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(thr->heap, curr); @@ -5829,10 +5847,9 @@ DUK_ASSERT_API_ENTRY(thr); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ return duk_get_top_index_unsafe(thr); } @@ -5941,12 +5958,12 @@ DUK_ASSERT_API_ENTRY(thr); duk_pop_n(thr, count); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_pop_n_unsafe(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); duk__pop_n_unsafe_raw(thr, count); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Pop N elements without DECREF (in effect "stealing" any actual refcounts). */ #if defined(DUK_USE_REFERENCE_COUNTING) @@ -5969,12 +5986,12 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ DUK_INTERNAL void duk_pop_n_nodecref_unsafe(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); duk_pop_n_unsafe(thr, count); } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* Popping one element is called so often that when footprint is not an issue, * compile a specialized function for it. @@ -5992,7 +6009,7 @@ DUK_ASSERT_API_ENTRY(thr); duk_pop_n_nodecref_unsafe(thr, 1); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_LOCAL DUK_ALWAYS_INLINE void duk__pop_unsafe_raw(duk_hthread *thr) { duk_tval *tv; @@ -6004,7 +6021,7 @@ tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif @@ -6040,14 +6057,14 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ #if defined(DUK_USE_PREFER_SIZE) DUK_INTERNAL void duk_pop_undefined(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); duk_pop_nodecref_unsafe(thr); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_pop_undefined(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->valstack_top != thr->valstack_bottom); @@ -6059,7 +6076,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ #if defined(DUK_USE_PREFER_SIZE) DUK_EXTERNAL void duk_pop_2(duk_hthread *thr) { @@ -6086,14 +6103,14 @@ tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif @@ -6127,7 +6144,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_pop_3(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); @@ -6174,9 +6191,9 @@ * multiplying with sizeof(duk_tval) won't wrap. */ DUK_ASSERT(count >= 0 && count <= (duk_idx_t) DUK_USE_VALSTACK_LIMIT); - DUK_ASSERT((duk_size_t) count <= DUK_SIZE_MAX / sizeof(duk_tval)); /* no wrapping */ + DUK_ASSERT((duk_size_t) count <= DUK_SIZE_MAX / sizeof(duk_tval)); /* no wrapping */ - tv_dst = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) count); /* XXX: uninitialized would be OK */ + tv_dst = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) count); /* XXX: uninitialized would be OK */ DUK_ASSERT(count == 0 || tv_dst != NULL); DUK_ASSERT(!duk_is_bare_object(thr, -1)); @@ -6190,7 +6207,7 @@ * the rest; no refcount operations needed. */ - tv_dst = tv_src; /* when count == 0, same as tv_src (OK) */ + tv_dst = tv_src; /* when count == 0, same as tv_src (OK) */ tv_src = thr->valstack_top - 1; DUK_TVAL_SET_TVAL(tv_dst, tv_src); @@ -6220,9 +6237,8 @@ DUK_ASSERT(h != NULL); DUK_UNREF(h); -#if defined(DUK_USE_ARRAY_FASTPATH) /* close enough */ - if (DUK_LIKELY(DUK_HOBJECT_IS_ARRAY(h) && - ((duk_harray *) h)->length <= DUK_HOBJECT_GET_ASIZE(h))) { +#if defined(DUK_USE_ARRAY_FASTPATH) /* close enough */ + if (DUK_LIKELY(DUK_HOBJECT_IS_ARRAY(h) && ((duk_harray *) h)->length <= DUK_HOBJECT_GET_ASIZE(h))) { duk_harray *h_arr; duk_tval *tv_src; duk_tval *tv_dst; @@ -6243,8 +6259,7 @@ * XXX: alternatively, could prevent finalizers for the * duration. */ - if (DUK_UNLIKELY(len != h_arr->length || - h_arr->length > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr))) { + if (DUK_UNLIKELY(len != h_arr->length || h_arr->length > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr))) { goto skip_fast; } @@ -6263,7 +6278,7 @@ * without an ancestor lookup (technically * not compliant). */ - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_dst)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_dst)); /* valstack policy */ } else { DUK_TVAL_SET_TVAL(tv_dst, tv_src); DUK_TVAL_INCREF(thr, tv_dst); @@ -6275,8 +6290,8 @@ thr->valstack_top = tv_dst; return (duk_idx_t) h_arr->length; } - skip_fast: -#endif /* DUK_USE_ARRAY_FASTPATH */ + skip_fast: +#endif /* DUK_USE_ARRAY_FASTPATH */ /* Slow path: actual lookups. The initial 'length' lookup * decides the output length, regardless of side effects that @@ -6285,7 +6300,7 @@ */ idx = duk_normalize_index(thr, idx); duk_get_prop_stridx(thr, idx, DUK_STRIDX_LENGTH); - len = duk_to_uint32(thr, -1); /* ToUint32() coercion required */ + len = duk_to_uint32(thr, -1); /* ToUint32() coercion required */ if (DUK_UNLIKELY(len >= 0x80000000UL)) { goto fail_over_2g; } @@ -6304,7 +6319,7 @@ DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); - fail_over_2g: +fail_over_2g: DUK_ERROR_RANGE_INVALID_LENGTH(thr); DUK_WO_NORETURN(return 0;); } @@ -6389,7 +6404,12 @@ } } -DUK_EXTERNAL void duk_error_va_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap) { +DUK_EXTERNAL void duk_error_va_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + va_list ap) { DUK_ASSERT_API_ENTRY(thr); duk_push_error_object_va_raw(thr, err_code, filename, line, fmt, ap); @@ -6397,7 +6417,12 @@ DUK_WO_NORETURN(return;); } -DUK_EXTERNAL void duk_error_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { +DUK_EXTERNAL void duk_error_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + ...) { va_list ap; DUK_ASSERT_API_ENTRY(thr); @@ -6416,7 +6441,8 @@ #endif #if !defined(DUK_USE_VARIADIC_MACROS) -DUK_NORETURN(DUK_LOCAL_DECL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap)); +DUK_NORETURN( + DUK_LOCAL_DECL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap)); DUK_LOCAL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap) { const char *filename; @@ -6434,7 +6460,8 @@ DUK_WO_NORETURN(return;); } -#define DUK__ERROR_STASH_SHARED(code) do { \ +#define DUK__ERROR_STASH_SHARED(code) \ + do { \ va_list ap; \ va_start(ap, fmt); \ duk__throw_error_from_stash(thr, (code), fmt, ap); \ @@ -6474,7 +6501,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK__ERROR_STASH_SHARED(DUK_ERR_URI_ERROR); } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ /* * Comparison @@ -6593,7 +6620,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(tv)); - DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags); /* read before 'tv' potentially invalidated */ + DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags); /* read before 'tv' potentially invalidated */ duk_push_literal(thr, "function "); duk_push_lightfunc_name_raw(thr, func, lf_flags); duk_push_literal(thr, "() { lightfunc code }"); @@ -6614,7 +6641,7 @@ duk_small_uint_t t; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(sz <= 32); /* sanity limit for function pointer size */ + DUK_ASSERT(sz <= 32); /* sanity limit for function pointer size */ p = buf; #if defined(DUK_USE_INTEGER_LE) @@ -6643,9 +6670,9 @@ */ /* String limits for summary strings. */ -#define DUK__READABLE_SUMMARY_MAXCHARS 96 /* maximum supported by helper */ -#define DUK__READABLE_STRING_MAXCHARS 32 /* for strings/symbols */ -#define DUK__READABLE_ERRMSG_MAXCHARS 96 /* for error messages */ +#define DUK__READABLE_SUMMARY_MAXCHARS 96 /* maximum supported by helper */ +#define DUK__READABLE_STRING_MAXCHARS 32 /* for strings/symbols */ +#define DUK__READABLE_ERRMSG_MAXCHARS 96 /* for error messages */ /* String sanitizer which escapes ASCII control characters and a few other * ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with @@ -6654,8 +6681,7 @@ */ DUK_LOCAL void duk__push_hstring_readable_unicode(duk_hthread *thr, duk_hstring *h_input, duk_small_uint_t maxchars) { const duk_uint8_t *p, *p_start, *p_end; - duk_uint8_t bufDUK_UNICODE_MAX_XUTF8_LENGTH * DUK__READABLE_SUMMARY_MAXCHARS + - 2 /*quotes*/ + 3 /*periods*/; + duk_uint8_t bufDUK_UNICODE_MAX_XUTF8_LENGTH * DUK__READABLE_SUMMARY_MAXCHARS + 2 /*quotes*/ + 3 /*periods*/; duk_uint8_t *q; duk_ucodepoint_t cp; duk_small_uint_t nchars; @@ -6683,7 +6709,7 @@ } if (duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp)) { if (cp < 0x20 || cp == 0x7f || cp == DUK_ASC_SINGLEQUOTE || cp == DUK_ASC_BACKSLASH) { - DUK_ASSERT(DUK_UNICODE_MAX_XUTF8_LENGTH >= 4); /* estimate is valid */ + DUK_ASSERT(DUK_UNICODE_MAX_XUTF8_LENGTH >= 4); /* estimate is valid */ DUK_ASSERT((cp >> 4) <= 0x0f); *q++ = (duk_uint8_t) DUK_ASC_BACKSLASH; *q++ = (duk_uint8_t) DUK_ASC_LC_X; @@ -6693,7 +6719,7 @@ q += duk_unicode_encode_xutf8(cp, q); } } else { - p++; /* advance manually */ + p++; /* advance manually */ *q++ = (duk_uint8_t) DUK_ASC_QUESTION; } nchars++; @@ -6732,8 +6758,10 @@ duk_hobject *h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); - if (error_aware && - duk_hobject_prototype_chain_contains(thr, h, thr->builtinsDUK_BIDX_ERROR_PROTOTYPE, 1 /*ignore_loop*/)) { + if (error_aware && duk_hobject_prototype_chain_contains(thr, + h, + thr->builtinsDUK_BIDX_ERROR_PROTOTYPE, + 1 /*ignore_loop*/)) { /* Get error message in a side effect free way if * possible; if not, summarize as a generic object. * Error message currently gets quoted. @@ -6747,7 +6775,9 @@ /* It's critical to avoid recursion so * only summarize a string .message. */ - duk__push_hstring_readable_unicode(thr, DUK_TVAL_GET_STRING(tv_msg), DUK__READABLE_ERRMSG_MAXCHARS); + duk__push_hstring_readable_unicode(thr, + DUK_TVAL_GET_STRING(tv_msg), + DUK__READABLE_ERRMSG_MAXCHARS); break; } } @@ -6830,7 +6860,7 @@ * Functions */ -#if 0 /* not used yet */ +#if 0 /* not used yet */ DUK_INTERNAL void duk_push_hnatfunc_name(duk_hthread *thr, duk_hnatfunc *h) { duk_c_function func; @@ -6857,7 +6887,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(thr); - DUK_ASSERT(count * sizeof(duk_tval) >= count); /* no wrap */ + DUK_ASSERT(count * sizeof(duk_tval) >= count); /* no wrap */ duk_memcpy_unsafe((void *) tv_dst, (const void *) tv_src, count * sizeof(duk_tval));
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_string.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_string.c
Changed
@@ -51,15 +51,14 @@ /* Impose a string maximum length, need to handle overflow * correctly. */ - if (new_len < len || /* wrapped */ + if (new_len < len || /* wrapped */ new_len > (duk_size_t) DUK_HSTRING_MAX_BYTELEN) { goto error_overflow; } len = new_len; } - DUK_DDD(DUK_DDDPRINT("join/concat %lu strings, total length %lu bytes", - (unsigned long) count, (unsigned long) len)); + DUK_DDD(DUK_DDDPRINT("join/concat %lu strings, total length %lu bytes", (unsigned long) count, (unsigned long) len)); /* Use stack allocated buffer to ensure reachability in errors * (e.g. intern error). @@ -72,11 +71,11 @@ idx = 0; for (i = count; i >= 1; i--) { if (is_join && i != count) { - h = duk_require_hstring(thr, -((duk_idx_t) count) - 2); /* extra -1 for buffer */ + h = duk_require_hstring(thr, -((duk_idx_t) count) - 2); /* extra -1 for buffer */ duk_memcpy(buf + idx, DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); idx += DUK_HSTRING_GET_BYTELEN(h); } - h = duk_require_hstring(thr, -((duk_idx_t) i) - 1); /* extra -1 for buffer */ + h = duk_require_hstring(thr, -((duk_idx_t) i) - 1); /* extra -1 for buffer */ duk_memcpy(buf + idx, DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); idx += DUK_HSTRING_GET_BYTELEN(h); } @@ -88,21 +87,21 @@ /* Get rid of the strings early to minimize memory use before intern. */ if (is_join) { - duk_replace(thr, -((duk_idx_t) count) - 2); /* overwrite sep */ + duk_replace(thr, -((duk_idx_t) count) - 2); /* overwrite sep */ duk_pop_n(thr, (duk_idx_t) count); } else { - duk_replace(thr, -((duk_idx_t) count) - 1); /* overwrite str1 */ + duk_replace(thr, -((duk_idx_t) count) - 1); /* overwrite str1 */ duk_pop_n(thr, (duk_idx_t) (count - 1)); } /* ... buf */ - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ /* ... res */ return; - error_overflow: +error_overflow: DUK_ERROR_RANGE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return;); } @@ -118,7 +117,7 @@ DUK_ASSERT_API_ENTRY(thr); duk_concat(thr, 2); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_concat_2(duk_hthread *thr) { duk_hstring *h1; duk_hstring *h2; @@ -128,14 +127,14 @@ duk_size_t len; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(duk_get_top(thr) >= 2); /* Trusted caller. */ + DUK_ASSERT(duk_get_top(thr) >= 2); /* Trusted caller. */ h1 = duk_to_hstring(thr, -2); h2 = duk_to_hstring(thr, -1); len1 = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h1); len2 = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h2); len = len1 + len2; - if (DUK_UNLIKELY(len < len1 || /* wrapped */ + if (DUK_UNLIKELY(len < len1 || /* wrapped */ len > (duk_size_t) DUK_HSTRING_MAX_BYTELEN)) { goto error_overflow; } @@ -144,7 +143,7 @@ duk_memcpy((void *) buf, (const void *) DUK_HSTRING_GET_DATA(h1), (size_t) len1); duk_memcpy((void *) (buf + len1), (const void *) DUK_HSTRING_GET_DATA(h2), (size_t) len2); - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ /* ... str1 str2 buf */ @@ -152,11 +151,11 @@ duk_pop_unsafe(thr); return; - error_overflow: +error_overflow: DUK_ERROR_RANGE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_join(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); @@ -175,7 +174,7 @@ DUK_ASSERT_API_ENTRY(thr); - h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ + h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input); @@ -202,11 +201,11 @@ idx = duk_normalize_index(thr, idx); - h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ + h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* Reasonable output estimate. */ + DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* Reasonable output estimate. */ p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); @@ -227,7 +226,7 @@ } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 encoded. */ duk_replace(thr, idx); } @@ -240,7 +239,7 @@ DUK_ASSERT_API_ENTRY(thr); - idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ + idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ h = duk_require_hstring(thr, idx); DUK_ASSERT(h != NULL); @@ -265,7 +264,7 @@ end_byte_offset = (duk_size_t) duk_heap_strcache_offset_char2byte(thr, h, (duk_uint_fast32_t) end_offset); DUK_ASSERT(end_byte_offset >= start_byte_offset); - DUK_ASSERT(end_byte_offset - start_byte_offset <= DUK_UINT32_MAX); /* Guaranteed by string limits. */ + DUK_ASSERT(end_byte_offset - start_byte_offset <= DUK_UINT32_MAX); /* Guaranteed by string limits. */ /* No size check is necessary. */ res = duk_heap_strtable_intern_checked(thr, @@ -281,13 +280,13 @@ */ DUK_EXTERNAL void duk_trim(duk_hthread *thr, duk_idx_t idx) { duk_hstring *h; - const duk_uint8_t *p, *p_start, *p_end, *p_tmp1, *p_tmp2; /* pointers for scanning */ - const duk_uint8_t *q_start, *q_end; /* start (incl) and end (excl) of trimmed part */ + const duk_uint8_t *p, *p_start, *p_end, *p_tmp1, *p_tmp2; /* pointers for scanning */ + const duk_uint8_t *q_start, *q_end; /* start (incl) and end (excl) of trimmed part */ duk_codepoint_t cp; DUK_ASSERT_API_ENTRY(thr); - idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ + idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ h = duk_require_hstring(thr, idx); DUK_ASSERT(h != NULL); @@ -329,7 +328,7 @@ } q_end = p; - scan_done: +scan_done: /* This may happen when forward and backward scanning disagree * (possible for non-extended-UTF-8 strings). */ @@ -342,8 +341,10 @@ DUK_ASSERT(q_end >= q_start); DUK_DDD(DUK_DDDPRINT("trim: p_start=%p, p_end=%p, q_start=%p, q_end=%p", - (const void *) p_start, (const void *) p_end, - (const void *) q_start, (const void *) q_end)); + (const void *) p_start, + (const void *) p_end, + (const void *) q_start, + (const void *) q_end)); if (q_start == p_start && q_end == p_end) { DUK_DDD(DUK_DDDPRINT("nothing was trimmed: avoid interning (hashing etc)")); @@ -364,15 +365,15 @@ * is handling of clamped offsets. */ - h = duk_require_hstring(thr, idx); /* Accept symbols. */ + h = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h != NULL); - DUK_ASSERT_DISABLE(char_offset >= 0); /* Always true, arg is unsigned. */ + DUK_ASSERT_DISABLE(char_offset >= 0); /* Always true, arg is unsigned. */ if (char_offset >= DUK_HSTRING_GET_CHARLEN(h)) { return 0; } - DUK_ASSERT(char_offset <= DUK_UINT_MAX); /* Guaranteed by string limits. */ + DUK_ASSERT(char_offset <= DUK_UINT_MAX); /* Guaranteed by string limits. */ cp = duk_hstring_char_code_at_raw(thr, h, (duk_uint_t) char_offset, 0 /*surrogate_aware*/); return (duk_codepoint_t) cp; }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_api_time.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_api_time.c
Changed
@@ -37,7 +37,7 @@ return duk_time_get_ecmascript_time(thr); } -#if 0 /* XXX: worth exposing? */ +#if 0 /* XXX: worth exposing? */ DUK_EXTERNAL duk_double_t duk_get_monotonic_time(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(thr); @@ -52,7 +52,7 @@ duk_uint_t flags; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(comp != NULL); /* XXX: or check? */ + DUK_ASSERT(comp != NULL); /* XXX: or check? */ DUK_UNREF(thr); /* Convert as one-based, but change month to zero-based to match the @@ -81,7 +81,7 @@ duk_uint_t flags; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(comp != NULL); /* XXX: or check? */ + DUK_ASSERT(comp != NULL); /* XXX: or check? */ DUK_UNREF(thr); /* Match Date constructor behavior (with UTC time). Month is given @@ -102,7 +102,7 @@ dpartsDUK_DATE_IDX_MINUTE = comp->minutes; dpartsDUK_DATE_IDX_SECOND = comp->seconds; dpartsDUK_DATE_IDX_MILLISECOND = comp->milliseconds; - dpartsDUK_DATE_IDX_WEEKDAY = 0; /* ignored */ + dpartsDUK_DATE_IDX_WEEKDAY = 0; /* ignored */ d = duk_bi_date_get_timeval_from_dparts(dparts, flags);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_array.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_array.c
Changed
@@ -43,7 +43,7 @@ /* Perform an intermediate join when this many elements have been pushed * on the value stack. */ -#define DUK__ARRAY_MID_JOIN_LIMIT 4096 +#define DUK__ARRAY_MID_JOIN_LIMIT 4096 #if defined(DUK_USE_ARRAY_BUILTIN) @@ -94,7 +94,7 @@ duk_hobject *h; duk_uint_t flags_mask, flags_bits, flags_value; - DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* because call in progress */ + DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* because call in progress */ tv = DUK_GET_THIS_TVAL_PTR(thr); /* Fast path requires that 'this' is a duk_harray. Read only arrays @@ -106,11 +106,8 @@ } h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); - flags_mask = DUK_HOBJECT_FLAG_ARRAY_PART | \ - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HEAPHDR_FLAG_READONLY; - flags_bits = DUK_HOBJECT_FLAG_ARRAY_PART | \ - DUK_HOBJECT_FLAG_EXOTIC_ARRAY; + flags_mask = DUK_HOBJECT_FLAG_ARRAY_PART | DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HEAPHDR_FLAG_READONLY; + flags_bits = DUK_HOBJECT_FLAG_ARRAY_PART | DUK_HOBJECT_FLAG_EXOTIC_ARRAY; flags_value = DUK_HEAPHDR_GET_FLAGS_RAW((duk_heaphdr *) h); if ((flags_value & flags_mask) != flags_bits) { DUK_DD(DUK_DDPRINT("reject array fast path: object flag check failed")); @@ -136,7 +133,7 @@ DUK_DD(DUK_DDPRINT("array fast path allowed for: %!O", (duk_heaphdr *) h)); return (duk_harray *) h; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ /* * Constructor @@ -206,7 +203,7 @@ */ DUK_DDD(DUK_DDDPRINT("this.join is not callable, fall back to (original) Object.toString")); duk_set_top(thr, 0); - return duk_bi_object_prototype_to_string(thr); /* has access to 'this' binding */ + return duk_bi_object_prototype_to_string(thr); /* has access to 'this' binding */ } /* ... this func */ @@ -215,9 +212,8 @@ /* ... func this */ - DUK_DDD(DUK_DDDPRINT("calling: func=%!iT, this=%!iT", - (duk_tval *) duk_get_tval(thr, -2), - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD( + DUK_DDDPRINT("calling: func=%!iT, this=%!iT", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_call_method(thr, 0); return 1; @@ -247,7 +243,7 @@ (void) duk_push_this_coercible_to_object(thr); duk_insert(thr, 0); n = duk_get_top(thr); - duk_push_array(thr); /* -> ToObject(this) item1 ... itemN arr */ + duk_push_array(thr); /* -> ToObject(this) item1 ... itemN arr */ /* NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index() * (which differs from the official algorithm). If no error is thrown, this @@ -298,7 +294,7 @@ } DUK_ASSERT(duk_is_object(thr, i)); - need_has_check = (DUK_HOBJECT_IS_PROXY(h) != 0); /* Always 0 w/o Proxy support. */ + need_has_check = (DUK_HOBJECT_IS_PROXY(h) != 0); /* Always 0 w/o Proxy support. */ /* ToObject(this) item1 ... itemN arr */ @@ -330,7 +326,7 @@ } } idx++; - DUK_ASSERT(idx != 0U); /* Wrap check above. */ + DUK_ASSERT(idx != 0U); /* Wrap check above. */ } } @@ -345,7 +341,7 @@ DUK_ASSERT_TOP(thr, n + 1); return 1; - fail_wrap: +fail_wrap: DUK_ERROR_RANGE_INVALID_LENGTH(thr); DUK_WO_NORETURN(return 0;); } @@ -391,8 +387,7 @@ (unsigned long) len)); /* The extra (+4) is tight. */ - valstack_required = (duk_idx_t) ((len >= DUK__ARRAY_MID_JOIN_LIMIT ? - DUK__ARRAY_MID_JOIN_LIMIT : len) + 4); + valstack_required = (duk_idx_t) ((len >= DUK__ARRAY_MID_JOIN_LIMIT ? DUK__ARRAY_MID_JOIN_LIMIT : len) + 4); duk_require_stack(thr, valstack_required); duk_dup_0(thr); @@ -403,14 +398,13 @@ idx = 0; for (;;) { DUK_DDD(DUK_DDDPRINT("join idx=%ld", (long) idx)); - if (count >= DUK__ARRAY_MID_JOIN_LIMIT || /* intermediate join to avoid valstack overflow */ + if (count >= DUK__ARRAY_MID_JOIN_LIMIT || /* intermediate join to avoid valstack overflow */ idx >= len) { /* end of loop (careful with len==0) */ /* sep ToObject(this) len sep str0 ... str(count-1) */ - DUK_DDD(DUK_DDDPRINT("mid/final join, count=%ld, idx=%ld, len=%ld", - (long) count, (long) idx, (long) len)); - duk_join(thr, (duk_idx_t) count); /* -> sep ToObject(this) len str */ - duk_dup_0(thr); /* -> sep ToObject(this) len str sep */ - duk_insert(thr, -2); /* -> sep ToObject(this) len sep str */ + DUK_DDD(DUK_DDDPRINT("mid/final join, count=%ld, idx=%ld, len=%ld", (long) count, (long) idx, (long) len)); + duk_join(thr, (duk_idx_t) count); /* -> sep ToObject(this) len str */ + duk_dup_0(thr); /* -> sep ToObject(this) len str sep */ + duk_insert(thr, -2); /* -> sep ToObject(this) len sep str */ count = 1; } if (idx >= len) { @@ -426,7 +420,7 @@ if (to_locale_string) { duk_to_object(thr, -1); duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_LOCALE_STRING); - duk_insert(thr, -2); /* -> ... toLocaleString ToObject(val) */ + duk_insert(thr, -2); /* -> ... toLocaleString ToObject(val) */ duk_call_method(thr, 0); } duk_to_string(thr, -1); @@ -484,7 +478,7 @@ return 1; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ DUK_INTERNAL duk_ret_t duk_bi_array_prototype_pop(duk_hthread *thr) { duk_uint32_t len; @@ -535,7 +529,7 @@ DUK_ASSERT((duk_uint32_t) n <= DUK_UINT32_MAX); if (DUK_UNLIKELY(len + (duk_uint32_t) n < len)) { DUK_D(DUK_DPRINT("Array.prototype.push() would go beyond 32-bit length, throw")); - DUK_DCERROR_RANGE_INVALID_LENGTH(thr); /* != 0 return value returned as is by caller */ + DUK_DCERROR_RANGE_INVALID_LENGTH(thr); /* != 0 return value returned as is by caller */ } if (len + (duk_uint32_t) n > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr)) { /* Array part would need to be extended. Rely on slow path @@ -565,7 +559,7 @@ duk_push_uint(thr, (duk_uint_t) len); return 1; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ DUK_INTERNAL duk_ret_t duk_bi_array_prototype_push(duk_hthread *thr) { /* Note: 'this' is not necessarily an Array object. The push() @@ -640,7 +634,7 @@ duk_bool_t have1, have2; duk_bool_t undef1, undef2; duk_small_int_t ret; - duk_idx_t idx_obj = 1; /* fixed offsets in valstack */ + duk_idx_t idx_obj = 1; /* fixed offsets in valstack */ duk_idx_t idx_fn = 0; duk_hstring *h1, *h2; @@ -661,7 +655,8 @@ if (idx1 == idx2) { DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%ld, idx2=%ld -> indices identical, quick exit", - (long) idx1, (long) idx2)); + (long) idx1, + (long) idx2)); return 0; } @@ -669,8 +664,12 @@ have2 = duk_get_prop_index(thr, idx_obj, (duk_uarridx_t) idx2); DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%ld, idx2=%ld, have1=%ld, have2=%ld, val1=%!T, val2=%!T", - (long) idx1, (long) idx2, (long) have1, (long) have2, - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (long) idx1, + (long) idx2, + (long) have1, + (long) have2, + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); if (have1) { if (have2) { @@ -712,9 +711,9 @@ duk_double_t d; /* No need to check callable; duk_call() will do that. */ - duk_dup(thr, idx_fn); /* -> ... x y fn */ - duk_insert(thr, -3); /* -> ... fn x y */ - duk_call(thr, 2); /* -> ... res */ + duk_dup(thr, idx_fn); /* -> ... x y fn */ + duk_insert(thr, -3); /* -> ... fn x y */ + duk_call(thr, 2); /* -> ... res */ /* ES5 is a bit vague about what to do if the return value is * not a number. ES2015 provides a concrete description: @@ -746,10 +745,10 @@ DUK_ASSERT(h1 != NULL); DUK_ASSERT(h2 != NULL); - ret = duk_js_string_compare(h1, h2); /* retval is directly usable */ + ret = duk_js_string_compare(h1, h2); /* retval is directly usable */ goto pop_ret; - pop_ret: +pop_ret: duk_pop_2_unsafe(thr); DUK_DDD(DUK_DDDPRINT("-> result %ld", (long) ret)); return ret; @@ -757,7 +756,7 @@ DUK_LOCAL void duk__array_sort_swap(duk_hthread *thr, duk_int_t l, duk_int_t r) { duk_bool_t have_l, have_r; - duk_idx_t idx_obj = 1; /* fixed offset in valstack */ + duk_idx_t idx_obj = 1; /* fixed offset in valstack */ if (l == r) { return; @@ -810,8 +809,7 @@ *ptr++ = ''; *ptr++ = '\0'; - DUK_DDD(DUK_DDDPRINT("%s (lo=%ld, hi=%ld, pivot=%ld)", - (const char *) buf, (long) lo, (long) hi, (long) pivot)); + DUK_DDD(DUK_DDDPRINT("%s (lo=%ld, hi=%ld, pivot=%ld)", (const char *) buf, (long) lo, (long) hi, (long) pivot)); } #endif @@ -820,8 +818,7 @@ /* The lo/hi indices may be crossed and hi < 0 is possible at entry. */ - DUK_DDD(DUK_DDDPRINT("duk__array_qsort: lo=%ld, hi=%ld, obj=%!T", - (long) lo, (long) hi, (duk_tval *) duk_get_tval(thr, 1))); + DUK_DDD(DUK_DDDPRINT("duk__array_qsort: lo=%ld, hi=%ld, obj=%!T", (long) lo, (long) hi, (duk_tval *) duk_get_tval(thr, 1))); DUK_ASSERT_TOP(thr, 3); @@ -839,7 +836,7 @@ DUK_ASSERT(hi - lo + 1 >= 2); /* randomized pivot selection */ - p = lo + (duk_int_t) (DUK_UTIL_GET_RANDOM_DOUBLE(thr) * (duk_double_t) (hi - lo + 1)); + p = lo + (duk_int_t) (duk_util_get_random_double(thr) * (duk_double_t) (hi - lo + 1)); DUK_ASSERT(p >= lo && p <= hi); DUK_DDD(DUK_DDDPRINT("lo=%ld, hi=%ld, chose pivot p=%ld", (long) lo, (long) hi, (long) p)); @@ -853,23 +850,21 @@ for (;;) { /* find elements to swap */ for (;;) { - DUK_DDD(DUK_DDDPRINT("left scan: l=%ld, r=%ld, p=%ld", - (long) l, (long) r, (long) p)); + DUK_DDD(DUK_DDDPRINT("left scan: l=%ld, r=%ld, p=%ld", (long) l, (long) r, (long) p)); if (l >= hi) { break; } - if (duk__array_sort_compare(thr, l, p) >= 0) { /* !(l < p) */ + if (duk__array_sort_compare(thr, l, p) >= 0) { /* !(l < p) */ break; } l++; } for (;;) { - DUK_DDD(DUK_DDDPRINT("right scan: l=%ld, r=%ld, p=%ld", - (long) l, (long) r, (long) p)); + DUK_DDD(DUK_DDDPRINT("right scan: l=%ld, r=%ld, p=%ld", (long) l, (long) r, (long) p)); if (r <= lo) { break; } - if (duk__array_sort_compare(thr, p, r) >= 0) { /* !(p < r) */ + if (duk__array_sort_compare(thr, p, r) >= 0) { /* !(p < r) */ break; } r--; @@ -887,7 +882,7 @@ l++; r--; } - done: +done: /* Note that 'l' and 'r' may cross, i.e. r < l */ DUK_ASSERT(l >= lo && l <= hi); DUK_ASSERT(r >= lo && r <= hi); @@ -931,7 +926,7 @@ DUK_ASSERT_TOP(thr, 3); duk_pop_nodecref_unsafe(thr); - return 1; /* return ToObject(this) */ + return 1; /* return ToObject(this) */ } /* @@ -1024,7 +1019,7 @@ for (i = 0; i < del_count; i++) { if (duk_get_prop_index(thr, -3, (duk_uarridx_t) (act_start + i))) { - duk_xdef_prop_index_wec(thr, -2, (duk_uarridx_t) i); /* throw flag irrelevant (false in std alg) */ + duk_xdef_prop_index_wec(thr, -2, (duk_uarridx_t) i); /* throw flag irrelevant (false in std alg) */ } else { duk_pop_undefined(thr); } @@ -1094,7 +1089,7 @@ /* Step 15: insert itemCount elements into the hole made above */ for (i = 0; i < item_count; i++) { - duk_dup(thr, i + 2); /* args start at index 2 */ + duk_dup(thr, i + 2); /* args start at index 2 */ duk_put_prop_index(thr, -4, (duk_uarridx_t) (act_start + i)); } @@ -1157,7 +1152,7 @@ } DUK_ASSERT_TOP(thr, 2); - duk_pop_unsafe(thr); /* -> ToObject(this) */ + duk_pop_unsafe(thr); /* -> ToObject(this) */ return 1; } @@ -1307,26 +1302,32 @@ if (duk_get_prop_index(thr, -2, (duk_uarridx_t) i)) { /* fromPresent = true */ /* ... ToObject(this) ToUint32(length) val */ - duk_put_prop_index(thr, -3, (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ + duk_put_prop_index( + thr, + -3, + (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ } else { /* fromPresent = false */ /* ... ToObject(this) ToUint32(length) val */ duk_pop_undefined(thr); - duk_del_prop_index(thr, -2, (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ + duk_del_prop_index( + thr, + -2, + (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ } DUK_ASSERT_TOP(thr, nargs + 2); } for (i = 0; i < (duk_uint32_t) nargs; i++) { DUK_ASSERT_TOP(thr, nargs + 2); - duk_dup(thr, (duk_idx_t) i); /* -> ... ToObject(this) ToUint32(length) argi */ + duk_dup(thr, (duk_idx_t) i); /* -> ... ToObject(this) ToUint32(length) argi */ duk_put_prop_index(thr, -3, (duk_uarridx_t) i); DUK_ASSERT_TOP(thr, nargs + 2); } DUK_ASSERT_TOP(thr, nargs + 2); duk_push_u32(thr, len + (duk_uint32_t) nargs); - duk_dup_top(thr); /* -> ... ToObject(this) ToUint32(length) final_len final_len */ + duk_dup_top(thr); /* -> ... ToObject(this) ToUint32(length) final_len final_len */ duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_LENGTH); return 1; } @@ -1339,7 +1340,7 @@ duk_idx_t nargs; duk_int_t i, len; duk_int_t from_idx; - duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for indexOf, -1 for lastIndexOf */ + duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for indexOf, -1 for lastIndexOf */ /* lastIndexOf() needs to be a vararg function because we must distinguish * between an undefined fromIndex and a "not given" fromIndex; indexOf() is @@ -1377,10 +1378,7 @@ * lastIndexOf: clamp fromIndex to -len - 1, len - 1 * (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly) */ - from_idx = duk_to_int_clamped(thr, - 1, - (idx_step > 0 ? -len : -len - 1), - (idx_step > 0 ? len : len - 1)); + from_idx = duk_to_int_clamped(thr, 1, (idx_step > 0 ? -len : -len - 1), (idx_step > 0 ? len : len - 1)); if (from_idx < 0) { /* for lastIndexOf, result may be -1 (mark immediate termination) */ from_idx = len + from_idx; @@ -1416,7 +1414,7 @@ duk_pop_unsafe(thr); } - not_found: +not_found: duk_push_int(thr, -1); return 1; } @@ -1425,11 +1423,11 @@ * every(), some(), forEach(), map(), filter() */ -#define DUK__ITER_EVERY 0 -#define DUK__ITER_SOME 1 -#define DUK__ITER_FOREACH 2 -#define DUK__ITER_MAP 3 -#define DUK__ITER_FILTER 4 +#define DUK__ITER_EVERY 0 +#define DUK__ITER_SOME 1 +#define DUK__ITER_FOREACH 2 +#define DUK__ITER_MAP 3 +#define DUK__ITER_FILTER 4 /* XXX: This helper is a bit awkward because the handling for the different iteration * callers is quite different. This now compiles to a bit less than 500 bytes, so with @@ -1464,7 +1462,7 @@ * stack4 = result array (or undefined) */ - k = 0; /* result index for filter() */ + k = 0; /* result index for filter() */ for (i = 0; i < len; i++) { DUK_ASSERT_TOP(thr, 5); @@ -1488,7 +1486,7 @@ duk_dup_1(thr); duk_dup_m3(thr); duk_push_u32(thr, i); - duk_dup_2(thr); /* ... val callback thisArg val i obj */ + duk_dup_2(thr); /* ... val callback thisArg val i obj */ duk_call_method(thr, 3); /* -> ... val retval */ switch (iter_type) { @@ -1511,13 +1509,13 @@ break; case DUK__ITER_MAP: duk_dup_top(thr); - duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) i); /* retval to resulti */ + duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) i); /* retval to resulti */ res_length = i + 1; break; case DUK__ITER_FILTER: bval = duk_to_boolean(thr, -1); if (bval) { - duk_dup_m2(thr); /* orig value */ + duk_dup_m2(thr); /* orig value */ duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) k); k++; res_length = k; @@ -1545,7 +1543,7 @@ case DUK__ITER_MAP: case DUK__ITER_FILTER: DUK_ASSERT_TOP(thr, 5); - DUK_ASSERT(duk_is_array(thr, -1)); /* topmost element is the result array already */ + DUK_ASSERT(duk_is_array(thr, -1)); /* topmost element is the result array already */ duk_push_u32(thr, res_length); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W); break; @@ -1565,7 +1563,7 @@ duk_idx_t nargs; duk_bool_t have_acc; duk_uint32_t i, len; - duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for reduce, -1 for reduceRight */ + duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for reduce, -1 for reduceRight */ /* We're a varargs function because we need to detect whether * initialValue was given or not. @@ -1589,8 +1587,7 @@ duk_dup_1(thr); have_acc = 1; } - DUK_DDD(DUK_DDDPRINT("have_acc=%ld, acc=%!T", - (long) have_acc, (duk_tval *) duk_get_tval(thr, 3))); + DUK_DDD(DUK_DDDPRINT("have_acc=%ld, acc=%!T", (long) have_acc, (duk_tval *) duk_get_tval(thr, 3))); /* For len == 0, i is initialized to len - 1 which underflows. * The condition (i < len) will then exit the for-loop on the @@ -1598,16 +1595,16 @@ * happens by i underflowing. */ - for (i = (idx_step >= 0 ? 0 : len - 1); - i < len; /* i >= 0 would always be true */ + for (i = (idx_step >= 0 ? 0 : len - 1); i < len; /* i >= 0 would always be true */ i += (duk_uint32_t) idx_step) { DUK_DDD(DUK_DDDPRINT("i=%ld, len=%ld, have_acc=%ld, top=%ld, acc=%!T", - (long) i, (long) len, (long) have_acc, + (long) i, + (long) len, + (long) have_acc, (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, 4))); - DUK_ASSERT((have_acc && duk_get_top(thr) == 5) || - (!have_acc && duk_get_top(thr) == 4)); + DUK_ASSERT((have_acc && duk_get_top(thr) == 5) || (!have_acc && duk_get_top(thr) == 4)); if (!duk_has_prop_index(thr, 2, (duk_uarridx_t) i)) { continue; @@ -1626,8 +1623,10 @@ duk_push_u32(thr, i); duk_dup_2(thr); DUK_DDD(DUK_DDDPRINT("calling reduce function: func=%!T, prev=%!T, curr=%!T, idx=%!T, obj=%!T", - (duk_tval *) duk_get_tval(thr, -5), (duk_tval *) duk_get_tval(thr, -4), - (duk_tval *) duk_get_tval(thr, -3), (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -5), + (duk_tval *) duk_get_tval(thr, -4), + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_call(thr, 4); DUK_DDD(DUK_DDDPRINT("-> result: %!T", (duk_tval *) duk_get_tval(thr, -1))); @@ -1644,4 +1643,4 @@ return 1; } -#endif /* DUK_USE_ARRAY_BUILTIN */ +#endif /* DUK_USE_ARRAY_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_boolean.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_boolean.c
Changed
@@ -39,7 +39,7 @@ DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* never here */ - type_ok: +type_ok: if (coerce_tostring) { duk_to_string(thr, -1); } @@ -59,11 +59,11 @@ DUK_HOBJECT_SET_CLASS_NUMBER(h_this, DUK_HOBJECT_CLASS_BOOLEAN); - duk_dup_0(thr); /* -> val obj val */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); /* XXX: proper flags? */ - } /* unbalanced stack */ + duk_dup_0(thr); /* -> val obj val */ + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); /* XXX: proper flags? */ + } /* unbalanced stack */ return 1; } -#endif /* DUK_USE_BOOLEAN_BUILTIN */ +#endif /* DUK_USE_BOOLEAN_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_buffer.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_buffer.c
Changed
@@ -13,57 +13,38 @@ * default internal prototype. */ static const duk_uint8_t duk__buffer_proto_from_classnum = { - DUK_BIDX_ARRAYBUFFER_PROTOTYPE, - DUK_BIDX_DATAVIEW_PROTOTYPE, - DUK_BIDX_INT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, - DUK_BIDX_INT16ARRAY_PROTOTYPE, - DUK_BIDX_UINT16ARRAY_PROTOTYPE, - DUK_BIDX_INT32ARRAY_PROTOTYPE, - DUK_BIDX_UINT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT64ARRAY_PROTOTYPE + DUK_BIDX_ARRAYBUFFER_PROTOTYPE, DUK_BIDX_DATAVIEW_PROTOTYPE, DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_BIDX_INT16ARRAY_PROTOTYPE, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE }; /* Map DUK_HBUFOBJ_ELEM_xxx to duk_hobject class number. * Sync with duk_hbufobj.h and duk_hobject.h. */ -static const duk_uint8_t duk__buffer_class_from_elemtype9 = { - DUK_HOBJECT_CLASS_UINT8ARRAY, - DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, - DUK_HOBJECT_CLASS_INT8ARRAY, - DUK_HOBJECT_CLASS_UINT16ARRAY, - DUK_HOBJECT_CLASS_INT16ARRAY, - DUK_HOBJECT_CLASS_UINT32ARRAY, - DUK_HOBJECT_CLASS_INT32ARRAY, - DUK_HOBJECT_CLASS_FLOAT32ARRAY, - DUK_HOBJECT_CLASS_FLOAT64ARRAY -}; +static const duk_uint8_t duk__buffer_class_from_elemtype9 = { DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, + DUK_HOBJECT_CLASS_INT8ARRAY, DUK_HOBJECT_CLASS_UINT16ARRAY, + DUK_HOBJECT_CLASS_INT16ARRAY, DUK_HOBJECT_CLASS_UINT32ARRAY, + DUK_HOBJECT_CLASS_INT32ARRAY, DUK_HOBJECT_CLASS_FLOAT32ARRAY, + DUK_HOBJECT_CLASS_FLOAT64ARRAY }; /* Map DUK_HBUFOBJ_ELEM_xxx to prototype object built-in index. * Sync with duk_hbufobj.h. */ static const duk_uint8_t duk__buffer_proto_from_elemtype9 = { - DUK_BIDX_UINT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, - DUK_BIDX_INT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT16ARRAY_PROTOTYPE, - DUK_BIDX_INT16ARRAY_PROTOTYPE, - DUK_BIDX_UINT32ARRAY_PROTOTYPE, - DUK_BIDX_INT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT64ARRAY_PROTOTYPE + DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_BIDX_INT16ARRAY_PROTOTYPE, DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE }; /* Map DUK__FLD_xxx to byte size. */ static const duk_uint8_t duk__buffer_nbytes_from_fldtype6 = { - 1, /* DUK__FLD_8BIT */ - 2, /* DUK__FLD_16BIT */ - 4, /* DUK__FLD_32BIT */ - 4, /* DUK__FLD_FLOAT */ - 8, /* DUK__FLD_DOUBLE */ - 0 /* DUK__FLD_VARINT; not relevant here */ + 1, /* DUK__FLD_8BIT */ + 2, /* DUK__FLD_16BIT */ + 4, /* DUK__FLD_32BIT */ + 4, /* DUK__FLD_FLOAT */ + 8, /* DUK__FLD_DOUBLE */ + 0 /* DUK__FLD_VARINT; not relevant here */ }; /* Bitfield for each DUK_HBUFOBJ_ELEM_xxx indicating which element types @@ -75,36 +56,27 @@ #if !defined(DUK_USE_PREFER_SIZE) static duk_uint16_t duk__buffer_elemtype_copy_compatible9 = { /* xxx -> DUK_HBUFOBJ_ELEM_UINT8 */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | - (1U << DUK_HBUFOBJ_ELEM_INT8), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | (1U << DUK_HBUFOBJ_ELEM_INT8), /* xxx -> DUK_HBUFOBJ_ELEM_UINT8CLAMPED * Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00. */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED), /* xxx -> DUK_HBUFOBJ_ELEM_INT8 */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | - (1U << DUK_HBUFOBJ_ELEM_INT8), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | (1U << DUK_HBUFOBJ_ELEM_INT8), /* xxx -> DUK_HBUFOBJ_ELEM_UINT16 */ - (1U << DUK_HBUFOBJ_ELEM_UINT16) | - (1U << DUK_HBUFOBJ_ELEM_INT16), + (1U << DUK_HBUFOBJ_ELEM_UINT16) | (1U << DUK_HBUFOBJ_ELEM_INT16), /* xxx -> DUK_HBUFOBJ_ELEM_INT16 */ - (1U << DUK_HBUFOBJ_ELEM_UINT16) | - (1U << DUK_HBUFOBJ_ELEM_INT16), + (1U << DUK_HBUFOBJ_ELEM_UINT16) | (1U << DUK_HBUFOBJ_ELEM_INT16), /* xxx -> DUK_HBUFOBJ_ELEM_UINT32 */ - (1U << DUK_HBUFOBJ_ELEM_UINT32) | - (1U << DUK_HBUFOBJ_ELEM_INT32), + (1U << DUK_HBUFOBJ_ELEM_UINT32) | (1U << DUK_HBUFOBJ_ELEM_INT32), /* xxx -> DUK_HBUFOBJ_ELEM_INT32 */ - (1U << DUK_HBUFOBJ_ELEM_UINT32) | - (1U << DUK_HBUFOBJ_ELEM_INT32), + (1U << DUK_HBUFOBJ_ELEM_UINT32) | (1U << DUK_HBUFOBJ_ELEM_INT32), /* xxx -> DUK_HBUFOBJ_ELEM_FLOAT32 */ (1U << DUK_HBUFOBJ_ELEM_FLOAT32), @@ -112,7 +84,7 @@ /* xxx -> DUK_HBUFOBJ_ELEM_FLOAT64 */ (1U << DUK_HBUFOBJ_ELEM_FLOAT64) }; -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_LOCAL duk_hbufobj *duk__hbufobj_promote_this(duk_hthread *thr) { duk_tval *tv_dst; @@ -131,8 +103,8 @@ return res; } -#define DUK__BUFOBJ_FLAG_THROW (1 << 0) -#define DUK__BUFOBJ_FLAG_PROMOTE (1 << 1) +#define DUK__BUFOBJ_FLAG_THROW (1 << 0) +#define DUK__BUFOBJ_FLAG_PROMOTE (1 << 1) /* Shared helper. When DUK__BUFOBJ_FLAG_PROMOTE is given, the return value is * always a duk_hbufobj *. Without the flag the return value can also be a @@ -223,7 +195,7 @@ DUK_LOCAL void duk__set_bufobj_buffer(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_hbuffer *h_val) { DUK_ASSERT(thr != NULL); DUK_ASSERT(h_bufobj != NULL); - DUK_ASSERT(h_bufobj->buf == NULL); /* no need to decref */ + DUK_ASSERT(h_bufobj->buf == NULL); /* no need to decref */ DUK_ASSERT(h_val != NULL); DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); DUK_UNREF(thr); @@ -259,12 +231,12 @@ if (offset > h_bufarg->length) { goto fail_range; } - DUK_ASSERT_DISABLE(offset >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(offset >= 0); /* unsigned */ DUK_ASSERT(offset <= h_bufarg->length); if (duk_is_undefined(thr, idx_length)) { DUK_ASSERT(h_bufarg->length >= offset); - length = h_bufarg->length - offset; /* >= 0 */ + length = h_bufarg->length - offset; /* >= 0 */ } else { length_signed = duk_to_int(thr, idx_length); if (length_signed < 0) { @@ -283,14 +255,14 @@ } } } - DUK_ASSERT_DISABLE(length >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(length >= 0); /* unsigned */ DUK_ASSERT(offset + length <= h_bufarg->length); *out_offset = offset; *out_length = length; return; - fail_range: +fail_range: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); } @@ -348,7 +320,7 @@ DUK_ASSERT(out_start_offset != NULL); DUK_ASSERT(out_end_offset != NULL); - buffer_length >>= buffer_shift; /* as (full) elements */ + buffer_length >>= buffer_shift; /* as (full) elements */ /* Resolve start/end offset as element indices first; arguments * at idx_start/idx_end are element offsets. Working with element @@ -440,7 +412,10 @@ } /* Indexed read helper for buffer objects, also called from outside this file. */ -DUK_INTERNAL void duk_hbufobj_push_validated_read(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size) { +DUK_INTERNAL void duk_hbufobj_push_validated_read(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size) { duk_double_union du; DUK_ASSERT(elem_size > 0); @@ -588,17 +563,17 @@ DUK_WO_NORETURN(return NULL;); } - done: +done: DUK_ASSERT(duk_is_buffer(thr, -1)); return duk_known_hbuffer(thr, -1); - slow_copy: +slow_copy: /* XXX: fast path for typed arrays and other buffer objects? */ (void) duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_LENGTH); len = duk_to_int_clamped(thr, -1, 0, DUK_INT_MAX); duk_pop(thr); - buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) len); /* no zeroing, all indices get initialized */ + buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) len); /* no zeroing, all indices get initialized */ for (i = 0; i < len; i++) { /* XXX: fast path for array or buffer arguments? */ duk_get_prop_index(thr, 0, (duk_uarridx_t) i); @@ -607,7 +582,7 @@ } goto done; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer constructor @@ -624,11 +599,7 @@ h_buf = duk__hbufobj_fixed_from_argvalue(thr); DUK_ASSERT(h_buf != NULL); - duk_push_buffer_object(thr, - -1, - 0, - DUK_HBUFFER_FIXED_GET_SIZE((duk_hbuffer_fixed *) (void *) h_buf), - DUK_BUFOBJ_UINT8ARRAY); + duk_push_buffer_object(thr, -1, 0, DUK_HBUFFER_FIXED_GET_SIZE((duk_hbuffer_fixed *) (void *) h_buf), DUK_BUFOBJ_UINT8ARRAY); duk_push_hobject_bidx(thr, DUK_BIDX_NODEJS_BUFFER_PROTOTYPE); duk_set_prototype(thr, -2); @@ -636,7 +607,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * ArrayBuffer, DataView, and TypedArray constructors @@ -660,9 +631,8 @@ h_val = (duk_hbuffer *) duk_known_hbuffer(thr, -1); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), DUK_BIDX_ARRAYBUFFER_PROTOTYPE); DUK_ASSERT(h_bufobj != NULL); @@ -671,11 +641,10 @@ return 1; - fail_length: +fail_length: DUK_DCERROR_RANGE_INVALID_LENGTH(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ - +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Format of magic, bits: * 0...1: elem size shift (0-3) @@ -715,8 +684,8 @@ * element type. */ magic = (duk_small_uint_t) duk_get_current_magic(thr); - shift = magic & 0x03U; /* bits 0...1: shift */ - elem_type = (magic >> 2) & 0x0fU; /* bits 2...5: type */ + shift = magic & 0x03U; /* bits 0...1: shift */ + elem_type = (magic >> 2) & 0x0fU; /* bits 2...5: type */ elem_size = 1U << shift; align_mask = elem_size - 1; DUK_ASSERT(elem_type < sizeof(duk__buffer_proto_from_elemtype) / sizeof(duk_uint8_t)); @@ -727,8 +696,12 @@ DUK_DD(DUK_DDPRINT("typedarray constructor, magic=%d, shift=%d, elem_type=%d, " "elem_size=%d, proto_bidx=%d, class_num=%d", - (int) magic, (int) shift, (int) elem_type, (int) elem_size, - (int) proto_bidx, (int) class_num)); + (int) magic, + (int) shift, + (int) elem_type, + (int) elem_size, + (int) proto_bidx, + (int) class_num)); /* Argument variants. When the argument is an ArrayBuffer a view to * the same buffer is created; otherwise a new ArrayBuffer is always @@ -742,7 +715,7 @@ duk_hbufobj_promote_plain(thr, 0); tv = duk_get_tval(thr, 0); - DUK_ASSERT(tv != NULL); /* arg count */ + DUK_ASSERT(tv != NULL); /* arg count */ if (DUK_TVAL_IS_OBJECT(tv)) { h_obj = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h_obj != NULL); @@ -762,8 +735,7 @@ goto fail_arguments; } byte_offset = (duk_uint_t) byte_offset_signed; - if (byte_offset > h_bufarg->length || - (byte_offset & align_mask) != 0) { + if (byte_offset > h_bufarg->length || (byte_offset & align_mask) != 0) { /* Must be >= 0 and multiple of element size. */ goto fail_arguments; } @@ -803,9 +775,8 @@ DUK_ASSERT((elem_length << shift) == byte_length); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(class_num), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(class_num), (duk_small_int_t) proto_bidx); h_val = h_bufarg->buf; if (h_val == NULL) { @@ -848,11 +819,13 @@ "src byte_length=%ld, src shift=%d, " "src/dst elem_length=%ld; " "dst shift=%d -> dst byte_length=%ld", - (long) h_bufarg->length, (int) h_bufarg->shift, - (long) elem_length_signed, (int) shift, + (long) h_bufarg->length, + (int) h_bufarg->shift, + (long) elem_length_signed, + (int) shift, (long) (elem_length_signed << shift))); - copy_mode = 2; /* default is explicit index read/write copy */ + copy_mode = 2; /* default is explicit index read/write copy */ #if !defined(DUK_USE_PREFER_SIZE) /* With a size optimized build copy_mode 2 is enough. * Modes 0 and 1 are faster but conceptually the same. @@ -861,14 +834,14 @@ if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { if ((duk__buffer_elemtype_copy_compatibleelem_type & (1 << h_bufarg->elem_type)) != 0) { DUK_DDD(DUK_DDDPRINT("source/target are copy compatible, memcpy")); - DUK_ASSERT(shift == h_bufarg->shift); /* byte sizes will match */ + DUK_ASSERT(shift == h_bufarg->shift); /* byte sizes will match */ copy_mode = 0; } else { DUK_DDD(DUK_DDDPRINT("source/target not copy compatible but valid, fast copy")); copy_mode = 1; } } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ } else { /* Array or Array-like */ elem_length_signed = (duk_int_t) duk_get_length(thr, 0); @@ -893,8 +866,7 @@ goto fail_arguments; } - DUK_DDD(DUK_DDDPRINT("elem_length=%ld, byte_length=%ld", - (long) elem_length, (long) byte_length)); + DUK_DDD(DUK_DDDPRINT("elem_length=%ld, byte_length=%ld", (long) elem_length, (long) byte_length)); /* ArrayBuffer argument is handled specially above; the rest of the * argument variants are handled by shared code below. @@ -909,11 +881,10 @@ h_val = duk_known_hbuffer(thr, -1); DUK_ASSERT(h_val != NULL); - h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(class_num), - (duk_small_int_t) proto_bidx); + h_bufobj = + duk_push_bufobj_raw(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(class_num), + (duk_small_int_t) proto_bidx); h_bufobj->buf = h_val; DUK_HBUFFER_INCREF(thr, h_val); @@ -953,7 +924,9 @@ p_src = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufarg); DUK_DDD(DUK_DDDPRINT("using memcpy: p_src=%p, p_dst=%p, byte_length=%ld", - (void *) p_src, (void *) p_dst, (long) byte_length)); + (void *) p_src, + (void *) p_dst, + (long) byte_length)); duk_memcpy_unsafe((void *) p_dst, (const void *) p_src, (size_t) byte_length); break; @@ -983,13 +956,18 @@ DUK_DDD(DUK_DDDPRINT("using fast copy: p_src=%p, p_src_end=%p, p_dst=%p, " "src_elem_size=%d, dst_elem_size=%d", - (void *) p_src, (void *) p_src_end, (void *) p_dst, - (int) src_elem_size, (int) dst_elem_size)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst, + (int) src_elem_size, + (int) dst_elem_size)); while (p_src != p_src_end) { DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: " "p_src=%p, p_src_end=%p, p_dst=%p", - (void *) p_src, (void *) p_src_end, (void *) p_dst)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst)); /* A validated read() is always a number, so it's write coercion * is always side effect free an won't invalidate pointers etc. */ @@ -1001,7 +979,7 @@ } break; } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ case 2: { /* Copy values by index reads and writes. Let virtual * property handling take care of coercion. @@ -1030,10 +1008,10 @@ return 1; - fail_arguments: +fail_arguments: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* When bufferobject support is disabled, new Uint8Array() could still be * supported to create a plain fixed buffer. Disabled for now. */ @@ -1060,8 +1038,8 @@ fail_arguments: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* 0 */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* 0 */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_dataview_constructor(duk_hthread *thr) { @@ -1084,9 +1062,8 @@ DUK_ASSERT(offset + length <= h_bufarg->length); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATAVIEW), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATAVIEW), DUK_BIDX_DATAVIEW_PROTOTYPE); h_val = h_bufarg->buf; @@ -1109,7 +1086,7 @@ DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * ArrayBuffer.isView() @@ -1135,7 +1112,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Uint8Array.allocPlain() @@ -1146,7 +1123,7 @@ duk__hbufobj_fixed_from_argvalue(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Uint8Array.plainOf() @@ -1175,7 +1152,7 @@ } return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer: toString(encoding, start, end) @@ -1206,12 +1183,11 @@ &end_offset); slice_length = (duk_size_t) (end_offset - start_offset); - buf_slice = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, slice_length); /* all bytes initialized below */ + buf_slice = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, slice_length); /* all bytes initialized below */ DUK_ASSERT(buf_slice != NULL); /* Neutered or uncovered, TypeError. */ - if (h_this->buf == NULL || - !DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, (duk_size_t) start_offset + slice_length)) { + if (h_this->buf == NULL || !DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, (duk_size_t) start_offset + slice_length)) { DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -1234,7 +1210,7 @@ duk_set_top(thr, 1); return duk_textdecoder_decode_utf8_nodejs(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype: toJSON() @@ -1264,19 +1240,19 @@ /* XXX: uninitialized would be OK */ DUK_ASSERT_DISABLE((duk_size_t) h_this->length <= (duk_size_t) DUK_UINT32_MAX); - tv = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) h_this->length); /* XXX: needs revision with >4G buffers */ + tv = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) h_this->length); /* XXX: needs revision with >4G buffers */ DUK_ASSERT(!duk_is_bare_object(thr, -1)); DUK_ASSERT(h_this->buf != NULL); buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); for (i = 0, n = h_this->length; i < n; i++) { - DUK_TVAL_SET_U32(tv + i, (duk_uint32_t) bufi); /* no need for decref or incref */ + DUK_TVAL_SET_U32(tv + i, (duk_uint32_t) bufi); /* no need for decref or incref */ } duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_DATA); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.equals() @@ -1311,14 +1287,14 @@ * matters is to be memory safe. */ - if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg1) && - DUK_HBUFOBJ_VALID_SLICE(h_bufarg2)) { - comp_res = duk_js_data_compare((const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg1->buf) + h_bufarg1->offset, - (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg2->buf) + h_bufarg2->offset, - (duk_size_t) h_bufarg1->length, - (duk_size_t) h_bufarg2->length); + if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg1) && DUK_HBUFOBJ_VALID_SLICE(h_bufarg2)) { + comp_res = duk_js_data_compare( + (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg1->buf) + h_bufarg1->offset, + (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg2->buf) + h_bufarg2->offset, + (duk_size_t) h_bufarg1->length, + (duk_size_t) h_bufarg2->length); } else { - comp_res = -1; /* either nonzero value is ok */ + comp_res = -1; /* either nonzero value is ok */ } if (magic & 0x01U) { @@ -1331,7 +1307,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.fill() @@ -1376,7 +1352,10 @@ &fill_end); DUK_DDD(DUK_DDDPRINT("fill: fill_value=%02x, fill_offset=%ld, fill_end=%ld, view length=%ld", - (unsigned int) fill_value, (long) fill_offset, (long) fill_end, (long) h_this->length)); + (unsigned int) fill_value, + (long) fill_offset, + (long) fill_end, + (long) h_this->length)); DUK_ASSERT(fill_end - fill_offset >= 0); DUK_ASSERT(h_this->buf != NULL); @@ -1405,7 +1384,7 @@ duk_push_this(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.write(string, offset, length, encoding) @@ -1448,7 +1427,7 @@ duk_push_uint(thr, length); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.copy() @@ -1483,8 +1462,11 @@ DUK_DDD(DUK_DDDPRINT("checking copy args: target_start=%ld, target_length=%ld, " "source_start=%ld, source_end=%ld, source_length=%ld", - (long) target_start, (long) h_bufarg->length, - (long) source_start, (long) source_end, (long) source_length)); + (long) target_start, + (long) h_bufarg->length, + (long) source_start, + (long) source_end, + (long) source_length)); /* This behavior mostly mimics Node.js now. */ @@ -1495,9 +1477,9 @@ source_ustart = (duk_uint_t) source_start; source_uend = (duk_uint_t) source_end; target_ustart = (duk_uint_t) target_start; - if (source_ustart >= source_uend || /* crossed offsets or zero size */ - source_ustart >= (duk_uint_t) source_length || /* source out-of-bounds (but positive) */ - target_ustart >= (duk_uint_t) target_length) { /* target out-of-bounds (but positive) */ + if (source_ustart >= source_uend || /* crossed offsets or zero size */ + source_ustart >= (duk_uint_t) source_length || /* source out-of-bounds (but positive) */ + target_ustart >= (duk_uint_t) target_length) { /* target out-of-bounds (but positive) */ goto silent_ignore; } if (source_uend >= (duk_uint_t) source_length) { @@ -1513,13 +1495,14 @@ * values in duk_int_t range. Adding them as duk_uint_t * values is then guaranteed not to overflow. */ - DUK_ASSERT(target_ustart + copy_size >= target_ustart); /* no overflow */ - DUK_ASSERT(target_ustart + copy_size >= copy_size); /* no overflow */ + DUK_ASSERT(target_ustart + copy_size >= target_ustart); /* no overflow */ + DUK_ASSERT(target_ustart + copy_size >= copy_size); /* no overflow */ copy_size = (duk_uint_t) target_length - target_ustart; } DUK_DDD(DUK_DDDPRINT("making copy: target_ustart=%lu source_ustart=%lu copy_size=%lu", - (unsigned long) target_ustart, (unsigned long) source_ustart, + (unsigned long) target_ustart, + (unsigned long) source_ustart, (unsigned long) copy_size)); DUK_ASSERT(copy_size >= 1); @@ -1529,8 +1512,8 @@ DUK_ASSERT(target_ustart + copy_size <= (duk_uint_t) target_length); /* Ensure copy is covered by underlying buffers. */ - DUK_ASSERT(h_bufarg->buf != NULL); /* length check */ - DUK_ASSERT(h_this->buf != NULL); /* length check */ + DUK_ASSERT(h_bufarg->buf != NULL); /* length check */ + DUK_ASSERT(h_this->buf != NULL); /* length check */ if (DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufarg, target_ustart + copy_size) && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, source_ustart + copy_size)) { /* Must use memmove() because copy area may overlap (source and target @@ -1543,18 +1526,18 @@ DUK_DDD(DUK_DDDPRINT("buffer copy not covered by underlying buffer(s), ignoring")); } - silent_ignore: +silent_ignore: /* Return value is like write(), number of bytes written. * The return value matters because of code like: * "off += buf.copy(...)". - */ + */ duk_push_uint(thr, copy_size); return 1; - fail_bounds: +fail_bounds: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * TypedArray.prototype.set() @@ -1666,16 +1649,15 @@ } /* Nominal size check. */ - src_length = h_bufarg->length; /* bytes in source */ - dst_length_elems = (src_length >> h_bufarg->shift); /* elems in source and dest */ - dst_length = dst_length_elems << h_this->shift; /* bytes in dest */ + src_length = h_bufarg->length; /* bytes in source */ + dst_length_elems = (src_length >> h_bufarg->shift); /* elems in source and dest */ + dst_length = dst_length_elems << h_this->shift; /* bytes in dest */ if ((dst_length >> h_this->shift) != dst_length_elems) { /* Byte length would overflow. */ /* XXX: easier check with less code? */ goto fail_args; } - DUK_DDD(DUK_DDDPRINT("nominal size check: src_length=%ld, dst_length=%ld", - (long) src_length, (long) dst_length)); + DUK_DDD(DUK_DDDPRINT("nominal size check: src_length=%ld, dst_length=%ld", (long) src_length, (long) dst_length)); DUK_ASSERT(offset_bytes <= h_this->length); if (dst_length > h_this->length - offset_bytes) { /* Overflow not an issue because subtraction is used on the right @@ -1696,8 +1678,7 @@ * cover the copy. No side effects are allowed after the check * so that the validity status doesn't change. */ - if (!DUK_HBUFOBJ_VALID_SLICE(h_this) || - !DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { + if (!DUK_HBUFOBJ_VALID_SLICE(h_this) || !DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { /* The condition could be more narrow and check for the * copy area only, but there's no need for fine grained * behavior when the underlying buffer is misconfigured. @@ -1728,7 +1709,7 @@ return 0; } DUK_DDD(DUK_DDDPRINT("fast path: views are not compatible with a byte copy, copy by item")); -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ /* We want to avoid making a copy to process set() but that's * not always possible: the source and the target may overlap @@ -1748,11 +1729,13 @@ DUK_DDD(DUK_DDDPRINT("overlap check: p_src_base=%p, src_length=%ld, " "p_dst_base=%p, dst_length=%ld", - (void *) p_src_base, (long) src_length, - (void *) p_dst_base, (long) dst_length)); + (void *) p_src_base, + (long) src_length, + (void *) p_dst_base, + (long) dst_length)); - if (p_src_base >= p_dst_base + dst_length || /* source starts after dest ends */ - p_src_base + src_length <= p_dst_base) { /* source ends before dest starts */ + if (p_src_base >= p_dst_base + dst_length || /* source starts after dest ends */ + p_src_base + src_length <= p_dst_base) { /* source ends before dest starts */ no_overlap = 1; } @@ -1769,14 +1752,16 @@ DUK_ASSERT(p_src_copy != NULL); duk_memcpy_unsafe((void *) p_src_copy, (const void *) p_src_base, (size_t) src_length); - p_src_base = p_src_copy; /* use p_src_base from now on */ + p_src_base = p_src_copy; /* use p_src_base from now on */ } /* Value stack intentionally mixed size here. */ DUK_DDD(DUK_DDDPRINT("after overlap check: p_src_base=%p, src_length=%ld, " "p_dst_base=%p, dst_length=%ld, valstack top=%ld", - (void *) p_src_base, (long) src_length, - (void *) p_dst_base, (long) dst_length, + (void *) p_src_base, + (long) src_length, + (void *) p_dst_base, + (long) dst_length, (long) duk_get_top(thr))); /* Ready to make the copy. We must proceed element by element @@ -1796,7 +1781,9 @@ while (p_src != p_src_end) { DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: " "p_src=%p, p_src_end=%p, p_dst=%p", - (void *) p_src, (void *) p_src_end, (void *) p_dst)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst)); /* A validated read() is always a number, so it's write coercion * is always side effect free an won't invalidate pointers etc. */ @@ -1846,10 +1833,10 @@ return 0; - fail_args: +fail_args: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.slice(start, end) @@ -1944,7 +1931,7 @@ /* fall through */ } } - tv = NULL; /* No longer valid nor needed. */ + tv = NULL; /* No longer valid nor needed. */ h_this = duk__require_bufobj_this(thr); @@ -1982,22 +1969,21 @@ * be an Uint8Array but inherit from Buffer.prototype. */ res_class_num = DUK_HOBJECT_GET_CLASS_NUMBER((duk_hobject *) h_this); - DUK_ASSERT(res_class_num >= DUK_HOBJECT_CLASS_BUFOBJ_MIN); /* type check guarantees */ + DUK_ASSERT(res_class_num >= DUK_HOBJECT_CLASS_BUFOBJ_MIN); /* type check guarantees */ DUK_ASSERT(res_class_num <= DUK_HOBJECT_CLASS_BUFOBJ_MAX); res_proto_bidx = duk__buffer_proto_from_classnumres_class_num - DUK_HOBJECT_CLASS_BUFOBJ_MIN; if (magic & 0x04) { res_proto_bidx = DUK_BIDX_NODEJS_BUFFER_PROTOTYPE; } - h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(res_class_num), - res_proto_bidx); + h_bufobj = + duk_push_bufobj_raw(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(res_class_num), + res_proto_bidx); DUK_ASSERT(h_bufobj != NULL); DUK_ASSERT(h_bufobj->length == 0); - h_bufobj->shift = h_this->shift; /* inherit */ - h_bufobj->elem_type = h_this->elem_type; /* inherit */ + h_bufobj->shift = h_this->shift; /* inherit */ + h_bufobj->elem_type = h_this->elem_type; /* inherit */ h_bufobj->is_typedarray = magic & 0x01; DUK_ASSERT(h_bufobj->is_typedarray == 0 || h_bufobj->is_typedarray == 1); @@ -2011,7 +1997,9 @@ duk_uint8_t *p_copy; duk_size_t copy_length; - p_copy = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, (duk_size_t) slice_length); /* must be zeroed, not all bytes always copied */ + p_copy = (duk_uint8_t *) duk_push_fixed_buffer_zero( + thr, + (duk_size_t) slice_length); /* must be zeroed, not all bytes always copied */ DUK_ASSERT(p_copy != NULL); /* Copy slice, respecting underlying buffer limits; remainder @@ -2029,7 +2017,7 @@ h_bufobj->length = slice_length; DUK_ASSERT(h_bufobj->offset == 0); - duk_pop(thr); /* reachable so pop OK */ + duk_pop(thr); /* reachable so pop OK */ } else { h_bufobj->buf = h_val; DUK_HBUFFER_INCREF(thr, h_val); @@ -2042,7 +2030,7 @@ */ DUK_ASSERT(h_bufobj->buf_prop == NULL); - h_bufobj->buf_prop = h_this->buf_prop; /* may be NULL */ + h_bufobj->buf_prop = h_this->buf_prop; /* may be NULL */ DUK_HOBJECT_INCREF_ALLOWNULL(thr, (duk_hobject *) h_bufobj->buf_prop); } /* unbalanced stack on purpose */ @@ -2050,7 +2038,7 @@ DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.isEncoding() @@ -2063,11 +2051,11 @@ /* only accept lowercase 'utf8' now. */ encoding = duk_to_string(thr, 0); - DUK_ASSERT(duk_is_string(thr, 0)); /* guaranteed by duk_to_string() */ + DUK_ASSERT(duk_is_string(thr, 0)); /* guaranteed by duk_to_string() */ duk_push_boolean(thr, DUK_STRCMP(encoding, "utf8") == 0); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.isBuffer() @@ -2079,7 +2067,7 @@ duk_hobject *h_proto; duk_bool_t ret = 0; - DUK_ASSERT(duk_get_top(thr) >= 1); /* nargs */ + DUK_ASSERT(duk_get_top(thr) >= 1); /* nargs */ h = duk_get_hobject(thr, 0); if (h != NULL) { h_proto = thr->builtinsDUK_BIDX_NODEJS_BUFFER_PROTOTYPE; @@ -2094,7 +2082,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.byteLength() @@ -2125,7 +2113,7 @@ duk_push_size_t(thr, len); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.concat() @@ -2156,13 +2144,13 @@ /* Neutered checks not necessary here: neutered buffers have * zero 'length' so we'll effectively skip them. */ - DUK_ASSERT_TOP(thr, 2); /* array totalLength */ - duk_get_prop_index(thr, 0, (duk_uarridx_t) i); /* -> array totalLength buf */ + DUK_ASSERT_TOP(thr, 2); /* array totalLength */ + duk_get_prop_index(thr, 0, (duk_uarridx_t) i); /* -> array totalLength buf */ h_bufobj = duk__require_bufobj_value(thr, 2); DUK_ASSERT(h_bufobj != NULL); total_length += h_bufobj->length; if (DUK_UNLIKELY(total_length < h_bufobj->length)) { - DUK_DCERROR_RANGE_INVALID_ARGS(thr); /* Wrapped. */ + DUK_DCERROR_RANGE_INVALID_ARGS(thr); /* Wrapped. */ } duk_pop(thr); } @@ -2188,18 +2176,18 @@ } h_bufres = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_UINT8ARRAY), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_UINT8ARRAY), DUK_BIDX_NODEJS_BUFFER_PROTOTYPE); DUK_ASSERT(h_bufres != NULL); - p = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, total_length); /* must be zeroed, all bytes not necessarily written over */ + p = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, + total_length); /* must be zeroed, all bytes not necessarily written over */ DUK_ASSERT(p != NULL); space_left = (duk_size_t) total_length; for (i = 0; i < n; i++) { - DUK_ASSERT_TOP(thr, 4); /* array totalLength bufres buf */ + DUK_ASSERT_TOP(thr, 4); /* array totalLength bufres buf */ duk_get_prop_index(thr, 0, (duk_uarridx_t) i); h_bufobj = duk__require_bufobj_value(thr, 4); @@ -2210,11 +2198,8 @@ copy_size = space_left; } - if (h_bufobj->buf != NULL && - DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { - duk_memcpy_unsafe((void *) p, - (const void *) DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj), - copy_size); + if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { + duk_memcpy_unsafe((void *) p, (const void *) DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj), copy_size); } else { /* Just skip, leaving zeroes in the result. */ ; @@ -2231,11 +2216,11 @@ h_bufres->is_typedarray = 1; DUK_HBUFOBJ_ASSERT_VALID(h_bufres); - duk_pop(thr); /* pop plain buffer, now reachable through h_bufres */ + duk_pop(thr); /* pop plain buffer, now reachable through h_bufres */ - return 1; /* return h_bufres */ + return 1; /* return h_bufres */ } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Shared readfield and writefield methods @@ -2251,15 +2236,15 @@ * 4: signed: 1=yes, 0=no * 5: typedarray: 1=yes, 0=no */ -#define DUK__FLD_8BIT 0 -#define DUK__FLD_16BIT 1 -#define DUK__FLD_32BIT 2 -#define DUK__FLD_FLOAT 3 -#define DUK__FLD_DOUBLE 4 -#define DUK__FLD_VARINT 5 -#define DUK__FLD_BIGENDIAN (1 << 3) -#define DUK__FLD_SIGNED (1 << 4) -#define DUK__FLD_TYPEDARRAY (1 << 5) +#define DUK__FLD_8BIT 0 +#define DUK__FLD_16BIT 1 +#define DUK__FLD_32BIT 2 +#define DUK__FLD_FLOAT 3 +#define DUK__FLD_DOUBLE 4 +#define DUK__FLD_VARINT 5 +#define DUK__FLD_BIGENDIAN (1 << 3) +#define DUK__FLD_SIGNED (1 << 4) +#define DUK__FLD_TYPEDARRAY (1 << 5) /* XXX: split into separate functions for each field type? */ DUK_INTERNAL duk_ret_t duk_bi_buffer_readfield(duk_hthread *thr) { @@ -2283,7 +2268,7 @@ magic_signed = magic & 0x0010U; magic_typedarray = magic & 0x0020U; - h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ + h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ DUK_ASSERT(h_this != NULL); buffer_length = h_this->length; @@ -2295,9 +2280,9 @@ if (magic_typedarray) { no_assert = 0; #if defined(DUK_USE_INTEGER_LE) - endswap = !duk_to_boolean(thr, 1); /* 1=little endian */ + endswap = !duk_to_boolean(thr, 1); /* 1=little endian */ #else - endswap = duk_to_boolean(thr, 1); /* 1=little endian */ + endswap = duk_to_boolean(thr, 1); /* 1=little endian */ #endif } else { no_assert = duk_to_boolean(thr, (magic_ftype == DUK__FLD_VARINT) ? 2 : 1); @@ -2321,17 +2306,21 @@ DUK_DDD(DUK_DDDPRINT("readfield, buffer_length=%ld, offset=%ld, no_assert=%d, " "magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, " "endswap=%u", - (long) buffer_length, (long) offset, (int) no_assert, - (unsigned int) magic, (int) magic_ftype, (int) (magic_bigendian >> 3), - (int) (magic_signed >> 4), (int) endswap)); + (long) buffer_length, + (long) offset, + (int) no_assert, + (unsigned int) magic, + (int) magic_ftype, + (int) (magic_bigendian >> 3), + (int) (magic_signed >> 4), + (int) endswap)); /* Update 'buffer_length' to be the effective, safe limit which * takes into account the underlying buffer. This value will be * potentially invalidated by any side effect. */ check_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, buffer_length); - DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", - (long) buffer_length, (long) check_length)); + DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", (long) buffer_length, (long) check_length)); if (h_this->buf) { buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); @@ -2433,7 +2422,7 @@ #endif const duk_uint8_t *p; - field_bytelen = duk_get_int(thr, 1); /* avoid side effects! */ + field_bytelen = duk_get_int(thr, 1); /* avoid side effects! */ if (field_bytelen < 1 || field_bytelen > 6) { goto fail_field_length; } @@ -2451,12 +2440,12 @@ /* Gather in big endian */ i = 0; i_step = 1; - i_end = field_bytelen; /* one i_step over */ + i_end = field_bytelen; /* one i_step over */ } else { /* Gather in little endian */ i = field_bytelen - 1; i_step = -1; - i_end = -1; /* one i_step over */ + i_end = -1; /* one i_step over */ } #if defined(DUK_USE_64BIT_OPS) @@ -2498,16 +2487,16 @@ #endif break; } - default: { /* should never happen but default here */ + default: { /* should never happen but default here */ goto fail_bounds; } } return 1; - fail_neutered: - fail_field_length: - fail_bounds: +fail_neutered: +fail_field_length: +fail_bounds: if (no_assert) { /* Node.js return value for noAssert out-of-bounds reads is * usually (but not always) NaN. Return NaN consistently. @@ -2517,7 +2506,7 @@ } DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) /* XXX: split into separate functions for each field type? */ @@ -2544,7 +2533,7 @@ magic_typedarray = magic & 0x0020U; DUK_UNREF(magic_signed); - h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ + h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ DUK_ASSERT(h_this != NULL); buffer_length = h_this->length; @@ -2556,11 +2545,11 @@ if (magic_typedarray) { no_assert = 0; #if defined(DUK_USE_INTEGER_LE) - endswap = !duk_to_boolean(thr, 2); /* 1=little endian */ + endswap = !duk_to_boolean(thr, 2); /* 1=little endian */ #else - endswap = duk_to_boolean(thr, 2); /* 1=little endian */ + endswap = duk_to_boolean(thr, 2); /* 1=little endian */ #endif - duk_swap(thr, 0, 1); /* offset/value order different from Node.js */ + duk_swap(thr, 0, 1); /* offset/value order different from Node.js */ } else { no_assert = duk_to_boolean(thr, (magic_ftype == DUK__FLD_VARINT) ? 3 : 2); #if defined(DUK_USE_INTEGER_LE) @@ -2599,9 +2588,15 @@ DUK_DDD(DUK_DDDPRINT("writefield, value=%!T, buffer_length=%ld, offset=%ld, no_assert=%d, " "magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, " "endswap=%u", - duk_get_tval(thr, 0), (long) buffer_length, (long) offset, (int) no_assert, - (unsigned int) magic, (int) magic_ftype, (int) (magic_bigendian >> 3), - (int) (magic_signed >> 4), (int) endswap)); + duk_get_tval(thr, 0), + (long) buffer_length, + (long) offset, + (int) no_assert, + (unsigned int) magic, + (int) magic_ftype, + (int) (magic_bigendian >> 3), + (int) (magic_signed >> 4), + (int) endswap)); /* Coerce value to a number before computing check_length, so that * the field type specific coercion below can't have side effects @@ -2614,8 +2609,7 @@ * potentially invalidated by any side effect. */ check_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, buffer_length); - DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", - (long) buffer_length, (long) check_length)); + DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", (long) buffer_length, (long) check_length)); if (h_this->buf) { buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); @@ -2718,12 +2712,12 @@ if (magic_bigendian) { /* Write in big endian */ - i = field_bytelen; /* one i_step added at top of loop */ + i = field_bytelen; /* one i_step added at top of loop */ i_step = -1; i_end = 0; } else { /* Write in little endian */ - i = -1; /* one i_step added at top of loop */ + i = -1; /* one i_step added at top of loop */ i_step = 1; i_end = field_bytelen - 1; } @@ -2741,7 +2735,7 @@ i += i_step; DUK_ASSERT(i >= 0 && i < field_bytelen); pi = (duk_uint8_t) (tmp & 0xff); - tmp = tmp >> 8; /* unnecessary shift for last byte */ + tmp = tmp >> 8; /* unnecessary shift for last byte */ } while (i != i_end); #else tmp = duk_to_number(thr, 0); @@ -2751,12 +2745,12 @@ tmp = DUK_FLOOR(tmp); DUK_ASSERT(i >= 0 && i < field_bytelen); pi = (duk_uint8_t) (DUK_FMOD(tmp, 256.0)); - tmp = tmp / 256.0; /* unnecessary div for last byte */ + tmp = tmp / 256.0; /* unnecessary div for last byte */ } while (i != i_end); #endif break; } - default: { /* should never happen but default here */ + default: { /* should never happen but default here */ goto fail_bounds; } } @@ -2773,9 +2767,9 @@ duk_push_uint(thr, offset + (duk_uint_t) nbytes); return 1; - fail_neutered: - fail_field_length: - fail_bounds: +fail_neutered: +fail_field_length: +fail_bounds: if (no_assert) { /* Node.js return value for failed writes is offset + #bytes * that would have been written. @@ -2791,7 +2785,7 @@ } DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Accessors for .buffer, .byteLength, .byteOffset @@ -2802,9 +2796,8 @@ duk_hbufobj *h_res; h_res = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), DUK_BIDX_ARRAYBUFFER_PROTOTYPE); DUK_ASSERT(h_res != NULL); DUK_UNREF(h_res); @@ -2844,13 +2837,13 @@ * matches view0. */ h_arrbuf->offset = 0; - DUK_ASSERT(h_bufobj->offset + h_bufobj->length >= h_bufobj->offset); /* Wrap check on creation. */ + DUK_ASSERT(h_bufobj->offset + h_bufobj->length >= h_bufobj->offset); /* Wrap check on creation. */ h_arrbuf->length = h_bufobj->offset + h_bufobj->length; DUK_ASSERT(h_arrbuf->buf_prop == NULL); DUK_ASSERT(h_bufobj->buf_prop == NULL); h_bufobj->buf_prop = (duk_hobject *) h_arrbuf; - DUK_HBUFOBJ_INCREF(thr, h_arrbuf); /* Now reachable and accounted for. */ + DUK_HBUFOBJ_INCREF(thr, h_arrbuf); /* Now reachable and accounted for. */ } /* Left on stack; pushed for the second time below (OK). */ @@ -2888,7 +2881,7 @@ duk_hbuffer *h_buf; h_buf = (duk_hbuffer *) h_bufobj; - DUK_ASSERT(DUK_HBUFFER_GET_SIZE(h_buf) <= DUK_UINT_MAX); /* Buffer limits. */ + DUK_ASSERT(DUK_HBUFFER_GET_SIZE(h_buf) <= DUK_UINT_MAX); /* Buffer limits. */ duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_buf)); } else { /* If neutered must return 0; length is zeroed during @@ -2898,7 +2891,7 @@ } return 1; } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* No .buffer getter without ArrayBuffer support. */ #if 0 DUK_INTERNAL duk_ret_t duk_bi_typedarray_buffer_getter(duk_hthread *thr) { @@ -2920,4 +2913,4 @@ duk_push_uint(thr, DUK_HBUFFER_GET_SIZE(h_buf)); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_cbor.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_cbor.c
Changed
@@ -194,7 +194,7 @@ p += 8; enc_ctx->ptr = p; } -#else /* DUK_CBOR_DOUBLE_AS_IS */ +#else /* DUK_CBOR_DOUBLE_AS_IS */ DUK_LOCAL void duk__cbor_encode_double_fp(duk_cbor_encode_context *enc_ctx, double d) { duk_double_union u; duk_uint16_t u16; @@ -229,8 +229,7 @@ duk_bool_t use_half_float; use_half_float = - (u.uc0 == 0 && u.uc1 == 0 && u.uc2 == 0 && u.uc3 == 0 && - u.uc4 == 0 && (u.uc5 & 0x03U) == 0); + (u.uc0 == 0 && u.uc1 == 0 && u.uc2 == 0 && u.uc3 == 0 && u.uc4 == 0 && (u.uc5 & 0x03U) == 0); if (use_half_float) { duk_uint32_t t; @@ -382,9 +381,9 @@ /* Most important path is integers. The floor() test will be true * for Inf too (but not NaN). */ - d_floor = DUK_FLOOR(d); /* identity if d is +/- 0.0, NaN, or +/- Infinity */ + d_floor = DUK_FLOOR(d); /* identity if d is +/- 0.0, NaN, or +/- Infinity */ if (DUK_LIKELY(duk_double_equals(d_floor, d) != 0)) { - DUK_ASSERT(!DUK_ISNAN(d)); /* NaN == NaN compares false. */ + DUK_ASSERT(!DUK_ISNAN(d)); /* NaN == NaN compares false. */ if (DUK_SIGNBIT(d)) { if (d >= -4294967296.0) { d = -1.0 - d; @@ -423,7 +422,7 @@ DUK_ASSERT(DUK_FPCLASSIFY(d) != DUK_FP_ZERO); duk__cbor_encode_double_fp(enc_ctx, d); } -#endif /* DUK_CBOR_DOUBLE_AS_IS */ +#endif /* DUK_CBOR_DOUBLE_AS_IS */ DUK_LOCAL void duk__cbor_encode_string_top(duk_cbor_encode_context *enc_ctx) { const duk_uint8_t *str; @@ -474,7 +473,8 @@ #elif defined(DUK_CBOR_BYTE_STRINGS) duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, 0x40U); #else - duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, + duk__cbor_encode_uint32(enc_ctx, + (duk_uint32_t) len, (DUK_LIKELY(duk_unicode_is_utf8_compatible(str, len) != 0) ? 0x60U : 0x40U)); #endif duk__cbor_encode_ensure(enc_ctx, len); @@ -534,14 +534,14 @@ * indefinite length. This works well up to 23 * properties which is practical and good enough. */ - off_ib = (duk_size_t) (enc_ctx->ptr - enc_ctx->buf); /* XXX: get_offset? */ + off_ib = (duk_size_t) (enc_ctx->ptr - enc_ctx->buf); /* XXX: get_offset? */ count = 0U; p = enc_ctx->ptr; - *p++ = 0xa0U + 0x1fU; /* indefinite length */ + *p++ = 0xa0U + 0x1fU; /* indefinite length */ enc_ctx->ptr = p; duk_enum(enc_ctx->thr, -1, DUK_ENUM_OWN_PROPERTIES_ONLY); while (duk_next(enc_ctx->thr, -1, 1 /*get_value*/)) { - duk_insert(enc_ctx->thr, -2); /* ... key value -> ... value key */ + duk_insert(enc_ctx->thr, -2); /* ... key value -> ... value key */ duk__cbor_encode_value(enc_ctx); duk__cbor_encode_value(enc_ctx); count++; @@ -556,7 +556,7 @@ } else { duk__cbor_encode_ensure(enc_ctx, 1); p = enc_ctx->ptr; - *p++ = 0xffU; /* break */ + *p++ = 0xffU; /* break */ enc_ctx->ptr = p; } } @@ -684,7 +684,7 @@ duk_pop(enc_ctx->thr); return; - fail: +fail: duk__cbor_encode_error(enc_ctx); } @@ -761,7 +761,7 @@ } DUK_LOCAL void duk__cbor_decode_rewind(duk_cbor_decode_context *dec_ctx, duk_size_t len) { - DUK_ASSERT(len <= dec_ctx->off); /* Caller must ensure. */ + DUK_ASSERT(len <= dec_ctx->off); /* Caller must ensure. */ dec_ctx->off -= len; } @@ -781,7 +781,7 @@ return res; } - duk__cbor_decode_error(dec_ctx); /* Not enough input. */ + duk__cbor_decode_error(dec_ctx); /* Not enough input. */ return NULL; } @@ -813,16 +813,16 @@ } switch (ai) { - case 0x18U: /* 1 byte */ + case 0x18U: /* 1 byte */ t = (duk_uint32_t) duk__cbor_decode_readbyte(dec_ctx); goto shared_exit; - case 0x19U: /* 2 byte */ + case 0x19U: /* 2 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u16(dec_ctx); goto shared_exit; - case 0x1aU: /* 4 byte */ + case 0x1aU: /* 4 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); goto shared_exit; - case 0x1bU: /* 8 byte */ + case 0x1bU: /* 8 byte */ /* For uint64 it's important to handle the -1.0 part before * casting to double: otherwise the adjustment might be lost * in the cast. Uses: -1.0 - d <=> -(d + 1.0). @@ -879,7 +879,7 @@ * * No fastint check for this path at present. */ - d1 = (duk_double_t) t1; /* XXX: cast helpers */ + d1 = (duk_double_t) t1; /* XXX: cast helpers */ d2 = (duk_double_t) t2 * 4294967296.0; if (negative) { d1 += 1.0; @@ -897,10 +897,10 @@ duk__cbor_decode_error(dec_ctx); return; - shared_exit: +shared_exit: if (negative) { /* XXX: a push and check for fastint API would be nice */ - if ((duk_uint_t) t <= (duk_uint_t) -(DUK_INT_MIN + 1)) { + if ((duk_uint_t) t <= (duk_uint_t) - (DUK_INT_MIN + 1)) { duk_push_int(dec_ctx->thr, -1 - ((duk_int_t) t)); } else { duk_push_number(dec_ctx->thr, -1.0 - (duk_double_t) t); @@ -911,10 +911,8 @@ } DUK_LOCAL void duk__cbor_decode_skip_aival_int(duk_cbor_decode_context *dec_ctx, duk_uint8_t ib) { - const duk_int8_t skips32 = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, -1, -1, -1, -1 - }; + const duk_int8_t skips32 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, -1, -1, -1, -1 }; duk_uint8_t ai; duk_int8_t skip; @@ -937,16 +935,16 @@ } switch (ai) { - case 0x18U: /* 1 byte */ + case 0x18U: /* 1 byte */ t = (duk_uint32_t) duk__cbor_decode_readbyte(dec_ctx); return t; - case 0x19U: /* 2 byte */ + case 0x19U: /* 2 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u16(dec_ctx); return t; - case 0x1aU: /* 4 byte */ + case 0x1aU: /* 4 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); return t; - case 0x1bU: /* 8 byte */ + case 0x1bU: /* 8 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); if (t != 0U) { break; @@ -980,7 +978,7 @@ DUK_LOCAL void duk__cbor_decode_join_buffers(duk_cbor_decode_context *dec_ctx, duk_idx_t count) { duk_size_t total_size = 0; duk_idx_t top = duk_get_top(dec_ctx->thr); - duk_idx_t base = top - count; /* count is >= 1 */ + duk_idx_t base = top - count; /* count is >= 1 */ duk_idx_t idx; duk_uint8_t *p = NULL; @@ -1001,7 +999,7 @@ p += buf_size; } else { total_size += buf_size; - if (DUK_UNLIKELY(total_size < buf_size)) { /* Wrap check. */ + if (DUK_UNLIKELY(total_size < buf_size)) { /* Wrap check. */ duk__cbor_decode_error(dec_ctx); } } @@ -1028,7 +1026,7 @@ duk_require_stack(dec_ctx->thr, 1); duk__cbor_decode_buffer(dec_ctx, expected_base); count++; - if (DUK_UNLIKELY(count <= 0)) { /* Wrap check. */ + if (DUK_UNLIKELY(count <= 0)) { /* Wrap check. */ duk__cbor_decode_error(dec_ctx); } } @@ -1076,10 +1074,10 @@ */ u.uc7 = 0x3fU; u.uc6 = 0x10U + (duk_uint8_t) ((u16 >> 6) & 0x0fU); - u.uc5 = (duk_uint8_t) ((u16 << 2) & 0xffU); /* Mask is really 0xfcU */ + u.uc5 = (duk_uint8_t) ((u16 << 2) & 0xffU); /* Mask is really 0xfcU */ duk_dblunion_little_to_host(&u); - res = u.d - 0.00006103515625; /* 2^(-14) */ + res = u.d - 0.00006103515625; /* 2^(-14) */ if (u16 & 0x8000U) { res = -res; } @@ -1178,7 +1176,7 @@ /* XXX: use bare array? */ duk_push_array(dec_ctx->thr); - for (idx = 0U; ;) { + for (idx = 0U;;) { if (len == 0xffffffffUL && duk__cbor_decode_checkbreak(dec_ctx)) { break; } @@ -1192,7 +1190,7 @@ duk_put_prop_index(dec_ctx->thr, -2, (duk_uarridx_t) idx); idx++; if (idx == 0U) { - goto failure; /* wrapped */ + goto failure; /* wrapped */ } } @@ -1202,7 +1200,7 @@ duk__cbor_decode_objarr_exit(dec_ctx); return 1; - failure: +failure: /* No need to unwind recursion checks, caller will throw. */ return 0; } @@ -1254,7 +1252,7 @@ duk__cbor_decode_objarr_exit(dec_ctx); return 1; - failure: +failure: /* No need to unwind recursion checks, caller will throw. */ return 0; } @@ -1278,7 +1276,7 @@ } #if defined(DUK_CBOR_DECODE_FASTPATH) -#define DUK__CBOR_AI (ib & 0x1fU) +#define DUK__CBOR_AI (ib & 0x1fU) DUK_LOCAL void duk__cbor_decode_value(duk_cbor_decode_context *dec_ctx) { duk_uint8_t ib; @@ -1288,7 +1286,7 @@ * here for simple paths like primitive values. */ - reread_initial_byte: +reread_initial_byte: DUK_DDD(DUK_DDDPRINT("cbor decode off=%ld len=%ld", (long) dec_ctx->off, (long) dec_ctx->len)); ib = duk__cbor_decode_readbyte(dec_ctx); @@ -1297,107 +1295,292 @@ /* XXX: Force full switch with no range check. */ switch (ib) { - case 0x00U: case 0x01U: case 0x02U: case 0x03U: case 0x04U: case 0x05U: case 0x06U: case 0x07U: - case 0x08U: case 0x09U: case 0x0aU: case 0x0bU: case 0x0cU: case 0x0dU: case 0x0eU: case 0x0fU: - case 0x10U: case 0x11U: case 0x12U: case 0x13U: case 0x14U: case 0x15U: case 0x16U: case 0x17U: + case 0x00U: + case 0x01U: + case 0x02U: + case 0x03U: + case 0x04U: + case 0x05U: + case 0x06U: + case 0x07U: + case 0x08U: + case 0x09U: + case 0x0aU: + case 0x0bU: + case 0x0cU: + case 0x0dU: + case 0x0eU: + case 0x0fU: + case 0x10U: + case 0x11U: + case 0x12U: + case 0x13U: + case 0x14U: + case 0x15U: + case 0x16U: + case 0x17U: duk_push_uint(dec_ctx->thr, ib); break; - case 0x18U: case 0x19U: case 0x1aU: case 0x1bU: + case 0x18U: + case 0x19U: + case 0x1aU: + case 0x1bU: duk__cbor_decode_push_aival_int(dec_ctx, ib, 0 /*negative*/); break; - case 0x1cU: case 0x1dU: case 0x1eU: case 0x1fU: + case 0x1cU: + case 0x1dU: + case 0x1eU: + case 0x1fU: goto format_error; - case 0x20U: case 0x21U: case 0x22U: case 0x23U: case 0x24U: case 0x25U: case 0x26U: case 0x27U: - case 0x28U: case 0x29U: case 0x2aU: case 0x2bU: case 0x2cU: case 0x2dU: case 0x2eU: case 0x2fU: - case 0x30U: case 0x31U: case 0x32U: case 0x33U: case 0x34U: case 0x35U: case 0x36U: case 0x37U: + case 0x20U: + case 0x21U: + case 0x22U: + case 0x23U: + case 0x24U: + case 0x25U: + case 0x26U: + case 0x27U: + case 0x28U: + case 0x29U: + case 0x2aU: + case 0x2bU: + case 0x2cU: + case 0x2dU: + case 0x2eU: + case 0x2fU: + case 0x30U: + case 0x31U: + case 0x32U: + case 0x33U: + case 0x34U: + case 0x35U: + case 0x36U: + case 0x37U: duk_push_int(dec_ctx->thr, -((duk_int_t) ((ib - 0x20U) + 1U))); break; - case 0x38U: case 0x39U: case 0x3aU: case 0x3bU: + case 0x38U: + case 0x39U: + case 0x3aU: + case 0x3bU: duk__cbor_decode_push_aival_int(dec_ctx, ib, 1 /*negative*/); break; - case 0x3cU: case 0x3dU: case 0x3eU: case 0x3fU: + case 0x3cU: + case 0x3dU: + case 0x3eU: + case 0x3fU: goto format_error; - case 0x40U: case 0x41U: case 0x42U: case 0x43U: case 0x44U: case 0x45U: case 0x46U: case 0x47U: - case 0x48U: case 0x49U: case 0x4aU: case 0x4bU: case 0x4cU: case 0x4dU: case 0x4eU: case 0x4fU: - case 0x50U: case 0x51U: case 0x52U: case 0x53U: case 0x54U: case 0x55U: case 0x56U: case 0x57U: + case 0x40U: + case 0x41U: + case 0x42U: + case 0x43U: + case 0x44U: + case 0x45U: + case 0x46U: + case 0x47U: + case 0x48U: + case 0x49U: + case 0x4aU: + case 0x4bU: + case 0x4cU: + case 0x4dU: + case 0x4eU: + case 0x4fU: + case 0x50U: + case 0x51U: + case 0x52U: + case 0x53U: + case 0x54U: + case 0x55U: + case 0x56U: + case 0x57U: /* XXX: Avoid rewind, we know the length already. */ DUK_ASSERT(dec_ctx->off > 0U); dec_ctx->off--; duk__cbor_decode_buffer(dec_ctx, 0x40U); break; - case 0x58U: case 0x59U: case 0x5aU: case 0x5bU: + case 0x58U: + case 0x59U: + case 0x5aU: + case 0x5bU: /* XXX: Avoid rewind, decode length inline. */ DUK_ASSERT(dec_ctx->off > 0U); dec_ctx->off--; duk__cbor_decode_buffer(dec_ctx, 0x40U); break; - case 0x5cU: case 0x5dU: case 0x5eU: + case 0x5cU: + case 0x5dU: + case 0x5eU: goto format_error; case 0x5fU: duk__cbor_decode_and_join_strbuf(dec_ctx, 0x40U); break; - case 0x60U: case 0x61U: case 0x62U: case 0x63U: case 0x64U: case 0x65U: case 0x66U: case 0x67U: - case 0x68U: case 0x69U: case 0x6aU: case 0x6bU: case 0x6cU: case 0x6dU: case 0x6eU: case 0x6fU: - case 0x70U: case 0x71U: case 0x72U: case 0x73U: case 0x74U: case 0x75U: case 0x76U: case 0x77U: + case 0x60U: + case 0x61U: + case 0x62U: + case 0x63U: + case 0x64U: + case 0x65U: + case 0x66U: + case 0x67U: + case 0x68U: + case 0x69U: + case 0x6aU: + case 0x6bU: + case 0x6cU: + case 0x6dU: + case 0x6eU: + case 0x6fU: + case 0x70U: + case 0x71U: + case 0x72U: + case 0x73U: + case 0x74U: + case 0x75U: + case 0x76U: + case 0x77U: /* XXX: Avoid double decode of length. */ duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x78U: case 0x79U: case 0x7aU: case 0x7bU: + case 0x78U: + case 0x79U: + case 0x7aU: + case 0x7bU: /* XXX: Avoid double decode of length. */ duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x7cU: case 0x7dU: case 0x7eU: + case 0x7cU: + case 0x7dU: + case 0x7eU: goto format_error; case 0x7fU: duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x80U: case 0x81U: case 0x82U: case 0x83U: case 0x84U: case 0x85U: case 0x86U: case 0x87U: - case 0x88U: case 0x89U: case 0x8aU: case 0x8bU: case 0x8cU: case 0x8dU: case 0x8eU: case 0x8fU: - case 0x90U: case 0x91U: case 0x92U: case 0x93U: case 0x94U: case 0x95U: case 0x96U: case 0x97U: + case 0x80U: + case 0x81U: + case 0x82U: + case 0x83U: + case 0x84U: + case 0x85U: + case 0x86U: + case 0x87U: + case 0x88U: + case 0x89U: + case 0x8aU: + case 0x8bU: + case 0x8cU: + case 0x8dU: + case 0x8eU: + case 0x8fU: + case 0x90U: + case 0x91U: + case 0x92U: + case 0x93U: + case 0x94U: + case 0x95U: + case 0x96U: + case 0x97U: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0x98U: case 0x99U: case 0x9aU: case 0x9bU: + case 0x98U: + case 0x99U: + case 0x9aU: + case 0x9bU: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0x9cU: case 0x9dU: case 0x9eU: + case 0x9cU: + case 0x9dU: + case 0x9eU: goto format_error; case 0x9fU: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xa0U: case 0xa1U: case 0xa2U: case 0xa3U: case 0xa4U: case 0xa5U: case 0xa6U: case 0xa7U: - case 0xa8U: case 0xa9U: case 0xaaU: case 0xabU: case 0xacU: case 0xadU: case 0xaeU: case 0xafU: - case 0xb0U: case 0xb1U: case 0xb2U: case 0xb3U: case 0xb4U: case 0xb5U: case 0xb6U: case 0xb7U: + case 0xa0U: + case 0xa1U: + case 0xa2U: + case 0xa3U: + case 0xa4U: + case 0xa5U: + case 0xa6U: + case 0xa7U: + case 0xa8U: + case 0xa9U: + case 0xaaU: + case 0xabU: + case 0xacU: + case 0xadU: + case 0xaeU: + case 0xafU: + case 0xb0U: + case 0xb1U: + case 0xb2U: + case 0xb3U: + case 0xb4U: + case 0xb5U: + case 0xb6U: + case 0xb7U: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xb8U: case 0xb9U: case 0xbaU: case 0xbbU: + case 0xb8U: + case 0xb9U: + case 0xbaU: + case 0xbbU: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xbcU: case 0xbdU: case 0xbeU: + case 0xbcU: + case 0xbdU: + case 0xbeU: goto format_error; case 0xbfU: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xc0U: case 0xc1U: case 0xc2U: case 0xc3U: case 0xc4U: case 0xc5U: case 0xc6U: case 0xc7U: - case 0xc8U: case 0xc9U: case 0xcaU: case 0xcbU: case 0xccU: case 0xcdU: case 0xceU: case 0xcfU: - case 0xd0U: case 0xd1U: case 0xd2U: case 0xd3U: case 0xd4U: case 0xd5U: case 0xd6U: case 0xd7U: + case 0xc0U: + case 0xc1U: + case 0xc2U: + case 0xc3U: + case 0xc4U: + case 0xc5U: + case 0xc6U: + case 0xc7U: + case 0xc8U: + case 0xc9U: + case 0xcaU: + case 0xcbU: + case 0xccU: + case 0xcdU: + case 0xceU: + case 0xcfU: + case 0xd0U: + case 0xd1U: + case 0xd2U: + case 0xd3U: + case 0xd4U: + case 0xd5U: + case 0xd6U: + case 0xd7U: /* Tag 0-23: drop. */ goto reread_initial_byte; - case 0xd8U: case 0xd9U: case 0xdaU: case 0xdbU: + case 0xd8U: + case 0xd9U: + case 0xdaU: + case 0xdbU: duk__cbor_decode_skip_aival_int(dec_ctx, ib); goto reread_initial_byte; - case 0xdcU: case 0xddU: case 0xdeU: case 0xdfU: + case 0xdcU: + case 0xddU: + case 0xdeU: + case 0xdfU: goto format_error; case 0xe0U: goto format_error; @@ -1477,14 +1660,14 @@ case 0xfeU: case 0xffU: goto format_error; - } /* end switch */ + } /* end switch */ return; - format_error: +format_error: duk__cbor_decode_error(dec_ctx); } -#else /* DUK_CBOR_DECODE_FASTPATH */ +#else /* DUK_CBOR_DECODE_FASTPATH */ DUK_LOCAL void duk__cbor_decode_value(duk_cbor_decode_context *dec_ctx) { duk_uint8_t ib, mt, ai; @@ -1493,7 +1676,7 @@ * here for simple paths like primitive values. */ - reread_initial_byte: +reread_initial_byte: DUK_DDD(DUK_DDDPRINT("cbor decode off=%ld len=%ld", (long) dec_ctx->off, (long) dec_ctx->len)); ib = duk__cbor_decode_readbyte(dec_ctx); @@ -1509,15 +1692,15 @@ */ switch (mt) { - case 0U: { /* unsigned integer */ + case 0U: { /* unsigned integer */ duk__cbor_decode_push_aival_int(dec_ctx, ib, 0 /*negative*/); break; } - case 1U: { /* negative integer */ + case 1U: { /* negative integer */ duk__cbor_decode_push_aival_int(dec_ctx, ib, 1 /*negative*/); break; } - case 2U: { /* byte string */ + case 2U: { /* byte string */ if (ai == 0x1fU) { duk__cbor_decode_and_join_strbuf(dec_ctx, 0x40U); } else { @@ -1526,23 +1709,23 @@ } break; } - case 3U: { /* text string */ + case 3U: { /* text string */ duk__cbor_decode_string(dec_ctx, ib, ai); break; } - case 4U: { /* array of data items */ + case 4U: { /* array of data items */ if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, ai) == 0)) { goto format_error; } break; } - case 5U: { /* map of pairs of data items */ + case 5U: { /* map of pairs of data items */ if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, ai) == 0)) { goto format_error; } break; } - case 6U: { /* semantic tagging */ + case 6U: { /* semantic tagging */ /* Tags are ignored now, re-read initial byte. A tagged * value may itself be tagged (an unlimited number of times) * so keep on peeling away tags. @@ -1550,7 +1733,7 @@ duk__cbor_decode_skip_aival_int(dec_ctx, ib); goto reread_initial_byte; } - case 7U: { /* floating point numbers, simple data types, break; other */ + case 7U: { /* floating point numbers, simple data types, break; other */ switch (ai) { case 0x14U: { duk_push_false(dec_ctx->thr); @@ -1568,7 +1751,7 @@ duk_push_undefined(dec_ctx->thr); break; } - case 0x18U: { /* more simple values (1 byte) */ + case 0x18U: { /* more simple values (1 byte) */ /* Simple value encoded in additional byte (none * are defined so far). RFC 7049 states that the * follow-up byte must be 32-255 to minimize @@ -1579,42 +1762,42 @@ */ goto format_error; } - case 0x19U: { /* half-float (2 bytes) */ + case 0x19U: { /* half-float (2 bytes) */ duk_double_t d; d = duk__cbor_decode_half_float(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0x1aU: { /* float (4 bytes) */ + case 0x1aU: { /* float (4 bytes) */ duk_double_t d; d = duk__cbor_decode_float(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0x1bU: { /* double (8 bytes) */ + case 0x1bU: { /* double (8 bytes) */ duk_double_t d; d = duk__cbor_decode_double(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0xffU: /* unexpected break */ + case 0xffU: /* unexpected break */ default: { goto format_error; } - } /* end switch */ + } /* end switch */ break; } default: { - goto format_error; /* will never actually occur */ + goto format_error; /* will never actually occur */ } - } /* end switch */ + } /* end switch */ return; - format_error: +format_error: duk__cbor_decode_error(dec_ctx); } -#endif /* DUK_CBOR_DECODE_FASTPATH */ +#endif /* DUK_CBOR_DECODE_FASTPATH */ DUK_LOCAL void duk__cbor_encode(duk_hthread *thr, duk_idx_t idx, duk_uint_t encode_flags) { duk_cbor_encode_context enc_ctx; @@ -1674,7 +1857,7 @@ duk_replace(thr, idx); } -#else /* DUK_USE_CBOR_SUPPORT */ +#else /* DUK_USE_CBOR_SUPPORT */ DUK_LOCAL void duk__cbor_encode(duk_hthread *thr, duk_idx_t idx, duk_uint_t encode_flags) { DUK_UNREF(idx); @@ -1688,7 +1871,7 @@ DUK_ERROR_UNSUPPORTED(thr); } -#endif /* DUK_USE_CBOR_SUPPORT */ +#endif /* DUK_USE_CBOR_SUPPORT */ /* * Public APIs @@ -1724,7 +1907,7 @@ duk__cbor_decode(thr, -1, 0 /*flags*/); return 1; } -#else /* DUK_USE_CBOR_SUPPORT */ +#else /* DUK_USE_CBOR_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_cbor_encode(duk_hthread *thr) { DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); @@ -1733,5 +1916,5 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_CBOR_SUPPORT */ -#endif /* DUK_USE_CBOR_BUILTIN */ +#endif /* DUK_USE_CBOR_SUPPORT */ +#endif /* DUK_USE_CBOR_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_date.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_date.c
Changed
@@ -29,30 +29,49 @@ */ /* Debug macro to print all parts and dparts (used manually because of debug level). */ -#define DUK__DPRINT_PARTS_AND_DPARTS(parts,dparts) do { \ +#define DUK__DPRINT_PARTS_AND_DPARTS(parts, dparts) \ + do { \ DUK_D(DUK_DPRINT("parts: %ld %ld %ld %ld %ld %ld %ld %ld, dparts: %lf %lf %lf %lf %lf %lf %lf %lf", \ - (long) (parts)0, (long) (parts)1, \ - (long) (parts)2, (long) (parts)3, \ - (long) (parts)4, (long) (parts)5, \ - (long) (parts)6, (long) (parts)7, \ - (double) (dparts)0, (double) (dparts)1, \ - (double) (dparts)2, (double) (dparts)3, \ - (double) (dparts)4, (double) (dparts)5, \ - (double) (dparts)6, (double) (dparts)7)); \ + (long) (parts)0, \ + (long) (parts)1, \ + (long) (parts)2, \ + (long) (parts)3, \ + (long) (parts)4, \ + (long) (parts)5, \ + (long) (parts)6, \ + (long) (parts)7, \ + (double) (dparts)0, \ + (double) (dparts)1, \ + (double) (dparts)2, \ + (double) (dparts)3, \ + (double) (dparts)4, \ + (double) (dparts)5, \ + (double) (dparts)6, \ + (double) (dparts)7)); \ } while (0) -#define DUK__DPRINT_PARTS(parts) do { \ +#define DUK__DPRINT_PARTS(parts) \ + do { \ DUK_D(DUK_DPRINT("parts: %ld %ld %ld %ld %ld %ld %ld %ld", \ - (long) (parts)0, (long) (parts)1, \ - (long) (parts)2, (long) (parts)3, \ - (long) (parts)4, (long) (parts)5, \ - (long) (parts)6, (long) (parts)7)); \ + (long) (parts)0, \ + (long) (parts)1, \ + (long) (parts)2, \ + (long) (parts)3, \ + (long) (parts)4, \ + (long) (parts)5, \ + (long) (parts)6, \ + (long) (parts)7)); \ } while (0) -#define DUK__DPRINT_DPARTS(dparts) do { \ +#define DUK__DPRINT_DPARTS(dparts) \ + do { \ DUK_D(DUK_DPRINT("dparts: %lf %lf %lf %lf %lf %lf %lf %lf", \ - (double) (dparts)0, (double) (dparts)1, \ - (double) (dparts)2, (double) (dparts)3, \ - (double) (dparts)4, (double) (dparts)5, \ - (double) (dparts)6, (double) (dparts)7)); \ + (double) (dparts)0, \ + (double) (dparts)1, \ + (double) (dparts)2, \ + (double) (dparts)3, \ + (double) (dparts)4, \ + (double) (dparts)5, \ + (double) (dparts)6, \ + (double) (dparts)7)); \ } while (0) /* Equivalent year for DST calculations outside 1970,2038 range, see @@ -60,7 +79,7 @@ * starts with the same weekday on Jan 1. * https://bugzilla.mozilla.org/show_bug.cgi?id=351066 */ -#define DUK__YEAR(x) ((duk_uint8_t) ((x) - 1970)) +#define DUK__YEAR(x) ((duk_uint8_t) ((x) -1970)) DUK_LOCAL duk_uint8_t duk__date_equivyear14 = { #if 1 /* This is based on V8 EquivalentYear() algorithm (see util/genequivyear.py): @@ -68,12 +87,22 @@ */ /* non-leap year: sunday, monday, ... */ - DUK__YEAR(2023), DUK__YEAR(2035), DUK__YEAR(2019), DUK__YEAR(2031), - DUK__YEAR(2015), DUK__YEAR(2027), DUK__YEAR(2011), + DUK__YEAR(2023), + DUK__YEAR(2035), + DUK__YEAR(2019), + DUK__YEAR(2031), + DUK__YEAR(2015), + DUK__YEAR(2027), + DUK__YEAR(2011), /* leap year: sunday, monday, ... */ - DUK__YEAR(2012), DUK__YEAR(2024), DUK__YEAR(2008), DUK__YEAR(2020), - DUK__YEAR(2032), DUK__YEAR(2016), DUK__YEAR(2028) + DUK__YEAR(2012), + DUK__YEAR(2024), + DUK__YEAR(2008), + DUK__YEAR(2020), + DUK__YEAR(2032), + DUK__YEAR(2016), + DUK__YEAR(2028) #endif #if 0 @@ -96,71 +125,70 @@ */ /* Parser part count. */ -#define DUK__NUM_ISO8601_PARSER_PARTS 9 +#define DUK__NUM_ISO8601_PARSER_PARTS 9 /* Parser part indices. */ -#define DUK__PI_YEAR 0 -#define DUK__PI_MONTH 1 -#define DUK__PI_DAY 2 -#define DUK__PI_HOUR 3 -#define DUK__PI_MINUTE 4 -#define DUK__PI_SECOND 5 -#define DUK__PI_MILLISECOND 6 -#define DUK__PI_TZHOUR 7 -#define DUK__PI_TZMINUTE 8 +#define DUK__PI_YEAR 0 +#define DUK__PI_MONTH 1 +#define DUK__PI_DAY 2 +#define DUK__PI_HOUR 3 +#define DUK__PI_MINUTE 4 +#define DUK__PI_SECOND 5 +#define DUK__PI_MILLISECOND 6 +#define DUK__PI_TZHOUR 7 +#define DUK__PI_TZMINUTE 8 /* Parser part masks. */ -#define DUK__PM_YEAR (1 << DUK__PI_YEAR) -#define DUK__PM_MONTH (1 << DUK__PI_MONTH) -#define DUK__PM_DAY (1 << DUK__PI_DAY) -#define DUK__PM_HOUR (1 << DUK__PI_HOUR) -#define DUK__PM_MINUTE (1 << DUK__PI_MINUTE) -#define DUK__PM_SECOND (1 << DUK__PI_SECOND) -#define DUK__PM_MILLISECOND (1 << DUK__PI_MILLISECOND) -#define DUK__PM_TZHOUR (1 << DUK__PI_TZHOUR) -#define DUK__PM_TZMINUTE (1 << DUK__PI_TZMINUTE) +#define DUK__PM_YEAR (1 << DUK__PI_YEAR) +#define DUK__PM_MONTH (1 << DUK__PI_MONTH) +#define DUK__PM_DAY (1 << DUK__PI_DAY) +#define DUK__PM_HOUR (1 << DUK__PI_HOUR) +#define DUK__PM_MINUTE (1 << DUK__PI_MINUTE) +#define DUK__PM_SECOND (1 << DUK__PI_SECOND) +#define DUK__PM_MILLISECOND (1 << DUK__PI_MILLISECOND) +#define DUK__PM_TZHOUR (1 << DUK__PI_TZHOUR) +#define DUK__PM_TZMINUTE (1 << DUK__PI_TZMINUTE) /* Parser separator indices. */ -#define DUK__SI_PLUS 0 -#define DUK__SI_MINUS 1 -#define DUK__SI_T 2 -#define DUK__SI_SPACE 3 -#define DUK__SI_COLON 4 -#define DUK__SI_PERIOD 5 -#define DUK__SI_Z 6 -#define DUK__SI_NUL 7 +#define DUK__SI_PLUS 0 +#define DUK__SI_MINUS 1 +#define DUK__SI_T 2 +#define DUK__SI_SPACE 3 +#define DUK__SI_COLON 4 +#define DUK__SI_PERIOD 5 +#define DUK__SI_Z 6 +#define DUK__SI_NUL 7 /* Parser separator masks. */ -#define DUK__SM_PLUS (1 << DUK__SI_PLUS) -#define DUK__SM_MINUS (1 << DUK__SI_MINUS) -#define DUK__SM_T (1 << DUK__SI_T) -#define DUK__SM_SPACE (1 << DUK__SI_SPACE) -#define DUK__SM_COLON (1 << DUK__SI_COLON) -#define DUK__SM_PERIOD (1 << DUK__SI_PERIOD) -#define DUK__SM_Z (1 << DUK__SI_Z) -#define DUK__SM_NUL (1 << DUK__SI_NUL) +#define DUK__SM_PLUS (1 << DUK__SI_PLUS) +#define DUK__SM_MINUS (1 << DUK__SI_MINUS) +#define DUK__SM_T (1 << DUK__SI_T) +#define DUK__SM_SPACE (1 << DUK__SI_SPACE) +#define DUK__SM_COLON (1 << DUK__SI_COLON) +#define DUK__SM_PERIOD (1 << DUK__SI_PERIOD) +#define DUK__SM_Z (1 << DUK__SI_Z) +#define DUK__SM_NUL (1 << DUK__SI_NUL) /* Rule control flags. */ -#define DUK__CF_NEG (1 << 0) /* continue matching, set neg_tzoffset flag */ -#define DUK__CF_ACCEPT (1 << 1) /* accept string */ -#define DUK__CF_ACCEPT_NUL (1 << 2) /* accept string if next char is NUL (otherwise reject) */ - -#define DUK__PACK_RULE(partmask,sepmask,nextpart,flags) \ - ((duk_uint32_t) (partmask) + \ - (((duk_uint32_t) (sepmask)) << 9) + \ - (((duk_uint32_t) (nextpart)) << 17) + \ +#define DUK__CF_NEG (1 << 0) /* continue matching, set neg_tzoffset flag */ +#define DUK__CF_ACCEPT (1 << 1) /* accept string */ +#define DUK__CF_ACCEPT_NUL (1 << 2) /* accept string if next char is NUL (otherwise reject) */ + +#define DUK__PACK_RULE(partmask, sepmask, nextpart, flags) \ + ((duk_uint32_t) (partmask) + (((duk_uint32_t) (sepmask)) << 9) + (((duk_uint32_t) (nextpart)) << 17) + \ (((duk_uint32_t) (flags)) << 21)) -#define DUK__UNPACK_RULE(rule,var_nextidx,var_flags) do { \ +#define DUK__UNPACK_RULE(rule, var_nextidx, var_flags) \ + do { \ (var_nextidx) = (duk_small_uint_t) (((rule) >> 17) & 0x0f); \ (var_flags) = (duk_small_uint_t) ((rule) >> 21); \ } while (0) -#define DUK__RULE_MASK_PART_SEP 0x1ffffUL +#define DUK__RULE_MASK_PART_SEP 0x1ffffUL /* Matching separator index is used in the control table */ DUK_LOCAL const duk_uint8_t duk__parse_iso8601_seps = { - DUK_ASC_PLUS /*0*/, DUK_ASC_MINUS /*1*/, DUK_ASC_UC_T /*2*/, DUK_ASC_SPACE /*3*/, + DUK_ASC_PLUS /*0*/, DUK_ASC_MINUS /*1*/, DUK_ASC_UC_T /*2*/, DUK_ASC_SPACE /*3*/, DUK_ASC_COLON /*4*/, DUK_ASC_PERIOD /*5*/, DUK_ASC_UC_Z /*6*/, DUK_ASC_NUL /*7*/ }; @@ -173,10 +201,26 @@ DUK__PACK_RULE(DUK__PM_MINUTE, DUK__SM_COLON, DUK__PI_SECOND, 0), DUK__PACK_RULE(DUK__PM_SECOND, DUK__SM_PERIOD, DUK__PI_MILLISECOND, 0), DUK__PACK_RULE(DUK__PM_TZHOUR, DUK__SM_COLON, DUK__PI_TZMINUTE, 0), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_PLUS, DUK__PI_TZHOUR, 0), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_MINUS, DUK__PI_TZHOUR, DUK__CF_NEG), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_Z, 0, DUK__CF_ACCEPT_NUL), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND | DUK__PM_TZHOUR /*Note2*/ | DUK__PM_TZMINUTE, DUK__SM_NUL, 0, DUK__CF_ACCEPT) + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_PLUS, + DUK__PI_TZHOUR, + 0), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_MINUS, + DUK__PI_TZHOUR, + DUK__CF_NEG), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_Z, + 0, + DUK__CF_ACCEPT_NUL), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND | DUK__PM_TZHOUR /*Note2*/ | DUK__PM_TZMINUTE, + DUK__SM_NUL, + 0, + DUK__CF_ACCEPT) /* Note1: the specification doesn't require matching a time form with * just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z". @@ -201,7 +245,7 @@ /* During parsing, month and day are one-based; set defaults here. */ duk_memzero(parts, sizeof(parts)); - DUK_ASSERT(partsDUK_DATE_IDX_YEAR == 0); /* don't care value, year is mandatory */ + DUK_ASSERT(partsDUK_DATE_IDX_YEAR == 0); /* don't care value, year is mandatory */ partsDUK_DATE_IDX_MONTH = 1; partsDUK_DATE_IDX_DAY = 1; @@ -218,7 +262,8 @@ for (;;) { ch = *p++; DUK_DDD(DUK_DDDPRINT("parsing, part_idx=%ld, char=%ld ('%c')", - (long) part_idx, (long) ch, + (long) part_idx, + (long) ch, (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : DUK_ASC_QUESTION))); if (ch >= DUK_ASC_0 && ch <= DUK_ASC_9) { @@ -263,7 +308,7 @@ } sep_idx = i; - match_val = (1UL << part_idx) + (1UL << (sep_idx + 9)); /* match against rule part/sep bits */ + match_val = (1UL << part_idx) + (1UL << (sep_idx + 9)); /* match against rule part/sep bits */ for (i = 0; i < (duk_small_uint_t) (sizeof(duk__parse_iso8601_control) / sizeof(duk_uint32_t)); i++) { duk_uint_fast32_t rule = duk__parse_iso8601_controli; @@ -271,8 +316,10 @@ duk_small_uint_t cflags; DUK_DDD(DUK_DDDPRINT("part_idx=%ld, sep_idx=%ld, match_val=0x%08lx, considering rule=0x%08lx", - (long) part_idx, (long) sep_idx, - (unsigned long) match_val, (unsigned long) rule)); + (long) part_idx, + (long) sep_idx, + (unsigned long) match_val, + (unsigned long) rule)); if ((rule & match_val) != match_val) { continue; @@ -282,9 +329,12 @@ DUK_DDD(DUK_DDDPRINT("rule match -> part_idx=%ld, sep_idx=%ld, match_val=0x%08lx, " "rule=0x%08lx -> nextpart=%ld, cflags=0x%02lx", - (long) part_idx, (long) sep_idx, - (unsigned long) match_val, (unsigned long) rule, - (long) nextpart, (unsigned long) cflags)); + (long) part_idx, + (long) sep_idx, + (unsigned long) match_val, + (unsigned long) rule, + (long) nextpart, + (unsigned long) cflags)); if (cflags & DUK__CF_NEG) { neg_tzoffset = 1; @@ -304,7 +354,7 @@ part_idx = nextpart; break; - } /* rule match */ + } /* rule match */ if (i == (duk_small_uint_t) (sizeof(duk__parse_iso8601_control) / sizeof(duk_uint32_t))) { DUK_DDD(DUK_DDDPRINT("no rule matches -> reject")); @@ -318,17 +368,17 @@ DUK_DDD(DUK_DDDPRINT("NUL after rule matching (should not happen) -> reject")); goto reject; } - } /* if-digit-else-ctrl */ - } /* char loop */ + } /* if-digit-else-ctrl */ + } /* char loop */ /* We should never exit the loop above. */ DUK_UNREACHABLE(); - reject: +reject: DUK_DDD(DUK_DDDPRINT("reject")); return 0; - accept: +accept: DUK_DDD(DUK_DDDPRINT("accept")); /* Apply timezone offset to get the main parts in UTC */ @@ -342,8 +392,8 @@ partsDUK__PI_HOUR -= partsDUK__PI_TZHOUR; partsDUK__PI_MINUTE -= partsDUK__PI_TZMINUTE; } - partsDUK__PI_MONTH -= 1; /* zero-based month */ - partsDUK__PI_DAY -= 1; /* zero-based day */ + partsDUK__PI_MONTH -= 1; /* zero-based month */ + partsDUK__PI_DAY -= 1; /* zero-based day */ /* Use double parts, they tolerate unnormalized time. * @@ -420,16 +470,14 @@ * out for non-finite numbers etc. */ -DUK_LOCAL duk_uint8_t duk__days_in_month12 = { - (duk_uint8_t) 31, (duk_uint8_t) 28, (duk_uint8_t) 31, (duk_uint8_t) 30, - (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 31, - (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31 -}; +DUK_LOCAL duk_uint8_t duk__days_in_month12 = { (duk_uint8_t) 31, (duk_uint8_t) 28, (duk_uint8_t) 31, (duk_uint8_t) 30, + (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 31, + (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31 }; /* Maximum iteration count for computing UTC-to-local time offset when * creating an ECMAScript time value from local parts. */ -#define DUK__LOCAL_TZOFFSET_MAXITER 4 +#define DUK__LOCAL_TZOFFSET_MAXITER 4 /* Because 'day since epoch' can be negative and is used to compute weekday * using a modulo operation, add this multiple of 7 to avoid negative values @@ -437,7 +485,7 @@ * +/- 100 million days from epoch, so this adder fits nicely into 32 bits. * Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin. */ -#define DUK__WEEKDAY_MOD_ADDER (20000000 * 7) /* 0x08583b00 */ +#define DUK__WEEKDAY_MOD_ADDER (20000000 * 7) /* 0x08583b00 */ DUK_INTERNAL duk_bool_t duk_bi_date_is_leap_year(duk_int_t year) { if ((year % 4) != 0) { @@ -498,10 +546,8 @@ /* Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative * values, but is incorrect for negative ones. */ - return 365 * (year - 1970) - + duk__div_floor(year - 1969, 4) - - duk__div_floor(year - 1901, 100) - + duk__div_floor(year - 1601, 400); + return 365 * (year - 1970) + duk__div_floor(year - 1969, 4) - duk__div_floor(year - 1901, 100) + + duk__div_floor(year - 1601, 400); } /* Given a day number, determine year and day-within-year. */ @@ -523,10 +569,9 @@ diff_days = duk__day_from_year(year) - day; DUK_DDD(DUK_DDDPRINT("year=%ld day=%ld, diff_days=%ld", (long) year, (long) day, (long) diff_days)); if (diff_days <= 0) { - DUK_ASSERT(-diff_days < 366); /* fits into duk_small_int_t */ + DUK_ASSERT(-diff_days < 366); /* fits into duk_small_int_t */ *out_day_within_year = -diff_days; - DUK_DDD(DUK_DDDPRINT("--> year=%ld, day-within-year=%ld", - (long) year, (long) *out_day_within_year)); + DUK_DDD(DUK_DDDPRINT("--> year=%ld, day-within-year=%ld", (long) year, (long) *out_day_within_year)); DUK_ASSERT(*out_day_within_year >= 0); DUK_ASSERT(*out_day_within_year < (duk_bi_date_is_leap_year(year) ? 366 : 365)); return year; @@ -535,7 +580,7 @@ /* Note: this is very tricky; we must never 'overshoot' the * correction downwards. */ - year -= 1 + (diff_days - 1) / 366; /* conservative */ + year -= 1 + (diff_days - 1) / 366; /* conservative */ } } @@ -608,7 +653,7 @@ duk_double_t d1, d2; duk_int_t t1, t2; duk_int_t day_since_epoch; - duk_int_t year; /* does not fit into 16 bits */ + duk_int_t year; /* does not fit into 16 bits */ duk_small_int_t day_in_year; duk_small_int_t month; duk_small_int_t day; @@ -620,8 +665,8 @@ duk_bool_t is_leap; duk_small_int_t arridx; - DUK_ASSERT(DUK_ISFINITE(d)); /* caller checks */ - d = DUK_FLOOR(d); /* remove fractions if present */ + DUK_ASSERT(DUK_ISFINITE(d)); /* caller checks */ + d = DUK_FLOOR(d); /* remove fractions if present */ DUK_ASSERT(duk_double_equals(DUK_FLOOR(d), d)); /* The timevalue must be in valid ECMAScript range, but since a local @@ -653,9 +698,12 @@ * t2 = day number from epoch (fits 32 bit, may be negative) */ - partsDUK_DATE_IDX_MILLISECOND = t1 % 1000; t1 /= 1000; - partsDUK_DATE_IDX_SECOND = t1 % 60; t1 /= 60; - partsDUK_DATE_IDX_MINUTE = t1 % 60; t1 /= 60; + partsDUK_DATE_IDX_MILLISECOND = t1 % 1000; + t1 /= 1000; + partsDUK_DATE_IDX_SECOND = t1 % 60; + t1 /= 60; + partsDUK_DATE_IDX_MINUTE = t1 % 60; + t1 /= 60; partsDUK_DATE_IDX_HOUR = t1; DUK_ASSERT(partsDUK_DATE_IDX_MILLISECOND >= 0 && partsDUK_DATE_IDX_MILLISECOND <= 999); DUK_ASSERT(partsDUK_DATE_IDX_SECOND >= 0 && partsDUK_DATE_IDX_SECOND <= 59); @@ -663,7 +711,11 @@ DUK_ASSERT(partsDUK_DATE_IDX_HOUR >= 0 && partsDUK_DATE_IDX_HOUR <= 23); DUK_DDD(DUK_DDDPRINT("d=%lf, d1=%lf, d2=%lf, t1=%ld, t2=%ld, parts: hour=%ld min=%ld sec=%ld msec=%ld", - (double) d, (double) d1, (double) d2, (long) t1, (long) t2, + (double) d, + (double) d1, + (double) d2, + (long) t1, + (long) t2, (long) partsDUK_DATE_IDX_HOUR, (long) partsDUK_DATE_IDX_MINUTE, (long) partsDUK_DATE_IDX_SECOND, @@ -673,7 +725,7 @@ * the ECMAScript range. */ DUK_ASSERT(t2 + DUK__WEEKDAY_MOD_ADDER >= 0); - partsDUK_DATE_IDX_WEEKDAY = (t2 + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ + partsDUK_DATE_IDX_WEEKDAY = (t2 + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ DUK_ASSERT(partsDUK_DATE_IDX_WEEKDAY >= 0 && partsDUK_DATE_IDX_WEEKDAY <= 6); year = duk__year_from_day(t2, &day_in_year); @@ -684,8 +736,7 @@ if (month == 1 && is_leap) { dim++; } - DUK_DDD(DUK_DDDPRINT("month=%ld, dim=%ld, day=%ld", - (long) month, (long) dim, (long) day)); + DUK_DDD(DUK_DDDPRINT("month=%ld, dim=%ld, day=%ld", (long) month, (long) dim, (long) day)); if (day < dim) { break; } @@ -710,9 +761,9 @@ if ((flags & DUK_DATE_FLAG_EQUIVYEAR) && (year < 1971 || year > 2037)) { DUK_ASSERT(is_leap == 0 || is_leap == 1); - jan1_since_epoch = day_since_epoch - day_in_year; /* day number for Jan 1 since epoch */ + jan1_since_epoch = day_since_epoch - day_in_year; /* day number for Jan 1 since epoch */ DUK_ASSERT(jan1_since_epoch + DUK__WEEKDAY_MOD_ADDER >= 0); - jan1_weekday = (jan1_since_epoch + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ + jan1_weekday = (jan1_since_epoch + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ DUK_ASSERT(jan1_weekday >= 0 && jan1_weekday <= 6); arridx = jan1_weekday; if (is_leap) { @@ -724,8 +775,12 @@ year = equiv_year; DUK_DDD(DUK_DDDPRINT("equiv year mapping, year=%ld, day_in_year=%ld, day_since_epoch=%ld, " "jan1_since_epoch=%ld, jan1_weekday=%ld -> equiv year %ld", - (long) year, (long) day_in_year, (long) day_since_epoch, - (long) jan1_since_epoch, (long) jan1_weekday, (long) equiv_year)); + (long) year, + (long) day_in_year, + (long) day_since_epoch, + (long) jan1_since_epoch, + (long) jan1_weekday, + (long) equiv_year)); } partsDUK_DATE_IDX_YEAR = year; @@ -733,8 +788,8 @@ partsDUK_DATE_IDX_DAY = day; if (flags & DUK_DATE_FLAG_ONEBASED) { - partsDUK_DATE_IDX_MONTH++; /* zero-based -> one-based */ - partsDUK_DATE_IDX_DAY++; /* -""- */ + partsDUK_DATE_IDX_MONTH++; /* zero-based -> one-based */ + partsDUK_DATE_IDX_DAY++; /* -""- */ } if (dparts != NULL) { @@ -814,8 +869,7 @@ /* MakeDate */ d = tmp_day * ((duk_double_t) DUK_DATE_MSEC_DAY) + tmp_time; - DUK_DDD(DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf", - (double) tmp_time, (double) tmp_day, (double) d)); + DUK_DDD(DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf", (double) tmp_time, (double) tmp_day, (double) d)); /* Optional UTC conversion. */ if (flags & DUK_DATE_FLAG_LOCALTIME) { @@ -845,16 +899,22 @@ /* Iteration solution */ tzoff = 0; - tzoffprev1 = 999999999L; /* invalid value which never matches */ + tzoffprev1 = 999999999L; /* invalid value which never matches */ for (i = 0; i < DUK__LOCAL_TZOFFSET_MAXITER; i++) { tzoffprev2 = tzoffprev1; tzoffprev1 = tzoff; tzoff = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d - tzoff * 1000L); DUK_DDD(DUK_DDDPRINT("tzoffset iteration, i=%d, tzoff=%ld, tzoffprev1=%ld tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); if (tzoff == tzoffprev1) { DUK_DDD(DUK_DDDPRINT("tzoffset iteration finished, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); break; } else if (tzoff == tzoffprev2) { /* Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js. @@ -862,8 +922,12 @@ * result which is independent of iteration count. Not sure if * this is a generically correct solution. */ - DUK_DDD(DUK_DDDPRINT("tzoffset iteration two-value cycle, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + DUK_DDD(DUK_DDDPRINT( + "tzoffset iteration two-value cycle, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); if (tzoffprev1 > tzoff) { tzoff = tzoffprev1; } @@ -894,7 +958,7 @@ duk_int_t tzoffset = 0; duk_push_this(thr); - h = duk_get_hobject(thr, -1); /* XXX: getter with class check, useful in built-ins */ + h = duk_get_hobject(thr, -1); /* XXX: getter with class check, useful in built-ins */ if (h == NULL || DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_DATE) { DUK_ERROR_TYPE(thr, "expected Date"); DUK_WO_NORETURN(return 0.0;); @@ -920,7 +984,7 @@ /* Note: DST adjustment is determined using UTC time. * If 'd' is NaN, tzoffset will be 0. */ - tzoffset = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d); /* seconds */ + tzoffset = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d); /* seconds */ d += tzoffset * 1000L; } if (out_tzoffset) { @@ -945,8 +1009,8 @@ /* ... this */ d = duk_bi_date_get_timeval_from_dparts(dparts, flags); - duk_push_number(thr, d); /* -> ... this timeval_new */ - duk_dup_top(thr); /* -> ... this timeval_new timeval_new */ + duk_push_number(thr, d); /* -> ... this timeval_new */ + duk_dup_top(thr); /* -> ... this timeval_new timeval_new */ /* Must force write because e.g. .setYear() must work even when * the Date instance is frozen. @@ -959,8 +1023,8 @@ /* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long. */ DUK_LOCAL void duk__format_parts_iso8601(duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags, duk_uint8_t *out_buf) { - char yearstr8; /* "-123456\0" */ - char tzstr8; /* "+11:22\0" */ + char yearstr8; /* "-123456\0" */ + char tzstr8; /* "+11:22\0" */ char sep = (flags & DUK_DATE_FLAG_SEP_T) ? DUK_ASC_UC_T : DUK_ASC_SPACE; DUK_ASSERT(partsDUK_DATE_IDX_MONTH >= 1 && partsDUK_DATE_IDX_MONTH <= 12); @@ -972,8 +1036,9 @@ */ DUK_SNPRINTF(yearstr, sizeof(yearstr), - (partsDUK_DATE_IDX_YEAR >= 0 && partsDUK_DATE_IDX_YEAR <= 9999) ? "%04ld" : - ((partsDUK_DATE_IDX_YEAR >= 0) ? "+%06ld" : "%07ld"), + (partsDUK_DATE_IDX_YEAR >= 0 && partsDUK_DATE_IDX_YEAR <= 9999) ? + "%04ld" : + ((partsDUK_DATE_IDX_YEAR >= 0) ? "+%06ld" : "%07ld"), (long) partsDUK_DATE_IDX_YEAR); yearstrsizeof(yearstr) - 1 = (char) 0; @@ -994,8 +1059,9 @@ tmp = tmp / 60; arg_hours = tmp / 60; arg_minutes = tmp % 60; - DUK_ASSERT(arg_hours <= 24); /* Even less is actually guaranteed for a valid tzoffset. */ - arg_hours = arg_hours & 0x3f; /* For 0,24 this is a no-op, but fixes GCC 7 warning, see https://github.com/svaarala/duktape/issues/1602. */ + DUK_ASSERT(arg_hours <= 24); /* Even less is actually guaranteed for a valid tzoffset. */ + arg_hours = arg_hours & 0x3f; /* For 0,24 this is a no-op, but fixes GCC 7 warning, see + https://github.com/svaarala/duktape/issues/1602. */ DUK_SNPRINTF(tzstr, sizeof(tzstr), fmt, (int) arg_hours, (int) arg_minutes); tzstrsizeof(tzstr) - 1 = (char) 0; @@ -1008,18 +1074,31 @@ * is portable. */ if ((flags & DUK_DATE_FLAG_TOSTRING_DATE) && (flags & DUK_DATE_FLAG_TOSTRING_TIME)) { - DUK_SPRINTF((char *) out_buf, "%s-%02d-%02d%c%02d:%02d:%02d.%03d%s", - (const char *) yearstr, (int) partsDUK_DATE_IDX_MONTH, (int) partsDUK_DATE_IDX_DAY, (int) sep, - (int) partsDUK_DATE_IDX_HOUR, (int) partsDUK_DATE_IDX_MINUTE, - (int) partsDUK_DATE_IDX_SECOND, (int) partsDUK_DATE_IDX_MILLISECOND, (const char *) tzstr); + DUK_SPRINTF((char *) out_buf, + "%s-%02d-%02d%c%02d:%02d:%02d.%03d%s", + (const char *) yearstr, + (int) partsDUK_DATE_IDX_MONTH, + (int) partsDUK_DATE_IDX_DAY, + (int) sep, + (int) partsDUK_DATE_IDX_HOUR, + (int) partsDUK_DATE_IDX_MINUTE, + (int) partsDUK_DATE_IDX_SECOND, + (int) partsDUK_DATE_IDX_MILLISECOND, + (const char *) tzstr); } else if (flags & DUK_DATE_FLAG_TOSTRING_DATE) { - DUK_SPRINTF((char *) out_buf, "%s-%02d-%02d", - (const char *) yearstr, (int) partsDUK_DATE_IDX_MONTH, (int) partsDUK_DATE_IDX_DAY); + DUK_SPRINTF((char *) out_buf, + "%s-%02d-%02d", + (const char *) yearstr, + (int) partsDUK_DATE_IDX_MONTH, + (int) partsDUK_DATE_IDX_DAY); } else { DUK_ASSERT(flags & DUK_DATE_FLAG_TOSTRING_TIME); - DUK_SPRINTF((char *) out_buf, "%02d:%02d:%02d.%03d%s", - (int) partsDUK_DATE_IDX_HOUR, (int) partsDUK_DATE_IDX_MINUTE, - (int) partsDUK_DATE_IDX_SECOND, (int) partsDUK_DATE_IDX_MILLISECOND, + DUK_SPRINTF((char *) out_buf, + "%02d:%02d:%02d.%03d%s", + (int) partsDUK_DATE_IDX_HOUR, + (int) partsDUK_DATE_IDX_MINUTE, + (int) partsDUK_DATE_IDX_SECOND, + (int) partsDUK_DATE_IDX_MILLISECOND, (const char *) tzstr); } } @@ -1031,11 +1110,11 @@ DUK_LOCAL duk_ret_t duk__to_string_helper(duk_hthread *thr, duk_small_uint_t flags) { duk_double_t d; duk_int_t partsDUK_DATE_IDX_NUM_PARTS; - duk_int_t tzoffset; /* seconds, doesn't fit into 16 bits */ + duk_int_t tzoffset; /* seconds, doesn't fit into 16 bits */ duk_bool_t rc; duk_uint8_t bufDUK_BI_DATE_ISO8601_BUFSIZE; - DUK_UNREF(rc); /* unreferenced with some options */ + DUK_UNREF(rc); /* unreferenced with some options */ d = duk__push_this_get_timeval_tzoffset(thr, flags, &tzoffset); if (DUK_ISNAN(d)) { @@ -1087,9 +1166,9 @@ DUK_LOCAL duk_ret_t duk__get_part_helper(duk_hthread *thr, duk_small_uint_t flags_and_idx) { duk_double_t d; duk_int_t partsDUK_DATE_IDX_NUM_PARTS; - duk_small_uint_t idx_part = (duk_small_uint_t) (flags_and_idx >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ + duk_small_uint_t idx_part = (duk_small_uint_t) (flags_and_idx >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ - DUK_ASSERT_DISABLE(idx_part >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx_part >= 0); /* unsigned */ DUK_ASSERT(idx_part < DUK_DATE_IDX_NUM_PARTS); d = duk__push_this_get_timeval(thr, flags_and_idx); @@ -1099,7 +1178,7 @@ } DUK_ASSERT(DUK_ISFINITE(d)); - duk_bi_date_timeval_to_parts(d, parts, NULL, flags_and_idx); /* no need to mask idx portion */ + duk_bi_date_timeval_to_parts(d, parts, NULL, flags_and_idx); /* no need to mask idx portion */ /* Setter APIs detect special year numbers (0...99) and apply a +1900 * only in certain cases. The legacy getYear() getter applies -1900 @@ -1121,7 +1200,7 @@ duk_int_t partsDUK_DATE_IDX_NUM_PARTS; duk_double_t dpartsDUK_DATE_IDX_NUM_PARTS; duk_idx_t nargs; - duk_small_uint_t maxnargs = (duk_small_uint_t) (flags_and_maxnargs >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ + duk_small_uint_t maxnargs = (duk_small_uint_t) (flags_and_maxnargs >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ duk_small_uint_t idx_first, idx; duk_small_uint_t i; @@ -1168,7 +1247,7 @@ DUK_ASSERT(maxnargs >= 1 && maxnargs <= 3); idx_first = DUK_DATE_IDX_DAY - (maxnargs - 1); } - DUK_ASSERT_DISABLE(idx_first >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx_first >= 0); /* unsigned */ DUK_ASSERT(idx_first < DUK_DATE_IDX_NUM_PARTS); for (i = 0; i < maxnargs; i++) { @@ -1177,7 +1256,7 @@ break; } idx = idx_first + i; - DUK_ASSERT_DISABLE(idx >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx >= 0); /* unsigned */ DUK_ASSERT(idx < DUK_DATE_IDX_NUM_PARTS); if (idx == DUK_DATE_IDX_YEAR && (flags_and_maxnargs & DUK_DATE_FLAG_YEAR_FIXUP)) { @@ -1229,7 +1308,7 @@ } duk_dup(thr, idx_val); duk_to_int(thr, -1); - d = duk_get_number(thr, -1); /* get as double to handle huge numbers correctly */ + d = duk_get_number(thr, -1); /* get as double to handle huge numbers correctly */ if (d >= 0.0 && d <= 99.0) { d += 1900.0; duk_push_number(thr, d); @@ -1277,10 +1356,14 @@ } DUK_DDD(DUK_DDDPRINT("parts from args -> %lf %lf %lf %lf %lf %lf %lf %lf", - (double) dparts0, (double) dparts1, - (double) dparts2, (double) dparts3, - (double) dparts4, (double) dparts5, - (double) dparts6, (double) dparts7)); + (double) dparts0, + (double) dparts1, + (double) dparts2, + (double) dparts3, + (double) dparts4, + (double) dparts5, + (double) dparts6, + (double) dparts7)); } /* @@ -1436,9 +1519,8 @@ DUK_DDD(DUK_DDDPRINT("Date constructor, nargs=%ld, is_cons=%ld", (long) nargs, (long) is_cons)); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATE), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATE), DUK_BIDX_DATE_PROTOTYPE); /* Unlike most built-ins, the internal PrimitiveValue of a Date @@ -1460,9 +1542,9 @@ str = duk_get_string_notsymbol(thr, 0); if (str) { duk__parse_string(thr, str); - duk_replace(thr, 0); /* may be NaN */ + duk_replace(thr, 0); /* may be NaN */ } - d = duk__timeclip(duk_to_number(thr, 0)); /* symbols fail here */ + d = duk__timeclip(duk_to_number(thr, 0)); /* symbols fail here */ duk_push_number(thr, d); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_W); return 1; @@ -1472,8 +1554,8 @@ /* Parts are in local time, convert when setting. */ - (void) duk__set_this_timeval_from_dparts(thr, dparts, DUK_DATE_FLAG_LOCALTIME /*flags*/); /* -> ... this timeval */ - duk_pop(thr); /* -> ... this */ + (void) duk__set_this_timeval_from_dparts(thr, dparts, DUK_DATE_FLAG_LOCALTIME /*flags*/); /* -> ... this timeval */ + duk_pop(thr); /* -> ... this */ return 1; } @@ -1504,7 +1586,7 @@ duk_double_t d; d = duk_time_get_ecmascript_time_nofrac(thr); - DUK_ASSERT(duk_double_equals(duk__timeclip(d), d)); /* TimeClip() should never be necessary */ + DUK_ASSERT(duk_double_equals(duk__timeclip(d), d)); /* TimeClip() should never be necessary */ duk_push_number(thr, d); return 1; } @@ -1553,7 +1635,7 @@ * as their behavior is identical. */ - duk_double_t d = duk__push_this_get_timeval(thr, 0 /*flags*/); /* -> this */ + duk_double_t d = duk__push_this_get_timeval(thr, 0 /*flags*/); /* -> this */ DUK_ASSERT(DUK_ISFINITE(d) || DUK_ISNAN(d)); duk_push_number(thr, d); return 1; @@ -1579,7 +1661,7 @@ duk_pop(thr); duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_ISO_STRING); - duk_dup_m2(thr); /* -> O toIsoString O */ + duk_dup_m2(thr); /* -> O toIsoString O */ duk_call_method(thr, 0); return 1; } @@ -1752,8 +1834,7 @@ DUK_ASSERT_TOP(thr, 2); hintstr = duk_require_lstring(thr, 0, &hintlen); - if ((hintlen == 6 && DUK_STRCMP(hintstr, "string") == 0) || - (hintlen == 7 && DUK_STRCMP(hintstr, "default") == 0)) { + if ((hintlen == 6 && DUK_STRCMP(hintstr, "string") == 0) || (hintlen == 7 && DUK_STRCMP(hintstr, "default") == 0)) { hint = DUK_HINT_STRING; } else if (hintlen == 6 && DUK_STRCMP(hintstr, "number") == 0) { hint = DUK_HINT_NUMBER; @@ -1764,6 +1845,6 @@ duk_to_primitive_ordinary(thr, -1, hint); return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ -#endif /* DUK_USE_DATE_BUILTIN */ +#endif /* DUK_USE_DATE_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_date_unix.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_date_unix.c
Changed
@@ -11,8 +11,8 @@ /* Buffer sizes for some UNIX calls. Larger than strictly necessary * to avoid Valgrind errors. */ -#define DUK__STRPTIME_BUF_SIZE 64 -#define DUK__STRFTIME_BUF_SIZE 64 +#define DUK__STRPTIME_BUF_SIZE 64 +#define DUK__STRFTIME_BUF_SIZE 64 #if defined(DUK_USE_DATE_NOW_GETTIMEOFDAY) /* Get current ECMAScript time (= UNIX/Posix time, but in milliseconds). */ @@ -26,12 +26,11 @@ } /* As of Duktape 2.2.0 allow fractions. */ - d = ((duk_double_t) tv.tv_sec) * 1000.0 + - ((duk_double_t) tv.tv_usec) / 1000.0; + d = ((duk_double_t) tv.tv_sec) * 1000.0 + ((duk_double_t) tv.tv_usec) / 1000.0; return d; } -#endif /* DUK_USE_DATE_NOW_GETTIMEOFDAY */ +#endif /* DUK_USE_DATE_NOW_GETTIMEOFDAY */ #if defined(DUK_USE_DATE_NOW_TIME) /* Not a very good provider: only full seconds are available. */ @@ -45,7 +44,7 @@ } return ((duk_double_t) t) * 1000.0; } -#endif /* DUK_USE_DATE_NOW_TIME */ +#endif /* DUK_USE_DATE_NOW_TIME */ #if defined(DUK_USE_DATE_TZO_GMTIME) || defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) /* Get local time offset (in seconds) for a certain (UTC) instant 'd'. */ @@ -128,7 +127,7 @@ DUK_ASSERT(partsDUK_DATE_IDX_YEAR >= 1970 && partsDUK_DATE_IDX_YEAR <= 2038); d = duk_bi_date_get_timeval_from_dparts(dparts, 0 /*flags*/); - DUK_ASSERT(d >= 0 && d < 2147483648.0 * 1000.0); /* unsigned 31-bit range */ + DUK_ASSERT(d >= 0 && d < 2147483648.0 * 1000.0); /* unsigned 31-bit range */ t = (time_t) (d / 1000.0); DUK_DDD(DUK_DDDPRINT("timeval: %lf -> time_t %ld", (double) d, (long) t)); @@ -150,14 +149,26 @@ #endif DUK_DDD(DUK_DDDPRINT("gmtime result: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tms0.tm_sec, (long) tms0.tm_min, (long) tms0.tm_hour, - (long) tms0.tm_mday, (long) tms0.tm_mon, (long) tms0.tm_year, - (long) tms0.tm_wday, (long) tms0.tm_yday, (long) tms0.tm_isdst)); + (long) tms0.tm_sec, + (long) tms0.tm_min, + (long) tms0.tm_hour, + (long) tms0.tm_mday, + (long) tms0.tm_mon, + (long) tms0.tm_year, + (long) tms0.tm_wday, + (long) tms0.tm_yday, + (long) tms0.tm_isdst)); DUK_DDD(DUK_DDDPRINT("localtime result: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tms1.tm_sec, (long) tms1.tm_min, (long) tms1.tm_hour, - (long) tms1.tm_mday, (long) tms1.tm_mon, (long) tms1.tm_year, - (long) tms1.tm_wday, (long) tms1.tm_yday, (long) tms1.tm_isdst)); + (long) tms1.tm_sec, + (long) tms1.tm_min, + (long) tms1.tm_hour, + (long) tms1.tm_mday, + (long) tms1.tm_mon, + (long) tms1.tm_year, + (long) tms1.tm_wday, + (long) tms1.tm_yday, + (long) tms1.tm_isdst)); /* tm_isdst is both an input and an output to mktime(), use 0 to * avoid DST handling in mktime(): @@ -166,8 +177,8 @@ */ tms0.tm_isdst = 0; tms1.tm_isdst = 0; - t1 = mktime(&tms0); /* UTC */ - t2 = mktime(&tms1); /* local */ + t1 = mktime(&tms0); /* UTC */ + t2 = mktime(&tms1); /* local */ if (t1 == (time_t) -1 || t2 == (time_t) -1) { /* This check used to be for (t < 0) but on some platforms * time_t is unsigned and apparently the proper way to detect @@ -190,12 +201,12 @@ #endif return (duk_int_t) difftime(t2, t1); - mktime_error: +mktime_error: /* XXX: return something more useful, so that caller can throw? */ DUK_D(DUK_DPRINT("mktime() failed, d=%lf", (double) d)); return 0; } -#endif /* DUK_USE_DATE_TZO_GMTIME */ +#endif /* DUK_USE_DATE_TZO_GMTIME */ #if defined(DUK_USE_DATE_PRS_STRPTIME) DUK_INTERNAL duk_bool_t duk_bi_date_parse_string_strptime(duk_hthread *thr, const char *str) { @@ -205,7 +216,7 @@ /* Copy to buffer with slack to avoid Valgrind gripes from strptime. */ DUK_ASSERT(str != NULL); - duk_memzero(buf, sizeof(buf)); /* valgrind whine without this */ + duk_memzero(buf, sizeof(buf)); /* valgrind whine without this */ DUK_SNPRINTF(buf, sizeof(buf), "%s", (const char *) str); bufsizeof(buf) - 1 = (char) 0; @@ -215,10 +226,16 @@ if (strptime((const char *) buf, "%c", &tm) != NULL) { DUK_DDD(DUK_DDDPRINT("before mktime: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tm.tm_sec, (long) tm.tm_min, (long) tm.tm_hour, - (long) tm.tm_mday, (long) tm.tm_mon, (long) tm.tm_year, - (long) tm.tm_wday, (long) tm.tm_yday, (long) tm.tm_isdst)); - tm.tm_isdst = -1; /* negative: dst info not available */ + (long) tm.tm_sec, + (long) tm.tm_min, + (long) tm.tm_hour, + (long) tm.tm_mday, + (long) tm.tm_mon, + (long) tm.tm_year, + (long) tm.tm_wday, + (long) tm.tm_yday, + (long) tm.tm_isdst)); + tm.tm_isdst = -1; /* negative: dst info not available */ t = mktime(&tm); DUK_DDD(DUK_DDDPRINT("mktime() -> %ld", (long) t)); @@ -230,7 +247,7 @@ return 0; } -#endif /* DUK_USE_DATE_PRS_STRPTIME */ +#endif /* DUK_USE_DATE_PRS_STRPTIME */ #if defined(DUK_USE_DATE_PRS_GETDATE) DUK_INTERNAL duk_bool_t duk_bi_date_parse_string_getdate(duk_hthread *thr, const char *str) { @@ -257,10 +274,13 @@ return 0; } -#endif /* DUK_USE_DATE_PRS_GETDATE */ +#endif /* DUK_USE_DATE_PRS_GETDATE */ #if defined(DUK_USE_DATE_FMT_STRFTIME) -DUK_INTERNAL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags) { +DUK_INTERNAL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, + duk_int_t *parts, + duk_int_t tzoffset, + duk_small_uint_t flags) { char bufDUK__STRFTIME_BUF_SIZE; struct tm tm; const char *fmt; @@ -278,8 +298,7 @@ * probably not an accurate guarantee of strftime() supporting or not * supporting a large time range (the full ECMAScript range). */ - if (sizeof(time_t) < 8 && - (partsDUK_DATE_IDX_YEAR < 1970 || partsDUK_DATE_IDX_YEAR > 2037)) { + if (sizeof(time_t) < 8 && (partsDUK_DATE_IDX_YEAR < 1970 || partsDUK_DATE_IDX_YEAR > 2037)) { /* be paranoid for 32-bit time values (even avoiding negative ones) */ return 0; } @@ -288,8 +307,8 @@ tm.tm_sec = partsDUK_DATE_IDX_SECOND; tm.tm_min = partsDUK_DATE_IDX_MINUTE; tm.tm_hour = partsDUK_DATE_IDX_HOUR; - tm.tm_mday = partsDUK_DATE_IDX_DAY; /* already one-based */ - tm.tm_mon = partsDUK_DATE_IDX_MONTH - 1; /* one-based -> zero-based */ + tm.tm_mday = partsDUK_DATE_IDX_DAY; /* already one-based */ + tm.tm_mon = partsDUK_DATE_IDX_MONTH - 1; /* one-based -> zero-based */ tm.tm_year = partsDUK_DATE_IDX_YEAR - 1900; tm.tm_wday = partsDUK_DATE_IDX_WEEKDAY; tm.tm_isdst = 0; @@ -309,7 +328,7 @@ duk_push_string(thr, buf); return 1; } -#endif /* DUK_USE_DATE_FMT_STRFTIME */ +#endif /* DUK_USE_DATE_FMT_STRFTIME */ #if defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME) DUK_INTERNAL duk_double_t duk_bi_date_get_monotonic_time_clock_gettime(void) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_date_windows.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_date_windows.c
Changed
@@ -28,20 +28,20 @@ res->LowPart = ft->dwLowDateTime; res->HighPart = ft->dwHighDateTime; } -#endif /* DUK_USE_DATE_NOW_WINDOWS_SUBMS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS_SUBMS */ DUK_LOCAL void duk__set_systime_jan1970(SYSTEMTIME *st) { duk_memzero((void *) st, sizeof(*st)); st->wYear = 1970; st->wMonth = 1; - st->wDayOfWeek = 4; /* not sure whether or not needed; Thursday */ + st->wDayOfWeek = 4; /* not sure whether or not needed; Thursday */ st->wDay = 1; DUK_ASSERT(st->wHour == 0); DUK_ASSERT(st->wMinute == 0); DUK_ASSERT(st->wSecond == 0); DUK_ASSERT(st->wMilliseconds == 0); } -#endif /* defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS) */ +#endif /* defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS) */ #if defined(DUK_USE_DATE_NOW_WINDOWS) DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows(void) { @@ -63,7 +63,7 @@ */ return (duk_double_t) ((LONGLONG) tmp1.QuadPart - (LONGLONG) tmp2.QuadPart) / 10000.0; } -#endif /* DUK_USE_DATE_NOW_WINDOWS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS */ #if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows_subms(void) { @@ -85,7 +85,7 @@ */ return (duk_double_t) ((LONGLONG) tmp1.QuadPart - (LONGLONG) tmp2.QuadPart) / 10000.0; } -#endif /* DUK_USE_DATE_NOW_WINDOWS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS */ #if defined(DUK_USE_DATE_TZO_WINDOWS) DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows(duk_double_t d) { @@ -110,8 +110,8 @@ duk__set_systime_jan1970(&st1); duk__convert_systime_to_ularge((const SYSTEMTIME *) &st1, &tmp1); - tmp2.QuadPart = (ULONGLONG) (d * 10000.0); /* millisec -> 100ns units since jan 1, 1970 */ - tmp2.QuadPart += tmp1.QuadPart; /* input 'd' in Windows UTC, 100ns units */ + tmp2.QuadPart = (ULONGLONG) (d * 10000.0); /* millisec -> 100ns units since jan 1, 1970 */ + tmp2.QuadPart += tmp1.QuadPart; /* input 'd' in Windows UTC, 100ns units */ ft1.dwLowDateTime = tmp2.LowPart; ft1.dwHighDateTime = tmp2.HighPart; @@ -126,9 +126,9 @@ duk__convert_systime_to_ularge((const SYSTEMTIME *) &st3, &tmp3); /* Positive if local time ahead of UTC. */ - return (duk_int_t) (((LONGLONG) tmp3.QuadPart - (LONGLONG) tmp2.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ + return (duk_int_t) (((LONGLONG) tmp3.QuadPart - (LONGLONG) tmp2.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ } -#endif /* DUK_USE_DATE_TZO_WINDOWS */ +#endif /* DUK_USE_DATE_TZO_WINDOWS */ #if defined(DUK_USE_DATE_TZO_WINDOWS_NO_DST) DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows_no_dst(duk_double_t d) { @@ -163,17 +163,19 @@ } duk__convert_systime_to_ularge((const SYSTEMTIME *) &st2, &tmp2); - return (duk_int_t) (((LONGLONG) tmp2.QuadPart - (LONGLONG) tmp1.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ + return (duk_int_t) (((LONGLONG) tmp2.QuadPart - (LONGLONG) tmp1.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ } -#endif /* DUK_USE_DATE_TZO_WINDOWS_NO_DST */ +#endif /* DUK_USE_DATE_TZO_WINDOWS_NO_DST */ #if defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC) DUK_INTERNAL duk_double_t duk_bi_date_get_monotonic_time_windows_qpc(void) { LARGE_INTEGER count, freq; /* There are legacy issues with QueryPerformanceCounter(): - * - Potential jumps: https://support.microsoft.com/en-us/help/274323/performance-counter-value-may-unexpectedly-leap-forward - * - Differences between cores (XP): https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions + * - Potential jumps: + * https://support.microsoft.com/en-us/help/274323/performance-counter-value-may-unexpectedly-leap-forward + * - Differences between cores (XP): + * https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions * * We avoid these by enabling QPC by default only for Vista or later. */ @@ -190,4 +192,4 @@ return 0.0; } } -#endif /* DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC */ +#endif /* DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_duktape.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_duktape.c
Changed
@@ -60,7 +60,7 @@ return 1; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_duktape_object_enc(duk_hthread *thr) { duk_hstring *h_str; @@ -70,7 +70,7 @@ * non-existent optional parameters. */ - h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons. */ + h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons. */ duk_require_valid_index(thr, 1); if (h_str == DUK_HTHREAD_STRING_HEX(thr)) { @@ -87,9 +87,8 @@ 1 /*idx_value*/, 2 /*idx_replacer*/, 3 /*idx_space*/, - DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_ASCII_ONLY | - DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); + DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_ASCII_ONLY | + DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); #endif #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JC) } else if (h_str == DUK_HTHREAD_STRING_JC(thr)) { @@ -97,8 +96,7 @@ 1 /*idx_value*/, 2 /*idx_replacer*/, 3 /*idx_space*/, - DUK_JSON_FLAG_EXT_COMPATIBLE | - DUK_JSON_FLAG_ASCII_ONLY /*flags*/); + DUK_JSON_FLAG_EXT_COMPATIBLE | DUK_JSON_FLAG_ASCII_ONLY /*flags*/); #endif } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -114,7 +112,7 @@ * non-existent optional parameters. */ - h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons */ + h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons */ duk_require_valid_index(thr, 1); if (h_str == DUK_HTHREAD_STRING_HEX(thr)) { @@ -127,17 +125,11 @@ DUK_ASSERT_TOP(thr, 2); #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JX) } else if (h_str == DUK_HTHREAD_STRING_JX(thr)) { - duk_bi_json_parse_helper(thr, - 1 /*idx_value*/, - 2 /*idx_replacer*/, - DUK_JSON_FLAG_EXT_CUSTOM /*flags*/); + duk_bi_json_parse_helper(thr, 1 /*idx_value*/, 2 /*idx_replacer*/, DUK_JSON_FLAG_EXT_CUSTOM /*flags*/); #endif #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JC) } else if (h_str == DUK_HTHREAD_STRING_JC(thr)) { - duk_bi_json_parse_helper(thr, - 1 /*idx_value*/, - 2 /*idx_replacer*/, - DUK_JSON_FLAG_EXT_COMPATIBLE /*flags*/); + duk_bi_json_parse_helper(thr, 1 /*idx_value*/, 2 /*idx_replacer*/, DUK_JSON_FLAG_EXT_COMPATIBLE /*flags*/); #endif } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -152,7 +144,7 @@ DUK_INTERNAL duk_ret_t duk_bi_duktape_object_compact(duk_hthread *thr) { DUK_ASSERT_TOP(thr, 1); duk_compact(thr, 0); - return 1; /* return the argument object */ + return 1; /* return the argument object */ } -#endif /* DUK_USE_DUKTAPE_BUILTIN */ +#endif /* DUK_USE_DUKTAPE_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_encoding.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_encoding.c
Changed
@@ -12,17 +12,17 @@ */ typedef struct { - duk_uint8_t *out; /* where to write next byte(s) */ - duk_codepoint_t lead; /* lead surrogate */ + duk_uint8_t *out; /* where to write next byte(s) */ + duk_codepoint_t lead; /* lead surrogate */ } duk__encode_context; typedef struct { /* UTF-8 decoding state */ - duk_codepoint_t codepoint; /* built up incrementally */ - duk_uint8_t upper; /* max value of next byte (decode error otherwise) */ - duk_uint8_t lower; /* min value of next byte (ditto) */ - duk_uint8_t needed; /* how many more bytes we need */ - duk_uint8_t bom_handled; /* BOM seen or no longer expected */ + duk_codepoint_t codepoint; /* built up incrementally */ + duk_uint8_t upper; /* max value of next byte (decode error otherwise) */ + duk_uint8_t lower; /* min value of next byte (ditto) */ + duk_uint8_t needed; /* how many more bytes we need */ + duk_uint8_t bom_handled; /* BOM seen or no longer expected */ /* Decoder configuration */ duk_uint8_t fatal; @@ -32,9 +32,9 @@ /* The signed duk_codepoint_t type is used to signal a decoded codepoint * (>= 0) or various other states using negative values. */ -#define DUK__CP_CONTINUE (-1) /* continue to next byte, no completed codepoint */ -#define DUK__CP_ERROR (-2) /* decoding error */ -#define DUK__CP_RETRY (-3) /* decoding error; retry last byte */ +#define DUK__CP_CONTINUE (-1) /* continue to next byte, no completed codepoint */ +#define DUK__CP_ERROR (-2) /* decoding error */ +#define DUK__CP_RETRY (-3) /* decoding error; retry last byte */ /* * Raw helpers for encoding/decoding @@ -121,7 +121,7 @@ } else { /* got a codepoint */ duk_codepoint_t ret; - DUK_ASSERT(dec_ctx->codepoint <= 0x10ffffL); /* Decoding rules guarantee. */ + DUK_ASSERT(dec_ctx->codepoint <= 0x10ffffL); /* Decoding rules guarantee. */ ret = dec_ctx->codepoint; dec_ctx->codepoint = 0x0000L; dec_ctx->needed = 0; @@ -177,7 +177,8 @@ } else { /* low surrogate */ if (enc_ctx->lead != 0x0000L) { - codepoint = (duk_codepoint_t) (0x010000L + ((enc_ctx->lead - 0xd800L) << 10) + (codepoint - 0xdc00L)); + codepoint = + (duk_codepoint_t) (0x010000L + ((enc_ctx->lead - 0xd800L) << 10) + (codepoint - 0xdc00L)); enc_ctx->lead = 0x0000L; } else { /* unpaired low surrogate */ @@ -198,7 +199,7 @@ */ enc_ctx->out += duk_unicode_encode_xutf8((duk_ucodepoint_t) codepoint, enc_ctx->out); } -#endif /* DUK_USE_ENCODING_BUILTINS */ +#endif /* DUK_USE_ENCODING_BUILTINS */ /* Shared helper for buffer-to-string using a TextDecoder() compatible UTF-8 * decoder. @@ -227,18 +228,15 @@ duk_push_fixed_buffer_nozero(thr, 0); duk_replace(thr, 0); } - (void) duk_require_buffer_data(thr, 0, &len); /* Need 'len', avoid pointer. */ + (void) duk_require_buffer_data(thr, 0, &len); /* Need 'len', avoid pointer. */ - if (duk_check_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_NONE)) { + if (duk_check_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_NONE)) { /* Use defaults, treat missing value like undefined. */ } else { - duk_require_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_OBJECT); + duk_require_type_mask(thr, + 1, + DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_LIGHTFUNC | + DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_OBJECT); if (duk_get_prop_literal(thr, 1, "stream")) { stream = duk_to_boolean(thr, -1); } @@ -256,7 +254,8 @@ DUK_ERROR_TYPE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return 0;); } - output = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, 3 + (3 * len)); /* used parts will be always manually written over */ + output = + (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, 3 + (3 * len)); /* used parts will be always manually written over */ input = (const duk_uint8_t *) duk_get_buffer_data(thr, 0, &len_tmp); DUK_ASSERT(input != NULL || len == 0); @@ -288,7 +287,7 @@ /* Decoding error with or without retry. */ DUK_ASSERT(codepoint == DUK__CP_ERROR || codepoint == DUK__CP_RETRY); if (codepoint == DUK__CP_RETRY) { - --in; /* retry last byte */ + --in; /* retry last byte */ } /* replacement mode: replace with U+FFFD */ codepoint = DUK_UNICODE_CP_REPLACEMENT_CHARACTER; @@ -321,7 +320,7 @@ DUK_ASSERT(out <= output + (3 + (3 * len))); } } - duk__utf8_decode_init(dec_ctx); /* Initialize decoding state for potential reuse. */ + duk__utf8_decode_init(dec_ctx); /* Initialize decoding state for potential reuse. */ } /* Output buffer is fixed and thus stable even if there had been @@ -330,7 +329,7 @@ duk_push_lstring(thr, (const char *) output, (duk_size_t) (out - output)); return 1; - fail_type: +fail_type: DUK_ERROR_TYPE(thr, DUK_STR_UTF8_DECODE_FAILED); DUK_WO_NORETURN(return 0;); } @@ -389,7 +388,7 @@ output = (duk_uint8_t *) duk_push_dynamic_buffer(thr, 3 * len); if (len > 0) { - DUK_ASSERT(duk_is_string(thr, 0)); /* True if len > 0. */ + DUK_ASSERT(duk_is_string(thr, 0)); /* True if len > 0. */ /* XXX: duk_decode_string() is used to process the input * string. For standard ECMAScript strings, represented @@ -465,7 +464,7 @@ dec_ctx = (duk__decode_context *) duk_push_fixed_buffer(thr, sizeof(duk__decode_context)); dec_ctx->fatal = (duk_uint8_t) fatal; dec_ctx->ignore_bom = (duk_uint8_t) ignore_bom; - duk__utf8_decode_init(dec_ctx); /* Initializes remaining fields. */ + duk__utf8_decode_init(dec_ctx); /* Initializes remaining fields. */ duk_put_prop_literal(thr, -2, DUK_INTERNAL_SYMBOL("Context")); return 0; @@ -511,7 +510,7 @@ dec_ctx = duk__get_textdecoder_context(thr); return duk__decode_helper(thr, dec_ctx); } -#endif /* DUK_USE_ENCODING_BUILTINS */ +#endif /* DUK_USE_ENCODING_BUILTINS */ /* * Internal helper for Node.js Buffer @@ -525,8 +524,8 @@ DUK_INTERNAL duk_ret_t duk_textdecoder_decode_utf8_nodejs(duk_hthread *thr) { duk__decode_context dec_ctx; - dec_ctx.fatal = 0; /* use replacement chars */ - dec_ctx.ignore_bom = 1; /* ignore BOMs (matches Node.js Buffer .toString()) */ + dec_ctx.fatal = 0; /* use replacement chars */ + dec_ctx.ignore_bom = 1; /* ignore BOMs (matches Node.js Buffer .toString()) */ duk__utf8_decode_init(&dec_ctx); return duk__decode_helper(thr, &dec_ctx);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_error.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_error.c
Changed
@@ -15,9 +15,8 @@ duk_small_int_t bidx_prototype = duk_get_current_magic(thr); /* same for both error and each subclass like TypeError */ - duk_uint_t flags_and_class = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR); + duk_uint_t flags_and_class = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR); (void) duk_push_object_helper(thr, flags_and_class, bidx_prototype); @@ -26,7 +25,7 @@ */ if (!duk_is_undefined(thr, 0)) { duk_to_string(thr, 0); - duk_dup_0(thr); /* message error message */ + duk_dup_0(thr); /* message error message */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC); } @@ -85,7 +84,7 @@ return 1; } duk_push_literal(thr, ": "); - duk_insert(thr, -2); /* ... name ': ' message */ + duk_insert(thr, -2); /* ... name ': ' message */ duk_concat(thr, 3); return 1; @@ -108,15 +107,15 @@ */ /* constants arbitrary, chosen for small loads */ -#define DUK__OUTPUT_TYPE_TRACEBACK (-1) -#define DUK__OUTPUT_TYPE_FILENAME 0 -#define DUK__OUTPUT_TYPE_LINENUMBER 1 +#define DUK__OUTPUT_TYPE_TRACEBACK (-1) +#define DUK__OUTPUT_TYPE_FILENAME 0 +#define DUK__OUTPUT_TYPE_LINENUMBER 1 DUK_LOCAL duk_ret_t duk__error_getter_helper(duk_hthread *thr, duk_small_int_t output_type) { duk_idx_t idx_td; - duk_small_int_t i; /* traceback depth fits into 16 bits */ - duk_small_int_t t; /* stack type fits into 16 bits */ - duk_small_int_t count_func = 0; /* traceback depth ensures fits into 16 bits */ + duk_small_int_t i; /* traceback depth fits into 16 bits */ + duk_small_int_t t; /* stack type fits into 16 bits */ + duk_small_int_t count_func = 0; /* traceback depth ensures fits into 16 bits */ const char *str_tailcall = " tailcall"; const char *str_strict = " strict"; const char *str_construct = " construct"; @@ -124,7 +123,7 @@ const char *str_directeval = " directeval"; const char *str_empty = ""; - DUK_ASSERT_TOP(thr, 0); /* fixed arg count */ + DUK_ASSERT_TOP(thr, 0); /* fixed arg count */ duk_push_this(thr); duk_xget_owndataprop_stridx_short(thr, -1, DUK_STRIDX_INT_TRACEDATA); @@ -139,7 +138,7 @@ if (duk_check_type(thr, idx_td, DUK_TYPE_OBJECT)) { /* Current tracedata contains 2 entries per callstack entry. */ - for (i = 0; ; i += 2) { + for (i = 0;; i += 2) { duk_int_t pc; duk_uint_t line; duk_uint_t flags; @@ -195,46 +194,53 @@ /* XXX: Change 'anon' handling here too, to use empty string for anonymous functions? */ /* XXX: Could be improved by coercing to a readable duk_tval (especially string escaping) */ - h_name = duk_get_hstring_notsymbol(thr, -2); /* may be NULL */ + h_name = duk_get_hstring_notsymbol(thr, -2); /* may be NULL */ funcname = (h_name == NULL || h_name == DUK_HTHREAD_STRING_EMPTY_STRING(thr)) ? - "anon" : (const char *) DUK_HSTRING_GET_DATA(h_name); + "anon" : + (const char *) DUK_HSTRING_GET_DATA(h_name); filename = duk_get_string_notsymbol(thr, -1); filename = filename ? filename : ""; DUK_ASSERT(funcname != NULL); DUK_ASSERT(filename != NULL); - h_func = duk_get_hobject(thr, -4); /* NULL for lightfunc */ + h_func = duk_get_hobject(thr, -4); /* NULL for lightfunc */ if (h_func == NULL) { - duk_push_sprintf(thr, "at %s light%s%s%s%s%s", - (const char *) funcname, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s light%s%s%s%s%s", + (const char *) funcname, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } else if (DUK_HOBJECT_HAS_NATFUNC(h_func)) { - duk_push_sprintf(thr, "at %s (%s) native%s%s%s%s%s", - (const char *) funcname, - (const char *) filename, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s (%s) native%s%s%s%s%s", + (const char *) funcname, + (const char *) filename, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } else { - duk_push_sprintf(thr, "at %s (%s:%lu)%s%s%s%s%s", - (const char *) funcname, - (const char *) filename, - (unsigned long) line, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s (%s:%lu)%s%s%s%s%s", + (const char *) funcname, + (const char *) filename, + (unsigned long) line, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } - duk_replace(thr, -5); /* ... v1 v2 name filename str -> ... str v2 name filename */ - duk_pop_3(thr); /* -> ... str */ + duk_replace(thr, -5); /* ... v1 v2 name filename str -> ... str v2 name filename */ + duk_pop_3(thr); /* -> ... str */ } else if (t == DUK_TYPE_STRING) { const char *str_file; @@ -265,10 +271,12 @@ * safety issues. */ str_file = (const char *) duk_get_string(thr, -2); - duk_push_sprintf(thr, "at anon (%s:%ld) internal", - (const char *) (str_file ? str_file : "null"), (long) pc); - duk_replace(thr, -3); /* ... v1 v2 str -> ... str v2 */ - duk_pop(thr); /* -> ... str */ + duk_push_sprintf(thr, + "at anon (%s:%ld) internal", + (const char *) (str_file ? str_file : "null"), + (long) pc); + duk_replace(thr, -3); /* ... v1 v2 str -> ... str v2 */ + duk_pop(thr); /* -> ... str */ } else { /* unknown, ignore */ duk_pop_2(thr); @@ -315,7 +323,7 @@ return duk__error_getter_helper(thr, DUK__OUTPUT_TYPE_LINENUMBER); } -#else /* DUK_USE_TRACEBACKS */ +#else /* DUK_USE_TRACEBACKS */ /* * Traceback handling when tracebacks disabled. @@ -346,7 +354,7 @@ return 0; } -#endif /* DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_TRACEBACKS */ DUK_LOCAL duk_ret_t duk__error_setter_helper(duk_hthread *thr, duk_small_uint_t stridx_key) { /* Attempt to write 'stack', 'fileName', 'lineNumber' works as if @@ -356,7 +364,7 @@ * See https://github.com/svaarala/duktape/issues/387. */ - DUK_ASSERT_TOP(thr, 1); /* fixed arg count: value */ + DUK_ASSERT_TOP(thr, 1); /* fixed arg count: value */ duk_push_this(thr); duk_push_hstring_stridx(thr, stridx_key); @@ -364,13 +372,13 @@ /* ... obj key value */ - DUK_DD(DUK_DDPRINT("error setter: %!T %!T %!T", - duk_get_tval(thr, -3), duk_get_tval(thr, -2), duk_get_tval(thr, -1))); + DUK_DD(DUK_DDPRINT("error setter: %!T %!T %!T", duk_get_tval(thr, -3), duk_get_tval(thr, -2), duk_get_tval(thr, -1))); - duk_def_prop(thr, -3, DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE | - DUK_DEFPROP_HAVE_ENUMERABLE | /*not enumerable*/ - DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE); + duk_def_prop(thr, + -3, + DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE | + DUK_DEFPROP_HAVE_ENUMERABLE | /*not enumerable*/ + DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE); return 0; }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_function.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_function.c
Changed
@@ -25,7 +25,7 @@ nargs = duk_get_top(thr); for (i = 0; i < nargs; i++) { - duk_to_string(thr, i); /* Rejects Symbols during coercion. */ + duk_to_string(thr, i); /* Rejects Symbols during coercion. */ } if (nargs == 0) { @@ -35,7 +35,7 @@ /* XXX: cover this with the generic >1 case? */ duk_push_hstring_empty(thr); } else { - duk_insert(thr, 0); /* arg1 ... argN-1 body -> body arg1 ... argN-1 */ + duk_insert(thr, 0); /* arg1 ... argN-1 body -> body arg1 ... argN-1 */ duk_push_literal(thr, ","); duk_insert(thr, 1); duk_join(thr, nargs - 1); @@ -52,7 +52,7 @@ duk_dup_1(thr); duk_push_literal(thr, "){"); duk_dup_0(thr); - duk_push_literal(thr, "\n}"); /* Newline is important to handle trailing // comment. */ + duk_push_literal(thr, "\n}"); /* Newline is important to handle trailing // comment. */ duk_concat(thr, 5); /* body formals source */ @@ -62,8 +62,8 @@ /* strictness is not inherited, intentional */ comp_flags = DUK_COMPILE_FUNCEXPR; - duk_push_hstring_stridx(thr, DUK_STRIDX_COMPILE); /* XXX: copy from caller? */ /* XXX: ignored now */ - h_sourcecode = duk_require_hstring(thr, -2); /* no symbol check needed; -2 is concat'd code */ + duk_push_hstring_stridx(thr, DUK_STRIDX_COMPILE); /* XXX: copy from caller? */ /* XXX: ignored now */ + h_sourcecode = duk_require_hstring(thr, -2); /* no symbol check needed; -2 is concat'd code */ duk_js_compile(thr, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_sourcecode), (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sourcecode), @@ -92,7 +92,7 @@ return 1; } -#endif /* DUK_USE_FUNCTION_BUILTIN */ +#endif /* DUK_USE_FUNCTION_BUILTIN */ #if defined(DUK_USE_FUNCTION_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_function_prototype_to_string(duk_hthread *thr) { @@ -158,7 +158,7 @@ return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } #endif @@ -200,7 +200,7 @@ */ DUK_INTERNAL duk_ret_t duk_bi_function_prototype_bind(duk_hthread *thr) { duk_hboundfunc *h_bound; - duk_idx_t nargs; /* bound args, not counting 'this' binding */ + duk_idx_t nargs; /* bound args, not counting 'this' binding */ duk_idx_t bound_nargs; duk_int_t bound_len; duk_tval *tv_prevbound; @@ -213,7 +213,7 @@ /* Vararg function, careful arg handling, e.g. thisArg may not * be present. */ - nargs = duk_get_top(thr) - 1; /* actual args, not counting 'this' binding */ + nargs = duk_get_top(thr) - 1; /* actual args, not counting 'this' binding */ if (nargs < 0) { nargs++; duk_push_undefined(thr); @@ -308,7 +308,7 @@ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) h_bound, bound_proto); } - DUK_TVAL_INCREF(thr, &h_bound->target); /* old values undefined, no decref needed */ + DUK_TVAL_INCREF(thr, &h_bound->target); /* old values undefined, no decref needed */ DUK_TVAL_INCREF(thr, &h_bound->this_binding); bound_nargs = n_prevbound + nargs; @@ -333,7 +333,7 @@ * For lightfuncs, simply read the virtual property. */ duk_get_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH); - bound_len = duk_get_int(thr, -1); /* ES2015: no coercion */ + bound_len = duk_get_int(thr, -1); /* ES2015: no coercion */ if (bound_len < nargs) { bound_len = 0; } else { @@ -347,8 +347,8 @@ tv_tmp = thr->valstack_top++; DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_tmp)); DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_tmp)); - DUK_TVAL_SET_U32(tv_tmp, (duk_uint32_t) bound_len); /* in-place update, fastint */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* attrs in E6 Section 9.2.4 */ + DUK_TVAL_SET_U32(tv_tmp, (duk_uint32_t) bound_len); /* in-place update, fastint */ + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* attrs in E6 Section 9.2.4 */ /* XXX: could these be virtual? */ /* Caller and arguments must use the same thrower, ThrowTypeError. */ @@ -356,7 +356,7 @@ duk_xdef_prop_stridx_thrower(thr, -1, DUK_STRIDX_LC_ARGUMENTS); /* Function name and fileName (non-standard). */ - duk_push_literal(thr, "bound "); /* ES2015 19.2.3.2. */ + duk_push_literal(thr, "bound "); /* ES2015 19.2.3.2. */ duk_get_prop_stridx(thr, -3, DUK_STRIDX_NAME); if (!duk_is_string_notsymbol(thr, -1)) { /* ES2015 has requirement to check that .name of target is a string @@ -377,7 +377,7 @@ return 1; } -#endif /* DUK_USE_FUNCTION_BUILTIN */ +#endif /* DUK_USE_FUNCTION_BUILTIN */ /* %NativeFunctionPrototype% .length getter. */ DUK_INTERNAL duk_ret_t duk_bi_native_function_length(duk_hthread *thr) { @@ -408,7 +408,7 @@ } return 1; - fail_type: +fail_type: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -437,7 +437,7 @@ } return 1; - fail_type: +fail_type: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -450,4 +450,4 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_global.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_global.c
Changed
@@ -16,73 +16,71 @@ /* Macros for creating and checking bitmasks for character encoding. * Bit number is a bit counterintuitive, but minimizes code size. */ -#define DUK__MKBITS(a,b,c,d,e,f,g,h) ((duk_uint8_t) ( \ - ((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | \ - ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7) \ - )) -#define DUK__CHECK_BITMASK(table,cp) ((table)(cp) >> 3 & (1 << ((cp) & 0x07))) +#define DUK__MKBITS(a, b, c, d, e, f, g, h) \ + ((duk_uint8_t) (((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7))) +#define DUK__CHECK_BITMASK(table, cp) ((table)(cp) >> 3 & (1 << ((cp) &0x07))) /* E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#' */ DUK_LOCAL const duk_uint8_t duk__encode_uriunescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 1, 0, 1, 1, 0, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 1, 0, 1, 1, 0, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.4: uriUnescaped */ DUK_LOCAL const duk_uint8_t duk__encode_uricomponent_unescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 1, 0, 0, 0, 0, 0, 1), DUK__MKBITS(1, 1, 1, 0, 0, 1, 1, 0), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 1, 0, 0, 0, 0, 0, 1), DUK__MKBITS(1, 1, 1, 0, 0, 1, 1, 0), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.1: uriReserved + '#' */ DUK_LOCAL const duk_uint8_t duk__decode_uri_reserved_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 1, 1, 0, 1, 0), DUK__MKBITS(0, 0, 0, 1, 1, 0, 0, 1), /* 0x20-0x2f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ - DUK__MKBITS(1, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 1, 1, 0, 1, 0), DUK__MKBITS(0, 0, 0, 1, 1, 0, 0, 1), /* 0x20-0x2f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ + DUK__MKBITS(1, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.2: empty */ DUK_LOCAL const duk_uint8_t duk__decode_uri_component_reserved_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x20-0x2f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x20-0x2f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ }; #if defined(DUK_USE_SECTION_B) /* E5.1 Section B.2.2, step 7. */ DUK_LOCAL const duk_uint8_t duk__escape_unescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 1, 1), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 0) /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 1, 1), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 0) /* 0x70-0x7f */ }; -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ typedef struct { duk_hthread *thr; @@ -123,7 +121,7 @@ tfm_ctx->h_str = duk_to_hstring(thr, 0); DUK_ASSERT(tfm_ctx->h_str != NULL); - DUK_BW_INIT_PUSHBUF(thr, &tfm_ctx->bw, DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str)); /* initial size guess */ + DUK_BW_INIT_PUSHBUF(thr, &tfm_ctx->bw, DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str)); /* initial size guess */ tfm_ctx->p_start = DUK_HSTRING_GET_DATA(tfm_ctx->h_str); tfm_ctx->p_end = tfm_ctx->p_start + DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str); @@ -136,7 +134,7 @@ DUK_BW_COMPACT(thr, &tfm_ctx->bw); - (void) duk_buffer_to_string(thr, -1); /* Safe if transform is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if transform is safe. */ return 1; } @@ -162,7 +160,11 @@ goto uri_error; } else if (cp >= 0xd800L && cp <= 0xdbffL) { /* Needs lookahead */ - if (duk_unicode_decode_xutf8(tfm_ctx->thr, &tfm_ctx->p, tfm_ctx->p_start, tfm_ctx->p_end, (duk_ucodepoint_t *) &cp2) == 0) { + if (duk_unicode_decode_xutf8(tfm_ctx->thr, + &tfm_ctx->p, + tfm_ctx->p_start, + tfm_ctx->p_end, + (duk_ucodepoint_t *) &cp2) == 0) { goto uri_error; } if (!(cp2 >= 0xdc00L && cp2 <= 0xdfffL)) { @@ -193,12 +195,12 @@ &tfm_ctx->bw, DUK_ASC_PERCENT, (duk_uint8_t) duk_uc_nybblest >> 4, - (duk_uint8_t) duk_uc_nybblest & 0x0f); + (duk_uint8_t) duk_uc_nybblest & 0x0f); } return; - uri_error: +uri_error: DUK_ERROR_URI(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -207,7 +209,7 @@ const duk_uint8_t *reserved_table = (const duk_uint8_t *) udata; duk_small_uint_t utf8_blen; duk_codepoint_t min_cp; - duk_small_int_t t; /* must be signed */ + duk_small_int_t t; /* must be signed */ duk_small_uint_t i; /* Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH, @@ -215,12 +217,12 @@ */ DUK_BW_ENSURE(tfm_ctx->thr, &tfm_ctx->bw, - (DUK_UNICODE_MAX_XUTF8_LENGTH >= 2 * DUK_UNICODE_MAX_CESU8_BMP_LENGTH ? - DUK_UNICODE_MAX_XUTF8_LENGTH : DUK_UNICODE_MAX_CESU8_BMP_LENGTH)); + (DUK_UNICODE_MAX_XUTF8_LENGTH >= 2 * DUK_UNICODE_MAX_CESU8_BMP_LENGTH ? DUK_UNICODE_MAX_XUTF8_LENGTH : + DUK_UNICODE_MAX_CESU8_BMP_LENGTH)); if (cp == (duk_codepoint_t) '%') { const duk_uint8_t *p = tfm_ctx->p; - duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ + duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ DUK_DDD(DUK_DDDPRINT("percent encoding, left=%ld", (long) left)); @@ -238,11 +240,7 @@ if (DUK__CHECK_BITMASK(reserved_table, t)) { /* decode '%xx' to '%xx' if decoded char in reserved set */ DUK_ASSERT(tfm_ctx->p - 1 >= tfm_ctx->p_start); - DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr, - &tfm_ctx->bw, - DUK_ASC_PERCENT, - p0, - p1); + DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr, &tfm_ctx->bw, DUK_ASC_PERCENT, p0, p1); } else { DUK_BW_WRITE_RAW_U8(tfm_ctx->thr, &tfm_ctx->bw, (duk_uint8_t) t); } @@ -293,7 +291,10 @@ /* p points to digit part ('%xy', p points to 'x') */ t = duk__decode_hex_escape(p, 2); DUK_DDD(DUK_DDDPRINT("i=%ld utf8_blen=%ld cp=%ld t=0x%02lx", - (long) i, (long) utf8_blen, (long) cp, (unsigned long) t)); + (long) i, + (long) utf8_blen, + (long) cp, + (unsigned long) t)); if (t < 0) { goto uri_error; } @@ -303,7 +304,7 @@ cp = (cp << 6) + (t & 0x3f); p += 3; } - p--; /* p overshoots */ + p--; /* p overshoots */ tfm_ctx->p = p; DUK_DDD(DUK_DDDPRINT("final cp=%ld, min_cp=%ld", (long) cp, (long) min_cp)); @@ -337,7 +338,7 @@ } return; - uri_error: +uri_error: DUK_ERROR_URI(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -378,7 +379,7 @@ return; - esc_error: +esc_error: DUK_ERROR_TYPE(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -390,14 +391,12 @@ if (cp == (duk_codepoint_t) '%') { const duk_uint8_t *p = tfm_ctx->p; - duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ + duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ - if (left >= 5 && p0 == 'u' && - ((t = duk__decode_hex_escape(p + 1, 4)) >= 0)) { + if (left >= 5 && p0 == 'u' && ((t = duk__decode_hex_escape(p + 1, 4)) >= 0)) { cp = (duk_codepoint_t) t; tfm_ctx->p += 5; - } else if (left >= 2 && - ((t = duk__decode_hex_escape(p, 2)) >= 0)) { + } else if (left >= 2 && ((t = duk__decode_hex_escape(p, 2)) >= 0)) { cp = (duk_codepoint_t) t; tfm_ctx->p += 2; } @@ -405,7 +404,7 @@ DUK_BW_WRITE_ENSURE_XUTF8(tfm_ctx->thr, &tfm_ctx->bw, cp); } -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ /* * Eval @@ -430,11 +429,11 @@ duk_int_t level = -2; duk_small_uint_t call_flags; - DUK_ASSERT(duk_get_top(thr) == 1 || duk_get_top(thr) == 2); /* 2 when called by debugger */ - DUK_ASSERT(thr->callstack_top >= 1); /* at least this function exists */ + DUK_ASSERT(duk_get_top(thr) == 1 || duk_get_top(thr) == 2); /* 2 when called by debugger */ + DUK_ASSERT(thr->callstack_top >= 1); /* at least this function exists */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT((thr->callstack_curr->flags & DUK_ACT_FLAG_DIRECT_EVAL) == 0 || /* indirect eval */ - (thr->callstack_top >= 2)); /* if direct eval, calling activation must exist */ + (thr->callstack_top >= 2)); /* if direct eval, calling activation must exist */ /* * callstack_top - 1 --> this function @@ -447,32 +446,31 @@ h = duk_get_hstring_notsymbol(thr, 0); if (!h) { /* Symbol must be returned as is, like any non-string values. */ - return 1; /* return arg as-is */ + return 1; /* return arg as-is */ } #if defined(DUK_USE_DEBUGGER_SUPPORT) /* NOTE: level is used only by the debugger and should never be present * for an ECMAScript eval(). */ - DUK_ASSERT(level == -2); /* by default, use caller's environment */ + DUK_ASSERT(level == -2); /* by default, use caller's environment */ if (duk_get_top(thr) >= 2 && duk_is_number(thr, 1)) { level = duk_get_int(thr, 1); } - DUK_ASSERT(level <= -2); /* This is guaranteed by debugger code. */ + DUK_ASSERT(level <= -2); /* This is guaranteed by debugger code. */ #endif /* source */ comp_flags = DUK_COMPILE_EVAL; - act_eval = thr->callstack_curr; /* this function */ + act_eval = thr->callstack_curr; /* this function */ DUK_ASSERT(act_eval != NULL); act_caller = duk_hthread_get_activation_for_level(thr, level); if (act_caller != NULL) { /* Have a calling activation, check for direct eval (otherwise * assume indirect eval. */ - if ((act_caller->flags & DUK_ACT_FLAG_STRICT) && - (act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL)) { + if ((act_caller->flags & DUK_ACT_FLAG_STRICT) && (act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL)) { /* Only direct eval inherits strictness from calling code * (E5.1 Section 10.1.1). */ @@ -482,11 +480,8 @@ DUK_ASSERT((act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL) == 0); } - duk_push_hstring_stridx(thr, DUK_STRIDX_INPUT); /* XXX: copy from caller? */ - duk_js_compile(thr, - (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), - (duk_size_t) DUK_HSTRING_GET_BYTELEN(h), - comp_flags); + duk_push_hstring_stridx(thr, DUK_STRIDX_INPUT); /* XXX: copy from caller? */ + duk_js_compile(thr, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), (duk_size_t) DUK_HSTRING_GET_BYTELEN(h), comp_flags); func = (duk_hcompfunc *) duk_known_hobject(thr, -1); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) func)); @@ -519,9 +514,9 @@ act_lex_env = act_caller->lex_env; - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); @@ -533,7 +528,7 @@ outer_lex_env = (duk_hobject *) new_env; outer_var_env = (duk_hobject *) new_env; - duk_insert(thr, 0); /* stash to bottom of value stack to keep new_env reachable for duration of eval */ + duk_insert(thr, 0); /* stash to bottom of value stack to keep new_env reachable for duration of eval */ /* compiler's responsibility */ DUK_ASSERT(DUK_HOBJECT_HAS_NEWENV((duk_hobject *) func)); @@ -569,7 +564,8 @@ duk_tval *tv; DUK_ASSERT(thr->callstack_top >= 2); DUK_ASSERT(act_caller != NULL); - tv = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act_caller->bottom_byteoff - sizeof(duk_tval)); /* this is just beneath bottom */ + tv = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act_caller->bottom_byteoff - + sizeof(duk_tval)); /* this is just beneath bottom */ DUK_ASSERT(tv >= thr->valstack); duk_push_tval(thr, tv); } @@ -608,19 +604,15 @@ duk_small_uint_t s2n_flags; DUK_ASSERT_TOP(thr, 2); - duk_to_string(thr, 0); /* Reject symbols. */ + duk_to_string(thr, 0); /* Reject symbols. */ radix = duk_to_int32(thr, 1); /* While parseInt() recognizes 0xdeadbeef, it doesn't recognize * ES2015 0o123 or 0b10001. */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_GARBAGE | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO | - DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_GARBAGE | DUK_S2N_FLAG_ALLOW_PLUS | DUK_S2N_FLAG_ALLOW_MINUS | + DUK_S2N_FLAG_ALLOW_LEADING_ZERO | DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT; /* Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT. * @@ -644,35 +636,28 @@ duk_numconv_parse(thr, (duk_small_int_t) radix, s2n_flags); return 1; - ret_nan: +ret_nan: duk_push_nan(thr); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ #if defined(DUK_USE_GLOBAL_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_global_object_parse_float(duk_hthread *thr) { duk_small_uint_t s2n_flags; DUK_ASSERT_TOP(thr, 1); - duk_to_string(thr, 0); /* Reject symbols. */ + duk_to_string(thr, 0); /* Reject symbols. */ /* XXX: check flags */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_GARBAGE | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_INF | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_GARBAGE | DUK_S2N_FLAG_ALLOW_PLUS | + DUK_S2N_FLAG_ALLOW_MINUS | DUK_S2N_FLAG_ALLOW_INF | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_LEADING_ZERO; duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ /* * Number checkers @@ -684,7 +669,7 @@ duk_push_boolean(thr, (duk_bool_t) DUK_ISNAN(d)); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ #if defined(DUK_USE_GLOBAL_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_global_object_is_finite(duk_hthread *thr) { @@ -692,7 +677,7 @@ duk_push_boolean(thr, (duk_bool_t) DUK_ISFINITE(d)); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ /* * URI handling @@ -704,7 +689,9 @@ } DUK_INTERNAL duk_ret_t duk_bi_global_object_decode_uri_component(duk_hthread *thr) { - return duk__transform_helper(thr, duk__transform_callback_decode_uri, (const void *) duk__decode_uri_component_reserved_table); + return duk__transform_helper(thr, + duk__transform_callback_decode_uri, + (const void *) duk__decode_uri_component_reserved_table); } DUK_INTERNAL duk_ret_t duk_bi_global_object_encode_uri(duk_hthread *thr) { @@ -712,7 +699,9 @@ } DUK_INTERNAL duk_ret_t duk_bi_global_object_encode_uri_component(duk_hthread *thr) { - return duk__transform_helper(thr, duk__transform_callback_encode_uri, (const void *) duk__encode_uricomponent_unescaped_table); + return duk__transform_helper(thr, + duk__transform_callback_encode_uri, + (const void *) duk__encode_uricomponent_unescaped_table); } #if defined(DUK_USE_SECTION_B) @@ -723,5 +712,5 @@ DUK_INTERNAL duk_ret_t duk_bi_global_object_unescape(duk_hthread *thr) { return duk__transform_helper(thr, duk__transform_callback_unescape, (const void *) NULL); } -#endif /* DUK_USE_SECTION_B */ -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_GLOBAL_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_json.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_json.c
Changed
@@ -22,11 +22,11 @@ * Local defines and forward declarations. */ -#define DUK__JSON_DECSTR_BUFSIZE 128 -#define DUK__JSON_DECSTR_CHUNKSIZE 64 -#define DUK__JSON_ENCSTR_CHUNKSIZE 64 +#define DUK__JSON_DECSTR_BUFSIZE 128 +#define DUK__JSON_DECSTR_CHUNKSIZE 64 +#define DUK__JSON_ENCSTR_CHUNKSIZE 64 #define DUK__JSON_STRINGIFY_BUFSIZE 128 -#define DUK__JSON_MAX_ESC_LEN 10 /* '\Udeadbeef' */ +#define DUK__JSON_MAX_ESC_LEN 10 /* '\Udeadbeef' */ DUK_LOCAL_DECL void duk__json_dec_syntax_error(duk_json_dec_ctx *js_ctx); DUK_LOCAL_DECL void duk__json_dec_eat_white(duk_json_dec_ctx *js_ctx); @@ -96,103 +96,88 @@ * 0xa0 ... 0xff: backslash + one char */ - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xe2, 0xf4, 0xee, 0x80, 0xe6, 0xf2, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x20, 0x21, 0xa2, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0xdc, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xe2, 0xf4, 0xee, 0x80, 0xe6, 0xf2, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x20, 0x21, 0xa2, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0xdc, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81 }; -#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ -DUK_LOCAL const duk_uint8_t duk__json_quotestr_esc14 = { - DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, - DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, - DUK_ASC_LC_B, DUK_ASC_LC_T, DUK_ASC_LC_N, DUK_ASC_NUL, - DUK_ASC_LC_F, DUK_ASC_LC_R -}; -#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +DUK_LOCAL const duk_uint8_t duk__json_quotestr_esc14 = { DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, + DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_LC_B, DUK_ASC_LC_T, + DUK_ASC_LC_N, DUK_ASC_NUL, DUK_ASC_LC_F, DUK_ASC_LC_R }; +#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ #if defined(DUK_USE_JSON_DECSTRING_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_decstr_lookup256 = { /* 0x00: slow path * other: as is */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x20, 0x21, 0x00, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x00, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x21, 0x00, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x00, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, + 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; -#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ +#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ #if defined(DUK_USE_JSON_EATWHITE_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_eatwhite_lookup256 = { /* 0x00: finish (non-white) * 0x01: continue */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ #if defined(DUK_USE_JSON_DECNUMBER_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_decnumber_lookup256 = { /* 0x00: finish (not part of number) * 0x01: continue */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ +#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ /* * Parsing implementation. @@ -212,8 +197,7 @@ * hidden, unfortunately, but we'll have an offset which * is often quite enough. */ - DUK_ERROR_FMT1(js_ctx->thr, DUK_ERR_SYNTAX_ERROR, DUK_STR_FMT_INVALID_JSON, - (long) (js_ctx->p - js_ctx->p_start)); + DUK_ERROR_FMT1(js_ctx->thr, DUK_ERR_SYNTAX_ERROR, DUK_STR_FMT_INVALID_JSON, (long) (js_ctx->p - js_ctx->p_start)); DUK_WO_NORETURN(return;); } @@ -230,18 +214,18 @@ /* This fast path is pretty marginal in practice. * XXX: candidate for removal. */ - DUK_ASSERT(duk__json_eatwhite_lookup0x00 == 0x00); /* end-of-input breaks */ + DUK_ASSERT(duk__json_eatwhite_lookup0x00 == 0x00); /* end-of-input breaks */ if (duk__json_eatwhite_lookupt == 0) { break; } -#else /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#else /* DUK_USE_JSON_EATWHITE_FASTPATH */ if (!(t == 0x20 || t == 0x0a || t == 0x0d || t == 0x09)) { /* NUL also comes here. Comparison order matters, 0x20 * is most common whitespace. */ break; } -#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ p++; } js_ctx->p = p; @@ -275,8 +259,7 @@ /* XXX: share helper from lexer; duk_lexer.c / hexval(). */ x = duk__json_dec_get(js_ctx); - DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%ld, n=%ld, res=%ld, x=%ld", - (long) i, (long) n, (long) res, (long) x)); + DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%ld, n=%ld, res=%ld, x=%ld", (long) i, (long) n, (long) res, (long) x)); /* x == 0x00 (EOF) causes syntax_error */ DUK_ASSERT(duk_hex_dectab0 == -1); @@ -292,7 +275,7 @@ DUK_DDD(DUK_DDDPRINT("final hex decoded value: %ld", (long) res)); return res; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); return 0; @@ -313,7 +296,7 @@ DUK_ASSERT(h != NULL); p = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h) + 1; - DUK_ASSERT(*(js_ctx->p - 1) == *(p - 1)); /* first character has been matched */ + DUK_ASSERT(*(js_ctx->p - 1) == *(p - 1)); /* first character has been matched */ for (;;) { x = *p; @@ -330,7 +313,7 @@ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -344,14 +327,27 @@ */ cp = (duk_uint_fast32_t) duk__json_dec_get(js_ctx); switch (cp) { - case DUK_ASC_BACKSLASH: break; - case DUK_ASC_DOUBLEQUOTE: break; - case DUK_ASC_SLASH: break; - case DUK_ASC_LC_T: cp = 0x09; break; - case DUK_ASC_LC_N: cp = 0x0a; break; - case DUK_ASC_LC_R: cp = 0x0d; break; - case DUK_ASC_LC_F: cp = 0x0c; break; - case DUK_ASC_LC_B: cp = 0x08; break; + case DUK_ASC_BACKSLASH: + break; + case DUK_ASC_DOUBLEQUOTE: + break; + case DUK_ASC_SLASH: + break; + case DUK_ASC_LC_T: + cp = 0x09; + break; + case DUK_ASC_LC_N: + cp = 0x0a; + break; + case DUK_ASC_LC_R: + cp = 0x0d; + break; + case DUK_ASC_LC_F: + cp = 0x0c; + break; + case DUK_ASC_LC_B: + cp = 0x08; + break; case DUK_ASC_LC_U: { cp = duk__json_dec_decode_hex_escape(js_ctx, 4); break; @@ -361,7 +357,7 @@ if (js_ctx->flag_ext_custom) { cp = duk__json_dec_decode_hex_escape(js_ctx, 8); } else { - return 1; /* syntax error */ + return 1; /* syntax error */ } break; } @@ -369,14 +365,14 @@ if (js_ctx->flag_ext_custom) { cp = duk__json_dec_decode_hex_escape(js_ctx, 2); } else { - return 1; /* syntax error */ + return 1; /* syntax error */ } break; } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ default: /* catches EOF (0x00) */ - return 1; /* syntax error */ + return 1; /* syntax error */ } DUK_RAW_WRITEINC_XUTF8(*ext_p, cp); @@ -418,7 +414,7 @@ /* Ensure space for 1:1 output plus one escape. */ q = DUK_BW_ENSURE_RAW(js_ctx->thr, bw, safe + DUK_UNICODE_MAX_XUTF8_LENGTH, q); - p = js_ctx->p; /* temp copy, write back for next loop */ + p = js_ctx->p; /* temp copy, write back for next loop */ for (;;) { if (safe == 0) { js_ctx->p = p; @@ -453,8 +449,8 @@ } } } - found_quote: -#else /* DUK_USE_JSON_DECSTRING_FASTPATH */ +found_quote: +#else /* DUK_USE_JSON_DECSTRING_FASTPATH */ for (;;) { duk_uint8_t x; @@ -475,16 +471,16 @@ *q++ = (duk_uint8_t) x; } } -#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ +#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ DUK_BW_SETPTR_AND_COMPACT(js_ctx->thr, bw, q); - (void) duk_buffer_to_string(thr, -1); /* Safe if input string is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if input string is safe. */ /* ... str */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -500,7 +496,7 @@ /* Caller has already eaten the first char so backtrack one byte. */ - js_ctx->p--; /* safe */ + js_ctx->p--; /* safe */ p = js_ctx->p; /* Here again we parse bytes, and non-ASCII UTF-8 will cause end of @@ -532,7 +528,7 @@ /* ... str */ } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) DUK_LOCAL void duk__json_dec_pointer(duk_json_dec_ctx *js_ctx) { @@ -575,17 +571,17 @@ voidptr = NULL; (void) DUK_SSCANF((const char *) js_ctx->p, DUK_STR_FMT_PTR, &voidptr); duk_push_pointer(thr, voidptr); - js_ctx->p = p + 1; /* skip ')' */ + js_ctx->p = p + 1; /* skip ')' */ /* ... ptr */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) DUK_LOCAL void duk__json_dec_buffer(duk_json_dec_ctx *js_ctx) { @@ -633,17 +629,17 @@ duk_memcpy((void *) buf, (const void *) js_ctx->p, src_len); duk_hex_decode(thr, -1); - js_ctx->p = p + 1; /* skip '|' */ + js_ctx->p = p + 1; /* skip '|' */ /* ... buf */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ /* Parse a number, other than NaN or +/- Infinity */ DUK_LOCAL void duk__json_dec_number(duk_json_dec_ctx *js_ctx) { @@ -666,47 +662,45 @@ x = *p; DUK_DDD(DUK_DDDPRINT("parse_number: p_start=%p, p=%p, p_end=%p, x=%ld", - (const void *) p_start, (const void *) p, - (const void *) js_ctx->p_end, (long) x)); + (const void *) p_start, + (const void *) p, + (const void *) js_ctx->p_end, + (long) x)); #if defined(DUK_USE_JSON_DECNUMBER_FASTPATH) /* This fast path is pretty marginal in practice. * XXX: candidate for removal. */ - DUK_ASSERT(duk__json_decnumber_lookup0x00 == 0x00); /* end-of-input breaks */ + DUK_ASSERT(duk__json_decnumber_lookup0x00 == 0x00); /* end-of-input breaks */ if (duk__json_decnumber_lookupx == 0) { break; } -#else /* DUK_USE_JSON_DECNUMBER_FASTPATH */ +#else /* DUK_USE_JSON_DECNUMBER_FASTPATH */ if (!((x >= DUK_ASC_0 && x <= DUK_ASC_9) || - (x == DUK_ASC_PERIOD || x == DUK_ASC_LC_E || - x == DUK_ASC_UC_E || x == DUK_ASC_MINUS || x == DUK_ASC_PLUS))) { + (x == DUK_ASC_PERIOD || x == DUK_ASC_LC_E || x == DUK_ASC_UC_E || x == DUK_ASC_MINUS || x == DUK_ASC_PLUS))) { /* Plus sign must be accepted for positive exponents * (e.g. '1.5e+2'). This clause catches NULs. */ break; } -#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ - p++; /* safe, because matched (NUL causes a break) */ +#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ + p++; /* safe, because matched (NUL causes a break) */ } js_ctx->p = p; DUK_ASSERT(js_ctx->p > p_start); duk_push_lstring(thr, (const char *) p_start, (duk_size_t) (p - p_start)); - s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_MINUS | /* but don't allow leading plus */ + s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_MINUS | /* but don't allow leading plus */ DUK_S2N_FLAG_ALLOW_FRAC; - DUK_DDD(DUK_DDDPRINT("parse_number: string before parsing: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_number: string before parsing: %!T", (duk_tval *) duk_get_tval(thr, -1))); duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); if (duk_is_nan(thr, -1)) { duk__json_dec_syntax_error(js_ctx); } DUK_ASSERT(duk_is_number(thr, -1)); - DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T", (duk_tval *) duk_get_tval(thr, -1))); /* ... num */ } @@ -719,7 +713,7 @@ duk_native_stack_check(thr); - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_ERROR_RANGE(thr, DUK_STR_DEC_RECLIMIT); @@ -738,7 +732,7 @@ DUK_LOCAL void duk__json_dec_object(duk_json_dec_ctx *js_ctx) { duk_hthread *thr = js_ctx->thr; - duk_int_t key_count; /* XXX: a "first" flag would suffice */ + duk_int_t key_count; /* XXX: a "first" flag would suffice */ duk_uint8_t x; DUK_DDD(DUK_DDDPRINT("parse_object")); @@ -755,7 +749,8 @@ DUK_DDD(DUK_DDDPRINT("parse_object: obj=%!T, x=%ld, key_count=%ld", (duk_tval *) duk_get_tval(thr, -1), - (long) x, (long) key_count)); + (long) x, + (long) key_count)); /* handle comma and closing brace */ @@ -780,8 +775,7 @@ if (x == DUK_ASC_DOUBLEQUOTE) { duk__json_dec_string(js_ctx); #if defined(DUK_USE_JX) - } else if (js_ctx->flag_ext_custom && - duk_unicode_is_identifier_start((duk_codepoint_t) x)) { + } else if (js_ctx->flag_ext_custom && duk_unicode_is_identifier_start((duk_codepoint_t) x)) { duk__json_dec_plain_string(js_ctx); #endif } else { @@ -808,13 +802,12 @@ /* ... obj */ - DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_dec_objarr_exit(js_ctx); return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -838,7 +831,8 @@ DUK_DDD(DUK_DDDPRINT("parse_array: arr=%!T, x=%ld, arr_idx=%ld", (duk_tval *) duk_get_tval(thr, -1), - (long) x, (long) arr_idx)); + (long) x, + (long) arr_idx)); /* handle comma and closing bracket */ @@ -852,7 +846,7 @@ /* accept anything, expect first value (EOF will be * caught by duk__json_dec_value() below. */ - js_ctx->p--; /* backtrack (safe) */ + js_ctx->p--; /* backtrack (safe) */ } else { /* catches EOF (NUL) and initial comma */ goto syntax_error; @@ -876,13 +870,12 @@ /* ... arr */ - DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_dec_objarr_exit(js_ctx); return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -902,14 +895,14 @@ } else if ((x >= DUK_ASC_0 && x <= DUK_ASC_9) || (x == DUK_ASC_MINUS)) { #if defined(DUK_USE_JX) if (js_ctx->flag_ext_custom && x == DUK_ASC_MINUS && duk__json_dec_peek(js_ctx) == DUK_ASC_UC_I) { - duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY); /* "-Infinity", '-' has been eaten */ + duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY); /* "-Infinity", '-' has been eaten */ duk_push_number(thr, -DUK_DOUBLE_INFINITY); } else { #else - { /* unconditional block */ + { /* unconditional block */ #endif /* We already ate 'x', so backup one byte. */ - js_ctx->p--; /* safe */ + js_ctx->p--; /* safe */ duk__json_dec_number(js_ctx); } } else if (x == DUK_ASC_LC_T) { @@ -950,7 +943,7 @@ /* ... val */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -973,7 +966,7 @@ (duk_tval *) duk_get_tval(thr, -1))); duk_dup_top(thr); - duk_get_prop(thr, -3); /* -> ... holder name val */ + duk_get_prop(thr, -3); /* -> ... holder name val */ h = duk_get_hobject(thr, -1); if (h != NULL) { @@ -983,13 +976,17 @@ /* ... holder name val */ DUK_DDD(DUK_DDDPRINT("walk: array, top=%ld, i=%ld, arr_len=%ld, holder=%!T, name=%!T, val=%!T", - (long) duk_get_top(thr), (long) i, (long) arr_len, - (duk_tval *) duk_get_tval(thr, -3), (duk_tval *) duk_get_tval(thr, -2), + (long) duk_get_top(thr), + (long) i, + (long) arr_len, + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_dup_top(thr); - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... holder name val val ToString(i) */ - duk__json_dec_reviver_walk(js_ctx); /* -> ... holder name val new_elem */ + (void) duk_push_uint_to_hstring(thr, + (duk_uint_t) i); /* -> ... holder name val val ToString(i) */ + duk__json_dec_reviver_walk(js_ctx); /* -> ... holder name val new_elem */ if (duk_is_undefined(thr, -1)) { duk_pop(thr); @@ -1007,9 +1004,12 @@ duk_enum(thr, -1, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); while (duk_next(thr, -1 /*enum_index*/, 0 /*get_value*/)) { DUK_DDD(DUK_DDDPRINT("walk: object, top=%ld, holder=%!T, name=%!T, val=%!T, enum=%!iT, obj_key=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -5), - (duk_tval *) duk_get_tval(thr, -4), (duk_tval *) duk_get_tval(thr, -3), - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, -5), + (duk_tval *) duk_get_tval(thr, -4), + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); /* ... holder name val enum obj_key */ duk_dup_m3(thr); @@ -1035,34 +1035,33 @@ duk_put_prop(thr, -4); } } - duk_pop(thr); /* pop enum */ + duk_pop(thr); /* pop enum */ } } /* ... holder name val */ duk_dup(thr, js_ctx->idx_reviver); - duk_insert(thr, -4); /* -> ... reviver holder name val */ - duk_call_method(thr, 2); /* -> ... res */ + duk_insert(thr, -4); /* -> ... reviver holder name val */ + duk_call_method(thr, 2); /* -> ... res */ duk__json_dec_objarr_exit(js_ctx); - DUK_DDD(DUK_DDDPRINT("walk: top=%ld, result=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("walk: top=%ld, result=%!T", (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -1))); } /* * Stringify implementation. */ -#define DUK__EMIT_1(js_ctx,ch) duk__emit_1((js_ctx), (duk_uint_fast8_t) (ch)) -#define DUK__EMIT_2(js_ctx,ch1,ch2) duk__emit_2((js_ctx), (duk_uint_fast8_t) (ch1), (duk_uint_fast8_t) (ch2)) -#define DUK__EMIT_HSTR(js_ctx,h) duk__emit_hstring((js_ctx), (h)) +#define DUK__EMIT_1(js_ctx, ch) duk__emit_1((js_ctx), (duk_uint_fast8_t) (ch)) +#define DUK__EMIT_2(js_ctx, ch1, ch2) duk__emit_2((js_ctx), (duk_uint_fast8_t) (ch1), (duk_uint_fast8_t) (ch2)) +#define DUK__EMIT_HSTR(js_ctx, h) duk__emit_hstring((js_ctx), (h)) #if defined(DUK_USE_FASTINT) || defined(DUK_USE_JX) || defined(DUK_USE_JC) -#define DUK__EMIT_CSTR(js_ctx,p) duk__emit_cstring((js_ctx), (p)) +#define DUK__EMIT_CSTR(js_ctx, p) duk__emit_cstring((js_ctx), (p)) #endif -#define DUK__EMIT_STRIDX(js_ctx,i) duk__emit_stridx((js_ctx), (i)) -#define DUK__UNEMIT_1(js_ctx) duk__unemit_1((js_ctx)) +#define DUK__EMIT_STRIDX(js_ctx, i) duk__emit_stridx((js_ctx), (i)) +#define DUK__UNEMIT_1(js_ctx) duk__unemit_1((js_ctx)) DUK_LOCAL void duk__emit_1(duk_json_enc_ctx *js_ctx, duk_uint_fast8_t ch) { DUK_BW_WRITE_ENSURE_U8(js_ctx->thr, &js_ctx->bw, ch); @@ -1097,10 +1096,8 @@ DUK_BW_ADD_PTR(js_ctx->thr, &js_ctx->bw, -1); } -#define DUK__MKESC(nybbles,esc1,esc2) \ - (((duk_uint_fast32_t) (nybbles)) << 16) | \ - (((duk_uint_fast32_t) (esc1)) << 8) | \ - ((duk_uint_fast32_t) (esc2)) +#define DUK__MKESC(nybbles, esc1, esc2) \ + (((duk_uint_fast32_t) (nybbles)) << 16) | (((duk_uint_fast32_t) (esc1)) << 8) | ((duk_uint_fast32_t) (esc2)) DUK_LOCAL duk_uint8_t *duk__emit_esc_auto_fast(duk_json_enc_ctx *js_ctx, duk_uint_fast32_t cp, duk_uint8_t *q) { duk_uint_fast32_t tmp; @@ -1125,7 +1122,7 @@ } } else #endif - if (DUK_LIKELY(cp < 0x10000UL)) { + if (DUK_LIKELY(cp < 0x10000UL)) { tmp = DUK__MKESC(4, DUK_ASC_BACKSLASH, DUK_ASC_LC_U); } else { #if defined(DUK_USE_JX) @@ -1157,7 +1154,7 @@ } DUK_LOCAL void duk__json_enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k) { - const duk_int8_t *p, *p_start, *p_end; /* Note: intentionally signed. */ + const duk_int8_t *p, *p_start, *p_end; /* Note: intentionally signed. */ duk_size_t k_len; duk_codepoint_t cp; @@ -1198,7 +1195,7 @@ return; } - quote_normally: +quote_normally: duk__json_enc_quote_string(js_ctx, k); } @@ -1211,7 +1208,7 @@ duk_hthread *thr = js_ctx->thr; const duk_uint8_t *p, *p_start, *p_end, *p_now, *p_tmp; duk_uint8_t *q; - duk_ucodepoint_t cp; /* typed for duk_unicode_decode_xutf8() */ + duk_ucodepoint_t cp; /* typed for duk_unicode_decode_xutf8() */ DUK_DDD(DUK_DDDPRINT("duk__json_enc_quote_string: h_str=%!O", (duk_heaphdr *) h_str)); @@ -1230,8 +1227,7 @@ duk_size_t left, now, space; left = (duk_size_t) (p_end - p); - now = (left > DUK__JSON_ENCSTR_CHUNKSIZE ? - DUK__JSON_ENCSTR_CHUNKSIZE : left); + now = (left > DUK__JSON_ENCSTR_CHUNKSIZE ? DUK__JSON_ENCSTR_CHUNKSIZE : left); /* Maximum expansion per input byte is 6: * - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6). @@ -1267,7 +1263,7 @@ p--; /* slow path is shared */ -#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ cp = *p; if (DUK_LIKELY(cp <= 0x7f)) { @@ -1298,7 +1294,7 @@ } } else { /* slow path is shared */ -#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ /* slow path decode */ @@ -1374,11 +1370,10 @@ /* Negative zero needs special handling in JX/JC because * it would otherwise serialize to '0', not '-0'. */ - if (DUK_UNLIKELY(c == DUK_FP_ZERO && s != 0 && - (js_ctx->flag_ext_custom_or_compatible))) { - duk_push_hstring_stridx(thr, DUK_STRIDX_MINUS_ZERO); /* '-0' */ + if (DUK_UNLIKELY(c == DUK_FP_ZERO && s != 0 && (js_ctx->flag_ext_custom_or_compatible))) { + duk_push_hstring_stridx(thr, DUK_STRIDX_MINUS_ZERO); /* '-0' */ } else -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ { n2s_flags = 0; /* ... number -> ... string */ @@ -1390,8 +1385,7 @@ } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (!(js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE))) { + if (!(js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE))) { stridx = DUK_STRIDX_LC_NULL; } else if (c == DUK_FP_NAN) { stridx = js_ctx->stridx_custom_nan; @@ -1490,7 +1484,7 @@ return q; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ DUK_LOCAL duk_uint8_t *duk__json_enc_buffer_data_hex(const duk_uint8_t *src, duk_size_t src_len, duk_uint8_t *dst) { const duk_uint8_t *p; const duk_uint8_t *p_end; @@ -1508,7 +1502,7 @@ return q; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ DUK_LOCAL void duk__json_enc_buffer_data(duk_json_enc_ctx *js_ctx, duk_uint8_t *buf_data, duk_size_t buf_len) { duk_hthread *thr; @@ -1517,7 +1511,7 @@ thr = js_ctx->thr; - DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ + DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ DUK_ASSERT(js_ctx->flag_ext_custom_or_compatible); /* Buffer values are encoded in (lowercase) hex to make the @@ -1533,7 +1527,7 @@ /* Note: space must cater for both JX and JC. */ space = 9 + buf_len * 2 + 2; DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7ffffffeUL); - DUK_ASSERT((space - 2) / 2 >= buf_len); /* overflow not possible, buffer limits */ + DUK_ASSERT((space - 2) / 2 >= buf_len); /* overflow not possible, buffer limits */ q = DUK_BW_ENSURE_GETPTR(thr, &js_ctx->bw, space); #if defined(DUK_USE_JX) && defined(DUK_USE_JC) @@ -1553,7 +1547,7 @@ #if defined(DUK_USE_JC) { DUK_ASSERT(js_ctx->flag_ext_compatible); - duk_memcpy((void *) q, (const void *) "{\"_buf\":\"", 9); /* len: 9 */ + duk_memcpy((void *) q, (const void *) "{\"_buf\":\"", 9); /* len: 9 */ q += 9; q = duk__json_enc_buffer_data_hex(buf_data, buf_len, q); *q++ = DUK_ASC_DOUBLEQUOTE; @@ -1566,10 +1560,10 @@ DUK_LOCAL void duk__json_enc_buffer_jx_jc(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) { duk__json_enc_buffer_data(js_ctx, - (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h), - (duk_size_t) DUK_HBUFFER_GET_SIZE(h)); + (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h), + (duk_size_t) DUK_HBUFFER_GET_SIZE(h)); } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) DUK_LOCAL void duk__json_enc_buffer_json_fastpath(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) { @@ -1609,21 +1603,21 @@ } DUK_BW_SET_PTR(js_ctx->thr, &js_ctx->bw, q); } - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth); } DUK__EMIT_1(js_ctx, DUK_ASC_RCURLY); } -#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ +#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) DUK_LOCAL void duk__json_enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr) { - char buf64; /* XXX: how to figure correct size? */ + char buf64; /* XXX: how to figure correct size? */ const char *fmt; - DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ + DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ DUK_ASSERT(js_ctx->flag_ext_custom_or_compatible); duk_memzero(buf, sizeof(buf)); @@ -1650,10 +1644,10 @@ #endif /* When ptr == NULL, the format argument is unused. */ - DUK_SNPRINTF(buf, sizeof(buf) - 1, fmt, ptr); /* must not truncate */ + DUK_SNPRINTF(buf, sizeof(buf) - 1, fmt, ptr); /* must not truncate */ DUK__EMIT_CSTR(js_ctx, buf); } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) #if defined(DUK_USE_JX) || defined(DUK_USE_JC) @@ -1665,12 +1659,12 @@ } else { /* Handle both full and partial slice (as long as covered). */ duk__json_enc_buffer_data(js_ctx, - (duk_uint8_t *) DUK_HBUFOBJ_GET_SLICE_BASE(js_ctx->thr->heap, h_bufobj), - (duk_size_t) h_bufobj->length); + (duk_uint8_t *) DUK_HBUFOBJ_GET_SLICE_BASE(js_ctx->thr->heap, h_bufobj), + (duk_size_t) h_bufobj->length); } } -#endif /* DUK_USE_JX || DUK_USE_JC */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Indent helper. Calling code relies on js_ctx->recursion_depth also being * directly related to indent depth. @@ -1678,24 +1672,24 @@ #if defined(DUK_USE_PREFER_SIZE) DUK_LOCAL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) { DUK_ASSERT(js_ctx->h_gap != NULL); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ DUK__EMIT_1(js_ctx, 0x0a); while (depth-- > 0) { DUK__EMIT_HSTR(js_ctx, js_ctx->h_gap); } } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_LOCAL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) { const duk_uint8_t *gap_data; duk_size_t gap_len; - duk_size_t avail_bytes; /* bytes of indent available for copying */ - duk_size_t need_bytes; /* bytes of indent still needed */ + duk_size_t avail_bytes; /* bytes of indent available for copying */ + duk_size_t need_bytes; /* bytes of indent still needed */ duk_uint8_t *p_start; duk_uint8_t *p; DUK_ASSERT(js_ctx->h_gap != NULL); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ DUK__EMIT_1(js_ctx, 0x0a); if (DUK_UNLIKELY(depth == 0)) { @@ -1729,14 +1723,14 @@ avail_bytes <<= 1; } - DUK_ASSERT(need_bytes < avail_bytes); /* need_bytes may be zero */ + DUK_ASSERT(need_bytes < avail_bytes); /* need_bytes may be zero */ duk_memcpy((void *) p, (const void *) p_start, (size_t) need_bytes); p += need_bytes; /*avail_bytes += need_bytes*/ DUK_BW_SET_PTR(js_ctx->thr, &js_ctx->bw, p); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Shared entry handling for object/array serialization. */ DUK_LOCAL void duk__json_enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top) { @@ -1753,7 +1747,7 @@ * with overflow in a loop check object. */ - h_target = duk_known_hobject(thr, -1); /* object or array */ + h_target = duk_known_hobject(thr, -1); /* object or array */ n = js_ctx->recursion_depth; if (DUK_UNLIKELY(n > DUK_JSON_ENC_LOOPARRAY)) { @@ -1770,18 +1764,18 @@ js_ctx->visitingjs_ctx->recursion_depth = h_target; } else { duk_push_sprintf(thr, DUK_STR_FMT_PTR, (void *) h_target); - duk_dup_top(thr); /* -> ... voidp voidp */ + duk_dup_top(thr); /* -> ... voidp voidp */ if (duk_has_prop(thr, js_ctx->idx_loop)) { DUK_ERROR_TYPE(thr, DUK_STR_CYCLIC_INPUT); DUK_WO_NORETURN(return;); } - duk_push_true(thr); /* -> ... voidp true */ - duk_put_prop(thr, js_ctx->idx_loop); /* -> ... */ + duk_push_true(thr); /* -> ... voidp true */ + duk_put_prop(thr, js_ctx->idx_loop); /* -> ... */ } /* C recursion check. */ - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_ERROR_RANGE(thr, DUK_STR_ENC_RECLIMIT); @@ -1790,7 +1784,8 @@ js_ctx->recursion_depth++; DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%ld, loop=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); } /* Shared exit handling for object/array serialization. */ @@ -1806,20 +1801,21 @@ /* Loop check. */ - h_target = duk_known_hobject(thr, *entry_top - 1); /* original target at entry_top - 1 */ + h_target = duk_known_hobject(thr, *entry_top - 1); /* original target at entry_top - 1 */ if (js_ctx->recursion_depth < DUK_JSON_ENC_LOOPARRAY) { /* Previous entry was inside visited, nothing to do. */ } else { duk_push_sprintf(thr, DUK_STR_FMT_PTR, (void *) h_target); - duk_del_prop(thr, js_ctx->idx_loop); /* -> ... */ + duk_del_prop(thr, js_ctx->idx_loop); /* -> ... */ } /* Restore stack top after unbalanced code paths. */ duk_set_top(thr, *entry_top); DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%ld, loop=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); } /* The JO(value) operation: encode object. @@ -1847,13 +1843,14 @@ } else { /* XXX: would be nice to enumerate an object at specified index */ duk_dup(thr, idx_obj); - (void) duk_hobject_get_enumerated_keys(thr, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); /* ... target -> ... target keys */ + (void) duk_hobject_get_enumerated_keys( + thr, + DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); /* ... target -> ... target keys */ idx_keys = duk_require_normalize_index(thr, -1); /* leave stack unbalanced on purpose */ } - DUK_DDD(DUK_DDDPRINT("idx_keys=%ld, h_keys=%!T", - (long) idx_keys, (duk_tval *) duk_get_tval(thr, idx_keys))); + DUK_DDD(DUK_DDDPRINT("idx_keys=%ld, h_keys=%!T", (long) idx_keys, (duk_tval *) duk_get_tval(thr, idx_keys))); /* Steps 8-10 have been merged to avoid a "partial" variable. */ @@ -1868,7 +1865,7 @@ arr_len = (duk_uarridx_t) duk_get_length(thr, idx_keys); emitted = 0; for (i = 0; i < arr_len; i++) { - duk_get_prop_index(thr, idx_keys, i); /* -> ... key */ + duk_get_prop_index(thr, idx_keys, i); /* -> ... key */ DUK_DDD(DUK_DDDPRINT("object property loop: holder=%!T, key=%!T", (duk_tval *) duk_get_tval(thr, idx_obj), @@ -1876,7 +1873,7 @@ h_key = duk_known_hstring(thr, -1); DUK_ASSERT(h_key != NULL); - DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(h_key)); /* proplist filtering; enum options */ + DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(h_key)); /* proplist filtering; enum options */ prev_size = DUK_BW_GET_SIZE(js_ctx->thr, &js_ctx->bw); if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { @@ -1905,7 +1902,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -1929,8 +1926,7 @@ duk_bool_t emitted; duk_uarridx_t i, arr_len; - DUK_DDD(DUK_DDDPRINT("duk__json_enc_array: array=%!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("duk__json_enc_array: array=%!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_enc_objarr_entry(js_ctx, &entry_top); @@ -1945,14 +1941,15 @@ for (i = 0; i < arr_len; i++) { DUK_DDD(DUK_DDDPRINT("array entry loop: array=%!T, index=%ld, arr_len=%ld", (duk_tval *) duk_get_tval(thr, idx_arr), - (long) i, (long) arr_len)); + (long) i, + (long) arr_len)); if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth); } - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... key */ + (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... key */ /* ... key */ @@ -1971,7 +1968,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -1996,14 +1993,15 @@ duk_small_int_t c; DUK_DDD(DUK_DDDPRINT("duk__json_enc_value: idx_holder=%ld, holder=%!T, key=%!T", - (long) idx_holder, (duk_tval *) duk_get_tval(thr, idx_holder), + (long) idx_holder, + (duk_tval *) duk_get_tval(thr, idx_holder), (duk_tval *) duk_get_tval(thr, -1))); tv_holder = DUK_GET_TVAL_POSIDX(thr, idx_holder); DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv_holder)); tv_key = DUK_GET_TVAL_NEGIDX(thr, -1); DUK_ASSERT(DUK_TVAL_IS_STRING(tv_key)); - DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING(tv_key))); /* Caller responsible. */ + DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING(tv_key))); /* Caller responsible. */ (void) duk_hobject_getprop(thr, tv_holder, tv_key); /* -> ... key val */ @@ -2015,19 +2013,17 @@ * number won't invoke the .toJSON() method. However, lightfuncs and * plain buffers mimic objects so we check for their .toJSON() method. */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_JSON); - if (duk_is_callable(thr, -1)) { /* toJSON() can also be a lightfunc */ + if (duk_is_callable(thr, -1)) { /* toJSON() can also be a lightfunc */ DUK_DDD(DUK_DDDPRINT("value is object, has callable toJSON() -> call it")); /* XXX: duk_dup_unvalidated(thr, -2) etc. */ - duk_dup_m2(thr); /* -> ... key val toJSON val */ - duk_dup_m4(thr); /* -> ... key val toJSON val key */ - duk_call_method(thr, 1); /* -> ... key val val' */ - duk_remove_m2(thr); /* -> ... key val' */ + duk_dup_m2(thr); /* -> ... key val toJSON val */ + duk_dup_m4(thr); /* -> ... key val toJSON val key */ + duk_call_method(thr, 1); /* -> ... key val val' */ + duk_remove_m2(thr); /* -> ... key val' */ } else { - duk_pop(thr); /* -> ... key val */ + duk_pop(thr); /* -> ... key val */ } } @@ -2038,12 +2034,12 @@ if (js_ctx->h_replacer) { /* XXX: Here a "slice copy" would be useful. */ DUK_DDD(DUK_DDDPRINT("replacer is set, call replacer")); - duk_push_hobject(thr, js_ctx->h_replacer); /* -> ... key val replacer */ - duk_dup(thr, idx_holder); /* -> ... key val replacer holder */ - duk_dup_m4(thr); /* -> ... key val replacer holder key */ - duk_dup_m4(thr); /* -> ... key val replacer holder key val */ - duk_call_method(thr, 2); /* -> ... key val val' */ - duk_remove_m2(thr); /* -> ... key val' */ + duk_push_hobject(thr, js_ctx->h_replacer); /* -> ... key val replacer */ + duk_dup(thr, idx_holder); /* -> ... key val replacer holder */ + duk_dup_m4(thr); /* -> ... key val replacer holder key */ + duk_dup_m4(thr); /* -> ... key val replacer holder key val */ + duk_call_method(thr, 2); /* -> ... key val val' */ + duk_remove_m2(thr); /* -> ... key val' */ } /* ... key val */ @@ -2059,8 +2055,7 @@ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (DUK_HOBJECT_IS_BUFOBJ(h) && - js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { + if (DUK_HOBJECT_IS_BUFOBJ(h) && js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { /* With JX/JC a bufferobject gets serialized specially. */ duk_hbufobj *h_bufobj; h_bufobj = (duk_hbufobj *) h; @@ -2069,8 +2064,8 @@ goto pop2_emitted; } /* Otherwise bufferobjects get serialized as normal objects. */ -#endif /* JX || JC */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* JX || JC */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ c = (duk_small_int_t) DUK_HOBJECT_GET_CLASS_NUMBER(h); switch (c) { case DUK_HOBJECT_CLASS_NUMBER: { @@ -2110,8 +2105,7 @@ DUK_ASSERT(h != NULL); if (DUK_HOBJECT_IS_CALLABLE(h)) { #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE)) { + if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { /* We only get here when doing non-standard JSON encoding */ DUK_DDD(DUK_DDDPRINT("-> function allowed, serialize to custom format")); DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); @@ -2121,13 +2115,13 @@ DUK_DDD(DUK_DDDPRINT("-> will result in undefined (function)")); goto pop2_undef; } -#else /* DUK_USE_JX || DUK_USE_JC */ +#else /* DUK_USE_JX || DUK_USE_JC */ DUK_DDD(DUK_DDDPRINT("-> will result in undefined (function)")); goto pop2_undef; -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ } } - } /* end switch */ + } /* end switch */ } /* ... key val */ @@ -2154,8 +2148,7 @@ break; } case DUK_TAG_BOOLEAN: { - DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? - DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); + DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); break; } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) @@ -2164,7 +2157,7 @@ duk__json_enc_pointer(js_ctx, DUK_TVAL_GET_POINTER(tv)); break; } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ case DUK_TAG_STRING: { duk_hstring *h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); @@ -2243,14 +2236,14 @@ } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - pop2_emitted: +pop2_emitted: #endif duk_pop_2(thr); /* ... key val -> ... */ - return 1; /* emitted */ + return 1; /* emitted */ - pop2_undef: - duk_pop_2(thr); /* ... key val -> ... */ - return 0; /* not emitted */ +pop2_undef: + duk_pop_2(thr); /* ... key val -> ... */ + return 0; /* not emitted */ } /* E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4. */ @@ -2326,8 +2319,7 @@ break; } case DUK_TAG_BOOLEAN: { - DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? - DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); + DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); break; } case DUK_TAG_STRING: { @@ -2344,8 +2336,7 @@ duk_hobject *obj; duk_tval *tv_val; duk_bool_t emitted = 0; - duk_uint32_t c_bit, c_all, c_array, c_unbox, c_undef, - c_func, c_bufobj, c_object, c_abort; + duk_uint32_t c_bit, c_all, c_array, c_unbox, c_undef, c_func, c_bufobj, c_object, c_abort; /* For objects JSON.stringify() only looks for own, enumerable * properties which is nice for the fast path here. @@ -2378,7 +2369,7 @@ * it (though it's OK to abort the fast path). */ - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_DD(DUK_DDPRINT("fast path recursion limit")); @@ -2430,28 +2421,23 @@ if (js_ctx->flag_ext_custom_or_compatible) { c_all = DUK_HOBJECT_CMASK_ALL; c_array = DUK_HOBJECT_CMASK_ARRAY; - c_unbox = DUK_HOBJECT_CMASK_NUMBER | - DUK_HOBJECT_CMASK_STRING | - DUK_HOBJECT_CMASK_BOOLEAN | - DUK_HOBJECT_CMASK_POINTER; /* Symbols are not unboxed. */ + c_unbox = DUK_HOBJECT_CMASK_NUMBER | DUK_HOBJECT_CMASK_STRING | DUK_HOBJECT_CMASK_BOOLEAN | + DUK_HOBJECT_CMASK_POINTER; /* Symbols are not unboxed. */ c_func = DUK_HOBJECT_CMASK_FUNCTION; c_bufobj = DUK_HOBJECT_CMASK_ALL_BUFOBJS; c_undef = 0; c_abort = 0; c_object = c_all & ~(c_array | c_unbox | c_func | c_bufobj | c_undef | c_abort); - } - else + } else #endif { c_all = DUK_HOBJECT_CMASK_ALL; c_array = DUK_HOBJECT_CMASK_ARRAY; - c_unbox = DUK_HOBJECT_CMASK_NUMBER | - DUK_HOBJECT_CMASK_STRING | - DUK_HOBJECT_CMASK_BOOLEAN; /* Symbols are not unboxed. */ + c_unbox = DUK_HOBJECT_CMASK_NUMBER | DUK_HOBJECT_CMASK_STRING | + DUK_HOBJECT_CMASK_BOOLEAN; /* Symbols are not unboxed. */ c_func = 0; c_bufobj = 0; - c_undef = DUK_HOBJECT_CMASK_FUNCTION | - DUK_HOBJECT_CMASK_POINTER; + c_undef = DUK_HOBJECT_CMASK_FUNCTION | DUK_HOBJECT_CMASK_POINTER; /* As the fast path doesn't currently properly support * duk_hbufobj virtual properties, abort fast path if * we encounter them in plain JSON mode. @@ -2533,7 +2519,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -2603,14 +2589,14 @@ #endif /* fall through */ - elem_done: + elem_done: DUK__EMIT_1(js_ctx, DUK_ASC_COMMA); emitted = 1; } if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -2622,7 +2608,7 @@ * automatic unboxing. Rely on internal value being * sane (to avoid infinite recursion). */ - DUK_ASSERT((c_bit & DUK_HOBJECT_CMASK_SYMBOL) == 0); /* Symbols are not unboxed. */ + DUK_ASSERT((c_bit & DUK_HOBJECT_CMASK_SYMBOL) == 0); /* Symbols are not unboxed. */ #if 1 /* The code below is incorrect if .toString() or .valueOf() have @@ -2632,7 +2618,7 @@ * Unimplemented for now, abort fast path for boxed values. */ goto abort_fastpath; -#else /* disabled */ +#else /* disabled */ /* Disabled until fixed, see above. */ duk_tval *tv_internal; @@ -2640,16 +2626,14 @@ tv_internal = duk_hobject_get_internal_value_tval_ptr(js_ctx->thr->heap, obj); DUK_ASSERT(tv_internal != NULL); - DUK_ASSERT(DUK_TVAL_IS_STRING(tv_internal) || - DUK_TVAL_IS_NUMBER(tv_internal) || - DUK_TVAL_IS_BOOLEAN(tv_internal) || - DUK_TVAL_IS_POINTER(tv_internal)); + DUK_ASSERT(DUK_TVAL_IS_STRING(tv_internal) || DUK_TVAL_IS_NUMBER(tv_internal) || + DUK_TVAL_IS_BOOLEAN(tv_internal) || DUK_TVAL_IS_POINTER(tv_internal)); tv = tv_internal; DUK_ASSERT(js_ctx->recursion_depth > 0); - js_ctx->recursion_depth--; /* required to keep recursion depth correct */ + js_ctx->recursion_depth--; /* required to keep recursion depth correct */ goto restart_match; -#endif /* disabled */ +#endif /* disabled */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) } else if (c_bit & c_func) { DUK__EMIT_STRIDX(js_ctx, js_ctx->stridx_custom_function); @@ -2762,12 +2746,12 @@ #endif } } - return 1; /* not undefined */ + return 1; /* not undefined */ - emit_undefined: - return 0; /* value was undefined/unsupported */ +emit_undefined: + return 0; /* value was undefined/unsupported */ - abort_fastpath: +abort_fastpath: /* Error message doesn't matter: the error is ignored anyway. */ DUK_DD(DUK_DDPRINT("aborting fast path")); DUK_ERROR_INTERNAL(js_ctx->thr); @@ -2787,22 +2771,19 @@ tv = DUK_GET_TVAL_NEGIDX(thr, -1); if (duk__json_stringify_fast_value(js_ctx, tv) == 0) { DUK_DD(DUK_DDPRINT("top level value not supported, fail fast path")); - DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* Error message is ignored, so doesn't matter. */ + DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* Error message is ignored, so doesn't matter. */ } return 0; } -#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ +#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ /* * Top level wrappers */ DUK_INTERNAL -void duk_bi_json_parse_helper(duk_hthread *thr, - duk_idx_t idx_value, - duk_idx_t idx_reviver, - duk_small_uint_t flags) { +void duk_bi_json_parse_helper(duk_hthread *thr, duk_idx_t idx_value, duk_idx_t idx_reviver, duk_small_uint_t flags) { duk_json_dec_ctx js_ctx_alloc; duk_json_dec_ctx *js_ctx = &js_ctx_alloc; duk_hstring *h_text; @@ -2843,7 +2824,7 @@ js_ctx->flag_ext_custom_or_compatible = flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE); #endif - h_text = duk_to_hstring(thr, idx_value); /* coerce in-place; rejects Symbols */ + h_text = duk_to_hstring(thr, idx_value); /* coerce in-place; rejects Symbols */ DUK_ASSERT(h_text != NULL); /* JSON parsing code is allowed to read p_start,p_end: p_end is @@ -2852,11 +2833,10 @@ */ js_ctx->p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text); js_ctx->p = js_ctx->p_start; - js_ctx->p_end = ((const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text)) + - DUK_HSTRING_GET_BYTELEN(h_text); + js_ctx->p_end = ((const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text)) + DUK_HSTRING_GET_BYTELEN(h_text); DUK_ASSERT(*(js_ctx->p_end) == 0x00); - duk__json_dec_value(js_ctx); /* -> ... value */ + duk__json_dec_value(js_ctx); /* -> ... value */ DUK_ASSERT(js_ctx->recursion_depth == 0); /* Trailing whitespace has been eaten by duk__json_dec_value(), so if @@ -2868,27 +2848,26 @@ } if (duk_is_callable(thr, idx_reviver)) { - DUK_DDD(DUK_DDDPRINT("applying reviver: %!T", - (duk_tval *) duk_get_tval(thr, idx_reviver))); + DUK_DDD(DUK_DDDPRINT("applying reviver: %!T", (duk_tval *) duk_get_tval(thr, idx_reviver))); js_ctx->idx_reviver = idx_reviver; duk_push_object(thr); - duk_dup_m2(thr); /* -> ... val root val */ - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_EMPTY_STRING); /* default attrs ok */ - duk_push_hstring_stridx(thr, DUK_STRIDX_EMPTY_STRING); /* -> ... val root "" */ + duk_dup_m2(thr); /* -> ... val root val */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_EMPTY_STRING); /* default attrs ok */ + duk_push_hstring_stridx(thr, DUK_STRIDX_EMPTY_STRING); /* -> ... val root "" */ DUK_DDD(DUK_DDDPRINT("start reviver walk, root=%!T, name=%!T", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(js_ctx->recursion_depth == 0); - duk__json_dec_reviver_walk(js_ctx); /* ... val root "" -> ... val val' */ + duk__json_dec_reviver_walk(js_ctx); /* ... val root "" -> ... val val' */ DUK_ASSERT(js_ctx->recursion_depth == 0); - duk_remove_m2(thr); /* -> ... val' */ + duk_remove_m2(thr); /* -> ... val' */ } else { - DUK_DDD(DUK_DDDPRINT("reviver does not exist or is not callable: %!T", - (duk_tval *) duk_get_tval(thr, idx_reviver))); + DUK_DDD( + DUK_DDDPRINT("reviver does not exist or is not callable: %!T", (duk_tval *) duk_get_tval(thr, idx_reviver))); } /* Final result is at stack top. */ @@ -2962,7 +2941,7 @@ * combinations properly. */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_NULL; /* standard JSON; array gaps */ + js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_NULL; /* standard JSON; array gaps */ #if defined(DUK_USE_JX) if (flags & DUK_JSON_FLAG_EXT_CUSTOM) { js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_UNDEFINED; @@ -2970,41 +2949,35 @@ js_ctx->stridx_custom_neginf = DUK_STRIDX_MINUS_INFINITY; js_ctx->stridx_custom_posinf = DUK_STRIDX_INFINITY; js_ctx->stridx_custom_function = - (flags & DUK_JSON_FLAG_AVOID_KEY_QUOTES) ? - DUK_STRIDX_JSON_EXT_FUNCTION2 : - DUK_STRIDX_JSON_EXT_FUNCTION1; + (flags & DUK_JSON_FLAG_AVOID_KEY_QUOTES) ? DUK_STRIDX_JSON_EXT_FUNCTION2 : DUK_STRIDX_JSON_EXT_FUNCTION1; } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) && defined(DUK_USE_JC) else -#endif /* DUK_USE_JX && DUK_USE_JC */ +#endif /* DUK_USE_JX && DUK_USE_JC */ #if defined(DUK_USE_JC) - if (js_ctx->flags & DUK_JSON_FLAG_EXT_COMPATIBLE) { + if (js_ctx->flags & DUK_JSON_FLAG_EXT_COMPATIBLE) { js_ctx->stridx_custom_undefined = DUK_STRIDX_JSON_EXT_UNDEFINED; js_ctx->stridx_custom_nan = DUK_STRIDX_JSON_EXT_NAN; js_ctx->stridx_custom_neginf = DUK_STRIDX_JSON_EXT_NEGINF; js_ctx->stridx_custom_posinf = DUK_STRIDX_JSON_EXT_POSINF; js_ctx->stridx_custom_function = DUK_STRIDX_JSON_EXT_FUNCTION1; } -#endif /* DUK_USE_JC */ -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE)) { - DUK_ASSERT(js_ctx->mask_for_undefined == 0); /* already zero */ - } - else -#endif /* DUK_USE_JX || DUK_USE_JC */ + if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { + DUK_ASSERT(js_ctx->mask_for_undefined == 0); /* already zero */ + } else +#endif /* DUK_USE_JX || DUK_USE_JC */ { /* Plain buffer is treated like ArrayBuffer and serialized. * Lightfuncs are treated like objects, but JSON explicitly * skips serializing Function objects so we can just reject * lightfuncs here. */ - js_ctx->mask_for_undefined = DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_POINTER | - DUK_TYPE_MASK_LIGHTFUNC; + js_ctx->mask_for_undefined = DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_POINTER | DUK_TYPE_MASK_LIGHTFUNC; } DUK_BW_INIT_PUSHBUF(thr, &js_ctx->bw, DUK__JSON_STRINGIFY_BUFSIZE); @@ -3034,8 +3007,7 @@ js_ctx->idx_proplist = duk_push_bare_array(thr); - enum_flags = DUK_ENUM_ARRAY_INDICES_ONLY | - DUK_ENUM_SORT_ARRAY_INDICES; /* expensive flag */ + enum_flags = DUK_ENUM_ARRAY_INDICES_ONLY | DUK_ENUM_SORT_ARRAY_INDICES; /* expensive flag */ duk_enum(thr, idx_replacer, enum_flags); while (duk_next(thr, -1 /*enum_index*/, 1 /*get_value*/)) { /* ... proplist enum_obj key val */ @@ -3044,8 +3016,8 @@ DUK_DDD(DUK_DDDPRINT("proplist enum: key=%!T, val=%!T --> accept", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); - duk_to_string(thr, -1); /* extra coercion of strings is OK */ - duk_put_prop_index(thr, -4, plist_idx); /* -> ... proplist enum_obj key */ + duk_to_string(thr, -1); /* extra coercion of strings is OK */ + duk_put_prop_index(thr, -4, plist_idx); /* -> ... proplist enum_obj key */ plist_idx++; duk_pop(thr); } else { @@ -3054,8 +3026,8 @@ (duk_tval *) duk_get_tval(thr, -1))); duk_pop_2(thr); } - } - duk_pop(thr); /* pop enum */ + } + duk_pop(thr); /* pop enum */ /* ... proplist */ } @@ -3081,10 +3053,9 @@ duk_small_int_t nspace; /* spaces must be static to allow initializer with old compilers like BCC */ static const char spaces10 = { - DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, - DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, - DUK_ASC_SPACE, DUK_ASC_SPACE - }; /* XXX: helper */ + DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, + DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE + }; /* XXX: helper */ /* ToInteger() coercion; NaN -> 0, infinities are clamped to 0 and 10 */ nspace = (duk_small_int_t) duk_to_int_clamped(thr, idx_space, 0 /*minval*/, 10 /*maxval*/); @@ -3095,7 +3066,7 @@ DUK_ASSERT(js_ctx->h_gap != NULL); } else if (duk_is_string_notsymbol(thr, idx_space)) { duk_dup(thr, idx_space); - duk_substring(thr, -1, 0, 10); /* clamp to 10 chars */ + duk_substring(thr, -1, 0, 10); /* clamp to 10 chars */ js_ctx->h_gap = duk_known_hstring(thr, -1); } else { /* nop */ @@ -3119,8 +3090,8 @@ */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) - if (js_ctx->h_replacer == NULL && /* replacer is a mutation risk */ - js_ctx->idx_proplist == -1) { /* proplist is very rare */ + if (js_ctx->h_replacer == NULL && /* replacer is a mutation risk */ + js_ctx->idx_proplist == -1) { /* proplist is very rare */ duk_int_t pcall_rc; duk_small_uint_t prev_ms_base_flags; @@ -3145,10 +3116,9 @@ /* Must prevent finalizers which may have arbitrary side effects. */ prev_ms_base_flags = thr->heap->ms_base_flags; - thr->heap->ms_base_flags |= - DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact any objects. */ - thr->heap->pf_prevent_count++; /* Prevent finalizers. */ - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + thr->heap->ms_base_flags |= DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact any objects. */ + thr->heap->pf_prevent_count++; /* Prevent finalizers. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ pcall_rc = duk_safe_call(thr, duk__json_stringify_fast, (void *) js_ctx /*udata*/, 1 /*nargs*/, 0 /*nret*/); @@ -3199,7 +3169,7 @@ js_ctx->recursion_limit = DUK_USE_JSON_ENC_RECLIMIT; DUK_ASSERT(js_ctx->recursion_depth == 0); - if (DUK_UNLIKELY(duk__json_enc_value(js_ctx, idx_holder) == 0)) { /* ... holder key -> ... holder */ + if (DUK_UNLIKELY(duk__json_enc_value(js_ctx, idx_holder) == 0)) { /* ... holder key -> ... holder */ /* Result is undefined. */ duk_push_undefined(thr); } else { @@ -3221,7 +3191,7 @@ */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) - replace_finished: +replace_finished: #endif duk_replace(thr, entry_top); duk_set_top(thr, entry_top + 1); @@ -3245,22 +3215,15 @@ */ DUK_INTERNAL duk_ret_t duk_bi_json_object_parse(duk_hthread *thr) { - duk_bi_json_parse_helper(thr, - 0 /*idx_value*/, - 1 /*idx_replacer*/, - 0 /*flags*/); + duk_bi_json_parse_helper(thr, 0 /*idx_value*/, 1 /*idx_replacer*/, 0 /*flags*/); return 1; } DUK_INTERNAL duk_ret_t duk_bi_json_object_stringify(duk_hthread *thr) { - duk_bi_json_stringify_helper(thr, - 0 /*idx_value*/, - 1 /*idx_replacer*/, - 2 /*idx_space*/, - 0 /*flags*/); + duk_bi_json_stringify_helper(thr, 0 /*idx_value*/, 1 /*idx_replacer*/, 2 /*idx_space*/, 0 /*flags*/); return 1; } -#endif /* DUK_USE_JSON_BUILTIN */ +#endif /* DUK_USE_JSON_BUILTIN */ -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_math.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_math.c
Changed
@@ -141,7 +141,7 @@ return x >= 0.0 ? DUK_FLOOR(x) : DUK_CEIL(x); #endif } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ DUK_LOCAL double duk__round_fixed(double x) { /* Numbers half-way between integers must be rounded towards +Infinity, @@ -256,51 +256,23 @@ return DUK_ATAN2(x, y); } -#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ +#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ /* order must match constants in genbuiltins.py */ DUK_LOCAL const duk__one_arg_func duk__one_arg_funcs = { #if defined(DUK_USE_AVOID_PLATFORM_FUNCPTRS) - duk__fabs, - duk__acos, - duk__asin, - duk__atan, - duk__ceil, - duk__cos, - duk__exp, - duk__floor, - duk__log, - duk__round_fixed, - duk__sin, - duk__sqrt, - duk__tan, + duk__fabs, duk__acos, duk__asin, duk__atan, duk__ceil, duk__cos, duk__exp, + duk__floor, duk__log, duk__round_fixed, duk__sin, duk__sqrt, duk__tan, #if defined(DUK_USE_ES6) - duk__cbrt, - duk__log2, - duk__log10, - duk__trunc + duk__cbrt, duk__log2, duk__log10, duk__trunc #endif -#else /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ - DUK_FABS, - DUK_ACOS, - DUK_ASIN, - DUK_ATAN, - DUK_CEIL, - DUK_COS, - DUK_EXP, - DUK_FLOOR, - DUK_LOG, - duk__round_fixed, - DUK_SIN, - DUK_SQRT, - DUK_TAN, +#else /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ + DUK_FABS, DUK_ACOS, DUK_ASIN, DUK_ATAN, DUK_CEIL, DUK_COS, DUK_EXP, + DUK_FLOOR, DUK_LOG, duk__round_fixed, DUK_SIN, DUK_SQRT, DUK_TAN, #if defined(DUK_USE_ES6) - duk__cbrt, - duk__log2, - duk__log10, - duk__trunc + duk__cbrt, duk__log2, duk__log10, duk__trunc #endif -#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ +#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ }; /* order must match constants in genbuiltins.py */ @@ -335,7 +307,7 @@ DUK_ASSERT(fun_idx >= 0); DUK_ASSERT(fun_idx < (duk_small_int_t) (sizeof(duk__two_arg_funcs) / sizeof(duk__two_arg_func))); - arg1 = duk_to_number(thr, 0); /* explicit ordered evaluation to match coercion semantics */ + arg1 = duk_to_number(thr, 0); /* explicit ordered evaluation to match coercion semantics */ arg2 = duk_to_number(thr, 1); fun = duk__two_arg_funcsfun_idx; duk_push_number(thr, (duk_double_t) fun((double) arg1, (double) arg2)); @@ -351,7 +323,7 @@ } DUK_INTERNAL duk_ret_t duk_bi_math_object_random(duk_hthread *thr) { - duk_push_number(thr, (duk_double_t) DUK_UTIL_GET_RANDOM_DOUBLE(thr)); + duk_push_number(thr, (duk_double_t) duk_util_get_random_double(thr)); return 1; } @@ -421,7 +393,7 @@ duk_push_number(thr, (duk_double_t) DUK_SQRT(sum) * max); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_sign(duk_hthread *thr) { @@ -430,7 +402,7 @@ d = duk_to_number(thr, 0); if (duk_double_is_nan(d)) { DUK_ASSERT(duk_is_nan(thr, -1)); - return 1; /* NaN input -> return NaN */ + return 1; /* NaN input -> return NaN */ } if (duk_double_equals(d, 0.0)) { /* Zero sign kept, i.e. -0 -> -0, +0 -> +0. */ @@ -439,7 +411,7 @@ duk_push_int(thr, (d > 0.0 ? 1 : -1)); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_clz32(duk_hthread *thr) { @@ -459,7 +431,7 @@ DUK_ASSERT(i <= 32); duk_push_uint(thr, i); return 1; -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ i = 0; x = duk_to_uint32(thr, 0); if (x & 0xffff0000UL) { @@ -495,9 +467,9 @@ DUK_ASSERT(i <= 32); duk_push_uint(thr, i); return 1; -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_imul(duk_hthread *thr) { @@ -514,6 +486,6 @@ duk_push_i32(thr, (duk_int32_t) z); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_MATH_BUILTIN */ +#endif /* DUK_USE_MATH_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_number.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_number.c
Changed
@@ -19,8 +19,7 @@ goto done; } h = duk_get_hobject(thr, -1); - if (!h || - (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_NUMBER)) { + if (!h || (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_NUMBER)) { DUK_DDD(DUK_DDDPRINT("unacceptable this value: %!T", (duk_tval *) duk_get_tval(thr, -1))); DUK_ERROR_TYPE(thr, "number expected"); DUK_WO_NORETURN(return 0.0;); @@ -28,10 +27,11 @@ duk_xget_owndataprop_stridx_short(thr, -1, DUK_STRIDX_INT_VALUE); DUK_ASSERT(duk_is_number(thr, -1)); DUK_DDD(DUK_DDDPRINT("number object: %!T, internal value: %!T", - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); duk_remove_m2(thr); - done: +done: return duk_get_number(thr, -1); } @@ -80,9 +80,9 @@ DUK_ASSERT(DUK_HOBJECT_GET_CLASS_NUMBER(h_this) == DUK_HOBJECT_CLASS_NUMBER); DUK_ASSERT(DUK_HOBJECT_HAS_EXTENSIBLE(h_this)); - duk_dup_0(thr); /* -> val obj val */ + duk_dup_0(thr); /* -> val obj val */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); - return 0; /* no return value -> don't replace created value */ + return 0; /* no return value -> don't replace created value */ } DUK_INTERNAL duk_ret_t duk_bi_number_prototype_value_of(duk_hthread *thr) { @@ -104,10 +104,7 @@ n2s_flags = 0; - duk_numconv_stringify(thr, - radix /*radix*/, - 0 /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, radix /*radix*/, 0 /*digits*/, n2s_flags /*flags*/); return 1; } @@ -145,16 +142,12 @@ goto use_to_string; } - n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | - DUK_N2S_FLAG_FRACTION_DIGITS; + n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | DUK_N2S_FLAG_FRACTION_DIGITS; - duk_numconv_stringify(thr, - 10 /*radix*/, - frac_digits /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, frac_digits /*digits*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: DUK_ASSERT_TOP(thr, 2); duk_to_string(thr, -1); return 1; @@ -170,7 +163,7 @@ d = duk__push_this_number_plain(thr); frac_undefined = duk_is_undefined(thr, 0); - duk_to_int(thr, 0); /* for side effects */ + duk_to_int(thr, 0); /* for side effects */ c = (duk_small_int_t) DUK_FPCLASSIFY(d); if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) { @@ -179,16 +172,12 @@ frac_digits = (duk_small_int_t) duk_to_int_check_range(thr, 0, 0, 20); - n2s_flags = DUK_N2S_FLAG_FORCE_EXP | - (frac_undefined ? 0 : DUK_N2S_FLAG_FIXED_FORMAT); + n2s_flags = DUK_N2S_FLAG_FORCE_EXP | (frac_undefined ? 0 : DUK_N2S_FLAG_FIXED_FORMAT); - duk_numconv_stringify(thr, - 10 /*radix*/, - frac_digits + 1 /*leading digit + fractions*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, frac_digits + 1 /*leading digit + fractions*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: DUK_ASSERT_TOP(thr, 2); duk_to_string(thr, -1); return 1; @@ -213,7 +202,7 @@ } DUK_ASSERT_TOP(thr, 2); - duk_to_int(thr, 0); /* for side effects */ + duk_to_int(thr, 0); /* for side effects */ c = (duk_small_int_t) DUK_FPCLASSIFY(d); if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) { @@ -222,16 +211,12 @@ prec = (duk_small_int_t) duk_to_int_check_range(thr, 0, 1, 21); - n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | - DUK_N2S_FLAG_NO_ZERO_PAD; + n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | DUK_N2S_FLAG_NO_ZERO_PAD; - duk_numconv_stringify(thr, - 10 /*radix*/, - prec /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, prec /*digits*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: /* Used when precision is undefined; also used for NaN (-> "NaN"), * and +/- infinity (-> "Infinity", "-Infinity"). */ @@ -257,16 +242,16 @@ d = duk_get_number(thr, 0); switch (magic) { - case 0: /* isFinite() */ + case 0: /* isFinite() */ ret = duk_double_is_finite(d); break; - case 1: /* isInteger() */ + case 1: /* isInteger() */ ret = duk_double_is_integer(d); break; - case 2: /* isNaN() */ + case 2: /* isNaN() */ ret = duk_double_is_nan(d); break; - default: /* isSafeInteger() */ + default: /* isSafeInteger() */ DUK_ASSERT(magic == 3); ret = duk_double_is_safe_integer(d); } @@ -275,6 +260,6 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_NUMBER_BUILTIN */ +#endif /* DUK_USE_NUMBER_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_object.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_object.c
Changed
@@ -19,8 +19,8 @@ arg_mask = duk_get_type_mask(thr, 0); - if (!duk_is_constructor_call(thr) && /* not a constructor call */ - ((arg_mask & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) == 0)) { /* and argument not null or undefined */ + if (!duk_is_constructor_call(thr) && /* not a constructor call */ + ((arg_mask & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) == 0)) { /* and argument not null or undefined */ duk_to_object(thr, 0); return 1; } @@ -30,13 +30,8 @@ * promote to an object value. Lightfuncs and plain buffers are * coerced with ToObject() even they could also be returned as is. */ - if (arg_mask & (DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_STRING | - DUK_TYPE_MASK_BOOLEAN | - DUK_TYPE_MASK_NUMBER | - DUK_TYPE_MASK_POINTER | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_LIGHTFUNC)) { + if (arg_mask & (DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER | + DUK_TYPE_MASK_POINTER | DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_LIGHTFUNC)) { /* For DUK_TYPE_OBJECT the coercion is a no-op and could * be checked for explicitly, but Object(obj) calls are * not very common so opt for minimal footprint. @@ -46,13 +41,12 @@ } (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) && defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_assign(duk_hthread *thr) { @@ -109,9 +103,8 @@ DUK_ASSERT(proto != NULL || duk_is_null(thr, 0)); (void) duk_push_object_helper_proto(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), proto); if (!duk_is_undefined(thr, 1)) { @@ -132,7 +125,7 @@ return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_properties(duk_hthread *thr) { @@ -147,11 +140,9 @@ obj = duk_require_hobject_promote_mask(thr, 0, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); DUK_ASSERT(obj != NULL); - duk_to_object(thr, 1); /* properties object */ + duk_to_object(thr, 1); /* properties object */ - DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT", - (duk_tval *) duk_get_tval(thr, 0), - (duk_tval *) duk_get_tval(thr, 1))); + DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT", (duk_tval *) duk_get_tval(thr, 0), (duk_tval *) duk_get_tval(thr, 1))); /* * Two pass approach to processing the property descriptors. @@ -164,7 +155,7 @@ */ for (pass = 0; pass < 2; pass++) { - duk_set_top(thr, 2); /* -> hobject props */ + duk_set_top(thr, 2); /* -> hobject props */ duk_enum(thr, 1, DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_INCLUDE_SYMBOLS /*enum_flags*/); for (;;) { @@ -184,12 +175,7 @@ /* hobject props enum(props) key desc */ - duk_hobject_prepare_property_descriptor(thr, - 4 /*idx_desc*/, - &defprop_flags, - &idx_value, - &get, - &set); + duk_hobject_prepare_property_descriptor(thr, 4 /*idx_desc*/, &defprop_flags, &idx_value, &get, &set); /* hobject props enum(props) key desc multiple values */ @@ -201,14 +187,7 @@ key = duk_known_hstring(thr, 3); DUK_ASSERT(key != NULL); - duk_hobject_define_property_helper(thr, - defprop_flags, - obj, - key, - idx_value, - get, - set, - 1 /*throw_flag*/); + duk_hobject_define_property_helper(thr, defprop_flags, obj, key, idx_value, get, set, 1 /*throw_flag*/); } } @@ -219,7 +198,7 @@ duk_dup_0(thr); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_seal_freeze_shared(duk_hthread *thr) { @@ -228,7 +207,7 @@ duk_seal_freeze_raw(thr, 0, (duk_bool_t) duk_get_current_magic(thr) /*is_freeze*/); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_is_sealed_frozen_shared(duk_hthread *thr) { @@ -240,34 +219,33 @@ mask = duk_get_type_mask(thr, 0); if (mask & (DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { DUK_ASSERT(is_frozen == 0 || is_frozen == 1); - duk_push_boolean(thr, (mask & DUK_TYPE_MASK_LIGHTFUNC) ? - 1 : /* lightfunc always frozen and sealed */ - (is_frozen ^ 1)); /* buffer sealed but not frozen (index props writable) */ + duk_push_boolean(thr, + (mask & DUK_TYPE_MASK_LIGHTFUNC) ? 1 : /* lightfunc always frozen and sealed */ + (is_frozen ^ 1)); /* buffer sealed but not frozen (index props writable) */ } else { /* ES2015 Sections 19.1.2.12, 19.1.2.13: anything other than an object * is considered to be already sealed and frozen. */ h = duk_get_hobject(thr, 0); - duk_push_boolean(thr, (h == NULL) || - duk_hobject_object_is_sealed_frozen_helper(thr, h, is_frozen /*is_frozen*/)); + duk_push_boolean(thr, (h == NULL) || duk_hobject_object_is_sealed_frozen_helper(thr, h, is_frozen /*is_frozen*/)); } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_to_locale_string(duk_hthread *thr) { DUK_ASSERT_TOP(thr, 0); (void) duk_push_this_coercible_to_object(thr); duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_TO_STRING); -#if 0 /* This is mentioned explicitly in the E5.1 spec, but duk_call_method() checks for it in practice. */ +#if 0 /* This is mentioned explicitly in the E5.1 spec, but duk_call_method() checks for it in practice. */ duk_require_callable(thr, 1); #endif - duk_dup_0(thr); /* -> O toString O */ - duk_call_method(thr, 0); /* XXX: call method tail call? */ + duk_dup_0(thr); /* -> O toString O */ + duk_call_method(thr, 0); /* XXX: call method tail call? */ return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_value_of(duk_hthread *thr) { @@ -275,7 +253,7 @@ (void) duk_push_this_coercible_to_object(thr); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_is_prototype_of(duk_hthread *thr) { @@ -286,7 +264,7 @@ h_v = duk_get_hobject(thr, 0); if (!h_v) { - duk_push_false(thr); /* XXX: tail call: return duk_push_false(thr) */ + duk_push_false(thr); /* XXX: tail call: return duk_push_false(thr) */ return 1; } @@ -296,22 +274,24 @@ /* E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare. * Prototype loops should cause an error to be thrown. */ - duk_push_boolean(thr, duk_hobject_prototype_chain_contains(thr, DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_v), h_obj, 0 /*ignore_loop*/)); + duk_push_boolean( + thr, + duk_hobject_prototype_chain_contains(thr, DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_v), h_obj, 0 /*ignore_loop*/)); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_has_own_property(duk_hthread *thr) { return (duk_ret_t) duk_hobject_object_ownprop_helper(thr, 0 /*required_desc_flags*/); } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_property_is_enumerable(duk_hthread *thr) { return (duk_ret_t) duk_hobject_object_ownprop_helper(thr, DUK_PROPDESC_FLAG_ENUMERABLE /*required_desc_flags*/); } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper to implement Object.getPrototypeOf, @@ -368,7 +348,7 @@ } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper to implement ES2015 Object.setPrototypeOf, @@ -387,7 +367,7 @@ duk_hobject *h_obj; duk_hobject *h_new_proto; duk_hobject *h_curr; - duk_ret_t ret_success = 1; /* retval for success path */ + duk_ret_t ret_success = 1; /* retval for success path */ duk_uint_t mask; duk_int_t magic; @@ -408,9 +388,7 @@ if (magic == 1) { duk_require_object_coercible(thr, 0); } else { - duk_require_hobject_accept_mask(thr, 0, - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER); + duk_require_hobject_accept_mask(thr, 0, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); } duk_require_type_mask(thr, 1, DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_OBJECT); } @@ -421,9 +399,8 @@ mask = duk_get_type_mask(thr, 0); if (mask & (DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { duk_hobject *curr_proto; - curr_proto = thr->builtins(mask & DUK_TYPE_MASK_LIGHTFUNC) ? - DUK_BIDX_FUNCTION_PROTOTYPE : - DUK_BIDX_UINT8ARRAY_PROTOTYPE; + curr_proto = + thr->builtins(mask & DUK_TYPE_MASK_LIGHTFUNC) ? DUK_BIDX_FUNCTION_PROTOTYPE : DUK_BIDX_UINT8ARRAY_PROTOTYPE; if (h_new_proto == curr_proto) { goto skip; } @@ -453,15 +430,15 @@ DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h_obj, h_new_proto); /* fall thru */ - skip: +skip: duk_set_top(thr, 1); if (magic == 2) { duk_push_true(thr); } return ret_success; - fail_nonextensible: - fail_loop: +fail_nonextensible: +fail_loop: if (magic != 2) { DUK_DCERROR_TYPE_INVALID_ARGS(thr); } else { @@ -469,7 +446,7 @@ return 1; } } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_property(duk_hthread *thr) { @@ -521,12 +498,7 @@ * Lightfunc set/get values are coerced to full Functions. */ - duk_hobject_prepare_property_descriptor(thr, - 2 /*idx_desc*/, - &defprop_flags, - &idx_value, - &get, - &set); + duk_hobject_prepare_property_descriptor(thr, 2 /*idx_desc*/, &defprop_flags, &idx_value, &get, &set); /* * Use Object.defineProperty() helper for the actual operation. @@ -534,14 +506,7 @@ DUK_ASSERT(magic == 0U || magic == 1U); throw_flag = magic ^ 1U; - ret = duk_hobject_define_property_helper(thr, - defprop_flags, - obj, - key, - idx_value, - get, - set, - throw_flag); + ret = duk_hobject_define_property_helper(thr, defprop_flags, obj, key, idx_value, get, set, throw_flag); /* Ignore the normalize/validate helper outputs on the value stack, * they're popped automatically. @@ -556,7 +521,7 @@ } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_get_own_property_descriptor(duk_hthread *thr) { @@ -572,7 +537,7 @@ duk_hobject_object_get_own_property_descriptor(thr, -2); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_is_extensible(duk_hthread *thr) { @@ -595,7 +560,7 @@ duk_push_boolean(thr, (h != NULL) && DUK_HOBJECT_HAS_EXTENSIBLE(h)); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper for various key/symbol listings, magic: @@ -606,26 +571,17 @@ */ DUK_LOCAL const duk_small_uint_t duk__object_keys_enum_flags4 = { /* Object.keys() */ - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_NO_PROXY_BEHAVIOR, + DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Object.getOwnPropertyNames() */ - DUK_ENUM_INCLUDE_NONENUMERABLE | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_NO_PROXY_BEHAVIOR, + DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Object.getOwnPropertySymbols() */ - DUK_ENUM_INCLUDE_SYMBOLS | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_EXCLUDE_STRINGS | - DUK_ENUM_INCLUDE_NONENUMERABLE | + DUK_ENUM_INCLUDE_SYMBOLS | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_EXCLUDE_STRINGS | DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Reflect.ownKeys() */ - DUK_ENUM_INCLUDE_SYMBOLS | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_INCLUDE_NONENUMERABLE | - DUK_ENUM_NO_PROXY_BEHAVIOR + DUK_ENUM_INCLUDE_SYMBOLS | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_NO_PROXY_BEHAVIOR }; DUK_INTERNAL duk_ret_t duk_bi_object_constructor_keys_shared(duk_hthread *thr) { @@ -657,9 +613,7 @@ #if defined(DUK_USE_ES6_PROXY) /* XXX: better sharing of code between proxy target call sites */ - if (DUK_LIKELY(!duk_hobject_proxy_check(obj, - &h_proxy_target, - &h_proxy_handler))) { + if (DUK_LIKELY(!duk_hobject_proxy_check(obj, &h_proxy_target, &h_proxy_handler))) { goto skip_proxy; } @@ -678,8 +632,8 @@ /* obj handler trap */ duk_insert(thr, -2); - duk_push_hobject(thr, h_proxy_target); /* -> obj trap handler target */ - duk_call_method(thr, 1 /*nargs*/); /* -> obj trap_result */ + duk_push_hobject(thr, h_proxy_target); /* -> obj trap handler target */ + duk_call_method(thr, 1 /*nargs*/); /* -> obj trap_result */ h_trap_result = duk_require_hobject(thr, -1); DUK_UNREF(h_trap_result); @@ -690,8 +644,8 @@ duk_proxy_ownkeys_postprocess(thr, h_proxy_target, enum_flags); return 1; - skip_proxy: -#endif /* DUK_USE_ES6_PROXY */ +skip_proxy: +#endif /* DUK_USE_ES6_PROXY */ DUK_ASSERT_TOP(thr, 1); magic = duk_get_current_magic(thr); @@ -699,7 +653,7 @@ enum_flags = duk__object_keys_enum_flagsmagic; return duk_hobject_get_enumerated_keys(thr, enum_flags); } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_prevent_extensions(duk_hthread *thr) { @@ -719,12 +673,8 @@ /* Object.preventExtensions() silent success for non-object. */ if (magic == 0) { - mask |= DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_BOOLEAN | - DUK_TYPE_MASK_NUMBER | - DUK_TYPE_MASK_STRING | - DUK_TYPE_MASK_POINTER; + mask |= DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER | + DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_POINTER; } if (duk_check_type_mask(thr, 0, mask)) { @@ -741,13 +691,13 @@ */ duk_hobject_compact_props(thr, h); - done: +done: if (magic == 1) { duk_push_true(thr); } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ /* * __defineGetter__, __defineSetter__, __lookupGetter__, __lookupSetter__ @@ -763,9 +713,10 @@ /* ToObject(this) key getter/setter */ /* ToPropertyKey() coercion is not needed, duk_def_prop() does it. */ - duk_def_prop(thr, 0, DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE | - (duk_get_current_magic(thr) ? DUK_DEFPROP_HAVE_SETTER : DUK_DEFPROP_HAVE_GETTER)); + duk_def_prop(thr, + 0, + DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE | + (duk_get_current_magic(thr) ? DUK_DEFPROP_HAVE_SETTER : DUK_DEFPROP_HAVE_GETTER)); return 0; } DUK_INTERNAL duk_ret_t duk_bi_object_prototype_lookupaccessor(duk_hthread *thr) { @@ -800,4 +751,4 @@ } return 1; } -#endif /* DUK_USE_ES8 */ +#endif /* DUK_USE_ES8 */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_performance.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_performance.c
Changed
@@ -18,7 +18,7 @@ return 1; } -#if 0 /* Missing until semantics decided. */ +#if 0 /* Missing until semantics decided. */ DUK_INTERNAL duk_ret_t duk_bi_performance_timeorigin_getter(duk_hthread *thr) { /* No decision yet how to handle timeOrigins, e.g. should one be * initialized per heap, or per global object set. See @@ -27,5 +27,5 @@ duk_push_uint(thr, 0); return 1; } -#endif /* 0 */ -#endif /* DUK_USE_PERFORMANCE_BUILTIN */ +#endif /* 0 */ +#endif /* DUK_USE_PERFORMANCE_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_pointer.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_pointer.c
Changed
@@ -23,9 +23,8 @@ if (duk_is_constructor_call(thr)) { (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER), DUK_BIDX_POINTER_PROTOTYPE); /* Pointer object internal value is immutable. */ @@ -70,6 +69,6 @@ } return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_promise.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_promise.c
Changed
@@ -41,4 +41,4 @@ DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_PROMISE_BUILTIN */ +#endif /* DUK_USE_PROMISE_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_protos.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_protos.h
Changed
@@ -12,7 +12,7 @@ * 32 * Include additional space to be safe. */ -#define DUK_BI_DATE_ISO8601_BUFSIZE 40 +#define DUK_BI_DATE_ISO8601_BUFSIZE 40 /* Helpers exposed for internal use */ DUK_INTERNAL_DECL void duk_bi_date_timeval_to_parts(duk_double_t d, duk_int_t *parts, duk_double_t *dparts, duk_small_uint_t flags); @@ -50,7 +50,10 @@ DUK_INTERNAL_DECL duk_bool_t duk_bi_date_parse_string_getdate(duk_hthread *thr, const char *str); #endif #if defined(DUK_USE_DATE_FMT_STRFTIME) -DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags); +DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, + duk_int_t *parts, + duk_int_t tzoffset, + duk_small_uint_t flags); #endif #if defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME) @@ -61,10 +64,7 @@ #endif DUK_INTERNAL_DECL -void duk_bi_json_parse_helper(duk_hthread *thr, - duk_idx_t idx_value, - duk_idx_t idx_reviver, - duk_small_uint_t flags); +void duk_bi_json_parse_helper(duk_hthread *thr, duk_idx_t idx_value, duk_idx_t idx_reviver, duk_small_uint_t flags); DUK_INTERNAL_DECL void duk_bi_json_stringify_helper(duk_hthread *thr, duk_idx_t idx_value, @@ -78,4 +78,4 @@ DUK_INTERNAL_DECL void duk_proxy_ownkeys_postprocess(duk_hthread *thr, duk_hobject *h_proxy_target, duk_uint_t flags); #endif -#endif /* DUK_BUILTIN_PROTOS_H_INCLUDED */ +#endif /* DUK_BUILTIN_PROTOS_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_proxy.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_proxy.c
Changed
@@ -68,7 +68,7 @@ duk_def_prop(thr, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_SET_WEC); continue; - skip_key: + skip_key: duk_pop(thr); continue; } @@ -85,14 +85,14 @@ * handled above. */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ES6_PROXY) DUK_INTERNAL duk_ret_t duk_bi_proxy_constructor(duk_hthread *thr) { - DUK_ASSERT_TOP(thr, 2); /* target handler */ + DUK_ASSERT_TOP(thr, 2); /* target handler */ duk_require_constructor_call(thr); - duk_push_proxy(thr, 0 /*flags*/); /* target handler -> proxy */ - return 1; /* replacement */ + duk_push_proxy(thr, 0 /*flags*/); /* target handler -> proxy */ + return 1; /* replacement */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_reflect.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_reflect.c
Changed
@@ -47,7 +47,7 @@ tv_obj = DUK_GET_TVAL_POSIDX(thr, 0); tv_key = DUK_GET_TVAL_POSIDX(thr, 1); - (void) duk_hobject_getprop(thr, tv_obj, tv_key); /* This could also be a duk_get_prop(). */ + (void) duk_hobject_getprop(thr, tv_obj, tv_key); /* This could also be a duk_get_prop(). */ return 1; } @@ -96,4 +96,4 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_REFLECT_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_regexp.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_regexp.c
Changed
@@ -13,7 +13,7 @@ h = duk_require_hobject_with_class(thr, -1, DUK_HOBJECT_CLASS_REGEXP); DUK_ASSERT(h != NULL); DUK_UNREF(h); - duk_insert(thr, 0); /* prepend regexp to valstack 0 index */ + duk_insert(thr, 0); /* prepend regexp to valstack 0 index */ } /* XXX: much to improve (code size) */ @@ -23,10 +23,8 @@ DUK_ASSERT_TOP(thr, 2); h_pattern = duk_get_hobject(thr, 0); - if (!duk_is_constructor_call(thr) && - h_pattern != NULL && - DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP && - duk_is_undefined(thr, 1)) { + if (!duk_is_constructor_call(thr) && h_pattern != NULL && + DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP && duk_is_undefined(thr, 1)) { /* Called as a function, pattern has Class "RegExp" and * flags is undefined -> return object as is. */ @@ -41,8 +39,7 @@ * call. */ - if (h_pattern != NULL && - DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP) { + if (h_pattern != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP) { duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_SOURCE); if (duk_is_undefined(thr, 1)) { /* In ES5 one would need to read the flags individually; @@ -58,20 +55,21 @@ duk_push_hstring_empty(thr); } else { duk_dup_0(thr); - duk_to_string(thr, -1); /* Rejects Symbols. */ + duk_to_string(thr, -1); /* Rejects Symbols. */ } if (duk_is_undefined(thr, 1)) { duk_push_hstring_empty(thr); } else { duk_dup_1(thr); - duk_to_string(thr, -1); /* Rejects Symbols. */ + duk_to_string(thr, -1); /* Rejects Symbols. */ } /* ... pattern flags */ } DUK_DDD(DUK_DDDPRINT("RegExp constructor/function call, pattern=%!T, flags=%!T", - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); /* ... pattern flags (both uncoerced) */ @@ -121,7 +119,7 @@ duk_push_this(thr); duk_push_literal(thr, "/"); duk_get_prop_stridx(thr, 0, DUK_STRIDX_SOURCE); - duk_dup_m2(thr); /* another "/" */ + duk_dup_m2(thr); /* another "/" */ duk_get_prop_stridx(thr, 0, DUK_STRIDX_FLAGS); duk_concat(thr, 4); return 1; @@ -131,7 +129,7 @@ /* .flags is ES2015 but present even when ES2015 bindings are * disabled because the constructor relies on it. */ - duk_uint8_t buf8; /* enough for all flags + NUL */ + duk_uint8_t buf8; /* enough for all flags + NUL */ duk_uint8_t *p = buf; /* .flags is generic and works on any object. */ @@ -172,7 +170,7 @@ duk_xget_owndataprop_stridx_short(thr, 0, DUK_STRIDX_INT_SOURCE); duk_xget_owndataprop_stridx_short(thr, 0, DUK_STRIDX_INT_BYTECODE); h_bc = duk_require_hstring(thr, -1); - re_flags = (duk_small_uint_t) DUK_HSTRING_GET_DATA(h_bc)0; /* Safe even if h_bc length is 0 (= NUL) */ + re_flags = (duk_small_uint_t) DUK_HSTRING_GET_DATA(h_bc)0; /* Safe even if h_bc length is 0 (= NUL) */ duk_pop(thr); } else if (h == thr->builtinsDUK_BIDX_REGEXP_PROTOTYPE) { /* In ES2015 and ES2016 a TypeError would be thrown here. @@ -183,7 +181,7 @@ if (magic != 16 /* .source */) { return 0; } - duk_push_literal(thr, "(?:)"); /* .source handled by switch-case */ + duk_push_literal(thr, "(?:)"); /* .source handled by switch-case */ re_flags = 0; } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -192,15 +190,15 @@ /* regexp source */ switch (magic) { - case 0: { /* global */ + case 0: { /* global */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_GLOBAL)); break; } - case 1: { /* ignoreCase */ + case 1: { /* ignoreCase */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_IGNORE_CASE)); break; } - case 2: { /* multiline */ + case 2: { /* multiline */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_MULTILINE)); break; } @@ -214,7 +212,7 @@ break; } #endif - default: { /* source */ + default: { /* source */ /* leave 'source' on top */ break; } @@ -223,4 +221,4 @@ return 1; } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_string.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_string.c
Changed
@@ -36,7 +36,8 @@ return h; } -DUK_LOCAL duk_int_t duk__str_search_shared(duk_hthread *thr, duk_hstring *h_this, duk_hstring *h_search, duk_int_t start_cpos, duk_bool_t backwards) { +DUK_LOCAL duk_int_t +duk__str_search_shared(duk_hthread *thr, duk_hstring *h_this, duk_hstring *h_search, duk_int_t start_cpos, duk_bool_t backwards) { duk_int_t cpos; duk_int_t bpos; const duk_uint8_t *p_start, *p_end, *p; @@ -71,7 +72,7 @@ * must be updated if 'p' is wound back (backward scanning). */ - firstbyte = q_start0; /* leading byte of match string */ + firstbyte = q_start0; /* leading byte of match string */ while (p <= p_end && p >= p_start) { t = *p; @@ -137,15 +138,13 @@ duk_replace(thr, 0); } } - duk_to_string(thr, 0); /* catches symbol argument for constructor call */ + duk_to_string(thr, 0); /* catches symbol argument for constructor call */ DUK_ASSERT(duk_is_string(thr, 0)); - duk_set_top(thr, 1); /* Top may be 1 or larger. */ + duk_set_top(thr, 1); /* Top may be 1 or larger. */ if (duk_is_constructor_call(thr)) { /* String object internal value is immutable */ - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_STRING); duk_push_object_helper(thr, flags, DUK_BIDX_STRING_PROTOTYPE); duk_dup_0(thr); @@ -171,7 +170,7 @@ n = duk_get_top(thr); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, (duk_size_t) n); /* initial estimate for ASCII only codepoints */ + DUK_BW_INIT_PUSHBUF(thr, bw, (duk_size_t) n); /* initial estimate for ASCII only codepoints */ for (i = 0; i < n; i++) { /* XXX: could improve bufwriter handling to write multiple codepoints @@ -185,8 +184,7 @@ * the same. */ duk_int32_t i32 = 0; - if (!duk_is_whole_get_int32(duk_to_number(thr, i), &i32) || - i32 < 0 || i32 > 0x10ffffL) { + if (!duk_is_whole_get_int32(duk_to_number(thr, i), &i32) || i32 < 0 || i32 > 0x10ffffL) { DUK_DCERROR_RANGE_INVALID_ARGS(thr); } DUK_ASSERT(i32 >= 0 && i32 <= 0x10ffffL); @@ -210,7 +208,7 @@ } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 or CESU-8 encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 or CESU-8 encoded. */ return 1; } @@ -252,10 +250,10 @@ goto type_error; } - (void) duk_require_hstring_notsymbol(thr, -1); /* Reject symbols (and wrapped symbols). */ + (void) duk_require_hstring_notsymbol(thr, -1); /* Reject symbols (and wrapped symbols). */ return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -391,7 +389,7 @@ * ("undefined" and "null"). */ duk_push_this(thr); - h = duk_to_hstring_m1(thr); /* Reject Symbols. */ + h = duk_to_hstring_m1(thr); /* Reject Symbols. */ DUK_ASSERT(h != NULL); len = (duk_int_t) DUK_HSTRING_GET_CHARLEN(h); @@ -423,7 +421,7 @@ duk_substring(thr, -1, (duk_size_t) start_pos, (duk_size_t) end_pos); return 1; } -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_slice(duk_hthread *thr) { duk_hstring *h; @@ -482,7 +480,7 @@ duk_hstring *h_search; duk_int_t clen_this; duk_int_t cpos; - duk_small_uint_t is_lastindexof = (duk_small_uint_t) duk_get_current_magic(thr); /* 0=indexOf, 1=lastIndexOf */ + duk_small_uint_t is_lastindexof = (duk_small_uint_t) duk_get_current_magic(thr); /* 0=indexOf, 1=lastIndexOf */ h_this = duk_push_this_coercible_to_string(thr); DUK_ASSERT(h_this != NULL); @@ -539,7 +537,7 @@ duk_int_t match_caps; #endif duk_uint32_t prev_match_end_boff; - const duk_uint8_t *r_start, *r_end, *r; /* repl string scan */ + const duk_uint8_t *r_start, *r_end, *r; /* repl string scan */ duk_size_t tmp_sz; DUK_ASSERT_TOP(thr, 2); @@ -547,7 +545,7 @@ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* input size is good output starting point */ + DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* input size is good output starting point */ DUK_ASSERT_TOP(thr, 4); @@ -568,11 +566,11 @@ duk_push_int(thr, 0); duk_put_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ DUK_DCERROR_UNSUPPORTED(thr); -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } else { - duk_to_string(thr, 0); /* rejects symbols */ + duk_to_string(thr, 0); /* rejects symbols */ #if defined(DUK_USE_REGEXP_SUPPORT) is_regexp = 0; is_global = 0; @@ -587,7 +585,7 @@ duk_hstring *h_repl; is_repl_func = 0; - h_repl = duk_to_hstring(thr, 1); /* reject symbols */ + h_repl = duk_to_hstring(thr, 1); /* reject symbols */ DUK_ASSERT(h_repl != NULL); r_start = DUK_HSTRING_GET_DATA(h_repl); r_end = r_start + DUK_HSTRING_GET_BYTELEN(h_repl); @@ -625,7 +623,7 @@ if (is_regexp) { duk_dup_0(thr); duk_dup_2(thr); - duk_regexp_match(thr); /* ... regexp input -> res_obj */ + duk_regexp_match(thr); /* ... regexp input -> res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); break; @@ -639,7 +637,7 @@ duk_get_prop_index(thr, -1, 0); DUK_ASSERT(duk_is_string(thr, -1)); h_match = duk_known_hstring(thr, -1); - duk_pop(thr); /* h_match is borrowed, remains reachable through match_obj */ + duk_pop(thr); /* h_match is borrowed, remains reachable through match_obj */ if (DUK_HSTRING_GET_BYTELEN(h_match) == 0) { /* This should be equivalent to match() algorithm step 8.f.iii.2: @@ -650,25 +648,26 @@ duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); last_index = (duk_uint32_t) duk_get_uint(thr, -1); DUK_DDD(DUK_DDDPRINT("empty match, bump lastIndex: %ld -> %ld", - (long) last_index, (long) (last_index + 1))); + (long) last_index, + (long) (last_index + 1))); duk_pop(thr); duk_push_uint(thr, (duk_uint_t) (last_index + 1)); duk_put_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); } - DUK_ASSERT(duk_get_length(thr, -1) <= DUK_INT_MAX); /* string limits */ + DUK_ASSERT(duk_get_length(thr, -1) <= DUK_INT_MAX); /* string limits */ match_caps = (duk_int_t) duk_get_length(thr, -1); } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ - const duk_uint8_t *q_start; /* match string */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ + const duk_uint8_t *q_start; /* match string */ duk_size_t p_blen; duk_size_t q_blen; #if defined(DUK_USE_REGEXP_SUPPORT) - DUK_ASSERT(!is_global); /* single match always */ + DUK_ASSERT(!is_global); /* single match always */ #endif p_start = DUK_HSTRING_GET_DATA(h_input); @@ -681,10 +680,10 @@ q_blen = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_search); if (q_blen > p_blen) { - break; /* no match */ + break; /* no match */ } - p_end -= q_blen; /* ensure full memcmp() fits in while */ + p_end -= q_blen; /* ensure full memcmp() fits in while */ DUK_ASSERT(p_end >= p); match_start_coff = 0; @@ -710,7 +709,7 @@ /* not found */ break; } - found: + found: /* stack0 = search value * stack1 = replace value @@ -744,9 +743,9 @@ duk_get_prop_index(thr, 4, (duk_uarridx_t) idx); } } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* match == search string, by definition */ duk_dup_0(thr); } @@ -756,12 +755,12 @@ /* ... replacer match captures match_char_offset input */ duk_call(thr, duk_get_top(thr) - idx_args); - h_repl = duk_to_hstring_m1(thr); /* -> ... repl_value */ + h_repl = duk_to_hstring_m1(thr); /* -> ... repl_value */ DUK_ASSERT(h_repl != NULL); DUK_BW_WRITE_ENSURE_HSTRING(thr, bw, h_repl); - duk_pop(thr); /* repl_value */ + duk_pop(thr); /* repl_value */ } else { r = r_start; @@ -808,9 +807,10 @@ * match codepoint encodings would have different lengths. */ /* XXX: charlen computed here, and also in char2byte helper. */ - match_end_boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte(thr, - h_input, - match_start_coff + (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_match)); + match_end_boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte( + thr, + h_input, + match_start_coff + (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_match)); tmp_sz = (duk_size_t) (DUK_HSTRING_GET_BYTELEN(h_input) - match_end_boff); DUK_BW_WRITE_ENSURE_BYTES(thr, bw, DUK_HSTRING_GET_DATA(h_input) + match_end_boff, tmp_sz); @@ -846,7 +846,7 @@ } if (capnum > 0 && capnum < match_caps) { - DUK_ASSERT(is_regexp != 0); /* match_caps == 0 without regexps */ + DUK_ASSERT(is_regexp != 0); /* match_caps == 0 without regexps */ /* regexp res_obj is at offset 4 */ duk_get_prop_index(thr, 4, (duk_uarridx_t) capnum); @@ -865,26 +865,26 @@ } else { goto repl_write; } -#else /* DUK_USE_REGEXP_SUPPORT */ - goto repl_write; /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - } /* default case */ - } /* switch (ch2) */ +#else /* DUK_USE_REGEXP_SUPPORT */ + goto repl_write; /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + } /* default case */ + } /* switch (ch2) */ - repl_write: + repl_write: /* ch1 = (r_increment << 8) + byte */ DUK_BW_WRITE_ENSURE_U8(thr, bw, (duk_uint8_t) (ch1 & 0xff)); r += ch1 >> 8; - } /* while repl */ - } /* if (is_repl_func) */ + } /* while repl */ + } /* if (is_repl_func) */ - duk_pop(thr); /* pop regexp res_obj or match string */ + duk_pop(thr); /* pop regexp res_obj or match string */ #if defined(DUK_USE_REGEXP_SUPPORT) if (!is_global) { #else - { /* unconditionally; is_global==0 */ + { /* unconditionally; is_global==0 */ #endif break; } @@ -896,7 +896,7 @@ DUK_ASSERT_TOP(thr, 4); DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ return 1; } @@ -916,7 +916,7 @@ #if defined(DUK_USE_REGEXP_SUPPORT) duk_bool_t is_regexp; #endif - duk_bool_t matched; /* set to 1 if any match exists (needed for empty input special case) */ + duk_bool_t matched; /* set to 1 if any match exists (needed for empty input special case) */ duk_uint32_t prev_match_end_coff, prev_match_end_boff; duk_uint32_t match_start_boff, match_start_coff; duk_uint32_t match_end_boff, match_end_coff; @@ -954,7 +954,7 @@ #if defined(DUK_USE_REGEXP_SUPPORT) duk_push_hobject_bidx(thr, DUK_BIDX_REGEXP_CONSTRUCTOR); duk_dup_0(thr); - duk_new(thr, 1); /* ... RegExp val -> ... res */ + duk_new(thr, 1); /* ... RegExp val -> ... res */ duk_replace(thr, 0); /* lastIndex is initialized to zero by new RegExp() */ is_regexp = 1; @@ -993,7 +993,7 @@ if (is_regexp) { duk_dup_0(thr); duk_dup_2(thr); - duk_regexp_match_force_global(thr); /* ... regexp input -> res_obj */ + duk_regexp_match_force_global(thr); /* ... regexp input -> res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); break; @@ -1026,23 +1026,23 @@ continue; } } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ - const duk_uint8_t *q_start; /* match string */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ + const duk_uint8_t *q_start; /* match string */ duk_size_t q_blen, q_clen; p_start = DUK_HSTRING_GET_DATA(h_input); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); p = p_start + prev_match_end_boff; - h_sep = duk_known_hstring(thr, 0); /* symbol already rejected above */ + h_sep = duk_known_hstring(thr, 0); /* symbol already rejected above */ q_start = DUK_HSTRING_GET_DATA(h_sep); q_blen = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sep); q_clen = (duk_size_t) DUK_HSTRING_GET_CHARLEN(h_sep); - p_end -= q_blen; /* ensure full memcmp() fits in while */ + p_end -= q_blen; /* ensure full memcmp() fits in while */ match_start_coff = prev_match_end_coff; @@ -1055,7 +1055,7 @@ * Don't allow an empty string to match at the end of the input. */ - matched = 1; /* empty separator can always match */ + matched = 1; /* empty separator can always match */ match_start_coff++; p++; @@ -1071,7 +1071,7 @@ DUK_ASSERT(q_blen > 0 && q_clen > 0); while (p <= p_end) { DUK_ASSERT(p + q_blen <= DUK_HSTRING_GET_DATA(h_input) + DUK_HSTRING_GET_BYTELEN(h_input)); - DUK_ASSERT(q_blen > 0); /* no issues with empty memcmp() */ + DUK_ASSERT(q_blen > 0); /* no issues with empty memcmp() */ if (duk_memcmp((const void *) p, (const void *) q_start, (size_t) q_blen) == 0) { /* never an empty match, so step 13.c.iii can't be triggered */ goto found; @@ -1084,15 +1084,15 @@ p++; } - not_found: + not_found: /* not found */ break; - found: + found: matched = 1; match_start_boff = (duk_uint32_t) (p - p_start); - match_end_coff = (duk_uint32_t) (match_start_coff + q_clen); /* constrained by string length */ - match_end_boff = (duk_uint32_t) (match_start_boff + q_blen); /* ditto */ + match_end_coff = (duk_uint32_t) (match_start_coff + q_clen); /* constrained by string length */ + match_end_boff = (duk_uint32_t) (match_start_boff + q_blen); /* ditto */ /* empty match (may happen with empty separator) -> bump and continue */ if (prev_match_end_boff == match_end_boff) { @@ -1100,7 +1100,7 @@ prev_match_end_coff++; continue; } - } /* if (is_regexp) */ + } /* if (is_regexp) */ /* stack0 = separator (string or regexp) * stack1 = limit @@ -1110,9 +1110,12 @@ */ DUK_DDD(DUK_DDDPRINT("split; match_start b=%ld,c=%ld, match_end b=%ld,c=%ld, prev_end b=%ld,c=%ld", - (long) match_start_boff, (long) match_start_coff, - (long) match_end_boff, (long) match_end_coff, - (long) prev_match_end_boff, (long) prev_match_end_coff)); + (long) match_start_boff, + (long) match_start_coff, + (long) match_end_boff, + (long) match_end_coff, + (long) prev_match_end_boff, + (long) prev_match_end_coff)); duk_push_lstring(thr, (const char *) (DUK_HSTRING_GET_DATA(h_input) + prev_match_end_boff), @@ -1129,7 +1132,7 @@ len = duk_get_length(thr, 4); for (i = 1; i < len; i++) { - DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* cannot have >4G captures */ + DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* cannot have >4G captures */ duk_get_prop_index(thr, 4, (duk_uarridx_t) i); duk_put_prop_index(thr, 3, arr_idx); arr_idx++; @@ -1141,21 +1144,21 @@ duk_pop(thr); /* lastIndex already set up for next match */ } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { + /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* no action */ } prev_match_end_boff = match_end_boff; prev_match_end_coff = match_end_coff; continue; - } /* for */ + } /* for */ /* Combined step 11 (empty string special case) and 14-15. */ - DUK_DDD(DUK_DDDPRINT("split trailer; prev_end b=%ld,c=%ld", - (long) prev_match_end_boff, (long) prev_match_end_coff)); + DUK_DDD(DUK_DDDPRINT("split trailer; prev_end b=%ld,c=%ld", (long) prev_match_end_boff, (long) prev_match_end_coff)); if (DUK_HSTRING_GET_BYTELEN(h_input) > 0 || !matched) { /* Add trailer if: @@ -1172,7 +1175,7 @@ return 1; - hit_limit: +hit_limit: #if defined(DUK_USE_REGEXP_SUPPORT) if (is_regexp) { duk_pop(thr); @@ -1204,13 +1207,13 @@ } return; - do_new: +do_new: duk_push_hobject_bidx(thr, DUK_BIDX_REGEXP_CONSTRUCTOR); duk_dup(thr, idx); - duk_new(thr, 1); /* ... RegExp val -> ... res */ + duk_new(thr, 1); /* ... RegExp val -> ... res */ duk_replace(thr, idx); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_search(duk_hthread *thr) { @@ -1225,7 +1228,7 @@ */ DUK_ASSERT_TOP(thr, 1); - (void) duk_push_this_coercible_to_string(thr); /* at index 1 */ + (void) duk_push_this_coercible_to_string(thr); /* at index 1 */ duk__to_regexp_helper(thr, 0 /*index*/, 1 /*force_new*/); /* stack0 = regexp @@ -1237,8 +1240,8 @@ */ duk_dup_0(thr); - duk_dup_1(thr); /* ... re_obj input */ - duk_regexp_match(thr); /* -> ... res_obj */ + duk_dup_1(thr); /* ... re_obj input */ + duk_regexp_match(thr); /* -> ... res_obj */ if (!duk_is_object(thr, -1)) { duk_push_int(thr, -1); @@ -1249,7 +1252,7 @@ DUK_ASSERT(duk_is_number(thr, -1)); return 1; } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_match(duk_hthread *thr) { @@ -1269,8 +1272,8 @@ */ if (!global) { - duk_regexp_match(thr); /* -> res_obj */ - return 1; /* return 'res_obj' */ + duk_regexp_match(thr); /* -> res_obj */ + return 1; /* return 'res_obj' */ } /* Global case is more complex. */ @@ -1291,7 +1294,7 @@ duk_dup_0(thr); duk_dup_1(thr); - duk_regexp_match(thr); /* -> ... regexp string -> ... res_obj */ + duk_regexp_match(thr); /* -> ... regexp string -> ... res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); @@ -1310,24 +1313,24 @@ } prev_last_index = this_index; - duk_get_prop_index(thr, -1, 0); /* match string */ + duk_get_prop_index(thr, -1, 0); /* match string */ duk_put_prop_index(thr, 2, (duk_uarridx_t) arr_idx); arr_idx++; - duk_pop(thr); /* res_obj */ + duk_pop(thr); /* res_obj */ } if (arr_idx == 0) { duk_push_null(thr); } - return 1; /* return 'res_arr' or 'null' */ + return 1; /* return 'res_arr' or 'null' */ } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_concat(duk_hthread *thr) { /* duk_concat() coerces arguments with ToString() in correct order */ (void) duk_push_this_coercible_to_string(thr); - duk_insert(thr, 0); /* this is relatively expensive */ + duk_insert(thr, 0); /* this is relatively expensive */ duk_concat(thr, duk_get_top(thr)); return 1; } @@ -1392,10 +1395,10 @@ #if defined(DUK_USE_PREFER_SIZE) p = buf; while (count-- > 0) { - duk_memcpy((void *) p, (const void *) src, input_blen); /* copy size may be zero, but pointers are valid */ + duk_memcpy((void *) p, (const void *) src, input_blen); /* copy size may be zero, but pointers are valid */ p += input_blen; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* Take advantage of already copied pieces to speed up the process * especially for small repeated strings. */ @@ -1405,7 +1408,9 @@ for (;;) { duk_size_t remain = (duk_size_t) (p_end - p); DUK_DDD(DUK_DDDPRINT("remain=%ld, copy_size=%ld, input_blen=%ld, result_len=%ld", - (long) remain, (long) copy_size, (long) input_blen, + (long) remain, + (long) copy_size, + (long) input_blen, (long) result_len)); if (remain <= copy_size) { /* If result_len is zero, this case is taken and does @@ -1418,10 +1423,10 @@ p += copy_size; } - src = (const duk_uint8_t *) buf; /* Use buf as source for larger copies. */ + src = (const duk_uint8_t *) buf; /* Use buf as source for larger copies. */ copy_size = (duk_size_t) (p - buf); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* XXX: It would be useful to be able to create a duk_hstring with * a certain byte size whose data area wasn't initialized and which @@ -1432,13 +1437,13 @@ * intern table (they are not in heap_allocated). */ - duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ + duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ return 1; - fail_range: +fail_range: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_locale_compare(duk_hthread *thr) { duk_hstring *h1; @@ -1492,7 +1497,7 @@ ret = -1; goto done; - done: +done: duk_push_int(thr, (duk_int_t) ret); return 1; } @@ -1579,11 +1584,11 @@ } } - finish: +finish: duk_push_boolean(thr, result); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_includes(duk_hthread *thr) { @@ -1606,5 +1611,5 @@ duk_push_boolean(thr, pos >= 0); return 1; } -#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_STRING_BUILTIN */ +#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_STRING_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_symbol.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_symbol.c
Changed
@@ -39,7 +39,7 @@ buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, 1 + len + 1 + 17 + 1); DUK_ASSERT(buf != NULL); p = buf + 1; - DUK_ASSERT(desc != NULL || len == 0); /* may be NULL if len is 0 */ + DUK_ASSERT(desc != NULL || len == 0); /* may be NULL if len is 0 */ duk_memcpy_unsafe((void *) p, (const void *) desc, len); p += len; if (magic == 0) { @@ -50,7 +50,9 @@ if (++thr->heap->sym_counter0 == 0) { thr->heap->sym_counter1++; } - p += DUK_SPRINTF((char *) p, "\xFF" "%lx-%lx", + p += DUK_SPRINTF((char *) p, + "\xFF" + "%lx-%lx", (unsigned long) thr->heap->sym_counter1, (unsigned long) thr->heap->sym_counter0); if (desc == NULL) { @@ -167,4 +169,4 @@ return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_bi_thread.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_bi_thread.c
Changed
@@ -31,7 +31,7 @@ */ duk_push_hobject(new_thr, func); - return 1; /* return thread */ + return 1; /* return thread */ } #endif @@ -77,14 +77,15 @@ */ if (thr->callstack_top < 2) { - DUK_DD(DUK_DDPRINT("resume state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.resume)")); + DUK_DD(DUK_DDPRINT( + "resume state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.resume)")); goto state_error; } DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr))); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ caller_func = DUK_ACT_GET_FUNC(thr->callstack_curr->parent); if (!DUK_HOBJECT_IS_COMPFUNC(caller_func)) { @@ -96,14 +97,12 @@ * like for yield. */ - if (thr_resume->state != DUK_HTHREAD_STATE_INACTIVE && - thr_resume->state != DUK_HTHREAD_STATE_YIELDED) { + if (thr_resume->state != DUK_HTHREAD_STATE_INACTIVE && thr_resume->state != DUK_HTHREAD_STATE_YIELDED) { DUK_DD(DUK_DDPRINT("resume state invalid: target thread must be INACTIVE or YIELDED")); goto state_error; } - DUK_ASSERT(thr_resume->state == DUK_HTHREAD_STATE_INACTIVE || - thr_resume->state == DUK_HTHREAD_STATE_YIELDED); + DUK_ASSERT(thr_resume->state == DUK_HTHREAD_STATE_INACTIVE || thr_resume->state == DUK_HTHREAD_STATE_YIELDED); /* Further state-dependent pre-checks */ @@ -121,14 +120,13 @@ * because an error in the RESUME handler call processing will * not be handled very cleanly. */ - if ((thr_resume->callstack_top != 0) || - (thr_resume->valstack_top - thr_resume->valstack != 1)) { + if ((thr_resume->callstack_top != 0) || (thr_resume->valstack_top - thr_resume->valstack != 1)) { goto state_error; } duk_push_tval(thr, DUK_GET_TVAL_NEGIDX(thr_resume, -1)); duk_resolve_nonbound_function(thr); - h_fun = duk_require_hobject(thr, -1); /* reject lightfuncs on purpose */ + h_fun = duk_require_hobject(thr, -1); /* reject lightfuncs on purpose */ if (!DUK_HOBJECT_IS_CALLABLE(h_fun) || !DUK_HOBJECT_IS_COMPFUNC(h_fun)) { goto state_error; } @@ -157,8 +155,8 @@ #if defined(DUK_USE_AUGMENT_ERROR_THROW) if (is_error) { - DUK_ASSERT_TOP(thr, 2); /* value (error) is at stack top */ - duk_err_augment_error_throw(thr); /* in resumer's context */ + DUK_ASSERT_TOP(thr, 2); /* value (error) is at stack top */ + duk_err_augment_error_throw(thr); /* in resumer's context */ } #endif @@ -182,21 +180,21 @@ /* lj value2: thread */ DUK_ASSERT(thr->valstack_bottom < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value2, &thr->valstack_bottom0); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value2, &thr->valstack_bottom0); /* side effects */ /* lj value1: value */ DUK_ASSERT(thr->valstack_bottom + 1 < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom1); /* side effects */ DUK_TVAL_CHKFAST_INPLACE_SLOW(&thr->heap->lj.value1); thr->heap->lj.iserror = is_error; - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ - duk_err_longjmp(thr); /* execution resumes in bytecode executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ + duk_err_longjmp(thr); /* execution resumes in bytecode executor */ DUK_UNREACHABLE(); /* Never here, fall through to error (from compiler point of view). */ - state_error: +state_error: DUK_DCERROR_TYPE_INVALID_STATE(thr); } #endif @@ -245,14 +243,15 @@ DUK_ASSERT(thr->resumer->state == DUK_HTHREAD_STATE_RESUMED); if (thr->callstack_top < 2) { - DUK_DD(DUK_DDPRINT("yield state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.yield)")); + DUK_DD(DUK_DDPRINT( + "yield state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.yield)")); goto state_error; } DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr))); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ caller_func = DUK_ACT_GET_FUNC(thr->callstack_curr->parent); if (!DUK_HOBJECT_IS_COMPFUNC(caller_func)) { @@ -260,10 +259,11 @@ goto state_error; } - DUK_ASSERT(thr->callstack_preventcount >= 1); /* should never be zero, because we (Duktape.Thread.yield) are on the stack */ + DUK_ASSERT(thr->callstack_preventcount >= 1); /* should never be zero, because we (Duktape.Thread.yield) are on the stack */ if (thr->callstack_preventcount != 1) { /* Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0 */ - DUK_DD(DUK_DDPRINT("yield state invalid: there must be no yield-preventing calls in current thread callstack (preventcount is %ld)", + DUK_DD(DUK_DDPRINT("yield state invalid: there must be no yield-preventing calls in current thread callstack " + "(preventcount is %ld)", (long) thr->callstack_preventcount)); goto state_error; } @@ -277,18 +277,16 @@ #if defined(DUK_USE_AUGMENT_ERROR_THROW) if (is_error) { - DUK_ASSERT_TOP(thr, 1); /* value (error) is at stack top */ - duk_err_augment_error_throw(thr); /* in yielder's context */ + DUK_ASSERT_TOP(thr, 1); /* value (error) is at stack top */ + duk_err_augment_error_throw(thr); /* in yielder's context */ } #endif #if defined(DUK_USE_DEBUG) if (is_error) { - DUK_DDD(DUK_DDDPRINT("YIELD ERROR: value=%!T", - (duk_tval *) duk_get_tval(thr, 0))); + DUK_DDD(DUK_DDDPRINT("YIELD ERROR: value=%!T", (duk_tval *) duk_get_tval(thr, 0))); } else { - DUK_DDD(DUK_DDDPRINT("YIELD NORMAL: value=%!T", - (duk_tval *) duk_get_tval(thr, 0))); + DUK_DDD(DUK_DDDPRINT("YIELD NORMAL: value=%!T", (duk_tval *) duk_get_tval(thr, 0))); } #endif @@ -303,17 +301,17 @@ /* lj value1: value */ DUK_ASSERT(thr->valstack_bottom < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom0); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom0); /* side effects */ DUK_TVAL_CHKFAST_INPLACE_SLOW(&thr->heap->lj.value1); thr->heap->lj.iserror = is_error; - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ - duk_err_longjmp(thr); /* execution resumes in bytecode executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ + duk_err_longjmp(thr); /* execution resumes in bytecode executor */ DUK_UNREACHABLE(); /* Never here, fall through to error (from compiler point of view). */ - state_error: +state_error: DUK_DCERROR_TYPE_INVALID_STATE(thr); } #endif
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_builtins.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_builtins.c
Changed
@@ -363,7 +363,7 @@ 137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35, 23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165, 19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70, -72,115,96,0,0,0,0,0,15,106,32,91,60,165,195,201,194,8,134,149,216,162,0, +72,115,96,0,0,0,0,0,27,234,32,91,60,165,195,201,194,8,134,149,216,162,0, 192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176, 195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20, 1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219, @@ -563,7 +563,7 @@ 137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35, 23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165, 19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70, -72,115,96,32,106,15,0,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, +72,115,96,32,106,27,128,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, 192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176, 195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20, 1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219, @@ -763,7 +763,7 @@ 137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35, 23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165, 19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70, -72,115,96,0,15,106,32,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, +72,115,96,0,27,234,32,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, 192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176, 195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20, 1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219,
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_config.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_config.h
Changed
@@ -1,9 +1,9 @@ /* * duk_config.h configuration header generated by genconfig.py. * - * Git commit: fffa346eff06a8764b02c31d4336f63a773a95c3 - * Git describe: v2.6.0 - * Git branch: v2-maintenance + * Git commit: 03d4d728f8365021de6955c649e6dcd05dcca99f + * Git describe: 03d4d72-dirty + * Git branch: HEAD * * Supported platforms: * - Mac OSX, iPhone, Darwin
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_dblunion.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_dblunion.h
Changed
@@ -66,7 +66,7 @@ duk_uint16_t us4; duk_uint8_t uc8; #if defined(DUK_USE_PACKED_TVAL) - void *vp2; /* used by packed duk_tval, assumes sizeof(void *) == 4 */ + void *vp2; /* used by packed duk_tval, assumes sizeof(void *) == 4 */ #endif }; @@ -78,64 +78,64 @@ #if defined(DUK_USE_DOUBLE_LE) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 +#define DUK_DBL_IDX_ULL0 0 #endif -#define DUK_DBL_IDX_UI0 1 -#define DUK_DBL_IDX_UI1 0 -#define DUK_DBL_IDX_US0 3 -#define DUK_DBL_IDX_US1 2 -#define DUK_DBL_IDX_US2 1 -#define DUK_DBL_IDX_US3 0 -#define DUK_DBL_IDX_UC0 7 -#define DUK_DBL_IDX_UC1 6 -#define DUK_DBL_IDX_UC2 5 -#define DUK_DBL_IDX_UC3 4 -#define DUK_DBL_IDX_UC4 3 -#define DUK_DBL_IDX_UC5 2 -#define DUK_DBL_IDX_UC6 1 -#define DUK_DBL_IDX_UC7 0 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 1 +#define DUK_DBL_IDX_UI1 0 +#define DUK_DBL_IDX_US0 3 +#define DUK_DBL_IDX_US1 2 +#define DUK_DBL_IDX_US2 1 +#define DUK_DBL_IDX_US3 0 +#define DUK_DBL_IDX_UC0 7 +#define DUK_DBL_IDX_UC1 6 +#define DUK_DBL_IDX_UC2 5 +#define DUK_DBL_IDX_UC3 4 +#define DUK_DBL_IDX_UC4 3 +#define DUK_DBL_IDX_UC5 2 +#define DUK_DBL_IDX_UC6 1 +#define DUK_DBL_IDX_UC7 0 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #elif defined(DUK_USE_DOUBLE_BE) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 +#define DUK_DBL_IDX_ULL0 0 #endif -#define DUK_DBL_IDX_UI0 0 -#define DUK_DBL_IDX_UI1 1 -#define DUK_DBL_IDX_US0 0 -#define DUK_DBL_IDX_US1 1 -#define DUK_DBL_IDX_US2 2 -#define DUK_DBL_IDX_US3 3 -#define DUK_DBL_IDX_UC0 0 -#define DUK_DBL_IDX_UC1 1 -#define DUK_DBL_IDX_UC2 2 -#define DUK_DBL_IDX_UC3 3 -#define DUK_DBL_IDX_UC4 4 -#define DUK_DBL_IDX_UC5 5 -#define DUK_DBL_IDX_UC6 6 -#define DUK_DBL_IDX_UC7 7 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 0 +#define DUK_DBL_IDX_UI1 1 +#define DUK_DBL_IDX_US0 0 +#define DUK_DBL_IDX_US1 1 +#define DUK_DBL_IDX_US2 2 +#define DUK_DBL_IDX_US3 3 +#define DUK_DBL_IDX_UC0 0 +#define DUK_DBL_IDX_UC1 1 +#define DUK_DBL_IDX_UC2 2 +#define DUK_DBL_IDX_UC3 3 +#define DUK_DBL_IDX_UC4 4 +#define DUK_DBL_IDX_UC5 5 +#define DUK_DBL_IDX_UC6 6 +#define DUK_DBL_IDX_UC7 7 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #elif defined(DUK_USE_DOUBLE_ME) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */ +#define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */ #endif -#define DUK_DBL_IDX_UI0 0 -#define DUK_DBL_IDX_UI1 1 -#define DUK_DBL_IDX_US0 1 -#define DUK_DBL_IDX_US1 0 -#define DUK_DBL_IDX_US2 3 -#define DUK_DBL_IDX_US3 2 -#define DUK_DBL_IDX_UC0 3 -#define DUK_DBL_IDX_UC1 2 -#define DUK_DBL_IDX_UC2 1 -#define DUK_DBL_IDX_UC3 0 -#define DUK_DBL_IDX_UC4 7 -#define DUK_DBL_IDX_UC5 6 -#define DUK_DBL_IDX_UC6 5 -#define DUK_DBL_IDX_UC7 4 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 0 +#define DUK_DBL_IDX_UI1 1 +#define DUK_DBL_IDX_US0 1 +#define DUK_DBL_IDX_US1 0 +#define DUK_DBL_IDX_US2 3 +#define DUK_DBL_IDX_US3 2 +#define DUK_DBL_IDX_UC0 3 +#define DUK_DBL_IDX_UC1 2 +#define DUK_DBL_IDX_UC2 1 +#define DUK_DBL_IDX_UC3 0 +#define DUK_DBL_IDX_UC4 7 +#define DUK_DBL_IDX_UC5 6 +#define DUK_DBL_IDX_UC6 5 +#define DUK_DBL_IDX_UC7 4 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #else #error internal error #endif @@ -145,57 +145,63 @@ * by duk_numconv.c and duk_tval.h. */ -#define DUK_DBLUNION_SET_DOUBLE(u,v) do { \ +#define DUK_DBLUNION_SET_DOUBLE(u, v) \ + do { \ (u)->d = (v); \ } while (0) -#define DUK_DBLUNION_SET_HIGH32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) (v); \ } while (0) #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = (duk_uint64_t) (v); \ } while (0) #else -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = ((duk_uint64_t) (v)) << 32; \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) (v); \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) 0; \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ -#define DUK_DBLUNION_SET_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_LOW32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d) -#define DUK_DBLUNION_GET_HIGH32(u) ((u)->uiDUK_DBL_IDX_UI0) -#define DUK_DBLUNION_GET_LOW32(u) ((u)->uiDUK_DBL_IDX_UI1) +#define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d) +#define DUK_DBLUNION_GET_HIGH32(u) ((u)->uiDUK_DBL_IDX_UI0) +#define DUK_DBLUNION_GET_LOW32(u) ((u)->uiDUK_DBL_IDX_UI1) #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_SET_UINT64(u,v) do { \ +#define DUK_DBLUNION_SET_UINT64(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) ((v) >> 32); \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_UINT64(u) \ - ((((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI0) << 32) | \ - ((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI1)) +#define DUK_DBLUNION_GET_UINT64(u) ((((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI1)) #else -#define DUK_DBLUNION_SET_UINT64(u,v) do { \ +#define DUK_DBLUNION_SET_UINT64(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = (duk_uint64_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_UINT64(u) ((u)->ullDUK_DBL_IDX_ULL0) +#define DUK_DBLUNION_GET_UINT64(u) ((u)->ullDUK_DBL_IDX_ULL0) #endif -#define DUK_DBLUNION_SET_INT64(u,v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v)) -#define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u))) -#endif /* DUK_USE_64BIT_OPS */ +#define DUK_DBLUNION_SET_INT64(u, v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v)) +#define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u))) +#endif /* DUK_USE_64BIT_OPS */ /* * Double NaN manipulation macros related to NaN normalization needed when @@ -226,102 +232,85 @@ #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) /* Macros for 64-bit ops + mixed endian doubles. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = DUK_U64_CONSTANT(0x000000007ff80000); \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x000000007ff00000)) == DUK_U64_CONSTANT(0x000000007ff00000)) && \ ((((u)->ullDUK_DBL_IDX_ULL0) & DUK_U64_CONSTANT(0xffffffff000fffff)) != 0)) -#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff80000)) +#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff80000)) #define DUK__DBLUNION_IS_ANYINF(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0xffffffff7fffffff)) == DUK_U64_CONSTANT(0x000000007ff00000)) -#define DUK__DBLUNION_IS_POSINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff00000)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x00000000fff00000)) +#define DUK__DBLUNION_IS_POSINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff00000)) +#define DUK__DBLUNION_IS_NEGINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x00000000fff00000)) #define DUK__DBLUNION_IS_ANYZERO(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0xffffffff7fffffff)) == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000080000000)) +#define DUK__DBLUNION_IS_POSZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) +#define DUK__DBLUNION_IS_NEGZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000080000000)) #else /* Macros for 64-bit ops + big/little endian doubles. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = DUK_U64_CONSTANT(0x7ff8000000000000); \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7ff0000000000000)) == DUK_U64_CONSTANT(0x7ff0000000000000)) && \ ((((u)->ullDUK_DBL_IDX_ULL0) & DUK_U64_CONSTANT(0x000fffffffffffff)) != 0)) -#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff8000000000000)) +#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff8000000000000)) #define DUK__DBLUNION_IS_ANYINF(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7fffffffffffffff)) == DUK_U64_CONSTANT(0x7ff0000000000000)) -#define DUK__DBLUNION_IS_POSINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff0000000000000)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0xfff0000000000000)) +#define DUK__DBLUNION_IS_POSINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff0000000000000)) +#define DUK__DBLUNION_IS_NEGINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0xfff0000000000000)) #define DUK__DBLUNION_IS_ANYZERO(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7fffffffffffffff)) == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x8000000000000000)) +#define DUK__DBLUNION_IS_POSZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) +#define DUK__DBLUNION_IS_NEGZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x8000000000000000)) #endif -#else /* DUK_USE_64BIT_OPS */ +#else /* DUK_USE_64BIT_OPS */ /* Macros for no 64-bit ops, any endianness. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) 0x7ff80000UL; \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) 0x00000000UL; \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->uiDUK_DBL_IDX_UI0 & 0x7ff00000UL) == 0x7ff00000UL) && \ - (((u)->uiDUK_DBL_IDX_UI0 & 0x000fffffUL) != 0 || \ - (u)->uiDUK_DBL_IDX_UI1 != 0)) + (((u)->uiDUK_DBL_IDX_UI0 & 0x000fffffUL) != 0 || (u)->uiDUK_DBL_IDX_UI1 != 0)) #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff80000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) + (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff80000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) #define DUK__DBLUNION_IS_ANYINF(u) \ - ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x7ff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_POSINF(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0xfff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) + ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x7ff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_POSINF(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_NEGINF(u) (((u)->uiDUK_DBL_IDX_UI0 == 0xfff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) #define DUK__DBLUNION_IS_ANYZERO(u) \ - ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x00000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x00000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x80000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#endif /* DUK_USE_64BIT_OPS */ + ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x00000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_POSZERO(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x00000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_NEGZERO(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x80000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#endif /* DUK_USE_64BIT_OPS */ -#define DUK__DBLUNION_SET_NAN_NOTFULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_NOTFULL(u) \ + do { \ (u)->usDUK_DBL_IDX_US0 = 0x7ff8UL; \ } while (0) #define DUK__DBLUNION_IS_NAN_NOTFULL(u) \ /* E == 0x7ff, topmost four bits of F != 0 => assume NaN */ \ - ((((u)->usDUK_DBL_IDX_US0 & 0x7ff0UL) == 0x7ff0UL) && \ - (((u)->usDUK_DBL_IDX_US0 & 0x000fUL) != 0x0000UL)) + ((((u)->usDUK_DBL_IDX_US0 & 0x7ff0UL) == 0x7ff0UL) && (((u)->usDUK_DBL_IDX_US0 & 0x000fUL) != 0x0000UL)) #define DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL(u) \ /* E == 0x7ff, F == 8 => normalized NaN */ \ ((u)->usDUK_DBL_IDX_US0 == 0x7ff8UL) -#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) do { \ +#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) \ + do { \ if (DUK__DBLUNION_IS_NAN_FULL((u))) { \ DUK__DBLUNION_SET_NAN_FULL((u)); \ } \ } while (0) -#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) do { \ +#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) \ + do { \ /* Check must be full. */ \ if (DUK__DBLUNION_IS_NAN_FULL((u))) { \ DUK__DBLUNION_SET_NAN_NOTFULL((u)); \ @@ -335,29 +324,30 @@ */ #if defined(DUK_USE_PACKED_TVAL) -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u)) -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u)) -#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d)) +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u)) +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u)) +#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d)) #if 0 -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u)) -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u)) -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u)) -#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d)) +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u)) +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u)) +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u)) +#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d)) #endif #define DUK_DBLUNION_IS_NORMALIZED(u) \ - (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \ - DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */ -#else /* DUK_USE_PACKED_TVAL */ -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */ -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ -#define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */ -#define DUK_DBLUNION_SET_NAN(u) do { \ + (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \ + DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */ +#else /* DUK_USE_PACKED_TVAL */ +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */ +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ +#define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */ +#define DUK_DBLUNION_SET_NAN(u) \ + do { \ /* in non-packed representation we don't care about which NaN is used */ \ (u)->d = DUK_DOUBLE_NAN; \ } while (0) -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ #define DUK_DBLUNION_IS_ANYINF(u) DUK__DBLUNION_IS_ANYINF((u)) #define DUK_DBLUNION_IS_POSINF(u) DUK__DBLUNION_IS_POSINF((u)) @@ -370,7 +360,8 @@ /* XXX: native 64-bit byteswaps when available */ /* 64-bit byteswap, same operation independent of target endianness. */ -#define DUK_DBLUNION_BSWAP64(u) do { \ +#define DUK_DBLUNION_BSWAP64(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -384,7 +375,8 @@ * order. For a big endian target this is a no-op. */ #if defined(DUK_USE_DOUBLE_LE) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { \ +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -394,7 +386,8 @@ (u)->ui1 = duk__bswaptmp1; \ } while (0) #elif defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { \ +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -404,7 +397,9 @@ (u)->ui1 = duk__bswaptmp2; \ } while (0) #elif defined(DUK_USE_DOUBLE_BE) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { } while (0) +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ + } while (0) #else #error internal error, double endianness insane #endif @@ -421,4 +416,4 @@ #define DUK_DBLUNION_GET_SIGNBIT(u) (((u)->uiDUK_DBL_IDX_UI0 >> 31U)) #endif -#endif /* DUK_DBLUNION_H_INCLUDED */ +#endif /* DUK_DBLUNION_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_debug.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_debug.h
Changed
@@ -28,19 +28,25 @@ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) #define DUK_D(x) x #else -#define DUK_D(x) do { } while (0) /* omit */ +#define DUK_D(x) \ + do { \ + } while (0) /* omit */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) #define DUK_DD(x) x #else -#define DUK_DD(x) do { } while (0) /* omit */ +#define DUK_DD(x) \ + do { \ + } while (0) /* omit */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) #define DUK_DDD(x) x #else -#define DUK_DDD(x) do { } while (0) /* omit */ +#define DUK_DDD(x) \ + do { \ + } while (0) /* omit */ #endif /* @@ -52,35 +58,35 @@ /* Note: combining __FILE__, __LINE__, and __func__ into fmt would be * possible compile time, but waste some space with shared function names. */ -#define DUK__DEBUG_LOG(lev,...) duk_debug_log((duk_int_t) (lev), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, DUK_FUNC_MACRO, __VA_ARGS__); +#define DUK__DEBUG_LOG(lev, ...) \ + duk_debug_log((duk_int_t) (lev), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, DUK_FUNC_MACRO, __VA_ARGS__); #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) -#define DUK_DPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DEBUG, __VA_ARGS__) +#define DUK_DPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DEBUG, __VA_ARGS__) #else #define DUK_DPRINT(...) #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) -#define DUK_DDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDEBUG, __VA_ARGS__) +#define DUK_DDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDEBUG, __VA_ARGS__) #else #define DUK_DDPRINT(...) #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK_DDDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDDEBUG, __VA_ARGS__) +#define DUK_DDDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDDEBUG, __VA_ARGS__) #else #define DUK_DDDPRINT(...) #endif -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ -#define DUK__DEBUG_STASH(lev) \ +#define DUK__DEBUG_STASH(lev) \ (void) DUK_SNPRINTF(duk_debug_file_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FILE_MACRO), \ - (void) (duk_debug_file_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ - (void) (duk_debug_line_stash = (duk_int_t) DUK_LINE_MACRO), \ - (void) DUK_SNPRINTF(duk_debug_func_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FUNC_MACRO), \ - (void) (duk_debug_func_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ - (void) (duk_debug_level_stash = (lev)) + (void) (duk_debug_file_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ + (void) (duk_debug_line_stash = (duk_int_t) DUK_LINE_MACRO), \ + (void) DUK_SNPRINTF(duk_debug_func_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FUNC_MACRO), \ + (void) (duk_debug_func_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), (void) (duk_debug_level_stash = (lev)) /* Without variadic macros resort to comma expression trickery to handle debug * prints. This generates a lot of harmless warnings. These hacks are not @@ -89,34 +95,40 @@ */ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) -#define DUK_DPRINT DUK__DEBUG_STASH(DUK_LEVEL_DEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DPRINT DUK__DEBUG_STASH(DUK_LEVEL_DEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ +#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) -#define DUK_DDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DDPRINT 0 && /* args */ +#define DUK_DDPRINT 0 && /* args */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK_DDDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDDEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DDDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDDEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DDDPRINT 0 && /* args */ +#define DUK_DDDPRINT 0 && /* args */ #endif -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#else /* DUK_USE_DEBUG */ +#else /* DUK_USE_DEBUG */ /* * Exposed debug macros: debugging disabled */ -#define DUK_D(x) do { } while (0) /* omit */ -#define DUK_DD(x) do { } while (0) /* omit */ -#define DUK_DDD(x) do { } while (0) /* omit */ +#define DUK_D(x) \ + do { \ + } while (0) /* omit */ +#define DUK_DD(x) \ + do { \ + } while (0) /* omit */ +#define DUK_DDD(x) \ + do { \ + } while (0) /* omit */ #if defined(DUK_USE_VARIADIC_MACROS) @@ -124,15 +136,15 @@ #define DUK_DDPRINT(...) #define DUK_DDDPRINT(...) -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ -#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ -#define DUK_DDPRINT 0 && /* args */ -#define DUK_DDDPRINT 0 && /* args */ +#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ +#define DUK_DDPRINT 0 && /* args */ +#define DUK_DDDPRINT 0 && /* args */ -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Structs @@ -153,16 +165,16 @@ #if defined(DUK_USE_DEBUG) DUK_INTERNAL_DECL duk_int_t duk_debug_vsnprintf(char *str, duk_size_t size, const char *format, va_list ap); -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL duk_int_t duk_debug_snprintf(char *str, duk_size_t size, const char *format, ...); #endif DUK_INTERNAL_DECL void duk_debug_format_funcptr(char *buf, duk_size_t buf_size, duk_uint8_t *fptr, duk_size_t fptr_size); #if defined(DUK_USE_VARIADIC_MACROS) DUK_INTERNAL_DECL void duk_debug_log(duk_int_t level, const char *file, duk_int_t line, const char *func, const char *fmt, ...); -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ /* parameter passing, not thread safe */ -#define DUK_DEBUG_STASH_SIZE 128 +#define DUK_DEBUG_STASH_SIZE 128 #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL char duk_debug_file_stashDUK_DEBUG_STASH_SIZE; DUK_INTERNAL_DECL duk_int_t duk_debug_line_stash; @@ -170,7 +182,7 @@ DUK_INTERNAL_DECL duk_int_t duk_debug_level_stash; #endif DUK_INTERNAL_DECL void duk_debug_log(const char *fmt, ...); -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ DUK_INTERNAL_DECL void duk_fb_put_bytes(duk_fixedbuffer *fb, const duk_uint8_t *buffer, duk_size_t length); DUK_INTERNAL_DECL void duk_fb_put_byte(duk_fixedbuffer *fb, duk_uint8_t x); @@ -179,6 +191,6 @@ DUK_INTERNAL_DECL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size); DUK_INTERNAL_DECL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb); -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ -#endif /* DUK_DEBUG_H_INCLUDED */ +#endif /* DUK_DEBUG_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_debug_fixedbuffer.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_debug_fixedbuffer.c
Changed
@@ -56,7 +56,7 @@ } DUK_INTERNAL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size) { - char buf64+1; + char buf64 + 1; duk_debug_format_funcptr(buf, sizeof(buf), fptr, fptr_size); bufsizeof(buf) - 1 = (char) 0; duk_fb_put_cstring(fb, buf); @@ -66,4 +66,4 @@ return (fb->offset >= fb->length); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_debug_macros.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_debug_macros.c
Changed
@@ -18,7 +18,7 @@ #error debugging enabled (DUK_USE_DEBUG) but DUK_USE_DEBUG_WRITE not defined #endif -#define DUK__DEBUG_BUFSIZE DUK_USE_DEBUG_BUFSIZE +#define DUK__DEBUG_BUFSIZE DUK_USE_DEBUG_BUFSIZE #if defined(DUK_USE_VARIADIC_MACROS) @@ -46,7 +46,7 @@ va_end(ap); } -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ DUK_INTERNAL char duk_debug_file_stashDUK_DEBUG_STASH_SIZE; DUK_INTERNAL duk_int_t duk_debug_line_stash; @@ -77,12 +77,12 @@ va_end(ap); } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#else /* DUK_USE_DEBUG */ +#else /* DUK_USE_DEBUG */ /* * Debugging disabled */ -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_debug_vsnprintf.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_debug_vsnprintf.c
Changed
@@ -63,58 +63,58 @@ /* list of conversion specifiers that terminate a format tag; * this is unfortunately guesswork. */ -#define DUK__ALLOWED_STANDARD_SPECIFIERS "diouxXeEfFgGaAcsCSpnm" +#define DUK__ALLOWED_STANDARD_SPECIFIERS "diouxXeEfFgGaAcsCSpnm" /* maximum length of standard format tag that we support */ -#define DUK__MAX_FORMAT_TAG_LENGTH 32 +#define DUK__MAX_FORMAT_TAG_LENGTH 32 /* heapobj recursion depth when deep printing is selected */ -#define DUK__DEEP_DEPTH_LIMIT 8 +#define DUK__DEEP_DEPTH_LIMIT 8 /* maximum recursion depth for loop detection stacks */ -#define DUK__LOOP_STACK_DEPTH 256 +#define DUK__LOOP_STACK_DEPTH 256 /* must match bytecode defines now; build autogenerate? */ DUK_LOCAL const char * const duk__bc_optab256 = { - "LDREG", "STREG", "JUMP", "LDCONST", "LDINT", "LDINTX", "LDTHIS", "LDUNDEF", - "LDNULL", "LDTRUE", "LDFALSE", "GETVAR", "BNOT", "LNOT", "UNM", "UNP", - "EQ_RR", "EQ_CR", "EQ_RC", "EQ_CC", "NEQ_RR", "NEQ_CR", "NEQ_RC", "NEQ_CC", - "SEQ_RR", "SEQ_CR", "SEQ_RC", "SEQ_CC", "SNEQ_RR", "SNEQ_CR", "SNEQ_RC", "SNEQ_CC", - - "GT_RR", "GT_CR", "GT_RC", "GT_CC", "GE_RR", "GE_CR", "GE_RC", "GE_CC", - "LT_RR", "LT_CR", "LT_RC", "LT_CC", "LE_RR", "LE_CR", "LE_RC", "LE_CC", - "IFTRUE_R", "IFTRUE_C", "IFFALSE_R", "IFFALSE_C", "ADD_RR", "ADD_CR", "ADD_RC", "ADD_CC", - "SUB_RR", "SUB_CR", "SUB_RC", "SUB_CC", "MUL_RR", "MUL_CR", "MUL_RC", "MUL_CC", - - "DIV_RR", "DIV_CR", "DIV_RC", "DIV_CC", "MOD_RR", "MOD_CR", "MOD_RC", "MOD_CC", - "EXP_RR", "EXP_CR", "EXP_RC", "EXP_CC", "BAND_RR", "BAND_CR", "BAND_RC", "BAND_CC", - "BOR_RR", "BOR_CR", "BOR_RC", "BOR_CC", "BXOR_RR", "BXOR_CR", "BXOR_RC", "BXOR_CC", - "BASL_RR", "BASL_CR", "BASL_RC", "BASL_CC", "BLSR_RR", "BLSR_CR", "BLSR_RC", "BLSR_CC", - - "BASR_RR", "BASR_CR", "BASR_RC", "BASR_CC", "INSTOF_RR", "INSTOF_CR", "INSTOF_RC", "INSTOF_CC", - "IN_RR", "IN_CR", "IN_RC", "IN_CC", "GETPROP_RR", "GETPROP_CR", "GETPROP_RC", "GETPROP_CC", - "PUTPROP_RR", "PUTPROP_CR", "PUTPROP_RC", "PUTPROP_CC", "DELPROP_RR", "DELPROP_CR", "DELPROP_RC", "DELPROP_CC", - "PREINCR", "PREDECR", "POSTINCR", "POSTDECR", "PREINCV", "PREDECV", "POSTINCV", "POSTDECV", - - "PREINCP_RR", "PREINCP_CR", "PREINCP_RC", "PREINCP_CC", "PREDECP_RR", "PREDECP_CR", "PREDECP_RC", "PREDECP_CC", + "LDREG", "STREG", "JUMP", "LDCONST", "LDINT", "LDINTX", "LDTHIS", "LDUNDEF", + "LDNULL", "LDTRUE", "LDFALSE", "GETVAR", "BNOT", "LNOT", "UNM", "UNP", + "EQ_RR", "EQ_CR", "EQ_RC", "EQ_CC", "NEQ_RR", "NEQ_CR", "NEQ_RC", "NEQ_CC", + "SEQ_RR", "SEQ_CR", "SEQ_RC", "SEQ_CC", "SNEQ_RR", "SNEQ_CR", "SNEQ_RC", "SNEQ_CC", + + "GT_RR", "GT_CR", "GT_RC", "GT_CC", "GE_RR", "GE_CR", "GE_RC", "GE_CC", + "LT_RR", "LT_CR", "LT_RC", "LT_CC", "LE_RR", "LE_CR", "LE_RC", "LE_CC", + "IFTRUE_R", "IFTRUE_C", "IFFALSE_R", "IFFALSE_C", "ADD_RR", "ADD_CR", "ADD_RC", "ADD_CC", + "SUB_RR", "SUB_CR", "SUB_RC", "SUB_CC", "MUL_RR", "MUL_CR", "MUL_RC", "MUL_CC", + + "DIV_RR", "DIV_CR", "DIV_RC", "DIV_CC", "MOD_RR", "MOD_CR", "MOD_RC", "MOD_CC", + "EXP_RR", "EXP_CR", "EXP_RC", "EXP_CC", "BAND_RR", "BAND_CR", "BAND_RC", "BAND_CC", + "BOR_RR", "BOR_CR", "BOR_RC", "BOR_CC", "BXOR_RR", "BXOR_CR", "BXOR_RC", "BXOR_CC", + "BASL_RR", "BASL_CR", "BASL_RC", "BASL_CC", "BLSR_RR", "BLSR_CR", "BLSR_RC", "BLSR_CC", + + "BASR_RR", "BASR_CR", "BASR_RC", "BASR_CC", "INSTOF_RR", "INSTOF_CR", "INSTOF_RC", "INSTOF_CC", + "IN_RR", "IN_CR", "IN_RC", "IN_CC", "GETPROP_RR", "GETPROP_CR", "GETPROP_RC", "GETPROP_CC", + "PUTPROP_RR", "PUTPROP_CR", "PUTPROP_RC", "PUTPROP_CC", "DELPROP_RR", "DELPROP_CR", "DELPROP_RC", "DELPROP_CC", + "PREINCR", "PREDECR", "POSTINCR", "POSTDECR", "PREINCV", "PREDECV", "POSTINCV", "POSTDECV", + + "PREINCP_RR", "PREINCP_CR", "PREINCP_RC", "PREINCP_CC", "PREDECP_RR", "PREDECP_CR", "PREDECP_RC", "PREDECP_CC", "POSTINCP_RR", "POSTINCP_CR", "POSTINCP_RC", "POSTINCP_CC", "POSTDECP_RR", "POSTDECP_CR", "POSTDECP_RC", "POSTDECP_CC", - "DECLVAR_RR", "DECLVAR_CR", "DECLVAR_RC", "DECLVAR_CC", "REGEXP_RR", "REGEXP_RC", "REGEXP_CR", "REGEXP_CC", - "CLOSURE", "TYPEOF", "TYPEOFID", "PUTVAR", "DELVAR", "RETREG", "RETUNDEF", "RETCONST", - - "RETCONSTN", "LABEL", "ENDLABEL", "BREAK", "CONTINUE", "TRYCATCH", "ENDTRY", "ENDCATCH", - "ENDFIN", "THROW", "INVLHS", "CSREG", "CSVAR_RR", "CSVAR_CR", "CSVAR_RC", "CSVAR_CC", - "CALL0", "CALL1", "CALL2", "CALL3", "CALL4", "CALL5", "CALL6", "CALL7", - "CALL8", "CALL9", "CALL10", "CALL11", "CALL12", "CALL13", "CALL14", "CALL15", - - "NEWOBJ", "NEWARR", "MPUTOBJ", "MPUTOBJI", "INITSET", "INITGET", "MPUTARR", "MPUTARRI", - "SETALEN", "INITENUM", "NEXTENUM", "NEWTARGET", "DEBUGGER", "NOP", "INVALID", "UNUSED207", - "GETPROPC_RR", "GETPROPC_CR", "GETPROPC_RC", "GETPROPC_CC", "UNUSED212", "UNUSED213", "UNUSED214", "UNUSED215", - "UNUSED216", "UNUSED217", "UNUSED218", "UNUSED219", "UNUSED220", "UNUSED221", "UNUSED222", "UNUSED223", - - "UNUSED224", "UNUSED225", "UNUSED226", "UNUSED227", "UNUSED228", "UNUSED229", "UNUSED230", "UNUSED231", - "UNUSED232", "UNUSED233", "UNUSED234", "UNUSED235", "UNUSED236", "UNUSED237", "UNUSED238", "UNUSED239", - "UNUSED240", "UNUSED241", "UNUSED242", "UNUSED243", "UNUSED244", "UNUSED245", "UNUSED246", "UNUSED247", - "UNUSED248", "UNUSED249", "UNUSED250", "UNUSED251", "UNUSED252", "UNUSED253", "UNUSED254", "UNUSED255" + "DECLVAR_RR", "DECLVAR_CR", "DECLVAR_RC", "DECLVAR_CC", "REGEXP_RR", "REGEXP_RC", "REGEXP_CR", "REGEXP_CC", + "CLOSURE", "TYPEOF", "TYPEOFID", "PUTVAR", "DELVAR", "RETREG", "RETUNDEF", "RETCONST", + + "RETCONSTN", "LABEL", "ENDLABEL", "BREAK", "CONTINUE", "TRYCATCH", "ENDTRY", "ENDCATCH", + "ENDFIN", "THROW", "INVLHS", "CSREG", "CSVAR_RR", "CSVAR_CR", "CSVAR_RC", "CSVAR_CC", + "CALL0", "CALL1", "CALL2", "CALL3", "CALL4", "CALL5", "CALL6", "CALL7", + "CALL8", "CALL9", "CALL10", "CALL11", "CALL12", "CALL13", "CALL14", "CALL15", + + "NEWOBJ", "NEWARR", "MPUTOBJ", "MPUTOBJI", "INITSET", "INITGET", "MPUTARR", "MPUTARRI", + "SETALEN", "INITENUM", "NEXTENUM", "NEWTARGET", "DEBUGGER", "NOP", "INVALID", "UNUSED207", + "GETPROPC_RR", "GETPROPC_CR", "GETPROPC_RC", "GETPROPC_CC", "UNUSED212", "UNUSED213", "UNUSED214", "UNUSED215", + "UNUSED216", "UNUSED217", "UNUSED218", "UNUSED219", "UNUSED220", "UNUSED221", "UNUSED222", "UNUSED223", + + "UNUSED224", "UNUSED225", "UNUSED226", "UNUSED227", "UNUSED228", "UNUSED229", "UNUSED230", "UNUSED231", + "UNUSED232", "UNUSED233", "UNUSED234", "UNUSED235", "UNUSED236", "UNUSED237", "UNUSED238", "UNUSED239", + "UNUSED240", "UNUSED241", "UNUSED242", "UNUSED243", "UNUSED244", "UNUSED245", "UNUSED246", "UNUSED247", + "UNUSED248", "UNUSED249", "UNUSED250", "UNUSED251", "UNUSED252", "UNUSED253", "UNUSED254", "UNUSED255" }; typedef struct duk__dprint_state duk__dprint_state; @@ -164,14 +164,15 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*h); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)h)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) h)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } -#if defined(DUK_USE_REFERENCE_COUNTING) /* currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP */ +#if defined(DUK_USE_REFERENCE_COUNTING) /* currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP */ if (st->heavy) { - duk_fb_sprintf(fb, "h_next=%p,h_prev=%p,h_refcount=%lu,h_flags=%08lx,type=%ld," + duk_fb_sprintf(fb, + "h_next=%p,h_prev=%p,h_refcount=%lu,h_flags=%08lx,type=%ld," "reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (void *) DUK_HEAPHDR_GET_NEXT(NULL, h), (void *) DUK_HEAPHDR_GET_PREV(NULL, h), @@ -185,7 +186,8 @@ } #else if (st->heavy) { - duk_fb_sprintf(fb, "h_next=%p,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_next=%p,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (void *) DUK_HEAPHDR_GET_NEXT(NULL, h), (unsigned long) DUK_HEAPHDR_GET_FLAGS(h), (long) DUK_HEAPHDR_GET_TYPE(h), @@ -212,14 +214,15 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*h); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)h)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) h)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } #if defined(DUK_USE_REFERENCE_COUNTING) if (st->heavy) { - duk_fb_sprintf(fb, "h_refcount=%lu,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_refcount=%lu,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h), (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h), (long) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h), @@ -230,7 +233,8 @@ } #else if (st->heavy) { - duk_fb_sprintf(fb, "h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h), (long) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h), (long) (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h) ? 1 : 0), @@ -301,7 +305,8 @@ #endif } -#define DUK__COMMA() do { \ +#define DUK__COMMA() \ + do { \ if (first) { \ first = 0; \ } else { \ @@ -414,7 +419,8 @@ duk__print_hstring(st, key, 0); duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_COLON); if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(NULL, h, i)) { - duk_fb_sprintf(fb, "get:%p,set:%p", + duk_fb_sprintf(fb, + "get:%p,set:%p", (void *) DUK_HOBJECT_E_GET_VALUE(NULL, h, i).a.get, (void *) DUK_HOBJECT_E_GET_VALUE(NULL, h, i).a.set); } else { @@ -428,158 +434,238 @@ } if (st->internal) { if (DUK_HOBJECT_IS_ARRAY(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__array:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__array:true"); } if (DUK_HOBJECT_HAS_EXTENSIBLE(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__extensible:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__extensible:true"); } if (DUK_HOBJECT_HAS_CONSTRUCTABLE(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__constructable:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__constructable:true"); } if (DUK_HOBJECT_HAS_BOUNDFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__boundfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__boundfunc:true"); } if (DUK_HOBJECT_HAS_COMPFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__compfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__compfunc:true"); } if (DUK_HOBJECT_HAS_NATFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__natfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__natfunc:true"); } if (DUK_HOBJECT_HAS_BUFOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__bufobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__bufobj:true"); } if (DUK_HOBJECT_IS_THREAD(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__thread:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__thread:true"); } if (DUK_HOBJECT_HAS_ARRAY_PART(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__array_part:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__array_part:true"); } if (DUK_HOBJECT_HAS_STRICT(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__strict:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__strict:true"); } if (DUK_HOBJECT_HAS_NOTAIL(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__notail:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__notail:true"); } if (DUK_HOBJECT_HAS_NEWENV(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__newenv:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__newenv:true"); } if (DUK_HOBJECT_HAS_NAMEBINDING(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__namebinding:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__namebinding:true"); } if (DUK_HOBJECT_HAS_CREATEARGS(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__createargs:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__createargs:true"); } if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_array:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_array:true"); } if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_stringobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_stringobj:true"); } if (DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_arguments:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_arguments:true"); } if (DUK_HOBJECT_IS_BUFOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_bufobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_bufobj:true"); } if (DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_proxyobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_proxyobj:true"); } } if (st->internal && DUK_HOBJECT_IS_ARRAY(h)) { duk_harray *a = (duk_harray *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__length:%ld", (long) a->length); - DUK__COMMA(); duk_fb_sprintf(fb, "__length_nonwritable:%ld", (long) a->length_nonwritable); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length:%ld", (long) a->length); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length_nonwritable:%ld", (long) a->length_nonwritable); } else if (st->internal && DUK_HOBJECT_IS_COMPFUNC(h)) { duk_hcompfunc *f = (duk_hcompfunc *) h; - DUK__COMMA(); duk_fb_put_cstring(fb, "__data:"); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__data:"); duk__print_hbuffer(st, (duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA(NULL, f)); - DUK__COMMA(); duk_fb_put_cstring(fb, "__lexenv:"); duk__print_hobject(st, DUK_HCOMPFUNC_GET_LEXENV(NULL, f)); - DUK__COMMA(); duk_fb_put_cstring(fb, "__varenv:"); duk__print_hobject(st, DUK_HCOMPFUNC_GET_VARENV(NULL, f)); - DUK__COMMA(); duk_fb_sprintf(fb, "__nregs:%ld", (long) f->nregs); - DUK__COMMA(); duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__lexenv:"); + duk__print_hobject(st, DUK_HCOMPFUNC_GET_LEXENV(NULL, f)); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__varenv:"); + duk__print_hobject(st, DUK_HCOMPFUNC_GET_VARENV(NULL, f)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nregs:%ld", (long) f->nregs); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); #if defined(DUK_USE_DEBUGGER_SUPPORT) - DUK__COMMA(); duk_fb_sprintf(fb, "__start_line:%ld", (long) f->start_line); - DUK__COMMA(); duk_fb_sprintf(fb, "__end_line:%ld", (long) f->end_line); + DUK__COMMA(); + duk_fb_sprintf(fb, "__start_line:%ld", (long) f->start_line); + DUK__COMMA(); + duk_fb_sprintf(fb, "__end_line:%ld", (long) f->end_line); #endif - DUK__COMMA(); duk_fb_put_cstring(fb, "__data:"); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__data:"); duk__print_hbuffer(st, (duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA(NULL, f)); } else if (st->internal && DUK_HOBJECT_IS_NATFUNC(h)) { duk_hnatfunc *f = (duk_hnatfunc *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__func:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__func:"); duk_fb_put_funcptr(fb, (duk_uint8_t *) &f->func, sizeof(f->func)); - DUK__COMMA(); duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); - DUK__COMMA(); duk_fb_sprintf(fb, "__magic:%ld", (long) f->magic); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); + DUK__COMMA(); + duk_fb_sprintf(fb, "__magic:%ld", (long) f->magic); } else if (st->internal && DUK_HOBJECT_IS_DECENV(h)) { duk_hdecenv *e = (duk_hdecenv *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__thread:"); duk__print_hobject(st, (duk_hobject *) e->thread); - DUK__COMMA(); duk_fb_sprintf(fb, "__varmap:"); duk__print_hobject(st, (duk_hobject *) e->varmap); - DUK__COMMA(); duk_fb_sprintf(fb, "__regbase_byteoff:%ld", (long) e->regbase_byteoff); + DUK__COMMA(); + duk_fb_sprintf(fb, "__thread:"); + duk__print_hobject(st, (duk_hobject *) e->thread); + DUK__COMMA(); + duk_fb_sprintf(fb, "__varmap:"); + duk__print_hobject(st, (duk_hobject *) e->varmap); + DUK__COMMA(); + duk_fb_sprintf(fb, "__regbase_byteoff:%ld", (long) e->regbase_byteoff); } else if (st->internal && DUK_HOBJECT_IS_OBJENV(h)) { duk_hobjenv *e = (duk_hobjenv *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__target:"); duk__print_hobject(st, (duk_hobject *) e->target); - DUK__COMMA(); duk_fb_sprintf(fb, "__has_this:%ld", (long) e->has_this); + DUK__COMMA(); + duk_fb_sprintf(fb, "__target:"); + duk__print_hobject(st, (duk_hobject *) e->target); + DUK__COMMA(); + duk_fb_sprintf(fb, "__has_this:%ld", (long) e->has_this); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) } else if (st->internal && DUK_HOBJECT_IS_BUFOBJ(h)) { duk_hbufobj *b = (duk_hbufobj *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__buf:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__buf:"); duk__print_hbuffer(st, (duk_hbuffer *) b->buf); - DUK__COMMA(); duk_fb_sprintf(fb, "__buf_prop:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__buf_prop:"); duk__print_hobject(st, (duk_hobject *) b->buf_prop); - DUK__COMMA(); duk_fb_sprintf(fb, "__offset:%ld", (long) b->offset); - DUK__COMMA(); duk_fb_sprintf(fb, "__length:%ld", (long) b->length); - DUK__COMMA(); duk_fb_sprintf(fb, "__shift:%ld", (long) b->shift); - DUK__COMMA(); duk_fb_sprintf(fb, "__elemtype:%ld", (long) b->elem_type); + DUK__COMMA(); + duk_fb_sprintf(fb, "__offset:%ld", (long) b->offset); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length:%ld", (long) b->length); + DUK__COMMA(); + duk_fb_sprintf(fb, "__shift:%ld", (long) b->shift); + DUK__COMMA(); + duk_fb_sprintf(fb, "__elemtype:%ld", (long) b->elem_type); #endif } else if (st->internal && DUK_HOBJECT_IS_PROXY(h)) { duk_hproxy *p = (duk_hproxy *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__target:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__target:"); duk__print_hobject(st, p->target); - DUK__COMMA(); duk_fb_sprintf(fb, "__handler:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__handler:"); duk__print_hobject(st, p->handler); } else if (st->internal && DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__ptr_curr_pc:%p", (void *) t->ptr_curr_pc); - DUK__COMMA(); duk_fb_sprintf(fb, "__heap:%p", (void *) t->heap); - DUK__COMMA(); duk_fb_sprintf(fb, "__strict:%ld", (long) t->strict); - DUK__COMMA(); duk_fb_sprintf(fb, "__state:%ld", (long) t->state); - DUK__COMMA(); duk_fb_sprintf(fb, "__unused1:%ld", (long) t->unused1); - DUK__COMMA(); duk_fb_sprintf(fb, "__unused2:%ld", (long) t->unused2); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack:%p", (void *) t->valstack); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_end:%p/%ld", (void *) t->valstack_end, (long) (t->valstack_end - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_alloc_end:%p/%ld", (void *) t->valstack_alloc_end, (long) (t->valstack_alloc_end - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_bottom:%p/%ld", (void *) t->valstack_bottom, (long) (t->valstack_bottom - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_top:%p/%ld", (void *) t->valstack_top, (long) (t->valstack_top - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_curr:%p", (void *) t->callstack_curr); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_top:%ld", (long) t->callstack_top); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_preventcount:%ld", (long) t->callstack_preventcount); - DUK__COMMA(); duk_fb_sprintf(fb, "__resumer:"); duk__print_hobject(st, (duk_hobject *) t->resumer); - DUK__COMMA(); duk_fb_sprintf(fb, "__compile_ctx:%p", (void *) t->compile_ctx); + DUK__COMMA(); + duk_fb_sprintf(fb, "__ptr_curr_pc:%p", (void *) t->ptr_curr_pc); + DUK__COMMA(); + duk_fb_sprintf(fb, "__heap:%p", (void *) t->heap); + DUK__COMMA(); + duk_fb_sprintf(fb, "__strict:%ld", (long) t->strict); + DUK__COMMA(); + duk_fb_sprintf(fb, "__state:%ld", (long) t->state); + DUK__COMMA(); + duk_fb_sprintf(fb, "__unused1:%ld", (long) t->unused1); + DUK__COMMA(); + duk_fb_sprintf(fb, "__unused2:%ld", (long) t->unused2); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack:%p", (void *) t->valstack); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack_end:%p/%ld", (void *) t->valstack_end, (long) (t->valstack_end - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, + "__valstack_alloc_end:%p/%ld", + (void *) t->valstack_alloc_end, + (long) (t->valstack_alloc_end - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, + "__valstack_bottom:%p/%ld", + (void *) t->valstack_bottom, + (long) (t->valstack_bottom - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack_top:%p/%ld", (void *) t->valstack_top, (long) (t->valstack_top - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_curr:%p", (void *) t->callstack_curr); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_top:%ld", (long) t->callstack_top); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_preventcount:%ld", (long) t->callstack_preventcount); + DUK__COMMA(); + duk_fb_sprintf(fb, "__resumer:"); + duk__print_hobject(st, (duk_hobject *) t->resumer); + DUK__COMMA(); + duk_fb_sprintf(fb, "__compile_ctx:%p", (void *) t->compile_ctx); #if defined(DUK_USE_INTERRUPT_COUNTER) - DUK__COMMA(); duk_fb_sprintf(fb, "__interrupt_counter:%ld", (long) t->interrupt_counter); - DUK__COMMA(); duk_fb_sprintf(fb, "__interrupt_init:%ld", (long) t->interrupt_init); + DUK__COMMA(); + duk_fb_sprintf(fb, "__interrupt_counter:%ld", (long) t->interrupt_counter); + DUK__COMMA(); + duk_fb_sprintf(fb, "__interrupt_init:%ld", (long) t->interrupt_init); #endif /* XXX: print built-ins array? */ - } #if defined(DUK_USE_REFERENCE_COUNTING) if (st->internal) { - DUK__COMMA(); duk_fb_sprintf(fb, "__refcount:%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__refcount:%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h)); } #endif if (st->internal) { - DUK__COMMA(); duk_fb_sprintf(fb, "__class:%ld", (long) DUK_HOBJECT_GET_CLASS_NUMBER(h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__class:%ld", (long) DUK_HOBJECT_GET_CLASS_NUMBER(h)); } - DUK__COMMA(); duk_fb_sprintf(fb, "__heapptr:%p", (void *) h); /* own pointer */ + DUK__COMMA(); + duk_fb_sprintf(fb, "__heapptr:%p", (void *) h); /* own pointer */ /* prototype should be last, for readability */ if (DUK_HOBJECT_GET_PROTOTYPE(NULL, h)) { if (st->follow_proto) { - DUK__COMMA(); duk_fb_put_cstring(fb, "__prototype:"); duk__print_hobject(st, DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__prototype:"); + duk__print_hobject(st, DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); } else { - DUK__COMMA(); duk_fb_sprintf(fb, "__prototype:%p", (void *) DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__prototype:%p", (void *) DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); } } @@ -605,7 +691,7 @@ } #endif - finished: +finished: st->depth--; if (pushed_loopstack) { st->loop_stack_index--; @@ -632,12 +718,14 @@ if (DUK_HBUFFER_HAS_DYNAMIC(h)) { if (DUK_HBUFFER_HAS_EXTERNAL(h)) { duk_hbuffer_external *g = (duk_hbuffer_external *) h; - duk_fb_sprintf(fb, "buffer:external:%p:%ld", + duk_fb_sprintf(fb, + "buffer:external:%p:%ld", (void *) DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(NULL, g), (long) DUK_HBUFFER_EXTERNAL_GET_SIZE(g)); } else { duk_hbuffer_dynamic *g = (duk_hbuffer_dynamic *) h; - duk_fb_sprintf(fb, "buffer:dynamic:%p:%ld", + duk_fb_sprintf(fb, + "buffer:dynamic:%p:%ld", (void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(NULL, g), (long) DUK_HBUFFER_DYNAMIC_GET_SIZE(g)); } @@ -710,7 +798,7 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*tv); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)tv)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) tv)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } @@ -793,17 +881,22 @@ /* XXX: option to fix opcode length so it lines up nicely */ if (op == DUK_OP_JUMP) { - duk_int_t diff1 = (duk_int_t) (DUK_DEC_ABC(ins) - DUK_BC_JUMP_BIAS); /* from next pc */ - duk_int_t diff2 = diff1 + 1; /* from curr pc */ - - duk_fb_sprintf(fb, "%s %ld (to pc%c%ld)", - (const char *) op_name, (long) diff1, - (int) (diff2 >= 0 ? '+' : '-'), /* char format: use int */ + duk_int_t diff1 = (duk_int_t) (DUK_DEC_ABC(ins) - DUK_BC_JUMP_BIAS); /* from next pc */ + duk_int_t diff2 = diff1 + 1; /* from curr pc */ + + duk_fb_sprintf(fb, + "%s %ld (to pc%c%ld)", + (const char *) op_name, + (long) diff1, + (int) (diff2 >= 0 ? '+' : '-'), /* char format: use int */ (long) (diff2 >= 0 ? diff2 : -diff2)); } else { - duk_fb_sprintf(fb, "%s %ld, %ld, %ld", - (const char *) op_name, (long) DUK_DEC_A(ins), - (long) DUK_DEC_B(ins), (long) DUK_DEC_C(ins)); + duk_fb_sprintf(fb, + "%s %ld, %ld, %ld", + (const char *) op_name, + (long) DUK_DEC_A(ins), + (long) DUK_DEC_B(ins), + (long) DUK_DEC_C(ins)); } } @@ -829,13 +922,16 @@ return; } - duk_fb_sprintf(fb, "catcher ptr=%p parent=%p varname=%p pc_base=%p, idx_base=%ld, flags=0x%08lx", + duk_fb_sprintf(fb, + "catcher ptr=%p parent=%p varname=%p pc_base=%p, idx_base=%ld, flags=0x%08lx", (void *) cat, - (void *) cat->parent, (void *) cat->h_varname, (void *) cat->pc_base, - (long) cat->idx_base, (unsigned long) cat->flags); + (void *) cat->parent, + (void *) cat->h_varname, + (void *) cat->pc_base, + (long) cat->idx_base, + (unsigned long) cat->flags); } - DUK_LOCAL void duk__print_activation(duk__dprint_state *st, duk_activation *act) { duk_fixedbuffer *fb = st->fb; @@ -850,12 +946,20 @@ /* prev_caller: conditional, omitted on purpose, it's rarely used. */ /* prev_line: conditional, omitted on purpose (but would be nice). */ - duk_fb_sprintf(fb, "activation ptr=%p tv_func=<omit> func=%p parent=%p var_env=%p lex_env=%p cat=%p curr_pc=%p bottom_byteoff=%ld retval_byteoff=%ld reserve_byteoff=%ld flags=%ld", + duk_fb_sprintf(fb, + "activation ptr=%p tv_func=<omit> func=%p parent=%p var_env=%p lex_env=%p cat=%p curr_pc=%p " + "bottom_byteoff=%ld retval_byteoff=%ld reserve_byteoff=%ld flags=%ld", (void *) act, - (void *) act->func, (void *) act->parent, (void *) act->var_env, - (void *) act->lex_env, (void *) act->cat, (void *) act->curr_pc, - (long) act->bottom_byteoff, (long) act->retval_byteoff, (long) act->reserve_byteoff, - (long) act->flags); + (void *) act->func, + (void *) act->parent, + (void *) act->var_env, + (void *) act->lex_env, + (void *) act->cat, + (void *) act->curr_pc, + (long) act->bottom_byteoff, + (long) act->retval_byteoff, + (long) act->reserve_byteoff, + (long) act->flags); } DUK_INTERNAL duk_int_t duk_debug_vsnprintf(char *str, duk_size_t size, const char *format, va_list ap) { @@ -874,7 +978,7 @@ char ch = *p++; const char *p_begfmt = NULL; duk_bool_t got_exclamation = 0; - duk_bool_t got_long = 0; /* %lf, %ld etc */ + duk_bool_t got_long = 0; /* %lf, %ld etc */ duk__dprint_state st; if (ch != DUK_ASC_PERCENT) { @@ -1037,11 +1141,11 @@ } goto done; - format_error: +format_error: duk_fb_put_cstring(&fb, "FMTERR"); /* fall through */ - done: +done: retval = (duk_int_t) fb.offset; duk_fb_put_byte(&fb, (duk_uint8_t) 0); @@ -1049,7 +1153,7 @@ return retval; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_int_t duk_debug_snprintf(char *str, duk_size_t size, const char *format, ...) { duk_int_t retval; va_list ap; @@ -1090,4 +1194,4 @@ } } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_debugger.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_debugger.c
Changed
@@ -11,17 +11,23 @@ */ #if defined(DUK_USE_ASSERTIONS) -#define DUK__DBG_TPORT_ENTER() do { \ +#define DUK__DBG_TPORT_ENTER() \ + do { \ DUK_ASSERT(heap->dbg_calling_transport == 0); \ heap->dbg_calling_transport = 1; \ } while (0) -#define DUK__DBG_TPORT_EXIT() do { \ +#define DUK__DBG_TPORT_EXIT() \ + do { \ DUK_ASSERT(heap->dbg_calling_transport == 1); \ heap->dbg_calling_transport = 0; \ } while (0) #else -#define DUK__DBG_TPORT_ENTER() do {} while (0) -#define DUK__DBG_TPORT_EXIT() do {} while (0) +#define DUK__DBG_TPORT_ENTER() \ + do { \ + } while (0) +#define DUK__DBG_TPORT_EXIT() \ + do { \ + } while (0) #endif /* @@ -41,7 +47,8 @@ * Detach handling */ -#define DUK__SET_CONN_BROKEN(thr,reason) do { \ +#define DUK__SET_CONN_BROKEN(thr, reason) \ + do { \ /* For now shared handler is fine. */ \ duk__debug_do_detach1((thr)->heap, (reason)); \ } while (0) @@ -62,7 +69,7 @@ DUK_D(DUK_DPRINT("debugger transport detaching, marking transport broken")); - heap->dbg_detaching = 1; /* prevent multiple in-progress detaches */ + heap->dbg_detaching = 1; /* prevent multiple in-progress detaches */ if (heap->dbg_write_cb != NULL) { duk_hthread *thr; @@ -90,8 +97,8 @@ heap->dbg_pause_act = NULL; heap->dbg_pause_startline = 0; heap->dbg_have_next_byte = 0; - duk_debug_clear_paused(heap); /* XXX: some overlap with field inits above */ - heap->dbg_state_dirty = 0; /* XXX: clear_paused sets dirty; rework? */ + duk_debug_clear_paused(heap); /* XXX: some overlap with field inits above */ + heap->dbg_state_dirty = 0; /* XXX: clear_paused sets dirty; rework? */ /* Ensure there are no stale active breakpoint pointers. * Breakpoint list is currently kept - we could empty it @@ -151,7 +158,7 @@ heap = thr->heap; DUK_D(DUK_DPRINT("transport read/write error, NULL all callbacks expected detached")); heap->dbg_read_cb = NULL; - heap->dbg_write_cb = NULL; /* this is especially critical to avoid another write call in detach1() */ + heap->dbg_write_cb = NULL; /* this is especially critical to avoid another write call in detach1() */ heap->dbg_peek_cb = NULL; heap->dbg_read_flush_cb = NULL; heap->dbg_write_flush_cb = NULL; @@ -173,7 +180,8 @@ updated_flags = pause_flags & ~(DUK_PAUSE_FLAG_LINE_CHANGE); DUK_D(DUK_DPRINT("no line info for current activation, disable line-based pause flags: 0x%08lx -> 0x%08lx", - (long) pause_flags, (long) updated_flags)); + (long) pause_flags, + (long) updated_flags)); pause_flags = updated_flags; } @@ -183,7 +191,8 @@ heap->dbg_state_dirty = 1; DUK_D(DUK_DPRINT("set state for automatic pause triggers, flags=0x%08lx, act=%p, startline=%ld", - (long) heap->dbg_pause_flags, (void *) heap->dbg_pause_act, + (long) heap->dbg_pause_flags, + (void *) heap->dbg_pause_act, (long) heap->dbg_pause_startline)); } @@ -338,7 +347,7 @@ if (got == 0 || got > left) { DUK_D(DUK_DPRINT("connection error during read, return zero data")); - duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ + duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ DUK__SET_CONN_BROKEN(thr, 1); goto fail; } @@ -346,14 +355,14 @@ } return; - fail: +fail: duk_memzero((void *) data, (size_t) length); } DUK_INTERNAL duk_uint8_t duk_debug_read_byte(duk_hthread *thr) { duk_uint8_t x; - x = 0; /* just in case callback is broken and won't write 'x' */ + x = 0; /* just in case callback is broken and won't write 'x' */ duk_debug_read_bytes(thr, &x, 1); return x; } @@ -364,10 +373,7 @@ DUK_ASSERT(thr != NULL); duk_debug_read_bytes(thr, buf, 4); - return ((duk_uint32_t) buf0 << 24) | - ((duk_uint32_t) buf1 << 16) | - ((duk_uint32_t) buf2 << 8) | - (duk_uint32_t) buf3; + return ((duk_uint32_t) buf0 << 24) | ((duk_uint32_t) buf1 << 16) | ((duk_uint32_t) buf2 << 8) | (duk_uint32_t) buf3; } DUK_LOCAL duk_int32_t duk__debug_read_int32_raw(duk_hthread *thr) { @@ -380,8 +386,7 @@ DUK_ASSERT(thr != NULL); duk_debug_read_bytes(thr, buf, 2); - return ((duk_uint16_t) buf0 << 8) | - (duk_uint16_t) buf1; + return ((duk_uint16_t) buf0 << 8) | (duk_uint16_t) buf1; } DUK_INTERNAL duk_int32_t duk_debug_read_int(duk_hthread *thr) { @@ -413,10 +418,10 @@ duk_debug_read_bytes(thr, buf, (duk_size_t) len); duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); } else { - p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ + p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ DUK_ASSERT(p != NULL); duk_debug_read_bytes(thr, p, (duk_size_t) len); - (void) duk_buffer_to_string(thr, -1); /* Safety relies on debug client, which is OK. */ + (void) duk_buffer_to_string(thr, -1); /* Safety relies on debug client, which is OK. */ } return duk_require_hstring(thr, -1); @@ -442,17 +447,17 @@ return duk__debug_read_hstring_raw(thr, len); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode int")); DUK__SET_CONN_BROKEN(thr, 1); - duk_push_hstring_empty(thr); /* always push some string */ + duk_push_hstring_empty(thr); /* always push some string */ return duk_require_hstring(thr, -1); } DUK_LOCAL duk_hbuffer *duk__debug_read_hbuffer_raw(duk_hthread *thr, duk_uint32_t len) { duk_uint8_t *p; - p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ + p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ DUK_ASSERT(p != NULL); duk_debug_read_bytes(thr, p, (duk_size_t) len); @@ -475,7 +480,7 @@ #endif return (void *) pu.p; - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode pointer")); DUK__SET_CONN_BROKEN(thr, 1); return (void *) NULL; @@ -533,7 +538,7 @@ return (duk_heaphdr *) duk__debug_read_pointer_raw(thr); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode any pointer (object, pointer, heapptr)")); DUK__SET_CONN_BROKEN(thr, 1); return NULL; @@ -639,15 +644,15 @@ duk_push_heapptr(thr, (void *) h); break; } - case DUK_DBG_IB_UNUSED: /* unused: not accepted in inbound messages */ + case DUK_DBG_IB_UNUSED: /* unused: not accepted in inbound messages */ default: goto fail; } - return_ptr: +return_ptr: return DUK_GET_TVAL_NEGIDX(thr, -1); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode tval")); DUK__SET_CONN_BROKEN(thr, 1); return NULL; @@ -697,7 +702,7 @@ DUK__DBG_TPORT_EXIT(); if (got == 0 || got > left) { - duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ + duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ DUK_D(DUK_DPRINT("connection error during write")); DUK__SET_CONN_BROKEN(thr, 1); return; @@ -764,8 +769,7 @@ * unsigned 32-bit dvalue. */ if (x >= 0x80000000UL) { - DUK_D(DUK_DPRINT("writing unsigned integer 0x%08lx as signed integer", - (long) x)); + DUK_D(DUK_DPRINT("writing unsigned integer 0x%08lx as signed integer", (long) x)); } duk_debug_write_int(thr, (duk_int32_t) x); } @@ -806,9 +810,7 @@ DUK_INTERNAL void duk_debug_write_cstring(duk_hthread *thr, const char *data) { DUK_ASSERT(thr != NULL); - duk_debug_write_string(thr, - data, - data ? DUK_STRLEN(data) : 0); + duk_debug_write_string(thr, data, data ? DUK_STRLEN(data) : 0); } DUK_INTERNAL void duk_debug_write_hstring(duk_hthread *thr, duk_hstring *h) { @@ -862,7 +864,7 @@ DUK_INTERNAL void duk_debug_write_heapptr(duk_hthread *thr, duk_heaphdr *h) { duk__debug_write_pointer_raw(thr, (void *) h, DUK_DBG_IB_HEAPPTR); } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT */ DUK_INTERNAL void duk_debug_write_hobject(duk_hthread *thr, duk_hobject *obj) { duk_uint8_t buf3; @@ -905,8 +907,7 @@ duk_debug_write_byte(thr, DUK_DBG_IB_NULL); break; case DUK_TAG_BOOLEAN: - DUK_ASSERT(DUK_TVAL_GET_BOOLEAN(tv) == 0 || - DUK_TVAL_GET_BOOLEAN(tv) == 1); + DUK_ASSERT(DUK_TVAL_GET_BOOLEAN(tv) == 0 || DUK_TVAL_GET_BOOLEAN(tv) == 1); duk_debug_write_boolean(thr, DUK_TVAL_GET_BOOLEAN(tv)); break; case DUK_TAG_POINTER: @@ -951,14 +952,22 @@ DUK_DD(DUK_DDPRINT("i32=%ld du1=%02x%02x%02x%02x%02x%02x%02x%02x " "du2=%02x%02x%02x%02x%02x%02x%02x%02x", (long) i32, - (unsigned int) du1.uc0, (unsigned int) du1.uc1, - (unsigned int) du1.uc2, (unsigned int) du1.uc3, - (unsigned int) du1.uc4, (unsigned int) du1.uc5, - (unsigned int) du1.uc6, (unsigned int) du1.uc7, - (unsigned int) du2.uc0, (unsigned int) du2.uc1, - (unsigned int) du2.uc2, (unsigned int) du2.uc3, - (unsigned int) du2.uc4, (unsigned int) du2.uc5, - (unsigned int) du2.uc6, (unsigned int) du2.uc7)); + (unsigned int) du1.uc0, + (unsigned int) du1.uc1, + (unsigned int) du1.uc2, + (unsigned int) du1.uc3, + (unsigned int) du1.uc4, + (unsigned int) du1.uc5, + (unsigned int) du1.uc6, + (unsigned int) du1.uc7, + (unsigned int) du2.uc0, + (unsigned int) du2.uc1, + (unsigned int) du2.uc2, + (unsigned int) du2.uc3, + (unsigned int) du2.uc4, + (unsigned int) du2.uc5, + (unsigned int) du2.uc6, + (unsigned int) du2.uc7)); if (duk_memcmp((const void *) du1.uc, (const void *) du2.uc, sizeof(du1.uc)) == 0) { duk_debug_write_int(thr, i32); @@ -982,13 +991,13 @@ duk_debug_write_tval(thr, tv); } } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ /* * Debug connection message write helpers */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL void duk_debug_write_request(duk_hthread *thr, duk_small_uint_t command) { duk_debug_write_byte(thr, DUK_DBG_IB_REQUEST); duk_debug_write_int(thr, command); @@ -1091,7 +1100,7 @@ duk_activation *act; duk_uint32_t pc; - DUK_ASSERT(thr->valstack_top > thr->valstack); /* At least: ... err */ + DUK_ASSERT(thr->valstack_top > thr->valstack); /* At least: ... err */ duk_debug_write_notify(thr, DUK_DBG_CMD_THROW); duk_debug_write_int(thr, (duk_int32_t) fatal); @@ -1132,7 +1141,7 @@ duk_debug_write_eom(thr); } -#endif /* DUK_USE_DEBUGGER_THROW_NOTIFY */ +#endif /* DUK_USE_DEBUGGER_THROW_NOTIFY */ /* * Debug message processing @@ -1156,9 +1165,9 @@ duk_debug_skip_bytes(thr, (duk_size_t) (x - 0x60)); return 0; } - switch(x) { + switch (x) { case DUK_DBG_IB_EOM: - return 1; /* Return 1: got EOM */ + return 1; /* Return 1: got EOM */ case DUK_DBG_IB_REQUEST: case DUK_DBG_IB_REPLY: case DUK_DBG_IB_ERROR: @@ -1207,9 +1216,9 @@ return 0; - fail: +fail: DUK__SET_CONN_BROKEN(thr, 1); - return 1; /* Pretend like we got EOM */ + return 1; /* Pretend like we got EOM */ } /* Skip dvalues to EOM. */ @@ -1229,7 +1238,7 @@ level = duk_debug_read_int(thr); if (level >= 0 || -level > (duk_int32_t) thr->callstack_top) { duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack index"); - return 0; /* zero indicates failure */ + return 0; /* zero indicates failure */ } return level; } @@ -1298,7 +1307,7 @@ duk_debug_clear_paused(heap); pause_flags = 0; -#if 0 /* manual testing */ +#if 0 /* manual testing */ pause_flags |= DUK_PAUSE_FLAG_ONE_OPCODE; pause_flags |= DUK_PAUSE_FLAG_CAUGHT_ERROR; pause_flags |= DUK_PAUSE_FLAG_UNCAUGHT_ERROR; @@ -1319,12 +1328,9 @@ DUK_D(DUK_DPRINT("debug command StepInto/StepOver/StepOut: %d", (int) cmd)); if (cmd == DUK_DBG_CMD_STEPINTO) { - pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | - DUK_PAUSE_FLAG_FUNC_ENTRY | - DUK_PAUSE_FLAG_FUNC_EXIT; + pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | DUK_PAUSE_FLAG_FUNC_ENTRY | DUK_PAUSE_FLAG_FUNC_EXIT; } else if (cmd == DUK_DBG_CMD_STEPOVER) { - pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | - DUK_PAUSE_FLAG_FUNC_EXIT; + pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | DUK_PAUSE_FLAG_FUNC_EXIT; } else { DUK_ASSERT(cmd == DUK_DBG_CMD_STEPOUT); pause_flags = DUK_PAUSE_FLAG_FUNC_EXIT; @@ -1403,7 +1409,7 @@ if (act == NULL) { return; } - str = duk_debug_read_hstring(thr); /* push to stack */ + str = duk_debug_read_hstring(thr); /* push to stack */ DUK_ASSERT(str != NULL); rc = duk_js_getvar_activation(thr, act, str, 0); @@ -1432,7 +1438,7 @@ if (act == NULL) { return; } - str = duk_debug_read_hstring(thr); /* push to stack */ + str = duk_debug_read_hstring(thr); /* push to stack */ DUK_ASSERT(str != NULL); tv = duk_debug_read_tval(thr); if (tv == NULL) { @@ -1530,7 +1536,7 @@ /* ... func varmap enum key value this */ duk_debug_write_hstring(thr, duk_get_hstring(thr, -3)); duk_debug_write_tval(thr, duk_get_tval(thr, -2)); - duk_pop_3(thr); /* -> ... func varmap enum */ + duk_pop_3(thr); /* -> ... func varmap enum */ } } else { DUK_D(DUK_DPRINT("varmap missing in GetLocals, ignore")); @@ -1565,12 +1571,12 @@ /* nargs == 2 so we can pass a callstack index to eval(). */ idx_func = duk_get_top(thr); duk_push_c_function(thr, duk_bi_global_object_eval, 2 /*nargs*/); - duk_push_undefined(thr); /* 'this' binding shouldn't matter here */ + duk_push_undefined(thr); /* 'this' binding shouldn't matter here */ /* Read callstack index, if non-null. */ if (duk_debug_peek_byte(thr) == DUK_DBG_IB_NULL) { direct_eval = 0; - level = -1; /* Not needed, but silences warning. */ + level = -1; /* Not needed, but silences warning. */ (void) duk_debug_read_byte(thr); } else { direct_eval = 1; @@ -1580,12 +1586,11 @@ } } - DUK_ASSERT(!direct_eval || - (level < 0 && -level <= (duk_int32_t) thr->callstack_top)); + DUK_ASSERT(!direct_eval || (level < 0 && -level <= (duk_int32_t) thr->callstack_top)); (void) duk_debug_read_hstring(thr); if (direct_eval) { - duk_push_int(thr, level - 1); /* compensate for eval() call */ + duk_push_int(thr, level - 1); /* compensate for eval() call */ } /* ... eval "eval" eval_input level? */ @@ -1640,7 +1645,7 @@ duk_debug_write_eom(thr); DUK_D(DUK_DPRINT("debug connection detached, mark broken")); - DUK__SET_CONN_BROKEN(thr, 0); /* not an error */ + DUK__SET_CONN_BROKEN(thr, 0); /* not an error */ } DUK_LOCAL void duk__debug_handle_apprequest(duk_hthread *thr, duk_heap *heap) { @@ -1648,7 +1653,7 @@ DUK_D(DUK_DPRINT("debug command AppRequest")); - old_top = duk_get_top(thr); /* save stack top */ + old_top = duk_get_top(thr); /* save stack top */ if (heap->dbg_request_cb != NULL) { duk_idx_t nrets; @@ -1664,7 +1669,7 @@ DUK_D(DUK_DPRINT("failed to allocate space for request dvalue(s)")); goto fail; } - tv = duk_debug_read_tval(thr); /* push to stack */ + tv = duk_debug_read_tval(thr); /* push to stack */ if (tv == NULL) { /* detached */ return; @@ -1675,17 +1680,24 @@ /* Request callback should push values for reply to client onto valstack */ DUK_D(DUK_DPRINT("calling into AppRequest request_cb with nvalues=%ld, old_top=%ld, top=%ld", - (long) nvalues, (long) old_top, (long) duk_get_top(thr))); + (long) nvalues, + (long) old_top, + (long) duk_get_top(thr))); nrets = heap->dbg_request_cb(thr, heap->dbg_udata, nvalues); DUK_D(DUK_DPRINT("returned from AppRequest request_cb; nvalues=%ld -> nrets=%ld, old_top=%ld, top=%ld", - (long) nvalues, (long) nrets, (long) old_top, (long) duk_get_top(thr))); + (long) nvalues, + (long) nrets, + (long) old_top, + (long) duk_get_top(thr))); if (nrets >= 0) { DUK_ASSERT(duk_get_top(thr) >= old_top + nrets); if (duk_get_top(thr) < old_top + nrets) { DUK_D(DUK_DPRINT("AppRequest callback doesn't match value stack configuration, " "top=%ld < old_top=%ld + nrets=%ld; " "this might mean it's unsafe to continue!", - (long) duk_get_top(thr), (long) old_top, (long) nrets)); + (long) duk_get_top(thr), + (long) old_top, + (long) nrets)); goto fail; } @@ -1705,7 +1717,7 @@ duk_debug_write_error_eom(thr, DUK_DBG_ERR_APPLICATION, duk_get_string(thr, -1)); } - duk_set_top(thr, old_top); /* restore stack top */ + duk_set_top(thr, old_top); /* restore stack top */ } else { DUK_D(DUK_DPRINT("no request callback, treat AppRequest as unsupported")); duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNSUPPORTED, "AppRequest unsupported by target"); @@ -1713,8 +1725,8 @@ return; - fail: - duk_set_top(thr, old_top); /* restore stack top */ +fail: + duk_set_top(thr, old_top); /* restore stack top */ DUK__SET_CONN_BROKEN(thr, 1); } @@ -1765,16 +1777,16 @@ k = DUK_HOBJECT_E_GET_KEY(heap, h, i); duk_debug_write_heapptr(thr, (duk_heaphdr *) k); if (k == NULL) { - duk_debug_write_int(thr, 0); /* isAccessor */ + duk_debug_write_int(thr, 0); /* isAccessor */ duk_debug_write_unused(thr); continue; } if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap, h, i)) { - duk_debug_write_int(thr, 1); /* isAccessor */ + duk_debug_write_int(thr, 1); /* isAccessor */ duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->a.get); duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->a.set); } else { - duk_debug_write_int(thr, 0); /* isAccessor */ + duk_debug_write_int(thr, 0); /* isAccessor */ duk__debug_write_tval_heapptr(thr, &DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->v); } @@ -1836,7 +1848,7 @@ duk__debug_dump_strtab(thr, heap); duk_debug_write_eom(thr); } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ DUK_LOCAL void duk__debug_handle_get_bytecode(duk_hthread *thr, duk_heap *heap) { duk_activation *act; @@ -1905,11 +1917,11 @@ duk_debug_write_eom(thr); return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid argument"); return; - fail_index: +fail_index: duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack index"); return; } @@ -1961,53 +1973,22 @@ DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS, #endif DUK_HSTRING_FLAG_EXTDATA, - 0 /* terminator */ + 0 /* terminator */ }; DUK_LOCAL const char * const duk__debug_getinfo_hobject_keys = { - "extensible", - "constructable", - "callable", - "boundfunc", - "compfunc", - "natfunc", - "bufobj", - "fastrefs", - "array_part", - "strict", - "notail", - "newenv", - "namebinding", - "createargs", - "have_finalizer", - "exotic_array", - "exotic_stringobj", - "exotic_arguments", - "exotic_proxyobj", - "special_call" + "extensible", "constructable", "callable", "boundfunc", "compfunc", "natfunc", "bufobj", + "fastrefs", "array_part", "strict", "notail", "newenv", "namebinding", "createargs", + "have_finalizer", "exotic_array", "exotic_stringobj", "exotic_arguments", "exotic_proxyobj", "special_call" /* NULL not needed here */ }; DUK_LOCAL duk_uint_t duk__debug_getinfo_hobject_masks = { - DUK_HOBJECT_FLAG_EXTENSIBLE, - DUK_HOBJECT_FLAG_CONSTRUCTABLE, - DUK_HOBJECT_FLAG_CALLABLE, - DUK_HOBJECT_FLAG_BOUNDFUNC, - DUK_HOBJECT_FLAG_COMPFUNC, - DUK_HOBJECT_FLAG_NATFUNC, - DUK_HOBJECT_FLAG_BUFOBJ, - DUK_HOBJECT_FLAG_FASTREFS, - DUK_HOBJECT_FLAG_ARRAY_PART, - DUK_HOBJECT_FLAG_STRICT, - DUK_HOBJECT_FLAG_NOTAIL, - DUK_HOBJECT_FLAG_NEWENV, - DUK_HOBJECT_FLAG_NAMEBINDING, - DUK_HOBJECT_FLAG_CREATEARGS, - DUK_HOBJECT_FLAG_HAVE_FINALIZER, - DUK_HOBJECT_FLAG_EXOTIC_ARRAY, - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ, - DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS, - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ, - DUK_HOBJECT_FLAG_SPECIAL_CALL, - 0 /* terminator */ + DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_HOBJECT_FLAG_CONSTRUCTABLE, DUK_HOBJECT_FLAG_CALLABLE, + DUK_HOBJECT_FLAG_BOUNDFUNC, DUK_HOBJECT_FLAG_COMPFUNC, DUK_HOBJECT_FLAG_NATFUNC, + DUK_HOBJECT_FLAG_BUFOBJ, DUK_HOBJECT_FLAG_FASTREFS, DUK_HOBJECT_FLAG_ARRAY_PART, + DUK_HOBJECT_FLAG_STRICT, DUK_HOBJECT_FLAG_NOTAIL, DUK_HOBJECT_FLAG_NEWENV, + DUK_HOBJECT_FLAG_NAMEBINDING, DUK_HOBJECT_FLAG_CREATEARGS, DUK_HOBJECT_FLAG_HAVE_FINALIZER, + DUK_HOBJECT_FLAG_EXOTIC_ARRAY, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS, + DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ, DUK_HOBJECT_FLAG_SPECIAL_CALL, 0 /* terminator */ }; DUK_LOCAL const char * const duk__debug_getinfo_hbuffer_keys = { "dynamic", @@ -2017,7 +1998,7 @@ DUK_LOCAL duk_uint_t duk__debug_getinfo_hbuffer_masks = { DUK_HBUFFER_FLAG_DYNAMIC, DUK_HBUFFER_FLAG_EXTERNAL, - 0 /* terminator */ + 0 /* terminator */ }; DUK_LOCAL void duk__debug_getinfo_flags_key(duk_hthread *thr, const char *key) { @@ -2043,7 +2024,7 @@ duk_debug_write_boolean(thr, val); } -DUK_LOCAL void duk__debug_getinfo_bitmask(duk_hthread *thr, const char * const * keys, duk_uint_t *masks, duk_uint_t flags) { +DUK_LOCAL void duk__debug_getinfo_bitmask(duk_hthread *thr, const char * const *keys, duk_uint_t *masks, duk_uint_t flags) { const char *key; duk_uint_t mask; @@ -2055,7 +2036,10 @@ key = *keys++; DUK_ASSERT(key != NULL); - DUK_DD(DUK_DDPRINT("inspect bitmask: key=%s, mask=0x%08lx, flags=0x%08lx", key, (unsigned long) mask, (unsigned long) flags)); + DUK_DD(DUK_DDPRINT("inspect bitmask: key=%s, mask=0x%08lx, flags=0x%08lx", + key, + (unsigned long) mask, + (unsigned long) flags)); duk__debug_getinfo_prop_bool(thr, key, flags & mask); } } @@ -2131,9 +2115,12 @@ DUK_D(DUK_DPRINT("debug command GetHeapObjInfo")); DUK_UNREF(heap); - DUK_ASSERT(sizeof(duk__debug_getinfo_hstring_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hstring_masks) / sizeof(duk_uint_t) - 1); - DUK_ASSERT(sizeof(duk__debug_getinfo_hobject_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hobject_masks) / sizeof(duk_uint_t) - 1); - DUK_ASSERT(sizeof(duk__debug_getinfo_hbuffer_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hbuffer_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hstring_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hstring_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hobject_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hobject_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hbuffer_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hbuffer_masks) / sizeof(duk_uint_t) - 1); h = duk_debug_read_any_ptr(thr); if (!h) { @@ -2321,7 +2308,7 @@ duk_debug_write_heapptr(thr, (duk_heaphdr *) h_bufobj->buf); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ break; } case DUK_HTYPE_BUFFER: { @@ -2336,7 +2323,7 @@ duk__debug_getinfo_flags_key(thr, "dataptr"); duk_debug_write_pointer(thr, (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_buf)); duk__debug_getinfo_flags_key(thr, "data"); - duk_debug_write_hbuffer(thr, h_buf); /* tolerates NULL h_buf */ + duk_debug_write_hbuffer(thr, h_buf); /* tolerates NULL h_buf */ break; } default: { @@ -2374,8 +2361,7 @@ /* To use the shared helper need the virtual index. */ DUK_ASSERT(desc.e_idx >= 0 || desc.a_idx >= 0); - virtual_idx = (desc.a_idx >= 0 ? desc.a_idx : - (duk_int_t) DUK_HOBJECT_GET_ASIZE(h_obj) + desc.e_idx); + virtual_idx = (desc.a_idx >= 0 ? desc.a_idx : (duk_int_t) DUK_HOBJECT_GET_ASIZE(h_obj) + desc.e_idx); duk_debug_write_reply(thr); rc = duk__debug_getprop_index(thr, heap, h_obj, (duk_uint_t) virtual_idx); @@ -2387,7 +2373,7 @@ } return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid args"); } @@ -2423,11 +2409,11 @@ duk_debug_write_eom(thr); return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid args"); } -#endif /* DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_INSPECT */ /* * Process incoming debug requests @@ -2525,7 +2511,7 @@ duk__debug_handle_dump_heap(thr, heap); break; } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ case DUK_DBG_CMD_GETBYTECODE: { duk__debug_handle_get_bytecode(thr, heap); break; @@ -2547,12 +2533,12 @@ duk__debug_handle_get_obj_prop_desc_range(thr, heap); break; } -#endif /* DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_INSPECT */ default: { DUK_D(DUK_DPRINT("debug command unsupported: %d", (int) cmd)); duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNSUPPORTED, "unsupported command"); } - } /* switch cmd */ + } /* switch cmd */ break; } case DUK_DBG_IB_REPLY: { @@ -2571,14 +2557,14 @@ DUK_D(DUK_DPRINT("invalid initial byte, drop connection: %d", (int) x)); goto fail; } - } /* switch initial byte */ + } /* switch initial byte */ DUK_ASSERT(duk_get_top(thr) >= entry_top); duk_set_top(thr, entry_top); duk__debug_skip_to_eom(thr); return; - fail: +fail: DUK_ASSERT(duk_get_top(thr) >= entry_top); duk_set_top(thr, entry_top); DUK__SET_CONN_BROKEN(thr, 1); @@ -2605,8 +2591,10 @@ #endif DUK_D(DUK_DPRINT("process debug messages: read_cb=%s, no_block=%ld, detaching=%ld, processing=%ld", - thr->heap->dbg_read_cb ? "not NULL" : "NULL", (long) no_block, - (long) thr->heap->dbg_detaching, (long) thr->heap->dbg_processing)); + thr->heap->dbg_read_cb ? "not NULL" : "NULL", + (long) no_block, + (long) thr->heap->dbg_detaching, + (long) thr->heap->dbg_processing)); DUK_DD(DUK_DDPRINT("top at entry: %ld", (long) duk_get_top(thr))); /* thr->heap->dbg_detaching may be != 0 if a debugger write outside @@ -2653,13 +2641,14 @@ DUK_D(DUK_DPRINT("detach pending (dbg_read_cb == NULL, dbg_detaching != 0), call detach2")); duk__debug_do_detach2(thr->heap); - thr->heap->dbg_processing = 1; /* may be set to 0 by duk_debugger_attach() inside callback */ + thr->heap->dbg_processing = 1; /* may be set to 0 by duk_debugger_attach() inside callback */ DUK_D(DUK_DPRINT("after detach2 (and possible reattach): dbg_read_cb=%s, dbg_detaching=%ld", - thr->heap->dbg_read_cb ? "not NULL" : "NULL", (long) thr->heap->dbg_detaching)); + thr->heap->dbg_read_cb ? "not NULL" : "NULL", + (long) thr->heap->dbg_detaching)); } - DUK_ASSERT(thr->heap->dbg_detaching == 0); /* true even with reattach */ - DUK_ASSERT(thr->heap->dbg_processing == 1); /* even after a detach and possible reattach */ + DUK_ASSERT(thr->heap->dbg_detaching == 0); /* true even with reattach */ + DUK_ASSERT(thr->heap->dbg_processing == 1); /* even after a detach and possible reattach */ if (thr->heap->dbg_read_cb == NULL) { DUK_D(DUK_DPRINT("debug connection broken (and not detaching), stop processing messages")); @@ -2684,7 +2673,7 @@ duk__debug_process_message(thr); duk__check_resend_status(thr); - retval = 1; /* processed one or more messages */ + retval = 1; /* processed one or more messages */ } DUK_ASSERT(thr->heap->dbg_detaching == 0); @@ -2694,7 +2683,7 @@ /* As an initial implementation, read flush after exiting the message * loop. If transport is broken, this is a no-op (with debug logs). */ - duk_debug_read_flush(thr); /* this cannot initiate a detach */ + duk_debug_read_flush(thr); /* this cannot initiate a detach */ DUK_ASSERT(thr->heap->dbg_detaching == 0); DUK_DD(DUK_DDPRINT("top at exit: %ld", (long) duk_get_top(thr))); @@ -2745,11 +2734,8 @@ /* Short circuit if is safe: if act->curr_pc != NULL, 'fun' is * guaranteed to be a non-NULL ECMAScript function. */ - DUK_ASSERT(act->curr_pc == NULL || - (fun != NULL && DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun))); - if (use_prev_pc && - act->curr_pc != NULL && - act->curr_pc > DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, fun)) { + DUK_ASSERT(act->curr_pc == NULL || (fun != NULL && DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun))); + if (use_prev_pc && act->curr_pc != NULL && act->curr_pc > DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, fun)) { act->curr_pc--; } } @@ -2776,7 +2762,7 @@ * with PC values. */ if (act != NULL) { - act->curr_pc = old_pc; /* restore PC */ + act->curr_pc = old_pc; /* restore PC */ } } @@ -2800,7 +2786,8 @@ if (heap->dbg_breakpoint_count >= DUK_HEAP_MAX_BREAKPOINTS) { DUK_D(DUK_DPRINT("failed to add breakpoint for %O:%ld, all breakpoint slots used", - (duk_heaphdr *) filename, (long) line)); + (duk_heaphdr *) filename, + (long) line)); return -1; } heap->dbg_breakpoints_active0 = (duk_breakpoint *) NULL; @@ -2809,7 +2796,7 @@ b->line = line; DUK_HSTRING_INCREF(thr, filename); - return (duk_small_int_t) (heap->dbg_breakpoint_count - 1); /* index */ + return (duk_small_int_t) (heap->dbg_breakpoint_count - 1); /* index */ } DUK_INTERNAL duk_bool_t duk_debug_remove_breakpoint(duk_hthread *thr, duk_small_uint_t breakpoint_index) { @@ -2827,7 +2814,7 @@ heap = thr->heap; DUK_ASSERT(heap != NULL); DUK_ASSERT(duk_debug_is_attached(thr->heap)); - DUK_ASSERT_DISABLE(breakpoint_index >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(breakpoint_index >= 0); /* unsigned */ if (breakpoint_index >= heap->dbg_breakpoint_count) { DUK_D(DUK_DPRINT("invalid breakpoint index: %ld", (long) breakpoint_index)); @@ -2839,15 +2826,13 @@ DUK_ASSERT(h != NULL); move_size = sizeof(duk_breakpoint) * (heap->dbg_breakpoint_count - breakpoint_index - 1); - duk_memmove((void *) b, - (const void *) (b + 1), - (size_t) move_size); + duk_memmove((void *) b, (const void *) (b + 1), (size_t) move_size); heap->dbg_breakpoint_count--; heap->dbg_breakpoints_active0 = (duk_breakpoint *) NULL; - DUK_HSTRING_DECREF(thr, h); /* side effects */ - DUK_UNREF(h); /* w/o refcounting */ + DUK_HSTRING_DECREF(thr, h); /* side effects */ + DUK_UNREF(h); /* w/o refcounting */ /* Breakpoint entries above the used area are left as garbage. */ @@ -2873,10 +2858,10 @@ DUK_HEAP_SET_DEBUGGER_PAUSED(heap); heap->dbg_state_dirty = 1; duk_debug_clear_pause_state(heap); - DUK_ASSERT(heap->ms_running == 0); /* debugger can't be triggered within mark-and-sweep */ - heap->ms_running = 2; /* prevent mark-and-sweep, prevent refzero queueing */ + DUK_ASSERT(heap->ms_running == 0); /* debugger can't be triggered within mark-and-sweep */ + heap->ms_running = 2; /* prevent mark-and-sweep, prevent refzero queueing */ heap->ms_prevent_count++; - DUK_ASSERT(heap->ms_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(heap->ms_prevent_count != 0); /* Wrap. */ DUK_ASSERT(heap->heap_thread != NULL); } } @@ -2902,8 +2887,8 @@ heap->dbg_pause_startline = 0; } -#else /* DUK_USE_DEBUGGER_SUPPORT */ +#else /* DUK_USE_DEBUGGER_SUPPORT */ /* No debugger support. */ -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_debugger.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_debugger.h
Changed
@@ -4,77 +4,77 @@ /* Debugger protocol version is defined in the public API header. */ /* Initial bytes for markers. */ -#define DUK_DBG_IB_EOM 0x00 -#define DUK_DBG_IB_REQUEST 0x01 -#define DUK_DBG_IB_REPLY 0x02 -#define DUK_DBG_IB_ERROR 0x03 -#define DUK_DBG_IB_NOTIFY 0x04 +#define DUK_DBG_IB_EOM 0x00 +#define DUK_DBG_IB_REQUEST 0x01 +#define DUK_DBG_IB_REPLY 0x02 +#define DUK_DBG_IB_ERROR 0x03 +#define DUK_DBG_IB_NOTIFY 0x04 /* Other initial bytes. */ -#define DUK_DBG_IB_INT4 0x10 -#define DUK_DBG_IB_STR4 0x11 -#define DUK_DBG_IB_STR2 0x12 -#define DUK_DBG_IB_BUF4 0x13 -#define DUK_DBG_IB_BUF2 0x14 -#define DUK_DBG_IB_UNUSED 0x15 -#define DUK_DBG_IB_UNDEFINED 0x16 -#define DUK_DBG_IB_NULL 0x17 -#define DUK_DBG_IB_TRUE 0x18 -#define DUK_DBG_IB_FALSE 0x19 -#define DUK_DBG_IB_NUMBER 0x1a -#define DUK_DBG_IB_OBJECT 0x1b -#define DUK_DBG_IB_POINTER 0x1c -#define DUK_DBG_IB_LIGHTFUNC 0x1d -#define DUK_DBG_IB_HEAPPTR 0x1e +#define DUK_DBG_IB_INT4 0x10 +#define DUK_DBG_IB_STR4 0x11 +#define DUK_DBG_IB_STR2 0x12 +#define DUK_DBG_IB_BUF4 0x13 +#define DUK_DBG_IB_BUF2 0x14 +#define DUK_DBG_IB_UNUSED 0x15 +#define DUK_DBG_IB_UNDEFINED 0x16 +#define DUK_DBG_IB_NULL 0x17 +#define DUK_DBG_IB_TRUE 0x18 +#define DUK_DBG_IB_FALSE 0x19 +#define DUK_DBG_IB_NUMBER 0x1a +#define DUK_DBG_IB_OBJECT 0x1b +#define DUK_DBG_IB_POINTER 0x1c +#define DUK_DBG_IB_LIGHTFUNC 0x1d +#define DUK_DBG_IB_HEAPPTR 0x1e /* The short string/integer initial bytes starting from 0x60 don't have * defines now. */ /* Error codes. */ -#define DUK_DBG_ERR_UNKNOWN 0x00 -#define DUK_DBG_ERR_UNSUPPORTED 0x01 -#define DUK_DBG_ERR_TOOMANY 0x02 -#define DUK_DBG_ERR_NOTFOUND 0x03 -#define DUK_DBG_ERR_APPLICATION 0x04 +#define DUK_DBG_ERR_UNKNOWN 0x00 +#define DUK_DBG_ERR_UNSUPPORTED 0x01 +#define DUK_DBG_ERR_TOOMANY 0x02 +#define DUK_DBG_ERR_NOTFOUND 0x03 +#define DUK_DBG_ERR_APPLICATION 0x04 /* Commands and notifys initiated by Duktape. */ -#define DUK_DBG_CMD_STATUS 0x01 -#define DUK_DBG_CMD_UNUSED_2 0x02 /* Duktape 1.x: print notify */ -#define DUK_DBG_CMD_UNUSED_3 0x03 /* Duktape 1.x: alert notify */ -#define DUK_DBG_CMD_UNUSED_4 0x04 /* Duktape 1.x: log notify */ -#define DUK_DBG_CMD_THROW 0x05 -#define DUK_DBG_CMD_DETACHING 0x06 -#define DUK_DBG_CMD_APPNOTIFY 0x07 +#define DUK_DBG_CMD_STATUS 0x01 +#define DUK_DBG_CMD_UNUSED_2 0x02 /* Duktape 1.x: print notify */ +#define DUK_DBG_CMD_UNUSED_3 0x03 /* Duktape 1.x: alert notify */ +#define DUK_DBG_CMD_UNUSED_4 0x04 /* Duktape 1.x: log notify */ +#define DUK_DBG_CMD_THROW 0x05 +#define DUK_DBG_CMD_DETACHING 0x06 +#define DUK_DBG_CMD_APPNOTIFY 0x07 /* Commands initiated by debug client. */ -#define DUK_DBG_CMD_BASICINFO 0x10 -#define DUK_DBG_CMD_TRIGGERSTATUS 0x11 -#define DUK_DBG_CMD_PAUSE 0x12 -#define DUK_DBG_CMD_RESUME 0x13 -#define DUK_DBG_CMD_STEPINTO 0x14 -#define DUK_DBG_CMD_STEPOVER 0x15 -#define DUK_DBG_CMD_STEPOUT 0x16 -#define DUK_DBG_CMD_LISTBREAK 0x17 -#define DUK_DBG_CMD_ADDBREAK 0x18 -#define DUK_DBG_CMD_DELBREAK 0x19 -#define DUK_DBG_CMD_GETVAR 0x1a -#define DUK_DBG_CMD_PUTVAR 0x1b -#define DUK_DBG_CMD_GETCALLSTACK 0x1c -#define DUK_DBG_CMD_GETLOCALS 0x1d -#define DUK_DBG_CMD_EVAL 0x1e -#define DUK_DBG_CMD_DETACH 0x1f -#define DUK_DBG_CMD_DUMPHEAP 0x20 -#define DUK_DBG_CMD_GETBYTECODE 0x21 -#define DUK_DBG_CMD_APPREQUEST 0x22 -#define DUK_DBG_CMD_GETHEAPOBJINFO 0x23 -#define DUK_DBG_CMD_GETOBJPROPDESC 0x24 -#define DUK_DBG_CMD_GETOBJPROPDESCRANGE 0x25 +#define DUK_DBG_CMD_BASICINFO 0x10 +#define DUK_DBG_CMD_TRIGGERSTATUS 0x11 +#define DUK_DBG_CMD_PAUSE 0x12 +#define DUK_DBG_CMD_RESUME 0x13 +#define DUK_DBG_CMD_STEPINTO 0x14 +#define DUK_DBG_CMD_STEPOVER 0x15 +#define DUK_DBG_CMD_STEPOUT 0x16 +#define DUK_DBG_CMD_LISTBREAK 0x17 +#define DUK_DBG_CMD_ADDBREAK 0x18 +#define DUK_DBG_CMD_DELBREAK 0x19 +#define DUK_DBG_CMD_GETVAR 0x1a +#define DUK_DBG_CMD_PUTVAR 0x1b +#define DUK_DBG_CMD_GETCALLSTACK 0x1c +#define DUK_DBG_CMD_GETLOCALS 0x1d +#define DUK_DBG_CMD_EVAL 0x1e +#define DUK_DBG_CMD_DETACH 0x1f +#define DUK_DBG_CMD_DUMPHEAP 0x20 +#define DUK_DBG_CMD_GETBYTECODE 0x21 +#define DUK_DBG_CMD_APPREQUEST 0x22 +#define DUK_DBG_CMD_GETHEAPOBJINFO 0x23 +#define DUK_DBG_CMD_GETOBJPROPDESC 0x24 +#define DUK_DBG_CMD_GETOBJPROPDESCRANGE 0x25 /* The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx. * The remaining flags are specific to the debugger. */ -#define DUK_DBG_PROPFLAG_SYMBOL (1U << 8) -#define DUK_DBG_PROPFLAG_HIDDEN (1U << 9) +#define DUK_DBG_PROPFLAG_SYMBOL (1U << 8) +#define DUK_DBG_PROPFLAG_HIDDEN (1U << 9) #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_INTERNAL_DECL void duk_debug_do_detach(duk_heap *heap); @@ -121,7 +121,7 @@ #endif DUK_INTERNAL_DECL void duk_debug_write_hobject(duk_hthread *thr, duk_hobject *obj); DUK_INTERNAL_DECL void duk_debug_write_tval(duk_hthread *thr, duk_tval *tv); -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL_DECL void duk_debug_write_request(duk_hthread *thr, duk_small_uint_t command); #endif DUK_INTERNAL_DECL void duk_debug_write_reply(duk_hthread *thr); @@ -146,6 +146,6 @@ DUK_INTERNAL_DECL void duk_debug_set_paused(duk_heap *heap); DUK_INTERNAL_DECL void duk_debug_clear_paused(duk_heap *heap); DUK_INTERNAL_DECL void duk_debug_clear_pause_state(duk_heap *heap); -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ -#endif /* DUK_DEBUGGER_H_INCLUDED */ +#endif /* DUK_DEBUGGER_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_error.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_error.h
Changed
@@ -53,79 +53,153 @@ /* Because there are quite many call sites, pack error code (require at most * 8-bit) into a single argument. */ -#define DUK_ERROR(thr,err,msg) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ +#define DUK_ERROR(thr, err, msg) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ duk_err_handle_error((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (msg)); \ } while (0) -#define DUK_ERROR_RAW(thr,file,line,err,msg) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ +#define DUK_ERROR_RAW(thr, file, line, err, msg) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ duk_err_handle_error((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (msg)); \ } while (0) -#define DUK_ERROR_FMT1(thr,err,fmt,arg1) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1)); \ - } while (0) -#define DUK_ERROR_RAW_FMT1(thr,file,line,err,fmt,arg1) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1)); \ - } while (0) - -#define DUK_ERROR_FMT2(thr,err,fmt,arg1,arg2) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2)); \ - } while (0) -#define DUK_ERROR_RAW_FMT2(thr,file,line,err,fmt,arg1,arg2) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2)); \ - } while (0) - -#define DUK_ERROR_FMT3(thr,err,fmt,arg1,arg2,arg3) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3)); \ - } while (0) -#define DUK_ERROR_RAW_FMT3(thr,file,line,err,fmt,arg1,arg2,arg3) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3)); \ - } while (0) - -#define DUK_ERROR_FMT4(thr,err,fmt,arg1,arg2,arg3,arg4) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3), (arg4)); \ - } while (0) -#define DUK_ERROR_RAW_FMT4(thr,file,line,err,fmt,arg1,arg2,arg3,arg4) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3), (arg4)); \ - } while (0) - -#else /* DUK_USE_VERBOSE_ERRORS */ - -#define DUK_ERROR(thr,err,msg) duk_err_handle_error((thr), (err)) -#define DUK_ERROR_RAW(thr,file,line,err,msg) duk_err_handle_error((thr), (err)) - -#define DUK_ERROR_FMT1(thr,err,fmt,arg1) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT1(thr,file,line,err,fmt,arg1) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#define DUK_ERROR_FMT2(thr,err,fmt,arg1,arg2) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT2(thr,file,line,err,fmt,arg1,arg2) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#define DUK_ERROR_FMT3(thr,err,fmt,arg1,arg2,arg3) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT3(thr,file,line,err,fmt,arg1,arg2,arg3) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#define DUK_ERROR_FMT4(thr,err,fmt,arg1,arg2,arg3,arg4) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT4(thr,file,line,err,fmt,arg1,arg2,arg3,arg4) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#endif /* DUK_USE_VERBOSE_ERRORS */ +#define DUK_ERROR_FMT1(thr, err, fmt, arg1) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1)); \ + } while (0) +#define DUK_ERROR_RAW_FMT1(thr, file, line, err, fmt, arg1) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1)); \ + } while (0) + +#define DUK_ERROR_FMT2(thr, err, fmt, arg1, arg2) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2)); \ + } while (0) +#define DUK_ERROR_RAW_FMT2(thr, file, line, err, fmt, arg1, arg2) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2)); \ + } while (0) + +#define DUK_ERROR_FMT3(thr, err, fmt, arg1, arg2, arg3) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3)); \ + } while (0) +#define DUK_ERROR_RAW_FMT3(thr, file, line, err, fmt, arg1, arg2, arg3) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3)); \ + } while (0) + +#define DUK_ERROR_FMT4(thr, err, fmt, arg1, arg2, arg3, arg4) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3), \ + (arg4)); \ + } while (0) +#define DUK_ERROR_RAW_FMT4(thr, file, line, err, fmt, arg1, arg2, arg3, arg4) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3), \ + (arg4)); \ + } while (0) + +#else /* DUK_USE_VERBOSE_ERRORS */ + +#define DUK_ERROR(thr, err, msg) duk_err_handle_error((thr), (err)) +#define DUK_ERROR_RAW(thr, file, line, err, msg) duk_err_handle_error((thr), (err)) + +#define DUK_ERROR_FMT1(thr, err, fmt, arg1) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT1(thr, file, line, err, fmt, arg1) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) + +#define DUK_ERROR_FMT2(thr, err, fmt, arg1, arg2) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT2(thr, file, line, err, fmt, arg1, arg2) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) + +#define DUK_ERROR_FMT3(thr, err, fmt, arg1, arg2, arg3) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT3(thr, file, line, err, fmt, arg1, arg2, arg3) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) + +#define DUK_ERROR_FMT4(thr, err, fmt, arg1, arg2, arg3, arg4) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT4(thr, file, line, err, fmt, arg1, arg2, arg3, arg4) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) + +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Fatal error without context @@ -133,8 +207,7 @@ * The macro is an expression to make it compatible with DUK_ASSERT_EXPR(). */ -#define DUK_FATAL_WITHOUT_CONTEXT(msg) \ - duk_default_fatal_handler(NULL, (msg)) +#define DUK_FATAL_WITHOUT_CONTEXT(msg) duk_default_fatal_handler(NULL, (msg)) /* * Error throwing helpers @@ -159,196 +232,252 @@ * vs. non-paranoid distinction affects only a few specific errors. */ #if defined(DUK_USE_PARANOID_ERRORS) -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_require_type_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx), (expectname)); \ } while (0) -#else /* DUK_USE_PARANOID_ERRORS */ -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#else /* DUK_USE_PARANOID_ERRORS */ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_require_type_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx), (expectname)); \ } while (0) -#endif /* DUK_USE_PARANOID_ERRORS */ +#endif /* DUK_USE_PARANOID_ERRORS */ -#define DUK_ERROR_INTERNAL(thr) do { \ +#define DUK_ERROR_INTERNAL(thr) \ + do { \ duk_err_error_internal((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_INTERNAL(thr) do { \ +#define DUK_DCERROR_INTERNAL(thr) \ + do { \ DUK_ERROR_INTERNAL((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_ALLOC_FAILED(thr) do { \ +#define DUK_ERROR_ALLOC_FAILED(thr) \ + do { \ duk_err_error_alloc_failed((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_ERROR_UNSUPPORTED(thr) do { \ +#define DUK_ERROR_UNSUPPORTED(thr) \ + do { \ DUK_ERROR((thr), DUK_ERR_ERROR, DUK_STR_UNSUPPORTED); \ } while (0) -#define DUK_DCERROR_UNSUPPORTED(thr) do { \ +#define DUK_DCERROR_UNSUPPORTED(thr) \ + do { \ DUK_ERROR_UNSUPPORTED((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_ERROR(thr,msg) do { \ +#define DUK_ERROR_ERROR(thr, msg) \ + do { \ duk_err_error((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \ } while (0) -#define DUK_ERROR_RANGE_INDEX(thr,idx) do { \ +#define DUK_ERROR_RANGE_INDEX(thr, idx) \ + do { \ duk_err_range_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx)); \ } while (0) -#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) do { \ +#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) \ + do { \ duk_err_range_push_beyond((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_ERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_ARGS); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_ARGS((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_COUNT); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_COUNT((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_LENGTH); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_LENGTH((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE(thr,msg) do { \ +#define DUK_ERROR_RANGE(thr, msg) \ + do { \ duk_err_range((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \ } while (0) -#define DUK_ERROR_EVAL(thr,msg) do { \ +#define DUK_ERROR_EVAL(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_EVAL_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_REFERENCE(thr,msg) do { \ +#define DUK_ERROR_REFERENCE(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_REFERENCE_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_SYNTAX(thr,msg) do { \ +#define DUK_ERROR_SYNTAX(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_SYNTAX_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_ARGS(thr) \ + do { \ duk_err_type_invalid_args((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_TYPE_INVALID_ARGS((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type_invalid_state((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_STATE(thr) \ + do { \ DUK_ERROR_TYPE_INVALID_STATE((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type_invalid_trap_result((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ DUK_ERROR_TYPE((thr), DUK_STR_INVALID_TRAP_RESULT); \ } while (0) -#define DUK_ERROR_TYPE(thr,msg) do { \ +#define DUK_ERROR_TYPE(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_TYPE_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_URI(thr,msg) do { \ +#define DUK_ERROR_URI(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_URI_ERROR, (msg)); \ } while (0) -#else /* DUK_USE_VERBOSE_ERRORS */ +#else /* DUK_USE_VERBOSE_ERRORS */ /* Non-verbose errors for low memory targets: no file, line, or message. */ -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_INTERNAL(thr) do { \ +#define DUK_ERROR_INTERNAL(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_DCERROR_INTERNAL(thr) do { \ +#define DUK_DCERROR_INTERNAL(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_ERROR; \ } while (0) -#define DUK_ERROR_ALLOC_FAILED(thr) do { \ +#define DUK_ERROR_ALLOC_FAILED(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_ERROR_UNSUPPORTED(thr) do { \ +#define DUK_ERROR_UNSUPPORTED(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_DCERROR_UNSUPPORTED(thr) do { \ +#define DUK_DCERROR_UNSUPPORTED(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_ERROR; \ } while (0) -#define DUK_ERROR_ERROR(thr,msg) do { \ +#define DUK_ERROR_ERROR(thr, msg) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_ERROR_RANGE_INDEX(thr,idx) do { \ +#define DUK_ERROR_RANGE_INDEX(thr, idx) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) do { \ +#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_ARGS(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_COUNT(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE(thr,msg) do { \ +#define DUK_ERROR_RANGE(thr, msg) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_EVAL(thr,msg) do { \ +#define DUK_ERROR_EVAL(thr, msg) \ + do { \ duk_err_eval((thr)); \ } while (0) -#define DUK_ERROR_REFERENCE(thr,msg) do { \ +#define DUK_ERROR_REFERENCE(thr, msg) \ + do { \ duk_err_reference((thr)); \ } while (0) -#define DUK_ERROR_SYNTAX(thr,msg) do { \ +#define DUK_ERROR_SYNTAX(thr, msg) \ + do { \ duk_err_syntax((thr)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_ARGS(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_TYPE_ERROR; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_TYPE_ERROR; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_TYPE(thr,msg) do { \ +#define DUK_ERROR_TYPE(thr, msg) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_URI(thr,msg) do { \ +#define DUK_ERROR_URI(thr, msg) \ + do { \ duk_err_uri((thr)); \ } while (0) -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Assert macro: failure causes a fatal error. @@ -366,63 +495,72 @@ * we don't care about assertion text size because they're not used in production * builds. */ -#define DUK_ASSERT(x) do { \ - if (!(x)) { \ - DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x \ - " (" DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"); \ - } \ +#define DUK_ASSERT(x) \ + do { \ + if (!(x)) { \ + DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x " (" DUK_FILE_MACRO \ + ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"); \ + } \ } while (0) /* Assertion compatible inside a comma expression, evaluates to void. */ #define DUK_ASSERT_EXPR(x) \ - ((void) ((x) ? 0 : (DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x \ - " (" DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"), 0))) + ((void) ((x) ? 0 : \ + (DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x " (" DUK_FILE_MACRO \ + ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"), \ + 0))) -#else /* DUK_USE_ASSERTIONS */ +#else /* DUK_USE_ASSERTIONS */ -#define DUK_ASSERT(x) do { /* assertion omitted */ } while (0) +#define DUK_ASSERT(x) \ + do { /* assertion omitted */ \ + } while (0) -#define DUK_ASSERT_EXPR(x) ((void) 0) +#define DUK_ASSERT_EXPR(x) ((void) 0) -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* this variant is used when an assert would generate a compile warning by * being always true (e.g. >= 0 comparison for an unsigned value */ -#define DUK_ASSERT_DISABLE(x) do { /* assertion disabled */ } while (0) +#define DUK_ASSERT_DISABLE(x) \ + do { /* assertion disabled */ \ + } while (0) /* * Assertion helpers */ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) do { \ +#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) \ + do { \ DUK_ASSERT((h) == NULL || DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) (h)) > 0); \ } while (0) -#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) do { \ +#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) \ + do { \ if ((tv) != NULL && DUK_TVAL_IS_HEAP_ALLOCATED((tv))) { \ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(DUK_TVAL_GET_HEAPHDR((tv))) > 0); \ } \ } while (0) #else -#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) /* no refcount check */ -#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) /* no refcount check */ +#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) /* no refcount check */ +#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) /* no refcount check */ #endif -#define DUK_ASSERT_TOP(ctx,n) DUK_ASSERT((duk_idx_t) duk_get_top((ctx)) == (duk_idx_t) (n)) +#define DUK_ASSERT_TOP(ctx, n) DUK_ASSERT((duk_idx_t) duk_get_top((ctx)) == (duk_idx_t) (n)) #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_PACKED_TVAL) -#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) do { \ +#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) \ + do { \ duk_double_union duk__assert_tmp_du; \ duk__assert_tmp_du.d = (dval); \ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&duk__assert_tmp_du)); \ } while (0) #else -#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) /* nop */ +#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) /* nop */ #endif -#define DUK_ASSERT_VS_SPACE(thr) \ - DUK_ASSERT(thr->valstack_top < thr->valstack_end) +#define DUK_ASSERT_VS_SPACE(thr) DUK_ASSERT(thr->valstack_top < thr->valstack_end) /* * Helper to initialize a memory area (e.g. struct) with garbage when @@ -430,11 +568,14 @@ */ #if defined(DUK_USE_ASSERTIONS) -#define DUK_ASSERT_SET_GARBAGE(ptr,size) do { \ +#define DUK_ASSERT_SET_GARBAGE(ptr, size) \ + do { \ duk_memset_unsafe((void *) (ptr), 0x5a, size); \ } while (0) #else -#define DUK_ASSERT_SET_GARBAGE(ptr,size) do {} while (0) +#define DUK_ASSERT_SET_GARBAGE(ptr, size) \ + do { \ + } while (0) #endif /* @@ -445,16 +586,18 @@ * or (b) Duktape calls which involve extending the valstack (e.g. getter call). */ -#define DUK_VALSTACK_ASSERT_EXTRA 5 /* this is added to checks to allow for Duktape - * API calls in addition to function's own use - */ +#define DUK_VALSTACK_ASSERT_EXTRA \ + 5 /* this is added to checks to allow for Duktape \ + * API calls in addition to function's own use \ + */ #if defined(DUK_USE_ASSERTIONS) -#define DUK_ASSERT_VALSTACK_SPACE(thr,n) do { \ +#define DUK_ASSERT_VALSTACK_SPACE(thr, n) \ + do { \ DUK_ASSERT((thr) != NULL); \ DUK_ASSERT((thr)->valstack_end - (thr)->valstack_top >= (n) + DUK_VALSTACK_ASSERT_EXTRA); \ } while (0) #else -#define DUK_ASSERT_VALSTACK_SPACE(thr,n) /* no valstack space check */ +#define DUK_ASSERT_VALSTACK_SPACE(thr, n) /* no valstack space check */ #endif /* @@ -462,25 +605,35 @@ */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...)); -#else /* DUK_USE_VERBOSE_ERRORS */ +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg)); +DUK_NORETURN(DUK_INTERNAL_DECL void + duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...)); +#else /* DUK_USE_VERBOSE_ERRORS */ DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, duk_errcode_t code)); -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code, const char *msg, const char *filename, duk_int_t line)); +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, + duk_errcode_t code, + const char *msg, + const char *filename, + duk_int_t line)); #else DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code)); #endif DUK_NORETURN(DUK_INTERNAL_DECL void duk_error_throw_from_negative_rc(duk_hthread *thr, duk_ret_t rc)); -#define DUK_AUGMENT_FLAG_NOBLAME_FILELINE (1U << 0) /* if set, don't blame C file/line for .fileName and .lineNumber */ -#define DUK_AUGMENT_FLAG_SKIP_ONE (1U << 1) /* if set, skip topmost activation in traceback construction */ +#define DUK_AUGMENT_FLAG_NOBLAME_FILELINE (1U << 0) /* if set, don't blame C file/line for .fileName and .lineNumber */ +#define DUK_AUGMENT_FLAG_SKIP_ONE (1U << 1) /* if set, skip topmost activation in traceback construction */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *filename, duk_int_t line, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *filename, + duk_int_t line, + duk_small_uint_t flags); #endif #if defined(DUK_USE_AUGMENT_ERROR_THROW) DUK_INTERNAL_DECL void duk_err_augment_error_throw(duk_hthread *thr); @@ -488,20 +641,31 @@ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name)); +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name)); #else -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name)); +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name)); #endif DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error_alloc_failed(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_range_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range_push_beyond(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_args(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_state(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_trap_result(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -#else /* DUK_VERBOSE_ERRORS */ +#else /* DUK_VERBOSE_ERRORS */ DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_eval(duk_hthread *thr)); @@ -522,4 +686,4 @@ DUK_INTERNAL_DECL duk_hobject *duk_error_prototype_from_code(duk_hthread *thr, duk_errcode_t err_code); -#endif /* DUK_ERROR_H_INCLUDED */ +#endif /* DUK_ERROR_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_error_augment.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_error_augment.c
Changed
@@ -82,7 +82,7 @@ * when it is called and that error replaces the original one. */ - DUK_ASSERT_VALSTACK_SPACE(thr, 4); /* 3 entries actually needed below */ + DUK_ASSERT_VALSTACK_SPACE(thr, 4); /* 3 entries actually needed below */ /* ... errval */ @@ -93,23 +93,19 @@ DUK_DD(DUK_DDPRINT("error occurred when DUK_BIDX_DUKTAPE is NULL, ignoring")); return; } - tv_hnd = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, - thr->builtinsDUK_BIDX_DUKTAPE, - stridx_cb); + tv_hnd = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, thr->builtinsDUK_BIDX_DUKTAPE, stridx_cb); if (tv_hnd == NULL) { - DUK_DD(DUK_DDPRINT("error handler does not exist or is not a plain value: %!T", - (duk_tval *) tv_hnd)); + DUK_DD(DUK_DDPRINT("error handler does not exist or is not a plain value: %!T", (duk_tval *) tv_hnd)); return; } - DUK_DDD(DUK_DDDPRINT("error handler dump (callability not checked): %!T", - (duk_tval *) tv_hnd)); + DUK_DDD(DUK_DDDPRINT("error handler dump (callability not checked): %!T", (duk_tval *) tv_hnd)); duk_push_tval(thr, tv_hnd); /* ... errval errhandler */ - duk_insert(thr, -2); /* -> ... errhandler errval */ + duk_insert(thr, -2); /* -> ... errhandler errval */ duk_push_undefined(thr); - duk_insert(thr, -2); /* -> ... errhandler undefined(= this) errval */ + duk_insert(thr, -2); /* -> ... errhandler undefined(= this) errval */ /* ... errhandler undefined errval */ @@ -126,21 +122,25 @@ thr->heap->augmenting_error = 1; rc = duk_pcall_method(thr, 1); - DUK_UNREF(rc); /* no need to check now: both success and error are OK */ + DUK_UNREF(rc); /* no need to check now: both success and error are OK */ DUK_ASSERT(thr->heap->augmenting_error == 1); thr->heap->augmenting_error = 0; /* ... errval */ } -#endif /* DUK_USE_ERRTHROW || DUK_USE_ERRCREATE */ +#endif /* DUK_USE_ERRTHROW || DUK_USE_ERRCREATE */ /* * Add ._Tracedata to an error on the stack top. */ #if defined(DUK_USE_TRACEBACKS) -DUK_LOCAL void duk__add_traceback(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_LOCAL void duk__add_traceback(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { duk_activation *act; duk_int_t depth; duk_int_t arr_size; @@ -162,15 +162,14 @@ * See doc/error-objects.rst. */ - DUK_DDD(DUK_DDDPRINT("adding traceback to object: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("adding traceback to object: %!T", (duk_tval *) duk_get_tval(thr, -1))); /* Preallocate array to correct size, so that we can just write out * the _Tracedata values into the array part. */ act = thr->callstack_curr; depth = DUK_USE_TRACEBACK_DEPTH; - DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ + DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ if (depth > (duk_int_t) thr_callstack->callstack_top) { depth = (duk_int_t) thr_callstack->callstack_top; } @@ -212,7 +211,7 @@ DUK_HSTRING_INCREF(thr, s); tv++; - u32 = (duk_uint32_t) thr->compile_ctx->curr_token.start_line; /* (flags<<32) + (line), flags = 0 */ + u32 = (duk_uint32_t) thr->compile_ctx->curr_token.start_line; /* (flags<<32) + (line), flags = 0 */ DUK_TVAL_SET_U32(tv, u32); tv++; } @@ -226,13 +225,15 @@ if (c_filename) { DUK_ASSERT(DUK_TVAL_IS_STRING(thr->valstack_top - 2)); - s = DUK_TVAL_GET_STRING(thr->valstack_top - 2); /* interned c_filename */ + s = DUK_TVAL_GET_STRING(thr->valstack_top - 2); /* interned c_filename */ DUK_ASSERT(s != NULL); DUK_TVAL_SET_STRING(tv, s); DUK_HSTRING_INCREF(thr, s); tv++; - d = ((flags & DUK_AUGMENT_FLAG_NOBLAME_FILELINE) ? ((duk_double_t) DUK_TB_FLAG_NOBLAME_FILELINE) * DUK_DOUBLE_2TO32 : 0.0) + + d = ((flags & DUK_AUGMENT_FLAG_NOBLAME_FILELINE) ? + ((duk_double_t) DUK_TB_FLAG_NOBLAME_FILELINE) * DUK_DOUBLE_2TO32 : + 0.0) + (duk_double_t) c_line; DUK_TVAL_SET_DOUBLE(tv, d); tv++; @@ -247,11 +248,11 @@ /* ... arr */ - DUK_ASSERT(act != NULL); /* depth check above, assumes book-keeping is correct */ - DUK_ASSERT_DISABLE(act->pc >= 0); /* unsigned */ + DUK_ASSERT(act != NULL); /* depth check above, assumes book-keeping is correct */ + DUK_ASSERT_DISABLE(act->pc >= 0); /* unsigned */ /* Add function object. */ - tv_src = &act->tv_func; /* object (function) or lightfunc */ + tv_src = &act->tv_func; /* object (function) or lightfunc */ DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv_src) || DUK_TVAL_IS_LIGHTFUNC(tv_src)); DUK_TVAL_SET_TVAL(tv, tv_src); DUK_TVAL_INCREF(thr, tv); @@ -263,8 +264,8 @@ * PC == 0 for native code. */ pc = (duk_uint32_t) duk_hthread_get_act_prev_pc(thr_callstack, act); - DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ - DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ + DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ + DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ d = ((duk_double_t) act->flags) * DUK_DOUBLE_2TO32 + (duk_double_t) pc; DUK_TVAL_SET_DOUBLE(tv, d); tv++; @@ -289,16 +290,20 @@ /* ... error arr */ - duk_xdef_prop_stridx_short_wec(thr, -2, DUK_STRIDX_INT_TRACEDATA); /* -> ... error */ + duk_xdef_prop_stridx_short_wec(thr, -2, DUK_STRIDX_INT_TRACEDATA); /* -> ... error */ } -#endif /* DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_TRACEBACKS */ /* * Add .fileName and .lineNumber to an error on the stack top. */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) && !defined(DUK_USE_TRACEBACKS) -DUK_LOCAL void duk__add_fileline(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_LOCAL void duk__add_fileline(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { #if defined(DUK_USE_ASSERTIONS) duk_int_t entry_top; #endif @@ -336,7 +341,7 @@ duk_uint32_t ecma_line; duk_activation *act; - DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ + DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ depth = DUK_USE_TRACEBACK_DEPTH; if (depth > thr_callstack->callstack_top) { depth = thr_callstack->callstack_top; @@ -355,10 +360,12 @@ /* PC points to next instruction, find offending PC, * PC == 0 for native code. */ - pc = duk_hthread_get_act_prev_pc(thr, act); /* thr argument only used for thr->heap, so specific thread doesn't matter */ + pc = duk_hthread_get_act_prev_pc( + thr, + act); /* thr argument only used for thr->heap, so specific thread doesn't matter */ DUK_UNREF(pc); - DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ - DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ + DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ + DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ duk_push_hobject(thr, func); @@ -379,7 +386,7 @@ } else { /* Native function, no relevant lineNumber. */ } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ duk_push_u32(thr, ecma_line); /* ... error func fileName lineNumber */ @@ -398,7 +405,7 @@ duk_push_undefined(thr); } - define_props: +define_props: /* ... error lineNumber fileName */ #if defined(DUK_USE_ASSERTIONS) DUK_ASSERT(duk_get_top(thr) == entry_top + 2); @@ -406,7 +413,7 @@ duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_C | DUK_PROPDESC_FLAG_NO_OVERWRITE); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LINE_NUMBER, DUK_PROPDESC_FLAGS_C | DUK_PROPDESC_FLAG_NO_OVERWRITE); } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE && !DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE && !DUK_USE_TRACEBACKS */ /* * Add line number to a compiler error. @@ -414,7 +421,6 @@ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) DUK_LOCAL void duk__add_compiler_error_line(duk_hthread *thr) { - /* Append a "(line NNN)" to the "message" property of any error * thrown during compilation. Usually compilation errors are * SyntaxErrors but they can also be out-of-memory errors and @@ -429,8 +435,7 @@ return; } - DUK_DDD(DUK_DDDPRINT("compile error, before adding line info: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("compile error, before adding line info: %!T", (duk_tval *) duk_get_tval(thr, -1))); if (duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_MESSAGE)) { duk_bool_t at_end; @@ -452,7 +457,8 @@ (long) thr->compile_ctx->lex.window0.codepoint, (long) thr->compile_ctx->lex.window1.codepoint)); - duk_push_sprintf(thr, " (line %ld%s)", + duk_push_sprintf(thr, + " (line %ld%s)", (long) thr->compile_ctx->curr_token.start_line, at_end ? ", end of input" : ""); duk_concat(thr, 2); @@ -461,10 +467,9 @@ duk_pop(thr); } - DUK_DDD(DUK_DDDPRINT("compile error, after adding line info: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("compile error, after adding line info: %!T", (duk_tval *) duk_get_tval(thr, -1))); } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error being created using Duktape specific properties @@ -472,7 +477,12 @@ */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_LOCAL void duk__err_augment_builtin_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_hobject *obj, duk_small_uint_t flags) { +DUK_LOCAL void duk__err_augment_builtin_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_hobject *obj, + duk_small_uint_t flags) { #if defined(DUK_USE_ASSERTIONS) duk_int_t entry_top; #endif @@ -482,7 +492,7 @@ #endif DUK_ASSERT(obj != NULL); - DUK_UNREF(obj); /* unreferenced w/o tracebacks */ + DUK_UNREF(obj); /* unreferenced w/o tracebacks */ duk__add_compiler_error_line(thr); @@ -507,7 +517,7 @@ DUK_ASSERT(duk_get_top(thr) == entry_top); #endif } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error at creation time with _Tracedata/fileName/lineNumber @@ -525,7 +535,11 @@ */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_INTERNAL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_INTERNAL void duk_err_augment_error_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { duk_hobject *obj; DUK_ASSERT(thr != NULL); @@ -571,7 +585,7 @@ duk__err_augment_user(thr, DUK_STRIDX_ERR_CREATE); #endif } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error at throw time; allow a user error handler (if defined) @@ -583,6 +597,6 @@ DUK_INTERNAL void duk_err_augment_error_throw(duk_hthread *thr) { #if defined(DUK_USE_ERRTHROW) duk__err_augment_user(thr, DUK_STRIDX_ERR_THROW); -#endif /* DUK_USE_ERRTHROW */ +#endif /* DUK_USE_ERRTHROW */ } -#endif /* DUK_USE_AUGMENT_ERROR_THROW */ +#endif /* DUK_USE_AUGMENT_ERROR_THROW */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_error_longjmp.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_error_longjmp.c
Changed
@@ -47,8 +47,10 @@ DUK_ASSERT(thr->heap != NULL); DUK_DD(DUK_DDPRINT("longjmp error: type=%d iserror=%d value1=%!T value2=%!T", - (int) thr->heap->lj.type, (int) thr->heap->lj.iserror, - &thr->heap->lj.value1, &thr->heap->lj.value2)); + (int) thr->heap->lj.type, + (int) thr->heap->lj.iserror, + &thr->heap->lj.value1, + &thr->heap->lj.value2)); /* Prevent finalizer execution during error handling. All error * handling sites will process pending finalizers once error handling @@ -66,11 +68,11 @@ DUK_ASSERT_LJSTATE_SET(thr->heap); thr->heap->pf_prevent_count++; - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ #if defined(DUK_USE_ASSERTIONS) /* XXX: set this immediately when longjmp state is set */ - DUK_ASSERT(thr->heap->error_not_allowed == 0); /* Detect error within critical section. */ + DUK_ASSERT(thr->heap->error_not_allowed == 0); /* Detect error within critical section. */ thr->heap->error_not_allowed = 1; #endif @@ -82,8 +84,10 @@ */ if (!thr->heap->lj.jmpbuf_ptr) { DUK_D(DUK_DPRINT("uncaught error: type=%d iserror=%d value1=%!T value2=%!T", - (int) thr->heap->lj.type, (int) thr->heap->lj.iserror, - &thr->heap->lj.value1, &thr->heap->lj.value2)); + (int) thr->heap->lj.type, + (int) thr->heap->lj.iserror, + &thr->heap->lj.value1, + &thr->heap->lj.value2)); #if defined(DUK_USE_PREFER_SIZE) duk__uncaught_minimal(thr); @@ -94,7 +98,7 @@ } #if defined(DUK_USE_CPP_EXCEPTIONS) - throw duk_internal_exception(); /* dummy */ + throw duk_internal_exception(); /* dummy */ #else DUK_LONGJMP(thr->heap->lj.jmpbuf_ptr->jb); #endif
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_error_macros.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_error_macros.c
Changed
@@ -4,31 +4,43 @@ #include "duk_internal.h" -#define DUK__ERRFMT_BUFSIZE 256 /* size for formatting buffers */ +#define DUK__ERRFMT_BUFSIZE 256 /* size for formatting buffers */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_INTERNAL DUK_COLD void duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...) { +DUK_INTERNAL DUK_COLD void duk_err_handle_error_fmt(duk_hthread *thr, + const char *filename, + duk_uint_t line_and_code, + const char *fmt, + ...) { va_list ap; char msgDUK__ERRFMT_BUFSIZE; va_start(ap, fmt); (void) DUK_VSNPRINTF(msg, sizeof(msg), fmt, ap); msgsizeof(msg) - 1 = (char) 0; - duk_err_create_and_throw(thr, (duk_errcode_t) (line_and_code >> 24), msg, filename, (duk_int_t) (line_and_code & 0x00ffffffL)); - va_end(ap); /* dead code, but ensures portability (see Linux man page notes) */ + duk_err_create_and_throw(thr, + (duk_errcode_t) (line_and_code >> 24), + msg, + filename, + (duk_int_t) (line_and_code & 0x00ffffffL)); + va_end(ap); /* dead code, but ensures portability (see Linux man page notes) */ } DUK_INTERNAL DUK_COLD void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg) { - duk_err_create_and_throw(thr, (duk_errcode_t) (line_and_code >> 24), msg, filename, (duk_int_t) (line_and_code & 0x00ffffffL)); + duk_err_create_and_throw(thr, + (duk_errcode_t) (line_and_code >> 24), + msg, + filename, + (duk_int_t) (line_and_code & 0x00ffffffL)); } -#else /* DUK_USE_VERBOSE_ERRORS */ +#else /* DUK_USE_VERBOSE_ERRORS */ DUK_INTERNAL DUK_COLD void duk_err_handle_error(duk_hthread *thr, duk_errcode_t code) { duk_err_create_and_throw(thr, code); } -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Error throwing helpers @@ -36,14 +48,34 @@ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) -DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name) { - DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)", - expect_name, duk_get_type_name(thr, idx), (long) idx); +DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name) { + DUK_ERROR_RAW_FMT3(thr, + filename, + linenumber, + DUK_ERR_TYPE_ERROR, + "%s required, found %s (stack index %ld)", + expect_name, + duk_get_type_name(thr, idx), + (long) idx); } #else -DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name) { - DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)", - expect_name, duk_push_string_readable(thr, idx), (long) idx); +DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name) { + DUK_ERROR_RAW_FMT3(thr, + filename, + linenumber, + DUK_ERR_TYPE_ERROR, + "%s required, found %s (stack index %ld)", + expect_name, + duk_push_string_readable(thr, idx), + (long) idx); } #endif DUK_INTERNAL DUK_COLD void duk_err_error_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_error_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_error_misc.c
Changed
@@ -26,14 +26,14 @@ for (act = thr->callstack_curr; act != NULL; act = act->parent) { for (cat = act->cat; cat != NULL; cat = cat->parent) { if (DUK_CAT_HAS_CATCH_ENABLED(cat)) { - return 1; /* all we need to know */ + return 1; /* all we need to know */ } } } } return 0; } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Get prototype object for an integer error code. @@ -83,11 +83,10 @@ * config options. */ - if (!duk_debug_is_attached(thr->heap) || - thr->heap->dbg_processing || - thr->heap->lj.type != DUK_LJ_TYPE_THROW || + if (!duk_debug_is_attached(thr->heap) || thr->heap->dbg_processing || thr->heap->lj.type != DUK_LJ_TYPE_THROW || thr->heap->creating_error) { - DUK_D(DUK_DPRINT("skip debugger error integration; not attached, debugger processing, not THROW, or error thrown while creating error")); + DUK_D(DUK_DPRINT("skip debugger error integration; not attached, debugger processing, not THROW, or error thrown " + "while creating error")); return; } @@ -115,7 +114,7 @@ /* Store and reset longjmp state. */ DUK_ASSERT_LJSTATE_SET(thr->heap); DUK_TVAL_DECREF_NORZ(thr, tv_obj); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&thr->heap->lj.value2)); /* Always for THROW type. */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&thr->heap->lj.value2)); /* Always for THROW type. */ DUK_TVAL_SET_UNDEFINED(tv_obj); thr->heap->lj.type = DUK_LJ_TYPE_UNKNOWN; DUK_ASSERT_LJSTATE_UNSET(thr->heap); @@ -150,7 +149,7 @@ duk_pop(thr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Helpers for setting up heap longjmp state.
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_error_throw.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_error_throw.c
Changed
@@ -21,14 +21,20 @@ */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code, const char *msg, const char *filename, duk_int_t line) { +DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, + duk_errcode_t code, + const char *msg, + const char *filename, + duk_int_t line) { #else DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code) { #endif #if defined(DUK_USE_VERBOSE_ERRORS) DUK_DD(DUK_DDPRINT("duk_err_create_and_throw(): code=%ld, msg=%s, filename=%s, line=%ld", - (long) code, (const char *) msg, - (const char *) filename, (long) line)); + (long) code, + (const char *) msg, + (const char *) filename, + (long) line)); #else DUK_DD(DUK_DDPRINT("duk_err_create_and_throw(): code=%ld", (long) code)); #endif @@ -88,18 +94,9 @@ * use 'msg' as a format string directly. */ #if defined(DUK_USE_VERBOSE_ERRORS) - duk_push_error_object_raw(thr, - code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - filename, - line, - "%s", - (const char *) msg); + duk_push_error_object_raw(thr, code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, filename, line, "%s", (const char *) msg); #else - duk_push_error_object_raw(thr, - code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - NULL, - 0, - NULL); + duk_push_error_object_raw(thr, code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, NULL, 0, NULL); #endif /* Note that an alloc error may happen during error augmentation. @@ -109,8 +106,7 @@ * avoiding it for alloc errors (this differs from Duktape 1.x). */ #if defined(DUK_USE_AUGMENT_ERROR_THROW) - DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT (before throw augment)", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT (before throw augment)", (duk_tval *) duk_get_tval(thr, -1))); duk_err_augment_error_throw(thr); #endif @@ -133,7 +129,8 @@ */ DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT, %!iT (after throw augment)", - (duk_tval *) &thr->heap->lj.value1, (duk_tval *) &thr->heap->lj.value2)); + (duk_tval *) &thr->heap->lj.value1, + (duk_tval *) &thr->heap->lj.value2)); duk_err_longjmp(thr); DUK_UNREACHABLE();
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_exception.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_exception.h
Changed
@@ -22,9 +22,10 @@ * aware of the "unsafe to continue" semantics. */ class duk_fatal_exception : public virtual std::runtime_error { - public: - duk_fatal_exception(const char *message) : std::runtime_error(message) {} + public: + duk_fatal_exception(const char *message) : std::runtime_error(message) { + } }; #endif -#endif /* DUK_EXCEPTION_H_INCLUDED */ +#endif /* DUK_EXCEPTION_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_fltunion.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_fltunion.h
Changed
@@ -17,23 +17,23 @@ typedef union duk_float_union duk_float_union; #if defined(DUK_USE_DOUBLE_LE) || defined(DUK_USE_DOUBLE_ME) -#define DUK_FLT_IDX_UI0 0 -#define DUK_FLT_IDX_US0 1 -#define DUK_FLT_IDX_US1 0 -#define DUK_FLT_IDX_UC0 3 -#define DUK_FLT_IDX_UC1 2 -#define DUK_FLT_IDX_UC2 1 -#define DUK_FLT_IDX_UC3 0 +#define DUK_FLT_IDX_UI0 0 +#define DUK_FLT_IDX_US0 1 +#define DUK_FLT_IDX_US1 0 +#define DUK_FLT_IDX_UC0 3 +#define DUK_FLT_IDX_UC1 2 +#define DUK_FLT_IDX_UC2 1 +#define DUK_FLT_IDX_UC3 0 #elif defined(DUK_USE_DOUBLE_BE) -#define DUK_FLT_IDX_UI0 0 -#define DUK_FLT_IDX_US0 0 -#define DUK_FLT_IDX_US1 1 -#define DUK_FLT_IDX_UC0 0 -#define DUK_FLT_IDX_UC1 1 -#define DUK_FLT_IDX_UC2 2 -#define DUK_FLT_IDX_UC3 3 +#define DUK_FLT_IDX_UI0 0 +#define DUK_FLT_IDX_US0 0 +#define DUK_FLT_IDX_US1 1 +#define DUK_FLT_IDX_UC0 0 +#define DUK_FLT_IDX_UC1 1 +#define DUK_FLT_IDX_UC2 2 +#define DUK_FLT_IDX_UC3 3 #else #error internal error #endif -#endif /* DUK_FLTUNION_H_INCLUDED */ +#endif /* DUK_FLTUNION_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_forwdecl.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_forwdecl.h
Changed
@@ -131,4 +131,4 @@ typedef struct duk_re_matcher_ctx duk_re_matcher_ctx; typedef struct duk_re_compiler_ctx duk_re_compiler_ctx; -#endif /* DUK_FORWDECL_H_INCLUDED */ +#endif /* DUK_FORWDECL_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_harray.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_harray.h
Changed
@@ -11,15 +11,26 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_harray_assert_valid(duk_harray *h); -#define DUK_HARRAY_ASSERT_VALID(h) do { duk_harray_assert_valid((h)); } while (0) +#define DUK_HARRAY_ASSERT_VALID(h) \ + do { \ + duk_harray_assert_valid((h)); \ + } while (0) #else -#define DUK_HARRAY_ASSERT_VALID(h) do {} while (0) +#define DUK_HARRAY_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#define DUK_HARRAY_LENGTH_WRITABLE(h) (!(h)->length_nonwritable) -#define DUK_HARRAY_LENGTH_NONWRITABLE(h) ((h)->length_nonwritable) -#define DUK_HARRAY_SET_LENGTH_WRITABLE(h) do { (h)->length_nonwritable = 0; } while (0) -#define DUK_HARRAY_SET_LENGTH_NONWRITABLE(h) do { (h)->length_nonwritable = 1; } while (0) +#define DUK_HARRAY_LENGTH_WRITABLE(h) (!(h)->length_nonwritable) +#define DUK_HARRAY_LENGTH_NONWRITABLE(h) ((h)->length_nonwritable) +#define DUK_HARRAY_SET_LENGTH_WRITABLE(h) \ + do { \ + (h)->length_nonwritable = 0; \ + } while (0) +#define DUK_HARRAY_SET_LENGTH_NONWRITABLE(h) \ + do { \ + (h)->length_nonwritable = 1; \ + } while (0) struct duk_harray { /* Shared object part. */ @@ -45,4 +56,4 @@ duk_bool_t length_nonwritable; }; -#endif /* DUK_HARRAY_H_INCLUDED */ +#endif /* DUK_HARRAY_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hboundfunc.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hboundfunc.h
Changed
@@ -12,9 +12,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hboundfunc_assert_valid(duk_hboundfunc *h); -#define DUK_HBOUNDFUNC_ASSERT_VALID(h) do { duk_hboundfunc_assert_valid((h)); } while (0) +#define DUK_HBOUNDFUNC_ASSERT_VALID(h) \ + do { \ + duk_hboundfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HBOUNDFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HBOUNDFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hboundfunc { @@ -30,8 +35,8 @@ duk_tval this_binding; /* Arguments to prepend. */ - duk_tval *args; /* Separate allocation. */ + duk_tval *args; /* Separate allocation. */ duk_idx_t nargs; }; -#endif /* DUK_HBOUNDFUNC_H_INCLUDED */ +#endif /* DUK_HBOUNDFUNC_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hbuffer.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hbuffer.h
Changed
@@ -20,17 +20,17 @@ * External buffer: DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL */ -#define DUK_HBUFFER_FLAG_DYNAMIC DUK_HEAPHDR_USER_FLAG(0) /* buffer is behind a pointer, dynamic or external */ -#define DUK_HBUFFER_FLAG_EXTERNAL DUK_HEAPHDR_USER_FLAG(1) /* buffer pointer is to an externally allocated buffer */ +#define DUK_HBUFFER_FLAG_DYNAMIC DUK_HEAPHDR_USER_FLAG(0) /* buffer is behind a pointer, dynamic or external */ +#define DUK_HBUFFER_FLAG_EXTERNAL DUK_HEAPHDR_USER_FLAG(1) /* buffer pointer is to an externally allocated buffer */ -#define DUK_HBUFFER_HAS_DYNAMIC(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_HAS_EXTERNAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_HAS_DYNAMIC(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_HAS_EXTERNAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) -#define DUK_HBUFFER_SET_DYNAMIC(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_SET_EXTERNAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_SET_DYNAMIC(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_SET_EXTERNAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) -#define DUK_HBUFFER_CLEAR_DYNAMIC(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_CLEAR_EXTERNAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_CLEAR_DYNAMIC(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_CLEAR_EXTERNAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) /* * Misc defines @@ -43,12 +43,12 @@ */ #if defined(DUK_USE_BUFLEN16) -#define DUK_HBUFFER_MAX_BYTELEN (0x0000ffffUL) +#define DUK_HBUFFER_MAX_BYTELEN (0x0000ffffUL) #else /* Intentionally not 0x7fffffffUL; at least JSON code expects that * 2*len + 2 fits in 32 bits. */ -#define DUK_HBUFFER_MAX_BYTELEN (0x7ffffffeUL) +#define DUK_HBUFFER_MAX_BYTELEN (0x7ffffffeUL) #endif /* @@ -57,60 +57,70 @@ #if defined(DUK_USE_BUFLEN16) /* size stored in duk_heaphdr unused flag bits */ -#define DUK_HBUFFER_GET_SIZE(x) ((x)->hdr.h_flags >> 16) -#define DUK_HBUFFER_SET_SIZE(x,v) do { \ +#define DUK_HBUFFER_GET_SIZE(x) ((x)->hdr.h_flags >> 16) +#define DUK_HBUFFER_SET_SIZE(x, v) \ + do { \ duk_size_t duk__v; \ duk__v = (v); \ DUK_ASSERT(duk__v <= 0xffffUL); \ (x)->hdr.h_flags = ((x)->hdr.h_flags & 0x0000ffffUL) | (((duk_uint32_t) duk__v) << 16); \ } while (0) -#define DUK_HBUFFER_ADD_SIZE(x,dv) do { \ +#define DUK_HBUFFER_ADD_SIZE(x, dv) \ + do { \ (x)->hdr.h_flags += ((dv) << 16); \ } while (0) -#define DUK_HBUFFER_SUB_SIZE(x,dv) do { \ +#define DUK_HBUFFER_SUB_SIZE(x, dv) \ + do { \ (x)->hdr.h_flags -= ((dv) << 16); \ } while (0) #else -#define DUK_HBUFFER_GET_SIZE(x) (((duk_hbuffer *) (x))->size) -#define DUK_HBUFFER_SET_SIZE(x,v) do { \ +#define DUK_HBUFFER_GET_SIZE(x) (((duk_hbuffer *) (x))->size) +#define DUK_HBUFFER_SET_SIZE(x, v) \ + do { \ ((duk_hbuffer *) (x))->size = (v); \ } while (0) -#define DUK_HBUFFER_ADD_SIZE(x,dv) do { \ +#define DUK_HBUFFER_ADD_SIZE(x, dv) \ + do { \ (x)->size += (dv); \ } while (0) -#define DUK_HBUFFER_SUB_SIZE(x,dv) do { \ +#define DUK_HBUFFER_SUB_SIZE(x, dv) \ + do { \ (x)->size -= (dv); \ } while (0) #endif -#define DUK_HBUFFER_FIXED_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_FIXED_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x)) +#define DUK_HBUFFER_FIXED_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) +#define DUK_HBUFFER_FIXED_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x)) #define DUK_HBUFFER_DYNAMIC_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_DYNAMIC_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) -#define DUK_HBUFFER_DYNAMIC_ADD_SIZE(x,dv) DUK_HBUFFER_ADD_SIZE((duk_hbuffer *) (x), (dv)) -#define DUK_HBUFFER_DYNAMIC_SUB_SIZE(x,dv) DUK_HBUFFER_SUB_SIZE((duk_hbuffer *) (x), (dv)) +#define DUK_HBUFFER_DYNAMIC_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) +#define DUK_HBUFFER_DYNAMIC_ADD_SIZE(x, dv) DUK_HBUFFER_ADD_SIZE((duk_hbuffer *) (x), (dv)) +#define DUK_HBUFFER_DYNAMIC_SUB_SIZE(x, dv) DUK_HBUFFER_SUB_SIZE((duk_hbuffer *) (x), (dv)) #define DUK_HBUFFER_EXTERNAL_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_EXTERNAL_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) +#define DUK_HBUFFER_EXTERNAL_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) -#define DUK_HBUFFER_FIXED_GET_DATA_PTR(heap,x) ((duk_uint8_t *) (((duk_hbuffer_fixed *) (void *) (x)) + 1)) +#define DUK_HBUFFER_FIXED_GET_DATA_PTR(heap, x) ((duk_uint8_t *) (((duk_hbuffer_fixed *) (void *) (x)) + 1)) #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap,x) \ +#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, x) \ ((void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (x))->h_extra16)) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, x, v) \ + do { \ ((duk_heaphdr *) (x))->h_extra16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap,x) do { \ - ((duk_heaphdr *) (x))->h_extra16 = 0; /* assume 0 <=> NULL */ \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap, x) \ + do { \ + ((duk_heaphdr *) (x))->h_extra16 = 0; /* assume 0 <=> NULL */ \ } while (0) #else -#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap,x) ((x)->curr_alloc) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, x) ((x)->curr_alloc) +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #endif @@ -119,21 +129,23 @@ * Duktape heap. */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap,x) \ - ((void *) (x)->curr_alloc) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap, x) ((void *) (x)->curr_alloc) +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #else -#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap,x) \ - ((void *) (x)->curr_alloc) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap, x) ((void *) (x)->curr_alloc) +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #endif @@ -142,32 +154,31 @@ * size). May be NULL for zero size dynamic/external buffer. */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_GET_DATA_PTR(heap,x) ( \ - DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ - ( \ - DUK_HBUFFER_HAS_EXTERNAL((x)) ? \ - DUK_HBUFFER_EXTERNAL_GET_DATA_PTR((heap), (duk_hbuffer_external *) (x)) : \ - DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) \ - ) : \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x)) \ - ) +#define DUK_HBUFFER_GET_DATA_PTR(heap, x) \ + (DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ + (DUK_HBUFFER_HAS_EXTERNAL((x)) ? DUK_HBUFFER_EXTERNAL_GET_DATA_PTR((heap), (duk_hbuffer_external *) (x)) : \ + DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x))) : \ + DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x))) #else /* Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external * have the same layout so checking for fixed vs. dynamic (or external) is enough. */ -#define DUK_HBUFFER_GET_DATA_PTR(heap,x) ( \ - DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ - DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) : \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x)) \ - ) +#define DUK_HBUFFER_GET_DATA_PTR(heap, x) \ + (DUK_HBUFFER_HAS_DYNAMIC((x)) ? DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) : \ + DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x))) #endif /* Validity assert. */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hbuffer_assert_valid(duk_hbuffer *h); -#define DUK_HBUFFER_ASSERT_VALID(h) do { duk_hbuffer_assert_valid((h)); } while (0) +#define DUK_HBUFFER_ASSERT_VALID(h) \ + do { \ + duk_hbuffer_assert_valid((h)); \ + } while (0) #else -#define DUK_HBUFFER_ASSERT_VALID(h) do {} while (0) +#define DUK_HBUFFER_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -265,9 +276,9 @@ */ } #if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_GCC_ATTR) -__attribute__ ((aligned (8))) +__attribute__((aligned(8))) #elif (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_CLANG_ATTR) -__attribute__ ((aligned (8))) +__attribute__((aligned(8))) #endif ; #if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_MSVC_PRAGMA) @@ -290,7 +301,7 @@ #if defined(DUK_USE_HEAPPTR16) /* Stored in duk_heaphdr h_extra16. */ #else - void *curr_alloc; /* may be NULL if alloc_size == 0 */ + void *curr_alloc; /* may be NULL if alloc_size == 0 */ #endif /* @@ -319,7 +330,7 @@ /* Cannot be compressed as a heap pointer because may point to * an arbitrary address. */ - void *curr_alloc; /* may be NULL if alloc_size == 0 */ + void *curr_alloc; /* may be NULL if alloc_size == 0 */ }; /* @@ -327,10 +338,10 @@ */ DUK_INTERNAL_DECL duk_hbuffer *duk_hbuffer_alloc(duk_heap *heap, duk_size_t size, duk_small_uint_t flags, void **out_bufdata); -DUK_INTERNAL_DECL void *duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud); /* indirect allocs */ +DUK_INTERNAL_DECL void *duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud); /* indirect allocs */ /* dynamic buffer ops */ DUK_INTERNAL_DECL void duk_hbuffer_resize(duk_hthread *thr, duk_hbuffer_dynamic *buf, duk_size_t new_size); DUK_INTERNAL_DECL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *buf); -#endif /* DUK_HBUFFER_H_INCLUDED */ +#endif /* DUK_HBUFFER_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hbuffer_alloc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hbuffer_alloc.c
Changed
@@ -25,7 +25,7 @@ */ if (size > DUK_HBUFFER_MAX_BYTELEN) { DUK_D(DUK_DPRINT("hbuffer alloc failed: size too large: %ld", (long) size)); - return NULL; /* no need to write 'out_bufdata' */ + return NULL; /* no need to write 'out_bufdata' */ } if (flags & DUK_BUF_FLAG_EXTERNAL) { @@ -37,7 +37,7 @@ } else { header_size = sizeof(duk_hbuffer_fixed); alloc_size = sizeof(duk_hbuffer_fixed) + size; - DUK_ASSERT(alloc_size >= sizeof(duk_hbuffer_fixed)); /* no wrapping */ + DUK_ASSERT(alloc_size >= sizeof(duk_hbuffer_fixed)); /* no wrapping */ } res = (duk_hbuffer *) DUK_ALLOC(heap, alloc_size); @@ -47,8 +47,7 @@ /* zero everything unless requested not to do so */ #if defined(DUK_USE_ZERO_BUFFER_DATA) - duk_memzero((void *) res, - (flags & DUK_BUF_FLAG_NOZERO) ? header_size : alloc_size); + duk_memzero((void *) res, (flags & DUK_BUF_FLAG_NOZERO) ? header_size : alloc_size); #else duk_memzero((void *) res, header_size); #endif @@ -71,7 +70,7 @@ void *ptr; if (size > 0) { - DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); /* alloc external with size zero */ + DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); /* alloc external with size zero */ DUK_DDD(DUK_DDDPRINT("dynamic buffer with nonzero size, alloc actual buffer")); #if defined(DUK_USE_ZERO_BUFFER_DATA) ptr = DUK_ALLOC_ZEROED(heap, size); @@ -111,16 +110,16 @@ } else { DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); } - DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, &res->hdr); + DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, &res->hdr); DUK_DDD(DUK_DDDPRINT("allocated hbuffer: %p", (void *) res)); return res; - alloc_error: +alloc_error: DUK_DD(DUK_DDPRINT("hbuffer allocation failed")); DUK_FREE(heap, res); - return NULL; /* no need to write 'out_bufdata' */ + return NULL; /* no need to write 'out_bufdata' */ } /* For indirect allocs. */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hbuffer_assert.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hbuffer_assert.c
Changed
@@ -10,4 +10,4 @@ DUK_ASSERT(h != NULL); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hbuffer_ops.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hbuffer_ops.c
Changed
@@ -53,8 +53,7 @@ if (new_size > prev_size) { DUK_ASSERT(new_size - prev_size > 0); #if defined(DUK_USE_ZERO_BUFFER_DATA) - duk_memzero((void *) ((char *) res + prev_size), - (duk_size_t) (new_size - prev_size)); + duk_memzero((void *) ((char *) res + prev_size), (duk_size_t) (new_size - prev_size)); #endif }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hbufobj.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hbufobj.h
Changed
@@ -8,31 +8,37 @@ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) /* All element accessors are host endian now (driven by TypedArray spec). */ -#define DUK_HBUFOBJ_ELEM_UINT8 0 -#define DUK_HBUFOBJ_ELEM_UINT8CLAMPED 1 -#define DUK_HBUFOBJ_ELEM_INT8 2 -#define DUK_HBUFOBJ_ELEM_UINT16 3 -#define DUK_HBUFOBJ_ELEM_INT16 4 -#define DUK_HBUFOBJ_ELEM_UINT32 5 -#define DUK_HBUFOBJ_ELEM_INT32 6 -#define DUK_HBUFOBJ_ELEM_FLOAT32 7 -#define DUK_HBUFOBJ_ELEM_FLOAT64 8 -#define DUK_HBUFOBJ_ELEM_MAX 8 +#define DUK_HBUFOBJ_ELEM_UINT8 0 +#define DUK_HBUFOBJ_ELEM_UINT8CLAMPED 1 +#define DUK_HBUFOBJ_ELEM_INT8 2 +#define DUK_HBUFOBJ_ELEM_UINT16 3 +#define DUK_HBUFOBJ_ELEM_INT16 4 +#define DUK_HBUFOBJ_ELEM_UINT32 5 +#define DUK_HBUFOBJ_ELEM_INT32 6 +#define DUK_HBUFOBJ_ELEM_FLOAT32 7 +#define DUK_HBUFOBJ_ELEM_FLOAT64 8 +#define DUK_HBUFOBJ_ELEM_MAX 8 #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hbufobj_assert_valid(duk_hbufobj *h); -#define DUK_HBUFOBJ_ASSERT_VALID(h) do { duk_hbufobj_assert_valid((h)); } while (0) +#define DUK_HBUFOBJ_ASSERT_VALID(h) \ + do { \ + duk_hbufobj_assert_valid((h)); \ + } while (0) #else -#define DUK_HBUFOBJ_ASSERT_VALID(h) do {} while (0) +#define DUK_HBUFOBJ_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* Get the current data pointer (caller must ensure buf != NULL) as a * duk_uint8_t ptr. Note that the result may be NULL if the underlying * buffer has zero size and is not a fixed buffer. */ -#define DUK_HBUFOBJ_GET_SLICE_BASE(heap,h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - (((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR((heap), (h)->buf)) + (h)->offset)) +#define DUK_HBUFOBJ_GET_SLICE_BASE(heap, h) \ + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + (((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR((heap), (h)->buf)) + (h)->offset)) /* True if slice is full, i.e. offset is zero and length covers the entire * buffer. This status may change independently of the duk_hbufobj if @@ -40,15 +46,17 @@ * being changed. */ #define DUK_HBUFOBJ_FULL_SLICE(h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset == 0 && (h)->length == DUK_HBUFFER_GET_SIZE((h)->buf))) + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + ((h)->offset == 0 && (h)->length == DUK_HBUFFER_GET_SIZE((h)->buf))) /* Validate that the whole slice 0,length is contained in the underlying * buffer. Caller must ensure 'buf' != NULL. */ #define DUK_HBUFOBJ_VALID_SLICE(h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (h)->length <= DUK_HBUFFER_GET_SIZE((h)->buf))) + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + ((h)->offset + (h)->length <= DUK_HBUFFER_GET_SIZE((h)->buf))) /* Validate byte read/write for virtual 'offset', i.e. check that the * offset, taking into account h->offset, is within the underlying @@ -57,13 +65,11 @@ * behavior (e.g. if an underlying dynamic buffer changes after being * setup). Caller must ensure 'buf' != NULL. */ -#define DUK_HBUFOBJ_VALID_BYTEOFFSET_INCL(h,off) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf))) +#define DUK_HBUFOBJ_VALID_BYTEOFFSET_INCL(h, off) \ + (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), ((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf))) -#define DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h,off) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (off) <= DUK_HBUFFER_GET_SIZE((h)->buf))) +#define DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h, off) \ + (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), ((h)->offset + (off) <= DUK_HBUFFER_GET_SIZE((h)->buf))) /* Clamp an input byte length (already assumed to be within the nominal * duk_hbufobj 'length') to the current dynamic buffer limits to yield @@ -71,12 +77,10 @@ * be invalidated by any side effect because it may trigger a user * callback that resizes the underlying buffer. */ -#define DUK_HBUFOBJ_CLAMP_BYTELENGTH(h,len) \ - (DUK_ASSERT_EXPR((h) != NULL), \ - duk_hbufobj_clamp_bytelength((h), (len))) +#define DUK_HBUFOBJ_CLAMP_BYTELENGTH(h, len) (DUK_ASSERT_EXPR((h) != NULL), duk_hbufobj_clamp_bytelength((h), (len))) /* Typed arrays have virtual indices, ArrayBuffer and DataView do not. */ -#define DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h) ((h)->is_typedarray) +#define DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h) ((h)->is_typedarray) struct duk_hbufobj { /* Shared object part. */ @@ -101,27 +105,33 @@ * be dynamic and its pointer unstable. */ - duk_uint_t offset; /* byte offset to buf */ - duk_uint_t length; /* byte index limit for element access, exclusive */ - duk_uint8_t shift; /* element size shift: - * 0 = u8/i8 - * 1 = u16/i16 - * 2 = u32/i32/float - * 3 = double - */ - duk_uint8_t elem_type; /* element type */ + duk_uint_t offset; /* byte offset to buf */ + duk_uint_t length; /* byte index limit for element access, exclusive */ + duk_uint8_t shift; /* element size shift: + * 0 = u8/i8 + * 1 = u16/i16 + * 2 = u32/i32/float + * 3 = double + */ + duk_uint8_t elem_type; /* element type */ duk_uint8_t is_typedarray; }; DUK_INTERNAL_DECL duk_uint_t duk_hbufobj_clamp_bytelength(duk_hbufobj *h_bufobj, duk_uint_t len); DUK_INTERNAL_DECL void duk_hbufobj_push_uint8array_from_plain(duk_hthread *thr, duk_hbuffer *h_buf); -DUK_INTERNAL_DECL void duk_hbufobj_push_validated_read(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size); -DUK_INTERNAL_DECL void duk_hbufobj_validated_write(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size); +DUK_INTERNAL_DECL void duk_hbufobj_push_validated_read(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size); +DUK_INTERNAL_DECL void duk_hbufobj_validated_write(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size); DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_hthread *thr, duk_idx_t idx); -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* nothing */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ -#endif /* DUK_HBUFOBJ_H_INCLUDED */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_HBUFOBJ_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hbufobj_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hbufobj_misc.c
Changed
@@ -17,4 +17,4 @@ return buf_avail >= len ? len : buf_avail; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hcompfunc.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hcompfunc.h
Changed
@@ -15,50 +15,55 @@ /* XXX: casts could be improved, especially for GET/SET DATA */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HCOMPFUNC_GET_DATA(heap,h) \ - ((duk_hbuffer_fixed *) (void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->data16)) -#define DUK_HCOMPFUNC_SET_DATA(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_DATA(heap, h) ((duk_hbuffer_fixed *) (void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->data16)) +#define DUK_HCOMPFUNC_SET_DATA(heap, h, v) \ + do { \ (h)->data16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_FUNCS(heap,h) \ - ((duk_hobject **) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->funcs16))) -#define DUK_HCOMPFUNC_SET_FUNCS(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_FUNCS(heap, h) ((duk_hobject **) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->funcs16))) +#define DUK_HCOMPFUNC_SET_FUNCS(heap, h, v) \ + do { \ (h)->funcs16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_BYTECODE(heap,h) \ - ((duk_instr_t *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->bytecode16))) -#define DUK_HCOMPFUNC_SET_BYTECODE(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_BYTECODE(heap, h) ((duk_instr_t *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->bytecode16))) +#define DUK_HCOMPFUNC_SET_BYTECODE(heap, h, v) \ + do { \ (h)->bytecode16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_LEXENV(heap,h) \ - ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->lex_env16))) -#define DUK_HCOMPFUNC_SET_LEXENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_LEXENV(heap, h) ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->lex_env16))) +#define DUK_HCOMPFUNC_SET_LEXENV(heap, h, v) \ + do { \ (h)->lex_env16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_VARENV(heap,h) \ - ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->var_env16))) -#define DUK_HCOMPFUNC_SET_VARENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_VARENV(heap, h) ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->var_env16))) +#define DUK_HCOMPFUNC_SET_VARENV(heap, h, v) \ + do { \ (h)->var_env16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) #else -#define DUK_HCOMPFUNC_GET_DATA(heap,h) ((duk_hbuffer_fixed *) (void *) (h)->data) -#define DUK_HCOMPFUNC_SET_DATA(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_DATA(heap, h) ((duk_hbuffer_fixed *) (void *) (h)->data) +#define DUK_HCOMPFUNC_SET_DATA(heap, h, v) \ + do { \ (h)->data = (duk_hbuffer *) (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_FUNCS(heap,h) ((h)->funcs) -#define DUK_HCOMPFUNC_SET_FUNCS(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_FUNCS(heap, h) ((h)->funcs) +#define DUK_HCOMPFUNC_SET_FUNCS(heap, h, v) \ + do { \ (h)->funcs = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_BYTECODE(heap,h) ((h)->bytecode) -#define DUK_HCOMPFUNC_SET_BYTECODE(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_BYTECODE(heap, h) ((h)->bytecode) +#define DUK_HCOMPFUNC_SET_BYTECODE(heap, h, v) \ + do { \ (h)->bytecode = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_LEXENV(heap,h) ((h)->lex_env) -#define DUK_HCOMPFUNC_SET_LEXENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_LEXENV(heap, h) ((h)->lex_env) +#define DUK_HCOMPFUNC_SET_LEXENV(heap, h, v) \ + do { \ (h)->lex_env = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_VARENV(heap,h) ((h)->var_env) -#define DUK_HCOMPFUNC_SET_VARENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_VARENV(heap, h) ((h)->var_env) +#define DUK_HCOMPFUNC_SET_VARENV(heap, h, v) \ + do { \ (h)->var_env = (v); \ } while (0) #endif @@ -68,64 +73,40 @@ */ /* Note: assumes 'data' is always a fixed buffer */ -#define DUK_HCOMPFUNC_GET_BUFFER_BASE(heap,h) \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) +#define DUK_HCOMPFUNC_GET_BUFFER_BASE(heap, h) DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) -#define DUK_HCOMPFUNC_GET_CONSTS_BASE(heap,h) \ - ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_BUFFER_BASE((heap), (h))) +#define DUK_HCOMPFUNC_GET_CONSTS_BASE(heap, h) ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_BUFFER_BASE((heap), (h))) -#define DUK_HCOMPFUNC_GET_FUNCS_BASE(heap,h) \ - DUK_HCOMPFUNC_GET_FUNCS((heap), (h)) +#define DUK_HCOMPFUNC_GET_FUNCS_BASE(heap, h) DUK_HCOMPFUNC_GET_FUNCS((heap), (h)) -#define DUK_HCOMPFUNC_GET_CODE_BASE(heap,h) \ - DUK_HCOMPFUNC_GET_BYTECODE((heap), (h)) +#define DUK_HCOMPFUNC_GET_CODE_BASE(heap, h) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h)) -#define DUK_HCOMPFUNC_GET_CONSTS_END(heap,h) \ - ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_FUNCS((heap), (h))) +#define DUK_HCOMPFUNC_GET_CONSTS_END(heap, h) ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_FUNCS((heap), (h))) -#define DUK_HCOMPFUNC_GET_FUNCS_END(heap,h) \ - ((duk_hobject **) (void *) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h))) +#define DUK_HCOMPFUNC_GET_FUNCS_END(heap, h) ((duk_hobject **) (void *) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h))) /* XXX: double evaluation of DUK_HCOMPFUNC_GET_DATA() */ -#define DUK_HCOMPFUNC_GET_CODE_END(heap,h) \ +#define DUK_HCOMPFUNC_GET_CODE_END(heap, h) \ ((duk_instr_t *) (void *) (DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) + \ - DUK_HBUFFER_GET_SIZE((duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA((heap), h)))) + DUK_HBUFFER_GET_SIZE((duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA((heap), h)))) -#define DUK_HCOMPFUNC_GET_CONSTS_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_END((heap), (h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_BASE((heap), (h))) \ - ) \ - ) +#define DUK_HCOMPFUNC_GET_CONSTS_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_BASE((heap), (h))))) -#define DUK_HCOMPFUNC_GET_FUNCS_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_END((heap), (h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_BASE((heap), (h))) \ - ) \ - ) +#define DUK_HCOMPFUNC_GET_FUNCS_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_BASE((heap), (h))))) -#define DUK_HCOMPFUNC_GET_CODE_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_END((heap),(h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_BASE((heap),(h))) \ - ) \ - ) +#define DUK_HCOMPFUNC_GET_CODE_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_BASE((heap), (h))))) -#define DUK_HCOMPFUNC_GET_CONSTS_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_CONSTS_SIZE((heap), (h)) / sizeof(duk_tval))) +#define DUK_HCOMPFUNC_GET_CONSTS_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_CONSTS_SIZE((heap), (h)) / sizeof(duk_tval))) -#define DUK_HCOMPFUNC_GET_FUNCS_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_FUNCS_SIZE((heap), (h)) / sizeof(duk_hobject *))) +#define DUK_HCOMPFUNC_GET_FUNCS_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_FUNCS_SIZE((heap), (h)) / sizeof(duk_hobject *))) -#define DUK_HCOMPFUNC_GET_CODE_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_CODE_SIZE((heap), (h)) / sizeof(duk_instr_t))) +#define DUK_HCOMPFUNC_GET_CODE_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_CODE_SIZE((heap), (h)) / sizeof(duk_instr_t))) /* * Validity assert @@ -133,9 +114,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hcompfunc_assert_valid(duk_hcompfunc *h); -#define DUK_HCOMPFUNC_ASSERT_VALID(h) do { duk_hcompfunc_assert_valid((h)); } while (0) +#define DUK_HCOMPFUNC_ASSERT_VALID(h) \ + do { \ + duk_hcompfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HCOMPFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HCOMPFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -222,8 +208,8 @@ * at run time, except for debugging, so it is not maintained. */ - duk_uint16_t nregs; /* regs to allocate */ - duk_uint16_t nargs; /* number of arguments allocated to regs */ + duk_uint16_t nregs; /* regs to allocate */ + duk_uint16_t nargs; /* number of arguments allocated to regs */ /* * Additional control information is placed into the object itself @@ -270,4 +256,4 @@ #endif }; -#endif /* DUK_HCOMPFUNC_H_INCLUDED */ +#endif /* DUK_HCOMPFUNC_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heap.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heap.h
Changed
@@ -14,46 +14,50 @@ * Heap flags */ -#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED (1U << 0) /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */ -#define DUK_HEAP_FLAG_INTERRUPT_RUNNING (1U << 1) /* executor interrupt running (used to avoid nested interrupts) */ -#define DUK_HEAP_FLAG_FINALIZER_NORESCUE (1U << 2) /* heap destruction ongoing, finalizer rescue no longer possible */ -#define DUK_HEAP_FLAG_DEBUGGER_PAUSED (1U << 3) /* debugger is paused: talk with debug client until step/resume */ - -#define DUK__HEAP_HAS_FLAGS(heap,bits) ((heap)->flags & (bits)) -#define DUK__HEAP_SET_FLAGS(heap,bits) do { \ +#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED \ + (1U << 0) /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */ +#define DUK_HEAP_FLAG_INTERRUPT_RUNNING (1U << 1) /* executor interrupt running (used to avoid nested interrupts) */ +#define DUK_HEAP_FLAG_FINALIZER_NORESCUE (1U << 2) /* heap destruction ongoing, finalizer rescue no longer possible */ +#define DUK_HEAP_FLAG_DEBUGGER_PAUSED (1U << 3) /* debugger is paused: talk with debug client until step/resume */ + +#define DUK__HEAP_HAS_FLAGS(heap, bits) ((heap)->flags & (bits)) +#define DUK__HEAP_SET_FLAGS(heap, bits) \ + do { \ (heap)->flags |= (bits); \ } while (0) -#define DUK__HEAP_CLEAR_FLAGS(heap,bits) do { \ +#define DUK__HEAP_CLEAR_FLAGS(heap, bits) \ + do { \ (heap)->flags &= ~(bits); \ } while (0) -#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_HAS_INTERRUPT_RUNNING(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_HAS_DEBUGGER_PAUSED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) +#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_HAS_INTERRUPT_RUNNING(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_HAS_DEBUGGER_PAUSED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) -#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_SET_INTERRUPT_RUNNING(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_SET_DEBUGGER_PAUSED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) +#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_SET_INTERRUPT_RUNNING(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_SET_DEBUGGER_PAUSED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) -#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_CLEAR_INTERRUPT_RUNNING(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_CLEAR_FINALIZER_NORESCUE(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_CLEAR_DEBUGGER_PAUSED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) +#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap) \ + DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_CLEAR_INTERRUPT_RUNNING(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_CLEAR_FINALIZER_NORESCUE(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_CLEAR_DEBUGGER_PAUSED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) /* * Longjmp types, also double as identifying continuation type for a rethrow (in 'finally') */ -#define DUK_LJ_TYPE_UNKNOWN 0 /* unused */ -#define DUK_LJ_TYPE_THROW 1 /* value1 -> error object */ -#define DUK_LJ_TYPE_YIELD 2 /* value1 -> yield value, iserror -> error / normal */ -#define DUK_LJ_TYPE_RESUME 3 /* value1 -> resume value, value2 -> resumee thread, iserror -> error/normal */ -#define DUK_LJ_TYPE_BREAK 4 /* value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_CONTINUE 5 /* value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_RETURN 6 /* value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_NORMAL 7 /* no value, pseudo-type to indicate a normal continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_UNKNOWN 0 /* unused */ +#define DUK_LJ_TYPE_THROW 1 /* value1 -> error object */ +#define DUK_LJ_TYPE_YIELD 2 /* value1 -> yield value, iserror -> error / normal */ +#define DUK_LJ_TYPE_RESUME 3 /* value1 -> resume value, value2 -> resumee thread, iserror -> error/normal */ +#define DUK_LJ_TYPE_BREAK 4 /* value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_CONTINUE 5 /* value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_RETURN 6 /* value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_NORMAL 7 /* no value, pseudo-type to indicate a normal continuation (for ENDFIN) */ /* * Mark-and-sweep flags @@ -66,19 +70,19 @@ /* Emergency mark-and-sweep: try extra hard, even at the cost of * performance. */ -#define DUK_MS_FLAG_EMERGENCY (1U << 0) +#define DUK_MS_FLAG_EMERGENCY (1U << 0) /* Postpone rescue decisions for reachable objects with FINALIZED set. * Used during finalize_list processing to avoid incorrect rescue * decisions due to finalize_list being a reachability root. */ -#define DUK_MS_FLAG_POSTPONE_RESCUE (1U << 1) +#define DUK_MS_FLAG_POSTPONE_RESCUE (1U << 1) /* Don't compact objects; needed during object property table resize * to prevent a recursive resize. It would suffice to protect only the * current object being resized, but this is not yet implemented. */ -#define DUK_MS_FLAG_NO_OBJECT_COMPACTION (1U << 2) +#define DUK_MS_FLAG_NO_OBJECT_COMPACTION (1U << 2) /* * Thread switching @@ -89,9 +93,10 @@ */ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK_HEAP_SWITCH_THREAD(heap,newthr) duk_heap_switch_thread((heap), (newthr)) +#define DUK_HEAP_SWITCH_THREAD(heap, newthr) duk_heap_switch_thread((heap), (newthr)) #else -#define DUK_HEAP_SWITCH_THREAD(heap,newthr) do { \ +#define DUK_HEAP_SWITCH_THREAD(heap, newthr) \ + do { \ (heap)->curr_thread = (newthr); \ } while (0) #endif @@ -101,11 +106,14 @@ */ #if defined(DUK_USE_DEBUG) -#define DUK_STATS_INC(heap,fieldname) do { \ +#define DUK_STATS_INC(heap, fieldname) \ + do { \ (heap)->fieldname += 1; \ } while (0) #else -#define DUK_STATS_INC(heap,fieldname) do {} while (0) +#define DUK_STATS_INC(heap, fieldname) \ + do { \ + } while (0) #endif /* @@ -123,36 +131,41 @@ * only during init phases). */ #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 12800L /* 50x heap size */ -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 12800L /* 50x heap size */ +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L #else -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 256L /* 1x heap size */ -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 256L /* 1x heap size */ +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L #endif /* GC torture. */ #if defined(DUK_USE_GC_TORTURE) -#define DUK_GC_TORTURE(heap) do { duk_heap_mark_and_sweep((heap), 0); } while (0) +#define DUK_GC_TORTURE(heap) \ + do { \ + duk_heap_mark_and_sweep((heap), 0); \ + } while (0) #else -#define DUK_GC_TORTURE(heap) do { } while (0) +#define DUK_GC_TORTURE(heap) \ + do { \ + } while (0) #endif /* Stringcache is used for speeding up char-offset-to-byte-offset * translations for non-ASCII strings. */ -#define DUK_HEAP_STRCACHE_SIZE 4 -#define DUK_HEAP_STRINGCACHE_NOCACHE_LIMIT 16 /* strings up to the this length are not cached */ +#define DUK_HEAP_STRCACHE_SIZE 4 +#define DUK_HEAP_STRINGCACHE_NOCACHE_LIMIT 16 /* strings up to the this length are not cached */ /* Some list management macros. */ -#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap,hdr) duk_heap_insert_into_heap_allocated((heap), (hdr)) +#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, hdr) duk_heap_insert_into_heap_allocated((heap), (hdr)) #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAP_REMOVE_FROM_HEAP_ALLOCATED(heap,hdr) duk_heap_remove_from_heap_allocated((heap), (hdr)) +#define DUK_HEAP_REMOVE_FROM_HEAP_ALLOCATED(heap, hdr) duk_heap_remove_from_heap_allocated((heap), (hdr)) #endif #if defined(DUK_USE_FINALIZER_SUPPORT) -#define DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap,hdr) duk_heap_insert_into_finalize_list((heap), (hdr)) -#define DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(heap,hdr) duk_heap_remove_from_finalize_list((heap), (hdr)) +#define DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap, hdr) duk_heap_insert_into_finalize_list((heap), (hdr)) +#define DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(heap, hdr) duk_heap_remove_from_finalize_list((heap), (hdr)) #endif /* @@ -161,30 +174,24 @@ /* heap string indices are autogenerated in duk_strings.h */ #if defined(DUK_USE_ROM_STRINGS) -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) -#else /* DUK_USE_ROM_STRINGS */ +#define DUK_HEAP_GET_STRING(heap, idx) ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (heap)->strs16(idx))) +#define DUK_HEAP_GET_STRING(heap, idx) ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (heap)->strs16(idx))) #else -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((heap)->strs(idx)) +#define DUK_HEAP_GET_STRING(heap, idx) ((heap)->strs(idx)) #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ /* * Raw memory calls: relative to heap, but no GC interaction */ -#define DUK_ALLOC_RAW(heap,size) \ - ((heap)->alloc_func((heap)->heap_udata, (size))) +#define DUK_ALLOC_RAW(heap, size) ((heap)->alloc_func((heap)->heap_udata, (size))) -#define DUK_REALLOC_RAW(heap,ptr,newsize) \ - ((heap)->realloc_func((heap)->heap_udata, (void *) (ptr), (newsize))) +#define DUK_REALLOC_RAW(heap, ptr, newsize) ((heap)->realloc_func((heap)->heap_udata, (void *) (ptr), (newsize))) -#define DUK_FREE_RAW(heap,ptr) \ - ((heap)->free_func((heap)->heap_udata, (void *) (ptr))) +#define DUK_FREE_RAW(heap, ptr) ((heap)->free_func((heap)->heap_udata, (void *) (ptr))) /* * Memory calls: relative to heap, GC interaction, but no error throwing. @@ -217,11 +224,11 @@ /* callback for indirect reallocs, request for current pointer */ typedef void *(*duk_mem_getptr)(duk_heap *heap, void *ud); -#define DUK_ALLOC(heap,size) duk_heap_mem_alloc((heap), (size)) -#define DUK_ALLOC_ZEROED(heap,size) duk_heap_mem_alloc_zeroed((heap), (size)) -#define DUK_REALLOC(heap,ptr,newsize) duk_heap_mem_realloc((heap), (ptr), (newsize)) -#define DUK_REALLOC_INDIRECT(heap,cb,ud,newsize) duk_heap_mem_realloc_indirect((heap), (cb), (ud), (newsize)) -#define DUK_FREE(heap,ptr) duk_heap_mem_free((heap), (ptr)) +#define DUK_ALLOC(heap, size) duk_heap_mem_alloc((heap), (size)) +#define DUK_ALLOC_ZEROED(heap, size) duk_heap_mem_alloc_zeroed((heap), (size)) +#define DUK_REALLOC(heap, ptr, newsize) duk_heap_mem_realloc((heap), (ptr), (newsize)) +#define DUK_REALLOC_INDIRECT(heap, cb, ud, newsize) duk_heap_mem_realloc_indirect((heap), (cb), (ud), (newsize)) +#define DUK_FREE(heap, ptr) duk_heap_mem_free((heap), (ptr)) /* * Checked allocation, relative to a thread @@ -230,24 +237,26 @@ * for convenience. */ -#define DUK_ALLOC_CHECKED(thr,size) duk_heap_mem_alloc_checked((thr), (size)) -#define DUK_ALLOC_CHECKED_ZEROED(thr,size) duk_heap_mem_alloc_checked_zeroed((thr), (size)) -#define DUK_FREE_CHECKED(thr,ptr) duk_heap_mem_free((thr)->heap, (ptr)) +#define DUK_ALLOC_CHECKED(thr, size) duk_heap_mem_alloc_checked((thr), (size)) +#define DUK_ALLOC_CHECKED_ZEROED(thr, size) duk_heap_mem_alloc_checked_zeroed((thr), (size)) +#define DUK_FREE_CHECKED(thr, ptr) duk_heap_mem_free((thr)->heap, (ptr)) /* * Memory constants */ -#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_LIMIT 10 /* Retry allocation after mark-and-sweep for this - * many times. A single mark-and-sweep round is - * not guaranteed to free all unreferenced memory - * because of finalization (in fact, ANY number of - * rounds is strictly not enough). - */ +#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_LIMIT \ + 10 /* Retry allocation after mark-and-sweep for this \ + * many times. A single mark-and-sweep round is \ + * not guaranteed to free all unreferenced memory \ + * because of finalization (in fact, ANY number of \ + * rounds is strictly not enough). \ + */ -#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_EMERGENCY_LIMIT 3 /* Starting from this round, use emergency mode - * for mark-and-sweep. - */ +#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_EMERGENCY_LIMIT \ + 3 /* Starting from this round, use emergency mode \ + * for mark-and-sweep. \ + */ /* * Debugger support @@ -256,26 +265,26 @@ /* Maximum number of breakpoints. Only breakpoints that are set are * consulted so increasing this has no performance impact. */ -#define DUK_HEAP_MAX_BREAKPOINTS 16 +#define DUK_HEAP_MAX_BREAKPOINTS 16 /* Opcode interval for a Date-based status/peek rate limit check. Only * relevant when debugger is attached. Requesting a timestamp may be a * slow operation on some platforms so this shouldn't be too low. On the * other hand a high value makes Duktape react to a pause request slowly. */ -#define DUK_HEAP_DBG_RATELIMIT_OPCODES 4000 +#define DUK_HEAP_DBG_RATELIMIT_OPCODES 4000 /* Milliseconds between status notify and transport peeks. */ -#define DUK_HEAP_DBG_RATELIMIT_MILLISECS 200 +#define DUK_HEAP_DBG_RATELIMIT_MILLISECS 200 /* Debugger pause flags. */ -#define DUK_PAUSE_FLAG_ONE_OPCODE (1U << 0) /* pause when a single opcode has been executed */ -#define DUK_PAUSE_FLAG_ONE_OPCODE_ACTIVE (1U << 1) /* one opcode pause actually active; artifact of current implementation */ -#define DUK_PAUSE_FLAG_LINE_CHANGE (1U << 2) /* pause when current line number changes */ -#define DUK_PAUSE_FLAG_FUNC_ENTRY (1U << 3) /* pause when entering a function */ -#define DUK_PAUSE_FLAG_FUNC_EXIT (1U << 4) /* pause when exiting current function */ -#define DUK_PAUSE_FLAG_CAUGHT_ERROR (1U << 5) /* pause when about to throw an error that is caught */ -#define DUK_PAUSE_FLAG_UNCAUGHT_ERROR (1U << 6) /* pause when about to throw an error that won't be caught */ +#define DUK_PAUSE_FLAG_ONE_OPCODE (1U << 0) /* pause when a single opcode has been executed */ +#define DUK_PAUSE_FLAG_ONE_OPCODE_ACTIVE (1U << 1) /* one opcode pause actually active; artifact of current implementation */ +#define DUK_PAUSE_FLAG_LINE_CHANGE (1U << 2) /* pause when current line number changes */ +#define DUK_PAUSE_FLAG_FUNC_ENTRY (1U << 3) /* pause when entering a function */ +#define DUK_PAUSE_FLAG_FUNC_EXIT (1U << 4) /* pause when exiting current function */ +#define DUK_PAUSE_FLAG_CAUGHT_ERROR (1U << 5) /* pause when about to throw an error that is caught */ +#define DUK_PAUSE_FLAG_UNCAUGHT_ERROR (1U << 6) /* pause when about to throw an error that won't be caught */ struct duk_breakpoint { duk_hstring *filename; @@ -303,21 +312,23 @@ */ struct duk_ljstate { - duk_jmpbuf *jmpbuf_ptr; /* current setjmp() catchpoint */ - duk_small_uint_t type; /* longjmp type */ - duk_bool_t iserror; /* isError flag for yield */ - duk_tval value1; /* 1st related value (type specific) */ - duk_tval value2; /* 2nd related value (type specific) */ + duk_jmpbuf *jmpbuf_ptr; /* current setjmp() catchpoint */ + duk_small_uint_t type; /* longjmp type */ + duk_bool_t iserror; /* isError flag for yield */ + duk_tval value1; /* 1st related value (type specific) */ + duk_tval value2; /* 2nd related value (type specific) */ }; -#define DUK_ASSERT_LJSTATE_UNSET(heap) do { \ +#define DUK_ASSERT_LJSTATE_UNSET(heap) \ + do { \ DUK_ASSERT(heap != NULL); \ DUK_ASSERT(heap->lj.type == DUK_LJ_TYPE_UNKNOWN); \ DUK_ASSERT(heap->lj.iserror == 0); \ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&heap->lj.value1)); \ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&heap->lj.value2)); \ } while (0) -#define DUK_ASSERT_LJSTATE_SET(heap) do { \ +#define DUK_ASSERT_LJSTATE_SET(heap) \ + do { \ DUK_ASSERT(heap != NULL); \ DUK_ASSERT(heap->lj.type != DUK_LJ_TYPE_UNKNOWN); \ } while (0) @@ -337,9 +348,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_heap_assert_valid(duk_heap *heap); -#define DUK_HEAP_ASSERT_VALID(heap) do { duk_heap_assert_valid((heap)); } while (0) +#define DUK_HEAP_ASSERT_VALID(heap) \ + do { \ + duk_heap_assert_valid((heap)); \ + } while (0) #else -#define DUK_HEAP_ASSERT_VALID(heap) do {} while (0) +#define DUK_HEAP_ASSERT_VALID(heap) \ + do { \ + } while (0) #endif struct duk_heap { @@ -493,9 +509,9 @@ /* Random number state for duk_util_tinyrandom.c. */ #if !defined(DUK_USE_GET_RANDOM_DOUBLE) #if defined(DUK_USE_PREFER_SIZE) || !defined(DUK_USE_64BIT_OPS) - duk_uint32_t rnd_state; /* State for Shamir's three-op algorithm */ + duk_uint32_t rnd_state; /* State for Shamir's three-op algorithm */ #else - duk_uint64_t rnd_state2; /* State for xoroshiro128+ */ + duk_uint64_t rnd_state2; /* State for xoroshiro128+ */ #endif #endif @@ -518,8 +534,8 @@ /* Debugger state. */ #if defined(DUK_USE_DEBUGGER_SUPPORT) /* Callbacks and udata; dbg_read_cb != NULL is used to indicate attached state. */ - duk_debug_read_function dbg_read_cb; /* required, NULL implies detached */ - duk_debug_write_function dbg_write_cb; /* required */ + duk_debug_read_function dbg_read_cb; /* required, NULL implies detached */ + duk_debug_write_function dbg_write_cb; /* required */ duk_debug_peek_function dbg_peek_cb; duk_debug_read_flush_function dbg_read_flush_cb; duk_debug_write_flush_function dbg_write_flush_cb; @@ -528,29 +544,32 @@ void *dbg_udata; /* The following are only relevant when debugger is attached. */ - duk_bool_t dbg_processing; /* currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval) */ - duk_bool_t dbg_state_dirty; /* resend state next time executor is about to run */ - duk_bool_t dbg_force_restart; /* force executor restart to recheck breakpoints; used to handle function returns (see GH-303) */ - duk_bool_t dbg_detaching; /* debugger detaching; used to avoid calling detach handler recursively */ - duk_small_uint_t dbg_pause_flags; /* flags for automatic pause behavior */ - duk_activation *dbg_pause_act; /* activation related to pause behavior (pause on line change, function entry/exit) */ - duk_uint32_t dbg_pause_startline; /* starting line number for line change related pause behavior */ - duk_breakpoint dbg_breakpointsDUK_HEAP_MAX_BREAKPOINTS; /* breakpoints: 0,breakpoint_count gc reachable */ + duk_bool_t dbg_processing; /* currently processing messages or breakpoints: don't enter message processing recursively (e.g. + no breakpoints when processing debugger eval) */ + duk_bool_t dbg_state_dirty; /* resend state next time executor is about to run */ + duk_bool_t + dbg_force_restart; /* force executor restart to recheck breakpoints; used to handle function returns (see GH-303) */ + duk_bool_t dbg_detaching; /* debugger detaching; used to avoid calling detach handler recursively */ + duk_small_uint_t dbg_pause_flags; /* flags for automatic pause behavior */ + duk_activation *dbg_pause_act; /* activation related to pause behavior (pause on line change, function entry/exit) */ + duk_uint32_t dbg_pause_startline; /* starting line number for line change related pause behavior */ + duk_breakpoint dbg_breakpointsDUK_HEAP_MAX_BREAKPOINTS; /* breakpoints: 0,breakpoint_count gc reachable */ duk_small_uint_t dbg_breakpoint_count; - duk_breakpoint *dbg_breakpoints_activeDUK_HEAP_MAX_BREAKPOINTS + 1; /* currently active breakpoints: NULL term, borrowed pointers */ + duk_breakpoint + *dbg_breakpoints_activeDUK_HEAP_MAX_BREAKPOINTS + 1; /* currently active breakpoints: NULL term, borrowed pointers */ /* XXX: make active breakpoints actual copies instead of pointers? */ /* These are for rate limiting Status notifications and transport peeking. */ - duk_uint_t dbg_exec_counter; /* cumulative opcode execution count (overflows are OK) */ - duk_uint_t dbg_last_counter; /* value of dbg_exec_counter when we last did a Date-based check */ - duk_double_t dbg_last_time; /* time when status/peek was last done (Date-based rate limit) */ + duk_uint_t dbg_exec_counter; /* cumulative opcode execution count (overflows are OK) */ + duk_uint_t dbg_last_counter; /* value of dbg_exec_counter when we last did a Date-based check */ + duk_double_t dbg_last_time; /* time when status/peek was last done (Date-based rate limit) */ /* Used to support single-byte stream lookahead. */ duk_bool_t dbg_have_next_byte; duk_uint8_t dbg_next_byte; -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) - duk_bool_t dbg_calling_transport; /* transport call in progress, calling into Duktape forbidden */ + duk_bool_t dbg_calling_transport; /* transport call in progress, calling into Duktape forbidden */ #endif /* String intern table (weak refs). */ @@ -559,12 +578,12 @@ #else duk_hstring **strtable; #endif - duk_uint32_t st_mask; /* mask for lookup, st_size - 1 */ - duk_uint32_t st_size; /* stringtable size */ + duk_uint32_t st_mask; /* mask for lookup, st_size - 1 */ + duk_uint32_t st_size; /* stringtable size */ #if (DUK_USE_STRTAB_MINSIZE != DUK_USE_STRTAB_MAXSIZE) - duk_uint32_t st_count; /* string count for resize load factor checks */ + duk_uint32_t st_count; /* string count for resize load factor checks */ #endif - duk_bool_t st_resizing; /* string table is being resized; avoid recursive resize */ + duk_bool_t st_resizing; /* string table is being resized; avoid recursive resize */ /* String access cache (codepoint offset -> byte offset) for fast string * character looping; 'weak' reference which needs special handling in GC. @@ -678,7 +697,9 @@ DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen); DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_checked(duk_hthread *thr, const duk_uint8_t *str, duk_uint32_t len); #if defined(DUK_USE_LITCACHE_SIZE) -DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_literal_checked(duk_hthread *thr, const duk_uint8_t *str, duk_uint32_t blen); +DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_literal_checked(duk_hthread *thr, + const duk_uint8_t *str, + duk_uint32_t blen); #endif DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_u32(duk_heap *heap, duk_uint32_t val); DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_u32_checked(duk_hthread *thr, duk_uint32_t val); @@ -693,7 +714,9 @@ #endif DUK_INTERNAL_DECL void duk_heap_strcache_string_remove(duk_heap *heap, duk_hstring *h); -DUK_INTERNAL_DECL duk_uint_fast32_t duk_heap_strcache_offset_char2byte(duk_hthread *thr, duk_hstring *h, duk_uint_fast32_t char_offset); +DUK_INTERNAL_DECL duk_uint_fast32_t duk_heap_strcache_offset_char2byte(duk_hthread *thr, + duk_hstring *h, + duk_uint_fast32_t char_offset); #if defined(DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS) DUK_INTERNAL_DECL void *duk_default_alloc_function(void *udata, duk_size_t size); @@ -714,10 +737,10 @@ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL_DECL void duk_heap_run_finalizer(duk_heap *heap, duk_hobject *obj); DUK_INTERNAL_DECL void duk_heap_process_finalize_list(duk_heap *heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL_DECL void duk_heap_mark_and_sweep(duk_heap *heap, duk_small_uint_t flags); DUK_INTERNAL_DECL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len); -#endif /* DUK_HEAP_H_INCLUDED */ +#endif /* DUK_HEAP_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heap_alloc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heap_alloc.c
Changed
@@ -6,7 +6,7 @@ #if defined(DUK_USE_ROM_STRINGS) /* Fixed seed value used with ROM strings. */ -#define DUK__FIXED_HASH_SEED 0xabcd1234 +#define DUK__FIXED_HASH_SEED 0xabcd1234 #endif /* @@ -95,8 +95,8 @@ #if defined(DUK_USE_HSTRING_EXTDATA) && defined(DUK_USE_EXTSTR_FREE) if (DUK_HSTRING_HAS_EXTDATA(h)) { - DUK_DDD(DUK_DDDPRINT("free extstr: hstring %!O, extdata: %p", - h, DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h))); + DUK_DDD( + DUK_DDDPRINT("free extstr: hstring %!O, extdata: %p", h, DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h))); DUK_USE_EXTSTR_FREE(heap->heap_udata, (const void *) DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h)); } #endif @@ -120,7 +120,6 @@ DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(hdr) == DUK_HTYPE_BUFFER); duk_free_hbuffer(heap, (duk_hbuffer *) hdr); } - } /* @@ -150,10 +149,10 @@ count_act++; #endif } - heap->activation_free = NULL; /* needed when called from mark-and-sweep */ + heap->activation_free = NULL; /* needed when called from mark-and-sweep */ return count_act; } -#endif /* DUK_USE_CACHE_ACTIVATION */ +#endif /* DUK_USE_CACHE_ACTIVATION */ #if defined(DUK_USE_CACHE_CATCHER) DUK_LOCAL duk_size_t duk__heap_free_catcher_freelist(duk_heap *heap) { @@ -169,11 +168,11 @@ count_cat++; #endif } - heap->catcher_free = NULL; /* needed when called from mark-and-sweep */ + heap->catcher_free = NULL; /* needed when called from mark-and-sweep */ return count_cat; } -#endif /* DUK_USE_CACHE_CATCHER */ +#endif /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL void duk_heap_free_freelists(duk_heap *heap) { duk_size_t count_act = 0; @@ -189,8 +188,8 @@ DUK_UNREF(count_act); DUK_UNREF(count_cat); - DUK_D(DUK_DPRINT("freed %ld activation freelist entries, %ld catcher freelist entries", - (long) count_act, (long) count_cat)); + DUK_D( + DUK_DPRINT("freed %ld activation freelist entries, %ld catcher freelist entries", (long) count_act, (long) count_cat)); } DUK_LOCAL void duk__free_allocated(duk_heap *heap) { @@ -203,8 +202,7 @@ * because they may happen with finalizer processing. */ - DUK_DDD(DUK_DDDPRINT("FINALFREE (allocated): %!iO", - (duk_heaphdr *) curr)); + DUK_DDD(DUK_DDDPRINT("FINALFREE (allocated): %!iO", (duk_heaphdr *) curr)); next = DUK_HEAPHDR_GET_NEXT(heap, curr); duk_heap_free_heaphdr_raw(heap, curr); curr = next; @@ -218,14 +216,13 @@ curr = heap->finalize_list; while (curr) { - DUK_DDD(DUK_DDDPRINT("FINALFREE (finalize_list): %!iO", - (duk_heaphdr *) curr)); + DUK_DDD(DUK_DDDPRINT("FINALFREE (finalize_list): %!iO", (duk_heaphdr *) curr)); next = DUK_HEAPHDR_GET_NEXT(heap, curr); duk_heap_free_heaphdr_raw(heap, curr); curr = next; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_LOCAL void duk__free_stringtable(duk_heap *heap) { /* strings are only tracked by stringtable */ @@ -243,9 +240,9 @@ DUK_ASSERT(heap != NULL); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* refzero not running -> must be empty */ + DUK_ASSERT(heap->refzero_list == NULL); /* refzero not running -> must be empty */ #endif - DUK_ASSERT(heap->finalize_list == NULL); /* mark-and-sweep last pass */ + DUK_ASSERT(heap->finalize_list == NULL); /* mark-and-sweep last pass */ if (heap->heap_thread == NULL) { /* May happen when heap allocation fails right off. There @@ -268,11 +265,11 @@ DUK_ASSERT(heap->ms_running == 0); DUK_ASSERT(heap->ms_prevent_count == 0); heap->pf_prevent_count = 1; - heap->ms_running = 2; /* Use distinguishable value. */ - heap->ms_prevent_count = 1; /* Bump, because mark-and-sweep assumes it's bumped when ms_running is set. */ + heap->ms_running = 2; /* Use distinguishable value. */ + heap->ms_prevent_count = 1; /* Bump, because mark-and-sweep assumes it's bumped when ms_running is set. */ - curr_limit = 0; /* suppress warning, not used */ - for (round_no = 0; ; round_no++) { + curr_limit = 0; /* suppress warning, not used */ + for (round_no = 0;; round_no++) { curr = heap->heap_allocated; count_all = 0; count_finalized = 0; @@ -287,7 +284,8 @@ if (DUK_HOBJECT_HAS_FINALIZER_FAST(heap, (duk_hobject *) curr)) { if (!DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) curr)) { - DUK_ASSERT(DUK_HEAP_HAS_FINALIZER_NORESCUE(heap)); /* maps to finalizer 2nd argument */ + DUK_ASSERT( + DUK_HEAP_HAS_FINALIZER_NORESCUE(heap)); /* maps to finalizer 2nd argument */ duk_heap_run_finalizer(heap, (duk_hobject *) curr); count_finalized++; } @@ -314,10 +312,13 @@ */ curr_limit = count_all * 2; } else { - curr_limit = (curr_limit * 3) / 4; /* Decrease by 25% every round */ + curr_limit = (curr_limit * 3) / 4; /* Decrease by 25% every round */ } DUK_D(DUK_DPRINT("finalizer round %ld complete, %ld objects, tried to execute %ld finalizers, current limit is %ld", - (long) round_no, (long) count_all, (long) count_finalized, (long) curr_limit)); + (long) round_no, + (long) count_all, + (long) count_finalized, + (long) curr_limit)); if (count_finalized == 0) { DUK_D(DUK_DPRINT("no more finalizable objects, forced finalization finished")); @@ -334,7 +335,7 @@ heap->ms_running = 0; heap->pf_prevent_count = 0; } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL void duk_heap_free(duk_heap *heap) { DUK_D(DUK_DPRINT("free heap: %p", (void *) heap)); @@ -377,7 +378,7 @@ duk_heap_mark_and_sweep(heap, 0); DUK_D(DUK_DPRINT("forced gc #3 in heap destruction (don't run finalizers)")); heap->pf_skip_finalizers = 1; - duk_heap_mark_and_sweep(heap, 0); /* Skip finalizers; queue finalizable objects to heap_allocated. */ + duk_heap_mark_and_sweep(heap, 0); /* Skip finalizers; queue finalizable objects to heap_allocated. */ /* There are never objects in refzero_list at this point, or at any * point beyond a DECREF (even a DECREF_NORZ). Since Duktape 2.1 @@ -386,17 +387,17 @@ * refcount. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) - DUK_ASSERT(heap->finalize_list == NULL); /* Last mark-and-sweep with skip_finalizers. */ + DUK_ASSERT(heap->finalize_list == NULL); /* Last mark-and-sweep with skip_finalizers. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_D(DUK_DPRINT("run finalizers for remaining finalizable objects")); - DUK_HEAP_SET_FINALIZER_NORESCUE(heap); /* Rescue no longer supported. */ + DUK_HEAP_SET_FINALIZER_NORESCUE(heap); /* Rescue no longer supported. */ duk__free_run_finalizers(heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* Note: heap->heap_thread, heap->curr_thread, and heap->heap_object * are on the heap allocated list. @@ -409,7 +410,7 @@ duk__free_allocated(heap); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) @@ -452,7 +453,9 @@ while (h != NULL) { hash = duk_heap_hashstring(heap, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); DUK_DD(DUK_DDPRINT("duk_rom_strings_lookup%d -> hash 0x%08lx, computed 0x%08lx", - (int) i, (unsigned long) DUK_HSTRING_GET_HASH(h), (unsigned long) hash)); + (int) i, + (unsigned long) DUK_HSTRING_GET_HASH(h), + (unsigned long) hash)); DUK_ASSERT(hash == (duk_uint32_t) DUK_HSTRING_GET_HASH(h)); h = (const duk_hstring *) h->hdr.h_next; @@ -461,11 +464,11 @@ #endif return 1; } -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ DUK_LOCAL duk_bool_t duk__init_heap_strings(duk_heap *heap) { duk_bitdecoder_ctx bd_ctx; - duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ + duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ duk_small_uint_t i; duk_memzero(&bd_ctx, sizeof(bd_ctx)); @@ -521,18 +524,16 @@ return 1; - failed: +failed: return 0; } -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ DUK_LOCAL duk_bool_t duk__init_heap_thread(duk_heap *heap) { duk_hthread *thr; DUK_D(DUK_DPRINT("heap init: alloc heap thread")); - thr = duk_hthread_alloc_unchecked(heap, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); + thr = duk_hthread_alloc_unchecked(heap, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); if (thr == NULL) { DUK_D(DUK_DPRINT("failed to alloc heap_thread")); return 0; @@ -540,16 +541,16 @@ thr->state = DUK_HTHREAD_STATE_INACTIVE; #if defined(DUK_USE_ROM_STRINGS) /* No strs pointer. */ -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) thr->strs16 = heap->strs16; #else thr->strs = heap->strs; #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ heap->heap_thread = thr; - DUK_HTHREAD_INCREF(thr, thr); /* Note: first argument not really used */ + DUK_HTHREAD_INCREF(thr, thr); /* Note: first argument not really used */ /* 'thr' is now reachable */ @@ -568,7 +569,8 @@ } #if defined(DUK_USE_DEBUG) -#define DUK__DUMPSZ(t) do { \ +#define DUK__DUMPSZ(t) \ + do { \ DUK_D(DUK_DPRINT("" #t "=%ld", (long) sizeof(t))); \ } while (0) @@ -577,20 +579,20 @@ * enough; the limits will then not be printed accurately but the magnitude * will be correct. */ -#define DUK__DUMPLM_SIGNED_RAW(t,a,b) do { \ - DUK_D(DUK_DPRINT(t "=%ld,%ld=%lf,%lf", \ - (long) (a), (long) (b), \ - (double) (a), (double) (b))); \ +#define DUK__DUMPLM_SIGNED_RAW(t, a, b) \ + do { \ + DUK_D(DUK_DPRINT(t "=%ld,%ld=%lf,%lf", (long) (a), (long) (b), (double) (a), (double) (b))); \ } while (0) -#define DUK__DUMPLM_UNSIGNED_RAW(t,a,b) do { \ - DUK_D(DUK_DPRINT(t "=%lu,%lu=%lf,%lf", \ - (unsigned long) (a), (unsigned long) (b), \ - (double) (a), (double) (b))); \ +#define DUK__DUMPLM_UNSIGNED_RAW(t, a, b) \ + do { \ + DUK_D(DUK_DPRINT(t "=%lu,%lu=%lf,%lf", (unsigned long) (a), (unsigned long) (b), (double) (a), (double) (b))); \ } while (0) -#define DUK__DUMPLM_SIGNED(t) do { \ +#define DUK__DUMPLM_SIGNED(t) \ + do { \ DUK__DUMPLM_SIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \ } while (0) -#define DUK__DUMPLM_UNSIGNED(t) do { \ +#define DUK__DUMPLM_UNSIGNED(t) \ + do { \ DUK__DUMPLM_UNSIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \ } while (0) @@ -663,7 +665,7 @@ DUK__DUMPSZ(duk_tval); /* structs from duk_forwdecl.h */ - DUK__DUMPSZ(duk_jmpbuf); /* just one 'int' for C++ exceptions */ + DUK__DUMPSZ(duk_jmpbuf); /* just one 'int' for C++ exceptions */ DUK__DUMPSZ(duk_heaphdr); DUK__DUMPSZ(duk_heaphdr_string); DUK__DUMPSZ(duk_hstring); @@ -787,7 +789,7 @@ DUK_D(DUK_DPRINT("IEEE double endianness: ???")); #endif } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ DUK_INTERNAL duk_heap *duk_heap_alloc(duk_alloc_function alloc_func, @@ -808,7 +810,7 @@ DUK_ASSERT((DUK_HTYPE_STRING & 0x01U) == 0); DUK_ASSERT((DUK_HTYPE_BUFFER & 0x01U) == 0); - DUK_ASSERT((DUK_HTYPE_OBJECT & 0x01U) == 1); /* DUK_HEAPHDR_IS_OBJECT() relies ont his. */ + DUK_ASSERT((DUK_HTYPE_OBJECT & 0x01U) == 1); /* DUK_HEAPHDR_IS_OBJECT() relies ont his. */ /* * Debug dump type sizes @@ -849,7 +851,7 @@ #endif fatal_func(heap_udata, "sizeof(duk_tval) not 8 or 16, cannot use DUK_USE_EXEC_REGCONST_OPTIMIZE option"); } -#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ /* * Computed values (e.g. INFINITY) @@ -933,18 +935,18 @@ #endif #if defined(DUK_USE_ROM_STRINGS) /* no res->strs */ -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) /* res->strs16 is zeroed and zero decodes to NULL, so no NULL inits. */ #else { duk_small_uint_t i; - for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) { + for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) { res->strsi = NULL; - } + } } #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_DEBUGGER_SUPPORT) res->dbg_read_cb = NULL; res->dbg_write_cb = NULL; @@ -955,7 +957,7 @@ res->dbg_udata = NULL; res->dbg_pause_act = NULL; #endif -#endif /* DUK_USE_EXPLICIT_NULL_INIT */ +#endif /* DUK_USE_EXPLICIT_NULL_INIT */ res->alloc_func = alloc_func; res->realloc_func = realloc_func; @@ -994,17 +996,17 @@ /* XXX: make a common DUK_USE_ option, and allow custom fixed seed? */ DUK_D(DUK_DPRINT("using rom strings, force heap hash_seed to fixed value 0x%08lx", (long) DUK__FIXED_HASH_SEED)); res->hash_seed = (duk_uint32_t) DUK__FIXED_HASH_SEED; -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ res->hash_seed = (duk_uint32_t) (duk_uintptr_t) res; #if !defined(DUK_USE_STRHASH_DENSE) - res->hash_seed ^= 5381; /* Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0 */ + res->hash_seed ^= 5381; /* Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0 */ #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) res->lj.jmpbuf_ptr = NULL; #endif - DUK_ASSERT(res->lj.type == DUK_LJ_TYPE_UNKNOWN); /* zero */ + DUK_ASSERT(res->lj.type == DUK_LJ_TYPE_UNKNOWN); /* zero */ DUK_ASSERT(res->lj.iserror == 0); DUK_TVAL_SET_UNDEFINED(&res->lj.value1); DUK_TVAL_SET_UNDEFINED(&res->lj.value2); @@ -1040,14 +1042,14 @@ #if defined(DUK_USE_EXPLICIT_NULL_INIT) { duk_uint32_t i; - for (i = 0; i < st_initsize; i++) { + for (i = 0; i < st_initsize; i++) { res->strtablei = NULL; - } + } } #else duk_memzero(res->strtable, sizeof(duk_hstring *) * st_initsize); -#endif /* DUK_USE_EXPLICIT_NULL_INIT */ -#endif /* DUK_USE_STRTAB_PTRCOMP */ +#endif /* DUK_USE_EXPLICIT_NULL_INIT */ +#endif /* DUK_USE_STRTAB_PTRCOMP */ /* * Init stringcache @@ -1077,7 +1079,7 @@ } } #endif -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ /* XXX: error handling is incomplete. It would be cleanest if * there was a setjmp catchpoint, so that all init code could @@ -1118,9 +1120,9 @@ #endif DUK_D(DUK_DPRINT("heap init: initialize heap object")); DUK_ASSERT(res->heap_thread != NULL); - res->heap_object = duk_hobject_alloc_unchecked(res, DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT)); + res->heap_object = duk_hobject_alloc_unchecked(res, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT)); if (res->heap_object == NULL) { goto failed; } @@ -1136,8 +1138,8 @@ duk_util_tinyrandom_prepare_seed(res->heap_thread); #else res->rnd_state0 = (duk_uint64_t) duk_time_get_ecmascript_time(res->heap_thread); - DUK_ASSERT(res->rnd_state1 == 0); /* Not filled here, filled in by seed preparation. */ -#if 0 /* Manual test values matching misc/xoroshiro128plus_test.c. */ + DUK_ASSERT(res->rnd_state1 == 0); /* Not filled here, filled in by seed preparation. */ +#if 0 /* Manual test values matching misc/xoroshiro128plus_test.c. */ res->rnd_state0 = DUK_U64_CONSTANT(0xdeadbeef12345678); res->rnd_state1 = DUK_U64_CONSTANT(0xcafed00d12345678); #endif @@ -1189,7 +1191,7 @@ DUK_D(DUK_DPRINT("allocated heap: %p", (void *) res)); return res; - failed: +failed: DUK_D(DUK_DPRINT("heap allocation failed")); if (res != NULL) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heap_finalize.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heap_finalize.c
Changed
@@ -24,14 +24,14 @@ /* Inner function call, error throw. */ duk_eval_string_noresult(thr, - "(function dummy() {\n" - " dummy.prototype = null; /* break reference loop */\n" - " try {\n" - " throw 'fake-finalizer-dummy-error';\n" - " } catch (e) {\n" - " void e;\n" - " }\n" - "})()"); + "(function dummy() {\n" + " dummy.prototype = null; /* break reference loop */\n" + " try {\n" + " throw 'fake-finalizer-dummy-error';\n" + " } catch (e) {\n" + " void e;\n" + " }\n" + "})()"); /* The above creates garbage (e.g. a function instance). Because * the function/prototype reference loop is broken, it gets collected @@ -63,7 +63,7 @@ (void) duk_pcall(thr, 0 /*nargs*/); duk_pop(thr); } -#endif /* DUK_USE_FINALIZER_TORTURE */ +#endif /* DUK_USE_FINALIZER_TORTURE */ /* * Process the finalize_list to completion. @@ -175,12 +175,13 @@ DUK_DD(DUK_DDPRINT("processing finalize_list entry: %p -> %!iO", (void *) curr, curr)); - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* Only objects have finalizers. */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* Only objects have finalizers. */ DUK_ASSERT(!DUK_HEAPHDR_HAS_REACHABLE(curr)); DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(curr)); - DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(curr)); /* All objects on finalize_list will have this flag (except object being finalized right now). */ - DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); /* Queueing code ensures. */ - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY(curr)); /* ROM objects never get freed (or finalized). */ + DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE( + curr)); /* All objects on finalize_list will have this flag (except object being finalized right now). */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); /* Queueing code ensures. */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY(curr)); /* ROM objects never get freed (or finalized). */ #if defined(DUK_USE_ASSERTIONS) DUK_ASSERT(heap->currently_finalizing == NULL); @@ -208,11 +209,11 @@ */ #if defined(DUK_USE_REFERENCE_COUNTING) DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); - had_zero_refcount = (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1); /* Preincremented on finalize_list insert. */ + had_zero_refcount = (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1); /* Preincremented on finalize_list insert. */ #endif DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); - duk_heap_run_finalizer(heap, (duk_hobject *) curr); /* must never longjmp */ + duk_heap_run_finalizer(heap, (duk_hobject *) curr); /* must never longjmp */ DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZED(curr)); /* XXX: assert that object is still in finalize_list * when duk_push_heapptr() allows automatic rescue. @@ -220,12 +221,14 @@ #if defined(DUK_USE_REFERENCE_COUNTING) DUK_DD(DUK_DDPRINT("refcount after finalizer (includes bump): %ld", (long) DUK_HEAPHDR_GET_REFCOUNT(curr))); - if (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1) { /* Only artificial bump in refcount? */ + if (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1) { /* Only artificial bump in refcount? */ #if defined(DUK_USE_DEBUG) if (had_zero_refcount) { - DUK_DD(DUK_DDPRINT("finalized object's refcount is zero -> free immediately (refcount queued)")); + DUK_DD(DUK_DDPRINT( + "finalized object's refcount is zero -> free immediately (refcount queued)")); } else { - DUK_DD(DUK_DDPRINT("finalized object's refcount is zero -> free immediately (mark-and-sweep queued)")); + DUK_DD(DUK_DDPRINT( + "finalized object's refcount is zero -> free immediately (mark-and-sweep queued)")); } #endif queue_back = 0; @@ -275,21 +278,21 @@ * decision. */ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); - DUK_HEAPHDR_PREDEC_REFCOUNT(curr); /* Remove artificial refcount bump. */ + DUK_HEAPHDR_PREDEC_REFCOUNT(curr); /* Remove artificial refcount bump. */ DUK_HEAPHDR_CLEAR_FINALIZABLE(curr); DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, curr); } else { /* No need to remove the refcount bump here. */ - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ DUK_DD(DUK_DDPRINT("refcount finalize after finalizer call: %!O", curr)); duk_hobject_refcount_finalize_norz(heap, (duk_hobject *) curr); duk_free_hobject(heap, (duk_hobject *) curr); DUK_DD(DUK_DDPRINT("freed hobject after finalization: %p", (void *) curr)); } -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ DUK_HEAPHDR_CLEAR_FINALIZABLE(curr); DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, curr); -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_DEBUG) count++; @@ -355,11 +358,11 @@ * caller must ensure that this function is not called if the target is * a Proxy. */ - duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_INT_FINALIZER); /* -> ... obj finalizer */ + duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_INT_FINALIZER); /* -> ... obj finalizer */ duk_dup_m2(thr); duk_push_boolean(thr, DUK_HEAP_HAS_FINALIZER_NORESCUE(thr->heap)); DUK_DDD(DUK_DDDPRINT("calling finalizer")); - duk_call(thr, 2); /* ... obj finalizer obj heapDestruct -> ... obj retval */ + duk_call(thr, 2); /* ... obj finalizer obj heapDestruct -> ... obj retval */ DUK_DDD(DUK_DDDPRINT("finalizer returned successfully")); return 0; @@ -408,7 +411,7 @@ return; } #endif - DUK_HEAPHDR_SET_FINALIZED((duk_heaphdr *) obj); /* ensure never re-entered until rescue cycle complete */ + DUK_HEAPHDR_SET_FINALIZED((duk_heaphdr *) obj); /* ensure never re-entered until rescue cycle complete */ #if defined(DUK_USE_ES6_PROXY) if (DUK_HOBJECT_IS_PROXY(obj)) { @@ -420,26 +423,27 @@ DUK_D(DUK_DPRINT("object is a Proxy, skip finalizer call")); return; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ - duk_push_hobject(thr, obj); /* this also increases refcount by one */ - rc = duk_safe_call(thr, duk__finalize_helper, NULL /*udata*/, 0 /*nargs*/, 1 /*nrets*/); /* -> ... obj retval/error */ - DUK_ASSERT_TOP(thr, entry_top + 2); /* duk_safe_call discipline */ + duk_push_hobject(thr, obj); /* this also increases refcount by one */ + rc = duk_safe_call(thr, duk__finalize_helper, NULL /*udata*/, 0 /*nargs*/, 1 /*nrets*/); /* -> ... obj retval/error */ + DUK_ASSERT_TOP(thr, entry_top + 2); /* duk_safe_call discipline */ if (rc != DUK_EXEC_SUCCESS) { /* Note: we ask for one return value from duk_safe_call to get this * error debugging here. */ DUK_D(DUK_DPRINT("wrapped finalizer call failed for object %p (ignored); error: %!T", - (void *) obj, (duk_tval *) duk_get_tval(thr, -1))); + (void *) obj, + (duk_tval *) duk_get_tval(thr, -1))); } - duk_pop_2(thr); /* -> ... */ + duk_pop_2(thr); /* -> ... */ DUK_ASSERT_TOP(thr, entry_top); } -#else /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ /* nothing */ -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heap_hashstring.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heap_hashstring.c
Changed
@@ -21,9 +21,9 @@ #if defined(DUK_USE_STRHASH_DENSE) /* Constants for duk_hashstring(). */ -#define DUK__STRHASH_SHORTSTRING 4096L -#define DUK__STRHASH_MEDIUMSTRING (256L * 1024L) -#define DUK__STRHASH_BLOCKSIZE 256L +#define DUK__STRHASH_SHORTSTRING 4096L +#define DUK__STRHASH_MEDIUMSTRING (256L * 1024L) +#define DUK__STRHASH_BLOCKSIZE 256L DUK_INTERNAL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len) { duk_uint32_t hash; @@ -80,7 +80,7 @@ #endif return hash; } -#else /* DUK_USE_STRHASH_DENSE */ +#else /* DUK_USE_STRHASH_DENSE */ DUK_INTERNAL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len) { duk_uint32_t hash; duk_size_t step; @@ -98,10 +98,10 @@ * more often in the suffix than in the prefix. */ - hash = heap->hash_seed ^ ((duk_uint32_t) len); /* Bernstein hash init value is normally 5381 */ + hash = heap->hash_seed ^ ((duk_uint32_t) len); /* Bernstein hash init value is normally 5381 */ step = (len >> DUK_USE_STRHASH_SKIP_SHIFT) + 1; for (off = len; off >= step; off -= step) { - DUK_ASSERT(off >= 1); /* off >= step, and step >= 1 */ + DUK_ASSERT(off >= 1); /* off >= step, and step >= 1 */ hash = (hash * 33) + stroff - 1; } @@ -113,4 +113,4 @@ #endif return hash; } -#endif /* DUK_USE_STRHASH_DENSE */ +#endif /* DUK_USE_STRHASH_DENSE */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heap_markandsweep.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heap_markandsweep.c
Changed
@@ -114,7 +114,7 @@ DUK_HBUFOBJ_ASSERT_VALID(b); duk__mark_heaphdr(heap, (duk_heaphdr *) b->buf); duk__mark_heaphdr(heap, (duk_heaphdr *) b->buf_prop); -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ } else if (DUK_HOBJECT_IS_BOUNDFUNC(h)) { duk_hboundfunc *f = (duk_hboundfunc *) (void *) h; DUK_HBOUNDFUNC_ASSERT_VALID(f); @@ -127,7 +127,7 @@ DUK_HPROXY_ASSERT_VALID(p); duk__mark_heaphdr_nonnull(heap, (duk_heaphdr *) p->target); duk__mark_heaphdr_nonnull(heap, (duk_heaphdr *) p->handler); -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ } else if (DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; duk_activation *act; @@ -148,7 +148,7 @@ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) duk__mark_heaphdr(heap, (duk_heaphdr *) act->prev_caller); #endif -#if 0 /* nothing now */ +#if 0 /* nothing now */ for (cat = act->cat; cat != NULL; cat = cat->parent) { } #endif @@ -171,9 +171,8 @@ /* Mark any duk_heaphdr type. Recursion tracking happens only here. */ DUK_LOCAL void duk__mark_heaphdr(duk_heap *heap, duk_heaphdr *h) { - DUK_DDD(DUK_DDDPRINT("duk__mark_heaphdr %p, type %ld", - (void *) h, - (h != NULL ? (long) DUK_HEAPHDR_GET_TYPE(h) : (long) -1))); + DUK_DDD( + DUK_DDDPRINT("duk__mark_heaphdr %p, type %ld", (void *) h, (h != NULL ? (long) DUK_HEAPHDR_GET_TYPE(h) : (long) -1))); /* XXX: add non-null variant? */ if (h == NULL) { @@ -185,7 +184,7 @@ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) if (!DUK_HEAPHDR_HAS_READONLY(h)) { - h->h_assert_refcount++; /* Comparison refcount: bump even if already reachable. */ + h->h_assert_refcount++; /* Comparison refcount: bump even if already reachable. */ } #endif if (DUK_HEAPHDR_HAS_REACHABLE(h)) { @@ -209,7 +208,7 @@ } heap->ms_recursion_depth++; - DUK_ASSERT(heap->ms_recursion_depth != 0); /* Wrap. */ + DUK_ASSERT(heap->ms_recursion_depth != 0); /* Wrap. */ switch (DUK_HEAPHDR_GET_TYPE(h)) { case DUK_HTYPE_STRING: @@ -324,9 +323,7 @@ * of a _Finalizer hidden symbol. */ - if (!DUK_HEAPHDR_HAS_REACHABLE(hdr) && - DUK_HEAPHDR_IS_OBJECT(hdr) && - !DUK_HEAPHDR_HAS_FINALIZED(hdr) && + if (!DUK_HEAPHDR_HAS_REACHABLE(hdr) && DUK_HEAPHDR_IS_OBJECT(hdr) && !DUK_HEAPHDR_HAS_FINALIZED(hdr) && DUK_HOBJECT_HAS_FINALIZER_FAST(heap, (duk_hobject *) hdr)) { /* heaphdr: * - is not reachable @@ -351,8 +348,7 @@ return; } - DUK_DD(DUK_DDPRINT("marked %ld heap objects as finalizable, now mark them reachable", - (long) count_finalizable)); + DUK_DD(DUK_DDPRINT("marked %ld heap objects as finalizable, now mark them reachable", (long) count_finalizable)); hdr = heap->heap_allocated; while (hdr != NULL) { @@ -365,7 +361,7 @@ /* Caller will finish the marking process if we hit a recursion limit. */ } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Mark objects on finalize_list. @@ -396,7 +392,7 @@ } #endif } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Fallback marking handler if recursion limit is reached. @@ -429,9 +425,9 @@ DUK_DDD(DUK_DDDPRINT("found a temp root: %p", (void *) hdr)); DUK_HEAPHDR_CLEAR_TEMPROOT(hdr); - DUK_HEAPHDR_CLEAR_REACHABLE(hdr); /* Done so that duk__mark_heaphdr() works correctly. */ + DUK_HEAPHDR_CLEAR_REACHABLE(hdr); /* Done so that duk__mark_heaphdr() works correctly. */ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) - hdr->h_assert_refcount--; /* Same node visited twice. */ + hdr->h_assert_refcount--; /* Same node visited twice. */ #endif duk__mark_heaphdr_nonnull(heap, hdr); @@ -526,7 +522,7 @@ hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr); } } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Clear (reachable) flags of finalize_list. @@ -549,15 +545,14 @@ while (hdr) { DUK_HEAPHDR_CLEAR_REACHABLE(hdr); #if defined(DUK_USE_ASSERTIONS) - DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(hdr) || \ - (heap->currently_finalizing == hdr)); + DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(hdr) || (heap->currently_finalizing == hdr)); #endif /* DUK_HEAPHDR_FLAG_FINALIZED may be set. */ DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(hdr)); hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr); } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Sweep stringtable. @@ -593,8 +588,7 @@ duk_hstring *next; next = h->hdr.h_next; - if (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h)) - { + if (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h)) { DUK_HEAPHDR_CLEAR_REACHABLE((duk_heaphdr *) h); count_keep++; prev = h; @@ -621,8 +615,8 @@ * should have decreased unreachable string refcounts to zero * (even for cycles). However, pinned strings have a +1 bump. */ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) == - DUK_HSTRING_HAS_PINNED_LITERAL(h) ? 1U : 0U); + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) == DUK_HSTRING_HAS_PINNED_LITERAL(h) ? 1U : + 0U); #endif /* Deal with weak references first. */ @@ -643,10 +637,9 @@ } } - done: +done: #if defined(DUK_USE_DEBUG) - DUK_D(DUK_DPRINT("mark-and-sweep sweep stringtable: %ld freed, %ld kept", - (long) count_free, (long) count_keep)); + DUK_D(DUK_DPRINT("mark-and-sweep sweep stringtable: %ld freed, %ld kept", (long) count_free, (long) count_keep)); #endif *out_count_keep = count_keep; } @@ -656,7 +649,7 @@ */ DUK_LOCAL void duk__sweep_heap(duk_heap *heap, duk_small_uint_t flags, duk_size_t *out_count_keep) { - duk_heaphdr *prev; /* last element that was left in the heap */ + duk_heaphdr *prev; /* last element that was left in the heap */ duk_heaphdr *curr; duk_heaphdr *next; #if defined(DUK_USE_DEBUG) @@ -699,25 +692,28 @@ DUK_DD(DUK_DDPRINT("sweep; reachable, finalizable --> move to finalize_list: %p", (void *) curr)); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_HEAPHDR_PREINC_REFCOUNT(curr); /* Bump refcount so that refzero never occurs when pending a finalizer call. */ + DUK_HEAPHDR_PREINC_REFCOUNT( + curr); /* Bump refcount so that refzero never occurs when pending a finalizer call. */ #endif DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap, curr); #if defined(DUK_USE_DEBUG) count_finalize++; #endif - } - else -#endif /* DUK_USE_FINALIZER_SUPPORT */ + } else +#endif /* DUK_USE_FINALIZER_SUPPORT */ { if (DUK_UNLIKELY(DUK_HEAPHDR_HAS_FINALIZED(curr))) { DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZABLE(curr)); DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); if (flags & DUK_MS_FLAG_POSTPONE_RESCUE) { - DUK_DD(DUK_DDPRINT("sweep; reachable, finalized, but postponing rescue decisions --> keep object (with FINALIZED set): %!iO", curr)); + DUK_DD(DUK_DDPRINT("sweep; reachable, finalized, but postponing rescue decisions " + "--> keep object (with FINALIZED set): %!iO", + curr)); count_keep++; } else { - DUK_DD(DUK_DDPRINT("sweep; reachable, finalized --> rescued after finalization: %p", (void *) curr)); + DUK_DD(DUK_DDPRINT("sweep; reachable, finalized --> rescued after finalization: %p", + (void *) curr)); #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_HEAPHDR_CLEAR_FINALIZED(curr); #endif @@ -786,7 +782,8 @@ #if defined(DUK_USE_DEBUG) if (DUK_HEAPHDR_HAS_FINALIZED(curr)) { - DUK_DD(DUK_DDPRINT("sweep; unreachable, finalized --> finalized object not rescued: %p", (void *) curr)); + DUK_DD(DUK_DDPRINT("sweep; unreachable, finalized --> finalized object not rescued: %p", + (void *) curr)); } else { DUK_DD(DUK_DDPRINT("sweep; not reachable --> free: %p", (void *) curr)); } @@ -820,7 +817,10 @@ #if defined(DUK_USE_DEBUG) DUK_D(DUK_DPRINT("mark-and-sweep sweep objects (non-string): %ld freed, %ld kept, %ld rescued, %ld queued for finalization", - (long) count_free, (long) count_keep, (long) count_rescue, (long) count_finalize)); + (long) count_free, + (long) count_keep, + (long) count_rescue, + (long) count_finalize)); #endif *out_count_keep = count_keep; } @@ -843,7 +843,7 @@ e++; } } -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ /* * Object compaction. @@ -862,7 +862,12 @@ } #if defined(DUK_USE_DEBUG) -DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start, duk_size_t *p_count_check, duk_size_t *p_count_compact, duk_size_t *p_count_bytes_saved) { +DUK_LOCAL void duk__compact_object_list(duk_heap *heap, + duk_hthread *thr, + duk_heaphdr *start, + duk_size_t *p_count_check, + duk_size_t *p_count_compact, + duk_size_t *p_count_bytes_saved) { #else DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start) { #endif @@ -884,9 +889,8 @@ obj = (duk_hobject *) curr; #if defined(DUK_USE_DEBUG) - old_size = DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)); + old_size = + DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)); #endif DUK_DD(DUK_DDPRINT("compact object: %p", (void *) obj)); @@ -895,9 +899,8 @@ duk_safe_call(thr, duk__protected_compact_object, NULL, 1, 0); #if defined(DUK_USE_DEBUG) - new_size = DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)); + new_size = + DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)); #endif #if defined(DUK_USE_DEBUG) @@ -905,7 +908,7 @@ (*p_count_bytes_saved) += (duk_size_t) (old_size - new_size); #endif - next: + next: curr = DUK_HEAPHDR_GET_NEXT(heap, curr); #if defined(DUK_USE_DEBUG) (*p_count_check)++; @@ -937,12 +940,14 @@ #endif #endif #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif #if defined(DUK_USE_DEBUG) DUK_D(DUK_DPRINT("mark-and-sweep compact objects: %ld checked, %ld compaction attempts, %ld bytes saved by compaction", - (long) count_check, (long) count_compact, (long) count_bytes_saved)); + (long) count_check, + (long) count_compact, + (long) count_bytes_saved)); #endif } @@ -989,7 +994,7 @@ DUK_LOCAL void duk__assert_heaphdr_flags(duk_heap *heap) { duk__assert_walk_list(heap, heap->heap_allocated, duk__assert_heaphdr_flags_cb); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif /* XXX: Assertions for finalize_list? */ } @@ -1020,8 +1025,7 @@ /* Cannot really assert much w.r.t. refcounts now. */ DUK_UNREF(heap); - if (DUK_HEAPHDR_GET_REFCOUNT(h) == 0 && - DUK_HEAPHDR_HAS_FINALIZED(h)) { + if (DUK_HEAPHDR_GET_REFCOUNT(h) == 0 && DUK_HEAPHDR_HAS_FINALIZED(h)) { /* An object may be in heap_allocated list with a zero * refcount if it has just been finalized and is waiting * to be collected by the next cycle. @@ -1035,7 +1039,7 @@ * (presumably not reachable because refcount is 0). */ } - DUK_ASSERT_DISABLE(DUK_HEAPHDR_GET_REFCOUNT(h) >= 0); /* Unsigned. */ + DUK_ASSERT_DISABLE(DUK_HEAPHDR_GET_REFCOUNT(h) >= 0); /* Unsigned. */ } DUK_LOCAL void duk__assert_valid_refcounts(duk_heap *heap) { duk__assert_walk_list(heap, heap->heap_allocated, duk__assert_valid_refcounts_cb); @@ -1086,8 +1090,10 @@ count_ok = ((duk_size_t) DUK_HEAPHDR_GET_REFCOUNT(hdr) == expect_refc); if (!count_ok) { DUK_D(DUK_DPRINT("refcount mismatch for: %p: header=%ld counted=%ld --> %!iO", - (void *) hdr, (long) DUK_HEAPHDR_GET_REFCOUNT(hdr), - (long) hdr->h_assert_refcount, hdr)); + (void *) hdr, + (long) DUK_HEAPHDR_GET_REFCOUNT(hdr), + (long) hdr->h_assert_refcount, + hdr)); DUK_ASSERT(0); } } @@ -1108,7 +1114,7 @@ /* XXX: Assert anything for refzero_list? */ duk__assert_walk_strtable(heap, duk__check_assert_refcounts_cb2); } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_LITCACHE_SIZE) DUK_LOCAL void duk__assert_litcache_nulls(duk_heap *heap) { @@ -1124,8 +1130,8 @@ DUK_ASSERT(e->addr == NULL); } } -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_ASSERTIONS */ /* * Stats dump. @@ -1134,49 +1140,64 @@ #if defined(DUK_USE_DEBUG) DUK_LOCAL void duk__dump_stats(duk_heap *heap) { DUK_D(DUK_DPRINT("stats executor: opcodes=%ld, interrupt=%ld, throw=%ld", - (long) heap->stats_exec_opcodes, (long) heap->stats_exec_interrupt, + (long) heap->stats_exec_opcodes, + (long) heap->stats_exec_interrupt, (long) heap->stats_exec_throw)); DUK_D(DUK_DPRINT("stats call: all=%ld, tailcall=%ld, ecmatoecma=%ld", - (long) heap->stats_call_all, (long) heap->stats_call_tailcall, + (long) heap->stats_call_all, + (long) heap->stats_call_tailcall, (long) heap->stats_call_ecmatoecma)); DUK_D(DUK_DPRINT("stats safecall: all=%ld, nothrow=%ld, throw=%ld", - (long) heap->stats_safecall_all, (long) heap->stats_safecall_nothrow, + (long) heap->stats_safecall_all, + (long) heap->stats_safecall_nothrow, (long) heap->stats_safecall_throw)); DUK_D(DUK_DPRINT("stats mark-and-sweep: try_count=%ld, skip_count=%ld, emergency_count=%ld", - (long) heap->stats_ms_try_count, (long) heap->stats_ms_skip_count, + (long) heap->stats_ms_try_count, + (long) heap->stats_ms_skip_count, (long) heap->stats_ms_emergency_count)); DUK_D(DUK_DPRINT("stats stringtable: intern_hit=%ld, intern_miss=%ld, " "resize_check=%ld, resize_grow=%ld, resize_shrink=%ld, " "litcache_hit=%ld, litcache_miss=%ld, litcache_pin=%ld", - (long) heap->stats_strtab_intern_hit, (long) heap->stats_strtab_intern_miss, - (long) heap->stats_strtab_resize_check, (long) heap->stats_strtab_resize_grow, - (long) heap->stats_strtab_resize_shrink, (long) heap->stats_strtab_litcache_hit, - (long) heap->stats_strtab_litcache_miss, (long) heap->stats_strtab_litcache_pin)); + (long) heap->stats_strtab_intern_hit, + (long) heap->stats_strtab_intern_miss, + (long) heap->stats_strtab_resize_check, + (long) heap->stats_strtab_resize_grow, + (long) heap->stats_strtab_resize_shrink, + (long) heap->stats_strtab_litcache_hit, + (long) heap->stats_strtab_litcache_miss, + (long) heap->stats_strtab_litcache_pin)); DUK_D(DUK_DPRINT("stats object: realloc_props=%ld, abandon_array=%ld", - (long) heap->stats_object_realloc_props, (long) heap->stats_object_abandon_array)); + (long) heap->stats_object_realloc_props, + (long) heap->stats_object_abandon_array)); DUK_D(DUK_DPRINT("stats getownpropdesc: count=%ld, hit=%ld, miss=%ld", - (long) heap->stats_getownpropdesc_count, (long) heap->stats_getownpropdesc_hit, + (long) heap->stats_getownpropdesc_count, + (long) heap->stats_getownpropdesc_hit, (long) heap->stats_getownpropdesc_miss)); DUK_D(DUK_DPRINT("stats getpropdesc: count=%ld, hit=%ld, miss=%ld", - (long) heap->stats_getpropdesc_count, (long) heap->stats_getpropdesc_hit, + (long) heap->stats_getpropdesc_count, + (long) heap->stats_getpropdesc_hit, (long) heap->stats_getpropdesc_miss)); DUK_D(DUK_DPRINT("stats getprop: all=%ld, arrayidx=%ld, bufobjidx=%ld, " "bufferidx=%ld, bufferlen=%ld, stringidx=%ld, stringlen=%ld, " "proxy=%ld, arguments=%ld", - (long) heap->stats_getprop_all, (long) heap->stats_getprop_arrayidx, - (long) heap->stats_getprop_bufobjidx, (long) heap->stats_getprop_bufferidx, - (long) heap->stats_getprop_bufferlen, (long) heap->stats_getprop_stringidx, - (long) heap->stats_getprop_stringlen, (long) heap->stats_getprop_proxy, + (long) heap->stats_getprop_all, + (long) heap->stats_getprop_arrayidx, + (long) heap->stats_getprop_bufobjidx, + (long) heap->stats_getprop_bufferidx, + (long) heap->stats_getprop_bufferlen, + (long) heap->stats_getprop_stringidx, + (long) heap->stats_getprop_stringlen, + (long) heap->stats_getprop_proxy, (long) heap->stats_getprop_arguments)); DUK_D(DUK_DPRINT("stats putprop: all=%ld, arrayidx=%ld, bufobjidx=%ld, " "bufferidx=%ld, proxy=%ld", - (long) heap->stats_putprop_all, (long) heap->stats_putprop_arrayidx, - (long) heap->stats_putprop_bufobjidx, (long) heap->stats_putprop_bufferidx, + (long) heap->stats_putprop_all, + (long) heap->stats_putprop_arrayidx, + (long) heap->stats_putprop_bufobjidx, + (long) heap->stats_putprop_bufferidx, (long) heap->stats_putprop_proxy)); - DUK_D(DUK_DPRINT("stats getvar: all=%ld", - (long) heap->stats_getvar_all)); - DUK_D(DUK_DPRINT("stats putvar: all=%ld", - (long) heap->stats_putvar_all)); + DUK_D(DUK_DPRINT("stats getvar: all=%ld", (long) heap->stats_getvar_all)); + DUK_D(DUK_DPRINT("stats putvar: all=%ld", (long) heap->stats_putvar_all)); DUK_D(DUK_DPRINT("stats envrec: delayedcreate=%ld, create=%ld, newenv=%ld, oldenv=%ld, pushclosure=%ld", (long) heap->stats_envrec_delayedcreate, (long) heap->stats_envrec_create, @@ -1184,7 +1205,7 @@ (long) heap->stats_envrec_oldenv, (long) heap->stats_envrec_pushclosure)); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Main mark-and-sweep function. @@ -1223,7 +1244,7 @@ DUK_STATS_INC(heap, stats_ms_skip_count); return; } - DUK_ASSERT(heap->ms_running == 0); /* ms_prevent_count is bumped when ms_running is set */ + DUK_ASSERT(heap->ms_running == 0); /* ms_prevent_count is bumped when ms_running is set */ /* Heap_thread is used during mark-and-sweep for refcount finalization * (it's also used for finalizer execution once mark-and-sweep is @@ -1234,7 +1255,8 @@ DUK_ASSERT(heap->heap_thread->valstack != NULL); DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) starting, requested flags: 0x%08lx, effective flags: 0x%08lx", - (unsigned long) flags, (unsigned long) (flags | heap->ms_base_flags))); + (unsigned long) flags, + (unsigned long) (flags | heap->ms_base_flags))); flags |= heap->ms_base_flags; #if defined(DUK_USE_FINALIZER_SUPPORT) @@ -1260,8 +1282,8 @@ * finalizer may trigger a mark-and-sweep. */ duk__assert_valid_refcounts(heap); -#endif /* DUK_USE_REFERENCE_COUNTING */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_ASSERTIONS */ /* * Begin @@ -1305,17 +1327,17 @@ #if defined(DUK_USE_LITCACHE_SIZE) duk__wipe_litcache(heap); #endif - duk__mark_roots_heap(heap); /* Mark main reachability roots. */ + duk__mark_roots_heap(heap); /* Mark main reachability roots. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif - duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ + duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ #if defined(DUK_USE_FINALIZER_SUPPORT) - duk__mark_finalizable(heap); /* Mark finalizable as reachability roots. */ - duk__mark_finalize_list(heap); /* Mark finalizer work list as reachability roots. */ + duk__mark_finalizable(heap); /* Mark finalizable as reachability roots. */ + duk__mark_finalize_list(heap); /* Mark finalizer work list as reachability roots. */ #endif - duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ + duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ /* * Sweep garbage and remove marking flags, and move objects with @@ -1342,7 +1364,7 @@ duk__check_assert_refcounts(heap); #endif #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) duk__clear_finalize_list_flags(heap); @@ -1369,8 +1391,7 @@ * interfering with error state. */ - if ((flags & DUK_MS_FLAG_EMERGENCY) && - !(flags & DUK_MS_FLAG_NO_OBJECT_COMPACTION)) { + if ((flags & DUK_MS_FLAG_EMERGENCY) && !(flags & DUK_MS_FLAG_NO_OBJECT_COMPACTION)) { if (heap->lj.type != DUK_LJ_TYPE_UNKNOWN) { DUK_D(DUK_DPRINT("lj.type (%ld) not DUK_LJ_TYPE_UNKNOWN, skip object compaction", (long) heap->lj.type)); } else { @@ -1403,7 +1424,7 @@ DUK_ASSERT(heap->ms_running == 1); heap->ms_prevent_count = 0; heap->ms_running = 0; - heap->creating_error = entry_creating_error; /* for nested error handling, see GH-2278 */ + heap->creating_error = entry_creating_error; /* for nested error handling, see GH-2278 */ /* * Assertions after @@ -1420,11 +1441,11 @@ * finalizer may trigger a mark-and-sweep. */ duk__assert_valid_refcounts(heap); -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_LITCACHE_SIZE) duk__assert_litcache_nulls(heap); -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_ASSERTIONS */ /* * Reset trigger counter @@ -1432,14 +1453,15 @@ #if defined(DUK_USE_VOLUNTARY_GC) tmp = (count_keep_obj + count_keep_str) / 256; - heap->ms_trigger_counter = (duk_int_t) ( - (tmp * DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT) + - DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD); + heap->ms_trigger_counter = (duk_int_t) ((tmp * DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT) + DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD); DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) finished: %ld objects kept, %ld strings kept, trigger reset to %ld", - (long) count_keep_obj, (long) count_keep_str, (long) heap->ms_trigger_counter)); + (long) count_keep_obj, + (long) count_keep_str, + (long) heap->ms_trigger_counter)); #else DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) finished: %ld objects kept, %ld strings kept, no voluntary trigger", - (long) count_keep_obj, (long) count_keep_str)); + (long) count_keep_obj, + (long) count_keep_str)); #endif /* @@ -1482,5 +1504,5 @@ * is inside the target. */ duk_heap_process_finalize_list(heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heap_memory.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heap_memory.c
Changed
@@ -58,7 +58,8 @@ res = heap->alloc_func(heap->heap_udata, size); if (res != NULL) { DUK_D(DUK_DPRINT("duk_heap_mem_alloc() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) size)); + (long) (i + 1), + (long) size)); return res; } } @@ -102,7 +103,7 @@ return res; } - slowpath: +slowpath: if (size == 0) { DUK_D(DUK_DPRINT("first alloc attempt returned NULL for zero size alloc, use slow path to deal with it")); @@ -177,13 +178,7 @@ /* ptr may be NULL */ DUK_ASSERT_DISABLE(newsize >= 0); - /* Newsize was 0 and realloc() returned NULL, this has the semantics - * of free(oldptr), i.e. memory was successfully freed. - */ - if (newsize == 0) { - DUK_D(DUK_DPRINT("zero size realloc in slow path, return NULL")); - return NULL; - } + /* Unlike for malloc(), zero size NULL result check happens at the call site. */ DUK_D(DUK_DPRINT("first realloc attempt failed, attempt to gc and retry")); @@ -214,11 +209,11 @@ duk_heap_mark_and_sweep(heap, flags); - DUK_ASSERT(newsize > 0); res = heap->realloc_func(heap->heap_udata, ptr, newsize); - if (res || newsize == 0) { + if (res != NULL || newsize == 0) { DUK_D(DUK_DPRINT("duk_heap_mem_realloc() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) newsize)); + (long) (i + 1), + (long) newsize)); return res; } } @@ -238,7 +233,7 @@ #if defined(DUK_USE_VOLUNTARY_GC) /* Voluntary periodic GC (if enabled). */ if (DUK_UNLIKELY(--(heap)->ms_trigger_counter < 0)) { - goto slowpath; + goto gc_retry; } #endif @@ -250,22 +245,22 @@ DUK_DDD(DUK_DDDPRINT("gc torture enabled, pretend that first realloc attempt fails")); res = NULL; DUK_UNREF(res); - goto slowpath; + goto gc_retry; } #endif res = heap->realloc_func(heap->heap_udata, ptr, newsize); - if (DUK_LIKELY(res != NULL)) { + if (DUK_LIKELY(res != NULL) || newsize == 0) { + if (res != NULL && newsize == 0) { + DUK_DD(DUK_DDPRINT("first realloc attempt returned NULL for zero size realloc, accept and return NULL")); + } return res; - } - - slowpath: - - if (newsize == 0) { - DUK_D(DUK_DPRINT("first realloc attempt returned NULL for zero size realloc, use slow path to deal with it")); } else { - DUK_D(DUK_DPRINT("first realloc attempt failed, attempt to gc and retry")); + goto gc_retry; } + /* Never here. */ + +gc_retry: return duk__heap_mem_realloc_slowpath(heap, ptr, newsize); } @@ -276,7 +271,10 @@ */ /* Slow path: voluntary GC triggered, first realloc attempt failed, or zero size. */ -DUK_LOCAL DUK_NOINLINE_PERF DUK_COLD void *duk__heap_mem_realloc_indirect_slowpath(duk_heap *heap, duk_mem_getptr cb, void *ud, duk_size_t newsize) { +DUK_LOCAL DUK_NOINLINE_PERF DUK_COLD void *duk__heap_mem_realloc_indirect_slowpath(duk_heap *heap, + duk_mem_getptr cb, + void *ud, + duk_size_t newsize) { void *res; duk_small_int_t i; @@ -284,10 +282,7 @@ DUK_ASSERT(heap->realloc_func != NULL); DUK_ASSERT_DISABLE(newsize >= 0); - if (newsize == 0) { - DUK_D(DUK_DPRINT("zero size indirect realloc in slow path, return NULL")); - return NULL; - } + /* Unlike for malloc(), zero size NULL result check happens at the call site. */ DUK_D(DUK_DPRINT("first indirect realloc attempt failed, attempt to gc and retry")); @@ -329,7 +324,8 @@ ptr_post = cb(heap, ud); if (ptr_pre != ptr_post) { DUK_DD(DUK_DDPRINT("realloc base pointer changed by mark-and-sweep: %p -> %p", - (void *) ptr_pre, (void *) ptr_post)); + (void *) ptr_pre, + (void *) ptr_post)); } #endif @@ -337,11 +333,11 @@ * The pointer being reallocated may change after every mark-and-sweep. */ - DUK_ASSERT(newsize > 0); res = heap->realloc_func(heap->heap_udata, cb(heap, ud), newsize); - if (res || newsize == 0) { + if (res != NULL || newsize == 0) { DUK_D(DUK_DPRINT("duk_heap_mem_realloc_indirect() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) newsize)); + (long) (i + 1), + (long) newsize)); return res; } } @@ -350,7 +346,10 @@ return NULL; } -DUK_INTERNAL DUK_INLINE_PERF DUK_HOT void *duk_heap_mem_realloc_indirect(duk_heap *heap, duk_mem_getptr cb, void *ud, duk_size_t newsize) { +DUK_INTERNAL DUK_INLINE_PERF DUK_HOT void *duk_heap_mem_realloc_indirect(duk_heap *heap, + duk_mem_getptr cb, + void *ud, + duk_size_t newsize) { void *res; DUK_ASSERT(heap != NULL); @@ -360,7 +359,7 @@ #if defined(DUK_USE_VOLUNTARY_GC) /* Voluntary periodic GC (if enabled). */ if (DUK_UNLIKELY(--(heap)->ms_trigger_counter < 0)) { - goto slowpath; + goto gc_retry; } #endif @@ -372,22 +371,23 @@ DUK_DDD(DUK_DDDPRINT("gc torture enabled, pretend that first indirect realloc attempt fails")); res = NULL; DUK_UNREF(res); - goto slowpath; + goto gc_retry; } #endif res = heap->realloc_func(heap->heap_udata, cb(heap, ud), newsize); - if (DUK_LIKELY(res != NULL)) { + if (DUK_LIKELY(res != NULL) || newsize == 0) { + if (res != NULL && newsize == 0) { + DUK_DD(DUK_DDPRINT( + "first indirect realloc attempt returned NULL for zero size realloc, accept and return NULL")); + } return res; - } - - slowpath: - - if (newsize == 0) { - DUK_D(DUK_DPRINT("first indirect realloc attempt returned NULL for zero size realloc, use slow path to deal with it")); } else { - DUK_D(DUK_DPRINT("first indirect realloc attempt failed, attempt to gc and retry")); + goto gc_retry; } + /* Never here. */ + +gc_retry: return duk__heap_mem_realloc_indirect_slowpath(heap, cb, ud, newsize); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heap_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heap_misc.c
Changed
@@ -64,7 +64,7 @@ ; } } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL void duk_heap_insert_into_finalize_list(duk_heap *heap, duk_heaphdr *hdr) { @@ -83,7 +83,7 @@ DUK_HEAPHDR_ASSERT_LINKS(heap, root); heap->finalize_list = hdr; } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL void duk_heap_remove_from_finalize_list(duk_heap *heap, duk_heaphdr *hdr) { @@ -117,7 +117,7 @@ } else { DUK_ASSERT(hdr != heap->finalize_list); for (;;) { - DUK_ASSERT(curr != NULL); /* Caller responsibility. */ + DUK_ASSERT(curr != NULL); /* Caller responsibility. */ next = DUK_HEAPHDR_GET_NEXT(heap, curr); if (next == hdr) { @@ -129,7 +129,7 @@ } #endif } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL duk_bool_t duk_heap_in_heap_allocated(duk_heap *heap, duk_heaphdr *ptr) { @@ -143,7 +143,7 @@ } return 0; } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ #if defined(DUK_USE_INTERRUPT_COUNTER) DUK_INTERNAL void duk_heap_switch_thread(duk_heap *heap, duk_hthread *new_thr) { @@ -176,9 +176,9 @@ DUK_DD(DUK_DDPRINT("switch thread, new thread is NULL, no interrupt counter changes")); } - heap->curr_thread = new_thr; /* may be NULL */ + heap->curr_thread = new_thr; /* may be NULL */ } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL void duk_heap_assert_valid(duk_heap *heap) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heap_refcount.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heap_refcount.c
Changed
@@ -160,7 +160,7 @@ } else if (DUK_HOBJECT_IS_OBJENV(h)) { duk_hobjenv *e = (duk_hobjenv *) h; DUK_HOBJENV_ASSERT_VALID(e); - DUK_ASSERT(e->target != NULL); /* Required for object environments. */ + DUK_ASSERT(e->target != NULL); /* Required for object environments. */ DUK_HOBJECT_DECREF_NORZ(thr, e->target); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) } else if (DUK_HOBJECT_IS_BUFOBJ(h)) { @@ -168,7 +168,7 @@ DUK_HBUFOBJ_ASSERT_VALID(b); DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, (duk_hbuffer *) b->buf); DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) b->buf_prop); -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ } else if (DUK_HOBJECT_IS_BOUNDFUNC(h)) { duk_hboundfunc *f = (duk_hboundfunc *) (void *) h; DUK_HBOUNDFUNC_ASSERT_VALID(f); @@ -181,7 +181,7 @@ DUK_HPROXY_ASSERT_VALID(p); DUK_HOBJECT_DECREF_NORZ(thr, p->target); DUK_HOBJECT_DECREF_NORZ(thr, p->handler); -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ } else if (DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; duk_activation *act; @@ -202,13 +202,12 @@ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) act->prev_caller); #endif -#if 0 /* nothing now */ +#if 0 /* nothing now */ for (cat = act->cat; cat != NULL; cat = cat->parent) { } #endif } - for (i = 0; i < DUK_NUM_BUILTINS; i++) { DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) t->builtinsi); } @@ -293,7 +292,7 @@ curr = heap->refzero_list; DUK_ASSERT(curr != NULL); - DUK_ASSERT(DUK_HEAPHDR_GET_PREV(heap, curr) == NULL); /* We're called on initial insert only. */ + DUK_ASSERT(DUK_HEAPHDR_GET_PREV(heap, curr) == NULL); /* We're called on initial insert only. */ /* curr->next is GARBAGE. */ do { @@ -306,7 +305,7 @@ #endif DUK_ASSERT(curr != NULL); - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ /* FINALIZED may be set; don't care about flags here. */ /* Refcount finalize 'curr'. Refzero_list must be non-NULL @@ -316,11 +315,10 @@ duk_hobject_refcount_finalize_norz(heap, (duk_hobject *) curr); prev = DUK_HEAPHDR_GET_PREV(heap, curr); - DUK_ASSERT((prev == NULL && heap->refzero_list == curr) || \ - (prev != NULL && heap->refzero_list != curr)); + DUK_ASSERT((prev == NULL && heap->refzero_list == curr) || (prev != NULL && heap->refzero_list != curr)); /* prev->next is intentionally not updated and is garbage. */ - duk_free_hobject(heap, (duk_hobject *) curr); /* Invalidates 'curr'. */ + duk_free_hobject(heap, (duk_hobject *) curr); /* Invalidates 'curr'. */ curr = prev; } while (curr != NULL); @@ -396,7 +394,7 @@ return; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* No need to finalize, free object via refzero_list. */ @@ -440,7 +438,7 @@ DUK_INTERNAL DUK_ALWAYS_INLINE void duk_refzero_check_fast(duk_hthread *thr) { DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ + DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ if (DUK_UNLIKELY(thr->heap->finalize_list != NULL)) { duk_heap_process_finalize_list(thr->heap); @@ -450,13 +448,13 @@ DUK_INTERNAL void duk_refzero_check_slow(duk_hthread *thr) { DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ + DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ if (DUK_UNLIKELY(thr->heap->finalize_list != NULL)) { duk_heap_process_finalize_list(thr->heap); } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Refzero processing for duk_hstring. @@ -516,7 +514,8 @@ * The suppress condition is important to performance. */ -#define DUK__RZ_SUPPRESS_ASSERT1() do { \ +#define DUK__RZ_SUPPRESS_ASSERT1() \ + do { \ DUK_ASSERT(thr != NULL); \ DUK_ASSERT(thr->heap != NULL); \ /* When mark-and-sweep runs, heap_thread must exist. */ \ @@ -538,32 +537,41 @@ } while (0) #if defined(DUK_USE_DEBUGGER_SUPPORT) -#define DUK__RZ_SUPPRESS_ASSERT2() do { \ +#define DUK__RZ_SUPPRESS_ASSERT2() \ + do { \ /* When debugger is paused, ms_running is set. */ \ DUK_ASSERT(!DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || thr->heap->ms_running != 0); \ } while (0) -#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) +#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) #else -#define DUK__RZ_SUPPRESS_ASSERT2() do { } while (0) -#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#define DUK__RZ_SUPPRESS_ASSERT2() \ + do { \ + } while (0) +#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) +#endif /* DUK_USE_DEBUGGER_SUPPORT */ -#define DUK__RZ_SUPPRESS_CHECK() do { \ +#define DUK__RZ_SUPPRESS_CHECK() \ + do { \ DUK__RZ_SUPPRESS_ASSERT1(); \ DUK__RZ_SUPPRESS_ASSERT2(); \ if (DUK_UNLIKELY(DUK__RZ_SUPPRESS_COND())) { \ - DUK_DDD(DUK_DDDPRINT("refzero handling suppressed (not even queued) when mark-and-sweep running, object: %p", (void *) h)); \ + DUK_DDD( \ + DUK_DDDPRINT("refzero handling suppressed (not even queued) when mark-and-sweep running, object: %p", \ + (void *) h)); \ return; \ } \ } while (0) -#define DUK__RZ_STRING() do { \ +#define DUK__RZ_STRING() \ + do { \ duk__refcount_refzero_hstring(heap, (duk_hstring *) h); \ } while (0) -#define DUK__RZ_BUFFER() do { \ +#define DUK__RZ_BUFFER() \ + do { \ duk__refcount_refzero_hbuffer(heap, (duk_hbuffer *) h); \ } while (0) -#define DUK__RZ_OBJECT() do { \ +#define DUK__RZ_OBJECT() \ + do { \ duk__refcount_refzero_hobject(heap, (duk_hobject *) h, skip_free_pending); \ } while (0) @@ -684,7 +692,7 @@ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(h)); DUK_ASSERT_DISABLE(h->h_refcount >= 0); DUK_HEAPHDR_PREINC_REFCOUNT(h); - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(h) != 0); /* No wrapping. */ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(h) != 0); /* No wrapping. */ } } @@ -727,9 +735,10 @@ #endif } } -#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ +#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ -#define DUK__DECREF_ASSERTS() do { \ +#define DUK__DECREF_ASSERTS() \ + do { \ DUK_ASSERT(thr != NULL); \ DUK_ASSERT(thr->heap != NULL); \ DUK_ASSERT(h != NULL); \ @@ -737,14 +746,16 @@ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) >= 1); \ } while (0) #if defined(DUK_USE_ROM_OBJECTS) -#define DUK__INCREF_SHARED() do { \ +#define DUK__INCREF_SHARED() \ + do { \ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) h)) { \ return; \ } \ DUK_HEAPHDR_PREINC_REFCOUNT((duk_heaphdr *) h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ } while (0) -#define DUK__DECREF_SHARED() do { \ +#define DUK__DECREF_SHARED() \ + do { \ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) h)) { \ return; \ } \ @@ -753,11 +764,13 @@ } \ } while (0) #else -#define DUK__INCREF_SHARED() do { \ +#define DUK__INCREF_SHARED() \ + do { \ DUK_HEAPHDR_PREINC_REFCOUNT((duk_heaphdr *) h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ } while (0) -#define DUK__DECREF_SHARED() do { \ +#define DUK__DECREF_SHARED() \ + do { \ if (DUK_HEAPHDR_PREDEC_REFCOUNT((duk_heaphdr *) h) != 0) { \ return; \ } \ @@ -791,9 +804,9 @@ DUK__DECREF_SHARED(); duk_heaphdr_refzero_norz(thr, h); } -#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ +#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ -#if 0 /* Not needed. */ +#if 0 /* Not needed. */ DUK_INTERNAL void duk_hstring_decref(duk_hthread *thr, duk_hstring *h) { DUK__DECREF_ASSERTS(); DUK__DECREF_SHARED(); @@ -826,8 +839,8 @@ } #endif -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ /* no refcounting */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heap_stringcache.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heap_stringcache.c
Changed
@@ -22,8 +22,8 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; if (c->h == h) { - DUK_DD(DUK_DDPRINT("deleting weak strcache reference to hstring %p from heap %p", - (void *) h, (void *) heap)); + DUK_DD( + DUK_DDPRINT("deleting weak strcache reference to hstring %p from heap %p", (void *) h, (void *) heap)); c->h = NULL; /* XXX: the string shouldn't appear twice, but we now loop to the @@ -133,7 +133,8 @@ */ DUK_DDD(DUK_DDDPRINT("non-ascii string %p, char_offset=%ld, clen=%ld, blen=%ld", - (void *) h, (long) char_offset, + (void *) h, + (long) char_offset, (long) DUK_HSTRING_GET_CHARLEN(h), (long) DUK_HSTRING_GET_BYTELEN(h))); @@ -147,7 +148,10 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; DUK_DDD(DUK_DDDPRINT(" %ld -> h=%p, cidx=%ld, bidx=%ld", - (long) i, (void *) c->h, (long) c->cidx, (long) c->bidx)); + (long) i, + (void *) c->h, + (long) c->cidx, + (long) c->bidx)); } #endif @@ -171,7 +175,8 @@ DUK_ASSERT(DUK_HSTRING_GET_CHARLEN(h) >= char_offset); dist_start = char_offset; dist_end = char_length - char_offset; - dist_sce = 0; DUK_UNREF(dist_sce); /* initialize for debug prints, needed if sce==NULL */ + dist_sce = 0; + DUK_UNREF(dist_sce); /* initialize for debug prints, needed if sce==NULL */ p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h); p_end = (const duk_uint8_t *) (p_start + DUK_HSTRING_GET_BYTELEN(h)); @@ -184,14 +189,15 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan forwards from sce", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_forwards(p_start + sce->bidx, - p_end, - dist_sce); + p_found = duk__scan_forwards(p_start + sce->bidx, p_end, dist_sce); goto scan_done; } } else { @@ -200,14 +206,15 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan backwards from sce", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_backwards(p_start + sce->bidx, - p_start, - dist_sce); + p_found = duk__scan_backwards(p_start + sce->bidx, p_start, dist_sce); goto scan_done; } } @@ -219,29 +226,31 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan forwards from string start", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_forwards(p_start, - p_end, - dist_start); + p_found = duk__scan_forwards(p_start, p_end, dist_start); } else { DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan backwards from string end", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_backwards(p_end, - p_start, - dist_end); + p_found = duk__scan_backwards(p_end, p_start, dist_end); } - scan_done: +scan_done: if (DUK_UNLIKELY(p_found == NULL)) { /* Scan error: this shouldn't normally happen; it could happen if @@ -252,11 +261,10 @@ } DUK_ASSERT(p_found >= p_start); - DUK_ASSERT(p_found <= p_end); /* may be equal */ + DUK_ASSERT(p_found <= p_end); /* may be equal */ byte_offset = (duk_uint32_t) (p_found - p_start); - DUK_DDD(DUK_DDDPRINT("-> string %p, cidx %ld -> bidx %ld", - (void *) h, (long) char_offset, (long) byte_offset)); + DUK_DDD(DUK_DDDPRINT("-> string %p, cidx %ld -> bidx %ld", (void *) h, (long) char_offset, (long) byte_offset)); /* * Update cache entry (allocating if necessary), and move the @@ -266,7 +274,7 @@ if (use_cache) { /* update entry, allocating if necessary */ if (!sce) { - sce = heap->strcache + DUK_HEAP_STRCACHE_SIZE - 1; /* take last entry */ + sce = heap->strcache + DUK_HEAP_STRCACHE_SIZE - 1; /* take last entry */ sce->h = h; } DUK_ASSERT(sce != NULL); @@ -296,14 +304,17 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; DUK_DDD(DUK_DDDPRINT(" %ld -> h=%p, cidx=%ld, bidx=%ld", - (long) i, (void *) c->h, (long) c->cidx, (long) c->bidx)); + (long) i, + (void *) c->h, + (long) c->cidx, + (long) c->bidx)); } #endif } return byte_offset; - scan_error: +scan_error: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heap_stringtable.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heap_stringtable.c
Changed
@@ -13,16 +13,16 @@ #endif #if defined(DUK_USE_STRTAB_PTRCOMP) -#define DUK__HEAPPTR_ENC16(heap,ptr) DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (ptr)) -#define DUK__HEAPPTR_DEC16(heap,val) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (val)) -#define DUK__GET_STRTABLE(heap) ((heap)->strtable16) +#define DUK__HEAPPTR_ENC16(heap, ptr) DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (ptr)) +#define DUK__HEAPPTR_DEC16(heap, val) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (val)) +#define DUK__GET_STRTABLE(heap) ((heap)->strtable16) #else -#define DUK__HEAPPTR_ENC16(heap,ptr) (ptr) -#define DUK__HEAPPTR_DEC16(heap,val) (val) -#define DUK__GET_STRTABLE(heap) ((heap)->strtable) +#define DUK__HEAPPTR_ENC16(heap, ptr) (ptr) +#define DUK__HEAPPTR_DEC16(heap, val) (val) +#define DUK__GET_STRTABLE(heap) ((heap)->strtable) #endif -#define DUK__STRTAB_U32_MAX_STRLEN 10 /* 4'294'967'295 */ +#define DUK__STRTAB_U32_MAX_STRLEN 10 /* 4'294'967'295 */ /* * Debug dump stringtable. @@ -41,7 +41,7 @@ duk_size_t count_chain; duk_size_t count_chain_min = DUK_SIZE_MAX; duk_size_t count_chain_max = 0; - duk_size_t count_len8; /* chain lengths from 0 to 7 */ + duk_size_t count_len8; /* chain lengths from 0 to 7 */ if (heap == NULL) { DUK_D(DUK_DPRINT("string table, heap=NULL")); @@ -72,15 +72,21 @@ DUK_D(DUK_DPRINT("string table, strtab=%p, count=%lu, chain min=%lu max=%lu avg=%lf: " "counts: %lu %lu %lu %lu %lu %lu %lu %lu ...", - (void *) heap->strtable, (unsigned long) count_total, - (unsigned long) count_chain_min, (unsigned long) count_chain_max, + (void *) heap->strtable, + (unsigned long) count_total, + (unsigned long) count_chain_min, + (unsigned long) count_chain_max, (double) count_total / (double) heap->st_size, - (unsigned long) count_len0, (unsigned long) count_len1, - (unsigned long) count_len2, (unsigned long) count_len3, - (unsigned long) count_len4, (unsigned long) count_len5, - (unsigned long) count_len6, (unsigned long) count_len7)); + (unsigned long) count_len0, + (unsigned long) count_len1, + (unsigned long) count_len2, + (unsigned long) count_len3, + (unsigned long) count_len4, + (unsigned long) count_len5, + (unsigned long) count_len6, + (unsigned long) count_len7)); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Assertion helper to ensure strtable is populated correctly. @@ -121,7 +127,7 @@ DUK_ASSERT(count == (duk_size_t) heap->st_count); #endif } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Allocate and initialize a duk_hstring. @@ -172,16 +178,16 @@ #endif DUK_HEAPHDR_SET_TYPE_AND_FLAGS(&res->hdr, DUK_HTYPE_STRING, DUK_HSTRING_FLAG_EXTDATA); - DUK_ASSERT(extdatablen == 0); /* Application responsibility. */ + DUK_ASSERT(extdatablen == 0); /* Application responsibility. */ data = extdata; ((duk_hstring_external *) res)->extdata = extdata; } else -#endif /* DUK_USE_HSTRING_EXTDATA && DUK_USE_EXTSTR_INTERN_CHECK */ +#endif /* DUK_USE_HSTRING_EXTDATA && DUK_USE_EXTSTR_INTERN_CHECK */ { duk_uint8_t *data_tmp; /* NUL terminate for convenient C access */ - DUK_ASSERT(sizeof(duk_hstring) + blen + 1 > blen); /* No wrap, limits ensure. */ + DUK_ASSERT(sizeof(duk_hstring) + blen + 1 > blen); /* No wrap, limits ensure. */ res = (duk_hstring *) DUK_ALLOC(heap, sizeof(duk_hstring) + blen + 1); if (DUK_UNLIKELY(res == NULL)) { goto alloc_error; @@ -240,7 +246,7 @@ #if defined(DUK_USE_HSTRING_LAZY_CLEN) /* Charlen initialized to 0, updated on-the-fly. */ #else - duk_hstring_init_charlen(res); /* Also sets ASCII flag. */ + duk_hstring_init_charlen(res); /* Also sets ASCII flag. */ #endif } @@ -253,7 +259,7 @@ DUK_ASSERT(res != NULL); return res; - alloc_error: +alloc_error: return NULL; } @@ -282,13 +288,13 @@ DUK_ASSERT(heap != NULL); DUK_ASSERT(heap->st_resizing == 1); DUK_ASSERT(heap->st_size >= 2); - DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ + DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ DUK_ASSERT(DUK__GET_STRTABLE(heap) != NULL); DUK_STATS_INC(heap, stats_strtab_resize_grow); new_st_size = heap->st_size << 1U; - DUK_ASSERT(new_st_size > heap->st_size); /* No overflow. */ + DUK_ASSERT(new_st_size > heap->st_size); /* No overflow. */ /* Reallocate the strtable first and then work in-place to rehash * strings. We don't need an indirect allocation here: even if GC @@ -372,7 +378,7 @@ duk__strtable_assert_checks(heap); #endif } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Shrink strtable allocation in-place. @@ -400,7 +406,7 @@ DUK_ASSERT(heap != NULL); DUK_ASSERT(heap->st_resizing == 1); DUK_ASSERT(heap->st_size >= 2); - DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ + DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ DUK_ASSERT(DUK__GET_STRTABLE(heap) != NULL); DUK_STATS_INC(heap, stats_strtab_resize_shrink); @@ -458,7 +464,7 @@ duk__strtable_assert_checks(heap); #endif } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Grow/shrink check. @@ -466,7 +472,7 @@ #if defined(DUK__STRTAB_RESIZE_CHECK) DUK_LOCAL DUK_COLD DUK_NOINLINE void duk__strtable_resize_check(duk_heap *heap) { - duk_uint32_t load_factor; /* fixed point */ + duk_uint32_t load_factor; /* fixed point */ DUK_ASSERT(heap != NULL); #if defined(DUK_USE_STRTAB_PTRCOMP) @@ -490,7 +496,8 @@ load_factor = heap->st_count / (heap->st_size >> 4U); DUK_DD(DUK_DDPRINT("resize check string table: size=%lu, count=%lu, load_factor=%lu (fixed point .4; float %lf)", - (unsigned long) heap->st_size, (unsigned long) heap->st_count, + (unsigned long) heap->st_size, + (unsigned long) heap->st_count, (unsigned long) load_factor, (double) heap->st_count / (double) heap->st_size)); @@ -498,7 +505,9 @@ if (heap->st_size >= DUK_USE_STRTAB_MAXSIZE) { DUK_DD(DUK_DDPRINT("want to grow strtable (based on load factor) but already maximum size")); } else { - DUK_D(DUK_DPRINT("grow string table: %lu -> %lu", (unsigned long) heap->st_size, (unsigned long) heap->st_size * 2)); + DUK_D(DUK_DPRINT("grow string table: %lu -> %lu", + (unsigned long) heap->st_size, + (unsigned long) heap->st_size * 2)); #if defined(DUK_USE_DEBUG) duk_heap_strtable_dump(heap); #endif @@ -508,7 +517,9 @@ if (heap->st_size <= DUK_USE_STRTAB_MINSIZE) { DUK_DD(DUK_DDPRINT("want to shrink strtable (based on load factor) but already minimum size")); } else { - DUK_D(DUK_DPRINT("shrink string table: %lu -> %lu", (unsigned long) heap->st_size, (unsigned long) heap->st_size / 2)); + DUK_D(DUK_DPRINT("shrink string table: %lu -> %lu", + (unsigned long) heap->st_size, + (unsigned long) heap->st_size / 2)); #if defined(DUK_USE_DEBUG) duk_heap_strtable_dump(heap); #endif @@ -520,7 +531,7 @@ heap->st_resizing = 0; } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Torture grow/shrink: unconditionally grow and shrink back. @@ -544,7 +555,7 @@ } heap->st_resizing = 0; } -#endif /* DUK_USE_STRTAB_TORTURE && DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK_USE_STRTAB_TORTURE && DUK__STRTAB_RESIZE_CHECK */ /* * Raw intern; string already checked not to be present. @@ -560,8 +571,12 @@ #endif DUK_DDD(DUK_DDDPRINT("do_intern: heap=%p, str=%p, blen=%lu, strhash=%lx, st_size=%lu, st_count=%lu, load=%lf", - (void *) heap, (const void *) str, (unsigned long) blen, (unsigned long) strhash, - (unsigned long) heap->st_size, (unsigned long) heap->st_count, + (void *) heap, + (const void *) str, + (unsigned long) blen, + (unsigned long) strhash, + (unsigned long) heap->st_size, + (unsigned long) heap->st_count, (double) heap->st_count / (double) heap->st_size)); DUK_ASSERT(heap != NULL); @@ -577,7 +592,7 @@ */ heap->pf_prevent_count++; - DUK_ASSERT(heap->pf_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(heap->pf_prevent_count != 0); /* Wrap. */ #if defined(DUK_USE_STRTAB_TORTURE) && defined(DUK__STRTAB_RESIZE_CHECK) duk__strtable_resize_torture(heap); @@ -604,7 +619,8 @@ /* External string check (low memory optimization). */ #if defined(DUK_USE_HSTRING_EXTDATA) && defined(DUK_USE_EXTSTR_INTERN_CHECK) - extdata = (const duk_uint8_t *) DUK_USE_EXTSTR_INTERN_CHECK(heap->heap_udata, (void *) DUK_LOSE_CONST(str), (duk_size_t) blen); + extdata = + (const duk_uint8_t *) DUK_USE_EXTSTR_INTERN_CHECK(heap->heap_udata, (void *) DUK_LOSE_CONST(str), (duk_size_t) blen); #else extdata = (const duk_uint8_t *) NULL; #endif @@ -642,7 +658,7 @@ #else slot = heap->strtable + (strhash & heap->st_mask); #endif - DUK_ASSERT(res->hdr.h_next == NULL); /* This is the case now, but unnecessary zeroing/NULLing. */ + DUK_ASSERT(res->hdr.h_next == NULL); /* This is the case now, but unnecessary zeroing/NULLing. */ res->hdr.h_next = DUK__HEAPPTR_DEC16(heap, *slot); *slot = DUK__HEAPPTR_ENC16(heap, res); @@ -689,11 +705,12 @@ curr = (duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_lookuplookup_hash); while (curr != NULL) { /* Unsafe memcmp() because for zero blen, str may be NULL. */ - if (strhash == DUK_HSTRING_GET_HASH(curr) && - blen == DUK_HSTRING_GET_BYTELEN(curr) && + if (strhash == DUK_HSTRING_GET_HASH(curr) && blen == DUK_HSTRING_GET_BYTELEN(curr) && duk_memcmp_unsafe((const void *) str, (const void *) DUK_HSTRING_GET_DATA(curr), blen) == 0) { DUK_DDD(DUK_DDDPRINT("intern check: rom string: %!O, computed hash 0x%08lx, rom hash 0x%08lx", - curr, (unsigned long) strhash, (unsigned long) DUK_HSTRING_GET_HASH(curr))); + curr, + (unsigned long) strhash, + (unsigned long) DUK_HSTRING_GET_HASH(curr))); return curr; } curr = curr->hdr.h_next; @@ -701,7 +718,7 @@ return NULL; } -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ DUK_INTERNAL duk_hstring *duk_heap_strtable_intern(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen) { duk_uint32_t strhash; @@ -714,7 +731,7 @@ /* XXX: maybe just require 'str != NULL' even for zero size? */ DUK_ASSERT(heap != NULL); DUK_ASSERT(blen == 0 || str != NULL); - DUK_ASSERT(blen <= DUK_HSTRING_MAX_BYTELEN); /* Caller is responsible for ensuring this. */ + DUK_ASSERT(blen <= DUK_HSTRING_MAX_BYTELEN); /* Caller is responsible for ensuring this. */ strhash = duk_heap_hashstring(heap, str, (duk_size_t) blen); /* String table lookup. */ @@ -728,8 +745,7 @@ h = heap->strtablestrhash & heap->st_mask; #endif while (h != NULL) { - if (DUK_HSTRING_GET_HASH(h) == strhash && - DUK_HSTRING_GET_BYTELEN(h) == blen && + if (DUK_HSTRING_GET_HASH(h) == strhash && DUK_HSTRING_GET_BYTELEN(h) == blen && duk_memcmp_unsafe((const void *) str, (const void *) DUK_HSTRING_GET_DATA(h), (size_t) blen) == 0) { /* Found existing entry. */ DUK_STATS_INC(heap, stats_strtab_intern_hit); @@ -755,7 +771,7 @@ DUK_STATS_INC(heap, stats_strtab_intern_miss); h = duk__strtable_do_intern(heap, str, blen, strhash); - return h; /* may be NULL */ + return h; /* may be NULL */ } /* @@ -778,7 +794,7 @@ p--; *p = duk_lc_digitsval % 10; val = val / 10; - } while (val != 0); /* For val == 0, emit exactly one '0'. */ + } while (val != 0); /* For val == 0, emit exactly one '0'. */ DUK_ASSERT(p >= buf); return duk_heap_strtable_intern(heap, (const duk_uint8_t *) p, (duk_uint32_t) ((buf + sizeof(buf)) - p)); @@ -816,7 +832,7 @@ DUK_ASSERT(DUK_IS_POWER_OF_TWO((duk_uint_t) DUK_USE_LITCACHE_SIZE)); key = (duk_uintptr_t) blen ^ (duk_uintptr_t) str; - key &= (duk_uintptr_t) (DUK_USE_LITCACHE_SIZE - 1); /* Assumes size is power of 2. */ + key &= (duk_uintptr_t) (DUK_USE_LITCACHE_SIZE - 1); /* Assumes size is power of 2. */ /* Due to masking, cast is in 32-bit range. */ DUK_ASSERT(key <= DUK_UINT_MAX); return (duk_uint_t) key; @@ -832,7 +848,9 @@ ent = thr->heap->litcache + key; if (ent->addr == str) { DUK_DD(DUK_DDPRINT("intern check for cached, pinned literal: str=%p, blen=%ld -> duk_hstring %!O", - (const void *) str, (long) blen, (duk_heaphdr *) ent->h)); + (const void *) str, + (long) blen, + (duk_heaphdr *) ent->h)); DUK_ASSERT(ent->h != NULL); DUK_ASSERT(DUK_HSTRING_HAS_PINNED_LITERAL(ent->h)); DUK_STATS_INC(thr->heap, stats_strtab_litcache_hit); @@ -862,7 +880,7 @@ return h; } -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ DUK_INTERNAL duk_hstring *duk_heap_strtable_intern_u32_checked(duk_hthread *thr, duk_uint32_t val) { duk_hstring *res; @@ -897,7 +915,8 @@ duk_hstring *prev; DUK_DDD(DUK_DDDPRINT("remove: heap=%p, h=%p, blen=%lu, strhash=%lx", - (void *) heap, (void *) h, + (void *) heap, + (void *) h, (unsigned long) (h != NULL ? DUK_HSTRING_GET_BYTELEN(h) : 0), (unsigned long) (h != NULL ? DUK_HSTRING_GET_HASH(h) : 0))); @@ -915,13 +934,13 @@ slot = heap->strtable + (DUK_HSTRING_GET_HASH(h) & heap->st_mask); #endif other = DUK__HEAPPTR_DEC16(heap, *slot); - DUK_ASSERT(other != NULL); /* At least argument string is in the chain. */ + DUK_ASSERT(other != NULL); /* At least argument string is in the chain. */ prev = NULL; while (other != h) { prev = other; other = other->hdr.h_next; - DUK_ASSERT(other != NULL); /* We'll eventually find 'h'. */ + DUK_ASSERT(other != NULL); /* We'll eventually find 'h'. */ } if (prev != NULL) { /* Middle of list. */ @@ -935,7 +954,7 @@ * intern will do one. */ } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* Unlink with a 'prev' pointer. */ DUK_INTERNAL void duk_heap_strtable_unlink_prev(duk_heap *heap, duk_hstring *h, duk_hstring *prev) { @@ -946,7 +965,9 @@ #endif DUK_DDD(DUK_DDDPRINT("remove: heap=%p, prev=%p, h=%p, blen=%lu, strhash=%lx", - (void *) heap, (void *) prev, (void *) h, + (void *) heap, + (void *) prev, + (void *) h, (unsigned long) (h != NULL ? DUK_HSTRING_GET_BYTELEN(h) : 0), (unsigned long) (h != NULL ? DUK_HSTRING_GET_HASH(h) : 0)));
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heaphdr.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heaphdr.h
Changed
@@ -49,7 +49,7 @@ #else duk_size_t h_refcount; #endif -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_HEAPPTR16) duk_uint16_t h_next16; @@ -97,7 +97,7 @@ #endif #if defined(DUK_USE_REFCOUNT16) duk_uint16_t h_refcount; - duk_uint16_t h_strextra16; /* round out to 8 bytes */ + duk_uint16_t h_strextra16; /* round out to 8 bytes */ #elif defined(DUK_USE_REFCOUNT32) duk_uint32_t h_refcount; #else @@ -105,160 +105,169 @@ #endif #else duk_uint16_t h_strextra16; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ duk_hstring *h_next; /* No 'h_prev' pointer for strings. */ }; -#define DUK_HEAPHDR_FLAGS_TYPE_MASK 0x00000003UL -#define DUK_HEAPHDR_FLAGS_FLAG_MASK (~DUK_HEAPHDR_FLAGS_TYPE_MASK) +#define DUK_HEAPHDR_FLAGS_TYPE_MASK 0x00000003UL +#define DUK_HEAPHDR_FLAGS_FLAG_MASK (~DUK_HEAPHDR_FLAGS_TYPE_MASK) - /* 2 bits for heap type */ -#define DUK_HEAPHDR_FLAGS_HEAP_START 2 /* 5 heap flags */ -#define DUK_HEAPHDR_FLAGS_USER_START 7 /* 25 user flags */ +/* 2 bits for heap type */ +#define DUK_HEAPHDR_FLAGS_HEAP_START 2 /* 5 heap flags */ +#define DUK_HEAPHDR_FLAGS_USER_START 7 /* 25 user flags */ -#define DUK_HEAPHDR_HEAP_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_HEAP_START + (n)) -#define DUK_HEAPHDR_USER_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_USER_START + (n)) -#define DUK_HEAPHDR_HEAP_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_HEAP_START + (n))) -#define DUK_HEAPHDR_USER_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_USER_START + (n))) +#define DUK_HEAPHDR_HEAP_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_HEAP_START + (n)) +#define DUK_HEAPHDR_USER_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_USER_START + (n)) +#define DUK_HEAPHDR_HEAP_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_HEAP_START + (n))) +#define DUK_HEAPHDR_USER_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_USER_START + (n))) -#define DUK_HEAPHDR_FLAG_REACHABLE DUK_HEAPHDR_HEAP_FLAG(0) /* mark-and-sweep: reachable */ -#define DUK_HEAPHDR_FLAG_TEMPROOT DUK_HEAPHDR_HEAP_FLAG(1) /* mark-and-sweep: children not processed */ -#define DUK_HEAPHDR_FLAG_FINALIZABLE DUK_HEAPHDR_HEAP_FLAG(2) /* mark-and-sweep: finalizable (on current pass) */ -#define DUK_HEAPHDR_FLAG_FINALIZED DUK_HEAPHDR_HEAP_FLAG(3) /* mark-and-sweep: finalized (on previous pass) */ -#define DUK_HEAPHDR_FLAG_READONLY DUK_HEAPHDR_HEAP_FLAG(4) /* read-only object, in code section */ +#define DUK_HEAPHDR_FLAG_REACHABLE DUK_HEAPHDR_HEAP_FLAG(0) /* mark-and-sweep: reachable */ +#define DUK_HEAPHDR_FLAG_TEMPROOT DUK_HEAPHDR_HEAP_FLAG(1) /* mark-and-sweep: children not processed */ +#define DUK_HEAPHDR_FLAG_FINALIZABLE DUK_HEAPHDR_HEAP_FLAG(2) /* mark-and-sweep: finalizable (on current pass) */ +#define DUK_HEAPHDR_FLAG_FINALIZED DUK_HEAPHDR_HEAP_FLAG(3) /* mark-and-sweep: finalized (on previous pass) */ +#define DUK_HEAPHDR_FLAG_READONLY DUK_HEAPHDR_HEAP_FLAG(4) /* read-only object, in code section */ -#define DUK_HTYPE_MIN 0 -#define DUK_HTYPE_STRING 0 -#define DUK_HTYPE_OBJECT 1 -#define DUK_HTYPE_BUFFER 2 -#define DUK_HTYPE_MAX 2 +#define DUK_HTYPE_MIN 0 +#define DUK_HTYPE_STRING 0 +#define DUK_HTYPE_OBJECT 1 +#define DUK_HTYPE_BUFFER 2 +#define DUK_HTYPE_MAX 2 #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAPHDR_GET_NEXT(heap,h) \ - ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_next16)) -#define DUK_HEAPHDR_SET_NEXT(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_NEXT(heap, h) ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_next16)) +#define DUK_HEAPHDR_SET_NEXT(heap, h, val) \ + do { \ (h)->h_next16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) val); \ } while (0) #else -#define DUK_HEAPHDR_GET_NEXT(heap,h) ((h)->h_next) -#define DUK_HEAPHDR_SET_NEXT(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_NEXT(heap, h) ((h)->h_next) +#define DUK_HEAPHDR_SET_NEXT(heap, h, val) \ + do { \ (h)->h_next = (val); \ } while (0) #endif #if defined(DUK_USE_DOUBLE_LINKED_HEAP) #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAPHDR_GET_PREV(heap,h) \ - ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_prev16)) -#define DUK_HEAPHDR_SET_PREV(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_PREV(heap, h) ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_prev16)) +#define DUK_HEAPHDR_SET_PREV(heap, h, val) \ + do { \ (h)->h_prev16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (val)); \ } while (0) #else -#define DUK_HEAPHDR_GET_PREV(heap,h) ((h)->h_prev) -#define DUK_HEAPHDR_SET_PREV(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_PREV(heap, h) ((h)->h_prev) +#define DUK_HEAPHDR_SET_PREV(heap, h, val) \ + do { \ (h)->h_prev = (val); \ } while (0) #endif #endif #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAPHDR_GET_REFCOUNT(h) ((h)->h_refcount) -#define DUK_HEAPHDR_SET_REFCOUNT(h,val) do { \ +#define DUK_HEAPHDR_GET_REFCOUNT(h) ((h)->h_refcount) +#define DUK_HEAPHDR_SET_REFCOUNT(h, val) \ + do { \ (h)->h_refcount = (val); \ - DUK_ASSERT((h)->h_refcount == (val)); /* No truncation. */ \ + DUK_ASSERT((h)->h_refcount == (val)); /* No truncation. */ \ } while (0) -#define DUK_HEAPHDR_PREINC_REFCOUNT(h) (++(h)->h_refcount) /* result: updated refcount */ -#define DUK_HEAPHDR_PREDEC_REFCOUNT(h) (--(h)->h_refcount) /* result: updated refcount */ +#define DUK_HEAPHDR_PREINC_REFCOUNT(h) (++(h)->h_refcount) /* result: updated refcount */ +#define DUK_HEAPHDR_PREDEC_REFCOUNT(h) (--(h)->h_refcount) /* result: updated refcount */ #else /* refcount macros not defined without refcounting, caller must #if defined() now */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Note: type is treated as a field separate from flags, so some masking is * involved in the macros below. */ -#define DUK_HEAPHDR_GET_FLAGS_RAW(h) ((h)->h_flags) -#define DUK_HEAPHDR_SET_FLAGS_RAW(h,val) do { \ - (h)->h_flags = (val); } \ +#define DUK_HEAPHDR_GET_FLAGS_RAW(h) ((h)->h_flags) +#define DUK_HEAPHDR_SET_FLAGS_RAW(h, val) \ + do { \ + (h)->h_flags = (val); \ + } \ } -#define DUK_HEAPHDR_GET_FLAGS(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_FLAG_MASK) -#define DUK_HEAPHDR_SET_FLAGS(h,val) do { \ +#define DUK_HEAPHDR_GET_FLAGS(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_FLAG_MASK) +#define DUK_HEAPHDR_SET_FLAGS(h, val) \ + do { \ (h)->h_flags = ((h)->h_flags & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) | (val); \ } while (0) -#define DUK_HEAPHDR_GET_TYPE(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_TYPE_MASK) -#define DUK_HEAPHDR_SET_TYPE(h,val) do { \ +#define DUK_HEAPHDR_GET_TYPE(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_TYPE_MASK) +#define DUK_HEAPHDR_SET_TYPE(h, val) \ + do { \ (h)->h_flags = ((h)->h_flags & ~(DUK_HEAPHDR_FLAGS_TYPE_MASK)) | (val); \ } while (0) /* Comparison for type >= DUK_HTYPE_MIN skipped; because DUK_HTYPE_MIN is zero * and the comparison is unsigned, it's always true and generates warnings. */ -#define DUK_HEAPHDR_HTYPE_VALID(h) ( \ - DUK_HEAPHDR_GET_TYPE((h)) <= DUK_HTYPE_MAX \ - ) +#define DUK_HEAPHDR_HTYPE_VALID(h) (DUK_HEAPHDR_GET_TYPE((h)) <= DUK_HTYPE_MAX) -#define DUK_HEAPHDR_SET_TYPE_AND_FLAGS(h,tval,fval) do { \ - (h)->h_flags = ((tval) & DUK_HEAPHDR_FLAGS_TYPE_MASK) | \ - ((fval) & DUK_HEAPHDR_FLAGS_FLAG_MASK); \ +#define DUK_HEAPHDR_SET_TYPE_AND_FLAGS(h, tval, fval) \ + do { \ + (h)->h_flags = ((tval) &DUK_HEAPHDR_FLAGS_TYPE_MASK) | ((fval) &DUK_HEAPHDR_FLAGS_FLAG_MASK); \ } while (0) -#define DUK_HEAPHDR_SET_FLAG_BITS(h,bits) do { \ +#define DUK_HEAPHDR_SET_FLAG_BITS(h, bits) \ + do { \ DUK_ASSERT(((bits) & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) == 0); \ (h)->h_flags |= (bits); \ } while (0) -#define DUK_HEAPHDR_CLEAR_FLAG_BITS(h,bits) do { \ +#define DUK_HEAPHDR_CLEAR_FLAG_BITS(h, bits) \ + do { \ DUK_ASSERT(((bits) & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) == 0); \ (h)->h_flags &= ~((bits)); \ } while (0) -#define DUK_HEAPHDR_CHECK_FLAG_BITS(h,bits) (((h)->h_flags & (bits)) != 0) +#define DUK_HEAPHDR_CHECK_FLAG_BITS(h, bits) (((h)->h_flags & (bits)) != 0) -#define DUK_HEAPHDR_SET_REACHABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) -#define DUK_HEAPHDR_CLEAR_REACHABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) -#define DUK_HEAPHDR_HAS_REACHABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) +#define DUK_HEAPHDR_SET_REACHABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) +#define DUK_HEAPHDR_CLEAR_REACHABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) +#define DUK_HEAPHDR_HAS_REACHABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) -#define DUK_HEAPHDR_SET_TEMPROOT(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) -#define DUK_HEAPHDR_CLEAR_TEMPROOT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) -#define DUK_HEAPHDR_HAS_TEMPROOT(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) +#define DUK_HEAPHDR_SET_TEMPROOT(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) +#define DUK_HEAPHDR_CLEAR_TEMPROOT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) +#define DUK_HEAPHDR_HAS_TEMPROOT(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) -#define DUK_HEAPHDR_SET_FINALIZABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) -#define DUK_HEAPHDR_CLEAR_FINALIZABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) -#define DUK_HEAPHDR_HAS_FINALIZABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) +#define DUK_HEAPHDR_SET_FINALIZABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) +#define DUK_HEAPHDR_CLEAR_FINALIZABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) +#define DUK_HEAPHDR_HAS_FINALIZABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) -#define DUK_HEAPHDR_SET_FINALIZED(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) -#define DUK_HEAPHDR_CLEAR_FINALIZED(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) -#define DUK_HEAPHDR_HAS_FINALIZED(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) +#define DUK_HEAPHDR_SET_FINALIZED(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) +#define DUK_HEAPHDR_CLEAR_FINALIZED(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) +#define DUK_HEAPHDR_HAS_FINALIZED(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) -#define DUK_HEAPHDR_SET_READONLY(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) -#define DUK_HEAPHDR_CLEAR_READONLY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) -#define DUK_HEAPHDR_HAS_READONLY(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_SET_READONLY(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_CLEAR_READONLY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_HAS_READONLY(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) /* get or set a range of flags; m=first bit number, n=number of bits */ -#define DUK_HEAPHDR_GET_FLAG_RANGE(h,m,n) (((h)->h_flags >> (m)) & ((1UL << (n)) - 1UL)) +#define DUK_HEAPHDR_GET_FLAG_RANGE(h, m, n) (((h)->h_flags >> (m)) & ((1UL << (n)) - 1UL)) -#define DUK_HEAPHDR_SET_FLAG_RANGE(h,m,n,v) do { \ - (h)->h_flags = \ - ((h)->h_flags & (~(((1UL << (n)) - 1UL) << (m)))) \ - | ((v) << (m)); \ +#define DUK_HEAPHDR_SET_FLAG_RANGE(h, m, n, v) \ + do { \ + (h)->h_flags = ((h)->h_flags & (~(((1UL << (n)) - 1UL) << (m)))) | ((v) << (m)); \ } while (0) /* init pointer fields to null */ #if defined(DUK_USE_DOUBLE_LINKED_HEAP) -#define DUK_HEAPHDR_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_INIT_NULLS(h) \ + do { \ DUK_HEAPHDR_SET_NEXT((h), (void *) NULL); \ DUK_HEAPHDR_SET_PREV((h), (void *) NULL); \ } while (0) #else -#define DUK_HEAPHDR_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_INIT_NULLS(h) \ + do { \ DUK_HEAPHDR_SET_NEXT((h), (void *) NULL); \ } while (0) #endif -#define DUK_HEAPHDR_STRING_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_STRING_INIT_NULLS(h) \ + do { \ (h)->h_next = NULL; \ } while (0) @@ -287,11 +296,21 @@ DUK_INTERNAL_DECL void duk_heaphdr_assert_valid_subclassed(duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_assert_links(duk_heap *heap, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_assert_valid(duk_heaphdr *h); -#define DUK_HEAPHDR_ASSERT_LINKS(heap,h) do { duk_heaphdr_assert_links((heap), (h)); } while (0) -#define DUK_HEAPHDR_ASSERT_VALID(h) do { duk_heaphdr_assert_valid((h)); } while (0) +#define DUK_HEAPHDR_ASSERT_LINKS(heap, h) \ + do { \ + duk_heaphdr_assert_links((heap), (h)); \ + } while (0) +#define DUK_HEAPHDR_ASSERT_VALID(h) \ + do { \ + duk_heaphdr_assert_valid((h)); \ + } while (0) #else -#define DUK_HEAPHDR_ASSERT_LINKS(heap,h) do {} while (0) -#define DUK_HEAPHDR_ASSERT_VALID(h) do {} while (0) +#define DUK_HEAPHDR_ASSERT_LINKS(heap, h) \ + do { \ + } while (0) +#define DUK_HEAPHDR_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#endif /* DUK_HEAPHDR_H_INCLUDED */ +#endif /* DUK_HEAPHDR_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_heaphdr_assert.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_heaphdr_assert.c
Changed
@@ -75,4 +75,4 @@ } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_henv.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_henv.h
Changed
@@ -8,11 +8,21 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hdecenv_assert_valid(duk_hdecenv *h); DUK_INTERNAL_DECL void duk_hobjenv_assert_valid(duk_hobjenv *h); -#define DUK_HDECENV_ASSERT_VALID(h) do { duk_hdecenv_assert_valid((h)); } while (0) -#define DUK_HOBJENV_ASSERT_VALID(h) do { duk_hobjenv_assert_valid((h)); } while (0) +#define DUK_HDECENV_ASSERT_VALID(h) \ + do { \ + duk_hdecenv_assert_valid((h)); \ + } while (0) +#define DUK_HOBJENV_ASSERT_VALID(h) \ + do { \ + duk_hobjenv_assert_valid((h)); \ + } while (0) #else -#define DUK_HDECENV_ASSERT_VALID(h) do {} while (0) -#define DUK_HOBJENV_ASSERT_VALID(h) do {} while (0) +#define DUK_HDECENV_ASSERT_VALID(h) \ + do { \ + } while (0) +#define DUK_HOBJENV_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hdecenv { @@ -42,4 +52,4 @@ duk_bool_t has_this; }; -#endif /* DUK_HENV_H_INCLUDED */ +#endif /* DUK_HENV_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hnatfunc.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hnatfunc.h
Changed
@@ -7,13 +7,18 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hnatfunc_assert_valid(duk_hnatfunc *h); -#define DUK_HNATFUNC_ASSERT_VALID(h) do { duk_hnatfunc_assert_valid((h)); } while (0) +#define DUK_HNATFUNC_ASSERT_VALID(h) \ + do { \ + duk_hnatfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HNATFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HNATFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#define DUK_HNATFUNC_NARGS_VARARGS ((duk_int16_t) -1) -#define DUK_HNATFUNC_NARGS_MAX ((duk_int16_t) 0x7fff) +#define DUK_HNATFUNC_NARGS_VARARGS ((duk_int16_t) -1) +#define DUK_HNATFUNC_NARGS_MAX ((duk_int16_t) 0x7fff) struct duk_hnatfunc { /* shared object part */ @@ -36,4 +41,4 @@ */ }; -#endif /* DUK_HNATFUNC_H_INCLUDED */ +#endif /* DUK_HNATFUNC_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hobject.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hobject.h
Changed
@@ -39,36 +39,40 @@ /* XXX: some flags are object subtype specific (e.g. common to all function * subtypes, duk_harray, etc) and could be reused for different subtypes. */ -#define DUK_HOBJECT_FLAG_EXTENSIBLE DUK_HEAPHDR_USER_FLAG(0) /* object is extensible */ -#define DUK_HOBJECT_FLAG_CONSTRUCTABLE DUK_HEAPHDR_USER_FLAG(1) /* object is constructable */ -#define DUK_HOBJECT_FLAG_CALLABLE DUK_HEAPHDR_USER_FLAG(2) /* object is callable */ -#define DUK_HOBJECT_FLAG_BOUNDFUNC DUK_HEAPHDR_USER_FLAG(3) /* object established using Function.prototype.bind() */ -#define DUK_HOBJECT_FLAG_COMPFUNC DUK_HEAPHDR_USER_FLAG(4) /* object is a compiled function (duk_hcompfunc) */ -#define DUK_HOBJECT_FLAG_NATFUNC DUK_HEAPHDR_USER_FLAG(5) /* object is a native function (duk_hnatfunc) */ -#define DUK_HOBJECT_FLAG_BUFOBJ DUK_HEAPHDR_USER_FLAG(6) /* object is a buffer object (duk_hbufobj) (always exotic) */ -#define DUK_HOBJECT_FLAG_FASTREFS DUK_HEAPHDR_USER_FLAG(7) /* object has no fields needing DECREF/marking beyond base duk_hobject header */ -#define DUK_HOBJECT_FLAG_ARRAY_PART DUK_HEAPHDR_USER_FLAG(8) /* object has an array part (a_size may still be 0) */ -#define DUK_HOBJECT_FLAG_STRICT DUK_HEAPHDR_USER_FLAG(9) /* function: function object is strict */ -#define DUK_HOBJECT_FLAG_NOTAIL DUK_HEAPHDR_USER_FLAG(10) /* function: function must not be tail called */ -#define DUK_HOBJECT_FLAG_NEWENV DUK_HEAPHDR_USER_FLAG(11) /* function: create new environment when called (see duk_hcompfunc) */ -#define DUK_HOBJECT_FLAG_NAMEBINDING DUK_HEAPHDR_USER_FLAG(12) /* function: create binding for func name (function templates only, used for named function expressions) */ -#define DUK_HOBJECT_FLAG_CREATEARGS DUK_HEAPHDR_USER_FLAG(13) /* function: create an arguments object on function call */ -#define DUK_HOBJECT_FLAG_HAVE_FINALIZER DUK_HEAPHDR_USER_FLAG(14) /* object has a callable (own) finalizer property */ -#define DUK_HOBJECT_FLAG_EXOTIC_ARRAY DUK_HEAPHDR_USER_FLAG(15) /* 'Array' object, array length and index exotic behavior */ -#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ DUK_HEAPHDR_USER_FLAG(16) /* 'String' object, array index exotic behavior */ -#define DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS DUK_HEAPHDR_USER_FLAG(17) /* 'Arguments' object and has arguments exotic behavior (non-strict callee) */ -#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(18) /* 'Proxy' object */ -#define DUK_HOBJECT_FLAG_SPECIAL_CALL DUK_HEAPHDR_USER_FLAG(19) /* special casing in call behavior, for .call(), .apply(), etc. */ - -#define DUK_HOBJECT_FLAG_CLASS_BASE DUK_HEAPHDR_USER_FLAG_NUMBER(20) -#define DUK_HOBJECT_FLAG_CLASS_BITS 5 - -#define DUK_HOBJECT_GET_CLASS_NUMBER(h) \ +#define DUK_HOBJECT_FLAG_EXTENSIBLE DUK_HEAPHDR_USER_FLAG(0) /* object is extensible */ +#define DUK_HOBJECT_FLAG_CONSTRUCTABLE DUK_HEAPHDR_USER_FLAG(1) /* object is constructable */ +#define DUK_HOBJECT_FLAG_CALLABLE DUK_HEAPHDR_USER_FLAG(2) /* object is callable */ +#define DUK_HOBJECT_FLAG_BOUNDFUNC DUK_HEAPHDR_USER_FLAG(3) /* object established using Function.prototype.bind() */ +#define DUK_HOBJECT_FLAG_COMPFUNC DUK_HEAPHDR_USER_FLAG(4) /* object is a compiled function (duk_hcompfunc) */ +#define DUK_HOBJECT_FLAG_NATFUNC DUK_HEAPHDR_USER_FLAG(5) /* object is a native function (duk_hnatfunc) */ +#define DUK_HOBJECT_FLAG_BUFOBJ DUK_HEAPHDR_USER_FLAG(6) /* object is a buffer object (duk_hbufobj) (always exotic) */ +#define DUK_HOBJECT_FLAG_FASTREFS \ + DUK_HEAPHDR_USER_FLAG(7) /* object has no fields needing DECREF/marking beyond base duk_hobject header */ +#define DUK_HOBJECT_FLAG_ARRAY_PART DUK_HEAPHDR_USER_FLAG(8) /* object has an array part (a_size may still be 0) */ +#define DUK_HOBJECT_FLAG_STRICT DUK_HEAPHDR_USER_FLAG(9) /* function: function object is strict */ +#define DUK_HOBJECT_FLAG_NOTAIL DUK_HEAPHDR_USER_FLAG(10) /* function: function must not be tail called */ +#define DUK_HOBJECT_FLAG_NEWENV DUK_HEAPHDR_USER_FLAG(11) /* function: create new environment when called (see duk_hcompfunc) */ +#define DUK_HOBJECT_FLAG_NAMEBINDING \ + DUK_HEAPHDR_USER_FLAG( \ + 12) /* function: create binding for func name (function templates only, used for named function expressions) */ +#define DUK_HOBJECT_FLAG_CREATEARGS DUK_HEAPHDR_USER_FLAG(13) /* function: create an arguments object on function call */ +#define DUK_HOBJECT_FLAG_HAVE_FINALIZER DUK_HEAPHDR_USER_FLAG(14) /* object has a callable (own) finalizer property */ +#define DUK_HOBJECT_FLAG_EXOTIC_ARRAY DUK_HEAPHDR_USER_FLAG(15) /* 'Array' object, array length and index exotic behavior */ +#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ DUK_HEAPHDR_USER_FLAG(16) /* 'String' object, array index exotic behavior */ +#define DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS \ + DUK_HEAPHDR_USER_FLAG(17) /* 'Arguments' object and has arguments exotic behavior (non-strict callee) */ +#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(18) /* 'Proxy' object */ +#define DUK_HOBJECT_FLAG_SPECIAL_CALL DUK_HEAPHDR_USER_FLAG(19) /* special casing in call behavior, for .call(), .apply(), etc. */ + +#define DUK_HOBJECT_FLAG_CLASS_BASE DUK_HEAPHDR_USER_FLAG_NUMBER(20) +#define DUK_HOBJECT_FLAG_CLASS_BITS 5 + +#define DUK_HOBJECT_GET_CLASS_NUMBER(h) \ DUK_HEAPHDR_GET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS) -#define DUK_HOBJECT_SET_CLASS_NUMBER(h,v) \ +#define DUK_HOBJECT_SET_CLASS_NUMBER(h, v) \ DUK_HEAPHDR_SET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS, (v)) -#define DUK_HOBJECT_GET_CLASS_MASK(h) \ +#define DUK_HOBJECT_GET_CLASS_MASK(h) \ (1UL << DUK_HEAPHDR_GET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS)) /* Macro for creating flag initializer from a class number. @@ -76,256 +80,239 @@ * a signed integer to an unsigned one; the largest class values * have the highest bit (bit 31) set which causes this. */ -#define DUK_HOBJECT_CLASS_AS_FLAGS(v) (((duk_uint_t) (v)) << DUK_HOBJECT_FLAG_CLASS_BASE) +#define DUK_HOBJECT_CLASS_AS_FLAGS(v) (((duk_uint_t) (v)) << DUK_HOBJECT_FLAG_CLASS_BASE) /* E5 Section 8.6.2 + custom classes */ -#define DUK_HOBJECT_CLASS_NONE 0 -#define DUK_HOBJECT_CLASS_OBJECT 1 -#define DUK_HOBJECT_CLASS_ARRAY 2 -#define DUK_HOBJECT_CLASS_FUNCTION 3 -#define DUK_HOBJECT_CLASS_ARGUMENTS 4 -#define DUK_HOBJECT_CLASS_BOOLEAN 5 -#define DUK_HOBJECT_CLASS_DATE 6 -#define DUK_HOBJECT_CLASS_ERROR 7 -#define DUK_HOBJECT_CLASS_JSON 8 -#define DUK_HOBJECT_CLASS_MATH 9 -#define DUK_HOBJECT_CLASS_NUMBER 10 -#define DUK_HOBJECT_CLASS_REGEXP 11 -#define DUK_HOBJECT_CLASS_STRING 12 -#define DUK_HOBJECT_CLASS_GLOBAL 13 -#define DUK_HOBJECT_CLASS_SYMBOL 14 -#define DUK_HOBJECT_CLASS_OBJENV 15 /* custom */ -#define DUK_HOBJECT_CLASS_DECENV 16 /* custom */ -#define DUK_HOBJECT_CLASS_POINTER 17 /* custom */ -#define DUK_HOBJECT_CLASS_THREAD 18 /* custom; implies DUK_HOBJECT_IS_THREAD */ -#define DUK_HOBJECT_CLASS_BUFOBJ_MIN 19 -#define DUK_HOBJECT_CLASS_ARRAYBUFFER 19 /* implies DUK_HOBJECT_IS_BUFOBJ */ -#define DUK_HOBJECT_CLASS_DATAVIEW 20 -#define DUK_HOBJECT_CLASS_INT8ARRAY 21 -#define DUK_HOBJECT_CLASS_UINT8ARRAY 22 -#define DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY 23 -#define DUK_HOBJECT_CLASS_INT16ARRAY 24 -#define DUK_HOBJECT_CLASS_UINT16ARRAY 25 -#define DUK_HOBJECT_CLASS_INT32ARRAY 26 -#define DUK_HOBJECT_CLASS_UINT32ARRAY 27 -#define DUK_HOBJECT_CLASS_FLOAT32ARRAY 28 -#define DUK_HOBJECT_CLASS_FLOAT64ARRAY 29 -#define DUK_HOBJECT_CLASS_BUFOBJ_MAX 29 -#define DUK_HOBJECT_CLASS_MAX 29 +#define DUK_HOBJECT_CLASS_NONE 0 +#define DUK_HOBJECT_CLASS_OBJECT 1 +#define DUK_HOBJECT_CLASS_ARRAY 2 +#define DUK_HOBJECT_CLASS_FUNCTION 3 +#define DUK_HOBJECT_CLASS_ARGUMENTS 4 +#define DUK_HOBJECT_CLASS_BOOLEAN 5 +#define DUK_HOBJECT_CLASS_DATE 6 +#define DUK_HOBJECT_CLASS_ERROR 7 +#define DUK_HOBJECT_CLASS_JSON 8 +#define DUK_HOBJECT_CLASS_MATH 9 +#define DUK_HOBJECT_CLASS_NUMBER 10 +#define DUK_HOBJECT_CLASS_REGEXP 11 +#define DUK_HOBJECT_CLASS_STRING 12 +#define DUK_HOBJECT_CLASS_GLOBAL 13 +#define DUK_HOBJECT_CLASS_SYMBOL 14 +#define DUK_HOBJECT_CLASS_OBJENV 15 /* custom */ +#define DUK_HOBJECT_CLASS_DECENV 16 /* custom */ +#define DUK_HOBJECT_CLASS_POINTER 17 /* custom */ +#define DUK_HOBJECT_CLASS_THREAD 18 /* custom; implies DUK_HOBJECT_IS_THREAD */ +#define DUK_HOBJECT_CLASS_BUFOBJ_MIN 19 +#define DUK_HOBJECT_CLASS_ARRAYBUFFER 19 /* implies DUK_HOBJECT_IS_BUFOBJ */ +#define DUK_HOBJECT_CLASS_DATAVIEW 20 +#define DUK_HOBJECT_CLASS_INT8ARRAY 21 +#define DUK_HOBJECT_CLASS_UINT8ARRAY 22 +#define DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY 23 +#define DUK_HOBJECT_CLASS_INT16ARRAY 24 +#define DUK_HOBJECT_CLASS_UINT16ARRAY 25 +#define DUK_HOBJECT_CLASS_INT32ARRAY 26 +#define DUK_HOBJECT_CLASS_UINT32ARRAY 27 +#define DUK_HOBJECT_CLASS_FLOAT32ARRAY 28 +#define DUK_HOBJECT_CLASS_FLOAT64ARRAY 29 +#define DUK_HOBJECT_CLASS_BUFOBJ_MAX 29 +#define DUK_HOBJECT_CLASS_MAX 29 /* Class masks. */ -#define DUK_HOBJECT_CMASK_ALL ((1UL << (DUK_HOBJECT_CLASS_MAX + 1)) - 1UL) -#define DUK_HOBJECT_CMASK_NONE (1UL << DUK_HOBJECT_CLASS_NONE) -#define DUK_HOBJECT_CMASK_ARGUMENTS (1UL << DUK_HOBJECT_CLASS_ARGUMENTS) -#define DUK_HOBJECT_CMASK_ARRAY (1UL << DUK_HOBJECT_CLASS_ARRAY) -#define DUK_HOBJECT_CMASK_BOOLEAN (1UL << DUK_HOBJECT_CLASS_BOOLEAN) -#define DUK_HOBJECT_CMASK_DATE (1UL << DUK_HOBJECT_CLASS_DATE) -#define DUK_HOBJECT_CMASK_ERROR (1UL << DUK_HOBJECT_CLASS_ERROR) -#define DUK_HOBJECT_CMASK_FUNCTION (1UL << DUK_HOBJECT_CLASS_FUNCTION) -#define DUK_HOBJECT_CMASK_JSON (1UL << DUK_HOBJECT_CLASS_JSON) -#define DUK_HOBJECT_CMASK_MATH (1UL << DUK_HOBJECT_CLASS_MATH) -#define DUK_HOBJECT_CMASK_NUMBER (1UL << DUK_HOBJECT_CLASS_NUMBER) -#define DUK_HOBJECT_CMASK_OBJECT (1UL << DUK_HOBJECT_CLASS_OBJECT) -#define DUK_HOBJECT_CMASK_REGEXP (1UL << DUK_HOBJECT_CLASS_REGEXP) -#define DUK_HOBJECT_CMASK_STRING (1UL << DUK_HOBJECT_CLASS_STRING) -#define DUK_HOBJECT_CMASK_GLOBAL (1UL << DUK_HOBJECT_CLASS_GLOBAL) -#define DUK_HOBJECT_CMASK_SYMBOL (1UL << DUK_HOBJECT_CLASS_SYMBOL) -#define DUK_HOBJECT_CMASK_OBJENV (1UL << DUK_HOBJECT_CLASS_OBJENV) -#define DUK_HOBJECT_CMASK_DECENV (1UL << DUK_HOBJECT_CLASS_DECENV) -#define DUK_HOBJECT_CMASK_POINTER (1UL << DUK_HOBJECT_CLASS_POINTER) -#define DUK_HOBJECT_CMASK_ARRAYBUFFER (1UL << DUK_HOBJECT_CLASS_ARRAYBUFFER) -#define DUK_HOBJECT_CMASK_DATAVIEW (1UL << DUK_HOBJECT_CLASS_DATAVIEW) -#define DUK_HOBJECT_CMASK_INT8ARRAY (1UL << DUK_HOBJECT_CLASS_INT8ARRAY) -#define DUK_HOBJECT_CMASK_UINT8ARRAY (1UL << DUK_HOBJECT_CLASS_UINT8ARRAY) -#define DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY (1UL << DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY) -#define DUK_HOBJECT_CMASK_INT16ARRAY (1UL << DUK_HOBJECT_CLASS_INT16ARRAY) -#define DUK_HOBJECT_CMASK_UINT16ARRAY (1UL << DUK_HOBJECT_CLASS_UINT16ARRAY) -#define DUK_HOBJECT_CMASK_INT32ARRAY (1UL << DUK_HOBJECT_CLASS_INT32ARRAY) -#define DUK_HOBJECT_CMASK_UINT32ARRAY (1UL << DUK_HOBJECT_CLASS_UINT32ARRAY) -#define DUK_HOBJECT_CMASK_FLOAT32ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT32ARRAY) -#define DUK_HOBJECT_CMASK_FLOAT64ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT64ARRAY) +#define DUK_HOBJECT_CMASK_ALL ((1UL << (DUK_HOBJECT_CLASS_MAX + 1)) - 1UL) +#define DUK_HOBJECT_CMASK_NONE (1UL << DUK_HOBJECT_CLASS_NONE) +#define DUK_HOBJECT_CMASK_ARGUMENTS (1UL << DUK_HOBJECT_CLASS_ARGUMENTS) +#define DUK_HOBJECT_CMASK_ARRAY (1UL << DUK_HOBJECT_CLASS_ARRAY) +#define DUK_HOBJECT_CMASK_BOOLEAN (1UL << DUK_HOBJECT_CLASS_BOOLEAN) +#define DUK_HOBJECT_CMASK_DATE (1UL << DUK_HOBJECT_CLASS_DATE) +#define DUK_HOBJECT_CMASK_ERROR (1UL << DUK_HOBJECT_CLASS_ERROR) +#define DUK_HOBJECT_CMASK_FUNCTION (1UL << DUK_HOBJECT_CLASS_FUNCTION) +#define DUK_HOBJECT_CMASK_JSON (1UL << DUK_HOBJECT_CLASS_JSON) +#define DUK_HOBJECT_CMASK_MATH (1UL << DUK_HOBJECT_CLASS_MATH) +#define DUK_HOBJECT_CMASK_NUMBER (1UL << DUK_HOBJECT_CLASS_NUMBER) +#define DUK_HOBJECT_CMASK_OBJECT (1UL << DUK_HOBJECT_CLASS_OBJECT) +#define DUK_HOBJECT_CMASK_REGEXP (1UL << DUK_HOBJECT_CLASS_REGEXP) +#define DUK_HOBJECT_CMASK_STRING (1UL << DUK_HOBJECT_CLASS_STRING) +#define DUK_HOBJECT_CMASK_GLOBAL (1UL << DUK_HOBJECT_CLASS_GLOBAL) +#define DUK_HOBJECT_CMASK_SYMBOL (1UL << DUK_HOBJECT_CLASS_SYMBOL) +#define DUK_HOBJECT_CMASK_OBJENV (1UL << DUK_HOBJECT_CLASS_OBJENV) +#define DUK_HOBJECT_CMASK_DECENV (1UL << DUK_HOBJECT_CLASS_DECENV) +#define DUK_HOBJECT_CMASK_POINTER (1UL << DUK_HOBJECT_CLASS_POINTER) +#define DUK_HOBJECT_CMASK_ARRAYBUFFER (1UL << DUK_HOBJECT_CLASS_ARRAYBUFFER) +#define DUK_HOBJECT_CMASK_DATAVIEW (1UL << DUK_HOBJECT_CLASS_DATAVIEW) +#define DUK_HOBJECT_CMASK_INT8ARRAY (1UL << DUK_HOBJECT_CLASS_INT8ARRAY) +#define DUK_HOBJECT_CMASK_UINT8ARRAY (1UL << DUK_HOBJECT_CLASS_UINT8ARRAY) +#define DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY (1UL << DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY) +#define DUK_HOBJECT_CMASK_INT16ARRAY (1UL << DUK_HOBJECT_CLASS_INT16ARRAY) +#define DUK_HOBJECT_CMASK_UINT16ARRAY (1UL << DUK_HOBJECT_CLASS_UINT16ARRAY) +#define DUK_HOBJECT_CMASK_INT32ARRAY (1UL << DUK_HOBJECT_CLASS_INT32ARRAY) +#define DUK_HOBJECT_CMASK_UINT32ARRAY (1UL << DUK_HOBJECT_CLASS_UINT32ARRAY) +#define DUK_HOBJECT_CMASK_FLOAT32ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT32ARRAY) +#define DUK_HOBJECT_CMASK_FLOAT64ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT64ARRAY) #define DUK_HOBJECT_CMASK_ALL_BUFOBJS \ - (DUK_HOBJECT_CMASK_ARRAYBUFFER | \ - DUK_HOBJECT_CMASK_DATAVIEW | \ - DUK_HOBJECT_CMASK_INT8ARRAY | \ - DUK_HOBJECT_CMASK_UINT8ARRAY | \ - DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY | \ - DUK_HOBJECT_CMASK_INT16ARRAY | \ - DUK_HOBJECT_CMASK_UINT16ARRAY | \ - DUK_HOBJECT_CMASK_INT32ARRAY | \ - DUK_HOBJECT_CMASK_UINT32ARRAY | \ - DUK_HOBJECT_CMASK_FLOAT32ARRAY | \ + (DUK_HOBJECT_CMASK_ARRAYBUFFER | DUK_HOBJECT_CMASK_DATAVIEW | DUK_HOBJECT_CMASK_INT8ARRAY | DUK_HOBJECT_CMASK_UINT8ARRAY | \ + DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY | DUK_HOBJECT_CMASK_INT16ARRAY | DUK_HOBJECT_CMASK_UINT16ARRAY | \ + DUK_HOBJECT_CMASK_INT32ARRAY | DUK_HOBJECT_CMASK_UINT32ARRAY | DUK_HOBJECT_CMASK_FLOAT32ARRAY | \ DUK_HOBJECT_CMASK_FLOAT64ARRAY) -#define DUK_HOBJECT_IS_OBJENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_OBJENV) -#define DUK_HOBJECT_IS_DECENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_DECENV) -#define DUK_HOBJECT_IS_ENV(h) (DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_DECENV((h))) -#define DUK_HOBJECT_IS_ARRAY(h) DUK_HOBJECT_HAS_EXOTIC_ARRAY((h)) /* Rely on class Array <=> exotic Array */ -#define DUK_HOBJECT_IS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_IS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_IS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_OBJENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_OBJENV) +#define DUK_HOBJECT_IS_DECENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_DECENV) +#define DUK_HOBJECT_IS_ENV(h) (DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_DECENV((h))) +#define DUK_HOBJECT_IS_ARRAY(h) DUK_HOBJECT_HAS_EXOTIC_ARRAY((h)) /* Rely on class Array <=> exotic Array */ +#define DUK_HOBJECT_IS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_IS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_IS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_IS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_IS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #else -#define DUK_HOBJECT_IS_BUFOBJ(h) 0 +#define DUK_HOBJECT_IS_BUFOBJ(h) 0 #endif -#define DUK_HOBJECT_IS_THREAD(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_THREAD) +#define DUK_HOBJECT_IS_THREAD(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_THREAD) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_IS_PROXY(h) DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ((h)) +#define DUK_HOBJECT_IS_PROXY(h) DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ((h)) #else -#define DUK_HOBJECT_IS_PROXY(h) 0 +#define DUK_HOBJECT_IS_PROXY(h) 0 #endif -#define DUK_HOBJECT_IS_NONBOUND_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_COMPFUNC | \ - DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_NONBOUND_FUNCTION(h) \ + DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC | DUK_HOBJECT_FLAG_NATFUNC) -#define DUK_HOBJECT_IS_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_BOUNDFUNC | \ - DUK_HOBJECT_FLAG_COMPFUNC | \ - DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_FUNCTION(h) \ + DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC | DUK_HOBJECT_FLAG_COMPFUNC | DUK_HOBJECT_FLAG_NATFUNC) -#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HOBJECT_HAS_CALLABLE((h)) +#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HOBJECT_HAS_CALLABLE((h)) /* Object has any exotic behavior(s). */ -#define DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS | \ - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ - DUK_HOBJECT_FLAG_BUFOBJ | \ - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) -#define DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS) +#define DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS \ + (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ + DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS) /* Object has any virtual properties (not counting Proxy behavior). */ -#define DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ - DUK_HOBJECT_FLAG_BUFOBJ) -#define DUK_HOBJECT_HAS_VIRTUAL_PROPERTIES(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS) - -#define DUK_HOBJECT_HAS_EXTENSIBLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_HAS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_HAS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_HAS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_HAS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS \ + (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_HAS_VIRTUAL_PROPERTIES(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS) + +#define DUK_HOBJECT_HAS_EXTENSIBLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_HAS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_HAS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_HAS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_HAS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_HAS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_HAS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #else -#define DUK_HOBJECT_HAS_BUFOBJ(h) 0 +#define DUK_HOBJECT_HAS_BUFOBJ(h) 0 #endif -#define DUK_HOBJECT_HAS_FASTREFS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_HAS_ARRAY_PART(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_HAS_STRICT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_HAS_NOTAIL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_HAS_NEWENV(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_HAS_NAMEBINDING(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_HAS_CREATEARGS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_HAS_HAVE_FINALIZER(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_HAS_EXOTIC_ARRAY(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_HAS_FASTREFS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_HAS_ARRAY_PART(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_HAS_STRICT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_HAS_NOTAIL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_HAS_NEWENV(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_HAS_NAMEBINDING(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_HAS_CREATEARGS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_HAS_HAVE_FINALIZER(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_HAS_EXOTIC_ARRAY(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #else -#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) 0 +#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) 0 #endif -#define DUK_HOBJECT_HAS_SPECIAL_CALL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) - -#define DUK_HOBJECT_SET_EXTENSIBLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_SET_CONSTRUCTABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_SET_CALLABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_SET_BOUNDFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_SET_COMPFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_SET_NATFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_HAS_SPECIAL_CALL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) + +#define DUK_HOBJECT_SET_EXTENSIBLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_SET_CONSTRUCTABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_SET_CALLABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_SET_BOUNDFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_SET_COMPFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_SET_NATFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_SET_BUFOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_SET_BUFOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #endif -#define DUK_HOBJECT_SET_FASTREFS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_SET_ARRAY_PART(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_SET_STRICT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_SET_NOTAIL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_SET_NEWENV(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_SET_NAMEBINDING(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_SET_CREATEARGS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_SET_HAVE_FINALIZER(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_SET_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_SET_FASTREFS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_SET_ARRAY_PART(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_SET_STRICT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_SET_NOTAIL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_SET_NEWENV(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_SET_NAMEBINDING(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_SET_CREATEARGS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_SET_HAVE_FINALIZER(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_SET_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_SET_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_SET_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #endif -#define DUK_HOBJECT_SET_SPECIAL_CALL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) - -#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_CLEAR_CALLABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_CLEAR_BOUNDFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_CLEAR_COMPFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_CLEAR_NATFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_SET_SPECIAL_CALL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) + +#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_CLEAR_CALLABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_CLEAR_BOUNDFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_CLEAR_COMPFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_CLEAR_NATFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_CLEAR_BUFOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_CLEAR_BUFOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #endif -#define DUK_HOBJECT_CLEAR_FASTREFS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_CLEAR_ARRAY_PART(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_CLEAR_STRICT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_CLEAR_NOTAIL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_CLEAR_NEWENV(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_CLEAR_NAMEBINDING(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_CLEAR_CREATEARGS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_CLEAR_EXOTIC_ARRAY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_CLEAR_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_CLEAR_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_CLEAR_FASTREFS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_CLEAR_ARRAY_PART(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_CLEAR_STRICT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_CLEAR_NOTAIL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_CLEAR_NEWENV(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_CLEAR_NAMEBINDING(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_CLEAR_CREATEARGS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_CLEAR_EXOTIC_ARRAY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_CLEAR_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_CLEAR_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_CLEAR_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_CLEAR_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #endif -#define DUK_HOBJECT_CLEAR_SPECIAL_CALL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) +#define DUK_HOBJECT_CLEAR_SPECIAL_CALL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) /* Object can/cannot use FASTREFS, i.e. has no strong reference fields beyond * duk_hobject base header. This is used just for asserts so doesn't need to * be optimized. */ #define DUK_HOBJECT_PROHIBITS_FASTREFS(h) \ - (DUK_HOBJECT_IS_COMPFUNC((h)) || DUK_HOBJECT_IS_DECENV((h)) || DUK_HOBJECT_IS_OBJENV((h)) || \ - DUK_HOBJECT_IS_BUFOBJ((h)) || DUK_HOBJECT_IS_THREAD((h)) || DUK_HOBJECT_IS_PROXY((h)) || \ - DUK_HOBJECT_IS_BOUNDFUNC((h))) + (DUK_HOBJECT_IS_COMPFUNC((h)) || DUK_HOBJECT_IS_DECENV((h)) || DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_BUFOBJ((h)) || \ + DUK_HOBJECT_IS_THREAD((h)) || DUK_HOBJECT_IS_PROXY((h)) || DUK_HOBJECT_IS_BOUNDFUNC((h))) #define DUK_HOBJECT_ALLOWS_FASTREFS(h) (!DUK_HOBJECT_PROHIBITS_FASTREFS((h))) /* Flags used for property attributes in duk_propdesc and packed flags. * Must fit into 8 bits. */ -#define DUK_PROPDESC_FLAG_WRITABLE (1U << 0) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_ENUMERABLE (1U << 1) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_CONFIGURABLE (1U << 2) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_ACCESSOR (1U << 3) /* accessor */ -#define DUK_PROPDESC_FLAG_VIRTUAL (1U << 4) /* property is virtual: used in duk_propdesc, never stored - * (used by e.g. buffer virtual properties) - */ -#define DUK_PROPDESC_FLAGS_MASK (DUK_PROPDESC_FLAG_WRITABLE | \ - DUK_PROPDESC_FLAG_ENUMERABLE | \ - DUK_PROPDESC_FLAG_CONFIGURABLE | \ - DUK_PROPDESC_FLAG_ACCESSOR) +#define DUK_PROPDESC_FLAG_WRITABLE (1U << 0) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_ENUMERABLE (1U << 1) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_CONFIGURABLE (1U << 2) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_ACCESSOR (1U << 3) /* accessor */ +#define DUK_PROPDESC_FLAG_VIRTUAL \ + (1U << 4) /* property is virtual: used in duk_propdesc, never stored \ + * (used by e.g. buffer virtual properties) \ + */ +#define DUK_PROPDESC_FLAGS_MASK \ + (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE | DUK_PROPDESC_FLAG_ACCESSOR) /* Additional flags which are passed in the same flags argument as property * flags but are not stored in object properties. */ -#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1U << 4) /* internal define property: skip write silently if exists */ +#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1U << 4) /* internal define property: skip write silently if exists */ /* Convenience defines for property attributes. */ -#define DUK_PROPDESC_FLAGS_NONE 0 -#define DUK_PROPDESC_FLAGS_W (DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_PROPDESC_FLAGS_E (DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_PROPDESC_FLAGS_C (DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_WE (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_PROPDESC_FLAGS_WC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_EC (DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_WEC (DUK_PROPDESC_FLAG_WRITABLE | \ - DUK_PROPDESC_FLAG_ENUMERABLE | \ - DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_NONE 0 +#define DUK_PROPDESC_FLAGS_W (DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_PROPDESC_FLAGS_E (DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_PROPDESC_FLAGS_C (DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_WE (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_PROPDESC_FLAGS_WC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_EC (DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_WEC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) /* Flags for duk_hobject_get_own_propdesc() and variants. */ -#define DUK_GETDESC_FLAG_PUSH_VALUE (1U << 0) /* push value to stack */ -#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1U << 1) /* don't throw for prototype loop */ +#define DUK_GETDESC_FLAG_PUSH_VALUE (1U << 0) /* push value to stack */ +#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1U << 1) /* don't throw for prototype loop */ /* * Macro for object validity check @@ -335,9 +322,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hobject_assert_valid(duk_hobject *h); -#define DUK_HOBJECT_ASSERT_VALID(h) do { duk_hobject_assert_valid((h)); } while (0) +#define DUK_HOBJECT_ASSERT_VALID(h) \ + do { \ + duk_hobject_assert_valid((h)); \ + } while (0) #else -#define DUK_HOBJECT_ASSERT_VALID(h) do {} while (0) +#define DUK_HOBJECT_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -345,52 +337,41 @@ */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_GET_PROPS(heap,h) \ - ((duk_uint8_t *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (h))->h_extra16)) -#define DUK_HOBJECT_SET_PROPS(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROPS(heap, h) ((duk_uint8_t *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (h))->h_extra16)) +#define DUK_HOBJECT_SET_PROPS(heap, h, x) \ + do { \ ((duk_heaphdr *) (h))->h_extra16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (x)); \ } while (0) #else -#define DUK_HOBJECT_GET_PROPS(heap,h) \ - ((h)->props) -#define DUK_HOBJECT_SET_PROPS(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROPS(heap, h) ((h)->props) +#define DUK_HOBJECT_SET_PROPS(heap, h, x) \ + do { \ (h)->props = (duk_uint8_t *) (x); \ } while (0) #endif #if defined(DUK_USE_HOBJECT_LAYOUT_1) /* LAYOUT 1 */ -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_hstring *) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) \ + ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_hstring *))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + (n_arr) * sizeof(duk_tval) + \ + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_k) = (duk_hstring **) (void *) (p_base); \ (set_e_pv) = (duk_propvalue *) (void *) ((set_e_k) + (n_ent)); \ (set_e_f) = (duk_uint8_t *) (void *) ((set_e_pv) + (n_ent)); \ @@ -408,85 +389,57 @@ #else #error invalid DUK_USE_ALIGN_BY #endif -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING((n_ent)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) \ + ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + DUK_HOBJECT_E_FLAG_PADDING((n_ent)) + \ + (n_arr) * sizeof(duk_tval) + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_pv) = (duk_propvalue *) (void *) (p_base); \ (set_e_k) = (duk_hstring **) (void *) ((set_e_pv) + (n_ent)); \ (set_e_f) = (duk_uint8_t *) (void *) ((set_e_k) + (n_ent)); \ - (set_a) = (duk_tval *) (void *) (((duk_uint8_t *) (set_e_f)) + \ - sizeof(duk_uint8_t) * (n_ent) + \ + (set_a) = (duk_tval *) (void *) (((duk_uint8_t *) (set_e_f)) + sizeof(duk_uint8_t) * (n_ent) + \ DUK_HOBJECT_E_FLAG_PADDING((n_ent))); \ (set_h) = (duk_uint32_t *) (void *) ((set_a) + (n_arr)); \ } while (0) #elif defined(DUK_USE_HOBJECT_LAYOUT_3) /* LAYOUT 3 */ -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) + \ - DUK_HOBJECT_GET_HSIZE((h)) * sizeof(duk_uint32_t) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_propvalue) + sizeof(duk_hstring *) + sizeof(duk_uint8_t)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) \ + ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) + \ + DUK_HOBJECT_GET_HSIZE((h)) * sizeof(duk_uint32_t))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_propvalue) + sizeof(duk_hstring *) + sizeof(duk_uint8_t)) + (n_arr) * sizeof(duk_tval) + \ + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_pv) = (duk_propvalue *) (void *) (p_base); \ (set_a) = (duk_tval *) (void *) ((set_e_pv) + (n_ent)); \ (set_e_k) = (duk_hstring **) (void *) ((set_a) + (n_arr)); \ @@ -495,85 +448,99 @@ } while (0) #else #error invalid hobject layout defines -#endif /* hobject property layout */ +#endif /* hobject property layout */ #define DUK_HOBJECT_P_ALLOC_SIZE(h) \ DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE((h)), DUK_HOBJECT_GET_ASIZE((h)), DUK_HOBJECT_GET_HSIZE((h))) -#define DUK_HOBJECT_E_GET_KEY(heap,h,i) (DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_KEY_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE(heap,h,i) (DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE_TVAL(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) -#define DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) -#define DUK_HOBJECT_E_GET_VALUE_GETTER(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) -#define DUK_HOBJECT_E_GET_VALUE_GETTER_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) -#define DUK_HOBJECT_E_GET_VALUE_SETTER(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) -#define DUK_HOBJECT_E_GET_VALUE_SETTER_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) -#define DUK_HOBJECT_E_GET_FLAGS(heap,h,i) (DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_FLAGS_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) -#define DUK_HOBJECT_A_GET_VALUE(heap,h,i) (DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_A_GET_VALUE_PTR(heap,h,i) (&DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_H_GET_INDEX(heap,h,i) (DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_H_GET_INDEX_PTR(heap,h,i) (&DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) - -#define DUK_HOBJECT_E_SET_KEY(heap,h,i,k) do { \ +#define DUK_HOBJECT_E_GET_KEY(heap, h, i) (DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_KEY_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE(heap, h, i) (DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE_TVAL(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) +#define DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) +#define DUK_HOBJECT_E_GET_VALUE_GETTER(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) +#define DUK_HOBJECT_E_GET_VALUE_GETTER_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) +#define DUK_HOBJECT_E_GET_VALUE_SETTER(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) +#define DUK_HOBJECT_E_GET_VALUE_SETTER_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) +#define DUK_HOBJECT_E_GET_FLAGS(heap, h, i) (DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_FLAGS_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) +#define DUK_HOBJECT_A_GET_VALUE(heap, h, i) (DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_A_GET_VALUE_PTR(heap, h, i) (&DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_H_GET_INDEX(heap, h, i) (DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_H_GET_INDEX_PTR(heap, h, i) (&DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) + +#define DUK_HOBJECT_E_SET_KEY(heap, h, i, k) \ + do { \ DUK_HOBJECT_E_GET_KEY((heap), (h), (i)) = (k); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_TVAL(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_TVAL(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_GETTER(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_GETTER(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_SETTER(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_SETTER(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_FLAGS(heap,h,i,f) do { \ +#define DUK_HOBJECT_E_SET_FLAGS(heap, h, i, f) \ + do { \ DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) = (duk_uint8_t) (f); \ } while (0) -#define DUK_HOBJECT_A_SET_VALUE(heap,h,i,v) do { \ +#define DUK_HOBJECT_A_SET_VALUE(heap, h, i, v) \ + do { \ DUK_HOBJECT_A_GET_VALUE((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_A_SET_VALUE_TVAL(heap,h,i,v) \ - DUK_HOBJECT_A_SET_VALUE((heap), (h), (i), (v)) /* alias for above */ -#define DUK_HOBJECT_H_SET_INDEX(heap,h,i,v) do { \ +#define DUK_HOBJECT_A_SET_VALUE_TVAL(heap, h, i, v) DUK_HOBJECT_A_SET_VALUE((heap), (h), (i), (v)) /* alias for above */ +#define DUK_HOBJECT_H_SET_INDEX(heap, h, i, v) \ + do { \ DUK_HOBJECT_H_GET_INDEX((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_FLAG_BITS(heap,h,i,mask) do { \ +#define DUK_HOBJECT_E_SET_FLAG_BITS(heap, h, i, mask) \ + do { \ DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i) |= (mask); \ } while (0) -#define DUK_HOBJECT_E_CLEAR_FLAG_BITS(heap,h,i,mask) do { \ +#define DUK_HOBJECT_E_CLEAR_FLAG_BITS(heap, h, i, mask) \ + do { \ DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i) &= ~(mask); \ } while (0) -#define DUK_HOBJECT_E_SLOT_IS_WRITABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_WRITABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ACCESSOR) != 0) - -#define DUK_HOBJECT_E_SLOT_SET_WRITABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_HOBJECT_E_SLOT_SET_ENUMERABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_HOBJECT_E_SLOT_SET_CONFIGURABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_HOBJECT_E_SLOT_SET_ACCESSOR(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ACCESSOR) - -#define DUK_HOBJECT_E_SLOT_CLEAR_WRITABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_ENUMERABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_CONFIGURABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_ACCESSOR(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ACCESSOR) - -#define DUK_PROPDESC_IS_WRITABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_WRITABLE) != 0) -#define DUK_PROPDESC_IS_ENUMERABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) -#define DUK_PROPDESC_IS_CONFIGURABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) -#define DUK_PROPDESC_IS_ACCESSOR(p) (((p)->flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0) - -#define DUK_HOBJECT_HASHIDX_UNUSED 0xffffffffUL -#define DUK_HOBJECT_HASHIDX_DELETED 0xfffffffeUL +#define DUK_HOBJECT_E_SLOT_IS_WRITABLE(heap, h, i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_WRITABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(heap, h, i) \ + ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(heap, h, i) \ + ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap, h, i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ACCESSOR) != 0) + +#define DUK_HOBJECT_E_SLOT_SET_WRITABLE(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_HOBJECT_E_SLOT_SET_ENUMERABLE(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_HOBJECT_E_SLOT_SET_CONFIGURABLE(heap, h, i) \ + DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_HOBJECT_E_SLOT_SET_ACCESSOR(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ACCESSOR) + +#define DUK_HOBJECT_E_SLOT_CLEAR_WRITABLE(heap, h, i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_ENUMERABLE(heap, h, i) \ + DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_CONFIGURABLE(heap, h, i) \ + DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_ACCESSOR(heap, h, i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ACCESSOR) + +#define DUK_PROPDESC_IS_WRITABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_WRITABLE) != 0) +#define DUK_PROPDESC_IS_ENUMERABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) +#define DUK_PROPDESC_IS_CONFIGURABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) +#define DUK_PROPDESC_IS_ACCESSOR(p) (((p)->flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0) + +#define DUK_HOBJECT_HASHIDX_UNUSED 0xffffffffUL +#define DUK_HOBJECT_HASHIDX_DELETED 0xfffffffeUL /* * Macros for accessing size fields @@ -581,33 +548,63 @@ #if defined(DUK_USE_OBJSIZES16) #define DUK_HOBJECT_GET_ESIZE(h) ((h)->e_size16) -#define DUK_HOBJECT_SET_ESIZE(h,v) do { (h)->e_size16 = (v); } while (0) +#define DUK_HOBJECT_SET_ESIZE(h, v) \ + do { \ + (h)->e_size16 = (v); \ + } while (0) #define DUK_HOBJECT_GET_ENEXT(h) ((h)->e_next16) -#define DUK_HOBJECT_SET_ENEXT(h,v) do { (h)->e_next16 = (v); } while (0) +#define DUK_HOBJECT_SET_ENEXT(h, v) \ + do { \ + (h)->e_next16 = (v); \ + } while (0) #define DUK_HOBJECT_POSTINC_ENEXT(h) ((h)->e_next16++) -#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size16) -#define DUK_HOBJECT_SET_ASIZE(h,v) do { (h)->a_size16 = (v); } while (0) +#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size16) +#define DUK_HOBJECT_SET_ASIZE(h, v) \ + do { \ + (h)->a_size16 = (v); \ + } while (0) #if defined(DUK_USE_HOBJECT_HASH_PART) #define DUK_HOBJECT_GET_HSIZE(h) ((h)->h_size16) -#define DUK_HOBJECT_SET_HSIZE(h,v) do { (h)->h_size16 = (v); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + (h)->h_size16 = (v); \ + } while (0) #else #define DUK_HOBJECT_GET_HSIZE(h) 0 -#define DUK_HOBJECT_SET_HSIZE(h,v) do { DUK_ASSERT((v) == 0); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + DUK_ASSERT((v) == 0); \ + } while (0) #endif #else #define DUK_HOBJECT_GET_ESIZE(h) ((h)->e_size) -#define DUK_HOBJECT_SET_ESIZE(h,v) do { (h)->e_size = (v); } while (0) +#define DUK_HOBJECT_SET_ESIZE(h, v) \ + do { \ + (h)->e_size = (v); \ + } while (0) #define DUK_HOBJECT_GET_ENEXT(h) ((h)->e_next) -#define DUK_HOBJECT_SET_ENEXT(h,v) do { (h)->e_next = (v); } while (0) +#define DUK_HOBJECT_SET_ENEXT(h, v) \ + do { \ + (h)->e_next = (v); \ + } while (0) #define DUK_HOBJECT_POSTINC_ENEXT(h) ((h)->e_next++) -#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size) -#define DUK_HOBJECT_SET_ASIZE(h,v) do { (h)->a_size = (v); } while (0) +#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size) +#define DUK_HOBJECT_SET_ASIZE(h, v) \ + do { \ + (h)->a_size = (v); \ + } while (0) #if defined(DUK_USE_HOBJECT_HASH_PART) #define DUK_HOBJECT_GET_HSIZE(h) ((h)->h_size) -#define DUK_HOBJECT_SET_HSIZE(h,v) do { (h)->h_size = (v); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + (h)->h_size = (v); \ + } while (0) #else #define DUK_HOBJECT_GET_HSIZE(h) 0 -#define DUK_HOBJECT_SET_HSIZE(h,v) do { DUK_ASSERT((v) == 0); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + DUK_ASSERT((v) == 0); \ + } while (0) #endif #endif @@ -618,46 +615,44 @@ /* Maximum prototype traversal depth. Sanity limit which handles e.g. * prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4). */ -#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY 10000L +#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY 10000L /* * ECMAScript Class */ /* range check not necessary because all 4-bit values are mapped */ -#define DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(n) duk_class_number_to_stridx(n) +#define DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(n) duk_class_number_to_stridx(n) -#define DUK_HOBJECT_GET_CLASS_STRING(heap,h) \ - DUK_HEAP_GET_STRING( \ - (heap), \ - DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(DUK_HOBJECT_GET_CLASS_NUMBER((h))) \ - ) +#define DUK_HOBJECT_GET_CLASS_STRING(heap, h) \ + DUK_HEAP_GET_STRING((heap), DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(DUK_HOBJECT_GET_CLASS_NUMBER((h)))) /* * Macros for property handling */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_GET_PROTOTYPE(heap,h) \ - ((duk_hobject *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->prototype16)) -#define DUK_HOBJECT_SET_PROTOTYPE(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROTOTYPE(heap, h) ((duk_hobject *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->prototype16)) +#define DUK_HOBJECT_SET_PROTOTYPE(heap, h, x) \ + do { \ (h)->prototype16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (x)); \ } while (0) #else -#define DUK_HOBJECT_GET_PROTOTYPE(heap,h) \ - ((h)->prototype) -#define DUK_HOBJECT_SET_PROTOTYPE(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROTOTYPE(heap, h) ((h)->prototype) +#define DUK_HOBJECT_SET_PROTOTYPE(heap, h, x) \ + do { \ (h)->prototype = (x); \ } while (0) #endif /* Set prototype, DECREF earlier value, INCREF new value (tolerating NULLs). */ -#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr,h,p) duk_hobject_set_prototype_updref((thr), (h), (p)) +#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, p) duk_hobject_set_prototype_updref((thr), (h), (p)) /* Set initial prototype, assume NULL previous prototype, INCREF new value, * tolerate NULL. */ -#define DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr,h,proto) do { \ +#define DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, h, proto) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_hobject *duk__obj = (h); \ duk_hobject *duk__proto = (proto); \ @@ -672,9 +667,9 @@ */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap,h) duk_hobject_has_finalizer_fast_raw((heap), (h)) +#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap, h) duk_hobject_has_finalizer_fast_raw((heap), (h)) #else -#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap,h) duk_hobject_has_finalizer_fast_raw((h)) +#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap, h) duk_hobject_has_finalizer_fast_raw((h)) #endif /* @@ -688,18 +683,18 @@ * so anything above 0x80000000 will cause trouble now. */ #if defined(DUK_USE_OBJSIZES16) -#define DUK_HOBJECT_MAX_PROPERTIES 0x0000ffffUL +#define DUK_HOBJECT_MAX_PROPERTIES 0x0000ffffUL #else -#define DUK_HOBJECT_MAX_PROPERTIES 0x3fffffffUL /* 2**30-1 ~= 1G properties */ +#define DUK_HOBJECT_MAX_PROPERTIES 0x3fffffffUL /* 2**30-1 ~= 1G properties */ #endif /* internal align target for props allocation, must be 2*n for some n */ #if (DUK_USE_ALIGN_BY == 4) -#define DUK_HOBJECT_ALIGN_TARGET 4 +#define DUK_HOBJECT_ALIGN_TARGET 4 #elif (DUK_USE_ALIGN_BY == 8) -#define DUK_HOBJECT_ALIGN_TARGET 8 +#define DUK_HOBJECT_ALIGN_TARGET 8 #elif (DUK_USE_ALIGN_BY == 1) -#define DUK_HOBJECT_ALIGN_TARGET 1 +#define DUK_HOBJECT_ALIGN_TARGET 1 #else #error invalid DUK_USE_ALIGN_BY #endif @@ -708,10 +703,10 @@ * PC-to-line constants */ -#define DUK_PC2LINE_SKIP 64 +#define DUK_PC2LINE_SKIP 64 /* maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes */ -#define DUK_PC2LINE_MAX_DIFF_LENGTH (((DUK_PC2LINE_SKIP - 1) * 35 + 7) / 8) +#define DUK_PC2LINE_MAX_DIFF_LENGTH (((DUK_PC2LINE_SKIP - 1) * 35 + 7) / 8) /* * Struct defs @@ -738,9 +733,9 @@ duk_hobject *set; /* for updating (all are set to < 0 for virtual properties) */ - duk_int_t e_idx; /* prop index in 'entry part', < 0 if not there */ - duk_int_t h_idx; /* prop index in 'hash part', < 0 if not there */ - duk_int_t a_idx; /* prop index in 'array part', < 0 if not there */ + duk_int_t e_idx; /* prop index in 'entry part', < 0 if not there */ + duk_int_t h_idx; /* prop index in 'hash part', < 0 if not there */ + duk_int_t a_idx; /* prop index in 'array part', < 0 if not there */ }; struct duk_hobject { @@ -835,11 +830,11 @@ duk_uint16_t h_size16; #endif #else - duk_uint32_t e_size; /* entry part size */ - duk_uint32_t e_next; /* index for next new key (0,e_next are gc reachable) */ - duk_uint32_t a_size; /* array part size (entirely gc reachable) */ + duk_uint32_t e_size; /* entry part size */ + duk_uint32_t e_next; /* index for next new key (0,e_next are gc reachable) */ + duk_uint32_t a_size; /* array part size (entirely gc reachable) */ #if defined(DUK_USE_HOBJECT_HASH_PART) - duk_uint32_t h_size; /* hash part size or 0 if unused */ + duk_uint32_t h_size; /* hash part size or 0 if unused */ #endif #endif }; @@ -850,7 +845,7 @@ #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL duk_uint8_t duk_class_number_to_stridx32; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* * Prototypes @@ -879,36 +874,46 @@ duk_uint32_t new_a_size, duk_uint32_t new_h_size, duk_bool_t abandon_array); -DUK_INTERNAL_DECL void duk_hobject_resize_entrypart(duk_hthread *thr, - duk_hobject *obj, - duk_uint32_t new_e_size); -#if 0 /*unused*/ +DUK_INTERNAL_DECL void duk_hobject_resize_entrypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_e_size); +#if 0 /*unused*/ DUK_INTERNAL_DECL void duk_hobject_resize_arraypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_a_size); #endif /* low-level property functions */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_hstring *key); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_stridx(duk_heap *heap, duk_hobject *obj, duk_small_uint_t stridx); -DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_uint_t *out_attrs); +DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, + duk_hobject *obj, + duk_hstring *key, + duk_uint_t *out_attrs); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_array_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_uarridx_t i); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); /* core property functions */ DUK_INTERNAL_DECL duk_bool_t duk_hobject_getprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag); DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_bool_t throw_flag); DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key); /* internal property functions */ -#define DUK_DELPROP_FLAG_THROW (1U << 0) -#define DUK_DELPROP_FLAG_FORCE (1U << 1) +#define DUK_DELPROP_FLAG_THROW (1U << 0) +#define DUK_DELPROP_FLAG_FORCE (1U << 1) DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags); DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key); -DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags); -DUK_INTERNAL_DECL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, duk_hobject *obj, duk_uarridx_t arr_idx, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, + duk_hobject *obj, + duk_uarridx_t arr_idx, + duk_small_uint_t flags); DUK_INTERNAL_DECL duk_size_t duk_hobject_get_length(duk_hthread *thr, duk_hobject *obj); #if defined(DUK_USE_HEAPPTR16) DUK_INTERNAL_DECL duk_bool_t duk_hobject_has_finalizer_fast_raw(duk_heap *heap, duk_hobject *obj); @@ -968,7 +973,10 @@ #endif /* misc */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop); +DUK_INTERNAL_DECL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, + duk_hobject *h, + duk_hobject *p, + duk_bool_t ignore_loop); #if !defined(DUK_USE_OBJECT_BUILTIN) /* These declarations are needed when related built-in is disabled and @@ -978,4 +986,4 @@ DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype(duk_hthread *thr); #endif -#endif /* DUK_HOBJECT_H_INCLUDED */ +#endif /* DUK_HOBJECT_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hobject_alloc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hobject_alloc.c
Changed
@@ -21,7 +21,7 @@ /* Zeroed by caller. */ obj->hdr.h_flags = hobject_flags | DUK_HTYPE_OBJECT; - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(&obj->hdr) == DUK_HTYPE_OBJECT); /* Assume zero shift. */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(&obj->hdr) == DUK_HTYPE_OBJECT); /* Assume zero shift. */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) DUK_HOBJECT_SET_PROTOTYPE(heap, obj, NULL); @@ -157,7 +157,7 @@ DUK_HBUFOBJ_ASSERT_VALID(res); return res; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Allocate a new thread. *
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hobject_assert.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hobject_assert.c
Changed
@@ -8,20 +8,18 @@ DUK_INTERNAL void duk_hobject_assert_valid(duk_hobject *h) { DUK_ASSERT(h != NULL); - DUK_ASSERT(!DUK_HOBJECT_IS_CALLABLE(h) || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FUNCTION); - DUK_ASSERT(!DUK_HOBJECT_IS_BUFOBJ(h) || - (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAYBUFFER || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_DATAVIEW || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT8ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT16ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT16ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT64ARRAY)); + DUK_ASSERT(!DUK_HOBJECT_IS_CALLABLE(h) || DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FUNCTION); + DUK_ASSERT(!DUK_HOBJECT_IS_BUFOBJ(h) || (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAYBUFFER || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_DATAVIEW || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT8ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT16ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT16ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT64ARRAY)); /* Object is an Array <=> object has exotic array behavior */ DUK_ASSERT((DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAY && DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)) || (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_ARRAY && !DUK_HOBJECT_HAS_EXOTIC_ARRAY(h))); @@ -37,8 +35,7 @@ DUK_ASSERT(h != NULL); DUK_ASSERT(DUK_HOBJECT_IS_BOUNDFUNC((duk_hobject *) h)); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(&h->target) || - (DUK_TVAL_IS_OBJECT(&h->target) && - DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(&h->target)))); + (DUK_TVAL_IS_OBJECT(&h->target) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(&h->target)))); DUK_ASSERT(!DUK_TVAL_IS_UNUSED(&h->this_binding)); DUK_ASSERT(h->nargs == 0 || h->args != NULL); } @@ -70,7 +67,7 @@ DUK_ASSERT(h->offset + h->length >= h->offset); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_INTERNAL void duk_hcompfunc_assert_valid(duk_hcompfunc *h) { DUK_ASSERT(h != NULL); @@ -124,4 +121,4 @@ DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hobject_class.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hobject_class.c
Changed
@@ -94,7 +94,7 @@ /* Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that */ DUK_INTERNAL duk_uint8_t duk_class_number_to_stridx32 = { - DUK_STRIDX_EMPTY_STRING, /* NONE, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* NONE, intentionally empty */ DUK_STRIDX_UC_OBJECT, DUK_STRIDX_UC_ARRAY, DUK_STRIDX_UC_FUNCTION, @@ -124,6 +124,6 @@ DUK_STRIDX_UINT32_ARRAY, DUK_STRIDX_FLOAT32_ARRAY, DUK_STRIDX_FLOAT64_ARRAY, - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ };
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hobject_enum.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hobject_enum.c
Changed
@@ -24,7 +24,7 @@ /* First enumerated key index in enumerator object, must match exactly the * number of control properties inserted to the enumerator. */ -#define DUK__ENUM_START_INDEX 2 +#define DUK__ENUM_START_INDEX 2 /* Current implementation suffices for ES2015 for now because there's no symbol * sorting, so commented out for now. @@ -93,7 +93,7 @@ DUK_ASSERT(a != NULL); DUK_ASSERT(b != NULL); - DUK_UNREF(b); /* Not actually needed now, val_b suffices. */ + DUK_UNREF(b); /* Not actually needed now, val_b suffices. */ val_a = duk__hstring_sort_key(a); @@ -114,7 +114,7 @@ DUK_UNREF(thr); if (idx_end <= idx_start + 1) { - return; /* Zero or one element(s). */ + return; /* Zero or one element(s). */ } keys = DUK_HOBJECT_E_GET_KEY_BASE(thr->heap, h_obj); @@ -132,7 +132,7 @@ * (and optimized for) case. */ - val_curr = duk__hstring_sort_key(h_curr); /* Remains same during scanning. */ + val_curr = duk__hstring_sort_key(h_curr); /* Remains same during scanning. */ for (idx_insert = idx - 1; idx_insert >= idx_start; idx_insert--) { duk_hstring *h_insert; h_insert = keysidx_insert; @@ -205,7 +205,7 @@ duk_hobject *h_proxy_handler; duk_hobject *h_trap_result; #endif - duk_uint_fast32_t i, len; /* used for array, stack, and entry indices */ + duk_uint_fast32_t i, len; /* used for array, stack, and entry indices */ duk_uint_fast32_t sort_start_index; DUK_ASSERT(thr != NULL); @@ -224,11 +224,11 @@ * real object to check against. */ duk_push_hobject(thr, enum_target); - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ /* Initialize index so that we skip internal control keys. */ duk_push_int(thr, DUK__ENUM_START_INDEX); - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_NEXT); /* Target is bare, plain put OK. */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_NEXT); /* Target is bare, plain put OK. */ /* * Proxy object handling @@ -238,9 +238,7 @@ if (DUK_LIKELY((enum_flags & DUK_ENUM_NO_PROXY_BEHAVIOR) != 0)) { goto skip_proxy; } - if (DUK_LIKELY(!duk_hobject_proxy_check(enum_target, - &h_proxy_target, - &h_proxy_handler))) { + if (DUK_LIKELY(!duk_hobject_proxy_check(enum_target, &h_proxy_target, &h_proxy_handler))) { goto skip_proxy; } @@ -261,17 +259,17 @@ DUK_DDD(DUK_DDDPRINT("h_proxy_target=%!O", (duk_heaphdr *) h_proxy_target)); enum_target = h_proxy_target; - duk_push_hobject(thr, enum_target); /* -> ... enum_target res handler undefined target */ - duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ + duk_push_hobject(thr, enum_target); /* -> ... enum_target res handler undefined target */ + duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ - duk_pop_2(thr); /* -> ... enum_target res */ + duk_pop_2(thr); /* -> ... enum_target res */ goto skip_proxy; } /* ... enum_target res handler trap */ duk_insert(thr, -2); - duk_push_hobject(thr, h_proxy_target); /* -> ... enum_target res trap handler target */ - duk_call_method(thr, 1 /*nargs*/); /* -> ... enum_target res trap_result */ + duk_push_hobject(thr, h_proxy_target); /* -> ... enum_target res trap handler target */ + duk_call_method(thr, 1 /*nargs*/); /* -> ... enum_target res trap_result */ h_trap_result = duk_require_hobject(thr, -1); DUK_UNREF(h_trap_result); @@ -284,7 +282,7 @@ len = (duk_uint_fast32_t) duk_get_length(thr, -1); for (i = 0; i < len; i++) { (void) duk_get_prop_index(thr, -1, (duk_uarridx_t) i); - DUK_ASSERT(duk_is_string(thr, -1)); /* postprocess cleaned up */ + DUK_ASSERT(duk_is_string(thr, -1)); /* postprocess cleaned up */ /* ... enum_target res trap_result keys_array val */ duk_push_true(thr); /* ... enum_target res trap_result keys_array val true */ @@ -305,8 +303,8 @@ DUK_DDD(DUK_DDDPRINT("proxy enumeration, final res: %!O", (duk_heaphdr *) res)); goto compact_and_return; - skip_proxy: -#endif /* DUK_USE_ES6_PROXY */ +skip_proxy: +#endif /* DUK_USE_ES6_PROXY */ curr = enum_target; sort_start_index = DUK__ENUM_START_INDEX; @@ -357,7 +355,7 @@ if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(curr)) { duk_hstring *h_val; h_val = duk_hobject_get_internal_value_string(thr->heap, curr); - DUK_ASSERT(h_val != NULL); /* string objects must not created without internal value */ + DUK_ASSERT(h_val != NULL); /* string objects must not created without internal value */ len = (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_val); } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -380,7 +378,7 @@ len = (duk_uint_fast32_t) (h_bufobj->length >> h_bufobj->shift); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ for (i = 0; i < len; i++) { duk_hstring *k; @@ -420,7 +418,7 @@ if (DUK_TVAL_IS_UNUSED(tv)) { continue; } - k = duk_heap_strtable_intern_u32_checked(thr, (duk_uint32_t) i); /* Fragile reachability. */ + k = duk_heap_strtable_intern_u32_checked(thr, (duk_uint32_t) i); /* Fragile reachability. */ DUK_ASSERT(k); duk__add_enum_key(thr, k); @@ -452,8 +450,7 @@ continue; } if (DUK_UNLIKELY(DUK_HSTRING_HAS_SYMBOL(k))) { - if (!(enum_flags & DUK_ENUM_INCLUDE_HIDDEN) && - DUK_HSTRING_HAS_HIDDEN(k)) { + if (!(enum_flags & DUK_ENUM_INCLUDE_HIDDEN) && DUK_HSTRING_HAS_HIDDEN(k)) { continue; } if (!(enum_flags & DUK_ENUM_INCLUDE_SYMBOLS)) { @@ -463,7 +460,7 @@ need_sort = 1; #endif } else { - DUK_ASSERT(!DUK_HSTRING_HAS_HIDDEN(k)); /* would also have symbol flag */ + DUK_ASSERT(!DUK_HSTRING_HAS_HIDDEN(k)); /* would also have symbol flag */ if (enum_flags & DUK_ENUM_EXCLUDE_STRINGS) { continue; } @@ -512,7 +509,10 @@ #else if (need_sort) { DUK_DDD(DUK_DDDPRINT("need to sort")); - duk__sort_enum_keys_es6(thr, res, (duk_int_fast32_t) sort_start_index, (duk_int_fast32_t) sort_end_index); + duk__sort_enum_keys_es6(thr, + res, + (duk_int_fast32_t) sort_start_index, + (duk_int_fast32_t) sort_end_index); } else { DUK_DDD(DUK_DDDPRINT("no need to sort")); } @@ -545,11 +545,14 @@ /* Sort to ES2015 order which works for pure array incides but * also for mixed keys. */ - duk__sort_enum_keys_es6(thr, res, (duk_int_fast32_t) DUK__ENUM_START_INDEX, (duk_int_fast32_t) DUK_HOBJECT_GET_ENEXT(res)); + duk__sort_enum_keys_es6(thr, + res, + (duk_int_fast32_t) DUK__ENUM_START_INDEX, + (duk_int_fast32_t) DUK_HOBJECT_GET_ENEXT(res)); } #if defined(DUK_USE_ES6_PROXY) - compact_and_return: +compact_and_return: #endif /* compact; no need to seal because object is internal */ duk_hobject_compact_props(thr, res); @@ -597,10 +600,11 @@ #else check_existence = 1; #endif - duk_pop(thr); /* still reachable */ + duk_pop(thr); /* still reachable */ DUK_DDD(DUK_DDDPRINT("getting next enum value, enum_target=%!iO, enumerator=%!iT", - (duk_heaphdr *) enum_target, (duk_tval *) duk_get_tval(thr, -1))); + (duk_heaphdr *) enum_target, + (duk_tval *) duk_get_tval(thr, -1))); /* no array part */ for (;;) { @@ -641,16 +645,16 @@ duk_push_hstring(thr, res); if (get_value) { duk_push_hobject(thr, enum_target); - duk_dup_m2(thr); /* -> ... enum key enum_target key */ + duk_dup_m2(thr); /* -> ... enum key enum_target key */ duk_get_prop(thr, -2); /* -> ... enum key enum_target val */ - duk_remove_m2(thr); /* -> ... enum key val */ - duk_remove(thr, -3); /* -> ... key val */ + duk_remove_m2(thr); /* -> ... enum key val */ + duk_remove(thr, -3); /* -> ... key val */ } else { - duk_remove_m2(thr); /* -> ... key */ + duk_remove_m2(thr); /* -> ... key */ } return 1; } else { - duk_pop(thr); /* -> ... */ + duk_pop(thr); /* -> ... */ return 0; } } @@ -697,7 +701,7 @@ duk_hstring *k; k = *keys++; - DUK_ASSERT(k != NULL); /* enumerator must have no keys deleted */ + DUK_ASSERT(k != NULL); /* enumerator must have no keys deleted */ DUK_TVAL_SET_STRING(tv, k); tv++; @@ -709,5 +713,5 @@ /* enum_target res */ - return 1; /* return 1 to allow callers to tail call */ + return 1; /* return 1 to allow callers to tail call */ }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hobject_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hobject_misc.c
Changed
@@ -4,7 +4,10 @@ #include "duk_internal.h" -DUK_INTERNAL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop) { +DUK_INTERNAL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, + duk_hobject *h, + duk_hobject *p, + duk_bool_t ignore_loop) { duk_uint_t sanity; DUK_ASSERT(thr != NULL); @@ -43,7 +46,7 @@ DUK_ASSERT(h); tmp = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, h, p); - DUK_HOBJECT_INCREF_ALLOWNULL(thr, p); /* avoid problems if p == h->prototype */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, p); /* avoid problems if p == h->prototype */ DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); #else DUK_ASSERT(h);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hobject_pc2line.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hobject_pc2line.c
Changed
@@ -35,7 +35,7 @@ hdr = (duk_uint32_t *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, h_buf); DUK_ASSERT(hdr != NULL); - hdr0 = (duk_uint32_t) length; /* valid pc range is 0, length */ + hdr0 = (duk_uint32_t) length; /* valid pc range is 0, length */ curr_pc = 0U; while (curr_pc < length) { @@ -64,8 +64,8 @@ for (;;) { curr_pc++; - if ( ((curr_pc % DUK_PC2LINE_SKIP) == 0) || /* end of diff run */ - (curr_pc >= length) ) { /* end of bytecode */ + if (((curr_pc % DUK_PC2LINE_SKIP) == 0) || /* end of diff run */ + (curr_pc >= length)) { /* end of bytecode */ break; } DUK_ASSERT(curr_pc < length); @@ -112,7 +112,9 @@ (void) duk_to_fixed_buffer(thr, -1, NULL); DUK_DDD(DUK_DDDPRINT("final pc2line data: pc_limit=%ld, length=%ld, %lf bits/opcode --> %!ixT", - (long) length, (long) new_size, (double) new_size * 8.0 / (double) length, + (long) length, + (long) new_size, + (double) new_size * 8.0 / (double) length, (duk_tval *) duk_get_tval(thr, -1))); } @@ -152,8 +154,7 @@ pc_limit = hdr0; if (pc >= pc_limit) { /* Note: pc is unsigned and cannot be negative */ - DUK_DD(DUK_DDPRINT("pc2line lookup failed: pc out of bounds (pc=%ld, limit=%ld)", - (long) pc, (long) pc_limit)); + DUK_DD(DUK_DDPRINT("pc2line lookup failed: pc out of bounds (pc=%ld, limit=%ld)", (long) pc, (long) pc_limit)); goto pc2line_error; } @@ -161,7 +162,8 @@ start_offset = hdr1 + hdr_index * 2 + 1; if ((duk_size_t) start_offset > DUK_HBUFFER_FIXED_GET_SIZE(buf)) { DUK_DD(DUK_DDPRINT("pc2line lookup failed: start_offset out of bounds (start_offset=%ld, buffer_size=%ld)", - (long) start_offset, (long) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) buf))); + (long) start_offset, + (long) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) buf))); goto pc2line_error; } @@ -188,7 +190,7 @@ if (duk_bd_decode_flag(bd_ctx)) { /* 1 1 1 <32 bits> */ duk_uint_fast32_t t; - t = duk_bd_decode(bd_ctx, 16); /* workaround: max nbits = 24 now */ + t = duk_bd_decode(bd_ctx, 16); /* workaround: max nbits = 24 now */ t = (t << 16) + duk_bd_decode(bd_ctx, 16); curr_line = t; } else { @@ -213,7 +215,7 @@ DUK_DDD(DUK_DDDPRINT("pc2line lookup result: pc %ld -> line %ld", (long) pc, (long) curr_line)); return curr_line; - pc2line_error: +pc2line_error: DUK_D(DUK_DPRINT("pc2line conversion failed for pc=%ld", (long) pc)); return 0; } @@ -241,4 +243,4 @@ return line; } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hobject_props.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hobject_props.c
Changed
@@ -46,35 +46,56 @@ * Local defines */ -#define DUK__NO_ARRAY_INDEX DUK_HSTRING_NO_ARRAY_INDEX +#define DUK__NO_ARRAY_INDEX DUK_HSTRING_NO_ARRAY_INDEX /* Marker values for hash part. */ -#define DUK__HASH_UNUSED DUK_HOBJECT_HASHIDX_UNUSED -#define DUK__HASH_DELETED DUK_HOBJECT_HASHIDX_DELETED +#define DUK__HASH_UNUSED DUK_HOBJECT_HASHIDX_UNUSED +#define DUK__HASH_DELETED DUK_HOBJECT_HASHIDX_DELETED /* Valstack space that suffices for all local calls, excluding any recursion * into ECMAScript or Duktape/C calls (Proxy, getters, etc). */ -#define DUK__VALSTACK_SPACE 10 +#define DUK__VALSTACK_SPACE 10 /* Valstack space allocated especially for proxy lookup which does a * recursive property lookup. */ -#define DUK__VALSTACK_PROXY_LOOKUP 20 +#define DUK__VALSTACK_PROXY_LOOKUP 20 /* * Local prototypes */ -DUK_LOCAL_DECL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc); -DUK_LOCAL_DECL void duk__check_arguments_map_for_put(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc, duk_bool_t throw_flag); -DUK_LOCAL_DECL void duk__check_arguments_map_for_delete(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc); - -DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length_smaller(duk_hthread *thr, duk_hobject *obj, duk_uint32_t old_len, duk_uint32_t new_len, duk_bool_t force_flag, duk_uint32_t *out_result_len); +DUK_LOCAL_DECL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc); +DUK_LOCAL_DECL void duk__check_arguments_map_for_put(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc, + duk_bool_t throw_flag); +DUK_LOCAL_DECL void duk__check_arguments_map_for_delete(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc); + +DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length_smaller(duk_hthread *thr, + duk_hobject *obj, + duk_uint32_t old_len, + duk_uint32_t new_len, + duk_bool_t force_flag, + duk_uint32_t *out_result_len); DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length(duk_hthread *thr, duk_hobject *obj); -DUK_LOCAL_DECL duk_bool_t duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); -DUK_LOCAL_DECL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_uint32_t arr_idx, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_LOCAL_DECL duk_bool_t +duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_LOCAL_DECL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_uint32_t arr_idx, + duk_propdesc *out_desc, + duk_small_uint_t flags); DUK_LOCAL_DECL void duk__abandon_array_part(duk_hthread *thr, duk_hobject *obj); DUK_LOCAL_DECL void duk__grow_props_for_array_item(duk_hthread *thr, duk_hobject *obj, duk_uint32_t highest_arr_idx); @@ -103,7 +124,7 @@ dbl = DUK_TVAL_GET_NUMBER(tv); idx = (duk_uint32_t) dbl; if (duk_double_equals((duk_double_t) idx, dbl)) { - /* Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF, + /* Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF, * it's not a valid array index but will then match DUK__NO_ARRAY_INDEX. */ return idx; @@ -130,7 +151,7 @@ */ return (duk_uint32_t) t; } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* Convert a duk_tval on the value stack (in a trusted index we don't validate) * to a string or symbol using ES2015 ToPropertyKey(): @@ -155,7 +176,7 @@ * but still be compliant and share code. */ - tv_dst = DUK_GET_TVAL_NEGIDX(thr, idx); /* intentionally unvalidated */ + tv_dst = DUK_GET_TVAL_NEGIDX(thr, idx); /* intentionally unvalidated */ if (DUK_TVAL_IS_STRING(tv_dst)) { /* Most important path: strings and plain symbols are used as * is. For symbols the array index check below is unnecessary @@ -175,7 +196,7 @@ } DUK_LOCAL duk_uint32_t duk__push_tval_to_property_key(duk_hthread *thr, duk_tval *tv_key, duk_hstring **out_h) { - duk_push_tval(thr, tv_key); /* XXX: could use an unsafe push here */ + duk_push_tval(thr, tv_key); /* XXX: could use an unsafe push here */ return duk__to_property_key(thr, -1, out_h); } @@ -215,7 +236,7 @@ * is relatively sparse. */ tmp = e_size; - res = 2; /* Result will be 2 ** (N + 1). */ + res = 2; /* Result will be 2 ** (N + 1). */ while (tmp >= 0x40) { tmp >>= 6; res <<= 6; @@ -224,21 +245,21 @@ tmp >>= 1; res <<= 1; } - DUK_ASSERT((DUK_HOBJECT_MAX_PROPERTIES << 2U) > DUK_HOBJECT_MAX_PROPERTIES); /* Won't wrap, even shifted by 2. */ + DUK_ASSERT((DUK_HOBJECT_MAX_PROPERTIES << 2U) > DUK_HOBJECT_MAX_PROPERTIES); /* Won't wrap, even shifted by 2. */ DUK_ASSERT(res > e_size); return res; } else { return 0; } } -#endif /* USE_PROP_HASH_PART */ +#endif /* USE_PROP_HASH_PART */ /* Get minimum entry part growth for a certain size. */ DUK_LOCAL duk_uint32_t duk__get_min_grow_e(duk_uint32_t e_size) { duk_uint32_t res; res = (e_size + DUK_USE_HOBJECT_ENTRY_MINGROW_ADD) / DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR; - DUK_ASSERT(res >= 1); /* important for callers */ + DUK_ASSERT(res >= 1); /* important for callers */ return res; } @@ -247,7 +268,7 @@ duk_uint32_t res; res = (a_size + DUK_USE_HOBJECT_ARRAY_MINGROW_ADD) / DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR; - DUK_ASSERT(res >= 1); /* important for callers */ + DUK_ASSERT(res >= 1); /* important for callers */ return res; } @@ -277,7 +298,7 @@ DUK_LOCAL void duk__compute_a_stats(duk_hthread *thr, duk_hobject *obj, duk_uint32_t *out_used, duk_uint32_t *out_min_size) { duk_uint_fast32_t i; duk_uint_fast32_t used = 0; - duk_uint_fast32_t highest_idx = (duk_uint_fast32_t) -1; /* see below */ + duk_uint_fast32_t highest_idx = (duk_uint_fast32_t) -1; /* see below */ duk_tval *a; DUK_ASSERT(obj != NULL); @@ -300,7 +321,7 @@ */ *out_used = (duk_uint32_t) used; - *out_min_size = (duk_uint32_t) (highest_idx + 1); /* 0 if no used entries */ + *out_min_size = (duk_uint32_t) (highest_idx + 1); /* 0 if no used entries */ } /* Check array density and indicate whether or not the array part should be abandoned. */ @@ -367,7 +388,9 @@ duk__compute_a_stats(thr, obj, &old_used, &old_size); DUK_DDD(DUK_DDDPRINT("abandon check, array stats: old_used=%ld, old_size=%ld, arr_idx=%ld", - (long) old_used, (long) old_size, (long) arr_idx)); + (long) old_used, + (long) old_size, + (long) arr_idx)); min_size = arr_idx + 1; #if defined(DUK_USE_OBJSIZES16) @@ -395,7 +418,7 @@ DUK_DDD(DUK_DDDPRINT("=> decided to keep array part")); return 0; - do_abandon: +do_abandon: duk__abandon_array_part(thr, obj); DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(obj)); return 1; @@ -422,7 +445,8 @@ DUK_DDD(DUK_DDDPRINT("write to new array requires array resize, decide whether to do a " "fast resize without abandon check (arr_idx=%ld, old_size=%ld)", - (long) arr_idx, (long) DUK_HOBJECT_GET_ASIZE(obj))); + (long) arr_idx, + (long) DUK_HOBJECT_GET_ASIZE(obj))); if (DUK_UNLIKELY(duk__abandon_array_check(thr, arr_idx, obj) != 0)) { DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(obj)); @@ -481,7 +505,7 @@ return 1; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* Get Proxy target object. If the argument is not a Proxy, return it as is. * If a Proxy is revoked, an error is thrown. @@ -507,10 +531,14 @@ DUK_ASSERT(obj != NULL); return obj; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ES6_PROXY) -DUK_LOCAL duk_bool_t duk__proxy_check_prop(duk_hthread *thr, duk_hobject *obj, duk_small_uint_t stridx_trap, duk_tval *tv_key, duk_hobject **out_target) { +DUK_LOCAL duk_bool_t duk__proxy_check_prop(duk_hthread *thr, + duk_hobject *obj, + duk_small_uint_t stridx_trap, + duk_tval *tv_key, + duk_hobject **out_target) { duk_hobject *h_handler; DUK_ASSERT(thr != NULL); @@ -564,7 +592,7 @@ duk_push_hobject(thr, h_handler); if (duk_get_prop_stridx_short(thr, -1, stridx_trap)) { /* -> ... handler trap */ - duk_insert(thr, -2); /* -> ... trap handler */ + duk_insert(thr, -2); /* -> ... trap handler */ /* stack prepped for func call: ... trap handler */ return 1; @@ -573,7 +601,7 @@ return 0; } } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* * Reallocate property allocation, moving properties to the new allocation. @@ -628,11 +656,12 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(obj != NULL); - DUK_ASSERT(!abandon_array || new_a_size == 0); /* if abandon_array, new_a_size must be 0 */ - DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || (DUK_HOBJECT_GET_ESIZE(obj) == 0 && DUK_HOBJECT_GET_ASIZE(obj) == 0)); - DUK_ASSERT(new_h_size == 0 || new_h_size >= new_e_size); /* required to guarantee success of rehashing, - * intentionally use unadjusted new_e_size - */ + DUK_ASSERT(!abandon_array || new_a_size == 0); /* if abandon_array, new_a_size must be 0 */ + DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || + (DUK_HOBJECT_GET_ESIZE(obj) == 0 && DUK_HOBJECT_GET_ASIZE(obj) == 0)); + DUK_ASSERT(new_h_size == 0 || new_h_size >= new_e_size); /* required to guarantee success of rehashing, + * intentionally use unadjusted new_e_size + */ DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); @@ -662,10 +691,12 @@ DUK_DDD(DUK_DDDPRINT("using layout 1, but no need to pad e_size: %ld", (long) new_e_size)); new_e_size_adjusted = new_e_size; #elif defined(DUK_USE_HOBJECT_LAYOUT_1) && ((DUK_HOBJECT_ALIGN_TARGET == 4) || (DUK_HOBJECT_ALIGN_TARGET == 8)) - new_e_size_adjusted = (new_e_size + (duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U) & - (~((duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U)); + new_e_size_adjusted = + (new_e_size + (duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U) & (~((duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U)); DUK_DDD(DUK_DDDPRINT("using layout 1, and alignment target is %ld, adjusted e_size: %ld -> %ld", - (long) DUK_HOBJECT_ALIGN_TARGET, (long) new_e_size, (long) new_e_size_adjusted)); + (long) DUK_HOBJECT_ALIGN_TARGET, + (long) new_e_size, + (long) new_e_size_adjusted)); DUK_ASSERT(new_e_size_adjusted >= new_e_size); #else #error invalid hobject layout defines @@ -675,23 +706,22 @@ * Debug logging after adjustment. */ - DUK_DDD(DUK_DDDPRINT("attempt to resize hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " - "{e_size=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", - (void *) obj, - (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)), - (long) DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size), - (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), - (long) DUK_HOBJECT_GET_ESIZE(obj), - (long) DUK_HOBJECT_GET_ENEXT(obj), - (long) DUK_HOBJECT_GET_ASIZE(obj), - (long) DUK_HOBJECT_GET_HSIZE(obj), - (long) new_e_size_adjusted, - (long) new_a_size, - (long) new_h_size, - (long) abandon_array, - (long) new_e_size)); + DUK_DDD(DUK_DDDPRINT( + "attempt to resize hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " + "{e_size=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", + (void *) obj, + (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)), + (long) DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size), + (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), + (long) DUK_HOBJECT_GET_ESIZE(obj), + (long) DUK_HOBJECT_GET_ENEXT(obj), + (long) DUK_HOBJECT_GET_ASIZE(obj), + (long) DUK_HOBJECT_GET_HSIZE(obj), + (long) new_e_size_adjusted, + (long) new_a_size, + (long) new_h_size, + (long) abandon_array, + (long) new_e_size)); /* * Property count check. This is the only point where we ensure that @@ -734,9 +764,9 @@ #endif prev_ms_base_flags = thr->heap->ms_base_flags; thr->heap->ms_base_flags |= - DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact the current object (all objects really). */ - thr->heap->pf_prevent_count++; /* Avoid finalizers. */ - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact the current object (all objects really). */ + thr->heap->pf_prevent_count++; /* Avoid finalizers. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ new_alloc_size = DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size); DUK_DDD(DUK_DDDPRINT("new hobject allocation size is %ld", (long) new_alloc_size)); @@ -749,7 +779,7 @@ /* Alloc may trigger mark-and-sweep but no compaction, and * cannot throw. */ -#if 0 /* XXX: inject test */ +#if 0 /* XXX: inject test */ if (1) { new_p = NULL; goto alloc_failed; @@ -767,19 +797,28 @@ /* Set up pointers to the new property area: this is hidden behind a macro * because it is memory layout specific. */ - DUK_HOBJECT_P_SET_REALLOC_PTRS(new_p, new_e_k, new_e_pv, new_e_f, new_a, new_h, - new_e_size_adjusted, new_a_size, new_h_size); - DUK_UNREF(new_h); /* happens when hash part dropped */ + DUK_HOBJECT_P_SET_REALLOC_PTRS(new_p, + new_e_k, + new_e_pv, + new_e_f, + new_a, + new_h, + new_e_size_adjusted, + new_a_size, + new_h_size); + DUK_UNREF(new_h); /* happens when hash part dropped */ new_e_next = 0; /* if new_p == NULL, all of these pointers are NULL */ - DUK_ASSERT((new_p != NULL) || - (new_e_k == NULL && new_e_pv == NULL && new_e_f == NULL && - new_a == NULL && new_h == NULL)); + DUK_ASSERT((new_p != NULL) || (new_e_k == NULL && new_e_pv == NULL && new_e_f == NULL && new_a == NULL && new_h == NULL)); DUK_DDD(DUK_DDDPRINT("new alloc size %ld, new_e_k=%p, new_e_pv=%p, new_e_f=%p, new_a=%p, new_h=%p", - (long) new_alloc_size, (void *) new_e_k, (void *) new_e_pv, (void *) new_e_f, - (void *) new_a, (void *) new_h)); + (long) new_alloc_size, + (void *) new_e_k, + (void *) new_e_pv, + (void *) new_e_f, + (void *) new_a, + (void *) new_h)); /* * Migrate array part to start of entries if requested. @@ -820,8 +859,7 @@ continue; } - DUK_ASSERT(new_p != NULL && new_e_k != NULL && - new_e_pv != NULL && new_e_f != NULL); + DUK_ASSERT(new_p != NULL && new_e_k != NULL && new_e_pv != NULL && new_e_f != NULL); /* * Intern key via the valstack to ensure reachability behaves @@ -833,7 +871,7 @@ * must be careful. */ -#if 0 /* XXX: inject test */ +#if 0 /* XXX: inject test */ if (1) { goto abandon_error; } @@ -849,7 +887,7 @@ if (key == NULL) { goto abandon_error; } - duk_push_hstring(thr, key); /* keep key reachable for GC etc; guaranteed not to fail */ + duk_push_hstring(thr, key); /* keep key reachable for GC etc; guaranteed not to fail */ /* Key is now reachable in the valstack, don't INCREF * the new allocation yet (we'll steal the refcounts @@ -857,11 +895,10 @@ */ new_e_knew_e_next = key; - tv2 = &new_e_pvnew_e_next.v; /* array entries are all plain values */ + tv2 = &new_e_pvnew_e_next.v; /* array entries are all plain values */ DUK_TVAL_SET_TVAL(tv2, tv1); - new_e_fnew_e_next = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE | - DUK_PROPDESC_FLAG_CONFIGURABLE; + new_e_fnew_e_next = + DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE; new_e_next++; /* Note: new_e_next matches pushed temp key count, and nothing can @@ -888,8 +925,7 @@ continue; } - DUK_ASSERT(new_p != NULL && new_e_k != NULL && - new_e_pv != NULL && new_e_f != NULL); + DUK_ASSERT(new_p != NULL && new_e_k != NULL && new_e_pv != NULL && new_e_f != NULL); new_e_knew_e_next = key; new_e_pvnew_e_next = DUK_HOBJECT_E_GET_VALUE(thr->heap, obj, i); @@ -923,9 +959,7 @@ DUK_ASSERT(new_a != NULL || array_copy_size == 0U); DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || array_copy_size == 0U); DUK_ASSERT(DUK_HOBJECT_GET_ASIZE(obj) > 0 || array_copy_size == 0U); - duk_memcpy_unsafe((void *) new_a, - (const void *) DUK_HOBJECT_A_GET_BASE(thr->heap, obj), - array_copy_size); + duk_memcpy_unsafe((void *) new_a, (const void *) DUK_HOBJECT_A_GET_BASE(thr->heap, obj), array_copy_size); for (i = DUK_HOBJECT_GET_ASIZE(obj); i < new_a_size; i++) { duk_tval *tv = &new_ai; @@ -953,7 +987,7 @@ DUK_ASSERT(new_h_size > 0); duk_memset(new_h, 0xff, sizeof(duk_uint32_t) * new_h_size); - DUK_ASSERT(new_e_next <= new_h_size); /* equality not actually possible */ + DUK_ASSERT(new_e_next <= new_h_size); /* equality not actually possible */ mask = new_h_size - 1; for (i = 0; i < new_e_next; i++) { @@ -962,10 +996,10 @@ DUK_ASSERT(key != NULL); j = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { - DUK_ASSERT(new_hj != DUK__HASH_DELETED); /* should never happen */ + DUK_ASSERT(new_hj != DUK__HASH_DELETED); /* should never happen */ if (new_hj == DUK__HASH_UNUSED) { DUK_DDD(DUK_DDDPRINT("rebuild hit %ld -> %ld", (long) j, (long) i)); new_hj = (duk_uint32_t) i; @@ -978,37 +1012,36 @@ } } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* * Nice debug log. */ - DUK_DD(DUK_DDPRINT("resized hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " - "{p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", - (void *) obj, - (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)), - (long) new_alloc_size, - (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), - (long) DUK_HOBJECT_GET_ESIZE(obj), - (long) DUK_HOBJECT_GET_ENEXT(obj), - (long) DUK_HOBJECT_GET_ASIZE(obj), - (long) DUK_HOBJECT_GET_HSIZE(obj), - (void *) new_p, - (long) new_e_size_adjusted, - (long) new_e_next, - (long) new_a_size, - (long) new_h_size, - (long) abandon_array, - (long) new_e_size)); + DUK_DD(DUK_DDPRINT( + "resized hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " + "{p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", + (void *) obj, + (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)), + (long) new_alloc_size, + (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), + (long) DUK_HOBJECT_GET_ESIZE(obj), + (long) DUK_HOBJECT_GET_ENEXT(obj), + (long) DUK_HOBJECT_GET_ASIZE(obj), + (long) DUK_HOBJECT_GET_HSIZE(obj), + (void *) new_p, + (long) new_e_size_adjusted, + (long) new_e_next, + (long) new_a_size, + (long) new_h_size, + (long) abandon_array, + (long) new_e_size)); /* * All done, switch properties ('p') allocation to new one. */ - DUK_FREE_CHECKED(thr, DUK_HOBJECT_GET_PROPS(thr->heap, obj)); /* NULL obj->p is OK */ + DUK_FREE_CHECKED(thr, DUK_HOBJECT_GET_PROPS(thr->heap, obj)); /* NULL obj->p is OK */ DUK_HOBJECT_SET_PROPS(thr->heap, obj, new_p); DUK_HOBJECT_SET_ESIZE(obj, new_e_size_adjusted); DUK_HOBJECT_SET_ENEXT(obj, new_e_next); @@ -1047,11 +1080,11 @@ * unwind. */ - abandon_error: - alloc_failed: +abandon_error: +alloc_failed: DUK_D(DUK_DPRINT("object property table resize failed")); - DUK_FREE_CHECKED(thr, new_p); /* OK for NULL. */ + DUK_FREE_CHECKED(thr, new_p); /* OK for NULL. */ thr->heap->pf_prevent_count--; thr->heap->ms_base_flags = prev_ms_base_flags; @@ -1068,9 +1101,7 @@ * Helpers to resize properties allocation on specific needs. */ -DUK_INTERNAL void duk_hobject_resize_entrypart(duk_hthread *thr, - duk_hobject *obj, - duk_uint32_t new_e_size) { +DUK_INTERNAL void duk_hobject_resize_entrypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_e_size) { duk_uint32_t old_e_size; duk_uint32_t new_a_size; duk_uint32_t new_h_size; @@ -1094,7 +1125,7 @@ /* Grow entry part allocation for one additional entry. */ DUK_LOCAL void duk__grow_props_for_new_entry_item(duk_hthread *thr, duk_hobject *obj) { - duk_uint32_t old_e_used; /* actually used, non-NULL entries */ + duk_uint32_t old_e_used; /* actually used, non-NULL entries */ duk_uint32_t new_e_size_minimum; duk_uint32_t new_e_size; duk_uint32_t new_a_size; @@ -1156,7 +1187,7 @@ new_h_size = DUK_HOBJECT_GET_HSIZE(obj); new_a_size_minimum = highest_arr_idx + 1; new_a_size = highest_arr_idx + duk__get_min_grow_a(highest_arr_idx); - DUK_ASSERT(new_a_size >= highest_arr_idx + 1); /* duk__get_min_grow_a() is always >= 1 */ + DUK_ASSERT(new_a_size >= highest_arr_idx + 1); /* duk__get_min_grow_a() is always >= 1 */ #if defined(DUK_USE_OBJSIZES16) if (new_e_size > DUK_UINT16_MAX) { @@ -1188,7 +1219,7 @@ duk_uint32_t new_e_size; duk_uint32_t new_a_size; duk_uint32_t new_h_size; - duk_uint32_t e_used; /* actually used, non-NULL keys */ + duk_uint32_t e_used; /* actually used, non-NULL keys */ duk_uint32_t a_used; duk_uint32_t a_size; @@ -1233,8 +1264,13 @@ DUK_DD(DUK_DDPRINT("abandon array part for hobject %p, " "array stats before: e_used=%ld, a_used=%ld, a_size=%ld; " "resize to e_size=%ld, a_size=%ld, h_size=%ld", - (void *) obj, (long) e_used, (long) a_used, (long) a_size, - (long) new_e_size, (long) new_a_size, (long) new_h_size)); + (void *) obj, + (long) e_used, + (long) a_used, + (long) a_size, + (long) new_e_size, + (long) new_a_size, + (long) new_h_size)); duk_hobject_realloc_props(thr, obj, new_e_size, new_a_size, new_h_size, 1); } @@ -1252,9 +1288,9 @@ */ DUK_INTERNAL void duk_hobject_compact_props(duk_hthread *thr, duk_hobject *obj) { - duk_uint32_t e_size; /* currently used -> new size */ - duk_uint32_t a_size; /* currently required */ - duk_uint32_t a_used; /* actually used */ + duk_uint32_t e_size; /* currently used -> new size */ + duk_uint32_t a_size; /* currently required */ + duk_uint32_t a_used; /* actually used */ duk_uint32_t h_size; duk_bool_t abandon_array; @@ -1273,13 +1309,17 @@ DUK_DD(DUK_DDPRINT("compacting hobject, used e keys %ld, used a keys %ld, min a size %ld, " "resized array density would be: %ld/%ld = %lf", - (long) e_size, (long) a_used, (long) a_size, - (long) a_used, (long) a_size, + (long) e_size, + (long) a_used, + (long) a_size, + (long) a_used, + (long) a_size, (double) a_used / (double) a_size)); if (duk__abandon_array_density_check(a_used, a_size)) { DUK_DD(DUK_DDPRINT("decided to abandon array during compaction, a_used=%ld, a_size=%ld", - (long) a_used, (long) a_size)); + (long) a_used, + (long) a_size)); abandon_array = 1; e_size += a_used; a_size = 0; @@ -1299,7 +1339,10 @@ #endif DUK_DD(DUK_DDPRINT("compacting hobject -> new e_size %ld, new a_size=%ld, new h_size=%ld, abandon_array=%ld", - (long) e_size, (long) a_size, (long) h_size, (long) abandon_array)); + (long) e_size, + (long) a_size, + (long) h_size, + (long) abandon_array)); duk_hobject_realloc_props(thr, obj, e_size, a_size, h_size, abandon_array); } @@ -1314,15 +1357,15 @@ * but there is no hash part, h_idx is set to -1. */ -DUK_INTERNAL duk_bool_t duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx) { +DUK_INTERNAL duk_bool_t +duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx) { DUK_ASSERT(obj != NULL); DUK_ASSERT(key != NULL); DUK_ASSERT(e_idx != NULL); DUK_ASSERT(h_idx != NULL); DUK_UNREF(heap); - if (DUK_LIKELY(DUK_HOBJECT_GET_HSIZE(obj) == 0)) - { + if (DUK_LIKELY(DUK_HOBJECT_GET_HSIZE(obj) == 0)) { /* Linear scan: more likely because most objects are small. * This is an important fast path. * @@ -1344,8 +1387,7 @@ } } #if defined(DUK_USE_HOBJECT_HASH_PART) - else - { + else { /* hash lookup */ duk_uint32_t n; duk_uint32_t i, step; @@ -1358,40 +1400,38 @@ n = DUK_HOBJECT_GET_HSIZE(obj); mask = n - 1; i = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { duk_uint32_t t; - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HOBJECT_GET_HSIZE(obj)); t = h_basei; DUK_ASSERT(t == DUK__HASH_UNUSED || t == DUK__HASH_DELETED || - (t < DUK_HOBJECT_GET_ESIZE(obj))); /* t >= 0 always true, unsigned */ + (t < DUK_HOBJECT_GET_ESIZE(obj))); /* t >= 0 always true, unsigned */ if (t == DUK__HASH_UNUSED) { break; } else if (t == DUK__HASH_DELETED) { - DUK_DDD(DUK_DDDPRINT("lookup miss (deleted) i=%ld, t=%ld", - (long) i, (long) t)); + DUK_DDD(DUK_DDDPRINT("lookup miss (deleted) i=%ld, t=%ld", (long) i, (long) t)); } else { DUK_ASSERT(t < DUK_HOBJECT_GET_ESIZE(obj)); if (DUK_HOBJECT_E_GET_KEY(heap, obj, t) == key) { - DUK_DDD(DUK_DDDPRINT("lookup hit i=%ld, t=%ld -> key %p", - (long) i, (long) t, (void *) key)); + DUK_DDD( + DUK_DDDPRINT("lookup hit i=%ld, t=%ld -> key %p", (long) i, (long) t, (void *) key)); *e_idx = (duk_int_t) t; *h_idx = (duk_int_t) i; return 1; } - DUK_DDD(DUK_DDDPRINT("lookup miss i=%ld, t=%ld", - (long) i, (long) t)); + DUK_DDD(DUK_DDDPRINT("lookup miss i=%ld, t=%ld", (long) i, (long) t)); } i = (i + step) & mask; /* Guaranteed to finish (hash is larger than #props). */ } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* Not found, leave e_idx and h_idx unset. */ return 0; @@ -1420,7 +1460,10 @@ } /* For internal use: get non-accessor entry value and attributes */ -DUK_INTERNAL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_uint_t *out_attrs) { +DUK_INTERNAL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, + duk_hobject *obj, + duk_hstring *key, + duk_uint_t *out_attrs) { duk_int_t e_idx; duk_int_t h_idx; @@ -1505,14 +1548,15 @@ n = DUK_HOBJECT_GET_HSIZE(obj); mask = n - 1; i = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { duk_uint32_t t = h_basei; if (t == DUK__HASH_UNUSED || t == DUK__HASH_DELETED) { DUK_DDD(DUK_DDDPRINT("duk__hobject_alloc_entry_checked() inserted key into hash part, %ld -> %ld", - (long) i, (long) idx)); - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + (long) i, + (long) idx)); + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HOBJECT_GET_HSIZE(obj)); DUK_ASSERT_DISABLE(idx >= 0); DUK_ASSERT(idx < DUK_HOBJECT_GET_ESIZE(obj)); @@ -1525,7 +1569,7 @@ /* Guaranteed to finish (hash is larger than #props). */ } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* Note: we could return the hash index here too, but it's not * needed right now. @@ -1633,8 +1677,12 @@ DUK_DDD(DUK_DDDPRINT("arguments map lookup: thr=%p, obj=%p, key=%p, temp_desc=%p " "(obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) temp_desc, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) temp_desc, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); if (!duk_hobject_get_own_propdesc(thr, obj, DUK_HTHREAD_STRING_INT_MAP(thr), temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { DUK_DDD(DUK_DDDPRINT("-> no 'map'")); @@ -1643,7 +1691,7 @@ map = duk_require_hobject(thr, -1); DUK_ASSERT(map != NULL); - duk_pop_unsafe(thr); /* map is reachable through obj */ + duk_pop_unsafe(thr); /* map is reachable through obj */ if (!duk_hobject_get_own_propdesc(thr, map, key, temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { DUK_DDD(DUK_DDDPRINT("-> 'map' exists, but key not in map")); @@ -1653,29 +1701,32 @@ /* ... varname */ DUK_DDD(DUK_DDDPRINT("-> 'map' exists, and contains key, key is mapped to argument/variable binding %!T", (duk_tval *) duk_get_tval(thr, -1))); - DUK_ASSERT(duk_is_string(thr, -1)); /* guaranteed when building arguments */ + DUK_ASSERT(duk_is_string(thr, -1)); /* guaranteed when building arguments */ /* get varenv for varname (callee's declarative lexical environment) */ rc = duk_hobject_get_own_propdesc(thr, obj, DUK_HTHREAD_STRING_INT_VARENV(thr), temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); - DUK_ASSERT(rc != 0); /* arguments MUST have an initialized lexical environment reference */ + DUK_ASSERT(rc != 0); /* arguments MUST have an initialized lexical environment reference */ varenv = duk_require_hobject(thr, -1); DUK_ASSERT(varenv != NULL); - duk_pop_unsafe(thr); /* varenv remains reachable through 'obj' */ + duk_pop_unsafe(thr); /* varenv remains reachable through 'obj' */ DUK_DDD(DUK_DDDPRINT("arguments varenv is: %!dO", (duk_heaphdr *) varenv)); /* success: leave varname in stack */ *out_map = map; *out_varenv = varenv; - return 1; /* ... varname */ + return 1; /* ... varname */ } /* Lookup 'key' from arguments internal 'map', and leave replacement value * on stack top if mapped (and return non-zero). * Used in E5 Section 10.6 algorithm for GetOwnProperty (used by Get). */ -DUK_LOCAL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc) { +DUK_LOCAL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc) { duk_hobject *map; duk_hobject *varenv; duk_hstring *varname; @@ -1691,7 +1742,7 @@ varname = duk_require_hstring(thr, -1); DUK_ASSERT(varname != NULL); - duk_pop_unsafe(thr); /* varname is still reachable */ + duk_pop_unsafe(thr); /* varname is still reachable */ DUK_DDD(DUK_DDDPRINT("arguments object automatic getvar for a bound variable; " "key=%!O, varname=%!O", @@ -1712,7 +1763,11 @@ * Used in E5 Section 10.6 algorithm for DefineOwnProperty (used by Put). * Assumes stack top contains 'put' value (which is NOT popped). */ -DUK_LOCAL void duk__check_arguments_map_for_put(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc, duk_bool_t throw_flag) { +DUK_LOCAL void duk__check_arguments_map_for_put(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc, + duk_bool_t throw_flag) { duk_hobject *map; duk_hobject *varenv; duk_hstring *varname; @@ -1728,7 +1783,7 @@ varname = duk_require_hstring(thr, -1); DUK_ASSERT(varname != NULL); - duk_pop_unsafe(thr); /* varname is still reachable */ + duk_pop_unsafe(thr); /* varname is still reachable */ DUK_DDD(DUK_DDDPRINT("arguments object automatic putvar for a bound variable; " "key=%!O, varname=%!O, value=%!T", @@ -1767,15 +1822,14 @@ map = duk_require_hobject(thr, -1); DUK_ASSERT(map != NULL); - duk_pop_unsafe(thr); /* map is reachable through obj */ + duk_pop_unsafe(thr); /* map is reachable through obj */ - DUK_DDD(DUK_DDDPRINT("-> have 'map', delete key %!O from map (if exists)); ignore result", - (duk_heaphdr *) key)); + DUK_DDD(DUK_DDDPRINT("-> have 'map', delete key %!O from map (if exists)); ignore result", (duk_heaphdr *) key)); /* Note: no recursion issue, we can trust 'map' to behave */ DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(map)); DUK_DDD(DUK_DDDPRINT("map before deletion: %!O", (duk_heaphdr *) map)); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ DUK_DDD(DUK_DDDPRINT("map after deletion: %!O", (duk_heaphdr *) map)); } @@ -1818,14 +1872,24 @@ * accessor properties later, this would need to change. */ -DUK_LOCAL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_uint32_t arr_idx, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_LOCAL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_uint32_t arr_idx, + duk_propdesc *out_desc, + duk_small_uint_t flags) { duk_tval *tv; DUK_DDD(DUK_DDDPRINT("duk_hobject_get_own_propdesc: thr=%p, obj=%p, key=%p, out_desc=%p, flags=%lx, " "arr_idx=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) out_desc, - (long) flags, (long) arr_idx, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) out_desc, + (long) flags, + (long) arr_idx, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -1899,14 +1963,13 @@ duk_push_tval(thr, tv); } /* implicit attributes */ - out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_CONFIGURABLE | - DUK_PROPDESC_FLAG_ENUMERABLE; + out_desc->flags = + DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE | DUK_PROPDESC_FLAG_ENUMERABLE; out_desc->get = NULL; out_desc->set = NULL; out_desc->e_idx = -1; out_desc->h_idx = -1; - out_desc->a_idx = (duk_int_t) arr_idx; /* XXX: limit 2G due to being signed */ + out_desc->a_idx = (duk_int_t) arr_idx; /* XXX: limit 2G due to being signed */ goto prop_found; } } @@ -1927,7 +1990,8 @@ duk_harray *a; DUK_DDD(DUK_DDDPRINT("array object exotic property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + (duk_heaphdr *) key, + (long) arr_idx)); a = (duk_harray *) obj; DUK_HARRAY_ASSERT_VALID(a); @@ -1949,11 +2013,12 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } else if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj)) { DUK_DDD(DUK_DDDPRINT("string object exotic property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + (duk_heaphdr *) key, + (long) arr_idx)); /* XXX: charlen; avoid multiple lookups? */ @@ -1968,9 +2033,9 @@ DUK_DDD(DUK_DDDPRINT("-> found, array index inside string")); if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_push_hstring(thr, h_val); - duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ + duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ } - out_desc->flags = DUK_PROPDESC_FLAG_ENUMERABLE | /* E5 Section 15.5.5.2 */ + out_desc->flags = DUK_PROPDESC_FLAG_ENUMERABLE | /* E5 Section 15.5.5.2 */ DUK_PROPDESC_FLAG_VIRTUAL; out_desc->get = NULL; out_desc->set = NULL; @@ -1979,7 +2044,7 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } else { /* index is above internal string length -> property is fully normal */ DUK_DDD(DUK_DDDPRINT("array index outside string -> normal property")); @@ -1994,7 +2059,7 @@ if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h_val)); } - out_desc->flags = DUK_PROPDESC_FLAG_VIRTUAL; /* E5 Section 15.5.5.1 */ + out_desc->flags = DUK_PROPDESC_FLAG_VIRTUAL; /* E5 Section 15.5.5.1 */ out_desc->get = NULL; out_desc->set = NULL; out_desc->e_idx = -1; @@ -2002,7 +2067,7 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -2013,8 +2078,7 @@ h_bufobj = (duk_hbufobj *) obj; DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); - DUK_DDD(DUK_DDDPRINT("bufobj property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + DUK_DDD(DUK_DDDPRINT("bufobj property get for key: %!O, arr_idx: %ld", (duk_heaphdr *) key, (long) arr_idx)); if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { DUK_DDD(DUK_DDDPRINT("array index exists")); @@ -2023,21 +2087,22 @@ * length downshift won't. */ if (arr_idx < (h_bufobj->length >> h_bufobj->shift)) { - byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_uint8_t *data; - if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { - data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + h_bufobj->offset + byte_off; + if (h_bufobj->buf != NULL && + DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { + data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + + h_bufobj->offset + byte_off; duk_hbufobj_push_validated_read(thr, h_bufobj, data, elem_size); } else { DUK_D(DUK_DPRINT("bufobj access out of underlying buffer, ignoring (read zero)")); duk_push_uint(thr, 0); } } - out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_VIRTUAL; + out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_VIRTUAL; if (DUK_HOBJECT_GET_CLASS_NUMBER(obj) != DUK_HOBJECT_CLASS_ARRAYBUFFER) { /* ArrayBuffer indices are non-standard and are * non-enumerable to avoid their serialization. @@ -2051,7 +2116,8 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be e.g. arguments exotic, since exotic 'traits' are mutually exclusive */ + goto prop_found_noexotic; /* cannot be e.g. arguments exotic, since exotic 'traits' are mutually + exclusive */ } else { /* index is above internal buffer length -> property is fully normal */ DUK_DDD(DUK_DDDPRINT("array index outside buffer -> normal property")); @@ -2073,10 +2139,10 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Array properties have exotic behavior but they are concrete, * so no special handling here. @@ -2090,7 +2156,7 @@ * Not found as concrete or virtual. */ - prop_not_found: +prop_not_found: DUK_DDD(DUK_DDDPRINT("-> not found (virtual, entry part, or array part)")); DUK_STATS_INC(thr->heap, stats_getownpropdesc_miss); return 0; @@ -2102,7 +2168,7 @@ * description of GetOwnProperty variant for arguments. */ - prop_found: +prop_found: DUK_DDD(DUK_DDDPRINT("-> property found, checking for arguments exotic post-behavior")); /* Notes: @@ -2112,8 +2178,7 @@ * DUK_GETDESC_FLAG_PUSH_VALUE is not set. */ - if (DUK_UNLIKELY(DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && - arr_idx != DUK__NO_ARRAY_INDEX && + if (DUK_UNLIKELY(DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && arr_idx != DUK__NO_ARRAY_INDEX && (flags & DUK_GETDESC_FLAG_PUSH_VALUE))) { duk_propdesc temp_desc; @@ -2139,12 +2204,13 @@ } } - prop_found_noexotic: +prop_found_noexotic: DUK_STATS_INC(thr->heap, stats_getownpropdesc_hit); return 1; } -DUK_INTERNAL duk_bool_t duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_INTERNAL duk_bool_t +duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { DUK_ASSERT(thr != NULL); DUK_ASSERT(obj != NULL); DUK_ASSERT(key != NULL); @@ -2173,7 +2239,8 @@ * pointers. */ -DUK_LOCAL duk_bool_t duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_LOCAL duk_bool_t +duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { duk_hobject *curr; duk_uint32_t arr_idx; duk_uint_t sanity; @@ -2191,9 +2258,14 @@ DUK_DDD(DUK_DDDPRINT("duk__get_propdesc: thr=%p, obj=%p, key=%p, out_desc=%p, flags=%lx, " "arr_idx=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) out_desc, - (long) flags, (long) arr_idx, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) out_desc, + (long) flags, + (long) arr_idx, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); curr = obj; DUK_ASSERT(curr != NULL); @@ -2253,11 +2325,8 @@ DUK_UNREF(thr); - if (!(DUK_HOBJECT_HAS_ARRAY_PART(obj) && - !DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && - !DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj) && - !DUK_HOBJECT_IS_BUFOBJ(obj) && - !DUK_HOBJECT_IS_PROXY(obj))) { + if (!(DUK_HOBJECT_HAS_ARRAY_PART(obj) && !DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && !DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj) && + !DUK_HOBJECT_IS_BUFOBJ(obj) && !DUK_HOBJECT_IS_PROXY(obj))) { /* Must have array part and no conflicting exotic behaviors. * Doesn't need to have array special behavior, e.g. Arguments * object has array part. @@ -2275,7 +2344,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { DUK_DDD(DUK_DDDPRINT("key is not a number")); @@ -2309,18 +2378,19 @@ return NULL; } -DUK_LOCAL duk_bool_t duk__putprop_shallow_fastpath_array_tval(duk_hthread *thr, duk_hobject *obj, duk_tval *tv_key, duk_tval *tv_val) { +DUK_LOCAL duk_bool_t duk__putprop_shallow_fastpath_array_tval(duk_hthread *thr, + duk_hobject *obj, + duk_tval *tv_key, + duk_tval *tv_val) { duk_tval *tv; duk_harray *a; duk_uint32_t idx; duk_uint32_t old_len, new_len; - if (!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj) && - DUK_HOBJECT_HAS_ARRAY_PART(obj) && - DUK_HOBJECT_HAS_EXTENSIBLE(obj))) { + if (!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj) && DUK_HOBJECT_HAS_ARRAY_PART(obj) && DUK_HOBJECT_HAS_EXTENSIBLE(obj))) { return 0; } - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures */ a = (duk_harray *) obj; DUK_HARRAY_ASSERT_VALID(a); @@ -2330,7 +2400,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { DUK_DDD(DUK_DDDPRINT("key is not a number")); @@ -2342,7 +2412,7 @@ * because 0xffffffffUL will never be inside object 'a_size'. */ - if (idx >= DUK_HOBJECT_GET_ASIZE(obj)) { /* for resizing of array part, use slow path */ + if (idx >= DUK_HOBJECT_GET_ASIZE(obj)) { /* for resizing of array part, use slow path */ return 0; } DUK_ASSERT(idx != 0xffffffffUL); @@ -2353,7 +2423,8 @@ if (idx >= old_len) { DUK_DDD(DUK_DDDPRINT("write new array entry requires length update " "(arr_idx=%ld, old_len=%ld)", - (long) idx, (long) old_len)); + (long) idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a)) { /* The correct behavior here is either a silent error * or a TypeError, depending on strictness. Fall back @@ -2367,12 +2438,12 @@ } tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects */ DUK_DDD(DUK_DDDPRINT("array fast path success for index %ld", (long) idx)); return 1; } -#endif /* DUK_USE_ARRAY_PROP_FASTPATH */ +#endif /* DUK_USE_ARRAY_PROP_FASTPATH */ /* * Fast path for bufobj getprop/putprop @@ -2399,7 +2470,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { return 0; @@ -2416,7 +2487,7 @@ } DUK_ASSERT(idx != DUK__NO_ARRAY_INDEX); - byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { @@ -2429,7 +2500,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) DUK_LOCAL duk_bool_t duk__putprop_fastpath_bufobj_tval(duk_hthread *thr, duk_hobject *obj, duk_tval *tv_key, duk_tval *tv_val) { @@ -2439,11 +2510,10 @@ duk_small_uint_t elem_size; duk_uint8_t *data; - if (!(DUK_HOBJECT_IS_BUFOBJ(obj) && - DUK_TVAL_IS_NUMBER(tv_val))) { + if (!(DUK_HOBJECT_IS_BUFOBJ(obj) && DUK_TVAL_IS_NUMBER(tv_val))) { return 0; } - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures; rom objects are never bufobjs now */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures; rom objects are never bufobjs now */ h_bufobj = (duk_hbufobj *) obj; if (!DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { @@ -2455,7 +2525,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { return 0; @@ -2472,7 +2542,7 @@ } DUK_ASSERT(idx != DUK__NO_ARRAY_INDEX); - byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); /* Value is required to be a number in the fast path so there @@ -2491,7 +2561,7 @@ duk_pop_unsafe(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * GETPROP: ECMAScript property read. @@ -2507,8 +2577,11 @@ duk_uint_t sanity; DUK_DDD(DUK_DDDPRINT("getprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -2545,8 +2618,11 @@ #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot read property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot read property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); break; @@ -2576,7 +2652,7 @@ pop_count = 0; } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object string, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -2585,15 +2661,15 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object string, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { duk_pop_n_unsafe(thr, pop_count); duk_push_hstring(thr, h); - duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ + duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ DUK_STATS_INC(thr->heap, stats_getprop_stringidx); DUK_DDD(DUK_DDDPRINT("-> %!T (base is string, key is an index inside string length " @@ -2610,12 +2686,13 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object string, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { - duk_pop_unsafe(thr); /* key -> */ - duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); /* -> res */ + duk_pop_unsafe(thr); /* key -> */ + duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); /* -> res */ DUK_STATS_INC(thr->heap, stats_getprop_stringlen); DUK_DDD(DUK_DDDPRINT("-> %!T (base is string, key is 'length' after coercion -> " @@ -2626,7 +2703,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a string, start lookup from string prototype")); curr = thr->builtinsDUK_BIDX_STRING_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_OBJECT: { @@ -2671,9 +2748,9 @@ /* -> ... trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'get' for key %!T", (duk_tval *) tv_key)); DUK_STATS_INC(thr->heap, stats_getprop_proxy); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ - duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ + duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ duk_call_method(thr, 3 /*nargs*/); /* Target object must be checked for a conflicting @@ -2683,25 +2760,27 @@ DUK_ASSERT(key != NULL); if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { - duk_tval *tv_hook = duk_require_tval(thr, -3); /* value from hook */ - duk_tval *tv_targ = duk_require_tval(thr, -1); /* value from target */ + duk_tval *tv_hook = duk_require_tval(thr, -3); /* value from hook */ + duk_tval *tv_targ = duk_require_tval(thr, -1); /* value from target */ duk_bool_t datadesc_reject; duk_bool_t accdesc_reject; DUK_DDD(DUK_DDDPRINT("proxy 'get': target has matching property %!O, check for " "conflicting property; tv_hook=%!T, tv_targ=%!T, desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (duk_tval *) tv_hook, (duk_tval *) tv_targ, + (duk_heaphdr *) key, + (duk_tval *) tv_hook, + (duk_tval *) tv_targ, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (void *) desc.get, + (void *) desc.set)); datadesc_reject = !(desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && !(desc.flags & DUK_PROPDESC_FLAG_WRITABLE) && !duk_js_samevalue(tv_hook, tv_targ); accdesc_reject = (desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && - !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && - (desc.get == NULL) && + !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && (desc.get == NULL) && !DUK_TVAL_IS_UNDEFINED(tv_hook); if (datadesc_reject || accdesc_reject) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); @@ -2712,13 +2791,13 @@ } else { duk_pop_unsafe(thr); } - return 1; /* return value */ + return 1; /* return value */ } - curr = h_target; /* resume lookup from target */ + curr = h_target; /* resume lookup from target */ DUK_TVAL_SET_OBJECT(tv_obj, curr); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ if (DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(curr)) { arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); @@ -2733,11 +2812,11 @@ /* no need for 'caller' post-check, because 'key' must be an array index */ - duk_remove_m2(thr); /* key result -> result */ + duk_remove_m2(thr); /* key result -> result */ return 1; } - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } break; } @@ -2759,10 +2838,9 @@ arr_idx = duk__tval_fastint_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path fastint; arr_idx %ld", (long) arr_idx)); pop_count = 0; - } - else + } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -2771,12 +2849,12 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { duk_pop_n_unsafe(thr, pop_count); duk_push_uint(thr, ((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h))arr_idx); DUK_STATS_INC(thr->heap, stats_getprop_bufferidx); @@ -2794,12 +2872,13 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { - duk_pop_unsafe(thr); /* key -> */ - duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h)); /* -> res */ + duk_pop_unsafe(thr); /* key -> */ + duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h)); /* -> res */ DUK_STATS_INC(thr->heap, stats_getprop_bufferlen); DUK_DDD(DUK_DDDPRINT("-> %!T (base is buffer, key is 'length' " @@ -2810,7 +2889,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a buffer, start lookup from Uint8Array prototype")); curr = thr->builtinsDUK_BIDX_UINT8ARRAY_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_POINTER: { @@ -2847,7 +2926,7 @@ * Property lookup */ - lookup: +lookup: /* key (coerced) */ DUK_ASSERT(curr != NULL); DUK_ASSERT(key != NULL); @@ -2862,25 +2941,23 @@ /* accessor with defined getter */ DUK_ASSERT((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0); - duk_pop_unsafe(thr); /* key undefined -> key */ + duk_pop_unsafe(thr); /* key undefined -> key */ duk_push_hobject(thr, desc.get); - duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ + duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ #if defined(DUK_USE_NONSTD_GETTER_KEY_ARGUMENT) duk_dup_m3(thr); - duk_call_method(thr, 1); /* key getter this key -> key retval */ + duk_call_method(thr, 1); /* key getter this key -> key retval */ #else - duk_call_method(thr, 0); /* key getter this -> key retval */ + duk_call_method(thr, 0); /* key getter this -> key retval */ #endif } else { /* key value or key undefined */ /* data property or accessor without getter */ - DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || - (desc.get == NULL)); + DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || (desc.get == NULL)); /* if accessor without getter, return value is undefined */ - DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || - duk_is_undefined(thr, -1)); + DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || duk_is_undefined(thr, -1)); /* Note: for an accessor without getter, falling through to * check for "caller" exotic behavior is unnecessary as @@ -2889,9 +2966,9 @@ */ } - goto found; /* key result */ + goto found; /* key result */ - next_in_chain: + next_in_chain: /* XXX: option to pretend property doesn't exist if sanity limit is * hit might be useful. */ @@ -2906,7 +2983,7 @@ * Not found */ - duk_to_undefined(thr, -1); /* key -> undefined (default value) */ + duk_to_undefined(thr, -1); /* key -> undefined (default value) */ DUK_DDD(DUK_DDDPRINT("-> %!T (not found)", (duk_tval *) duk_get_tval(thr, -1))); return 0; @@ -2915,7 +2992,7 @@ * Found; post-processing (Function and arguments objects) */ - found: +found: /* key result */ #if !defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) @@ -2945,13 +3022,11 @@ * This exotic behavior is disabled when the non-standard 'caller' property * is enabled, as it conflicts with the free use of 'caller'. */ - if (key == DUK_HTHREAD_STRING_CALLER(thr) && - DUK_TVAL_IS_OBJECT(tv_obj)) { + if (key == DUK_HTHREAD_STRING_CALLER(thr) && DUK_TVAL_IS_OBJECT(tv_obj)) { duk_hobject *orig = DUK_TVAL_GET_OBJECT(tv_obj); DUK_ASSERT(orig != NULL); - if (DUK_HOBJECT_IS_NONBOUND_FUNCTION(orig) || - DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { + if (DUK_HOBJECT_IS_NONBOUND_FUNCTION(orig) || DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { duk_hobject *h; /* XXX: The TypeError is currently not applied to bound @@ -2962,19 +3037,17 @@ */ DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(orig)); - h = duk_get_hobject(thr, -1); /* NULL if not an object */ - if (h && - DUK_HOBJECT_IS_FUNCTION(h) && - DUK_HOBJECT_HAS_STRICT(h)) { + h = duk_get_hobject(thr, -1); /* NULL if not an object */ + if (h && DUK_HOBJECT_IS_FUNCTION(h) && DUK_HOBJECT_HAS_STRICT(h)) { /* XXX: sufficient to check 'strict', assert for 'is function' */ DUK_ERROR_TYPE(thr, DUK_STR_STRICT_CALLER_READ); DUK_WO_NORETURN(return 0;); } } } -#endif /* !DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ +#endif /* !DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ - duk_remove_m2(thr); /* key result -> result */ + duk_remove_m2(thr); /* key result -> result */ DUK_DDD(DUK_DDDPRINT("-> %!T (found)", (duk_tval *) duk_get_tval(thr, -1))); return 1; @@ -2996,8 +3069,11 @@ duk_propdesc desc; DUK_DDD(DUK_DDDPRINT("hasprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -3069,8 +3145,8 @@ if (duk__proxy_check_prop(thr, obj, DUK_STRIDX_HAS, tv_key, &h_target)) { /* ... key trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'has' for key %!T", (duk_tval *) tv_key)); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ duk_call_method(thr, 2 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { @@ -3078,39 +3154,42 @@ * non-configurable property. */ - if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push + value */ DUK_DDD(DUK_DDDPRINT("proxy 'has': target has matching property %!O, check for " "conflicting property; desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (duk_heaphdr *) key, + (unsigned long) desc.flags, + (void *) desc.get, + (void *) desc.set)); /* XXX: Extensibility check for target uses IsExtensible(). If we * implemented the isExtensible trap and didn't reject proxies as * proxy targets, it should be respected here. */ - if (!((desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && /* property is configurable and */ - DUK_HOBJECT_HAS_EXTENSIBLE(h_target))) { /* ... target is extensible */ + if (!((desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && /* property is configurable and */ + DUK_HOBJECT_HAS_EXTENSIBLE(h_target))) { /* ... target is extensible */ DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); } } } - duk_pop_unsafe(thr); /* key -> */ + duk_pop_unsafe(thr); /* key -> */ return tmp_bool; } - obj = h_target; /* resume check from proxy target */ + obj = h_target; /* resume check from proxy target */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* XXX: inline into a prototype walking loop? */ - rc = duk__get_propdesc(thr, obj, key, &desc, 0 /*flags*/); /* don't push value */ + rc = duk__get_propdesc(thr, obj, key, &desc, 0 /*flags*/); /* don't push value */ /* fall through */ - pop_and_return: - duk_pop_unsafe(thr); /* key -> */ +pop_and_return: + duk_pop_unsafe(thr); /* key -> */ return rc; } @@ -3136,7 +3215,7 @@ DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); - return duk__get_propdesc(thr, obj, key, &dummy, DUK_GETDESC_FLAG_IGNORE_PROTOLOOP); /* don't push value */ + return duk__get_propdesc(thr, obj, key, &dummy, DUK_GETDESC_FLAG_IGNORE_PROTOLOOP); /* don't push value */ } /* @@ -3168,16 +3247,16 @@ } return (duk_uint32_t) fi; } -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ /* When fastints are not enabled, the most interesting case is any * number. */ if (DUK_TVAL_IS_DOUBLE(tv)) { d = DUK_TVAL_GET_NUMBER(tv); } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ else -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ { /* In all other cases, and when doing a size optimized build, * fall back to the comprehensive handler. @@ -3195,7 +3274,7 @@ return res; - fail_range: +fail_range: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARRAY_LENGTH); DUK_WO_NORETURN(return 0;); } @@ -3223,7 +3302,8 @@ DUK_DDD(DUK_DDDPRINT("new array length smaller than old (%ld -> %ld), " "probably need to remove elements", - (long) old_len, (long) new_len)); + (long) old_len, + (long) new_len)); /* * New length is smaller than old length, need to delete properties above @@ -3269,7 +3349,7 @@ while (i > new_len) { i--; tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, i); - DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ } *out_result_len = new_len; @@ -3304,19 +3384,22 @@ continue; } - DUK_ASSERT(DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ + DUK_ASSERT( + DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); - DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ + DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ if (arr_idx < new_len) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is array index %ld, below new_len", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } if (DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is a relevant array index %ld, but configurable", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } @@ -3324,17 +3407,19 @@ if (arr_idx >= target_len) { DUK_DDD(DUK_DDDPRINT("entry at index %ld has arr_idx %ld, is not configurable, " "update target_len %ld -> %ld", - (long) i, (long) arr_idx, (long) target_len, + (long) i, + (long) arr_idx, + (long) target_len, (long) (arr_idx + 1))); target_len = arr_idx + 1; } } - skip_stage1: + skip_stage1: /* stage 2: delete configurable entries above target length */ - DUK_DDD(DUK_DDDPRINT("old_len=%ld, new_len=%ld, target_len=%ld", - (long) old_len, (long) new_len, (long) target_len)); + DUK_DDD( + DUK_DDDPRINT("old_len=%ld, new_len=%ld, target_len=%ld", (long) old_len, (long) new_len, (long) target_len)); DUK_DDD(DUK_DDDPRINT("array length write, no array part, stage 2: remove " "entries >= target_len")); @@ -3350,20 +3435,21 @@ continue; } - DUK_ASSERT(DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ + DUK_ASSERT( + DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); - DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ + DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ if (arr_idx < target_len) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is array index %ld, below target_len", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } - DUK_ASSERT(force_flag || DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)); /* stage 1 guarantees */ + DUK_ASSERT(force_flag || DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)); /* stage 1 guarantees */ - DUK_DDD(DUK_DDDPRINT("delete entry index %ld: key is array index %ld", - (long) i, (long) arr_idx)); + DUK_DDD(DUK_DDDPRINT("delete entry index %ld: key is array index %ld", (long) i, (long) arr_idx)); /* * Slow delete, but we don't care as we're already in a very slow path. @@ -3494,11 +3580,12 @@ * (We currently make a copy of all of the input values to avoid issues.) */ -DUK_INTERNAL duk_bool_t duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag) { +DUK_INTERNAL duk_bool_t +duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag) { duk_tval tv_obj_copy; duk_tval tv_key_copy; duk_tval tv_val_copy; - duk_hobject *orig = NULL; /* NULL if tv_obj is primitive */ + duk_hobject *orig = NULL; /* NULL if tv_obj is primitive */ duk_hobject *curr; duk_hstring *key = NULL; duk_propdesc desc; @@ -3507,12 +3594,18 @@ duk_bool_t rc; duk_int_t e_idx; duk_uint_t sanity; - duk_uint32_t new_array_length = 0; /* 0 = no update */ + duk_uint32_t new_array_length = 0; /* 0 = no update */ DUK_DDD(DUK_DDDPRINT("putprop: thr=%p, obj=%p, key=%p, val=%p, throw=%ld " "(obj -> %!T, key -> %!T, val -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, (void *) tv_val, - (long) throw_flag, (duk_tval *) tv_obj, (duk_tval *) tv_key, (duk_tval *) tv_val)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (void *) tv_val, + (long) throw_flag, + (duk_tval *) tv_obj, + (duk_tval *) tv_key, + (duk_tval *) tv_val)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -3547,13 +3640,15 @@ case DUK_TAG_UNDEFINED: case DUK_TAG_NULL: { /* Note: unconditional throw */ - DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject (object=%!iT)", - (duk_tval *) tv_obj)); + DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject (object=%!iT)", (duk_tval *) tv_obj)); #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot write property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot write property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); break; @@ -3587,14 +3682,13 @@ goto fail_not_writable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { goto fail_not_writable; } DUK_DDD(DUK_DDDPRINT("base object is a string, start lookup from string prototype")); curr = thr->builtinsDUK_BIDX_STRING_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_OBJECT: { @@ -3609,7 +3703,7 @@ */ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) orig)) { DUK_DD(DUK_DDPRINT("attempt to putprop on read-only target object")); - goto fail_not_writable_no_pop; /* Must avoid duk_pop() in exit path */ + goto fail_not_writable_no_pop; /* Must avoid duk_pop() in exit path */ } #endif @@ -3655,10 +3749,10 @@ /* -> ... trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'set' for key %!T", (duk_tval *) tv_key)); DUK_STATS_INC(thr->heap, stats_putprop_proxy); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ - duk_push_tval(thr, tv_val); /* V */ - duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ + duk_push_tval(thr, tv_val); /* V */ + duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ duk_call_method(thr, 4 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { @@ -3679,17 +3773,19 @@ DUK_DDD(DUK_DDDPRINT("proxy 'set': target has matching property %!O, check for " "conflicting property; tv_val=%!T, tv_targ=%!T, desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (duk_tval *) tv_val, (duk_tval *) tv_targ, + (duk_heaphdr *) key, + (duk_tval *) tv_val, + (duk_tval *) tv_targ, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (void *) desc.get, + (void *) desc.set)); datadesc_reject = !(desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && !(desc.flags & DUK_PROPDESC_FLAG_WRITABLE) && !duk_js_samevalue(tv_val, tv_targ); accdesc_reject = (desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && - !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && - (desc.set == NULL); + !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && (desc.set == NULL); if (datadesc_reject || accdesc_reject) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); @@ -3699,13 +3795,13 @@ } else { duk_pop_unsafe(thr); } - return 1; /* success */ + return 1; /* success */ } - orig = h_target; /* resume write to target */ + orig = h_target; /* resume write to target */ DUK_TVAL_SET_OBJECT(tv_obj, orig); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ curr = orig; break; @@ -3727,7 +3823,7 @@ pop_count = 0; } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -3736,12 +3832,12 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { duk_uint8_t *data; DUK_DDD(DUK_DDDPRINT("writing to buffer data at index %ld", (long) arr_idx)); data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); @@ -3753,8 +3849,7 @@ /* Buffer writes are often integers. */ if (DUK_TVAL_IS_FASTINT(tv_val)) { dataarr_idx = (duk_uint8_t) DUK_TVAL_GET_FASTINT_U32(tv_val); - } - else + } else #endif { duk_push_tval(thr, tv_val); @@ -3776,7 +3871,8 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { @@ -3785,7 +3881,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a buffer, start lookup from Uint8Array prototype")); curr = thr->builtinsDUK_BIDX_UINT8ARRAY_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_POINTER: { @@ -3820,7 +3916,7 @@ arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); DUK_ASSERT(key != NULL); - lookup: +lookup: /* * Check whether the property already exists in the prototype chain. @@ -3833,7 +3929,7 @@ DUK_ASSERT(curr != NULL); sanity = DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY; do { - if (!duk__get_own_propdesc_raw(thr, curr, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (!duk__get_own_propdesc_raw(thr, curr, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ goto next_in_chain; } @@ -3856,15 +3952,15 @@ goto fail_no_setter; } duk_push_hobject(thr, setter); - duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ - duk_push_tval(thr, tv_val); /* key setter this val */ + duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ + duk_push_tval(thr, tv_val); /* key setter this val */ #if defined(DUK_USE_NONSTD_SETTER_KEY_ARGUMENT) duk_dup_m4(thr); - duk_call_method(thr, 2); /* key setter this val key -> key retval */ + duk_call_method(thr, 2); /* key setter this val key -> key retval */ #else - duk_call_method(thr, 1); /* key setter this val -> key retval */ + duk_call_method(thr, 1); /* key setter this val -> key retval */ #endif - duk_pop_unsafe(thr); /* ignore retval -> key */ + duk_pop_unsafe(thr); /* ignore retval -> key */ goto success_no_arguments_exotic; } @@ -3884,11 +3980,13 @@ * new property to 'orig'. */ if (!DUK_HOBJECT_HAS_EXTENSIBLE(orig)) { - DUK_DD(DUK_DDPRINT("found existing inherited plain property, but original object is not extensible")); + DUK_DD( + DUK_DDPRINT("found existing inherited plain property, but original object is not extensible")); goto fail_not_extensible; } if (!(desc.flags & DUK_PROPDESC_FLAG_WRITABLE)) { - DUK_DD(DUK_DDPRINT("found existing inherited plain property, original object is extensible, but inherited property is not writable")); + DUK_DD(DUK_DDPRINT("found existing inherited plain property, original object is extensible, but " + "inherited property is not writable")); goto fail_not_writable; } DUK_DD(DUK_DDPRINT("put to new property, object extensible, inherited property found and is writable")); @@ -3900,7 +3998,8 @@ */ if (!(desc.flags & DUK_PROPDESC_FLAG_WRITABLE)) { - DUK_DD(DUK_DDPRINT("found existing own (non-inherited) plain property, but property is not writable")); + DUK_DD( + DUK_DDPRINT("found existing own (non-inherited) plain property, but property is not writable")); goto fail_not_writable; } if (desc.flags & DUK_PROPDESC_FLAG_VIRTUAL) { @@ -3917,18 +4016,19 @@ * Note: the helper has an unnecessary writability check * for 'length', we already know it is writable. */ - DUK_ASSERT(key == DUK_HTHREAD_STRING_LENGTH(thr)); /* only virtual array property */ + DUK_ASSERT(key == DUK_HTHREAD_STRING_LENGTH(thr)); /* only virtual array property */ - DUK_DDD(DUK_DDDPRINT("writing existing 'length' property to array exotic, invoke complex helper")); + DUK_DDD(DUK_DDDPRINT( + "writing existing 'length' property to array exotic, invoke complex helper")); /* XXX: the helper currently assumes stack top contains new * 'length' value and the whole calling convention is not very * compatible with what we need. */ - duk_push_tval(thr, tv_val); /* key val */ + duk_push_tval(thr, tv_val); /* key val */ rc = duk__handle_put_array_length(thr, orig); - duk_pop_unsafe(thr); /* key val -> key */ + duk_pop_unsafe(thr); /* key val -> key */ if (!rc) { goto fail_array_length_partial; } @@ -3950,12 +4050,14 @@ /* Careful with wrapping: arr_idx upshift may easily wrap, whereas * length downshift won't. */ - if (arr_idx < (h_bufobj->length >> h_bufobj->shift) && DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { + if (arr_idx < (h_bufobj->length >> h_bufobj->shift) && + DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { duk_uint8_t *data; DUK_DDD(DUK_DDDPRINT("writing to buffer data at index %ld", (long) arr_idx)); - DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); /* index/length check guarantees */ - byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); /* index/length check guarantees */ + byte_off = arr_idx + << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); /* Coerce to number before validating pointers etc so that the @@ -3966,27 +4068,30 @@ duk_push_tval(thr, tv_val); (void) duk_to_number_m1(thr); - if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { - data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + h_bufobj->offset + byte_off; + if (h_bufobj->buf != NULL && + DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { + data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + + h_bufobj->offset + byte_off; duk_hbufobj_validated_write(thr, h_bufobj, data, elem_size); } else { - DUK_D(DUK_DPRINT("bufobj access out of underlying buffer, ignoring (write skipped)")); + DUK_D(DUK_DPRINT( + "bufobj access out of underlying buffer, ignoring (write skipped)")); } duk_pop_unsafe(thr); goto success_no_arguments_exotic; } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_D(DUK_DPRINT("should not happen, key %!O", key)); - goto fail_internal; /* should not happen */ + goto fail_internal; /* should not happen */ } DUK_DD(DUK_DDPRINT("put to existing own plain property, property is writable")); goto update_old; } DUK_UNREACHABLE(); - next_in_chain: + next_in_chain: /* XXX: option to pretend property doesn't exist if sanity limit is * hit might be useful. */ @@ -4015,7 +4120,7 @@ goto create_new; - update_old: +update_old: /* * Update an existing property of the base object. @@ -4048,10 +4153,9 @@ if (desc.e_idx >= 0) { tv = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, orig, desc.e_idx); DUK_DDD(DUK_DDDPRINT("previous entry value: %!iT", (duk_tval *) tv)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; e_idx may be invalidated */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; e_idx may be invalidated */ /* don't touch property attributes or hash part */ - DUK_DD(DUK_DDPRINT("put to an existing entry at index %ld -> new value %!iT", - (long) desc.e_idx, (duk_tval *) tv)); + DUK_DD(DUK_DDPRINT("put to an existing entry at index %ld -> new value %!iT", (long) desc.e_idx, (duk_tval *) tv)); } else { /* Note: array entries are always writable, so the writability check * above is pointless for them. The check could be avoided with some @@ -4061,9 +4165,10 @@ DUK_ASSERT(desc.a_idx >= 0); tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, orig, desc.a_idx); DUK_DDD(DUK_DDDPRINT("previous array value: %!iT", (duk_tval *) tv)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; a_idx may be invalidated */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; a_idx may be invalidated */ DUK_DD(DUK_DDPRINT("put to an existing array entry at index %ld -> new value %!iT", - (long) desc.a_idx, (duk_tval *) tv)); + (long) desc.a_idx, + (duk_tval *) tv)); } /* Regardless of whether property is found in entry or array part, @@ -4072,7 +4177,7 @@ */ goto success_with_arguments_exotic; - create_new: +create_new: /* * Create a new property in the original object. @@ -4105,11 +4210,9 @@ * from its creation and cannot be deleted, and is thus * caught as an existing property above. */ - DUK_ASSERT(!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && - key == DUK_HTHREAD_STRING_LENGTH(thr))); + DUK_ASSERT(!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && key == DUK_HTHREAD_STRING_LENGTH(thr))); - if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && - arr_idx != DUK__NO_ARRAY_INDEX) { + if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && arr_idx != DUK__NO_ARRAY_INDEX) { /* automatic length update */ duk_uint32_t old_len; duk_harray *a; @@ -4122,7 +4225,8 @@ if (arr_idx >= old_len) { DUK_DDD(DUK_DDDPRINT("write new array entry requires length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a)) { DUK_DD(DUK_DDPRINT("attempt to extend array, but array 'length' is not writable")); @@ -4136,15 +4240,16 @@ */ DUK_ASSERT(arr_idx != 0xffffffffUL); - new_array_length = arr_idx + 1; /* flag for later write */ + new_array_length = arr_idx + 1; /* flag for later write */ } else { DUK_DDD(DUK_DDDPRINT("write new array entry does not require length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); } } - /* write_to_array_part: */ + /* write_to_array_part: */ /* * Write to array part? @@ -4166,8 +4271,7 @@ DUK_ASSERT(DUK_TVAL_IS_UNUSED(tv)); DUK_TVAL_SET_TVAL(tv, tv_val); DUK_TVAL_INCREF(thr, tv); - DUK_DD(DUK_DDPRINT("put to new array entry: %ld -> %!T", - (long) arr_idx, (duk_tval *) tv)); + DUK_DD(DUK_DDPRINT("put to new array entry: %ld -> %!T", (long) arr_idx, (duk_tval *) tv)); /* Note: array part values are Writable, Enumerable, * and Configurable which matches the required attributes @@ -4176,7 +4280,7 @@ goto entry_updated; } - write_to_entry_part: +write_to_entry_part: /* * Write to entry part @@ -4196,7 +4300,7 @@ DUK_HOBJECT_E_SET_FLAGS(thr->heap, orig, e_idx, DUK_PROPDESC_FLAGS_WEC); goto entry_updated; - entry_updated: +entry_updated: /* * Possible pending array length update, which must only be done @@ -4210,8 +4314,7 @@ DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig)); - DUK_DDD(DUK_DDDPRINT("write successful, pending array length update to: %ld", - (long) new_array_length)); + DUK_DDD(DUK_DDDPRINT("write successful, pending array length update to: %ld", (long) new_array_length)); ((duk_harray *) orig)->length = new_array_length; } @@ -4225,7 +4328,7 @@ goto success_no_arguments_exotic; - success_with_arguments_exotic: +success_with_arguments_exotic: /* * Arguments objects have exotic DefineOwnProperty which updates @@ -4240,8 +4343,7 @@ * we end up in step 5.b.i. */ - if (arr_idx != DUK__NO_ARRAY_INDEX && - DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { /* Note: only numbered indices are relevant, so arr_idx fast reject * is good (this is valid unless there are more than 4**32-1 arguments). */ @@ -4260,14 +4362,14 @@ } /* fall thru */ - success_no_arguments_exotic: +success_no_arguments_exotic: /* shared exit path now */ DUK_DDD(DUK_DDDPRINT("result: success")); - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 1; #if defined(DUK_USE_ES6_PROXY) - fail_proxy_rejected: +fail_proxy_rejected: DUK_DDD(DUK_DDDPRINT("result: error, proxy rejects")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); @@ -4277,40 +4379,43 @@ return 0; #endif - fail_base_primitive: +fail_base_primitive: DUK_DDD(DUK_DDDPRINT("result: error, base primitive")); if (throw_flag) { #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot write property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot write property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_not_extensible: +fail_not_extensible: DUK_DDD(DUK_DDDPRINT("result: error, not extensible")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_EXTENSIBLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_not_writable: +fail_not_writable: DUK_DDD(DUK_DDDPRINT("result: error, not writable")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_WRITABLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; #if defined(DUK_USE_ROM_OBJECTS) - fail_not_writable_no_pop: +fail_not_writable_no_pop: DUK_DDD(DUK_DDDPRINT("result: error, not writable")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_WRITABLE); @@ -4319,31 +4424,31 @@ return 0; #endif - fail_array_length_partial: +fail_array_length_partial: DUK_DD(DUK_DDPRINT("result: error, array length write only partially successful")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_no_setter: +fail_no_setter: DUK_DDD(DUK_DDDPRINT("result: error, accessor property without setter")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_SETTER_UNDEFINED); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_internal: +fail_internal: DUK_DDD(DUK_DDDPRINT("result: error, internal")); if (throw_flag) { DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; } @@ -4362,8 +4467,13 @@ force_flag = (flags & DUK_DELPROP_FLAG_FORCE); DUK_DDD(DUK_DDDPRINT("delprop_raw: thr=%p, obj=%p, key=%p, throw=%ld, force=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (long) throw_flag, (long) force_flag, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (long) throw_flag, + (long) force_flag, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -4375,7 +4485,7 @@ arr_idx = DUK_HSTRING_GET_ARRIDX_FAST(key); /* 0 = don't push current value */ - if (!duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (!duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ DUK_DDD(DUK_DDDPRINT("property not found, succeed always")); goto success; } @@ -4402,7 +4512,7 @@ DUK_ASSERT(desc.e_idx < 0); tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, desc.a_idx); - DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ goto success; } else { DUK_ASSERT(desc.a_idx < 0); @@ -4428,7 +4538,9 @@ * invalidated. */ DUK_DDD(DUK_DDDPRINT("before removing value, e_idx %ld, key %p, key at slot %p", - (long) desc.e_idx, (void *) key, (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); + (long) desc.e_idx, + (void *) key, + (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); DUK_DDD(DUK_DDDPRINT("removing value at e_idx %ld", (long) desc.e_idx)); if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, desc.e_idx)) { duk_hobject *tmp; @@ -4453,7 +4565,9 @@ /* Remove key. */ DUK_DDD(DUK_DDDPRINT("before removing key, e_idx %ld, key %p, key at slot %p", - (long) desc.e_idx, (void *) key, (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); + (long) desc.e_idx, + (void *) key, + (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); DUK_DDD(DUK_DDDPRINT("removing key at e_idx %ld", (long) desc.e_idx)); DUK_ASSERT(key == DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx)); DUK_HOBJECT_E_SET_KEY(thr->heap, obj, desc.e_idx, NULL); @@ -4469,7 +4583,7 @@ DUK_UNREACHABLE(); - success: +success: /* * Argument exotic Delete behavior (E5 Section 10.6) is * a post-check, keeping arguments internal 'map' in sync with @@ -4496,8 +4610,8 @@ DUK_DDD(DUK_DDDPRINT("delete successful")); return 1; - fail_virtual: /* just use the same "not configurable" error message */ - fail_not_configurable: +fail_virtual: /* just use the same "not configurable" error message */ +fail_not_configurable: DUK_DDD(DUK_DDDPRINT("delete failed: property found, not configurable")); if (throw_flag) { @@ -4521,8 +4635,11 @@ duk_bool_t rc; DUK_DDD(DUK_DDDPRINT("delprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -4536,8 +4653,7 @@ */ entry_top = duk_get_top(thr); - if (DUK_TVAL_IS_UNDEFINED(tv_obj) || - DUK_TVAL_IS_NULL(tv_obj)) { + if (DUK_TVAL_IS_UNDEFINED(tv_obj) || DUK_TVAL_IS_NULL(tv_obj)) { DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject")); goto fail_invalid_base_uncond; } @@ -4560,12 +4676,12 @@ if (duk__proxy_check_prop(thr, obj, DUK_STRIDX_DELETE_PROPERTY, tv_key, &h_target)) { /* -> ... obj key trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'deleteProperty' for key %!T", (duk_tval *) tv_key)); - duk_push_hobject(thr, h_target); /* target */ - duk_dup_m4(thr); /* P */ + duk_push_hobject(thr, h_target); /* target */ + duk_dup_m4(thr); /* P */ duk_call_method(thr, 2 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { - goto fail_proxy_rejected; /* retval indicates delete failed */ + goto fail_proxy_rejected; /* retval indicates delete failed */ } /* Target object must be checked for a conflicting @@ -4575,14 +4691,17 @@ arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); DUK_ASSERT(key != NULL); - if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push + value */ duk_small_int_t desc_reject; DUK_DDD(DUK_DDDPRINT("proxy 'deleteProperty': target has matching property %!O, check for " "conflicting property; desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (duk_heaphdr *) key, + (unsigned long) desc.flags, + (void *) desc.get, + (void *) desc.set)); desc_reject = !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE); if (desc_reject) { @@ -4591,13 +4710,13 @@ DUK_WO_NORETURN(return 0;); } } - rc = 1; /* success */ + rc = 1; /* success */ goto done_rc; } - obj = h_target; /* resume delete to target */ + obj = h_target; /* resume delete to target */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ arr_idx = duk__to_property_key(thr, -1, &key); DUK_ASSERT(key != NULL); @@ -4622,8 +4741,7 @@ goto fail_not_configurable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { goto fail_not_configurable; } } else if (DUK_TVAL_IS_BUFFER(tv_obj)) { @@ -4641,8 +4759,7 @@ goto fail_not_configurable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { goto fail_not_configurable; } } else if (DUK_TVAL_IS_LIGHTFUNC(tv_obj)) { @@ -4659,23 +4776,26 @@ rc = 1; goto done_rc; - done_rc: +done_rc: duk_set_top_unsafe(thr, entry_top); return rc; - fail_invalid_base_uncond: +fail_invalid_base_uncond: /* Note: unconditional throw */ DUK_ASSERT(duk_get_top(thr) == entry_top); #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot delete property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot delete property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); #if defined(DUK_USE_ES6_PROXY) - fail_proxy_rejected: +fail_proxy_rejected: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); @@ -4684,7 +4804,7 @@ return 0; #endif - fail_not_configurable: +fail_not_configurable: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); @@ -4712,17 +4832,23 @@ * operations. */ -DUK_INTERNAL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags) { +DUK_INTERNAL void duk_hobject_define_property_internal(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_small_uint_t flags) { duk_propdesc desc; duk_uint32_t arr_idx; duk_int_t e_idx; duk_tval *tv1 = NULL; duk_tval *tv2 = NULL; - duk_small_uint_t propflags = flags & DUK_PROPDESC_FLAGS_MASK; /* mask out flags not actually stored */ + duk_small_uint_t propflags = flags & DUK_PROPDESC_FLAGS_MASK; /* mask out flags not actually stored */ DUK_DDD(DUK_DDDPRINT("define new property (internal): thr=%p, obj=%!O, key=%!O, flags=0x%02lx, val=%!T", - (void *) thr, (duk_heaphdr *) obj, (duk_heaphdr *) key, - (unsigned long) flags, (duk_tval *) duk_get_tval(thr, -1))); + (void *) thr, + (duk_heaphdr *) obj, + (duk_heaphdr *) key, + (unsigned long) flags, + (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -4730,11 +4856,11 @@ DUK_ASSERT(key != NULL); DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); - DUK_ASSERT(duk_is_valid_index(thr, -1)); /* contains value */ + DUK_ASSERT(duk_is_valid_index(thr, -1)); /* contains value */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); - if (duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ if (desc.e_idx >= 0) { if (flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) { DUK_DDD(DUK_DDDPRINT("property already exists in the entry part -> skip as requested")); @@ -4775,7 +4901,8 @@ new_len = duk__to_new_array_length_checked(thr, DUK_GET_TVAL_NEGIDX(thr, -1)); ((duk_harray *) obj)->length = new_len; DUK_DD(DUK_DDPRINT("internal define property for array .length: %ld -> %ld", - (long) prev_len, (long) ((duk_harray *) obj)->length)); + (long) prev_len, + (long) ((duk_harray *) obj)->length)); goto pop_exit; } DUK_DD(DUK_DDPRINT("property already exists but is virtual -> failure")); @@ -4787,7 +4914,8 @@ if (DUK_HOBJECT_HAS_ARRAY_PART(obj)) { if (arr_idx != DUK__NO_ARRAY_INDEX) { - DUK_DDD(DUK_DDDPRINT("property does not exist, object has array part -> possibly extend array part and write value (assert attributes)")); + DUK_DDD(DUK_DDDPRINT("property does not exist, object has array part -> possibly extend array part and " + "write value (assert attributes)")); DUK_ASSERT(propflags == DUK_PROPDESC_FLAGS_WEC); tv1 = duk__obtain_arridx_slot(thr, arr_idx, obj); @@ -4801,9 +4929,10 @@ } } - write_to_entry_part: - DUK_DDD(DUK_DDDPRINT("property does not exist, object belongs in entry part -> allocate new entry and write value and attributes")); - e_idx = duk__hobject_alloc_entry_checked(thr, obj, key); /* increases key refcount */ +write_to_entry_part: + DUK_DDD(DUK_DDDPRINT( + "property does not exist, object belongs in entry part -> allocate new entry and write value and attributes")); + e_idx = duk__hobject_alloc_entry_checked(thr, obj, key); /* increases key refcount */ DUK_ASSERT(e_idx >= 0); DUK_HOBJECT_E_SET_FLAGS(thr->heap, obj, e_idx, propflags); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, e_idx); @@ -4811,22 +4940,21 @@ DUK_TVAL_SET_UNDEFINED(tv1); goto write_value; - write_value: +write_value: /* tv1 points to value storage */ - tv2 = duk_require_tval(thr, -1); /* late lookup, avoid side effects */ - DUK_DDD(DUK_DDDPRINT("writing/updating value: %!T -> %!T", - (duk_tval *) tv1, (duk_tval *) tv2)); + tv2 = duk_require_tval(thr, -1); /* late lookup, avoid side effects */ + DUK_DDD(DUK_DDDPRINT("writing/updating value: %!T -> %!T", (duk_tval *) tv1, (duk_tval *) tv2)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ goto pop_exit; - pop_exit: - duk_pop_unsafe(thr); /* remove in_val */ +pop_exit: + duk_pop_unsafe(thr); /* remove in_val */ return; - error_virtual: /* share error message */ - error_internal: +error_virtual: /* share error message */ +error_internal: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); } @@ -4837,13 +4965,19 @@ * must avoid interning. */ -DUK_INTERNAL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, duk_hobject *obj, duk_uarridx_t arr_idx, duk_small_uint_t flags) { +DUK_INTERNAL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, + duk_hobject *obj, + duk_uarridx_t arr_idx, + duk_small_uint_t flags) { duk_hstring *key; duk_tval *tv1, *tv2; DUK_DDD(DUK_DDDPRINT("define new property (internal) arr_idx fast path: thr=%p, obj=%!O, " "arr_idx=%ld, flags=0x%02lx, val=%!T", - (void *) thr, obj, (long) arr_idx, (unsigned long) flags, + (void *) thr, + obj, + (long) arr_idx, + (unsigned long) flags, (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(thr != NULL); @@ -4851,10 +4985,8 @@ DUK_ASSERT(obj != NULL); DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); - if (DUK_HOBJECT_HAS_ARRAY_PART(obj) && - arr_idx != DUK__NO_ARRAY_INDEX && - flags == DUK_PROPDESC_FLAGS_WEC) { - DUK_ASSERT((flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) == 0); /* covered by comparison */ + if (DUK_HOBJECT_HAS_ARRAY_PART(obj) && arr_idx != DUK__NO_ARRAY_INDEX && flags == DUK_PROPDESC_FLAGS_WEC) { + DUK_ASSERT((flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) == 0); /* covered by comparison */ DUK_DDD(DUK_DDDPRINT("define property to array part (property may or may not exist yet)")); @@ -4865,22 +4997,22 @@ } tv2 = duk_require_tval(thr, -1); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ - duk_pop_unsafe(thr); /* ...val -> ... */ + duk_pop_unsafe(thr); /* ...val -> ... */ return; } - write_slow: +write_slow: DUK_DDD(DUK_DDDPRINT("define property fast path didn't work, use slow path")); key = duk_push_uint_to_hstring(thr, (duk_uint_t) arr_idx); DUK_ASSERT(key != NULL); - duk_insert(thr, -2); /* ... val key -> ... key val */ + duk_insert(thr, -2); /* ... val key -> ... key val */ duk_hobject_define_property_internal(thr, obj, key, flags); - duk_pop_unsafe(thr); /* ... key -> ... */ + duk_pop_unsafe(thr); /* ... key -> ... */ } /* @@ -4901,9 +5033,7 @@ /* Slow path, .length can be e.g. accessor, obj can be a Proxy, etc. */ duk_push_hobject(thr, obj); duk_push_hstring_stridx(thr, DUK_STRIDX_LENGTH); - (void) duk_hobject_getprop(thr, - DUK_GET_TVAL_NEGIDX(thr, -2), - DUK_GET_TVAL_NEGIDX(thr, -1)); + (void) duk_hobject_getprop(thr, DUK_GET_TVAL_NEGIDX(thr, -2), DUK_GET_TVAL_NEGIDX(thr, -1)); val = duk_to_number_m1(thr); duk_pop_3_unsafe(thr); @@ -4944,7 +5074,7 @@ DUK_ASSERT(heap != NULL); obj = DUK_HOBJECT_GET_PROTOTYPE(heap, obj); #else - obj = DUK_HOBJECT_GET_PROTOTYPE(NULL, obj); /* 'heap' arg ignored */ + obj = DUK_HOBJECT_GET_PROTOTYPE(NULL, obj); /* 'heap' arg ignored */ #endif } while (obj != NULL); @@ -5011,7 +5141,7 @@ /* ... key value desc */ duk_replace(thr, -3); - duk_pop_unsafe(thr); /* -> ... desc */ + duk_pop_unsafe(thr); /* -> ... desc */ } /* @@ -5048,7 +5178,7 @@ DUK_ASSERT(out_idx_value != NULL); DUK_ASSERT(out_getter != NULL); DUK_ASSERT(out_setter != NULL); - DUK_ASSERT(idx_in <= 0x7fffL); /* short variants would be OK, but not used to avoid shifts */ + DUK_ASSERT(idx_in <= 0x7fffL); /* short variants would be OK, but not used to avoid shifts */ /* Must be an object, otherwise TypeError (E5.1 Section 8.10.5, step 1). */ idx_in = duk_require_normalize_index(thr, idx_in); @@ -5104,7 +5234,7 @@ if (DUK_TVAL_IS_UNDEFINED(tv)) { /* undefined is accepted */ DUK_ASSERT(setter == NULL); - } else { + } else { /* NOTE: lightfuncs are coerced to full functions because * lightfuncs don't fit into a property value slot. This * has some side effects, see test-dev-lightfunc-accessor.js. @@ -5147,7 +5277,7 @@ /* ... multiple values */ return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_DESCRIPTOR); DUK_WO_NORETURN(return;); } @@ -5195,7 +5325,7 @@ duk_bool_t force_flag; duk_small_uint_t new_flags; duk_propdesc curr; - duk_uint32_t arridx_new_array_length; /* != 0 => post-update for array 'length' (used when key is an array index) */ + duk_uint32_t arridx_new_array_length; /* != 0 => post-update for array 'length' (used when key is an array index) */ duk_uint32_t arrlen_old_len; duk_uint32_t arrlen_new_len; duk_bool_t pending_write_protect; @@ -5235,13 +5365,22 @@ "has_get=%ld get=%p=%!O " "has_set=%ld set=%p=%!O " "arr_idx=%ld throw_flag=!%ld", - (long) has_enumerable, (long) is_enumerable, - (long) has_configurable, (long) is_configurable, - (long) has_writable, (long) is_writable, - (long) has_value, (duk_tval *) (idx_value >= 0 ? duk_get_tval(thr, idx_value) : NULL), - (long) has_get, (void *) get, (duk_heaphdr *) get, - (long) has_set, (void *) set, (duk_heaphdr *) set, - (long) arr_idx, (long) throw_flag)); + (long) has_enumerable, + (long) is_enumerable, + (long) has_configurable, + (long) is_configurable, + (long) has_writable, + (long) is_writable, + (long) has_value, + (duk_tval *) (idx_value >= 0 ? duk_get_tval(thr, idx_value) : NULL), + (long) has_get, + (void *) get, + (duk_heaphdr *) get, + (long) has_set, + (void *) set, + (duk_heaphdr *) set, + (long) arr_idx, + (long) throw_flag)); /* * Array exotic behaviors can be implemented at this point. The local variables @@ -5275,7 +5414,7 @@ DUK_ASSERT(idx_value >= 0); arrlen_new_len = duk__to_new_array_length_checked(thr, DUK_GET_TVAL_POSIDX(thr, idx_value)); duk_push_u32(thr, arrlen_new_len); - duk_replace(thr, idx_value); /* step 3.e: replace 'Desc.Value' */ + duk_replace(thr, idx_value); /* step 3.e: replace 'Desc.Value' */ DUK_DDD(DUK_DDDPRINT("old_len=%ld, new_len=%ld", (long) arrlen_old_len, (long) arrlen_new_len)); @@ -5317,7 +5456,8 @@ if (arr_idx >= old_len) { DUK_DDD(DUK_DDDPRINT("defineProperty requires array length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a) && !force_flag) { /* Array .length is always non-configurable, so @@ -5335,10 +5475,11 @@ } else { DUK_DDD(DUK_DDDPRINT("defineProperty does not require length update " "(arr_idx=%ld, old_len=%ld) -> standard behavior", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); } } - skip_array_exotic: +skip_array_exotic: /* XXX: There is currently no support for writing buffer object * indexed elements here. Attempt to do so will succeed and @@ -5390,7 +5531,7 @@ DUK_ASSERT(!has_value); DUK_ASSERT(!has_writable); - new_flags = DUK_PROPDESC_FLAG_ACCESSOR; /* defaults, E5 Section 8.6.1, Table 7 */ + new_flags = DUK_PROPDESC_FLAG_ACCESSOR; /* defaults, E5 Section 8.6.1, Table 7 */ if (has_enumerable && is_enumerable) { new_flags |= DUK_PROPDESC_FLAG_ENUMERABLE; } @@ -5423,7 +5564,7 @@ DUK_ASSERT(!has_set); DUK_ASSERT(!has_get); - new_flags = 0; /* defaults, E5 Section 8.6.1, Table 7 */ + new_flags = 0; /* defaults, E5 Section 8.6.1, Table 7 */ if (has_writable && is_writable) { new_flags |= DUK_PROPDESC_FLAG_WRITABLE; } @@ -5437,12 +5578,13 @@ duk_tval *tv_tmp = duk_require_tval(thr, idx_value); DUK_TVAL_SET_TVAL(&tv, tv_tmp); } else { - DUK_TVAL_SET_UNDEFINED(&tv); /* default value */ + DUK_TVAL_SET_UNDEFINED(&tv); /* default value */ } if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HOBJECT_HAS_ARRAY_PART(obj)) { if (new_flags == DUK_PROPDESC_FLAGS_WEC) { - DUK_DDD(DUK_DDDPRINT("new data property attributes match array defaults, attempt to write to array part")); + DUK_DDD(DUK_DDDPRINT( + "new data property attributes match array defaults, attempt to write to array part")); tv2 = duk__obtain_arridx_slot(thr, arr_idx, obj); if (tv2 == NULL) { DUK_DDD(DUK_DDDPRINT("failed writing to array part, abandoned array")); @@ -5515,8 +5657,8 @@ goto need_check; } - tmp1 = duk_require_tval(thr, -1); /* curr value */ - tmp2 = duk_require_tval(thr, idx_value); /* new value */ + tmp1 = duk_require_tval(thr, -1); /* curr value */ + tmp2 = duk_require_tval(thr, idx_value); /* new value */ if (!duk_js_samevalue(tmp1, tmp2)) { goto need_check; } @@ -5561,7 +5703,7 @@ */ goto success_no_exotics; - need_check: +need_check: /* * Some change(s) need to be made. Steps 7-11. @@ -5633,9 +5775,10 @@ DUK_DDD(DUK_DDDPRINT("convert property to accessor property")); if (curr.a_idx >= 0) { - DUK_DDD(DUK_DDDPRINT("property to convert is stored in an array entry, abandon array and re-lookup")); + DUK_DDD( + DUK_DDDPRINT("property to convert is stored in an array entry, abandon array and re-lookup")); duk__abandon_array_part(thr, obj); - duk_pop_unsafe(thr); /* remove old value */ + duk_pop_unsafe(thr); /* remove old value */ rc = duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &curr, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); DUK_ASSERT(rc != 0); @@ -5643,14 +5786,14 @@ } if (curr.e_idx < 0) { DUK_ASSERT(curr.a_idx < 0 && curr.e_idx < 0); - goto fail_virtual; /* safeguard for virtual property */ + goto fail_virtual; /* safeguard for virtual property */ } DUK_ASSERT(curr.e_idx >= 0); DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, curr.e_idx)); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, curr.e_idx); - DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ(thr, tv1); /* XXX: just decref */ + DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ(thr, tv1); /* XXX: just decref */ DUK_HOBJECT_E_SET_VALUE_GETTER(thr->heap, obj, curr.e_idx, NULL); DUK_HOBJECT_E_SET_VALUE_SETTER(thr->heap, obj, curr.e_idx, NULL); @@ -5679,7 +5822,7 @@ /* curr is accessor -> cannot be in array part. */ DUK_ASSERT(curr.a_idx < 0); if (curr.e_idx < 0) { - goto fail_virtual; /* safeguard; no virtual accessors now */ + goto fail_virtual; /* safeguard; no virtual accessors now */ } DUK_DDD(DUK_DDDPRINT("convert property to data property")); @@ -5711,8 +5854,8 @@ } /* Note: changing from writable to non-writable is OK */ if (!(curr.flags & DUK_PROPDESC_FLAG_WRITABLE) && has_value) { - duk_tval *tmp1 = duk_require_tval(thr, -1); /* curr value */ - duk_tval *tmp2 = duk_require_tval(thr, idx_value); /* new value */ + duk_tval *tmp1 = duk_require_tval(thr, -1); /* curr value */ + duk_tval *tmp2 = duk_require_tval(thr, idx_value); /* new value */ if (!duk_js_samevalue(tmp1, tmp2)) { goto fail_not_configurable; } @@ -5761,8 +5904,7 @@ /* XXX: write protect after flag? -> any chance of handling it here? */ - DUK_DDD(DUK_DDDPRINT("new flags that we want to write: 0x%02lx", - (unsigned long) new_flags)); + DUK_DDD(DUK_DDDPRINT("new flags that we want to write: 0x%02lx", (unsigned long) new_flags)); /* * Check whether we need to abandon an array part (if it exists) @@ -5778,20 +5920,23 @@ DUK_DDD(DUK_DDDPRINT("array index, new property attributes match array defaults, update in-place")); - DUK_ASSERT(curr.flags == DUK_PROPDESC_FLAGS_WEC); /* must have been, since in array part */ + DUK_ASSERT(curr.flags == DUK_PROPDESC_FLAGS_WEC); /* must have been, since in array part */ DUK_ASSERT(!has_set); DUK_ASSERT(!has_get); - DUK_ASSERT(idx_value >= 0); /* must be: if attributes match and we get here the value must differ (otherwise no change) */ + DUK_ASSERT( + idx_value >= + 0); /* must be: if attributes match and we get here the value must differ (otherwise no change) */ tv2 = duk_require_tval(thr, idx_value); tv1 = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, curr.a_idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate a_idx */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate a_idx */ goto success_exotics; } - DUK_DDD(DUK_DDDPRINT("array index, new property attributes do not match array defaults, abandon array and re-lookup")); + DUK_DDD( + DUK_DDDPRINT("array index, new property attributes do not match array defaults, abandon array and re-lookup")); duk__abandon_array_part(thr, obj); - duk_pop_unsafe(thr); /* remove old value */ + duk_pop_unsafe(thr); /* remove old value */ rc = duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &curr, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); DUK_ASSERT(rc != 0); @@ -5815,10 +5960,12 @@ if (key == DUK_HTHREAD_STRING_LENGTH(thr) && DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)) { duk_harray *a; a = (duk_harray *) obj; - DUK_DD(DUK_DDPRINT("Object.defineProperty() attribute update for duk_harray .length -> %02lx", (unsigned long) new_flags)); + DUK_DD(DUK_DDPRINT("Object.defineProperty() attribute update for duk_harray .length -> %02lx", + (unsigned long) new_flags)); DUK_HARRAY_ASSERT_VALID(a); if ((new_flags & DUK_PROPDESC_FLAGS_EC) != (curr.flags & DUK_PROPDESC_FLAGS_EC)) { - DUK_D(DUK_DPRINT("Object.defineProperty() attempt to change virtual array .length enumerable or configurable attribute, fail")); + DUK_D(DUK_DPRINT("Object.defineProperty() attempt to change virtual array .length enumerable or " + "configurable attribute, fail")); goto fail_virtual; } if (new_flags & DUK_PROPDESC_FLAG_WRITABLE) { @@ -5846,7 +5993,7 @@ DUK_UNREF(tmp); DUK_HOBJECT_E_SET_VALUE_SETTER(thr->heap, obj, curr.e_idx, set); DUK_HOBJECT_INCREF_ALLOWNULL(thr, set); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ } if (has_get) { duk_hobject *tmp; @@ -5862,7 +6009,7 @@ DUK_UNREF(tmp); DUK_HOBJECT_E_SET_VALUE_GETTER(thr->heap, obj, curr.e_idx, get); DUK_HOBJECT_INCREF_ALLOWNULL(thr, get); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ } if (has_value) { duk_tval *tv1, *tv2; @@ -5873,9 +6020,9 @@ DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, curr.e_idx)); tv2 = duk_require_tval(thr, idx_value); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, curr.e_idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate e_idx */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate e_idx */ } else { - DUK_ASSERT(curr.a_idx < 0); /* array part case handled comprehensively previously */ + DUK_ASSERT(curr.a_idx < 0); /* array part case handled comprehensively previously */ DUK_DD(DUK_DDPRINT("Object.defineProperty(), value update for virtual property")); /* XXX: Uint8Array and other typed array virtual writes not currently @@ -5884,11 +6031,12 @@ if (key == DUK_HTHREAD_STRING_LENGTH(thr) && DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)) { duk_harray *a; a = (duk_harray *) obj; - DUK_DD(DUK_DDPRINT("Object.defineProperty() value update for duk_harray .length -> %ld", (long) arrlen_new_len)); + DUK_DD(DUK_DDPRINT("Object.defineProperty() value update for duk_harray .length -> %ld", + (long) arrlen_new_len)); DUK_HARRAY_ASSERT_VALID(a); a->length = arrlen_new_len; } else { - goto fail_virtual; /* should not happen */ + goto fail_virtual; /* should not happen */ } } } @@ -5905,7 +6053,7 @@ * - for 'length' key the element deletion and 'length' update occurs here */ - success_exotics: +success_exotics: /* curr.a_idx or curr.e_idx may have been invalidated by side effects * above. @@ -5949,7 +6097,8 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key is 'length', exotic array behavior, " "doing array element deletion and length update")); - rc = duk__handle_put_array_length_smaller(thr, obj, arrlen_old_len, arrlen_new_len, force_flag, &result_len); + rc = + duk__handle_put_array_length_smaller(thr, obj, arrlen_old_len, arrlen_new_len, force_flag, &result_len); /* update length (curr points to length, and we assume it's still valid) */ DUK_ASSERT(result_len >= arrlen_new_len && result_len <= arrlen_old_len); @@ -5972,7 +6121,7 @@ duk_hobject *varenv; DUK_ASSERT(arridx_new_array_length == 0); - DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)); /* traits are separate; in particular, arguments not an array */ + DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)); /* traits are separate; in particular, arguments not an array */ map = NULL; varenv = NULL; @@ -5989,7 +6138,7 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map' " "changed to an accessor, delete arguments binding")); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ } else { /* Note: this order matters (final value before deleting map entry must be done) */ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map', " @@ -6017,7 +6166,7 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map', " "changed to non-writable, delete arguments binding")); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ } } @@ -6026,22 +6175,22 @@ */ } - success_no_exotics: +success_no_exotics: /* Some code paths use NORZ macros for simplicity, ensure refzero * handling is completed. */ DUK_REFZERO_CHECK_SLOW(thr); return 1; - fail_not_extensible: +fail_not_extensible: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_EXTENSIBLE); DUK_WO_NORETURN(return 0;); } return 0; - fail_virtual: /* just use the same "not configurable" error message" */ - fail_not_configurable: +fail_virtual: /* just use the same "not configurable" error message" */ +fail_not_configurable: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); @@ -6066,7 +6215,7 @@ h_obj = duk_push_this_coercible_to_object(thr); DUK_ASSERT(h_obj != NULL); - ret = duk_hobject_get_own_propdesc(thr, h_obj, h_v, &desc, 0 /*flags*/); /* don't push value */ + ret = duk_hobject_get_own_propdesc(thr, h_obj, h_v, &desc, 0 /*flags*/); /* don't push value */ duk_push_boolean(thr, ret && ((desc.flags & required_desc_flags) == required_desc_flags)); return 1; @@ -6180,9 +6329,7 @@ if (flags & DUK_PROPDESC_FLAG_CONFIGURABLE) { return 0; } - if (is_frozen && - !(flags & DUK_PROPDESC_FLAG_ACCESSOR) && - (flags & DUK_PROPDESC_FLAG_WRITABLE)) { + if (is_frozen && !(flags & DUK_PROPDESC_FLAG_ACCESSOR) && (flags & DUK_PROPDESC_FLAG_WRITABLE)) { return 0; } }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hproxy.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hproxy.h
Changed
@@ -7,9 +7,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hproxy_assert_valid(duk_hproxy *h); -#define DUK_HPROXY_ASSERT_VALID(h) do { duk_hproxy_assert_valid((h)); } while (0) +#define DUK_HPROXY_ASSERT_VALID(h) \ + do { \ + duk_hproxy_assert_valid((h)); \ + } while (0) #else -#define DUK_HPROXY_ASSERT_VALID(h) do {} while (0) +#define DUK_HPROXY_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hproxy { @@ -23,4 +28,4 @@ duk_hobject *handler; }; -#endif /* DUK_HPROXY_H_INCLUDED */ +#endif /* DUK_HPROXY_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hstring.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hstring.h
Changed
@@ -27,9 +27,9 @@ */ #if defined(DUK_USE_STRLEN16) -#define DUK_HSTRING_MAX_BYTELEN (0x0000ffffUL) +#define DUK_HSTRING_MAX_BYTELEN (0x0000ffffUL) #else -#define DUK_HSTRING_MAX_BYTELEN (0x7fffffffUL) +#define DUK_HSTRING_MAX_BYTELEN (0x7fffffffUL) #endif /* XXX: could add flags for "is valid CESU-8" (ECMAScript compatible strings), @@ -41,139 +41,148 @@ /* With lowmem builds the high 16 bits of duk_heaphdr are used for other * purposes, so this leaves 7 duk_heaphdr flags and 9 duk_hstring flags. */ -#define DUK_HSTRING_FLAG_ASCII DUK_HEAPHDR_USER_FLAG(0) /* string is ASCII, clen == blen */ -#define DUK_HSTRING_FLAG_ARRIDX DUK_HEAPHDR_USER_FLAG(1) /* string is a valid array index */ -#define DUK_HSTRING_FLAG_SYMBOL DUK_HEAPHDR_USER_FLAG(2) /* string is a symbol (invalid utf-8) */ -#define DUK_HSTRING_FLAG_HIDDEN DUK_HEAPHDR_USER_FLAG(3) /* string is a hidden symbol (implies symbol, Duktape 1.x internal string) */ -#define DUK_HSTRING_FLAG_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(4) /* string is a reserved word (non-strict) */ -#define DUK_HSTRING_FLAG_STRICT_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(5) /* string is a reserved word (strict) */ -#define DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS DUK_HEAPHDR_USER_FLAG(6) /* string is 'eval' or 'arguments' */ -#define DUK_HSTRING_FLAG_EXTDATA DUK_HEAPHDR_USER_FLAG(7) /* string data is external (duk_hstring_external) */ -#define DUK_HSTRING_FLAG_PINNED_LITERAL DUK_HEAPHDR_USER_FLAG(8) /* string is a literal, and pinned */ - -#define DUK_HSTRING_HAS_ASCII(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_HAS_ARRIDX(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_HAS_SYMBOL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_HAS_HIDDEN(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_HAS_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_HAS_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_HAS_EXTDATA(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_HAS_PINNED_LITERAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#define DUK_HSTRING_SET_ASCII(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_SET_ARRIDX(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_SET_SYMBOL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_SET_HIDDEN(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_SET_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_SET_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_SET_EXTDATA(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_SET_PINNED_LITERAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#define DUK_HSTRING_CLEAR_ASCII(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_CLEAR_ARRIDX(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_CLEAR_SYMBOL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_CLEAR_HIDDEN(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_CLEAR_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_CLEAR_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_CLEAR_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_CLEAR_EXTDATA(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_CLEAR_PINNED_LITERAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#if 0 /* Slightly smaller code without explicit flag, but explicit flag - * is very useful when 'clen' is dropped. - */ -#define DUK_HSTRING_IS_ASCII(x) (DUK_HSTRING_GET_BYTELEN((x)) == DUK_HSTRING_GET_CHARLEN((x))) +#define DUK_HSTRING_FLAG_ASCII DUK_HEAPHDR_USER_FLAG(0) /* string is ASCII, clen == blen */ +#define DUK_HSTRING_FLAG_ARRIDX DUK_HEAPHDR_USER_FLAG(1) /* string is a valid array index */ +#define DUK_HSTRING_FLAG_SYMBOL DUK_HEAPHDR_USER_FLAG(2) /* string is a symbol (invalid utf-8) */ +#define DUK_HSTRING_FLAG_HIDDEN \ + DUK_HEAPHDR_USER_FLAG(3) /* string is a hidden symbol (implies symbol, Duktape 1.x internal string) */ +#define DUK_HSTRING_FLAG_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(4) /* string is a reserved word (non-strict) */ +#define DUK_HSTRING_FLAG_STRICT_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(5) /* string is a reserved word (strict) */ +#define DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS DUK_HEAPHDR_USER_FLAG(6) /* string is 'eval' or 'arguments' */ +#define DUK_HSTRING_FLAG_EXTDATA DUK_HEAPHDR_USER_FLAG(7) /* string data is external (duk_hstring_external) */ +#define DUK_HSTRING_FLAG_PINNED_LITERAL DUK_HEAPHDR_USER_FLAG(8) /* string is a literal, and pinned */ + +#define DUK_HSTRING_HAS_ASCII(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_HAS_ARRIDX(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_HAS_SYMBOL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_HAS_HIDDEN(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_HAS_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_HAS_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_HAS_EXTDATA(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_HAS_PINNED_LITERAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#define DUK_HSTRING_SET_ASCII(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_SET_ARRIDX(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_SET_SYMBOL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_SET_HIDDEN(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_SET_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_SET_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_SET_EXTDATA(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_SET_PINNED_LITERAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#define DUK_HSTRING_CLEAR_ASCII(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_CLEAR_ARRIDX(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_CLEAR_SYMBOL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_CLEAR_HIDDEN(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_CLEAR_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_CLEAR_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_CLEAR_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_CLEAR_EXTDATA(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_CLEAR_PINNED_LITERAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#if 0 /* Slightly smaller code without explicit flag, but explicit flag \ + * is very useful when 'clen' is dropped. \ + */ +#define DUK_HSTRING_IS_ASCII(x) (DUK_HSTRING_GET_BYTELEN((x)) == DUK_HSTRING_GET_CHARLEN((x))) #endif -#define DUK_HSTRING_IS_ASCII(x) DUK_HSTRING_HAS_ASCII((x)) /* lazily set! */ -#define DUK_HSTRING_IS_EMPTY(x) (DUK_HSTRING_GET_BYTELEN((x)) == 0) +#define DUK_HSTRING_IS_ASCII(x) DUK_HSTRING_HAS_ASCII((x)) /* lazily set! */ +#define DUK_HSTRING_IS_EMPTY(x) (DUK_HSTRING_GET_BYTELEN((x)) == 0) #if defined(DUK_USE_STRHASH16) -#define DUK_HSTRING_GET_HASH(x) ((x)->hdr.h_flags >> 16) -#define DUK_HSTRING_SET_HASH(x,v) do { \ +#define DUK_HSTRING_GET_HASH(x) ((x)->hdr.h_flags >> 16) +#define DUK_HSTRING_SET_HASH(x, v) \ + do { \ (x)->hdr.h_flags = ((x)->hdr.h_flags & 0x0000ffffUL) | ((v) << 16); \ } while (0) #else -#define DUK_HSTRING_GET_HASH(x) ((x)->hash) -#define DUK_HSTRING_SET_HASH(x,v) do { \ +#define DUK_HSTRING_GET_HASH(x) ((x)->hash) +#define DUK_HSTRING_SET_HASH(x, v) \ + do { \ (x)->hash = (v); \ } while (0) #endif #if defined(DUK_USE_STRLEN16) -#define DUK_HSTRING_GET_BYTELEN(x) ((x)->hdr.h_strextra16) -#define DUK_HSTRING_SET_BYTELEN(x,v) do { \ +#define DUK_HSTRING_GET_BYTELEN(x) ((x)->hdr.h_strextra16) +#define DUK_HSTRING_SET_BYTELEN(x, v) \ + do { \ (x)->hdr.h_strextra16 = (v); \ } while (0) #if defined(DUK_USE_HSTRING_CLEN) -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ (x)->clen16 = (v); \ } while (0) #else -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ - DUK_ASSERT(0); /* should never be called */ \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ + DUK_ASSERT(0); /* should never be called */ \ } while (0) #endif #else -#define DUK_HSTRING_GET_BYTELEN(x) ((x)->blen) -#define DUK_HSTRING_SET_BYTELEN(x,v) do { \ +#define DUK_HSTRING_GET_BYTELEN(x) ((x)->blen) +#define DUK_HSTRING_SET_BYTELEN(x, v) \ + do { \ (x)->blen = (v); \ } while (0) -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ (x)->clen = (v); \ } while (0) #endif #if defined(DUK_USE_HSTRING_EXTDATA) -#define DUK_HSTRING_GET_EXTDATA(x) \ - ((x)->extdata) +#define DUK_HSTRING_GET_EXTDATA(x) ((x)->extdata) #define DUK_HSTRING_GET_DATA(x) \ - (DUK_HSTRING_HAS_EXTDATA((x)) ? \ - DUK_HSTRING_GET_EXTDATA((const duk_hstring_external *) (x)) : ((const duk_uint8_t *) ((x) + 1))) + (DUK_HSTRING_HAS_EXTDATA((x)) ? DUK_HSTRING_GET_EXTDATA((const duk_hstring_external *) (x)) : \ + ((const duk_uint8_t *) ((x) + 1))) #else -#define DUK_HSTRING_GET_DATA(x) \ - ((const duk_uint8_t *) ((x) + 1)) +#define DUK_HSTRING_GET_DATA(x) ((const duk_uint8_t *) ((x) + 1)) #endif -#define DUK_HSTRING_GET_DATA_END(x) \ - (DUK_HSTRING_GET_DATA((x)) + (x)->blen) +#define DUK_HSTRING_GET_DATA_END(x) (DUK_HSTRING_GET_DATA((x)) + (x)->blen) /* Marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest * valid). */ -#define DUK_HSTRING_NO_ARRAY_INDEX (0xffffffffUL) +#define DUK_HSTRING_NO_ARRAY_INDEX (0xffffffffUL) #if defined(DUK_USE_HSTRING_ARRIDX) -#define DUK_HSTRING_GET_ARRIDX_FAST(h) ((h)->arridx) -#define DUK_HSTRING_GET_ARRIDX_SLOW(h) ((h)->arridx) +#define DUK_HSTRING_GET_ARRIDX_FAST(h) ((h)->arridx) +#define DUK_HSTRING_GET_ARRIDX_SLOW(h) ((h)->arridx) #else /* Get array index related to string (or return DUK_HSTRING_NO_ARRAY_INDEX); * avoids helper call if string has no array index value. */ -#define DUK_HSTRING_GET_ARRIDX_FAST(h) \ +#define DUK_HSTRING_GET_ARRIDX_FAST(h) \ (DUK_HSTRING_HAS_ARRIDX((h)) ? duk_js_to_arrayindex_hstring_fast_known((h)) : DUK_HSTRING_NO_ARRAY_INDEX) /* Slower but more compact variant. */ -#define DUK_HSTRING_GET_ARRIDX_SLOW(h) \ - (duk_js_to_arrayindex_hstring_fast((h))) +#define DUK_HSTRING_GET_ARRIDX_SLOW(h) (duk_js_to_arrayindex_hstring_fast((h))) #endif /* XXX: these actually fit into duk_hstring */ -#define DUK_SYMBOL_TYPE_HIDDEN 0 -#define DUK_SYMBOL_TYPE_GLOBAL 1 -#define DUK_SYMBOL_TYPE_LOCAL 2 +#define DUK_SYMBOL_TYPE_HIDDEN 0 +#define DUK_SYMBOL_TYPE_GLOBAL 1 +#define DUK_SYMBOL_TYPE_LOCAL 2 #define DUK_SYMBOL_TYPE_WELLKNOWN 3 /* Assertion for duk_hstring validity. */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hstring_assert_valid(duk_hstring *h); -#define DUK_HSTRING_ASSERT_VALID(h) do { duk_hstring_assert_valid((h)); } while (0) +#define DUK_HSTRING_ASSERT_VALID(h) \ + do { \ + duk_hstring_assert_valid((h)); \ + } while (0) #else -#define DUK_HSTRING_ASSERT_VALID(h) do {} while (0) +#define DUK_HSTRING_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -243,11 +252,14 @@ * Prototypes */ -DUK_INTERNAL_DECL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, duk_hstring *h, duk_uint_t pos, duk_bool_t surrogate_aware); +DUK_INTERNAL_DECL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, + duk_hstring *h, + duk_uint_t pos, + duk_bool_t surrogate_aware); DUK_INTERNAL_DECL duk_bool_t duk_hstring_equals_ascii_cstring(duk_hstring *h, const char *cstr); DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h); #if !defined(DUK_USE_HSTRING_LAZY_CLEN) DUK_INTERNAL_DECL void duk_hstring_init_charlen(duk_hstring *h); #endif -#endif /* DUK_HSTRING_H_INCLUDED */ +#endif /* DUK_HSTRING_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hstring_assert.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hstring_assert.c
Changed
@@ -10,4 +10,4 @@ DUK_ASSERT(h != NULL); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hstring_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hstring_misc.c
Changed
@@ -8,7 +8,10 @@ * duk_hstring charCodeAt, with and without surrogate awareness */ -DUK_INTERNAL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, duk_hstring *h, duk_uint_t pos, duk_bool_t surrogate_aware) { +DUK_INTERNAL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, + duk_hstring *h, + duk_uint_t pos, + duk_bool_t surrogate_aware) { duk_uint32_t boff; const duk_uint8_t *p, *p_start, *p_end; duk_ucodepoint_t cp1; @@ -17,21 +20,18 @@ /* Caller must check character offset to be inside the string. */ DUK_ASSERT(thr != NULL); DUK_ASSERT(h != NULL); - DUK_ASSERT_DISABLE(pos >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(pos >= 0); /* unsigned */ DUK_ASSERT(pos < (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte(thr, h, (duk_uint32_t) pos); - DUK_DDD(DUK_DDDPRINT("charCodeAt: pos=%ld -> boff=%ld, str=%!O", - (long) pos, (long) boff, (duk_heaphdr *) h)); + DUK_DDD(DUK_DDDPRINT("charCodeAt: pos=%ld -> boff=%ld, str=%!O", (long) pos, (long) boff, (duk_heaphdr *) h)); DUK_ASSERT_DISABLE(boff >= 0); DUK_ASSERT(boff < DUK_HSTRING_GET_BYTELEN(h)); p_start = DUK_HSTRING_GET_DATA(h); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h); p = p_start + boff; - DUK_DDD(DUK_DDDPRINT("p_start=%p, p_end=%p, p=%p", - (const void *) p_start, (const void *) p_end, - (const void *) p)); + DUK_DDD(DUK_DDDPRINT("p_start=%p, p_end=%p, p=%p", (const void *) p_start, (const void *) p_end, (const void *) p)); /* For invalid UTF-8 (never happens for standard ECMAScript strings) * return U+FFFD replacement character. @@ -42,7 +42,7 @@ * decoded at the end of the string and 'p' is no longer * within string memory range. */ - cp2 = 0; /* If call fails, this is left untouched and won't match cp2 check. */ + cp2 = 0; /* If call fails, this is left untouched and won't match cp2 check. */ (void) duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp2); if (cp2 >= 0xdc00UL && cp2 <= 0xdfffUL) { cp1 = (duk_ucodepoint_t) (((cp1 - 0xd800UL) << 10) + (cp2 - 0xdc00UL) + 0x10000UL); @@ -72,7 +72,7 @@ clen = duk_unicode_unvalidated_utf8_length(DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); #if defined(DUK_USE_STRLEN16) - DUK_ASSERT(clen <= 0xffffUL); /* Bytelength checked during interning. */ + DUK_ASSERT(clen <= 0xffffUL); /* Bytelength checked during interning. */ h->clen16 = (duk_uint16_t) clen; #else h->clen = (duk_uint32_t) clen; @@ -89,7 +89,7 @@ return h->clen; #endif } -#endif /* !DUK_USE_HSTRING_LAZY_CLEN */ +#endif /* !DUK_USE_HSTRING_LAZY_CLEN */ /* * duk_hstring charlen, when lazy charlen enabled @@ -100,7 +100,7 @@ DUK_LOCAL DUK_COLD duk_size_t duk__hstring_get_charlen_slowpath(duk_hstring *h) { duk_size_t res; - DUK_ASSERT(h->clen == 0); /* Checked by caller. */ + DUK_ASSERT(h->clen == 0); /* Checked by caller. */ #if defined(DUK_USE_ROM_STRINGS) /* ROM strings have precomputed clen, but if the computed clen is zero @@ -113,7 +113,7 @@ res = duk_unicode_unvalidated_utf8_length(DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); #if defined(DUK_USE_STRLEN16) - DUK_ASSERT(res <= 0xffffUL); /* Bytelength checked during interning. */ + DUK_ASSERT(res <= 0xffffUL); /* Bytelength checked during interning. */ h->clen16 = (duk_uint16_t) res; #else h->clen = (duk_uint32_t) res; @@ -123,7 +123,7 @@ } return res; } -#else /* DUK_USE_HSTRING_CLEN */ +#else /* DUK_USE_HSTRING_CLEN */ DUK_LOCAL duk_size_t duk__hstring_get_charlen_slowpath(duk_hstring *h) { if (DUK_LIKELY(DUK_HSTRING_HAS_ASCII(h))) { /* Most practical strings will go here. */ @@ -152,7 +152,7 @@ return res; } } -#endif /* DUK_USE_HSTRING_CLEN */ +#endif /* DUK_USE_HSTRING_CLEN */ #if defined(DUK_USE_HSTRING_CLEN) DUK_INTERNAL DUK_HOT duk_size_t duk_hstring_get_charlen(duk_hstring *h) { @@ -167,13 +167,13 @@ #endif return duk__hstring_get_charlen_slowpath(h); } -#else /* DUK_USE_HSTRING_CLEN */ +#else /* DUK_USE_HSTRING_CLEN */ DUK_INTERNAL DUK_HOT duk_size_t duk_hstring_get_charlen(duk_hstring *h) { /* Always use slow path. */ return duk__hstring_get_charlen_slowpath(h); } -#endif /* DUK_USE_HSTRING_CLEN */ -#endif /* DUK_USE_HSTRING_LAZY_CLEN */ +#endif /* DUK_USE_HSTRING_CLEN */ +#endif /* DUK_USE_HSTRING_LAZY_CLEN */ /* * Compare duk_hstring to an ASCII cstring.
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hthread.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hthread.h
Changed
@@ -14,38 +14,38 @@ */ /* Initial valstack size, roughly 0.7kiB. */ -#define DUK_VALSTACK_INITIAL_SIZE 96U +#define DUK_VALSTACK_INITIAL_SIZE 96U /* Internal extra elements assumed on function entry, always added to * user-defined 'extra' for e.g. the duk_check_stack() call. */ -#define DUK_VALSTACK_INTERNAL_EXTRA 32U +#define DUK_VALSTACK_INTERNAL_EXTRA 32U /* Number of elements guaranteed to be user accessible (in addition to call * arguments) on Duktape/C function entry. This is the major public API * commitment. */ -#define DUK_VALSTACK_API_ENTRY_MINIMUM DUK_API_ENTRY_STACK +#define DUK_VALSTACK_API_ENTRY_MINIMUM DUK_API_ENTRY_STACK /* * Activation defines */ -#define DUK_ACT_FLAG_STRICT (1U << 0) /* function executes in strict mode */ -#define DUK_ACT_FLAG_TAILCALLED (1U << 1) /* activation has tail called one or more times */ -#define DUK_ACT_FLAG_CONSTRUCT (1U << 2) /* function executes as a constructor (called via "new") */ -#define DUK_ACT_FLAG_PREVENT_YIELD (1U << 3) /* activation prevents yield (native call or "new") */ -#define DUK_ACT_FLAG_DIRECT_EVAL (1U << 4) /* activation is a direct eval call */ -#define DUK_ACT_FLAG_CONSTRUCT_PROXY (1U << 5) /* activation is for Proxy 'construct' call, special return value handling */ -#define DUK_ACT_FLAG_BREAKPOINT_ACTIVE (1U << 6) /* activation has active breakpoint(s) */ +#define DUK_ACT_FLAG_STRICT (1U << 0) /* function executes in strict mode */ +#define DUK_ACT_FLAG_TAILCALLED (1U << 1) /* activation has tail called one or more times */ +#define DUK_ACT_FLAG_CONSTRUCT (1U << 2) /* function executes as a constructor (called via "new") */ +#define DUK_ACT_FLAG_PREVENT_YIELD (1U << 3) /* activation prevents yield (native call or "new") */ +#define DUK_ACT_FLAG_DIRECT_EVAL (1U << 4) /* activation is a direct eval call */ +#define DUK_ACT_FLAG_CONSTRUCT_PROXY (1U << 5) /* activation is for Proxy 'construct' call, special return value handling */ +#define DUK_ACT_FLAG_BREAKPOINT_ACTIVE (1U << 6) /* activation has active breakpoint(s) */ -#define DUK_ACT_GET_FUNC(act) ((act)->func) +#define DUK_ACT_GET_FUNC(act) ((act)->func) /* * Flags for __FILE__ / __LINE__ registered into tracedata */ -#define DUK_TB_FLAG_NOBLAME_FILELINE (1U << 0) /* don't report __FILE__ / __LINE__ as fileName/lineNumber */ +#define DUK_TB_FLAG_NOBLAME_FILELINE (1U << 0) /* don't report __FILE__ / __LINE__ as fileName/lineNumber */ /* * Catcher defines @@ -54,52 +54,60 @@ /* XXX: remove catcher type entirely */ /* flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits) */ -#define DUK_CAT_TYPE_MASK 0x0000000fUL -#define DUK_CAT_TYPE_BITS 4 -#define DUK_CAT_LABEL_MASK 0xffffff00UL -#define DUK_CAT_LABEL_BITS 24 -#define DUK_CAT_LABEL_SHIFT 8 - -#define DUK_CAT_FLAG_CATCH_ENABLED (1U << 4) /* catch part will catch */ -#define DUK_CAT_FLAG_FINALLY_ENABLED (1U << 5) /* finally part will catch */ -#define DUK_CAT_FLAG_CATCH_BINDING_ENABLED (1U << 6) /* request to create catch binding */ -#define DUK_CAT_FLAG_LEXENV_ACTIVE (1U << 7) /* catch or with binding is currently active */ - -#define DUK_CAT_TYPE_UNKNOWN 0 -#define DUK_CAT_TYPE_TCF 1 -#define DUK_CAT_TYPE_LABEL 2 - -#define DUK_CAT_GET_TYPE(c) ((c)->flags & DUK_CAT_TYPE_MASK) -#define DUK_CAT_GET_LABEL(c) (((c)->flags & DUK_CAT_LABEL_MASK) >> DUK_CAT_LABEL_SHIFT) - -#define DUK_CAT_HAS_CATCH_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_ENABLED) -#define DUK_CAT_HAS_FINALLY_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_FINALLY_ENABLED) -#define DUK_CAT_HAS_CATCH_BINDING_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_BINDING_ENABLED) -#define DUK_CAT_HAS_LEXENV_ACTIVE(c) ((c)->flags & DUK_CAT_FLAG_LEXENV_ACTIVE) - -#define DUK_CAT_SET_CATCH_ENABLED(c) do { \ +#define DUK_CAT_TYPE_MASK 0x0000000fUL +#define DUK_CAT_TYPE_BITS 4 +#define DUK_CAT_LABEL_MASK 0xffffff00UL +#define DUK_CAT_LABEL_BITS 24 +#define DUK_CAT_LABEL_SHIFT 8 + +#define DUK_CAT_FLAG_CATCH_ENABLED (1U << 4) /* catch part will catch */ +#define DUK_CAT_FLAG_FINALLY_ENABLED (1U << 5) /* finally part will catch */ +#define DUK_CAT_FLAG_CATCH_BINDING_ENABLED (1U << 6) /* request to create catch binding */ +#define DUK_CAT_FLAG_LEXENV_ACTIVE (1U << 7) /* catch or with binding is currently active */ + +#define DUK_CAT_TYPE_UNKNOWN 0 +#define DUK_CAT_TYPE_TCF 1 +#define DUK_CAT_TYPE_LABEL 2 + +#define DUK_CAT_GET_TYPE(c) ((c)->flags & DUK_CAT_TYPE_MASK) +#define DUK_CAT_GET_LABEL(c) (((c)->flags & DUK_CAT_LABEL_MASK) >> DUK_CAT_LABEL_SHIFT) + +#define DUK_CAT_HAS_CATCH_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_ENABLED) +#define DUK_CAT_HAS_FINALLY_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_FINALLY_ENABLED) +#define DUK_CAT_HAS_CATCH_BINDING_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_BINDING_ENABLED) +#define DUK_CAT_HAS_LEXENV_ACTIVE(c) ((c)->flags & DUK_CAT_FLAG_LEXENV_ACTIVE) + +#define DUK_CAT_SET_CATCH_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_CATCH_ENABLED; \ } while (0) -#define DUK_CAT_SET_FINALLY_ENABLED(c) do { \ +#define DUK_CAT_SET_FINALLY_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_FINALLY_ENABLED; \ } while (0) -#define DUK_CAT_SET_CATCH_BINDING_ENABLED(c) do { \ +#define DUK_CAT_SET_CATCH_BINDING_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_CATCH_BINDING_ENABLED; \ } while (0) -#define DUK_CAT_SET_LEXENV_ACTIVE(c) do { \ +#define DUK_CAT_SET_LEXENV_ACTIVE(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_LEXENV_ACTIVE; \ } while (0) -#define DUK_CAT_CLEAR_CATCH_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_CATCH_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_CATCH_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_FINALLY_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_FINALLY_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_FINALLY_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_CATCH_BINDING_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_CATCH_BINDING_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_CATCH_BINDING_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_LEXENV_ACTIVE(c) do { \ +#define DUK_CAT_CLEAR_LEXENV_ACTIVE(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_LEXENV_ACTIVE; \ } while (0) @@ -108,24 +116,21 @@ */ #if defined(DUK_USE_ROM_STRINGS) -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) -#else /* DUK_USE_ROM_STRINGS */ +#define DUK_HTHREAD_GET_STRING(thr, idx) ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((thr)->heap->heap_udata, (thr)->strs16(idx))) +#define DUK_HTHREAD_GET_STRING(thr, idx) ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((thr)->heap->heap_udata, (thr)->strs16(idx))) #else -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((thr)->strs(idx)) +#define DUK_HTHREAD_GET_STRING(thr, idx) ((thr)->strs(idx)) #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ /* values for the state field */ -#define DUK_HTHREAD_STATE_INACTIVE 1 /* thread not currently running */ -#define DUK_HTHREAD_STATE_RUNNING 2 /* thread currently running (only one at a time) */ -#define DUK_HTHREAD_STATE_RESUMED 3 /* thread resumed another thread (active but not running) */ -#define DUK_HTHREAD_STATE_YIELDED 4 /* thread has yielded */ -#define DUK_HTHREAD_STATE_TERMINATED 5 /* thread has terminated */ +#define DUK_HTHREAD_STATE_INACTIVE 1 /* thread not currently running */ +#define DUK_HTHREAD_STATE_RUNNING 2 /* thread currently running (only one at a time) */ +#define DUK_HTHREAD_STATE_RESUMED 3 /* thread resumed another thread (active but not running) */ +#define DUK_HTHREAD_STATE_YIELDED 4 /* thread has yielded */ +#define DUK_HTHREAD_STATE_TERMINATED 5 /* thread has terminated */ /* Executor interrupt default interval when nothing else requires a * smaller value. The default interval must be small enough to allow @@ -133,7 +138,7 @@ * impact on execution performance low. */ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK_HTHREAD_INTCTR_DEFAULT (256L * 1024L) +#define DUK_HTHREAD_INTCTR_DEFAULT (256L * 1024L) #endif /* @@ -147,20 +152,31 @@ #if defined(DUK_USE_ASSERTIONS) /* Assertions for internals. */ DUK_INTERNAL_DECL void duk_hthread_assert_valid(duk_hthread *thr); -#define DUK_HTHREAD_ASSERT_VALID(thr) do { duk_hthread_assert_valid((thr)); } while (0) +#define DUK_HTHREAD_ASSERT_VALID(thr) \ + do { \ + duk_hthread_assert_valid((thr)); \ + } while (0) /* Assertions for public API calls; a bit stronger. */ DUK_INTERNAL_DECL void duk_ctx_assert_valid(duk_hthread *thr); -#define DUK_CTX_ASSERT_VALID(thr) do { duk_ctx_assert_valid((thr)); } while (0) +#define DUK_CTX_ASSERT_VALID(thr) \ + do { \ + duk_ctx_assert_valid((thr)); \ + } while (0) #else -#define DUK_HTHREAD_ASSERT_VALID(thr) do {} while (0) -#define DUK_CTX_ASSERT_VALID(thr) do {} while (0) +#define DUK_HTHREAD_ASSERT_VALID(thr) \ + do { \ + } while (0) +#define DUK_CTX_ASSERT_VALID(thr) \ + do { \ + } while (0) #endif /* Assertions for API call entry specifically. Checks 'ctx' but also may * check internal state (e.g. not in a debugger transport callback). */ -#define DUK_ASSERT_API_ENTRY(thr) do { \ +#define DUK_ASSERT_API_ENTRY(thr) \ + do { \ DUK_CTX_ASSERT_VALID((thr)); \ DUK_ASSERT((thr)->heap != NULL); \ DUK_ASSERT((thr)->heap->dbg_calling_transport == 0); \ @@ -170,11 +186,9 @@ * Assertion helpers. */ -#define DUK_ASSERT_STRIDX_VALID(val) \ - DUK_ASSERT((duk_uint_t) (val) < DUK_HEAP_NUM_STRINGS) +#define DUK_ASSERT_STRIDX_VALID(val) DUK_ASSERT((duk_uint_t) (val) < DUK_HEAP_NUM_STRINGS) -#define DUK_ASSERT_BIDX_VALID(val) \ - DUK_ASSERT((duk_uint_t) (val) < DUK_NUM_BUILTINS) +#define DUK_ASSERT_BIDX_VALID(val) DUK_ASSERT((duk_uint_t) (val) < DUK_NUM_BUILTINS) /* * Misc @@ -182,9 +196,7 @@ /* Fast access to 'this' binding. Assumes there's a call in progress. */ #define DUK_HTHREAD_THIS_PTR(thr) \ - (DUK_ASSERT_EXPR((thr) != NULL), \ - DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), \ - (thr)->valstack_bottom - 1) + (DUK_ASSERT_EXPR((thr) != NULL), DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), (thr)->valstack_bottom - 1) /* * Struct defines @@ -192,12 +204,13 @@ /* Fields are ordered for alignment/packing. */ struct duk_activation { - duk_tval tv_func; /* borrowed: full duk_tval for function being executed; for lightfuncs */ - duk_hobject *func; /* borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs */ + duk_tval tv_func; /* borrowed: full duk_tval for function being executed; for lightfuncs */ + duk_hobject *func; /* borrowed: function being executed; for bound function calls, this is the final, real function, NULL + for lightfuncs */ duk_activation *parent; /* previous (parent) activation (or NULL if none) */ - duk_hobject *var_env; /* current variable environment (may be NULL if delayed) */ - duk_hobject *lex_env; /* current lexical environment (may be NULL if delayed) */ - duk_catcher *cat; /* current catcher (or NULL) */ + duk_hobject *var_env; /* current variable environment (may be NULL if delayed) */ + duk_hobject *lex_env; /* current lexical environment (may be NULL if delayed) */ + duk_catcher *cat; /* current catcher (or NULL) */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) /* Previous value of 'func' caller, restored when unwound. Only in use @@ -206,7 +219,7 @@ duk_hobject *prev_caller; #endif - duk_instr_t *curr_pc; /* next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls */ + duk_instr_t *curr_pc; /* next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls */ /* bottom_byteoff and retval_byteoff are only used for book-keeping * of ECMAScript-initiated calls, to allow returning to an ECMAScript @@ -253,12 +266,12 @@ }; struct duk_catcher { - duk_catcher *parent; /* previous (parent) catcher (or NULL if none) */ - duk_hstring *h_varname; /* borrowed reference to catch variable name (or NULL if none) */ - /* (reference is valid as long activation exists) */ - duk_instr_t *pc_base; /* resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer) */ - duk_size_t idx_base; /* idx_base and idx_base+1 get completion value and type */ - duk_uint32_t flags; /* type and control flags, label number */ + duk_catcher *parent; /* previous (parent) catcher (or NULL if none) */ + duk_hstring *h_varname; /* borrowed reference to catch variable name (or NULL if none) */ + /* (reference is valid as long activation exists) */ + duk_instr_t *pc_base; /* resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer) */ + duk_size_t idx_base; /* idx_base and idx_base+1 get completion value and type */ + duk_uint32_t flags; /* type and control flags, label number */ /* XXX: could pack 'flags' and 'idx_base' to same value in practice, * on 32-bit targets this would make duk_catcher 16 bytes. */ @@ -316,21 +329,21 @@ * yyy = arbitrary values, inside current frame * uuu = outside active value stack, initialized to 'undefined' */ - duk_tval *valstack; /* start of valstack allocation */ - duk_tval *valstack_end; /* end of valstack reservation/guarantee (exclusive) */ - duk_tval *valstack_alloc_end; /* end of valstack allocation */ - duk_tval *valstack_bottom; /* bottom of current frame */ - duk_tval *valstack_top; /* top of current frame (exclusive) */ + duk_tval *valstack; /* start of valstack allocation */ + duk_tval *valstack_end; /* end of valstack reservation/guarantee (exclusive) */ + duk_tval *valstack_alloc_end; /* end of valstack allocation */ + duk_tval *valstack_bottom; /* bottom of current frame */ + duk_tval *valstack_top; /* top of current frame (exclusive) */ /* Call stack, represented as a linked list starting from the current * activation (or NULL if nothing is active). */ - duk_activation *callstack_curr; /* current activation (or NULL if none) */ - duk_size_t callstack_top; /* number of activation records in callstack (0 if none) */ - duk_size_t callstack_preventcount; /* number of activation records in callstack preventing a yield */ + duk_activation *callstack_curr; /* current activation (or NULL if none) */ + duk_size_t callstack_top; /* number of activation records in callstack (0 if none) */ + duk_size_t callstack_preventcount; /* number of activation records in callstack preventing a yield */ /* Yield/resume book-keeping. */ - duk_hthread *resumer; /* who resumed us (if any) */ + duk_hthread *resumer; /* who resumed us (if any) */ /* Current compiler state (if any), used for augmenting SyntaxErrors. */ duk_compiler_ctx *compile_ctx; @@ -343,8 +356,8 @@ * important for the counter to be conveniently accessible for the * bytecode executor inner loop for performance reasons. */ - duk_int_t interrupt_counter; /* countdown state */ - duk_int_t interrupt_init; /* start value for current countdown */ + duk_int_t interrupt_counter; /* countdown state */ + duk_int_t interrupt_init; /* start value for current countdown */ #endif /* Builtin-objects; may or may not be shared with other threads, @@ -396,7 +409,7 @@ DUK_INTERNAL_DECL void duk_hthread_valstack_torture_realloc(duk_hthread *thr); #endif -DUK_INTERNAL_DECL void *duk_hthread_get_valstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */ +DUK_INTERNAL_DECL void *duk_hthread_get_valstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */ #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_INTERNAL_DECL duk_uint_fast32_t duk_hthread_get_act_curr_pc(duk_hthread *thr, duk_activation *act); @@ -405,4 +418,4 @@ DUK_INTERNAL_DECL void duk_hthread_sync_currpc(duk_hthread *thr); DUK_INTERNAL_DECL void duk_hthread_sync_and_null_currpc(duk_hthread *thr); -#endif /* DUK_HTHREAD_H_INCLUDED */ +#endif /* DUK_HTHREAD_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hthread_alloc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hthread_alloc.c
Changed
@@ -42,7 +42,7 @@ return 1; - fail: +fail: DUK_FREE(heap, thr->valstack); DUK_ASSERT(thr->callstack_curr == NULL);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hthread_builtins.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hthread_builtins.c
Changed
@@ -10,21 +10,21 @@ * Encoding constants, must match genbuiltins.py */ -#define DUK__PROP_FLAGS_BITS 3 -#define DUK__LENGTH_PROP_BITS 3 -#define DUK__NARGS_BITS 3 -#define DUK__PROP_TYPE_BITS 3 - -#define DUK__NARGS_VARARGS_MARKER 0x07 - -#define DUK__PROP_TYPE_DOUBLE 0 -#define DUK__PROP_TYPE_STRING 1 -#define DUK__PROP_TYPE_STRIDX 2 -#define DUK__PROP_TYPE_BUILTIN 3 -#define DUK__PROP_TYPE_UNDEFINED 4 -#define DUK__PROP_TYPE_BOOLEAN_TRUE 5 -#define DUK__PROP_TYPE_BOOLEAN_FALSE 6 -#define DUK__PROP_TYPE_ACCESSOR 7 +#define DUK__PROP_FLAGS_BITS 3 +#define DUK__LENGTH_PROP_BITS 3 +#define DUK__NARGS_BITS 3 +#define DUK__PROP_TYPE_BITS 3 + +#define DUK__NARGS_VARARGS_MARKER 0x07 + +#define DUK__PROP_TYPE_DOUBLE 0 +#define DUK__PROP_TYPE_STRING 1 +#define DUK__PROP_TYPE_STRIDX 2 +#define DUK__PROP_TYPE_BUILTIN 3 +#define DUK__PROP_TYPE_UNDEFINED 4 +#define DUK__PROP_TYPE_BOOLEAN_TRUE 5 +#define DUK__PROP_TYPE_BOOLEAN_FALSE 6 +#define DUK__PROP_TYPE_ACCESSOR 7 /* * Create built-in objects by parsing an init bitstream generated @@ -47,9 +47,8 @@ #if defined(DUK_USE_ROM_GLOBAL_INHERIT) /* Inherit from ROM-based global object: less RAM usage, less transparent. */ h_global = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), DUK_BIDX_GLOBAL); DUK_ASSERT(h_global != NULL); #elif defined(DUK_USE_ROM_GLOBAL_CLONE) @@ -58,9 +57,8 @@ * model but more compliant. */ h_global = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), DUK_BIDX_OBJECT_PROTOTYPE); DUK_ASSERT(h_global != NULL); h_oldglobal = thr->builtinsDUK_BIDX_GLOBAL; @@ -94,7 +92,8 @@ duk_hobject_compact_props(thr, h_global); DUK_ASSERT(thr->builtinsDUK_BIDX_GLOBAL != NULL); - DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL)); /* no need to decref: ROM object */ + DUK_ASSERT( + !DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL)); /* no need to decref: ROM object */ thr->builtinsDUK_BIDX_GLOBAL = h_global; DUK_HOBJECT_INCREF(thr, h_global); DUK_D(DUK_DPRINT("duplicated global object: %!O", h_global)); @@ -103,9 +102,9 @@ * needed so that the global scope points to the newly created RAM-based * global object. */ - h_objenv = (duk_hobject *) duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + h_objenv = + (duk_hobject *) duk_hobjenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(h_objenv != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_objenv) == NULL); duk_push_hobject(thr, h_objenv); @@ -116,16 +115,17 @@ DUK_ASSERT(((duk_hobjenv *) h_objenv)->has_this == 0); DUK_ASSERT(thr->builtinsDUK_BIDX_GLOBAL_ENV != NULL); - DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL_ENV)); /* no need to decref: ROM object */ + DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE( + (duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL_ENV)); /* no need to decref: ROM object */ thr->builtinsDUK_BIDX_GLOBAL_ENV = h_objenv; DUK_HOBJECT_INCREF(thr, h_objenv); DUK_D(DUK_DPRINT("duplicated global env: %!O", h_objenv)); DUK_HOBJENV_ASSERT_VALID((duk_hobjenv *) h_objenv); - duk_pop_2(thr); /* Pop global object and global env. */ + duk_pop_2(thr); /* Pop global object and global env. */ } -#endif /* DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT */ +#endif /* DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT */ DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { /* Setup builtins from ROM objects. All heaps/threads will share @@ -149,12 +149,12 @@ duk__duplicate_ram_global_object(thr); #endif } -#else /* DUK_USE_ROM_OBJECTS */ +#else /* DUK_USE_ROM_OBJECTS */ DUK_LOCAL void duk__push_stridx(duk_hthread *thr, duk_bitdecoder_ctx *bd) { duk_small_uint_t n; n = (duk_small_uint_t) duk_bd_decode_varuint(bd); - DUK_ASSERT_DISABLE(n >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(n >= 0); /* unsigned */ DUK_ASSERT(n < DUK_HEAP_NUM_STRINGS); duk_push_hstring_stridx(thr, n); } @@ -191,16 +191,18 @@ du.uci = (duk_uint8_t) duk_bd_decode(bd, 8); } - duk_push_number(thr, du.d); /* push operation normalizes NaNs */ + duk_push_number(thr, du.d); /* push operation normalizes NaNs */ } DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { duk_bitdecoder_ctx bd_ctx; - duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ + duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ duk_hobject *h; duk_small_uint_t i, j; - DUK_D(DUK_DPRINT("INITBUILTINS BEGIN: DUK_NUM_BUILTINS=%d, DUK_NUM_BUILTINS_ALL=%d", (int) DUK_NUM_BUILTINS, (int) DUK_NUM_ALL_BUILTINS)); + DUK_D(DUK_DPRINT("INITBUILTINS BEGIN: DUK_NUM_BUILTINS=%d, DUK_NUM_BUILTINS_ALL=%d", + (int) DUK_NUM_BUILTINS, + (int) DUK_NUM_ALL_BUILTINS)); duk_memzero(&bd_ctx, sizeof(bd_ctx)); bd->data = (const duk_uint8_t *) duk_builtins_data; @@ -227,14 +229,14 @@ DUK_ASSERT_TOP(thr, 0); for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) { duk_small_uint_t class_num; - duk_small_int_t len = -1; /* must be signed */ + duk_small_int_t len = -1; /* must be signed */ class_num = (duk_small_uint_t) duk_bd_decode_varuint(bd); len = (duk_small_int_t) duk_bd_decode_flagged_signed(bd, DUK__LENGTH_PROP_BITS, (duk_int32_t) -1 /*def_value*/); if (class_num == DUK_HOBJECT_CLASS_FUNCTION) { duk_small_uint_t natidx; - duk_small_int_t c_nargs; /* must hold DUK_VARARGS */ + duk_small_int_t c_nargs; /* must hold DUK_VARARGS */ duk_c_function c_func; duk_int16_t magic; @@ -265,12 +267,9 @@ duk__push_stridx_or_string(thr, bd); #if defined(DUK_USE_FUNC_NAME_PROPERTY) - duk_xdef_prop_stridx_short(thr, - -2, - DUK_STRIDX_NAME, - DUK_PROPDESC_FLAGS_C); + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); #else - duk_pop(thr); /* Not very ideal but good enough for now. */ + duk_pop(thr); /* Not very ideal but good enough for now. */ #endif /* Almost all global level Function objects are constructable @@ -296,8 +295,7 @@ DUK_ASSERT(DUK_BIDX_GLOBAL_ENV > DUK_BIDX_GLOBAL); env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(env->target == NULL); duk_push_hobject(thr, (duk_hobject *) env); @@ -312,10 +310,8 @@ DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_DECENV); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXTENSIBLE, - -1); /* no prototype or class yet */ - + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXTENSIBLE, + -1); /* no prototype or class yet */ } h = duk_known_hobject(thr, -1); @@ -337,18 +333,15 @@ * not encoded explicitly in init data. */ - DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_ARRAY); /* .length is virtual */ + DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_ARRAY); /* .length is virtual */ duk_push_int(thr, len); - duk_xdef_prop_stridx_short(thr, - -2, - DUK_STRIDX_LENGTH, - DUK_PROPDESC_FLAGS_C); + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); } /* enable exotic behaviors last */ if (class_num == DUK_HOBJECT_CLASS_ARRAY) { - DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)); /* set by duk_push_array() */ + DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)); /* set by duk_push_array() */ } if (class_num == DUK_HOBJECT_CLASS_STRING) { DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h); @@ -365,7 +358,7 @@ DUK_ASSERT(!DUK_HOBJECT_IS_PROXY(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(h) || class_num == DUK_HOBJECT_CLASS_ARRAY); /* DUK_HOBJECT_FLAG_STRICT varies */ - DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(h) || /* all native functions have NEWENV */ + DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(h) || /* all native functions have NEWENV */ DUK_HOBJECT_HAS_NEWENV(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_NAMEBINDING(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_CREATEARGS(h)); @@ -448,11 +441,9 @@ defprop_flags = (duk_small_uint_t) duk_bd_decode_flagged(bd, DUK__PROP_FLAGS_BITS, (duk_uint32_t) DUK_PROPDESC_FLAGS_WC); - defprop_flags |= DUK_DEFPROP_FORCE | - DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | + defprop_flags |= DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE | - DUK_DEFPROP_HAVE_CONFIGURABLE; /* Defaults for data properties. */ + DUK_DEFPROP_HAVE_CONFIGURABLE; /* Defaults for data properties. */ /* The writable, enumerable, configurable flags in prop_flags * match both duk_def_prop() and internal property flags. @@ -464,7 +455,11 @@ t = (duk_small_uint_t) duk_bd_decode(bd, DUK__PROP_TYPE_BITS); DUK_DDD(DUK_DDDPRINT("built-in %ld, normal-valued property %ld, key %!T, flags 0x%02lx, type %ld", - (long) i, (long) j, duk_get_tval(thr, -1), (unsigned long) defprop_flags, (long) t)); + (long) i, + (long) j, + duk_get_tval(thr, -1), + (unsigned long) defprop_flags, + (long) t)); switch (t) { case DUK__PROP_TYPE_DOUBLE: { @@ -505,24 +500,29 @@ duk_c_function c_func_getter; duk_c_function c_func_setter; - DUK_DDD(DUK_DDDPRINT("built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx", - (long) i, duk_get_tval(thr, -1), (long) natidx_getter, (long) natidx_setter, (unsigned long) defprop_flags)); + DUK_DDD(DUK_DDDPRINT( + "built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx", + (long) i, + duk_get_tval(thr, -1), + (long) natidx_getter, + (long) natidx_setter, + (unsigned long) defprop_flags)); c_func_getter = duk_bi_native_functionsnatidx_getter; if (c_func_getter != NULL) { - duk_push_c_function_builtin_noconstruct(thr, c_func_getter, 0); /* always 0 args */ + duk_push_c_function_builtin_noconstruct(thr, c_func_getter, 0); /* always 0 args */ duk_set_magic(thr, -1, (duk_int_t) accessor_magic); defprop_flags |= DUK_DEFPROP_HAVE_GETTER; } c_func_setter = duk_bi_native_functionsnatidx_setter; if (c_func_setter != NULL) { - duk_push_c_function_builtin_noconstruct(thr, c_func_setter, 1); /* always 1 arg */ + duk_push_c_function_builtin_noconstruct(thr, c_func_setter, 1); /* always 1 arg */ duk_set_magic(thr, -1, (duk_int_t) accessor_magic); defprop_flags |= DUK_DEFPROP_HAVE_SETTER; } /* Writable flag doesn't make sense for an accessor. */ - DUK_ASSERT((defprop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */ + DUK_ASSERT((defprop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */ defprop_flags &= ~(DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE); defprop_flags |= DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE; @@ -544,7 +544,7 @@ for (j = 0; j < num; j++) { duk_hstring *h_key; duk_small_uint_t natidx; - duk_int_t c_nargs; /* must hold DUK_VARARGS */ + duk_int_t c_nargs; /* must hold DUK_VARARGS */ duk_small_uint_t c_length; duk_int16_t magic; duk_c_function c_func; @@ -567,51 +567,66 @@ c_func = duk_bi_native_functionsnatidx; - DUK_DDD(DUK_DDDPRINT("built-in %ld, function-valued property %ld, key %!O, natidx %ld, length %ld, nargs %ld", - (long) i, (long) j, (duk_heaphdr *) h_key, (long) natidx, (long) c_length, - (c_nargs == DUK_VARARGS ? (long) -1 : (long) c_nargs))); + DUK_DDD( + DUK_DDDPRINT("built-in %ld, function-valued property %ld, key %!O, natidx %ld, length %ld, nargs %ld", + (long) i, + (long) j, + (duk_heaphdr *) h_key, + (long) natidx, + (long) c_length, + (c_nargs == DUK_VARARGS ? (long) -1 : (long) c_nargs))); /* Cast converts magic to 16-bit signed value */ magic = (duk_int16_t) duk_bd_decode_varuint(bd); #if defined(DUK_USE_LIGHTFUNC_BUILTINS) lightfunc_eligible = - ((c_nargs >= DUK_LFUNC_NARGS_MIN && c_nargs <= DUK_LFUNC_NARGS_MAX) || (c_nargs == DUK_VARARGS)) && - (c_length <= DUK_LFUNC_LENGTH_MAX) && - (magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX); + ((c_nargs >= DUK_LFUNC_NARGS_MIN && c_nargs <= DUK_LFUNC_NARGS_MAX) || (c_nargs == DUK_VARARGS)) && + (c_length <= DUK_LFUNC_LENGTH_MAX) && (magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX); /* These functions have trouble working as lightfuncs. * Some of them have specific asserts and some may have - * additional properties (e.g. 'require.id' may be written). + * additional properties (e.g. 'require.id' may be written). */ if (c_func == duk_bi_global_object_eval) { lightfunc_eligible = 0; } #if defined(DUK_USE_COROUTINE_SUPPORT) - if (c_func == duk_bi_thread_yield || - c_func == duk_bi_thread_resume) { + if (c_func == duk_bi_thread_yield || c_func == duk_bi_thread_resume) { lightfunc_eligible = 0; } #endif - if (c_func == duk_bi_function_prototype_call || - c_func == duk_bi_function_prototype_apply || - c_func == duk_bi_reflect_apply || - c_func == duk_bi_reflect_construct) { + if (c_func == duk_bi_function_prototype_call || c_func == duk_bi_function_prototype_apply || + c_func == duk_bi_reflect_apply || c_func == duk_bi_reflect_construct) { lightfunc_eligible = 0; } if (lightfunc_eligible) { duk_tval tv_lfunc; - duk_small_uint_t lf_nargs = (duk_small_uint_t) (c_nargs == DUK_VARARGS ? DUK_LFUNC_NARGS_VARARGS : c_nargs); + duk_small_uint_t lf_nargs = + (duk_small_uint_t) (c_nargs == DUK_VARARGS ? DUK_LFUNC_NARGS_VARARGS : c_nargs); duk_small_uint_t lf_flags = DUK_LFUNC_FLAGS_PACK(magic, c_length, lf_nargs); DUK_TVAL_SET_LIGHTFUNC(&tv_lfunc, c_func, lf_flags); duk_push_tval(thr, &tv_lfunc); - DUK_D(DUK_DPRINT("built-in function eligible as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld -> %!iT", (int) i, (int) j, (long) c_length, (long) c_nargs, (long) magic, duk_get_tval(thr, -1))); + DUK_D(DUK_DPRINT("built-in function eligible as light function: i=%d, j=%d c_length=%ld, " + "c_nargs=%ld, magic=%ld -> %!iT", + (int) i, + (int) j, + (long) c_length, + (long) c_nargs, + (long) magic, + duk_get_tval(thr, -1))); goto lightfunc_skip; } - DUK_D(DUK_DPRINT("built-in function NOT ELIGIBLE as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld", (int) i, (int) j, (long) c_length, (long) c_nargs, (long) magic)); -#endif /* DUK_USE_LIGHTFUNC_BUILTINS */ + DUK_D(DUK_DPRINT( + "built-in function NOT ELIGIBLE as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld", + (int) i, + (int) j, + (long) c_length, + (long) c_nargs, + (long) magic)); +#endif /* DUK_USE_LIGHTFUNC_BUILTINS */ /* (builtin objects) name */ @@ -622,10 +637,8 @@ /* XXX: add into init data? */ /* Special call handling, not described in init data. */ - if (c_func == duk_bi_global_object_eval || - c_func == duk_bi_function_prototype_call || - c_func == duk_bi_function_prototype_apply || - c_func == duk_bi_reflect_apply || + if (c_func == duk_bi_global_object_eval || c_func == duk_bi_function_prototype_call || + c_func == duk_bi_function_prototype_apply || c_func == duk_bi_reflect_apply || c_func == duk_bi_reflect_construct) { DUK_HOBJECT_SET_SPECIAL_CALL((duk_hobject *) h_func); } @@ -659,7 +672,9 @@ /* XXX: other properties of function instances; 'arguments', 'caller'. */ DUK_DD(DUK_DDPRINT("built-in object %ld, function property %ld -> %!T", - (long) i, (long) j, (duk_tval *) duk_get_tval(thr, -1))); + (long) i, + (long) j, + (duk_tval *) duk_get_tval(thr, -1))); /* (builtin objects) name func */ @@ -669,17 +684,14 @@ */ #if defined(DUK_USE_LIGHTFUNC_BUILTINS) - lightfunc_skip: + lightfunc_skip: #endif defprop_flags = (duk_small_uint_t) duk_bd_decode_flagged(bd, DUK__PROP_FLAGS_BITS, (duk_uint32_t) DUK_PROPDESC_FLAGS_WC); - defprop_flags |= DUK_DEFPROP_FORCE | - DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | - DUK_DEFPROP_HAVE_ENUMERABLE | - DUK_DEFPROP_HAVE_CONFIGURABLE; + defprop_flags |= DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | + DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE; DUK_ASSERT(DUK_PROPDESC_FLAG_WRITABLE == DUK_DEFPROP_WRITABLE); DUK_ASSERT(DUK_PROPDESC_FLAG_ENUMERABLE == DUK_DEFPROP_ENUMERABLE); DUK_ASSERT(DUK_PROPDESC_FLAG_CONFIGURABLE == DUK_DEFPROP_CONFIGURABLE); @@ -717,22 +729,28 @@ #if !defined(DUK_USE_ES6_OBJECT_PROTO_PROPERTY) DUK_DD(DUK_DDPRINT("delete Object.prototype.__proto__ built-in which is not enabled in features")); - (void) duk_hobject_delprop_raw(thr, thr->builtinsDUK_BIDX_OBJECT_PROTOTYPE, DUK_HTHREAD_STRING___PROTO__(thr), DUK_DELPROP_FLAG_THROW); + (void) duk_hobject_delprop_raw(thr, + thr->builtinsDUK_BIDX_OBJECT_PROTOTYPE, + DUK_HTHREAD_STRING___PROTO__(thr), + DUK_DELPROP_FLAG_THROW); #endif #if !defined(DUK_USE_ES6_OBJECT_SETPROTOTYPEOF) DUK_DD(DUK_DDPRINT("delete Object.setPrototypeOf built-in which is not enabled in features")); - (void) duk_hobject_delprop_raw(thr, thr->builtinsDUK_BIDX_OBJECT_CONSTRUCTOR, DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr), DUK_DELPROP_FLAG_THROW); + (void) duk_hobject_delprop_raw(thr, + thr->builtinsDUK_BIDX_OBJECT_CONSTRUCTOR, + DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr), + DUK_DELPROP_FLAG_THROW); #endif /* XXX: relocate */ duk_push_string(thr, - /* Endianness indicator */ + /* Endianness indicator */ #if defined(DUK_USE_INTEGER_LE) "l" #elif defined(DUK_USE_INTEGER_BE) "b" -#elif defined(DUK_USE_INTEGER_ME) /* integer mixed endian not really used now */ +#elif defined(DUK_USE_INTEGER_ME) /* integer mixed endian not really used now */ "m" #else "?" @@ -747,89 +765,85 @@ "?" #endif " " - /* Packed or unpacked tval */ + /* Packed or unpacked tval */ #if defined(DUK_USE_PACKED_TVAL) "p" #else "u" #endif #if defined(DUK_USE_FASTINT) - "f" + "f" #endif - " " - /* Low memory/performance options */ + " " + /* Low memory/performance options */ #if defined(DUK_USE_STRTAB_PTRCOMP) - "s" + "s" #endif #if !defined(DUK_USE_HEAPPTR16) && !defined(DUK_DATAPTR16) && !defined(DUK_FUNCPTR16) - "n" + "n" #endif #if defined(DUK_USE_HEAPPTR16) - "h" + "h" #endif #if defined(DUK_USE_DATAPTR16) - "d" + "d" #endif #if defined(DUK_USE_FUNCPTR16) - "f" + "f" #endif #if defined(DUK_USE_REFCOUNT16) - "R" + "R" #endif #if defined(DUK_USE_STRHASH16) - "H" + "H" #endif #if defined(DUK_USE_STRLEN16) - "S" + "S" #endif #if defined(DUK_USE_BUFLEN16) - "B" + "B" #endif #if defined(DUK_USE_OBJSIZES16) - "O" + "O" #endif #if defined(DUK_USE_LIGHTFUNC_BUILTINS) - "L" + "L" #endif #if defined(DUK_USE_ROM_STRINGS) || defined(DUK_USE_ROM_OBJECTS) - /* XXX: This won't be shown in practice now - * because this code is not run when builtins - * are in ROM. - */ - "Z" + /* XXX: This won't be shown in practice now + * because this code is not run when builtins + * are in ROM. + */ + "Z" #endif #if defined(DUK_USE_LITCACHE_SIZE) - "l" + "l" #endif " " - /* Object property allocation layout */ + /* Object property allocation layout */ #if defined(DUK_USE_HOBJECT_LAYOUT_1) - "p1" + "p1" #elif defined(DUK_USE_HOBJECT_LAYOUT_2) - "p2" + "p2" #elif defined(DUK_USE_HOBJECT_LAYOUT_3) - "p3" + "p3" #else - "p?" + "p?" #endif - " " - /* Alignment guarantee */ + " " + /* Alignment guarantee */ #if (DUK_USE_ALIGN_BY == 4) - "a4" + "a4" #elif (DUK_USE_ALIGN_BY == 8) - "a8" + "a8" #elif (DUK_USE_ALIGN_BY == 1) - "a1" + "a1" #else #error invalid DUK_USE_ALIGN_BY #endif - " " - /* Architecture, OS, and compiler strings */ - DUK_USE_ARCH_STRING - " " - DUK_USE_OS_STRING - " " - DUK_USE_COMPILER_STRING); + " " + /* Architecture, OS, and compiler strings */ + DUK_USE_ARCH_STRING " " DUK_USE_OS_STRING " " DUK_USE_COMPILER_STRING); duk_xdef_prop_stridx_short(thr, DUK_BIDX_DUKTAPE, DUK_STRIDX_ENV, DUK_PROPDESC_FLAGS_WC); /* @@ -846,7 +860,8 @@ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) { DUK_DD(DUK_DDPRINT("built-in object %ld after initialization and compacting: %!@iO", - (long) i, (duk_heaphdr *) duk_require_hobject(thr, (duk_idx_t) i))); + (long) i, + (duk_heaphdr *) duk_require_hobject(thr, (duk_idx_t) i))); } #endif @@ -859,13 +874,13 @@ duk_set_top(thr, 0); DUK_ASSERT_TOP(thr, 0); } -#endif /* DUK_USE_ROM_OBJECTS */ +#endif /* DUK_USE_ROM_OBJECTS */ DUK_INTERNAL void duk_hthread_copy_builtin_objects(duk_hthread *thr_from, duk_hthread *thr_to) { duk_small_uint_t i; for (i = 0; i < DUK_NUM_BUILTINS; i++) { thr_to->builtinsi = thr_from->builtinsi; - DUK_HOBJECT_INCREF_ALLOWNULL(thr_to, thr_to->builtinsi); /* side effect free */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr_to, thr_to->builtinsi); /* side effect free */ } }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hthread_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hthread_misc.c
Changed
@@ -12,7 +12,7 @@ } thr->valstack_bottom = thr->valstack; - duk_set_top(thr, 0); /* unwinds valstack, updating refcounts */ + duk_set_top(thr, 0); /* unwinds valstack, updating refcounts */ thr->state = DUK_HTHREAD_STATE_TERMINATED; @@ -43,7 +43,7 @@ } return 0; } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ DUK_INTERNAL duk_uint_fast32_t duk_hthread_get_act_prev_pc(duk_hthread *thr, duk_activation *act) { duk_instr_t *bcode;
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_hthread_stacks.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_hthread_stacks.c
Changed
@@ -15,7 +15,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(act != NULL); - DUK_ASSERT(act->cat != NULL); /* caller must check */ + DUK_ASSERT(act->cat != NULL); /* caller must check */ cat = act->cat; DUK_ASSERT(cat != NULL); @@ -24,9 +24,9 @@ if (DUK_CAT_HAS_LEXENV_ACTIVE(cat)) { duk_hobject *env; - env = act->lex_env; /* current lex_env of the activation (created for catcher) */ - DUK_ASSERT(env != NULL); /* must be, since env was created when catcher was created */ - act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); /* prototype is lex_env before catcher created */ + env = act->lex_env; /* current lex_env of the activation (created for catcher) */ + DUK_ASSERT(env != NULL); /* must be, since env was created when catcher was created */ + act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); /* prototype is lex_env before catcher created */ DUK_HOBJECT_INCREF(thr, act->lex_env); DUK_HOBJECT_DECREF_NORZ(thr, env); @@ -45,7 +45,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(act != NULL); - DUK_ASSERT(act->cat != NULL); /* caller must check */ + DUK_ASSERT(act->cat != NULL); /* caller must check */ cat = act->cat; DUK_ASSERT(cat != NULL); @@ -83,11 +83,11 @@ return duk__hthread_catcher_alloc_slow(thr); } -#else /* DUK_USE_CACHE_CATCHER */ +#else /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL duk_catcher *duk_hthread_catcher_alloc(duk_hthread *thr) { return duk__hthread_catcher_alloc_slow(thr); } -#endif /* DUK_USE_CACHE_CATCHER */ +#endif /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL void duk_hthread_catcher_free(duk_hthread *thr, duk_catcher *cat) { DUK_ASSERT(thr != NULL); @@ -128,12 +128,11 @@ return duk__hthread_activation_alloc_slow(thr); } -#else /* DUK_USE_CACHE_ACTIVATION */ +#else /* DUK_USE_CACHE_ACTIVATION */ DUK_INTERNAL duk_activation *duk_hthread_activation_alloc(duk_hthread *thr) { return duk__hthread_activation_alloc_slow(thr); } -#endif /* DUK_USE_CACHE_ACTIVATION */ - +#endif /* DUK_USE_CACHE_ACTIVATION */ DUK_INTERNAL void duk_hthread_activation_free(duk_hthread *thr, duk_activation *act) { DUK_ASSERT(thr != NULL); @@ -160,7 +159,7 @@ duk_hobject *tmp; DUK_ASSERT(thr != NULL); - DUK_ASSERT(thr->callstack_curr != NULL); /* caller must check */ + DUK_ASSERT(thr->callstack_curr != NULL); /* caller must check */ DUK_ASSERT(thr->callstack_top > 0); act = thr->callstack_curr; DUK_ASSERT(act != NULL); @@ -197,7 +196,7 @@ DUK_TVAL_SET_OBJECT(tv_caller, act->prev_caller); act->prev_caller = NULL; } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref needed */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref needed */ DUK_ASSERT(act->prev_caller == NULL); } DUK_TVAL_DECREF_NORZ(thr, &tv_tmp); @@ -226,7 +225,7 @@ duk_debug_set_paused(heap); } else { DUK_D(DUK_DPRINT("unwound past dbg_pause_act, set to NULL")); - heap->dbg_pause_act = NULL; /* avoid stale pointers */ + heap->dbg_pause_act = NULL; /* avoid stale pointers */ } DUK_ASSERT(heap->dbg_pause_act == NULL); } @@ -275,12 +274,11 @@ * fixed e.g. by preallocating the scope property slots. */ if (act->var_env != NULL) { - DUK_DDD(DUK_DDDPRINT("closing var_env record %p -> %!O", - (void *) act->var_env, (duk_heaphdr *) act->var_env)); + DUK_DDD(DUK_DDDPRINT("closing var_env record %p -> %!O", (void *) act->var_env, (duk_heaphdr *) act->var_env)); duk_js_close_environment_record(thr, act->var_env); } - skip_env_close: +skip_env_close: /* * Update preventcount @@ -404,4 +402,4 @@ DUK_D(DUK_DPRINT("failed to realloc valstack for torture, ignore")); } } -#endif /* DUK_USE_FINALIZER_TORTURE */ +#endif /* DUK_USE_FINALIZER_TORTURE */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_internal.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_internal.h
Changed
@@ -40,8 +40,8 @@ #include "duk_jmpbuf.h" #include "duk_exception.h" #include "duk_forwdecl.h" -#include "duk_tval.h" /* builtins need e.g. duk_tval tag definitions */ -#include "duk_builtins.h" /* autogenerated: strings and built-in object init data */ +#include "duk_tval.h" /* builtins need e.g. duk_tval tag definitions */ +#include "duk_builtins.h" /* autogenerated: strings and built-in object init data */ #include "duk_util.h" #include "duk_strings.h" @@ -74,4 +74,4 @@ #include "duk_bi_protos.h" #include "duk_selftest.h" -#endif /* DUK_INTERNAL_H_INCLUDED */ +#endif /* DUK_INTERNAL_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_jmpbuf.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_jmpbuf.h
Changed
@@ -13,7 +13,7 @@ #if defined(DUK_USE_CPP_EXCEPTIONS) struct duk_jmpbuf { - duk_small_int_t dummy; /* unused */ + duk_small_int_t dummy; /* unused */ }; #else struct duk_jmpbuf { @@ -21,4 +21,4 @@ }; #endif -#endif /* DUK_JMPBUF_H_INCLUDED */ +#endif /* DUK_JMPBUF_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_js.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_js.h
Changed
@@ -6,21 +6,22 @@ #define DUK_JS_H_INCLUDED /* Flags for call handling. Lowest flags must match bytecode DUK_BC_CALL_FLAG_xxx 1:1. */ -#define DUK_CALL_FLAG_TAILCALL (1U << 0) /* setup for a tail call */ -#define DUK_CALL_FLAG_CONSTRUCT (1U << 1) /* constructor call (i.e. called as 'new Foo()') */ -#define DUK_CALL_FLAG_CALLED_AS_EVAL (1U << 2) /* call was made using the identifier 'eval' */ -#define DUK_CALL_FLAG_ALLOW_ECMATOECMA (1U << 3) /* ecma-to-ecma call with executor reuse is possible */ -#define DUK_CALL_FLAG_DIRECT_EVAL (1U << 4) /* call is a direct eval call */ -#define DUK_CALL_FLAG_CONSTRUCT_PROXY (1U << 5) /* handled via 'construct' proxy trap, check return value invariant(s) */ -#define DUK_CALL_FLAG_DEFAULT_INSTANCE_UPDATED (1U << 6) /* prototype of 'default instance' updated, temporary flag in call handling */ +#define DUK_CALL_FLAG_TAILCALL (1U << 0) /* setup for a tail call */ +#define DUK_CALL_FLAG_CONSTRUCT (1U << 1) /* constructor call (i.e. called as 'new Foo()') */ +#define DUK_CALL_FLAG_CALLED_AS_EVAL (1U << 2) /* call was made using the identifier 'eval' */ +#define DUK_CALL_FLAG_ALLOW_ECMATOECMA (1U << 3) /* ecma-to-ecma call with executor reuse is possible */ +#define DUK_CALL_FLAG_DIRECT_EVAL (1U << 4) /* call is a direct eval call */ +#define DUK_CALL_FLAG_CONSTRUCT_PROXY (1U << 5) /* handled via 'construct' proxy trap, check return value invariant(s) */ +#define DUK_CALL_FLAG_DEFAULT_INSTANCE_UPDATED \ + (1U << 6) /* prototype of 'default instance' updated, temporary flag in call handling */ /* Flags for duk_js_equals_helper(). */ -#define DUK_EQUALS_FLAG_SAMEVALUE (1U << 0) /* use SameValue instead of non-strict equality */ -#define DUK_EQUALS_FLAG_STRICT (1U << 1) /* use strict equality instead of non-strict equality */ +#define DUK_EQUALS_FLAG_SAMEVALUE (1U << 0) /* use SameValue instead of non-strict equality */ +#define DUK_EQUALS_FLAG_STRICT (1U << 1) /* use strict equality instead of non-strict equality */ /* Flags for duk_js_compare_helper(). */ -#define DUK_COMPARE_FLAG_NEGATE (1U << 0) /* negate result */ -#define DUK_COMPARE_FLAG_EVAL_LEFT_FIRST (1U << 1) /* eval left argument first */ +#define DUK_COMPARE_FLAG_NEGATE (1U << 0) /* negate result */ +#define DUK_COMPARE_FLAG_EVAL_LEFT_FIRST (1U << 1) /* eval left argument first */ /* conversions, coercions, comparison, etc */ DUK_INTERNAL_DECL duk_bool_t duk_js_toboolean(duk_tval *tv); @@ -36,9 +37,12 @@ DUK_INTERNAL_DECL duk_uarridx_t duk_js_to_arrayindex_hstring_fast(duk_hstring *h); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_equals_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags); -DUK_INTERNAL_DECL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, const duk_uint8_t *buf2, duk_size_t len1, duk_size_t len2); +DUK_INTERNAL_DECL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, + const duk_uint8_t *buf2, + duk_size_t len1, + duk_size_t len2); DUK_INTERNAL_DECL duk_small_int_t duk_js_string_compare(duk_hstring *h1, duk_hstring *h2); -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL_DECL duk_small_int_t duk_js_buffer_compare(duk_heap *heap, duk_hbuffer *h1, duk_hbuffer *h2); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_compare_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags); @@ -55,45 +59,57 @@ DUK_INTERNAL_DECL double duk_js_arith_pow(double x, double y); DUK_INTERNAL_DECL double duk_js_arith_mod(double x, double y); -#define duk_js_equals(thr,tv_x,tv_y) \ - duk_js_equals_helper((thr), (tv_x), (tv_y), 0) -#define duk_js_strict_equals(tv_x,tv_y) \ - duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_STRICT) -#define duk_js_samevalue(tv_x,tv_y) \ - duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_SAMEVALUE) +#define duk_js_equals(thr, tv_x, tv_y) duk_js_equals_helper((thr), (tv_x), (tv_y), 0) +#define duk_js_strict_equals(tv_x, tv_y) duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_STRICT) +#define duk_js_samevalue(tv_x, tv_y) duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_SAMEVALUE) /* E5 Sections 11.8.1, 11.8.5; x < y */ -#define duk_js_lessthan(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_x), (tv_Y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) +#define duk_js_lessthan(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_x), (tv_Y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) /* E5 Sections 11.8.2, 11.8.5; x > y --> y < x */ -#define duk_js_greaterthan(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_y), (tv_x), 0) +#define duk_js_greaterthan(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_y), (tv_x), 0) /* E5 Sections 11.8.3, 11.8.5; x <= y --> not (x > y) --> not (y < x) */ -#define duk_js_lessthanorequal(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_y), (tv_x), DUK_COMPARE_FLAG_NEGATE) +#define duk_js_lessthanorequal(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_y), (tv_x), DUK_COMPARE_FLAG_NEGATE) /* E5 Sections 11.8.4, 11.8.5; x >= y --> not (x < y) */ -#define duk_js_greaterthanorequal(thr,tv_x,tv_y) \ +#define duk_js_greaterthanorequal(thr, tv_x, tv_y) \ duk_js_compare_helper((thr), (tv_x), (tv_y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) /* identifiers and environment handling */ -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_hasvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_bool_t throw_flag); -DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag); -DUK_INTERNAL_DECL void duk_js_putvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_tval *val, duk_bool_t strict); -DUK_INTERNAL_DECL void duk_js_putvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_bool_t strict); -#if 0 /*unused*/ +DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_bool_t throw_flag); +DUK_INTERNAL_DECL void duk_js_putvar_envrec(duk_hthread *thr, + duk_hobject *env, + duk_hstring *name, + duk_tval *val, + duk_bool_t strict); +DUK_INTERNAL_DECL void duk_js_putvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_tval *val, + duk_bool_t strict); +#if 0 /*unused*/ DUK_INTERNAL_DECL duk_bool_t duk_js_delvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_delvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name); -DUK_INTERNAL_DECL duk_bool_t duk_js_declvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_small_uint_t prop_flags, duk_bool_t is_func_decl); +DUK_INTERNAL_DECL duk_bool_t duk_js_declvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_tval *val, + duk_small_uint_t prop_flags, + duk_bool_t is_func_decl); DUK_INTERNAL_DECL void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, duk_activation *act); DUK_INTERNAL_DECL void duk_js_close_environment_record(duk_hthread *thr, duk_hobject *env); -DUK_INTERNAL_DECL duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, duk_hobject *func, duk_size_t bottom_byteoff); +DUK_INTERNAL_DECL duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, + duk_hobject *func, + duk_size_t bottom_byteoff); DUK_INTERNAL_DECL void duk_js_push_closure(duk_hthread *thr, duk_hcompfunc *fun_temp, duk_hobject *outer_var_env, @@ -104,7 +120,8 @@ DUK_INTERNAL_DECL void duk_native_stack_check(duk_hthread *thr); DUK_INTERNAL_DECL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags); DUK_INTERNAL_DECL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags); -DUK_INTERNAL_DECL duk_int_t duk_handle_safe_call(duk_hthread *thr, duk_safe_call_function func, void *udata, duk_idx_t num_stack_args, duk_idx_t num_stack_res); +DUK_INTERNAL_DECL duk_int_t +duk_handle_safe_call(duk_hthread *thr, duk_safe_call_function func, void *udata, duk_idx_t num_stack_args, duk_idx_t num_stack_res); DUK_INTERNAL_DECL void duk_call_construct_postprocess(duk_hthread *thr, duk_small_uint_t proxy_invariant); #if defined(DUK_USE_VERBOSE_ERRORS) DUK_INTERNAL_DECL void duk_call_setup_propcall_error(duk_hthread *thr, duk_tval *tv_base, duk_tval *tv_key); @@ -113,4 +130,4 @@ /* bytecode execution */ DUK_INTERNAL_DECL void duk_js_execute_bytecode(duk_hthread *exec_thr); -#endif /* DUK_JS_H_INCLUDED */ +#endif /* DUK_JS_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_js_arith.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_js_arith.c
Changed
@@ -41,10 +41,14 @@ DUK_ASSERT(DUK_ISNAN(DUK_FMOD(-DUK_DOUBLE_INFINITY, -DUK_DOUBLE_INFINITY))); DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, 1.0), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, 1.0)) == 0); DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, 1.0), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, 1.0)) != 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY)) != 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, -DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY)) != 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY)) != 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, -DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY)) != 0); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(0.0, 0.0))); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(-0.0, 0.0))); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(0.0, -0.0))); @@ -132,6 +136,6 @@ return DUK_POW(x, y); - ret_nan: +ret_nan: return DUK_DOUBLE_NAN; }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_js_bytecode.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_js_bytecode.h
Changed
@@ -83,400 +83,391 @@ typedef duk_uint32_t duk_instr_t; -#define DUK_BC_SHIFT_OP 0 -#define DUK_BC_SHIFT_A 8 -#define DUK_BC_SHIFT_B 16 -#define DUK_BC_SHIFT_C 24 -#define DUK_BC_SHIFT_BC DUK_BC_SHIFT_B -#define DUK_BC_SHIFT_ABC DUK_BC_SHIFT_A +#define DUK_BC_SHIFT_OP 0 +#define DUK_BC_SHIFT_A 8 +#define DUK_BC_SHIFT_B 16 +#define DUK_BC_SHIFT_C 24 +#define DUK_BC_SHIFT_BC DUK_BC_SHIFT_B +#define DUK_BC_SHIFT_ABC DUK_BC_SHIFT_A -#define DUK_BC_UNSHIFTED_MASK_OP 0xffUL -#define DUK_BC_UNSHIFTED_MASK_A 0xffUL -#define DUK_BC_UNSHIFTED_MASK_B 0xffUL -#define DUK_BC_UNSHIFTED_MASK_C 0xffUL -#define DUK_BC_UNSHIFTED_MASK_BC 0xffffUL -#define DUK_BC_UNSHIFTED_MASK_ABC 0xffffffUL +#define DUK_BC_UNSHIFTED_MASK_OP 0xffUL +#define DUK_BC_UNSHIFTED_MASK_A 0xffUL +#define DUK_BC_UNSHIFTED_MASK_B 0xffUL +#define DUK_BC_UNSHIFTED_MASK_C 0xffUL +#define DUK_BC_UNSHIFTED_MASK_BC 0xffffUL +#define DUK_BC_UNSHIFTED_MASK_ABC 0xffffffUL -#define DUK_BC_SHIFTED_MASK_OP (DUK_BC_UNSHIFTED_MASK_OP << DUK_BC_SHIFT_OP) -#define DUK_BC_SHIFTED_MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK_BC_SHIFT_A) -#define DUK_BC_SHIFTED_MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK_BC_SHIFT_B) -#define DUK_BC_SHIFTED_MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK_BC_SHIFT_C) -#define DUK_BC_SHIFTED_MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK_BC_SHIFT_BC) -#define DUK_BC_SHIFTED_MASK_ABC (DUK_BC_UNSHIFTED_MASK_ABC << DUK_BC_SHIFT_ABC) +#define DUK_BC_SHIFTED_MASK_OP (DUK_BC_UNSHIFTED_MASK_OP << DUK_BC_SHIFT_OP) +#define DUK_BC_SHIFTED_MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK_BC_SHIFT_A) +#define DUK_BC_SHIFTED_MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK_BC_SHIFT_B) +#define DUK_BC_SHIFTED_MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK_BC_SHIFT_C) +#define DUK_BC_SHIFTED_MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK_BC_SHIFT_BC) +#define DUK_BC_SHIFTED_MASK_ABC (DUK_BC_UNSHIFTED_MASK_ABC << DUK_BC_SHIFT_ABC) -#define DUK_DEC_OP(x) ((x) & 0xffUL) -#define DUK_DEC_A(x) (((x) >> 8) & 0xffUL) -#define DUK_DEC_B(x) (((x) >> 16) & 0xffUL) -#define DUK_DEC_C(x) (((x) >> 24) & 0xffUL) -#define DUK_DEC_BC(x) (((x) >> 16) & 0xffffUL) -#define DUK_DEC_ABC(x) (((x) >> 8) & 0xffffffUL) +#define DUK_DEC_OP(x) ((x) &0xffUL) +#define DUK_DEC_A(x) (((x) >> 8) & 0xffUL) +#define DUK_DEC_B(x) (((x) >> 16) & 0xffUL) +#define DUK_DEC_C(x) (((x) >> 24) & 0xffUL) +#define DUK_DEC_BC(x) (((x) >> 16) & 0xffffUL) +#define DUK_DEC_ABC(x) (((x) >> 8) & 0xffffffUL) -#define DUK_ENC_OP(op) ((duk_instr_t) (op)) -#define DUK_ENC_OP_ABC(op,abc) ((duk_instr_t) ( \ - (((duk_instr_t) (abc)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_BC(op,a,bc) ((duk_instr_t) ( \ - (((duk_instr_t) (bc)) << 16) | \ - (((duk_instr_t) (a)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_B_C(op,a,b,c) ((duk_instr_t) ( \ - (((duk_instr_t) (c)) << 24) | \ - (((duk_instr_t) (b)) << 16) | \ - (((duk_instr_t) (a)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_B(op,a,b) DUK_ENC_OP_A_B_C((op),(a),(b),0) -#define DUK_ENC_OP_A(op,a) DUK_ENC_OP_A_B_C((op),(a),0,0) -#define DUK_ENC_OP_BC(op,bc) DUK_ENC_OP_A_BC((op),0,(bc)) +#define DUK_ENC_OP(op) ((duk_instr_t) (op)) +#define DUK_ENC_OP_ABC(op, abc) ((duk_instr_t) ((((duk_instr_t) (abc)) << 8) | ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_BC(op, a, bc) \ + ((duk_instr_t) ((((duk_instr_t) (bc)) << 16) | (((duk_instr_t) (a)) << 8) | ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_B_C(op, a, b, c) \ + ((duk_instr_t) ((((duk_instr_t) (c)) << 24) | (((duk_instr_t) (b)) << 16) | (((duk_instr_t) (a)) << 8) | \ + ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_B(op, a, b) DUK_ENC_OP_A_B_C((op), (a), (b), 0) +#define DUK_ENC_OP_A(op, a) DUK_ENC_OP_A_B_C((op), (a), 0, 0) +#define DUK_ENC_OP_BC(op, bc) DUK_ENC_OP_A_BC((op), 0, (bc)) /* Get opcode base value with B/C reg/const flags cleared. */ -#define DUK_BC_NOREGCONST_OP(op) ((op) & 0xfc) +#define DUK_BC_NOREGCONST_OP(op) ((op) &0xfc) /* Constants should be signed so that signed arithmetic involving them * won't cause values to be coerced accidentally to unsigned. */ -#define DUK_BC_OP_MIN 0 -#define DUK_BC_OP_MAX 0xffL -#define DUK_BC_A_MIN 0 -#define DUK_BC_A_MAX 0xffL -#define DUK_BC_B_MIN 0 -#define DUK_BC_B_MAX 0xffL -#define DUK_BC_C_MIN 0 -#define DUK_BC_C_MAX 0xffL -#define DUK_BC_BC_MIN 0 -#define DUK_BC_BC_MAX 0xffffL -#define DUK_BC_ABC_MIN 0 -#define DUK_BC_ABC_MAX 0xffffffL +#define DUK_BC_OP_MIN 0 +#define DUK_BC_OP_MAX 0xffL +#define DUK_BC_A_MIN 0 +#define DUK_BC_A_MAX 0xffL +#define DUK_BC_B_MIN 0 +#define DUK_BC_B_MAX 0xffL +#define DUK_BC_C_MIN 0 +#define DUK_BC_C_MAX 0xffL +#define DUK_BC_BC_MIN 0 +#define DUK_BC_BC_MAX 0xffffL +#define DUK_BC_ABC_MIN 0 +#define DUK_BC_ABC_MAX 0xffffffL /* Masks for B/C reg/const indicator in opcode field. */ -#define DUK_BC_REGCONST_B (0x01UL) -#define DUK_BC_REGCONST_C (0x02UL) +#define DUK_BC_REGCONST_B (0x01UL) +#define DUK_BC_REGCONST_C (0x02UL) /* Misc. masks for opcode field. */ -#define DUK_BC_INCDECP_FLAG_DEC (0x04UL) -#define DUK_BC_INCDECP_FLAG_POST (0x08UL) +#define DUK_BC_INCDECP_FLAG_DEC (0x04UL) +#define DUK_BC_INCDECP_FLAG_POST (0x08UL) /* Opcodes. */ -#define DUK_OP_LDREG 0 -#define DUK_OP_STREG 1 -#define DUK_OP_JUMP 2 -#define DUK_OP_LDCONST 3 -#define DUK_OP_LDINT 4 -#define DUK_OP_LDINTX 5 -#define DUK_OP_LDTHIS 6 -#define DUK_OP_LDUNDEF 7 -#define DUK_OP_LDNULL 8 -#define DUK_OP_LDTRUE 9 -#define DUK_OP_LDFALSE 10 -#define DUK_OP_GETVAR 11 -#define DUK_OP_BNOT 12 -#define DUK_OP_LNOT 13 -#define DUK_OP_UNM 14 -#define DUK_OP_UNP 15 -#define DUK_OP_EQ 16 -#define DUK_OP_EQ_RR 16 -#define DUK_OP_EQ_CR 17 -#define DUK_OP_EQ_RC 18 -#define DUK_OP_EQ_CC 19 -#define DUK_OP_NEQ 20 -#define DUK_OP_NEQ_RR 20 -#define DUK_OP_NEQ_CR 21 -#define DUK_OP_NEQ_RC 22 -#define DUK_OP_NEQ_CC 23 -#define DUK_OP_SEQ 24 -#define DUK_OP_SEQ_RR 24 -#define DUK_OP_SEQ_CR 25 -#define DUK_OP_SEQ_RC 26 -#define DUK_OP_SEQ_CC 27 -#define DUK_OP_SNEQ 28 -#define DUK_OP_SNEQ_RR 28 -#define DUK_OP_SNEQ_CR 29 -#define DUK_OP_SNEQ_RC 30 -#define DUK_OP_SNEQ_CC 31 -#define DUK_OP_GT 32 -#define DUK_OP_GT_RR 32 -#define DUK_OP_GT_CR 33 -#define DUK_OP_GT_RC 34 -#define DUK_OP_GT_CC 35 -#define DUK_OP_GE 36 -#define DUK_OP_GE_RR 36 -#define DUK_OP_GE_CR 37 -#define DUK_OP_GE_RC 38 -#define DUK_OP_GE_CC 39 -#define DUK_OP_LT 40 -#define DUK_OP_LT_RR 40 -#define DUK_OP_LT_CR 41 -#define DUK_OP_LT_RC 42 -#define DUK_OP_LT_CC 43 -#define DUK_OP_LE 44 -#define DUK_OP_LE_RR 44 -#define DUK_OP_LE_CR 45 -#define DUK_OP_LE_RC 46 -#define DUK_OP_LE_CC 47 -#define DUK_OP_IFTRUE 48 -#define DUK_OP_IFTRUE_R 48 -#define DUK_OP_IFTRUE_C 49 -#define DUK_OP_IFFALSE 50 -#define DUK_OP_IFFALSE_R 50 -#define DUK_OP_IFFALSE_C 51 -#define DUK_OP_ADD 52 -#define DUK_OP_ADD_RR 52 -#define DUK_OP_ADD_CR 53 -#define DUK_OP_ADD_RC 54 -#define DUK_OP_ADD_CC 55 -#define DUK_OP_SUB 56 -#define DUK_OP_SUB_RR 56 -#define DUK_OP_SUB_CR 57 -#define DUK_OP_SUB_RC 58 -#define DUK_OP_SUB_CC 59 -#define DUK_OP_MUL 60 -#define DUK_OP_MUL_RR 60 -#define DUK_OP_MUL_CR 61 -#define DUK_OP_MUL_RC 62 -#define DUK_OP_MUL_CC 63 -#define DUK_OP_DIV 64 -#define DUK_OP_DIV_RR 64 -#define DUK_OP_DIV_CR 65 -#define DUK_OP_DIV_RC 66 -#define DUK_OP_DIV_CC 67 -#define DUK_OP_MOD 68 -#define DUK_OP_MOD_RR 68 -#define DUK_OP_MOD_CR 69 -#define DUK_OP_MOD_RC 70 -#define DUK_OP_MOD_CC 71 -#define DUK_OP_EXP 72 -#define DUK_OP_EXP_RR 72 -#define DUK_OP_EXP_CR 73 -#define DUK_OP_EXP_RC 74 -#define DUK_OP_EXP_CC 75 -#define DUK_OP_BAND 76 -#define DUK_OP_BAND_RR 76 -#define DUK_OP_BAND_CR 77 -#define DUK_OP_BAND_RC 78 -#define DUK_OP_BAND_CC 79 -#define DUK_OP_BOR 80 -#define DUK_OP_BOR_RR 80 -#define DUK_OP_BOR_CR 81 -#define DUK_OP_BOR_RC 82 -#define DUK_OP_BOR_CC 83 -#define DUK_OP_BXOR 84 -#define DUK_OP_BXOR_RR 84 -#define DUK_OP_BXOR_CR 85 -#define DUK_OP_BXOR_RC 86 -#define DUK_OP_BXOR_CC 87 -#define DUK_OP_BASL 88 -#define DUK_OP_BASL_RR 88 -#define DUK_OP_BASL_CR 89 -#define DUK_OP_BASL_RC 90 -#define DUK_OP_BASL_CC 91 -#define DUK_OP_BLSR 92 -#define DUK_OP_BLSR_RR 92 -#define DUK_OP_BLSR_CR 93 -#define DUK_OP_BLSR_RC 94 -#define DUK_OP_BLSR_CC 95 -#define DUK_OP_BASR 96 -#define DUK_OP_BASR_RR 96 -#define DUK_OP_BASR_CR 97 -#define DUK_OP_BASR_RC 98 -#define DUK_OP_BASR_CC 99 -#define DUK_OP_INSTOF 100 -#define DUK_OP_INSTOF_RR 100 -#define DUK_OP_INSTOF_CR 101 -#define DUK_OP_INSTOF_RC 102 -#define DUK_OP_INSTOF_CC 103 -#define DUK_OP_IN 104 -#define DUK_OP_IN_RR 104 -#define DUK_OP_IN_CR 105 -#define DUK_OP_IN_RC 106 -#define DUK_OP_IN_CC 107 -#define DUK_OP_GETPROP 108 -#define DUK_OP_GETPROP_RR 108 -#define DUK_OP_GETPROP_CR 109 -#define DUK_OP_GETPROP_RC 110 -#define DUK_OP_GETPROP_CC 111 -#define DUK_OP_PUTPROP 112 -#define DUK_OP_PUTPROP_RR 112 -#define DUK_OP_PUTPROP_CR 113 -#define DUK_OP_PUTPROP_RC 114 -#define DUK_OP_PUTPROP_CC 115 -#define DUK_OP_DELPROP 116 -#define DUK_OP_DELPROP_RR 116 -#define DUK_OP_DELPROP_CR_UNUSED 117 /* unused now */ -#define DUK_OP_DELPROP_RC 118 -#define DUK_OP_DELPROP_CC_UNUSED 119 /* unused now */ -#define DUK_OP_PREINCR 120 /* pre/post opcode values have constraints, */ -#define DUK_OP_PREDECR 121 /* see duk_js_executor.c and duk_js_compiler.c. */ -#define DUK_OP_POSTINCR 122 -#define DUK_OP_POSTDECR 123 -#define DUK_OP_PREINCV 124 -#define DUK_OP_PREDECV 125 -#define DUK_OP_POSTINCV 126 -#define DUK_OP_POSTDECV 127 -#define DUK_OP_PREINCP 128 /* pre/post inc/dec prop opcodes have constraints */ -#define DUK_OP_PREINCP_RR 128 -#define DUK_OP_PREINCP_CR 129 -#define DUK_OP_PREINCP_RC 130 -#define DUK_OP_PREINCP_CC 131 -#define DUK_OP_PREDECP 132 -#define DUK_OP_PREDECP_RR 132 -#define DUK_OP_PREDECP_CR 133 -#define DUK_OP_PREDECP_RC 134 -#define DUK_OP_PREDECP_CC 135 -#define DUK_OP_POSTINCP 136 -#define DUK_OP_POSTINCP_RR 136 -#define DUK_OP_POSTINCP_CR 137 -#define DUK_OP_POSTINCP_RC 138 -#define DUK_OP_POSTINCP_CC 139 -#define DUK_OP_POSTDECP 140 -#define DUK_OP_POSTDECP_RR 140 -#define DUK_OP_POSTDECP_CR 141 -#define DUK_OP_POSTDECP_RC 142 -#define DUK_OP_POSTDECP_CC 143 -#define DUK_OP_DECLVAR 144 -#define DUK_OP_DECLVAR_RR 144 -#define DUK_OP_DECLVAR_CR 145 -#define DUK_OP_DECLVAR_RC 146 -#define DUK_OP_DECLVAR_CC 147 -#define DUK_OP_REGEXP 148 -#define DUK_OP_REGEXP_RR 148 -#define DUK_OP_REGEXP_CR 149 -#define DUK_OP_REGEXP_RC 150 -#define DUK_OP_REGEXP_CC 151 -#define DUK_OP_CLOSURE 152 -#define DUK_OP_TYPEOF 153 -#define DUK_OP_TYPEOFID 154 -#define DUK_OP_PUTVAR 155 -#define DUK_OP_DELVAR 156 -#define DUK_OP_RETREG 157 -#define DUK_OP_RETUNDEF 158 -#define DUK_OP_RETCONST 159 -#define DUK_OP_RETCONSTN 160 /* return const without incref (e.g. number) */ -#define DUK_OP_LABEL 161 -#define DUK_OP_ENDLABEL 162 -#define DUK_OP_BREAK 163 -#define DUK_OP_CONTINUE 164 -#define DUK_OP_TRYCATCH 165 -#define DUK_OP_ENDTRY 166 -#define DUK_OP_ENDCATCH 167 -#define DUK_OP_ENDFIN 168 -#define DUK_OP_THROW 169 -#define DUK_OP_INVLHS 170 -#define DUK_OP_CSREG 171 -#define DUK_OP_CSVAR 172 -#define DUK_OP_CSVAR_RR 172 -#define DUK_OP_CSVAR_CR 173 -#define DUK_OP_CSVAR_RC 174 -#define DUK_OP_CSVAR_CC 175 -#define DUK_OP_CALL0 176 /* DUK_OP_CALL0 & 0x0F must be zero. */ -#define DUK_OP_CALL1 177 -#define DUK_OP_CALL2 178 -#define DUK_OP_CALL3 179 -#define DUK_OP_CALL4 180 -#define DUK_OP_CALL5 181 -#define DUK_OP_CALL6 182 -#define DUK_OP_CALL7 183 -#define DUK_OP_CALL8 184 -#define DUK_OP_CALL9 185 -#define DUK_OP_CALL10 186 -#define DUK_OP_CALL11 187 -#define DUK_OP_CALL12 188 -#define DUK_OP_CALL13 189 -#define DUK_OP_CALL14 190 -#define DUK_OP_CALL15 191 -#define DUK_OP_NEWOBJ 192 -#define DUK_OP_NEWARR 193 -#define DUK_OP_MPUTOBJ 194 -#define DUK_OP_MPUTOBJI 195 -#define DUK_OP_INITSET 196 -#define DUK_OP_INITGET 197 -#define DUK_OP_MPUTARR 198 -#define DUK_OP_MPUTARRI 199 -#define DUK_OP_SETALEN 200 -#define DUK_OP_INITENUM 201 -#define DUK_OP_NEXTENUM 202 -#define DUK_OP_NEWTARGET 203 -#define DUK_OP_DEBUGGER 204 -#define DUK_OP_NOP 205 -#define DUK_OP_INVALID 206 -#define DUK_OP_UNUSED207 207 -#define DUK_OP_GETPROPC 208 -#define DUK_OP_GETPROPC_RR 208 -#define DUK_OP_GETPROPC_CR 209 -#define DUK_OP_GETPROPC_RC 210 -#define DUK_OP_GETPROPC_CC 211 -#define DUK_OP_UNUSED212 212 -#define DUK_OP_UNUSED213 213 -#define DUK_OP_UNUSED214 214 -#define DUK_OP_UNUSED215 215 -#define DUK_OP_UNUSED216 216 -#define DUK_OP_UNUSED217 217 -#define DUK_OP_UNUSED218 218 -#define DUK_OP_UNUSED219 219 -#define DUK_OP_UNUSED220 220 -#define DUK_OP_UNUSED221 221 -#define DUK_OP_UNUSED222 222 -#define DUK_OP_UNUSED223 223 -#define DUK_OP_UNUSED224 224 -#define DUK_OP_UNUSED225 225 -#define DUK_OP_UNUSED226 226 -#define DUK_OP_UNUSED227 227 -#define DUK_OP_UNUSED228 228 -#define DUK_OP_UNUSED229 229 -#define DUK_OP_UNUSED230 230 -#define DUK_OP_UNUSED231 231 -#define DUK_OP_UNUSED232 232 -#define DUK_OP_UNUSED233 233 -#define DUK_OP_UNUSED234 234 -#define DUK_OP_UNUSED235 235 -#define DUK_OP_UNUSED236 236 -#define DUK_OP_UNUSED237 237 -#define DUK_OP_UNUSED238 238 -#define DUK_OP_UNUSED239 239 -#define DUK_OP_UNUSED240 240 -#define DUK_OP_UNUSED241 241 -#define DUK_OP_UNUSED242 242 -#define DUK_OP_UNUSED243 243 -#define DUK_OP_UNUSED244 244 -#define DUK_OP_UNUSED245 245 -#define DUK_OP_UNUSED246 246 -#define DUK_OP_UNUSED247 247 -#define DUK_OP_UNUSED248 248 -#define DUK_OP_UNUSED249 249 -#define DUK_OP_UNUSED250 250 -#define DUK_OP_UNUSED251 251 -#define DUK_OP_UNUSED252 252 -#define DUK_OP_UNUSED253 253 -#define DUK_OP_UNUSED254 254 -#define DUK_OP_UNUSED255 255 -#define DUK_OP_NONE 256 /* dummy value used as marker (doesn't fit in 8-bit field) */ +#define DUK_OP_LDREG 0 +#define DUK_OP_STREG 1 +#define DUK_OP_JUMP 2 +#define DUK_OP_LDCONST 3 +#define DUK_OP_LDINT 4 +#define DUK_OP_LDINTX 5 +#define DUK_OP_LDTHIS 6 +#define DUK_OP_LDUNDEF 7 +#define DUK_OP_LDNULL 8 +#define DUK_OP_LDTRUE 9 +#define DUK_OP_LDFALSE 10 +#define DUK_OP_GETVAR 11 +#define DUK_OP_BNOT 12 +#define DUK_OP_LNOT 13 +#define DUK_OP_UNM 14 +#define DUK_OP_UNP 15 +#define DUK_OP_EQ 16 +#define DUK_OP_EQ_RR 16 +#define DUK_OP_EQ_CR 17 +#define DUK_OP_EQ_RC 18 +#define DUK_OP_EQ_CC 19 +#define DUK_OP_NEQ 20 +#define DUK_OP_NEQ_RR 20 +#define DUK_OP_NEQ_CR 21 +#define DUK_OP_NEQ_RC 22 +#define DUK_OP_NEQ_CC 23 +#define DUK_OP_SEQ 24 +#define DUK_OP_SEQ_RR 24 +#define DUK_OP_SEQ_CR 25 +#define DUK_OP_SEQ_RC 26 +#define DUK_OP_SEQ_CC 27 +#define DUK_OP_SNEQ 28 +#define DUK_OP_SNEQ_RR 28 +#define DUK_OP_SNEQ_CR 29 +#define DUK_OP_SNEQ_RC 30 +#define DUK_OP_SNEQ_CC 31 +#define DUK_OP_GT 32 +#define DUK_OP_GT_RR 32 +#define DUK_OP_GT_CR 33 +#define DUK_OP_GT_RC 34 +#define DUK_OP_GT_CC 35 +#define DUK_OP_GE 36 +#define DUK_OP_GE_RR 36 +#define DUK_OP_GE_CR 37 +#define DUK_OP_GE_RC 38 +#define DUK_OP_GE_CC 39 +#define DUK_OP_LT 40 +#define DUK_OP_LT_RR 40 +#define DUK_OP_LT_CR 41 +#define DUK_OP_LT_RC 42 +#define DUK_OP_LT_CC 43 +#define DUK_OP_LE 44 +#define DUK_OP_LE_RR 44 +#define DUK_OP_LE_CR 45 +#define DUK_OP_LE_RC 46 +#define DUK_OP_LE_CC 47 +#define DUK_OP_IFTRUE 48 +#define DUK_OP_IFTRUE_R 48 +#define DUK_OP_IFTRUE_C 49 +#define DUK_OP_IFFALSE 50 +#define DUK_OP_IFFALSE_R 50 +#define DUK_OP_IFFALSE_C 51 +#define DUK_OP_ADD 52 +#define DUK_OP_ADD_RR 52 +#define DUK_OP_ADD_CR 53 +#define DUK_OP_ADD_RC 54 +#define DUK_OP_ADD_CC 55 +#define DUK_OP_SUB 56 +#define DUK_OP_SUB_RR 56 +#define DUK_OP_SUB_CR 57 +#define DUK_OP_SUB_RC 58 +#define DUK_OP_SUB_CC 59 +#define DUK_OP_MUL 60 +#define DUK_OP_MUL_RR 60 +#define DUK_OP_MUL_CR 61 +#define DUK_OP_MUL_RC 62 +#define DUK_OP_MUL_CC 63 +#define DUK_OP_DIV 64 +#define DUK_OP_DIV_RR 64 +#define DUK_OP_DIV_CR 65 +#define DUK_OP_DIV_RC 66 +#define DUK_OP_DIV_CC 67 +#define DUK_OP_MOD 68 +#define DUK_OP_MOD_RR 68 +#define DUK_OP_MOD_CR 69 +#define DUK_OP_MOD_RC 70 +#define DUK_OP_MOD_CC 71 +#define DUK_OP_EXP 72 +#define DUK_OP_EXP_RR 72 +#define DUK_OP_EXP_CR 73 +#define DUK_OP_EXP_RC 74 +#define DUK_OP_EXP_CC 75 +#define DUK_OP_BAND 76 +#define DUK_OP_BAND_RR 76 +#define DUK_OP_BAND_CR 77 +#define DUK_OP_BAND_RC 78 +#define DUK_OP_BAND_CC 79 +#define DUK_OP_BOR 80 +#define DUK_OP_BOR_RR 80 +#define DUK_OP_BOR_CR 81 +#define DUK_OP_BOR_RC 82 +#define DUK_OP_BOR_CC 83 +#define DUK_OP_BXOR 84 +#define DUK_OP_BXOR_RR 84 +#define DUK_OP_BXOR_CR 85 +#define DUK_OP_BXOR_RC 86 +#define DUK_OP_BXOR_CC 87 +#define DUK_OP_BASL 88 +#define DUK_OP_BASL_RR 88 +#define DUK_OP_BASL_CR 89 +#define DUK_OP_BASL_RC 90 +#define DUK_OP_BASL_CC 91 +#define DUK_OP_BLSR 92 +#define DUK_OP_BLSR_RR 92 +#define DUK_OP_BLSR_CR 93 +#define DUK_OP_BLSR_RC 94 +#define DUK_OP_BLSR_CC 95 +#define DUK_OP_BASR 96 +#define DUK_OP_BASR_RR 96 +#define DUK_OP_BASR_CR 97 +#define DUK_OP_BASR_RC 98 +#define DUK_OP_BASR_CC 99 +#define DUK_OP_INSTOF 100 +#define DUK_OP_INSTOF_RR 100 +#define DUK_OP_INSTOF_CR 101 +#define DUK_OP_INSTOF_RC 102 +#define DUK_OP_INSTOF_CC 103 +#define DUK_OP_IN 104 +#define DUK_OP_IN_RR 104 +#define DUK_OP_IN_CR 105 +#define DUK_OP_IN_RC 106 +#define DUK_OP_IN_CC 107 +#define DUK_OP_GETPROP 108 +#define DUK_OP_GETPROP_RR 108 +#define DUK_OP_GETPROP_CR 109 +#define DUK_OP_GETPROP_RC 110 +#define DUK_OP_GETPROP_CC 111 +#define DUK_OP_PUTPROP 112 +#define DUK_OP_PUTPROP_RR 112 +#define DUK_OP_PUTPROP_CR 113 +#define DUK_OP_PUTPROP_RC 114 +#define DUK_OP_PUTPROP_CC 115 +#define DUK_OP_DELPROP 116 +#define DUK_OP_DELPROP_RR 116 +#define DUK_OP_DELPROP_CR_UNUSED 117 /* unused now */ +#define DUK_OP_DELPROP_RC 118 +#define DUK_OP_DELPROP_CC_UNUSED 119 /* unused now */ +#define DUK_OP_PREINCR 120 /* pre/post opcode values have constraints, */ +#define DUK_OP_PREDECR 121 /* see duk_js_executor.c and duk_js_compiler.c. */ +#define DUK_OP_POSTINCR 122 +#define DUK_OP_POSTDECR 123 +#define DUK_OP_PREINCV 124 +#define DUK_OP_PREDECV 125 +#define DUK_OP_POSTINCV 126 +#define DUK_OP_POSTDECV 127 +#define DUK_OP_PREINCP 128 /* pre/post inc/dec prop opcodes have constraints */ +#define DUK_OP_PREINCP_RR 128 +#define DUK_OP_PREINCP_CR 129 +#define DUK_OP_PREINCP_RC 130 +#define DUK_OP_PREINCP_CC 131 +#define DUK_OP_PREDECP 132 +#define DUK_OP_PREDECP_RR 132 +#define DUK_OP_PREDECP_CR 133 +#define DUK_OP_PREDECP_RC 134 +#define DUK_OP_PREDECP_CC 135 +#define DUK_OP_POSTINCP 136 +#define DUK_OP_POSTINCP_RR 136 +#define DUK_OP_POSTINCP_CR 137 +#define DUK_OP_POSTINCP_RC 138 +#define DUK_OP_POSTINCP_CC 139 +#define DUK_OP_POSTDECP 140 +#define DUK_OP_POSTDECP_RR 140 +#define DUK_OP_POSTDECP_CR 141 +#define DUK_OP_POSTDECP_RC 142 +#define DUK_OP_POSTDECP_CC 143 +#define DUK_OP_DECLVAR 144 +#define DUK_OP_DECLVAR_RR 144 +#define DUK_OP_DECLVAR_CR 145 +#define DUK_OP_DECLVAR_RC 146 +#define DUK_OP_DECLVAR_CC 147 +#define DUK_OP_REGEXP 148 +#define DUK_OP_REGEXP_RR 148 +#define DUK_OP_REGEXP_CR 149 +#define DUK_OP_REGEXP_RC 150 +#define DUK_OP_REGEXP_CC 151 +#define DUK_OP_CLOSURE 152 +#define DUK_OP_TYPEOF 153 +#define DUK_OP_TYPEOFID 154 +#define DUK_OP_PUTVAR 155 +#define DUK_OP_DELVAR 156 +#define DUK_OP_RETREG 157 +#define DUK_OP_RETUNDEF 158 +#define DUK_OP_RETCONST 159 +#define DUK_OP_RETCONSTN 160 /* return const without incref (e.g. number) */ +#define DUK_OP_LABEL 161 +#define DUK_OP_ENDLABEL 162 +#define DUK_OP_BREAK 163 +#define DUK_OP_CONTINUE 164 +#define DUK_OP_TRYCATCH 165 +#define DUK_OP_ENDTRY 166 +#define DUK_OP_ENDCATCH 167 +#define DUK_OP_ENDFIN 168 +#define DUK_OP_THROW 169 +#define DUK_OP_INVLHS 170 +#define DUK_OP_CSREG 171 +#define DUK_OP_CSVAR 172 +#define DUK_OP_CSVAR_RR 172 +#define DUK_OP_CSVAR_CR 173 +#define DUK_OP_CSVAR_RC 174 +#define DUK_OP_CSVAR_CC 175 +#define DUK_OP_CALL0 176 /* DUK_OP_CALL0 & 0x0F must be zero. */ +#define DUK_OP_CALL1 177 +#define DUK_OP_CALL2 178 +#define DUK_OP_CALL3 179 +#define DUK_OP_CALL4 180 +#define DUK_OP_CALL5 181 +#define DUK_OP_CALL6 182 +#define DUK_OP_CALL7 183 +#define DUK_OP_CALL8 184 +#define DUK_OP_CALL9 185 +#define DUK_OP_CALL10 186 +#define DUK_OP_CALL11 187 +#define DUK_OP_CALL12 188 +#define DUK_OP_CALL13 189 +#define DUK_OP_CALL14 190 +#define DUK_OP_CALL15 191 +#define DUK_OP_NEWOBJ 192 +#define DUK_OP_NEWARR 193 +#define DUK_OP_MPUTOBJ 194 +#define DUK_OP_MPUTOBJI 195 +#define DUK_OP_INITSET 196 +#define DUK_OP_INITGET 197 +#define DUK_OP_MPUTARR 198 +#define DUK_OP_MPUTARRI 199 +#define DUK_OP_SETALEN 200 +#define DUK_OP_INITENUM 201 +#define DUK_OP_NEXTENUM 202 +#define DUK_OP_NEWTARGET 203 +#define DUK_OP_DEBUGGER 204 +#define DUK_OP_NOP 205 +#define DUK_OP_INVALID 206 +#define DUK_OP_UNUSED207 207 +#define DUK_OP_GETPROPC 208 +#define DUK_OP_GETPROPC_RR 208 +#define DUK_OP_GETPROPC_CR 209 +#define DUK_OP_GETPROPC_RC 210 +#define DUK_OP_GETPROPC_CC 211 +#define DUK_OP_UNUSED212 212 +#define DUK_OP_UNUSED213 213 +#define DUK_OP_UNUSED214 214 +#define DUK_OP_UNUSED215 215 +#define DUK_OP_UNUSED216 216 +#define DUK_OP_UNUSED217 217 +#define DUK_OP_UNUSED218 218 +#define DUK_OP_UNUSED219 219 +#define DUK_OP_UNUSED220 220 +#define DUK_OP_UNUSED221 221 +#define DUK_OP_UNUSED222 222 +#define DUK_OP_UNUSED223 223 +#define DUK_OP_UNUSED224 224 +#define DUK_OP_UNUSED225 225 +#define DUK_OP_UNUSED226 226 +#define DUK_OP_UNUSED227 227 +#define DUK_OP_UNUSED228 228 +#define DUK_OP_UNUSED229 229 +#define DUK_OP_UNUSED230 230 +#define DUK_OP_UNUSED231 231 +#define DUK_OP_UNUSED232 232 +#define DUK_OP_UNUSED233 233 +#define DUK_OP_UNUSED234 234 +#define DUK_OP_UNUSED235 235 +#define DUK_OP_UNUSED236 236 +#define DUK_OP_UNUSED237 237 +#define DUK_OP_UNUSED238 238 +#define DUK_OP_UNUSED239 239 +#define DUK_OP_UNUSED240 240 +#define DUK_OP_UNUSED241 241 +#define DUK_OP_UNUSED242 242 +#define DUK_OP_UNUSED243 243 +#define DUK_OP_UNUSED244 244 +#define DUK_OP_UNUSED245 245 +#define DUK_OP_UNUSED246 246 +#define DUK_OP_UNUSED247 247 +#define DUK_OP_UNUSED248 248 +#define DUK_OP_UNUSED249 249 +#define DUK_OP_UNUSED250 250 +#define DUK_OP_UNUSED251 251 +#define DUK_OP_UNUSED252 252 +#define DUK_OP_UNUSED253 253 +#define DUK_OP_UNUSED254 254 +#define DUK_OP_UNUSED255 255 +#define DUK_OP_NONE 256 /* dummy value used as marker (doesn't fit in 8-bit field) */ /* XXX: Allocate flags from opcode field? Would take 16 opcode slots * but avoids shuffling in more cases. Maybe not worth it. */ /* DUK_OP_TRYCATCH flags in A. */ -#define DUK_BC_TRYCATCH_FLAG_HAVE_CATCH (1U << 0) -#define DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY (1U << 1) -#define DUK_BC_TRYCATCH_FLAG_CATCH_BINDING (1U << 2) -#define DUK_BC_TRYCATCH_FLAG_WITH_BINDING (1U << 3) +#define DUK_BC_TRYCATCH_FLAG_HAVE_CATCH (1U << 0) +#define DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY (1U << 1) +#define DUK_BC_TRYCATCH_FLAG_CATCH_BINDING (1U << 2) +#define DUK_BC_TRYCATCH_FLAG_WITH_BINDING (1U << 3) /* DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags * (DUK_PROPDESC_FLAG_XXX). */ -#define DUK_BC_DECLVAR_FLAG_FUNC_DECL (1U << 4) /* function declaration */ +#define DUK_BC_DECLVAR_FLAG_FUNC_DECL (1U << 4) /* function declaration */ /* DUK_OP_CALLn flags, part of opcode field. Three lowest bits must match * DUK_CALL_FLAG_xxx directly. */ -#define DUK_BC_CALL_FLAG_TAILCALL (1U << 0) -#define DUK_BC_CALL_FLAG_CONSTRUCT (1U << 1) -#define DUK_BC_CALL_FLAG_CALLED_AS_EVAL (1U << 2) -#define DUK_BC_CALL_FLAG_INDIRECT (1U << 3) +#define DUK_BC_CALL_FLAG_TAILCALL (1U << 0) +#define DUK_BC_CALL_FLAG_CONSTRUCT (1U << 1) +#define DUK_BC_CALL_FLAG_CALLED_AS_EVAL (1U << 2) +#define DUK_BC_CALL_FLAG_INDIRECT (1U << 3) /* Misc constants and helper macros. */ -#define DUK_BC_LDINT_BIAS (1L << 15) -#define DUK_BC_LDINTX_SHIFT 16 -#define DUK_BC_JUMP_BIAS (1L << 23) +#define DUK_BC_LDINT_BIAS (1L << 15) +#define DUK_BC_LDINTX_SHIFT 16 +#define DUK_BC_JUMP_BIAS (1L << 23) -#endif /* DUK_JS_BYTECODE_H_INCLUDED */ +#endif /* DUK_JS_BYTECODE_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_js_call.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_js_call.c
Changed
@@ -51,10 +51,10 @@ * for, e.g. a print() call at the deepest level, and an extra * +1 for protected call wrapping. */ -#define DUK__AUGMENT_CALL_RELAX_COUNT (10 + 2) +#define DUK__AUGMENT_CALL_RELAX_COUNT (10 + 2) /* Stack space required by call handling entry. */ -#define DUK__CALL_HANDLING_REQUIRE_STACK 8 +#define DUK__CALL_HANDLING_REQUIRE_STACK 8 DUK_LOCAL DUK_NOINLINE void duk__call_c_recursion_limit_check_slowpath(duk_hthread *thr) { /* When augmenting an error, the effective limit is a bit higher. @@ -148,7 +148,8 @@ thr->heap->inst_count_interrupt += thr->interrupt_init; DUK_DD(DUK_DDPRINT("debug test: updated interrupt count on exit to " "user code, instruction counts: executor=%ld, interrupt=%ld", - (long) thr->heap->inst_count_exec, (long) thr->heap->inst_count_interrupt)); + (long) thr->heap->inst_count_exec, + (long) thr->heap->inst_count_interrupt)); DUK_ASSERT(thr->heap->inst_count_exec == thr->heap->inst_count_interrupt); } #else @@ -167,12 +168,9 @@ * object flag DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS. */ -DUK_LOCAL void duk__create_arguments_object(duk_hthread *thr, - duk_hobject *func, - duk_hobject *varenv, - duk_idx_t idx_args) { - duk_hobject *arg; /* 'arguments' */ - duk_hobject *formals; /* formals for 'func' (may be NULL if func is a C function) */ +DUK_LOCAL void duk__create_arguments_object(duk_hthread *thr, duk_hobject *func, duk_hobject *varenv, duk_idx_t idx_args) { + duk_hobject *arg; /* 'arguments' */ + duk_hobject *formals; /* formals for 'func' (may be NULL if func is a C function) */ duk_idx_t i_arg; duk_idx_t i_map; duk_idx_t i_mappednames; @@ -218,9 +216,8 @@ DUK_ASSERT(n_formals >= 0); DUK_ASSERT(formals != NULL || n_formals == 0); - DUK_DDD(DUK_DDDPRINT("func=%!O, formals=%!O, n_formals=%ld", - (duk_heaphdr *) func, (duk_heaphdr *) formals, - (long) n_formals)); + DUK_DDD( + DUK_DDDPRINT("func=%!O, formals=%!O, n_formals=%ld", (duk_heaphdr *) func, (duk_heaphdr *) formals, (long) n_formals)); /* ... formals */ @@ -232,28 +229,24 @@ */ arg = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARGUMENTS), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARGUMENTS), DUK_BIDX_OBJECT_PROTOTYPE); DUK_ASSERT(arg != NULL); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ i_arg = duk_get_top(thr) - 3; i_map = i_arg + 1; i_mappednames = i_arg + 2; - DUK_ASSERT(!duk_is_bare_object(thr, -3)); /* arguments */ - DUK_ASSERT(duk_is_bare_object(thr, -2)); /* map */ - DUK_ASSERT(duk_is_bare_object(thr, -1)); /* mappedNames */ + DUK_ASSERT(!duk_is_bare_object(thr, -3)); /* arguments */ + DUK_ASSERT(duk_is_bare_object(thr, -2)); /* map */ + DUK_ASSERT(duk_is_bare_object(thr, -1)); /* mappedNames */ /* ... formals arguments map mappedNames */ @@ -261,9 +254,12 @@ "arguments at index %ld -> %!O " "map at index %ld -> %!O " "mappednames at index %ld -> %!O", - (long) i_arg, (duk_heaphdr *) duk_get_hobject(thr, i_arg), - (long) i_map, (duk_heaphdr *) duk_get_hobject(thr, i_map), - (long) i_mappednames, (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); + (long) i_arg, + (duk_heaphdr *) duk_get_hobject(thr, i_arg), + (long) i_map, + (duk_heaphdr *) duk_get_hobject(thr, i_map), + (long) i_mappednames, + (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); /* * Init arguments properties, map, etc. @@ -279,8 +275,8 @@ /* step 11 */ idx = num_stack_args - 1; while (idx >= 0) { - DUK_DDD(DUK_DDDPRINT("arg idx %ld, argbase=%ld, argidx=%ld", - (long) idx, (long) i_argbase, (long) (i_argbase + idx))); + DUK_DDD( + DUK_DDDPRINT("arg idx %ld, argbase=%ld, argidx=%ld", (long) idx, (long) i_argbase, (long) (i_argbase + idx))); DUK_DDD(DUK_DDDPRINT("define arguments%ld=arg", (long) idx)); duk_dup(thr, i_argbase + idx); @@ -291,13 +287,12 @@ if (!DUK_HOBJECT_HAS_STRICT(func) && idx < n_formals) { DUK_ASSERT(formals != NULL); - DUK_DDD(DUK_DDDPRINT("strict function, index within formals (%ld < %ld)", - (long) idx, (long) n_formals)); + DUK_DDD(DUK_DDDPRINT("strict function, index within formals (%ld < %ld)", (long) idx, (long) n_formals)); duk_get_prop_index(thr, i_formals, (duk_uarridx_t) idx); DUK_ASSERT(duk_is_string(thr, -1)); - duk_dup_top(thr); /* ... name name */ + duk_dup_top(thr); /* ... name name */ if (!duk_has_prop(thr, i_mappednames)) { /* steps 11.c.ii.1 - 11.c.ii.4, but our internal book-keeping @@ -308,24 +303,21 @@ need_map = 1; - DUK_DDD(DUK_DDDPRINT("set mappednames%s=%ld", - (const char *) duk_get_string(thr, -1), - (long) idx)); - duk_dup_top(thr); /* name */ - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) idx); /* index */ - duk_xdef_prop_wec(thr, i_mappednames); /* out of spec, must be configurable */ - - DUK_DDD(DUK_DDDPRINT("set map%ld=%s", - (long) idx, - duk_get_string(thr, -1))); - duk_dup_top(thr); /* name */ - duk_xdef_prop_index_wec(thr, i_map, (duk_uarridx_t) idx); /* out of spec, must be configurable */ + DUK_DDD( + DUK_DDDPRINT("set mappednames%s=%ld", (const char *) duk_get_string(thr, -1), (long) idx)); + duk_dup_top(thr); /* name */ + (void) duk_push_uint_to_hstring(thr, (duk_uint_t) idx); /* index */ + duk_xdef_prop_wec(thr, i_mappednames); /* out of spec, must be configurable */ + + DUK_DDD(DUK_DDDPRINT("set map%ld=%s", (long) idx, duk_get_string(thr, -1))); + duk_dup_top(thr); /* name */ + duk_xdef_prop_index_wec(thr, i_map, (duk_uarridx_t) idx); /* out of spec, must be configurable */ } else { /* duk_has_prop() popped the second 'name' */ } /* ... name */ - duk_pop(thr); /* pop 'name' */ + duk_pop(thr); /* pop 'name' */ } idx--; @@ -341,7 +333,7 @@ DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(func)); duk_dup(thr, i_map); - duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_MAP, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ + duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_MAP, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ /* The variable environment for magic variable bindings needs to be * given by the caller and recorded in the arguments object. @@ -353,7 +345,7 @@ */ duk_push_hobject(thr, varenv); - duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_VARENV, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ + duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_VARENV, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ } /* steps 13-14 */ @@ -406,9 +398,12 @@ "arguments at index %ld -> %!O " "map at index %ld -> %!O " "mappednames at index %ld -> %!O", - (long) i_arg, (duk_heaphdr *) duk_get_hobject(thr, i_arg), - (long) i_map, (duk_heaphdr *) duk_get_hobject(thr, i_map), - (long) i_mappednames, (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); + (long) i_arg, + (duk_heaphdr *) duk_get_hobject(thr, i_arg), + (long) i_map, + (duk_heaphdr *) duk_get_hobject(thr, i_map), + (long) i_mappednames, + (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); /* args(n) envobj formals arguments map mappednames */ @@ -421,10 +416,7 @@ /* Helper for creating the arguments object and adding it to the env record * on top of the value stack. */ -DUK_LOCAL void duk__handle_createargs_for_call(duk_hthread *thr, - duk_hobject *func, - duk_hobject *env, - duk_idx_t idx_args) { +DUK_LOCAL void duk__handle_createargs_for_call(duk_hthread *thr, duk_hobject *func, duk_hobject *env, duk_idx_t idx_args) { DUK_DDD(DUK_DDDPRINT("creating arguments object for function call")); DUK_ASSERT(thr != NULL); @@ -434,18 +426,15 @@ /* ... arg1 ... argN envobj */ - duk__create_arguments_object(thr, - func, - env, - idx_args); + duk__create_arguments_object(thr, func, env, idx_args); /* ... arg1 ... argN envobj argobj */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LC_ARGUMENTS, - DUK_HOBJECT_HAS_STRICT(func) ? DUK_PROPDESC_FLAGS_E : /* strict: non-deletable, non-writable */ - DUK_PROPDESC_FLAGS_WE); /* non-strict: non-deletable, writable */ + DUK_HOBJECT_HAS_STRICT(func) ? DUK_PROPDESC_FLAGS_E : /* strict: non-deletable, non-writable */ + DUK_PROPDESC_FLAGS_WE); /* non-strict: non-deletable, writable */ /* ... arg1 ... argN envobj */ } @@ -495,7 +484,8 @@ "-> leave standard Object prototype as fallback prototype")); } else { DUK_DDD(DUK_DDDPRINT("constructor has 'prototype' property with object value " - "-> set fallback prototype to that value: %!iO", (duk_heaphdr *) proto)); + "-> set fallback prototype to that value: %!iO", + (duk_heaphdr *) proto)); /* Original fallback (default instance) is untouched when * resolving bound functions etc. */ @@ -517,9 +507,7 @@ * Object (we accept object-like values like buffers and * lightfuncs too). If not, TypeError. */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_LIGHTFUNC)) { + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_LIGHTFUNC)) { DUK_DDD(DUK_DDDPRINT("replacement value")); } else { if (DUK_UNLIKELY(proxy_invariant != 0U)) { @@ -541,8 +529,7 @@ * out right; however it is always synced here so just assert for it. */ DUK_ASSERT(thr->ptr_curr_pc == NULL); - duk_err_augment_error_create(thr, thr, NULL, 0, DUK_AUGMENT_FLAG_NOBLAME_FILELINE | - DUK_AUGMENT_FLAG_SKIP_ONE); + duk_err_augment_error_create(thr, thr, NULL, 0, DUK_AUGMENT_FLAG_NOBLAME_FILELINE | DUK_AUGMENT_FLAG_SKIP_ONE); #endif } @@ -559,9 +546,7 @@ * BoundThis. */ -DUK_LOCAL void duk__handle_bound_chain_for_call(duk_hthread *thr, - duk_idx_t idx_func, - duk_bool_t is_constructor_call) { +DUK_LOCAL void duk__handle_bound_chain_for_call(duk_hthread *thr, duk_idx_t idx_func, duk_bool_t is_constructor_call) { duk_tval *tv_func; duk_hobject *func; duk_idx_t len; @@ -592,7 +577,8 @@ DUK_ASSERT(len == 0 || tv_args != NULL); DUK_DDD(DUK_DDDPRINT("bound function encountered, ptr=%p: %!T", - (void *) DUK_TVAL_GET_OBJECT(tv_func), tv_func)); + (void *) DUK_TVAL_GET_OBJECT(tv_func), + tv_func)); /* ... func this arg1 ... argN */ @@ -602,7 +588,7 @@ } else { /* XXX: duk_replace_tval */ duk_push_tval(thr, &h_bound->this_binding); - duk_replace(thr, idx_func + 1); /* idx_this = idx_func + 1 */ + duk_replace(thr, idx_func + 1); /* idx_this = idx_func + 1 */ } /* ... func this arg1 ... argN */ @@ -615,10 +601,11 @@ /* ... func this <bound args> arg1 ... argN */ duk_push_tval(thr, &h_bound->target); - duk_replace(thr, idx_func); /* replace in stack */ + duk_replace(thr, idx_func); /* replace in stack */ DUK_DDD(DUK_DDDPRINT("bound function handled, idx_func=%ld, curr func=%!T", - (long) idx_func, duk_get_tval(thr, idx_func))); + (long) idx_func, + duk_get_tval(thr, idx_func))); } } else if (DUK_TVAL_IS_LIGHTFUNC(tv_func)) { /* Lightweight function: never bound, so terminate. */ @@ -640,9 +627,7 @@ func = DUK_TVAL_GET_OBJECT(tv_func); DUK_ASSERT(func != NULL); DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func) || - DUK_HOBJECT_HAS_NATFUNC(func) || - DUK_HOBJECT_IS_PROXY(func)); + DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func) || DUK_HOBJECT_HAS_NATFUNC(func) || DUK_HOBJECT_IS_PROXY(func)); } #endif } @@ -651,14 +636,18 @@ * Helper for inline handling of .call(), .apply(), and .construct(). */ -DUK_LOCAL duk_bool_t duk__handle_specialfuncs_for_call(duk_hthread *thr, duk_idx_t idx_func, duk_hobject *func, duk_small_uint_t *call_flags, duk_bool_t first) { +DUK_LOCAL duk_bool_t duk__handle_specialfuncs_for_call(duk_hthread *thr, + duk_idx_t idx_func, + duk_hobject *func, + duk_small_uint_t *call_flags, + duk_bool_t first) { #if defined(DUK_USE_ASSERTIONS) duk_c_function natfunc; #endif duk_tval *tv_args; DUK_ASSERT(func != NULL); - DUK_ASSERT((*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0); /* Caller. */ + DUK_ASSERT((*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0); /* Caller. */ #if defined(DUK_USE_ASSERTIONS) natfunc = ((duk_hnatfunc *) func)->func; @@ -686,7 +675,7 @@ *call_flags = (*call_flags & ~DUK_CALL_FLAG_CALLED_AS_EVAL) | DUK_CALL_FLAG_DIRECT_EVAL; } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 1; /* stop resolving */ + return 1; /* stop resolving */ } /* Handle special functions based on the DUK_HOBJECT_FLAG_SPECIAL_CALL @@ -696,7 +685,7 @@ * for the result values (unlike most other value stack calls). */ switch (((duk_hnatfunc *) func)->magic) { - case 0: { /* 0=Function.prototype.call() */ + case 0: { /* 0=Function.prototype.call() */ /* Value stack: * idx_func + 0: Function.prototype.call() removed * idx_func + 1: this binding for .call (target function) @@ -715,11 +704,11 @@ tv_args = thr->valstack_bottom + idx_func + 2; if (thr->valstack_top < tv_args) { DUK_ASSERT(tv_args <= thr->valstack_end); - thr->valstack_top = tv_args; /* at least target function and 'this' binding present */ + thr->valstack_top = tv_args; /* at least target function and 'this' binding present */ } break; } - case 1: { /* 1=Function.prototype.apply() */ + case 1: { /* 1=Function.prototype.apply() */ /* Value stack: * idx_func + 0: Function.prototype.apply() removed * idx_func + 1: this binding for .apply (target function) @@ -738,7 +727,7 @@ goto apply_shared; } #if defined(DUK_USE_REFLECT_BUILTIN) - case 2: { /* 2=Reflect.apply() */ + case 2: { /* 2=Reflect.apply() */ /* Value stack: * idx_func + 0: Reflect.apply() removed * idx_func + 1: this binding for .apply (ignored, usually Reflect) removed @@ -757,7 +746,7 @@ duk_remove_n_unsafe(thr, idx_func, 2); goto apply_shared; } - case 3: { /* 3=Reflect.construct() */ + case 3: { /* 3=Reflect.construct() */ /* Value stack: * idx_func + 0: Reflect.construct() removed * idx_func + 1: this binding for .construct (ignored, usually Reflect) removed @@ -791,11 +780,11 @@ * unpacking argArray (which may cause side effects). * Just return; caller will throw the error. */ - duk_set_top_unsafe(thr, idx_func + 2); /* satisfy asserts */ + duk_set_top_unsafe(thr, idx_func + 2); /* satisfy asserts */ break; } duk_push_object(thr); - duk_insert(thr, idx_func + 1); /* default instance */ + duk_insert(thr, idx_func + 1); /* default instance */ /* ... func default_instance argArray newTarget? */ @@ -811,16 +800,17 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } - duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ + duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ } DUK_ASSERT(duk_get_top(thr) == idx_func + 3); DUK_ASSERT(duk_is_valid_index(thr, idx_func + 2)); - (void) duk_unpack_array_like(thr, idx_func + 2); /* XXX: should also remove target to be symmetric with duk_pack()? */ + (void) duk_unpack_array_like(thr, + idx_func + 2); /* XXX: should also remove target to be symmetric with duk_pack()? */ duk_remove(thr, idx_func + 2); DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); break; } -#endif /* DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_REFLECT_BUILTIN */ default: { DUK_ASSERT(0); DUK_UNREACHABLE(); @@ -828,18 +818,18 @@ } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 0; /* keep resolving */ + return 0; /* keep resolving */ - apply_shared: +apply_shared: tv_args = thr->valstack_bottom + idx_func + 2; if (thr->valstack_top <= tv_args) { DUK_ASSERT(tv_args <= thr->valstack_end); - thr->valstack_top = tv_args; /* at least target func and 'this' binding present */ + thr->valstack_top = tv_args; /* at least target func and 'this' binding present */ /* No need to check for argArray. */ } else { - DUK_ASSERT(duk_get_top(thr) >= idx_func + 3); /* idx_func + 2 covered above */ + DUK_ASSERT(duk_get_top(thr) >= idx_func + 3); /* idx_func + 2 covered above */ if (thr->valstack_top > tv_args + 1) { - duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ + duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ } DUK_ASSERT(duk_is_valid_index(thr, idx_func + 2)); if (!duk_is_callable(thr, idx_func)) { @@ -852,7 +842,7 @@ } } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 0; /* keep resolving */ + return 0; /* keep resolving */ } /* @@ -950,8 +940,8 @@ DUK_ASSERT(duk_get_top(thr) == idx_func + 6); if (*call_flags & DUK_CALL_FLAG_CONSTRUCT) { - *call_flags |= DUK_CALL_FLAG_CONSTRUCT_PROXY; /* Enable 'construct' trap return invariant check. */ - *call_flags &= ~(DUK_CALL_FLAG_CONSTRUCT); /* Resume as non-constructor call to the trap. */ + *call_flags |= DUK_CALL_FLAG_CONSTRUCT_PROXY; /* Enable 'construct' trap return invariant check. */ + *call_flags &= ~(DUK_CALL_FLAG_CONSTRUCT); /* Resume as non-constructor call to the trap. */ /* 'apply' args: target, thisArg, argArray * 'construct' args: target, argArray, newTarget @@ -962,19 +952,17 @@ /* Finalize value stack layout by removing Proxy reference. */ duk_remove(thr, idx_func); - h_proxy = NULL; /* invalidated */ + h_proxy = NULL; /* invalidated */ DUK_ASSERT(duk_get_top(thr) == idx_func + 5); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* * Helper for setting up var_env and lex_env of an activation, * assuming it does NOT have the DUK_HOBJECT_FLAG_NEWENV flag. */ -DUK_LOCAL void duk__handle_oldenv_for_call(duk_hthread *thr, - duk_hobject *func, - duk_activation *act) { +DUK_LOCAL void duk__handle_oldenv_for_call(duk_hthread *thr, duk_hobject *func, duk_activation *act) { duk_hcompfunc *f; duk_hobject *h_lex; duk_hobject *h_var; @@ -990,7 +978,7 @@ f = (duk_hcompfunc *) func; h_lex = DUK_HCOMPFUNC_GET_LEXENV(thr->heap, f); h_var = DUK_HCOMPFUNC_GET_VARENV(thr->heap, f); - DUK_ASSERT(h_lex != NULL); /* Always true for closures (not for templates) */ + DUK_ASSERT(h_lex != NULL); /* Always true for closures (not for templates) */ DUK_ASSERT(h_var != NULL); act->lex_env = h_lex; act->var_env = h_var; @@ -1011,7 +999,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(func != NULL); - DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound chain resolved */ + DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound chain resolved */ DUK_ASSERT(thr->callstack_top >= 1); if (DUK_HOBJECT_HAS_STRICT(func)) { @@ -1065,7 +1053,7 @@ DUK_TVAL_SET_OBJECT(tv_caller, act_caller->func); DUK_TVAL_INCREF(thr, tv_caller); } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref */ } } else { /* 'caller' must only take on 'null' or function value */ @@ -1078,12 +1066,12 @@ DUK_TVAL_SET_OBJECT(tv_caller, act_caller->func); DUK_TVAL_INCREF(thr, tv_caller); } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref */ } } } } -#endif /* DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ +#endif /* DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ /* * Shared helpers for resolving the final, non-bound target function of the @@ -1129,7 +1117,7 @@ obj_global = thr->builtinsDUK_BIDX_GLOBAL; /* XXX: avoid this check somehow */ if (DUK_LIKELY(obj_global != NULL)) { - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ DUK_TVAL_SET_OBJECT(tv_this, obj_global); DUK_HOBJECT_INCREF(thr, obj_global); } else { @@ -1137,8 +1125,8 @@ * This behavior is out of specification scope. */ DUK_D(DUK_DPRINT("this binding: wanted to use global object, but it is NULL -> using undefined instead")); - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ - DUK_TVAL_SET_UNDEFINED(tv_this); /* nothing to incref */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ + DUK_TVAL_SET_UNDEFINED(tv_this); /* nothing to incref */ } break; default: @@ -1149,18 +1137,21 @@ */ DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv_this)); DUK_DDD(DUK_DDDPRINT("this binding: non-strict, not object/undefined/null -> use ToObject(value)")); - duk_to_object(thr, idx_this); /* may have side effects */ + duk_to_object(thr, idx_this); /* may have side effects */ break; } } -DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__resolve_target_fastpath_check(duk_hthread *thr, duk_idx_t idx_func, duk_hobject **out_func, duk_small_uint_t call_flags) { +DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__resolve_target_fastpath_check(duk_hthread *thr, + duk_idx_t idx_func, + duk_hobject **out_func, + duk_small_uint_t call_flags) { #if defined(DUK_USE_PREFER_SIZE) DUK_UNREF(thr); DUK_UNREF(idx_func); DUK_UNREF(out_func); DUK_UNREF(call_flags); -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ duk_tval *tv_func; duk_hobject *func; @@ -1173,9 +1164,7 @@ if (DUK_LIKELY(DUK_TVAL_IS_OBJECT(tv_func))) { func = DUK_TVAL_GET_OBJECT(tv_func); - if (DUK_HOBJECT_IS_CALLABLE(func) && - !DUK_HOBJECT_HAS_BOUNDFUNC(func) && - !DUK_HOBJECT_HAS_SPECIAL_CALL(func)) { + if (DUK_HOBJECT_IS_CALLABLE(func) && !DUK_HOBJECT_HAS_BOUNDFUNC(func) && !DUK_HOBJECT_HAS_SPECIAL_CALL(func)) { *out_func = func; if (DUK_HOBJECT_HAS_STRICT(func)) { @@ -1195,8 +1184,8 @@ */ return 1; } -#endif /* DUK_USE_PREFER_SIZE */ - return 0; /* let slow path deal with it */ +#endif /* DUK_USE_PREFER_SIZE */ + return 0; /* let slow path deal with it */ } DUK_LOCAL duk_hobject *duk__resolve_target_func_and_this_binding(duk_hthread *thr, @@ -1229,8 +1218,7 @@ } } - if (DUK_LIKELY(!DUK_HOBJECT_HAS_BOUNDFUNC(func) && - !DUK_HOBJECT_HAS_SPECIAL_CALL(func) && + if (DUK_LIKELY(!DUK_HOBJECT_HAS_BOUNDFUNC(func) && !DUK_HOBJECT_HAS_SPECIAL_CALL(func) && !DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(func))) { /* Common case, so test for using a single bitfield test. * Break out to handle this coercion etc. @@ -1266,8 +1254,7 @@ * the trap may be bound. */ duk__handle_proxy_for_call(thr, idx_func, (duk_hproxy *) func, call_flags); - } - else + } else #endif { DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(func)); @@ -1314,28 +1301,25 @@ } } - finished: - +finished : #if defined(DUK_USE_ASSERTIONS) - { - duk_tval *tv_tmp; +{ + duk_tval *tv_tmp; - tv_tmp = duk_get_tval(thr, idx_func); - DUK_ASSERT(tv_tmp != NULL); + tv_tmp = duk_get_tval(thr, idx_func); + DUK_ASSERT(tv_tmp != NULL); - DUK_ASSERT((DUK_TVAL_IS_OBJECT(tv_tmp) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(tv_tmp))) || - DUK_TVAL_IS_LIGHTFUNC(tv_tmp)); - DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || - DUK_HOBJECT_IS_NATFUNC(func))); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_HAS_CONSTRUCTABLE(func) || - (*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0)); - } + DUK_ASSERT((DUK_TVAL_IS_OBJECT(tv_tmp) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(tv_tmp))) || + DUK_TVAL_IS_LIGHTFUNC(tv_tmp)); + DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || DUK_HOBJECT_IS_NATFUNC(func))); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_HAS_CONSTRUCTABLE(func) || (*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0)); +} #endif return func; - not_callable: +not_callable: DUK_ASSERT(tv_func != NULL); #if defined(DUK_USE_VERBOSE_ERRORS) @@ -1347,7 +1331,8 @@ * (which would be dangerous). */ if (DUK_TVAL_IS_OBJECT(tv_func)) { - duk_tval *tv_wrap = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, DUK_TVAL_GET_OBJECT(tv_func), DUK_STRIDX_INT_TARGET); + duk_tval *tv_wrap = + duk_hobject_find_entry_tval_ptr_stridx(thr->heap, DUK_TVAL_GET_OBJECT(tv_func), DUK_STRIDX_INT_TARGET); if (tv_wrap != NULL) { DUK_DD(DUK_DDPRINT("delayed error from GETPROPC: %!T", tv_wrap)); duk_push_tval(thr, tv_wrap); @@ -1368,7 +1353,7 @@ #endif DUK_WO_NORETURN(return NULL;); - not_constructable: +not_constructable: /* For now GETPROPC delayed error not needed for constructor calls. */ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) @@ -1392,7 +1377,10 @@ * empty (below idx_retbase). */ -DUK_LOCAL void duk__safe_call_adjust_valstack(duk_hthread *thr, duk_idx_t idx_retbase, duk_idx_t num_stack_rets, duk_idx_t num_actual_rets) { +DUK_LOCAL void duk__safe_call_adjust_valstack(duk_hthread *thr, + duk_idx_t idx_retbase, + duk_idx_t num_stack_rets, + duk_idx_t num_actual_rets) { duk_idx_t idx_rcbase; DUK_ASSERT(thr != NULL); @@ -1400,7 +1388,7 @@ DUK_ASSERT(num_stack_rets >= 0); DUK_ASSERT(num_actual_rets >= 0); - idx_rcbase = duk_get_top(thr) - num_actual_rets; /* base of known return values */ + idx_rcbase = duk_get_top(thr) - num_actual_rets; /* base of known return values */ if (DUK_UNLIKELY(idx_rcbase < 0)) { DUK_ERROR_TYPE(thr, DUK_STR_INVALID_CFUNC_RC); DUK_WO_NORETURN(return;); @@ -1408,10 +1396,13 @@ DUK_DDD(DUK_DDDPRINT("adjust valstack after func call: " "num_stack_rets=%ld, num_actual_rets=%ld, stack_top=%ld, idx_retbase=%ld, idx_rcbase=%ld", - (long) num_stack_rets, (long) num_actual_rets, (long) duk_get_top(thr), - (long) idx_retbase, (long) idx_rcbase)); + (long) num_stack_rets, + (long) num_actual_rets, + (long) duk_get_top(thr), + (long) idx_retbase, + (long) idx_rcbase)); - DUK_ASSERT(idx_rcbase >= 0); /* caller must check */ + DUK_ASSERT(idx_rcbase >= 0); /* caller must check */ /* Space for num_stack_rets was reserved before the safe call. * Because value stack reserve cannot shrink except in call returns, @@ -1426,24 +1417,28 @@ duk_idx_t count = idx_rcbase - idx_retbase; DUK_DDD(DUK_DDDPRINT("elements at/after idx_retbase have enough to cover func retvals " - "(idx_retbase=%ld, idx_rcbase=%ld)", (long) idx_retbase, (long) idx_rcbase)); + "(idx_retbase=%ld, idx_rcbase=%ld)", + (long) idx_retbase, + (long) idx_rcbase)); /* Remove values between irc_rcbase (start of intended return * values) and idx_retbase to lower return values to idx_retbase. */ DUK_ASSERT(count > 0); - duk_remove_n(thr, idx_retbase, count); /* may be NORZ */ + duk_remove_n(thr, idx_retbase, count); /* may be NORZ */ } else { duk_idx_t count = idx_retbase - idx_rcbase; DUK_DDD(DUK_DDDPRINT("not enough elements at/after idx_retbase to cover func retvals " - "(idx_retbase=%ld, idx_rcbase=%ld)", (long) idx_retbase, (long) idx_rcbase)); + "(idx_retbase=%ld, idx_rcbase=%ld)", + (long) idx_retbase, + (long) idx_rcbase)); /* Insert 'undefined' at idx_rcbase (start of intended return * values) to lift return values to idx_retbase. */ DUK_ASSERT(count >= 0); - DUK_ASSERT(thr->valstack_end - thr->valstack_top >= count); /* reserve cannot shrink */ + DUK_ASSERT(thr->valstack_end - thr->valstack_top >= count); /* reserve cannot shrink */ duk_insert_undefined_n(thr, idx_rcbase, count); } @@ -1504,12 +1499,12 @@ #if defined(DUK_USE_ES6_PROXY) | (duk_small_uint_t) ((act->flags & DUK_ACT_FLAG_CONSTRUCT_PROXY) ? 2 : 0) #endif - ; + ; flags2 = (duk_small_uint_t) ((call_flags & DUK_CALL_FLAG_CONSTRUCT) ? 1 : 0) #if defined(DUK_USE_ES6_PROXY) | (duk_small_uint_t) ((call_flags & DUK_CALL_FLAG_CONSTRUCT_PROXY) ? 2 : 0); #endif - ; + ; if (flags1 != flags2) { DUK_DDD(DUK_DDDPRINT("tail call prevented by incompatible return value handling")); return 0; @@ -1547,8 +1542,7 @@ * https://github.com/svaarala/duktape/issues/1726. */ - DUK_DDD(DUK_DDDPRINT("is tail call, reusing activation at callstack top, at index %ld", - (long) (thr->callstack_top - 1))); + DUK_DDD(DUK_DDDPRINT("is tail call, reusing activation at callstack top, at index %ld", (long) (thr->callstack_top - 1))); DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(func)); @@ -1592,7 +1586,7 @@ act->lex_env = NULL; DUK_ASSERT(func != NULL); DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func)); - act->func = func; /* don't want an intermediate exposed state with func == NULL */ + act->func = func; /* don't want an intermediate exposed state with func == NULL */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) act->prev_caller = NULL; #endif @@ -1601,7 +1595,7 @@ #if defined(DUK_USE_DEBUGGER_SUPPORT) act->prev_line = 0; #endif - DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ + DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ DUK_HOBJECT_INCREF(thr, func); act->flags = DUK_ACT_FLAG_TAILCALLED; @@ -1617,10 +1611,10 @@ } #endif - DUK_ASSERT(DUK_ACT_GET_FUNC(act) == func); /* already updated */ + DUK_ASSERT(DUK_ACT_GET_FUNC(act) == func); /* already updated */ DUK_ASSERT(act->var_env == NULL); DUK_ASSERT(act->lex_env == NULL); - act->bottom_byteoff = entry_valstack_bottom_byteoff; /* tail call -> reuse current "frame" */ + act->bottom_byteoff = entry_valstack_bottom_byteoff; /* tail call -> reuse current "frame" */ #if 0 /* Topmost activation retval_byteoff is considered garbage, no need to init. */ act->retval_byteoff = 0; @@ -1645,22 +1639,23 @@ tv1 = thr->valstack_bottom - 1; tv2 = thr->valstack_bottom + idx_func + 1; - DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); /* tv1 is -below- valstack_bottom */ + DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); /* tv1 is -below- valstack_bottom */ DUK_ASSERT(tv2 >= thr->valstack_bottom && tv2 < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ idx_args = idx_func + 2; - duk_remove_n(thr, 0, idx_args); /* may be NORZ */ + duk_remove_n(thr, 0, idx_args); /* may be NORZ */ - idx_func = 0; DUK_UNREF(idx_func); /* really 'not applicable' anymore, should not be referenced after this */ + idx_func = 0; + DUK_UNREF(idx_func); /* really 'not applicable' anymore, should not be referenced after this */ idx_args = 0; *out_nargs = ((duk_hcompfunc *) func)->nargs; *out_nregs = ((duk_hcompfunc *) func)->nregs; DUK_ASSERT(*out_nregs >= 0); DUK_ASSERT(*out_nregs >= *out_nargs); - *out_vs_min_bytes = entry_valstack_bottom_byteoff + sizeof(duk_tval) * ((duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); - + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + sizeof(duk_tval) * ((duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) #if defined(DUK_USE_TAILCALL) @@ -1677,7 +1672,7 @@ return 1; } -#endif /* DUK_USE_TAILCALL */ +#endif /* DUK_USE_TAILCALL */ DUK_LOCAL void duk__call_setup_act_not_tailcall(duk_hthread *thr, duk_small_uint_t call_flags, @@ -1694,8 +1689,7 @@ DUK_UNREF(entry_valstack_end_byteoff); - DUK_DDD(DUK_DDDPRINT("not a tail call, pushing a new activation to callstack, to index %ld", - (long) (thr->callstack_top))); + DUK_DDD(DUK_DDDPRINT("not a tail call, pushing a new activation to callstack, to index %ld", (long) (thr->callstack_top))); duk__call_callstack_limit_check(thr); new_act = duk_hthread_activation_alloc(thr); @@ -1722,7 +1716,7 @@ act = new_act; *out_act = act; - DUK_ASSERT(thr->valstack_top > thr->valstack_bottom); /* at least effective 'this' */ + DUK_ASSERT(thr->valstack_top > thr->valstack_bottom); /* at least effective 'this' */ DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); act->cat = NULL; @@ -1741,9 +1735,9 @@ } /* start of arguments: idx_func + 2. */ - act->func = func; /* NULL for lightfunc */ + act->func = func; /* NULL for lightfunc */ if (DUK_LIKELY(func != NULL)) { - DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ + DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ if (DUK_HOBJECT_HAS_STRICT(func)) { act->flags |= DUK_ACT_FLAG_STRICT; } @@ -1752,8 +1746,9 @@ *out_nregs = ((duk_hcompfunc *) func)->nregs; DUK_ASSERT(*out_nregs >= 0); DUK_ASSERT(*out_nregs >= *out_nargs); - *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); } else { /* True because of call target lookup checks. */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(func)); @@ -1761,13 +1756,16 @@ *out_nargs = ((duk_hnatfunc *) func)->nargs; *out_nregs = *out_nargs; if (*out_nargs >= 0) { - *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); } else { /* Vararg function. */ - duk_size_t valstack_top_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); - *out_vs_min_bytes = valstack_top_byteoff + - sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + duk_size_t valstack_top_byteoff = + (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); + *out_vs_min_bytes = valstack_top_byteoff + sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + + DUK_VALSTACK_INTERNAL_EXTRA); } } } else { @@ -1778,18 +1776,20 @@ tv_func = DUK_GET_TVAL_POSIDX(thr, idx_func); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(tv_func)); - DUK_TVAL_SET_TVAL(&act->tv_func, tv_func); /* borrowed, no refcount */ + DUK_TVAL_SET_TVAL(&act->tv_func, tv_func); /* borrowed, no refcount */ lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv_func); *out_nargs = DUK_LFUNC_FLAGS_GET_NARGS(lf_flags); if (*out_nargs != DUK_LFUNC_NARGS_VARARGS) { *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nargs + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nargs + + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); } else { - duk_size_t valstack_top_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); + duk_size_t valstack_top_byteoff = + (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); *out_vs_min_bytes = valstack_top_byteoff + - sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); - *out_nargs = -1; /* vararg */ + sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + *out_nargs = -1; /* vararg */ } *out_nregs = *out_nargs; } @@ -1811,13 +1811,13 @@ * even in error unwind because reserve_byteoff is only used when * returning to -this- activation. */ - act->reserve_byteoff = 0; /* filled in by caller */ + act->reserve_byteoff = 0; /* filled in by caller */ /* XXX: Is this INCREF necessary? 'func' is always a borrowed * reference reachable through the value stack? If changed, stack * unwind code also needs to be fixed to match. */ - DUK_HOBJECT_INCREF_ALLOWNULL(thr, func); /* act->func */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, func); /* act->func */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) if (func) { @@ -1833,7 +1833,7 @@ DUK_LOCAL void duk__call_env_setup(duk_hthread *thr, duk_hobject *func, duk_activation *act, duk_idx_t idx_args) { duk_hobject *env; - DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound function has already been resolved */ + DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound function has already been resolved */ if (DUK_LIKELY(func != NULL)) { if (DUK_LIKELY(DUK_HOBJECT_HAS_NEWENV(func))) { @@ -1864,7 +1864,7 @@ act->lex_env = env; act->var_env = env; DUK_HOBJECT_INCREF(thr, env); - DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (2) directly */ + DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (2) directly */ duk_pop(thr); } } else { @@ -1902,8 +1902,7 @@ goto thread_state_error; } } else { - DUK_ASSERT(thr->heap->curr_thread == NULL || - thr->heap->curr_thread->state == DUK_HTHREAD_STATE_RUNNING); + DUK_ASSERT(thr->heap->curr_thread == NULL || thr->heap->curr_thread->state == DUK_HTHREAD_STATE_RUNNING); if (DUK_UNLIKELY(thr->state != DUK_HTHREAD_STATE_INACTIVE)) { goto thread_state_error; } @@ -1918,7 +1917,7 @@ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); return; - thread_state_error: +thread_state_error: DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "invalid thread state (%ld)", (long) thr->state); DUK_WO_NORETURN(return;); } @@ -1944,9 +1943,7 @@ * place; the only guarantee is that the state is consistent for unwinding. */ -DUK_LOCAL duk_int_t duk__handle_call_raw(duk_hthread *thr, - duk_idx_t idx_func, - duk_small_uint_t call_flags) { +DUK_LOCAL duk_int_t duk__handle_call_raw(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags) { #if defined(DUK_USE_ASSERTIONS) duk_activation *entry_act; duk_size_t entry_callstack_top; @@ -1958,10 +1955,10 @@ duk_uint_fast8_t entry_thread_state; duk_instr_t **entry_ptr_curr_pc; duk_idx_t idx_args; - duk_idx_t nargs; /* # argument registers target function wants (< 0 => "as is") */ - duk_idx_t nregs; /* # total registers target function wants on entry (< 0 => "as is") */ - duk_size_t vs_min_bytes; /* minimum value stack size (bytes) for handling call */ - duk_hobject *func; /* 'func' on stack (borrowed reference) */ + duk_idx_t nargs; /* # argument registers target function wants (< 0 => "as is") */ + duk_idx_t nregs; /* # total registers target function wants on entry (< 0 => "as is") */ + duk_size_t vs_min_bytes; /* minimum value stack size (bytes) for handling call */ + duk_hobject *func; /* 'func' on stack (borrowed reference) */ duk_activation *act; duk_ret_t rc; duk_small_uint_t use_tailcall; @@ -2002,7 +1999,7 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(tmp_cat) == DUK_CAT_TYPE_LABEL); /* a non-catching entry */ } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Store entry state. @@ -2015,9 +2012,9 @@ entry_valstack_bottom_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack); entry_valstack_end_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); entry_call_recursion_depth = thr->heap->call_recursion_depth; - entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ + entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ entry_thread_state = thr->state; - entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ + entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ /* If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL * thr->ptr_curr_pc so that it's not accidentally used with an incorrect @@ -2085,11 +2082,10 @@ DUK_DDD(DUK_DDDPRINT("slow path target resolve")); func = duk__resolve_target_func_and_this_binding(thr, idx_func, &call_flags); } - DUK_ASSERT(duk_get_top(thr) - idx_func >= 2); /* at least func and this present */ + DUK_ASSERT(duk_get_top(thr) - idx_func >= 2); /* at least func and this present */ DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || - DUK_HOBJECT_IS_NATFUNC(func))); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || DUK_HOBJECT_IS_NATFUNC(func))); /* ... func this arg1 ... argN */ @@ -2124,7 +2120,7 @@ &act); } #else - DUK_ASSERT((call_flags & DUK_CALL_FLAG_TAILCALL) == 0); /* compiler ensures this */ + DUK_ASSERT((call_flags & DUK_CALL_FLAG_TAILCALL) == 0); /* compiler ensures this */ use_tailcall = 0; #endif @@ -2151,6 +2147,15 @@ /* ... func this arg1 ... argN */ /* + * Grow value stack to required size before env setup. This + * must happen before env setup to handle some corner cases + * correctly, e.g. test-bug-scope-segv-gh2448.js. + */ + + duk_valstack_grow_check_throw(thr, vs_min_bytes); + act->reserve_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); + + /* * Environment record creation and 'arguments' object creation. * Named function expression name binding is handled by the * compiler; the compiled function's parent env will contain @@ -2171,13 +2176,8 @@ * Setup value stack: clamp to 'nargs', fill up to 'nregs', * ensure value stack size matches target requirements, and * switch value stack bottom. Valstack top is kept. - * - * Value stack can only grow here. */ - duk_valstack_grow_check_throw(thr, vs_min_bytes); - act->reserve_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); - if (use_tailcall) { DUK_ASSERT(nregs >= 0); DUK_ASSERT(nregs >= nargs); @@ -2216,8 +2216,8 @@ DUK_ASSERT((act->flags & DUK_ACT_FLAG_PREVENT_YIELD) == 0); DUK_REFZERO_CHECK_FAST(thr); DUK_ASSERT(thr->ptr_curr_pc == NULL); - thr->heap->call_recursion_depth--; /* No recursion increase for this case. */ - return 1; /* 1=reuse executor */ + thr->heap->call_recursion_depth--; /* No recursion increase for this case. */ + return 1; /* 1=reuse executor */ } DUK_ASSERT(use_tailcall == 0); @@ -2341,7 +2341,7 @@ /* Explicit check for fastint downgrade. */ DUK_TVAL_CHKFAST_INPLACE_FAST(tv_funret); #endif - DUK_TVAL_SET_TVAL_UPDREF(thr, tv_ret, tv_funret); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv_ret, tv_funret); /* side effects */ } duk_set_top_unsafe(thr, idx_func + 1); @@ -2360,7 +2360,7 @@ /* Restore entry thread executor curr_pc stack frame pointer. */ thr->ptr_curr_pc = entry_ptr_curr_pc; - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; /* Disabled assert: triggered with some torture tests. */ @@ -2401,12 +2401,10 @@ DUK_REFZERO_CHECK_FAST(thr); - return 0; /* 0=call handled inline */ + return 0; /* 0=call handled inline */ } -DUK_INTERNAL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, - duk_idx_t nargs, - duk_small_uint_t call_flags) { +DUK_INTERNAL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags) { duk_idx_t idx_func; DUK_ASSERT(duk_get_top(thr) >= nargs + 2); idx_func = duk_get_top(thr) - (nargs + 2); @@ -2414,9 +2412,7 @@ return duk_handle_call_unprotected(thr, idx_func, call_flags); } -DUK_INTERNAL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, - duk_idx_t idx_func, - duk_small_uint_t call_flags) { +DUK_INTERNAL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags) { DUK_ASSERT(duk_is_valid_index(thr, idx_func)); DUK_ASSERT(idx_func >= 0); return duk__handle_call_raw(thr, idx_func, call_flags); @@ -2483,7 +2479,8 @@ /* we're running inside the caller's activation, so no change in call/catch stack or valstack bottom */ DUK_ASSERT(thr->callstack_top == entry_callstack_top); DUK_ASSERT(thr->valstack_bottom >= thr->valstack); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == entry_valstack_bottom_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == + entry_valstack_bottom_byteoff); DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); DUK_ASSERT(thr->valstack_end >= thr->valstack_top); @@ -2493,9 +2490,9 @@ } DUK_ASSERT(rc >= 0); - duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, rc); /* throws for insane rc */ + duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, rc); /* throws for insane rc */ - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; } @@ -2548,7 +2545,7 @@ /* Switch active thread before any side effects to avoid a * dangling curr_thread pointer. */ - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; DUK_ASSERT(thr->heap->curr_thread == entry_curr_thread); @@ -2564,9 +2561,9 @@ /* ... | (crud) errobj */ - DUK_ASSERT(duk_get_top(thr) >= 1); /* at least errobj must be on stack */ + DUK_ASSERT(duk_get_top(thr) >= 1); /* at least errobj must be on stack */ - duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, 1); /* 1 = num actual 'return values' */ + duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, 1); /* 1 = num actual 'return values' */ /* ... | or ... | errobj (M * undefined) where M = num_stack_rets - 1 */ @@ -2652,7 +2649,7 @@ duk_int_t retval; DUK_ASSERT(thr != NULL); - DUK_ASSERT(duk_get_top(thr) >= num_stack_args); /* Caller ensures. */ + DUK_ASSERT(duk_get_top(thr) >= num_stack_args); /* Caller ensures. */ DUK_STATS_INC(thr->heap, stats_safecall_all); @@ -2671,14 +2668,14 @@ entry_callstack_preventcount = thr->callstack_preventcount; #endif entry_call_recursion_depth = thr->heap->call_recursion_depth; - entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ + entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ entry_thread_state = thr->state; - entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ - idx_retbase = duk_get_top(thr) - num_stack_args; /* not a valid stack index if num_stack_args == 0 */ + entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ + idx_retbase = duk_get_top(thr) - num_stack_args; /* not a valid stack index if num_stack_args == 0 */ DUK_ASSERT(idx_retbase >= 0); - DUK_ASSERT((duk_idx_t) (thr->valstack_top - thr->valstack_bottom) >= num_stack_args); /* Caller ensures. */ - DUK_ASSERT((duk_idx_t) (thr->valstack_end - (thr->valstack_bottom + idx_retbase)) >= num_stack_rets); /* Caller ensures. */ + DUK_ASSERT((duk_idx_t) (thr->valstack_top - thr->valstack_bottom) >= num_stack_args); /* Caller ensures. */ + DUK_ASSERT((duk_idx_t) (thr->valstack_end - (thr->valstack_bottom + idx_retbase)) >= num_stack_rets); /* Caller ensures. */ /* Cannot portably debug print a function pointer, hence 'func' not printed! */ DUK_DD(DUK_DDPRINT("duk_handle_safe_call: thr=%p, num_stack_args=%ld, num_stack_rets=%ld, " @@ -2738,7 +2735,8 @@ * whatever calls are made. Reserve cannot decrease. */ DUK_ASSERT(thr->callstack_curr == entry_act); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); retval = DUK_EXEC_SUCCESS; #if defined(DUK_USE_CPP_EXCEPTIONS) @@ -2748,7 +2746,8 @@ } else { /* Error path. */ #endif - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); @@ -2773,14 +2772,18 @@ throw; } catch (std::exception &exc) { const char *what = exc.what(); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); if (!what) { what = "unknown"; } DUK_D(DUK_DPRINT("unexpected c++ std::exception (perhaps thrown by user code)")); try { - DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", what); + DUK_ERROR_FMT1(thr, + DUK_ERR_TYPE_ERROR, + "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", + what); DUK_WO_NORETURN(return 0;); } catch (duk_internal_exception exc) { DUK_D(DUK_DPRINT("caught api error thrown from unexpected c++ std::exception")); @@ -2800,7 +2803,8 @@ } } catch (...) { DUK_D(DUK_DPRINT("unexpected c++ exception (perhaps thrown by user code)")); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); try { DUK_ERROR_TYPE(thr, "caught invalid c++ exception (perhaps thrown by user code)"); @@ -2824,7 +2828,7 @@ } #endif - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr == old_jmpbuf_ptr); /* success/error path both do this */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr == old_jmpbuf_ptr); /* success/error path both do this */ DUK_ASSERT_LJSTATE_UNSET(thr->heap); @@ -2845,7 +2849,8 @@ /* Final asserts. */ DUK_ASSERT(thr->callstack_curr == entry_act); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == entry_valstack_bottom_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == + entry_valstack_bottom_byteoff); DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); DUK_ASSERT(thr->callstack_top == entry_callstack_top); DUK_ASSERT(thr->heap->call_recursion_depth == entry_call_recursion_depth); @@ -2906,8 +2911,11 @@ str_base = duk_get_type_name(thr, -3); duk_push_error_object(thr, DUK_ERR_TYPE_ERROR | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - "%s not callable (property %s of %s)", str_targ, str_key, str_base); - duk_xdef_prop_stridx(thr, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ + "%s not callable (property %s of %s)", + str_targ, + str_key, + str_base); + duk_xdef_prop_stridx(thr, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ /* <nargs> target base key { _Target: error } */ duk_replace(thr, entry_top - 1); #else @@ -2916,9 +2924,12 @@ str_base = duk_push_string_readable(thr, -5); duk_push_error_object(thr, DUK_ERR_TYPE_ERROR | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - "%s not callable (property %s of %s)", str_targ, str_key, str_base); + "%s not callable (property %s of %s)", + str_targ, + str_key, + str_base); /* <nargs> target base key {} str_targ str_key str_base error */ - duk_xdef_prop_stridx(thr, -5, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ + duk_xdef_prop_stridx(thr, -5, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ /* <nargs> target base key { _Target: error } str_targ str_key str_base */ duk_swap(thr, -4, entry_top - 1); /* <nargs> { _Target: error } base key target str_targ str_key str_base */ @@ -2928,6 +2939,6 @@ duk_set_top(thr, entry_top); /* <nregs> { _Target: error } */ - DUK_ASSERT(!duk_is_callable(thr, -1)); /* Critical so that call handling will throw the error. */ + DUK_ASSERT(!duk_is_callable(thr, -1)); /* Critical so that call handling will throw the error. */ } -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_js_compiler.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_js_compiler.c
Changed
@@ -34,45 +34,51 @@ * uses this approach to avoid an explicit DUK__ISREG() check (the condition is * logically "'x' is a register AND 'x' >= temp_first"). */ -#define DUK__CONST_MARKER DUK_REGCONST_CONST_MARKER -#define DUK__REMOVECONST(x) ((x) & ~DUK__CONST_MARKER) -#define DUK__ISREG(x) ((x) >= 0) -#define DUK__ISCONST(x) ((x) < 0) -#define DUK__ISREG_TEMP(comp_ctx,x) ((duk_int32_t) (x) >= (duk_int32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= temp_first && x >= 0 by comparing as signed. */ -#define DUK__ISREG_NOTTEMP(comp_ctx,x) ((duk_uint32_t) (x) < (duk_uint32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= 0 && x < temp_first by interpreting as unsigned. */ -#define DUK__GETTEMP(comp_ctx) ((comp_ctx)->curr_func.temp_next) -#define DUK__SETTEMP(comp_ctx,x) ((comp_ctx)->curr_func.temp_next = (x)) /* dangerous: must only lower (temp_max not updated) */ -#define DUK__SETTEMP_CHECKMAX(comp_ctx,x) duk__settemp_checkmax((comp_ctx),(x)) -#define DUK__ALLOCTEMP(comp_ctx) duk__alloctemp((comp_ctx)) -#define DUK__ALLOCTEMPS(comp_ctx,count) duk__alloctemps((comp_ctx),(count)) +#define DUK__CONST_MARKER DUK_REGCONST_CONST_MARKER +#define DUK__REMOVECONST(x) ((x) & ~DUK__CONST_MARKER) +#define DUK__ISREG(x) ((x) >= 0) +#define DUK__ISCONST(x) ((x) < 0) +#define DUK__ISREG_TEMP(comp_ctx, x) \ + ((duk_int32_t) (x) >= \ + (duk_int32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= temp_first && x >= 0 by comparing as signed. */ +#define DUK__ISREG_NOTTEMP(comp_ctx, x) \ + ((duk_uint32_t) (x) < \ + (duk_uint32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= 0 && x < temp_first by interpreting as unsigned. */ +#define DUK__GETTEMP(comp_ctx) ((comp_ctx)->curr_func.temp_next) +#define DUK__SETTEMP(comp_ctx, x) ((comp_ctx)->curr_func.temp_next = (x)) /* dangerous: must only lower (temp_max not updated) */ +#define DUK__SETTEMP_CHECKMAX(comp_ctx, x) duk__settemp_checkmax((comp_ctx), (x)) +#define DUK__ALLOCTEMP(comp_ctx) duk__alloctemp((comp_ctx)) +#define DUK__ALLOCTEMPS(comp_ctx, count) duk__alloctemps((comp_ctx), (count)) /* Init value set size for array and object literals. */ -#define DUK__MAX_ARRAY_INIT_VALUES 20 -#define DUK__MAX_OBJECT_INIT_PAIRS 10 +#define DUK__MAX_ARRAY_INIT_VALUES 20 +#define DUK__MAX_OBJECT_INIT_PAIRS 10 /* XXX: hack, remove when const lookup is not O(n) */ -#define DUK__GETCONST_MAX_CONSTS_CHECK 256 +#define DUK__GETCONST_MAX_CONSTS_CHECK 256 /* These limits are based on bytecode limits. Max temps is limited * by duk_hcompfunc nargs/nregs fields being 16 bits. */ -#define DUK__MAX_CONSTS DUK_BC_BC_MAX -#define DUK__MAX_FUNCS DUK_BC_BC_MAX -#define DUK__MAX_TEMPS 0xffffL +#define DUK__MAX_CONSTS DUK_BC_BC_MAX +#define DUK__MAX_FUNCS DUK_BC_BC_MAX +#define DUK__MAX_TEMPS 0xffffL /* Initial bytecode size allocation. */ #if defined(DUK_USE_PREFER_SIZE) -#define DUK__BC_INITIAL_INSTS 16 +#define DUK__BC_INITIAL_INSTS 16 #else -#define DUK__BC_INITIAL_INSTS 256 +#define DUK__BC_INITIAL_INSTS 256 #endif -#define DUK__RECURSION_INCREASE(comp_ctx,thr) do { \ +#define DUK__RECURSION_INCREASE(comp_ctx, thr) \ + do { \ DUK_DDD(DUK_DDDPRINT("RECURSION INCREASE: %s:%ld", (const char *) DUK_FILE_MACRO, (long) DUK_LINE_MACRO)); \ duk__comp_recursion_increase((comp_ctx)); \ } while (0) -#define DUK__RECURSION_DECREASE(comp_ctx,thr) do { \ +#define DUK__RECURSION_DECREASE(comp_ctx, thr) \ + do { \ DUK_DDD(DUK_DDDPRINT("RECURSION DECREASE: %s:%ld", (const char *) DUK_FILE_MACRO, (long) DUK_LINE_MACRO)); \ duk__comp_recursion_decrease((comp_ctx)); \ } while (0) @@ -80,11 +86,11 @@ /* Value stack slot limits: these are quite approximate right now, and * because they overlap in control flow, some could be eliminated. */ -#define DUK__COMPILE_ENTRY_SLOTS 8 -#define DUK__FUNCTION_INIT_REQUIRE_SLOTS 16 -#define DUK__FUNCTION_BODY_REQUIRE_SLOTS 16 -#define DUK__PARSE_STATEMENTS_SLOTS 16 -#define DUK__PARSE_EXPR_SLOTS 16 +#define DUK__COMPILE_ENTRY_SLOTS 8 +#define DUK__FUNCTION_INIT_REQUIRE_SLOTS 16 +#define DUK__FUNCTION_BODY_REQUIRE_SLOTS 16 +#define DUK__PARSE_STATEMENTS_SLOTS 16 +#define DUK__PARSE_EXPR_SLOTS 16 /* Temporary structure used to pass a stack allocated region through * duk_safe_call(). @@ -116,10 +122,14 @@ DUK_LOCAL_DECL duk_compiler_instr *duk__get_instr_ptr(duk_compiler_ctx *comp_ctx, duk_int_t pc); DUK_LOCAL_DECL void duk__emit(duk_compiler_ctx *comp_ctx, duk_instr_t ins); DUK_LOCAL_DECL void duk__emit_op_only(duk_compiler_ctx *comp_ctx, duk_small_uint_t op); -DUK_LOCAL_DECL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b, duk_regconst_t c); +DUK_LOCAL_DECL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, + duk_small_uint_t op_flags, + duk_regconst_t a, + duk_regconst_t b, + duk_regconst_t c); DUK_LOCAL_DECL void duk__emit_a_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b); DUK_LOCAL_DECL void duk__emit_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b, duk_regconst_t c); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL void duk__emit_a(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a); DUK_LOCAL_DECL void duk__emit_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b); #endif @@ -133,7 +143,12 @@ DUK_LOCAL_DECL void duk__insert_jump_entry(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc); DUK_LOCAL_DECL void duk__patch_jump(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc, duk_int_t target_pc); DUK_LOCAL_DECL void duk__patch_jump_here(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc); -DUK_LOCAL_DECL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, duk_int_t ldconst_pc, duk_int_t trycatch_pc, duk_regconst_t reg_catch, duk_regconst_t const_varname, duk_small_uint_t flags); +DUK_LOCAL_DECL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, + duk_int_t ldconst_pc, + duk_int_t trycatch_pc, + duk_regconst_t reg_catch, + duk_regconst_t const_varname, + duk_small_uint_t flags); DUK_LOCAL_DECL void duk__emit_if_false_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst); DUK_LOCAL_DECL void duk__emit_if_true_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst); DUK_LOCAL_DECL void duk__emit_invalid(duk_compiler_ctx *comp_ctx); @@ -164,7 +179,7 @@ duk_regconst_t forced_reg, duk_small_uint_t flags); DUK_LOCAL_DECL duk_regconst_t duk__ivalue_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *x); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__ivalue_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *x); #endif DUK_LOCAL_DECL void duk__ivalue_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *x, duk_int_t forced_reg); @@ -178,7 +193,13 @@ /* label handling */ DUK_LOCAL_DECL void duk__add_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_int_t pc_label, duk_int_t label_id); DUK_LOCAL_DECL void duk__update_label_flags(duk_compiler_ctx *comp_ctx, duk_int_t label_id, duk_small_uint_t flags); -DUK_LOCAL_DECL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_bool_t is_break, duk_int_t *out_label_id, duk_int_t *out_label_catch_depth, duk_int_t *out_label_pc, duk_bool_t *out_is_closest); +DUK_LOCAL_DECL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, + duk_hstring *h_label, + duk_bool_t is_break, + duk_int_t *out_label_id, + duk_int_t *out_label_catch_depth, + duk_int_t *out_label_pc, + duk_bool_t *out_is_closest); DUK_LOCAL_DECL void duk__reset_labels_to_length(duk_compiler_ctx *comp_ctx, duk_size_t len); /* top-down expression parser */ @@ -192,26 +213,32 @@ DUK_LOCAL_DECL void duk__exprtop(duk_compiler_ctx *ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); /* convenience helpers */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -DUK_LOCAL_DECL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg); +DUK_LOCAL_DECL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg); DUK_LOCAL_DECL duk_regconst_t duk__expr_toregconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_totempconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif DUK_LOCAL_DECL void duk__expr_toplain(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); DUK_LOCAL_DECL void duk__expr_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); DUK_LOCAL_DECL duk_regconst_t duk__exprtop_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__exprtop_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -DUK_LOCAL_DECL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg); +DUK_LOCAL_DECL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg); DUK_LOCAL_DECL duk_regconst_t duk__exprtop_toregconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL void duk__exprtop_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif @@ -221,7 +248,11 @@ DUK_LOCAL_DECL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res); /* statement parsing */ -DUK_LOCAL_DECL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags, duk_regconst_t *out_reg_varbind, duk_regconst_t *out_rc_varname); +DUK_LOCAL_DECL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t expr_flags, + duk_regconst_t *out_reg_varbind, + duk_regconst_t *out_rc_varname); DUK_LOCAL_DECL void duk__parse_var_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags); DUK_LOCAL_DECL void duk__parse_for_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site); DUK_LOCAL_DECL void duk__parse_switch_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site); @@ -235,18 +266,25 @@ DUK_LOCAL_DECL void duk__parse_with_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res); DUK_LOCAL_DECL void duk__parse_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_bool_t allow_source_elem); DUK_LOCAL_DECL duk_int_t duk__stmt_label_site(duk_compiler_ctx *comp_ctx, duk_int_t label_id); -DUK_LOCAL_DECL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, duk_bool_t allow_source_elem, duk_bool_t expect_eof, duk_bool_t regexp_after); - -DUK_LOCAL_DECL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, duk_bool_t expect_eof, duk_bool_t implicit_return_value, duk_bool_t regexp_after, duk_small_int_t expect_token); +DUK_LOCAL_DECL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, + duk_bool_t allow_source_elem, + duk_bool_t expect_eof, + duk_bool_t regexp_after); + +DUK_LOCAL_DECL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, + duk_bool_t expect_eof, + duk_bool_t implicit_return_value, + duk_bool_t regexp_after, + duk_small_int_t expect_token); DUK_LOCAL_DECL void duk__parse_func_formals(duk_compiler_ctx *comp_ctx); DUK_LOCAL_DECL void duk__parse_func_like_raw(duk_compiler_ctx *comp_ctx, duk_small_uint_t flags); DUK_LOCAL_DECL duk_int_t duk__parse_func_like_fnum(duk_compiler_ctx *comp_ctx, duk_small_uint_t flags); -#define DUK__FUNC_FLAG_DECL (1 << 0) /* Parsing a function declaration. */ -#define DUK__FUNC_FLAG_GETSET (1 << 1) /* Parsing an object literal getter/setter. */ -#define DUK__FUNC_FLAG_METDEF (1 << 2) /* Parsing an object literal method definition shorthand. */ -#define DUK__FUNC_FLAG_PUSHNAME_PASS1 (1 << 3) /* Push function name when creating template (first pass only). */ -#define DUK__FUNC_FLAG_USE_PREVTOKEN (1 << 4) /* Use prev_token to start function parsing (workaround for object literal). */ +#define DUK__FUNC_FLAG_DECL (1 << 0) /* Parsing a function declaration. */ +#define DUK__FUNC_FLAG_GETSET (1 << 1) /* Parsing an object literal getter/setter. */ +#define DUK__FUNC_FLAG_METDEF (1 << 2) /* Parsing an object literal method definition shorthand. */ +#define DUK__FUNC_FLAG_PUSHNAME_PASS1 (1 << 3) /* Push function name when creating template (first pass only). */ +#define DUK__FUNC_FLAG_USE_PREVTOKEN (1 << 4) /* Use prev_token to start function parsing (workaround for object literal). */ /* * Parser control values for tokens. The token table is ordered by the @@ -263,141 +301,141 @@ /* XXX: actually single step levels would work just fine, clean up */ /* binding power "levels" (see doc/compiler.rst) */ -#define DUK__BP_INVALID 0 /* always terminates led() */ -#define DUK__BP_EOF 2 -#define DUK__BP_CLOSING 4 /* token closes expression, e.g. ')', '' */ -#define DUK__BP_FOR_EXPR DUK__BP_CLOSING /* bp to use when parsing a top level Expression */ -#define DUK__BP_COMMA 6 -#define DUK__BP_ASSIGNMENT 8 -#define DUK__BP_CONDITIONAL 10 -#define DUK__BP_LOR 12 -#define DUK__BP_LAND 14 -#define DUK__BP_BOR 16 -#define DUK__BP_BXOR 18 -#define DUK__BP_BAND 20 -#define DUK__BP_EQUALITY 22 -#define DUK__BP_RELATIONAL 24 -#define DUK__BP_SHIFT 26 -#define DUK__BP_ADDITIVE 28 -#define DUK__BP_MULTIPLICATIVE 30 -#define DUK__BP_EXPONENTIATION 32 -#define DUK__BP_POSTFIX 34 -#define DUK__BP_CALL 36 -#define DUK__BP_MEMBER 38 +#define DUK__BP_INVALID 0 /* always terminates led() */ +#define DUK__BP_EOF 2 +#define DUK__BP_CLOSING 4 /* token closes expression, e.g. ')', '' */ +#define DUK__BP_FOR_EXPR DUK__BP_CLOSING /* bp to use when parsing a top level Expression */ +#define DUK__BP_COMMA 6 +#define DUK__BP_ASSIGNMENT 8 +#define DUK__BP_CONDITIONAL 10 +#define DUK__BP_LOR 12 +#define DUK__BP_LAND 14 +#define DUK__BP_BOR 16 +#define DUK__BP_BXOR 18 +#define DUK__BP_BAND 20 +#define DUK__BP_EQUALITY 22 +#define DUK__BP_RELATIONAL 24 +#define DUK__BP_SHIFT 26 +#define DUK__BP_ADDITIVE 28 +#define DUK__BP_MULTIPLICATIVE 30 +#define DUK__BP_EXPONENTIATION 32 +#define DUK__BP_POSTFIX 34 +#define DUK__BP_CALL 36 +#define DUK__BP_MEMBER 38 #define DUK__TOKEN_LBP_BP_MASK 0x1f -#define DUK__TOKEN_LBP_FLAG_NO_REGEXP (1 << 5) /* regexp literal must not follow this token */ -#define DUK__TOKEN_LBP_FLAG_TERMINATES (1 << 6) /* terminates expression; e.g. post-increment/-decrement */ -#define DUK__TOKEN_LBP_FLAG_UNUSED (1 << 7) /* unused */ +#define DUK__TOKEN_LBP_FLAG_NO_REGEXP (1 << 5) /* regexp literal must not follow this token */ +#define DUK__TOKEN_LBP_FLAG_TERMINATES (1 << 6) /* terminates expression; e.g. post-increment/-decrement */ +#define DUK__TOKEN_LBP_FLAG_UNUSED (1 << 7) /* unused */ -#define DUK__TOKEN_LBP_GET_BP(x) ((duk_small_uint_t) (((x) & DUK__TOKEN_LBP_BP_MASK) * 2)) +#define DUK__TOKEN_LBP_GET_BP(x) ((duk_small_uint_t) (((x) &DUK__TOKEN_LBP_BP_MASK) * 2)) -#define DUK__MK_LBP(bp) ((bp) >> 1) /* bp is assumed to be even */ -#define DUK__MK_LBP_FLAGS(bp,flags) (((bp) >> 1) | (flags)) +#define DUK__MK_LBP(bp) ((bp) >> 1) /* bp is assumed to be even */ +#define DUK__MK_LBP_FLAGS(bp, flags) (((bp) >> 1) | (flags)) DUK_LOCAL const duk_uint8_t duk__token_lbp = { - DUK__MK_LBP(DUK__BP_EOF), /* DUK_TOK_EOF */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_IDENTIFIER */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BREAK */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CASE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CATCH */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONTINUE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEBUGGER */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEFAULT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DELETE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DO */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ELSE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FINALLY */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FOR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FUNCTION */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IF */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_IN */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_INSTANCEOF */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_NEW */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_RETURN */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SWITCH */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_THIS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_THROW */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TRY */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TYPEOF */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VAR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONST */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VOID */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WHILE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WITH */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CLASS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ENUM */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXPORT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXTENDS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPORT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SUPER */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NULL */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_TRUE */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_FALSE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_GET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPLEMENTS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_INTERFACE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PACKAGE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PRIVATE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PROTECTED */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PUBLIC */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_STATIC */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_YIELD */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LCURLY */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RCURLY */ - DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_LBRACKET */ - DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RBRACKET */ - DUK__MK_LBP(DUK__BP_CALL), /* DUK_TOK_LPAREN */ - DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RPAREN */ - DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_PERIOD */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SEMICOLON */ - DUK__MK_LBP(DUK__BP_COMMA), /* DUK_TOK_COMMA */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LT */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GT */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LE */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GE */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_EQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_NEQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SEQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SNEQ */ - DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_ADD */ - DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_SUB */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MUL */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_DIV */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MOD */ - DUK__MK_LBP(DUK__BP_EXPONENTIATION), /* DUK_TOK_EXP */ - DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_INCREMENT */ - DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_DECREMENT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ALSHIFT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ARSHIFT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_RSHIFT */ - DUK__MK_LBP(DUK__BP_BAND), /* DUK_TOK_BAND */ - DUK__MK_LBP(DUK__BP_BOR), /* DUK_TOK_BOR */ - DUK__MK_LBP(DUK__BP_BXOR), /* DUK_TOK_BXOR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LNOT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BNOT */ - DUK__MK_LBP(DUK__BP_LAND), /* DUK_TOK_LAND */ - DUK__MK_LBP(DUK__BP_LOR), /* DUK_TOK_LOR */ - DUK__MK_LBP(DUK__BP_CONDITIONAL), /* DUK_TOK_QUESTION */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_COLON */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EQUALSIGN */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ADD_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_SUB_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MUL_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_DIV_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MOD_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EXP_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ALSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ARSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_RSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BAND_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BOR_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BXOR_EQ */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NUMBER */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_STRING */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_REGEXP */ + DUK__MK_LBP(DUK__BP_EOF), /* DUK_TOK_EOF */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_IDENTIFIER */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BREAK */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CASE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CATCH */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONTINUE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEBUGGER */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEFAULT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DELETE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DO */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ELSE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FINALLY */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FOR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FUNCTION */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IF */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_IN */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_INSTANCEOF */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_NEW */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_RETURN */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SWITCH */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_THIS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_THROW */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TRY */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TYPEOF */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VAR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONST */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VOID */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WHILE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WITH */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CLASS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ENUM */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXPORT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXTENDS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPORT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SUPER */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NULL */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_TRUE */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_FALSE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_GET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPLEMENTS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_INTERFACE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PACKAGE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PRIVATE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PROTECTED */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PUBLIC */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_STATIC */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_YIELD */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LCURLY */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RCURLY */ + DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_LBRACKET */ + DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RBRACKET */ + DUK__MK_LBP(DUK__BP_CALL), /* DUK_TOK_LPAREN */ + DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RPAREN */ + DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_PERIOD */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SEMICOLON */ + DUK__MK_LBP(DUK__BP_COMMA), /* DUK_TOK_COMMA */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LT */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GT */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LE */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GE */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_EQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_NEQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SEQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SNEQ */ + DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_ADD */ + DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_SUB */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MUL */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_DIV */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MOD */ + DUK__MK_LBP(DUK__BP_EXPONENTIATION), /* DUK_TOK_EXP */ + DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_INCREMENT */ + DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_DECREMENT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ALSHIFT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ARSHIFT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_RSHIFT */ + DUK__MK_LBP(DUK__BP_BAND), /* DUK_TOK_BAND */ + DUK__MK_LBP(DUK__BP_BOR), /* DUK_TOK_BOR */ + DUK__MK_LBP(DUK__BP_BXOR), /* DUK_TOK_BXOR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LNOT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BNOT */ + DUK__MK_LBP(DUK__BP_LAND), /* DUK_TOK_LAND */ + DUK__MK_LBP(DUK__BP_LOR), /* DUK_TOK_LOR */ + DUK__MK_LBP(DUK__BP_CONDITIONAL), /* DUK_TOK_QUESTION */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_COLON */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EQUALSIGN */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ADD_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_SUB_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MUL_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_DIV_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MOD_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EXP_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ALSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ARSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_RSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BAND_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BOR_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BXOR_EQ */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NUMBER */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_STRING */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_REGEXP */ }; /* @@ -428,8 +466,7 @@ DUK_LOCAL duk_bool_t duk__hstring_is_eval_or_arguments_in_strict_mode(duk_compiler_ctx *comp_ctx, duk_hstring *h) { DUK_ASSERT(h != NULL); - return (comp_ctx->curr_func.is_strict && - DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(h)); + return (comp_ctx->curr_func.is_strict && DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(h)); } /* @@ -444,8 +481,8 @@ duk_hthread *thr = comp_ctx->thr; duk_bool_t regexp; - DUK_ASSERT_DISABLE(comp_ctx->curr_token.t >= 0); /* unsigned */ - DUK_ASSERT(comp_ctx->curr_token.t <= DUK_TOK_MAXVAL); /* MAXVAL is inclusive */ + DUK_ASSERT_DISABLE(comp_ctx->curr_token.t >= 0); /* unsigned */ + DUK_ASSERT(comp_ctx->curr_token.t <= DUK_TOK_MAXVAL); /* MAXVAL is inclusive */ /* * Use current token to decide whether a RegExp can follow. @@ -470,8 +507,7 @@ } if (expect >= 0 && comp_ctx->curr_token.t != (duk_small_uint_t) expect) { - DUK_D(DUK_DPRINT("parse error: expect=%ld, got=%ld", - (long) expect, (long) comp_ctx->curr_token.t)); + DUK_D(DUK_DPRINT("parse error: expect=%ld, got=%ld", (long) expect, (long) comp_ctx->curr_token.t)); DUK_ERROR_SYNTAX(thr, DUK_STR_PARSE_ERROR); DUK_WO_NORETURN(return;); } @@ -482,10 +518,7 @@ duk_copy(thr, comp_ctx->tok12_idx, comp_ctx->tok22_idx); /* parse new token */ - duk_lexer_parse_js_input_element(&comp_ctx->lex, - &comp_ctx->curr_token, - comp_ctx->curr_func.is_strict, - regexp); + duk_lexer_parse_js_input_element(&comp_ctx->lex, &comp_ctx->curr_token, comp_ctx->curr_func.is_strict, regexp); DUK_DDD(DUK_DDDPRINT("advance: curr: tok=%ld/%ld,%ld,term=%ld,%!T,%!T " "prev: tok=%ld/%ld,%ld,term=%ld,%!T,%!T", @@ -525,7 +558,7 @@ entry_top = duk_get_top(thr); - duk_memzero(func, sizeof(*func)); /* intentional overlap with earlier memzero */ + duk_memzero(func, sizeof(*func)); /* intentional overlap with earlier memzero */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) func->h_name = NULL; func->h_consts = NULL; @@ -691,7 +724,7 @@ h_res = duk_push_hcompfunc(thr); DUK_ASSERT(h_res != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_res) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); - DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) h_res, NULL); /* Function templates are "bare objects". */ + DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) h_res, NULL); /* Function templates are "bare objects". */ if (func->is_function) { DUK_DDD(DUK_DDDPRINT("function -> set NEWENV")); @@ -760,16 +793,19 @@ code_count = DUK_BW_GET_SIZE(thr, &func->bw_code) / sizeof(duk_compiler_instr); code_size = code_count * sizeof(duk_instr_t); - data_size = consts_count * sizeof(duk_tval) + - funcs_count * sizeof(duk_hobject *) + - code_size; + data_size = consts_count * sizeof(duk_tval) + funcs_count * sizeof(duk_hobject *) + code_size; DUK_DDD(DUK_DDDPRINT("consts_count=%ld, funcs_count=%ld, code_size=%ld -> " "data_size=%ld*%ld + %ld*%ld + %ld = %ld", - (long) consts_count, (long) funcs_count, (long) code_size, - (long) consts_count, (long) sizeof(duk_tval), - (long) funcs_count, (long) sizeof(duk_hobject *), - (long) code_size, (long) data_size)); + (long) consts_count, + (long) funcs_count, + (long) code_size, + (long) consts_count, + (long) sizeof(duk_tval), + (long) funcs_count, + (long) sizeof(duk_hobject *), + (long) code_size, + (long) data_size)); duk_push_fixed_buffer_nozero(thr, data_size); h_data = (duk_hbuffer_fixed *) (void *) duk_known_hbuffer(thr, -1); @@ -779,12 +815,12 @@ p_const = (duk_tval *) (void *) DUK_HBUFFER_FIXED_GET_DATA_PTR(thr->heap, h_data); for (i = 0; i < consts_count; i++) { - DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* const limits */ + DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* const limits */ tv = duk_hobject_find_array_entry_tval_ptr(thr->heap, func->h_consts, (duk_uarridx_t) i); DUK_ASSERT(tv != NULL); DUK_TVAL_SET_TVAL(p_const, tv); p_const++; - DUK_TVAL_INCREF(thr, tv); /* may be a string constant */ + DUK_TVAL_INCREF(thr, tv); /* may be a string constant */ DUK_DDD(DUK_DDDPRINT("constant: %!T", (duk_tval *) tv)); } @@ -793,7 +829,7 @@ DUK_HCOMPFUNC_SET_FUNCS(thr->heap, h_res, p_func); for (i = 0; i < funcs_count; i++) { duk_hobject *h; - DUK_ASSERT(i * 3 <= DUK_UARRIDX_MAX); /* func limits */ + DUK_ASSERT(i * 3 <= DUK_UARRIDX_MAX); /* func limits */ tv = duk_hobject_find_array_entry_tval_ptr(thr->heap, func->h_funcs, (duk_uarridx_t) (i * 3)); DUK_ASSERT(tv != NULL); DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv)); @@ -803,8 +839,7 @@ *p_func++ = h; DUK_HOBJECT_INCREF(thr, h); - DUK_DDD(DUK_DDDPRINT("inner function: %p -> %!iO", - (void *) h, (duk_heaphdr *) h)); + DUK_DDD(DUK_DDDPRINT("inner function: %p -> %!iO", (void *) h, (duk_heaphdr *) h)); } p_instr = (duk_instr_t *) p_func; @@ -819,7 +854,7 @@ DUK_ASSERT((duk_uint8_t *) (p_instr + code_count) == DUK_HBUFFER_FIXED_GET_DATA_PTR(thr->heap, h_data) + data_size); - duk_pop(thr); /* 'data' (and everything in it) is reachable through h_res now */ + duk_pop(thr); /* 'data' (and everything in it) is reachable through h_res now */ /* * Init non-property result fields @@ -834,7 +869,7 @@ DUK_ASSERT(func->temp_max >= 0); h_res->nregs = (duk_uint16_t) func->temp_max; h_res->nargs = (duk_uint16_t) duk_hobject_get_length(thr, func->h_argnames); - DUK_ASSERT(h_res->nregs >= h_res->nargs); /* pass2 allocation handles this */ + DUK_ASSERT(h_res->nregs >= h_res->nargs); /* pass2 allocation handles this */ #if defined(DUK_USE_DEBUGGER_SUPPORT) h_res->start_line = (duk_uint32_t) func->min_line; h_res->end_line = (duk_uint32_t) func->max_line; @@ -862,11 +897,13 @@ DUK_DD(DUK_DDPRINT("keeping _Varmap because debugger support is enabled")); keep_varmap = 1; #else - if (func->id_access_slow_own || /* directly uses slow accesses that may match own variables */ - func->id_access_arguments || /* accesses 'arguments' directly */ - func->may_direct_eval || /* may indirectly slow access through a direct eval */ - funcs_count > 0) { /* has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions) */ - DUK_DD(DUK_DDPRINT("keeping _Varmap because of direct eval, slow path access that may match local variables, or presence of inner functions")); + if (func->id_access_slow_own || /* directly uses slow accesses that may match own variables */ + func->id_access_arguments || /* accesses 'arguments' directly */ + func->may_direct_eval || /* may indirectly slow access through a direct eval */ + funcs_count > + 0) { /* has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions) */ + DUK_DD(DUK_DDPRINT("keeping _Varmap because of direct eval, slow path access that may match local variables, or " + "presence of inner functions")); keep_varmap = 1; } else { DUK_DD(DUK_DDPRINT("dropping _Varmap")); @@ -878,8 +915,7 @@ duk_int_t num_used; duk_dup(thr, func->varmap_idx); num_used = duk__cleanup_varmap(comp_ctx); - DUK_DDD(DUK_DDDPRINT("cleaned up varmap: %!T (num_used=%ld)", - (duk_tval *) duk_get_tval(thr, -1), (long) num_used)); + DUK_DDD(DUK_DDDPRINT("cleaned up varmap: %!T (num_used=%ld)", (duk_tval *) duk_get_tval(thr, -1), (long) num_used)); if (num_used > 0) { duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VARMAP, DUK_PROPDESC_FLAGS_NONE); @@ -908,12 +944,12 @@ */ DUK_DD(DUK_DDPRINT("keeping _Formals because _Formals.length != nargs")); keep_formals = 1; - } else if ((func->id_access_arguments || func->may_direct_eval) && - (formals_length > 0)) { + } else if ((func->id_access_arguments || func->may_direct_eval) && (formals_length > 0)) { /* Direct eval (may access 'arguments') or accesses 'arguments' * explicitly: keep _Formals unless it is zero length. */ - DUK_DD(DUK_DDPRINT("keeping _Formals because of direct eval or explicit access to 'arguments', and _Formals.length != 0")); + DUK_DD(DUK_DDPRINT( + "keeping _Formals because of direct eval or explicit access to 'arguments', and _Formals.length != 0")); keep_formals = 1; } else { DUK_DD(DUK_DDPRINT("omitting _Formals, nargs matches _Formals.length, so no properties added")); @@ -933,7 +969,7 @@ DUK_DD(DUK_DDPRINT("setting function template .name to %!T", duk_get_tval(thr, -1))); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_NONE); } -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ /* _Source */ #if defined(DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY) @@ -981,7 +1017,7 @@ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_SOURCE, DUK_PROPDESC_FLAGS_NONE); #endif } -#endif /* DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY */ +#endif /* DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY */ /* _Pc2line */ #if defined(DUK_USE_PC2LINE) @@ -991,14 +1027,14 @@ */ DUK_ASSERT(code_count <= DUK_COMPILER_MAX_BYTECODE_LENGTH); - duk_hobject_pc2line_pack(thr, q_instr, (duk_uint_fast32_t) code_count); /* -> pushes fixed buffer */ + duk_hobject_pc2line_pack(thr, q_instr, (duk_uint_fast32_t) code_count); /* -> pushes fixed buffer */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_NONE); /* XXX: if assertions enabled, walk through all valid PCs * and check line mapping. */ } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ /* fileName */ #if defined(DUK_USE_FUNC_FILENAME_PROPERTY) @@ -1012,8 +1048,7 @@ } #endif - DUK_DD(DUK_DDPRINT("converted function: %!ixT", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DD(DUK_DDPRINT("converted function: %!ixT", (duk_tval *) duk_get_tval(thr, -1))); /* * Compact the function template. @@ -1085,14 +1120,14 @@ /* Code emission flags, passed in the 'opcode' field. Opcode + flags * fit into 16 bits for now, so use duk_small_uint_t. */ -#define DUK__EMIT_FLAG_NO_SHUFFLE_A (1 << 8) -#define DUK__EMIT_FLAG_NO_SHUFFLE_B (1 << 9) -#define DUK__EMIT_FLAG_NO_SHUFFLE_C (1 << 10) -#define DUK__EMIT_FLAG_A_IS_SOURCE (1 << 11) /* slot A is a source (default: target) */ -#define DUK__EMIT_FLAG_B_IS_TARGET (1 << 12) /* slot B is a target (default: source) */ -#define DUK__EMIT_FLAG_C_IS_TARGET (1 << 13) /* slot C is a target (default: source) */ -#define DUK__EMIT_FLAG_BC_REGCONST (1 << 14) /* slots B and C are reg/const */ -#define DUK__EMIT_FLAG_RESERVE_JUMPSLOT (1 << 15) /* reserve a jumpslot after instr before target spilling, used for NEXTENUM */ +#define DUK__EMIT_FLAG_NO_SHUFFLE_A (1 << 8) +#define DUK__EMIT_FLAG_NO_SHUFFLE_B (1 << 9) +#define DUK__EMIT_FLAG_NO_SHUFFLE_C (1 << 10) +#define DUK__EMIT_FLAG_A_IS_SOURCE (1 << 11) /* slot A is a source (default: target) */ +#define DUK__EMIT_FLAG_B_IS_TARGET (1 << 12) /* slot B is a target (default: source) */ +#define DUK__EMIT_FLAG_C_IS_TARGET (1 << 13) /* slot C is a target (default: source) */ +#define DUK__EMIT_FLAG_BC_REGCONST (1 << 14) /* slots B and C are reg/const */ +#define DUK__EMIT_FLAG_RESERVE_JUMPSLOT (1 << 15) /* reserve a jumpslot after instr before target spilling, used for NEXTENUM */ /* XXX: macro smaller than call? */ DUK_LOCAL duk_int_t duk__get_current_pc(duk_compiler_ctx *comp_ctx) { @@ -1103,7 +1138,8 @@ DUK_LOCAL duk_compiler_instr *duk__get_instr_ptr(duk_compiler_ctx *comp_ctx, duk_int_t pc) { DUK_ASSERT(pc >= 0); - DUK_ASSERT((duk_size_t) pc < (duk_size_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr))); + DUK_ASSERT((duk_size_t) pc < + (duk_size_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr))); return ((duk_compiler_instr *) (void *) DUK_BW_GET_BASEPTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code)) + pc; } @@ -1123,7 +1159,9 @@ (long) duk__get_current_pc(comp_ctx), (duk_instr_t) ins)); - instr = (duk_compiler_instr *) (void *) DUK_BW_ENSURE_GETPTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, sizeof(duk_compiler_instr)); + instr = (duk_compiler_instr *) (void *) DUK_BW_ENSURE_GETPTR(comp_ctx->thr, + &comp_ctx->curr_func.bw_code, + sizeof(duk_compiler_instr)); DUK_BW_ADD_PTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, sizeof(duk_compiler_instr)); #if defined(DUK_USE_PC2LINE) @@ -1174,7 +1212,7 @@ return; - fail_bc_limit: +fail_bc_limit: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_BYTECODE_LIMIT); DUK_WO_NORETURN(return;); } @@ -1208,7 +1246,11 @@ } /* Important main primitive. */ -DUK_LOCAL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b, duk_regconst_t c) { +DUK_LOCAL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, + duk_small_uint_t op_flags, + duk_regconst_t a, + duk_regconst_t b, + duk_regconst_t c) { duk_instr_t ins = 0; duk_int_t a_out = -1; duk_int_t b_out = -1; @@ -1216,8 +1258,7 @@ duk_int_t tmp; duk_small_uint_t op = op_flags & 0xffU; - DUK_DDD(DUK_DDDPRINT("emit: op_flags=%04lx, a=%ld, b=%ld, c=%ld", - (unsigned long) op_flags, (long) a, (long) b, (long) c)); + DUK_DDD(DUK_DDDPRINT("emit: op_flags=%04lx, a=%ld, b=%ld, c=%ld", (unsigned long) op_flags, (long) a, (long) b, (long) c)); /* We could rely on max temp/const checks: if they don't exceed BC * limit, nothing here can either (just asserts would be enough). @@ -1226,11 +1267,11 @@ * bugs. */ - DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT((op_flags & 0xff) <= DUK_BC_OP_MAX); DUK_ASSERT(DUK__ISREG(a)); - DUK_ASSERT(b != -1); /* Not 'none'. */ - DUK_ASSERT(c != -1); /* Not 'none'. */ + DUK_ASSERT(b != -1); /* Not 'none'. */ + DUK_ASSERT(c != -1); /* Not 'none'. */ /* Input shuffling happens before the actual operation, while output * shuffling happens afterwards. Output shuffling decisions are still @@ -1292,7 +1333,7 @@ if (op_flags & DUK__EMIT_FLAG_BC_REGCONST) { /* Opcode follows B/C reg/const convention. */ DUK_ASSERT((op & 0x01) == 0); - ins |= DUK_ENC_OP_A_B_C(0x01, 0, 0, 0); /* const flag for B */ + ins |= DUK_ENC_OP_A_B_C(0x01, 0, 0, 0); /* const flag for B */ } else { DUK_D(DUK_DPRINT("B is const, opcode is not B/C reg/const: %x", op_flags)); } @@ -1315,7 +1356,8 @@ } else if (op_flags & DUK__EMIT_FLAG_NO_SHUFFLE_B) { if (b > DUK_BC_B_MAX) { /* Note: 0xff != DUK_BC_B_MAX */ - DUK_D(DUK_DPRINT("out of regs: 'b' (reg) needs shuffling but shuffle prohibited, b: %ld", (long) b)); + DUK_D( + DUK_DPRINT("out of regs: 'b' (reg) needs shuffling but shuffle prohibited, b: %ld", (long) b)); goto error_outofregs; } } else if (b <= DUK_BC_BC_MAX) { @@ -1336,7 +1378,7 @@ duk__emit_load_int32_noshuffle(comp_ctx, tmp, b); DUK_ASSERT(DUK_OP_MPUTOBJI == DUK_OP_MPUTOBJ + 1); DUK_ASSERT(DUK_OP_MPUTARRI == DUK_OP_MPUTARR + 1); - op_flags++; /* indirect opcode follows direct */ + op_flags++; /* indirect opcode follows direct */ } else { duk__emit(comp_ctx, DUK_ENC_OP_A_BC(DUK_OP_LDREG, tmp, b)); } @@ -1362,7 +1404,7 @@ if (op_flags & DUK__EMIT_FLAG_BC_REGCONST) { /* Opcode follows B/C reg/const convention. */ DUK_ASSERT((op & 0x02) == 0); - ins |= DUK_ENC_OP_A_B_C(0x02, 0, 0, 0); /* const flag for C */ + ins |= DUK_ENC_OP_A_B_C(0x02, 0, 0, 0); /* const flag for C */ } else { DUK_D(DUK_DPRINT("C is const, opcode is not B/C reg/const: %x", op_flags)); } @@ -1385,7 +1427,8 @@ } else if (op_flags & DUK__EMIT_FLAG_NO_SHUFFLE_C) { if (c > DUK_BC_C_MAX) { /* Note: 0xff != DUK_BC_C_MAX */ - DUK_D(DUK_DPRINT("out of regs: 'c' (reg) needs shuffling but shuffle prohibited, c: %ld", (long) c)); + DUK_D( + DUK_DPRINT("out of regs: 'c' (reg) needs shuffling but shuffle prohibited, c: %ld", (long) c)); goto error_outofregs; } } else if (c <= DUK_BC_BC_MAX) { @@ -1459,7 +1502,7 @@ return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -1487,7 +1530,7 @@ duk__emit_a_b_c(comp_ctx, op_flags, 0, b, c); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__emit_a(duk_compiler_ctx *comp_ctx, int op_flags, int a) { #if defined(DUK_USE_SHUFFLE_TORTURE) op_flags |= DUK__EMIT_FLAG_NO_SHUFFLE_B | DUK__EMIT_FLAG_NO_SHUFFLE_C; @@ -1496,7 +1539,7 @@ } #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__emit_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b) { #if defined(DUK_USE_SHUFFLE_TORTURE) op_flags |= DUK__EMIT_FLAG_NO_SHUFFLE_A | DUK__EMIT_FLAG_NO_SHUFFLE_C; @@ -1510,10 +1553,10 @@ duk_int_t tmp; /* allow caller to give a const number with the DUK__CONST_MARKER */ - DUK_ASSERT(bc != -1); /* Not 'none'. */ + DUK_ASSERT(bc != -1); /* Not 'none'. */ bc = bc & (~DUK__CONST_MARKER); - DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT((op_flags & 0xff) <= DUK_BC_OP_MAX); DUK_ASSERT(bc >= DUK_BC_BC_MIN); DUK_ASSERT(bc <= DUK_BC_BC_MAX); @@ -1558,7 +1601,7 @@ } return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -1573,12 +1616,12 @@ DUK_LOCAL void duk__emit_abc(duk_compiler_ctx *comp_ctx, duk_small_uint_t op, duk_regconst_t abc) { duk_instr_t ins; - DUK_ASSERT_DISABLE(op >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE(op >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT(op <= DUK_BC_OP_MAX); - DUK_ASSERT_DISABLE(abc >= DUK_BC_ABC_MIN); /* unsigned */ + DUK_ASSERT_DISABLE(abc >= DUK_BC_ABC_MIN); /* unsigned */ DUK_ASSERT(abc <= DUK_BC_ABC_MAX); DUK_ASSERT((abc & DUK__CONST_MARKER) == 0); - DUK_ASSERT(abc != -1); /* Not 'none'. */ + DUK_ASSERT(abc != -1); /* Not 'none'. */ if (abc <= DUK_BC_ABC_MAX) { ; @@ -1587,18 +1630,25 @@ } ins = DUK_ENC_OP_ABC(op, abc); DUK_DDD(DUK_DDDPRINT("duk__emit_abc: 0x%08lx line=%ld pc=%ld op=%ld (%!X) abc=%ld (%!I)", - (unsigned long) ins, (long) comp_ctx->curr_token.start_line, - (long) duk__get_current_pc(comp_ctx), (long) op, (long) op, - (long) abc, (duk_instr_t) ins)); + (unsigned long) ins, + (long) comp_ctx->curr_token.start_line, + (long) duk__get_current_pc(comp_ctx), + (long) op, + (long) op, + (long) abc, + (duk_instr_t) ins)); duk__emit(comp_ctx, ins); return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } -DUK_LOCAL void duk__emit_load_int32_raw(duk_compiler_ctx *comp_ctx, duk_regconst_t reg, duk_int32_t val, duk_small_uint_t op_flags) { +DUK_LOCAL void duk__emit_load_int32_raw(duk_compiler_ctx *comp_ctx, + duk_regconst_t reg, + duk_int32_t val, + duk_small_uint_t op_flags) { /* XXX: Shuffling support could be implemented here so that LDINT+LDINTX * would only shuffle once (instead of twice). The current code works * though, and has a smaller compiler footprint. @@ -1613,7 +1663,10 @@ duk_int32_t lo = val & ((((duk_int32_t) 1) << DUK_BC_LDINTX_SHIFT) - 1); DUK_ASSERT(lo >= 0); DUK_DDD(DUK_DDDPRINT("emit LDINT+LDINTX to reg %ld for %ld -> hi %ld, lo %ld", - (long) reg, (long) val, (long) hi, (long) lo)); + (long) reg, + (long) val, + (long) hi, + (long) lo)); duk__emit_a_bc(comp_ctx, DUK_OP_LDINT | op_flags, reg, (duk_regconst_t) (hi + (duk_int32_t) DUK_BC_LDINT_BIAS)); duk__emit_a_bc(comp_ctx, DUK_OP_LDINTX | op_flags, reg, (duk_regconst_t) lo); } @@ -1654,7 +1707,7 @@ DUK_LOCAL duk_int_t duk__emit_jump_empty(duk_compiler_ctx *comp_ctx) { duk_int_t ret; - ret = duk__get_current_pc(comp_ctx); /* useful for patching jumps later */ + ret = duk__get_current_pc(comp_ctx); /* useful for patching jumps later */ duk__emit_op_only(comp_ctx, DUK_OP_JUMP); return ret; } @@ -1672,13 +1725,10 @@ DUK_ASSERT(jump_pc >= 0); offset = (duk_size_t) jump_pc * sizeof(duk_compiler_instr); instr = (duk_compiler_instr *) (void *) - DUK_BW_INSERT_ENSURE_AREA(comp_ctx->thr, - &comp_ctx->curr_func.bw_code, - offset, - sizeof(duk_compiler_instr)); + DUK_BW_INSERT_ENSURE_AREA(comp_ctx->thr, &comp_ctx->curr_func.bw_code, offset, sizeof(duk_compiler_instr)); #if defined(DUK_USE_PC2LINE) - line = comp_ctx->curr_token.start_line; /* approximation, close enough */ + line = comp_ctx->curr_token.start_line; /* approximation, close enough */ #endif instr->ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, 0); #if defined(DUK_USE_PC2LINE) @@ -1691,7 +1741,7 @@ } return; - fail_bc_limit: +fail_bc_limit: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_BYTECODE_LIMIT); DUK_WO_NORETURN(return;); } @@ -1705,8 +1755,8 @@ /* allow negative PCs, behave as a no-op */ if (jump_pc < 0) { - DUK_DDD(DUK_DDDPRINT("duk__patch_jump(): nop call, jump_pc=%ld (<0), target_pc=%ld", - (long) jump_pc, (long) target_pc)); + DUK_DDD( + DUK_DDDPRINT("duk__patch_jump(): nop call, jump_pc=%ld (<0), target_pc=%ld", (long) jump_pc, (long) target_pc)); return; } DUK_ASSERT(jump_pc >= 0); @@ -1720,14 +1770,21 @@ instr->ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, offset + DUK_BC_JUMP_BIAS); DUK_DDD(DUK_DDDPRINT("duk__patch_jump(): jump_pc=%ld, target_pc=%ld, offset=%ld", - (long) jump_pc, (long) target_pc, (long) offset)); + (long) jump_pc, + (long) target_pc, + (long) offset)); } DUK_LOCAL void duk__patch_jump_here(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc) { duk__patch_jump(comp_ctx, jump_pc, duk__get_current_pc(comp_ctx)); } -DUK_LOCAL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, duk_int_t ldconst_pc, duk_int_t trycatch_pc, duk_regconst_t reg_catch, duk_regconst_t const_varname, duk_small_uint_t flags) { +DUK_LOCAL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, + duk_int_t ldconst_pc, + duk_int_t trycatch_pc, + duk_regconst_t reg_catch, + duk_regconst_t const_varname, + duk_small_uint_t flags) { duk_compiler_instr *instr; DUK_ASSERT(DUK__ISREG(reg_catch)); @@ -1747,7 +1804,10 @@ * See: test-bug-trycatch-many-constants.js. */ DUK_D(DUK_DPRINT("failed to patch trycatch: flags=%ld, reg_catch=%ld, const_varname=%ld (0x%08lx)", - (long) flags, (long) reg_catch, (long) const_varname, (long) const_varname)); + (long) flags, + (long) reg_catch, + (long) const_varname, + (long) const_varname)); DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -1770,14 +1830,14 @@ duk_small_uint_t op; op = DUK__ISREG(regconst) ? DUK_OP_IFFALSE_R : DUK_OP_IFFALSE_C; - duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ + duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ } DUK_LOCAL void duk__emit_if_true_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst) { duk_small_uint_t op; op = DUK__ISREG(regconst) ? DUK_OP_IFTRUE_R : DUK_OP_IFTRUE_C; - duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ + duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ } DUK_LOCAL void duk__emit_invalid(duk_compiler_ctx *comp_ctx) { @@ -1801,7 +1861,8 @@ #if defined(DUK_USE_BUFLEN16) /* No need to assert, buffer size maximum is 0xffff. */ #else - DUK_ASSERT((duk_size_t) DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr) <= (duk_size_t) DUK_INT_MAX); /* bytecode limits */ + DUK_ASSERT((duk_size_t) DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr) <= + (duk_size_t) DUK_INT_MAX); /* bytecode limits */ #endif n = (duk_int_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr)); @@ -1836,7 +1897,9 @@ target_pc2 = target_pc1 + 1 + (duk_int_t) DUK_DEC_ABC(ins) - (duk_int_t) DUK_BC_JUMP_BIAS; DUK_DDD(DUK_DDDPRINT("optimizing jump at pc %ld; old target is %ld -> new target is %ld", - (long) i, (long) target_pc1, (long) target_pc2)); + (long) i, + (long) target_pc1, + (long) target_pc2)); bci.ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, target_pc2 - (i + 1) + DUK_BC_JUMP_BIAS); @@ -1862,15 +1925,21 @@ /* XXX: DUK__IVAL_FLAG_REQUIRE_SHORT is passed but not currently implemented * by ispec/ivalue operations. */ -#define DUK__IVAL_FLAG_ALLOW_CONST (1 << 0) /* allow a constant to be returned */ -#define DUK__IVAL_FLAG_REQUIRE_TEMP (1 << 1) /* require a (mutable) temporary as a result (or a const if allowed) */ -#define DUK__IVAL_FLAG_REQUIRE_SHORT (1 << 2) /* require a short (8-bit) reg/const which fits into bytecode B/C slot */ +#define DUK__IVAL_FLAG_ALLOW_CONST (1 << 0) /* allow a constant to be returned */ +#define DUK__IVAL_FLAG_REQUIRE_TEMP (1 << 1) /* require a (mutable) temporary as a result (or a const if allowed) */ +#define DUK__IVAL_FLAG_REQUIRE_SHORT (1 << 2) /* require a short (8-bit) reg/const which fits into bytecode B/C slot */ /* XXX: some code might benefit from DUK__SETTEMP_IFTEMP(thr,x) */ -#if 0 /* enable manually for dumping */ -#define DUK__DUMP_ISPEC(compctx,ispec) do { duk__dump_ispec((compctx), (ispec)); } while (0) -#define DUK__DUMP_IVALUE(compctx,ivalue) do { duk__dump_ivalue((compctx), (ivalue)); } while (0) +#if 0 /* enable manually for dumping */ +#define DUK__DUMP_ISPEC(compctx, ispec) \ + do { \ + duk__dump_ispec((compctx), (ispec)); \ + } while (0) +#define DUK__DUMP_IVALUE(compctx, ivalue) \ + do { \ + duk__dump_ivalue((compctx), (ivalue)); \ + } while (0) DUK_LOCAL void duk__dump_ispec(duk_compiler_ctx *comp_ctx, duk_ispec *x) { DUK_D(DUK_DPRINT("ispec dump: t=%ld regconst=0x%08lx, valstack_idx=%ld, value=%!T", @@ -1888,8 +1957,12 @@ duk_get_tval(comp_ctx->thr, x->x2.valstack_idx))); } #else -#define DUK__DUMP_ISPEC(comp_ctx,x) do {} while (0) -#define DUK__DUMP_IVALUE(comp_ctx,x) do {} while (0) +#define DUK__DUMP_ISPEC(comp_ctx, x) \ + do { \ + } while (0) +#define DUK__DUMP_IVALUE(comp_ctx, x) \ + do { \ + } while (0) #endif DUK_LOCAL void duk__ivalue_regconst(duk_ivalue *x, duk_regconst_t regconst) { @@ -1939,7 +2012,7 @@ res = comp_ctx->curr_func.temp_next; comp_ctx->curr_func.temp_next += num; - if (comp_ctx->curr_func.temp_next > DUK__MAX_TEMPS) { /* == DUK__MAX_TEMPS is OK */ + if (comp_ctx->curr_func.temp_next > DUK__MAX_TEMPS) { /* == DUK__MAX_TEMPS is OK */ DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_TEMP_LIMIT); DUK_WO_NORETURN(return 0;); } @@ -1992,8 +2065,7 @@ * constant for e.g. +0 and -0. */ if (duk_js_samevalue(tv1, tv2)) { - DUK_DDD(DUK_DDDPRINT("reused existing constant for %!T -> const index %ld", - (duk_tval *) tv1, (long) i)); + DUK_DDD(DUK_DDDPRINT("reused existing constant for %!T -> const index %ld", (duk_tval *) tv1, (long) i)); duk_pop(thr); return (duk_regconst_t) i | (duk_regconst_t) DUK__CONST_MARKER; } @@ -2004,9 +2076,8 @@ DUK_WO_NORETURN(return 0;); } - DUK_DDD(DUK_DDDPRINT("allocating new constant for %!T -> const index %ld", - (duk_tval *) tv1, (long) n)); - (void) duk_put_prop_index(thr, f->consts_idx, (duk_uarridx_t) n); /* invalidates tv1, tv2 */ + DUK_DDD(DUK_DDDPRINT("allocating new constant for %!T -> const index %ld", (duk_tval *) tv1, (long) n)); + (void) duk_put_prop_index(thr, f->consts_idx, (duk_uarridx_t) n); /* invalidates tv1, tv2 */ return (duk_regconst_t) n | (duk_regconst_t) DUK__CONST_MARKER; } @@ -2015,15 +2086,15 @@ duk_compiler_func *f = &comp_ctx->curr_func; duk_bool_t ret; - DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ + DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ (void) duk_get_prop_index(comp_ctx->thr, f->consts_idx, (duk_uarridx_t) rc); - ret = !duk_is_number(comp_ctx->thr, -1); /* now only number/string, so conservative check */ + ret = !duk_is_number(comp_ctx->thr, -1); /* now only number/string, so conservative check */ duk_pop(comp_ctx->thr); return ret; #else DUK_UNREF(comp_ctx); DUK_UNREF(rc); - DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ + DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ return 0; #endif } @@ -2086,9 +2157,7 @@ } case DUK_TAG_BOOLEAN: { duk_regconst_t dest = (forced_reg >= 0 ? forced_reg : DUK__ALLOCTEMP(comp_ctx)); - duk__emit_bc(comp_ctx, - (DUK_TVAL_GET_BOOLEAN(tv) ? DUK_OP_LDTRUE : DUK_OP_LDFALSE), - dest); + duk__emit_bc(comp_ctx, (DUK_TVAL_GET_BOOLEAN(tv) ? DUK_OP_LDTRUE : DUK_OP_LDFALSE), dest); return dest; } case DUK_TAG_POINTER: { @@ -2104,7 +2173,7 @@ DUK_UNREF(h); DUK_ASSERT(h != NULL); -#if 0 /* XXX: to be implemented? */ +#if 0 /* XXX: to be implemented? */ /* Use special opcodes to load short strings */ if (DUK_HSTRING_GET_BYTELEN(h) <= 2) { /* Encode into a single opcode (18 bits can encode 1-2 bytes + length indicator) */ @@ -2174,8 +2243,8 @@ return dest; } } - } /* end switch */ - goto fail_internal; /* never here */ + } /* end switch */ + goto fail_internal; /* never here */ } case DUK_ISPEC_REGCONST: { if (forced_reg >= 0) { @@ -2208,11 +2277,11 @@ return x->regconst; } default: { - break; /* never here */ + break; /* never here */ } } - fail_internal: +fail_internal: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); } @@ -2232,10 +2301,13 @@ DUK_DDD(DUK_DDDPRINT("duk__ivalue_toplain_raw(): x={t=%ld,op=%ld,x1={%ld:%ld:%!T},x2={%ld:%ld:%!T}}, " "forced_reg=%ld", - (long) x->t, (long) x->op, - (long) x->x1.t, (long) x->x1.regconst, + (long) x->t, + (long) x->op, + (long) x->x1.t, + (long) x->x1.regconst, (duk_tval *) duk_get_tval(thr, x->x1.valstack_idx), - (long) x->x2.t, (long) x->x2.regconst, + (long) x->x2.t, + (long) x->x2.regconst, (duk_tval *) duk_get_tval(thr, x->x2.valstack_idx), (long) forced_reg)); @@ -2261,9 +2333,7 @@ DUK_ASSERT(tv1 != NULL); DUK_ASSERT(tv2 != NULL); - DUK_DDD(DUK_DDDPRINT("arith: tv1=%!T, tv2=%!T", - (duk_tval *) tv1, - (duk_tval *) tv2)); + DUK_DDD(DUK_DDDPRINT("arith: tv1=%!T, tv2=%!T", (duk_tval *) tv1, (duk_tval *) tv2)); if (DUK_TVAL_IS_NUMBER(tv1) && DUK_TVAL_IS_NUMBER(tv2)) { duk_double_t d1 = DUK_TVAL_GET_NUMBER(tv1); @@ -2272,7 +2342,9 @@ duk_bool_t accept_fold = 1; DUK_DDD(DUK_DDDPRINT("arith inline check: d1=%lf, d2=%lf, op=%ld", - (double) d1, (double) d2, (long) x->op)); + (double) d1, + (double) d2, + (long) x->op)); switch (x->op) { case DUK_OP_ADD: { d3 = d1 + d2; @@ -2298,7 +2370,7 @@ break; } default: { - d3 = 0.0; /* Won't be used, but silence MSVC /W4 warning. */ + d3 = 0.0; /* Won't be used, but silence MSVC /W4 warning. */ accept_fold = 0; break; } @@ -2312,7 +2384,7 @@ x->t = DUK_IVAL_PLAIN; DUK_ASSERT(x->x1.t == DUK_ISPEC_VALUE); - DUK_TVAL_SET_NUMBER(tv1, d3); /* old value is number: no refcount */ + DUK_TVAL_SET_NUMBER(tv1, d3); /* old value is number: no refcount */ return; } } else if (x->op == DUK_OP_ADD && DUK_TVAL_IS_STRING(tv1) && DUK_TVAL_IS_STRING(tv2)) { @@ -2329,8 +2401,14 @@ } } - arg1 = duk__ispec_toregconst_raw(comp_ctx, &x->x1, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); - arg2 = duk__ispec_toregconst_raw(comp_ctx, &x->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg1 = duk__ispec_toregconst_raw(comp_ctx, + &x->x1, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg2 = duk__ispec_toregconst_raw(comp_ctx, + &x->x2, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); /* If forced reg, use it as destination. Otherwise try to * use either coerced ispec if it is a temporary. @@ -2358,8 +2436,14 @@ duk_regconst_t dest; /* Need a short reg/const, does not have to be a mutable temp. */ - arg1 = duk__ispec_toregconst_raw(comp_ctx, &x->x1, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); - arg2 = duk__ispec_toregconst_raw(comp_ctx, &x->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg1 = duk__ispec_toregconst_raw(comp_ctx, + &x->x1, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg2 = duk__ispec_toregconst_raw(comp_ctx, + &x->x2, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); /* Pick a destination register. If either base value or key * happens to be a temp value, reuse it as the destination. @@ -2380,11 +2464,7 @@ dest = DUK__ALLOCTEMP(comp_ctx); } - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, - dest, - arg1, - arg2); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, dest, arg1, arg2); duk__ivalue_regconst(x, dest); return; @@ -2452,10 +2532,13 @@ DUK_DDD(DUK_DDDPRINT("duk__ivalue_toregconst_raw(): x={t=%ld,op=%ld,x1={%ld:%ld:%!T},x2={%ld:%ld:%!T}}, " "forced_reg=%ld, flags 0x%08lx: allow_const=%ld require_temp=%ld require_short=%ld", - (long) x->t, (long) x->op, - (long) x->x1.t, (long) x->x1.regconst, + (long) x->t, + (long) x->op, + (long) x->x1.t, + (long) x->x1.regconst, (duk_tval *) duk_get_tval(thr, x->x1.valstack_idx), - (long) x->x2.t, (long) x->x2.regconst, + (long) x->x2.t, + (long) x->x2.regconst, (duk_tval *) duk_get_tval(thr, x->x2.valstack_idx), (long) forced_reg, (unsigned long) flags, @@ -2478,7 +2561,7 @@ return duk__ivalue_toregconst_raw(comp_ctx, x, -1, 0 /*flags*/); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__ivalue_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *x) { return duk__ivalue_toregconst_raw(comp_ctx, x, -1, DUK__IVAL_FLAG_REQUIRE_TEMP /*flags*/); } @@ -2514,8 +2597,7 @@ duk_hstring *h_varname; duk_regconst_t ret; - DUK_DDD(DUK_DDDPRINT("resolving identifier reference to '%!T'", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("resolving identifier reference to '%!T'", (duk_tval *) duk_get_tval(thr, -1))); /* * Special name handling @@ -2568,13 +2650,13 @@ DUK_DDD(DUK_DDDPRINT("identifier lookup -> reg %ld", (long) ret)); return ret; - slow_path_notown: +slow_path_notown: DUK_DDD(DUK_DDDPRINT("identifier lookup -> slow path, not own variable")); comp_ctx->curr_func.id_access_slow = 1; return (duk_regconst_t) -1; - slow_path_own: +slow_path_own: DUK_DDD(DUK_DDDPRINT("identifier lookup -> slow path, may be own variable")); comp_ctx->curr_func.id_access_slow = 1; @@ -2602,7 +2684,7 @@ if (reg_varbind >= 0) { *out_reg_varbind = reg_varbind; - *out_rc_varname = 0; /* duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller) */ + *out_rc_varname = 0; /* duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller) */ duk_pop(thr); return 1; } else { @@ -2652,7 +2734,7 @@ } duk_push_hstring(thr, h_label); - DUK_ASSERT(n <= DUK_UARRIDX_MAX); /* label limits */ + DUK_ASSERT(n <= DUK_UARRIDX_MAX); /* label limits */ (void) duk_put_prop_index(thr, comp_ctx->curr_func.labelnames_idx, (duk_uarridx_t) n); new_size = (n + 1) * sizeof(duk_labelinfo); @@ -2662,7 +2744,7 @@ /* relookup after possible realloc */ p = (duk_uint8_t *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, comp_ctx->curr_func.h_labelinfos); li_start = (duk_labelinfo *) (void *) p; - DUK_UNREF(li_start); /* silence scan-build warning */ + DUK_UNREF(li_start); /* silence scan-build warning */ li = (duk_labelinfo *) (void *) (p + DUK_HBUFFER_GET_SIZE(comp_ctx->curr_func.h_labelinfos)); li--; @@ -2676,12 +2758,15 @@ li->flags = DUK_LABEL_FLAG_ALLOW_BREAK; li->label_id = label_id; li->h_label = h_label; - li->catch_depth = comp_ctx->curr_func.catch_depth; /* catch depth from current func */ + li->catch_depth = comp_ctx->curr_func.catch_depth; /* catch depth from current func */ li->pc_label = pc_label; DUK_DDD(DUK_DDDPRINT("registered label: flags=0x%08lx, id=%ld, name=%!O, catch_depth=%ld, pc_label=%ld", - (unsigned long) li->flags, (long) li->label_id, (duk_heaphdr *) li->h_label, - (long) li->catch_depth, (long) li->pc_label)); + (unsigned long) li->flags, + (long) li->label_id, + (duk_heaphdr *) li->h_label, + (long) li->catch_depth, + (long) li->pc_label)); } /* Update all labels with matching label_id. */ @@ -2705,7 +2790,9 @@ } DUK_DDD(DUK_DDDPRINT("updating (overwriting) label flags for li=%p, label_id=%ld, flags=%ld", - (void *) li, (long) label_id, (long) flags)); + (void *) li, + (long) label_id, + (long) flags)); li->flags = flags; } @@ -2726,14 +2813,19 @@ */ /* XXX: awkward, especially the bunch of separate output values -> output struct? */ -DUK_LOCAL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_bool_t is_break, duk_int_t *out_label_id, duk_int_t *out_label_catch_depth, duk_int_t *out_label_pc, duk_bool_t *out_is_closest) { +DUK_LOCAL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, + duk_hstring *h_label, + duk_bool_t is_break, + duk_int_t *out_label_id, + duk_int_t *out_label_catch_depth, + duk_int_t *out_label_pc, + duk_bool_t *out_is_closest) { duk_hthread *thr = comp_ctx->thr; duk_uint8_t *p; duk_labelinfo *li_start, *li_end, *li; duk_bool_t match = 0; - DUK_DDD(DUK_DDDPRINT("looking up active label: label='%!O', is_break=%ld", - (duk_heaphdr *) h_label, (long) is_break)); + DUK_DDD(DUK_DDDPRINT("looking up active label: label='%!O', is_break=%ld", (duk_heaphdr *) h_label, (long) is_break)); DUK_UNREF(thr); @@ -2757,7 +2849,8 @@ } DUK_DDD(DUK_DDDPRINT("labelinfo%ld -> '%!O' label name matches (still need to check type)", - (long) (li - li_start), (duk_heaphdr *) h_label)); + (long) (li - li_start), + (duk_heaphdr *) h_label)); /* currently all labels accept a break, so no explicit check for it now */ DUK_ASSERT(li->flags & DUK_LABEL_FLAG_ALLOW_BREAK); @@ -2791,8 +2884,10 @@ } DUK_DDD(DUK_DDDPRINT("label match: %!O -> label_id %ld, catch_depth=%ld, pc_label=%ld", - (duk_heaphdr *) h_label, (long) li->label_id, - (long) li->catch_depth, (long) li->pc_label)); + (duk_heaphdr *) h_label, + (long) li->label_id, + (long) li->catch_depth, + (long) li->pc_label)); *out_label_id = li->label_id; *out_label_catch_depth = li->catch_depth; @@ -2816,21 +2911,21 @@ */ /* object literal key tracking flags */ -#define DUK__OBJ_LIT_KEY_PLAIN (1 << 0) /* key encountered as a plain property */ -#define DUK__OBJ_LIT_KEY_GET (1 << 1) /* key encountered as a getter */ -#define DUK__OBJ_LIT_KEY_SET (1 << 2) /* key encountered as a setter */ +#define DUK__OBJ_LIT_KEY_PLAIN (1 << 0) /* key encountered as a plain property */ +#define DUK__OBJ_LIT_KEY_GET (1 << 1) /* key encountered as a getter */ +#define DUK__OBJ_LIT_KEY_SET (1 << 2) /* key encountered as a setter */ DUK_LOCAL void duk__nud_array_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; - duk_regconst_t reg_obj; /* result reg */ - duk_regconst_t reg_temp; /* temp reg */ - duk_regconst_t temp_start; /* temp reg value for start of loop */ - duk_small_uint_t max_init_values; /* max # of values initialized in one MPUTARR set */ - duk_small_uint_t num_values; /* number of values in current MPUTARR set */ - duk_uarridx_t curr_idx; /* current (next) array index */ - duk_uarridx_t start_idx; /* start array index of current MPUTARR set */ - duk_uarridx_t init_idx; /* last array index explicitly initialized, +1 */ - duk_bool_t require_comma; /* next loop requires a comma */ + duk_regconst_t reg_obj; /* result reg */ + duk_regconst_t reg_temp; /* temp reg */ + duk_regconst_t temp_start; /* temp reg value for start of loop */ + duk_small_uint_t max_init_values; /* max # of values initialized in one MPUTARR set */ + duk_small_uint_t num_values; /* number of values in current MPUTARR set */ + duk_uarridx_t curr_idx; /* current (next) array index */ + duk_uarridx_t start_idx; /* start array index of current MPUTARR set */ + duk_uarridx_t init_idx; /* last array index explicitly initialized, +1 */ + duk_bool_t require_comma; /* next loop requires a comma */ #if !defined(DUK_USE_PREFER_SIZE) duk_int_t pc_newarr; duk_compiler_instr *instr; @@ -2839,13 +2934,13 @@ /* DUK_TOK_LBRACKET already eaten, current token is right after that */ DUK_ASSERT(comp_ctx->prev_token.t == DUK_TOK_LBRACKET); - max_init_values = DUK__MAX_ARRAY_INIT_VALUES; /* XXX: depend on available temps? */ + max_init_values = DUK__MAX_ARRAY_INIT_VALUES; /* XXX: depend on available temps? */ reg_obj = DUK__ALLOCTEMP(comp_ctx); #if !defined(DUK_USE_PREFER_SIZE) pc_newarr = duk__get_current_pc(comp_ctx); #endif - duk__emit_bc(comp_ctx, DUK_OP_NEWARR, reg_obj); /* XXX: patch initial size hint afterwards? */ + duk__emit_bc(comp_ctx, DUK_OP_NEWARR, reg_obj); /* XXX: patch initial size hint afterwards? */ temp_start = DUK__GETTEMP(comp_ctx); /* @@ -2861,7 +2956,7 @@ */ curr_idx = 0; - init_idx = 0; /* tracks maximum initialized index + 1 */ + init_idx = 0; /* tracks maximum initialized index + 1 */ start_idx = 0; require_comma = 0; @@ -2907,7 +3002,7 @@ duk__emit_load_int32(comp_ctx, reg_temp, (duk_int32_t) start_idx); } - reg_temp = DUK__ALLOCTEMP(comp_ctx); /* alloc temp just in case, to update max temp */ + reg_temp = DUK__ALLOCTEMP(comp_ctx); /* alloc temp just in case, to update max temp */ DUK__SETTEMP(comp_ctx, reg_temp); duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); DUK__SETTEMP(comp_ctx, reg_temp + 1); @@ -2932,9 +3027,7 @@ * never needs to be. */ duk__emit_a_b_c(comp_ctx, - DUK_OP_MPUTARR | - DUK__EMIT_FLAG_NO_SHUFFLE_C | - DUK__EMIT_FLAG_A_IS_SOURCE, + DUK_OP_MPUTARR | DUK__EMIT_FLAG_NO_SHUFFLE_C | DUK__EMIT_FLAG_A_IS_SOURCE, reg_obj, temp_start, (duk_regconst_t) (num_values + 1)); @@ -2955,8 +3048,7 @@ DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RBRACKET); duk__advance(comp_ctx); - DUK_DDD(DUK_DDDPRINT("array literal done, curridx=%ld, initidx=%ld", - (long) curr_idx, (long) init_idx)); + DUK_DDD(DUK_DDDPRINT("array literal done, curridx=%ld, initidx=%ld", (long) curr_idx, (long) init_idx)); /* trailing elisions? */ if (curr_idx > init_idx) { @@ -2964,10 +3056,7 @@ DUK_DDD(DUK_DDDPRINT("array literal has trailing elisions which affect its length")); reg_temp = DUK__ALLOCTEMP(comp_ctx); duk__emit_load_int32(comp_ctx, reg_temp, (duk_int_t) curr_idx); - duk__emit_a_bc(comp_ctx, - DUK_OP_SETALEN | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_obj, - reg_temp); + duk__emit_a_bc(comp_ctx, DUK_OP_SETALEN | DUK__EMIT_FLAG_A_IS_SOURCE, reg_obj, reg_temp); } DUK__SETTEMP(comp_ctx, temp_start); @@ -2975,7 +3064,7 @@ duk__ivalue_regconst(res, reg_obj); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_ARRAY_LITERAL); DUK_WO_NORETURN(return;); } @@ -2999,9 +3088,7 @@ */ DUK_ASSERT(st->num_pairs > 0); duk__emit_a_b_c(comp_ctx, - DUK_OP_MPUTOBJ | - DUK__EMIT_FLAG_NO_SHUFFLE_C | - DUK__EMIT_FLAG_A_IS_SOURCE, + DUK_OP_MPUTOBJ | DUK__EMIT_FLAG_NO_SHUFFLE_C | DUK__EMIT_FLAG_A_IS_SOURCE, st->reg_obj, st->temp_start, (duk_regconst_t) (st->num_pairs * 2)); @@ -3020,7 +3107,7 @@ /* numbers can be loaded as numbers and coerced on the fly */ duk_push_number(comp_ctx->thr, tok->num); } else { - return 1; /* error */ + return 1; /* error */ } duk__ivalue_plain_fromstack(comp_ctx, res); @@ -3033,10 +3120,10 @@ DUK_LOCAL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; duk__objlit_state st; - duk_regconst_t reg_temp; /* temp reg */ - duk_small_uint_t max_init_pairs; /* max # of key-value pairs initialized in one MPUTOBJ set */ - duk_bool_t first; /* first value: comma must not precede the value */ - duk_bool_t is_set, is_get; /* temps */ + duk_regconst_t reg_temp; /* temp reg */ + duk_small_uint_t max_init_pairs; /* max # of key-value pairs initialized in one MPUTOBJ set */ + duk_bool_t first; /* first value: comma must not precede the value */ + duk_bool_t is_set, is_get; /* temps */ #if !defined(DUK_USE_PREFER_SIZE) duk_int_t pc_newobj; duk_compiler_instr *instr; @@ -3044,12 +3131,12 @@ DUK_ASSERT(comp_ctx->prev_token.t == DUK_TOK_LCURLY); - max_init_pairs = DUK__MAX_OBJECT_INIT_PAIRS; /* XXX: depend on available temps? */ + max_init_pairs = DUK__MAX_OBJECT_INIT_PAIRS; /* XXX: depend on available temps? */ - st.reg_obj = DUK__ALLOCTEMP(comp_ctx); /* target object */ - st.temp_start = DUK__GETTEMP(comp_ctx); /* start of MPUTOBJ argument list */ - st.num_pairs = 0; /* number of key/value pairs emitted for current MPUTOBJ set */ - st.num_total_pairs = 0; /* number of key/value pairs emitted overall */ + st.reg_obj = DUK__ALLOCTEMP(comp_ctx); /* target object */ + st.temp_start = DUK__GETTEMP(comp_ctx); /* start of MPUTOBJ argument list */ + st.num_pairs = 0; /* number of key/value pairs emitted for current MPUTOBJ set */ + st.num_total_pairs = 0; /* number of key/value pairs emitted overall */ #if !defined(DUK_USE_PREFER_SIZE) pc_newobj = duk__get_current_pc(comp_ctx); @@ -3088,8 +3175,7 @@ * worth the effort and would increase code size. */ - DUK_DDD(DUK_DDDPRINT("object literal loop, curr_token->t = %ld", - (long) comp_ctx->curr_token.t)); + DUK_DDD(DUK_DDDPRINT("object literal loop, curr_token->t = %ld", (long) comp_ctx->curr_token.t)); if (comp_ctx->curr_token.t == DUK_TOK_RCURLY) { break; @@ -3129,16 +3215,15 @@ * identifier string content. */ - is_get = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_GET(thr)); - is_set = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_SET(thr)); + is_get = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_GET(thr)); + is_set = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_SET(thr)); if ((is_get || is_set) && comp_ctx->curr_token.t != DUK_TOK_COLON) { /* getter/setter */ duk_int_t fnum; duk__objlit_flush_keys(comp_ctx, &st); - DUK_ASSERT(DUK__GETTEMP(comp_ctx) == st.temp_start); /* 2 regs are guaranteed to be allocated w.r.t. temp_max */ + DUK_ASSERT(DUK__GETTEMP(comp_ctx) == + st.temp_start); /* 2 regs are guaranteed to be allocated w.r.t. temp_max */ reg_temp = DUK__ALLOCTEMPS(comp_ctx, 2); if (duk__objlit_load_key(comp_ctx, res, &comp_ctx->curr_token, reg_temp) != 0) { @@ -3148,21 +3233,18 @@ /* curr_token = get/set name */ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_GETSET); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - st.temp_start + 1, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, st.temp_start + 1, (duk_regconst_t) fnum); /* Slot C is used in a non-standard fashion (range of regs), * emitter code has special handling for it (must not set the * "no shuffle" flag). */ duk__emit_a_bc(comp_ctx, - (is_get ? DUK_OP_INITGET : DUK_OP_INITSET) | DUK__EMIT_FLAG_A_IS_SOURCE, - st.reg_obj, - st.temp_start); /* temp_start+0 = key, temp_start+1 = closure */ + (is_get ? DUK_OP_INITGET : DUK_OP_INITSET) | DUK__EMIT_FLAG_A_IS_SOURCE, + st.reg_obj, + st.temp_start); /* temp_start+0 = key, temp_start+1 = closure */ - DUK_ASSERT(st.num_pairs == 0); /* temp state is reset on next loop */ + DUK_ASSERT(st.num_pairs == 0); /* temp state is reset on next loop */ #if defined(DUK_USE_ES6) } else if (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && (comp_ctx->curr_token.t == DUK_TOK_COMMA || comp_ctx->curr_token.t == DUK_TOK_RCURLY)) { @@ -3170,15 +3252,14 @@ load_rc = duk__objlit_load_key(comp_ctx, res, &comp_ctx->prev_token, reg_temp); DUK_UNREF(load_rc); - DUK_ASSERT(load_rc == 0); /* always succeeds because token is identifier */ + DUK_ASSERT(load_rc == 0); /* always succeeds because token is identifier */ duk__ivalue_var_hstring(comp_ctx, res, comp_ctx->prev_token.str1); DUK_ASSERT(DUK__GETTEMP(comp_ctx) == reg_temp + 1); duk__ivalue_toforcedreg(comp_ctx, res, reg_temp + 1); st.num_pairs++; - } else if ((comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER || - comp_ctx->prev_token.t == DUK_TOK_STRING || + } else if ((comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER || comp_ctx->prev_token.t == DUK_TOK_STRING || comp_ctx->prev_token.t == DUK_TOK_NUMBER) && comp_ctx->curr_token.t == DUK_TOK_LPAREN) { duk_int_t fnum; @@ -3196,13 +3277,10 @@ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_USE_PREVTOKEN | DUK__FUNC_FLAG_METDEF); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp + 1, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp + 1, (duk_regconst_t) fnum); st.num_pairs++; -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ } else { #if defined(DUK_USE_ES6) if (comp_ctx->prev_token.t == DUK_TOK_LBRACKET) { @@ -3219,9 +3297,8 @@ * form is not yet supported and causes a * SyntaxError on the DUK_TOK_COLON check below. */ - } - else -#endif /* DUK_USE_ES6 */ + } else +#endif /* DUK_USE_ES6 */ { if (duk__objlit_load_key(comp_ctx, res, &comp_ctx->prev_token, reg_temp) != 0) { goto syntax_error; @@ -3235,7 +3312,7 @@ st.num_pairs++; } - } /* property loop */ + } /* property loop */ /* Flush remaining properties. */ duk__objlit_flush_keys(comp_ctx, &st); @@ -3254,12 +3331,12 @@ #endif DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RCURLY); - duk__advance(comp_ctx); /* No RegExp after object literal. */ + duk__advance(comp_ctx); /* No RegExp after object literal. */ duk__ivalue_regconst(res, st.reg_obj); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_OBJECT_LITERAL); DUK_WO_NORETURN(return;); } @@ -3275,7 +3352,8 @@ /* Note: expect that caller has already eaten the left paren */ DUK_DDD(DUK_DDDPRINT("start parsing arguments, prev_token.t=%ld, curr_token.t=%ld", - (long) comp_ctx->prev_token.t, (long) comp_ctx->curr_token.t)); + (long) comp_ctx->prev_token.t, + (long) comp_ctx->curr_token.t)); for (;;) { if (comp_ctx->curr_token.t == DUK_TOK_RPAREN) { @@ -3292,11 +3370,14 @@ * This is not the cleanest possible approach. */ - reg_temp = DUK__ALLOCTEMP(comp_ctx); /* bump up "allocated" reg count, just in case */ + reg_temp = DUK__ALLOCTEMP(comp_ctx); /* bump up "allocated" reg count, just in case */ DUK__SETTEMP(comp_ctx, reg_temp); /* binding power must be high enough to NOT allow comma expressions directly */ - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp); /* always allow 'in', coerce to 'tr' just in case */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp); /* always allow 'in', coerce to 'tr' just in case */ DUK__SETTEMP(comp_ctx, reg_temp + 1); nargs++; @@ -3305,7 +3386,7 @@ } /* eat the right paren */ - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ DUK_DDD(DUK_DDDPRINT("end parsing arguments")); @@ -3314,8 +3395,7 @@ DUK_LOCAL duk_bool_t duk__expr_is_empty(duk_compiler_ctx *comp_ctx) { /* empty expressions can be detected conveniently with nud/led counts */ - return (comp_ctx->curr_func.nud_count == 0) && - (comp_ctx->curr_func.led_count == 0); + return (comp_ctx->curr_func.nud_count == 0) && (comp_ctx->curr_func.led_count == 0); } DUK_LOCAL void duk__expr_nud(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { @@ -3323,7 +3403,7 @@ duk_token *tk; duk_regconst_t temp_at_entry; duk_small_uint_t tok; - duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ + duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ /* * ctx->prev_token token to process with duk__expr_nud() @@ -3341,18 +3421,17 @@ res->t = DUK_IVAL_NONE; DUK_DDD(DUK_DDDPRINT("duk__expr_nud(), prev_token.t=%ld, allow_in=%ld, paren_level=%ld", - (long) tk->t, (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); + (long) tk->t, + (long) comp_ctx->curr_func.allow_in, + (long) comp_ctx->curr_func.paren_level)); switch (tok) { - - /* PRIMARY EXPRESSIONS */ + /* PRIMARY EXPRESSIONS */ case DUK_TOK_THIS: { duk_regconst_t reg_temp; reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_bc(comp_ctx, - DUK_OP_LDTHIS, - reg_temp); + duk__emit_bc(comp_ctx, DUK_OP_LDTHIS, reg_temp); duk__ivalue_regconst(res, reg_temp); return; } @@ -3384,15 +3463,13 @@ case DUK_TOK_REGEXP: { #if defined(DUK_USE_REGEXP_SUPPORT) duk_regconst_t reg_temp; - duk_regconst_t rc_re_bytecode; /* const */ - duk_regconst_t rc_re_source; /* const */ + duk_regconst_t rc_re_bytecode; /* const */ + duk_regconst_t rc_re_source; /* const */ DUK_ASSERT(tk->str1 != NULL); DUK_ASSERT(tk->str2 != NULL); - DUK_DDD(DUK_DDDPRINT("emitting regexp op, str1=%!O, str2=%!O", - (duk_heaphdr *) tk->str1, - (duk_heaphdr *) tk->str2)); + DUK_DDD(DUK_DDDPRINT("emitting regexp op, str1=%!O, str2=%!O", (duk_heaphdr *) tk->str1, (duk_heaphdr *) tk->str2)); reg_temp = DUK__ALLOCTEMP(comp_ctx); duk_push_hstring(thr, tk->str1); @@ -3415,9 +3492,9 @@ duk__ivalue_regconst(res, reg_temp); return; -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ goto syntax_error; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } case DUK_TOK_LBRACKET: { DUK_DDD(DUK_DDDPRINT("parsing array literal")); @@ -3436,15 +3513,15 @@ prev_allow_in = comp_ctx->curr_func.allow_in; comp_ctx->curr_func.allow_in = 1; /* reset 'allow_in' for parenthesized expression */ - duk__expr(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, terminates at a ')' */ + duk__expr(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, terminates at a ')' */ - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* No RegExp after parenthesized expression. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* No RegExp after parenthesized expression. */ comp_ctx->curr_func.allow_in = prev_allow_in; comp_ctx->curr_func.paren_level--; return; } - /* MEMBER/NEW/CALL EXPRESSIONS */ + /* MEMBER/NEW/CALL EXPRESSIONS */ case DUK_TOK_NEW: { /* @@ -3481,16 +3558,14 @@ goto syntax_error_newtarget; } duk__advance(comp_ctx); - duk__emit_bc(comp_ctx, - DUK_OP_NEWTARGET, - reg_target); + duk__emit_bc(comp_ctx, DUK_OP_NEWTARGET, reg_target); duk__ivalue_regconst(res, reg_target); return; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ duk__expr_toforcedreg(comp_ctx, res, DUK__BP_CALL /*rbp_flags*/, reg_target /*forced_reg*/); - duk__emit_bc(comp_ctx, DUK_OP_NEWOBJ, reg_target + 1); /* default instance */ + duk__emit_bc(comp_ctx, DUK_OP_NEWOBJ, reg_target + 1); /* default instance */ DUK__SETTEMP(comp_ctx, reg_target + 2); /* XXX: 'new obj.noSuch()' doesn't use GETPROPC now which @@ -3501,7 +3576,7 @@ /* 'new' MemberExpression Arguments */ DUK_DDD(DUK_DDDPRINT("new expression has argument list")); duk__advance(comp_ctx); - nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp", reg_target + 1 */ + nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp", reg_target + 1 */ /* right paren eaten */ } else { /* 'new' MemberExpression */ @@ -3509,10 +3584,7 @@ nargs = 0; } - duk__emit_a_bc(comp_ctx, - DUK_OP_CALL0 | DUK_BC_CALL_FLAG_CONSTRUCT, - nargs /*num_args*/, - reg_target /*target*/); + duk__emit_a_bc(comp_ctx, DUK_OP_CALL0 | DUK_BC_CALL_FLAG_CONSTRUCT, nargs /*num_args*/, reg_target /*target*/); DUK_DDD(DUK_DDDPRINT("end parsing new expression")); @@ -3520,7 +3592,7 @@ return; } - /* FUNCTION EXPRESSIONS */ + /* FUNCTION EXPRESSIONS */ case DUK_TOK_FUNCTION: { /* Function expression. Note that any statement beginning with 'function' @@ -3543,16 +3615,13 @@ fnum = duk__parse_func_like_fnum(comp_ctx, 0 /*flags*/); DUK_DDD(DUK_DDDPRINT("parsed inner function -> fnum %ld", (long) fnum)); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp /*a*/, - (duk_regconst_t) fnum /*bc*/); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp /*a*/, (duk_regconst_t) fnum /*bc*/); duk__ivalue_regconst(res, reg_temp); return; } - /* UNARY EXPRESSIONS */ + /* UNARY EXPRESSIONS */ case DUK_TOK_DELETE: { /* Delete semantics are a bit tricky. The description in E5 specification @@ -3560,7 +3629,7 @@ * a reference (which is only known at runtime) seemingly at compile time * (= SyntaxError throwing). */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_VAR) { /* not allowed in strict mode, regardless of whether resolves; * in non-strict mode DELVAR handles both non-resolving and @@ -3582,16 +3651,11 @@ duk_dup(thr, res->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { /* register bound variables are non-configurable -> always false */ - duk__emit_bc(comp_ctx, - DUK_OP_LDFALSE, - reg_temp); + duk__emit_bc(comp_ctx, DUK_OP_LDFALSE, reg_temp); } else { duk_dup(thr, res->x1.valstack_idx); rc_varname = duk__getconst(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_DELVAR, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_DELVAR, reg_temp, rc_varname); } duk__ivalue_regconst(res, reg_temp); } else if (res->t == DUK_IVAL_PROP) { @@ -3601,13 +3665,11 @@ DUK__SETTEMP(comp_ctx, temp_at_entry); reg_temp = DUK__ALLOCTEMP(comp_ctx); - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - DUK_OP_DELPROP | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - reg_obj, - rc_key); + reg_obj = + duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = + duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, DUK_OP_DELPROP | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, reg_obj, rc_key); duk__ivalue_regconst(res, reg_temp); } else { @@ -3618,7 +3680,7 @@ return; } case DUK_TOK_VOID: { - duk__expr_toplain_ignore(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr_toplain_ignore(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ duk_push_undefined(thr); goto plain_value; } @@ -3628,7 +3690,7 @@ * will never be unresolvable so special handling is only required * when an identifier is a "slow path" one. */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_VAR) { duk_regconst_t reg_varbind; @@ -3640,10 +3702,7 @@ DUK_DDD(DUK_DDDPRINT("typeof for an identifier name which could not be resolved " "at compile time, need to use special run-time handling")); reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_TYPEOFID, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_TYPEOFID, reg_temp, rc_varname); duk__ivalue_regconst(res, reg_temp); return; } @@ -3662,9 +3721,8 @@ } case DUK_TOK_ADD: { /* unary plus */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && - duk_is_number(thr, res->x1.valstack_idx)) { + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && duk_is_number(thr, res->x1.valstack_idx)) { /* unary plus of a number is identity */ return; } @@ -3673,9 +3731,8 @@ } case DUK_TOK_SUB: { /* unary minus */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && - duk_is_number(thr, res->x1.valstack_idx)) { + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && duk_is_number(thr, res->x1.valstack_idx)) { /* this optimization is important to handle negative literals * (which are not directly provided by the lexical grammar) */ @@ -3695,12 +3752,12 @@ goto unary; } case DUK_TOK_BNOT: { - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ args = DUK_OP_BNOT; goto unary; } case DUK_TOK_LNOT: { - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE) { /* Very minimal inlining to handle common idioms '!0' and '!1', * and also boolean arguments like '!false' and '!true'. @@ -3735,117 +3792,110 @@ goto unary; } - } /* end switch */ + } /* end switch */ DUK_ERROR_SYNTAX(thr, DUK_STR_PARSE_ERROR); DUK_WO_NORETURN(return;); - unary: - { - /* Unary opcodes use just the 'BC' register source because it - * matches current shuffle limits, and maps cleanly to 16 high - * bits of the opcode. - */ - - duk_regconst_t reg_src, reg_res; - - reg_src = duk__ivalue_toregconst_raw(comp_ctx, res, -1 /*forced_reg*/, 0 /*flags*/); - if (DUK__ISREG_TEMP(comp_ctx, reg_src)) { - reg_res = reg_src; - } else { - reg_res = DUK__ALLOCTEMP(comp_ctx); - } - duk__emit_a_bc(comp_ctx, - args, - reg_res, - reg_src); - duk__ivalue_regconst(res, reg_res); - return; - } +unary : { + /* Unary opcodes use just the 'BC' register source because it + * matches current shuffle limits, and maps cleanly to 16 high + * bits of the opcode. + */ - preincdec: - { - /* preincrement and predecrement */ - duk_regconst_t reg_res; - duk_small_uint_t args_op1 = args & 0xff; /* DUK_OP_PREINCR/DUK_OP_PREDECR */ - duk_small_uint_t args_op2 = args >> 8; /* DUK_OP_PREINCP_RR/DUK_OP_PREDECP_RR */ - - /* Specific assumptions for opcode numbering. */ - DUK_ASSERT(DUK_OP_PREINCR + 4 == DUK_OP_PREINCV); - DUK_ASSERT(DUK_OP_PREDECR + 4 == DUK_OP_PREDECV); + duk_regconst_t reg_src, reg_res; + reg_src = duk__ivalue_toregconst_raw(comp_ctx, res, -1 /*forced_reg*/, 0 /*flags*/); + if (DUK__ISREG_TEMP(comp_ctx, reg_src)) { + reg_res = reg_src; + } else { reg_res = DUK__ALLOCTEMP(comp_ctx); + } + duk__emit_a_bc(comp_ctx, args, reg_res, reg_src); + duk__ivalue_regconst(res, reg_res); + return; +} - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_VAR) { - duk_hstring *h_varname; - duk_regconst_t reg_varbind; - duk_regconst_t rc_varname; - - h_varname = duk_known_hstring(thr, res->x1.valstack_idx); +preincdec : { + /* preincrement and predecrement */ + duk_regconst_t reg_res; + duk_small_uint_t args_op1 = args & 0xff; /* DUK_OP_PREINCR/DUK_OP_PREDECR */ + duk_small_uint_t args_op2 = args >> 8; /* DUK_OP_PREINCP_RR/DUK_OP_PREDECP_RR */ + + /* Specific assumptions for opcode numbering. */ + DUK_ASSERT(DUK_OP_PREINCR + 4 == DUK_OP_PREINCV); + DUK_ASSERT(DUK_OP_PREDECR + 4 == DUK_OP_PREDECV); + + reg_res = DUK__ALLOCTEMP(comp_ctx); + + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_VAR) { + duk_hstring *h_varname; + duk_regconst_t reg_varbind; + duk_regconst_t rc_varname; - if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { - goto syntax_error; - } + h_varname = duk_known_hstring(thr, res->x1.valstack_idx); - duk_dup(thr, res->x1.valstack_idx); - if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - args_op1, /* e.g. DUK_OP_PREINCR */ - reg_res, - reg_varbind); - } else { - duk__emit_a_bc(comp_ctx, - args_op1 + 4, /* e.g. DUK_OP_PREINCV */ - reg_res, - rc_varname); - } + if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { + goto syntax_error; + } - DUK_DDD(DUK_DDDPRINT("preincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); - } else if (res->t == DUK_IVAL_PROP) { - duk_regconst_t reg_obj; /* allocate to reg only (not const) */ - duk_regconst_t rc_key; - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_PREINCP */ - reg_res, - reg_obj, - rc_key); + duk_dup(thr, res->x1.valstack_idx); + if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { + duk__emit_a_bc(comp_ctx, + args_op1, /* e.g. DUK_OP_PREINCR */ + reg_res, + reg_varbind); } else { - /* Technically return value is not needed because INVLHS will - * unconditially throw a ReferenceError. Coercion is necessary - * for proper semantics (consider ToNumber() called for an object). - * Use DUK_OP_UNP with a dummy register to get ToNumber(). - */ - - duk__ivalue_toforcedreg(comp_ctx, res, reg_res); - duk__emit_bc(comp_ctx, - DUK_OP_UNP, - reg_res); /* for side effects, result ignored */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__emit_a_bc(comp_ctx, + args_op1 + 4, /* e.g. DUK_OP_PREINCV */ + reg_res, + rc_varname); } - DUK__SETTEMP(comp_ctx, reg_res + 1); - duk__ivalue_regconst(res, reg_res); - return; - } - plain_value: - { - /* Stack top contains plain value */ - duk__ivalue_plain_fromstack(comp_ctx, res); - return; + DUK_DDD(DUK_DDDPRINT("preincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); + } else if (res->t == DUK_IVAL_PROP) { + duk_regconst_t reg_obj; /* allocate to reg only (not const) */ + duk_regconst_t rc_key; + reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, + args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_PREINCP */ + reg_res, + reg_obj, + rc_key); + } else { + /* Technically return value is not needed because INVLHS will + * unconditially throw a ReferenceError. Coercion is necessary + * for proper semantics (consider ToNumber() called for an object). + * Use DUK_OP_UNP with a dummy register to get ToNumber(). + */ + + duk__ivalue_toforcedreg(comp_ctx, res, reg_res); + duk__emit_bc(comp_ctx, DUK_OP_UNP, reg_res); /* for side effects, result ignored */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } + DUK__SETTEMP(comp_ctx, reg_res + 1); + duk__ivalue_regconst(res, reg_res); + return; +} + +plain_value : { + /* Stack top contains plain value */ + duk__ivalue_plain_fromstack(comp_ctx, res); + return; +} #if defined(DUK_USE_ES6) - syntax_error_newtarget: +syntax_error_newtarget: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_NEWTARGET); DUK_WO_NORETURN(return;); #endif - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_EXPRESSION); DUK_WO_NORETURN(return;); } @@ -3858,7 +3908,7 @@ duk_hthread *thr = comp_ctx->thr; duk_token *tk; duk_small_uint_t tok; - duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ + duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ /* * ctx->prev_token token to process with duk__expr_led() @@ -3872,13 +3922,14 @@ tok = tk->t; DUK_DDD(DUK_DDDPRINT("duk__expr_led(), prev_token.t=%ld, allow_in=%ld, paren_level=%ld", - (long) tk->t, (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); + (long) tk->t, + (long) comp_ctx->curr_func.allow_in, + (long) comp_ctx->curr_func.paren_level)); /* XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here? */ switch (tok) { - - /* PRIMARY EXPRESSIONS */ + /* PRIMARY EXPRESSIONS */ case DUK_TOK_PERIOD: { /* Property access expressions are critical for correct LHS ordering, @@ -3906,7 +3957,7 @@ } res->t = DUK_IVAL_PROP; - duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ + duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); duk_push_hstring(thr, comp_ctx->curr_token.str1); duk_replace(thr, res->x2.valstack_idx); @@ -3941,12 +3992,12 @@ * See: test-bug-nested-prop-mutate.js. */ duk__ivalue_totempconst(comp_ctx, left); - duk__expr_toplain(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, '' terminates */ + duk__expr_toplain(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, '' terminates */ duk__advance_expect(comp_ctx, DUK_TOK_RBRACKET); res->t = DUK_IVAL_PROP; - duk__copy_ispec(comp_ctx, &res->x1, &res->x2); /* res.x1 -> res.x2 */ - duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ + duk__copy_ispec(comp_ctx, &res->x1, &res->x2); /* res.x1 -> res.x2 */ + duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ return; } case DUK_TOK_LPAREN: { @@ -3990,19 +4041,13 @@ duk_dup(thr, left->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - DUK_OP_CSREG | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_varbind, - reg_cs + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_CSREG | DUK__EMIT_FLAG_A_IS_SOURCE, reg_varbind, reg_cs + 0); } else { /* XXX: expand target register or constant field to * reduce shuffling. */ DUK_ASSERT(DUK__ISCONST(rc_varname)); - duk__emit_a_b(comp_ctx, - DUK_OP_CSVAR | DUK__EMIT_FLAG_BC_REGCONST, - reg_cs + 0, - rc_varname); + duk__emit_a_b(comp_ctx, DUK_OP_CSVAR | DUK__EMIT_FLAG_BC_REGCONST, reg_cs + 0, rc_varname); } } else if (left->t == DUK_IVAL_PROP) { /* Call through a property lookup, E5 Section 11.2.3, step 6.a.i, @@ -4024,16 +4069,12 @@ * and reuse, but it would still be in the wrong position * (reg_cs + 0 rather than reg_cs + 1). */ - duk__ispec_toforcedreg(comp_ctx, &left->x1, reg_cs + 1); /* base */ + duk__ispec_toforcedreg(comp_ctx, &left->x1, reg_cs + 1); /* base */ #if defined(DUK_USE_VERBOSE_ERRORS) reg_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROPC | DUK__EMIT_FLAG_BC_REGCONST, - reg_cs + 0, - reg_cs + 1, - reg_key); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROPC | DUK__EMIT_FLAG_BC_REGCONST, reg_cs + 0, reg_cs + 1, reg_key); #else - duk__ivalue_toforcedreg(comp_ctx, left, reg_cs + 0); /* basekey */ + duk__ivalue_toforcedreg(comp_ctx, left, reg_cs + 0); /* basekey */ #endif } else { DUK_DDD(DUK_DDDPRINT("function call with register base")); @@ -4052,23 +4093,20 @@ } DUK__SETTEMP(comp_ctx, reg_cs + 2); - nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp" */ + nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp" */ /* Tailcalls are handled by back-patching the already emitted opcode * later in return statement parser. */ - duk__emit_a_bc(comp_ctx, - call_op, - (duk_regconst_t) nargs /*numargs*/, - reg_cs /*basereg*/); - DUK__SETTEMP(comp_ctx, reg_cs + 1); /* result in csreg */ + duk__emit_a_bc(comp_ctx, call_op, (duk_regconst_t) nargs /*numargs*/, reg_cs /*basereg*/); + DUK__SETTEMP(comp_ctx, reg_cs + 1); /* result in csreg */ duk__ivalue_regconst(res, reg_cs); return; } - /* POSTFIX EXPRESSION */ + /* POSTFIX EXPRESSION */ case DUK_TOK_INCREMENT: { args = (DUK_OP_POSTINCP_RR << 16) + (DUK_OP_POSTINCR << 8) + 0; @@ -4083,38 +4121,38 @@ #if defined(DUK_USE_ES7_EXP_OPERATOR) case DUK_TOK_EXP: { - args = (DUK_OP_EXP << 8) + DUK__BP_EXPONENTIATION - 1; /* UnaryExpression */ + args = (DUK_OP_EXP << 8) + DUK__BP_EXPONENTIATION - 1; /* UnaryExpression */ goto binary; } #endif - /* MULTIPLICATIVE EXPRESSION */ + /* MULTIPLICATIVE EXPRESSION */ case DUK_TOK_MUL: { - args = (DUK_OP_MUL << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_MUL << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } case DUK_TOK_DIV: { - args = (DUK_OP_DIV << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_DIV << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } case DUK_TOK_MOD: { - args = (DUK_OP_MOD << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_MOD << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } - /* ADDITIVE EXPRESSION */ + /* ADDITIVE EXPRESSION */ case DUK_TOK_ADD: { - args = (DUK_OP_ADD << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ + args = (DUK_OP_ADD << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ goto binary; } case DUK_TOK_SUB: { - args = (DUK_OP_SUB << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ + args = (DUK_OP_SUB << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ goto binary; } - /* SHIFT EXPRESSION */ + /* SHIFT EXPRESSION */ case DUK_TOK_ALSHIFT: { /* << */ @@ -4132,7 +4170,7 @@ goto binary; } - /* RELATIONAL EXPRESSION */ + /* RELATIONAL EXPRESSION */ case DUK_TOK_LT: { /* < */ @@ -4160,7 +4198,7 @@ goto binary; } - /* EQUALITY EXPRESSION */ + /* EQUALITY EXPRESSION */ case DUK_TOK_EQ: { args = (DUK_OP_EQ << 8) + DUK__BP_EQUALITY; @@ -4179,7 +4217,7 @@ goto binary; } - /* BITWISE EXPRESSIONS */ + /* BITWISE EXPRESSIONS */ case DUK_TOK_BAND: { args = (DUK_OP_BAND << 8) + DUK__BP_BAND; @@ -4194,7 +4232,7 @@ goto binary; } - /* LOGICAL EXPRESSIONS */ + /* LOGICAL EXPRESSIONS */ case DUK_TOK_LAND: { /* syntactically left-associative but parsed as right-associative */ @@ -4207,7 +4245,7 @@ goto binary_logical; } - /* CONDITIONAL EXPRESSION */ + /* CONDITIONAL EXPRESSION */ case DUK_TOK_QUESTION: { /* XXX: common reg allocation need is to reuse a sub-expression's temp reg, @@ -4220,12 +4258,18 @@ reg_temp = DUK__ALLOCTEMP(comp_ctx); duk__ivalue_toforcedreg(comp_ctx, left, reg_temp); duk__emit_if_true_skip(comp_ctx, reg_temp); - pc_jump1 = duk__emit_jump_empty(comp_ctx); /* jump to false */ - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); /* AssignmentExpression */ + pc_jump1 = duk__emit_jump_empty(comp_ctx); /* jump to false */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp /*forced_reg*/); /* AssignmentExpression */ duk__advance_expect(comp_ctx, DUK_TOK_COLON); - pc_jump2 = duk__emit_jump_empty(comp_ctx); /* jump to end */ + pc_jump2 = duk__emit_jump_empty(comp_ctx); /* jump to end */ duk__patch_jump_here(comp_ctx, pc_jump1); - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); /* AssignmentExpression */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp /*forced_reg*/); /* AssignmentExpression */ duk__patch_jump_here(comp_ctx, pc_jump2); DUK__SETTEMP(comp_ctx, reg_temp + 1); @@ -4233,7 +4277,7 @@ return; } - /* ASSIGNMENT EXPRESSION */ + /* ASSIGNMENT EXPRESSION */ case DUK_TOK_EQUALSIGN: { /* @@ -4247,7 +4291,7 @@ * * XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)? */ - args = (DUK_OP_NONE << 8) + DUK__BP_ASSIGNMENT - 1; /* DUK_OP_NONE marks a 'plain' assignment */ + args = (DUK_OP_NONE << 8) + DUK__BP_ASSIGNMENT - 1; /* DUK_OP_NONE marks a 'plain' assignment */ goto assign; } case DUK_TOK_ADD_EQ: { @@ -4313,12 +4357,12 @@ goto assign; } - /* COMMA */ + /* COMMA */ case DUK_TOK_COMMA: { /* right associative */ - duk__ivalue_toplain_ignore(comp_ctx, left); /* need side effects, not value */ + duk__ivalue_toplain_ignore(comp_ctx, left); /* need side effects, not value */ duk__expr_toplain(comp_ctx, res, DUK__BP_COMMA - 1 /*rbp_flags*/); /* return 'res' (of right part) as our result */ @@ -4341,7 +4385,7 @@ } #endif - binary: +binary: /* * Shared handling of binary operations * @@ -4367,11 +4411,15 @@ duk_copy(thr, left->x1.valstack_idx, res->x1.valstack_idx); DUK_DDD(DUK_DDDPRINT("binary op, res: t=%ld, x1.t=%ld, x1.regconst=0x%08lx, x2.t=%ld, x2.regconst=0x%08lx", - (long) res->t, (long) res->x1.t, (unsigned long) res->x1.regconst, (long) res->x2.t, (unsigned long) res->x2.regconst)); + (long) res->t, + (long) res->x1.t, + (unsigned long) res->x1.regconst, + (long) res->x2.t, + (unsigned long) res->x2.regconst)); return; } - binary_logical: +binary_logical: /* * Shared handling for logical AND and logical OR. * @@ -4404,8 +4452,8 @@ duk__ivalue_toforcedreg(comp_ctx, left, reg_temp); DUK_ASSERT(DUK__ISREG(reg_temp)); duk__emit_bc(comp_ctx, - (args_truthval ? DUK_OP_IFTRUE_R : DUK_OP_IFFALSE_R), - reg_temp); /* skip jump conditionally */ + (args_truthval ? DUK_OP_IFTRUE_R : DUK_OP_IFFALSE_R), + reg_temp); /* skip jump conditionally */ pc_jump = duk__emit_jump_empty(comp_ctx); duk__expr_toforcedreg(comp_ctx, res, args_rbp /*rbp_flags*/, reg_temp /*forced_reg*/); duk__patch_jump_here(comp_ctx, pc_jump); @@ -4414,7 +4462,7 @@ return; } - assign: +assign: /* * Shared assignment expression handling * @@ -4467,7 +4515,7 @@ * is relevant for e.g. eval code. */ toplevel_assign = (comp_ctx->curr_func.nud_count == 1 && /* one token before */ - comp_ctx->curr_func.led_count == 1); /* one operator (= assign) */ + comp_ctx->curr_func.led_count == 1); /* one operator (= assign) */ DUK_DDD(DUK_DDDPRINT("assignment: nud_count=%ld, led_count=%ld, toplevel_assign=%ld", (long) comp_ctx->curr_func.nud_count, (long) comp_ctx->curr_func.led_count, @@ -4478,7 +4526,7 @@ duk_regconst_t reg_varbind; duk_regconst_t rc_varname; - DUK_ASSERT(left->x1.t == DUK_ISPEC_VALUE); /* LHS is already side effect free */ + DUK_ASSERT(left->x1.t == DUK_ISPEC_VALUE); /* LHS is already side effect free */ h_varname = duk_known_hstring(thr, left->x1.valstack_idx); if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { @@ -4495,9 +4543,10 @@ DUK_DDD(DUK_DDDPRINT("plain assignment, toplevel assign, use as is")); } else { /* 'res' must be a plain ivalue, and not register-bound variable. */ - DUK_DDD(DUK_DDDPRINT("plain assignment, not toplevel assign, ensure not a reg-bound identifier")); - if (res->t != DUK_IVAL_PLAIN || (res->x1.t == DUK_ISPEC_REGCONST && - DUK__ISREG_NOTTEMP(comp_ctx, res->x1.regconst))) { + DUK_DDD(DUK_DDDPRINT( + "plain assignment, not toplevel assign, ensure not a reg-bound identifier")); + if (res->t != DUK_IVAL_PLAIN || + (res->x1.t == DUK_ISPEC_REGCONST && DUK__ISREG_NOTTEMP(comp_ctx, res->x1.regconst))) { duk__ivalue_totempconst(comp_ctx, res); } } @@ -4530,7 +4579,7 @@ * value, so go through a temp. */ DUK_DD(DUK_DDPRINT("<op>= expression is not top level, write to reg_temp")); - reg_res = reg_temp; /* reg_res should be smallest possible */ + reg_res = reg_temp; /* reg_res should be smallest possible */ reg_temp = DUK__ALLOCTEMP(comp_ctx); } @@ -4542,10 +4591,7 @@ */ pc_temp_load = duk__get_current_pc(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_temp, - reg_varbind); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_temp, reg_varbind); pc_before_rhs = duk__get_current_pc(comp_ctx); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); @@ -4553,7 +4599,8 @@ pc_after_rhs = duk__get_current_pc(comp_ctx); DUK_DD(DUK_DDPRINT("pc_temp_load=%ld, pc_before_rhs=%ld, pc_after_rhs=%ld", - (long) pc_temp_load, (long) pc_before_rhs, + (long) pc_temp_load, + (long) pc_before_rhs, (long) pc_after_rhs)); if (pc_after_rhs == pc_before_rhs) { @@ -4561,11 +4608,16 @@ * instructions, we may need to rewind more than * one instruction, so use explicit PC computation. */ - DUK_DD(DUK_DDPRINT("rhs is side effect free, rewind and avoid unnecessary temp for reg-based <op>=")); - DUK_BW_ADD_PTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, (pc_temp_load - pc_before_rhs) * (duk_int_t) sizeof(duk_compiler_instr)); + DUK_DD(DUK_DDPRINT("rhs is side effect free, rewind and avoid unnecessary temp for " + "reg-based <op>=")); + DUK_BW_ADD_PTR(comp_ctx->thr, + &comp_ctx->curr_func.bw_code, + (pc_temp_load - pc_before_rhs) * + (duk_int_t) sizeof(duk_compiler_instr)); reg_src = reg_varbind; } else { - DUK_DD(DUK_DDPRINT("rhs evaluation emitted code, not sure if rhs is side effect free; use temp reg for LHS")); + DUK_DD(DUK_DDPRINT("rhs evaluation emitted code, not sure if rhs is side effect " + "free; use temp reg for LHS")); reg_src = reg_temp; } @@ -4586,10 +4638,7 @@ * temporary. No optimization for top level assignment. */ - duk__emit_a_bc(comp_ctx, - DUK_OP_GETVAR, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_GETVAR, reg_temp, rc_varname); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); DUK_ASSERT(res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_REGCONST); @@ -4622,7 +4671,7 @@ duk__ivalue_toforcedreg(comp_ctx, res, (duk_int_t) reg_varbind); } else { duk__ivalue_totempconst(comp_ctx, res); - duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ + duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ duk__ivalue_toforcedreg(comp_ctx, left, (duk_int_t) reg_varbind); } } else { @@ -4630,7 +4679,7 @@ * free and may be a plain value, a register, or a * constant) and write it to the LHS binding too. */ - duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ + duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ duk__ivalue_toforcedreg(comp_ctx, left, (duk_int_t) reg_varbind); } } else { @@ -4643,10 +4692,7 @@ */ duk__ivalue_toreg(comp_ctx, res); - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - res->x1.regconst, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, res->x1.regconst, rc_varname); } /* 'res' contains expression value */ @@ -4686,11 +4732,7 @@ rc_res = res->x1.regconst; } else { reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - reg_obj, - rc_key); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, reg_obj, rc_key); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); DUK_ASSERT(res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_REGCONST); @@ -4741,90 +4783,88 @@ return; } - postincdec: - { - /* - * Post-increment/decrement will return the original value as its - * result value. However, even that value will be coerced using - * ToNumber() which is quite awkward. Specific bytecode opcodes - * are used to handle these semantics. - * - * Note that post increment/decrement has a "no LineTerminator here" - * restriction. This is handled by duk__expr_lbp(), which forcibly terminates - * the previous expression if a LineTerminator occurs before '++'/'--'. - */ - - duk_regconst_t reg_res; - duk_small_uint_t args_op1 = (args >> 8) & 0xff; /* DUK_OP_POSTINCR/DUK_OP_POSTDECR */ - duk_small_uint_t args_op2 = args >> 16; /* DUK_OP_POSTINCP_RR/DUK_OP_POSTDECP_RR */ - - /* Specific assumptions for opcode numbering. */ - DUK_ASSERT(DUK_OP_POSTINCR + 4 == DUK_OP_POSTINCV); - DUK_ASSERT(DUK_OP_POSTDECR + 4 == DUK_OP_POSTDECV); +postincdec : { + /* + * Post-increment/decrement will return the original value as its + * result value. However, even that value will be coerced using + * ToNumber() which is quite awkward. Specific bytecode opcodes + * are used to handle these semantics. + * + * Note that post increment/decrement has a "no LineTerminator here" + * restriction. This is handled by duk__expr_lbp(), which forcibly terminates + * the previous expression if a LineTerminator occurs before '++'/'--'. + */ - reg_res = DUK__ALLOCTEMP(comp_ctx); + duk_regconst_t reg_res; + duk_small_uint_t args_op1 = (args >> 8) & 0xff; /* DUK_OP_POSTINCR/DUK_OP_POSTDECR */ + duk_small_uint_t args_op2 = args >> 16; /* DUK_OP_POSTINCP_RR/DUK_OP_POSTDECP_RR */ - if (left->t == DUK_IVAL_VAR) { - duk_hstring *h_varname; - duk_regconst_t reg_varbind; - duk_regconst_t rc_varname; + /* Specific assumptions for opcode numbering. */ + DUK_ASSERT(DUK_OP_POSTINCR + 4 == DUK_OP_POSTINCV); + DUK_ASSERT(DUK_OP_POSTDECR + 4 == DUK_OP_POSTDECV); - h_varname = duk_known_hstring(thr, left->x1.valstack_idx); + reg_res = DUK__ALLOCTEMP(comp_ctx); - if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { - goto syntax_error; - } + if (left->t == DUK_IVAL_VAR) { + duk_hstring *h_varname; + duk_regconst_t reg_varbind; + duk_regconst_t rc_varname; - duk_dup(thr, left->x1.valstack_idx); - if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - args_op1, /* e.g. DUK_OP_POSTINCR */ - reg_res, - reg_varbind); - } else { - duk__emit_a_bc(comp_ctx, - args_op1 + 4, /* e.g. DUK_OP_POSTINCV */ - reg_res, - rc_varname); - } + h_varname = duk_known_hstring(thr, left->x1.valstack_idx); - DUK_DDD(DUK_DDDPRINT("postincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); - } else if (left->t == DUK_IVAL_PROP) { - duk_regconst_t reg_obj; /* allocate to reg only (not const) */ - duk_regconst_t rc_key; + if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { + goto syntax_error; + } - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &left->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_POSTINCP */ - reg_res, - reg_obj, - rc_key); + duk_dup(thr, left->x1.valstack_idx); + if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { + duk__emit_a_bc(comp_ctx, + args_op1, /* e.g. DUK_OP_POSTINCR */ + reg_res, + reg_varbind); } else { - /* Technically return value is not needed because INVLHS will - * unconditially throw a ReferenceError. Coercion is necessary - * for proper semantics (consider ToNumber() called for an object). - * Use DUK_OP_UNP with a dummy register to get ToNumber(). - */ - duk__ivalue_toforcedreg(comp_ctx, left, reg_res); - duk__emit_bc(comp_ctx, - DUK_OP_UNP, - reg_res); /* for side effects, result ignored */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__emit_a_bc(comp_ctx, + args_op1 + 4, /* e.g. DUK_OP_POSTINCV */ + reg_res, + rc_varname); } - DUK__SETTEMP(comp_ctx, reg_res + 1); - duk__ivalue_regconst(res, reg_res); - return; + DUK_DDD(DUK_DDDPRINT("postincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); + } else if (left->t == DUK_IVAL_PROP) { + duk_regconst_t reg_obj; /* allocate to reg only (not const) */ + duk_regconst_t rc_key; + + reg_obj = duk__ispec_toregconst_raw(comp_ctx, &left->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, + args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_POSTINCP */ + reg_res, + reg_obj, + rc_key); + } else { + /* Technically return value is not needed because INVLHS will + * unconditially throw a ReferenceError. Coercion is necessary + * for proper semantics (consider ToNumber() called for an object). + * Use DUK_OP_UNP with a dummy register to get ToNumber(). + */ + duk__ivalue_toforcedreg(comp_ctx, left, reg_res); + duk__emit_bc(comp_ctx, DUK_OP_UNP, reg_res); /* for side effects, result ignored */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } - syntax_error: + DUK__SETTEMP(comp_ctx, reg_res + 1); + duk__ivalue_regconst(res, reg_res); + return; +} + +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_EXPRESSION); DUK_WO_NORETURN(return;); - syntax_error_lvalue: +syntax_error_lvalue: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_LVALUE); DUK_WO_NORETURN(return;); } @@ -4832,7 +4872,7 @@ DUK_LOCAL duk_small_uint_t duk__expr_lbp(duk_compiler_ctx *comp_ctx) { duk_small_uint_t tok = comp_ctx->curr_token.t; - DUK_ASSERT_DISABLE(tok >= DUK_TOK_MINVAL); /* unsigned */ + DUK_ASSERT_DISABLE(tok >= DUK_TOK_MINVAL); /* unsigned */ DUK_ASSERT(tok <= DUK_TOK_MAXVAL); DUK_ASSERT(sizeof(duk__token_lbp) == DUK_TOK_MAXVAL + 1); @@ -4845,8 +4885,7 @@ return 0; } - if ((tok == DUK_TOK_DECREMENT || tok == DUK_TOK_INCREMENT) && - (comp_ctx->curr_token.lineterm)) { + if ((tok == DUK_TOK_DECREMENT || tok == DUK_TOK_INCREMENT) && (comp_ctx->curr_token.lineterm)) { /* '++' or '--' in a post-increment/decrement position, * and a LineTerminator occurs between the operator and * the preceding expression. Force the previous expr @@ -4856,7 +4895,7 @@ return 0; } - return DUK__TOKEN_LBP_GET_BP(duk__token_lbptok); /* format is bit packed */ + return DUK__TOKEN_LBP_GET_BP(duk__token_lbptok); /* format is bit packed */ } /* @@ -4868,15 +4907,15 @@ * statement). */ -#define DUK__EXPR_RBP_MASK 0xff -#define DUK__EXPR_FLAG_REJECT_IN (1 << 8) /* reject 'in' token (used for for-in) */ -#define DUK__EXPR_FLAG_ALLOW_EMPTY (1 << 9) /* allow empty expression */ -#define DUK__EXPR_FLAG_REQUIRE_INIT (1 << 10) /* require initializer for var/const */ +#define DUK__EXPR_RBP_MASK 0xff +#define DUK__EXPR_FLAG_REJECT_IN (1 << 8) /* reject 'in' token (used for for-in) */ +#define DUK__EXPR_FLAG_ALLOW_EMPTY (1 << 9) /* allow empty expression */ +#define DUK__EXPR_FLAG_REQUIRE_INIT (1 << 10) /* require initializer for var/const */ /* main expression parser function */ DUK_LOCAL void duk__expr(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk_hthread *thr = comp_ctx->thr; - duk_ivalue tmp_alloc; /* 'res' is used for "left", and 'tmp' for "right" */ + duk_ivalue tmp_alloc; /* 'res' is used for "left", and 'tmp' for "right" */ duk_ivalue *tmp = &tmp_alloc; duk_small_uint_t rbp; @@ -4888,7 +4927,9 @@ rbp = rbp_flags & DUK__EXPR_RBP_MASK; DUK_DDD(DUK_DDDPRINT("duk__expr(), rbp_flags=%ld, rbp=%ld, allow_in=%ld, paren_level=%ld", - (long) rbp_flags, (long) rbp, (long) comp_ctx->curr_func.allow_in, + (long) rbp_flags, + (long) rbp, + (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); duk_memzero(&tmp_alloc, sizeof(tmp_alloc)); @@ -4919,14 +4960,14 @@ } duk__advance(comp_ctx); - duk__expr_nud(comp_ctx, res); /* reuse 'res' as 'left' */ + duk__expr_nud(comp_ctx, res); /* reuse 'res' as 'left' */ while (rbp < duk__expr_lbp(comp_ctx)) { duk__advance(comp_ctx); duk__expr_led(comp_ctx, res, tmp); - duk__copy_ivalue(comp_ctx, tmp, res); /* tmp -> res */ + duk__copy_ivalue(comp_ctx, tmp, res); /* tmp -> res */ } - cleanup: +cleanup: /* final result is already in 'res' */ duk_pop_2(thr); @@ -4960,21 +5001,24 @@ * Each helper needs at least 2-3 calls to make it worth while to wrap. */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_toreg(comp_ctx, res); } #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_totemp(comp_ctx, res); } #endif -DUK_LOCAL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg) { +DUK_LOCAL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg) { DUK_ASSERT(forced_reg >= 0); duk__expr(comp_ctx, res, rbp_flags); duk__ivalue_toforcedreg(comp_ctx, res, forced_reg); @@ -4985,7 +5029,7 @@ return duk__ivalue_toregconst(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_totempconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_totempconst(comp_ctx, res); @@ -5007,14 +5051,17 @@ return duk__ivalue_toreg(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__exprtop_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__exprtop(comp_ctx, res, rbp_flags); return duk__ivalue_totemp(comp_ctx, res); } #endif -DUK_LOCAL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg) { +DUK_LOCAL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg) { DUK_ASSERT(forced_reg >= 0); duk__exprtop(comp_ctx, res, rbp_flags); duk__ivalue_toforcedreg(comp_ctx, res, forced_reg); @@ -5025,7 +5072,7 @@ return duk__ivalue_toregconst(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__exprtop_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, int rbp_flags) { duk__exprtop(comp_ctx, res, rbp_flags); duk__ivalue_toplain_ignore(comp_ctx, res); @@ -5044,11 +5091,11 @@ * the token after the terminator). */ -#define DUK__HAS_VAL (1 << 0) /* stmt has non-empty value */ -#define DUK__HAS_TERM (1 << 1) /* stmt has explicit/implicit semicolon terminator */ -#define DUK__ALLOW_AUTO_SEMI_ALWAYS (1 << 2) /* allow automatic semicolon even without lineterm (compatibility) */ -#define DUK__STILL_PROLOGUE (1 << 3) /* statement does not terminate directive prologue */ -#define DUK__IS_TERMINAL (1 << 4) /* statement is guaranteed to be terminal (control doesn't flow to next statement) */ +#define DUK__HAS_VAL (1 << 0) /* stmt has non-empty value */ +#define DUK__HAS_TERM (1 << 1) /* stmt has explicit/implicit semicolon terminator */ +#define DUK__ALLOW_AUTO_SEMI_ALWAYS (1 << 2) /* allow automatic semicolon even without lineterm (compatibility) */ +#define DUK__STILL_PROLOGUE (1 << 3) /* statement does not terminate directive prologue */ +#define DUK__IS_TERMINAL (1 << 4) /* statement is guaranteed to be terminal (control doesn't flow to next statement) */ /* Parse a single variable declaration (e.g. "i" or "i=10"). A leading 'var' * has already been eaten. These is no return value in 'res', it is used only @@ -5068,7 +5115,11 @@ * as is done in 'for-in' parsing. */ -DUK_LOCAL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags, duk_regconst_t *out_reg_varbind, duk_regconst_t *out_rc_varname) { +DUK_LOCAL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t expr_flags, + duk_regconst_t *out_reg_varbind, + duk_regconst_t *out_rc_varname) { duk_hthread *thr = comp_ctx->thr; duk_hstring *h_varname; duk_regconst_t reg_varbind; @@ -5092,8 +5143,7 @@ /* register declarations in first pass */ if (comp_ctx->curr_func.in_scanning) { duk_uarridx_t n; - DUK_DDD(DUK_DDDPRINT("register variable declaration %!O in pass 1", - (duk_heaphdr *) h_varname)); + DUK_DDD(DUK_DDDPRINT("register variable declaration %!O in pass 1", (duk_heaphdr *) h_varname)); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); duk_push_hstring(thr, h_varname); duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n); @@ -5101,31 +5151,30 @@ duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n + 1); } - duk_push_hstring(thr, h_varname); /* push before advancing to keep reachable */ + duk_push_hstring(thr, h_varname); /* push before advancing to keep reachable */ /* register binding lookup is based on varmap (even in first pass) */ duk_dup_top(thr); (void) duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname); - duk__advance(comp_ctx); /* eat identifier */ + duk__advance(comp_ctx); /* eat identifier */ if (comp_ctx->curr_token.t == DUK_TOK_EQUALSIGN) { duk__advance(comp_ctx); DUK_DDD(DUK_DDDPRINT("vardecl, assign to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); - duk__exprtop(comp_ctx, res, DUK__BP_COMMA | expr_flags /*rbp_flags*/); /* AssignmentExpression */ + duk__exprtop(comp_ctx, res, DUK__BP_COMMA | expr_flags /*rbp_flags*/); /* AssignmentExpression */ if (reg_varbind >= 0) { duk__ivalue_toforcedreg(comp_ctx, res, reg_varbind); } else { duk_regconst_t reg_val; reg_val = duk__ivalue_toreg(comp_ctx, res); - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_val, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, reg_val, rc_varname); } } else { if (expr_flags & DUK__EXPR_FLAG_REQUIRE_INIT) { @@ -5134,14 +5183,14 @@ } } - duk_pop(thr); /* pop varname */ + duk_pop(thr); /* pop varname */ *out_rc_varname = rc_varname; *out_reg_varbind = reg_varbind; return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_VAR_DECLARATION); DUK_WO_NORETURN(return;); } @@ -5150,7 +5199,7 @@ duk_regconst_t reg_varbind; duk_regconst_t rc_varname; - duk__advance(comp_ctx); /* eat 'var' */ + duk__advance(comp_ctx); /* eat 'var' */ for (;;) { /* rc_varname and reg_varbind are ignored here */ @@ -5165,9 +5214,9 @@ DUK_LOCAL void duk__parse_for_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site) { duk_hthread *thr = comp_ctx->thr; - duk_int_t pc_v34_lhs; /* start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example) */ - duk_regconst_t temp_reset; /* knock back "next temp" to this whenever possible */ - duk_regconst_t reg_temps; /* preallocated temporaries (2) for variants 3 and 4 */ + duk_int_t pc_v34_lhs; /* start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example) */ + duk_regconst_t temp_reset; /* knock back "next temp" to this whenever possible */ + duk_regconst_t reg_temps; /* preallocated temporaries (2) for variants 3 and 4 */ DUK_DDD(DUK_DDDPRINT("start parsing a for/for-in statement")); @@ -5196,7 +5245,7 @@ * issues, evaluation order issues, etc. */ - duk__advance(comp_ctx); /* eat 'for' */ + duk__advance(comp_ctx); /* eat 'for' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); DUK_DDD(DUK_DDDPRINT("detecting for/for-in loop variant, pc=%ld", (long) duk__get_current_pc(comp_ctx))); @@ -5210,10 +5259,10 @@ * Variant 2 or 4 */ - duk_regconst_t reg_varbind; /* variable binding register if register-bound (otherwise < 0) */ - duk_regconst_t rc_varname; /* variable name reg/const, if variable not register-bound */ + duk_regconst_t reg_varbind; /* variable binding register if register-bound (otherwise < 0) */ + duk_regconst_t rc_varname; /* variable name reg/const, if variable not register-bound */ - duk__advance(comp_ctx); /* eat 'var' */ + duk__advance(comp_ctx); /* eat 'var' */ duk__parse_var_decl(comp_ctx, res, DUK__EXPR_FLAG_REJECT_IN, ®_varbind, &rc_varname); DUK__SETTEMP(comp_ctx, temp_reset); @@ -5223,17 +5272,11 @@ */ DUK_DDD(DUK_DDDPRINT("detected for variant 4: for (var VariableDeclarationNoIn in Expression) Statement")); - pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here */ + pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here */ if (reg_varbind >= 0) { - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_varbind, - reg_temps + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_varbind, reg_temps + 0); } else { - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_temps + 0, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, reg_temps + 0, rc_varname); } goto parse_3_or_4; } else { @@ -5241,7 +5284,8 @@ * Variant 2 */ - DUK_DDD(DUK_DDDPRINT("detected for variant 2: for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement")); + DUK_DDD(DUK_DDDPRINT( + "detected for variant 2: for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement")); for (;;) { /* more initializers */ if (comp_ctx->curr_token.t != DUK_TOK_COMMA) { @@ -5249,7 +5293,7 @@ } DUK_DDD(DUK_DDDPRINT("variant 2 has another variable initializer")); - duk__advance(comp_ctx); /* eat comma */ + duk__advance(comp_ctx); /* eat comma */ duk__parse_var_decl(comp_ctx, res, DUK__EXPR_FLAG_REJECT_IN, ®_varbind, &rc_varname); } goto parse_1_or_2; @@ -5259,14 +5303,17 @@ * Variant 1 or 3 */ - pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here (variant 3) */ + pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here (variant 3) */ /* Note that duk__exprtop() here can clobber any reg above current temp_next, * so any loop variables (e.g. enumerator) must be "preallocated". */ /* don't coerce yet to a plain value (variant 3 needs special handling) */ - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_REJECT_IN | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression */ + duk__exprtop(comp_ctx, + res, + DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_REJECT_IN | + DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression */ if (comp_ctx->curr_token.t == DUK_TOK_IN) { /* * Variant 3 @@ -5275,7 +5322,7 @@ /* XXX: need to determine LHS type, and check that it is LHS compatible */ DUK_DDD(DUK_DDDPRINT("detected for variant 3: for (LeftHandSideExpression in Expression) Statement")); if (duk__expr_is_empty(comp_ctx)) { - goto syntax_error; /* LeftHandSideExpression does not allow empty expression */ + goto syntax_error; /* LeftHandSideExpression does not allow empty expression */ } if (res->t == DUK_IVAL_VAR) { @@ -5284,10 +5331,7 @@ duk_dup(thr, res->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_varbind, - reg_temps + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_varbind, reg_temps + 0); } else { duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, @@ -5300,17 +5344,22 @@ */ duk_regconst_t reg_obj; duk_regconst_t rc_key; - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + reg_obj = duk__ispec_toregconst_raw(comp_ctx, + &res->x1, + -1 /*forced_reg*/, + 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, + &res->x2, + -1 /*forced_reg*/, + DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); duk__emit_a_b_c(comp_ctx, DUK_OP_PUTPROP | DUK__EMIT_FLAG_A_IS_SOURCE | DUK__EMIT_FLAG_BC_REGCONST, reg_obj, rc_key, reg_temps + 0); } else { - duk__ivalue_toplain_ignore(comp_ctx, res); /* just in case */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__ivalue_toplain_ignore(comp_ctx, res); /* just in case */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } goto parse_3_or_4; } else { @@ -5318,13 +5367,14 @@ * Variant 1 */ - DUK_DDD(DUK_DDDPRINT("detected for variant 1: for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement")); + DUK_DDD(DUK_DDDPRINT( + "detected for variant 1: for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement")); duk__ivalue_toplain_ignore(comp_ctx, res); goto parse_1_or_2; } } - parse_1_or_2: +parse_1_or_2: /* * Parse variant 1 or 2. The first part expression (which differs * in the variants) has already been parsed and its code emitted. @@ -5347,23 +5397,23 @@ duk__advance_expect(comp_ctx, DUK_TOK_SEMICOLON); pc_l1 = duk__get_current_pc(comp_ctx); - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ + duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ if (duk__expr_is_empty(comp_ctx)) { /* no need to coerce */ - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ - pc_jumpto_l4 = -1; /* omitted */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ + pc_jumpto_l4 = -1; /* omitted */ } else { rc_cond = duk__ivalue_toregconst(comp_ctx, res); duk__emit_if_false_skip(comp_ctx, rc_cond); - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ - pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); /* to exit */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ + pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); /* to exit */ } DUK__SETTEMP(comp_ctx, temp_reset); duk__advance_expect(comp_ctx, DUK_TOK_SEMICOLON); pc_l2 = duk__get_current_pc(comp_ctx); - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ + duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ if (duk__expr_is_empty(comp_ctx)) { /* no need to coerce */ expr_c_empty = 1; @@ -5376,7 +5426,7 @@ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_l3 = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -5391,21 +5441,23 @@ DUK_DDD(DUK_DDDPRINT("patching jumps: jumpto_l3: %ld->%ld, jumpto_l4: %ld->%ld, " "break: %ld->%ld, continue: %ld->%ld", - (long) pc_jumpto_l3, (long) pc_l3, (long) pc_jumpto_l4, (long) pc_l4, - (long) (pc_label_site + 1), (long) pc_l4, (long) (pc_label_site + 2), (long) pc_l2)); + (long) pc_jumpto_l3, + (long) pc_l3, + (long) pc_jumpto_l4, + (long) pc_l4, + (long) (pc_label_site + 1), + (long) pc_l4, + (long) (pc_label_site + 2), + (long) pc_l2)); duk__patch_jump(comp_ctx, pc_jumpto_l3, pc_l3); duk__patch_jump(comp_ctx, pc_jumpto_l4, pc_l4); - duk__patch_jump(comp_ctx, - pc_label_site + 1, - pc_l4); /* break jump */ - duk__patch_jump(comp_ctx, - pc_label_site + 2, - expr_c_empty ? pc_l1 : pc_l2); /* continue jump */ + duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l4); /* break jump */ + duk__patch_jump(comp_ctx, pc_label_site + 2, expr_c_empty ? pc_l1 : pc_l2); /* continue jump */ } goto finished; - parse_3_or_4: +parse_3_or_4: /* * Parse variant 3 or 4. * @@ -5441,16 +5493,16 @@ */ duk__insert_jump_entry(comp_ctx, pc_v34_lhs); - pc_jumpto_l2 = pc_v34_lhs; /* inserted jump */ - pc_l1 = pc_v34_lhs + 1; /* +1, right after inserted jump */ + pc_jumpto_l2 = pc_v34_lhs; /* inserted jump */ + pc_l1 = pc_v34_lhs + 1; /* +1, right after inserted jump */ /* The code for writing reg_temps + 0 to the left hand side has already * been emitted. */ - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* -> loop body */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* -> loop body */ - duk__advance(comp_ctx); /* eat 'in' */ + duk__advance(comp_ctx); /* eat 'in' */ /* Parse enumeration target and initialize enumerator. For 'null' and 'undefined', * INITENUM will creates a 'null' enumerator which works like an empty enumerator @@ -5459,16 +5511,13 @@ */ pc_l2 = duk__get_current_pc(comp_ctx); - reg_target = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression */ - duk__emit_b_c(comp_ctx, - DUK_OP_INITENUM | DUK__EMIT_FLAG_B_IS_TARGET, - reg_temps + 1, - reg_target); + reg_target = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression */ + duk__emit_b_c(comp_ctx, DUK_OP_INITENUM | DUK__EMIT_FLAG_B_IS_TARGET, reg_temps + 1, reg_target); pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_l3 = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -5485,8 +5534,8 @@ DUK_OP_NEXTENUM | DUK__EMIT_FLAG_B_IS_TARGET | DUK__EMIT_FLAG_RESERVE_JUMPSLOT, reg_temps + 0, reg_temps + 1); - pc_jumpto_l5 = comp_ctx->emit_jumpslot_pc; /* NEXTENUM jump slot: executed when enum finished */ - duk__emit_jump(comp_ctx, pc_l1); /* jump to next loop, using reg_v34_iter as iterated value */ + pc_jumpto_l5 = comp_ctx->emit_jumpslot_pc; /* NEXTENUM jump slot: executed when enum finished */ + duk__emit_jump(comp_ctx, pc_l1); /* jump to next loop, using reg_v34_iter as iterated value */ pc_l5 = duk__get_current_pc(comp_ctx); @@ -5498,24 +5547,33 @@ DUK_DDD(DUK_DDDPRINT("patching jumps: jumpto_l2: %ld->%ld, jumpto_l3: %ld->%ld, " "jumpto_l4: %ld->%ld, jumpto_l5: %ld->%ld, " "break: %ld->%ld, continue: %ld->%ld", - (long) pc_jumpto_l2, (long) pc_l2, (long) pc_jumpto_l3, (long) pc_l3, - (long) pc_jumpto_l4, (long) pc_l4, (long) pc_jumpto_l5, (long) pc_l5, - (long) (pc_label_site + 1), (long) pc_l5, (long) (pc_label_site + 2), (long) pc_l4)); + (long) pc_jumpto_l2, + (long) pc_l2, + (long) pc_jumpto_l3, + (long) pc_l3, + (long) pc_jumpto_l4, + (long) pc_l4, + (long) pc_jumpto_l5, + (long) pc_l5, + (long) (pc_label_site + 1), + (long) pc_l5, + (long) (pc_label_site + 2), + (long) pc_l4)); duk__patch_jump(comp_ctx, pc_jumpto_l2, pc_l2); duk__patch_jump(comp_ctx, pc_jumpto_l3, pc_l3); duk__patch_jump(comp_ctx, pc_jumpto_l4, pc_l4); duk__patch_jump(comp_ctx, pc_jumpto_l5, pc_l5); - duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l5); /* break jump */ - duk__patch_jump(comp_ctx, pc_label_site + 2, pc_l4); /* continue jump */ + duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l5); /* break jump */ + duk__patch_jump(comp_ctx, pc_label_site + 2, pc_l4); /* continue jump */ } goto finished; - finished: +finished: DUK_DDD(DUK_DDDPRINT("end parsing a for/for-in statement")); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_FOR); DUK_WO_NORETURN(return;); } @@ -5523,12 +5581,12 @@ DUK_LOCAL void duk__parse_switch_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site) { duk_hthread *thr = comp_ctx->thr; duk_regconst_t temp_at_loop; - duk_regconst_t rc_switch; /* reg/const for switch value */ - duk_regconst_t rc_case; /* reg/const for case value */ - duk_regconst_t reg_temp; /* general temp register */ + duk_regconst_t rc_switch; /* reg/const for switch value */ + duk_regconst_t rc_case; /* reg/const for case value */ + duk_regconst_t reg_temp; /* general temp register */ duk_int_t pc_prevcase = -1; duk_int_t pc_prevstmt = -1; - duk_int_t pc_default = -1; /* -1 == not set, -2 == pending (next statement list) */ + duk_int_t pc_default = -1; /* -1 == not set, -2 == pending (next statement list) */ /* Note: negative pc values are ignored when patching jumps, so no explicit checks needed */ @@ -5559,7 +5617,7 @@ duk__advance(comp_ctx); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); rc_switch = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); DUK_DDD(DUK_DDDPRINT("switch value in register %ld", (long) rc_switch)); @@ -5589,24 +5647,20 @@ * because it may be a constant. */ - duk__patch_jump_here(comp_ctx, pc_prevcase); /* chain jumps for case - * evaluation and checking - */ + duk__patch_jump_here(comp_ctx, pc_prevcase); /* chain jumps for case + * evaluation and checking + */ duk__advance(comp_ctx); rc_case = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__advance_expect(comp_ctx, DUK_TOK_COLON); reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_b_c(comp_ctx, - DUK_OP_SEQ | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - rc_switch, - rc_case); + duk__emit_a_b_c(comp_ctx, DUK_OP_SEQ | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, rc_switch, rc_case); duk__emit_if_true_skip(comp_ctx, reg_temp); /* jump to next case clause */ - pc_prevcase = duk__emit_jump_empty(comp_ctx); /* no match, next case */ + pc_prevcase = duk__emit_jump_empty(comp_ctx); /* no match, next case */ /* statements go here (if any) on next loop */ } else if (comp_ctx->curr_token.t == DUK_TOK_DEFAULT) { @@ -5655,14 +5709,13 @@ * they participate in 'fall-through' behavior even if the * default clause is in the middle. */ - duk__patch_jump_here(comp_ctx, pc_prevstmt); /* chain jumps for 'fall-through' - * after a case matches. - */ + duk__patch_jump_here(comp_ctx, pc_prevstmt); /* chain jumps for 'fall-through' + * after a case matches. + */ for (;;) { tok = comp_ctx->curr_token.t; - if (tok == DUK_TOK_CASE || tok == DUK_TOK_DEFAULT || - tok == DUK_TOK_RCURLY) { + if (tok == DUK_TOK_CASE || tok == DUK_TOK_DEFAULT || tok == DUK_TOK_RCURLY) { break; } num_stmts++; @@ -5685,7 +5738,7 @@ DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RCURLY); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance(comp_ctx); /* Allow RegExp as part of next stmt. */ + duk__advance(comp_ctx); /* Allow RegExp as part of next stmt. */ /* default case control flow patchup; note that if pc_prevcase < 0 * (i.e. no case clauses), control enters default case automatically. @@ -5706,7 +5759,7 @@ duk__patch_jump_here(comp_ctx, pc_prevstmt); /* continue jump not patched, an INVALID opcode remains there */ - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ /* Note: 'fast' breaks will jump to pc_label_site + 1, which will * then jump here. The double jump will be eliminated by a @@ -5716,7 +5769,7 @@ return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_SWITCH); DUK_WO_NORETURN(return;); } @@ -5730,16 +5783,16 @@ temp_reset = DUK__GETTEMP(comp_ctx); - duk__advance(comp_ctx); /* eat 'if' */ + duk__advance(comp_ctx); /* eat 'if' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); rc_cond = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__emit_if_true_skip(comp_ctx, rc_cond); - pc_jump_false = duk__emit_jump_empty(comp_ctx); /* jump to end or else part */ + pc_jump_false = duk__emit_jump_empty(comp_ctx); /* jump to end or else part */ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -5754,7 +5807,7 @@ duk__advance(comp_ctx); - pc_jump_end = duk__emit_jump_empty(comp_ctx); /* jump from true part to end */ + pc_jump_end = duk__emit_jump_empty(comp_ctx); /* jump from true part to end */ duk__patch_jump_here(comp_ctx, pc_jump_false); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -5775,11 +5828,11 @@ DUK_DDD(DUK_DDDPRINT("begin parsing do statement")); - duk__advance(comp_ctx); /* Eat 'do'; allow RegExp as part of next stmt. */ + duk__advance(comp_ctx); /* Eat 'do'; allow RegExp as part of next stmt. */ pc_start = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); - duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ duk__advance_expect(comp_ctx, DUK_TOK_WHILE); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); @@ -5789,10 +5842,10 @@ duk__emit_jump(comp_ctx, pc_start); /* no need to reset temps, as we're finished emitting code */ - comp_ctx->curr_func.allow_regexp_in_adv = 1; /* Allow RegExp as part of next stmt. */ + comp_ctx->curr_func.allow_regexp_in_adv = 1; /* Allow RegExp as part of next stmt. */ duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ DUK_DDD(DUK_DDDPRINT("end parsing do statement")); } @@ -5807,12 +5860,12 @@ temp_reset = DUK__GETTEMP(comp_ctx); - duk__advance(comp_ctx); /* eat 'while' */ + duk__advance(comp_ctx); /* eat 'while' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); pc_start = duk__get_current_pc(comp_ctx); - duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ rc_cond = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__emit_if_true_skip(comp_ctx, rc_cond); @@ -5820,13 +5873,13 @@ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); duk__emit_jump(comp_ctx, pc_start); duk__patch_jump_here(comp_ctx, pc_jump_false); - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ DUK_DDD(DUK_DDDPRINT("end parsing while statement")); } @@ -5836,23 +5889,35 @@ duk_bool_t is_break = (comp_ctx->curr_token.t == DUK_TOK_BREAK); duk_int_t label_id; duk_int_t label_catch_depth; - duk_int_t label_pc; /* points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue */ + duk_int_t label_pc; /* points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue */ duk_bool_t label_is_closest; DUK_UNREF(res); - duk__advance(comp_ctx); /* eat 'break' or 'continue' */ + duk__advance(comp_ctx); /* eat 'break' or 'continue' */ - if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ - comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ - comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ + if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ + comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ + comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ /* break/continue without label */ - duk__lookup_active_label(comp_ctx, DUK_HTHREAD_STRING_EMPTY_STRING(thr), is_break, &label_id, &label_catch_depth, &label_pc, &label_is_closest); + duk__lookup_active_label(comp_ctx, + DUK_HTHREAD_STRING_EMPTY_STRING(thr), + is_break, + &label_id, + &label_catch_depth, + &label_pc, + &label_is_closest); } else if (comp_ctx->curr_token.t == DUK_TOK_IDENTIFIER) { /* break/continue with label (label cannot be a reserved word, production is 'Identifier' */ DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); - duk__lookup_active_label(comp_ctx, comp_ctx->curr_token.str1, is_break, &label_id, &label_catch_depth, &label_pc, &label_is_closest); + duk__lookup_active_label(comp_ctx, + comp_ctx->curr_token.str1, + is_break, + &label_id, + &label_catch_depth, + &label_pc, + &label_is_closest); duk__advance(comp_ctx); } else { DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_BREAK_CONT_LABEL); @@ -5865,25 +5930,28 @@ * The peephole optimizer will optimize the jump to a direct one. */ - if (label_catch_depth == comp_ctx->curr_func.catch_depth && - label_is_closest) { + if (label_catch_depth == comp_ctx->curr_func.catch_depth && label_is_closest) { DUK_DDD(DUK_DDDPRINT("break/continue: is_break=%ld, label_id=%ld, label_is_closest=%ld, " "label_catch_depth=%ld, catch_depth=%ld " "-> use fast variant (direct jump)", - (long) is_break, (long) label_id, (long) label_is_closest, - (long) label_catch_depth, (long) comp_ctx->curr_func.catch_depth)); + (long) is_break, + (long) label_id, + (long) label_is_closest, + (long) label_catch_depth, + (long) comp_ctx->curr_func.catch_depth)); duk__emit_jump(comp_ctx, label_pc + (is_break ? 1 : 2)); } else { DUK_DDD(DUK_DDDPRINT("break/continue: is_break=%ld, label_id=%ld, label_is_closest=%ld, " "label_catch_depth=%ld, catch_depth=%ld " "-> use slow variant (longjmp)", - (long) is_break, (long) label_id, (long) label_is_closest, - (long) label_catch_depth, (long) comp_ctx->curr_func.catch_depth)); + (long) is_break, + (long) label_id, + (long) label_is_closest, + (long) label_catch_depth, + (long) comp_ctx->curr_func.catch_depth)); - duk__emit_bc(comp_ctx, - is_break ? DUK_OP_BREAK : DUK_OP_CONTINUE, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, is_break ? DUK_OP_BREAK : DUK_OP_CONTINUE, (duk_regconst_t) label_id); } } @@ -5891,7 +5959,7 @@ duk_hthread *thr = comp_ctx->thr; duk_regconst_t rc_val; - duk__advance(comp_ctx); /* eat 'return' */ + duk__advance(comp_ctx); /* eat 'return' */ /* A 'return' statement is only allowed inside an actual function body, * not as part of eval or global code. @@ -5901,9 +5969,9 @@ DUK_WO_NORETURN(return;); } - if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ - comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ - comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ + if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ + comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ + comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ DUK_DDD(DUK_DDDPRINT("empty return value -> undefined")); duk__emit_op_only(comp_ctx, DUK_OP_RETUNDEF); } else { @@ -5955,8 +6023,8 @@ */ #if defined(DUK_USE_TAILCALL) - if (comp_ctx->curr_func.catch_depth == 0 && /* no catchers */ - pc_after_expr > pc_before_expr) { /* at least one opcode emitted */ + if (comp_ctx->curr_func.catch_depth == 0 && /* no catchers */ + pc_after_expr > pc_before_expr) { /* at least one opcode emitted */ duk_compiler_instr *instr; duk_instr_t ins; duk_small_uint_t op; @@ -5966,8 +6034,7 @@ ins = instr->ins; op = (duk_small_uint_t) DUK_DEC_OP(ins); - if ((op & ~0x0fU) == DUK_OP_CALL0 && - DUK__ISREG_TEMP(comp_ctx, rc_val) /* see above */) { + if ((op & ~0x0fU) == DUK_OP_CALL0 && DUK__ISREG_TEMP(comp_ctx, rc_val) /* see above */) { DUK_DDD(DUK_DDDPRINT("return statement detected a tail call opportunity: " "catch depth is 0, duk__exprtop() emitted >= 1 instructions, " "and last instruction is a CALL " @@ -5976,7 +6043,7 @@ instr->ins = ins; } } -#endif /* DUK_USE_TAILCALL */ +#endif /* DUK_USE_TAILCALL */ if (DUK__ISREG(rc_val)) { duk__emit_bc(comp_ctx, DUK_OP_RETREG, rc_val); @@ -5994,7 +6061,7 @@ DUK_LOCAL void duk__parse_throw_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_regconst_t reg_val; - duk__advance(comp_ctx); /* eat 'throw' */ + duk__advance(comp_ctx); /* eat 'throw' */ /* Unlike break/continue, throw statement does not allow an empty value. */ @@ -6004,14 +6071,12 @@ } reg_val = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - duk__emit_bc(comp_ctx, - DUK_OP_THROW, - reg_val); + duk__emit_bc(comp_ctx, DUK_OP_THROW, reg_val); } DUK_LOCAL void duk__parse_try_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; - duk_regconst_t reg_catch; /* reg_catch+0 and reg_catch+1 are reserved for TRYCATCH */ + duk_regconst_t reg_catch; /* reg_catch+0 and reg_catch+1 are reserved for TRYCATCH */ duk_regconst_t rc_varname = 0; duk_small_uint_t trycatch_flags = 0; duk_int_t pc_ldconst = -1; @@ -6038,7 +6103,7 @@ comp_ctx->curr_func.catch_depth++; - duk__advance(comp_ctx); /* eat 'try' */ + duk__advance(comp_ctx); /* eat 'try' */ reg_catch = DUK__ALLOCTEMPS(comp_ctx, 2); @@ -6051,9 +6116,9 @@ duk__emit_a_bc(comp_ctx, DUK_OP_LDCONST, reg_catch, 0 /*patched later*/); pc_trycatch = duk__get_current_pc(comp_ctx); - duk__emit_invalid(comp_ctx); /* TRYCATCH, cannot emit now (not enough info) */ - duk__emit_invalid(comp_ctx); /* jump for 'catch' case */ - duk__emit_invalid(comp_ctx); /* jump for 'finally' case or end (if no finally) */ + duk__emit_invalid(comp_ctx); /* TRYCATCH, cannot emit now (not enough info) */ + duk__emit_invalid(comp_ctx); /* jump for 'catch' case */ + duk__emit_invalid(comp_ctx); /* jump for 'finally' case or end (if no finally) */ /* try part */ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); @@ -6082,7 +6147,7 @@ */ duk_hstring *h_var; - duk_int_t varmap_value; /* for storing/restoring the varmap binding for catch variable */ + duk_int_t varmap_value; /* for storing/restoring the varmap binding for catch variable */ DUK_DDD(DUK_DDDPRINT("stack top at start of catch clause: %ld", (long) duk_get_top(thr))); @@ -6100,19 +6165,17 @@ h_var = comp_ctx->curr_token.str1; DUK_ASSERT(h_var != NULL); - duk_push_hstring(thr, h_var); /* keep in on valstack, use borrowed ref below */ + duk_push_hstring(thr, h_var); /* keep in on valstack, use borrowed ref below */ if (comp_ctx->curr_func.is_strict && - ((h_var == DUK_HTHREAD_STRING_EVAL(thr)) || - (h_var == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr)))) { + ((h_var == DUK_HTHREAD_STRING_EVAL(thr)) || (h_var == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr)))) { DUK_DDD(DUK_DDDPRINT("catch identifier 'eval' or 'arguments' in strict mode -> SyntaxError")); goto syntax_error; } duk_dup_top(thr); rc_varname = duk__getconst(comp_ctx); - DUK_DDD(DUK_DDDPRINT("catch clause, rc_varname=0x%08lx (%ld)", - (unsigned long) rc_varname, (long) rc_varname)); + DUK_DDD(DUK_DDDPRINT("catch clause, rc_varname=0x%08lx (%ld)", (unsigned long) rc_varname, (long) rc_varname)); duk__advance(comp_ctx); duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); @@ -6175,8 +6238,7 @@ DUK_DDD(DUK_DDDPRINT("varmap after restore catch clause: %!iT", (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.varmap_idx))); - duk__emit_op_only(comp_ctx, - DUK_OP_ENDCATCH); + duk__emit_op_only(comp_ctx, DUK_OP_ENDCATCH); /* * XXX: for now, indicate that an expensive catch binding @@ -6199,13 +6261,10 @@ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); duk__parse_stmts(comp_ctx, 0 /*allow_source_elem*/, 0 /*expect_eof*/, 1 /*regexp_after*/); /* the DUK_TOK_RCURLY is eaten by duk__parse_stmts() */ - duk__emit_abc(comp_ctx, - DUK_OP_ENDFIN, - reg_catch); /* rethrow */ + duk__emit_abc(comp_ctx, DUK_OP_ENDFIN, reg_catch); /* rethrow */ } - if (!(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) && - !(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY)) { + if (!(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) && !(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY)) { /* must have catch and/or finally */ goto syntax_error; } @@ -6215,12 +6274,7 @@ * constant 0) the DUK__CONST_MARKER flag will be set in rc_varname. */ - duk__patch_trycatch(comp_ctx, - pc_ldconst, - pc_trycatch, - reg_catch, - rc_varname, - trycatch_flags); + duk__patch_trycatch(comp_ctx, pc_ldconst, pc_trycatch, reg_catch, rc_varname, trycatch_flags); if (trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) { DUK_ASSERT(pc_catch >= 0); @@ -6238,7 +6292,7 @@ comp_ctx->curr_func.catch_depth--; return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_TRY); DUK_WO_NORETURN(return;); } @@ -6256,23 +6310,23 @@ comp_ctx->curr_func.catch_depth++; - duk__advance(comp_ctx); /* eat 'with' */ + duk__advance(comp_ctx); /* eat 'with' */ reg_catch = DUK__ALLOCTEMPS(comp_ctx, 2); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); duk__exprtop_toforcedreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/, reg_catch); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_trycatch = duk__get_current_pc(comp_ctx); trycatch_flags = DUK_BC_TRYCATCH_FLAG_WITH_BINDING; duk__emit_a_bc(comp_ctx, - DUK_OP_TRYCATCH | DUK__EMIT_FLAG_NO_SHUFFLE_A, - (duk_regconst_t) trycatch_flags /*a*/, - reg_catch /*bc*/); - duk__emit_invalid(comp_ctx); /* catch jump */ - duk__emit_invalid(comp_ctx); /* finished jump */ + DUK_OP_TRYCATCH | DUK__EMIT_FLAG_NO_SHUFFLE_A, + (duk_regconst_t) trycatch_flags /*a*/, + reg_catch /*bc*/); + duk__emit_invalid(comp_ctx); /* catch jump */ + duk__emit_invalid(comp_ctx); /* finished jump */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); duk__emit_op_only(comp_ctx, DUK_OP_ENDTRY); @@ -6293,9 +6347,7 @@ label_id = comp_ctx->curr_func.label_next++; DUK_DDD(DUK_DDDPRINT("allocated new label id for label site: %ld", (long) label_id)); - duk__emit_bc(comp_ctx, - DUK_OP_LABEL, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, DUK_OP_LABEL, (duk_regconst_t) label_id); duk__emit_invalid(comp_ctx); duk__emit_invalid(comp_ctx); @@ -6309,10 +6361,10 @@ */ DUK_LOCAL void duk__parse_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_bool_t allow_source_elem) { duk_hthread *thr = comp_ctx->thr; - duk_bool_t dir_prol_at_entry; /* directive prologue status at entry */ + duk_bool_t dir_prol_at_entry; /* directive prologue status at entry */ duk_regconst_t temp_at_entry; duk_size_t labels_len_at_entry; - duk_int_t pc_at_entry; /* assumed to also be PC of "LABEL" */ + duk_int_t pc_at_entry; /* assumed to also be PC of "LABEL" */ duk_int_t stmt_id; duk_small_uint_t stmt_flags = 0; duk_int_t label_id = -1; @@ -6331,8 +6383,11 @@ DUK_DDD(DUK_DDDPRINT("parsing a statement, stmt_id=%ld, temp_at_entry=%ld, labels_len_at_entry=%ld, " "is_strict=%ld, in_directive_prologue=%ld, catch_depth=%ld", - (long) stmt_id, (long) temp_at_entry, (long) labels_len_at_entry, - (long) comp_ctx->curr_func.is_strict, (long) comp_ctx->curr_func.in_directive_prologue, + (long) stmt_id, + (long) temp_at_entry, + (long) labels_len_at_entry, + (long) comp_ctx->curr_func.is_strict, + (long) comp_ctx->curr_func.in_directive_prologue, (long) comp_ctx->curr_func.catch_depth)); /* The directive prologue flag is cleared by default so that it is @@ -6342,10 +6397,12 @@ */ comp_ctx->curr_func.in_directive_prologue = 0; - retry_parse: +retry_parse: DUK_DDD(DUK_DDDPRINT("try stmt parse, stmt_id=%ld, label_id=%ld, allow_source_elem=%ld, catch_depth=%ld", - (long) stmt_id, (long) label_id, (long) allow_source_elem, + (long) stmt_id, + (long) label_id, + (long) allow_source_elem, (long) comp_ctx->curr_func.catch_depth)); /* @@ -6354,15 +6411,11 @@ */ tok = comp_ctx->curr_token.t; - if (tok == DUK_TOK_FOR || tok == DUK_TOK_DO || tok == DUK_TOK_WHILE || - tok == DUK_TOK_SWITCH) { + if (tok == DUK_TOK_FOR || tok == DUK_TOK_DO || tok == DUK_TOK_WHILE || tok == DUK_TOK_SWITCH) { DUK_DDD(DUK_DDDPRINT("iteration/switch statement -> add empty label")); label_id = duk__stmt_label_site(comp_ctx, label_id); - duk__add_label(comp_ctx, - DUK_HTHREAD_STRING_EMPTY_STRING(thr), - pc_at_entry /*pc_label*/, - label_id); + duk__add_label(comp_ctx, DUK_HTHREAD_STRING_EMPTY_STRING(thr), pc_at_entry /*pc_label*/, label_id); } /* @@ -6389,10 +6442,8 @@ * strict and non-strict modes. However, don't allow labelled * function declarations in strict mode. */ - test_func_decl = test_func_decl || - !comp_ctx->curr_func.is_strict || - label_id < 0; -#endif /* DUK_USE_NONSTD_FUNC_STMT */ + test_func_decl = test_func_decl || !comp_ctx->curr_func.is_strict || label_id < 0; +#endif /* DUK_USE_NONSTD_FUNC_STMT */ /* Strict: never allow function declarations outside top level. */ if (test_func_decl) { /* FunctionDeclaration: not strictly a statement but handled as such. @@ -6414,7 +6465,7 @@ top_before = duk_get_top(thr); #endif - duk__advance(comp_ctx); /* eat 'function' */ + duk__advance(comp_ctx); /* eat 'function' */ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_DECL | DUK__FUNC_FLAG_PUSHNAME_PASS1); /* The value stack convention here is a bit odd: the function @@ -6428,7 +6479,8 @@ DUK_ASSERT(duk_get_top(thr) == top_before + 1); #endif DUK_DDD(DUK_DDDPRINT("register function declaration %!T in pass 1, fnum %ld", - duk_get_tval(thr, -1), (long) fnum)); + duk_get_tval(thr, -1), + (long) fnum)); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); /* funcname is at index -1 */ duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n); @@ -6455,7 +6507,7 @@ duk__parse_stmts(comp_ctx, 0 /*allow_source_elem*/, 0 /*expect_eof*/, 1 /*regexp_after*/); /* the DUK_TOK_RCURLY is eaten by duk__parse_stmts() */ if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } stmt_flags = 0; break; @@ -6482,7 +6534,7 @@ DUK_DDD(DUK_DDDPRINT("if statement")); duk__parse_if_stmt(comp_ctx, res); if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } stmt_flags = 0; break; @@ -6499,19 +6551,15 @@ */ DUK_DDD(DUK_DDDPRINT("do statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_do_stmt(comp_ctx, res, pc_at_entry); - stmt_flags = DUK__HAS_TERM | DUK__ALLOW_AUTO_SEMI_ALWAYS; /* DUK__ALLOW_AUTO_SEMI_ALWAYS workaround */ + stmt_flags = DUK__HAS_TERM | DUK__ALLOW_AUTO_SEMI_ALWAYS; /* DUK__ALLOW_AUTO_SEMI_ALWAYS workaround */ break; } case DUK_TOK_WHILE: { DUK_DDD(DUK_DDDPRINT("while statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_while_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -6526,9 +6574,7 @@ */ DUK_DDD(DUK_DDDPRINT("for/for-in statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_for_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -6551,7 +6597,7 @@ comp_ctx->curr_func.with_depth++; duk__parse_with_stmt(comp_ctx, res); if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } comp_ctx->curr_func.with_depth--; stmt_flags = 0; @@ -6564,9 +6610,7 @@ */ DUK_DDD(DUK_DDDPRINT("switch statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK); /* don't allow continue */ + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK); /* don't allow continue */ duk__parse_switch_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -6633,12 +6677,10 @@ DUK_DDD(DUK_DDDPRINT("expression statement")); duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - single_token = (comp_ctx->curr_func.nud_count == 1 && /* one token */ - comp_ctx->curr_func.led_count == 0); /* no operators */ + single_token = (comp_ctx->curr_func.nud_count == 1 && /* one token */ + comp_ctx->curr_func.led_count == 0); /* no operators */ - if (single_token && - comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->curr_token.t == DUK_TOK_COLON) { + if (single_token && comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->curr_token.t == DUK_TOK_COLON) { /* * Detected label */ @@ -6652,17 +6694,13 @@ h_lab = comp_ctx->prev_token.str1; DUK_ASSERT(h_lab != NULL); - DUK_DDD(DUK_DDDPRINT("explicit label site for label '%!O'", - (duk_heaphdr *) h_lab)); + DUK_DDD(DUK_DDDPRINT("explicit label site for label '%!O'", (duk_heaphdr *) h_lab)); - duk__advance(comp_ctx); /* eat colon */ + duk__advance(comp_ctx); /* eat colon */ label_id = duk__stmt_label_site(comp_ctx, label_id); - duk__add_label(comp_ctx, - h_lab, - pc_at_entry /*pc_label*/, - label_id); + duk__add_label(comp_ctx, h_lab, pc_at_entry /*pc_label*/, label_id); /* a statement following a label cannot be a source element * (a function declaration). @@ -6675,8 +6713,8 @@ stmt_flags = 0; - if (dir_prol_at_entry && /* still in prologue */ - single_token && /* single string token */ + if (dir_prol_at_entry && /* still in prologue */ + single_token && /* single string token */ comp_ctx->prev_token.t == DUK_TOK_STRING) { /* * Detected a directive @@ -6709,7 +6747,8 @@ DUK_STRCMP((const char *) DUK_HSTRING_GET_DATA(h_dir), "use strict") == 0) { #if defined(DUK_USE_STRICT_DECL) DUK_DDD(DUK_DDDPRINT("use strict directive detected: strict flag %ld -> %ld", - (long) comp_ctx->curr_func.is_strict, (long) 1)); + (long) comp_ctx->curr_func.is_strict, + (long) 1)); comp_ctx->curr_func.is_strict = 1; #else DUK_DDD(DUK_DDDPRINT("use strict detected but strict declarations disabled, ignoring")); @@ -6717,21 +6756,23 @@ } else if (DUK_HSTRING_GET_BYTELEN(h_dir) == 14 && DUK_STRCMP((const char *) DUK_HSTRING_GET_DATA(h_dir), "use duk notail") == 0) { DUK_DDD(DUK_DDDPRINT("use duk notail directive detected: notail flag %ld -> %ld", - (long) comp_ctx->curr_func.is_notail, (long) 1)); + (long) comp_ctx->curr_func.is_notail, + (long) 1)); comp_ctx->curr_func.is_notail = 1; } else { DUK_DD(DUK_DDPRINT("unknown directive: '%!O', ignoring but not terminating " - "directive prologue", (duk_hobject *) h_dir)); + "directive prologue", + (duk_hobject *) h_dir)); } } } else { DUK_DDD(DUK_DDDPRINT("non-directive expression statement or no longer in prologue; " "prologue terminated if still active")); - } + } stmt_flags |= DUK__HAS_VAL | DUK__HAS_TERM; } - } /* end switch (tok) */ + } /* end switch (tok) */ /* * Statement value handling. @@ -6807,9 +6848,7 @@ */ if (label_id >= 0) { - duk__emit_bc(comp_ctx, - DUK_OP_ENDLABEL, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, DUK_OP_ENDLABEL, (duk_regconst_t) label_id); } DUK__SETTEMP(comp_ctx, temp_at_entry); @@ -6832,7 +6871,10 @@ * (EOF or closing brace). */ -DUK_LOCAL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, duk_bool_t allow_source_elem, duk_bool_t expect_eof, duk_bool_t regexp_after) { +DUK_LOCAL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, + duk_bool_t allow_source_elem, + duk_bool_t expect_eof, + duk_bool_t regexp_after) { duk_hthread *thr = comp_ctx->thr; duk_ivalue res_alloc; duk_ivalue *res = &res_alloc; @@ -6998,7 +7040,7 @@ /* only functions can have arguments */ DUK_ASSERT(comp_ctx->curr_func.is_function); - duk_push_uarridx(thr, i); /* -> ... name index */ + duk_push_uarridx(thr, i); /* -> ... name index */ duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* -> ... */ /* no code needs to be emitted, the regs already have values */ @@ -7034,16 +7076,15 @@ */ num_decls = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); - DUK_DDD(DUK_DDDPRINT("num_decls=%ld -> %!T", - (long) num_decls, - (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.decls_idx))); + DUK_DDD( + DUK_DDDPRINT("num_decls=%ld -> %!T", (long) num_decls, (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.decls_idx))); for (i = 0; i < num_decls; i += 2) { duk_int_t decl_type; duk_int_t fnum; - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ decl_type = duk_to_int(thr, -1); - fnum = decl_type >> 8; /* XXX: macros */ + fnum = decl_type >> 8; /* XXX: macros */ decl_type = decl_type & 0xff; duk_pop(thr); @@ -7051,7 +7092,7 @@ continue; } - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ /* XXX: spilling */ if (comp_ctx->curr_func.is_function) { @@ -7061,18 +7102,12 @@ /* shadowed; update value */ duk_dup_top(thr); duk_get_prop(thr, comp_ctx->curr_func.varmap_idx); - reg_bind = duk_to_int(thr, -1); /* ... name reg_bind */ - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_bind, - (duk_regconst_t) fnum); + reg_bind = duk_to_int(thr, -1); /* ... name reg_bind */ + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_bind, (duk_regconst_t) fnum); } else { /* function: always register bound */ reg_bind = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_bind, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_bind, (duk_regconst_t) fnum); duk_push_int(thr, (duk_int_t) reg_bind); } } else { @@ -7089,14 +7124,9 @@ rc_name = duk__getconst(comp_ctx); duk_push_null(thr); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp, - (duk_regconst_t) fnum); - - declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE | - DUK_BC_DECLVAR_FLAG_FUNC_DECL; + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp, (duk_regconst_t) fnum); + + declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_BC_DECLVAR_FLAG_FUNC_DECL; if (configurable_bindings) { declvar_flags |= DUK_PROPDESC_FLAG_CONFIGURABLE; @@ -7108,7 +7138,7 @@ rc_name /*name*/, reg_temp /*value*/); - DUK__SETTEMP(comp_ctx, reg_temp); /* forget temp */ + DUK__SETTEMP(comp_ctx, reg_temp); /* forget temp */ } DUK_DDD(DUK_DDDPRINT("function declaration to varmap: %!T -> %!T", @@ -7118,7 +7148,7 @@ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_NULL(duk_get_tval(thr, -1)) || DUK_TVAL_IS_FASTINT(duk_get_tval(thr, -1))); #endif - duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ + duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ } /* @@ -7145,7 +7175,7 @@ for (i = 0; i < num_decls; i += 2) { duk_int_t decl_type; - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ decl_type = duk_to_int(thr, -1); decl_type = decl_type & 0xff; duk_pop(thr); @@ -7154,16 +7184,15 @@ continue; } - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ if (duk_has_prop(thr, comp_ctx->curr_func.varmap_idx)) { /* shadowed, ignore */ } else { - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ h_name = duk_known_hstring(thr, -1); - if (h_name == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr) && - !comp_ctx->curr_func.is_arguments_shadowed) { + if (h_name == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr) && !comp_ctx->curr_func.is_arguments_shadowed) { /* E5 Section steps 7-8 */ DUK_DDD(DUK_DDDPRINT("'arguments' not shadowed by a function declaration, " "but appears as a variable declaration -> treat as " @@ -7182,8 +7211,7 @@ rc_name = duk__getconst(comp_ctx); duk_push_null(thr); - declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE; + declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE; if (configurable_bindings) { declvar_flags |= DUK_PROPDESC_FLAG_CONFIGURABLE; } @@ -7195,7 +7223,7 @@ 0 /*value*/); } - duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ + duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ } } @@ -7210,11 +7238,11 @@ DUK_ASSERT_TOP(thr, entry_top); return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); - error_argname: +error_argname: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_ARG_NAME); DUK_WO_NORETURN(return;); } @@ -7253,7 +7281,11 @@ * token (EOF or closing brace). */ -DUK_LOCAL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, duk_bool_t expect_eof, duk_bool_t implicit_return_value, duk_bool_t regexp_after, duk_small_int_t expect_token) { +DUK_LOCAL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, + duk_bool_t expect_eof, + duk_bool_t implicit_return_value, + duk_bool_t regexp_after, + duk_small_int_t expect_token) { duk_compiler_func *func; duk_hthread *thr; duk_regconst_t reg_stmt_value = -1; @@ -7345,8 +7377,8 @@ DUK_DDD(DUK_DDDPRINT("begin 1st pass")); duk__parse_stmts(comp_ctx, - 1, /* allow source elements */ - expect_eof, /* expect EOF instead of } */ + 1, /* allow source elements */ + expect_eof, /* expect EOF instead of } */ regexp_after); /* regexp after */ DUK_DDD(DUK_DDDPRINT("end 1st pass")); @@ -7375,8 +7407,8 @@ DUK_DDD(DUK_DDDPRINT("rewind lexer")); DUK_LEXER_SETPOINT(&comp_ctx->lex, &lex_pt); - comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ duk__advance(comp_ctx); /* @@ -7397,8 +7429,7 @@ /* must be able to emit code, alloc consts, etc. */ - duk__init_varmap_and_prologue_for_pass2(comp_ctx, - (implicit_return_value ? ®_stmt_value : NULL)); + duk__init_varmap_and_prologue_for_pass2(comp_ctx, (implicit_return_value ? ®_stmt_value : NULL)); func->reg_stmt_value = reg_stmt_value; temp_first = DUK__GETTEMP(comp_ctx); @@ -7446,15 +7477,13 @@ if (implicit_return_value) { /* Default implicit return value. */ - duk__emit_bc(comp_ctx, - DUK_OP_LDUNDEF, - 0); + duk__emit_bc(comp_ctx, DUK_OP_LDUNDEF, 0); } DUK_DDD(DUK_DDDPRINT("begin 2nd pass")); duk__parse_stmts(comp_ctx, - 1, /* allow source elements */ - expect_eof, /* expect EOF instead of } */ + 1, /* allow source elements */ + expect_eof, /* expect EOF instead of } */ regexp_after); /* regexp after */ DUK_DDD(DUK_DDDPRINT("end 2nd pass")); @@ -7510,7 +7539,7 @@ DUK__RECURSION_DECREASE(comp_ctx, thr); return; - error_funcname: +error_funcname: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_FUNC_NAME); DUK_WO_NORETURN(return;); } @@ -7565,15 +7594,14 @@ } DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_IDENTIFIER); DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); - DUK_DDD(DUK_DDDPRINT("formal argument: %!O", - (duk_heaphdr *) comp_ctx->curr_token.str1)); + DUK_DDD(DUK_DDDPRINT("formal argument: %!O", (duk_heaphdr *) comp_ctx->curr_token.str1)); /* XXX: append primitive */ duk_push_hstring(thr, comp_ctx->curr_token.str1); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.argnames_idx); duk_put_prop_index(thr, comp_ctx->curr_func.argnames_idx, n); - duk__advance(comp_ctx); /* eat identifier */ + duk__advance(comp_ctx); /* eat identifier */ } } @@ -7621,7 +7649,7 @@ if (flags & DUK__FUNC_FLAG_GETSET) { /* PropertyName -> IdentifierName | StringLiteral | NumericLiteral */ if (tok->t_nores == DUK_TOK_IDENTIFIER || tok->t == DUK_TOK_STRING) { - duk_push_hstring(thr, tok->str1); /* keep in valstack */ + duk_push_hstring(thr, tok->str1); /* keep in valstack */ } else if (tok->t == DUK_TOK_NUMBER) { duk_push_number(thr, tok->num); duk_to_string(thr, -1); @@ -7629,15 +7657,15 @@ DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_GETSET_NAME); DUK_WO_NORETURN(return;); } - comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ + comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ } else { /* Function name is an Identifier (not IdentifierName), but we get * the raw name (not recognizing keywords) here and perform the name * checks only after pass 1. */ if (tok->t_nores == DUK_TOK_IDENTIFIER) { - duk_push_hstring(thr, tok->str1); /* keep in valstack */ - comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ + duk_push_hstring(thr, tok->str1); /* keep in valstack */ + comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ } else { /* valstack will be unbalanced, which is OK */ DUK_ASSERT((flags & DUK__FUNC_FLAG_GETSET) == 0); @@ -7650,8 +7678,7 @@ } } - DUK_DD(DUK_DDPRINT("function name: %!O", - (duk_heaphdr *) comp_ctx->curr_func.h_name)); + DUK_DD(DUK_DDPRINT("function name: %!O", (duk_heaphdr *) comp_ctx->curr_func.h_name)); if (!no_advance) { duk__advance(comp_ctx); @@ -7677,17 +7704,17 @@ */ duk__parse_func_body(comp_ctx, - 0, /* expect_eof */ - 0, /* implicit_return_value */ + 0, /* expect_eof */ + 0, /* implicit_return_value */ flags & DUK__FUNC_FLAG_DECL, /* regexp_after */ - DUK_TOK_LCURLY); /* expect_token */ + DUK_TOK_LCURLY); /* expect_token */ /* * Convert duk_compiler_func to a function template and add it * to the parent function table. */ - duk__convert_to_func_template(comp_ctx); /* -> ... func */ + duk__convert_to_func_template(comp_ctx); /* -> ... func */ } /* Parse an inner function, adding the function template to the current function's @@ -7725,12 +7752,14 @@ lex_pt.line = duk_to_int(thr, -1); duk_pop(thr); - DUK_DDD(DUK_DDDPRINT("second pass of an inner func, skip the function, reparse closing brace; lex offset=%ld, line=%ld", - (long) lex_pt.offset, (long) lex_pt.line)); + DUK_DDD( + DUK_DDDPRINT("second pass of an inner func, skip the function, reparse closing brace; lex offset=%ld, line=%ld", + (long) lex_pt.offset, + (long) lex_pt.line)); DUK_LEXER_SETPOINT(&comp_ctx->lex, &lex_pt); - comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ duk__advance(comp_ctx); /* RegExp is not allowed after a function expression, e.g. in @@ -7752,7 +7781,8 @@ entry_top = duk_get_top(thr); DUK_DDD(DUK_DDDPRINT("before func: entry_top=%ld, curr_tok.start_offset=%ld", - (long) entry_top, (long) comp_ctx->curr_token.start_offset)); + (long) entry_top, + (long) comp_ctx->curr_token.start_offset)); duk_memcpy(&old_func, &comp_ctx->curr_func, sizeof(duk_compiler_func)); @@ -7772,24 +7802,25 @@ DUK_ASSERT(comp_ctx->curr_func.is_eval == 0); DUK_ASSERT(comp_ctx->curr_func.is_global == 0); comp_ctx->curr_func.is_setget = ((flags & DUK__FUNC_FLAG_GETSET) != 0); - comp_ctx->curr_func.is_namebinding = !(flags & (DUK__FUNC_FLAG_GETSET | - DUK__FUNC_FLAG_METDEF | - DUK__FUNC_FLAG_DECL)); /* no name binding for: declarations, objlit getset, objlit method def */ - comp_ctx->curr_func.is_constructable = !(flags & (DUK__FUNC_FLAG_GETSET | - DUK__FUNC_FLAG_METDEF)); /* not constructable: objlit getset, objlit method def */ + comp_ctx->curr_func.is_namebinding = + !(flags & (DUK__FUNC_FLAG_GETSET | DUK__FUNC_FLAG_METDEF | + DUK__FUNC_FLAG_DECL)); /* no name binding for: declarations, objlit getset, objlit method def */ + comp_ctx->curr_func.is_constructable = + !(flags & (DUK__FUNC_FLAG_GETSET | DUK__FUNC_FLAG_METDEF)); /* not constructable: objlit getset, objlit method def */ /* * Parse inner function */ - duk__parse_func_like_raw(comp_ctx, flags); /* pushes function template */ + duk__parse_func_like_raw(comp_ctx, flags); /* pushes function template */ /* prev_token.start_offset points to the closing brace here; when skipping * we're going to reparse the closing brace to ensure semicolon insertion * etc work as expected. */ DUK_DDD(DUK_DDDPRINT("after func: prev_tok.start_offset=%ld, curr_tok.start_offset=%ld", - (long) comp_ctx->prev_token.start_offset, (long) comp_ctx->curr_token.start_offset)); + (long) comp_ctx->prev_token.start_offset, + (long) comp_ctx->curr_token.start_offset)); DUK_ASSERT(comp_ctx->lex.inputcomp_ctx->prev_token.start_offset == (duk_uint8_t) DUK_ASC_RCURLY); /* XXX: append primitive */ @@ -7875,7 +7906,7 @@ is_strict = (flags & DUK_COMPILE_STRICT ? 1 : 0); is_funcexpr = (flags & DUK_COMPILE_FUNCEXPR ? 1 : 0); - h_filename = duk_get_hstring(thr, -1); /* may be undefined */ + h_filename = duk_get_hstring(thr, -1); /* may be undefined */ /* * Init compiler and lexer contexts @@ -7893,11 +7924,11 @@ duk_require_stack(thr, DUK__COMPILE_ENTRY_SLOTS); - duk_push_dynamic_buffer(thr, 0); /* entry_top + 0 */ - duk_push_undefined(thr); /* entry_top + 1 */ - duk_push_undefined(thr); /* entry_top + 2 */ - duk_push_undefined(thr); /* entry_top + 3 */ - duk_push_undefined(thr); /* entry_top + 4 */ + duk_push_dynamic_buffer(thr, 0); /* entry_top + 0 */ + duk_push_undefined(thr); /* entry_top + 1 */ + duk_push_undefined(thr); /* entry_top + 2 */ + duk_push_undefined(thr); /* entry_top + 3 */ + duk_push_undefined(thr); /* entry_top + 4 */ comp_ctx->thr = thr; comp_ctx->h_filename = h_filename; @@ -7921,8 +7952,8 @@ lex_pt->offset = 0; lex_pt->line = 1; - DUK_LEXER_SETPOINT(&comp_ctx->lex, lex_pt); /* fills window */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + DUK_LEXER_SETPOINT(&comp_ctx->lex, lex_pt); /* fills window */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ /* * Initialize function state for a zero-argument function @@ -7938,8 +7969,7 @@ */ DUK_ASSERT(func->h_name == NULL); } else { - duk_push_hstring_stridx(thr, (is_eval ? DUK_STRIDX_EVAL : - DUK_STRIDX_GLOBAL)); + duk_push_hstring_stridx(thr, (is_eval ? DUK_STRIDX_EVAL : DUK_STRIDX_GLOBAL)); func->h_name = duk_get_hstring(thr, -1); } @@ -7959,7 +7989,7 @@ func->is_namebinding = 1; func->is_constructable = 1; - duk__advance(comp_ctx); /* init 'curr_token' */ + duk__advance(comp_ctx); /* init 'curr_token' */ duk__advance_expect(comp_ctx, DUK_TOK_FUNCTION); (void) duk__parse_func_like_raw(comp_ctx, 0 /*flags*/); } else { @@ -7971,10 +8001,10 @@ DUK_ASSERT(func->is_constructable == 0); duk__parse_func_body(comp_ctx, - 1, /* expect_eof */ - 1, /* implicit_return_value */ - 1, /* regexp_after (does not matter) */ - -1); /* expect_token */ + 1, /* expect_eof */ + 1, /* implicit_return_value */ + 1, /* regexp_after (does not matter) */ + -1); /* expect_token */ } /* @@ -8006,14 +8036,14 @@ DUK_LEXER_INITCTX(&comp_stk.comp_ctx_alloc.lex); comp_stk.comp_ctx_alloc.lex.input = src_buffer; comp_stk.comp_ctx_alloc.lex.input_length = src_length; - comp_stk.comp_ctx_alloc.lex.flags = flags; /* Forward flags directly for now. */ + comp_stk.comp_ctx_alloc.lex.flags = flags; /* Forward flags directly for now. */ /* ... filename */ prev_ctx = thr->compile_ctx; - thr->compile_ctx = &comp_stk.comp_ctx_alloc; /* for duk_error_augment.c */ + thr->compile_ctx = &comp_stk.comp_ctx_alloc; /* for duk_error_augment.c */ safe_rc = duk_safe_call(thr, duk__js_compile_raw, (void *) &comp_stk /*udata*/, 1 /*nargs*/, 1 /*nrets*/); - thr->compile_ctx = prev_ctx; /* must restore reliably before returning */ + thr->compile_ctx = prev_ctx; /* must restore reliably before returning */ if (safe_rc != DUK_EXEC_SUCCESS) { DUK_D(DUK_DPRINT("compilation failed: %!T", duk_get_tval(thr, -1)));
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_js_compiler.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_js_compiler.h
Changed
@@ -6,13 +6,13 @@ #define DUK_JS_COMPILER_H_INCLUDED /* ECMAScript compiler limits */ -#define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */ +#define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */ /* maximum loopcount for peephole optimization */ -#define DUK_COMPILER_PEEPHOLE_MAXITER 3 +#define DUK_COMPILER_PEEPHOLE_MAXITER 3 /* maximum bytecode length in instructions */ -#define DUK_COMPILER_MAX_BYTECODE_LENGTH (256L * 1024L * 1024L) /* 1 GB */ +#define DUK_COMPILER_MAX_BYTECODE_LENGTH (256L * 1024L * 1024L) /* 1 GB */ /* * Compiler intermediate values @@ -22,21 +22,21 @@ * either a left-hand-side or right-hand-side role (e.g. object property). */ -#define DUK_IVAL_NONE 0 /* no value */ -#define DUK_IVAL_PLAIN 1 /* register, constant, or value */ -#define DUK_IVAL_ARITH 2 /* binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops */ -#define DUK_IVAL_PROP 3 /* property access */ -#define DUK_IVAL_VAR 4 /* variable access */ +#define DUK_IVAL_NONE 0 /* no value */ +#define DUK_IVAL_PLAIN 1 /* register, constant, or value */ +#define DUK_IVAL_ARITH 2 /* binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops */ +#define DUK_IVAL_PROP 3 /* property access */ +#define DUK_IVAL_VAR 4 /* variable access */ -#define DUK_ISPEC_NONE 0 /* no value */ -#define DUK_ISPEC_VALUE 1 /* value resides in 'valstack_idx' */ -#define DUK_ISPEC_REGCONST 2 /* value resides in a register or constant */ +#define DUK_ISPEC_NONE 0 /* no value */ +#define DUK_ISPEC_VALUE 1 /* value resides in 'valstack_idx' */ +#define DUK_ISPEC_REGCONST 2 /* value resides in a register or constant */ /* Bit mask which indicates that a regconst is a constant instead of a register. * Chosen so that when a regconst is cast to duk_int32_t, all consts are * negative values. */ -#define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */ +#define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */ /* Type to represent a reg/const reference during compilation, with <0 * indicating a constant. Some call sites also use -1 to indicate 'none'. @@ -44,9 +44,9 @@ typedef duk_int32_t duk_regconst_t; typedef struct { - duk_small_uint_t t; /* DUK_ISPEC_XXX */ + duk_small_uint_t t; /* DUK_ISPEC_XXX */ duk_regconst_t regconst; - duk_idx_t valstack_idx; /* always set; points to a reserved valstack slot */ + duk_idx_t valstack_idx; /* always set; points to a reserved valstack slot */ } duk_ispec; typedef struct { @@ -58,8 +58,8 @@ */ /* XXX: can be optimized for smaller footprint esp. on 32-bit environments */ - duk_small_uint_t t; /* DUK_IVAL_XXX */ - duk_small_uint_t op; /* bytecode opcode for binary ops */ + duk_small_uint_t t; /* DUK_IVAL_XXX */ + duk_small_uint_t op; /* bytecode opcode for binary ops */ duk_ispec x1; duk_ispec x2; } duk_ivalue; @@ -81,22 +81,22 @@ * Compiler state */ -#define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0) -#define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1) +#define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0) +#define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1) -#define DUK_DECL_TYPE_VAR 0 -#define DUK_DECL_TYPE_FUNC 1 +#define DUK_DECL_TYPE_VAR 0 +#define DUK_DECL_TYPE_FUNC 1 /* XXX: optimize to 16 bytes */ typedef struct { duk_small_uint_t flags; - duk_int_t label_id; /* numeric label_id (-1 reserved as marker) */ - duk_hstring *h_label; /* borrowed label name */ - duk_int_t catch_depth; /* catch depth at point of definition */ - duk_int_t pc_label; /* pc of label statement: - * pc+1: break jump site - * pc+2: continue jump site - */ + duk_int_t label_id; /* numeric label_id (-1 reserved as marker) */ + duk_hstring *h_label; /* borrowed label name */ + duk_int_t catch_depth; /* catch depth at point of definition */ + duk_int_t pc_label; /* pc of label statement: + * pc+1: break jump site + * pc+2: continue jump site + */ /* Fast jumps (which avoid longjmp) jump directly to the jump sites * which are always known even while the iteration/switch statement @@ -112,22 +112,22 @@ * platforms (e.g. if int is 32 bits and pointers are 64 bits). */ - duk_bufwriter_ctx bw_code; /* bufwriter for code */ + duk_bufwriter_ctx bw_code; /* bufwriter for code */ - duk_hstring *h_name; /* function name (borrowed reference), ends up in _name */ + duk_hstring *h_name; /* function name (borrowed reference), ends up in _name */ /* h_code: held in bw_code */ - duk_hobject *h_consts; /* array */ - duk_hobject *h_funcs; /* array of function templates: func1, offset1, line1, func2, offset2, line2 - * offset/line points to closing brace to allow skipping on pass 2 - */ - duk_hobject *h_decls; /* array of declarations: name1, val1, name2, val2, ... - * valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars) - * record function and variable declarations in pass 1 - */ - duk_hobject *h_labelnames; /* array of active label names */ - duk_hbuffer_dynamic *h_labelinfos; /* C array of duk_labelinfo */ - duk_hobject *h_argnames; /* array of formal argument names (-> _Formals) */ - duk_hobject *h_varmap; /* variable map for pass 2 (identifier -> register number or null (unmapped)) */ + duk_hobject *h_consts; /* array */ + duk_hobject *h_funcs; /* array of function templates: func1, offset1, line1, func2, offset2, line2 + * offset/line points to closing brace to allow skipping on pass 2 + */ + duk_hobject *h_decls; /* array of declarations: name1, val1, name2, val2, ... + * valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars) + * record function and variable declarations in pass 1 + */ + duk_hobject *h_labelnames; /* array of active label names */ + duk_hbuffer_dynamic *h_labelinfos; /* C array of duk_labelinfo */ + duk_hobject *h_argnames; /* array of formal argument names (-> _Formals) */ + duk_hobject *h_varmap; /* variable map for pass 2 (identifier -> register number or null (unmapped)) */ /* Value stack indices for tracking objects. */ /* code_idx: not needed */ @@ -140,9 +140,9 @@ duk_idx_t varmap_idx; /* Temp reg handling. */ - duk_regconst_t temp_first; /* first register that is a temporary (below: variables) */ - duk_regconst_t temp_next; /* next temporary register to allocate */ - duk_regconst_t temp_max; /* highest value of temp_reg (temp_max - 1 is highest used reg) */ + duk_regconst_t temp_first; /* first register that is a temporary (below: variables) */ + duk_regconst_t temp_next; /* next temporary register to allocate */ + duk_regconst_t temp_max; /* highest value of temp_reg (temp_max - 1 is highest used reg) */ /* Shuffle registers if large number of regs/consts. */ duk_regconst_t shuffle1; @@ -152,49 +152,51 @@ /* Stats for current expression being parsed. */ duk_int_t nud_count; duk_int_t led_count; - duk_int_t paren_level; /* parenthesis count, 0 = top level */ - duk_bool_t expr_lhs; /* expression is left-hand-side compatible */ - duk_bool_t allow_in; /* current paren level allows 'in' token */ + duk_int_t paren_level; /* parenthesis count, 0 = top level */ + duk_bool_t expr_lhs; /* expression is left-hand-side compatible */ + duk_bool_t allow_in; /* current paren level allows 'in' token */ /* Misc. */ - duk_int_t stmt_next; /* statement id allocation (running counter) */ - duk_int_t label_next; /* label id allocation (running counter) */ - duk_int_t catch_depth; /* catch stack depth */ - duk_int_t with_depth; /* with stack depth (affects identifier lookups) */ - duk_int_t fnum_next; /* inner function numbering */ - duk_int_t num_formals; /* number of formal arguments */ - duk_regconst_t reg_stmt_value; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */ + duk_int_t stmt_next; /* statement id allocation (running counter) */ + duk_int_t label_next; /* label id allocation (running counter) */ + duk_int_t catch_depth; /* catch stack depth */ + duk_int_t with_depth; /* with stack depth (affects identifier lookups) */ + duk_int_t fnum_next; /* inner function numbering */ + duk_int_t num_formals; /* number of formal arguments */ + duk_regconst_t + reg_stmt_value; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */ #if defined(DUK_USE_DEBUGGER_SUPPORT) - duk_int_t min_line; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */ + duk_int_t min_line; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */ duk_int_t max_line; #endif /* Status booleans. */ - duk_uint8_t is_function; /* is an actual function (not global/eval code) */ - duk_uint8_t is_eval; /* is eval code */ - duk_uint8_t is_global; /* is global code */ - duk_uint8_t is_namebinding; /* needs a name binding */ - duk_uint8_t is_constructable; /* result is constructable */ - duk_uint8_t is_setget; /* is a setter/getter */ - duk_uint8_t is_strict; /* function is strict */ - duk_uint8_t is_notail; /* function must not be tail called */ - duk_uint8_t in_directive_prologue; /* parsing in "directive prologue", recognize directives */ - duk_uint8_t in_scanning; /* parsing in "scanning" phase (first pass) */ - duk_uint8_t may_direct_eval; /* function may call direct eval */ - duk_uint8_t id_access_arguments; /* function refers to 'arguments' identifier */ - duk_uint8_t id_access_slow; /* function makes one or more slow path accesses that won't match own static variables */ - duk_uint8_t id_access_slow_own; /* function makes one or more slow path accesses that may match own static variables */ - duk_uint8_t is_arguments_shadowed; /* argument/function declaration shadows 'arguments' */ - duk_uint8_t needs_shuffle; /* function needs shuffle registers */ - duk_uint8_t reject_regexp_in_adv; /* reject RegExp literal on next advance() call; needed for handling IdentifierName productions */ - duk_uint8_t allow_regexp_in_adv; /* allow RegExp literal on next advance() call */ + duk_uint8_t is_function; /* is an actual function (not global/eval code) */ + duk_uint8_t is_eval; /* is eval code */ + duk_uint8_t is_global; /* is global code */ + duk_uint8_t is_namebinding; /* needs a name binding */ + duk_uint8_t is_constructable; /* result is constructable */ + duk_uint8_t is_setget; /* is a setter/getter */ + duk_uint8_t is_strict; /* function is strict */ + duk_uint8_t is_notail; /* function must not be tail called */ + duk_uint8_t in_directive_prologue; /* parsing in "directive prologue", recognize directives */ + duk_uint8_t in_scanning; /* parsing in "scanning" phase (first pass) */ + duk_uint8_t may_direct_eval; /* function may call direct eval */ + duk_uint8_t id_access_arguments; /* function refers to 'arguments' identifier */ + duk_uint8_t id_access_slow; /* function makes one or more slow path accesses that won't match own static variables */ + duk_uint8_t id_access_slow_own; /* function makes one or more slow path accesses that may match own static variables */ + duk_uint8_t is_arguments_shadowed; /* argument/function declaration shadows 'arguments' */ + duk_uint8_t needs_shuffle; /* function needs shuffle registers */ + duk_uint8_t + reject_regexp_in_adv; /* reject RegExp literal on next advance() call; needed for handling IdentifierName productions */ + duk_uint8_t allow_regexp_in_adv; /* allow RegExp literal on next advance() call */ }; struct duk_compiler_ctx { duk_hthread *thr; /* filename being compiled (ends up in functions' '_filename' property) */ - duk_hstring *h_filename; /* borrowed reference */ + duk_hstring *h_filename; /* borrowed reference */ /* lexing (tokenization) state (contains two valstack slot indices) */ duk_lexer_ctx lex; @@ -202,10 +204,10 @@ /* current and previous token for parsing */ duk_token prev_token; duk_token curr_token; - duk_idx_t tok11_idx; /* curr_token slot1 (matches 'lex' slot1_idx) */ - duk_idx_t tok12_idx; /* curr_token slot2 (matches 'lex' slot2_idx) */ - duk_idx_t tok21_idx; /* prev_token slot1 */ - duk_idx_t tok22_idx; /* prev_token slot2 */ + duk_idx_t tok11_idx; /* curr_token slot1 (matches 'lex' slot1_idx) */ + duk_idx_t tok12_idx; /* curr_token slot2 (matches 'lex' slot2_idx) */ + duk_idx_t tok21_idx; /* prev_token slot1 */ + duk_idx_t tok22_idx; /* prev_token slot2 */ /* recursion limit */ duk_int_t recursion_depth; @@ -222,6 +224,9 @@ * Prototypes */ -DUK_INTERNAL_DECL void duk_js_compile(duk_hthread *thr, const duk_uint8_t *src_buffer, duk_size_t src_length, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_js_compile(duk_hthread *thr, + const duk_uint8_t *src_buffer, + duk_size_t src_length, + duk_small_uint_t flags); -#endif /* DUK_JS_COMPILER_H_INCLUDED */ +#endif /* DUK_JS_COMPILER_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_js_executor.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_js_executor.c
Changed
@@ -17,7 +17,8 @@ /* Replace value stack top to value at 'tv_ptr'. Optimize for * performance by only applying the net refcount change. */ -#define DUK__REPLACE_TO_TVPTR(thr,tv_ptr) do { \ +#define DUK__REPLACE_TO_TVPTR(thr, tv_ptr) \ + do { \ duk_hthread *duk__thr; \ duk_tval *duk__tvsrc; \ duk_tval *duk__tvdst; \ @@ -27,13 +28,13 @@ duk__tvdst = (tv_ptr); \ DUK_TVAL_SET_TVAL(&duk__tvtmp, duk__tvdst); \ DUK_TVAL_SET_TVAL(duk__tvdst, duk__tvsrc); \ - DUK_TVAL_SET_UNDEFINED(duk__tvsrc); /* value stack init policy */ \ + DUK_TVAL_SET_UNDEFINED(duk__tvsrc); /* value stack init policy */ \ duk__thr->valstack_top = duk__tvsrc; \ DUK_TVAL_DECREF(duk__thr, &duk__tvtmp); \ } while (0) /* XXX: candidate of being an internal shared API call */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__push_tvals_incref_only(duk_hthread *thr, duk_tval *tv_src, duk_small_uint_fast_t count) { duk_tval *tv_dst; duk_size_t copy_size; @@ -75,7 +76,10 @@ } #endif -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_add(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_fast_t idx_z) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_add(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_small_uint_fast_t idx_z) { /* * Addition operator is different from other arithmetic * operations in that it also provides string concatenation. @@ -95,9 +99,9 @@ duk_double_union du; DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); /* @@ -120,14 +124,14 @@ v3_hi = (duk_int32_t) (v3 >> 32); if (DUK_LIKELY(v3_hi >= DUK_I64_CONSTANT(-0x8000) && v3_hi <= DUK_I64_CONSTANT(0x7fff))) { tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ return; } else { /* overflow, fall through */ ; } } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { #if !defined(DUK_USE_EXEC_PREFER_SIZE) @@ -136,14 +140,14 @@ du.d = DUK_TVAL_GET_NUMBER(tv_x) + DUK_TVAL_GET_NUMBER(tv_y); #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ return; } @@ -153,7 +157,7 @@ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -2, DUK_HINT_NONE); /* side effects -> don't use tv_x, tv_y after */ + duk_to_primitive(thr, -2, DUK_HINT_NONE); /* side effects -> don't use tv_x, tv_y after */ duk_to_primitive(thr, -1, DUK_HINT_NONE); /* Since Duktape 2.x plain buffers are treated like ArrayBuffer. */ @@ -164,7 +168,7 @@ * in duk_concat_2() which also fails with TypeError so no * explicit check is needed. */ - duk_concat_2(thr); /* ... s1 s2 -> ... s1+s2 */ + duk_concat_2(thr); /* ... s1 s2 -> ... s1+s2 */ } else { duk_double_t d1, d2; @@ -177,12 +181,16 @@ du.d = d1 + d2; duk_pop_2_unsafe(thr); - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ } - duk_replace(thr, (duk_idx_t) idx_z); /* side effects */ + duk_replace(thr, (duk_idx_t) idx_z); /* side effects */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_binary_op(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_uint_fast_t idx_z, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_binary_op(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_uint_fast_t idx_z, + duk_small_uint_fast_t opcode) { /* * Arithmetic operations other than '+' have number-only semantics * and are implemented here. The separate switch-case here means a @@ -199,12 +207,12 @@ #endif DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); - opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ + opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y)) { @@ -271,13 +279,13 @@ v3_hi = (duk_int32_t) (v3 >> 32); if (DUK_LIKELY(v3_hi >= DUK_I64_CONSTANT(-0x8000) && v3_hi <= DUK_I64_CONSTANT(0x7fff))) { tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ return; } /* fall through if overflow etc */ } - skip_fastint: -#endif /* DUK_USE_FASTINT */ +skip_fastint: +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { /* fast path */ @@ -286,7 +294,7 @@ } else { duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - d1 = duk_to_number_m2(thr); /* side effects */ + d1 = duk_to_number_m2(thr); /* side effects */ d2 = duk_to_number_m1(thr); DUK_ASSERT(duk_is_number(thr, -2)); DUK_ASSERT(duk_is_number(thr, -1)); @@ -323,24 +331,28 @@ #endif default: { DUK_UNREACHABLE(); - du.d = DUK_DOUBLE_NAN; /* should not happen */ + du.d = DUK_DOUBLE_NAN; /* should not happen */ break; } } #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ /* important to use normalized NaN with 8-byte tagged types */ DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_bitwise_binary_op(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_fast_t idx_z, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_bitwise_binary_op(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_small_uint_fast_t idx_z, + duk_small_uint_fast_t opcode) { /* * Binary bitwise operations use different coercions (ToInt32, ToUint32) * depending on the operation. We coerce the arguments first using @@ -364,20 +376,19 @@ #endif DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); - opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ + opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y)) { i1 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv_x); i2 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv_y); - } - else -#endif /* DUK_USE_FASTINT */ + } else +#endif /* DUK_USE_FASTINT */ { duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); @@ -406,15 +417,15 @@ */ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; - i3 = (duk_int32_t) (((duk_uint32_t) i1) << (u2 & 0x1fUL)); /* E5 Section 11.7.1, steps 7 and 8 */ - i3 = i3 & ((duk_int32_t) 0xffffffffUL); /* Note: left shift, should mask */ + i3 = (duk_int32_t) (((duk_uint32_t) i1) << (u2 & 0x1fUL)); /* E5 Section 11.7.1, steps 7 and 8 */ + i3 = i3 & ((duk_int32_t) 0xffffffffUL); /* Note: left shift, should mask */ break; } case DUK_OP_BASR >> 2: { /* signed shift */ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; - i3 = i1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ + i3 = i1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ break; } case DUK_OP_BLSR >> 2: { @@ -424,7 +435,7 @@ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; /* special result value handling */ - u3 = u1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ + u3 = u1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ #if defined(DUK_USE_FASTINT) fi3 = (duk_int64_t) u3; goto fastint_result_set; @@ -435,7 +446,7 @@ } default: { DUK_UNREACHABLE(); - i3 = 0; /* should not happen */ + i3 = 0; /* should not happen */ break; } } @@ -447,28 +458,31 @@ */ fi3 = (duk_int64_t) i3; - fastint_result_set: +fastint_result_set: tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, fi3); /* side effects */ -#else /* DUK_USE_FASTINT */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, fi3); /* side effects */ +#else /* DUK_USE_FASTINT */ d3 = (duk_double_t) i3; - result_set: - DUK_ASSERT(!DUK_ISNAN(d3)); /* 'd3' is never NaN, so no need to normalize */ - DUK_ASSERT_DOUBLE_IS_NORMALIZED(d3); /* always normalized */ +result_set: + DUK_ASSERT(!DUK_ISNAN(d3)); /* 'd3' is never NaN, so no need to normalize */ + DUK_ASSERT_DOUBLE_IS_NORMALIZED(d3); /* always normalized */ #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, d3); /* would NaN normalize result, but unnecessary */ + duk_push_number(thr, d3); /* would NaN normalize result, but unnecessary */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, d3); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ -#endif /* DUK_USE_FASTINT */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, d3); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_FASTINT */ } /* In-place unary operation. */ -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_unary_op(duk_hthread *thr, duk_uint_fast_t idx_src, duk_uint_fast_t idx_dst, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_unary_op(duk_hthread *thr, + duk_uint_fast_t idx_src, + duk_uint_fast_t idx_dst, + duk_small_uint_fast_t opcode) { /* * Arithmetic operations other than '+' have number-only semantics * and are implemented here. The separate switch-case here means a @@ -514,12 +528,12 @@ } /* fall through if overflow etc */ } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv)) { d1 = DUK_TVAL_GET_NUMBER(tv); } else { - d1 = duk_to_number_tval(thr, tv); /* side effects */ + d1 = duk_to_number_tval(thr, tv); /* side effects */ } if (opcode == DUK_OP_UNP) { @@ -530,13 +544,13 @@ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); #if defined(DUK_USE_FASTINT) tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); - DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF(thr, tv, du.d); /* always 'fast', i.e. inlined */ + DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF(thr, tv, du.d); /* always 'fast', i.e. inlined */ return; #endif } else { DUK_ASSERT(opcode == DUK_OP_UNM); du.d = -d1; - DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); /* mandatory if du.d is a NaN */ + DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); /* mandatory if du.d is a NaN */ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); } @@ -564,19 +578,18 @@ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv)) { i1 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv); - } - else -#endif /* DUK_USE_FASTINT */ + } else +#endif /* DUK_USE_FASTINT */ { duk_push_tval(thr, tv); - i1 = duk_to_int32(thr, -1); /* side effects */ + i1 = duk_to_int32(thr, -1); /* side effects */ duk_pop_unsafe(thr); } /* Result is always fastint compatible. */ i2 = ~i1; tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); - DUK_TVAL_SET_I32_UPDREF(thr, tv, i2); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv, i2); /* side effects */ } DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_logical_not(duk_hthread *thr, duk_uint_fast_t idx_src, duk_uint_fast_t idx_dst) { @@ -598,16 +611,19 @@ * duk_js_toboolean() and then push+replace to the result slot. */ tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_src); - res = duk_js_toboolean(tv); /* does not modify 'tv' */ + res = duk_js_toboolean(tv); /* does not modify 'tv' */ DUK_ASSERT(res == 0 || res == 1); res ^= 1; tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); /* XXX: size optimize: push+replace? */ - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, res); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, res); /* side effects */ } /* XXX: size optimized variant */ -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_reg_helper(duk_hthread *thr, duk_tval *tv_dst, duk_tval *tv_src, duk_small_uint_t op) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_reg_helper(duk_hthread *thr, + duk_tval *tv_dst, + duk_tval *tv_src, + duk_small_uint_t op) { duk_double_t x, y, z; /* Two lowest bits of opcode are used to distinguish @@ -634,13 +650,13 @@ y_fi = x_fi + 1; } - DUK_TVAL_SET_FASTINT(tv_src, y_fi); /* no need for refcount update */ + DUK_TVAL_SET_FASTINT(tv_src, y_fi); /* no need for refcount update */ z_fi = (op & 0x02) ? x_fi : y_fi; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_dst, z_fi); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_dst, z_fi); /* side effects */ return; } - skip_fastint: +skip_fastint: #endif if (DUK_TVAL_IS_NUMBER(tv_src)) { /* Fast path for the case where the register @@ -654,7 +670,7 @@ y = x + 1.0; } - DUK_TVAL_SET_NUMBER(tv_src, y); /* no need for refcount update */ + DUK_TVAL_SET_NUMBER(tv_src, y); /* no need for refcount update */ } else { /* Preserve duk_tval pointer(s) across a potential valstack * resize by converting them into offsets temporarily. @@ -663,8 +679,8 @@ duk_size_t off_dst; off_dst = (duk_size_t) ((duk_uint8_t *) tv_dst - (duk_uint8_t *) thr->valstack_bottom); - bc = (duk_idx_t) (tv_src - thr->valstack_bottom); /* XXX: pass index explicitly? */ - tv_src = NULL; /* no longer referenced */ + bc = (duk_idx_t) (tv_src - thr->valstack_bottom); /* XXX: pass index explicitly? */ + tv_src = NULL; /* no longer referenced */ x = duk_to_number(thr, bc); if (op & 0x01) { @@ -680,10 +696,14 @@ } z = (op & 0x02) ? x : y; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_dst, z); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_dst, z); /* side effects */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_var_helper(duk_hthread *thr, duk_small_uint_t idx_dst, duk_tval *tv_id, duk_small_uint_t op, duk_small_uint_t is_strict) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_var_helper(duk_hthread *thr, + duk_small_uint_t idx_dst, + duk_tval *tv_id, + duk_small_uint_t op, + duk_small_uint_t is_strict) { duk_activation *act; duk_double_t x, y; duk_hstring *name; @@ -709,7 +729,7 @@ name = DUK_TVAL_GET_STRING(tv_id); DUK_ASSERT(name != NULL); act = thr->callstack_curr; - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ /* XXX: Fastint fast path would be useful here. Also fastints * now lose their fastint status in current handling which is @@ -726,22 +746,22 @@ /* ... x this */ if (op & 0x02) { - duk_push_number(thr, y); /* -> ... x this y */ + duk_push_number(thr, y); /* -> ... x this y */ DUK_ASSERT(act == thr->callstack_curr); duk_js_putvar_activation(thr, act, name, DUK_GET_TVAL_NEGIDX(thr, -1), is_strict); - duk_pop_2_unsafe(thr); /* -> ... x */ + duk_pop_2_unsafe(thr); /* -> ... x */ } else { - duk_pop_2_unsafe(thr); /* -> ... */ - duk_push_number(thr, y); /* -> ... y */ + duk_pop_2_unsafe(thr); /* -> ... */ + duk_push_number(thr, y); /* -> ... y */ DUK_ASSERT(act == thr->callstack_curr); duk_js_putvar_activation(thr, act, name, DUK_GET_TVAL_NEGIDX(thr, -1), is_strict); } #if defined(DUK_USE_EXEC_PREFER_SIZE) duk_replace(thr, (duk_idx_t) idx_dst); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ DUK__REPLACE_TO_TVPTR(thr, DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } /* @@ -755,11 +775,11 @@ * handled recursively. */ -#define DUK__LONGJMP_RESTART 0 /* state updated, restart bytecode execution */ -#define DUK__LONGJMP_RETHROW 1 /* exit bytecode executor by rethrowing an error to caller */ +#define DUK__LONGJMP_RESTART 0 /* state updated, restart bytecode execution */ +#define DUK__LONGJMP_RETHROW 1 /* exit bytecode executor by rethrowing an error to caller */ -#define DUK__RETHAND_RESTART 0 /* state updated, restart bytecode execution */ -#define DUK__RETHAND_FINISHED 1 /* exit bytecode execution with return value */ +#define DUK__RETHAND_RESTART 0 /* state updated, restart bytecode execution */ +#define DUK__RETHAND_FINISHED 1 /* exit bytecode execution with return value */ /* XXX: optimize reconfig valstack operations so that resize, clamp, and setting * top are combined into one pass. @@ -788,7 +808,8 @@ thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act->bottom_byteoff); DUK_ASSERT(act->retval_byteoff >= act->bottom_byteoff); - clamp_top = (duk_idx_t) ((act->retval_byteoff - act->bottom_byteoff + sizeof(duk_tval)) / sizeof(duk_tval)); /* +1 = one retval */ + clamp_top = + (duk_idx_t) ((act->retval_byteoff - act->bottom_byteoff + sizeof(duk_tval)) / sizeof(duk_tval)); /* +1 = one retval */ duk_set_top_and_wipe(thr, h_func->nregs, clamp_top); DUK_ASSERT((duk_uint8_t *) thr->valstack_end >= (duk_uint8_t *) thr->valstack + act->reserve_byteoff); @@ -818,7 +839,7 @@ thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act->bottom_byteoff); idx_bottom = (duk_size_t) (thr->valstack_bottom - thr->valstack); DUK_ASSERT(cat->idx_base >= idx_bottom); - clamp_top = (duk_idx_t) (cat->idx_base - idx_bottom + 2); /* +2 = catcher value, catcher lj_type */ + clamp_top = (duk_idx_t) (cat->idx_base - idx_bottom + 2); /* +2 = catcher value, catcher lj_type */ duk_set_top_and_wipe(thr, h_func->nregs, clamp_top); DUK_ASSERT((duk_uint8_t *) thr->valstack_end >= (duk_uint8_t *) thr->valstack + act->reserve_byteoff); @@ -846,7 +867,10 @@ DUK_TVAL_SET_U32_UPDREF_NORZ(thr, tv1, (duk_uint32_t) lj_type); } -DUK_LOCAL void duk__handle_catch_part1(duk_hthread *thr, duk_tval *tv_val_unstable, duk_small_uint_t lj_type, volatile duk_bool_t *out_delayed_catch_setup) { +DUK_LOCAL void duk__handle_catch_part1(duk_hthread *thr, + duk_tval *tv_val_unstable, + duk_small_uint_t lj_type, + volatile duk_bool_t *out_delayed_catch_setup) { duk_activation *act; duk_catcher *cat; @@ -884,7 +908,7 @@ cat = act->cat; DUK_ASSERT(cat != NULL); - act->curr_pc = cat->pc_base + 0; /* +0 = catch */ + act->curr_pc = cat->pc_base + 0; /* +0 = catch */ /* * If the catch block has an automatic catch variable binding, @@ -944,9 +968,7 @@ DUK_ASSERT(act->var_env != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(act) != NULL); - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) new_env) == NULL); @@ -964,7 +986,7 @@ duk_push_hstring(thr, cat->h_varname); DUK_ASSERT(thr->valstack + cat->idx_base < thr->valstack_top); duk_push_tval(thr, thr->valstack + cat->idx_base); - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_W); /* writable, not configurable */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_W); /* writable, not configurable */ /* ... env */ @@ -972,7 +994,7 @@ DUK_ASSERT(act != NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) new_env, act->lex_env); act->lex_env = (duk_hobject *) new_env; - DUK_HOBJECT_INCREF(thr, (duk_hobject *) new_env); /* reachable through activation */ + DUK_HOBJECT_INCREF(thr, (duk_hobject *) new_env); /* reachable through activation */ /* Net refcount change to act->lex_env is 0: incref for new_env's * prototype, decref for act->lex_env overwrite. */ @@ -1014,7 +1036,7 @@ cat = act->cat; DUK_ASSERT(cat != NULL); - act->curr_pc = cat->pc_base + 1; /* +1 = finally */ + act->curr_pc = cat->pc_base + 1; /* +1 = finally */ DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } @@ -1063,18 +1085,21 @@ act_resumer = resumer->callstack_curr; DUK_ASSERT(act_resumer != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(act_resumer) != NULL); - DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(act_resumer))); /* resume caller must be an ECMAScript func */ + DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(act_resumer))); /* resume caller must be an ECMAScript func */ - tv1 = (duk_tval *) (void *) ((duk_uint8_t *) resumer->valstack + act_resumer->retval_byteoff); /* return value from Duktape.Thread.resume() */ - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv_val_unstable); /* side effects */ /* XXX: avoid side effects */ + tv1 = (duk_tval *) (void *) ((duk_uint8_t *) resumer->valstack + + act_resumer->retval_byteoff); /* return value from Duktape.Thread.resume() */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv_val_unstable); /* side effects */ /* XXX: avoid side effects */ duk__reconfig_valstack_ecma_return(resumer); /* caller must change active thread, and set thr->resumer to NULL */ } -#endif /* DUK_USE_COROUTINE_SUPPORT */ +#endif /* DUK_USE_COROUTINE_SUPPORT */ -DUK_LOCAL duk_small_uint_t duk__handle_longjmp(duk_hthread *thr, duk_activation *entry_act, volatile duk_bool_t *out_delayed_catch_setup) { +DUK_LOCAL duk_small_uint_t duk__handle_longjmp(duk_hthread *thr, + duk_activation *entry_act, + volatile duk_bool_t *out_delayed_catch_setup) { duk_small_uint_t retval = DUK__LONGJMP_RESTART; DUK_ASSERT(thr != NULL); @@ -1095,17 +1120,16 @@ * - 'thr' must reflect the "throwing" thread */ - check_longjmp: +check_longjmp: DUK_DD(DUK_DDPRINT("handling longjmp: type=%ld, value1=%!T, value2=%!T, iserror=%ld, top=%ld", (long) thr->heap->lj.type, (duk_tval *) &thr->heap->lj.value1, (duk_tval *) &thr->heap->lj.value2, (long) thr->heap->lj.iserror, - (long) duk_get_top(thr))); + (long) duk_get_top(thr))); switch (thr->heap->lj.type) { - #if defined(DUK_USE_COROUTINE_SUPPORT) case DUK_LJ_TYPE_RESUME: { /* @@ -1119,15 +1143,15 @@ /* duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met */ - DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged by Duktape.Thread.resume() */ - DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged by Duktape.Thread.resume() */ + DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->callstack_curr))->func == duk_bi_thread_resume); - tv = &thr->heap->lj.value2; /* resumee */ + tv = &thr->heap->lj.value2; /* resumee */ DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv)); DUK_ASSERT(DUK_TVAL_GET_OBJECT(tv) != NULL); DUK_ASSERT(DUK_HOBJECT_IS_THREAD(DUK_TVAL_GET_OBJECT(tv))); @@ -1136,15 +1160,15 @@ DUK_ASSERT(resumee != NULL); DUK_ASSERT(resumee->resumer == NULL); DUK_ASSERT(resumee->state == DUK_HTHREAD_STATE_INACTIVE || - resumee->state == DUK_HTHREAD_STATE_YIELDED); /* checked by Duktape.Thread.resume() */ + resumee->state == DUK_HTHREAD_STATE_YIELDED); /* checked by Duktape.Thread.resume() */ DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_YIELDED || - resumee->callstack_top >= 2); /* YIELDED: ECMAScript activation + Duktape.Thread.yield() activation */ + resumee->callstack_top >= 2); /* YIELDED: ECMAScript activation + Duktape.Thread.yield() activation */ DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_YIELDED || (DUK_ACT_GET_FUNC(resumee->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(resumee->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(resumee->callstack_curr))->func == duk_bi_thread_yield)); DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_INACTIVE || - resumee->callstack_top == 0); /* INACTIVE: no activation, single function value on valstack */ + resumee->callstack_top == 0); /* INACTIVE: no activation, single function value on valstack */ if (thr->heap->lj.iserror) { /* @@ -1170,7 +1194,7 @@ /* thr->heap->lj.value1 is already the value to throw */ /* thr->heap->lj.value2 is 'thread', will be wiped out at the end */ - DUK_ASSERT(thr->heap->lj.iserror); /* already set */ + DUK_ASSERT(thr->heap->lj.iserror); /* already set */ DUK_DD(DUK_DDPRINT("-> resume with an error, converted to a throw in the resumee, propagate")); goto check_longjmp; @@ -1183,17 +1207,18 @@ duk_activation *act_resumee; DUK_ASSERT(resumee->callstack_top >= 2); - act_resumee = resumee->callstack_curr; /* Duktape.Thread.yield() */ + act_resumee = resumee->callstack_curr; /* Duktape.Thread.yield() */ DUK_ASSERT(act_resumee != NULL); - act_resumee = act_resumee->parent; /* ECMAScript call site for yield() */ + act_resumee = act_resumee->parent; /* ECMAScript call site for yield() */ DUK_ASSERT(act_resumee != NULL); - tv = (duk_tval *) (void *) ((duk_uint8_t *) resumee->valstack + act_resumee->retval_byteoff); /* return value from Duktape.Thread.yield() */ + tv = (duk_tval *) (void *) ((duk_uint8_t *) resumee->valstack + + act_resumee->retval_byteoff); /* return value from Duktape.Thread.yield() */ DUK_ASSERT(tv >= resumee->valstack && tv < resumee->valstack_top); tv2 = &thr->heap->lj.value1; - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv2); /* side effects */ /* XXX: avoid side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv2); /* side effects */ /* XXX: avoid side effects */ - duk_hthread_activation_unwind_norz(resumee); /* unwind to 'yield' caller */ + duk_hthread_activation_unwind_norz(resumee); /* unwind to 'yield' caller */ /* no need to unwind catch stack */ duk__reconfig_valstack_ecma_return(resumee); @@ -1223,7 +1248,7 @@ /* resumee: ... initial_func undefined(= this) resume_value */ - call_flags = DUK_CALL_FLAG_ALLOW_ECMATOECMA; /* not tailcall, ecma-to-ecma (assumed to succeed) */ + call_flags = DUK_CALL_FLAG_ALLOW_ECMATOECMA; /* not tailcall, ecma-to-ecma (assumed to succeed) */ setup_rc = duk_handle_call_unprotected_nargs(resumee, 1 /*nargs*/, call_flags); if (setup_rc == 0) { @@ -1250,7 +1275,7 @@ goto wipe_and_return; } DUK_UNREACHABLE(); - break; /* never here */ + break; /* never here */ } case DUK_LJ_TYPE_YIELD: { @@ -1268,31 +1293,31 @@ /* duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met */ -#if 0 /* entry_thread not available for assert */ +#if 0 /* entry_thread not available for assert */ DUK_ASSERT(thr != entry_thread); /* Duktape.Thread.yield() should prevent */ #endif - DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged from Duktape.Thread.yield() */ - DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.yield() activation */ + DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged from Duktape.Thread.yield() */ + DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.yield() activation */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->callstack_curr))->func == duk_bi_thread_yield); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* an ECMAScript function */ resumer = thr->resumer; DUK_ASSERT(resumer != NULL); - DUK_ASSERT(resumer->state == DUK_HTHREAD_STATE_RESUMED); /* written by a previous RESUME handling */ - DUK_ASSERT(resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(resumer->state == DUK_HTHREAD_STATE_RESUMED); /* written by a previous RESUME handling */ + DUK_ASSERT(resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(resumer->callstack_curr != NULL); DUK_ASSERT(resumer->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(resumer->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(resumer->callstack_curr))->func == duk_bi_thread_resume); DUK_ASSERT(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent))); /* an ECMAScript function */ if (thr->heap->lj.iserror) { thr->state = DUK_HTHREAD_STATE_YIELDED; @@ -1304,7 +1329,7 @@ thr->heap->lj.type = DUK_LJ_TYPE_THROW; /* lj.value1 is already set */ - DUK_ASSERT(thr->heap->lj.iserror); /* already set */ + DUK_ASSERT(thr->heap->lj.iserror); /* already set */ DUK_DD(DUK_DDPRINT("-> yield an error, converted to a throw in the resumer, propagate")); goto check_longjmp; @@ -1330,9 +1355,9 @@ goto wipe_and_return; } DUK_UNREACHABLE(); - break; /* never here */ + break; /* never here */ } -#endif /* DUK_USE_COROUTINE_SUPPORT */ +#endif /* DUK_USE_COROUTINE_SUPPORT */ case DUK_LJ_TYPE_THROW: { /* @@ -1373,11 +1398,13 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF); DUK_DDD(DUK_DDDPRINT("before catch part 1: thr=%p, act=%p, cat=%p", - (void *) thr, (void *) act, (void *) act->cat)); + (void *) thr, + (void *) act, + (void *) act->cat)); duk__handle_catch_part1(thr, &thr->heap->lj.value1, DUK_LJ_TYPE_THROW, - out_delayed_catch_setup); + out_delayed_catch_setup); DUK_DD(DUK_DDPRINT("-> throw caught by a 'catch' clause, restart execution")); retval = DUK__LONGJMP_RESTART; @@ -1388,9 +1415,7 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF); DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); - duk__handle_finally(thr, - &thr->heap->lj.value1, - DUK_LJ_TYPE_THROW); + duk__handle_finally(thr, &thr->heap->lj.value1, DUK_LJ_TYPE_THROW); DUK_DD(DUK_DDPRINT("-> throw caught by a 'finally' clause, restart execution")); retval = DUK__LONGJMP_RESTART; @@ -1420,20 +1445,21 @@ */ DUK_ASSERT(thr->resumer != NULL); - DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->resumer->callstack_curr != NULL); DUK_ASSERT(thr->resumer->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_ASSERT( + DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ resumer = thr->resumer; /* reset longjmp */ - DUK_ASSERT(thr->heap->lj.type == DUK_LJ_TYPE_THROW); /* already set */ + DUK_ASSERT(thr->heap->lj.type == DUK_LJ_TYPE_THROW); /* already set */ /* lj.value1 already set */ - duk_hthread_terminate(thr); /* updates thread state, minimizes its allocations */ + duk_hthread_terminate(thr); /* updates thread state, minimizes its allocations */ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_TERMINATED); thr->resumer = NULL; @@ -1444,7 +1470,7 @@ goto check_longjmp; } - case DUK_LJ_TYPE_BREAK: /* pseudotypes, not used in actual longjmps */ + case DUK_LJ_TYPE_BREAK: /* pseudotypes, not used in actual longjmps */ case DUK_LJ_TYPE_CONTINUE: case DUK_LJ_TYPE_RETURN: case DUK_LJ_TYPE_NORMAL: @@ -1454,25 +1480,24 @@ goto convert_to_internal_error; } - } /* end switch */ + } /* end switch */ DUK_UNREACHABLE(); - wipe_and_return: - DUK_DD(DUK_DDPRINT("handling longjmp done, wipe-and-return, top=%ld", - (long) duk_get_top(thr))); +wipe_and_return: + DUK_DD(DUK_DDPRINT("handling longjmp done, wipe-and-return, top=%ld", (long) duk_get_top(thr))); thr->heap->lj.type = DUK_LJ_TYPE_UNKNOWN; thr->heap->lj.iserror = 0; - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value1); /* side effects */ - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value2); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value2); /* side effects */ DUK_GC_TORTURE(thr->heap); - just_return: +just_return: return retval; - convert_to_internal_error: +convert_to_internal_error: /* This could also be thrown internally (set the error, goto check_longjmp), * but it's better for internal errors to bubble outwards so that we won't * infinite loop in this catchpoint. @@ -1518,8 +1543,7 @@ /* XXX: bit mask test; FINALLY <-> TCF, single bit mask would suffice? */ - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && - DUK_CAT_HAS_FINALLY_ENABLED(cat)) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && DUK_CAT_HAS_FINALLY_ENABLED(cat)) { duk_tval tv_tmp; DUK_TVAL_SET_U32(&tv_tmp, (duk_uint32_t) label_id); @@ -1528,11 +1552,11 @@ DUK_DD(DUK_DDPRINT("-> break/continue caught by 'finally', restart execution")); return; } - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_LABEL && - (duk_uint_t) DUK_CAT_GET_LABEL(cat) == label_id) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_LABEL && (duk_uint_t) DUK_CAT_GET_LABEL(cat) == label_id) { duk__handle_label(thr, lj_type); - DUK_DD(DUK_DDPRINT("-> break/continue caught by a label catcher (in the same function), restart execution")); + DUK_DD( + DUK_DDPRINT("-> break/continue caught by a label catcher (in the same function), restart execution")); return; } @@ -1540,7 +1564,8 @@ } /* Should never happen, but be robust. */ - DUK_D(DUK_DPRINT("-> break/continue not caught by anything in the current function (should never happen), throw internal error")); + DUK_D(DUK_DPRINT( + "-> break/continue not caught by anything in the current function (should never happen), throw internal error")); DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); } @@ -1564,7 +1589,7 @@ DUK_ASSERT(entry_act != NULL); DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); tv1 = thr->valstack_top - 1; - DUK_TVAL_CHKFAST_INPLACE_FAST(tv1); /* fastint downgrade check for return values */ + DUK_TVAL_CHKFAST_INPLACE_FAST(tv1); /* fastint downgrade check for return values */ /* * Four possible outcomes: @@ -1599,8 +1624,7 @@ break; } - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && - DUK_CAT_HAS_FINALLY_ENABLED(cat)) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && DUK_CAT_HAS_FINALLY_ENABLED(cat)) { DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); duk__handle_finally(thr, thr->valstack_top - 1, DUK_LJ_TYPE_RETURN); @@ -1631,22 +1655,24 @@ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* must be ECMAScript */ + DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* must be ECMAScript */ #if defined(DUK_USE_ES6_PROXY) if (thr->callstack_curr->flags & (DUK_ACT_FLAG_CONSTRUCT | DUK_ACT_FLAG_CONSTRUCT_PROXY)) { - duk_call_construct_postprocess(thr, thr->callstack_curr->flags & DUK_ACT_FLAG_CONSTRUCT_PROXY); /* side effects */ + duk_call_construct_postprocess(thr, + thr->callstack_curr->flags & + DUK_ACT_FLAG_CONSTRUCT_PROXY); /* side effects */ } #else if (thr->callstack_curr->flags & DUK_ACT_FLAG_CONSTRUCT) { - duk_call_construct_postprocess(thr, 0); /* side effects */ + duk_call_construct_postprocess(thr, 0); /* side effects */ } #endif tv1 = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + thr->callstack_curr->parent->retval_byteoff); DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); tv2 = thr->valstack_top - 1; - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ /* Catch stack unwind happens inline in callstack unwind. */ duk_hthread_activation_unwind_norz(thr); @@ -1661,14 +1687,15 @@ DUK_DD(DUK_DDPRINT("no calling activation, thread finishes (similar to yield)")); DUK_ASSERT(thr->resumer != NULL); - DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->resumer->callstack_curr != NULL); DUK_ASSERT(thr->resumer->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr) != NULL && - DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr)) && - ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->resumer->callstack_curr))->func == duk_bi_thread_resume); /* Duktape.Thread.resume() */ + DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr)) && + ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->resumer->callstack_curr))->func == + duk_bi_thread_resume); /* Duktape.Thread.resume() */ DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); DUK_ASSERT(thr->resumer->state == DUK_HTHREAD_STATE_RESUMED); @@ -1690,11 +1717,11 @@ */ DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); - duk_hthread_activation_unwind_norz(resumer); /* May remove last reference to 'thr', but is NORZ. */ - duk_push_tval(resumer, thr->valstack_top - 1); /* Capture return value, side effect free. */ - duk_push_hthread(resumer, thr); /* Make 'thr' reachable again, before side effects. */ + duk_hthread_activation_unwind_norz(resumer); /* May remove last reference to 'thr', but is NORZ. */ + duk_push_tval(resumer, thr->valstack_top - 1); /* Capture return value, side effect free. */ + duk_push_hthread(resumer, thr); /* Make 'thr' reachable again, before side effects. */ - duk_hthread_terminate(thr); /* Updates thread state, minimizes its allocations. */ + duk_hthread_terminate(thr); /* Updates thread state, minimizes its allocations. */ thr->resumer = NULL; DUK_HTHREAD_DECREF(thr, resumer); DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_TERMINATED); @@ -1704,7 +1731,7 @@ DUK_ASSERT(resumer->valstack_top - 2 >= resumer->valstack_bottom); duk__handle_yield(thr, resumer, resumer->valstack_top - 2); - thr = NULL; /* 'thr' invalidated by call */ + thr = NULL; /* 'thr' invalidated by call */ #if 0 thr = resumer; /* not needed */ @@ -1746,8 +1773,8 @@ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK__INT_NOACTION 0 /* no specific action, resume normal execution */ -#define DUK__INT_RESTART 1 /* must "goto restart_execution", e.g. breakpoints changed */ +#define DUK__INT_NOACTION 0 /* no specific action, resume normal execution */ +#define DUK__INT_RESTART 1 /* must "goto restart_execution", e.g. breakpoints changed */ #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_LOCAL void duk__interrupt_handle_debugger(duk_hthread *thr, duk_bool_t *out_immediate, duk_small_uint_t *out_interrupt_retval) { @@ -1758,7 +1785,7 @@ duk_bool_t process_messages; duk_bool_t processed_messages = 0; - DUK_ASSERT(thr->heap->dbg_processing == 0); /* don't re-enter e.g. during Eval */ + DUK_ASSERT(thr->heap->dbg_processing == 0); /* don't re-enter e.g. during Eval */ act = thr->callstack_curr; DUK_ASSERT(act != NULL); @@ -1781,17 +1808,14 @@ * Breakpoint and step state checks */ - if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || - (thr->heap->dbg_pause_act == thr->callstack_curr)) { + if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || (thr->heap->dbg_pause_act == thr->callstack_curr)) { line = duk_debug_curr_line(thr); if (act->prev_line != line) { /* Stepped? Step out is handled by callstack unwind. */ if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && - (thr->heap->dbg_pause_act == thr->callstack_curr) && - (line != thr->heap->dbg_pause_startline)) { - DUK_D(DUK_DPRINT("PAUSE TRIGGERED by line change, at line %ld", - (long) line)); + (thr->heap->dbg_pause_act == thr->callstack_curr) && (line != thr->heap->dbg_pause_startline)) { + DUK_D(DUK_DPRINT("PAUSE TRIGGERED by line change, at line %ld", (long) line)); duk_debug_set_paused(thr->heap); } @@ -1817,7 +1841,8 @@ DUK_ASSERT(bp->filename != NULL); if (act->prev_line != bp->line && line == bp->line) { DUK_D(DUK_DPRINT("PAUSE TRIGGERED by breakpoint at %!O:%ld", - (duk_heaphdr *) bp->filename, (long) bp->line)); + (duk_heaphdr *) bp->filename, + (long) bp->line)); duk_debug_set_paused(thr->heap); } } @@ -1910,11 +1935,10 @@ if (duk_debug_is_attached(thr->heap)) { DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); - if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || - (thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_ONE_OPCODE) || + if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || (thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_ONE_OPCODE) || ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && thr->heap->dbg_pause_act == thr->callstack_curr) || - DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap)) { + DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap)) { *out_immediate = 1; } @@ -1936,7 +1960,7 @@ DUK_D(DUK_DPRINT("debugger became detached, resume normal execution")); } } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ DUK_LOCAL DUK_EXEC_NOINLINE_PERF DUK_COLD duk_small_uint_t duk__executor_interrupt(duk_hthread *thr) { duk_int_t ctr; @@ -1953,8 +1977,10 @@ thr->heap->inst_count_interrupt += thr->interrupt_init; DUK_DD(DUK_DDPRINT("execution interrupt, counter=%ld, init=%ld, " "instruction counts: executor=%ld, interrupt=%ld", - (long) thr->interrupt_counter, (long) thr->interrupt_init, - (long) thr->heap->inst_count_exec, (long) thr->heap->inst_count_interrupt)); + (long) thr->interrupt_counter, + (long) thr->interrupt_init, + (long) thr->heap->inst_count_exec, + (long) thr->heap->inst_count_interrupt)); #endif retval = DUK__INT_NOACTION; @@ -2016,18 +2042,17 @@ DUK_ERROR_RANGE(thr, "execution timeout"); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_EXEC_TIMEOUT_CHECK */ +#endif /* DUK_USE_EXEC_TIMEOUT_CHECK */ #if defined(DUK_USE_DEBUGGER_SUPPORT) - if (!thr->heap->dbg_processing && - (thr->heap->dbg_read_cb != NULL || thr->heap->dbg_detaching)) { + if (!thr->heap->dbg_processing && (thr->heap->dbg_read_cb != NULL || thr->heap->dbg_detaching)) { /* Avoid recursive re-entry; enter when we're attached or * detaching (to finish off the pending detach). */ duk__interrupt_handle_debugger(thr, &immediate, &retval); DUK_ASSERT(act == thr->callstack_curr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Update the interrupt counter @@ -2050,7 +2075,7 @@ return retval; } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ /* * Debugger handling for executor restart @@ -2118,8 +2143,7 @@ duk_hcompfunc *inner_fun; duk_bool_t bp_match; - if (bp->filename == filename && - bp->line >= fun->start_line && bp->line <= fun->end_line) { + if (bp->filename == filename && bp->line >= fun->start_line && bp->line <= fun->end_line) { bp_match = 1; DUK_DD(DUK_DDPRINT("breakpoint filename and line match: " "%s:%ld vs. %s (line %ld vs. %ld-%ld)", @@ -2156,13 +2180,12 @@ } } - *bp_active = NULL; /* terminate */ + *bp_active = NULL; /* terminate */ DUK_DD(DUK_DDPRINT("ACTIVE BREAKPOINTS: %ld", (long) (bp_active - thr->heap->dbg_breakpoints_active))); /* Force pause if we were doing "step into" in another activation. */ - if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_FUNC_ENTRY) && - thr->heap->dbg_pause_act != thr->callstack_curr) { + if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_FUNC_ENTRY) && thr->heap->dbg_pause_act != thr->callstack_curr) { DUK_D(DUK_DPRINT("PAUSE TRIGGERED by function entry")); duk_debug_set_paused(thr->heap); } @@ -2170,10 +2193,8 @@ /* Force interrupt right away if we're paused or in "checked mode". * Step out is handled by callstack unwind. */ - if ((act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE) || - DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || - ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && - thr->heap->dbg_pause_act == thr->callstack_curr)) { + if ((act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE) || DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || + ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && thr->heap->dbg_pause_act == thr->callstack_curr)) { /* We'll need to interrupt early so recompute the init * counter to reflect the number of bytecode instructions * executed so that step counts for e.g. debugger rate @@ -2184,7 +2205,7 @@ thr->interrupt_counter = 0; } } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Opcode handlers for opcodes with a lot of code and which are relatively @@ -2208,18 +2229,14 @@ /* This could be made more optimal by accessing internals directly. */ idx = (duk_uint_fast_t) DUK_DEC_BC(ins); - duk_dup(thr, (duk_idx_t) (idx + 0)); /* key */ - duk_dup(thr, (duk_idx_t) (idx + 1)); /* getter/setter */ + duk_dup(thr, (duk_idx_t) (idx + 0)); /* key */ + duk_dup(thr, (duk_idx_t) (idx + 1)); /* getter/setter */ if (is_set) { - defprop_flags = DUK_DEFPROP_HAVE_SETTER | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE; + defprop_flags = + DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE; } else { - defprop_flags = DUK_DEFPROP_HAVE_GETTER | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE; + defprop_flags = + DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE; } duk_def_prop(thr, (duk_idx_t) DUK_DEC_A(ins), defprop_flags); } @@ -2284,7 +2301,7 @@ * error handling, so there's no side effect problem even if the * error value has a finalizer. */ - duk_dup(thr, (duk_idx_t) bc); /* Stabilize value. */ + duk_dup(thr, (duk_idx_t) bc); /* Stabilize value. */ duk_to_undefined(thr, (duk_idx_t) bc); duk_to_undefined(thr, (duk_idx_t) (bc + 1)); @@ -2299,7 +2316,7 @@ cat->flags = DUK_CAT_TYPE_TCF; cat->h_varname = NULL; - cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ + cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ cat->idx_base = (duk_size_t) (thr->valstack_bottom - thr->valstack) + bc; act = thr->callstack_curr; @@ -2338,7 +2355,7 @@ duk_js_init_activation_environment_records_delayed(thr, act); DUK_ASSERT(act == thr->callstack_curr); - DUK_UNREF(act); /* 'act' is no longer accessed, scanbuild fix */ + DUK_UNREF(act); /* 'act' is no longer accessed, scanbuild fix */ } DUK_ASSERT(act->lex_env != NULL); DUK_ASSERT(act->var_env != NULL); @@ -2351,12 +2368,10 @@ * so avoid side effects very carefully until it is * referenced. */ - env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + env = duk_hobjenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(env != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); - env->target = target; /* always provideThis=true */ + env->target = target; /* always provideThis=true */ DUK_HOBJECT_INCREF(thr, target); env->has_this = 1; DUK_HOBJENV_ASSERT_VALID(env); @@ -2366,7 +2381,7 @@ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); DUK_ASSERT(act->lex_env != NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) env, act->lex_env); - act->lex_env = (duk_hobject *) env; /* Now reachable. */ + act->lex_env = (duk_hobject *) env; /* Now reachable. */ DUK_HOBJECT_INCREF(thr, (duk_hobject *) env); /* Net refcount change to act->lex_env is 0: incref for env's * prototype, decref for act->lex_env overwrite. @@ -2375,7 +2390,7 @@ /* Set catcher lex_env active (affects unwind) * only when the whole setup is complete. */ - cat = act->cat; /* XXX: better to relookup? not mandatory because 'cat' is stable */ + cat = act->cat; /* XXX: better to relookup? not mandatory because 'cat' is stable */ cat->flags |= DUK_CAT_FLAG_LEXENV_ACTIVE; } else { ; @@ -2384,7 +2399,9 @@ DUK_DDD(DUK_DDDPRINT("TRYCATCH catcher: flags=0x%08lx, pc_base=%ld, " "idx_base=%ld, h_varname=%!O", (unsigned long) cat->flags, - (long) cat->pc_base, (long) cat->idx_base, (duk_heaphdr *) cat->h_varname)); + (long) cat->pc_base, + (long) cat->idx_base, + (duk_heaphdr *) cat->h_varname)); duk_pop_unsafe(thr); } @@ -2414,23 +2431,24 @@ tv1 = thr->valstack + cat->idx_base; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ tv1 = NULL; tv1 = thr->valstack + cat->idx_base + 1; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ tv1 = NULL; DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } else { - DUK_DDD(DUK_DDDPRINT("ENDTRY: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); + DUK_DDD( + DUK_DDDPRINT("ENDTRY: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); - duk_hthread_catcher_unwind_norz(thr, act); /* lexenv may be set for 'with' binding */ + duk_hthread_catcher_unwind_norz(thr, act); /* lexenv may be set for 'with' binding */ /* no need to unwind callstack */ } - return pc_base + 1; /* new curr_pc value */ + return pc_base + 1; /* new curr_pc value */ } DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_instr_t *duk__handle_op_endcatch(duk_hthread *thr, duk_uint_fast32_t ins) { @@ -2446,7 +2464,7 @@ DUK_ASSERT(act != NULL); cat = act->cat; DUK_ASSERT(cat != NULL); - DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); /* cleared before entering catch part */ + DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); /* cleared before entering catch part */ if (DUK_CAT_HAS_LEXENV_ACTIVE(cat)) { duk_hobject *prev_env; @@ -2462,7 +2480,7 @@ act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, prev_env); DUK_CAT_CLEAR_LEXENV_ACTIVE(cat); DUK_HOBJECT_INCREF(thr, act->lex_env); - DUK_HOBJECT_DECREF(thr, prev_env); /* side effects */ + DUK_HOBJECT_DECREF(thr, prev_env); /* side effects */ DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); @@ -2475,26 +2493,29 @@ tv1 = thr->valstack + cat->idx_base; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ tv1 = NULL; tv1 = thr->valstack + cat->idx_base + 1; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ tv1 = NULL; DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } else { - DUK_DDD(DUK_DDDPRINT("ENDCATCH: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); + DUK_DDD( + DUK_DDDPRINT("ENDCATCH: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); duk_hthread_catcher_unwind_norz(thr, act); /* no need to unwind callstack */ } - return pc_base + 1; /* new curr_pc value */ + return pc_base + 1; /* new curr_pc value */ } -DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_small_uint_t duk__handle_op_endfin(duk_hthread *thr, duk_uint_fast32_t ins, duk_activation *entry_act) { +DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_small_uint_t duk__handle_op_endfin(duk_hthread *thr, + duk_uint_fast32_t ins, + duk_activation *entry_act) { duk_activation *act; duk_tval *tv1; duk_uint_t reg_catch; @@ -2516,7 +2537,7 @@ (duk_tval *) (thr->valstack_bottom + reg_catch + 0), (duk_tval *) (thr->valstack_bottom + reg_catch + 1))); - tv1 = thr->valstack_bottom + reg_catch + 1; /* type */ + tv1 = thr->valstack_bottom + reg_catch + 1; /* type */ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv1)); #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv1)); @@ -2525,7 +2546,7 @@ cont_type = (duk_small_uint_t) DUK_TVAL_GET_NUMBER(tv1); #endif - tv1--; /* value */ + tv1--; /* value */ switch (cont_type) { case DUK_LJ_TYPE_NORMAL: { @@ -2534,11 +2555,12 @@ duk_hthread_catcher_unwind_norz(thr, act); /* no need to unwind callstack */ - return 0; /* restart execution */ + return 0; /* restart execution */ } case DUK_LJ_TYPE_RETURN: { DUK_DDD(DUK_DDDPRINT("ENDFIN: finally part finishing with 'return' complation -> dismantle " - "catcher, handle return, lj.value1=%!T", tv1)); + "catcher, handle return, lj.value1=%!T", + tv1)); /* Not necessary to unwind catch stack: return handling will * do it. The finally flag of 'cat' is no longer set. The @@ -2548,12 +2570,12 @@ duk_push_tval(thr, tv1); ret_result = duk__handle_return(thr, entry_act); if (ret_result == DUK__RETHAND_RESTART) { - return 0; /* restart execution */ + return 0; /* restart execution */ } DUK_ASSERT(ret_result == DUK__RETHAND_FINISHED); DUK_DDD(DUK_DDDPRINT("exiting executor after ENDFIN and RETURN (pseudo) longjmp type")); - return 1; /* exit executor */ + return 1; /* exit executor */ } case DUK_LJ_TYPE_BREAK: case DUK_LJ_TYPE_CONTINUE: { @@ -2575,7 +2597,7 @@ #endif lj_type = cont_type; duk__handle_break_or_continue(thr, label_id, lj_type); - return 0; /* restart execution */ + return 0; /* restart execution */ } default: { DUK_DDD(DUK_DDDPRINT("ENDFIN: finally part finishing with abrupt completion, lj_type=%ld -> " @@ -2585,7 +2607,7 @@ duk_err_setup_ljstate1(thr, (duk_small_uint_t) cont_type, tv1); /* No debugger Throw notify check on purpose (rethrow). */ - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ duk_err_longjmp(thr); DUK_UNREACHABLE(); } @@ -2618,7 +2640,7 @@ } else { duk_dup(thr, (duk_idx_t) c); duk_to_object(thr, -1); - duk_hobject_enumerator_create(thr, 0 /*enum_flags*/); /* ... val --> ... enum */ + duk_hobject_enumerator_create(thr, 0 /*enum_flags*/); /* ... val --> ... enum */ duk_replace(thr, (duk_idx_t) b); } } @@ -2650,13 +2672,12 @@ duk_dup(thr, (duk_idx_t) c); if (duk_hobject_enumerator_next(thr, 0 /*get_value*/)) { /* ... enum -> ... next_key */ - DUK_DDD(DUK_DDDPRINT("enum active, next key is %!T, skip jump slot ", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("enum active, next key is %!T, skip jump slot ", (duk_tval *) duk_get_tval(thr, -1))); pc_skip = 1; } else { /* ... enum -> ... */ DUK_DDD(DUK_DDDPRINT("enum finished, execute jump slot")); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } duk_replace(thr, (duk_idx_t) b); @@ -2676,7 +2697,7 @@ DUK_LOCAL duk_bool_t duk__executor_handle_call(duk_hthread *thr, duk_idx_t idx, duk_idx_t nargs, duk_small_uint_t call_flags) { duk_bool_t rc; - duk_set_top_unsafe(thr, (duk_idx_t) (idx + nargs + 2)); /* ... func this arg1 ... argN */ + duk_set_top_unsafe(thr, (duk_idx_t) (idx + nargs + 2)); /* ... func this arg1 ... argN */ /* Attempt an Ecma-to-Ecma call setup. If the call * target is (directly or indirectly) Reflect.construct(), @@ -2730,22 +2751,22 @@ * difference and the best option is architecture dependent. */ #if defined(DUK_USE_EXEC_FUN_LOCAL) -#define DUK__FUN() fun +#define DUK__FUN() fun #else -#define DUK__FUN() ((duk_hcompfunc *) DUK_ACT_GET_FUNC((thr)->callstack_curr)) +#define DUK__FUN() ((duk_hcompfunc *) DUK_ACT_GET_FUNC((thr)->callstack_curr)) #endif /* Strict flag. */ -#define DUK__STRICT() ((duk_small_uint_t) DUK_HOBJECT_HAS_STRICT((duk_hobject *) DUK__FUN())) +#define DUK__STRICT() ((duk_small_uint_t) DUK_HOBJECT_HAS_STRICT((duk_hobject *) DUK__FUN())) /* Reg/const access macros: these are very footprint and performance sensitive * so modify with care. Arguments are sometimes evaluated multiple times which * is not ideal. */ -#define DUK__REG(x) (*(thr->valstack_bottom + (x))) -#define DUK__REGP(x) (thr->valstack_bottom + (x)) -#define DUK__CONST(x) (*(consts + (x))) -#define DUK__CONSTP(x) (consts + (x)) +#define DUK__REG(x) (*(thr->valstack_bottom + (x))) +#define DUK__REGP(x) (thr->valstack_bottom + (x)) +#define DUK__CONST(x) (*(consts + (x))) +#define DUK__CONSTP(x) (consts + (x)) /* Reg/const access macros which take the 32-bit instruction and avoid an * explicit field decoding step by using shifts and masks. These must be @@ -2754,68 +2775,74 @@ * instead of a duk_tval offset which needs further shifting (which is an * issue on some, but not all, CPUs). */ -#define DUK__RCBIT_B DUK_BC_REGCONST_B -#define DUK__RCBIT_C DUK_BC_REGCONST_C +#define DUK__RCBIT_B DUK_BC_REGCONST_B +#define DUK__RCBIT_C DUK_BC_REGCONST_C #if defined(DUK_USE_EXEC_REGCONST_OPTIMIZE) #if defined(DUK_USE_PACKED_TVAL) -#define DUK__TVAL_SHIFT 3 /* sizeof(duk_tval) == 8 */ +#define DUK__TVAL_SHIFT 3 /* sizeof(duk_tval) == 8 */ #else -#define DUK__TVAL_SHIFT 4 /* sizeof(duk_tval) == 16; not always the case so also asserted for */ +#define DUK__TVAL_SHIFT 4 /* sizeof(duk_tval) == 16; not always the case so also asserted for */ #endif -#define DUK__SHIFT_A (DUK_BC_SHIFT_A - DUK__TVAL_SHIFT) -#define DUK__SHIFT_B (DUK_BC_SHIFT_B - DUK__TVAL_SHIFT) -#define DUK__SHIFT_C (DUK_BC_SHIFT_C - DUK__TVAL_SHIFT) -#define DUK__SHIFT_BC (DUK_BC_SHIFT_BC - DUK__TVAL_SHIFT) -#define DUK__MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK__TVAL_SHIFT) -#define DUK__MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK__TVAL_SHIFT) -#define DUK__MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK__TVAL_SHIFT) -#define DUK__MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK__TVAL_SHIFT) -#define DUK__BYTEOFF_A(ins) (((ins) >> DUK__SHIFT_A) & DUK__MASK_A) -#define DUK__BYTEOFF_B(ins) (((ins) >> DUK__SHIFT_B) & DUK__MASK_B) -#define DUK__BYTEOFF_C(ins) (((ins) >> DUK__SHIFT_C) & DUK__MASK_C) -#define DUK__BYTEOFF_BC(ins) (((ins) >> DUK__SHIFT_BC) & DUK__MASK_BC) - -#define DUK__REGP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_A((ins)))) -#define DUK__REGP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_B((ins)))) -#define DUK__REGP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_C((ins)))) -#define DUK__REGP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_BC((ins)))) -#define DUK__CONSTP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_A((ins)))) -#define DUK__CONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_B((ins)))) -#define DUK__CONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_C((ins)))) -#define DUK__CONSTP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_BC((ins)))) -#define DUK__REGCONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) & DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_B((ins)))) -#define DUK__REGCONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) & DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_C((ins)))) -#else /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#define DUK__SHIFT_A (DUK_BC_SHIFT_A - DUK__TVAL_SHIFT) +#define DUK__SHIFT_B (DUK_BC_SHIFT_B - DUK__TVAL_SHIFT) +#define DUK__SHIFT_C (DUK_BC_SHIFT_C - DUK__TVAL_SHIFT) +#define DUK__SHIFT_BC (DUK_BC_SHIFT_BC - DUK__TVAL_SHIFT) +#define DUK__MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK__TVAL_SHIFT) +#define DUK__MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK__TVAL_SHIFT) +#define DUK__MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK__TVAL_SHIFT) +#define DUK__MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK__TVAL_SHIFT) +#define DUK__BYTEOFF_A(ins) (((ins) >> DUK__SHIFT_A) & DUK__MASK_A) +#define DUK__BYTEOFF_B(ins) (((ins) >> DUK__SHIFT_B) & DUK__MASK_B) +#define DUK__BYTEOFF_C(ins) (((ins) >> DUK__SHIFT_C) & DUK__MASK_C) +#define DUK__BYTEOFF_BC(ins) (((ins) >> DUK__SHIFT_BC) & DUK__MASK_BC) + +#define DUK__REGP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_A((ins)))) +#define DUK__REGP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_B((ins)))) +#define DUK__REGP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_C((ins)))) +#define DUK__REGP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_BC((ins)))) +#define DUK__CONSTP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_A((ins)))) +#define DUK__CONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_B((ins)))) +#define DUK__CONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_C((ins)))) +#define DUK__CONSTP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_BC((ins)))) +#define DUK__REGCONSTP_B(ins) \ + ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) &DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_B((ins)))) +#define DUK__REGCONSTP_C(ins) \ + ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) &DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_C((ins)))) +#else /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ /* Safe alternatives, no assumption about duk_tval size. */ -#define DUK__REGP_A(ins) DUK__REGP(DUK_DEC_A((ins))) -#define DUK__REGP_B(ins) DUK__REGP(DUK_DEC_B((ins))) -#define DUK__REGP_C(ins) DUK__REGP(DUK_DEC_C((ins))) -#define DUK__REGP_BC(ins) DUK__REGP(DUK_DEC_BC((ins))) -#define DUK__CONSTP_A(ins) DUK__CONSTP(DUK_DEC_A((ins))) -#define DUK__CONSTP_B(ins) DUK__CONSTP(DUK_DEC_B((ins))) -#define DUK__CONSTP_C(ins) DUK__CONSTP(DUK_DEC_C((ins))) -#define DUK__CONSTP_BC(ins) DUK__CONSTP(DUK_DEC_BC((ins))) -#define DUK__REGCONSTP_B(ins) ((((ins) & DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK_DEC_B((ins))) -#define DUK__REGCONSTP_C(ins) ((((ins) & DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK_DEC_C((ins))) -#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#define DUK__REGP_A(ins) DUK__REGP(DUK_DEC_A((ins))) +#define DUK__REGP_B(ins) DUK__REGP(DUK_DEC_B((ins))) +#define DUK__REGP_C(ins) DUK__REGP(DUK_DEC_C((ins))) +#define DUK__REGP_BC(ins) DUK__REGP(DUK_DEC_BC((ins))) +#define DUK__CONSTP_A(ins) DUK__CONSTP(DUK_DEC_A((ins))) +#define DUK__CONSTP_B(ins) DUK__CONSTP(DUK_DEC_B((ins))) +#define DUK__CONSTP_C(ins) DUK__CONSTP(DUK_DEC_C((ins))) +#define DUK__CONSTP_BC(ins) DUK__CONSTP(DUK_DEC_BC((ins))) +#define DUK__REGCONSTP_B(ins) ((((ins) &DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK_DEC_B((ins))) +#define DUK__REGCONSTP_C(ins) ((((ins) &DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK_DEC_C((ins))) +#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ #if defined(DUK_USE_VERBOSE_EXECUTOR_ERRORS) -#define DUK__INTERNAL_ERROR(msg) do { \ +#define DUK__INTERNAL_ERROR(msg) \ + do { \ DUK_ERROR_ERROR(thr, (msg)); \ DUK_WO_NORETURN(return;); \ } while (0) #else -#define DUK__INTERNAL_ERROR(msg) do { \ +#define DUK__INTERNAL_ERROR(msg) \ + do { \ goto internal_error; \ } while (0) #endif -#define DUK__SYNC_CURR_PC() do { \ +#define DUK__SYNC_CURR_PC() \ + do { \ duk_activation *duk__act; \ duk__act = thr->callstack_curr; \ duk__act->curr_pc = curr_pc; \ } while (0) -#define DUK__SYNC_AND_NULL_CURR_PC() do { \ +#define DUK__SYNC_AND_NULL_CURR_PC() \ + do { \ duk_activation *duk__act; \ duk__act = thr->callstack_curr; \ duk__act->curr_pc = curr_pc; \ @@ -2823,19 +2850,22 @@ } while (0) #if defined(DUK_USE_EXEC_PREFER_SIZE) -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ (idx) = (duk_uint_fast_t) duk_get_uint(thr, (duk_idx_t) (idx)); \ } while (0) #elif defined(DUK_USE_FASTINT) -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ duk_tval *tv_ind; \ tv_ind = DUK__REGP((idx)); \ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_ind)); \ - DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_ind)); /* compiler guarantees */ \ + DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_ind)); /* compiler guarantees */ \ (idx) = (duk_uint_fast_t) DUK_TVAL_GET_FASTINT_U32(tv_ind); \ } while (0) #else -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ duk_tval *tv_ind; \ tv_ind = DUK__REGP(idx); \ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_ind)); \ @@ -2888,8 +2918,8 @@ * will be re-bumped by the longjmp. */ - DUK_ASSERT(lj_ret == DUK__LONGJMP_RETHROW); /* Rethrow error to calling state. */ - DUK_ASSERT(heap->lj.jmpbuf_ptr == entry_jmpbuf_ptr); /* Longjmp handling has restored jmpbuf_ptr. */ + DUK_ASSERT(lj_ret == DUK__LONGJMP_RETHROW); /* Rethrow error to calling state. */ + DUK_ASSERT(heap->lj.jmpbuf_ptr == entry_jmpbuf_ptr); /* Longjmp handling has restored jmpbuf_ptr. */ /* Thread may have changed, e.g. YIELD converted to THROW. */ duk_err_longjmp(heap->curr_thread); @@ -2912,7 +2942,7 @@ DUK_ASSERT(exec_thr->heap != NULL); DUK_ASSERT(exec_thr->heap->curr_thread != NULL); DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR((duk_heaphdr *) exec_thr); - DUK_ASSERT(exec_thr->callstack_top >= 1); /* at least one activation, ours */ + DUK_ASSERT(exec_thr->callstack_top >= 1); /* at least one activation, ours */ DUK_ASSERT(exec_thr->callstack_curr != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(exec_thr->callstack_curr) != NULL); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(exec_thr->callstack_curr))); @@ -2978,7 +3008,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } #if defined(DUK_USE_CPP_EXCEPTIONS) catch (duk_fatal_exception &exc) { @@ -2994,7 +3024,10 @@ DUK_STATS_INC(exec_thr->heap, stats_exec_throw); try { DUK_ASSERT(heap->curr_thread != NULL); - DUK_ERROR_FMT1(heap->curr_thread, DUK_ERR_TYPE_ERROR, "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", what); + DUK_ERROR_FMT1(heap->curr_thread, + DUK_ERR_TYPE_ERROR, + "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", + what); DUK_WO_NORETURN(return;); } catch (duk_internal_exception exc) { DUK_D(DUK_DPRINT("caught api error thrown from unexpected c++ std::exception")); @@ -3003,7 +3036,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } } catch (...) { DUK_D(DUK_DPRINT("unexpected c++ exception (perhaps thrown by user code)")); @@ -3019,7 +3052,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } } #endif @@ -3035,13 +3068,13 @@ * but that eliminates performance benefits; aliasing guarantees * should be enough though. */ - duk_instr_t *curr_pc; /* bytecode has a stable pointer */ + duk_instr_t *curr_pc; /* bytecode has a stable pointer */ /* Hot variables for interpretation. Critical for performance, * but must add sparingly to minimize register shuffling. */ - duk_hthread *thr; /* stable */ - duk_tval *consts; /* stable */ + duk_hthread *thr; /* stable */ + duk_tval *consts; /* stable */ duk_uint_fast32_t ins; /* 'funcs' is quite rarely used, so no local for it */ #if defined(DUK_USE_EXEC_FUN_LOCAL) @@ -3055,7 +3088,7 @@ #endif #if defined(DUK_USE_ASSERTIONS) - duk_size_t valstack_top_base; /* valstack top, should match before interpreting each op (no leftovers) */ + duk_size_t valstack_top_base; /* valstack top, should match before interpreting each op (no leftovers) */ #endif /* Optimized reg/const access macros assume sizeof(duk_tval) to be @@ -3111,7 +3144,7 @@ * See execution.rst for discussion. */ - restart_execution: +restart_execution: /* Lookup current thread; use the stable 'entry_thread' for this to * avoid clobber warnings. Any valid, reachable 'thr' value would be @@ -3152,7 +3185,7 @@ DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) valstack_top_base = (duk_size_t) (thr->valstack_top - thr->valstack); @@ -3216,7 +3249,7 @@ */ #if defined(DUK_USE_DEBUGGER_SUPPORT) if (thr->heap->dbg_force_restart) { - DUK_DD(DUK_DDPRINT("dbg_force_restart flag forced restart execution")); /* GH-303 */ + DUK_DD(DUK_DDPRINT("dbg_force_restart flag forced restart execution")); /* GH-303 */ thr->heap->dbg_force_restart = 0; goto restart_execution; } @@ -3228,7 +3261,7 @@ goto restart_execution; } } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ #if defined(DUK_USE_INTERRUPT_COUNTER) && defined(DUK_USE_DEBUG) /* For cross-checking during development: ensure dispatch count * matches cumulative interrupt counter init value sums. @@ -3242,16 +3275,17 @@ act = thr->callstack_curr; DUK_ASSERT(curr_pc >= DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())); DUK_ASSERT(curr_pc < DUK_HCOMPFUNC_GET_CODE_END(thr->heap, DUK__FUN())); - DUK_UNREF(act); /* if debugging disabled */ + DUK_UNREF(act); /* if debugging disabled */ - DUK_DDD(DUK_DDDPRINT("executing bytecode: pc=%ld, ins=0x%08lx, op=%ld, valstack_top=%ld/%ld, nregs=%ld --> %!I", - (long) (curr_pc - DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())), - (unsigned long) *curr_pc, - (long) DUK_DEC_OP(*curr_pc), - (long) (thr->valstack_top - thr->valstack), - (long) (thr->valstack_end - thr->valstack), - (long) (DUK__FUN() ? DUK__FUN()->nregs : -1), - (duk_instr_t) *curr_pc)); + DUK_DDD(DUK_DDDPRINT( + "executing bytecode: pc=%ld, ins=0x%08lx, op=%ld, valstack_top=%ld/%ld, nregs=%ld --> %!I", + (long) (curr_pc - DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())), + (unsigned long) *curr_pc, + (long) DUK_DEC_OP(*curr_pc), + (long) (thr->valstack_top - thr->valstack), + (long) (thr->valstack_end - thr->valstack), + (long) (DUK__FUN() ? DUK__FUN()->nregs : -1), + (duk_instr_t) *curr_pc)); } #endif @@ -3288,14 +3322,16 @@ */ op = (duk_uint8_t) DUK_DEC_OP(ins); switch (op) { - - /* Some useful macros. These access inner executor variables - * directly so they only apply within the executor. - */ + /* Some useful macros. These access inner executor variables + * directly so they only apply within the executor. + */ #if defined(DUK_USE_EXEC_PREFER_SIZE) -#define DUK__REPLACE_TOP_A_BREAK() { goto replace_top_a; } -#define DUK__REPLACE_TOP_BC_BREAK() { goto replace_top_bc; } -#define DUK__REPLACE_BOOL_A_BREAK(bval) { \ +#define DUK__REPLACE_TOP_A_BREAK() \ + { goto replace_top_a; } +#define DUK__REPLACE_TOP_BC_BREAK() \ + { goto replace_top_bc; } +#define DUK__REPLACE_BOOL_A_BREAK(bval) \ + { \ duk_bool_t duk__bval; \ duk__bval = (bval); \ DUK_ASSERT(duk__bval == 0 || duk__bval == 1); \ @@ -3303,9 +3339,18 @@ DUK__REPLACE_TOP_A_BREAK(); \ } #else -#define DUK__REPLACE_TOP_A_BREAK() { DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); break; } -#define DUK__REPLACE_TOP_BC_BREAK() { DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); break; } -#define DUK__REPLACE_BOOL_A_BREAK(bval) { \ +#define DUK__REPLACE_TOP_A_BREAK() \ + { \ + DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); \ + break; \ + } +#define DUK__REPLACE_TOP_BC_BREAK() \ + { \ + DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); \ + break; \ + } +#define DUK__REPLACE_BOOL_A_BREAK(bval) \ + { \ duk_bool_t duk__bval; \ duk_tval *duk__tvdst; \ duk__bval = (bval); \ @@ -3329,7 +3374,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__REGP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } @@ -3338,7 +3383,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__REGP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv2, tv1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv2, tv1); /* side effects */ break; } @@ -3347,7 +3392,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__CONSTP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } @@ -3367,18 +3412,18 @@ duk_int32_t val; val = (duk_int32_t) duk_get_int(thr, DUK_DEC_A(ins)); - val = (val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ + val = (val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ duk_push_int(thr, val); DUK__REPLACE_TOP_A_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LDINT: { duk_tval *tv1; duk_int32_t val; val = (duk_int32_t) DUK_DEC_BC(ins) - (duk_int32_t) DUK_BC_LDINT_BIAS; tv1 = DUK__REGP_A(ins); - DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ break; } case DUK_OP_LDINTX: { @@ -3394,11 +3439,12 @@ /* XXX: fast double-to-int conversion, we know number is integer in -0x80000000,0xffffffff. */ val = (duk_int32_t) DUK_TVAL_GET_NUMBER(tv1); #endif - val = (duk_int32_t) ((duk_uint32_t) val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ - DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ + val = + (duk_int32_t) ((duk_uint32_t) val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ + DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_LDTHIS: { @@ -3421,46 +3467,46 @@ duk_push_false(thr); DUK__REPLACE_TOP_BC_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LDTHIS: { /* Note: 'this' may be bound to any value, not just an object */ duk_tval *tv1, *tv2; tv1 = DUK__REGP_BC(ins); - tv2 = thr->valstack_bottom - 1; /* 'this binding' is just under bottom */ + tv2 = thr->valstack_bottom - 1; /* 'this binding' is just under bottom */ DUK_ASSERT(tv2 >= thr->valstack); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } case DUK_OP_LDUNDEF: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ break; } case DUK_OP_LDNULL: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_NULL_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_NULL_UPDREF(thr, tv1); /* side effects */ break; } case DUK_OP_LDTRUE: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 1); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 1); /* side effects */ break; } case DUK_OP_LDFALSE: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 0); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 0); /* side effects */ break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_BNOT: { duk__vm_bitwise_not(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins)); @@ -3478,7 +3524,7 @@ duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_UNM: { duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), DUK_OP_UNM); break; @@ -3487,7 +3533,7 @@ duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), DUK_OP_UNP); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_TYPEOF: { @@ -3498,7 +3544,7 @@ duk_push_hstring_stridx(thr, stridx); DUK__REPLACE_TOP_A_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_TYPEOF: { duk_tval *tv; duk_small_uint_t stridx; @@ -3512,7 +3558,7 @@ DUK_TVAL_SET_STRING_UPDREF(thr, tv, h_str); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_TYPEOFID: { duk_small_uint_t stridx; @@ -3530,13 +3576,13 @@ tv = DUK__CONSTP_BC(ins); DUK_ASSERT(DUK_TVAL_IS_STRING(tv)); name = DUK_TVAL_GET_STRING(tv); - tv = NULL; /* lookup has side effects */ + tv = NULL; /* lookup has side effects */ act = thr->callstack_curr; if (duk_js_getvar_activation(thr, act, name, 0 /*throw*/)) { /* -> ... val this */ tv = DUK_GET_TVAL_NEGIDX(thr, -2); stridx = duk_js_typeof_stridx(tv); - tv = NULL; /* no longer needed */ + tv = NULL; /* no longer needed */ duk_pop_2_unsafe(thr); } else { /* unresolvable, no stack changes */ @@ -3546,36 +3592,40 @@ #if defined(DUK_USE_EXEC_PREFER_SIZE) duk_push_hstring_stridx(thr, stridx); DUK__REPLACE_TOP_A_BREAK(); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ h_str = DUK_HTHREAD_GET_STRING(thr, stridx); tv = DUK__REGP_A(ins); DUK_TVAL_SET_STRING_UPDREF(thr, tv, h_str); break; -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } /* Equality: E5 Sections 11.9.1, 11.9.3 */ -#define DUK__EQ_BODY(barg,carg) { \ +#define DUK__EQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_equals(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__NEQ_BODY(barg,carg) { \ +#define DUK__NEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_equals(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ tmp ^= 1; \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__SEQ_BODY(barg,carg) { \ +#define DUK__SEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_strict_equals((barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__SNEQ_BODY(barg,carg) { \ +#define DUK__SNEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_strict_equals((barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ @@ -3603,7 +3653,7 @@ case DUK_OP_SNEQ_RC: case DUK_OP_SNEQ_CC: DUK__SNEQ_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_EQ_RR: DUK__EQ_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_EQ_CR: @@ -3636,18 +3686,19 @@ DUK__SNEQ_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_SNEQ_CC: DUK__SNEQ_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ -#define DUK__COMPARE_BODY(arg1,arg2,flags) { \ +#define DUK__COMPARE_BODY(arg1, arg2, flags) \ + { \ duk_bool_t tmp; \ tmp = duk_js_compare_helper(thr, (arg1), (arg2), (flags)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__GT_BODY(barg,carg) DUK__COMPARE_BODY((carg), (barg), 0) -#define DUK__GE_BODY(barg,carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) -#define DUK__LT_BODY(barg,carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) -#define DUK__LE_BODY(barg,carg) DUK__COMPARE_BODY((carg), (barg), DUK_COMPARE_FLAG_NEGATE) +#define DUK__GT_BODY(barg, carg) DUK__COMPARE_BODY((carg), (barg), 0) +#define DUK__GE_BODY(barg, carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) +#define DUK__LT_BODY(barg, carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) +#define DUK__LE_BODY(barg, carg) DUK__COMPARE_BODY((carg), (barg), DUK_COMPARE_FLAG_NEGATE) #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_GT_RR: case DUK_OP_GT_CR: @@ -3669,7 +3720,7 @@ case DUK_OP_LE_RC: case DUK_OP_LE_CC: DUK__LE_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_GT_RR: DUK__GT_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_GT_CR: @@ -3702,7 +3753,7 @@ DUK__LE_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_LE_CC: DUK__LE_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* No size optimized variant at present for IF. */ case DUK_OP_IFTRUE_R: { @@ -3739,7 +3790,7 @@ duk__vm_arith_add(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins)); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_ADD_RR: { duk__vm_arith_add(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins)); break; @@ -3756,7 +3807,7 @@ duk__vm_arith_add(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins)); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_SUB_RR: @@ -3780,13 +3831,13 @@ case DUK_OP_EXP_CR: case DUK_OP_EXP_RC: case DUK_OP_EXP_CC: -#endif /* DUK_USE_ES7_EXP_OPERATOR */ +#endif /* DUK_USE_ES7_EXP_OPERATOR */ { /* XXX: could leave value on stack top and goto replace_top_a; */ duk__vm_arith_binary_op(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_SUB_RR: { duk__vm_arith_binary_op(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins), DUK_OP_SUB); break; @@ -3868,8 +3919,8 @@ duk__vm_arith_binary_op(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins), DUK_OP_EXP); break; } -#endif /* DUK_USE_ES7_EXP_OPERATOR */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_ES7_EXP_OPERATOR */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_BAND_RR: @@ -3900,7 +3951,7 @@ duk__vm_bitwise_binary_op(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_BAND_RR: { duk__vm_bitwise_binary_op(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins), DUK_OP_BAND); break; @@ -3997,16 +4048,18 @@ duk__vm_bitwise_binary_op(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins), DUK_OP_BASR); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* For INSTOF and IN, B is always a register. */ -#define DUK__INSTOF_BODY(barg,carg) { \ +#define DUK__INSTOF_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_instanceof(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__IN_BODY(barg,carg) { \ +#define DUK__IN_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_in(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ @@ -4023,7 +4076,7 @@ case DUK_OP_IN_RC: case DUK_OP_IN_CC: DUK__IN_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_INSTOF_RR: DUK__INSTOF_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_INSTOF_CR: @@ -4040,9 +4093,9 @@ DUK__IN_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_IN_CC: DUK__IN_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ - /* Pre/post inc/dec for register variables, important for loops. */ + /* Pre/post inc/dec for register variables, important for loops. */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_PREINCR: case DUK_OP_PREDECR: @@ -4058,7 +4111,7 @@ duk__prepost_incdec_var_helper(thr, DUK_DEC_A(ins), DUK__CONSTP_BC(ins), op, DUK__STRICT()); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_PREINCR: { duk__prepost_incdec_reg_helper(thr, DUK__REGP_A(ins), DUK__REGP_BC(ins), DUK_OP_PREINCR); break; @@ -4091,7 +4144,7 @@ duk__prepost_incdec_var_helper(thr, DUK_DEC_A(ins), DUK__CONSTP_BC(ins), DUK_OP_POSTDECV, DUK__STRICT()); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* XXX: Move to separate helper, optimize for perf/size separately. */ /* Preinc/predec for object properties. */ @@ -4118,7 +4171,7 @@ duk_double_t x, y, z; #if !defined(DUK_USE_EXEC_PREFER_SIZE) duk_tval *tv_dst; -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* A -> target reg * B -> object reg/const (may be const e.g. in "'foo'1") @@ -4136,10 +4189,10 @@ tv_obj = DUK__REGCONSTP_B(ins); tv_key = DUK__REGCONSTP_C(ins); - rc = duk_hobject_getprop(thr, tv_obj, tv_key); /* -> val */ - DUK_UNREF(rc); /* ignore */ - tv_obj = NULL; /* invalidated */ - tv_key = NULL; /* invalidated */ + rc = duk_hobject_getprop(thr, tv_obj, tv_key); /* -> val */ + DUK_UNREF(rc); /* ignore */ + tv_obj = NULL; /* invalidated */ + tv_key = NULL; /* invalidated */ /* XXX: Fastint fast path would be useful here. Also fastints * now lose their fastint status in current handling which is @@ -4160,9 +4213,9 @@ tv_obj = DUK__REGCONSTP_B(ins); tv_key = DUK__REGCONSTP_C(ins); rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, DUK__STRICT()); - DUK_UNREF(rc); /* ignore */ - tv_obj = NULL; /* invalidated */ - tv_key = NULL; /* invalidated */ + DUK_UNREF(rc); /* ignore */ + tv_obj = NULL; /* invalidated */ + tv_key = NULL; /* invalidated */ duk_pop_unsafe(thr); z = (ins & DUK_BC_INCDECP_FLAG_POST) ? x : y; @@ -4180,7 +4233,8 @@ * Occurs relatively often in object oriented code. */ -#define DUK__GETPROP_BODY(barg,carg) { \ +#define DUK__GETPROP_BODY(barg, carg) \ + { \ /* A -> target reg \ * B -> object reg/const (may be const e.g. in "'foo'1") \ * C -> key reg/const \ @@ -4188,7 +4242,8 @@ (void) duk_hobject_getprop(thr, (barg), (carg)); \ DUK__REPLACE_TOP_A_BREAK(); \ } -#define DUK__GETPROPC_BODY(barg,carg) { \ +#define DUK__GETPROPC_BODY(barg, carg) \ + { \ /* Same as GETPROP but callability check for property-based calls. */ \ duk_tval *tv__targ; \ (void) duk_hobject_getprop(thr, (barg), (carg)); \ @@ -4203,7 +4258,8 @@ } \ DUK__REPLACE_TOP_A_BREAK(); \ } -#define DUK__PUTPROP_BODY(aarg,barg,carg) { \ +#define DUK__PUTPROP_BODY(aarg, barg, carg) \ + { \ /* A -> object reg \ * B -> key reg/const \ * C -> value reg/const \ @@ -4214,7 +4270,8 @@ (void) duk_hobject_putprop(thr, (aarg), (barg), (carg), DUK__STRICT()); \ break; \ } -#define DUK__DELPROP_BODY(barg,carg) { \ +#define DUK__DELPROP_BODY(barg, carg) \ + { \ /* A -> result reg \ * B -> object reg \ * C -> key reg/const \ @@ -4243,9 +4300,9 @@ case DUK_OP_PUTPROP_CC: DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); case DUK_OP_DELPROP_RR: - case DUK_OP_DELPROP_RC: /* B is always reg */ + case DUK_OP_DELPROP_RC: /* B is always reg */ DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_GETPROP_RR: DUK__GETPROP_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_GETPROP_CR: @@ -4272,11 +4329,11 @@ DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_PUTPROP_CC: DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); - case DUK_OP_DELPROP_RR: /* B is always reg */ + case DUK_OP_DELPROP_RR: /* B is always reg */ DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_DELPROP_RC: DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* No fast path for DECLVAR now, it's quite a rare instruction. */ case DUK_OP_DECLVAR_RR: @@ -4309,7 +4366,7 @@ if (is_func_decl) { duk_push_tval(thr, DUK__REGCONSTP_C(ins)); } else { - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } tv1 = DUK_GET_TVAL_NEGIDX(thr, -1); @@ -4345,11 +4402,11 @@ */ duk_push_tval(thr, DUK__REGCONSTP_C(ins)); - duk_push_tval(thr, DUK__REGCONSTP_B(ins)); /* -> ... escaped_source bytecode */ - duk_regexp_create_instance(thr); /* -> ... regexp_instance */ + duk_push_tval(thr, DUK__REGCONSTP_B(ins)); /* -> ... escaped_source bytecode */ + duk_regexp_create_instance(thr); /* -> ... regexp_instance */ DUK__REPLACE_TOP_A_BREAK(); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* XXX: 'c' is unused, use whole BC, etc. */ case DUK_OP_CSVAR_RR: @@ -4378,13 +4435,13 @@ name = DUK_TVAL_GET_STRING(tv1); DUK_ASSERT(name != NULL); act = thr->callstack_curr; - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ idx = (duk_uint_fast_t) DUK_DEC_A(ins); /* Could add direct value stack handling. */ - duk_replace(thr, (duk_idx_t) (idx + 1)); /* 'this' binding */ - duk_replace(thr, (duk_idx_t) idx); /* variable value (function, we hope, not checked here) */ + duk_replace(thr, (duk_idx_t) (idx + 1)); /* 'this' binding */ + duk_replace(thr, (duk_idx_t) idx); /* variable value (function, we hope, not checked here) */ break; } @@ -4399,7 +4456,9 @@ */ DUK_DDD(DUK_DDDPRINT("CLOSURE to target register %ld, fnum %ld (count %ld)", - (long) DUK_DEC_A(ins), (long) DUK_DEC_BC(ins), (long) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN()))); + (long) DUK_DEC_A(ins), + (long) DUK_DEC_BC(ins), + (long) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN()))); DUK_ASSERT_DISABLE(bc >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) bc < (duk_uint_t) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN())); @@ -4410,8 +4469,8 @@ DUK_ASSERT(fun_temp != NULL); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(fun_temp)); - DUK_DDD(DUK_DDDPRINT("CLOSURE: function template is: %p -> %!O", - (void *) fun_temp, (duk_heaphdr *) fun_temp)); + DUK_DDD( + DUK_DDDPRINT("CLOSURE: function template is: %p -> %!O", (void *) fun_temp, (duk_heaphdr *) fun_temp)); if (act->lex_env == NULL) { DUK_ASSERT(act->var_env == NULL); @@ -4425,11 +4484,7 @@ * new variable declaration environment, so only lex_env * matters here. */ - duk_js_push_closure(thr, - (duk_hcompfunc *) fun_temp, - act->var_env, - act->lex_env, - 1 /*add_auto_proto*/); + duk_js_push_closure(thr, (duk_hcompfunc *) fun_temp, act->var_env, act->lex_env, 1 /*add_auto_proto*/); DUK__REPLACE_TOP_A_BREAK(); } @@ -4444,8 +4499,8 @@ DUK_ASSERT(name != NULL); act = thr->callstack_curr; DUK_ASSERT(act != NULL); - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ - duk_pop_unsafe(thr); /* 'this' binding is not needed here */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + duk_pop_unsafe(thr); /* 'this' binding is not needed here */ DUK__REPLACE_TOP_A_BREAK(); } @@ -4463,7 +4518,7 @@ * should be reworked. */ - tv1 = DUK__REGP_A(ins); /* val */ + tv1 = DUK__REGP_A(ins); /* val */ act = thr->callstack_curr; duk_js_putvar_activation(thr, act, name, tv1, DUK__STRICT()); break; @@ -4493,7 +4548,8 @@ break; } -#define DUK__RETURN_SHARED() do { \ +#define DUK__RETURN_SHARED() \ + do { \ duk_small_uint_t ret_result; \ /* duk__handle_return() is guaranteed never to throw, except \ * for potential out-of-memory situations which will then \ @@ -4512,14 +4568,14 @@ case DUK_OP_RETCONST: case DUK_OP_RETCONSTN: case DUK_OP_RETUNDEF: { - /* BC -> return value reg/const */ + /* BC -> return value reg/const */ DUK__SYNC_AND_NULL_CURR_PC(); if (op == DUK_OP_RETREG) { duk_push_tval(thr, DUK__REGP_BC(ins)); } else if (op == DUK_OP_RETUNDEF) { - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } else { DUK_ASSERT(op == DUK_OP_RETCONST || op == DUK_OP_RETCONSTN); @@ -4528,7 +4584,7 @@ DUK__RETURN_SHARED(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_RETREG: { duk_tval *tv; @@ -4558,18 +4614,18 @@ DUK_TVAL_SET_TVAL(thr->valstack_top, tv); #if defined(DUK_USE_REFERENCE_COUNTING) /* Without refcounting only RETCONSTN is used. */ - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv)); /* no INCREF for this constant */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv)); /* no INCREF for this constant */ #endif thr->valstack_top++; DUK__RETURN_SHARED(); } case DUK_OP_RETUNDEF: { DUK__SYNC_AND_NULL_CURR_PC(); - thr->valstack_top++; /* value at valstack top is already undefined by valstack policy */ + thr->valstack_top++; /* value at valstack top is already undefined by valstack policy */ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); DUK__RETURN_SHARED(); } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LABEL: { duk_activation *act; @@ -4582,8 +4638,8 @@ DUK_ASSERT(cat != NULL); cat->flags = (duk_uint32_t) (DUK_CAT_TYPE_LABEL | (bc << DUK_CAT_LABEL_SHIFT)); - cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ - cat->idx_base = 0; /* unused for label */ + cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ + cat->idx_base = 0; /* unused for label */ cat->h_varname = NULL; act = thr->callstack_curr; @@ -4593,10 +4649,13 @@ DUK_DDD(DUK_DDDPRINT("LABEL catcher: flags=0x%08lx, pc_base=%ld, " "idx_base=%ld, h_varname=%!O, label_id=%ld", - (long) cat->flags, (long) cat->pc_base, - (long) cat->idx_base, (duk_heaphdr *) cat->h_varname, (long) DUK_CAT_GET_LABEL(cat))); + (long) cat->flags, + (long) cat->pc_base, + (long) cat->idx_base, + (duk_heaphdr *) cat->h_varname, + (long) DUK_CAT_GET_LABEL(cat))); - curr_pc += 2; /* skip jump slots */ + curr_pc += 2; /* skip jump slots */ break; } @@ -4638,7 +4697,7 @@ /* XXX: move to helper, too large to be inline here */ case DUK_OP_TRYCATCH: { duk__handle_op_trycatch(thr, ins, curr_pc); - curr_pc += 2; /* skip jump slots */ + curr_pc += 2; /* skip jump slots */ break; } @@ -4683,8 +4742,8 @@ (duk_tval *) duk_get_tval(thr, -1))); #if defined(DUK_USE_AUGMENT_ERROR_THROW) duk_err_augment_error_throw(thr); - DUK_DDD(DUK_DDDPRINT("THROW ERROR (BYTECODE): %!dT (after throw augment)", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD( + DUK_DDDPRINT("THROW ERROR (BYTECODE): %!dT (after throw augment)", (duk_tval *) duk_get_tval(thr, -1))); #endif duk_err_setup_ljstate1(thr, DUK_LJ_TYPE_THROW, DUK_GET_TVAL_NEGIDX(thr, -1)); @@ -4692,7 +4751,7 @@ duk_err_check_debugger_integration(thr); #endif - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ duk_err_longjmp(thr); DUK_UNREACHABLE(); break; @@ -4729,20 +4788,19 @@ DUK_TVAL_SET_TVAL(&tv_tmp2, tv2); tv3 = DUK__REGP(a); DUK_TVAL_SET_TVAL(tv1, tv3); - DUK_TVAL_INCREF(thr, tv1); /* no side effects */ - DUK_TVAL_SET_UNDEFINED(tv2); /* no need for incref */ + DUK_TVAL_INCREF(thr, tv1); /* no side effects */ + DUK_TVAL_SET_UNDEFINED(tv2); /* no need for incref */ DUK_TVAL_DECREF(thr, &tv_tmp1); DUK_TVAL_DECREF(thr, &tv_tmp2); #endif break; } - - /* XXX: in some cases it's faster NOT to reuse the value - * stack but rather copy the arguments on top of the stack - * (mainly when the calling value stack is large and the value - * stack resize would be large). - */ + /* XXX: in some cases it's faster NOT to reuse the value + * stack but rather copy the arguments on top of the stack + * (mainly when the calling value stack is large and the value + * stack resize would be large). + */ case DUK_OP_CALL0: case DUK_OP_CALL1: @@ -4903,7 +4961,7 @@ } count = (duk_small_uint_fast_t) DUK_DEC_C(ins); - DUK_ASSERT(count > 0); /* compiler guarantees */ + DUK_ASSERT(count > 0); /* compiler guarantees */ idx_end = idx + count; #if defined(DUK_USE_EXEC_INDIRECT_BOUND_CHECK) @@ -4927,11 +4985,10 @@ /* XXX: faster initialization (direct access or better primitives) */ duk_dup(thr, (duk_idx_t) idx); duk_dup(thr, (duk_idx_t) (idx + 1)); - duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_WRITABLE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE); + duk_def_prop(thr, + obj_idx, + DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_WRITABLE | + DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE); idx += 2; } while (idx < idx_end); break; @@ -4966,7 +5023,7 @@ } count = (duk_small_uint_fast_t) DUK_DEC_C(ins); - DUK_ASSERT(count > 0 + 1); /* compiler guarantees */ + DUK_ASSERT(count > 0 + 1); /* compiler guarantees */ idx_end = idx + count; #if defined(DUK_USE_EXEC_INDIRECT_BOUND_CHECK) @@ -5093,7 +5150,7 @@ duk_push_new_target(thr); DUK__REPLACE_TOP_BC_BREAK(); } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if !defined(DUK_USE_EXEC_PREFER_SIZE) #if !defined(DUK_USE_ES7_EXP_OPERATOR) @@ -5156,16 +5213,16 @@ case DUK_OP_UNUSED253: case DUK_OP_UNUSED254: case DUK_OP_UNUSED255: - /* Force all case clauses to map to an actual handler - * so that the compiler can emit a jump without a bounds - * check: the switch argument is a duk_uint8_t so that - * the compiler may be able to figure it out. This is - * a small detail and obviously compiler dependent. - */ - /* default: clause omitted on purpose */ -#else /* DUK_USE_EXEC_PREFER_SIZE */ + /* Force all case clauses to map to an actual handler + * so that the compiler can emit a jump without a bounds + * check: the switch argument is a duk_uint8_t so that + * the compiler may be able to figure it out. This is + * a small detail and obviously compiler dependent. + */ + /* default: clause omitted on purpose */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ default: -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ { /* Default case catches invalid/unsupported opcodes. */ DUK_D(DUK_DPRINT("invalid opcode: %ld - %!I", (long) op, ins)); @@ -5173,7 +5230,7 @@ break; } - } /* end switch */ + } /* end switch */ continue; @@ -5184,10 +5241,10 @@ */ #if defined(DUK_USE_EXEC_PREFER_SIZE) - replace_top_a: + replace_top_a: DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); continue; - replace_top_bc: + replace_top_bc: DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); continue; #endif @@ -5195,7 +5252,7 @@ DUK_WO_NORETURN(return;); #if !defined(DUK_USE_VERBOSE_EXECUTOR_ERRORS) - internal_error: +internal_error: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); #endif
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_js_ops.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_js_ops.c
Changed
@@ -161,19 +161,10 @@ /* Quite lenient, e.g. allow empty as zero, but don't allow trailing * garbage. */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_INF | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO | - DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT | - DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT | - DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_PLUS | DUK_S2N_FLAG_ALLOW_MINUS | + DUK_S2N_FLAG_ALLOW_INF | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO | DUK_S2N_FLAG_ALLOW_LEADING_ZERO | + DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT | DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT | DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT; duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); @@ -183,9 +174,9 @@ #else thr->valstack_top--; DUK_ASSERT(DUK_TVAL_IS_NUMBER(thr->valstack_top)); - DUK_ASSERT(DUK_TVAL_IS_DOUBLE(thr->valstack_top)); /* no fastint conversion in numconv now */ + DUK_ASSERT(DUK_TVAL_IS_DOUBLE(thr->valstack_top)); /* no fastint conversion in numconv now */ DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(thr->valstack_top)); - d = DUK_TVAL_GET_DOUBLE(thr->valstack_top); /* assumes not a fastint */ + d = DUK_TVAL_GET_DOUBLE(thr->valstack_top); /* assumes not a fastint */ DUK_TVAL_SET_UNDEFINED(thr->valstack_top); #endif @@ -224,11 +215,11 @@ duk_push_hstring(thr, h); return duk__tonumber_string_raw(thr); } - case DUK_TAG_BUFFER: /* plain buffer treated like object */ + case DUK_TAG_BUFFER: /* plain buffer treated like object */ case DUK_TAG_OBJECT: { duk_double_t d; duk_push_tval(thr, tv); - duk_to_primitive(thr, -1, DUK_HINT_NUMBER); /* 'tv' becomes invalid */ + duk_to_primitive(thr, -1, DUK_HINT_NUMBER); /* 'tv' becomes invalid */ /* recursive call for a primitive value (guaranteed not to cause second * recursion). @@ -283,7 +274,7 @@ */ return duk_double_trunc_towards_zero(x); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* NaN and Infinity have the same exponent so it's a cheap * initial check for the rare path. */ @@ -296,12 +287,12 @@ } else { return duk_double_trunc_towards_zero(x); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } DUK_INTERNAL duk_double_t duk_js_tointeger(duk_hthread *thr, duk_tval *tv) { /* XXX: fastint */ - duk_double_t d = duk_js_tonumber(thr, tv); /* invalidates tv */ + duk_double_t d = duk_js_tonumber(thr, tv); /* invalidates tv */ return duk_js_tointeger_number(d); } @@ -311,11 +302,11 @@ /* combined algorithm matching E5 Sections 9.5 and 9.6 */ DUK_LOCAL duk_double_t duk__toint32_touint32_helper(duk_double_t x, duk_bool_t is_toint32) { -#if defined (DUK_USE_PREFER_SIZE) +#if defined(DUK_USE_PREFER_SIZE) duk_small_int_t c; #endif -#if defined (DUK_USE_PREFER_SIZE) +#if defined(DUK_USE_PREFER_SIZE) c = (duk_small_int_t) DUK_FPCLASSIFY(x); if (c == DUK_FP_NAN || c == DUK_FP_ZERO || c == DUK_FP_INFINITE) { return 0.0; @@ -333,18 +324,18 @@ * differs from what Javascript wants (see Section 9.6). */ - x = DUK_FMOD(x, DUK_DOUBLE_2TO32); /* -> x in -2**32, 2**32 */ + x = DUK_FMOD(x, DUK_DOUBLE_2TO32); /* -> x in -2**32, 2**32 */ if (x < 0.0) { x += DUK_DOUBLE_2TO32; } - DUK_ASSERT(x >= 0 && x < DUK_DOUBLE_2TO32); /* -> x in 0, 2**32 */ + DUK_ASSERT(x >= 0 && x < DUK_DOUBLE_2TO32); /* -> x in 0, 2**32 */ if (is_toint32) { if (x >= DUK_DOUBLE_2TO31) { /* x in 2**31, 2**32 */ - x -= DUK_DOUBLE_2TO32; /* -> x in -2**31,2**31 */ + x -= DUK_DOUBLE_2TO32; /* -> x in -2**31,2**31 */ } } @@ -360,15 +351,14 @@ } #endif - d = duk_js_tonumber(thr, tv); /* invalidates tv */ + d = duk_js_tonumber(thr, tv); /* invalidates tv */ d = duk__toint32_touint32_helper(d, 1); DUK_ASSERT(DUK_FPCLASSIFY(d) == DUK_FP_ZERO || DUK_FPCLASSIFY(d) == DUK_FP_NORMAL); - DUK_ASSERT(d >= -2147483648.0 && d <= 2147483647.0); /* -0x80000000,0x7fffffff */ - DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_int32_t) d))); /* whole, won't clip */ + DUK_ASSERT(d >= -2147483648.0 && d <= 2147483647.0); /* -0x80000000,0x7fffffff */ + DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_int32_t) d))); /* whole, won't clip */ return (duk_int32_t) d; } - DUK_INTERNAL duk_uint32_t duk_js_touint32(duk_hthread *thr, duk_tval *tv) { duk_double_t d; @@ -378,13 +368,12 @@ } #endif - d = duk_js_tonumber(thr, tv); /* invalidates tv */ + d = duk_js_tonumber(thr, tv); /* invalidates tv */ d = duk__toint32_touint32_helper(d, 0); DUK_ASSERT(DUK_FPCLASSIFY(d) == DUK_FP_ZERO || DUK_FPCLASSIFY(d) == DUK_FP_NORMAL); - DUK_ASSERT(d >= 0.0 && d <= 4294967295.0); /* 0x00000000, 0xffffffff */ - DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_uint32_t) d))); /* whole, won't clip */ + DUK_ASSERT(d >= 0.0 && d <= 4294967295.0); /* 0x00000000, 0xffffffff */ + DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_uint32_t) d))); /* whole, won't clip */ return (duk_uint32_t) d; - } DUK_INTERNAL duk_uint16_t duk_js_touint16(duk_hthread *thr, duk_tval *tv) { @@ -434,7 +423,7 @@ return 1; } return 0; -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ /* Better equivalent algorithm. If the compiler is compliant, C and * ECMAScript semantics are identical for this particular comparison. * In particular, NaNs must never compare equal and zeroes must compare @@ -454,7 +443,7 @@ DUK_ASSERT(!(DUK_FPCLASSIFY(x) == DUK_FP_ZERO && DUK_FPCLASSIFY(y) == DUK_FP_ZERO)); return 0; } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ } DUK_LOCAL duk_bool_t duk__js_samevalue_number(duk_double_t x, duk_double_t y) { @@ -484,7 +473,7 @@ */ return (x == y); -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ duk_small_int_t cx = (duk_small_int_t) DUK_FPCLASSIFY(x); duk_small_int_t cy = (duk_small_int_t) DUK_FPCLASSIFY(y); @@ -519,7 +508,7 @@ } return 0; } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ } DUK_INTERNAL duk_bool_t duk_js_equals_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags) { @@ -545,10 +534,9 @@ } else { return 0; } - } - else + } else #endif - if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { + if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { duk_double_t d1, d2; /* Catches both doubles and cases where only one argument is @@ -622,7 +610,7 @@ return 0; } - DUK_ASSERT(flags == 0); /* non-strict equality from here on */ + DUK_ASSERT(flags == 0); /* non-strict equality from here on */ /* * Types are different; various cases for non-strict comparison @@ -679,34 +667,29 @@ } /* String-number-symbol/object -> coerce object to primitive (apparently without hint), then try again. */ - if ((type_mask_x & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER)) && - (type_mask_y & DUK_TYPE_MASK_OBJECT)) { + if ((type_mask_x & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER)) && (type_mask_y & DUK_TYPE_MASK_OBJECT)) { /* No symbol check needed because symbols and strings are accepted. */ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -1, DUK_HINT_NONE); /* apparently no hint? */ + duk_to_primitive(thr, -1, DUK_HINT_NONE); /* apparently no hint? */ goto recursive_call; } - if ((type_mask_x & DUK_TYPE_MASK_OBJECT) && - (type_mask_y & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER))) { + if ((type_mask_x & DUK_TYPE_MASK_OBJECT) && (type_mask_y & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER))) { /* No symbol check needed because symbols and strings are accepted. */ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -2, DUK_HINT_NONE); /* apparently no hint? */ + duk_to_primitive(thr, -2, DUK_HINT_NONE); /* apparently no hint? */ goto recursive_call; } /* Nothing worked -> not equal. */ return 0; - recursive_call: +recursive_call: /* Shared code path to call the helper again with arguments on stack top. */ { duk_bool_t rc; - rc = duk_js_equals_helper(thr, - DUK_GET_TVAL_NEGIDX(thr, -2), - DUK_GET_TVAL_NEGIDX(thr, -1), - 0 /*flags:nonstrict*/); + rc = duk_js_equals_helper(thr, DUK_GET_TVAL_NEGIDX(thr, -2), DUK_GET_TVAL_NEGIDX(thr, -1), 0 /*flags:nonstrict*/); duk_pop_2_unsafe(thr); return rc; } @@ -723,7 +706,10 @@ * needs to push stuff on the stack anyway... */ -DUK_INTERNAL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, const duk_uint8_t *buf2, duk_size_t len1, duk_size_t len2) { +DUK_INTERNAL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, + const duk_uint8_t *buf2, + duk_size_t len1, + duk_size_t len2) { duk_size_t prefix_len; duk_small_int_t rc; @@ -732,9 +718,7 @@ /* duk_memcmp() is guaranteed to return zero (equal) for zero length * inputs. */ - rc = duk_memcmp_unsafe((const void *) buf1, - (const void *) buf2, - (size_t) prefix_len); + rc = duk_memcmp_unsafe((const void *) buf1, (const void *) buf2, (size_t) prefix_len); if (rc < 0) { return -1; @@ -776,7 +760,7 @@ (duk_size_t) DUK_HSTRING_GET_BYTELEN(h2)); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL duk_small_int_t duk_js_buffer_compare(duk_heap *heap, duk_hbuffer *h1, duk_hbuffer *h2) { /* Similar to String comparison. */ @@ -813,47 +797,47 @@ s2 = (duk_small_int_t) DUK_SIGNBIT(d2); if (c1 == DUK_FP_NAN || c2 == DUK_FP_NAN) { - return 0; /* Always false, regardless of negation. */ + return 0; /* Always false, regardless of negation. */ } if (c1 == DUK_FP_ZERO && c2 == DUK_FP_ZERO) { /* For all combinations: +0 < +0, +0 < -0, -0 < +0, -0 < -0, * steps e, f, and g. */ - return retval; /* false */ + return retval; /* false */ } if (d1 == d2) { - return retval; /* false */ + return retval; /* false */ } if (c1 == DUK_FP_INFINITE && s1 == 0) { /* x == +Infinity */ - return retval; /* false */ + return retval; /* false */ } if (c2 == DUK_FP_INFINITE && s2 == 0) { /* y == +Infinity */ - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } if (c2 == DUK_FP_INFINITE && s2 != 0) { /* y == -Infinity */ - return retval; /* false */ + return retval; /* false */ } if (c1 == DUK_FP_INFINITE && s1 != 0) { /* x == -Infinity */ - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } if (d1 < d2) { - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } - return retval; /* false */ + return retval; /* false */ } -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ DUK_LOCAL duk_bool_t duk__compare_number(duk_bool_t retval, duk_double_t d1, duk_double_t d2) { /* This comparison tree relies doesn't match the exact steps in * E5 Section 11.8.5 but should produce the same results. The @@ -890,39 +874,35 @@ * results in false return (see e.g. Section * 11.8.3) - hence special treatment here. */ - return 0; /* zero regardless of negation */ + return 0; /* zero regardless of negation */ } else { return retval; } } } } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ DUK_INTERNAL duk_bool_t duk_js_compare_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags) { duk_double_t d1, d2; duk_small_int_t rc; duk_bool_t retval; - DUK_ASSERT(DUK_COMPARE_FLAG_NEGATE == 1); /* Rely on this flag being lowest. */ + DUK_ASSERT(DUK_COMPARE_FLAG_NEGATE == 1); /* Rely on this flag being lowest. */ retval = flags & DUK_COMPARE_FLAG_NEGATE; DUK_ASSERT(retval == 0 || retval == 1); /* Fast path for fastints */ #if defined(DUK_USE_FASTINT) if (DUK_LIKELY(DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y))) { - return duk__compare_fastint(retval, - DUK_TVAL_GET_FASTINT(tv_x), - DUK_TVAL_GET_FASTINT(tv_y)); + return duk__compare_fastint(retval, DUK_TVAL_GET_FASTINT(tv_x), DUK_TVAL_GET_FASTINT(tv_y)); } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* Fast path for numbers (one of which may be a fastint) */ #if !defined(DUK_USE_PREFER_SIZE) if (DUK_LIKELY(DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y))) { - return duk__compare_number(retval, - DUK_TVAL_GET_NUMBER(tv_x), - DUK_TVAL_GET_NUMBER(tv_y)); + return duk__compare_number(retval, DUK_TVAL_GET_NUMBER(tv_x), DUK_TVAL_GET_NUMBER(tv_y)); } #endif @@ -989,7 +969,7 @@ thr->valstack_top -= 2; tv_x = thr->valstack_top; tv_y = tv_x + 1; - DUK_TVAL_SET_UNDEFINED(tv_x); /* Value stack policy */ + DUK_TVAL_SET_UNDEFINED(tv_x); /* Value stack policy */ DUK_TVAL_SET_UNDEFINED(tv_y); #endif @@ -1043,8 +1023,8 @@ if (!skip_sym_check) { if (duk_get_method_stridx(thr, -1, DUK_STRIDX_WELLKNOWN_SYMBOL_HAS_INSTANCE)) { /* ... lhs rhs func */ - duk_insert(thr, -3); /* -> ... func lhs rhs */ - duk_swap_top(thr, -2); /* -> ... func rhs(this) lhs */ + duk_insert(thr, -3); /* -> ... func lhs rhs */ + duk_swap_top(thr, -2); /* -> ... func rhs(this) lhs */ duk_call_method(thr, 1); return duk_to_boolean_top_pop(thr); } @@ -1076,7 +1056,7 @@ if (DUK_HOBJECT_HAS_BOUNDFUNC(func)) { duk_push_tval(thr, &((duk_hboundfunc *) (void *) func)->target); duk_replace(thr, -2); - func = duk_require_hobject(thr, -1); /* lightfunc throws */ + func = duk_require_hobject(thr, -1); /* lightfunc throws */ /* Rely on Function.prototype.bind() never creating bound * functions whose target is not proper. @@ -1116,19 +1096,19 @@ DUK_ASSERT(val != NULL); break; case DUK_TAG_OBJECT: - skip_first = 1; /* Ignore object itself on first round. */ + skip_first = 1; /* Ignore object itself on first round. */ val = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(val != NULL); break; default: goto pop2_and_false; } - DUK_ASSERT(val != NULL); /* Loop doesn't actually rely on this. */ + DUK_ASSERT(val != NULL); /* Loop doesn't actually rely on this. */ /* Look up .prototype of rval. Leave it on the value stack in case it * has been virtualized (e.g. getter, Proxy trap). */ - duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_PROTOTYPE); /* -> ... lval rval rval.prototype */ + duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_PROTOTYPE); /* -> ... lval rval rval.prototype */ #if defined(DUK_USE_VERBOSE_ERRORS) proto = duk_get_hobject(thr, -1); if (proto == NULL) { @@ -1181,24 +1161,24 @@ DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); DUK_WO_NORETURN(return 0;); - pop2_and_false: +pop2_and_false: duk_pop_2_unsafe(thr); return 0; - pop3_and_false: +pop3_and_false: duk_pop_3_unsafe(thr); return 0; - pop3_and_true: +pop3_and_true: duk_pop_3_unsafe(thr); return 1; - error_invalid_rval: +error_invalid_rval: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_INSTANCEOF_RVAL); DUK_WO_NORETURN(return 0;); #if defined(DUK_USE_VERBOSE_ERRORS) - error_invalid_rval_noproto: +error_invalid_rval_noproto: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO); DUK_WO_NORETURN(return 0;); #endif @@ -1250,9 +1230,7 @@ (void) duk_to_property_key_hstring(thr, -2); - retval = duk_hobject_hasprop(thr, - DUK_GET_TVAL_NEGIDX(thr, -1), - DUK_GET_TVAL_NEGIDX(thr, -2)); + retval = duk_hobject_hasprop(thr, DUK_GET_TVAL_NEGIDX(thr, -1), DUK_GET_TVAL_NEGIDX(thr, -2)); duk_pop_2_unsafe(thr); return retval; @@ -1412,7 +1390,7 @@ } res = 0xfffffffaUL + dig; DUK_ASSERT(res >= 0xfffffffaUL); - DUK_ASSERT_DISABLE(res <= 0xffffffffUL); /* range */ + DUK_ASSERT_DISABLE(res <= 0xffffffffUL); /* range */ } else { res = res * 10U + dig; if (DUK_UNLIKELY(res == 0)) { @@ -1437,7 +1415,7 @@ return res; - parse_fail: +parse_fail: return DUK_HSTRING_NO_ARRAY_INDEX; } @@ -1475,4 +1453,4 @@ } return duk_js_to_arrayindex_hstring_fast_known(h); } -#endif /* DUK_USE_HSTRING_ARRIDX */ +#endif /* DUK_USE_HSTRING_ARRIDX */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_js_var.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_js_var.c
Changed
@@ -38,10 +38,10 @@ typedef struct { duk_hobject *env; - duk_hobject *holder; /* for object-bound identifiers */ - duk_tval *value; /* for register-bound and declarative env identifiers */ - duk_uint_t attrs; /* property attributes for identifier (relevant if value != NULL) */ - duk_bool_t has_this; /* for object-bound identifiers: provide 'this' binding */ + duk_hobject *holder; /* for object-bound identifiers */ + duk_tval *value; /* for register-bound and declarative env identifiers */ + duk_uint_t attrs; /* property attributes for identifier (relevant if value != NULL) */ + duk_bool_t has_this; /* for object-bound identifiers: provide 'this' binding */ } duk__id_lookup_result; /* @@ -145,7 +145,7 @@ DUK_ASSERT(fun_clos != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) fun_clos) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); - duk_push_hobject(thr, &fun_temp->obj); /* -> ... closure template */ + duk_push_hobject(thr, &fun_temp->obj); /* -> ... closure template */ DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun_clos)); DUK_ASSERT(DUK_HCOMPFUNC_GET_DATA(thr->heap, fun_clos) == NULL); @@ -253,9 +253,9 @@ } /* -> ... closure template env */ - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); @@ -263,7 +263,7 @@ DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) new_env, proto); DUK_HOBJECT_INCREF_ALLOWNULL(thr, proto); - DUK_ASSERT(new_env->thread == NULL); /* Closed. */ + DUK_ASSERT(new_env->thread == NULL); /* Closed. */ DUK_ASSERT(new_env->varmap == NULL); /* It's important that duk_xdef_prop() is a 'raw define' so that any @@ -277,8 +277,8 @@ */ (void) duk_get_prop_stridx_short(thr, -2, DUK_STRIDX_NAME); /* -> ... closure template env funcname */ - duk_dup_m4(thr); /* -> ... closure template env funcname closure */ - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> ... closure template env */ + duk_dup_m4(thr); /* -> ... closure template env funcname closure */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> ... closure template env */ /* envfuncname = closure */ /* ... closure template env */ @@ -290,9 +290,8 @@ duk_pop_unsafe(thr); /* ... closure template */ - } - else -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ + } else +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ { /* * Other cases (function declaration, anonymous function expression, @@ -320,7 +319,7 @@ DUK_HCOMPFUNC_SET_LEXENV(thr->heap, fun_clos, outer_lex_env); DUK_HCOMPFUNC_SET_VARENV(thr->heap, fun_clos, outer_var_env); - DUK_HOBJECT_INCREF(thr, outer_lex_env); /* NULLs not allowed; asserted on entry */ + DUK_HOBJECT_INCREF(thr, outer_lex_env); /* NULLs not allowed; asserted on entry */ DUK_HOBJECT_INCREF(thr, outer_var_env); } DUK_DDD(DUK_DDDPRINT("closure varenv -> %!ipO, lexenv -> %!ipO", @@ -379,7 +378,7 @@ DUK_DD(DUK_DDPRINT("closure length defaulted from nargs -> %ld", (long) len_value)); } - duk_push_uint(thr, len_value); /* ... closure template len_value */ + duk_push_uint(thr, len_value); /* ... closure template len_value */ duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* @@ -399,11 +398,14 @@ /* ... closure template */ if (add_auto_proto) { - duk_push_object(thr); /* -> ... closure template newobj */ - duk_dup_m3(thr); /* -> ... closure template newobj closure */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC); /* -> ... closure template newobj */ - duk_compact(thr, -1); /* compact the prototype */ - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); /* -> ... closure template */ + duk_push_object(thr); /* -> ... closure template newobj */ + duk_dup_m3(thr); /* -> ... closure template newobj closure */ + duk_xdef_prop_stridx_short(thr, + -2, + DUK_STRIDX_CONSTRUCTOR, + DUK_PROPDESC_FLAGS_WC); /* -> ... closure template newobj */ + duk_compact(thr, -1); /* compact the prototype */ + duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); /* -> ... closure template */ } /* @@ -444,7 +446,7 @@ /* ... closure template name */ DUK_ASSERT(duk_is_string(thr, -1)); DUK_DD(DUK_DDPRINT("setting function instance name to %!T", duk_get_tval(thr, -1))); - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); /* -> ... closure template */ + duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); /* -> ... closure template */ } else { /* Anonymous functions don't have a .name in ES2015, so don't set * it on the instance either. The instance will then inherit @@ -476,10 +478,8 @@ DUK_ASSERT(duk_has_prop_stridx(thr, -2, DUK_STRIDX_LENGTH) != 0); DUK_ASSERT(add_auto_proto == 0 || duk_has_prop_stridx(thr, -2, DUK_STRIDX_PROTOTYPE) != 0); /* May be missing .name */ - DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || - duk_has_prop_stridx(thr, -2, DUK_STRIDX_CALLER) != 0); - DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || - duk_has_prop_stridx(thr, -2, DUK_STRIDX_LC_ARGUMENTS) != 0); + DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || duk_has_prop_stridx(thr, -2, DUK_STRIDX_CALLER) != 0); + DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || duk_has_prop_stridx(thr, -2, DUK_STRIDX_LC_ARGUMENTS) != 0); /* * Finish @@ -510,8 +510,8 @@ duk_hstring *key; key = DUK_HOBJECT_E_GET_KEY(thr->heap, varmap, i); - DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ - DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ + DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ + DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ /* Predefine as 'undefined' to reserve a property slot. * This makes the unwind process (where register values @@ -528,9 +528,7 @@ /* shared helper */ DUK_INTERNAL -duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, - duk_hobject *func, - duk_size_t bottom_byteoff) { +duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, duk_hobject *func, duk_size_t bottom_byteoff) { duk_hdecenv *env; duk_hobject *parent; duk_hcompfunc *f; @@ -546,15 +544,13 @@ parent = thr->builtinsDUK_BIDX_GLOBAL_ENV; } - env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + env = duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(env != NULL); duk_push_hobject(thr, (duk_hobject *) env); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) env, parent); - DUK_HOBJECT_INCREF_ALLOWNULL(thr, parent); /* parent env is the prototype */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, parent); /* parent env is the prototype */ /* open scope information, for compiled functions only */ @@ -588,15 +584,14 @@ } DUK_INTERNAL -void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, - duk_activation *act) { +void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, duk_activation *act) { duk_hobject *func; duk_hobject *env; DUK_ASSERT(thr != NULL); func = DUK_ACT_GET_FUNC(act); DUK_ASSERT(func != NULL); - DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound functions are never in act 'func' */ + DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound functions are never in act 'func' */ /* * Delayed initialization only occurs for 'NEWENV' functions. @@ -625,7 +620,7 @@ act->lex_env = env; act->var_env = env; - DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (here 2 times) */ + DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (here 2 times) */ DUK_HOBJECT_INCREF(thr, env); duk_pop_unsafe(thr); @@ -695,12 +690,12 @@ duk_size_t regbase_byteoff; key = DUK_HOBJECT_E_GET_KEY(thr->heap, varmap, i); - DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ - DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ + DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ + DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ tv = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, varmap, i); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ + DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv)); regnum = (duk_uint_t) DUK_TVAL_GET_FASTINT_U32(tv); @@ -709,8 +704,10 @@ #endif regbase_byteoff = ((duk_hdecenv *) env)->regbase_byteoff; - DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum >= (duk_uint8_t *) thr->valstack); - DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum < (duk_uint8_t *) thr->valstack_top); + DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum >= + (duk_uint8_t *) thr->valstack); + DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum < + (duk_uint8_t *) thr->valstack_top); /* Write register value into env as named properties. * If property already exists, overwrites silently. @@ -724,7 +721,8 @@ * out-of-memory error should be possible. If this guarantee * is not provided, problems like GH-476 may happen. */ - duk_push_tval(thr, (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum)); + duk_push_tval(thr, + (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum)); DUK_DDD(DUK_DDDPRINT("closing identifier %!O -> reg %ld, value %!T", (duk_heaphdr *) key, (long) regnum, @@ -766,10 +764,7 @@ /* lookup name from an open declarative record's registers */ DUK_LOCAL -duk_bool_t duk__getid_open_decl_env_regs(duk_hthread *thr, - duk_hstring *name, - duk_hdecenv *env, - duk__id_lookup_result *out) { +duk_bool_t duk__getid_open_decl_env_regs(duk_hthread *thr, duk_hstring *name, duk_hdecenv *env, duk__id_lookup_result *out) { duk_tval *tv; duk_size_t reg_rel; @@ -793,20 +788,20 @@ } DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ + DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv)); reg_rel = (duk_size_t) DUK_TVAL_GET_FASTINT_U32(tv); #else reg_rel = (duk_size_t) DUK_TVAL_GET_NUMBER(tv); #endif - DUK_ASSERT_DISABLE(reg_rel >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(reg_rel >= 0); /* unsigned */ tv = (duk_tval *) (void *) ((duk_uint8_t *) env->thread->valstack + env->regbase_byteoff + sizeof(duk_tval) * reg_rel); - DUK_ASSERT(tv >= env->thread->valstack && tv < env->thread->valstack_end); /* XXX: more accurate? */ + DUK_ASSERT(tv >= env->thread->valstack && tv < env->thread->valstack_end); /* XXX: more accurate? */ out->value = tv; - out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ + out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ out->env = (duk_hobject *) env; out->holder = NULL; out->has_this = 0; @@ -815,10 +810,7 @@ /* lookup name from current activation record's functions' registers */ DUK_LOCAL -duk_bool_t duk__getid_activation_regs(duk_hthread *thr, - duk_hstring *name, - duk_activation *act, - duk__id_lookup_result *out) { +duk_bool_t duk__getid_activation_regs(duk_hthread *thr, duk_hstring *name, duk_activation *act, duk__id_lookup_result *out) { duk_tval *tv; duk_hobject *func; duk_hobject *varmap; @@ -856,7 +848,7 @@ tv += reg_rel; out->value = tv; - out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ + out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ out->env = NULL; out->holder = NULL; out->has_this = 0; @@ -912,9 +904,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(found from register bindings when env=NULL)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } @@ -951,8 +946,7 @@ env = thr->builtinsDUK_BIDX_GLOBAL_ENV; } - DUK_DDD(DUK_DDDPRINT("continue lookup from env: %!iO", - (duk_heaphdr *) env)); + DUK_DDD(DUK_DDDPRINT("continue lookup from env: %!iO", (duk_heaphdr *) env)); } /* @@ -995,9 +989,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(declarative environment record, scope open, found in regs)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } @@ -1012,9 +1009,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(declarative environment record, found in properties)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } } else { @@ -1059,7 +1059,7 @@ found = duk_hobject_hasprop(thr, &tv_target_tmp, &tv_name); } else -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ { /* XXX: duk_hobject_hasprop() would be correct for * non-Proxy objects too, but it is about ~20-25% @@ -1070,8 +1070,8 @@ } if (found) { - out->value = NULL; /* can't get value, may be accessor */ - out->attrs = 0; /* irrelevant when out->value == NULL */ + out->value = NULL; /* can't get value, may be accessor */ + out->attrs = 0; /* irrelevant when out->value == NULL */ out->env = env; out->holder = target; out->has_this = ((duk_hobjenv *) env)->has_this; @@ -1079,9 +1079,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(object environment record)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } } @@ -1092,10 +1095,10 @@ goto fail_not_found; } - if (DUK_UNLIKELY(sanity-- == 0)) { - DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); + if (DUK_UNLIKELY(sanity-- == 0)) { + DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); DUK_WO_NORETURN(return 0;); - } + } env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); } @@ -1103,7 +1106,7 @@ * Not found (even in global object) */ - fail_not_found: +fail_not_found: return 0; } @@ -1122,7 +1125,7 @@ * a 'strict' parameter. */ -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_hasvar_envrec(duk_hthread *thr, duk_hobject *env, @@ -1178,11 +1181,7 @@ */ DUK_LOCAL -duk_bool_t duk__getvar_helper(duk_hthread *thr, - duk_hobject *env, - duk_activation *act, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk__getvar_helper(duk_hthread *thr, duk_hobject *env, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag) { duk__id_lookup_result ref; duk_tval tv_tmp_obj; duk_tval tv_tmp_key; @@ -1190,8 +1189,11 @@ DUK_DDD(DUK_DDDPRINT("getvar: thr=%p, env=%p, act=%p, name=%!O " "(env -> %!dO)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); @@ -1199,10 +1201,10 @@ DUK_STATS_INC(thr->heap, stats_getvar_all); - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(env); - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(env); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value) { duk_push_tval(thr, ref.value); @@ -1217,7 +1219,7 @@ DUK_TVAL_SET_OBJECT(&tv_tmp_obj, ref.holder); DUK_TVAL_SET_STRING(&tv_tmp_key, name); - (void) duk_hobject_getprop(thr, &tv_tmp_obj, &tv_tmp_key); /* value */ + (void) duk_hobject_getprop(thr, &tv_tmp_obj, &tv_tmp_key); /* value */ if (ref.has_this) { duk_push_hobject(thr, ref.holder); @@ -1231,7 +1233,8 @@ return 1; } else { if (throw_flag) { - DUK_ERROR_FMT1(thr, DUK_ERR_REFERENCE_ERROR, + DUK_ERROR_FMT1(thr, + DUK_ERR_REFERENCE_ERROR, "identifier '%s' undefined", (const char *) DUK_HSTRING_GET_DATA(name)); DUK_WO_NORETURN(return 0;); @@ -1242,18 +1245,12 @@ } DUK_INTERNAL -duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, - duk_hobject *env, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_bool_t throw_flag) { return duk__getvar_helper(thr, env, NULL, name, throw_flag); } DUK_INTERNAL -duk_bool_t duk_js_getvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk_js_getvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag) { DUK_ASSERT(act != NULL); return duk__getvar_helper(thr, act->lex_env, act, name, throw_flag); } @@ -1290,9 +1287,14 @@ DUK_DDD(DUK_DDDPRINT("putvar: thr=%p, env=%p, act=%p, name=%!O, val=%p, strict=%ld " "(env -> %!dO, val -> %!T)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (void *) val, (long) strict, - (duk_heaphdr *) env, (duk_tval *) val)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (void *) val, + (long) strict, + (duk_heaphdr *) env, + (duk_tval *) val)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); @@ -1303,7 +1305,7 @@ DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); DUK_ASSERT_REFCOUNT_NONZERO_TVAL(val); - DUK_TVAL_SET_TVAL(&tv_tmp_val, val); /* Stabilize. */ + DUK_TVAL_SET_TVAL(&tv_tmp_val, val); /* Stabilize. */ val = NULL; /* @@ -1316,15 +1318,13 @@ * and name 'eval' or 'arguments'. */ - DUK_ASSERT(!strict || - (name != DUK_HTHREAD_STRING_EVAL(thr) && - name != DUK_HTHREAD_STRING_LC_ARGUMENTS(thr))); + DUK_ASSERT(!strict || (name != DUK_HTHREAD_STRING_EVAL(thr) && name != DUK_HTHREAD_STRING_LC_ARGUMENTS(thr))); /* * Lookup variable and update in-place if found. */ - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value && (ref.attrs & DUK_PROPDESC_FLAG_WRITABLE)) { @@ -1337,7 +1337,7 @@ tv_val = ref.value; DUK_ASSERT(tv_val != NULL); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv_val, &tv_tmp_val); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv_val, &tv_tmp_val); /* side effects */ /* ref.value invalidated here */ } else { @@ -1360,7 +1360,8 @@ if (strict) { DUK_DDD(DUK_DDDPRINT("identifier binding not found, strict => reference error")); - DUK_ERROR_FMT1(thr, DUK_ERR_REFERENCE_ERROR, + DUK_ERROR_FMT1(thr, + DUK_ERR_REFERENCE_ERROR, "identifier '%s' undefined", (const char *) DUK_HSTRING_GET_DATA(name)); DUK_WO_NORETURN(return;); @@ -1370,7 +1371,7 @@ DUK_TVAL_SET_OBJECT(&tv_tmp_obj, thr->builtinsDUK_BIDX_GLOBAL); DUK_TVAL_SET_STRING(&tv_tmp_key, name); - (void) duk_hobject_putprop(thr, &tv_tmp_obj, &tv_tmp_key, &tv_tmp_val, 0); /* 0 = no throw */ + (void) duk_hobject_putprop(thr, &tv_tmp_obj, &tv_tmp_key, &tv_tmp_val, 0); /* 0 = no throw */ /* NB: 'val' may be invalidated here because put_value may realloc valstack, * caller beware. @@ -1378,20 +1379,12 @@ } DUK_INTERNAL -void duk_js_putvar_envrec(duk_hthread *thr, - duk_hobject *env, - duk_hstring *name, - duk_tval *val, - duk_bool_t strict) { +void duk_js_putvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_tval *val, duk_bool_t strict) { duk__putvar_helper(thr, env, NULL, name, val, strict); } DUK_INTERNAL -void duk_js_putvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name, - duk_tval *val, - duk_bool_t strict) { +void duk_js_putvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_bool_t strict) { DUK_ASSERT(act != NULL); duk__putvar_helper(thr, act->lex_env, act, name, val, strict); } @@ -1416,25 +1409,25 @@ */ DUK_LOCAL -duk_bool_t duk__delvar_helper(duk_hthread *thr, - duk_hobject *env, - duk_activation *act, - duk_hstring *name) { +duk_bool_t duk__delvar_helper(duk_hthread *thr, duk_hobject *env, duk_activation *act, duk_hstring *name) { duk__id_lookup_result ref; duk_bool_t parents; DUK_DDD(DUK_DDDPRINT("delvar: thr=%p, env=%p, act=%p, name=%!O " "(env -> %!dO)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); /* env and act may be NULL */ - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value && !(ref.attrs & DUK_PROPDESC_FLAG_CONFIGURABLE)) { @@ -1462,7 +1455,7 @@ return 1; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_delvar_envrec(duk_hthread *thr, duk_hobject *env, @@ -1472,9 +1465,7 @@ #endif DUK_INTERNAL -duk_bool_t duk_js_delvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name) { +duk_bool_t duk_js_delvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name) { DUK_ASSERT(act != NULL); return duk__delvar_helper(thr, act->lex_env, act, name); } @@ -1543,9 +1534,13 @@ DUK_DDD(DUK_DDDPRINT("declvar: thr=%p, env=%p, name=%!O, val=%!T, prop_flags=0x%08lx, is_func_decl=%ld " "(env -> %!iO)", - (void *) thr, (void *) env, (duk_heaphdr *) name, - (duk_tval *) val, (unsigned long) prop_flags, - (unsigned int) is_func_decl, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (duk_heaphdr *) name, + (duk_tval *) val, + (unsigned long) prop_flags, + (unsigned int) is_func_decl, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(env != NULL); @@ -1572,7 +1567,7 @@ * environment target object. */ - parents = 0; /* just check 'env' */ + parents = 0; /* just check 'env' */ if (duk__get_identifier_reference(thr, env, name, NULL, parents, &ref)) { duk_int_t e_idx; duk_int_t h_idx; @@ -1587,7 +1582,7 @@ if (!(is_func_decl && env == thr->builtinsDUK_BIDX_GLOBAL_ENV)) { DUK_DDD(DUK_DDDPRINT("re-declare a binding, ignoring")); - return 1; /* 1 -> needs a PUTVAR */ + return 1; /* 1 -> needs a PUTVAR */ } /* @@ -1617,7 +1612,7 @@ * where the property was found (see duk__get_identifier_reference()). */ DUK_ASSERT(DUK_HOBJECT_GET_CLASS_NUMBER(holder) == DUK_HOBJECT_CLASS_GLOBAL); - DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(holder)); /* global object doesn't have array part */ + DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(holder)); /* global object doesn't have array part */ /* XXX: use a helper for prototype traversal; no loop check here */ /* must be found: was found earlier, and cannot be inherited */ @@ -1650,8 +1645,7 @@ "accessor -> reject")); goto fail_existing_attributes; } - if (!((flags & DUK_PROPDESC_FLAG_WRITABLE) && - (flags & DUK_PROPDESC_FLAG_ENUMERABLE))) { + if (!((flags & DUK_PROPDESC_FLAG_WRITABLE) && (flags & DUK_PROPDESC_FLAG_ENUMERABLE))) { DUK_DDD(DUK_DDDPRINT("existing property is a non-configurable " "plain property which is not writable and " "enumerable -> reject")); @@ -1746,13 +1740,13 @@ duk_push_hobject(thr, holder); duk_push_hstring(thr, name); duk_push_tval(thr, val); - duk_xdef_prop(thr, -3, prop_flags); /* holder name val -> holder */ + duk_xdef_prop(thr, -3, prop_flags); /* holder name val -> holder */ duk_pop_unsafe(thr); return 0; - fail_existing_attributes: - fail_not_extensible: +fail_existing_attributes: +fail_not_extensible: DUK_ERROR_TYPE(thr, "declaration failed"); DUK_WO_NORETURN(return 0;); }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_json.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_json.h
Changed
@@ -6,28 +6,28 @@ #define DUK_JSON_H_INCLUDED /* Encoding/decoding flags */ -#define DUK_JSON_FLAG_ASCII_ONLY (1U << 0) /* escape any non-ASCII characters */ -#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1U << 1) /* avoid key quotes when key is an ASCII Identifier */ -#define DUK_JSON_FLAG_EXT_CUSTOM (1U << 2) /* extended types: custom encoding */ -#define DUK_JSON_FLAG_EXT_COMPATIBLE (1U << 3) /* extended types: compatible encoding */ +#define DUK_JSON_FLAG_ASCII_ONLY (1U << 0) /* escape any non-ASCII characters */ +#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1U << 1) /* avoid key quotes when key is an ASCII Identifier */ +#define DUK_JSON_FLAG_EXT_CUSTOM (1U << 2) /* extended types: custom encoding */ +#define DUK_JSON_FLAG_EXT_COMPATIBLE (1U << 3) /* extended types: compatible encoding */ /* How much stack to require on entry to object/array encode */ -#define DUK_JSON_ENC_REQSTACK 32 +#define DUK_JSON_ENC_REQSTACK 32 /* How much stack to require on entry to object/array decode */ -#define DUK_JSON_DEC_REQSTACK 32 +#define DUK_JSON_DEC_REQSTACK 32 /* How large a loop detection stack to use */ -#define DUK_JSON_ENC_LOOPARRAY 64 +#define DUK_JSON_ENC_LOOPARRAY 64 /* Encoding state. Heap object references are all borrowed. */ typedef struct { duk_hthread *thr; - duk_bufwriter_ctx bw; /* output bufwriter */ - duk_hobject *h_replacer; /* replacer function */ - duk_hstring *h_gap; /* gap (if empty string, NULL) */ - duk_idx_t idx_proplist; /* explicit PropertyList */ - duk_idx_t idx_loop; /* valstack index of loop detection object */ + duk_bufwriter_ctx bw; /* output bufwriter */ + duk_hobject *h_replacer; /* replacer function */ + duk_hstring *h_gap; /* gap (if empty string, NULL) */ + duk_idx_t idx_proplist; /* explicit PropertyList */ + duk_idx_t idx_loop; /* valstack index of loop detection object */ duk_small_uint_t flags; duk_small_uint_t flag_ascii_only; duk_small_uint_t flag_avoid_key_quotes; @@ -38,7 +38,7 @@ #endif duk_uint_t recursion_depth; duk_uint_t recursion_limit; - duk_uint_t mask_for_undefined; /* type bit mask: types which certainly produce 'undefined' */ + duk_uint_t mask_for_undefined; /* type bit mask: types which certainly produce 'undefined' */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) duk_small_uint_t stridx_custom_undefined; duk_small_uint_t stridx_custom_nan; @@ -46,7 +46,7 @@ duk_small_uint_t stridx_custom_posinf; duk_small_uint_t stridx_custom_function; #endif - duk_hobject *visitingDUK_JSON_ENC_LOOPARRAY; /* indexed by recursion_depth */ + duk_hobject *visitingDUK_JSON_ENC_LOOPARRAY; /* indexed by recursion_depth */ } duk_json_enc_ctx; typedef struct { @@ -65,4 +65,4 @@ duk_int_t recursion_limit; } duk_json_dec_ctx; -#endif /* DUK_JSON_H_INCLUDED */ +#endif /* DUK_JSON_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_lexer.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_lexer.c
Changed
@@ -76,34 +76,34 @@ * Various defines and file specific helper macros */ -#define DUK__MAX_RE_DECESC_DIGITS 9 -#define DUK__MAX_RE_QUANT_DIGITS 9 /* Does not allow e.g. 2**31-1, but one more would allow overflows of u32. */ +#define DUK__MAX_RE_DECESC_DIGITS 9 +#define DUK__MAX_RE_QUANT_DIGITS 9 /* Does not allow e.g. 2**31-1, but one more would allow overflows of u32. */ /* whether to use macros or helper function depends on call count */ -#define DUK__ISDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_9) -#define DUK__ISHEXDIGIT(x) duk__is_hex_digit((x)) -#define DUK__ISOCTDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_7) -#define DUK__ISDIGIT03(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_3) -#define DUK__ISDIGIT47(x) ((x) >= DUK_ASC_4 && (x) <= DUK_ASC_7) +#define DUK__ISDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_9) +#define DUK__ISHEXDIGIT(x) duk__is_hex_digit((x)) +#define DUK__ISOCTDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_7) +#define DUK__ISDIGIT03(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_3) +#define DUK__ISDIGIT47(x) ((x) >= DUK_ASC_4 && (x) <= DUK_ASC_7) /* lexer character window helpers */ -#define DUK__LOOKUP(lex_ctx,idx) ((lex_ctx)->window(idx).codepoint) -#define DUK__ADVANCECHARS(lex_ctx,count) duk__advance_chars((lex_ctx), (count)) -#define DUK__ADVANCEBYTES(lex_ctx,count) duk__advance_bytes((lex_ctx), (count)) +#define DUK__LOOKUP(lex_ctx, idx) ((lex_ctx)->window(idx).codepoint) +#define DUK__ADVANCECHARS(lex_ctx, count) duk__advance_chars((lex_ctx), (count)) +#define DUK__ADVANCEBYTES(lex_ctx, count) duk__advance_bytes((lex_ctx), (count)) #define DUK__INITBUFFER(lex_ctx) duk__initbuffer((lex_ctx)) -#define DUK__APPENDBUFFER(lex_ctx,x) duk__appendbuffer((lex_ctx), (duk_codepoint_t) (x)) -#define DUK__APPENDBUFFER_ASCII(lex_ctx,x) duk__appendbuffer_ascii((lex_ctx), (duk_codepoint_t) (x)) +#define DUK__APPENDBUFFER(lex_ctx, x) duk__appendbuffer((lex_ctx), (duk_codepoint_t) (x)) +#define DUK__APPENDBUFFER_ASCII(lex_ctx, x) duk__appendbuffer_ascii((lex_ctx), (duk_codepoint_t) (x)) /* lookup shorthands (note: assume context variable is named 'lex_ctx') */ -#define DUK__L0() DUK__LOOKUP(lex_ctx, 0) -#define DUK__L1() DUK__LOOKUP(lex_ctx, 1) -#define DUK__L2() DUK__LOOKUP(lex_ctx, 2) -#define DUK__L3() DUK__LOOKUP(lex_ctx, 3) -#define DUK__L4() DUK__LOOKUP(lex_ctx, 4) -#define DUK__L5() DUK__LOOKUP(lex_ctx, 5) +#define DUK__L0() DUK__LOOKUP(lex_ctx, 0) +#define DUK__L1() DUK__LOOKUP(lex_ctx, 1) +#define DUK__L2() DUK__LOOKUP(lex_ctx, 2) +#define DUK__L3() DUK__LOOKUP(lex_ctx, 3) +#define DUK__L4() DUK__LOOKUP(lex_ctx, 4) +#define DUK__L5() DUK__LOOKUP(lex_ctx, 5) /* packed advance/token number macro used by multiple functions */ -#define DUK__ADVTOK(advbytes,tok) ((((advbytes) * sizeof(duk_lexer_codepoint)) << 8) + (tok)) +#define DUK__ADVTOK(advbytes, tok) ((((advbytes) * sizeof(duk_lexer_codepoint)) << 8) + (tok)) /* * Advance lookup window by N characters, filling in new characters as @@ -213,10 +213,9 @@ /* Fast path. */ if (DUK_LIKELY(x < 0x80UL)) { - DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ + DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ if (DUK_UNLIKELY(x <= 0x000dUL)) { - if ((x == 0x000aUL) || - ((x == 0x000dUL) && (p >= p_end || *p != 0x000aUL))) { + if ((x == 0x000aUL) || ((x == 0x000dUL) && (p >= p_end || *p != 0x000aUL))) { /* lookup for 0x000a above assumes shortest encoding now */ /* E5 Section 7.3, treat the following as newlines: @@ -307,8 +306,8 @@ lex_ctx->input_line = input_line; return; - error_clipped: /* clipped codepoint */ - error_encoding: /* invalid codepoint encoding or codepoint */ +error_clipped: /* clipped codepoint */ +error_encoding: /* invalid codepoint encoding or codepoint */ lex_ctx->input_offset = (duk_size_t) (p - lex_ctx->input); lex_ctx->input_line = input_line; @@ -319,26 +318,25 @@ DUK_LOCAL void duk__advance_bytes(duk_lexer_ctx *lex_ctx, duk_small_uint_t count_bytes) { duk_small_uint_t used_bytes, avail_bytes; - DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ DUK_ASSERT(count_bytes <= (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))); DUK_ASSERT(lex_ctx->window >= lex_ctx->buffer); DUK_ASSERT(lex_ctx->window < lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE); - DUK_ASSERT((duk_uint8_t *) lex_ctx->window + count_bytes <= (duk_uint8_t *) lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint)); + DUK_ASSERT((duk_uint8_t *) lex_ctx->window + count_bytes <= + (duk_uint8_t *) lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint)); /* Zero 'count' is also allowed to make call sites easier. * Arithmetic in bytes generates better code in GCC. */ - lex_ctx->window = (duk_lexer_codepoint *) (void *) ((duk_uint8_t *) lex_ctx->window + count_bytes); /* avoid multiply */ + lex_ctx->window = (duk_lexer_codepoint *) (void *) ((duk_uint8_t *) lex_ctx->window + count_bytes); /* avoid multiply */ used_bytes = (duk_small_uint_t) ((duk_uint8_t *) lex_ctx->window - (duk_uint8_t *) lex_ctx->buffer); avail_bytes = DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint) - used_bytes; if (avail_bytes < (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))) { /* Not enough data to provide a full window, so "scroll" window to * start of buffer and fill up the rest. */ - duk_memmove((void *) lex_ctx->buffer, - (const void *) lex_ctx->window, - (size_t) avail_bytes); + duk_memmove((void *) lex_ctx->buffer, (const void *) lex_ctx->window, (size_t) avail_bytes); lex_ctx->window = lex_ctx->buffer; duk__fill_lexer_buffer(lex_ctx, avail_bytes); } @@ -348,7 +346,7 @@ lex_ctx->window = lex_ctx->buffer; duk__fill_lexer_buffer(lex_ctx, 0); } -#else /* DUK_USE_LEXER_SLIDING_WINDOW */ +#else /* DUK_USE_LEXER_SLIDING_WINDOW */ DUK_LOCAL duk_codepoint_t duk__read_char(duk_lexer_ctx *lex_ctx) { duk_ucodepoint_t x; duk_small_uint_t len; @@ -378,11 +376,10 @@ /* input offset tracking */ lex_ctx->input_offset++; - DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ + DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ if (DUK_UNLIKELY(x <= 0x000dUL)) { - if ((x == 0x000aUL) || - ((x == 0x000dUL) && (lex_ctx->input_offset >= lex_ctx->input_length || - lex_ctx->inputlex_ctx->input_offset != 0x000aUL))) { + if ((x == 0x000aUL) || ((x == 0x000dUL) && (lex_ctx->input_offset >= lex_ctx->input_length || + lex_ctx->inputlex_ctx->input_offset != 0x000aUL))) { /* lookup for 0x000a above assumes shortest encoding now */ /* E5 Section 7.3, treat the following as newlines: @@ -471,8 +468,8 @@ return (duk_codepoint_t) x; - error_clipped: /* clipped codepoint */ - error_encoding: /* invalid codepoint encoding or codepoint */ +error_clipped: /* clipped codepoint */ +error_encoding: /* invalid codepoint encoding or codepoint */ DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_SOURCE_DECODE_FAILED); DUK_WO_NORETURN(return 0;); } @@ -481,15 +478,13 @@ duk_small_uint_t keep_bytes; duk_lexer_codepoint *cp, *cp_end; - DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ DUK_ASSERT(count_bytes <= (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))); /* Zero 'count' is also allowed to make call sites easier. */ keep_bytes = DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint) - count_bytes; - duk_memmove((void *) lex_ctx->window, - (const void *) ((duk_uint8_t *) lex_ctx->window + count_bytes), - (size_t) keep_bytes); + duk_memmove((void *) lex_ctx->window, (const void *) ((duk_uint8_t *) lex_ctx->window + count_bytes), (size_t) keep_bytes); cp = (duk_lexer_codepoint *) ((duk_uint8_t *) lex_ctx->window + keep_bytes); cp_end = lex_ctx->window + DUK_LEXER_WINDOW_SIZE; @@ -502,9 +497,9 @@ DUK_LOCAL void duk__init_lexer_window(duk_lexer_ctx *lex_ctx) { /* Call with count == DUK_LEXER_WINDOW_SIZE to fill buffer initially. */ - duk__advance_bytes(lex_ctx, DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint)); /* fill window */ + duk__advance_bytes(lex_ctx, DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint)); /* fill window */ } -#endif /* DUK_USE_LEXER_SLIDING_WINDOW */ +#endif /* DUK_USE_LEXER_SLIDING_WINDOW */ DUK_LOCAL void duk__advance_chars(duk_lexer_ctx *lex_ctx, duk_small_uint_t count_chars) { duk__advance_bytes(lex_ctx, count_chars * sizeof(duk_lexer_codepoint)); @@ -597,7 +592,7 @@ } DUK_INTERNAL void duk_lexer_setpoint(duk_lexer_ctx *lex_ctx, duk_lexer_point *pt) { - DUK_ASSERT_DISABLE(pt->offset >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(pt->offset >= 0); /* unsigned */ DUK_ASSERT(pt->line >= 1); lex_ctx->input_offset = pt->offset; lex_ctx->input_line = pt->line; @@ -631,8 +626,7 @@ DUK_LOCAL duk_codepoint_t duk__hexval(duk_codepoint_t x) { duk_codepoint_t ret; - DUK_ASSERT((x >= DUK_ASC_0 && x <= DUK_ASC_9) || - (x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_F) || + DUK_ASSERT((x >= DUK_ASC_0 && x <= DUK_ASC_9) || (x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_F) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_F)); ret = duk__hexval_validate(x); DUK_ASSERT(ret >= 0 && ret <= 15); @@ -651,12 +645,12 @@ * source and RegExp parsing. */ DUK_LOCAL duk_codepoint_t duk__lexer_parse_escape(duk_lexer_ctx *lex_ctx, duk_bool_t allow_es6) { - duk_small_int_t digits; /* Initial value 2 or 4 for fixed length escapes, 0 for ES2015 \u{H+}. */ + duk_small_int_t digits; /* Initial value 2 or 4 for fixed length escapes, 0 for ES2015 \u{H+}. */ duk_codepoint_t escval; duk_codepoint_t x; duk_small_uint_t adv; - DUK_ASSERT(DUK__L0() == DUK_ASC_BACKSLASH); /* caller responsibilities */ + DUK_ASSERT(DUK__L0() == DUK_ASC_BACKSLASH); /* caller responsibilities */ DUK_ASSERT(DUK__L1() == DUK_ASC_LC_X || DUK__L1() == DUK_ASC_LC_U); DUK_UNREF(allow_es6); @@ -730,16 +724,16 @@ } else { goto fail_escape; } - digits = -1; /* Indicate we have at least one digit. */ -#else /* DUK_USE_ES6_UNICODE_ESCAPE */ - DUK_ASSERT(0); /* Never happens if \u{H+} support disabled. */ -#endif /* DUK_USE_ES6_UNICODE_ESCAPE */ + digits = -1; /* Indicate we have at least one digit. */ +#else /* DUK_USE_ES6_UNICODE_ESCAPE */ + DUK_ASSERT(0); /* Never happens if \u{H+} support disabled. */ +#endif /* DUK_USE_ES6_UNICODE_ESCAPE */ } } return escval; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return 0;); } @@ -749,7 +743,9 @@ * RegExp octal escape parsing. Window0 must be the slash '\' and the first * digit must already be validated to be in 0-9 by the caller. */ -DUK_LOCAL duk_codepoint_t duk__lexer_parse_legacy_octal(duk_lexer_ctx *lex_ctx, duk_small_uint_t *out_adv, duk_bool_t reject_annex_b) { +DUK_LOCAL duk_codepoint_t duk__lexer_parse_legacy_octal(duk_lexer_ctx *lex_ctx, + duk_small_uint_t *out_adv, + duk_bool_t reject_annex_b) { duk_codepoint_t cp; duk_small_uint_t lookup_idx; duk_small_uint_t adv; @@ -784,7 +780,7 @@ DUK_DDD(DUK_DDDPRINT("\\8 or \\9 -> treat as literal, accept in strict mode too")); DUK_ASSERT(tmp == DUK_ASC_8 || tmp == DUK_ASC_9); cp = tmp; - adv++; /* correction to above, eat offending character */ + adv++; /* correction to above, eat offending character */ } else if (lookup_idx == 2 && cp == 0) { /* Note: 'foo\0bar' is OK in strict mode, but 'foo\00bar' is not. * It won't be interpreted as 'foo\u{0}0bar' but as a SyntaxError. @@ -808,18 +804,21 @@ } /* XXX: move strict mode to lex_ctx? */ -DUK_LOCAL void duk__lexer_parse_string_literal(duk_lexer_ctx *lex_ctx, duk_token *out_token, duk_small_int_t quote, duk_bool_t strict_mode) { +DUK_LOCAL void duk__lexer_parse_string_literal(duk_lexer_ctx *lex_ctx, + duk_token *out_token, + duk_small_int_t quote, + duk_bool_t strict_mode) { duk_small_uint_t adv; - for (adv = 1 /* initial quote */ ;;) { + for (adv = 1 /* initial quote */;;) { duk_codepoint_t x; - DUK__ADVANCECHARS(lex_ctx, adv); /* eat opening quote on first loop */ + DUK__ADVANCECHARS(lex_ctx, adv); /* eat opening quote on first loop */ x = DUK__L0(); adv = 1; if (x == quote) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing quote */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing quote */ break; } else if (x == '\\') { /* DUK__L0 -> '\' char @@ -830,7 +829,7 @@ x = DUK__L1(); /* How much to advance before next loop. */ - adv = 2; /* note: long live range */ + adv = 2; /* note: long live range */ switch (x) { case '\'': @@ -873,7 +872,7 @@ /* line continuation */ if (x == 0x000d && DUK__L2() == 0x000a) { /* CR LF again a special case */ - adv = 3; /* line terminator, CR, LF */ + adv = 3; /* line terminator, CR, LF */ } } else if (DUK__ISDIGIT(x)) { /* @@ -902,8 +901,8 @@ /* escaped NonEscapeCharacter */ DUK__APPENDBUFFER(lex_ctx, x); } - } /* end default clause */ - } /* end switch */ + } /* end default clause */ + } /* end switch */ /* Shared handling for single codepoint escapes. */ if (emitcp >= 0) { @@ -936,11 +935,11 @@ return; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return;); - fail_unterminated: +fail_unterminated: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_STRING); DUK_WO_NORETURN(return;); } @@ -1027,19 +1026,19 @@ duk_token *out_token, duk_bool_t strict_mode, duk_bool_t regexp_mode) { - duk_codepoint_t x; /* temporary, must be signed and 32-bit to hold Unicode code points */ + duk_codepoint_t x; /* temporary, must be signed and 32-bit to hold Unicode code points */ duk_small_uint_t advtok = 0; /* (advance << 8) + token_type, updated at function end, * init is unnecessary but suppresses "may be used uninitialized" warnings. */ - duk_bool_t got_lineterm = 0; /* got lineterm preceding non-whitespace, non-lineterm token */ + duk_bool_t got_lineterm = 0; /* got lineterm preceding non-whitespace, non-lineterm token */ if (++lex_ctx->token_count >= lex_ctx->token_limit) { goto fail_token_limit; } out_token->t = DUK_TOK_EOF; - out_token->t_nores = DUK_TOK_INVALID; /* marker: copy t if not changed */ -#if 0 /* not necessary to init, disabled for faster parsing */ + out_token->t_nores = DUK_TOK_INVALID; /* marker: copy t if not changed */ +#if 0 /* not necessary to init, disabled for faster parsing */ out_token->num = DUK_DOUBLE_NAN; out_token->str1 = NULL; out_token->str2 = NULL; @@ -1079,35 +1078,34 @@ * in the clauses, so it's not trivial to convert to a switch. */ - restart_lineupdate: +restart_lineupdate: out_token->start_line = lex_ctx->window0.line; - restart: +restart: out_token->start_offset = lex_ctx->window0.offset; x = DUK__L0(); switch (x) { case DUK_ASC_SPACE: - case DUK_ASC_HT: /* fast paths for space and tab */ + case DUK_ASC_HT: /* fast paths for space and tab */ DUK__ADVANCECHARS(lex_ctx, 1); goto restart; - case DUK_ASC_LF: /* LF line terminator; CR LF and Unicode lineterms are handled in slow path */ + case DUK_ASC_LF: /* LF line terminator; CR LF and Unicode lineterms are handled in slow path */ DUK__ADVANCECHARS(lex_ctx, 1); got_lineterm = 1; goto restart_lineupdate; #if defined(DUK_USE_SHEBANG_COMMENTS) - case DUK_ASC_HASH: /* '#' */ - if (DUK__L1() == DUK_ASC_EXCLAMATION && lex_ctx->window0.offset == 0 && - (lex_ctx->flags & DUK_COMPILE_SHEBANG)) { + case DUK_ASC_HASH: /* '#' */ + if (DUK__L1() == DUK_ASC_EXCLAMATION && lex_ctx->window0.offset == 0 && (lex_ctx->flags & DUK_COMPILE_SHEBANG)) { /* "Shebang" comment ('#! ...') on first line. */ /* DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } goto fail_token; -#endif /* DUK_USE_SHEBANG_COMMENTS */ - case DUK_ASC_SLASH: /* '/' */ +#endif /* DUK_USE_SHEBANG_COMMENTS */ + case DUK_ASC_SLASH: /* '/' */ if (DUK__L1() == DUK_ASC_SLASH) { /* * E5 Section 7.4, allow SourceCharacter (which is any 16-bit @@ -1116,7 +1114,7 @@ /* DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } else if (DUK__L1() == DUK_ASC_STAR) { /* * E5 Section 7.4. If the multi-line comment contains a newline, @@ -1200,19 +1198,19 @@ /* first, parse regexp body roughly */ - duk_small_int_t state = 0; /* 0=base, 1=esc, 2=class, 3=class+esc */ + duk_small_int_t state = 0; /* 0=base, 1=esc, 2=class, 3=class+esc */ DUK__INITBUFFER(lex_ctx); for (;;) { - DUK__ADVANCECHARS(lex_ctx, 1); /* skip opening slash on first loop */ + DUK__ADVANCECHARS(lex_ctx, 1); /* skip opening slash on first loop */ x = DUK__L0(); if (x < 0 || duk_unicode_is_line_terminator(x)) { goto fail_unterm_regexp; } - x = DUK__L0(); /* re-read to avoid spill / fetch */ + x = DUK__L0(); /* re-read to avoid spill / fetch */ if (state == 0) { if (x == DUK_ASC_SLASH) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing slash */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing slash */ break; } else if (x == DUK_ASC_BACKSLASH) { state = 1; @@ -1242,20 +1240,20 @@ if (!duk_unicode_is_identifier_part(x)) { break; } - x = DUK__L0(); /* re-read to avoid spill / fetch */ + x = DUK__L0(); /* re-read to avoid spill / fetch */ DUK__APPENDBUFFER(lex_ctx, x); DUK__ADVANCECHARS(lex_ctx, 1); } out_token->str2 = duk__internbuffer(lex_ctx, lex_ctx->slot2_idx); - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* validation of the regexp is caller's responsibility */ advtok = DUK__ADVTOK(0, DUK_TOK_REGEXP); -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ goto fail_regexp_support; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } else if (DUK__L1() == DUK_ASC_EQUALS) { /* "/=" and not in regexp mode */ advtok = DUK__ADVTOK(2, DUK_TOK_DIV_EQ); @@ -1264,25 +1262,25 @@ advtok = DUK__ADVTOK(1, DUK_TOK_DIV); } break; - case DUK_ASC_LCURLY: /* '{' */ + case DUK_ASC_LCURLY: /* '{' */ advtok = DUK__ADVTOK(1, DUK_TOK_LCURLY); break; - case DUK_ASC_RCURLY: /* '}' */ + case DUK_ASC_RCURLY: /* '}' */ advtok = DUK__ADVTOK(1, DUK_TOK_RCURLY); break; - case DUK_ASC_LPAREN: /* '(' */ + case DUK_ASC_LPAREN: /* '(' */ advtok = DUK__ADVTOK(1, DUK_TOK_LPAREN); break; - case DUK_ASC_RPAREN: /* ')' */ + case DUK_ASC_RPAREN: /* ')' */ advtok = DUK__ADVTOK(1, DUK_TOK_RPAREN); break; - case DUK_ASC_LBRACKET: /* '' */ + case DUK_ASC_LBRACKET: /* '' */ advtok = DUK__ADVTOK(1, DUK_TOK_LBRACKET); break; - case DUK_ASC_RBRACKET: /* '' */ + case DUK_ASC_RBRACKET: /* '' */ advtok = DUK__ADVTOK(1, DUK_TOK_RBRACKET); break; - case DUK_ASC_PERIOD: /* '.' */ + case DUK_ASC_PERIOD: /* '.' */ if (DUK__ISDIGIT(DUK__L1())) { /* Period followed by a digit can only start DecimalLiteral * (handled in slow path). We could jump straight into the @@ -1293,13 +1291,13 @@ } advtok = DUK__ADVTOK(1, DUK_TOK_PERIOD); break; - case DUK_ASC_SEMICOLON: /* ';' */ + case DUK_ASC_SEMICOLON: /* ';' */ advtok = DUK__ADVTOK(1, DUK_TOK_SEMICOLON); break; - case DUK_ASC_COMMA: /* ',' */ + case DUK_ASC_COMMA: /* ',' */ advtok = DUK__ADVTOK(1, DUK_TOK_COMMA); break; - case DUK_ASC_LANGLE: /* '<' */ + case DUK_ASC_LANGLE: /* '<' */ #if defined(DUK_USE_HTML_COMMENTS) if (DUK__L1() == DUK_ASC_EXCLAMATION && DUK__L2() == DUK_ASC_MINUS && DUK__L3() == DUK_ASC_MINUS) { /* @@ -1308,11 +1306,10 @@ /* DUK__ADVANCECHARS(lex_ctx, 4) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ - } - else -#endif /* DUK_USE_HTML_COMMENTS */ - if (DUK__L1() == DUK_ASC_LANGLE && DUK__L2() == DUK_ASC_EQUALS) { + goto restart; /* line terminator will be handled on next round */ + } else +#endif /* DUK_USE_HTML_COMMENTS */ + if (DUK__L1() == DUK_ASC_LANGLE && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_ALSHIFT_EQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_LE); @@ -1322,7 +1319,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_LT); } break; - case DUK_ASC_RANGLE: /* '>' */ + case DUK_ASC_RANGLE: /* '>' */ if (DUK__L1() == DUK_ASC_RANGLE && DUK__L2() == DUK_ASC_RANGLE && DUK__L3() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(4, DUK_TOK_RSHIFT_EQ); } else if (DUK__L1() == DUK_ASC_RANGLE && DUK__L2() == DUK_ASC_RANGLE) { @@ -1337,7 +1334,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_GT); } break; - case DUK_ASC_EQUALS: /* '=' */ + case DUK_ASC_EQUALS: /* '=' */ if (DUK__L1() == DUK_ASC_EQUALS && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_SEQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -1346,7 +1343,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_EQUALSIGN); } break; - case DUK_ASC_EXCLAMATION: /* '!' */ + case DUK_ASC_EXCLAMATION: /* '!' */ if (DUK__L1() == DUK_ASC_EQUALS && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_SNEQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -1355,7 +1352,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_LNOT); } break; - case DUK_ASC_PLUS: /* '+' */ + case DUK_ASC_PLUS: /* '+' */ if (DUK__L1() == DUK_ASC_PLUS) { advtok = DUK__ADVTOK(2, DUK_TOK_INCREMENT); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -1364,7 +1361,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_ADD); } break; - case DUK_ASC_MINUS: /* '-' */ + case DUK_ASC_MINUS: /* '-' */ #if defined(DUK_USE_HTML_COMMENTS) if (got_lineterm && DUK__L1() == DUK_ASC_MINUS && DUK__L2() == DUK_ASC_RANGLE) { /* @@ -1381,10 +1378,10 @@ /* DUK__ADVANCECHARS(lex_ctx, 3) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } else -#endif /* DUK_USE_HTML_COMMENTS */ - if (DUK__L1() == DUK_ASC_MINUS) { +#endif /* DUK_USE_HTML_COMMENTS */ + if (DUK__L1() == DUK_ASC_MINUS) { advtok = DUK__ADVTOK(2, DUK_TOK_DECREMENT); } else if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_SUB_EQ); @@ -1392,7 +1389,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_SUB); } break; - case DUK_ASC_STAR: /* '*' */ + case DUK_ASC_STAR: /* '*' */ #if defined(DUK_USE_ES7_EXP_OPERATOR) if (DUK__L1() == DUK_ASC_STAR && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_EXP_EQ); @@ -1400,20 +1397,20 @@ advtok = DUK__ADVTOK(2, DUK_TOK_EXP); } else #endif - if (DUK__L1() == DUK_ASC_EQUALS) { + if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_MUL_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_MUL); } break; - case DUK_ASC_PERCENT: /* '%' */ + case DUK_ASC_PERCENT: /* '%' */ if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_MOD_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_MOD); } break; - case DUK_ASC_AMP: /* '&' */ + case DUK_ASC_AMP: /* '&' */ if (DUK__L1() == DUK_ASC_AMP) { advtok = DUK__ADVTOK(2, DUK_TOK_LAND); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -1422,7 +1419,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_BAND); } break; - case DUK_ASC_PIPE: /* '|' */ + case DUK_ASC_PIPE: /* '|' */ if (DUK__L1() == DUK_ASC_PIPE) { advtok = DUK__ADVTOK(2, DUK_TOK_LOR); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -1431,41 +1428,41 @@ advtok = DUK__ADVTOK(1, DUK_TOK_BOR); } break; - case DUK_ASC_CARET: /* '^' */ + case DUK_ASC_CARET: /* '^' */ if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_BXOR_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_BXOR); } break; - case DUK_ASC_TILDE: /* '~' */ + case DUK_ASC_TILDE: /* '~' */ advtok = DUK__ADVTOK(1, DUK_TOK_BNOT); break; - case DUK_ASC_QUESTION: /* '?' */ + case DUK_ASC_QUESTION: /* '?' */ advtok = DUK__ADVTOK(1, DUK_TOK_QUESTION); break; - case DUK_ASC_COLON: /* ':' */ + case DUK_ASC_COLON: /* ':' */ advtok = DUK__ADVTOK(1, DUK_TOK_COLON); break; - case DUK_ASC_DOUBLEQUOTE: /* '"' */ - case DUK_ASC_SINGLEQUOTE: { /* '\'' */ + case DUK_ASC_DOUBLEQUOTE: /* '"' */ + case DUK_ASC_SINGLEQUOTE: { /* '\'' */ DUK__INITBUFFER(lex_ctx); duk__lexer_parse_string_literal(lex_ctx, out_token, x /*quote*/, strict_mode); duk__internbuffer(lex_ctx, lex_ctx->slot1_idx); out_token->str1 = duk_known_hstring(lex_ctx->thr, lex_ctx->slot1_idx); - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ advtok = DUK__ADVTOK(0, DUK_TOK_STRING); break; } default: goto slow_path; - } /* switch */ + } /* switch */ goto skip_slow_path; - slow_path: +slow_path: if (duk_unicode_is_line_terminator(x)) { if (x == 0x000d && DUK__L1() == 0x000a) { /* @@ -1556,7 +1553,7 @@ str = out_token->str1; out_token->t_nores = DUK_TOK_IDENTIFIER; - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* * Interned identifier is compared against reserved words, which are @@ -1583,7 +1580,7 @@ advtok = DUK__ADVTOK(0, DUK_TOK_IDENTIFIER); if (out_token->num_escapes == 0) { for (i = DUK_STRIDX_START_RESERVED; i < i_end; i++) { - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HEAP_NUM_STRINGS); if (DUK_HTHREAD_GET_STRING(lex_ctx->thr, i) == str) { advtok = DUK__ADVTOK(0, DUK_STRIDX_TO_TOK(i)); @@ -1618,11 +1615,11 @@ duk_double_t val; duk_bool_t legacy_oct = 0; - duk_small_int_t state; /* 0=before period/exp, - * 1=after period, before exp - * 2=after exp, allow '+' or '-' - * 3=after exp and exp sign - */ + duk_small_int_t state; /* 0=before period/exp, + * 1=after period, before exp + * 2=after exp, allow '+' or '-' + * 3=after exp and exp sign + */ duk_small_uint_t s2n_flags; duk_codepoint_t y, z; duk_small_int_t s2n_radix = 10; @@ -1634,7 +1631,7 @@ if (x == DUK_ASC_0) { z = DUK_LOWERCASE_CHAR_ASCII(y); - pre_adv = 2; /* default for 0xNNN, 0oNNN, 0bNNN. */ + pre_adv = 2; /* default for 0xNNN, 0oNNN, 0bNNN. */ if (z == DUK_ASC_LC_X) { s2n_radix = 16; } else if (z == DUK_ASC_LC_O) { @@ -1657,7 +1654,7 @@ DUK__APPENDBUFFER(lex_ctx, x); pre_adv = 1; legacy_oct = 1; - s2n_radix = 8; /* tentative unless conflicting digits found */ + s2n_radix = 8; /* tentative unless conflicting digits found */ } } } @@ -1671,7 +1668,7 @@ */ state = 0; for (;;) { - x = DUK__L0(); /* re-lookup curr char on first round */ + x = DUK__L0(); /* re-lookup curr char on first round */ if (DUK__ISDIGIT(x)) { /* Note: intentionally allow leading zeroes here, as the * actual parser will check for them. @@ -1724,11 +1721,8 @@ /* For bases other than 10, integer only. */ s2n_flags = DUK_S2N_FLAG_ALLOW_LEADING_ZERO; } else { - s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO; + s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_LEADING_ZERO; } duk_dup(lex_ctx->thr, lex_ctx->slot1_idx); @@ -1737,9 +1731,9 @@ if (DUK_ISNAN(val)) { goto fail_number_literal; } - duk_replace(lex_ctx->thr, lex_ctx->slot1_idx); /* could also just pop? */ + duk_replace(lex_ctx->thr, lex_ctx->slot1_idx); /* could also just pop? */ - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* Section 7.8.3 (note): NumericLiteral must be followed by something other than * IdentifierStart or DecimalDigit. @@ -1759,7 +1753,7 @@ } else { goto fail_token; } - skip_slow_path: +skip_slow_path: /* * Shared exit path @@ -1784,32 +1778,32 @@ return; - fail_token_limit: +fail_token_limit: DUK_ERROR_RANGE(lex_ctx->thr, DUK_STR_TOKEN_LIMIT); DUK_WO_NORETURN(return;); - fail_token: +fail_token: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_TOKEN); DUK_WO_NORETURN(return;); - fail_number_literal: +fail_number_literal: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_NUMBER_LITERAL); DUK_WO_NORETURN(return;); - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return;); - fail_unterm_regexp: +fail_unterm_regexp: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_REGEXP); DUK_WO_NORETURN(return;); - fail_unterm_comment: +fail_unterm_comment: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_COMMENT); DUK_WO_NORETURN(return;); #if !defined(DUK_USE_REGEXP_SUPPORT) - fail_regexp_support: +fail_regexp_support: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_REGEXP_SUPPORT_DISABLED); DUK_WO_NORETURN(return;); #endif @@ -1827,7 +1821,7 @@ */ DUK_INTERNAL void duk_lexer_parse_re_token(duk_lexer_ctx *lex_ctx, duk_re_token *out_token) { - duk_small_uint_t advtok = 0; /* init is unnecessary but suppresses "may be used uninitialized" warnings */ + duk_small_uint_t advtok = 0; /* init is unnecessary but suppresses "may be used uninitialized" warnings */ duk_codepoint_t x, y; if (++lex_ctx->token_count >= lex_ctx->token_limit) { @@ -1905,7 +1899,7 @@ #endif for (;;) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat '{' on entry */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat '{' on entry */ x = DUK__L0(); if (DUK__ISDIGIT(x)) { digits++; @@ -1929,7 +1923,7 @@ } val2 = val1; val1 = 0; - digits = 0; /* not strictly necessary because of lookahead '}' above */ + digits = 0; /* not strictly necessary because of lookahead '}' above */ } else if (x == DUK_ASC_RCURLY) { if (digits > DUK__MAX_RE_QUANT_DIGITS) { goto invalid_quantifier; @@ -1960,7 +1954,7 @@ } advtok = DUK__ADVTOK(0, DUK_RETOK_QUANTIFIER); break; - invalid_quantifier: + invalid_quantifier: #if defined(DUK_USE_ES6_REGEXP_SYNTAX) /* Failed to match the quantifier, restore lexer and parse * opening brace as a literal. @@ -1986,7 +1980,7 @@ * ES2015 Annex B relaxes the rules to allow these (and other) real world forms. */ - advtok = DUK__ADVTOK(2, DUK_RETOK_ATOM_CHAR); /* default: char escape (two chars) */ + advtok = DUK__ADVTOK(2, DUK_RETOK_ATOM_CHAR); /* default: char escape (two chars) */ if (y == DUK_ASC_LC_B) { advtok = DUK__ADVTOK(2, DUK_RETOK_ASSERT_WORD_BOUNDARY); } else if (y == DUK_ASC_UC_B) { @@ -2003,8 +1997,7 @@ out_token->num = 0x000b; } else if (y == DUK_ASC_LC_C) { x = DUK__L2(); - if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || - (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { + if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { out_token->num = (duk_uint32_t) (x % 32); advtok = DUK__ADVTOK(3, DUK_RETOK_ATOM_CHAR); } else { @@ -2042,11 +2035,11 @@ /* XXX: shared parsing? */ duk_uint32_t val = 0; duk_small_int_t i; - for (i = 0; ; i++) { + for (i = 0;; i++) { if (i >= DUK__MAX_RE_DECESC_DIGITS) { goto fail_escape; } - DUK__ADVANCECHARS(lex_ctx, 1); /* eat backslash on entry */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat backslash on entry */ x = DUK__L0(); if (!DUK__ISDIGIT(x)) { break; @@ -2066,17 +2059,15 @@ * This is not yet full ES2015 Annex B because cases above * (like hex escape) won't backtrack. */ - DUK_ASSERT(y != DUK_ASC_LC_C); /* covered above */ -#else /* DUK_USE_ES6_REGEXP_SYNTAX */ - } else if ((y >= 0 && !duk_unicode_is_identifier_part(y)) || - y == DUK_UNICODE_CP_ZWNJ || - y == DUK_UNICODE_CP_ZWJ) { + DUK_ASSERT(y != DUK_ASC_LC_C); /* covered above */ +#else /* DUK_USE_ES6_REGEXP_SYNTAX */ + } else if ((y >= 0 && !duk_unicode_is_identifier_part(y)) || y == DUK_UNICODE_CP_ZWNJ || y == DUK_UNICODE_CP_ZWJ) { /* For ES5.1 identity escapes are not allowed for identifier * parts. This conflicts with a lot of real world code as this * doesn't e.g. allow escaping a dollar sign as /\$/, see * test-regexp-identity-escape-dollar.js. */ -#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ +#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ out_token->num = (duk_uint32_t) y; } else { goto fail_escape; @@ -2157,24 +2148,24 @@ out_token->t = advtok & 0xff; return; - fail_token_limit: +fail_token_limit: DUK_ERROR_RANGE(lex_ctx->thr, DUK_STR_TOKEN_LIMIT); DUK_WO_NORETURN(return;); - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_ESCAPE); DUK_WO_NORETURN(return;); - fail_group: +fail_group: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_GROUP); DUK_WO_NORETURN(return;); #if !defined(DUK_USE_ES6_REGEXP_SYNTAX) - fail_invalid_char: +fail_invalid_char: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_CHARACTER); DUK_WO_NORETURN(return;); - fail_quantifier: +fail_quantifier: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_QUANTIFIER); DUK_WO_NORETURN(return;); #endif @@ -2233,7 +2224,7 @@ x = DUK__L0(); - ch = -1; /* not strictly necessary, but avoids "uninitialized variable" warnings */ + ch = -1; /* not strictly necessary, but avoids "uninitialized variable" warnings */ DUK_UNREF(ch); if (x < 0) { @@ -2242,7 +2233,7 @@ if (start >= 0) { gen_range(userdata, start, start, 0); } - DUK__ADVANCECHARS(lex_ctx, 1); /* eat '' before finishing */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat '' before finishing */ break; } else if (x == DUK_ASC_MINUS) { if (start >= 0 && !dash && DUK__L1() != DUK_ASC_RBRACKET) { @@ -2287,8 +2278,7 @@ } else if (x == DUK_ASC_LC_C) { x = DUK__L2(); adv = 3; - if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || - (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { + if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { ch = (x % 32); } else { goto fail_escape; @@ -2352,7 +2342,7 @@ #if defined(DUK_USE_ES6_REGEXP_SYNTAX) ch = duk__lexer_parse_legacy_octal(lex_ctx, &adv, 0 /*reject_annex_b*/); - DUK_ASSERT(ch >= 0); /* no rejections */ + DUK_ASSERT(ch >= 0); /* no rejections */ #else if (x == DUK_ASC_0 && !DUK__ISDIGIT(DUK__L2())) { ch = 0x0000; @@ -2367,7 +2357,7 @@ * EOF here. */ ch = x; -#else /* DUK_USE_ES6_REGEXP_SYNTAX */ +#else /* DUK_USE_ES6_REGEXP_SYNTAX */ } else if (!duk_unicode_is_identifier_part(x)) { /* IdentityEscape: ES5.1 doesn't allow identity escape * for identifier part characters, which conflicts with @@ -2375,7 +2365,7 @@ * /\$/ which is awkward. */ ch = x; -#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ +#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ } else { goto fail_escape; } @@ -2423,17 +2413,17 @@ return; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_ESCAPE); DUK_WO_NORETURN(return;); - fail_range: +fail_range: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_RANGE); DUK_WO_NORETURN(return;); - fail_unterm_charclass: +fail_unterm_charclass: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_CHARCLASS); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_lexer.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_lexer.h
Changed
@@ -26,156 +26,156 @@ * in a continuous range and in a particular order. See genstrings.py. */ -#define DUK_LEXER_INITCTX(ctx) duk_lexer_initctx((ctx)) +#define DUK_LEXER_INITCTX(ctx) duk_lexer_initctx((ctx)) -#define DUK_LEXER_SETPOINT(ctx,pt) duk_lexer_setpoint((ctx), (pt)) +#define DUK_LEXER_SETPOINT(ctx, pt) duk_lexer_setpoint((ctx), (pt)) -#define DUK_LEXER_GETPOINT(ctx,pt) duk_lexer_getpoint((ctx), (pt)) +#define DUK_LEXER_GETPOINT(ctx, pt) duk_lexer_getpoint((ctx), (pt)) /* Currently 6 characters of lookup are actually needed (duk_lexer.c). */ -#define DUK_LEXER_WINDOW_SIZE 6 +#define DUK_LEXER_WINDOW_SIZE 6 #if defined(DUK_USE_LEXER_SLIDING_WINDOW) -#define DUK_LEXER_BUFFER_SIZE 64 +#define DUK_LEXER_BUFFER_SIZE 64 #endif -#define DUK_TOK_MINVAL 0 +#define DUK_TOK_MINVAL 0 /* returned after EOF (infinite amount) */ -#define DUK_TOK_EOF 0 +#define DUK_TOK_EOF 0 /* identifier names (E5 Section 7.6) */ -#define DUK_TOK_IDENTIFIER 1 +#define DUK_TOK_IDENTIFIER 1 /* reserved words: keywords */ -#define DUK_TOK_START_RESERVED 2 -#define DUK_TOK_BREAK 2 -#define DUK_TOK_CASE 3 -#define DUK_TOK_CATCH 4 -#define DUK_TOK_CONTINUE 5 -#define DUK_TOK_DEBUGGER 6 -#define DUK_TOK_DEFAULT 7 -#define DUK_TOK_DELETE 8 -#define DUK_TOK_DO 9 -#define DUK_TOK_ELSE 10 -#define DUK_TOK_FINALLY 11 -#define DUK_TOK_FOR 12 -#define DUK_TOK_FUNCTION 13 -#define DUK_TOK_IF 14 -#define DUK_TOK_IN 15 -#define DUK_TOK_INSTANCEOF 16 -#define DUK_TOK_NEW 17 -#define DUK_TOK_RETURN 18 -#define DUK_TOK_SWITCH 19 -#define DUK_TOK_THIS 20 -#define DUK_TOK_THROW 21 -#define DUK_TOK_TRY 22 -#define DUK_TOK_TYPEOF 23 -#define DUK_TOK_VAR 24 -#define DUK_TOK_CONST 25 -#define DUK_TOK_VOID 26 -#define DUK_TOK_WHILE 27 -#define DUK_TOK_WITH 28 +#define DUK_TOK_START_RESERVED 2 +#define DUK_TOK_BREAK 2 +#define DUK_TOK_CASE 3 +#define DUK_TOK_CATCH 4 +#define DUK_TOK_CONTINUE 5 +#define DUK_TOK_DEBUGGER 6 +#define DUK_TOK_DEFAULT 7 +#define DUK_TOK_DELETE 8 +#define DUK_TOK_DO 9 +#define DUK_TOK_ELSE 10 +#define DUK_TOK_FINALLY 11 +#define DUK_TOK_FOR 12 +#define DUK_TOK_FUNCTION 13 +#define DUK_TOK_IF 14 +#define DUK_TOK_IN 15 +#define DUK_TOK_INSTANCEOF 16 +#define DUK_TOK_NEW 17 +#define DUK_TOK_RETURN 18 +#define DUK_TOK_SWITCH 19 +#define DUK_TOK_THIS 20 +#define DUK_TOK_THROW 21 +#define DUK_TOK_TRY 22 +#define DUK_TOK_TYPEOF 23 +#define DUK_TOK_VAR 24 +#define DUK_TOK_CONST 25 +#define DUK_TOK_VOID 26 +#define DUK_TOK_WHILE 27 +#define DUK_TOK_WITH 28 /* reserved words: future reserved words */ -#define DUK_TOK_CLASS 29 -#define DUK_TOK_ENUM 30 -#define DUK_TOK_EXPORT 31 -#define DUK_TOK_EXTENDS 32 -#define DUK_TOK_IMPORT 33 -#define DUK_TOK_SUPER 34 +#define DUK_TOK_CLASS 29 +#define DUK_TOK_ENUM 30 +#define DUK_TOK_EXPORT 31 +#define DUK_TOK_EXTENDS 32 +#define DUK_TOK_IMPORT 33 +#define DUK_TOK_SUPER 34 /* "null", "true", and "false" are always reserved words. * Note that "get" and "set" are not! */ -#define DUK_TOK_NULL 35 -#define DUK_TOK_TRUE 36 -#define DUK_TOK_FALSE 37 +#define DUK_TOK_NULL 35 +#define DUK_TOK_TRUE 36 +#define DUK_TOK_FALSE 37 /* reserved words: additional future reserved words in strict mode */ -#define DUK_TOK_START_STRICT_RESERVED 38 /* inclusive */ -#define DUK_TOK_IMPLEMENTS 38 -#define DUK_TOK_INTERFACE 39 -#define DUK_TOK_LET 40 -#define DUK_TOK_PACKAGE 41 -#define DUK_TOK_PRIVATE 42 -#define DUK_TOK_PROTECTED 43 -#define DUK_TOK_PUBLIC 44 -#define DUK_TOK_STATIC 45 -#define DUK_TOK_YIELD 46 - -#define DUK_TOK_END_RESERVED 47 /* exclusive */ +#define DUK_TOK_START_STRICT_RESERVED 38 /* inclusive */ +#define DUK_TOK_IMPLEMENTS 38 +#define DUK_TOK_INTERFACE 39 +#define DUK_TOK_LET 40 +#define DUK_TOK_PACKAGE 41 +#define DUK_TOK_PRIVATE 42 +#define DUK_TOK_PROTECTED 43 +#define DUK_TOK_PUBLIC 44 +#define DUK_TOK_STATIC 45 +#define DUK_TOK_YIELD 46 + +#define DUK_TOK_END_RESERVED 47 /* exclusive */ /* "get" and "set" are tokens but NOT ReservedWords. They are currently * parsed and identifiers and these defines are actually now unused. */ -#define DUK_TOK_GET 47 -#define DUK_TOK_SET 48 +#define DUK_TOK_GET 47 +#define DUK_TOK_SET 48 /* punctuators (unlike the spec, also includes "/" and "/=") */ -#define DUK_TOK_LCURLY 49 -#define DUK_TOK_RCURLY 50 -#define DUK_TOK_LBRACKET 51 -#define DUK_TOK_RBRACKET 52 -#define DUK_TOK_LPAREN 53 -#define DUK_TOK_RPAREN 54 -#define DUK_TOK_PERIOD 55 -#define DUK_TOK_SEMICOLON 56 -#define DUK_TOK_COMMA 57 -#define DUK_TOK_LT 58 -#define DUK_TOK_GT 59 -#define DUK_TOK_LE 60 -#define DUK_TOK_GE 61 -#define DUK_TOK_EQ 62 -#define DUK_TOK_NEQ 63 -#define DUK_TOK_SEQ 64 -#define DUK_TOK_SNEQ 65 -#define DUK_TOK_ADD 66 -#define DUK_TOK_SUB 67 -#define DUK_TOK_MUL 68 -#define DUK_TOK_DIV 69 -#define DUK_TOK_MOD 70 -#define DUK_TOK_EXP 71 -#define DUK_TOK_INCREMENT 72 -#define DUK_TOK_DECREMENT 73 -#define DUK_TOK_ALSHIFT 74 /* named "arithmetic" because result is signed */ -#define DUK_TOK_ARSHIFT 75 -#define DUK_TOK_RSHIFT 76 -#define DUK_TOK_BAND 77 -#define DUK_TOK_BOR 78 -#define DUK_TOK_BXOR 79 -#define DUK_TOK_LNOT 80 -#define DUK_TOK_BNOT 81 -#define DUK_TOK_LAND 82 -#define DUK_TOK_LOR 83 -#define DUK_TOK_QUESTION 84 -#define DUK_TOK_COLON 85 -#define DUK_TOK_EQUALSIGN 86 -#define DUK_TOK_ADD_EQ 87 -#define DUK_TOK_SUB_EQ 88 -#define DUK_TOK_MUL_EQ 89 -#define DUK_TOK_DIV_EQ 90 -#define DUK_TOK_MOD_EQ 91 -#define DUK_TOK_EXP_EQ 92 -#define DUK_TOK_ALSHIFT_EQ 93 -#define DUK_TOK_ARSHIFT_EQ 94 -#define DUK_TOK_RSHIFT_EQ 95 -#define DUK_TOK_BAND_EQ 96 -#define DUK_TOK_BOR_EQ 97 -#define DUK_TOK_BXOR_EQ 98 +#define DUK_TOK_LCURLY 49 +#define DUK_TOK_RCURLY 50 +#define DUK_TOK_LBRACKET 51 +#define DUK_TOK_RBRACKET 52 +#define DUK_TOK_LPAREN 53 +#define DUK_TOK_RPAREN 54 +#define DUK_TOK_PERIOD 55 +#define DUK_TOK_SEMICOLON 56 +#define DUK_TOK_COMMA 57 +#define DUK_TOK_LT 58 +#define DUK_TOK_GT 59 +#define DUK_TOK_LE 60 +#define DUK_TOK_GE 61 +#define DUK_TOK_EQ 62 +#define DUK_TOK_NEQ 63 +#define DUK_TOK_SEQ 64 +#define DUK_TOK_SNEQ 65 +#define DUK_TOK_ADD 66 +#define DUK_TOK_SUB 67 +#define DUK_TOK_MUL 68 +#define DUK_TOK_DIV 69 +#define DUK_TOK_MOD 70 +#define DUK_TOK_EXP 71 +#define DUK_TOK_INCREMENT 72 +#define DUK_TOK_DECREMENT 73 +#define DUK_TOK_ALSHIFT 74 /* named "arithmetic" because result is signed */ +#define DUK_TOK_ARSHIFT 75 +#define DUK_TOK_RSHIFT 76 +#define DUK_TOK_BAND 77 +#define DUK_TOK_BOR 78 +#define DUK_TOK_BXOR 79 +#define DUK_TOK_LNOT 80 +#define DUK_TOK_BNOT 81 +#define DUK_TOK_LAND 82 +#define DUK_TOK_LOR 83 +#define DUK_TOK_QUESTION 84 +#define DUK_TOK_COLON 85 +#define DUK_TOK_EQUALSIGN 86 +#define DUK_TOK_ADD_EQ 87 +#define DUK_TOK_SUB_EQ 88 +#define DUK_TOK_MUL_EQ 89 +#define DUK_TOK_DIV_EQ 90 +#define DUK_TOK_MOD_EQ 91 +#define DUK_TOK_EXP_EQ 92 +#define DUK_TOK_ALSHIFT_EQ 93 +#define DUK_TOK_ARSHIFT_EQ 94 +#define DUK_TOK_RSHIFT_EQ 95 +#define DUK_TOK_BAND_EQ 96 +#define DUK_TOK_BOR_EQ 97 +#define DUK_TOK_BXOR_EQ 98 /* literals (E5 Section 7.8), except null, true, false, which are treated * like reserved words (above). */ -#define DUK_TOK_NUMBER 99 -#define DUK_TOK_STRING 100 -#define DUK_TOK_REGEXP 101 +#define DUK_TOK_NUMBER 99 +#define DUK_TOK_STRING 100 +#define DUK_TOK_REGEXP 101 -#define DUK_TOK_MAXVAL 101 /* inclusive */ +#define DUK_TOK_MAXVAL 101 /* inclusive */ -#define DUK_TOK_INVALID DUK_SMALL_UINT_MAX +#define DUK_TOK_INVALID DUK_SMALL_UINT_MAX /* Convert heap string index to a token (reserved words) */ -#define DUK_STRIDX_TO_TOK(x) ((x) - DUK_STRIDX_START_RESERVED + DUK_TOK_START_RESERVED) +#define DUK_STRIDX_TO_TOK(x) ((x) -DUK_STRIDX_START_RESERVED + DUK_TOK_START_RESERVED) /* Sanity check */ #if (DUK_TOK_MAXVAL > 255) @@ -320,57 +320,57 @@ #endif /* Regexp tokens */ -#define DUK_RETOK_EOF 0 -#define DUK_RETOK_DISJUNCTION 1 -#define DUK_RETOK_QUANTIFIER 2 -#define DUK_RETOK_ASSERT_START 3 -#define DUK_RETOK_ASSERT_END 4 -#define DUK_RETOK_ASSERT_WORD_BOUNDARY 5 -#define DUK_RETOK_ASSERT_NOT_WORD_BOUNDARY 6 -#define DUK_RETOK_ASSERT_START_POS_LOOKAHEAD 7 -#define DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD 8 -#define DUK_RETOK_ATOM_PERIOD 9 -#define DUK_RETOK_ATOM_CHAR 10 -#define DUK_RETOK_ATOM_DIGIT 11 /* assumptions in regexp compiler */ -#define DUK_RETOK_ATOM_NOT_DIGIT 12 /* -""- */ -#define DUK_RETOK_ATOM_WHITE 13 /* -""- */ -#define DUK_RETOK_ATOM_NOT_WHITE 14 /* -""- */ -#define DUK_RETOK_ATOM_WORD_CHAR 15 /* -""- */ -#define DUK_RETOK_ATOM_NOT_WORD_CHAR 16 /* -""- */ -#define DUK_RETOK_ATOM_BACKREFERENCE 17 -#define DUK_RETOK_ATOM_START_CAPTURE_GROUP 18 -#define DUK_RETOK_ATOM_START_NONCAPTURE_GROUP 19 -#define DUK_RETOK_ATOM_START_CHARCLASS 20 -#define DUK_RETOK_ATOM_START_CHARCLASS_INVERTED 21 -#define DUK_RETOK_ATOM_END_GROUP 22 +#define DUK_RETOK_EOF 0 +#define DUK_RETOK_DISJUNCTION 1 +#define DUK_RETOK_QUANTIFIER 2 +#define DUK_RETOK_ASSERT_START 3 +#define DUK_RETOK_ASSERT_END 4 +#define DUK_RETOK_ASSERT_WORD_BOUNDARY 5 +#define DUK_RETOK_ASSERT_NOT_WORD_BOUNDARY 6 +#define DUK_RETOK_ASSERT_START_POS_LOOKAHEAD 7 +#define DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD 8 +#define DUK_RETOK_ATOM_PERIOD 9 +#define DUK_RETOK_ATOM_CHAR 10 +#define DUK_RETOK_ATOM_DIGIT 11 /* assumptions in regexp compiler */ +#define DUK_RETOK_ATOM_NOT_DIGIT 12 /* -""- */ +#define DUK_RETOK_ATOM_WHITE 13 /* -""- */ +#define DUK_RETOK_ATOM_NOT_WHITE 14 /* -""- */ +#define DUK_RETOK_ATOM_WORD_CHAR 15 /* -""- */ +#define DUK_RETOK_ATOM_NOT_WORD_CHAR 16 /* -""- */ +#define DUK_RETOK_ATOM_BACKREFERENCE 17 +#define DUK_RETOK_ATOM_START_CAPTURE_GROUP 18 +#define DUK_RETOK_ATOM_START_NONCAPTURE_GROUP 19 +#define DUK_RETOK_ATOM_START_CHARCLASS 20 +#define DUK_RETOK_ATOM_START_CHARCLASS_INVERTED 21 +#define DUK_RETOK_ATOM_END_GROUP 22 /* Constants for duk_lexer_ctx.buf. */ -#define DUK_LEXER_TEMP_BUF_LIMIT 256 +#define DUK_LEXER_TEMP_BUF_LIMIT 256 /* A token value. Can be memcpy()'d, but note that slot1/slot2 values are on the valstack. * Some fields (like num, str1, str2) are only valid for specific token types and may have * stale values otherwise. */ struct duk_token { - duk_small_uint_t t; /* token type (with reserved word identification) */ - duk_small_uint_t t_nores; /* token type (with reserved words as DUK_TOK_IDENTIFER) */ - duk_double_t num; /* numeric value of token */ - duk_hstring *str1; /* string 1 of token (borrowed, stored to ctx->slot1_idx) */ - duk_hstring *str2; /* string 2 of token (borrowed, stored to ctx->slot2_idx) */ - duk_size_t start_offset; /* start byte offset of token in lexer input */ - duk_int_t start_line; /* start line of token (first char) */ - duk_int_t num_escapes; /* number of escapes and line continuations (for directive prologue) */ - duk_bool_t lineterm; /* token was preceded by a lineterm */ - duk_bool_t allow_auto_semi; /* token allows automatic semicolon insertion (eof or preceded by newline) */ + duk_small_uint_t t; /* token type (with reserved word identification) */ + duk_small_uint_t t_nores; /* token type (with reserved words as DUK_TOK_IDENTIFER) */ + duk_double_t num; /* numeric value of token */ + duk_hstring *str1; /* string 1 of token (borrowed, stored to ctx->slot1_idx) */ + duk_hstring *str2; /* string 2 of token (borrowed, stored to ctx->slot2_idx) */ + duk_size_t start_offset; /* start byte offset of token in lexer input */ + duk_int_t start_line; /* start line of token (first char) */ + duk_int_t num_escapes; /* number of escapes and line continuations (for directive prologue) */ + duk_bool_t lineterm; /* token was preceded by a lineterm */ + duk_bool_t allow_auto_semi; /* token allows automatic semicolon insertion (eof or preceded by newline) */ }; -#define DUK_RE_QUANTIFIER_INFINITE ((duk_uint32_t) 0xffffffffUL) +#define DUK_RE_QUANTIFIER_INFINITE ((duk_uint32_t) 0xffffffffUL) /* A regexp token value. */ struct duk_re_token { - duk_small_uint_t t; /* token type */ + duk_small_uint_t t; /* token type */ duk_small_uint_t greedy; - duk_uint32_t num; /* numeric value (character, count) */ + duk_uint32_t num; /* numeric value (character, count) */ duk_uint32_t qmin; duk_uint32_t qmax; }; @@ -397,23 +397,23 @@ duk_lexer_codepoint windowDUK_LEXER_WINDOW_SIZE; /* unicode code points, window0 is always next */ #endif - duk_hthread *thr; /* thread; minimizes argument passing */ + duk_hthread *thr; /* thread; minimizes argument passing */ - const duk_uint8_t *input; /* input string (may be a user pointer) */ - duk_size_t input_length; /* input byte length */ - duk_size_t input_offset; /* input offset for window leading edge (not window0) */ - duk_int_t input_line; /* input linenumber at input_offset (not window0), init to 1 */ + const duk_uint8_t *input; /* input string (may be a user pointer) */ + duk_size_t input_length; /* input byte length */ + duk_size_t input_offset; /* input offset for window leading edge (not window0) */ + duk_int_t input_line; /* input linenumber at input_offset (not window0), init to 1 */ - duk_idx_t slot1_idx; /* valstack slot for 1st token value */ - duk_idx_t slot2_idx; /* valstack slot for 2nd token value */ - duk_idx_t buf_idx; /* valstack slot for temp buffer */ - duk_hbuffer_dynamic *buf; /* temp accumulation buffer */ - duk_bufwriter_ctx bw; /* bufwriter for temp accumulation */ + duk_idx_t slot1_idx; /* valstack slot for 1st token value */ + duk_idx_t slot2_idx; /* valstack slot for 2nd token value */ + duk_idx_t buf_idx; /* valstack slot for temp buffer */ + duk_hbuffer_dynamic *buf; /* temp accumulation buffer */ + duk_bufwriter_ctx bw; /* bufwriter for temp accumulation */ - duk_int_t token_count; /* number of tokens parsed */ - duk_int_t token_limit; /* maximum token count before error (sanity backstop) */ + duk_int_t token_count; /* number of tokens parsed */ + duk_int_t token_limit; /* maximum token count before error (sanity backstop) */ - duk_small_uint_t flags; /* lexer flags, use compiler flag defines for now */ + duk_small_uint_t flags; /* lexer flags, use compiler flag defines for now */ }; /* @@ -426,13 +426,10 @@ DUK_INTERNAL_DECL void duk_lexer_setpoint(duk_lexer_ctx *lex_ctx, duk_lexer_point *pt); DUK_INTERNAL_DECL -void duk_lexer_parse_js_input_element(duk_lexer_ctx *lex_ctx, - duk_token *out_token, - duk_bool_t strict_mode, - duk_bool_t regexp_mode); +void duk_lexer_parse_js_input_element(duk_lexer_ctx *lex_ctx, duk_token *out_token, duk_bool_t strict_mode, duk_bool_t regexp_mode); #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL_DECL void duk_lexer_parse_re_token(duk_lexer_ctx *lex_ctx, duk_re_token *out_token); DUK_INTERNAL_DECL void duk_lexer_parse_re_ranges(duk_lexer_ctx *lex_ctx, duk_re_range_callback gen_range, void *userdata); -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ -#endif /* DUK_LEXER_H_INCLUDED */ +#endif /* DUK_LEXER_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_numconv.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_numconv.c
Changed
@@ -12,10 +12,10 @@ #include "duk_internal.h" -#define DUK__IEEE_DOUBLE_EXP_BIAS 1023 -#define DUK__IEEE_DOUBLE_EXP_MIN (-1022) /* biased exp == 0 -> denormal, exp -1022 */ +#define DUK__IEEE_DOUBLE_EXP_BIAS 1023 +#define DUK__IEEE_DOUBLE_EXP_MIN (-1022) /* biased exp == 0 -> denormal, exp -1022 */ -#define DUK__DIGITCHAR(x) duk_lc_digits(x) +#define DUK__DIGITCHAR(x) duk_lc_digits(x) /* * Tables generated with util/gennumdigits.py. @@ -33,10 +33,10 @@ */ DUK_LOCAL const duk_uint8_t duk__str2num_digits_for_radix = { - 69, 44, 35, 30, 27, 25, 23, 22, 20, 20, /* 2 to 11 */ - 20, 19, 19, 18, 18, 17, 17, 17, 16, 16, /* 12 to 21 */ - 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, /* 22 to 31 */ - 14, 14, 14, 14, 14 /* 31 to 36 */ + 69, 44, 35, 30, 27, 25, 23, 22, 20, 20, /* 2 to 11 */ + 20, 19, 19, 18, 18, 17, 17, 17, 16, 16, /* 12 to 21 */ + 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, /* 22 to 31 */ + 14, 14, 14, 14, 14 /* 31 to 36 */ }; typedef struct { @@ -45,15 +45,11 @@ } duk__exp_limits; DUK_LOCAL const duk__exp_limits duk__str2num_exp_limits = { - { 957, -1147 }, { 605, -725 }, { 479, -575 }, { 414, -496 }, - { 372, -446 }, { 342, -411 }, { 321, -384 }, { 304, -364 }, - { 291, -346 }, { 279, -334 }, { 268, -323 }, { 260, -312 }, - { 252, -304 }, { 247, -296 }, { 240, -289 }, { 236, -283 }, - { 231, -278 }, { 227, -273 }, { 223, -267 }, { 220, -263 }, - { 216, -260 }, { 213, -256 }, { 210, -253 }, { 208, -249 }, - { 205, -246 }, { 203, -244 }, { 201, -241 }, { 198, -239 }, - { 196, -237 }, { 195, -234 }, { 193, -232 }, { 191, -230 }, - { 190, -228 }, { 188, -226 }, { 187, -225 }, + { 957, -1147 }, { 605, -725 }, { 479, -575 }, { 414, -496 }, { 372, -446 }, { 342, -411 }, { 321, -384 }, + { 304, -364 }, { 291, -346 }, { 279, -334 }, { 268, -323 }, { 260, -312 }, { 252, -304 }, { 247, -296 }, + { 240, -289 }, { 236, -283 }, { 231, -278 }, { 227, -273 }, { 223, -267 }, { 220, -263 }, { 216, -260 }, + { 213, -256 }, { 210, -253 }, { 208, -249 }, { 205, -246 }, { 203, -244 }, { 201, -241 }, { 198, -239 }, + { 196, -237 }, { 195, -234 }, { 193, -232 }, { 191, -230 }, { 190, -228 }, { 188, -226 }, { 187, -225 }, }; /* @@ -71,18 +67,18 @@ /* This upper value has been experimentally determined; debug build will check * bigint size with assertions. */ -#define DUK__BI_MAX_PARTS 37 /* 37x32 = 1184 bits */ +#define DUK__BI_MAX_PARTS 37 /* 37x32 = 1184 bits */ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK__BI_PRINT(name,x) duk__bi_print((name),(x)) +#define DUK__BI_PRINT(name, x) duk__bi_print((name), (x)) #else -#define DUK__BI_PRINT(name,x) +#define DUK__BI_PRINT(name, x) #endif /* Current size is about 152 bytes. */ typedef struct { duk_small_int_t n; - duk_uint32_t vDUK__BI_MAX_PARTS; /* low to high */ + duk_uint32_t vDUK__BI_MAX_PARTS; /* low to high */ } duk__bigint; #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) @@ -107,9 +103,8 @@ #if defined(DUK_USE_ASSERTIONS) DUK_LOCAL duk_small_int_t duk__bi_is_valid(duk__bigint *x) { - return (duk_small_int_t) - ( ((x->n >= 0) && (x->n <= DUK__BI_MAX_PARTS)) /* is valid size */ && - ((x->n == 0) || (x->vx->n - 1 != 0)) /* is normalized */ ); + return (duk_small_int_t) (((x->n >= 0) && (x->n <= DUK__BI_MAX_PARTS)) /* is valid size */ && + ((x->n == 0) || (x->vx->n - 1 != 0)) /* is normalized */); } #endif @@ -180,10 +175,10 @@ return 0; - ret_gt: +ret_gt: return 1; - ret_lt: +ret_lt: return -1; } @@ -198,11 +193,14 @@ if (z->n > y->n) { duk__bigint *t; - t = y; y = z; z = t; + t = y; + y = z; + z = t; } DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; tmp = 0U; for (i = 0; i < ny; i++) { DUK_ASSERT(i < DUK__BI_MAX_PARTS); @@ -223,7 +221,7 @@ /* no need to normalize */ DUK_ASSERT(duk__bi_is_valid(x)); } -#else /* DUK_USE_64BIT_OPS */ +#else /* DUK_USE_64BIT_OPS */ DUK_LOCAL void duk__bi_add(duk__bigint *x, duk__bigint *y, duk__bigint *z) { duk_uint32_t carry, tmp1, tmp2; duk_small_int_t i, ny, nz; @@ -233,11 +231,14 @@ if (z->n > y->n) { duk__bigint *t; - t = y; y = z; z = t; + t = y; + y = z; + z = t; } DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; carry = 0U; for (i = 0; i < ny; i++) { /* Carry is detected based on wrapping which relies on exact 32-bit @@ -274,7 +275,7 @@ /* no need to normalize */ DUK_ASSERT(duk__bi_is_valid(x)); } -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ /* x <- y + z */ DUK_LOCAL void duk__bi_add_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) { @@ -289,7 +290,7 @@ DUK_ASSERT(duk__bi_is_valid(x)); } -#if 0 /* unused */ +#if 0 /* unused */ /* x <- x + y, use t as temp */ DUK_LOCAL void duk__bi_add_copy(duk__bigint *x, duk__bigint *y, duk__bigint *t) { duk__bi_add(t, x, y); @@ -309,7 +310,8 @@ DUK_ASSERT(duk__bi_compare(y, z) >= 0); DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; tmp = 0; for (i = 0; i < ny; i++) { ty = y->vi; @@ -320,12 +322,12 @@ } tmp = (duk_int64_t) ty - (duk_int64_t) tz + tmp; x->vi = (duk_uint32_t) ((duk_uint64_t) tmp & 0xffffffffUL); - tmp = tmp >> 32; /* 0 or -1 */ + tmp = tmp >> 32; /* 0 or -1 */ } DUK_ASSERT(tmp == 0); x->n = i; - duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ + duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ DUK_ASSERT(duk__bi_is_valid(x)); } #else @@ -338,7 +340,8 @@ DUK_ASSERT(duk__bi_compare(y, z) >= 0); DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; borrow = 0U; for (i = 0; i < ny; i++) { /* Borrow is detected based on wrapping which relies on exact 32-bit @@ -366,12 +369,12 @@ DUK_ASSERT(borrow == 0U); x->n = i; - duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ + duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ DUK_ASSERT(duk__bi_is_valid(x)); } #endif -#if 0 /* unused */ +#if 0 /* unused */ /* x <- y - z */ DUK_LOCAL void duk__bi_sub_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) { duk__bigint tmp; @@ -399,7 +402,7 @@ DUK_ASSERT(duk__bi_is_valid(y)); DUK_ASSERT(duk__bi_is_valid(z)); - nx = y->n + z->n; /* max possible */ + nx = y->n + z->n; /* max possible */ DUK_ASSERT(nx <= DUK__BI_MAX_PARTS); if (nx == 0) { @@ -418,15 +421,15 @@ #if defined(DUK_USE_64BIT_OPS) duk_uint64_t tmp = 0U; for (j = 0; j < nz; j++) { - tmp += (duk_uint64_t) y->vi * (duk_uint64_t) z->vj + x->vi+j; - x->vi+j = (duk_uint32_t) (tmp & 0xffffffffUL); + tmp += (duk_uint64_t) y->vi * (duk_uint64_t) z->vj + x->vi + j; + x->vi + j = (duk_uint32_t) (tmp & 0xffffffffUL); tmp = tmp >> 32; } if (tmp > 0) { DUK_ASSERT(i + j < nx); DUK_ASSERT(i + j < DUK__BI_MAX_PARTS); - DUK_ASSERT(x->vi+j == 0U); - x->vi+j = (duk_uint32_t) tmp; + DUK_ASSERT(x->vi + j == 0U); + x->vi + j = (duk_uint32_t) tmp; } #else /* @@ -446,12 +449,16 @@ duk_uint32_t a, b, c, d, e, f; duk_uint32_t r, s, t; - a = y->vi; b = a & 0xffffUL; a = a >> 16; + a = y->vi; + b = a & 0xffffUL; + a = a >> 16; f = 0; for (j = 0; j < nz; j++) { - c = z->vj; d = c & 0xffffUL; c = c >> 16; - e = x->vi+j; + c = z->vj; + d = c & 0xffffUL; + c = c >> 16; + e = x->vi + j; /* build result as: (r << 32) + s: start with (BD + E + F) */ r = 0; @@ -459,26 +466,34 @@ /* add E */ t = s + e; - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add F */ t = s + f; - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add BC*2^16 */ t = b * c; r += (t >> 16); t = s + ((t & 0xffffUL) << 16); - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add AD*2^16 */ t = a * d; r += (t >> 16); t = s + ((t & 0xffffUL) << 16); - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add AC*2^32 */ @@ -486,20 +501,22 @@ r += t; DUK_DDD(DUK_DDDPRINT("ab=%08lx cd=%08lx ef=%08lx -> rs=%08lx %08lx", - (unsigned long) y->vi, (unsigned long) z->vj, - (unsigned long) x->vi+j, (unsigned long) r, + (unsigned long) y->vi, + (unsigned long) z->vj, + (unsigned long) x->vi + j, + (unsigned long) r, (unsigned long) s)); - x->vi+j = s; + x->vi + j = s; f = r; } if (f > 0U) { DUK_ASSERT(i + j < nx); DUK_ASSERT(i + j < DUK__BI_MAX_PARTS); - DUK_ASSERT(x->vi+j == 0U); - x->vi+j = (duk_uint32_t) f; + DUK_ASSERT(x->vi + j == 0U); + x->vi + j = (duk_uint32_t) f; } -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ } duk__bi_normalize(x); @@ -538,7 +555,7 @@ DUK_LOCAL int duk__bi_is_zero(duk__bigint *x) { DUK_ASSERT(duk__bi_is_valid(x)); - return (x->n == 0); /* this is the case for normalized numbers */ + return (x->n == 0); /* this is the case for normalized numbers */ } /* Bigint is 2^52. Used to detect normalized IEEE double mantissa values @@ -549,8 +566,7 @@ */ DUK_LOCAL duk_small_int_t duk__bi_is_2to52(duk__bigint *x) { DUK_ASSERT(duk__bi_is_valid(x)); - return (duk_small_int_t) - (x->n == 2) && (x->v0 == 0U) && (x->v1 == (1U << (52-32))); + return (duk_small_int_t) (x->n == 2) && (x->v0 == 0U) && (x->v1 == (1U << (52 - 32))); } /* x <- (1<<y) */ @@ -569,7 +585,7 @@ DUK_LOCAL void duk__bi_exp_small(duk__bigint *x, duk_small_int_t b, duk_small_int_t y, duk__bigint *t1, duk__bigint *t2) { /* Fast path the binary case */ - DUK_ASSERT(x != t1 && x != t2 && t1 != t2); /* distinct bignums, easy mistake to make */ + DUK_ASSERT(x != t1 && x != t2 && t1 != t2); /* distinct bignums, easy mistake to make */ DUK_ASSERT(b >= 0); DUK_ASSERT(y >= 0); @@ -624,14 +640,14 @@ */ /* Maximum number of digits generated. */ -#define DUK__MAX_OUTPUT_DIGITS 1040 /* (Number.MAX_VALUE).toString(2).length == 1024, + slack */ +#define DUK__MAX_OUTPUT_DIGITS 1040 /* (Number.MAX_VALUE).toString(2).length == 1024, + slack */ /* Maximum number of characters in formatted value. */ -#define DUK__MAX_FORMATTED_LENGTH 1040 /* (-Number.MAX_VALUE).toString(2).length == 1025, + slack */ +#define DUK__MAX_FORMATTED_LENGTH 1040 /* (-Number.MAX_VALUE).toString(2).length == 1025, + slack */ /* Number and (minimum) size of bigints in the nc_ctx structure. */ -#define DUK__NUMCONV_CTX_NUM_BIGINTS 7 -#define DUK__NUMCONV_CTX_BIGINTS_SIZE (sizeof(duk__bigint) * DUK__NUMCONV_CTX_NUM_BIGINTS) +#define DUK__NUMCONV_CTX_NUM_BIGINTS 7 +#define DUK__NUMCONV_CTX_BIGINTS_SIZE (sizeof(duk__bigint) * DUK__NUMCONV_CTX_NUM_BIGINTS) typedef struct { /* Currently about 7*152 = 1064 bytes. The space for these @@ -641,31 +657,32 @@ */ duk__bigint f, r, s, mp, mm, t1, t2; - duk_small_int_t is_s2n; /* if 1, doing a string-to-number; else doing a number-to-string */ - duk_small_int_t is_fixed; /* if 1, doing a fixed format output (not free format) */ - duk_small_int_t req_digits; /* requested number of output digits; 0 = free-format */ - duk_small_int_t abs_pos; /* digit position is absolute, not relative */ - duk_small_int_t e; /* exponent for 'f' */ - duk_small_int_t b; /* input radix */ - duk_small_int_t B; /* output radix */ - duk_small_int_t k; /* see algorithm */ - duk_small_int_t low_ok; /* see algorithm */ - duk_small_int_t high_ok; /* see algorithm */ - duk_small_int_t unequal_gaps; /* m+ != m- (very rarely) */ + duk_small_int_t is_s2n; /* if 1, doing a string-to-number; else doing a number-to-string */ + duk_small_int_t is_fixed; /* if 1, doing a fixed format output (not free format) */ + duk_small_int_t req_digits; /* requested number of output digits; 0 = free-format */ + duk_small_int_t abs_pos; /* digit position is absolute, not relative */ + duk_small_int_t e; /* exponent for 'f' */ + duk_small_int_t b; /* input radix */ + duk_small_int_t B; /* output radix */ + duk_small_int_t k; /* see algorithm */ + duk_small_int_t low_ok; /* see algorithm */ + duk_small_int_t high_ok; /* see algorithm */ + duk_small_int_t unequal_gaps; /* m+ != m- (very rarely) */ /* Buffer used for generated digits, values are in the range 0,B-1. */ duk_uint8_t digitsDUK__MAX_OUTPUT_DIGITS; - duk_small_int_t count; /* digit count */ + duk_small_int_t count; /* digit count */ } duk__numconv_stringify_ctx; /* Note: computes with 'idx' in assertions, so caller beware. * 'idx' is preincremented, i.e. '1' on first call, because it * is more convenient for the caller. */ -#define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx,preinc_idx,x) do { \ - DUK_ASSERT((preinc_idx) - 1 >= 0); \ - DUK_ASSERT((preinc_idx) - 1 < DUK__MAX_OUTPUT_DIGITS); \ - ((nc_ctx)->digits(preinc_idx) - 1) = (duk_uint8_t) (x); \ +#define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, preinc_idx, x) \ + do { \ + DUK_ASSERT((preinc_idx) -1 >= 0); \ + DUK_ASSERT((preinc_idx) -1 < DUK__MAX_OUTPUT_DIGITS); \ + ((nc_ctx)->digits(preinc_idx) -1) = (duk_uint8_t) (x); \ } while (0) DUK_LOCAL duk_size_t duk__dragon4_format_uint32(duk_uint8_t *buf, duk_uint32_t x, duk_small_int_t radix) { @@ -764,11 +781,11 @@ "lowest mantissa value for this exponent -> " "unequal gaps")); - duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ - duk__bi_mul_small(&nc_ctx->mp, &nc_ctx->mm, (duk_uint32_t) nc_ctx->b); /* mp <- b^(e+1) */ + duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ + duk__bi_mul_small(&nc_ctx->mp, &nc_ctx->mm, (duk_uint32_t) nc_ctx->b); /* mp <- b^(e+1) */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->f, 2); - duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^(e+1) */ - duk__bi_set_small(&nc_ctx->s, (duk_uint32_t) (nc_ctx->b * 2)); /* s <- 2 * b */ + duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^(e+1) */ + duk__bi_set_small(&nc_ctx->s, (duk_uint32_t) (nc_ctx->b * 2)); /* s <- 2 * b */ nc_ctx->unequal_gaps = 1; } else { /* (>= e 0) AND (not (= f (expt b (- p 1)))) @@ -788,11 +805,11 @@ "not lowest mantissa for this exponent -> " "equal gaps")); - duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ - duk__bi_copy(&nc_ctx->mp, &nc_ctx->mm); /* mp <- b^e */ + duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ + duk__bi_copy(&nc_ctx->mp, &nc_ctx->mm); /* mp <- b^e */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->f, 2); - duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^e */ - duk__bi_set_small(&nc_ctx->s, 2); /* s <- 2 */ + duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^e */ + duk__bi_set_small(&nc_ctx->s, 2); /* s <- 2 */ } } else { /* When doing string-to-number, lowest_mantissa is always 0 so @@ -814,9 +831,13 @@ "lowest mantissa for this exponent -> " "unequal gaps")); - duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, (duk_uint32_t) (nc_ctx->b * 2)); /* r <- (2 * b) * f */ - duk__bi_exp_small(&nc_ctx->t1, nc_ctx->b, 1 - nc_ctx->e, &nc_ctx->s, &nc_ctx->t2); /* NB: use 's' as temp on purpose */ - duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(1-e) * 2 */ + duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, (duk_uint32_t) (nc_ctx->b * 2)); /* r <- (2 * b) * f */ + duk__bi_exp_small(&nc_ctx->t1, + nc_ctx->b, + 1 - nc_ctx->e, + &nc_ctx->s, + &nc_ctx->t2); /* NB: use 's' as temp on purpose */ + duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(1-e) * 2 */ duk__bi_set_small(&nc_ctx->mp, 2); duk__bi_set_small(&nc_ctx->mm, 1); nc_ctx->unequal_gaps = 1; @@ -835,9 +856,13 @@ "lowest mantissa for this exponent -> " "equal gaps")); - duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, 2); /* r <- 2 * f */ - duk__bi_exp_small(&nc_ctx->t1, nc_ctx->b, -nc_ctx->e, &nc_ctx->s, &nc_ctx->t2); /* NB: use 's' as temp on purpose */ - duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(-e) * 2 */ + duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, 2); /* r <- 2 * f */ + duk__bi_exp_small(&nc_ctx->t1, + nc_ctx->b, + -nc_ctx->e, + &nc_ctx->s, + &nc_ctx->t2); /* NB: use 's' as temp on purpose */ + duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(-e) * 2 */ duk__bi_set_small(&nc_ctx->mp, 1); duk__bi_set_small(&nc_ctx->mm, 1); } @@ -869,8 +894,8 @@ * impact for very large and very small numbers. */ - DUK_DDD(DUK_DDDPRINT("scale: B=%ld, low_ok=%ld, high_ok=%ld", - (long) nc_ctx->B, (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); + DUK_DDD( + DUK_DDDPRINT("scale: B=%ld, low_ok=%ld, high_ok=%ld", (long) nc_ctx->B, (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); DUK__BI_PRINT("r(init)", &nc_ctx->r); DUK__BI_PRINT("s(init)", &nc_ctx->s); DUK__BI_PRINT("mp(init)", &nc_ctx->mp); @@ -883,7 +908,7 @@ DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) >= (nc_ctx->high_ok ? 0 : 1)) { DUK_DDD(DUK_DDDPRINT("k is too low")); /* r <- r @@ -912,8 +937,8 @@ DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ - duk__bi_mul_small(&nc_ctx->t2, &nc_ctx->t1, (duk_uint32_t) nc_ctx->B); /* t2 = (* (+ r m+) B) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ + duk__bi_mul_small(&nc_ctx->t2, &nc_ctx->t1, (duk_uint32_t) nc_ctx->B); /* t2 = (* (+ r m+) B) */ if (duk__bi_compare(&nc_ctx->t2, &nc_ctx->s) <= (nc_ctx->high_ok ? -1 : 0)) { DUK_DDD(DUK_DDDPRINT("k is too high")); /* r <- (* r B) @@ -934,11 +959,11 @@ } } - skip_dec_k: +skip_dec_k: if (!nc_ctx->unequal_gaps) { DUK_DDD(DUK_DDDPRINT("equal gaps, copy m- from m+")); - duk__bi_copy(&nc_ctx->mm, &nc_ctx->mp); /* mm <- mp */ + duk__bi_copy(&nc_ctx->mm, &nc_ctx->mp); /* mm <- mp */ } nc_ctx->k = k; @@ -950,9 +975,9 @@ } DUK_LOCAL void duk__dragon4_generate(duk__numconv_stringify_ctx *nc_ctx) { - duk_small_int_t tc1, tc2; /* terminating conditions */ - duk_small_int_t d; /* current digit */ - duk_small_int_t count = 0; /* digit count */ + duk_small_int_t tc1, tc2; /* terminating conditions */ + duk_small_int_t d; /* current digit */ + duk_small_int_t count = 0; /* digit count */ /* * Digit generation loop. @@ -974,25 +999,28 @@ for (;;) { DUK_DDD(DUK_DDDPRINT("generate loop, count=%ld, k=%ld, B=%ld, low_ok=%ld, high_ok=%ld", - (long) count, (long) nc_ctx->k, (long) nc_ctx->B, - (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); + (long) count, + (long) nc_ctx->k, + (long) nc_ctx->B, + (long) nc_ctx->low_ok, + (long) nc_ctx->high_ok)); DUK__BI_PRINT("r", &nc_ctx->r); DUK__BI_PRINT("s", &nc_ctx->s); DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); /* (quotient-remainder (* r B) s) using a dummy subtraction loop */ - duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, (duk_uint32_t) nc_ctx->B); /* t1 <- (* r B) */ + duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, (duk_uint32_t) nc_ctx->B); /* t1 <- (* r B) */ d = 0; for (;;) { if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { break; } - duk__bi_sub_copy(&nc_ctx->t1, &nc_ctx->s, &nc_ctx->t2); /* t1 <- t1 - s */ + duk__bi_sub_copy(&nc_ctx->t1, &nc_ctx->s, &nc_ctx->t2); /* t1 <- t1 - s */ d++; } - duk__bi_copy(&nc_ctx->r, &nc_ctx->t1); /* r <- (remainder (* r B) s) */ - /* d <- (quotient (* r B) s) (in range 0...B-1) */ + duk__bi_copy(&nc_ctx->r, &nc_ctx->t1); /* r <- (remainder (* r B) s) */ + /* d <- (quotient (* r B) s) (in range 0...B-1) */ DUK_DDD(DUK_DDDPRINT("-> d(quot)=%ld", (long) d)); DUK__BI_PRINT("r(rem)", &nc_ctx->r); @@ -1011,7 +1039,7 @@ /* free-form */ tc1 = (duk__bi_compare(&nc_ctx->r, &nc_ctx->mm) <= (nc_ctx->low_ok ? 0 : -1)); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 <- (+ r m+) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 <- (+ r m+) */ tc2 = (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) >= (nc_ctx->high_ok ? 0 : 1)); DUK_DDD(DUK_DDDPRINT("tc1=%ld, tc2=%ld", (long) tc1, (long) tc2)); @@ -1030,20 +1058,21 @@ if (tc2) { /* tc1 = true, tc2 = true */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, 2); - if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { /* (< (* r 2) s) */ + if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { /* (< (* r 2) s) */ DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=true, 2r > s: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + (long) d, + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); } else { DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=true, 2r <= s: output d+1 --> %ld (k=%ld)", - (long) (d + 1), (long) nc_ctx->k)); + (long) (d + 1), + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d + 1); } break; } else { /* tc1 = true, tc2 = false */ - DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=false: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=false: output d --> %ld (k=%ld)", (long) d, (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); break; } @@ -1051,13 +1080,13 @@ if (tc2) { /* tc1 = false, tc2 = true */ DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=true: output d+1 --> %ld (k=%ld)", - (long) (d + 1), (long) nc_ctx->k)); + (long) (d + 1), + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d + 1); break; } else { /* tc1 = false, tc2 = false */ - DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=false: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=false: output d --> %ld (k=%ld)", (long) d, (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); /* r <- r (updated above: r <- (remainder (* r B) s) @@ -1074,23 +1103,28 @@ /* fixed-format termination conditions */ if (nc_ctx->is_fixed) { if (nc_ctx->abs_pos) { - int pos = nc_ctx->k - count + 1; /* count is already incremented, take into account */ + int pos = nc_ctx->k - count + 1; /* count is already incremented, take into account */ DUK_DDD(DUK_DDDPRINT("fixed format, absolute: abs pos=%ld, k=%ld, count=%ld, req=%ld", - (long) pos, (long) nc_ctx->k, (long) count, (long) nc_ctx->req_digits)); + (long) pos, + (long) nc_ctx->k, + (long) count, + (long) nc_ctx->req_digits)); if (pos <= nc_ctx->req_digits) { DUK_DDD(DUK_DDDPRINT("digit position reached req_digits, end generate loop")); break; } } else { DUK_DDD(DUK_DDDPRINT("fixed format, relative: k=%ld, count=%ld, req=%ld", - (long) nc_ctx->k, (long) count, (long) nc_ctx->req_digits)); + (long) nc_ctx->k, + (long) count, + (long) nc_ctx->req_digits)); if (count >= nc_ctx->req_digits) { DUK_DDD(DUK_DDDPRINT("digit count reached req_digits, end generate loop")); break; } } } - } /* for */ + } /* for */ nc_ctx->count = count; @@ -1109,8 +1143,7 @@ bufi = (duk_uint8_t) DUK__DIGITCHAR(t); } } - DUK_DDD(DUK_DDDPRINT("-> generated digits; k=%ld, digits='%s'", - (long) nc_ctx->k, (const char *) buf)); + DUK_DDD(DUK_DDDPRINT("-> generated digits; k=%ld, digits='%s'", (long) nc_ctx->k, (const char *) buf)); } #endif } @@ -1139,11 +1172,11 @@ if (round_idx >= nc_ctx->count) { DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld >= %ld (count)) -> no rounding", - (long) round_idx, (long) nc_ctx->count)); + (long) round_idx, + (long) nc_ctx->count)); return 0; } else if (round_idx < 0) { - DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld < 0) -> no rounding", - (long) round_idx)); + DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld < 0) -> no rounding", (long) round_idx)); return 0; } @@ -1168,15 +1201,18 @@ duk_memmove((void *) (&nc_ctx->digits1), (const void *) (&nc_ctx->digits0), (size_t) (sizeof(char) * (size_t) nc_ctx->count)); - nc_ctx->digits0 = 1; /* don't increase 'count' */ - nc_ctx->k++; /* position of highest digit changed */ - nc_ctx->count++; /* number of digits changed */ + nc_ctx->digits0 = 1; /* don't increase 'count' */ + nc_ctx->k++; /* position of highest digit changed */ + nc_ctx->count++; /* number of digits changed */ ret = 1; break; } DUK_DDD(DUK_DDDPRINT("fixed-format rounding carry: B=%ld, roundup_limit=%ld, p=%p, digits=%p", - (long) nc_ctx->B, (long) roundup_limit, (void *) p, (void *) nc_ctx->digits)); + (long) nc_ctx->B, + (long) roundup_limit, + (void *) p, + (void *) nc_ctx->digits)); p--; t = *p; DUK_DDD(DUK_DDDPRINT("digit before carry: %ld", (long) t)); @@ -1193,7 +1229,7 @@ return ret; } -#define DUK__NO_EXP (65536) /* arbitrary marker, outside valid exp range */ +#define DUK__NO_EXP (65536) /* arbitrary marker, outside valid exp range */ DUK_LOCAL void duk__dragon4_convert_and_push(duk__numconv_stringify_ctx *nc_ctx, duk_hthread *thr, @@ -1236,7 +1272,7 @@ DUK_ASSERT(nc_ctx->count >= 1); k = nc_ctx->k; - buf = (duk_uint8_t *) &nc_ctx->f; /* XXX: union would be more correct */ + buf = (duk_uint8_t *) &nc_ctx->f; /* XXX: union would be more correct */ q = buf; /* Exponent handling: if exponent format is used, record exponent value and @@ -1248,14 +1284,13 @@ expt = DUK__NO_EXP; if (!nc_ctx->abs_pos /* toFixed() */) { - if ((flags & DUK_N2S_FLAG_FORCE_EXP) || /* exponential notation forced */ - ((flags & DUK_N2S_FLAG_NO_ZERO_PAD) && /* fixed precision and zero padding would be required */ - (k - digits >= 1)) || /* (e.g. k=3, digits=2 -> "12X") */ - ((k > 21 || k <= -6) && (radix == 10))) { /* toString() conditions */ - DUK_DDD(DUK_DDDPRINT("use exponential notation: k=%ld -> expt=%ld", - (long) k, (long) (k - 1))); - expt = k - 1; /* e.g. 12.3 -> digits="123" k=2 -> 1.23e1 */ - k = 1; /* generate mantissa with a single leading whole number digit */ + if ((flags & DUK_N2S_FLAG_FORCE_EXP) || /* exponential notation forced */ + ((flags & DUK_N2S_FLAG_NO_ZERO_PAD) && /* fixed precision and zero padding would be required */ + (k - digits >= 1)) || /* (e.g. k=3, digits=2 -> "12X") */ + ((k > 21 || k <= -6) && (radix == 10))) { /* toString() conditions */ + DUK_DDD(DUK_DDDPRINT("use exponential notation: k=%ld -> expt=%ld", (long) k, (long) (k - 1))); + expt = k - 1; /* e.g. 12.3 -> digits="123" k=2 -> 1.23e1 */ + k = 1; /* generate mantissa with a single leading whole number digit */ } } @@ -1281,13 +1316,18 @@ DUK_DDD(DUK_DDDPRINT("expt=%ld, k=%ld, count=%ld, pos=%ld, pos_end=%ld, is_fixed=%ld, " "digits=%ld, abs_pos=%ld", - (long) expt, (long) k, (long) nc_ctx->count, (long) pos, (long) pos_end, - (long) nc_ctx->is_fixed, (long) digits, (long) nc_ctx->abs_pos)); + (long) expt, + (long) k, + (long) nc_ctx->count, + (long) pos, + (long) pos_end, + (long) nc_ctx->is_fixed, + (long) digits, + (long) nc_ctx->abs_pos)); /* Digit generation */ while (pos > pos_end) { - DUK_DDD(DUK_DDDPRINT("digit generation: pos=%ld, pos_end=%ld", - (long) pos, (long) pos_end)); + DUK_DDD(DUK_DDDPRINT("digit generation: pos=%ld, pos_end=%ld", (long) pos, (long) pos_end)); if (pos == 0) { *q++ = (duk_uint8_t) '.'; } @@ -1380,7 +1420,7 @@ /* normal: implicit leading 1-bit */ nc_ctx->f.v1 |= 0x00100000UL; expt = expt - DUK__IEEE_DOUBLE_EXP_BIAS - 52; - DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); /* true, because v1 has at least one bit set */ + DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); /* true, because v1 has at least one bit set */ } DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); @@ -1403,7 +1443,7 @@ /* Sometimes this assert is not true right now; it will be true after * rounding. See: test-bug-numconv-mantissa-assert.js. */ - DUK_ASSERT_DISABLE(nc_ctx->digits0 == 1); /* zero handled by caller */ + DUK_ASSERT_DISABLE(nc_ctx->digits0 == 1); /* zero handled by caller */ /* Should not be required because the code below always sets both high * and low parts, but at least gcc-4.4.5 fails to deduce this correctly @@ -1448,31 +1488,30 @@ skip_round = 0; - recheck_exp: +recheck_exp: - expt = nc_ctx->k - 1; /* IEEE exp without bias */ + expt = nc_ctx->k - 1; /* IEEE exp without bias */ if (expt > 1023) { /* Infinity */ - bitstart = -255; /* needed for inf: causes mantissa to become zero, - * and rounding to be skipped. - */ + bitstart = -255; /* needed for inf: causes mantissa to become zero, + * and rounding to be skipped. + */ expt = 2047; } else if (expt >= -1022) { /* normal */ - bitstart = 1; /* skip leading digit */ + bitstart = 1; /* skip leading digit */ expt += DUK__IEEE_DOUBLE_EXP_BIAS; DUK_ASSERT(expt >= 1 && expt <= 2046); } else { /* denormal or zero */ - bitstart = 1023 + expt; /* expt==-1023 -> bitstart=0 (leading 1); - * expt==-1024 -> bitstart=-1 (one left of leading 1), etc - */ + bitstart = 1023 + expt; /* expt==-1023 -> bitstart=0 (leading 1); + * expt==-1024 -> bitstart=-1 (one left of leading 1), etc + */ expt = 0; } bitround = bitstart + 52; - DUK_DDD(DUK_DDDPRINT("ieee expt=%ld, bitstart=%ld, bitround=%ld", - (long) expt, (long) bitstart, (long) bitround)); + DUK_DDD(DUK_DDDPRINT("ieee expt=%ld, bitstart=%ld, bitround=%ld", (long) expt, (long) bitstart, (long) bitround)); if (!skip_round) { if (duk__dragon4_fixed_format_round(nc_ctx, bitround)) { @@ -1510,13 +1549,11 @@ } /* t has high mantissa */ - DUK_DDD(DUK_DDDPRINT("mantissa is complete: %08lx %08lx", - (unsigned long) t, - (unsigned long) DUK_DBLUNION_GET_LOW32(&u))); + DUK_DDD(DUK_DDDPRINT("mantissa is complete: %08lx %08lx", (unsigned long) t, (unsigned long) DUK_DBLUNION_GET_LOW32(&u))); DUK_ASSERT(expt >= 0 && expt <= 0x7ffL); t += ((duk_uint32_t) expt) << 20; -#if 0 /* caller handles sign change */ +#if 0 /* caller handles sign change */ if (negative) { t |= 0x80000000U; } @@ -1537,12 +1574,15 @@ * Output: string */ -DUK_LOCAL DUK_NOINLINE void duk__numconv_stringify_raw(duk_hthread *thr, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags) { +DUK_LOCAL DUK_NOINLINE void duk__numconv_stringify_raw(duk_hthread *thr, + duk_small_int_t radix, + duk_small_int_t digits, + duk_small_uint_t flags) { duk_double_t x; duk_small_int_t c; duk_small_int_t neg; duk_uint32_t uval; - duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ + duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ duk__numconv_stringify_ctx *nc_ctx = &nc_ctx_alloc; x = (duk_double_t) duk_require_number(thr, -1); @@ -1594,13 +1634,13 @@ */ uval = duk_double_to_uint32_t(x); - if (duk_double_equals((double) uval, x) && /* integer number in range */ - flags == 0) { /* no special formatting */ + if (duk_double_equals((double) uval, x) && /* integer number in range */ + flags == 0) { /* no special formatting */ /* use bigint area as a temp */ duk_uint8_t *buf = (duk_uint8_t *) (&nc_ctx->f); duk_uint8_t *p = buf; - DUK_ASSERT(DUK__NUMCONV_CTX_BIGINTS_SIZE >= 32 + 1); /* max size: radix=2 + sign */ + DUK_ASSERT(DUK__NUMCONV_CTX_BIGINTS_SIZE >= 32 + 1); /* max size: radix=2 + sign */ if (neg && uval != 0) { /* no negative sign for zero */ *p++ = (duk_uint8_t) '-'; @@ -1656,9 +1696,9 @@ duk_small_int_t count; if (nc_ctx->is_fixed) { if (nc_ctx->abs_pos) { - count = digits + 2; /* lead zero + 'digits' fractions + 1 for rounding */ + count = digits + 2; /* lead zero + 'digits' fractions + 1 for rounding */ } else { - count = digits + 1; /* + 1 for rounding */ + count = digits + 1; /* + 1 for rounding */ } } else { count = 1; @@ -1667,12 +1707,12 @@ DUK_ASSERT(count >= 1); duk_memzero((void *) nc_ctx->digits, (size_t) count); nc_ctx->count = count; - nc_ctx->k = 1; /* 0.000... */ + nc_ctx->k = 1; /* 0.000... */ neg = 0; goto zero_skip; } - duk__dragon4_double_to_ctx(nc_ctx, x); /* -> sets 'f' and 'e' */ + duk__dragon4_double_to_ctx(nc_ctx, x); /* -> sets 'f' and 'e' */ DUK__BI_PRINT("f", &nc_ctx->f); DUK_DDD(DUK_DDDPRINT("e=%ld", (long) nc_ctx->e)); @@ -1680,7 +1720,7 @@ * Dragon4 slow path digit generation. */ - duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ + duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ DUK_DDD(DUK_DDDPRINT("after prepare:")); DUK__BI_PRINT("r", &nc_ctx->r); @@ -1702,7 +1742,7 @@ * Convert and push final string. */ - zero_skip: +zero_skip: if (flags & DUK_N2S_FLAG_FIXED_FORMAT) { /* Perform fixed-format rounding. */ @@ -1711,13 +1751,16 @@ /* 'roundpos' is relative to nc_ctx->k and increases to the right * (opposite of how 'k' changes). */ - roundpos = -digits; /* absolute position for digit considered for rounding */ + roundpos = -digits; /* absolute position for digit considered for rounding */ roundpos = nc_ctx->k - roundpos; } else { roundpos = digits; } DUK_DDD(DUK_DDDPRINT("rounding: k=%ld, count=%ld, digits=%ld, roundpos=%ld", - (long) nc_ctx->k, (long) nc_ctx->count, (long) digits, (long) roundpos)); + (long) nc_ctx->k, + (long) nc_ctx->count, + (long) digits, + (long) roundpos)); (void) duk__dragon4_fixed_format_round(nc_ctx, roundpos); /* Note: 'count' is currently not adjusted by rounding (i.e. the @@ -1746,7 +1789,7 @@ */ DUK_LOCAL DUK_NOINLINE void duk__numconv_parse_raw(duk_hthread *thr, duk_small_int_t radix, duk_small_uint_t flags) { - duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ + duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ duk__numconv_stringify_ctx *nc_ctx = &nc_ctx_alloc; duk_double_t res; duk_hstring *h_str; @@ -1766,7 +1809,8 @@ DUK_DDD(DUK_DDDPRINT("parse number: %!T, radix=%ld, flags=0x%08lx", (duk_tval *) duk_get_tval(thr, -1), - (long) radix, (unsigned long) flags)); + (long) radix, + (unsigned long) flags)); DUK_ASSERT(radix >= 2 && radix <= 36); DUK_ASSERT(radix - 2 < (duk_small_int_t) sizeof(duk__str2num_digits_for_radix)); @@ -1839,7 +1883,7 @@ ch = *p; if (ch == (duk_small_int_t) '0') { duk_small_int_t detect_radix = 0; - ch = DUK_LOWERCASE_CHAR_ASCII(p1); /* 'x' or 'X' -> 'x' */ + ch = DUK_LOWERCASE_CHAR_ASCII(p1); /* 'x' or 'X' -> 'x' */ if ((flags & DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT) && ch == DUK_ASC_LC_X) { DUK_DDD(DUK_DDDPRINT("detected 0x/0X hex prefix, changing radix and preventing fractions and exponent")); detect_radix = 16; @@ -1866,10 +1910,9 @@ if (detect_radix > 0) { radix = detect_radix; /* Clear empty as zero flag: interpret e.g. '0x' and '0xg' as a NaN (= parse error) */ - flags &= ~(DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO); - flags |= DUK_S2N_FLAG_ALLOW_LEADING_ZERO; /* allow e.g. '0x0009' and '0b00010001' */ + flags &= ~(DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_FRAC | + DUK_S2N_FLAG_ALLOW_NAKED_FRAC | DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO); + flags |= DUK_S2N_FLAG_ALLOW_LEADING_ZERO; /* allow e.g. '0x0009' and '0b00010001' */ p += 2; } } @@ -1927,16 +1970,23 @@ dig_frac = -1; dig_expt = -1; expt = 0; - expt_adj = 0; /* essentially tracks digit position of lowest 'f' digit */ + expt_adj = 0; /* essentially tracks digit position of lowest 'f' digit */ expt_neg = 0; for (;;) { ch = *p++; DUK_DDD(DUK_DDDPRINT("parse digits: p=%p, ch='%c' (%ld), expt=%ld, expt_adj=%ld, " "dig_whole=%ld, dig_frac=%ld, dig_expt=%ld, dig_lzero=%ld, dig_prec=%ld", - (const void *) p, (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : '?'), (long) ch, - (long) expt, (long) expt_adj, (long) dig_whole, (long) dig_frac, - (long) dig_expt, (long) dig_lzero, (long) dig_prec)); + (const void *) p, + (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : '?'), + (long) ch, + (long) expt, + (long) expt_adj, + (long) dig_whole, + (long) dig_frac, + (long) dig_expt, + (long) dig_lzero, + (long) dig_prec)); DUK__BI_PRINT("f", &nc_ctx->f); /* Most common cases first. */ @@ -1975,8 +2025,8 @@ } else if (ch == (duk_small_int_t) 0) { DUK_DDD(DUK_DDDPRINT("NUL termination")); break; - } else if ((flags & DUK_S2N_FLAG_ALLOW_EXP) && - dig_expt < 0 && (ch == (duk_small_int_t) 'e' || ch == (duk_small_int_t) 'E')) { + } else if ((flags & DUK_S2N_FLAG_ALLOW_EXP) && dig_expt < 0 && + (ch == (duk_small_int_t) 'e' || ch == (duk_small_int_t) 'E')) { /* Note: we don't parse back exponent notation for anything else * than radix 10, so this is not an ambiguous check (e.g. hex * exponent values may have 'e' either as a significand digit @@ -2006,7 +2056,7 @@ } else if (ch >= (duk_small_int_t) 'A' && ch <= (duk_small_int_t) 'Z') { dig = (duk_small_int_t) (ch - (duk_small_int_t) 'A' + 0x0a); } else { - dig = 255; /* triggers garbage digit check below */ + dig = 255; /* triggers garbage digit check below */ } DUK_ASSERT((dig >= 0 && dig <= 35) || dig == 255); @@ -2139,14 +2189,14 @@ if (expt_neg) { expt = -expt; } - DUK_DDD(DUK_DDDPRINT("expt=%ld, expt_adj=%ld, net exponent -> %ld", - (long) expt, (long) expt_adj, (long) (expt + expt_adj))); + DUK_DDD( + DUK_DDDPRINT("expt=%ld, expt_adj=%ld, net exponent -> %ld", (long) expt, (long) expt_adj, (long) (expt + expt_adj))); expt += expt_adj; /* Fast path check. */ - if (nc_ctx->f.n <= 1 && /* 32-bit value */ - expt == 0 /* no net exponent */) { + if (nc_ctx->f.n <= 1 && /* 32-bit value */ + expt == 0 /* no net exponent */) { /* Fast path is triggered for no exponent and also for balanced exponent * and fraction parts, e.g. for "1.23e2" == "123". Remember to respect * zero sign. @@ -2188,7 +2238,6 @@ goto negcheck_and_ret; } - /* Quick reject of too large or too small exponents. This check * would be incorrect for zero (e.g. "0e1000" is zero, not Infinity) * so zero check must be above. @@ -2221,7 +2270,7 @@ * An extra digit is generated for rounding. */ - duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ + duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ DUK_DDD(DUK_DDDPRINT("after prepare:")); DUK__BI_PRINT("r", &nc_ctx->r); @@ -2253,7 +2302,7 @@ duk__dragon4_ctx_to_double(nc_ctx, &res); goto negcheck_and_ret; - negcheck_and_ret: +negcheck_and_ret: if (neg) { res = -res; } @@ -2262,13 +2311,13 @@ DUK_DDD(DUK_DDDPRINT("result: %!T", (duk_tval *) duk_get_tval(thr, -1))); return; - parse_fail: +parse_fail: DUK_DDD(DUK_DDDPRINT("parse failed")); duk_pop(thr); duk_push_nan(thr); return; - parse_explimit_error: +parse_explimit_error: DUK_DDD(DUK_DDDPRINT("parse failed, internal error, can't return a value")); DUK_ERROR_RANGE(thr, "exponent too large"); DUK_WO_NORETURN(return;);
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_numconv.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_numconv.h
Changed
@@ -9,23 +9,23 @@ /* Output a specified number of digits instead of using the shortest * form. Used for toPrecision() and toFixed(). */ -#define DUK_N2S_FLAG_FIXED_FORMAT (1U << 0) +#define DUK_N2S_FLAG_FIXED_FORMAT (1U << 0) /* Force exponential format. Used for toExponential(). */ -#define DUK_N2S_FLAG_FORCE_EXP (1U << 1) +#define DUK_N2S_FLAG_FORCE_EXP (1U << 1) /* If number would need zero padding (for whole number part), use * exponential format instead. E.g. if input number is 12300, 3 * digits are generated ("123"), output "1.23e+4" instead of "12300". * Used for toPrecision(). */ -#define DUK_N2S_FLAG_NO_ZERO_PAD (1U << 2) +#define DUK_N2S_FLAG_NO_ZERO_PAD (1U << 2) /* Digit count indicates number of fractions (i.e. an absolute * digit index instead of a relative one). Used together with * DUK_N2S_FLAG_FIXED_FORMAT for toFixed(). */ -#define DUK_N2S_FLAG_FRACTION_DIGITS (1U << 3) +#define DUK_N2S_FLAG_FRACTION_DIGITS (1U << 3) /* * String-to-number conversion @@ -39,66 +39,69 @@ * radix 10, but with maximum radix (36) a safe limit is: * (10000000*36).toString(16) -> '15752a00' */ -#define DUK_S2N_MAX_EXPONENT 10000000L +#define DUK_S2N_MAX_EXPONENT 10000000L /* Trim white space (= allow leading and trailing whitespace) */ -#define DUK_S2N_FLAG_TRIM_WHITE (1U << 0) +#define DUK_S2N_FLAG_TRIM_WHITE (1U << 0) /* Allow exponent */ -#define DUK_S2N_FLAG_ALLOW_EXP (1U << 1) +#define DUK_S2N_FLAG_ALLOW_EXP (1U << 1) /* Allow trailing garbage (e.g. treat "123foo" as "123) */ -#define DUK_S2N_FLAG_ALLOW_GARBAGE (1U << 2) +#define DUK_S2N_FLAG_ALLOW_GARBAGE (1U << 2) /* Allow leading plus sign */ -#define DUK_S2N_FLAG_ALLOW_PLUS (1U << 3) +#define DUK_S2N_FLAG_ALLOW_PLUS (1U << 3) /* Allow leading minus sign */ -#define DUK_S2N_FLAG_ALLOW_MINUS (1U << 4) +#define DUK_S2N_FLAG_ALLOW_MINUS (1U << 4) /* Allow 'Infinity' */ -#define DUK_S2N_FLAG_ALLOW_INF (1U << 5) +#define DUK_S2N_FLAG_ALLOW_INF (1U << 5) /* Allow fraction part */ -#define DUK_S2N_FLAG_ALLOW_FRAC (1U << 6) +#define DUK_S2N_FLAG_ALLOW_FRAC (1U << 6) /* Allow naked fraction (e.g. ".123") */ -#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1U << 7) +#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1U << 7) /* Allow empty fraction (e.g. "123.") */ -#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1U << 8) +#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1U << 8) /* Allow empty string to be interpreted as 0 */ -#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1U << 9) +#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1U << 9) /* Allow leading zeroes (e.g. "0123" -> "123") */ -#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1U << 10) +#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1U << 10) /* Allow automatic detection of hex base ("0x" or "0X" prefix), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1U << 11) +#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1U << 11) /* Allow automatic detection of legacy octal base ("0n"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_LEGACY_OCT_INT (1U << 12) +#define DUK_S2N_FLAG_ALLOW_AUTO_LEGACY_OCT_INT (1U << 12) /* Allow automatic detection of ES2015 octal base ("0o123"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1U << 13) +#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1U << 13) /* Allow automatic detection of ES2015 binary base ("0b10001"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT (1U << 14) +#define DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT (1U << 14) /* * Prototypes */ -DUK_INTERNAL_DECL void duk_numconv_stringify(duk_hthread *thr, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_numconv_stringify(duk_hthread *thr, + duk_small_int_t radix, + duk_small_int_t digits, + duk_small_uint_t flags); DUK_INTERNAL_DECL void duk_numconv_parse(duk_hthread *thr, duk_small_int_t radix, duk_small_uint_t flags); -#endif /* DUK_NUMCONV_H_INCLUDED */ +#endif /* DUK_NUMCONV_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_refcount.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_refcount.h
Changed
@@ -17,19 +17,20 @@ /* XXX: double evaluation for 'tv' argument. */ #define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) \ (DUK_TVAL_IS_HEAP_ALLOCATED((tv)) && !DUK_HEAPHDR_HAS_READONLY(DUK_TVAL_GET_HEAPHDR((tv)))) -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) (!DUK_HEAPHDR_HAS_READONLY((h))) -#else /* DUK_USE_ROM_OBJECTS */ +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) (!DUK_HEAPHDR_HAS_READONLY((h))) +#else /* DUK_USE_ROM_OBJECTS */ /* Without ROM objects "needs refcount update" == is heap allocated. */ -#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) DUK_TVAL_IS_HEAP_ALLOCATED((tv)) -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 1 -#endif /* DUK_USE_ROM_OBJECTS */ +#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) DUK_TVAL_IS_HEAP_ALLOCATED((tv)) +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 1 +#endif /* DUK_USE_ROM_OBJECTS */ /* Fast variants, inline refcount operations except for refzero handling. * Can be used explicitly when speed is always more important than size. * For a good compiler and a single file build, these are basically the * same as a forced inline. */ -#define DUK_TVAL_INCREF_FAST(thr,tv) do { \ +#define DUK_TVAL_INCREF_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -37,10 +38,11 @@ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ DUK_HEAPHDR_PREINC_REFCOUNT(duk__h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ } \ } while (0) -#define DUK_TVAL_DECREF_FAST(thr,tv) do { \ +#define DUK_TVAL_DECREF_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -53,7 +55,8 @@ } \ } \ } while (0) -#define DUK_TVAL_DECREF_NORZ_FAST(thr,tv) do { \ +#define DUK_TVAL_DECREF_NORZ_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -66,16 +69,18 @@ } \ } \ } while (0) -#define DUK_HEAPHDR_INCREF_FAST(thr,h) do { \ +#define DUK_HEAPHDR_INCREF_FAST(thr, h) \ + do { \ duk_heaphdr *duk__h = (duk_heaphdr *) (h); \ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ if (DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(duk__h)) { \ DUK_HEAPHDR_PREINC_REFCOUNT(duk__h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_FAST_RAW(thr,h,rzcall,rzcast) do { \ +#define DUK_HEAPHDR_DECREF_FAST_RAW(thr, h, rzcall, rzcast) \ + do { \ duk_heaphdr *duk__h = (duk_heaphdr *) (h); \ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ @@ -86,29 +91,72 @@ } \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_FAST(thr,h) \ - DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero,duk_heaphdr *) -#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr,h) \ - DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero_norz,duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_FAST(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero, duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero_norz, duk_heaphdr *) /* Slow variants, call to a helper to reduce code size. * Can be used explicitly when size is always more important than speed. */ -#define DUK_TVAL_INCREF_SLOW(thr,tv) do { duk_tval_incref((tv)); } while (0) -#define DUK_TVAL_DECREF_SLOW(thr,tv) do { duk_tval_decref((thr), (tv)); } while (0) -#define DUK_TVAL_DECREF_NORZ_SLOW(thr,tv) do { duk_tval_decref_norz((thr), (tv)); } while (0) -#define DUK_HEAPHDR_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HEAPHDR_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) +#define DUK_TVAL_INCREF_SLOW(thr, tv) \ + do { \ + duk_tval_incref((tv)); \ + } while (0) +#define DUK_TVAL_DECREF_SLOW(thr, tv) \ + do { \ + duk_tval_decref((thr), (tv)); \ + } while (0) +#define DUK_TVAL_DECREF_NORZ_SLOW(thr, tv) \ + do { \ + duk_tval_decref_norz((thr), (tv)); \ + } while (0) +#define DUK_HEAPHDR_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HEAPHDR_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) /* Default variants. Selection depends on speed/size preference. * Concretely: with gcc 4.8.1 -Os x64 the difference in final binary @@ -118,122 +166,136 @@ /* XXX: It would be nice to specialize for specific duk_hobject subtypes * but current refzero queue handling prevents that. */ -#define DUK_TVAL_INCREF(thr,tv) DUK_TVAL_INCREF_FAST((thr),(tv)) -#define DUK_TVAL_DECREF(thr,tv) DUK_TVAL_DECREF_FAST((thr),(tv)) -#define DUK_TVAL_DECREF_NORZ(thr,tv) DUK_TVAL_DECREF_NORZ_FAST((thr),(tv)) -#define DUK_HEAPHDR_INCREF(thr,h) DUK_HEAPHDR_INCREF_FAST((thr),(h)) -#define DUK_HEAPHDR_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero,duk_heaphdr *) -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero_norz,duk_heaphdr *) -#define DUK_HSTRING_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HSTRING_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hstring_refzero,duk_hstring *) -#define DUK_HSTRING_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hstring_refzero,duk_hstring *) /* no 'norz' variant */ -#define DUK_HOBJECT_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HOBJECT_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HOBJECT_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HBUFFER_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HBUFFER_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hbuffer_refzero,duk_hbuffer *) -#define DUK_HBUFFER_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hbuffer_refzero,duk_hbuffer *) /* no 'norz' variant */ -#define DUK_HCOMPFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HNATFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HNATFUNC_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HBUFOBJ_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HBUFOBJ_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HBUFOBJ_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HTHREAD_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HTHREAD_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HTHREAD_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) +#define DUK_TVAL_INCREF(thr, tv) DUK_TVAL_INCREF_FAST((thr), (tv)) +#define DUK_TVAL_DECREF(thr, tv) DUK_TVAL_DECREF_FAST((thr), (tv)) +#define DUK_TVAL_DECREF_NORZ(thr, tv) DUK_TVAL_DECREF_NORZ_FAST((thr), (tv)) +#define DUK_HEAPHDR_INCREF(thr, h) DUK_HEAPHDR_INCREF_FAST((thr), (h)) +#define DUK_HEAPHDR_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero, duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero_norz, duk_heaphdr *) +#define DUK_HSTRING_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HSTRING_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hstring_refzero, duk_hstring *) +#define DUK_HSTRING_DECREF_NORZ(thr, h) \ + DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hstring_refzero, duk_hstring *) /* no 'norz' variant */ +#define DUK_HOBJECT_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HOBJECT_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HOBJECT_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HBUFFER_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HBUFFER_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hbuffer_refzero, duk_hbuffer *) +#define DUK_HBUFFER_DECREF_NORZ(thr, h) \ + DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hbuffer_refzero, duk_hbuffer *) /* no 'norz' variant */ +#define DUK_HCOMPFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HNATFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HNATFUNC_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HBUFOBJ_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HBUFOBJ_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HBUFOBJ_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HTHREAD_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HTHREAD_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HTHREAD_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) #else -#define DUK_TVAL_INCREF(thr,tv) DUK_TVAL_INCREF_SLOW((thr),(tv)) -#define DUK_TVAL_DECREF(thr,tv) DUK_TVAL_DECREF_SLOW((thr),(tv)) -#define DUK_TVAL_DECREF_NORZ(thr,tv) DUK_TVAL_DECREF_NORZ_SLOW((thr),(tv)) -#define DUK_HEAPHDR_INCREF(thr,h) DUK_HEAPHDR_INCREF_SLOW((thr),(h)) -#define DUK_HEAPHDR_DECREF(thr,h) DUK_HEAPHDR_DECREF_SLOW((thr),(h)) -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HSTRING_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HSTRING_DECREF(thr,h) DUK_HSTRING_DECREF_SLOW((thr),(h)) -#define DUK_HSTRING_DECREF_NORZ(thr,h) DUK_HSTRING_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HOBJECT_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HOBJECT_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(h)) -#define DUK_HOBJECT_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HBUFFER_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HBUFFER_DECREF(thr,h) DUK_HBUFFER_DECREF_SLOW((thr),(h)) -#define DUK_HBUFFER_DECREF_NORZ(thr,h) DUK_HBUFFER_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HCOMPFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HNATFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HNATFUNC_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HBUFOBJ_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HBUFOBJ_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HBUFOB_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HTHREAD_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HTHREAD_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HTHREAD_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) +#define DUK_TVAL_INCREF(thr, tv) DUK_TVAL_INCREF_SLOW((thr), (tv)) +#define DUK_TVAL_DECREF(thr, tv) DUK_TVAL_DECREF_SLOW((thr), (tv)) +#define DUK_TVAL_DECREF_NORZ(thr, tv) DUK_TVAL_DECREF_NORZ_SLOW((thr), (tv)) +#define DUK_HEAPHDR_INCREF(thr, h) DUK_HEAPHDR_INCREF_SLOW((thr), (h)) +#define DUK_HEAPHDR_DECREF(thr, h) DUK_HEAPHDR_DECREF_SLOW((thr), (h)) +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HSTRING_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HSTRING_DECREF(thr, h) DUK_HSTRING_DECREF_SLOW((thr), (h)) +#define DUK_HSTRING_DECREF_NORZ(thr, h) DUK_HSTRING_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HOBJECT_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HOBJECT_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (h)) +#define DUK_HOBJECT_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HBUFFER_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HBUFFER_DECREF(thr, h) DUK_HBUFFER_DECREF_SLOW((thr), (h)) +#define DUK_HBUFFER_DECREF_NORZ(thr, h) DUK_HBUFFER_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HCOMPFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HNATFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HNATFUNC_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HBUFOBJ_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HBUFOBJ_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HBUFOB_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HTHREAD_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HTHREAD_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HTHREAD_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) #endif /* Convenience for some situations; the above macros don't allow NULLs * for performance reasons. Macros cover only actually needed cases. */ -#define DUK_HEAPHDR_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_DECREF((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_DECREF_NORZ((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HOBJECT_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HOBJECT_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_DECREF_NORZ((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_DECREF_NORZ((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_DECREF_NORZ((thr), (h)); \ } \ @@ -245,16 +307,22 @@ * variant is performance critical. */ #if defined(DUK_USE_FINALIZER_SUPPORT) -#define DUK_REFZERO_CHECK_FAST(thr) do { \ +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ duk_refzero_check_fast((thr)); \ } while (0) -#define DUK_REFZERO_CHECK_SLOW(thr) do { \ +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ duk_refzero_check_slow((thr)); \ } while (0) -#else /* DUK_USE_FINALIZER_SUPPORT */ -#define DUK_REFZERO_CHECK_FAST(thr) do { } while (0) -#define DUK_REFZERO_CHECK_SLOW(thr) do { } while (0) -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ + } while (0) +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ + } while (0) +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Macros to set a duk_tval and update refcount of the target (decref the @@ -262,125 +330,176 @@ * and footprint critical; any changes made should be measured for size/speed. */ -#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ DUK_TVAL_DECREF_NORZ((thr), &tv__tmp); \ } while (0) -#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNUSED(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NULL(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_BOOLEAN(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NUMBER(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_DOUBLE(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NAN(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_I48(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_I32(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_U32(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) #else -#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr,tvptr_dst,newval) \ +#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr, tvptr_dst, newval) \ DUK_TVAL_SET_DOUBLE_UPDREF((thr), (tvptr_dst), (duk_double_t) (newval)) -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr,tvptr_dst,lf_v,lf_fp,lf_flags) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr, tvptr_dst, lf_v, lf_fp, lf_flags) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_LIGHTFUNC(tv__dst, (lf_v), (lf_fp), (lf_flags)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_STRING(tv__dst, (newval)); \ DUK_HSTRING_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_OBJECT(tv__dst, (newval)); \ DUK_HOBJECT_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_BUFFER(tv__dst, (newval)); \ DUK_HBUFFER_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_POINTER(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) /* DUK_TVAL_SET_TVAL_UPDREF() is used a lot in executor, property lookups, @@ -391,281 +510,452 @@ */ /* Original idiom used, minimal code size. */ -#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr,tvptr_dst,tvptr_src) do { \ - duk_tval *tv__dst, *tv__src; duk_tval tv__tmp; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr, tvptr_dst, tvptr_src) \ + do { \ + duk_tval *tv__dst, *tv__src; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ DUK_TVAL_INCREF((thr), tv__src); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) /* Faster alternative: avoid making a temporary copy of tvptr_dst and use * fast incref/decref macros. */ -#define DUK_TVAL_SET_TVAL_UPDREF_ALT1(thr,tvptr_dst,tvptr_src) do { \ - duk_tval *tv__dst, *tv__src; duk_heaphdr *h__obj; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT1(thr, tvptr_dst, tvptr_src) \ + do { \ + duk_tval *tv__dst, *tv__src; \ + duk_heaphdr *h__obj; \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_INCREF_FAST((thr), tv__src); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv__dst)) { \ h__obj = DUK_TVAL_GET_HEAPHDR(tv__dst); \ DUK_ASSERT(h__obj != NULL); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ - DUK_HEAPHDR_DECREF_FAST((thr), h__obj); /* side effects */ \ + DUK_HEAPHDR_DECREF_FAST((thr), h__obj); /* side effects */ \ } else { \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ } \ } while (0) /* XXX: no optimized variants yet */ -#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0 -#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 -#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 -#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 -#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 -#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0 +#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 +#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 +#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 +#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 +#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 #else -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 -#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 -#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 -#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 -#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 +#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 +#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 +#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 +#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 #if defined(DUK_USE_FAST_REFCOUNT_DEFAULT) /* Optimized for speed. */ -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT1 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT1 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT1 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT1 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 #else /* Optimized for size. */ -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 #endif -#else /* DUK_USE_REFERENCE_COUNTING */ - -#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) 0 -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 0 - -#define DUK_TVAL_INCREF_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_INCREF_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_INCREF(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ(thr,v) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ(thr,h) do {} while (0) /* nop */ - -#define DUK_HCOMPFUNC_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HCOMPFUNC_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr,h) do {} while (0) /* nop */ - -#define DUK_REFZERO_CHECK_FAST(thr) do {} while (0) /* nop */ -#define DUK_REFZERO_CHECK_SLOW(thr) do {} while (0) /* nop */ - -#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#else /* DUK_USE_REFERENCE_COUNTING */ + +#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) 0 +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 0 + +#define DUK_TVAL_INCREF_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_INCREF_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_INCREF(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ + +#define DUK_HCOMPFUNC_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HCOMPFUNC_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ + +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ + } while (0) /* nop */ +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ + } while (0) /* nop */ + +#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_UNUSED(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NULL(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_BOOLEAN(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NUMBER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_DOUBLE(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NAN(tv__dst); \ DUK_UNREF((thr)); \ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_I48(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_I32(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_U32(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) #else -#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr,tvptr_dst,newval) \ +#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr, tvptr_dst, newval) \ DUK_TVAL_SET_DOUBLE_UPDREF((thr), (tvptr_dst), (duk_double_t) (newval)) -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr,tvptr_dst,lf_v,lf_fp,lf_flags) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr, tvptr_dst, lf_v, lf_fp, lf_flags) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_LIGHTFUNC(tv__dst, (lf_v), (lf_fp), (lf_flags)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_STRING(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_OBJECT(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_BUFFER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_POINTER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr,tvptr_dst,tvptr_src) do { \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr, tvptr_dst, tvptr_src) \ + do { \ duk_tval *tv__dst, *tv__src; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 -#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 -#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 -#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 -#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 +#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 +#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 +#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 +#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 #else -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast-int-to-double */ -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 -#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 -#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 -#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 -#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 - -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 - -#endif /* DUK_USE_REFERENCE_COUNTING */ +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast-int-to-double */ +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 +#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 +#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 +#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 +#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 + +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 + +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Some convenience macros that don't have optimized implementations now. */ -#define DUK_TVAL_SET_TVAL_UPDREF_NORZ(thr,tv_dst,tv_src) do { \ +#define DUK_TVAL_SET_TVAL_UPDREF_NORZ(thr, tv_dst, tv_src) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_tval *duk__dst = (tv_dst); \ duk_tval *duk__src = (tv_src); \ @@ -675,7 +965,8 @@ DUK_TVAL_INCREF(thr, duk__dst); \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_NORZ(thr,tv_dst,val) do { \ +#define DUK_TVAL_SET_U32_UPDREF_NORZ(thr, tv_dst, val) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_tval *duk__dst = (tv_dst); \ duk_uint32_t duk__val = (duk_uint32_t) (val); \ @@ -695,7 +986,7 @@ #endif DUK_INTERNAL_DECL void duk_heaphdr_refcount_finalize_norz(duk_heap *heap, duk_heaphdr *hdr); DUK_INTERNAL_DECL void duk_hobject_refcount_finalize_norz(duk_heap *heap, duk_hobject *h); -#if 0 /* Not needed: fast path handles inline; slow path uses duk_heaphdr_decref() which is needed anyway. */ +#if 0 /* Not needed: fast path handles inline; slow path uses duk_heaphdr_decref() which is needed anyway. */ DUK_INTERNAL_DECL void duk_hstring_decref(duk_hthread *thr, duk_hstring *h); DUK_INTERNAL_DECL void duk_hstring_decref_norz(duk_hthread *thr, duk_hstring *h); DUK_INTERNAL_DECL void duk_hbuffer_decref(duk_hthread *thr, duk_hbuffer *h); @@ -706,8 +997,8 @@ DUK_INTERNAL_DECL void duk_heaphdr_refzero(duk_hthread *thr, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_refzero_norz(duk_hthread *thr, duk_heaphdr *h); #if defined(DUK_USE_FAST_REFCOUNT_DEFAULT) -DUK_INTERNAL_DECL void duk_hstring_refzero(duk_hthread *thr, duk_hstring *h); /* no 'norz' variant */ -DUK_INTERNAL_DECL void duk_hbuffer_refzero(duk_hthread *thr, duk_hbuffer *h); /* no 'norz' variant */ +DUK_INTERNAL_DECL void duk_hstring_refzero(duk_hthread *thr, duk_hstring *h); /* no 'norz' variant */ +DUK_INTERNAL_DECL void duk_hbuffer_refzero(duk_hthread *thr, duk_hbuffer *h); /* no 'norz' variant */ DUK_INTERNAL_DECL void duk_hobject_refzero(duk_hthread *thr, duk_hobject *h); DUK_INTERNAL_DECL void duk_hobject_refzero_norz(duk_hthread *thr, duk_hobject *h); #else @@ -718,8 +1009,8 @@ DUK_INTERNAL_DECL void duk_heaphdr_decref(duk_hthread *thr, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_decref_norz(duk_hthread *thr, duk_heaphdr *h); #endif -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ /* no refcounting */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ -#endif /* DUK_REFCOUNT_H_INCLUDED */ +#endif /* DUK_REFCOUNT_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_regexp.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_regexp.h
Changed
@@ -6,39 +6,39 @@ #define DUK_REGEXP_H_INCLUDED /* maximum bytecode copies for {n,m} quantifiers */ -#define DUK_RE_MAX_ATOM_COPIES 1000 +#define DUK_RE_MAX_ATOM_COPIES 1000 /* regexp compilation limits */ -#define DUK_RE_COMPILE_TOKEN_LIMIT 100000000L /* 1e8 */ +#define DUK_RE_COMPILE_TOKEN_LIMIT 100000000L /* 1e8 */ /* regexp execution limits */ -#define DUK_RE_EXECUTE_STEPS_LIMIT 1000000000L /* 1e9 */ +#define DUK_RE_EXECUTE_STEPS_LIMIT 1000000000L /* 1e9 */ /* regexp opcodes */ -#define DUK_REOP_MATCH 1 -#define DUK_REOP_CHAR 2 -#define DUK_REOP_PERIOD 3 -#define DUK_REOP_RANGES 4 -#define DUK_REOP_INVRANGES 5 -#define DUK_REOP_JUMP 6 -#define DUK_REOP_SPLIT1 7 -#define DUK_REOP_SPLIT2 8 -#define DUK_REOP_SQMINIMAL 9 -#define DUK_REOP_SQGREEDY 10 -#define DUK_REOP_SAVE 11 -#define DUK_REOP_WIPERANGE 12 -#define DUK_REOP_LOOKPOS 13 -#define DUK_REOP_LOOKNEG 14 -#define DUK_REOP_BACKREFERENCE 15 -#define DUK_REOP_ASSERT_START 16 -#define DUK_REOP_ASSERT_END 17 -#define DUK_REOP_ASSERT_WORD_BOUNDARY 18 -#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY 19 +#define DUK_REOP_MATCH 1 +#define DUK_REOP_CHAR 2 +#define DUK_REOP_PERIOD 3 +#define DUK_REOP_RANGES 4 +#define DUK_REOP_INVRANGES 5 +#define DUK_REOP_JUMP 6 +#define DUK_REOP_SPLIT1 7 +#define DUK_REOP_SPLIT2 8 +#define DUK_REOP_SQMINIMAL 9 +#define DUK_REOP_SQGREEDY 10 +#define DUK_REOP_SAVE 11 +#define DUK_REOP_WIPERANGE 12 +#define DUK_REOP_LOOKPOS 13 +#define DUK_REOP_LOOKNEG 14 +#define DUK_REOP_BACKREFERENCE 15 +#define DUK_REOP_ASSERT_START 16 +#define DUK_REOP_ASSERT_END 17 +#define DUK_REOP_ASSERT_WORD_BOUNDARY 18 +#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY 19 /* flags */ -#define DUK_RE_FLAG_GLOBAL (1U << 0) -#define DUK_RE_FLAG_IGNORE_CASE (1U << 1) -#define DUK_RE_FLAG_MULTILINE (1U << 2) +#define DUK_RE_FLAG_GLOBAL (1U << 0) +#define DUK_RE_FLAG_IGNORE_CASE (1U << 1) +#define DUK_RE_FLAG_MULTILINE (1U << 2) struct duk_re_matcher_ctx { duk_hthread *thr; @@ -48,7 +48,7 @@ const duk_uint8_t *input_end; const duk_uint8_t *bytecode; const duk_uint8_t *bytecode_end; - const duk_uint8_t **saved; /* allocated from valstack (fixed buffer) */ + const duk_uint8_t **saved; /* allocated from valstack (fixed buffer) */ duk_uint32_t nsaved; duk_uint32_t recursion_depth; duk_uint32_t recursion_limit; @@ -63,11 +63,11 @@ duk_lexer_ctx lex; duk_re_token curr_token; duk_bufwriter_ctx bw; - duk_uint32_t captures; /* highest capture number emitted so far (used as: ++captures) */ + duk_uint32_t captures; /* highest capture number emitted so far (used as: ++captures) */ duk_uint32_t highest_backref; duk_uint32_t recursion_depth; duk_uint32_t recursion_limit; - duk_uint32_t nranges; /* internal temporary value, used for char classes */ + duk_uint32_t nranges; /* internal temporary value, used for char classes */ }; /* @@ -78,7 +78,7 @@ DUK_INTERNAL_DECL void duk_regexp_compile(duk_hthread *thr); DUK_INTERNAL_DECL void duk_regexp_create_instance(duk_hthread *thr); DUK_INTERNAL_DECL void duk_regexp_match(duk_hthread *thr); -DUK_INTERNAL_DECL void duk_regexp_match_force_global(duk_hthread *thr); /* hacky helper for String.prototype.split() */ +DUK_INTERNAL_DECL void duk_regexp_match_force_global(duk_hthread *thr); /* hacky helper for String.prototype.split() */ #endif -#endif /* DUK_REGEXP_H_INCLUDED */ +#endif /* DUK_REGEXP_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_regexp_compiler.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_regexp_compiler.c
Changed
@@ -28,8 +28,7 @@ #define DUK__RE_INITIAL_BUFSIZE 64 -#define DUK__RE_BUFLEN(re_ctx) \ - DUK_BW_GET_SIZE(re_ctx->thr, &re_ctx->bw) +#define DUK__RE_BUFLEN(re_ctx) DUK_BW_GET_SIZE(re_ctx->thr, &re_ctx->bw) /* * Disjunction struct: result of parsing a disjunction @@ -119,7 +118,7 @@ (void) duk__append_7bit(re_ctx, reop); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__append_i32(duk_re_compiler_ctx *re_ctx, duk_int32_t x) { duk__append_u32(re_ctx, duk__encode_i32(x)); } @@ -133,7 +132,10 @@ } } -DUK_LOCAL void duk__insert_slice(duk_re_compiler_ctx *re_ctx, duk_uint32_t offset, duk_uint32_t data_offset, duk_uint32_t data_length) { +DUK_LOCAL void duk__insert_slice(duk_re_compiler_ctx *re_ctx, + duk_uint32_t offset, + duk_uint32_t data_offset, + duk_uint32_t data_length) { DUK_BW_INSERT_ENSURE_SLICE(re_ctx->thr, &re_ctx->bw, offset, data_offset, data_length); } @@ -196,7 +198,7 @@ skip--; } } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* Closed form solution, this produces fastest code. * See re_neg_jump_offset (closed1). */ @@ -217,7 +219,7 @@ skip -= 7; } } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ return duk__insert_i32(re_ctx, offset, skip); } @@ -350,10 +352,10 @@ } } } - DUK_ASSERT(blk == end_blk + 1); /* Reached end block which is continuous. */ + DUK_ASSERT(blk == end_blk + 1); /* Reached end block which is continuous. */ return end; } -#else /* DUK_USE_REGEXP_CANON_BITMAP */ +#else /* DUK_USE_REGEXP_CANON_BITMAP */ DUK_LOCAL duk_codepoint_t duk__re_canon_next_discontinuity(duk_codepoint_t start, duk_codepoint_t end) { DUK_ASSERT(start >= 0); DUK_ASSERT(end >= 0); @@ -364,7 +366,7 @@ } return start; } -#endif /* DUK_USE_REGEXP_CANON_BITMAP */ +#endif /* DUK_USE_REGEXP_CANON_BITMAP */ DUK_LOCAL void duk__regexp_generate_ranges(void *userdata, duk_codepoint_t r1, duk_codepoint_t r2, duk_bool_t direct) { duk_re_compiler_ctx *re_ctx = (duk_re_compiler_ctx *) userdata; @@ -375,9 +377,12 @@ duk_codepoint_t r_disc; DUK_DD(DUK_DDPRINT("duk__regexp_generate_ranges(): re_ctx=%p, range=%ld,%ld direct=%ld", - (void *) re_ctx, (long) r1, (long) r2, (long) direct)); + (void *) re_ctx, + (long) r1, + (long) r2, + (long) direct)); - DUK_ASSERT(r2 >= r1); /* SyntaxError for out of order range. */ + DUK_ASSERT(r2 >= r1); /* SyntaxError for out of order range. */ if (direct || (re_ctx->re_flags & DUK_RE_FLAG_IGNORE_CASE) == 0) { DUK_DD(DUK_DDPRINT("direct or not case sensitive, emit range: %ld,%ld", (long) r1, (long) r2)); @@ -399,7 +404,7 @@ DUK_ASSERT(r_disc >= i); DUK_ASSERT(r_disc <= r2); - r_end += r_disc - i; /* May be zero. */ + r_end += r_disc - i; /* May be zero. */ t = duk_unicode_re_canonicalize_char(re_ctx->thr, r_disc); if (t == r_end + 1) { /* Not actually a discontinuity, continue range @@ -411,11 +416,11 @@ r_start = t; r_end = t; } - i = r_disc + 1; /* Guarantees progress. */ + i = r_disc + 1; /* Guarantees progress. */ } duk__regexp_emit_range(re_ctx, r_start, r_end); -#if 0 /* Exhaustive search, very slow. */ +#if 0 /* Exhaustive search, very slow. */ r_start = duk_unicode_re_canonicalize_char(re_ctx->thr, r1); r_end = r_start; for (i = r1 + 1; i <= r2; i++) { @@ -488,18 +493,17 @@ * as complex though. */ -DUK_LOCAL const duk_uint16_t * const duk__re_range_lookup13 = { - duk_unicode_re_ranges_digit, - duk_unicode_re_ranges_white, - duk_unicode_re_ranges_wordchar -}; -DUK_LOCAL const duk_uint8_t duk__re_range_lookup23 = { - sizeof(duk_unicode_re_ranges_digit) / (2 * sizeof(duk_uint16_t)), - sizeof(duk_unicode_re_ranges_white) / (2 * sizeof(duk_uint16_t)), - sizeof(duk_unicode_re_ranges_wordchar) / (2 * sizeof(duk_uint16_t)) -}; - -DUK_LOCAL void duk__append_range_atom_matcher(duk_re_compiler_ctx *re_ctx, duk_small_uint_t re_op, const duk_uint16_t *ranges, duk_small_uint_t count) { +DUK_LOCAL const duk_uint16_t * const duk__re_range_lookup13 = { duk_unicode_re_ranges_digit, + duk_unicode_re_ranges_white, + duk_unicode_re_ranges_wordchar }; +DUK_LOCAL const duk_uint8_t duk__re_range_lookup23 = { sizeof(duk_unicode_re_ranges_digit) / (2 * sizeof(duk_uint16_t)), + sizeof(duk_unicode_re_ranges_white) / (2 * sizeof(duk_uint16_t)), + sizeof(duk_unicode_re_ranges_wordchar) / (2 * sizeof(duk_uint16_t)) }; + +DUK_LOCAL void duk__append_range_atom_matcher(duk_re_compiler_ctx *re_ctx, + duk_small_uint_t re_op, + const duk_uint16_t *ranges, + duk_small_uint_t count) { #if 0 DUK_ASSERT(re_op <= 0x7fUL); DUK_ASSERT(count <= 0x7fUL); @@ -511,13 +515,13 @@ } DUK_LOCAL void duk__parse_disjunction(duk_re_compiler_ctx *re_ctx, duk_bool_t expect_eof, duk__re_disjunction_info *out_atom_info) { - duk_int32_t atom_start_offset = -1; /* negative -> no atom matched on previous round */ - duk_int32_t atom_char_length = 0; /* negative -> complex atom */ - duk_uint32_t atom_start_captures = re_ctx->captures; /* value of re_ctx->captures at start of atom */ + duk_int32_t atom_start_offset = -1; /* negative -> no atom matched on previous round */ + duk_int32_t atom_char_length = 0; /* negative -> complex atom */ + duk_uint32_t atom_start_captures = re_ctx->captures; /* value of re_ctx->captures at start of atom */ duk_int32_t unpatched_disjunction_split = -1; duk_int32_t unpatched_disjunction_jump = -1; duk_uint32_t entry_offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); - duk_int32_t res_charlen = 0; /* -1 if disjunction is complex, char length if simple */ + duk_int32_t res_charlen = 0; /* -1 if disjunction is complex, char length if simple */ duk__re_disjunction_info tmp_disj; DUK_ASSERT(out_atom_info != NULL); @@ -540,19 +544,19 @@ * new_atom_char_length etc are for the atom parsed on this round; * they're written to atom_char_length etc at the end of the round. */ - duk_int32_t new_atom_char_length; /* char length of the atom parsed in this loop */ - duk_int32_t new_atom_start_offset; /* bytecode start offset of the atom parsed in this loop - * (allows quantifiers to copy the atom bytecode) - */ - duk_uint32_t new_atom_start_captures; /* re_ctx->captures at the start of the atom parsed in this loop */ + duk_int32_t new_atom_char_length; /* char length of the atom parsed in this loop */ + duk_int32_t new_atom_start_offset; /* bytecode start offset of the atom parsed in this loop + * (allows quantifiers to copy the atom bytecode) + */ + duk_uint32_t new_atom_start_captures; /* re_ctx->captures at the start of the atom parsed in this loop */ duk_lexer_parse_re_token(&re_ctx->lex, &re_ctx->curr_token); - DUK_DD(DUK_DDPRINT("re token: %ld (num=%ld, char=%c)", - (long) re_ctx->curr_token.t, - (long) re_ctx->curr_token.num, - (re_ctx->curr_token.num >= 0x20 && re_ctx->curr_token.num <= 0x7e) ? - (int) re_ctx->curr_token.num : (int) '?')); + DUK_DD(DUK_DDPRINT( + "re token: %ld (num=%ld, char=%c)", + (long) re_ctx->curr_token.t, + (long) re_ctx->curr_token.num, + (re_ctx->curr_token.num >= 0x20 && re_ctx->curr_token.num <= 0x7e) ? (int) re_ctx->curr_token.num : (int) '?')); /* set by atom case clauses */ new_atom_start_offset = -1; @@ -573,9 +577,7 @@ DUK_ASSERT(unpatched_disjunction_split >= 0); offset = (duk_uint32_t) unpatched_disjunction_jump; - offset += duk__insert_jump_offset(re_ctx, - offset, - (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); + offset += duk__insert_jump_offset(re_ctx, offset, (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); /* offset is now target of the pending split (right after jump) */ duk__insert_jump_offset(re_ctx, (duk_uint32_t) unpatched_disjunction_split, @@ -583,10 +585,8 @@ } /* add a new pending split to the beginning of the entire disjunction */ - (void) duk__insert_u32(re_ctx, - entry_offset, - DUK_REOP_SPLIT1); /* prefer direct execution */ - unpatched_disjunction_split = (duk_int32_t) (entry_offset + 1); /* +1 for opcode */ + (void) duk__insert_u32(re_ctx, entry_offset, DUK_REOP_SPLIT1); /* prefer direct execution */ + unpatched_disjunction_split = (duk_int32_t) (entry_offset + 1); /* +1 for opcode */ /* add a new pending match jump for latest finished alternative */ duk__append_reop(re_ctx, DUK_REOP_JUMP); @@ -634,7 +634,7 @@ } } - duk__append_reop(re_ctx, DUK_REOP_MATCH); /* complete 'sub atom' */ + duk__append_reop(re_ctx, DUK_REOP_MATCH); /* complete 'sub atom' */ atom_code_length = (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (duk_size_t) atom_start_offset); offset = (duk_uint32_t) atom_start_offset; @@ -650,7 +650,7 @@ offset += duk__insert_u32(re_ctx, offset, qmax); offset += duk__insert_jump_offset(re_ctx, offset, atom_code_length); } - DUK_UNREF(offset); /* silence scan-build warning */ + DUK_UNREF(offset); /* silence scan-build warning */ } else { /* * Complex atom @@ -668,8 +668,8 @@ duk_uint32_t tmp_qmin, tmp_qmax; /* pre-check how many atom copies we're willing to make (atom_copies not needed below) */ - atom_copies = (re_ctx->curr_token.qmax == DUK_RE_QUANTIFIER_INFINITE) ? - re_ctx->curr_token.qmin : re_ctx->curr_token.qmax; + atom_copies = (re_ctx->curr_token.qmax == DUK_RE_QUANTIFIER_INFINITE) ? re_ctx->curr_token.qmin : + re_ctx->curr_token.qmax; if (atom_copies > DUK_RE_MAX_ATOM_COPIES) { DUK_ERROR_RANGE(re_ctx->thr, DUK_STR_QUANTIFIER_TOO_MANY_COPIES); DUK_WO_NORETURN(return;); @@ -680,15 +680,19 @@ if (atom_start_captures != re_ctx->captures) { DUK_ASSERT(atom_start_captures < re_ctx->captures); DUK_DDD(DUK_DDDPRINT("must wipe atom_start_captures,re_ctx->captures: %ld,%ld", - (long) atom_start_captures, (long) re_ctx->captures)); + (long) atom_start_captures, + (long) re_ctx->captures)); /* insert (DUK_REOP_WIPERANGE, start, count) in reverse order so the order ends up right */ - duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, (re_ctx->captures - atom_start_captures) * 2U); + duk__insert_u32(re_ctx, + (duk_uint32_t) atom_start_offset, + (re_ctx->captures - atom_start_captures) * 2U); duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, (atom_start_captures + 1) * 2); duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, DUK_REOP_WIPERANGE); } else { - DUK_DDD(DUK_DDDPRINT("no need to wipe captures: atom_start_captures == re_ctx->captures == %ld", - (long) atom_start_captures)); + DUK_DDD( + DUK_DDDPRINT("no need to wipe captures: atom_start_captures == re_ctx->captures == %ld", + (long) atom_start_captures)); } atom_code_length = (duk_int32_t) DUK__RE_BUFLEN(re_ctx) - atom_start_offset; @@ -697,7 +701,9 @@ tmp_qmin = re_ctx->curr_token.qmin; tmp_qmax = re_ctx->curr_token.qmax; while (tmp_qmin > 0) { - duk__append_slice(re_ctx, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__append_slice(re_ctx, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); tmp_qmin--; if (tmp_qmax != DUK_RE_QUANTIFIER_INFINITE) { tmp_qmax--; @@ -715,14 +721,16 @@ */ duk__append_reop(re_ctx, DUK_REOP_JUMP); duk__append_jump_offset(re_ctx, atom_code_length); - duk__append_slice(re_ctx, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__append_slice(re_ctx, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); } if (re_ctx->curr_token.greedy) { - duk__append_reop(re_ctx, DUK_REOP_SPLIT2); /* prefer jump */ + duk__append_reop(re_ctx, DUK_REOP_SPLIT2); /* prefer jump */ } else { - duk__append_reop(re_ctx, DUK_REOP_SPLIT1); /* prefer direct */ + duk__append_reop(re_ctx, DUK_REOP_SPLIT1); /* prefer direct */ } - duk__append_jump_offset(re_ctx, -atom_code_length - 1); /* -1 for opcode */ + duk__append_jump_offset(re_ctx, -atom_code_length - 1); /* -1 for opcode */ } else { /* * The remaining matches are emitted as sequence of SPLITs and atom @@ -742,14 +750,17 @@ */ duk_uint32_t offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); while (tmp_qmax > 0) { - duk__insert_slice(re_ctx, offset, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__insert_slice(re_ctx, + offset, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); if (re_ctx->curr_token.greedy) { - duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT1); /* prefer direct */ + duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT1); /* prefer direct */ } else { - duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT2); /* prefer jump */ + duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT2); /* prefer jump */ } duk__insert_jump_offset(re_ctx, - offset + 1, /* +1 for opcode */ + offset + 1, /* +1 for opcode */ (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (offset + 1))); tmp_qmax--; } @@ -782,8 +793,8 @@ case DUK_RETOK_ASSERT_START_POS_LOOKAHEAD: case DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD: { duk_uint32_t offset; - duk_uint32_t opcode = (re_ctx->curr_token.t == DUK_RETOK_ASSERT_START_POS_LOOKAHEAD) ? - DUK_REOP_LOOKPOS : DUK_REOP_LOOKNEG; + duk_uint32_t opcode = + (re_ctx->curr_token.t == DUK_RETOK_ASSERT_START_POS_LOOKAHEAD) ? DUK_REOP_LOOKPOS : DUK_REOP_LOOKNEG; offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); duk__parse_disjunction(re_ctx, 0, &tmp_disj); @@ -791,7 +802,7 @@ (void) duk__insert_u32(re_ctx, offset, opcode); (void) duk__insert_jump_offset(re_ctx, - offset + 1, /* +1 for opcode */ + offset + 1, /* +1 for opcode */ (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (offset + 1))); /* 'taint' result as complex -- this is conservative, @@ -852,7 +863,7 @@ DUK_ASSERT(DUK_RETOK_ATOM_WHITE == DUK_RETOK_ATOM_DIGIT + 2); DUK_ASSERT(DUK_RETOK_ATOM_WORD_CHAR == DUK_RETOK_ATOM_DIGIT + 4); idx = (duk_small_uint_t) ((re_ctx->curr_token.t - DUK_RETOK_ATOM_DIGIT) >> 1U); - DUK_ASSERT(idx <= 2U); /* Assume continuous token numbers; also checks negative underflow. */ + DUK_ASSERT(idx <= 2U); /* Assume continuous token numbers; also checks negative underflow. */ duk__append_range_atom_matcher(re_ctx, re_op, duk__re_range_lookup1idx, duk__re_range_lookup2idx); break; @@ -862,7 +873,7 @@ if (backref > re_ctx->highest_backref) { re_ctx->highest_backref = backref; } - new_atom_char_length = -1; /* mark as complex */ + new_atom_char_length = -1; /* mark as complex */ new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); duk__append_reop(re_ctx, DUK_REOP_BACKREFERENCE); duk__append_u32(re_ctx, backref); @@ -871,12 +882,14 @@ case DUK_RETOK_ATOM_START_CAPTURE_GROUP: { duk_uint32_t cap; - new_atom_char_length = -1; /* mark as complex (capture handling) */ + new_atom_char_length = -1; /* mark as complex (capture handling) */ new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); cap = ++re_ctx->captures; duk__append_reop(re_ctx, DUK_REOP_SAVE); duk__append_u32(re_ctx, cap * 2); - duk__parse_disjunction(re_ctx, 0, &tmp_disj); /* retval (sub-atom char length) unused, tainted as complex above */ + duk__parse_disjunction(re_ctx, + 0, + &tmp_disj); /* retval (sub-atom char length) unused, tainted as complex above */ duk__append_reop(re_ctx, DUK_REOP_SAVE); duk__append_u32(re_ctx, cap * 2 + 1); break; @@ -921,12 +934,12 @@ new_atom_char_length = 1; new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); duk__append_reop(re_ctx, - (re_ctx->curr_token.t == DUK_RETOK_ATOM_START_CHARCLASS) ? - DUK_REOP_RANGES : DUK_REOP_INVRANGES); - offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); /* patch in range count later */ + (re_ctx->curr_token.t == DUK_RETOK_ATOM_START_CHARCLASS) ? DUK_REOP_RANGES : + DUK_REOP_INVRANGES); + offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); /* patch in range count later */ /* parse ranges until character class ends */ - re_ctx->nranges = 0; /* note: ctx-wide temporary */ + re_ctx->nranges = 0; /* note: ctx-wide temporary */ duk_lexer_parse_re_ranges(&re_ctx->lex, duk__regexp_generate_ranges, (void *) re_ctx); /* insert range count */ @@ -969,7 +982,7 @@ atom_start_captures = new_atom_start_captures; } - done: +done: /* finish up pending jump and split for last alternative */ if (unpatched_disjunction_jump >= 0) { @@ -977,9 +990,7 @@ DUK_ASSERT(unpatched_disjunction_split >= 0); offset = (duk_uint32_t) unpatched_disjunction_jump; - offset += duk__insert_jump_offset(re_ctx, - offset, - (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); + offset += duk__insert_jump_offset(re_ctx, offset, (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); /* offset is now target of the pending split (right after jump) */ duk__insert_jump_offset(re_ctx, (duk_uint32_t) unpatched_disjunction_split, @@ -990,8 +1001,7 @@ out_atom_info->end_captures = re_ctx->captures; #endif out_atom_info->charlen = res_charlen; - DUK_DDD(DUK_DDDPRINT("parse disjunction finished: charlen=%ld", - (long) out_atom_info->charlen)); + DUK_DDD(DUK_DDDPRINT("parse disjunction finished: charlen=%ld", (long) out_atom_info->charlen)); re_ctx->recursion_depth--; } @@ -1042,7 +1052,7 @@ return flags; - flags_error: +flags_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_REGEXP_FLAGS); DUK_WO_NORETURN(return 0U;); } @@ -1108,7 +1118,7 @@ } DUK_BW_SETPTR_AND_COMPACT(thr, bw, q); - (void) duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ /* ... escaped_source */ } @@ -1162,7 +1172,7 @@ /* ... pattern flags escaped_source buffer */ duk_memzero(&re_ctx, sizeof(re_ctx)); - DUK_LEXER_INITCTX(&re_ctx.lex); /* duplicate zeroing, expect for (possible) NULL inits */ + DUK_LEXER_INITCTX(&re_ctx.lex); /* duplicate zeroing, expect for (possible) NULL inits */ re_ctx.thr = thr; re_ctx.lex.thr = thr; re_ctx.lex.input = DUK_HSTRING_GET_DATA(h_pattern); @@ -1174,13 +1184,14 @@ DUK_BW_INIT_PUSHBUF(thr, &re_ctx.bw, DUK__RE_INITIAL_BUFSIZE); DUK_DD(DUK_DDPRINT("regexp compiler ctx initialized, flags=0x%08lx, recursion_limit=%ld", - (unsigned long) re_ctx.re_flags, (long) re_ctx.recursion_limit)); + (unsigned long) re_ctx.re_flags, + (long) re_ctx.recursion_limit)); /* * Init lexer */ - lex_point.offset = 0; /* expensive init, just want to fill window */ + lex_point.offset = 0; /* expensive init, just want to fill window */ lex_point.line = 1; DUK_LEXER_SETPOINT(&re_ctx.lex, &lex_point); @@ -1222,7 +1233,7 @@ /* ... pattern flags escaped_source buffer */ DUK_BW_COMPACT(thr, &re_ctx.bw); - (void) duk_buffer_to_string(thr, -1); /* Safe because flags is at most 7 bit. */ + (void) duk_buffer_to_string(thr, -1); /* Safe because flags is at most 7 bit. */ /* ... pattern flags escaped_source bytecode */ @@ -1230,11 +1241,12 @@ * Finalize stack */ - duk_remove(thr, -4); /* -> ... flags escaped_source bytecode */ - duk_remove(thr, -3); /* -> ... escaped_source bytecode */ + duk_remove(thr, -4); /* -> ... flags escaped_source bytecode */ + duk_remove(thr, -3); /* -> ... escaped_source bytecode */ DUK_DD(DUK_DDPRINT("regexp compilation successful, bytecode: %!T, escaped source: %!T", - (duk_tval *) duk_get_tval(thr, -1), (duk_tval *) duk_get_tval(thr, -2))); + (duk_tval *) duk_get_tval(thr, -1), + (duk_tval *) duk_get_tval(thr, -2))); } /* @@ -1280,8 +1292,8 @@ /* ... regexp_object */ } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ /* regexp support disabled */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_regexp_executor.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_regexp_executor.c
Changed
@@ -41,7 +41,11 @@ } } -DUK_LOCAL const duk_uint8_t *duk__utf8_backtrack(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_uint_fast32_t count) { +DUK_LOCAL const duk_uint8_t *duk__utf8_backtrack(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_uint_fast32_t count) { const duk_uint8_t *p; /* Note: allow backtracking from p == ptr_end */ @@ -66,12 +70,16 @@ *ptr = p; return p; - fail: +fail: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return NULL;); } -DUK_LOCAL const duk_uint8_t *duk__utf8_advance(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_uint_fast32_t count) { +DUK_LOCAL const duk_uint8_t *duk__utf8_advance(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_uint_fast32_t count) { const duk_uint8_t *p; p = *ptr; @@ -97,7 +105,7 @@ *ptr = p; return p; - fail: +fail: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return NULL;); } @@ -201,7 +209,7 @@ c1 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); DUK_ASSERT(!(re_ctx->re_flags & DUK_RE_FLAG_IGNORE_CASE) || - c1 == duk_unicode_re_canonicalize_char(re_ctx->thr, c1)); /* canonicalized by compiler */ + c1 == duk_unicode_re_canonicalize_char(re_ctx->thr, c1)); /* canonicalized by compiler */ c2 = duk__inp_get_cp(re_ctx, &sp); /* No need to check for c2 < 0 (end of input): because c1 >= 0, it * will fail the match below automatically and cause goto fail. @@ -247,7 +255,10 @@ r1 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); r2 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("matching ranges/invranges, n=%ld, r1=%ld, r2=%ld, c=%ld", - (long) n, (long) r1, (long) r2, (long) c)); + (long) n, + (long) r1, + (long) r2, + (long) c)); if (c >= r1 && c <= r2) { /* Note: don't bail out early, we must read all the ranges from * bytecode. Another option is to skip them efficiently after @@ -316,16 +327,16 @@ duk_small_int_t w1, w2; if (sp <= re_ctx->input) { - w1 = 0; /* not a wordchar */ + w1 = 0; /* not a wordchar */ } else { duk_codepoint_t c; c = duk__inp_get_prev_cp(re_ctx, sp); w1 = duk_unicode_re_is_wordchar(c); } if (sp >= re_ctx->input_end) { - w2 = 0; /* not a wordchar */ + w2 = 0; /* not a wordchar */ } else { - const duk_uint8_t *tmp_sp = sp; /* dummy so sp won't get updated */ + const duk_uint8_t *tmp_sp = sp; /* dummy so sp won't get updated */ duk_codepoint_t c; c = duk__inp_get_cp(re_ctx, &tmp_sp); w2 = duk_unicode_re_is_wordchar(c); @@ -386,7 +397,9 @@ qmax = duk__bc_get_u32(re_ctx, &pc); skip = duk__bc_get_i32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("minimal quantifier, qmin=%lu, qmax=%lu, skip=%ld", - (unsigned long) qmin, (unsigned long) qmax, (long) skip)); + (unsigned long) qmin, + (unsigned long) qmax, + (long) skip)); q = 0; while (q <= qmax) { @@ -416,7 +429,10 @@ atomlen = duk__bc_get_u32(re_ctx, &pc); skip = duk__bc_get_i32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("greedy quantifier, qmin=%lu, qmax=%lu, atomlen=%lu, skip=%ld", - (unsigned long) qmin, (unsigned long) qmax, (unsigned long) atomlen, (long) skip)); + (unsigned long) qmin, + (unsigned long) qmax, + (unsigned long) atomlen, + (long) skip)); q = 0; while (q < qmax) { @@ -442,8 +458,7 @@ * do not allow captures in their atom now, so this is not an issue. */ - DUK_DDD(DUK_DDDPRINT("greedy quantifier, backtrack %ld characters (atomlen)", - (long) atomlen)); + DUK_DDD(DUK_DDDPRINT("greedy quantifier, backtrack %ld characters (atomlen)", (long) atomlen)); sp = duk__inp_backtrack(re_ctx, &sp, (duk_uint_fast32_t) atomlen); q--; } @@ -489,20 +504,23 @@ idx_start = duk__bc_get_u32(re_ctx, &pc); idx_count = duk__bc_get_u32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("wipe saved range: start=%ld, count=%ld -> %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) idx_count, - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) idx_count, + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); if (idx_start + idx_count > re_ctx->nsaved || idx_count == 0) { /* idx is unsigned, < 0 check is not necessary */ DUK_D(DUK_DPRINT("internal error, regexp wipe indices insane: idx_start=%ld, idx_count=%ld", - (long) idx_start, (long) idx_count)); + (long) idx_start, + (long) idx_count)); goto internal_error; } DUK_ASSERT(idx_count > 0); duk_require_stack(re_ctx->thr, 1); - range_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, - sizeof(duk_uint8_t *) * idx_count); + range_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, sizeof(duk_uint8_t *) * idx_count); DUK_ASSERT(range_save != NULL); duk_memcpy(range_save, re_ctx->saved + idx_start, sizeof(duk_uint8_t *) * idx_count); #if defined(DUK_USE_EXPLICIT_NULL_INIT) @@ -518,8 +536,10 @@ if (sub_sp) { /* match: keep wiped/resaved values */ DUK_DDD(DUK_DDDPRINT("match: keep wiped/resaved values %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); duk_pop_unsafe(re_ctx->thr); sp = sub_sp; goto match; @@ -527,8 +547,10 @@ /* fail: restore saves */ DUK_DDD(DUK_DDDPRINT("fail: restore wiped/resaved values %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); duk_memcpy((void *) (re_ctx->saved + idx_start), (const void *) range_save, sizeof(duk_uint8_t *) * idx_count); @@ -558,8 +580,8 @@ DUK_ASSERT(re_ctx->nsaved > 0); duk_require_stack(re_ctx->thr, 1); - full_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, - sizeof(duk_uint8_t *) * re_ctx->nsaved); + full_save = + (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, sizeof(duk_uint8_t *) * re_ctx->nsaved); DUK_ASSERT(full_save != NULL); duk_memcpy(full_save, re_ctx->saved, sizeof(duk_uint8_t *) * re_ctx->nsaved); @@ -584,11 +606,9 @@ /* fall through */ - lookahead_fail: + lookahead_fail: /* fail: restore saves */ - duk_memcpy((void *) re_ctx->saved, - (const void *) full_save, - sizeof(duk_uint8_t *) * re_ctx->nsaved); + duk_memcpy((void *) re_ctx->saved, (const void *) full_save, sizeof(duk_uint8_t *) * re_ctx->nsaved); duk_pop_unsafe(re_ctx->thr); goto fail; } @@ -611,22 +631,23 @@ const duk_uint8_t *p; idx = duk__bc_get_u32(re_ctx, &pc); - idx = idx << 1; /* backref n -> saved indices n*2, n*2+1 */ + idx = idx << 1; /* backref n -> saved indices n*2, n*2+1 */ if (idx < 2 || idx + 1 >= re_ctx->nsaved) { /* regexp compiler should catch these */ DUK_D(DUK_DPRINT("internal error, backreference index insane")); goto internal_error; } - if (!re_ctx->savedidx || !re_ctx->savedidx+1) { + if (!re_ctx->savedidx || !re_ctx->savedidx + 1) { /* capture is 'undefined', always matches! */ DUK_DDD(DUK_DDDPRINT("backreference: saved%ld,%ld not complete, always match", - (long) idx, (long) (idx + 1))); + (long) idx, + (long) (idx + 1))); break; } DUK_DDD(DUK_DDDPRINT("backreference: match saved%ld,%ld", (long) idx, (long) (idx + 1))); p = re_ctx->savedidx; - while (p < re_ctx->savedidx+1) { + while (p < re_ctx->savedidx + 1) { duk_codepoint_t c1, c2; /* Note: not necessary to check p against re_ctx->input_end: @@ -658,15 +679,15 @@ } } - match: +match: re_ctx->recursion_depth--; return sp; - fail: +fail: re_ctx->recursion_depth--; return NULL; - internal_error: +internal_error: DUK_ERROR_INTERNAL(re_ctx->thr); DUK_WO_NORETURN(return NULL;); } @@ -718,8 +739,9 @@ h_input = duk_to_hstring(thr, -1); DUK_ASSERT(h_input != NULL); - duk_xget_owndataprop_stridx_short(thr, -2, DUK_STRIDX_INT_BYTECODE); /* ... re_obj input -> ... re_obj input bc */ - h_bytecode = duk_require_hstring(thr, -1); /* no regexp instance should exist without a non-configurable bytecode property */ + duk_xget_owndataprop_stridx_short(thr, -2, DUK_STRIDX_INT_BYTECODE); /* ... re_obj input -> ... re_obj input bc */ + h_bytecode = + duk_require_hstring(thr, -1); /* no regexp instance should exist without a non-configurable bytecode property */ DUK_ASSERT(h_bytecode != NULL); /* @@ -751,13 +773,13 @@ re_ctx.nsaved = duk__bc_get_u32(&re_ctx, &pc); re_ctx.bytecode = pc; - DUK_ASSERT(DUK_RE_FLAG_GLOBAL < 0x10000UL); /* must fit into duk_small_int_t */ + DUK_ASSERT(DUK_RE_FLAG_GLOBAL < 0x10000UL); /* must fit into duk_small_int_t */ global = (duk_small_int_t) (force_global | (duk_small_int_t) (re_ctx.re_flags & DUK_RE_FLAG_GLOBAL)); DUK_ASSERT(re_ctx.nsaved >= 2); DUK_ASSERT((re_ctx.nsaved % 2) == 0); - p_buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, sizeof(duk_uint8_t *) * re_ctx.nsaved); /* rely on zeroing */ + p_buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, sizeof(duk_uint8_t *) * re_ctx.nsaved); /* rely on zeroing */ DUK_UNREF(p_buf); re_ctx.saved = (const duk_uint8_t **) duk_get_buffer(thr, -1, NULL); DUK_ASSERT(re_ctx.saved != NULL); @@ -775,7 +797,9 @@ #endif DUK_DDD(DUK_DDDPRINT("regexp ctx initialized, flags=0x%08lx, nsaved=%ld, recursion_limit=%ld, steps_limit=%ld", - (unsigned long) re_ctx.re_flags, (long) re_ctx.nsaved, (long) re_ctx.recursion_limit, + (unsigned long) re_ctx.re_flags, + (long) re_ctx.nsaved, + (long) re_ctx.recursion_limit, (long) re_ctx.steps_limit)); /* @@ -797,15 +821,15 @@ /* ... re_obj input bc saved_buf */ - duk_get_prop_stridx_short(thr, -4, DUK_STRIDX_LAST_INDEX); /* -> ... re_obj input bc saved_buf lastIndex */ - (void) duk_to_int(thr, -1); /* ToInteger(lastIndex) */ - d = duk_get_number(thr, -1); /* integer, but may be +/- Infinite, +/- zero (not NaN, though) */ + duk_get_prop_stridx_short(thr, -4, DUK_STRIDX_LAST_INDEX); /* -> ... re_obj input bc saved_buf lastIndex */ + (void) duk_to_int(thr, -1); /* ToInteger(lastIndex) */ + d = duk_get_number(thr, -1); /* integer, but may be +/- Infinite, +/- zero (not NaN, though) */ duk_pop_nodecref_unsafe(thr); if (global) { if (d < 0.0 || d > (double) DUK_HSTRING_GET_CHARLEN(h_input)) { /* match fail */ - char_offset = 0; /* not really necessary */ + char_offset = 0; /* not really necessary */ DUK_ASSERT(match == 0); goto match_over; } @@ -841,8 +865,10 @@ DUK_ASSERT(re_ctx.recursion_depth == 0); DUK_DDD(DUK_DDDPRINT("attempt match at char offset %ld; %p %p,%p", - (long) char_offset, (const void *) sp, - (const void *) re_ctx.input, (const void *) re_ctx.input_end)); + (long) char_offset, + (const void *) sp, + (const void *) re_ctx.input, + (const void *) re_ctx.input_end)); /* * Note: @@ -889,7 +915,7 @@ (void) duk__utf8_advance(thr, &sp, re_ctx.input, re_ctx.input_end, (duk_uint_fast32_t) 1); } - match_over: +match_over: /* * Matching complete, create result array or return a 'null'. Update lastIndex @@ -915,8 +941,8 @@ DUK_DDD(DUK_DDDPRINT("regexp matches at char_offset %ld", (long) char_offset)); - DUK_ASSERT(re_ctx.nsaved >= 2); /* must have start and end */ - DUK_ASSERT((re_ctx.nsaved % 2) == 0); /* and even number */ + DUK_ASSERT(re_ctx.nsaved >= 2); /* must have start and end */ + DUK_ASSERT((re_ctx.nsaved % 2) == 0); /* and even number */ /* XXX: Array size is known before and (2 * re_ctx.nsaved) but not taken * advantage of now. The array is not compacted either, as regexp match @@ -957,7 +983,7 @@ * will be zero). Also assumes clen reflects the * correct char length. */ - char_end_offset = char_offset + (duk_uint32_t) duk_get_length(thr, -1); /* add charlen */ + char_end_offset = char_offset + (duk_uint32_t) duk_get_length(thr, -1); /* add charlen */ } } else { duk_push_undefined(thr); @@ -1022,8 +1048,8 @@ duk__regexp_match_helper(thr, 1 /*force_global*/); } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ /* regexp support disabled */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_replacements.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_replacements.h
Changed
@@ -8,7 +8,7 @@ #if defined(DUK_USE_COMPUTED_NAN) DUK_INTERNAL_DECL double duk_computed_nan; #endif -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ #if defined(DUK_USE_REPL_FPCLASSIFY) DUK_INTERNAL_DECL int duk_repl_fpclassify(double x); @@ -26,4 +26,4 @@ DUK_INTERNAL_DECL int duk_repl_isinf(double x); #endif -#endif /* DUK_REPLACEMENTS_H_INCLUDED */ +#endif /* DUK_REPLACEMENTS_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_selftest.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_selftest.c
Changed
@@ -17,18 +17,21 @@ } duk__test_double_union; /* Self test failed. Expects a local variable 'error_count' to exist. */ -#define DUK__FAILED(msg) do { \ +#define DUK__FAILED(msg) \ + do { \ DUK_D(DUK_DPRINT("self test failed: " #msg " at " DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO))); \ error_count++; \ } while (0) -#define DUK__DBLUNION_CMP_TRUE(a,b) do { \ +#define DUK__DBLUNION_CMP_TRUE(a, b) \ + do { \ if (duk_memcmp((const void *) (a), (const void *) (b), sizeof(duk__test_double_union)) != 0) { \ DUK__FAILED("double union compares false (expected true)"); \ } \ } while (0) -#define DUK__DBLUNION_CMP_FALSE(a,b) do { \ +#define DUK__DBLUNION_CMP_FALSE(a, b) \ + do { \ if (duk_memcmp((const void *) (a), (const void *) (b), sizeof(duk__test_double_union)) == 0) { \ DUK__FAILED("double union compares true (expected false)"); \ } \ @@ -40,43 +43,72 @@ } duk__test_u32_union; #if defined(DUK_USE_INTEGER_LE) -#define DUK__U32_INIT(u, a, b, c, d) do { \ - (u)->x0 = (d); (u)->x1 = (c); (u)->x2 = (b); (u)->x3 = (a); \ +#define DUK__U32_INIT(u, a, b, c, d) \ + do { \ + (u)->x0 = (d); \ + (u)->x1 = (c); \ + (u)->x2 = (b); \ + (u)->x3 = (a); \ } while (0) #elif defined(DUK_USE_INTEGER_ME) #error integer mixed endian not supported now #elif defined(DUK_USE_INTEGER_BE) -#define DUK__U32_INIT(u, a, b, c, d) do { \ - (u)->x0 = (a); (u)->x1 = (b); (u)->x2 = (c); (u)->x3 = (d); \ +#define DUK__U32_INIT(u, a, b, c, d) \ + do { \ + (u)->x0 = (a); \ + (u)->x1 = (b); \ + (u)->x2 = (c); \ + (u)->x3 = (d); \ } while (0) #else #error unknown integer endianness #endif #if defined(DUK_USE_DOUBLE_LE) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (h); (u)->x1 = (g); (u)->x2 = (f); (u)->x3 = (e); \ - (u)->x4 = (d); (u)->x5 = (c); (u)->x6 = (b); (u)->x7 = (a); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (h); \ + (u)->x1 = (g); \ + (u)->x2 = (f); \ + (u)->x3 = (e); \ + (u)->x4 = (d); \ + (u)->x5 = (c); \ + (u)->x6 = (b); \ + (u)->x7 = (a); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (h) && (u)->x1 == (g) && (u)->x2 == (f) && (u)->x3 == (e) && \ - (u)->x4 == (d) && (u)->x5 == (c) && (u)->x6 == (b) && (u)->x7 == (a)) + ((u)->x0 == (h) && (u)->x1 == (g) && (u)->x2 == (f) && (u)->x3 == (e) && (u)->x4 == (d) && (u)->x5 == (c) && \ + (u)->x6 == (b) && (u)->x7 == (a)) #elif defined(DUK_USE_DOUBLE_ME) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (d); (u)->x1 = (c); (u)->x2 = (b); (u)->x3 = (a); \ - (u)->x4 = (h); (u)->x5 = (g); (u)->x6 = (f); (u)->x7 = (e); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (d); \ + (u)->x1 = (c); \ + (u)->x2 = (b); \ + (u)->x3 = (a); \ + (u)->x4 = (h); \ + (u)->x5 = (g); \ + (u)->x6 = (f); \ + (u)->x7 = (e); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (d) && (u)->x1 == (c) && (u)->x2 == (b) && (u)->x3 == (a) && \ - (u)->x4 == (h) && (u)->x5 == (g) && (u)->x6 == (f) && (u)->x7 == (e)) + ((u)->x0 == (d) && (u)->x1 == (c) && (u)->x2 == (b) && (u)->x3 == (a) && (u)->x4 == (h) && (u)->x5 == (g) && \ + (u)->x6 == (f) && (u)->x7 == (e)) #elif defined(DUK_USE_DOUBLE_BE) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (a); (u)->x1 = (b); (u)->x2 = (c); (u)->x3 = (d); \ - (u)->x4 = (e); (u)->x5 = (f); (u)->x6 = (g); (u)->x7 = (h); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (a); \ + (u)->x1 = (b); \ + (u)->x2 = (c); \ + (u)->x3 = (d); \ + (u)->x4 = (e); \ + (u)->x5 = (f); \ + (u)->x6 = (g); \ + (u)->x7 = (h); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (a) && (u)->x1 == (b) && (u)->x2 == (c) && (u)->x3 == (d) && \ - (u)->x4 == (e) && (u)->x5 == (f) && (u)->x6 == (g) && (u)->x7 == (h)) + ((u)->x0 == (a) && (u)->x1 == (b) && (u)->x2 == (c) && (u)->x3 == (d) && (u)->x4 == (e) && (u)->x5 == (f) && \ + (u)->x6 == (g) && (u)->x7 == (h)) #else #error unknown double endianness #endif @@ -88,17 +120,12 @@ DUK_LOCAL duk_uint_t duk__selftest_types(void) { duk_uint_t error_count = 0; - if (!(sizeof(duk_int8_t) == 1 && - sizeof(duk_uint8_t) == 1 && - sizeof(duk_int16_t) == 2 && - sizeof(duk_uint16_t) == 2 && - sizeof(duk_int32_t) == 4 && - sizeof(duk_uint32_t) == 4)) { + if (!(sizeof(duk_int8_t) == 1 && sizeof(duk_uint8_t) == 1 && sizeof(duk_int16_t) == 2 && sizeof(duk_uint16_t) == 2 && + sizeof(duk_int32_t) == 4 && sizeof(duk_uint32_t) == 4)) { DUK__FAILED("duk_(u)int{8,16,32}_t size"); } #if defined(DUK_USE_64BIT_OPS) - if (!(sizeof(duk_int64_t) == 8 && - sizeof(duk_uint64_t) == 8)) { + if (!(sizeof(duk_int64_t) == 8 && sizeof(duk_uint64_t) == 8)) { DUK__FAILED("duk_(u)int64_t size"); } #endif @@ -250,8 +277,14 @@ * (2.008366013071895,) */ - du.uc0 = 0x40; du.uc1 = 0x00; du.uc2 = 0x11; du.uc3 = 0x22; - du.uc4 = 0x33; du.uc5 = 0x44; du.uc6 = 0x55; du.uc7 = 0x66; + du.uc0 = 0x40; + du.uc1 = 0x00; + du.uc2 = 0x11; + du.uc3 = 0x22; + du.uc4 = 0x33; + du.uc5 = 0x44; + du.uc6 = 0x55; + du.uc7 = 0x66; DUK_DBLUNION_DOUBLE_NTOH(&du); du_diff = du.d - 2.008366013071895; #if 0 @@ -306,20 +339,38 @@ */ /* little endian */ - a.x0 = 0x11; a.x1 = 0x22; a.x2 = 0x33; a.x3 = 0x44; - a.x4 = 0x00; a.x5 = 0x00; a.x6 = 0xf1; a.x7 = 0xff; + a.x0 = 0x11; + a.x1 = 0x22; + a.x2 = 0x33; + a.x3 = 0x44; + a.x4 = 0x00; + a.x5 = 0x00; + a.x6 = 0xf1; + a.x7 = 0xff; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); /* big endian */ - a.x0 = 0xff; a.x1 = 0xf1; a.x2 = 0x00; a.x3 = 0x00; - a.x4 = 0x44; a.x5 = 0x33; a.x6 = 0x22; a.x7 = 0x11; + a.x0 = 0xff; + a.x1 = 0xf1; + a.x2 = 0x00; + a.x3 = 0x00; + a.x4 = 0x44; + a.x5 = 0x33; + a.x6 = 0x22; + a.x7 = 0x11; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); /* mixed endian */ - a.x0 = 0x00; a.x1 = 0x00; a.x2 = 0xf1; a.x3 = 0xff; - a.x4 = 0x11; a.x5 = 0x22; a.x6 = 0x33; a.x7 = 0x44; + a.x0 = 0x00; + a.x1 = 0x00; + a.x2 = 0xf1; + a.x3 = 0xff; + a.x4 = 0x11; + a.x5 = 0x22; + a.x6 = 0x33; + a.x7 = 0x44; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); @@ -384,10 +435,14 @@ c.d = a.d + b.d; if (!DUK__DOUBLE_COMPARE(&c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)) { DUK_D(DUK_DPRINT("broken result (native endiannesss): %02x %02x %02x %02x %02x %02x %02x %02x", - (unsigned int) c.x0, (unsigned int) c.x1, - (unsigned int) c.x2, (unsigned int) c.x3, - (unsigned int) c.x4, (unsigned int) c.x5, - (unsigned int) c.x6, (unsigned int) c.x7)); + (unsigned int) c.x0, + (unsigned int) c.x1, + (unsigned int) c.x2, + (unsigned int) c.x3, + (unsigned int) c.x4, + (unsigned int) c.x5, + (unsigned int) c.x6, + (unsigned int) c.x7)); DUK__FAILED("invalid result from 1.0 + 0.5ulp"); } @@ -404,10 +459,14 @@ c.d = a.d + b.d; if (!DUK__DOUBLE_COMPARE(&c, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02)) { DUK_D(DUK_DPRINT("broken result (native endiannesss): %02x %02x %02x %02x %02x %02x %02x %02x", - (unsigned int) c.x0, (unsigned int) c.x1, - (unsigned int) c.x2, (unsigned int) c.x3, - (unsigned int) c.x4, (unsigned int) c.x5, - (unsigned int) c.x6, (unsigned int) c.x7)); + (unsigned int) c.x0, + (unsigned int) c.x1, + (unsigned int) c.x2, + (unsigned int) c.x3, + (unsigned int) c.x4, + (unsigned int) c.x5, + (unsigned int) c.x6, + (unsigned int) c.x7)); DUK__FAILED("invalid result from (1.0 + ulp) + 0.5ulp"); } @@ -578,7 +637,7 @@ duk_double_t dv; duk_uint32_t uv; - dv = 3735928559.0; /* 0xdeadbeef in decimal */ + dv = 3735928559.0; /* 0xdeadbeef in decimal */ uv = (duk_uint32_t) dv; if (uv != 0xdeadbeefUL) { @@ -615,7 +674,7 @@ ptr = alloc_func(udata, (duk_size_t) i); if (ptr == NULL) { DUK_D(DUK_DPRINT("alloc failed, ignore")); - continue; /* alloc failed, ignore */ + continue; /* alloc failed, ignore */ } for (j = 0; j < i; j++) { ((unsigned char *) ptr)j = (unsigned char) (0x80 + j); @@ -624,14 +683,15 @@ if (new_ptr == NULL) { DUK_D(DUK_DPRINT("realloc failed, ignore")); free_func(udata, ptr); - continue; /* realloc failed, ignore */ + continue; /* realloc failed, ignore */ } ptr = new_ptr; for (j = 0; j < i; j++) { x = ((unsigned char *) ptr)j; if (x != (unsigned char) (0x80 + j)) { DUK_D(DUK_DPRINT("byte at index %ld doesn't match after realloc: %02lx", - (long) j, (unsigned long) x)); + (long) j, + (unsigned long) x)); DUK__FAILED("byte compare after realloc"); break; } @@ -675,4 +735,4 @@ return error_count; } -#endif /* DUK_USE_SELF_TESTS */ +#endif /* DUK_USE_SELF_TESTS */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_selftest.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_selftest.h
Changed
@@ -12,4 +12,4 @@ void *udata); #endif -#endif /* DUK_SELFTEST_H_INCLUDED */ +#endif /* DUK_SELFTEST_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_source_meta.json -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_source_meta.json
Changed
@@ -1,10 +1,10 @@ { "comment": "Metadata for Duktape sources", - "duk_version_string": "2.6.0", + "duk_version_string": "2.7.0", "type": "duk_source_meta", - "duk_version": 20600, - "git_branch": "v2-maintenance", - "git_commit": "fffa346eff06a8764b02c31d4336f63a773a95c3", + "duk_version": 20700, + "git_branch": "HEAD", + "git_commit": "03d4d728f8365021de6955c649e6dcd05dcca99f", "builtin_strings_info": { "plain": "Undefined", @@ -1011,7 +1011,7 @@ "c3RhdGlj", "eWllbGQ=" , - "git_describe": "v2.6.0", + "git_describe": "03d4d72-dirty", "builtin_strings": "Undefined", "Null",
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_strings.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_strings.h
Changed
@@ -22,148 +22,148 @@ #define DUK_ERRMSG_H_INCLUDED /* Mostly API and built-in method related */ -#define DUK_STR_INTERNAL_ERROR "internal error" -#define DUK_STR_UNSUPPORTED "unsupported" -#define DUK_STR_INVALID_COUNT "invalid count" -#define DUK_STR_INVALID_ARGS "invalid args" -#define DUK_STR_INVALID_STATE "invalid state" -#define DUK_STR_INVALID_INPUT "invalid input" -#define DUK_STR_INVALID_LENGTH "invalid length" -#define DUK_STR_NOT_CONSTRUCTABLE "not constructable" -#define DUK_STR_CONSTRUCT_ONLY "constructor requires 'new'" -#define DUK_STR_NOT_CALLABLE "not callable" -#define DUK_STR_NOT_EXTENSIBLE "not extensible" -#define DUK_STR_NOT_WRITABLE "not writable" -#define DUK_STR_NOT_CONFIGURABLE "not configurable" -#define DUK_STR_INVALID_CONTEXT "invalid context" -#define DUK_STR_INVALID_INDEX "invalid args" -#define DUK_STR_PUSH_BEYOND_ALLOC_STACK "cannot push beyond allocated stack" -#define DUK_STR_NOT_UNDEFINED "unexpected type" -#define DUK_STR_NOT_NULL "unexpected type" -#define DUK_STR_NOT_BOOLEAN "unexpected type" -#define DUK_STR_NOT_NUMBER "unexpected type" -#define DUK_STR_NOT_STRING "unexpected type" -#define DUK_STR_NOT_OBJECT "unexpected type" -#define DUK_STR_NOT_POINTER "unexpected type" -#define DUK_STR_NOT_BUFFER "not buffer" /* still in use with verbose messages */ -#define DUK_STR_UNEXPECTED_TYPE "unexpected type" -#define DUK_STR_NOT_THREAD "unexpected type" -#define DUK_STR_NOT_COMPFUNC "unexpected type" -#define DUK_STR_NOT_NATFUNC "unexpected type" -#define DUK_STR_NOT_C_FUNCTION "unexpected type" -#define DUK_STR_NOT_FUNCTION "unexpected type" -#define DUK_STR_NOT_REGEXP "unexpected type" -#define DUK_STR_TOPRIMITIVE_FAILED "coercion to primitive failed" -#define DUK_STR_NUMBER_OUTSIDE_RANGE "number outside range" -#define DUK_STR_NOT_OBJECT_COERCIBLE "not object coercible" -#define DUK_STR_CANNOT_NUMBER_COERCE_SYMBOL "cannot number coerce Symbol" -#define DUK_STR_CANNOT_STRING_COERCE_SYMBOL "cannot string coerce Symbol" -#define DUK_STR_STRING_TOO_LONG "string too long" -#define DUK_STR_BUFFER_TOO_LONG "buffer too long" -#define DUK_STR_ALLOC_FAILED "alloc failed" -#define DUK_STR_WRONG_BUFFER_TYPE "wrong buffer type" -#define DUK_STR_BASE64_ENCODE_FAILED "base64 encode failed" -#define DUK_STR_SOURCE_DECODE_FAILED "source decode failed" -#define DUK_STR_UTF8_DECODE_FAILED "utf-8 decode failed" -#define DUK_STR_BASE64_DECODE_FAILED "base64 decode failed" -#define DUK_STR_HEX_DECODE_FAILED "hex decode failed" -#define DUK_STR_INVALID_BYTECODE "invalid bytecode" -#define DUK_STR_NO_SOURCECODE "no sourcecode" -#define DUK_STR_RESULT_TOO_LONG "result too long" -#define DUK_STR_INVALID_CFUNC_RC "invalid C function rc" -#define DUK_STR_INVALID_INSTANCEOF_RVAL "invalid instanceof rval" -#define DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO "instanceof rval has no .prototype" +#define DUK_STR_INTERNAL_ERROR "internal error" +#define DUK_STR_UNSUPPORTED "unsupported" +#define DUK_STR_INVALID_COUNT "invalid count" +#define DUK_STR_INVALID_ARGS "invalid args" +#define DUK_STR_INVALID_STATE "invalid state" +#define DUK_STR_INVALID_INPUT "invalid input" +#define DUK_STR_INVALID_LENGTH "invalid length" +#define DUK_STR_NOT_CONSTRUCTABLE "not constructable" +#define DUK_STR_CONSTRUCT_ONLY "constructor requires 'new'" +#define DUK_STR_NOT_CALLABLE "not callable" +#define DUK_STR_NOT_EXTENSIBLE "not extensible" +#define DUK_STR_NOT_WRITABLE "not writable" +#define DUK_STR_NOT_CONFIGURABLE "not configurable" +#define DUK_STR_INVALID_CONTEXT "invalid context" +#define DUK_STR_INVALID_INDEX "invalid args" +#define DUK_STR_PUSH_BEYOND_ALLOC_STACK "cannot push beyond allocated stack" +#define DUK_STR_NOT_UNDEFINED "unexpected type" +#define DUK_STR_NOT_NULL "unexpected type" +#define DUK_STR_NOT_BOOLEAN "unexpected type" +#define DUK_STR_NOT_NUMBER "unexpected type" +#define DUK_STR_NOT_STRING "unexpected type" +#define DUK_STR_NOT_OBJECT "unexpected type" +#define DUK_STR_NOT_POINTER "unexpected type" +#define DUK_STR_NOT_BUFFER "not buffer" /* still in use with verbose messages */ +#define DUK_STR_UNEXPECTED_TYPE "unexpected type" +#define DUK_STR_NOT_THREAD "unexpected type" +#define DUK_STR_NOT_COMPFUNC "unexpected type" +#define DUK_STR_NOT_NATFUNC "unexpected type" +#define DUK_STR_NOT_C_FUNCTION "unexpected type" +#define DUK_STR_NOT_FUNCTION "unexpected type" +#define DUK_STR_NOT_REGEXP "unexpected type" +#define DUK_STR_TOPRIMITIVE_FAILED "coercion to primitive failed" +#define DUK_STR_NUMBER_OUTSIDE_RANGE "number outside range" +#define DUK_STR_NOT_OBJECT_COERCIBLE "not object coercible" +#define DUK_STR_CANNOT_NUMBER_COERCE_SYMBOL "cannot number coerce Symbol" +#define DUK_STR_CANNOT_STRING_COERCE_SYMBOL "cannot string coerce Symbol" +#define DUK_STR_STRING_TOO_LONG "string too long" +#define DUK_STR_BUFFER_TOO_LONG "buffer too long" +#define DUK_STR_ALLOC_FAILED "alloc failed" +#define DUK_STR_WRONG_BUFFER_TYPE "wrong buffer type" +#define DUK_STR_BASE64_ENCODE_FAILED "base64 encode failed" +#define DUK_STR_SOURCE_DECODE_FAILED "source decode failed" +#define DUK_STR_UTF8_DECODE_FAILED "utf-8 decode failed" +#define DUK_STR_BASE64_DECODE_FAILED "base64 decode failed" +#define DUK_STR_HEX_DECODE_FAILED "hex decode failed" +#define DUK_STR_INVALID_BYTECODE "invalid bytecode" +#define DUK_STR_NO_SOURCECODE "no sourcecode" +#define DUK_STR_RESULT_TOO_LONG "result too long" +#define DUK_STR_INVALID_CFUNC_RC "invalid C function rc" +#define DUK_STR_INVALID_INSTANCEOF_RVAL "invalid instanceof rval" +#define DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO "instanceof rval has no .prototype" /* JSON */ -#define DUK_STR_FMT_PTR "%p" -#define DUK_STR_FMT_INVALID_JSON "invalid json (at offset %ld)" -#define DUK_STR_CYCLIC_INPUT "cyclic input" +#define DUK_STR_FMT_PTR "%p" +#define DUK_STR_FMT_INVALID_JSON "invalid json (at offset %ld)" +#define DUK_STR_CYCLIC_INPUT "cyclic input" /* Generic codec */ -#define DUK_STR_DEC_RECLIMIT "decode recursion limit" -#define DUK_STR_ENC_RECLIMIT "encode recursion limit" +#define DUK_STR_DEC_RECLIMIT "decode recursion limit" +#define DUK_STR_ENC_RECLIMIT "encode recursion limit" /* Object property access */ -#define DUK_STR_INVALID_BASE "invalid base value" -#define DUK_STR_STRICT_CALLER_READ "cannot read strict 'caller'" -#define DUK_STR_PROXY_REJECTED "proxy rejected" -#define DUK_STR_INVALID_ARRAY_LENGTH "invalid array length" -#define DUK_STR_SETTER_UNDEFINED "setter undefined" -#define DUK_STR_INVALID_DESCRIPTOR "invalid descriptor" +#define DUK_STR_INVALID_BASE "invalid base value" +#define DUK_STR_STRICT_CALLER_READ "cannot read strict 'caller'" +#define DUK_STR_PROXY_REJECTED "proxy rejected" +#define DUK_STR_INVALID_ARRAY_LENGTH "invalid array length" +#define DUK_STR_SETTER_UNDEFINED "setter undefined" +#define DUK_STR_INVALID_DESCRIPTOR "invalid descriptor" /* Proxy */ -#define DUK_STR_PROXY_REVOKED "proxy revoked" -#define DUK_STR_INVALID_TRAP_RESULT "invalid trap result" +#define DUK_STR_PROXY_REVOKED "proxy revoked" +#define DUK_STR_INVALID_TRAP_RESULT "invalid trap result" /* Variables */ /* Lexer */ -#define DUK_STR_INVALID_ESCAPE "invalid escape" -#define DUK_STR_UNTERMINATED_STRING "unterminated string" -#define DUK_STR_UNTERMINATED_COMMENT "unterminated comment" -#define DUK_STR_UNTERMINATED_REGEXP "unterminated regexp" -#define DUK_STR_TOKEN_LIMIT "token limit" -#define DUK_STR_REGEXP_SUPPORT_DISABLED "regexp support disabled" -#define DUK_STR_INVALID_NUMBER_LITERAL "invalid number literal" -#define DUK_STR_INVALID_TOKEN "invalid token" +#define DUK_STR_INVALID_ESCAPE "invalid escape" +#define DUK_STR_UNTERMINATED_STRING "unterminated string" +#define DUK_STR_UNTERMINATED_COMMENT "unterminated comment" +#define DUK_STR_UNTERMINATED_REGEXP "unterminated regexp" +#define DUK_STR_TOKEN_LIMIT "token limit" +#define DUK_STR_REGEXP_SUPPORT_DISABLED "regexp support disabled" +#define DUK_STR_INVALID_NUMBER_LITERAL "invalid number literal" +#define DUK_STR_INVALID_TOKEN "invalid token" /* Compiler */ -#define DUK_STR_PARSE_ERROR "parse error" -#define DUK_STR_DUPLICATE_LABEL "duplicate label" -#define DUK_STR_INVALID_LABEL "invalid label" -#define DUK_STR_INVALID_ARRAY_LITERAL "invalid array literal" -#define DUK_STR_INVALID_OBJECT_LITERAL "invalid object literal" -#define DUK_STR_INVALID_VAR_DECLARATION "invalid variable declaration" -#define DUK_STR_CANNOT_DELETE_IDENTIFIER "cannot delete identifier" -#define DUK_STR_INVALID_EXPRESSION "invalid expression" -#define DUK_STR_INVALID_LVALUE "invalid lvalue" -#define DUK_STR_INVALID_NEWTARGET "invalid new.target" -#define DUK_STR_EXPECTED_IDENTIFIER "expected identifier" -#define DUK_STR_EMPTY_EXPR_NOT_ALLOWED "empty expression not allowed" -#define DUK_STR_INVALID_FOR "invalid for statement" -#define DUK_STR_INVALID_SWITCH "invalid switch statement" -#define DUK_STR_INVALID_BREAK_CONT_LABEL "invalid break/continue label" -#define DUK_STR_INVALID_RETURN "invalid return" -#define DUK_STR_INVALID_TRY "invalid try" -#define DUK_STR_INVALID_THROW "invalid throw" -#define DUK_STR_WITH_IN_STRICT_MODE "with in strict mode" -#define DUK_STR_FUNC_STMT_NOT_ALLOWED "function statement not allowed" -#define DUK_STR_UNTERMINATED_STMT "unterminated statement" -#define DUK_STR_INVALID_ARG_NAME "invalid argument name" -#define DUK_STR_INVALID_FUNC_NAME "invalid function name" -#define DUK_STR_INVALID_GETSET_NAME "invalid getter/setter name" -#define DUK_STR_FUNC_NAME_REQUIRED "function name required" +#define DUK_STR_PARSE_ERROR "parse error" +#define DUK_STR_DUPLICATE_LABEL "duplicate label" +#define DUK_STR_INVALID_LABEL "invalid label" +#define DUK_STR_INVALID_ARRAY_LITERAL "invalid array literal" +#define DUK_STR_INVALID_OBJECT_LITERAL "invalid object literal" +#define DUK_STR_INVALID_VAR_DECLARATION "invalid variable declaration" +#define DUK_STR_CANNOT_DELETE_IDENTIFIER "cannot delete identifier" +#define DUK_STR_INVALID_EXPRESSION "invalid expression" +#define DUK_STR_INVALID_LVALUE "invalid lvalue" +#define DUK_STR_INVALID_NEWTARGET "invalid new.target" +#define DUK_STR_EXPECTED_IDENTIFIER "expected identifier" +#define DUK_STR_EMPTY_EXPR_NOT_ALLOWED "empty expression not allowed" +#define DUK_STR_INVALID_FOR "invalid for statement" +#define DUK_STR_INVALID_SWITCH "invalid switch statement" +#define DUK_STR_INVALID_BREAK_CONT_LABEL "invalid break/continue label" +#define DUK_STR_INVALID_RETURN "invalid return" +#define DUK_STR_INVALID_TRY "invalid try" +#define DUK_STR_INVALID_THROW "invalid throw" +#define DUK_STR_WITH_IN_STRICT_MODE "with in strict mode" +#define DUK_STR_FUNC_STMT_NOT_ALLOWED "function statement not allowed" +#define DUK_STR_UNTERMINATED_STMT "unterminated statement" +#define DUK_STR_INVALID_ARG_NAME "invalid argument name" +#define DUK_STR_INVALID_FUNC_NAME "invalid function name" +#define DUK_STR_INVALID_GETSET_NAME "invalid getter/setter name" +#define DUK_STR_FUNC_NAME_REQUIRED "function name required" /* RegExp */ -#define DUK_STR_INVALID_QUANTIFIER "invalid regexp quantifier" -#define DUK_STR_INVALID_QUANTIFIER_NO_ATOM "quantifier without preceding atom" -#define DUK_STR_INVALID_QUANTIFIER_VALUES "quantifier values invalid (qmin > qmax)" -#define DUK_STR_QUANTIFIER_TOO_MANY_COPIES "quantifier requires too many atom copies" -#define DUK_STR_UNEXPECTED_CLOSING_PAREN "unexpected closing parenthesis" -#define DUK_STR_UNEXPECTED_END_OF_PATTERN "unexpected end of pattern" -#define DUK_STR_UNEXPECTED_REGEXP_TOKEN "unexpected token in regexp" -#define DUK_STR_INVALID_REGEXP_FLAGS "invalid regexp flags" -#define DUK_STR_INVALID_REGEXP_ESCAPE "invalid regexp escape" -#define DUK_STR_INVALID_BACKREFS "invalid backreference(s)" -#define DUK_STR_INVALID_REGEXP_CHARACTER "invalid regexp character" -#define DUK_STR_INVALID_REGEXP_GROUP "invalid regexp group" -#define DUK_STR_UNTERMINATED_CHARCLASS "unterminated character class" -#define DUK_STR_INVALID_RANGE "invalid range" +#define DUK_STR_INVALID_QUANTIFIER "invalid regexp quantifier" +#define DUK_STR_INVALID_QUANTIFIER_NO_ATOM "quantifier without preceding atom" +#define DUK_STR_INVALID_QUANTIFIER_VALUES "quantifier values invalid (qmin > qmax)" +#define DUK_STR_QUANTIFIER_TOO_MANY_COPIES "quantifier requires too many atom copies" +#define DUK_STR_UNEXPECTED_CLOSING_PAREN "unexpected closing parenthesis" +#define DUK_STR_UNEXPECTED_END_OF_PATTERN "unexpected end of pattern" +#define DUK_STR_UNEXPECTED_REGEXP_TOKEN "unexpected token in regexp" +#define DUK_STR_INVALID_REGEXP_FLAGS "invalid regexp flags" +#define DUK_STR_INVALID_REGEXP_ESCAPE "invalid regexp escape" +#define DUK_STR_INVALID_BACKREFS "invalid backreference(s)" +#define DUK_STR_INVALID_REGEXP_CHARACTER "invalid regexp character" +#define DUK_STR_INVALID_REGEXP_GROUP "invalid regexp group" +#define DUK_STR_UNTERMINATED_CHARCLASS "unterminated character class" +#define DUK_STR_INVALID_RANGE "invalid range" /* Limits */ -#define DUK_STR_VALSTACK_LIMIT "valstack limit" -#define DUK_STR_CALLSTACK_LIMIT "callstack limit" -#define DUK_STR_PROTOTYPE_CHAIN_LIMIT "prototype chain limit" -#define DUK_STR_BOUND_CHAIN_LIMIT "function call bound chain limit" -#define DUK_STR_NATIVE_STACK_LIMIT "C stack depth limit" -#define DUK_STR_COMPILER_RECURSION_LIMIT "compiler recursion limit" -#define DUK_STR_BYTECODE_LIMIT "bytecode limit" -#define DUK_STR_REG_LIMIT "register limit" -#define DUK_STR_TEMP_LIMIT "temp limit" -#define DUK_STR_CONST_LIMIT "const limit" -#define DUK_STR_FUNC_LIMIT "function limit" -#define DUK_STR_REGEXP_COMPILER_RECURSION_LIMIT "regexp compiler recursion limit" -#define DUK_STR_REGEXP_EXECUTOR_RECURSION_LIMIT "regexp executor recursion limit" -#define DUK_STR_REGEXP_EXECUTOR_STEP_LIMIT "regexp step limit" +#define DUK_STR_VALSTACK_LIMIT "valstack limit" +#define DUK_STR_CALLSTACK_LIMIT "callstack limit" +#define DUK_STR_PROTOTYPE_CHAIN_LIMIT "prototype chain limit" +#define DUK_STR_BOUND_CHAIN_LIMIT "function call bound chain limit" +#define DUK_STR_NATIVE_STACK_LIMIT "C stack depth limit" +#define DUK_STR_COMPILER_RECURSION_LIMIT "compiler recursion limit" +#define DUK_STR_BYTECODE_LIMIT "bytecode limit" +#define DUK_STR_REG_LIMIT "register limit" +#define DUK_STR_TEMP_LIMIT "temp limit" +#define DUK_STR_CONST_LIMIT "const limit" +#define DUK_STR_FUNC_LIMIT "function limit" +#define DUK_STR_REGEXP_COMPILER_RECURSION_LIMIT "regexp compiler recursion limit" +#define DUK_STR_REGEXP_EXECUTOR_RECURSION_LIMIT "regexp executor recursion limit" +#define DUK_STR_REGEXP_EXECUTOR_STEP_LIMIT "regexp step limit" -#endif /* DUK_ERRMSG_H_INCLUDED */ +#endif /* DUK_ERRMSG_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_tval.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_tval.c
Changed
@@ -32,11 +32,11 @@ expt = (duk_small_int_t) ((i >> 52) & 0x07ff); shift = expt - 1023; - if (shift >= 0 && shift <= 46) { /* exponents 1023 to 1069 */ + if (shift >= 0 && shift <= 46) { /* exponents 1023 to 1069 */ duk_int64_t t; if (((DUK_I64_CONSTANT(0x000fffffffffffff) >> shift) & i) == 0) { - t = i | DUK_I64_CONSTANT(0x0010000000000000); /* implicit leading one */ + t = i | DUK_I64_CONSTANT(0x0010000000000000); /* implicit leading one */ t = t & DUK_I64_CONSTANT(0x001fffffffffffff); t = t >> (52 - shift); if (i < 0) { @@ -45,13 +45,13 @@ DUK_TVAL_SET_FASTINT(tv, t); return; } - } else if (shift == -1023) { /* exponent 0 */ + } else if (shift == -1023) { /* exponent 0 */ if (i >= 0 && (i & DUK_I64_CONSTANT(0x000fffffffffffff)) == 0) { /* Note: reject negative zero. */ DUK_TVAL_SET_FASTINT(tv, (duk_int64_t) 0); return; } - } else if (shift == 47) { /* exponent 1070 */ + } else if (shift == 47) { /* exponent 1070 */ if (i < 0 && (i & DUK_I64_CONSTANT(0x000fffffffffffff)) == 0) { DUK_TVAL_SET_FASTINT(tv, (duk_int64_t) DUK_FASTINT_MIN); return; @@ -79,23 +79,23 @@ if ((t >> 48) != DUK_TAG_FASTINT) { return tv->d; } else if (t & DUK_U64_CONSTANT(0x0000800000000000)) { - t = (duk_uint64_t) (-((duk_int64_t) t)); /* avoid unary minus on unsigned */ - t = t & DUK_U64_CONSTANT(0x0000ffffffffffff); /* negative */ + t = (duk_uint64_t) (-((duk_int64_t) t)); /* avoid unary minus on unsigned */ + t = t & DUK_U64_CONSTANT(0x0000ffffffffffff); /* negative */ t |= DUK_U64_CONSTANT(0xc330000000000000); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d + 4503599627370496.0; /* 1 << 52 */ + return du.d + 4503599627370496.0; /* 1 << 52 */ } else if (t != 0) { - t &= DUK_U64_CONSTANT(0x0000ffffffffffff); /* positive */ + t &= DUK_U64_CONSTANT(0x0000ffffffffffff); /* positive */ t |= DUK_U64_CONSTANT(0x4330000000000000); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d - 4503599627370496.0; /* 1 << 52 */ + return du.d - 4503599627370496.0; /* 1 << 52 */ } else { - return 0.0; /* zero */ + return 0.0; /* zero */ } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#if 0 /* unused */ +#if 0 /* unused */ #if defined(DUK_USE_FASTINT) && !defined(DUK_USE_PACKED_TVAL) DUK_INTERNAL DUK_ALWAYS_INLINE duk_double_t duk_tval_get_number_unpacked(duk_tval *tv) { duk_double_union du; @@ -117,8 +117,8 @@ return tv->v.d; } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#endif /* 0 */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* 0 */ #if defined(DUK_USE_FASTINT) && !defined(DUK_USE_PACKED_TVAL) DUK_INTERNAL DUK_ALWAYS_INLINE duk_double_t duk_tval_get_number_unpacked_fastint(duk_tval *tv) { @@ -130,16 +130,16 @@ if (tv->v.fi >= 0) { t = DUK_U64_CONSTANT(0x4330000000000000) | (duk_uint64_t) tv->v.fi; DUK_DBLUNION_SET_UINT64(&du, t); - return du.d - 4503599627370496.0; /* 1 << 52 */ + return du.d - 4503599627370496.0; /* 1 << 52 */ } else { t = DUK_U64_CONSTANT(0xc330000000000000) | (duk_uint64_t) (-tv->v.fi); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d + 4503599627370496.0; /* 1 << 52 */ + return du.d + 4503599627370496.0; /* 1 << 52 */ } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* * Assertion helpers.
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_tval.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_tval.h
Changed
@@ -41,30 +41,29 @@ } duk_tval_unused; /* tags */ -#define DUK_TAG_NORMALIZED_NAN 0x7ff8UL /* the NaN variant we use */ +#define DUK_TAG_NORMALIZED_NAN 0x7ff8UL /* the NaN variant we use */ /* avoid tag 0xfff0, no risk of confusion with negative infinity */ -#define DUK_TAG_MIN 0xfff1UL +#define DUK_TAG_MIN 0xfff1UL #if defined(DUK_USE_FASTINT) -#define DUK_TAG_FASTINT 0xfff1UL /* embed: integer value */ +#define DUK_TAG_FASTINT 0xfff1UL /* embed: integer value */ #endif -#define DUK_TAG_UNUSED 0xfff2UL /* marker; not actual tagged value */ -#define DUK_TAG_UNDEFINED 0xfff3UL /* embed: nothing */ -#define DUK_TAG_NULL 0xfff4UL /* embed: nothing */ -#define DUK_TAG_BOOLEAN 0xfff5UL /* embed: 0 or 1 (false or true) */ +#define DUK_TAG_UNUSED 0xfff2UL /* marker; not actual tagged value */ +#define DUK_TAG_UNDEFINED 0xfff3UL /* embed: nothing */ +#define DUK_TAG_NULL 0xfff4UL /* embed: nothing */ +#define DUK_TAG_BOOLEAN 0xfff5UL /* embed: 0 or 1 (false or true) */ /* DUK_TAG_NUMBER would logically go here, but it has multiple 'tags' */ -#define DUK_TAG_POINTER 0xfff6UL /* embed: void ptr */ -#define DUK_TAG_LIGHTFUNC 0xfff7UL /* embed: func ptr */ -#define DUK_TAG_STRING 0xfff8UL /* embed: duk_hstring ptr */ -#define DUK_TAG_OBJECT 0xfff9UL /* embed: duk_hobject ptr */ -#define DUK_TAG_BUFFER 0xfffaUL /* embed: duk_hbuffer ptr */ -#define DUK_TAG_MAX 0xfffaUL +#define DUK_TAG_POINTER 0xfff6UL /* embed: void ptr */ +#define DUK_TAG_LIGHTFUNC 0xfff7UL /* embed: func ptr */ +#define DUK_TAG_STRING 0xfff8UL /* embed: duk_hstring ptr */ +#define DUK_TAG_OBJECT 0xfff9UL /* embed: duk_hobject ptr */ +#define DUK_TAG_BUFFER 0xfffaUL /* embed: duk_hbuffer ptr */ +#define DUK_TAG_MAX 0xfffaUL /* for convenience */ -#define DUK_XTAG_BOOLEAN_FALSE 0xfff50000UL -#define DUK_XTAG_BOOLEAN_TRUE 0xfff50001UL +#define DUK_XTAG_BOOLEAN_FALSE 0xfff50000UL +#define DUK_XTAG_BOOLEAN_TRUE 0xfff50001UL -#define DUK_TVAL_IS_VALID_TAG(tv) \ - (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) +#define DUK_TVAL_IS_VALID_TAG(tv) (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) /* DUK_TVAL_UNUSED initializer for duk_tval_unused, works for any endianness. */ #define DUK_TVAL_UNUSED_INITIALIZER() \ @@ -73,116 +72,136 @@ /* two casts to avoid gcc warning: "warning: cast from pointer to integer of different size -Wpointer-to-int-cast" */ #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) (tag)) << 16) | (((duk_uint64_t) (duk_uint32_t) (h)) << 32); \ } while (0) #else -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) (tag)) << 48) | ((duk_uint64_t) (duk_uint32_t) (h)); \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) (tag)) << 16; \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (h); \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ #if defined(DUK_USE_64BIT_OPS) /* Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size) */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 16) | \ - ((duk_uint64_t) (flags)) | \ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 16) | ((duk_uint64_t) (flags)) | \ (((duk_uint64_t) (duk_uint32_t) (fp)) << 32); \ } while (0) #else -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 48) | \ - (((duk_uint64_t) (flags)) << 32) | \ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 48) | (((duk_uint64_t) (flags)) << 32) | \ ((duk_uint64_t) (duk_uint32_t) (fp)); \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = (((duk_uint32_t) DUK_TAG_LIGHTFUNC) << 16) | ((duk_uint32_t) (flags)); \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (fp); \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ #if defined(DUK_USE_FASTINT) /* Note: masking is done for 'i' to deal with negative numbers correctly */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_I48(tv,i) do { \ +#define DUK__TVAL_SET_I48(tv, i) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ - duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) DUK_TAG_FASTINT) << 16 | (((duk_uint32_t) ((i) >> 32)) & 0x0000ffffUL); \ + duk__tv->uiDUK_DBL_IDX_UI0 = \ + ((duk_uint32_t) DUK_TAG_FASTINT) << 16 | (((duk_uint32_t) ((i) >> 32)) & 0x0000ffffUL); \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (i); \ } while (0) -#define DUK__TVAL_SET_U32(tv,i) do { \ +#define DUK__TVAL_SET_U32(tv, i) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) DUK_TAG_FASTINT) << 16; \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (i); \ } while (0) #else -#define DUK__TVAL_SET_I48(tv,i) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & DUK_U64_CONSTANT(0x0000ffffffffffff)); \ +#define DUK__TVAL_SET_I48(tv, i) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = \ + (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & DUK_U64_CONSTANT(0x0000ffffffffffff)); \ } while (0) -#define DUK__TVAL_SET_U32(tv,i) do { \ +#define DUK__TVAL_SET_U32(tv, i) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (duk_uint64_t) (i); \ } while (0) #endif /* This needs to go through a cast because sign extension is needed. */ -#define DUK__TVAL_SET_I32(tv,i) do { \ +#define DUK__TVAL_SET_I32(tv, i) \ + do { \ duk_int64_t duk__tmp = (duk_int64_t) (i); \ DUK_TVAL_SET_I48((tv), duk__tmp); \ } while (0) /* XXX: Clumsy sign extend and masking of 16 topmost bits. */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_GET_FASTINT(tv) (((duk_int64_t) ((((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI1))) << 16 >> 16) +#define DUK__TVAL_GET_FASTINT(tv) \ + (((duk_int64_t) ((((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI1))) \ + << 16 >> \ + 16) #else -#define DUK__TVAL_GET_FASTINT(tv) ((((duk_int64_t) (tv)->ullDUK_DBL_IDX_ULL0) << 16) >> 16) +#define DUK__TVAL_GET_FASTINT(tv) ((((duk_int64_t) (tv)->ullDUK_DBL_IDX_ULL0) << 16) >> 16) #endif -#define DUK__TVAL_GET_FASTINT_U32(tv) ((tv)->uiDUK_DBL_IDX_UI1) -#define DUK__TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) (tv)->uiDUK_DBL_IDX_UI1) -#endif /* DUK_USE_FASTINT */ +#define DUK__TVAL_GET_FASTINT_U32(tv) ((tv)->uiDUK_DBL_IDX_UI1) +#define DUK__TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) (tv)->uiDUK_DBL_IDX_UI1) +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_UNDEFINED(tv) do { \ +#define DUK_TVAL_SET_UNDEFINED(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_UNDEFINED; \ } while (0) -#define DUK_TVAL_SET_UNUSED(tv) do { \ +#define DUK_TVAL_SET_UNUSED(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_UNUSED; \ } while (0) -#define DUK_TVAL_SET_NULL(tv) do { \ +#define DUK_TVAL_SET_NULL(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_NULL; \ } while (0) -#define DUK_TVAL_SET_BOOLEAN(tv,val) DUK_DBLUNION_SET_HIGH32((tv), (((duk_uint32_t) DUK_TAG_BOOLEAN) << 16) | ((duk_uint32_t) (val))) +#define DUK_TVAL_SET_BOOLEAN(tv, val) \ + DUK_DBLUNION_SET_HIGH32((tv), (((duk_uint32_t) DUK_TAG_BOOLEAN) << 16) | ((duk_uint32_t) (val))) -#define DUK_TVAL_SET_NAN(tv) DUK_DBLUNION_SET_NAN_FULL((tv)) +#define DUK_TVAL_SET_NAN(tv) DUK_DBLUNION_SET_NAN_FULL((tv)) /* Assumes that caller has normalized NaNs, otherwise trouble ahead. */ #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_DOUBLE(tv,d) do { \ +#define DUK_TVAL_SET_DOUBLE(tv, d) \ + do { \ duk_double_t duk__dblval; \ duk__dblval = (d); \ DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \ DUK_DBLUNION_SET_DOUBLE((tv), duk__dblval); \ } while (0) -#define DUK_TVAL_SET_I48(tv,i) DUK__TVAL_SET_I48((tv), (i)) -#define DUK_TVAL_SET_I32(tv,i) DUK__TVAL_SET_I32((tv), (i)) -#define DUK_TVAL_SET_U32(tv,i) DUK__TVAL_SET_U32((tv), (i)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) duk_tval_set_number_chkfast_fast((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) duk_tval_set_number_chkfast_slow((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { \ +#define DUK_TVAL_SET_I48(tv, i) DUK__TVAL_SET_I48((tv), (i)) +#define DUK_TVAL_SET_I32(tv, i) DUK__TVAL_SET_I32((tv), (i)) +#define DUK_TVAL_SET_U32(tv, i) DUK__TVAL_SET_U32((tv), (i)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) duk_tval_set_number_chkfast_fast((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) duk_tval_set_number_chkfast_slow((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -191,7 +210,8 @@ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(duk__tv, duk__d); \ } \ } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { \ +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -200,89 +220,98 @@ DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(duk__tv, duk__d); \ } \ } while (0) -#else /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_DOUBLE(tv,d) do { \ +#else /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_DOUBLE(tv, d) \ + do { \ duk_double_t duk__dblval; \ duk__dblval = (d); \ DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \ DUK_DBLUNION_SET_DOUBLE((tv), duk__dblval); \ } while (0) -#define DUK_TVAL_SET_I48(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_I32(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) -#define DUK_TVAL_SET_U32(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { } while (0) -#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_I48(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_I32(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) +#define DUK_TVAL_SET_U32(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ + } while (0) +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ + } while (0) +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT(tv,i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ +#define DUK_TVAL_SET_FASTINT(tv, i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ -#define DUK_TVAL_SET_LIGHTFUNC(tv,fp,flags) DUK__TVAL_SET_LIGHTFUNC((tv), (fp), (flags)) -#define DUK_TVAL_SET_STRING(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_STRING) -#define DUK_TVAL_SET_OBJECT(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_OBJECT) -#define DUK_TVAL_SET_BUFFER(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_BUFFER) -#define DUK_TVAL_SET_POINTER(tv,p) DUK__TVAL_SET_TAGGEDPOINTER((tv), (p), DUK_TAG_POINTER) +#define DUK_TVAL_SET_LIGHTFUNC(tv, fp, flags) DUK__TVAL_SET_LIGHTFUNC((tv), (fp), (flags)) +#define DUK_TVAL_SET_STRING(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_STRING) +#define DUK_TVAL_SET_OBJECT(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_OBJECT) +#define DUK_TVAL_SET_BUFFER(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_BUFFER) +#define DUK_TVAL_SET_POINTER(tv, p) DUK__TVAL_SET_TAGGEDPOINTER((tv), (p), DUK_TAG_POINTER) -#define DUK_TVAL_SET_TVAL(tv,x) do { *(tv) = *(x); } while (0) +#define DUK_TVAL_SET_TVAL(tv, x) \ + do { \ + *(tv) = *(x); \ + } while (0) /* getters */ -#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US1) +#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US1) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) -#define DUK_TVAL_GET_FASTINT(tv) DUK__TVAL_GET_FASTINT((tv)) -#define DUK_TVAL_GET_FASTINT_U32(tv) DUK__TVAL_GET_FASTINT_U32((tv)) -#define DUK_TVAL_GET_FASTINT_I32(tv) DUK__TVAL_GET_FASTINT_I32((tv)) -#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_packed((tv)) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) +#define DUK_TVAL_GET_FASTINT(tv) DUK__TVAL_GET_FASTINT((tv)) +#define DUK_TVAL_GET_FASTINT_U32(tv) DUK__TVAL_GET_FASTINT_U32((tv)) +#define DUK_TVAL_GET_FASTINT_I32(tv) DUK__TVAL_GET_FASTINT_I32((tv)) +#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_packed((tv)) #else -#define DUK_TVAL_GET_NUMBER(tv) ((tv)->d) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) +#define DUK_TVAL_GET_NUMBER(tv) ((tv)->d) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) #endif -#define DUK_TVAL_GET_LIGHTFUNC(tv,out_fp,out_flags) do { \ +#define DUK_TVAL_GET_LIGHTFUNC(tv, out_fp, out_flags) \ + do { \ (out_flags) = (tv)->uiDUK_DBL_IDX_UI0 & 0xffffUL; \ (out_fp) = (duk_c_function) (tv)->uiDUK_DBL_IDX_UI1; \ } while (0) -#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((duk_c_function) ((tv)->uiDUK_DBL_IDX_UI1)) -#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) (((duk_small_uint_t) (tv)->uiDUK_DBL_IDX_UI0) & 0xffffUL) -#define DUK_TVAL_GET_STRING(tv) ((duk_hstring *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_OBJECT(tv) ((duk_hobject *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_BUFFER(tv) ((duk_hbuffer *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_POINTER(tv) ((void *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_HEAPHDR(tv) ((duk_heaphdr *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((duk_c_function) ((tv)->uiDUK_DBL_IDX_UI1)) +#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) (((duk_small_uint_t) (tv)->uiDUK_DBL_IDX_UI0) & 0xffffUL) +#define DUK_TVAL_GET_STRING(tv) ((duk_hstring *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_OBJECT(tv) ((duk_hobject *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_BUFFER(tv) ((duk_hbuffer *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_POINTER(tv) ((void *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_HEAPHDR(tv) ((duk_heaphdr *) (tv)->vpDUK_DBL_IDX_VP1) /* decoding */ -#define DUK_TVAL_GET_TAG(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US0) - -#define DUK_TVAL_IS_UNDEFINED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNDEFINED) -#define DUK_TVAL_IS_UNUSED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNUSED) -#define DUK_TVAL_IS_NULL(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_NULL) -#define DUK_TVAL_IS_BOOLEAN(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BOOLEAN) -#define DUK_TVAL_IS_BOOLEAN_TRUE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_TRUE) -#define DUK_TVAL_IS_BOOLEAN_FALSE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_FALSE) -#define DUK_TVAL_IS_LIGHTFUNC(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_LIGHTFUNC) -#define DUK_TVAL_IS_STRING(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_STRING) -#define DUK_TVAL_IS_OBJECT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_OBJECT) -#define DUK_TVAL_IS_BUFFER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BUFFER) -#define DUK_TVAL_IS_POINTER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_POINTER) +#define DUK_TVAL_GET_TAG(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US0) + +#define DUK_TVAL_IS_UNDEFINED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNDEFINED) +#define DUK_TVAL_IS_UNUSED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNUSED) +#define DUK_TVAL_IS_NULL(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_NULL) +#define DUK_TVAL_IS_BOOLEAN(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BOOLEAN) +#define DUK_TVAL_IS_BOOLEAN_TRUE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_TRUE) +#define DUK_TVAL_IS_BOOLEAN_FALSE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_FALSE) +#define DUK_TVAL_IS_LIGHTFUNC(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_LIGHTFUNC) +#define DUK_TVAL_IS_STRING(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_STRING) +#define DUK_TVAL_IS_OBJECT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_OBJECT) +#define DUK_TVAL_IS_BUFFER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BUFFER) +#define DUK_TVAL_IS_POINTER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_POINTER) #if defined(DUK_USE_FASTINT) /* 0xfff0 is -Infinity */ -#define DUK_TVAL_IS_DOUBLE(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) -#define DUK_TVAL_IS_FASTINT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_FASTINT) -#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff1UL) +#define DUK_TVAL_IS_DOUBLE(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) +#define DUK_TVAL_IS_FASTINT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_FASTINT) +#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff1UL) #else -#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) -#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) +#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) +#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) #endif /* This is performance critical because it appears in every DECREF. */ -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) (DUK_TVAL_GET_TAG((tv)) >= DUK_TAG_STRING) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) (DUK_TVAL_GET_TAG((tv)) >= DUK_TAG_STRING) #if defined(DUK_USE_FASTINT) DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_packed(duk_tval *tv); #endif -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ /* ======================================================================== */ /* @@ -306,7 +335,7 @@ duk_double_t d; duk_small_int_t i; #if defined(DUK_USE_FASTINT) - duk_int64_t fi; /* if present, forces 16-byte duk_tval */ + duk_int64_t fi; /* if present, forces 16-byte duk_tval */ #endif void *voidptr; duk_hstring *hstring; @@ -334,24 +363,23 @@ #define DUK_TVAL_UNUSED_INITIALIZER() \ { DUK_TAG_UNUSED, 0, 0.0 } -#define DUK_TAG_MIN 0 -#define DUK_TAG_NUMBER 0 /* DUK_TAG_NUMBER only defined for non-packed duk_tval */ +#define DUK_TAG_MIN 0 +#define DUK_TAG_NUMBER 0 /* DUK_TAG_NUMBER only defined for non-packed duk_tval */ #if defined(DUK_USE_FASTINT) -#define DUK_TAG_FASTINT 1 +#define DUK_TAG_FASTINT 1 #endif -#define DUK_TAG_UNDEFINED 2 -#define DUK_TAG_NULL 3 -#define DUK_TAG_BOOLEAN 4 -#define DUK_TAG_POINTER 5 -#define DUK_TAG_LIGHTFUNC 6 -#define DUK_TAG_UNUSED 7 /* marker; not actual tagged type */ -#define DUK_TAG_STRING 8 /* first heap allocated, match bit boundary */ -#define DUK_TAG_OBJECT 9 -#define DUK_TAG_BUFFER 10 -#define DUK_TAG_MAX 10 - -#define DUK_TVAL_IS_VALID_TAG(tv) \ - (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) +#define DUK_TAG_UNDEFINED 2 +#define DUK_TAG_NULL 3 +#define DUK_TAG_BOOLEAN 4 +#define DUK_TAG_POINTER 5 +#define DUK_TAG_LIGHTFUNC 6 +#define DUK_TAG_UNUSED 7 /* marker; not actual tagged type */ +#define DUK_TAG_STRING 8 /* first heap allocated, match bit boundary */ +#define DUK_TAG_OBJECT 9 +#define DUK_TAG_BUFFER 10 +#define DUK_TAG_MAX 10 + +#define DUK_TVAL_IS_VALID_TAG(tv) (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) /* DUK_TAG_NUMBER is intentionally first, as it is the default clause in code * to support the 8-byte representation. Further, it is a non-heap-allocated @@ -360,25 +388,29 @@ */ /* setters */ -#define DUK_TVAL_SET_UNDEFINED(tv) do { \ +#define DUK_TVAL_SET_UNDEFINED(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_UNDEFINED; \ } while (0) -#define DUK_TVAL_SET_UNUSED(tv) do { \ +#define DUK_TVAL_SET_UNUSED(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_UNUSED; \ } while (0) -#define DUK_TVAL_SET_NULL(tv) do { \ +#define DUK_TVAL_SET_NULL(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_NULL; \ } while (0) -#define DUK_TVAL_SET_BOOLEAN(tv,val) do { \ +#define DUK_TVAL_SET_BOOLEAN(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_BOOLEAN; \ @@ -386,7 +418,8 @@ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_DOUBLE(tv,val) do { \ +#define DUK_TVAL_SET_DOUBLE(tv, val) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__dblval; \ duk__dblval = (val); \ @@ -395,31 +428,32 @@ duk__tv->t = DUK_TAG_NUMBER; \ duk__tv->v.d = duk__dblval; \ } while (0) -#define DUK_TVAL_SET_I48(tv,val) do { \ +#define DUK_TVAL_SET_I48(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (val); \ } while (0) -#define DUK_TVAL_SET_U32(tv,val) do { \ +#define DUK_TVAL_SET_U32(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (duk_int64_t) (val); \ } while (0) -#define DUK_TVAL_SET_I32(tv,val) do { \ +#define DUK_TVAL_SET_I32(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (duk_int64_t) (val); \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) \ - duk_tval_set_number_chkfast_fast((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) \ - duk_tval_set_number_chkfast_slow((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,val) \ - DUK_TVAL_SET_DOUBLE((tv), (val)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) duk_tval_set_number_chkfast_fast((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) duk_tval_set_number_chkfast_slow((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, val) DUK_TVAL_SET_DOUBLE((tv), (val)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -428,7 +462,8 @@ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(duk__tv, duk__d); \ } \ } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { \ +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -437,16 +472,13 @@ DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(duk__tv, duk__d); \ } \ } while (0) -#else /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_DOUBLE(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_SET_I48(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_U32(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) -#define DUK_TVAL_SET_I32(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) -#define DUK_TVAL_SET_NUMBER(tv,val) do { \ +#else /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_DOUBLE(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_SET_I48(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_U32(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) +#define DUK_TVAL_SET_I32(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) +#define DUK_TVAL_SET_NUMBER(tv, val) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__dblval; \ duk__dblval = (val); \ @@ -455,25 +487,28 @@ duk__tv->t = DUK_TAG_NUMBER; \ duk__tv->v.d = duk__dblval; \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { } while (0) -#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ + } while (0) +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ + } while (0) +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT(tv,i) \ - DUK_TVAL_SET_I48((tv), (i)) /* alias */ +#define DUK_TVAL_SET_FASTINT(tv, i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ -#define DUK_TVAL_SET_POINTER(tv,hptr) do { \ +#define DUK_TVAL_SET_POINTER(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_POINTER; \ duk__tv->v.voidptr = (hptr); \ } while (0) -#define DUK_TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ +#define DUK_TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_LIGHTFUNC; \ @@ -481,28 +516,32 @@ duk__tv->v.lightfunc = (duk_c_function) (fp); \ } while (0) -#define DUK_TVAL_SET_STRING(tv,hptr) do { \ +#define DUK_TVAL_SET_STRING(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_STRING; \ duk__tv->v.hstring = (hptr); \ } while (0) -#define DUK_TVAL_SET_OBJECT(tv,hptr) do { \ +#define DUK_TVAL_SET_OBJECT(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_OBJECT; \ duk__tv->v.hobject = (hptr); \ } while (0) -#define DUK_TVAL_SET_BUFFER(tv,hptr) do { \ +#define DUK_TVAL_SET_BUFFER(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_BUFFER; \ duk__tv->v.hbuffer = (hptr); \ } while (0) -#define DUK_TVAL_SET_NAN(tv) do { \ +#define DUK_TVAL_SET_NAN(tv) \ + do { \ /* in non-packed representation we don't care about which NaN is used */ \ duk_tval *duk__tv; \ duk__tv = (tv); \ @@ -510,32 +549,32 @@ duk__tv->v.d = DUK_DOUBLE_NAN; \ } while (0) -#define DUK_TVAL_SET_TVAL(tv,x) do { *(tv) = *(x); } while (0) +#define DUK_TVAL_SET_TVAL(tv, x) \ + do { \ + *(tv) = *(x); \ + } while (0) /* getters */ -#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->v.i) +#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->v.i) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) -#define DUK_TVAL_GET_FASTINT(tv) ((tv)->v.fi) -#define DUK_TVAL_GET_FASTINT_U32(tv) ((duk_uint32_t) ((tv)->v.fi)) -#define DUK_TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) ((tv)->v.fi)) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) +#define DUK_TVAL_GET_FASTINT(tv) ((tv)->v.fi) +#define DUK_TVAL_GET_FASTINT_U32(tv) ((duk_uint32_t) ((tv)->v.fi)) +#define DUK_TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) ((tv)->v.fi)) #if 0 -#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? \ - (duk_double_t) DUK_TVAL_GET_FASTINT((tv)) : \ - DUK_TVAL_GET_DOUBLE((tv))) -#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_unpacked((tv)) +#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? (duk_double_t) DUK_TVAL_GET_FASTINT((tv)) : DUK_TVAL_GET_DOUBLE((tv))) +#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_unpacked((tv)) #else /* This seems reasonable overall. */ -#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? \ - duk_tval_get_number_unpacked_fastint((tv)) : \ - DUK_TVAL_GET_DOUBLE((tv))) +#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? duk_tval_get_number_unpacked_fastint((tv)) : DUK_TVAL_GET_DOUBLE((tv))) #endif #else -#define DUK_TVAL_GET_NUMBER(tv) ((tv)->v.d) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_GET_POINTER(tv) ((tv)->v.voidptr) -#define DUK_TVAL_GET_LIGHTFUNC(tv,out_fp,out_flags) do { \ +#define DUK_TVAL_GET_NUMBER(tv) ((tv)->v.d) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_GET_POINTER(tv) ((tv)->v.voidptr) +#define DUK_TVAL_GET_LIGHTFUNC(tv, out_fp, out_flags) \ + do { \ (out_flags) = (duk_uint32_t) (tv)->v_extra; \ (out_fp) = (tv)->v.lightfunc; \ } while (0) @@ -555,19 +594,18 @@ #define DUK_TVAL_IS_BOOLEAN_TRUE(tv) (((tv)->t == DUK_TAG_BOOLEAN) && ((tv)->v.i != 0)) #define DUK_TVAL_IS_BOOLEAN_FALSE(tv) (((tv)->t == DUK_TAG_BOOLEAN) && ((tv)->v.i == 0)) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_IS_DOUBLE(tv) ((tv)->t == DUK_TAG_NUMBER) -#define DUK_TVAL_IS_FASTINT(tv) ((tv)->t == DUK_TAG_FASTINT) -#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER || \ - (tv)->t == DUK_TAG_FASTINT) +#define DUK_TVAL_IS_DOUBLE(tv) ((tv)->t == DUK_TAG_NUMBER) +#define DUK_TVAL_IS_FASTINT(tv) ((tv)->t == DUK_TAG_FASTINT) +#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER || (tv)->t == DUK_TAG_FASTINT) #else -#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER) -#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_IS_POINTER(tv) ((tv)->t == DUK_TAG_POINTER) -#define DUK_TVAL_IS_LIGHTFUNC(tv) ((tv)->t == DUK_TAG_LIGHTFUNC) -#define DUK_TVAL_IS_STRING(tv) ((tv)->t == DUK_TAG_STRING) -#define DUK_TVAL_IS_OBJECT(tv) ((tv)->t == DUK_TAG_OBJECT) -#define DUK_TVAL_IS_BUFFER(tv) ((tv)->t == DUK_TAG_BUFFER) +#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER) +#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_IS_POINTER(tv) ((tv)->t == DUK_TAG_POINTER) +#define DUK_TVAL_IS_LIGHTFUNC(tv) ((tv)->t == DUK_TAG_LIGHTFUNC) +#define DUK_TVAL_IS_STRING(tv) ((tv)->t == DUK_TAG_STRING) +#define DUK_TVAL_IS_OBJECT(tv) ((tv)->t == DUK_TAG_OBJECT) +#define DUK_TVAL_IS_BUFFER(tv) ((tv)->t == DUK_TAG_BUFFER) /* This is performance critical because it's needed for every DECREF. * Take advantage of the fact that the first heap allocated tag is 8, @@ -575,9 +613,9 @@ * non-heap-allocated tags). */ #if 0 -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t >= DUK_TAG_STRING) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t >= DUK_TAG_STRING) #endif -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t & 0x08) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t & 0x08) #if defined(DUK_USE_FASTINT) #if 0 @@ -586,44 +624,39 @@ DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_unpacked_fastint(duk_tval *tv); #endif -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ /* * Convenience (independent of representation) */ -#define DUK_TVAL_SET_BOOLEAN_TRUE(tv) DUK_TVAL_SET_BOOLEAN((tv), 1) -#define DUK_TVAL_SET_BOOLEAN_FALSE(tv) DUK_TVAL_SET_BOOLEAN((tv), 0) +#define DUK_TVAL_SET_BOOLEAN_TRUE(tv) DUK_TVAL_SET_BOOLEAN((tv), 1) +#define DUK_TVAL_SET_BOOLEAN_FALSE(tv) DUK_TVAL_SET_BOOLEAN((tv), 0) -#define DUK_TVAL_STRING_IS_SYMBOL(tv) \ - DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING((tv))) +#define DUK_TVAL_STRING_IS_SYMBOL(tv) DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING((tv))) /* Lightfunc flags packing and unpacking. */ /* Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss##. * Avoid signed shifts due to portability limitations. */ -#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags) \ - ((duk_int32_t) (duk_int8_t) (((duk_uint16_t) (lf_flags)) >> 8)) -#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags) \ - (((lf_flags) >> 4) & 0x0fU) -#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags) \ - ((lf_flags) & 0x0fU) -#define DUK_LFUNC_FLAGS_PACK(magic,length,nargs) \ - ((((duk_small_uint_t) (magic)) & 0xffU) << 8) | ((length) << 4) | (nargs) - -#define DUK_LFUNC_NARGS_VARARGS 0x0f /* varargs marker */ -#define DUK_LFUNC_NARGS_MIN 0x00 -#define DUK_LFUNC_NARGS_MAX 0x0e /* max, excl. varargs marker */ -#define DUK_LFUNC_LENGTH_MIN 0x00 -#define DUK_LFUNC_LENGTH_MAX 0x0f -#define DUK_LFUNC_MAGIC_MIN (-0x80) -#define DUK_LFUNC_MAGIC_MAX 0x7f +#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags) ((duk_int32_t) (duk_int8_t) (((duk_uint16_t) (lf_flags)) >> 8)) +#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags) (((lf_flags) >> 4) & 0x0fU) +#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags) ((lf_flags) &0x0fU) +#define DUK_LFUNC_FLAGS_PACK(magic, length, nargs) ((((duk_small_uint_t) (magic)) & 0xffU) << 8) | ((length) << 4) | (nargs) + +#define DUK_LFUNC_NARGS_VARARGS 0x0f /* varargs marker */ +#define DUK_LFUNC_NARGS_MIN 0x00 +#define DUK_LFUNC_NARGS_MAX 0x0e /* max, excl. varargs marker */ +#define DUK_LFUNC_LENGTH_MIN 0x00 +#define DUK_LFUNC_LENGTH_MAX 0x0f +#define DUK_LFUNC_MAGIC_MIN (-0x80) +#define DUK_LFUNC_MAGIC_MAX 0x7f /* fastint constants etc */ #if defined(DUK_USE_FASTINT) -#define DUK_FASTINT_MIN (DUK_I64_CONSTANT(-0x800000000000)) -#define DUK_FASTINT_MAX (DUK_I64_CONSTANT(0x7fffffffffff)) -#define DUK_FASTINT_BITS 48 +#define DUK_FASTINT_MIN (DUK_I64_CONSTANT(-0x800000000000)) +#define DUK_FASTINT_MAX (DUK_I64_CONSTANT(0x7fffffffffff)) +#define DUK_FASTINT_BITS 48 DUK_INTERNAL_DECL void duk_tval_set_number_chkfast_fast(duk_tval *tv, duk_double_t x); DUK_INTERNAL_DECL void duk_tval_set_number_chkfast_slow(duk_tval *tv, duk_double_t x); @@ -631,9 +664,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_tval_assert_valid(duk_tval *tv); -#define DUK_TVAL_ASSERT_VALID(tv) do { duk_tval_assert_valid((tv)); } while (0) +#define DUK_TVAL_ASSERT_VALID(tv) \ + do { \ + duk_tval_assert_valid((tv)); \ + } while (0) #else -#define DUK_TVAL_ASSERT_VALID(tv) do {} while (0) +#define DUK_TVAL_ASSERT_VALID(tv) \ + do { \ + } while (0) #endif -#endif /* DUK_TVAL_H_INCLUDED */ +#endif /* DUK_TVAL_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_unicode.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_unicode.h
Changed
@@ -9,10 +9,10 @@ * UTF-8 / XUTF-8 / CESU-8 constants */ -#define DUK_UNICODE_MAX_XUTF8_LENGTH 7 /* up to 36 bit codepoints */ -#define DUK_UNICODE_MAX_XUTF8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ -#define DUK_UNICODE_MAX_CESU8_LENGTH 6 /* all codepoints up to U+10FFFF */ -#define DUK_UNICODE_MAX_CESU8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ +#define DUK_UNICODE_MAX_XUTF8_LENGTH 7 /* up to 36 bit codepoints */ +#define DUK_UNICODE_MAX_XUTF8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ +#define DUK_UNICODE_MAX_CESU8_LENGTH 6 /* all codepoints up to U+10FFFF */ +#define DUK_UNICODE_MAX_CESU8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ /* * Useful Unicode codepoints @@ -21,9 +21,11 @@ * in comparisons. */ -#define DUK_UNICODE_CP_ZWNJ 0x200cL /* zero-width non-joiner */ -#define DUK_UNICODE_CP_ZWJ 0x200dL /* zero-width joiner */ -#define DUK_UNICODE_CP_REPLACEMENT_CHARACTER 0xfffdL /* http://en.wikipedia.org/wiki/Replacement_character#Replacement_character */ +#define DUK_UNICODE_CP_ZWNJ 0x200cL /* zero-width non-joiner */ +#define DUK_UNICODE_CP_ZWJ 0x200dL /* zero-width joiner */ +#define DUK_UNICODE_CP_REPLACEMENT_CHARACTER \ + 0xfffdL /* http://en.wikipedia.org/wiki/Replacement_character#Replacement_character \ + */ /* * ASCII character constants @@ -36,134 +38,134 @@ * http://en.wikipedia.org/wiki/ASCII */ -#define DUK_ASC_NUL 0x00 -#define DUK_ASC_SOH 0x01 -#define DUK_ASC_STX 0x02 -#define DUK_ASC_ETX 0x03 -#define DUK_ASC_EOT 0x04 -#define DUK_ASC_ENQ 0x05 -#define DUK_ASC_ACK 0x06 -#define DUK_ASC_BEL 0x07 -#define DUK_ASC_BS 0x08 -#define DUK_ASC_HT 0x09 -#define DUK_ASC_LF 0x0a -#define DUK_ASC_VT 0x0b -#define DUK_ASC_FF 0x0c -#define DUK_ASC_CR 0x0d -#define DUK_ASC_SO 0x0e -#define DUK_ASC_SI 0x0f -#define DUK_ASC_DLE 0x10 -#define DUK_ASC_DC1 0x11 -#define DUK_ASC_DC2 0x12 -#define DUK_ASC_DC3 0x13 -#define DUK_ASC_DC4 0x14 -#define DUK_ASC_NAK 0x15 -#define DUK_ASC_SYN 0x16 -#define DUK_ASC_ETB 0x17 -#define DUK_ASC_CAN 0x18 -#define DUK_ASC_EM 0x19 -#define DUK_ASC_SUB 0x1a -#define DUK_ASC_ESC 0x1b -#define DUK_ASC_FS 0x1c -#define DUK_ASC_GS 0x1d -#define DUK_ASC_RS 0x1e -#define DUK_ASC_US 0x1f -#define DUK_ASC_SPACE 0x20 -#define DUK_ASC_EXCLAMATION 0x21 -#define DUK_ASC_DOUBLEQUOTE 0x22 -#define DUK_ASC_HASH 0x23 -#define DUK_ASC_DOLLAR 0x24 -#define DUK_ASC_PERCENT 0x25 -#define DUK_ASC_AMP 0x26 -#define DUK_ASC_SINGLEQUOTE 0x27 -#define DUK_ASC_LPAREN 0x28 -#define DUK_ASC_RPAREN 0x29 -#define DUK_ASC_STAR 0x2a -#define DUK_ASC_PLUS 0x2b -#define DUK_ASC_COMMA 0x2c -#define DUK_ASC_MINUS 0x2d -#define DUK_ASC_PERIOD 0x2e -#define DUK_ASC_SLASH 0x2f -#define DUK_ASC_0 0x30 -#define DUK_ASC_1 0x31 -#define DUK_ASC_2 0x32 -#define DUK_ASC_3 0x33 -#define DUK_ASC_4 0x34 -#define DUK_ASC_5 0x35 -#define DUK_ASC_6 0x36 -#define DUK_ASC_7 0x37 -#define DUK_ASC_8 0x38 -#define DUK_ASC_9 0x39 -#define DUK_ASC_COLON 0x3a -#define DUK_ASC_SEMICOLON 0x3b -#define DUK_ASC_LANGLE 0x3c -#define DUK_ASC_EQUALS 0x3d -#define DUK_ASC_RANGLE 0x3e -#define DUK_ASC_QUESTION 0x3f -#define DUK_ASC_ATSIGN 0x40 -#define DUK_ASC_UC_A 0x41 -#define DUK_ASC_UC_B 0x42 -#define DUK_ASC_UC_C 0x43 -#define DUK_ASC_UC_D 0x44 -#define DUK_ASC_UC_E 0x45 -#define DUK_ASC_UC_F 0x46 -#define DUK_ASC_UC_G 0x47 -#define DUK_ASC_UC_H 0x48 -#define DUK_ASC_UC_I 0x49 -#define DUK_ASC_UC_J 0x4a -#define DUK_ASC_UC_K 0x4b -#define DUK_ASC_UC_L 0x4c -#define DUK_ASC_UC_M 0x4d -#define DUK_ASC_UC_N 0x4e -#define DUK_ASC_UC_O 0x4f -#define DUK_ASC_UC_P 0x50 -#define DUK_ASC_UC_Q 0x51 -#define DUK_ASC_UC_R 0x52 -#define DUK_ASC_UC_S 0x53 -#define DUK_ASC_UC_T 0x54 -#define DUK_ASC_UC_U 0x55 -#define DUK_ASC_UC_V 0x56 -#define DUK_ASC_UC_W 0x57 -#define DUK_ASC_UC_X 0x58 -#define DUK_ASC_UC_Y 0x59 -#define DUK_ASC_UC_Z 0x5a -#define DUK_ASC_LBRACKET 0x5b -#define DUK_ASC_BACKSLASH 0x5c -#define DUK_ASC_RBRACKET 0x5d -#define DUK_ASC_CARET 0x5e -#define DUK_ASC_UNDERSCORE 0x5f -#define DUK_ASC_GRAVE 0x60 -#define DUK_ASC_LC_A 0x61 -#define DUK_ASC_LC_B 0x62 -#define DUK_ASC_LC_C 0x63 -#define DUK_ASC_LC_D 0x64 -#define DUK_ASC_LC_E 0x65 -#define DUK_ASC_LC_F 0x66 -#define DUK_ASC_LC_G 0x67 -#define DUK_ASC_LC_H 0x68 -#define DUK_ASC_LC_I 0x69 -#define DUK_ASC_LC_J 0x6a -#define DUK_ASC_LC_K 0x6b -#define DUK_ASC_LC_L 0x6c -#define DUK_ASC_LC_M 0x6d -#define DUK_ASC_LC_N 0x6e -#define DUK_ASC_LC_O 0x6f -#define DUK_ASC_LC_P 0x70 -#define DUK_ASC_LC_Q 0x71 -#define DUK_ASC_LC_R 0x72 -#define DUK_ASC_LC_S 0x73 -#define DUK_ASC_LC_T 0x74 -#define DUK_ASC_LC_U 0x75 -#define DUK_ASC_LC_V 0x76 -#define DUK_ASC_LC_W 0x77 -#define DUK_ASC_LC_X 0x78 -#define DUK_ASC_LC_Y 0x79 -#define DUK_ASC_LC_Z 0x7a -#define DUK_ASC_LCURLY 0x7b -#define DUK_ASC_PIPE 0x7c -#define DUK_ASC_RCURLY 0x7d -#define DUK_ASC_TILDE 0x7e -#define DUK_ASC_DEL 0x7f +#define DUK_ASC_NUL 0x00 +#define DUK_ASC_SOH 0x01 +#define DUK_ASC_STX 0x02 +#define DUK_ASC_ETX 0x03 +#define DUK_ASC_EOT 0x04 +#define DUK_ASC_ENQ 0x05 +#define DUK_ASC_ACK 0x06 +#define DUK_ASC_BEL 0x07 +#define DUK_ASC_BS 0x08 +#define DUK_ASC_HT 0x09 +#define DUK_ASC_LF 0x0a +#define DUK_ASC_VT 0x0b +#define DUK_ASC_FF 0x0c +#define DUK_ASC_CR 0x0d +#define DUK_ASC_SO 0x0e +#define DUK_ASC_SI 0x0f +#define DUK_ASC_DLE 0x10 +#define DUK_ASC_DC1 0x11 +#define DUK_ASC_DC2 0x12 +#define DUK_ASC_DC3 0x13 +#define DUK_ASC_DC4 0x14 +#define DUK_ASC_NAK 0x15 +#define DUK_ASC_SYN 0x16 +#define DUK_ASC_ETB 0x17 +#define DUK_ASC_CAN 0x18 +#define DUK_ASC_EM 0x19 +#define DUK_ASC_SUB 0x1a +#define DUK_ASC_ESC 0x1b +#define DUK_ASC_FS 0x1c +#define DUK_ASC_GS 0x1d +#define DUK_ASC_RS 0x1e +#define DUK_ASC_US 0x1f +#define DUK_ASC_SPACE 0x20 +#define DUK_ASC_EXCLAMATION 0x21 +#define DUK_ASC_DOUBLEQUOTE 0x22 +#define DUK_ASC_HASH 0x23 +#define DUK_ASC_DOLLAR 0x24 +#define DUK_ASC_PERCENT 0x25 +#define DUK_ASC_AMP 0x26 +#define DUK_ASC_SINGLEQUOTE 0x27 +#define DUK_ASC_LPAREN 0x28 +#define DUK_ASC_RPAREN 0x29 +#define DUK_ASC_STAR 0x2a +#define DUK_ASC_PLUS 0x2b +#define DUK_ASC_COMMA 0x2c +#define DUK_ASC_MINUS 0x2d +#define DUK_ASC_PERIOD 0x2e +#define DUK_ASC_SLASH 0x2f +#define DUK_ASC_0 0x30 +#define DUK_ASC_1 0x31 +#define DUK_ASC_2 0x32 +#define DUK_ASC_3 0x33 +#define DUK_ASC_4 0x34 +#define DUK_ASC_5 0x35 +#define DUK_ASC_6 0x36 +#define DUK_ASC_7 0x37 +#define DUK_ASC_8 0x38 +#define DUK_ASC_9 0x39 +#define DUK_ASC_COLON 0x3a +#define DUK_ASC_SEMICOLON 0x3b +#define DUK_ASC_LANGLE 0x3c +#define DUK_ASC_EQUALS 0x3d +#define DUK_ASC_RANGLE 0x3e +#define DUK_ASC_QUESTION 0x3f +#define DUK_ASC_ATSIGN 0x40 +#define DUK_ASC_UC_A 0x41 +#define DUK_ASC_UC_B 0x42 +#define DUK_ASC_UC_C 0x43 +#define DUK_ASC_UC_D 0x44 +#define DUK_ASC_UC_E 0x45 +#define DUK_ASC_UC_F 0x46 +#define DUK_ASC_UC_G 0x47 +#define DUK_ASC_UC_H 0x48 +#define DUK_ASC_UC_I 0x49 +#define DUK_ASC_UC_J 0x4a +#define DUK_ASC_UC_K 0x4b +#define DUK_ASC_UC_L 0x4c +#define DUK_ASC_UC_M 0x4d +#define DUK_ASC_UC_N 0x4e +#define DUK_ASC_UC_O 0x4f +#define DUK_ASC_UC_P 0x50 +#define DUK_ASC_UC_Q 0x51 +#define DUK_ASC_UC_R 0x52 +#define DUK_ASC_UC_S 0x53 +#define DUK_ASC_UC_T 0x54 +#define DUK_ASC_UC_U 0x55 +#define DUK_ASC_UC_V 0x56 +#define DUK_ASC_UC_W 0x57 +#define DUK_ASC_UC_X 0x58 +#define DUK_ASC_UC_Y 0x59 +#define DUK_ASC_UC_Z 0x5a +#define DUK_ASC_LBRACKET 0x5b +#define DUK_ASC_BACKSLASH 0x5c +#define DUK_ASC_RBRACKET 0x5d +#define DUK_ASC_CARET 0x5e +#define DUK_ASC_UNDERSCORE 0x5f +#define DUK_ASC_GRAVE 0x60 +#define DUK_ASC_LC_A 0x61 +#define DUK_ASC_LC_B 0x62 +#define DUK_ASC_LC_C 0x63 +#define DUK_ASC_LC_D 0x64 +#define DUK_ASC_LC_E 0x65 +#define DUK_ASC_LC_F 0x66 +#define DUK_ASC_LC_G 0x67 +#define DUK_ASC_LC_H 0x68 +#define DUK_ASC_LC_I 0x69 +#define DUK_ASC_LC_J 0x6a +#define DUK_ASC_LC_K 0x6b +#define DUK_ASC_LC_L 0x6c +#define DUK_ASC_LC_M 0x6d +#define DUK_ASC_LC_N 0x6e +#define DUK_ASC_LC_O 0x6f +#define DUK_ASC_LC_P 0x70 +#define DUK_ASC_LC_Q 0x71 +#define DUK_ASC_LC_R 0x72 +#define DUK_ASC_LC_S 0x73 +#define DUK_ASC_LC_T 0x74 +#define DUK_ASC_LC_U 0x75 +#define DUK_ASC_LC_V 0x76 +#define DUK_ASC_LC_W 0x77 +#define DUK_ASC_LC_X 0x78 +#define DUK_ASC_LC_Y 0x79 +#define DUK_ASC_LC_Z 0x7a +#define DUK_ASC_LCURLY 0x7b +#define DUK_ASC_PIPE 0x7c +#define DUK_ASC_RCURLY 0x7d +#define DUK_ASC_TILDE 0x7e +#define DUK_ASC_DEL 0x7f /* * Miscellaneous @@ -172,7 +174,7 @@ /* Uppercase A is 0x41, lowercase a is 0x61; OR 0x20 to convert uppercase * to lowercase. */ -#define DUK_LOWERCASE_CHAR_ASCII(x) ((x) | 0x20) +#define DUK_LOWERCASE_CHAR_ASCII(x) ((x) | 0x20) /* * Unicode tables @@ -260,7 +262,7 @@ DUK_INTERNAL_DECL const duk_uint16_t duk_unicode_re_ranges_not_white24; DUK_INTERNAL_DECL const duk_uint16_t duk_unicode_re_ranges_not_wordchar10; DUK_INTERNAL_DECL const duk_int8_t duk_is_idchar_tab128; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* * Prototypes @@ -272,8 +274,15 @@ #endif DUK_INTERNAL_DECL duk_small_int_t duk_unicode_encode_xutf8(duk_ucodepoint_t cp, duk_uint8_t *out); DUK_INTERNAL_DECL duk_small_int_t duk_unicode_encode_cesu8(duk_ucodepoint_t cp, duk_uint8_t *out); -DUK_INTERNAL_DECL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_ucodepoint_t *out_cp); -DUK_INTERNAL_DECL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end); +DUK_INTERNAL_DECL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_ucodepoint_t *out_cp); +DUK_INTERNAL_DECL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end); DUK_INTERNAL_DECL duk_size_t duk_unicode_unvalidated_utf8_length(const duk_uint8_t *data, duk_size_t blen); DUK_INTERNAL_DECL duk_bool_t duk_unicode_is_utf8_compatible(const duk_uint8_t *buf, duk_size_t len); DUK_INTERNAL_DECL duk_small_int_t duk_unicode_is_whitespace(duk_codepoint_t cp); @@ -287,4 +296,4 @@ DUK_INTERNAL_DECL duk_small_int_t duk_unicode_re_is_wordchar(duk_codepoint_t cp); #endif -#endif /* DUK_UNICODE_H_INCLUDED */ +#endif /* DUK_UNICODE_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_unicode_support.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_unicode_support.c
Changed
@@ -15,14 +15,14 @@ * 1: IdentifierStart and IdentifierPart * -1: IdentifierPart only */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00...0x0f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10...0x1f */ - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20...0x2f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, /* 0x30...0x3f */ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40...0x4f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50...0x5f */ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60...0x6f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70...0x7f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00...0x0f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10...0x1f */ + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20...0x2f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, /* 0x30...0x3f */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40...0x4f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50...0x5f */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60...0x6f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70...0x7f */ }; #endif @@ -72,15 +72,13 @@ /* Encoded as surrogate pair, each encoding to 3 bytes for * 6 bytes total. Codepoints above U+10FFFF encode as 6 bytes * too, see duk_unicode_encode_cesu8(). - */ + */ return 3 + 3; } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ -DUK_INTERNAL const duk_uint8_t duk_unicode_xutf8_markers7 = { - 0x00, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe -}; +DUK_INTERNAL const duk_uint8_t duk_unicode_xutf8_markers7 = { 0x00, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe }; /* Encode to extended UTF-8; 'out' must have space for at least * DUK_UNICODE_MAX_XUTF8_LENGTH bytes. Allows encoding of any @@ -95,7 +93,7 @@ len = duk_unicode_get_xutf8_length(cp); DUK_ASSERT(len > 0); - marker = duk_unicode_xutf8_markerslen - 1; /* 64-bit OK because always >= 0 */ + marker = duk_unicode_xutf8_markerslen - 1; /* 64-bit OK because always >= 0 */ i = len; DUK_ASSERT(i > 0); @@ -180,7 +178,11 @@ } /* Decode helper. Return zero on error. */ -DUK_INTERNAL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_ucodepoint_t *out_cp) { +DUK_INTERNAL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_ucodepoint_t *out_cp) { const duk_uint8_t *p; duk_uint32_t res; duk_uint_fast8_t ch; @@ -242,7 +244,7 @@ goto fail; } - DUK_ASSERT(p >= ptr_start); /* verified at beginning */ + DUK_ASSERT(p >= ptr_start); /* verified at beginning */ if (p + n > ptr_end) { /* check pointer at end */ goto fail; @@ -268,12 +270,15 @@ *out_cp = res; return 1; - fail: +fail: return 0; } /* used by e.g. duk_regexp_executor.c, string built-ins */ -DUK_INTERNAL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end) { +DUK_INTERNAL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end) { duk_ucodepoint_t cp; if (duk_unicode_decode_xutf8(thr, ptr, ptr_start, ptr_end, &cp)) { @@ -320,7 +325,7 @@ DUK_ASSERT(clen <= blen); return clen; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* This seems like a good overall approach. Fast path for ASCII in 4 byte * blocks. */ @@ -332,7 +337,7 @@ duk_size_t ncont; duk_size_t clen; - ncont = 0; /* number of continuation (non-initial) bytes in 0x80,0xbf */ + ncont = 0; /* number of continuation (non-initial) bytes in 0x80,0xbf */ p = data; p_end = data + blen; if (blen < 16) { @@ -357,7 +362,7 @@ duk_uint32_t x; x = *p32++; if (DUK_LIKELY((x & 0x80808080UL) == 0)) { - ; /* ASCII fast path */ + ; /* ASCII fast path */ } else { /* Flip highest bit of each byte which changes * the bit pattern 10xxxxxx into 00xxxxxx which @@ -381,7 +386,7 @@ p = (const duk_uint8_t *) p32; /* Fall through to handle the rest. */ - skip_fastpath: +skip_fastpath: while (p != p_end) { duk_uint8_t x; x = *p++; @@ -395,7 +400,7 @@ DUK_ASSERT(clen <= blen); return clen; } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Check whether a string is UTF-8 compatible or not. */ DUK_INTERNAL duk_bool_t duk_unicode_is_utf8_compatible(const duk_uint8_t *buf, duk_size_t len) { @@ -444,18 +449,18 @@ * 1111 0xxx + 3*CONT -> 0x10000, 0x10ffff */ left = len - i; - if (t <= 0xdfU) { /* 1101 1111 = 0xdf */ - if (t <= 0xbfU) { /* 1011 1111 = 0xbf */ + if (t <= 0xdfU) { /* 1101 1111 = 0xdf */ + if (t <= 0xbfU) { /* 1011 1111 = 0xbf */ return 0; } ncont = 1; mincp = 0x80UL; cp = t & 0x1fU; - } else if (t <= 0xefU) { /* 1110 1111 = 0xef */ + } else if (t <= 0xefU) { /* 1110 1111 = 0xef */ ncont = 2; mincp = 0x800UL; cp = t & 0x0fU; - } else if (t <= 0xf7U) { /* 1111 0111 = 0xf7 */ + } else if (t <= 0xf7U) { /* 1111 0111 = 0xf7 */ ncont = 3; mincp = 0x10000UL; cp = t & 0x07U; @@ -467,7 +472,7 @@ } while (ncont > 0U) { t = bufi++; - if ((t & 0xc0U) != 0x80U) { /* 10xx xxxx */ + if ((t & 0xc0U) != 0x80U) { /* 10xx xxxx */ return 0; } cp = (cp << 6) + (t & 0x3fU); @@ -533,7 +538,9 @@ /* r1,r2 is the range */ DUK_DDD(DUK_DDDPRINT("duk__uni_range_match: cp=%06lx range=0x%06lx,0x%06lx", - (unsigned long) cp, (unsigned long) r1, (unsigned long) r2)); + (unsigned long) cp, + (unsigned long) r1, + (unsigned long) r2)); if (cp >= r1 && cp <= r2) { return 1; } @@ -603,19 +610,17 @@ /* cp == -1 (EOF) never matches and causes return value 0 */ lo = (duk_uint_fast8_t) (cp & 0xff); - hi = (duk_uint_fast32_t) (cp >> 8); /* does not fit into an uchar */ + hi = (duk_uint_fast32_t) (cp >> 8); /* does not fit into an uchar */ if (hi == 0x0000UL) { - if (lo == 0x09U || lo == 0x0bU || lo == 0x0cU || - lo == 0x20U || lo == 0xa0U) { + if (lo == 0x09U || lo == 0x0bU || lo == 0x0cU || lo == 0x20U || lo == 0xa0U) { return 1; } } else if (hi == 0x0020UL) { if (lo <= 0x0aU || lo == 0x2fU || lo == 0x5fU) { return 1; } - } else if (cp == 0x1680L || cp == 0x180eL || cp == 0x3000L || - cp == 0xfeffL) { + } else if (cp == 0x1680L || cp == 0x180eL || cp == 0x3000L || cp == 0xfeffL) { return 1; } @@ -634,8 +639,7 @@ * into a single line terminator. This must be handled by the caller. */ - if (cp == 0x000aL || cp == 0x000dL || cp == 0x2028L || - cp == 0x2029L) { + if (cp == 0x000aL || cp == 0x000dL || cp == 0x2028L || cp == 0x2029L) { return 1; } @@ -686,9 +690,7 @@ #if defined(DUK_USE_IDCHAR_FASTPATH) return (cp >= 0) && (duk_is_idchar_tabcp > 0); #else - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z') || - cp == '_' || cp == '$') { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || cp == '_' || cp == '$') { return 1; } return 0; @@ -698,17 +700,13 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - (duk_size_t) sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, (duk_size_t) sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp)) { return 1; } return 0; @@ -775,10 +773,7 @@ #if defined(DUK_USE_IDCHAR_FASTPATH) return (cp >= 0) && (duk_is_idchar_tabcp != 0); #else - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z') || - (cp >= '0' && cp <= '9') || - cp == '_' || cp == '$') { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || (cp >= '0' && cp <= '9') || cp == '_' || cp == '$') { return 1; } return 0; @@ -788,20 +783,14 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp) || - duk__uni_range_match(duk_unicode_idp_m_ids_noa, - sizeof(duk_unicode_idp_m_ids_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp) || + duk__uni_range_match(duk_unicode_idp_m_ids_noa, sizeof(duk_unicode_idp_m_ids_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp) || + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp) || duk__uni_range_match(duk_unicode_idp_m_ids_noabmp, sizeof(duk_unicode_idp_m_ids_noabmp), (duk_codepoint_t) cp)) { @@ -837,8 +826,7 @@ /* ASCII (and EOF) fast path -- quick accept and reject */ if (cp <= 0x7fL) { - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z')) { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z')) { return 1; } return 0; @@ -847,20 +835,14 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp) && - !duk__uni_range_match(duk_unicode_ids_m_let_noa, - sizeof(duk_unicode_ids_m_let_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp) && + !duk__uni_range_match(duk_unicode_ids_m_let_noa, sizeof(duk_unicode_ids_m_let_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp) && + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp) && !duk__uni_range_match(duk_unicode_ids_m_let_noabmp, sizeof(duk_unicode_ids_m_let_noabmp), (duk_codepoint_t) cp)) { @@ -897,10 +879,7 @@ */ DUK_LOCAL -duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr, - duk_bufwriter_ctx *bw, - duk_codepoint_t cp, - duk_bitdecoder_ctx *bd_ctx) { +duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_codepoint_t cp, duk_bitdecoder_ctx *bd_ctx) { duk_small_int_t skip = 0; duk_small_int_t n; duk_small_int_t t; @@ -930,10 +909,13 @@ start_o = (duk_codepoint_t) duk_bd_decode(bd_ctx, 16); count = (duk_small_int_t) duk_bd_decode(bd_ctx, 7); DUK_DDD(DUK_DDDPRINT("range: start_i=%ld, start_o=%ld, count=%ld, skip=%ld", - (long) start_i, (long) start_o, (long) count, (long) skip)); + (long) start_i, + (long) start_o, + (long) count, + (long) skip)); if (cp >= start_i) { - tmp_cp = cp - start_i; /* always >= 0 */ + tmp_cp = cp - start_i; /* always >= 0 */ if (tmp_cp < (duk_codepoint_t) count * (duk_codepoint_t) skip && (tmp_cp % (duk_codepoint_t) skip) == 0) { DUK_DDD(DUK_DDDPRINT("range matches input codepoint")); @@ -985,7 +967,7 @@ DUK_DDD(DUK_DDDPRINT("no rule matches, output is same as input")); /* fall through */ - single: +single: if (bw != NULL) { DUK_BW_WRITE_RAW_XUTF8(thr, bw, (duk_ucodepoint_t) cp); } @@ -1047,9 +1029,9 @@ * The rule is not locale/language specific so it is supported. */ - if (cp == 0x03a3L && /* U+03A3 = GREEK CAPITAL LETTER SIGMA */ - duk_unicode_is_letter(prev) && /* prev exists and is not a letter */ - !duk_unicode_is_letter(next)) { /* next does not exist or next is not a letter */ + if (cp == 0x03a3L && /* U+03A3 = GREEK CAPITAL LETTER SIGMA */ + duk_unicode_is_letter(prev) && /* prev exists and is not a letter */ + !duk_unicode_is_letter(next)) { /* next does not exist or next is not a letter */ /* Capital sigma occurred at "end of word", lowercase to * U+03C2 = GREEK SMALL LETTER FINAL SIGMA. Otherwise * fall through and let the normal rules lowercase it to @@ -1075,13 +1057,13 @@ } return duk__slow_case_conversion(thr, bw, cp, &bd_ctx); - singlechar: +singlechar: if (bw != NULL) { DUK_BW_WRITE_RAW_XUTF8(thr, bw, (duk_ucodepoint_t) cp); } return cp; - /* unused now, not needed until Turkish/Azeri */ + /* unused now, not needed until Turkish/Azeri */ #if 0 nochar: return -1; @@ -1099,7 +1081,7 @@ const duk_uint8_t *p, *p_start, *p_end; duk_codepoint_t prev, curr, next; - h_input = duk_require_hstring(thr, -1); /* Accept symbols. */ + h_input = duk_require_hstring(thr, -1); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; @@ -1111,7 +1093,8 @@ p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); p = p_start; - prev = -1; DUK_UNREF(prev); + prev = -1; + DUK_UNREF(prev); curr = -1; next = -1; for (;;) { @@ -1136,17 +1119,12 @@ /* Ensure space for maximum multi-character result; estimate is overkill. */ DUK_BW_ENSURE(thr, bw, 8 * DUK_UNICODE_MAX_XUTF8_LENGTH); - duk__case_transform_helper(thr, - bw, - (duk_codepoint_t) curr, - prev, - next, - uppercase); + duk__case_transform_helper(thr, bw, (duk_codepoint_t) curr, prev, next, uppercase); } } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, output is encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, output is encoded. */ /* invalidates h_buf pointer */ duk_remove_m2(thr); } @@ -1169,15 +1147,15 @@ return (duk_codepoint_t) duk_unicode_re_canon_lookupcp; } return cp; -#else /* DUK_USE_REGEXP_CANON_WORKAROUND */ +#else /* DUK_USE_REGEXP_CANON_WORKAROUND */ duk_codepoint_t y; y = duk__case_transform_helper(thr, - NULL, /* NULL is allowed, no output */ - cp, /* curr char */ - -1, /* prev char */ - -1, /* next char */ - 1); /* uppercase */ + NULL, /* NULL is allowed, no output */ + cp, /* curr char */ + -1, /* prev char */ + -1, /* next char */ + 1); /* uppercase */ if ((y < 0) || (cp >= 0x80 && y < 0x80)) { /* multiple codepoint conversion or non-ASCII mapped to ASCII @@ -1187,7 +1165,7 @@ } return y; -#endif /* DUK_USE_REGEXP_CANON_WORKAROUND */ +#endif /* DUK_USE_REGEXP_CANON_WORKAROUND */ } /* @@ -1200,10 +1178,7 @@ * Note: the description in E5 Section 15.10.2.6 has a typo, it * contains 'A' twice and lacks 'a'; the intent is 0-9a-zA-Z_. */ - if ((x >= '0' && x <= '9') || - (x >= 'a' && x <= 'z') || - (x >= 'A' && x <= 'Z') || - (x == '_')) { + if ((x >= '0' && x <= '9') || (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z') || (x == '_')) { return 1; } return 0; @@ -1215,51 +1190,36 @@ /* exposed because lexer needs these too */ DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_digit2 = { - (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, + (duk_uint16_t) 0x0030UL, + (duk_uint16_t) 0x0039UL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_white22 = { - (duk_uint16_t) 0x0009UL, (duk_uint16_t) 0x000DUL, - (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x0020UL, - (duk_uint16_t) 0x00A0UL, (duk_uint16_t) 0x00A0UL, - (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x1680UL, - (duk_uint16_t) 0x180EUL, (duk_uint16_t) 0x180EUL, - (duk_uint16_t) 0x2000UL, (duk_uint16_t) 0x200AUL, - (duk_uint16_t) 0x2028UL, (duk_uint16_t) 0x2029UL, - (duk_uint16_t) 0x202FUL, (duk_uint16_t) 0x202FUL, - (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x205FUL, - (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0x3000UL, + (duk_uint16_t) 0x0009UL, (duk_uint16_t) 0x000DUL, (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x00A0UL, + (duk_uint16_t) 0x00A0UL, (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x180EUL, (duk_uint16_t) 0x180EUL, + (duk_uint16_t) 0x2000UL, (duk_uint16_t) 0x200AUL, (duk_uint16_t) 0x2028UL, (duk_uint16_t) 0x2029UL, (duk_uint16_t) 0x202FUL, + (duk_uint16_t) 0x202FUL, (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0xFEFFUL, (duk_uint16_t) 0xFEFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_wordchar8 = { - (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, - (duk_uint16_t) 0x0041UL, (duk_uint16_t) 0x005AUL, - (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x005FUL, - (duk_uint16_t) 0x0061UL, (duk_uint16_t) 0x007AUL, + (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, (duk_uint16_t) 0x0041UL, (duk_uint16_t) 0x005AUL, + (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x0061UL, (duk_uint16_t) 0x007AUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_digit4 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, - (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, + (duk_uint16_t) 0x002FUL, + (duk_uint16_t) 0x003AUL, + (duk_uint16_t) 0xFFFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_white24 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x0008UL, - (duk_uint16_t) 0x000EUL, (duk_uint16_t) 0x001FUL, - (duk_uint16_t) 0x0021UL, (duk_uint16_t) 0x009FUL, - (duk_uint16_t) 0x00A1UL, (duk_uint16_t) 0x167FUL, - (duk_uint16_t) 0x1681UL, (duk_uint16_t) 0x180DUL, - (duk_uint16_t) 0x180FUL, (duk_uint16_t) 0x1FFFUL, - (duk_uint16_t) 0x200BUL, (duk_uint16_t) 0x2027UL, - (duk_uint16_t) 0x202AUL, (duk_uint16_t) 0x202EUL, - (duk_uint16_t) 0x2030UL, (duk_uint16_t) 0x205EUL, - (duk_uint16_t) 0x2060UL, (duk_uint16_t) 0x2FFFUL, - (duk_uint16_t) 0x3001UL, (duk_uint16_t) 0xFEFEUL, - (duk_uint16_t) 0xFF00UL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x0008UL, (duk_uint16_t) 0x000EUL, (duk_uint16_t) 0x001FUL, (duk_uint16_t) 0x0021UL, + (duk_uint16_t) 0x009FUL, (duk_uint16_t) 0x00A1UL, (duk_uint16_t) 0x167FUL, (duk_uint16_t) 0x1681UL, (duk_uint16_t) 0x180DUL, + (duk_uint16_t) 0x180FUL, (duk_uint16_t) 0x1FFFUL, (duk_uint16_t) 0x200BUL, (duk_uint16_t) 0x2027UL, (duk_uint16_t) 0x202AUL, + (duk_uint16_t) 0x202EUL, (duk_uint16_t) 0x2030UL, (duk_uint16_t) 0x205EUL, (duk_uint16_t) 0x2060UL, (duk_uint16_t) 0x2FFFUL, + (duk_uint16_t) 0x3001UL, (duk_uint16_t) 0xFEFEUL, (duk_uint16_t) 0xFF00UL, (duk_uint16_t) 0xFFFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_wordchar10 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, - (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0x0040UL, - (duk_uint16_t) 0x005BUL, (duk_uint16_t) 0x005EUL, - (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x0060UL, - (duk_uint16_t) 0x007BUL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0x0040UL, (duk_uint16_t) 0x005BUL, + (duk_uint16_t) 0x005EUL, (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x007BUL, (duk_uint16_t) 0xFFFFUL, }; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_util.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_util.h
Changed
@@ -5,20 +5,14 @@ #if !defined(DUK_UTIL_H_INCLUDED) #define DUK_UTIL_H_INCLUDED -#if defined(DUK_USE_GET_RANDOM_DOUBLE) -#define DUK_UTIL_GET_RANDOM_DOUBLE(thr) DUK_USE_GET_RANDOM_DOUBLE((thr)->heap_udata) -#else -#define DUK_UTIL_GET_RANDOM_DOUBLE(thr) duk_util_tinyrandom_get_double(thr) -#endif - /* * Some useful constants */ -#define DUK_DOUBLE_2TO32 4294967296.0 -#define DUK_DOUBLE_2TO31 2147483648.0 -#define DUK_DOUBLE_LOG2E 1.4426950408889634 -#define DUK_DOUBLE_LOG10E 0.4342944819032518 +#define DUK_DOUBLE_2TO32 4294967296.0 +#define DUK_DOUBLE_2TO31 2147483648.0 +#define DUK_DOUBLE_LOG2E 1.4426950408889634 +#define DUK_DOUBLE_LOG10E 0.4342944819032518 /* * Endian conversion @@ -71,33 +65,35 @@ * update the pointer argument automatically. */ -#define DUK_RAW_WRITE_U8(ptr,val) do { \ +#define DUK_RAW_WRITE_U8(ptr, val) \ + do { \ *(ptr) = (duk_uint8_t) (val); \ } while (0) -#define DUK_RAW_WRITE_U16_BE(ptr,val) duk_raw_write_u16_be((ptr), (duk_uint16_t) (val)) -#define DUK_RAW_WRITE_U32_BE(ptr,val) duk_raw_write_u32_be((ptr), (duk_uint32_t) (val)) -#define DUK_RAW_WRITE_FLOAT_BE(ptr,val) duk_raw_write_float_be((ptr), (duk_float_t) (val)) -#define DUK_RAW_WRITE_DOUBLE_BE(ptr,val) duk_raw_write_double_be((ptr), (duk_double_t) (val)) -#define DUK_RAW_WRITE_XUTF8(ptr,val) duk_raw_write_xutf8((ptr), (duk_ucodepoint_t) (val)) +#define DUK_RAW_WRITE_U16_BE(ptr, val) duk_raw_write_u16_be((ptr), (duk_uint16_t) (val)) +#define DUK_RAW_WRITE_U32_BE(ptr, val) duk_raw_write_u32_be((ptr), (duk_uint32_t) (val)) +#define DUK_RAW_WRITE_FLOAT_BE(ptr, val) duk_raw_write_float_be((ptr), (duk_float_t) (val)) +#define DUK_RAW_WRITE_DOUBLE_BE(ptr, val) duk_raw_write_double_be((ptr), (duk_double_t) (val)) +#define DUK_RAW_WRITE_XUTF8(ptr, val) duk_raw_write_xutf8((ptr), (duk_ucodepoint_t) (val)) -#define DUK_RAW_WRITEINC_U8(ptr,val) do { \ +#define DUK_RAW_WRITEINC_U8(ptr, val) \ + do { \ *(ptr)++ = (duk_uint8_t) (val); \ } while (0) -#define DUK_RAW_WRITEINC_U16_BE(ptr,val) duk_raw_writeinc_u16_be(&(ptr), (duk_uint16_t) (val)) -#define DUK_RAW_WRITEINC_U32_BE(ptr,val) duk_raw_writeinc_u32_be(&(ptr), (duk_uint32_t) (val)) -#define DUK_RAW_WRITEINC_FLOAT_BE(ptr,val) duk_raw_writeinc_float_be(&(ptr), (duk_float_t) (val)) -#define DUK_RAW_WRITEINC_DOUBLE_BE(ptr,val) duk_raw_writeinc_double_be(&(ptr), (duk_double_t) (val)) -#define DUK_RAW_WRITEINC_XUTF8(ptr,val) duk_raw_writeinc_xutf8(&(ptr), (duk_ucodepoint_t) (val)) -#define DUK_RAW_WRITEINC_CESU8(ptr,val) duk_raw_writeinc_cesu8(&(ptr), (duk_ucodepoint_t) (val)) +#define DUK_RAW_WRITEINC_U16_BE(ptr, val) duk_raw_writeinc_u16_be(&(ptr), (duk_uint16_t) (val)) +#define DUK_RAW_WRITEINC_U32_BE(ptr, val) duk_raw_writeinc_u32_be(&(ptr), (duk_uint32_t) (val)) +#define DUK_RAW_WRITEINC_FLOAT_BE(ptr, val) duk_raw_writeinc_float_be(&(ptr), (duk_float_t) (val)) +#define DUK_RAW_WRITEINC_DOUBLE_BE(ptr, val) duk_raw_writeinc_double_be(&(ptr), (duk_double_t) (val)) +#define DUK_RAW_WRITEINC_XUTF8(ptr, val) duk_raw_writeinc_xutf8(&(ptr), (duk_ucodepoint_t) (val)) +#define DUK_RAW_WRITEINC_CESU8(ptr, val) duk_raw_writeinc_cesu8(&(ptr), (duk_ucodepoint_t) (val)) -#define DUK_RAW_READ_U8(ptr) ((duk_uint8_t) (*(ptr))) -#define DUK_RAW_READ_U16_BE(ptr) duk_raw_read_u16_be((ptr)); -#define DUK_RAW_READ_U32_BE(ptr) duk_raw_read_u32_be((ptr)); +#define DUK_RAW_READ_U8(ptr) ((duk_uint8_t) (*(ptr))) +#define DUK_RAW_READ_U16_BE(ptr) duk_raw_read_u16_be((ptr)); +#define DUK_RAW_READ_U32_BE(ptr) duk_raw_read_u32_be((ptr)); #define DUK_RAW_READ_DOUBLE_BE(ptr) duk_raw_read_double_be((ptr)); -#define DUK_RAW_READINC_U8(ptr) ((duk_uint8_t) (*(ptr)++)) -#define DUK_RAW_READINC_U16_BE(ptr) duk_raw_readinc_u16_be(&(ptr)); -#define DUK_RAW_READINC_U32_BE(ptr) duk_raw_readinc_u32_be(&(ptr)); +#define DUK_RAW_READINC_U8(ptr) ((duk_uint8_t) (*(ptr)++)) +#define DUK_RAW_READINC_U16_BE(ptr) duk_raw_readinc_u16_be(&(ptr)); +#define DUK_RAW_READINC_U32_BE(ptr) duk_raw_readinc_u32_be(&(ptr)); #define DUK_RAW_READINC_DOUBLE_BE(ptr) duk_raw_readinc_double_be(&(ptr)); /* @@ -144,29 +140,31 @@ }; #if defined(DUK_USE_PREFER_SIZE) -#define DUK_BW_SLACK_ADD 64 -#define DUK_BW_SLACK_SHIFT 4 /* 2^4 -> 1/16 = 6.25% slack */ +#define DUK_BW_SLACK_ADD 64 +#define DUK_BW_SLACK_SHIFT 4 /* 2^4 -> 1/16 = 6.25% slack */ #else -#define DUK_BW_SLACK_ADD 64 -#define DUK_BW_SLACK_SHIFT 2 /* 2^2 -> 1/4 = 25% slack */ +#define DUK_BW_SLACK_ADD 64 +#define DUK_BW_SLACK_SHIFT 2 /* 2^2 -> 1/4 = 25% slack */ #endif /* Initialization and finalization (compaction), converting to other types. */ -#define DUK_BW_INIT_PUSHBUF(thr,bw_ctx,sz) do { \ +#define DUK_BW_INIT_PUSHBUF(thr, bw_ctx, sz) \ + do { \ duk_bw_init_pushbuf((thr), (bw_ctx), (sz)); \ } while (0) -#define DUK_BW_INIT_WITHBUF(thr,bw_ctx,buf) do { \ +#define DUK_BW_INIT_WITHBUF(thr, bw_ctx, buf) \ + do { \ duk_bw_init((thr), (bw_ctx), (buf)); \ } while (0) -#define DUK_BW_COMPACT(thr,bw_ctx) do { \ +#define DUK_BW_COMPACT(thr, bw_ctx) \ + do { \ /* Make underlying buffer compact to match DUK_BW_GET_SIZE(). */ \ duk_bw_compact((thr), (bw_ctx)); \ } while (0) -#define DUK_BW_PUSH_AS_STRING(thr,bw_ctx) do { \ - duk_push_lstring((thr), \ - (const char *) (bw_ctx)->p_base, \ - (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ +#define DUK_BW_PUSH_AS_STRING(thr, bw_ctx) \ + do { \ + duk_push_lstring((thr), (const char *) (bw_ctx)->p_base, (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ } while (0) /* Pointers may be NULL for a while when 'buf' size is zero and before any @@ -176,43 +174,48 @@ */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_bw_assert_valid(duk_hthread *thr, duk_bufwriter_ctx *bw_ctx); -#define DUK_BW_ASSERT_VALID_EXPR(thr,bw_ctx) (duk_bw_assert_valid((thr), (bw_ctx))) -#define DUK_BW_ASSERT_VALID(thr,bw_ctx) do { duk_bw_assert_valid((thr), (bw_ctx)); } while (0) +#define DUK_BW_ASSERT_VALID_EXPR(thr, bw_ctx) (duk_bw_assert_valid((thr), (bw_ctx))) +#define DUK_BW_ASSERT_VALID(thr, bw_ctx) \ + do { \ + duk_bw_assert_valid((thr), (bw_ctx)); \ + } while (0) #else -#define DUK_BW_ASSERT_VALID_EXPR(thr,bw_ctx) DUK_ASSERT_EXPR(1) -#define DUK_BW_ASSERT_VALID(thr,bw_ctx) do {} while (0) +#define DUK_BW_ASSERT_VALID_EXPR(thr, bw_ctx) DUK_ASSERT_EXPR(1) +#define DUK_BW_ASSERT_VALID(thr, bw_ctx) \ + do { \ + } while (0) #endif /* Working with the pointer and current size. */ -#define DUK_BW_GET_PTR(thr,bw_ctx) \ - ((bw_ctx)->p) -#define DUK_BW_SET_PTR(thr,bw_ctx,ptr) do { \ +#define DUK_BW_GET_PTR(thr, bw_ctx) ((bw_ctx)->p) +#define DUK_BW_SET_PTR(thr, bw_ctx, ptr) \ + do { \ (bw_ctx)->p = (ptr); \ } while (0) -#define DUK_BW_ADD_PTR(thr,bw_ctx,delta) do { \ +#define DUK_BW_ADD_PTR(thr, bw_ctx, delta) \ + do { \ (bw_ctx)->p += (delta); \ } while (0) -#define DUK_BW_GET_BASEPTR(thr,bw_ctx) \ - ((bw_ctx)->p_base) -#define DUK_BW_GET_LIMITPTR(thr,bw_ctx) \ - ((bw_ctx)->p_limit) -#define DUK_BW_GET_SIZE(thr,bw_ctx) \ - ((duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)) -#define DUK_BW_SET_SIZE(thr,bw_ctx,sz) do { \ +#define DUK_BW_GET_BASEPTR(thr, bw_ctx) ((bw_ctx)->p_base) +#define DUK_BW_GET_LIMITPTR(thr, bw_ctx) ((bw_ctx)->p_limit) +#define DUK_BW_GET_SIZE(thr, bw_ctx) ((duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)) +#define DUK_BW_SET_SIZE(thr, bw_ctx, sz) \ + do { \ DUK_ASSERT((duk_size_t) (sz) <= (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ (bw_ctx)->p = (bw_ctx)->p_base + (sz); \ } while (0) -#define DUK_BW_RESET_SIZE(thr,bw_ctx) do { \ +#define DUK_BW_RESET_SIZE(thr, bw_ctx) \ + do { \ /* Reset to zero size, keep current limit. */ \ (bw_ctx)->p = (bw_ctx)->p_base; \ } while (0) -#define DUK_BW_GET_BUFFER(thr,bw_ctx) \ - ((bw_ctx)->buf) +#define DUK_BW_GET_BUFFER(thr, bw_ctx) ((bw_ctx)->buf) /* Ensuring (reserving) space. */ -#define DUK_BW_ENSURE(thr,bw_ctx,sz) do { \ +#define DUK_BW_ENSURE(thr, bw_ctx, sz) \ + do { \ duk_size_t duk__sz, duk__space; \ DUK_BW_ASSERT_VALID((thr), (bw_ctx)); \ duk__sz = (sz); \ @@ -223,22 +226,21 @@ } while (0) /* NOTE: Multiple evaluation of 'ptr' in this macro. */ /* XXX: Rework to use an always-inline function? */ -#define DUK_BW_ENSURE_RAW(thr,bw_ctx,sz,ptr) \ - (((duk_size_t) ((bw_ctx)->p_limit - (ptr)) >= (sz)) ? \ - (ptr) : \ - ((bw_ctx)->p = (ptr), duk_bw_resize((thr),(bw_ctx),(sz)))) -#define DUK_BW_ENSURE_GETPTR(thr,bw_ctx,sz) \ - DUK_BW_ENSURE_RAW((thr), (bw_ctx), (sz), (bw_ctx)->p) -#define DUK_BW_ASSERT_SPACE_EXPR(thr,bw_ctx,sz) \ +#define DUK_BW_ENSURE_RAW(thr, bw_ctx, sz, ptr) \ + (((duk_size_t) ((bw_ctx)->p_limit - (ptr)) >= (sz)) ? (ptr) : ((bw_ctx)->p = (ptr), duk_bw_resize((thr), (bw_ctx), (sz)))) +#define DUK_BW_ENSURE_GETPTR(thr, bw_ctx, sz) DUK_BW_ENSURE_RAW((thr), (bw_ctx), (sz), (bw_ctx)->p) +#define DUK_BW_ASSERT_SPACE_EXPR(thr, bw_ctx, sz) \ (DUK_BW_ASSERT_VALID_EXPR((thr), (bw_ctx)), \ DUK_ASSERT_EXPR((duk_size_t) ((bw_ctx)->p_limit - (bw_ctx)->p) >= (duk_size_t) (sz))) -#define DUK_BW_ASSERT_SPACE(thr,bw_ctx,sz) do { \ +#define DUK_BW_ASSERT_SPACE(thr, bw_ctx, sz) \ + do { \ DUK_BW_ASSERT_SPACE_EXPR((thr), (bw_ctx), (sz)); \ } while (0) /* Miscellaneous. */ -#define DUK_BW_SETPTR_AND_COMPACT(thr,bw_ctx,ptr) do { \ +#define DUK_BW_SETPTR_AND_COMPACT(thr, bw_ctx, ptr) \ + do { \ (bw_ctx)->p = (ptr); \ duk_bw_compact((thr), (bw_ctx)); \ } while (0) @@ -249,11 +251,13 @@ * explicit pointer load/stores get generated (e.g. gcc -Os). */ -#define DUK_BW_WRITE_RAW_U8(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_U8(thr, bw_ctx, val) \ + do { \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 1); \ *(bw_ctx)->p++ = (duk_uint8_t) (val); \ } while (0) -#define DUK_BW_WRITE_RAW_U8_2(thr,bw_ctx,val1,val2) do { \ +#define DUK_BW_WRITE_RAW_U8_2(thr, bw_ctx, val1, val2) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 2); \ duk__p = (bw_ctx)->p; \ @@ -261,7 +265,8 @@ *duk__p++ = (duk_uint8_t) (val2); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_3(thr,bw_ctx,val1,val2,val3) do { \ +#define DUK_BW_WRITE_RAW_U8_3(thr, bw_ctx, val1, val2, val3) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 3); \ duk__p = (bw_ctx)->p; \ @@ -270,7 +275,8 @@ *duk__p++ = (duk_uint8_t) (val3); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_4(thr,bw_ctx,val1,val2,val3,val4) do { \ +#define DUK_BW_WRITE_RAW_U8_4(thr, bw_ctx, val1, val2, val3, val4) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 4); \ duk__p = (bw_ctx)->p; \ @@ -280,7 +286,8 @@ *duk__p++ = (duk_uint8_t) (val4); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_5(thr,bw_ctx,val1,val2,val3,val4,val5) do { \ +#define DUK_BW_WRITE_RAW_U8_5(thr, bw_ctx, val1, val2, val3, val4, val5) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 5); \ duk__p = (bw_ctx)->p; \ @@ -291,7 +298,8 @@ *duk__p++ = (duk_uint8_t) (val5); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_6(thr,bw_ctx,val1,val2,val3,val4,val5,val6) do { \ +#define DUK_BW_WRITE_RAW_U8_6(thr, bw_ctx, val1, val2, val3, val4, val5, val6) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 6); \ duk__p = (bw_ctx)->p; \ @@ -303,7 +311,8 @@ *duk__p++ = (duk_uint8_t) (val6); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_XUTF8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_RAW_XUTF8(thr, bw_ctx, cp) \ + do { \ duk_ucodepoint_t duk__cp; \ duk_small_int_t duk__enc_len; \ duk__cp = (duk_ucodepoint_t) (cp); \ @@ -311,7 +320,8 @@ duk__enc_len = duk_unicode_encode_xutf8(duk__cp, (bw_ctx)->p); \ (bw_ctx)->p += duk__enc_len; \ } while (0) -#define DUK_BW_WRITE_RAW_CESU8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_RAW_CESU8(thr, bw_ctx, cp) \ + do { \ duk_ucodepoint_t duk__cp; \ duk_small_int_t duk__enc_len; \ duk__cp = (duk_ucodepoint_t) (cp); \ @@ -321,7 +331,8 @@ } while (0) /* XXX: add temporary duk__p pointer here too; sharing */ /* XXX: avoid unsafe variants */ -#define DUK_BW_WRITE_RAW_BYTES(thr,bw_ctx,valptr,valsz) do { \ +#define DUK_BW_WRITE_RAW_BYTES(thr, bw_ctx, valptr, valsz) \ + do { \ const void *duk__valptr; \ duk_size_t duk__valsz; \ duk__valptr = (const void *) (valptr); \ @@ -329,7 +340,8 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), duk__valptr, duk__valsz); \ (bw_ctx)->p += duk__valsz; \ } while (0) -#define DUK_BW_WRITE_RAW_CSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_CSTRING(thr, bw_ctx, val) \ + do { \ const duk_uint8_t *duk__val; \ duk_size_t duk__val_len; \ duk__val = (const duk_uint8_t *) (val); \ @@ -337,93 +349,107 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) duk__val, duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HSTRING(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HSTRING_GET_BYTELEN((val)); \ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HSTRING_GET_DATA((val)), duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER_FIXED(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER_FIXED(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_FIXED_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER_DYNAMIC(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER_DYNAMIC(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_DYNAMIC_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) /* Append bytes from a slice already in the buffer. */ -#define DUK_BW_WRITE_RAW_SLICE(thr,bw,dst_off,dst_len) \ - duk_bw_write_raw_slice((thr), (bw), (dst_off), (dst_len)) +#define DUK_BW_WRITE_RAW_SLICE(thr, bw, dst_off, dst_len) duk_bw_write_raw_slice((thr), (bw), (dst_off), (dst_len)) /* Insert bytes in the middle of the buffer from an external buffer. */ -#define DUK_BW_INSERT_RAW_BYTES(thr,bw,dst_off,buf,len) \ - duk_bw_insert_raw_bytes((thr), (bw), (dst_off), (buf), (len)) +#define DUK_BW_INSERT_RAW_BYTES(thr, bw, dst_off, buf, len) duk_bw_insert_raw_bytes((thr), (bw), (dst_off), (buf), (len)) /* Insert bytes in the middle of the buffer from a slice already * in the buffer. Source offset is interpreted "before" the operation. */ -#define DUK_BW_INSERT_RAW_SLICE(thr,bw,dst_off,src_off,len) \ - duk_bw_insert_raw_slice((thr), (bw), (dst_off), (src_off), (len)) +#define DUK_BW_INSERT_RAW_SLICE(thr, bw, dst_off, src_off, len) duk_bw_insert_raw_slice((thr), (bw), (dst_off), (src_off), (len)) /* Insert a reserved area somewhere in the buffer; caller fills it. * Evaluates to a (duk_uint_t *) pointing to the start of the reserved * area for convenience. */ -#define DUK_BW_INSERT_RAW_AREA(thr,bw,off,len) \ - duk_bw_insert_raw_area((thr), (bw), (off), (len)) +#define DUK_BW_INSERT_RAW_AREA(thr, bw, off, len) duk_bw_insert_raw_area((thr), (bw), (off), (len)) /* Remove a slice from inside buffer. */ -#define DUK_BW_REMOVE_RAW_SLICE(thr,bw,off,len) \ - duk_bw_remove_raw_slice((thr), (bw), (off), (len)) +#define DUK_BW_REMOVE_RAW_SLICE(thr, bw, off, len) duk_bw_remove_raw_slice((thr), (bw), (off), (len)) /* Safe write calls which will ensure space first. */ -#define DUK_BW_WRITE_ENSURE_U8(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_U8(thr, bw_ctx, val) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 1); \ DUK_BW_WRITE_RAW_U8((thr), (bw_ctx), (val)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_2(thr,bw_ctx,val1,val2) do { \ +#define DUK_BW_WRITE_ENSURE_U8_2(thr, bw_ctx, val1, val2) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 2); \ DUK_BW_WRITE_RAW_U8_2((thr), (bw_ctx), (val1), (val2)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_3(thr,bw_ctx,val1,val2,val3) do { \ +#define DUK_BW_WRITE_ENSURE_U8_3(thr, bw_ctx, val1, val2, val3) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 3); \ DUK_BW_WRITE_RAW_U8_3((thr), (bw_ctx), (val1), (val2), (val3)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_4(thr,bw_ctx,val1,val2,val3,val4) do { \ +#define DUK_BW_WRITE_ENSURE_U8_4(thr, bw_ctx, val1, val2, val3, val4) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 4); \ DUK_BW_WRITE_RAW_U8_4((thr), (bw_ctx), (val1), (val2), (val3), (val4)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_5(thr,bw_ctx,val1,val2,val3,val4,val5) do { \ +#define DUK_BW_WRITE_ENSURE_U8_5(thr, bw_ctx, val1, val2, val3, val4, val5) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 5); \ DUK_BW_WRITE_RAW_U8_5((thr), (bw_ctx), (val1), (val2), (val3), (val4), (val5)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_6(thr,bw_ctx,val1,val2,val3,val4,val5,val6) do { \ +#define DUK_BW_WRITE_ENSURE_U8_6(thr, bw_ctx, val1, val2, val3, val4, val5, val6) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 6); \ DUK_BW_WRITE_RAW_U8_6((thr), (bw_ctx), (val1), (val2), (val3), (val4), (val5), (val6)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_XUTF8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_ENSURE_XUTF8(thr, bw_ctx, cp) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), DUK_UNICODE_MAX_XUTF8_LENGTH); \ DUK_BW_WRITE_RAW_XUTF8((thr), (bw_ctx), (cp)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_CESU8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_ENSURE_CESU8(thr, bw_ctx, cp) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), DUK_UNICODE_MAX_CESU8_LENGTH); \ DUK_BW_WRITE_RAW_CESU8((thr), (bw_ctx), (cp)); \ } while (0) /* XXX: add temporary duk__p pointer here too; sharing */ /* XXX: avoid unsafe */ -#define DUK_BW_WRITE_ENSURE_BYTES(thr,bw_ctx,valptr,valsz) do { \ +#define DUK_BW_WRITE_ENSURE_BYTES(thr, bw_ctx, valptr, valsz) \ + do { \ const void *duk__valptr; \ duk_size_t duk__valsz; \ duk__valptr = (const void *) (valptr); \ @@ -432,7 +458,8 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), duk__valptr, duk__valsz); \ (bw_ctx)->p += duk__valsz; \ } while (0) -#define DUK_BW_WRITE_ENSURE_CSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_CSTRING(thr, bw_ctx, val) \ + do { \ const duk_uint8_t *duk__val; \ duk_size_t duk__val_len; \ duk__val = (const duk_uint8_t *) (val); \ @@ -441,45 +468,53 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) duk__val, duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HSTRING(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HSTRING_GET_BYTELEN((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HSTRING_GET_DATA((val)), duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER_FIXED(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER_FIXED(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_FIXED_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER_DYNAMIC(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER_DYNAMIC(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_DYNAMIC_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_SLICE(thr,bw,dst_off,dst_len) \ - duk_bw_write_ensure_slice((thr), (bw), (dst_off), (dst_len)) -#define DUK_BW_INSERT_ENSURE_BYTES(thr,bw,dst_off,buf,len) \ - duk_bw_insert_ensure_bytes((thr), (bw), (dst_off), (buf), (len)) -#define DUK_BW_INSERT_ENSURE_SLICE(thr,bw,dst_off,src_off,len) \ +#define DUK_BW_WRITE_ENSURE_SLICE(thr, bw, dst_off, dst_len) duk_bw_write_ensure_slice((thr), (bw), (dst_off), (dst_len)) +#define DUK_BW_INSERT_ENSURE_BYTES(thr, bw, dst_off, buf, len) duk_bw_insert_ensure_bytes((thr), (bw), (dst_off), (buf), (len)) +#define DUK_BW_INSERT_ENSURE_SLICE(thr, bw, dst_off, src_off, len) \ duk_bw_insert_ensure_slice((thr), (bw), (dst_off), (src_off), (len)) -#define DUK_BW_INSERT_ENSURE_AREA(thr,bw,off,len) \ +#define DUK_BW_INSERT_ENSURE_AREA(thr, bw, off, len) \ /* Evaluates to (duk_uint8_t *) pointing to start of area. */ \ duk_bw_insert_ensure_area((thr), (bw), (off), (len)) -#define DUK_BW_REMOVE_ENSURE_SLICE(thr,bw,off,len) \ +#define DUK_BW_REMOVE_ENSURE_SLICE(thr, bw, off, len) \ /* No difference between raw/ensure because the buffer shrinks. */ \ DUK_BW_REMOVE_RAW_SLICE((thr), (bw), (off), (len)) @@ -495,13 +530,13 @@ DUK_INTERNAL_DECL const duk_int16_t duk_hex_dectab_shift4256; DUK_INTERNAL_DECL const duk_uint16_t duk_hex_enctab256; #endif -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* Note: assumes that duk_util_probe_steps size is 32 */ #if defined(DUK_USE_HOBJECT_HASH_PART) #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL duk_uint8_t duk_util_probe_steps32; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ #endif #if defined(DUK_USE_STRHASH_DENSE) @@ -529,10 +564,26 @@ DUK_INTERNAL_DECL void duk_bw_compact(duk_hthread *thr, duk_bufwriter_ctx *bw_ctx); DUK_INTERNAL_DECL void duk_bw_write_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t src_off, duk_size_t len); DUK_INTERNAL_DECL void duk_bw_write_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t src_off, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_raw_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_ensure_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_raw_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_ensure_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_raw_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_ensure_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len); DUK_INTERNAL_DECL duk_uint8_t *duk_bw_insert_raw_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); DUK_INTERNAL_DECL duk_uint8_t *duk_bw_insert_ensure_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); DUK_INTERNAL_DECL void duk_bw_remove_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); @@ -559,10 +610,12 @@ DUK_INTERNAL_DECL void duk_raw_writeinc_xutf8(duk_uint8_t **p, duk_ucodepoint_t val); DUK_INTERNAL_DECL void duk_raw_writeinc_cesu8(duk_uint8_t **p, duk_ucodepoint_t val); -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ DUK_INTERNAL_DECL void duk_byteswap_bytes(duk_uint8_t *p, duk_small_uint_t len); #endif +DUK_INTERNAL_DECL duk_double_t duk_util_get_random_double(duk_hthread *thr); + /* memcpy(), memmove() etc wrappers. The plain variants like duk_memcpy() * assume C99+ and 'src' and 'dst' pointers must be non-NULL even when the * operation size is zero. The unsafe variants like duk_memcpy_safe() deal @@ -573,7 +626,8 @@ * few extra bytes per call site adds up to ~1kB footprint. */ #if defined(DUK_USE_ALLOW_UNDEFINED_BEHAVIOR) -#define duk_memcpy(dst,src,len) do { \ +#define duk_memcpy(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -581,8 +635,9 @@ DUK_ASSERT(duk__src != NULL || duk__len == 0U); \ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memcpy_unsafe(dst,src,len) duk_memcpy((dst), (src), (len)) -#define duk_memmove(dst,src,len) do { \ +#define duk_memcpy_unsafe(dst, src, len) duk_memcpy((dst), (src), (len)) +#define duk_memmove(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -590,24 +645,27 @@ DUK_ASSERT(duk__src != NULL || duk__len == 0U); \ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memmove_unsafe(dst,src,len) duk_memmove((dst), (src), (len)) -#define duk_memset(dst,val,len) do { \ +#define duk_memmove_unsafe(dst, src, len) duk_memmove((dst), (src), (len)) +#define duk_memset(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } while (0) -#define duk_memset_unsafe(dst,val,len) duk_memset((dst), (val), (len)) -#define duk_memzero(dst,len) do { \ +#define duk_memset_unsafe(dst, val, len) duk_memset((dst), (val), (len)) +#define duk_memzero(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } while (0) -#define duk_memzero_unsafe(dst,len) duk_memzero((dst), (len)) -#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ -#define duk_memcpy(dst,src,len) do { \ +#define duk_memzero_unsafe(dst, len) duk_memzero((dst), (len)) +#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#define duk_memcpy(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -615,7 +673,8 @@ DUK_ASSERT(duk__src != NULL); \ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memcpy_unsafe(dst,src,len) do { \ +#define duk_memcpy_unsafe(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -627,7 +686,8 @@ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } \ } while (0) -#define duk_memmove(dst,src,len) do { \ +#define duk_memmove(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -635,7 +695,8 @@ DUK_ASSERT(duk__src != NULL); \ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memmove_unsafe(dst,src,len) do { \ +#define duk_memmove_unsafe(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -647,14 +708,16 @@ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } \ } while (0) -#define duk_memset(dst,val,len) do { \ +#define duk_memset(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL); \ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } while (0) -#define duk_memset_unsafe(dst,val,len) do { \ +#define duk_memset_unsafe(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ @@ -664,13 +727,15 @@ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } \ } while (0) -#define duk_memzero(dst,len) do { \ +#define duk_memzero(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL); \ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } while (0) -#define duk_memzero_unsafe(dst,len) do { \ +#define duk_memzero_unsafe(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ @@ -679,7 +744,7 @@ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } \ } while (0) -#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ DUK_INTERNAL_DECL duk_small_int_t duk_memcmp(const void *s1, const void *s2, duk_size_t len); DUK_INTERNAL_DECL duk_small_int_t duk_memcmp_unsafe(const void *s1, const void *s2, duk_size_t len); @@ -725,7 +790,6 @@ * * However, incorrectly true for x == 0 so check for that explicitly. */ -#define DUK_IS_POWER_OF_TWO(x) \ - ((x) != 0U && ((x) & ((x) - 1U)) == 0U) +#define DUK_IS_POWER_OF_TWO(x) ((x) != 0U && ((x) & ((x) -1U)) == 0U) -#endif /* DUK_UTIL_H_INCLUDED */ +#endif /* DUK_UTIL_H_INCLUDED */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_util_bitdecoder.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_util_bitdecoder.c
Changed
@@ -43,7 +43,7 @@ shift = ctx->currbits - bits; mask = (((duk_uint32_t) 1U) << bits) - 1U; tmp = (ctx->currval >> shift) & mask; - ctx->currbits = shift; /* remaining */ + ctx->currbits = shift; /* remaining */ #if 0 DUK_DDD(DUK_DDDPRINT("decode_bits: %ld bits -> 0x%08lx (%ld), currbits=%ld, currval=0x%08lx", @@ -82,17 +82,17 @@ */ switch (duk_bd_decode(ctx, 2)) { case 0: - return 0; /* 0,0 */ + return 0; /* 0,0 */ case 1: - return duk_bd_decode(ctx, 2) + 1; /* 1,4 */ + return duk_bd_decode(ctx, 2) + 1; /* 1,4 */ case 2: - return duk_bd_decode(ctx, 5) + 5; /* 5,36 */ + return duk_bd_decode(ctx, 5) + 5; /* 5,36 */ default: t = duk_bd_decode(ctx, 7); if (t == 0) { return duk_bd_decode(ctx, 20); } - return (t - 1) + 37; /* 37,163 */ + return (t - 1) + 37; /* 37,163 */ } } @@ -101,20 +101,18 @@ * Caller must supply the output buffer whose size is NOT checked! */ -#define DUK__BITPACK_LETTER_LIMIT 26 -#define DUK__BITPACK_LOOKUP1 26 -#define DUK__BITPACK_LOOKUP2 27 -#define DUK__BITPACK_SWITCH1 28 -#define DUK__BITPACK_SWITCH 29 -#define DUK__BITPACK_UNUSED1 30 -#define DUK__BITPACK_EIGHTBIT 31 - -DUK_LOCAL const duk_uint8_t duk__bitpacked_lookup16 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_UNDERSCORE, DUK_ASC_SPACE, - 0x82, 0x80, DUK_ASC_DOUBLEQUOTE, DUK_ASC_LCURLY -}; +#define DUK__BITPACK_LETTER_LIMIT 26 +#define DUK__BITPACK_LOOKUP1 26 +#define DUK__BITPACK_LOOKUP2 27 +#define DUK__BITPACK_SWITCH1 28 +#define DUK__BITPACK_SWITCH 29 +#define DUK__BITPACK_UNUSED1 30 +#define DUK__BITPACK_EIGHTBIT 31 + +DUK_LOCAL const duk_uint8_t duk__bitpacked_lookup16 = { DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, + DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_UNDERSCORE, DUK_ASC_SPACE, + 0x82, 0x80, DUK_ASC_DOUBLEQUOTE, DUK_ASC_LCURLY }; DUK_INTERNAL duk_small_uint_t duk_bd_decode_bitpacked_string(duk_bitdecoder_ctx *bd, duk_uint8_t *out) { duk_small_uint_t len; @@ -124,10 +122,10 @@ len = duk_bd_decode(bd, 5); if (len == 31) { - len = duk_bd_decode(bd, 8); /* Support up to 256 bytes; rare. */ + len = duk_bd_decode(bd, 8); /* Support up to 256 bytes; rare. */ } - mode = 32; /* 0 = uppercase, 32 = lowercase (= 'a' - 'A') */ + mode = 32; /* 0 = uppercase, 32 = lowercase (= 'a' - 'A') */ for (i = 0; i < len; i++) { t = duk_bd_decode(bd, 5); if (t < DUK__BITPACK_LETTER_LIMIT) { @@ -138,7 +136,7 @@ t = duk__bitpacked_lookup8 + duk_bd_decode(bd, 3); } else if (t == DUK__BITPACK_SWITCH1) { t = duk_bd_decode(bd, 5); - DUK_ASSERT_DISABLE(t >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(t >= 0); /* unsigned */ DUK_ASSERT(t <= 25); t = t + DUK_ASC_UC_A + (mode ^ 32); } else if (t == DUK__BITPACK_SWITCH) {
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_util_bufwriter.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_util_bufwriter.c
Changed
@@ -71,7 +71,7 @@ DUK_ERROR_RANGE(thr, DUK_STR_BUFFER_TOO_LONG); DUK_WO_NORETURN(return NULL;); } -#if 0 /* for manual torture testing: tight allocation, useful with valgrind */ +#if 0 /* for manual torture testing: tight allocation, useful with valgrind */ new_sz = curr_off + sz; #endif @@ -112,9 +112,7 @@ DUK_UNREF(thr); p_base = bw->p_base; - duk_memcpy_unsafe((void *) bw->p, - (const void *) (p_base + src_off), - (size_t) len); + duk_memcpy_unsafe((void *) bw->p, (const void *) (p_base + src_off), (size_t) len); bw->p += len; } @@ -129,7 +127,11 @@ duk_bw_write_raw_slice(thr, bw, src_off, len); } -DUK_INTERNAL void duk_bw_insert_raw_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_raw_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len) { duk_uint8_t *p_base; duk_size_t buf_sz, move_sz; @@ -140,20 +142,20 @@ DUK_UNREF(thr); p_base = bw->p_base; - buf_sz = (duk_size_t) (bw->p - p_base); /* constrained by maximum buffer size */ + buf_sz = (duk_size_t) (bw->p - p_base); /* constrained by maximum buffer size */ move_sz = buf_sz - dst_off; - DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ - duk_memmove_unsafe((void *) (p_base + dst_off + len), - (const void *) (p_base + dst_off), - (size_t) move_sz); - duk_memcpy_unsafe((void *) (p_base + dst_off), - (const void *) buf, - (size_t) len); + DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ + duk_memmove_unsafe((void *) (p_base + dst_off + len), (const void *) (p_base + dst_off), (size_t) move_sz); + duk_memcpy_unsafe((void *) (p_base + dst_off), (const void *) buf, (size_t) len); bw->p += len; } -DUK_INTERNAL void duk_bw_insert_ensure_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_ensure_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len) { DUK_ASSERT(thr != NULL); DUK_ASSERT(bw != NULL); DUK_ASSERT(dst_off <= DUK_BW_GET_SIZE(thr, bw)); @@ -163,7 +165,11 @@ duk_bw_insert_raw_bytes(thr, bw, dst_off, buf, len); } -DUK_INTERNAL void duk_bw_insert_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_raw_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len) { duk_uint8_t *p_base; duk_size_t buf_sz, move_sz; @@ -190,17 +196,17 @@ buf_sz = (duk_size_t) (bw->p - p_base); move_sz = buf_sz - dst_off; - DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ - duk_memmove_unsafe((void *) (p_base + dst_off + len), - (const void *) (p_base + dst_off), - (size_t) move_sz); - duk_memcpy_unsafe((void *) (p_base + dst_off), - (const void *) (p_base + src_off), - (size_t) len); + DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ + duk_memmove_unsafe((void *) (p_base + dst_off + len), (const void *) (p_base + dst_off), (size_t) move_sz); + duk_memcpy_unsafe((void *) (p_base + dst_off), (const void *) (p_base + src_off), (size_t) len); bw->p += len; } -DUK_INTERNAL void duk_bw_insert_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_ensure_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len) { DUK_ASSERT(thr != NULL); DUK_ASSERT(bw != NULL); DUK_ASSERT(dst_off <= DUK_BW_GET_SIZE(thr, bw)); @@ -230,7 +236,7 @@ p_dst = p_base + off + len; p_src = p_base + off; duk_memmove_unsafe((void *) p_dst, (const void *) p_src, (size_t) move_sz); - return p_src; /* point to start of 'reserved area' */ + return p_src; /* point to start of 'reserved area' */ } DUK_INTERNAL duk_uint8_t *duk_bw_insert_ensure_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len) { @@ -260,9 +266,7 @@ p_dst = p_base + off; p_src = p_dst + len; move_sz = (duk_size_t) (bw->p - p_src); - duk_memmove_unsafe((void *) p_dst, - (const void *) p_src, - (size_t) move_sz); + duk_memmove_unsafe((void *) p_dst, (const void *) p_src, (size_t) move_sz); bw->p -= len; } @@ -276,11 +280,7 @@ DUK_ASSERT(bw_ctx != NULL); DUK_ASSERT(bw_ctx->buf != NULL); DUK_ASSERT((DUK_HBUFFER_DYNAMIC_GET_SIZE(bw_ctx->buf) == 0) || - (bw_ctx->p != NULL && - bw_ctx->p_base != NULL && - bw_ctx->p_limit != NULL && - bw_ctx->p_limit >= bw_ctx->p_base && - bw_ctx->p >= bw_ctx->p_base && - bw_ctx->p <= bw_ctx->p_limit)); + (bw_ctx->p != NULL && bw_ctx->p_base != NULL && bw_ctx->p_limit != NULL && bw_ctx->p_limit >= bw_ctx->p_base && + bw_ctx->p >= bw_ctx->p_base && bw_ctx->p <= bw_ctx->p_limit)); } #endif
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_util_cast.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_util_cast.c
Changed
@@ -17,7 +17,8 @@ * relying on fmin(), fmax(), or other intrinsics. Out-of-range results are * not assumed by caller, but here value is clamped, NaN converts to minval. */ -#define DUK__DOUBLE_INT_CAST1(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST1(tname, minval, maxval) \ + do { \ if (DUK_LIKELY(x >= (duk_double_t) (minval))) { \ DUK_ASSERT(!DUK_ISNAN(x)); \ if (DUK_LIKELY(x <= (duk_double_t) (maxval))) { \ @@ -38,19 +39,22 @@ * argument is a NaN, return the second argument. This avoids a * NaN-to-integer cast which is undefined behavior. */ -#define DUK__DOUBLE_INT_CAST2(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST2(tname, minval, maxval) \ + do { \ return (tname) duk_double_fmin(duk_double_fmax(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ } while (0) /* Another solution which doesn't need C99+ behavior for fmin() and fmax(). */ -#define DUK__DOUBLE_INT_CAST3(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST3(tname, minval, maxval) \ + do { \ if (DUK_ISNAN(x)) { \ /* 0 or any other value is fine. */ \ return (tname) 0; \ } else \ return (tname) DUK_FMIN(DUK_FMAX(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ - } \ - } while (0) + } \ + } \ + while (0) /* C99+ solution: relies on specific fmin() and fmax() behavior in C99: if * one argument is NaN but the other isn't, the non-NaN argument is returned. @@ -59,7 +63,8 @@ * the fmin() and fmax() calls (unless one uses -ffast-math which we don't * support). */ -#define DUK__DOUBLE_INT_CAST4(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST4(tname, minval, maxval) \ + do { \ return (tname) DUK_FMIN(DUK_FMAX(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ } while (0) @@ -103,12 +108,12 @@ * infinity, at least on x64. This number is one double unit below that * midpoint. See misc/float_cast.c. */ -#define DUK__FLOAT_ROUND_LIMIT 340282356779733623858607532500980858880.0 +#define DUK__FLOAT_ROUND_LIMIT 340282356779733623858607532500980858880.0 /* Maximum IEEE float. Double-to-float conversion above this would be out of * range and thus technically undefined behavior. */ -#define DUK__FLOAT_MAX 340282346638528859811704183484516925440.0 +#define DUK__FLOAT_MAX 340282346638528859811704183484516925440.0 DUK_INTERNAL duk_float_t duk_double_to_float_t(duk_double_t x) { /* Even a double-to-float cast is technically undefined behavior if @@ -127,8 +132,7 @@ duk_double_t t; t = DUK_FABS(x); - DUK_ASSERT((DUK_ISNAN(x) && DUK_ISNAN(t)) || - (!DUK_ISNAN(x) && !DUK_ISNAN(t))); + DUK_ASSERT((DUK_ISNAN(x) && DUK_ISNAN(t)) || (!DUK_ISNAN(x) && !DUK_ISNAN(t))); if (DUK_LIKELY(t <= DUK__FLOAT_MAX)) { /* Standard in-range case, try to get here with a minimum
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_util_double.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_util_double.c
Changed
@@ -108,7 +108,7 @@ DUK_INTERNAL duk_double_t duk_double_trunc_towards_zero(duk_double_t x) { /* XXX: optimize */ duk_small_uint_t s = duk_double_signbit(x); - x = DUK_FLOOR(DUK_FABS(x)); /* truncate towards zero */ + x = DUK_FLOOR(DUK_FABS(x)); /* truncate towards zero */ if (s) { x = -x; }
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_util_hashbytes.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_util_hashbytes.c
Changed
@@ -11,8 +11,8 @@ #if defined(DUK_USE_STRHASH_DENSE) /* 'magic' constants for Murmurhash2 */ -#define DUK__MAGIC_M ((duk_uint32_t) 0x5bd1e995UL) -#define DUK__MAGIC_R 24 +#define DUK__MAGIC_M ((duk_uint32_t) 0x5bd1e995UL) +#define DUK__MAGIC_R 24 DUK_INTERNAL duk_uint32_t duk_util_hashbytes(const duk_uint8_t *data, duk_size_t len, duk_uint32_t seed) { duk_uint32_t h = seed ^ ((duk_uint32_t) len); @@ -26,9 +26,7 @@ #if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS) duk_uint32_t k = *((const duk_uint32_t *) (const void *) data); #else - duk_uint32_t k = ((duk_uint32_t) data0) | - (((duk_uint32_t) data1) << 8) | - (((duk_uint32_t) data2) << 16) | + duk_uint32_t k = ((duk_uint32_t) data0) | (((duk_uint32_t) data1) << 8) | (((duk_uint32_t) data2) << 16) | (((duk_uint32_t) data3) << 24); #endif @@ -42,11 +40,14 @@ } switch (len) { - case 3: h ^= data2 << 16; - case 2: h ^= data1 << 8; - case 1: h ^= data0; - h *= DUK__MAGIC_M; - } + case 3: + h ^= data2 << 16; + case 2: + h ^= data1 << 8; + case 1: + h ^= data0; + h *= DUK__MAGIC_M; + } h ^= h >> 13; h *= DUK__MAGIC_M; @@ -54,4 +55,4 @@ return h; } -#endif /* DUK_USE_STRHASH_DENSE */ +#endif /* DUK_USE_STRHASH_DENSE */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_util_memory.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_util_memory.c
Changed
@@ -16,7 +16,7 @@ DUK_ASSERT(s2 != NULL); return DUK_MEMCMP(s1, s2, (size_t) len); } -#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ DUK_INTERNAL DUK_INLINE duk_small_int_t duk_memcmp_unsafe(const void *s1, const void *s2, duk_size_t len) { DUK_ASSERT(s1 != NULL || len == 0U); DUK_ASSERT(s2 != NULL || len == 0U); @@ -33,4 +33,4 @@ DUK_ASSERT(s2 != NULL); return DUK_MEMCMP(s1, s2, (size_t) len); } -#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_util_misc.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_util_misc.c
Changed
@@ -10,23 +10,17 @@ */ DUK_INTERNAL const duk_uint8_t duk_lc_digits36 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_LC_A, DUK_ASC_LC_B, - DUK_ASC_LC_C, DUK_ASC_LC_D, DUK_ASC_LC_E, DUK_ASC_LC_F, - DUK_ASC_LC_G, DUK_ASC_LC_H, DUK_ASC_LC_I, DUK_ASC_LC_J, - DUK_ASC_LC_K, DUK_ASC_LC_L, DUK_ASC_LC_M, DUK_ASC_LC_N, - DUK_ASC_LC_O, DUK_ASC_LC_P, DUK_ASC_LC_Q, DUK_ASC_LC_R, - DUK_ASC_LC_S, DUK_ASC_LC_T, DUK_ASC_LC_U, DUK_ASC_LC_V, + DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_LC_A, DUK_ASC_LC_B, DUK_ASC_LC_C, DUK_ASC_LC_D, DUK_ASC_LC_E, DUK_ASC_LC_F, + DUK_ASC_LC_G, DUK_ASC_LC_H, DUK_ASC_LC_I, DUK_ASC_LC_J, DUK_ASC_LC_K, DUK_ASC_LC_L, DUK_ASC_LC_M, DUK_ASC_LC_N, + DUK_ASC_LC_O, DUK_ASC_LC_P, DUK_ASC_LC_Q, DUK_ASC_LC_R, DUK_ASC_LC_S, DUK_ASC_LC_T, DUK_ASC_LC_U, DUK_ASC_LC_V, DUK_ASC_LC_W, DUK_ASC_LC_X, DUK_ASC_LC_Y, DUK_ASC_LC_Z }; -DUK_INTERNAL const duk_uint8_t duk_uc_nybbles16 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_UC_A, DUK_ASC_UC_B, - DUK_ASC_UC_C, DUK_ASC_UC_D, DUK_ASC_UC_E, DUK_ASC_UC_F -}; +DUK_INTERNAL const duk_uint8_t duk_uc_nybbles16 = { DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, + DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_UC_A, DUK_ASC_UC_B, + DUK_ASC_UC_C, DUK_ASC_UC_D, DUK_ASC_UC_E, DUK_ASC_UC_F }; /* * Table for hex decoding ASCII hex digits @@ -34,43 +28,43 @@ DUK_INTERNAL const duk_int8_t duk_hex_dectab256 = { /* -1 if invalid */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ }; #if defined(DUK_USE_HEX_FASTPATH) /* Preshifted << 4. Must use 16-bit entry to allow negative value signaling. */ DUK_INTERNAL const duk_int16_t duk_hex_dectab_shift4256 = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ - 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ - -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ - -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ + 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ + -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ + -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ }; #endif @@ -89,77 +83,53 @@ * print('0x' + t.encode('hex') + 'U') * print('big endian'); genhextab(False) * print('little endian'); genhextab(True) -*/ + */ DUK_INTERNAL const duk_uint16_t duk_hex_enctab256 = { #if defined(DUK_USE_INTEGER_BE) - 0x3030U, 0x3031U, 0x3032U, 0x3033U, 0x3034U, 0x3035U, 0x3036U, 0x3037U, - 0x3038U, 0x3039U, 0x3061U, 0x3062U, 0x3063U, 0x3064U, 0x3065U, 0x3066U, - 0x3130U, 0x3131U, 0x3132U, 0x3133U, 0x3134U, 0x3135U, 0x3136U, 0x3137U, - 0x3138U, 0x3139U, 0x3161U, 0x3162U, 0x3163U, 0x3164U, 0x3165U, 0x3166U, - 0x3230U, 0x3231U, 0x3232U, 0x3233U, 0x3234U, 0x3235U, 0x3236U, 0x3237U, - 0x3238U, 0x3239U, 0x3261U, 0x3262U, 0x3263U, 0x3264U, 0x3265U, 0x3266U, - 0x3330U, 0x3331U, 0x3332U, 0x3333U, 0x3334U, 0x3335U, 0x3336U, 0x3337U, - 0x3338U, 0x3339U, 0x3361U, 0x3362U, 0x3363U, 0x3364U, 0x3365U, 0x3366U, - 0x3430U, 0x3431U, 0x3432U, 0x3433U, 0x3434U, 0x3435U, 0x3436U, 0x3437U, - 0x3438U, 0x3439U, 0x3461U, 0x3462U, 0x3463U, 0x3464U, 0x3465U, 0x3466U, - 0x3530U, 0x3531U, 0x3532U, 0x3533U, 0x3534U, 0x3535U, 0x3536U, 0x3537U, - 0x3538U, 0x3539U, 0x3561U, 0x3562U, 0x3563U, 0x3564U, 0x3565U, 0x3566U, - 0x3630U, 0x3631U, 0x3632U, 0x3633U, 0x3634U, 0x3635U, 0x3636U, 0x3637U, - 0x3638U, 0x3639U, 0x3661U, 0x3662U, 0x3663U, 0x3664U, 0x3665U, 0x3666U, - 0x3730U, 0x3731U, 0x3732U, 0x3733U, 0x3734U, 0x3735U, 0x3736U, 0x3737U, - 0x3738U, 0x3739U, 0x3761U, 0x3762U, 0x3763U, 0x3764U, 0x3765U, 0x3766U, - 0x3830U, 0x3831U, 0x3832U, 0x3833U, 0x3834U, 0x3835U, 0x3836U, 0x3837U, - 0x3838U, 0x3839U, 0x3861U, 0x3862U, 0x3863U, 0x3864U, 0x3865U, 0x3866U, - 0x3930U, 0x3931U, 0x3932U, 0x3933U, 0x3934U, 0x3935U, 0x3936U, 0x3937U, - 0x3938U, 0x3939U, 0x3961U, 0x3962U, 0x3963U, 0x3964U, 0x3965U, 0x3966U, - 0x6130U, 0x6131U, 0x6132U, 0x6133U, 0x6134U, 0x6135U, 0x6136U, 0x6137U, - 0x6138U, 0x6139U, 0x6161U, 0x6162U, 0x6163U, 0x6164U, 0x6165U, 0x6166U, - 0x6230U, 0x6231U, 0x6232U, 0x6233U, 0x6234U, 0x6235U, 0x6236U, 0x6237U, - 0x6238U, 0x6239U, 0x6261U, 0x6262U, 0x6263U, 0x6264U, 0x6265U, 0x6266U, - 0x6330U, 0x6331U, 0x6332U, 0x6333U, 0x6334U, 0x6335U, 0x6336U, 0x6337U, - 0x6338U, 0x6339U, 0x6361U, 0x6362U, 0x6363U, 0x6364U, 0x6365U, 0x6366U, - 0x6430U, 0x6431U, 0x6432U, 0x6433U, 0x6434U, 0x6435U, 0x6436U, 0x6437U, - 0x6438U, 0x6439U, 0x6461U, 0x6462U, 0x6463U, 0x6464U, 0x6465U, 0x6466U, - 0x6530U, 0x6531U, 0x6532U, 0x6533U, 0x6534U, 0x6535U, 0x6536U, 0x6537U, - 0x6538U, 0x6539U, 0x6561U, 0x6562U, 0x6563U, 0x6564U, 0x6565U, 0x6566U, - 0x6630U, 0x6631U, 0x6632U, 0x6633U, 0x6634U, 0x6635U, 0x6636U, 0x6637U, - 0x6638U, 0x6639U, 0x6661U, 0x6662U, 0x6663U, 0x6664U, 0x6665U, 0x6666U -#else /* DUK_USE_INTEGER_BE */ - 0x3030U, 0x3130U, 0x3230U, 0x3330U, 0x3430U, 0x3530U, 0x3630U, 0x3730U, - 0x3830U, 0x3930U, 0x6130U, 0x6230U, 0x6330U, 0x6430U, 0x6530U, 0x6630U, - 0x3031U, 0x3131U, 0x3231U, 0x3331U, 0x3431U, 0x3531U, 0x3631U, 0x3731U, - 0x3831U, 0x3931U, 0x6131U, 0x6231U, 0x6331U, 0x6431U, 0x6531U, 0x6631U, - 0x3032U, 0x3132U, 0x3232U, 0x3332U, 0x3432U, 0x3532U, 0x3632U, 0x3732U, - 0x3832U, 0x3932U, 0x6132U, 0x6232U, 0x6332U, 0x6432U, 0x6532U, 0x6632U, - 0x3033U, 0x3133U, 0x3233U, 0x3333U, 0x3433U, 0x3533U, 0x3633U, 0x3733U, - 0x3833U, 0x3933U, 0x6133U, 0x6233U, 0x6333U, 0x6433U, 0x6533U, 0x6633U, - 0x3034U, 0x3134U, 0x3234U, 0x3334U, 0x3434U, 0x3534U, 0x3634U, 0x3734U, - 0x3834U, 0x3934U, 0x6134U, 0x6234U, 0x6334U, 0x6434U, 0x6534U, 0x6634U, - 0x3035U, 0x3135U, 0x3235U, 0x3335U, 0x3435U, 0x3535U, 0x3635U, 0x3735U, - 0x3835U, 0x3935U, 0x6135U, 0x6235U, 0x6335U, 0x6435U, 0x6535U, 0x6635U, - 0x3036U, 0x3136U, 0x3236U, 0x3336U, 0x3436U, 0x3536U, 0x3636U, 0x3736U, - 0x3836U, 0x3936U, 0x6136U, 0x6236U, 0x6336U, 0x6436U, 0x6536U, 0x6636U, - 0x3037U, 0x3137U, 0x3237U, 0x3337U, 0x3437U, 0x3537U, 0x3637U, 0x3737U, - 0x3837U, 0x3937U, 0x6137U, 0x6237U, 0x6337U, 0x6437U, 0x6537U, 0x6637U, - 0x3038U, 0x3138U, 0x3238U, 0x3338U, 0x3438U, 0x3538U, 0x3638U, 0x3738U, - 0x3838U, 0x3938U, 0x6138U, 0x6238U, 0x6338U, 0x6438U, 0x6538U, 0x6638U, - 0x3039U, 0x3139U, 0x3239U, 0x3339U, 0x3439U, 0x3539U, 0x3639U, 0x3739U, - 0x3839U, 0x3939U, 0x6139U, 0x6239U, 0x6339U, 0x6439U, 0x6539U, 0x6639U, - 0x3061U, 0x3161U, 0x3261U, 0x3361U, 0x3461U, 0x3561U, 0x3661U, 0x3761U, - 0x3861U, 0x3961U, 0x6161U, 0x6261U, 0x6361U, 0x6461U, 0x6561U, 0x6661U, - 0x3062U, 0x3162U, 0x3262U, 0x3362U, 0x3462U, 0x3562U, 0x3662U, 0x3762U, - 0x3862U, 0x3962U, 0x6162U, 0x6262U, 0x6362U, 0x6462U, 0x6562U, 0x6662U, - 0x3063U, 0x3163U, 0x3263U, 0x3363U, 0x3463U, 0x3563U, 0x3663U, 0x3763U, - 0x3863U, 0x3963U, 0x6163U, 0x6263U, 0x6363U, 0x6463U, 0x6563U, 0x6663U, - 0x3064U, 0x3164U, 0x3264U, 0x3364U, 0x3464U, 0x3564U, 0x3664U, 0x3764U, - 0x3864U, 0x3964U, 0x6164U, 0x6264U, 0x6364U, 0x6464U, 0x6564U, 0x6664U, - 0x3065U, 0x3165U, 0x3265U, 0x3365U, 0x3465U, 0x3565U, 0x3665U, 0x3765U, - 0x3865U, 0x3965U, 0x6165U, 0x6265U, 0x6365U, 0x6465U, 0x6565U, 0x6665U, - 0x3066U, 0x3166U, 0x3266U, 0x3366U, 0x3466U, 0x3566U, 0x3666U, 0x3766U, - 0x3866U, 0x3966U, 0x6166U, 0x6266U, 0x6366U, 0x6466U, 0x6566U, 0x6666U -#endif /* DUK_USE_INTEGER_BE */ + 0x3030U, 0x3031U, 0x3032U, 0x3033U, 0x3034U, 0x3035U, 0x3036U, 0x3037U, 0x3038U, 0x3039U, 0x3061U, 0x3062U, 0x3063U, + 0x3064U, 0x3065U, 0x3066U, 0x3130U, 0x3131U, 0x3132U, 0x3133U, 0x3134U, 0x3135U, 0x3136U, 0x3137U, 0x3138U, 0x3139U, + 0x3161U, 0x3162U, 0x3163U, 0x3164U, 0x3165U, 0x3166U, 0x3230U, 0x3231U, 0x3232U, 0x3233U, 0x3234U, 0x3235U, 0x3236U, + 0x3237U, 0x3238U, 0x3239U, 0x3261U, 0x3262U, 0x3263U, 0x3264U, 0x3265U, 0x3266U, 0x3330U, 0x3331U, 0x3332U, 0x3333U, + 0x3334U, 0x3335U, 0x3336U, 0x3337U, 0x3338U, 0x3339U, 0x3361U, 0x3362U, 0x3363U, 0x3364U, 0x3365U, 0x3366U, 0x3430U, + 0x3431U, 0x3432U, 0x3433U, 0x3434U, 0x3435U, 0x3436U, 0x3437U, 0x3438U, 0x3439U, 0x3461U, 0x3462U, 0x3463U, 0x3464U, + 0x3465U, 0x3466U, 0x3530U, 0x3531U, 0x3532U, 0x3533U, 0x3534U, 0x3535U, 0x3536U, 0x3537U, 0x3538U, 0x3539U, 0x3561U, + 0x3562U, 0x3563U, 0x3564U, 0x3565U, 0x3566U, 0x3630U, 0x3631U, 0x3632U, 0x3633U, 0x3634U, 0x3635U, 0x3636U, 0x3637U, + 0x3638U, 0x3639U, 0x3661U, 0x3662U, 0x3663U, 0x3664U, 0x3665U, 0x3666U, 0x3730U, 0x3731U, 0x3732U, 0x3733U, 0x3734U, + 0x3735U, 0x3736U, 0x3737U, 0x3738U, 0x3739U, 0x3761U, 0x3762U, 0x3763U, 0x3764U, 0x3765U, 0x3766U, 0x3830U, 0x3831U, + 0x3832U, 0x3833U, 0x3834U, 0x3835U, 0x3836U, 0x3837U, 0x3838U, 0x3839U, 0x3861U, 0x3862U, 0x3863U, 0x3864U, 0x3865U, + 0x3866U, 0x3930U, 0x3931U, 0x3932U, 0x3933U, 0x3934U, 0x3935U, 0x3936U, 0x3937U, 0x3938U, 0x3939U, 0x3961U, 0x3962U, + 0x3963U, 0x3964U, 0x3965U, 0x3966U, 0x6130U, 0x6131U, 0x6132U, 0x6133U, 0x6134U, 0x6135U, 0x6136U, 0x6137U, 0x6138U, + 0x6139U, 0x6161U, 0x6162U, 0x6163U, 0x6164U, 0x6165U, 0x6166U, 0x6230U, 0x6231U, 0x6232U, 0x6233U, 0x6234U, 0x6235U, + 0x6236U, 0x6237U, 0x6238U, 0x6239U, 0x6261U, 0x6262U, 0x6263U, 0x6264U, 0x6265U, 0x6266U, 0x6330U, 0x6331U, 0x6332U, + 0x6333U, 0x6334U, 0x6335U, 0x6336U, 0x6337U, 0x6338U, 0x6339U, 0x6361U, 0x6362U, 0x6363U, 0x6364U, 0x6365U, 0x6366U, + 0x6430U, 0x6431U, 0x6432U, 0x6433U, 0x6434U, 0x6435U, 0x6436U, 0x6437U, 0x6438U, 0x6439U, 0x6461U, 0x6462U, 0x6463U, + 0x6464U, 0x6465U, 0x6466U, 0x6530U, 0x6531U, 0x6532U, 0x6533U, 0x6534U, 0x6535U, 0x6536U, 0x6537U, 0x6538U, 0x6539U, + 0x6561U, 0x6562U, 0x6563U, 0x6564U, 0x6565U, 0x6566U, 0x6630U, 0x6631U, 0x6632U, 0x6633U, 0x6634U, 0x6635U, 0x6636U, + 0x6637U, 0x6638U, 0x6639U, 0x6661U, 0x6662U, 0x6663U, 0x6664U, 0x6665U, 0x6666U +#else /* DUK_USE_INTEGER_BE */ + 0x3030U, 0x3130U, 0x3230U, 0x3330U, 0x3430U, 0x3530U, 0x3630U, 0x3730U, 0x3830U, 0x3930U, 0x6130U, 0x6230U, 0x6330U, + 0x6430U, 0x6530U, 0x6630U, 0x3031U, 0x3131U, 0x3231U, 0x3331U, 0x3431U, 0x3531U, 0x3631U, 0x3731U, 0x3831U, 0x3931U, + 0x6131U, 0x6231U, 0x6331U, 0x6431U, 0x6531U, 0x6631U, 0x3032U, 0x3132U, 0x3232U, 0x3332U, 0x3432U, 0x3532U, 0x3632U, + 0x3732U, 0x3832U, 0x3932U, 0x6132U, 0x6232U, 0x6332U, 0x6432U, 0x6532U, 0x6632U, 0x3033U, 0x3133U, 0x3233U, 0x3333U, + 0x3433U, 0x3533U, 0x3633U, 0x3733U, 0x3833U, 0x3933U, 0x6133U, 0x6233U, 0x6333U, 0x6433U, 0x6533U, 0x6633U, 0x3034U, + 0x3134U, 0x3234U, 0x3334U, 0x3434U, 0x3534U, 0x3634U, 0x3734U, 0x3834U, 0x3934U, 0x6134U, 0x6234U, 0x6334U, 0x6434U, + 0x6534U, 0x6634U, 0x3035U, 0x3135U, 0x3235U, 0x3335U, 0x3435U, 0x3535U, 0x3635U, 0x3735U, 0x3835U, 0x3935U, 0x6135U, + 0x6235U, 0x6335U, 0x6435U, 0x6535U, 0x6635U, 0x3036U, 0x3136U, 0x3236U, 0x3336U, 0x3436U, 0x3536U, 0x3636U, 0x3736U, + 0x3836U, 0x3936U, 0x6136U, 0x6236U, 0x6336U, 0x6436U, 0x6536U, 0x6636U, 0x3037U, 0x3137U, 0x3237U, 0x3337U, 0x3437U, + 0x3537U, 0x3637U, 0x3737U, 0x3837U, 0x3937U, 0x6137U, 0x6237U, 0x6337U, 0x6437U, 0x6537U, 0x6637U, 0x3038U, 0x3138U, + 0x3238U, 0x3338U, 0x3438U, 0x3538U, 0x3638U, 0x3738U, 0x3838U, 0x3938U, 0x6138U, 0x6238U, 0x6338U, 0x6438U, 0x6538U, + 0x6638U, 0x3039U, 0x3139U, 0x3239U, 0x3339U, 0x3439U, 0x3539U, 0x3639U, 0x3739U, 0x3839U, 0x3939U, 0x6139U, 0x6239U, + 0x6339U, 0x6439U, 0x6539U, 0x6639U, 0x3061U, 0x3161U, 0x3261U, 0x3361U, 0x3461U, 0x3561U, 0x3661U, 0x3761U, 0x3861U, + 0x3961U, 0x6161U, 0x6261U, 0x6361U, 0x6461U, 0x6561U, 0x6661U, 0x3062U, 0x3162U, 0x3262U, 0x3362U, 0x3462U, 0x3562U, + 0x3662U, 0x3762U, 0x3862U, 0x3962U, 0x6162U, 0x6262U, 0x6362U, 0x6462U, 0x6562U, 0x6662U, 0x3063U, 0x3163U, 0x3263U, + 0x3363U, 0x3463U, 0x3563U, 0x3663U, 0x3763U, 0x3863U, 0x3963U, 0x6163U, 0x6263U, 0x6363U, 0x6463U, 0x6563U, 0x6663U, + 0x3064U, 0x3164U, 0x3264U, 0x3364U, 0x3464U, 0x3564U, 0x3664U, 0x3764U, 0x3864U, 0x3964U, 0x6164U, 0x6264U, 0x6364U, + 0x6464U, 0x6564U, 0x6664U, 0x3065U, 0x3165U, 0x3265U, 0x3365U, 0x3465U, 0x3565U, 0x3665U, 0x3765U, 0x3865U, 0x3965U, + 0x6165U, 0x6265U, 0x6365U, 0x6465U, 0x6565U, 0x6665U, 0x3066U, 0x3166U, 0x3266U, 0x3366U, 0x3466U, 0x3566U, 0x3666U, + 0x3766U, 0x3866U, 0x3966U, 0x6166U, 0x6266U, 0x6366U, 0x6466U, 0x6566U, 0x6666U +#endif /* DUK_USE_INTEGER_BE */ }; -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ /* * Arbitrary byteswap for potentially unaligned values @@ -167,7 +137,7 @@ * Used to byteswap pointers e.g. in debugger code. */ -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ DUK_INTERNAL void duk_byteswap_bytes(duk_uint8_t *p, duk_small_uint_t len) { duk_uint8_t tmp; duk_uint8_t *q = p + len - 1; @@ -181,3 +151,15 @@ } } #endif + +/* + * Random + */ + +DUK_INTERNAL duk_double_t duk_util_get_random_double(duk_hthread *thr) { +#if defined(DUK_USE_GET_RANDOM_DOUBLE) + return DUK_USE_GET_RANDOM_DOUBLE(thr->heap->heap_udata); +#else + return duk_util_tinyrandom_get_double(thr); +#endif +}
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duk_util_tinyrandom.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duk_util_tinyrandom.c
Changed
@@ -21,15 +21,16 @@ #endif #if defined(DUK__RANDOM_SHAMIR3OP) -#define DUK__UPDATE_RND(rnd) do { \ +#define DUK__UPDATE_RND(rnd) \ + do { \ (rnd) += ((rnd) * (rnd)) | 0x05UL; \ - (rnd) = ((rnd) & 0xffffffffUL); /* if duk_uint32_t is exactly 32 bits, this is a NOP */ \ + (rnd) = ((rnd) &0xffffffffUL); /* if duk_uint32_t is exactly 32 bits, this is a NOP */ \ } while (0) -#define DUK__RND_BIT(rnd) ((rnd) >> 31) /* only use the highest bit */ +#define DUK__RND_BIT(rnd) ((rnd) >> 31) /* only use the highest bit */ DUK_INTERNAL void duk_util_tinyrandom_prepare_seed(duk_hthread *thr) { - DUK_UNREF(thr); /* Nothing now. */ + DUK_UNREF(thr); /* Nothing now. */ } DUK_INTERNAL duk_double_t duk_util_tinyrandom_get_double(duk_hthread *thr) { @@ -39,7 +40,7 @@ rnd = thr->heap->rnd_state; - n = 53; /* enough to cover the whole mantissa */ + n = 53; /* enough to cover the whole mantissa */ t = 0.0; do { @@ -55,7 +56,7 @@ return t; } -#endif /* DUK__RANDOM_SHAMIR3OP */ +#endif /* DUK__RANDOM_SHAMIR3OP */ #if defined(DUK__RANDOM_XOROSHIRO128PLUS) DUK_LOCAL DUK_ALWAYS_INLINE duk_uint64_t duk__rnd_splitmix64(duk_uint64_t *x) { @@ -94,9 +95,9 @@ * because current seed is Date.now()) result in different xoroshiro128+ * seeds. */ - x = thr->heap->rnd_state0; /* Only 0 is used as input here. */ + x = thr->heap->rnd_state0; /* Only 0 is used as input here. */ for (i = 0; i < 64; i++) { - thr->heap->rnd_statei & 0x01 = duk__rnd_splitmix64(&x); /* Keep last 2 values. */ + thr->heap->rnd_statei & 0x01 = duk__rnd_splitmix64(&x); /* Keep last 2 values. */ } } @@ -120,6 +121,6 @@ #endif return du.d - 1.0; } -#endif /* DUK__RANDOM_XOROSHIRO128PLUS */ +#endif /* DUK__RANDOM_XOROSHIRO128PLUS */ -#endif /* !DUK_USE_GET_RANDOM_DOUBLE */ +#endif /* !DUK_USE_GET_RANDOM_DOUBLE */
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src-separate/duktape.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src-separate/duktape.h
Changed
@@ -1,13 +1,13 @@ /* - * Duktape public API for Duktape 2.6.0. + * Duktape public API for Duktape 2.7.0. * * See the API reference for documentation on call semantics. The exposed, * supported API is between the "BEGIN PUBLIC API" and "END PUBLIC API" * comments. Other parts of the header are Duktape internal and related to * e.g. platform/compiler/feature detection. * - * Git commit fffa346eff06a8764b02c31d4336f63a773a95c3 (v2.6.0). - * Git branch v2-maintenance. + * Git commit 03d4d728f8365021de6955c649e6dcd05dcca99f (03d4d72-dirty). + * Git branch HEAD. * * See Duktape AUTHORS.rst and LICENSE.txt for copyright and * licensing information. @@ -21,7 +21,7 @@ * * (http://opensource.org/licenses/MIT) * - * Copyright (c) 2013-2019 by Duktape authors (see AUTHORS.rst) + * Copyright (c) 2013-present by Duktape authors (see AUTHORS.rst) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -110,6 +110,12 @@ * * Luis de Bethencourt (https://github.com/luisbg) * * Ian Whyman (https://github.com/v00d00) * * Rick Sayre (https://github.com/whorfin) + * * Craig Leres (https://github.com/leres) + * * Maurici Abad (https://github.com/mauriciabad) + * * Nancy Li (https://github.com/NancyLi1013) + * * William Parks (https://github.com/WilliamParks) + * * Sam Hellawell (https://github.com/samhellawell) + * * Vladislavs Sokurenko (https://github.com/sokurenko) * * Other contributions * =================== @@ -176,16 +182,16 @@ * development snapshots have 99 for patch level (e.g. 0.10.99 would be a * development version after 0.10.0 but before the next official release). */ -#define DUK_VERSION 20600L +#define DUK_VERSION 20700L /* Git commit, describe, and branch for Duktape build. Useful for * non-official snapshot builds so that application code can easily log * which Duktape snapshot was used. Not available in the ECMAScript * environment. */ -#define DUK_GIT_COMMIT "fffa346eff06a8764b02c31d4336f63a773a95c3" -#define DUK_GIT_DESCRIBE "v2.6.0" -#define DUK_GIT_BRANCH "v2-maintenance" +#define DUK_GIT_COMMIT "03d4d728f8365021de6955c649e6dcd05dcca99f" +#define DUK_GIT_DESCRIBE "03d4d72-dirty" +#define DUK_GIT_BRANCH "HEAD" /* External duk_config.h provides platform/compiler/OS dependent * typedefs and macros, and DUK_USE_xxx config options so that
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src/duk_config.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src/duk_config.h
Changed
@@ -1,9 +1,9 @@ /* * duk_config.h configuration header generated by genconfig.py. * - * Git commit: fffa346eff06a8764b02c31d4336f63a773a95c3 - * Git describe: v2.6.0 - * Git branch: v2-maintenance + * Git commit: 03d4d728f8365021de6955c649e6dcd05dcca99f + * Git describe: 03d4d72-dirty + * Git branch: HEAD * * Supported platforms: * - Mac OSX, iPhone, Darwin
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src/duk_source_meta.json -> _service:tar_scm:duktape-2.7.0.tar.xz/src/duk_source_meta.json
Changed
@@ -1,737 +1,737 @@ { "comment": "Metadata for Duktape sources", - "duk_version_string": "2.6.0", + "duk_version_string": "2.7.0", "type": "duk_source_meta", "line_map": { "original_line": 1, - "combined_line": 156, + "combined_line": 162, "original_file": "duk_replacements.c" }, { "original_line": 1, - "combined_line": 166, + "combined_line": 172, "original_file": "duk_internal.h" }, { "original_line": 1, - "combined_line": 204, + "combined_line": 210, "original_file": "duk_dblunion.h" }, { "original_line": 1, - "combined_line": 630, + "combined_line": 631, "original_file": "duk_fltunion.h" }, { "original_line": 1, - "combined_line": 671, + "combined_line": 672, "original_file": "duk_replacements.h" }, { "original_line": 1, - "combined_line": 702, + "combined_line": 703, "original_file": "duk_jmpbuf.h" }, { "original_line": 1, - "combined_line": 728, + "combined_line": 729, "original_file": "duk_exception.h" }, { "original_line": 1, - "combined_line": 760, + "combined_line": 762, "original_file": "duk_forwdecl.h" }, { "original_line": 1, - "combined_line": 896, + "combined_line": 898, "original_file": "duk_tval.h" }, { "original_line": 1, - "combined_line": 1537, + "combined_line": 1577, "original_file": "duk_builtins.h" }, { "original_line": 45, - "combined_line": 2329, + "combined_line": 2369, "original_file": "duk_internal.h" }, { "original_line": 1, - "combined_line": 2332, + "combined_line": 2372, "original_file": "duk_util.h" }, { "original_line": 1, - "combined_line": 3065, + "combined_line": 3169, "original_file": "duk_strings.h" }, { "original_line": 1, - "combined_line": 3236, + "combined_line": 3340, "original_file": "duk_js_bytecode.h" }, { "original_line": 1, - "combined_line": 3720, + "combined_line": 3815, "original_file": "duk_lexer.h" }, { "original_line": 1, - "combined_line": 4160, + "combined_line": 4252, "original_file": "duk_js_compiler.h" }, { "original_line": 1, - "combined_line": 4389, + "combined_line": 4486, "original_file": "duk_regexp.h" }, { "original_line": 1, - "combined_line": 4475, + "combined_line": 4572, "original_file": "duk_heaphdr.h" }, { "original_line": 1, - "combined_line": 4774, + "combined_line": 4890, "original_file": "duk_refcount.h" }, { "original_line": 1, - "combined_line": 5501, + "combined_line": 5908, "original_file": "duk_api_internal.h" }, { "original_line": 1, - "combined_line": 5889, + "combined_line": 6303, "original_file": "duk_hstring.h" }, { "original_line": 1, - "combined_line": 6144, + "combined_line": 6570, "original_file": "duk_hobject.h" }, { "original_line": 1, - "combined_line": 7127, + "combined_line": 7561, "original_file": "duk_hcompfunc.h" }, { "original_line": 1, - "combined_line": 7402, + "combined_line": 7822, "original_file": "duk_hnatfunc.h" }, { "original_line": 1, - "combined_line": 7443, + "combined_line": 7868, "original_file": "duk_hboundfunc.h" }, { "original_line": 1, - "combined_line": 7482, + "combined_line": 7912, "original_file": "duk_hbufobj.h" }, { "original_line": 1, - "combined_line": 7611, + "combined_line": 8051, "original_file": "duk_hthread.h" }, { "original_line": 1, - "combined_line": 8021, + "combined_line": 8474, "original_file": "duk_harray.h" }, { "original_line": 1, - "combined_line": 8071, + "combined_line": 8535, "original_file": "duk_henv.h" }, { "original_line": 1, - "combined_line": 8118, + "combined_line": 8592, "original_file": "duk_hbuffer.h" }, { "original_line": 1, - "combined_line": 8456, + "combined_line": 8941, "original_file": "duk_hproxy.h" }, { "original_line": 1, - "combined_line": 8484, + "combined_line": 8974, "original_file": "duk_heap.h" }, { "original_line": 1, - "combined_line": 9209, + "combined_line": 9722, "original_file": "duk_debugger.h" }, { "original_line": 1, - "combined_line": 9362, + "combined_line": 9875, "original_file": "duk_debug.h" }, { "original_line": 1, - "combined_line": 9548, + "combined_line": 10073, "original_file": "duk_error.h" }, { "original_line": 1, - "combined_line": 10075, + "combined_line": 10764, "original_file": "duk_unicode.h" }, { "original_line": 1, - "combined_line": 10367, + "combined_line": 11065, "original_file": "duk_json.h" }, { "original_line": 1, - "combined_line": 10437, + "combined_line": 11135, "original_file": "duk_js.h" }, { "original_line": 1, - "combined_line": 10555, + "combined_line": 11270, "original_file": "duk_numconv.h" }, { "original_line": 1, - "combined_line": 10661, + "combined_line": 11379, "original_file": "duk_bi_protos.h" }, { "original_line": 1, - "combined_line": 10744, + "combined_line": 11462, "original_file": "duk_selftest.h" }, { "original_line": 76, - "combined_line": 10760, + "combined_line": 11478, "original_file": "duk_internal.h" }, { "original_line": 10, - "combined_line": 10763, + "combined_line": 11481, "original_file": "duk_replacements.c" }, { "original_line": 1, - "combined_line": 10837, + "combined_line": 11555, "original_file": "duk_debug_macros.c" }, { "original_line": 1, - "combined_line": 10929, + "combined_line": 11647, "original_file": "duk_builtins.c" }, { "original_line": 1, - "combined_line": 11794, + "combined_line": 12512, "original_file": "duk_error_macros.c" }, { "original_line": 1, - "combined_line": 11950, + "combined_line": 12700, "original_file": "duk_unicode_support.c" }, { "original_line": 1, - "combined_line": 13216, + "combined_line": 13926, "original_file": "duk_util_memrw.c" }, { "original_line": 1, - "combined_line": 13365, + "combined_line": 14075, "original_file": "duk_util_misc.c" }, { "original_line": 1, - "combined_line": 13549, + "combined_line": 14241, "original_file": "duk_hobject_class.c" }, { "original_line": 1, - "combined_line": 13679, + "combined_line": 14371, "original_file": "duk_alloc_default.c" }, { "original_line": 1, - "combined_line": 13714, + "combined_line": 14404, "original_file": "duk_api_buffer.c" }, { "original_line": 1, - "combined_line": 13788, + "combined_line": 14478, "original_file": "duk_api_bytecode.c" }, { "original_line": 1, - "combined_line": 14557, + "combined_line": 15258, "original_file": "duk_api_call.c" }, { "original_line": 1, - "combined_line": 15074, + "combined_line": 15777, "original_file": "duk_api_codec.c" }, { "original_line": 1, - "combined_line": 16001, + "combined_line": 16709, "original_file": "duk_api_compile.c" }, { "original_line": 1, - "combined_line": 16174, + "combined_line": 16884, "original_file": "duk_api_debug.c" }, { "original_line": 1, - "combined_line": 16436, + "combined_line": 17146, "original_file": "duk_api_heap.c" }, { "original_line": 1, - "combined_line": 16648, + "combined_line": 17356, "original_file": "duk_api_inspect.c" }, { "original_line": 1, - "combined_line": 16894, + "combined_line": 17628, "original_file": "duk_api_memory.c" }, { "original_line": 1, - "combined_line": 16975, + "combined_line": 17709, "original_file": "duk_api_object.c" }, { "original_line": 1, - "combined_line": 18026, + "combined_line": 18748, "original_file": "duk_api_random.c" }, { "original_line": 1, - "combined_line": 18036, + "combined_line": 18758, "original_file": "duk_api_stack.c" }, { "original_line": 1, - "combined_line": 24915, + "combined_line": 25667, "original_file": "duk_api_string.c" }, { "original_line": 1, - "combined_line": 25294, + "combined_line": 26047, "original_file": "duk_api_time.c" }, { "original_line": 1, - "combined_line": 25405, + "combined_line": 26158, "original_file": "duk_bi_array.c" }, { "original_line": 1, - "combined_line": 27061, + "combined_line": 27813, "original_file": "duk_bi_boolean.c" }, { "original_line": 1, - "combined_line": 27131, + "combined_line": 27883, "original_file": "duk_bi_buffer.c" }, { "original_line": 1, - "combined_line": 30068, + "combined_line": 30813, "original_file": "duk_bi_cbor.c" }, { "original_line": 1, - "combined_line": 31809, + "combined_line": 32737, "original_file": "duk_bi_date.c" }, { "original_line": 1, - "combined_line": 33628, + "combined_line": 34637, "original_file": "duk_bi_date_unix.c" }, { "original_line": 1, - "combined_line": 33958, + "combined_line": 34986, "original_file": "duk_bi_date_windows.c" }, { "original_line": 1, - "combined_line": 34152, + "combined_line": 35182, "original_file": "duk_bi_duktape.c" }, { "original_line": 1, - "combined_line": 34311, + "combined_line": 35333, "original_file": "duk_bi_encoding.c" }, { "original_line": 1, - "combined_line": 34850, + "combined_line": 35871, "original_file": "duk_bi_error.c" }, { "original_line": 1, - "combined_line": 35243, + "combined_line": 36272, "original_file": "duk_bi_function.c" }, { "original_line": 1, - "combined_line": 35697, + "combined_line": 36726, "original_file": "duk_bi_global.c" }, { "original_line": 1, - "combined_line": 36429, + "combined_line": 37447, "original_file": "duk_bi_json.c" }, { "original_line": 1, - "combined_line": 39710, + "combined_line": 40691, "original_file": "duk_bi_math.c" }, { "original_line": 1, - "combined_line": 40230, + "combined_line": 41183, "original_file": "duk_bi_number.c" }, { "original_line": 1, - "combined_line": 40511, + "combined_line": 41449, "original_file": "duk_bi_object.c" }, { "original_line": 1, - "combined_line": 41315, + "combined_line": 42204, "original_file": "duk_bi_performance.c" }, { "original_line": 1, - "combined_line": 41347, + "combined_line": 42236, "original_file": "duk_bi_pointer.c" }, { "original_line": 1, - "combined_line": 41423, + "combined_line": 42311, "original_file": "duk_bi_promise.c" }, { "original_line": 1, - "combined_line": 41468, + "combined_line": 42356, "original_file": "duk_bi_proxy.c" }, { "original_line": 1, - "combined_line": 41567, + "combined_line": 42455, "original_file": "duk_bi_reflect.c" }, { "original_line": 1, - "combined_line": 41667, + "combined_line": 42555, "original_file": "duk_bi_regexp.c" }, { "original_line": 1, - "combined_line": 41894, + "combined_line": 42780, "original_file": "duk_bi_string.c" }, { "original_line": 1, - "combined_line": 43505, + "combined_line": 44396, "original_file": "duk_bi_symbol.c" }, { "original_line": 1, - "combined_line": 43676, + "combined_line": 44569, "original_file": "duk_bi_thread.c" }, { "original_line": 1, - "combined_line": 44003, + "combined_line": 44894, "original_file": "duk_bi_thrower.c" }, { "original_line": 1, - "combined_line": 44013, + "combined_line": 44904, "original_file": "duk_debug_fixedbuffer.c" }, { "original_line": 1, - "combined_line": 44083, + "combined_line": 44974, "original_file": "duk_debug_vsnprintf.c" }, { "original_line": 1, - "combined_line": 45184, + "combined_line": 46179, "original_file": "duk_debugger.c" }, { "original_line": 1, - "combined_line": 48099, + "combined_line": 49079, "original_file": "duk_error_augment.c" }, { "original_line": 1, - "combined_line": 48688, + "combined_line": 49682, "original_file": "duk_error_longjmp.c" }, { "original_line": 1, - "combined_line": 48792, + "combined_line": 49790, "original_file": "duk_error_misc.c" }, { "original_line": 1, - "combined_line": 48967, + "combined_line": 49964, "original_file": "duk_error_throw.c" }, { "original_line": 1, - "combined_line": 49130, + "combined_line": 50124, "original_file": "duk_hbuffer_alloc.c" }, { "original_line": 1, - "combined_line": 49263, + "combined_line": 50256, "original_file": "duk_hbuffer_assert.c" }, { "original_line": 1, - "combined_line": 49277, + "combined_line": 50270, "original_file": "duk_hbuffer_ops.c" }, { "original_line": 2, - "combined_line": 49357, + "combined_line": 50349, "original_file": "duk_hbufobj_misc.c" }, { "original_line": 1, - "combined_line": 49377, + "combined_line": 50369, "original_file": "duk_heap_alloc.c" }, { "original_line": 1, - "combined_line": 50603, + "combined_line": 51597, "original_file": "duk_heap_finalize.c" }, { "original_line": 1, - "combined_line": 51049, + "combined_line": 52047, "original_file": "duk_heap_hashstring.c" }, { "original_line": 1, - "combined_line": 51171, + "combined_line": 52169, "original_file": "duk_heap_markandsweep.c" }, { "original_line": 1, - "combined_line": 52658, + "combined_line": 53678, "original_file": "duk_heap_memory.c" }, { "original_line": 1, - "combined_line": 53071, + "combined_line": 54091, "original_file": "duk_heap_misc.c" }, { "original_line": 1, - "combined_line": 53259, + "combined_line": 54279, "original_file": "duk_heap_refcount.c" }, { "original_line": 1, - "combined_line": 54106, + "combined_line": 55139, "original_file": "duk_heap_stringcache.c" }, { "original_line": 1, - "combined_line": 54416, + "combined_line": 55460, "original_file": "duk_heap_stringtable.c" }, { "original_line": 1, - "combined_line": 55466, + "combined_line": 56531, "original_file": "duk_heaphdr_assert.c" }, { "original_line": 1, - "combined_line": 55545, + "combined_line": 56610, "original_file": "duk_hobject_alloc.c" }, { "original_line": 1, - "combined_line": 55817, + "combined_line": 56882, "original_file": "duk_hobject_assert.c" }, { "original_line": 1, - "combined_line": 55945, + "combined_line": 57007, "original_file": "duk_hobject_enum.c" }, { "original_line": 1, - "combined_line": 56662, + "combined_line": 57728, "original_file": "duk_hobject_misc.c" }, { "original_line": 1, - "combined_line": 56716, + "combined_line": 57785, "original_file": "duk_hobject_pc2line.c" }, { "original_line": 1, - "combined_line": 56961, + "combined_line": 58032, "original_file": "duk_hobject_props.c" }, { "original_line": 1, - "combined_line": 63177, + "combined_line": 64395, "original_file": "duk_hstring_assert.c" }, { "original_line": 1, - "combined_line": 63191, + "combined_line": 64409, "original_file": "duk_hstring_misc.c" }, { "original_line": 1, - "combined_line": 63388, + "combined_line": 64606, "original_file": "duk_hthread_alloc.c" }, { "original_line": 1, - "combined_line": 63448, + "combined_line": 64666, "original_file": "duk_hthread_builtins.c" }, { "original_line": 1, - "combined_line": 64335, + "combined_line": 65568, "original_file": "duk_hthread_misc.c" }, { "original_line": 1, - "combined_line": 64433, + "combined_line": 65666, "original_file": "duk_hthread_stacks.c" }, { "original_line": 1, - "combined_line": 64841, + "combined_line": 66072, "original_file": "duk_js_arith.c" }, { "original_line": 1, - "combined_line": 64979, + "combined_line": 66214, "original_file": "duk_js_call.c" }, { "original_line": 1, - "combined_line": 67917, + "combined_line": 69163, "original_file": "duk_js_compiler.c" }, { "original_line": 1, - "combined_line": 76028, + "combined_line": 77304, "original_file": "duk_js_executor.c" }, { "original_line": 1, - "combined_line": 81294, + "combined_line": 82627, "original_file": "duk_js_ops.c" }, { "original_line": 1, - "combined_line": 82773, + "combined_line": 84084, "original_file": "duk_js_var.c" }, { "original_line": 1, - "combined_line": 84571, + "combined_line": 85876, "original_file": "duk_lexer.c" }, { "original_line": 1, - "combined_line": 87033, + "combined_line": 88328, "original_file": "duk_numconv.c" }, { "original_line": 1, - "combined_line": 89327, + "combined_line": 90671, "original_file": "duk_regexp_compiler.c" }, { "original_line": 1, - "combined_line": 90619, + "combined_line": 91975, "original_file": "duk_regexp_executor.c" }, { "original_line": 1, - "combined_line": 91649, + "combined_line": 93031, "original_file": "duk_selftest.c" }, { "original_line": 2, - "combined_line": 92337, + "combined_line": 93779, "original_file": "duk_tval.c" }, { "original_line": 1, - "combined_line": 92489, + "combined_line": 93931, "original_file": "duk_unicode_tables.c" }, { "original_line": 1, - "combined_line": 98665, + "combined_line": 100107, "original_file": "duk_util_bitdecoder.c" }, { "original_line": 1, - "combined_line": 98832, + "combined_line": 100272, "original_file": "duk_util_bitencoder.c" }, { "original_line": 1, - "combined_line": 98876, + "combined_line": 100316, "original_file": "duk_util_bufwriter.c" }, { "original_line": 1, - "combined_line": 99163, + "combined_line": 100603, "original_file": "duk_util_cast.c" }, { "original_line": 1, - "combined_line": 99332, + "combined_line": 100776, "original_file": "duk_util_double.c" }, { "original_line": 1, - "combined_line": 99676, + "combined_line": 101120, "original_file": "duk_util_hashbytes.c" }, { "original_line": 1, - "combined_line": 99738, + "combined_line": 101183, "original_file": "duk_util_memory.c" }, { "original_line": 1, - "combined_line": 99775, + "combined_line": 101220, "original_file": "duk_util_tinyrandom.c" } , - "duk_version": 20600, - "git_branch": "v2-maintenance", - "git_commit": "fffa346eff06a8764b02c31d4336f63a773a95c3", + "duk_version": 20700, + "git_branch": "HEAD", + "git_commit": "03d4d728f8365021de6955c649e6dcd05dcca99f", "builtin_strings_info": { "plain": "Undefined", @@ -1738,7 +1738,7 @@ "c3RhdGlj", "eWllbGQ=" , - "git_describe": "v2.6.0", + "git_describe": "03d4d72-dirty", "builtin_strings": "Undefined", "Null",
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src/duktape.c -> _service:tar_scm:duktape-2.7.0.tar.xz/src/duktape.c
Changed
@@ -1,8 +1,8 @@ /* - * Single source autogenerated distributable for Duktape 2.6.0. + * Single source autogenerated distributable for Duktape 2.7.0. * - * Git commit fffa346eff06a8764b02c31d4336f63a773a95c3 (v2.6.0). - * Git branch v2-maintenance. + * Git commit 03d4d728f8365021de6955c649e6dcd05dcca99f (03d4d72-dirty). + * Git branch HEAD. * * See Duktape AUTHORS.rst and LICENSE.txt for copyright and * licensing information. @@ -16,7 +16,7 @@ * * (http://opensource.org/licenses/MIT) * -* Copyright (c) 2013-2019 by Duktape authors (see AUTHORS.rst) +* Copyright (c) 2013-present by Duktape authors (see AUTHORS.rst) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -105,6 +105,12 @@ * * Luis de Bethencourt (https://github.com/luisbg) * * Ian Whyman (https://github.com/v00d00) * * Rick Sayre (https://github.com/whorfin) +* * Craig Leres (https://github.com/leres) +* * Maurici Abad (https://github.com/mauriciabad) +* * Nancy Li (https://github.com/NancyLi1013) +* * William Parks (https://github.com/WilliamParks) +* * Sam Hellawell (https://github.com/samhellawell) +* * Vladislavs Sokurenko (https://github.com/sokurenko) * * Other contributions * =================== @@ -269,7 +275,7 @@ duk_uint16_t us4; duk_uint8_t uc8; #if defined(DUK_USE_PACKED_TVAL) - void *vp2; /* used by packed duk_tval, assumes sizeof(void *) == 4 */ + void *vp2; /* used by packed duk_tval, assumes sizeof(void *) == 4 */ #endif }; @@ -281,64 +287,64 @@ #if defined(DUK_USE_DOUBLE_LE) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 +#define DUK_DBL_IDX_ULL0 0 #endif -#define DUK_DBL_IDX_UI0 1 -#define DUK_DBL_IDX_UI1 0 -#define DUK_DBL_IDX_US0 3 -#define DUK_DBL_IDX_US1 2 -#define DUK_DBL_IDX_US2 1 -#define DUK_DBL_IDX_US3 0 -#define DUK_DBL_IDX_UC0 7 -#define DUK_DBL_IDX_UC1 6 -#define DUK_DBL_IDX_UC2 5 -#define DUK_DBL_IDX_UC3 4 -#define DUK_DBL_IDX_UC4 3 -#define DUK_DBL_IDX_UC5 2 -#define DUK_DBL_IDX_UC6 1 -#define DUK_DBL_IDX_UC7 0 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 1 +#define DUK_DBL_IDX_UI1 0 +#define DUK_DBL_IDX_US0 3 +#define DUK_DBL_IDX_US1 2 +#define DUK_DBL_IDX_US2 1 +#define DUK_DBL_IDX_US3 0 +#define DUK_DBL_IDX_UC0 7 +#define DUK_DBL_IDX_UC1 6 +#define DUK_DBL_IDX_UC2 5 +#define DUK_DBL_IDX_UC3 4 +#define DUK_DBL_IDX_UC4 3 +#define DUK_DBL_IDX_UC5 2 +#define DUK_DBL_IDX_UC6 1 +#define DUK_DBL_IDX_UC7 0 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #elif defined(DUK_USE_DOUBLE_BE) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 +#define DUK_DBL_IDX_ULL0 0 #endif -#define DUK_DBL_IDX_UI0 0 -#define DUK_DBL_IDX_UI1 1 -#define DUK_DBL_IDX_US0 0 -#define DUK_DBL_IDX_US1 1 -#define DUK_DBL_IDX_US2 2 -#define DUK_DBL_IDX_US3 3 -#define DUK_DBL_IDX_UC0 0 -#define DUK_DBL_IDX_UC1 1 -#define DUK_DBL_IDX_UC2 2 -#define DUK_DBL_IDX_UC3 3 -#define DUK_DBL_IDX_UC4 4 -#define DUK_DBL_IDX_UC5 5 -#define DUK_DBL_IDX_UC6 6 -#define DUK_DBL_IDX_UC7 7 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 0 +#define DUK_DBL_IDX_UI1 1 +#define DUK_DBL_IDX_US0 0 +#define DUK_DBL_IDX_US1 1 +#define DUK_DBL_IDX_US2 2 +#define DUK_DBL_IDX_US3 3 +#define DUK_DBL_IDX_UC0 0 +#define DUK_DBL_IDX_UC1 1 +#define DUK_DBL_IDX_UC2 2 +#define DUK_DBL_IDX_UC3 3 +#define DUK_DBL_IDX_UC4 4 +#define DUK_DBL_IDX_UC5 5 +#define DUK_DBL_IDX_UC6 6 +#define DUK_DBL_IDX_UC7 7 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #elif defined(DUK_USE_DOUBLE_ME) #if defined(DUK_USE_64BIT_OPS) -#define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */ +#define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */ #endif -#define DUK_DBL_IDX_UI0 0 -#define DUK_DBL_IDX_UI1 1 -#define DUK_DBL_IDX_US0 1 -#define DUK_DBL_IDX_US1 0 -#define DUK_DBL_IDX_US2 3 -#define DUK_DBL_IDX_US3 2 -#define DUK_DBL_IDX_UC0 3 -#define DUK_DBL_IDX_UC1 2 -#define DUK_DBL_IDX_UC2 1 -#define DUK_DBL_IDX_UC3 0 -#define DUK_DBL_IDX_UC4 7 -#define DUK_DBL_IDX_UC5 6 -#define DUK_DBL_IDX_UC6 5 -#define DUK_DBL_IDX_UC7 4 -#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ -#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ +#define DUK_DBL_IDX_UI0 0 +#define DUK_DBL_IDX_UI1 1 +#define DUK_DBL_IDX_US0 1 +#define DUK_DBL_IDX_US1 0 +#define DUK_DBL_IDX_US2 3 +#define DUK_DBL_IDX_US3 2 +#define DUK_DBL_IDX_UC0 3 +#define DUK_DBL_IDX_UC1 2 +#define DUK_DBL_IDX_UC2 1 +#define DUK_DBL_IDX_UC3 0 +#define DUK_DBL_IDX_UC4 7 +#define DUK_DBL_IDX_UC5 6 +#define DUK_DBL_IDX_UC6 5 +#define DUK_DBL_IDX_UC7 4 +#define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */ +#define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */ #else #error internal error #endif @@ -348,57 +354,63 @@ * by duk_numconv.c and duk_tval.h. */ -#define DUK_DBLUNION_SET_DOUBLE(u,v) do { \ +#define DUK_DBLUNION_SET_DOUBLE(u, v) \ + do { \ (u)->d = (v); \ } while (0) -#define DUK_DBLUNION_SET_HIGH32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) (v); \ } while (0) #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = (duk_uint64_t) (v); \ } while (0) #else -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = ((duk_uint64_t) (v)) << 32; \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) (v); \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) 0; \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ -#define DUK_DBLUNION_SET_LOW32(u,v) do { \ +#define DUK_DBLUNION_SET_LOW32(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d) -#define DUK_DBLUNION_GET_HIGH32(u) ((u)->uiDUK_DBL_IDX_UI0) -#define DUK_DBLUNION_GET_LOW32(u) ((u)->uiDUK_DBL_IDX_UI1) +#define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d) +#define DUK_DBLUNION_GET_HIGH32(u) ((u)->uiDUK_DBL_IDX_UI0) +#define DUK_DBLUNION_GET_LOW32(u) ((u)->uiDUK_DBL_IDX_UI1) #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_SET_UINT64(u,v) do { \ +#define DUK_DBLUNION_SET_UINT64(u, v) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) ((v) >> 32); \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_UINT64(u) \ - ((((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI0) << 32) | \ - ((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI1)) +#define DUK_DBLUNION_GET_UINT64(u) ((((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (u)->uiDUK_DBL_IDX_UI1)) #else -#define DUK_DBLUNION_SET_UINT64(u,v) do { \ +#define DUK_DBLUNION_SET_UINT64(u, v) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = (duk_uint64_t) (v); \ } while (0) -#define DUK_DBLUNION_GET_UINT64(u) ((u)->ullDUK_DBL_IDX_ULL0) +#define DUK_DBLUNION_GET_UINT64(u) ((u)->ullDUK_DBL_IDX_ULL0) #endif -#define DUK_DBLUNION_SET_INT64(u,v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v)) -#define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u))) -#endif /* DUK_USE_64BIT_OPS */ +#define DUK_DBLUNION_SET_INT64(u, v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v)) +#define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u))) +#endif /* DUK_USE_64BIT_OPS */ /* * Double NaN manipulation macros related to NaN normalization needed when @@ -429,102 +441,85 @@ #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) /* Macros for 64-bit ops + mixed endian doubles. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = DUK_U64_CONSTANT(0x000000007ff80000); \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x000000007ff00000)) == DUK_U64_CONSTANT(0x000000007ff00000)) && \ ((((u)->ullDUK_DBL_IDX_ULL0) & DUK_U64_CONSTANT(0xffffffff000fffff)) != 0)) -#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff80000)) +#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff80000)) #define DUK__DBLUNION_IS_ANYINF(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0xffffffff7fffffff)) == DUK_U64_CONSTANT(0x000000007ff00000)) -#define DUK__DBLUNION_IS_POSINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff00000)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x00000000fff00000)) +#define DUK__DBLUNION_IS_POSINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x000000007ff00000)) +#define DUK__DBLUNION_IS_NEGINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x00000000fff00000)) #define DUK__DBLUNION_IS_ANYZERO(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0xffffffff7fffffff)) == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000080000000)) +#define DUK__DBLUNION_IS_POSZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) +#define DUK__DBLUNION_IS_NEGZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000080000000)) #else /* Macros for 64-bit ops + big/little endian doubles. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->ullDUK_DBL_IDX_ULL0 = DUK_U64_CONSTANT(0x7ff8000000000000); \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7ff0000000000000)) == DUK_U64_CONSTANT(0x7ff0000000000000)) && \ ((((u)->ullDUK_DBL_IDX_ULL0) & DUK_U64_CONSTANT(0x000fffffffffffff)) != 0)) -#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff8000000000000)) +#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff8000000000000)) #define DUK__DBLUNION_IS_ANYINF(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7fffffffffffffff)) == DUK_U64_CONSTANT(0x7ff0000000000000)) -#define DUK__DBLUNION_IS_POSINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff0000000000000)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0xfff0000000000000)) +#define DUK__DBLUNION_IS_POSINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x7ff0000000000000)) +#define DUK__DBLUNION_IS_NEGINF(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0xfff0000000000000)) #define DUK__DBLUNION_IS_ANYZERO(u) \ (((u)->ullDUK_DBL_IDX_ULL0 & DUK_U64_CONSTANT(0x7fffffffffffffff)) == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x8000000000000000)) +#define DUK__DBLUNION_IS_POSZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x0000000000000000)) +#define DUK__DBLUNION_IS_NEGZERO(u) ((u)->ullDUK_DBL_IDX_ULL0 == DUK_U64_CONSTANT(0x8000000000000000)) #endif -#else /* DUK_USE_64BIT_OPS */ +#else /* DUK_USE_64BIT_OPS */ /* Macros for no 64-bit ops, any endianness. */ -#define DUK__DBLUNION_SET_NAN_FULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_FULL(u) \ + do { \ (u)->uiDUK_DBL_IDX_UI0 = (duk_uint32_t) 0x7ff80000UL; \ (u)->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) 0x00000000UL; \ } while (0) #define DUK__DBLUNION_IS_NAN_FULL(u) \ ((((u)->uiDUK_DBL_IDX_UI0 & 0x7ff00000UL) == 0x7ff00000UL) && \ - (((u)->uiDUK_DBL_IDX_UI0 & 0x000fffffUL) != 0 || \ - (u)->uiDUK_DBL_IDX_UI1 != 0)) + (((u)->uiDUK_DBL_IDX_UI0 & 0x000fffffUL) != 0 || (u)->uiDUK_DBL_IDX_UI1 != 0)) #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff80000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) + (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff80000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) #define DUK__DBLUNION_IS_ANYINF(u) \ - ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x7ff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_POSINF(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_NEGINF(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0xfff00000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) + ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x7ff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_POSINF(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x7ff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_NEGINF(u) (((u)->uiDUK_DBL_IDX_UI0 == 0xfff00000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) #define DUK__DBLUNION_IS_ANYZERO(u) \ - ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x00000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_POSZERO(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x00000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#define DUK__DBLUNION_IS_NEGZERO(u) \ - (((u)->uiDUK_DBL_IDX_UI0 == 0x80000000UL) && \ - ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) -#endif /* DUK_USE_64BIT_OPS */ + ((((u)->uiDUK_DBL_IDX_UI0 & 0x7fffffffUL) == 0x00000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_POSZERO(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x00000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#define DUK__DBLUNION_IS_NEGZERO(u) (((u)->uiDUK_DBL_IDX_UI0 == 0x80000000UL) && ((u)->uiDUK_DBL_IDX_UI1 == 0x00000000UL)) +#endif /* DUK_USE_64BIT_OPS */ -#define DUK__DBLUNION_SET_NAN_NOTFULL(u) do { \ +#define DUK__DBLUNION_SET_NAN_NOTFULL(u) \ + do { \ (u)->usDUK_DBL_IDX_US0 = 0x7ff8UL; \ } while (0) #define DUK__DBLUNION_IS_NAN_NOTFULL(u) \ /* E == 0x7ff, topmost four bits of F != 0 => assume NaN */ \ - ((((u)->usDUK_DBL_IDX_US0 & 0x7ff0UL) == 0x7ff0UL) && \ - (((u)->usDUK_DBL_IDX_US0 & 0x000fUL) != 0x0000UL)) + ((((u)->usDUK_DBL_IDX_US0 & 0x7ff0UL) == 0x7ff0UL) && (((u)->usDUK_DBL_IDX_US0 & 0x000fUL) != 0x0000UL)) #define DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL(u) \ /* E == 0x7ff, F == 8 => normalized NaN */ \ ((u)->usDUK_DBL_IDX_US0 == 0x7ff8UL) -#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) do { \ +#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) \ + do { \ if (DUK__DBLUNION_IS_NAN_FULL((u))) { \ DUK__DBLUNION_SET_NAN_FULL((u)); \ } \ } while (0) -#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) do { \ +#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) \ + do { \ /* Check must be full. */ \ if (DUK__DBLUNION_IS_NAN_FULL((u))) { \ DUK__DBLUNION_SET_NAN_NOTFULL((u)); \ @@ -538,29 +533,30 @@ */ #if defined(DUK_USE_PACKED_TVAL) -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u)) -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u)) -#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d)) +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u)) +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u)) +#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d)) #if 0 -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u)) -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u)) -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u)) -#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d)) +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u)) +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u)) +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u)) +#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d)) #endif #define DUK_DBLUNION_IS_NORMALIZED(u) \ - (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \ - DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */ -#else /* DUK_USE_PACKED_TVAL */ -#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */ -#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ -#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ -#define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */ -#define DUK_DBLUNION_SET_NAN(u) do { \ + (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \ + DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */ +#else /* DUK_USE_PACKED_TVAL */ +#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */ +#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ +#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u)) /* (DUK_ISNAN((u)->d)) */ +#define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */ +#define DUK_DBLUNION_SET_NAN(u) \ + do { \ /* in non-packed representation we don't care about which NaN is used */ \ (u)->d = DUK_DOUBLE_NAN; \ } while (0) -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ #define DUK_DBLUNION_IS_ANYINF(u) DUK__DBLUNION_IS_ANYINF((u)) #define DUK_DBLUNION_IS_POSINF(u) DUK__DBLUNION_IS_POSINF((u)) @@ -573,7 +569,8 @@ /* XXX: native 64-bit byteswaps when available */ /* 64-bit byteswap, same operation independent of target endianness. */ -#define DUK_DBLUNION_BSWAP64(u) do { \ +#define DUK_DBLUNION_BSWAP64(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -587,7 +584,8 @@ * order. For a big endian target this is a no-op. */ #if defined(DUK_USE_DOUBLE_LE) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { \ +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -597,7 +595,8 @@ (u)->ui1 = duk__bswaptmp1; \ } while (0) #elif defined(DUK_USE_DOUBLE_ME) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { \ +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \ duk__bswaptmp1 = (u)->ui0; \ duk__bswaptmp2 = (u)->ui1; \ @@ -607,7 +606,9 @@ (u)->ui1 = duk__bswaptmp2; \ } while (0) #elif defined(DUK_USE_DOUBLE_BE) -#define DUK_DBLUNION_DOUBLE_HTON(u) do { } while (0) +#define DUK_DBLUNION_DOUBLE_HTON(u) \ + do { \ + } while (0) #else #error internal error, double endianness insane #endif @@ -624,7 +625,7 @@ #define DUK_DBLUNION_GET_SIGNBIT(u) (((u)->uiDUK_DBL_IDX_UI0 >> 31U)) #endif -#endif /* DUK_DBLUNION_H_INCLUDED */ +#endif /* DUK_DBLUNION_H_INCLUDED */ /* #include duk_fltunion.h */ #line 1 "duk_fltunion.h" /* @@ -646,26 +647,26 @@ typedef union duk_float_union duk_float_union; #if defined(DUK_USE_DOUBLE_LE) || defined(DUK_USE_DOUBLE_ME) -#define DUK_FLT_IDX_UI0 0 -#define DUK_FLT_IDX_US0 1 -#define DUK_FLT_IDX_US1 0 -#define DUK_FLT_IDX_UC0 3 -#define DUK_FLT_IDX_UC1 2 -#define DUK_FLT_IDX_UC2 1 -#define DUK_FLT_IDX_UC3 0 +#define DUK_FLT_IDX_UI0 0 +#define DUK_FLT_IDX_US0 1 +#define DUK_FLT_IDX_US1 0 +#define DUK_FLT_IDX_UC0 3 +#define DUK_FLT_IDX_UC1 2 +#define DUK_FLT_IDX_UC2 1 +#define DUK_FLT_IDX_UC3 0 #elif defined(DUK_USE_DOUBLE_BE) -#define DUK_FLT_IDX_UI0 0 -#define DUK_FLT_IDX_US0 0 -#define DUK_FLT_IDX_US1 1 -#define DUK_FLT_IDX_UC0 0 -#define DUK_FLT_IDX_UC1 1 -#define DUK_FLT_IDX_UC2 2 -#define DUK_FLT_IDX_UC3 3 +#define DUK_FLT_IDX_UI0 0 +#define DUK_FLT_IDX_US0 0 +#define DUK_FLT_IDX_US1 1 +#define DUK_FLT_IDX_UC0 0 +#define DUK_FLT_IDX_UC1 1 +#define DUK_FLT_IDX_UC2 2 +#define DUK_FLT_IDX_UC3 3 #else #error internal error #endif -#endif /* DUK_FLTUNION_H_INCLUDED */ +#endif /* DUK_FLTUNION_H_INCLUDED */ /* #include duk_replacements.h */ #line 1 "duk_replacements.h" #if !defined(DUK_REPLACEMENTS_H_INCLUDED) @@ -678,7 +679,7 @@ #if defined(DUK_USE_COMPUTED_NAN) DUK_INTERNAL_DECL double duk_computed_nan; #endif -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ #if defined(DUK_USE_REPL_FPCLASSIFY) DUK_INTERNAL_DECL int duk_repl_fpclassify(double x); @@ -696,7 +697,7 @@ DUK_INTERNAL_DECL int duk_repl_isinf(double x); #endif -#endif /* DUK_REPLACEMENTS_H_INCLUDED */ +#endif /* DUK_REPLACEMENTS_H_INCLUDED */ /* #include duk_jmpbuf.h */ #line 1 "duk_jmpbuf.h" /* @@ -714,7 +715,7 @@ #if defined(DUK_USE_CPP_EXCEPTIONS) struct duk_jmpbuf { - duk_small_int_t dummy; /* unused */ + duk_small_int_t dummy; /* unused */ }; #else struct duk_jmpbuf { @@ -722,7 +723,7 @@ }; #endif -#endif /* DUK_JMPBUF_H_INCLUDED */ +#endif /* DUK_JMPBUF_H_INCLUDED */ /* #include duk_exception.h */ #line 1 "duk_exception.h" /* @@ -749,12 +750,13 @@ * aware of the "unsafe to continue" semantics. */ class duk_fatal_exception : public virtual std::runtime_error { - public: - duk_fatal_exception(const char *message) : std::runtime_error(message) {} + public: + duk_fatal_exception(const char *message) : std::runtime_error(message) { + } }; #endif -#endif /* DUK_EXCEPTION_H_INCLUDED */ +#endif /* DUK_EXCEPTION_H_INCLUDED */ /* #include duk_forwdecl.h */ #line 1 "duk_forwdecl.h" /* @@ -890,7 +892,7 @@ typedef struct duk_re_matcher_ctx duk_re_matcher_ctx; typedef struct duk_re_compiler_ctx duk_re_compiler_ctx; -#endif /* DUK_FORWDECL_H_INCLUDED */ +#endif /* DUK_FORWDECL_H_INCLUDED */ /* #include duk_tval.h */ #line 1 "duk_tval.h" /* @@ -936,30 +938,29 @@ } duk_tval_unused; /* tags */ -#define DUK_TAG_NORMALIZED_NAN 0x7ff8UL /* the NaN variant we use */ +#define DUK_TAG_NORMALIZED_NAN 0x7ff8UL /* the NaN variant we use */ /* avoid tag 0xfff0, no risk of confusion with negative infinity */ -#define DUK_TAG_MIN 0xfff1UL +#define DUK_TAG_MIN 0xfff1UL #if defined(DUK_USE_FASTINT) -#define DUK_TAG_FASTINT 0xfff1UL /* embed: integer value */ +#define DUK_TAG_FASTINT 0xfff1UL /* embed: integer value */ #endif -#define DUK_TAG_UNUSED 0xfff2UL /* marker; not actual tagged value */ -#define DUK_TAG_UNDEFINED 0xfff3UL /* embed: nothing */ -#define DUK_TAG_NULL 0xfff4UL /* embed: nothing */ -#define DUK_TAG_BOOLEAN 0xfff5UL /* embed: 0 or 1 (false or true) */ +#define DUK_TAG_UNUSED 0xfff2UL /* marker; not actual tagged value */ +#define DUK_TAG_UNDEFINED 0xfff3UL /* embed: nothing */ +#define DUK_TAG_NULL 0xfff4UL /* embed: nothing */ +#define DUK_TAG_BOOLEAN 0xfff5UL /* embed: 0 or 1 (false or true) */ /* DUK_TAG_NUMBER would logically go here, but it has multiple 'tags' */ -#define DUK_TAG_POINTER 0xfff6UL /* embed: void ptr */ -#define DUK_TAG_LIGHTFUNC 0xfff7UL /* embed: func ptr */ -#define DUK_TAG_STRING 0xfff8UL /* embed: duk_hstring ptr */ -#define DUK_TAG_OBJECT 0xfff9UL /* embed: duk_hobject ptr */ -#define DUK_TAG_BUFFER 0xfffaUL /* embed: duk_hbuffer ptr */ -#define DUK_TAG_MAX 0xfffaUL +#define DUK_TAG_POINTER 0xfff6UL /* embed: void ptr */ +#define DUK_TAG_LIGHTFUNC 0xfff7UL /* embed: func ptr */ +#define DUK_TAG_STRING 0xfff8UL /* embed: duk_hstring ptr */ +#define DUK_TAG_OBJECT 0xfff9UL /* embed: duk_hobject ptr */ +#define DUK_TAG_BUFFER 0xfffaUL /* embed: duk_hbuffer ptr */ +#define DUK_TAG_MAX 0xfffaUL /* for convenience */ -#define DUK_XTAG_BOOLEAN_FALSE 0xfff50000UL -#define DUK_XTAG_BOOLEAN_TRUE 0xfff50001UL +#define DUK_XTAG_BOOLEAN_FALSE 0xfff50000UL +#define DUK_XTAG_BOOLEAN_TRUE 0xfff50001UL -#define DUK_TVAL_IS_VALID_TAG(tv) \ - (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) +#define DUK_TVAL_IS_VALID_TAG(tv) (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) /* DUK_TVAL_UNUSED initializer for duk_tval_unused, works for any endianness. */ #define DUK_TVAL_UNUSED_INITIALIZER() \ @@ -968,116 +969,136 @@ /* two casts to avoid gcc warning: "warning: cast from pointer to integer of different size -Wpointer-to-int-cast" */ #if defined(DUK_USE_64BIT_OPS) #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) (tag)) << 16) | (((duk_uint64_t) (duk_uint32_t) (h)) << 32); \ } while (0) #else -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) (tag)) << 48) | ((duk_uint64_t) (duk_uint32_t) (h)); \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK__TVAL_SET_TAGGEDPOINTER(tv,h,tag) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK__TVAL_SET_TAGGEDPOINTER(tv, h, tag) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) (tag)) << 16; \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (h); \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ #if defined(DUK_USE_64BIT_OPS) /* Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size) */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 16) | \ - ((duk_uint64_t) (flags)) | \ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 16) | ((duk_uint64_t) (flags)) | \ (((duk_uint64_t) (duk_uint32_t) (fp)) << 32); \ } while (0) #else -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 48) | \ - (((duk_uint64_t) (flags)) << 32) | \ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_LIGHTFUNC) << 48) | (((duk_uint64_t) (flags)) << 32) | \ ((duk_uint64_t) (duk_uint32_t) (fp)); \ } while (0) #endif -#else /* DUK_USE_64BIT_OPS */ -#define DUK__TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ +#else /* DUK_USE_64BIT_OPS */ +#define DUK__TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = (((duk_uint32_t) DUK_TAG_LIGHTFUNC) << 16) | ((duk_uint32_t) (flags)); \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (fp); \ } while (0) -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ #if defined(DUK_USE_FASTINT) /* Note: masking is done for 'i' to deal with negative numbers correctly */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_SET_I48(tv,i) do { \ +#define DUK__TVAL_SET_I48(tv, i) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ - duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) DUK_TAG_FASTINT) << 16 | (((duk_uint32_t) ((i) >> 32)) & 0x0000ffffUL); \ + duk__tv->uiDUK_DBL_IDX_UI0 = \ + ((duk_uint32_t) DUK_TAG_FASTINT) << 16 | (((duk_uint32_t) ((i) >> 32)) & 0x0000ffffUL); \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (i); \ } while (0) -#define DUK__TVAL_SET_U32(tv,i) do { \ +#define DUK__TVAL_SET_U32(tv, i) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->uiDUK_DBL_IDX_UI0 = ((duk_uint32_t) DUK_TAG_FASTINT) << 16; \ duk__tv->uiDUK_DBL_IDX_UI1 = (duk_uint32_t) (i); \ } while (0) #else -#define DUK__TVAL_SET_I48(tv,i) do { \ - (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & DUK_U64_CONSTANT(0x0000ffffffffffff)); \ +#define DUK__TVAL_SET_I48(tv, i) \ + do { \ + (tv)->ullDUK_DBL_IDX_ULL0 = \ + (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & DUK_U64_CONSTANT(0x0000ffffffffffff)); \ } while (0) -#define DUK__TVAL_SET_U32(tv,i) do { \ +#define DUK__TVAL_SET_U32(tv, i) \ + do { \ (tv)->ullDUK_DBL_IDX_ULL0 = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (duk_uint64_t) (i); \ } while (0) #endif /* This needs to go through a cast because sign extension is needed. */ -#define DUK__TVAL_SET_I32(tv,i) do { \ +#define DUK__TVAL_SET_I32(tv, i) \ + do { \ duk_int64_t duk__tmp = (duk_int64_t) (i); \ DUK_TVAL_SET_I48((tv), duk__tmp); \ } while (0) /* XXX: Clumsy sign extend and masking of 16 topmost bits. */ #if defined(DUK_USE_DOUBLE_ME) -#define DUK__TVAL_GET_FASTINT(tv) (((duk_int64_t) ((((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI1))) << 16 >> 16) -#else -#define DUK__TVAL_GET_FASTINT(tv) ((((duk_int64_t) (tv)->ullDUK_DBL_IDX_ULL0) << 16) >> 16) -#endif -#define DUK__TVAL_GET_FASTINT_U32(tv) ((tv)->uiDUK_DBL_IDX_UI1) -#define DUK__TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) (tv)->uiDUK_DBL_IDX_UI1) -#endif /* DUK_USE_FASTINT */ +#define DUK__TVAL_GET_FASTINT(tv) \ + (((duk_int64_t) ((((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI0) << 32) | ((duk_uint64_t) (tv)->uiDUK_DBL_IDX_UI1))) \ + << 16 >> \ + 16) +#else +#define DUK__TVAL_GET_FASTINT(tv) ((((duk_int64_t) (tv)->ullDUK_DBL_IDX_ULL0) << 16) >> 16) +#endif +#define DUK__TVAL_GET_FASTINT_U32(tv) ((tv)->uiDUK_DBL_IDX_UI1) +#define DUK__TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) (tv)->uiDUK_DBL_IDX_UI1) +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_UNDEFINED(tv) do { \ +#define DUK_TVAL_SET_UNDEFINED(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_UNDEFINED; \ } while (0) -#define DUK_TVAL_SET_UNUSED(tv) do { \ +#define DUK_TVAL_SET_UNUSED(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_UNUSED; \ } while (0) -#define DUK_TVAL_SET_NULL(tv) do { \ +#define DUK_TVAL_SET_NULL(tv) \ + do { \ (tv)->usDUK_DBL_IDX_US0 = (duk_uint16_t) DUK_TAG_NULL; \ } while (0) -#define DUK_TVAL_SET_BOOLEAN(tv,val) DUK_DBLUNION_SET_HIGH32((tv), (((duk_uint32_t) DUK_TAG_BOOLEAN) << 16) | ((duk_uint32_t) (val))) +#define DUK_TVAL_SET_BOOLEAN(tv, val) \ + DUK_DBLUNION_SET_HIGH32((tv), (((duk_uint32_t) DUK_TAG_BOOLEAN) << 16) | ((duk_uint32_t) (val))) -#define DUK_TVAL_SET_NAN(tv) DUK_DBLUNION_SET_NAN_FULL((tv)) +#define DUK_TVAL_SET_NAN(tv) DUK_DBLUNION_SET_NAN_FULL((tv)) /* Assumes that caller has normalized NaNs, otherwise trouble ahead. */ #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_DOUBLE(tv,d) do { \ +#define DUK_TVAL_SET_DOUBLE(tv, d) \ + do { \ duk_double_t duk__dblval; \ duk__dblval = (d); \ DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \ DUK_DBLUNION_SET_DOUBLE((tv), duk__dblval); \ } while (0) -#define DUK_TVAL_SET_I48(tv,i) DUK__TVAL_SET_I48((tv), (i)) -#define DUK_TVAL_SET_I32(tv,i) DUK__TVAL_SET_I32((tv), (i)) -#define DUK_TVAL_SET_U32(tv,i) DUK__TVAL_SET_U32((tv), (i)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) duk_tval_set_number_chkfast_fast((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) duk_tval_set_number_chkfast_slow((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { \ +#define DUK_TVAL_SET_I48(tv, i) DUK__TVAL_SET_I48((tv), (i)) +#define DUK_TVAL_SET_I32(tv, i) DUK__TVAL_SET_I32((tv), (i)) +#define DUK_TVAL_SET_U32(tv, i) DUK__TVAL_SET_U32((tv), (i)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) duk_tval_set_number_chkfast_fast((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) duk_tval_set_number_chkfast_slow((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -1086,7 +1107,8 @@ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(duk__tv, duk__d); \ } \ } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { \ +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -1095,89 +1117,98 @@ DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(duk__tv, duk__d); \ } \ } while (0) -#else /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_DOUBLE(tv,d) do { \ +#else /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_DOUBLE(tv, d) \ + do { \ duk_double_t duk__dblval; \ duk__dblval = (d); \ DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \ DUK_DBLUNION_SET_DOUBLE((tv), duk__dblval); \ } while (0) -#define DUK_TVAL_SET_I48(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_I32(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) -#define DUK_TVAL_SET_U32(tv,i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,d) DUK_TVAL_SET_DOUBLE((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { } while (0) -#endif /* DUK_USE_FASTINT */ - -#define DUK_TVAL_SET_FASTINT(tv,i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ - -#define DUK_TVAL_SET_LIGHTFUNC(tv,fp,flags) DUK__TVAL_SET_LIGHTFUNC((tv), (fp), (flags)) -#define DUK_TVAL_SET_STRING(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_STRING) -#define DUK_TVAL_SET_OBJECT(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_OBJECT) -#define DUK_TVAL_SET_BUFFER(tv,h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_BUFFER) -#define DUK_TVAL_SET_POINTER(tv,p) DUK__TVAL_SET_TAGGEDPOINTER((tv), (p), DUK_TAG_POINTER) - -#define DUK_TVAL_SET_TVAL(tv,x) do { *(tv) = *(x); } while (0) +#define DUK_TVAL_SET_I48(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_I32(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) +#define DUK_TVAL_SET_U32(tv, i) DUK_TVAL_SET_DOUBLE((tv), (duk_double_t) (i)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, d) DUK_TVAL_SET_DOUBLE((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ + } while (0) +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ + } while (0) +#endif /* DUK_USE_FASTINT */ + +#define DUK_TVAL_SET_FASTINT(tv, i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ + +#define DUK_TVAL_SET_LIGHTFUNC(tv, fp, flags) DUK__TVAL_SET_LIGHTFUNC((tv), (fp), (flags)) +#define DUK_TVAL_SET_STRING(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_STRING) +#define DUK_TVAL_SET_OBJECT(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_OBJECT) +#define DUK_TVAL_SET_BUFFER(tv, h) DUK__TVAL_SET_TAGGEDPOINTER((tv), (h), DUK_TAG_BUFFER) +#define DUK_TVAL_SET_POINTER(tv, p) DUK__TVAL_SET_TAGGEDPOINTER((tv), (p), DUK_TAG_POINTER) + +#define DUK_TVAL_SET_TVAL(tv, x) \ + do { \ + *(tv) = *(x); \ + } while (0) /* getters */ -#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US1) +#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US1) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) -#define DUK_TVAL_GET_FASTINT(tv) DUK__TVAL_GET_FASTINT((tv)) -#define DUK_TVAL_GET_FASTINT_U32(tv) DUK__TVAL_GET_FASTINT_U32((tv)) -#define DUK_TVAL_GET_FASTINT_I32(tv) DUK__TVAL_GET_FASTINT_I32((tv)) -#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_packed((tv)) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) +#define DUK_TVAL_GET_FASTINT(tv) DUK__TVAL_GET_FASTINT((tv)) +#define DUK_TVAL_GET_FASTINT_U32(tv) DUK__TVAL_GET_FASTINT_U32((tv)) +#define DUK_TVAL_GET_FASTINT_I32(tv) DUK__TVAL_GET_FASTINT_I32((tv)) +#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_packed((tv)) #else -#define DUK_TVAL_GET_NUMBER(tv) ((tv)->d) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) +#define DUK_TVAL_GET_NUMBER(tv) ((tv)->d) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d) #endif -#define DUK_TVAL_GET_LIGHTFUNC(tv,out_fp,out_flags) do { \ +#define DUK_TVAL_GET_LIGHTFUNC(tv, out_fp, out_flags) \ + do { \ (out_flags) = (tv)->uiDUK_DBL_IDX_UI0 & 0xffffUL; \ (out_fp) = (duk_c_function) (tv)->uiDUK_DBL_IDX_UI1; \ } while (0) -#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((duk_c_function) ((tv)->uiDUK_DBL_IDX_UI1)) -#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) (((duk_small_uint_t) (tv)->uiDUK_DBL_IDX_UI0) & 0xffffUL) -#define DUK_TVAL_GET_STRING(tv) ((duk_hstring *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_OBJECT(tv) ((duk_hobject *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_BUFFER(tv) ((duk_hbuffer *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_POINTER(tv) ((void *) (tv)->vpDUK_DBL_IDX_VP1) -#define DUK_TVAL_GET_HEAPHDR(tv) ((duk_heaphdr *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((duk_c_function) ((tv)->uiDUK_DBL_IDX_UI1)) +#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) (((duk_small_uint_t) (tv)->uiDUK_DBL_IDX_UI0) & 0xffffUL) +#define DUK_TVAL_GET_STRING(tv) ((duk_hstring *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_OBJECT(tv) ((duk_hobject *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_BUFFER(tv) ((duk_hbuffer *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_POINTER(tv) ((void *) (tv)->vpDUK_DBL_IDX_VP1) +#define DUK_TVAL_GET_HEAPHDR(tv) ((duk_heaphdr *) (tv)->vpDUK_DBL_IDX_VP1) /* decoding */ -#define DUK_TVAL_GET_TAG(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US0) +#define DUK_TVAL_GET_TAG(tv) ((duk_small_uint_t) (tv)->usDUK_DBL_IDX_US0) -#define DUK_TVAL_IS_UNDEFINED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNDEFINED) -#define DUK_TVAL_IS_UNUSED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNUSED) -#define DUK_TVAL_IS_NULL(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_NULL) -#define DUK_TVAL_IS_BOOLEAN(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BOOLEAN) -#define DUK_TVAL_IS_BOOLEAN_TRUE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_TRUE) -#define DUK_TVAL_IS_BOOLEAN_FALSE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_FALSE) -#define DUK_TVAL_IS_LIGHTFUNC(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_LIGHTFUNC) -#define DUK_TVAL_IS_STRING(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_STRING) -#define DUK_TVAL_IS_OBJECT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_OBJECT) -#define DUK_TVAL_IS_BUFFER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BUFFER) -#define DUK_TVAL_IS_POINTER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_POINTER) +#define DUK_TVAL_IS_UNDEFINED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNDEFINED) +#define DUK_TVAL_IS_UNUSED(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_UNUSED) +#define DUK_TVAL_IS_NULL(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_NULL) +#define DUK_TVAL_IS_BOOLEAN(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BOOLEAN) +#define DUK_TVAL_IS_BOOLEAN_TRUE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_TRUE) +#define DUK_TVAL_IS_BOOLEAN_FALSE(tv) ((tv)->uiDUK_DBL_IDX_UI0 == DUK_XTAG_BOOLEAN_FALSE) +#define DUK_TVAL_IS_LIGHTFUNC(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_LIGHTFUNC) +#define DUK_TVAL_IS_STRING(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_STRING) +#define DUK_TVAL_IS_OBJECT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_OBJECT) +#define DUK_TVAL_IS_BUFFER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_BUFFER) +#define DUK_TVAL_IS_POINTER(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_POINTER) #if defined(DUK_USE_FASTINT) /* 0xfff0 is -Infinity */ -#define DUK_TVAL_IS_DOUBLE(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) -#define DUK_TVAL_IS_FASTINT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_FASTINT) -#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff1UL) +#define DUK_TVAL_IS_DOUBLE(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) +#define DUK_TVAL_IS_FASTINT(tv) (DUK_TVAL_GET_TAG((tv)) == DUK_TAG_FASTINT) +#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff1UL) #else -#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) -#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) +#define DUK_TVAL_IS_NUMBER(tv) (DUK_TVAL_GET_TAG((tv)) <= 0xfff0UL) +#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) #endif /* This is performance critical because it appears in every DECREF. */ -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) (DUK_TVAL_GET_TAG((tv)) >= DUK_TAG_STRING) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) (DUK_TVAL_GET_TAG((tv)) >= DUK_TAG_STRING) #if defined(DUK_USE_FASTINT) DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_packed(duk_tval *tv); #endif -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ /* ======================================================================== */ /* @@ -1201,7 +1232,7 @@ duk_double_t d; duk_small_int_t i; #if defined(DUK_USE_FASTINT) - duk_int64_t fi; /* if present, forces 16-byte duk_tval */ + duk_int64_t fi; /* if present, forces 16-byte duk_tval */ #endif void *voidptr; duk_hstring *hstring; @@ -1229,24 +1260,23 @@ #define DUK_TVAL_UNUSED_INITIALIZER() \ { DUK_TAG_UNUSED, 0, 0.0 } -#define DUK_TAG_MIN 0 -#define DUK_TAG_NUMBER 0 /* DUK_TAG_NUMBER only defined for non-packed duk_tval */ +#define DUK_TAG_MIN 0 +#define DUK_TAG_NUMBER 0 /* DUK_TAG_NUMBER only defined for non-packed duk_tval */ #if defined(DUK_USE_FASTINT) -#define DUK_TAG_FASTINT 1 +#define DUK_TAG_FASTINT 1 #endif -#define DUK_TAG_UNDEFINED 2 -#define DUK_TAG_NULL 3 -#define DUK_TAG_BOOLEAN 4 -#define DUK_TAG_POINTER 5 -#define DUK_TAG_LIGHTFUNC 6 -#define DUK_TAG_UNUSED 7 /* marker; not actual tagged type */ -#define DUK_TAG_STRING 8 /* first heap allocated, match bit boundary */ -#define DUK_TAG_OBJECT 9 -#define DUK_TAG_BUFFER 10 -#define DUK_TAG_MAX 10 +#define DUK_TAG_UNDEFINED 2 +#define DUK_TAG_NULL 3 +#define DUK_TAG_BOOLEAN 4 +#define DUK_TAG_POINTER 5 +#define DUK_TAG_LIGHTFUNC 6 +#define DUK_TAG_UNUSED 7 /* marker; not actual tagged type */ +#define DUK_TAG_STRING 8 /* first heap allocated, match bit boundary */ +#define DUK_TAG_OBJECT 9 +#define DUK_TAG_BUFFER 10 +#define DUK_TAG_MAX 10 -#define DUK_TVAL_IS_VALID_TAG(tv) \ - (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) +#define DUK_TVAL_IS_VALID_TAG(tv) (DUK_TVAL_GET_TAG((tv)) - DUK_TAG_MIN <= DUK_TAG_MAX - DUK_TAG_MIN) /* DUK_TAG_NUMBER is intentionally first, as it is the default clause in code * to support the 8-byte representation. Further, it is a non-heap-allocated @@ -1255,25 +1285,29 @@ */ /* setters */ -#define DUK_TVAL_SET_UNDEFINED(tv) do { \ +#define DUK_TVAL_SET_UNDEFINED(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_UNDEFINED; \ } while (0) -#define DUK_TVAL_SET_UNUSED(tv) do { \ +#define DUK_TVAL_SET_UNUSED(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_UNUSED; \ } while (0) -#define DUK_TVAL_SET_NULL(tv) do { \ +#define DUK_TVAL_SET_NULL(tv) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_NULL; \ } while (0) -#define DUK_TVAL_SET_BOOLEAN(tv,val) do { \ +#define DUK_TVAL_SET_BOOLEAN(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_BOOLEAN; \ @@ -1281,7 +1315,8 @@ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_DOUBLE(tv,val) do { \ +#define DUK_TVAL_SET_DOUBLE(tv, val) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__dblval; \ duk__dblval = (val); \ @@ -1290,31 +1325,32 @@ duk__tv->t = DUK_TAG_NUMBER; \ duk__tv->v.d = duk__dblval; \ } while (0) -#define DUK_TVAL_SET_I48(tv,val) do { \ +#define DUK_TVAL_SET_I48(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (val); \ } while (0) -#define DUK_TVAL_SET_U32(tv,val) do { \ +#define DUK_TVAL_SET_U32(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (duk_int64_t) (val); \ } while (0) -#define DUK_TVAL_SET_I32(tv,val) do { \ +#define DUK_TVAL_SET_I32(tv, val) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_FASTINT; \ duk__tv->v.fi = (duk_int64_t) (val); \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) \ - duk_tval_set_number_chkfast_fast((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) \ - duk_tval_set_number_chkfast_slow((tv), (d)) -#define DUK_TVAL_SET_NUMBER(tv,val) \ - DUK_TVAL_SET_DOUBLE((tv), (val)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) duk_tval_set_number_chkfast_fast((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) duk_tval_set_number_chkfast_slow((tv), (d)) +#define DUK_TVAL_SET_NUMBER(tv, val) DUK_TVAL_SET_DOUBLE((tv), (val)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -1323,7 +1359,8 @@ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(duk__tv, duk__d); \ } \ } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { \ +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__d; \ duk__tv = (tv); \ @@ -1332,16 +1369,13 @@ DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(duk__tv, duk__d); \ } \ } while (0) -#else /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_DOUBLE(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_SET_I48(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_U32(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) -#define DUK_TVAL_SET_I32(tv,val) \ - DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) -#define DUK_TVAL_SET_NUMBER(tv,val) do { \ +#else /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_DOUBLE(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_SET_I48(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_U32(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) +#define DUK_TVAL_SET_I32(tv, val) DUK_TVAL_SET_NUMBER((tv), (duk_double_t) (val)) +#define DUK_TVAL_SET_NUMBER(tv, val) \ + do { \ duk_tval *duk__tv; \ duk_double_t duk__dblval; \ duk__dblval = (val); \ @@ -1350,25 +1384,28 @@ duk__tv->t = DUK_TAG_NUMBER; \ duk__tv->v.d = duk__dblval; \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv,d) \ - DUK_TVAL_SET_NUMBER((tv), (d)) -#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) do { } while (0) -#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) do { } while (0) -#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, d) DUK_TVAL_SET_NUMBER((tv), (d)) +#define DUK_TVAL_CHKFAST_INPLACE_FAST(tv) \ + do { \ + } while (0) +#define DUK_TVAL_CHKFAST_INPLACE_SLOW(tv) \ + do { \ + } while (0) +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT(tv,i) \ - DUK_TVAL_SET_I48((tv), (i)) /* alias */ +#define DUK_TVAL_SET_FASTINT(tv, i) DUK_TVAL_SET_I48((tv), (i)) /* alias */ -#define DUK_TVAL_SET_POINTER(tv,hptr) do { \ +#define DUK_TVAL_SET_POINTER(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_POINTER; \ duk__tv->v.voidptr = (hptr); \ } while (0) -#define DUK_TVAL_SET_LIGHTFUNC(tv,fp,flags) do { \ +#define DUK_TVAL_SET_LIGHTFUNC(tv, fp, flags) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_LIGHTFUNC; \ @@ -1376,28 +1413,32 @@ duk__tv->v.lightfunc = (duk_c_function) (fp); \ } while (0) -#define DUK_TVAL_SET_STRING(tv,hptr) do { \ +#define DUK_TVAL_SET_STRING(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_STRING; \ duk__tv->v.hstring = (hptr); \ } while (0) -#define DUK_TVAL_SET_OBJECT(tv,hptr) do { \ +#define DUK_TVAL_SET_OBJECT(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_OBJECT; \ duk__tv->v.hobject = (hptr); \ } while (0) -#define DUK_TVAL_SET_BUFFER(tv,hptr) do { \ +#define DUK_TVAL_SET_BUFFER(tv, hptr) \ + do { \ duk_tval *duk__tv; \ duk__tv = (tv); \ duk__tv->t = DUK_TAG_BUFFER; \ duk__tv->v.hbuffer = (hptr); \ } while (0) -#define DUK_TVAL_SET_NAN(tv) do { \ +#define DUK_TVAL_SET_NAN(tv) \ + do { \ /* in non-packed representation we don't care about which NaN is used */ \ duk_tval *duk__tv; \ duk__tv = (tv); \ @@ -1405,32 +1446,32 @@ duk__tv->v.d = DUK_DOUBLE_NAN; \ } while (0) -#define DUK_TVAL_SET_TVAL(tv,x) do { *(tv) = *(x); } while (0) +#define DUK_TVAL_SET_TVAL(tv, x) \ + do { \ + *(tv) = *(x); \ + } while (0) /* getters */ -#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->v.i) +#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->v.i) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) -#define DUK_TVAL_GET_FASTINT(tv) ((tv)->v.fi) -#define DUK_TVAL_GET_FASTINT_U32(tv) ((duk_uint32_t) ((tv)->v.fi)) -#define DUK_TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) ((tv)->v.fi)) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) +#define DUK_TVAL_GET_FASTINT(tv) ((tv)->v.fi) +#define DUK_TVAL_GET_FASTINT_U32(tv) ((duk_uint32_t) ((tv)->v.fi)) +#define DUK_TVAL_GET_FASTINT_I32(tv) ((duk_int32_t) ((tv)->v.fi)) #if 0 -#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? \ - (duk_double_t) DUK_TVAL_GET_FASTINT((tv)) : \ - DUK_TVAL_GET_DOUBLE((tv))) -#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_unpacked((tv)) +#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? (duk_double_t) DUK_TVAL_GET_FASTINT((tv)) : DUK_TVAL_GET_DOUBLE((tv))) +#define DUK_TVAL_GET_NUMBER(tv) duk_tval_get_number_unpacked((tv)) #else /* This seems reasonable overall. */ -#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? \ - duk_tval_get_number_unpacked_fastint((tv)) : \ - DUK_TVAL_GET_DOUBLE((tv))) +#define DUK_TVAL_GET_NUMBER(tv) (DUK_TVAL_IS_FASTINT((tv)) ? duk_tval_get_number_unpacked_fastint((tv)) : DUK_TVAL_GET_DOUBLE((tv))) #endif #else -#define DUK_TVAL_GET_NUMBER(tv) ((tv)->v.d) -#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_GET_POINTER(tv) ((tv)->v.voidptr) -#define DUK_TVAL_GET_LIGHTFUNC(tv,out_fp,out_flags) do { \ +#define DUK_TVAL_GET_NUMBER(tv) ((tv)->v.d) +#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d) +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_GET_POINTER(tv) ((tv)->v.voidptr) +#define DUK_TVAL_GET_LIGHTFUNC(tv, out_fp, out_flags) \ + do { \ (out_flags) = (duk_uint32_t) (tv)->v_extra; \ (out_fp) = (tv)->v.lightfunc; \ } while (0) @@ -1450,19 +1491,18 @@ #define DUK_TVAL_IS_BOOLEAN_TRUE(tv) (((tv)->t == DUK_TAG_BOOLEAN) && ((tv)->v.i != 0)) #define DUK_TVAL_IS_BOOLEAN_FALSE(tv) (((tv)->t == DUK_TAG_BOOLEAN) && ((tv)->v.i == 0)) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_IS_DOUBLE(tv) ((tv)->t == DUK_TAG_NUMBER) -#define DUK_TVAL_IS_FASTINT(tv) ((tv)->t == DUK_TAG_FASTINT) -#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER || \ - (tv)->t == DUK_TAG_FASTINT) -#else -#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER) -#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_IS_POINTER(tv) ((tv)->t == DUK_TAG_POINTER) -#define DUK_TVAL_IS_LIGHTFUNC(tv) ((tv)->t == DUK_TAG_LIGHTFUNC) -#define DUK_TVAL_IS_STRING(tv) ((tv)->t == DUK_TAG_STRING) -#define DUK_TVAL_IS_OBJECT(tv) ((tv)->t == DUK_TAG_OBJECT) -#define DUK_TVAL_IS_BUFFER(tv) ((tv)->t == DUK_TAG_BUFFER) +#define DUK_TVAL_IS_DOUBLE(tv) ((tv)->t == DUK_TAG_NUMBER) +#define DUK_TVAL_IS_FASTINT(tv) ((tv)->t == DUK_TAG_FASTINT) +#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER || (tv)->t == DUK_TAG_FASTINT) +#else +#define DUK_TVAL_IS_NUMBER(tv) ((tv)->t == DUK_TAG_NUMBER) +#define DUK_TVAL_IS_DOUBLE(tv) DUK_TVAL_IS_NUMBER((tv)) +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_IS_POINTER(tv) ((tv)->t == DUK_TAG_POINTER) +#define DUK_TVAL_IS_LIGHTFUNC(tv) ((tv)->t == DUK_TAG_LIGHTFUNC) +#define DUK_TVAL_IS_STRING(tv) ((tv)->t == DUK_TAG_STRING) +#define DUK_TVAL_IS_OBJECT(tv) ((tv)->t == DUK_TAG_OBJECT) +#define DUK_TVAL_IS_BUFFER(tv) ((tv)->t == DUK_TAG_BUFFER) /* This is performance critical because it's needed for every DECREF. * Take advantage of the fact that the first heap allocated tag is 8, @@ -1470,9 +1510,9 @@ * non-heap-allocated tags). */ #if 0 -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t >= DUK_TAG_STRING) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t >= DUK_TAG_STRING) #endif -#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t & 0x08) +#define DUK_TVAL_IS_HEAP_ALLOCATED(tv) ((tv)->t & 0x08) #if defined(DUK_USE_FASTINT) #if 0 @@ -1481,44 +1521,39 @@ DUK_INTERNAL_DECL duk_double_t duk_tval_get_number_unpacked_fastint(duk_tval *tv); #endif -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ /* * Convenience (independent of representation) */ -#define DUK_TVAL_SET_BOOLEAN_TRUE(tv) DUK_TVAL_SET_BOOLEAN((tv), 1) -#define DUK_TVAL_SET_BOOLEAN_FALSE(tv) DUK_TVAL_SET_BOOLEAN((tv), 0) +#define DUK_TVAL_SET_BOOLEAN_TRUE(tv) DUK_TVAL_SET_BOOLEAN((tv), 1) +#define DUK_TVAL_SET_BOOLEAN_FALSE(tv) DUK_TVAL_SET_BOOLEAN((tv), 0) -#define DUK_TVAL_STRING_IS_SYMBOL(tv) \ - DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING((tv))) +#define DUK_TVAL_STRING_IS_SYMBOL(tv) DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING((tv))) /* Lightfunc flags packing and unpacking. */ /* Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss##. * Avoid signed shifts due to portability limitations. */ -#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags) \ - ((duk_int32_t) (duk_int8_t) (((duk_uint16_t) (lf_flags)) >> 8)) -#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags) \ - (((lf_flags) >> 4) & 0x0fU) -#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags) \ - ((lf_flags) & 0x0fU) -#define DUK_LFUNC_FLAGS_PACK(magic,length,nargs) \ - ((((duk_small_uint_t) (magic)) & 0xffU) << 8) | ((length) << 4) | (nargs) - -#define DUK_LFUNC_NARGS_VARARGS 0x0f /* varargs marker */ -#define DUK_LFUNC_NARGS_MIN 0x00 -#define DUK_LFUNC_NARGS_MAX 0x0e /* max, excl. varargs marker */ -#define DUK_LFUNC_LENGTH_MIN 0x00 -#define DUK_LFUNC_LENGTH_MAX 0x0f -#define DUK_LFUNC_MAGIC_MIN (-0x80) -#define DUK_LFUNC_MAGIC_MAX 0x7f +#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags) ((duk_int32_t) (duk_int8_t) (((duk_uint16_t) (lf_flags)) >> 8)) +#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags) (((lf_flags) >> 4) & 0x0fU) +#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags) ((lf_flags) &0x0fU) +#define DUK_LFUNC_FLAGS_PACK(magic, length, nargs) ((((duk_small_uint_t) (magic)) & 0xffU) << 8) | ((length) << 4) | (nargs) + +#define DUK_LFUNC_NARGS_VARARGS 0x0f /* varargs marker */ +#define DUK_LFUNC_NARGS_MIN 0x00 +#define DUK_LFUNC_NARGS_MAX 0x0e /* max, excl. varargs marker */ +#define DUK_LFUNC_LENGTH_MIN 0x00 +#define DUK_LFUNC_LENGTH_MAX 0x0f +#define DUK_LFUNC_MAGIC_MIN (-0x80) +#define DUK_LFUNC_MAGIC_MAX 0x7f /* fastint constants etc */ #if defined(DUK_USE_FASTINT) -#define DUK_FASTINT_MIN (DUK_I64_CONSTANT(-0x800000000000)) -#define DUK_FASTINT_MAX (DUK_I64_CONSTANT(0x7fffffffffff)) -#define DUK_FASTINT_BITS 48 +#define DUK_FASTINT_MIN (DUK_I64_CONSTANT(-0x800000000000)) +#define DUK_FASTINT_MAX (DUK_I64_CONSTANT(0x7fffffffffff)) +#define DUK_FASTINT_BITS 48 DUK_INTERNAL_DECL void duk_tval_set_number_chkfast_fast(duk_tval *tv, duk_double_t x); DUK_INTERNAL_DECL void duk_tval_set_number_chkfast_slow(duk_tval *tv, duk_double_t x); @@ -1526,12 +1561,17 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_tval_assert_valid(duk_tval *tv); -#define DUK_TVAL_ASSERT_VALID(tv) do { duk_tval_assert_valid((tv)); } while (0) +#define DUK_TVAL_ASSERT_VALID(tv) \ + do { \ + duk_tval_assert_valid((tv)); \ + } while (0) #else -#define DUK_TVAL_ASSERT_VALID(tv) do {} while (0) +#define DUK_TVAL_ASSERT_VALID(tv) \ + do { \ + } while (0) #endif -#endif /* DUK_TVAL_H_INCLUDED */ +#endif /* DUK_TVAL_H_INCLUDED */ /* #include duk_builtins.h */ #line 1 "duk_builtins.h" /* @@ -2336,20 +2376,14 @@ #if !defined(DUK_UTIL_H_INCLUDED) #define DUK_UTIL_H_INCLUDED -#if defined(DUK_USE_GET_RANDOM_DOUBLE) -#define DUK_UTIL_GET_RANDOM_DOUBLE(thr) DUK_USE_GET_RANDOM_DOUBLE((thr)->heap_udata) -#else -#define DUK_UTIL_GET_RANDOM_DOUBLE(thr) duk_util_tinyrandom_get_double(thr) -#endif - /* * Some useful constants */ -#define DUK_DOUBLE_2TO32 4294967296.0 -#define DUK_DOUBLE_2TO31 2147483648.0 -#define DUK_DOUBLE_LOG2E 1.4426950408889634 -#define DUK_DOUBLE_LOG10E 0.4342944819032518 +#define DUK_DOUBLE_2TO32 4294967296.0 +#define DUK_DOUBLE_2TO31 2147483648.0 +#define DUK_DOUBLE_LOG2E 1.4426950408889634 +#define DUK_DOUBLE_LOG10E 0.4342944819032518 /* * Endian conversion @@ -2402,33 +2436,35 @@ * update the pointer argument automatically. */ -#define DUK_RAW_WRITE_U8(ptr,val) do { \ +#define DUK_RAW_WRITE_U8(ptr, val) \ + do { \ *(ptr) = (duk_uint8_t) (val); \ } while (0) -#define DUK_RAW_WRITE_U16_BE(ptr,val) duk_raw_write_u16_be((ptr), (duk_uint16_t) (val)) -#define DUK_RAW_WRITE_U32_BE(ptr,val) duk_raw_write_u32_be((ptr), (duk_uint32_t) (val)) -#define DUK_RAW_WRITE_FLOAT_BE(ptr,val) duk_raw_write_float_be((ptr), (duk_float_t) (val)) -#define DUK_RAW_WRITE_DOUBLE_BE(ptr,val) duk_raw_write_double_be((ptr), (duk_double_t) (val)) -#define DUK_RAW_WRITE_XUTF8(ptr,val) duk_raw_write_xutf8((ptr), (duk_ucodepoint_t) (val)) +#define DUK_RAW_WRITE_U16_BE(ptr, val) duk_raw_write_u16_be((ptr), (duk_uint16_t) (val)) +#define DUK_RAW_WRITE_U32_BE(ptr, val) duk_raw_write_u32_be((ptr), (duk_uint32_t) (val)) +#define DUK_RAW_WRITE_FLOAT_BE(ptr, val) duk_raw_write_float_be((ptr), (duk_float_t) (val)) +#define DUK_RAW_WRITE_DOUBLE_BE(ptr, val) duk_raw_write_double_be((ptr), (duk_double_t) (val)) +#define DUK_RAW_WRITE_XUTF8(ptr, val) duk_raw_write_xutf8((ptr), (duk_ucodepoint_t) (val)) -#define DUK_RAW_WRITEINC_U8(ptr,val) do { \ +#define DUK_RAW_WRITEINC_U8(ptr, val) \ + do { \ *(ptr)++ = (duk_uint8_t) (val); \ } while (0) -#define DUK_RAW_WRITEINC_U16_BE(ptr,val) duk_raw_writeinc_u16_be(&(ptr), (duk_uint16_t) (val)) -#define DUK_RAW_WRITEINC_U32_BE(ptr,val) duk_raw_writeinc_u32_be(&(ptr), (duk_uint32_t) (val)) -#define DUK_RAW_WRITEINC_FLOAT_BE(ptr,val) duk_raw_writeinc_float_be(&(ptr), (duk_float_t) (val)) -#define DUK_RAW_WRITEINC_DOUBLE_BE(ptr,val) duk_raw_writeinc_double_be(&(ptr), (duk_double_t) (val)) -#define DUK_RAW_WRITEINC_XUTF8(ptr,val) duk_raw_writeinc_xutf8(&(ptr), (duk_ucodepoint_t) (val)) -#define DUK_RAW_WRITEINC_CESU8(ptr,val) duk_raw_writeinc_cesu8(&(ptr), (duk_ucodepoint_t) (val)) - -#define DUK_RAW_READ_U8(ptr) ((duk_uint8_t) (*(ptr))) -#define DUK_RAW_READ_U16_BE(ptr) duk_raw_read_u16_be((ptr)); -#define DUK_RAW_READ_U32_BE(ptr) duk_raw_read_u32_be((ptr)); +#define DUK_RAW_WRITEINC_U16_BE(ptr, val) duk_raw_writeinc_u16_be(&(ptr), (duk_uint16_t) (val)) +#define DUK_RAW_WRITEINC_U32_BE(ptr, val) duk_raw_writeinc_u32_be(&(ptr), (duk_uint32_t) (val)) +#define DUK_RAW_WRITEINC_FLOAT_BE(ptr, val) duk_raw_writeinc_float_be(&(ptr), (duk_float_t) (val)) +#define DUK_RAW_WRITEINC_DOUBLE_BE(ptr, val) duk_raw_writeinc_double_be(&(ptr), (duk_double_t) (val)) +#define DUK_RAW_WRITEINC_XUTF8(ptr, val) duk_raw_writeinc_xutf8(&(ptr), (duk_ucodepoint_t) (val)) +#define DUK_RAW_WRITEINC_CESU8(ptr, val) duk_raw_writeinc_cesu8(&(ptr), (duk_ucodepoint_t) (val)) + +#define DUK_RAW_READ_U8(ptr) ((duk_uint8_t) (*(ptr))) +#define DUK_RAW_READ_U16_BE(ptr) duk_raw_read_u16_be((ptr)); +#define DUK_RAW_READ_U32_BE(ptr) duk_raw_read_u32_be((ptr)); #define DUK_RAW_READ_DOUBLE_BE(ptr) duk_raw_read_double_be((ptr)); -#define DUK_RAW_READINC_U8(ptr) ((duk_uint8_t) (*(ptr)++)) -#define DUK_RAW_READINC_U16_BE(ptr) duk_raw_readinc_u16_be(&(ptr)); -#define DUK_RAW_READINC_U32_BE(ptr) duk_raw_readinc_u32_be(&(ptr)); +#define DUK_RAW_READINC_U8(ptr) ((duk_uint8_t) (*(ptr)++)) +#define DUK_RAW_READINC_U16_BE(ptr) duk_raw_readinc_u16_be(&(ptr)); +#define DUK_RAW_READINC_U32_BE(ptr) duk_raw_readinc_u32_be(&(ptr)); #define DUK_RAW_READINC_DOUBLE_BE(ptr) duk_raw_readinc_double_be(&(ptr)); /* @@ -2475,29 +2511,31 @@ }; #if defined(DUK_USE_PREFER_SIZE) -#define DUK_BW_SLACK_ADD 64 -#define DUK_BW_SLACK_SHIFT 4 /* 2^4 -> 1/16 = 6.25% slack */ +#define DUK_BW_SLACK_ADD 64 +#define DUK_BW_SLACK_SHIFT 4 /* 2^4 -> 1/16 = 6.25% slack */ #else -#define DUK_BW_SLACK_ADD 64 -#define DUK_BW_SLACK_SHIFT 2 /* 2^2 -> 1/4 = 25% slack */ +#define DUK_BW_SLACK_ADD 64 +#define DUK_BW_SLACK_SHIFT 2 /* 2^2 -> 1/4 = 25% slack */ #endif /* Initialization and finalization (compaction), converting to other types. */ -#define DUK_BW_INIT_PUSHBUF(thr,bw_ctx,sz) do { \ +#define DUK_BW_INIT_PUSHBUF(thr, bw_ctx, sz) \ + do { \ duk_bw_init_pushbuf((thr), (bw_ctx), (sz)); \ } while (0) -#define DUK_BW_INIT_WITHBUF(thr,bw_ctx,buf) do { \ +#define DUK_BW_INIT_WITHBUF(thr, bw_ctx, buf) \ + do { \ duk_bw_init((thr), (bw_ctx), (buf)); \ } while (0) -#define DUK_BW_COMPACT(thr,bw_ctx) do { \ +#define DUK_BW_COMPACT(thr, bw_ctx) \ + do { \ /* Make underlying buffer compact to match DUK_BW_GET_SIZE(). */ \ duk_bw_compact((thr), (bw_ctx)); \ } while (0) -#define DUK_BW_PUSH_AS_STRING(thr,bw_ctx) do { \ - duk_push_lstring((thr), \ - (const char *) (bw_ctx)->p_base, \ - (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ +#define DUK_BW_PUSH_AS_STRING(thr, bw_ctx) \ + do { \ + duk_push_lstring((thr), (const char *) (bw_ctx)->p_base, (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ } while (0) /* Pointers may be NULL for a while when 'buf' size is zero and before any @@ -2507,43 +2545,48 @@ */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_bw_assert_valid(duk_hthread *thr, duk_bufwriter_ctx *bw_ctx); -#define DUK_BW_ASSERT_VALID_EXPR(thr,bw_ctx) (duk_bw_assert_valid((thr), (bw_ctx))) -#define DUK_BW_ASSERT_VALID(thr,bw_ctx) do { duk_bw_assert_valid((thr), (bw_ctx)); } while (0) +#define DUK_BW_ASSERT_VALID_EXPR(thr, bw_ctx) (duk_bw_assert_valid((thr), (bw_ctx))) +#define DUK_BW_ASSERT_VALID(thr, bw_ctx) \ + do { \ + duk_bw_assert_valid((thr), (bw_ctx)); \ + } while (0) #else -#define DUK_BW_ASSERT_VALID_EXPR(thr,bw_ctx) DUK_ASSERT_EXPR(1) -#define DUK_BW_ASSERT_VALID(thr,bw_ctx) do {} while (0) +#define DUK_BW_ASSERT_VALID_EXPR(thr, bw_ctx) DUK_ASSERT_EXPR(1) +#define DUK_BW_ASSERT_VALID(thr, bw_ctx) \ + do { \ + } while (0) #endif /* Working with the pointer and current size. */ -#define DUK_BW_GET_PTR(thr,bw_ctx) \ - ((bw_ctx)->p) -#define DUK_BW_SET_PTR(thr,bw_ctx,ptr) do { \ +#define DUK_BW_GET_PTR(thr, bw_ctx) ((bw_ctx)->p) +#define DUK_BW_SET_PTR(thr, bw_ctx, ptr) \ + do { \ (bw_ctx)->p = (ptr); \ } while (0) -#define DUK_BW_ADD_PTR(thr,bw_ctx,delta) do { \ +#define DUK_BW_ADD_PTR(thr, bw_ctx, delta) \ + do { \ (bw_ctx)->p += (delta); \ } while (0) -#define DUK_BW_GET_BASEPTR(thr,bw_ctx) \ - ((bw_ctx)->p_base) -#define DUK_BW_GET_LIMITPTR(thr,bw_ctx) \ - ((bw_ctx)->p_limit) -#define DUK_BW_GET_SIZE(thr,bw_ctx) \ - ((duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)) -#define DUK_BW_SET_SIZE(thr,bw_ctx,sz) do { \ +#define DUK_BW_GET_BASEPTR(thr, bw_ctx) ((bw_ctx)->p_base) +#define DUK_BW_GET_LIMITPTR(thr, bw_ctx) ((bw_ctx)->p_limit) +#define DUK_BW_GET_SIZE(thr, bw_ctx) ((duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)) +#define DUK_BW_SET_SIZE(thr, bw_ctx, sz) \ + do { \ DUK_ASSERT((duk_size_t) (sz) <= (duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \ (bw_ctx)->p = (bw_ctx)->p_base + (sz); \ } while (0) -#define DUK_BW_RESET_SIZE(thr,bw_ctx) do { \ +#define DUK_BW_RESET_SIZE(thr, bw_ctx) \ + do { \ /* Reset to zero size, keep current limit. */ \ (bw_ctx)->p = (bw_ctx)->p_base; \ } while (0) -#define DUK_BW_GET_BUFFER(thr,bw_ctx) \ - ((bw_ctx)->buf) +#define DUK_BW_GET_BUFFER(thr, bw_ctx) ((bw_ctx)->buf) /* Ensuring (reserving) space. */ -#define DUK_BW_ENSURE(thr,bw_ctx,sz) do { \ +#define DUK_BW_ENSURE(thr, bw_ctx, sz) \ + do { \ duk_size_t duk__sz, duk__space; \ DUK_BW_ASSERT_VALID((thr), (bw_ctx)); \ duk__sz = (sz); \ @@ -2554,22 +2597,21 @@ } while (0) /* NOTE: Multiple evaluation of 'ptr' in this macro. */ /* XXX: Rework to use an always-inline function? */ -#define DUK_BW_ENSURE_RAW(thr,bw_ctx,sz,ptr) \ - (((duk_size_t) ((bw_ctx)->p_limit - (ptr)) >= (sz)) ? \ - (ptr) : \ - ((bw_ctx)->p = (ptr), duk_bw_resize((thr),(bw_ctx),(sz)))) -#define DUK_BW_ENSURE_GETPTR(thr,bw_ctx,sz) \ - DUK_BW_ENSURE_RAW((thr), (bw_ctx), (sz), (bw_ctx)->p) -#define DUK_BW_ASSERT_SPACE_EXPR(thr,bw_ctx,sz) \ +#define DUK_BW_ENSURE_RAW(thr, bw_ctx, sz, ptr) \ + (((duk_size_t) ((bw_ctx)->p_limit - (ptr)) >= (sz)) ? (ptr) : ((bw_ctx)->p = (ptr), duk_bw_resize((thr), (bw_ctx), (sz)))) +#define DUK_BW_ENSURE_GETPTR(thr, bw_ctx, sz) DUK_BW_ENSURE_RAW((thr), (bw_ctx), (sz), (bw_ctx)->p) +#define DUK_BW_ASSERT_SPACE_EXPR(thr, bw_ctx, sz) \ (DUK_BW_ASSERT_VALID_EXPR((thr), (bw_ctx)), \ DUK_ASSERT_EXPR((duk_size_t) ((bw_ctx)->p_limit - (bw_ctx)->p) >= (duk_size_t) (sz))) -#define DUK_BW_ASSERT_SPACE(thr,bw_ctx,sz) do { \ +#define DUK_BW_ASSERT_SPACE(thr, bw_ctx, sz) \ + do { \ DUK_BW_ASSERT_SPACE_EXPR((thr), (bw_ctx), (sz)); \ } while (0) /* Miscellaneous. */ -#define DUK_BW_SETPTR_AND_COMPACT(thr,bw_ctx,ptr) do { \ +#define DUK_BW_SETPTR_AND_COMPACT(thr, bw_ctx, ptr) \ + do { \ (bw_ctx)->p = (ptr); \ duk_bw_compact((thr), (bw_ctx)); \ } while (0) @@ -2580,11 +2622,13 @@ * explicit pointer load/stores get generated (e.g. gcc -Os). */ -#define DUK_BW_WRITE_RAW_U8(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_U8(thr, bw_ctx, val) \ + do { \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 1); \ *(bw_ctx)->p++ = (duk_uint8_t) (val); \ } while (0) -#define DUK_BW_WRITE_RAW_U8_2(thr,bw_ctx,val1,val2) do { \ +#define DUK_BW_WRITE_RAW_U8_2(thr, bw_ctx, val1, val2) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 2); \ duk__p = (bw_ctx)->p; \ @@ -2592,7 +2636,8 @@ *duk__p++ = (duk_uint8_t) (val2); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_3(thr,bw_ctx,val1,val2,val3) do { \ +#define DUK_BW_WRITE_RAW_U8_3(thr, bw_ctx, val1, val2, val3) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 3); \ duk__p = (bw_ctx)->p; \ @@ -2601,7 +2646,8 @@ *duk__p++ = (duk_uint8_t) (val3); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_4(thr,bw_ctx,val1,val2,val3,val4) do { \ +#define DUK_BW_WRITE_RAW_U8_4(thr, bw_ctx, val1, val2, val3, val4) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 4); \ duk__p = (bw_ctx)->p; \ @@ -2611,7 +2657,8 @@ *duk__p++ = (duk_uint8_t) (val4); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_5(thr,bw_ctx,val1,val2,val3,val4,val5) do { \ +#define DUK_BW_WRITE_RAW_U8_5(thr, bw_ctx, val1, val2, val3, val4, val5) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 5); \ duk__p = (bw_ctx)->p; \ @@ -2622,7 +2669,8 @@ *duk__p++ = (duk_uint8_t) (val5); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_U8_6(thr,bw_ctx,val1,val2,val3,val4,val5,val6) do { \ +#define DUK_BW_WRITE_RAW_U8_6(thr, bw_ctx, val1, val2, val3, val4, val5, val6) \ + do { \ duk_uint8_t *duk__p; \ DUK_BW_ASSERT_SPACE((thr), (bw_ctx), 6); \ duk__p = (bw_ctx)->p; \ @@ -2634,7 +2682,8 @@ *duk__p++ = (duk_uint8_t) (val6); \ (bw_ctx)->p = duk__p; \ } while (0) -#define DUK_BW_WRITE_RAW_XUTF8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_RAW_XUTF8(thr, bw_ctx, cp) \ + do { \ duk_ucodepoint_t duk__cp; \ duk_small_int_t duk__enc_len; \ duk__cp = (duk_ucodepoint_t) (cp); \ @@ -2642,7 +2691,8 @@ duk__enc_len = duk_unicode_encode_xutf8(duk__cp, (bw_ctx)->p); \ (bw_ctx)->p += duk__enc_len; \ } while (0) -#define DUK_BW_WRITE_RAW_CESU8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_RAW_CESU8(thr, bw_ctx, cp) \ + do { \ duk_ucodepoint_t duk__cp; \ duk_small_int_t duk__enc_len; \ duk__cp = (duk_ucodepoint_t) (cp); \ @@ -2652,7 +2702,8 @@ } while (0) /* XXX: add temporary duk__p pointer here too; sharing */ /* XXX: avoid unsafe variants */ -#define DUK_BW_WRITE_RAW_BYTES(thr,bw_ctx,valptr,valsz) do { \ +#define DUK_BW_WRITE_RAW_BYTES(thr, bw_ctx, valptr, valsz) \ + do { \ const void *duk__valptr; \ duk_size_t duk__valsz; \ duk__valptr = (const void *) (valptr); \ @@ -2660,7 +2711,8 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), duk__valptr, duk__valsz); \ (bw_ctx)->p += duk__valsz; \ } while (0) -#define DUK_BW_WRITE_RAW_CSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_CSTRING(thr, bw_ctx, val) \ + do { \ const duk_uint8_t *duk__val; \ duk_size_t duk__val_len; \ duk__val = (const duk_uint8_t *) (val); \ @@ -2668,93 +2720,107 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) duk__val, duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HSTRING(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HSTRING_GET_BYTELEN((val)); \ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HSTRING_GET_DATA((val)), duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER_FIXED(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER_FIXED(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_FIXED_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_RAW_HBUFFER_DYNAMIC(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_RAW_HBUFFER_DYNAMIC(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_DYNAMIC_GET_SIZE((val)); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) /* Append bytes from a slice already in the buffer. */ -#define DUK_BW_WRITE_RAW_SLICE(thr,bw,dst_off,dst_len) \ - duk_bw_write_raw_slice((thr), (bw), (dst_off), (dst_len)) +#define DUK_BW_WRITE_RAW_SLICE(thr, bw, dst_off, dst_len) duk_bw_write_raw_slice((thr), (bw), (dst_off), (dst_len)) /* Insert bytes in the middle of the buffer from an external buffer. */ -#define DUK_BW_INSERT_RAW_BYTES(thr,bw,dst_off,buf,len) \ - duk_bw_insert_raw_bytes((thr), (bw), (dst_off), (buf), (len)) +#define DUK_BW_INSERT_RAW_BYTES(thr, bw, dst_off, buf, len) duk_bw_insert_raw_bytes((thr), (bw), (dst_off), (buf), (len)) /* Insert bytes in the middle of the buffer from a slice already * in the buffer. Source offset is interpreted "before" the operation. */ -#define DUK_BW_INSERT_RAW_SLICE(thr,bw,dst_off,src_off,len) \ - duk_bw_insert_raw_slice((thr), (bw), (dst_off), (src_off), (len)) +#define DUK_BW_INSERT_RAW_SLICE(thr, bw, dst_off, src_off, len) duk_bw_insert_raw_slice((thr), (bw), (dst_off), (src_off), (len)) /* Insert a reserved area somewhere in the buffer; caller fills it. * Evaluates to a (duk_uint_t *) pointing to the start of the reserved * area for convenience. */ -#define DUK_BW_INSERT_RAW_AREA(thr,bw,off,len) \ - duk_bw_insert_raw_area((thr), (bw), (off), (len)) +#define DUK_BW_INSERT_RAW_AREA(thr, bw, off, len) duk_bw_insert_raw_area((thr), (bw), (off), (len)) /* Remove a slice from inside buffer. */ -#define DUK_BW_REMOVE_RAW_SLICE(thr,bw,off,len) \ - duk_bw_remove_raw_slice((thr), (bw), (off), (len)) +#define DUK_BW_REMOVE_RAW_SLICE(thr, bw, off, len) duk_bw_remove_raw_slice((thr), (bw), (off), (len)) /* Safe write calls which will ensure space first. */ -#define DUK_BW_WRITE_ENSURE_U8(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_U8(thr, bw_ctx, val) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 1); \ DUK_BW_WRITE_RAW_U8((thr), (bw_ctx), (val)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_2(thr,bw_ctx,val1,val2) do { \ +#define DUK_BW_WRITE_ENSURE_U8_2(thr, bw_ctx, val1, val2) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 2); \ DUK_BW_WRITE_RAW_U8_2((thr), (bw_ctx), (val1), (val2)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_3(thr,bw_ctx,val1,val2,val3) do { \ +#define DUK_BW_WRITE_ENSURE_U8_3(thr, bw_ctx, val1, val2, val3) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 3); \ DUK_BW_WRITE_RAW_U8_3((thr), (bw_ctx), (val1), (val2), (val3)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_4(thr,bw_ctx,val1,val2,val3,val4) do { \ +#define DUK_BW_WRITE_ENSURE_U8_4(thr, bw_ctx, val1, val2, val3, val4) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 4); \ DUK_BW_WRITE_RAW_U8_4((thr), (bw_ctx), (val1), (val2), (val3), (val4)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_5(thr,bw_ctx,val1,val2,val3,val4,val5) do { \ +#define DUK_BW_WRITE_ENSURE_U8_5(thr, bw_ctx, val1, val2, val3, val4, val5) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 5); \ DUK_BW_WRITE_RAW_U8_5((thr), (bw_ctx), (val1), (val2), (val3), (val4), (val5)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_U8_6(thr,bw_ctx,val1,val2,val3,val4,val5,val6) do { \ +#define DUK_BW_WRITE_ENSURE_U8_6(thr, bw_ctx, val1, val2, val3, val4, val5, val6) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), 6); \ DUK_BW_WRITE_RAW_U8_6((thr), (bw_ctx), (val1), (val2), (val3), (val4), (val5), (val6)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_XUTF8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_ENSURE_XUTF8(thr, bw_ctx, cp) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), DUK_UNICODE_MAX_XUTF8_LENGTH); \ DUK_BW_WRITE_RAW_XUTF8((thr), (bw_ctx), (cp)); \ } while (0) -#define DUK_BW_WRITE_ENSURE_CESU8(thr,bw_ctx,cp) do { \ +#define DUK_BW_WRITE_ENSURE_CESU8(thr, bw_ctx, cp) \ + do { \ DUK_BW_ENSURE((thr), (bw_ctx), DUK_UNICODE_MAX_CESU8_LENGTH); \ DUK_BW_WRITE_RAW_CESU8((thr), (bw_ctx), (cp)); \ } while (0) /* XXX: add temporary duk__p pointer here too; sharing */ /* XXX: avoid unsafe */ -#define DUK_BW_WRITE_ENSURE_BYTES(thr,bw_ctx,valptr,valsz) do { \ +#define DUK_BW_WRITE_ENSURE_BYTES(thr, bw_ctx, valptr, valsz) \ + do { \ const void *duk__valptr; \ duk_size_t duk__valsz; \ duk__valptr = (const void *) (valptr); \ @@ -2763,7 +2829,8 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), duk__valptr, duk__valsz); \ (bw_ctx)->p += duk__valsz; \ } while (0) -#define DUK_BW_WRITE_ENSURE_CSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_CSTRING(thr, bw_ctx, val) \ + do { \ const duk_uint8_t *duk__val; \ duk_size_t duk__val_len; \ duk__val = (const duk_uint8_t *) (val); \ @@ -2772,45 +2839,53 @@ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) duk__val, duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HSTRING(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HSTRING(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HSTRING_GET_BYTELEN((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HSTRING_GET_DATA((val)), duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER_FIXED(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER_FIXED(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_FIXED_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_FIXED_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_HBUFFER_DYNAMIC(thr,bw_ctx,val) do { \ +#define DUK_BW_WRITE_ENSURE_HBUFFER_DYNAMIC(thr, bw_ctx, val) \ + do { \ duk_size_t duk__val_len; \ duk__val_len = DUK_HBUFFER_DYNAMIC_GET_SIZE((val)); \ DUK_BW_ENSURE((thr), (bw_ctx), duk__val_len); \ - duk_memcpy_unsafe((void *) ((bw_ctx)->p), (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), duk__val_len); \ + duk_memcpy_unsafe((void *) ((bw_ctx)->p), \ + (const void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((thr)->heap, (val)), \ + duk__val_len); \ (bw_ctx)->p += duk__val_len; \ } while (0) -#define DUK_BW_WRITE_ENSURE_SLICE(thr,bw,dst_off,dst_len) \ - duk_bw_write_ensure_slice((thr), (bw), (dst_off), (dst_len)) -#define DUK_BW_INSERT_ENSURE_BYTES(thr,bw,dst_off,buf,len) \ - duk_bw_insert_ensure_bytes((thr), (bw), (dst_off), (buf), (len)) -#define DUK_BW_INSERT_ENSURE_SLICE(thr,bw,dst_off,src_off,len) \ +#define DUK_BW_WRITE_ENSURE_SLICE(thr, bw, dst_off, dst_len) duk_bw_write_ensure_slice((thr), (bw), (dst_off), (dst_len)) +#define DUK_BW_INSERT_ENSURE_BYTES(thr, bw, dst_off, buf, len) duk_bw_insert_ensure_bytes((thr), (bw), (dst_off), (buf), (len)) +#define DUK_BW_INSERT_ENSURE_SLICE(thr, bw, dst_off, src_off, len) \ duk_bw_insert_ensure_slice((thr), (bw), (dst_off), (src_off), (len)) -#define DUK_BW_INSERT_ENSURE_AREA(thr,bw,off,len) \ +#define DUK_BW_INSERT_ENSURE_AREA(thr, bw, off, len) \ /* Evaluates to (duk_uint8_t *) pointing to start of area. */ \ duk_bw_insert_ensure_area((thr), (bw), (off), (len)) -#define DUK_BW_REMOVE_ENSURE_SLICE(thr,bw,off,len) \ +#define DUK_BW_REMOVE_ENSURE_SLICE(thr, bw, off, len) \ /* No difference between raw/ensure because the buffer shrinks. */ \ DUK_BW_REMOVE_RAW_SLICE((thr), (bw), (off), (len)) @@ -2826,13 +2901,13 @@ DUK_INTERNAL_DECL const duk_int16_t duk_hex_dectab_shift4256; DUK_INTERNAL_DECL const duk_uint16_t duk_hex_enctab256; #endif -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* Note: assumes that duk_util_probe_steps size is 32 */ #if defined(DUK_USE_HOBJECT_HASH_PART) #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL duk_uint8_t duk_util_probe_steps32; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ #endif #if defined(DUK_USE_STRHASH_DENSE) @@ -2860,10 +2935,26 @@ DUK_INTERNAL_DECL void duk_bw_compact(duk_hthread *thr, duk_bufwriter_ctx *bw_ctx); DUK_INTERNAL_DECL void duk_bw_write_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t src_off, duk_size_t len); DUK_INTERNAL_DECL void duk_bw_write_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t src_off, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_raw_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_ensure_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len); -DUK_INTERNAL_DECL void duk_bw_insert_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_raw_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_ensure_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_raw_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len); +DUK_INTERNAL_DECL void duk_bw_insert_ensure_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len); DUK_INTERNAL_DECL duk_uint8_t *duk_bw_insert_raw_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); DUK_INTERNAL_DECL duk_uint8_t *duk_bw_insert_ensure_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); DUK_INTERNAL_DECL void duk_bw_remove_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len); @@ -2890,10 +2981,12 @@ DUK_INTERNAL_DECL void duk_raw_writeinc_xutf8(duk_uint8_t **p, duk_ucodepoint_t val); DUK_INTERNAL_DECL void duk_raw_writeinc_cesu8(duk_uint8_t **p, duk_ucodepoint_t val); -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ DUK_INTERNAL_DECL void duk_byteswap_bytes(duk_uint8_t *p, duk_small_uint_t len); #endif +DUK_INTERNAL_DECL duk_double_t duk_util_get_random_double(duk_hthread *thr); + /* memcpy(), memmove() etc wrappers. The plain variants like duk_memcpy() * assume C99+ and 'src' and 'dst' pointers must be non-NULL even when the * operation size is zero. The unsafe variants like duk_memcpy_safe() deal @@ -2904,7 +2997,8 @@ * few extra bytes per call site adds up to ~1kB footprint. */ #if defined(DUK_USE_ALLOW_UNDEFINED_BEHAVIOR) -#define duk_memcpy(dst,src,len) do { \ +#define duk_memcpy(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2912,8 +3006,9 @@ DUK_ASSERT(duk__src != NULL || duk__len == 0U); \ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memcpy_unsafe(dst,src,len) duk_memcpy((dst), (src), (len)) -#define duk_memmove(dst,src,len) do { \ +#define duk_memcpy_unsafe(dst, src, len) duk_memcpy((dst), (src), (len)) +#define duk_memmove(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2921,24 +3016,27 @@ DUK_ASSERT(duk__src != NULL || duk__len == 0U); \ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memmove_unsafe(dst,src,len) duk_memmove((dst), (src), (len)) -#define duk_memset(dst,val,len) do { \ +#define duk_memmove_unsafe(dst, src, len) duk_memmove((dst), (src), (len)) +#define duk_memset(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } while (0) -#define duk_memset_unsafe(dst,val,len) duk_memset((dst), (val), (len)) -#define duk_memzero(dst,len) do { \ +#define duk_memset_unsafe(dst, val, len) duk_memset((dst), (val), (len)) +#define duk_memzero(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } while (0) -#define duk_memzero_unsafe(dst,len) duk_memzero((dst), (len)) -#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ -#define duk_memcpy(dst,src,len) do { \ +#define duk_memzero_unsafe(dst, len) duk_memzero((dst), (len)) +#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#define duk_memcpy(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2946,7 +3044,8 @@ DUK_ASSERT(duk__src != NULL); \ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memcpy_unsafe(dst,src,len) do { \ +#define duk_memcpy_unsafe(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2958,7 +3057,8 @@ (void) DUK_MEMCPY(duk__dst, duk__src, (size_t) duk__len); \ } \ } while (0) -#define duk_memmove(dst,src,len) do { \ +#define duk_memmove(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2966,7 +3066,8 @@ DUK_ASSERT(duk__src != NULL); \ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } while (0) -#define duk_memmove_unsafe(dst,src,len) do { \ +#define duk_memmove_unsafe(dst, src, len) \ + do { \ void *duk__dst = (dst); \ const void *duk__src = (src); \ duk_size_t duk__len = (len); \ @@ -2978,14 +3079,16 @@ (void) DUK_MEMMOVE(duk__dst, duk__src, (size_t) duk__len); \ } \ } while (0) -#define duk_memset(dst,val,len) do { \ +#define duk_memset(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL); \ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } while (0) -#define duk_memset_unsafe(dst,val,len) do { \ +#define duk_memset_unsafe(dst, val, len) \ + do { \ void *duk__dst = (dst); \ duk_small_int_t duk__val = (val); \ duk_size_t duk__len = (len); \ @@ -2995,13 +3098,15 @@ (void) DUK_MEMSET(duk__dst, duk__val, (size_t) duk__len); \ } \ } while (0) -#define duk_memzero(dst,len) do { \ +#define duk_memzero(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL); \ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } while (0) -#define duk_memzero_unsafe(dst,len) do { \ +#define duk_memzero_unsafe(dst, len) \ + do { \ void *duk__dst = (dst); \ duk_size_t duk__len = (len); \ DUK_ASSERT(duk__dst != NULL || duk__len == 0U); \ @@ -3010,7 +3115,7 @@ (void) DUK_MEMZERO(duk__dst, (size_t) duk__len); \ } \ } while (0) -#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ DUK_INTERNAL_DECL duk_small_int_t duk_memcmp(const void *s1, const void *s2, duk_size_t len); DUK_INTERNAL_DECL duk_small_int_t duk_memcmp_unsafe(const void *s1, const void *s2, duk_size_t len); @@ -3056,10 +3161,9 @@ * * However, incorrectly true for x == 0 so check for that explicitly. */ -#define DUK_IS_POWER_OF_TWO(x) \ - ((x) != 0U && ((x) & ((x) - 1U)) == 0U) +#define DUK_IS_POWER_OF_TWO(x) ((x) != 0U && ((x) & ((x) -1U)) == 0U) -#endif /* DUK_UTIL_H_INCLUDED */ +#endif /* DUK_UTIL_H_INCLUDED */ /* #include duk_strings.h */ #line 1 "duk_strings.h" /* @@ -3086,151 +3190,151 @@ #define DUK_ERRMSG_H_INCLUDED /* Mostly API and built-in method related */ -#define DUK_STR_INTERNAL_ERROR "internal error" -#define DUK_STR_UNSUPPORTED "unsupported" -#define DUK_STR_INVALID_COUNT "invalid count" -#define DUK_STR_INVALID_ARGS "invalid args" -#define DUK_STR_INVALID_STATE "invalid state" -#define DUK_STR_INVALID_INPUT "invalid input" -#define DUK_STR_INVALID_LENGTH "invalid length" -#define DUK_STR_NOT_CONSTRUCTABLE "not constructable" -#define DUK_STR_CONSTRUCT_ONLY "constructor requires 'new'" -#define DUK_STR_NOT_CALLABLE "not callable" -#define DUK_STR_NOT_EXTENSIBLE "not extensible" -#define DUK_STR_NOT_WRITABLE "not writable" -#define DUK_STR_NOT_CONFIGURABLE "not configurable" -#define DUK_STR_INVALID_CONTEXT "invalid context" -#define DUK_STR_INVALID_INDEX "invalid args" -#define DUK_STR_PUSH_BEYOND_ALLOC_STACK "cannot push beyond allocated stack" -#define DUK_STR_NOT_UNDEFINED "unexpected type" -#define DUK_STR_NOT_NULL "unexpected type" -#define DUK_STR_NOT_BOOLEAN "unexpected type" -#define DUK_STR_NOT_NUMBER "unexpected type" -#define DUK_STR_NOT_STRING "unexpected type" -#define DUK_STR_NOT_OBJECT "unexpected type" -#define DUK_STR_NOT_POINTER "unexpected type" -#define DUK_STR_NOT_BUFFER "not buffer" /* still in use with verbose messages */ -#define DUK_STR_UNEXPECTED_TYPE "unexpected type" -#define DUK_STR_NOT_THREAD "unexpected type" -#define DUK_STR_NOT_COMPFUNC "unexpected type" -#define DUK_STR_NOT_NATFUNC "unexpected type" -#define DUK_STR_NOT_C_FUNCTION "unexpected type" -#define DUK_STR_NOT_FUNCTION "unexpected type" -#define DUK_STR_NOT_REGEXP "unexpected type" -#define DUK_STR_TOPRIMITIVE_FAILED "coercion to primitive failed" -#define DUK_STR_NUMBER_OUTSIDE_RANGE "number outside range" -#define DUK_STR_NOT_OBJECT_COERCIBLE "not object coercible" -#define DUK_STR_CANNOT_NUMBER_COERCE_SYMBOL "cannot number coerce Symbol" -#define DUK_STR_CANNOT_STRING_COERCE_SYMBOL "cannot string coerce Symbol" -#define DUK_STR_STRING_TOO_LONG "string too long" -#define DUK_STR_BUFFER_TOO_LONG "buffer too long" -#define DUK_STR_ALLOC_FAILED "alloc failed" -#define DUK_STR_WRONG_BUFFER_TYPE "wrong buffer type" -#define DUK_STR_BASE64_ENCODE_FAILED "base64 encode failed" -#define DUK_STR_SOURCE_DECODE_FAILED "source decode failed" -#define DUK_STR_UTF8_DECODE_FAILED "utf-8 decode failed" -#define DUK_STR_BASE64_DECODE_FAILED "base64 decode failed" -#define DUK_STR_HEX_DECODE_FAILED "hex decode failed" -#define DUK_STR_INVALID_BYTECODE "invalid bytecode" -#define DUK_STR_NO_SOURCECODE "no sourcecode" -#define DUK_STR_RESULT_TOO_LONG "result too long" -#define DUK_STR_INVALID_CFUNC_RC "invalid C function rc" -#define DUK_STR_INVALID_INSTANCEOF_RVAL "invalid instanceof rval" -#define DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO "instanceof rval has no .prototype" +#define DUK_STR_INTERNAL_ERROR "internal error" +#define DUK_STR_UNSUPPORTED "unsupported" +#define DUK_STR_INVALID_COUNT "invalid count" +#define DUK_STR_INVALID_ARGS "invalid args" +#define DUK_STR_INVALID_STATE "invalid state" +#define DUK_STR_INVALID_INPUT "invalid input" +#define DUK_STR_INVALID_LENGTH "invalid length" +#define DUK_STR_NOT_CONSTRUCTABLE "not constructable" +#define DUK_STR_CONSTRUCT_ONLY "constructor requires 'new'" +#define DUK_STR_NOT_CALLABLE "not callable" +#define DUK_STR_NOT_EXTENSIBLE "not extensible" +#define DUK_STR_NOT_WRITABLE "not writable" +#define DUK_STR_NOT_CONFIGURABLE "not configurable" +#define DUK_STR_INVALID_CONTEXT "invalid context" +#define DUK_STR_INVALID_INDEX "invalid args" +#define DUK_STR_PUSH_BEYOND_ALLOC_STACK "cannot push beyond allocated stack" +#define DUK_STR_NOT_UNDEFINED "unexpected type" +#define DUK_STR_NOT_NULL "unexpected type" +#define DUK_STR_NOT_BOOLEAN "unexpected type" +#define DUK_STR_NOT_NUMBER "unexpected type" +#define DUK_STR_NOT_STRING "unexpected type" +#define DUK_STR_NOT_OBJECT "unexpected type" +#define DUK_STR_NOT_POINTER "unexpected type" +#define DUK_STR_NOT_BUFFER "not buffer" /* still in use with verbose messages */ +#define DUK_STR_UNEXPECTED_TYPE "unexpected type" +#define DUK_STR_NOT_THREAD "unexpected type" +#define DUK_STR_NOT_COMPFUNC "unexpected type" +#define DUK_STR_NOT_NATFUNC "unexpected type" +#define DUK_STR_NOT_C_FUNCTION "unexpected type" +#define DUK_STR_NOT_FUNCTION "unexpected type" +#define DUK_STR_NOT_REGEXP "unexpected type" +#define DUK_STR_TOPRIMITIVE_FAILED "coercion to primitive failed" +#define DUK_STR_NUMBER_OUTSIDE_RANGE "number outside range" +#define DUK_STR_NOT_OBJECT_COERCIBLE "not object coercible" +#define DUK_STR_CANNOT_NUMBER_COERCE_SYMBOL "cannot number coerce Symbol" +#define DUK_STR_CANNOT_STRING_COERCE_SYMBOL "cannot string coerce Symbol" +#define DUK_STR_STRING_TOO_LONG "string too long" +#define DUK_STR_BUFFER_TOO_LONG "buffer too long" +#define DUK_STR_ALLOC_FAILED "alloc failed" +#define DUK_STR_WRONG_BUFFER_TYPE "wrong buffer type" +#define DUK_STR_BASE64_ENCODE_FAILED "base64 encode failed" +#define DUK_STR_SOURCE_DECODE_FAILED "source decode failed" +#define DUK_STR_UTF8_DECODE_FAILED "utf-8 decode failed" +#define DUK_STR_BASE64_DECODE_FAILED "base64 decode failed" +#define DUK_STR_HEX_DECODE_FAILED "hex decode failed" +#define DUK_STR_INVALID_BYTECODE "invalid bytecode" +#define DUK_STR_NO_SOURCECODE "no sourcecode" +#define DUK_STR_RESULT_TOO_LONG "result too long" +#define DUK_STR_INVALID_CFUNC_RC "invalid C function rc" +#define DUK_STR_INVALID_INSTANCEOF_RVAL "invalid instanceof rval" +#define DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO "instanceof rval has no .prototype" /* JSON */ -#define DUK_STR_FMT_PTR "%p" -#define DUK_STR_FMT_INVALID_JSON "invalid json (at offset %ld)" -#define DUK_STR_CYCLIC_INPUT "cyclic input" +#define DUK_STR_FMT_PTR "%p" +#define DUK_STR_FMT_INVALID_JSON "invalid json (at offset %ld)" +#define DUK_STR_CYCLIC_INPUT "cyclic input" /* Generic codec */ -#define DUK_STR_DEC_RECLIMIT "decode recursion limit" -#define DUK_STR_ENC_RECLIMIT "encode recursion limit" +#define DUK_STR_DEC_RECLIMIT "decode recursion limit" +#define DUK_STR_ENC_RECLIMIT "encode recursion limit" /* Object property access */ -#define DUK_STR_INVALID_BASE "invalid base value" -#define DUK_STR_STRICT_CALLER_READ "cannot read strict 'caller'" -#define DUK_STR_PROXY_REJECTED "proxy rejected" -#define DUK_STR_INVALID_ARRAY_LENGTH "invalid array length" -#define DUK_STR_SETTER_UNDEFINED "setter undefined" -#define DUK_STR_INVALID_DESCRIPTOR "invalid descriptor" +#define DUK_STR_INVALID_BASE "invalid base value" +#define DUK_STR_STRICT_CALLER_READ "cannot read strict 'caller'" +#define DUK_STR_PROXY_REJECTED "proxy rejected" +#define DUK_STR_INVALID_ARRAY_LENGTH "invalid array length" +#define DUK_STR_SETTER_UNDEFINED "setter undefined" +#define DUK_STR_INVALID_DESCRIPTOR "invalid descriptor" /* Proxy */ -#define DUK_STR_PROXY_REVOKED "proxy revoked" -#define DUK_STR_INVALID_TRAP_RESULT "invalid trap result" +#define DUK_STR_PROXY_REVOKED "proxy revoked" +#define DUK_STR_INVALID_TRAP_RESULT "invalid trap result" /* Variables */ /* Lexer */ -#define DUK_STR_INVALID_ESCAPE "invalid escape" -#define DUK_STR_UNTERMINATED_STRING "unterminated string" -#define DUK_STR_UNTERMINATED_COMMENT "unterminated comment" -#define DUK_STR_UNTERMINATED_REGEXP "unterminated regexp" -#define DUK_STR_TOKEN_LIMIT "token limit" -#define DUK_STR_REGEXP_SUPPORT_DISABLED "regexp support disabled" -#define DUK_STR_INVALID_NUMBER_LITERAL "invalid number literal" -#define DUK_STR_INVALID_TOKEN "invalid token" +#define DUK_STR_INVALID_ESCAPE "invalid escape" +#define DUK_STR_UNTERMINATED_STRING "unterminated string" +#define DUK_STR_UNTERMINATED_COMMENT "unterminated comment" +#define DUK_STR_UNTERMINATED_REGEXP "unterminated regexp" +#define DUK_STR_TOKEN_LIMIT "token limit" +#define DUK_STR_REGEXP_SUPPORT_DISABLED "regexp support disabled" +#define DUK_STR_INVALID_NUMBER_LITERAL "invalid number literal" +#define DUK_STR_INVALID_TOKEN "invalid token" /* Compiler */ -#define DUK_STR_PARSE_ERROR "parse error" -#define DUK_STR_DUPLICATE_LABEL "duplicate label" -#define DUK_STR_INVALID_LABEL "invalid label" -#define DUK_STR_INVALID_ARRAY_LITERAL "invalid array literal" -#define DUK_STR_INVALID_OBJECT_LITERAL "invalid object literal" -#define DUK_STR_INVALID_VAR_DECLARATION "invalid variable declaration" -#define DUK_STR_CANNOT_DELETE_IDENTIFIER "cannot delete identifier" -#define DUK_STR_INVALID_EXPRESSION "invalid expression" -#define DUK_STR_INVALID_LVALUE "invalid lvalue" -#define DUK_STR_INVALID_NEWTARGET "invalid new.target" -#define DUK_STR_EXPECTED_IDENTIFIER "expected identifier" -#define DUK_STR_EMPTY_EXPR_NOT_ALLOWED "empty expression not allowed" -#define DUK_STR_INVALID_FOR "invalid for statement" -#define DUK_STR_INVALID_SWITCH "invalid switch statement" -#define DUK_STR_INVALID_BREAK_CONT_LABEL "invalid break/continue label" -#define DUK_STR_INVALID_RETURN "invalid return" -#define DUK_STR_INVALID_TRY "invalid try" -#define DUK_STR_INVALID_THROW "invalid throw" -#define DUK_STR_WITH_IN_STRICT_MODE "with in strict mode" -#define DUK_STR_FUNC_STMT_NOT_ALLOWED "function statement not allowed" -#define DUK_STR_UNTERMINATED_STMT "unterminated statement" -#define DUK_STR_INVALID_ARG_NAME "invalid argument name" -#define DUK_STR_INVALID_FUNC_NAME "invalid function name" -#define DUK_STR_INVALID_GETSET_NAME "invalid getter/setter name" -#define DUK_STR_FUNC_NAME_REQUIRED "function name required" +#define DUK_STR_PARSE_ERROR "parse error" +#define DUK_STR_DUPLICATE_LABEL "duplicate label" +#define DUK_STR_INVALID_LABEL "invalid label" +#define DUK_STR_INVALID_ARRAY_LITERAL "invalid array literal" +#define DUK_STR_INVALID_OBJECT_LITERAL "invalid object literal" +#define DUK_STR_INVALID_VAR_DECLARATION "invalid variable declaration" +#define DUK_STR_CANNOT_DELETE_IDENTIFIER "cannot delete identifier" +#define DUK_STR_INVALID_EXPRESSION "invalid expression" +#define DUK_STR_INVALID_LVALUE "invalid lvalue" +#define DUK_STR_INVALID_NEWTARGET "invalid new.target" +#define DUK_STR_EXPECTED_IDENTIFIER "expected identifier" +#define DUK_STR_EMPTY_EXPR_NOT_ALLOWED "empty expression not allowed" +#define DUK_STR_INVALID_FOR "invalid for statement" +#define DUK_STR_INVALID_SWITCH "invalid switch statement" +#define DUK_STR_INVALID_BREAK_CONT_LABEL "invalid break/continue label" +#define DUK_STR_INVALID_RETURN "invalid return" +#define DUK_STR_INVALID_TRY "invalid try" +#define DUK_STR_INVALID_THROW "invalid throw" +#define DUK_STR_WITH_IN_STRICT_MODE "with in strict mode" +#define DUK_STR_FUNC_STMT_NOT_ALLOWED "function statement not allowed" +#define DUK_STR_UNTERMINATED_STMT "unterminated statement" +#define DUK_STR_INVALID_ARG_NAME "invalid argument name" +#define DUK_STR_INVALID_FUNC_NAME "invalid function name" +#define DUK_STR_INVALID_GETSET_NAME "invalid getter/setter name" +#define DUK_STR_FUNC_NAME_REQUIRED "function name required" /* RegExp */ -#define DUK_STR_INVALID_QUANTIFIER "invalid regexp quantifier" -#define DUK_STR_INVALID_QUANTIFIER_NO_ATOM "quantifier without preceding atom" -#define DUK_STR_INVALID_QUANTIFIER_VALUES "quantifier values invalid (qmin > qmax)" -#define DUK_STR_QUANTIFIER_TOO_MANY_COPIES "quantifier requires too many atom copies" -#define DUK_STR_UNEXPECTED_CLOSING_PAREN "unexpected closing parenthesis" -#define DUK_STR_UNEXPECTED_END_OF_PATTERN "unexpected end of pattern" -#define DUK_STR_UNEXPECTED_REGEXP_TOKEN "unexpected token in regexp" -#define DUK_STR_INVALID_REGEXP_FLAGS "invalid regexp flags" -#define DUK_STR_INVALID_REGEXP_ESCAPE "invalid regexp escape" -#define DUK_STR_INVALID_BACKREFS "invalid backreference(s)" -#define DUK_STR_INVALID_REGEXP_CHARACTER "invalid regexp character" -#define DUK_STR_INVALID_REGEXP_GROUP "invalid regexp group" -#define DUK_STR_UNTERMINATED_CHARCLASS "unterminated character class" -#define DUK_STR_INVALID_RANGE "invalid range" +#define DUK_STR_INVALID_QUANTIFIER "invalid regexp quantifier" +#define DUK_STR_INVALID_QUANTIFIER_NO_ATOM "quantifier without preceding atom" +#define DUK_STR_INVALID_QUANTIFIER_VALUES "quantifier values invalid (qmin > qmax)" +#define DUK_STR_QUANTIFIER_TOO_MANY_COPIES "quantifier requires too many atom copies" +#define DUK_STR_UNEXPECTED_CLOSING_PAREN "unexpected closing parenthesis" +#define DUK_STR_UNEXPECTED_END_OF_PATTERN "unexpected end of pattern" +#define DUK_STR_UNEXPECTED_REGEXP_TOKEN "unexpected token in regexp" +#define DUK_STR_INVALID_REGEXP_FLAGS "invalid regexp flags" +#define DUK_STR_INVALID_REGEXP_ESCAPE "invalid regexp escape" +#define DUK_STR_INVALID_BACKREFS "invalid backreference(s)" +#define DUK_STR_INVALID_REGEXP_CHARACTER "invalid regexp character" +#define DUK_STR_INVALID_REGEXP_GROUP "invalid regexp group" +#define DUK_STR_UNTERMINATED_CHARCLASS "unterminated character class" +#define DUK_STR_INVALID_RANGE "invalid range" /* Limits */ -#define DUK_STR_VALSTACK_LIMIT "valstack limit" -#define DUK_STR_CALLSTACK_LIMIT "callstack limit" -#define DUK_STR_PROTOTYPE_CHAIN_LIMIT "prototype chain limit" -#define DUK_STR_BOUND_CHAIN_LIMIT "function call bound chain limit" -#define DUK_STR_NATIVE_STACK_LIMIT "C stack depth limit" -#define DUK_STR_COMPILER_RECURSION_LIMIT "compiler recursion limit" -#define DUK_STR_BYTECODE_LIMIT "bytecode limit" -#define DUK_STR_REG_LIMIT "register limit" -#define DUK_STR_TEMP_LIMIT "temp limit" -#define DUK_STR_CONST_LIMIT "const limit" -#define DUK_STR_FUNC_LIMIT "function limit" -#define DUK_STR_REGEXP_COMPILER_RECURSION_LIMIT "regexp compiler recursion limit" -#define DUK_STR_REGEXP_EXECUTOR_RECURSION_LIMIT "regexp executor recursion limit" -#define DUK_STR_REGEXP_EXECUTOR_STEP_LIMIT "regexp step limit" +#define DUK_STR_VALSTACK_LIMIT "valstack limit" +#define DUK_STR_CALLSTACK_LIMIT "callstack limit" +#define DUK_STR_PROTOTYPE_CHAIN_LIMIT "prototype chain limit" +#define DUK_STR_BOUND_CHAIN_LIMIT "function call bound chain limit" +#define DUK_STR_NATIVE_STACK_LIMIT "C stack depth limit" +#define DUK_STR_COMPILER_RECURSION_LIMIT "compiler recursion limit" +#define DUK_STR_BYTECODE_LIMIT "bytecode limit" +#define DUK_STR_REG_LIMIT "register limit" +#define DUK_STR_TEMP_LIMIT "temp limit" +#define DUK_STR_CONST_LIMIT "const limit" +#define DUK_STR_FUNC_LIMIT "function limit" +#define DUK_STR_REGEXP_COMPILER_RECURSION_LIMIT "regexp compiler recursion limit" +#define DUK_STR_REGEXP_EXECUTOR_RECURSION_LIMIT "regexp executor recursion limit" +#define DUK_STR_REGEXP_EXECUTOR_STEP_LIMIT "regexp step limit" -#endif /* DUK_ERRMSG_H_INCLUDED */ +#endif /* DUK_ERRMSG_H_INCLUDED */ /* #include duk_js_bytecode.h */ #line 1 "duk_js_bytecode.h" /* @@ -3318,403 +3422,394 @@ typedef duk_uint32_t duk_instr_t; -#define DUK_BC_SHIFT_OP 0 -#define DUK_BC_SHIFT_A 8 -#define DUK_BC_SHIFT_B 16 -#define DUK_BC_SHIFT_C 24 -#define DUK_BC_SHIFT_BC DUK_BC_SHIFT_B -#define DUK_BC_SHIFT_ABC DUK_BC_SHIFT_A - -#define DUK_BC_UNSHIFTED_MASK_OP 0xffUL -#define DUK_BC_UNSHIFTED_MASK_A 0xffUL -#define DUK_BC_UNSHIFTED_MASK_B 0xffUL -#define DUK_BC_UNSHIFTED_MASK_C 0xffUL -#define DUK_BC_UNSHIFTED_MASK_BC 0xffffUL -#define DUK_BC_UNSHIFTED_MASK_ABC 0xffffffUL - -#define DUK_BC_SHIFTED_MASK_OP (DUK_BC_UNSHIFTED_MASK_OP << DUK_BC_SHIFT_OP) -#define DUK_BC_SHIFTED_MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK_BC_SHIFT_A) -#define DUK_BC_SHIFTED_MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK_BC_SHIFT_B) -#define DUK_BC_SHIFTED_MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK_BC_SHIFT_C) -#define DUK_BC_SHIFTED_MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK_BC_SHIFT_BC) -#define DUK_BC_SHIFTED_MASK_ABC (DUK_BC_UNSHIFTED_MASK_ABC << DUK_BC_SHIFT_ABC) - -#define DUK_DEC_OP(x) ((x) & 0xffUL) -#define DUK_DEC_A(x) (((x) >> 8) & 0xffUL) -#define DUK_DEC_B(x) (((x) >> 16) & 0xffUL) -#define DUK_DEC_C(x) (((x) >> 24) & 0xffUL) -#define DUK_DEC_BC(x) (((x) >> 16) & 0xffffUL) -#define DUK_DEC_ABC(x) (((x) >> 8) & 0xffffffUL) - -#define DUK_ENC_OP(op) ((duk_instr_t) (op)) -#define DUK_ENC_OP_ABC(op,abc) ((duk_instr_t) ( \ - (((duk_instr_t) (abc)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_BC(op,a,bc) ((duk_instr_t) ( \ - (((duk_instr_t) (bc)) << 16) | \ - (((duk_instr_t) (a)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_B_C(op,a,b,c) ((duk_instr_t) ( \ - (((duk_instr_t) (c)) << 24) | \ - (((duk_instr_t) (b)) << 16) | \ - (((duk_instr_t) (a)) << 8) | \ - ((duk_instr_t) (op)) \ - )) -#define DUK_ENC_OP_A_B(op,a,b) DUK_ENC_OP_A_B_C((op),(a),(b),0) -#define DUK_ENC_OP_A(op,a) DUK_ENC_OP_A_B_C((op),(a),0,0) -#define DUK_ENC_OP_BC(op,bc) DUK_ENC_OP_A_BC((op),0,(bc)) +#define DUK_BC_SHIFT_OP 0 +#define DUK_BC_SHIFT_A 8 +#define DUK_BC_SHIFT_B 16 +#define DUK_BC_SHIFT_C 24 +#define DUK_BC_SHIFT_BC DUK_BC_SHIFT_B +#define DUK_BC_SHIFT_ABC DUK_BC_SHIFT_A + +#define DUK_BC_UNSHIFTED_MASK_OP 0xffUL +#define DUK_BC_UNSHIFTED_MASK_A 0xffUL +#define DUK_BC_UNSHIFTED_MASK_B 0xffUL +#define DUK_BC_UNSHIFTED_MASK_C 0xffUL +#define DUK_BC_UNSHIFTED_MASK_BC 0xffffUL +#define DUK_BC_UNSHIFTED_MASK_ABC 0xffffffUL + +#define DUK_BC_SHIFTED_MASK_OP (DUK_BC_UNSHIFTED_MASK_OP << DUK_BC_SHIFT_OP) +#define DUK_BC_SHIFTED_MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK_BC_SHIFT_A) +#define DUK_BC_SHIFTED_MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK_BC_SHIFT_B) +#define DUK_BC_SHIFTED_MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK_BC_SHIFT_C) +#define DUK_BC_SHIFTED_MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK_BC_SHIFT_BC) +#define DUK_BC_SHIFTED_MASK_ABC (DUK_BC_UNSHIFTED_MASK_ABC << DUK_BC_SHIFT_ABC) + +#define DUK_DEC_OP(x) ((x) &0xffUL) +#define DUK_DEC_A(x) (((x) >> 8) & 0xffUL) +#define DUK_DEC_B(x) (((x) >> 16) & 0xffUL) +#define DUK_DEC_C(x) (((x) >> 24) & 0xffUL) +#define DUK_DEC_BC(x) (((x) >> 16) & 0xffffUL) +#define DUK_DEC_ABC(x) (((x) >> 8) & 0xffffffUL) + +#define DUK_ENC_OP(op) ((duk_instr_t) (op)) +#define DUK_ENC_OP_ABC(op, abc) ((duk_instr_t) ((((duk_instr_t) (abc)) << 8) | ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_BC(op, a, bc) \ + ((duk_instr_t) ((((duk_instr_t) (bc)) << 16) | (((duk_instr_t) (a)) << 8) | ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_B_C(op, a, b, c) \ + ((duk_instr_t) ((((duk_instr_t) (c)) << 24) | (((duk_instr_t) (b)) << 16) | (((duk_instr_t) (a)) << 8) | \ + ((duk_instr_t) (op)))) +#define DUK_ENC_OP_A_B(op, a, b) DUK_ENC_OP_A_B_C((op), (a), (b), 0) +#define DUK_ENC_OP_A(op, a) DUK_ENC_OP_A_B_C((op), (a), 0, 0) +#define DUK_ENC_OP_BC(op, bc) DUK_ENC_OP_A_BC((op), 0, (bc)) /* Get opcode base value with B/C reg/const flags cleared. */ -#define DUK_BC_NOREGCONST_OP(op) ((op) & 0xfc) +#define DUK_BC_NOREGCONST_OP(op) ((op) &0xfc) /* Constants should be signed so that signed arithmetic involving them * won't cause values to be coerced accidentally to unsigned. */ -#define DUK_BC_OP_MIN 0 -#define DUK_BC_OP_MAX 0xffL -#define DUK_BC_A_MIN 0 -#define DUK_BC_A_MAX 0xffL -#define DUK_BC_B_MIN 0 -#define DUK_BC_B_MAX 0xffL -#define DUK_BC_C_MIN 0 -#define DUK_BC_C_MAX 0xffL -#define DUK_BC_BC_MIN 0 -#define DUK_BC_BC_MAX 0xffffL -#define DUK_BC_ABC_MIN 0 -#define DUK_BC_ABC_MAX 0xffffffL +#define DUK_BC_OP_MIN 0 +#define DUK_BC_OP_MAX 0xffL +#define DUK_BC_A_MIN 0 +#define DUK_BC_A_MAX 0xffL +#define DUK_BC_B_MIN 0 +#define DUK_BC_B_MAX 0xffL +#define DUK_BC_C_MIN 0 +#define DUK_BC_C_MAX 0xffL +#define DUK_BC_BC_MIN 0 +#define DUK_BC_BC_MAX 0xffffL +#define DUK_BC_ABC_MIN 0 +#define DUK_BC_ABC_MAX 0xffffffL /* Masks for B/C reg/const indicator in opcode field. */ -#define DUK_BC_REGCONST_B (0x01UL) -#define DUK_BC_REGCONST_C (0x02UL) +#define DUK_BC_REGCONST_B (0x01UL) +#define DUK_BC_REGCONST_C (0x02UL) /* Misc. masks for opcode field. */ -#define DUK_BC_INCDECP_FLAG_DEC (0x04UL) -#define DUK_BC_INCDECP_FLAG_POST (0x08UL) +#define DUK_BC_INCDECP_FLAG_DEC (0x04UL) +#define DUK_BC_INCDECP_FLAG_POST (0x08UL) /* Opcodes. */ -#define DUK_OP_LDREG 0 -#define DUK_OP_STREG 1 -#define DUK_OP_JUMP 2 -#define DUK_OP_LDCONST 3 -#define DUK_OP_LDINT 4 -#define DUK_OP_LDINTX 5 -#define DUK_OP_LDTHIS 6 -#define DUK_OP_LDUNDEF 7 -#define DUK_OP_LDNULL 8 -#define DUK_OP_LDTRUE 9 -#define DUK_OP_LDFALSE 10 -#define DUK_OP_GETVAR 11 -#define DUK_OP_BNOT 12 -#define DUK_OP_LNOT 13 -#define DUK_OP_UNM 14 -#define DUK_OP_UNP 15 -#define DUK_OP_EQ 16 -#define DUK_OP_EQ_RR 16 -#define DUK_OP_EQ_CR 17 -#define DUK_OP_EQ_RC 18 -#define DUK_OP_EQ_CC 19 -#define DUK_OP_NEQ 20 -#define DUK_OP_NEQ_RR 20 -#define DUK_OP_NEQ_CR 21 -#define DUK_OP_NEQ_RC 22 -#define DUK_OP_NEQ_CC 23 -#define DUK_OP_SEQ 24 -#define DUK_OP_SEQ_RR 24 -#define DUK_OP_SEQ_CR 25 -#define DUK_OP_SEQ_RC 26 -#define DUK_OP_SEQ_CC 27 -#define DUK_OP_SNEQ 28 -#define DUK_OP_SNEQ_RR 28 -#define DUK_OP_SNEQ_CR 29 -#define DUK_OP_SNEQ_RC 30 -#define DUK_OP_SNEQ_CC 31 -#define DUK_OP_GT 32 -#define DUK_OP_GT_RR 32 -#define DUK_OP_GT_CR 33 -#define DUK_OP_GT_RC 34 -#define DUK_OP_GT_CC 35 -#define DUK_OP_GE 36 -#define DUK_OP_GE_RR 36 -#define DUK_OP_GE_CR 37 -#define DUK_OP_GE_RC 38 -#define DUK_OP_GE_CC 39 -#define DUK_OP_LT 40 -#define DUK_OP_LT_RR 40 -#define DUK_OP_LT_CR 41 -#define DUK_OP_LT_RC 42 -#define DUK_OP_LT_CC 43 -#define DUK_OP_LE 44 -#define DUK_OP_LE_RR 44 -#define DUK_OP_LE_CR 45 -#define DUK_OP_LE_RC 46 -#define DUK_OP_LE_CC 47 -#define DUK_OP_IFTRUE 48 -#define DUK_OP_IFTRUE_R 48 -#define DUK_OP_IFTRUE_C 49 -#define DUK_OP_IFFALSE 50 -#define DUK_OP_IFFALSE_R 50 -#define DUK_OP_IFFALSE_C 51 -#define DUK_OP_ADD 52 -#define DUK_OP_ADD_RR 52 -#define DUK_OP_ADD_CR 53 -#define DUK_OP_ADD_RC 54 -#define DUK_OP_ADD_CC 55 -#define DUK_OP_SUB 56 -#define DUK_OP_SUB_RR 56 -#define DUK_OP_SUB_CR 57 -#define DUK_OP_SUB_RC 58 -#define DUK_OP_SUB_CC 59 -#define DUK_OP_MUL 60 -#define DUK_OP_MUL_RR 60 -#define DUK_OP_MUL_CR 61 -#define DUK_OP_MUL_RC 62 -#define DUK_OP_MUL_CC 63 -#define DUK_OP_DIV 64 -#define DUK_OP_DIV_RR 64 -#define DUK_OP_DIV_CR 65 -#define DUK_OP_DIV_RC 66 -#define DUK_OP_DIV_CC 67 -#define DUK_OP_MOD 68 -#define DUK_OP_MOD_RR 68 -#define DUK_OP_MOD_CR 69 -#define DUK_OP_MOD_RC 70 -#define DUK_OP_MOD_CC 71 -#define DUK_OP_EXP 72 -#define DUK_OP_EXP_RR 72 -#define DUK_OP_EXP_CR 73 -#define DUK_OP_EXP_RC 74 -#define DUK_OP_EXP_CC 75 -#define DUK_OP_BAND 76 -#define DUK_OP_BAND_RR 76 -#define DUK_OP_BAND_CR 77 -#define DUK_OP_BAND_RC 78 -#define DUK_OP_BAND_CC 79 -#define DUK_OP_BOR 80 -#define DUK_OP_BOR_RR 80 -#define DUK_OP_BOR_CR 81 -#define DUK_OP_BOR_RC 82 -#define DUK_OP_BOR_CC 83 -#define DUK_OP_BXOR 84 -#define DUK_OP_BXOR_RR 84 -#define DUK_OP_BXOR_CR 85 -#define DUK_OP_BXOR_RC 86 -#define DUK_OP_BXOR_CC 87 -#define DUK_OP_BASL 88 -#define DUK_OP_BASL_RR 88 -#define DUK_OP_BASL_CR 89 -#define DUK_OP_BASL_RC 90 -#define DUK_OP_BASL_CC 91 -#define DUK_OP_BLSR 92 -#define DUK_OP_BLSR_RR 92 -#define DUK_OP_BLSR_CR 93 -#define DUK_OP_BLSR_RC 94 -#define DUK_OP_BLSR_CC 95 -#define DUK_OP_BASR 96 -#define DUK_OP_BASR_RR 96 -#define DUK_OP_BASR_CR 97 -#define DUK_OP_BASR_RC 98 -#define DUK_OP_BASR_CC 99 -#define DUK_OP_INSTOF 100 -#define DUK_OP_INSTOF_RR 100 -#define DUK_OP_INSTOF_CR 101 -#define DUK_OP_INSTOF_RC 102 -#define DUK_OP_INSTOF_CC 103 -#define DUK_OP_IN 104 -#define DUK_OP_IN_RR 104 -#define DUK_OP_IN_CR 105 -#define DUK_OP_IN_RC 106 -#define DUK_OP_IN_CC 107 -#define DUK_OP_GETPROP 108 -#define DUK_OP_GETPROP_RR 108 -#define DUK_OP_GETPROP_CR 109 -#define DUK_OP_GETPROP_RC 110 -#define DUK_OP_GETPROP_CC 111 -#define DUK_OP_PUTPROP 112 -#define DUK_OP_PUTPROP_RR 112 -#define DUK_OP_PUTPROP_CR 113 -#define DUK_OP_PUTPROP_RC 114 -#define DUK_OP_PUTPROP_CC 115 -#define DUK_OP_DELPROP 116 -#define DUK_OP_DELPROP_RR 116 -#define DUK_OP_DELPROP_CR_UNUSED 117 /* unused now */ -#define DUK_OP_DELPROP_RC 118 -#define DUK_OP_DELPROP_CC_UNUSED 119 /* unused now */ -#define DUK_OP_PREINCR 120 /* pre/post opcode values have constraints, */ -#define DUK_OP_PREDECR 121 /* see duk_js_executor.c and duk_js_compiler.c. */ -#define DUK_OP_POSTINCR 122 -#define DUK_OP_POSTDECR 123 -#define DUK_OP_PREINCV 124 -#define DUK_OP_PREDECV 125 -#define DUK_OP_POSTINCV 126 -#define DUK_OP_POSTDECV 127 -#define DUK_OP_PREINCP 128 /* pre/post inc/dec prop opcodes have constraints */ -#define DUK_OP_PREINCP_RR 128 -#define DUK_OP_PREINCP_CR 129 -#define DUK_OP_PREINCP_RC 130 -#define DUK_OP_PREINCP_CC 131 -#define DUK_OP_PREDECP 132 -#define DUK_OP_PREDECP_RR 132 -#define DUK_OP_PREDECP_CR 133 -#define DUK_OP_PREDECP_RC 134 -#define DUK_OP_PREDECP_CC 135 -#define DUK_OP_POSTINCP 136 -#define DUK_OP_POSTINCP_RR 136 -#define DUK_OP_POSTINCP_CR 137 -#define DUK_OP_POSTINCP_RC 138 -#define DUK_OP_POSTINCP_CC 139 -#define DUK_OP_POSTDECP 140 -#define DUK_OP_POSTDECP_RR 140 -#define DUK_OP_POSTDECP_CR 141 -#define DUK_OP_POSTDECP_RC 142 -#define DUK_OP_POSTDECP_CC 143 -#define DUK_OP_DECLVAR 144 -#define DUK_OP_DECLVAR_RR 144 -#define DUK_OP_DECLVAR_CR 145 -#define DUK_OP_DECLVAR_RC 146 -#define DUK_OP_DECLVAR_CC 147 -#define DUK_OP_REGEXP 148 -#define DUK_OP_REGEXP_RR 148 -#define DUK_OP_REGEXP_CR 149 -#define DUK_OP_REGEXP_RC 150 -#define DUK_OP_REGEXP_CC 151 -#define DUK_OP_CLOSURE 152 -#define DUK_OP_TYPEOF 153 -#define DUK_OP_TYPEOFID 154 -#define DUK_OP_PUTVAR 155 -#define DUK_OP_DELVAR 156 -#define DUK_OP_RETREG 157 -#define DUK_OP_RETUNDEF 158 -#define DUK_OP_RETCONST 159 -#define DUK_OP_RETCONSTN 160 /* return const without incref (e.g. number) */ -#define DUK_OP_LABEL 161 -#define DUK_OP_ENDLABEL 162 -#define DUK_OP_BREAK 163 -#define DUK_OP_CONTINUE 164 -#define DUK_OP_TRYCATCH 165 -#define DUK_OP_ENDTRY 166 -#define DUK_OP_ENDCATCH 167 -#define DUK_OP_ENDFIN 168 -#define DUK_OP_THROW 169 -#define DUK_OP_INVLHS 170 -#define DUK_OP_CSREG 171 -#define DUK_OP_CSVAR 172 -#define DUK_OP_CSVAR_RR 172 -#define DUK_OP_CSVAR_CR 173 -#define DUK_OP_CSVAR_RC 174 -#define DUK_OP_CSVAR_CC 175 -#define DUK_OP_CALL0 176 /* DUK_OP_CALL0 & 0x0F must be zero. */ -#define DUK_OP_CALL1 177 -#define DUK_OP_CALL2 178 -#define DUK_OP_CALL3 179 -#define DUK_OP_CALL4 180 -#define DUK_OP_CALL5 181 -#define DUK_OP_CALL6 182 -#define DUK_OP_CALL7 183 -#define DUK_OP_CALL8 184 -#define DUK_OP_CALL9 185 -#define DUK_OP_CALL10 186 -#define DUK_OP_CALL11 187 -#define DUK_OP_CALL12 188 -#define DUK_OP_CALL13 189 -#define DUK_OP_CALL14 190 -#define DUK_OP_CALL15 191 -#define DUK_OP_NEWOBJ 192 -#define DUK_OP_NEWARR 193 -#define DUK_OP_MPUTOBJ 194 -#define DUK_OP_MPUTOBJI 195 -#define DUK_OP_INITSET 196 -#define DUK_OP_INITGET 197 -#define DUK_OP_MPUTARR 198 -#define DUK_OP_MPUTARRI 199 -#define DUK_OP_SETALEN 200 -#define DUK_OP_INITENUM 201 -#define DUK_OP_NEXTENUM 202 -#define DUK_OP_NEWTARGET 203 -#define DUK_OP_DEBUGGER 204 -#define DUK_OP_NOP 205 -#define DUK_OP_INVALID 206 -#define DUK_OP_UNUSED207 207 -#define DUK_OP_GETPROPC 208 -#define DUK_OP_GETPROPC_RR 208 -#define DUK_OP_GETPROPC_CR 209 -#define DUK_OP_GETPROPC_RC 210 -#define DUK_OP_GETPROPC_CC 211 -#define DUK_OP_UNUSED212 212 -#define DUK_OP_UNUSED213 213 -#define DUK_OP_UNUSED214 214 -#define DUK_OP_UNUSED215 215 -#define DUK_OP_UNUSED216 216 -#define DUK_OP_UNUSED217 217 -#define DUK_OP_UNUSED218 218 -#define DUK_OP_UNUSED219 219 -#define DUK_OP_UNUSED220 220 -#define DUK_OP_UNUSED221 221 -#define DUK_OP_UNUSED222 222 -#define DUK_OP_UNUSED223 223 -#define DUK_OP_UNUSED224 224 -#define DUK_OP_UNUSED225 225 -#define DUK_OP_UNUSED226 226 -#define DUK_OP_UNUSED227 227 -#define DUK_OP_UNUSED228 228 -#define DUK_OP_UNUSED229 229 -#define DUK_OP_UNUSED230 230 -#define DUK_OP_UNUSED231 231 -#define DUK_OP_UNUSED232 232 -#define DUK_OP_UNUSED233 233 -#define DUK_OP_UNUSED234 234 -#define DUK_OP_UNUSED235 235 -#define DUK_OP_UNUSED236 236 -#define DUK_OP_UNUSED237 237 -#define DUK_OP_UNUSED238 238 -#define DUK_OP_UNUSED239 239 -#define DUK_OP_UNUSED240 240 -#define DUK_OP_UNUSED241 241 -#define DUK_OP_UNUSED242 242 -#define DUK_OP_UNUSED243 243 -#define DUK_OP_UNUSED244 244 -#define DUK_OP_UNUSED245 245 -#define DUK_OP_UNUSED246 246 -#define DUK_OP_UNUSED247 247 -#define DUK_OP_UNUSED248 248 -#define DUK_OP_UNUSED249 249 -#define DUK_OP_UNUSED250 250 -#define DUK_OP_UNUSED251 251 -#define DUK_OP_UNUSED252 252 -#define DUK_OP_UNUSED253 253 -#define DUK_OP_UNUSED254 254 -#define DUK_OP_UNUSED255 255 -#define DUK_OP_NONE 256 /* dummy value used as marker (doesn't fit in 8-bit field) */ +#define DUK_OP_LDREG 0 +#define DUK_OP_STREG 1 +#define DUK_OP_JUMP 2 +#define DUK_OP_LDCONST 3 +#define DUK_OP_LDINT 4 +#define DUK_OP_LDINTX 5 +#define DUK_OP_LDTHIS 6 +#define DUK_OP_LDUNDEF 7 +#define DUK_OP_LDNULL 8 +#define DUK_OP_LDTRUE 9 +#define DUK_OP_LDFALSE 10 +#define DUK_OP_GETVAR 11 +#define DUK_OP_BNOT 12 +#define DUK_OP_LNOT 13 +#define DUK_OP_UNM 14 +#define DUK_OP_UNP 15 +#define DUK_OP_EQ 16 +#define DUK_OP_EQ_RR 16 +#define DUK_OP_EQ_CR 17 +#define DUK_OP_EQ_RC 18 +#define DUK_OP_EQ_CC 19 +#define DUK_OP_NEQ 20 +#define DUK_OP_NEQ_RR 20 +#define DUK_OP_NEQ_CR 21 +#define DUK_OP_NEQ_RC 22 +#define DUK_OP_NEQ_CC 23 +#define DUK_OP_SEQ 24 +#define DUK_OP_SEQ_RR 24 +#define DUK_OP_SEQ_CR 25 +#define DUK_OP_SEQ_RC 26 +#define DUK_OP_SEQ_CC 27 +#define DUK_OP_SNEQ 28 +#define DUK_OP_SNEQ_RR 28 +#define DUK_OP_SNEQ_CR 29 +#define DUK_OP_SNEQ_RC 30 +#define DUK_OP_SNEQ_CC 31 +#define DUK_OP_GT 32 +#define DUK_OP_GT_RR 32 +#define DUK_OP_GT_CR 33 +#define DUK_OP_GT_RC 34 +#define DUK_OP_GT_CC 35 +#define DUK_OP_GE 36 +#define DUK_OP_GE_RR 36 +#define DUK_OP_GE_CR 37 +#define DUK_OP_GE_RC 38 +#define DUK_OP_GE_CC 39 +#define DUK_OP_LT 40 +#define DUK_OP_LT_RR 40 +#define DUK_OP_LT_CR 41 +#define DUK_OP_LT_RC 42 +#define DUK_OP_LT_CC 43 +#define DUK_OP_LE 44 +#define DUK_OP_LE_RR 44 +#define DUK_OP_LE_CR 45 +#define DUK_OP_LE_RC 46 +#define DUK_OP_LE_CC 47 +#define DUK_OP_IFTRUE 48 +#define DUK_OP_IFTRUE_R 48 +#define DUK_OP_IFTRUE_C 49 +#define DUK_OP_IFFALSE 50 +#define DUK_OP_IFFALSE_R 50 +#define DUK_OP_IFFALSE_C 51 +#define DUK_OP_ADD 52 +#define DUK_OP_ADD_RR 52 +#define DUK_OP_ADD_CR 53 +#define DUK_OP_ADD_RC 54 +#define DUK_OP_ADD_CC 55 +#define DUK_OP_SUB 56 +#define DUK_OP_SUB_RR 56 +#define DUK_OP_SUB_CR 57 +#define DUK_OP_SUB_RC 58 +#define DUK_OP_SUB_CC 59 +#define DUK_OP_MUL 60 +#define DUK_OP_MUL_RR 60 +#define DUK_OP_MUL_CR 61 +#define DUK_OP_MUL_RC 62 +#define DUK_OP_MUL_CC 63 +#define DUK_OP_DIV 64 +#define DUK_OP_DIV_RR 64 +#define DUK_OP_DIV_CR 65 +#define DUK_OP_DIV_RC 66 +#define DUK_OP_DIV_CC 67 +#define DUK_OP_MOD 68 +#define DUK_OP_MOD_RR 68 +#define DUK_OP_MOD_CR 69 +#define DUK_OP_MOD_RC 70 +#define DUK_OP_MOD_CC 71 +#define DUK_OP_EXP 72 +#define DUK_OP_EXP_RR 72 +#define DUK_OP_EXP_CR 73 +#define DUK_OP_EXP_RC 74 +#define DUK_OP_EXP_CC 75 +#define DUK_OP_BAND 76 +#define DUK_OP_BAND_RR 76 +#define DUK_OP_BAND_CR 77 +#define DUK_OP_BAND_RC 78 +#define DUK_OP_BAND_CC 79 +#define DUK_OP_BOR 80 +#define DUK_OP_BOR_RR 80 +#define DUK_OP_BOR_CR 81 +#define DUK_OP_BOR_RC 82 +#define DUK_OP_BOR_CC 83 +#define DUK_OP_BXOR 84 +#define DUK_OP_BXOR_RR 84 +#define DUK_OP_BXOR_CR 85 +#define DUK_OP_BXOR_RC 86 +#define DUK_OP_BXOR_CC 87 +#define DUK_OP_BASL 88 +#define DUK_OP_BASL_RR 88 +#define DUK_OP_BASL_CR 89 +#define DUK_OP_BASL_RC 90 +#define DUK_OP_BASL_CC 91 +#define DUK_OP_BLSR 92 +#define DUK_OP_BLSR_RR 92 +#define DUK_OP_BLSR_CR 93 +#define DUK_OP_BLSR_RC 94 +#define DUK_OP_BLSR_CC 95 +#define DUK_OP_BASR 96 +#define DUK_OP_BASR_RR 96 +#define DUK_OP_BASR_CR 97 +#define DUK_OP_BASR_RC 98 +#define DUK_OP_BASR_CC 99 +#define DUK_OP_INSTOF 100 +#define DUK_OP_INSTOF_RR 100 +#define DUK_OP_INSTOF_CR 101 +#define DUK_OP_INSTOF_RC 102 +#define DUK_OP_INSTOF_CC 103 +#define DUK_OP_IN 104 +#define DUK_OP_IN_RR 104 +#define DUK_OP_IN_CR 105 +#define DUK_OP_IN_RC 106 +#define DUK_OP_IN_CC 107 +#define DUK_OP_GETPROP 108 +#define DUK_OP_GETPROP_RR 108 +#define DUK_OP_GETPROP_CR 109 +#define DUK_OP_GETPROP_RC 110 +#define DUK_OP_GETPROP_CC 111 +#define DUK_OP_PUTPROP 112 +#define DUK_OP_PUTPROP_RR 112 +#define DUK_OP_PUTPROP_CR 113 +#define DUK_OP_PUTPROP_RC 114 +#define DUK_OP_PUTPROP_CC 115 +#define DUK_OP_DELPROP 116 +#define DUK_OP_DELPROP_RR 116 +#define DUK_OP_DELPROP_CR_UNUSED 117 /* unused now */ +#define DUK_OP_DELPROP_RC 118 +#define DUK_OP_DELPROP_CC_UNUSED 119 /* unused now */ +#define DUK_OP_PREINCR 120 /* pre/post opcode values have constraints, */ +#define DUK_OP_PREDECR 121 /* see duk_js_executor.c and duk_js_compiler.c. */ +#define DUK_OP_POSTINCR 122 +#define DUK_OP_POSTDECR 123 +#define DUK_OP_PREINCV 124 +#define DUK_OP_PREDECV 125 +#define DUK_OP_POSTINCV 126 +#define DUK_OP_POSTDECV 127 +#define DUK_OP_PREINCP 128 /* pre/post inc/dec prop opcodes have constraints */ +#define DUK_OP_PREINCP_RR 128 +#define DUK_OP_PREINCP_CR 129 +#define DUK_OP_PREINCP_RC 130 +#define DUK_OP_PREINCP_CC 131 +#define DUK_OP_PREDECP 132 +#define DUK_OP_PREDECP_RR 132 +#define DUK_OP_PREDECP_CR 133 +#define DUK_OP_PREDECP_RC 134 +#define DUK_OP_PREDECP_CC 135 +#define DUK_OP_POSTINCP 136 +#define DUK_OP_POSTINCP_RR 136 +#define DUK_OP_POSTINCP_CR 137 +#define DUK_OP_POSTINCP_RC 138 +#define DUK_OP_POSTINCP_CC 139 +#define DUK_OP_POSTDECP 140 +#define DUK_OP_POSTDECP_RR 140 +#define DUK_OP_POSTDECP_CR 141 +#define DUK_OP_POSTDECP_RC 142 +#define DUK_OP_POSTDECP_CC 143 +#define DUK_OP_DECLVAR 144 +#define DUK_OP_DECLVAR_RR 144 +#define DUK_OP_DECLVAR_CR 145 +#define DUK_OP_DECLVAR_RC 146 +#define DUK_OP_DECLVAR_CC 147 +#define DUK_OP_REGEXP 148 +#define DUK_OP_REGEXP_RR 148 +#define DUK_OP_REGEXP_CR 149 +#define DUK_OP_REGEXP_RC 150 +#define DUK_OP_REGEXP_CC 151 +#define DUK_OP_CLOSURE 152 +#define DUK_OP_TYPEOF 153 +#define DUK_OP_TYPEOFID 154 +#define DUK_OP_PUTVAR 155 +#define DUK_OP_DELVAR 156 +#define DUK_OP_RETREG 157 +#define DUK_OP_RETUNDEF 158 +#define DUK_OP_RETCONST 159 +#define DUK_OP_RETCONSTN 160 /* return const without incref (e.g. number) */ +#define DUK_OP_LABEL 161 +#define DUK_OP_ENDLABEL 162 +#define DUK_OP_BREAK 163 +#define DUK_OP_CONTINUE 164 +#define DUK_OP_TRYCATCH 165 +#define DUK_OP_ENDTRY 166 +#define DUK_OP_ENDCATCH 167 +#define DUK_OP_ENDFIN 168 +#define DUK_OP_THROW 169 +#define DUK_OP_INVLHS 170 +#define DUK_OP_CSREG 171 +#define DUK_OP_CSVAR 172 +#define DUK_OP_CSVAR_RR 172 +#define DUK_OP_CSVAR_CR 173 +#define DUK_OP_CSVAR_RC 174 +#define DUK_OP_CSVAR_CC 175 +#define DUK_OP_CALL0 176 /* DUK_OP_CALL0 & 0x0F must be zero. */ +#define DUK_OP_CALL1 177 +#define DUK_OP_CALL2 178 +#define DUK_OP_CALL3 179 +#define DUK_OP_CALL4 180 +#define DUK_OP_CALL5 181 +#define DUK_OP_CALL6 182 +#define DUK_OP_CALL7 183 +#define DUK_OP_CALL8 184 +#define DUK_OP_CALL9 185 +#define DUK_OP_CALL10 186 +#define DUK_OP_CALL11 187 +#define DUK_OP_CALL12 188 +#define DUK_OP_CALL13 189 +#define DUK_OP_CALL14 190 +#define DUK_OP_CALL15 191 +#define DUK_OP_NEWOBJ 192 +#define DUK_OP_NEWARR 193 +#define DUK_OP_MPUTOBJ 194 +#define DUK_OP_MPUTOBJI 195 +#define DUK_OP_INITSET 196 +#define DUK_OP_INITGET 197 +#define DUK_OP_MPUTARR 198 +#define DUK_OP_MPUTARRI 199 +#define DUK_OP_SETALEN 200 +#define DUK_OP_INITENUM 201 +#define DUK_OP_NEXTENUM 202 +#define DUK_OP_NEWTARGET 203 +#define DUK_OP_DEBUGGER 204 +#define DUK_OP_NOP 205 +#define DUK_OP_INVALID 206 +#define DUK_OP_UNUSED207 207 +#define DUK_OP_GETPROPC 208 +#define DUK_OP_GETPROPC_RR 208 +#define DUK_OP_GETPROPC_CR 209 +#define DUK_OP_GETPROPC_RC 210 +#define DUK_OP_GETPROPC_CC 211 +#define DUK_OP_UNUSED212 212 +#define DUK_OP_UNUSED213 213 +#define DUK_OP_UNUSED214 214 +#define DUK_OP_UNUSED215 215 +#define DUK_OP_UNUSED216 216 +#define DUK_OP_UNUSED217 217 +#define DUK_OP_UNUSED218 218 +#define DUK_OP_UNUSED219 219 +#define DUK_OP_UNUSED220 220 +#define DUK_OP_UNUSED221 221 +#define DUK_OP_UNUSED222 222 +#define DUK_OP_UNUSED223 223 +#define DUK_OP_UNUSED224 224 +#define DUK_OP_UNUSED225 225 +#define DUK_OP_UNUSED226 226 +#define DUK_OP_UNUSED227 227 +#define DUK_OP_UNUSED228 228 +#define DUK_OP_UNUSED229 229 +#define DUK_OP_UNUSED230 230 +#define DUK_OP_UNUSED231 231 +#define DUK_OP_UNUSED232 232 +#define DUK_OP_UNUSED233 233 +#define DUK_OP_UNUSED234 234 +#define DUK_OP_UNUSED235 235 +#define DUK_OP_UNUSED236 236 +#define DUK_OP_UNUSED237 237 +#define DUK_OP_UNUSED238 238 +#define DUK_OP_UNUSED239 239 +#define DUK_OP_UNUSED240 240 +#define DUK_OP_UNUSED241 241 +#define DUK_OP_UNUSED242 242 +#define DUK_OP_UNUSED243 243 +#define DUK_OP_UNUSED244 244 +#define DUK_OP_UNUSED245 245 +#define DUK_OP_UNUSED246 246 +#define DUK_OP_UNUSED247 247 +#define DUK_OP_UNUSED248 248 +#define DUK_OP_UNUSED249 249 +#define DUK_OP_UNUSED250 250 +#define DUK_OP_UNUSED251 251 +#define DUK_OP_UNUSED252 252 +#define DUK_OP_UNUSED253 253 +#define DUK_OP_UNUSED254 254 +#define DUK_OP_UNUSED255 255 +#define DUK_OP_NONE 256 /* dummy value used as marker (doesn't fit in 8-bit field) */ /* XXX: Allocate flags from opcode field? Would take 16 opcode slots * but avoids shuffling in more cases. Maybe not worth it. */ /* DUK_OP_TRYCATCH flags in A. */ -#define DUK_BC_TRYCATCH_FLAG_HAVE_CATCH (1U << 0) -#define DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY (1U << 1) -#define DUK_BC_TRYCATCH_FLAG_CATCH_BINDING (1U << 2) -#define DUK_BC_TRYCATCH_FLAG_WITH_BINDING (1U << 3) +#define DUK_BC_TRYCATCH_FLAG_HAVE_CATCH (1U << 0) +#define DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY (1U << 1) +#define DUK_BC_TRYCATCH_FLAG_CATCH_BINDING (1U << 2) +#define DUK_BC_TRYCATCH_FLAG_WITH_BINDING (1U << 3) /* DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags * (DUK_PROPDESC_FLAG_XXX). */ -#define DUK_BC_DECLVAR_FLAG_FUNC_DECL (1U << 4) /* function declaration */ +#define DUK_BC_DECLVAR_FLAG_FUNC_DECL (1U << 4) /* function declaration */ /* DUK_OP_CALLn flags, part of opcode field. Three lowest bits must match * DUK_CALL_FLAG_xxx directly. */ -#define DUK_BC_CALL_FLAG_TAILCALL (1U << 0) -#define DUK_BC_CALL_FLAG_CONSTRUCT (1U << 1) -#define DUK_BC_CALL_FLAG_CALLED_AS_EVAL (1U << 2) -#define DUK_BC_CALL_FLAG_INDIRECT (1U << 3) +#define DUK_BC_CALL_FLAG_TAILCALL (1U << 0) +#define DUK_BC_CALL_FLAG_CONSTRUCT (1U << 1) +#define DUK_BC_CALL_FLAG_CALLED_AS_EVAL (1U << 2) +#define DUK_BC_CALL_FLAG_INDIRECT (1U << 3) /* Misc constants and helper macros. */ -#define DUK_BC_LDINT_BIAS (1L << 15) -#define DUK_BC_LDINTX_SHIFT 16 -#define DUK_BC_JUMP_BIAS (1L << 23) +#define DUK_BC_LDINT_BIAS (1L << 15) +#define DUK_BC_LDINTX_SHIFT 16 +#define DUK_BC_JUMP_BIAS (1L << 23) -#endif /* DUK_JS_BYTECODE_H_INCLUDED */ +#endif /* DUK_JS_BYTECODE_H_INCLUDED */ /* #include duk_lexer.h */ #line 1 "duk_lexer.h" /* @@ -3745,156 +3840,156 @@ * in a continuous range and in a particular order. See genstrings.py. */ -#define DUK_LEXER_INITCTX(ctx) duk_lexer_initctx((ctx)) +#define DUK_LEXER_INITCTX(ctx) duk_lexer_initctx((ctx)) -#define DUK_LEXER_SETPOINT(ctx,pt) duk_lexer_setpoint((ctx), (pt)) +#define DUK_LEXER_SETPOINT(ctx, pt) duk_lexer_setpoint((ctx), (pt)) -#define DUK_LEXER_GETPOINT(ctx,pt) duk_lexer_getpoint((ctx), (pt)) +#define DUK_LEXER_GETPOINT(ctx, pt) duk_lexer_getpoint((ctx), (pt)) /* Currently 6 characters of lookup are actually needed (duk_lexer.c). */ -#define DUK_LEXER_WINDOW_SIZE 6 +#define DUK_LEXER_WINDOW_SIZE 6 #if defined(DUK_USE_LEXER_SLIDING_WINDOW) -#define DUK_LEXER_BUFFER_SIZE 64 +#define DUK_LEXER_BUFFER_SIZE 64 #endif -#define DUK_TOK_MINVAL 0 +#define DUK_TOK_MINVAL 0 /* returned after EOF (infinite amount) */ -#define DUK_TOK_EOF 0 +#define DUK_TOK_EOF 0 /* identifier names (E5 Section 7.6) */ -#define DUK_TOK_IDENTIFIER 1 +#define DUK_TOK_IDENTIFIER 1 /* reserved words: keywords */ -#define DUK_TOK_START_RESERVED 2 -#define DUK_TOK_BREAK 2 -#define DUK_TOK_CASE 3 -#define DUK_TOK_CATCH 4 -#define DUK_TOK_CONTINUE 5 -#define DUK_TOK_DEBUGGER 6 -#define DUK_TOK_DEFAULT 7 -#define DUK_TOK_DELETE 8 -#define DUK_TOK_DO 9 -#define DUK_TOK_ELSE 10 -#define DUK_TOK_FINALLY 11 -#define DUK_TOK_FOR 12 -#define DUK_TOK_FUNCTION 13 -#define DUK_TOK_IF 14 -#define DUK_TOK_IN 15 -#define DUK_TOK_INSTANCEOF 16 -#define DUK_TOK_NEW 17 -#define DUK_TOK_RETURN 18 -#define DUK_TOK_SWITCH 19 -#define DUK_TOK_THIS 20 -#define DUK_TOK_THROW 21 -#define DUK_TOK_TRY 22 -#define DUK_TOK_TYPEOF 23 -#define DUK_TOK_VAR 24 -#define DUK_TOK_CONST 25 -#define DUK_TOK_VOID 26 -#define DUK_TOK_WHILE 27 -#define DUK_TOK_WITH 28 +#define DUK_TOK_START_RESERVED 2 +#define DUK_TOK_BREAK 2 +#define DUK_TOK_CASE 3 +#define DUK_TOK_CATCH 4 +#define DUK_TOK_CONTINUE 5 +#define DUK_TOK_DEBUGGER 6 +#define DUK_TOK_DEFAULT 7 +#define DUK_TOK_DELETE 8 +#define DUK_TOK_DO 9 +#define DUK_TOK_ELSE 10 +#define DUK_TOK_FINALLY 11 +#define DUK_TOK_FOR 12 +#define DUK_TOK_FUNCTION 13 +#define DUK_TOK_IF 14 +#define DUK_TOK_IN 15 +#define DUK_TOK_INSTANCEOF 16 +#define DUK_TOK_NEW 17 +#define DUK_TOK_RETURN 18 +#define DUK_TOK_SWITCH 19 +#define DUK_TOK_THIS 20 +#define DUK_TOK_THROW 21 +#define DUK_TOK_TRY 22 +#define DUK_TOK_TYPEOF 23 +#define DUK_TOK_VAR 24 +#define DUK_TOK_CONST 25 +#define DUK_TOK_VOID 26 +#define DUK_TOK_WHILE 27 +#define DUK_TOK_WITH 28 /* reserved words: future reserved words */ -#define DUK_TOK_CLASS 29 -#define DUK_TOK_ENUM 30 -#define DUK_TOK_EXPORT 31 -#define DUK_TOK_EXTENDS 32 -#define DUK_TOK_IMPORT 33 -#define DUK_TOK_SUPER 34 +#define DUK_TOK_CLASS 29 +#define DUK_TOK_ENUM 30 +#define DUK_TOK_EXPORT 31 +#define DUK_TOK_EXTENDS 32 +#define DUK_TOK_IMPORT 33 +#define DUK_TOK_SUPER 34 /* "null", "true", and "false" are always reserved words. * Note that "get" and "set" are not! */ -#define DUK_TOK_NULL 35 -#define DUK_TOK_TRUE 36 -#define DUK_TOK_FALSE 37 +#define DUK_TOK_NULL 35 +#define DUK_TOK_TRUE 36 +#define DUK_TOK_FALSE 37 /* reserved words: additional future reserved words in strict mode */ -#define DUK_TOK_START_STRICT_RESERVED 38 /* inclusive */ -#define DUK_TOK_IMPLEMENTS 38 -#define DUK_TOK_INTERFACE 39 -#define DUK_TOK_LET 40 -#define DUK_TOK_PACKAGE 41 -#define DUK_TOK_PRIVATE 42 -#define DUK_TOK_PROTECTED 43 -#define DUK_TOK_PUBLIC 44 -#define DUK_TOK_STATIC 45 -#define DUK_TOK_YIELD 46 +#define DUK_TOK_START_STRICT_RESERVED 38 /* inclusive */ +#define DUK_TOK_IMPLEMENTS 38 +#define DUK_TOK_INTERFACE 39 +#define DUK_TOK_LET 40 +#define DUK_TOK_PACKAGE 41 +#define DUK_TOK_PRIVATE 42 +#define DUK_TOK_PROTECTED 43 +#define DUK_TOK_PUBLIC 44 +#define DUK_TOK_STATIC 45 +#define DUK_TOK_YIELD 46 -#define DUK_TOK_END_RESERVED 47 /* exclusive */ +#define DUK_TOK_END_RESERVED 47 /* exclusive */ /* "get" and "set" are tokens but NOT ReservedWords. They are currently * parsed and identifiers and these defines are actually now unused. */ -#define DUK_TOK_GET 47 -#define DUK_TOK_SET 48 +#define DUK_TOK_GET 47 +#define DUK_TOK_SET 48 /* punctuators (unlike the spec, also includes "/" and "/=") */ -#define DUK_TOK_LCURLY 49 -#define DUK_TOK_RCURLY 50 -#define DUK_TOK_LBRACKET 51 -#define DUK_TOK_RBRACKET 52 -#define DUK_TOK_LPAREN 53 -#define DUK_TOK_RPAREN 54 -#define DUK_TOK_PERIOD 55 -#define DUK_TOK_SEMICOLON 56 -#define DUK_TOK_COMMA 57 -#define DUK_TOK_LT 58 -#define DUK_TOK_GT 59 -#define DUK_TOK_LE 60 -#define DUK_TOK_GE 61 -#define DUK_TOK_EQ 62 -#define DUK_TOK_NEQ 63 -#define DUK_TOK_SEQ 64 -#define DUK_TOK_SNEQ 65 -#define DUK_TOK_ADD 66 -#define DUK_TOK_SUB 67 -#define DUK_TOK_MUL 68 -#define DUK_TOK_DIV 69 -#define DUK_TOK_MOD 70 -#define DUK_TOK_EXP 71 -#define DUK_TOK_INCREMENT 72 -#define DUK_TOK_DECREMENT 73 -#define DUK_TOK_ALSHIFT 74 /* named "arithmetic" because result is signed */ -#define DUK_TOK_ARSHIFT 75 -#define DUK_TOK_RSHIFT 76 -#define DUK_TOK_BAND 77 -#define DUK_TOK_BOR 78 -#define DUK_TOK_BXOR 79 -#define DUK_TOK_LNOT 80 -#define DUK_TOK_BNOT 81 -#define DUK_TOK_LAND 82 -#define DUK_TOK_LOR 83 -#define DUK_TOK_QUESTION 84 -#define DUK_TOK_COLON 85 -#define DUK_TOK_EQUALSIGN 86 -#define DUK_TOK_ADD_EQ 87 -#define DUK_TOK_SUB_EQ 88 -#define DUK_TOK_MUL_EQ 89 -#define DUK_TOK_DIV_EQ 90 -#define DUK_TOK_MOD_EQ 91 -#define DUK_TOK_EXP_EQ 92 -#define DUK_TOK_ALSHIFT_EQ 93 -#define DUK_TOK_ARSHIFT_EQ 94 -#define DUK_TOK_RSHIFT_EQ 95 -#define DUK_TOK_BAND_EQ 96 -#define DUK_TOK_BOR_EQ 97 -#define DUK_TOK_BXOR_EQ 98 +#define DUK_TOK_LCURLY 49 +#define DUK_TOK_RCURLY 50 +#define DUK_TOK_LBRACKET 51 +#define DUK_TOK_RBRACKET 52 +#define DUK_TOK_LPAREN 53 +#define DUK_TOK_RPAREN 54 +#define DUK_TOK_PERIOD 55 +#define DUK_TOK_SEMICOLON 56 +#define DUK_TOK_COMMA 57 +#define DUK_TOK_LT 58 +#define DUK_TOK_GT 59 +#define DUK_TOK_LE 60 +#define DUK_TOK_GE 61 +#define DUK_TOK_EQ 62 +#define DUK_TOK_NEQ 63 +#define DUK_TOK_SEQ 64 +#define DUK_TOK_SNEQ 65 +#define DUK_TOK_ADD 66 +#define DUK_TOK_SUB 67 +#define DUK_TOK_MUL 68 +#define DUK_TOK_DIV 69 +#define DUK_TOK_MOD 70 +#define DUK_TOK_EXP 71 +#define DUK_TOK_INCREMENT 72 +#define DUK_TOK_DECREMENT 73 +#define DUK_TOK_ALSHIFT 74 /* named "arithmetic" because result is signed */ +#define DUK_TOK_ARSHIFT 75 +#define DUK_TOK_RSHIFT 76 +#define DUK_TOK_BAND 77 +#define DUK_TOK_BOR 78 +#define DUK_TOK_BXOR 79 +#define DUK_TOK_LNOT 80 +#define DUK_TOK_BNOT 81 +#define DUK_TOK_LAND 82 +#define DUK_TOK_LOR 83 +#define DUK_TOK_QUESTION 84 +#define DUK_TOK_COLON 85 +#define DUK_TOK_EQUALSIGN 86 +#define DUK_TOK_ADD_EQ 87 +#define DUK_TOK_SUB_EQ 88 +#define DUK_TOK_MUL_EQ 89 +#define DUK_TOK_DIV_EQ 90 +#define DUK_TOK_MOD_EQ 91 +#define DUK_TOK_EXP_EQ 92 +#define DUK_TOK_ALSHIFT_EQ 93 +#define DUK_TOK_ARSHIFT_EQ 94 +#define DUK_TOK_RSHIFT_EQ 95 +#define DUK_TOK_BAND_EQ 96 +#define DUK_TOK_BOR_EQ 97 +#define DUK_TOK_BXOR_EQ 98 /* literals (E5 Section 7.8), except null, true, false, which are treated * like reserved words (above). */ -#define DUK_TOK_NUMBER 99 -#define DUK_TOK_STRING 100 -#define DUK_TOK_REGEXP 101 +#define DUK_TOK_NUMBER 99 +#define DUK_TOK_STRING 100 +#define DUK_TOK_REGEXP 101 -#define DUK_TOK_MAXVAL 101 /* inclusive */ +#define DUK_TOK_MAXVAL 101 /* inclusive */ -#define DUK_TOK_INVALID DUK_SMALL_UINT_MAX +#define DUK_TOK_INVALID DUK_SMALL_UINT_MAX /* Convert heap string index to a token (reserved words) */ -#define DUK_STRIDX_TO_TOK(x) ((x) - DUK_STRIDX_START_RESERVED + DUK_TOK_START_RESERVED) +#define DUK_STRIDX_TO_TOK(x) ((x) -DUK_STRIDX_START_RESERVED + DUK_TOK_START_RESERVED) /* Sanity check */ #if (DUK_TOK_MAXVAL > 255) @@ -4039,57 +4134,57 @@ #endif /* Regexp tokens */ -#define DUK_RETOK_EOF 0 -#define DUK_RETOK_DISJUNCTION 1 -#define DUK_RETOK_QUANTIFIER 2 -#define DUK_RETOK_ASSERT_START 3 -#define DUK_RETOK_ASSERT_END 4 -#define DUK_RETOK_ASSERT_WORD_BOUNDARY 5 -#define DUK_RETOK_ASSERT_NOT_WORD_BOUNDARY 6 -#define DUK_RETOK_ASSERT_START_POS_LOOKAHEAD 7 -#define DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD 8 -#define DUK_RETOK_ATOM_PERIOD 9 -#define DUK_RETOK_ATOM_CHAR 10 -#define DUK_RETOK_ATOM_DIGIT 11 /* assumptions in regexp compiler */ -#define DUK_RETOK_ATOM_NOT_DIGIT 12 /* -""- */ -#define DUK_RETOK_ATOM_WHITE 13 /* -""- */ -#define DUK_RETOK_ATOM_NOT_WHITE 14 /* -""- */ -#define DUK_RETOK_ATOM_WORD_CHAR 15 /* -""- */ -#define DUK_RETOK_ATOM_NOT_WORD_CHAR 16 /* -""- */ -#define DUK_RETOK_ATOM_BACKREFERENCE 17 -#define DUK_RETOK_ATOM_START_CAPTURE_GROUP 18 -#define DUK_RETOK_ATOM_START_NONCAPTURE_GROUP 19 -#define DUK_RETOK_ATOM_START_CHARCLASS 20 -#define DUK_RETOK_ATOM_START_CHARCLASS_INVERTED 21 -#define DUK_RETOK_ATOM_END_GROUP 22 +#define DUK_RETOK_EOF 0 +#define DUK_RETOK_DISJUNCTION 1 +#define DUK_RETOK_QUANTIFIER 2 +#define DUK_RETOK_ASSERT_START 3 +#define DUK_RETOK_ASSERT_END 4 +#define DUK_RETOK_ASSERT_WORD_BOUNDARY 5 +#define DUK_RETOK_ASSERT_NOT_WORD_BOUNDARY 6 +#define DUK_RETOK_ASSERT_START_POS_LOOKAHEAD 7 +#define DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD 8 +#define DUK_RETOK_ATOM_PERIOD 9 +#define DUK_RETOK_ATOM_CHAR 10 +#define DUK_RETOK_ATOM_DIGIT 11 /* assumptions in regexp compiler */ +#define DUK_RETOK_ATOM_NOT_DIGIT 12 /* -""- */ +#define DUK_RETOK_ATOM_WHITE 13 /* -""- */ +#define DUK_RETOK_ATOM_NOT_WHITE 14 /* -""- */ +#define DUK_RETOK_ATOM_WORD_CHAR 15 /* -""- */ +#define DUK_RETOK_ATOM_NOT_WORD_CHAR 16 /* -""- */ +#define DUK_RETOK_ATOM_BACKREFERENCE 17 +#define DUK_RETOK_ATOM_START_CAPTURE_GROUP 18 +#define DUK_RETOK_ATOM_START_NONCAPTURE_GROUP 19 +#define DUK_RETOK_ATOM_START_CHARCLASS 20 +#define DUK_RETOK_ATOM_START_CHARCLASS_INVERTED 21 +#define DUK_RETOK_ATOM_END_GROUP 22 /* Constants for duk_lexer_ctx.buf. */ -#define DUK_LEXER_TEMP_BUF_LIMIT 256 +#define DUK_LEXER_TEMP_BUF_LIMIT 256 /* A token value. Can be memcpy()'d, but note that slot1/slot2 values are on the valstack. * Some fields (like num, str1, str2) are only valid for specific token types and may have * stale values otherwise. */ struct duk_token { - duk_small_uint_t t; /* token type (with reserved word identification) */ - duk_small_uint_t t_nores; /* token type (with reserved words as DUK_TOK_IDENTIFER) */ - duk_double_t num; /* numeric value of token */ - duk_hstring *str1; /* string 1 of token (borrowed, stored to ctx->slot1_idx) */ - duk_hstring *str2; /* string 2 of token (borrowed, stored to ctx->slot2_idx) */ - duk_size_t start_offset; /* start byte offset of token in lexer input */ - duk_int_t start_line; /* start line of token (first char) */ - duk_int_t num_escapes; /* number of escapes and line continuations (for directive prologue) */ - duk_bool_t lineterm; /* token was preceded by a lineterm */ - duk_bool_t allow_auto_semi; /* token allows automatic semicolon insertion (eof or preceded by newline) */ + duk_small_uint_t t; /* token type (with reserved word identification) */ + duk_small_uint_t t_nores; /* token type (with reserved words as DUK_TOK_IDENTIFER) */ + duk_double_t num; /* numeric value of token */ + duk_hstring *str1; /* string 1 of token (borrowed, stored to ctx->slot1_idx) */ + duk_hstring *str2; /* string 2 of token (borrowed, stored to ctx->slot2_idx) */ + duk_size_t start_offset; /* start byte offset of token in lexer input */ + duk_int_t start_line; /* start line of token (first char) */ + duk_int_t num_escapes; /* number of escapes and line continuations (for directive prologue) */ + duk_bool_t lineterm; /* token was preceded by a lineterm */ + duk_bool_t allow_auto_semi; /* token allows automatic semicolon insertion (eof or preceded by newline) */ }; -#define DUK_RE_QUANTIFIER_INFINITE ((duk_uint32_t) 0xffffffffUL) +#define DUK_RE_QUANTIFIER_INFINITE ((duk_uint32_t) 0xffffffffUL) /* A regexp token value. */ struct duk_re_token { - duk_small_uint_t t; /* token type */ + duk_small_uint_t t; /* token type */ duk_small_uint_t greedy; - duk_uint32_t num; /* numeric value (character, count) */ + duk_uint32_t num; /* numeric value (character, count) */ duk_uint32_t qmin; duk_uint32_t qmax; }; @@ -4116,23 +4211,23 @@ duk_lexer_codepoint windowDUK_LEXER_WINDOW_SIZE; /* unicode code points, window0 is always next */ #endif - duk_hthread *thr; /* thread; minimizes argument passing */ + duk_hthread *thr; /* thread; minimizes argument passing */ - const duk_uint8_t *input; /* input string (may be a user pointer) */ - duk_size_t input_length; /* input byte length */ - duk_size_t input_offset; /* input offset for window leading edge (not window0) */ - duk_int_t input_line; /* input linenumber at input_offset (not window0), init to 1 */ - - duk_idx_t slot1_idx; /* valstack slot for 1st token value */ - duk_idx_t slot2_idx; /* valstack slot for 2nd token value */ - duk_idx_t buf_idx; /* valstack slot for temp buffer */ - duk_hbuffer_dynamic *buf; /* temp accumulation buffer */ - duk_bufwriter_ctx bw; /* bufwriter for temp accumulation */ + const duk_uint8_t *input; /* input string (may be a user pointer) */ + duk_size_t input_length; /* input byte length */ + duk_size_t input_offset; /* input offset for window leading edge (not window0) */ + duk_int_t input_line; /* input linenumber at input_offset (not window0), init to 1 */ + + duk_idx_t slot1_idx; /* valstack slot for 1st token value */ + duk_idx_t slot2_idx; /* valstack slot for 2nd token value */ + duk_idx_t buf_idx; /* valstack slot for temp buffer */ + duk_hbuffer_dynamic *buf; /* temp accumulation buffer */ + duk_bufwriter_ctx bw; /* bufwriter for temp accumulation */ - duk_int_t token_count; /* number of tokens parsed */ - duk_int_t token_limit; /* maximum token count before error (sanity backstop) */ + duk_int_t token_count; /* number of tokens parsed */ + duk_int_t token_limit; /* maximum token count before error (sanity backstop) */ - duk_small_uint_t flags; /* lexer flags, use compiler flag defines for now */ + duk_small_uint_t flags; /* lexer flags, use compiler flag defines for now */ }; /* @@ -4145,16 +4240,13 @@ DUK_INTERNAL_DECL void duk_lexer_setpoint(duk_lexer_ctx *lex_ctx, duk_lexer_point *pt); DUK_INTERNAL_DECL -void duk_lexer_parse_js_input_element(duk_lexer_ctx *lex_ctx, - duk_token *out_token, - duk_bool_t strict_mode, - duk_bool_t regexp_mode); +void duk_lexer_parse_js_input_element(duk_lexer_ctx *lex_ctx, duk_token *out_token, duk_bool_t strict_mode, duk_bool_t regexp_mode); #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL_DECL void duk_lexer_parse_re_token(duk_lexer_ctx *lex_ctx, duk_re_token *out_token); DUK_INTERNAL_DECL void duk_lexer_parse_re_ranges(duk_lexer_ctx *lex_ctx, duk_re_range_callback gen_range, void *userdata); -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ -#endif /* DUK_LEXER_H_INCLUDED */ +#endif /* DUK_LEXER_H_INCLUDED */ /* #include duk_js_compiler.h */ #line 1 "duk_js_compiler.h" /* @@ -4165,13 +4257,13 @@ #define DUK_JS_COMPILER_H_INCLUDED /* ECMAScript compiler limits */ -#define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */ +#define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */ /* maximum loopcount for peephole optimization */ -#define DUK_COMPILER_PEEPHOLE_MAXITER 3 +#define DUK_COMPILER_PEEPHOLE_MAXITER 3 /* maximum bytecode length in instructions */ -#define DUK_COMPILER_MAX_BYTECODE_LENGTH (256L * 1024L * 1024L) /* 1 GB */ +#define DUK_COMPILER_MAX_BYTECODE_LENGTH (256L * 1024L * 1024L) /* 1 GB */ /* * Compiler intermediate values @@ -4181,21 +4273,21 @@ * either a left-hand-side or right-hand-side role (e.g. object property). */ -#define DUK_IVAL_NONE 0 /* no value */ -#define DUK_IVAL_PLAIN 1 /* register, constant, or value */ -#define DUK_IVAL_ARITH 2 /* binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops */ -#define DUK_IVAL_PROP 3 /* property access */ -#define DUK_IVAL_VAR 4 /* variable access */ - -#define DUK_ISPEC_NONE 0 /* no value */ -#define DUK_ISPEC_VALUE 1 /* value resides in 'valstack_idx' */ -#define DUK_ISPEC_REGCONST 2 /* value resides in a register or constant */ +#define DUK_IVAL_NONE 0 /* no value */ +#define DUK_IVAL_PLAIN 1 /* register, constant, or value */ +#define DUK_IVAL_ARITH 2 /* binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops */ +#define DUK_IVAL_PROP 3 /* property access */ +#define DUK_IVAL_VAR 4 /* variable access */ + +#define DUK_ISPEC_NONE 0 /* no value */ +#define DUK_ISPEC_VALUE 1 /* value resides in 'valstack_idx' */ +#define DUK_ISPEC_REGCONST 2 /* value resides in a register or constant */ /* Bit mask which indicates that a regconst is a constant instead of a register. * Chosen so that when a regconst is cast to duk_int32_t, all consts are * negative values. */ -#define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */ +#define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */ /* Type to represent a reg/const reference during compilation, with <0 * indicating a constant. Some call sites also use -1 to indicate 'none'. @@ -4203,9 +4295,9 @@ typedef duk_int32_t duk_regconst_t; typedef struct { - duk_small_uint_t t; /* DUK_ISPEC_XXX */ + duk_small_uint_t t; /* DUK_ISPEC_XXX */ duk_regconst_t regconst; - duk_idx_t valstack_idx; /* always set; points to a reserved valstack slot */ + duk_idx_t valstack_idx; /* always set; points to a reserved valstack slot */ } duk_ispec; typedef struct { @@ -4217,8 +4309,8 @@ */ /* XXX: can be optimized for smaller footprint esp. on 32-bit environments */ - duk_small_uint_t t; /* DUK_IVAL_XXX */ - duk_small_uint_t op; /* bytecode opcode for binary ops */ + duk_small_uint_t t; /* DUK_IVAL_XXX */ + duk_small_uint_t op; /* bytecode opcode for binary ops */ duk_ispec x1; duk_ispec x2; } duk_ivalue; @@ -4240,22 +4332,22 @@ * Compiler state */ -#define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0) -#define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1) +#define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0) +#define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1) -#define DUK_DECL_TYPE_VAR 0 -#define DUK_DECL_TYPE_FUNC 1 +#define DUK_DECL_TYPE_VAR 0 +#define DUK_DECL_TYPE_FUNC 1 /* XXX: optimize to 16 bytes */ typedef struct { duk_small_uint_t flags; - duk_int_t label_id; /* numeric label_id (-1 reserved as marker) */ - duk_hstring *h_label; /* borrowed label name */ - duk_int_t catch_depth; /* catch depth at point of definition */ - duk_int_t pc_label; /* pc of label statement: - * pc+1: break jump site - * pc+2: continue jump site - */ + duk_int_t label_id; /* numeric label_id (-1 reserved as marker) */ + duk_hstring *h_label; /* borrowed label name */ + duk_int_t catch_depth; /* catch depth at point of definition */ + duk_int_t pc_label; /* pc of label statement: + * pc+1: break jump site + * pc+2: continue jump site + */ /* Fast jumps (which avoid longjmp) jump directly to the jump sites * which are always known even while the iteration/switch statement @@ -4271,22 +4363,22 @@ * platforms (e.g. if int is 32 bits and pointers are 64 bits). */ - duk_bufwriter_ctx bw_code; /* bufwriter for code */ + duk_bufwriter_ctx bw_code; /* bufwriter for code */ - duk_hstring *h_name; /* function name (borrowed reference), ends up in _name */ + duk_hstring *h_name; /* function name (borrowed reference), ends up in _name */ /* h_code: held in bw_code */ - duk_hobject *h_consts; /* array */ - duk_hobject *h_funcs; /* array of function templates: func1, offset1, line1, func2, offset2, line2 - * offset/line points to closing brace to allow skipping on pass 2 - */ - duk_hobject *h_decls; /* array of declarations: name1, val1, name2, val2, ... - * valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars) - * record function and variable declarations in pass 1 - */ - duk_hobject *h_labelnames; /* array of active label names */ - duk_hbuffer_dynamic *h_labelinfos; /* C array of duk_labelinfo */ - duk_hobject *h_argnames; /* array of formal argument names (-> _Formals) */ - duk_hobject *h_varmap; /* variable map for pass 2 (identifier -> register number or null (unmapped)) */ + duk_hobject *h_consts; /* array */ + duk_hobject *h_funcs; /* array of function templates: func1, offset1, line1, func2, offset2, line2 + * offset/line points to closing brace to allow skipping on pass 2 + */ + duk_hobject *h_decls; /* array of declarations: name1, val1, name2, val2, ... + * valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars) + * record function and variable declarations in pass 1 + */ + duk_hobject *h_labelnames; /* array of active label names */ + duk_hbuffer_dynamic *h_labelinfos; /* C array of duk_labelinfo */ + duk_hobject *h_argnames; /* array of formal argument names (-> _Formals) */ + duk_hobject *h_varmap; /* variable map for pass 2 (identifier -> register number or null (unmapped)) */ /* Value stack indices for tracking objects. */ /* code_idx: not needed */ @@ -4299,9 +4391,9 @@ duk_idx_t varmap_idx; /* Temp reg handling. */ - duk_regconst_t temp_first; /* first register that is a temporary (below: variables) */ - duk_regconst_t temp_next; /* next temporary register to allocate */ - duk_regconst_t temp_max; /* highest value of temp_reg (temp_max - 1 is highest used reg) */ + duk_regconst_t temp_first; /* first register that is a temporary (below: variables) */ + duk_regconst_t temp_next; /* next temporary register to allocate */ + duk_regconst_t temp_max; /* highest value of temp_reg (temp_max - 1 is highest used reg) */ /* Shuffle registers if large number of regs/consts. */ duk_regconst_t shuffle1; @@ -4311,49 +4403,51 @@ /* Stats for current expression being parsed. */ duk_int_t nud_count; duk_int_t led_count; - duk_int_t paren_level; /* parenthesis count, 0 = top level */ - duk_bool_t expr_lhs; /* expression is left-hand-side compatible */ - duk_bool_t allow_in; /* current paren level allows 'in' token */ + duk_int_t paren_level; /* parenthesis count, 0 = top level */ + duk_bool_t expr_lhs; /* expression is left-hand-side compatible */ + duk_bool_t allow_in; /* current paren level allows 'in' token */ /* Misc. */ - duk_int_t stmt_next; /* statement id allocation (running counter) */ - duk_int_t label_next; /* label id allocation (running counter) */ - duk_int_t catch_depth; /* catch stack depth */ - duk_int_t with_depth; /* with stack depth (affects identifier lookups) */ - duk_int_t fnum_next; /* inner function numbering */ - duk_int_t num_formals; /* number of formal arguments */ - duk_regconst_t reg_stmt_value; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */ + duk_int_t stmt_next; /* statement id allocation (running counter) */ + duk_int_t label_next; /* label id allocation (running counter) */ + duk_int_t catch_depth; /* catch stack depth */ + duk_int_t with_depth; /* with stack depth (affects identifier lookups) */ + duk_int_t fnum_next; /* inner function numbering */ + duk_int_t num_formals; /* number of formal arguments */ + duk_regconst_t + reg_stmt_value; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */ #if defined(DUK_USE_DEBUGGER_SUPPORT) - duk_int_t min_line; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */ + duk_int_t min_line; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */ duk_int_t max_line; #endif /* Status booleans. */ - duk_uint8_t is_function; /* is an actual function (not global/eval code) */ - duk_uint8_t is_eval; /* is eval code */ - duk_uint8_t is_global; /* is global code */ - duk_uint8_t is_namebinding; /* needs a name binding */ - duk_uint8_t is_constructable; /* result is constructable */ - duk_uint8_t is_setget; /* is a setter/getter */ - duk_uint8_t is_strict; /* function is strict */ - duk_uint8_t is_notail; /* function must not be tail called */ - duk_uint8_t in_directive_prologue; /* parsing in "directive prologue", recognize directives */ - duk_uint8_t in_scanning; /* parsing in "scanning" phase (first pass) */ - duk_uint8_t may_direct_eval; /* function may call direct eval */ - duk_uint8_t id_access_arguments; /* function refers to 'arguments' identifier */ - duk_uint8_t id_access_slow; /* function makes one or more slow path accesses that won't match own static variables */ - duk_uint8_t id_access_slow_own; /* function makes one or more slow path accesses that may match own static variables */ - duk_uint8_t is_arguments_shadowed; /* argument/function declaration shadows 'arguments' */ - duk_uint8_t needs_shuffle; /* function needs shuffle registers */ - duk_uint8_t reject_regexp_in_adv; /* reject RegExp literal on next advance() call; needed for handling IdentifierName productions */ - duk_uint8_t allow_regexp_in_adv; /* allow RegExp literal on next advance() call */ + duk_uint8_t is_function; /* is an actual function (not global/eval code) */ + duk_uint8_t is_eval; /* is eval code */ + duk_uint8_t is_global; /* is global code */ + duk_uint8_t is_namebinding; /* needs a name binding */ + duk_uint8_t is_constructable; /* result is constructable */ + duk_uint8_t is_setget; /* is a setter/getter */ + duk_uint8_t is_strict; /* function is strict */ + duk_uint8_t is_notail; /* function must not be tail called */ + duk_uint8_t in_directive_prologue; /* parsing in "directive prologue", recognize directives */ + duk_uint8_t in_scanning; /* parsing in "scanning" phase (first pass) */ + duk_uint8_t may_direct_eval; /* function may call direct eval */ + duk_uint8_t id_access_arguments; /* function refers to 'arguments' identifier */ + duk_uint8_t id_access_slow; /* function makes one or more slow path accesses that won't match own static variables */ + duk_uint8_t id_access_slow_own; /* function makes one or more slow path accesses that may match own static variables */ + duk_uint8_t is_arguments_shadowed; /* argument/function declaration shadows 'arguments' */ + duk_uint8_t needs_shuffle; /* function needs shuffle registers */ + duk_uint8_t + reject_regexp_in_adv; /* reject RegExp literal on next advance() call; needed for handling IdentifierName productions */ + duk_uint8_t allow_regexp_in_adv; /* allow RegExp literal on next advance() call */ }; struct duk_compiler_ctx { duk_hthread *thr; /* filename being compiled (ends up in functions' '_filename' property) */ - duk_hstring *h_filename; /* borrowed reference */ + duk_hstring *h_filename; /* borrowed reference */ /* lexing (tokenization) state (contains two valstack slot indices) */ duk_lexer_ctx lex; @@ -4361,10 +4455,10 @@ /* current and previous token for parsing */ duk_token prev_token; duk_token curr_token; - duk_idx_t tok11_idx; /* curr_token slot1 (matches 'lex' slot1_idx) */ - duk_idx_t tok12_idx; /* curr_token slot2 (matches 'lex' slot2_idx) */ - duk_idx_t tok21_idx; /* prev_token slot1 */ - duk_idx_t tok22_idx; /* prev_token slot2 */ + duk_idx_t tok11_idx; /* curr_token slot1 (matches 'lex' slot1_idx) */ + duk_idx_t tok12_idx; /* curr_token slot2 (matches 'lex' slot2_idx) */ + duk_idx_t tok21_idx; /* prev_token slot1 */ + duk_idx_t tok22_idx; /* prev_token slot2 */ /* recursion limit */ duk_int_t recursion_depth; @@ -4381,9 +4475,12 @@ * Prototypes */ -DUK_INTERNAL_DECL void duk_js_compile(duk_hthread *thr, const duk_uint8_t *src_buffer, duk_size_t src_length, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_js_compile(duk_hthread *thr, + const duk_uint8_t *src_buffer, + duk_size_t src_length, + duk_small_uint_t flags); -#endif /* DUK_JS_COMPILER_H_INCLUDED */ +#endif /* DUK_JS_COMPILER_H_INCLUDED */ /* #include duk_regexp.h */ #line 1 "duk_regexp.h" /* @@ -4394,39 +4491,39 @@ #define DUK_REGEXP_H_INCLUDED /* maximum bytecode copies for {n,m} quantifiers */ -#define DUK_RE_MAX_ATOM_COPIES 1000 +#define DUK_RE_MAX_ATOM_COPIES 1000 /* regexp compilation limits */ -#define DUK_RE_COMPILE_TOKEN_LIMIT 100000000L /* 1e8 */ +#define DUK_RE_COMPILE_TOKEN_LIMIT 100000000L /* 1e8 */ /* regexp execution limits */ -#define DUK_RE_EXECUTE_STEPS_LIMIT 1000000000L /* 1e9 */ +#define DUK_RE_EXECUTE_STEPS_LIMIT 1000000000L /* 1e9 */ /* regexp opcodes */ -#define DUK_REOP_MATCH 1 -#define DUK_REOP_CHAR 2 -#define DUK_REOP_PERIOD 3 -#define DUK_REOP_RANGES 4 -#define DUK_REOP_INVRANGES 5 -#define DUK_REOP_JUMP 6 -#define DUK_REOP_SPLIT1 7 -#define DUK_REOP_SPLIT2 8 -#define DUK_REOP_SQMINIMAL 9 -#define DUK_REOP_SQGREEDY 10 -#define DUK_REOP_SAVE 11 -#define DUK_REOP_WIPERANGE 12 -#define DUK_REOP_LOOKPOS 13 -#define DUK_REOP_LOOKNEG 14 -#define DUK_REOP_BACKREFERENCE 15 -#define DUK_REOP_ASSERT_START 16 -#define DUK_REOP_ASSERT_END 17 -#define DUK_REOP_ASSERT_WORD_BOUNDARY 18 -#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY 19 +#define DUK_REOP_MATCH 1 +#define DUK_REOP_CHAR 2 +#define DUK_REOP_PERIOD 3 +#define DUK_REOP_RANGES 4 +#define DUK_REOP_INVRANGES 5 +#define DUK_REOP_JUMP 6 +#define DUK_REOP_SPLIT1 7 +#define DUK_REOP_SPLIT2 8 +#define DUK_REOP_SQMINIMAL 9 +#define DUK_REOP_SQGREEDY 10 +#define DUK_REOP_SAVE 11 +#define DUK_REOP_WIPERANGE 12 +#define DUK_REOP_LOOKPOS 13 +#define DUK_REOP_LOOKNEG 14 +#define DUK_REOP_BACKREFERENCE 15 +#define DUK_REOP_ASSERT_START 16 +#define DUK_REOP_ASSERT_END 17 +#define DUK_REOP_ASSERT_WORD_BOUNDARY 18 +#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY 19 /* flags */ -#define DUK_RE_FLAG_GLOBAL (1U << 0) -#define DUK_RE_FLAG_IGNORE_CASE (1U << 1) -#define DUK_RE_FLAG_MULTILINE (1U << 2) +#define DUK_RE_FLAG_GLOBAL (1U << 0) +#define DUK_RE_FLAG_IGNORE_CASE (1U << 1) +#define DUK_RE_FLAG_MULTILINE (1U << 2) struct duk_re_matcher_ctx { duk_hthread *thr; @@ -4436,7 +4533,7 @@ const duk_uint8_t *input_end; const duk_uint8_t *bytecode; const duk_uint8_t *bytecode_end; - const duk_uint8_t **saved; /* allocated from valstack (fixed buffer) */ + const duk_uint8_t **saved; /* allocated from valstack (fixed buffer) */ duk_uint32_t nsaved; duk_uint32_t recursion_depth; duk_uint32_t recursion_limit; @@ -4451,11 +4548,11 @@ duk_lexer_ctx lex; duk_re_token curr_token; duk_bufwriter_ctx bw; - duk_uint32_t captures; /* highest capture number emitted so far (used as: ++captures) */ + duk_uint32_t captures; /* highest capture number emitted so far (used as: ++captures) */ duk_uint32_t highest_backref; duk_uint32_t recursion_depth; duk_uint32_t recursion_limit; - duk_uint32_t nranges; /* internal temporary value, used for char classes */ + duk_uint32_t nranges; /* internal temporary value, used for char classes */ }; /* @@ -4466,10 +4563,10 @@ DUK_INTERNAL_DECL void duk_regexp_compile(duk_hthread *thr); DUK_INTERNAL_DECL void duk_regexp_create_instance(duk_hthread *thr); DUK_INTERNAL_DECL void duk_regexp_match(duk_hthread *thr); -DUK_INTERNAL_DECL void duk_regexp_match_force_global(duk_hthread *thr); /* hacky helper for String.prototype.split() */ +DUK_INTERNAL_DECL void duk_regexp_match_force_global(duk_hthread *thr); /* hacky helper for String.prototype.split() */ #endif -#endif /* DUK_REGEXP_H_INCLUDED */ +#endif /* DUK_REGEXP_H_INCLUDED */ /* #include duk_heaphdr.h */ #line 1 "duk_heaphdr.h" /* @@ -4523,7 +4620,7 @@ #else duk_size_t h_refcount; #endif -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_HEAPPTR16) duk_uint16_t h_next16; @@ -4571,7 +4668,7 @@ #endif #if defined(DUK_USE_REFCOUNT16) duk_uint16_t h_refcount; - duk_uint16_t h_strextra16; /* round out to 8 bytes */ + duk_uint16_t h_strextra16; /* round out to 8 bytes */ #elif defined(DUK_USE_REFCOUNT32) duk_uint32_t h_refcount; #else @@ -4579,160 +4676,169 @@ #endif #else duk_uint16_t h_strextra16; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ duk_hstring *h_next; /* No 'h_prev' pointer for strings. */ }; -#define DUK_HEAPHDR_FLAGS_TYPE_MASK 0x00000003UL -#define DUK_HEAPHDR_FLAGS_FLAG_MASK (~DUK_HEAPHDR_FLAGS_TYPE_MASK) +#define DUK_HEAPHDR_FLAGS_TYPE_MASK 0x00000003UL +#define DUK_HEAPHDR_FLAGS_FLAG_MASK (~DUK_HEAPHDR_FLAGS_TYPE_MASK) - /* 2 bits for heap type */ -#define DUK_HEAPHDR_FLAGS_HEAP_START 2 /* 5 heap flags */ -#define DUK_HEAPHDR_FLAGS_USER_START 7 /* 25 user flags */ - -#define DUK_HEAPHDR_HEAP_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_HEAP_START + (n)) -#define DUK_HEAPHDR_USER_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_USER_START + (n)) -#define DUK_HEAPHDR_HEAP_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_HEAP_START + (n))) -#define DUK_HEAPHDR_USER_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_USER_START + (n))) - -#define DUK_HEAPHDR_FLAG_REACHABLE DUK_HEAPHDR_HEAP_FLAG(0) /* mark-and-sweep: reachable */ -#define DUK_HEAPHDR_FLAG_TEMPROOT DUK_HEAPHDR_HEAP_FLAG(1) /* mark-and-sweep: children not processed */ -#define DUK_HEAPHDR_FLAG_FINALIZABLE DUK_HEAPHDR_HEAP_FLAG(2) /* mark-and-sweep: finalizable (on current pass) */ -#define DUK_HEAPHDR_FLAG_FINALIZED DUK_HEAPHDR_HEAP_FLAG(3) /* mark-and-sweep: finalized (on previous pass) */ -#define DUK_HEAPHDR_FLAG_READONLY DUK_HEAPHDR_HEAP_FLAG(4) /* read-only object, in code section */ - -#define DUK_HTYPE_MIN 0 -#define DUK_HTYPE_STRING 0 -#define DUK_HTYPE_OBJECT 1 -#define DUK_HTYPE_BUFFER 2 -#define DUK_HTYPE_MAX 2 +/* 2 bits for heap type */ +#define DUK_HEAPHDR_FLAGS_HEAP_START 2 /* 5 heap flags */ +#define DUK_HEAPHDR_FLAGS_USER_START 7 /* 25 user flags */ + +#define DUK_HEAPHDR_HEAP_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_HEAP_START + (n)) +#define DUK_HEAPHDR_USER_FLAG_NUMBER(n) (DUK_HEAPHDR_FLAGS_USER_START + (n)) +#define DUK_HEAPHDR_HEAP_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_HEAP_START + (n))) +#define DUK_HEAPHDR_USER_FLAG(n) (1UL << (DUK_HEAPHDR_FLAGS_USER_START + (n))) + +#define DUK_HEAPHDR_FLAG_REACHABLE DUK_HEAPHDR_HEAP_FLAG(0) /* mark-and-sweep: reachable */ +#define DUK_HEAPHDR_FLAG_TEMPROOT DUK_HEAPHDR_HEAP_FLAG(1) /* mark-and-sweep: children not processed */ +#define DUK_HEAPHDR_FLAG_FINALIZABLE DUK_HEAPHDR_HEAP_FLAG(2) /* mark-and-sweep: finalizable (on current pass) */ +#define DUK_HEAPHDR_FLAG_FINALIZED DUK_HEAPHDR_HEAP_FLAG(3) /* mark-and-sweep: finalized (on previous pass) */ +#define DUK_HEAPHDR_FLAG_READONLY DUK_HEAPHDR_HEAP_FLAG(4) /* read-only object, in code section */ + +#define DUK_HTYPE_MIN 0 +#define DUK_HTYPE_STRING 0 +#define DUK_HTYPE_OBJECT 1 +#define DUK_HTYPE_BUFFER 2 +#define DUK_HTYPE_MAX 2 #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAPHDR_GET_NEXT(heap,h) \ - ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_next16)) -#define DUK_HEAPHDR_SET_NEXT(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_NEXT(heap, h) ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_next16)) +#define DUK_HEAPHDR_SET_NEXT(heap, h, val) \ + do { \ (h)->h_next16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) val); \ } while (0) #else -#define DUK_HEAPHDR_GET_NEXT(heap,h) ((h)->h_next) -#define DUK_HEAPHDR_SET_NEXT(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_NEXT(heap, h) ((h)->h_next) +#define DUK_HEAPHDR_SET_NEXT(heap, h, val) \ + do { \ (h)->h_next = (val); \ } while (0) #endif #if defined(DUK_USE_DOUBLE_LINKED_HEAP) #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAPHDR_GET_PREV(heap,h) \ - ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_prev16)) -#define DUK_HEAPHDR_SET_PREV(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_PREV(heap, h) ((duk_heaphdr *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->h_prev16)) +#define DUK_HEAPHDR_SET_PREV(heap, h, val) \ + do { \ (h)->h_prev16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (val)); \ } while (0) #else -#define DUK_HEAPHDR_GET_PREV(heap,h) ((h)->h_prev) -#define DUK_HEAPHDR_SET_PREV(heap,h,val) do { \ +#define DUK_HEAPHDR_GET_PREV(heap, h) ((h)->h_prev) +#define DUK_HEAPHDR_SET_PREV(heap, h, val) \ + do { \ (h)->h_prev = (val); \ } while (0) #endif #endif #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAPHDR_GET_REFCOUNT(h) ((h)->h_refcount) -#define DUK_HEAPHDR_SET_REFCOUNT(h,val) do { \ +#define DUK_HEAPHDR_GET_REFCOUNT(h) ((h)->h_refcount) +#define DUK_HEAPHDR_SET_REFCOUNT(h, val) \ + do { \ (h)->h_refcount = (val); \ - DUK_ASSERT((h)->h_refcount == (val)); /* No truncation. */ \ + DUK_ASSERT((h)->h_refcount == (val)); /* No truncation. */ \ } while (0) -#define DUK_HEAPHDR_PREINC_REFCOUNT(h) (++(h)->h_refcount) /* result: updated refcount */ -#define DUK_HEAPHDR_PREDEC_REFCOUNT(h) (--(h)->h_refcount) /* result: updated refcount */ +#define DUK_HEAPHDR_PREINC_REFCOUNT(h) (++(h)->h_refcount) /* result: updated refcount */ +#define DUK_HEAPHDR_PREDEC_REFCOUNT(h) (--(h)->h_refcount) /* result: updated refcount */ #else /* refcount macros not defined without refcounting, caller must #if defined() now */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Note: type is treated as a field separate from flags, so some masking is * involved in the macros below. */ -#define DUK_HEAPHDR_GET_FLAGS_RAW(h) ((h)->h_flags) -#define DUK_HEAPHDR_SET_FLAGS_RAW(h,val) do { \ - (h)->h_flags = (val); } \ +#define DUK_HEAPHDR_GET_FLAGS_RAW(h) ((h)->h_flags) +#define DUK_HEAPHDR_SET_FLAGS_RAW(h, val) \ + do { \ + (h)->h_flags = (val); \ + } \ } -#define DUK_HEAPHDR_GET_FLAGS(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_FLAG_MASK) -#define DUK_HEAPHDR_SET_FLAGS(h,val) do { \ +#define DUK_HEAPHDR_GET_FLAGS(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_FLAG_MASK) +#define DUK_HEAPHDR_SET_FLAGS(h, val) \ + do { \ (h)->h_flags = ((h)->h_flags & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) | (val); \ } while (0) -#define DUK_HEAPHDR_GET_TYPE(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_TYPE_MASK) -#define DUK_HEAPHDR_SET_TYPE(h,val) do { \ +#define DUK_HEAPHDR_GET_TYPE(h) ((h)->h_flags & DUK_HEAPHDR_FLAGS_TYPE_MASK) +#define DUK_HEAPHDR_SET_TYPE(h, val) \ + do { \ (h)->h_flags = ((h)->h_flags & ~(DUK_HEAPHDR_FLAGS_TYPE_MASK)) | (val); \ } while (0) /* Comparison for type >= DUK_HTYPE_MIN skipped; because DUK_HTYPE_MIN is zero * and the comparison is unsigned, it's always true and generates warnings. */ -#define DUK_HEAPHDR_HTYPE_VALID(h) ( \ - DUK_HEAPHDR_GET_TYPE((h)) <= DUK_HTYPE_MAX \ - ) +#define DUK_HEAPHDR_HTYPE_VALID(h) (DUK_HEAPHDR_GET_TYPE((h)) <= DUK_HTYPE_MAX) -#define DUK_HEAPHDR_SET_TYPE_AND_FLAGS(h,tval,fval) do { \ - (h)->h_flags = ((tval) & DUK_HEAPHDR_FLAGS_TYPE_MASK) | \ - ((fval) & DUK_HEAPHDR_FLAGS_FLAG_MASK); \ +#define DUK_HEAPHDR_SET_TYPE_AND_FLAGS(h, tval, fval) \ + do { \ + (h)->h_flags = ((tval) &DUK_HEAPHDR_FLAGS_TYPE_MASK) | ((fval) &DUK_HEAPHDR_FLAGS_FLAG_MASK); \ } while (0) -#define DUK_HEAPHDR_SET_FLAG_BITS(h,bits) do { \ +#define DUK_HEAPHDR_SET_FLAG_BITS(h, bits) \ + do { \ DUK_ASSERT(((bits) & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) == 0); \ (h)->h_flags |= (bits); \ } while (0) -#define DUK_HEAPHDR_CLEAR_FLAG_BITS(h,bits) do { \ +#define DUK_HEAPHDR_CLEAR_FLAG_BITS(h, bits) \ + do { \ DUK_ASSERT(((bits) & ~(DUK_HEAPHDR_FLAGS_FLAG_MASK)) == 0); \ (h)->h_flags &= ~((bits)); \ } while (0) -#define DUK_HEAPHDR_CHECK_FLAG_BITS(h,bits) (((h)->h_flags & (bits)) != 0) +#define DUK_HEAPHDR_CHECK_FLAG_BITS(h, bits) (((h)->h_flags & (bits)) != 0) -#define DUK_HEAPHDR_SET_REACHABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) -#define DUK_HEAPHDR_CLEAR_REACHABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) -#define DUK_HEAPHDR_HAS_REACHABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_REACHABLE) - -#define DUK_HEAPHDR_SET_TEMPROOT(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) -#define DUK_HEAPHDR_CLEAR_TEMPROOT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) -#define DUK_HEAPHDR_HAS_TEMPROOT(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_TEMPROOT) - -#define DUK_HEAPHDR_SET_FINALIZABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) -#define DUK_HEAPHDR_CLEAR_FINALIZABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) -#define DUK_HEAPHDR_HAS_FINALIZABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZABLE) - -#define DUK_HEAPHDR_SET_FINALIZED(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) -#define DUK_HEAPHDR_CLEAR_FINALIZED(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) -#define DUK_HEAPHDR_HAS_FINALIZED(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_FINALIZED) - -#define DUK_HEAPHDR_SET_READONLY(h) DUK_HEAPHDR_SET_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) -#define DUK_HEAPHDR_CLEAR_READONLY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) -#define DUK_HEAPHDR_HAS_READONLY(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h),DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_SET_REACHABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) +#define DUK_HEAPHDR_CLEAR_REACHABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) +#define DUK_HEAPHDR_HAS_REACHABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_REACHABLE) + +#define DUK_HEAPHDR_SET_TEMPROOT(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) +#define DUK_HEAPHDR_CLEAR_TEMPROOT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) +#define DUK_HEAPHDR_HAS_TEMPROOT(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_TEMPROOT) + +#define DUK_HEAPHDR_SET_FINALIZABLE(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) +#define DUK_HEAPHDR_CLEAR_FINALIZABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) +#define DUK_HEAPHDR_HAS_FINALIZABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZABLE) + +#define DUK_HEAPHDR_SET_FINALIZED(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) +#define DUK_HEAPHDR_CLEAR_FINALIZED(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) +#define DUK_HEAPHDR_HAS_FINALIZED(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_FINALIZED) + +#define DUK_HEAPHDR_SET_READONLY(h) DUK_HEAPHDR_SET_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_CLEAR_READONLY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) +#define DUK_HEAPHDR_HAS_READONLY(h) DUK_HEAPHDR_CHECK_FLAG_BITS((h), DUK_HEAPHDR_FLAG_READONLY) /* get or set a range of flags; m=first bit number, n=number of bits */ -#define DUK_HEAPHDR_GET_FLAG_RANGE(h,m,n) (((h)->h_flags >> (m)) & ((1UL << (n)) - 1UL)) +#define DUK_HEAPHDR_GET_FLAG_RANGE(h, m, n) (((h)->h_flags >> (m)) & ((1UL << (n)) - 1UL)) -#define DUK_HEAPHDR_SET_FLAG_RANGE(h,m,n,v) do { \ - (h)->h_flags = \ - ((h)->h_flags & (~(((1UL << (n)) - 1UL) << (m)))) \ - | ((v) << (m)); \ +#define DUK_HEAPHDR_SET_FLAG_RANGE(h, m, n, v) \ + do { \ + (h)->h_flags = ((h)->h_flags & (~(((1UL << (n)) - 1UL) << (m)))) | ((v) << (m)); \ } while (0) /* init pointer fields to null */ #if defined(DUK_USE_DOUBLE_LINKED_HEAP) -#define DUK_HEAPHDR_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_INIT_NULLS(h) \ + do { \ DUK_HEAPHDR_SET_NEXT((h), (void *) NULL); \ DUK_HEAPHDR_SET_PREV((h), (void *) NULL); \ } while (0) #else -#define DUK_HEAPHDR_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_INIT_NULLS(h) \ + do { \ DUK_HEAPHDR_SET_NEXT((h), (void *) NULL); \ } while (0) #endif -#define DUK_HEAPHDR_STRING_INIT_NULLS(h) do { \ +#define DUK_HEAPHDR_STRING_INIT_NULLS(h) \ + do { \ (h)->h_next = NULL; \ } while (0) @@ -4761,14 +4867,24 @@ DUK_INTERNAL_DECL void duk_heaphdr_assert_valid_subclassed(duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_assert_links(duk_heap *heap, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_assert_valid(duk_heaphdr *h); -#define DUK_HEAPHDR_ASSERT_LINKS(heap,h) do { duk_heaphdr_assert_links((heap), (h)); } while (0) -#define DUK_HEAPHDR_ASSERT_VALID(h) do { duk_heaphdr_assert_valid((h)); } while (0) +#define DUK_HEAPHDR_ASSERT_LINKS(heap, h) \ + do { \ + duk_heaphdr_assert_links((heap), (h)); \ + } while (0) +#define DUK_HEAPHDR_ASSERT_VALID(h) \ + do { \ + duk_heaphdr_assert_valid((h)); \ + } while (0) #else -#define DUK_HEAPHDR_ASSERT_LINKS(heap,h) do {} while (0) -#define DUK_HEAPHDR_ASSERT_VALID(h) do {} while (0) +#define DUK_HEAPHDR_ASSERT_LINKS(heap, h) \ + do { \ + } while (0) +#define DUK_HEAPHDR_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#endif /* DUK_HEAPHDR_H_INCLUDED */ +#endif /* DUK_HEAPHDR_H_INCLUDED */ /* #include duk_refcount.h */ #line 1 "duk_refcount.h" /* @@ -4790,19 +4906,20 @@ /* XXX: double evaluation for 'tv' argument. */ #define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) \ (DUK_TVAL_IS_HEAP_ALLOCATED((tv)) && !DUK_HEAPHDR_HAS_READONLY(DUK_TVAL_GET_HEAPHDR((tv)))) -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) (!DUK_HEAPHDR_HAS_READONLY((h))) -#else /* DUK_USE_ROM_OBJECTS */ +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) (!DUK_HEAPHDR_HAS_READONLY((h))) +#else /* DUK_USE_ROM_OBJECTS */ /* Without ROM objects "needs refcount update" == is heap allocated. */ -#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) DUK_TVAL_IS_HEAP_ALLOCATED((tv)) -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 1 -#endif /* DUK_USE_ROM_OBJECTS */ +#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) DUK_TVAL_IS_HEAP_ALLOCATED((tv)) +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 1 +#endif /* DUK_USE_ROM_OBJECTS */ /* Fast variants, inline refcount operations except for refzero handling. * Can be used explicitly when speed is always more important than size. * For a good compiler and a single file build, these are basically the * same as a forced inline. */ -#define DUK_TVAL_INCREF_FAST(thr,tv) do { \ +#define DUK_TVAL_INCREF_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -4810,10 +4927,11 @@ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ DUK_HEAPHDR_PREINC_REFCOUNT(duk__h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ } \ } while (0) -#define DUK_TVAL_DECREF_FAST(thr,tv) do { \ +#define DUK_TVAL_DECREF_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -4826,7 +4944,8 @@ } \ } \ } while (0) -#define DUK_TVAL_DECREF_NORZ_FAST(thr,tv) do { \ +#define DUK_TVAL_DECREF_NORZ_FAST(thr, tv) \ + do { \ duk_tval *duk__tv = (tv); \ DUK_ASSERT(duk__tv != NULL); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(duk__tv)) { \ @@ -4839,16 +4958,18 @@ } \ } \ } while (0) -#define DUK_HEAPHDR_INCREF_FAST(thr,h) do { \ +#define DUK_HEAPHDR_INCREF_FAST(thr, h) \ + do { \ duk_heaphdr *duk__h = (duk_heaphdr *) (h); \ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ if (DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(duk__h)) { \ DUK_HEAPHDR_PREINC_REFCOUNT(duk__h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(duk__h) != 0); /* No wrapping. */ \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_FAST_RAW(thr,h,rzcall,rzcast) do { \ +#define DUK_HEAPHDR_DECREF_FAST_RAW(thr, h, rzcall, rzcast) \ + do { \ duk_heaphdr *duk__h = (duk_heaphdr *) (h); \ DUK_ASSERT(duk__h != NULL); \ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(duk__h)); \ @@ -4859,29 +4980,72 @@ } \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_FAST(thr,h) \ - DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero,duk_heaphdr *) -#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr,h) \ - DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero_norz,duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_FAST(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero, duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero_norz, duk_heaphdr *) /* Slow variants, call to a helper to reduce code size. * Can be used explicitly when size is always more important than speed. */ -#define DUK_TVAL_INCREF_SLOW(thr,tv) do { duk_tval_incref((tv)); } while (0) -#define DUK_TVAL_DECREF_SLOW(thr,tv) do { duk_tval_decref((thr), (tv)); } while (0) -#define DUK_TVAL_DECREF_NORZ_SLOW(thr,tv) do { duk_tval_decref_norz((thr), (tv)); } while (0) -#define DUK_HEAPHDR_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HEAPHDR_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HSTRING_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_INCREF_SLOW(thr,h) do { duk_heaphdr_incref((duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_DECREF_SLOW(thr,h) do { duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); } while (0) -#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr,h) do { duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); } while (0) +#define DUK_TVAL_INCREF_SLOW(thr, tv) \ + do { \ + duk_tval_incref((tv)); \ + } while (0) +#define DUK_TVAL_DECREF_SLOW(thr, tv) \ + do { \ + duk_tval_decref((thr), (tv)); \ + } while (0) +#define DUK_TVAL_DECREF_NORZ_SLOW(thr, tv) \ + do { \ + duk_tval_decref_norz((thr), (tv)); \ + } while (0) +#define DUK_HEAPHDR_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HEAPHDR_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HSTRING_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_INCREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_incref((duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_DECREF_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref((thr), (duk_heaphdr *) (h)); \ + } while (0) +#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr, h) \ + do { \ + duk_heaphdr_decref_norz((thr), (duk_heaphdr *) (h)); \ + } while (0) /* Default variants. Selection depends on speed/size preference. * Concretely: with gcc 4.8.1 -Os x64 the difference in final binary @@ -4891,122 +5055,136 @@ /* XXX: It would be nice to specialize for specific duk_hobject subtypes * but current refzero queue handling prevents that. */ -#define DUK_TVAL_INCREF(thr,tv) DUK_TVAL_INCREF_FAST((thr),(tv)) -#define DUK_TVAL_DECREF(thr,tv) DUK_TVAL_DECREF_FAST((thr),(tv)) -#define DUK_TVAL_DECREF_NORZ(thr,tv) DUK_TVAL_DECREF_NORZ_FAST((thr),(tv)) -#define DUK_HEAPHDR_INCREF(thr,h) DUK_HEAPHDR_INCREF_FAST((thr),(h)) -#define DUK_HEAPHDR_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero,duk_heaphdr *) -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_heaphdr_refzero_norz,duk_heaphdr *) -#define DUK_HSTRING_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HSTRING_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hstring_refzero,duk_hstring *) -#define DUK_HSTRING_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hstring_refzero,duk_hstring *) /* no 'norz' variant */ -#define DUK_HOBJECT_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HOBJECT_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HOBJECT_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HBUFFER_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HBUFFER_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hbuffer_refzero,duk_hbuffer *) -#define DUK_HBUFFER_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hbuffer_refzero,duk_hbuffer *) /* no 'norz' variant */ -#define DUK_HCOMPFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HNATFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HNATFUNC_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HBUFOBJ_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HBUFOBJ_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HBUFOBJ_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#define DUK_HTHREAD_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HTHREAD_DECREF(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero,duk_hobject *) -#define DUK_HTHREAD_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_FAST_RAW((thr),(h),duk_hobject_refzero_norz,duk_hobject *) -#else -#define DUK_TVAL_INCREF(thr,tv) DUK_TVAL_INCREF_SLOW((thr),(tv)) -#define DUK_TVAL_DECREF(thr,tv) DUK_TVAL_DECREF_SLOW((thr),(tv)) -#define DUK_TVAL_DECREF_NORZ(thr,tv) DUK_TVAL_DECREF_NORZ_SLOW((thr),(tv)) -#define DUK_HEAPHDR_INCREF(thr,h) DUK_HEAPHDR_INCREF_SLOW((thr),(h)) -#define DUK_HEAPHDR_DECREF(thr,h) DUK_HEAPHDR_DECREF_SLOW((thr),(h)) -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) DUK_HEAPHDR_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HSTRING_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HSTRING_DECREF(thr,h) DUK_HSTRING_DECREF_SLOW((thr),(h)) -#define DUK_HSTRING_DECREF_NORZ(thr,h) DUK_HSTRING_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HOBJECT_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HOBJECT_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(h)) -#define DUK_HOBJECT_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HBUFFER_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) (h)) -#define DUK_HBUFFER_DECREF(thr,h) DUK_HBUFFER_DECREF_SLOW((thr),(h)) -#define DUK_HBUFFER_DECREF_NORZ(thr,h) DUK_HBUFFER_DECREF_NORZ_SLOW((thr),(h)) -#define DUK_HCOMPFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HNATFUNC_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HNATFUNC_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HBUFOBJ_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HBUFOBJ_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HBUFOB_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HTHREAD_INCREF(thr,h) DUK_HEAPHDR_INCREF((thr),(duk_heaphdr *) &(h)->obj) -#define DUK_HTHREAD_DECREF(thr,h) DUK_HOBJECT_DECREF_SLOW((thr),(duk_hobject *) &(h)->obj) -#define DUK_HTHREAD_DECREF_NORZ(thr,h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr),(duk_hobject *) &(h)->obj) +#define DUK_TVAL_INCREF(thr, tv) DUK_TVAL_INCREF_FAST((thr), (tv)) +#define DUK_TVAL_DECREF(thr, tv) DUK_TVAL_DECREF_FAST((thr), (tv)) +#define DUK_TVAL_DECREF_NORZ(thr, tv) DUK_TVAL_DECREF_NORZ_FAST((thr), (tv)) +#define DUK_HEAPHDR_INCREF(thr, h) DUK_HEAPHDR_INCREF_FAST((thr), (h)) +#define DUK_HEAPHDR_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero, duk_heaphdr *) +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_heaphdr_refzero_norz, duk_heaphdr *) +#define DUK_HSTRING_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HSTRING_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hstring_refzero, duk_hstring *) +#define DUK_HSTRING_DECREF_NORZ(thr, h) \ + DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hstring_refzero, duk_hstring *) /* no 'norz' variant */ +#define DUK_HOBJECT_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HOBJECT_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HOBJECT_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HBUFFER_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HBUFFER_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hbuffer_refzero, duk_hbuffer *) +#define DUK_HBUFFER_DECREF_NORZ(thr, h) \ + DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hbuffer_refzero, duk_hbuffer *) /* no 'norz' variant */ +#define DUK_HCOMPFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HNATFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HNATFUNC_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HBUFOBJ_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HBUFOBJ_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HBUFOBJ_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#define DUK_HTHREAD_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HTHREAD_DECREF(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero, duk_hobject *) +#define DUK_HTHREAD_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_FAST_RAW((thr), (h), duk_hobject_refzero_norz, duk_hobject *) +#else +#define DUK_TVAL_INCREF(thr, tv) DUK_TVAL_INCREF_SLOW((thr), (tv)) +#define DUK_TVAL_DECREF(thr, tv) DUK_TVAL_DECREF_SLOW((thr), (tv)) +#define DUK_TVAL_DECREF_NORZ(thr, tv) DUK_TVAL_DECREF_NORZ_SLOW((thr), (tv)) +#define DUK_HEAPHDR_INCREF(thr, h) DUK_HEAPHDR_INCREF_SLOW((thr), (h)) +#define DUK_HEAPHDR_DECREF(thr, h) DUK_HEAPHDR_DECREF_SLOW((thr), (h)) +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) DUK_HEAPHDR_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HSTRING_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HSTRING_DECREF(thr, h) DUK_HSTRING_DECREF_SLOW((thr), (h)) +#define DUK_HSTRING_DECREF_NORZ(thr, h) DUK_HSTRING_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HOBJECT_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HOBJECT_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (h)) +#define DUK_HOBJECT_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HBUFFER_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)) +#define DUK_HBUFFER_DECREF(thr, h) DUK_HBUFFER_DECREF_SLOW((thr), (h)) +#define DUK_HBUFFER_DECREF_NORZ(thr, h) DUK_HBUFFER_DECREF_NORZ_SLOW((thr), (h)) +#define DUK_HCOMPFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HNATFUNC_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HNATFUNC_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HBUFOBJ_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HBUFOBJ_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HBUFOB_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HTHREAD_INCREF(thr, h) DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) &(h)->obj) +#define DUK_HTHREAD_DECREF(thr, h) DUK_HOBJECT_DECREF_SLOW((thr), (duk_hobject *) &(h)->obj) +#define DUK_HTHREAD_DECREF_NORZ(thr, h) DUK_HOBJECT_DECREF_NORZ_SLOW((thr), (duk_hobject *) &(h)->obj) #endif /* Convenience for some situations; the above macros don't allow NULLs * for performance reasons. Macros cover only actually needed cases. */ -#define DUK_HEAPHDR_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_INCREF((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_DECREF((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HEAPHDR_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HEAPHDR_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HEAPHDR_DECREF_NORZ((thr), (duk_heaphdr *) (h)); \ } \ } while (0) -#define DUK_HOBJECT_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HOBJECT_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HOBJECT_DECREF_NORZ((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HBUFFER_DECREF_NORZ((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_INCREF_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_INCREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_INCREF((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_DECREF_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_DECREF_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_DECREF((thr), (h)); \ } \ } while (0) -#define DUK_HTHREAD_DECREF_NORZ_ALLOWNULL(thr,h) do { \ +#define DUK_HTHREAD_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ if ((h) != NULL) { \ DUK_HTHREAD_DECREF_NORZ((thr), (h)); \ } \ @@ -5018,16 +5196,22 @@ * variant is performance critical. */ #if defined(DUK_USE_FINALIZER_SUPPORT) -#define DUK_REFZERO_CHECK_FAST(thr) do { \ +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ duk_refzero_check_fast((thr)); \ } while (0) -#define DUK_REFZERO_CHECK_SLOW(thr) do { \ +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ duk_refzero_check_slow((thr)); \ } while (0) -#else /* DUK_USE_FINALIZER_SUPPORT */ -#define DUK_REFZERO_CHECK_FAST(thr) do { } while (0) -#define DUK_REFZERO_CHECK_SLOW(thr) do { } while (0) -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ + } while (0) +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ + } while (0) +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Macros to set a duk_tval and update refcount of the target (decref the @@ -5035,125 +5219,176 @@ * and footprint critical; any changes made should be measured for size/speed. */ -#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ DUK_TVAL_DECREF_NORZ((thr), &tv__tmp); \ } while (0) -#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_UNUSED(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NULL(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_BOOLEAN(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NUMBER(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_DOUBLE(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_NAN(tv__dst); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_I48(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_I32(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_U32(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) #else -#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr,tvptr_dst,newval) \ +#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr, tvptr_dst, newval) \ DUK_TVAL_SET_DOUBLE_UPDREF((thr), (tvptr_dst), (duk_double_t) (newval)) -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr,tvptr_dst,lf_v,lf_fp,lf_flags) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr, tvptr_dst, lf_v, lf_fp, lf_flags) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_LIGHTFUNC(tv__dst, (lf_v), (lf_fp), (lf_flags)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_STRING(tv__dst, (newval)); \ DUK_HSTRING_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_OBJECT(tv__dst, (newval)); \ DUK_HOBJECT_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_BUFFER(tv__dst, (newval)); \ DUK_HBUFFER_INCREF((thr), (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) -#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; duk_tval tv__tmp; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_POINTER(tv__dst, (newval)); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) /* DUK_TVAL_SET_TVAL_UPDREF() is used a lot in executor, property lookups, @@ -5164,281 +5399,452 @@ */ /* Original idiom used, minimal code size. */ -#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr,tvptr_dst,tvptr_src) do { \ - duk_tval *tv__dst, *tv__src; duk_tval tv__tmp; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr, tvptr_dst, tvptr_src) \ + do { \ + duk_tval *tv__dst, *tv__src; \ + duk_tval tv__tmp; \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_SET_TVAL(&tv__tmp, tv__dst); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ DUK_TVAL_INCREF((thr), tv__src); \ - DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ + DUK_TVAL_DECREF((thr), &tv__tmp); /* side effects */ \ } while (0) /* Faster alternative: avoid making a temporary copy of tvptr_dst and use * fast incref/decref macros. */ -#define DUK_TVAL_SET_TVAL_UPDREF_ALT1(thr,tvptr_dst,tvptr_src) do { \ - duk_tval *tv__dst, *tv__src; duk_heaphdr *h__obj; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT1(thr, tvptr_dst, tvptr_src) \ + do { \ + duk_tval *tv__dst, *tv__src; \ + duk_heaphdr *h__obj; \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_INCREF_FAST((thr), tv__src); \ if (DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv__dst)) { \ h__obj = DUK_TVAL_GET_HEAPHDR(tv__dst); \ DUK_ASSERT(h__obj != NULL); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ - DUK_HEAPHDR_DECREF_FAST((thr), h__obj); /* side effects */ \ + DUK_HEAPHDR_DECREF_FAST((thr), h__obj); /* side effects */ \ } else { \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ } \ } while (0) /* XXX: no optimized variants yet */ -#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0 -#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 -#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 -#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 -#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 -#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ_ALT0 +#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 +#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 +#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 +#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 +#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 -#else -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast int-to-double */ -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 -#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 -#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 -#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 -#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 +#else +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast int-to-double */ +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 +#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 +#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 +#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 +#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 #if defined(DUK_USE_FAST_REFCOUNT_DEFAULT) /* Optimized for speed. */ -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT1 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT1 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT1 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT1 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 #else /* Optimized for size. */ -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#endif - -#else /* DUK_USE_REFERENCE_COUNTING */ - -#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) 0 -#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 0 - -#define DUK_TVAL_INCREF_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ_FAST(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_INCREF_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ_SLOW(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_INCREF(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF(thr,v) do {} while (0) /* nop */ -#define DUK_TVAL_DECREF_NORZ(thr,v) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HEAPHDR_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HSTRING_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_FAST(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ(thr,h) do {} while (0) /* nop */ - -#define DUK_HCOMPFUNC_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HCOMPFUNC_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HCOMPFUNC_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HNATFUNC_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFOBJ_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_INCREF(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_DECREF(thr,h) do {} while (0) /* nop */ -#define DUK_HTHREAD_DECREF_NORZ(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_INCREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_INCREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_ALLOWNULL(thr,h) do {} while (0) /* nop */ -#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr,h) do {} while (0) /* nop */ - -#define DUK_REFZERO_CHECK_FAST(thr) do {} while (0) /* nop */ -#define DUK_REFZERO_CHECK_SLOW(thr) do {} while (0) /* nop */ - -#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#endif + +#else /* DUK_USE_REFERENCE_COUNTING */ + +#define DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv) 0 +#define DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE(h) 0 + +#define DUK_TVAL_INCREF_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ_FAST(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_INCREF_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ_SLOW(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_INCREF(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_TVAL_DECREF_NORZ(thr, v) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HEAPHDR_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HSTRING_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_FAST(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_SLOW(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ + +#define DUK_HCOMPFUNC_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HCOMPFUNC_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HCOMPFUNC_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HNATFUNC_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFOBJ_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_INCREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_DECREF(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HTHREAD_DECREF_NORZ(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_INCREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_INCREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ +#define DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, h) \ + do { \ + } while (0) /* nop */ + +#define DUK_REFZERO_CHECK_FAST(thr) \ + do { \ + } while (0) /* nop */ +#define DUK_REFZERO_CHECK_SLOW(thr) \ + do { \ + } while (0) /* nop */ + +#define DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_UNDEFINED(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_UNUSED_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_UNUSED(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NULL_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NULL(tv__dst); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_BOOLEAN(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NUMBER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NUMBER_CHKFAST_FAST(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_DOUBLE_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_DOUBLE(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr,tvptr_dst) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_NAN_UPDREF_ALT0(thr, tvptr_dst) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_NAN(tv__dst); \ DUK_UNREF((thr)); \ } while (0) #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I48_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_I48(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_I32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_I32(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_U32_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_U32(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) #else -#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr,tvptr_dst,newval) \ +#define DUK_TVAL_SET_DOUBLE_CAST_UPDREF(thr, tvptr_dst, newval) \ DUK_TVAL_SET_DOUBLE_UPDREF((thr), (tvptr_dst), (duk_double_t) (newval)) -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr,tvptr_dst,lf_v,lf_fp,lf_flags) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0(thr, tvptr_dst, lf_v, lf_fp, lf_flags) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_LIGHTFUNC(tv__dst, (lf_v), (lf_fp), (lf_flags)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_STRING_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_STRING(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_OBJECT_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_OBJECT(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_BUFFER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_BUFFER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr,tvptr_dst,newval) do { \ - duk_tval *tv__dst; tv__dst = (tvptr_dst); \ +#define DUK_TVAL_SET_POINTER_UPDREF_ALT0(thr, tvptr_dst, newval) \ + do { \ + duk_tval *tv__dst; \ + tv__dst = (tvptr_dst); \ DUK_TVAL_SET_POINTER(tv__dst, (newval)); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr,tvptr_dst,tvptr_src) do { \ +#define DUK_TVAL_SET_TVAL_UPDREF_ALT0(thr, tvptr_dst, tvptr_src) \ + do { \ duk_tval *tv__dst, *tv__src; \ - tv__dst = (tvptr_dst); tv__src = (tvptr_src); \ + tv__dst = (tvptr_dst); \ + tv__src = (tvptr_src); \ DUK_TVAL_SET_TVAL(tv__dst, tv__src); \ DUK_UNREF((thr)); \ } while (0) -#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 -#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 -#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 -#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 -#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 -#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 -#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ DUK_TVAL_SET_UNDEFINED_UPDREF_ALT0 +#define DUK_TVAL_SET_UNUSED_UPDREF DUK_TVAL_SET_UNUSED_UPDREF_ALT0 +#define DUK_TVAL_SET_NULL_UPDREF DUK_TVAL_SET_NULL_UPDREF_ALT0 +#define DUK_TVAL_SET_BOOLEAN_UPDREF DUK_TVAL_SET_BOOLEAN_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_UPDREF DUK_TVAL_SET_NUMBER_UPDREF_ALT0 +#define DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF_ALT0 +#define DUK_TVAL_SET_DOUBLE_UPDREF DUK_TVAL_SET_DOUBLE_UPDREF_ALT0 +#define DUK_TVAL_SET_NAN_UPDREF DUK_TVAL_SET_NAN_UPDREF_ALT0 #if defined(DUK_USE_FASTINT) -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 -#else -#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast-int-to-double */ -#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF -#endif /* DUK_USE_FASTINT */ -#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ -#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 -#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 -#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 -#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 -#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 - -#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_I48_UPDREF_ALT0 +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_I32_UPDREF_ALT0 +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_U32_UPDREF_ALT0 +#else +#define DUK_TVAL_SET_I48_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF /* XXX: fast-int-to-double */ +#define DUK_TVAL_SET_I32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#define DUK_TVAL_SET_U32_UPDREF DUK_TVAL_SET_DOUBLE_CAST_UPDREF +#endif /* DUK_USE_FASTINT */ +#define DUK_TVAL_SET_FASTINT_UPDREF DUK_TVAL_SET_I48_UPDREF /* convenience */ +#define DUK_TVAL_SET_LIGHTFUNC_UPDREF DUK_TVAL_SET_LIGHTFUNC_UPDREF_ALT0 +#define DUK_TVAL_SET_STRING_UPDREF DUK_TVAL_SET_STRING_UPDREF_ALT0 +#define DUK_TVAL_SET_OBJECT_UPDREF DUK_TVAL_SET_OBJECT_UPDREF_ALT0 +#define DUK_TVAL_SET_BUFFER_UPDREF DUK_TVAL_SET_BUFFER_UPDREF_ALT0 +#define DUK_TVAL_SET_POINTER_UPDREF DUK_TVAL_SET_POINTER_UPDREF_ALT0 + +#define DUK_TVAL_SET_TVAL_UPDREF DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_FAST DUK_TVAL_SET_TVAL_UPDREF_ALT0 +#define DUK_TVAL_SET_TVAL_UPDREF_SLOW DUK_TVAL_SET_TVAL_UPDREF_ALT0 -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Some convenience macros that don't have optimized implementations now. */ -#define DUK_TVAL_SET_TVAL_UPDREF_NORZ(thr,tv_dst,tv_src) do { \ +#define DUK_TVAL_SET_TVAL_UPDREF_NORZ(thr, tv_dst, tv_src) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_tval *duk__dst = (tv_dst); \ duk_tval *duk__src = (tv_src); \ @@ -5448,7 +5854,8 @@ DUK_TVAL_INCREF(thr, duk__dst); \ } while (0) -#define DUK_TVAL_SET_U32_UPDREF_NORZ(thr,tv_dst,val) do { \ +#define DUK_TVAL_SET_U32_UPDREF_NORZ(thr, tv_dst, val) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_tval *duk__dst = (tv_dst); \ duk_uint32_t duk__val = (duk_uint32_t) (val); \ @@ -5468,7 +5875,7 @@ #endif DUK_INTERNAL_DECL void duk_heaphdr_refcount_finalize_norz(duk_heap *heap, duk_heaphdr *hdr); DUK_INTERNAL_DECL void duk_hobject_refcount_finalize_norz(duk_heap *heap, duk_hobject *h); -#if 0 /* Not needed: fast path handles inline; slow path uses duk_heaphdr_decref() which is needed anyway. */ +#if 0 /* Not needed: fast path handles inline; slow path uses duk_heaphdr_decref() which is needed anyway. */ DUK_INTERNAL_DECL void duk_hstring_decref(duk_hthread *thr, duk_hstring *h); DUK_INTERNAL_DECL void duk_hstring_decref_norz(duk_hthread *thr, duk_hstring *h); DUK_INTERNAL_DECL void duk_hbuffer_decref(duk_hthread *thr, duk_hbuffer *h); @@ -5479,8 +5886,8 @@ DUK_INTERNAL_DECL void duk_heaphdr_refzero(duk_hthread *thr, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_refzero_norz(duk_hthread *thr, duk_heaphdr *h); #if defined(DUK_USE_FAST_REFCOUNT_DEFAULT) -DUK_INTERNAL_DECL void duk_hstring_refzero(duk_hthread *thr, duk_hstring *h); /* no 'norz' variant */ -DUK_INTERNAL_DECL void duk_hbuffer_refzero(duk_hthread *thr, duk_hbuffer *h); /* no 'norz' variant */ +DUK_INTERNAL_DECL void duk_hstring_refzero(duk_hthread *thr, duk_hstring *h); /* no 'norz' variant */ +DUK_INTERNAL_DECL void duk_hbuffer_refzero(duk_hthread *thr, duk_hbuffer *h); /* no 'norz' variant */ DUK_INTERNAL_DECL void duk_hobject_refzero(duk_hthread *thr, duk_hobject *h); DUK_INTERNAL_DECL void duk_hobject_refzero_norz(duk_hthread *thr, duk_hobject *h); #else @@ -5491,11 +5898,11 @@ DUK_INTERNAL_DECL void duk_heaphdr_decref(duk_hthread *thr, duk_heaphdr *h); DUK_INTERNAL_DECL void duk_heaphdr_decref_norz(duk_hthread *thr, duk_heaphdr *h); #endif -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ /* no refcounting */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ -#endif /* DUK_REFCOUNT_H_INCLUDED */ +#endif /* DUK_REFCOUNT_H_INCLUDED */ /* #include duk_api_internal.h */ #line 1 "duk_api_internal.h" /* @@ -5512,9 +5919,9 @@ #define DUK_ALWAYS_INLINE_PERF #define DUK_NOINLINE_PERF #else -#define DUK_INLINE_PERF DUK_INLINE +#define DUK_INLINE_PERF DUK_INLINE #define DUK_ALWAYS_INLINE_PERF DUK_ALWAYS_INLINE -#define DUK_NOINLINE_PERF DUK_NOINLINE +#define DUK_NOINLINE_PERF DUK_NOINLINE #endif /* Inline macro helpers, for bytecode executor. */ @@ -5523,19 +5930,19 @@ #define DUK_EXEC_ALWAYS_INLINE_PERF #define DUK_EXEC_NOINLINE_PERF #else -#define DUK_EXEC_INLINE_PERF DUK_INLINE +#define DUK_EXEC_INLINE_PERF DUK_INLINE #define DUK_EXEC_ALWAYS_INLINE_PERF DUK_ALWAYS_INLINE -#define DUK_EXEC_NOINLINE_PERF DUK_NOINLINE +#define DUK_EXEC_NOINLINE_PERF DUK_NOINLINE #endif /* duk_push_sprintf constants */ -#define DUK_PUSH_SPRINTF_INITIAL_SIZE 256L -#define DUK_PUSH_SPRINTF_SANITY_LIMIT (1L * 1024L * 1024L * 1024L) +#define DUK_PUSH_SPRINTF_INITIAL_SIZE 256L +#define DUK_PUSH_SPRINTF_SANITY_LIMIT (1L * 1024L * 1024L * 1024L) /* Flag ORed to err_code to indicate __FILE__ / __LINE__ is not * blamed as source of error for error fileName / lineNumber. */ -#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE (1L << 24) +#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE (1L << 24) /* Current convention is to use duk_size_t for value stack sizes and global indices, * and duk_idx_t for local frame indices. @@ -5597,24 +6004,17 @@ DUK_INTERNAL_DECL duk_tval *duk_get_borrowed_this_tval(duk_hthread *thr); /* XXX: add fastint support? */ -#define duk_push_u64(thr,val) \ - duk_push_number((thr), (duk_double_t) (val)) -#define duk_push_i64(thr,val) \ - duk_push_number((thr), (duk_double_t) (val)) +#define duk_push_u64(thr, val) duk_push_number((thr), (duk_double_t) (val)) +#define duk_push_i64(thr, val) duk_push_number((thr), (duk_double_t) (val)) /* duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range */ -#define duk_push_u32(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) -#define duk_push_i32(thr,val) \ - duk_push_int((thr), (duk_int_t) (val)) +#define duk_push_u32(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) +#define duk_push_i32(thr, val) duk_push_int((thr), (duk_int_t) (val)) /* sometimes stack and array indices need to go on the stack */ -#define duk_push_idx(thr,val) \ - duk_push_int((thr), (duk_int_t) (val)) -#define duk_push_uarridx(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) -#define duk_push_size_t(thr,val) \ - duk_push_uint((thr), (duk_uint_t) (val)) /* XXX: assumed to fit for now */ +#define duk_push_idx(thr, val) duk_push_int((thr), (duk_int_t) (val)) +#define duk_push_uarridx(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) +#define duk_push_size_t(thr, val) duk_push_uint((thr), (duk_uint_t) (val)) /* XXX: assumed to fit for now */ DUK_INTERNAL_DECL duk_bool_t duk_is_string_notsymbol(duk_hthread *thr, duk_idx_t idx); @@ -5631,19 +6031,23 @@ DUK_INTERNAL_DECL duk_hcompfunc *duk_get_hcompfunc(duk_hthread *thr, duk_idx_t idx); DUK_INTERNAL_DECL duk_hnatfunc *duk_get_hnatfunc(duk_hthread *thr, duk_idx_t idx); -DUK_INTERNAL_DECL void *duk_get_buffer_data_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len, duk_bool_t throw_flag, duk_bool_t *out_isbuffer); +DUK_INTERNAL_DECL void *duk_get_buffer_data_raw(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_len, + duk_bool_t throw_flag, + duk_bool_t *out_isbuffer); DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_with_class(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t classnum); DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_accept_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask); -#define duk_require_hobject_promote_lfunc(thr,idx) \ - duk_require_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) -#define duk_get_hobject_promote_lfunc(thr,idx) \ - duk_get_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) +#define duk_require_hobject_promote_lfunc(thr, idx) duk_require_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) +#define duk_get_hobject_promote_lfunc(thr, idx) duk_get_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC) -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL void *duk_get_voidptr(duk_hthread *thr, duk_idx_t idx); #endif @@ -5666,12 +6070,16 @@ DUK_INTERNAL_DECL duk_bool_t duk_to_boolean_top_pop(duk_hthread *thr); -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ DUK_INTERNAL_DECL duk_hstring *duk_safe_to_hstring(duk_hthread *thr, duk_idx_t idx); #endif DUK_INTERNAL_DECL void duk_push_class_string_tval(duk_hthread *thr, duk_tval *tv, duk_bool_t avoid_side_effects); -DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped); /* out_clamped=NULL, RangeError if outside range */ +DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, + duk_idx_t idx, + duk_int_t minval, + duk_int_t maxval, + duk_bool_t *out_clamped); /* out_clamped=NULL, RangeError if outside range */ DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval); DUK_INTERNAL_DECL duk_int_t duk_to_int_check_range(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -5696,13 +6104,15 @@ DUK_INTERNAL_DECL void duk_push_hstring_empty(duk_hthread *thr); DUK_INTERNAL_DECL void duk_push_hobject(duk_hthread *thr, duk_hobject *h); DUK_INTERNAL_DECL void duk_push_hbuffer(duk_hthread *thr, duk_hbuffer *h); -#define duk_push_hthread(thr,h) \ - duk_push_hobject((thr), (duk_hobject *) (h)) -#define duk_push_hnatfunc(thr,h) \ - duk_push_hobject((thr), (duk_hobject *) (h)) +#define duk_push_hthread(thr, h) duk_push_hobject((thr), (duk_hobject *) (h)) +#define duk_push_hnatfunc(thr, h) duk_push_hobject((thr), (duk_hobject *) (h)) DUK_INTERNAL_DECL void duk_push_hobject_bidx(duk_hthread *thr, duk_small_int_t builtin_idx); -DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx); -DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper_proto(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_hobject *proto); +DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx); +DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper_proto(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_hobject *proto); DUK_INTERNAL_DECL duk_hcompfunc *duk_push_hcompfunc(duk_hthread *thr); DUK_INTERNAL_DECL duk_hboundfunc *duk_push_hboundfunc(duk_hthread *thr); DUK_INTERNAL_DECL void duk_push_c_function_builtin(duk_hthread *thr, duk_c_function func, duk_int_t nargs); @@ -5719,11 +6129,13 @@ DUK_INTERNAL_DECL void duk_push_lightfunc_name_raw(duk_hthread *thr, duk_c_function func, duk_small_uint_t lf_flags); DUK_INTERNAL_DECL void duk_push_lightfunc_name(duk_hthread *thr, duk_tval *tv); DUK_INTERNAL_DECL void duk_push_lightfunc_tostring(duk_hthread *thr, duk_tval *tv); -#if 0 /* not used yet */ +#if 0 /* not used yet */ DUK_INTERNAL_DECL void duk_push_hnatfunc_name(duk_hthread *thr, duk_hnatfunc *h); #endif #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_INTERNAL_DECL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx); +DUK_INTERNAL_DECL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx); #endif DUK_INTERNAL_DECL void *duk_push_fixed_buffer_nozero(duk_hthread *thr, duk_size_t len); @@ -5740,80 +6152,86 @@ * arguments and such call sites are also easiest to verify to be correct. */ -DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> val */ +DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> val */ DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_get_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_get_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_get_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop); /* -> */ +DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_bool_t *out_has_prop); /* -> */ DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop(duk_hthread *thr, duk_idx_t obj_idx); DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); DUK_INTERNAL_DECL duk_bool_t duk_xget_owndataprop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_xget_owndataprop_stridx_short(thr,obj_idx,stridx) \ +#define duk_xget_owndataprop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_xget_owndataprop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* val -> */ +DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* val -> */ DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_put_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_put_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ duk_put_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) -DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ -#if 0 /* Too few call sites to be useful. */ +DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +#if 0 /* Too few call sites to be useful. */ DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_del_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_del_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((obj_idx) >= -0x8000L && (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((stridx) >= 0 && (stridx) <= 0xffffL), \ duk_del_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) #endif -#define duk_del_prop_stridx_short(thr,obj_idx,stridx) \ - duk_del_prop_stridx((thr), (obj_idx), (stridx)) +#define duk_del_prop_stridx_short(thr, obj_idx, stridx) duk_del_prop_stridx((thr), (obj_idx), (stridx)) -DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ -#if 0 /* Too few call sites to be useful. */ +DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +#if 0 /* Too few call sites to be useful. */ DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_has_prop_stridx_short(thr,obj_idx,stridx) \ +#define duk_has_prop_stridx_short(thr, obj_idx, stridx) \ (DUK_ASSERT_EXPR((obj_idx) >= -0x8000L && (obj_idx) <= 0x7fffL), \ DUK_ASSERT_EXPR((stridx) >= 0 && (stridx) <= 0xffffL), \ duk_has_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx)))) #endif -#define duk_has_prop_stridx_short(thr,obj_idx,stridx) \ - duk_has_prop_stridx((thr), (obj_idx), (stridx)) +#define duk_has_prop_stridx_short(thr, obj_idx, stridx) duk_has_prop_stridx((thr), (obj_idx), (stridx)) -DUK_INTERNAL_DECL void duk_xdef_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t desc_flags); /* key val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t desc_flags); /* key val -> */ -DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags); /* val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_hthread *thr, + duk_idx_t obj_idx, + duk_uarridx_t arr_idx, + duk_small_uint_t desc_flags); /* val -> */ /* XXX: Because stridx and desc_flags have a limited range, this call could * always pack stridx and desc_flags into a single argument. */ -DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_uint_t desc_flags); /* val -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_small_uint_t desc_flags); /* val -> */ DUK_INTERNAL_DECL void duk_xdef_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args); -#define duk_xdef_prop_stridx_short(thr,obj_idx,stridx,desc_flags) \ +#define duk_xdef_prop_stridx_short(thr, obj_idx, stridx, desc_flags) \ (DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x80L && (duk_int_t) (obj_idx) <= 0x7fL), \ DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \ DUK_ASSERT_EXPR((duk_int_t) (desc_flags) >= 0 && (duk_int_t) (desc_flags) <= 0xffL), \ - duk_xdef_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 24) + (((duk_uint_t) (stridx)) << 8) + (duk_uint_t) (desc_flags))) - -#define duk_xdef_prop_wec(thr,obj_idx) \ - duk_xdef_prop((thr), (obj_idx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_index_wec(thr,obj_idx,arr_idx) \ - duk_xdef_prop_index((thr), (obj_idx), (arr_idx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_stridx_wec(thr,obj_idx,stridx) \ - duk_xdef_prop_stridx((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) -#define duk_xdef_prop_stridx_short_wec(thr,obj_idx,stridx) \ + duk_xdef_prop_stridx_short_raw((thr), \ + (((duk_uint_t) (obj_idx)) << 24) + (((duk_uint_t) (stridx)) << 8) + \ + (duk_uint_t) (desc_flags))) + +#define duk_xdef_prop_wec(thr, obj_idx) duk_xdef_prop((thr), (obj_idx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_index_wec(thr, obj_idx, arr_idx) duk_xdef_prop_index((thr), (obj_idx), (arr_idx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_stridx_wec(thr, obj_idx, stridx) duk_xdef_prop_stridx((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) +#define duk_xdef_prop_stridx_short_wec(thr, obj_idx, stridx) \ duk_xdef_prop_stridx_short((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC) -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL void duk_xdef_prop_stridx_builtin(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags); /* -> */ #endif -DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ +DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* -> */ DUK_INTERNAL_DECL duk_bool_t duk_get_method_stridx(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t stridx); @@ -5862,28 +6280,24 @@ * using these macro results in faster and smaller code than duk_get_tval(). * Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts. */ -#define DUK_ASSERT_VALID_NEGIDX(thr,idx) \ +#define DUK_ASSERT_VALID_NEGIDX(thr, idx) \ (DUK_ASSERT_EXPR((duk_int_t) (idx) < 0), DUK_ASSERT_EXPR(duk_is_valid_index((thr), (idx)))) -#define DUK_ASSERT_VALID_POSIDX(thr,idx) \ +#define DUK_ASSERT_VALID_POSIDX(thr, idx) \ (DUK_ASSERT_EXPR((duk_int_t) (idx) >= 0), DUK_ASSERT_EXPR(duk_is_valid_index((thr), (idx)))) -#define DUK_GET_TVAL_NEGIDX(thr,idx) \ - (DUK_ASSERT_VALID_NEGIDX((thr),(idx)), ((duk_hthread *) (thr))->valstack_top + (idx)) -#define DUK_GET_TVAL_POSIDX(thr,idx) \ - (DUK_ASSERT_VALID_POSIDX((thr),(idx)), ((duk_hthread *) (thr))->valstack_bottom + (idx)) -#define DUK_GET_HOBJECT_NEGIDX(thr,idx) \ - (DUK_ASSERT_VALID_NEGIDX((thr),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_top + (idx))) -#define DUK_GET_HOBJECT_POSIDX(thr,idx) \ - (DUK_ASSERT_VALID_POSIDX((thr),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_bottom + (idx))) - -#define DUK_GET_THIS_TVAL_PTR(thr) \ - (DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), \ - (thr)->valstack_bottom - 1) +#define DUK_GET_TVAL_NEGIDX(thr, idx) (DUK_ASSERT_VALID_NEGIDX((thr), (idx)), ((duk_hthread *) (thr))->valstack_top + (idx)) +#define DUK_GET_TVAL_POSIDX(thr, idx) (DUK_ASSERT_VALID_POSIDX((thr), (idx)), ((duk_hthread *) (thr))->valstack_bottom + (idx)) +#define DUK_GET_HOBJECT_NEGIDX(thr, idx) \ + (DUK_ASSERT_VALID_NEGIDX((thr), (idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_top + (idx))) +#define DUK_GET_HOBJECT_POSIDX(thr, idx) \ + (DUK_ASSERT_VALID_POSIDX((thr), (idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_bottom + (idx))) + +#define DUK_GET_THIS_TVAL_PTR(thr) (DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), (thr)->valstack_bottom - 1) DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time(duk_hthread *thr); DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time_nofrac(duk_hthread *thr); DUK_INTERNAL_DECL duk_double_t duk_time_get_monotonic_time(duk_hthread *thr); -#endif /* DUK_API_INTERNAL_H_INCLUDED */ +#endif /* DUK_API_INTERNAL_H_INCLUDED */ /* #include duk_hstring.h */ #line 1 "duk_hstring.h" /* @@ -5915,9 +6329,9 @@ */ #if defined(DUK_USE_STRLEN16) -#define DUK_HSTRING_MAX_BYTELEN (0x0000ffffUL) +#define DUK_HSTRING_MAX_BYTELEN (0x0000ffffUL) #else -#define DUK_HSTRING_MAX_BYTELEN (0x7fffffffUL) +#define DUK_HSTRING_MAX_BYTELEN (0x7fffffffUL) #endif /* XXX: could add flags for "is valid CESU-8" (ECMAScript compatible strings), @@ -5929,139 +6343,148 @@ /* With lowmem builds the high 16 bits of duk_heaphdr are used for other * purposes, so this leaves 7 duk_heaphdr flags and 9 duk_hstring flags. */ -#define DUK_HSTRING_FLAG_ASCII DUK_HEAPHDR_USER_FLAG(0) /* string is ASCII, clen == blen */ -#define DUK_HSTRING_FLAG_ARRIDX DUK_HEAPHDR_USER_FLAG(1) /* string is a valid array index */ -#define DUK_HSTRING_FLAG_SYMBOL DUK_HEAPHDR_USER_FLAG(2) /* string is a symbol (invalid utf-8) */ -#define DUK_HSTRING_FLAG_HIDDEN DUK_HEAPHDR_USER_FLAG(3) /* string is a hidden symbol (implies symbol, Duktape 1.x internal string) */ -#define DUK_HSTRING_FLAG_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(4) /* string is a reserved word (non-strict) */ -#define DUK_HSTRING_FLAG_STRICT_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(5) /* string is a reserved word (strict) */ -#define DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS DUK_HEAPHDR_USER_FLAG(6) /* string is 'eval' or 'arguments' */ -#define DUK_HSTRING_FLAG_EXTDATA DUK_HEAPHDR_USER_FLAG(7) /* string data is external (duk_hstring_external) */ -#define DUK_HSTRING_FLAG_PINNED_LITERAL DUK_HEAPHDR_USER_FLAG(8) /* string is a literal, and pinned */ - -#define DUK_HSTRING_HAS_ASCII(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_HAS_ARRIDX(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_HAS_SYMBOL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_HAS_HIDDEN(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_HAS_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_HAS_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_HAS_EXTDATA(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_HAS_PINNED_LITERAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#define DUK_HSTRING_SET_ASCII(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_SET_ARRIDX(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_SET_SYMBOL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_SET_HIDDEN(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_SET_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_SET_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_SET_EXTDATA(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_SET_PINNED_LITERAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#define DUK_HSTRING_CLEAR_ASCII(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) -#define DUK_HSTRING_CLEAR_ARRIDX(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) -#define DUK_HSTRING_CLEAR_SYMBOL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) -#define DUK_HSTRING_CLEAR_HIDDEN(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) -#define DUK_HSTRING_CLEAR_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) -#define DUK_HSTRING_CLEAR_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) -#define DUK_HSTRING_CLEAR_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) -#define DUK_HSTRING_CLEAR_EXTDATA(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) -#define DUK_HSTRING_CLEAR_PINNED_LITERAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) - -#if 0 /* Slightly smaller code without explicit flag, but explicit flag - * is very useful when 'clen' is dropped. - */ -#define DUK_HSTRING_IS_ASCII(x) (DUK_HSTRING_GET_BYTELEN((x)) == DUK_HSTRING_GET_CHARLEN((x))) +#define DUK_HSTRING_FLAG_ASCII DUK_HEAPHDR_USER_FLAG(0) /* string is ASCII, clen == blen */ +#define DUK_HSTRING_FLAG_ARRIDX DUK_HEAPHDR_USER_FLAG(1) /* string is a valid array index */ +#define DUK_HSTRING_FLAG_SYMBOL DUK_HEAPHDR_USER_FLAG(2) /* string is a symbol (invalid utf-8) */ +#define DUK_HSTRING_FLAG_HIDDEN \ + DUK_HEAPHDR_USER_FLAG(3) /* string is a hidden symbol (implies symbol, Duktape 1.x internal string) */ +#define DUK_HSTRING_FLAG_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(4) /* string is a reserved word (non-strict) */ +#define DUK_HSTRING_FLAG_STRICT_RESERVED_WORD DUK_HEAPHDR_USER_FLAG(5) /* string is a reserved word (strict) */ +#define DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS DUK_HEAPHDR_USER_FLAG(6) /* string is 'eval' or 'arguments' */ +#define DUK_HSTRING_FLAG_EXTDATA DUK_HEAPHDR_USER_FLAG(7) /* string data is external (duk_hstring_external) */ +#define DUK_HSTRING_FLAG_PINNED_LITERAL DUK_HEAPHDR_USER_FLAG(8) /* string is a literal, and pinned */ + +#define DUK_HSTRING_HAS_ASCII(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_HAS_ARRIDX(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_HAS_SYMBOL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_HAS_HIDDEN(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_HAS_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_HAS_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_HAS_EXTDATA(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_HAS_PINNED_LITERAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#define DUK_HSTRING_SET_ASCII(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_SET_ARRIDX(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_SET_SYMBOL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_SET_HIDDEN(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_SET_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_SET_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_SET_EXTDATA(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_SET_PINNED_LITERAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#define DUK_HSTRING_CLEAR_ASCII(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ASCII) +#define DUK_HSTRING_CLEAR_ARRIDX(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_ARRIDX) +#define DUK_HSTRING_CLEAR_SYMBOL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_SYMBOL) +#define DUK_HSTRING_CLEAR_HIDDEN(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_HIDDEN) +#define DUK_HSTRING_CLEAR_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_RESERVED_WORD) +#define DUK_HSTRING_CLEAR_STRICT_RESERVED_WORD(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_STRICT_RESERVED_WORD) +#define DUK_HSTRING_CLEAR_EVAL_OR_ARGUMENTS(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS) +#define DUK_HSTRING_CLEAR_EXTDATA(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_EXTDATA) +#define DUK_HSTRING_CLEAR_PINNED_LITERAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HSTRING_FLAG_PINNED_LITERAL) + +#if 0 /* Slightly smaller code without explicit flag, but explicit flag \ + * is very useful when 'clen' is dropped. \ + */ +#define DUK_HSTRING_IS_ASCII(x) (DUK_HSTRING_GET_BYTELEN((x)) == DUK_HSTRING_GET_CHARLEN((x))) #endif -#define DUK_HSTRING_IS_ASCII(x) DUK_HSTRING_HAS_ASCII((x)) /* lazily set! */ -#define DUK_HSTRING_IS_EMPTY(x) (DUK_HSTRING_GET_BYTELEN((x)) == 0) +#define DUK_HSTRING_IS_ASCII(x) DUK_HSTRING_HAS_ASCII((x)) /* lazily set! */ +#define DUK_HSTRING_IS_EMPTY(x) (DUK_HSTRING_GET_BYTELEN((x)) == 0) #if defined(DUK_USE_STRHASH16) -#define DUK_HSTRING_GET_HASH(x) ((x)->hdr.h_flags >> 16) -#define DUK_HSTRING_SET_HASH(x,v) do { \ +#define DUK_HSTRING_GET_HASH(x) ((x)->hdr.h_flags >> 16) +#define DUK_HSTRING_SET_HASH(x, v) \ + do { \ (x)->hdr.h_flags = ((x)->hdr.h_flags & 0x0000ffffUL) | ((v) << 16); \ } while (0) #else -#define DUK_HSTRING_GET_HASH(x) ((x)->hash) -#define DUK_HSTRING_SET_HASH(x,v) do { \ +#define DUK_HSTRING_GET_HASH(x) ((x)->hash) +#define DUK_HSTRING_SET_HASH(x, v) \ + do { \ (x)->hash = (v); \ } while (0) #endif #if defined(DUK_USE_STRLEN16) -#define DUK_HSTRING_GET_BYTELEN(x) ((x)->hdr.h_strextra16) -#define DUK_HSTRING_SET_BYTELEN(x,v) do { \ +#define DUK_HSTRING_GET_BYTELEN(x) ((x)->hdr.h_strextra16) +#define DUK_HSTRING_SET_BYTELEN(x, v) \ + do { \ (x)->hdr.h_strextra16 = (v); \ } while (0) #if defined(DUK_USE_HSTRING_CLEN) -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ (x)->clen16 = (v); \ } while (0) #else -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ - DUK_ASSERT(0); /* should never be called */ \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ + DUK_ASSERT(0); /* should never be called */ \ } while (0) #endif #else -#define DUK_HSTRING_GET_BYTELEN(x) ((x)->blen) -#define DUK_HSTRING_SET_BYTELEN(x,v) do { \ +#define DUK_HSTRING_GET_BYTELEN(x) ((x)->blen) +#define DUK_HSTRING_SET_BYTELEN(x, v) \ + do { \ (x)->blen = (v); \ } while (0) -#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) -#define DUK_HSTRING_SET_CHARLEN(x,v) do { \ +#define DUK_HSTRING_GET_CHARLEN(x) duk_hstring_get_charlen((x)) +#define DUK_HSTRING_SET_CHARLEN(x, v) \ + do { \ (x)->clen = (v); \ } while (0) #endif #if defined(DUK_USE_HSTRING_EXTDATA) -#define DUK_HSTRING_GET_EXTDATA(x) \ - ((x)->extdata) +#define DUK_HSTRING_GET_EXTDATA(x) ((x)->extdata) #define DUK_HSTRING_GET_DATA(x) \ - (DUK_HSTRING_HAS_EXTDATA((x)) ? \ - DUK_HSTRING_GET_EXTDATA((const duk_hstring_external *) (x)) : ((const duk_uint8_t *) ((x) + 1))) + (DUK_HSTRING_HAS_EXTDATA((x)) ? DUK_HSTRING_GET_EXTDATA((const duk_hstring_external *) (x)) : \ + ((const duk_uint8_t *) ((x) + 1))) #else -#define DUK_HSTRING_GET_DATA(x) \ - ((const duk_uint8_t *) ((x) + 1)) +#define DUK_HSTRING_GET_DATA(x) ((const duk_uint8_t *) ((x) + 1)) #endif -#define DUK_HSTRING_GET_DATA_END(x) \ - (DUK_HSTRING_GET_DATA((x)) + (x)->blen) +#define DUK_HSTRING_GET_DATA_END(x) (DUK_HSTRING_GET_DATA((x)) + (x)->blen) /* Marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest * valid). */ -#define DUK_HSTRING_NO_ARRAY_INDEX (0xffffffffUL) +#define DUK_HSTRING_NO_ARRAY_INDEX (0xffffffffUL) #if defined(DUK_USE_HSTRING_ARRIDX) -#define DUK_HSTRING_GET_ARRIDX_FAST(h) ((h)->arridx) -#define DUK_HSTRING_GET_ARRIDX_SLOW(h) ((h)->arridx) +#define DUK_HSTRING_GET_ARRIDX_FAST(h) ((h)->arridx) +#define DUK_HSTRING_GET_ARRIDX_SLOW(h) ((h)->arridx) #else /* Get array index related to string (or return DUK_HSTRING_NO_ARRAY_INDEX); * avoids helper call if string has no array index value. */ -#define DUK_HSTRING_GET_ARRIDX_FAST(h) \ +#define DUK_HSTRING_GET_ARRIDX_FAST(h) \ (DUK_HSTRING_HAS_ARRIDX((h)) ? duk_js_to_arrayindex_hstring_fast_known((h)) : DUK_HSTRING_NO_ARRAY_INDEX) /* Slower but more compact variant. */ -#define DUK_HSTRING_GET_ARRIDX_SLOW(h) \ - (duk_js_to_arrayindex_hstring_fast((h))) +#define DUK_HSTRING_GET_ARRIDX_SLOW(h) (duk_js_to_arrayindex_hstring_fast((h))) #endif /* XXX: these actually fit into duk_hstring */ -#define DUK_SYMBOL_TYPE_HIDDEN 0 -#define DUK_SYMBOL_TYPE_GLOBAL 1 -#define DUK_SYMBOL_TYPE_LOCAL 2 +#define DUK_SYMBOL_TYPE_HIDDEN 0 +#define DUK_SYMBOL_TYPE_GLOBAL 1 +#define DUK_SYMBOL_TYPE_LOCAL 2 #define DUK_SYMBOL_TYPE_WELLKNOWN 3 /* Assertion for duk_hstring validity. */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hstring_assert_valid(duk_hstring *h); -#define DUK_HSTRING_ASSERT_VALID(h) do { duk_hstring_assert_valid((h)); } while (0) +#define DUK_HSTRING_ASSERT_VALID(h) \ + do { \ + duk_hstring_assert_valid((h)); \ + } while (0) #else -#define DUK_HSTRING_ASSERT_VALID(h) do {} while (0) +#define DUK_HSTRING_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -6131,14 +6554,17 @@ * Prototypes */ -DUK_INTERNAL_DECL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, duk_hstring *h, duk_uint_t pos, duk_bool_t surrogate_aware); +DUK_INTERNAL_DECL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, + duk_hstring *h, + duk_uint_t pos, + duk_bool_t surrogate_aware); DUK_INTERNAL_DECL duk_bool_t duk_hstring_equals_ascii_cstring(duk_hstring *h, const char *cstr); DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h); #if !defined(DUK_USE_HSTRING_LAZY_CLEN) DUK_INTERNAL_DECL void duk_hstring_init_charlen(duk_hstring *h); #endif -#endif /* DUK_HSTRING_H_INCLUDED */ +#endif /* DUK_HSTRING_H_INCLUDED */ /* #include duk_hobject.h */ #line 1 "duk_hobject.h" /* @@ -6182,36 +6608,40 @@ /* XXX: some flags are object subtype specific (e.g. common to all function * subtypes, duk_harray, etc) and could be reused for different subtypes. */ -#define DUK_HOBJECT_FLAG_EXTENSIBLE DUK_HEAPHDR_USER_FLAG(0) /* object is extensible */ -#define DUK_HOBJECT_FLAG_CONSTRUCTABLE DUK_HEAPHDR_USER_FLAG(1) /* object is constructable */ -#define DUK_HOBJECT_FLAG_CALLABLE DUK_HEAPHDR_USER_FLAG(2) /* object is callable */ -#define DUK_HOBJECT_FLAG_BOUNDFUNC DUK_HEAPHDR_USER_FLAG(3) /* object established using Function.prototype.bind() */ -#define DUK_HOBJECT_FLAG_COMPFUNC DUK_HEAPHDR_USER_FLAG(4) /* object is a compiled function (duk_hcompfunc) */ -#define DUK_HOBJECT_FLAG_NATFUNC DUK_HEAPHDR_USER_FLAG(5) /* object is a native function (duk_hnatfunc) */ -#define DUK_HOBJECT_FLAG_BUFOBJ DUK_HEAPHDR_USER_FLAG(6) /* object is a buffer object (duk_hbufobj) (always exotic) */ -#define DUK_HOBJECT_FLAG_FASTREFS DUK_HEAPHDR_USER_FLAG(7) /* object has no fields needing DECREF/marking beyond base duk_hobject header */ -#define DUK_HOBJECT_FLAG_ARRAY_PART DUK_HEAPHDR_USER_FLAG(8) /* object has an array part (a_size may still be 0) */ -#define DUK_HOBJECT_FLAG_STRICT DUK_HEAPHDR_USER_FLAG(9) /* function: function object is strict */ -#define DUK_HOBJECT_FLAG_NOTAIL DUK_HEAPHDR_USER_FLAG(10) /* function: function must not be tail called */ -#define DUK_HOBJECT_FLAG_NEWENV DUK_HEAPHDR_USER_FLAG(11) /* function: create new environment when called (see duk_hcompfunc) */ -#define DUK_HOBJECT_FLAG_NAMEBINDING DUK_HEAPHDR_USER_FLAG(12) /* function: create binding for func name (function templates only, used for named function expressions) */ -#define DUK_HOBJECT_FLAG_CREATEARGS DUK_HEAPHDR_USER_FLAG(13) /* function: create an arguments object on function call */ -#define DUK_HOBJECT_FLAG_HAVE_FINALIZER DUK_HEAPHDR_USER_FLAG(14) /* object has a callable (own) finalizer property */ -#define DUK_HOBJECT_FLAG_EXOTIC_ARRAY DUK_HEAPHDR_USER_FLAG(15) /* 'Array' object, array length and index exotic behavior */ -#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ DUK_HEAPHDR_USER_FLAG(16) /* 'String' object, array index exotic behavior */ -#define DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS DUK_HEAPHDR_USER_FLAG(17) /* 'Arguments' object and has arguments exotic behavior (non-strict callee) */ -#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(18) /* 'Proxy' object */ -#define DUK_HOBJECT_FLAG_SPECIAL_CALL DUK_HEAPHDR_USER_FLAG(19) /* special casing in call behavior, for .call(), .apply(), etc. */ +#define DUK_HOBJECT_FLAG_EXTENSIBLE DUK_HEAPHDR_USER_FLAG(0) /* object is extensible */ +#define DUK_HOBJECT_FLAG_CONSTRUCTABLE DUK_HEAPHDR_USER_FLAG(1) /* object is constructable */ +#define DUK_HOBJECT_FLAG_CALLABLE DUK_HEAPHDR_USER_FLAG(2) /* object is callable */ +#define DUK_HOBJECT_FLAG_BOUNDFUNC DUK_HEAPHDR_USER_FLAG(3) /* object established using Function.prototype.bind() */ +#define DUK_HOBJECT_FLAG_COMPFUNC DUK_HEAPHDR_USER_FLAG(4) /* object is a compiled function (duk_hcompfunc) */ +#define DUK_HOBJECT_FLAG_NATFUNC DUK_HEAPHDR_USER_FLAG(5) /* object is a native function (duk_hnatfunc) */ +#define DUK_HOBJECT_FLAG_BUFOBJ DUK_HEAPHDR_USER_FLAG(6) /* object is a buffer object (duk_hbufobj) (always exotic) */ +#define DUK_HOBJECT_FLAG_FASTREFS \ + DUK_HEAPHDR_USER_FLAG(7) /* object has no fields needing DECREF/marking beyond base duk_hobject header */ +#define DUK_HOBJECT_FLAG_ARRAY_PART DUK_HEAPHDR_USER_FLAG(8) /* object has an array part (a_size may still be 0) */ +#define DUK_HOBJECT_FLAG_STRICT DUK_HEAPHDR_USER_FLAG(9) /* function: function object is strict */ +#define DUK_HOBJECT_FLAG_NOTAIL DUK_HEAPHDR_USER_FLAG(10) /* function: function must not be tail called */ +#define DUK_HOBJECT_FLAG_NEWENV DUK_HEAPHDR_USER_FLAG(11) /* function: create new environment when called (see duk_hcompfunc) */ +#define DUK_HOBJECT_FLAG_NAMEBINDING \ + DUK_HEAPHDR_USER_FLAG( \ + 12) /* function: create binding for func name (function templates only, used for named function expressions) */ +#define DUK_HOBJECT_FLAG_CREATEARGS DUK_HEAPHDR_USER_FLAG(13) /* function: create an arguments object on function call */ +#define DUK_HOBJECT_FLAG_HAVE_FINALIZER DUK_HEAPHDR_USER_FLAG(14) /* object has a callable (own) finalizer property */ +#define DUK_HOBJECT_FLAG_EXOTIC_ARRAY DUK_HEAPHDR_USER_FLAG(15) /* 'Array' object, array length and index exotic behavior */ +#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ DUK_HEAPHDR_USER_FLAG(16) /* 'String' object, array index exotic behavior */ +#define DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS \ + DUK_HEAPHDR_USER_FLAG(17) /* 'Arguments' object and has arguments exotic behavior (non-strict callee) */ +#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(18) /* 'Proxy' object */ +#define DUK_HOBJECT_FLAG_SPECIAL_CALL DUK_HEAPHDR_USER_FLAG(19) /* special casing in call behavior, for .call(), .apply(), etc. */ -#define DUK_HOBJECT_FLAG_CLASS_BASE DUK_HEAPHDR_USER_FLAG_NUMBER(20) -#define DUK_HOBJECT_FLAG_CLASS_BITS 5 +#define DUK_HOBJECT_FLAG_CLASS_BASE DUK_HEAPHDR_USER_FLAG_NUMBER(20) +#define DUK_HOBJECT_FLAG_CLASS_BITS 5 -#define DUK_HOBJECT_GET_CLASS_NUMBER(h) \ +#define DUK_HOBJECT_GET_CLASS_NUMBER(h) \ DUK_HEAPHDR_GET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS) -#define DUK_HOBJECT_SET_CLASS_NUMBER(h,v) \ +#define DUK_HOBJECT_SET_CLASS_NUMBER(h, v) \ DUK_HEAPHDR_SET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS, (v)) -#define DUK_HOBJECT_GET_CLASS_MASK(h) \ +#define DUK_HOBJECT_GET_CLASS_MASK(h) \ (1UL << DUK_HEAPHDR_GET_FLAG_RANGE(&(h)->hdr, DUK_HOBJECT_FLAG_CLASS_BASE, DUK_HOBJECT_FLAG_CLASS_BITS)) /* Macro for creating flag initializer from a class number. @@ -6219,256 +6649,239 @@ * a signed integer to an unsigned one; the largest class values * have the highest bit (bit 31) set which causes this. */ -#define DUK_HOBJECT_CLASS_AS_FLAGS(v) (((duk_uint_t) (v)) << DUK_HOBJECT_FLAG_CLASS_BASE) +#define DUK_HOBJECT_CLASS_AS_FLAGS(v) (((duk_uint_t) (v)) << DUK_HOBJECT_FLAG_CLASS_BASE) /* E5 Section 8.6.2 + custom classes */ -#define DUK_HOBJECT_CLASS_NONE 0 -#define DUK_HOBJECT_CLASS_OBJECT 1 -#define DUK_HOBJECT_CLASS_ARRAY 2 -#define DUK_HOBJECT_CLASS_FUNCTION 3 -#define DUK_HOBJECT_CLASS_ARGUMENTS 4 -#define DUK_HOBJECT_CLASS_BOOLEAN 5 -#define DUK_HOBJECT_CLASS_DATE 6 -#define DUK_HOBJECT_CLASS_ERROR 7 -#define DUK_HOBJECT_CLASS_JSON 8 -#define DUK_HOBJECT_CLASS_MATH 9 -#define DUK_HOBJECT_CLASS_NUMBER 10 -#define DUK_HOBJECT_CLASS_REGEXP 11 -#define DUK_HOBJECT_CLASS_STRING 12 -#define DUK_HOBJECT_CLASS_GLOBAL 13 -#define DUK_HOBJECT_CLASS_SYMBOL 14 -#define DUK_HOBJECT_CLASS_OBJENV 15 /* custom */ -#define DUK_HOBJECT_CLASS_DECENV 16 /* custom */ -#define DUK_HOBJECT_CLASS_POINTER 17 /* custom */ -#define DUK_HOBJECT_CLASS_THREAD 18 /* custom; implies DUK_HOBJECT_IS_THREAD */ -#define DUK_HOBJECT_CLASS_BUFOBJ_MIN 19 -#define DUK_HOBJECT_CLASS_ARRAYBUFFER 19 /* implies DUK_HOBJECT_IS_BUFOBJ */ -#define DUK_HOBJECT_CLASS_DATAVIEW 20 -#define DUK_HOBJECT_CLASS_INT8ARRAY 21 -#define DUK_HOBJECT_CLASS_UINT8ARRAY 22 -#define DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY 23 -#define DUK_HOBJECT_CLASS_INT16ARRAY 24 -#define DUK_HOBJECT_CLASS_UINT16ARRAY 25 -#define DUK_HOBJECT_CLASS_INT32ARRAY 26 -#define DUK_HOBJECT_CLASS_UINT32ARRAY 27 -#define DUK_HOBJECT_CLASS_FLOAT32ARRAY 28 -#define DUK_HOBJECT_CLASS_FLOAT64ARRAY 29 -#define DUK_HOBJECT_CLASS_BUFOBJ_MAX 29 -#define DUK_HOBJECT_CLASS_MAX 29 +#define DUK_HOBJECT_CLASS_NONE 0 +#define DUK_HOBJECT_CLASS_OBJECT 1 +#define DUK_HOBJECT_CLASS_ARRAY 2 +#define DUK_HOBJECT_CLASS_FUNCTION 3 +#define DUK_HOBJECT_CLASS_ARGUMENTS 4 +#define DUK_HOBJECT_CLASS_BOOLEAN 5 +#define DUK_HOBJECT_CLASS_DATE 6 +#define DUK_HOBJECT_CLASS_ERROR 7 +#define DUK_HOBJECT_CLASS_JSON 8 +#define DUK_HOBJECT_CLASS_MATH 9 +#define DUK_HOBJECT_CLASS_NUMBER 10 +#define DUK_HOBJECT_CLASS_REGEXP 11 +#define DUK_HOBJECT_CLASS_STRING 12 +#define DUK_HOBJECT_CLASS_GLOBAL 13 +#define DUK_HOBJECT_CLASS_SYMBOL 14 +#define DUK_HOBJECT_CLASS_OBJENV 15 /* custom */ +#define DUK_HOBJECT_CLASS_DECENV 16 /* custom */ +#define DUK_HOBJECT_CLASS_POINTER 17 /* custom */ +#define DUK_HOBJECT_CLASS_THREAD 18 /* custom; implies DUK_HOBJECT_IS_THREAD */ +#define DUK_HOBJECT_CLASS_BUFOBJ_MIN 19 +#define DUK_HOBJECT_CLASS_ARRAYBUFFER 19 /* implies DUK_HOBJECT_IS_BUFOBJ */ +#define DUK_HOBJECT_CLASS_DATAVIEW 20 +#define DUK_HOBJECT_CLASS_INT8ARRAY 21 +#define DUK_HOBJECT_CLASS_UINT8ARRAY 22 +#define DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY 23 +#define DUK_HOBJECT_CLASS_INT16ARRAY 24 +#define DUK_HOBJECT_CLASS_UINT16ARRAY 25 +#define DUK_HOBJECT_CLASS_INT32ARRAY 26 +#define DUK_HOBJECT_CLASS_UINT32ARRAY 27 +#define DUK_HOBJECT_CLASS_FLOAT32ARRAY 28 +#define DUK_HOBJECT_CLASS_FLOAT64ARRAY 29 +#define DUK_HOBJECT_CLASS_BUFOBJ_MAX 29 +#define DUK_HOBJECT_CLASS_MAX 29 /* Class masks. */ -#define DUK_HOBJECT_CMASK_ALL ((1UL << (DUK_HOBJECT_CLASS_MAX + 1)) - 1UL) -#define DUK_HOBJECT_CMASK_NONE (1UL << DUK_HOBJECT_CLASS_NONE) -#define DUK_HOBJECT_CMASK_ARGUMENTS (1UL << DUK_HOBJECT_CLASS_ARGUMENTS) -#define DUK_HOBJECT_CMASK_ARRAY (1UL << DUK_HOBJECT_CLASS_ARRAY) -#define DUK_HOBJECT_CMASK_BOOLEAN (1UL << DUK_HOBJECT_CLASS_BOOLEAN) -#define DUK_HOBJECT_CMASK_DATE (1UL << DUK_HOBJECT_CLASS_DATE) -#define DUK_HOBJECT_CMASK_ERROR (1UL << DUK_HOBJECT_CLASS_ERROR) -#define DUK_HOBJECT_CMASK_FUNCTION (1UL << DUK_HOBJECT_CLASS_FUNCTION) -#define DUK_HOBJECT_CMASK_JSON (1UL << DUK_HOBJECT_CLASS_JSON) -#define DUK_HOBJECT_CMASK_MATH (1UL << DUK_HOBJECT_CLASS_MATH) -#define DUK_HOBJECT_CMASK_NUMBER (1UL << DUK_HOBJECT_CLASS_NUMBER) -#define DUK_HOBJECT_CMASK_OBJECT (1UL << DUK_HOBJECT_CLASS_OBJECT) -#define DUK_HOBJECT_CMASK_REGEXP (1UL << DUK_HOBJECT_CLASS_REGEXP) -#define DUK_HOBJECT_CMASK_STRING (1UL << DUK_HOBJECT_CLASS_STRING) -#define DUK_HOBJECT_CMASK_GLOBAL (1UL << DUK_HOBJECT_CLASS_GLOBAL) -#define DUK_HOBJECT_CMASK_SYMBOL (1UL << DUK_HOBJECT_CLASS_SYMBOL) -#define DUK_HOBJECT_CMASK_OBJENV (1UL << DUK_HOBJECT_CLASS_OBJENV) -#define DUK_HOBJECT_CMASK_DECENV (1UL << DUK_HOBJECT_CLASS_DECENV) -#define DUK_HOBJECT_CMASK_POINTER (1UL << DUK_HOBJECT_CLASS_POINTER) -#define DUK_HOBJECT_CMASK_ARRAYBUFFER (1UL << DUK_HOBJECT_CLASS_ARRAYBUFFER) -#define DUK_HOBJECT_CMASK_DATAVIEW (1UL << DUK_HOBJECT_CLASS_DATAVIEW) -#define DUK_HOBJECT_CMASK_INT8ARRAY (1UL << DUK_HOBJECT_CLASS_INT8ARRAY) -#define DUK_HOBJECT_CMASK_UINT8ARRAY (1UL << DUK_HOBJECT_CLASS_UINT8ARRAY) -#define DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY (1UL << DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY) -#define DUK_HOBJECT_CMASK_INT16ARRAY (1UL << DUK_HOBJECT_CLASS_INT16ARRAY) -#define DUK_HOBJECT_CMASK_UINT16ARRAY (1UL << DUK_HOBJECT_CLASS_UINT16ARRAY) -#define DUK_HOBJECT_CMASK_INT32ARRAY (1UL << DUK_HOBJECT_CLASS_INT32ARRAY) -#define DUK_HOBJECT_CMASK_UINT32ARRAY (1UL << DUK_HOBJECT_CLASS_UINT32ARRAY) -#define DUK_HOBJECT_CMASK_FLOAT32ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT32ARRAY) -#define DUK_HOBJECT_CMASK_FLOAT64ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT64ARRAY) +#define DUK_HOBJECT_CMASK_ALL ((1UL << (DUK_HOBJECT_CLASS_MAX + 1)) - 1UL) +#define DUK_HOBJECT_CMASK_NONE (1UL << DUK_HOBJECT_CLASS_NONE) +#define DUK_HOBJECT_CMASK_ARGUMENTS (1UL << DUK_HOBJECT_CLASS_ARGUMENTS) +#define DUK_HOBJECT_CMASK_ARRAY (1UL << DUK_HOBJECT_CLASS_ARRAY) +#define DUK_HOBJECT_CMASK_BOOLEAN (1UL << DUK_HOBJECT_CLASS_BOOLEAN) +#define DUK_HOBJECT_CMASK_DATE (1UL << DUK_HOBJECT_CLASS_DATE) +#define DUK_HOBJECT_CMASK_ERROR (1UL << DUK_HOBJECT_CLASS_ERROR) +#define DUK_HOBJECT_CMASK_FUNCTION (1UL << DUK_HOBJECT_CLASS_FUNCTION) +#define DUK_HOBJECT_CMASK_JSON (1UL << DUK_HOBJECT_CLASS_JSON) +#define DUK_HOBJECT_CMASK_MATH (1UL << DUK_HOBJECT_CLASS_MATH) +#define DUK_HOBJECT_CMASK_NUMBER (1UL << DUK_HOBJECT_CLASS_NUMBER) +#define DUK_HOBJECT_CMASK_OBJECT (1UL << DUK_HOBJECT_CLASS_OBJECT) +#define DUK_HOBJECT_CMASK_REGEXP (1UL << DUK_HOBJECT_CLASS_REGEXP) +#define DUK_HOBJECT_CMASK_STRING (1UL << DUK_HOBJECT_CLASS_STRING) +#define DUK_HOBJECT_CMASK_GLOBAL (1UL << DUK_HOBJECT_CLASS_GLOBAL) +#define DUK_HOBJECT_CMASK_SYMBOL (1UL << DUK_HOBJECT_CLASS_SYMBOL) +#define DUK_HOBJECT_CMASK_OBJENV (1UL << DUK_HOBJECT_CLASS_OBJENV) +#define DUK_HOBJECT_CMASK_DECENV (1UL << DUK_HOBJECT_CLASS_DECENV) +#define DUK_HOBJECT_CMASK_POINTER (1UL << DUK_HOBJECT_CLASS_POINTER) +#define DUK_HOBJECT_CMASK_ARRAYBUFFER (1UL << DUK_HOBJECT_CLASS_ARRAYBUFFER) +#define DUK_HOBJECT_CMASK_DATAVIEW (1UL << DUK_HOBJECT_CLASS_DATAVIEW) +#define DUK_HOBJECT_CMASK_INT8ARRAY (1UL << DUK_HOBJECT_CLASS_INT8ARRAY) +#define DUK_HOBJECT_CMASK_UINT8ARRAY (1UL << DUK_HOBJECT_CLASS_UINT8ARRAY) +#define DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY (1UL << DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY) +#define DUK_HOBJECT_CMASK_INT16ARRAY (1UL << DUK_HOBJECT_CLASS_INT16ARRAY) +#define DUK_HOBJECT_CMASK_UINT16ARRAY (1UL << DUK_HOBJECT_CLASS_UINT16ARRAY) +#define DUK_HOBJECT_CMASK_INT32ARRAY (1UL << DUK_HOBJECT_CLASS_INT32ARRAY) +#define DUK_HOBJECT_CMASK_UINT32ARRAY (1UL << DUK_HOBJECT_CLASS_UINT32ARRAY) +#define DUK_HOBJECT_CMASK_FLOAT32ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT32ARRAY) +#define DUK_HOBJECT_CMASK_FLOAT64ARRAY (1UL << DUK_HOBJECT_CLASS_FLOAT64ARRAY) #define DUK_HOBJECT_CMASK_ALL_BUFOBJS \ - (DUK_HOBJECT_CMASK_ARRAYBUFFER | \ - DUK_HOBJECT_CMASK_DATAVIEW | \ - DUK_HOBJECT_CMASK_INT8ARRAY | \ - DUK_HOBJECT_CMASK_UINT8ARRAY | \ - DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY | \ - DUK_HOBJECT_CMASK_INT16ARRAY | \ - DUK_HOBJECT_CMASK_UINT16ARRAY | \ - DUK_HOBJECT_CMASK_INT32ARRAY | \ - DUK_HOBJECT_CMASK_UINT32ARRAY | \ - DUK_HOBJECT_CMASK_FLOAT32ARRAY | \ + (DUK_HOBJECT_CMASK_ARRAYBUFFER | DUK_HOBJECT_CMASK_DATAVIEW | DUK_HOBJECT_CMASK_INT8ARRAY | DUK_HOBJECT_CMASK_UINT8ARRAY | \ + DUK_HOBJECT_CMASK_UINT8CLAMPEDARRAY | DUK_HOBJECT_CMASK_INT16ARRAY | DUK_HOBJECT_CMASK_UINT16ARRAY | \ + DUK_HOBJECT_CMASK_INT32ARRAY | DUK_HOBJECT_CMASK_UINT32ARRAY | DUK_HOBJECT_CMASK_FLOAT32ARRAY | \ DUK_HOBJECT_CMASK_FLOAT64ARRAY) -#define DUK_HOBJECT_IS_OBJENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_OBJENV) -#define DUK_HOBJECT_IS_DECENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_DECENV) -#define DUK_HOBJECT_IS_ENV(h) (DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_DECENV((h))) -#define DUK_HOBJECT_IS_ARRAY(h) DUK_HOBJECT_HAS_EXOTIC_ARRAY((h)) /* Rely on class Array <=> exotic Array */ -#define DUK_HOBJECT_IS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_IS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_IS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_OBJENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_OBJENV) +#define DUK_HOBJECT_IS_DECENV(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_DECENV) +#define DUK_HOBJECT_IS_ENV(h) (DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_DECENV((h))) +#define DUK_HOBJECT_IS_ARRAY(h) DUK_HOBJECT_HAS_EXOTIC_ARRAY((h)) /* Rely on class Array <=> exotic Array */ +#define DUK_HOBJECT_IS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_IS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_IS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_IS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_IS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #else -#define DUK_HOBJECT_IS_BUFOBJ(h) 0 +#define DUK_HOBJECT_IS_BUFOBJ(h) 0 #endif -#define DUK_HOBJECT_IS_THREAD(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_THREAD) +#define DUK_HOBJECT_IS_THREAD(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_THREAD) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_IS_PROXY(h) DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ((h)) +#define DUK_HOBJECT_IS_PROXY(h) DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ((h)) #else -#define DUK_HOBJECT_IS_PROXY(h) 0 +#define DUK_HOBJECT_IS_PROXY(h) 0 #endif -#define DUK_HOBJECT_IS_NONBOUND_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_COMPFUNC | \ - DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_NONBOUND_FUNCTION(h) \ + DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC | DUK_HOBJECT_FLAG_NATFUNC) -#define DUK_HOBJECT_IS_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \ - DUK_HOBJECT_FLAG_BOUNDFUNC | \ - DUK_HOBJECT_FLAG_COMPFUNC | \ - DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_IS_FUNCTION(h) \ + DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC | DUK_HOBJECT_FLAG_COMPFUNC | DUK_HOBJECT_FLAG_NATFUNC) -#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HOBJECT_HAS_CALLABLE((h)) +#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HOBJECT_HAS_CALLABLE((h)) /* Object has any exotic behavior(s). */ -#define DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS | \ - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ - DUK_HOBJECT_FLAG_BUFOBJ | \ - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) -#define DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS) +#define DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS \ + (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ + DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS) /* Object has any virtual properties (not counting Proxy behavior). */ -#define DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \ - DUK_HOBJECT_FLAG_BUFOBJ) -#define DUK_HOBJECT_HAS_VIRTUAL_PROPERTIES(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS) - -#define DUK_HOBJECT_HAS_EXTENSIBLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_HAS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_HAS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_HAS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_HAS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS \ + (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_HAS_VIRTUAL_PROPERTIES(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS) + +#define DUK_HOBJECT_HAS_EXTENSIBLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_HAS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_HAS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_HAS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_HAS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_HAS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_HAS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #else -#define DUK_HOBJECT_HAS_BUFOBJ(h) 0 +#define DUK_HOBJECT_HAS_BUFOBJ(h) 0 #endif -#define DUK_HOBJECT_HAS_FASTREFS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_HAS_ARRAY_PART(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_HAS_STRICT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_HAS_NOTAIL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_HAS_NEWENV(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_HAS_NAMEBINDING(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_HAS_CREATEARGS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_HAS_HAVE_FINALIZER(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_HAS_EXOTIC_ARRAY(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_HAS_FASTREFS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_HAS_ARRAY_PART(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_HAS_STRICT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_HAS_NOTAIL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_HAS_NEWENV(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_HAS_NAMEBINDING(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_HAS_CREATEARGS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_HAS_HAVE_FINALIZER(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_HAS_EXOTIC_ARRAY(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #else -#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) 0 +#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) 0 #endif -#define DUK_HOBJECT_HAS_SPECIAL_CALL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) +#define DUK_HOBJECT_HAS_SPECIAL_CALL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) -#define DUK_HOBJECT_SET_EXTENSIBLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_SET_CONSTRUCTABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_SET_CALLABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_SET_BOUNDFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_SET_COMPFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_SET_NATFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_SET_EXTENSIBLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_SET_CONSTRUCTABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_SET_CALLABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_SET_BOUNDFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_SET_COMPFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_SET_NATFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_SET_BUFOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_SET_BUFOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #endif -#define DUK_HOBJECT_SET_FASTREFS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_SET_ARRAY_PART(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_SET_STRICT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_SET_NOTAIL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_SET_NEWENV(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_SET_NAMEBINDING(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_SET_CREATEARGS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_SET_HAVE_FINALIZER(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_SET_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_SET_FASTREFS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_SET_ARRAY_PART(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_SET_STRICT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_SET_NOTAIL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_SET_NEWENV(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_SET_NAMEBINDING(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_SET_CREATEARGS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_SET_HAVE_FINALIZER(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_SET_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_SET_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_SET_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #endif -#define DUK_HOBJECT_SET_SPECIAL_CALL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) +#define DUK_HOBJECT_SET_SPECIAL_CALL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) -#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) -#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) -#define DUK_HOBJECT_CLEAR_CALLABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) -#define DUK_HOBJECT_CLEAR_BOUNDFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) -#define DUK_HOBJECT_CLEAR_COMPFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) -#define DUK_HOBJECT_CLEAR_NATFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) +#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE) +#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE) +#define DUK_HOBJECT_CLEAR_CALLABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE) +#define DUK_HOBJECT_CLEAR_BOUNDFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC) +#define DUK_HOBJECT_CLEAR_COMPFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC) +#define DUK_HOBJECT_CLEAR_NATFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC) #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK_HOBJECT_CLEAR_BUFOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) +#define DUK_HOBJECT_CLEAR_BUFOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ) #endif -#define DUK_HOBJECT_CLEAR_FASTREFS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) -#define DUK_HOBJECT_CLEAR_ARRAY_PART(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) -#define DUK_HOBJECT_CLEAR_STRICT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) -#define DUK_HOBJECT_CLEAR_NOTAIL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) -#define DUK_HOBJECT_CLEAR_NEWENV(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) -#define DUK_HOBJECT_CLEAR_NAMEBINDING(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) -#define DUK_HOBJECT_CLEAR_CREATEARGS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) -#define DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) -#define DUK_HOBJECT_CLEAR_EXOTIC_ARRAY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) -#define DUK_HOBJECT_CLEAR_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) -#define DUK_HOBJECT_CLEAR_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) +#define DUK_HOBJECT_CLEAR_FASTREFS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS) +#define DUK_HOBJECT_CLEAR_ARRAY_PART(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART) +#define DUK_HOBJECT_CLEAR_STRICT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT) +#define DUK_HOBJECT_CLEAR_NOTAIL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NOTAIL) +#define DUK_HOBJECT_CLEAR_NEWENV(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NEWENV) +#define DUK_HOBJECT_CLEAR_NAMEBINDING(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NAMEBINDING) +#define DUK_HOBJECT_CLEAR_CREATEARGS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CREATEARGS) +#define DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_HAVE_FINALIZER) +#define DUK_HOBJECT_CLEAR_EXOTIC_ARRAY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY) +#define DUK_HOBJECT_CLEAR_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ) +#define DUK_HOBJECT_CLEAR_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS) #if defined(DUK_USE_ES6_PROXY) -#define DUK_HOBJECT_CLEAR_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) +#define DUK_HOBJECT_CLEAR_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ) #endif -#define DUK_HOBJECT_CLEAR_SPECIAL_CALL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) +#define DUK_HOBJECT_CLEAR_SPECIAL_CALL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL) /* Object can/cannot use FASTREFS, i.e. has no strong reference fields beyond * duk_hobject base header. This is used just for asserts so doesn't need to * be optimized. */ #define DUK_HOBJECT_PROHIBITS_FASTREFS(h) \ - (DUK_HOBJECT_IS_COMPFUNC((h)) || DUK_HOBJECT_IS_DECENV((h)) || DUK_HOBJECT_IS_OBJENV((h)) || \ - DUK_HOBJECT_IS_BUFOBJ((h)) || DUK_HOBJECT_IS_THREAD((h)) || DUK_HOBJECT_IS_PROXY((h)) || \ - DUK_HOBJECT_IS_BOUNDFUNC((h))) + (DUK_HOBJECT_IS_COMPFUNC((h)) || DUK_HOBJECT_IS_DECENV((h)) || DUK_HOBJECT_IS_OBJENV((h)) || DUK_HOBJECT_IS_BUFOBJ((h)) || \ + DUK_HOBJECT_IS_THREAD((h)) || DUK_HOBJECT_IS_PROXY((h)) || DUK_HOBJECT_IS_BOUNDFUNC((h))) #define DUK_HOBJECT_ALLOWS_FASTREFS(h) (!DUK_HOBJECT_PROHIBITS_FASTREFS((h))) /* Flags used for property attributes in duk_propdesc and packed flags. * Must fit into 8 bits. */ -#define DUK_PROPDESC_FLAG_WRITABLE (1U << 0) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_ENUMERABLE (1U << 1) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_CONFIGURABLE (1U << 2) /* E5 Section 8.6.1 */ -#define DUK_PROPDESC_FLAG_ACCESSOR (1U << 3) /* accessor */ -#define DUK_PROPDESC_FLAG_VIRTUAL (1U << 4) /* property is virtual: used in duk_propdesc, never stored - * (used by e.g. buffer virtual properties) - */ -#define DUK_PROPDESC_FLAGS_MASK (DUK_PROPDESC_FLAG_WRITABLE | \ - DUK_PROPDESC_FLAG_ENUMERABLE | \ - DUK_PROPDESC_FLAG_CONFIGURABLE | \ - DUK_PROPDESC_FLAG_ACCESSOR) +#define DUK_PROPDESC_FLAG_WRITABLE (1U << 0) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_ENUMERABLE (1U << 1) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_CONFIGURABLE (1U << 2) /* E5 Section 8.6.1 */ +#define DUK_PROPDESC_FLAG_ACCESSOR (1U << 3) /* accessor */ +#define DUK_PROPDESC_FLAG_VIRTUAL \ + (1U << 4) /* property is virtual: used in duk_propdesc, never stored \ + * (used by e.g. buffer virtual properties) \ + */ +#define DUK_PROPDESC_FLAGS_MASK \ + (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE | DUK_PROPDESC_FLAG_ACCESSOR) /* Additional flags which are passed in the same flags argument as property * flags but are not stored in object properties. */ -#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1U << 4) /* internal define property: skip write silently if exists */ +#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1U << 4) /* internal define property: skip write silently if exists */ /* Convenience defines for property attributes. */ -#define DUK_PROPDESC_FLAGS_NONE 0 -#define DUK_PROPDESC_FLAGS_W (DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_PROPDESC_FLAGS_E (DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_PROPDESC_FLAGS_C (DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_WE (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_PROPDESC_FLAGS_WC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_EC (DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_PROPDESC_FLAGS_WEC (DUK_PROPDESC_FLAG_WRITABLE | \ - DUK_PROPDESC_FLAG_ENUMERABLE | \ - DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_NONE 0 +#define DUK_PROPDESC_FLAGS_W (DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_PROPDESC_FLAGS_E (DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_PROPDESC_FLAGS_C (DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_WE (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_PROPDESC_FLAGS_WC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_EC (DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_PROPDESC_FLAGS_WEC (DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE) /* Flags for duk_hobject_get_own_propdesc() and variants. */ -#define DUK_GETDESC_FLAG_PUSH_VALUE (1U << 0) /* push value to stack */ -#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1U << 1) /* don't throw for prototype loop */ +#define DUK_GETDESC_FLAG_PUSH_VALUE (1U << 0) /* push value to stack */ +#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1U << 1) /* don't throw for prototype loop */ /* * Macro for object validity check @@ -6478,9 +6891,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hobject_assert_valid(duk_hobject *h); -#define DUK_HOBJECT_ASSERT_VALID(h) do { duk_hobject_assert_valid((h)); } while (0) +#define DUK_HOBJECT_ASSERT_VALID(h) \ + do { \ + duk_hobject_assert_valid((h)); \ + } while (0) #else -#define DUK_HOBJECT_ASSERT_VALID(h) do {} while (0) +#define DUK_HOBJECT_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -6488,52 +6906,41 @@ */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_GET_PROPS(heap,h) \ - ((duk_uint8_t *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (h))->h_extra16)) -#define DUK_HOBJECT_SET_PROPS(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROPS(heap, h) ((duk_uint8_t *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (h))->h_extra16)) +#define DUK_HOBJECT_SET_PROPS(heap, h, x) \ + do { \ ((duk_heaphdr *) (h))->h_extra16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (x)); \ } while (0) #else -#define DUK_HOBJECT_GET_PROPS(heap,h) \ - ((h)->props) -#define DUK_HOBJECT_SET_PROPS(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROPS(heap, h) ((h)->props) +#define DUK_HOBJECT_SET_PROPS(heap, h, x) \ + do { \ (h)->props = (duk_uint8_t *) (x); \ } while (0) #endif #if defined(DUK_USE_HOBJECT_LAYOUT_1) /* LAYOUT 1 */ -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_hstring *) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) \ + ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_hstring *))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + (n_arr) * sizeof(duk_tval) + \ + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_k) = (duk_hstring **) (void *) (p_base); \ (set_e_pv) = (duk_propvalue *) (void *) ((set_e_k) + (n_ent)); \ (set_e_f) = (duk_uint8_t *) (void *) ((set_e_pv) + (n_ent)); \ @@ -6551,85 +6958,57 @@ #else #error invalid DUK_USE_ALIGN_BY #endif -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ - DUK_HOBJECT_E_FLAG_PADDING((n_ent)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) \ + ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_hstring *) + sizeof(duk_propvalue)))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * \ + (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + \ + DUK_HOBJECT_E_FLAG_PADDING(DUK_HOBJECT_GET_ESIZE((h))) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_hstring *) + sizeof(duk_propvalue) + sizeof(duk_uint8_t)) + DUK_HOBJECT_E_FLAG_PADDING((n_ent)) + \ + (n_arr) * sizeof(duk_tval) + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_pv) = (duk_propvalue *) (void *) (p_base); \ (set_e_k) = (duk_hstring **) (void *) ((set_e_pv) + (n_ent)); \ (set_e_f) = (duk_uint8_t *) (void *) ((set_e_k) + (n_ent)); \ - (set_a) = (duk_tval *) (void *) (((duk_uint8_t *) (set_e_f)) + \ - sizeof(duk_uint8_t) * (n_ent) + \ + (set_a) = (duk_tval *) (void *) (((duk_uint8_t *) (set_e_f)) + sizeof(duk_uint8_t) * (n_ent) + \ DUK_HOBJECT_E_FLAG_PADDING((n_ent))); \ (set_h) = (duk_uint32_t *) (void *) ((set_a) + (n_arr)); \ } while (0) #elif defined(DUK_USE_HOBJECT_LAYOUT_3) /* LAYOUT 3 */ -#define DUK_HOBJECT_E_GET_KEY_BASE(heap,h) \ - ((duk_hstring **) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_E_GET_VALUE_BASE(heap,h) \ - ((duk_propvalue *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) \ - )) -#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap,h) \ - ((duk_uint8_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) + \ - DUK_HOBJECT_GET_HSIZE((h)) * sizeof(duk_uint32_t) \ - )) -#define DUK_HOBJECT_A_GET_BASE(heap,h) \ - ((duk_tval *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) \ - )) -#define DUK_HOBJECT_H_GET_BASE(heap,h) \ - ((duk_uint32_t *) (void *) ( \ - DUK_HOBJECT_GET_PROPS((heap), (h)) + \ - DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ - DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) \ - )) -#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent,n_arr,n_hash) \ - ( \ - (n_ent) * (sizeof(duk_propvalue) + sizeof(duk_hstring *) + sizeof(duk_uint8_t)) + \ - (n_arr) * sizeof(duk_tval) + \ - (n_hash) * sizeof(duk_uint32_t) \ - ) -#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base,set_e_k,set_e_pv,set_e_f,set_a,set_h,n_ent,n_arr,n_hash) do { \ +#define DUK_HOBJECT_E_GET_KEY_BASE(heap, h) \ + ((duk_hstring **) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_E_GET_VALUE_BASE(heap, h) ((duk_propvalue *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)))) +#define DUK_HOBJECT_E_GET_FLAGS_BASE(heap, h) \ + ((duk_uint8_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval) + \ + DUK_HOBJECT_GET_HSIZE((h)) * sizeof(duk_uint32_t))) +#define DUK_HOBJECT_A_GET_BASE(heap, h) \ + ((duk_tval *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + DUK_HOBJECT_GET_ESIZE((h)) * sizeof(duk_propvalue))) +#define DUK_HOBJECT_H_GET_BASE(heap, h) \ + ((duk_uint32_t *) (void *) (DUK_HOBJECT_GET_PROPS((heap), (h)) + \ + DUK_HOBJECT_GET_ESIZE((h)) * (sizeof(duk_propvalue) + sizeof(duk_hstring *)) + \ + DUK_HOBJECT_GET_ASIZE((h)) * sizeof(duk_tval))) +#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash) \ + ((n_ent) * (sizeof(duk_propvalue) + sizeof(duk_hstring *) + sizeof(duk_uint8_t)) + (n_arr) * sizeof(duk_tval) + \ + (n_hash) * sizeof(duk_uint32_t)) +#define DUK_HOBJECT_P_SET_REALLOC_PTRS(p_base, set_e_k, set_e_pv, set_e_f, set_a, set_h, n_ent, n_arr, n_hash) \ + do { \ (set_e_pv) = (duk_propvalue *) (void *) (p_base); \ (set_a) = (duk_tval *) (void *) ((set_e_pv) + (n_ent)); \ (set_e_k) = (duk_hstring **) (void *) ((set_a) + (n_arr)); \ @@ -6638,85 +7017,99 @@ } while (0) #else #error invalid hobject layout defines -#endif /* hobject property layout */ +#endif /* hobject property layout */ #define DUK_HOBJECT_P_ALLOC_SIZE(h) \ DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE((h)), DUK_HOBJECT_GET_ASIZE((h)), DUK_HOBJECT_GET_HSIZE((h))) -#define DUK_HOBJECT_E_GET_KEY(heap,h,i) (DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_KEY_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE(heap,h,i) (DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_VALUE_TVAL(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) -#define DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) -#define DUK_HOBJECT_E_GET_VALUE_GETTER(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) -#define DUK_HOBJECT_E_GET_VALUE_GETTER_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) -#define DUK_HOBJECT_E_GET_VALUE_SETTER(heap,h,i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) -#define DUK_HOBJECT_E_GET_VALUE_SETTER_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) -#define DUK_HOBJECT_E_GET_FLAGS(heap,h,i) (DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_GET_FLAGS_PTR(heap,h,i) (&DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) -#define DUK_HOBJECT_A_GET_VALUE(heap,h,i) (DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_A_GET_VALUE_PTR(heap,h,i) (&DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_H_GET_INDEX(heap,h,i) (DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_H_GET_INDEX_PTR(heap,h,i) (&DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_KEY(heap, h, i) (DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_KEY_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_KEY_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE(heap, h, i) (DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_VALUE_TVAL(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) +#define DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v) +#define DUK_HOBJECT_E_GET_VALUE_GETTER(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) +#define DUK_HOBJECT_E_GET_VALUE_GETTER_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get) +#define DUK_HOBJECT_E_GET_VALUE_SETTER(heap, h, i) (DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) +#define DUK_HOBJECT_E_GET_VALUE_SETTER_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set) +#define DUK_HOBJECT_E_GET_FLAGS(heap, h, i) (DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) +#define DUK_HOBJECT_E_GET_FLAGS_PTR(heap, h, i) (&DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i)) +#define DUK_HOBJECT_A_GET_VALUE(heap, h, i) (DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_A_GET_VALUE_PTR(heap, h, i) (&DUK_HOBJECT_A_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_H_GET_INDEX(heap, h, i) (DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) +#define DUK_HOBJECT_H_GET_INDEX_PTR(heap, h, i) (&DUK_HOBJECT_H_GET_BASE((heap), (h))(i)) -#define DUK_HOBJECT_E_SET_KEY(heap,h,i,k) do { \ +#define DUK_HOBJECT_E_SET_KEY(heap, h, i, k) \ + do { \ DUK_HOBJECT_E_GET_KEY((heap), (h), (i)) = (k); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_TVAL(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_TVAL(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).v = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_GETTER(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_GETTER(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.get = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_VALUE_SETTER(heap,h,i,v) do { \ +#define DUK_HOBJECT_E_SET_VALUE_SETTER(heap, h, i, v) \ + do { \ DUK_HOBJECT_E_GET_VALUE((heap), (h), (i)).a.set = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_FLAGS(heap,h,i,f) do { \ +#define DUK_HOBJECT_E_SET_FLAGS(heap, h, i, f) \ + do { \ DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) = (duk_uint8_t) (f); \ } while (0) -#define DUK_HOBJECT_A_SET_VALUE(heap,h,i,v) do { \ +#define DUK_HOBJECT_A_SET_VALUE(heap, h, i, v) \ + do { \ DUK_HOBJECT_A_GET_VALUE((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_A_SET_VALUE_TVAL(heap,h,i,v) \ - DUK_HOBJECT_A_SET_VALUE((heap), (h), (i), (v)) /* alias for above */ -#define DUK_HOBJECT_H_SET_INDEX(heap,h,i,v) do { \ +#define DUK_HOBJECT_A_SET_VALUE_TVAL(heap, h, i, v) DUK_HOBJECT_A_SET_VALUE((heap), (h), (i), (v)) /* alias for above */ +#define DUK_HOBJECT_H_SET_INDEX(heap, h, i, v) \ + do { \ DUK_HOBJECT_H_GET_INDEX((heap), (h), (i)) = (v); \ } while (0) -#define DUK_HOBJECT_E_SET_FLAG_BITS(heap,h,i,mask) do { \ +#define DUK_HOBJECT_E_SET_FLAG_BITS(heap, h, i, mask) \ + do { \ DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i) |= (mask); \ } while (0) -#define DUK_HOBJECT_E_CLEAR_FLAG_BITS(heap,h,i,mask) do { \ +#define DUK_HOBJECT_E_CLEAR_FLAG_BITS(heap, h, i, mask) \ + do { \ DUK_HOBJECT_E_GET_FLAGS_BASE((heap), (h))(i) &= ~(mask); \ } while (0) -#define DUK_HOBJECT_E_SLOT_IS_WRITABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_WRITABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) -#define DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap,h,i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ACCESSOR) != 0) - -#define DUK_HOBJECT_E_SLOT_SET_WRITABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_HOBJECT_E_SLOT_SET_ENUMERABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_HOBJECT_E_SLOT_SET_CONFIGURABLE(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_HOBJECT_E_SLOT_SET_ACCESSOR(heap,h,i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ACCESSOR) - -#define DUK_HOBJECT_E_SLOT_CLEAR_WRITABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_WRITABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_ENUMERABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ENUMERABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_CONFIGURABLE(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_CONFIGURABLE) -#define DUK_HOBJECT_E_SLOT_CLEAR_ACCESSOR(heap,h,i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i),DUK_PROPDESC_FLAG_ACCESSOR) - -#define DUK_PROPDESC_IS_WRITABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_WRITABLE) != 0) -#define DUK_PROPDESC_IS_ENUMERABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) -#define DUK_PROPDESC_IS_CONFIGURABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) -#define DUK_PROPDESC_IS_ACCESSOR(p) (((p)->flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0) +#define DUK_HOBJECT_E_SLOT_IS_WRITABLE(heap, h, i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_WRITABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_ENUMERABLE(heap, h, i) \ + ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(heap, h, i) \ + ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) +#define DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap, h, i) ((DUK_HOBJECT_E_GET_FLAGS((heap), (h), (i)) & DUK_PROPDESC_FLAG_ACCESSOR) != 0) + +#define DUK_HOBJECT_E_SLOT_SET_WRITABLE(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_HOBJECT_E_SLOT_SET_ENUMERABLE(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_HOBJECT_E_SLOT_SET_CONFIGURABLE(heap, h, i) \ + DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_HOBJECT_E_SLOT_SET_ACCESSOR(heap, h, i) DUK_HOBJECT_E_SET_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ACCESSOR) + +#define DUK_HOBJECT_E_SLOT_CLEAR_WRITABLE(heap, h, i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_WRITABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_ENUMERABLE(heap, h, i) \ + DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ENUMERABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_CONFIGURABLE(heap, h, i) \ + DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_CONFIGURABLE) +#define DUK_HOBJECT_E_SLOT_CLEAR_ACCESSOR(heap, h, i) DUK_HOBJECT_E_CLEAR_FLAG_BITS((heap), (h), (i), DUK_PROPDESC_FLAG_ACCESSOR) + +#define DUK_PROPDESC_IS_WRITABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_WRITABLE) != 0) +#define DUK_PROPDESC_IS_ENUMERABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_ENUMERABLE) != 0) +#define DUK_PROPDESC_IS_CONFIGURABLE(p) (((p)->flags & DUK_PROPDESC_FLAG_CONFIGURABLE) != 0) +#define DUK_PROPDESC_IS_ACCESSOR(p) (((p)->flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0) -#define DUK_HOBJECT_HASHIDX_UNUSED 0xffffffffUL -#define DUK_HOBJECT_HASHIDX_DELETED 0xfffffffeUL +#define DUK_HOBJECT_HASHIDX_UNUSED 0xffffffffUL +#define DUK_HOBJECT_HASHIDX_DELETED 0xfffffffeUL /* * Macros for accessing size fields @@ -6724,33 +7117,63 @@ #if defined(DUK_USE_OBJSIZES16) #define DUK_HOBJECT_GET_ESIZE(h) ((h)->e_size16) -#define DUK_HOBJECT_SET_ESIZE(h,v) do { (h)->e_size16 = (v); } while (0) +#define DUK_HOBJECT_SET_ESIZE(h, v) \ + do { \ + (h)->e_size16 = (v); \ + } while (0) #define DUK_HOBJECT_GET_ENEXT(h) ((h)->e_next16) -#define DUK_HOBJECT_SET_ENEXT(h,v) do { (h)->e_next16 = (v); } while (0) +#define DUK_HOBJECT_SET_ENEXT(h, v) \ + do { \ + (h)->e_next16 = (v); \ + } while (0) #define DUK_HOBJECT_POSTINC_ENEXT(h) ((h)->e_next16++) -#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size16) -#define DUK_HOBJECT_SET_ASIZE(h,v) do { (h)->a_size16 = (v); } while (0) +#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size16) +#define DUK_HOBJECT_SET_ASIZE(h, v) \ + do { \ + (h)->a_size16 = (v); \ + } while (0) #if defined(DUK_USE_HOBJECT_HASH_PART) #define DUK_HOBJECT_GET_HSIZE(h) ((h)->h_size16) -#define DUK_HOBJECT_SET_HSIZE(h,v) do { (h)->h_size16 = (v); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + (h)->h_size16 = (v); \ + } while (0) #else #define DUK_HOBJECT_GET_HSIZE(h) 0 -#define DUK_HOBJECT_SET_HSIZE(h,v) do { DUK_ASSERT((v) == 0); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + DUK_ASSERT((v) == 0); \ + } while (0) #endif #else #define DUK_HOBJECT_GET_ESIZE(h) ((h)->e_size) -#define DUK_HOBJECT_SET_ESIZE(h,v) do { (h)->e_size = (v); } while (0) +#define DUK_HOBJECT_SET_ESIZE(h, v) \ + do { \ + (h)->e_size = (v); \ + } while (0) #define DUK_HOBJECT_GET_ENEXT(h) ((h)->e_next) -#define DUK_HOBJECT_SET_ENEXT(h,v) do { (h)->e_next = (v); } while (0) +#define DUK_HOBJECT_SET_ENEXT(h, v) \ + do { \ + (h)->e_next = (v); \ + } while (0) #define DUK_HOBJECT_POSTINC_ENEXT(h) ((h)->e_next++) -#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size) -#define DUK_HOBJECT_SET_ASIZE(h,v) do { (h)->a_size = (v); } while (0) +#define DUK_HOBJECT_GET_ASIZE(h) ((h)->a_size) +#define DUK_HOBJECT_SET_ASIZE(h, v) \ + do { \ + (h)->a_size = (v); \ + } while (0) #if defined(DUK_USE_HOBJECT_HASH_PART) #define DUK_HOBJECT_GET_HSIZE(h) ((h)->h_size) -#define DUK_HOBJECT_SET_HSIZE(h,v) do { (h)->h_size = (v); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + (h)->h_size = (v); \ + } while (0) #else #define DUK_HOBJECT_GET_HSIZE(h) 0 -#define DUK_HOBJECT_SET_HSIZE(h,v) do { DUK_ASSERT((v) == 0); } while (0) +#define DUK_HOBJECT_SET_HSIZE(h, v) \ + do { \ + DUK_ASSERT((v) == 0); \ + } while (0) #endif #endif @@ -6761,46 +7184,44 @@ /* Maximum prototype traversal depth. Sanity limit which handles e.g. * prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4). */ -#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY 10000L +#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY 10000L /* * ECMAScript Class */ /* range check not necessary because all 4-bit values are mapped */ -#define DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(n) duk_class_number_to_stridx(n) +#define DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(n) duk_class_number_to_stridx(n) -#define DUK_HOBJECT_GET_CLASS_STRING(heap,h) \ - DUK_HEAP_GET_STRING( \ - (heap), \ - DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(DUK_HOBJECT_GET_CLASS_NUMBER((h))) \ - ) +#define DUK_HOBJECT_GET_CLASS_STRING(heap, h) \ + DUK_HEAP_GET_STRING((heap), DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(DUK_HOBJECT_GET_CLASS_NUMBER((h)))) /* * Macros for property handling */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_GET_PROTOTYPE(heap,h) \ - ((duk_hobject *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->prototype16)) -#define DUK_HOBJECT_SET_PROTOTYPE(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROTOTYPE(heap, h) ((duk_hobject *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->prototype16)) +#define DUK_HOBJECT_SET_PROTOTYPE(heap, h, x) \ + do { \ (h)->prototype16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (x)); \ } while (0) #else -#define DUK_HOBJECT_GET_PROTOTYPE(heap,h) \ - ((h)->prototype) -#define DUK_HOBJECT_SET_PROTOTYPE(heap,h,x) do { \ +#define DUK_HOBJECT_GET_PROTOTYPE(heap, h) ((h)->prototype) +#define DUK_HOBJECT_SET_PROTOTYPE(heap, h, x) \ + do { \ (h)->prototype = (x); \ } while (0) #endif /* Set prototype, DECREF earlier value, INCREF new value (tolerating NULLs). */ -#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr,h,p) duk_hobject_set_prototype_updref((thr), (h), (p)) +#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, p) duk_hobject_set_prototype_updref((thr), (h), (p)) /* Set initial prototype, assume NULL previous prototype, INCREF new value, * tolerate NULL. */ -#define DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr,h,proto) do { \ +#define DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, h, proto) \ + do { \ duk_hthread *duk__thr = (thr); \ duk_hobject *duk__obj = (h); \ duk_hobject *duk__proto = (proto); \ @@ -6815,9 +7236,9 @@ */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap,h) duk_hobject_has_finalizer_fast_raw((heap), (h)) +#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap, h) duk_hobject_has_finalizer_fast_raw((heap), (h)) #else -#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap,h) duk_hobject_has_finalizer_fast_raw((h)) +#define DUK_HOBJECT_HAS_FINALIZER_FAST(heap, h) duk_hobject_has_finalizer_fast_raw((h)) #endif /* @@ -6831,18 +7252,18 @@ * so anything above 0x80000000 will cause trouble now. */ #if defined(DUK_USE_OBJSIZES16) -#define DUK_HOBJECT_MAX_PROPERTIES 0x0000ffffUL +#define DUK_HOBJECT_MAX_PROPERTIES 0x0000ffffUL #else -#define DUK_HOBJECT_MAX_PROPERTIES 0x3fffffffUL /* 2**30-1 ~= 1G properties */ +#define DUK_HOBJECT_MAX_PROPERTIES 0x3fffffffUL /* 2**30-1 ~= 1G properties */ #endif /* internal align target for props allocation, must be 2*n for some n */ #if (DUK_USE_ALIGN_BY == 4) -#define DUK_HOBJECT_ALIGN_TARGET 4 +#define DUK_HOBJECT_ALIGN_TARGET 4 #elif (DUK_USE_ALIGN_BY == 8) -#define DUK_HOBJECT_ALIGN_TARGET 8 +#define DUK_HOBJECT_ALIGN_TARGET 8 #elif (DUK_USE_ALIGN_BY == 1) -#define DUK_HOBJECT_ALIGN_TARGET 1 +#define DUK_HOBJECT_ALIGN_TARGET 1 #else #error invalid DUK_USE_ALIGN_BY #endif @@ -6851,10 +7272,10 @@ * PC-to-line constants */ -#define DUK_PC2LINE_SKIP 64 +#define DUK_PC2LINE_SKIP 64 /* maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes */ -#define DUK_PC2LINE_MAX_DIFF_LENGTH (((DUK_PC2LINE_SKIP - 1) * 35 + 7) / 8) +#define DUK_PC2LINE_MAX_DIFF_LENGTH (((DUK_PC2LINE_SKIP - 1) * 35 + 7) / 8) /* * Struct defs @@ -6881,9 +7302,9 @@ duk_hobject *set; /* for updating (all are set to < 0 for virtual properties) */ - duk_int_t e_idx; /* prop index in 'entry part', < 0 if not there */ - duk_int_t h_idx; /* prop index in 'hash part', < 0 if not there */ - duk_int_t a_idx; /* prop index in 'array part', < 0 if not there */ + duk_int_t e_idx; /* prop index in 'entry part', < 0 if not there */ + duk_int_t h_idx; /* prop index in 'hash part', < 0 if not there */ + duk_int_t a_idx; /* prop index in 'array part', < 0 if not there */ }; struct duk_hobject { @@ -6978,11 +7399,11 @@ duk_uint16_t h_size16; #endif #else - duk_uint32_t e_size; /* entry part size */ - duk_uint32_t e_next; /* index for next new key (0,e_next are gc reachable) */ - duk_uint32_t a_size; /* array part size (entirely gc reachable) */ + duk_uint32_t e_size; /* entry part size */ + duk_uint32_t e_next; /* index for next new key (0,e_next are gc reachable) */ + duk_uint32_t a_size; /* array part size (entirely gc reachable) */ #if defined(DUK_USE_HOBJECT_HASH_PART) - duk_uint32_t h_size; /* hash part size or 0 if unused */ + duk_uint32_t h_size; /* hash part size or 0 if unused */ #endif #endif }; @@ -6993,7 +7414,7 @@ #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL duk_uint8_t duk_class_number_to_stridx32; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* * Prototypes @@ -7022,36 +7443,46 @@ duk_uint32_t new_a_size, duk_uint32_t new_h_size, duk_bool_t abandon_array); -DUK_INTERNAL_DECL void duk_hobject_resize_entrypart(duk_hthread *thr, - duk_hobject *obj, - duk_uint32_t new_e_size); -#if 0 /*unused*/ +DUK_INTERNAL_DECL void duk_hobject_resize_entrypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_e_size); +#if 0 /*unused*/ DUK_INTERNAL_DECL void duk_hobject_resize_arraypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_a_size); #endif /* low-level property functions */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_hstring *key); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_stridx(duk_heap *heap, duk_hobject *obj, duk_small_uint_t stridx); -DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_uint_t *out_attrs); +DUK_INTERNAL_DECL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, + duk_hobject *obj, + duk_hstring *key, + duk_uint_t *out_attrs); DUK_INTERNAL_DECL duk_tval *duk_hobject_find_array_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_uarridx_t i); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); /* core property functions */ DUK_INTERNAL_DECL duk_bool_t duk_hobject_getprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key); -DUK_INTERNAL_DECL duk_bool_t duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag); +DUK_INTERNAL_DECL duk_bool_t +duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag); DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_bool_t throw_flag); DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key); /* internal property functions */ -#define DUK_DELPROP_FLAG_THROW (1U << 0) -#define DUK_DELPROP_FLAG_FORCE (1U << 1) +#define DUK_DELPROP_FLAG_THROW (1U << 0) +#define DUK_DELPROP_FLAG_FORCE (1U << 1) DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags); DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key); -DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags); -DUK_INTERNAL_DECL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, duk_hobject *obj, duk_uarridx_t arr_idx, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, + duk_hobject *obj, + duk_uarridx_t arr_idx, + duk_small_uint_t flags); DUK_INTERNAL_DECL duk_size_t duk_hobject_get_length(duk_hthread *thr, duk_hobject *obj); #if defined(DUK_USE_HEAPPTR16) DUK_INTERNAL_DECL duk_bool_t duk_hobject_has_finalizer_fast_raw(duk_heap *heap, duk_hobject *obj); @@ -7111,7 +7542,10 @@ #endif /* misc */ -DUK_INTERNAL_DECL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop); +DUK_INTERNAL_DECL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, + duk_hobject *h, + duk_hobject *p, + duk_bool_t ignore_loop); #if !defined(DUK_USE_OBJECT_BUILTIN) /* These declarations are needed when related built-in is disabled and @@ -7121,7 +7555,7 @@ DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype(duk_hthread *thr); #endif -#endif /* DUK_HOBJECT_H_INCLUDED */ +#endif /* DUK_HOBJECT_H_INCLUDED */ /* #include duk_hcompfunc.h */ #line 1 "duk_hcompfunc.h" /* @@ -7141,50 +7575,55 @@ /* XXX: casts could be improved, especially for GET/SET DATA */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HCOMPFUNC_GET_DATA(heap,h) \ - ((duk_hbuffer_fixed *) (void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->data16)) -#define DUK_HCOMPFUNC_SET_DATA(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_DATA(heap, h) ((duk_hbuffer_fixed *) (void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->data16)) +#define DUK_HCOMPFUNC_SET_DATA(heap, h, v) \ + do { \ (h)->data16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_FUNCS(heap,h) \ - ((duk_hobject **) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->funcs16))) -#define DUK_HCOMPFUNC_SET_FUNCS(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_FUNCS(heap, h) ((duk_hobject **) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->funcs16))) +#define DUK_HCOMPFUNC_SET_FUNCS(heap, h, v) \ + do { \ (h)->funcs16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_BYTECODE(heap,h) \ - ((duk_instr_t *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->bytecode16))) -#define DUK_HCOMPFUNC_SET_BYTECODE(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_BYTECODE(heap, h) ((duk_instr_t *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->bytecode16))) +#define DUK_HCOMPFUNC_SET_BYTECODE(heap, h, v) \ + do { \ (h)->bytecode16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_LEXENV(heap,h) \ - ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->lex_env16))) -#define DUK_HCOMPFUNC_SET_LEXENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_LEXENV(heap, h) ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->lex_env16))) +#define DUK_HCOMPFUNC_SET_LEXENV(heap, h, v) \ + do { \ (h)->lex_env16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HCOMPFUNC_GET_VARENV(heap,h) \ - ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->var_env16))) -#define DUK_HCOMPFUNC_SET_VARENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_VARENV(heap, h) ((duk_hobject *) (void *) (DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (h)->var_env16))) +#define DUK_HCOMPFUNC_SET_VARENV(heap, h, v) \ + do { \ (h)->var_env16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) #else -#define DUK_HCOMPFUNC_GET_DATA(heap,h) ((duk_hbuffer_fixed *) (void *) (h)->data) -#define DUK_HCOMPFUNC_SET_DATA(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_DATA(heap, h) ((duk_hbuffer_fixed *) (void *) (h)->data) +#define DUK_HCOMPFUNC_SET_DATA(heap, h, v) \ + do { \ (h)->data = (duk_hbuffer *) (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_FUNCS(heap,h) ((h)->funcs) -#define DUK_HCOMPFUNC_SET_FUNCS(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_FUNCS(heap, h) ((h)->funcs) +#define DUK_HCOMPFUNC_SET_FUNCS(heap, h, v) \ + do { \ (h)->funcs = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_BYTECODE(heap,h) ((h)->bytecode) -#define DUK_HCOMPFUNC_SET_BYTECODE(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_BYTECODE(heap, h) ((h)->bytecode) +#define DUK_HCOMPFUNC_SET_BYTECODE(heap, h, v) \ + do { \ (h)->bytecode = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_LEXENV(heap,h) ((h)->lex_env) -#define DUK_HCOMPFUNC_SET_LEXENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_LEXENV(heap, h) ((h)->lex_env) +#define DUK_HCOMPFUNC_SET_LEXENV(heap, h, v) \ + do { \ (h)->lex_env = (v); \ } while (0) -#define DUK_HCOMPFUNC_GET_VARENV(heap,h) ((h)->var_env) -#define DUK_HCOMPFUNC_SET_VARENV(heap,h,v) do { \ +#define DUK_HCOMPFUNC_GET_VARENV(heap, h) ((h)->var_env) +#define DUK_HCOMPFUNC_SET_VARENV(heap, h, v) \ + do { \ (h)->var_env = (v); \ } while (0) #endif @@ -7194,64 +7633,40 @@ */ /* Note: assumes 'data' is always a fixed buffer */ -#define DUK_HCOMPFUNC_GET_BUFFER_BASE(heap,h) \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) +#define DUK_HCOMPFUNC_GET_BUFFER_BASE(heap, h) DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) -#define DUK_HCOMPFUNC_GET_CONSTS_BASE(heap,h) \ - ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_BUFFER_BASE((heap), (h))) +#define DUK_HCOMPFUNC_GET_CONSTS_BASE(heap, h) ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_BUFFER_BASE((heap), (h))) -#define DUK_HCOMPFUNC_GET_FUNCS_BASE(heap,h) \ - DUK_HCOMPFUNC_GET_FUNCS((heap), (h)) +#define DUK_HCOMPFUNC_GET_FUNCS_BASE(heap, h) DUK_HCOMPFUNC_GET_FUNCS((heap), (h)) -#define DUK_HCOMPFUNC_GET_CODE_BASE(heap,h) \ - DUK_HCOMPFUNC_GET_BYTECODE((heap), (h)) +#define DUK_HCOMPFUNC_GET_CODE_BASE(heap, h) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h)) -#define DUK_HCOMPFUNC_GET_CONSTS_END(heap,h) \ - ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_FUNCS((heap), (h))) +#define DUK_HCOMPFUNC_GET_CONSTS_END(heap, h) ((duk_tval *) (void *) DUK_HCOMPFUNC_GET_FUNCS((heap), (h))) -#define DUK_HCOMPFUNC_GET_FUNCS_END(heap,h) \ - ((duk_hobject **) (void *) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h))) +#define DUK_HCOMPFUNC_GET_FUNCS_END(heap, h) ((duk_hobject **) (void *) DUK_HCOMPFUNC_GET_BYTECODE((heap), (h))) /* XXX: double evaluation of DUK_HCOMPFUNC_GET_DATA() */ -#define DUK_HCOMPFUNC_GET_CODE_END(heap,h) \ +#define DUK_HCOMPFUNC_GET_CODE_END(heap, h) \ ((duk_instr_t *) (void *) (DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), DUK_HCOMPFUNC_GET_DATA((heap), (h))) + \ - DUK_HBUFFER_GET_SIZE((duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA((heap), h)))) + DUK_HBUFFER_GET_SIZE((duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA((heap), h)))) + +#define DUK_HCOMPFUNC_GET_CONSTS_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_BASE((heap), (h))))) + +#define DUK_HCOMPFUNC_GET_FUNCS_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_BASE((heap), (h))))) -#define DUK_HCOMPFUNC_GET_CONSTS_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_END((heap), (h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CONSTS_BASE((heap), (h))) \ - ) \ - ) - -#define DUK_HCOMPFUNC_GET_FUNCS_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_END((heap), (h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_FUNCS_BASE((heap), (h))) \ - ) \ - ) - -#define DUK_HCOMPFUNC_GET_CODE_SIZE(heap,h) \ - ( \ - (duk_size_t) \ - ( \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_END((heap),(h))) - \ - ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_BASE((heap),(h))) \ - ) \ - ) +#define DUK_HCOMPFUNC_GET_CODE_SIZE(heap, h) \ + ((duk_size_t) (((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_END((heap), (h))) - \ + ((const duk_uint8_t *) DUK_HCOMPFUNC_GET_CODE_BASE((heap), (h))))) -#define DUK_HCOMPFUNC_GET_CONSTS_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_CONSTS_SIZE((heap), (h)) / sizeof(duk_tval))) +#define DUK_HCOMPFUNC_GET_CONSTS_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_CONSTS_SIZE((heap), (h)) / sizeof(duk_tval))) -#define DUK_HCOMPFUNC_GET_FUNCS_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_FUNCS_SIZE((heap), (h)) / sizeof(duk_hobject *))) +#define DUK_HCOMPFUNC_GET_FUNCS_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_FUNCS_SIZE((heap), (h)) / sizeof(duk_hobject *))) -#define DUK_HCOMPFUNC_GET_CODE_COUNT(heap,h) \ - ((duk_size_t) (DUK_HCOMPFUNC_GET_CODE_SIZE((heap), (h)) / sizeof(duk_instr_t))) +#define DUK_HCOMPFUNC_GET_CODE_COUNT(heap, h) ((duk_size_t) (DUK_HCOMPFUNC_GET_CODE_SIZE((heap), (h)) / sizeof(duk_instr_t))) /* * Validity assert @@ -7259,9 +7674,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hcompfunc_assert_valid(duk_hcompfunc *h); -#define DUK_HCOMPFUNC_ASSERT_VALID(h) do { duk_hcompfunc_assert_valid((h)); } while (0) +#define DUK_HCOMPFUNC_ASSERT_VALID(h) \ + do { \ + duk_hcompfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HCOMPFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HCOMPFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -7348,8 +7768,8 @@ * at run time, except for debugging, so it is not maintained. */ - duk_uint16_t nregs; /* regs to allocate */ - duk_uint16_t nargs; /* number of arguments allocated to regs */ + duk_uint16_t nregs; /* regs to allocate */ + duk_uint16_t nargs; /* number of arguments allocated to regs */ /* * Additional control information is placed into the object itself @@ -7396,7 +7816,7 @@ #endif }; -#endif /* DUK_HCOMPFUNC_H_INCLUDED */ +#endif /* DUK_HCOMPFUNC_H_INCLUDED */ /* #include duk_hnatfunc.h */ #line 1 "duk_hnatfunc.h" /* @@ -7408,13 +7828,18 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hnatfunc_assert_valid(duk_hnatfunc *h); -#define DUK_HNATFUNC_ASSERT_VALID(h) do { duk_hnatfunc_assert_valid((h)); } while (0) +#define DUK_HNATFUNC_ASSERT_VALID(h) \ + do { \ + duk_hnatfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HNATFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HNATFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#define DUK_HNATFUNC_NARGS_VARARGS ((duk_int16_t) -1) -#define DUK_HNATFUNC_NARGS_MAX ((duk_int16_t) 0x7fff) +#define DUK_HNATFUNC_NARGS_VARARGS ((duk_int16_t) -1) +#define DUK_HNATFUNC_NARGS_MAX ((duk_int16_t) 0x7fff) struct duk_hnatfunc { /* shared object part */ @@ -7437,7 +7862,7 @@ */ }; -#endif /* DUK_HNATFUNC_H_INCLUDED */ +#endif /* DUK_HNATFUNC_H_INCLUDED */ /* #include duk_hboundfunc.h */ #line 1 "duk_hboundfunc.h" /* @@ -7454,9 +7879,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hboundfunc_assert_valid(duk_hboundfunc *h); -#define DUK_HBOUNDFUNC_ASSERT_VALID(h) do { duk_hboundfunc_assert_valid((h)); } while (0) +#define DUK_HBOUNDFUNC_ASSERT_VALID(h) \ + do { \ + duk_hboundfunc_assert_valid((h)); \ + } while (0) #else -#define DUK_HBOUNDFUNC_ASSERT_VALID(h) do {} while (0) +#define DUK_HBOUNDFUNC_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hboundfunc { @@ -7472,11 +7902,11 @@ duk_tval this_binding; /* Arguments to prepend. */ - duk_tval *args; /* Separate allocation. */ + duk_tval *args; /* Separate allocation. */ duk_idx_t nargs; }; -#endif /* DUK_HBOUNDFUNC_H_INCLUDED */ +#endif /* DUK_HBOUNDFUNC_H_INCLUDED */ /* #include duk_hbufobj.h */ #line 1 "duk_hbufobj.h" /* @@ -7489,31 +7919,37 @@ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) /* All element accessors are host endian now (driven by TypedArray spec). */ -#define DUK_HBUFOBJ_ELEM_UINT8 0 -#define DUK_HBUFOBJ_ELEM_UINT8CLAMPED 1 -#define DUK_HBUFOBJ_ELEM_INT8 2 -#define DUK_HBUFOBJ_ELEM_UINT16 3 -#define DUK_HBUFOBJ_ELEM_INT16 4 -#define DUK_HBUFOBJ_ELEM_UINT32 5 -#define DUK_HBUFOBJ_ELEM_INT32 6 -#define DUK_HBUFOBJ_ELEM_FLOAT32 7 -#define DUK_HBUFOBJ_ELEM_FLOAT64 8 -#define DUK_HBUFOBJ_ELEM_MAX 8 +#define DUK_HBUFOBJ_ELEM_UINT8 0 +#define DUK_HBUFOBJ_ELEM_UINT8CLAMPED 1 +#define DUK_HBUFOBJ_ELEM_INT8 2 +#define DUK_HBUFOBJ_ELEM_UINT16 3 +#define DUK_HBUFOBJ_ELEM_INT16 4 +#define DUK_HBUFOBJ_ELEM_UINT32 5 +#define DUK_HBUFOBJ_ELEM_INT32 6 +#define DUK_HBUFOBJ_ELEM_FLOAT32 7 +#define DUK_HBUFOBJ_ELEM_FLOAT64 8 +#define DUK_HBUFOBJ_ELEM_MAX 8 #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hbufobj_assert_valid(duk_hbufobj *h); -#define DUK_HBUFOBJ_ASSERT_VALID(h) do { duk_hbufobj_assert_valid((h)); } while (0) +#define DUK_HBUFOBJ_ASSERT_VALID(h) \ + do { \ + duk_hbufobj_assert_valid((h)); \ + } while (0) #else -#define DUK_HBUFOBJ_ASSERT_VALID(h) do {} while (0) +#define DUK_HBUFOBJ_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* Get the current data pointer (caller must ensure buf != NULL) as a * duk_uint8_t ptr. Note that the result may be NULL if the underlying * buffer has zero size and is not a fixed buffer. */ -#define DUK_HBUFOBJ_GET_SLICE_BASE(heap,h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - (((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR((heap), (h)->buf)) + (h)->offset)) +#define DUK_HBUFOBJ_GET_SLICE_BASE(heap, h) \ + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + (((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR((heap), (h)->buf)) + (h)->offset)) /* True if slice is full, i.e. offset is zero and length covers the entire * buffer. This status may change independently of the duk_hbufobj if @@ -7521,15 +7957,17 @@ * being changed. */ #define DUK_HBUFOBJ_FULL_SLICE(h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset == 0 && (h)->length == DUK_HBUFFER_GET_SIZE((h)->buf))) + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + ((h)->offset == 0 && (h)->length == DUK_HBUFFER_GET_SIZE((h)->buf))) /* Validate that the whole slice 0,length is contained in the underlying * buffer. Caller must ensure 'buf' != NULL. */ #define DUK_HBUFOBJ_VALID_SLICE(h) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (h)->length <= DUK_HBUFFER_GET_SIZE((h)->buf))) + (DUK_ASSERT_EXPR((h) != NULL), \ + DUK_ASSERT_EXPR((h)->buf != NULL), \ + ((h)->offset + (h)->length <= DUK_HBUFFER_GET_SIZE((h)->buf))) /* Validate byte read/write for virtual 'offset', i.e. check that the * offset, taking into account h->offset, is within the underlying @@ -7538,13 +7976,11 @@ * behavior (e.g. if an underlying dynamic buffer changes after being * setup). Caller must ensure 'buf' != NULL. */ -#define DUK_HBUFOBJ_VALID_BYTEOFFSET_INCL(h,off) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf))) - -#define DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h,off) \ - (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \ - ((h)->offset + (off) <= DUK_HBUFFER_GET_SIZE((h)->buf))) +#define DUK_HBUFOBJ_VALID_BYTEOFFSET_INCL(h, off) \ + (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), ((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf))) + +#define DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h, off) \ + (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), ((h)->offset + (off) <= DUK_HBUFFER_GET_SIZE((h)->buf))) /* Clamp an input byte length (already assumed to be within the nominal * duk_hbufobj 'length') to the current dynamic buffer limits to yield @@ -7552,12 +7988,10 @@ * be invalidated by any side effect because it may trigger a user * callback that resizes the underlying buffer. */ -#define DUK_HBUFOBJ_CLAMP_BYTELENGTH(h,len) \ - (DUK_ASSERT_EXPR((h) != NULL), \ - duk_hbufobj_clamp_bytelength((h), (len))) +#define DUK_HBUFOBJ_CLAMP_BYTELENGTH(h, len) (DUK_ASSERT_EXPR((h) != NULL), duk_hbufobj_clamp_bytelength((h), (len))) /* Typed arrays have virtual indices, ArrayBuffer and DataView do not. */ -#define DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h) ((h)->is_typedarray) +#define DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h) ((h)->is_typedarray) struct duk_hbufobj { /* Shared object part. */ @@ -7582,30 +8016,36 @@ * be dynamic and its pointer unstable. */ - duk_uint_t offset; /* byte offset to buf */ - duk_uint_t length; /* byte index limit for element access, exclusive */ - duk_uint8_t shift; /* element size shift: - * 0 = u8/i8 - * 1 = u16/i16 - * 2 = u32/i32/float - * 3 = double - */ - duk_uint8_t elem_type; /* element type */ + duk_uint_t offset; /* byte offset to buf */ + duk_uint_t length; /* byte index limit for element access, exclusive */ + duk_uint8_t shift; /* element size shift: + * 0 = u8/i8 + * 1 = u16/i16 + * 2 = u32/i32/float + * 3 = double + */ + duk_uint8_t elem_type; /* element type */ duk_uint8_t is_typedarray; }; DUK_INTERNAL_DECL duk_uint_t duk_hbufobj_clamp_bytelength(duk_hbufobj *h_bufobj, duk_uint_t len); DUK_INTERNAL_DECL void duk_hbufobj_push_uint8array_from_plain(duk_hthread *thr, duk_hbuffer *h_buf); -DUK_INTERNAL_DECL void duk_hbufobj_push_validated_read(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size); -DUK_INTERNAL_DECL void duk_hbufobj_validated_write(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size); +DUK_INTERNAL_DECL void duk_hbufobj_push_validated_read(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size); +DUK_INTERNAL_DECL void duk_hbufobj_validated_write(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size); DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_hthread *thr, duk_idx_t idx); -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* nothing */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ -#endif /* DUK_HBUFOBJ_H_INCLUDED */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_HBUFOBJ_H_INCLUDED */ /* #include duk_hthread.h */ #line 1 "duk_hthread.h" /* @@ -7624,38 +8064,38 @@ */ /* Initial valstack size, roughly 0.7kiB. */ -#define DUK_VALSTACK_INITIAL_SIZE 96U +#define DUK_VALSTACK_INITIAL_SIZE 96U /* Internal extra elements assumed on function entry, always added to * user-defined 'extra' for e.g. the duk_check_stack() call. */ -#define DUK_VALSTACK_INTERNAL_EXTRA 32U +#define DUK_VALSTACK_INTERNAL_EXTRA 32U /* Number of elements guaranteed to be user accessible (in addition to call * arguments) on Duktape/C function entry. This is the major public API * commitment. */ -#define DUK_VALSTACK_API_ENTRY_MINIMUM DUK_API_ENTRY_STACK +#define DUK_VALSTACK_API_ENTRY_MINIMUM DUK_API_ENTRY_STACK /* * Activation defines */ -#define DUK_ACT_FLAG_STRICT (1U << 0) /* function executes in strict mode */ -#define DUK_ACT_FLAG_TAILCALLED (1U << 1) /* activation has tail called one or more times */ -#define DUK_ACT_FLAG_CONSTRUCT (1U << 2) /* function executes as a constructor (called via "new") */ -#define DUK_ACT_FLAG_PREVENT_YIELD (1U << 3) /* activation prevents yield (native call or "new") */ -#define DUK_ACT_FLAG_DIRECT_EVAL (1U << 4) /* activation is a direct eval call */ -#define DUK_ACT_FLAG_CONSTRUCT_PROXY (1U << 5) /* activation is for Proxy 'construct' call, special return value handling */ -#define DUK_ACT_FLAG_BREAKPOINT_ACTIVE (1U << 6) /* activation has active breakpoint(s) */ +#define DUK_ACT_FLAG_STRICT (1U << 0) /* function executes in strict mode */ +#define DUK_ACT_FLAG_TAILCALLED (1U << 1) /* activation has tail called one or more times */ +#define DUK_ACT_FLAG_CONSTRUCT (1U << 2) /* function executes as a constructor (called via "new") */ +#define DUK_ACT_FLAG_PREVENT_YIELD (1U << 3) /* activation prevents yield (native call or "new") */ +#define DUK_ACT_FLAG_DIRECT_EVAL (1U << 4) /* activation is a direct eval call */ +#define DUK_ACT_FLAG_CONSTRUCT_PROXY (1U << 5) /* activation is for Proxy 'construct' call, special return value handling */ +#define DUK_ACT_FLAG_BREAKPOINT_ACTIVE (1U << 6) /* activation has active breakpoint(s) */ -#define DUK_ACT_GET_FUNC(act) ((act)->func) +#define DUK_ACT_GET_FUNC(act) ((act)->func) /* * Flags for __FILE__ / __LINE__ registered into tracedata */ -#define DUK_TB_FLAG_NOBLAME_FILELINE (1U << 0) /* don't report __FILE__ / __LINE__ as fileName/lineNumber */ +#define DUK_TB_FLAG_NOBLAME_FILELINE (1U << 0) /* don't report __FILE__ / __LINE__ as fileName/lineNumber */ /* * Catcher defines @@ -7664,52 +8104,60 @@ /* XXX: remove catcher type entirely */ /* flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits) */ -#define DUK_CAT_TYPE_MASK 0x0000000fUL -#define DUK_CAT_TYPE_BITS 4 -#define DUK_CAT_LABEL_MASK 0xffffff00UL -#define DUK_CAT_LABEL_BITS 24 -#define DUK_CAT_LABEL_SHIFT 8 - -#define DUK_CAT_FLAG_CATCH_ENABLED (1U << 4) /* catch part will catch */ -#define DUK_CAT_FLAG_FINALLY_ENABLED (1U << 5) /* finally part will catch */ -#define DUK_CAT_FLAG_CATCH_BINDING_ENABLED (1U << 6) /* request to create catch binding */ -#define DUK_CAT_FLAG_LEXENV_ACTIVE (1U << 7) /* catch or with binding is currently active */ - -#define DUK_CAT_TYPE_UNKNOWN 0 -#define DUK_CAT_TYPE_TCF 1 -#define DUK_CAT_TYPE_LABEL 2 - -#define DUK_CAT_GET_TYPE(c) ((c)->flags & DUK_CAT_TYPE_MASK) -#define DUK_CAT_GET_LABEL(c) (((c)->flags & DUK_CAT_LABEL_MASK) >> DUK_CAT_LABEL_SHIFT) - -#define DUK_CAT_HAS_CATCH_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_ENABLED) -#define DUK_CAT_HAS_FINALLY_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_FINALLY_ENABLED) -#define DUK_CAT_HAS_CATCH_BINDING_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_BINDING_ENABLED) -#define DUK_CAT_HAS_LEXENV_ACTIVE(c) ((c)->flags & DUK_CAT_FLAG_LEXENV_ACTIVE) +#define DUK_CAT_TYPE_MASK 0x0000000fUL +#define DUK_CAT_TYPE_BITS 4 +#define DUK_CAT_LABEL_MASK 0xffffff00UL +#define DUK_CAT_LABEL_BITS 24 +#define DUK_CAT_LABEL_SHIFT 8 + +#define DUK_CAT_FLAG_CATCH_ENABLED (1U << 4) /* catch part will catch */ +#define DUK_CAT_FLAG_FINALLY_ENABLED (1U << 5) /* finally part will catch */ +#define DUK_CAT_FLAG_CATCH_BINDING_ENABLED (1U << 6) /* request to create catch binding */ +#define DUK_CAT_FLAG_LEXENV_ACTIVE (1U << 7) /* catch or with binding is currently active */ + +#define DUK_CAT_TYPE_UNKNOWN 0 +#define DUK_CAT_TYPE_TCF 1 +#define DUK_CAT_TYPE_LABEL 2 + +#define DUK_CAT_GET_TYPE(c) ((c)->flags & DUK_CAT_TYPE_MASK) +#define DUK_CAT_GET_LABEL(c) (((c)->flags & DUK_CAT_LABEL_MASK) >> DUK_CAT_LABEL_SHIFT) + +#define DUK_CAT_HAS_CATCH_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_ENABLED) +#define DUK_CAT_HAS_FINALLY_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_FINALLY_ENABLED) +#define DUK_CAT_HAS_CATCH_BINDING_ENABLED(c) ((c)->flags & DUK_CAT_FLAG_CATCH_BINDING_ENABLED) +#define DUK_CAT_HAS_LEXENV_ACTIVE(c) ((c)->flags & DUK_CAT_FLAG_LEXENV_ACTIVE) -#define DUK_CAT_SET_CATCH_ENABLED(c) do { \ +#define DUK_CAT_SET_CATCH_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_CATCH_ENABLED; \ } while (0) -#define DUK_CAT_SET_FINALLY_ENABLED(c) do { \ +#define DUK_CAT_SET_FINALLY_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_FINALLY_ENABLED; \ } while (0) -#define DUK_CAT_SET_CATCH_BINDING_ENABLED(c) do { \ +#define DUK_CAT_SET_CATCH_BINDING_ENABLED(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_CATCH_BINDING_ENABLED; \ } while (0) -#define DUK_CAT_SET_LEXENV_ACTIVE(c) do { \ +#define DUK_CAT_SET_LEXENV_ACTIVE(c) \ + do { \ (c)->flags |= DUK_CAT_FLAG_LEXENV_ACTIVE; \ } while (0) -#define DUK_CAT_CLEAR_CATCH_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_CATCH_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_CATCH_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_FINALLY_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_FINALLY_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_FINALLY_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_CATCH_BINDING_ENABLED(c) do { \ +#define DUK_CAT_CLEAR_CATCH_BINDING_ENABLED(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_CATCH_BINDING_ENABLED; \ } while (0) -#define DUK_CAT_CLEAR_LEXENV_ACTIVE(c) do { \ +#define DUK_CAT_CLEAR_LEXENV_ACTIVE(c) \ + do { \ (c)->flags &= ~DUK_CAT_FLAG_LEXENV_ACTIVE; \ } while (0) @@ -7718,24 +8166,21 @@ */ #if defined(DUK_USE_ROM_STRINGS) -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) -#else /* DUK_USE_ROM_STRINGS */ +#define DUK_HTHREAD_GET_STRING(thr, idx) ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((thr)->heap->heap_udata, (thr)->strs16(idx))) +#define DUK_HTHREAD_GET_STRING(thr, idx) ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((thr)->heap->heap_udata, (thr)->strs16(idx))) #else -#define DUK_HTHREAD_GET_STRING(thr,idx) \ - ((thr)->strs(idx)) +#define DUK_HTHREAD_GET_STRING(thr, idx) ((thr)->strs(idx)) #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ /* values for the state field */ -#define DUK_HTHREAD_STATE_INACTIVE 1 /* thread not currently running */ -#define DUK_HTHREAD_STATE_RUNNING 2 /* thread currently running (only one at a time) */ -#define DUK_HTHREAD_STATE_RESUMED 3 /* thread resumed another thread (active but not running) */ -#define DUK_HTHREAD_STATE_YIELDED 4 /* thread has yielded */ -#define DUK_HTHREAD_STATE_TERMINATED 5 /* thread has terminated */ +#define DUK_HTHREAD_STATE_INACTIVE 1 /* thread not currently running */ +#define DUK_HTHREAD_STATE_RUNNING 2 /* thread currently running (only one at a time) */ +#define DUK_HTHREAD_STATE_RESUMED 3 /* thread resumed another thread (active but not running) */ +#define DUK_HTHREAD_STATE_YIELDED 4 /* thread has yielded */ +#define DUK_HTHREAD_STATE_TERMINATED 5 /* thread has terminated */ /* Executor interrupt default interval when nothing else requires a * smaller value. The default interval must be small enough to allow @@ -7743,7 +8188,7 @@ * impact on execution performance low. */ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK_HTHREAD_INTCTR_DEFAULT (256L * 1024L) +#define DUK_HTHREAD_INTCTR_DEFAULT (256L * 1024L) #endif /* @@ -7757,20 +8202,31 @@ #if defined(DUK_USE_ASSERTIONS) /* Assertions for internals. */ DUK_INTERNAL_DECL void duk_hthread_assert_valid(duk_hthread *thr); -#define DUK_HTHREAD_ASSERT_VALID(thr) do { duk_hthread_assert_valid((thr)); } while (0) +#define DUK_HTHREAD_ASSERT_VALID(thr) \ + do { \ + duk_hthread_assert_valid((thr)); \ + } while (0) /* Assertions for public API calls; a bit stronger. */ DUK_INTERNAL_DECL void duk_ctx_assert_valid(duk_hthread *thr); -#define DUK_CTX_ASSERT_VALID(thr) do { duk_ctx_assert_valid((thr)); } while (0) +#define DUK_CTX_ASSERT_VALID(thr) \ + do { \ + duk_ctx_assert_valid((thr)); \ + } while (0) #else -#define DUK_HTHREAD_ASSERT_VALID(thr) do {} while (0) -#define DUK_CTX_ASSERT_VALID(thr) do {} while (0) +#define DUK_HTHREAD_ASSERT_VALID(thr) \ + do { \ + } while (0) +#define DUK_CTX_ASSERT_VALID(thr) \ + do { \ + } while (0) #endif /* Assertions for API call entry specifically. Checks 'ctx' but also may * check internal state (e.g. not in a debugger transport callback). */ -#define DUK_ASSERT_API_ENTRY(thr) do { \ +#define DUK_ASSERT_API_ENTRY(thr) \ + do { \ DUK_CTX_ASSERT_VALID((thr)); \ DUK_ASSERT((thr)->heap != NULL); \ DUK_ASSERT((thr)->heap->dbg_calling_transport == 0); \ @@ -7780,11 +8236,9 @@ * Assertion helpers. */ -#define DUK_ASSERT_STRIDX_VALID(val) \ - DUK_ASSERT((duk_uint_t) (val) < DUK_HEAP_NUM_STRINGS) +#define DUK_ASSERT_STRIDX_VALID(val) DUK_ASSERT((duk_uint_t) (val) < DUK_HEAP_NUM_STRINGS) -#define DUK_ASSERT_BIDX_VALID(val) \ - DUK_ASSERT((duk_uint_t) (val) < DUK_NUM_BUILTINS) +#define DUK_ASSERT_BIDX_VALID(val) DUK_ASSERT((duk_uint_t) (val) < DUK_NUM_BUILTINS) /* * Misc @@ -7792,9 +8246,7 @@ /* Fast access to 'this' binding. Assumes there's a call in progress. */ #define DUK_HTHREAD_THIS_PTR(thr) \ - (DUK_ASSERT_EXPR((thr) != NULL), \ - DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), \ - (thr)->valstack_bottom - 1) + (DUK_ASSERT_EXPR((thr) != NULL), DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), (thr)->valstack_bottom - 1) /* * Struct defines @@ -7802,12 +8254,13 @@ /* Fields are ordered for alignment/packing. */ struct duk_activation { - duk_tval tv_func; /* borrowed: full duk_tval for function being executed; for lightfuncs */ - duk_hobject *func; /* borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs */ + duk_tval tv_func; /* borrowed: full duk_tval for function being executed; for lightfuncs */ + duk_hobject *func; /* borrowed: function being executed; for bound function calls, this is the final, real function, NULL + for lightfuncs */ duk_activation *parent; /* previous (parent) activation (or NULL if none) */ - duk_hobject *var_env; /* current variable environment (may be NULL if delayed) */ - duk_hobject *lex_env; /* current lexical environment (may be NULL if delayed) */ - duk_catcher *cat; /* current catcher (or NULL) */ + duk_hobject *var_env; /* current variable environment (may be NULL if delayed) */ + duk_hobject *lex_env; /* current lexical environment (may be NULL if delayed) */ + duk_catcher *cat; /* current catcher (or NULL) */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) /* Previous value of 'func' caller, restored when unwound. Only in use @@ -7816,7 +8269,7 @@ duk_hobject *prev_caller; #endif - duk_instr_t *curr_pc; /* next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls */ + duk_instr_t *curr_pc; /* next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls */ /* bottom_byteoff and retval_byteoff are only used for book-keeping * of ECMAScript-initiated calls, to allow returning to an ECMAScript @@ -7863,12 +8316,12 @@ }; struct duk_catcher { - duk_catcher *parent; /* previous (parent) catcher (or NULL if none) */ - duk_hstring *h_varname; /* borrowed reference to catch variable name (or NULL if none) */ - /* (reference is valid as long activation exists) */ - duk_instr_t *pc_base; /* resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer) */ - duk_size_t idx_base; /* idx_base and idx_base+1 get completion value and type */ - duk_uint32_t flags; /* type and control flags, label number */ + duk_catcher *parent; /* previous (parent) catcher (or NULL if none) */ + duk_hstring *h_varname; /* borrowed reference to catch variable name (or NULL if none) */ + /* (reference is valid as long activation exists) */ + duk_instr_t *pc_base; /* resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer) */ + duk_size_t idx_base; /* idx_base and idx_base+1 get completion value and type */ + duk_uint32_t flags; /* type and control flags, label number */ /* XXX: could pack 'flags' and 'idx_base' to same value in practice, * on 32-bit targets this would make duk_catcher 16 bytes. */ @@ -7926,21 +8379,21 @@ * yyy = arbitrary values, inside current frame * uuu = outside active value stack, initialized to 'undefined' */ - duk_tval *valstack; /* start of valstack allocation */ - duk_tval *valstack_end; /* end of valstack reservation/guarantee (exclusive) */ - duk_tval *valstack_alloc_end; /* end of valstack allocation */ - duk_tval *valstack_bottom; /* bottom of current frame */ - duk_tval *valstack_top; /* top of current frame (exclusive) */ + duk_tval *valstack; /* start of valstack allocation */ + duk_tval *valstack_end; /* end of valstack reservation/guarantee (exclusive) */ + duk_tval *valstack_alloc_end; /* end of valstack allocation */ + duk_tval *valstack_bottom; /* bottom of current frame */ + duk_tval *valstack_top; /* top of current frame (exclusive) */ /* Call stack, represented as a linked list starting from the current * activation (or NULL if nothing is active). */ - duk_activation *callstack_curr; /* current activation (or NULL if none) */ - duk_size_t callstack_top; /* number of activation records in callstack (0 if none) */ - duk_size_t callstack_preventcount; /* number of activation records in callstack preventing a yield */ + duk_activation *callstack_curr; /* current activation (or NULL if none) */ + duk_size_t callstack_top; /* number of activation records in callstack (0 if none) */ + duk_size_t callstack_preventcount; /* number of activation records in callstack preventing a yield */ /* Yield/resume book-keeping. */ - duk_hthread *resumer; /* who resumed us (if any) */ + duk_hthread *resumer; /* who resumed us (if any) */ /* Current compiler state (if any), used for augmenting SyntaxErrors. */ duk_compiler_ctx *compile_ctx; @@ -7953,8 +8406,8 @@ * important for the counter to be conveniently accessible for the * bytecode executor inner loop for performance reasons. */ - duk_int_t interrupt_counter; /* countdown state */ - duk_int_t interrupt_init; /* start value for current countdown */ + duk_int_t interrupt_counter; /* countdown state */ + duk_int_t interrupt_init; /* start value for current countdown */ #endif /* Builtin-objects; may or may not be shared with other threads, @@ -8006,7 +8459,7 @@ DUK_INTERNAL_DECL void duk_hthread_valstack_torture_realloc(duk_hthread *thr); #endif -DUK_INTERNAL_DECL void *duk_hthread_get_valstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */ +DUK_INTERNAL_DECL void *duk_hthread_get_valstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */ #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_INTERNAL_DECL duk_uint_fast32_t duk_hthread_get_act_curr_pc(duk_hthread *thr, duk_activation *act); @@ -8015,7 +8468,7 @@ DUK_INTERNAL_DECL void duk_hthread_sync_currpc(duk_hthread *thr); DUK_INTERNAL_DECL void duk_hthread_sync_and_null_currpc(duk_hthread *thr); -#endif /* DUK_HTHREAD_H_INCLUDED */ +#endif /* DUK_HTHREAD_H_INCLUDED */ /* #include duk_harray.h */ #line 1 "duk_harray.h" /* @@ -8031,15 +8484,26 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_harray_assert_valid(duk_harray *h); -#define DUK_HARRAY_ASSERT_VALID(h) do { duk_harray_assert_valid((h)); } while (0) +#define DUK_HARRAY_ASSERT_VALID(h) \ + do { \ + duk_harray_assert_valid((h)); \ + } while (0) #else -#define DUK_HARRAY_ASSERT_VALID(h) do {} while (0) +#define DUK_HARRAY_ASSERT_VALID(h) \ + do { \ + } while (0) #endif -#define DUK_HARRAY_LENGTH_WRITABLE(h) (!(h)->length_nonwritable) -#define DUK_HARRAY_LENGTH_NONWRITABLE(h) ((h)->length_nonwritable) -#define DUK_HARRAY_SET_LENGTH_WRITABLE(h) do { (h)->length_nonwritable = 0; } while (0) -#define DUK_HARRAY_SET_LENGTH_NONWRITABLE(h) do { (h)->length_nonwritable = 1; } while (0) +#define DUK_HARRAY_LENGTH_WRITABLE(h) (!(h)->length_nonwritable) +#define DUK_HARRAY_LENGTH_NONWRITABLE(h) ((h)->length_nonwritable) +#define DUK_HARRAY_SET_LENGTH_WRITABLE(h) \ + do { \ + (h)->length_nonwritable = 0; \ + } while (0) +#define DUK_HARRAY_SET_LENGTH_NONWRITABLE(h) \ + do { \ + (h)->length_nonwritable = 1; \ + } while (0) struct duk_harray { /* Shared object part. */ @@ -8065,7 +8529,7 @@ duk_bool_t length_nonwritable; }; -#endif /* DUK_HARRAY_H_INCLUDED */ +#endif /* DUK_HARRAY_H_INCLUDED */ /* #include duk_henv.h */ #line 1 "duk_henv.h" /* @@ -8078,11 +8542,21 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hdecenv_assert_valid(duk_hdecenv *h); DUK_INTERNAL_DECL void duk_hobjenv_assert_valid(duk_hobjenv *h); -#define DUK_HDECENV_ASSERT_VALID(h) do { duk_hdecenv_assert_valid((h)); } while (0) -#define DUK_HOBJENV_ASSERT_VALID(h) do { duk_hobjenv_assert_valid((h)); } while (0) +#define DUK_HDECENV_ASSERT_VALID(h) \ + do { \ + duk_hdecenv_assert_valid((h)); \ + } while (0) +#define DUK_HOBJENV_ASSERT_VALID(h) \ + do { \ + duk_hobjenv_assert_valid((h)); \ + } while (0) #else -#define DUK_HDECENV_ASSERT_VALID(h) do {} while (0) -#define DUK_HOBJENV_ASSERT_VALID(h) do {} while (0) +#define DUK_HDECENV_ASSERT_VALID(h) \ + do { \ + } while (0) +#define DUK_HOBJENV_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hdecenv { @@ -8112,7 +8586,7 @@ duk_bool_t has_this; }; -#endif /* DUK_HENV_H_INCLUDED */ +#endif /* DUK_HENV_H_INCLUDED */ /* #include duk_hbuffer.h */ #line 1 "duk_hbuffer.h" /* @@ -8137,17 +8611,17 @@ * External buffer: DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL */ -#define DUK_HBUFFER_FLAG_DYNAMIC DUK_HEAPHDR_USER_FLAG(0) /* buffer is behind a pointer, dynamic or external */ -#define DUK_HBUFFER_FLAG_EXTERNAL DUK_HEAPHDR_USER_FLAG(1) /* buffer pointer is to an externally allocated buffer */ +#define DUK_HBUFFER_FLAG_DYNAMIC DUK_HEAPHDR_USER_FLAG(0) /* buffer is behind a pointer, dynamic or external */ +#define DUK_HBUFFER_FLAG_EXTERNAL DUK_HEAPHDR_USER_FLAG(1) /* buffer pointer is to an externally allocated buffer */ -#define DUK_HBUFFER_HAS_DYNAMIC(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_HAS_EXTERNAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_HAS_DYNAMIC(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_HAS_EXTERNAL(x) DUK_HEAPHDR_CHECK_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) -#define DUK_HBUFFER_SET_DYNAMIC(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_SET_EXTERNAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_SET_DYNAMIC(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_SET_EXTERNAL(x) DUK_HEAPHDR_SET_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) -#define DUK_HBUFFER_CLEAR_DYNAMIC(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) -#define DUK_HBUFFER_CLEAR_EXTERNAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) +#define DUK_HBUFFER_CLEAR_DYNAMIC(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_DYNAMIC) +#define DUK_HBUFFER_CLEAR_EXTERNAL(x) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(x)->hdr, DUK_HBUFFER_FLAG_EXTERNAL) /* * Misc defines @@ -8160,12 +8634,12 @@ */ #if defined(DUK_USE_BUFLEN16) -#define DUK_HBUFFER_MAX_BYTELEN (0x0000ffffUL) +#define DUK_HBUFFER_MAX_BYTELEN (0x0000ffffUL) #else /* Intentionally not 0x7fffffffUL; at least JSON code expects that * 2*len + 2 fits in 32 bits. */ -#define DUK_HBUFFER_MAX_BYTELEN (0x7ffffffeUL) +#define DUK_HBUFFER_MAX_BYTELEN (0x7ffffffeUL) #endif /* @@ -8174,60 +8648,70 @@ #if defined(DUK_USE_BUFLEN16) /* size stored in duk_heaphdr unused flag bits */ -#define DUK_HBUFFER_GET_SIZE(x) ((x)->hdr.h_flags >> 16) -#define DUK_HBUFFER_SET_SIZE(x,v) do { \ +#define DUK_HBUFFER_GET_SIZE(x) ((x)->hdr.h_flags >> 16) +#define DUK_HBUFFER_SET_SIZE(x, v) \ + do { \ duk_size_t duk__v; \ duk__v = (v); \ DUK_ASSERT(duk__v <= 0xffffUL); \ (x)->hdr.h_flags = ((x)->hdr.h_flags & 0x0000ffffUL) | (((duk_uint32_t) duk__v) << 16); \ } while (0) -#define DUK_HBUFFER_ADD_SIZE(x,dv) do { \ +#define DUK_HBUFFER_ADD_SIZE(x, dv) \ + do { \ (x)->hdr.h_flags += ((dv) << 16); \ } while (0) -#define DUK_HBUFFER_SUB_SIZE(x,dv) do { \ +#define DUK_HBUFFER_SUB_SIZE(x, dv) \ + do { \ (x)->hdr.h_flags -= ((dv) << 16); \ } while (0) #else -#define DUK_HBUFFER_GET_SIZE(x) (((duk_hbuffer *) (x))->size) -#define DUK_HBUFFER_SET_SIZE(x,v) do { \ +#define DUK_HBUFFER_GET_SIZE(x) (((duk_hbuffer *) (x))->size) +#define DUK_HBUFFER_SET_SIZE(x, v) \ + do { \ ((duk_hbuffer *) (x))->size = (v); \ } while (0) -#define DUK_HBUFFER_ADD_SIZE(x,dv) do { \ +#define DUK_HBUFFER_ADD_SIZE(x, dv) \ + do { \ (x)->size += (dv); \ } while (0) -#define DUK_HBUFFER_SUB_SIZE(x,dv) do { \ +#define DUK_HBUFFER_SUB_SIZE(x, dv) \ + do { \ (x)->size -= (dv); \ } while (0) #endif -#define DUK_HBUFFER_FIXED_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_FIXED_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x)) +#define DUK_HBUFFER_FIXED_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) +#define DUK_HBUFFER_FIXED_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x)) #define DUK_HBUFFER_DYNAMIC_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_DYNAMIC_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) -#define DUK_HBUFFER_DYNAMIC_ADD_SIZE(x,dv) DUK_HBUFFER_ADD_SIZE((duk_hbuffer *) (x), (dv)) -#define DUK_HBUFFER_DYNAMIC_SUB_SIZE(x,dv) DUK_HBUFFER_SUB_SIZE((duk_hbuffer *) (x), (dv)) +#define DUK_HBUFFER_DYNAMIC_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) +#define DUK_HBUFFER_DYNAMIC_ADD_SIZE(x, dv) DUK_HBUFFER_ADD_SIZE((duk_hbuffer *) (x), (dv)) +#define DUK_HBUFFER_DYNAMIC_SUB_SIZE(x, dv) DUK_HBUFFER_SUB_SIZE((duk_hbuffer *) (x), (dv)) #define DUK_HBUFFER_EXTERNAL_GET_SIZE(x) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) (x)) -#define DUK_HBUFFER_EXTERNAL_SET_SIZE(x,v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) +#define DUK_HBUFFER_EXTERNAL_SET_SIZE(x, v) DUK_HBUFFER_SET_SIZE((duk_hbuffer *) (x), (v)) -#define DUK_HBUFFER_FIXED_GET_DATA_PTR(heap,x) ((duk_uint8_t *) (((duk_hbuffer_fixed *) (void *) (x)) + 1)) +#define DUK_HBUFFER_FIXED_GET_DATA_PTR(heap, x) ((duk_uint8_t *) (((duk_hbuffer_fixed *) (void *) (x)) + 1)) #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap,x) \ +#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, x) \ ((void *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, ((duk_heaphdr *) (x))->h_extra16)) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, x, v) \ + do { \ ((duk_heaphdr *) (x))->h_extra16 = DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (void *) (v)); \ } while (0) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap,x) do { \ - ((duk_heaphdr *) (x))->h_extra16 = 0; /* assume 0 <=> NULL */ \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap, x) \ + do { \ + ((duk_heaphdr *) (x))->h_extra16 = 0; /* assume 0 <=> NULL */ \ } while (0) #else -#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap,x) ((x)->curr_alloc) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, x) ((x)->curr_alloc) +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #endif @@ -8236,21 +8720,23 @@ * Duktape heap. */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap,x) \ - ((void *) (x)->curr_alloc) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap, x) ((void *) (x)->curr_alloc) +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #else -#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap,x) \ - ((void *) (x)->curr_alloc) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap,x,v) do { \ +#define DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(heap, x) ((void *) (x)->curr_alloc) +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(heap, x, v) \ + do { \ (x)->curr_alloc = (void *) (v); \ } while (0) -#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap,x) do { \ +#define DUK_HBUFFER_EXTERNAL_SET_DATA_PTR_NULL(heap, x) \ + do { \ (x)->curr_alloc = (void *) NULL; \ } while (0) #endif @@ -8259,32 +8745,31 @@ * size). May be NULL for zero size dynamic/external buffer. */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HBUFFER_GET_DATA_PTR(heap,x) ( \ - DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ - ( \ - DUK_HBUFFER_HAS_EXTERNAL((x)) ? \ - DUK_HBUFFER_EXTERNAL_GET_DATA_PTR((heap), (duk_hbuffer_external *) (x)) : \ - DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) \ - ) : \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x)) \ - ) +#define DUK_HBUFFER_GET_DATA_PTR(heap, x) \ + (DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ + (DUK_HBUFFER_HAS_EXTERNAL((x)) ? DUK_HBUFFER_EXTERNAL_GET_DATA_PTR((heap), (duk_hbuffer_external *) (x)) : \ + DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x))) : \ + DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x))) #else /* Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external * have the same layout so checking for fixed vs. dynamic (or external) is enough. */ -#define DUK_HBUFFER_GET_DATA_PTR(heap,x) ( \ - DUK_HBUFFER_HAS_DYNAMIC((x)) ? \ - DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) : \ - DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x)) \ - ) +#define DUK_HBUFFER_GET_DATA_PTR(heap, x) \ + (DUK_HBUFFER_HAS_DYNAMIC((x)) ? DUK_HBUFFER_DYNAMIC_GET_DATA_PTR((heap), (duk_hbuffer_dynamic *) (x)) : \ + DUK_HBUFFER_FIXED_GET_DATA_PTR((heap), (duk_hbuffer_fixed *) (void *) (x))) #endif /* Validity assert. */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hbuffer_assert_valid(duk_hbuffer *h); -#define DUK_HBUFFER_ASSERT_VALID(h) do { duk_hbuffer_assert_valid((h)); } while (0) +#define DUK_HBUFFER_ASSERT_VALID(h) \ + do { \ + duk_hbuffer_assert_valid((h)); \ + } while (0) #else -#define DUK_HBUFFER_ASSERT_VALID(h) do {} while (0) +#define DUK_HBUFFER_ASSERT_VALID(h) \ + do { \ + } while (0) #endif /* @@ -8382,9 +8867,9 @@ */ } #if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_GCC_ATTR) -__attribute__ ((aligned (8))) +__attribute__((aligned(8))) #elif (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_CLANG_ATTR) -__attribute__ ((aligned (8))) +__attribute__((aligned(8))) #endif ; #if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_MSVC_PRAGMA) @@ -8407,7 +8892,7 @@ #if defined(DUK_USE_HEAPPTR16) /* Stored in duk_heaphdr h_extra16. */ #else - void *curr_alloc; /* may be NULL if alloc_size == 0 */ + void *curr_alloc; /* may be NULL if alloc_size == 0 */ #endif /* @@ -8436,7 +8921,7 @@ /* Cannot be compressed as a heap pointer because may point to * an arbitrary address. */ - void *curr_alloc; /* may be NULL if alloc_size == 0 */ + void *curr_alloc; /* may be NULL if alloc_size == 0 */ }; /* @@ -8444,13 +8929,13 @@ */ DUK_INTERNAL_DECL duk_hbuffer *duk_hbuffer_alloc(duk_heap *heap, duk_size_t size, duk_small_uint_t flags, void **out_bufdata); -DUK_INTERNAL_DECL void *duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud); /* indirect allocs */ +DUK_INTERNAL_DECL void *duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud); /* indirect allocs */ /* dynamic buffer ops */ DUK_INTERNAL_DECL void duk_hbuffer_resize(duk_hthread *thr, duk_hbuffer_dynamic *buf, duk_size_t new_size); DUK_INTERNAL_DECL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *buf); -#endif /* DUK_HBUFFER_H_INCLUDED */ +#endif /* DUK_HBUFFER_H_INCLUDED */ /* #include duk_hproxy.h */ #line 1 "duk_hproxy.h" /* @@ -8462,9 +8947,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_hproxy_assert_valid(duk_hproxy *h); -#define DUK_HPROXY_ASSERT_VALID(h) do { duk_hproxy_assert_valid((h)); } while (0) +#define DUK_HPROXY_ASSERT_VALID(h) \ + do { \ + duk_hproxy_assert_valid((h)); \ + } while (0) #else -#define DUK_HPROXY_ASSERT_VALID(h) do {} while (0) +#define DUK_HPROXY_ASSERT_VALID(h) \ + do { \ + } while (0) #endif struct duk_hproxy { @@ -8478,7 +8968,7 @@ duk_hobject *handler; }; -#endif /* DUK_HPROXY_H_INCLUDED */ +#endif /* DUK_HPROXY_H_INCLUDED */ /* #include duk_heap.h */ #line 1 "duk_heap.h" /* @@ -8497,46 +8987,50 @@ * Heap flags */ -#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED (1U << 0) /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */ -#define DUK_HEAP_FLAG_INTERRUPT_RUNNING (1U << 1) /* executor interrupt running (used to avoid nested interrupts) */ -#define DUK_HEAP_FLAG_FINALIZER_NORESCUE (1U << 2) /* heap destruction ongoing, finalizer rescue no longer possible */ -#define DUK_HEAP_FLAG_DEBUGGER_PAUSED (1U << 3) /* debugger is paused: talk with debug client until step/resume */ - -#define DUK__HEAP_HAS_FLAGS(heap,bits) ((heap)->flags & (bits)) -#define DUK__HEAP_SET_FLAGS(heap,bits) do { \ +#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED \ + (1U << 0) /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */ +#define DUK_HEAP_FLAG_INTERRUPT_RUNNING (1U << 1) /* executor interrupt running (used to avoid nested interrupts) */ +#define DUK_HEAP_FLAG_FINALIZER_NORESCUE (1U << 2) /* heap destruction ongoing, finalizer rescue no longer possible */ +#define DUK_HEAP_FLAG_DEBUGGER_PAUSED (1U << 3) /* debugger is paused: talk with debug client until step/resume */ + +#define DUK__HEAP_HAS_FLAGS(heap, bits) ((heap)->flags & (bits)) +#define DUK__HEAP_SET_FLAGS(heap, bits) \ + do { \ (heap)->flags |= (bits); \ } while (0) -#define DUK__HEAP_CLEAR_FLAGS(heap,bits) do { \ +#define DUK__HEAP_CLEAR_FLAGS(heap, bits) \ + do { \ (heap)->flags &= ~(bits); \ } while (0) -#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_HAS_INTERRUPT_RUNNING(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_HAS_DEBUGGER_PAUSED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) - -#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_SET_INTERRUPT_RUNNING(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_SET_DEBUGGER_PAUSED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) - -#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) -#define DUK_HEAP_CLEAR_INTERRUPT_RUNNING(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) -#define DUK_HEAP_CLEAR_FINALIZER_NORESCUE(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) -#define DUK_HEAP_CLEAR_DEBUGGER_PAUSED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) +#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_HAS_INTERRUPT_RUNNING(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_HAS_DEBUGGER_PAUSED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) + +#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_SET_INTERRUPT_RUNNING(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_SET_DEBUGGER_PAUSED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) + +#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap) \ + DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED) +#define DUK_HEAP_CLEAR_INTERRUPT_RUNNING(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING) +#define DUK_HEAP_CLEAR_FINALIZER_NORESCUE(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE) +#define DUK_HEAP_CLEAR_DEBUGGER_PAUSED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED) /* * Longjmp types, also double as identifying continuation type for a rethrow (in 'finally') */ -#define DUK_LJ_TYPE_UNKNOWN 0 /* unused */ -#define DUK_LJ_TYPE_THROW 1 /* value1 -> error object */ -#define DUK_LJ_TYPE_YIELD 2 /* value1 -> yield value, iserror -> error / normal */ -#define DUK_LJ_TYPE_RESUME 3 /* value1 -> resume value, value2 -> resumee thread, iserror -> error/normal */ -#define DUK_LJ_TYPE_BREAK 4 /* value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_CONTINUE 5 /* value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_RETURN 6 /* value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN) */ -#define DUK_LJ_TYPE_NORMAL 7 /* no value, pseudo-type to indicate a normal continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_UNKNOWN 0 /* unused */ +#define DUK_LJ_TYPE_THROW 1 /* value1 -> error object */ +#define DUK_LJ_TYPE_YIELD 2 /* value1 -> yield value, iserror -> error / normal */ +#define DUK_LJ_TYPE_RESUME 3 /* value1 -> resume value, value2 -> resumee thread, iserror -> error/normal */ +#define DUK_LJ_TYPE_BREAK 4 /* value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_CONTINUE 5 /* value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_RETURN 6 /* value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN) */ +#define DUK_LJ_TYPE_NORMAL 7 /* no value, pseudo-type to indicate a normal continuation (for ENDFIN) */ /* * Mark-and-sweep flags @@ -8549,19 +9043,19 @@ /* Emergency mark-and-sweep: try extra hard, even at the cost of * performance. */ -#define DUK_MS_FLAG_EMERGENCY (1U << 0) +#define DUK_MS_FLAG_EMERGENCY (1U << 0) /* Postpone rescue decisions for reachable objects with FINALIZED set. * Used during finalize_list processing to avoid incorrect rescue * decisions due to finalize_list being a reachability root. */ -#define DUK_MS_FLAG_POSTPONE_RESCUE (1U << 1) +#define DUK_MS_FLAG_POSTPONE_RESCUE (1U << 1) /* Don't compact objects; needed during object property table resize * to prevent a recursive resize. It would suffice to protect only the * current object being resized, but this is not yet implemented. */ -#define DUK_MS_FLAG_NO_OBJECT_COMPACTION (1U << 2) +#define DUK_MS_FLAG_NO_OBJECT_COMPACTION (1U << 2) /* * Thread switching @@ -8572,9 +9066,10 @@ */ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK_HEAP_SWITCH_THREAD(heap,newthr) duk_heap_switch_thread((heap), (newthr)) +#define DUK_HEAP_SWITCH_THREAD(heap, newthr) duk_heap_switch_thread((heap), (newthr)) #else -#define DUK_HEAP_SWITCH_THREAD(heap,newthr) do { \ +#define DUK_HEAP_SWITCH_THREAD(heap, newthr) \ + do { \ (heap)->curr_thread = (newthr); \ } while (0) #endif @@ -8584,11 +9079,14 @@ */ #if defined(DUK_USE_DEBUG) -#define DUK_STATS_INC(heap,fieldname) do { \ +#define DUK_STATS_INC(heap, fieldname) \ + do { \ (heap)->fieldname += 1; \ } while (0) #else -#define DUK_STATS_INC(heap,fieldname) do {} while (0) +#define DUK_STATS_INC(heap, fieldname) \ + do { \ + } while (0) #endif /* @@ -8606,36 +9104,41 @@ * only during init phases). */ #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 12800L /* 50x heap size */ -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L -#else -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 256L /* 1x heap size */ -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L -#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 12800L /* 50x heap size */ +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L +#else +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT 256L /* 1x heap size */ +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD 1024L +#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L #endif /* GC torture. */ #if defined(DUK_USE_GC_TORTURE) -#define DUK_GC_TORTURE(heap) do { duk_heap_mark_and_sweep((heap), 0); } while (0) +#define DUK_GC_TORTURE(heap) \ + do { \ + duk_heap_mark_and_sweep((heap), 0); \ + } while (0) #else -#define DUK_GC_TORTURE(heap) do { } while (0) +#define DUK_GC_TORTURE(heap) \ + do { \ + } while (0) #endif /* Stringcache is used for speeding up char-offset-to-byte-offset * translations for non-ASCII strings. */ -#define DUK_HEAP_STRCACHE_SIZE 4 -#define DUK_HEAP_STRINGCACHE_NOCACHE_LIMIT 16 /* strings up to the this length are not cached */ +#define DUK_HEAP_STRCACHE_SIZE 4 +#define DUK_HEAP_STRINGCACHE_NOCACHE_LIMIT 16 /* strings up to the this length are not cached */ /* Some list management macros. */ -#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap,hdr) duk_heap_insert_into_heap_allocated((heap), (hdr)) +#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, hdr) duk_heap_insert_into_heap_allocated((heap), (hdr)) #if defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_HEAP_REMOVE_FROM_HEAP_ALLOCATED(heap,hdr) duk_heap_remove_from_heap_allocated((heap), (hdr)) +#define DUK_HEAP_REMOVE_FROM_HEAP_ALLOCATED(heap, hdr) duk_heap_remove_from_heap_allocated((heap), (hdr)) #endif #if defined(DUK_USE_FINALIZER_SUPPORT) -#define DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap,hdr) duk_heap_insert_into_finalize_list((heap), (hdr)) -#define DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(heap,hdr) duk_heap_remove_from_finalize_list((heap), (hdr)) +#define DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap, hdr) duk_heap_insert_into_finalize_list((heap), (hdr)) +#define DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(heap, hdr) duk_heap_remove_from_finalize_list((heap), (hdr)) #endif /* @@ -8644,30 +9147,24 @@ /* heap string indices are autogenerated in duk_strings.h */ #if defined(DUK_USE_ROM_STRINGS) -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) -#else /* DUK_USE_ROM_STRINGS */ +#define DUK_HEAP_GET_STRING(heap, idx) ((duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_stridx(idx))) +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (heap)->strs16(idx))) +#define DUK_HEAP_GET_STRING(heap, idx) ((duk_hstring *) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (heap)->strs16(idx))) #else -#define DUK_HEAP_GET_STRING(heap,idx) \ - ((heap)->strs(idx)) +#define DUK_HEAP_GET_STRING(heap, idx) ((heap)->strs(idx)) #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ /* * Raw memory calls: relative to heap, but no GC interaction */ -#define DUK_ALLOC_RAW(heap,size) \ - ((heap)->alloc_func((heap)->heap_udata, (size))) +#define DUK_ALLOC_RAW(heap, size) ((heap)->alloc_func((heap)->heap_udata, (size))) -#define DUK_REALLOC_RAW(heap,ptr,newsize) \ - ((heap)->realloc_func((heap)->heap_udata, (void *) (ptr), (newsize))) +#define DUK_REALLOC_RAW(heap, ptr, newsize) ((heap)->realloc_func((heap)->heap_udata, (void *) (ptr), (newsize))) -#define DUK_FREE_RAW(heap,ptr) \ - ((heap)->free_func((heap)->heap_udata, (void *) (ptr))) +#define DUK_FREE_RAW(heap, ptr) ((heap)->free_func((heap)->heap_udata, (void *) (ptr))) /* * Memory calls: relative to heap, GC interaction, but no error throwing. @@ -8700,11 +9197,11 @@ /* callback for indirect reallocs, request for current pointer */ typedef void *(*duk_mem_getptr)(duk_heap *heap, void *ud); -#define DUK_ALLOC(heap,size) duk_heap_mem_alloc((heap), (size)) -#define DUK_ALLOC_ZEROED(heap,size) duk_heap_mem_alloc_zeroed((heap), (size)) -#define DUK_REALLOC(heap,ptr,newsize) duk_heap_mem_realloc((heap), (ptr), (newsize)) -#define DUK_REALLOC_INDIRECT(heap,cb,ud,newsize) duk_heap_mem_realloc_indirect((heap), (cb), (ud), (newsize)) -#define DUK_FREE(heap,ptr) duk_heap_mem_free((heap), (ptr)) +#define DUK_ALLOC(heap, size) duk_heap_mem_alloc((heap), (size)) +#define DUK_ALLOC_ZEROED(heap, size) duk_heap_mem_alloc_zeroed((heap), (size)) +#define DUK_REALLOC(heap, ptr, newsize) duk_heap_mem_realloc((heap), (ptr), (newsize)) +#define DUK_REALLOC_INDIRECT(heap, cb, ud, newsize) duk_heap_mem_realloc_indirect((heap), (cb), (ud), (newsize)) +#define DUK_FREE(heap, ptr) duk_heap_mem_free((heap), (ptr)) /* * Checked allocation, relative to a thread @@ -8713,24 +9210,26 @@ * for convenience. */ -#define DUK_ALLOC_CHECKED(thr,size) duk_heap_mem_alloc_checked((thr), (size)) -#define DUK_ALLOC_CHECKED_ZEROED(thr,size) duk_heap_mem_alloc_checked_zeroed((thr), (size)) -#define DUK_FREE_CHECKED(thr,ptr) duk_heap_mem_free((thr)->heap, (ptr)) +#define DUK_ALLOC_CHECKED(thr, size) duk_heap_mem_alloc_checked((thr), (size)) +#define DUK_ALLOC_CHECKED_ZEROED(thr, size) duk_heap_mem_alloc_checked_zeroed((thr), (size)) +#define DUK_FREE_CHECKED(thr, ptr) duk_heap_mem_free((thr)->heap, (ptr)) /* * Memory constants */ -#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_LIMIT 10 /* Retry allocation after mark-and-sweep for this - * many times. A single mark-and-sweep round is - * not guaranteed to free all unreferenced memory - * because of finalization (in fact, ANY number of - * rounds is strictly not enough). - */ - -#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_EMERGENCY_LIMIT 3 /* Starting from this round, use emergency mode - * for mark-and-sweep. - */ +#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_LIMIT \ + 10 /* Retry allocation after mark-and-sweep for this \ + * many times. A single mark-and-sweep round is \ + * not guaranteed to free all unreferenced memory \ + * because of finalization (in fact, ANY number of \ + * rounds is strictly not enough). \ + */ + +#define DUK_HEAP_ALLOC_FAIL_MARKANDSWEEP_EMERGENCY_LIMIT \ + 3 /* Starting from this round, use emergency mode \ + * for mark-and-sweep. \ + */ /* * Debugger support @@ -8739,26 +9238,26 @@ /* Maximum number of breakpoints. Only breakpoints that are set are * consulted so increasing this has no performance impact. */ -#define DUK_HEAP_MAX_BREAKPOINTS 16 +#define DUK_HEAP_MAX_BREAKPOINTS 16 /* Opcode interval for a Date-based status/peek rate limit check. Only * relevant when debugger is attached. Requesting a timestamp may be a * slow operation on some platforms so this shouldn't be too low. On the * other hand a high value makes Duktape react to a pause request slowly. */ -#define DUK_HEAP_DBG_RATELIMIT_OPCODES 4000 +#define DUK_HEAP_DBG_RATELIMIT_OPCODES 4000 /* Milliseconds between status notify and transport peeks. */ -#define DUK_HEAP_DBG_RATELIMIT_MILLISECS 200 +#define DUK_HEAP_DBG_RATELIMIT_MILLISECS 200 /* Debugger pause flags. */ -#define DUK_PAUSE_FLAG_ONE_OPCODE (1U << 0) /* pause when a single opcode has been executed */ -#define DUK_PAUSE_FLAG_ONE_OPCODE_ACTIVE (1U << 1) /* one opcode pause actually active; artifact of current implementation */ -#define DUK_PAUSE_FLAG_LINE_CHANGE (1U << 2) /* pause when current line number changes */ -#define DUK_PAUSE_FLAG_FUNC_ENTRY (1U << 3) /* pause when entering a function */ -#define DUK_PAUSE_FLAG_FUNC_EXIT (1U << 4) /* pause when exiting current function */ -#define DUK_PAUSE_FLAG_CAUGHT_ERROR (1U << 5) /* pause when about to throw an error that is caught */ -#define DUK_PAUSE_FLAG_UNCAUGHT_ERROR (1U << 6) /* pause when about to throw an error that won't be caught */ +#define DUK_PAUSE_FLAG_ONE_OPCODE (1U << 0) /* pause when a single opcode has been executed */ +#define DUK_PAUSE_FLAG_ONE_OPCODE_ACTIVE (1U << 1) /* one opcode pause actually active; artifact of current implementation */ +#define DUK_PAUSE_FLAG_LINE_CHANGE (1U << 2) /* pause when current line number changes */ +#define DUK_PAUSE_FLAG_FUNC_ENTRY (1U << 3) /* pause when entering a function */ +#define DUK_PAUSE_FLAG_FUNC_EXIT (1U << 4) /* pause when exiting current function */ +#define DUK_PAUSE_FLAG_CAUGHT_ERROR (1U << 5) /* pause when about to throw an error that is caught */ +#define DUK_PAUSE_FLAG_UNCAUGHT_ERROR (1U << 6) /* pause when about to throw an error that won't be caught */ struct duk_breakpoint { duk_hstring *filename; @@ -8786,21 +9285,23 @@ */ struct duk_ljstate { - duk_jmpbuf *jmpbuf_ptr; /* current setjmp() catchpoint */ - duk_small_uint_t type; /* longjmp type */ - duk_bool_t iserror; /* isError flag for yield */ - duk_tval value1; /* 1st related value (type specific) */ - duk_tval value2; /* 2nd related value (type specific) */ + duk_jmpbuf *jmpbuf_ptr; /* current setjmp() catchpoint */ + duk_small_uint_t type; /* longjmp type */ + duk_bool_t iserror; /* isError flag for yield */ + duk_tval value1; /* 1st related value (type specific) */ + duk_tval value2; /* 2nd related value (type specific) */ }; -#define DUK_ASSERT_LJSTATE_UNSET(heap) do { \ +#define DUK_ASSERT_LJSTATE_UNSET(heap) \ + do { \ DUK_ASSERT(heap != NULL); \ DUK_ASSERT(heap->lj.type == DUK_LJ_TYPE_UNKNOWN); \ DUK_ASSERT(heap->lj.iserror == 0); \ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&heap->lj.value1)); \ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&heap->lj.value2)); \ } while (0) -#define DUK_ASSERT_LJSTATE_SET(heap) do { \ +#define DUK_ASSERT_LJSTATE_SET(heap) \ + do { \ DUK_ASSERT(heap != NULL); \ DUK_ASSERT(heap->lj.type != DUK_LJ_TYPE_UNKNOWN); \ } while (0) @@ -8820,9 +9321,14 @@ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL_DECL void duk_heap_assert_valid(duk_heap *heap); -#define DUK_HEAP_ASSERT_VALID(heap) do { duk_heap_assert_valid((heap)); } while (0) +#define DUK_HEAP_ASSERT_VALID(heap) \ + do { \ + duk_heap_assert_valid((heap)); \ + } while (0) #else -#define DUK_HEAP_ASSERT_VALID(heap) do {} while (0) +#define DUK_HEAP_ASSERT_VALID(heap) \ + do { \ + } while (0) #endif struct duk_heap { @@ -8976,9 +9482,9 @@ /* Random number state for duk_util_tinyrandom.c. */ #if !defined(DUK_USE_GET_RANDOM_DOUBLE) #if defined(DUK_USE_PREFER_SIZE) || !defined(DUK_USE_64BIT_OPS) - duk_uint32_t rnd_state; /* State for Shamir's three-op algorithm */ + duk_uint32_t rnd_state; /* State for Shamir's three-op algorithm */ #else - duk_uint64_t rnd_state2; /* State for xoroshiro128+ */ + duk_uint64_t rnd_state2; /* State for xoroshiro128+ */ #endif #endif @@ -9001,8 +9507,8 @@ /* Debugger state. */ #if defined(DUK_USE_DEBUGGER_SUPPORT) /* Callbacks and udata; dbg_read_cb != NULL is used to indicate attached state. */ - duk_debug_read_function dbg_read_cb; /* required, NULL implies detached */ - duk_debug_write_function dbg_write_cb; /* required */ + duk_debug_read_function dbg_read_cb; /* required, NULL implies detached */ + duk_debug_write_function dbg_write_cb; /* required */ duk_debug_peek_function dbg_peek_cb; duk_debug_read_flush_function dbg_read_flush_cb; duk_debug_write_flush_function dbg_write_flush_cb; @@ -9011,29 +9517,32 @@ void *dbg_udata; /* The following are only relevant when debugger is attached. */ - duk_bool_t dbg_processing; /* currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval) */ - duk_bool_t dbg_state_dirty; /* resend state next time executor is about to run */ - duk_bool_t dbg_force_restart; /* force executor restart to recheck breakpoints; used to handle function returns (see GH-303) */ - duk_bool_t dbg_detaching; /* debugger detaching; used to avoid calling detach handler recursively */ - duk_small_uint_t dbg_pause_flags; /* flags for automatic pause behavior */ - duk_activation *dbg_pause_act; /* activation related to pause behavior (pause on line change, function entry/exit) */ - duk_uint32_t dbg_pause_startline; /* starting line number for line change related pause behavior */ - duk_breakpoint dbg_breakpointsDUK_HEAP_MAX_BREAKPOINTS; /* breakpoints: 0,breakpoint_count gc reachable */ + duk_bool_t dbg_processing; /* currently processing messages or breakpoints: don't enter message processing recursively (e.g. + no breakpoints when processing debugger eval) */ + duk_bool_t dbg_state_dirty; /* resend state next time executor is about to run */ + duk_bool_t + dbg_force_restart; /* force executor restart to recheck breakpoints; used to handle function returns (see GH-303) */ + duk_bool_t dbg_detaching; /* debugger detaching; used to avoid calling detach handler recursively */ + duk_small_uint_t dbg_pause_flags; /* flags for automatic pause behavior */ + duk_activation *dbg_pause_act; /* activation related to pause behavior (pause on line change, function entry/exit) */ + duk_uint32_t dbg_pause_startline; /* starting line number for line change related pause behavior */ + duk_breakpoint dbg_breakpointsDUK_HEAP_MAX_BREAKPOINTS; /* breakpoints: 0,breakpoint_count gc reachable */ duk_small_uint_t dbg_breakpoint_count; - duk_breakpoint *dbg_breakpoints_activeDUK_HEAP_MAX_BREAKPOINTS + 1; /* currently active breakpoints: NULL term, borrowed pointers */ + duk_breakpoint + *dbg_breakpoints_activeDUK_HEAP_MAX_BREAKPOINTS + 1; /* currently active breakpoints: NULL term, borrowed pointers */ /* XXX: make active breakpoints actual copies instead of pointers? */ /* These are for rate limiting Status notifications and transport peeking. */ - duk_uint_t dbg_exec_counter; /* cumulative opcode execution count (overflows are OK) */ - duk_uint_t dbg_last_counter; /* value of dbg_exec_counter when we last did a Date-based check */ - duk_double_t dbg_last_time; /* time when status/peek was last done (Date-based rate limit) */ + duk_uint_t dbg_exec_counter; /* cumulative opcode execution count (overflows are OK) */ + duk_uint_t dbg_last_counter; /* value of dbg_exec_counter when we last did a Date-based check */ + duk_double_t dbg_last_time; /* time when status/peek was last done (Date-based rate limit) */ /* Used to support single-byte stream lookahead. */ duk_bool_t dbg_have_next_byte; duk_uint8_t dbg_next_byte; -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) - duk_bool_t dbg_calling_transport; /* transport call in progress, calling into Duktape forbidden */ + duk_bool_t dbg_calling_transport; /* transport call in progress, calling into Duktape forbidden */ #endif /* String intern table (weak refs). */ @@ -9042,12 +9551,12 @@ #else duk_hstring **strtable; #endif - duk_uint32_t st_mask; /* mask for lookup, st_size - 1 */ - duk_uint32_t st_size; /* stringtable size */ + duk_uint32_t st_mask; /* mask for lookup, st_size - 1 */ + duk_uint32_t st_size; /* stringtable size */ #if (DUK_USE_STRTAB_MINSIZE != DUK_USE_STRTAB_MAXSIZE) - duk_uint32_t st_count; /* string count for resize load factor checks */ + duk_uint32_t st_count; /* string count for resize load factor checks */ #endif - duk_bool_t st_resizing; /* string table is being resized; avoid recursive resize */ + duk_bool_t st_resizing; /* string table is being resized; avoid recursive resize */ /* String access cache (codepoint offset -> byte offset) for fast string * character looping; 'weak' reference which needs special handling in GC. @@ -9161,7 +9670,9 @@ DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen); DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_checked(duk_hthread *thr, const duk_uint8_t *str, duk_uint32_t len); #if defined(DUK_USE_LITCACHE_SIZE) -DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_literal_checked(duk_hthread *thr, const duk_uint8_t *str, duk_uint32_t blen); +DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_literal_checked(duk_hthread *thr, + const duk_uint8_t *str, + duk_uint32_t blen); #endif DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_u32(duk_heap *heap, duk_uint32_t val); DUK_INTERNAL_DECL duk_hstring *duk_heap_strtable_intern_u32_checked(duk_hthread *thr, duk_uint32_t val); @@ -9176,7 +9687,9 @@ #endif DUK_INTERNAL_DECL void duk_heap_strcache_string_remove(duk_heap *heap, duk_hstring *h); -DUK_INTERNAL_DECL duk_uint_fast32_t duk_heap_strcache_offset_char2byte(duk_hthread *thr, duk_hstring *h, duk_uint_fast32_t char_offset); +DUK_INTERNAL_DECL duk_uint_fast32_t duk_heap_strcache_offset_char2byte(duk_hthread *thr, + duk_hstring *h, + duk_uint_fast32_t char_offset); #if defined(DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS) DUK_INTERNAL_DECL void *duk_default_alloc_function(void *udata, duk_size_t size); @@ -9197,13 +9710,13 @@ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL_DECL void duk_heap_run_finalizer(duk_heap *heap, duk_hobject *obj); DUK_INTERNAL_DECL void duk_heap_process_finalize_list(duk_heap *heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL_DECL void duk_heap_mark_and_sweep(duk_heap *heap, duk_small_uint_t flags); DUK_INTERNAL_DECL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len); -#endif /* DUK_HEAP_H_INCLUDED */ +#endif /* DUK_HEAP_H_INCLUDED */ /* #include duk_debugger.h */ #line 1 "duk_debugger.h" #if !defined(DUK_DEBUGGER_H_INCLUDED) @@ -9212,77 +9725,77 @@ /* Debugger protocol version is defined in the public API header. */ /* Initial bytes for markers. */ -#define DUK_DBG_IB_EOM 0x00 -#define DUK_DBG_IB_REQUEST 0x01 -#define DUK_DBG_IB_REPLY 0x02 -#define DUK_DBG_IB_ERROR 0x03 -#define DUK_DBG_IB_NOTIFY 0x04 +#define DUK_DBG_IB_EOM 0x00 +#define DUK_DBG_IB_REQUEST 0x01 +#define DUK_DBG_IB_REPLY 0x02 +#define DUK_DBG_IB_ERROR 0x03 +#define DUK_DBG_IB_NOTIFY 0x04 /* Other initial bytes. */ -#define DUK_DBG_IB_INT4 0x10 -#define DUK_DBG_IB_STR4 0x11 -#define DUK_DBG_IB_STR2 0x12 -#define DUK_DBG_IB_BUF4 0x13 -#define DUK_DBG_IB_BUF2 0x14 -#define DUK_DBG_IB_UNUSED 0x15 -#define DUK_DBG_IB_UNDEFINED 0x16 -#define DUK_DBG_IB_NULL 0x17 -#define DUK_DBG_IB_TRUE 0x18 -#define DUK_DBG_IB_FALSE 0x19 -#define DUK_DBG_IB_NUMBER 0x1a -#define DUK_DBG_IB_OBJECT 0x1b -#define DUK_DBG_IB_POINTER 0x1c -#define DUK_DBG_IB_LIGHTFUNC 0x1d -#define DUK_DBG_IB_HEAPPTR 0x1e +#define DUK_DBG_IB_INT4 0x10 +#define DUK_DBG_IB_STR4 0x11 +#define DUK_DBG_IB_STR2 0x12 +#define DUK_DBG_IB_BUF4 0x13 +#define DUK_DBG_IB_BUF2 0x14 +#define DUK_DBG_IB_UNUSED 0x15 +#define DUK_DBG_IB_UNDEFINED 0x16 +#define DUK_DBG_IB_NULL 0x17 +#define DUK_DBG_IB_TRUE 0x18 +#define DUK_DBG_IB_FALSE 0x19 +#define DUK_DBG_IB_NUMBER 0x1a +#define DUK_DBG_IB_OBJECT 0x1b +#define DUK_DBG_IB_POINTER 0x1c +#define DUK_DBG_IB_LIGHTFUNC 0x1d +#define DUK_DBG_IB_HEAPPTR 0x1e /* The short string/integer initial bytes starting from 0x60 don't have * defines now. */ /* Error codes. */ -#define DUK_DBG_ERR_UNKNOWN 0x00 -#define DUK_DBG_ERR_UNSUPPORTED 0x01 -#define DUK_DBG_ERR_TOOMANY 0x02 -#define DUK_DBG_ERR_NOTFOUND 0x03 -#define DUK_DBG_ERR_APPLICATION 0x04 +#define DUK_DBG_ERR_UNKNOWN 0x00 +#define DUK_DBG_ERR_UNSUPPORTED 0x01 +#define DUK_DBG_ERR_TOOMANY 0x02 +#define DUK_DBG_ERR_NOTFOUND 0x03 +#define DUK_DBG_ERR_APPLICATION 0x04 /* Commands and notifys initiated by Duktape. */ -#define DUK_DBG_CMD_STATUS 0x01 -#define DUK_DBG_CMD_UNUSED_2 0x02 /* Duktape 1.x: print notify */ -#define DUK_DBG_CMD_UNUSED_3 0x03 /* Duktape 1.x: alert notify */ -#define DUK_DBG_CMD_UNUSED_4 0x04 /* Duktape 1.x: log notify */ -#define DUK_DBG_CMD_THROW 0x05 -#define DUK_DBG_CMD_DETACHING 0x06 -#define DUK_DBG_CMD_APPNOTIFY 0x07 +#define DUK_DBG_CMD_STATUS 0x01 +#define DUK_DBG_CMD_UNUSED_2 0x02 /* Duktape 1.x: print notify */ +#define DUK_DBG_CMD_UNUSED_3 0x03 /* Duktape 1.x: alert notify */ +#define DUK_DBG_CMD_UNUSED_4 0x04 /* Duktape 1.x: log notify */ +#define DUK_DBG_CMD_THROW 0x05 +#define DUK_DBG_CMD_DETACHING 0x06 +#define DUK_DBG_CMD_APPNOTIFY 0x07 /* Commands initiated by debug client. */ -#define DUK_DBG_CMD_BASICINFO 0x10 -#define DUK_DBG_CMD_TRIGGERSTATUS 0x11 -#define DUK_DBG_CMD_PAUSE 0x12 -#define DUK_DBG_CMD_RESUME 0x13 -#define DUK_DBG_CMD_STEPINTO 0x14 -#define DUK_DBG_CMD_STEPOVER 0x15 -#define DUK_DBG_CMD_STEPOUT 0x16 -#define DUK_DBG_CMD_LISTBREAK 0x17 -#define DUK_DBG_CMD_ADDBREAK 0x18 -#define DUK_DBG_CMD_DELBREAK 0x19 -#define DUK_DBG_CMD_GETVAR 0x1a -#define DUK_DBG_CMD_PUTVAR 0x1b -#define DUK_DBG_CMD_GETCALLSTACK 0x1c -#define DUK_DBG_CMD_GETLOCALS 0x1d -#define DUK_DBG_CMD_EVAL 0x1e -#define DUK_DBG_CMD_DETACH 0x1f -#define DUK_DBG_CMD_DUMPHEAP 0x20 -#define DUK_DBG_CMD_GETBYTECODE 0x21 -#define DUK_DBG_CMD_APPREQUEST 0x22 -#define DUK_DBG_CMD_GETHEAPOBJINFO 0x23 -#define DUK_DBG_CMD_GETOBJPROPDESC 0x24 -#define DUK_DBG_CMD_GETOBJPROPDESCRANGE 0x25 +#define DUK_DBG_CMD_BASICINFO 0x10 +#define DUK_DBG_CMD_TRIGGERSTATUS 0x11 +#define DUK_DBG_CMD_PAUSE 0x12 +#define DUK_DBG_CMD_RESUME 0x13 +#define DUK_DBG_CMD_STEPINTO 0x14 +#define DUK_DBG_CMD_STEPOVER 0x15 +#define DUK_DBG_CMD_STEPOUT 0x16 +#define DUK_DBG_CMD_LISTBREAK 0x17 +#define DUK_DBG_CMD_ADDBREAK 0x18 +#define DUK_DBG_CMD_DELBREAK 0x19 +#define DUK_DBG_CMD_GETVAR 0x1a +#define DUK_DBG_CMD_PUTVAR 0x1b +#define DUK_DBG_CMD_GETCALLSTACK 0x1c +#define DUK_DBG_CMD_GETLOCALS 0x1d +#define DUK_DBG_CMD_EVAL 0x1e +#define DUK_DBG_CMD_DETACH 0x1f +#define DUK_DBG_CMD_DUMPHEAP 0x20 +#define DUK_DBG_CMD_GETBYTECODE 0x21 +#define DUK_DBG_CMD_APPREQUEST 0x22 +#define DUK_DBG_CMD_GETHEAPOBJINFO 0x23 +#define DUK_DBG_CMD_GETOBJPROPDESC 0x24 +#define DUK_DBG_CMD_GETOBJPROPDESCRANGE 0x25 /* The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx. * The remaining flags are specific to the debugger. */ -#define DUK_DBG_PROPFLAG_SYMBOL (1U << 8) -#define DUK_DBG_PROPFLAG_HIDDEN (1U << 9) +#define DUK_DBG_PROPFLAG_SYMBOL (1U << 8) +#define DUK_DBG_PROPFLAG_HIDDEN (1U << 9) #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_INTERNAL_DECL void duk_debug_do_detach(duk_heap *heap); @@ -9329,7 +9842,7 @@ #endif DUK_INTERNAL_DECL void duk_debug_write_hobject(duk_hthread *thr, duk_hobject *obj); DUK_INTERNAL_DECL void duk_debug_write_tval(duk_hthread *thr, duk_tval *tv); -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL_DECL void duk_debug_write_request(duk_hthread *thr, duk_small_uint_t command); #endif DUK_INTERNAL_DECL void duk_debug_write_reply(duk_hthread *thr); @@ -9354,9 +9867,9 @@ DUK_INTERNAL_DECL void duk_debug_set_paused(duk_heap *heap); DUK_INTERNAL_DECL void duk_debug_clear_paused(duk_heap *heap); DUK_INTERNAL_DECL void duk_debug_clear_pause_state(duk_heap *heap); -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ -#endif /* DUK_DEBUGGER_H_INCLUDED */ +#endif /* DUK_DEBUGGER_H_INCLUDED */ /* #include duk_debug.h */ #line 1 "duk_debug.h" /* @@ -9389,19 +9902,25 @@ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) #define DUK_D(x) x #else -#define DUK_D(x) do { } while (0) /* omit */ +#define DUK_D(x) \ + do { \ + } while (0) /* omit */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) #define DUK_DD(x) x #else -#define DUK_DD(x) do { } while (0) /* omit */ +#define DUK_DD(x) \ + do { \ + } while (0) /* omit */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) #define DUK_DDD(x) x #else -#define DUK_DDD(x) do { } while (0) /* omit */ +#define DUK_DDD(x) \ + do { \ + } while (0) /* omit */ #endif /* @@ -9413,35 +9932,35 @@ /* Note: combining __FILE__, __LINE__, and __func__ into fmt would be * possible compile time, but waste some space with shared function names. */ -#define DUK__DEBUG_LOG(lev,...) duk_debug_log((duk_int_t) (lev), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, DUK_FUNC_MACRO, __VA_ARGS__); +#define DUK__DEBUG_LOG(lev, ...) \ + duk_debug_log((duk_int_t) (lev), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, DUK_FUNC_MACRO, __VA_ARGS__); #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) -#define DUK_DPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DEBUG, __VA_ARGS__) +#define DUK_DPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DEBUG, __VA_ARGS__) #else #define DUK_DPRINT(...) #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) -#define DUK_DDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDEBUG, __VA_ARGS__) +#define DUK_DDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDEBUG, __VA_ARGS__) #else #define DUK_DDPRINT(...) #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK_DDDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDDEBUG, __VA_ARGS__) +#define DUK_DDDPRINT(...) DUK__DEBUG_LOG(DUK_LEVEL_DDDEBUG, __VA_ARGS__) #else #define DUK_DDDPRINT(...) #endif -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ -#define DUK__DEBUG_STASH(lev) \ +#define DUK__DEBUG_STASH(lev) \ (void) DUK_SNPRINTF(duk_debug_file_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FILE_MACRO), \ - (void) (duk_debug_file_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ - (void) (duk_debug_line_stash = (duk_int_t) DUK_LINE_MACRO), \ - (void) DUK_SNPRINTF(duk_debug_func_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FUNC_MACRO), \ - (void) (duk_debug_func_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ - (void) (duk_debug_level_stash = (lev)) + (void) (duk_debug_file_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), \ + (void) (duk_debug_line_stash = (duk_int_t) DUK_LINE_MACRO), \ + (void) DUK_SNPRINTF(duk_debug_func_stash, DUK_DEBUG_STASH_SIZE, "%s", (const char *) DUK_FUNC_MACRO), \ + (void) (duk_debug_func_stashDUK_DEBUG_STASH_SIZE - 1 = (char) 0), (void) (duk_debug_level_stash = (lev)) /* Without variadic macros resort to comma expression trickery to handle debug * prints. This generates a lot of harmless warnings. These hacks are not @@ -9450,34 +9969,40 @@ */ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 0) -#define DUK_DPRINT DUK__DEBUG_STASH(DUK_LEVEL_DEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DPRINT DUK__DEBUG_STASH(DUK_LEVEL_DEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ +#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) -#define DUK_DDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DDPRINT 0 && /* args */ +#define DUK_DDPRINT 0 && /* args */ #endif #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK_DDDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDDEBUG), (void) duk_debug_log /* args go here in parens */ +#define DUK_DDDPRINT DUK__DEBUG_STASH(DUK_LEVEL_DDDEBUG), (void) duk_debug_log /* args go here in parens */ #else -#define DUK_DDDPRINT 0 && /* args */ +#define DUK_DDDPRINT 0 && /* args */ #endif -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#else /* DUK_USE_DEBUG */ +#else /* DUK_USE_DEBUG */ /* * Exposed debug macros: debugging disabled */ -#define DUK_D(x) do { } while (0) /* omit */ -#define DUK_DD(x) do { } while (0) /* omit */ -#define DUK_DDD(x) do { } while (0) /* omit */ +#define DUK_D(x) \ + do { \ + } while (0) /* omit */ +#define DUK_DD(x) \ + do { \ + } while (0) /* omit */ +#define DUK_DDD(x) \ + do { \ + } while (0) /* omit */ #if defined(DUK_USE_VARIADIC_MACROS) @@ -9485,15 +10010,15 @@ #define DUK_DDPRINT(...) #define DUK_DDDPRINT(...) -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ -#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ -#define DUK_DDPRINT 0 && /* args */ -#define DUK_DDDPRINT 0 && /* args */ +#define DUK_DPRINT 0 && /* args go here as a comma expression in parens */ +#define DUK_DDPRINT 0 && /* args */ +#define DUK_DDDPRINT 0 && /* args */ -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Structs @@ -9514,16 +10039,16 @@ #if defined(DUK_USE_DEBUG) DUK_INTERNAL_DECL duk_int_t duk_debug_vsnprintf(char *str, duk_size_t size, const char *format, va_list ap); -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL_DECL duk_int_t duk_debug_snprintf(char *str, duk_size_t size, const char *format, ...); #endif DUK_INTERNAL_DECL void duk_debug_format_funcptr(char *buf, duk_size_t buf_size, duk_uint8_t *fptr, duk_size_t fptr_size); #if defined(DUK_USE_VARIADIC_MACROS) DUK_INTERNAL_DECL void duk_debug_log(duk_int_t level, const char *file, duk_int_t line, const char *func, const char *fmt, ...); -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ /* parameter passing, not thread safe */ -#define DUK_DEBUG_STASH_SIZE 128 +#define DUK_DEBUG_STASH_SIZE 128 #if !defined(DUK_SINGLE_FILE) DUK_INTERNAL_DECL char duk_debug_file_stashDUK_DEBUG_STASH_SIZE; DUK_INTERNAL_DECL duk_int_t duk_debug_line_stash; @@ -9531,7 +10056,7 @@ DUK_INTERNAL_DECL duk_int_t duk_debug_level_stash; #endif DUK_INTERNAL_DECL void duk_debug_log(const char *fmt, ...); -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ DUK_INTERNAL_DECL void duk_fb_put_bytes(duk_fixedbuffer *fb, const duk_uint8_t *buffer, duk_size_t length); DUK_INTERNAL_DECL void duk_fb_put_byte(duk_fixedbuffer *fb, duk_uint8_t x); @@ -9540,9 +10065,9 @@ DUK_INTERNAL_DECL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size); DUK_INTERNAL_DECL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb); -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ -#endif /* DUK_DEBUG_H_INCLUDED */ +#endif /* DUK_DEBUG_H_INCLUDED */ /* #include duk_error.h */ #line 1 "duk_error.h" /* @@ -9600,79 +10125,153 @@ /* Because there are quite many call sites, pack error code (require at most * 8-bit) into a single argument. */ -#define DUK_ERROR(thr,err,msg) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ +#define DUK_ERROR(thr, err, msg) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ duk_err_handle_error((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (msg)); \ } while (0) -#define DUK_ERROR_RAW(thr,file,line,err,msg) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ +#define DUK_ERROR_RAW(thr, file, line, err, msg) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ duk_err_handle_error((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (msg)); \ } while (0) -#define DUK_ERROR_FMT1(thr,err,fmt,arg1) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1)); \ - } while (0) -#define DUK_ERROR_RAW_FMT1(thr,file,line,err,fmt,arg1) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1)); \ - } while (0) - -#define DUK_ERROR_FMT2(thr,err,fmt,arg1,arg2) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2)); \ - } while (0) -#define DUK_ERROR_RAW_FMT2(thr,file,line,err,fmt,arg1,arg2) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2)); \ - } while (0) - -#define DUK_ERROR_FMT3(thr,err,fmt,arg1,arg2,arg3) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3)); \ - } while (0) -#define DUK_ERROR_RAW_FMT3(thr,file,line,err,fmt,arg1,arg2,arg3) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3)); \ - } while (0) - -#define DUK_ERROR_FMT4(thr,err,fmt,arg1,arg2,arg3,arg4) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), DUK_FILE_MACRO, (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3), (arg4)); \ - } while (0) -#define DUK_ERROR_RAW_FMT4(thr,file,line,err,fmt,arg1,arg2,arg3,arg4) do { \ - duk_errcode_t duk__err = (err); duk_int_t duk__line = (duk_int_t) (line); \ - DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ - duk_err_handle_error_fmt((thr), (file), (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), (fmt), (arg1), (arg2), (arg3), (arg4)); \ - } while (0) - -#else /* DUK_USE_VERBOSE_ERRORS */ - -#define DUK_ERROR(thr,err,msg) duk_err_handle_error((thr), (err)) -#define DUK_ERROR_RAW(thr,file,line,err,msg) duk_err_handle_error((thr), (err)) +#define DUK_ERROR_FMT1(thr, err, fmt, arg1) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1)); \ + } while (0) +#define DUK_ERROR_RAW_FMT1(thr, file, line, err, fmt, arg1) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1)); \ + } while (0) + +#define DUK_ERROR_FMT2(thr, err, fmt, arg1, arg2) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2)); \ + } while (0) +#define DUK_ERROR_RAW_FMT2(thr, file, line, err, fmt, arg1, arg2) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2)); \ + } while (0) + +#define DUK_ERROR_FMT3(thr, err, fmt, arg1, arg2, arg3) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3)); \ + } while (0) +#define DUK_ERROR_RAW_FMT3(thr, file, line, err, fmt, arg1, arg2, arg3) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3)); \ + } while (0) + +#define DUK_ERROR_FMT4(thr, err, fmt, arg1, arg2, arg3, arg4) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) DUK_LINE_MACRO; \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + DUK_FILE_MACRO, \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3), \ + (arg4)); \ + } while (0) +#define DUK_ERROR_RAW_FMT4(thr, file, line, err, fmt, arg1, arg2, arg3, arg4) \ + do { \ + duk_errcode_t duk__err = (err); \ + duk_int_t duk__line = (duk_int_t) (line); \ + DUK_ASSERT(duk__err >= 0 && duk__err <= 0xff); \ + DUK_ASSERT(duk__line >= 0 && duk__line <= 0x00ffffffL); \ + duk_err_handle_error_fmt((thr), \ + (file), \ + (((duk_uint_t) duk__err) << 24) | ((duk_uint_t) duk__line), \ + (fmt), \ + (arg1), \ + (arg2), \ + (arg3), \ + (arg4)); \ + } while (0) + +#else /* DUK_USE_VERBOSE_ERRORS */ + +#define DUK_ERROR(thr, err, msg) duk_err_handle_error((thr), (err)) +#define DUK_ERROR_RAW(thr, file, line, err, msg) duk_err_handle_error((thr), (err)) + +#define DUK_ERROR_FMT1(thr, err, fmt, arg1) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT1(thr, file, line, err, fmt, arg1) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) + +#define DUK_ERROR_FMT2(thr, err, fmt, arg1, arg2) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT2(thr, file, line, err, fmt, arg1, arg2) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) -#define DUK_ERROR_FMT1(thr,err,fmt,arg1) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT1(thr,file,line,err,fmt,arg1) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) +#define DUK_ERROR_FMT3(thr, err, fmt, arg1, arg2, arg3) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT3(thr, file, line, err, fmt, arg1, arg2, arg3) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) -#define DUK_ERROR_FMT2(thr,err,fmt,arg1,arg2) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT2(thr,file,line,err,fmt,arg1,arg2) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) +#define DUK_ERROR_FMT4(thr, err, fmt, arg1, arg2, arg3, arg4) DUK_ERROR((thr), (err), (fmt)) +#define DUK_ERROR_RAW_FMT4(thr, file, line, err, fmt, arg1, arg2, arg3, arg4) DUK_ERROR_RAW((thr), (file), (line), (err), (fmt)) -#define DUK_ERROR_FMT3(thr,err,fmt,arg1,arg2,arg3) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT3(thr,file,line,err,fmt,arg1,arg2,arg3) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#define DUK_ERROR_FMT4(thr,err,fmt,arg1,arg2,arg3,arg4) DUK_ERROR((thr),(err),(fmt)) -#define DUK_ERROR_RAW_FMT4(thr,file,line,err,fmt,arg1,arg2,arg3,arg4) DUK_ERROR_RAW((thr),(file),(line),(err),(fmt)) - -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Fatal error without context @@ -9680,8 +10279,7 @@ * The macro is an expression to make it compatible with DUK_ASSERT_EXPR(). */ -#define DUK_FATAL_WITHOUT_CONTEXT(msg) \ - duk_default_fatal_handler(NULL, (msg)) +#define DUK_FATAL_WITHOUT_CONTEXT(msg) duk_default_fatal_handler(NULL, (msg)) /* * Error throwing helpers @@ -9706,196 +10304,252 @@ * vs. non-paranoid distinction affects only a few specific errors. */ #if defined(DUK_USE_PARANOID_ERRORS) -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_require_type_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx), (expectname)); \ } while (0) -#else /* DUK_USE_PARANOID_ERRORS */ -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#else /* DUK_USE_PARANOID_ERRORS */ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_require_type_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx), (expectname)); \ } while (0) -#endif /* DUK_USE_PARANOID_ERRORS */ +#endif /* DUK_USE_PARANOID_ERRORS */ -#define DUK_ERROR_INTERNAL(thr) do { \ +#define DUK_ERROR_INTERNAL(thr) \ + do { \ duk_err_error_internal((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_INTERNAL(thr) do { \ +#define DUK_DCERROR_INTERNAL(thr) \ + do { \ DUK_ERROR_INTERNAL((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_ALLOC_FAILED(thr) do { \ +#define DUK_ERROR_ALLOC_FAILED(thr) \ + do { \ duk_err_error_alloc_failed((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_ERROR_UNSUPPORTED(thr) do { \ +#define DUK_ERROR_UNSUPPORTED(thr) \ + do { \ DUK_ERROR((thr), DUK_ERR_ERROR, DUK_STR_UNSUPPORTED); \ } while (0) -#define DUK_DCERROR_UNSUPPORTED(thr) do { \ +#define DUK_DCERROR_UNSUPPORTED(thr) \ + do { \ DUK_ERROR_UNSUPPORTED((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_ERROR(thr,msg) do { \ +#define DUK_ERROR_ERROR(thr, msg) \ + do { \ duk_err_error((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \ } while (0) -#define DUK_ERROR_RANGE_INDEX(thr,idx) do { \ +#define DUK_ERROR_RANGE_INDEX(thr, idx) \ + do { \ duk_err_range_index((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (idx)); \ } while (0) -#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) do { \ +#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) \ + do { \ duk_err_range_push_beyond((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_ERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_ARGS); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_ARGS((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_COUNT); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_COUNT((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_ERROR_RANGE((thr), DUK_STR_INVALID_LENGTH); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_ERROR_RANGE_INVALID_LENGTH((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_RANGE(thr,msg) do { \ +#define DUK_ERROR_RANGE(thr, msg) \ + do { \ duk_err_range((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO, (msg)); \ } while (0) -#define DUK_ERROR_EVAL(thr,msg) do { \ +#define DUK_ERROR_EVAL(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_EVAL_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_REFERENCE(thr,msg) do { \ +#define DUK_ERROR_REFERENCE(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_REFERENCE_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_SYNTAX(thr,msg) do { \ +#define DUK_ERROR_SYNTAX(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_SYNTAX_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_ARGS(thr) \ + do { \ duk_err_type_invalid_args((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) \ + do { \ DUK_ERROR_TYPE_INVALID_ARGS((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type_invalid_state((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_STATE(thr) \ + do { \ DUK_ERROR_TYPE_INVALID_STATE((thr)); \ return 0; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type_invalid_trap_result((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ DUK_ERROR_TYPE((thr), DUK_STR_INVALID_TRAP_RESULT); \ } while (0) -#define DUK_ERROR_TYPE(thr,msg) do { \ +#define DUK_ERROR_TYPE(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_TYPE_ERROR, (msg)); \ } while (0) -#define DUK_ERROR_URI(thr,msg) do { \ +#define DUK_ERROR_URI(thr, msg) \ + do { \ DUK_ERROR((thr), DUK_ERR_URI_ERROR, (msg)); \ } while (0) -#else /* DUK_USE_VERBOSE_ERRORS */ +#else /* DUK_USE_VERBOSE_ERRORS */ /* Non-verbose errors for low memory targets: no file, line, or message. */ -#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr,idx,expectname,lowmemstr) do { \ +#define DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, expectname, lowmemstr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_INTERNAL(thr) do { \ +#define DUK_ERROR_INTERNAL(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_DCERROR_INTERNAL(thr) do { \ +#define DUK_DCERROR_INTERNAL(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_ERROR; \ } while (0) -#define DUK_ERROR_ALLOC_FAILED(thr) do { \ +#define DUK_ERROR_ALLOC_FAILED(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_ERROR_UNSUPPORTED(thr) do { \ +#define DUK_ERROR_UNSUPPORTED(thr) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_DCERROR_UNSUPPORTED(thr) do { \ +#define DUK_DCERROR_UNSUPPORTED(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_ERROR; \ } while (0) -#define DUK_ERROR_ERROR(thr,msg) do { \ +#define DUK_ERROR_ERROR(thr, msg) \ + do { \ duk_err_error((thr)); \ } while (0) -#define DUK_ERROR_RANGE_INDEX(thr,idx) do { \ +#define DUK_ERROR_RANGE_INDEX(thr, idx) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) do { \ +#define DUK_ERROR_RANGE_PUSH_BEYOND(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_ARGS(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_ARGS(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_COUNT(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) do { \ +#define DUK_DCERROR_RANGE_INVALID_LENGTH(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_RANGE_ERROR; \ } while (0) -#define DUK_ERROR_RANGE(thr,msg) do { \ +#define DUK_ERROR_RANGE(thr, msg) \ + do { \ duk_err_range((thr)); \ } while (0) -#define DUK_ERROR_EVAL(thr,msg) do { \ +#define DUK_ERROR_EVAL(thr, msg) \ + do { \ duk_err_eval((thr)); \ } while (0) -#define DUK_ERROR_REFERENCE(thr,msg) do { \ +#define DUK_ERROR_REFERENCE(thr, msg) \ + do { \ duk_err_reference((thr)); \ } while (0) -#define DUK_ERROR_SYNTAX(thr,msg) do { \ +#define DUK_ERROR_SYNTAX(thr, msg) \ + do { \ duk_err_syntax((thr)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_ARGS(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_ARGS(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_TYPE_ERROR; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_STATE(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_STATE(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_DCERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ DUK_UNREF((thr)); \ return DUK_RET_TYPE_ERROR; \ } while (0) -#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) do { \ +#define DUK_ERROR_TYPE_INVALID_TRAP_RESULT(thr) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_TYPE(thr,msg) do { \ +#define DUK_ERROR_TYPE(thr, msg) \ + do { \ duk_err_type((thr)); \ } while (0) -#define DUK_ERROR_URI(thr,msg) do { \ +#define DUK_ERROR_URI(thr, msg) \ + do { \ duk_err_uri((thr)); \ } while (0) -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Assert macro: failure causes a fatal error. @@ -9913,63 +10567,72 @@ * we don't care about assertion text size because they're not used in production * builds. */ -#define DUK_ASSERT(x) do { \ - if (!(x)) { \ - DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x \ - " (" DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"); \ - } \ +#define DUK_ASSERT(x) \ + do { \ + if (!(x)) { \ + DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x " (" DUK_FILE_MACRO \ + ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"); \ + } \ } while (0) /* Assertion compatible inside a comma expression, evaluates to void. */ #define DUK_ASSERT_EXPR(x) \ - ((void) ((x) ? 0 : (DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x \ - " (" DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"), 0))) + ((void) ((x) ? 0 : \ + (DUK_FATAL_WITHOUT_CONTEXT("assertion failed: " #x " (" DUK_FILE_MACRO \ + ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO) ")"), \ + 0))) -#else /* DUK_USE_ASSERTIONS */ +#else /* DUK_USE_ASSERTIONS */ -#define DUK_ASSERT(x) do { /* assertion omitted */ } while (0) +#define DUK_ASSERT(x) \ + do { /* assertion omitted */ \ + } while (0) -#define DUK_ASSERT_EXPR(x) ((void) 0) +#define DUK_ASSERT_EXPR(x) ((void) 0) -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* this variant is used when an assert would generate a compile warning by * being always true (e.g. >= 0 comparison for an unsigned value */ -#define DUK_ASSERT_DISABLE(x) do { /* assertion disabled */ } while (0) +#define DUK_ASSERT_DISABLE(x) \ + do { /* assertion disabled */ \ + } while (0) /* * Assertion helpers */ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) -#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) do { \ +#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) \ + do { \ DUK_ASSERT((h) == NULL || DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) (h)) > 0); \ } while (0) -#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) do { \ +#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) \ + do { \ if ((tv) != NULL && DUK_TVAL_IS_HEAP_ALLOCATED((tv))) { \ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(DUK_TVAL_GET_HEAPHDR((tv))) > 0); \ } \ } while (0) #else -#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) /* no refcount check */ -#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) /* no refcount check */ +#define DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(h) /* no refcount check */ +#define DUK_ASSERT_REFCOUNT_NONZERO_TVAL(tv) /* no refcount check */ #endif -#define DUK_ASSERT_TOP(ctx,n) DUK_ASSERT((duk_idx_t) duk_get_top((ctx)) == (duk_idx_t) (n)) +#define DUK_ASSERT_TOP(ctx, n) DUK_ASSERT((duk_idx_t) duk_get_top((ctx)) == (duk_idx_t) (n)) #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_PACKED_TVAL) -#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) do { \ +#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) \ + do { \ duk_double_union duk__assert_tmp_du; \ duk__assert_tmp_du.d = (dval); \ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&duk__assert_tmp_du)); \ } while (0) #else -#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) /* nop */ +#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) /* nop */ #endif -#define DUK_ASSERT_VS_SPACE(thr) \ - DUK_ASSERT(thr->valstack_top < thr->valstack_end) +#define DUK_ASSERT_VS_SPACE(thr) DUK_ASSERT(thr->valstack_top < thr->valstack_end) /* * Helper to initialize a memory area (e.g. struct) with garbage when @@ -9977,11 +10640,14 @@ */ #if defined(DUK_USE_ASSERTIONS) -#define DUK_ASSERT_SET_GARBAGE(ptr,size) do { \ +#define DUK_ASSERT_SET_GARBAGE(ptr, size) \ + do { \ duk_memset_unsafe((void *) (ptr), 0x5a, size); \ } while (0) #else -#define DUK_ASSERT_SET_GARBAGE(ptr,size) do {} while (0) +#define DUK_ASSERT_SET_GARBAGE(ptr, size) \ + do { \ + } while (0) #endif /* @@ -9992,16 +10658,18 @@ * or (b) Duktape calls which involve extending the valstack (e.g. getter call). */ -#define DUK_VALSTACK_ASSERT_EXTRA 5 /* this is added to checks to allow for Duktape - * API calls in addition to function's own use - */ +#define DUK_VALSTACK_ASSERT_EXTRA \ + 5 /* this is added to checks to allow for Duktape \ + * API calls in addition to function's own use \ + */ #if defined(DUK_USE_ASSERTIONS) -#define DUK_ASSERT_VALSTACK_SPACE(thr,n) do { \ +#define DUK_ASSERT_VALSTACK_SPACE(thr, n) \ + do { \ DUK_ASSERT((thr) != NULL); \ DUK_ASSERT((thr)->valstack_end - (thr)->valstack_top >= (n) + DUK_VALSTACK_ASSERT_EXTRA); \ } while (0) #else -#define DUK_ASSERT_VALSTACK_SPACE(thr,n) /* no valstack space check */ +#define DUK_ASSERT_VALSTACK_SPACE(thr, n) /* no valstack space check */ #endif /* @@ -10009,25 +10677,35 @@ */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...)); -#else /* DUK_USE_VERBOSE_ERRORS */ +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg)); +DUK_NORETURN(DUK_INTERNAL_DECL void + duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...)); +#else /* DUK_USE_VERBOSE_ERRORS */ DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_handle_error(duk_hthread *thr, duk_errcode_t code)); -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code, const char *msg, const char *filename, duk_int_t line)); +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, + duk_errcode_t code, + const char *msg, + const char *filename, + duk_int_t line)); #else DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code)); #endif DUK_NORETURN(DUK_INTERNAL_DECL void duk_error_throw_from_negative_rc(duk_hthread *thr, duk_ret_t rc)); -#define DUK_AUGMENT_FLAG_NOBLAME_FILELINE (1U << 0) /* if set, don't blame C file/line for .fileName and .lineNumber */ -#define DUK_AUGMENT_FLAG_SKIP_ONE (1U << 1) /* if set, skip topmost activation in traceback construction */ +#define DUK_AUGMENT_FLAG_NOBLAME_FILELINE (1U << 0) /* if set, don't blame C file/line for .fileName and .lineNumber */ +#define DUK_AUGMENT_FLAG_SKIP_ONE (1U << 1) /* if set, skip topmost activation in traceback construction */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *filename, duk_int_t line, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *filename, + duk_int_t line, + duk_small_uint_t flags); #endif #if defined(DUK_USE_AUGMENT_ERROR_THROW) DUK_INTERNAL_DECL void duk_err_augment_error_throw(duk_hthread *thr); @@ -10035,20 +10713,31 @@ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name)); -#else -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name)); +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name)); +#else +DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name)); #endif DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error_alloc_failed(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_range_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range_push_beyond(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); +DUK_NORETURN( + DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr, const char *filename, duk_int_t linenumber, const char *message)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_args(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_state(duk_hthread *thr, const char *filename, duk_int_t linenumber)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_type_invalid_trap_result(duk_hthread *thr, const char *filename, duk_int_t linenumber)); -#else /* DUK_VERBOSE_ERRORS */ +#else /* DUK_VERBOSE_ERRORS */ DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_error(duk_hthread *thr)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_range(duk_hthread *thr)); DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_eval(duk_hthread *thr)); @@ -10069,7 +10758,7 @@ DUK_INTERNAL_DECL duk_hobject *duk_error_prototype_from_code(duk_hthread *thr, duk_errcode_t err_code); -#endif /* DUK_ERROR_H_INCLUDED */ +#endif /* DUK_ERROR_H_INCLUDED */ /* #include duk_unicode.h */ #line 1 "duk_unicode.h" /* @@ -10083,10 +10772,10 @@ * UTF-8 / XUTF-8 / CESU-8 constants */ -#define DUK_UNICODE_MAX_XUTF8_LENGTH 7 /* up to 36 bit codepoints */ -#define DUK_UNICODE_MAX_XUTF8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ -#define DUK_UNICODE_MAX_CESU8_LENGTH 6 /* all codepoints up to U+10FFFF */ -#define DUK_UNICODE_MAX_CESU8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ +#define DUK_UNICODE_MAX_XUTF8_LENGTH 7 /* up to 36 bit codepoints */ +#define DUK_UNICODE_MAX_XUTF8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ +#define DUK_UNICODE_MAX_CESU8_LENGTH 6 /* all codepoints up to U+10FFFF */ +#define DUK_UNICODE_MAX_CESU8_BMP_LENGTH 3 /* all codepoints up to U+FFFF */ /* * Useful Unicode codepoints @@ -10095,9 +10784,11 @@ * in comparisons. */ -#define DUK_UNICODE_CP_ZWNJ 0x200cL /* zero-width non-joiner */ -#define DUK_UNICODE_CP_ZWJ 0x200dL /* zero-width joiner */ -#define DUK_UNICODE_CP_REPLACEMENT_CHARACTER 0xfffdL /* http://en.wikipedia.org/wiki/Replacement_character#Replacement_character */ +#define DUK_UNICODE_CP_ZWNJ 0x200cL /* zero-width non-joiner */ +#define DUK_UNICODE_CP_ZWJ 0x200dL /* zero-width joiner */ +#define DUK_UNICODE_CP_REPLACEMENT_CHARACTER \ + 0xfffdL /* http://en.wikipedia.org/wiki/Replacement_character#Replacement_character \ + */ /* * ASCII character constants @@ -10110,134 +10801,134 @@ * http://en.wikipedia.org/wiki/ASCII */ -#define DUK_ASC_NUL 0x00 -#define DUK_ASC_SOH 0x01 -#define DUK_ASC_STX 0x02 -#define DUK_ASC_ETX 0x03 -#define DUK_ASC_EOT 0x04 -#define DUK_ASC_ENQ 0x05 -#define DUK_ASC_ACK 0x06 -#define DUK_ASC_BEL 0x07 -#define DUK_ASC_BS 0x08 -#define DUK_ASC_HT 0x09 -#define DUK_ASC_LF 0x0a -#define DUK_ASC_VT 0x0b -#define DUK_ASC_FF 0x0c -#define DUK_ASC_CR 0x0d -#define DUK_ASC_SO 0x0e -#define DUK_ASC_SI 0x0f -#define DUK_ASC_DLE 0x10 -#define DUK_ASC_DC1 0x11 -#define DUK_ASC_DC2 0x12 -#define DUK_ASC_DC3 0x13 -#define DUK_ASC_DC4 0x14 -#define DUK_ASC_NAK 0x15 -#define DUK_ASC_SYN 0x16 -#define DUK_ASC_ETB 0x17 -#define DUK_ASC_CAN 0x18 -#define DUK_ASC_EM 0x19 -#define DUK_ASC_SUB 0x1a -#define DUK_ASC_ESC 0x1b -#define DUK_ASC_FS 0x1c -#define DUK_ASC_GS 0x1d -#define DUK_ASC_RS 0x1e -#define DUK_ASC_US 0x1f -#define DUK_ASC_SPACE 0x20 -#define DUK_ASC_EXCLAMATION 0x21 -#define DUK_ASC_DOUBLEQUOTE 0x22 -#define DUK_ASC_HASH 0x23 -#define DUK_ASC_DOLLAR 0x24 -#define DUK_ASC_PERCENT 0x25 -#define DUK_ASC_AMP 0x26 -#define DUK_ASC_SINGLEQUOTE 0x27 -#define DUK_ASC_LPAREN 0x28 -#define DUK_ASC_RPAREN 0x29 -#define DUK_ASC_STAR 0x2a -#define DUK_ASC_PLUS 0x2b -#define DUK_ASC_COMMA 0x2c -#define DUK_ASC_MINUS 0x2d -#define DUK_ASC_PERIOD 0x2e -#define DUK_ASC_SLASH 0x2f -#define DUK_ASC_0 0x30 -#define DUK_ASC_1 0x31 -#define DUK_ASC_2 0x32 -#define DUK_ASC_3 0x33 -#define DUK_ASC_4 0x34 -#define DUK_ASC_5 0x35 -#define DUK_ASC_6 0x36 -#define DUK_ASC_7 0x37 -#define DUK_ASC_8 0x38 -#define DUK_ASC_9 0x39 -#define DUK_ASC_COLON 0x3a -#define DUK_ASC_SEMICOLON 0x3b -#define DUK_ASC_LANGLE 0x3c -#define DUK_ASC_EQUALS 0x3d -#define DUK_ASC_RANGLE 0x3e -#define DUK_ASC_QUESTION 0x3f -#define DUK_ASC_ATSIGN 0x40 -#define DUK_ASC_UC_A 0x41 -#define DUK_ASC_UC_B 0x42 -#define DUK_ASC_UC_C 0x43 -#define DUK_ASC_UC_D 0x44 -#define DUK_ASC_UC_E 0x45 -#define DUK_ASC_UC_F 0x46 -#define DUK_ASC_UC_G 0x47 -#define DUK_ASC_UC_H 0x48 -#define DUK_ASC_UC_I 0x49 -#define DUK_ASC_UC_J 0x4a -#define DUK_ASC_UC_K 0x4b -#define DUK_ASC_UC_L 0x4c -#define DUK_ASC_UC_M 0x4d -#define DUK_ASC_UC_N 0x4e -#define DUK_ASC_UC_O 0x4f -#define DUK_ASC_UC_P 0x50 -#define DUK_ASC_UC_Q 0x51 -#define DUK_ASC_UC_R 0x52 -#define DUK_ASC_UC_S 0x53 -#define DUK_ASC_UC_T 0x54 -#define DUK_ASC_UC_U 0x55 -#define DUK_ASC_UC_V 0x56 -#define DUK_ASC_UC_W 0x57 -#define DUK_ASC_UC_X 0x58 -#define DUK_ASC_UC_Y 0x59 -#define DUK_ASC_UC_Z 0x5a -#define DUK_ASC_LBRACKET 0x5b -#define DUK_ASC_BACKSLASH 0x5c -#define DUK_ASC_RBRACKET 0x5d -#define DUK_ASC_CARET 0x5e -#define DUK_ASC_UNDERSCORE 0x5f -#define DUK_ASC_GRAVE 0x60 -#define DUK_ASC_LC_A 0x61 -#define DUK_ASC_LC_B 0x62 -#define DUK_ASC_LC_C 0x63 -#define DUK_ASC_LC_D 0x64 -#define DUK_ASC_LC_E 0x65 -#define DUK_ASC_LC_F 0x66 -#define DUK_ASC_LC_G 0x67 -#define DUK_ASC_LC_H 0x68 -#define DUK_ASC_LC_I 0x69 -#define DUK_ASC_LC_J 0x6a -#define DUK_ASC_LC_K 0x6b -#define DUK_ASC_LC_L 0x6c -#define DUK_ASC_LC_M 0x6d -#define DUK_ASC_LC_N 0x6e -#define DUK_ASC_LC_O 0x6f -#define DUK_ASC_LC_P 0x70 -#define DUK_ASC_LC_Q 0x71 -#define DUK_ASC_LC_R 0x72 -#define DUK_ASC_LC_S 0x73 -#define DUK_ASC_LC_T 0x74 -#define DUK_ASC_LC_U 0x75 -#define DUK_ASC_LC_V 0x76 -#define DUK_ASC_LC_W 0x77 -#define DUK_ASC_LC_X 0x78 -#define DUK_ASC_LC_Y 0x79 -#define DUK_ASC_LC_Z 0x7a -#define DUK_ASC_LCURLY 0x7b -#define DUK_ASC_PIPE 0x7c -#define DUK_ASC_RCURLY 0x7d -#define DUK_ASC_TILDE 0x7e -#define DUK_ASC_DEL 0x7f +#define DUK_ASC_NUL 0x00 +#define DUK_ASC_SOH 0x01 +#define DUK_ASC_STX 0x02 +#define DUK_ASC_ETX 0x03 +#define DUK_ASC_EOT 0x04 +#define DUK_ASC_ENQ 0x05 +#define DUK_ASC_ACK 0x06 +#define DUK_ASC_BEL 0x07 +#define DUK_ASC_BS 0x08 +#define DUK_ASC_HT 0x09 +#define DUK_ASC_LF 0x0a +#define DUK_ASC_VT 0x0b +#define DUK_ASC_FF 0x0c +#define DUK_ASC_CR 0x0d +#define DUK_ASC_SO 0x0e +#define DUK_ASC_SI 0x0f +#define DUK_ASC_DLE 0x10 +#define DUK_ASC_DC1 0x11 +#define DUK_ASC_DC2 0x12 +#define DUK_ASC_DC3 0x13 +#define DUK_ASC_DC4 0x14 +#define DUK_ASC_NAK 0x15 +#define DUK_ASC_SYN 0x16 +#define DUK_ASC_ETB 0x17 +#define DUK_ASC_CAN 0x18 +#define DUK_ASC_EM 0x19 +#define DUK_ASC_SUB 0x1a +#define DUK_ASC_ESC 0x1b +#define DUK_ASC_FS 0x1c +#define DUK_ASC_GS 0x1d +#define DUK_ASC_RS 0x1e +#define DUK_ASC_US 0x1f +#define DUK_ASC_SPACE 0x20 +#define DUK_ASC_EXCLAMATION 0x21 +#define DUK_ASC_DOUBLEQUOTE 0x22 +#define DUK_ASC_HASH 0x23 +#define DUK_ASC_DOLLAR 0x24 +#define DUK_ASC_PERCENT 0x25 +#define DUK_ASC_AMP 0x26 +#define DUK_ASC_SINGLEQUOTE 0x27 +#define DUK_ASC_LPAREN 0x28 +#define DUK_ASC_RPAREN 0x29 +#define DUK_ASC_STAR 0x2a +#define DUK_ASC_PLUS 0x2b +#define DUK_ASC_COMMA 0x2c +#define DUK_ASC_MINUS 0x2d +#define DUK_ASC_PERIOD 0x2e +#define DUK_ASC_SLASH 0x2f +#define DUK_ASC_0 0x30 +#define DUK_ASC_1 0x31 +#define DUK_ASC_2 0x32 +#define DUK_ASC_3 0x33 +#define DUK_ASC_4 0x34 +#define DUK_ASC_5 0x35 +#define DUK_ASC_6 0x36 +#define DUK_ASC_7 0x37 +#define DUK_ASC_8 0x38 +#define DUK_ASC_9 0x39 +#define DUK_ASC_COLON 0x3a +#define DUK_ASC_SEMICOLON 0x3b +#define DUK_ASC_LANGLE 0x3c +#define DUK_ASC_EQUALS 0x3d +#define DUK_ASC_RANGLE 0x3e +#define DUK_ASC_QUESTION 0x3f +#define DUK_ASC_ATSIGN 0x40 +#define DUK_ASC_UC_A 0x41 +#define DUK_ASC_UC_B 0x42 +#define DUK_ASC_UC_C 0x43 +#define DUK_ASC_UC_D 0x44 +#define DUK_ASC_UC_E 0x45 +#define DUK_ASC_UC_F 0x46 +#define DUK_ASC_UC_G 0x47 +#define DUK_ASC_UC_H 0x48 +#define DUK_ASC_UC_I 0x49 +#define DUK_ASC_UC_J 0x4a +#define DUK_ASC_UC_K 0x4b +#define DUK_ASC_UC_L 0x4c +#define DUK_ASC_UC_M 0x4d +#define DUK_ASC_UC_N 0x4e +#define DUK_ASC_UC_O 0x4f +#define DUK_ASC_UC_P 0x50 +#define DUK_ASC_UC_Q 0x51 +#define DUK_ASC_UC_R 0x52 +#define DUK_ASC_UC_S 0x53 +#define DUK_ASC_UC_T 0x54 +#define DUK_ASC_UC_U 0x55 +#define DUK_ASC_UC_V 0x56 +#define DUK_ASC_UC_W 0x57 +#define DUK_ASC_UC_X 0x58 +#define DUK_ASC_UC_Y 0x59 +#define DUK_ASC_UC_Z 0x5a +#define DUK_ASC_LBRACKET 0x5b +#define DUK_ASC_BACKSLASH 0x5c +#define DUK_ASC_RBRACKET 0x5d +#define DUK_ASC_CARET 0x5e +#define DUK_ASC_UNDERSCORE 0x5f +#define DUK_ASC_GRAVE 0x60 +#define DUK_ASC_LC_A 0x61 +#define DUK_ASC_LC_B 0x62 +#define DUK_ASC_LC_C 0x63 +#define DUK_ASC_LC_D 0x64 +#define DUK_ASC_LC_E 0x65 +#define DUK_ASC_LC_F 0x66 +#define DUK_ASC_LC_G 0x67 +#define DUK_ASC_LC_H 0x68 +#define DUK_ASC_LC_I 0x69 +#define DUK_ASC_LC_J 0x6a +#define DUK_ASC_LC_K 0x6b +#define DUK_ASC_LC_L 0x6c +#define DUK_ASC_LC_M 0x6d +#define DUK_ASC_LC_N 0x6e +#define DUK_ASC_LC_O 0x6f +#define DUK_ASC_LC_P 0x70 +#define DUK_ASC_LC_Q 0x71 +#define DUK_ASC_LC_R 0x72 +#define DUK_ASC_LC_S 0x73 +#define DUK_ASC_LC_T 0x74 +#define DUK_ASC_LC_U 0x75 +#define DUK_ASC_LC_V 0x76 +#define DUK_ASC_LC_W 0x77 +#define DUK_ASC_LC_X 0x78 +#define DUK_ASC_LC_Y 0x79 +#define DUK_ASC_LC_Z 0x7a +#define DUK_ASC_LCURLY 0x7b +#define DUK_ASC_PIPE 0x7c +#define DUK_ASC_RCURLY 0x7d +#define DUK_ASC_TILDE 0x7e +#define DUK_ASC_DEL 0x7f /* * Miscellaneous @@ -10246,7 +10937,7 @@ /* Uppercase A is 0x41, lowercase a is 0x61; OR 0x20 to convert uppercase * to lowercase. */ -#define DUK_LOWERCASE_CHAR_ASCII(x) ((x) | 0x20) +#define DUK_LOWERCASE_CHAR_ASCII(x) ((x) | 0x20) /* * Unicode tables @@ -10334,7 +11025,7 @@ DUK_INTERNAL_DECL const duk_uint16_t duk_unicode_re_ranges_not_white24; DUK_INTERNAL_DECL const duk_uint16_t duk_unicode_re_ranges_not_wordchar10; DUK_INTERNAL_DECL const duk_int8_t duk_is_idchar_tab128; -#endif /* !DUK_SINGLE_FILE */ +#endif /* !DUK_SINGLE_FILE */ /* * Prototypes @@ -10346,8 +11037,15 @@ #endif DUK_INTERNAL_DECL duk_small_int_t duk_unicode_encode_xutf8(duk_ucodepoint_t cp, duk_uint8_t *out); DUK_INTERNAL_DECL duk_small_int_t duk_unicode_encode_cesu8(duk_ucodepoint_t cp, duk_uint8_t *out); -DUK_INTERNAL_DECL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_ucodepoint_t *out_cp); -DUK_INTERNAL_DECL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end); +DUK_INTERNAL_DECL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_ucodepoint_t *out_cp); +DUK_INTERNAL_DECL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end); DUK_INTERNAL_DECL duk_size_t duk_unicode_unvalidated_utf8_length(const duk_uint8_t *data, duk_size_t blen); DUK_INTERNAL_DECL duk_bool_t duk_unicode_is_utf8_compatible(const duk_uint8_t *buf, duk_size_t len); DUK_INTERNAL_DECL duk_small_int_t duk_unicode_is_whitespace(duk_codepoint_t cp); @@ -10361,7 +11059,7 @@ DUK_INTERNAL_DECL duk_small_int_t duk_unicode_re_is_wordchar(duk_codepoint_t cp); #endif -#endif /* DUK_UNICODE_H_INCLUDED */ +#endif /* DUK_UNICODE_H_INCLUDED */ /* #include duk_json.h */ #line 1 "duk_json.h" /* @@ -10372,28 +11070,28 @@ #define DUK_JSON_H_INCLUDED /* Encoding/decoding flags */ -#define DUK_JSON_FLAG_ASCII_ONLY (1U << 0) /* escape any non-ASCII characters */ -#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1U << 1) /* avoid key quotes when key is an ASCII Identifier */ -#define DUK_JSON_FLAG_EXT_CUSTOM (1U << 2) /* extended types: custom encoding */ -#define DUK_JSON_FLAG_EXT_COMPATIBLE (1U << 3) /* extended types: compatible encoding */ +#define DUK_JSON_FLAG_ASCII_ONLY (1U << 0) /* escape any non-ASCII characters */ +#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1U << 1) /* avoid key quotes when key is an ASCII Identifier */ +#define DUK_JSON_FLAG_EXT_CUSTOM (1U << 2) /* extended types: custom encoding */ +#define DUK_JSON_FLAG_EXT_COMPATIBLE (1U << 3) /* extended types: compatible encoding */ /* How much stack to require on entry to object/array encode */ -#define DUK_JSON_ENC_REQSTACK 32 +#define DUK_JSON_ENC_REQSTACK 32 /* How much stack to require on entry to object/array decode */ -#define DUK_JSON_DEC_REQSTACK 32 +#define DUK_JSON_DEC_REQSTACK 32 /* How large a loop detection stack to use */ -#define DUK_JSON_ENC_LOOPARRAY 64 +#define DUK_JSON_ENC_LOOPARRAY 64 /* Encoding state. Heap object references are all borrowed. */ typedef struct { duk_hthread *thr; - duk_bufwriter_ctx bw; /* output bufwriter */ - duk_hobject *h_replacer; /* replacer function */ - duk_hstring *h_gap; /* gap (if empty string, NULL) */ - duk_idx_t idx_proplist; /* explicit PropertyList */ - duk_idx_t idx_loop; /* valstack index of loop detection object */ + duk_bufwriter_ctx bw; /* output bufwriter */ + duk_hobject *h_replacer; /* replacer function */ + duk_hstring *h_gap; /* gap (if empty string, NULL) */ + duk_idx_t idx_proplist; /* explicit PropertyList */ + duk_idx_t idx_loop; /* valstack index of loop detection object */ duk_small_uint_t flags; duk_small_uint_t flag_ascii_only; duk_small_uint_t flag_avoid_key_quotes; @@ -10404,7 +11102,7 @@ #endif duk_uint_t recursion_depth; duk_uint_t recursion_limit; - duk_uint_t mask_for_undefined; /* type bit mask: types which certainly produce 'undefined' */ + duk_uint_t mask_for_undefined; /* type bit mask: types which certainly produce 'undefined' */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) duk_small_uint_t stridx_custom_undefined; duk_small_uint_t stridx_custom_nan; @@ -10412,7 +11110,7 @@ duk_small_uint_t stridx_custom_posinf; duk_small_uint_t stridx_custom_function; #endif - duk_hobject *visitingDUK_JSON_ENC_LOOPARRAY; /* indexed by recursion_depth */ + duk_hobject *visitingDUK_JSON_ENC_LOOPARRAY; /* indexed by recursion_depth */ } duk_json_enc_ctx; typedef struct { @@ -10431,7 +11129,7 @@ duk_int_t recursion_limit; } duk_json_dec_ctx; -#endif /* DUK_JSON_H_INCLUDED */ +#endif /* DUK_JSON_H_INCLUDED */ /* #include duk_js.h */ #line 1 "duk_js.h" /* @@ -10442,21 +11140,22 @@ #define DUK_JS_H_INCLUDED /* Flags for call handling. Lowest flags must match bytecode DUK_BC_CALL_FLAG_xxx 1:1. */ -#define DUK_CALL_FLAG_TAILCALL (1U << 0) /* setup for a tail call */ -#define DUK_CALL_FLAG_CONSTRUCT (1U << 1) /* constructor call (i.e. called as 'new Foo()') */ -#define DUK_CALL_FLAG_CALLED_AS_EVAL (1U << 2) /* call was made using the identifier 'eval' */ -#define DUK_CALL_FLAG_ALLOW_ECMATOECMA (1U << 3) /* ecma-to-ecma call with executor reuse is possible */ -#define DUK_CALL_FLAG_DIRECT_EVAL (1U << 4) /* call is a direct eval call */ -#define DUK_CALL_FLAG_CONSTRUCT_PROXY (1U << 5) /* handled via 'construct' proxy trap, check return value invariant(s) */ -#define DUK_CALL_FLAG_DEFAULT_INSTANCE_UPDATED (1U << 6) /* prototype of 'default instance' updated, temporary flag in call handling */ +#define DUK_CALL_FLAG_TAILCALL (1U << 0) /* setup for a tail call */ +#define DUK_CALL_FLAG_CONSTRUCT (1U << 1) /* constructor call (i.e. called as 'new Foo()') */ +#define DUK_CALL_FLAG_CALLED_AS_EVAL (1U << 2) /* call was made using the identifier 'eval' */ +#define DUK_CALL_FLAG_ALLOW_ECMATOECMA (1U << 3) /* ecma-to-ecma call with executor reuse is possible */ +#define DUK_CALL_FLAG_DIRECT_EVAL (1U << 4) /* call is a direct eval call */ +#define DUK_CALL_FLAG_CONSTRUCT_PROXY (1U << 5) /* handled via 'construct' proxy trap, check return value invariant(s) */ +#define DUK_CALL_FLAG_DEFAULT_INSTANCE_UPDATED \ + (1U << 6) /* prototype of 'default instance' updated, temporary flag in call handling */ /* Flags for duk_js_equals_helper(). */ -#define DUK_EQUALS_FLAG_SAMEVALUE (1U << 0) /* use SameValue instead of non-strict equality */ -#define DUK_EQUALS_FLAG_STRICT (1U << 1) /* use strict equality instead of non-strict equality */ +#define DUK_EQUALS_FLAG_SAMEVALUE (1U << 0) /* use SameValue instead of non-strict equality */ +#define DUK_EQUALS_FLAG_STRICT (1U << 1) /* use strict equality instead of non-strict equality */ /* Flags for duk_js_compare_helper(). */ -#define DUK_COMPARE_FLAG_NEGATE (1U << 0) /* negate result */ -#define DUK_COMPARE_FLAG_EVAL_LEFT_FIRST (1U << 1) /* eval left argument first */ +#define DUK_COMPARE_FLAG_NEGATE (1U << 0) /* negate result */ +#define DUK_COMPARE_FLAG_EVAL_LEFT_FIRST (1U << 1) /* eval left argument first */ /* conversions, coercions, comparison, etc */ DUK_INTERNAL_DECL duk_bool_t duk_js_toboolean(duk_tval *tv); @@ -10472,9 +11171,12 @@ DUK_INTERNAL_DECL duk_uarridx_t duk_js_to_arrayindex_hstring_fast(duk_hstring *h); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_equals_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags); -DUK_INTERNAL_DECL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, const duk_uint8_t *buf2, duk_size_t len1, duk_size_t len2); +DUK_INTERNAL_DECL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, + const duk_uint8_t *buf2, + duk_size_t len1, + duk_size_t len2); DUK_INTERNAL_DECL duk_small_int_t duk_js_string_compare(duk_hstring *h1, duk_hstring *h2); -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL_DECL duk_small_int_t duk_js_buffer_compare(duk_heap *heap, duk_hbuffer *h1, duk_hbuffer *h2); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_compare_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags); @@ -10491,45 +11193,57 @@ DUK_INTERNAL_DECL double duk_js_arith_pow(double x, double y); DUK_INTERNAL_DECL double duk_js_arith_mod(double x, double y); -#define duk_js_equals(thr,tv_x,tv_y) \ - duk_js_equals_helper((thr), (tv_x), (tv_y), 0) -#define duk_js_strict_equals(tv_x,tv_y) \ - duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_STRICT) -#define duk_js_samevalue(tv_x,tv_y) \ - duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_SAMEVALUE) +#define duk_js_equals(thr, tv_x, tv_y) duk_js_equals_helper((thr), (tv_x), (tv_y), 0) +#define duk_js_strict_equals(tv_x, tv_y) duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_STRICT) +#define duk_js_samevalue(tv_x, tv_y) duk_js_equals_helper(NULL, (tv_x), (tv_y), DUK_EQUALS_FLAG_SAMEVALUE) /* E5 Sections 11.8.1, 11.8.5; x < y */ -#define duk_js_lessthan(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_x), (tv_Y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) +#define duk_js_lessthan(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_x), (tv_Y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) /* E5 Sections 11.8.2, 11.8.5; x > y --> y < x */ -#define duk_js_greaterthan(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_y), (tv_x), 0) +#define duk_js_greaterthan(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_y), (tv_x), 0) /* E5 Sections 11.8.3, 11.8.5; x <= y --> not (x > y) --> not (y < x) */ -#define duk_js_lessthanorequal(thr,tv_x,tv_y) \ - duk_js_compare_helper((thr), (tv_y), (tv_x), DUK_COMPARE_FLAG_NEGATE) +#define duk_js_lessthanorequal(thr, tv_x, tv_y) duk_js_compare_helper((thr), (tv_y), (tv_x), DUK_COMPARE_FLAG_NEGATE) /* E5 Sections 11.8.4, 11.8.5; x >= y --> not (x < y) */ -#define duk_js_greaterthanorequal(thr,tv_x,tv_y) \ +#define duk_js_greaterthanorequal(thr, tv_x, tv_y) \ duk_js_compare_helper((thr), (tv_x), (tv_y), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) /* identifiers and environment handling */ -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_hasvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_bool_t throw_flag); -DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag); -DUK_INTERNAL_DECL void duk_js_putvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_tval *val, duk_bool_t strict); -DUK_INTERNAL_DECL void duk_js_putvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_bool_t strict); -#if 0 /*unused*/ +DUK_INTERNAL_DECL duk_bool_t duk_js_getvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_bool_t throw_flag); +DUK_INTERNAL_DECL void duk_js_putvar_envrec(duk_hthread *thr, + duk_hobject *env, + duk_hstring *name, + duk_tval *val, + duk_bool_t strict); +DUK_INTERNAL_DECL void duk_js_putvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_tval *val, + duk_bool_t strict); +#if 0 /*unused*/ DUK_INTERNAL_DECL duk_bool_t duk_js_delvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name); #endif DUK_INTERNAL_DECL duk_bool_t duk_js_delvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name); -DUK_INTERNAL_DECL duk_bool_t duk_js_declvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_small_uint_t prop_flags, duk_bool_t is_func_decl); +DUK_INTERNAL_DECL duk_bool_t duk_js_declvar_activation(duk_hthread *thr, + duk_activation *act, + duk_hstring *name, + duk_tval *val, + duk_small_uint_t prop_flags, + duk_bool_t is_func_decl); DUK_INTERNAL_DECL void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, duk_activation *act); DUK_INTERNAL_DECL void duk_js_close_environment_record(duk_hthread *thr, duk_hobject *env); -DUK_INTERNAL_DECL duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, duk_hobject *func, duk_size_t bottom_byteoff); +DUK_INTERNAL_DECL duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, + duk_hobject *func, + duk_size_t bottom_byteoff); DUK_INTERNAL_DECL void duk_js_push_closure(duk_hthread *thr, duk_hcompfunc *fun_temp, duk_hobject *outer_var_env, @@ -10540,7 +11254,8 @@ DUK_INTERNAL_DECL void duk_native_stack_check(duk_hthread *thr); DUK_INTERNAL_DECL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags); DUK_INTERNAL_DECL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags); -DUK_INTERNAL_DECL duk_int_t duk_handle_safe_call(duk_hthread *thr, duk_safe_call_function func, void *udata, duk_idx_t num_stack_args, duk_idx_t num_stack_res); +DUK_INTERNAL_DECL duk_int_t +duk_handle_safe_call(duk_hthread *thr, duk_safe_call_function func, void *udata, duk_idx_t num_stack_args, duk_idx_t num_stack_res); DUK_INTERNAL_DECL void duk_call_construct_postprocess(duk_hthread *thr, duk_small_uint_t proxy_invariant); #if defined(DUK_USE_VERBOSE_ERRORS) DUK_INTERNAL_DECL void duk_call_setup_propcall_error(duk_hthread *thr, duk_tval *tv_base, duk_tval *tv_key); @@ -10549,7 +11264,7 @@ /* bytecode execution */ DUK_INTERNAL_DECL void duk_js_execute_bytecode(duk_hthread *exec_thr); -#endif /* DUK_JS_H_INCLUDED */ +#endif /* DUK_JS_H_INCLUDED */ /* #include duk_numconv.h */ #line 1 "duk_numconv.h" /* @@ -10563,23 +11278,23 @@ /* Output a specified number of digits instead of using the shortest * form. Used for toPrecision() and toFixed(). */ -#define DUK_N2S_FLAG_FIXED_FORMAT (1U << 0) +#define DUK_N2S_FLAG_FIXED_FORMAT (1U << 0) /* Force exponential format. Used for toExponential(). */ -#define DUK_N2S_FLAG_FORCE_EXP (1U << 1) +#define DUK_N2S_FLAG_FORCE_EXP (1U << 1) /* If number would need zero padding (for whole number part), use * exponential format instead. E.g. if input number is 12300, 3 * digits are generated ("123"), output "1.23e+4" instead of "12300". * Used for toPrecision(). */ -#define DUK_N2S_FLAG_NO_ZERO_PAD (1U << 2) +#define DUK_N2S_FLAG_NO_ZERO_PAD (1U << 2) /* Digit count indicates number of fractions (i.e. an absolute * digit index instead of a relative one). Used together with * DUK_N2S_FLAG_FIXED_FORMAT for toFixed(). */ -#define DUK_N2S_FLAG_FRACTION_DIGITS (1U << 3) +#define DUK_N2S_FLAG_FRACTION_DIGITS (1U << 3) /* * String-to-number conversion @@ -10593,69 +11308,72 @@ * radix 10, but with maximum radix (36) a safe limit is: * (10000000*36).toString(16) -> '15752a00' */ -#define DUK_S2N_MAX_EXPONENT 10000000L +#define DUK_S2N_MAX_EXPONENT 10000000L /* Trim white space (= allow leading and trailing whitespace) */ -#define DUK_S2N_FLAG_TRIM_WHITE (1U << 0) +#define DUK_S2N_FLAG_TRIM_WHITE (1U << 0) /* Allow exponent */ -#define DUK_S2N_FLAG_ALLOW_EXP (1U << 1) +#define DUK_S2N_FLAG_ALLOW_EXP (1U << 1) /* Allow trailing garbage (e.g. treat "123foo" as "123) */ -#define DUK_S2N_FLAG_ALLOW_GARBAGE (1U << 2) +#define DUK_S2N_FLAG_ALLOW_GARBAGE (1U << 2) /* Allow leading plus sign */ -#define DUK_S2N_FLAG_ALLOW_PLUS (1U << 3) +#define DUK_S2N_FLAG_ALLOW_PLUS (1U << 3) /* Allow leading minus sign */ -#define DUK_S2N_FLAG_ALLOW_MINUS (1U << 4) +#define DUK_S2N_FLAG_ALLOW_MINUS (1U << 4) /* Allow 'Infinity' */ -#define DUK_S2N_FLAG_ALLOW_INF (1U << 5) +#define DUK_S2N_FLAG_ALLOW_INF (1U << 5) /* Allow fraction part */ -#define DUK_S2N_FLAG_ALLOW_FRAC (1U << 6) +#define DUK_S2N_FLAG_ALLOW_FRAC (1U << 6) /* Allow naked fraction (e.g. ".123") */ -#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1U << 7) +#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1U << 7) /* Allow empty fraction (e.g. "123.") */ -#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1U << 8) +#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1U << 8) /* Allow empty string to be interpreted as 0 */ -#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1U << 9) +#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1U << 9) /* Allow leading zeroes (e.g. "0123" -> "123") */ -#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1U << 10) +#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1U << 10) /* Allow automatic detection of hex base ("0x" or "0X" prefix), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1U << 11) +#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1U << 11) /* Allow automatic detection of legacy octal base ("0n"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_LEGACY_OCT_INT (1U << 12) +#define DUK_S2N_FLAG_ALLOW_AUTO_LEGACY_OCT_INT (1U << 12) /* Allow automatic detection of ES2015 octal base ("0o123"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1U << 13) +#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1U << 13) /* Allow automatic detection of ES2015 binary base ("0b10001"), * overrides radix argument and forces integer mode. */ -#define DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT (1U << 14) +#define DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT (1U << 14) /* * Prototypes */ -DUK_INTERNAL_DECL void duk_numconv_stringify(duk_hthread *thr, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags); +DUK_INTERNAL_DECL void duk_numconv_stringify(duk_hthread *thr, + duk_small_int_t radix, + duk_small_int_t digits, + duk_small_uint_t flags); DUK_INTERNAL_DECL void duk_numconv_parse(duk_hthread *thr, duk_small_int_t radix, duk_small_uint_t flags); -#endif /* DUK_NUMCONV_H_INCLUDED */ +#endif /* DUK_NUMCONV_H_INCLUDED */ /* #include duk_bi_protos.h */ #line 1 "duk_bi_protos.h" /* @@ -10672,7 +11390,7 @@ * 32 * Include additional space to be safe. */ -#define DUK_BI_DATE_ISO8601_BUFSIZE 40 +#define DUK_BI_DATE_ISO8601_BUFSIZE 40 /* Helpers exposed for internal use */ DUK_INTERNAL_DECL void duk_bi_date_timeval_to_parts(duk_double_t d, duk_int_t *parts, duk_double_t *dparts, duk_small_uint_t flags); @@ -10710,7 +11428,10 @@ DUK_INTERNAL_DECL duk_bool_t duk_bi_date_parse_string_getdate(duk_hthread *thr, const char *str); #endif #if defined(DUK_USE_DATE_FMT_STRFTIME) -DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags); +DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, + duk_int_t *parts, + duk_int_t tzoffset, + duk_small_uint_t flags); #endif #if defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME) @@ -10721,10 +11442,7 @@ #endif DUK_INTERNAL_DECL -void duk_bi_json_parse_helper(duk_hthread *thr, - duk_idx_t idx_value, - duk_idx_t idx_reviver, - duk_small_uint_t flags); +void duk_bi_json_parse_helper(duk_hthread *thr, duk_idx_t idx_value, duk_idx_t idx_reviver, duk_small_uint_t flags); DUK_INTERNAL_DECL void duk_bi_json_stringify_helper(duk_hthread *thr, duk_idx_t idx_value, @@ -10738,7 +11456,7 @@ DUK_INTERNAL_DECL void duk_proxy_ownkeys_postprocess(duk_hthread *thr, duk_hobject *h_proxy_target, duk_uint_t flags); #endif -#endif /* DUK_BUILTIN_PROTOS_H_INCLUDED */ +#endif /* DUK_BUILTIN_PROTOS_H_INCLUDED */ /* #include duk_selftest.h */ #line 1 "duk_selftest.h" /* @@ -10755,10 +11473,10 @@ void *udata); #endif -#endif /* DUK_SELFTEST_H_INCLUDED */ +#endif /* DUK_SELFTEST_H_INCLUDED */ #line 76 "duk_internal.h" -#endif /* DUK_INTERNAL_H_INCLUDED */ +#endif /* DUK_INTERNAL_H_INCLUDED */ #line 10 "duk_replacements.c" #if defined(DUK_USE_COMPUTED_NAN) @@ -10854,7 +11572,7 @@ #error debugging enabled (DUK_USE_DEBUG) but DUK_USE_DEBUG_WRITE not defined #endif -#define DUK__DEBUG_BUFSIZE DUK_USE_DEBUG_BUFSIZE +#define DUK__DEBUG_BUFSIZE DUK_USE_DEBUG_BUFSIZE #if defined(DUK_USE_VARIADIC_MACROS) @@ -10882,7 +11600,7 @@ va_end(ap); } -#else /* DUK_USE_VARIADIC_MACROS */ +#else /* DUK_USE_VARIADIC_MACROS */ DUK_INTERNAL char duk_debug_file_stashDUK_DEBUG_STASH_SIZE; DUK_INTERNAL duk_int_t duk_debug_line_stash; @@ -10913,15 +11631,15 @@ va_end(ap); } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ -#else /* DUK_USE_DEBUG */ +#else /* DUK_USE_DEBUG */ /* * Debugging disabled */ -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* automatic undefs */ #undef DUK__DEBUG_BUFSIZE @@ -11291,7 +12009,7 @@ 137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35, 23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165, 19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70, -72,115,96,0,0,0,0,0,15,106,32,91,60,165,195,201,194,8,134,149,216,162,0, +72,115,96,0,0,0,0,0,27,234,32,91,60,165,195,201,194,8,134,149,216,162,0, 192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176, 195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20, 1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219, @@ -11491,7 +12209,7 @@ 137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35, 23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165, 19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70, -72,115,96,32,106,15,0,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, +72,115,96,32,106,27,128,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, 192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176, 195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20, 1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219, @@ -11691,7 +12409,7 @@ 137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35, 23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165, 19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70, -72,115,96,0,15,106,32,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, +72,115,96,0,27,234,32,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0, 192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176, 195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20, 1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219, @@ -11797,31 +12515,43 @@ /* #include duk_internal.h -> already included */ -#define DUK__ERRFMT_BUFSIZE 256 /* size for formatting buffers */ +#define DUK__ERRFMT_BUFSIZE 256 /* size for formatting buffers */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_INTERNAL DUK_COLD void duk_err_handle_error_fmt(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *fmt, ...) { +DUK_INTERNAL DUK_COLD void duk_err_handle_error_fmt(duk_hthread *thr, + const char *filename, + duk_uint_t line_and_code, + const char *fmt, + ...) { va_list ap; char msgDUK__ERRFMT_BUFSIZE; va_start(ap, fmt); (void) DUK_VSNPRINTF(msg, sizeof(msg), fmt, ap); msgsizeof(msg) - 1 = (char) 0; - duk_err_create_and_throw(thr, (duk_errcode_t) (line_and_code >> 24), msg, filename, (duk_int_t) (line_and_code & 0x00ffffffL)); - va_end(ap); /* dead code, but ensures portability (see Linux man page notes) */ + duk_err_create_and_throw(thr, + (duk_errcode_t) (line_and_code >> 24), + msg, + filename, + (duk_int_t) (line_and_code & 0x00ffffffL)); + va_end(ap); /* dead code, but ensures portability (see Linux man page notes) */ } DUK_INTERNAL DUK_COLD void duk_err_handle_error(duk_hthread *thr, const char *filename, duk_uint_t line_and_code, const char *msg) { - duk_err_create_and_throw(thr, (duk_errcode_t) (line_and_code >> 24), msg, filename, (duk_int_t) (line_and_code & 0x00ffffffL)); + duk_err_create_and_throw(thr, + (duk_errcode_t) (line_and_code >> 24), + msg, + filename, + (duk_int_t) (line_and_code & 0x00ffffffL)); } -#else /* DUK_USE_VERBOSE_ERRORS */ +#else /* DUK_USE_VERBOSE_ERRORS */ DUK_INTERNAL DUK_COLD void duk_err_handle_error(duk_hthread *thr, duk_errcode_t code) { duk_err_create_and_throw(thr, code); } -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* * Error throwing helpers @@ -11829,14 +12559,34 @@ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) -DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name) { - DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)", - expect_name, duk_get_type_name(thr, idx), (long) idx); -} -#else -DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name) { - DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)", - expect_name, duk_push_string_readable(thr, idx), (long) idx); +DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name) { + DUK_ERROR_RAW_FMT3(thr, + filename, + linenumber, + DUK_ERR_TYPE_ERROR, + "%s required, found %s (stack index %ld)", + expect_name, + duk_get_type_name(thr, idx), + (long) idx); +} +#else +DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, + const char *filename, + duk_int_t linenumber, + duk_idx_t idx, + const char *expect_name) { + DUK_ERROR_RAW_FMT3(thr, + filename, + linenumber, + DUK_ERR_TYPE_ERROR, + "%s required, found %s (stack index %ld)", + expect_name, + duk_push_string_readable(thr, idx), + (long) idx); } #endif DUK_INTERNAL DUK_COLD void duk_err_error_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber) { @@ -11964,14 +12714,14 @@ * 1: IdentifierStart and IdentifierPart * -1: IdentifierPart only */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00...0x0f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10...0x1f */ - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20...0x2f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, /* 0x30...0x3f */ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40...0x4f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50...0x5f */ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60...0x6f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70...0x7f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00...0x0f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10...0x1f */ + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20...0x2f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, /* 0x30...0x3f */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40...0x4f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x50...0x5f */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60...0x6f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70...0x7f */ }; #endif @@ -12021,15 +12771,13 @@ /* Encoded as surrogate pair, each encoding to 3 bytes for * 6 bytes total. Codepoints above U+10FFFF encode as 6 bytes * too, see duk_unicode_encode_cesu8(). - */ + */ return 3 + 3; } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ -DUK_INTERNAL const duk_uint8_t duk_unicode_xutf8_markers7 = { - 0x00, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe -}; +DUK_INTERNAL const duk_uint8_t duk_unicode_xutf8_markers7 = { 0x00, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe }; /* Encode to extended UTF-8; 'out' must have space for at least * DUK_UNICODE_MAX_XUTF8_LENGTH bytes. Allows encoding of any @@ -12044,7 +12792,7 @@ len = duk_unicode_get_xutf8_length(cp); DUK_ASSERT(len > 0); - marker = duk_unicode_xutf8_markerslen - 1; /* 64-bit OK because always >= 0 */ + marker = duk_unicode_xutf8_markerslen - 1; /* 64-bit OK because always >= 0 */ i = len; DUK_ASSERT(i > 0); @@ -12129,7 +12877,11 @@ } /* Decode helper. Return zero on error. */ -DUK_INTERNAL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_ucodepoint_t *out_cp) { +DUK_INTERNAL duk_small_int_t duk_unicode_decode_xutf8(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_ucodepoint_t *out_cp) { const duk_uint8_t *p; duk_uint32_t res; duk_uint_fast8_t ch; @@ -12191,7 +12943,7 @@ goto fail; } - DUK_ASSERT(p >= ptr_start); /* verified at beginning */ + DUK_ASSERT(p >= ptr_start); /* verified at beginning */ if (p + n > ptr_end) { /* check pointer at end */ goto fail; @@ -12217,12 +12969,15 @@ *out_cp = res; return 1; - fail: +fail: return 0; } /* used by e.g. duk_regexp_executor.c, string built-ins */ -DUK_INTERNAL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end) { +DUK_INTERNAL duk_ucodepoint_t duk_unicode_decode_xutf8_checked(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end) { duk_ucodepoint_t cp; if (duk_unicode_decode_xutf8(thr, ptr, ptr_start, ptr_end, &cp)) { @@ -12269,7 +13024,7 @@ DUK_ASSERT(clen <= blen); return clen; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* This seems like a good overall approach. Fast path for ASCII in 4 byte * blocks. */ @@ -12281,7 +13036,7 @@ duk_size_t ncont; duk_size_t clen; - ncont = 0; /* number of continuation (non-initial) bytes in 0x80,0xbf */ + ncont = 0; /* number of continuation (non-initial) bytes in 0x80,0xbf */ p = data; p_end = data + blen; if (blen < 16) { @@ -12306,7 +13061,7 @@ duk_uint32_t x; x = *p32++; if (DUK_LIKELY((x & 0x80808080UL) == 0)) { - ; /* ASCII fast path */ + ; /* ASCII fast path */ } else { /* Flip highest bit of each byte which changes * the bit pattern 10xxxxxx into 00xxxxxx which @@ -12330,7 +13085,7 @@ p = (const duk_uint8_t *) p32; /* Fall through to handle the rest. */ - skip_fastpath: +skip_fastpath: while (p != p_end) { duk_uint8_t x; x = *p++; @@ -12344,7 +13099,7 @@ DUK_ASSERT(clen <= blen); return clen; } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Check whether a string is UTF-8 compatible or not. */ DUK_INTERNAL duk_bool_t duk_unicode_is_utf8_compatible(const duk_uint8_t *buf, duk_size_t len) { @@ -12393,18 +13148,18 @@ * 1111 0xxx + 3*CONT -> 0x10000, 0x10ffff */ left = len - i; - if (t <= 0xdfU) { /* 1101 1111 = 0xdf */ - if (t <= 0xbfU) { /* 1011 1111 = 0xbf */ + if (t <= 0xdfU) { /* 1101 1111 = 0xdf */ + if (t <= 0xbfU) { /* 1011 1111 = 0xbf */ return 0; } ncont = 1; mincp = 0x80UL; cp = t & 0x1fU; - } else if (t <= 0xefU) { /* 1110 1111 = 0xef */ + } else if (t <= 0xefU) { /* 1110 1111 = 0xef */ ncont = 2; mincp = 0x800UL; cp = t & 0x0fU; - } else if (t <= 0xf7U) { /* 1111 0111 = 0xf7 */ + } else if (t <= 0xf7U) { /* 1111 0111 = 0xf7 */ ncont = 3; mincp = 0x10000UL; cp = t & 0x07U; @@ -12416,7 +13171,7 @@ } while (ncont > 0U) { t = bufi++; - if ((t & 0xc0U) != 0x80U) { /* 10xx xxxx */ + if ((t & 0xc0U) != 0x80U) { /* 10xx xxxx */ return 0; } cp = (cp << 6) + (t & 0x3fU); @@ -12482,7 +13237,9 @@ /* r1,r2 is the range */ DUK_DDD(DUK_DDDPRINT("duk__uni_range_match: cp=%06lx range=0x%06lx,0x%06lx", - (unsigned long) cp, (unsigned long) r1, (unsigned long) r2)); + (unsigned long) cp, + (unsigned long) r1, + (unsigned long) r2)); if (cp >= r1 && cp <= r2) { return 1; } @@ -12552,19 +13309,17 @@ /* cp == -1 (EOF) never matches and causes return value 0 */ lo = (duk_uint_fast8_t) (cp & 0xff); - hi = (duk_uint_fast32_t) (cp >> 8); /* does not fit into an uchar */ + hi = (duk_uint_fast32_t) (cp >> 8); /* does not fit into an uchar */ if (hi == 0x0000UL) { - if (lo == 0x09U || lo == 0x0bU || lo == 0x0cU || - lo == 0x20U || lo == 0xa0U) { + if (lo == 0x09U || lo == 0x0bU || lo == 0x0cU || lo == 0x20U || lo == 0xa0U) { return 1; } } else if (hi == 0x0020UL) { if (lo <= 0x0aU || lo == 0x2fU || lo == 0x5fU) { return 1; } - } else if (cp == 0x1680L || cp == 0x180eL || cp == 0x3000L || - cp == 0xfeffL) { + } else if (cp == 0x1680L || cp == 0x180eL || cp == 0x3000L || cp == 0xfeffL) { return 1; } @@ -12583,8 +13338,7 @@ * into a single line terminator. This must be handled by the caller. */ - if (cp == 0x000aL || cp == 0x000dL || cp == 0x2028L || - cp == 0x2029L) { + if (cp == 0x000aL || cp == 0x000dL || cp == 0x2028L || cp == 0x2029L) { return 1; } @@ -12635,9 +13389,7 @@ #if defined(DUK_USE_IDCHAR_FASTPATH) return (cp >= 0) && (duk_is_idchar_tabcp > 0); #else - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z') || - cp == '_' || cp == '$') { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || cp == '_' || cp == '$') { return 1; } return 0; @@ -12647,17 +13399,13 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - (duk_size_t) sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, (duk_size_t) sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp)) { return 1; } return 0; @@ -12724,10 +13472,7 @@ #if defined(DUK_USE_IDCHAR_FASTPATH) return (cp >= 0) && (duk_is_idchar_tabcp != 0); #else - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z') || - (cp >= '0' && cp <= '9') || - cp == '_' || cp == '$') { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || (cp >= '0' && cp <= '9') || cp == '_' || cp == '$') { return 1; } return 0; @@ -12737,20 +13482,14 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp) || - duk__uni_range_match(duk_unicode_idp_m_ids_noa, - sizeof(duk_unicode_idp_m_ids_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp) || + duk__uni_range_match(duk_unicode_idp_m_ids_noa, sizeof(duk_unicode_idp_m_ids_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp) || + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp) || duk__uni_range_match(duk_unicode_idp_m_ids_noabmp, sizeof(duk_unicode_idp_m_ids_noabmp), (duk_codepoint_t) cp)) { @@ -12786,8 +13525,7 @@ /* ASCII (and EOF) fast path -- quick accept and reject */ if (cp <= 0x7fL) { - if ((cp >= 'a' && cp <= 'z') || - (cp >= 'A' && cp <= 'Z')) { + if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z')) { return 1; } return 0; @@ -12796,20 +13534,14 @@ /* Non-ASCII slow path (range-by-range linear comparison), very slow */ #if defined(DUK_USE_SOURCE_NONBMP) - if (duk__uni_range_match(duk_unicode_ids_noa, - sizeof(duk_unicode_ids_noa), - (duk_codepoint_t) cp) && - !duk__uni_range_match(duk_unicode_ids_m_let_noa, - sizeof(duk_unicode_ids_m_let_noa), - (duk_codepoint_t) cp)) { + if (duk__uni_range_match(duk_unicode_ids_noa, sizeof(duk_unicode_ids_noa), (duk_codepoint_t) cp) && + !duk__uni_range_match(duk_unicode_ids_m_let_noa, sizeof(duk_unicode_ids_m_let_noa), (duk_codepoint_t) cp)) { return 1; } return 0; #else if (cp < 0x10000L) { - if (duk__uni_range_match(duk_unicode_ids_noabmp, - sizeof(duk_unicode_ids_noabmp), - (duk_codepoint_t) cp) && + if (duk__uni_range_match(duk_unicode_ids_noabmp, sizeof(duk_unicode_ids_noabmp), (duk_codepoint_t) cp) && !duk__uni_range_match(duk_unicode_ids_m_let_noabmp, sizeof(duk_unicode_ids_m_let_noabmp), (duk_codepoint_t) cp)) { @@ -12846,10 +13578,7 @@ */ DUK_LOCAL -duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr, - duk_bufwriter_ctx *bw, - duk_codepoint_t cp, - duk_bitdecoder_ctx *bd_ctx) { +duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_codepoint_t cp, duk_bitdecoder_ctx *bd_ctx) { duk_small_int_t skip = 0; duk_small_int_t n; duk_small_int_t t; @@ -12879,10 +13608,13 @@ start_o = (duk_codepoint_t) duk_bd_decode(bd_ctx, 16); count = (duk_small_int_t) duk_bd_decode(bd_ctx, 7); DUK_DDD(DUK_DDDPRINT("range: start_i=%ld, start_o=%ld, count=%ld, skip=%ld", - (long) start_i, (long) start_o, (long) count, (long) skip)); + (long) start_i, + (long) start_o, + (long) count, + (long) skip)); if (cp >= start_i) { - tmp_cp = cp - start_i; /* always >= 0 */ + tmp_cp = cp - start_i; /* always >= 0 */ if (tmp_cp < (duk_codepoint_t) count * (duk_codepoint_t) skip && (tmp_cp % (duk_codepoint_t) skip) == 0) { DUK_DDD(DUK_DDDPRINT("range matches input codepoint")); @@ -12934,7 +13666,7 @@ DUK_DDD(DUK_DDDPRINT("no rule matches, output is same as input")); /* fall through */ - single: +single: if (bw != NULL) { DUK_BW_WRITE_RAW_XUTF8(thr, bw, (duk_ucodepoint_t) cp); } @@ -12996,9 +13728,9 @@ * The rule is not locale/language specific so it is supported. */ - if (cp == 0x03a3L && /* U+03A3 = GREEK CAPITAL LETTER SIGMA */ - duk_unicode_is_letter(prev) && /* prev exists and is not a letter */ - !duk_unicode_is_letter(next)) { /* next does not exist or next is not a letter */ + if (cp == 0x03a3L && /* U+03A3 = GREEK CAPITAL LETTER SIGMA */ + duk_unicode_is_letter(prev) && /* prev exists and is not a letter */ + !duk_unicode_is_letter(next)) { /* next does not exist or next is not a letter */ /* Capital sigma occurred at "end of word", lowercase to * U+03C2 = GREEK SMALL LETTER FINAL SIGMA. Otherwise * fall through and let the normal rules lowercase it to @@ -13024,13 +13756,13 @@ } return duk__slow_case_conversion(thr, bw, cp, &bd_ctx); - singlechar: +singlechar: if (bw != NULL) { DUK_BW_WRITE_RAW_XUTF8(thr, bw, (duk_ucodepoint_t) cp); } return cp; - /* unused now, not needed until Turkish/Azeri */ + /* unused now, not needed until Turkish/Azeri */ #if 0 nochar: return -1; @@ -13048,7 +13780,7 @@ const duk_uint8_t *p, *p_start, *p_end; duk_codepoint_t prev, curr, next; - h_input = duk_require_hstring(thr, -1); /* Accept symbols. */ + h_input = duk_require_hstring(thr, -1); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; @@ -13060,7 +13792,8 @@ p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); p = p_start; - prev = -1; DUK_UNREF(prev); + prev = -1; + DUK_UNREF(prev); curr = -1; next = -1; for (;;) { @@ -13085,17 +13818,12 @@ /* Ensure space for maximum multi-character result; estimate is overkill. */ DUK_BW_ENSURE(thr, bw, 8 * DUK_UNICODE_MAX_XUTF8_LENGTH); - duk__case_transform_helper(thr, - bw, - (duk_codepoint_t) curr, - prev, - next, - uppercase); + duk__case_transform_helper(thr, bw, (duk_codepoint_t) curr, prev, next, uppercase); } } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, output is encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, output is encoded. */ /* invalidates h_buf pointer */ duk_remove_m2(thr); } @@ -13118,15 +13846,15 @@ return (duk_codepoint_t) duk_unicode_re_canon_lookupcp; } return cp; -#else /* DUK_USE_REGEXP_CANON_WORKAROUND */ +#else /* DUK_USE_REGEXP_CANON_WORKAROUND */ duk_codepoint_t y; y = duk__case_transform_helper(thr, - NULL, /* NULL is allowed, no output */ - cp, /* curr char */ - -1, /* prev char */ - -1, /* next char */ - 1); /* uppercase */ + NULL, /* NULL is allowed, no output */ + cp, /* curr char */ + -1, /* prev char */ + -1, /* next char */ + 1); /* uppercase */ if ((y < 0) || (cp >= 0x80 && y < 0x80)) { /* multiple codepoint conversion or non-ASCII mapped to ASCII @@ -13136,7 +13864,7 @@ } return y; -#endif /* DUK_USE_REGEXP_CANON_WORKAROUND */ +#endif /* DUK_USE_REGEXP_CANON_WORKAROUND */ } /* @@ -13149,10 +13877,7 @@ * Note: the description in E5 Section 15.10.2.6 has a typo, it * contains 'A' twice and lacks 'a'; the intent is 0-9a-zA-Z_. */ - if ((x >= '0' && x <= '9') || - (x >= 'a' && x <= 'z') || - (x >= 'A' && x <= 'Z') || - (x == '_')) { + if ((x >= '0' && x <= '9') || (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z') || (x == '_')) { return 1; } return 0; @@ -13164,54 +13889,39 @@ /* exposed because lexer needs these too */ DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_digit2 = { - (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, + (duk_uint16_t) 0x0030UL, + (duk_uint16_t) 0x0039UL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_white22 = { - (duk_uint16_t) 0x0009UL, (duk_uint16_t) 0x000DUL, - (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x0020UL, - (duk_uint16_t) 0x00A0UL, (duk_uint16_t) 0x00A0UL, - (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x1680UL, - (duk_uint16_t) 0x180EUL, (duk_uint16_t) 0x180EUL, - (duk_uint16_t) 0x2000UL, (duk_uint16_t) 0x200AUL, - (duk_uint16_t) 0x2028UL, (duk_uint16_t) 0x2029UL, - (duk_uint16_t) 0x202FUL, (duk_uint16_t) 0x202FUL, - (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x205FUL, - (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0x3000UL, + (duk_uint16_t) 0x0009UL, (duk_uint16_t) 0x000DUL, (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x0020UL, (duk_uint16_t) 0x00A0UL, + (duk_uint16_t) 0x00A0UL, (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x1680UL, (duk_uint16_t) 0x180EUL, (duk_uint16_t) 0x180EUL, + (duk_uint16_t) 0x2000UL, (duk_uint16_t) 0x200AUL, (duk_uint16_t) 0x2028UL, (duk_uint16_t) 0x2029UL, (duk_uint16_t) 0x202FUL, + (duk_uint16_t) 0x202FUL, (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x205FUL, (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0x3000UL, (duk_uint16_t) 0xFEFFUL, (duk_uint16_t) 0xFEFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_wordchar8 = { - (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, - (duk_uint16_t) 0x0041UL, (duk_uint16_t) 0x005AUL, - (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x005FUL, - (duk_uint16_t) 0x0061UL, (duk_uint16_t) 0x007AUL, + (duk_uint16_t) 0x0030UL, (duk_uint16_t) 0x0039UL, (duk_uint16_t) 0x0041UL, (duk_uint16_t) 0x005AUL, + (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x005FUL, (duk_uint16_t) 0x0061UL, (duk_uint16_t) 0x007AUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_digit4 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, - (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, + (duk_uint16_t) 0x002FUL, + (duk_uint16_t) 0x003AUL, + (duk_uint16_t) 0xFFFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_white24 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x0008UL, - (duk_uint16_t) 0x000EUL, (duk_uint16_t) 0x001FUL, - (duk_uint16_t) 0x0021UL, (duk_uint16_t) 0x009FUL, - (duk_uint16_t) 0x00A1UL, (duk_uint16_t) 0x167FUL, - (duk_uint16_t) 0x1681UL, (duk_uint16_t) 0x180DUL, - (duk_uint16_t) 0x180FUL, (duk_uint16_t) 0x1FFFUL, - (duk_uint16_t) 0x200BUL, (duk_uint16_t) 0x2027UL, - (duk_uint16_t) 0x202AUL, (duk_uint16_t) 0x202EUL, - (duk_uint16_t) 0x2030UL, (duk_uint16_t) 0x205EUL, - (duk_uint16_t) 0x2060UL, (duk_uint16_t) 0x2FFFUL, - (duk_uint16_t) 0x3001UL, (duk_uint16_t) 0xFEFEUL, - (duk_uint16_t) 0xFF00UL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x0008UL, (duk_uint16_t) 0x000EUL, (duk_uint16_t) 0x001FUL, (duk_uint16_t) 0x0021UL, + (duk_uint16_t) 0x009FUL, (duk_uint16_t) 0x00A1UL, (duk_uint16_t) 0x167FUL, (duk_uint16_t) 0x1681UL, (duk_uint16_t) 0x180DUL, + (duk_uint16_t) 0x180FUL, (duk_uint16_t) 0x1FFFUL, (duk_uint16_t) 0x200BUL, (duk_uint16_t) 0x2027UL, (duk_uint16_t) 0x202AUL, + (duk_uint16_t) 0x202EUL, (duk_uint16_t) 0x2030UL, (duk_uint16_t) 0x205EUL, (duk_uint16_t) 0x2060UL, (duk_uint16_t) 0x2FFFUL, + (duk_uint16_t) 0x3001UL, (duk_uint16_t) 0xFEFEUL, (duk_uint16_t) 0xFF00UL, (duk_uint16_t) 0xFFFFUL, }; DUK_INTERNAL const duk_uint16_t duk_unicode_re_ranges_not_wordchar10 = { - (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, - (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0x0040UL, - (duk_uint16_t) 0x005BUL, (duk_uint16_t) 0x005EUL, - (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x0060UL, - (duk_uint16_t) 0x007BUL, (duk_uint16_t) 0xFFFFUL, + (duk_uint16_t) 0x0000UL, (duk_uint16_t) 0x002FUL, (duk_uint16_t) 0x003AUL, (duk_uint16_t) 0x0040UL, (duk_uint16_t) 0x005BUL, + (duk_uint16_t) 0x005EUL, (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x0060UL, (duk_uint16_t) 0x007BUL, (duk_uint16_t) 0xFFFFUL, }; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #line 1 "duk_util_memrw.c" /* * Macro support functions for reading/writing raw data. @@ -13374,23 +14084,17 @@ */ DUK_INTERNAL const duk_uint8_t duk_lc_digits36 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_LC_A, DUK_ASC_LC_B, - DUK_ASC_LC_C, DUK_ASC_LC_D, DUK_ASC_LC_E, DUK_ASC_LC_F, - DUK_ASC_LC_G, DUK_ASC_LC_H, DUK_ASC_LC_I, DUK_ASC_LC_J, - DUK_ASC_LC_K, DUK_ASC_LC_L, DUK_ASC_LC_M, DUK_ASC_LC_N, - DUK_ASC_LC_O, DUK_ASC_LC_P, DUK_ASC_LC_Q, DUK_ASC_LC_R, - DUK_ASC_LC_S, DUK_ASC_LC_T, DUK_ASC_LC_U, DUK_ASC_LC_V, + DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_LC_A, DUK_ASC_LC_B, DUK_ASC_LC_C, DUK_ASC_LC_D, DUK_ASC_LC_E, DUK_ASC_LC_F, + DUK_ASC_LC_G, DUK_ASC_LC_H, DUK_ASC_LC_I, DUK_ASC_LC_J, DUK_ASC_LC_K, DUK_ASC_LC_L, DUK_ASC_LC_M, DUK_ASC_LC_N, + DUK_ASC_LC_O, DUK_ASC_LC_P, DUK_ASC_LC_Q, DUK_ASC_LC_R, DUK_ASC_LC_S, DUK_ASC_LC_T, DUK_ASC_LC_U, DUK_ASC_LC_V, DUK_ASC_LC_W, DUK_ASC_LC_X, DUK_ASC_LC_Y, DUK_ASC_LC_Z }; -DUK_INTERNAL const duk_uint8_t duk_uc_nybbles16 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_UC_A, DUK_ASC_UC_B, - DUK_ASC_UC_C, DUK_ASC_UC_D, DUK_ASC_UC_E, DUK_ASC_UC_F -}; +DUK_INTERNAL const duk_uint8_t duk_uc_nybbles16 = { DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, + DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_UC_A, DUK_ASC_UC_B, + DUK_ASC_UC_C, DUK_ASC_UC_D, DUK_ASC_UC_E, DUK_ASC_UC_F }; /* * Table for hex decoding ASCII hex digits @@ -13398,43 +14102,43 @@ DUK_INTERNAL const duk_int8_t duk_hex_dectab256 = { /* -1 if invalid */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ }; #if defined(DUK_USE_HEX_FASTPATH) /* Preshifted << 4. Must use 16-bit entry to allow negative value signaling. */ DUK_INTERNAL const duk_int16_t duk_hex_dectab_shift4256 = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ - 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ - -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ - -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20-0x2f */ + 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, -1, -1, -1, -1, -1, -1, /* 0x30-0x3f */ + -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40-0x4f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50-0x5f */ + -1, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60-0x6f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70-0x7f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80-0x8f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90-0x9f */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xa0-0xaf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb0-0xbf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc0-0xcf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd0-0xdf */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe0-0xef */ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xf0-0xff */ }; #endif @@ -13453,77 +14157,53 @@ * print('0x' + t.encode('hex') + 'U') * print('big endian'); genhextab(False) * print('little endian'); genhextab(True) -*/ + */ DUK_INTERNAL const duk_uint16_t duk_hex_enctab256 = { #if defined(DUK_USE_INTEGER_BE) - 0x3030U, 0x3031U, 0x3032U, 0x3033U, 0x3034U, 0x3035U, 0x3036U, 0x3037U, - 0x3038U, 0x3039U, 0x3061U, 0x3062U, 0x3063U, 0x3064U, 0x3065U, 0x3066U, - 0x3130U, 0x3131U, 0x3132U, 0x3133U, 0x3134U, 0x3135U, 0x3136U, 0x3137U, - 0x3138U, 0x3139U, 0x3161U, 0x3162U, 0x3163U, 0x3164U, 0x3165U, 0x3166U, - 0x3230U, 0x3231U, 0x3232U, 0x3233U, 0x3234U, 0x3235U, 0x3236U, 0x3237U, - 0x3238U, 0x3239U, 0x3261U, 0x3262U, 0x3263U, 0x3264U, 0x3265U, 0x3266U, - 0x3330U, 0x3331U, 0x3332U, 0x3333U, 0x3334U, 0x3335U, 0x3336U, 0x3337U, - 0x3338U, 0x3339U, 0x3361U, 0x3362U, 0x3363U, 0x3364U, 0x3365U, 0x3366U, - 0x3430U, 0x3431U, 0x3432U, 0x3433U, 0x3434U, 0x3435U, 0x3436U, 0x3437U, - 0x3438U, 0x3439U, 0x3461U, 0x3462U, 0x3463U, 0x3464U, 0x3465U, 0x3466U, - 0x3530U, 0x3531U, 0x3532U, 0x3533U, 0x3534U, 0x3535U, 0x3536U, 0x3537U, - 0x3538U, 0x3539U, 0x3561U, 0x3562U, 0x3563U, 0x3564U, 0x3565U, 0x3566U, - 0x3630U, 0x3631U, 0x3632U, 0x3633U, 0x3634U, 0x3635U, 0x3636U, 0x3637U, - 0x3638U, 0x3639U, 0x3661U, 0x3662U, 0x3663U, 0x3664U, 0x3665U, 0x3666U, - 0x3730U, 0x3731U, 0x3732U, 0x3733U, 0x3734U, 0x3735U, 0x3736U, 0x3737U, - 0x3738U, 0x3739U, 0x3761U, 0x3762U, 0x3763U, 0x3764U, 0x3765U, 0x3766U, - 0x3830U, 0x3831U, 0x3832U, 0x3833U, 0x3834U, 0x3835U, 0x3836U, 0x3837U, - 0x3838U, 0x3839U, 0x3861U, 0x3862U, 0x3863U, 0x3864U, 0x3865U, 0x3866U, - 0x3930U, 0x3931U, 0x3932U, 0x3933U, 0x3934U, 0x3935U, 0x3936U, 0x3937U, - 0x3938U, 0x3939U, 0x3961U, 0x3962U, 0x3963U, 0x3964U, 0x3965U, 0x3966U, - 0x6130U, 0x6131U, 0x6132U, 0x6133U, 0x6134U, 0x6135U, 0x6136U, 0x6137U, - 0x6138U, 0x6139U, 0x6161U, 0x6162U, 0x6163U, 0x6164U, 0x6165U, 0x6166U, - 0x6230U, 0x6231U, 0x6232U, 0x6233U, 0x6234U, 0x6235U, 0x6236U, 0x6237U, - 0x6238U, 0x6239U, 0x6261U, 0x6262U, 0x6263U, 0x6264U, 0x6265U, 0x6266U, - 0x6330U, 0x6331U, 0x6332U, 0x6333U, 0x6334U, 0x6335U, 0x6336U, 0x6337U, - 0x6338U, 0x6339U, 0x6361U, 0x6362U, 0x6363U, 0x6364U, 0x6365U, 0x6366U, - 0x6430U, 0x6431U, 0x6432U, 0x6433U, 0x6434U, 0x6435U, 0x6436U, 0x6437U, - 0x6438U, 0x6439U, 0x6461U, 0x6462U, 0x6463U, 0x6464U, 0x6465U, 0x6466U, - 0x6530U, 0x6531U, 0x6532U, 0x6533U, 0x6534U, 0x6535U, 0x6536U, 0x6537U, - 0x6538U, 0x6539U, 0x6561U, 0x6562U, 0x6563U, 0x6564U, 0x6565U, 0x6566U, - 0x6630U, 0x6631U, 0x6632U, 0x6633U, 0x6634U, 0x6635U, 0x6636U, 0x6637U, - 0x6638U, 0x6639U, 0x6661U, 0x6662U, 0x6663U, 0x6664U, 0x6665U, 0x6666U -#else /* DUK_USE_INTEGER_BE */ - 0x3030U, 0x3130U, 0x3230U, 0x3330U, 0x3430U, 0x3530U, 0x3630U, 0x3730U, - 0x3830U, 0x3930U, 0x6130U, 0x6230U, 0x6330U, 0x6430U, 0x6530U, 0x6630U, - 0x3031U, 0x3131U, 0x3231U, 0x3331U, 0x3431U, 0x3531U, 0x3631U, 0x3731U, - 0x3831U, 0x3931U, 0x6131U, 0x6231U, 0x6331U, 0x6431U, 0x6531U, 0x6631U, - 0x3032U, 0x3132U, 0x3232U, 0x3332U, 0x3432U, 0x3532U, 0x3632U, 0x3732U, - 0x3832U, 0x3932U, 0x6132U, 0x6232U, 0x6332U, 0x6432U, 0x6532U, 0x6632U, - 0x3033U, 0x3133U, 0x3233U, 0x3333U, 0x3433U, 0x3533U, 0x3633U, 0x3733U, - 0x3833U, 0x3933U, 0x6133U, 0x6233U, 0x6333U, 0x6433U, 0x6533U, 0x6633U, - 0x3034U, 0x3134U, 0x3234U, 0x3334U, 0x3434U, 0x3534U, 0x3634U, 0x3734U, - 0x3834U, 0x3934U, 0x6134U, 0x6234U, 0x6334U, 0x6434U, 0x6534U, 0x6634U, - 0x3035U, 0x3135U, 0x3235U, 0x3335U, 0x3435U, 0x3535U, 0x3635U, 0x3735U, - 0x3835U, 0x3935U, 0x6135U, 0x6235U, 0x6335U, 0x6435U, 0x6535U, 0x6635U, - 0x3036U, 0x3136U, 0x3236U, 0x3336U, 0x3436U, 0x3536U, 0x3636U, 0x3736U, - 0x3836U, 0x3936U, 0x6136U, 0x6236U, 0x6336U, 0x6436U, 0x6536U, 0x6636U, - 0x3037U, 0x3137U, 0x3237U, 0x3337U, 0x3437U, 0x3537U, 0x3637U, 0x3737U, - 0x3837U, 0x3937U, 0x6137U, 0x6237U, 0x6337U, 0x6437U, 0x6537U, 0x6637U, - 0x3038U, 0x3138U, 0x3238U, 0x3338U, 0x3438U, 0x3538U, 0x3638U, 0x3738U, - 0x3838U, 0x3938U, 0x6138U, 0x6238U, 0x6338U, 0x6438U, 0x6538U, 0x6638U, - 0x3039U, 0x3139U, 0x3239U, 0x3339U, 0x3439U, 0x3539U, 0x3639U, 0x3739U, - 0x3839U, 0x3939U, 0x6139U, 0x6239U, 0x6339U, 0x6439U, 0x6539U, 0x6639U, - 0x3061U, 0x3161U, 0x3261U, 0x3361U, 0x3461U, 0x3561U, 0x3661U, 0x3761U, - 0x3861U, 0x3961U, 0x6161U, 0x6261U, 0x6361U, 0x6461U, 0x6561U, 0x6661U, - 0x3062U, 0x3162U, 0x3262U, 0x3362U, 0x3462U, 0x3562U, 0x3662U, 0x3762U, - 0x3862U, 0x3962U, 0x6162U, 0x6262U, 0x6362U, 0x6462U, 0x6562U, 0x6662U, - 0x3063U, 0x3163U, 0x3263U, 0x3363U, 0x3463U, 0x3563U, 0x3663U, 0x3763U, - 0x3863U, 0x3963U, 0x6163U, 0x6263U, 0x6363U, 0x6463U, 0x6563U, 0x6663U, - 0x3064U, 0x3164U, 0x3264U, 0x3364U, 0x3464U, 0x3564U, 0x3664U, 0x3764U, - 0x3864U, 0x3964U, 0x6164U, 0x6264U, 0x6364U, 0x6464U, 0x6564U, 0x6664U, - 0x3065U, 0x3165U, 0x3265U, 0x3365U, 0x3465U, 0x3565U, 0x3665U, 0x3765U, - 0x3865U, 0x3965U, 0x6165U, 0x6265U, 0x6365U, 0x6465U, 0x6565U, 0x6665U, - 0x3066U, 0x3166U, 0x3266U, 0x3366U, 0x3466U, 0x3566U, 0x3666U, 0x3766U, - 0x3866U, 0x3966U, 0x6166U, 0x6266U, 0x6366U, 0x6466U, 0x6566U, 0x6666U -#endif /* DUK_USE_INTEGER_BE */ + 0x3030U, 0x3031U, 0x3032U, 0x3033U, 0x3034U, 0x3035U, 0x3036U, 0x3037U, 0x3038U, 0x3039U, 0x3061U, 0x3062U, 0x3063U, + 0x3064U, 0x3065U, 0x3066U, 0x3130U, 0x3131U, 0x3132U, 0x3133U, 0x3134U, 0x3135U, 0x3136U, 0x3137U, 0x3138U, 0x3139U, + 0x3161U, 0x3162U, 0x3163U, 0x3164U, 0x3165U, 0x3166U, 0x3230U, 0x3231U, 0x3232U, 0x3233U, 0x3234U, 0x3235U, 0x3236U, + 0x3237U, 0x3238U, 0x3239U, 0x3261U, 0x3262U, 0x3263U, 0x3264U, 0x3265U, 0x3266U, 0x3330U, 0x3331U, 0x3332U, 0x3333U, + 0x3334U, 0x3335U, 0x3336U, 0x3337U, 0x3338U, 0x3339U, 0x3361U, 0x3362U, 0x3363U, 0x3364U, 0x3365U, 0x3366U, 0x3430U, + 0x3431U, 0x3432U, 0x3433U, 0x3434U, 0x3435U, 0x3436U, 0x3437U, 0x3438U, 0x3439U, 0x3461U, 0x3462U, 0x3463U, 0x3464U, + 0x3465U, 0x3466U, 0x3530U, 0x3531U, 0x3532U, 0x3533U, 0x3534U, 0x3535U, 0x3536U, 0x3537U, 0x3538U, 0x3539U, 0x3561U, + 0x3562U, 0x3563U, 0x3564U, 0x3565U, 0x3566U, 0x3630U, 0x3631U, 0x3632U, 0x3633U, 0x3634U, 0x3635U, 0x3636U, 0x3637U, + 0x3638U, 0x3639U, 0x3661U, 0x3662U, 0x3663U, 0x3664U, 0x3665U, 0x3666U, 0x3730U, 0x3731U, 0x3732U, 0x3733U, 0x3734U, + 0x3735U, 0x3736U, 0x3737U, 0x3738U, 0x3739U, 0x3761U, 0x3762U, 0x3763U, 0x3764U, 0x3765U, 0x3766U, 0x3830U, 0x3831U, + 0x3832U, 0x3833U, 0x3834U, 0x3835U, 0x3836U, 0x3837U, 0x3838U, 0x3839U, 0x3861U, 0x3862U, 0x3863U, 0x3864U, 0x3865U, + 0x3866U, 0x3930U, 0x3931U, 0x3932U, 0x3933U, 0x3934U, 0x3935U, 0x3936U, 0x3937U, 0x3938U, 0x3939U, 0x3961U, 0x3962U, + 0x3963U, 0x3964U, 0x3965U, 0x3966U, 0x6130U, 0x6131U, 0x6132U, 0x6133U, 0x6134U, 0x6135U, 0x6136U, 0x6137U, 0x6138U, + 0x6139U, 0x6161U, 0x6162U, 0x6163U, 0x6164U, 0x6165U, 0x6166U, 0x6230U, 0x6231U, 0x6232U, 0x6233U, 0x6234U, 0x6235U, + 0x6236U, 0x6237U, 0x6238U, 0x6239U, 0x6261U, 0x6262U, 0x6263U, 0x6264U, 0x6265U, 0x6266U, 0x6330U, 0x6331U, 0x6332U, + 0x6333U, 0x6334U, 0x6335U, 0x6336U, 0x6337U, 0x6338U, 0x6339U, 0x6361U, 0x6362U, 0x6363U, 0x6364U, 0x6365U, 0x6366U, + 0x6430U, 0x6431U, 0x6432U, 0x6433U, 0x6434U, 0x6435U, 0x6436U, 0x6437U, 0x6438U, 0x6439U, 0x6461U, 0x6462U, 0x6463U, + 0x6464U, 0x6465U, 0x6466U, 0x6530U, 0x6531U, 0x6532U, 0x6533U, 0x6534U, 0x6535U, 0x6536U, 0x6537U, 0x6538U, 0x6539U, + 0x6561U, 0x6562U, 0x6563U, 0x6564U, 0x6565U, 0x6566U, 0x6630U, 0x6631U, 0x6632U, 0x6633U, 0x6634U, 0x6635U, 0x6636U, + 0x6637U, 0x6638U, 0x6639U, 0x6661U, 0x6662U, 0x6663U, 0x6664U, 0x6665U, 0x6666U +#else /* DUK_USE_INTEGER_BE */ + 0x3030U, 0x3130U, 0x3230U, 0x3330U, 0x3430U, 0x3530U, 0x3630U, 0x3730U, 0x3830U, 0x3930U, 0x6130U, 0x6230U, 0x6330U, + 0x6430U, 0x6530U, 0x6630U, 0x3031U, 0x3131U, 0x3231U, 0x3331U, 0x3431U, 0x3531U, 0x3631U, 0x3731U, 0x3831U, 0x3931U, + 0x6131U, 0x6231U, 0x6331U, 0x6431U, 0x6531U, 0x6631U, 0x3032U, 0x3132U, 0x3232U, 0x3332U, 0x3432U, 0x3532U, 0x3632U, + 0x3732U, 0x3832U, 0x3932U, 0x6132U, 0x6232U, 0x6332U, 0x6432U, 0x6532U, 0x6632U, 0x3033U, 0x3133U, 0x3233U, 0x3333U, + 0x3433U, 0x3533U, 0x3633U, 0x3733U, 0x3833U, 0x3933U, 0x6133U, 0x6233U, 0x6333U, 0x6433U, 0x6533U, 0x6633U, 0x3034U, + 0x3134U, 0x3234U, 0x3334U, 0x3434U, 0x3534U, 0x3634U, 0x3734U, 0x3834U, 0x3934U, 0x6134U, 0x6234U, 0x6334U, 0x6434U, + 0x6534U, 0x6634U, 0x3035U, 0x3135U, 0x3235U, 0x3335U, 0x3435U, 0x3535U, 0x3635U, 0x3735U, 0x3835U, 0x3935U, 0x6135U, + 0x6235U, 0x6335U, 0x6435U, 0x6535U, 0x6635U, 0x3036U, 0x3136U, 0x3236U, 0x3336U, 0x3436U, 0x3536U, 0x3636U, 0x3736U, + 0x3836U, 0x3936U, 0x6136U, 0x6236U, 0x6336U, 0x6436U, 0x6536U, 0x6636U, 0x3037U, 0x3137U, 0x3237U, 0x3337U, 0x3437U, + 0x3537U, 0x3637U, 0x3737U, 0x3837U, 0x3937U, 0x6137U, 0x6237U, 0x6337U, 0x6437U, 0x6537U, 0x6637U, 0x3038U, 0x3138U, + 0x3238U, 0x3338U, 0x3438U, 0x3538U, 0x3638U, 0x3738U, 0x3838U, 0x3938U, 0x6138U, 0x6238U, 0x6338U, 0x6438U, 0x6538U, + 0x6638U, 0x3039U, 0x3139U, 0x3239U, 0x3339U, 0x3439U, 0x3539U, 0x3639U, 0x3739U, 0x3839U, 0x3939U, 0x6139U, 0x6239U, + 0x6339U, 0x6439U, 0x6539U, 0x6639U, 0x3061U, 0x3161U, 0x3261U, 0x3361U, 0x3461U, 0x3561U, 0x3661U, 0x3761U, 0x3861U, + 0x3961U, 0x6161U, 0x6261U, 0x6361U, 0x6461U, 0x6561U, 0x6661U, 0x3062U, 0x3162U, 0x3262U, 0x3362U, 0x3462U, 0x3562U, + 0x3662U, 0x3762U, 0x3862U, 0x3962U, 0x6162U, 0x6262U, 0x6362U, 0x6462U, 0x6562U, 0x6662U, 0x3063U, 0x3163U, 0x3263U, + 0x3363U, 0x3463U, 0x3563U, 0x3663U, 0x3763U, 0x3863U, 0x3963U, 0x6163U, 0x6263U, 0x6363U, 0x6463U, 0x6563U, 0x6663U, + 0x3064U, 0x3164U, 0x3264U, 0x3364U, 0x3464U, 0x3564U, 0x3664U, 0x3764U, 0x3864U, 0x3964U, 0x6164U, 0x6264U, 0x6364U, + 0x6464U, 0x6564U, 0x6664U, 0x3065U, 0x3165U, 0x3265U, 0x3365U, 0x3465U, 0x3565U, 0x3665U, 0x3765U, 0x3865U, 0x3965U, + 0x6165U, 0x6265U, 0x6365U, 0x6465U, 0x6565U, 0x6665U, 0x3066U, 0x3166U, 0x3266U, 0x3366U, 0x3466U, 0x3566U, 0x3666U, + 0x3766U, 0x3866U, 0x3966U, 0x6166U, 0x6266U, 0x6366U, 0x6466U, 0x6566U, 0x6666U +#endif /* DUK_USE_INTEGER_BE */ }; -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ /* * Arbitrary byteswap for potentially unaligned values @@ -13531,7 +14211,7 @@ * Used to byteswap pointers e.g. in debugger code. */ -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* For now only needed by the debugger. */ DUK_INTERNAL void duk_byteswap_bytes(duk_uint8_t *p, duk_small_uint_t len) { duk_uint8_t tmp; duk_uint8_t *q = p + len - 1; @@ -13545,6 +14225,18 @@ } } #endif + +/* + * Random + */ + +DUK_INTERNAL duk_double_t duk_util_get_random_double(duk_hthread *thr) { +#if defined(DUK_USE_GET_RANDOM_DOUBLE) + return DUK_USE_GET_RANDOM_DOUBLE(thr->heap->heap_udata); +#else + return duk_util_tinyrandom_get_double(thr); +#endif +} #line 1 "duk_hobject_class.c" /* * Hobject ECMAScript Class. @@ -13642,7 +14334,7 @@ /* Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that */ DUK_INTERNAL duk_uint8_t duk_class_number_to_stridx32 = { - DUK_STRIDX_EMPTY_STRING, /* NONE, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* NONE, intentionally empty */ DUK_STRIDX_UC_OBJECT, DUK_STRIDX_UC_ARRAY, DUK_STRIDX_UC_FUNCTION, @@ -13672,8 +14364,8 @@ DUK_STRIDX_UINT32_ARRAY, DUK_STRIDX_FLOAT32_ARRAY, DUK_STRIDX_FLOAT64_ARRAY, - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ - DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ + DUK_STRIDX_EMPTY_STRING, /* UNUSED, intentionally empty */ }; #line 1 "duk_alloc_default.c" /* @@ -13690,8 +14382,7 @@ void *res; DUK_UNREF(udata); res = DUK_ANSI_MALLOC(size); - DUK_DDD(DUK_DDDPRINT("default alloc function: %lu -> %p", - (unsigned long) size, (void *) res)); + DUK_DDD(DUK_DDDPRINT("default alloc function: %lu -> %p", (unsigned long) size, (void *) res)); return res; } @@ -13699,8 +14390,7 @@ void *res; DUK_UNREF(udata); res = DUK_ANSI_REALLOC(ptr, newsize); - DUK_DDD(DUK_DDDPRINT("default realloc function: %p %lu -> %p", - (void *) ptr, (unsigned long) newsize, (void *) res)); + DUK_DDD(DUK_DDDPRINT("default realloc function: %p %lu -> %p", (void *) ptr, (unsigned long) newsize, (void *) res)); return res; } @@ -13709,7 +14399,7 @@ DUK_UNREF(udata); DUK_ANSI_FREE(ptr); } -#endif /* DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS */ +#endif /* DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS */ #line 1 "duk_api_buffer.c" /* * Buffer @@ -13801,11 +14491,11 @@ #if defined(DUK_USE_BYTECODE_DUMP_SUPPORT) -#define DUK__SER_MARKER 0xbf -#define DUK__SER_STRING 0x00 -#define DUK__SER_NUMBER 0x01 +#define DUK__SER_MARKER 0xbf +#define DUK__SER_STRING 0x00 +#define DUK__SER_NUMBER 0x01 #define DUK__BYTECODE_INITIAL_ALLOC 256 -#define DUK__NO_FORMALS 0xffffffffUL +#define DUK__NO_FORMALS 0xffffffffUL /* * Dump/load helpers, xxx_raw() helpers do no buffer checks @@ -13839,12 +14529,10 @@ DUK_ASSERT(h != NULL); len = DUK_HSTRING_GET_BYTELEN(h); - DUK_ASSERT(len <= 0xffffffffUL); /* string limits */ + DUK_ASSERT(len <= 0xffffffffUL); /* string limits */ tmp32 = (duk_uint32_t) len; DUK_RAW_WRITEINC_U32_BE(p, tmp32); - duk_memcpy((void *) p, - (const void *) DUK_HSTRING_GET_DATA(h), - len); + duk_memcpy((void *) p, (const void *) DUK_HSTRING_GET_DATA(h), len); p += len; return p; } @@ -13858,18 +14546,20 @@ DUK_UNREF(thr); len = DUK_HBUFFER_GET_SIZE(h); - DUK_ASSERT(len <= 0xffffffffUL); /* buffer limits */ + DUK_ASSERT(len <= 0xffffffffUL); /* buffer limits */ tmp32 = (duk_uint32_t) len; DUK_RAW_WRITEINC_U32_BE(p, tmp32); /* When len == 0, buffer data pointer may be NULL. */ - duk_memcpy_unsafe((void *) p, - (const void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h), - len); + duk_memcpy_unsafe((void *) p, (const void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h), len); p += len; return p; } -DUK_LOCAL duk_uint8_t *duk__dump_string_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx) { +DUK_LOCAL duk_uint8_t *duk__dump_string_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx) { duk_hstring *h_str; duk_tval *tv; @@ -13881,13 +14571,17 @@ h_str = DUK_HTHREAD_STRING_EMPTY_STRING(thr); DUK_ASSERT(h_str != NULL); } - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(h_str), p); p = duk__dump_hstring_raw(p, h_str); return p; } -DUK_LOCAL duk_uint8_t *duk__dump_buffer_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx) { +DUK_LOCAL duk_uint8_t *duk__dump_buffer_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx) { duk_tval *tv; tv = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, (duk_hobject *) func, stridx); @@ -13895,7 +14589,7 @@ duk_hbuffer *h_buf; h_buf = DUK_TVAL_GET_BUFFER(tv); DUK_ASSERT(h_buf != NULL); - DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HBUFFER_GET_SIZE(h_buf), p); p = duk__dump_hbuffer_raw(thr, p, h_buf); } else { @@ -13905,7 +14599,12 @@ return p; } -DUK_LOCAL duk_uint8_t *duk__dump_uint32_prop(duk_hthread *thr, duk_uint8_t *p, duk_bufwriter_ctx *bw_ctx, duk_hobject *func, duk_small_uint_t stridx, duk_uint32_t def_value) { +DUK_LOCAL duk_uint8_t *duk__dump_uint32_prop(duk_hthread *thr, + duk_uint8_t *p, + duk_bufwriter_ctx *bw_ctx, + duk_hobject *func, + duk_small_uint_t stridx, + duk_uint32_t def_value) { duk_tval *tv; duk_uint32_t val; @@ -13938,27 +14637,28 @@ duk_uint32_t val; key = DUK_HOBJECT_E_GET_KEY(thr->heap, h, i); - DUK_ASSERT(key != NULL); /* _Varmap is dense */ + DUK_ASSERT(key != NULL); /* _Varmap is dense */ DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, h, i)); tv_val = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, h, i); DUK_ASSERT(tv_val != NULL); - DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_val)); /* known to be number; in fact an integer */ + DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_val)); /* known to be number; in fact an integer */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_val)); - DUK_ASSERT(DUK_TVAL_GET_FASTINT(tv_val) == (duk_int64_t) DUK_TVAL_GET_FASTINT_U32(tv_val)); /* known to be 32-bit */ + DUK_ASSERT(DUK_TVAL_GET_FASTINT(tv_val) == + (duk_int64_t) DUK_TVAL_GET_FASTINT_U32(tv_val)); /* known to be 32-bit */ val = DUK_TVAL_GET_FASTINT_U32(tv_val); #else val = (duk_uint32_t) DUK_TVAL_GET_NUMBER(tv_val); #endif - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(key) + 4U, p); p = duk__dump_hstring_raw(p, key); DUK_RAW_WRITEINC_U32_BE(p, val); } } p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_RAW_WRITEINC_U32_BE(p, 0); /* end of _Varmap */ + DUK_RAW_WRITEINC_U32_BE(p, 0); /* end of _Varmap */ return p; } @@ -13976,7 +14676,7 @@ */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_ASSERT(h->length != DUK__NO_FORMALS); /* limits */ + DUK_ASSERT(h->length != DUK__NO_FORMALS); /* limits */ DUK_RAW_WRITEINC_U32_BE(p, h->length); for (i = 0; i < h->length; i++) { @@ -13991,14 +14691,14 @@ DUK_ASSERT(varname != NULL); DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(varname) >= 1); - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(varname), p); p = duk__dump_hstring_raw(p, varname); } } else { DUK_DD(DUK_DDPRINT("dumping function without _Formals, emit marker to indicate missing _Formals")); p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p); - DUK_RAW_WRITEINC_U32_BE(p, DUK__NO_FORMALS); /* marker: no formals */ + DUK_RAW_WRITEINC_U32_BE(p, DUK__NO_FORMALS); /* marker: no formals */ } return p; } @@ -14032,7 +14732,7 @@ (long) DUK_HCOMPFUNC_GET_CODE_SIZE(thr->heap, func), (long) DUK_HCOMPFUNC_GET_CODE_COUNT(thr->heap, func))); - DUK_ASSERT(DUK_USE_ESBC_MAX_BYTES <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_USE_ESBC_MAX_BYTES <= 0x7fffffffUL); /* ensures no overflow */ count_instr = (duk_uint32_t) DUK_HCOMPFUNC_GET_CODE_COUNT(thr->heap, func); p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 3U * 4U + 2U * 2U + 3U * 4U + count_instr * 4U, p); @@ -14056,8 +14756,8 @@ DUK_RAW_WRITEINC_U32_BE(p, 0); DUK_RAW_WRITEINC_U32_BE(p, 0); #endif - tmp32 = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) func); /* masks flags, only duk_hobject flags */ - tmp32 &= ~(DUK_HOBJECT_FLAG_HAVE_FINALIZER); /* finalizer flag is lost */ + tmp32 = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) func); /* masks flags, only duk_hobject flags */ + tmp32 &= ~(DUK_HOBJECT_FLAG_HAVE_FINALIZER); /* finalizer flag is lost */ DUK_RAW_WRITEINC_U32_BE(p, tmp32); /* Bytecode instructions: endian conversion needed unless @@ -14067,8 +14767,9 @@ ins_end = DUK_HCOMPFUNC_GET_CODE_END(thr->heap, func); DUK_ASSERT((duk_size_t) (ins_end - ins) == (duk_size_t) count_instr); #if defined(DUK_USE_INTEGER_BE) - duk_memcpy_unsafe((void *) p, (const void *) ins, (size_t) (ins_end - ins)); - p += (size_t) (ins_end - ins); + duk_memcpy_unsafe((void *) p, (const void *) ins, count_instr * sizeof(duk_instr_t)); + p += count_instr * sizeof(duk_instr_t); + DUK_UNREF(ins_end); #else while (ins != ins_end) { tmp32 = (duk_uint32_t) (*ins); @@ -14082,13 +14783,12 @@ tv_end = DUK_HCOMPFUNC_GET_CONSTS_END(thr->heap, func); while (tv != tv_end) { /* constants are strings or numbers now */ - DUK_ASSERT(DUK_TVAL_IS_STRING(tv) || - DUK_TVAL_IS_NUMBER(tv)); + DUK_ASSERT(DUK_TVAL_IS_STRING(tv) || DUK_TVAL_IS_NUMBER(tv)); if (DUK_TVAL_IS_STRING(tv)) { h_str = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h_str != NULL); - DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ + DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 1U + 4U + DUK_HSTRING_GET_BYTELEN(h_str), p); *p++ = DUK__SER_STRING; p = duk__dump_hstring_raw(p, h_str); @@ -14154,7 +14854,8 @@ * are validated (which is quite complex, especially for indirect opcodes). */ -#define DUK__ASSERT_LEFT(n) do { \ +#define DUK__ASSERT_LEFT(n) \ + do { \ DUK_ASSERT((duk_size_t) (p_end - p) >= (duk_size_t) (n)); \ } while (0) @@ -14189,13 +14890,13 @@ count_const = DUK_RAW_READINC_U32_BE(p); count_funcs = DUK_RAW_READINC_U32_BE(p); - data_size = sizeof(duk_tval) * count_const + - sizeof(duk_hobject *) * count_funcs + - sizeof(duk_instr_t) * count_instr; + data_size = sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs + sizeof(duk_instr_t) * count_instr; DUK_DD(DUK_DDPRINT("instr=%ld, const=%ld, funcs=%ld, data_size=%ld", - (long) count_instr, (long) count_const, - (long) count_const, (long) data_size)); + (long) count_instr, + (long) count_const, + (long) count_const, + (long) data_size)); /* Value stack is used to ensure reachability of constants and * inner functions being loaded. Require enough space to handle @@ -14221,12 +14922,12 @@ h_fun->start_line = DUK_RAW_READINC_U32_BE(p); h_fun->end_line = DUK_RAW_READINC_U32_BE(p); #else - p += 8; /* skip line info */ + p += 8; /* skip line info */ #endif /* duk_hcompfunc flags; quite version specific */ tmp32 = DUK_RAW_READINC_U32_BE(p); - DUK_HEAPHDR_SET_FLAGS((duk_heaphdr *) h_fun, tmp32); /* masks flags to only change duk_hobject flags */ + DUK_HEAPHDR_SET_FLAGS((duk_heaphdr *) h_fun, tmp32); /* masks flags to only change duk_hobject flags */ /* standard prototype (no need to set here, already set) */ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_fun) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); @@ -14254,9 +14955,7 @@ DUK__ASSERT_LEFT(count_instr * sizeof(duk_instr_t)); #if defined(DUK_USE_INTEGER_BE) q = fun_data + sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs; - duk_memcpy((void *) q, - (const void *) p, - sizeof(duk_instr_t) * count_instr); + duk_memcpy((void *) q, (const void *) p, sizeof(duk_instr_t) * count_instr); p += sizeof(duk_instr_t) * count_instr; #else q = fun_data + sizeof(duk_tval) * count_const + sizeof(duk_hobject *) * count_funcs; @@ -14315,13 +15014,13 @@ DUK_HCOMPFUNC_SET_DATA(thr->heap, h_fun, h_data); DUK_HBUFFER_INCREF(thr, h_data); - tv1 = duk_get_tval(thr, idx_base + 2); /* may be NULL if no constants or inner funcs */ + tv1 = duk_get_tval(thr, idx_base + 2); /* may be NULL if no constants or inner funcs */ DUK_ASSERT((count_const == 0 && count_funcs == 0) || tv1 != NULL); q = fun_data; duk_memcpy_unsafe((void *) q, (const void *) tv1, sizeof(duk_tval) * count_const); for (n = count_const; n > 0; n--) { - DUK_TVAL_INCREF_FAST(thr, (duk_tval *) (void *) q); /* no side effects */ + DUK_TVAL_INCREF_FAST(thr, (duk_tval *) (void *) q); /* no side effects */ q += sizeof(duk_tval); } tv1 += count_const; @@ -14354,7 +15053,7 @@ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); #if defined(DUK_USE_FUNC_NAME_PROPERTY) - p = duk__load_string_raw(thr, p); /* -> func funcname */ + p = duk__load_string_raw(thr, p); /* -> func funcname */ func_env = thr->builtinsDUK_BIDX_GLOBAL_ENV; DUK_ASSERT(func_env != NULL); need_pop = 0; @@ -14365,11 +15064,10 @@ */ duk_hdecenv *new_env; - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); - DUK_ASSERT(new_env->thread == NULL); /* Closed. */ + DUK_ASSERT(new_env->thread == NULL); /* Closed. */ DUK_ASSERT(new_env->varmap == NULL); DUK_ASSERT(new_env->regbase_byteoff == 0); DUK_HDECENV_ASSERT_VALID(new_env); @@ -14381,11 +15079,11 @@ duk_push_hobject(thr, (duk_hobject *) new_env); - duk_dup_m2(thr); /* -> func funcname env funcname */ - duk_dup(thr, idx_base); /* -> func funcname env funcname func */ - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> func funcname env */ + duk_dup_m2(thr); /* -> func funcname env funcname */ + duk_dup(thr, idx_base); /* -> func funcname env funcname func */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> func funcname env */ - need_pop = 1; /* Need to pop env, but -after- updating h_fun and increfs. */ + need_pop = 1; /* Need to pop env, but -after- updating h_fun and increfs. */ } DUK_ASSERT(func_env != NULL); DUK_HCOMPFUNC_SET_LEXENV(thr->heap, h_fun, func_env); @@ -14396,12 +15094,12 @@ duk_pop(thr); } duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ #if defined(DUK_USE_FUNC_FILENAME_PROPERTY) p = duk__load_string_raw(thr, p); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_C); -#endif /* DUK_USE_FUNC_FILENAME_PROPERTY */ +#endif /* DUK_USE_FUNC_FILENAME_PROPERTY */ if (DUK_HOBJECT_HAS_CONSTRUCTABLE((duk_hobject *) h_fun)) { /* Restore empty external .prototype only for constructable @@ -14411,7 +15109,10 @@ duk_push_object(thr); DUK_ASSERT(!duk_is_bare_object(thr, -1)); duk_dup_m2(thr); - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC); /* func.prototype.constructor = func */ + duk_xdef_prop_stridx_short(thr, + -2, + DUK_STRIDX_CONSTRUCTOR, + DUK_PROPDESC_FLAGS_WC); /* func.prototype.constructor = func */ duk_compact_m1(thr); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); } @@ -14419,9 +15120,9 @@ #if defined(DUK_USE_PC2LINE) p = duk__load_buffer_raw(thr, p); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_WC); -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ - duk_push_bare_object(thr); /* _Varmap */ + duk_push_bare_object(thr); /* _Varmap */ for (;;) { /* XXX: awkward */ p = duk__load_string_raw(thr, p); @@ -14441,7 +15142,7 @@ */ arr_limit = DUK_RAW_READINC_U32_BE(p); if (arr_limit != DUK__NO_FORMALS) { - duk_push_bare_array(thr); /* _Formals */ + duk_push_bare_array(thr); /* _Formals */ for (arr_idx = 0; arr_idx < arr_limit; arr_idx++) { p = duk__load_string_raw(thr, p); duk_put_prop_index(thr, -2, arr_idx); @@ -14457,7 +15158,7 @@ DUK_ASSERT_TOP(thr, idx_base + 1); return p; - format_error: +format_error: return NULL; } @@ -14489,7 +15190,7 @@ DUK_DD(DUK_DDPRINT("serialized result: %!T", duk_get_tval(thr, -1))); - duk_remove_m2(thr); /* ... func buf -> ... buf */ + duk_remove_m2(thr); /* ... func buf -> ... buf */ } DUK_EXTERNAL void duk_load_function(duk_hthread *thr) { @@ -14522,15 +15223,15 @@ goto format_error; } - duk_remove_m2(thr); /* ... buf func -> ... func */ + duk_remove_m2(thr); /* ... buf func -> ... func */ return; - format_error: +format_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BYTECODE); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BYTECODE_DUMP_SUPPORT */ +#else /* DUK_USE_BYTECODE_DUMP_SUPPORT */ DUK_EXTERNAL void duk_dump_function(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); @@ -14544,7 +15245,7 @@ DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BYTECODE_DUMP_SUPPORT */ +#endif /* DUK_USE_BYTECODE_DUMP_SUPPORT */ /* automatic undefs */ #undef DUK__ASSERT_LEFT @@ -14607,7 +15308,7 @@ DUK_ASSERT(other >= 0); idx_func = duk_get_top(thr) - nargs - other; - if (DUK_UNLIKELY((idx_func | nargs) < 0)) { /* idx_func < 0 || nargs < 0; OR sign bits */ + if (DUK_UNLIKELY((idx_func | nargs) < 0)) { /* idx_func < 0 || nargs < 0; OR sign bits */ DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } @@ -14641,12 +15342,14 @@ DUK_ASSERT(nargs >= 0); DUK_DDD(DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_idx=%ld, nargs=%ld, stacktop=%ld", - (long) normalized_obj_idx, (long) nargs, (long) duk_get_top(thr))); + (long) normalized_obj_idx, + (long) nargs, + (long) duk_get_top(thr))); /* ... key arg1 ... argN */ /* duplicate key */ - duk_dup(thr, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */ + duk_dup(thr, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */ (void) duk_get_prop(thr, normalized_obj_idx); DUK_DDD(DUK_DDDPRINT("func: %!T", (duk_tval *) duk_get_tval(thr, -1))); @@ -14689,7 +15392,7 @@ duk_insert_undefined(thr, idx_func + 1); - call_flags = 0; /* not protected, respect reclimit, not constructor */ + call_flags = 0; /* not protected, respect reclimit, not constructor */ duk_handle_call_unprotected(thr, idx_func, call_flags); } @@ -14702,7 +15405,7 @@ idx_func = duk__call_get_idx_func(thr, nargs, 2); DUK_ASSERT(duk_is_valid_index(thr, idx_func)); - call_flags = 0; /* not protected, respect reclimit, not constructor */ + call_flags = 0; /* not protected, respect reclimit, not constructor */ duk_handle_call_unprotected(thr, idx_func, call_flags); } @@ -14716,7 +15419,7 @@ DUK_ASSERT_API_ENTRY(thr); - obj_idx = duk_require_normalize_index(thr, obj_idx); /* make absolute */ + obj_idx = duk_require_normalize_index(thr, obj_idx); /* make absolute */ if (DUK_UNLIKELY(nargs < 0)) { DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return;); @@ -14814,7 +15517,7 @@ args = (duk__pcall_prop_args *) udata; - obj_idx = duk_require_normalize_index(thr, args->obj_idx); /* make absolute */ + obj_idx = duk_require_normalize_index(thr, args->obj_idx); /* make absolute */ duk__call_prop_prep_stack(thr, obj_idx, args->nargs); ret = duk_handle_call_unprotected_nargs(thr, args->nargs, args->call_flags); @@ -14852,30 +15555,30 @@ */ /* XXX: check for any reserve? */ - if (DUK_UNLIKELY((nargs | nrets) < 0 || /* nargs < 0 || nrets < 0; OR sign bits */ - thr->valstack_top < thr->valstack_bottom + nargs || /* nargs too large compared to top */ - thr->valstack_end + nargs < thr->valstack_top + nrets)) { /* nrets too large compared to reserve */ + if (DUK_UNLIKELY((nargs | nrets) < 0 || /* nargs < 0 || nrets < 0; OR sign bits */ + thr->valstack_top < thr->valstack_bottom + nargs || /* nargs too large compared to top */ + thr->valstack_end + nargs < thr->valstack_top + nrets)) { /* nrets too large compared to reserve */ DUK_D(DUK_DPRINT("not enough stack reserve for safe call or invalid arguments: " "nargs=%ld < 0 (?), nrets=%ld < 0 (?), top=%ld < bottom=%ld + nargs=%ld (?), " "end=%ld + nargs=%ld < top=%ld + nrets=%ld (?)", - (long) nargs, - (long) nrets, - (long) (thr->valstack_top - thr->valstack), - (long) (thr->valstack_bottom - thr->valstack), - (long) nargs, - (long) (thr->valstack_end - thr->valstack), - (long) nargs, - (long) (thr->valstack_top - thr->valstack), - (long) nrets)); + (long) nargs, + (long) nrets, + (long) (thr->valstack_top - thr->valstack), + (long) (thr->valstack_bottom - thr->valstack), + (long) nargs, + (long) (thr->valstack_end - thr->valstack), + (long) nargs, + (long) (thr->valstack_top - thr->valstack), + (long) nrets)); DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return DUK_EXEC_ERROR;); } - rc = duk_handle_safe_call(thr, /* thread */ - func, /* func */ - udata, /* udata */ - nargs, /* num_stack_args */ - nrets); /* num_stack_res */ + rc = duk_handle_safe_call(thr, /* thread */ + func, /* func */ + udata, /* udata */ + nargs, /* num_stack_args */ + nrets); /* num_stack_res */ return rc; } @@ -14888,7 +15591,7 @@ idx_func = duk__call_get_idx_func(thr, nargs, 1); DUK_ASSERT(duk_is_valid_index(thr, idx_func)); - duk_push_object(thr); /* default instance; internal proto updated by call handling */ + duk_push_object(thr); /* default instance; internal proto updated by call handling */ duk_insert(thr, idx_func + 1); duk_handle_call_unprotected(thr, idx_func, DUK_CALL_FLAG_CONSTRUCT); @@ -15016,7 +15719,7 @@ } /* fall through */ - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_UNEXPECTED_TYPE); DUK_WO_NORETURN(return 0;); } @@ -15091,15 +15794,16 @@ * is guaranteed to be non-NULL, even for zero length input. */ DUK_LOCAL const duk_uint8_t *duk__prep_codec_arg(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) { - const void *def_ptr = (const void *) out_len; /* Any non-NULL pointer will do. */ + const void *def_ptr = (const void *) out_len; /* Any non-NULL pointer will do. */ const void *ptr; duk_bool_t isbuffer; DUK_ASSERT(out_len != NULL); DUK_ASSERT(def_ptr != NULL); - DUK_ASSERT(duk_is_valid_index(thr, idx)); /* checked by caller */ + DUK_ASSERT(duk_is_valid_index(thr, idx)); /* checked by caller */ - ptr = (const void *) duk_get_buffer_data_raw(thr, idx, out_len, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, &isbuffer); + ptr = (const void *) + duk_get_buffer_data_raw(thr, idx, out_len, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, &isbuffer); if (isbuffer) { DUK_ASSERT(ptr != NULL || *out_len == 0U); if (DUK_UNLIKELY(ptr == NULL)) { @@ -15124,21 +15828,21 @@ #if defined(DUK_USE_BASE64_SUPPORT) /* Bytes emitted for number of padding characters in range 0,4. */ DUK_LOCAL const duk_int8_t duk__base64_decode_nequal_step5 = { - 3, /* #### -> 24 bits, emit 3 bytes */ - 2, /* ###= -> 18 bits, emit 2 bytes */ - 1, /* ##== -> 12 bits, emit 1 byte */ - -1, /* #=== -> 6 bits, error */ - 0, /* ==== -> 0 bits, emit 0 bytes */ + 3, /* #### -> 24 bits, emit 3 bytes */ + 2, /* ###= -> 18 bits, emit 2 bytes */ + 1, /* ##== -> 12 bits, emit 1 byte */ + -1, /* #=== -> 6 bits, error */ + 0, /* ==== -> 0 bits, emit 0 bytes */ }; #if defined(DUK_USE_BASE64_FASTPATH) DUK_LOCAL const duk_uint8_t duk__base64_enctab_fast64 = { - 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x50U, /* A...P */ - 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x58U, 0x59U, 0x5aU, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, /* Q...f */ - 0x67U, 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, 0x6fU, 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, /* g...v */ - 0x77U, 0x78U, 0x79U, 0x7aU, 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x2bU, 0x2fU /* w.../ */ + 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x50U, /* A...P */ + 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x58U, 0x59U, 0x5aU, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, /* Q...f */ + 0x67U, 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, 0x6fU, 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, /* g...v */ + 0x77U, 0x78U, 0x79U, 0x7aU, 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x2bU, 0x2fU /* w.../ */ }; -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) /* Decode table for one byte of input: @@ -15148,24 +15852,24 @@ * 0...63 decoded bytes */ DUK_LOCAL const duk_int8_t duk__base64_dectab_fast256 = { - -3, -3, -3, -3, -3, -3, -3, -3, -3, -1, -1, -3, -3, -1, -3, -3, /* 0x00...0x0f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x10...0x1f */ - -1, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 62, -3, -3, -3, 63, /* 0x20...0x2f */ - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -3, -3, -3, -2, -3, -3, /* 0x30...0x3f */ - -3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40...0x4f */ - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -3, -3, -3, -3, -3, /* 0x50...0x5f */ - -3, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60...0x6f */ - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -3, -3, -3, -3, -3, /* 0x70...0x7f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x80...0x8f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x90...0x9f */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xa0...0xaf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xb0...0xbf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xc0...0xcf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xd0...0xdf */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xe0...0xef */ - -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3 /* 0xf0...0xff */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -1, -1, -3, -3, -1, -3, -3, /* 0x00...0x0f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x10...0x1f */ + -1, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 62, -3, -3, -3, 63, /* 0x20...0x2f */ + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -3, -3, -3, -2, -3, -3, /* 0x30...0x3f */ + -3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40...0x4f */ + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -3, -3, -3, -3, -3, /* 0x50...0x5f */ + -3, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60...0x6f */ + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -3, -3, -3, -3, -3, /* 0x70...0x7f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x80...0x8f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0x90...0x9f */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xa0...0xaf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xb0...0xbf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xc0...0xcf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xd0...0xdf */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, /* 0xe0...0xef */ + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3 /* 0xf0...0xff */ }; -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) DUK_LOCAL DUK_ALWAYS_INLINE void duk__base64_encode_fast_3(const duk_uint8_t *src, duk_uint8_t *dst) { @@ -15197,9 +15901,9 @@ t = (duk_uint_t) src0; t = (t << 8) + (duk_uint_t) src1; - dst0 = duk__base64_enctab_fastt >> 10; /* XXXXXX-- -------- */ - dst1 = duk__base64_enctab_fast(t >> 4) & 0x3fU; /* ------XX XXXX---- */ - dst2 = duk__base64_enctab_fast(t << 2) & 0x3fU; /* -------- ----XXXX */ + dst0 = duk__base64_enctab_fastt >> 10; /* XXXXXX-- -------- */ + dst1 = duk__base64_enctab_fast(t >> 4) & 0x3fU; /* ------XX XXXX---- */ + dst2 = duk__base64_enctab_fast(t << 2) & 0x3fU; /* -------- ----XXXX */ dst3 = DUK_ASC_EQUALS; } @@ -15207,8 +15911,8 @@ duk_uint_t t; t = (duk_uint_t) src0; - dst0 = duk__base64_enctab_fastt >> 2; /* XXXXXX-- */ - dst1 = duk__base64_enctab_fast(t << 4) & 0x3fU; /* ------XX */ + dst0 = duk__base64_enctab_fastt >> 2; /* XXXXXX-- */ + dst1 = duk__base64_enctab_fast(t << 4) & 0x3fU; /* ------XX */ dst2 = DUK_ASC_EQUALS; dst3 = DUK_ASC_EQUALS; } @@ -15256,24 +15960,24 @@ DUK_ASSERT(n == 0U || n == 1U || n == 2U); if (n == 1U) { duk__base64_encode_fast_1(p, q); -#if 0 /* Unnecessary. */ +#if 0 /* Unnecessary. */ p += 1; q += 4; n -= 1U; #endif } else if (n == 2U) { duk__base64_encode_fast_2(p, q); -#if 0 /* Unnecessary. */ +#if 0 /* Unnecessary. */ p += 2; q += 4; n -= 2U; #endif } else { - DUK_ASSERT(n == 0U); /* nothing to do */ + DUK_ASSERT(n == 0U); /* nothing to do */ ; } } -#else /* DUK_USE_BASE64_FASTPATH */ +#else /* DUK_USE_BASE64_FASTPATH */ DUK_LOCAL void duk__base64_encode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst) { duk_small_uint_t i, npad; duk_uint_t t, x, y; @@ -15345,10 +16049,13 @@ npad--; } } -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ #if defined(DUK_USE_BASE64_FASTPATH) -DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst, duk_uint8_t **out_dst_final) { +DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, + duk_size_t srclen, + duk_uint8_t *dst, + duk_uint8_t **out_dst_final) { duk_int_t x; duk_uint_t t; duk_small_uint_t n_equal; @@ -15358,11 +16065,11 @@ const duk_uint8_t *p_end_safe; duk_uint8_t *q; - DUK_ASSERT(src != NULL); /* Required by pointer arithmetic below, which fails for NULL. */ + DUK_ASSERT(src != NULL); /* Required by pointer arithmetic below, which fails for NULL. */ p = src; p_end = src + srclen; - p_end_safe = p_end - 8; /* If 'src <= src_end_safe', safe to read 8 bytes. */ + p_end_safe = p_end - 8; /* If 'src <= src_end_safe', safe to read 8 bytes. */ q = dst; /* Alternate between a fast path which processes clean groups with no @@ -15392,7 +16099,9 @@ * bytes to minimize aliasing. */ DUK_DDD(DUK_DDDPRINT("fast loop: p=%p, p_end_safe=%p, p_end=%p", - (const void *) p, (const void *) p_end_safe, (const void *) p_end)); + (const void *) p, + (const void *) p_end_safe, + (const void *) p_end)); t1 = (duk_int_t) duk__base64_dectab_fastp0; t1 = (duk_int_t) ((duk_uint_t) t1 << 6) | (duk_int_t) duk__base64_dectab_fastp1; @@ -15417,17 +16126,19 @@ p += 8; q += 6; } else if (t1 >= 0) { - DUK_DDD(DUK_DDDPRINT("fast loop first group was clean, second was not, process one slow path group")); + DUK_DDD( + DUK_DDDPRINT("fast loop first group was clean, second was not, process one slow path group")); DUK_ASSERT(t2 < 0); p += 4; q += 3; break; } else { - DUK_DDD(DUK_DDDPRINT("fast loop first group was not clean, second does not matter, process one slow path group")); + DUK_DDD(DUK_DDDPRINT( + "fast loop first group was not clean, second does not matter, process one slow path group")); DUK_ASSERT(t1 < 0); break; } - } /* fast path */ + } /* fast path */ /* Slow path step 1: try to scan a 4-character encoded group, * end-of-input, or start-of-padding. We exit with: @@ -15442,7 +16153,9 @@ t = 1UL; for (;;) { DUK_DDD(DUK_DDDPRINT("slow loop: p=%p, p_end=%p, t=%lu", - (const void *) p, (const void *) p_end, (unsigned long) t)); + (const void *) p, + (const void *) p_end, + (unsigned long) t)); if (DUK_LIKELY(p < p_end)) { x = duk__base64_dectab_fast*p++; @@ -15453,18 +16166,18 @@ break; } } else if (x == -1) { - continue; /* allowed ascii whitespace */ + continue; /* allowed ascii whitespace */ } else if (x == -2) { p--; - break; /* start of padding */ + break; /* start of padding */ } else { DUK_ASSERT(x == -3); goto decode_error; } } else { - break; /* end of input */ + break; /* end of input */ } - } /* slow path step 1 */ + } /* slow path step 1 */ /* Complete the padding by simulating pad characters, * regardless of actual input padding chars. @@ -15523,28 +16236,30 @@ } x = duk__base64_dectab_fast*p++; if (x == -1 || x == -2) { - ; /* padding or whitespace, keep eating */ + ; /* padding or whitespace, keep eating */ } else { p--; - break; /* backtrack and go back to fast path, even for -1 */ + break; /* backtrack and go back to fast path, even for -1 */ } - } /* slow path step 3 */ - } /* outer fast+slow path loop */ + } /* slow path step 3 */ + } /* outer fast+slow path loop */ - done: - DUK_DDD(DUK_DDDPRINT("done; p=%p, p_end=%p", - (const void *) p, (const void *) p_end)); +done: + DUK_DDD(DUK_DDDPRINT("done; p=%p, p_end=%p", (const void *) p, (const void *) p_end)); DUK_ASSERT(p == p_end); *out_dst_final = q; return 1; - decode_error: +decode_error: return 0; } -#else /* DUK_USE_BASE64_FASTPATH */ -DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_t srclen, duk_uint8_t *dst, duk_uint8_t **out_dst_final) { +#else /* DUK_USE_BASE64_FASTPATH */ +DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, + duk_size_t srclen, + duk_uint8_t *dst, + duk_uint8_t **out_dst_final) { duk_uint_t t, x; duk_int_t y; duk_int8_t step; @@ -15630,7 +16345,7 @@ } else { /* Valid: whitespace. */ duk_uint32_t m; - DUK_ASSERT(x < 0x20U); /* 0x00 to 0x1f */ + DUK_ASSERT(x < 0x20U); /* 0x00 to 0x1f */ m = (1U << x); if (mask_white & m) { /* Allow basic ASCII whitespace. */ @@ -15647,7 +16362,7 @@ } /* fall through; no padding will be added */ - simulate_padding: + simulate_padding: n_equal = 0; while (t < 0x1000000UL) { t = (t << 6) + 0U; @@ -15679,10 +16394,10 @@ *out_dst_final = q; return 1; - decode_error: +decode_error: return 0; } -#endif /* DUK_USE_BASE64_FASTPATH */ +#endif /* DUK_USE_BASE64_FASTPATH */ DUK_EXTERNAL const char *duk_base64_encode(duk_hthread *thr, duk_idx_t idx) { const duk_uint8_t *src; @@ -15711,11 +16426,11 @@ duk__base64_encode_helper((const duk_uint8_t *) src, srclen, dst); - ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ + ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ duk_replace(thr, idx); return ret; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_BASE64_ENCODE_FAILED); DUK_WO_NORETURN(return NULL;); } @@ -15740,7 +16455,7 @@ * Similarly, 'xx' may ecause 1+3 = bytes to be emitted and then * backtracked. */ - dstlen = (srclen / 4) * 3 + 6; /* upper limit, assuming no whitespace etc */ + dstlen = (srclen / 4) * 3 + 6; /* upper limit, assuming no whitespace etc */ dst = (duk_uint8_t *) duk_push_dynamic_buffer(thr, dstlen); /* Note: for dstlen=0, dst may be NULL */ @@ -15753,11 +16468,11 @@ duk_replace(thr, idx); return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_BASE64_DECODE_FAILED); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BASE64_SUPPORT */ +#else /* DUK_USE_BASE64_SUPPORT */ DUK_EXTERNAL const char *duk_base64_encode(duk_hthread *thr, duk_idx_t idx) { DUK_UNREF(idx); DUK_ERROR_UNSUPPORTED(thr); @@ -15769,7 +16484,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BASE64_SUPPORT */ +#endif /* DUK_USE_BASE64_SUPPORT */ /* * Hex @@ -15798,7 +16513,7 @@ DUK_ASSERT(buf != NULL); #if defined(DUK_USE_HEX_FASTPATH) - DUK_ASSERT((((duk_size_t) buf) & 0x01U) == 0); /* pointer is aligned, guaranteed for fixed buffer */ + DUK_ASSERT((((duk_size_t) buf) & 0x01U) == 0); /* pointer is aligned, guaranteed for fixed buffer */ p16 = (duk_uint16_t *) (void *) buf; len_safe = len & ~0x03U; for (i = 0; i < len_safe; i += 4) { @@ -15811,14 +16526,14 @@ for (; i < len; i++) { *p16++ = duk_hex_enctabinpi; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ for (i = 0; i < len; i++) { duk_small_uint_t t; t = (duk_small_uint_t) inpi; - bufi*2 + 0 = duk_lc_digitst >> 4; - bufi*2 + 1 = duk_lc_digitst & 0x0f; + bufi * 2 + 0 = duk_lc_digitst >> 4; + bufi * 2 + 1 = duk_lc_digitst & 0x0f; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ /* XXX: Using a string return value forces a string intern which is * not always necessary. As a rough performance measure, hex encode @@ -15827,7 +16542,7 @@ * caller coerce to string if necessary? */ - ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ + ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */ duk_replace(thr, idx); return ret; } @@ -15862,20 +16577,16 @@ p = buf; len_safe = len & ~0x07U; for (i = 0; i < len_safe; i += 8) { - t = ((duk_int_t) duk_hex_dectab_shift4inpi) | - ((duk_int_t) duk_hex_dectabinpi + 1); + t = ((duk_int_t) duk_hex_dectab_shift4inpi) | ((duk_int_t) duk_hex_dectabinpi + 1); chk = t; p0 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 2) | - ((duk_int_t) duk_hex_dectabinpi + 3); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 2) | ((duk_int_t) duk_hex_dectabinpi + 3); chk |= t; p1 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 4) | - ((duk_int_t) duk_hex_dectabinpi + 5); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 4) | ((duk_int_t) duk_hex_dectabinpi + 5); chk |= t; p2 = (duk_uint8_t) t; - t = ((duk_int_t) duk_hex_dectab_shift4inpi + 6) | - ((duk_int_t) duk_hex_dectabinpi + 7); + t = ((duk_int_t) duk_hex_dectab_shift4inpi + 6) | ((duk_int_t) duk_hex_dectabinpi + 7); chk |= t; p3 = (duk_uint8_t) t; p += 4; @@ -15897,7 +16608,7 @@ } *p++ = (duk_uint8_t) t; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ for (i = 0; i < len; i += 2) { /* For invalid characters the value -1 gets extended to * at least 16 bits. If either nybble is invalid, the @@ -15910,16 +16621,16 @@ } bufi >> 1 = (duk_uint8_t) t; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ duk_replace(thr, idx); return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_HEX_DECODE_FAILED); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_HEX_SUPPORT */ +#else /* DUK_USE_HEX_SUPPORT */ DUK_EXTERNAL const char *duk_hex_encode(duk_hthread *thr, duk_idx_t idx) { DUK_UNREF(idx); DUK_ERROR_UNSUPPORTED(thr); @@ -15930,7 +16641,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_HEX_SUPPORT */ +#endif /* DUK_USE_HEX_SUPPORT */ /* * JSON @@ -15974,15 +16685,12 @@ #endif idx = duk_require_normalize_index(thr, idx); - duk_bi_json_parse_helper(thr, - idx /*idx_value*/, - DUK_INVALID_INDEX /*idx_reviver*/, - 0 /*flags*/); + duk_bi_json_parse_helper(thr, idx /*idx_value*/, DUK_INVALID_INDEX /*idx_reviver*/, 0 /*flags*/); duk_replace(thr, idx); DUK_ASSERT(duk_get_top(thr) == top_at_entry); } -#else /* DUK_USE_JSON_SUPPORT */ +#else /* DUK_USE_JSON_SUPPORT */ DUK_EXTERNAL const char *duk_json_encode(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx); @@ -15996,7 +16704,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */ #line 1 "duk_api_compile.c" /* * Compilation and evaluation @@ -16006,7 +16714,7 @@ typedef struct duk__compile_raw_args duk__compile_raw_args; struct duk__compile_raw_args { - duk_size_t src_length; /* should be first on 64-bit platforms */ + duk_size_t src_length; /* should be first on 64-bit platforms */ const duk_uint8_t *src_buffer; duk_uint_t flags; }; @@ -16026,7 +16734,10 @@ /* ... source? filename? (depends on flags) */ - rc = duk_compile_raw(thr, src_buffer, src_length, flags | DUK_COMPILE_EVAL); /* may be safe, or non-safe depending on flags */ + rc = duk_compile_raw(thr, + src_buffer, + src_length, + flags | DUK_COMPILE_EVAL); /* may be safe, or non-safe depending on flags */ /* ... closure/error */ @@ -16035,7 +16746,7 @@ goto got_rc; } - duk_push_global_object(thr); /* explicit 'this' binding, see GH-164 */ + duk_push_global_object(thr); /* explicit 'this' binding, see GH-164 */ if (flags & DUK_COMPILE_SAFE) { rc = duk_pcall_method(thr, 0); @@ -16046,7 +16757,7 @@ /* ... result/error */ - got_rc: +got_rc: if (flags & DUK_COMPILE_NORESULT) { duk_pop(thr); } @@ -16086,8 +16797,8 @@ duk_hstring *h_sourcecode; h_sourcecode = duk_get_hstring(thr, -2); - if ((flags & DUK_COMPILE_NOSOURCE) || /* args incorrect */ - (h_sourcecode == NULL)) { /* e.g. duk_push_string_file_raw() pushed undefined */ + if ((flags & DUK_COMPILE_NOSOURCE) || /* args incorrect */ + (h_sourcecode == NULL)) { /* e.g. duk_push_string_file_raw() pushed undefined */ DUK_ERROR_TYPE(thr, DUK_STR_NO_SOURCECODE); DUK_WO_NORETURN(return 0;); } @@ -16117,11 +16828,11 @@ h_templ = (duk_hcompfunc *) duk_known_hobject(thr, -1); duk_js_push_closure(thr, - h_templ, - thr->builtinsDUK_BIDX_GLOBAL_ENV, - thr->builtinsDUK_BIDX_GLOBAL_ENV, - 1 /*add_auto_proto*/); - duk_remove_m2(thr); /* -> ... closure */ + h_templ, + thr->builtinsDUK_BIDX_GLOBAL_ENV, + thr->builtinsDUK_BIDX_GLOBAL_ENV, + 1 /*add_auto_proto*/); + duk_remove_m2(thr); /* -> ... closure */ /* ... closure */ @@ -16157,8 +16868,7 @@ * directly into flags. */ nargs = flags & 0x07; - DUK_ASSERT(nargs == ((flags & DUK_COMPILE_NOSOURCE) ? 0 : 1) + - ((flags & DUK_COMPILE_NOFILENAME) ? 0 : 1)); + DUK_ASSERT(nargs == ((flags & DUK_COMPILE_NOSOURCE) ? 0 : 1) + ((flags & DUK_COMPILE_NOFILENAME) ? 0 : 1)); rc = duk_safe_call(thr, duk__do_compile, (void *) comp_args, nargs, nrets); /* ... closure */ @@ -16199,25 +16909,24 @@ * Perhaps values need to be coerced individually? */ duk_bi_json_stringify_helper(thr, - duk_get_top_index(thr), /*idx_value*/ - DUK_INVALID_INDEX, /*idx_replacer*/ - DUK_INVALID_INDEX, /*idx_space*/ - DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_ASCII_ONLY | - DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); + duk_get_top_index(thr), /*idx_value*/ + DUK_INVALID_INDEX, /*idx_replacer*/ + DUK_INVALID_INDEX, /*idx_space*/ + DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_ASCII_ONLY | + DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); duk_push_sprintf(thr, "ctx: top=%ld, stack=%s", (long) top, (const char *) duk_safe_to_string(thr, -1)); - duk_replace(thr, -3); /* ... arr jsonx(arr) res -> ... res jsonx(arr) */ + duk_replace(thr, -3); /* ... arr jsonx(arr) res -> ... res jsonx(arr) */ duk_pop(thr); DUK_ASSERT(duk_is_string(thr, -1)); } -#else /* DUK_USE_JSON_SUPPORT */ +#else /* DUK_USE_JSON_SUPPORT */ DUK_EXTERNAL void duk_push_context_dump(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */ #if defined(DUK_USE_DEBUGGER_SUPPORT) @@ -16266,12 +16975,13 @@ heap->dbg_exec_counter = 0; heap->dbg_last_counter = 0; heap->dbg_last_time = 0.0; - duk_debug_set_paused(heap); /* XXX: overlap with fields above */ + duk_debug_set_paused(heap); /* XXX: overlap with fields above */ /* Send version identification and flush right afterwards. Note that * we must write raw, unframed bytes here. */ - duk_push_sprintf(thr, "%ld %ld %s %s\n", + duk_push_sprintf(thr, + "%ld %ld %s %s\n", (long) DUK_DEBUG_PROTOCOL_VERSION, (long) DUK_VERSION, (const char *) DUK_GIT_DESCRIBE, @@ -16373,7 +17083,7 @@ } } -#else /* DUK_USE_DEBUGGER_SUPPORT */ +#else /* DUK_USE_DEBUGGER_SUPPORT */ DUK_EXTERNAL void duk_debugger_attach(duk_hthread *thr, duk_debug_read_function read_cb, @@ -16431,7 +17141,7 @@ DUK_UNREF(thr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ #line 1 "duk_api_heap.c" /* * Heap creation and destruction @@ -16520,7 +17230,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(state != NULL); /* unvalidated */ + DUK_ASSERT(state != NULL); /* unvalidated */ /* Currently not supported when called from within a finalizer. * If that is done, the finalizer will remain running indefinitely, @@ -16564,7 +17274,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(state != NULL); /* unvalidated */ + DUK_ASSERT(state != NULL); /* unvalidated */ /* Shouldn't be necessary if duk_suspend() is called before * duk_resume(), but assert in case API sequence is incorrect. @@ -16606,7 +17316,7 @@ DUK_UNREF(h_prev_glob); thr->builtinsDUK_BIDX_GLOBAL = h_glob; DUK_HOBJECT_INCREF(thr, h_glob); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_glob); /* side effects, in theory (referenced by global env) */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_glob); /* side effects, in theory (referenced by global env) */ /* * Replace lexical environment for global scope @@ -16617,9 +17327,7 @@ * same (initial) built-ins. */ - h_env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + h_env = duk_hobjenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(h_env != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_env) == NULL); @@ -16634,8 +17342,8 @@ h_prev_env = thr->builtinsDUK_BIDX_GLOBAL_ENV; thr->builtinsDUK_BIDX_GLOBAL_ENV = (duk_hobject *) h_env; DUK_HOBJECT_INCREF(thr, (duk_hobject *) h_env); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_env); /* side effects */ - DUK_UNREF(h_env); /* without refcounts */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, h_prev_env); /* side effects */ + DUK_UNREF(h_env); /* without refcounts */ DUK_UNREF(h_prev_env); /* ... new_glob */ @@ -16686,20 +17394,20 @@ * be security implications. */ -#define DUK__IDX_TYPE 0 -#define DUK__IDX_ITAG 1 -#define DUK__IDX_REFC 2 -#define DUK__IDX_HBYTES 3 -#define DUK__IDX_CLASS 4 -#define DUK__IDX_PBYTES 5 -#define DUK__IDX_ESIZE 6 -#define DUK__IDX_ENEXT 7 -#define DUK__IDX_ASIZE 8 -#define DUK__IDX_HSIZE 9 -#define DUK__IDX_BCBYTES 10 -#define DUK__IDX_DBYTES 11 -#define DUK__IDX_TSTATE 12 -#define DUK__IDX_VARIANT 13 +#define DUK__IDX_TYPE 0 +#define DUK__IDX_ITAG 1 +#define DUK__IDX_REFC 2 +#define DUK__IDX_HBYTES 3 +#define DUK__IDX_CLASS 4 +#define DUK__IDX_PBYTES 5 +#define DUK__IDX_ESIZE 6 +#define DUK__IDX_ENEXT 7 +#define DUK__IDX_ASIZE 8 +#define DUK__IDX_HSIZE 9 +#define DUK__IDX_BCBYTES 10 +#define DUK__IDX_DBYTES 11 +#define DUK__IDX_TSTATE 12 +#define DUK__IDX_VARIANT 13 DUK_EXTERNAL void duk_inspect_value(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; @@ -16714,7 +17422,7 @@ /* Assume two's complement and set everything to -1. */ duk_memset((void *) &vals, (int) 0xff, sizeof(vals)); - DUK_ASSERT(valsDUK__IDX_TYPE == -1); /* spot check one */ + DUK_ASSERT(valsDUK__IDX_TYPE == -1); /* spot check one */ tv = duk_get_tval_or_unused(thr, idx); h = (DUK_TVAL_IS_HEAP_ALLOCATED(tv) ? DUK_TVAL_GET_HEAPHDR(tv) : NULL); @@ -16722,7 +17430,7 @@ valsDUK__IDX_TYPE = duk_get_type_tval(tv); valsDUK__IDX_ITAG = (duk_int_t) DUK_TVAL_GET_TAG(tv); - duk_push_bare_object(thr); /* Invalidates 'tv'. */ + duk_push_bare_object(thr); /* Invalidates 'tv'. */ tv = NULL; if (h == NULL) { @@ -16804,30 +17512,56 @@ if (DUK_HBUFFER_HAS_DYNAMIC(h_buf)) { if (DUK_HBUFFER_HAS_EXTERNAL(h_buf)) { - valsDUK__IDX_VARIANT = 2; /* buffer variant 2: external */ + valsDUK__IDX_VARIANT = 2; /* buffer variant 2: external */ valsDUK__IDX_HBYTES = (duk_uint_t) (sizeof(duk_hbuffer_external)); } else { /* When alloc_size == 0 the second allocation may not * actually exist. */ - valsDUK__IDX_VARIANT = 1; /* buffer variant 1: dynamic */ + valsDUK__IDX_VARIANT = 1; /* buffer variant 1: dynamic */ valsDUK__IDX_HBYTES = (duk_uint_t) (sizeof(duk_hbuffer_dynamic)); } valsDUK__IDX_DBYTES = (duk_int_t) (DUK_HBUFFER_GET_SIZE(h_buf)); } else { - DUK_ASSERT(valsDUK__IDX_VARIANT == 0); /* buffer variant 0: fixed */ + DUK_ASSERT(valsDUK__IDX_VARIANT == 0); /* buffer variant 0: fixed */ valsDUK__IDX_HBYTES = (duk_int_t) (sizeof(duk_hbuffer_fixed) + DUK_HBUFFER_GET_SIZE(h_buf)); } break; } } - finish: +finish: duk__inspect_multiple_uint(thr, - "type" "\x00" "itag" "\x00" "refc" "\x00" "hbytes" "\x00" "class" "\x00" - "pbytes" "\x00" "esize" "\x00" "enext" "\x00" "asize" "\x00" "hsize" "\x00" - "bcbytes" "\x00" "dbytes" "\x00" "tstate" "\x00" "variant" "\x00" "\x00", - (duk_int_t *) &vals); + "type" + "\x00" + "itag" + "\x00" + "refc" + "\x00" + "hbytes" + "\x00" + "class" + "\x00" + "pbytes" + "\x00" + "esize" + "\x00" + "enext" + "\x00" + "asize" + "\x00" + "hsize" + "\x00" + "bcbytes" + "\x00" + "dbytes" + "\x00" + "tstate" + "\x00" + "variant" + "\x00" + "\x00", + (duk_int_t *) &vals); } DUK_EXTERNAL void duk_inspect_callstack_entry(duk_hthread *thr, duk_int_t level) { @@ -16967,7 +17701,7 @@ DUK_ASSERT(heap != NULL); DUK_D(DUK_DPRINT("mark-and-sweep requested by application")); - DUK_ASSERT(DUK_GC_COMPACT == DUK_MS_FLAG_EMERGENCY); /* Compact flag is 1:1 with emergency flag which forces compaction. */ + DUK_ASSERT(DUK_GC_COMPACT == DUK_MS_FLAG_EMERGENCY); /* Compact flag is 1:1 with emergency flag which forces compaction. */ ms_flags = (duk_small_uint_t) flags; duk_heap_mark_and_sweep(heap, ms_flags); } @@ -17004,9 +17738,9 @@ DUK_ASSERT(rc == 0 || rc == 1); /* a value is left on stack regardless of rc */ - duk_remove_m2(thr); /* remove key */ + duk_remove_m2(thr); /* remove key */ DUK_ASSERT(duk_is_undefined(thr, -1) || rc == 1); - return rc; /* 1 if property found, 0 otherwise */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_get_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) { @@ -17051,7 +17785,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_get_prop(thr, obj_idx); } @@ -17065,11 +17799,13 @@ } DUK_INTERNAL duk_bool_t duk_get_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_get_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), - (duk_small_uint_t) (packed_args & 0xffffUL)); + return duk_get_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } -DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop) { +DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, + duk_idx_t obj_idx, + duk_small_uint_t stridx, + duk_bool_t *out_has_prop) { duk_bool_t rc; DUK_ASSERT_API_ENTRY(thr); @@ -17114,7 +17850,7 @@ } duk_push_tval(thr, tv_val); - duk_remove_m2(thr); /* remove key */ + duk_remove_m2(thr); /* remove key */ return 1; } @@ -17129,7 +17865,8 @@ } DUK_INTERNAL duk_bool_t duk_xget_owndataprop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_xget_owndataprop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), + return duk_xget_owndataprop_stridx(thr, + (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } @@ -17148,8 +17885,7 @@ /* Key and value indices are either (-2, -1) or (-1, -2). Given idx_key, * idx_val is always (idx_key ^ 0x01). */ - DUK_ASSERT((idx_key == -2 && (idx_key ^ 1) == -1) || - (idx_key == -1 && (idx_key ^ 1) == -2)); + DUK_ASSERT((idx_key == -2 && (idx_key ^ 1) == -1) || (idx_key == -1 && (idx_key ^ 1) == -2)); /* XXX: Direct access; faster validation. */ tv_obj = duk_require_tval(thr, obj_idx); tv_key = duk_require_tval(thr, idx_key); @@ -17159,8 +17895,8 @@ rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, throw_flag); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop_2(thr); /* remove key and value */ - return rc; /* 1 if property found, 0 otherwise */ + duk_pop_2(thr); /* remove key and value */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_put_prop(duk_hthread *thr, duk_idx_t obj_idx) { @@ -17214,11 +17950,10 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk__put_prop_shared(thr, obj_idx, -1); } - DUK_INTERNAL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT_STRIDX_VALID(stridx); @@ -17229,8 +17964,7 @@ } DUK_INTERNAL duk_bool_t duk_put_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - return duk_put_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), - (duk_small_uint_t) (packed_args & 0xffffUL)); + return duk_put_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16), (duk_small_uint_t) (packed_args & 0xffffUL)); } DUK_EXTERNAL duk_bool_t duk_del_prop(duk_hthread *thr, duk_idx_t obj_idx) { @@ -17252,7 +17986,7 @@ rc = duk_hobject_delprop(thr, tv_obj, tv_key, throw_flag); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop(thr); /* remove key */ + duk_pop(thr); /* remove key */ return rc; } @@ -17298,7 +18032,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_del_prop(thr, obj_idx); } @@ -17335,8 +18069,8 @@ rc = duk_hobject_hasprop(thr, tv_obj, tv_key); DUK_ASSERT(rc == 0 || rc == 1); - duk_pop(thr); /* remove key */ - return rc; /* 1 if property found, 0 otherwise */ + duk_pop(thr); /* remove key */ + return rc; /* 1 if property found, 0 otherwise */ } DUK_EXTERNAL duk_bool_t duk_has_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) { @@ -17381,7 +18115,7 @@ DUK_ASSERT_API_ENTRY(thr); obj_idx = duk_require_normalize_index(thr, obj_idx); - (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ + (void) duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */ return duk_has_prop(thr, obj_idx); } @@ -17420,7 +18154,7 @@ duk_hobject_define_property_internal(thr, obj, key, desc_flags); - duk_pop(thr); /* pop key */ + duk_pop(thr); /* pop key */ } DUK_INTERNAL void duk_xdef_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags) { @@ -17453,12 +18187,13 @@ } DUK_INTERNAL void duk_xdef_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) { - duk_xdef_prop_stridx(thr, (duk_idx_t) (duk_int8_t) (packed_args >> 24), - (duk_small_uint_t) (packed_args >> 8) & 0xffffUL, - (duk_small_uint_t) (packed_args & 0xffL)); + duk_xdef_prop_stridx(thr, + (duk_idx_t) (duk_int8_t) (packed_args >> 24), + (duk_small_uint_t) (packed_args >> 8) & 0xffffUL, + (duk_small_uint_t) (packed_args & 0xffL)); } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL void duk_xdef_prop_stridx_builtin(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags) { duk_hobject *obj; duk_hstring *key; @@ -17490,15 +18225,15 @@ duk_push_hstring_stridx(thr, stridx); duk_push_hobject_bidx(thr, DUK_BIDX_TYPE_ERROR_THROWER); duk_dup_top(thr); - duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE); /* attributes always 0 */ + duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE); /* attributes always 0 */ } /* Object.getOwnPropertyDescriptor() equivalent C binding. */ DUK_EXTERNAL void duk_get_prop_desc(duk_hthread *thr, duk_idx_t obj_idx, duk_uint_t flags) { DUK_ASSERT_API_ENTRY(thr); - DUK_UNREF(flags); /* no flags defined yet */ + DUK_UNREF(flags); /* no flags defined yet */ - duk_hobject_object_get_own_property_descriptor(thr, obj_idx); /* ... key -> ... desc */ + duk_hobject_object_get_own_property_descriptor(thr, obj_idx); /* ... key -> ... desc */ } /* Object.defineProperty() equivalent C binding. */ @@ -17528,9 +18263,7 @@ idx_base = duk_get_top_index(thr); if (flags & DUK_DEFPROP_HAVE_SETTER) { - duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC); + duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC); set = duk_get_hobject_promote_lfunc(thr, idx_base); if (set != NULL && !DUK_HOBJECT_IS_CALLABLE(set)) { goto fail_not_callable; @@ -17540,9 +18273,7 @@ set = NULL; } if (flags & DUK_DEFPROP_HAVE_GETTER) { - duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC); + duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC); get = duk_get_hobject_promote_lfunc(thr, idx_base); if (get != NULL && !DUK_HOBJECT_IS_CALLABLE(get)) { goto fail_not_callable; @@ -17562,14 +18293,7 @@ duk_require_valid_index(thr, idx_base); - duk_hobject_define_property_helper(thr, - flags /*defprop_flags*/, - obj, - key, - idx_value, - get, - set, - 1 /*throw_flag*/); + duk_hobject_define_property_helper(thr, flags /*defprop_flags*/, obj, key, idx_value, get, set, 1 /*throw_flag*/); /* Clean up stack */ @@ -17579,11 +18303,11 @@ return; - fail_invalid_desc: +fail_invalid_desc: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_DESCRIPTOR); DUK_WO_NORETURN(return;); - fail_not_callable: +fail_not_callable: DUK_ERROR_TYPE(thr, DUK_STR_NOT_CALLABLE); DUK_WO_NORETURN(return;); } @@ -17617,7 +18341,7 @@ duk_dup(thr, obj_idx); duk_require_hobject_promote_mask(thr, -1, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); - duk_hobject_enumerator_create(thr, enum_flags); /* target -> enum */ + duk_hobject_enumerator_create(thr, enum_flags); /* target -> enum */ } DUK_EXTERNAL duk_bool_t duk_next(duk_hthread *thr, duk_idx_t enum_index, duk_bool_t get_value) { @@ -17678,8 +18402,8 @@ } return; - fail_cannot_freeze: - DUK_ERROR_TYPE_INVALID_ARGS(thr); /* XXX: proper error message */ +fail_cannot_freeze: + DUK_ERROR_TYPE_INVALID_ARGS(thr); /* XXX: proper error message */ DUK_WO_NORETURN(return;); } @@ -17724,8 +18448,8 @@ if (ent != NULL) { while (ent->key != NULL) { tv = thr->valstack_top++; - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv)); /* value stack init policy */ - DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, ent->value); /* no need for decref/incref */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv)); /* value stack init policy */ + DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, ent->value); /* no need for decref/incref */ duk_put_prop_string(thr, obj_idx, ent->key); ent++; } @@ -17795,7 +18519,6 @@ return ret; } - DUK_EXTERNAL duk_bool_t duk_put_global_string(duk_hthread *thr, const char *key) { duk_bool_t ret; @@ -17806,7 +18529,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_string(thr, -2, key); /* ... global val -> ... global */ + ret = duk_put_prop_string(thr, -2, key); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -17821,7 +18544,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_lstring(thr, -2, key, key_len); /* ... global val -> ... global */ + ret = duk_put_prop_lstring(thr, -2, key, key_len); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -17838,7 +18561,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_literal_raw(thr, -2, key, key_len); /* ... global val -> ... global */ + ret = duk_put_prop_literal_raw(thr, -2, key, key_len); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -17854,7 +18577,7 @@ duk_push_hobject(thr, thr->builtinsDUK_BIDX_GLOBAL); duk_insert(thr, -2); - ret = duk_put_prop_heapptr(thr, -2, ptr); /* ... global val -> ... global */ + ret = duk_put_prop_heapptr(thr, -2, ptr); /* ... global val -> ... global */ duk_pop(thr); return ret; } @@ -17906,14 +18629,13 @@ obj = duk_require_hobject(thr, idx); DUK_ASSERT(obj != NULL); - duk_require_type_mask(thr, -1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_OBJECT); + duk_require_type_mask(thr, -1, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_OBJECT); proto = duk_get_hobject(thr, -1); /* proto can also be NULL here (allowed explicitly) */ #if defined(DUK_USE_ROM_OBJECTS) if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)) { - DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ + DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ DUK_WO_NORETURN(return;); } #endif @@ -17933,7 +18655,7 @@ #if defined(DUK_USE_ROM_OBJECTS) if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)) { - DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ + DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); /* XXX: "read only object"? */ DUK_WO_NORETURN(return;); } #endif @@ -17980,7 +18702,7 @@ DUK_ASSERT_API_ENTRY(thr); - h = duk_require_hobject(thr, idx); /* Get before 'put' so that 'idx' is correct. */ + h = duk_require_hobject(thr, idx); /* Get before 'put' so that 'idx' is correct. */ callable = duk_is_callable(thr, -1); /* At present finalizer is stored as a hidden Symbol, with normal @@ -18007,7 +18729,7 @@ DUK_HOBJECT_CLEAR_HAVE_FINALIZER(h); } } -#else /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ DUK_EXTERNAL void duk_get_finalizer(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx); @@ -18021,7 +18743,7 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #line 1 "duk_api_random.c" /* * Random numbers @@ -18030,7 +18752,7 @@ /* #include duk_internal.h -> already included */ DUK_EXTERNAL duk_double_t duk_random(duk_hthread *thr) { - return (duk_double_t) DUK_UTIL_GET_RANDOM_DOUBLE(thr); + return (duk_double_t) duk_util_get_random_double(thr); } #line 1 "duk_api_stack.c" /* @@ -18051,7 +18773,8 @@ * Forward declarations */ -DUK_LOCAL_DECL duk_idx_t duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx); +DUK_LOCAL_DECL duk_idx_t +duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx); /* * Global state for working around missing variadic macros @@ -18066,41 +18789,24 @@ * Misc helpers */ -DUK_LOCAL const char * const duk__symbol_type_strings4 = { - "hidden", "global", "local", "wellknown" -}; +DUK_LOCAL const char * const duk__symbol_type_strings4 = { "hidden", "global", "local", "wellknown" }; #if !defined(DUK_USE_PACKED_TVAL) DUK_LOCAL const duk_uint_t duk__type_from_tag = { - DUK_TYPE_NUMBER, - DUK_TYPE_NUMBER, /* fastint */ - DUK_TYPE_UNDEFINED, - DUK_TYPE_NULL, - DUK_TYPE_BOOLEAN, - DUK_TYPE_POINTER, - DUK_TYPE_LIGHTFUNC, - DUK_TYPE_NONE, - DUK_TYPE_STRING, - DUK_TYPE_OBJECT, - DUK_TYPE_BUFFER, + DUK_TYPE_NUMBER, DUK_TYPE_NUMBER, /* fastint */ + DUK_TYPE_UNDEFINED, DUK_TYPE_NULL, DUK_TYPE_BOOLEAN, DUK_TYPE_POINTER, DUK_TYPE_LIGHTFUNC, + DUK_TYPE_NONE, DUK_TYPE_STRING, DUK_TYPE_OBJECT, DUK_TYPE_BUFFER, }; DUK_LOCAL const duk_uint_t duk__type_mask_from_tag = { - DUK_TYPE_MASK_NUMBER, - DUK_TYPE_MASK_NUMBER, /* fastint */ - DUK_TYPE_MASK_UNDEFINED, - DUK_TYPE_MASK_NULL, - DUK_TYPE_MASK_BOOLEAN, - DUK_TYPE_MASK_POINTER, - DUK_TYPE_MASK_LIGHTFUNC, - DUK_TYPE_MASK_NONE, - DUK_TYPE_MASK_STRING, - DUK_TYPE_MASK_OBJECT, - DUK_TYPE_MASK_BUFFER, + DUK_TYPE_MASK_NUMBER, DUK_TYPE_MASK_NUMBER, /* fastint */ + DUK_TYPE_MASK_UNDEFINED, DUK_TYPE_MASK_NULL, DUK_TYPE_MASK_BOOLEAN, DUK_TYPE_MASK_POINTER, DUK_TYPE_MASK_LIGHTFUNC, + DUK_TYPE_MASK_NONE, DUK_TYPE_MASK_STRING, DUK_TYPE_MASK_OBJECT, DUK_TYPE_MASK_BUFFER, }; -#endif /* !DUK_USE_PACKED_TVAL */ +#endif /* !DUK_USE_PACKED_TVAL */ /* Assert that there's room for one value. */ -#define DUK__ASSERT_SPACE() do { \ +#define DUK__ASSERT_SPACE() \ + do { \ DUK_ASSERT(!(thr->valstack_top >= thr->valstack_end)); \ } while (0) @@ -18109,7 +18815,8 @@ /* Faster but value stack overruns are memory unsafe. */ #define DUK__CHECK_SPACE() DUK__ASSERT_SPACE() #else -#define DUK__CHECK_SPACE() do { \ +#define DUK__CHECK_SPACE() \ + do { \ if (DUK_UNLIKELY(thr->valstack_top >= thr->valstack_end)) { \ DUK_ERROR_RANGE_PUSH_BEYOND(thr); \ } \ @@ -18122,7 +18829,7 @@ DUK_ASSERT(h != NULL); DUK_ASSERT(DUK_HSTRING_HAS_SYMBOL(h)); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h) >= 1); /* always true, symbol prefix */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h) >= 1); /* always true, symbol prefix */ data = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h); len = DUK_HSTRING_GET_BYTELEN(h); @@ -18289,7 +18996,7 @@ /* Assume value stack sizes (in elements) fits into duk_idx_t. */ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -18317,7 +19024,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -18345,7 +19052,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ if (idx < 0) { uidx = vs_size + (duk_uidx_t) idx; @@ -18392,7 +19099,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom); - DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(vs_size >= 0); /* unsigned */ /* Use unsigned arithmetic to optimize comparison. */ if (idx < 0) { @@ -18531,7 +19238,7 @@ DUK_ASSERT(count > 0); tv = thr->valstack_top; tv_end = tv - count; - DUK_ASSERT(tv > tv_end); /* Because count > 0. */ + DUK_ASSERT(tv > tv_end); /* Because count > 0. */ do { tv--; DUK_ASSERT(tv >= thr->valstack_bottom); @@ -18539,7 +19246,7 @@ } while (tv != tv_end); thr->valstack_top = tv_end; DUK_REFZERO_CHECK_FAST(thr); -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ duk_uidx_t count; duk_tval *tv_end; @@ -18552,7 +19259,7 @@ DUK_TVAL_SET_UNDEFINED(tv); } while (tv != tv_end); thr->valstack_top = tv_end; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ } } @@ -18563,7 +19270,7 @@ duk_set_top(thr, idx); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_set_top_unsafe(duk_hthread *thr, duk_idx_t idx) { duk_uidx_t uidx; duk_uidx_t vs_size; @@ -18602,7 +19309,7 @@ DUK_ASSERT(count > 0); tv = thr->valstack_top; tv_end = tv - count; - DUK_ASSERT(tv > tv_end); /* Because count > 0. */ + DUK_ASSERT(tv > tv_end); /* Because count > 0. */ do { tv--; DUK_ASSERT(tv >= thr->valstack_bottom); @@ -18610,7 +19317,7 @@ } while (tv != tv_end); thr->valstack_top = tv_end; DUK_REFZERO_CHECK_FAST(thr); -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ duk_uidx_t count; duk_tval *tv_end; @@ -18623,10 +19330,10 @@ DUK_TVAL_SET_UNDEFINED(tv); } while (tv != tv_end); thr->valstack_top = tv_end; -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ } } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Internal helper: set top to 'top', and set idx_wipe_start,top to * 'undefined' (doing nothing if idx_wipe_start == top). Indices are @@ -18726,9 +19433,9 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); DUK_ASSERT(thr->valstack_end >= thr->valstack_top); DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end); - DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size); /* can't resize below 'top' */ - DUK_ASSERT(new_size <= DUK_USE_VALSTACK_LIMIT); /* valstack limit caller has check, prevents wrapping */ - DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval)); /* specific assert for wrapping */ + DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size); /* can't resize below 'top' */ + DUK_ASSERT(new_size <= DUK_USE_VALSTACK_LIMIT); /* valstack limit caller has check, prevents wrapping */ + DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval)); /* specific assert for wrapping */ /* Pre-realloc pointer copies for asserts and debug logs. */ pre_valstack = thr->valstack; @@ -18763,7 +19470,8 @@ */ DUK_ASSERT(new_size != 0); DUK_D(DUK_DPRINT("failed to resize valstack to %lu entries (%lu bytes)", - (unsigned long) new_size, (unsigned long) new_alloc_size)); + (unsigned long) new_size, + (unsigned long) new_alloc_size)); return 0; } @@ -18774,23 +19482,28 @@ #if defined(DUK_USE_DEBUG) if (thr->valstack != pre_valstack) { DUK_D(DUK_DPRINT("valstack base pointer changed during valstack resize: %p -> %p", - (void *) pre_valstack, (void *) thr->valstack)); + (void *) pre_valstack, + (void *) thr->valstack)); } if (thr->valstack_bottom != pre_bottom) { DUK_D(DUK_DPRINT("valstack bottom pointer changed during valstack resize: %p -> %p", - (void *) pre_bottom, (void *) thr->valstack_bottom)); + (void *) pre_bottom, + (void *) thr->valstack_bottom)); } if (thr->valstack_top != pre_top) { DUK_D(DUK_DPRINT("valstack top pointer changed during valstack resize: %p -> %p", - (void *) pre_top, (void *) thr->valstack_top)); + (void *) pre_top, + (void *) thr->valstack_top)); } if (thr->valstack_end != pre_end) { DUK_D(DUK_DPRINT("valstack end pointer changed during valstack resize: %p -> %p", - (void *) pre_end, (void *) thr->valstack_end)); + (void *) pre_end, + (void *) thr->valstack_end)); } if (thr->valstack_alloc_end != pre_alloc_end) { DUK_D(DUK_DPRINT("valstack alloc_end pointer changed during valstack resize: %p -> %p", - (void *) pre_alloc_end, (void *) thr->valstack_alloc_end)); + (void *) pre_alloc_end, + (void *) thr->valstack_alloc_end)); } #endif @@ -18829,12 +19542,22 @@ (unsigned long) new_size, (unsigned long) ((duk_uint8_t *) pre_alloc_end - (duk_uint8_t *) pre_valstack), (unsigned long) new_alloc_size, - (void *) pre_valstack, (void *) thr->valstack, - (void *) pre_bottom, (void *) thr->valstack_bottom, (long) (thr->valstack_bottom - thr->valstack), - (void *) pre_top, (void *) thr->valstack_top, (long) (thr->valstack_top - thr->valstack), - (void *) pre_end, (void *) thr->valstack_end, (long) (thr->valstack_end - thr->valstack), - (void *) pre_alloc_end, (void *) thr->valstack_alloc_end, (long) (thr->valstack_alloc_end - thr->valstack), - (void *) tv_prev_alloc_end, (long) (thr->valstack_alloc_end - tv_prev_alloc_end))); + (void *) pre_valstack, + (void *) thr->valstack, + (void *) pre_bottom, + (void *) thr->valstack_bottom, + (long) (thr->valstack_bottom - thr->valstack), + (void *) pre_top, + (void *) thr->valstack_top, + (long) (thr->valstack_top - thr->valstack), + (void *) pre_end, + (void *) thr->valstack_end, + (long) (thr->valstack_end - thr->valstack), + (void *) pre_alloc_end, + (void *) thr->valstack_alloc_end, + (long) (thr->valstack_alloc_end - thr->valstack), + (void *) tv_prev_alloc_end, + (long) (thr->valstack_alloc_end - tv_prev_alloc_end))); /* If allocation grew, init any new slots to 'undefined'. */ p = tv_prev_alloc_end; @@ -18861,7 +19584,7 @@ duk_size_t new_size; DUK_ASSERT(min_bytes / sizeof(duk_tval) * sizeof(duk_tval) == min_bytes); - min_size = min_bytes / sizeof(duk_tval); /* from bytes to slots */ + min_size = min_bytes / sizeof(duk_tval); /* from bytes to slots */ #if defined(DUK_USE_VALSTACK_GROW_SHIFT) /* New size is minimum size plus a proportional slack, e.g. shift of @@ -18978,17 +19701,18 @@ #else slack = 0; #endif - shrink_bytes = reserve_bytes + - slack / sizeof(duk_tval) * sizeof(duk_tval); /* multiple of duk_tval */ + shrink_bytes = reserve_bytes + slack / sizeof(duk_tval) * sizeof(duk_tval); /* multiple of duk_tval */ } -#else /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ +#else /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ /* Always snug, useful in some low memory environments. */ DUK_UNREF(snug); shrink_bytes = reserve_bytes; -#endif /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ +#endif /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */ DUK_D(DUK_DPRINT("valstack shrink check: alloc_bytes=%ld, reserve_bytes=%ld, shrink_bytes=%ld (unvalidated)", - (long) alloc_bytes, (long) reserve_bytes, (long) shrink_bytes)); + (long) alloc_bytes, + (long) reserve_bytes, + (long) shrink_bytes)); DUK_ASSERT(shrink_bytes >= reserve_bytes); if (shrink_bytes >= alloc_bytes) { /* Skip if shrink target is same as current one (or higher, @@ -19135,7 +19859,7 @@ DUK_ASSERT(tv_from != NULL); DUK_ASSERT(tv_to != NULL); DUK_TVAL_SET_TVAL(tv_to, tv_from); - DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ + DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ } DUK_EXTERNAL void duk_dup_top(duk_hthread *thr) { @@ -19157,7 +19881,7 @@ DUK_ASSERT(tv_from != NULL); DUK_ASSERT(tv_to != NULL); DUK_TVAL_SET_TVAL(tv_to, tv_from); - DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ + DUK_TVAL_INCREF(thr, tv_to); /* no side effects */ #endif } @@ -19210,7 +19934,10 @@ nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); DUK_DDD(DUK_DDDPRINT("duk_insert: to_idx=%ld, p=%p, q=%p, nbytes=%lu", - (long) to_idx, (void *) p, (void *) q, (unsigned long) nbytes)); + (long) to_idx, + (void *) p, + (void *) q, + (unsigned long) nbytes)); /* No net refcount changes. No need to special case nbytes == 0 * (p == q). @@ -19222,7 +19949,7 @@ DUK_INTERNAL void duk_insert_undefined(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(idx >= 0); /* Doesn't support negative indices. */ + DUK_ASSERT(idx >= 0); /* Doesn't support negative indices. */ duk_push_undefined(thr); duk_insert(thr, idx); @@ -19232,7 +19959,7 @@ duk_tval *tv, *tv_end; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(idx >= 0); /* Doesn't support negative indices or count. */ + DUK_ASSERT(idx >= 0); /* Doesn't support negative indices or count. */ DUK_ASSERT(count >= 0); tv = duk_reserve_gap(thr, idx, count); @@ -19267,7 +19994,10 @@ nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); DUK_DDD(DUK_DDDPRINT("duk_pull: from_idx=%ld, p=%p, q=%p, nbytes=%lu", - (long) from_idx, (void *) p, (void *) q, (unsigned long) nbytes)); + (long) from_idx, + (void *) p, + (void *) q, + (unsigned long) nbytes)); /* No net refcount changes. No need to special case nbytes == 0 * (p == q). @@ -19296,7 +20026,7 @@ DUK_TVAL_SET_TVAL(tv2, tv1); DUK_TVAL_SET_UNDEFINED(tv1); thr->valstack_top--; - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ } DUK_EXTERNAL void duk_copy(duk_hthread *thr, duk_idx_t from_idx, duk_idx_t to_idx) { @@ -19311,7 +20041,7 @@ DUK_ASSERT(tv2 != NULL); /* For tv1 == tv2, this is a no-op (no explicit check needed). */ - DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */ } DUK_EXTERNAL void duk_remove(duk_hthread *thr, duk_idx_t idx) { @@ -19342,21 +20072,21 @@ DUK_TVAL_SET_TVAL(&tv_tmp, p); #endif - nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */ + nbytes = (duk_size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */ duk_memmove((void *) p, (const void *) (p + 1), (size_t) nbytes); DUK_TVAL_SET_UNDEFINED(q); thr->valstack_top--; #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ #endif } DUK_INTERNAL void duk_remove_unsafe(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - duk_remove(thr, idx); /* XXX: no optimization for now */ + duk_remove(thr, idx); /* XXX: no optimization for now */ } DUK_INTERNAL void duk_remove_m2(duk_hthread *thr) { @@ -19375,7 +20105,7 @@ while (count-- > 0) { duk_remove(thr, idx); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ duk_tval *tv_src; duk_tval *tv_dst; duk_tval *tv_newtop; @@ -19407,13 +20137,13 @@ /* When not preferring size, only NORZ macros are used; caller * is expected to DUK_REFZERO_CHECK(). */ -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } DUK_INTERNAL void duk_remove_n_unsafe(duk_hthread *thr, duk_idx_t idx, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); - duk_remove_n(thr, idx, count); /* XXX: no optimization for now */ + duk_remove_n(thr, idx, count); /* XXX: no optimization for now */ } /* @@ -19474,7 +20204,7 @@ /* Incref copies, keep originals. */ q = to_thr->valstack_top; while (p < q) { - DUK_TVAL_INCREF(to_thr, p); /* no side effects */ + DUK_TVAL_INCREF(to_thr, p); /* no side effects */ p++; } } else { @@ -19574,7 +20304,7 @@ DUK_EXTERNAL duk_bool_t duk_get_boolean(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__get_boolean_raw(thr, idx, 0); /* default: false */ + return duk__get_boolean_raw(thr, idx, 0); /* default: false */ } DUK_EXTERNAL duk_bool_t duk_get_boolean_default(duk_hthread *thr, duk_idx_t idx, duk_bool_t def_value) { @@ -19620,11 +20350,10 @@ DUK_ASSERT(tv != NULL); #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv)) { - ret.d = (duk_double_t) DUK_TVAL_GET_FASTINT(tv); /* XXX: cast trick */ - } - else + ret.d = (duk_double_t) DUK_TVAL_GET_FASTINT(tv); /* XXX: cast trick */ + } else #endif - if (DUK_TVAL_IS_DOUBLE(tv)) { + if (DUK_TVAL_IS_DOUBLE(tv)) { /* When using packed duk_tval, number must be in NaN-normalized form * for it to be a duk_tval, so no need to normalize. NOP for unpacked * duk_tval. @@ -19641,7 +20370,7 @@ DUK_EXTERNAL duk_double_t duk_get_number(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__get_number_raw(thr, idx, DUK_DOUBLE_NAN); /* default: NaN */ + return duk__get_number_raw(thr, idx, DUK_DOUBLE_NAN); /* default: NaN */ } DUK_EXTERNAL duk_double_t duk_get_number_default(duk_hthread *thr, duk_idx_t idx, duk_double_t def_value) { @@ -19797,7 +20526,11 @@ } } -DUK_EXTERNAL const char *duk_opt_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL const char *duk_opt_lstring(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_len, + const char *def_ptr, + duk_size_t def_len) { DUK_ASSERT_API_ENTRY(thr); if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) { @@ -19818,7 +20551,11 @@ return duk_require_string(thr, idx); } -DUK_EXTERNAL const char *duk_get_lstring_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL const char *duk_get_lstring_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_len, + const char *def_ptr, + duk_size_t def_len) { duk_hstring *h; const char *ret; duk_size_t len; @@ -19907,7 +20644,7 @@ return def_value; } - p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ + p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ return p; } @@ -19945,11 +20682,11 @@ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "pointer", DUK_STR_NOT_POINTER); DUK_WO_NORETURN(return NULL;); } - p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ + p = DUK_TVAL_GET_POINTER(tv); /* may be NULL */ return p; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL void *duk_get_voidptr(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; duk_heaphdr *h; @@ -19968,7 +20705,12 @@ } #endif -DUK_LOCAL void *duk__get_buffer_helper(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag) { +DUK_LOCAL void *duk__get_buffer_helper(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size, + duk_bool_t throw_flag) { duk_hbuffer *h; void *ret; duk_size_t len; @@ -20021,7 +20763,11 @@ return duk_require_buffer(thr, idx, out_size); } -DUK_EXTERNAL void *duk_get_buffer_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len) { +DUK_EXTERNAL void *duk_get_buffer_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_len) { DUK_ASSERT_API_ENTRY(thr); return duk__get_buffer_helper(thr, idx, out_size, def_ptr, def_len, 0 /*throw_flag*/); @@ -20038,7 +20784,13 @@ * have a NULL data pointer when its size is zero, the optional 'out_isbuffer' * argument allows caller to detect this reliably. */ -DUK_INTERNAL void *duk_get_buffer_data_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag, duk_bool_t *out_isbuffer) { +DUK_INTERNAL void *duk_get_buffer_data_raw(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size, + duk_bool_t throw_flag, + duk_bool_t *out_isbuffer) { duk_tval *tv; DUK_ASSERT_API_ENTRY(thr); @@ -20062,7 +20814,7 @@ if (out_isbuffer != NULL) { *out_isbuffer = 1; } - return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */ + return (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); /* may be NULL (but only if size is 0) */ } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) else if (DUK_TVAL_IS_OBJECT(tv)) { @@ -20075,8 +20827,7 @@ duk_hbufobj *h_bufobj = (duk_hbufobj *) h; DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); - if (h_bufobj->buf != NULL && - DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { + if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { duk_uint8_t *p; p = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf); @@ -20091,7 +20842,7 @@ /* if slice not fully valid, treat as error */ } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ if (throw_flag) { DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "buffer", DUK_STR_NOT_BUFFER); @@ -20105,7 +20856,11 @@ return duk_get_buffer_data_raw(thr, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, NULL); } -DUK_EXTERNAL void *duk_get_buffer_data_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size) { +DUK_EXTERNAL void *duk_get_buffer_data_default(duk_hthread *thr, + duk_idx_t idx, + duk_size_t *out_size, + void *def_ptr, + duk_size_t def_size) { DUK_ASSERT_API_ENTRY(thr); return duk_get_buffer_data_raw(thr, idx, out_size, def_ptr, def_size, 0 /*throw_flag*/, NULL); } @@ -20145,9 +20900,8 @@ } ret = DUK_TVAL_GET_HEAPHDR(tv); - DUK_ASSERT(ret != NULL); /* tagged null pointers should never occur */ + DUK_ASSERT(ret != NULL); /* tagged null pointers should never occur */ return ret; - } DUK_INTERNAL duk_hstring *duk_get_hstring(duk_hthread *thr, duk_idx_t idx) { @@ -20482,7 +21236,7 @@ DUK_CTX_ASSERT_VALID(thr); - res = duk_get_hobject(thr, idx); /* common case, not promoted */ + res = duk_get_hobject(thr, idx); /* common case, not promoted */ if (DUK_LIKELY(res != NULL)) { DUK_ASSERT(res != NULL); return res; @@ -20495,7 +21249,7 @@ DUK_ASSERT(res != NULL); return res; } else { - return NULL; /* accept without promoting */ + return NULL; /* accept without promoting */ } } @@ -20538,7 +21292,7 @@ duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX); h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT); @@ -20552,7 +21306,7 @@ duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */ DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX); h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT); @@ -20598,7 +21352,7 @@ duk_pop_unsafe(thr); return ret; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ case DUK_TAG_STRING: { duk_hstring *h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); @@ -20624,7 +21378,7 @@ duk_pop_unsafe(thr); return ret; } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ case DUK_TAG_OBJECT: { duk_hobject *h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); @@ -20721,8 +21475,8 @@ if (duk_get_prop_stridx(thr, idx, func_stridx)) { /* ... func */ if (duk_is_callable(thr, -1)) { - duk_dup(thr, idx); /* -> ... func this */ - duk_call_method(thr, 0); /* -> ... retval */ + duk_dup(thr, idx); /* -> ... func this */ + duk_call_method(thr, 0); /* -> ... retval */ if (duk_is_primitive(thr, -1)) { duk_replace(thr, idx); return 1; @@ -20730,7 +21484,7 @@ /* ... retval ; popped below */ } } - duk_pop_unsafe(thr); /* ... func/retval -> ... */ + duk_pop_unsafe(thr); /* ... func/retval -> ... */ return 0; } @@ -20741,7 +21495,7 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ } DUK_EXTERNAL void duk_to_null(duk_hthread *thr, duk_idx_t idx) { @@ -20751,13 +21505,11 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */ } /* E5 Section 9.1 */ -DUK_LOCAL const char * const duk__toprim_hint_strings3 = { - "default", "string", "number" -}; +DUK_LOCAL const char * const duk__toprim_hint_strings3 = { "default", "string", "number" }; DUK_LOCAL void duk__to_primitive_helper(duk_hthread *thr, duk_idx_t idx, duk_int_t hint, duk_bool_t check_symbol) { /* Inline initializer for coercers is not allowed by old compilers like BCC. */ duk_small_uint_t coercers2; @@ -20768,10 +21520,8 @@ idx = duk_require_normalize_index(thr, idx); /* If already primitive, return as is. */ - if (!duk_check_type_mask(thr, idx, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + if (!duk_check_type_mask(thr, idx, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } @@ -20782,10 +21532,8 @@ DUK_ASSERT(hint >= 0 && (duk_size_t) hint < sizeof(duk__toprim_hint_strings) / sizeof(const char *)); duk_dup(thr, idx); duk_push_string(thr, duk__toprim_hint_stringshint); - duk_call_method(thr, 1); /* ... method value hint -> ... res */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { + duk_call_method(thr, 1); /* ... method value hint -> ... res */ + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { goto fail; } duk_replace(thr, idx); @@ -20807,7 +21555,7 @@ if (hint == DUK_HINT_NONE) { hint = DUK_HINT_NUMBER; } -#else /* DUK_USE_SYMBOL_BUILTIN */ +#else /* DUK_USE_SYMBOL_BUILTIN */ if (hint == DUK_HINT_NONE) { duk_small_uint_t class_number; @@ -20818,7 +21566,7 @@ hint = DUK_HINT_NUMBER; } } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ coercers0 = DUK_STRIDX_VALUE_OF; coercers1 = DUK_STRIDX_TO_STRING; @@ -20828,16 +21576,16 @@ } if (duk__defaultvalue_coerce_attempt(thr, idx, coercers0)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } if (duk__defaultvalue_coerce_attempt(thr, idx, coercers1)) { - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */ return; } - fail: +fail: DUK_ERROR_TYPE(thr, DUK_STR_TOPRIMITIVE_FAILED); DUK_WO_NORETURN(return;); } @@ -20868,7 +21616,7 @@ /* Note: no need to re-lookup tv, conversion is side effect free. */ DUK_ASSERT(tv != NULL); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, val); /* side effects */ return val; } @@ -20900,11 +21648,11 @@ idx = duk_require_normalize_index(thr, idx); tv = DUK_GET_TVAL_POSIDX(thr, idx); DUK_ASSERT(tv != NULL); - d = duk_js_tonumber(thr, tv); /* XXX: fastint coercion? now result will always be a non-fastint */ + d = duk_js_tonumber(thr, tv); /* XXX: fastint coercion? now result will always be a non-fastint */ /* ToNumber() may have side effects so must relookup 'tv'. */ tv = DUK_GET_TVAL_POSIDX(thr, idx); - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ return d; } @@ -20936,13 +21684,13 @@ tv_dst = thr->valstack_top++; DUK_TVAL_SET_TVAL(tv_dst, tv); - DUK_TVAL_INCREF(thr, tv_dst); /* decref not necessary */ - res = duk_to_number_m1(thr); /* invalidates tv_dst */ + DUK_TVAL_INCREF(thr, tv_dst); /* decref not necessary */ + res = duk_to_number_m1(thr); /* invalidates tv_dst */ tv_dst = --thr->valstack_top; DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_dst)); - DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_dst)); /* plain number */ - DUK_TVAL_SET_UNDEFINED(tv_dst); /* valstack init policy */ + DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_dst)); /* plain number */ + DUK_TVAL_SET_UNDEFINED(tv_dst); /* valstack init policy */ return res; #endif @@ -20978,7 +21726,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */ return d; } @@ -21012,7 +21760,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_I32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -21028,7 +21776,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -21044,7 +21792,7 @@ /* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */ tv = duk_require_tval(thr, idx); - DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */ return ret; } @@ -21076,16 +21824,16 @@ if (duk_double_equals(t, 0.5)) { /* Exact halfway, round to even. */ ret = (duk_uint8_t) d; - ret = (ret + 1) & 0xfe; /* Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4 - * Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4 - */ + ret = (ret + 1) & 0xfe; /* Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4 + * Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4 + */ } else { /* Not halfway, round to nearest. */ ret = (duk_uint8_t) (d + 0.5); } return ret; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL const char *duk_to_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) { DUK_ASSERT_API_ENTRY(thr); @@ -21195,7 +21943,7 @@ DUK_ASSERT_API_ENTRY(thr); - duk_to_primitive(thr, idx, DUK_HINT_STRING); /* needed for e.g. Symbol objects */ + duk_to_primitive(thr, idx, DUK_HINT_STRING); /* needed for e.g. Symbol objects */ h = duk_get_hstring(thr, idx); if (h == NULL) { /* The "is string?" check may seem unnecessary, but as things @@ -21209,7 +21957,7 @@ return h; } -#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ +#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */ DUK_INTERNAL duk_hstring *duk_safe_to_hstring(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); @@ -21251,10 +21999,10 @@ * Object.prototype.toString() is usually not performance critical. */ - duk_push_literal(thr, "object "); /* -> ... "object" */ + duk_push_literal(thr, "object "); /* -> ... "object" */ switch (DUK_TVAL_GET_TAG(tv)) { - case DUK_TAG_UNUSED: /* Treat like 'undefined', shouldn't happen. */ + case DUK_TAG_UNUSED: /* Treat like 'undefined', shouldn't happen. */ case DUK_TAG_UNDEFINED: { duk_push_hstring_stridx(thr, DUK_STRIDX_UC_UNDEFINED); goto finish; @@ -21266,7 +22014,7 @@ } duk_push_tval(thr, tv); - tv = NULL; /* Invalidated by ToObject(). */ + tv = NULL; /* Invalidated by ToObject(). */ h_obj = duk_to_hobject(thr, -1); DUK_ASSERT(h_obj != NULL); if (duk_js_isarray_hobject(h_obj)) { @@ -21297,14 +22045,15 @@ duk_pop_unsafe(thr); duk_push_hstring_stridx(thr, stridx); - finish: +finish: /* ... "object" tag */ duk_push_literal(thr, ""); - duk_concat(thr, 3); /* ... "object" tag "" -> ... res */ + duk_concat(thr, 3); /* ... "object" tag "" -> ... res */ } /* XXX: other variants like uint, u32 etc */ -DUK_INTERNAL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) { +DUK_INTERNAL duk_int_t +duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) { duk_tval *tv; duk_tval tv_tmp; duk_double_t d, dmin, dmax; @@ -21315,7 +22064,7 @@ tv = duk_require_tval(thr, idx); DUK_ASSERT(tv != NULL); - d = duk_js_tointeger(thr, tv); /* E5 Section 9.4, ToInteger() */ + d = duk_js_tointeger(thr, tv); /* E5 Section 9.4, ToInteger() */ dmin = (duk_double_t) minval; dmax = (duk_double_t) maxval; @@ -21331,12 +22080,12 @@ } else { res = (duk_int_t) d; } - DUK_UNREF(d); /* SCANBUILD: with suitable dmin/dmax limits 'd' is unused */ + DUK_UNREF(d); /* SCANBUILD: with suitable dmin/dmax limits 'd' is unused */ /* 'd' and 'res' agree here */ /* Relookup in case duk_js_tointeger() ends up e.g. coercing an object. */ tv = duk_get_tval(thr, idx); - DUK_ASSERT(tv != NULL); /* not popped by side effect */ + DUK_ASSERT(tv != NULL); /* not popped by side effect */ DUK_TVAL_SET_TVAL(&tv_tmp, tv); #if defined(DUK_USE_FASTINT) #if (DUK_INT_MAX <= 0x7fffffffL) @@ -21350,9 +22099,9 @@ } #endif #else - DUK_TVAL_SET_NUMBER(tv, d); /* no need to incref */ + DUK_TVAL_SET_NUMBER(tv, d); /* no need to incref */ #endif - DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ + DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */ if (out_clamped) { *out_clamped = clamped; @@ -21377,7 +22126,7 @@ DUK_INTERNAL duk_int_t duk_to_int_check_range(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval) { DUK_ASSERT_API_ENTRY(thr); - return duk_to_int_clamped_raw(thr, idx, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */ + return duk_to_int_clamped_raw(thr, idx, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */ } DUK_EXTERNAL const char *duk_to_string(duk_hthread *thr, duk_idx_t idx) { @@ -21436,9 +22185,9 @@ * value, and duk_to_string() then causes a TypeError. */ duk_to_primitive(thr, idx, DUK_HINT_STRING); - DUK_ASSERT(!duk_is_buffer(thr, idx)); /* ToPrimitive() must guarantee */ + DUK_ASSERT(!duk_is_buffer(thr, idx)); /* ToPrimitive() must guarantee */ DUK_ASSERT(!duk_is_object(thr, idx)); - return duk_to_string(thr, idx); /* Note: recursive call */ + return duk_to_string(thr, idx); /* Note: recursive call */ } case DUK_TAG_POINTER: { void *ptr = DUK_TVAL_GET_POINTER(tv); @@ -21466,17 +22215,14 @@ DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv)); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); duk_push_tval(thr, tv); - duk_numconv_stringify(thr, - 10 /*radix*/, - 0 /*precision:shortest*/, - 0 /*force_exponential*/); + duk_numconv_stringify(thr, 10 /*radix*/, 0 /*precision:shortest*/, 0 /*force_exponential*/); break; } } duk_replace(thr, idx); - skip_replace: +skip_replace: DUK_ASSERT(duk_is_string(thr, idx)); return duk_require_string(thr, idx); } @@ -21558,8 +22304,7 @@ src_size = DUK_HBUFFER_GET_SIZE(h_buf); tmp = (DUK_HBUFFER_HAS_DYNAMIC(h_buf) ? DUK_BUF_MODE_DYNAMIC : DUK_BUF_MODE_FIXED); - if ((tmp == mode && !DUK_HBUFFER_HAS_EXTERNAL(h_buf)) || - mode == DUK_BUF_MODE_DONTCARE) { + if ((tmp == mode && !DUK_HBUFFER_HAS_EXTERNAL(h_buf)) || mode == DUK_BUF_MODE_DONTCARE) { /* Note: src_data may be NULL if input is a zero-size * dynamic buffer. */ @@ -21580,7 +22325,7 @@ duk_memcpy_unsafe((void *) dst_data, (const void *) src_data, (size_t) src_size); duk_replace(thr, idx); - skip_copy: +skip_copy: if (out_size) { *out_size = src_size; @@ -21640,7 +22385,7 @@ DUK_LOCAL void duk__push_func_from_lightfunc(duk_hthread *thr, duk_c_function func, duk_small_uint_t lf_flags) { duk_idx_t nargs; - duk_uint_t flags = 0; /* shared flags for a subset of types */ + duk_uint_t flags = 0; /* shared flags for a subset of types */ duk_small_uint_t lf_len; duk_hnatfunc *nf; @@ -21649,15 +22394,9 @@ nargs = (duk_idx_t) DUK_VARARGS; } - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_NATIVE_FUNCTION_PROTOTYPE); lf_len = DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags); @@ -21678,7 +22417,7 @@ DUK_EXTERNAL void duk_to_object(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; - duk_uint_t flags = 0; /* shared flags for a subset of types */ + duk_uint_t flags = 0; /* shared flags for a subset of types */ duk_small_int_t proto = 0; DUK_ASSERT_API_ENTRY(thr); @@ -21689,7 +22428,7 @@ switch (DUK_TVAL_GET_TAG(tv)) { #if !defined(DUK_USE_BUFFEROBJECT_SUPPORT) - case DUK_TAG_BUFFER: /* With no bufferobject support, don't object coerce. */ + case DUK_TAG_BUFFER: /* With no bufferobject support, don't object coerce. */ #endif case DUK_TAG_UNDEFINED: case DUK_TAG_NULL: { @@ -21698,9 +22437,8 @@ break; } case DUK_TAG_BOOLEAN: { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BOOLEAN); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_BOOLEAN); proto = DUK_BIDX_BOOLEAN_PROTOTYPE; goto create_object; } @@ -21709,14 +22447,11 @@ h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); if (DUK_UNLIKELY(DUK_HSTRING_HAS_SYMBOL(h))) { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_SYMBOL); proto = DUK_BIDX_SYMBOL_PROTOTYPE; } else { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_STRING); proto = DUK_BIDX_STRING_PROTOTYPE; } @@ -21742,11 +22477,10 @@ duk_hbufobj_push_uint8array_from_plain(thr, h_buf); goto replace_value; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ case DUK_TAG_POINTER: { - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER); proto = DUK_BIDX_POINTER_PROTOTYPE; goto create_object; } @@ -21773,9 +22507,8 @@ default: { DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv)); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_NUMBER); + flags = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_NUMBER); proto = DUK_BIDX_NUMBER_PROTOTYPE; goto create_object; } @@ -21783,7 +22516,7 @@ DUK_ASSERT(duk_is_object(thr, idx)); return; - create_object: +create_object: (void) duk_push_object_helper(thr, flags, proto); /* Note: Boolean prototype's internal value property is not writable, @@ -21796,7 +22529,7 @@ duk_dup(thr, idx); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); - replace_value: +replace_value: duk_replace(thr, idx); DUK_ASSERT(duk_is_object(thr, idx)); } @@ -21867,11 +22600,11 @@ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); return DUK_TYPE_NUMBER; } -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ DUK_ASSERT(DUK_TVAL_IS_VALID_TAG(tv)); DUK_ASSERT(sizeof(duk__type_from_tag) / sizeof(duk_uint_t) == DUK_TAG_MAX - DUK_TAG_MIN + 1); return (duk_int_t) duk__type_from_tagDUK_TVAL_GET_TAG(tv) - DUK_TAG_MIN; -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ } DUK_EXTERNAL duk_int_t duk_get_type(duk_hthread *thr, duk_idx_t idx) { @@ -21886,18 +22619,8 @@ } #if defined(DUK_USE_VERBOSE_ERRORS) && defined(DUK_USE_PARANOID_ERRORS) -DUK_LOCAL const char * const duk__type_names = { - "none", - "undefined", - "null", - "boolean", - "number", - "string", - "object", - "buffer", - "pointer", - "lightfunc" -}; +DUK_LOCAL const char * const duk__type_names = { "none", "undefined", "null", "boolean", "number", + "string", "object", "buffer", "pointer", "lightfunc" }; DUK_INTERNAL const char *duk_get_type_name(duk_hthread *thr, duk_idx_t idx) { duk_int_t type_tag; @@ -21910,7 +22633,7 @@ return duk__type_namestype_tag; } -#endif /* DUK_USE_VERBOSE_ERRORS && DUK_USE_PARANOID_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS && DUK_USE_PARANOID_ERRORS */ DUK_INTERNAL duk_small_uint_t duk_get_class_number(duk_hthread *thr, duk_idx_t idx) { duk_tval *tv; @@ -21976,11 +22699,11 @@ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); return DUK_TYPE_MASK_NUMBER; } -#else /* DUK_USE_PACKED_TVAL */ +#else /* DUK_USE_PACKED_TVAL */ DUK_ASSERT(DUK_TVAL_IS_VALID_TAG(tv)); DUK_ASSERT(sizeof(duk__type_mask_from_tag) / sizeof(duk_uint_t) == DUK_TAG_MAX - DUK_TAG_MIN + 1); return duk__type_mask_from_tagDUK_TVAL_GET_TAG(tv) - DUK_TAG_MIN; -#endif /* DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_PACKED_TVAL */ } DUK_EXTERNAL duk_uint_t duk_get_type_mask(duk_hthread *thr, duk_idx_t idx) { @@ -22099,14 +22822,14 @@ } return 0; } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); return duk_is_buffer(thr, idx); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_EXTERNAL duk_bool_t duk_is_pointer(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); @@ -22200,23 +22923,17 @@ DUK_EXTERNAL duk_bool_t duk_is_c_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_NATFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_NATFUNC); } DUK_EXTERNAL duk_bool_t duk_is_ecmascript_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_COMPFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_COMPFUNC); } DUK_EXTERNAL duk_bool_t duk_is_bound_function(duk_hthread *thr, duk_idx_t idx) { DUK_ASSERT_API_ENTRY(thr); - return duk__obj_flag_any_default_false(thr, - idx, - DUK_HOBJECT_FLAG_BOUNDFUNC); + return duk__obj_flag_any_default_false(thr, idx, DUK_HOBJECT_FLAG_BOUNDFUNC); } DUK_EXTERNAL duk_bool_t duk_is_thread(duk_hthread *thr, duk_idx_t idx) { @@ -22333,7 +23050,7 @@ DUK__CHECK_SPACE(); tv_slot = thr->valstack_top++; DUK_TVAL_SET_TVAL(tv_slot, tv); - DUK_TVAL_INCREF(thr, tv); /* no side effects */ + DUK_TVAL_INCREF(thr, tv); /* no side effects */ } DUK_EXTERNAL void duk_push_undefined(duk_hthread *thr) { @@ -22363,7 +23080,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK__CHECK_SPACE(); - b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */ + b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */ tv_slot = thr->valstack_top++; DUK_TVAL_SET_BOOLEAN(tv_slot, b); } @@ -22416,7 +23133,7 @@ DUK_TVAL_SET_NUMBER(tv_slot, d); } #endif -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ duk_tval *tv_slot; duk_double_t d; @@ -22425,7 +23142,7 @@ d = (duk_double_t) val; tv_slot = thr->valstack_top++; DUK_TVAL_SET_NUMBER(tv_slot, d); -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ } DUK_EXTERNAL void duk_push_uint(duk_hthread *thr, duk_uint_t val) { @@ -22438,7 +23155,7 @@ #if DUK_UINT_MAX <= 0xffffffffUL DUK_TVAL_SET_U32(tv_slot, (duk_uint32_t) val); #else - if (val <= DUK_FASTINT_MAX) { /* val is unsigned so >= 0 */ + if (val <= DUK_FASTINT_MAX) { /* val is unsigned so >= 0 */ /* XXX: take advantage of val being unsigned, no need to mask */ DUK_TVAL_SET_FASTINT(tv_slot, (duk_int64_t) val); } else { @@ -22446,7 +23163,7 @@ DUK_TVAL_SET_NUMBER(tv_slot, d); } #endif -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ duk_tval *tv_slot; duk_double_t d; @@ -22455,7 +23172,7 @@ d = (duk_double_t) val; tv_slot = thr->valstack_top++; DUK_TVAL_SET_NUMBER(tv_slot, d); -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ } DUK_EXTERNAL void duk_push_nan(duk_hthread *thr) { @@ -22499,7 +23216,7 @@ tv_slot = thr->valstack_top++; DUK_TVAL_SET_STRING(tv_slot, h); - DUK_HSTRING_INCREF(thr, h); /* no side effects */ + DUK_HSTRING_INCREF(thr, h); /* no side effects */ return (const char *) DUK_HSTRING_GET_DATA(h); } @@ -22536,11 +23253,11 @@ tv_slot = thr->valstack_top++; DUK_TVAL_SET_STRING(tv_slot, h); - DUK_HSTRING_INCREF(thr, h); /* no side effects */ + DUK_HSTRING_INCREF(thr, h); /* no side effects */ return (const char *) DUK_HSTRING_GET_DATA(h); } -#else /* DUK_USE_LITCACHE_SIZE */ +#else /* DUK_USE_LITCACHE_SIZE */ DUK_EXTERNAL const char *duk_push_literal_raw(duk_hthread *thr, const char *str, duk_size_t len) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(str != NULL); @@ -22548,8 +23265,8 @@ return duk_push_lstring(thr, str, len); } -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_push_pointer(duk_hthread *thr, void *val) { duk_tval *tv_slot; @@ -22577,7 +23294,7 @@ DUK__CHECK_SPACE(); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */ tv_slot = thr->valstack_top++; if (DUK_UNLIKELY(thr->callstack_curr == NULL)) { @@ -22591,8 +23308,7 @@ /* 'this' binding is just before current activation's bottom */ DUK_ASSERT(thr->valstack_bottom > thr->valstack); tv = thr->valstack_bottom - 1; - if (check_object_coercible && - (DUK_TVAL_IS_UNDEFINED(tv) || DUK_TVAL_IS_NULL(tv))) { + if (check_object_coercible && (DUK_TVAL_IS_UNDEFINED(tv) || DUK_TVAL_IS_NULL(tv))) { /* XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv) */ goto type_error; } @@ -22602,7 +23318,7 @@ } return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_NOT_OBJECT_COERCIBLE); DUK_WO_NORETURN(return;); } @@ -22634,16 +23350,16 @@ DUK_ASSERT_API_ENTRY(thr); duk__push_this_helper(thr, 1 /*check_object_coercible*/); - return duk_to_hstring_m1(thr); /* This will reject all Symbol values; accepts Symbol objects. */ + return duk_to_hstring_m1(thr); /* This will reject all Symbol values; accepts Symbol objects. */ } DUK_INTERNAL duk_tval *duk_get_borrowed_this_tval(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */ - DUK_ASSERT(thr->callstack_curr != NULL); /* caller required to know */ - DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */ - DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */ + DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */ + DUK_ASSERT(thr->callstack_curr != NULL); /* caller required to know */ + DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */ + DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */ return thr->valstack_bottom - 1; } @@ -22724,7 +23440,10 @@ duk_pop_unsafe(thr); duk_push_bare_object(thr); duk_dup_top(thr); - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_C); /* ... parent stash stash -> ... parent stash */ + duk_xdef_prop_stridx_short(thr, + -3, + DUK_STRIDX_INT_VALUE, + DUK_PROPDESC_FLAGS_C); /* ... parent stash stash -> ... parent stash */ } duk_remove_m2(thr); } @@ -22777,7 +23496,7 @@ duk_size_t sz = DUK_PUSH_SPRINTF_INITIAL_SIZE; duk_bool_t pushed_buf = 0; void *buf; - duk_int_t len; /* XXX: duk_ssize_t */ + duk_int_t len; /* XXX: duk_ssize_t */ const char *res; DUK_ASSERT_API_ENTRY(thr); @@ -22791,7 +23510,7 @@ } /* initial estimate based on format string */ - sz = DUK_STRLEN(fmt) + 16; /* format plus something to avoid just missing */ + sz = DUK_STRLEN(fmt) + 16; /* format plus something to avoid just missing */ if (sz < DUK_PUSH_SPRINTF_INITIAL_SIZE) { sz = DUK_PUSH_SPRINTF_INITIAL_SIZE; } @@ -22801,7 +23520,7 @@ * This works 99% of the time which is quite nice. */ for (;;) { - va_list ap_copy; /* copied so that 'ap' can be reused */ + va_list ap_copy; /* copied so that 'ap' can be reused */ if (sz <= sizeof(stack_buf)) { buf = stack_buf; @@ -22831,7 +23550,7 @@ /* Cannot use duk_buffer_to_string() on the buffer because it is * usually larger than 'len'; 'buf' is also usually a stack buffer. */ - res = duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); /* buf? res */ + res = duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); /* buf? res */ if (pushed_buf) { duk_remove_m2(thr); } @@ -22852,13 +23571,14 @@ return ret; } -DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) { +DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx) { duk_tval *tv_slot; duk_hobject *h; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(prototype_bidx == -1 || - (prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS)); + DUK_ASSERT(prototype_bidx == -1 || (prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS)); DUK__CHECK_SPACE(); @@ -22869,7 +23589,7 @@ tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, h); - DUK_HOBJECT_INCREF(thr, h); /* no side effects */ + DUK_HOBJECT_INCREF(thr, h); /* no side effects */ thr->valstack_top++; /* object is now reachable */ @@ -22899,9 +23619,8 @@ DUK_ASSERT_API_ENTRY(thr); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return duk_get_top_index_unsafe(thr); } @@ -22914,11 +23633,8 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); obj = duk_harray_alloc(thr, flags); DUK_ASSERT(obj != NULL); @@ -22927,11 +23643,11 @@ tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); - DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ + DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom); thr->valstack_top++; - DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ + DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ return ret; } @@ -22943,22 +23659,19 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAY); obj = duk_harray_alloc(thr, flags); DUK_ASSERT(obj != NULL); tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); - DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ + DUK_HOBJECT_INCREF(thr, obj); /* XXX: could preallocate with refcount = 1 */ ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom); thr->valstack_top++; - DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ + DUK_ASSERT(obj->length == 0); /* Array .length starts at zero. */ return ret; } @@ -22985,12 +23698,7 @@ a = duk_push_harray(thr); - duk_hobject_realloc_props(thr, - (duk_hobject *) a, - 0, - size, - 0, - 0); + duk_hobject_realloc_props(thr, (duk_hobject *) a, 0, size, 0, 0); a->length = size; return a; } @@ -23014,9 +23722,7 @@ DUK__CHECK_SPACE(); - obj = duk_hthread_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); + obj = duk_hthread_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); DUK_ASSERT(obj != NULL); obj->state = DUK_HTHREAD_STATE_INACTIVE; #if defined(DUK_USE_ROM_STRINGS) @@ -23056,8 +23762,7 @@ /* Initial stack size satisfies the stack slack constraints so there * is no need to require stack here. */ - DUK_ASSERT(DUK_VALSTACK_INITIAL_SIZE >= - DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + DUK_ASSERT(DUK_VALSTACK_INITIAL_SIZE >= DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); return ret; } @@ -23076,10 +23781,8 @@ */ obj = duk_hcompfunc_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_COMPFUNC | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_COMPFUNC | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); if (DUK_UNLIKELY(obj == NULL)) { DUK_ERROR_ALLOC_FAILED(thr); DUK_WO_NORETURN(return NULL;); @@ -23107,11 +23810,8 @@ DUK__CHECK_SPACE(); obj = duk_hboundfunc_alloc(thr->heap, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BOUNDFUNC | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BOUNDFUNC | DUK_HOBJECT_FLAG_CONSTRUCTABLE | + DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION)); if (!obj) { DUK_ERROR_ALLOC_FAILED(thr); DUK_WO_NORETURN(return NULL;); @@ -23129,7 +23829,8 @@ return obj; } -DUK_LOCAL duk_idx_t duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx) { +DUK_LOCAL duk_idx_t +duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx) { duk_hnatfunc *obj; duk_idx_t ret; duk_tval *tv_slot; @@ -23157,7 +23858,8 @@ obj->nargs = func_nargs; DUK_DDD(DUK_DDDPRINT("created native function object with flags: 0x%08lx, nargs=%ld", - (unsigned long) obj->obj.hdr.h_flags, (long) obj->nargs)); + (unsigned long) obj->obj.hdr.h_flags, + (long) obj->nargs)); tv_slot = thr->valstack_top; DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj); @@ -23169,7 +23871,7 @@ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) obj, thr->builtinsproto_bidx); return ret; - api_error: +api_error: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } @@ -23179,15 +23881,9 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Default prototype is a Duktape specific %NativeFunctionPrototype% * which provides .length and .name getters. @@ -23200,15 +23896,9 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CONSTRUCTABLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE | DUK_HOBJECT_FLAG_CALLABLE | + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | + DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Must use Function.prototype for standard built-in functions. */ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_FUNCTION_PROTOTYPE); @@ -23219,20 +23909,16 @@ DUK_ASSERT_API_ENTRY(thr); - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_CALLABLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_NATFUNC | - DUK_HOBJECT_FLAG_NEWENV | - DUK_HOBJECT_FLAG_STRICT | - DUK_HOBJECT_FLAG_NOTAIL | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_NATFUNC | + DUK_HOBJECT_FLAG_NEWENV | DUK_HOBJECT_FLAG_STRICT | DUK_HOBJECT_FLAG_NOTAIL | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION); /* Must use Function.prototype for standard built-in functions. */ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_FUNCTION_PROTOTYPE); } -DUK_EXTERNAL duk_idx_t duk_push_c_lightfunc(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic) { +DUK_EXTERNAL duk_idx_t +duk_push_c_lightfunc(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic) { duk_small_uint_t lf_flags; duk_tval *tv_slot; @@ -23261,13 +23947,15 @@ DUK_ASSERT(tv_slot >= thr->valstack_bottom); return (duk_idx_t) (tv_slot - thr->valstack_bottom); - api_error: +api_error: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) { +DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, + duk_uint_t hobject_flags_and_class, + duk_small_int_t prototype_bidx) { duk_hbufobj *obj; duk_tval *tv_slot; @@ -23289,34 +23977,86 @@ return obj; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* XXX: There's quite a bit of overlap with buffer creation handling in * duk_bi_buffer.c. Look for overlap and refactor. */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -#define DUK__PACK_ARGS(classnum,protobidx,elemtype,elemshift,istypedarray) \ +#define DUK__PACK_ARGS(classnum, protobidx, elemtype, elemshift, istypedarray) \ (((classnum) << 24) | ((protobidx) << 16) | ((elemtype) << 8) | ((elemshift) << 4) | (istypedarray)) static const duk_uint32_t duk__bufobj_flags_lookup = { /* Node.js Buffers are Uint8Array instances which inherit from Buffer.prototype. */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_ARRAYBUFFER, DUK_BIDX_ARRAYBUFFER_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 0), /* DUK_BUFOBJ_ARRAYBUFFER */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_BIDX_NODEJS_BUFFER_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 1), /* DUK_BUFOBJ_NODEJS_BUFFER */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_DATAVIEW, DUK_BIDX_DATAVIEW_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 0), /* DUK_BUFOBJ_DATAVIEW */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT8ARRAY, DUK_BIDX_INT8ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT8, 0, 1), /* DUK_BUFOBJ_INT8ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8, 0, 1), /* DUK_BUFOBJ_UINT8ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT8CLAMPED, 0, 1), /* DUK_BUFOBJ_UINT8CLAMPEDARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT16ARRAY, DUK_BIDX_INT16ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT16, 1, 1), /* DUK_BUFOBJ_INT16ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT16ARRAY, DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT16, 1, 1), /* DUK_BUFOBJ_UINT16ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT32ARRAY, DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_INT32, 2, 1), /* DUK_BUFOBJ_INT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT32ARRAY, DUK_BIDX_UINT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_UINT32, 2, 1), /* DUK_BUFOBJ_UINT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT32ARRAY, DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_FLOAT32, 2, 1), /* DUK_BUFOBJ_FLOAT32ARRAY */ - DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT64ARRAY, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE, DUK_HBUFOBJ_ELEM_FLOAT64, 3, 1) /* DUK_BUFOBJ_FLOAT64ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_ARRAYBUFFER, + DUK_BIDX_ARRAYBUFFER_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 0), /* DUK_BUFOBJ_ARRAYBUFFER */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, + DUK_BIDX_NODEJS_BUFFER_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 1), /* DUK_BUFOBJ_NODEJS_BUFFER */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_DATAVIEW, + DUK_BIDX_DATAVIEW_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 0), /* DUK_BUFOBJ_DATAVIEW */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT8ARRAY, + DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT8, + 0, + 1), /* DUK_BUFOBJ_INT8ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8ARRAY, + DUK_BIDX_UINT8ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8, + 0, + 1), /* DUK_BUFOBJ_UINT8ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, + DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT8CLAMPED, + 0, + 1), /* DUK_BUFOBJ_UINT8CLAMPEDARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT16ARRAY, + DUK_BIDX_INT16ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT16, + 1, + 1), /* DUK_BUFOBJ_INT16ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT16ARRAY, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT16, + 1, + 1), /* DUK_BUFOBJ_UINT16ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_INT32ARRAY, + DUK_BIDX_INT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_INT32, + 2, + 1), /* DUK_BUFOBJ_INT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_UINT32ARRAY, + DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_UINT32, + 2, + 1), /* DUK_BUFOBJ_UINT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT32ARRAY, + DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_FLOAT32, + 2, + 1), /* DUK_BUFOBJ_FLOAT32ARRAY */ + DUK__PACK_ARGS(DUK_HOBJECT_CLASS_FLOAT64ARRAY, + DUK_BIDX_FLOAT64ARRAY_PROTOTYPE, + DUK_HBUFOBJ_ELEM_FLOAT64, + 3, + 1) /* DUK_BUFOBJ_FLOAT64ARRAY */ }; -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) -DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) { +DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, + duk_idx_t idx_buffer, + duk_size_t byte_offset, + duk_size_t byte_length, + duk_uint_t flags) { duk_hbufobj *h_bufobj; duk_hbuffer *h_val; duk_hobject *h_arraybuf; @@ -23339,7 +24079,7 @@ } } - DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */ + DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */ lookupidx = flags; if (DUK_UNLIKELY(lookupidx >= sizeof(duk__bufobj_flags_lookup) / sizeof(duk_uint32_t))) { goto arg_error; @@ -23349,9 +24089,9 @@ protobidx = (tmp >> 16) & 0xff; h_arraybuf = duk_get_hobject(thr, idx_buffer); - if (h_arraybuf != NULL && /* argument is an object */ - flags != DUK_BUFOBJ_ARRAYBUFFER && /* creating a view */ - DUK_HOBJECT_GET_CLASS_NUMBER(h_arraybuf) == DUK_HOBJECT_CLASS_ARRAYBUFFER /* argument is ArrayBuffer */) { + if (h_arraybuf != NULL && /* argument is an object */ + flags != DUK_BUFOBJ_ARRAYBUFFER && /* creating a view */ + DUK_HOBJECT_GET_CLASS_NUMBER(h_arraybuf) == DUK_HOBJECT_CLASS_ARRAYBUFFER /* argument is ArrayBuffer */) { duk_uint_t tmp_offset; DUK_HBUFOBJ_ASSERT_VALID((duk_hbufobj *) h_arraybuf); @@ -23388,9 +24128,7 @@ DUK_ASSERT(h_val != NULL); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(classnum), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(classnum), (duk_small_int_t) protobidx); DUK_ASSERT(h_bufobj != NULL); @@ -23413,16 +24151,20 @@ */ return; - range_error: +range_error: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); - arg_error: +arg_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ -DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) { +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, + duk_idx_t idx_buffer, + duk_size_t byte_offset, + duk_size_t byte_length, + duk_uint_t flags) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(idx_buffer); DUK_UNREF(byte_offset); @@ -23431,9 +24173,14 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ -DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap) { +DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + va_list ap) { duk_hobject *proto; #if defined(DUK_USE_AUGMENT_ERROR_CREATE) duk_small_uint_t augment_flags; @@ -23456,9 +24203,8 @@ /* error gets its 'name' from the prototype */ proto = duk_error_prototype_from_code(thr, err_code); (void) duk_push_object_helper_proto(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR), proto); /* ... and its 'message' from an instance property */ @@ -23481,13 +24227,14 @@ /* Creation time error augmentation */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) /* filename may be NULL in which case file/line is not recorded */ - duk_err_augment_error_create(thr, thr, filename, line, augment_flags); /* may throw an error */ + duk_err_augment_error_create(thr, thr, filename, line, augment_flags); /* may throw an error */ #endif return duk_get_top_index_unsafe(thr); } -DUK_EXTERNAL duk_idx_t duk_push_error_object_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { +DUK_EXTERNAL duk_idx_t +duk_push_error_object_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { va_list ap; duk_idx_t ret; @@ -23515,7 +24262,7 @@ va_end(ap); return ret; } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ DUK_EXTERNAL void *duk_push_buffer_raw(duk_hthread *thr, duk_size_t size, duk_small_uint_t flags) { duk_tval *tv_slot; @@ -23618,13 +24365,10 @@ /* CALLABLE and CONSTRUCTABLE flags are copied from the (initial) * target, see ES2015 Sections 9.5.15 and 9.5.13. */ - flags = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h_target) & - (DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE); - flags |= DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ; + flags = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h_target) & (DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE); + flags |= DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ; if (flags & DUK_HOBJECT_FLAG_CALLABLE) { - flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION) | - DUK_HOBJECT_FLAG_SPECIAL_CALL; + flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION) | DUK_HOBJECT_FLAG_SPECIAL_CALL; } else { flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT); } @@ -23650,25 +24394,25 @@ DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) h_proxy); DUK_HOBJECT_INCREF(thr, (duk_hobject *) h_proxy); tv_slot++; - DUK_TVAL_SET_UNDEFINED(tv_slot); /* ... target handler -> ... proxy undefined */ - thr->valstack_top = tv_slot; /* -> ... proxy */ + DUK_TVAL_SET_UNDEFINED(tv_slot); /* ... target handler -> ... proxy undefined */ + thr->valstack_top = tv_slot; /* -> ... proxy */ DUK_DD(DUK_DDPRINT("created Proxy: %!iT", duk_get_tval(thr, -1))); return (duk_idx_t) (thr->valstack_top - thr->valstack_bottom - 1); - fail_args: +fail_args: DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); } -#else /* DUK_USE_ES6_PROXY */ +#else /* DUK_USE_ES6_PROXY */ DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr, duk_uint_t proxy_flags) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(proxy_flags); DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ASSERTIONS) DUK_LOCAL void duk__validate_push_heapptr(duk_hthread *thr, void *ptr) { @@ -23695,9 +24439,7 @@ * the finalizer starts executing). */ #if defined(DUK_USE_FINALIZER_SUPPORT) - for (curr = thr->heap->finalize_list; - curr != NULL; - curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { + for (curr = thr->heap->finalize_list; curr != NULL; curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { /* FINALIZABLE is set for all objects on finalize_list * except for an object being finalized right now. So * can't assert here. @@ -23709,18 +24451,18 @@ if (curr == h) { if (DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) h)) { /* Object is currently being finalized. */ - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } else { /* Not being finalized but on finalize_list, * allowed since Duktape 2.1. */ - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_REFERENCE_COUNTING) /* Because refzero_list is now processed to completion inline with @@ -23746,7 +24488,7 @@ #endif while (str != NULL) { if (str == (duk_hstring *) h) { - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; break; } @@ -23755,18 +24497,16 @@ } DUK_ASSERT(found != 0); } else { - for (curr = thr->heap->heap_allocated; - curr != NULL; - curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { + for (curr = thr->heap->heap_allocated; curr != NULL; curr = DUK_HEAPHDR_GET_NEXT(thr->heap, curr)) { if (curr == h) { - DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ + DUK_ASSERT(found == 0); /* Would indicate corrupted lists. */ found = 1; } } DUK_ASSERT(found != 0); } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ DUK_EXTERNAL duk_idx_t duk_push_heapptr(duk_hthread *thr, void *ptr) { duk_idx_t ret; @@ -23832,7 +24572,7 @@ * heap_allocated. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); /* Preincremented on finalize_list insert. */ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); /* Preincremented on finalize_list insert. */ DUK_HEAPHDR_PREDEC_REFCOUNT(curr); #endif DUK_HEAP_REMOVE_FROM_FINALIZE_LIST(thr->heap, curr); @@ -23864,10 +24604,9 @@ DUK_ASSERT_API_ENTRY(thr); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ return duk_get_top_index_unsafe(thr); } @@ -23976,12 +24715,12 @@ DUK_ASSERT_API_ENTRY(thr); duk_pop_n(thr, count); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_pop_n_unsafe(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); duk__pop_n_unsafe_raw(thr, count); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Pop N elements without DECREF (in effect "stealing" any actual refcounts). */ #if defined(DUK_USE_REFERENCE_COUNTING) @@ -24004,12 +24743,12 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ DUK_INTERNAL void duk_pop_n_nodecref_unsafe(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); duk_pop_n_unsafe(thr, count); } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* Popping one element is called so often that when footprint is not an issue, * compile a specialized function for it. @@ -24027,7 +24766,7 @@ DUK_ASSERT_API_ENTRY(thr); duk_pop_n_nodecref_unsafe(thr, 1); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_LOCAL DUK_ALWAYS_INLINE void duk__pop_unsafe_raw(duk_hthread *thr) { duk_tval *tv; @@ -24039,7 +24778,7 @@ tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif @@ -24075,14 +24814,14 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ #if defined(DUK_USE_PREFER_SIZE) DUK_INTERNAL void duk_pop_undefined(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); duk_pop_nodecref_unsafe(thr); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_pop_undefined(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(thr->valstack_top != thr->valstack_bottom); @@ -24094,7 +24833,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ #if defined(DUK_USE_PREFER_SIZE) DUK_EXTERNAL void duk_pop_2(duk_hthread *thr) { @@ -24121,14 +24860,14 @@ tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif tv = --thr->valstack_top; DUK_ASSERT(tv >= thr->valstack_bottom); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */ #else DUK_TVAL_SET_UNDEFINED(tv); #endif @@ -24162,7 +24901,7 @@ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_pop_3(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); @@ -24209,9 +24948,9 @@ * multiplying with sizeof(duk_tval) won't wrap. */ DUK_ASSERT(count >= 0 && count <= (duk_idx_t) DUK_USE_VALSTACK_LIMIT); - DUK_ASSERT((duk_size_t) count <= DUK_SIZE_MAX / sizeof(duk_tval)); /* no wrapping */ + DUK_ASSERT((duk_size_t) count <= DUK_SIZE_MAX / sizeof(duk_tval)); /* no wrapping */ - tv_dst = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) count); /* XXX: uninitialized would be OK */ + tv_dst = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) count); /* XXX: uninitialized would be OK */ DUK_ASSERT(count == 0 || tv_dst != NULL); DUK_ASSERT(!duk_is_bare_object(thr, -1)); @@ -24225,7 +24964,7 @@ * the rest; no refcount operations needed. */ - tv_dst = tv_src; /* when count == 0, same as tv_src (OK) */ + tv_dst = tv_src; /* when count == 0, same as tv_src (OK) */ tv_src = thr->valstack_top - 1; DUK_TVAL_SET_TVAL(tv_dst, tv_src); @@ -24255,9 +24994,8 @@ DUK_ASSERT(h != NULL); DUK_UNREF(h); -#if defined(DUK_USE_ARRAY_FASTPATH) /* close enough */ - if (DUK_LIKELY(DUK_HOBJECT_IS_ARRAY(h) && - ((duk_harray *) h)->length <= DUK_HOBJECT_GET_ASIZE(h))) { +#if defined(DUK_USE_ARRAY_FASTPATH) /* close enough */ + if (DUK_LIKELY(DUK_HOBJECT_IS_ARRAY(h) && ((duk_harray *) h)->length <= DUK_HOBJECT_GET_ASIZE(h))) { duk_harray *h_arr; duk_tval *tv_src; duk_tval *tv_dst; @@ -24278,8 +25016,7 @@ * XXX: alternatively, could prevent finalizers for the * duration. */ - if (DUK_UNLIKELY(len != h_arr->length || - h_arr->length > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr))) { + if (DUK_UNLIKELY(len != h_arr->length || h_arr->length > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr))) { goto skip_fast; } @@ -24298,7 +25035,7 @@ * without an ancestor lookup (technically * not compliant). */ - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_dst)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_dst)); /* valstack policy */ } else { DUK_TVAL_SET_TVAL(tv_dst, tv_src); DUK_TVAL_INCREF(thr, tv_dst); @@ -24310,8 +25047,8 @@ thr->valstack_top = tv_dst; return (duk_idx_t) h_arr->length; } - skip_fast: -#endif /* DUK_USE_ARRAY_FASTPATH */ + skip_fast: +#endif /* DUK_USE_ARRAY_FASTPATH */ /* Slow path: actual lookups. The initial 'length' lookup * decides the output length, regardless of side effects that @@ -24320,7 +25057,7 @@ */ idx = duk_normalize_index(thr, idx); duk_get_prop_stridx(thr, idx, DUK_STRIDX_LENGTH); - len = duk_to_uint32(thr, -1); /* ToUint32() coercion required */ + len = duk_to_uint32(thr, -1); /* ToUint32() coercion required */ if (DUK_UNLIKELY(len >= 0x80000000UL)) { goto fail_over_2g; } @@ -24339,7 +25076,7 @@ DUK_ERROR_TYPE_INVALID_ARGS(thr); DUK_WO_NORETURN(return 0;); - fail_over_2g: +fail_over_2g: DUK_ERROR_RANGE_INVALID_LENGTH(thr); DUK_WO_NORETURN(return 0;); } @@ -24424,7 +25161,12 @@ } } -DUK_EXTERNAL void duk_error_va_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap) { +DUK_EXTERNAL void duk_error_va_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + va_list ap) { DUK_ASSERT_API_ENTRY(thr); duk_push_error_object_va_raw(thr, err_code, filename, line, fmt, ap); @@ -24432,7 +25174,12 @@ DUK_WO_NORETURN(return;); } -DUK_EXTERNAL void duk_error_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) { +DUK_EXTERNAL void duk_error_raw(duk_hthread *thr, + duk_errcode_t err_code, + const char *filename, + duk_int_t line, + const char *fmt, + ...) { va_list ap; DUK_ASSERT_API_ENTRY(thr); @@ -24451,7 +25198,8 @@ #endif #if !defined(DUK_USE_VARIADIC_MACROS) -DUK_NORETURN(DUK_LOCAL_DECL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap)); +DUK_NORETURN( + DUK_LOCAL_DECL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap)); DUK_LOCAL void duk__throw_error_from_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, va_list ap) { const char *filename; @@ -24469,7 +25217,8 @@ DUK_WO_NORETURN(return;); } -#define DUK__ERROR_STASH_SHARED(code) do { \ +#define DUK__ERROR_STASH_SHARED(code) \ + do { \ va_list ap; \ va_start(ap, fmt); \ duk__throw_error_from_stash(thr, (code), fmt, ap); \ @@ -24509,7 +25258,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK__ERROR_STASH_SHARED(DUK_ERR_URI_ERROR); } -#endif /* DUK_USE_VARIADIC_MACROS */ +#endif /* DUK_USE_VARIADIC_MACROS */ /* * Comparison @@ -24628,7 +25377,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(tv)); - DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags); /* read before 'tv' potentially invalidated */ + DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags); /* read before 'tv' potentially invalidated */ duk_push_literal(thr, "function "); duk_push_lightfunc_name_raw(thr, func, lf_flags); duk_push_literal(thr, "() { lightfunc code }"); @@ -24649,7 +25398,7 @@ duk_small_uint_t t; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(sz <= 32); /* sanity limit for function pointer size */ + DUK_ASSERT(sz <= 32); /* sanity limit for function pointer size */ p = buf; #if defined(DUK_USE_INTEGER_LE) @@ -24678,9 +25427,9 @@ */ /* String limits for summary strings. */ -#define DUK__READABLE_SUMMARY_MAXCHARS 96 /* maximum supported by helper */ -#define DUK__READABLE_STRING_MAXCHARS 32 /* for strings/symbols */ -#define DUK__READABLE_ERRMSG_MAXCHARS 96 /* for error messages */ +#define DUK__READABLE_SUMMARY_MAXCHARS 96 /* maximum supported by helper */ +#define DUK__READABLE_STRING_MAXCHARS 32 /* for strings/symbols */ +#define DUK__READABLE_ERRMSG_MAXCHARS 96 /* for error messages */ /* String sanitizer which escapes ASCII control characters and a few other * ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with @@ -24689,8 +25438,7 @@ */ DUK_LOCAL void duk__push_hstring_readable_unicode(duk_hthread *thr, duk_hstring *h_input, duk_small_uint_t maxchars) { const duk_uint8_t *p, *p_start, *p_end; - duk_uint8_t bufDUK_UNICODE_MAX_XUTF8_LENGTH * DUK__READABLE_SUMMARY_MAXCHARS + - 2 /*quotes*/ + 3 /*periods*/; + duk_uint8_t bufDUK_UNICODE_MAX_XUTF8_LENGTH * DUK__READABLE_SUMMARY_MAXCHARS + 2 /*quotes*/ + 3 /*periods*/; duk_uint8_t *q; duk_ucodepoint_t cp; duk_small_uint_t nchars; @@ -24718,7 +25466,7 @@ } if (duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp)) { if (cp < 0x20 || cp == 0x7f || cp == DUK_ASC_SINGLEQUOTE || cp == DUK_ASC_BACKSLASH) { - DUK_ASSERT(DUK_UNICODE_MAX_XUTF8_LENGTH >= 4); /* estimate is valid */ + DUK_ASSERT(DUK_UNICODE_MAX_XUTF8_LENGTH >= 4); /* estimate is valid */ DUK_ASSERT((cp >> 4) <= 0x0f); *q++ = (duk_uint8_t) DUK_ASC_BACKSLASH; *q++ = (duk_uint8_t) DUK_ASC_LC_X; @@ -24728,7 +25476,7 @@ q += duk_unicode_encode_xutf8(cp, q); } } else { - p++; /* advance manually */ + p++; /* advance manually */ *q++ = (duk_uint8_t) DUK_ASC_QUESTION; } nchars++; @@ -24767,8 +25515,10 @@ duk_hobject *h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); - if (error_aware && - duk_hobject_prototype_chain_contains(thr, h, thr->builtinsDUK_BIDX_ERROR_PROTOTYPE, 1 /*ignore_loop*/)) { + if (error_aware && duk_hobject_prototype_chain_contains(thr, + h, + thr->builtinsDUK_BIDX_ERROR_PROTOTYPE, + 1 /*ignore_loop*/)) { /* Get error message in a side effect free way if * possible; if not, summarize as a generic object. * Error message currently gets quoted. @@ -24782,7 +25532,9 @@ /* It's critical to avoid recursion so * only summarize a string .message. */ - duk__push_hstring_readable_unicode(thr, DUK_TVAL_GET_STRING(tv_msg), DUK__READABLE_ERRMSG_MAXCHARS); + duk__push_hstring_readable_unicode(thr, + DUK_TVAL_GET_STRING(tv_msg), + DUK__READABLE_ERRMSG_MAXCHARS); break; } } @@ -24865,7 +25617,7 @@ * Functions */ -#if 0 /* not used yet */ +#if 0 /* not used yet */ DUK_INTERNAL void duk_push_hnatfunc_name(duk_hthread *thr, duk_hnatfunc *h) { duk_c_function func; @@ -24892,7 +25644,7 @@ DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(thr); - DUK_ASSERT(count * sizeof(duk_tval) >= count); /* no wrap */ + DUK_ASSERT(count * sizeof(duk_tval) >= count); /* no wrap */ duk_memcpy_unsafe((void *) tv_dst, (const void *) tv_src, count * sizeof(duk_tval)); @@ -24965,15 +25717,14 @@ /* Impose a string maximum length, need to handle overflow * correctly. */ - if (new_len < len || /* wrapped */ + if (new_len < len || /* wrapped */ new_len > (duk_size_t) DUK_HSTRING_MAX_BYTELEN) { goto error_overflow; } len = new_len; } - DUK_DDD(DUK_DDDPRINT("join/concat %lu strings, total length %lu bytes", - (unsigned long) count, (unsigned long) len)); + DUK_DDD(DUK_DDDPRINT("join/concat %lu strings, total length %lu bytes", (unsigned long) count, (unsigned long) len)); /* Use stack allocated buffer to ensure reachability in errors * (e.g. intern error). @@ -24986,11 +25737,11 @@ idx = 0; for (i = count; i >= 1; i--) { if (is_join && i != count) { - h = duk_require_hstring(thr, -((duk_idx_t) count) - 2); /* extra -1 for buffer */ + h = duk_require_hstring(thr, -((duk_idx_t) count) - 2); /* extra -1 for buffer */ duk_memcpy(buf + idx, DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); idx += DUK_HSTRING_GET_BYTELEN(h); } - h = duk_require_hstring(thr, -((duk_idx_t) i) - 1); /* extra -1 for buffer */ + h = duk_require_hstring(thr, -((duk_idx_t) i) - 1); /* extra -1 for buffer */ duk_memcpy(buf + idx, DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); idx += DUK_HSTRING_GET_BYTELEN(h); } @@ -25002,21 +25753,21 @@ /* Get rid of the strings early to minimize memory use before intern. */ if (is_join) { - duk_replace(thr, -((duk_idx_t) count) - 2); /* overwrite sep */ + duk_replace(thr, -((duk_idx_t) count) - 2); /* overwrite sep */ duk_pop_n(thr, (duk_idx_t) count); } else { - duk_replace(thr, -((duk_idx_t) count) - 1); /* overwrite str1 */ + duk_replace(thr, -((duk_idx_t) count) - 1); /* overwrite str1 */ duk_pop_n(thr, (duk_idx_t) (count - 1)); } /* ... buf */ - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ /* ... res */ return; - error_overflow: +error_overflow: DUK_ERROR_RANGE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return;); } @@ -25032,7 +25783,7 @@ DUK_ASSERT_API_ENTRY(thr); duk_concat(thr, 2); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_INTERNAL void duk_concat_2(duk_hthread *thr) { duk_hstring *h1; duk_hstring *h2; @@ -25042,14 +25793,14 @@ duk_size_t len; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(duk_get_top(thr) >= 2); /* Trusted caller. */ + DUK_ASSERT(duk_get_top(thr) >= 2); /* Trusted caller. */ h1 = duk_to_hstring(thr, -2); h2 = duk_to_hstring(thr, -1); len1 = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h1); len2 = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h2); len = len1 + len2; - if (DUK_UNLIKELY(len < len1 || /* wrapped */ + if (DUK_UNLIKELY(len < len1 || /* wrapped */ len > (duk_size_t) DUK_HSTRING_MAX_BYTELEN)) { goto error_overflow; } @@ -25058,7 +25809,7 @@ duk_memcpy((void *) buf, (const void *) DUK_HSTRING_GET_DATA(h1), (size_t) len1); duk_memcpy((void *) (buf + len1), (const void *) DUK_HSTRING_GET_DATA(h2), (size_t) len2); - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ /* ... str1 str2 buf */ @@ -25066,11 +25817,11 @@ duk_pop_unsafe(thr); return; - error_overflow: +error_overflow: DUK_ERROR_RANGE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ DUK_EXTERNAL void duk_join(duk_hthread *thr, duk_idx_t count) { DUK_ASSERT_API_ENTRY(thr); @@ -25089,7 +25840,7 @@ DUK_ASSERT_API_ENTRY(thr); - h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ + h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input); @@ -25116,11 +25867,11 @@ idx = duk_normalize_index(thr, idx); - h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ + h_input = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* Reasonable output estimate. */ + DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* Reasonable output estimate. */ p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_input); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); @@ -25141,7 +25892,7 @@ } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 encoded. */ duk_replace(thr, idx); } @@ -25154,7 +25905,7 @@ DUK_ASSERT_API_ENTRY(thr); - idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ + idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ h = duk_require_hstring(thr, idx); DUK_ASSERT(h != NULL); @@ -25179,7 +25930,7 @@ end_byte_offset = (duk_size_t) duk_heap_strcache_offset_char2byte(thr, h, (duk_uint_fast32_t) end_offset); DUK_ASSERT(end_byte_offset >= start_byte_offset); - DUK_ASSERT(end_byte_offset - start_byte_offset <= DUK_UINT32_MAX); /* Guaranteed by string limits. */ + DUK_ASSERT(end_byte_offset - start_byte_offset <= DUK_UINT32_MAX); /* Guaranteed by string limits. */ /* No size check is necessary. */ res = duk_heap_strtable_intern_checked(thr, @@ -25195,13 +25946,13 @@ */ DUK_EXTERNAL void duk_trim(duk_hthread *thr, duk_idx_t idx) { duk_hstring *h; - const duk_uint8_t *p, *p_start, *p_end, *p_tmp1, *p_tmp2; /* pointers for scanning */ - const duk_uint8_t *q_start, *q_end; /* start (incl) and end (excl) of trimmed part */ + const duk_uint8_t *p, *p_start, *p_end, *p_tmp1, *p_tmp2; /* pointers for scanning */ + const duk_uint8_t *q_start, *q_end; /* start (incl) and end (excl) of trimmed part */ duk_codepoint_t cp; DUK_ASSERT_API_ENTRY(thr); - idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ + idx = duk_require_normalize_index(thr, idx); /* Accept symbols. */ h = duk_require_hstring(thr, idx); DUK_ASSERT(h != NULL); @@ -25243,7 +25994,7 @@ } q_end = p; - scan_done: +scan_done: /* This may happen when forward and backward scanning disagree * (possible for non-extended-UTF-8 strings). */ @@ -25256,8 +26007,10 @@ DUK_ASSERT(q_end >= q_start); DUK_DDD(DUK_DDDPRINT("trim: p_start=%p, p_end=%p, q_start=%p, q_end=%p", - (const void *) p_start, (const void *) p_end, - (const void *) q_start, (const void *) q_end)); + (const void *) p_start, + (const void *) p_end, + (const void *) q_start, + (const void *) q_end)); if (q_start == p_start && q_end == p_end) { DUK_DDD(DUK_DDDPRINT("nothing was trimmed: avoid interning (hashing etc)")); @@ -25278,15 +26031,15 @@ * is handling of clamped offsets. */ - h = duk_require_hstring(thr, idx); /* Accept symbols. */ + h = duk_require_hstring(thr, idx); /* Accept symbols. */ DUK_ASSERT(h != NULL); - DUK_ASSERT_DISABLE(char_offset >= 0); /* Always true, arg is unsigned. */ + DUK_ASSERT_DISABLE(char_offset >= 0); /* Always true, arg is unsigned. */ if (char_offset >= DUK_HSTRING_GET_CHARLEN(h)) { return 0; } - DUK_ASSERT(char_offset <= DUK_UINT_MAX); /* Guaranteed by string limits. */ + DUK_ASSERT(char_offset <= DUK_UINT_MAX); /* Guaranteed by string limits. */ cp = duk_hstring_char_code_at_raw(thr, h, (duk_uint_t) char_offset, 0 /*surrogate_aware*/); return (duk_codepoint_t) cp; } @@ -25330,7 +26083,7 @@ return duk_time_get_ecmascript_time(thr); } -#if 0 /* XXX: worth exposing? */ +#if 0 /* XXX: worth exposing? */ DUK_EXTERNAL duk_double_t duk_get_monotonic_time(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); DUK_UNREF(thr); @@ -25345,7 +26098,7 @@ duk_uint_t flags; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(comp != NULL); /* XXX: or check? */ + DUK_ASSERT(comp != NULL); /* XXX: or check? */ DUK_UNREF(thr); /* Convert as one-based, but change month to zero-based to match the @@ -25374,7 +26127,7 @@ duk_uint_t flags; DUK_ASSERT_API_ENTRY(thr); - DUK_ASSERT(comp != NULL); /* XXX: or check? */ + DUK_ASSERT(comp != NULL); /* XXX: or check? */ DUK_UNREF(thr); /* Match Date constructor behavior (with UTC time). Month is given @@ -25395,7 +26148,7 @@ dpartsDUK_DATE_IDX_MINUTE = comp->minutes; dpartsDUK_DATE_IDX_SECOND = comp->seconds; dpartsDUK_DATE_IDX_MILLISECOND = comp->milliseconds; - dpartsDUK_DATE_IDX_WEEKDAY = 0; /* ignored */ + dpartsDUK_DATE_IDX_WEEKDAY = 0; /* ignored */ d = duk_bi_date_get_timeval_from_dparts(dparts, flags); @@ -25447,7 +26200,7 @@ /* Perform an intermediate join when this many elements have been pushed * on the value stack. */ -#define DUK__ARRAY_MID_JOIN_LIMIT 4096 +#define DUK__ARRAY_MID_JOIN_LIMIT 4096 #if defined(DUK_USE_ARRAY_BUILTIN) @@ -25498,7 +26251,7 @@ duk_hobject *h; duk_uint_t flags_mask, flags_bits, flags_value; - DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* because call in progress */ + DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* because call in progress */ tv = DUK_GET_THIS_TVAL_PTR(thr); /* Fast path requires that 'this' is a duk_harray. Read only arrays @@ -25510,11 +26263,8 @@ } h = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h != NULL); - flags_mask = DUK_HOBJECT_FLAG_ARRAY_PART | \ - DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \ - DUK_HEAPHDR_FLAG_READONLY; - flags_bits = DUK_HOBJECT_FLAG_ARRAY_PART | \ - DUK_HOBJECT_FLAG_EXOTIC_ARRAY; + flags_mask = DUK_HOBJECT_FLAG_ARRAY_PART | DUK_HOBJECT_FLAG_EXOTIC_ARRAY | DUK_HEAPHDR_FLAG_READONLY; + flags_bits = DUK_HOBJECT_FLAG_ARRAY_PART | DUK_HOBJECT_FLAG_EXOTIC_ARRAY; flags_value = DUK_HEAPHDR_GET_FLAGS_RAW((duk_heaphdr *) h); if ((flags_value & flags_mask) != flags_bits) { DUK_DD(DUK_DDPRINT("reject array fast path: object flag check failed")); @@ -25540,7 +26290,7 @@ DUK_DD(DUK_DDPRINT("array fast path allowed for: %!O", (duk_heaphdr *) h)); return (duk_harray *) h; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ /* * Constructor @@ -25610,7 +26360,7 @@ */ DUK_DDD(DUK_DDDPRINT("this.join is not callable, fall back to (original) Object.toString")); duk_set_top(thr, 0); - return duk_bi_object_prototype_to_string(thr); /* has access to 'this' binding */ + return duk_bi_object_prototype_to_string(thr); /* has access to 'this' binding */ } /* ... this func */ @@ -25619,9 +26369,8 @@ /* ... func this */ - DUK_DDD(DUK_DDDPRINT("calling: func=%!iT, this=%!iT", - (duk_tval *) duk_get_tval(thr, -2), - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD( + DUK_DDDPRINT("calling: func=%!iT, this=%!iT", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_call_method(thr, 0); return 1; @@ -25651,7 +26400,7 @@ (void) duk_push_this_coercible_to_object(thr); duk_insert(thr, 0); n = duk_get_top(thr); - duk_push_array(thr); /* -> ToObject(this) item1 ... itemN arr */ + duk_push_array(thr); /* -> ToObject(this) item1 ... itemN arr */ /* NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index() * (which differs from the official algorithm). If no error is thrown, this @@ -25702,7 +26451,7 @@ } DUK_ASSERT(duk_is_object(thr, i)); - need_has_check = (DUK_HOBJECT_IS_PROXY(h) != 0); /* Always 0 w/o Proxy support. */ + need_has_check = (DUK_HOBJECT_IS_PROXY(h) != 0); /* Always 0 w/o Proxy support. */ /* ToObject(this) item1 ... itemN arr */ @@ -25734,7 +26483,7 @@ } } idx++; - DUK_ASSERT(idx != 0U); /* Wrap check above. */ + DUK_ASSERT(idx != 0U); /* Wrap check above. */ } } @@ -25749,7 +26498,7 @@ DUK_ASSERT_TOP(thr, n + 1); return 1; - fail_wrap: +fail_wrap: DUK_ERROR_RANGE_INVALID_LENGTH(thr); DUK_WO_NORETURN(return 0;); } @@ -25795,8 +26544,7 @@ (unsigned long) len)); /* The extra (+4) is tight. */ - valstack_required = (duk_idx_t) ((len >= DUK__ARRAY_MID_JOIN_LIMIT ? - DUK__ARRAY_MID_JOIN_LIMIT : len) + 4); + valstack_required = (duk_idx_t) ((len >= DUK__ARRAY_MID_JOIN_LIMIT ? DUK__ARRAY_MID_JOIN_LIMIT : len) + 4); duk_require_stack(thr, valstack_required); duk_dup_0(thr); @@ -25807,14 +26555,13 @@ idx = 0; for (;;) { DUK_DDD(DUK_DDDPRINT("join idx=%ld", (long) idx)); - if (count >= DUK__ARRAY_MID_JOIN_LIMIT || /* intermediate join to avoid valstack overflow */ + if (count >= DUK__ARRAY_MID_JOIN_LIMIT || /* intermediate join to avoid valstack overflow */ idx >= len) { /* end of loop (careful with len==0) */ /* sep ToObject(this) len sep str0 ... str(count-1) */ - DUK_DDD(DUK_DDDPRINT("mid/final join, count=%ld, idx=%ld, len=%ld", - (long) count, (long) idx, (long) len)); - duk_join(thr, (duk_idx_t) count); /* -> sep ToObject(this) len str */ - duk_dup_0(thr); /* -> sep ToObject(this) len str sep */ - duk_insert(thr, -2); /* -> sep ToObject(this) len sep str */ + DUK_DDD(DUK_DDDPRINT("mid/final join, count=%ld, idx=%ld, len=%ld", (long) count, (long) idx, (long) len)); + duk_join(thr, (duk_idx_t) count); /* -> sep ToObject(this) len str */ + duk_dup_0(thr); /* -> sep ToObject(this) len str sep */ + duk_insert(thr, -2); /* -> sep ToObject(this) len sep str */ count = 1; } if (idx >= len) { @@ -25830,7 +26577,7 @@ if (to_locale_string) { duk_to_object(thr, -1); duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_LOCALE_STRING); - duk_insert(thr, -2); /* -> ... toLocaleString ToObject(val) */ + duk_insert(thr, -2); /* -> ... toLocaleString ToObject(val) */ duk_call_method(thr, 0); } duk_to_string(thr, -1); @@ -25888,7 +26635,7 @@ return 1; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ DUK_INTERNAL duk_ret_t duk_bi_array_prototype_pop(duk_hthread *thr) { duk_uint32_t len; @@ -25939,7 +26686,7 @@ DUK_ASSERT((duk_uint32_t) n <= DUK_UINT32_MAX); if (DUK_UNLIKELY(len + (duk_uint32_t) n < len)) { DUK_D(DUK_DPRINT("Array.prototype.push() would go beyond 32-bit length, throw")); - DUK_DCERROR_RANGE_INVALID_LENGTH(thr); /* != 0 return value returned as is by caller */ + DUK_DCERROR_RANGE_INVALID_LENGTH(thr); /* != 0 return value returned as is by caller */ } if (len + (duk_uint32_t) n > DUK_HOBJECT_GET_ASIZE((duk_hobject *) h_arr)) { /* Array part would need to be extended. Rely on slow path @@ -25969,7 +26716,7 @@ duk_push_uint(thr, (duk_uint_t) len); return 1; } -#endif /* DUK_USE_ARRAY_FASTPATH */ +#endif /* DUK_USE_ARRAY_FASTPATH */ DUK_INTERNAL duk_ret_t duk_bi_array_prototype_push(duk_hthread *thr) { /* Note: 'this' is not necessarily an Array object. The push() @@ -26044,7 +26791,7 @@ duk_bool_t have1, have2; duk_bool_t undef1, undef2; duk_small_int_t ret; - duk_idx_t idx_obj = 1; /* fixed offsets in valstack */ + duk_idx_t idx_obj = 1; /* fixed offsets in valstack */ duk_idx_t idx_fn = 0; duk_hstring *h1, *h2; @@ -26065,7 +26812,8 @@ if (idx1 == idx2) { DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%ld, idx2=%ld -> indices identical, quick exit", - (long) idx1, (long) idx2)); + (long) idx1, + (long) idx2)); return 0; } @@ -26073,8 +26821,12 @@ have2 = duk_get_prop_index(thr, idx_obj, (duk_uarridx_t) idx2); DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%ld, idx2=%ld, have1=%ld, have2=%ld, val1=%!T, val2=%!T", - (long) idx1, (long) idx2, (long) have1, (long) have2, - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (long) idx1, + (long) idx2, + (long) have1, + (long) have2, + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); if (have1) { if (have2) { @@ -26116,9 +26868,9 @@ duk_double_t d; /* No need to check callable; duk_call() will do that. */ - duk_dup(thr, idx_fn); /* -> ... x y fn */ - duk_insert(thr, -3); /* -> ... fn x y */ - duk_call(thr, 2); /* -> ... res */ + duk_dup(thr, idx_fn); /* -> ... x y fn */ + duk_insert(thr, -3); /* -> ... fn x y */ + duk_call(thr, 2); /* -> ... res */ /* ES5 is a bit vague about what to do if the return value is * not a number. ES2015 provides a concrete description: @@ -26150,10 +26902,10 @@ DUK_ASSERT(h1 != NULL); DUK_ASSERT(h2 != NULL); - ret = duk_js_string_compare(h1, h2); /* retval is directly usable */ + ret = duk_js_string_compare(h1, h2); /* retval is directly usable */ goto pop_ret; - pop_ret: +pop_ret: duk_pop_2_unsafe(thr); DUK_DDD(DUK_DDDPRINT("-> result %ld", (long) ret)); return ret; @@ -26161,7 +26913,7 @@ DUK_LOCAL void duk__array_sort_swap(duk_hthread *thr, duk_int_t l, duk_int_t r) { duk_bool_t have_l, have_r; - duk_idx_t idx_obj = 1; /* fixed offset in valstack */ + duk_idx_t idx_obj = 1; /* fixed offset in valstack */ if (l == r) { return; @@ -26214,8 +26966,7 @@ *ptr++ = ''; *ptr++ = '\0'; - DUK_DDD(DUK_DDDPRINT("%s (lo=%ld, hi=%ld, pivot=%ld)", - (const char *) buf, (long) lo, (long) hi, (long) pivot)); + DUK_DDD(DUK_DDDPRINT("%s (lo=%ld, hi=%ld, pivot=%ld)", (const char *) buf, (long) lo, (long) hi, (long) pivot)); } #endif @@ -26224,8 +26975,7 @@ /* The lo/hi indices may be crossed and hi < 0 is possible at entry. */ - DUK_DDD(DUK_DDDPRINT("duk__array_qsort: lo=%ld, hi=%ld, obj=%!T", - (long) lo, (long) hi, (duk_tval *) duk_get_tval(thr, 1))); + DUK_DDD(DUK_DDDPRINT("duk__array_qsort: lo=%ld, hi=%ld, obj=%!T", (long) lo, (long) hi, (duk_tval *) duk_get_tval(thr, 1))); DUK_ASSERT_TOP(thr, 3); @@ -26243,7 +26993,7 @@ DUK_ASSERT(hi - lo + 1 >= 2); /* randomized pivot selection */ - p = lo + (duk_int_t) (DUK_UTIL_GET_RANDOM_DOUBLE(thr) * (duk_double_t) (hi - lo + 1)); + p = lo + (duk_int_t) (duk_util_get_random_double(thr) * (duk_double_t) (hi - lo + 1)); DUK_ASSERT(p >= lo && p <= hi); DUK_DDD(DUK_DDDPRINT("lo=%ld, hi=%ld, chose pivot p=%ld", (long) lo, (long) hi, (long) p)); @@ -26257,23 +27007,21 @@ for (;;) { /* find elements to swap */ for (;;) { - DUK_DDD(DUK_DDDPRINT("left scan: l=%ld, r=%ld, p=%ld", - (long) l, (long) r, (long) p)); + DUK_DDD(DUK_DDDPRINT("left scan: l=%ld, r=%ld, p=%ld", (long) l, (long) r, (long) p)); if (l >= hi) { break; } - if (duk__array_sort_compare(thr, l, p) >= 0) { /* !(l < p) */ + if (duk__array_sort_compare(thr, l, p) >= 0) { /* !(l < p) */ break; } l++; } for (;;) { - DUK_DDD(DUK_DDDPRINT("right scan: l=%ld, r=%ld, p=%ld", - (long) l, (long) r, (long) p)); + DUK_DDD(DUK_DDDPRINT("right scan: l=%ld, r=%ld, p=%ld", (long) l, (long) r, (long) p)); if (r <= lo) { break; } - if (duk__array_sort_compare(thr, p, r) >= 0) { /* !(p < r) */ + if (duk__array_sort_compare(thr, p, r) >= 0) { /* !(p < r) */ break; } r--; @@ -26291,7 +27039,7 @@ l++; r--; } - done: +done: /* Note that 'l' and 'r' may cross, i.e. r < l */ DUK_ASSERT(l >= lo && l <= hi); DUK_ASSERT(r >= lo && r <= hi); @@ -26335,7 +27083,7 @@ DUK_ASSERT_TOP(thr, 3); duk_pop_nodecref_unsafe(thr); - return 1; /* return ToObject(this) */ + return 1; /* return ToObject(this) */ } /* @@ -26428,7 +27176,7 @@ for (i = 0; i < del_count; i++) { if (duk_get_prop_index(thr, -3, (duk_uarridx_t) (act_start + i))) { - duk_xdef_prop_index_wec(thr, -2, (duk_uarridx_t) i); /* throw flag irrelevant (false in std alg) */ + duk_xdef_prop_index_wec(thr, -2, (duk_uarridx_t) i); /* throw flag irrelevant (false in std alg) */ } else { duk_pop_undefined(thr); } @@ -26498,7 +27246,7 @@ /* Step 15: insert itemCount elements into the hole made above */ for (i = 0; i < item_count; i++) { - duk_dup(thr, i + 2); /* args start at index 2 */ + duk_dup(thr, i + 2); /* args start at index 2 */ duk_put_prop_index(thr, -4, (duk_uarridx_t) (act_start + i)); } @@ -26561,7 +27309,7 @@ } DUK_ASSERT_TOP(thr, 2); - duk_pop_unsafe(thr); /* -> ToObject(this) */ + duk_pop_unsafe(thr); /* -> ToObject(this) */ return 1; } @@ -26711,26 +27459,32 @@ if (duk_get_prop_index(thr, -2, (duk_uarridx_t) i)) { /* fromPresent = true */ /* ... ToObject(this) ToUint32(length) val */ - duk_put_prop_index(thr, -3, (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ + duk_put_prop_index( + thr, + -3, + (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ } else { /* fromPresent = false */ /* ... ToObject(this) ToUint32(length) val */ duk_pop_undefined(thr); - duk_del_prop_index(thr, -2, (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ + duk_del_prop_index( + thr, + -2, + (duk_uarridx_t) (i + (duk_uint32_t) nargs)); /* -> ... ToObject(this) ToUint32(length) */ } DUK_ASSERT_TOP(thr, nargs + 2); } for (i = 0; i < (duk_uint32_t) nargs; i++) { DUK_ASSERT_TOP(thr, nargs + 2); - duk_dup(thr, (duk_idx_t) i); /* -> ... ToObject(this) ToUint32(length) argi */ + duk_dup(thr, (duk_idx_t) i); /* -> ... ToObject(this) ToUint32(length) argi */ duk_put_prop_index(thr, -3, (duk_uarridx_t) i); DUK_ASSERT_TOP(thr, nargs + 2); } DUK_ASSERT_TOP(thr, nargs + 2); duk_push_u32(thr, len + (duk_uint32_t) nargs); - duk_dup_top(thr); /* -> ... ToObject(this) ToUint32(length) final_len final_len */ + duk_dup_top(thr); /* -> ... ToObject(this) ToUint32(length) final_len final_len */ duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_LENGTH); return 1; } @@ -26743,7 +27497,7 @@ duk_idx_t nargs; duk_int_t i, len; duk_int_t from_idx; - duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for indexOf, -1 for lastIndexOf */ + duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for indexOf, -1 for lastIndexOf */ /* lastIndexOf() needs to be a vararg function because we must distinguish * between an undefined fromIndex and a "not given" fromIndex; indexOf() is @@ -26781,10 +27535,7 @@ * lastIndexOf: clamp fromIndex to -len - 1, len - 1 * (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly) */ - from_idx = duk_to_int_clamped(thr, - 1, - (idx_step > 0 ? -len : -len - 1), - (idx_step > 0 ? len : len - 1)); + from_idx = duk_to_int_clamped(thr, 1, (idx_step > 0 ? -len : -len - 1), (idx_step > 0 ? len : len - 1)); if (from_idx < 0) { /* for lastIndexOf, result may be -1 (mark immediate termination) */ from_idx = len + from_idx; @@ -26820,7 +27571,7 @@ duk_pop_unsafe(thr); } - not_found: +not_found: duk_push_int(thr, -1); return 1; } @@ -26829,11 +27580,11 @@ * every(), some(), forEach(), map(), filter() */ -#define DUK__ITER_EVERY 0 -#define DUK__ITER_SOME 1 -#define DUK__ITER_FOREACH 2 -#define DUK__ITER_MAP 3 -#define DUK__ITER_FILTER 4 +#define DUK__ITER_EVERY 0 +#define DUK__ITER_SOME 1 +#define DUK__ITER_FOREACH 2 +#define DUK__ITER_MAP 3 +#define DUK__ITER_FILTER 4 /* XXX: This helper is a bit awkward because the handling for the different iteration * callers is quite different. This now compiles to a bit less than 500 bytes, so with @@ -26868,7 +27619,7 @@ * stack4 = result array (or undefined) */ - k = 0; /* result index for filter() */ + k = 0; /* result index for filter() */ for (i = 0; i < len; i++) { DUK_ASSERT_TOP(thr, 5); @@ -26892,7 +27643,7 @@ duk_dup_1(thr); duk_dup_m3(thr); duk_push_u32(thr, i); - duk_dup_2(thr); /* ... val callback thisArg val i obj */ + duk_dup_2(thr); /* ... val callback thisArg val i obj */ duk_call_method(thr, 3); /* -> ... val retval */ switch (iter_type) { @@ -26915,13 +27666,13 @@ break; case DUK__ITER_MAP: duk_dup_top(thr); - duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) i); /* retval to resulti */ + duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) i); /* retval to resulti */ res_length = i + 1; break; case DUK__ITER_FILTER: bval = duk_to_boolean(thr, -1); if (bval) { - duk_dup_m2(thr); /* orig value */ + duk_dup_m2(thr); /* orig value */ duk_xdef_prop_index_wec(thr, 4, (duk_uarridx_t) k); k++; res_length = k; @@ -26949,7 +27700,7 @@ case DUK__ITER_MAP: case DUK__ITER_FILTER: DUK_ASSERT_TOP(thr, 5); - DUK_ASSERT(duk_is_array(thr, -1)); /* topmost element is the result array already */ + DUK_ASSERT(duk_is_array(thr, -1)); /* topmost element is the result array already */ duk_push_u32(thr, res_length); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_W); break; @@ -26969,7 +27720,7 @@ duk_idx_t nargs; duk_bool_t have_acc; duk_uint32_t i, len; - duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for reduce, -1 for reduceRight */ + duk_small_int_t idx_step = duk_get_current_magic(thr); /* idx_step is +1 for reduce, -1 for reduceRight */ /* We're a varargs function because we need to detect whether * initialValue was given or not. @@ -26993,8 +27744,7 @@ duk_dup_1(thr); have_acc = 1; } - DUK_DDD(DUK_DDDPRINT("have_acc=%ld, acc=%!T", - (long) have_acc, (duk_tval *) duk_get_tval(thr, 3))); + DUK_DDD(DUK_DDDPRINT("have_acc=%ld, acc=%!T", (long) have_acc, (duk_tval *) duk_get_tval(thr, 3))); /* For len == 0, i is initialized to len - 1 which underflows. * The condition (i < len) will then exit the for-loop on the @@ -27002,16 +27752,16 @@ * happens by i underflowing. */ - for (i = (idx_step >= 0 ? 0 : len - 1); - i < len; /* i >= 0 would always be true */ + for (i = (idx_step >= 0 ? 0 : len - 1); i < len; /* i >= 0 would always be true */ i += (duk_uint32_t) idx_step) { DUK_DDD(DUK_DDDPRINT("i=%ld, len=%ld, have_acc=%ld, top=%ld, acc=%!T", - (long) i, (long) len, (long) have_acc, + (long) i, + (long) len, + (long) have_acc, (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, 4))); - DUK_ASSERT((have_acc && duk_get_top(thr) == 5) || - (!have_acc && duk_get_top(thr) == 4)); + DUK_ASSERT((have_acc && duk_get_top(thr) == 5) || (!have_acc && duk_get_top(thr) == 4)); if (!duk_has_prop_index(thr, 2, (duk_uarridx_t) i)) { continue; @@ -27030,8 +27780,10 @@ duk_push_u32(thr, i); duk_dup_2(thr); DUK_DDD(DUK_DDDPRINT("calling reduce function: func=%!T, prev=%!T, curr=%!T, idx=%!T, obj=%!T", - (duk_tval *) duk_get_tval(thr, -5), (duk_tval *) duk_get_tval(thr, -4), - (duk_tval *) duk_get_tval(thr, -3), (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -5), + (duk_tval *) duk_get_tval(thr, -4), + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_call(thr, 4); DUK_DDD(DUK_DDDPRINT("-> result: %!T", (duk_tval *) duk_get_tval(thr, -1))); @@ -27048,7 +27800,7 @@ return 1; } -#endif /* DUK_USE_ARRAY_BUILTIN */ +#endif /* DUK_USE_ARRAY_BUILTIN */ /* automatic undefs */ #undef DUK__ARRAY_MID_JOIN_LIMIT @@ -27099,7 +27851,7 @@ DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* never here */ - type_ok: +type_ok: if (coerce_tostring) { duk_to_string(thr, -1); } @@ -27119,14 +27871,14 @@ DUK_HOBJECT_SET_CLASS_NUMBER(h_this, DUK_HOBJECT_CLASS_BOOLEAN); - duk_dup_0(thr); /* -> val obj val */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); /* XXX: proper flags? */ - } /* unbalanced stack */ + duk_dup_0(thr); /* -> val obj val */ + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); /* XXX: proper flags? */ + } /* unbalanced stack */ return 1; } -#endif /* DUK_USE_BOOLEAN_BUILTIN */ +#endif /* DUK_USE_BOOLEAN_BUILTIN */ #line 1 "duk_bi_buffer.c" /* * ES2015 TypedArray and Node.js Buffer built-ins @@ -27143,57 +27895,38 @@ * default internal prototype. */ static const duk_uint8_t duk__buffer_proto_from_classnum = { - DUK_BIDX_ARRAYBUFFER_PROTOTYPE, - DUK_BIDX_DATAVIEW_PROTOTYPE, - DUK_BIDX_INT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, - DUK_BIDX_INT16ARRAY_PROTOTYPE, - DUK_BIDX_UINT16ARRAY_PROTOTYPE, - DUK_BIDX_INT32ARRAY_PROTOTYPE, - DUK_BIDX_UINT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT64ARRAY_PROTOTYPE + DUK_BIDX_ARRAYBUFFER_PROTOTYPE, DUK_BIDX_DATAVIEW_PROTOTYPE, DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_BIDX_INT16ARRAY_PROTOTYPE, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE }; /* Map DUK_HBUFOBJ_ELEM_xxx to duk_hobject class number. * Sync with duk_hbufobj.h and duk_hobject.h. */ -static const duk_uint8_t duk__buffer_class_from_elemtype9 = { - DUK_HOBJECT_CLASS_UINT8ARRAY, - DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, - DUK_HOBJECT_CLASS_INT8ARRAY, - DUK_HOBJECT_CLASS_UINT16ARRAY, - DUK_HOBJECT_CLASS_INT16ARRAY, - DUK_HOBJECT_CLASS_UINT32ARRAY, - DUK_HOBJECT_CLASS_INT32ARRAY, - DUK_HOBJECT_CLASS_FLOAT32ARRAY, - DUK_HOBJECT_CLASS_FLOAT64ARRAY -}; +static const duk_uint8_t duk__buffer_class_from_elemtype9 = { DUK_HOBJECT_CLASS_UINT8ARRAY, DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY, + DUK_HOBJECT_CLASS_INT8ARRAY, DUK_HOBJECT_CLASS_UINT16ARRAY, + DUK_HOBJECT_CLASS_INT16ARRAY, DUK_HOBJECT_CLASS_UINT32ARRAY, + DUK_HOBJECT_CLASS_INT32ARRAY, DUK_HOBJECT_CLASS_FLOAT32ARRAY, + DUK_HOBJECT_CLASS_FLOAT64ARRAY }; /* Map DUK_HBUFOBJ_ELEM_xxx to prototype object built-in index. * Sync with duk_hbufobj.h. */ static const duk_uint8_t duk__buffer_proto_from_elemtype9 = { - DUK_BIDX_UINT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, - DUK_BIDX_INT8ARRAY_PROTOTYPE, - DUK_BIDX_UINT16ARRAY_PROTOTYPE, - DUK_BIDX_INT16ARRAY_PROTOTYPE, - DUK_BIDX_UINT32ARRAY_PROTOTYPE, - DUK_BIDX_INT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, - DUK_BIDX_FLOAT64ARRAY_PROTOTYPE + DUK_BIDX_UINT8ARRAY_PROTOTYPE, DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE, DUK_BIDX_INT8ARRAY_PROTOTYPE, + DUK_BIDX_UINT16ARRAY_PROTOTYPE, DUK_BIDX_INT16ARRAY_PROTOTYPE, DUK_BIDX_UINT32ARRAY_PROTOTYPE, + DUK_BIDX_INT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT32ARRAY_PROTOTYPE, DUK_BIDX_FLOAT64ARRAY_PROTOTYPE }; /* Map DUK__FLD_xxx to byte size. */ static const duk_uint8_t duk__buffer_nbytes_from_fldtype6 = { - 1, /* DUK__FLD_8BIT */ - 2, /* DUK__FLD_16BIT */ - 4, /* DUK__FLD_32BIT */ - 4, /* DUK__FLD_FLOAT */ - 8, /* DUK__FLD_DOUBLE */ - 0 /* DUK__FLD_VARINT; not relevant here */ + 1, /* DUK__FLD_8BIT */ + 2, /* DUK__FLD_16BIT */ + 4, /* DUK__FLD_32BIT */ + 4, /* DUK__FLD_FLOAT */ + 8, /* DUK__FLD_DOUBLE */ + 0 /* DUK__FLD_VARINT; not relevant here */ }; /* Bitfield for each DUK_HBUFOBJ_ELEM_xxx indicating which element types @@ -27205,36 +27938,27 @@ #if !defined(DUK_USE_PREFER_SIZE) static duk_uint16_t duk__buffer_elemtype_copy_compatible9 = { /* xxx -> DUK_HBUFOBJ_ELEM_UINT8 */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | - (1U << DUK_HBUFOBJ_ELEM_INT8), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | (1U << DUK_HBUFOBJ_ELEM_INT8), /* xxx -> DUK_HBUFOBJ_ELEM_UINT8CLAMPED * Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00. */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED), /* xxx -> DUK_HBUFOBJ_ELEM_INT8 */ - (1U << DUK_HBUFOBJ_ELEM_UINT8) | - (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | - (1U << DUK_HBUFOBJ_ELEM_INT8), + (1U << DUK_HBUFOBJ_ELEM_UINT8) | (1U << DUK_HBUFOBJ_ELEM_UINT8CLAMPED) | (1U << DUK_HBUFOBJ_ELEM_INT8), /* xxx -> DUK_HBUFOBJ_ELEM_UINT16 */ - (1U << DUK_HBUFOBJ_ELEM_UINT16) | - (1U << DUK_HBUFOBJ_ELEM_INT16), + (1U << DUK_HBUFOBJ_ELEM_UINT16) | (1U << DUK_HBUFOBJ_ELEM_INT16), /* xxx -> DUK_HBUFOBJ_ELEM_INT16 */ - (1U << DUK_HBUFOBJ_ELEM_UINT16) | - (1U << DUK_HBUFOBJ_ELEM_INT16), + (1U << DUK_HBUFOBJ_ELEM_UINT16) | (1U << DUK_HBUFOBJ_ELEM_INT16), /* xxx -> DUK_HBUFOBJ_ELEM_UINT32 */ - (1U << DUK_HBUFOBJ_ELEM_UINT32) | - (1U << DUK_HBUFOBJ_ELEM_INT32), + (1U << DUK_HBUFOBJ_ELEM_UINT32) | (1U << DUK_HBUFOBJ_ELEM_INT32), /* xxx -> DUK_HBUFOBJ_ELEM_INT32 */ - (1U << DUK_HBUFOBJ_ELEM_UINT32) | - (1U << DUK_HBUFOBJ_ELEM_INT32), + (1U << DUK_HBUFOBJ_ELEM_UINT32) | (1U << DUK_HBUFOBJ_ELEM_INT32), /* xxx -> DUK_HBUFOBJ_ELEM_FLOAT32 */ (1U << DUK_HBUFOBJ_ELEM_FLOAT32), @@ -27242,7 +27966,7 @@ /* xxx -> DUK_HBUFOBJ_ELEM_FLOAT64 */ (1U << DUK_HBUFOBJ_ELEM_FLOAT64) }; -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ DUK_LOCAL duk_hbufobj *duk__hbufobj_promote_this(duk_hthread *thr) { duk_tval *tv_dst; @@ -27261,8 +27985,8 @@ return res; } -#define DUK__BUFOBJ_FLAG_THROW (1 << 0) -#define DUK__BUFOBJ_FLAG_PROMOTE (1 << 1) +#define DUK__BUFOBJ_FLAG_THROW (1 << 0) +#define DUK__BUFOBJ_FLAG_PROMOTE (1 << 1) /* Shared helper. When DUK__BUFOBJ_FLAG_PROMOTE is given, the return value is * always a duk_hbufobj *. Without the flag the return value can also be a @@ -27353,7 +28077,7 @@ DUK_LOCAL void duk__set_bufobj_buffer(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_hbuffer *h_val) { DUK_ASSERT(thr != NULL); DUK_ASSERT(h_bufobj != NULL); - DUK_ASSERT(h_bufobj->buf == NULL); /* no need to decref */ + DUK_ASSERT(h_bufobj->buf == NULL); /* no need to decref */ DUK_ASSERT(h_val != NULL); DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); DUK_UNREF(thr); @@ -27389,12 +28113,12 @@ if (offset > h_bufarg->length) { goto fail_range; } - DUK_ASSERT_DISABLE(offset >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(offset >= 0); /* unsigned */ DUK_ASSERT(offset <= h_bufarg->length); if (duk_is_undefined(thr, idx_length)) { DUK_ASSERT(h_bufarg->length >= offset); - length = h_bufarg->length - offset; /* >= 0 */ + length = h_bufarg->length - offset; /* >= 0 */ } else { length_signed = duk_to_int(thr, idx_length); if (length_signed < 0) { @@ -27413,14 +28137,14 @@ } } } - DUK_ASSERT_DISABLE(length >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(length >= 0); /* unsigned */ DUK_ASSERT(offset + length <= h_bufarg->length); *out_offset = offset; *out_length = length; return; - fail_range: +fail_range: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARGS); DUK_WO_NORETURN(return;); } @@ -27478,7 +28202,7 @@ DUK_ASSERT(out_start_offset != NULL); DUK_ASSERT(out_end_offset != NULL); - buffer_length >>= buffer_shift; /* as (full) elements */ + buffer_length >>= buffer_shift; /* as (full) elements */ /* Resolve start/end offset as element indices first; arguments * at idx_start/idx_end are element offsets. Working with element @@ -27570,7 +28294,10 @@ } /* Indexed read helper for buffer objects, also called from outside this file. */ -DUK_INTERNAL void duk_hbufobj_push_validated_read(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size) { +DUK_INTERNAL void duk_hbufobj_push_validated_read(duk_hthread *thr, + duk_hbufobj *h_bufobj, + duk_uint8_t *p, + duk_small_uint_t elem_size) { duk_double_union du; DUK_ASSERT(elem_size > 0); @@ -27718,17 +28445,17 @@ DUK_WO_NORETURN(return NULL;); } - done: +done: DUK_ASSERT(duk_is_buffer(thr, -1)); return duk_known_hbuffer(thr, -1); - slow_copy: +slow_copy: /* XXX: fast path for typed arrays and other buffer objects? */ (void) duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_LENGTH); len = duk_to_int_clamped(thr, -1, 0, DUK_INT_MAX); duk_pop(thr); - buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) len); /* no zeroing, all indices get initialized */ + buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) len); /* no zeroing, all indices get initialized */ for (i = 0; i < len; i++) { /* XXX: fast path for array or buffer arguments? */ duk_get_prop_index(thr, 0, (duk_uarridx_t) i); @@ -27737,7 +28464,7 @@ } goto done; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer constructor @@ -27754,11 +28481,7 @@ h_buf = duk__hbufobj_fixed_from_argvalue(thr); DUK_ASSERT(h_buf != NULL); - duk_push_buffer_object(thr, - -1, - 0, - DUK_HBUFFER_FIXED_GET_SIZE((duk_hbuffer_fixed *) (void *) h_buf), - DUK_BUFOBJ_UINT8ARRAY); + duk_push_buffer_object(thr, -1, 0, DUK_HBUFFER_FIXED_GET_SIZE((duk_hbuffer_fixed *) (void *) h_buf), DUK_BUFOBJ_UINT8ARRAY); duk_push_hobject_bidx(thr, DUK_BIDX_NODEJS_BUFFER_PROTOTYPE); duk_set_prototype(thr, -2); @@ -27766,7 +28489,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * ArrayBuffer, DataView, and TypedArray constructors @@ -27790,9 +28513,8 @@ h_val = (duk_hbuffer *) duk_known_hbuffer(thr, -1); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), DUK_BIDX_ARRAYBUFFER_PROTOTYPE); DUK_ASSERT(h_bufobj != NULL); @@ -27801,11 +28523,10 @@ return 1; - fail_length: +fail_length: DUK_DCERROR_RANGE_INVALID_LENGTH(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ - +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Format of magic, bits: * 0...1: elem size shift (0-3) @@ -27845,8 +28566,8 @@ * element type. */ magic = (duk_small_uint_t) duk_get_current_magic(thr); - shift = magic & 0x03U; /* bits 0...1: shift */ - elem_type = (magic >> 2) & 0x0fU; /* bits 2...5: type */ + shift = magic & 0x03U; /* bits 0...1: shift */ + elem_type = (magic >> 2) & 0x0fU; /* bits 2...5: type */ elem_size = 1U << shift; align_mask = elem_size - 1; DUK_ASSERT(elem_type < sizeof(duk__buffer_proto_from_elemtype) / sizeof(duk_uint8_t)); @@ -27857,8 +28578,12 @@ DUK_DD(DUK_DDPRINT("typedarray constructor, magic=%d, shift=%d, elem_type=%d, " "elem_size=%d, proto_bidx=%d, class_num=%d", - (int) magic, (int) shift, (int) elem_type, (int) elem_size, - (int) proto_bidx, (int) class_num)); + (int) magic, + (int) shift, + (int) elem_type, + (int) elem_size, + (int) proto_bidx, + (int) class_num)); /* Argument variants. When the argument is an ArrayBuffer a view to * the same buffer is created; otherwise a new ArrayBuffer is always @@ -27872,7 +28597,7 @@ duk_hbufobj_promote_plain(thr, 0); tv = duk_get_tval(thr, 0); - DUK_ASSERT(tv != NULL); /* arg count */ + DUK_ASSERT(tv != NULL); /* arg count */ if (DUK_TVAL_IS_OBJECT(tv)) { h_obj = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(h_obj != NULL); @@ -27892,8 +28617,7 @@ goto fail_arguments; } byte_offset = (duk_uint_t) byte_offset_signed; - if (byte_offset > h_bufarg->length || - (byte_offset & align_mask) != 0) { + if (byte_offset > h_bufarg->length || (byte_offset & align_mask) != 0) { /* Must be >= 0 and multiple of element size. */ goto fail_arguments; } @@ -27933,9 +28657,8 @@ DUK_ASSERT((elem_length << shift) == byte_length); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(class_num), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(class_num), (duk_small_int_t) proto_bidx); h_val = h_bufarg->buf; if (h_val == NULL) { @@ -27978,11 +28701,13 @@ "src byte_length=%ld, src shift=%d, " "src/dst elem_length=%ld; " "dst shift=%d -> dst byte_length=%ld", - (long) h_bufarg->length, (int) h_bufarg->shift, - (long) elem_length_signed, (int) shift, + (long) h_bufarg->length, + (int) h_bufarg->shift, + (long) elem_length_signed, + (int) shift, (long) (elem_length_signed << shift))); - copy_mode = 2; /* default is explicit index read/write copy */ + copy_mode = 2; /* default is explicit index read/write copy */ #if !defined(DUK_USE_PREFER_SIZE) /* With a size optimized build copy_mode 2 is enough. * Modes 0 and 1 are faster but conceptually the same. @@ -27991,14 +28716,14 @@ if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { if ((duk__buffer_elemtype_copy_compatibleelem_type & (1 << h_bufarg->elem_type)) != 0) { DUK_DDD(DUK_DDDPRINT("source/target are copy compatible, memcpy")); - DUK_ASSERT(shift == h_bufarg->shift); /* byte sizes will match */ + DUK_ASSERT(shift == h_bufarg->shift); /* byte sizes will match */ copy_mode = 0; } else { DUK_DDD(DUK_DDDPRINT("source/target not copy compatible but valid, fast copy")); copy_mode = 1; } } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ } else { /* Array or Array-like */ elem_length_signed = (duk_int_t) duk_get_length(thr, 0); @@ -28023,8 +28748,7 @@ goto fail_arguments; } - DUK_DDD(DUK_DDDPRINT("elem_length=%ld, byte_length=%ld", - (long) elem_length, (long) byte_length)); + DUK_DDD(DUK_DDDPRINT("elem_length=%ld, byte_length=%ld", (long) elem_length, (long) byte_length)); /* ArrayBuffer argument is handled specially above; the rest of the * argument variants are handled by shared code below. @@ -28039,11 +28763,10 @@ h_val = duk_known_hbuffer(thr, -1); DUK_ASSERT(h_val != NULL); - h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(class_num), - (duk_small_int_t) proto_bidx); + h_bufobj = + duk_push_bufobj_raw(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(class_num), + (duk_small_int_t) proto_bidx); h_bufobj->buf = h_val; DUK_HBUFFER_INCREF(thr, h_val); @@ -28083,7 +28806,9 @@ p_src = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufarg); DUK_DDD(DUK_DDDPRINT("using memcpy: p_src=%p, p_dst=%p, byte_length=%ld", - (void *) p_src, (void *) p_dst, (long) byte_length)); + (void *) p_src, + (void *) p_dst, + (long) byte_length)); duk_memcpy_unsafe((void *) p_dst, (const void *) p_src, (size_t) byte_length); break; @@ -28113,13 +28838,18 @@ DUK_DDD(DUK_DDDPRINT("using fast copy: p_src=%p, p_src_end=%p, p_dst=%p, " "src_elem_size=%d, dst_elem_size=%d", - (void *) p_src, (void *) p_src_end, (void *) p_dst, - (int) src_elem_size, (int) dst_elem_size)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst, + (int) src_elem_size, + (int) dst_elem_size)); while (p_src != p_src_end) { DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: " "p_src=%p, p_src_end=%p, p_dst=%p", - (void *) p_src, (void *) p_src_end, (void *) p_dst)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst)); /* A validated read() is always a number, so it's write coercion * is always side effect free an won't invalidate pointers etc. */ @@ -28131,7 +28861,7 @@ } break; } -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ case 2: { /* Copy values by index reads and writes. Let virtual * property handling take care of coercion. @@ -28160,10 +28890,10 @@ return 1; - fail_arguments: +fail_arguments: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* When bufferobject support is disabled, new Uint8Array() could still be * supported to create a plain fixed buffer. Disabled for now. */ @@ -28190,8 +28920,8 @@ fail_arguments: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* 0 */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* 0 */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_dataview_constructor(duk_hthread *thr) { @@ -28214,9 +28944,8 @@ DUK_ASSERT(offset + length <= h_bufarg->length); h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATAVIEW), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATAVIEW), DUK_BIDX_DATAVIEW_PROTOTYPE); h_val = h_bufarg->buf; @@ -28239,7 +28968,7 @@ DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * ArrayBuffer.isView() @@ -28265,7 +28994,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Uint8Array.allocPlain() @@ -28276,7 +29005,7 @@ duk__hbufobj_fixed_from_argvalue(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Uint8Array.plainOf() @@ -28305,7 +29034,7 @@ } return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer: toString(encoding, start, end) @@ -28336,12 +29065,11 @@ &end_offset); slice_length = (duk_size_t) (end_offset - start_offset); - buf_slice = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, slice_length); /* all bytes initialized below */ + buf_slice = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, slice_length); /* all bytes initialized below */ DUK_ASSERT(buf_slice != NULL); /* Neutered or uncovered, TypeError. */ - if (h_this->buf == NULL || - !DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, (duk_size_t) start_offset + slice_length)) { + if (h_this->buf == NULL || !DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, (duk_size_t) start_offset + slice_length)) { DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -28364,7 +29092,7 @@ duk_set_top(thr, 1); return duk_textdecoder_decode_utf8_nodejs(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype: toJSON() @@ -28394,19 +29122,19 @@ /* XXX: uninitialized would be OK */ DUK_ASSERT_DISABLE((duk_size_t) h_this->length <= (duk_size_t) DUK_UINT32_MAX); - tv = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) h_this->length); /* XXX: needs revision with >4G buffers */ + tv = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) h_this->length); /* XXX: needs revision with >4G buffers */ DUK_ASSERT(!duk_is_bare_object(thr, -1)); DUK_ASSERT(h_this->buf != NULL); buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); for (i = 0, n = h_this->length; i < n; i++) { - DUK_TVAL_SET_U32(tv + i, (duk_uint32_t) bufi); /* no need for decref or incref */ + DUK_TVAL_SET_U32(tv + i, (duk_uint32_t) bufi); /* no need for decref or incref */ } duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_DATA); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.equals() @@ -28441,14 +29169,14 @@ * matters is to be memory safe. */ - if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg1) && - DUK_HBUFOBJ_VALID_SLICE(h_bufarg2)) { - comp_res = duk_js_data_compare((const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg1->buf) + h_bufarg1->offset, - (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg2->buf) + h_bufarg2->offset, - (duk_size_t) h_bufarg1->length, - (duk_size_t) h_bufarg2->length); + if (DUK_HBUFOBJ_VALID_SLICE(h_bufarg1) && DUK_HBUFOBJ_VALID_SLICE(h_bufarg2)) { + comp_res = duk_js_data_compare( + (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg1->buf) + h_bufarg1->offset, + (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufarg2->buf) + h_bufarg2->offset, + (duk_size_t) h_bufarg1->length, + (duk_size_t) h_bufarg2->length); } else { - comp_res = -1; /* either nonzero value is ok */ + comp_res = -1; /* either nonzero value is ok */ } if (magic & 0x01U) { @@ -28461,7 +29189,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.fill() @@ -28506,7 +29234,10 @@ &fill_end); DUK_DDD(DUK_DDDPRINT("fill: fill_value=%02x, fill_offset=%ld, fill_end=%ld, view length=%ld", - (unsigned int) fill_value, (long) fill_offset, (long) fill_end, (long) h_this->length)); + (unsigned int) fill_value, + (long) fill_offset, + (long) fill_end, + (long) h_this->length)); DUK_ASSERT(fill_end - fill_offset >= 0); DUK_ASSERT(h_this->buf != NULL); @@ -28535,7 +29266,7 @@ duk_push_this(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.write(string, offset, length, encoding) @@ -28578,7 +29309,7 @@ duk_push_uint(thr, length); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.copy() @@ -28613,8 +29344,11 @@ DUK_DDD(DUK_DDDPRINT("checking copy args: target_start=%ld, target_length=%ld, " "source_start=%ld, source_end=%ld, source_length=%ld", - (long) target_start, (long) h_bufarg->length, - (long) source_start, (long) source_end, (long) source_length)); + (long) target_start, + (long) h_bufarg->length, + (long) source_start, + (long) source_end, + (long) source_length)); /* This behavior mostly mimics Node.js now. */ @@ -28625,9 +29359,9 @@ source_ustart = (duk_uint_t) source_start; source_uend = (duk_uint_t) source_end; target_ustart = (duk_uint_t) target_start; - if (source_ustart >= source_uend || /* crossed offsets or zero size */ - source_ustart >= (duk_uint_t) source_length || /* source out-of-bounds (but positive) */ - target_ustart >= (duk_uint_t) target_length) { /* target out-of-bounds (but positive) */ + if (source_ustart >= source_uend || /* crossed offsets or zero size */ + source_ustart >= (duk_uint_t) source_length || /* source out-of-bounds (but positive) */ + target_ustart >= (duk_uint_t) target_length) { /* target out-of-bounds (but positive) */ goto silent_ignore; } if (source_uend >= (duk_uint_t) source_length) { @@ -28643,13 +29377,14 @@ * values in duk_int_t range. Adding them as duk_uint_t * values is then guaranteed not to overflow. */ - DUK_ASSERT(target_ustart + copy_size >= target_ustart); /* no overflow */ - DUK_ASSERT(target_ustart + copy_size >= copy_size); /* no overflow */ + DUK_ASSERT(target_ustart + copy_size >= target_ustart); /* no overflow */ + DUK_ASSERT(target_ustart + copy_size >= copy_size); /* no overflow */ copy_size = (duk_uint_t) target_length - target_ustart; } DUK_DDD(DUK_DDDPRINT("making copy: target_ustart=%lu source_ustart=%lu copy_size=%lu", - (unsigned long) target_ustart, (unsigned long) source_ustart, + (unsigned long) target_ustart, + (unsigned long) source_ustart, (unsigned long) copy_size)); DUK_ASSERT(copy_size >= 1); @@ -28659,8 +29394,8 @@ DUK_ASSERT(target_ustart + copy_size <= (duk_uint_t) target_length); /* Ensure copy is covered by underlying buffers. */ - DUK_ASSERT(h_bufarg->buf != NULL); /* length check */ - DUK_ASSERT(h_this->buf != NULL); /* length check */ + DUK_ASSERT(h_bufarg->buf != NULL); /* length check */ + DUK_ASSERT(h_this->buf != NULL); /* length check */ if (DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufarg, target_ustart + copy_size) && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_this, source_ustart + copy_size)) { /* Must use memmove() because copy area may overlap (source and target @@ -28673,18 +29408,18 @@ DUK_DDD(DUK_DDDPRINT("buffer copy not covered by underlying buffer(s), ignoring")); } - silent_ignore: +silent_ignore: /* Return value is like write(), number of bytes written. * The return value matters because of code like: * "off += buf.copy(...)". - */ + */ duk_push_uint(thr, copy_size); return 1; - fail_bounds: +fail_bounds: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * TypedArray.prototype.set() @@ -28796,16 +29531,15 @@ } /* Nominal size check. */ - src_length = h_bufarg->length; /* bytes in source */ - dst_length_elems = (src_length >> h_bufarg->shift); /* elems in source and dest */ - dst_length = dst_length_elems << h_this->shift; /* bytes in dest */ + src_length = h_bufarg->length; /* bytes in source */ + dst_length_elems = (src_length >> h_bufarg->shift); /* elems in source and dest */ + dst_length = dst_length_elems << h_this->shift; /* bytes in dest */ if ((dst_length >> h_this->shift) != dst_length_elems) { /* Byte length would overflow. */ /* XXX: easier check with less code? */ goto fail_args; } - DUK_DDD(DUK_DDDPRINT("nominal size check: src_length=%ld, dst_length=%ld", - (long) src_length, (long) dst_length)); + DUK_DDD(DUK_DDDPRINT("nominal size check: src_length=%ld, dst_length=%ld", (long) src_length, (long) dst_length)); DUK_ASSERT(offset_bytes <= h_this->length); if (dst_length > h_this->length - offset_bytes) { /* Overflow not an issue because subtraction is used on the right @@ -28826,8 +29560,7 @@ * cover the copy. No side effects are allowed after the check * so that the validity status doesn't change. */ - if (!DUK_HBUFOBJ_VALID_SLICE(h_this) || - !DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { + if (!DUK_HBUFOBJ_VALID_SLICE(h_this) || !DUK_HBUFOBJ_VALID_SLICE(h_bufarg)) { /* The condition could be more narrow and check for the * copy area only, but there's no need for fine grained * behavior when the underlying buffer is misconfigured. @@ -28858,7 +29591,7 @@ return 0; } DUK_DDD(DUK_DDDPRINT("fast path: views are not compatible with a byte copy, copy by item")); -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ /* We want to avoid making a copy to process set() but that's * not always possible: the source and the target may overlap @@ -28878,11 +29611,13 @@ DUK_DDD(DUK_DDDPRINT("overlap check: p_src_base=%p, src_length=%ld, " "p_dst_base=%p, dst_length=%ld", - (void *) p_src_base, (long) src_length, - (void *) p_dst_base, (long) dst_length)); + (void *) p_src_base, + (long) src_length, + (void *) p_dst_base, + (long) dst_length)); - if (p_src_base >= p_dst_base + dst_length || /* source starts after dest ends */ - p_src_base + src_length <= p_dst_base) { /* source ends before dest starts */ + if (p_src_base >= p_dst_base + dst_length || /* source starts after dest ends */ + p_src_base + src_length <= p_dst_base) { /* source ends before dest starts */ no_overlap = 1; } @@ -28899,14 +29634,16 @@ DUK_ASSERT(p_src_copy != NULL); duk_memcpy_unsafe((void *) p_src_copy, (const void *) p_src_base, (size_t) src_length); - p_src_base = p_src_copy; /* use p_src_base from now on */ + p_src_base = p_src_copy; /* use p_src_base from now on */ } /* Value stack intentionally mixed size here. */ DUK_DDD(DUK_DDDPRINT("after overlap check: p_src_base=%p, src_length=%ld, " "p_dst_base=%p, dst_length=%ld, valstack top=%ld", - (void *) p_src_base, (long) src_length, - (void *) p_dst_base, (long) dst_length, + (void *) p_src_base, + (long) src_length, + (void *) p_dst_base, + (long) dst_length, (long) duk_get_top(thr))); /* Ready to make the copy. We must proceed element by element @@ -28926,7 +29663,9 @@ while (p_src != p_src_end) { DUK_DDD(DUK_DDDPRINT("fast path per element copy loop: " "p_src=%p, p_src_end=%p, p_dst=%p", - (void *) p_src, (void *) p_src_end, (void *) p_dst)); + (void *) p_src, + (void *) p_src_end, + (void *) p_dst)); /* A validated read() is always a number, so it's write coercion * is always side effect free an won't invalidate pointers etc. */ @@ -28976,10 +29715,10 @@ return 0; - fail_args: +fail_args: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.prototype.slice(start, end) @@ -29074,7 +29813,7 @@ /* fall through */ } } - tv = NULL; /* No longer valid nor needed. */ + tv = NULL; /* No longer valid nor needed. */ h_this = duk__require_bufobj_this(thr); @@ -29112,22 +29851,21 @@ * be an Uint8Array but inherit from Buffer.prototype. */ res_class_num = DUK_HOBJECT_GET_CLASS_NUMBER((duk_hobject *) h_this); - DUK_ASSERT(res_class_num >= DUK_HOBJECT_CLASS_BUFOBJ_MIN); /* type check guarantees */ + DUK_ASSERT(res_class_num >= DUK_HOBJECT_CLASS_BUFOBJ_MIN); /* type check guarantees */ DUK_ASSERT(res_class_num <= DUK_HOBJECT_CLASS_BUFOBJ_MAX); res_proto_bidx = duk__buffer_proto_from_classnumres_class_num - DUK_HOBJECT_CLASS_BUFOBJ_MIN; if (magic & 0x04) { res_proto_bidx = DUK_BIDX_NODEJS_BUFFER_PROTOTYPE; } - h_bufobj = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(res_class_num), - res_proto_bidx); + h_bufobj = + duk_push_bufobj_raw(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(res_class_num), + res_proto_bidx); DUK_ASSERT(h_bufobj != NULL); DUK_ASSERT(h_bufobj->length == 0); - h_bufobj->shift = h_this->shift; /* inherit */ - h_bufobj->elem_type = h_this->elem_type; /* inherit */ + h_bufobj->shift = h_this->shift; /* inherit */ + h_bufobj->elem_type = h_this->elem_type; /* inherit */ h_bufobj->is_typedarray = magic & 0x01; DUK_ASSERT(h_bufobj->is_typedarray == 0 || h_bufobj->is_typedarray == 1); @@ -29141,7 +29879,9 @@ duk_uint8_t *p_copy; duk_size_t copy_length; - p_copy = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, (duk_size_t) slice_length); /* must be zeroed, not all bytes always copied */ + p_copy = (duk_uint8_t *) duk_push_fixed_buffer_zero( + thr, + (duk_size_t) slice_length); /* must be zeroed, not all bytes always copied */ DUK_ASSERT(p_copy != NULL); /* Copy slice, respecting underlying buffer limits; remainder @@ -29159,7 +29899,7 @@ h_bufobj->length = slice_length; DUK_ASSERT(h_bufobj->offset == 0); - duk_pop(thr); /* reachable so pop OK */ + duk_pop(thr); /* reachable so pop OK */ } else { h_bufobj->buf = h_val; DUK_HBUFFER_INCREF(thr, h_val); @@ -29172,7 +29912,7 @@ */ DUK_ASSERT(h_bufobj->buf_prop == NULL); - h_bufobj->buf_prop = h_this->buf_prop; /* may be NULL */ + h_bufobj->buf_prop = h_this->buf_prop; /* may be NULL */ DUK_HOBJECT_INCREF_ALLOWNULL(thr, (duk_hobject *) h_bufobj->buf_prop); } /* unbalanced stack on purpose */ @@ -29180,7 +29920,7 @@ DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.isEncoding() @@ -29193,11 +29933,11 @@ /* only accept lowercase 'utf8' now. */ encoding = duk_to_string(thr, 0); - DUK_ASSERT(duk_is_string(thr, 0)); /* guaranteed by duk_to_string() */ + DUK_ASSERT(duk_is_string(thr, 0)); /* guaranteed by duk_to_string() */ duk_push_boolean(thr, DUK_STRCMP(encoding, "utf8") == 0); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.isBuffer() @@ -29209,7 +29949,7 @@ duk_hobject *h_proto; duk_bool_t ret = 0; - DUK_ASSERT(duk_get_top(thr) >= 1); /* nargs */ + DUK_ASSERT(duk_get_top(thr) >= 1); /* nargs */ h = duk_get_hobject(thr, 0); if (h != NULL) { h_proto = thr->builtinsDUK_BIDX_NODEJS_BUFFER_PROTOTYPE; @@ -29224,7 +29964,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.byteLength() @@ -29255,7 +29995,7 @@ duk_push_size_t(thr, len); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Node.js Buffer.concat() @@ -29286,13 +30026,13 @@ /* Neutered checks not necessary here: neutered buffers have * zero 'length' so we'll effectively skip them. */ - DUK_ASSERT_TOP(thr, 2); /* array totalLength */ - duk_get_prop_index(thr, 0, (duk_uarridx_t) i); /* -> array totalLength buf */ + DUK_ASSERT_TOP(thr, 2); /* array totalLength */ + duk_get_prop_index(thr, 0, (duk_uarridx_t) i); /* -> array totalLength buf */ h_bufobj = duk__require_bufobj_value(thr, 2); DUK_ASSERT(h_bufobj != NULL); total_length += h_bufobj->length; if (DUK_UNLIKELY(total_length < h_bufobj->length)) { - DUK_DCERROR_RANGE_INVALID_ARGS(thr); /* Wrapped. */ + DUK_DCERROR_RANGE_INVALID_ARGS(thr); /* Wrapped. */ } duk_pop(thr); } @@ -29318,18 +30058,18 @@ } h_bufres = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_UINT8ARRAY), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_UINT8ARRAY), DUK_BIDX_NODEJS_BUFFER_PROTOTYPE); DUK_ASSERT(h_bufres != NULL); - p = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, total_length); /* must be zeroed, all bytes not necessarily written over */ + p = (duk_uint8_t *) duk_push_fixed_buffer_zero(thr, + total_length); /* must be zeroed, all bytes not necessarily written over */ DUK_ASSERT(p != NULL); space_left = (duk_size_t) total_length; for (i = 0; i < n; i++) { - DUK_ASSERT_TOP(thr, 4); /* array totalLength bufres buf */ + DUK_ASSERT_TOP(thr, 4); /* array totalLength bufres buf */ duk_get_prop_index(thr, 0, (duk_uarridx_t) i); h_bufobj = duk__require_bufobj_value(thr, 4); @@ -29340,11 +30080,8 @@ copy_size = space_left; } - if (h_bufobj->buf != NULL && - DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { - duk_memcpy_unsafe((void *) p, - (const void *) DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj), - copy_size); + if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) { + duk_memcpy_unsafe((void *) p, (const void *) DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_bufobj), copy_size); } else { /* Just skip, leaving zeroes in the result. */ ; @@ -29361,11 +30098,11 @@ h_bufres->is_typedarray = 1; DUK_HBUFOBJ_ASSERT_VALID(h_bufres); - duk_pop(thr); /* pop plain buffer, now reachable through h_bufres */ + duk_pop(thr); /* pop plain buffer, now reachable through h_bufres */ - return 1; /* return h_bufres */ + return 1; /* return h_bufres */ } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Shared readfield and writefield methods @@ -29381,15 +30118,15 @@ * 4: signed: 1=yes, 0=no * 5: typedarray: 1=yes, 0=no */ -#define DUK__FLD_8BIT 0 -#define DUK__FLD_16BIT 1 -#define DUK__FLD_32BIT 2 -#define DUK__FLD_FLOAT 3 -#define DUK__FLD_DOUBLE 4 -#define DUK__FLD_VARINT 5 -#define DUK__FLD_BIGENDIAN (1 << 3) -#define DUK__FLD_SIGNED (1 << 4) -#define DUK__FLD_TYPEDARRAY (1 << 5) +#define DUK__FLD_8BIT 0 +#define DUK__FLD_16BIT 1 +#define DUK__FLD_32BIT 2 +#define DUK__FLD_FLOAT 3 +#define DUK__FLD_DOUBLE 4 +#define DUK__FLD_VARINT 5 +#define DUK__FLD_BIGENDIAN (1 << 3) +#define DUK__FLD_SIGNED (1 << 4) +#define DUK__FLD_TYPEDARRAY (1 << 5) /* XXX: split into separate functions for each field type? */ DUK_INTERNAL duk_ret_t duk_bi_buffer_readfield(duk_hthread *thr) { @@ -29413,7 +30150,7 @@ magic_signed = magic & 0x0010U; magic_typedarray = magic & 0x0020U; - h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ + h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ DUK_ASSERT(h_this != NULL); buffer_length = h_this->length; @@ -29425,9 +30162,9 @@ if (magic_typedarray) { no_assert = 0; #if defined(DUK_USE_INTEGER_LE) - endswap = !duk_to_boolean(thr, 1); /* 1=little endian */ + endswap = !duk_to_boolean(thr, 1); /* 1=little endian */ #else - endswap = duk_to_boolean(thr, 1); /* 1=little endian */ + endswap = duk_to_boolean(thr, 1); /* 1=little endian */ #endif } else { no_assert = duk_to_boolean(thr, (magic_ftype == DUK__FLD_VARINT) ? 2 : 1); @@ -29451,17 +30188,21 @@ DUK_DDD(DUK_DDDPRINT("readfield, buffer_length=%ld, offset=%ld, no_assert=%d, " "magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, " "endswap=%u", - (long) buffer_length, (long) offset, (int) no_assert, - (unsigned int) magic, (int) magic_ftype, (int) (magic_bigendian >> 3), - (int) (magic_signed >> 4), (int) endswap)); + (long) buffer_length, + (long) offset, + (int) no_assert, + (unsigned int) magic, + (int) magic_ftype, + (int) (magic_bigendian >> 3), + (int) (magic_signed >> 4), + (int) endswap)); /* Update 'buffer_length' to be the effective, safe limit which * takes into account the underlying buffer. This value will be * potentially invalidated by any side effect. */ check_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, buffer_length); - DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", - (long) buffer_length, (long) check_length)); + DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", (long) buffer_length, (long) check_length)); if (h_this->buf) { buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); @@ -29563,7 +30304,7 @@ #endif const duk_uint8_t *p; - field_bytelen = duk_get_int(thr, 1); /* avoid side effects! */ + field_bytelen = duk_get_int(thr, 1); /* avoid side effects! */ if (field_bytelen < 1 || field_bytelen > 6) { goto fail_field_length; } @@ -29581,12 +30322,12 @@ /* Gather in big endian */ i = 0; i_step = 1; - i_end = field_bytelen; /* one i_step over */ + i_end = field_bytelen; /* one i_step over */ } else { /* Gather in little endian */ i = field_bytelen - 1; i_step = -1; - i_end = -1; /* one i_step over */ + i_end = -1; /* one i_step over */ } #if defined(DUK_USE_64BIT_OPS) @@ -29628,16 +30369,16 @@ #endif break; } - default: { /* should never happen but default here */ + default: { /* should never happen but default here */ goto fail_bounds; } } return 1; - fail_neutered: - fail_field_length: - fail_bounds: +fail_neutered: +fail_field_length: +fail_bounds: if (no_assert) { /* Node.js return value for noAssert out-of-bounds reads is * usually (but not always) NaN. Return NaN consistently. @@ -29647,7 +30388,7 @@ } DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) /* XXX: split into separate functions for each field type? */ @@ -29674,7 +30415,7 @@ magic_typedarray = magic & 0x0020U; DUK_UNREF(magic_signed); - h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ + h_this = duk__require_bufobj_this(thr); /* XXX: very inefficient for plain buffers */ DUK_ASSERT(h_this != NULL); buffer_length = h_this->length; @@ -29686,11 +30427,11 @@ if (magic_typedarray) { no_assert = 0; #if defined(DUK_USE_INTEGER_LE) - endswap = !duk_to_boolean(thr, 2); /* 1=little endian */ + endswap = !duk_to_boolean(thr, 2); /* 1=little endian */ #else - endswap = duk_to_boolean(thr, 2); /* 1=little endian */ + endswap = duk_to_boolean(thr, 2); /* 1=little endian */ #endif - duk_swap(thr, 0, 1); /* offset/value order different from Node.js */ + duk_swap(thr, 0, 1); /* offset/value order different from Node.js */ } else { no_assert = duk_to_boolean(thr, (magic_ftype == DUK__FLD_VARINT) ? 3 : 2); #if defined(DUK_USE_INTEGER_LE) @@ -29729,9 +30470,15 @@ DUK_DDD(DUK_DDDPRINT("writefield, value=%!T, buffer_length=%ld, offset=%ld, no_assert=%d, " "magic=%04x, magic_fieldtype=%d, magic_bigendian=%d, magic_signed=%d, " "endswap=%u", - duk_get_tval(thr, 0), (long) buffer_length, (long) offset, (int) no_assert, - (unsigned int) magic, (int) magic_ftype, (int) (magic_bigendian >> 3), - (int) (magic_signed >> 4), (int) endswap)); + duk_get_tval(thr, 0), + (long) buffer_length, + (long) offset, + (int) no_assert, + (unsigned int) magic, + (int) magic_ftype, + (int) (magic_bigendian >> 3), + (int) (magic_signed >> 4), + (int) endswap)); /* Coerce value to a number before computing check_length, so that * the field type specific coercion below can't have side effects @@ -29744,8 +30491,7 @@ * potentially invalidated by any side effect. */ check_length = DUK_HBUFOBJ_CLAMP_BYTELENGTH(h_this, buffer_length); - DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", - (long) buffer_length, (long) check_length)); + DUK_DDD(DUK_DDDPRINT("buffer_length=%ld, check_length=%ld", (long) buffer_length, (long) check_length)); if (h_this->buf) { buf = DUK_HBUFOBJ_GET_SLICE_BASE(thr->heap, h_this); @@ -29848,12 +30594,12 @@ if (magic_bigendian) { /* Write in big endian */ - i = field_bytelen; /* one i_step added at top of loop */ + i = field_bytelen; /* one i_step added at top of loop */ i_step = -1; i_end = 0; } else { /* Write in little endian */ - i = -1; /* one i_step added at top of loop */ + i = -1; /* one i_step added at top of loop */ i_step = 1; i_end = field_bytelen - 1; } @@ -29871,7 +30617,7 @@ i += i_step; DUK_ASSERT(i >= 0 && i < field_bytelen); pi = (duk_uint8_t) (tmp & 0xff); - tmp = tmp >> 8; /* unnecessary shift for last byte */ + tmp = tmp >> 8; /* unnecessary shift for last byte */ } while (i != i_end); #else tmp = duk_to_number(thr, 0); @@ -29881,12 +30627,12 @@ tmp = DUK_FLOOR(tmp); DUK_ASSERT(i >= 0 && i < field_bytelen); pi = (duk_uint8_t) (DUK_FMOD(tmp, 256.0)); - tmp = tmp / 256.0; /* unnecessary div for last byte */ + tmp = tmp / 256.0; /* unnecessary div for last byte */ } while (i != i_end); #endif break; } - default: { /* should never happen but default here */ + default: { /* should never happen but default here */ goto fail_bounds; } } @@ -29903,9 +30649,9 @@ duk_push_uint(thr, offset + (duk_uint_t) nbytes); return 1; - fail_neutered: - fail_field_length: - fail_bounds: +fail_neutered: +fail_field_length: +fail_bounds: if (no_assert) { /* Node.js return value for failed writes is offset + #bytes * that would have been written. @@ -29921,7 +30667,7 @@ } DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * Accessors for .buffer, .byteLength, .byteOffset @@ -29932,9 +30678,8 @@ duk_hbufobj *h_res; h_res = duk_push_bufobj_raw(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_BUFOBJ | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_BUFOBJ | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARRAYBUFFER), DUK_BIDX_ARRAYBUFFER_PROTOTYPE); DUK_ASSERT(h_res != NULL); DUK_UNREF(h_res); @@ -29974,13 +30719,13 @@ * matches view0. */ h_arrbuf->offset = 0; - DUK_ASSERT(h_bufobj->offset + h_bufobj->length >= h_bufobj->offset); /* Wrap check on creation. */ + DUK_ASSERT(h_bufobj->offset + h_bufobj->length >= h_bufobj->offset); /* Wrap check on creation. */ h_arrbuf->length = h_bufobj->offset + h_bufobj->length; DUK_ASSERT(h_arrbuf->buf_prop == NULL); DUK_ASSERT(h_bufobj->buf_prop == NULL); h_bufobj->buf_prop = (duk_hobject *) h_arrbuf; - DUK_HBUFOBJ_INCREF(thr, h_arrbuf); /* Now reachable and accounted for. */ + DUK_HBUFOBJ_INCREF(thr, h_arrbuf); /* Now reachable and accounted for. */ } /* Left on stack; pushed for the second time below (OK). */ @@ -30018,7 +30763,7 @@ duk_hbuffer *h_buf; h_buf = (duk_hbuffer *) h_bufobj; - DUK_ASSERT(DUK_HBUFFER_GET_SIZE(h_buf) <= DUK_UINT_MAX); /* Buffer limits. */ + DUK_ASSERT(DUK_HBUFFER_GET_SIZE(h_buf) <= DUK_UINT_MAX); /* Buffer limits. */ duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_buf)); } else { /* If neutered must return 0; length is zeroed during @@ -30028,7 +30773,7 @@ } return 1; } -#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#else /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* No .buffer getter without ArrayBuffer support. */ #if 0 DUK_INTERNAL duk_ret_t duk_bi_typedarray_buffer_getter(duk_hthread *thr) { @@ -30050,7 +30795,7 @@ duk_push_uint(thr, DUK_HBUFFER_GET_SIZE(h_buf)); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* automatic undefs */ #undef DUK__BUFOBJ_FLAG_PROMOTE @@ -30261,7 +31006,7 @@ p += 8; enc_ctx->ptr = p; } -#else /* DUK_CBOR_DOUBLE_AS_IS */ +#else /* DUK_CBOR_DOUBLE_AS_IS */ DUK_LOCAL void duk__cbor_encode_double_fp(duk_cbor_encode_context *enc_ctx, double d) { duk_double_union u; duk_uint16_t u16; @@ -30296,8 +31041,7 @@ duk_bool_t use_half_float; use_half_float = - (u.uc0 == 0 && u.uc1 == 0 && u.uc2 == 0 && u.uc3 == 0 && - u.uc4 == 0 && (u.uc5 & 0x03U) == 0); + (u.uc0 == 0 && u.uc1 == 0 && u.uc2 == 0 && u.uc3 == 0 && u.uc4 == 0 && (u.uc5 & 0x03U) == 0); if (use_half_float) { duk_uint32_t t; @@ -30449,9 +31193,9 @@ /* Most important path is integers. The floor() test will be true * for Inf too (but not NaN). */ - d_floor = DUK_FLOOR(d); /* identity if d is +/- 0.0, NaN, or +/- Infinity */ + d_floor = DUK_FLOOR(d); /* identity if d is +/- 0.0, NaN, or +/- Infinity */ if (DUK_LIKELY(duk_double_equals(d_floor, d) != 0)) { - DUK_ASSERT(!DUK_ISNAN(d)); /* NaN == NaN compares false. */ + DUK_ASSERT(!DUK_ISNAN(d)); /* NaN == NaN compares false. */ if (DUK_SIGNBIT(d)) { if (d >= -4294967296.0) { d = -1.0 - d; @@ -30490,7 +31234,7 @@ DUK_ASSERT(DUK_FPCLASSIFY(d) != DUK_FP_ZERO); duk__cbor_encode_double_fp(enc_ctx, d); } -#endif /* DUK_CBOR_DOUBLE_AS_IS */ +#endif /* DUK_CBOR_DOUBLE_AS_IS */ DUK_LOCAL void duk__cbor_encode_string_top(duk_cbor_encode_context *enc_ctx) { const duk_uint8_t *str; @@ -30541,7 +31285,8 @@ #elif defined(DUK_CBOR_BYTE_STRINGS) duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, 0x40U); #else - duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, + duk__cbor_encode_uint32(enc_ctx, + (duk_uint32_t) len, (DUK_LIKELY(duk_unicode_is_utf8_compatible(str, len) != 0) ? 0x60U : 0x40U)); #endif duk__cbor_encode_ensure(enc_ctx, len); @@ -30601,14 +31346,14 @@ * indefinite length. This works well up to 23 * properties which is practical and good enough. */ - off_ib = (duk_size_t) (enc_ctx->ptr - enc_ctx->buf); /* XXX: get_offset? */ + off_ib = (duk_size_t) (enc_ctx->ptr - enc_ctx->buf); /* XXX: get_offset? */ count = 0U; p = enc_ctx->ptr; - *p++ = 0xa0U + 0x1fU; /* indefinite length */ + *p++ = 0xa0U + 0x1fU; /* indefinite length */ enc_ctx->ptr = p; duk_enum(enc_ctx->thr, -1, DUK_ENUM_OWN_PROPERTIES_ONLY); while (duk_next(enc_ctx->thr, -1, 1 /*get_value*/)) { - duk_insert(enc_ctx->thr, -2); /* ... key value -> ... value key */ + duk_insert(enc_ctx->thr, -2); /* ... key value -> ... value key */ duk__cbor_encode_value(enc_ctx); duk__cbor_encode_value(enc_ctx); count++; @@ -30623,7 +31368,7 @@ } else { duk__cbor_encode_ensure(enc_ctx, 1); p = enc_ctx->ptr; - *p++ = 0xffU; /* break */ + *p++ = 0xffU; /* break */ enc_ctx->ptr = p; } } @@ -30751,7 +31496,7 @@ duk_pop(enc_ctx->thr); return; - fail: +fail: duk__cbor_encode_error(enc_ctx); } @@ -30828,7 +31573,7 @@ } DUK_LOCAL void duk__cbor_decode_rewind(duk_cbor_decode_context *dec_ctx, duk_size_t len) { - DUK_ASSERT(len <= dec_ctx->off); /* Caller must ensure. */ + DUK_ASSERT(len <= dec_ctx->off); /* Caller must ensure. */ dec_ctx->off -= len; } @@ -30848,7 +31593,7 @@ return res; } - duk__cbor_decode_error(dec_ctx); /* Not enough input. */ + duk__cbor_decode_error(dec_ctx); /* Not enough input. */ return NULL; } @@ -30880,16 +31625,16 @@ } switch (ai) { - case 0x18U: /* 1 byte */ + case 0x18U: /* 1 byte */ t = (duk_uint32_t) duk__cbor_decode_readbyte(dec_ctx); goto shared_exit; - case 0x19U: /* 2 byte */ + case 0x19U: /* 2 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u16(dec_ctx); goto shared_exit; - case 0x1aU: /* 4 byte */ + case 0x1aU: /* 4 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); goto shared_exit; - case 0x1bU: /* 8 byte */ + case 0x1bU: /* 8 byte */ /* For uint64 it's important to handle the -1.0 part before * casting to double: otherwise the adjustment might be lost * in the cast. Uses: -1.0 - d <=> -(d + 1.0). @@ -30946,7 +31691,7 @@ * * No fastint check for this path at present. */ - d1 = (duk_double_t) t1; /* XXX: cast helpers */ + d1 = (duk_double_t) t1; /* XXX: cast helpers */ d2 = (duk_double_t) t2 * 4294967296.0; if (negative) { d1 += 1.0; @@ -30964,10 +31709,10 @@ duk__cbor_decode_error(dec_ctx); return; - shared_exit: +shared_exit: if (negative) { /* XXX: a push and check for fastint API would be nice */ - if ((duk_uint_t) t <= (duk_uint_t) -(DUK_INT_MIN + 1)) { + if ((duk_uint_t) t <= (duk_uint_t) - (DUK_INT_MIN + 1)) { duk_push_int(dec_ctx->thr, -1 - ((duk_int_t) t)); } else { duk_push_number(dec_ctx->thr, -1.0 - (duk_double_t) t); @@ -30978,10 +31723,8 @@ } DUK_LOCAL void duk__cbor_decode_skip_aival_int(duk_cbor_decode_context *dec_ctx, duk_uint8_t ib) { - const duk_int8_t skips32 = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, -1, -1, -1, -1 - }; + const duk_int8_t skips32 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, -1, -1, -1, -1 }; duk_uint8_t ai; duk_int8_t skip; @@ -31004,16 +31747,16 @@ } switch (ai) { - case 0x18U: /* 1 byte */ + case 0x18U: /* 1 byte */ t = (duk_uint32_t) duk__cbor_decode_readbyte(dec_ctx); return t; - case 0x19U: /* 2 byte */ + case 0x19U: /* 2 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u16(dec_ctx); return t; - case 0x1aU: /* 4 byte */ + case 0x1aU: /* 4 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); return t; - case 0x1bU: /* 8 byte */ + case 0x1bU: /* 8 byte */ t = (duk_uint32_t) duk__cbor_decode_read_u32(dec_ctx); if (t != 0U) { break; @@ -31047,7 +31790,7 @@ DUK_LOCAL void duk__cbor_decode_join_buffers(duk_cbor_decode_context *dec_ctx, duk_idx_t count) { duk_size_t total_size = 0; duk_idx_t top = duk_get_top(dec_ctx->thr); - duk_idx_t base = top - count; /* count is >= 1 */ + duk_idx_t base = top - count; /* count is >= 1 */ duk_idx_t idx; duk_uint8_t *p = NULL; @@ -31068,7 +31811,7 @@ p += buf_size; } else { total_size += buf_size; - if (DUK_UNLIKELY(total_size < buf_size)) { /* Wrap check. */ + if (DUK_UNLIKELY(total_size < buf_size)) { /* Wrap check. */ duk__cbor_decode_error(dec_ctx); } } @@ -31095,7 +31838,7 @@ duk_require_stack(dec_ctx->thr, 1); duk__cbor_decode_buffer(dec_ctx, expected_base); count++; - if (DUK_UNLIKELY(count <= 0)) { /* Wrap check. */ + if (DUK_UNLIKELY(count <= 0)) { /* Wrap check. */ duk__cbor_decode_error(dec_ctx); } } @@ -31143,10 +31886,10 @@ */ u.uc7 = 0x3fU; u.uc6 = 0x10U + (duk_uint8_t) ((u16 >> 6) & 0x0fU); - u.uc5 = (duk_uint8_t) ((u16 << 2) & 0xffU); /* Mask is really 0xfcU */ + u.uc5 = (duk_uint8_t) ((u16 << 2) & 0xffU); /* Mask is really 0xfcU */ duk_dblunion_little_to_host(&u); - res = u.d - 0.00006103515625; /* 2^(-14) */ + res = u.d - 0.00006103515625; /* 2^(-14) */ if (u16 & 0x8000U) { res = -res; } @@ -31245,7 +31988,7 @@ /* XXX: use bare array? */ duk_push_array(dec_ctx->thr); - for (idx = 0U; ;) { + for (idx = 0U;;) { if (len == 0xffffffffUL && duk__cbor_decode_checkbreak(dec_ctx)) { break; } @@ -31259,7 +32002,7 @@ duk_put_prop_index(dec_ctx->thr, -2, (duk_uarridx_t) idx); idx++; if (idx == 0U) { - goto failure; /* wrapped */ + goto failure; /* wrapped */ } } @@ -31269,7 +32012,7 @@ duk__cbor_decode_objarr_exit(dec_ctx); return 1; - failure: +failure: /* No need to unwind recursion checks, caller will throw. */ return 0; } @@ -31321,7 +32064,7 @@ duk__cbor_decode_objarr_exit(dec_ctx); return 1; - failure: +failure: /* No need to unwind recursion checks, caller will throw. */ return 0; } @@ -31345,7 +32088,7 @@ } #if defined(DUK_CBOR_DECODE_FASTPATH) -#define DUK__CBOR_AI (ib & 0x1fU) +#define DUK__CBOR_AI (ib & 0x1fU) DUK_LOCAL void duk__cbor_decode_value(duk_cbor_decode_context *dec_ctx) { duk_uint8_t ib; @@ -31355,7 +32098,7 @@ * here for simple paths like primitive values. */ - reread_initial_byte: +reread_initial_byte: DUK_DDD(DUK_DDDPRINT("cbor decode off=%ld len=%ld", (long) dec_ctx->off, (long) dec_ctx->len)); ib = duk__cbor_decode_readbyte(dec_ctx); @@ -31364,107 +32107,292 @@ /* XXX: Force full switch with no range check. */ switch (ib) { - case 0x00U: case 0x01U: case 0x02U: case 0x03U: case 0x04U: case 0x05U: case 0x06U: case 0x07U: - case 0x08U: case 0x09U: case 0x0aU: case 0x0bU: case 0x0cU: case 0x0dU: case 0x0eU: case 0x0fU: - case 0x10U: case 0x11U: case 0x12U: case 0x13U: case 0x14U: case 0x15U: case 0x16U: case 0x17U: + case 0x00U: + case 0x01U: + case 0x02U: + case 0x03U: + case 0x04U: + case 0x05U: + case 0x06U: + case 0x07U: + case 0x08U: + case 0x09U: + case 0x0aU: + case 0x0bU: + case 0x0cU: + case 0x0dU: + case 0x0eU: + case 0x0fU: + case 0x10U: + case 0x11U: + case 0x12U: + case 0x13U: + case 0x14U: + case 0x15U: + case 0x16U: + case 0x17U: duk_push_uint(dec_ctx->thr, ib); break; - case 0x18U: case 0x19U: case 0x1aU: case 0x1bU: + case 0x18U: + case 0x19U: + case 0x1aU: + case 0x1bU: duk__cbor_decode_push_aival_int(dec_ctx, ib, 0 /*negative*/); break; - case 0x1cU: case 0x1dU: case 0x1eU: case 0x1fU: + case 0x1cU: + case 0x1dU: + case 0x1eU: + case 0x1fU: goto format_error; - case 0x20U: case 0x21U: case 0x22U: case 0x23U: case 0x24U: case 0x25U: case 0x26U: case 0x27U: - case 0x28U: case 0x29U: case 0x2aU: case 0x2bU: case 0x2cU: case 0x2dU: case 0x2eU: case 0x2fU: - case 0x30U: case 0x31U: case 0x32U: case 0x33U: case 0x34U: case 0x35U: case 0x36U: case 0x37U: + case 0x20U: + case 0x21U: + case 0x22U: + case 0x23U: + case 0x24U: + case 0x25U: + case 0x26U: + case 0x27U: + case 0x28U: + case 0x29U: + case 0x2aU: + case 0x2bU: + case 0x2cU: + case 0x2dU: + case 0x2eU: + case 0x2fU: + case 0x30U: + case 0x31U: + case 0x32U: + case 0x33U: + case 0x34U: + case 0x35U: + case 0x36U: + case 0x37U: duk_push_int(dec_ctx->thr, -((duk_int_t) ((ib - 0x20U) + 1U))); break; - case 0x38U: case 0x39U: case 0x3aU: case 0x3bU: + case 0x38U: + case 0x39U: + case 0x3aU: + case 0x3bU: duk__cbor_decode_push_aival_int(dec_ctx, ib, 1 /*negative*/); break; - case 0x3cU: case 0x3dU: case 0x3eU: case 0x3fU: + case 0x3cU: + case 0x3dU: + case 0x3eU: + case 0x3fU: goto format_error; - case 0x40U: case 0x41U: case 0x42U: case 0x43U: case 0x44U: case 0x45U: case 0x46U: case 0x47U: - case 0x48U: case 0x49U: case 0x4aU: case 0x4bU: case 0x4cU: case 0x4dU: case 0x4eU: case 0x4fU: - case 0x50U: case 0x51U: case 0x52U: case 0x53U: case 0x54U: case 0x55U: case 0x56U: case 0x57U: + case 0x40U: + case 0x41U: + case 0x42U: + case 0x43U: + case 0x44U: + case 0x45U: + case 0x46U: + case 0x47U: + case 0x48U: + case 0x49U: + case 0x4aU: + case 0x4bU: + case 0x4cU: + case 0x4dU: + case 0x4eU: + case 0x4fU: + case 0x50U: + case 0x51U: + case 0x52U: + case 0x53U: + case 0x54U: + case 0x55U: + case 0x56U: + case 0x57U: /* XXX: Avoid rewind, we know the length already. */ DUK_ASSERT(dec_ctx->off > 0U); dec_ctx->off--; duk__cbor_decode_buffer(dec_ctx, 0x40U); break; - case 0x58U: case 0x59U: case 0x5aU: case 0x5bU: + case 0x58U: + case 0x59U: + case 0x5aU: + case 0x5bU: /* XXX: Avoid rewind, decode length inline. */ DUK_ASSERT(dec_ctx->off > 0U); dec_ctx->off--; duk__cbor_decode_buffer(dec_ctx, 0x40U); break; - case 0x5cU: case 0x5dU: case 0x5eU: + case 0x5cU: + case 0x5dU: + case 0x5eU: goto format_error; case 0x5fU: duk__cbor_decode_and_join_strbuf(dec_ctx, 0x40U); break; - case 0x60U: case 0x61U: case 0x62U: case 0x63U: case 0x64U: case 0x65U: case 0x66U: case 0x67U: - case 0x68U: case 0x69U: case 0x6aU: case 0x6bU: case 0x6cU: case 0x6dU: case 0x6eU: case 0x6fU: - case 0x70U: case 0x71U: case 0x72U: case 0x73U: case 0x74U: case 0x75U: case 0x76U: case 0x77U: + case 0x60U: + case 0x61U: + case 0x62U: + case 0x63U: + case 0x64U: + case 0x65U: + case 0x66U: + case 0x67U: + case 0x68U: + case 0x69U: + case 0x6aU: + case 0x6bU: + case 0x6cU: + case 0x6dU: + case 0x6eU: + case 0x6fU: + case 0x70U: + case 0x71U: + case 0x72U: + case 0x73U: + case 0x74U: + case 0x75U: + case 0x76U: + case 0x77U: /* XXX: Avoid double decode of length. */ duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x78U: case 0x79U: case 0x7aU: case 0x7bU: + case 0x78U: + case 0x79U: + case 0x7aU: + case 0x7bU: /* XXX: Avoid double decode of length. */ duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x7cU: case 0x7dU: case 0x7eU: + case 0x7cU: + case 0x7dU: + case 0x7eU: goto format_error; case 0x7fU: duk__cbor_decode_string(dec_ctx, ib, DUK__CBOR_AI); break; - case 0x80U: case 0x81U: case 0x82U: case 0x83U: case 0x84U: case 0x85U: case 0x86U: case 0x87U: - case 0x88U: case 0x89U: case 0x8aU: case 0x8bU: case 0x8cU: case 0x8dU: case 0x8eU: case 0x8fU: - case 0x90U: case 0x91U: case 0x92U: case 0x93U: case 0x94U: case 0x95U: case 0x96U: case 0x97U: + case 0x80U: + case 0x81U: + case 0x82U: + case 0x83U: + case 0x84U: + case 0x85U: + case 0x86U: + case 0x87U: + case 0x88U: + case 0x89U: + case 0x8aU: + case 0x8bU: + case 0x8cU: + case 0x8dU: + case 0x8eU: + case 0x8fU: + case 0x90U: + case 0x91U: + case 0x92U: + case 0x93U: + case 0x94U: + case 0x95U: + case 0x96U: + case 0x97U: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0x98U: case 0x99U: case 0x9aU: case 0x9bU: + case 0x98U: + case 0x99U: + case 0x9aU: + case 0x9bU: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0x9cU: case 0x9dU: case 0x9eU: + case 0x9cU: + case 0x9dU: + case 0x9eU: goto format_error; case 0x9fU: if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xa0U: case 0xa1U: case 0xa2U: case 0xa3U: case 0xa4U: case 0xa5U: case 0xa6U: case 0xa7U: - case 0xa8U: case 0xa9U: case 0xaaU: case 0xabU: case 0xacU: case 0xadU: case 0xaeU: case 0xafU: - case 0xb0U: case 0xb1U: case 0xb2U: case 0xb3U: case 0xb4U: case 0xb5U: case 0xb6U: case 0xb7U: + case 0xa0U: + case 0xa1U: + case 0xa2U: + case 0xa3U: + case 0xa4U: + case 0xa5U: + case 0xa6U: + case 0xa7U: + case 0xa8U: + case 0xa9U: + case 0xaaU: + case 0xabU: + case 0xacU: + case 0xadU: + case 0xaeU: + case 0xafU: + case 0xb0U: + case 0xb1U: + case 0xb2U: + case 0xb3U: + case 0xb4U: + case 0xb5U: + case 0xb6U: + case 0xb7U: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xb8U: case 0xb9U: case 0xbaU: case 0xbbU: + case 0xb8U: + case 0xb9U: + case 0xbaU: + case 0xbbU: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xbcU: case 0xbdU: case 0xbeU: + case 0xbcU: + case 0xbdU: + case 0xbeU: goto format_error; case 0xbfU: if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, DUK__CBOR_AI) == 0)) { goto format_error; } break; - case 0xc0U: case 0xc1U: case 0xc2U: case 0xc3U: case 0xc4U: case 0xc5U: case 0xc6U: case 0xc7U: - case 0xc8U: case 0xc9U: case 0xcaU: case 0xcbU: case 0xccU: case 0xcdU: case 0xceU: case 0xcfU: - case 0xd0U: case 0xd1U: case 0xd2U: case 0xd3U: case 0xd4U: case 0xd5U: case 0xd6U: case 0xd7U: + case 0xc0U: + case 0xc1U: + case 0xc2U: + case 0xc3U: + case 0xc4U: + case 0xc5U: + case 0xc6U: + case 0xc7U: + case 0xc8U: + case 0xc9U: + case 0xcaU: + case 0xcbU: + case 0xccU: + case 0xcdU: + case 0xceU: + case 0xcfU: + case 0xd0U: + case 0xd1U: + case 0xd2U: + case 0xd3U: + case 0xd4U: + case 0xd5U: + case 0xd6U: + case 0xd7U: /* Tag 0-23: drop. */ goto reread_initial_byte; - case 0xd8U: case 0xd9U: case 0xdaU: case 0xdbU: + case 0xd8U: + case 0xd9U: + case 0xdaU: + case 0xdbU: duk__cbor_decode_skip_aival_int(dec_ctx, ib); goto reread_initial_byte; - case 0xdcU: case 0xddU: case 0xdeU: case 0xdfU: + case 0xdcU: + case 0xddU: + case 0xdeU: + case 0xdfU: goto format_error; case 0xe0U: goto format_error; @@ -31544,14 +32472,14 @@ case 0xfeU: case 0xffU: goto format_error; - } /* end switch */ + } /* end switch */ return; - format_error: +format_error: duk__cbor_decode_error(dec_ctx); } -#else /* DUK_CBOR_DECODE_FASTPATH */ +#else /* DUK_CBOR_DECODE_FASTPATH */ DUK_LOCAL void duk__cbor_decode_value(duk_cbor_decode_context *dec_ctx) { duk_uint8_t ib, mt, ai; @@ -31560,7 +32488,7 @@ * here for simple paths like primitive values. */ - reread_initial_byte: +reread_initial_byte: DUK_DDD(DUK_DDDPRINT("cbor decode off=%ld len=%ld", (long) dec_ctx->off, (long) dec_ctx->len)); ib = duk__cbor_decode_readbyte(dec_ctx); @@ -31576,15 +32504,15 @@ */ switch (mt) { - case 0U: { /* unsigned integer */ + case 0U: { /* unsigned integer */ duk__cbor_decode_push_aival_int(dec_ctx, ib, 0 /*negative*/); break; } - case 1U: { /* negative integer */ + case 1U: { /* negative integer */ duk__cbor_decode_push_aival_int(dec_ctx, ib, 1 /*negative*/); break; } - case 2U: { /* byte string */ + case 2U: { /* byte string */ if (ai == 0x1fU) { duk__cbor_decode_and_join_strbuf(dec_ctx, 0x40U); } else { @@ -31593,23 +32521,23 @@ } break; } - case 3U: { /* text string */ + case 3U: { /* text string */ duk__cbor_decode_string(dec_ctx, ib, ai); break; } - case 4U: { /* array of data items */ + case 4U: { /* array of data items */ if (DUK_UNLIKELY(duk__cbor_decode_array(dec_ctx, ib, ai) == 0)) { goto format_error; } break; } - case 5U: { /* map of pairs of data items */ + case 5U: { /* map of pairs of data items */ if (DUK_UNLIKELY(duk__cbor_decode_map(dec_ctx, ib, ai) == 0)) { goto format_error; } break; } - case 6U: { /* semantic tagging */ + case 6U: { /* semantic tagging */ /* Tags are ignored now, re-read initial byte. A tagged * value may itself be tagged (an unlimited number of times) * so keep on peeling away tags. @@ -31617,7 +32545,7 @@ duk__cbor_decode_skip_aival_int(dec_ctx, ib); goto reread_initial_byte; } - case 7U: { /* floating point numbers, simple data types, break; other */ + case 7U: { /* floating point numbers, simple data types, break; other */ switch (ai) { case 0x14U: { duk_push_false(dec_ctx->thr); @@ -31635,7 +32563,7 @@ duk_push_undefined(dec_ctx->thr); break; } - case 0x18U: { /* more simple values (1 byte) */ + case 0x18U: { /* more simple values (1 byte) */ /* Simple value encoded in additional byte (none * are defined so far). RFC 7049 states that the * follow-up byte must be 32-255 to minimize @@ -31646,42 +32574,42 @@ */ goto format_error; } - case 0x19U: { /* half-float (2 bytes) */ + case 0x19U: { /* half-float (2 bytes) */ duk_double_t d; d = duk__cbor_decode_half_float(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0x1aU: { /* float (4 bytes) */ + case 0x1aU: { /* float (4 bytes) */ duk_double_t d; d = duk__cbor_decode_float(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0x1bU: { /* double (8 bytes) */ + case 0x1bU: { /* double (8 bytes) */ duk_double_t d; d = duk__cbor_decode_double(dec_ctx); duk_push_number(dec_ctx->thr, d); break; } - case 0xffU: /* unexpected break */ + case 0xffU: /* unexpected break */ default: { goto format_error; } - } /* end switch */ + } /* end switch */ break; } default: { - goto format_error; /* will never actually occur */ + goto format_error; /* will never actually occur */ } - } /* end switch */ + } /* end switch */ return; - format_error: +format_error: duk__cbor_decode_error(dec_ctx); } -#endif /* DUK_CBOR_DECODE_FASTPATH */ +#endif /* DUK_CBOR_DECODE_FASTPATH */ DUK_LOCAL void duk__cbor_encode(duk_hthread *thr, duk_idx_t idx, duk_uint_t encode_flags) { duk_cbor_encode_context enc_ctx; @@ -31741,7 +32669,7 @@ duk_replace(thr, idx); } -#else /* DUK_USE_CBOR_SUPPORT */ +#else /* DUK_USE_CBOR_SUPPORT */ DUK_LOCAL void duk__cbor_encode(duk_hthread *thr, duk_idx_t idx, duk_uint_t encode_flags) { DUK_UNREF(idx); @@ -31755,7 +32683,7 @@ DUK_ERROR_UNSUPPORTED(thr); } -#endif /* DUK_USE_CBOR_SUPPORT */ +#endif /* DUK_USE_CBOR_SUPPORT */ /* * Public APIs @@ -31791,7 +32719,7 @@ duk__cbor_decode(thr, -1, 0 /*flags*/); return 1; } -#else /* DUK_USE_CBOR_SUPPORT */ +#else /* DUK_USE_CBOR_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_cbor_encode(duk_hthread *thr) { DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); @@ -31800,8 +32728,8 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_CBOR_SUPPORT */ -#endif /* DUK_USE_CBOR_BUILTIN */ +#endif /* DUK_USE_CBOR_SUPPORT */ +#endif /* DUK_USE_CBOR_BUILTIN */ /* automatic undefs */ #undef DUK__CBOR_AI @@ -31837,30 +32765,49 @@ */ /* Debug macro to print all parts and dparts (used manually because of debug level). */ -#define DUK__DPRINT_PARTS_AND_DPARTS(parts,dparts) do { \ +#define DUK__DPRINT_PARTS_AND_DPARTS(parts, dparts) \ + do { \ DUK_D(DUK_DPRINT("parts: %ld %ld %ld %ld %ld %ld %ld %ld, dparts: %lf %lf %lf %lf %lf %lf %lf %lf", \ - (long) (parts)0, (long) (parts)1, \ - (long) (parts)2, (long) (parts)3, \ - (long) (parts)4, (long) (parts)5, \ - (long) (parts)6, (long) (parts)7, \ - (double) (dparts)0, (double) (dparts)1, \ - (double) (dparts)2, (double) (dparts)3, \ - (double) (dparts)4, (double) (dparts)5, \ - (double) (dparts)6, (double) (dparts)7)); \ + (long) (parts)0, \ + (long) (parts)1, \ + (long) (parts)2, \ + (long) (parts)3, \ + (long) (parts)4, \ + (long) (parts)5, \ + (long) (parts)6, \ + (long) (parts)7, \ + (double) (dparts)0, \ + (double) (dparts)1, \ + (double) (dparts)2, \ + (double) (dparts)3, \ + (double) (dparts)4, \ + (double) (dparts)5, \ + (double) (dparts)6, \ + (double) (dparts)7)); \ } while (0) -#define DUK__DPRINT_PARTS(parts) do { \ +#define DUK__DPRINT_PARTS(parts) \ + do { \ DUK_D(DUK_DPRINT("parts: %ld %ld %ld %ld %ld %ld %ld %ld", \ - (long) (parts)0, (long) (parts)1, \ - (long) (parts)2, (long) (parts)3, \ - (long) (parts)4, (long) (parts)5, \ - (long) (parts)6, (long) (parts)7)); \ + (long) (parts)0, \ + (long) (parts)1, \ + (long) (parts)2, \ + (long) (parts)3, \ + (long) (parts)4, \ + (long) (parts)5, \ + (long) (parts)6, \ + (long) (parts)7)); \ } while (0) -#define DUK__DPRINT_DPARTS(dparts) do { \ +#define DUK__DPRINT_DPARTS(dparts) \ + do { \ DUK_D(DUK_DPRINT("dparts: %lf %lf %lf %lf %lf %lf %lf %lf", \ - (double) (dparts)0, (double) (dparts)1, \ - (double) (dparts)2, (double) (dparts)3, \ - (double) (dparts)4, (double) (dparts)5, \ - (double) (dparts)6, (double) (dparts)7)); \ + (double) (dparts)0, \ + (double) (dparts)1, \ + (double) (dparts)2, \ + (double) (dparts)3, \ + (double) (dparts)4, \ + (double) (dparts)5, \ + (double) (dparts)6, \ + (double) (dparts)7)); \ } while (0) /* Equivalent year for DST calculations outside 1970,2038 range, see @@ -31868,7 +32815,7 @@ * starts with the same weekday on Jan 1. * https://bugzilla.mozilla.org/show_bug.cgi?id=351066 */ -#define DUK__YEAR(x) ((duk_uint8_t) ((x) - 1970)) +#define DUK__YEAR(x) ((duk_uint8_t) ((x) -1970)) DUK_LOCAL duk_uint8_t duk__date_equivyear14 = { #if 1 /* This is based on V8 EquivalentYear() algorithm (see util/genequivyear.py): @@ -31876,12 +32823,22 @@ */ /* non-leap year: sunday, monday, ... */ - DUK__YEAR(2023), DUK__YEAR(2035), DUK__YEAR(2019), DUK__YEAR(2031), - DUK__YEAR(2015), DUK__YEAR(2027), DUK__YEAR(2011), + DUK__YEAR(2023), + DUK__YEAR(2035), + DUK__YEAR(2019), + DUK__YEAR(2031), + DUK__YEAR(2015), + DUK__YEAR(2027), + DUK__YEAR(2011), /* leap year: sunday, monday, ... */ - DUK__YEAR(2012), DUK__YEAR(2024), DUK__YEAR(2008), DUK__YEAR(2020), - DUK__YEAR(2032), DUK__YEAR(2016), DUK__YEAR(2028) + DUK__YEAR(2012), + DUK__YEAR(2024), + DUK__YEAR(2008), + DUK__YEAR(2020), + DUK__YEAR(2032), + DUK__YEAR(2016), + DUK__YEAR(2028) #endif #if 0 @@ -31904,71 +32861,70 @@ */ /* Parser part count. */ -#define DUK__NUM_ISO8601_PARSER_PARTS 9 +#define DUK__NUM_ISO8601_PARSER_PARTS 9 /* Parser part indices. */ -#define DUK__PI_YEAR 0 -#define DUK__PI_MONTH 1 -#define DUK__PI_DAY 2 -#define DUK__PI_HOUR 3 -#define DUK__PI_MINUTE 4 -#define DUK__PI_SECOND 5 -#define DUK__PI_MILLISECOND 6 -#define DUK__PI_TZHOUR 7 -#define DUK__PI_TZMINUTE 8 +#define DUK__PI_YEAR 0 +#define DUK__PI_MONTH 1 +#define DUK__PI_DAY 2 +#define DUK__PI_HOUR 3 +#define DUK__PI_MINUTE 4 +#define DUK__PI_SECOND 5 +#define DUK__PI_MILLISECOND 6 +#define DUK__PI_TZHOUR 7 +#define DUK__PI_TZMINUTE 8 /* Parser part masks. */ -#define DUK__PM_YEAR (1 << DUK__PI_YEAR) -#define DUK__PM_MONTH (1 << DUK__PI_MONTH) -#define DUK__PM_DAY (1 << DUK__PI_DAY) -#define DUK__PM_HOUR (1 << DUK__PI_HOUR) -#define DUK__PM_MINUTE (1 << DUK__PI_MINUTE) -#define DUK__PM_SECOND (1 << DUK__PI_SECOND) -#define DUK__PM_MILLISECOND (1 << DUK__PI_MILLISECOND) -#define DUK__PM_TZHOUR (1 << DUK__PI_TZHOUR) -#define DUK__PM_TZMINUTE (1 << DUK__PI_TZMINUTE) +#define DUK__PM_YEAR (1 << DUK__PI_YEAR) +#define DUK__PM_MONTH (1 << DUK__PI_MONTH) +#define DUK__PM_DAY (1 << DUK__PI_DAY) +#define DUK__PM_HOUR (1 << DUK__PI_HOUR) +#define DUK__PM_MINUTE (1 << DUK__PI_MINUTE) +#define DUK__PM_SECOND (1 << DUK__PI_SECOND) +#define DUK__PM_MILLISECOND (1 << DUK__PI_MILLISECOND) +#define DUK__PM_TZHOUR (1 << DUK__PI_TZHOUR) +#define DUK__PM_TZMINUTE (1 << DUK__PI_TZMINUTE) /* Parser separator indices. */ -#define DUK__SI_PLUS 0 -#define DUK__SI_MINUS 1 -#define DUK__SI_T 2 -#define DUK__SI_SPACE 3 -#define DUK__SI_COLON 4 -#define DUK__SI_PERIOD 5 -#define DUK__SI_Z 6 -#define DUK__SI_NUL 7 +#define DUK__SI_PLUS 0 +#define DUK__SI_MINUS 1 +#define DUK__SI_T 2 +#define DUK__SI_SPACE 3 +#define DUK__SI_COLON 4 +#define DUK__SI_PERIOD 5 +#define DUK__SI_Z 6 +#define DUK__SI_NUL 7 /* Parser separator masks. */ -#define DUK__SM_PLUS (1 << DUK__SI_PLUS) -#define DUK__SM_MINUS (1 << DUK__SI_MINUS) -#define DUK__SM_T (1 << DUK__SI_T) -#define DUK__SM_SPACE (1 << DUK__SI_SPACE) -#define DUK__SM_COLON (1 << DUK__SI_COLON) -#define DUK__SM_PERIOD (1 << DUK__SI_PERIOD) -#define DUK__SM_Z (1 << DUK__SI_Z) -#define DUK__SM_NUL (1 << DUK__SI_NUL) +#define DUK__SM_PLUS (1 << DUK__SI_PLUS) +#define DUK__SM_MINUS (1 << DUK__SI_MINUS) +#define DUK__SM_T (1 << DUK__SI_T) +#define DUK__SM_SPACE (1 << DUK__SI_SPACE) +#define DUK__SM_COLON (1 << DUK__SI_COLON) +#define DUK__SM_PERIOD (1 << DUK__SI_PERIOD) +#define DUK__SM_Z (1 << DUK__SI_Z) +#define DUK__SM_NUL (1 << DUK__SI_NUL) /* Rule control flags. */ -#define DUK__CF_NEG (1 << 0) /* continue matching, set neg_tzoffset flag */ -#define DUK__CF_ACCEPT (1 << 1) /* accept string */ -#define DUK__CF_ACCEPT_NUL (1 << 2) /* accept string if next char is NUL (otherwise reject) */ - -#define DUK__PACK_RULE(partmask,sepmask,nextpart,flags) \ - ((duk_uint32_t) (partmask) + \ - (((duk_uint32_t) (sepmask)) << 9) + \ - (((duk_uint32_t) (nextpart)) << 17) + \ +#define DUK__CF_NEG (1 << 0) /* continue matching, set neg_tzoffset flag */ +#define DUK__CF_ACCEPT (1 << 1) /* accept string */ +#define DUK__CF_ACCEPT_NUL (1 << 2) /* accept string if next char is NUL (otherwise reject) */ + +#define DUK__PACK_RULE(partmask, sepmask, nextpart, flags) \ + ((duk_uint32_t) (partmask) + (((duk_uint32_t) (sepmask)) << 9) + (((duk_uint32_t) (nextpart)) << 17) + \ (((duk_uint32_t) (flags)) << 21)) -#define DUK__UNPACK_RULE(rule,var_nextidx,var_flags) do { \ +#define DUK__UNPACK_RULE(rule, var_nextidx, var_flags) \ + do { \ (var_nextidx) = (duk_small_uint_t) (((rule) >> 17) & 0x0f); \ (var_flags) = (duk_small_uint_t) ((rule) >> 21); \ } while (0) -#define DUK__RULE_MASK_PART_SEP 0x1ffffUL +#define DUK__RULE_MASK_PART_SEP 0x1ffffUL /* Matching separator index is used in the control table */ DUK_LOCAL const duk_uint8_t duk__parse_iso8601_seps = { - DUK_ASC_PLUS /*0*/, DUK_ASC_MINUS /*1*/, DUK_ASC_UC_T /*2*/, DUK_ASC_SPACE /*3*/, + DUK_ASC_PLUS /*0*/, DUK_ASC_MINUS /*1*/, DUK_ASC_UC_T /*2*/, DUK_ASC_SPACE /*3*/, DUK_ASC_COLON /*4*/, DUK_ASC_PERIOD /*5*/, DUK_ASC_UC_Z /*6*/, DUK_ASC_NUL /*7*/ }; @@ -31981,10 +32937,26 @@ DUK__PACK_RULE(DUK__PM_MINUTE, DUK__SM_COLON, DUK__PI_SECOND, 0), DUK__PACK_RULE(DUK__PM_SECOND, DUK__SM_PERIOD, DUK__PI_MILLISECOND, 0), DUK__PACK_RULE(DUK__PM_TZHOUR, DUK__SM_COLON, DUK__PI_TZMINUTE, 0), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_PLUS, DUK__PI_TZHOUR, 0), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_MINUS, DUK__PI_TZHOUR, DUK__CF_NEG), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND, DUK__SM_Z, 0, DUK__CF_ACCEPT_NUL), - DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | DUK__PM_MILLISECOND | DUK__PM_TZHOUR /*Note2*/ | DUK__PM_TZMINUTE, DUK__SM_NUL, 0, DUK__CF_ACCEPT) + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_PLUS, + DUK__PI_TZHOUR, + 0), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_MINUS, + DUK__PI_TZHOUR, + DUK__CF_NEG), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND, + DUK__SM_Z, + 0, + DUK__CF_ACCEPT_NUL), + DUK__PACK_RULE(DUK__PM_YEAR | DUK__PM_MONTH | DUK__PM_DAY | DUK__PM_HOUR /*Note1*/ | DUK__PM_MINUTE | DUK__PM_SECOND | + DUK__PM_MILLISECOND | DUK__PM_TZHOUR /*Note2*/ | DUK__PM_TZMINUTE, + DUK__SM_NUL, + 0, + DUK__CF_ACCEPT) /* Note1: the specification doesn't require matching a time form with * just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z". @@ -32009,7 +32981,7 @@ /* During parsing, month and day are one-based; set defaults here. */ duk_memzero(parts, sizeof(parts)); - DUK_ASSERT(partsDUK_DATE_IDX_YEAR == 0); /* don't care value, year is mandatory */ + DUK_ASSERT(partsDUK_DATE_IDX_YEAR == 0); /* don't care value, year is mandatory */ partsDUK_DATE_IDX_MONTH = 1; partsDUK_DATE_IDX_DAY = 1; @@ -32026,7 +32998,8 @@ for (;;) { ch = *p++; DUK_DDD(DUK_DDDPRINT("parsing, part_idx=%ld, char=%ld ('%c')", - (long) part_idx, (long) ch, + (long) part_idx, + (long) ch, (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : DUK_ASC_QUESTION))); if (ch >= DUK_ASC_0 && ch <= DUK_ASC_9) { @@ -32071,7 +33044,7 @@ } sep_idx = i; - match_val = (1UL << part_idx) + (1UL << (sep_idx + 9)); /* match against rule part/sep bits */ + match_val = (1UL << part_idx) + (1UL << (sep_idx + 9)); /* match against rule part/sep bits */ for (i = 0; i < (duk_small_uint_t) (sizeof(duk__parse_iso8601_control) / sizeof(duk_uint32_t)); i++) { duk_uint_fast32_t rule = duk__parse_iso8601_controli; @@ -32079,8 +33052,10 @@ duk_small_uint_t cflags; DUK_DDD(DUK_DDDPRINT("part_idx=%ld, sep_idx=%ld, match_val=0x%08lx, considering rule=0x%08lx", - (long) part_idx, (long) sep_idx, - (unsigned long) match_val, (unsigned long) rule)); + (long) part_idx, + (long) sep_idx, + (unsigned long) match_val, + (unsigned long) rule)); if ((rule & match_val) != match_val) { continue; @@ -32090,9 +33065,12 @@ DUK_DDD(DUK_DDDPRINT("rule match -> part_idx=%ld, sep_idx=%ld, match_val=0x%08lx, " "rule=0x%08lx -> nextpart=%ld, cflags=0x%02lx", - (long) part_idx, (long) sep_idx, - (unsigned long) match_val, (unsigned long) rule, - (long) nextpart, (unsigned long) cflags)); + (long) part_idx, + (long) sep_idx, + (unsigned long) match_val, + (unsigned long) rule, + (long) nextpart, + (unsigned long) cflags)); if (cflags & DUK__CF_NEG) { neg_tzoffset = 1; @@ -32112,7 +33090,7 @@ part_idx = nextpart; break; - } /* rule match */ + } /* rule match */ if (i == (duk_small_uint_t) (sizeof(duk__parse_iso8601_control) / sizeof(duk_uint32_t))) { DUK_DDD(DUK_DDDPRINT("no rule matches -> reject")); @@ -32126,17 +33104,17 @@ DUK_DDD(DUK_DDDPRINT("NUL after rule matching (should not happen) -> reject")); goto reject; } - } /* if-digit-else-ctrl */ - } /* char loop */ + } /* if-digit-else-ctrl */ + } /* char loop */ /* We should never exit the loop above. */ DUK_UNREACHABLE(); - reject: +reject: DUK_DDD(DUK_DDDPRINT("reject")); return 0; - accept: +accept: DUK_DDD(DUK_DDDPRINT("accept")); /* Apply timezone offset to get the main parts in UTC */ @@ -32150,8 +33128,8 @@ partsDUK__PI_HOUR -= partsDUK__PI_TZHOUR; partsDUK__PI_MINUTE -= partsDUK__PI_TZMINUTE; } - partsDUK__PI_MONTH -= 1; /* zero-based month */ - partsDUK__PI_DAY -= 1; /* zero-based day */ + partsDUK__PI_MONTH -= 1; /* zero-based month */ + partsDUK__PI_DAY -= 1; /* zero-based day */ /* Use double parts, they tolerate unnormalized time. * @@ -32228,16 +33206,14 @@ * out for non-finite numbers etc. */ -DUK_LOCAL duk_uint8_t duk__days_in_month12 = { - (duk_uint8_t) 31, (duk_uint8_t) 28, (duk_uint8_t) 31, (duk_uint8_t) 30, - (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 31, - (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31 -}; +DUK_LOCAL duk_uint8_t duk__days_in_month12 = { (duk_uint8_t) 31, (duk_uint8_t) 28, (duk_uint8_t) 31, (duk_uint8_t) 30, + (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 31, + (duk_uint8_t) 30, (duk_uint8_t) 31, (duk_uint8_t) 30, (duk_uint8_t) 31 }; /* Maximum iteration count for computing UTC-to-local time offset when * creating an ECMAScript time value from local parts. */ -#define DUK__LOCAL_TZOFFSET_MAXITER 4 +#define DUK__LOCAL_TZOFFSET_MAXITER 4 /* Because 'day since epoch' can be negative and is used to compute weekday * using a modulo operation, add this multiple of 7 to avoid negative values @@ -32245,7 +33221,7 @@ * +/- 100 million days from epoch, so this adder fits nicely into 32 bits. * Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin. */ -#define DUK__WEEKDAY_MOD_ADDER (20000000 * 7) /* 0x08583b00 */ +#define DUK__WEEKDAY_MOD_ADDER (20000000 * 7) /* 0x08583b00 */ DUK_INTERNAL duk_bool_t duk_bi_date_is_leap_year(duk_int_t year) { if ((year % 4) != 0) { @@ -32306,10 +33282,8 @@ /* Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative * values, but is incorrect for negative ones. */ - return 365 * (year - 1970) - + duk__div_floor(year - 1969, 4) - - duk__div_floor(year - 1901, 100) - + duk__div_floor(year - 1601, 400); + return 365 * (year - 1970) + duk__div_floor(year - 1969, 4) - duk__div_floor(year - 1901, 100) + + duk__div_floor(year - 1601, 400); } /* Given a day number, determine year and day-within-year. */ @@ -32331,10 +33305,9 @@ diff_days = duk__day_from_year(year) - day; DUK_DDD(DUK_DDDPRINT("year=%ld day=%ld, diff_days=%ld", (long) year, (long) day, (long) diff_days)); if (diff_days <= 0) { - DUK_ASSERT(-diff_days < 366); /* fits into duk_small_int_t */ + DUK_ASSERT(-diff_days < 366); /* fits into duk_small_int_t */ *out_day_within_year = -diff_days; - DUK_DDD(DUK_DDDPRINT("--> year=%ld, day-within-year=%ld", - (long) year, (long) *out_day_within_year)); + DUK_DDD(DUK_DDDPRINT("--> year=%ld, day-within-year=%ld", (long) year, (long) *out_day_within_year)); DUK_ASSERT(*out_day_within_year >= 0); DUK_ASSERT(*out_day_within_year < (duk_bi_date_is_leap_year(year) ? 366 : 365)); return year; @@ -32343,7 +33316,7 @@ /* Note: this is very tricky; we must never 'overshoot' the * correction downwards. */ - year -= 1 + (diff_days - 1) / 366; /* conservative */ + year -= 1 + (diff_days - 1) / 366; /* conservative */ } } @@ -32416,7 +33389,7 @@ duk_double_t d1, d2; duk_int_t t1, t2; duk_int_t day_since_epoch; - duk_int_t year; /* does not fit into 16 bits */ + duk_int_t year; /* does not fit into 16 bits */ duk_small_int_t day_in_year; duk_small_int_t month; duk_small_int_t day; @@ -32428,8 +33401,8 @@ duk_bool_t is_leap; duk_small_int_t arridx; - DUK_ASSERT(DUK_ISFINITE(d)); /* caller checks */ - d = DUK_FLOOR(d); /* remove fractions if present */ + DUK_ASSERT(DUK_ISFINITE(d)); /* caller checks */ + d = DUK_FLOOR(d); /* remove fractions if present */ DUK_ASSERT(duk_double_equals(DUK_FLOOR(d), d)); /* The timevalue must be in valid ECMAScript range, but since a local @@ -32461,9 +33434,12 @@ * t2 = day number from epoch (fits 32 bit, may be negative) */ - partsDUK_DATE_IDX_MILLISECOND = t1 % 1000; t1 /= 1000; - partsDUK_DATE_IDX_SECOND = t1 % 60; t1 /= 60; - partsDUK_DATE_IDX_MINUTE = t1 % 60; t1 /= 60; + partsDUK_DATE_IDX_MILLISECOND = t1 % 1000; + t1 /= 1000; + partsDUK_DATE_IDX_SECOND = t1 % 60; + t1 /= 60; + partsDUK_DATE_IDX_MINUTE = t1 % 60; + t1 /= 60; partsDUK_DATE_IDX_HOUR = t1; DUK_ASSERT(partsDUK_DATE_IDX_MILLISECOND >= 0 && partsDUK_DATE_IDX_MILLISECOND <= 999); DUK_ASSERT(partsDUK_DATE_IDX_SECOND >= 0 && partsDUK_DATE_IDX_SECOND <= 59); @@ -32471,7 +33447,11 @@ DUK_ASSERT(partsDUK_DATE_IDX_HOUR >= 0 && partsDUK_DATE_IDX_HOUR <= 23); DUK_DDD(DUK_DDDPRINT("d=%lf, d1=%lf, d2=%lf, t1=%ld, t2=%ld, parts: hour=%ld min=%ld sec=%ld msec=%ld", - (double) d, (double) d1, (double) d2, (long) t1, (long) t2, + (double) d, + (double) d1, + (double) d2, + (long) t1, + (long) t2, (long) partsDUK_DATE_IDX_HOUR, (long) partsDUK_DATE_IDX_MINUTE, (long) partsDUK_DATE_IDX_SECOND, @@ -32481,7 +33461,7 @@ * the ECMAScript range. */ DUK_ASSERT(t2 + DUK__WEEKDAY_MOD_ADDER >= 0); - partsDUK_DATE_IDX_WEEKDAY = (t2 + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ + partsDUK_DATE_IDX_WEEKDAY = (t2 + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ DUK_ASSERT(partsDUK_DATE_IDX_WEEKDAY >= 0 && partsDUK_DATE_IDX_WEEKDAY <= 6); year = duk__year_from_day(t2, &day_in_year); @@ -32492,8 +33472,7 @@ if (month == 1 && is_leap) { dim++; } - DUK_DDD(DUK_DDDPRINT("month=%ld, dim=%ld, day=%ld", - (long) month, (long) dim, (long) day)); + DUK_DDD(DUK_DDDPRINT("month=%ld, dim=%ld, day=%ld", (long) month, (long) dim, (long) day)); if (day < dim) { break; } @@ -32518,9 +33497,9 @@ if ((flags & DUK_DATE_FLAG_EQUIVYEAR) && (year < 1971 || year > 2037)) { DUK_ASSERT(is_leap == 0 || is_leap == 1); - jan1_since_epoch = day_since_epoch - day_in_year; /* day number for Jan 1 since epoch */ + jan1_since_epoch = day_since_epoch - day_in_year; /* day number for Jan 1 since epoch */ DUK_ASSERT(jan1_since_epoch + DUK__WEEKDAY_MOD_ADDER >= 0); - jan1_weekday = (jan1_since_epoch + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ + jan1_weekday = (jan1_since_epoch + 4 + DUK__WEEKDAY_MOD_ADDER) % 7; /* E5.1 Section 15.9.1.6 */ DUK_ASSERT(jan1_weekday >= 0 && jan1_weekday <= 6); arridx = jan1_weekday; if (is_leap) { @@ -32532,8 +33511,12 @@ year = equiv_year; DUK_DDD(DUK_DDDPRINT("equiv year mapping, year=%ld, day_in_year=%ld, day_since_epoch=%ld, " "jan1_since_epoch=%ld, jan1_weekday=%ld -> equiv year %ld", - (long) year, (long) day_in_year, (long) day_since_epoch, - (long) jan1_since_epoch, (long) jan1_weekday, (long) equiv_year)); + (long) year, + (long) day_in_year, + (long) day_since_epoch, + (long) jan1_since_epoch, + (long) jan1_weekday, + (long) equiv_year)); } partsDUK_DATE_IDX_YEAR = year; @@ -32541,8 +33524,8 @@ partsDUK_DATE_IDX_DAY = day; if (flags & DUK_DATE_FLAG_ONEBASED) { - partsDUK_DATE_IDX_MONTH++; /* zero-based -> one-based */ - partsDUK_DATE_IDX_DAY++; /* -""- */ + partsDUK_DATE_IDX_MONTH++; /* zero-based -> one-based */ + partsDUK_DATE_IDX_DAY++; /* -""- */ } if (dparts != NULL) { @@ -32622,8 +33605,7 @@ /* MakeDate */ d = tmp_day * ((duk_double_t) DUK_DATE_MSEC_DAY) + tmp_time; - DUK_DDD(DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf", - (double) tmp_time, (double) tmp_day, (double) d)); + DUK_DDD(DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf", (double) tmp_time, (double) tmp_day, (double) d)); /* Optional UTC conversion. */ if (flags & DUK_DATE_FLAG_LOCALTIME) { @@ -32653,16 +33635,22 @@ /* Iteration solution */ tzoff = 0; - tzoffprev1 = 999999999L; /* invalid value which never matches */ + tzoffprev1 = 999999999L; /* invalid value which never matches */ for (i = 0; i < DUK__LOCAL_TZOFFSET_MAXITER; i++) { tzoffprev2 = tzoffprev1; tzoffprev1 = tzoff; tzoff = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d - tzoff * 1000L); DUK_DDD(DUK_DDDPRINT("tzoffset iteration, i=%d, tzoff=%ld, tzoffprev1=%ld tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); if (tzoff == tzoffprev1) { DUK_DDD(DUK_DDDPRINT("tzoffset iteration finished, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); break; } else if (tzoff == tzoffprev2) { /* Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js. @@ -32670,8 +33658,12 @@ * result which is independent of iteration count. Not sure if * this is a generically correct solution. */ - DUK_DDD(DUK_DDDPRINT("tzoffset iteration two-value cycle, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", - (int) i, (long) tzoff, (long) tzoffprev1, (long) tzoffprev2)); + DUK_DDD(DUK_DDDPRINT( + "tzoffset iteration two-value cycle, i=%d, tzoff=%ld, tzoffprev1=%ld, tzoffprev2=%ld", + (int) i, + (long) tzoff, + (long) tzoffprev1, + (long) tzoffprev2)); if (tzoffprev1 > tzoff) { tzoff = tzoffprev1; } @@ -32702,7 +33694,7 @@ duk_int_t tzoffset = 0; duk_push_this(thr); - h = duk_get_hobject(thr, -1); /* XXX: getter with class check, useful in built-ins */ + h = duk_get_hobject(thr, -1); /* XXX: getter with class check, useful in built-ins */ if (h == NULL || DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_DATE) { DUK_ERROR_TYPE(thr, "expected Date"); DUK_WO_NORETURN(return 0.0;); @@ -32728,7 +33720,7 @@ /* Note: DST adjustment is determined using UTC time. * If 'd' is NaN, tzoffset will be 0. */ - tzoffset = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d); /* seconds */ + tzoffset = DUK_USE_DATE_GET_LOCAL_TZOFFSET(d); /* seconds */ d += tzoffset * 1000L; } if (out_tzoffset) { @@ -32753,8 +33745,8 @@ /* ... this */ d = duk_bi_date_get_timeval_from_dparts(dparts, flags); - duk_push_number(thr, d); /* -> ... this timeval_new */ - duk_dup_top(thr); /* -> ... this timeval_new timeval_new */ + duk_push_number(thr, d); /* -> ... this timeval_new */ + duk_dup_top(thr); /* -> ... this timeval_new timeval_new */ /* Must force write because e.g. .setYear() must work even when * the Date instance is frozen. @@ -32767,8 +33759,8 @@ /* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long. */ DUK_LOCAL void duk__format_parts_iso8601(duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags, duk_uint8_t *out_buf) { - char yearstr8; /* "-123456\0" */ - char tzstr8; /* "+11:22\0" */ + char yearstr8; /* "-123456\0" */ + char tzstr8; /* "+11:22\0" */ char sep = (flags & DUK_DATE_FLAG_SEP_T) ? DUK_ASC_UC_T : DUK_ASC_SPACE; DUK_ASSERT(partsDUK_DATE_IDX_MONTH >= 1 && partsDUK_DATE_IDX_MONTH <= 12); @@ -32780,8 +33772,9 @@ */ DUK_SNPRINTF(yearstr, sizeof(yearstr), - (partsDUK_DATE_IDX_YEAR >= 0 && partsDUK_DATE_IDX_YEAR <= 9999) ? "%04ld" : - ((partsDUK_DATE_IDX_YEAR >= 0) ? "+%06ld" : "%07ld"), + (partsDUK_DATE_IDX_YEAR >= 0 && partsDUK_DATE_IDX_YEAR <= 9999) ? + "%04ld" : + ((partsDUK_DATE_IDX_YEAR >= 0) ? "+%06ld" : "%07ld"), (long) partsDUK_DATE_IDX_YEAR); yearstrsizeof(yearstr) - 1 = (char) 0; @@ -32802,8 +33795,9 @@ tmp = tmp / 60; arg_hours = tmp / 60; arg_minutes = tmp % 60; - DUK_ASSERT(arg_hours <= 24); /* Even less is actually guaranteed for a valid tzoffset. */ - arg_hours = arg_hours & 0x3f; /* For 0,24 this is a no-op, but fixes GCC 7 warning, see https://github.com/svaarala/duktape/issues/1602. */ + DUK_ASSERT(arg_hours <= 24); /* Even less is actually guaranteed for a valid tzoffset. */ + arg_hours = arg_hours & 0x3f; /* For 0,24 this is a no-op, but fixes GCC 7 warning, see + https://github.com/svaarala/duktape/issues/1602. */ DUK_SNPRINTF(tzstr, sizeof(tzstr), fmt, (int) arg_hours, (int) arg_minutes); tzstrsizeof(tzstr) - 1 = (char) 0; @@ -32816,18 +33810,31 @@ * is portable. */ if ((flags & DUK_DATE_FLAG_TOSTRING_DATE) && (flags & DUK_DATE_FLAG_TOSTRING_TIME)) { - DUK_SPRINTF((char *) out_buf, "%s-%02d-%02d%c%02d:%02d:%02d.%03d%s", - (const char *) yearstr, (int) partsDUK_DATE_IDX_MONTH, (int) partsDUK_DATE_IDX_DAY, (int) sep, - (int) partsDUK_DATE_IDX_HOUR, (int) partsDUK_DATE_IDX_MINUTE, - (int) partsDUK_DATE_IDX_SECOND, (int) partsDUK_DATE_IDX_MILLISECOND, (const char *) tzstr); + DUK_SPRINTF((char *) out_buf, + "%s-%02d-%02d%c%02d:%02d:%02d.%03d%s", + (const char *) yearstr, + (int) partsDUK_DATE_IDX_MONTH, + (int) partsDUK_DATE_IDX_DAY, + (int) sep, + (int) partsDUK_DATE_IDX_HOUR, + (int) partsDUK_DATE_IDX_MINUTE, + (int) partsDUK_DATE_IDX_SECOND, + (int) partsDUK_DATE_IDX_MILLISECOND, + (const char *) tzstr); } else if (flags & DUK_DATE_FLAG_TOSTRING_DATE) { - DUK_SPRINTF((char *) out_buf, "%s-%02d-%02d", - (const char *) yearstr, (int) partsDUK_DATE_IDX_MONTH, (int) partsDUK_DATE_IDX_DAY); + DUK_SPRINTF((char *) out_buf, + "%s-%02d-%02d", + (const char *) yearstr, + (int) partsDUK_DATE_IDX_MONTH, + (int) partsDUK_DATE_IDX_DAY); } else { DUK_ASSERT(flags & DUK_DATE_FLAG_TOSTRING_TIME); - DUK_SPRINTF((char *) out_buf, "%02d:%02d:%02d.%03d%s", - (int) partsDUK_DATE_IDX_HOUR, (int) partsDUK_DATE_IDX_MINUTE, - (int) partsDUK_DATE_IDX_SECOND, (int) partsDUK_DATE_IDX_MILLISECOND, + DUK_SPRINTF((char *) out_buf, + "%02d:%02d:%02d.%03d%s", + (int) partsDUK_DATE_IDX_HOUR, + (int) partsDUK_DATE_IDX_MINUTE, + (int) partsDUK_DATE_IDX_SECOND, + (int) partsDUK_DATE_IDX_MILLISECOND, (const char *) tzstr); } } @@ -32839,11 +33846,11 @@ DUK_LOCAL duk_ret_t duk__to_string_helper(duk_hthread *thr, duk_small_uint_t flags) { duk_double_t d; duk_int_t partsDUK_DATE_IDX_NUM_PARTS; - duk_int_t tzoffset; /* seconds, doesn't fit into 16 bits */ + duk_int_t tzoffset; /* seconds, doesn't fit into 16 bits */ duk_bool_t rc; duk_uint8_t bufDUK_BI_DATE_ISO8601_BUFSIZE; - DUK_UNREF(rc); /* unreferenced with some options */ + DUK_UNREF(rc); /* unreferenced with some options */ d = duk__push_this_get_timeval_tzoffset(thr, flags, &tzoffset); if (DUK_ISNAN(d)) { @@ -32895,9 +33902,9 @@ DUK_LOCAL duk_ret_t duk__get_part_helper(duk_hthread *thr, duk_small_uint_t flags_and_idx) { duk_double_t d; duk_int_t partsDUK_DATE_IDX_NUM_PARTS; - duk_small_uint_t idx_part = (duk_small_uint_t) (flags_and_idx >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ + duk_small_uint_t idx_part = (duk_small_uint_t) (flags_and_idx >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ - DUK_ASSERT_DISABLE(idx_part >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx_part >= 0); /* unsigned */ DUK_ASSERT(idx_part < DUK_DATE_IDX_NUM_PARTS); d = duk__push_this_get_timeval(thr, flags_and_idx); @@ -32907,7 +33914,7 @@ } DUK_ASSERT(DUK_ISFINITE(d)); - duk_bi_date_timeval_to_parts(d, parts, NULL, flags_and_idx); /* no need to mask idx portion */ + duk_bi_date_timeval_to_parts(d, parts, NULL, flags_and_idx); /* no need to mask idx portion */ /* Setter APIs detect special year numbers (0...99) and apply a +1900 * only in certain cases. The legacy getYear() getter applies -1900 @@ -32929,7 +33936,7 @@ duk_int_t partsDUK_DATE_IDX_NUM_PARTS; duk_double_t dpartsDUK_DATE_IDX_NUM_PARTS; duk_idx_t nargs; - duk_small_uint_t maxnargs = (duk_small_uint_t) (flags_and_maxnargs >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ + duk_small_uint_t maxnargs = (duk_small_uint_t) (flags_and_maxnargs >> DUK_DATE_FLAG_VALUE_SHIFT); /* unpack args */ duk_small_uint_t idx_first, idx; duk_small_uint_t i; @@ -32976,7 +33983,7 @@ DUK_ASSERT(maxnargs >= 1 && maxnargs <= 3); idx_first = DUK_DATE_IDX_DAY - (maxnargs - 1); } - DUK_ASSERT_DISABLE(idx_first >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx_first >= 0); /* unsigned */ DUK_ASSERT(idx_first < DUK_DATE_IDX_NUM_PARTS); for (i = 0; i < maxnargs; i++) { @@ -32985,7 +33992,7 @@ break; } idx = idx_first + i; - DUK_ASSERT_DISABLE(idx >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(idx >= 0); /* unsigned */ DUK_ASSERT(idx < DUK_DATE_IDX_NUM_PARTS); if (idx == DUK_DATE_IDX_YEAR && (flags_and_maxnargs & DUK_DATE_FLAG_YEAR_FIXUP)) { @@ -33037,7 +34044,7 @@ } duk_dup(thr, idx_val); duk_to_int(thr, -1); - d = duk_get_number(thr, -1); /* get as double to handle huge numbers correctly */ + d = duk_get_number(thr, -1); /* get as double to handle huge numbers correctly */ if (d >= 0.0 && d <= 99.0) { d += 1900.0; duk_push_number(thr, d); @@ -33085,10 +34092,14 @@ } DUK_DDD(DUK_DDDPRINT("parts from args -> %lf %lf %lf %lf %lf %lf %lf %lf", - (double) dparts0, (double) dparts1, - (double) dparts2, (double) dparts3, - (double) dparts4, (double) dparts5, - (double) dparts6, (double) dparts7)); + (double) dparts0, + (double) dparts1, + (double) dparts2, + (double) dparts3, + (double) dparts4, + (double) dparts5, + (double) dparts6, + (double) dparts7)); } /* @@ -33244,9 +34255,8 @@ DUK_DDD(DUK_DDDPRINT("Date constructor, nargs=%ld, is_cons=%ld", (long) nargs, (long) is_cons)); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATE), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DATE), DUK_BIDX_DATE_PROTOTYPE); /* Unlike most built-ins, the internal PrimitiveValue of a Date @@ -33268,9 +34278,9 @@ str = duk_get_string_notsymbol(thr, 0); if (str) { duk__parse_string(thr, str); - duk_replace(thr, 0); /* may be NaN */ + duk_replace(thr, 0); /* may be NaN */ } - d = duk__timeclip(duk_to_number(thr, 0)); /* symbols fail here */ + d = duk__timeclip(duk_to_number(thr, 0)); /* symbols fail here */ duk_push_number(thr, d); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_W); return 1; @@ -33280,8 +34290,8 @@ /* Parts are in local time, convert when setting. */ - (void) duk__set_this_timeval_from_dparts(thr, dparts, DUK_DATE_FLAG_LOCALTIME /*flags*/); /* -> ... this timeval */ - duk_pop(thr); /* -> ... this */ + (void) duk__set_this_timeval_from_dparts(thr, dparts, DUK_DATE_FLAG_LOCALTIME /*flags*/); /* -> ... this timeval */ + duk_pop(thr); /* -> ... this */ return 1; } @@ -33312,7 +34322,7 @@ duk_double_t d; d = duk_time_get_ecmascript_time_nofrac(thr); - DUK_ASSERT(duk_double_equals(duk__timeclip(d), d)); /* TimeClip() should never be necessary */ + DUK_ASSERT(duk_double_equals(duk__timeclip(d), d)); /* TimeClip() should never be necessary */ duk_push_number(thr, d); return 1; } @@ -33361,7 +34371,7 @@ * as their behavior is identical. */ - duk_double_t d = duk__push_this_get_timeval(thr, 0 /*flags*/); /* -> this */ + duk_double_t d = duk__push_this_get_timeval(thr, 0 /*flags*/); /* -> this */ DUK_ASSERT(DUK_ISFINITE(d) || DUK_ISNAN(d)); duk_push_number(thr, d); return 1; @@ -33387,7 +34397,7 @@ duk_pop(thr); duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_ISO_STRING); - duk_dup_m2(thr); /* -> O toIsoString O */ + duk_dup_m2(thr); /* -> O toIsoString O */ duk_call_method(thr, 0); return 1; } @@ -33560,8 +34570,7 @@ DUK_ASSERT_TOP(thr, 2); hintstr = duk_require_lstring(thr, 0, &hintlen); - if ((hintlen == 6 && DUK_STRCMP(hintstr, "string") == 0) || - (hintlen == 7 && DUK_STRCMP(hintstr, "default") == 0)) { + if ((hintlen == 6 && DUK_STRCMP(hintstr, "string") == 0) || (hintlen == 7 && DUK_STRCMP(hintstr, "default") == 0)) { hint = DUK_HINT_STRING; } else if (hintlen == 6 && DUK_STRCMP(hintstr, "number") == 0) { hint = DUK_HINT_NUMBER; @@ -33572,9 +34581,9 @@ duk_to_primitive_ordinary(thr, -1, hint); return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ -#endif /* DUK_USE_DATE_BUILTIN */ +#endif /* DUK_USE_DATE_BUILTIN */ /* automatic undefs */ #undef DUK__CF_ACCEPT @@ -33638,8 +34647,8 @@ /* Buffer sizes for some UNIX calls. Larger than strictly necessary * to avoid Valgrind errors. */ -#define DUK__STRPTIME_BUF_SIZE 64 -#define DUK__STRFTIME_BUF_SIZE 64 +#define DUK__STRPTIME_BUF_SIZE 64 +#define DUK__STRFTIME_BUF_SIZE 64 #if defined(DUK_USE_DATE_NOW_GETTIMEOFDAY) /* Get current ECMAScript time (= UNIX/Posix time, but in milliseconds). */ @@ -33653,12 +34662,11 @@ } /* As of Duktape 2.2.0 allow fractions. */ - d = ((duk_double_t) tv.tv_sec) * 1000.0 + - ((duk_double_t) tv.tv_usec) / 1000.0; + d = ((duk_double_t) tv.tv_sec) * 1000.0 + ((duk_double_t) tv.tv_usec) / 1000.0; return d; } -#endif /* DUK_USE_DATE_NOW_GETTIMEOFDAY */ +#endif /* DUK_USE_DATE_NOW_GETTIMEOFDAY */ #if defined(DUK_USE_DATE_NOW_TIME) /* Not a very good provider: only full seconds are available. */ @@ -33672,7 +34680,7 @@ } return ((duk_double_t) t) * 1000.0; } -#endif /* DUK_USE_DATE_NOW_TIME */ +#endif /* DUK_USE_DATE_NOW_TIME */ #if defined(DUK_USE_DATE_TZO_GMTIME) || defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) /* Get local time offset (in seconds) for a certain (UTC) instant 'd'. */ @@ -33755,7 +34763,7 @@ DUK_ASSERT(partsDUK_DATE_IDX_YEAR >= 1970 && partsDUK_DATE_IDX_YEAR <= 2038); d = duk_bi_date_get_timeval_from_dparts(dparts, 0 /*flags*/); - DUK_ASSERT(d >= 0 && d < 2147483648.0 * 1000.0); /* unsigned 31-bit range */ + DUK_ASSERT(d >= 0 && d < 2147483648.0 * 1000.0); /* unsigned 31-bit range */ t = (time_t) (d / 1000.0); DUK_DDD(DUK_DDDPRINT("timeval: %lf -> time_t %ld", (double) d, (long) t)); @@ -33777,14 +34785,26 @@ #endif DUK_DDD(DUK_DDDPRINT("gmtime result: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tms0.tm_sec, (long) tms0.tm_min, (long) tms0.tm_hour, - (long) tms0.tm_mday, (long) tms0.tm_mon, (long) tms0.tm_year, - (long) tms0.tm_wday, (long) tms0.tm_yday, (long) tms0.tm_isdst)); + (long) tms0.tm_sec, + (long) tms0.tm_min, + (long) tms0.tm_hour, + (long) tms0.tm_mday, + (long) tms0.tm_mon, + (long) tms0.tm_year, + (long) tms0.tm_wday, + (long) tms0.tm_yday, + (long) tms0.tm_isdst)); DUK_DDD(DUK_DDDPRINT("localtime result: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tms1.tm_sec, (long) tms1.tm_min, (long) tms1.tm_hour, - (long) tms1.tm_mday, (long) tms1.tm_mon, (long) tms1.tm_year, - (long) tms1.tm_wday, (long) tms1.tm_yday, (long) tms1.tm_isdst)); + (long) tms1.tm_sec, + (long) tms1.tm_min, + (long) tms1.tm_hour, + (long) tms1.tm_mday, + (long) tms1.tm_mon, + (long) tms1.tm_year, + (long) tms1.tm_wday, + (long) tms1.tm_yday, + (long) tms1.tm_isdst)); /* tm_isdst is both an input and an output to mktime(), use 0 to * avoid DST handling in mktime(): @@ -33793,8 +34813,8 @@ */ tms0.tm_isdst = 0; tms1.tm_isdst = 0; - t1 = mktime(&tms0); /* UTC */ - t2 = mktime(&tms1); /* local */ + t1 = mktime(&tms0); /* UTC */ + t2 = mktime(&tms1); /* local */ if (t1 == (time_t) -1 || t2 == (time_t) -1) { /* This check used to be for (t < 0) but on some platforms * time_t is unsigned and apparently the proper way to detect @@ -33817,12 +34837,12 @@ #endif return (duk_int_t) difftime(t2, t1); - mktime_error: +mktime_error: /* XXX: return something more useful, so that caller can throw? */ DUK_D(DUK_DPRINT("mktime() failed, d=%lf", (double) d)); return 0; } -#endif /* DUK_USE_DATE_TZO_GMTIME */ +#endif /* DUK_USE_DATE_TZO_GMTIME */ #if defined(DUK_USE_DATE_PRS_STRPTIME) DUK_INTERNAL duk_bool_t duk_bi_date_parse_string_strptime(duk_hthread *thr, const char *str) { @@ -33832,7 +34852,7 @@ /* Copy to buffer with slack to avoid Valgrind gripes from strptime. */ DUK_ASSERT(str != NULL); - duk_memzero(buf, sizeof(buf)); /* valgrind whine without this */ + duk_memzero(buf, sizeof(buf)); /* valgrind whine without this */ DUK_SNPRINTF(buf, sizeof(buf), "%s", (const char *) str); bufsizeof(buf) - 1 = (char) 0; @@ -33842,10 +34862,16 @@ if (strptime((const char *) buf, "%c", &tm) != NULL) { DUK_DDD(DUK_DDDPRINT("before mktime: tm={sec:%ld,min:%ld,hour:%ld,mday:%ld,mon:%ld,year:%ld," "wday:%ld,yday:%ld,isdst:%ld}", - (long) tm.tm_sec, (long) tm.tm_min, (long) tm.tm_hour, - (long) tm.tm_mday, (long) tm.tm_mon, (long) tm.tm_year, - (long) tm.tm_wday, (long) tm.tm_yday, (long) tm.tm_isdst)); - tm.tm_isdst = -1; /* negative: dst info not available */ + (long) tm.tm_sec, + (long) tm.tm_min, + (long) tm.tm_hour, + (long) tm.tm_mday, + (long) tm.tm_mon, + (long) tm.tm_year, + (long) tm.tm_wday, + (long) tm.tm_yday, + (long) tm.tm_isdst)); + tm.tm_isdst = -1; /* negative: dst info not available */ t = mktime(&tm); DUK_DDD(DUK_DDDPRINT("mktime() -> %ld", (long) t)); @@ -33857,7 +34883,7 @@ return 0; } -#endif /* DUK_USE_DATE_PRS_STRPTIME */ +#endif /* DUK_USE_DATE_PRS_STRPTIME */ #if defined(DUK_USE_DATE_PRS_GETDATE) DUK_INTERNAL duk_bool_t duk_bi_date_parse_string_getdate(duk_hthread *thr, const char *str) { @@ -33884,10 +34910,13 @@ return 0; } -#endif /* DUK_USE_DATE_PRS_GETDATE */ +#endif /* DUK_USE_DATE_PRS_GETDATE */ #if defined(DUK_USE_DATE_FMT_STRFTIME) -DUK_INTERNAL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags) { +DUK_INTERNAL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, + duk_int_t *parts, + duk_int_t tzoffset, + duk_small_uint_t flags) { char bufDUK__STRFTIME_BUF_SIZE; struct tm tm; const char *fmt; @@ -33905,8 +34934,7 @@ * probably not an accurate guarantee of strftime() supporting or not * supporting a large time range (the full ECMAScript range). */ - if (sizeof(time_t) < 8 && - (partsDUK_DATE_IDX_YEAR < 1970 || partsDUK_DATE_IDX_YEAR > 2037)) { + if (sizeof(time_t) < 8 && (partsDUK_DATE_IDX_YEAR < 1970 || partsDUK_DATE_IDX_YEAR > 2037)) { /* be paranoid for 32-bit time values (even avoiding negative ones) */ return 0; } @@ -33915,8 +34943,8 @@ tm.tm_sec = partsDUK_DATE_IDX_SECOND; tm.tm_min = partsDUK_DATE_IDX_MINUTE; tm.tm_hour = partsDUK_DATE_IDX_HOUR; - tm.tm_mday = partsDUK_DATE_IDX_DAY; /* already one-based */ - tm.tm_mon = partsDUK_DATE_IDX_MONTH - 1; /* one-based -> zero-based */ + tm.tm_mday = partsDUK_DATE_IDX_DAY; /* already one-based */ + tm.tm_mon = partsDUK_DATE_IDX_MONTH - 1; /* one-based -> zero-based */ tm.tm_year = partsDUK_DATE_IDX_YEAR - 1900; tm.tm_wday = partsDUK_DATE_IDX_WEEKDAY; tm.tm_isdst = 0; @@ -33936,7 +34964,7 @@ duk_push_string(thr, buf); return 1; } -#endif /* DUK_USE_DATE_FMT_STRFTIME */ +#endif /* DUK_USE_DATE_FMT_STRFTIME */ #if defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME) DUK_INTERNAL duk_double_t duk_bi_date_get_monotonic_time_clock_gettime(void) { @@ -33985,20 +35013,20 @@ res->LowPart = ft->dwLowDateTime; res->HighPart = ft->dwHighDateTime; } -#endif /* DUK_USE_DATE_NOW_WINDOWS_SUBMS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS_SUBMS */ DUK_LOCAL void duk__set_systime_jan1970(SYSTEMTIME *st) { duk_memzero((void *) st, sizeof(*st)); st->wYear = 1970; st->wMonth = 1; - st->wDayOfWeek = 4; /* not sure whether or not needed; Thursday */ + st->wDayOfWeek = 4; /* not sure whether or not needed; Thursday */ st->wDay = 1; DUK_ASSERT(st->wHour == 0); DUK_ASSERT(st->wMinute == 0); DUK_ASSERT(st->wSecond == 0); DUK_ASSERT(st->wMilliseconds == 0); } -#endif /* defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS) */ +#endif /* defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS) */ #if defined(DUK_USE_DATE_NOW_WINDOWS) DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows(void) { @@ -34020,7 +35048,7 @@ */ return (duk_double_t) ((LONGLONG) tmp1.QuadPart - (LONGLONG) tmp2.QuadPart) / 10000.0; } -#endif /* DUK_USE_DATE_NOW_WINDOWS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS */ #if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows_subms(void) { @@ -34042,7 +35070,7 @@ */ return (duk_double_t) ((LONGLONG) tmp1.QuadPart - (LONGLONG) tmp2.QuadPart) / 10000.0; } -#endif /* DUK_USE_DATE_NOW_WINDOWS */ +#endif /* DUK_USE_DATE_NOW_WINDOWS */ #if defined(DUK_USE_DATE_TZO_WINDOWS) DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows(duk_double_t d) { @@ -34067,8 +35095,8 @@ duk__set_systime_jan1970(&st1); duk__convert_systime_to_ularge((const SYSTEMTIME *) &st1, &tmp1); - tmp2.QuadPart = (ULONGLONG) (d * 10000.0); /* millisec -> 100ns units since jan 1, 1970 */ - tmp2.QuadPart += tmp1.QuadPart; /* input 'd' in Windows UTC, 100ns units */ + tmp2.QuadPart = (ULONGLONG) (d * 10000.0); /* millisec -> 100ns units since jan 1, 1970 */ + tmp2.QuadPart += tmp1.QuadPart; /* input 'd' in Windows UTC, 100ns units */ ft1.dwLowDateTime = tmp2.LowPart; ft1.dwHighDateTime = tmp2.HighPart; @@ -34083,9 +35111,9 @@ duk__convert_systime_to_ularge((const SYSTEMTIME *) &st3, &tmp3); /* Positive if local time ahead of UTC. */ - return (duk_int_t) (((LONGLONG) tmp3.QuadPart - (LONGLONG) tmp2.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ + return (duk_int_t) (((LONGLONG) tmp3.QuadPart - (LONGLONG) tmp2.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ } -#endif /* DUK_USE_DATE_TZO_WINDOWS */ +#endif /* DUK_USE_DATE_TZO_WINDOWS */ #if defined(DUK_USE_DATE_TZO_WINDOWS_NO_DST) DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows_no_dst(duk_double_t d) { @@ -34120,17 +35148,19 @@ } duk__convert_systime_to_ularge((const SYSTEMTIME *) &st2, &tmp2); - return (duk_int_t) (((LONGLONG) tmp2.QuadPart - (LONGLONG) tmp1.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ + return (duk_int_t) (((LONGLONG) tmp2.QuadPart - (LONGLONG) tmp1.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */ } -#endif /* DUK_USE_DATE_TZO_WINDOWS_NO_DST */ +#endif /* DUK_USE_DATE_TZO_WINDOWS_NO_DST */ #if defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC) DUK_INTERNAL duk_double_t duk_bi_date_get_monotonic_time_windows_qpc(void) { LARGE_INTEGER count, freq; /* There are legacy issues with QueryPerformanceCounter(): - * - Potential jumps: https://support.microsoft.com/en-us/help/274323/performance-counter-value-may-unexpectedly-leap-forward - * - Differences between cores (XP): https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions + * - Potential jumps: + * https://support.microsoft.com/en-us/help/274323/performance-counter-value-may-unexpectedly-leap-forward + * - Differences between cores (XP): + * https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions * * We avoid these by enabling QPC by default only for Vista or later. */ @@ -34147,7 +35177,7 @@ return 0.0; } } -#endif /* DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC */ +#endif /* DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC */ #line 1 "duk_bi_duktape.c" /* * Duktape built-ins @@ -34211,7 +35241,7 @@ return 1; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_duktape_object_enc(duk_hthread *thr) { duk_hstring *h_str; @@ -34221,7 +35251,7 @@ * non-existent optional parameters. */ - h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons. */ + h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons. */ duk_require_valid_index(thr, 1); if (h_str == DUK_HTHREAD_STRING_HEX(thr)) { @@ -34238,9 +35268,8 @@ 1 /*idx_value*/, 2 /*idx_replacer*/, 3 /*idx_space*/, - DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_ASCII_ONLY | - DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); + DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_ASCII_ONLY | + DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/); #endif #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JC) } else if (h_str == DUK_HTHREAD_STRING_JC(thr)) { @@ -34248,8 +35277,7 @@ 1 /*idx_value*/, 2 /*idx_replacer*/, 3 /*idx_space*/, - DUK_JSON_FLAG_EXT_COMPATIBLE | - DUK_JSON_FLAG_ASCII_ONLY /*flags*/); + DUK_JSON_FLAG_EXT_COMPATIBLE | DUK_JSON_FLAG_ASCII_ONLY /*flags*/); #endif } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -34265,7 +35293,7 @@ * non-existent optional parameters. */ - h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons */ + h_str = duk_require_hstring(thr, 0); /* Could reject symbols, but no point: won't match comparisons */ duk_require_valid_index(thr, 1); if (h_str == DUK_HTHREAD_STRING_HEX(thr)) { @@ -34278,17 +35306,11 @@ DUK_ASSERT_TOP(thr, 2); #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JX) } else if (h_str == DUK_HTHREAD_STRING_JX(thr)) { - duk_bi_json_parse_helper(thr, - 1 /*idx_value*/, - 2 /*idx_replacer*/, - DUK_JSON_FLAG_EXT_CUSTOM /*flags*/); + duk_bi_json_parse_helper(thr, 1 /*idx_value*/, 2 /*idx_replacer*/, DUK_JSON_FLAG_EXT_CUSTOM /*flags*/); #endif #if defined(DUK_USE_JSON_SUPPORT) && defined(DUK_USE_JC) } else if (h_str == DUK_HTHREAD_STRING_JC(thr)) { - duk_bi_json_parse_helper(thr, - 1 /*idx_value*/, - 2 /*idx_replacer*/, - DUK_JSON_FLAG_EXT_COMPATIBLE /*flags*/); + duk_bi_json_parse_helper(thr, 1 /*idx_value*/, 2 /*idx_replacer*/, DUK_JSON_FLAG_EXT_COMPATIBLE /*flags*/); #endif } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -34303,10 +35325,10 @@ DUK_INTERNAL duk_ret_t duk_bi_duktape_object_compact(duk_hthread *thr) { DUK_ASSERT_TOP(thr, 1); duk_compact(thr, 0); - return 1; /* return the argument object */ + return 1; /* return the argument object */ } -#endif /* DUK_USE_DUKTAPE_BUILTIN */ +#endif /* DUK_USE_DUKTAPE_BUILTIN */ #line 1 "duk_bi_encoding.c" /* * WHATWG Encoding API built-ins @@ -34322,17 +35344,17 @@ */ typedef struct { - duk_uint8_t *out; /* where to write next byte(s) */ - duk_codepoint_t lead; /* lead surrogate */ + duk_uint8_t *out; /* where to write next byte(s) */ + duk_codepoint_t lead; /* lead surrogate */ } duk__encode_context; typedef struct { /* UTF-8 decoding state */ - duk_codepoint_t codepoint; /* built up incrementally */ - duk_uint8_t upper; /* max value of next byte (decode error otherwise) */ - duk_uint8_t lower; /* min value of next byte (ditto) */ - duk_uint8_t needed; /* how many more bytes we need */ - duk_uint8_t bom_handled; /* BOM seen or no longer expected */ + duk_codepoint_t codepoint; /* built up incrementally */ + duk_uint8_t upper; /* max value of next byte (decode error otherwise) */ + duk_uint8_t lower; /* min value of next byte (ditto) */ + duk_uint8_t needed; /* how many more bytes we need */ + duk_uint8_t bom_handled; /* BOM seen or no longer expected */ /* Decoder configuration */ duk_uint8_t fatal; @@ -34342,9 +35364,9 @@ /* The signed duk_codepoint_t type is used to signal a decoded codepoint * (>= 0) or various other states using negative values. */ -#define DUK__CP_CONTINUE (-1) /* continue to next byte, no completed codepoint */ -#define DUK__CP_ERROR (-2) /* decoding error */ -#define DUK__CP_RETRY (-3) /* decoding error; retry last byte */ +#define DUK__CP_CONTINUE (-1) /* continue to next byte, no completed codepoint */ +#define DUK__CP_ERROR (-2) /* decoding error */ +#define DUK__CP_RETRY (-3) /* decoding error; retry last byte */ /* * Raw helpers for encoding/decoding @@ -34431,7 +35453,7 @@ } else { /* got a codepoint */ duk_codepoint_t ret; - DUK_ASSERT(dec_ctx->codepoint <= 0x10ffffL); /* Decoding rules guarantee. */ + DUK_ASSERT(dec_ctx->codepoint <= 0x10ffffL); /* Decoding rules guarantee. */ ret = dec_ctx->codepoint; dec_ctx->codepoint = 0x0000L; dec_ctx->needed = 0; @@ -34487,7 +35509,8 @@ } else { /* low surrogate */ if (enc_ctx->lead != 0x0000L) { - codepoint = (duk_codepoint_t) (0x010000L + ((enc_ctx->lead - 0xd800L) << 10) + (codepoint - 0xdc00L)); + codepoint = + (duk_codepoint_t) (0x010000L + ((enc_ctx->lead - 0xd800L) << 10) + (codepoint - 0xdc00L)); enc_ctx->lead = 0x0000L; } else { /* unpaired low surrogate */ @@ -34508,7 +35531,7 @@ */ enc_ctx->out += duk_unicode_encode_xutf8((duk_ucodepoint_t) codepoint, enc_ctx->out); } -#endif /* DUK_USE_ENCODING_BUILTINS */ +#endif /* DUK_USE_ENCODING_BUILTINS */ /* Shared helper for buffer-to-string using a TextDecoder() compatible UTF-8 * decoder. @@ -34537,18 +35560,15 @@ duk_push_fixed_buffer_nozero(thr, 0); duk_replace(thr, 0); } - (void) duk_require_buffer_data(thr, 0, &len); /* Need 'len', avoid pointer. */ + (void) duk_require_buffer_data(thr, 0, &len); /* Need 'len', avoid pointer. */ - if (duk_check_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_NONE)) { + if (duk_check_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_NONE)) { /* Use defaults, treat missing value like undefined. */ } else { - duk_require_type_mask(thr, 1, DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_OBJECT); + duk_require_type_mask(thr, + 1, + DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_LIGHTFUNC | + DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_OBJECT); if (duk_get_prop_literal(thr, 1, "stream")) { stream = duk_to_boolean(thr, -1); } @@ -34566,7 +35586,8 @@ DUK_ERROR_TYPE(thr, DUK_STR_RESULT_TOO_LONG); DUK_WO_NORETURN(return 0;); } - output = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, 3 + (3 * len)); /* used parts will be always manually written over */ + output = + (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, 3 + (3 * len)); /* used parts will be always manually written over */ input = (const duk_uint8_t *) duk_get_buffer_data(thr, 0, &len_tmp); DUK_ASSERT(input != NULL || len == 0); @@ -34598,7 +35619,7 @@ /* Decoding error with or without retry. */ DUK_ASSERT(codepoint == DUK__CP_ERROR || codepoint == DUK__CP_RETRY); if (codepoint == DUK__CP_RETRY) { - --in; /* retry last byte */ + --in; /* retry last byte */ } /* replacement mode: replace with U+FFFD */ codepoint = DUK_UNICODE_CP_REPLACEMENT_CHARACTER; @@ -34631,7 +35652,7 @@ DUK_ASSERT(out <= output + (3 + (3 * len))); } } - duk__utf8_decode_init(dec_ctx); /* Initialize decoding state for potential reuse. */ + duk__utf8_decode_init(dec_ctx); /* Initialize decoding state for potential reuse. */ } /* Output buffer is fixed and thus stable even if there had been @@ -34640,7 +35661,7 @@ duk_push_lstring(thr, (const char *) output, (duk_size_t) (out - output)); return 1; - fail_type: +fail_type: DUK_ERROR_TYPE(thr, DUK_STR_UTF8_DECODE_FAILED); DUK_WO_NORETURN(return 0;); } @@ -34699,7 +35720,7 @@ output = (duk_uint8_t *) duk_push_dynamic_buffer(thr, 3 * len); if (len > 0) { - DUK_ASSERT(duk_is_string(thr, 0)); /* True if len > 0. */ + DUK_ASSERT(duk_is_string(thr, 0)); /* True if len > 0. */ /* XXX: duk_decode_string() is used to process the input * string. For standard ECMAScript strings, represented @@ -34775,7 +35796,7 @@ dec_ctx = (duk__decode_context *) duk_push_fixed_buffer(thr, sizeof(duk__decode_context)); dec_ctx->fatal = (duk_uint8_t) fatal; dec_ctx->ignore_bom = (duk_uint8_t) ignore_bom; - duk__utf8_decode_init(dec_ctx); /* Initializes remaining fields. */ + duk__utf8_decode_init(dec_ctx); /* Initializes remaining fields. */ duk_put_prop_literal(thr, -2, DUK_INTERNAL_SYMBOL("Context")); return 0; @@ -34821,7 +35842,7 @@ dec_ctx = duk__get_textdecoder_context(thr); return duk__decode_helper(thr, dec_ctx); } -#endif /* DUK_USE_ENCODING_BUILTINS */ +#endif /* DUK_USE_ENCODING_BUILTINS */ /* * Internal helper for Node.js Buffer @@ -34835,8 +35856,8 @@ DUK_INTERNAL duk_ret_t duk_textdecoder_decode_utf8_nodejs(duk_hthread *thr) { duk__decode_context dec_ctx; - dec_ctx.fatal = 0; /* use replacement chars */ - dec_ctx.ignore_bom = 1; /* ignore BOMs (matches Node.js Buffer .toString()) */ + dec_ctx.fatal = 0; /* use replacement chars */ + dec_ctx.ignore_bom = 1; /* ignore BOMs (matches Node.js Buffer .toString()) */ duk__utf8_decode_init(&dec_ctx); return duk__decode_helper(thr, &dec_ctx); @@ -34864,9 +35885,8 @@ duk_small_int_t bidx_prototype = duk_get_current_magic(thr); /* same for both error and each subclass like TypeError */ - duk_uint_t flags_and_class = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR); + duk_uint_t flags_and_class = + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR); (void) duk_push_object_helper(thr, flags_and_class, bidx_prototype); @@ -34875,7 +35895,7 @@ */ if (!duk_is_undefined(thr, 0)) { duk_to_string(thr, 0); - duk_dup_0(thr); /* message error message */ + duk_dup_0(thr); /* message error message */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC); } @@ -34934,7 +35954,7 @@ return 1; } duk_push_literal(thr, ": "); - duk_insert(thr, -2); /* ... name ': ' message */ + duk_insert(thr, -2); /* ... name ': ' message */ duk_concat(thr, 3); return 1; @@ -34957,15 +35977,15 @@ */ /* constants arbitrary, chosen for small loads */ -#define DUK__OUTPUT_TYPE_TRACEBACK (-1) -#define DUK__OUTPUT_TYPE_FILENAME 0 -#define DUK__OUTPUT_TYPE_LINENUMBER 1 +#define DUK__OUTPUT_TYPE_TRACEBACK (-1) +#define DUK__OUTPUT_TYPE_FILENAME 0 +#define DUK__OUTPUT_TYPE_LINENUMBER 1 DUK_LOCAL duk_ret_t duk__error_getter_helper(duk_hthread *thr, duk_small_int_t output_type) { duk_idx_t idx_td; - duk_small_int_t i; /* traceback depth fits into 16 bits */ - duk_small_int_t t; /* stack type fits into 16 bits */ - duk_small_int_t count_func = 0; /* traceback depth ensures fits into 16 bits */ + duk_small_int_t i; /* traceback depth fits into 16 bits */ + duk_small_int_t t; /* stack type fits into 16 bits */ + duk_small_int_t count_func = 0; /* traceback depth ensures fits into 16 bits */ const char *str_tailcall = " tailcall"; const char *str_strict = " strict"; const char *str_construct = " construct"; @@ -34973,7 +35993,7 @@ const char *str_directeval = " directeval"; const char *str_empty = ""; - DUK_ASSERT_TOP(thr, 0); /* fixed arg count */ + DUK_ASSERT_TOP(thr, 0); /* fixed arg count */ duk_push_this(thr); duk_xget_owndataprop_stridx_short(thr, -1, DUK_STRIDX_INT_TRACEDATA); @@ -34988,7 +36008,7 @@ if (duk_check_type(thr, idx_td, DUK_TYPE_OBJECT)) { /* Current tracedata contains 2 entries per callstack entry. */ - for (i = 0; ; i += 2) { + for (i = 0;; i += 2) { duk_int_t pc; duk_uint_t line; duk_uint_t flags; @@ -35044,46 +36064,53 @@ /* XXX: Change 'anon' handling here too, to use empty string for anonymous functions? */ /* XXX: Could be improved by coercing to a readable duk_tval (especially string escaping) */ - h_name = duk_get_hstring_notsymbol(thr, -2); /* may be NULL */ + h_name = duk_get_hstring_notsymbol(thr, -2); /* may be NULL */ funcname = (h_name == NULL || h_name == DUK_HTHREAD_STRING_EMPTY_STRING(thr)) ? - "anon" : (const char *) DUK_HSTRING_GET_DATA(h_name); + "anon" : + (const char *) DUK_HSTRING_GET_DATA(h_name); filename = duk_get_string_notsymbol(thr, -1); filename = filename ? filename : ""; DUK_ASSERT(funcname != NULL); DUK_ASSERT(filename != NULL); - h_func = duk_get_hobject(thr, -4); /* NULL for lightfunc */ + h_func = duk_get_hobject(thr, -4); /* NULL for lightfunc */ if (h_func == NULL) { - duk_push_sprintf(thr, "at %s light%s%s%s%s%s", - (const char *) funcname, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s light%s%s%s%s%s", + (const char *) funcname, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } else if (DUK_HOBJECT_HAS_NATFUNC(h_func)) { - duk_push_sprintf(thr, "at %s (%s) native%s%s%s%s%s", - (const char *) funcname, - (const char *) filename, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s (%s) native%s%s%s%s%s", + (const char *) funcname, + (const char *) filename, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } else { - duk_push_sprintf(thr, "at %s (%s:%lu)%s%s%s%s%s", - (const char *) funcname, - (const char *) filename, - (unsigned long) line, - (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), - (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); + duk_push_sprintf( + thr, + "at %s (%s:%lu)%s%s%s%s%s", + (const char *) funcname, + (const char *) filename, + (unsigned long) line, + (const char *) ((flags & DUK_ACT_FLAG_STRICT) ? str_strict : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_TAILCALLED) ? str_tailcall : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_CONSTRUCT) ? str_construct : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_DIRECT_EVAL) ? str_directeval : str_empty), + (const char *) ((flags & DUK_ACT_FLAG_PREVENT_YIELD) ? str_prevyield : str_empty)); } - duk_replace(thr, -5); /* ... v1 v2 name filename str -> ... str v2 name filename */ - duk_pop_3(thr); /* -> ... str */ + duk_replace(thr, -5); /* ... v1 v2 name filename str -> ... str v2 name filename */ + duk_pop_3(thr); /* -> ... str */ } else if (t == DUK_TYPE_STRING) { const char *str_file; @@ -35114,10 +36141,12 @@ * safety issues. */ str_file = (const char *) duk_get_string(thr, -2); - duk_push_sprintf(thr, "at anon (%s:%ld) internal", - (const char *) (str_file ? str_file : "null"), (long) pc); - duk_replace(thr, -3); /* ... v1 v2 str -> ... str v2 */ - duk_pop(thr); /* -> ... str */ + duk_push_sprintf(thr, + "at anon (%s:%ld) internal", + (const char *) (str_file ? str_file : "null"), + (long) pc); + duk_replace(thr, -3); /* ... v1 v2 str -> ... str v2 */ + duk_pop(thr); /* -> ... str */ } else { /* unknown, ignore */ duk_pop_2(thr); @@ -35164,7 +36193,7 @@ return duk__error_getter_helper(thr, DUK__OUTPUT_TYPE_LINENUMBER); } -#else /* DUK_USE_TRACEBACKS */ +#else /* DUK_USE_TRACEBACKS */ /* * Traceback handling when tracebacks disabled. @@ -35195,7 +36224,7 @@ return 0; } -#endif /* DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_TRACEBACKS */ DUK_LOCAL duk_ret_t duk__error_setter_helper(duk_hthread *thr, duk_small_uint_t stridx_key) { /* Attempt to write 'stack', 'fileName', 'lineNumber' works as if @@ -35205,7 +36234,7 @@ * See https://github.com/svaarala/duktape/issues/387. */ - DUK_ASSERT_TOP(thr, 1); /* fixed arg count: value */ + DUK_ASSERT_TOP(thr, 1); /* fixed arg count: value */ duk_push_this(thr); duk_push_hstring_stridx(thr, stridx_key); @@ -35213,13 +36242,13 @@ /* ... obj key value */ - DUK_DD(DUK_DDPRINT("error setter: %!T %!T %!T", - duk_get_tval(thr, -3), duk_get_tval(thr, -2), duk_get_tval(thr, -1))); + DUK_DD(DUK_DDPRINT("error setter: %!T %!T %!T", duk_get_tval(thr, -3), duk_get_tval(thr, -2), duk_get_tval(thr, -1))); - duk_def_prop(thr, -3, DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE | - DUK_DEFPROP_HAVE_ENUMERABLE | /*not enumerable*/ - DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE); + duk_def_prop(thr, + -3, + DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE | + DUK_DEFPROP_HAVE_ENUMERABLE | /*not enumerable*/ + DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE); return 0; } @@ -35267,7 +36296,7 @@ nargs = duk_get_top(thr); for (i = 0; i < nargs; i++) { - duk_to_string(thr, i); /* Rejects Symbols during coercion. */ + duk_to_string(thr, i); /* Rejects Symbols during coercion. */ } if (nargs == 0) { @@ -35277,7 +36306,7 @@ /* XXX: cover this with the generic >1 case? */ duk_push_hstring_empty(thr); } else { - duk_insert(thr, 0); /* arg1 ... argN-1 body -> body arg1 ... argN-1 */ + duk_insert(thr, 0); /* arg1 ... argN-1 body -> body arg1 ... argN-1 */ duk_push_literal(thr, ","); duk_insert(thr, 1); duk_join(thr, nargs - 1); @@ -35294,7 +36323,7 @@ duk_dup_1(thr); duk_push_literal(thr, "){"); duk_dup_0(thr); - duk_push_literal(thr, "\n}"); /* Newline is important to handle trailing // comment. */ + duk_push_literal(thr, "\n}"); /* Newline is important to handle trailing // comment. */ duk_concat(thr, 5); /* body formals source */ @@ -35304,8 +36333,8 @@ /* strictness is not inherited, intentional */ comp_flags = DUK_COMPILE_FUNCEXPR; - duk_push_hstring_stridx(thr, DUK_STRIDX_COMPILE); /* XXX: copy from caller? */ /* XXX: ignored now */ - h_sourcecode = duk_require_hstring(thr, -2); /* no symbol check needed; -2 is concat'd code */ + duk_push_hstring_stridx(thr, DUK_STRIDX_COMPILE); /* XXX: copy from caller? */ /* XXX: ignored now */ + h_sourcecode = duk_require_hstring(thr, -2); /* no symbol check needed; -2 is concat'd code */ duk_js_compile(thr, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_sourcecode), (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sourcecode), @@ -35334,7 +36363,7 @@ return 1; } -#endif /* DUK_USE_FUNCTION_BUILTIN */ +#endif /* DUK_USE_FUNCTION_BUILTIN */ #if defined(DUK_USE_FUNCTION_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_function_prototype_to_string(duk_hthread *thr) { @@ -35400,7 +36429,7 @@ return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } #endif @@ -35442,7 +36471,7 @@ */ DUK_INTERNAL duk_ret_t duk_bi_function_prototype_bind(duk_hthread *thr) { duk_hboundfunc *h_bound; - duk_idx_t nargs; /* bound args, not counting 'this' binding */ + duk_idx_t nargs; /* bound args, not counting 'this' binding */ duk_idx_t bound_nargs; duk_int_t bound_len; duk_tval *tv_prevbound; @@ -35455,7 +36484,7 @@ /* Vararg function, careful arg handling, e.g. thisArg may not * be present. */ - nargs = duk_get_top(thr) - 1; /* actual args, not counting 'this' binding */ + nargs = duk_get_top(thr) - 1; /* actual args, not counting 'this' binding */ if (nargs < 0) { nargs++; duk_push_undefined(thr); @@ -35550,7 +36579,7 @@ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) h_bound, bound_proto); } - DUK_TVAL_INCREF(thr, &h_bound->target); /* old values undefined, no decref needed */ + DUK_TVAL_INCREF(thr, &h_bound->target); /* old values undefined, no decref needed */ DUK_TVAL_INCREF(thr, &h_bound->this_binding); bound_nargs = n_prevbound + nargs; @@ -35575,7 +36604,7 @@ * For lightfuncs, simply read the virtual property. */ duk_get_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH); - bound_len = duk_get_int(thr, -1); /* ES2015: no coercion */ + bound_len = duk_get_int(thr, -1); /* ES2015: no coercion */ if (bound_len < nargs) { bound_len = 0; } else { @@ -35589,8 +36618,8 @@ tv_tmp = thr->valstack_top++; DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_tmp)); DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_tmp)); - DUK_TVAL_SET_U32(tv_tmp, (duk_uint32_t) bound_len); /* in-place update, fastint */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* attrs in E6 Section 9.2.4 */ + DUK_TVAL_SET_U32(tv_tmp, (duk_uint32_t) bound_len); /* in-place update, fastint */ + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* attrs in E6 Section 9.2.4 */ /* XXX: could these be virtual? */ /* Caller and arguments must use the same thrower, ThrowTypeError. */ @@ -35598,7 +36627,7 @@ duk_xdef_prop_stridx_thrower(thr, -1, DUK_STRIDX_LC_ARGUMENTS); /* Function name and fileName (non-standard). */ - duk_push_literal(thr, "bound "); /* ES2015 19.2.3.2. */ + duk_push_literal(thr, "bound "); /* ES2015 19.2.3.2. */ duk_get_prop_stridx(thr, -3, DUK_STRIDX_NAME); if (!duk_is_string_notsymbol(thr, -1)) { /* ES2015 has requirement to check that .name of target is a string @@ -35619,7 +36648,7 @@ return 1; } -#endif /* DUK_USE_FUNCTION_BUILTIN */ +#endif /* DUK_USE_FUNCTION_BUILTIN */ /* %NativeFunctionPrototype% .length getter. */ DUK_INTERNAL duk_ret_t duk_bi_native_function_length(duk_hthread *thr) { @@ -35650,7 +36679,7 @@ } return 1; - fail_type: +fail_type: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -35679,7 +36708,7 @@ } return 1; - fail_type: +fail_type: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -35692,7 +36721,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ #line 1 "duk_bi_global.c" /* * Global object built-ins @@ -35712,73 +36741,71 @@ /* Macros for creating and checking bitmasks for character encoding. * Bit number is a bit counterintuitive, but minimizes code size. */ -#define DUK__MKBITS(a,b,c,d,e,f,g,h) ((duk_uint8_t) ( \ - ((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | \ - ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7) \ - )) -#define DUK__CHECK_BITMASK(table,cp) ((table)(cp) >> 3 & (1 << ((cp) & 0x07))) +#define DUK__MKBITS(a, b, c, d, e, f, g, h) \ + ((duk_uint8_t) (((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7))) +#define DUK__CHECK_BITMASK(table, cp) ((table)(cp) >> 3 & (1 << ((cp) &0x07))) /* E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#' */ DUK_LOCAL const duk_uint8_t duk__encode_uriunescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 1, 0, 1, 1, 0, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 1, 0, 1, 1, 0, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.4: uriUnescaped */ DUK_LOCAL const duk_uint8_t duk__encode_uricomponent_unescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 1, 0, 0, 0, 0, 0, 1), DUK__MKBITS(1, 1, 1, 0, 0, 1, 1, 0), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 1, 0, 0, 0, 0, 0, 1), DUK__MKBITS(1, 1, 1, 0, 0, 1, 1, 0), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 1, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.1: uriReserved + '#' */ DUK_LOCAL const duk_uint8_t duk__decode_uri_reserved_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 1, 1, 0, 1, 0), DUK__MKBITS(0, 0, 0, 1, 1, 0, 0, 1), /* 0x20-0x2f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ - DUK__MKBITS(1, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 1, 1, 0, 1, 0), DUK__MKBITS(0, 0, 0, 1, 1, 0, 0, 1), /* 0x20-0x2f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 0, 1), /* 0x30-0x3f */ + DUK__MKBITS(1, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ }; /* E5.1 Section 15.1.3.2: empty */ DUK_LOCAL const duk_uint8_t duk__decode_uri_component_reserved_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x20-0x2f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x20-0x2f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x40-0x4f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x50-0x5f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x60-0x6f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x70-0x7f */ }; #if defined(DUK_USE_SECTION_B) /* E5.1 Section B.2.2, step 7. */ DUK_LOCAL const duk_uint8_t duk__escape_unescaped_table16 = { - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ - DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 1, 1), /* 0x20-0x2f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ - DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ - DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 0) /* 0x70-0x7f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x00-0x0f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), /* 0x10-0x1f */ + DUK__MKBITS(0, 0, 0, 0, 0, 0, 0, 0), DUK__MKBITS(0, 0, 1, 1, 0, 1, 1, 1), /* 0x20-0x2f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 0, 0, 0, 0, 0, 0), /* 0x30-0x3f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x40-0x4f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 1), /* 0x50-0x5f */ + DUK__MKBITS(0, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), /* 0x60-0x6f */ + DUK__MKBITS(1, 1, 1, 1, 1, 1, 1, 1), DUK__MKBITS(1, 1, 1, 0, 0, 0, 0, 0) /* 0x70-0x7f */ }; -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ typedef struct { duk_hthread *thr; @@ -35819,7 +36846,7 @@ tfm_ctx->h_str = duk_to_hstring(thr, 0); DUK_ASSERT(tfm_ctx->h_str != NULL); - DUK_BW_INIT_PUSHBUF(thr, &tfm_ctx->bw, DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str)); /* initial size guess */ + DUK_BW_INIT_PUSHBUF(thr, &tfm_ctx->bw, DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str)); /* initial size guess */ tfm_ctx->p_start = DUK_HSTRING_GET_DATA(tfm_ctx->h_str); tfm_ctx->p_end = tfm_ctx->p_start + DUK_HSTRING_GET_BYTELEN(tfm_ctx->h_str); @@ -35832,7 +36859,7 @@ DUK_BW_COMPACT(thr, &tfm_ctx->bw); - (void) duk_buffer_to_string(thr, -1); /* Safe if transform is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if transform is safe. */ return 1; } @@ -35858,7 +36885,11 @@ goto uri_error; } else if (cp >= 0xd800L && cp <= 0xdbffL) { /* Needs lookahead */ - if (duk_unicode_decode_xutf8(tfm_ctx->thr, &tfm_ctx->p, tfm_ctx->p_start, tfm_ctx->p_end, (duk_ucodepoint_t *) &cp2) == 0) { + if (duk_unicode_decode_xutf8(tfm_ctx->thr, + &tfm_ctx->p, + tfm_ctx->p_start, + tfm_ctx->p_end, + (duk_ucodepoint_t *) &cp2) == 0) { goto uri_error; } if (!(cp2 >= 0xdc00L && cp2 <= 0xdfffL)) { @@ -35889,12 +36920,12 @@ &tfm_ctx->bw, DUK_ASC_PERCENT, (duk_uint8_t) duk_uc_nybblest >> 4, - (duk_uint8_t) duk_uc_nybblest & 0x0f); + (duk_uint8_t) duk_uc_nybblest & 0x0f); } return; - uri_error: +uri_error: DUK_ERROR_URI(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -35903,7 +36934,7 @@ const duk_uint8_t *reserved_table = (const duk_uint8_t *) udata; duk_small_uint_t utf8_blen; duk_codepoint_t min_cp; - duk_small_int_t t; /* must be signed */ + duk_small_int_t t; /* must be signed */ duk_small_uint_t i; /* Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH, @@ -35911,12 +36942,12 @@ */ DUK_BW_ENSURE(tfm_ctx->thr, &tfm_ctx->bw, - (DUK_UNICODE_MAX_XUTF8_LENGTH >= 2 * DUK_UNICODE_MAX_CESU8_BMP_LENGTH ? - DUK_UNICODE_MAX_XUTF8_LENGTH : DUK_UNICODE_MAX_CESU8_BMP_LENGTH)); + (DUK_UNICODE_MAX_XUTF8_LENGTH >= 2 * DUK_UNICODE_MAX_CESU8_BMP_LENGTH ? DUK_UNICODE_MAX_XUTF8_LENGTH : + DUK_UNICODE_MAX_CESU8_BMP_LENGTH)); if (cp == (duk_codepoint_t) '%') { const duk_uint8_t *p = tfm_ctx->p; - duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ + duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ DUK_DDD(DUK_DDDPRINT("percent encoding, left=%ld", (long) left)); @@ -35934,11 +36965,7 @@ if (DUK__CHECK_BITMASK(reserved_table, t)) { /* decode '%xx' to '%xx' if decoded char in reserved set */ DUK_ASSERT(tfm_ctx->p - 1 >= tfm_ctx->p_start); - DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr, - &tfm_ctx->bw, - DUK_ASC_PERCENT, - p0, - p1); + DUK_BW_WRITE_RAW_U8_3(tfm_ctx->thr, &tfm_ctx->bw, DUK_ASC_PERCENT, p0, p1); } else { DUK_BW_WRITE_RAW_U8(tfm_ctx->thr, &tfm_ctx->bw, (duk_uint8_t) t); } @@ -35989,7 +37016,10 @@ /* p points to digit part ('%xy', p points to 'x') */ t = duk__decode_hex_escape(p, 2); DUK_DDD(DUK_DDDPRINT("i=%ld utf8_blen=%ld cp=%ld t=0x%02lx", - (long) i, (long) utf8_blen, (long) cp, (unsigned long) t)); + (long) i, + (long) utf8_blen, + (long) cp, + (unsigned long) t)); if (t < 0) { goto uri_error; } @@ -35999,7 +37029,7 @@ cp = (cp << 6) + (t & 0x3f); p += 3; } - p--; /* p overshoots */ + p--; /* p overshoots */ tfm_ctx->p = p; DUK_DDD(DUK_DDDPRINT("final cp=%ld, min_cp=%ld", (long) cp, (long) min_cp)); @@ -36033,7 +37063,7 @@ } return; - uri_error: +uri_error: DUK_ERROR_URI(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -36074,7 +37104,7 @@ return; - esc_error: +esc_error: DUK_ERROR_TYPE(tfm_ctx->thr, DUK_STR_INVALID_INPUT); DUK_WO_NORETURN(return;); } @@ -36086,14 +37116,12 @@ if (cp == (duk_codepoint_t) '%') { const duk_uint8_t *p = tfm_ctx->p; - duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ + duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */ - if (left >= 5 && p0 == 'u' && - ((t = duk__decode_hex_escape(p + 1, 4)) >= 0)) { + if (left >= 5 && p0 == 'u' && ((t = duk__decode_hex_escape(p + 1, 4)) >= 0)) { cp = (duk_codepoint_t) t; tfm_ctx->p += 5; - } else if (left >= 2 && - ((t = duk__decode_hex_escape(p, 2)) >= 0)) { + } else if (left >= 2 && ((t = duk__decode_hex_escape(p, 2)) >= 0)) { cp = (duk_codepoint_t) t; tfm_ctx->p += 2; } @@ -36101,7 +37129,7 @@ DUK_BW_WRITE_ENSURE_XUTF8(tfm_ctx->thr, &tfm_ctx->bw, cp); } -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ /* * Eval @@ -36126,11 +37154,11 @@ duk_int_t level = -2; duk_small_uint_t call_flags; - DUK_ASSERT(duk_get_top(thr) == 1 || duk_get_top(thr) == 2); /* 2 when called by debugger */ - DUK_ASSERT(thr->callstack_top >= 1); /* at least this function exists */ + DUK_ASSERT(duk_get_top(thr) == 1 || duk_get_top(thr) == 2); /* 2 when called by debugger */ + DUK_ASSERT(thr->callstack_top >= 1); /* at least this function exists */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT((thr->callstack_curr->flags & DUK_ACT_FLAG_DIRECT_EVAL) == 0 || /* indirect eval */ - (thr->callstack_top >= 2)); /* if direct eval, calling activation must exist */ + (thr->callstack_top >= 2)); /* if direct eval, calling activation must exist */ /* * callstack_top - 1 --> this function @@ -36143,32 +37171,31 @@ h = duk_get_hstring_notsymbol(thr, 0); if (!h) { /* Symbol must be returned as is, like any non-string values. */ - return 1; /* return arg as-is */ + return 1; /* return arg as-is */ } #if defined(DUK_USE_DEBUGGER_SUPPORT) /* NOTE: level is used only by the debugger and should never be present * for an ECMAScript eval(). */ - DUK_ASSERT(level == -2); /* by default, use caller's environment */ + DUK_ASSERT(level == -2); /* by default, use caller's environment */ if (duk_get_top(thr) >= 2 && duk_is_number(thr, 1)) { level = duk_get_int(thr, 1); } - DUK_ASSERT(level <= -2); /* This is guaranteed by debugger code. */ + DUK_ASSERT(level <= -2); /* This is guaranteed by debugger code. */ #endif /* source */ comp_flags = DUK_COMPILE_EVAL; - act_eval = thr->callstack_curr; /* this function */ + act_eval = thr->callstack_curr; /* this function */ DUK_ASSERT(act_eval != NULL); act_caller = duk_hthread_get_activation_for_level(thr, level); if (act_caller != NULL) { /* Have a calling activation, check for direct eval (otherwise * assume indirect eval. */ - if ((act_caller->flags & DUK_ACT_FLAG_STRICT) && - (act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL)) { + if ((act_caller->flags & DUK_ACT_FLAG_STRICT) && (act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL)) { /* Only direct eval inherits strictness from calling code * (E5.1 Section 10.1.1). */ @@ -36178,11 +37205,8 @@ DUK_ASSERT((act_eval->flags & DUK_ACT_FLAG_DIRECT_EVAL) == 0); } - duk_push_hstring_stridx(thr, DUK_STRIDX_INPUT); /* XXX: copy from caller? */ - duk_js_compile(thr, - (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), - (duk_size_t) DUK_HSTRING_GET_BYTELEN(h), - comp_flags); + duk_push_hstring_stridx(thr, DUK_STRIDX_INPUT); /* XXX: copy from caller? */ + duk_js_compile(thr, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), (duk_size_t) DUK_HSTRING_GET_BYTELEN(h), comp_flags); func = (duk_hcompfunc *) duk_known_hobject(thr, -1); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) func)); @@ -36215,9 +37239,9 @@ act_lex_env = act_caller->lex_env; - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); @@ -36229,7 +37253,7 @@ outer_lex_env = (duk_hobject *) new_env; outer_var_env = (duk_hobject *) new_env; - duk_insert(thr, 0); /* stash to bottom of value stack to keep new_env reachable for duration of eval */ + duk_insert(thr, 0); /* stash to bottom of value stack to keep new_env reachable for duration of eval */ /* compiler's responsibility */ DUK_ASSERT(DUK_HOBJECT_HAS_NEWENV((duk_hobject *) func)); @@ -36265,7 +37289,8 @@ duk_tval *tv; DUK_ASSERT(thr->callstack_top >= 2); DUK_ASSERT(act_caller != NULL); - tv = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act_caller->bottom_byteoff - sizeof(duk_tval)); /* this is just beneath bottom */ + tv = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act_caller->bottom_byteoff - + sizeof(duk_tval)); /* this is just beneath bottom */ DUK_ASSERT(tv >= thr->valstack); duk_push_tval(thr, tv); } @@ -36304,19 +37329,15 @@ duk_small_uint_t s2n_flags; DUK_ASSERT_TOP(thr, 2); - duk_to_string(thr, 0); /* Reject symbols. */ + duk_to_string(thr, 0); /* Reject symbols. */ radix = duk_to_int32(thr, 1); /* While parseInt() recognizes 0xdeadbeef, it doesn't recognize * ES2015 0o123 or 0b10001. */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_GARBAGE | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO | - DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_GARBAGE | DUK_S2N_FLAG_ALLOW_PLUS | DUK_S2N_FLAG_ALLOW_MINUS | + DUK_S2N_FLAG_ALLOW_LEADING_ZERO | DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT; /* Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT. * @@ -36340,35 +37361,28 @@ duk_numconv_parse(thr, (duk_small_int_t) radix, s2n_flags); return 1; - ret_nan: +ret_nan: duk_push_nan(thr); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ #if defined(DUK_USE_GLOBAL_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_global_object_parse_float(duk_hthread *thr) { duk_small_uint_t s2n_flags; DUK_ASSERT_TOP(thr, 1); - duk_to_string(thr, 0); /* Reject symbols. */ + duk_to_string(thr, 0); /* Reject symbols. */ /* XXX: check flags */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_GARBAGE | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_INF | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_GARBAGE | DUK_S2N_FLAG_ALLOW_PLUS | + DUK_S2N_FLAG_ALLOW_MINUS | DUK_S2N_FLAG_ALLOW_INF | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_LEADING_ZERO; duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ /* * Number checkers @@ -36380,7 +37394,7 @@ duk_push_boolean(thr, (duk_bool_t) DUK_ISNAN(d)); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ #if defined(DUK_USE_GLOBAL_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_global_object_is_finite(duk_hthread *thr) { @@ -36388,7 +37402,7 @@ duk_push_boolean(thr, (duk_bool_t) DUK_ISFINITE(d)); return 1; } -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ /* * URI handling @@ -36400,7 +37414,9 @@ } DUK_INTERNAL duk_ret_t duk_bi_global_object_decode_uri_component(duk_hthread *thr) { - return duk__transform_helper(thr, duk__transform_callback_decode_uri, (const void *) duk__decode_uri_component_reserved_table); + return duk__transform_helper(thr, + duk__transform_callback_decode_uri, + (const void *) duk__decode_uri_component_reserved_table); } DUK_INTERNAL duk_ret_t duk_bi_global_object_encode_uri(duk_hthread *thr) { @@ -36408,7 +37424,9 @@ } DUK_INTERNAL duk_ret_t duk_bi_global_object_encode_uri_component(duk_hthread *thr) { - return duk__transform_helper(thr, duk__transform_callback_encode_uri, (const void *) duk__encode_uricomponent_unescaped_table); + return duk__transform_helper(thr, + duk__transform_callback_encode_uri, + (const void *) duk__encode_uricomponent_unescaped_table); } #if defined(DUK_USE_SECTION_B) @@ -36419,8 +37437,8 @@ DUK_INTERNAL duk_ret_t duk_bi_global_object_unescape(duk_hthread *thr) { return duk__transform_helper(thr, duk__transform_callback_unescape, (const void *) NULL); } -#endif /* DUK_USE_SECTION_B */ -#endif /* DUK_USE_GLOBAL_BUILTIN */ +#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_GLOBAL_BUILTIN */ /* automatic undefs */ #undef DUK__CHECK_BITMASK @@ -36450,11 +37468,11 @@ * Local defines and forward declarations. */ -#define DUK__JSON_DECSTR_BUFSIZE 128 -#define DUK__JSON_DECSTR_CHUNKSIZE 64 -#define DUK__JSON_ENCSTR_CHUNKSIZE 64 +#define DUK__JSON_DECSTR_BUFSIZE 128 +#define DUK__JSON_DECSTR_CHUNKSIZE 64 +#define DUK__JSON_ENCSTR_CHUNKSIZE 64 #define DUK__JSON_STRINGIFY_BUFSIZE 128 -#define DUK__JSON_MAX_ESC_LEN 10 /* '\Udeadbeef' */ +#define DUK__JSON_MAX_ESC_LEN 10 /* '\Udeadbeef' */ DUK_LOCAL_DECL void duk__json_dec_syntax_error(duk_json_dec_ctx *js_ctx); DUK_LOCAL_DECL void duk__json_dec_eat_white(duk_json_dec_ctx *js_ctx); @@ -36524,103 +37542,88 @@ * 0xa0 ... 0xff: backslash + one char */ - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xe2, 0xf4, 0xee, 0x80, 0xe6, 0xf2, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x20, 0x21, 0xa2, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0xdc, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, - 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xe2, 0xf4, 0xee, 0x80, 0xe6, 0xf2, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x20, 0x21, 0xa2, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0xdc, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81 }; -#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ -DUK_LOCAL const duk_uint8_t duk__json_quotestr_esc14 = { - DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, - DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, - DUK_ASC_LC_B, DUK_ASC_LC_T, DUK_ASC_LC_N, DUK_ASC_NUL, - DUK_ASC_LC_F, DUK_ASC_LC_R -}; -#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +DUK_LOCAL const duk_uint8_t duk__json_quotestr_esc14 = { DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, + DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_NUL, DUK_ASC_LC_B, DUK_ASC_LC_T, + DUK_ASC_LC_N, DUK_ASC_NUL, DUK_ASC_LC_F, DUK_ASC_LC_R }; +#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ #if defined(DUK_USE_JSON_DECSTRING_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_decstr_lookup256 = { /* 0x00: slow path * other: as is */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x20, 0x21, 0x00, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x00, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x21, 0x00, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x00, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, + 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; -#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ +#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ #if defined(DUK_USE_JSON_EATWHITE_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_eatwhite_lookup256 = { /* 0x00: finish (non-white) * 0x01: continue */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ #if defined(DUK_USE_JSON_DECNUMBER_FASTPATH) DUK_LOCAL const duk_uint8_t duk__json_decnumber_lookup256 = { /* 0x00: finish (not part of number) * 0x01: continue */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ +#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ /* * Parsing implementation. @@ -36640,8 +37643,7 @@ * hidden, unfortunately, but we'll have an offset which * is often quite enough. */ - DUK_ERROR_FMT1(js_ctx->thr, DUK_ERR_SYNTAX_ERROR, DUK_STR_FMT_INVALID_JSON, - (long) (js_ctx->p - js_ctx->p_start)); + DUK_ERROR_FMT1(js_ctx->thr, DUK_ERR_SYNTAX_ERROR, DUK_STR_FMT_INVALID_JSON, (long) (js_ctx->p - js_ctx->p_start)); DUK_WO_NORETURN(return;); } @@ -36658,18 +37660,18 @@ /* This fast path is pretty marginal in practice. * XXX: candidate for removal. */ - DUK_ASSERT(duk__json_eatwhite_lookup0x00 == 0x00); /* end-of-input breaks */ + DUK_ASSERT(duk__json_eatwhite_lookup0x00 == 0x00); /* end-of-input breaks */ if (duk__json_eatwhite_lookupt == 0) { break; } -#else /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#else /* DUK_USE_JSON_EATWHITE_FASTPATH */ if (!(t == 0x20 || t == 0x0a || t == 0x0d || t == 0x09)) { /* NUL also comes here. Comparison order matters, 0x20 * is most common whitespace. */ break; } -#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ +#endif /* DUK_USE_JSON_EATWHITE_FASTPATH */ p++; } js_ctx->p = p; @@ -36703,8 +37705,7 @@ /* XXX: share helper from lexer; duk_lexer.c / hexval(). */ x = duk__json_dec_get(js_ctx); - DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%ld, n=%ld, res=%ld, x=%ld", - (long) i, (long) n, (long) res, (long) x)); + DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%ld, n=%ld, res=%ld, x=%ld", (long) i, (long) n, (long) res, (long) x)); /* x == 0x00 (EOF) causes syntax_error */ DUK_ASSERT(duk_hex_dectab0 == -1); @@ -36720,7 +37721,7 @@ DUK_DDD(DUK_DDDPRINT("final hex decoded value: %ld", (long) res)); return res; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); return 0; @@ -36741,7 +37742,7 @@ DUK_ASSERT(h != NULL); p = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h) + 1; - DUK_ASSERT(*(js_ctx->p - 1) == *(p - 1)); /* first character has been matched */ + DUK_ASSERT(*(js_ctx->p - 1) == *(p - 1)); /* first character has been matched */ for (;;) { x = *p; @@ -36758,7 +37759,7 @@ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -36772,14 +37773,27 @@ */ cp = (duk_uint_fast32_t) duk__json_dec_get(js_ctx); switch (cp) { - case DUK_ASC_BACKSLASH: break; - case DUK_ASC_DOUBLEQUOTE: break; - case DUK_ASC_SLASH: break; - case DUK_ASC_LC_T: cp = 0x09; break; - case DUK_ASC_LC_N: cp = 0x0a; break; - case DUK_ASC_LC_R: cp = 0x0d; break; - case DUK_ASC_LC_F: cp = 0x0c; break; - case DUK_ASC_LC_B: cp = 0x08; break; + case DUK_ASC_BACKSLASH: + break; + case DUK_ASC_DOUBLEQUOTE: + break; + case DUK_ASC_SLASH: + break; + case DUK_ASC_LC_T: + cp = 0x09; + break; + case DUK_ASC_LC_N: + cp = 0x0a; + break; + case DUK_ASC_LC_R: + cp = 0x0d; + break; + case DUK_ASC_LC_F: + cp = 0x0c; + break; + case DUK_ASC_LC_B: + cp = 0x08; + break; case DUK_ASC_LC_U: { cp = duk__json_dec_decode_hex_escape(js_ctx, 4); break; @@ -36789,7 +37803,7 @@ if (js_ctx->flag_ext_custom) { cp = duk__json_dec_decode_hex_escape(js_ctx, 8); } else { - return 1; /* syntax error */ + return 1; /* syntax error */ } break; } @@ -36797,14 +37811,14 @@ if (js_ctx->flag_ext_custom) { cp = duk__json_dec_decode_hex_escape(js_ctx, 2); } else { - return 1; /* syntax error */ + return 1; /* syntax error */ } break; } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ default: /* catches EOF (0x00) */ - return 1; /* syntax error */ + return 1; /* syntax error */ } DUK_RAW_WRITEINC_XUTF8(*ext_p, cp); @@ -36846,7 +37860,7 @@ /* Ensure space for 1:1 output plus one escape. */ q = DUK_BW_ENSURE_RAW(js_ctx->thr, bw, safe + DUK_UNICODE_MAX_XUTF8_LENGTH, q); - p = js_ctx->p; /* temp copy, write back for next loop */ + p = js_ctx->p; /* temp copy, write back for next loop */ for (;;) { if (safe == 0) { js_ctx->p = p; @@ -36881,8 +37895,8 @@ } } } - found_quote: -#else /* DUK_USE_JSON_DECSTRING_FASTPATH */ +found_quote: +#else /* DUK_USE_JSON_DECSTRING_FASTPATH */ for (;;) { duk_uint8_t x; @@ -36903,16 +37917,16 @@ *q++ = (duk_uint8_t) x; } } -#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ +#endif /* DUK_USE_JSON_DECSTRING_FASTPATH */ DUK_BW_SETPTR_AND_COMPACT(js_ctx->thr, bw, q); - (void) duk_buffer_to_string(thr, -1); /* Safe if input string is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if input string is safe. */ /* ... str */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -36928,7 +37942,7 @@ /* Caller has already eaten the first char so backtrack one byte. */ - js_ctx->p--; /* safe */ + js_ctx->p--; /* safe */ p = js_ctx->p; /* Here again we parse bytes, and non-ASCII UTF-8 will cause end of @@ -36960,7 +37974,7 @@ /* ... str */ } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) DUK_LOCAL void duk__json_dec_pointer(duk_json_dec_ctx *js_ctx) { @@ -37003,17 +38017,17 @@ voidptr = NULL; (void) DUK_SSCANF((const char *) js_ctx->p, DUK_STR_FMT_PTR, &voidptr); duk_push_pointer(thr, voidptr); - js_ctx->p = p + 1; /* skip ')' */ + js_ctx->p = p + 1; /* skip ')' */ /* ... ptr */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) DUK_LOCAL void duk__json_dec_buffer(duk_json_dec_ctx *js_ctx) { @@ -37061,17 +38075,17 @@ duk_memcpy((void *) buf, (const void *) js_ctx->p, src_len); duk_hex_decode(thr, -1); - js_ctx->p = p + 1; /* skip '|' */ + js_ctx->p = p + 1; /* skip '|' */ /* ... buf */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ /* Parse a number, other than NaN or +/- Infinity */ DUK_LOCAL void duk__json_dec_number(duk_json_dec_ctx *js_ctx) { @@ -37094,47 +38108,45 @@ x = *p; DUK_DDD(DUK_DDDPRINT("parse_number: p_start=%p, p=%p, p_end=%p, x=%ld", - (const void *) p_start, (const void *) p, - (const void *) js_ctx->p_end, (long) x)); + (const void *) p_start, + (const void *) p, + (const void *) js_ctx->p_end, + (long) x)); #if defined(DUK_USE_JSON_DECNUMBER_FASTPATH) /* This fast path is pretty marginal in practice. * XXX: candidate for removal. */ - DUK_ASSERT(duk__json_decnumber_lookup0x00 == 0x00); /* end-of-input breaks */ + DUK_ASSERT(duk__json_decnumber_lookup0x00 == 0x00); /* end-of-input breaks */ if (duk__json_decnumber_lookupx == 0) { break; } -#else /* DUK_USE_JSON_DECNUMBER_FASTPATH */ +#else /* DUK_USE_JSON_DECNUMBER_FASTPATH */ if (!((x >= DUK_ASC_0 && x <= DUK_ASC_9) || - (x == DUK_ASC_PERIOD || x == DUK_ASC_LC_E || - x == DUK_ASC_UC_E || x == DUK_ASC_MINUS || x == DUK_ASC_PLUS))) { + (x == DUK_ASC_PERIOD || x == DUK_ASC_LC_E || x == DUK_ASC_UC_E || x == DUK_ASC_MINUS || x == DUK_ASC_PLUS))) { /* Plus sign must be accepted for positive exponents * (e.g. '1.5e+2'). This clause catches NULs. */ break; } -#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ - p++; /* safe, because matched (NUL causes a break) */ +#endif /* DUK_USE_JSON_DECNUMBER_FASTPATH */ + p++; /* safe, because matched (NUL causes a break) */ } js_ctx->p = p; DUK_ASSERT(js_ctx->p > p_start); duk_push_lstring(thr, (const char *) p_start, (duk_size_t) (p - p_start)); - s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_MINUS | /* but don't allow leading plus */ + s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_MINUS | /* but don't allow leading plus */ DUK_S2N_FLAG_ALLOW_FRAC; - DUK_DDD(DUK_DDDPRINT("parse_number: string before parsing: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_number: string before parsing: %!T", (duk_tval *) duk_get_tval(thr, -1))); duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); if (duk_is_nan(thr, -1)) { duk__json_dec_syntax_error(js_ctx); } DUK_ASSERT(duk_is_number(thr, -1)); - DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T", (duk_tval *) duk_get_tval(thr, -1))); /* ... num */ } @@ -37147,7 +38159,7 @@ duk_native_stack_check(thr); - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_ERROR_RANGE(thr, DUK_STR_DEC_RECLIMIT); @@ -37166,7 +38178,7 @@ DUK_LOCAL void duk__json_dec_object(duk_json_dec_ctx *js_ctx) { duk_hthread *thr = js_ctx->thr; - duk_int_t key_count; /* XXX: a "first" flag would suffice */ + duk_int_t key_count; /* XXX: a "first" flag would suffice */ duk_uint8_t x; DUK_DDD(DUK_DDDPRINT("parse_object")); @@ -37183,7 +38195,8 @@ DUK_DDD(DUK_DDDPRINT("parse_object: obj=%!T, x=%ld, key_count=%ld", (duk_tval *) duk_get_tval(thr, -1), - (long) x, (long) key_count)); + (long) x, + (long) key_count)); /* handle comma and closing brace */ @@ -37208,8 +38221,7 @@ if (x == DUK_ASC_DOUBLEQUOTE) { duk__json_dec_string(js_ctx); #if defined(DUK_USE_JX) - } else if (js_ctx->flag_ext_custom && - duk_unicode_is_identifier_start((duk_codepoint_t) x)) { + } else if (js_ctx->flag_ext_custom && duk_unicode_is_identifier_start((duk_codepoint_t) x)) { duk__json_dec_plain_string(js_ctx); #endif } else { @@ -37236,13 +38248,12 @@ /* ... obj */ - DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_dec_objarr_exit(js_ctx); return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -37266,7 +38277,8 @@ DUK_DDD(DUK_DDDPRINT("parse_array: arr=%!T, x=%ld, arr_idx=%ld", (duk_tval *) duk_get_tval(thr, -1), - (long) x, (long) arr_idx)); + (long) x, + (long) arr_idx)); /* handle comma and closing bracket */ @@ -37280,7 +38292,7 @@ /* accept anything, expect first value (EOF will be * caught by duk__json_dec_value() below. */ - js_ctx->p--; /* backtrack (safe) */ + js_ctx->p--; /* backtrack (safe) */ } else { /* catches EOF (NUL) and initial comma */ goto syntax_error; @@ -37304,13 +38316,12 @@ /* ... arr */ - DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_dec_objarr_exit(js_ctx); return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -37330,14 +38341,14 @@ } else if ((x >= DUK_ASC_0 && x <= DUK_ASC_9) || (x == DUK_ASC_MINUS)) { #if defined(DUK_USE_JX) if (js_ctx->flag_ext_custom && x == DUK_ASC_MINUS && duk__json_dec_peek(js_ctx) == DUK_ASC_UC_I) { - duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY); /* "-Infinity", '-' has been eaten */ + duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY); /* "-Infinity", '-' has been eaten */ duk_push_number(thr, -DUK_DOUBLE_INFINITY); } else { #else - { /* unconditional block */ + { /* unconditional block */ #endif /* We already ate 'x', so backup one byte. */ - js_ctx->p--; /* safe */ + js_ctx->p--; /* safe */ duk__json_dec_number(js_ctx); } } else if (x == DUK_ASC_LC_T) { @@ -37378,7 +38389,7 @@ /* ... val */ return; - syntax_error: +syntax_error: duk__json_dec_syntax_error(js_ctx); DUK_UNREACHABLE(); } @@ -37401,7 +38412,7 @@ (duk_tval *) duk_get_tval(thr, -1))); duk_dup_top(thr); - duk_get_prop(thr, -3); /* -> ... holder name val */ + duk_get_prop(thr, -3); /* -> ... holder name val */ h = duk_get_hobject(thr, -1); if (h != NULL) { @@ -37411,13 +38422,17 @@ /* ... holder name val */ DUK_DDD(DUK_DDDPRINT("walk: array, top=%ld, i=%ld, arr_len=%ld, holder=%!T, name=%!T, val=%!T", - (long) duk_get_top(thr), (long) i, (long) arr_len, - (duk_tval *) duk_get_tval(thr, -3), (duk_tval *) duk_get_tval(thr, -2), + (long) duk_get_top(thr), + (long) i, + (long) arr_len, + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); duk_dup_top(thr); - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... holder name val val ToString(i) */ - duk__json_dec_reviver_walk(js_ctx); /* -> ... holder name val new_elem */ + (void) duk_push_uint_to_hstring(thr, + (duk_uint_t) i); /* -> ... holder name val val ToString(i) */ + duk__json_dec_reviver_walk(js_ctx); /* -> ... holder name val new_elem */ if (duk_is_undefined(thr, -1)) { duk_pop(thr); @@ -37435,9 +38450,12 @@ duk_enum(thr, -1, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); while (duk_next(thr, -1 /*enum_index*/, 0 /*get_value*/)) { DUK_DDD(DUK_DDDPRINT("walk: object, top=%ld, holder=%!T, name=%!T, val=%!T, enum=%!iT, obj_key=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -5), - (duk_tval *) duk_get_tval(thr, -4), (duk_tval *) duk_get_tval(thr, -3), - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, -5), + (duk_tval *) duk_get_tval(thr, -4), + (duk_tval *) duk_get_tval(thr, -3), + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); /* ... holder name val enum obj_key */ duk_dup_m3(thr); @@ -37463,34 +38481,33 @@ duk_put_prop(thr, -4); } } - duk_pop(thr); /* pop enum */ + duk_pop(thr); /* pop enum */ } } /* ... holder name val */ duk_dup(thr, js_ctx->idx_reviver); - duk_insert(thr, -4); /* -> ... reviver holder name val */ - duk_call_method(thr, 2); /* -> ... res */ + duk_insert(thr, -4); /* -> ... reviver holder name val */ + duk_call_method(thr, 2); /* -> ... res */ duk__json_dec_objarr_exit(js_ctx); - DUK_DDD(DUK_DDDPRINT("walk: top=%ld, result=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("walk: top=%ld, result=%!T", (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -1))); } /* * Stringify implementation. */ -#define DUK__EMIT_1(js_ctx,ch) duk__emit_1((js_ctx), (duk_uint_fast8_t) (ch)) -#define DUK__EMIT_2(js_ctx,ch1,ch2) duk__emit_2((js_ctx), (duk_uint_fast8_t) (ch1), (duk_uint_fast8_t) (ch2)) -#define DUK__EMIT_HSTR(js_ctx,h) duk__emit_hstring((js_ctx), (h)) +#define DUK__EMIT_1(js_ctx, ch) duk__emit_1((js_ctx), (duk_uint_fast8_t) (ch)) +#define DUK__EMIT_2(js_ctx, ch1, ch2) duk__emit_2((js_ctx), (duk_uint_fast8_t) (ch1), (duk_uint_fast8_t) (ch2)) +#define DUK__EMIT_HSTR(js_ctx, h) duk__emit_hstring((js_ctx), (h)) #if defined(DUK_USE_FASTINT) || defined(DUK_USE_JX) || defined(DUK_USE_JC) -#define DUK__EMIT_CSTR(js_ctx,p) duk__emit_cstring((js_ctx), (p)) +#define DUK__EMIT_CSTR(js_ctx, p) duk__emit_cstring((js_ctx), (p)) #endif -#define DUK__EMIT_STRIDX(js_ctx,i) duk__emit_stridx((js_ctx), (i)) -#define DUK__UNEMIT_1(js_ctx) duk__unemit_1((js_ctx)) +#define DUK__EMIT_STRIDX(js_ctx, i) duk__emit_stridx((js_ctx), (i)) +#define DUK__UNEMIT_1(js_ctx) duk__unemit_1((js_ctx)) DUK_LOCAL void duk__emit_1(duk_json_enc_ctx *js_ctx, duk_uint_fast8_t ch) { DUK_BW_WRITE_ENSURE_U8(js_ctx->thr, &js_ctx->bw, ch); @@ -37525,10 +38542,8 @@ DUK_BW_ADD_PTR(js_ctx->thr, &js_ctx->bw, -1); } -#define DUK__MKESC(nybbles,esc1,esc2) \ - (((duk_uint_fast32_t) (nybbles)) << 16) | \ - (((duk_uint_fast32_t) (esc1)) << 8) | \ - ((duk_uint_fast32_t) (esc2)) +#define DUK__MKESC(nybbles, esc1, esc2) \ + (((duk_uint_fast32_t) (nybbles)) << 16) | (((duk_uint_fast32_t) (esc1)) << 8) | ((duk_uint_fast32_t) (esc2)) DUK_LOCAL duk_uint8_t *duk__emit_esc_auto_fast(duk_json_enc_ctx *js_ctx, duk_uint_fast32_t cp, duk_uint8_t *q) { duk_uint_fast32_t tmp; @@ -37553,7 +38568,7 @@ } } else #endif - if (DUK_LIKELY(cp < 0x10000UL)) { + if (DUK_LIKELY(cp < 0x10000UL)) { tmp = DUK__MKESC(4, DUK_ASC_BACKSLASH, DUK_ASC_LC_U); } else { #if defined(DUK_USE_JX) @@ -37585,7 +38600,7 @@ } DUK_LOCAL void duk__json_enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k) { - const duk_int8_t *p, *p_start, *p_end; /* Note: intentionally signed. */ + const duk_int8_t *p, *p_start, *p_end; /* Note: intentionally signed. */ duk_size_t k_len; duk_codepoint_t cp; @@ -37626,7 +38641,7 @@ return; } - quote_normally: +quote_normally: duk__json_enc_quote_string(js_ctx, k); } @@ -37639,7 +38654,7 @@ duk_hthread *thr = js_ctx->thr; const duk_uint8_t *p, *p_start, *p_end, *p_now, *p_tmp; duk_uint8_t *q; - duk_ucodepoint_t cp; /* typed for duk_unicode_decode_xutf8() */ + duk_ucodepoint_t cp; /* typed for duk_unicode_decode_xutf8() */ DUK_DDD(DUK_DDDPRINT("duk__json_enc_quote_string: h_str=%!O", (duk_heaphdr *) h_str)); @@ -37658,8 +38673,7 @@ duk_size_t left, now, space; left = (duk_size_t) (p_end - p); - now = (left > DUK__JSON_ENCSTR_CHUNKSIZE ? - DUK__JSON_ENCSTR_CHUNKSIZE : left); + now = (left > DUK__JSON_ENCSTR_CHUNKSIZE ? DUK__JSON_ENCSTR_CHUNKSIZE : left); /* Maximum expansion per input byte is 6: * - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6). @@ -37695,7 +38709,7 @@ p--; /* slow path is shared */ -#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#else /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ cp = *p; if (DUK_LIKELY(cp <= 0x7f)) { @@ -37726,7 +38740,7 @@ } } else { /* slow path is shared */ -#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ +#endif /* DUK_USE_JSON_QUOTESTRING_FASTPATH */ /* slow path decode */ @@ -37802,11 +38816,10 @@ /* Negative zero needs special handling in JX/JC because * it would otherwise serialize to '0', not '-0'. */ - if (DUK_UNLIKELY(c == DUK_FP_ZERO && s != 0 && - (js_ctx->flag_ext_custom_or_compatible))) { - duk_push_hstring_stridx(thr, DUK_STRIDX_MINUS_ZERO); /* '-0' */ + if (DUK_UNLIKELY(c == DUK_FP_ZERO && s != 0 && (js_ctx->flag_ext_custom_or_compatible))) { + duk_push_hstring_stridx(thr, DUK_STRIDX_MINUS_ZERO); /* '-0' */ } else -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ { n2s_flags = 0; /* ... number -> ... string */ @@ -37818,8 +38831,7 @@ } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (!(js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE))) { + if (!(js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE))) { stridx = DUK_STRIDX_LC_NULL; } else if (c == DUK_FP_NAN) { stridx = js_ctx->stridx_custom_nan; @@ -37918,7 +38930,7 @@ return q; } -#else /* DUK_USE_HEX_FASTPATH */ +#else /* DUK_USE_HEX_FASTPATH */ DUK_LOCAL duk_uint8_t *duk__json_enc_buffer_data_hex(const duk_uint8_t *src, duk_size_t src_len, duk_uint8_t *dst) { const duk_uint8_t *p; const duk_uint8_t *p_end; @@ -37936,7 +38948,7 @@ return q; } -#endif /* DUK_USE_HEX_FASTPATH */ +#endif /* DUK_USE_HEX_FASTPATH */ DUK_LOCAL void duk__json_enc_buffer_data(duk_json_enc_ctx *js_ctx, duk_uint8_t *buf_data, duk_size_t buf_len) { duk_hthread *thr; @@ -37945,7 +38957,7 @@ thr = js_ctx->thr; - DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ + DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ DUK_ASSERT(js_ctx->flag_ext_custom_or_compatible); /* Buffer values are encoded in (lowercase) hex to make the @@ -37961,7 +38973,7 @@ /* Note: space must cater for both JX and JC. */ space = 9 + buf_len * 2 + 2; DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7ffffffeUL); - DUK_ASSERT((space - 2) / 2 >= buf_len); /* overflow not possible, buffer limits */ + DUK_ASSERT((space - 2) / 2 >= buf_len); /* overflow not possible, buffer limits */ q = DUK_BW_ENSURE_GETPTR(thr, &js_ctx->bw, space); #if defined(DUK_USE_JX) && defined(DUK_USE_JC) @@ -37981,7 +38993,7 @@ #if defined(DUK_USE_JC) { DUK_ASSERT(js_ctx->flag_ext_compatible); - duk_memcpy((void *) q, (const void *) "{\"_buf\":\"", 9); /* len: 9 */ + duk_memcpy((void *) q, (const void *) "{\"_buf\":\"", 9); /* len: 9 */ q += 9; q = duk__json_enc_buffer_data_hex(buf_data, buf_len, q); *q++ = DUK_ASC_DOUBLEQUOTE; @@ -37994,10 +39006,10 @@ DUK_LOCAL void duk__json_enc_buffer_jx_jc(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) { duk__json_enc_buffer_data(js_ctx, - (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h), - (duk_size_t) DUK_HBUFFER_GET_SIZE(h)); + (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h), + (duk_size_t) DUK_HBUFFER_GET_SIZE(h)); } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) DUK_LOCAL void duk__json_enc_buffer_json_fastpath(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) { @@ -38037,21 +39049,21 @@ } DUK_BW_SET_PTR(js_ctx->thr, &js_ctx->bw, q); } - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth); } DUK__EMIT_1(js_ctx, DUK_ASC_RCURLY); } -#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ +#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) DUK_LOCAL void duk__json_enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr) { - char buf64; /* XXX: how to figure correct size? */ + char buf64; /* XXX: how to figure correct size? */ const char *fmt; - DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ + DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); /* caller checks */ DUK_ASSERT(js_ctx->flag_ext_custom_or_compatible); duk_memzero(buf, sizeof(buf)); @@ -38078,10 +39090,10 @@ #endif /* When ptr == NULL, the format argument is unused. */ - DUK_SNPRINTF(buf, sizeof(buf) - 1, fmt, ptr); /* must not truncate */ + DUK_SNPRINTF(buf, sizeof(buf) - 1, fmt, ptr); /* must not truncate */ DUK__EMIT_CSTR(js_ctx, buf); } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) #if defined(DUK_USE_JX) || defined(DUK_USE_JC) @@ -38093,12 +39105,12 @@ } else { /* Handle both full and partial slice (as long as covered). */ duk__json_enc_buffer_data(js_ctx, - (duk_uint8_t *) DUK_HBUFOBJ_GET_SLICE_BASE(js_ctx->thr->heap, h_bufobj), - (duk_size_t) h_bufobj->length); + (duk_uint8_t *) DUK_HBUFOBJ_GET_SLICE_BASE(js_ctx->thr->heap, h_bufobj), + (duk_size_t) h_bufobj->length); } } -#endif /* DUK_USE_JX || DUK_USE_JC */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Indent helper. Calling code relies on js_ctx->recursion_depth also being * directly related to indent depth. @@ -38106,24 +39118,24 @@ #if defined(DUK_USE_PREFER_SIZE) DUK_LOCAL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) { DUK_ASSERT(js_ctx->h_gap != NULL); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ DUK__EMIT_1(js_ctx, 0x0a); while (depth-- > 0) { DUK__EMIT_HSTR(js_ctx, js_ctx->h_gap); } } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ DUK_LOCAL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) { const duk_uint8_t *gap_data; duk_size_t gap_len; - duk_size_t avail_bytes; /* bytes of indent available for copying */ - duk_size_t need_bytes; /* bytes of indent still needed */ + duk_size_t avail_bytes; /* bytes of indent available for copying */ + duk_size_t need_bytes; /* bytes of indent still needed */ duk_uint8_t *p_start; duk_uint8_t *p; DUK_ASSERT(js_ctx->h_gap != NULL); - DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ + DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */ DUK__EMIT_1(js_ctx, 0x0a); if (DUK_UNLIKELY(depth == 0)) { @@ -38157,14 +39169,14 @@ avail_bytes <<= 1; } - DUK_ASSERT(need_bytes < avail_bytes); /* need_bytes may be zero */ + DUK_ASSERT(need_bytes < avail_bytes); /* need_bytes may be zero */ duk_memcpy((void *) p, (const void *) p_start, (size_t) need_bytes); p += need_bytes; /*avail_bytes += need_bytes*/ DUK_BW_SET_PTR(js_ctx->thr, &js_ctx->bw, p); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* Shared entry handling for object/array serialization. */ DUK_LOCAL void duk__json_enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top) { @@ -38181,7 +39193,7 @@ * with overflow in a loop check object. */ - h_target = duk_known_hobject(thr, -1); /* object or array */ + h_target = duk_known_hobject(thr, -1); /* object or array */ n = js_ctx->recursion_depth; if (DUK_UNLIKELY(n > DUK_JSON_ENC_LOOPARRAY)) { @@ -38198,18 +39210,18 @@ js_ctx->visitingjs_ctx->recursion_depth = h_target; } else { duk_push_sprintf(thr, DUK_STR_FMT_PTR, (void *) h_target); - duk_dup_top(thr); /* -> ... voidp voidp */ + duk_dup_top(thr); /* -> ... voidp voidp */ if (duk_has_prop(thr, js_ctx->idx_loop)) { DUK_ERROR_TYPE(thr, DUK_STR_CYCLIC_INPUT); DUK_WO_NORETURN(return;); } - duk_push_true(thr); /* -> ... voidp true */ - duk_put_prop(thr, js_ctx->idx_loop); /* -> ... */ + duk_push_true(thr); /* -> ... voidp true */ + duk_put_prop(thr, js_ctx->idx_loop); /* -> ... */ } /* C recursion check. */ - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_ERROR_RANGE(thr, DUK_STR_ENC_RECLIMIT); @@ -38218,7 +39230,8 @@ js_ctx->recursion_depth++; DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%ld, loop=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); } /* Shared exit handling for object/array serialization. */ @@ -38234,20 +39247,21 @@ /* Loop check. */ - h_target = duk_known_hobject(thr, *entry_top - 1); /* original target at entry_top - 1 */ + h_target = duk_known_hobject(thr, *entry_top - 1); /* original target at entry_top - 1 */ if (js_ctx->recursion_depth < DUK_JSON_ENC_LOOPARRAY) { /* Previous entry was inside visited, nothing to do. */ } else { duk_push_sprintf(thr, DUK_STR_FMT_PTR, (void *) h_target); - duk_del_prop(thr, js_ctx->idx_loop); /* -> ... */ + duk_del_prop(thr, js_ctx->idx_loop); /* -> ... */ } /* Restore stack top after unbalanced code paths. */ duk_set_top(thr, *entry_top); DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%ld, loop=%!T", - (long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); + (long) duk_get_top(thr), + (duk_tval *) duk_get_tval(thr, js_ctx->idx_loop))); } /* The JO(value) operation: encode object. @@ -38275,13 +39289,14 @@ } else { /* XXX: would be nice to enumerate an object at specified index */ duk_dup(thr, idx_obj); - (void) duk_hobject_get_enumerated_keys(thr, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); /* ... target -> ... target keys */ + (void) duk_hobject_get_enumerated_keys( + thr, + DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/); /* ... target -> ... target keys */ idx_keys = duk_require_normalize_index(thr, -1); /* leave stack unbalanced on purpose */ } - DUK_DDD(DUK_DDDPRINT("idx_keys=%ld, h_keys=%!T", - (long) idx_keys, (duk_tval *) duk_get_tval(thr, idx_keys))); + DUK_DDD(DUK_DDDPRINT("idx_keys=%ld, h_keys=%!T", (long) idx_keys, (duk_tval *) duk_get_tval(thr, idx_keys))); /* Steps 8-10 have been merged to avoid a "partial" variable. */ @@ -38296,7 +39311,7 @@ arr_len = (duk_uarridx_t) duk_get_length(thr, idx_keys); emitted = 0; for (i = 0; i < arr_len; i++) { - duk_get_prop_index(thr, idx_keys, i); /* -> ... key */ + duk_get_prop_index(thr, idx_keys, i); /* -> ... key */ DUK_DDD(DUK_DDDPRINT("object property loop: holder=%!T, key=%!T", (duk_tval *) duk_get_tval(thr, idx_obj), @@ -38304,7 +39319,7 @@ h_key = duk_known_hstring(thr, -1); DUK_ASSERT(h_key != NULL); - DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(h_key)); /* proplist filtering; enum options */ + DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(h_key)); /* proplist filtering; enum options */ prev_size = DUK_BW_GET_SIZE(js_ctx->thr, &js_ctx->bw); if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { @@ -38333,7 +39348,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -38357,8 +39372,7 @@ duk_bool_t emitted; duk_uarridx_t i, arr_len; - DUK_DDD(DUK_DDDPRINT("duk__json_enc_array: array=%!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("duk__json_enc_array: array=%!T", (duk_tval *) duk_get_tval(thr, -1))); duk__json_enc_objarr_entry(js_ctx, &entry_top); @@ -38373,14 +39387,15 @@ for (i = 0; i < arr_len; i++) { DUK_DDD(DUK_DDDPRINT("array entry loop: array=%!T, index=%ld, arr_len=%ld", (duk_tval *) duk_get_tval(thr, idx_arr), - (long) i, (long) arr_len)); + (long) i, + (long) arr_len)); if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth); } - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... key */ + (void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> ... key */ /* ... key */ @@ -38399,7 +39414,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -38424,14 +39439,15 @@ duk_small_int_t c; DUK_DDD(DUK_DDDPRINT("duk__json_enc_value: idx_holder=%ld, holder=%!T, key=%!T", - (long) idx_holder, (duk_tval *) duk_get_tval(thr, idx_holder), + (long) idx_holder, + (duk_tval *) duk_get_tval(thr, idx_holder), (duk_tval *) duk_get_tval(thr, -1))); tv_holder = DUK_GET_TVAL_POSIDX(thr, idx_holder); DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv_holder)); tv_key = DUK_GET_TVAL_NEGIDX(thr, -1); DUK_ASSERT(DUK_TVAL_IS_STRING(tv_key)); - DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING(tv_key))); /* Caller responsible. */ + DUK_ASSERT(!DUK_HSTRING_HAS_SYMBOL(DUK_TVAL_GET_STRING(tv_key))); /* Caller responsible. */ (void) duk_hobject_getprop(thr, tv_holder, tv_key); /* -> ... key val */ @@ -38443,19 +39459,17 @@ * number won't invoke the .toJSON() method. However, lightfuncs and * plain buffers mimic objects so we check for their .toJSON() method. */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER)) { + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_TO_JSON); - if (duk_is_callable(thr, -1)) { /* toJSON() can also be a lightfunc */ + if (duk_is_callable(thr, -1)) { /* toJSON() can also be a lightfunc */ DUK_DDD(DUK_DDDPRINT("value is object, has callable toJSON() -> call it")); /* XXX: duk_dup_unvalidated(thr, -2) etc. */ - duk_dup_m2(thr); /* -> ... key val toJSON val */ - duk_dup_m4(thr); /* -> ... key val toJSON val key */ - duk_call_method(thr, 1); /* -> ... key val val' */ - duk_remove_m2(thr); /* -> ... key val' */ + duk_dup_m2(thr); /* -> ... key val toJSON val */ + duk_dup_m4(thr); /* -> ... key val toJSON val key */ + duk_call_method(thr, 1); /* -> ... key val val' */ + duk_remove_m2(thr); /* -> ... key val' */ } else { - duk_pop(thr); /* -> ... key val */ + duk_pop(thr); /* -> ... key val */ } } @@ -38466,12 +39480,12 @@ if (js_ctx->h_replacer) { /* XXX: Here a "slice copy" would be useful. */ DUK_DDD(DUK_DDDPRINT("replacer is set, call replacer")); - duk_push_hobject(thr, js_ctx->h_replacer); /* -> ... key val replacer */ - duk_dup(thr, idx_holder); /* -> ... key val replacer holder */ - duk_dup_m4(thr); /* -> ... key val replacer holder key */ - duk_dup_m4(thr); /* -> ... key val replacer holder key val */ - duk_call_method(thr, 2); /* -> ... key val val' */ - duk_remove_m2(thr); /* -> ... key val' */ + duk_push_hobject(thr, js_ctx->h_replacer); /* -> ... key val replacer */ + duk_dup(thr, idx_holder); /* -> ... key val replacer holder */ + duk_dup_m4(thr); /* -> ... key val replacer holder key */ + duk_dup_m4(thr); /* -> ... key val replacer holder key val */ + duk_call_method(thr, 2); /* -> ... key val val' */ + duk_remove_m2(thr); /* -> ... key val' */ } /* ... key val */ @@ -38487,8 +39501,7 @@ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (DUK_HOBJECT_IS_BUFOBJ(h) && - js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { + if (DUK_HOBJECT_IS_BUFOBJ(h) && js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { /* With JX/JC a bufferobject gets serialized specially. */ duk_hbufobj *h_bufobj; h_bufobj = (duk_hbufobj *) h; @@ -38497,8 +39510,8 @@ goto pop2_emitted; } /* Otherwise bufferobjects get serialized as normal objects. */ -#endif /* JX || JC */ -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* JX || JC */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ c = (duk_small_int_t) DUK_HOBJECT_GET_CLASS_NUMBER(h); switch (c) { case DUK_HOBJECT_CLASS_NUMBER: { @@ -38538,8 +39551,7 @@ DUK_ASSERT(h != NULL); if (DUK_HOBJECT_IS_CALLABLE(h)) { #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE)) { + if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { /* We only get here when doing non-standard JSON encoding */ DUK_DDD(DUK_DDDPRINT("-> function allowed, serialize to custom format")); DUK_ASSERT(js_ctx->flag_ext_custom || js_ctx->flag_ext_compatible); @@ -38549,13 +39561,13 @@ DUK_DDD(DUK_DDDPRINT("-> will result in undefined (function)")); goto pop2_undef; } -#else /* DUK_USE_JX || DUK_USE_JC */ +#else /* DUK_USE_JX || DUK_USE_JC */ DUK_DDD(DUK_DDDPRINT("-> will result in undefined (function)")); goto pop2_undef; -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ } } - } /* end switch */ + } /* end switch */ } /* ... key val */ @@ -38582,8 +39594,7 @@ break; } case DUK_TAG_BOOLEAN: { - DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? - DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); + DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); break; } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) @@ -38592,7 +39603,7 @@ duk__json_enc_pointer(js_ctx, DUK_TVAL_GET_POINTER(tv)); break; } -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ case DUK_TAG_STRING: { duk_hstring *h = DUK_TVAL_GET_STRING(tv); DUK_ASSERT(h != NULL); @@ -38671,14 +39682,14 @@ } #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - pop2_emitted: +pop2_emitted: #endif duk_pop_2(thr); /* ... key val -> ... */ - return 1; /* emitted */ + return 1; /* emitted */ - pop2_undef: - duk_pop_2(thr); /* ... key val -> ... */ - return 0; /* not emitted */ +pop2_undef: + duk_pop_2(thr); /* ... key val -> ... */ + return 0; /* not emitted */ } /* E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4. */ @@ -38754,8 +39765,7 @@ break; } case DUK_TAG_BOOLEAN: { - DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? - DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); + DUK__EMIT_STRIDX(js_ctx, DUK_TVAL_GET_BOOLEAN(tv) ? DUK_STRIDX_TRUE : DUK_STRIDX_FALSE); break; } case DUK_TAG_STRING: { @@ -38772,8 +39782,7 @@ duk_hobject *obj; duk_tval *tv_val; duk_bool_t emitted = 0; - duk_uint32_t c_bit, c_all, c_array, c_unbox, c_undef, - c_func, c_bufobj, c_object, c_abort; + duk_uint32_t c_bit, c_all, c_array, c_unbox, c_undef, c_func, c_bufobj, c_object, c_abort; /* For objects JSON.stringify() only looks for own, enumerable * properties which is nice for the fast path here. @@ -38806,7 +39815,7 @@ * it (though it's OK to abort the fast path). */ - DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */ DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit); if (js_ctx->recursion_depth >= js_ctx->recursion_limit) { DUK_DD(DUK_DDPRINT("fast path recursion limit")); @@ -38858,28 +39867,23 @@ if (js_ctx->flag_ext_custom_or_compatible) { c_all = DUK_HOBJECT_CMASK_ALL; c_array = DUK_HOBJECT_CMASK_ARRAY; - c_unbox = DUK_HOBJECT_CMASK_NUMBER | - DUK_HOBJECT_CMASK_STRING | - DUK_HOBJECT_CMASK_BOOLEAN | - DUK_HOBJECT_CMASK_POINTER; /* Symbols are not unboxed. */ + c_unbox = DUK_HOBJECT_CMASK_NUMBER | DUK_HOBJECT_CMASK_STRING | DUK_HOBJECT_CMASK_BOOLEAN | + DUK_HOBJECT_CMASK_POINTER; /* Symbols are not unboxed. */ c_func = DUK_HOBJECT_CMASK_FUNCTION; c_bufobj = DUK_HOBJECT_CMASK_ALL_BUFOBJS; c_undef = 0; c_abort = 0; c_object = c_all & ~(c_array | c_unbox | c_func | c_bufobj | c_undef | c_abort); - } - else + } else #endif { c_all = DUK_HOBJECT_CMASK_ALL; c_array = DUK_HOBJECT_CMASK_ARRAY; - c_unbox = DUK_HOBJECT_CMASK_NUMBER | - DUK_HOBJECT_CMASK_STRING | - DUK_HOBJECT_CMASK_BOOLEAN; /* Symbols are not unboxed. */ + c_unbox = DUK_HOBJECT_CMASK_NUMBER | DUK_HOBJECT_CMASK_STRING | + DUK_HOBJECT_CMASK_BOOLEAN; /* Symbols are not unboxed. */ c_func = 0; c_bufobj = 0; - c_undef = DUK_HOBJECT_CMASK_FUNCTION | - DUK_HOBJECT_CMASK_POINTER; + c_undef = DUK_HOBJECT_CMASK_FUNCTION | DUK_HOBJECT_CMASK_POINTER; /* As the fast path doesn't currently properly support * duk_hbufobj virtual properties, abort fast path if * we encounter them in plain JSON mode. @@ -38961,7 +39965,7 @@ if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -39031,14 +40035,14 @@ #endif /* fall through */ - elem_done: + elem_done: DUK__EMIT_1(js_ctx, DUK_ASC_COMMA); emitted = 1; } if (emitted) { DUK_ASSERT(*((duk_uint8_t *) DUK_BW_GET_PTR(js_ctx->thr, &js_ctx->bw) - 1) == DUK_ASC_COMMA); - DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ + DUK__UNEMIT_1(js_ctx); /* eat trailing comma */ if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) { DUK_ASSERT(js_ctx->recursion_depth >= 1); duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U); @@ -39050,7 +40054,7 @@ * automatic unboxing. Rely on internal value being * sane (to avoid infinite recursion). */ - DUK_ASSERT((c_bit & DUK_HOBJECT_CMASK_SYMBOL) == 0); /* Symbols are not unboxed. */ + DUK_ASSERT((c_bit & DUK_HOBJECT_CMASK_SYMBOL) == 0); /* Symbols are not unboxed. */ #if 1 /* The code below is incorrect if .toString() or .valueOf() have @@ -39060,7 +40064,7 @@ * Unimplemented for now, abort fast path for boxed values. */ goto abort_fastpath; -#else /* disabled */ +#else /* disabled */ /* Disabled until fixed, see above. */ duk_tval *tv_internal; @@ -39068,16 +40072,14 @@ tv_internal = duk_hobject_get_internal_value_tval_ptr(js_ctx->thr->heap, obj); DUK_ASSERT(tv_internal != NULL); - DUK_ASSERT(DUK_TVAL_IS_STRING(tv_internal) || - DUK_TVAL_IS_NUMBER(tv_internal) || - DUK_TVAL_IS_BOOLEAN(tv_internal) || - DUK_TVAL_IS_POINTER(tv_internal)); + DUK_ASSERT(DUK_TVAL_IS_STRING(tv_internal) || DUK_TVAL_IS_NUMBER(tv_internal) || + DUK_TVAL_IS_BOOLEAN(tv_internal) || DUK_TVAL_IS_POINTER(tv_internal)); tv = tv_internal; DUK_ASSERT(js_ctx->recursion_depth > 0); - js_ctx->recursion_depth--; /* required to keep recursion depth correct */ + js_ctx->recursion_depth--; /* required to keep recursion depth correct */ goto restart_match; -#endif /* disabled */ +#endif /* disabled */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) } else if (c_bit & c_func) { DUK__EMIT_STRIDX(js_ctx, js_ctx->stridx_custom_function); @@ -39190,12 +40192,12 @@ #endif } } - return 1; /* not undefined */ + return 1; /* not undefined */ - emit_undefined: - return 0; /* value was undefined/unsupported */ +emit_undefined: + return 0; /* value was undefined/unsupported */ - abort_fastpath: +abort_fastpath: /* Error message doesn't matter: the error is ignored anyway. */ DUK_DD(DUK_DDPRINT("aborting fast path")); DUK_ERROR_INTERNAL(js_ctx->thr); @@ -39215,22 +40217,19 @@ tv = DUK_GET_TVAL_NEGIDX(thr, -1); if (duk__json_stringify_fast_value(js_ctx, tv) == 0) { DUK_DD(DUK_DDPRINT("top level value not supported, fail fast path")); - DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* Error message is ignored, so doesn't matter. */ + DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* Error message is ignored, so doesn't matter. */ } return 0; } -#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ +#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */ /* * Top level wrappers */ DUK_INTERNAL -void duk_bi_json_parse_helper(duk_hthread *thr, - duk_idx_t idx_value, - duk_idx_t idx_reviver, - duk_small_uint_t flags) { +void duk_bi_json_parse_helper(duk_hthread *thr, duk_idx_t idx_value, duk_idx_t idx_reviver, duk_small_uint_t flags) { duk_json_dec_ctx js_ctx_alloc; duk_json_dec_ctx *js_ctx = &js_ctx_alloc; duk_hstring *h_text; @@ -39271,7 +40270,7 @@ js_ctx->flag_ext_custom_or_compatible = flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE); #endif - h_text = duk_to_hstring(thr, idx_value); /* coerce in-place; rejects Symbols */ + h_text = duk_to_hstring(thr, idx_value); /* coerce in-place; rejects Symbols */ DUK_ASSERT(h_text != NULL); /* JSON parsing code is allowed to read p_start,p_end: p_end is @@ -39280,11 +40279,10 @@ */ js_ctx->p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text); js_ctx->p = js_ctx->p_start; - js_ctx->p_end = ((const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text)) + - DUK_HSTRING_GET_BYTELEN(h_text); + js_ctx->p_end = ((const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_text)) + DUK_HSTRING_GET_BYTELEN(h_text); DUK_ASSERT(*(js_ctx->p_end) == 0x00); - duk__json_dec_value(js_ctx); /* -> ... value */ + duk__json_dec_value(js_ctx); /* -> ... value */ DUK_ASSERT(js_ctx->recursion_depth == 0); /* Trailing whitespace has been eaten by duk__json_dec_value(), so if @@ -39296,27 +40294,26 @@ } if (duk_is_callable(thr, idx_reviver)) { - DUK_DDD(DUK_DDDPRINT("applying reviver: %!T", - (duk_tval *) duk_get_tval(thr, idx_reviver))); + DUK_DDD(DUK_DDDPRINT("applying reviver: %!T", (duk_tval *) duk_get_tval(thr, idx_reviver))); js_ctx->idx_reviver = idx_reviver; duk_push_object(thr); - duk_dup_m2(thr); /* -> ... val root val */ - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_EMPTY_STRING); /* default attrs ok */ - duk_push_hstring_stridx(thr, DUK_STRIDX_EMPTY_STRING); /* -> ... val root "" */ + duk_dup_m2(thr); /* -> ... val root val */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_EMPTY_STRING); /* default attrs ok */ + duk_push_hstring_stridx(thr, DUK_STRIDX_EMPTY_STRING); /* -> ... val root "" */ DUK_DDD(DUK_DDDPRINT("start reviver walk, root=%!T, name=%!T", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(js_ctx->recursion_depth == 0); - duk__json_dec_reviver_walk(js_ctx); /* ... val root "" -> ... val val' */ + duk__json_dec_reviver_walk(js_ctx); /* ... val root "" -> ... val val' */ DUK_ASSERT(js_ctx->recursion_depth == 0); - duk_remove_m2(thr); /* -> ... val' */ + duk_remove_m2(thr); /* -> ... val' */ } else { - DUK_DDD(DUK_DDDPRINT("reviver does not exist or is not callable: %!T", - (duk_tval *) duk_get_tval(thr, idx_reviver))); + DUK_DDD( + DUK_DDDPRINT("reviver does not exist or is not callable: %!T", (duk_tval *) duk_get_tval(thr, idx_reviver))); } /* Final result is at stack top. */ @@ -39390,7 +40387,7 @@ * combinations properly. */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_NULL; /* standard JSON; array gaps */ + js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_NULL; /* standard JSON; array gaps */ #if defined(DUK_USE_JX) if (flags & DUK_JSON_FLAG_EXT_CUSTOM) { js_ctx->stridx_custom_undefined = DUK_STRIDX_LC_UNDEFINED; @@ -39398,41 +40395,35 @@ js_ctx->stridx_custom_neginf = DUK_STRIDX_MINUS_INFINITY; js_ctx->stridx_custom_posinf = DUK_STRIDX_INFINITY; js_ctx->stridx_custom_function = - (flags & DUK_JSON_FLAG_AVOID_KEY_QUOTES) ? - DUK_STRIDX_JSON_EXT_FUNCTION2 : - DUK_STRIDX_JSON_EXT_FUNCTION1; + (flags & DUK_JSON_FLAG_AVOID_KEY_QUOTES) ? DUK_STRIDX_JSON_EXT_FUNCTION2 : DUK_STRIDX_JSON_EXT_FUNCTION1; } -#endif /* DUK_USE_JX */ +#endif /* DUK_USE_JX */ #if defined(DUK_USE_JX) && defined(DUK_USE_JC) else -#endif /* DUK_USE_JX && DUK_USE_JC */ +#endif /* DUK_USE_JX && DUK_USE_JC */ #if defined(DUK_USE_JC) - if (js_ctx->flags & DUK_JSON_FLAG_EXT_COMPATIBLE) { + if (js_ctx->flags & DUK_JSON_FLAG_EXT_COMPATIBLE) { js_ctx->stridx_custom_undefined = DUK_STRIDX_JSON_EXT_UNDEFINED; js_ctx->stridx_custom_nan = DUK_STRIDX_JSON_EXT_NAN; js_ctx->stridx_custom_neginf = DUK_STRIDX_JSON_EXT_NEGINF; js_ctx->stridx_custom_posinf = DUK_STRIDX_JSON_EXT_POSINF; js_ctx->stridx_custom_function = DUK_STRIDX_JSON_EXT_FUNCTION1; } -#endif /* DUK_USE_JC */ -#endif /* DUK_USE_JX || DUK_USE_JC */ +#endif /* DUK_USE_JC */ +#endif /* DUK_USE_JX || DUK_USE_JC */ #if defined(DUK_USE_JX) || defined(DUK_USE_JC) - if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | - DUK_JSON_FLAG_EXT_COMPATIBLE)) { - DUK_ASSERT(js_ctx->mask_for_undefined == 0); /* already zero */ - } - else -#endif /* DUK_USE_JX || DUK_USE_JC */ + if (js_ctx->flags & (DUK_JSON_FLAG_EXT_CUSTOM | DUK_JSON_FLAG_EXT_COMPATIBLE)) { + DUK_ASSERT(js_ctx->mask_for_undefined == 0); /* already zero */ + } else +#endif /* DUK_USE_JX || DUK_USE_JC */ { /* Plain buffer is treated like ArrayBuffer and serialized. * Lightfuncs are treated like objects, but JSON explicitly * skips serializing Function objects so we can just reject * lightfuncs here. */ - js_ctx->mask_for_undefined = DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_POINTER | - DUK_TYPE_MASK_LIGHTFUNC; + js_ctx->mask_for_undefined = DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_POINTER | DUK_TYPE_MASK_LIGHTFUNC; } DUK_BW_INIT_PUSHBUF(thr, &js_ctx->bw, DUK__JSON_STRINGIFY_BUFSIZE); @@ -39462,8 +40453,7 @@ js_ctx->idx_proplist = duk_push_bare_array(thr); - enum_flags = DUK_ENUM_ARRAY_INDICES_ONLY | - DUK_ENUM_SORT_ARRAY_INDICES; /* expensive flag */ + enum_flags = DUK_ENUM_ARRAY_INDICES_ONLY | DUK_ENUM_SORT_ARRAY_INDICES; /* expensive flag */ duk_enum(thr, idx_replacer, enum_flags); while (duk_next(thr, -1 /*enum_index*/, 1 /*get_value*/)) { /* ... proplist enum_obj key val */ @@ -39472,8 +40462,8 @@ DUK_DDD(DUK_DDDPRINT("proplist enum: key=%!T, val=%!T --> accept", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); - duk_to_string(thr, -1); /* extra coercion of strings is OK */ - duk_put_prop_index(thr, -4, plist_idx); /* -> ... proplist enum_obj key */ + duk_to_string(thr, -1); /* extra coercion of strings is OK */ + duk_put_prop_index(thr, -4, plist_idx); /* -> ... proplist enum_obj key */ plist_idx++; duk_pop(thr); } else { @@ -39482,8 +40472,8 @@ (duk_tval *) duk_get_tval(thr, -1))); duk_pop_2(thr); } - } - duk_pop(thr); /* pop enum */ + } + duk_pop(thr); /* pop enum */ /* ... proplist */ } @@ -39509,10 +40499,9 @@ duk_small_int_t nspace; /* spaces must be static to allow initializer with old compilers like BCC */ static const char spaces10 = { - DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, - DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, - DUK_ASC_SPACE, DUK_ASC_SPACE - }; /* XXX: helper */ + DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, + DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE, DUK_ASC_SPACE + }; /* XXX: helper */ /* ToInteger() coercion; NaN -> 0, infinities are clamped to 0 and 10 */ nspace = (duk_small_int_t) duk_to_int_clamped(thr, idx_space, 0 /*minval*/, 10 /*maxval*/); @@ -39523,7 +40512,7 @@ DUK_ASSERT(js_ctx->h_gap != NULL); } else if (duk_is_string_notsymbol(thr, idx_space)) { duk_dup(thr, idx_space); - duk_substring(thr, -1, 0, 10); /* clamp to 10 chars */ + duk_substring(thr, -1, 0, 10); /* clamp to 10 chars */ js_ctx->h_gap = duk_known_hstring(thr, -1); } else { /* nop */ @@ -39547,8 +40536,8 @@ */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) - if (js_ctx->h_replacer == NULL && /* replacer is a mutation risk */ - js_ctx->idx_proplist == -1) { /* proplist is very rare */ + if (js_ctx->h_replacer == NULL && /* replacer is a mutation risk */ + js_ctx->idx_proplist == -1) { /* proplist is very rare */ duk_int_t pcall_rc; duk_small_uint_t prev_ms_base_flags; @@ -39573,10 +40562,9 @@ /* Must prevent finalizers which may have arbitrary side effects. */ prev_ms_base_flags = thr->heap->ms_base_flags; - thr->heap->ms_base_flags |= - DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact any objects. */ - thr->heap->pf_prevent_count++; /* Prevent finalizers. */ - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + thr->heap->ms_base_flags |= DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact any objects. */ + thr->heap->pf_prevent_count++; /* Prevent finalizers. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ pcall_rc = duk_safe_call(thr, duk__json_stringify_fast, (void *) js_ctx /*udata*/, 1 /*nargs*/, 0 /*nret*/); @@ -39627,7 +40615,7 @@ js_ctx->recursion_limit = DUK_USE_JSON_ENC_RECLIMIT; DUK_ASSERT(js_ctx->recursion_depth == 0); - if (DUK_UNLIKELY(duk__json_enc_value(js_ctx, idx_holder) == 0)) { /* ... holder key -> ... holder */ + if (DUK_UNLIKELY(duk__json_enc_value(js_ctx, idx_holder) == 0)) { /* ... holder key -> ... holder */ /* Result is undefined. */ duk_push_undefined(thr); } else { @@ -39649,7 +40637,7 @@ */ #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH) - replace_finished: +replace_finished: #endif duk_replace(thr, entry_top); duk_set_top(thr, entry_top + 1); @@ -39673,25 +40661,18 @@ */ DUK_INTERNAL duk_ret_t duk_bi_json_object_parse(duk_hthread *thr) { - duk_bi_json_parse_helper(thr, - 0 /*idx_value*/, - 1 /*idx_replacer*/, - 0 /*flags*/); + duk_bi_json_parse_helper(thr, 0 /*idx_value*/, 1 /*idx_replacer*/, 0 /*flags*/); return 1; } DUK_INTERNAL duk_ret_t duk_bi_json_object_stringify(duk_hthread *thr) { - duk_bi_json_stringify_helper(thr, - 0 /*idx_value*/, - 1 /*idx_replacer*/, - 2 /*idx_space*/, - 0 /*flags*/); + duk_bi_json_stringify_helper(thr, 0 /*idx_value*/, 1 /*idx_replacer*/, 2 /*idx_space*/, 0 /*flags*/); return 1; } -#endif /* DUK_USE_JSON_BUILTIN */ +#endif /* DUK_USE_JSON_BUILTIN */ -#endif /* DUK_USE_JSON_SUPPORT */ +#endif /* DUK_USE_JSON_SUPPORT */ /* automatic undefs */ #undef DUK__EMIT_1 @@ -39850,7 +40831,7 @@ return x >= 0.0 ? DUK_FLOOR(x) : DUK_CEIL(x); #endif } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ DUK_LOCAL double duk__round_fixed(double x) { /* Numbers half-way between integers must be rounded towards +Infinity, @@ -39965,51 +40946,23 @@ return DUK_ATAN2(x, y); } -#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ +#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ /* order must match constants in genbuiltins.py */ DUK_LOCAL const duk__one_arg_func duk__one_arg_funcs = { #if defined(DUK_USE_AVOID_PLATFORM_FUNCPTRS) - duk__fabs, - duk__acos, - duk__asin, - duk__atan, - duk__ceil, - duk__cos, - duk__exp, - duk__floor, - duk__log, - duk__round_fixed, - duk__sin, - duk__sqrt, - duk__tan, + duk__fabs, duk__acos, duk__asin, duk__atan, duk__ceil, duk__cos, duk__exp, + duk__floor, duk__log, duk__round_fixed, duk__sin, duk__sqrt, duk__tan, #if defined(DUK_USE_ES6) - duk__cbrt, - duk__log2, - duk__log10, - duk__trunc -#endif -#else /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ - DUK_FABS, - DUK_ACOS, - DUK_ASIN, - DUK_ATAN, - DUK_CEIL, - DUK_COS, - DUK_EXP, - DUK_FLOOR, - DUK_LOG, - duk__round_fixed, - DUK_SIN, - DUK_SQRT, - DUK_TAN, + duk__cbrt, duk__log2, duk__log10, duk__trunc +#endif +#else /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ + DUK_FABS, DUK_ACOS, DUK_ASIN, DUK_ATAN, DUK_CEIL, DUK_COS, DUK_EXP, + DUK_FLOOR, DUK_LOG, duk__round_fixed, DUK_SIN, DUK_SQRT, DUK_TAN, #if defined(DUK_USE_ES6) - duk__cbrt, - duk__log2, - duk__log10, - duk__trunc + duk__cbrt, duk__log2, duk__log10, duk__trunc #endif -#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ +#endif /* DUK_USE_AVOID_PLATFORM_FUNCPTRS */ }; /* order must match constants in genbuiltins.py */ @@ -40044,7 +40997,7 @@ DUK_ASSERT(fun_idx >= 0); DUK_ASSERT(fun_idx < (duk_small_int_t) (sizeof(duk__two_arg_funcs) / sizeof(duk__two_arg_func))); - arg1 = duk_to_number(thr, 0); /* explicit ordered evaluation to match coercion semantics */ + arg1 = duk_to_number(thr, 0); /* explicit ordered evaluation to match coercion semantics */ arg2 = duk_to_number(thr, 1); fun = duk__two_arg_funcsfun_idx; duk_push_number(thr, (duk_double_t) fun((double) arg1, (double) arg2)); @@ -40060,7 +41013,7 @@ } DUK_INTERNAL duk_ret_t duk_bi_math_object_random(duk_hthread *thr) { - duk_push_number(thr, (duk_double_t) DUK_UTIL_GET_RANDOM_DOUBLE(thr)); + duk_push_number(thr, (duk_double_t) duk_util_get_random_double(thr)); return 1; } @@ -40130,7 +41083,7 @@ duk_push_number(thr, (duk_double_t) DUK_SQRT(sum) * max); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_sign(duk_hthread *thr) { @@ -40139,7 +41092,7 @@ d = duk_to_number(thr, 0); if (duk_double_is_nan(d)) { DUK_ASSERT(duk_is_nan(thr, -1)); - return 1; /* NaN input -> return NaN */ + return 1; /* NaN input -> return NaN */ } if (duk_double_equals(d, 0.0)) { /* Zero sign kept, i.e. -0 -> -0, +0 -> +0. */ @@ -40148,7 +41101,7 @@ duk_push_int(thr, (d > 0.0 ? 1 : -1)); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_clz32(duk_hthread *thr) { @@ -40168,7 +41121,7 @@ DUK_ASSERT(i <= 32); duk_push_uint(thr, i); return 1; -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ i = 0; x = duk_to_uint32(thr, 0); if (x & 0xffff0000UL) { @@ -40204,9 +41157,9 @@ DUK_ASSERT(i <= 32); duk_push_uint(thr, i); return 1; -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_math_object_imul(duk_hthread *thr) { @@ -40223,9 +41176,9 @@ duk_push_i32(thr, (duk_int32_t) z); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_MATH_BUILTIN */ +#endif /* DUK_USE_MATH_BUILTIN */ #line 1 "duk_bi_number.c" /* * Number built-ins @@ -40248,8 +41201,7 @@ goto done; } h = duk_get_hobject(thr, -1); - if (!h || - (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_NUMBER)) { + if (!h || (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_NUMBER)) { DUK_DDD(DUK_DDDPRINT("unacceptable this value: %!T", (duk_tval *) duk_get_tval(thr, -1))); DUK_ERROR_TYPE(thr, "number expected"); DUK_WO_NORETURN(return 0.0;); @@ -40257,10 +41209,11 @@ duk_xget_owndataprop_stridx_short(thr, -1, DUK_STRIDX_INT_VALUE); DUK_ASSERT(duk_is_number(thr, -1)); DUK_DDD(DUK_DDDPRINT("number object: %!T, internal value: %!T", - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); duk_remove_m2(thr); - done: +done: return duk_get_number(thr, -1); } @@ -40309,9 +41262,9 @@ DUK_ASSERT(DUK_HOBJECT_GET_CLASS_NUMBER(h_this) == DUK_HOBJECT_CLASS_NUMBER); DUK_ASSERT(DUK_HOBJECT_HAS_EXTENSIBLE(h_this)); - duk_dup_0(thr); /* -> val obj val */ + duk_dup_0(thr); /* -> val obj val */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); - return 0; /* no return value -> don't replace created value */ + return 0; /* no return value -> don't replace created value */ } DUK_INTERNAL duk_ret_t duk_bi_number_prototype_value_of(duk_hthread *thr) { @@ -40333,10 +41286,7 @@ n2s_flags = 0; - duk_numconv_stringify(thr, - radix /*radix*/, - 0 /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, radix /*radix*/, 0 /*digits*/, n2s_flags /*flags*/); return 1; } @@ -40374,16 +41324,12 @@ goto use_to_string; } - n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | - DUK_N2S_FLAG_FRACTION_DIGITS; + n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | DUK_N2S_FLAG_FRACTION_DIGITS; - duk_numconv_stringify(thr, - 10 /*radix*/, - frac_digits /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, frac_digits /*digits*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: DUK_ASSERT_TOP(thr, 2); duk_to_string(thr, -1); return 1; @@ -40399,7 +41345,7 @@ d = duk__push_this_number_plain(thr); frac_undefined = duk_is_undefined(thr, 0); - duk_to_int(thr, 0); /* for side effects */ + duk_to_int(thr, 0); /* for side effects */ c = (duk_small_int_t) DUK_FPCLASSIFY(d); if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) { @@ -40408,16 +41354,12 @@ frac_digits = (duk_small_int_t) duk_to_int_check_range(thr, 0, 0, 20); - n2s_flags = DUK_N2S_FLAG_FORCE_EXP | - (frac_undefined ? 0 : DUK_N2S_FLAG_FIXED_FORMAT); + n2s_flags = DUK_N2S_FLAG_FORCE_EXP | (frac_undefined ? 0 : DUK_N2S_FLAG_FIXED_FORMAT); - duk_numconv_stringify(thr, - 10 /*radix*/, - frac_digits + 1 /*leading digit + fractions*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, frac_digits + 1 /*leading digit + fractions*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: DUK_ASSERT_TOP(thr, 2); duk_to_string(thr, -1); return 1; @@ -40442,7 +41384,7 @@ } DUK_ASSERT_TOP(thr, 2); - duk_to_int(thr, 0); /* for side effects */ + duk_to_int(thr, 0); /* for side effects */ c = (duk_small_int_t) DUK_FPCLASSIFY(d); if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) { @@ -40451,16 +41393,12 @@ prec = (duk_small_int_t) duk_to_int_check_range(thr, 0, 1, 21); - n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | - DUK_N2S_FLAG_NO_ZERO_PAD; + n2s_flags = DUK_N2S_FLAG_FIXED_FORMAT | DUK_N2S_FLAG_NO_ZERO_PAD; - duk_numconv_stringify(thr, - 10 /*radix*/, - prec /*digits*/, - n2s_flags /*flags*/); + duk_numconv_stringify(thr, 10 /*radix*/, prec /*digits*/, n2s_flags /*flags*/); return 1; - use_to_string: +use_to_string: /* Used when precision is undefined; also used for NaN (-> "NaN"), * and +/- infinity (-> "Infinity", "-Infinity"). */ @@ -40486,16 +41424,16 @@ d = duk_get_number(thr, 0); switch (magic) { - case 0: /* isFinite() */ + case 0: /* isFinite() */ ret = duk_double_is_finite(d); break; - case 1: /* isInteger() */ + case 1: /* isInteger() */ ret = duk_double_is_integer(d); break; - case 2: /* isNaN() */ + case 2: /* isNaN() */ ret = duk_double_is_nan(d); break; - default: /* isSafeInteger() */ + default: /* isSafeInteger() */ DUK_ASSERT(magic == 3); ret = duk_double_is_safe_integer(d); } @@ -40504,9 +41442,9 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_NUMBER_BUILTIN */ +#endif /* DUK_USE_NUMBER_BUILTIN */ #line 1 "duk_bi_object.c" /* * Object built-ins @@ -40529,8 +41467,8 @@ arg_mask = duk_get_type_mask(thr, 0); - if (!duk_is_constructor_call(thr) && /* not a constructor call */ - ((arg_mask & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) == 0)) { /* and argument not null or undefined */ + if (!duk_is_constructor_call(thr) && /* not a constructor call */ + ((arg_mask & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) == 0)) { /* and argument not null or undefined */ duk_to_object(thr, 0); return 1; } @@ -40540,13 +41478,8 @@ * promote to an object value. Lightfuncs and plain buffers are * coerced with ToObject() even they could also be returned as is. */ - if (arg_mask & (DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_STRING | - DUK_TYPE_MASK_BOOLEAN | - DUK_TYPE_MASK_NUMBER | - DUK_TYPE_MASK_POINTER | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_LIGHTFUNC)) { + if (arg_mask & (DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER | + DUK_TYPE_MASK_POINTER | DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_LIGHTFUNC)) { /* For DUK_TYPE_OBJECT the coercion is a no-op and could * be checked for explicitly, but Object(obj) calls are * not very common so opt for minimal footprint. @@ -40556,13 +41489,12 @@ } (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) && defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_assign(duk_hthread *thr) { @@ -40619,9 +41551,8 @@ DUK_ASSERT(proto != NULL || duk_is_null(thr, 0)); (void) duk_push_object_helper_proto(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), proto); if (!duk_is_undefined(thr, 1)) { @@ -40642,7 +41573,7 @@ return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_properties(duk_hthread *thr) { @@ -40657,11 +41588,9 @@ obj = duk_require_hobject_promote_mask(thr, 0, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); DUK_ASSERT(obj != NULL); - duk_to_object(thr, 1); /* properties object */ + duk_to_object(thr, 1); /* properties object */ - DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT", - (duk_tval *) duk_get_tval(thr, 0), - (duk_tval *) duk_get_tval(thr, 1))); + DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT", (duk_tval *) duk_get_tval(thr, 0), (duk_tval *) duk_get_tval(thr, 1))); /* * Two pass approach to processing the property descriptors. @@ -40674,7 +41603,7 @@ */ for (pass = 0; pass < 2; pass++) { - duk_set_top(thr, 2); /* -> hobject props */ + duk_set_top(thr, 2); /* -> hobject props */ duk_enum(thr, 1, DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_INCLUDE_SYMBOLS /*enum_flags*/); for (;;) { @@ -40694,12 +41623,7 @@ /* hobject props enum(props) key desc */ - duk_hobject_prepare_property_descriptor(thr, - 4 /*idx_desc*/, - &defprop_flags, - &idx_value, - &get, - &set); + duk_hobject_prepare_property_descriptor(thr, 4 /*idx_desc*/, &defprop_flags, &idx_value, &get, &set); /* hobject props enum(props) key desc multiple values */ @@ -40711,14 +41635,7 @@ key = duk_known_hstring(thr, 3); DUK_ASSERT(key != NULL); - duk_hobject_define_property_helper(thr, - defprop_flags, - obj, - key, - idx_value, - get, - set, - 1 /*throw_flag*/); + duk_hobject_define_property_helper(thr, defprop_flags, obj, key, idx_value, get, set, 1 /*throw_flag*/); } } @@ -40729,7 +41646,7 @@ duk_dup_0(thr); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_seal_freeze_shared(duk_hthread *thr) { @@ -40738,7 +41655,7 @@ duk_seal_freeze_raw(thr, 0, (duk_bool_t) duk_get_current_magic(thr) /*is_freeze*/); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_is_sealed_frozen_shared(duk_hthread *thr) { @@ -40750,34 +41667,33 @@ mask = duk_get_type_mask(thr, 0); if (mask & (DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { DUK_ASSERT(is_frozen == 0 || is_frozen == 1); - duk_push_boolean(thr, (mask & DUK_TYPE_MASK_LIGHTFUNC) ? - 1 : /* lightfunc always frozen and sealed */ - (is_frozen ^ 1)); /* buffer sealed but not frozen (index props writable) */ + duk_push_boolean(thr, + (mask & DUK_TYPE_MASK_LIGHTFUNC) ? 1 : /* lightfunc always frozen and sealed */ + (is_frozen ^ 1)); /* buffer sealed but not frozen (index props writable) */ } else { /* ES2015 Sections 19.1.2.12, 19.1.2.13: anything other than an object * is considered to be already sealed and frozen. */ h = duk_get_hobject(thr, 0); - duk_push_boolean(thr, (h == NULL) || - duk_hobject_object_is_sealed_frozen_helper(thr, h, is_frozen /*is_frozen*/)); + duk_push_boolean(thr, (h == NULL) || duk_hobject_object_is_sealed_frozen_helper(thr, h, is_frozen /*is_frozen*/)); } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_to_locale_string(duk_hthread *thr) { DUK_ASSERT_TOP(thr, 0); (void) duk_push_this_coercible_to_object(thr); duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_TO_STRING); -#if 0 /* This is mentioned explicitly in the E5.1 spec, but duk_call_method() checks for it in practice. */ +#if 0 /* This is mentioned explicitly in the E5.1 spec, but duk_call_method() checks for it in practice. */ duk_require_callable(thr, 1); #endif - duk_dup_0(thr); /* -> O toString O */ - duk_call_method(thr, 0); /* XXX: call method tail call? */ + duk_dup_0(thr); /* -> O toString O */ + duk_call_method(thr, 0); /* XXX: call method tail call? */ return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_value_of(duk_hthread *thr) { @@ -40785,7 +41701,7 @@ (void) duk_push_this_coercible_to_object(thr); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_is_prototype_of(duk_hthread *thr) { @@ -40796,7 +41712,7 @@ h_v = duk_get_hobject(thr, 0); if (!h_v) { - duk_push_false(thr); /* XXX: tail call: return duk_push_false(thr) */ + duk_push_false(thr); /* XXX: tail call: return duk_push_false(thr) */ return 1; } @@ -40806,22 +41722,24 @@ /* E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare. * Prototype loops should cause an error to be thrown. */ - duk_push_boolean(thr, duk_hobject_prototype_chain_contains(thr, DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_v), h_obj, 0 /*ignore_loop*/)); + duk_push_boolean( + thr, + duk_hobject_prototype_chain_contains(thr, DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_v), h_obj, 0 /*ignore_loop*/)); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_has_own_property(duk_hthread *thr) { return (duk_ret_t) duk_hobject_object_ownprop_helper(thr, 0 /*required_desc_flags*/); } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_prototype_property_is_enumerable(duk_hthread *thr) { return (duk_ret_t) duk_hobject_object_ownprop_helper(thr, DUK_PROPDESC_FLAG_ENUMERABLE /*required_desc_flags*/); } -#endif /* DUK_USE_OBJECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper to implement Object.getPrototypeOf, @@ -40878,7 +41796,7 @@ } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper to implement ES2015 Object.setPrototypeOf, @@ -40897,7 +41815,7 @@ duk_hobject *h_obj; duk_hobject *h_new_proto; duk_hobject *h_curr; - duk_ret_t ret_success = 1; /* retval for success path */ + duk_ret_t ret_success = 1; /* retval for success path */ duk_uint_t mask; duk_int_t magic; @@ -40918,9 +41836,7 @@ if (magic == 1) { duk_require_object_coercible(thr, 0); } else { - duk_require_hobject_accept_mask(thr, 0, - DUK_TYPE_MASK_LIGHTFUNC | - DUK_TYPE_MASK_BUFFER); + duk_require_hobject_accept_mask(thr, 0, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); } duk_require_type_mask(thr, 1, DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_OBJECT); } @@ -40931,9 +41847,8 @@ mask = duk_get_type_mask(thr, 0); if (mask & (DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER)) { duk_hobject *curr_proto; - curr_proto = thr->builtins(mask & DUK_TYPE_MASK_LIGHTFUNC) ? - DUK_BIDX_FUNCTION_PROTOTYPE : - DUK_BIDX_UINT8ARRAY_PROTOTYPE; + curr_proto = + thr->builtins(mask & DUK_TYPE_MASK_LIGHTFUNC) ? DUK_BIDX_FUNCTION_PROTOTYPE : DUK_BIDX_UINT8ARRAY_PROTOTYPE; if (h_new_proto == curr_proto) { goto skip; } @@ -40963,15 +41878,15 @@ DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h_obj, h_new_proto); /* fall thru */ - skip: +skip: duk_set_top(thr, 1); if (magic == 2) { duk_push_true(thr); } return ret_success; - fail_nonextensible: - fail_loop: +fail_nonextensible: +fail_loop: if (magic != 2) { DUK_DCERROR_TYPE_INVALID_ARGS(thr); } else { @@ -40979,7 +41894,7 @@ return 1; } } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_property(duk_hthread *thr) { @@ -41031,12 +41946,7 @@ * Lightfunc set/get values are coerced to full Functions. */ - duk_hobject_prepare_property_descriptor(thr, - 2 /*idx_desc*/, - &defprop_flags, - &idx_value, - &get, - &set); + duk_hobject_prepare_property_descriptor(thr, 2 /*idx_desc*/, &defprop_flags, &idx_value, &get, &set); /* * Use Object.defineProperty() helper for the actual operation. @@ -41044,14 +41954,7 @@ DUK_ASSERT(magic == 0U || magic == 1U); throw_flag = magic ^ 1U; - ret = duk_hobject_define_property_helper(thr, - defprop_flags, - obj, - key, - idx_value, - get, - set, - throw_flag); + ret = duk_hobject_define_property_helper(thr, defprop_flags, obj, key, idx_value, get, set, throw_flag); /* Ignore the normalize/validate helper outputs on the value stack, * they're popped automatically. @@ -41066,7 +41969,7 @@ } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_get_own_property_descriptor(duk_hthread *thr) { @@ -41082,7 +41985,7 @@ duk_hobject_object_get_own_property_descriptor(thr, -2); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_is_extensible(duk_hthread *thr) { @@ -41105,7 +42008,7 @@ duk_push_boolean(thr, (h != NULL) && DUK_HOBJECT_HAS_EXTENSIBLE(h)); return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) /* Shared helper for various key/symbol listings, magic: @@ -41116,26 +42019,17 @@ */ DUK_LOCAL const duk_small_uint_t duk__object_keys_enum_flags4 = { /* Object.keys() */ - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_NO_PROXY_BEHAVIOR, + DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Object.getOwnPropertyNames() */ - DUK_ENUM_INCLUDE_NONENUMERABLE | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_NO_PROXY_BEHAVIOR, + DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Object.getOwnPropertySymbols() */ - DUK_ENUM_INCLUDE_SYMBOLS | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_EXCLUDE_STRINGS | - DUK_ENUM_INCLUDE_NONENUMERABLE | + DUK_ENUM_INCLUDE_SYMBOLS | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_EXCLUDE_STRINGS | DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_NO_PROXY_BEHAVIOR, /* Reflect.ownKeys() */ - DUK_ENUM_INCLUDE_SYMBOLS | - DUK_ENUM_OWN_PROPERTIES_ONLY | - DUK_ENUM_INCLUDE_NONENUMERABLE | - DUK_ENUM_NO_PROXY_BEHAVIOR + DUK_ENUM_INCLUDE_SYMBOLS | DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_NO_PROXY_BEHAVIOR }; DUK_INTERNAL duk_ret_t duk_bi_object_constructor_keys_shared(duk_hthread *thr) { @@ -41167,9 +42061,7 @@ #if defined(DUK_USE_ES6_PROXY) /* XXX: better sharing of code between proxy target call sites */ - if (DUK_LIKELY(!duk_hobject_proxy_check(obj, - &h_proxy_target, - &h_proxy_handler))) { + if (DUK_LIKELY(!duk_hobject_proxy_check(obj, &h_proxy_target, &h_proxy_handler))) { goto skip_proxy; } @@ -41188,8 +42080,8 @@ /* obj handler trap */ duk_insert(thr, -2); - duk_push_hobject(thr, h_proxy_target); /* -> obj trap handler target */ - duk_call_method(thr, 1 /*nargs*/); /* -> obj trap_result */ + duk_push_hobject(thr, h_proxy_target); /* -> obj trap handler target */ + duk_call_method(thr, 1 /*nargs*/); /* -> obj trap_result */ h_trap_result = duk_require_hobject(thr, -1); DUK_UNREF(h_trap_result); @@ -41200,8 +42092,8 @@ duk_proxy_ownkeys_postprocess(thr, h_proxy_target, enum_flags); return 1; - skip_proxy: -#endif /* DUK_USE_ES6_PROXY */ +skip_proxy: +#endif /* DUK_USE_ES6_PROXY */ DUK_ASSERT_TOP(thr, 1); magic = duk_get_current_magic(thr); @@ -41209,7 +42101,7 @@ enum_flags = duk__object_keys_enum_flagsmagic; return duk_hobject_get_enumerated_keys(thr, enum_flags); } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ #if defined(DUK_USE_OBJECT_BUILTIN) || defined(DUK_USE_REFLECT_BUILTIN) DUK_INTERNAL duk_ret_t duk_bi_object_constructor_prevent_extensions(duk_hthread *thr) { @@ -41229,12 +42121,8 @@ /* Object.preventExtensions() silent success for non-object. */ if (magic == 0) { - mask |= DUK_TYPE_MASK_UNDEFINED | - DUK_TYPE_MASK_NULL | - DUK_TYPE_MASK_BOOLEAN | - DUK_TYPE_MASK_NUMBER | - DUK_TYPE_MASK_STRING | - DUK_TYPE_MASK_POINTER; + mask |= DUK_TYPE_MASK_UNDEFINED | DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER | + DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_POINTER; } if (duk_check_type_mask(thr, 0, mask)) { @@ -41251,13 +42139,13 @@ */ duk_hobject_compact_props(thr, h); - done: +done: if (magic == 1) { duk_push_true(thr); } return 1; } -#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_OBJECT_BUILTIN || DUK_USE_REFLECT_BUILTIN */ /* * __defineGetter__, __defineSetter__, __lookupGetter__, __lookupSetter__ @@ -41273,9 +42161,10 @@ /* ToObject(this) key getter/setter */ /* ToPropertyKey() coercion is not needed, duk_def_prop() does it. */ - duk_def_prop(thr, 0, DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE | - (duk_get_current_magic(thr) ? DUK_DEFPROP_HAVE_SETTER : DUK_DEFPROP_HAVE_GETTER)); + duk_def_prop(thr, + 0, + DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE | + (duk_get_current_magic(thr) ? DUK_DEFPROP_HAVE_SETTER : DUK_DEFPROP_HAVE_GETTER)); return 0; } DUK_INTERNAL duk_ret_t duk_bi_object_prototype_lookupaccessor(duk_hthread *thr) { @@ -41310,7 +42199,7 @@ } return 1; } -#endif /* DUK_USE_ES8 */ +#endif /* DUK_USE_ES8 */ #line 1 "duk_bi_performance.c" /* * High resolution time API (performance.now() et al) @@ -41332,7 +42221,7 @@ return 1; } -#if 0 /* Missing until semantics decided. */ +#if 0 /* Missing until semantics decided. */ DUK_INTERNAL duk_ret_t duk_bi_performance_timeorigin_getter(duk_hthread *thr) { /* No decision yet how to handle timeOrigins, e.g. should one be * initialized per heap, or per global object set. See @@ -41341,8 +42230,8 @@ duk_push_uint(thr, 0); return 1; } -#endif /* 0 */ -#endif /* DUK_USE_PERFORMANCE_BUILTIN */ +#endif /* 0 */ +#endif /* DUK_USE_PERFORMANCE_BUILTIN */ #line 1 "duk_bi_pointer.c" /* * Pointer built-ins @@ -41369,9 +42258,8 @@ if (duk_is_constructor_call(thr)) { (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER), DUK_BIDX_POINTER_PROTOTYPE); /* Pointer object internal value is immutable. */ @@ -41416,7 +42304,7 @@ } return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } #line 1 "duk_bi_promise.c" @@ -41463,7 +42351,7 @@ DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_PROMISE_BUILTIN */ +#endif /* DUK_USE_PROMISE_BUILTIN */ #line 1 "duk_bi_proxy.c" /* * Proxy built-in (ES2015) @@ -41535,7 +42423,7 @@ duk_def_prop(thr, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_SET_WEC); continue; - skip_key: + skip_key: duk_pop(thr); continue; } @@ -41552,17 +42440,17 @@ * handled above. */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ES6_PROXY) DUK_INTERNAL duk_ret_t duk_bi_proxy_constructor(duk_hthread *thr) { - DUK_ASSERT_TOP(thr, 2); /* target handler */ + DUK_ASSERT_TOP(thr, 2); /* target handler */ duk_require_constructor_call(thr); - duk_push_proxy(thr, 0 /*flags*/); /* target handler -> proxy */ - return 1; /* replacement */ + duk_push_proxy(thr, 0 /*flags*/); /* target handler -> proxy */ + return 1; /* replacement */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #line 1 "duk_bi_reflect.c" /* * 'Reflect' built-in (ES2016 Section 26.1) @@ -41613,7 +42501,7 @@ tv_obj = DUK_GET_TVAL_POSIDX(thr, 0); tv_key = DUK_GET_TVAL_POSIDX(thr, 1); - (void) duk_hobject_getprop(thr, tv_obj, tv_key); /* This could also be a duk_get_prop(). */ + (void) duk_hobject_getprop(thr, tv_obj, tv_key); /* This could also be a duk_get_prop(). */ return 1; } @@ -41662,7 +42550,7 @@ duk_push_boolean(thr, ret); return 1; } -#endif /* DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_REFLECT_BUILTIN */ #line 1 "duk_bi_regexp.c" /* * RegExp built-ins @@ -41679,7 +42567,7 @@ h = duk_require_hobject_with_class(thr, -1, DUK_HOBJECT_CLASS_REGEXP); DUK_ASSERT(h != NULL); DUK_UNREF(h); - duk_insert(thr, 0); /* prepend regexp to valstack 0 index */ + duk_insert(thr, 0); /* prepend regexp to valstack 0 index */ } /* XXX: much to improve (code size) */ @@ -41689,10 +42577,8 @@ DUK_ASSERT_TOP(thr, 2); h_pattern = duk_get_hobject(thr, 0); - if (!duk_is_constructor_call(thr) && - h_pattern != NULL && - DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP && - duk_is_undefined(thr, 1)) { + if (!duk_is_constructor_call(thr) && h_pattern != NULL && + DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP && duk_is_undefined(thr, 1)) { /* Called as a function, pattern has Class "RegExp" and * flags is undefined -> return object as is. */ @@ -41707,8 +42593,7 @@ * call. */ - if (h_pattern != NULL && - DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP) { + if (h_pattern != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(h_pattern) == DUK_HOBJECT_CLASS_REGEXP) { duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_SOURCE); if (duk_is_undefined(thr, 1)) { /* In ES5 one would need to read the flags individually; @@ -41724,20 +42609,21 @@ duk_push_hstring_empty(thr); } else { duk_dup_0(thr); - duk_to_string(thr, -1); /* Rejects Symbols. */ + duk_to_string(thr, -1); /* Rejects Symbols. */ } if (duk_is_undefined(thr, 1)) { duk_push_hstring_empty(thr); } else { duk_dup_1(thr); - duk_to_string(thr, -1); /* Rejects Symbols. */ + duk_to_string(thr, -1); /* Rejects Symbols. */ } /* ... pattern flags */ } DUK_DDD(DUK_DDDPRINT("RegExp constructor/function call, pattern=%!T, flags=%!T", - (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); + (duk_tval *) duk_get_tval(thr, -2), + (duk_tval *) duk_get_tval(thr, -1))); /* ... pattern flags (both uncoerced) */ @@ -41787,7 +42673,7 @@ duk_push_this(thr); duk_push_literal(thr, "/"); duk_get_prop_stridx(thr, 0, DUK_STRIDX_SOURCE); - duk_dup_m2(thr); /* another "/" */ + duk_dup_m2(thr); /* another "/" */ duk_get_prop_stridx(thr, 0, DUK_STRIDX_FLAGS); duk_concat(thr, 4); return 1; @@ -41797,7 +42683,7 @@ /* .flags is ES2015 but present even when ES2015 bindings are * disabled because the constructor relies on it. */ - duk_uint8_t buf8; /* enough for all flags + NUL */ + duk_uint8_t buf8; /* enough for all flags + NUL */ duk_uint8_t *p = buf; /* .flags is generic and works on any object. */ @@ -41838,7 +42724,7 @@ duk_xget_owndataprop_stridx_short(thr, 0, DUK_STRIDX_INT_SOURCE); duk_xget_owndataprop_stridx_short(thr, 0, DUK_STRIDX_INT_BYTECODE); h_bc = duk_require_hstring(thr, -1); - re_flags = (duk_small_uint_t) DUK_HSTRING_GET_DATA(h_bc)0; /* Safe even if h_bc length is 0 (= NUL) */ + re_flags = (duk_small_uint_t) DUK_HSTRING_GET_DATA(h_bc)0; /* Safe even if h_bc length is 0 (= NUL) */ duk_pop(thr); } else if (h == thr->builtinsDUK_BIDX_REGEXP_PROTOTYPE) { /* In ES2015 and ES2016 a TypeError would be thrown here. @@ -41849,7 +42735,7 @@ if (magic != 16 /* .source */) { return 0; } - duk_push_literal(thr, "(?:)"); /* .source handled by switch-case */ + duk_push_literal(thr, "(?:)"); /* .source handled by switch-case */ re_flags = 0; } else { DUK_DCERROR_TYPE_INVALID_ARGS(thr); @@ -41858,15 +42744,15 @@ /* regexp source */ switch (magic) { - case 0: { /* global */ + case 0: { /* global */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_GLOBAL)); break; } - case 1: { /* ignoreCase */ + case 1: { /* ignoreCase */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_IGNORE_CASE)); break; } - case 2: { /* multiline */ + case 2: { /* multiline */ duk_push_boolean(thr, (re_flags & DUK_RE_FLAG_MULTILINE)); break; } @@ -41880,7 +42766,7 @@ break; } #endif - default: { /* source */ + default: { /* source */ /* leave 'source' on top */ break; } @@ -41889,7 +42775,7 @@ return 1; } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #line 1 "duk_bi_string.c" /* * String built-ins @@ -41929,7 +42815,8 @@ return h; } -DUK_LOCAL duk_int_t duk__str_search_shared(duk_hthread *thr, duk_hstring *h_this, duk_hstring *h_search, duk_int_t start_cpos, duk_bool_t backwards) { +DUK_LOCAL duk_int_t +duk__str_search_shared(duk_hthread *thr, duk_hstring *h_this, duk_hstring *h_search, duk_int_t start_cpos, duk_bool_t backwards) { duk_int_t cpos; duk_int_t bpos; const duk_uint8_t *p_start, *p_end, *p; @@ -41964,7 +42851,7 @@ * must be updated if 'p' is wound back (backward scanning). */ - firstbyte = q_start0; /* leading byte of match string */ + firstbyte = q_start0; /* leading byte of match string */ while (p <= p_end && p >= p_start) { t = *p; @@ -42030,15 +42917,13 @@ duk_replace(thr, 0); } } - duk_to_string(thr, 0); /* catches symbol argument for constructor call */ + duk_to_string(thr, 0); /* catches symbol argument for constructor call */ DUK_ASSERT(duk_is_string(thr, 0)); - duk_set_top(thr, 1); /* Top may be 1 or larger. */ + duk_set_top(thr, 1); /* Top may be 1 or larger. */ if (duk_is_constructor_call(thr)) { /* String object internal value is immutable */ - flags = DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | + flags = DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_STRING); duk_push_object_helper(thr, flags, DUK_BIDX_STRING_PROTOTYPE); duk_dup_0(thr); @@ -42064,7 +42949,7 @@ n = duk_get_top(thr); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, (duk_size_t) n); /* initial estimate for ASCII only codepoints */ + DUK_BW_INIT_PUSHBUF(thr, bw, (duk_size_t) n); /* initial estimate for ASCII only codepoints */ for (i = 0; i < n; i++) { /* XXX: could improve bufwriter handling to write multiple codepoints @@ -42078,8 +42963,7 @@ * the same. */ duk_int32_t i32 = 0; - if (!duk_is_whole_get_int32(duk_to_number(thr, i), &i32) || - i32 < 0 || i32 > 0x10ffffL) { + if (!duk_is_whole_get_int32(duk_to_number(thr, i), &i32) || i32 < 0 || i32 > 0x10ffffL) { DUK_DCERROR_RANGE_INVALID_ARGS(thr); } DUK_ASSERT(i32 >= 0 && i32 <= 0x10ffffL); @@ -42103,7 +42987,7 @@ } DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 or CESU-8 encoded. */ + (void) duk_buffer_to_string(thr, -1); /* Safe, extended UTF-8 or CESU-8 encoded. */ return 1; } @@ -42145,10 +43029,10 @@ goto type_error; } - (void) duk_require_hstring_notsymbol(thr, -1); /* Reject symbols (and wrapped symbols). */ + (void) duk_require_hstring_notsymbol(thr, -1); /* Reject symbols (and wrapped symbols). */ return 1; - type_error: +type_error: DUK_DCERROR_TYPE_INVALID_ARGS(thr); } @@ -42284,7 +43168,7 @@ * ("undefined" and "null"). */ duk_push_this(thr); - h = duk_to_hstring_m1(thr); /* Reject Symbols. */ + h = duk_to_hstring_m1(thr); /* Reject Symbols. */ DUK_ASSERT(h != NULL); len = (duk_int_t) DUK_HSTRING_GET_CHARLEN(h); @@ -42316,7 +43200,7 @@ duk_substring(thr, -1, (duk_size_t) start_pos, (duk_size_t) end_pos); return 1; } -#endif /* DUK_USE_SECTION_B */ +#endif /* DUK_USE_SECTION_B */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_slice(duk_hthread *thr) { duk_hstring *h; @@ -42375,7 +43259,7 @@ duk_hstring *h_search; duk_int_t clen_this; duk_int_t cpos; - duk_small_uint_t is_lastindexof = (duk_small_uint_t) duk_get_current_magic(thr); /* 0=indexOf, 1=lastIndexOf */ + duk_small_uint_t is_lastindexof = (duk_small_uint_t) duk_get_current_magic(thr); /* 0=indexOf, 1=lastIndexOf */ h_this = duk_push_this_coercible_to_string(thr); DUK_ASSERT(h_this != NULL); @@ -42432,7 +43316,7 @@ duk_int_t match_caps; #endif duk_uint32_t prev_match_end_boff; - const duk_uint8_t *r_start, *r_end, *r; /* repl string scan */ + const duk_uint8_t *r_start, *r_end, *r; /* repl string scan */ duk_size_t tmp_sz; DUK_ASSERT_TOP(thr, 2); @@ -42440,7 +43324,7 @@ DUK_ASSERT(h_input != NULL); bw = &bw_alloc; - DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* input size is good output starting point */ + DUK_BW_INIT_PUSHBUF(thr, bw, DUK_HSTRING_GET_BYTELEN(h_input)); /* input size is good output starting point */ DUK_ASSERT_TOP(thr, 4); @@ -42461,11 +43345,11 @@ duk_push_int(thr, 0); duk_put_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ DUK_DCERROR_UNSUPPORTED(thr); -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } else { - duk_to_string(thr, 0); /* rejects symbols */ + duk_to_string(thr, 0); /* rejects symbols */ #if defined(DUK_USE_REGEXP_SUPPORT) is_regexp = 0; is_global = 0; @@ -42480,7 +43364,7 @@ duk_hstring *h_repl; is_repl_func = 0; - h_repl = duk_to_hstring(thr, 1); /* reject symbols */ + h_repl = duk_to_hstring(thr, 1); /* reject symbols */ DUK_ASSERT(h_repl != NULL); r_start = DUK_HSTRING_GET_DATA(h_repl); r_end = r_start + DUK_HSTRING_GET_BYTELEN(h_repl); @@ -42518,7 +43402,7 @@ if (is_regexp) { duk_dup_0(thr); duk_dup_2(thr); - duk_regexp_match(thr); /* ... regexp input -> res_obj */ + duk_regexp_match(thr); /* ... regexp input -> res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); break; @@ -42532,7 +43416,7 @@ duk_get_prop_index(thr, -1, 0); DUK_ASSERT(duk_is_string(thr, -1)); h_match = duk_known_hstring(thr, -1); - duk_pop(thr); /* h_match is borrowed, remains reachable through match_obj */ + duk_pop(thr); /* h_match is borrowed, remains reachable through match_obj */ if (DUK_HSTRING_GET_BYTELEN(h_match) == 0) { /* This should be equivalent to match() algorithm step 8.f.iii.2: @@ -42543,25 +43427,26 @@ duk_get_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); last_index = (duk_uint32_t) duk_get_uint(thr, -1); DUK_DDD(DUK_DDDPRINT("empty match, bump lastIndex: %ld -> %ld", - (long) last_index, (long) (last_index + 1))); + (long) last_index, + (long) (last_index + 1))); duk_pop(thr); duk_push_uint(thr, (duk_uint_t) (last_index + 1)); duk_put_prop_stridx_short(thr, 0, DUK_STRIDX_LAST_INDEX); } - DUK_ASSERT(duk_get_length(thr, -1) <= DUK_INT_MAX); /* string limits */ + DUK_ASSERT(duk_get_length(thr, -1) <= DUK_INT_MAX); /* string limits */ match_caps = (duk_int_t) duk_get_length(thr, -1); } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ - const duk_uint8_t *q_start; /* match string */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ + const duk_uint8_t *q_start; /* match string */ duk_size_t p_blen; duk_size_t q_blen; #if defined(DUK_USE_REGEXP_SUPPORT) - DUK_ASSERT(!is_global); /* single match always */ + DUK_ASSERT(!is_global); /* single match always */ #endif p_start = DUK_HSTRING_GET_DATA(h_input); @@ -42574,10 +43459,10 @@ q_blen = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_search); if (q_blen > p_blen) { - break; /* no match */ + break; /* no match */ } - p_end -= q_blen; /* ensure full memcmp() fits in while */ + p_end -= q_blen; /* ensure full memcmp() fits in while */ DUK_ASSERT(p_end >= p); match_start_coff = 0; @@ -42603,7 +43488,7 @@ /* not found */ break; } - found: + found: /* stack0 = search value * stack1 = replace value @@ -42637,9 +43522,9 @@ duk_get_prop_index(thr, 4, (duk_uarridx_t) idx); } } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* match == search string, by definition */ duk_dup_0(thr); } @@ -42649,12 +43534,12 @@ /* ... replacer match captures match_char_offset input */ duk_call(thr, duk_get_top(thr) - idx_args); - h_repl = duk_to_hstring_m1(thr); /* -> ... repl_value */ + h_repl = duk_to_hstring_m1(thr); /* -> ... repl_value */ DUK_ASSERT(h_repl != NULL); DUK_BW_WRITE_ENSURE_HSTRING(thr, bw, h_repl); - duk_pop(thr); /* repl_value */ + duk_pop(thr); /* repl_value */ } else { r = r_start; @@ -42701,9 +43586,10 @@ * match codepoint encodings would have different lengths. */ /* XXX: charlen computed here, and also in char2byte helper. */ - match_end_boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte(thr, - h_input, - match_start_coff + (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_match)); + match_end_boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte( + thr, + h_input, + match_start_coff + (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_match)); tmp_sz = (duk_size_t) (DUK_HSTRING_GET_BYTELEN(h_input) - match_end_boff); DUK_BW_WRITE_ENSURE_BYTES(thr, bw, DUK_HSTRING_GET_DATA(h_input) + match_end_boff, tmp_sz); @@ -42739,7 +43625,7 @@ } if (capnum > 0 && capnum < match_caps) { - DUK_ASSERT(is_regexp != 0); /* match_caps == 0 without regexps */ + DUK_ASSERT(is_regexp != 0); /* match_caps == 0 without regexps */ /* regexp res_obj is at offset 4 */ duk_get_prop_index(thr, 4, (duk_uarridx_t) capnum); @@ -42758,26 +43644,26 @@ } else { goto repl_write; } -#else /* DUK_USE_REGEXP_SUPPORT */ - goto repl_write; /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - } /* default case */ - } /* switch (ch2) */ +#else /* DUK_USE_REGEXP_SUPPORT */ + goto repl_write; /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + } /* default case */ + } /* switch (ch2) */ - repl_write: + repl_write: /* ch1 = (r_increment << 8) + byte */ DUK_BW_WRITE_ENSURE_U8(thr, bw, (duk_uint8_t) (ch1 & 0xff)); r += ch1 >> 8; - } /* while repl */ - } /* if (is_repl_func) */ + } /* while repl */ + } /* if (is_repl_func) */ - duk_pop(thr); /* pop regexp res_obj or match string */ + duk_pop(thr); /* pop regexp res_obj or match string */ #if defined(DUK_USE_REGEXP_SUPPORT) if (!is_global) { #else - { /* unconditionally; is_global==0 */ + { /* unconditionally; is_global==0 */ #endif break; } @@ -42789,7 +43675,7 @@ DUK_ASSERT_TOP(thr, 4); DUK_BW_COMPACT(thr, bw); - (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if inputs are safe. */ return 1; } @@ -42809,7 +43695,7 @@ #if defined(DUK_USE_REGEXP_SUPPORT) duk_bool_t is_regexp; #endif - duk_bool_t matched; /* set to 1 if any match exists (needed for empty input special case) */ + duk_bool_t matched; /* set to 1 if any match exists (needed for empty input special case) */ duk_uint32_t prev_match_end_coff, prev_match_end_boff; duk_uint32_t match_start_boff, match_start_coff; duk_uint32_t match_end_boff, match_end_coff; @@ -42847,7 +43733,7 @@ #if defined(DUK_USE_REGEXP_SUPPORT) duk_push_hobject_bidx(thr, DUK_BIDX_REGEXP_CONSTRUCTOR); duk_dup_0(thr); - duk_new(thr, 1); /* ... RegExp val -> ... res */ + duk_new(thr, 1); /* ... RegExp val -> ... res */ duk_replace(thr, 0); /* lastIndex is initialized to zero by new RegExp() */ is_regexp = 1; @@ -42886,7 +43772,7 @@ if (is_regexp) { duk_dup_0(thr); duk_dup_2(thr); - duk_regexp_match_force_global(thr); /* ... regexp input -> res_obj */ + duk_regexp_match_force_global(thr); /* ... regexp input -> res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); break; @@ -42919,23 +43805,23 @@ continue; } } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ - const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ - const duk_uint8_t *q_start; /* match string */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ + const duk_uint8_t *p_start, *p_end, *p; /* input string scan */ + const duk_uint8_t *q_start; /* match string */ duk_size_t q_blen, q_clen; p_start = DUK_HSTRING_GET_DATA(h_input); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_input); p = p_start + prev_match_end_boff; - h_sep = duk_known_hstring(thr, 0); /* symbol already rejected above */ + h_sep = duk_known_hstring(thr, 0); /* symbol already rejected above */ q_start = DUK_HSTRING_GET_DATA(h_sep); q_blen = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sep); q_clen = (duk_size_t) DUK_HSTRING_GET_CHARLEN(h_sep); - p_end -= q_blen; /* ensure full memcmp() fits in while */ + p_end -= q_blen; /* ensure full memcmp() fits in while */ match_start_coff = prev_match_end_coff; @@ -42948,7 +43834,7 @@ * Don't allow an empty string to match at the end of the input. */ - matched = 1; /* empty separator can always match */ + matched = 1; /* empty separator can always match */ match_start_coff++; p++; @@ -42964,7 +43850,7 @@ DUK_ASSERT(q_blen > 0 && q_clen > 0); while (p <= p_end) { DUK_ASSERT(p + q_blen <= DUK_HSTRING_GET_DATA(h_input) + DUK_HSTRING_GET_BYTELEN(h_input)); - DUK_ASSERT(q_blen > 0); /* no issues with empty memcmp() */ + DUK_ASSERT(q_blen > 0); /* no issues with empty memcmp() */ if (duk_memcmp((const void *) p, (const void *) q_start, (size_t) q_blen) == 0) { /* never an empty match, so step 13.c.iii can't be triggered */ goto found; @@ -42977,15 +43863,15 @@ p++; } - not_found: + not_found: /* not found */ break; - found: + found: matched = 1; match_start_boff = (duk_uint32_t) (p - p_start); - match_end_coff = (duk_uint32_t) (match_start_coff + q_clen); /* constrained by string length */ - match_end_boff = (duk_uint32_t) (match_start_boff + q_blen); /* ditto */ + match_end_coff = (duk_uint32_t) (match_start_coff + q_clen); /* constrained by string length */ + match_end_boff = (duk_uint32_t) (match_start_boff + q_blen); /* ditto */ /* empty match (may happen with empty separator) -> bump and continue */ if (prev_match_end_boff == match_end_boff) { @@ -42993,7 +43879,7 @@ prev_match_end_coff++; continue; } - } /* if (is_regexp) */ + } /* if (is_regexp) */ /* stack0 = separator (string or regexp) * stack1 = limit @@ -43003,9 +43889,12 @@ */ DUK_DDD(DUK_DDDPRINT("split; match_start b=%ld,c=%ld, match_end b=%ld,c=%ld, prev_end b=%ld,c=%ld", - (long) match_start_boff, (long) match_start_coff, - (long) match_end_boff, (long) match_end_coff, - (long) prev_match_end_boff, (long) prev_match_end_coff)); + (long) match_start_boff, + (long) match_start_coff, + (long) match_end_boff, + (long) match_end_coff, + (long) prev_match_end_boff, + (long) prev_match_end_coff)); duk_push_lstring(thr, (const char *) (DUK_HSTRING_GET_DATA(h_input) + prev_match_end_boff), @@ -43022,7 +43911,7 @@ len = duk_get_length(thr, 4); for (i = 1; i < len; i++) { - DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* cannot have >4G captures */ + DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* cannot have >4G captures */ duk_get_prop_index(thr, 4, (duk_uarridx_t) i); duk_put_prop_index(thr, 3, arr_idx); arr_idx++; @@ -43034,21 +43923,21 @@ duk_pop(thr); /* lastIndex already set up for next match */ } else { -#else /* DUK_USE_REGEXP_SUPPORT */ - { /* unconditionally */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ + { + /* unconditionally */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* no action */ } prev_match_end_boff = match_end_boff; prev_match_end_coff = match_end_coff; continue; - } /* for */ + } /* for */ /* Combined step 11 (empty string special case) and 14-15. */ - DUK_DDD(DUK_DDDPRINT("split trailer; prev_end b=%ld,c=%ld", - (long) prev_match_end_boff, (long) prev_match_end_coff)); + DUK_DDD(DUK_DDDPRINT("split trailer; prev_end b=%ld,c=%ld", (long) prev_match_end_boff, (long) prev_match_end_coff)); if (DUK_HSTRING_GET_BYTELEN(h_input) > 0 || !matched) { /* Add trailer if: @@ -43065,7 +43954,7 @@ return 1; - hit_limit: +hit_limit: #if defined(DUK_USE_REGEXP_SUPPORT) if (is_regexp) { duk_pop(thr); @@ -43097,13 +43986,13 @@ } return; - do_new: +do_new: duk_push_hobject_bidx(thr, DUK_BIDX_REGEXP_CONSTRUCTOR); duk_dup(thr, idx); - duk_new(thr, 1); /* ... RegExp val -> ... res */ + duk_new(thr, 1); /* ... RegExp val -> ... res */ duk_replace(thr, idx); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_search(duk_hthread *thr) { @@ -43118,7 +44007,7 @@ */ DUK_ASSERT_TOP(thr, 1); - (void) duk_push_this_coercible_to_string(thr); /* at index 1 */ + (void) duk_push_this_coercible_to_string(thr); /* at index 1 */ duk__to_regexp_helper(thr, 0 /*index*/, 1 /*force_new*/); /* stack0 = regexp @@ -43130,8 +44019,8 @@ */ duk_dup_0(thr); - duk_dup_1(thr); /* ... re_obj input */ - duk_regexp_match(thr); /* -> ... res_obj */ + duk_dup_1(thr); /* ... re_obj input */ + duk_regexp_match(thr); /* -> ... res_obj */ if (!duk_is_object(thr, -1)) { duk_push_int(thr, -1); @@ -43142,7 +44031,7 @@ DUK_ASSERT(duk_is_number(thr, -1)); return 1; } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #if defined(DUK_USE_REGEXP_SUPPORT) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_match(duk_hthread *thr) { @@ -43162,8 +44051,8 @@ */ if (!global) { - duk_regexp_match(thr); /* -> res_obj */ - return 1; /* return 'res_obj' */ + duk_regexp_match(thr); /* -> res_obj */ + return 1; /* return 'res_obj' */ } /* Global case is more complex. */ @@ -43184,7 +44073,7 @@ duk_dup_0(thr); duk_dup_1(thr); - duk_regexp_match(thr); /* -> ... regexp string -> ... res_obj */ + duk_regexp_match(thr); /* -> ... regexp string -> ... res_obj */ if (!duk_is_object(thr, -1)) { duk_pop(thr); @@ -43203,24 +44092,24 @@ } prev_last_index = this_index; - duk_get_prop_index(thr, -1, 0); /* match string */ + duk_get_prop_index(thr, -1, 0); /* match string */ duk_put_prop_index(thr, 2, (duk_uarridx_t) arr_idx); arr_idx++; - duk_pop(thr); /* res_obj */ + duk_pop(thr); /* res_obj */ } if (arr_idx == 0) { duk_push_null(thr); } - return 1; /* return 'res_arr' or 'null' */ + return 1; /* return 'res_arr' or 'null' */ } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_concat(duk_hthread *thr) { /* duk_concat() coerces arguments with ToString() in correct order */ (void) duk_push_this_coercible_to_string(thr); - duk_insert(thr, 0); /* this is relatively expensive */ + duk_insert(thr, 0); /* this is relatively expensive */ duk_concat(thr, duk_get_top(thr)); return 1; } @@ -43285,10 +44174,10 @@ #if defined(DUK_USE_PREFER_SIZE) p = buf; while (count-- > 0) { - duk_memcpy((void *) p, (const void *) src, input_blen); /* copy size may be zero, but pointers are valid */ + duk_memcpy((void *) p, (const void *) src, input_blen); /* copy size may be zero, but pointers are valid */ p += input_blen; } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* Take advantage of already copied pieces to speed up the process * especially for small repeated strings. */ @@ -43298,7 +44187,9 @@ for (;;) { duk_size_t remain = (duk_size_t) (p_end - p); DUK_DDD(DUK_DDDPRINT("remain=%ld, copy_size=%ld, input_blen=%ld, result_len=%ld", - (long) remain, (long) copy_size, (long) input_blen, + (long) remain, + (long) copy_size, + (long) input_blen, (long) result_len)); if (remain <= copy_size) { /* If result_len is zero, this case is taken and does @@ -43311,10 +44202,10 @@ p += copy_size; } - src = (const duk_uint8_t *) buf; /* Use buf as source for larger copies. */ + src = (const duk_uint8_t *) buf; /* Use buf as source for larger copies. */ copy_size = (duk_size_t) (p - buf); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ /* XXX: It would be useful to be able to create a duk_hstring with * a certain byte size whose data area wasn't initialized and which @@ -43325,13 +44216,13 @@ * intern table (they are not in heap_allocated). */ - duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ + duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ return 1; - fail_range: +fail_range: DUK_DCERROR_RANGE_INVALID_ARGS(thr); } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ DUK_INTERNAL duk_ret_t duk_bi_string_prototype_locale_compare(duk_hthread *thr) { duk_hstring *h1; @@ -43385,7 +44276,7 @@ ret = -1; goto done; - done: +done: duk_push_int(thr, (duk_int_t) ret); return 1; } @@ -43472,11 +44363,11 @@ } } - finish: +finish: duk_push_boolean(thr, result); return 1; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if defined(DUK_USE_ES6) DUK_INTERNAL duk_ret_t duk_bi_string_prototype_includes(duk_hthread *thr) { @@ -43499,8 +44390,8 @@ duk_push_boolean(thr, pos >= 0); return 1; } -#endif /* DUK_USE_ES6 */ -#endif /* DUK_USE_STRING_BUILTIN */ +#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_STRING_BUILTIN */ #line 1 "duk_bi_symbol.c" /* * Symbol built-in @@ -43543,7 +44434,7 @@ buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, 1 + len + 1 + 17 + 1); DUK_ASSERT(buf != NULL); p = buf + 1; - DUK_ASSERT(desc != NULL || len == 0); /* may be NULL if len is 0 */ + DUK_ASSERT(desc != NULL || len == 0); /* may be NULL if len is 0 */ duk_memcpy_unsafe((void *) p, (const void *) desc, len); p += len; if (magic == 0) { @@ -43554,7 +44445,9 @@ if (++thr->heap->sym_counter0 == 0) { thr->heap->sym_counter1++; } - p += DUK_SPRINTF((char *) p, "\xFF" "%lx-%lx", + p += DUK_SPRINTF((char *) p, + "\xFF" + "%lx-%lx", (unsigned long) thr->heap->sym_counter1, (unsigned long) thr->heap->sym_counter0); if (desc == NULL) { @@ -43671,7 +44564,7 @@ return 1; } -#endif /* DUK_USE_SYMBOL_BUILTIN */ +#endif /* DUK_USE_SYMBOL_BUILTIN */ #line 1 "duk_bi_thread.c" /* * Thread builtins @@ -43706,7 +44599,7 @@ */ duk_push_hobject(new_thr, func); - return 1; /* return thread */ + return 1; /* return thread */ } #endif @@ -43752,14 +44645,15 @@ */ if (thr->callstack_top < 2) { - DUK_DD(DUK_DDPRINT("resume state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.resume)")); + DUK_DD(DUK_DDPRINT( + "resume state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.resume)")); goto state_error; } DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr))); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ caller_func = DUK_ACT_GET_FUNC(thr->callstack_curr->parent); if (!DUK_HOBJECT_IS_COMPFUNC(caller_func)) { @@ -43771,14 +44665,12 @@ * like for yield. */ - if (thr_resume->state != DUK_HTHREAD_STATE_INACTIVE && - thr_resume->state != DUK_HTHREAD_STATE_YIELDED) { + if (thr_resume->state != DUK_HTHREAD_STATE_INACTIVE && thr_resume->state != DUK_HTHREAD_STATE_YIELDED) { DUK_DD(DUK_DDPRINT("resume state invalid: target thread must be INACTIVE or YIELDED")); goto state_error; } - DUK_ASSERT(thr_resume->state == DUK_HTHREAD_STATE_INACTIVE || - thr_resume->state == DUK_HTHREAD_STATE_YIELDED); + DUK_ASSERT(thr_resume->state == DUK_HTHREAD_STATE_INACTIVE || thr_resume->state == DUK_HTHREAD_STATE_YIELDED); /* Further state-dependent pre-checks */ @@ -43796,14 +44688,13 @@ * because an error in the RESUME handler call processing will * not be handled very cleanly. */ - if ((thr_resume->callstack_top != 0) || - (thr_resume->valstack_top - thr_resume->valstack != 1)) { + if ((thr_resume->callstack_top != 0) || (thr_resume->valstack_top - thr_resume->valstack != 1)) { goto state_error; } duk_push_tval(thr, DUK_GET_TVAL_NEGIDX(thr_resume, -1)); duk_resolve_nonbound_function(thr); - h_fun = duk_require_hobject(thr, -1); /* reject lightfuncs on purpose */ + h_fun = duk_require_hobject(thr, -1); /* reject lightfuncs on purpose */ if (!DUK_HOBJECT_IS_CALLABLE(h_fun) || !DUK_HOBJECT_IS_COMPFUNC(h_fun)) { goto state_error; } @@ -43832,8 +44723,8 @@ #if defined(DUK_USE_AUGMENT_ERROR_THROW) if (is_error) { - DUK_ASSERT_TOP(thr, 2); /* value (error) is at stack top */ - duk_err_augment_error_throw(thr); /* in resumer's context */ + DUK_ASSERT_TOP(thr, 2); /* value (error) is at stack top */ + duk_err_augment_error_throw(thr); /* in resumer's context */ } #endif @@ -43857,21 +44748,21 @@ /* lj value2: thread */ DUK_ASSERT(thr->valstack_bottom < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value2, &thr->valstack_bottom0); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value2, &thr->valstack_bottom0); /* side effects */ /* lj value1: value */ DUK_ASSERT(thr->valstack_bottom + 1 < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom1); /* side effects */ DUK_TVAL_CHKFAST_INPLACE_SLOW(&thr->heap->lj.value1); thr->heap->lj.iserror = is_error; - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ - duk_err_longjmp(thr); /* execution resumes in bytecode executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ + duk_err_longjmp(thr); /* execution resumes in bytecode executor */ DUK_UNREACHABLE(); /* Never here, fall through to error (from compiler point of view). */ - state_error: +state_error: DUK_DCERROR_TYPE_INVALID_STATE(thr); } #endif @@ -43920,14 +44811,15 @@ DUK_ASSERT(thr->resumer->state == DUK_HTHREAD_STATE_RESUMED); if (thr->callstack_top < 2) { - DUK_DD(DUK_DDPRINT("yield state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.yield)")); + DUK_DD(DUK_DDPRINT( + "yield state invalid: callstack should contain at least 2 entries (caller and Duktape.Thread.yield)")); goto state_error; } DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL); /* us */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr))); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ + DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL); /* caller */ caller_func = DUK_ACT_GET_FUNC(thr->callstack_curr->parent); if (!DUK_HOBJECT_IS_COMPFUNC(caller_func)) { @@ -43935,10 +44827,11 @@ goto state_error; } - DUK_ASSERT(thr->callstack_preventcount >= 1); /* should never be zero, because we (Duktape.Thread.yield) are on the stack */ + DUK_ASSERT(thr->callstack_preventcount >= 1); /* should never be zero, because we (Duktape.Thread.yield) are on the stack */ if (thr->callstack_preventcount != 1) { /* Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0 */ - DUK_DD(DUK_DDPRINT("yield state invalid: there must be no yield-preventing calls in current thread callstack (preventcount is %ld)", + DUK_DD(DUK_DDPRINT("yield state invalid: there must be no yield-preventing calls in current thread callstack " + "(preventcount is %ld)", (long) thr->callstack_preventcount)); goto state_error; } @@ -43952,18 +44845,16 @@ #if defined(DUK_USE_AUGMENT_ERROR_THROW) if (is_error) { - DUK_ASSERT_TOP(thr, 1); /* value (error) is at stack top */ - duk_err_augment_error_throw(thr); /* in yielder's context */ + DUK_ASSERT_TOP(thr, 1); /* value (error) is at stack top */ + duk_err_augment_error_throw(thr); /* in yielder's context */ } #endif #if defined(DUK_USE_DEBUG) if (is_error) { - DUK_DDD(DUK_DDDPRINT("YIELD ERROR: value=%!T", - (duk_tval *) duk_get_tval(thr, 0))); + DUK_DDD(DUK_DDDPRINT("YIELD ERROR: value=%!T", (duk_tval *) duk_get_tval(thr, 0))); } else { - DUK_DDD(DUK_DDDPRINT("YIELD NORMAL: value=%!T", - (duk_tval *) duk_get_tval(thr, 0))); + DUK_DDD(DUK_DDDPRINT("YIELD NORMAL: value=%!T", (duk_tval *) duk_get_tval(thr, 0))); } #endif @@ -43978,17 +44869,17 @@ /* lj value1: value */ DUK_ASSERT(thr->valstack_bottom < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom0); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, &thr->heap->lj.value1, &thr->valstack_bottom0); /* side effects */ DUK_TVAL_CHKFAST_INPLACE_SLOW(&thr->heap->lj.value1); thr->heap->lj.iserror = is_error; - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ - duk_err_longjmp(thr); /* execution resumes in bytecode executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* call is from executor, so we know we have a jmpbuf */ + duk_err_longjmp(thr); /* execution resumes in bytecode executor */ DUK_UNREACHABLE(); /* Never here, fall through to error (from compiler point of view). */ - state_error: +state_error: DUK_DCERROR_TYPE_INVALID_STATE(thr); } #endif @@ -44068,7 +44959,7 @@ } DUK_INTERNAL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size) { - char buf64+1; + char buf64 + 1; duk_debug_format_funcptr(buf, sizeof(buf), fptr, fptr_size); bufsizeof(buf) - 1 = (char) 0; duk_fb_put_cstring(fb, buf); @@ -44078,7 +44969,7 @@ return (fb->offset >= fb->length); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ #line 1 "duk_debug_vsnprintf.c" /* * Custom formatter for debug printing, allowing Duktape specific data @@ -44145,58 +45036,58 @@ /* list of conversion specifiers that terminate a format tag; * this is unfortunately guesswork. */ -#define DUK__ALLOWED_STANDARD_SPECIFIERS "diouxXeEfFgGaAcsCSpnm" +#define DUK__ALLOWED_STANDARD_SPECIFIERS "diouxXeEfFgGaAcsCSpnm" /* maximum length of standard format tag that we support */ -#define DUK__MAX_FORMAT_TAG_LENGTH 32 +#define DUK__MAX_FORMAT_TAG_LENGTH 32 /* heapobj recursion depth when deep printing is selected */ -#define DUK__DEEP_DEPTH_LIMIT 8 +#define DUK__DEEP_DEPTH_LIMIT 8 /* maximum recursion depth for loop detection stacks */ -#define DUK__LOOP_STACK_DEPTH 256 +#define DUK__LOOP_STACK_DEPTH 256 /* must match bytecode defines now; build autogenerate? */ DUK_LOCAL const char * const duk__bc_optab256 = { - "LDREG", "STREG", "JUMP", "LDCONST", "LDINT", "LDINTX", "LDTHIS", "LDUNDEF", - "LDNULL", "LDTRUE", "LDFALSE", "GETVAR", "BNOT", "LNOT", "UNM", "UNP", - "EQ_RR", "EQ_CR", "EQ_RC", "EQ_CC", "NEQ_RR", "NEQ_CR", "NEQ_RC", "NEQ_CC", - "SEQ_RR", "SEQ_CR", "SEQ_RC", "SEQ_CC", "SNEQ_RR", "SNEQ_CR", "SNEQ_RC", "SNEQ_CC", - - "GT_RR", "GT_CR", "GT_RC", "GT_CC", "GE_RR", "GE_CR", "GE_RC", "GE_CC", - "LT_RR", "LT_CR", "LT_RC", "LT_CC", "LE_RR", "LE_CR", "LE_RC", "LE_CC", - "IFTRUE_R", "IFTRUE_C", "IFFALSE_R", "IFFALSE_C", "ADD_RR", "ADD_CR", "ADD_RC", "ADD_CC", - "SUB_RR", "SUB_CR", "SUB_RC", "SUB_CC", "MUL_RR", "MUL_CR", "MUL_RC", "MUL_CC", - - "DIV_RR", "DIV_CR", "DIV_RC", "DIV_CC", "MOD_RR", "MOD_CR", "MOD_RC", "MOD_CC", - "EXP_RR", "EXP_CR", "EXP_RC", "EXP_CC", "BAND_RR", "BAND_CR", "BAND_RC", "BAND_CC", - "BOR_RR", "BOR_CR", "BOR_RC", "BOR_CC", "BXOR_RR", "BXOR_CR", "BXOR_RC", "BXOR_CC", - "BASL_RR", "BASL_CR", "BASL_RC", "BASL_CC", "BLSR_RR", "BLSR_CR", "BLSR_RC", "BLSR_CC", - - "BASR_RR", "BASR_CR", "BASR_RC", "BASR_CC", "INSTOF_RR", "INSTOF_CR", "INSTOF_RC", "INSTOF_CC", - "IN_RR", "IN_CR", "IN_RC", "IN_CC", "GETPROP_RR", "GETPROP_CR", "GETPROP_RC", "GETPROP_CC", - "PUTPROP_RR", "PUTPROP_CR", "PUTPROP_RC", "PUTPROP_CC", "DELPROP_RR", "DELPROP_CR", "DELPROP_RC", "DELPROP_CC", - "PREINCR", "PREDECR", "POSTINCR", "POSTDECR", "PREINCV", "PREDECV", "POSTINCV", "POSTDECV", + "LDREG", "STREG", "JUMP", "LDCONST", "LDINT", "LDINTX", "LDTHIS", "LDUNDEF", + "LDNULL", "LDTRUE", "LDFALSE", "GETVAR", "BNOT", "LNOT", "UNM", "UNP", + "EQ_RR", "EQ_CR", "EQ_RC", "EQ_CC", "NEQ_RR", "NEQ_CR", "NEQ_RC", "NEQ_CC", + "SEQ_RR", "SEQ_CR", "SEQ_RC", "SEQ_CC", "SNEQ_RR", "SNEQ_CR", "SNEQ_RC", "SNEQ_CC", + + "GT_RR", "GT_CR", "GT_RC", "GT_CC", "GE_RR", "GE_CR", "GE_RC", "GE_CC", + "LT_RR", "LT_CR", "LT_RC", "LT_CC", "LE_RR", "LE_CR", "LE_RC", "LE_CC", + "IFTRUE_R", "IFTRUE_C", "IFFALSE_R", "IFFALSE_C", "ADD_RR", "ADD_CR", "ADD_RC", "ADD_CC", + "SUB_RR", "SUB_CR", "SUB_RC", "SUB_CC", "MUL_RR", "MUL_CR", "MUL_RC", "MUL_CC", + + "DIV_RR", "DIV_CR", "DIV_RC", "DIV_CC", "MOD_RR", "MOD_CR", "MOD_RC", "MOD_CC", + "EXP_RR", "EXP_CR", "EXP_RC", "EXP_CC", "BAND_RR", "BAND_CR", "BAND_RC", "BAND_CC", + "BOR_RR", "BOR_CR", "BOR_RC", "BOR_CC", "BXOR_RR", "BXOR_CR", "BXOR_RC", "BXOR_CC", + "BASL_RR", "BASL_CR", "BASL_RC", "BASL_CC", "BLSR_RR", "BLSR_CR", "BLSR_RC", "BLSR_CC", + + "BASR_RR", "BASR_CR", "BASR_RC", "BASR_CC", "INSTOF_RR", "INSTOF_CR", "INSTOF_RC", "INSTOF_CC", + "IN_RR", "IN_CR", "IN_RC", "IN_CC", "GETPROP_RR", "GETPROP_CR", "GETPROP_RC", "GETPROP_CC", + "PUTPROP_RR", "PUTPROP_CR", "PUTPROP_RC", "PUTPROP_CC", "DELPROP_RR", "DELPROP_CR", "DELPROP_RC", "DELPROP_CC", + "PREINCR", "PREDECR", "POSTINCR", "POSTDECR", "PREINCV", "PREDECV", "POSTINCV", "POSTDECV", - "PREINCP_RR", "PREINCP_CR", "PREINCP_RC", "PREINCP_CC", "PREDECP_RR", "PREDECP_CR", "PREDECP_RC", "PREDECP_CC", + "PREINCP_RR", "PREINCP_CR", "PREINCP_RC", "PREINCP_CC", "PREDECP_RR", "PREDECP_CR", "PREDECP_RC", "PREDECP_CC", "POSTINCP_RR", "POSTINCP_CR", "POSTINCP_RC", "POSTINCP_CC", "POSTDECP_RR", "POSTDECP_CR", "POSTDECP_RC", "POSTDECP_CC", - "DECLVAR_RR", "DECLVAR_CR", "DECLVAR_RC", "DECLVAR_CC", "REGEXP_RR", "REGEXP_RC", "REGEXP_CR", "REGEXP_CC", - "CLOSURE", "TYPEOF", "TYPEOFID", "PUTVAR", "DELVAR", "RETREG", "RETUNDEF", "RETCONST", + "DECLVAR_RR", "DECLVAR_CR", "DECLVAR_RC", "DECLVAR_CC", "REGEXP_RR", "REGEXP_RC", "REGEXP_CR", "REGEXP_CC", + "CLOSURE", "TYPEOF", "TYPEOFID", "PUTVAR", "DELVAR", "RETREG", "RETUNDEF", "RETCONST", - "RETCONSTN", "LABEL", "ENDLABEL", "BREAK", "CONTINUE", "TRYCATCH", "ENDTRY", "ENDCATCH", - "ENDFIN", "THROW", "INVLHS", "CSREG", "CSVAR_RR", "CSVAR_CR", "CSVAR_RC", "CSVAR_CC", - "CALL0", "CALL1", "CALL2", "CALL3", "CALL4", "CALL5", "CALL6", "CALL7", - "CALL8", "CALL9", "CALL10", "CALL11", "CALL12", "CALL13", "CALL14", "CALL15", - - "NEWOBJ", "NEWARR", "MPUTOBJ", "MPUTOBJI", "INITSET", "INITGET", "MPUTARR", "MPUTARRI", - "SETALEN", "INITENUM", "NEXTENUM", "NEWTARGET", "DEBUGGER", "NOP", "INVALID", "UNUSED207", - "GETPROPC_RR", "GETPROPC_CR", "GETPROPC_RC", "GETPROPC_CC", "UNUSED212", "UNUSED213", "UNUSED214", "UNUSED215", - "UNUSED216", "UNUSED217", "UNUSED218", "UNUSED219", "UNUSED220", "UNUSED221", "UNUSED222", "UNUSED223", - - "UNUSED224", "UNUSED225", "UNUSED226", "UNUSED227", "UNUSED228", "UNUSED229", "UNUSED230", "UNUSED231", - "UNUSED232", "UNUSED233", "UNUSED234", "UNUSED235", "UNUSED236", "UNUSED237", "UNUSED238", "UNUSED239", - "UNUSED240", "UNUSED241", "UNUSED242", "UNUSED243", "UNUSED244", "UNUSED245", "UNUSED246", "UNUSED247", - "UNUSED248", "UNUSED249", "UNUSED250", "UNUSED251", "UNUSED252", "UNUSED253", "UNUSED254", "UNUSED255" + "RETCONSTN", "LABEL", "ENDLABEL", "BREAK", "CONTINUE", "TRYCATCH", "ENDTRY", "ENDCATCH", + "ENDFIN", "THROW", "INVLHS", "CSREG", "CSVAR_RR", "CSVAR_CR", "CSVAR_RC", "CSVAR_CC", + "CALL0", "CALL1", "CALL2", "CALL3", "CALL4", "CALL5", "CALL6", "CALL7", + "CALL8", "CALL9", "CALL10", "CALL11", "CALL12", "CALL13", "CALL14", "CALL15", + + "NEWOBJ", "NEWARR", "MPUTOBJ", "MPUTOBJI", "INITSET", "INITGET", "MPUTARR", "MPUTARRI", + "SETALEN", "INITENUM", "NEXTENUM", "NEWTARGET", "DEBUGGER", "NOP", "INVALID", "UNUSED207", + "GETPROPC_RR", "GETPROPC_CR", "GETPROPC_RC", "GETPROPC_CC", "UNUSED212", "UNUSED213", "UNUSED214", "UNUSED215", + "UNUSED216", "UNUSED217", "UNUSED218", "UNUSED219", "UNUSED220", "UNUSED221", "UNUSED222", "UNUSED223", + + "UNUSED224", "UNUSED225", "UNUSED226", "UNUSED227", "UNUSED228", "UNUSED229", "UNUSED230", "UNUSED231", + "UNUSED232", "UNUSED233", "UNUSED234", "UNUSED235", "UNUSED236", "UNUSED237", "UNUSED238", "UNUSED239", + "UNUSED240", "UNUSED241", "UNUSED242", "UNUSED243", "UNUSED244", "UNUSED245", "UNUSED246", "UNUSED247", + "UNUSED248", "UNUSED249", "UNUSED250", "UNUSED251", "UNUSED252", "UNUSED253", "UNUSED254", "UNUSED255" }; typedef struct duk__dprint_state duk__dprint_state; @@ -44246,14 +45137,15 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*h); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)h)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) h)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } -#if defined(DUK_USE_REFERENCE_COUNTING) /* currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP */ +#if defined(DUK_USE_REFERENCE_COUNTING) /* currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP */ if (st->heavy) { - duk_fb_sprintf(fb, "h_next=%p,h_prev=%p,h_refcount=%lu,h_flags=%08lx,type=%ld," + duk_fb_sprintf(fb, + "h_next=%p,h_prev=%p,h_refcount=%lu,h_flags=%08lx,type=%ld," "reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (void *) DUK_HEAPHDR_GET_NEXT(NULL, h), (void *) DUK_HEAPHDR_GET_PREV(NULL, h), @@ -44267,7 +45159,8 @@ } #else if (st->heavy) { - duk_fb_sprintf(fb, "h_next=%p,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_next=%p,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (void *) DUK_HEAPHDR_GET_NEXT(NULL, h), (unsigned long) DUK_HEAPHDR_GET_FLAGS(h), (long) DUK_HEAPHDR_GET_TYPE(h), @@ -44294,14 +45187,15 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*h); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)h)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) h)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } #if defined(DUK_USE_REFERENCE_COUNTING) if (st->heavy) { - duk_fb_sprintf(fb, "h_refcount=%lu,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_refcount=%lu,h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h), (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h), (long) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h), @@ -44312,7 +45206,8 @@ } #else if (st->heavy) { - duk_fb_sprintf(fb, "h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", + duk_fb_sprintf(fb, + "h_flags=%08lx,type=%ld,reachable=%ld,temproot=%ld,finalizable=%ld,finalized=%ld", (unsigned long) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h), (long) DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h), (long) (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h) ? 1 : 0), @@ -44383,7 +45278,8 @@ #endif } -#define DUK__COMMA() do { \ +#define DUK__COMMA() \ + do { \ if (first) { \ first = 0; \ } else { \ @@ -44496,7 +45392,8 @@ duk__print_hstring(st, key, 0); duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_COLON); if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(NULL, h, i)) { - duk_fb_sprintf(fb, "get:%p,set:%p", + duk_fb_sprintf(fb, + "get:%p,set:%p", (void *) DUK_HOBJECT_E_GET_VALUE(NULL, h, i).a.get, (void *) DUK_HOBJECT_E_GET_VALUE(NULL, h, i).a.set); } else { @@ -44510,158 +45407,238 @@ } if (st->internal) { if (DUK_HOBJECT_IS_ARRAY(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__array:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__array:true"); } if (DUK_HOBJECT_HAS_EXTENSIBLE(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__extensible:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__extensible:true"); } if (DUK_HOBJECT_HAS_CONSTRUCTABLE(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__constructable:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__constructable:true"); } if (DUK_HOBJECT_HAS_BOUNDFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__boundfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__boundfunc:true"); } if (DUK_HOBJECT_HAS_COMPFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__compfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__compfunc:true"); } if (DUK_HOBJECT_HAS_NATFUNC(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__natfunc:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__natfunc:true"); } if (DUK_HOBJECT_HAS_BUFOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__bufobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__bufobj:true"); } if (DUK_HOBJECT_IS_THREAD(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__thread:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__thread:true"); } if (DUK_HOBJECT_HAS_ARRAY_PART(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__array_part:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__array_part:true"); } if (DUK_HOBJECT_HAS_STRICT(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__strict:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__strict:true"); } if (DUK_HOBJECT_HAS_NOTAIL(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__notail:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__notail:true"); } if (DUK_HOBJECT_HAS_NEWENV(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__newenv:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__newenv:true"); } if (DUK_HOBJECT_HAS_NAMEBINDING(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__namebinding:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__namebinding:true"); } if (DUK_HOBJECT_HAS_CREATEARGS(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__createargs:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__createargs:true"); } if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_array:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_array:true"); } if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_stringobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_stringobj:true"); } if (DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_arguments:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_arguments:true"); } if (DUK_HOBJECT_IS_BUFOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_bufobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_bufobj:true"); } if (DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h)) { - DUK__COMMA(); duk_fb_sprintf(fb, "__exotic_proxyobj:true"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__exotic_proxyobj:true"); } } if (st->internal && DUK_HOBJECT_IS_ARRAY(h)) { duk_harray *a = (duk_harray *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__length:%ld", (long) a->length); - DUK__COMMA(); duk_fb_sprintf(fb, "__length_nonwritable:%ld", (long) a->length_nonwritable); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length:%ld", (long) a->length); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length_nonwritable:%ld", (long) a->length_nonwritable); } else if (st->internal && DUK_HOBJECT_IS_COMPFUNC(h)) { duk_hcompfunc *f = (duk_hcompfunc *) h; - DUK__COMMA(); duk_fb_put_cstring(fb, "__data:"); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__data:"); duk__print_hbuffer(st, (duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA(NULL, f)); - DUK__COMMA(); duk_fb_put_cstring(fb, "__lexenv:"); duk__print_hobject(st, DUK_HCOMPFUNC_GET_LEXENV(NULL, f)); - DUK__COMMA(); duk_fb_put_cstring(fb, "__varenv:"); duk__print_hobject(st, DUK_HCOMPFUNC_GET_VARENV(NULL, f)); - DUK__COMMA(); duk_fb_sprintf(fb, "__nregs:%ld", (long) f->nregs); - DUK__COMMA(); duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__lexenv:"); + duk__print_hobject(st, DUK_HCOMPFUNC_GET_LEXENV(NULL, f)); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__varenv:"); + duk__print_hobject(st, DUK_HCOMPFUNC_GET_VARENV(NULL, f)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nregs:%ld", (long) f->nregs); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); #if defined(DUK_USE_DEBUGGER_SUPPORT) - DUK__COMMA(); duk_fb_sprintf(fb, "__start_line:%ld", (long) f->start_line); - DUK__COMMA(); duk_fb_sprintf(fb, "__end_line:%ld", (long) f->end_line); + DUK__COMMA(); + duk_fb_sprintf(fb, "__start_line:%ld", (long) f->start_line); + DUK__COMMA(); + duk_fb_sprintf(fb, "__end_line:%ld", (long) f->end_line); #endif - DUK__COMMA(); duk_fb_put_cstring(fb, "__data:"); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__data:"); duk__print_hbuffer(st, (duk_hbuffer *) DUK_HCOMPFUNC_GET_DATA(NULL, f)); } else if (st->internal && DUK_HOBJECT_IS_NATFUNC(h)) { duk_hnatfunc *f = (duk_hnatfunc *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__func:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__func:"); duk_fb_put_funcptr(fb, (duk_uint8_t *) &f->func, sizeof(f->func)); - DUK__COMMA(); duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); - DUK__COMMA(); duk_fb_sprintf(fb, "__magic:%ld", (long) f->magic); + DUK__COMMA(); + duk_fb_sprintf(fb, "__nargs:%ld", (long) f->nargs); + DUK__COMMA(); + duk_fb_sprintf(fb, "__magic:%ld", (long) f->magic); } else if (st->internal && DUK_HOBJECT_IS_DECENV(h)) { duk_hdecenv *e = (duk_hdecenv *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__thread:"); duk__print_hobject(st, (duk_hobject *) e->thread); - DUK__COMMA(); duk_fb_sprintf(fb, "__varmap:"); duk__print_hobject(st, (duk_hobject *) e->varmap); - DUK__COMMA(); duk_fb_sprintf(fb, "__regbase_byteoff:%ld", (long) e->regbase_byteoff); + DUK__COMMA(); + duk_fb_sprintf(fb, "__thread:"); + duk__print_hobject(st, (duk_hobject *) e->thread); + DUK__COMMA(); + duk_fb_sprintf(fb, "__varmap:"); + duk__print_hobject(st, (duk_hobject *) e->varmap); + DUK__COMMA(); + duk_fb_sprintf(fb, "__regbase_byteoff:%ld", (long) e->regbase_byteoff); } else if (st->internal && DUK_HOBJECT_IS_OBJENV(h)) { duk_hobjenv *e = (duk_hobjenv *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__target:"); duk__print_hobject(st, (duk_hobject *) e->target); - DUK__COMMA(); duk_fb_sprintf(fb, "__has_this:%ld", (long) e->has_this); + DUK__COMMA(); + duk_fb_sprintf(fb, "__target:"); + duk__print_hobject(st, (duk_hobject *) e->target); + DUK__COMMA(); + duk_fb_sprintf(fb, "__has_this:%ld", (long) e->has_this); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) } else if (st->internal && DUK_HOBJECT_IS_BUFOBJ(h)) { duk_hbufobj *b = (duk_hbufobj *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__buf:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__buf:"); duk__print_hbuffer(st, (duk_hbuffer *) b->buf); - DUK__COMMA(); duk_fb_sprintf(fb, "__buf_prop:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__buf_prop:"); duk__print_hobject(st, (duk_hobject *) b->buf_prop); - DUK__COMMA(); duk_fb_sprintf(fb, "__offset:%ld", (long) b->offset); - DUK__COMMA(); duk_fb_sprintf(fb, "__length:%ld", (long) b->length); - DUK__COMMA(); duk_fb_sprintf(fb, "__shift:%ld", (long) b->shift); - DUK__COMMA(); duk_fb_sprintf(fb, "__elemtype:%ld", (long) b->elem_type); + DUK__COMMA(); + duk_fb_sprintf(fb, "__offset:%ld", (long) b->offset); + DUK__COMMA(); + duk_fb_sprintf(fb, "__length:%ld", (long) b->length); + DUK__COMMA(); + duk_fb_sprintf(fb, "__shift:%ld", (long) b->shift); + DUK__COMMA(); + duk_fb_sprintf(fb, "__elemtype:%ld", (long) b->elem_type); #endif } else if (st->internal && DUK_HOBJECT_IS_PROXY(h)) { duk_hproxy *p = (duk_hproxy *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__target:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__target:"); duk__print_hobject(st, p->target); - DUK__COMMA(); duk_fb_sprintf(fb, "__handler:"); + DUK__COMMA(); + duk_fb_sprintf(fb, "__handler:"); duk__print_hobject(st, p->handler); } else if (st->internal && DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; - DUK__COMMA(); duk_fb_sprintf(fb, "__ptr_curr_pc:%p", (void *) t->ptr_curr_pc); - DUK__COMMA(); duk_fb_sprintf(fb, "__heap:%p", (void *) t->heap); - DUK__COMMA(); duk_fb_sprintf(fb, "__strict:%ld", (long) t->strict); - DUK__COMMA(); duk_fb_sprintf(fb, "__state:%ld", (long) t->state); - DUK__COMMA(); duk_fb_sprintf(fb, "__unused1:%ld", (long) t->unused1); - DUK__COMMA(); duk_fb_sprintf(fb, "__unused2:%ld", (long) t->unused2); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack:%p", (void *) t->valstack); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_end:%p/%ld", (void *) t->valstack_end, (long) (t->valstack_end - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_alloc_end:%p/%ld", (void *) t->valstack_alloc_end, (long) (t->valstack_alloc_end - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_bottom:%p/%ld", (void *) t->valstack_bottom, (long) (t->valstack_bottom - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__valstack_top:%p/%ld", (void *) t->valstack_top, (long) (t->valstack_top - t->valstack)); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_curr:%p", (void *) t->callstack_curr); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_top:%ld", (long) t->callstack_top); - DUK__COMMA(); duk_fb_sprintf(fb, "__callstack_preventcount:%ld", (long) t->callstack_preventcount); - DUK__COMMA(); duk_fb_sprintf(fb, "__resumer:"); duk__print_hobject(st, (duk_hobject *) t->resumer); - DUK__COMMA(); duk_fb_sprintf(fb, "__compile_ctx:%p", (void *) t->compile_ctx); + DUK__COMMA(); + duk_fb_sprintf(fb, "__ptr_curr_pc:%p", (void *) t->ptr_curr_pc); + DUK__COMMA(); + duk_fb_sprintf(fb, "__heap:%p", (void *) t->heap); + DUK__COMMA(); + duk_fb_sprintf(fb, "__strict:%ld", (long) t->strict); + DUK__COMMA(); + duk_fb_sprintf(fb, "__state:%ld", (long) t->state); + DUK__COMMA(); + duk_fb_sprintf(fb, "__unused1:%ld", (long) t->unused1); + DUK__COMMA(); + duk_fb_sprintf(fb, "__unused2:%ld", (long) t->unused2); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack:%p", (void *) t->valstack); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack_end:%p/%ld", (void *) t->valstack_end, (long) (t->valstack_end - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, + "__valstack_alloc_end:%p/%ld", + (void *) t->valstack_alloc_end, + (long) (t->valstack_alloc_end - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, + "__valstack_bottom:%p/%ld", + (void *) t->valstack_bottom, + (long) (t->valstack_bottom - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__valstack_top:%p/%ld", (void *) t->valstack_top, (long) (t->valstack_top - t->valstack)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_curr:%p", (void *) t->callstack_curr); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_top:%ld", (long) t->callstack_top); + DUK__COMMA(); + duk_fb_sprintf(fb, "__callstack_preventcount:%ld", (long) t->callstack_preventcount); + DUK__COMMA(); + duk_fb_sprintf(fb, "__resumer:"); + duk__print_hobject(st, (duk_hobject *) t->resumer); + DUK__COMMA(); + duk_fb_sprintf(fb, "__compile_ctx:%p", (void *) t->compile_ctx); #if defined(DUK_USE_INTERRUPT_COUNTER) - DUK__COMMA(); duk_fb_sprintf(fb, "__interrupt_counter:%ld", (long) t->interrupt_counter); - DUK__COMMA(); duk_fb_sprintf(fb, "__interrupt_init:%ld", (long) t->interrupt_init); + DUK__COMMA(); + duk_fb_sprintf(fb, "__interrupt_counter:%ld", (long) t->interrupt_counter); + DUK__COMMA(); + duk_fb_sprintf(fb, "__interrupt_init:%ld", (long) t->interrupt_init); #endif /* XXX: print built-ins array? */ - } #if defined(DUK_USE_REFERENCE_COUNTING) if (st->internal) { - DUK__COMMA(); duk_fb_sprintf(fb, "__refcount:%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__refcount:%lu", (unsigned long) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h)); } #endif if (st->internal) { - DUK__COMMA(); duk_fb_sprintf(fb, "__class:%ld", (long) DUK_HOBJECT_GET_CLASS_NUMBER(h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__class:%ld", (long) DUK_HOBJECT_GET_CLASS_NUMBER(h)); } - DUK__COMMA(); duk_fb_sprintf(fb, "__heapptr:%p", (void *) h); /* own pointer */ + DUK__COMMA(); + duk_fb_sprintf(fb, "__heapptr:%p", (void *) h); /* own pointer */ /* prototype should be last, for readability */ if (DUK_HOBJECT_GET_PROTOTYPE(NULL, h)) { if (st->follow_proto) { - DUK__COMMA(); duk_fb_put_cstring(fb, "__prototype:"); duk__print_hobject(st, DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); + DUK__COMMA(); + duk_fb_put_cstring(fb, "__prototype:"); + duk__print_hobject(st, DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); } else { - DUK__COMMA(); duk_fb_sprintf(fb, "__prototype:%p", (void *) DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); + DUK__COMMA(); + duk_fb_sprintf(fb, "__prototype:%p", (void *) DUK_HOBJECT_GET_PROTOTYPE(NULL, h)); } } @@ -44687,7 +45664,7 @@ } #endif - finished: +finished: st->depth--; if (pushed_loopstack) { st->loop_stack_index--; @@ -44714,12 +45691,14 @@ if (DUK_HBUFFER_HAS_DYNAMIC(h)) { if (DUK_HBUFFER_HAS_EXTERNAL(h)) { duk_hbuffer_external *g = (duk_hbuffer_external *) h; - duk_fb_sprintf(fb, "buffer:external:%p:%ld", + duk_fb_sprintf(fb, + "buffer:external:%p:%ld", (void *) DUK_HBUFFER_EXTERNAL_GET_DATA_PTR(NULL, g), (long) DUK_HBUFFER_EXTERNAL_GET_SIZE(g)); } else { duk_hbuffer_dynamic *g = (duk_hbuffer_dynamic *) h; - duk_fb_sprintf(fb, "buffer:dynamic:%p:%ld", + duk_fb_sprintf(fb, + "buffer:dynamic:%p:%ld", (void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(NULL, g), (long) DUK_HBUFFER_DYNAMIC_GET_SIZE(g)); } @@ -44792,7 +45771,7 @@ duk_size_t i; duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_LBRACKET); for (i = 0; i < (duk_size_t) sizeof(*tv); i++) { - duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *)tv)i); + duk_fb_sprintf(fb, "%02lx", (unsigned long) ((duk_uint8_t *) tv)i); } duk_fb_put_byte(fb, (duk_uint8_t) DUK_ASC_RBRACKET); } @@ -44875,17 +45854,22 @@ /* XXX: option to fix opcode length so it lines up nicely */ if (op == DUK_OP_JUMP) { - duk_int_t diff1 = (duk_int_t) (DUK_DEC_ABC(ins) - DUK_BC_JUMP_BIAS); /* from next pc */ - duk_int_t diff2 = diff1 + 1; /* from curr pc */ + duk_int_t diff1 = (duk_int_t) (DUK_DEC_ABC(ins) - DUK_BC_JUMP_BIAS); /* from next pc */ + duk_int_t diff2 = diff1 + 1; /* from curr pc */ - duk_fb_sprintf(fb, "%s %ld (to pc%c%ld)", - (const char *) op_name, (long) diff1, - (int) (diff2 >= 0 ? '+' : '-'), /* char format: use int */ + duk_fb_sprintf(fb, + "%s %ld (to pc%c%ld)", + (const char *) op_name, + (long) diff1, + (int) (diff2 >= 0 ? '+' : '-'), /* char format: use int */ (long) (diff2 >= 0 ? diff2 : -diff2)); } else { - duk_fb_sprintf(fb, "%s %ld, %ld, %ld", - (const char *) op_name, (long) DUK_DEC_A(ins), - (long) DUK_DEC_B(ins), (long) DUK_DEC_C(ins)); + duk_fb_sprintf(fb, + "%s %ld, %ld, %ld", + (const char *) op_name, + (long) DUK_DEC_A(ins), + (long) DUK_DEC_B(ins), + (long) DUK_DEC_C(ins)); } } @@ -44911,13 +45895,16 @@ return; } - duk_fb_sprintf(fb, "catcher ptr=%p parent=%p varname=%p pc_base=%p, idx_base=%ld, flags=0x%08lx", + duk_fb_sprintf(fb, + "catcher ptr=%p parent=%p varname=%p pc_base=%p, idx_base=%ld, flags=0x%08lx", (void *) cat, - (void *) cat->parent, (void *) cat->h_varname, (void *) cat->pc_base, - (long) cat->idx_base, (unsigned long) cat->flags); + (void *) cat->parent, + (void *) cat->h_varname, + (void *) cat->pc_base, + (long) cat->idx_base, + (unsigned long) cat->flags); } - DUK_LOCAL void duk__print_activation(duk__dprint_state *st, duk_activation *act) { duk_fixedbuffer *fb = st->fb; @@ -44932,12 +45919,20 @@ /* prev_caller: conditional, omitted on purpose, it's rarely used. */ /* prev_line: conditional, omitted on purpose (but would be nice). */ - duk_fb_sprintf(fb, "activation ptr=%p tv_func=<omit> func=%p parent=%p var_env=%p lex_env=%p cat=%p curr_pc=%p bottom_byteoff=%ld retval_byteoff=%ld reserve_byteoff=%ld flags=%ld", + duk_fb_sprintf(fb, + "activation ptr=%p tv_func=<omit> func=%p parent=%p var_env=%p lex_env=%p cat=%p curr_pc=%p " + "bottom_byteoff=%ld retval_byteoff=%ld reserve_byteoff=%ld flags=%ld", (void *) act, - (void *) act->func, (void *) act->parent, (void *) act->var_env, - (void *) act->lex_env, (void *) act->cat, (void *) act->curr_pc, - (long) act->bottom_byteoff, (long) act->retval_byteoff, (long) act->reserve_byteoff, - (long) act->flags); + (void *) act->func, + (void *) act->parent, + (void *) act->var_env, + (void *) act->lex_env, + (void *) act->cat, + (void *) act->curr_pc, + (long) act->bottom_byteoff, + (long) act->retval_byteoff, + (long) act->reserve_byteoff, + (long) act->flags); } DUK_INTERNAL duk_int_t duk_debug_vsnprintf(char *str, duk_size_t size, const char *format, va_list ap) { @@ -44956,7 +45951,7 @@ char ch = *p++; const char *p_begfmt = NULL; duk_bool_t got_exclamation = 0; - duk_bool_t got_long = 0; /* %lf, %ld etc */ + duk_bool_t got_long = 0; /* %lf, %ld etc */ duk__dprint_state st; if (ch != DUK_ASC_PERCENT) { @@ -45119,11 +46114,11 @@ } goto done; - format_error: +format_error: duk_fb_put_cstring(&fb, "FMTERR"); /* fall through */ - done: +done: retval = (duk_int_t) fb.offset; duk_fb_put_byte(&fb, (duk_uint8_t) 0); @@ -45131,7 +46126,7 @@ return retval; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_int_t duk_debug_snprintf(char *str, duk_size_t size, const char *format, ...) { duk_int_t retval; va_list ap; @@ -45172,7 +46167,7 @@ } } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* automatic undefs */ #undef DUK__ALLOWED_STANDARD_SPECIFIERS @@ -45194,17 +46189,23 @@ */ #if defined(DUK_USE_ASSERTIONS) -#define DUK__DBG_TPORT_ENTER() do { \ +#define DUK__DBG_TPORT_ENTER() \ + do { \ DUK_ASSERT(heap->dbg_calling_transport == 0); \ heap->dbg_calling_transport = 1; \ } while (0) -#define DUK__DBG_TPORT_EXIT() do { \ +#define DUK__DBG_TPORT_EXIT() \ + do { \ DUK_ASSERT(heap->dbg_calling_transport == 1); \ heap->dbg_calling_transport = 0; \ } while (0) #else -#define DUK__DBG_TPORT_ENTER() do {} while (0) -#define DUK__DBG_TPORT_EXIT() do {} while (0) +#define DUK__DBG_TPORT_ENTER() \ + do { \ + } while (0) +#define DUK__DBG_TPORT_EXIT() \ + do { \ + } while (0) #endif /* @@ -45224,7 +46225,8 @@ * Detach handling */ -#define DUK__SET_CONN_BROKEN(thr,reason) do { \ +#define DUK__SET_CONN_BROKEN(thr, reason) \ + do { \ /* For now shared handler is fine. */ \ duk__debug_do_detach1((thr)->heap, (reason)); \ } while (0) @@ -45245,7 +46247,7 @@ DUK_D(DUK_DPRINT("debugger transport detaching, marking transport broken")); - heap->dbg_detaching = 1; /* prevent multiple in-progress detaches */ + heap->dbg_detaching = 1; /* prevent multiple in-progress detaches */ if (heap->dbg_write_cb != NULL) { duk_hthread *thr; @@ -45273,8 +46275,8 @@ heap->dbg_pause_act = NULL; heap->dbg_pause_startline = 0; heap->dbg_have_next_byte = 0; - duk_debug_clear_paused(heap); /* XXX: some overlap with field inits above */ - heap->dbg_state_dirty = 0; /* XXX: clear_paused sets dirty; rework? */ + duk_debug_clear_paused(heap); /* XXX: some overlap with field inits above */ + heap->dbg_state_dirty = 0; /* XXX: clear_paused sets dirty; rework? */ /* Ensure there are no stale active breakpoint pointers. * Breakpoint list is currently kept - we could empty it @@ -45334,7 +46336,7 @@ heap = thr->heap; DUK_D(DUK_DPRINT("transport read/write error, NULL all callbacks expected detached")); heap->dbg_read_cb = NULL; - heap->dbg_write_cb = NULL; /* this is especially critical to avoid another write call in detach1() */ + heap->dbg_write_cb = NULL; /* this is especially critical to avoid another write call in detach1() */ heap->dbg_peek_cb = NULL; heap->dbg_read_flush_cb = NULL; heap->dbg_write_flush_cb = NULL; @@ -45356,7 +46358,8 @@ updated_flags = pause_flags & ~(DUK_PAUSE_FLAG_LINE_CHANGE); DUK_D(DUK_DPRINT("no line info for current activation, disable line-based pause flags: 0x%08lx -> 0x%08lx", - (long) pause_flags, (long) updated_flags)); + (long) pause_flags, + (long) updated_flags)); pause_flags = updated_flags; } @@ -45366,7 +46369,8 @@ heap->dbg_state_dirty = 1; DUK_D(DUK_DPRINT("set state for automatic pause triggers, flags=0x%08lx, act=%p, startline=%ld", - (long) heap->dbg_pause_flags, (void *) heap->dbg_pause_act, + (long) heap->dbg_pause_flags, + (void *) heap->dbg_pause_act, (long) heap->dbg_pause_startline)); } @@ -45521,7 +46525,7 @@ if (got == 0 || got > left) { DUK_D(DUK_DPRINT("connection error during read, return zero data")); - duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ + duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ DUK__SET_CONN_BROKEN(thr, 1); goto fail; } @@ -45529,14 +46533,14 @@ } return; - fail: +fail: duk_memzero((void *) data, (size_t) length); } DUK_INTERNAL duk_uint8_t duk_debug_read_byte(duk_hthread *thr) { duk_uint8_t x; - x = 0; /* just in case callback is broken and won't write 'x' */ + x = 0; /* just in case callback is broken and won't write 'x' */ duk_debug_read_bytes(thr, &x, 1); return x; } @@ -45547,10 +46551,7 @@ DUK_ASSERT(thr != NULL); duk_debug_read_bytes(thr, buf, 4); - return ((duk_uint32_t) buf0 << 24) | - ((duk_uint32_t) buf1 << 16) | - ((duk_uint32_t) buf2 << 8) | - (duk_uint32_t) buf3; + return ((duk_uint32_t) buf0 << 24) | ((duk_uint32_t) buf1 << 16) | ((duk_uint32_t) buf2 << 8) | (duk_uint32_t) buf3; } DUK_LOCAL duk_int32_t duk__debug_read_int32_raw(duk_hthread *thr) { @@ -45563,8 +46564,7 @@ DUK_ASSERT(thr != NULL); duk_debug_read_bytes(thr, buf, 2); - return ((duk_uint16_t) buf0 << 8) | - (duk_uint16_t) buf1; + return ((duk_uint16_t) buf0 << 8) | (duk_uint16_t) buf1; } DUK_INTERNAL duk_int32_t duk_debug_read_int(duk_hthread *thr) { @@ -45596,10 +46596,10 @@ duk_debug_read_bytes(thr, buf, (duk_size_t) len); duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); } else { - p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ + p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ DUK_ASSERT(p != NULL); duk_debug_read_bytes(thr, p, (duk_size_t) len); - (void) duk_buffer_to_string(thr, -1); /* Safety relies on debug client, which is OK. */ + (void) duk_buffer_to_string(thr, -1); /* Safety relies on debug client, which is OK. */ } return duk_require_hstring(thr, -1); @@ -45625,17 +46625,17 @@ return duk__debug_read_hstring_raw(thr, len); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode int")); DUK__SET_CONN_BROKEN(thr, 1); - duk_push_hstring_empty(thr); /* always push some string */ + duk_push_hstring_empty(thr); /* always push some string */ return duk_require_hstring(thr, -1); } DUK_LOCAL duk_hbuffer *duk__debug_read_hbuffer_raw(duk_hthread *thr, duk_uint32_t len) { duk_uint8_t *p; - p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ + p = (duk_uint8_t *) duk_push_fixed_buffer(thr, (duk_size_t) len); /* zero for paranoia */ DUK_ASSERT(p != NULL); duk_debug_read_bytes(thr, p, (duk_size_t) len); @@ -45658,7 +46658,7 @@ #endif return (void *) pu.p; - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode pointer")); DUK__SET_CONN_BROKEN(thr, 1); return (void *) NULL; @@ -45716,7 +46716,7 @@ return (duk_heaphdr *) duk__debug_read_pointer_raw(thr); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode any pointer (object, pointer, heapptr)")); DUK__SET_CONN_BROKEN(thr, 1); return NULL; @@ -45822,15 +46822,15 @@ duk_push_heapptr(thr, (void *) h); break; } - case DUK_DBG_IB_UNUSED: /* unused: not accepted in inbound messages */ + case DUK_DBG_IB_UNUSED: /* unused: not accepted in inbound messages */ default: goto fail; } - return_ptr: +return_ptr: return DUK_GET_TVAL_NEGIDX(thr, -1); - fail: +fail: DUK_D(DUK_DPRINT("debug connection error: failed to decode tval")); DUK__SET_CONN_BROKEN(thr, 1); return NULL; @@ -45880,7 +46880,7 @@ DUK__DBG_TPORT_EXIT(); if (got == 0 || got > left) { - duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ + duk__debug_null_most_callbacks(thr); /* avoid calling write callback in detach1() */ DUK_D(DUK_DPRINT("connection error during write")); DUK__SET_CONN_BROKEN(thr, 1); return; @@ -45947,8 +46947,7 @@ * unsigned 32-bit dvalue. */ if (x >= 0x80000000UL) { - DUK_D(DUK_DPRINT("writing unsigned integer 0x%08lx as signed integer", - (long) x)); + DUK_D(DUK_DPRINT("writing unsigned integer 0x%08lx as signed integer", (long) x)); } duk_debug_write_int(thr, (duk_int32_t) x); } @@ -45989,9 +46988,7 @@ DUK_INTERNAL void duk_debug_write_cstring(duk_hthread *thr, const char *data) { DUK_ASSERT(thr != NULL); - duk_debug_write_string(thr, - data, - data ? DUK_STRLEN(data) : 0); + duk_debug_write_string(thr, data, data ? DUK_STRLEN(data) : 0); } DUK_INTERNAL void duk_debug_write_hstring(duk_hthread *thr, duk_hstring *h) { @@ -46045,7 +47042,7 @@ DUK_INTERNAL void duk_debug_write_heapptr(duk_hthread *thr, duk_heaphdr *h) { duk__debug_write_pointer_raw(thr, (void *) h, DUK_DBG_IB_HEAPPTR); } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT */ DUK_INTERNAL void duk_debug_write_hobject(duk_hthread *thr, duk_hobject *obj) { duk_uint8_t buf3; @@ -46088,8 +47085,7 @@ duk_debug_write_byte(thr, DUK_DBG_IB_NULL); break; case DUK_TAG_BOOLEAN: - DUK_ASSERT(DUK_TVAL_GET_BOOLEAN(tv) == 0 || - DUK_TVAL_GET_BOOLEAN(tv) == 1); + DUK_ASSERT(DUK_TVAL_GET_BOOLEAN(tv) == 0 || DUK_TVAL_GET_BOOLEAN(tv) == 1); duk_debug_write_boolean(thr, DUK_TVAL_GET_BOOLEAN(tv)); break; case DUK_TAG_POINTER: @@ -46134,14 +47130,22 @@ DUK_DD(DUK_DDPRINT("i32=%ld du1=%02x%02x%02x%02x%02x%02x%02x%02x " "du2=%02x%02x%02x%02x%02x%02x%02x%02x", (long) i32, - (unsigned int) du1.uc0, (unsigned int) du1.uc1, - (unsigned int) du1.uc2, (unsigned int) du1.uc3, - (unsigned int) du1.uc4, (unsigned int) du1.uc5, - (unsigned int) du1.uc6, (unsigned int) du1.uc7, - (unsigned int) du2.uc0, (unsigned int) du2.uc1, - (unsigned int) du2.uc2, (unsigned int) du2.uc3, - (unsigned int) du2.uc4, (unsigned int) du2.uc5, - (unsigned int) du2.uc6, (unsigned int) du2.uc7)); + (unsigned int) du1.uc0, + (unsigned int) du1.uc1, + (unsigned int) du1.uc2, + (unsigned int) du1.uc3, + (unsigned int) du1.uc4, + (unsigned int) du1.uc5, + (unsigned int) du1.uc6, + (unsigned int) du1.uc7, + (unsigned int) du2.uc0, + (unsigned int) du2.uc1, + (unsigned int) du2.uc2, + (unsigned int) du2.uc3, + (unsigned int) du2.uc4, + (unsigned int) du2.uc5, + (unsigned int) du2.uc6, + (unsigned int) du2.uc7)); if (duk_memcmp((const void *) du1.uc, (const void *) du2.uc, sizeof(du1.uc)) == 0) { duk_debug_write_int(thr, i32); @@ -46165,13 +47169,13 @@ duk_debug_write_tval(thr, tv); } } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ /* * Debug connection message write helpers */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL void duk_debug_write_request(duk_hthread *thr, duk_small_uint_t command) { duk_debug_write_byte(thr, DUK_DBG_IB_REQUEST); duk_debug_write_int(thr, command); @@ -46274,7 +47278,7 @@ duk_activation *act; duk_uint32_t pc; - DUK_ASSERT(thr->valstack_top > thr->valstack); /* At least: ... err */ + DUK_ASSERT(thr->valstack_top > thr->valstack); /* At least: ... err */ duk_debug_write_notify(thr, DUK_DBG_CMD_THROW); duk_debug_write_int(thr, (duk_int32_t) fatal); @@ -46315,7 +47319,7 @@ duk_debug_write_eom(thr); } -#endif /* DUK_USE_DEBUGGER_THROW_NOTIFY */ +#endif /* DUK_USE_DEBUGGER_THROW_NOTIFY */ /* * Debug message processing @@ -46339,9 +47343,9 @@ duk_debug_skip_bytes(thr, (duk_size_t) (x - 0x60)); return 0; } - switch(x) { + switch (x) { case DUK_DBG_IB_EOM: - return 1; /* Return 1: got EOM */ + return 1; /* Return 1: got EOM */ case DUK_DBG_IB_REQUEST: case DUK_DBG_IB_REPLY: case DUK_DBG_IB_ERROR: @@ -46390,9 +47394,9 @@ return 0; - fail: +fail: DUK__SET_CONN_BROKEN(thr, 1); - return 1; /* Pretend like we got EOM */ + return 1; /* Pretend like we got EOM */ } /* Skip dvalues to EOM. */ @@ -46412,7 +47416,7 @@ level = duk_debug_read_int(thr); if (level >= 0 || -level > (duk_int32_t) thr->callstack_top) { duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack index"); - return 0; /* zero indicates failure */ + return 0; /* zero indicates failure */ } return level; } @@ -46481,7 +47485,7 @@ duk_debug_clear_paused(heap); pause_flags = 0; -#if 0 /* manual testing */ +#if 0 /* manual testing */ pause_flags |= DUK_PAUSE_FLAG_ONE_OPCODE; pause_flags |= DUK_PAUSE_FLAG_CAUGHT_ERROR; pause_flags |= DUK_PAUSE_FLAG_UNCAUGHT_ERROR; @@ -46502,12 +47506,9 @@ DUK_D(DUK_DPRINT("debug command StepInto/StepOver/StepOut: %d", (int) cmd)); if (cmd == DUK_DBG_CMD_STEPINTO) { - pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | - DUK_PAUSE_FLAG_FUNC_ENTRY | - DUK_PAUSE_FLAG_FUNC_EXIT; + pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | DUK_PAUSE_FLAG_FUNC_ENTRY | DUK_PAUSE_FLAG_FUNC_EXIT; } else if (cmd == DUK_DBG_CMD_STEPOVER) { - pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | - DUK_PAUSE_FLAG_FUNC_EXIT; + pause_flags = DUK_PAUSE_FLAG_LINE_CHANGE | DUK_PAUSE_FLAG_FUNC_EXIT; } else { DUK_ASSERT(cmd == DUK_DBG_CMD_STEPOUT); pause_flags = DUK_PAUSE_FLAG_FUNC_EXIT; @@ -46586,7 +47587,7 @@ if (act == NULL) { return; } - str = duk_debug_read_hstring(thr); /* push to stack */ + str = duk_debug_read_hstring(thr); /* push to stack */ DUK_ASSERT(str != NULL); rc = duk_js_getvar_activation(thr, act, str, 0); @@ -46615,7 +47616,7 @@ if (act == NULL) { return; } - str = duk_debug_read_hstring(thr); /* push to stack */ + str = duk_debug_read_hstring(thr); /* push to stack */ DUK_ASSERT(str != NULL); tv = duk_debug_read_tval(thr); if (tv == NULL) { @@ -46713,7 +47714,7 @@ /* ... func varmap enum key value this */ duk_debug_write_hstring(thr, duk_get_hstring(thr, -3)); duk_debug_write_tval(thr, duk_get_tval(thr, -2)); - duk_pop_3(thr); /* -> ... func varmap enum */ + duk_pop_3(thr); /* -> ... func varmap enum */ } } else { DUK_D(DUK_DPRINT("varmap missing in GetLocals, ignore")); @@ -46748,12 +47749,12 @@ /* nargs == 2 so we can pass a callstack index to eval(). */ idx_func = duk_get_top(thr); duk_push_c_function(thr, duk_bi_global_object_eval, 2 /*nargs*/); - duk_push_undefined(thr); /* 'this' binding shouldn't matter here */ + duk_push_undefined(thr); /* 'this' binding shouldn't matter here */ /* Read callstack index, if non-null. */ if (duk_debug_peek_byte(thr) == DUK_DBG_IB_NULL) { direct_eval = 0; - level = -1; /* Not needed, but silences warning. */ + level = -1; /* Not needed, but silences warning. */ (void) duk_debug_read_byte(thr); } else { direct_eval = 1; @@ -46763,12 +47764,11 @@ } } - DUK_ASSERT(!direct_eval || - (level < 0 && -level <= (duk_int32_t) thr->callstack_top)); + DUK_ASSERT(!direct_eval || (level < 0 && -level <= (duk_int32_t) thr->callstack_top)); (void) duk_debug_read_hstring(thr); if (direct_eval) { - duk_push_int(thr, level - 1); /* compensate for eval() call */ + duk_push_int(thr, level - 1); /* compensate for eval() call */ } /* ... eval "eval" eval_input level? */ @@ -46823,7 +47823,7 @@ duk_debug_write_eom(thr); DUK_D(DUK_DPRINT("debug connection detached, mark broken")); - DUK__SET_CONN_BROKEN(thr, 0); /* not an error */ + DUK__SET_CONN_BROKEN(thr, 0); /* not an error */ } DUK_LOCAL void duk__debug_handle_apprequest(duk_hthread *thr, duk_heap *heap) { @@ -46831,7 +47831,7 @@ DUK_D(DUK_DPRINT("debug command AppRequest")); - old_top = duk_get_top(thr); /* save stack top */ + old_top = duk_get_top(thr); /* save stack top */ if (heap->dbg_request_cb != NULL) { duk_idx_t nrets; @@ -46847,7 +47847,7 @@ DUK_D(DUK_DPRINT("failed to allocate space for request dvalue(s)")); goto fail; } - tv = duk_debug_read_tval(thr); /* push to stack */ + tv = duk_debug_read_tval(thr); /* push to stack */ if (tv == NULL) { /* detached */ return; @@ -46858,17 +47858,24 @@ /* Request callback should push values for reply to client onto valstack */ DUK_D(DUK_DPRINT("calling into AppRequest request_cb with nvalues=%ld, old_top=%ld, top=%ld", - (long) nvalues, (long) old_top, (long) duk_get_top(thr))); + (long) nvalues, + (long) old_top, + (long) duk_get_top(thr))); nrets = heap->dbg_request_cb(thr, heap->dbg_udata, nvalues); DUK_D(DUK_DPRINT("returned from AppRequest request_cb; nvalues=%ld -> nrets=%ld, old_top=%ld, top=%ld", - (long) nvalues, (long) nrets, (long) old_top, (long) duk_get_top(thr))); + (long) nvalues, + (long) nrets, + (long) old_top, + (long) duk_get_top(thr))); if (nrets >= 0) { DUK_ASSERT(duk_get_top(thr) >= old_top + nrets); if (duk_get_top(thr) < old_top + nrets) { DUK_D(DUK_DPRINT("AppRequest callback doesn't match value stack configuration, " "top=%ld < old_top=%ld + nrets=%ld; " "this might mean it's unsafe to continue!", - (long) duk_get_top(thr), (long) old_top, (long) nrets)); + (long) duk_get_top(thr), + (long) old_top, + (long) nrets)); goto fail; } @@ -46888,7 +47895,7 @@ duk_debug_write_error_eom(thr, DUK_DBG_ERR_APPLICATION, duk_get_string(thr, -1)); } - duk_set_top(thr, old_top); /* restore stack top */ + duk_set_top(thr, old_top); /* restore stack top */ } else { DUK_D(DUK_DPRINT("no request callback, treat AppRequest as unsupported")); duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNSUPPORTED, "AppRequest unsupported by target"); @@ -46896,8 +47903,8 @@ return; - fail: - duk_set_top(thr, old_top); /* restore stack top */ +fail: + duk_set_top(thr, old_top); /* restore stack top */ DUK__SET_CONN_BROKEN(thr, 1); } @@ -46948,16 +47955,16 @@ k = DUK_HOBJECT_E_GET_KEY(heap, h, i); duk_debug_write_heapptr(thr, (duk_heaphdr *) k); if (k == NULL) { - duk_debug_write_int(thr, 0); /* isAccessor */ + duk_debug_write_int(thr, 0); /* isAccessor */ duk_debug_write_unused(thr); continue; } if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap, h, i)) { - duk_debug_write_int(thr, 1); /* isAccessor */ + duk_debug_write_int(thr, 1); /* isAccessor */ duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->a.get); duk_debug_write_heapptr(thr, (duk_heaphdr *) DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->a.set); } else { - duk_debug_write_int(thr, 0); /* isAccessor */ + duk_debug_write_int(thr, 0); /* isAccessor */ duk__debug_write_tval_heapptr(thr, &DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)->v); } @@ -47019,7 +48026,7 @@ duk__debug_dump_strtab(thr, heap); duk_debug_write_eom(thr); } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ DUK_LOCAL void duk__debug_handle_get_bytecode(duk_hthread *thr, duk_heap *heap) { duk_activation *act; @@ -47088,11 +48095,11 @@ duk_debug_write_eom(thr); return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid argument"); return; - fail_index: +fail_index: duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack index"); return; } @@ -47144,53 +48151,22 @@ DUK_HSTRING_FLAG_EVAL_OR_ARGUMENTS, #endif DUK_HSTRING_FLAG_EXTDATA, - 0 /* terminator */ + 0 /* terminator */ }; DUK_LOCAL const char * const duk__debug_getinfo_hobject_keys = { - "extensible", - "constructable", - "callable", - "boundfunc", - "compfunc", - "natfunc", - "bufobj", - "fastrefs", - "array_part", - "strict", - "notail", - "newenv", - "namebinding", - "createargs", - "have_finalizer", - "exotic_array", - "exotic_stringobj", - "exotic_arguments", - "exotic_proxyobj", - "special_call" + "extensible", "constructable", "callable", "boundfunc", "compfunc", "natfunc", "bufobj", + "fastrefs", "array_part", "strict", "notail", "newenv", "namebinding", "createargs", + "have_finalizer", "exotic_array", "exotic_stringobj", "exotic_arguments", "exotic_proxyobj", "special_call" /* NULL not needed here */ }; DUK_LOCAL duk_uint_t duk__debug_getinfo_hobject_masks = { - DUK_HOBJECT_FLAG_EXTENSIBLE, - DUK_HOBJECT_FLAG_CONSTRUCTABLE, - DUK_HOBJECT_FLAG_CALLABLE, - DUK_HOBJECT_FLAG_BOUNDFUNC, - DUK_HOBJECT_FLAG_COMPFUNC, - DUK_HOBJECT_FLAG_NATFUNC, - DUK_HOBJECT_FLAG_BUFOBJ, - DUK_HOBJECT_FLAG_FASTREFS, - DUK_HOBJECT_FLAG_ARRAY_PART, - DUK_HOBJECT_FLAG_STRICT, - DUK_HOBJECT_FLAG_NOTAIL, - DUK_HOBJECT_FLAG_NEWENV, - DUK_HOBJECT_FLAG_NAMEBINDING, - DUK_HOBJECT_FLAG_CREATEARGS, - DUK_HOBJECT_FLAG_HAVE_FINALIZER, - DUK_HOBJECT_FLAG_EXOTIC_ARRAY, - DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ, - DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS, - DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ, - DUK_HOBJECT_FLAG_SPECIAL_CALL, - 0 /* terminator */ + DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_HOBJECT_FLAG_CONSTRUCTABLE, DUK_HOBJECT_FLAG_CALLABLE, + DUK_HOBJECT_FLAG_BOUNDFUNC, DUK_HOBJECT_FLAG_COMPFUNC, DUK_HOBJECT_FLAG_NATFUNC, + DUK_HOBJECT_FLAG_BUFOBJ, DUK_HOBJECT_FLAG_FASTREFS, DUK_HOBJECT_FLAG_ARRAY_PART, + DUK_HOBJECT_FLAG_STRICT, DUK_HOBJECT_FLAG_NOTAIL, DUK_HOBJECT_FLAG_NEWENV, + DUK_HOBJECT_FLAG_NAMEBINDING, DUK_HOBJECT_FLAG_CREATEARGS, DUK_HOBJECT_FLAG_HAVE_FINALIZER, + DUK_HOBJECT_FLAG_EXOTIC_ARRAY, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS, + DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ, DUK_HOBJECT_FLAG_SPECIAL_CALL, 0 /* terminator */ }; DUK_LOCAL const char * const duk__debug_getinfo_hbuffer_keys = { "dynamic", @@ -47200,7 +48176,7 @@ DUK_LOCAL duk_uint_t duk__debug_getinfo_hbuffer_masks = { DUK_HBUFFER_FLAG_DYNAMIC, DUK_HBUFFER_FLAG_EXTERNAL, - 0 /* terminator */ + 0 /* terminator */ }; DUK_LOCAL void duk__debug_getinfo_flags_key(duk_hthread *thr, const char *key) { @@ -47226,7 +48202,7 @@ duk_debug_write_boolean(thr, val); } -DUK_LOCAL void duk__debug_getinfo_bitmask(duk_hthread *thr, const char * const * keys, duk_uint_t *masks, duk_uint_t flags) { +DUK_LOCAL void duk__debug_getinfo_bitmask(duk_hthread *thr, const char * const *keys, duk_uint_t *masks, duk_uint_t flags) { const char *key; duk_uint_t mask; @@ -47238,7 +48214,10 @@ key = *keys++; DUK_ASSERT(key != NULL); - DUK_DD(DUK_DDPRINT("inspect bitmask: key=%s, mask=0x%08lx, flags=0x%08lx", key, (unsigned long) mask, (unsigned long) flags)); + DUK_DD(DUK_DDPRINT("inspect bitmask: key=%s, mask=0x%08lx, flags=0x%08lx", + key, + (unsigned long) mask, + (unsigned long) flags)); duk__debug_getinfo_prop_bool(thr, key, flags & mask); } } @@ -47314,9 +48293,12 @@ DUK_D(DUK_DPRINT("debug command GetHeapObjInfo")); DUK_UNREF(heap); - DUK_ASSERT(sizeof(duk__debug_getinfo_hstring_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hstring_masks) / sizeof(duk_uint_t) - 1); - DUK_ASSERT(sizeof(duk__debug_getinfo_hobject_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hobject_masks) / sizeof(duk_uint_t) - 1); - DUK_ASSERT(sizeof(duk__debug_getinfo_hbuffer_keys) / sizeof(const char *) == sizeof(duk__debug_getinfo_hbuffer_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hstring_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hstring_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hobject_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hobject_masks) / sizeof(duk_uint_t) - 1); + DUK_ASSERT(sizeof(duk__debug_getinfo_hbuffer_keys) / sizeof(const char *) == + sizeof(duk__debug_getinfo_hbuffer_masks) / sizeof(duk_uint_t) - 1); h = duk_debug_read_any_ptr(thr); if (!h) { @@ -47504,7 +48486,7 @@ duk_debug_write_heapptr(thr, (duk_heaphdr *) h_bufobj->buf); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ break; } case DUK_HTYPE_BUFFER: { @@ -47519,7 +48501,7 @@ duk__debug_getinfo_flags_key(thr, "dataptr"); duk_debug_write_pointer(thr, (void *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_buf)); duk__debug_getinfo_flags_key(thr, "data"); - duk_debug_write_hbuffer(thr, h_buf); /* tolerates NULL h_buf */ + duk_debug_write_hbuffer(thr, h_buf); /* tolerates NULL h_buf */ break; } default: { @@ -47557,8 +48539,7 @@ /* To use the shared helper need the virtual index. */ DUK_ASSERT(desc.e_idx >= 0 || desc.a_idx >= 0); - virtual_idx = (desc.a_idx >= 0 ? desc.a_idx : - (duk_int_t) DUK_HOBJECT_GET_ASIZE(h_obj) + desc.e_idx); + virtual_idx = (desc.a_idx >= 0 ? desc.a_idx : (duk_int_t) DUK_HOBJECT_GET_ASIZE(h_obj) + desc.e_idx); duk_debug_write_reply(thr); rc = duk__debug_getprop_index(thr, heap, h_obj, (duk_uint_t) virtual_idx); @@ -47570,7 +48551,7 @@ } return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid args"); } @@ -47606,11 +48587,11 @@ duk_debug_write_eom(thr); return; - fail_args: +fail_args: duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNKNOWN, "invalid args"); } -#endif /* DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_INSPECT */ /* * Process incoming debug requests @@ -47708,7 +48689,7 @@ duk__debug_handle_dump_heap(thr, heap); break; } -#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ +#endif /* DUK_USE_DEBUGGER_DUMPHEAP */ case DUK_DBG_CMD_GETBYTECODE: { duk__debug_handle_get_bytecode(thr, heap); break; @@ -47730,12 +48711,12 @@ duk__debug_handle_get_obj_prop_desc_range(thr, heap); break; } -#endif /* DUK_USE_DEBUGGER_INSPECT */ +#endif /* DUK_USE_DEBUGGER_INSPECT */ default: { DUK_D(DUK_DPRINT("debug command unsupported: %d", (int) cmd)); duk_debug_write_error_eom(thr, DUK_DBG_ERR_UNSUPPORTED, "unsupported command"); } - } /* switch cmd */ + } /* switch cmd */ break; } case DUK_DBG_IB_REPLY: { @@ -47754,14 +48735,14 @@ DUK_D(DUK_DPRINT("invalid initial byte, drop connection: %d", (int) x)); goto fail; } - } /* switch initial byte */ + } /* switch initial byte */ DUK_ASSERT(duk_get_top(thr) >= entry_top); duk_set_top(thr, entry_top); duk__debug_skip_to_eom(thr); return; - fail: +fail: DUK_ASSERT(duk_get_top(thr) >= entry_top); duk_set_top(thr, entry_top); DUK__SET_CONN_BROKEN(thr, 1); @@ -47788,8 +48769,10 @@ #endif DUK_D(DUK_DPRINT("process debug messages: read_cb=%s, no_block=%ld, detaching=%ld, processing=%ld", - thr->heap->dbg_read_cb ? "not NULL" : "NULL", (long) no_block, - (long) thr->heap->dbg_detaching, (long) thr->heap->dbg_processing)); + thr->heap->dbg_read_cb ? "not NULL" : "NULL", + (long) no_block, + (long) thr->heap->dbg_detaching, + (long) thr->heap->dbg_processing)); DUK_DD(DUK_DDPRINT("top at entry: %ld", (long) duk_get_top(thr))); /* thr->heap->dbg_detaching may be != 0 if a debugger write outside @@ -47836,13 +48819,14 @@ DUK_D(DUK_DPRINT("detach pending (dbg_read_cb == NULL, dbg_detaching != 0), call detach2")); duk__debug_do_detach2(thr->heap); - thr->heap->dbg_processing = 1; /* may be set to 0 by duk_debugger_attach() inside callback */ + thr->heap->dbg_processing = 1; /* may be set to 0 by duk_debugger_attach() inside callback */ DUK_D(DUK_DPRINT("after detach2 (and possible reattach): dbg_read_cb=%s, dbg_detaching=%ld", - thr->heap->dbg_read_cb ? "not NULL" : "NULL", (long) thr->heap->dbg_detaching)); + thr->heap->dbg_read_cb ? "not NULL" : "NULL", + (long) thr->heap->dbg_detaching)); } - DUK_ASSERT(thr->heap->dbg_detaching == 0); /* true even with reattach */ - DUK_ASSERT(thr->heap->dbg_processing == 1); /* even after a detach and possible reattach */ + DUK_ASSERT(thr->heap->dbg_detaching == 0); /* true even with reattach */ + DUK_ASSERT(thr->heap->dbg_processing == 1); /* even after a detach and possible reattach */ if (thr->heap->dbg_read_cb == NULL) { DUK_D(DUK_DPRINT("debug connection broken (and not detaching), stop processing messages")); @@ -47867,7 +48851,7 @@ duk__debug_process_message(thr); duk__check_resend_status(thr); - retval = 1; /* processed one or more messages */ + retval = 1; /* processed one or more messages */ } DUK_ASSERT(thr->heap->dbg_detaching == 0); @@ -47877,7 +48861,7 @@ /* As an initial implementation, read flush after exiting the message * loop. If transport is broken, this is a no-op (with debug logs). */ - duk_debug_read_flush(thr); /* this cannot initiate a detach */ + duk_debug_read_flush(thr); /* this cannot initiate a detach */ DUK_ASSERT(thr->heap->dbg_detaching == 0); DUK_DD(DUK_DDPRINT("top at exit: %ld", (long) duk_get_top(thr))); @@ -47928,11 +48912,8 @@ /* Short circuit if is safe: if act->curr_pc != NULL, 'fun' is * guaranteed to be a non-NULL ECMAScript function. */ - DUK_ASSERT(act->curr_pc == NULL || - (fun != NULL && DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun))); - if (use_prev_pc && - act->curr_pc != NULL && - act->curr_pc > DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, fun)) { + DUK_ASSERT(act->curr_pc == NULL || (fun != NULL && DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun))); + if (use_prev_pc && act->curr_pc != NULL && act->curr_pc > DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, fun)) { act->curr_pc--; } } @@ -47959,7 +48940,7 @@ * with PC values. */ if (act != NULL) { - act->curr_pc = old_pc; /* restore PC */ + act->curr_pc = old_pc; /* restore PC */ } } @@ -47983,7 +48964,8 @@ if (heap->dbg_breakpoint_count >= DUK_HEAP_MAX_BREAKPOINTS) { DUK_D(DUK_DPRINT("failed to add breakpoint for %O:%ld, all breakpoint slots used", - (duk_heaphdr *) filename, (long) line)); + (duk_heaphdr *) filename, + (long) line)); return -1; } heap->dbg_breakpoints_active0 = (duk_breakpoint *) NULL; @@ -47992,7 +48974,7 @@ b->line = line; DUK_HSTRING_INCREF(thr, filename); - return (duk_small_int_t) (heap->dbg_breakpoint_count - 1); /* index */ + return (duk_small_int_t) (heap->dbg_breakpoint_count - 1); /* index */ } DUK_INTERNAL duk_bool_t duk_debug_remove_breakpoint(duk_hthread *thr, duk_small_uint_t breakpoint_index) { @@ -48010,7 +48992,7 @@ heap = thr->heap; DUK_ASSERT(heap != NULL); DUK_ASSERT(duk_debug_is_attached(thr->heap)); - DUK_ASSERT_DISABLE(breakpoint_index >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(breakpoint_index >= 0); /* unsigned */ if (breakpoint_index >= heap->dbg_breakpoint_count) { DUK_D(DUK_DPRINT("invalid breakpoint index: %ld", (long) breakpoint_index)); @@ -48022,15 +49004,13 @@ DUK_ASSERT(h != NULL); move_size = sizeof(duk_breakpoint) * (heap->dbg_breakpoint_count - breakpoint_index - 1); - duk_memmove((void *) b, - (const void *) (b + 1), - (size_t) move_size); + duk_memmove((void *) b, (const void *) (b + 1), (size_t) move_size); heap->dbg_breakpoint_count--; heap->dbg_breakpoints_active0 = (duk_breakpoint *) NULL; - DUK_HSTRING_DECREF(thr, h); /* side effects */ - DUK_UNREF(h); /* w/o refcounting */ + DUK_HSTRING_DECREF(thr, h); /* side effects */ + DUK_UNREF(h); /* w/o refcounting */ /* Breakpoint entries above the used area are left as garbage. */ @@ -48056,10 +49036,10 @@ DUK_HEAP_SET_DEBUGGER_PAUSED(heap); heap->dbg_state_dirty = 1; duk_debug_clear_pause_state(heap); - DUK_ASSERT(heap->ms_running == 0); /* debugger can't be triggered within mark-and-sweep */ - heap->ms_running = 2; /* prevent mark-and-sweep, prevent refzero queueing */ + DUK_ASSERT(heap->ms_running == 0); /* debugger can't be triggered within mark-and-sweep */ + heap->ms_running = 2; /* prevent mark-and-sweep, prevent refzero queueing */ heap->ms_prevent_count++; - DUK_ASSERT(heap->ms_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(heap->ms_prevent_count != 0); /* Wrap. */ DUK_ASSERT(heap->heap_thread != NULL); } } @@ -48085,11 +49065,11 @@ heap->dbg_pause_startline = 0; } -#else /* DUK_USE_DEBUGGER_SUPPORT */ +#else /* DUK_USE_DEBUGGER_SUPPORT */ /* No debugger support. */ -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* automatic undefs */ #undef DUK__DBG_TPORT_ENTER @@ -48180,7 +49160,7 @@ * when it is called and that error replaces the original one. */ - DUK_ASSERT_VALSTACK_SPACE(thr, 4); /* 3 entries actually needed below */ + DUK_ASSERT_VALSTACK_SPACE(thr, 4); /* 3 entries actually needed below */ /* ... errval */ @@ -48191,23 +49171,19 @@ DUK_DD(DUK_DDPRINT("error occurred when DUK_BIDX_DUKTAPE is NULL, ignoring")); return; } - tv_hnd = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, - thr->builtinsDUK_BIDX_DUKTAPE, - stridx_cb); + tv_hnd = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, thr->builtinsDUK_BIDX_DUKTAPE, stridx_cb); if (tv_hnd == NULL) { - DUK_DD(DUK_DDPRINT("error handler does not exist or is not a plain value: %!T", - (duk_tval *) tv_hnd)); + DUK_DD(DUK_DDPRINT("error handler does not exist or is not a plain value: %!T", (duk_tval *) tv_hnd)); return; } - DUK_DDD(DUK_DDDPRINT("error handler dump (callability not checked): %!T", - (duk_tval *) tv_hnd)); + DUK_DDD(DUK_DDDPRINT("error handler dump (callability not checked): %!T", (duk_tval *) tv_hnd)); duk_push_tval(thr, tv_hnd); /* ... errval errhandler */ - duk_insert(thr, -2); /* -> ... errhandler errval */ + duk_insert(thr, -2); /* -> ... errhandler errval */ duk_push_undefined(thr); - duk_insert(thr, -2); /* -> ... errhandler undefined(= this) errval */ + duk_insert(thr, -2); /* -> ... errhandler undefined(= this) errval */ /* ... errhandler undefined errval */ @@ -48224,21 +49200,25 @@ thr->heap->augmenting_error = 1; rc = duk_pcall_method(thr, 1); - DUK_UNREF(rc); /* no need to check now: both success and error are OK */ + DUK_UNREF(rc); /* no need to check now: both success and error are OK */ DUK_ASSERT(thr->heap->augmenting_error == 1); thr->heap->augmenting_error = 0; /* ... errval */ } -#endif /* DUK_USE_ERRTHROW || DUK_USE_ERRCREATE */ +#endif /* DUK_USE_ERRTHROW || DUK_USE_ERRCREATE */ /* * Add ._Tracedata to an error on the stack top. */ #if defined(DUK_USE_TRACEBACKS) -DUK_LOCAL void duk__add_traceback(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_LOCAL void duk__add_traceback(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { duk_activation *act; duk_int_t depth; duk_int_t arr_size; @@ -48260,15 +49240,14 @@ * See doc/error-objects.rst. */ - DUK_DDD(DUK_DDDPRINT("adding traceback to object: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("adding traceback to object: %!T", (duk_tval *) duk_get_tval(thr, -1))); /* Preallocate array to correct size, so that we can just write out * the _Tracedata values into the array part. */ act = thr->callstack_curr; depth = DUK_USE_TRACEBACK_DEPTH; - DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ + DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ if (depth > (duk_int_t) thr_callstack->callstack_top) { depth = (duk_int_t) thr_callstack->callstack_top; } @@ -48310,7 +49289,7 @@ DUK_HSTRING_INCREF(thr, s); tv++; - u32 = (duk_uint32_t) thr->compile_ctx->curr_token.start_line; /* (flags<<32) + (line), flags = 0 */ + u32 = (duk_uint32_t) thr->compile_ctx->curr_token.start_line; /* (flags<<32) + (line), flags = 0 */ DUK_TVAL_SET_U32(tv, u32); tv++; } @@ -48324,13 +49303,15 @@ if (c_filename) { DUK_ASSERT(DUK_TVAL_IS_STRING(thr->valstack_top - 2)); - s = DUK_TVAL_GET_STRING(thr->valstack_top - 2); /* interned c_filename */ + s = DUK_TVAL_GET_STRING(thr->valstack_top - 2); /* interned c_filename */ DUK_ASSERT(s != NULL); DUK_TVAL_SET_STRING(tv, s); DUK_HSTRING_INCREF(thr, s); tv++; - d = ((flags & DUK_AUGMENT_FLAG_NOBLAME_FILELINE) ? ((duk_double_t) DUK_TB_FLAG_NOBLAME_FILELINE) * DUK_DOUBLE_2TO32 : 0.0) + + d = ((flags & DUK_AUGMENT_FLAG_NOBLAME_FILELINE) ? + ((duk_double_t) DUK_TB_FLAG_NOBLAME_FILELINE) * DUK_DOUBLE_2TO32 : + 0.0) + (duk_double_t) c_line; DUK_TVAL_SET_DOUBLE(tv, d); tv++; @@ -48345,11 +49326,11 @@ /* ... arr */ - DUK_ASSERT(act != NULL); /* depth check above, assumes book-keeping is correct */ - DUK_ASSERT_DISABLE(act->pc >= 0); /* unsigned */ + DUK_ASSERT(act != NULL); /* depth check above, assumes book-keeping is correct */ + DUK_ASSERT_DISABLE(act->pc >= 0); /* unsigned */ /* Add function object. */ - tv_src = &act->tv_func; /* object (function) or lightfunc */ + tv_src = &act->tv_func; /* object (function) or lightfunc */ DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv_src) || DUK_TVAL_IS_LIGHTFUNC(tv_src)); DUK_TVAL_SET_TVAL(tv, tv_src); DUK_TVAL_INCREF(thr, tv); @@ -48361,8 +49342,8 @@ * PC == 0 for native code. */ pc = (duk_uint32_t) duk_hthread_get_act_prev_pc(thr_callstack, act); - DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ - DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ + DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ + DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ d = ((duk_double_t) act->flags) * DUK_DOUBLE_2TO32 + (duk_double_t) pc; DUK_TVAL_SET_DOUBLE(tv, d); tv++; @@ -48387,16 +49368,20 @@ /* ... error arr */ - duk_xdef_prop_stridx_short_wec(thr, -2, DUK_STRIDX_INT_TRACEDATA); /* -> ... error */ + duk_xdef_prop_stridx_short_wec(thr, -2, DUK_STRIDX_INT_TRACEDATA); /* -> ... error */ } -#endif /* DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_TRACEBACKS */ /* * Add .fileName and .lineNumber to an error on the stack top. */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) && !defined(DUK_USE_TRACEBACKS) -DUK_LOCAL void duk__add_fileline(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_LOCAL void duk__add_fileline(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { #if defined(DUK_USE_ASSERTIONS) duk_int_t entry_top; #endif @@ -48434,7 +49419,7 @@ duk_uint32_t ecma_line; duk_activation *act; - DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ + DUK_ASSERT(thr_callstack->callstack_top <= DUK_INT_MAX); /* callstack limits */ depth = DUK_USE_TRACEBACK_DEPTH; if (depth > thr_callstack->callstack_top) { depth = thr_callstack->callstack_top; @@ -48453,10 +49438,12 @@ /* PC points to next instruction, find offending PC, * PC == 0 for native code. */ - pc = duk_hthread_get_act_prev_pc(thr, act); /* thr argument only used for thr->heap, so specific thread doesn't matter */ + pc = duk_hthread_get_act_prev_pc( + thr, + act); /* thr argument only used for thr->heap, so specific thread doesn't matter */ DUK_UNREF(pc); - DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ - DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ + DUK_ASSERT_DISABLE(pc >= 0); /* unsigned */ + DUK_ASSERT((duk_double_t) pc < DUK_DOUBLE_2TO32); /* assume PC is at most 32 bits and non-negative */ duk_push_hobject(thr, func); @@ -48477,7 +49464,7 @@ } else { /* Native function, no relevant lineNumber. */ } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ duk_push_u32(thr, ecma_line); /* ... error func fileName lineNumber */ @@ -48496,7 +49483,7 @@ duk_push_undefined(thr); } - define_props: +define_props: /* ... error lineNumber fileName */ #if defined(DUK_USE_ASSERTIONS) DUK_ASSERT(duk_get_top(thr) == entry_top + 2); @@ -48504,7 +49491,7 @@ duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_C | DUK_PROPDESC_FLAG_NO_OVERWRITE); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LINE_NUMBER, DUK_PROPDESC_FLAGS_C | DUK_PROPDESC_FLAG_NO_OVERWRITE); } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE && !DUK_USE_TRACEBACKS */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE && !DUK_USE_TRACEBACKS */ /* * Add line number to a compiler error. @@ -48512,7 +49499,6 @@ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) DUK_LOCAL void duk__add_compiler_error_line(duk_hthread *thr) { - /* Append a "(line NNN)" to the "message" property of any error * thrown during compilation. Usually compilation errors are * SyntaxErrors but they can also be out-of-memory errors and @@ -48527,8 +49513,7 @@ return; } - DUK_DDD(DUK_DDDPRINT("compile error, before adding line info: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("compile error, before adding line info: %!T", (duk_tval *) duk_get_tval(thr, -1))); if (duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_MESSAGE)) { duk_bool_t at_end; @@ -48550,7 +49535,8 @@ (long) thr->compile_ctx->lex.window0.codepoint, (long) thr->compile_ctx->lex.window1.codepoint)); - duk_push_sprintf(thr, " (line %ld%s)", + duk_push_sprintf(thr, + " (line %ld%s)", (long) thr->compile_ctx->curr_token.start_line, at_end ? ", end of input" : ""); duk_concat(thr, 2); @@ -48559,10 +49545,9 @@ duk_pop(thr); } - DUK_DDD(DUK_DDDPRINT("compile error, after adding line info: %!T", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("compile error, after adding line info: %!T", (duk_tval *) duk_get_tval(thr, -1))); } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error being created using Duktape specific properties @@ -48570,7 +49555,12 @@ */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_LOCAL void duk__err_augment_builtin_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_hobject *obj, duk_small_uint_t flags) { +DUK_LOCAL void duk__err_augment_builtin_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_hobject *obj, + duk_small_uint_t flags) { #if defined(DUK_USE_ASSERTIONS) duk_int_t entry_top; #endif @@ -48580,7 +49570,7 @@ #endif DUK_ASSERT(obj != NULL); - DUK_UNREF(obj); /* unreferenced w/o tracebacks */ + DUK_UNREF(obj); /* unreferenced w/o tracebacks */ duk__add_compiler_error_line(thr); @@ -48605,7 +49595,7 @@ DUK_ASSERT(duk_get_top(thr) == entry_top); #endif } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error at creation time with _Tracedata/fileName/lineNumber @@ -48623,7 +49613,11 @@ */ #if defined(DUK_USE_AUGMENT_ERROR_CREATE) -DUK_INTERNAL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *c_filename, duk_int_t c_line, duk_small_uint_t flags) { +DUK_INTERNAL void duk_err_augment_error_create(duk_hthread *thr, + duk_hthread *thr_callstack, + const char *c_filename, + duk_int_t c_line, + duk_small_uint_t flags) { duk_hobject *obj; DUK_ASSERT(thr != NULL); @@ -48669,7 +49663,7 @@ duk__err_augment_user(thr, DUK_STRIDX_ERR_CREATE); #endif } -#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ +#endif /* DUK_USE_AUGMENT_ERROR_CREATE */ /* * Augment an error at throw time; allow a user error handler (if defined) @@ -48681,9 +49675,9 @@ DUK_INTERNAL void duk_err_augment_error_throw(duk_hthread *thr) { #if defined(DUK_USE_ERRTHROW) duk__err_augment_user(thr, DUK_STRIDX_ERR_THROW); -#endif /* DUK_USE_ERRTHROW */ +#endif /* DUK_USE_ERRTHROW */ } -#endif /* DUK_USE_AUGMENT_ERROR_THROW */ +#endif /* DUK_USE_AUGMENT_ERROR_THROW */ #line 1 "duk_error_longjmp.c" /* * Do a longjmp call, calling the fatal error handler if no @@ -48734,8 +49728,10 @@ DUK_ASSERT(thr->heap != NULL); DUK_DD(DUK_DDPRINT("longjmp error: type=%d iserror=%d value1=%!T value2=%!T", - (int) thr->heap->lj.type, (int) thr->heap->lj.iserror, - &thr->heap->lj.value1, &thr->heap->lj.value2)); + (int) thr->heap->lj.type, + (int) thr->heap->lj.iserror, + &thr->heap->lj.value1, + &thr->heap->lj.value2)); /* Prevent finalizer execution during error handling. All error * handling sites will process pending finalizers once error handling @@ -48753,11 +49749,11 @@ DUK_ASSERT_LJSTATE_SET(thr->heap); thr->heap->pf_prevent_count++; - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ #if defined(DUK_USE_ASSERTIONS) /* XXX: set this immediately when longjmp state is set */ - DUK_ASSERT(thr->heap->error_not_allowed == 0); /* Detect error within critical section. */ + DUK_ASSERT(thr->heap->error_not_allowed == 0); /* Detect error within critical section. */ thr->heap->error_not_allowed = 1; #endif @@ -48769,8 +49765,10 @@ */ if (!thr->heap->lj.jmpbuf_ptr) { DUK_D(DUK_DPRINT("uncaught error: type=%d iserror=%d value1=%!T value2=%!T", - (int) thr->heap->lj.type, (int) thr->heap->lj.iserror, - &thr->heap->lj.value1, &thr->heap->lj.value2)); + (int) thr->heap->lj.type, + (int) thr->heap->lj.iserror, + &thr->heap->lj.value1, + &thr->heap->lj.value2)); #if defined(DUK_USE_PREFER_SIZE) duk__uncaught_minimal(thr); @@ -48781,7 +49779,7 @@ } #if defined(DUK_USE_CPP_EXCEPTIONS) - throw duk_internal_exception(); /* dummy */ + throw duk_internal_exception(); /* dummy */ #else DUK_LONGJMP(thr->heap->lj.jmpbuf_ptr->jb); #endif @@ -48817,14 +49815,14 @@ for (act = thr->callstack_curr; act != NULL; act = act->parent) { for (cat = act->cat; cat != NULL; cat = cat->parent) { if (DUK_CAT_HAS_CATCH_ENABLED(cat)) { - return 1; /* all we need to know */ + return 1; /* all we need to know */ } } } } return 0; } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Get prototype object for an integer error code. @@ -48874,11 +49872,10 @@ * config options. */ - if (!duk_debug_is_attached(thr->heap) || - thr->heap->dbg_processing || - thr->heap->lj.type != DUK_LJ_TYPE_THROW || + if (!duk_debug_is_attached(thr->heap) || thr->heap->dbg_processing || thr->heap->lj.type != DUK_LJ_TYPE_THROW || thr->heap->creating_error) { - DUK_D(DUK_DPRINT("skip debugger error integration; not attached, debugger processing, not THROW, or error thrown while creating error")); + DUK_D(DUK_DPRINT("skip debugger error integration; not attached, debugger processing, not THROW, or error thrown " + "while creating error")); return; } @@ -48906,7 +49903,7 @@ /* Store and reset longjmp state. */ DUK_ASSERT_LJSTATE_SET(thr->heap); DUK_TVAL_DECREF_NORZ(thr, tv_obj); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&thr->heap->lj.value2)); /* Always for THROW type. */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(&thr->heap->lj.value2)); /* Always for THROW type. */ DUK_TVAL_SET_UNDEFINED(tv_obj); thr->heap->lj.type = DUK_LJ_TYPE_UNKNOWN; DUK_ASSERT_LJSTATE_UNSET(thr->heap); @@ -48941,7 +49938,7 @@ duk_pop(thr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Helpers for setting up heap longjmp state. @@ -48987,14 +49984,20 @@ */ #if defined(DUK_USE_VERBOSE_ERRORS) -DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code, const char *msg, const char *filename, duk_int_t line) { +DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, + duk_errcode_t code, + const char *msg, + const char *filename, + duk_int_t line) { #else DUK_INTERNAL void duk_err_create_and_throw(duk_hthread *thr, duk_errcode_t code) { #endif #if defined(DUK_USE_VERBOSE_ERRORS) DUK_DD(DUK_DDPRINT("duk_err_create_and_throw(): code=%ld, msg=%s, filename=%s, line=%ld", - (long) code, (const char *) msg, - (const char *) filename, (long) line)); + (long) code, + (const char *) msg, + (const char *) filename, + (long) line)); #else DUK_DD(DUK_DDPRINT("duk_err_create_and_throw(): code=%ld", (long) code)); #endif @@ -49054,18 +50057,9 @@ * use 'msg' as a format string directly. */ #if defined(DUK_USE_VERBOSE_ERRORS) - duk_push_error_object_raw(thr, - code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - filename, - line, - "%s", - (const char *) msg); -#else - duk_push_error_object_raw(thr, - code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - NULL, - 0, - NULL); + duk_push_error_object_raw(thr, code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, filename, line, "%s", (const char *) msg); +#else + duk_push_error_object_raw(thr, code | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, NULL, 0, NULL); #endif /* Note that an alloc error may happen during error augmentation. @@ -49075,8 +50069,7 @@ * avoiding it for alloc errors (this differs from Duktape 1.x). */ #if defined(DUK_USE_AUGMENT_ERROR_THROW) - DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT (before throw augment)", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT (before throw augment)", (duk_tval *) duk_get_tval(thr, -1))); duk_err_augment_error_throw(thr); #endif @@ -49099,7 +50092,8 @@ */ DUK_DDD(DUK_DDDPRINT("THROW ERROR (INTERNAL): %!iT, %!iT (after throw augment)", - (duk_tval *) &thr->heap->lj.value1, (duk_tval *) &thr->heap->lj.value2)); + (duk_tval *) &thr->heap->lj.value1, + (duk_tval *) &thr->heap->lj.value2)); duk_err_longjmp(thr); DUK_UNREACHABLE(); @@ -49154,7 +50148,7 @@ */ if (size > DUK_HBUFFER_MAX_BYTELEN) { DUK_D(DUK_DPRINT("hbuffer alloc failed: size too large: %ld", (long) size)); - return NULL; /* no need to write 'out_bufdata' */ + return NULL; /* no need to write 'out_bufdata' */ } if (flags & DUK_BUF_FLAG_EXTERNAL) { @@ -49166,7 +50160,7 @@ } else { header_size = sizeof(duk_hbuffer_fixed); alloc_size = sizeof(duk_hbuffer_fixed) + size; - DUK_ASSERT(alloc_size >= sizeof(duk_hbuffer_fixed)); /* no wrapping */ + DUK_ASSERT(alloc_size >= sizeof(duk_hbuffer_fixed)); /* no wrapping */ } res = (duk_hbuffer *) DUK_ALLOC(heap, alloc_size); @@ -49176,8 +50170,7 @@ /* zero everything unless requested not to do so */ #if defined(DUK_USE_ZERO_BUFFER_DATA) - duk_memzero((void *) res, - (flags & DUK_BUF_FLAG_NOZERO) ? header_size : alloc_size); + duk_memzero((void *) res, (flags & DUK_BUF_FLAG_NOZERO) ? header_size : alloc_size); #else duk_memzero((void *) res, header_size); #endif @@ -49200,7 +50193,7 @@ void *ptr; if (size > 0) { - DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); /* alloc external with size zero */ + DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); /* alloc external with size zero */ DUK_DDD(DUK_DDDPRINT("dynamic buffer with nonzero size, alloc actual buffer")); #if defined(DUK_USE_ZERO_BUFFER_DATA) ptr = DUK_ALLOC_ZEROED(heap, size); @@ -49240,16 +50233,16 @@ } else { DUK_ASSERT(!(flags & DUK_BUF_FLAG_EXTERNAL)); } - DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, &res->hdr); + DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, &res->hdr); DUK_DDD(DUK_DDDPRINT("allocated hbuffer: %p", (void *) res)); return res; - alloc_error: +alloc_error: DUK_DD(DUK_DDPRINT("hbuffer allocation failed")); DUK_FREE(heap, res); - return NULL; /* no need to write 'out_bufdata' */ + return NULL; /* no need to write 'out_bufdata' */ } /* For indirect allocs. */ @@ -49272,7 +50265,7 @@ DUK_ASSERT(h != NULL); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ #line 1 "duk_hbuffer_ops.c" /* * duk_hbuffer operations such as resizing and inserting/appending data to @@ -49329,8 +50322,7 @@ if (new_size > prev_size) { DUK_ASSERT(new_size - prev_size > 0); #if defined(DUK_USE_ZERO_BUFFER_DATA) - duk_memzero((void *) ((char *) res + prev_size), - (duk_size_t) (new_size - prev_size)); + duk_memzero((void *) ((char *) res + prev_size), (duk_size_t) (new_size - prev_size)); #endif } @@ -49372,7 +50364,7 @@ return buf_avail >= len ? len : buf_avail; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #line 1 "duk_heap_alloc.c" /* * duk_heap allocation and freeing. @@ -49382,7 +50374,7 @@ #if defined(DUK_USE_ROM_STRINGS) /* Fixed seed value used with ROM strings. */ -#define DUK__FIXED_HASH_SEED 0xabcd1234 +#define DUK__FIXED_HASH_SEED 0xabcd1234 #endif /* @@ -49471,8 +50463,8 @@ #if defined(DUK_USE_HSTRING_EXTDATA) && defined(DUK_USE_EXTSTR_FREE) if (DUK_HSTRING_HAS_EXTDATA(h)) { - DUK_DDD(DUK_DDDPRINT("free extstr: hstring %!O, extdata: %p", - h, DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h))); + DUK_DDD( + DUK_DDDPRINT("free extstr: hstring %!O, extdata: %p", h, DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h))); DUK_USE_EXTSTR_FREE(heap->heap_udata, (const void *) DUK_HSTRING_GET_EXTDATA((duk_hstring_external *) h)); } #endif @@ -49496,7 +50488,6 @@ DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(hdr) == DUK_HTYPE_BUFFER); duk_free_hbuffer(heap, (duk_hbuffer *) hdr); } - } /* @@ -49526,10 +50517,10 @@ count_act++; #endif } - heap->activation_free = NULL; /* needed when called from mark-and-sweep */ + heap->activation_free = NULL; /* needed when called from mark-and-sweep */ return count_act; } -#endif /* DUK_USE_CACHE_ACTIVATION */ +#endif /* DUK_USE_CACHE_ACTIVATION */ #if defined(DUK_USE_CACHE_CATCHER) DUK_LOCAL duk_size_t duk__heap_free_catcher_freelist(duk_heap *heap) { @@ -49545,11 +50536,11 @@ count_cat++; #endif } - heap->catcher_free = NULL; /* needed when called from mark-and-sweep */ + heap->catcher_free = NULL; /* needed when called from mark-and-sweep */ return count_cat; } -#endif /* DUK_USE_CACHE_CATCHER */ +#endif /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL void duk_heap_free_freelists(duk_heap *heap) { duk_size_t count_act = 0; @@ -49565,8 +50556,8 @@ DUK_UNREF(count_act); DUK_UNREF(count_cat); - DUK_D(DUK_DPRINT("freed %ld activation freelist entries, %ld catcher freelist entries", - (long) count_act, (long) count_cat)); + DUK_D( + DUK_DPRINT("freed %ld activation freelist entries, %ld catcher freelist entries", (long) count_act, (long) count_cat)); } DUK_LOCAL void duk__free_allocated(duk_heap *heap) { @@ -49579,8 +50570,7 @@ * because they may happen with finalizer processing. */ - DUK_DDD(DUK_DDDPRINT("FINALFREE (allocated): %!iO", - (duk_heaphdr *) curr)); + DUK_DDD(DUK_DDDPRINT("FINALFREE (allocated): %!iO", (duk_heaphdr *) curr)); next = DUK_HEAPHDR_GET_NEXT(heap, curr); duk_heap_free_heaphdr_raw(heap, curr); curr = next; @@ -49594,14 +50584,13 @@ curr = heap->finalize_list; while (curr) { - DUK_DDD(DUK_DDDPRINT("FINALFREE (finalize_list): %!iO", - (duk_heaphdr *) curr)); + DUK_DDD(DUK_DDDPRINT("FINALFREE (finalize_list): %!iO", (duk_heaphdr *) curr)); next = DUK_HEAPHDR_GET_NEXT(heap, curr); duk_heap_free_heaphdr_raw(heap, curr); curr = next; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_LOCAL void duk__free_stringtable(duk_heap *heap) { /* strings are only tracked by stringtable */ @@ -49619,9 +50608,9 @@ DUK_ASSERT(heap != NULL); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* refzero not running -> must be empty */ + DUK_ASSERT(heap->refzero_list == NULL); /* refzero not running -> must be empty */ #endif - DUK_ASSERT(heap->finalize_list == NULL); /* mark-and-sweep last pass */ + DUK_ASSERT(heap->finalize_list == NULL); /* mark-and-sweep last pass */ if (heap->heap_thread == NULL) { /* May happen when heap allocation fails right off. There @@ -49644,11 +50633,11 @@ DUK_ASSERT(heap->ms_running == 0); DUK_ASSERT(heap->ms_prevent_count == 0); heap->pf_prevent_count = 1; - heap->ms_running = 2; /* Use distinguishable value. */ - heap->ms_prevent_count = 1; /* Bump, because mark-and-sweep assumes it's bumped when ms_running is set. */ + heap->ms_running = 2; /* Use distinguishable value. */ + heap->ms_prevent_count = 1; /* Bump, because mark-and-sweep assumes it's bumped when ms_running is set. */ - curr_limit = 0; /* suppress warning, not used */ - for (round_no = 0; ; round_no++) { + curr_limit = 0; /* suppress warning, not used */ + for (round_no = 0;; round_no++) { curr = heap->heap_allocated; count_all = 0; count_finalized = 0; @@ -49663,7 +50652,8 @@ if (DUK_HOBJECT_HAS_FINALIZER_FAST(heap, (duk_hobject *) curr)) { if (!DUK_HEAPHDR_HAS_FINALIZED((duk_heaphdr *) curr)) { - DUK_ASSERT(DUK_HEAP_HAS_FINALIZER_NORESCUE(heap)); /* maps to finalizer 2nd argument */ + DUK_ASSERT( + DUK_HEAP_HAS_FINALIZER_NORESCUE(heap)); /* maps to finalizer 2nd argument */ duk_heap_run_finalizer(heap, (duk_hobject *) curr); count_finalized++; } @@ -49690,10 +50680,13 @@ */ curr_limit = count_all * 2; } else { - curr_limit = (curr_limit * 3) / 4; /* Decrease by 25% every round */ + curr_limit = (curr_limit * 3) / 4; /* Decrease by 25% every round */ } DUK_D(DUK_DPRINT("finalizer round %ld complete, %ld objects, tried to execute %ld finalizers, current limit is %ld", - (long) round_no, (long) count_all, (long) count_finalized, (long) curr_limit)); + (long) round_no, + (long) count_all, + (long) count_finalized, + (long) curr_limit)); if (count_finalized == 0) { DUK_D(DUK_DPRINT("no more finalizable objects, forced finalization finished")); @@ -49710,7 +50703,7 @@ heap->ms_running = 0; heap->pf_prevent_count = 0; } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ DUK_INTERNAL void duk_heap_free(duk_heap *heap) { DUK_D(DUK_DPRINT("free heap: %p", (void *) heap)); @@ -49753,7 +50746,7 @@ duk_heap_mark_and_sweep(heap, 0); DUK_D(DUK_DPRINT("forced gc #3 in heap destruction (don't run finalizers)")); heap->pf_skip_finalizers = 1; - duk_heap_mark_and_sweep(heap, 0); /* Skip finalizers; queue finalizable objects to heap_allocated. */ + duk_heap_mark_and_sweep(heap, 0); /* Skip finalizers; queue finalizable objects to heap_allocated. */ /* There are never objects in refzero_list at this point, or at any * point beyond a DECREF (even a DECREF_NORZ). Since Duktape 2.1 @@ -49762,17 +50755,17 @@ * refcount. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) - DUK_ASSERT(heap->finalize_list == NULL); /* Last mark-and-sweep with skip_finalizers. */ + DUK_ASSERT(heap->finalize_list == NULL); /* Last mark-and-sweep with skip_finalizers. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_D(DUK_DPRINT("run finalizers for remaining finalizable objects")); - DUK_HEAP_SET_FINALIZER_NORESCUE(heap); /* Rescue no longer supported. */ + DUK_HEAP_SET_FINALIZER_NORESCUE(heap); /* Rescue no longer supported. */ duk__free_run_finalizers(heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* Note: heap->heap_thread, heap->curr_thread, and heap->heap_object * are on the heap allocated list. @@ -49785,7 +50778,7 @@ duk__free_allocated(heap); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always processed to completion inline. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) @@ -49828,7 +50821,9 @@ while (h != NULL) { hash = duk_heap_hashstring(heap, (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); DUK_DD(DUK_DDPRINT("duk_rom_strings_lookup%d -> hash 0x%08lx, computed 0x%08lx", - (int) i, (unsigned long) DUK_HSTRING_GET_HASH(h), (unsigned long) hash)); + (int) i, + (unsigned long) DUK_HSTRING_GET_HASH(h), + (unsigned long) hash)); DUK_ASSERT(hash == (duk_uint32_t) DUK_HSTRING_GET_HASH(h)); h = (const duk_hstring *) h->hdr.h_next; @@ -49837,11 +50832,11 @@ #endif return 1; } -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ DUK_LOCAL duk_bool_t duk__init_heap_strings(duk_heap *heap) { duk_bitdecoder_ctx bd_ctx; - duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ + duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ duk_small_uint_t i; duk_memzero(&bd_ctx, sizeof(bd_ctx)); @@ -49897,18 +50892,16 @@ return 1; - failed: +failed: return 0; } -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ DUK_LOCAL duk_bool_t duk__init_heap_thread(duk_heap *heap) { duk_hthread *thr; DUK_D(DUK_DPRINT("heap init: alloc heap thread")); - thr = duk_hthread_alloc_unchecked(heap, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); + thr = duk_hthread_alloc_unchecked(heap, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_THREAD)); if (thr == NULL) { DUK_D(DUK_DPRINT("failed to alloc heap_thread")); return 0; @@ -49916,16 +50909,16 @@ thr->state = DUK_HTHREAD_STATE_INACTIVE; #if defined(DUK_USE_ROM_STRINGS) /* No strs pointer. */ -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) thr->strs16 = heap->strs16; #else thr->strs = heap->strs; #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ heap->heap_thread = thr; - DUK_HTHREAD_INCREF(thr, thr); /* Note: first argument not really used */ + DUK_HTHREAD_INCREF(thr, thr); /* Note: first argument not really used */ /* 'thr' is now reachable */ @@ -49944,7 +50937,8 @@ } #if defined(DUK_USE_DEBUG) -#define DUK__DUMPSZ(t) do { \ +#define DUK__DUMPSZ(t) \ + do { \ DUK_D(DUK_DPRINT("" #t "=%ld", (long) sizeof(t))); \ } while (0) @@ -49953,20 +50947,20 @@ * enough; the limits will then not be printed accurately but the magnitude * will be correct. */ -#define DUK__DUMPLM_SIGNED_RAW(t,a,b) do { \ - DUK_D(DUK_DPRINT(t "=%ld,%ld=%lf,%lf", \ - (long) (a), (long) (b), \ - (double) (a), (double) (b))); \ - } while (0) -#define DUK__DUMPLM_UNSIGNED_RAW(t,a,b) do { \ - DUK_D(DUK_DPRINT(t "=%lu,%lu=%lf,%lf", \ - (unsigned long) (a), (unsigned long) (b), \ - (double) (a), (double) (b))); \ +#define DUK__DUMPLM_SIGNED_RAW(t, a, b) \ + do { \ + DUK_D(DUK_DPRINT(t "=%ld,%ld=%lf,%lf", (long) (a), (long) (b), (double) (a), (double) (b))); \ + } while (0) +#define DUK__DUMPLM_UNSIGNED_RAW(t, a, b) \ + do { \ + DUK_D(DUK_DPRINT(t "=%lu,%lu=%lf,%lf", (unsigned long) (a), (unsigned long) (b), (double) (a), (double) (b))); \ } while (0) -#define DUK__DUMPLM_SIGNED(t) do { \ +#define DUK__DUMPLM_SIGNED(t) \ + do { \ DUK__DUMPLM_SIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \ } while (0) -#define DUK__DUMPLM_UNSIGNED(t) do { \ +#define DUK__DUMPLM_UNSIGNED(t) \ + do { \ DUK__DUMPLM_UNSIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \ } while (0) @@ -50039,7 +51033,7 @@ DUK__DUMPSZ(duk_tval); /* structs from duk_forwdecl.h */ - DUK__DUMPSZ(duk_jmpbuf); /* just one 'int' for C++ exceptions */ + DUK__DUMPSZ(duk_jmpbuf); /* just one 'int' for C++ exceptions */ DUK__DUMPSZ(duk_heaphdr); DUK__DUMPSZ(duk_heaphdr_string); DUK__DUMPSZ(duk_hstring); @@ -50163,7 +51157,7 @@ DUK_D(DUK_DPRINT("IEEE double endianness: ???")); #endif } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ DUK_INTERNAL duk_heap *duk_heap_alloc(duk_alloc_function alloc_func, @@ -50184,7 +51178,7 @@ DUK_ASSERT((DUK_HTYPE_STRING & 0x01U) == 0); DUK_ASSERT((DUK_HTYPE_BUFFER & 0x01U) == 0); - DUK_ASSERT((DUK_HTYPE_OBJECT & 0x01U) == 1); /* DUK_HEAPHDR_IS_OBJECT() relies ont his. */ + DUK_ASSERT((DUK_HTYPE_OBJECT & 0x01U) == 1); /* DUK_HEAPHDR_IS_OBJECT() relies ont his. */ /* * Debug dump type sizes @@ -50225,7 +51219,7 @@ #endif fatal_func(heap_udata, "sizeof(duk_tval) not 8 or 16, cannot use DUK_USE_EXEC_REGCONST_OPTIMIZE option"); } -#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ /* * Computed values (e.g. INFINITY) @@ -50309,18 +51303,18 @@ #endif #if defined(DUK_USE_ROM_STRINGS) /* no res->strs */ -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_HEAPPTR16) /* res->strs16 is zeroed and zero decodes to NULL, so no NULL inits. */ #else { duk_small_uint_t i; - for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) { + for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) { res->strsi = NULL; - } + } } #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_DEBUGGER_SUPPORT) res->dbg_read_cb = NULL; res->dbg_write_cb = NULL; @@ -50331,7 +51325,7 @@ res->dbg_udata = NULL; res->dbg_pause_act = NULL; #endif -#endif /* DUK_USE_EXPLICIT_NULL_INIT */ +#endif /* DUK_USE_EXPLICIT_NULL_INIT */ res->alloc_func = alloc_func; res->realloc_func = realloc_func; @@ -50370,17 +51364,17 @@ /* XXX: make a common DUK_USE_ option, and allow custom fixed seed? */ DUK_D(DUK_DPRINT("using rom strings, force heap hash_seed to fixed value 0x%08lx", (long) DUK__FIXED_HASH_SEED)); res->hash_seed = (duk_uint32_t) DUK__FIXED_HASH_SEED; -#else /* DUK_USE_ROM_STRINGS */ +#else /* DUK_USE_ROM_STRINGS */ res->hash_seed = (duk_uint32_t) (duk_uintptr_t) res; #if !defined(DUK_USE_STRHASH_DENSE) - res->hash_seed ^= 5381; /* Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0 */ + res->hash_seed ^= 5381; /* Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0 */ #endif -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) res->lj.jmpbuf_ptr = NULL; #endif - DUK_ASSERT(res->lj.type == DUK_LJ_TYPE_UNKNOWN); /* zero */ + DUK_ASSERT(res->lj.type == DUK_LJ_TYPE_UNKNOWN); /* zero */ DUK_ASSERT(res->lj.iserror == 0); DUK_TVAL_SET_UNDEFINED(&res->lj.value1); DUK_TVAL_SET_UNDEFINED(&res->lj.value2); @@ -50416,14 +51410,14 @@ #if defined(DUK_USE_EXPLICIT_NULL_INIT) { duk_uint32_t i; - for (i = 0; i < st_initsize; i++) { + for (i = 0; i < st_initsize; i++) { res->strtablei = NULL; - } + } } #else duk_memzero(res->strtable, sizeof(duk_hstring *) * st_initsize); -#endif /* DUK_USE_EXPLICIT_NULL_INIT */ -#endif /* DUK_USE_STRTAB_PTRCOMP */ +#endif /* DUK_USE_EXPLICIT_NULL_INIT */ +#endif /* DUK_USE_STRTAB_PTRCOMP */ /* * Init stringcache @@ -50453,7 +51447,7 @@ } } #endif -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ /* XXX: error handling is incomplete. It would be cleanest if * there was a setjmp catchpoint, so that all init code could @@ -50494,9 +51488,9 @@ #endif DUK_D(DUK_DPRINT("heap init: initialize heap object")); DUK_ASSERT(res->heap_thread != NULL); - res->heap_object = duk_hobject_alloc_unchecked(res, DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT)); + res->heap_object = duk_hobject_alloc_unchecked(res, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT)); if (res->heap_object == NULL) { goto failed; } @@ -50512,8 +51506,8 @@ duk_util_tinyrandom_prepare_seed(res->heap_thread); #else res->rnd_state0 = (duk_uint64_t) duk_time_get_ecmascript_time(res->heap_thread); - DUK_ASSERT(res->rnd_state1 == 0); /* Not filled here, filled in by seed preparation. */ -#if 0 /* Manual test values matching misc/xoroshiro128plus_test.c. */ + DUK_ASSERT(res->rnd_state1 == 0); /* Not filled here, filled in by seed preparation. */ +#if 0 /* Manual test values matching misc/xoroshiro128plus_test.c. */ res->rnd_state0 = DUK_U64_CONSTANT(0xdeadbeef12345678); res->rnd_state1 = DUK_U64_CONSTANT(0xcafed00d12345678); #endif @@ -50565,7 +51559,7 @@ DUK_D(DUK_DPRINT("allocated heap: %p", (void *) res)); return res; - failed: +failed: DUK_D(DUK_DPRINT("heap allocation failed")); if (res != NULL) { @@ -50626,14 +51620,14 @@ /* Inner function call, error throw. */ duk_eval_string_noresult(thr, - "(function dummy() {\n" - " dummy.prototype = null; /* break reference loop */\n" - " try {\n" - " throw 'fake-finalizer-dummy-error';\n" - " } catch (e) {\n" - " void e;\n" - " }\n" - "})()"); + "(function dummy() {\n" + " dummy.prototype = null; /* break reference loop */\n" + " try {\n" + " throw 'fake-finalizer-dummy-error';\n" + " } catch (e) {\n" + " void e;\n" + " }\n" + "})()"); /* The above creates garbage (e.g. a function instance). Because * the function/prototype reference loop is broken, it gets collected @@ -50665,7 +51659,7 @@ (void) duk_pcall(thr, 0 /*nargs*/); duk_pop(thr); } -#endif /* DUK_USE_FINALIZER_TORTURE */ +#endif /* DUK_USE_FINALIZER_TORTURE */ /* * Process the finalize_list to completion. @@ -50777,12 +51771,13 @@ DUK_DD(DUK_DDPRINT("processing finalize_list entry: %p -> %!iO", (void *) curr, curr)); - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* Only objects have finalizers. */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* Only objects have finalizers. */ DUK_ASSERT(!DUK_HEAPHDR_HAS_REACHABLE(curr)); DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(curr)); - DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(curr)); /* All objects on finalize_list will have this flag (except object being finalized right now). */ - DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); /* Queueing code ensures. */ - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY(curr)); /* ROM objects never get freed (or finalized). */ + DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE( + curr)); /* All objects on finalize_list will have this flag (except object being finalized right now). */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); /* Queueing code ensures. */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY(curr)); /* ROM objects never get freed (or finalized). */ #if defined(DUK_USE_ASSERTIONS) DUK_ASSERT(heap->currently_finalizing == NULL); @@ -50810,11 +51805,11 @@ */ #if defined(DUK_USE_REFERENCE_COUNTING) DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); - had_zero_refcount = (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1); /* Preincremented on finalize_list insert. */ + had_zero_refcount = (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1); /* Preincremented on finalize_list insert. */ #endif DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr)); - duk_heap_run_finalizer(heap, (duk_hobject *) curr); /* must never longjmp */ + duk_heap_run_finalizer(heap, (duk_hobject *) curr); /* must never longjmp */ DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZED(curr)); /* XXX: assert that object is still in finalize_list * when duk_push_heapptr() allows automatic rescue. @@ -50822,12 +51817,14 @@ #if defined(DUK_USE_REFERENCE_COUNTING) DUK_DD(DUK_DDPRINT("refcount after finalizer (includes bump): %ld", (long) DUK_HEAPHDR_GET_REFCOUNT(curr))); - if (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1) { /* Only artificial bump in refcount? */ + if (DUK_HEAPHDR_GET_REFCOUNT(curr) == 1) { /* Only artificial bump in refcount? */ #if defined(DUK_USE_DEBUG) if (had_zero_refcount) { - DUK_DD(DUK_DDPRINT("finalized object's refcount is zero -> free immediately (refcount queued)")); + DUK_DD(DUK_DDPRINT( + "finalized object's refcount is zero -> free immediately (refcount queued)")); } else { - DUK_DD(DUK_DDPRINT("finalized object's refcount is zero -> free immediately (mark-and-sweep queued)")); + DUK_DD(DUK_DDPRINT( + "finalized object's refcount is zero -> free immediately (mark-and-sweep queued)")); } #endif queue_back = 0; @@ -50877,21 +51874,21 @@ * decision. */ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(curr) >= 1); - DUK_HEAPHDR_PREDEC_REFCOUNT(curr); /* Remove artificial refcount bump. */ + DUK_HEAPHDR_PREDEC_REFCOUNT(curr); /* Remove artificial refcount bump. */ DUK_HEAPHDR_CLEAR_FINALIZABLE(curr); DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, curr); } else { /* No need to remove the refcount bump here. */ - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ DUK_DD(DUK_DDPRINT("refcount finalize after finalizer call: %!O", curr)); duk_hobject_refcount_finalize_norz(heap, (duk_hobject *) curr); duk_free_hobject(heap, (duk_hobject *) curr); DUK_DD(DUK_DDPRINT("freed hobject after finalization: %p", (void *) curr)); } -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ DUK_HEAPHDR_CLEAR_FINALIZABLE(curr); DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, curr); -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_DEBUG) count++; @@ -50957,11 +51954,11 @@ * caller must ensure that this function is not called if the target is * a Proxy. */ - duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_INT_FINALIZER); /* -> ... obj finalizer */ + duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_INT_FINALIZER); /* -> ... obj finalizer */ duk_dup_m2(thr); duk_push_boolean(thr, DUK_HEAP_HAS_FINALIZER_NORESCUE(thr->heap)); DUK_DDD(DUK_DDDPRINT("calling finalizer")); - duk_call(thr, 2); /* ... obj finalizer obj heapDestruct -> ... obj retval */ + duk_call(thr, 2); /* ... obj finalizer obj heapDestruct -> ... obj retval */ DUK_DDD(DUK_DDDPRINT("finalizer returned successfully")); return 0; @@ -51010,7 +52007,7 @@ return; } #endif - DUK_HEAPHDR_SET_FINALIZED((duk_heaphdr *) obj); /* ensure never re-entered until rescue cycle complete */ + DUK_HEAPHDR_SET_FINALIZED((duk_heaphdr *) obj); /* ensure never re-entered until rescue cycle complete */ #if defined(DUK_USE_ES6_PROXY) if (DUK_HOBJECT_IS_PROXY(obj)) { @@ -51022,29 +52019,30 @@ DUK_D(DUK_DPRINT("object is a Proxy, skip finalizer call")); return; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ - duk_push_hobject(thr, obj); /* this also increases refcount by one */ - rc = duk_safe_call(thr, duk__finalize_helper, NULL /*udata*/, 0 /*nargs*/, 1 /*nrets*/); /* -> ... obj retval/error */ - DUK_ASSERT_TOP(thr, entry_top + 2); /* duk_safe_call discipline */ + duk_push_hobject(thr, obj); /* this also increases refcount by one */ + rc = duk_safe_call(thr, duk__finalize_helper, NULL /*udata*/, 0 /*nargs*/, 1 /*nrets*/); /* -> ... obj retval/error */ + DUK_ASSERT_TOP(thr, entry_top + 2); /* duk_safe_call discipline */ if (rc != DUK_EXEC_SUCCESS) { /* Note: we ask for one return value from duk_safe_call to get this * error debugging here. */ DUK_D(DUK_DPRINT("wrapped finalizer call failed for object %p (ignored); error: %!T", - (void *) obj, (duk_tval *) duk_get_tval(thr, -1))); + (void *) obj, + (duk_tval *) duk_get_tval(thr, -1))); } - duk_pop_2(thr); /* -> ... */ + duk_pop_2(thr); /* -> ... */ DUK_ASSERT_TOP(thr, entry_top); } -#else /* DUK_USE_FINALIZER_SUPPORT */ +#else /* DUK_USE_FINALIZER_SUPPORT */ /* nothing */ -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #line 1 "duk_heap_hashstring.c" /* * String hash computation (interning). @@ -51069,9 +52067,9 @@ #if defined(DUK_USE_STRHASH_DENSE) /* Constants for duk_hashstring(). */ -#define DUK__STRHASH_SHORTSTRING 4096L -#define DUK__STRHASH_MEDIUMSTRING (256L * 1024L) -#define DUK__STRHASH_BLOCKSIZE 256L +#define DUK__STRHASH_SHORTSTRING 4096L +#define DUK__STRHASH_MEDIUMSTRING (256L * 1024L) +#define DUK__STRHASH_BLOCKSIZE 256L DUK_INTERNAL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len) { duk_uint32_t hash; @@ -51128,7 +52126,7 @@ #endif return hash; } -#else /* DUK_USE_STRHASH_DENSE */ +#else /* DUK_USE_STRHASH_DENSE */ DUK_INTERNAL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len) { duk_uint32_t hash; duk_size_t step; @@ -51146,10 +52144,10 @@ * more often in the suffix than in the prefix. */ - hash = heap->hash_seed ^ ((duk_uint32_t) len); /* Bernstein hash init value is normally 5381 */ + hash = heap->hash_seed ^ ((duk_uint32_t) len); /* Bernstein hash init value is normally 5381 */ step = (len >> DUK_USE_STRHASH_SKIP_SHIFT) + 1; for (off = len; off >= step; off -= step) { - DUK_ASSERT(off >= 1); /* off >= step, and step >= 1 */ + DUK_ASSERT(off >= 1); /* off >= step, and step >= 1 */ hash = (hash * 33) + stroff - 1; } @@ -51161,7 +52159,7 @@ #endif return hash; } -#endif /* DUK_USE_STRHASH_DENSE */ +#endif /* DUK_USE_STRHASH_DENSE */ /* automatic undefs */ #undef DUK__STRHASH_BLOCKSIZE @@ -51284,7 +52282,7 @@ DUK_HBUFOBJ_ASSERT_VALID(b); duk__mark_heaphdr(heap, (duk_heaphdr *) b->buf); duk__mark_heaphdr(heap, (duk_heaphdr *) b->buf_prop); -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ } else if (DUK_HOBJECT_IS_BOUNDFUNC(h)) { duk_hboundfunc *f = (duk_hboundfunc *) (void *) h; DUK_HBOUNDFUNC_ASSERT_VALID(f); @@ -51297,7 +52295,7 @@ DUK_HPROXY_ASSERT_VALID(p); duk__mark_heaphdr_nonnull(heap, (duk_heaphdr *) p->target); duk__mark_heaphdr_nonnull(heap, (duk_heaphdr *) p->handler); -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ } else if (DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; duk_activation *act; @@ -51318,7 +52316,7 @@ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) duk__mark_heaphdr(heap, (duk_heaphdr *) act->prev_caller); #endif -#if 0 /* nothing now */ +#if 0 /* nothing now */ for (cat = act->cat; cat != NULL; cat = cat->parent) { } #endif @@ -51341,9 +52339,8 @@ /* Mark any duk_heaphdr type. Recursion tracking happens only here. */ DUK_LOCAL void duk__mark_heaphdr(duk_heap *heap, duk_heaphdr *h) { - DUK_DDD(DUK_DDDPRINT("duk__mark_heaphdr %p, type %ld", - (void *) h, - (h != NULL ? (long) DUK_HEAPHDR_GET_TYPE(h) : (long) -1))); + DUK_DDD( + DUK_DDDPRINT("duk__mark_heaphdr %p, type %ld", (void *) h, (h != NULL ? (long) DUK_HEAPHDR_GET_TYPE(h) : (long) -1))); /* XXX: add non-null variant? */ if (h == NULL) { @@ -51355,7 +52352,7 @@ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) if (!DUK_HEAPHDR_HAS_READONLY(h)) { - h->h_assert_refcount++; /* Comparison refcount: bump even if already reachable. */ + h->h_assert_refcount++; /* Comparison refcount: bump even if already reachable. */ } #endif if (DUK_HEAPHDR_HAS_REACHABLE(h)) { @@ -51379,7 +52376,7 @@ } heap->ms_recursion_depth++; - DUK_ASSERT(heap->ms_recursion_depth != 0); /* Wrap. */ + DUK_ASSERT(heap->ms_recursion_depth != 0); /* Wrap. */ switch (DUK_HEAPHDR_GET_TYPE(h)) { case DUK_HTYPE_STRING: @@ -51494,9 +52491,7 @@ * of a _Finalizer hidden symbol. */ - if (!DUK_HEAPHDR_HAS_REACHABLE(hdr) && - DUK_HEAPHDR_IS_OBJECT(hdr) && - !DUK_HEAPHDR_HAS_FINALIZED(hdr) && + if (!DUK_HEAPHDR_HAS_REACHABLE(hdr) && DUK_HEAPHDR_IS_OBJECT(hdr) && !DUK_HEAPHDR_HAS_FINALIZED(hdr) && DUK_HOBJECT_HAS_FINALIZER_FAST(heap, (duk_hobject *) hdr)) { /* heaphdr: * - is not reachable @@ -51521,8 +52516,7 @@ return; } - DUK_DD(DUK_DDPRINT("marked %ld heap objects as finalizable, now mark them reachable", - (long) count_finalizable)); + DUK_DD(DUK_DDPRINT("marked %ld heap objects as finalizable, now mark them reachable", (long) count_finalizable)); hdr = heap->heap_allocated; while (hdr != NULL) { @@ -51535,7 +52529,7 @@ /* Caller will finish the marking process if we hit a recursion limit. */ } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Mark objects on finalize_list. @@ -51566,7 +52560,7 @@ } #endif } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Fallback marking handler if recursion limit is reached. @@ -51599,9 +52593,9 @@ DUK_DDD(DUK_DDDPRINT("found a temp root: %p", (void *) hdr)); DUK_HEAPHDR_CLEAR_TEMPROOT(hdr); - DUK_HEAPHDR_CLEAR_REACHABLE(hdr); /* Done so that duk__mark_heaphdr() works correctly. */ + DUK_HEAPHDR_CLEAR_REACHABLE(hdr); /* Done so that duk__mark_heaphdr() works correctly. */ #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_REFERENCE_COUNTING) - hdr->h_assert_refcount--; /* Same node visited twice. */ + hdr->h_assert_refcount--; /* Same node visited twice. */ #endif duk__mark_heaphdr_nonnull(heap, hdr); @@ -51696,7 +52690,7 @@ hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr); } } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* * Clear (reachable) flags of finalize_list. @@ -51719,15 +52713,14 @@ while (hdr) { DUK_HEAPHDR_CLEAR_REACHABLE(hdr); #if defined(DUK_USE_ASSERTIONS) - DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(hdr) || \ - (heap->currently_finalizing == hdr)); + DUK_ASSERT(DUK_HEAPHDR_HAS_FINALIZABLE(hdr) || (heap->currently_finalizing == hdr)); #endif /* DUK_HEAPHDR_FLAG_FINALIZED may be set. */ DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(hdr)); hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr); } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Sweep stringtable. @@ -51763,8 +52756,7 @@ duk_hstring *next; next = h->hdr.h_next; - if (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h)) - { + if (DUK_HEAPHDR_HAS_REACHABLE((duk_heaphdr *) h)) { DUK_HEAPHDR_CLEAR_REACHABLE((duk_heaphdr *) h); count_keep++; prev = h; @@ -51791,8 +52783,8 @@ * should have decreased unreachable string refcounts to zero * (even for cycles). However, pinned strings have a +1 bump. */ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) == - DUK_HSTRING_HAS_PINNED_LITERAL(h) ? 1U : 0U); + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) == DUK_HSTRING_HAS_PINNED_LITERAL(h) ? 1U : + 0U); #endif /* Deal with weak references first. */ @@ -51813,10 +52805,9 @@ } } - done: +done: #if defined(DUK_USE_DEBUG) - DUK_D(DUK_DPRINT("mark-and-sweep sweep stringtable: %ld freed, %ld kept", - (long) count_free, (long) count_keep)); + DUK_D(DUK_DPRINT("mark-and-sweep sweep stringtable: %ld freed, %ld kept", (long) count_free, (long) count_keep)); #endif *out_count_keep = count_keep; } @@ -51826,7 +52817,7 @@ */ DUK_LOCAL void duk__sweep_heap(duk_heap *heap, duk_small_uint_t flags, duk_size_t *out_count_keep) { - duk_heaphdr *prev; /* last element that was left in the heap */ + duk_heaphdr *prev; /* last element that was left in the heap */ duk_heaphdr *curr; duk_heaphdr *next; #if defined(DUK_USE_DEBUG) @@ -51869,25 +52860,28 @@ DUK_DD(DUK_DDPRINT("sweep; reachable, finalizable --> move to finalize_list: %p", (void *) curr)); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_HEAPHDR_PREINC_REFCOUNT(curr); /* Bump refcount so that refzero never occurs when pending a finalizer call. */ + DUK_HEAPHDR_PREINC_REFCOUNT( + curr); /* Bump refcount so that refzero never occurs when pending a finalizer call. */ #endif DUK_HEAP_INSERT_INTO_FINALIZE_LIST(heap, curr); #if defined(DUK_USE_DEBUG) count_finalize++; #endif - } - else -#endif /* DUK_USE_FINALIZER_SUPPORT */ + } else +#endif /* DUK_USE_FINALIZER_SUPPORT */ { if (DUK_UNLIKELY(DUK_HEAPHDR_HAS_FINALIZED(curr))) { DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZABLE(curr)); DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); if (flags & DUK_MS_FLAG_POSTPONE_RESCUE) { - DUK_DD(DUK_DDPRINT("sweep; reachable, finalized, but postponing rescue decisions --> keep object (with FINALIZED set): %!iO", curr)); + DUK_DD(DUK_DDPRINT("sweep; reachable, finalized, but postponing rescue decisions " + "--> keep object (with FINALIZED set): %!iO", + curr)); count_keep++; } else { - DUK_DD(DUK_DDPRINT("sweep; reachable, finalized --> rescued after finalization: %p", (void *) curr)); + DUK_DD(DUK_DDPRINT("sweep; reachable, finalized --> rescued after finalization: %p", + (void *) curr)); #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_HEAPHDR_CLEAR_FINALIZED(curr); #endif @@ -51956,7 +52950,8 @@ #if defined(DUK_USE_DEBUG) if (DUK_HEAPHDR_HAS_FINALIZED(curr)) { - DUK_DD(DUK_DDPRINT("sweep; unreachable, finalized --> finalized object not rescued: %p", (void *) curr)); + DUK_DD(DUK_DDPRINT("sweep; unreachable, finalized --> finalized object not rescued: %p", + (void *) curr)); } else { DUK_DD(DUK_DDPRINT("sweep; not reachable --> free: %p", (void *) curr)); } @@ -51990,7 +52985,10 @@ #if defined(DUK_USE_DEBUG) DUK_D(DUK_DPRINT("mark-and-sweep sweep objects (non-string): %ld freed, %ld kept, %ld rescued, %ld queued for finalization", - (long) count_free, (long) count_keep, (long) count_rescue, (long) count_finalize)); + (long) count_free, + (long) count_keep, + (long) count_rescue, + (long) count_finalize)); #endif *out_count_keep = count_keep; } @@ -52013,7 +53011,7 @@ e++; } } -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ /* * Object compaction. @@ -52032,7 +53030,12 @@ } #if defined(DUK_USE_DEBUG) -DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start, duk_size_t *p_count_check, duk_size_t *p_count_compact, duk_size_t *p_count_bytes_saved) { +DUK_LOCAL void duk__compact_object_list(duk_heap *heap, + duk_hthread *thr, + duk_heaphdr *start, + duk_size_t *p_count_check, + duk_size_t *p_count_compact, + duk_size_t *p_count_bytes_saved) { #else DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start) { #endif @@ -52054,9 +53057,8 @@ obj = (duk_hobject *) curr; #if defined(DUK_USE_DEBUG) - old_size = DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)); + old_size = + DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)); #endif DUK_DD(DUK_DDPRINT("compact object: %p", (void *) obj)); @@ -52065,9 +53067,8 @@ duk_safe_call(thr, duk__protected_compact_object, NULL, 1, 0); #if defined(DUK_USE_DEBUG) - new_size = DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)); + new_size = + DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)); #endif #if defined(DUK_USE_DEBUG) @@ -52075,7 +53076,7 @@ (*p_count_bytes_saved) += (duk_size_t) (old_size - new_size); #endif - next: + next: curr = DUK_HEAPHDR_GET_NEXT(heap, curr); #if defined(DUK_USE_DEBUG) (*p_count_check)++; @@ -52107,12 +53108,14 @@ #endif #endif #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif #if defined(DUK_USE_DEBUG) DUK_D(DUK_DPRINT("mark-and-sweep compact objects: %ld checked, %ld compaction attempts, %ld bytes saved by compaction", - (long) count_check, (long) count_compact, (long) count_bytes_saved)); + (long) count_check, + (long) count_compact, + (long) count_bytes_saved)); #endif } @@ -52159,7 +53162,7 @@ DUK_LOCAL void duk__assert_heaphdr_flags(duk_heap *heap) { duk__assert_walk_list(heap, heap->heap_allocated, duk__assert_heaphdr_flags_cb); #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif /* XXX: Assertions for finalize_list? */ } @@ -52190,8 +53193,7 @@ /* Cannot really assert much w.r.t. refcounts now. */ DUK_UNREF(heap); - if (DUK_HEAPHDR_GET_REFCOUNT(h) == 0 && - DUK_HEAPHDR_HAS_FINALIZED(h)) { + if (DUK_HEAPHDR_GET_REFCOUNT(h) == 0 && DUK_HEAPHDR_HAS_FINALIZED(h)) { /* An object may be in heap_allocated list with a zero * refcount if it has just been finalized and is waiting * to be collected by the next cycle. @@ -52205,7 +53207,7 @@ * (presumably not reachable because refcount is 0). */ } - DUK_ASSERT_DISABLE(DUK_HEAPHDR_GET_REFCOUNT(h) >= 0); /* Unsigned. */ + DUK_ASSERT_DISABLE(DUK_HEAPHDR_GET_REFCOUNT(h) >= 0); /* Unsigned. */ } DUK_LOCAL void duk__assert_valid_refcounts(duk_heap *heap) { duk__assert_walk_list(heap, heap->heap_allocated, duk__assert_valid_refcounts_cb); @@ -52256,8 +53258,10 @@ count_ok = ((duk_size_t) DUK_HEAPHDR_GET_REFCOUNT(hdr) == expect_refc); if (!count_ok) { DUK_D(DUK_DPRINT("refcount mismatch for: %p: header=%ld counted=%ld --> %!iO", - (void *) hdr, (long) DUK_HEAPHDR_GET_REFCOUNT(hdr), - (long) hdr->h_assert_refcount, hdr)); + (void *) hdr, + (long) DUK_HEAPHDR_GET_REFCOUNT(hdr), + (long) hdr->h_assert_refcount, + hdr)); DUK_ASSERT(0); } } @@ -52278,7 +53282,7 @@ /* XXX: Assert anything for refzero_list? */ duk__assert_walk_strtable(heap, duk__check_assert_refcounts_cb2); } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_LITCACHE_SIZE) DUK_LOCAL void duk__assert_litcache_nulls(duk_heap *heap) { @@ -52294,8 +53298,8 @@ DUK_ASSERT(e->addr == NULL); } } -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_ASSERTIONS */ /* * Stats dump. @@ -52304,49 +53308,64 @@ #if defined(DUK_USE_DEBUG) DUK_LOCAL void duk__dump_stats(duk_heap *heap) { DUK_D(DUK_DPRINT("stats executor: opcodes=%ld, interrupt=%ld, throw=%ld", - (long) heap->stats_exec_opcodes, (long) heap->stats_exec_interrupt, + (long) heap->stats_exec_opcodes, + (long) heap->stats_exec_interrupt, (long) heap->stats_exec_throw)); DUK_D(DUK_DPRINT("stats call: all=%ld, tailcall=%ld, ecmatoecma=%ld", - (long) heap->stats_call_all, (long) heap->stats_call_tailcall, + (long) heap->stats_call_all, + (long) heap->stats_call_tailcall, (long) heap->stats_call_ecmatoecma)); DUK_D(DUK_DPRINT("stats safecall: all=%ld, nothrow=%ld, throw=%ld", - (long) heap->stats_safecall_all, (long) heap->stats_safecall_nothrow, + (long) heap->stats_safecall_all, + (long) heap->stats_safecall_nothrow, (long) heap->stats_safecall_throw)); DUK_D(DUK_DPRINT("stats mark-and-sweep: try_count=%ld, skip_count=%ld, emergency_count=%ld", - (long) heap->stats_ms_try_count, (long) heap->stats_ms_skip_count, + (long) heap->stats_ms_try_count, + (long) heap->stats_ms_skip_count, (long) heap->stats_ms_emergency_count)); DUK_D(DUK_DPRINT("stats stringtable: intern_hit=%ld, intern_miss=%ld, " "resize_check=%ld, resize_grow=%ld, resize_shrink=%ld, " "litcache_hit=%ld, litcache_miss=%ld, litcache_pin=%ld", - (long) heap->stats_strtab_intern_hit, (long) heap->stats_strtab_intern_miss, - (long) heap->stats_strtab_resize_check, (long) heap->stats_strtab_resize_grow, - (long) heap->stats_strtab_resize_shrink, (long) heap->stats_strtab_litcache_hit, - (long) heap->stats_strtab_litcache_miss, (long) heap->stats_strtab_litcache_pin)); + (long) heap->stats_strtab_intern_hit, + (long) heap->stats_strtab_intern_miss, + (long) heap->stats_strtab_resize_check, + (long) heap->stats_strtab_resize_grow, + (long) heap->stats_strtab_resize_shrink, + (long) heap->stats_strtab_litcache_hit, + (long) heap->stats_strtab_litcache_miss, + (long) heap->stats_strtab_litcache_pin)); DUK_D(DUK_DPRINT("stats object: realloc_props=%ld, abandon_array=%ld", - (long) heap->stats_object_realloc_props, (long) heap->stats_object_abandon_array)); + (long) heap->stats_object_realloc_props, + (long) heap->stats_object_abandon_array)); DUK_D(DUK_DPRINT("stats getownpropdesc: count=%ld, hit=%ld, miss=%ld", - (long) heap->stats_getownpropdesc_count, (long) heap->stats_getownpropdesc_hit, + (long) heap->stats_getownpropdesc_count, + (long) heap->stats_getownpropdesc_hit, (long) heap->stats_getownpropdesc_miss)); DUK_D(DUK_DPRINT("stats getpropdesc: count=%ld, hit=%ld, miss=%ld", - (long) heap->stats_getpropdesc_count, (long) heap->stats_getpropdesc_hit, + (long) heap->stats_getpropdesc_count, + (long) heap->stats_getpropdesc_hit, (long) heap->stats_getpropdesc_miss)); DUK_D(DUK_DPRINT("stats getprop: all=%ld, arrayidx=%ld, bufobjidx=%ld, " "bufferidx=%ld, bufferlen=%ld, stringidx=%ld, stringlen=%ld, " "proxy=%ld, arguments=%ld", - (long) heap->stats_getprop_all, (long) heap->stats_getprop_arrayidx, - (long) heap->stats_getprop_bufobjidx, (long) heap->stats_getprop_bufferidx, - (long) heap->stats_getprop_bufferlen, (long) heap->stats_getprop_stringidx, - (long) heap->stats_getprop_stringlen, (long) heap->stats_getprop_proxy, + (long) heap->stats_getprop_all, + (long) heap->stats_getprop_arrayidx, + (long) heap->stats_getprop_bufobjidx, + (long) heap->stats_getprop_bufferidx, + (long) heap->stats_getprop_bufferlen, + (long) heap->stats_getprop_stringidx, + (long) heap->stats_getprop_stringlen, + (long) heap->stats_getprop_proxy, (long) heap->stats_getprop_arguments)); DUK_D(DUK_DPRINT("stats putprop: all=%ld, arrayidx=%ld, bufobjidx=%ld, " "bufferidx=%ld, proxy=%ld", - (long) heap->stats_putprop_all, (long) heap->stats_putprop_arrayidx, - (long) heap->stats_putprop_bufobjidx, (long) heap->stats_putprop_bufferidx, + (long) heap->stats_putprop_all, + (long) heap->stats_putprop_arrayidx, + (long) heap->stats_putprop_bufobjidx, + (long) heap->stats_putprop_bufferidx, (long) heap->stats_putprop_proxy)); - DUK_D(DUK_DPRINT("stats getvar: all=%ld", - (long) heap->stats_getvar_all)); - DUK_D(DUK_DPRINT("stats putvar: all=%ld", - (long) heap->stats_putvar_all)); + DUK_D(DUK_DPRINT("stats getvar: all=%ld", (long) heap->stats_getvar_all)); + DUK_D(DUK_DPRINT("stats putvar: all=%ld", (long) heap->stats_putvar_all)); DUK_D(DUK_DPRINT("stats envrec: delayedcreate=%ld, create=%ld, newenv=%ld, oldenv=%ld, pushclosure=%ld", (long) heap->stats_envrec_delayedcreate, (long) heap->stats_envrec_create, @@ -52354,7 +53373,7 @@ (long) heap->stats_envrec_oldenv, (long) heap->stats_envrec_pushclosure)); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Main mark-and-sweep function. @@ -52393,7 +53412,7 @@ DUK_STATS_INC(heap, stats_ms_skip_count); return; } - DUK_ASSERT(heap->ms_running == 0); /* ms_prevent_count is bumped when ms_running is set */ + DUK_ASSERT(heap->ms_running == 0); /* ms_prevent_count is bumped when ms_running is set */ /* Heap_thread is used during mark-and-sweep for refcount finalization * (it's also used for finalizer execution once mark-and-sweep is @@ -52404,7 +53423,8 @@ DUK_ASSERT(heap->heap_thread->valstack != NULL); DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) starting, requested flags: 0x%08lx, effective flags: 0x%08lx", - (unsigned long) flags, (unsigned long) (flags | heap->ms_base_flags))); + (unsigned long) flags, + (unsigned long) (flags | heap->ms_base_flags))); flags |= heap->ms_base_flags; #if defined(DUK_USE_FINALIZER_SUPPORT) @@ -52430,8 +53450,8 @@ * finalizer may trigger a mark-and-sweep. */ duk__assert_valid_refcounts(heap); -#endif /* DUK_USE_REFERENCE_COUNTING */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_ASSERTIONS */ /* * Begin @@ -52475,17 +53495,17 @@ #if defined(DUK_USE_LITCACHE_SIZE) duk__wipe_litcache(heap); #endif - duk__mark_roots_heap(heap); /* Mark main reachability roots. */ + duk__mark_roots_heap(heap); /* Mark main reachability roots. */ #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif - duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ + duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ #if defined(DUK_USE_FINALIZER_SUPPORT) - duk__mark_finalizable(heap); /* Mark finalizable as reachability roots. */ - duk__mark_finalize_list(heap); /* Mark finalizer work list as reachability roots. */ + duk__mark_finalizable(heap); /* Mark finalizable as reachability roots. */ + duk__mark_finalize_list(heap); /* Mark finalizer work list as reachability roots. */ #endif - duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ + duk__mark_temproots_by_heap_scan(heap); /* Temproots. */ /* * Sweep garbage and remove marking flags, and move objects with @@ -52512,7 +53532,7 @@ duk__check_assert_refcounts(heap); #endif #if defined(DUK_USE_REFERENCE_COUNTING) - DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ + DUK_ASSERT(heap->refzero_list == NULL); /* Always handled to completion inline in DECREF. */ #endif #if defined(DUK_USE_FINALIZER_SUPPORT) duk__clear_finalize_list_flags(heap); @@ -52539,8 +53559,7 @@ * interfering with error state. */ - if ((flags & DUK_MS_FLAG_EMERGENCY) && - !(flags & DUK_MS_FLAG_NO_OBJECT_COMPACTION)) { + if ((flags & DUK_MS_FLAG_EMERGENCY) && !(flags & DUK_MS_FLAG_NO_OBJECT_COMPACTION)) { if (heap->lj.type != DUK_LJ_TYPE_UNKNOWN) { DUK_D(DUK_DPRINT("lj.type (%ld) not DUK_LJ_TYPE_UNKNOWN, skip object compaction", (long) heap->lj.type)); } else { @@ -52573,7 +53592,7 @@ DUK_ASSERT(heap->ms_running == 1); heap->ms_prevent_count = 0; heap->ms_running = 0; - heap->creating_error = entry_creating_error; /* for nested error handling, see GH-2278 */ + heap->creating_error = entry_creating_error; /* for nested error handling, see GH-2278 */ /* * Assertions after @@ -52590,11 +53609,11 @@ * finalizer may trigger a mark-and-sweep. */ duk__assert_valid_refcounts(heap); -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_LITCACHE_SIZE) duk__assert_litcache_nulls(heap); -#endif /* DUK_USE_LITCACHE_SIZE */ -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_ASSERTIONS */ /* * Reset trigger counter @@ -52602,14 +53621,15 @@ #if defined(DUK_USE_VOLUNTARY_GC) tmp = (count_keep_obj + count_keep_str) / 256; - heap->ms_trigger_counter = (duk_int_t) ( - (tmp * DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT) + - DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD); + heap->ms_trigger_counter = (duk_int_t) ((tmp * DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT) + DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD); DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) finished: %ld objects kept, %ld strings kept, trigger reset to %ld", - (long) count_keep_obj, (long) count_keep_str, (long) heap->ms_trigger_counter)); + (long) count_keep_obj, + (long) count_keep_str, + (long) heap->ms_trigger_counter)); #else DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) finished: %ld objects kept, %ld strings kept, no voluntary trigger", - (long) count_keep_obj, (long) count_keep_str)); + (long) count_keep_obj, + (long) count_keep_str)); #endif /* @@ -52652,7 +53672,7 @@ * is inside the target. */ duk_heap_process_finalize_list(heap); -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ } #line 1 "duk_heap_memory.c" /* @@ -52715,7 +53735,8 @@ res = heap->alloc_func(heap->heap_udata, size); if (res != NULL) { DUK_D(DUK_DPRINT("duk_heap_mem_alloc() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) size)); + (long) (i + 1), + (long) size)); return res; } } @@ -52759,7 +53780,7 @@ return res; } - slowpath: +slowpath: if (size == 0) { DUK_D(DUK_DPRINT("first alloc attempt returned NULL for zero size alloc, use slow path to deal with it")); @@ -52834,13 +53855,7 @@ /* ptr may be NULL */ DUK_ASSERT_DISABLE(newsize >= 0); - /* Newsize was 0 and realloc() returned NULL, this has the semantics - * of free(oldptr), i.e. memory was successfully freed. - */ - if (newsize == 0) { - DUK_D(DUK_DPRINT("zero size realloc in slow path, return NULL")); - return NULL; - } + /* Unlike for malloc(), zero size NULL result check happens at the call site. */ DUK_D(DUK_DPRINT("first realloc attempt failed, attempt to gc and retry")); @@ -52871,11 +53886,11 @@ duk_heap_mark_and_sweep(heap, flags); - DUK_ASSERT(newsize > 0); res = heap->realloc_func(heap->heap_udata, ptr, newsize); - if (res || newsize == 0) { + if (res != NULL || newsize == 0) { DUK_D(DUK_DPRINT("duk_heap_mem_realloc() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) newsize)); + (long) (i + 1), + (long) newsize)); return res; } } @@ -52895,7 +53910,7 @@ #if defined(DUK_USE_VOLUNTARY_GC) /* Voluntary periodic GC (if enabled). */ if (DUK_UNLIKELY(--(heap)->ms_trigger_counter < 0)) { - goto slowpath; + goto gc_retry; } #endif @@ -52907,22 +53922,22 @@ DUK_DDD(DUK_DDDPRINT("gc torture enabled, pretend that first realloc attempt fails")); res = NULL; DUK_UNREF(res); - goto slowpath; + goto gc_retry; } #endif res = heap->realloc_func(heap->heap_udata, ptr, newsize); - if (DUK_LIKELY(res != NULL)) { + if (DUK_LIKELY(res != NULL) || newsize == 0) { + if (res != NULL && newsize == 0) { + DUK_DD(DUK_DDPRINT("first realloc attempt returned NULL for zero size realloc, accept and return NULL")); + } return res; - } - - slowpath: - - if (newsize == 0) { - DUK_D(DUK_DPRINT("first realloc attempt returned NULL for zero size realloc, use slow path to deal with it")); } else { - DUK_D(DUK_DPRINT("first realloc attempt failed, attempt to gc and retry")); + goto gc_retry; } + /* Never here. */ + +gc_retry: return duk__heap_mem_realloc_slowpath(heap, ptr, newsize); } @@ -52933,7 +53948,10 @@ */ /* Slow path: voluntary GC triggered, first realloc attempt failed, or zero size. */ -DUK_LOCAL DUK_NOINLINE_PERF DUK_COLD void *duk__heap_mem_realloc_indirect_slowpath(duk_heap *heap, duk_mem_getptr cb, void *ud, duk_size_t newsize) { +DUK_LOCAL DUK_NOINLINE_PERF DUK_COLD void *duk__heap_mem_realloc_indirect_slowpath(duk_heap *heap, + duk_mem_getptr cb, + void *ud, + duk_size_t newsize) { void *res; duk_small_int_t i; @@ -52941,10 +53959,7 @@ DUK_ASSERT(heap->realloc_func != NULL); DUK_ASSERT_DISABLE(newsize >= 0); - if (newsize == 0) { - DUK_D(DUK_DPRINT("zero size indirect realloc in slow path, return NULL")); - return NULL; - } + /* Unlike for malloc(), zero size NULL result check happens at the call site. */ DUK_D(DUK_DPRINT("first indirect realloc attempt failed, attempt to gc and retry")); @@ -52986,7 +54001,8 @@ ptr_post = cb(heap, ud); if (ptr_pre != ptr_post) { DUK_DD(DUK_DDPRINT("realloc base pointer changed by mark-and-sweep: %p -> %p", - (void *) ptr_pre, (void *) ptr_post)); + (void *) ptr_pre, + (void *) ptr_post)); } #endif @@ -52994,11 +54010,11 @@ * The pointer being reallocated may change after every mark-and-sweep. */ - DUK_ASSERT(newsize > 0); res = heap->realloc_func(heap->heap_udata, cb(heap, ud), newsize); - if (res || newsize == 0) { + if (res != NULL || newsize == 0) { DUK_D(DUK_DPRINT("duk_heap_mem_realloc_indirect() succeeded after gc (pass %ld), alloc size %ld", - (long) (i + 1), (long) newsize)); + (long) (i + 1), + (long) newsize)); return res; } } @@ -53007,7 +54023,10 @@ return NULL; } -DUK_INTERNAL DUK_INLINE_PERF DUK_HOT void *duk_heap_mem_realloc_indirect(duk_heap *heap, duk_mem_getptr cb, void *ud, duk_size_t newsize) { +DUK_INTERNAL DUK_INLINE_PERF DUK_HOT void *duk_heap_mem_realloc_indirect(duk_heap *heap, + duk_mem_getptr cb, + void *ud, + duk_size_t newsize) { void *res; DUK_ASSERT(heap != NULL); @@ -53017,7 +54036,7 @@ #if defined(DUK_USE_VOLUNTARY_GC) /* Voluntary periodic GC (if enabled). */ if (DUK_UNLIKELY(--(heap)->ms_trigger_counter < 0)) { - goto slowpath; + goto gc_retry; } #endif @@ -53029,22 +54048,23 @@ DUK_DDD(DUK_DDDPRINT("gc torture enabled, pretend that first indirect realloc attempt fails")); res = NULL; DUK_UNREF(res); - goto slowpath; + goto gc_retry; } #endif res = heap->realloc_func(heap->heap_udata, cb(heap, ud), newsize); - if (DUK_LIKELY(res != NULL)) { + if (DUK_LIKELY(res != NULL) || newsize == 0) { + if (res != NULL && newsize == 0) { + DUK_DD(DUK_DDPRINT( + "first indirect realloc attempt returned NULL for zero size realloc, accept and return NULL")); + } return res; - } - - slowpath: - - if (newsize == 0) { - DUK_D(DUK_DPRINT("first indirect realloc attempt returned NULL for zero size realloc, use slow path to deal with it")); } else { - DUK_D(DUK_DPRINT("first indirect realloc attempt failed, attempt to gc and retry")); + goto gc_retry; } + /* Never here. */ + +gc_retry: return duk__heap_mem_realloc_indirect_slowpath(heap, cb, ud, newsize); } @@ -53134,7 +54154,7 @@ ; } } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL void duk_heap_insert_into_finalize_list(duk_heap *heap, duk_heaphdr *hdr) { @@ -53153,7 +54173,7 @@ DUK_HEAPHDR_ASSERT_LINKS(heap, root); heap->finalize_list = hdr; } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_FINALIZER_SUPPORT) DUK_INTERNAL void duk_heap_remove_from_finalize_list(duk_heap *heap, duk_heaphdr *hdr) { @@ -53187,7 +54207,7 @@ } else { DUK_ASSERT(hdr != heap->finalize_list); for (;;) { - DUK_ASSERT(curr != NULL); /* Caller responsibility. */ + DUK_ASSERT(curr != NULL); /* Caller responsibility. */ next = DUK_HEAPHDR_GET_NEXT(heap, curr); if (next == hdr) { @@ -53199,7 +54219,7 @@ } #endif } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL duk_bool_t duk_heap_in_heap_allocated(duk_heap *heap, duk_heaphdr *ptr) { @@ -53213,7 +54233,7 @@ } return 0; } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ #if defined(DUK_USE_INTERRUPT_COUNTER) DUK_INTERNAL void duk_heap_switch_thread(duk_heap *heap, duk_hthread *new_thr) { @@ -53246,9 +54266,9 @@ DUK_DD(DUK_DDPRINT("switch thread, new thread is NULL, no interrupt counter changes")); } - heap->curr_thread = new_thr; /* may be NULL */ + heap->curr_thread = new_thr; /* may be NULL */ } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ #if defined(DUK_USE_ASSERTIONS) DUK_INTERNAL void duk_heap_assert_valid(duk_heap *heap) { @@ -53418,7 +54438,7 @@ } else if (DUK_HOBJECT_IS_OBJENV(h)) { duk_hobjenv *e = (duk_hobjenv *) h; DUK_HOBJENV_ASSERT_VALID(e); - DUK_ASSERT(e->target != NULL); /* Required for object environments. */ + DUK_ASSERT(e->target != NULL); /* Required for object environments. */ DUK_HOBJECT_DECREF_NORZ(thr, e->target); #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) } else if (DUK_HOBJECT_IS_BUFOBJ(h)) { @@ -53426,7 +54446,7 @@ DUK_HBUFOBJ_ASSERT_VALID(b); DUK_HBUFFER_DECREF_NORZ_ALLOWNULL(thr, (duk_hbuffer *) b->buf); DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) b->buf_prop); -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ } else if (DUK_HOBJECT_IS_BOUNDFUNC(h)) { duk_hboundfunc *f = (duk_hboundfunc *) (void *) h; DUK_HBOUNDFUNC_ASSERT_VALID(f); @@ -53439,7 +54459,7 @@ DUK_HPROXY_ASSERT_VALID(p); DUK_HOBJECT_DECREF_NORZ(thr, p->target); DUK_HOBJECT_DECREF_NORZ(thr, p->handler); -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ } else if (DUK_HOBJECT_IS_THREAD(h)) { duk_hthread *t = (duk_hthread *) h; duk_activation *act; @@ -53460,13 +54480,12 @@ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) act->prev_caller); #endif -#if 0 /* nothing now */ +#if 0 /* nothing now */ for (cat = act->cat; cat != NULL; cat = cat->parent) { } #endif } - for (i = 0; i < DUK_NUM_BUILTINS; i++) { DUK_HOBJECT_DECREF_NORZ_ALLOWNULL(thr, (duk_hobject *) t->builtinsi); } @@ -53551,7 +54570,7 @@ curr = heap->refzero_list; DUK_ASSERT(curr != NULL); - DUK_ASSERT(DUK_HEAPHDR_GET_PREV(heap, curr) == NULL); /* We're called on initial insert only. */ + DUK_ASSERT(DUK_HEAPHDR_GET_PREV(heap, curr) == NULL); /* We're called on initial insert only. */ /* curr->next is GARBAGE. */ do { @@ -53564,7 +54583,7 @@ #endif DUK_ASSERT(curr != NULL); - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* currently, always the case */ /* FINALIZED may be set; don't care about flags here. */ /* Refcount finalize 'curr'. Refzero_list must be non-NULL @@ -53574,11 +54593,10 @@ duk_hobject_refcount_finalize_norz(heap, (duk_hobject *) curr); prev = DUK_HEAPHDR_GET_PREV(heap, curr); - DUK_ASSERT((prev == NULL && heap->refzero_list == curr) || \ - (prev != NULL && heap->refzero_list != curr)); + DUK_ASSERT((prev == NULL && heap->refzero_list == curr) || (prev != NULL && heap->refzero_list != curr)); /* prev->next is intentionally not updated and is garbage. */ - duk_free_hobject(heap, (duk_hobject *) curr); /* Invalidates 'curr'. */ + duk_free_hobject(heap, (duk_hobject *) curr); /* Invalidates 'curr'. */ curr = prev; } while (curr != NULL); @@ -53654,7 +54672,7 @@ return; } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* No need to finalize, free object via refzero_list. */ @@ -53698,7 +54716,7 @@ DUK_INTERNAL DUK_ALWAYS_INLINE void duk_refzero_check_fast(duk_hthread *thr) { DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ + DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ if (DUK_UNLIKELY(thr->heap->finalize_list != NULL)) { duk_heap_process_finalize_list(thr->heap); @@ -53708,13 +54726,13 @@ DUK_INTERNAL void duk_refzero_check_slow(duk_hthread *thr) { DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); - DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ + DUK_ASSERT(thr->heap->refzero_list == NULL); /* Processed to completion inline. */ if (DUK_UNLIKELY(thr->heap->finalize_list != NULL)) { duk_heap_process_finalize_list(thr->heap); } } -#endif /* DUK_USE_FINALIZER_SUPPORT */ +#endif /* DUK_USE_FINALIZER_SUPPORT */ /* * Refzero processing for duk_hstring. @@ -53774,7 +54792,8 @@ * The suppress condition is important to performance. */ -#define DUK__RZ_SUPPRESS_ASSERT1() do { \ +#define DUK__RZ_SUPPRESS_ASSERT1() \ + do { \ DUK_ASSERT(thr != NULL); \ DUK_ASSERT(thr->heap != NULL); \ /* When mark-and-sweep runs, heap_thread must exist. */ \ @@ -53796,32 +54815,41 @@ } while (0) #if defined(DUK_USE_DEBUGGER_SUPPORT) -#define DUK__RZ_SUPPRESS_ASSERT2() do { \ +#define DUK__RZ_SUPPRESS_ASSERT2() \ + do { \ /* When debugger is paused, ms_running is set. */ \ DUK_ASSERT(!DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || thr->heap->ms_running != 0); \ } while (0) -#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) +#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) #else -#define DUK__RZ_SUPPRESS_ASSERT2() do { } while (0) -#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#define DUK__RZ_SUPPRESS_ASSERT2() \ + do { \ + } while (0) +#define DUK__RZ_SUPPRESS_COND() (heap->ms_running != 0) +#endif /* DUK_USE_DEBUGGER_SUPPORT */ -#define DUK__RZ_SUPPRESS_CHECK() do { \ +#define DUK__RZ_SUPPRESS_CHECK() \ + do { \ DUK__RZ_SUPPRESS_ASSERT1(); \ DUK__RZ_SUPPRESS_ASSERT2(); \ if (DUK_UNLIKELY(DUK__RZ_SUPPRESS_COND())) { \ - DUK_DDD(DUK_DDDPRINT("refzero handling suppressed (not even queued) when mark-and-sweep running, object: %p", (void *) h)); \ + DUK_DDD( \ + DUK_DDDPRINT("refzero handling suppressed (not even queued) when mark-and-sweep running, object: %p", \ + (void *) h)); \ return; \ } \ } while (0) -#define DUK__RZ_STRING() do { \ +#define DUK__RZ_STRING() \ + do { \ duk__refcount_refzero_hstring(heap, (duk_hstring *) h); \ } while (0) -#define DUK__RZ_BUFFER() do { \ +#define DUK__RZ_BUFFER() \ + do { \ duk__refcount_refzero_hbuffer(heap, (duk_hbuffer *) h); \ } while (0) -#define DUK__RZ_OBJECT() do { \ +#define DUK__RZ_OBJECT() \ + do { \ duk__refcount_refzero_hobject(heap, (duk_hobject *) h, skip_free_pending); \ } while (0) @@ -53942,7 +54970,7 @@ DUK_ASSERT(DUK_HEAPHDR_HTYPE_VALID(h)); DUK_ASSERT_DISABLE(h->h_refcount >= 0); DUK_HEAPHDR_PREINC_REFCOUNT(h); - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(h) != 0); /* No wrapping. */ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(h) != 0); /* No wrapping. */ } } @@ -53985,9 +55013,10 @@ #endif } } -#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ +#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ -#define DUK__DECREF_ASSERTS() do { \ +#define DUK__DECREF_ASSERTS() \ + do { \ DUK_ASSERT(thr != NULL); \ DUK_ASSERT(thr->heap != NULL); \ DUK_ASSERT(h != NULL); \ @@ -53995,14 +55024,16 @@ DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) >= 1); \ } while (0) #if defined(DUK_USE_ROM_OBJECTS) -#define DUK__INCREF_SHARED() do { \ +#define DUK__INCREF_SHARED() \ + do { \ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) h)) { \ return; \ } \ DUK_HEAPHDR_PREINC_REFCOUNT((duk_heaphdr *) h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ } while (0) -#define DUK__DECREF_SHARED() do { \ +#define DUK__DECREF_SHARED() \ + do { \ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) h)) { \ return; \ } \ @@ -54011,11 +55042,13 @@ } \ } while (0) #else -#define DUK__INCREF_SHARED() do { \ +#define DUK__INCREF_SHARED() \ + do { \ DUK_HEAPHDR_PREINC_REFCOUNT((duk_heaphdr *) h); \ - DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ + DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) h) != 0); /* No wrapping. */ \ } while (0) -#define DUK__DECREF_SHARED() do { \ +#define DUK__DECREF_SHARED() \ + do { \ if (DUK_HEAPHDR_PREDEC_REFCOUNT((duk_heaphdr *) h) != 0) { \ return; \ } \ @@ -54049,9 +55082,9 @@ DUK__DECREF_SHARED(); duk_heaphdr_refzero_norz(thr, h); } -#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ +#endif /* !DUK_USE_FAST_REFCOUNT_DEFAULT */ -#if 0 /* Not needed. */ +#if 0 /* Not needed. */ DUK_INTERNAL void duk_hstring_decref(duk_hthread *thr, duk_hstring *h) { DUK__DECREF_ASSERTS(); DUK__DECREF_SHARED(); @@ -54084,11 +55117,11 @@ } #endif -#else /* DUK_USE_REFERENCE_COUNTING */ +#else /* DUK_USE_REFERENCE_COUNTING */ /* no refcounting */ -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* automatic undefs */ #undef DUK__DECREF_ASSERTS @@ -54127,8 +55160,8 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; if (c->h == h) { - DUK_DD(DUK_DDPRINT("deleting weak strcache reference to hstring %p from heap %p", - (void *) h, (void *) heap)); + DUK_DD( + DUK_DDPRINT("deleting weak strcache reference to hstring %p from heap %p", (void *) h, (void *) heap)); c->h = NULL; /* XXX: the string shouldn't appear twice, but we now loop to the @@ -54238,7 +55271,8 @@ */ DUK_DDD(DUK_DDDPRINT("non-ascii string %p, char_offset=%ld, clen=%ld, blen=%ld", - (void *) h, (long) char_offset, + (void *) h, + (long) char_offset, (long) DUK_HSTRING_GET_CHARLEN(h), (long) DUK_HSTRING_GET_BYTELEN(h))); @@ -54252,7 +55286,10 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; DUK_DDD(DUK_DDDPRINT(" %ld -> h=%p, cidx=%ld, bidx=%ld", - (long) i, (void *) c->h, (long) c->cidx, (long) c->bidx)); + (long) i, + (void *) c->h, + (long) c->cidx, + (long) c->bidx)); } #endif @@ -54276,7 +55313,8 @@ DUK_ASSERT(DUK_HSTRING_GET_CHARLEN(h) >= char_offset); dist_start = char_offset; dist_end = char_length - char_offset; - dist_sce = 0; DUK_UNREF(dist_sce); /* initialize for debug prints, needed if sce==NULL */ + dist_sce = 0; + DUK_UNREF(dist_sce); /* initialize for debug prints, needed if sce==NULL */ p_start = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h); p_end = (const duk_uint8_t *) (p_start + DUK_HSTRING_GET_BYTELEN(h)); @@ -54289,14 +55327,15 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan forwards from sce", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_forwards(p_start + sce->bidx, - p_end, - dist_sce); + p_found = duk__scan_forwards(p_start + sce->bidx, p_end, dist_sce); goto scan_done; } } else { @@ -54305,14 +55344,15 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan backwards from sce", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_backwards(p_start + sce->bidx, - p_start, - dist_sce); + p_found = duk__scan_backwards(p_start + sce->bidx, p_start, dist_sce); goto scan_done; } } @@ -54324,29 +55364,31 @@ DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan forwards from string start", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_forwards(p_start, - p_end, - dist_start); + p_found = duk__scan_forwards(p_start, p_end, dist_start); } else { DUK_DDD(DUK_DDDPRINT("non-ascii string, use_cache=%ld, sce=%p:%ld:%ld, " "dist_start=%ld, dist_end=%ld, dist_sce=%ld => " "scan backwards from string end", - (long) use_cache, (void *) (sce ? sce->h : NULL), + (long) use_cache, + (void *) (sce ? sce->h : NULL), (sce ? (long) sce->cidx : (long) -1), (sce ? (long) sce->bidx : (long) -1), - (long) dist_start, (long) dist_end, (long) dist_sce)); + (long) dist_start, + (long) dist_end, + (long) dist_sce)); - p_found = duk__scan_backwards(p_end, - p_start, - dist_end); + p_found = duk__scan_backwards(p_end, p_start, dist_end); } - scan_done: +scan_done: if (DUK_UNLIKELY(p_found == NULL)) { /* Scan error: this shouldn't normally happen; it could happen if @@ -54357,11 +55399,10 @@ } DUK_ASSERT(p_found >= p_start); - DUK_ASSERT(p_found <= p_end); /* may be equal */ + DUK_ASSERT(p_found <= p_end); /* may be equal */ byte_offset = (duk_uint32_t) (p_found - p_start); - DUK_DDD(DUK_DDDPRINT("-> string %p, cidx %ld -> bidx %ld", - (void *) h, (long) char_offset, (long) byte_offset)); + DUK_DDD(DUK_DDDPRINT("-> string %p, cidx %ld -> bidx %ld", (void *) h, (long) char_offset, (long) byte_offset)); /* * Update cache entry (allocating if necessary), and move the @@ -54371,7 +55412,7 @@ if (use_cache) { /* update entry, allocating if necessary */ if (!sce) { - sce = heap->strcache + DUK_HEAP_STRCACHE_SIZE - 1; /* take last entry */ + sce = heap->strcache + DUK_HEAP_STRCACHE_SIZE - 1; /* take last entry */ sce->h = h; } DUK_ASSERT(sce != NULL); @@ -54401,14 +55442,17 @@ for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) { duk_strcache_entry *c = heap->strcache + i; DUK_DDD(DUK_DDDPRINT(" %ld -> h=%p, cidx=%ld, bidx=%ld", - (long) i, (void *) c->h, (long) c->cidx, (long) c->bidx)); + (long) i, + (void *) c->h, + (long) c->cidx, + (long) c->bidx)); } #endif } return byte_offset; - scan_error: +scan_error: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); } @@ -54428,16 +55472,16 @@ #endif #if defined(DUK_USE_STRTAB_PTRCOMP) -#define DUK__HEAPPTR_ENC16(heap,ptr) DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (ptr)) -#define DUK__HEAPPTR_DEC16(heap,val) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (val)) -#define DUK__GET_STRTABLE(heap) ((heap)->strtable16) +#define DUK__HEAPPTR_ENC16(heap, ptr) DUK_USE_HEAPPTR_ENC16((heap)->heap_udata, (ptr)) +#define DUK__HEAPPTR_DEC16(heap, val) DUK_USE_HEAPPTR_DEC16((heap)->heap_udata, (val)) +#define DUK__GET_STRTABLE(heap) ((heap)->strtable16) #else -#define DUK__HEAPPTR_ENC16(heap,ptr) (ptr) -#define DUK__HEAPPTR_DEC16(heap,val) (val) -#define DUK__GET_STRTABLE(heap) ((heap)->strtable) +#define DUK__HEAPPTR_ENC16(heap, ptr) (ptr) +#define DUK__HEAPPTR_DEC16(heap, val) (val) +#define DUK__GET_STRTABLE(heap) ((heap)->strtable) #endif -#define DUK__STRTAB_U32_MAX_STRLEN 10 /* 4'294'967'295 */ +#define DUK__STRTAB_U32_MAX_STRLEN 10 /* 4'294'967'295 */ /* * Debug dump stringtable. @@ -54456,7 +55500,7 @@ duk_size_t count_chain; duk_size_t count_chain_min = DUK_SIZE_MAX; duk_size_t count_chain_max = 0; - duk_size_t count_len8; /* chain lengths from 0 to 7 */ + duk_size_t count_len8; /* chain lengths from 0 to 7 */ if (heap == NULL) { DUK_D(DUK_DPRINT("string table, heap=NULL")); @@ -54487,15 +55531,21 @@ DUK_D(DUK_DPRINT("string table, strtab=%p, count=%lu, chain min=%lu max=%lu avg=%lf: " "counts: %lu %lu %lu %lu %lu %lu %lu %lu ...", - (void *) heap->strtable, (unsigned long) count_total, - (unsigned long) count_chain_min, (unsigned long) count_chain_max, + (void *) heap->strtable, + (unsigned long) count_total, + (unsigned long) count_chain_min, + (unsigned long) count_chain_max, (double) count_total / (double) heap->st_size, - (unsigned long) count_len0, (unsigned long) count_len1, - (unsigned long) count_len2, (unsigned long) count_len3, - (unsigned long) count_len4, (unsigned long) count_len5, - (unsigned long) count_len6, (unsigned long) count_len7)); + (unsigned long) count_len0, + (unsigned long) count_len1, + (unsigned long) count_len2, + (unsigned long) count_len3, + (unsigned long) count_len4, + (unsigned long) count_len5, + (unsigned long) count_len6, + (unsigned long) count_len7)); } -#endif /* DUK_USE_DEBUG */ +#endif /* DUK_USE_DEBUG */ /* * Assertion helper to ensure strtable is populated correctly. @@ -54536,7 +55586,7 @@ DUK_ASSERT(count == (duk_size_t) heap->st_count); #endif } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Allocate and initialize a duk_hstring. @@ -54587,16 +55637,16 @@ #endif DUK_HEAPHDR_SET_TYPE_AND_FLAGS(&res->hdr, DUK_HTYPE_STRING, DUK_HSTRING_FLAG_EXTDATA); - DUK_ASSERT(extdatablen == 0); /* Application responsibility. */ + DUK_ASSERT(extdatablen == 0); /* Application responsibility. */ data = extdata; ((duk_hstring_external *) res)->extdata = extdata; } else -#endif /* DUK_USE_HSTRING_EXTDATA && DUK_USE_EXTSTR_INTERN_CHECK */ +#endif /* DUK_USE_HSTRING_EXTDATA && DUK_USE_EXTSTR_INTERN_CHECK */ { duk_uint8_t *data_tmp; /* NUL terminate for convenient C access */ - DUK_ASSERT(sizeof(duk_hstring) + blen + 1 > blen); /* No wrap, limits ensure. */ + DUK_ASSERT(sizeof(duk_hstring) + blen + 1 > blen); /* No wrap, limits ensure. */ res = (duk_hstring *) DUK_ALLOC(heap, sizeof(duk_hstring) + blen + 1); if (DUK_UNLIKELY(res == NULL)) { goto alloc_error; @@ -54655,7 +55705,7 @@ #if defined(DUK_USE_HSTRING_LAZY_CLEN) /* Charlen initialized to 0, updated on-the-fly. */ #else - duk_hstring_init_charlen(res); /* Also sets ASCII flag. */ + duk_hstring_init_charlen(res); /* Also sets ASCII flag. */ #endif } @@ -54668,7 +55718,7 @@ DUK_ASSERT(res != NULL); return res; - alloc_error: +alloc_error: return NULL; } @@ -54697,13 +55747,13 @@ DUK_ASSERT(heap != NULL); DUK_ASSERT(heap->st_resizing == 1); DUK_ASSERT(heap->st_size >= 2); - DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ + DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ DUK_ASSERT(DUK__GET_STRTABLE(heap) != NULL); DUK_STATS_INC(heap, stats_strtab_resize_grow); new_st_size = heap->st_size << 1U; - DUK_ASSERT(new_st_size > heap->st_size); /* No overflow. */ + DUK_ASSERT(new_st_size > heap->st_size); /* No overflow. */ /* Reallocate the strtable first and then work in-place to rehash * strings. We don't need an indirect allocation here: even if GC @@ -54787,7 +55837,7 @@ duk__strtable_assert_checks(heap); #endif } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Shrink strtable allocation in-place. @@ -54815,7 +55865,7 @@ DUK_ASSERT(heap != NULL); DUK_ASSERT(heap->st_resizing == 1); DUK_ASSERT(heap->st_size >= 2); - DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ + DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */ DUK_ASSERT(DUK__GET_STRTABLE(heap) != NULL); DUK_STATS_INC(heap, stats_strtab_resize_shrink); @@ -54873,7 +55923,7 @@ duk__strtable_assert_checks(heap); #endif } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Grow/shrink check. @@ -54881,7 +55931,7 @@ #if defined(DUK__STRTAB_RESIZE_CHECK) DUK_LOCAL DUK_COLD DUK_NOINLINE void duk__strtable_resize_check(duk_heap *heap) { - duk_uint32_t load_factor; /* fixed point */ + duk_uint32_t load_factor; /* fixed point */ DUK_ASSERT(heap != NULL); #if defined(DUK_USE_STRTAB_PTRCOMP) @@ -54905,7 +55955,8 @@ load_factor = heap->st_count / (heap->st_size >> 4U); DUK_DD(DUK_DDPRINT("resize check string table: size=%lu, count=%lu, load_factor=%lu (fixed point .4; float %lf)", - (unsigned long) heap->st_size, (unsigned long) heap->st_count, + (unsigned long) heap->st_size, + (unsigned long) heap->st_count, (unsigned long) load_factor, (double) heap->st_count / (double) heap->st_size)); @@ -54913,7 +55964,9 @@ if (heap->st_size >= DUK_USE_STRTAB_MAXSIZE) { DUK_DD(DUK_DDPRINT("want to grow strtable (based on load factor) but already maximum size")); } else { - DUK_D(DUK_DPRINT("grow string table: %lu -> %lu", (unsigned long) heap->st_size, (unsigned long) heap->st_size * 2)); + DUK_D(DUK_DPRINT("grow string table: %lu -> %lu", + (unsigned long) heap->st_size, + (unsigned long) heap->st_size * 2)); #if defined(DUK_USE_DEBUG) duk_heap_strtable_dump(heap); #endif @@ -54923,7 +55976,9 @@ if (heap->st_size <= DUK_USE_STRTAB_MINSIZE) { DUK_DD(DUK_DDPRINT("want to shrink strtable (based on load factor) but already minimum size")); } else { - DUK_D(DUK_DPRINT("shrink string table: %lu -> %lu", (unsigned long) heap->st_size, (unsigned long) heap->st_size / 2)); + DUK_D(DUK_DPRINT("shrink string table: %lu -> %lu", + (unsigned long) heap->st_size, + (unsigned long) heap->st_size / 2)); #if defined(DUK_USE_DEBUG) duk_heap_strtable_dump(heap); #endif @@ -54935,7 +55990,7 @@ heap->st_resizing = 0; } -#endif /* DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK__STRTAB_RESIZE_CHECK */ /* * Torture grow/shrink: unconditionally grow and shrink back. @@ -54959,7 +56014,7 @@ } heap->st_resizing = 0; } -#endif /* DUK_USE_STRTAB_TORTURE && DUK__STRTAB_RESIZE_CHECK */ +#endif /* DUK_USE_STRTAB_TORTURE && DUK__STRTAB_RESIZE_CHECK */ /* * Raw intern; string already checked not to be present. @@ -54975,8 +56030,12 @@ #endif DUK_DDD(DUK_DDDPRINT("do_intern: heap=%p, str=%p, blen=%lu, strhash=%lx, st_size=%lu, st_count=%lu, load=%lf", - (void *) heap, (const void *) str, (unsigned long) blen, (unsigned long) strhash, - (unsigned long) heap->st_size, (unsigned long) heap->st_count, + (void *) heap, + (const void *) str, + (unsigned long) blen, + (unsigned long) strhash, + (unsigned long) heap->st_size, + (unsigned long) heap->st_count, (double) heap->st_count / (double) heap->st_size)); DUK_ASSERT(heap != NULL); @@ -54992,7 +56051,7 @@ */ heap->pf_prevent_count++; - DUK_ASSERT(heap->pf_prevent_count != 0); /* Wrap. */ + DUK_ASSERT(heap->pf_prevent_count != 0); /* Wrap. */ #if defined(DUK_USE_STRTAB_TORTURE) && defined(DUK__STRTAB_RESIZE_CHECK) duk__strtable_resize_torture(heap); @@ -55019,7 +56078,8 @@ /* External string check (low memory optimization). */ #if defined(DUK_USE_HSTRING_EXTDATA) && defined(DUK_USE_EXTSTR_INTERN_CHECK) - extdata = (const duk_uint8_t *) DUK_USE_EXTSTR_INTERN_CHECK(heap->heap_udata, (void *) DUK_LOSE_CONST(str), (duk_size_t) blen); + extdata = + (const duk_uint8_t *) DUK_USE_EXTSTR_INTERN_CHECK(heap->heap_udata, (void *) DUK_LOSE_CONST(str), (duk_size_t) blen); #else extdata = (const duk_uint8_t *) NULL; #endif @@ -55057,7 +56117,7 @@ #else slot = heap->strtable + (strhash & heap->st_mask); #endif - DUK_ASSERT(res->hdr.h_next == NULL); /* This is the case now, but unnecessary zeroing/NULLing. */ + DUK_ASSERT(res->hdr.h_next == NULL); /* This is the case now, but unnecessary zeroing/NULLing. */ res->hdr.h_next = DUK__HEAPPTR_DEC16(heap, *slot); *slot = DUK__HEAPPTR_ENC16(heap, res); @@ -55104,11 +56164,12 @@ curr = (duk_hstring *) DUK_LOSE_CONST(duk_rom_strings_lookuplookup_hash); while (curr != NULL) { /* Unsafe memcmp() because for zero blen, str may be NULL. */ - if (strhash == DUK_HSTRING_GET_HASH(curr) && - blen == DUK_HSTRING_GET_BYTELEN(curr) && + if (strhash == DUK_HSTRING_GET_HASH(curr) && blen == DUK_HSTRING_GET_BYTELEN(curr) && duk_memcmp_unsafe((const void *) str, (const void *) DUK_HSTRING_GET_DATA(curr), blen) == 0) { DUK_DDD(DUK_DDDPRINT("intern check: rom string: %!O, computed hash 0x%08lx, rom hash 0x%08lx", - curr, (unsigned long) strhash, (unsigned long) DUK_HSTRING_GET_HASH(curr))); + curr, + (unsigned long) strhash, + (unsigned long) DUK_HSTRING_GET_HASH(curr))); return curr; } curr = curr->hdr.h_next; @@ -55116,7 +56177,7 @@ return NULL; } -#endif /* DUK_USE_ROM_STRINGS */ +#endif /* DUK_USE_ROM_STRINGS */ DUK_INTERNAL duk_hstring *duk_heap_strtable_intern(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen) { duk_uint32_t strhash; @@ -55129,7 +56190,7 @@ /* XXX: maybe just require 'str != NULL' even for zero size? */ DUK_ASSERT(heap != NULL); DUK_ASSERT(blen == 0 || str != NULL); - DUK_ASSERT(blen <= DUK_HSTRING_MAX_BYTELEN); /* Caller is responsible for ensuring this. */ + DUK_ASSERT(blen <= DUK_HSTRING_MAX_BYTELEN); /* Caller is responsible for ensuring this. */ strhash = duk_heap_hashstring(heap, str, (duk_size_t) blen); /* String table lookup. */ @@ -55143,8 +56204,7 @@ h = heap->strtablestrhash & heap->st_mask; #endif while (h != NULL) { - if (DUK_HSTRING_GET_HASH(h) == strhash && - DUK_HSTRING_GET_BYTELEN(h) == blen && + if (DUK_HSTRING_GET_HASH(h) == strhash && DUK_HSTRING_GET_BYTELEN(h) == blen && duk_memcmp_unsafe((const void *) str, (const void *) DUK_HSTRING_GET_DATA(h), (size_t) blen) == 0) { /* Found existing entry. */ DUK_STATS_INC(heap, stats_strtab_intern_hit); @@ -55170,7 +56230,7 @@ DUK_STATS_INC(heap, stats_strtab_intern_miss); h = duk__strtable_do_intern(heap, str, blen, strhash); - return h; /* may be NULL */ + return h; /* may be NULL */ } /* @@ -55193,7 +56253,7 @@ p--; *p = duk_lc_digitsval % 10; val = val / 10; - } while (val != 0); /* For val == 0, emit exactly one '0'. */ + } while (val != 0); /* For val == 0, emit exactly one '0'. */ DUK_ASSERT(p >= buf); return duk_heap_strtable_intern(heap, (const duk_uint8_t *) p, (duk_uint32_t) ((buf + sizeof(buf)) - p)); @@ -55231,7 +56291,7 @@ DUK_ASSERT(DUK_IS_POWER_OF_TWO((duk_uint_t) DUK_USE_LITCACHE_SIZE)); key = (duk_uintptr_t) blen ^ (duk_uintptr_t) str; - key &= (duk_uintptr_t) (DUK_USE_LITCACHE_SIZE - 1); /* Assumes size is power of 2. */ + key &= (duk_uintptr_t) (DUK_USE_LITCACHE_SIZE - 1); /* Assumes size is power of 2. */ /* Due to masking, cast is in 32-bit range. */ DUK_ASSERT(key <= DUK_UINT_MAX); return (duk_uint_t) key; @@ -55247,7 +56307,9 @@ ent = thr->heap->litcache + key; if (ent->addr == str) { DUK_DD(DUK_DDPRINT("intern check for cached, pinned literal: str=%p, blen=%ld -> duk_hstring %!O", - (const void *) str, (long) blen, (duk_heaphdr *) ent->h)); + (const void *) str, + (long) blen, + (duk_heaphdr *) ent->h)); DUK_ASSERT(ent->h != NULL); DUK_ASSERT(DUK_HSTRING_HAS_PINNED_LITERAL(ent->h)); DUK_STATS_INC(thr->heap, stats_strtab_litcache_hit); @@ -55277,7 +56339,7 @@ return h; } -#endif /* DUK_USE_LITCACHE_SIZE */ +#endif /* DUK_USE_LITCACHE_SIZE */ DUK_INTERNAL duk_hstring *duk_heap_strtable_intern_u32_checked(duk_hthread *thr, duk_uint32_t val) { duk_hstring *res; @@ -55312,7 +56374,8 @@ duk_hstring *prev; DUK_DDD(DUK_DDDPRINT("remove: heap=%p, h=%p, blen=%lu, strhash=%lx", - (void *) heap, (void *) h, + (void *) heap, + (void *) h, (unsigned long) (h != NULL ? DUK_HSTRING_GET_BYTELEN(h) : 0), (unsigned long) (h != NULL ? DUK_HSTRING_GET_HASH(h) : 0))); @@ -55330,13 +56393,13 @@ slot = heap->strtable + (DUK_HSTRING_GET_HASH(h) & heap->st_mask); #endif other = DUK__HEAPPTR_DEC16(heap, *slot); - DUK_ASSERT(other != NULL); /* At least argument string is in the chain. */ + DUK_ASSERT(other != NULL); /* At least argument string is in the chain. */ prev = NULL; while (other != h) { prev = other; other = other->hdr.h_next; - DUK_ASSERT(other != NULL); /* We'll eventually find 'h'. */ + DUK_ASSERT(other != NULL); /* We'll eventually find 'h'. */ } if (prev != NULL) { /* Middle of list. */ @@ -55350,7 +56413,7 @@ * intern will do one. */ } -#endif /* DUK_USE_REFERENCE_COUNTING */ +#endif /* DUK_USE_REFERENCE_COUNTING */ /* Unlink with a 'prev' pointer. */ DUK_INTERNAL void duk_heap_strtable_unlink_prev(duk_heap *heap, duk_hstring *h, duk_hstring *prev) { @@ -55361,7 +56424,9 @@ #endif DUK_DDD(DUK_DDDPRINT("remove: heap=%p, prev=%p, h=%p, blen=%lu, strhash=%lx", - (void *) heap, (void *) prev, (void *) h, + (void *) heap, + (void *) prev, + (void *) h, (unsigned long) (h != NULL ? DUK_HSTRING_GET_BYTELEN(h) : 0), (unsigned long) (h != NULL ? DUK_HSTRING_GET_HASH(h) : 0))); @@ -55540,7 +56605,7 @@ } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ #line 1 "duk_hobject_alloc.c" /* * Hobject allocation. @@ -55565,7 +56630,7 @@ /* Zeroed by caller. */ obj->hdr.h_flags = hobject_flags | DUK_HTYPE_OBJECT; - DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(&obj->hdr) == DUK_HTYPE_OBJECT); /* Assume zero shift. */ + DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(&obj->hdr) == DUK_HTYPE_OBJECT); /* Assume zero shift. */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) DUK_HOBJECT_SET_PROTOTYPE(heap, obj, NULL); @@ -55701,7 +56766,7 @@ DUK_HBUFOBJ_ASSERT_VALID(res); return res; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Allocate a new thread. * @@ -55824,20 +56889,18 @@ DUK_INTERNAL void duk_hobject_assert_valid(duk_hobject *h) { DUK_ASSERT(h != NULL); - DUK_ASSERT(!DUK_HOBJECT_IS_CALLABLE(h) || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FUNCTION); - DUK_ASSERT(!DUK_HOBJECT_IS_BUFOBJ(h) || - (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAYBUFFER || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_DATAVIEW || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT8ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT16ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT16ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT32ARRAY || - DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT64ARRAY)); + DUK_ASSERT(!DUK_HOBJECT_IS_CALLABLE(h) || DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FUNCTION); + DUK_ASSERT(!DUK_HOBJECT_IS_BUFOBJ(h) || (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAYBUFFER || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_DATAVIEW || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT8ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT8CLAMPEDARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT16ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT16ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_INT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_UINT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT32ARRAY || + DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_FLOAT64ARRAY)); /* Object is an Array <=> object has exotic array behavior */ DUK_ASSERT((DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_ARRAY && DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)) || (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_ARRAY && !DUK_HOBJECT_HAS_EXOTIC_ARRAY(h))); @@ -55853,8 +56916,7 @@ DUK_ASSERT(h != NULL); DUK_ASSERT(DUK_HOBJECT_IS_BOUNDFUNC((duk_hobject *) h)); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(&h->target) || - (DUK_TVAL_IS_OBJECT(&h->target) && - DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(&h->target)))); + (DUK_TVAL_IS_OBJECT(&h->target) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(&h->target)))); DUK_ASSERT(!DUK_TVAL_IS_UNUSED(&h->this_binding)); DUK_ASSERT(h->nargs == 0 || h->args != NULL); } @@ -55886,7 +56948,7 @@ DUK_ASSERT(h->offset + h->length >= h->offset); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_INTERNAL void duk_hcompfunc_assert_valid(duk_hcompfunc *h) { DUK_ASSERT(h != NULL); @@ -55940,7 +57002,7 @@ DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ #line 1 "duk_hobject_enum.c" /* * Object enumeration support. @@ -55968,7 +57030,7 @@ /* First enumerated key index in enumerator object, must match exactly the * number of control properties inserted to the enumerator. */ -#define DUK__ENUM_START_INDEX 2 +#define DUK__ENUM_START_INDEX 2 /* Current implementation suffices for ES2015 for now because there's no symbol * sorting, so commented out for now. @@ -56037,7 +57099,7 @@ DUK_ASSERT(a != NULL); DUK_ASSERT(b != NULL); - DUK_UNREF(b); /* Not actually needed now, val_b suffices. */ + DUK_UNREF(b); /* Not actually needed now, val_b suffices. */ val_a = duk__hstring_sort_key(a); @@ -56058,7 +57120,7 @@ DUK_UNREF(thr); if (idx_end <= idx_start + 1) { - return; /* Zero or one element(s). */ + return; /* Zero or one element(s). */ } keys = DUK_HOBJECT_E_GET_KEY_BASE(thr->heap, h_obj); @@ -56076,7 +57138,7 @@ * (and optimized for) case. */ - val_curr = duk__hstring_sort_key(h_curr); /* Remains same during scanning. */ + val_curr = duk__hstring_sort_key(h_curr); /* Remains same during scanning. */ for (idx_insert = idx - 1; idx_insert >= idx_start; idx_insert--) { duk_hstring *h_insert; h_insert = keysidx_insert; @@ -56149,7 +57211,7 @@ duk_hobject *h_proxy_handler; duk_hobject *h_trap_result; #endif - duk_uint_fast32_t i, len; /* used for array, stack, and entry indices */ + duk_uint_fast32_t i, len; /* used for array, stack, and entry indices */ duk_uint_fast32_t sort_start_index; DUK_ASSERT(thr != NULL); @@ -56168,11 +57230,11 @@ * real object to check against. */ duk_push_hobject(thr, enum_target); - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ /* Initialize index so that we skip internal control keys. */ duk_push_int(thr, DUK__ENUM_START_INDEX); - duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_NEXT); /* Target is bare, plain put OK. */ + duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_INT_NEXT); /* Target is bare, plain put OK. */ /* * Proxy object handling @@ -56182,9 +57244,7 @@ if (DUK_LIKELY((enum_flags & DUK_ENUM_NO_PROXY_BEHAVIOR) != 0)) { goto skip_proxy; } - if (DUK_LIKELY(!duk_hobject_proxy_check(enum_target, - &h_proxy_target, - &h_proxy_handler))) { + if (DUK_LIKELY(!duk_hobject_proxy_check(enum_target, &h_proxy_target, &h_proxy_handler))) { goto skip_proxy; } @@ -56205,17 +57265,17 @@ DUK_DDD(DUK_DDDPRINT("h_proxy_target=%!O", (duk_heaphdr *) h_proxy_target)); enum_target = h_proxy_target; - duk_push_hobject(thr, enum_target); /* -> ... enum_target res handler undefined target */ - duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ + duk_push_hobject(thr, enum_target); /* -> ... enum_target res handler undefined target */ + duk_put_prop_stridx_short(thr, -4, DUK_STRIDX_INT_TARGET); /* Target is bare, plain put OK. */ - duk_pop_2(thr); /* -> ... enum_target res */ + duk_pop_2(thr); /* -> ... enum_target res */ goto skip_proxy; } /* ... enum_target res handler trap */ duk_insert(thr, -2); - duk_push_hobject(thr, h_proxy_target); /* -> ... enum_target res trap handler target */ - duk_call_method(thr, 1 /*nargs*/); /* -> ... enum_target res trap_result */ + duk_push_hobject(thr, h_proxy_target); /* -> ... enum_target res trap handler target */ + duk_call_method(thr, 1 /*nargs*/); /* -> ... enum_target res trap_result */ h_trap_result = duk_require_hobject(thr, -1); DUK_UNREF(h_trap_result); @@ -56228,7 +57288,7 @@ len = (duk_uint_fast32_t) duk_get_length(thr, -1); for (i = 0; i < len; i++) { (void) duk_get_prop_index(thr, -1, (duk_uarridx_t) i); - DUK_ASSERT(duk_is_string(thr, -1)); /* postprocess cleaned up */ + DUK_ASSERT(duk_is_string(thr, -1)); /* postprocess cleaned up */ /* ... enum_target res trap_result keys_array val */ duk_push_true(thr); /* ... enum_target res trap_result keys_array val true */ @@ -56249,8 +57309,8 @@ DUK_DDD(DUK_DDDPRINT("proxy enumeration, final res: %!O", (duk_heaphdr *) res)); goto compact_and_return; - skip_proxy: -#endif /* DUK_USE_ES6_PROXY */ +skip_proxy: +#endif /* DUK_USE_ES6_PROXY */ curr = enum_target; sort_start_index = DUK__ENUM_START_INDEX; @@ -56301,7 +57361,7 @@ if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(curr)) { duk_hstring *h_val; h_val = duk_hobject_get_internal_value_string(thr->heap, curr); - DUK_ASSERT(h_val != NULL); /* string objects must not created without internal value */ + DUK_ASSERT(h_val != NULL); /* string objects must not created without internal value */ len = (duk_uint_fast32_t) DUK_HSTRING_GET_CHARLEN(h_val); } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -56324,7 +57384,7 @@ len = (duk_uint_fast32_t) (h_bufobj->length >> h_bufobj->shift); } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ for (i = 0; i < len; i++) { duk_hstring *k; @@ -56364,7 +57424,7 @@ if (DUK_TVAL_IS_UNUSED(tv)) { continue; } - k = duk_heap_strtable_intern_u32_checked(thr, (duk_uint32_t) i); /* Fragile reachability. */ + k = duk_heap_strtable_intern_u32_checked(thr, (duk_uint32_t) i); /* Fragile reachability. */ DUK_ASSERT(k); duk__add_enum_key(thr, k); @@ -56396,8 +57456,7 @@ continue; } if (DUK_UNLIKELY(DUK_HSTRING_HAS_SYMBOL(k))) { - if (!(enum_flags & DUK_ENUM_INCLUDE_HIDDEN) && - DUK_HSTRING_HAS_HIDDEN(k)) { + if (!(enum_flags & DUK_ENUM_INCLUDE_HIDDEN) && DUK_HSTRING_HAS_HIDDEN(k)) { continue; } if (!(enum_flags & DUK_ENUM_INCLUDE_SYMBOLS)) { @@ -56407,7 +57466,7 @@ need_sort = 1; #endif } else { - DUK_ASSERT(!DUK_HSTRING_HAS_HIDDEN(k)); /* would also have symbol flag */ + DUK_ASSERT(!DUK_HSTRING_HAS_HIDDEN(k)); /* would also have symbol flag */ if (enum_flags & DUK_ENUM_EXCLUDE_STRINGS) { continue; } @@ -56456,7 +57515,10 @@ #else if (need_sort) { DUK_DDD(DUK_DDDPRINT("need to sort")); - duk__sort_enum_keys_es6(thr, res, (duk_int_fast32_t) sort_start_index, (duk_int_fast32_t) sort_end_index); + duk__sort_enum_keys_es6(thr, + res, + (duk_int_fast32_t) sort_start_index, + (duk_int_fast32_t) sort_end_index); } else { DUK_DDD(DUK_DDDPRINT("no need to sort")); } @@ -56489,11 +57551,14 @@ /* Sort to ES2015 order which works for pure array incides but * also for mixed keys. */ - duk__sort_enum_keys_es6(thr, res, (duk_int_fast32_t) DUK__ENUM_START_INDEX, (duk_int_fast32_t) DUK_HOBJECT_GET_ENEXT(res)); + duk__sort_enum_keys_es6(thr, + res, + (duk_int_fast32_t) DUK__ENUM_START_INDEX, + (duk_int_fast32_t) DUK_HOBJECT_GET_ENEXT(res)); } #if defined(DUK_USE_ES6_PROXY) - compact_and_return: +compact_and_return: #endif /* compact; no need to seal because object is internal */ duk_hobject_compact_props(thr, res); @@ -56541,10 +57606,11 @@ #else check_existence = 1; #endif - duk_pop(thr); /* still reachable */ + duk_pop(thr); /* still reachable */ DUK_DDD(DUK_DDDPRINT("getting next enum value, enum_target=%!iO, enumerator=%!iT", - (duk_heaphdr *) enum_target, (duk_tval *) duk_get_tval(thr, -1))); + (duk_heaphdr *) enum_target, + (duk_tval *) duk_get_tval(thr, -1))); /* no array part */ for (;;) { @@ -56585,16 +57651,16 @@ duk_push_hstring(thr, res); if (get_value) { duk_push_hobject(thr, enum_target); - duk_dup_m2(thr); /* -> ... enum key enum_target key */ + duk_dup_m2(thr); /* -> ... enum key enum_target key */ duk_get_prop(thr, -2); /* -> ... enum key enum_target val */ - duk_remove_m2(thr); /* -> ... enum key val */ - duk_remove(thr, -3); /* -> ... key val */ + duk_remove_m2(thr); /* -> ... enum key val */ + duk_remove(thr, -3); /* -> ... key val */ } else { - duk_remove_m2(thr); /* -> ... key */ + duk_remove_m2(thr); /* -> ... key */ } return 1; } else { - duk_pop(thr); /* -> ... */ + duk_pop(thr); /* -> ... */ return 0; } } @@ -56641,7 +57707,7 @@ duk_hstring *k; k = *keys++; - DUK_ASSERT(k != NULL); /* enumerator must have no keys deleted */ + DUK_ASSERT(k != NULL); /* enumerator must have no keys deleted */ DUK_TVAL_SET_STRING(tv, k); tv++; @@ -56653,7 +57719,7 @@ /* enum_target res */ - return 1; /* return 1 to allow callers to tail call */ + return 1; /* return 1 to allow callers to tail call */ } /* automatic undefs */ @@ -56665,7 +57731,10 @@ /* #include duk_internal.h -> already included */ -DUK_INTERNAL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop) { +DUK_INTERNAL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, + duk_hobject *h, + duk_hobject *p, + duk_bool_t ignore_loop) { duk_uint_t sanity; DUK_ASSERT(thr != NULL); @@ -56704,7 +57773,7 @@ DUK_ASSERT(h); tmp = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, h, p); - DUK_HOBJECT_INCREF_ALLOWNULL(thr, p); /* avoid problems if p == h->prototype */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, p); /* avoid problems if p == h->prototype */ DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); #else DUK_ASSERT(h); @@ -56750,7 +57819,7 @@ hdr = (duk_uint32_t *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, h_buf); DUK_ASSERT(hdr != NULL); - hdr0 = (duk_uint32_t) length; /* valid pc range is 0, length */ + hdr0 = (duk_uint32_t) length; /* valid pc range is 0, length */ curr_pc = 0U; while (curr_pc < length) { @@ -56779,8 +57848,8 @@ for (;;) { curr_pc++; - if ( ((curr_pc % DUK_PC2LINE_SKIP) == 0) || /* end of diff run */ - (curr_pc >= length) ) { /* end of bytecode */ + if (((curr_pc % DUK_PC2LINE_SKIP) == 0) || /* end of diff run */ + (curr_pc >= length)) { /* end of bytecode */ break; } DUK_ASSERT(curr_pc < length); @@ -56827,7 +57896,9 @@ (void) duk_to_fixed_buffer(thr, -1, NULL); DUK_DDD(DUK_DDDPRINT("final pc2line data: pc_limit=%ld, length=%ld, %lf bits/opcode --> %!ixT", - (long) length, (long) new_size, (double) new_size * 8.0 / (double) length, + (long) length, + (long) new_size, + (double) new_size * 8.0 / (double) length, (duk_tval *) duk_get_tval(thr, -1))); } @@ -56867,8 +57938,7 @@ pc_limit = hdr0; if (pc >= pc_limit) { /* Note: pc is unsigned and cannot be negative */ - DUK_DD(DUK_DDPRINT("pc2line lookup failed: pc out of bounds (pc=%ld, limit=%ld)", - (long) pc, (long) pc_limit)); + DUK_DD(DUK_DDPRINT("pc2line lookup failed: pc out of bounds (pc=%ld, limit=%ld)", (long) pc, (long) pc_limit)); goto pc2line_error; } @@ -56876,7 +57946,8 @@ start_offset = hdr1 + hdr_index * 2 + 1; if ((duk_size_t) start_offset > DUK_HBUFFER_FIXED_GET_SIZE(buf)) { DUK_DD(DUK_DDPRINT("pc2line lookup failed: start_offset out of bounds (start_offset=%ld, buffer_size=%ld)", - (long) start_offset, (long) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) buf))); + (long) start_offset, + (long) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) buf))); goto pc2line_error; } @@ -56903,7 +57974,7 @@ if (duk_bd_decode_flag(bd_ctx)) { /* 1 1 1 <32 bits> */ duk_uint_fast32_t t; - t = duk_bd_decode(bd_ctx, 16); /* workaround: max nbits = 24 now */ + t = duk_bd_decode(bd_ctx, 16); /* workaround: max nbits = 24 now */ t = (t << 16) + duk_bd_decode(bd_ctx, 16); curr_line = t; } else { @@ -56928,7 +57999,7 @@ DUK_DDD(DUK_DDDPRINT("pc2line lookup result: pc %ld -> line %ld", (long) pc, (long) curr_line)); return curr_line; - pc2line_error: +pc2line_error: DUK_D(DUK_DPRINT("pc2line conversion failed for pc=%ld", (long) pc)); return 0; } @@ -56956,7 +58027,7 @@ return line; } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ #line 1 "duk_hobject_props.c" /* * duk_hobject property access functionality. @@ -57006,35 +58077,56 @@ * Local defines */ -#define DUK__NO_ARRAY_INDEX DUK_HSTRING_NO_ARRAY_INDEX +#define DUK__NO_ARRAY_INDEX DUK_HSTRING_NO_ARRAY_INDEX /* Marker values for hash part. */ -#define DUK__HASH_UNUSED DUK_HOBJECT_HASHIDX_UNUSED -#define DUK__HASH_DELETED DUK_HOBJECT_HASHIDX_DELETED +#define DUK__HASH_UNUSED DUK_HOBJECT_HASHIDX_UNUSED +#define DUK__HASH_DELETED DUK_HOBJECT_HASHIDX_DELETED /* Valstack space that suffices for all local calls, excluding any recursion * into ECMAScript or Duktape/C calls (Proxy, getters, etc). */ -#define DUK__VALSTACK_SPACE 10 +#define DUK__VALSTACK_SPACE 10 /* Valstack space allocated especially for proxy lookup which does a * recursive property lookup. */ -#define DUK__VALSTACK_PROXY_LOOKUP 20 +#define DUK__VALSTACK_PROXY_LOOKUP 20 /* * Local prototypes */ -DUK_LOCAL_DECL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc); -DUK_LOCAL_DECL void duk__check_arguments_map_for_put(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc, duk_bool_t throw_flag); -DUK_LOCAL_DECL void duk__check_arguments_map_for_delete(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc); - -DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length_smaller(duk_hthread *thr, duk_hobject *obj, duk_uint32_t old_len, duk_uint32_t new_len, duk_bool_t force_flag, duk_uint32_t *out_result_len); +DUK_LOCAL_DECL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc); +DUK_LOCAL_DECL void duk__check_arguments_map_for_put(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc, + duk_bool_t throw_flag); +DUK_LOCAL_DECL void duk__check_arguments_map_for_delete(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc); + +DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length_smaller(duk_hthread *thr, + duk_hobject *obj, + duk_uint32_t old_len, + duk_uint32_t new_len, + duk_bool_t force_flag, + duk_uint32_t *out_result_len); DUK_LOCAL_DECL duk_bool_t duk__handle_put_array_length(duk_hthread *thr, duk_hobject *obj); -DUK_LOCAL_DECL duk_bool_t duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); -DUK_LOCAL_DECL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_uint32_t arr_idx, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_LOCAL_DECL duk_bool_t +duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags); +DUK_LOCAL_DECL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_uint32_t arr_idx, + duk_propdesc *out_desc, + duk_small_uint_t flags); DUK_LOCAL_DECL void duk__abandon_array_part(duk_hthread *thr, duk_hobject *obj); DUK_LOCAL_DECL void duk__grow_props_for_array_item(duk_hthread *thr, duk_hobject *obj, duk_uint32_t highest_arr_idx); @@ -57063,7 +58155,7 @@ dbl = DUK_TVAL_GET_NUMBER(tv); idx = (duk_uint32_t) dbl; if (duk_double_equals((duk_double_t) idx, dbl)) { - /* Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF, + /* Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF, * it's not a valid array index but will then match DUK__NO_ARRAY_INDEX. */ return idx; @@ -57090,7 +58182,7 @@ */ return (duk_uint32_t) t; } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* Convert a duk_tval on the value stack (in a trusted index we don't validate) * to a string or symbol using ES2015 ToPropertyKey(): @@ -57115,7 +58207,7 @@ * but still be compliant and share code. */ - tv_dst = DUK_GET_TVAL_NEGIDX(thr, idx); /* intentionally unvalidated */ + tv_dst = DUK_GET_TVAL_NEGIDX(thr, idx); /* intentionally unvalidated */ if (DUK_TVAL_IS_STRING(tv_dst)) { /* Most important path: strings and plain symbols are used as * is. For symbols the array index check below is unnecessary @@ -57135,7 +58227,7 @@ } DUK_LOCAL duk_uint32_t duk__push_tval_to_property_key(duk_hthread *thr, duk_tval *tv_key, duk_hstring **out_h) { - duk_push_tval(thr, tv_key); /* XXX: could use an unsafe push here */ + duk_push_tval(thr, tv_key); /* XXX: could use an unsafe push here */ return duk__to_property_key(thr, -1, out_h); } @@ -57175,7 +58267,7 @@ * is relatively sparse. */ tmp = e_size; - res = 2; /* Result will be 2 ** (N + 1). */ + res = 2; /* Result will be 2 ** (N + 1). */ while (tmp >= 0x40) { tmp >>= 6; res <<= 6; @@ -57184,21 +58276,21 @@ tmp >>= 1; res <<= 1; } - DUK_ASSERT((DUK_HOBJECT_MAX_PROPERTIES << 2U) > DUK_HOBJECT_MAX_PROPERTIES); /* Won't wrap, even shifted by 2. */ + DUK_ASSERT((DUK_HOBJECT_MAX_PROPERTIES << 2U) > DUK_HOBJECT_MAX_PROPERTIES); /* Won't wrap, even shifted by 2. */ DUK_ASSERT(res > e_size); return res; } else { return 0; } } -#endif /* USE_PROP_HASH_PART */ +#endif /* USE_PROP_HASH_PART */ /* Get minimum entry part growth for a certain size. */ DUK_LOCAL duk_uint32_t duk__get_min_grow_e(duk_uint32_t e_size) { duk_uint32_t res; res = (e_size + DUK_USE_HOBJECT_ENTRY_MINGROW_ADD) / DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR; - DUK_ASSERT(res >= 1); /* important for callers */ + DUK_ASSERT(res >= 1); /* important for callers */ return res; } @@ -57207,7 +58299,7 @@ duk_uint32_t res; res = (a_size + DUK_USE_HOBJECT_ARRAY_MINGROW_ADD) / DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR; - DUK_ASSERT(res >= 1); /* important for callers */ + DUK_ASSERT(res >= 1); /* important for callers */ return res; } @@ -57237,7 +58329,7 @@ DUK_LOCAL void duk__compute_a_stats(duk_hthread *thr, duk_hobject *obj, duk_uint32_t *out_used, duk_uint32_t *out_min_size) { duk_uint_fast32_t i; duk_uint_fast32_t used = 0; - duk_uint_fast32_t highest_idx = (duk_uint_fast32_t) -1; /* see below */ + duk_uint_fast32_t highest_idx = (duk_uint_fast32_t) -1; /* see below */ duk_tval *a; DUK_ASSERT(obj != NULL); @@ -57260,7 +58352,7 @@ */ *out_used = (duk_uint32_t) used; - *out_min_size = (duk_uint32_t) (highest_idx + 1); /* 0 if no used entries */ + *out_min_size = (duk_uint32_t) (highest_idx + 1); /* 0 if no used entries */ } /* Check array density and indicate whether or not the array part should be abandoned. */ @@ -57327,7 +58419,9 @@ duk__compute_a_stats(thr, obj, &old_used, &old_size); DUK_DDD(DUK_DDDPRINT("abandon check, array stats: old_used=%ld, old_size=%ld, arr_idx=%ld", - (long) old_used, (long) old_size, (long) arr_idx)); + (long) old_used, + (long) old_size, + (long) arr_idx)); min_size = arr_idx + 1; #if defined(DUK_USE_OBJSIZES16) @@ -57355,7 +58449,7 @@ DUK_DDD(DUK_DDDPRINT("=> decided to keep array part")); return 0; - do_abandon: +do_abandon: duk__abandon_array_part(thr, obj); DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(obj)); return 1; @@ -57382,7 +58476,8 @@ DUK_DDD(DUK_DDDPRINT("write to new array requires array resize, decide whether to do a " "fast resize without abandon check (arr_idx=%ld, old_size=%ld)", - (long) arr_idx, (long) DUK_HOBJECT_GET_ASIZE(obj))); + (long) arr_idx, + (long) DUK_HOBJECT_GET_ASIZE(obj))); if (DUK_UNLIKELY(duk__abandon_array_check(thr, arr_idx, obj) != 0)) { DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(obj)); @@ -57441,7 +58536,7 @@ return 1; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* Get Proxy target object. If the argument is not a Proxy, return it as is. * If a Proxy is revoked, an error is thrown. @@ -57467,10 +58562,14 @@ DUK_ASSERT(obj != NULL); return obj; } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ #if defined(DUK_USE_ES6_PROXY) -DUK_LOCAL duk_bool_t duk__proxy_check_prop(duk_hthread *thr, duk_hobject *obj, duk_small_uint_t stridx_trap, duk_tval *tv_key, duk_hobject **out_target) { +DUK_LOCAL duk_bool_t duk__proxy_check_prop(duk_hthread *thr, + duk_hobject *obj, + duk_small_uint_t stridx_trap, + duk_tval *tv_key, + duk_hobject **out_target) { duk_hobject *h_handler; DUK_ASSERT(thr != NULL); @@ -57524,7 +58623,7 @@ duk_push_hobject(thr, h_handler); if (duk_get_prop_stridx_short(thr, -1, stridx_trap)) { /* -> ... handler trap */ - duk_insert(thr, -2); /* -> ... trap handler */ + duk_insert(thr, -2); /* -> ... trap handler */ /* stack prepped for func call: ... trap handler */ return 1; @@ -57533,7 +58632,7 @@ return 0; } } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* * Reallocate property allocation, moving properties to the new allocation. @@ -57588,11 +58687,12 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(obj != NULL); - DUK_ASSERT(!abandon_array || new_a_size == 0); /* if abandon_array, new_a_size must be 0 */ - DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || (DUK_HOBJECT_GET_ESIZE(obj) == 0 && DUK_HOBJECT_GET_ASIZE(obj) == 0)); - DUK_ASSERT(new_h_size == 0 || new_h_size >= new_e_size); /* required to guarantee success of rehashing, - * intentionally use unadjusted new_e_size - */ + DUK_ASSERT(!abandon_array || new_a_size == 0); /* if abandon_array, new_a_size must be 0 */ + DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || + (DUK_HOBJECT_GET_ESIZE(obj) == 0 && DUK_HOBJECT_GET_ASIZE(obj) == 0)); + DUK_ASSERT(new_h_size == 0 || new_h_size >= new_e_size); /* required to guarantee success of rehashing, + * intentionally use unadjusted new_e_size + */ DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); @@ -57622,10 +58722,12 @@ DUK_DDD(DUK_DDDPRINT("using layout 1, but no need to pad e_size: %ld", (long) new_e_size)); new_e_size_adjusted = new_e_size; #elif defined(DUK_USE_HOBJECT_LAYOUT_1) && ((DUK_HOBJECT_ALIGN_TARGET == 4) || (DUK_HOBJECT_ALIGN_TARGET == 8)) - new_e_size_adjusted = (new_e_size + (duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U) & - (~((duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U)); + new_e_size_adjusted = + (new_e_size + (duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U) & (~((duk_uint32_t) DUK_HOBJECT_ALIGN_TARGET - 1U)); DUK_DDD(DUK_DDDPRINT("using layout 1, and alignment target is %ld, adjusted e_size: %ld -> %ld", - (long) DUK_HOBJECT_ALIGN_TARGET, (long) new_e_size, (long) new_e_size_adjusted)); + (long) DUK_HOBJECT_ALIGN_TARGET, + (long) new_e_size, + (long) new_e_size_adjusted)); DUK_ASSERT(new_e_size_adjusted >= new_e_size); #else #error invalid hobject layout defines @@ -57635,23 +58737,22 @@ * Debug logging after adjustment. */ - DUK_DDD(DUK_DDDPRINT("attempt to resize hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " - "{e_size=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", - (void *) obj, - (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)), - (long) DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size), - (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), - (long) DUK_HOBJECT_GET_ESIZE(obj), - (long) DUK_HOBJECT_GET_ENEXT(obj), - (long) DUK_HOBJECT_GET_ASIZE(obj), - (long) DUK_HOBJECT_GET_HSIZE(obj), - (long) new_e_size_adjusted, - (long) new_a_size, - (long) new_h_size, - (long) abandon_array, - (long) new_e_size)); + DUK_DDD(DUK_DDDPRINT( + "attempt to resize hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " + "{e_size=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", + (void *) obj, + (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)), + (long) DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size), + (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), + (long) DUK_HOBJECT_GET_ESIZE(obj), + (long) DUK_HOBJECT_GET_ENEXT(obj), + (long) DUK_HOBJECT_GET_ASIZE(obj), + (long) DUK_HOBJECT_GET_HSIZE(obj), + (long) new_e_size_adjusted, + (long) new_a_size, + (long) new_h_size, + (long) abandon_array, + (long) new_e_size)); /* * Property count check. This is the only point where we ensure that @@ -57694,9 +58795,9 @@ #endif prev_ms_base_flags = thr->heap->ms_base_flags; thr->heap->ms_base_flags |= - DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact the current object (all objects really). */ - thr->heap->pf_prevent_count++; /* Avoid finalizers. */ - DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ + DUK_MS_FLAG_NO_OBJECT_COMPACTION; /* Avoid attempt to compact the current object (all objects really). */ + thr->heap->pf_prevent_count++; /* Avoid finalizers. */ + DUK_ASSERT(thr->heap->pf_prevent_count != 0); /* Wrap. */ new_alloc_size = DUK_HOBJECT_P_COMPUTE_SIZE(new_e_size_adjusted, new_a_size, new_h_size); DUK_DDD(DUK_DDDPRINT("new hobject allocation size is %ld", (long) new_alloc_size)); @@ -57709,7 +58810,7 @@ /* Alloc may trigger mark-and-sweep but no compaction, and * cannot throw. */ -#if 0 /* XXX: inject test */ +#if 0 /* XXX: inject test */ if (1) { new_p = NULL; goto alloc_failed; @@ -57727,19 +58828,28 @@ /* Set up pointers to the new property area: this is hidden behind a macro * because it is memory layout specific. */ - DUK_HOBJECT_P_SET_REALLOC_PTRS(new_p, new_e_k, new_e_pv, new_e_f, new_a, new_h, - new_e_size_adjusted, new_a_size, new_h_size); - DUK_UNREF(new_h); /* happens when hash part dropped */ + DUK_HOBJECT_P_SET_REALLOC_PTRS(new_p, + new_e_k, + new_e_pv, + new_e_f, + new_a, + new_h, + new_e_size_adjusted, + new_a_size, + new_h_size); + DUK_UNREF(new_h); /* happens when hash part dropped */ new_e_next = 0; /* if new_p == NULL, all of these pointers are NULL */ - DUK_ASSERT((new_p != NULL) || - (new_e_k == NULL && new_e_pv == NULL && new_e_f == NULL && - new_a == NULL && new_h == NULL)); + DUK_ASSERT((new_p != NULL) || (new_e_k == NULL && new_e_pv == NULL && new_e_f == NULL && new_a == NULL && new_h == NULL)); DUK_DDD(DUK_DDDPRINT("new alloc size %ld, new_e_k=%p, new_e_pv=%p, new_e_f=%p, new_a=%p, new_h=%p", - (long) new_alloc_size, (void *) new_e_k, (void *) new_e_pv, (void *) new_e_f, - (void *) new_a, (void *) new_h)); + (long) new_alloc_size, + (void *) new_e_k, + (void *) new_e_pv, + (void *) new_e_f, + (void *) new_a, + (void *) new_h)); /* * Migrate array part to start of entries if requested. @@ -57780,8 +58890,7 @@ continue; } - DUK_ASSERT(new_p != NULL && new_e_k != NULL && - new_e_pv != NULL && new_e_f != NULL); + DUK_ASSERT(new_p != NULL && new_e_k != NULL && new_e_pv != NULL && new_e_f != NULL); /* * Intern key via the valstack to ensure reachability behaves @@ -57793,7 +58902,7 @@ * must be careful. */ -#if 0 /* XXX: inject test */ +#if 0 /* XXX: inject test */ if (1) { goto abandon_error; } @@ -57809,7 +58918,7 @@ if (key == NULL) { goto abandon_error; } - duk_push_hstring(thr, key); /* keep key reachable for GC etc; guaranteed not to fail */ + duk_push_hstring(thr, key); /* keep key reachable for GC etc; guaranteed not to fail */ /* Key is now reachable in the valstack, don't INCREF * the new allocation yet (we'll steal the refcounts @@ -57817,11 +58926,10 @@ */ new_e_knew_e_next = key; - tv2 = &new_e_pvnew_e_next.v; /* array entries are all plain values */ + tv2 = &new_e_pvnew_e_next.v; /* array entries are all plain values */ DUK_TVAL_SET_TVAL(tv2, tv1); - new_e_fnew_e_next = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE | - DUK_PROPDESC_FLAG_CONFIGURABLE; + new_e_fnew_e_next = + DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_PROPDESC_FLAG_CONFIGURABLE; new_e_next++; /* Note: new_e_next matches pushed temp key count, and nothing can @@ -57848,8 +58956,7 @@ continue; } - DUK_ASSERT(new_p != NULL && new_e_k != NULL && - new_e_pv != NULL && new_e_f != NULL); + DUK_ASSERT(new_p != NULL && new_e_k != NULL && new_e_pv != NULL && new_e_f != NULL); new_e_knew_e_next = key; new_e_pvnew_e_next = DUK_HOBJECT_E_GET_VALUE(thr->heap, obj, i); @@ -57883,9 +58990,7 @@ DUK_ASSERT(new_a != NULL || array_copy_size == 0U); DUK_ASSERT(DUK_HOBJECT_GET_PROPS(thr->heap, obj) != NULL || array_copy_size == 0U); DUK_ASSERT(DUK_HOBJECT_GET_ASIZE(obj) > 0 || array_copy_size == 0U); - duk_memcpy_unsafe((void *) new_a, - (const void *) DUK_HOBJECT_A_GET_BASE(thr->heap, obj), - array_copy_size); + duk_memcpy_unsafe((void *) new_a, (const void *) DUK_HOBJECT_A_GET_BASE(thr->heap, obj), array_copy_size); for (i = DUK_HOBJECT_GET_ASIZE(obj); i < new_a_size; i++) { duk_tval *tv = &new_ai; @@ -57913,7 +59018,7 @@ DUK_ASSERT(new_h_size > 0); duk_memset(new_h, 0xff, sizeof(duk_uint32_t) * new_h_size); - DUK_ASSERT(new_e_next <= new_h_size); /* equality not actually possible */ + DUK_ASSERT(new_e_next <= new_h_size); /* equality not actually possible */ mask = new_h_size - 1; for (i = 0; i < new_e_next; i++) { @@ -57922,10 +59027,10 @@ DUK_ASSERT(key != NULL); j = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { - DUK_ASSERT(new_hj != DUK__HASH_DELETED); /* should never happen */ + DUK_ASSERT(new_hj != DUK__HASH_DELETED); /* should never happen */ if (new_hj == DUK__HASH_UNUSED) { DUK_DDD(DUK_DDDPRINT("rebuild hit %ld -> %ld", (long) j, (long) i)); new_hj = (duk_uint32_t) i; @@ -57938,37 +59043,36 @@ } } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* * Nice debug log. */ - DUK_DD(DUK_DDPRINT("resized hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " - "{p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", - (void *) obj, - (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), - DUK_HOBJECT_GET_ASIZE(obj), - DUK_HOBJECT_GET_HSIZE(obj)), - (long) new_alloc_size, - (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), - (long) DUK_HOBJECT_GET_ESIZE(obj), - (long) DUK_HOBJECT_GET_ENEXT(obj), - (long) DUK_HOBJECT_GET_ASIZE(obj), - (long) DUK_HOBJECT_GET_HSIZE(obj), - (void *) new_p, - (long) new_e_size_adjusted, - (long) new_e_next, - (long) new_a_size, - (long) new_h_size, - (long) abandon_array, - (long) new_e_size)); + DUK_DD(DUK_DDPRINT( + "resized hobject %p props (%ld -> %ld bytes), from {p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld} to " + "{p=%p,e_size=%ld,e_next=%ld,a_size=%ld,h_size=%ld}, abandon_array=%ld, unadjusted new_e_size=%ld", + (void *) obj, + (long) DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj), DUK_HOBJECT_GET_ASIZE(obj), DUK_HOBJECT_GET_HSIZE(obj)), + (long) new_alloc_size, + (void *) DUK_HOBJECT_GET_PROPS(thr->heap, obj), + (long) DUK_HOBJECT_GET_ESIZE(obj), + (long) DUK_HOBJECT_GET_ENEXT(obj), + (long) DUK_HOBJECT_GET_ASIZE(obj), + (long) DUK_HOBJECT_GET_HSIZE(obj), + (void *) new_p, + (long) new_e_size_adjusted, + (long) new_e_next, + (long) new_a_size, + (long) new_h_size, + (long) abandon_array, + (long) new_e_size)); /* * All done, switch properties ('p') allocation to new one. */ - DUK_FREE_CHECKED(thr, DUK_HOBJECT_GET_PROPS(thr->heap, obj)); /* NULL obj->p is OK */ + DUK_FREE_CHECKED(thr, DUK_HOBJECT_GET_PROPS(thr->heap, obj)); /* NULL obj->p is OK */ DUK_HOBJECT_SET_PROPS(thr->heap, obj, new_p); DUK_HOBJECT_SET_ESIZE(obj, new_e_size_adjusted); DUK_HOBJECT_SET_ENEXT(obj, new_e_next); @@ -58007,11 +59111,11 @@ * unwind. */ - abandon_error: - alloc_failed: +abandon_error: +alloc_failed: DUK_D(DUK_DPRINT("object property table resize failed")); - DUK_FREE_CHECKED(thr, new_p); /* OK for NULL. */ + DUK_FREE_CHECKED(thr, new_p); /* OK for NULL. */ thr->heap->pf_prevent_count--; thr->heap->ms_base_flags = prev_ms_base_flags; @@ -58028,9 +59132,7 @@ * Helpers to resize properties allocation on specific needs. */ -DUK_INTERNAL void duk_hobject_resize_entrypart(duk_hthread *thr, - duk_hobject *obj, - duk_uint32_t new_e_size) { +DUK_INTERNAL void duk_hobject_resize_entrypart(duk_hthread *thr, duk_hobject *obj, duk_uint32_t new_e_size) { duk_uint32_t old_e_size; duk_uint32_t new_a_size; duk_uint32_t new_h_size; @@ -58054,7 +59156,7 @@ /* Grow entry part allocation for one additional entry. */ DUK_LOCAL void duk__grow_props_for_new_entry_item(duk_hthread *thr, duk_hobject *obj) { - duk_uint32_t old_e_used; /* actually used, non-NULL entries */ + duk_uint32_t old_e_used; /* actually used, non-NULL entries */ duk_uint32_t new_e_size_minimum; duk_uint32_t new_e_size; duk_uint32_t new_a_size; @@ -58116,7 +59218,7 @@ new_h_size = DUK_HOBJECT_GET_HSIZE(obj); new_a_size_minimum = highest_arr_idx + 1; new_a_size = highest_arr_idx + duk__get_min_grow_a(highest_arr_idx); - DUK_ASSERT(new_a_size >= highest_arr_idx + 1); /* duk__get_min_grow_a() is always >= 1 */ + DUK_ASSERT(new_a_size >= highest_arr_idx + 1); /* duk__get_min_grow_a() is always >= 1 */ #if defined(DUK_USE_OBJSIZES16) if (new_e_size > DUK_UINT16_MAX) { @@ -58148,7 +59250,7 @@ duk_uint32_t new_e_size; duk_uint32_t new_a_size; duk_uint32_t new_h_size; - duk_uint32_t e_used; /* actually used, non-NULL keys */ + duk_uint32_t e_used; /* actually used, non-NULL keys */ duk_uint32_t a_used; duk_uint32_t a_size; @@ -58193,8 +59295,13 @@ DUK_DD(DUK_DDPRINT("abandon array part for hobject %p, " "array stats before: e_used=%ld, a_used=%ld, a_size=%ld; " "resize to e_size=%ld, a_size=%ld, h_size=%ld", - (void *) obj, (long) e_used, (long) a_used, (long) a_size, - (long) new_e_size, (long) new_a_size, (long) new_h_size)); + (void *) obj, + (long) e_used, + (long) a_used, + (long) a_size, + (long) new_e_size, + (long) new_a_size, + (long) new_h_size)); duk_hobject_realloc_props(thr, obj, new_e_size, new_a_size, new_h_size, 1); } @@ -58212,9 +59319,9 @@ */ DUK_INTERNAL void duk_hobject_compact_props(duk_hthread *thr, duk_hobject *obj) { - duk_uint32_t e_size; /* currently used -> new size */ - duk_uint32_t a_size; /* currently required */ - duk_uint32_t a_used; /* actually used */ + duk_uint32_t e_size; /* currently used -> new size */ + duk_uint32_t a_size; /* currently required */ + duk_uint32_t a_used; /* actually used */ duk_uint32_t h_size; duk_bool_t abandon_array; @@ -58233,13 +59340,17 @@ DUK_DD(DUK_DDPRINT("compacting hobject, used e keys %ld, used a keys %ld, min a size %ld, " "resized array density would be: %ld/%ld = %lf", - (long) e_size, (long) a_used, (long) a_size, - (long) a_used, (long) a_size, + (long) e_size, + (long) a_used, + (long) a_size, + (long) a_used, + (long) a_size, (double) a_used / (double) a_size)); if (duk__abandon_array_density_check(a_used, a_size)) { DUK_DD(DUK_DDPRINT("decided to abandon array during compaction, a_used=%ld, a_size=%ld", - (long) a_used, (long) a_size)); + (long) a_used, + (long) a_size)); abandon_array = 1; e_size += a_used; a_size = 0; @@ -58259,7 +59370,10 @@ #endif DUK_DD(DUK_DDPRINT("compacting hobject -> new e_size %ld, new a_size=%ld, new h_size=%ld, abandon_array=%ld", - (long) e_size, (long) a_size, (long) h_size, (long) abandon_array)); + (long) e_size, + (long) a_size, + (long) h_size, + (long) abandon_array)); duk_hobject_realloc_props(thr, obj, e_size, a_size, h_size, abandon_array); } @@ -58274,15 +59388,15 @@ * but there is no hash part, h_idx is set to -1. */ -DUK_INTERNAL duk_bool_t duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx) { +DUK_INTERNAL duk_bool_t +duk_hobject_find_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx) { DUK_ASSERT(obj != NULL); DUK_ASSERT(key != NULL); DUK_ASSERT(e_idx != NULL); DUK_ASSERT(h_idx != NULL); DUK_UNREF(heap); - if (DUK_LIKELY(DUK_HOBJECT_GET_HSIZE(obj) == 0)) - { + if (DUK_LIKELY(DUK_HOBJECT_GET_HSIZE(obj) == 0)) { /* Linear scan: more likely because most objects are small. * This is an important fast path. * @@ -58304,8 +59418,7 @@ } } #if defined(DUK_USE_HOBJECT_HASH_PART) - else - { + else { /* hash lookup */ duk_uint32_t n; duk_uint32_t i, step; @@ -58318,40 +59431,38 @@ n = DUK_HOBJECT_GET_HSIZE(obj); mask = n - 1; i = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { duk_uint32_t t; - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HOBJECT_GET_HSIZE(obj)); t = h_basei; DUK_ASSERT(t == DUK__HASH_UNUSED || t == DUK__HASH_DELETED || - (t < DUK_HOBJECT_GET_ESIZE(obj))); /* t >= 0 always true, unsigned */ + (t < DUK_HOBJECT_GET_ESIZE(obj))); /* t >= 0 always true, unsigned */ if (t == DUK__HASH_UNUSED) { break; } else if (t == DUK__HASH_DELETED) { - DUK_DDD(DUK_DDDPRINT("lookup miss (deleted) i=%ld, t=%ld", - (long) i, (long) t)); + DUK_DDD(DUK_DDDPRINT("lookup miss (deleted) i=%ld, t=%ld", (long) i, (long) t)); } else { DUK_ASSERT(t < DUK_HOBJECT_GET_ESIZE(obj)); if (DUK_HOBJECT_E_GET_KEY(heap, obj, t) == key) { - DUK_DDD(DUK_DDDPRINT("lookup hit i=%ld, t=%ld -> key %p", - (long) i, (long) t, (void *) key)); + DUK_DDD( + DUK_DDDPRINT("lookup hit i=%ld, t=%ld -> key %p", (long) i, (long) t, (void *) key)); *e_idx = (duk_int_t) t; *h_idx = (duk_int_t) i; return 1; } - DUK_DDD(DUK_DDDPRINT("lookup miss i=%ld, t=%ld", - (long) i, (long) t)); + DUK_DDD(DUK_DDDPRINT("lookup miss i=%ld, t=%ld", (long) i, (long) t)); } i = (i + step) & mask; /* Guaranteed to finish (hash is larger than #props). */ } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* Not found, leave e_idx and h_idx unset. */ return 0; @@ -58380,7 +59491,10 @@ } /* For internal use: get non-accessor entry value and attributes */ -DUK_INTERNAL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_uint_t *out_attrs) { +DUK_INTERNAL duk_tval *duk_hobject_find_entry_tval_ptr_and_attrs(duk_heap *heap, + duk_hobject *obj, + duk_hstring *key, + duk_uint_t *out_attrs) { duk_int_t e_idx; duk_int_t h_idx; @@ -58465,14 +59579,15 @@ n = DUK_HOBJECT_GET_HSIZE(obj); mask = n - 1; i = DUK_HSTRING_GET_HASH(key) & mask; - step = 1; /* Cache friendly but clustering prone. */ + step = 1; /* Cache friendly but clustering prone. */ for (;;) { duk_uint32_t t = h_basei; if (t == DUK__HASH_UNUSED || t == DUK__HASH_DELETED) { DUK_DDD(DUK_DDDPRINT("duk__hobject_alloc_entry_checked() inserted key into hash part, %ld -> %ld", - (long) i, (long) idx)); - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + (long) i, + (long) idx)); + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HOBJECT_GET_HSIZE(obj)); DUK_ASSERT_DISABLE(idx >= 0); DUK_ASSERT(idx < DUK_HOBJECT_GET_ESIZE(obj)); @@ -58485,7 +59600,7 @@ /* Guaranteed to finish (hash is larger than #props). */ } } -#endif /* DUK_USE_HOBJECT_HASH_PART */ +#endif /* DUK_USE_HOBJECT_HASH_PART */ /* Note: we could return the hash index here too, but it's not * needed right now. @@ -58593,8 +59708,12 @@ DUK_DDD(DUK_DDDPRINT("arguments map lookup: thr=%p, obj=%p, key=%p, temp_desc=%p " "(obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) temp_desc, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) temp_desc, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); if (!duk_hobject_get_own_propdesc(thr, obj, DUK_HTHREAD_STRING_INT_MAP(thr), temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { DUK_DDD(DUK_DDDPRINT("-> no 'map'")); @@ -58603,7 +59722,7 @@ map = duk_require_hobject(thr, -1); DUK_ASSERT(map != NULL); - duk_pop_unsafe(thr); /* map is reachable through obj */ + duk_pop_unsafe(thr); /* map is reachable through obj */ if (!duk_hobject_get_own_propdesc(thr, map, key, temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { DUK_DDD(DUK_DDDPRINT("-> 'map' exists, but key not in map")); @@ -58613,29 +59732,32 @@ /* ... varname */ DUK_DDD(DUK_DDDPRINT("-> 'map' exists, and contains key, key is mapped to argument/variable binding %!T", (duk_tval *) duk_get_tval(thr, -1))); - DUK_ASSERT(duk_is_string(thr, -1)); /* guaranteed when building arguments */ + DUK_ASSERT(duk_is_string(thr, -1)); /* guaranteed when building arguments */ /* get varenv for varname (callee's declarative lexical environment) */ rc = duk_hobject_get_own_propdesc(thr, obj, DUK_HTHREAD_STRING_INT_VARENV(thr), temp_desc, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); - DUK_ASSERT(rc != 0); /* arguments MUST have an initialized lexical environment reference */ + DUK_ASSERT(rc != 0); /* arguments MUST have an initialized lexical environment reference */ varenv = duk_require_hobject(thr, -1); DUK_ASSERT(varenv != NULL); - duk_pop_unsafe(thr); /* varenv remains reachable through 'obj' */ + duk_pop_unsafe(thr); /* varenv remains reachable through 'obj' */ DUK_DDD(DUK_DDDPRINT("arguments varenv is: %!dO", (duk_heaphdr *) varenv)); /* success: leave varname in stack */ *out_map = map; *out_varenv = varenv; - return 1; /* ... varname */ + return 1; /* ... varname */ } /* Lookup 'key' from arguments internal 'map', and leave replacement value * on stack top if mapped (and return non-zero). * Used in E5 Section 10.6 algorithm for GetOwnProperty (used by Get). */ -DUK_LOCAL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc) { +DUK_LOCAL duk_bool_t duk__check_arguments_map_for_get(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc) { duk_hobject *map; duk_hobject *varenv; duk_hstring *varname; @@ -58651,7 +59773,7 @@ varname = duk_require_hstring(thr, -1); DUK_ASSERT(varname != NULL); - duk_pop_unsafe(thr); /* varname is still reachable */ + duk_pop_unsafe(thr); /* varname is still reachable */ DUK_DDD(DUK_DDDPRINT("arguments object automatic getvar for a bound variable; " "key=%!O, varname=%!O", @@ -58672,7 +59794,11 @@ * Used in E5 Section 10.6 algorithm for DefineOwnProperty (used by Put). * Assumes stack top contains 'put' value (which is NOT popped). */ -DUK_LOCAL void duk__check_arguments_map_for_put(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *temp_desc, duk_bool_t throw_flag) { +DUK_LOCAL void duk__check_arguments_map_for_put(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_propdesc *temp_desc, + duk_bool_t throw_flag) { duk_hobject *map; duk_hobject *varenv; duk_hstring *varname; @@ -58688,7 +59814,7 @@ varname = duk_require_hstring(thr, -1); DUK_ASSERT(varname != NULL); - duk_pop_unsafe(thr); /* varname is still reachable */ + duk_pop_unsafe(thr); /* varname is still reachable */ DUK_DDD(DUK_DDDPRINT("arguments object automatic putvar for a bound variable; " "key=%!O, varname=%!O, value=%!T", @@ -58727,15 +59853,14 @@ map = duk_require_hobject(thr, -1); DUK_ASSERT(map != NULL); - duk_pop_unsafe(thr); /* map is reachable through obj */ + duk_pop_unsafe(thr); /* map is reachable through obj */ - DUK_DDD(DUK_DDDPRINT("-> have 'map', delete key %!O from map (if exists)); ignore result", - (duk_heaphdr *) key)); + DUK_DDD(DUK_DDDPRINT("-> have 'map', delete key %!O from map (if exists)); ignore result", (duk_heaphdr *) key)); /* Note: no recursion issue, we can trust 'map' to behave */ DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(map)); DUK_DDD(DUK_DDDPRINT("map before deletion: %!O", (duk_heaphdr *) map)); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ DUK_DDD(DUK_DDDPRINT("map after deletion: %!O", (duk_heaphdr *) map)); } @@ -58778,14 +59903,24 @@ * accessor properties later, this would need to change. */ -DUK_LOCAL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_uint32_t arr_idx, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_LOCAL duk_bool_t duk__get_own_propdesc_raw(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_uint32_t arr_idx, + duk_propdesc *out_desc, + duk_small_uint_t flags) { duk_tval *tv; DUK_DDD(DUK_DDDPRINT("duk_hobject_get_own_propdesc: thr=%p, obj=%p, key=%p, out_desc=%p, flags=%lx, " "arr_idx=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) out_desc, - (long) flags, (long) arr_idx, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) out_desc, + (long) flags, + (long) arr_idx, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -58859,14 +59994,13 @@ duk_push_tval(thr, tv); } /* implicit attributes */ - out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_CONFIGURABLE | - DUK_PROPDESC_FLAG_ENUMERABLE; + out_desc->flags = + DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE | DUK_PROPDESC_FLAG_ENUMERABLE; out_desc->get = NULL; out_desc->set = NULL; out_desc->e_idx = -1; out_desc->h_idx = -1; - out_desc->a_idx = (duk_int_t) arr_idx; /* XXX: limit 2G due to being signed */ + out_desc->a_idx = (duk_int_t) arr_idx; /* XXX: limit 2G due to being signed */ goto prop_found; } } @@ -58887,7 +60021,8 @@ duk_harray *a; DUK_DDD(DUK_DDDPRINT("array object exotic property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + (duk_heaphdr *) key, + (long) arr_idx)); a = (duk_harray *) obj; DUK_HARRAY_ASSERT_VALID(a); @@ -58909,11 +60044,12 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } else if (DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj)) { DUK_DDD(DUK_DDDPRINT("string object exotic property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + (duk_heaphdr *) key, + (long) arr_idx)); /* XXX: charlen; avoid multiple lookups? */ @@ -58928,9 +60064,9 @@ DUK_DDD(DUK_DDDPRINT("-> found, array index inside string")); if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_push_hstring(thr, h_val); - duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ + duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ } - out_desc->flags = DUK_PROPDESC_FLAG_ENUMERABLE | /* E5 Section 15.5.5.2 */ + out_desc->flags = DUK_PROPDESC_FLAG_ENUMERABLE | /* E5 Section 15.5.5.2 */ DUK_PROPDESC_FLAG_VIRTUAL; out_desc->get = NULL; out_desc->set = NULL; @@ -58939,7 +60075,7 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } else { /* index is above internal string length -> property is fully normal */ DUK_DDD(DUK_DDDPRINT("array index outside string -> normal property")); @@ -58954,7 +60090,7 @@ if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h_val)); } - out_desc->flags = DUK_PROPDESC_FLAG_VIRTUAL; /* E5 Section 15.5.5.1 */ + out_desc->flags = DUK_PROPDESC_FLAG_VIRTUAL; /* E5 Section 15.5.5.1 */ out_desc->get = NULL; out_desc->set = NULL; out_desc->e_idx = -1; @@ -58962,7 +60098,7 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) @@ -58973,8 +60109,7 @@ h_bufobj = (duk_hbufobj *) obj; DUK_HBUFOBJ_ASSERT_VALID(h_bufobj); - DUK_DDD(DUK_DDDPRINT("bufobj property get for key: %!O, arr_idx: %ld", - (duk_heaphdr *) key, (long) arr_idx)); + DUK_DDD(DUK_DDDPRINT("bufobj property get for key: %!O, arr_idx: %ld", (duk_heaphdr *) key, (long) arr_idx)); if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { DUK_DDD(DUK_DDDPRINT("array index exists")); @@ -58983,21 +60118,22 @@ * length downshift won't. */ if (arr_idx < (h_bufobj->length >> h_bufobj->shift)) { - byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); if (flags & DUK_GETDESC_FLAG_PUSH_VALUE) { duk_uint8_t *data; - if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { - data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + h_bufobj->offset + byte_off; + if (h_bufobj->buf != NULL && + DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { + data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + + h_bufobj->offset + byte_off; duk_hbufobj_push_validated_read(thr, h_bufobj, data, elem_size); } else { DUK_D(DUK_DPRINT("bufobj access out of underlying buffer, ignoring (read zero)")); duk_push_uint(thr, 0); } } - out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_VIRTUAL; + out_desc->flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_VIRTUAL; if (DUK_HOBJECT_GET_CLASS_NUMBER(obj) != DUK_HOBJECT_CLASS_ARRAYBUFFER) { /* ArrayBuffer indices are non-standard and are * non-enumerable to avoid their serialization. @@ -59011,7 +60147,8 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be e.g. arguments exotic, since exotic 'traits' are mutually exclusive */ + goto prop_found_noexotic; /* cannot be e.g. arguments exotic, since exotic 'traits' are mutually + exclusive */ } else { /* index is above internal buffer length -> property is fully normal */ DUK_DDD(DUK_DDDPRINT("array index outside buffer -> normal property")); @@ -59033,10 +60170,10 @@ out_desc->a_idx = -1; DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj)); - goto prop_found_noexotic; /* cannot be arguments exotic */ + goto prop_found_noexotic; /* cannot be arguments exotic */ } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* Array properties have exotic behavior but they are concrete, * so no special handling here. @@ -59050,7 +60187,7 @@ * Not found as concrete or virtual. */ - prop_not_found: +prop_not_found: DUK_DDD(DUK_DDDPRINT("-> not found (virtual, entry part, or array part)")); DUK_STATS_INC(thr->heap, stats_getownpropdesc_miss); return 0; @@ -59062,7 +60199,7 @@ * description of GetOwnProperty variant for arguments. */ - prop_found: +prop_found: DUK_DDD(DUK_DDDPRINT("-> property found, checking for arguments exotic post-behavior")); /* Notes: @@ -59072,8 +60209,7 @@ * DUK_GETDESC_FLAG_PUSH_VALUE is not set. */ - if (DUK_UNLIKELY(DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && - arr_idx != DUK__NO_ARRAY_INDEX && + if (DUK_UNLIKELY(DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && arr_idx != DUK__NO_ARRAY_INDEX && (flags & DUK_GETDESC_FLAG_PUSH_VALUE))) { duk_propdesc temp_desc; @@ -59099,12 +60235,13 @@ } } - prop_found_noexotic: +prop_found_noexotic: DUK_STATS_INC(thr->heap, stats_getownpropdesc_hit); return 1; } -DUK_INTERNAL duk_bool_t duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_INTERNAL duk_bool_t +duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { DUK_ASSERT(thr != NULL); DUK_ASSERT(obj != NULL); DUK_ASSERT(key != NULL); @@ -59133,7 +60270,8 @@ * pointers. */ -DUK_LOCAL duk_bool_t duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { +DUK_LOCAL duk_bool_t +duk__get_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags) { duk_hobject *curr; duk_uint32_t arr_idx; duk_uint_t sanity; @@ -59151,9 +60289,14 @@ DUK_DDD(DUK_DDDPRINT("duk__get_propdesc: thr=%p, obj=%p, key=%p, out_desc=%p, flags=%lx, " "arr_idx=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (void *) out_desc, - (long) flags, (long) arr_idx, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (void *) out_desc, + (long) flags, + (long) arr_idx, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); curr = obj; DUK_ASSERT(curr != NULL); @@ -59213,11 +60356,8 @@ DUK_UNREF(thr); - if (!(DUK_HOBJECT_HAS_ARRAY_PART(obj) && - !DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && - !DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj) && - !DUK_HOBJECT_IS_BUFOBJ(obj) && - !DUK_HOBJECT_IS_PROXY(obj))) { + if (!(DUK_HOBJECT_HAS_ARRAY_PART(obj) && !DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(obj) && !DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(obj) && + !DUK_HOBJECT_IS_BUFOBJ(obj) && !DUK_HOBJECT_IS_PROXY(obj))) { /* Must have array part and no conflicting exotic behaviors. * Doesn't need to have array special behavior, e.g. Arguments * object has array part. @@ -59235,7 +60375,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { DUK_DDD(DUK_DDDPRINT("key is not a number")); @@ -59269,18 +60409,19 @@ return NULL; } -DUK_LOCAL duk_bool_t duk__putprop_shallow_fastpath_array_tval(duk_hthread *thr, duk_hobject *obj, duk_tval *tv_key, duk_tval *tv_val) { +DUK_LOCAL duk_bool_t duk__putprop_shallow_fastpath_array_tval(duk_hthread *thr, + duk_hobject *obj, + duk_tval *tv_key, + duk_tval *tv_val) { duk_tval *tv; duk_harray *a; duk_uint32_t idx; duk_uint32_t old_len, new_len; - if (!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj) && - DUK_HOBJECT_HAS_ARRAY_PART(obj) && - DUK_HOBJECT_HAS_EXTENSIBLE(obj))) { + if (!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj) && DUK_HOBJECT_HAS_ARRAY_PART(obj) && DUK_HOBJECT_HAS_EXTENSIBLE(obj))) { return 0; } - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures */ a = (duk_harray *) obj; DUK_HARRAY_ASSERT_VALID(a); @@ -59290,7 +60431,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { DUK_DDD(DUK_DDDPRINT("key is not a number")); @@ -59302,7 +60443,7 @@ * because 0xffffffffUL will never be inside object 'a_size'. */ - if (idx >= DUK_HOBJECT_GET_ASIZE(obj)) { /* for resizing of array part, use slow path */ + if (idx >= DUK_HOBJECT_GET_ASIZE(obj)) { /* for resizing of array part, use slow path */ return 0; } DUK_ASSERT(idx != 0xffffffffUL); @@ -59313,7 +60454,8 @@ if (idx >= old_len) { DUK_DDD(DUK_DDDPRINT("write new array entry requires length update " "(arr_idx=%ld, old_len=%ld)", - (long) idx, (long) old_len)); + (long) idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a)) { /* The correct behavior here is either a silent error * or a TypeError, depending on strictness. Fall back @@ -59327,12 +60469,12 @@ } tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects */ DUK_DDD(DUK_DDDPRINT("array fast path success for index %ld", (long) idx)); return 1; } -#endif /* DUK_USE_ARRAY_PROP_FASTPATH */ +#endif /* DUK_USE_ARRAY_PROP_FASTPATH */ /* * Fast path for bufobj getprop/putprop @@ -59359,7 +60501,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { return 0; @@ -59376,7 +60518,7 @@ } DUK_ASSERT(idx != DUK__NO_ARRAY_INDEX); - byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { @@ -59389,7 +60531,7 @@ return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) DUK_LOCAL duk_bool_t duk__putprop_fastpath_bufobj_tval(duk_hthread *thr, duk_hobject *obj, duk_tval *tv_key, duk_tval *tv_val) { @@ -59399,11 +60541,10 @@ duk_small_uint_t elem_size; duk_uint8_t *data; - if (!(DUK_HOBJECT_IS_BUFOBJ(obj) && - DUK_TVAL_IS_NUMBER(tv_val))) { + if (!(DUK_HOBJECT_IS_BUFOBJ(obj) && DUK_TVAL_IS_NUMBER(tv_val))) { return 0; } - DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures; rom objects are never bufobjs now */ + DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); /* caller ensures; rom objects are never bufobjs now */ h_bufobj = (duk_hbufobj *) obj; if (!DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { @@ -59415,7 +60556,7 @@ idx = duk__tval_fastint_to_arr_idx(tv_key); } else #endif - if (DUK_TVAL_IS_DOUBLE(tv_key)) { + if (DUK_TVAL_IS_DOUBLE(tv_key)) { idx = duk__tval_number_to_arr_idx(tv_key); } else { return 0; @@ -59432,7 +60573,7 @@ } DUK_ASSERT(idx != DUK__NO_ARRAY_INDEX); - byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + byte_off = idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); /* Value is required to be a number in the fast path so there @@ -59451,7 +60592,7 @@ duk_pop_unsafe(thr); return 1; } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ /* * GETPROP: ECMAScript property read. @@ -59467,8 +60608,11 @@ duk_uint_t sanity; DUK_DDD(DUK_DDDPRINT("getprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -59505,8 +60649,11 @@ #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot read property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot read property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); break; @@ -59536,7 +60683,7 @@ pop_count = 0; } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object string, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -59545,15 +60692,15 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object string, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { duk_pop_n_unsafe(thr, pop_count); duk_push_hstring(thr, h); - duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ + duk_substring(thr, -1, arr_idx, arr_idx + 1); /* str -> substr */ DUK_STATS_INC(thr->heap, stats_getprop_stringidx); DUK_DDD(DUK_DDDPRINT("-> %!T (base is string, key is an index inside string length " @@ -59570,12 +60717,13 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object string, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { - duk_pop_unsafe(thr); /* key -> */ - duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); /* -> res */ + duk_pop_unsafe(thr); /* key -> */ + duk_push_uint(thr, (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); /* -> res */ DUK_STATS_INC(thr->heap, stats_getprop_stringlen); DUK_DDD(DUK_DDDPRINT("-> %!T (base is string, key is 'length' after coercion -> " @@ -59586,7 +60734,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a string, start lookup from string prototype")); curr = thr->builtinsDUK_BIDX_STRING_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_OBJECT: { @@ -59631,9 +60779,9 @@ /* -> ... trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'get' for key %!T", (duk_tval *) tv_key)); DUK_STATS_INC(thr->heap, stats_getprop_proxy); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ - duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ + duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ duk_call_method(thr, 3 /*nargs*/); /* Target object must be checked for a conflicting @@ -59643,25 +60791,27 @@ DUK_ASSERT(key != NULL); if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, DUK_GETDESC_FLAG_PUSH_VALUE)) { - duk_tval *tv_hook = duk_require_tval(thr, -3); /* value from hook */ - duk_tval *tv_targ = duk_require_tval(thr, -1); /* value from target */ + duk_tval *tv_hook = duk_require_tval(thr, -3); /* value from hook */ + duk_tval *tv_targ = duk_require_tval(thr, -1); /* value from target */ duk_bool_t datadesc_reject; duk_bool_t accdesc_reject; DUK_DDD(DUK_DDDPRINT("proxy 'get': target has matching property %!O, check for " "conflicting property; tv_hook=%!T, tv_targ=%!T, desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (duk_tval *) tv_hook, (duk_tval *) tv_targ, + (duk_heaphdr *) key, + (duk_tval *) tv_hook, + (duk_tval *) tv_targ, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (void *) desc.get, + (void *) desc.set)); datadesc_reject = !(desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && !(desc.flags & DUK_PROPDESC_FLAG_WRITABLE) && !duk_js_samevalue(tv_hook, tv_targ); accdesc_reject = (desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && - !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && - (desc.get == NULL) && + !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && (desc.get == NULL) && !DUK_TVAL_IS_UNDEFINED(tv_hook); if (datadesc_reject || accdesc_reject) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); @@ -59672,13 +60822,13 @@ } else { duk_pop_unsafe(thr); } - return 1; /* return value */ + return 1; /* return value */ } - curr = h_target; /* resume lookup from target */ + curr = h_target; /* resume lookup from target */ DUK_TVAL_SET_OBJECT(tv_obj, curr); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ if (DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(curr)) { arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); @@ -59693,11 +60843,11 @@ /* no need for 'caller' post-check, because 'key' must be an array index */ - duk_remove_m2(thr); /* key result -> result */ + duk_remove_m2(thr); /* key result -> result */ return 1; } - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } break; } @@ -59719,10 +60869,9 @@ arr_idx = duk__tval_fastint_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path fastint; arr_idx %ld", (long) arr_idx)); pop_count = 0; - } - else + } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -59731,12 +60880,12 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { duk_pop_n_unsafe(thr, pop_count); duk_push_uint(thr, ((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h))arr_idx); DUK_STATS_INC(thr->heap, stats_getprop_bufferidx); @@ -59754,12 +60903,13 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { - duk_pop_unsafe(thr); /* key -> */ - duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h)); /* -> res */ + duk_pop_unsafe(thr); /* key -> */ + duk_push_uint(thr, (duk_uint_t) DUK_HBUFFER_GET_SIZE(h)); /* -> res */ DUK_STATS_INC(thr->heap, stats_getprop_bufferlen); DUK_DDD(DUK_DDDPRINT("-> %!T (base is buffer, key is 'length' " @@ -59770,7 +60920,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a buffer, start lookup from Uint8Array prototype")); curr = thr->builtinsDUK_BIDX_UINT8ARRAY_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_POINTER: { @@ -59807,7 +60957,7 @@ * Property lookup */ - lookup: +lookup: /* key (coerced) */ DUK_ASSERT(curr != NULL); DUK_ASSERT(key != NULL); @@ -59822,25 +60972,23 @@ /* accessor with defined getter */ DUK_ASSERT((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) != 0); - duk_pop_unsafe(thr); /* key undefined -> key */ + duk_pop_unsafe(thr); /* key undefined -> key */ duk_push_hobject(thr, desc.get); - duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ + duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ #if defined(DUK_USE_NONSTD_GETTER_KEY_ARGUMENT) duk_dup_m3(thr); - duk_call_method(thr, 1); /* key getter this key -> key retval */ + duk_call_method(thr, 1); /* key getter this key -> key retval */ #else - duk_call_method(thr, 0); /* key getter this -> key retval */ + duk_call_method(thr, 0); /* key getter this -> key retval */ #endif } else { /* key value or key undefined */ /* data property or accessor without getter */ - DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || - (desc.get == NULL)); + DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || (desc.get == NULL)); /* if accessor without getter, return value is undefined */ - DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || - duk_is_undefined(thr, -1)); + DUK_ASSERT(((desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0) || duk_is_undefined(thr, -1)); /* Note: for an accessor without getter, falling through to * check for "caller" exotic behavior is unnecessary as @@ -59849,9 +60997,9 @@ */ } - goto found; /* key result */ + goto found; /* key result */ - next_in_chain: + next_in_chain: /* XXX: option to pretend property doesn't exist if sanity limit is * hit might be useful. */ @@ -59866,7 +61014,7 @@ * Not found */ - duk_to_undefined(thr, -1); /* key -> undefined (default value) */ + duk_to_undefined(thr, -1); /* key -> undefined (default value) */ DUK_DDD(DUK_DDDPRINT("-> %!T (not found)", (duk_tval *) duk_get_tval(thr, -1))); return 0; @@ -59875,7 +61023,7 @@ * Found; post-processing (Function and arguments objects) */ - found: +found: /* key result */ #if !defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) @@ -59905,13 +61053,11 @@ * This exotic behavior is disabled when the non-standard 'caller' property * is enabled, as it conflicts with the free use of 'caller'. */ - if (key == DUK_HTHREAD_STRING_CALLER(thr) && - DUK_TVAL_IS_OBJECT(tv_obj)) { + if (key == DUK_HTHREAD_STRING_CALLER(thr) && DUK_TVAL_IS_OBJECT(tv_obj)) { duk_hobject *orig = DUK_TVAL_GET_OBJECT(tv_obj); DUK_ASSERT(orig != NULL); - if (DUK_HOBJECT_IS_NONBOUND_FUNCTION(orig) || - DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { + if (DUK_HOBJECT_IS_NONBOUND_FUNCTION(orig) || DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { duk_hobject *h; /* XXX: The TypeError is currently not applied to bound @@ -59922,19 +61068,17 @@ */ DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(orig)); - h = duk_get_hobject(thr, -1); /* NULL if not an object */ - if (h && - DUK_HOBJECT_IS_FUNCTION(h) && - DUK_HOBJECT_HAS_STRICT(h)) { + h = duk_get_hobject(thr, -1); /* NULL if not an object */ + if (h && DUK_HOBJECT_IS_FUNCTION(h) && DUK_HOBJECT_HAS_STRICT(h)) { /* XXX: sufficient to check 'strict', assert for 'is function' */ DUK_ERROR_TYPE(thr, DUK_STR_STRICT_CALLER_READ); DUK_WO_NORETURN(return 0;); } } } -#endif /* !DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ +#endif /* !DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ - duk_remove_m2(thr); /* key result -> result */ + duk_remove_m2(thr); /* key result -> result */ DUK_DDD(DUK_DDDPRINT("-> %!T (found)", (duk_tval *) duk_get_tval(thr, -1))); return 1; @@ -59956,8 +61100,11 @@ duk_propdesc desc; DUK_DDD(DUK_DDDPRINT("hasprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -60029,8 +61176,8 @@ if (duk__proxy_check_prop(thr, obj, DUK_STRIDX_HAS, tv_key, &h_target)) { /* ... key trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'has' for key %!T", (duk_tval *) tv_key)); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ duk_call_method(thr, 2 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { @@ -60038,39 +61185,42 @@ * non-configurable property. */ - if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push + value */ DUK_DDD(DUK_DDDPRINT("proxy 'has': target has matching property %!O, check for " "conflicting property; desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (duk_heaphdr *) key, + (unsigned long) desc.flags, + (void *) desc.get, + (void *) desc.set)); /* XXX: Extensibility check for target uses IsExtensible(). If we * implemented the isExtensible trap and didn't reject proxies as * proxy targets, it should be respected here. */ - if (!((desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && /* property is configurable and */ - DUK_HOBJECT_HAS_EXTENSIBLE(h_target))) { /* ... target is extensible */ + if (!((desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && /* property is configurable and */ + DUK_HOBJECT_HAS_EXTENSIBLE(h_target))) { /* ... target is extensible */ DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); } } } - duk_pop_unsafe(thr); /* key -> */ + duk_pop_unsafe(thr); /* key -> */ return tmp_bool; } - obj = h_target; /* resume check from proxy target */ + obj = h_target; /* resume check from proxy target */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* XXX: inline into a prototype walking loop? */ - rc = duk__get_propdesc(thr, obj, key, &desc, 0 /*flags*/); /* don't push value */ + rc = duk__get_propdesc(thr, obj, key, &desc, 0 /*flags*/); /* don't push value */ /* fall through */ - pop_and_return: - duk_pop_unsafe(thr); /* key -> */ +pop_and_return: + duk_pop_unsafe(thr); /* key -> */ return rc; } @@ -60096,7 +61246,7 @@ DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); - return duk__get_propdesc(thr, obj, key, &dummy, DUK_GETDESC_FLAG_IGNORE_PROTOLOOP); /* don't push value */ + return duk__get_propdesc(thr, obj, key, &dummy, DUK_GETDESC_FLAG_IGNORE_PROTOLOOP); /* don't push value */ } /* @@ -60128,16 +61278,16 @@ } return (duk_uint32_t) fi; } -#else /* DUK_USE_FASTINT */ +#else /* DUK_USE_FASTINT */ /* When fastints are not enabled, the most interesting case is any * number. */ if (DUK_TVAL_IS_DOUBLE(tv)) { d = DUK_TVAL_GET_NUMBER(tv); } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ else -#endif /* !DUK_USE_PREFER_SIZE */ +#endif /* !DUK_USE_PREFER_SIZE */ { /* In all other cases, and when doing a size optimized build, * fall back to the comprehensive handler. @@ -60155,7 +61305,7 @@ return res; - fail_range: +fail_range: DUK_ERROR_RANGE(thr, DUK_STR_INVALID_ARRAY_LENGTH); DUK_WO_NORETURN(return 0;); } @@ -60183,7 +61333,8 @@ DUK_DDD(DUK_DDDPRINT("new array length smaller than old (%ld -> %ld), " "probably need to remove elements", - (long) old_len, (long) new_len)); + (long) old_len, + (long) new_len)); /* * New length is smaller than old length, need to delete properties above @@ -60229,7 +61380,7 @@ while (i > new_len) { i--; tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, i); - DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ } *out_result_len = new_len; @@ -60264,19 +61415,22 @@ continue; } - DUK_ASSERT(DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ + DUK_ASSERT( + DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); - DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ + DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ if (arr_idx < new_len) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is array index %ld, below new_len", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } if (DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is a relevant array index %ld, but configurable", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } @@ -60284,17 +61438,19 @@ if (arr_idx >= target_len) { DUK_DDD(DUK_DDDPRINT("entry at index %ld has arr_idx %ld, is not configurable, " "update target_len %ld -> %ld", - (long) i, (long) arr_idx, (long) target_len, + (long) i, + (long) arr_idx, + (long) target_len, (long) (arr_idx + 1))); target_len = arr_idx + 1; } } - skip_stage1: + skip_stage1: /* stage 2: delete configurable entries above target length */ - DUK_DDD(DUK_DDDPRINT("old_len=%ld, new_len=%ld, target_len=%ld", - (long) old_len, (long) new_len, (long) target_len)); + DUK_DDD( + DUK_DDDPRINT("old_len=%ld, new_len=%ld, target_len=%ld", (long) old_len, (long) new_len, (long) target_len)); DUK_DDD(DUK_DDDPRINT("array length write, no array part, stage 2: remove " "entries >= target_len")); @@ -60310,20 +61466,21 @@ continue; } - DUK_ASSERT(DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ + DUK_ASSERT( + DUK_HSTRING_HAS_ARRIDX(key)); /* XXX: macro checks for array index flag, which is unnecessary here */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); - DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ + DUK_ASSERT(arr_idx < old_len); /* consistency requires this */ if (arr_idx < target_len) { DUK_DDD(DUK_DDDPRINT("skip entry index %ld: key is array index %ld, below target_len", - (long) i, (long) arr_idx)); + (long) i, + (long) arr_idx)); continue; } - DUK_ASSERT(force_flag || DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)); /* stage 1 guarantees */ + DUK_ASSERT(force_flag || DUK_HOBJECT_E_SLOT_IS_CONFIGURABLE(thr->heap, obj, i)); /* stage 1 guarantees */ - DUK_DDD(DUK_DDDPRINT("delete entry index %ld: key is array index %ld", - (long) i, (long) arr_idx)); + DUK_DDD(DUK_DDDPRINT("delete entry index %ld: key is array index %ld", (long) i, (long) arr_idx)); /* * Slow delete, but we don't care as we're already in a very slow path. @@ -60454,11 +61611,12 @@ * (We currently make a copy of all of the input values to avoid issues.) */ -DUK_INTERNAL duk_bool_t duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag) { +DUK_INTERNAL duk_bool_t +duk_hobject_putprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key, duk_tval *tv_val, duk_bool_t throw_flag) { duk_tval tv_obj_copy; duk_tval tv_key_copy; duk_tval tv_val_copy; - duk_hobject *orig = NULL; /* NULL if tv_obj is primitive */ + duk_hobject *orig = NULL; /* NULL if tv_obj is primitive */ duk_hobject *curr; duk_hstring *key = NULL; duk_propdesc desc; @@ -60467,12 +61625,18 @@ duk_bool_t rc; duk_int_t e_idx; duk_uint_t sanity; - duk_uint32_t new_array_length = 0; /* 0 = no update */ + duk_uint32_t new_array_length = 0; /* 0 = no update */ DUK_DDD(DUK_DDDPRINT("putprop: thr=%p, obj=%p, key=%p, val=%p, throw=%ld " "(obj -> %!T, key -> %!T, val -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, (void *) tv_val, - (long) throw_flag, (duk_tval *) tv_obj, (duk_tval *) tv_key, (duk_tval *) tv_val)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (void *) tv_val, + (long) throw_flag, + (duk_tval *) tv_obj, + (duk_tval *) tv_key, + (duk_tval *) tv_val)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -60507,13 +61671,15 @@ case DUK_TAG_UNDEFINED: case DUK_TAG_NULL: { /* Note: unconditional throw */ - DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject (object=%!iT)", - (duk_tval *) tv_obj)); + DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject (object=%!iT)", (duk_tval *) tv_obj)); #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot write property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot write property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); break; @@ -60547,14 +61713,13 @@ goto fail_not_writable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { goto fail_not_writable; } DUK_DDD(DUK_DDDPRINT("base object is a string, start lookup from string prototype")); curr = thr->builtinsDUK_BIDX_STRING_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_OBJECT: { @@ -60569,7 +61734,7 @@ */ if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) orig)) { DUK_DD(DUK_DDPRINT("attempt to putprop on read-only target object")); - goto fail_not_writable_no_pop; /* Must avoid duk_pop() in exit path */ + goto fail_not_writable_no_pop; /* Must avoid duk_pop() in exit path */ } #endif @@ -60615,10 +61780,10 @@ /* -> ... trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'set' for key %!T", (duk_tval *) tv_key)); DUK_STATS_INC(thr->heap, stats_putprop_proxy); - duk_push_hobject(thr, h_target); /* target */ - duk_push_tval(thr, tv_key); /* P */ - duk_push_tval(thr, tv_val); /* V */ - duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ + duk_push_hobject(thr, h_target); /* target */ + duk_push_tval(thr, tv_key); /* P */ + duk_push_tval(thr, tv_val); /* V */ + duk_push_tval(thr, tv_obj); /* Receiver: Proxy object */ duk_call_method(thr, 4 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { @@ -60639,17 +61804,19 @@ DUK_DDD(DUK_DDDPRINT("proxy 'set': target has matching property %!O, check for " "conflicting property; tv_val=%!T, tv_targ=%!T, desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (duk_tval *) tv_val, (duk_tval *) tv_targ, + (duk_heaphdr *) key, + (duk_tval *) tv_val, + (duk_tval *) tv_targ, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (void *) desc.get, + (void *) desc.set)); datadesc_reject = !(desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && !(desc.flags & DUK_PROPDESC_FLAG_WRITABLE) && !duk_js_samevalue(tv_val, tv_targ); accdesc_reject = (desc.flags & DUK_PROPDESC_FLAG_ACCESSOR) && - !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && - (desc.set == NULL); + !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE) && (desc.set == NULL); if (datadesc_reject || accdesc_reject) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); @@ -60659,13 +61826,13 @@ } else { duk_pop_unsafe(thr); } - return 1; /* success */ + return 1; /* success */ } - orig = h_target; /* resume write to target */ + orig = h_target; /* resume write to target */ DUK_TVAL_SET_OBJECT(tv_obj, orig); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ curr = orig; break; @@ -60687,7 +61854,7 @@ pop_count = 0; } else #endif - if (DUK_TVAL_IS_NUMBER(tv_key)) { + if (DUK_TVAL_IS_NUMBER(tv_key)) { arr_idx = duk__tval_number_to_arr_idx(tv_key); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a fast-path number; arr_idx %ld", (long) arr_idx)); pop_count = 0; @@ -60696,12 +61863,12 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); pop_count = 1; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { duk_uint8_t *data; DUK_DDD(DUK_DDDPRINT("writing to buffer data at index %ld", (long) arr_idx)); data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h); @@ -60713,8 +61880,7 @@ /* Buffer writes are often integers. */ if (DUK_TVAL_IS_FASTINT(tv_val)) { dataarr_idx = (duk_uint8_t) DUK_TVAL_GET_FASTINT_U32(tv_val); - } - else + } else #endif { duk_push_tval(thr, tv_val); @@ -60736,7 +61902,8 @@ DUK_ASSERT(key != NULL); DUK_DDD(DUK_DDDPRINT("base object buffer, key is a non-fast-path number; after " "coercion key is %!T, arr_idx %ld", - (duk_tval *) duk_get_tval(thr, -1), (long) arr_idx)); + (duk_tval *) duk_get_tval(thr, -1), + (long) arr_idx)); } if (key == DUK_HTHREAD_STRING_LENGTH(thr)) { @@ -60745,7 +61912,7 @@ DUK_DDD(DUK_DDDPRINT("base object is a buffer, start lookup from Uint8Array prototype")); curr = thr->builtinsDUK_BIDX_UINT8ARRAY_PROTOTYPE; - goto lookup; /* avoid double coercion */ + goto lookup; /* avoid double coercion */ } case DUK_TAG_POINTER: { @@ -60780,7 +61947,7 @@ arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); DUK_ASSERT(key != NULL); - lookup: +lookup: /* * Check whether the property already exists in the prototype chain. @@ -60793,7 +61960,7 @@ DUK_ASSERT(curr != NULL); sanity = DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY; do { - if (!duk__get_own_propdesc_raw(thr, curr, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (!duk__get_own_propdesc_raw(thr, curr, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ goto next_in_chain; } @@ -60816,15 +61983,15 @@ goto fail_no_setter; } duk_push_hobject(thr, setter); - duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ - duk_push_tval(thr, tv_val); /* key setter this val */ + duk_push_tval(thr, tv_obj); /* note: original, uncoerced base */ + duk_push_tval(thr, tv_val); /* key setter this val */ #if defined(DUK_USE_NONSTD_SETTER_KEY_ARGUMENT) duk_dup_m4(thr); - duk_call_method(thr, 2); /* key setter this val key -> key retval */ + duk_call_method(thr, 2); /* key setter this val key -> key retval */ #else - duk_call_method(thr, 1); /* key setter this val -> key retval */ + duk_call_method(thr, 1); /* key setter this val -> key retval */ #endif - duk_pop_unsafe(thr); /* ignore retval -> key */ + duk_pop_unsafe(thr); /* ignore retval -> key */ goto success_no_arguments_exotic; } @@ -60844,11 +62011,13 @@ * new property to 'orig'. */ if (!DUK_HOBJECT_HAS_EXTENSIBLE(orig)) { - DUK_DD(DUK_DDPRINT("found existing inherited plain property, but original object is not extensible")); + DUK_DD( + DUK_DDPRINT("found existing inherited plain property, but original object is not extensible")); goto fail_not_extensible; } if (!(desc.flags & DUK_PROPDESC_FLAG_WRITABLE)) { - DUK_DD(DUK_DDPRINT("found existing inherited plain property, original object is extensible, but inherited property is not writable")); + DUK_DD(DUK_DDPRINT("found existing inherited plain property, original object is extensible, but " + "inherited property is not writable")); goto fail_not_writable; } DUK_DD(DUK_DDPRINT("put to new property, object extensible, inherited property found and is writable")); @@ -60860,7 +62029,8 @@ */ if (!(desc.flags & DUK_PROPDESC_FLAG_WRITABLE)) { - DUK_DD(DUK_DDPRINT("found existing own (non-inherited) plain property, but property is not writable")); + DUK_DD( + DUK_DDPRINT("found existing own (non-inherited) plain property, but property is not writable")); goto fail_not_writable; } if (desc.flags & DUK_PROPDESC_FLAG_VIRTUAL) { @@ -60877,18 +62047,19 @@ * Note: the helper has an unnecessary writability check * for 'length', we already know it is writable. */ - DUK_ASSERT(key == DUK_HTHREAD_STRING_LENGTH(thr)); /* only virtual array property */ + DUK_ASSERT(key == DUK_HTHREAD_STRING_LENGTH(thr)); /* only virtual array property */ - DUK_DDD(DUK_DDDPRINT("writing existing 'length' property to array exotic, invoke complex helper")); + DUK_DDD(DUK_DDDPRINT( + "writing existing 'length' property to array exotic, invoke complex helper")); /* XXX: the helper currently assumes stack top contains new * 'length' value and the whole calling convention is not very * compatible with what we need. */ - duk_push_tval(thr, tv_val); /* key val */ + duk_push_tval(thr, tv_val); /* key val */ rc = duk__handle_put_array_length(thr, orig); - duk_pop_unsafe(thr); /* key val -> key */ + duk_pop_unsafe(thr); /* key val -> key */ if (!rc) { goto fail_array_length_partial; } @@ -60910,12 +62081,14 @@ /* Careful with wrapping: arr_idx upshift may easily wrap, whereas * length downshift won't. */ - if (arr_idx < (h_bufobj->length >> h_bufobj->shift) && DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { + if (arr_idx < (h_bufobj->length >> h_bufobj->shift) && + DUK_HBUFOBJ_HAS_VIRTUAL_INDICES(h_bufobj)) { duk_uint8_t *data; DUK_DDD(DUK_DDDPRINT("writing to buffer data at index %ld", (long) arr_idx)); - DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); /* index/length check guarantees */ - byte_off = arr_idx << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ + DUK_ASSERT(arr_idx != DUK__NO_ARRAY_INDEX); /* index/length check guarantees */ + byte_off = arr_idx + << h_bufobj->shift; /* no wrap assuming h_bufobj->length is valid */ elem_size = (duk_small_uint_t) (1U << h_bufobj->shift); /* Coerce to number before validating pointers etc so that the @@ -60926,27 +62099,30 @@ duk_push_tval(thr, tv_val); (void) duk_to_number_m1(thr); - if (h_bufobj->buf != NULL && DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { - data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + h_bufobj->offset + byte_off; + if (h_bufobj->buf != NULL && + DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL(h_bufobj, byte_off + elem_size)) { + data = (duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(thr->heap, h_bufobj->buf) + + h_bufobj->offset + byte_off; duk_hbufobj_validated_write(thr, h_bufobj, data, elem_size); } else { - DUK_D(DUK_DPRINT("bufobj access out of underlying buffer, ignoring (write skipped)")); + DUK_D(DUK_DPRINT( + "bufobj access out of underlying buffer, ignoring (write skipped)")); } duk_pop_unsafe(thr); goto success_no_arguments_exotic; } } -#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ +#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ DUK_D(DUK_DPRINT("should not happen, key %!O", key)); - goto fail_internal; /* should not happen */ + goto fail_internal; /* should not happen */ } DUK_DD(DUK_DDPRINT("put to existing own plain property, property is writable")); goto update_old; } DUK_UNREACHABLE(); - next_in_chain: + next_in_chain: /* XXX: option to pretend property doesn't exist if sanity limit is * hit might be useful. */ @@ -60975,7 +62151,7 @@ goto create_new; - update_old: +update_old: /* * Update an existing property of the base object. @@ -61008,10 +62184,9 @@ if (desc.e_idx >= 0) { tv = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, orig, desc.e_idx); DUK_DDD(DUK_DDDPRINT("previous entry value: %!iT", (duk_tval *) tv)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; e_idx may be invalidated */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; e_idx may be invalidated */ /* don't touch property attributes or hash part */ - DUK_DD(DUK_DDPRINT("put to an existing entry at index %ld -> new value %!iT", - (long) desc.e_idx, (duk_tval *) tv)); + DUK_DD(DUK_DDPRINT("put to an existing entry at index %ld -> new value %!iT", (long) desc.e_idx, (duk_tval *) tv)); } else { /* Note: array entries are always writable, so the writability check * above is pointless for them. The check could be avoided with some @@ -61021,9 +62196,10 @@ DUK_ASSERT(desc.a_idx >= 0); tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, orig, desc.a_idx); DUK_DDD(DUK_DDDPRINT("previous array value: %!iT", (duk_tval *) tv)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; a_idx may be invalidated */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv_val); /* side effects; a_idx may be invalidated */ DUK_DD(DUK_DDPRINT("put to an existing array entry at index %ld -> new value %!iT", - (long) desc.a_idx, (duk_tval *) tv)); + (long) desc.a_idx, + (duk_tval *) tv)); } /* Regardless of whether property is found in entry or array part, @@ -61032,7 +62208,7 @@ */ goto success_with_arguments_exotic; - create_new: +create_new: /* * Create a new property in the original object. @@ -61065,11 +62241,9 @@ * from its creation and cannot be deleted, and is thus * caught as an existing property above. */ - DUK_ASSERT(!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && - key == DUK_HTHREAD_STRING_LENGTH(thr))); + DUK_ASSERT(!(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && key == DUK_HTHREAD_STRING_LENGTH(thr))); - if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && - arr_idx != DUK__NO_ARRAY_INDEX) { + if (DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig) && arr_idx != DUK__NO_ARRAY_INDEX) { /* automatic length update */ duk_uint32_t old_len; duk_harray *a; @@ -61082,7 +62256,8 @@ if (arr_idx >= old_len) { DUK_DDD(DUK_DDDPRINT("write new array entry requires length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a)) { DUK_DD(DUK_DDPRINT("attempt to extend array, but array 'length' is not writable")); @@ -61096,15 +62271,16 @@ */ DUK_ASSERT(arr_idx != 0xffffffffUL); - new_array_length = arr_idx + 1; /* flag for later write */ + new_array_length = arr_idx + 1; /* flag for later write */ } else { DUK_DDD(DUK_DDDPRINT("write new array entry does not require length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); } } - /* write_to_array_part: */ + /* write_to_array_part: */ /* * Write to array part? @@ -61126,8 +62302,7 @@ DUK_ASSERT(DUK_TVAL_IS_UNUSED(tv)); DUK_TVAL_SET_TVAL(tv, tv_val); DUK_TVAL_INCREF(thr, tv); - DUK_DD(DUK_DDPRINT("put to new array entry: %ld -> %!T", - (long) arr_idx, (duk_tval *) tv)); + DUK_DD(DUK_DDPRINT("put to new array entry: %ld -> %!T", (long) arr_idx, (duk_tval *) tv)); /* Note: array part values are Writable, Enumerable, * and Configurable which matches the required attributes @@ -61136,7 +62311,7 @@ goto entry_updated; } - write_to_entry_part: +write_to_entry_part: /* * Write to entry part @@ -61156,7 +62331,7 @@ DUK_HOBJECT_E_SET_FLAGS(thr->heap, orig, e_idx, DUK_PROPDESC_FLAGS_WEC); goto entry_updated; - entry_updated: +entry_updated: /* * Possible pending array length update, which must only be done @@ -61170,8 +62345,7 @@ DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(orig)); - DUK_DDD(DUK_DDDPRINT("write successful, pending array length update to: %ld", - (long) new_array_length)); + DUK_DDD(DUK_DDDPRINT("write successful, pending array length update to: %ld", (long) new_array_length)); ((duk_harray *) orig)->length = new_array_length; } @@ -61185,7 +62359,7 @@ goto success_no_arguments_exotic; - success_with_arguments_exotic: +success_with_arguments_exotic: /* * Arguments objects have exotic DefineOwnProperty which updates @@ -61200,8 +62374,7 @@ * we end up in step 5.b.i. */ - if (arr_idx != DUK__NO_ARRAY_INDEX && - DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(orig)) { /* Note: only numbered indices are relevant, so arr_idx fast reject * is good (this is valid unless there are more than 4**32-1 arguments). */ @@ -61220,14 +62393,14 @@ } /* fall thru */ - success_no_arguments_exotic: +success_no_arguments_exotic: /* shared exit path now */ DUK_DDD(DUK_DDDPRINT("result: success")); - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 1; #if defined(DUK_USE_ES6_PROXY) - fail_proxy_rejected: +fail_proxy_rejected: DUK_DDD(DUK_DDDPRINT("result: error, proxy rejects")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); @@ -61237,40 +62410,43 @@ return 0; #endif - fail_base_primitive: +fail_base_primitive: DUK_DDD(DUK_DDDPRINT("result: error, base primitive")); if (throw_flag) { #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot write property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot write property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_not_extensible: +fail_not_extensible: DUK_DDD(DUK_DDDPRINT("result: error, not extensible")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_EXTENSIBLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_not_writable: +fail_not_writable: DUK_DDD(DUK_DDDPRINT("result: error, not writable")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_WRITABLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; #if defined(DUK_USE_ROM_OBJECTS) - fail_not_writable_no_pop: +fail_not_writable_no_pop: DUK_DDD(DUK_DDDPRINT("result: error, not writable")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_WRITABLE); @@ -61279,31 +62455,31 @@ return 0; #endif - fail_array_length_partial: +fail_array_length_partial: DUK_DD(DUK_DDPRINT("result: error, array length write only partially successful")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_no_setter: +fail_no_setter: DUK_DDD(DUK_DDDPRINT("result: error, accessor property without setter")); if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_SETTER_UNDEFINED); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; - fail_internal: +fail_internal: DUK_DDD(DUK_DDDPRINT("result: error, internal")); if (throw_flag) { DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); } - duk_pop_unsafe(thr); /* remove key */ + duk_pop_unsafe(thr); /* remove key */ return 0; } @@ -61322,8 +62498,13 @@ force_flag = (flags & DUK_DELPROP_FLAG_FORCE); DUK_DDD(DUK_DDDPRINT("delprop_raw: thr=%p, obj=%p, key=%p, throw=%ld, force=%ld (obj -> %!O, key -> %!O)", - (void *) thr, (void *) obj, (void *) key, (long) throw_flag, (long) force_flag, - (duk_heaphdr *) obj, (duk_heaphdr *) key)); + (void *) thr, + (void *) obj, + (void *) key, + (long) throw_flag, + (long) force_flag, + (duk_heaphdr *) obj, + (duk_heaphdr *) key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -61335,7 +62516,7 @@ arr_idx = DUK_HSTRING_GET_ARRIDX_FAST(key); /* 0 = don't push current value */ - if (!duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (!duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ DUK_DDD(DUK_DDDPRINT("property not found, succeed always")); goto success; } @@ -61362,7 +62543,7 @@ DUK_ASSERT(desc.e_idx < 0); tv = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, desc.a_idx); - DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ + DUK_TVAL_SET_UNUSED_UPDREF(thr, tv); /* side effects */ goto success; } else { DUK_ASSERT(desc.a_idx < 0); @@ -61388,7 +62569,9 @@ * invalidated. */ DUK_DDD(DUK_DDDPRINT("before removing value, e_idx %ld, key %p, key at slot %p", - (long) desc.e_idx, (void *) key, (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); + (long) desc.e_idx, + (void *) key, + (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); DUK_DDD(DUK_DDDPRINT("removing value at e_idx %ld", (long) desc.e_idx)); if (DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, desc.e_idx)) { duk_hobject *tmp; @@ -61413,7 +62596,9 @@ /* Remove key. */ DUK_DDD(DUK_DDDPRINT("before removing key, e_idx %ld, key %p, key at slot %p", - (long) desc.e_idx, (void *) key, (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); + (long) desc.e_idx, + (void *) key, + (void *) DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx))); DUK_DDD(DUK_DDDPRINT("removing key at e_idx %ld", (long) desc.e_idx)); DUK_ASSERT(key == DUK_HOBJECT_E_GET_KEY(thr->heap, obj, desc.e_idx)); DUK_HOBJECT_E_SET_KEY(thr->heap, obj, desc.e_idx, NULL); @@ -61429,7 +62614,7 @@ DUK_UNREACHABLE(); - success: +success: /* * Argument exotic Delete behavior (E5 Section 10.6) is * a post-check, keeping arguments internal 'map' in sync with @@ -61456,8 +62641,8 @@ DUK_DDD(DUK_DDDPRINT("delete successful")); return 1; - fail_virtual: /* just use the same "not configurable" error message */ - fail_not_configurable: +fail_virtual: /* just use the same "not configurable" error message */ +fail_not_configurable: DUK_DDD(DUK_DDDPRINT("delete failed: property found, not configurable")); if (throw_flag) { @@ -61481,8 +62666,11 @@ duk_bool_t rc; DUK_DDD(DUK_DDDPRINT("delprop: thr=%p, obj=%p, key=%p (obj -> %!T, key -> %!T)", - (void *) thr, (void *) tv_obj, (void *) tv_key, - (duk_tval *) tv_obj, (duk_tval *) tv_key)); + (void *) thr, + (void *) tv_obj, + (void *) tv_key, + (duk_tval *) tv_obj, + (duk_tval *) tv_key)); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -61496,8 +62684,7 @@ */ entry_top = duk_get_top(thr); - if (DUK_TVAL_IS_UNDEFINED(tv_obj) || - DUK_TVAL_IS_NULL(tv_obj)) { + if (DUK_TVAL_IS_UNDEFINED(tv_obj) || DUK_TVAL_IS_NULL(tv_obj)) { DUK_DDD(DUK_DDDPRINT("base object is undefined or null -> reject")); goto fail_invalid_base_uncond; } @@ -61520,12 +62707,12 @@ if (duk__proxy_check_prop(thr, obj, DUK_STRIDX_DELETE_PROPERTY, tv_key, &h_target)) { /* -> ... obj key trap handler */ DUK_DDD(DUK_DDDPRINT("-> proxy object 'deleteProperty' for key %!T", (duk_tval *) tv_key)); - duk_push_hobject(thr, h_target); /* target */ - duk_dup_m4(thr); /* P */ + duk_push_hobject(thr, h_target); /* target */ + duk_dup_m4(thr); /* P */ duk_call_method(thr, 2 /*nargs*/); tmp_bool = duk_to_boolean_top_pop(thr); if (!tmp_bool) { - goto fail_proxy_rejected; /* retval indicates delete failed */ + goto fail_proxy_rejected; /* retval indicates delete failed */ } /* Target object must be checked for a conflicting @@ -61535,14 +62722,17 @@ arr_idx = duk__push_tval_to_property_key(thr, tv_key, &key); DUK_ASSERT(key != NULL); - if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, h_target, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push + value */ duk_small_int_t desc_reject; DUK_DDD(DUK_DDDPRINT("proxy 'deleteProperty': target has matching property %!O, check for " "conflicting property; desc.flags=0x%08lx, " "desc.get=%p, desc.set=%p", - (duk_heaphdr *) key, (unsigned long) desc.flags, - (void *) desc.get, (void *) desc.set)); + (duk_heaphdr *) key, + (unsigned long) desc.flags, + (void *) desc.get, + (void *) desc.set)); desc_reject = !(desc.flags & DUK_PROPDESC_FLAG_CONFIGURABLE); if (desc_reject) { @@ -61551,13 +62741,13 @@ DUK_WO_NORETURN(return 0;); } } - rc = 1; /* success */ + rc = 1; /* success */ goto done_rc; } - obj = h_target; /* resume delete to target */ + obj = h_target; /* resume delete to target */ } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ arr_idx = duk__to_property_key(thr, -1, &key); DUK_ASSERT(key != NULL); @@ -61582,8 +62772,7 @@ goto fail_not_configurable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HSTRING_GET_CHARLEN(h)) { goto fail_not_configurable; } } else if (DUK_TVAL_IS_BUFFER(tv_obj)) { @@ -61601,8 +62790,7 @@ goto fail_not_configurable; } - if (arr_idx != DUK__NO_ARRAY_INDEX && - arr_idx < DUK_HBUFFER_GET_SIZE(h)) { + if (arr_idx != DUK__NO_ARRAY_INDEX && arr_idx < DUK_HBUFFER_GET_SIZE(h)) { goto fail_not_configurable; } } else if (DUK_TVAL_IS_LIGHTFUNC(tv_obj)) { @@ -61619,23 +62807,26 @@ rc = 1; goto done_rc; - done_rc: +done_rc: duk_set_top_unsafe(thr, entry_top); return rc; - fail_invalid_base_uncond: +fail_invalid_base_uncond: /* Note: unconditional throw */ DUK_ASSERT(duk_get_top(thr) == entry_top); #if defined(DUK_USE_PARANOID_ERRORS) DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BASE); #else - DUK_ERROR_FMT2(thr, DUK_ERR_TYPE_ERROR, "cannot delete property %s of %s", - duk_push_string_tval_readable(thr, tv_key), duk_push_string_tval_readable(thr, tv_obj)); + DUK_ERROR_FMT2(thr, + DUK_ERR_TYPE_ERROR, + "cannot delete property %s of %s", + duk_push_string_tval_readable(thr, tv_key), + duk_push_string_tval_readable(thr, tv_obj)); #endif DUK_WO_NORETURN(return 0;); #if defined(DUK_USE_ES6_PROXY) - fail_proxy_rejected: +fail_proxy_rejected: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_PROXY_REJECTED); DUK_WO_NORETURN(return 0;); @@ -61644,7 +62835,7 @@ return 0; #endif - fail_not_configurable: +fail_not_configurable: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); @@ -61672,17 +62863,23 @@ * operations. */ -DUK_INTERNAL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags) { +DUK_INTERNAL void duk_hobject_define_property_internal(duk_hthread *thr, + duk_hobject *obj, + duk_hstring *key, + duk_small_uint_t flags) { duk_propdesc desc; duk_uint32_t arr_idx; duk_int_t e_idx; duk_tval *tv1 = NULL; duk_tval *tv2 = NULL; - duk_small_uint_t propflags = flags & DUK_PROPDESC_FLAGS_MASK; /* mask out flags not actually stored */ + duk_small_uint_t propflags = flags & DUK_PROPDESC_FLAGS_MASK; /* mask out flags not actually stored */ DUK_DDD(DUK_DDDPRINT("define new property (internal): thr=%p, obj=%!O, key=%!O, flags=0x%02lx, val=%!T", - (void *) thr, (duk_heaphdr *) obj, (duk_heaphdr *) key, - (unsigned long) flags, (duk_tval *) duk_get_tval(thr, -1))); + (void *) thr, + (duk_heaphdr *) obj, + (duk_heaphdr *) key, + (unsigned long) flags, + (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(thr != NULL); DUK_ASSERT(thr->heap != NULL); @@ -61690,11 +62887,11 @@ DUK_ASSERT(key != NULL); DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE); - DUK_ASSERT(duk_is_valid_index(thr, -1)); /* contains value */ + DUK_ASSERT(duk_is_valid_index(thr, -1)); /* contains value */ arr_idx = DUK_HSTRING_GET_ARRIDX_SLOW(key); - if (duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ + if (duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &desc, 0 /*flags*/)) { /* don't push value */ if (desc.e_idx >= 0) { if (flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) { DUK_DDD(DUK_DDDPRINT("property already exists in the entry part -> skip as requested")); @@ -61735,7 +62932,8 @@ new_len = duk__to_new_array_length_checked(thr, DUK_GET_TVAL_NEGIDX(thr, -1)); ((duk_harray *) obj)->length = new_len; DUK_DD(DUK_DDPRINT("internal define property for array .length: %ld -> %ld", - (long) prev_len, (long) ((duk_harray *) obj)->length)); + (long) prev_len, + (long) ((duk_harray *) obj)->length)); goto pop_exit; } DUK_DD(DUK_DDPRINT("property already exists but is virtual -> failure")); @@ -61747,7 +62945,8 @@ if (DUK_HOBJECT_HAS_ARRAY_PART(obj)) { if (arr_idx != DUK__NO_ARRAY_INDEX) { - DUK_DDD(DUK_DDDPRINT("property does not exist, object has array part -> possibly extend array part and write value (assert attributes)")); + DUK_DDD(DUK_DDDPRINT("property does not exist, object has array part -> possibly extend array part and " + "write value (assert attributes)")); DUK_ASSERT(propflags == DUK_PROPDESC_FLAGS_WEC); tv1 = duk__obtain_arridx_slot(thr, arr_idx, obj); @@ -61761,9 +62960,10 @@ } } - write_to_entry_part: - DUK_DDD(DUK_DDDPRINT("property does not exist, object belongs in entry part -> allocate new entry and write value and attributes")); - e_idx = duk__hobject_alloc_entry_checked(thr, obj, key); /* increases key refcount */ +write_to_entry_part: + DUK_DDD(DUK_DDDPRINT( + "property does not exist, object belongs in entry part -> allocate new entry and write value and attributes")); + e_idx = duk__hobject_alloc_entry_checked(thr, obj, key); /* increases key refcount */ DUK_ASSERT(e_idx >= 0); DUK_HOBJECT_E_SET_FLAGS(thr->heap, obj, e_idx, propflags); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, e_idx); @@ -61771,22 +62971,21 @@ DUK_TVAL_SET_UNDEFINED(tv1); goto write_value; - write_value: +write_value: /* tv1 points to value storage */ - tv2 = duk_require_tval(thr, -1); /* late lookup, avoid side effects */ - DUK_DDD(DUK_DDDPRINT("writing/updating value: %!T -> %!T", - (duk_tval *) tv1, (duk_tval *) tv2)); + tv2 = duk_require_tval(thr, -1); /* late lookup, avoid side effects */ + DUK_DDD(DUK_DDDPRINT("writing/updating value: %!T -> %!T", (duk_tval *) tv1, (duk_tval *) tv2)); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ goto pop_exit; - pop_exit: - duk_pop_unsafe(thr); /* remove in_val */ +pop_exit: + duk_pop_unsafe(thr); /* remove in_val */ return; - error_virtual: /* share error message */ - error_internal: +error_virtual: /* share error message */ +error_internal: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); } @@ -61797,13 +62996,19 @@ * must avoid interning. */ -DUK_INTERNAL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, duk_hobject *obj, duk_uarridx_t arr_idx, duk_small_uint_t flags) { +DUK_INTERNAL void duk_hobject_define_property_internal_arridx(duk_hthread *thr, + duk_hobject *obj, + duk_uarridx_t arr_idx, + duk_small_uint_t flags) { duk_hstring *key; duk_tval *tv1, *tv2; DUK_DDD(DUK_DDDPRINT("define new property (internal) arr_idx fast path: thr=%p, obj=%!O, " "arr_idx=%ld, flags=0x%02lx, val=%!T", - (void *) thr, obj, (long) arr_idx, (unsigned long) flags, + (void *) thr, + obj, + (long) arr_idx, + (unsigned long) flags, (duk_tval *) duk_get_tval(thr, -1))); DUK_ASSERT(thr != NULL); @@ -61811,10 +63016,8 @@ DUK_ASSERT(obj != NULL); DUK_ASSERT(!DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)); - if (DUK_HOBJECT_HAS_ARRAY_PART(obj) && - arr_idx != DUK__NO_ARRAY_INDEX && - flags == DUK_PROPDESC_FLAGS_WEC) { - DUK_ASSERT((flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) == 0); /* covered by comparison */ + if (DUK_HOBJECT_HAS_ARRAY_PART(obj) && arr_idx != DUK__NO_ARRAY_INDEX && flags == DUK_PROPDESC_FLAGS_WEC) { + DUK_ASSERT((flags & DUK_PROPDESC_FLAG_NO_OVERWRITE) == 0); /* covered by comparison */ DUK_DDD(DUK_DDDPRINT("define property to array part (property may or may not exist yet)")); @@ -61825,22 +63028,22 @@ } tv2 = duk_require_tval(thr, -1); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ - duk_pop_unsafe(thr); /* ...val -> ... */ + duk_pop_unsafe(thr); /* ...val -> ... */ return; } - write_slow: +write_slow: DUK_DDD(DUK_DDDPRINT("define property fast path didn't work, use slow path")); key = duk_push_uint_to_hstring(thr, (duk_uint_t) arr_idx); DUK_ASSERT(key != NULL); - duk_insert(thr, -2); /* ... val key -> ... key val */ + duk_insert(thr, -2); /* ... val key -> ... key val */ duk_hobject_define_property_internal(thr, obj, key, flags); - duk_pop_unsafe(thr); /* ... key -> ... */ + duk_pop_unsafe(thr); /* ... key -> ... */ } /* @@ -61861,9 +63064,7 @@ /* Slow path, .length can be e.g. accessor, obj can be a Proxy, etc. */ duk_push_hobject(thr, obj); duk_push_hstring_stridx(thr, DUK_STRIDX_LENGTH); - (void) duk_hobject_getprop(thr, - DUK_GET_TVAL_NEGIDX(thr, -2), - DUK_GET_TVAL_NEGIDX(thr, -1)); + (void) duk_hobject_getprop(thr, DUK_GET_TVAL_NEGIDX(thr, -2), DUK_GET_TVAL_NEGIDX(thr, -1)); val = duk_to_number_m1(thr); duk_pop_3_unsafe(thr); @@ -61904,7 +63105,7 @@ DUK_ASSERT(heap != NULL); obj = DUK_HOBJECT_GET_PROTOTYPE(heap, obj); #else - obj = DUK_HOBJECT_GET_PROTOTYPE(NULL, obj); /* 'heap' arg ignored */ + obj = DUK_HOBJECT_GET_PROTOTYPE(NULL, obj); /* 'heap' arg ignored */ #endif } while (obj != NULL); @@ -61971,7 +63172,7 @@ /* ... key value desc */ duk_replace(thr, -3); - duk_pop_unsafe(thr); /* -> ... desc */ + duk_pop_unsafe(thr); /* -> ... desc */ } /* @@ -62008,7 +63209,7 @@ DUK_ASSERT(out_idx_value != NULL); DUK_ASSERT(out_getter != NULL); DUK_ASSERT(out_setter != NULL); - DUK_ASSERT(idx_in <= 0x7fffL); /* short variants would be OK, but not used to avoid shifts */ + DUK_ASSERT(idx_in <= 0x7fffL); /* short variants would be OK, but not used to avoid shifts */ /* Must be an object, otherwise TypeError (E5.1 Section 8.10.5, step 1). */ idx_in = duk_require_normalize_index(thr, idx_in); @@ -62064,7 +63265,7 @@ if (DUK_TVAL_IS_UNDEFINED(tv)) { /* undefined is accepted */ DUK_ASSERT(setter == NULL); - } else { + } else { /* NOTE: lightfuncs are coerced to full functions because * lightfuncs don't fit into a property value slot. This * has some side effects, see test-dev-lightfunc-accessor.js. @@ -62107,7 +63308,7 @@ /* ... multiple values */ return; - type_error: +type_error: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_DESCRIPTOR); DUK_WO_NORETURN(return;); } @@ -62155,7 +63356,7 @@ duk_bool_t force_flag; duk_small_uint_t new_flags; duk_propdesc curr; - duk_uint32_t arridx_new_array_length; /* != 0 => post-update for array 'length' (used when key is an array index) */ + duk_uint32_t arridx_new_array_length; /* != 0 => post-update for array 'length' (used when key is an array index) */ duk_uint32_t arrlen_old_len; duk_uint32_t arrlen_new_len; duk_bool_t pending_write_protect; @@ -62195,13 +63396,22 @@ "has_get=%ld get=%p=%!O " "has_set=%ld set=%p=%!O " "arr_idx=%ld throw_flag=!%ld", - (long) has_enumerable, (long) is_enumerable, - (long) has_configurable, (long) is_configurable, - (long) has_writable, (long) is_writable, - (long) has_value, (duk_tval *) (idx_value >= 0 ? duk_get_tval(thr, idx_value) : NULL), - (long) has_get, (void *) get, (duk_heaphdr *) get, - (long) has_set, (void *) set, (duk_heaphdr *) set, - (long) arr_idx, (long) throw_flag)); + (long) has_enumerable, + (long) is_enumerable, + (long) has_configurable, + (long) is_configurable, + (long) has_writable, + (long) is_writable, + (long) has_value, + (duk_tval *) (idx_value >= 0 ? duk_get_tval(thr, idx_value) : NULL), + (long) has_get, + (void *) get, + (duk_heaphdr *) get, + (long) has_set, + (void *) set, + (duk_heaphdr *) set, + (long) arr_idx, + (long) throw_flag)); /* * Array exotic behaviors can be implemented at this point. The local variables @@ -62235,7 +63445,7 @@ DUK_ASSERT(idx_value >= 0); arrlen_new_len = duk__to_new_array_length_checked(thr, DUK_GET_TVAL_POSIDX(thr, idx_value)); duk_push_u32(thr, arrlen_new_len); - duk_replace(thr, idx_value); /* step 3.e: replace 'Desc.Value' */ + duk_replace(thr, idx_value); /* step 3.e: replace 'Desc.Value' */ DUK_DDD(DUK_DDDPRINT("old_len=%ld, new_len=%ld", (long) arrlen_old_len, (long) arrlen_new_len)); @@ -62277,7 +63487,8 @@ if (arr_idx >= old_len) { DUK_DDD(DUK_DDDPRINT("defineProperty requires array length update " "(arr_idx=%ld, old_len=%ld)", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); if (DUK_HARRAY_LENGTH_NONWRITABLE(a) && !force_flag) { /* Array .length is always non-configurable, so @@ -62295,10 +63506,11 @@ } else { DUK_DDD(DUK_DDDPRINT("defineProperty does not require length update " "(arr_idx=%ld, old_len=%ld) -> standard behavior", - (long) arr_idx, (long) old_len)); + (long) arr_idx, + (long) old_len)); } } - skip_array_exotic: +skip_array_exotic: /* XXX: There is currently no support for writing buffer object * indexed elements here. Attempt to do so will succeed and @@ -62350,7 +63562,7 @@ DUK_ASSERT(!has_value); DUK_ASSERT(!has_writable); - new_flags = DUK_PROPDESC_FLAG_ACCESSOR; /* defaults, E5 Section 8.6.1, Table 7 */ + new_flags = DUK_PROPDESC_FLAG_ACCESSOR; /* defaults, E5 Section 8.6.1, Table 7 */ if (has_enumerable && is_enumerable) { new_flags |= DUK_PROPDESC_FLAG_ENUMERABLE; } @@ -62383,7 +63595,7 @@ DUK_ASSERT(!has_set); DUK_ASSERT(!has_get); - new_flags = 0; /* defaults, E5 Section 8.6.1, Table 7 */ + new_flags = 0; /* defaults, E5 Section 8.6.1, Table 7 */ if (has_writable && is_writable) { new_flags |= DUK_PROPDESC_FLAG_WRITABLE; } @@ -62397,12 +63609,13 @@ duk_tval *tv_tmp = duk_require_tval(thr, idx_value); DUK_TVAL_SET_TVAL(&tv, tv_tmp); } else { - DUK_TVAL_SET_UNDEFINED(&tv); /* default value */ + DUK_TVAL_SET_UNDEFINED(&tv); /* default value */ } if (arr_idx != DUK__NO_ARRAY_INDEX && DUK_HOBJECT_HAS_ARRAY_PART(obj)) { if (new_flags == DUK_PROPDESC_FLAGS_WEC) { - DUK_DDD(DUK_DDDPRINT("new data property attributes match array defaults, attempt to write to array part")); + DUK_DDD(DUK_DDDPRINT( + "new data property attributes match array defaults, attempt to write to array part")); tv2 = duk__obtain_arridx_slot(thr, arr_idx, obj); if (tv2 == NULL) { DUK_DDD(DUK_DDDPRINT("failed writing to array part, abandoned array")); @@ -62475,8 +63688,8 @@ goto need_check; } - tmp1 = duk_require_tval(thr, -1); /* curr value */ - tmp2 = duk_require_tval(thr, idx_value); /* new value */ + tmp1 = duk_require_tval(thr, -1); /* curr value */ + tmp2 = duk_require_tval(thr, idx_value); /* new value */ if (!duk_js_samevalue(tmp1, tmp2)) { goto need_check; } @@ -62521,7 +63734,7 @@ */ goto success_no_exotics; - need_check: +need_check: /* * Some change(s) need to be made. Steps 7-11. @@ -62593,9 +63806,10 @@ DUK_DDD(DUK_DDDPRINT("convert property to accessor property")); if (curr.a_idx >= 0) { - DUK_DDD(DUK_DDDPRINT("property to convert is stored in an array entry, abandon array and re-lookup")); + DUK_DDD( + DUK_DDDPRINT("property to convert is stored in an array entry, abandon array and re-lookup")); duk__abandon_array_part(thr, obj); - duk_pop_unsafe(thr); /* remove old value */ + duk_pop_unsafe(thr); /* remove old value */ rc = duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &curr, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); DUK_ASSERT(rc != 0); @@ -62603,14 +63817,14 @@ } if (curr.e_idx < 0) { DUK_ASSERT(curr.a_idx < 0 && curr.e_idx < 0); - goto fail_virtual; /* safeguard for virtual property */ + goto fail_virtual; /* safeguard for virtual property */ } DUK_ASSERT(curr.e_idx >= 0); DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, curr.e_idx)); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, curr.e_idx); - DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ(thr, tv1); /* XXX: just decref */ + DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ(thr, tv1); /* XXX: just decref */ DUK_HOBJECT_E_SET_VALUE_GETTER(thr->heap, obj, curr.e_idx, NULL); DUK_HOBJECT_E_SET_VALUE_SETTER(thr->heap, obj, curr.e_idx, NULL); @@ -62639,7 +63853,7 @@ /* curr is accessor -> cannot be in array part. */ DUK_ASSERT(curr.a_idx < 0); if (curr.e_idx < 0) { - goto fail_virtual; /* safeguard; no virtual accessors now */ + goto fail_virtual; /* safeguard; no virtual accessors now */ } DUK_DDD(DUK_DDDPRINT("convert property to data property")); @@ -62671,8 +63885,8 @@ } /* Note: changing from writable to non-writable is OK */ if (!(curr.flags & DUK_PROPDESC_FLAG_WRITABLE) && has_value) { - duk_tval *tmp1 = duk_require_tval(thr, -1); /* curr value */ - duk_tval *tmp2 = duk_require_tval(thr, idx_value); /* new value */ + duk_tval *tmp1 = duk_require_tval(thr, -1); /* curr value */ + duk_tval *tmp2 = duk_require_tval(thr, idx_value); /* new value */ if (!duk_js_samevalue(tmp1, tmp2)) { goto fail_not_configurable; } @@ -62721,8 +63935,7 @@ /* XXX: write protect after flag? -> any chance of handling it here? */ - DUK_DDD(DUK_DDDPRINT("new flags that we want to write: 0x%02lx", - (unsigned long) new_flags)); + DUK_DDD(DUK_DDDPRINT("new flags that we want to write: 0x%02lx", (unsigned long) new_flags)); /* * Check whether we need to abandon an array part (if it exists) @@ -62738,20 +63951,23 @@ DUK_DDD(DUK_DDDPRINT("array index, new property attributes match array defaults, update in-place")); - DUK_ASSERT(curr.flags == DUK_PROPDESC_FLAGS_WEC); /* must have been, since in array part */ + DUK_ASSERT(curr.flags == DUK_PROPDESC_FLAGS_WEC); /* must have been, since in array part */ DUK_ASSERT(!has_set); DUK_ASSERT(!has_get); - DUK_ASSERT(idx_value >= 0); /* must be: if attributes match and we get here the value must differ (otherwise no change) */ + DUK_ASSERT( + idx_value >= + 0); /* must be: if attributes match and we get here the value must differ (otherwise no change) */ tv2 = duk_require_tval(thr, idx_value); tv1 = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, obj, curr.a_idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate a_idx */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate a_idx */ goto success_exotics; } - DUK_DDD(DUK_DDDPRINT("array index, new property attributes do not match array defaults, abandon array and re-lookup")); + DUK_DDD( + DUK_DDDPRINT("array index, new property attributes do not match array defaults, abandon array and re-lookup")); duk__abandon_array_part(thr, obj); - duk_pop_unsafe(thr); /* remove old value */ + duk_pop_unsafe(thr); /* remove old value */ rc = duk__get_own_propdesc_raw(thr, obj, key, arr_idx, &curr, DUK_GETDESC_FLAG_PUSH_VALUE); DUK_UNREF(rc); DUK_ASSERT(rc != 0); @@ -62775,10 +63991,12 @@ if (key == DUK_HTHREAD_STRING_LENGTH(thr) && DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)) { duk_harray *a; a = (duk_harray *) obj; - DUK_DD(DUK_DDPRINT("Object.defineProperty() attribute update for duk_harray .length -> %02lx", (unsigned long) new_flags)); + DUK_DD(DUK_DDPRINT("Object.defineProperty() attribute update for duk_harray .length -> %02lx", + (unsigned long) new_flags)); DUK_HARRAY_ASSERT_VALID(a); if ((new_flags & DUK_PROPDESC_FLAGS_EC) != (curr.flags & DUK_PROPDESC_FLAGS_EC)) { - DUK_D(DUK_DPRINT("Object.defineProperty() attempt to change virtual array .length enumerable or configurable attribute, fail")); + DUK_D(DUK_DPRINT("Object.defineProperty() attempt to change virtual array .length enumerable or " + "configurable attribute, fail")); goto fail_virtual; } if (new_flags & DUK_PROPDESC_FLAG_WRITABLE) { @@ -62806,7 +64024,7 @@ DUK_UNREF(tmp); DUK_HOBJECT_E_SET_VALUE_SETTER(thr->heap, obj, curr.e_idx, set); DUK_HOBJECT_INCREF_ALLOWNULL(thr, set); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ } if (has_get) { duk_hobject *tmp; @@ -62822,7 +64040,7 @@ DUK_UNREF(tmp); DUK_HOBJECT_E_SET_VALUE_GETTER(thr->heap, obj, curr.e_idx, get); DUK_HOBJECT_INCREF_ALLOWNULL(thr, get); - DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ + DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); /* side effects; may invalidate e_idx */ } if (has_value) { duk_tval *tv1, *tv2; @@ -62833,9 +64051,9 @@ DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, obj, curr.e_idx)); tv2 = duk_require_tval(thr, idx_value); tv1 = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, obj, curr.e_idx); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate e_idx */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects; may invalidate e_idx */ } else { - DUK_ASSERT(curr.a_idx < 0); /* array part case handled comprehensively previously */ + DUK_ASSERT(curr.a_idx < 0); /* array part case handled comprehensively previously */ DUK_DD(DUK_DDPRINT("Object.defineProperty(), value update for virtual property")); /* XXX: Uint8Array and other typed array virtual writes not currently @@ -62844,11 +64062,12 @@ if (key == DUK_HTHREAD_STRING_LENGTH(thr) && DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)) { duk_harray *a; a = (duk_harray *) obj; - DUK_DD(DUK_DDPRINT("Object.defineProperty() value update for duk_harray .length -> %ld", (long) arrlen_new_len)); + DUK_DD(DUK_DDPRINT("Object.defineProperty() value update for duk_harray .length -> %ld", + (long) arrlen_new_len)); DUK_HARRAY_ASSERT_VALID(a); a->length = arrlen_new_len; } else { - goto fail_virtual; /* should not happen */ + goto fail_virtual; /* should not happen */ } } } @@ -62865,7 +64084,7 @@ * - for 'length' key the element deletion and 'length' update occurs here */ - success_exotics: +success_exotics: /* curr.a_idx or curr.e_idx may have been invalidated by side effects * above. @@ -62909,7 +64128,8 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key is 'length', exotic array behavior, " "doing array element deletion and length update")); - rc = duk__handle_put_array_length_smaller(thr, obj, arrlen_old_len, arrlen_new_len, force_flag, &result_len); + rc = + duk__handle_put_array_length_smaller(thr, obj, arrlen_old_len, arrlen_new_len, force_flag, &result_len); /* update length (curr points to length, and we assume it's still valid) */ DUK_ASSERT(result_len >= arrlen_new_len && result_len <= arrlen_old_len); @@ -62932,7 +64152,7 @@ duk_hobject *varenv; DUK_ASSERT(arridx_new_array_length == 0); - DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)); /* traits are separate; in particular, arguments not an array */ + DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(obj)); /* traits are separate; in particular, arguments not an array */ map = NULL; varenv = NULL; @@ -62949,7 +64169,7 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map' " "changed to an accessor, delete arguments binding")); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ } else { /* Note: this order matters (final value before deleting map entry must be done) */ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map', " @@ -62977,7 +64197,7 @@ DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map', " "changed to non-writable, delete arguments binding")); - (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ + (void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */ } } @@ -62986,22 +64206,22 @@ */ } - success_no_exotics: +success_no_exotics: /* Some code paths use NORZ macros for simplicity, ensure refzero * handling is completed. */ DUK_REFZERO_CHECK_SLOW(thr); return 1; - fail_not_extensible: +fail_not_extensible: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_EXTENSIBLE); DUK_WO_NORETURN(return 0;); } return 0; - fail_virtual: /* just use the same "not configurable" error message" */ - fail_not_configurable: +fail_virtual: /* just use the same "not configurable" error message" */ +fail_not_configurable: if (throw_flag) { DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE); DUK_WO_NORETURN(return 0;); @@ -63026,7 +64246,7 @@ h_obj = duk_push_this_coercible_to_object(thr); DUK_ASSERT(h_obj != NULL); - ret = duk_hobject_get_own_propdesc(thr, h_obj, h_v, &desc, 0 /*flags*/); /* don't push value */ + ret = duk_hobject_get_own_propdesc(thr, h_obj, h_v, &desc, 0 /*flags*/); /* don't push value */ duk_push_boolean(thr, ret && ((desc.flags & required_desc_flags) == required_desc_flags)); return 1; @@ -63140,9 +64360,7 @@ if (flags & DUK_PROPDESC_FLAG_CONFIGURABLE) { return 0; } - if (is_frozen && - !(flags & DUK_PROPDESC_FLAG_ACCESSOR) && - (flags & DUK_PROPDESC_FLAG_WRITABLE)) { + if (is_frozen && !(flags & DUK_PROPDESC_FLAG_ACCESSOR) && (flags & DUK_PROPDESC_FLAG_WRITABLE)) { return 0; } } @@ -63186,7 +64404,7 @@ DUK_ASSERT(h != NULL); } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ #line 1 "duk_hstring_misc.c" /* * Misc support functions @@ -63198,7 +64416,10 @@ * duk_hstring charCodeAt, with and without surrogate awareness */ -DUK_INTERNAL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, duk_hstring *h, duk_uint_t pos, duk_bool_t surrogate_aware) { +DUK_INTERNAL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, + duk_hstring *h, + duk_uint_t pos, + duk_bool_t surrogate_aware) { duk_uint32_t boff; const duk_uint8_t *p, *p_start, *p_end; duk_ucodepoint_t cp1; @@ -63207,21 +64428,18 @@ /* Caller must check character offset to be inside the string. */ DUK_ASSERT(thr != NULL); DUK_ASSERT(h != NULL); - DUK_ASSERT_DISABLE(pos >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(pos >= 0); /* unsigned */ DUK_ASSERT(pos < (duk_uint_t) DUK_HSTRING_GET_CHARLEN(h)); boff = (duk_uint32_t) duk_heap_strcache_offset_char2byte(thr, h, (duk_uint32_t) pos); - DUK_DDD(DUK_DDDPRINT("charCodeAt: pos=%ld -> boff=%ld, str=%!O", - (long) pos, (long) boff, (duk_heaphdr *) h)); + DUK_DDD(DUK_DDDPRINT("charCodeAt: pos=%ld -> boff=%ld, str=%!O", (long) pos, (long) boff, (duk_heaphdr *) h)); DUK_ASSERT_DISABLE(boff >= 0); DUK_ASSERT(boff < DUK_HSTRING_GET_BYTELEN(h)); p_start = DUK_HSTRING_GET_DATA(h); p_end = p_start + DUK_HSTRING_GET_BYTELEN(h); p = p_start + boff; - DUK_DDD(DUK_DDDPRINT("p_start=%p, p_end=%p, p=%p", - (const void *) p_start, (const void *) p_end, - (const void *) p)); + DUK_DDD(DUK_DDDPRINT("p_start=%p, p_end=%p, p=%p", (const void *) p_start, (const void *) p_end, (const void *) p)); /* For invalid UTF-8 (never happens for standard ECMAScript strings) * return U+FFFD replacement character. @@ -63232,7 +64450,7 @@ * decoded at the end of the string and 'p' is no longer * within string memory range. */ - cp2 = 0; /* If call fails, this is left untouched and won't match cp2 check. */ + cp2 = 0; /* If call fails, this is left untouched and won't match cp2 check. */ (void) duk_unicode_decode_xutf8(thr, &p, p_start, p_end, &cp2); if (cp2 >= 0xdc00UL && cp2 <= 0xdfffUL) { cp1 = (duk_ucodepoint_t) (((cp1 - 0xd800UL) << 10) + (cp2 - 0xdc00UL) + 0x10000UL); @@ -63262,7 +64480,7 @@ clen = duk_unicode_unvalidated_utf8_length(DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); #if defined(DUK_USE_STRLEN16) - DUK_ASSERT(clen <= 0xffffUL); /* Bytelength checked during interning. */ + DUK_ASSERT(clen <= 0xffffUL); /* Bytelength checked during interning. */ h->clen16 = (duk_uint16_t) clen; #else h->clen = (duk_uint32_t) clen; @@ -63279,7 +64497,7 @@ return h->clen; #endif } -#endif /* !DUK_USE_HSTRING_LAZY_CLEN */ +#endif /* !DUK_USE_HSTRING_LAZY_CLEN */ /* * duk_hstring charlen, when lazy charlen enabled @@ -63290,7 +64508,7 @@ DUK_LOCAL DUK_COLD duk_size_t duk__hstring_get_charlen_slowpath(duk_hstring *h) { duk_size_t res; - DUK_ASSERT(h->clen == 0); /* Checked by caller. */ + DUK_ASSERT(h->clen == 0); /* Checked by caller. */ #if defined(DUK_USE_ROM_STRINGS) /* ROM strings have precomputed clen, but if the computed clen is zero @@ -63303,7 +64521,7 @@ res = duk_unicode_unvalidated_utf8_length(DUK_HSTRING_GET_DATA(h), DUK_HSTRING_GET_BYTELEN(h)); #if defined(DUK_USE_STRLEN16) - DUK_ASSERT(res <= 0xffffUL); /* Bytelength checked during interning. */ + DUK_ASSERT(res <= 0xffffUL); /* Bytelength checked during interning. */ h->clen16 = (duk_uint16_t) res; #else h->clen = (duk_uint32_t) res; @@ -63313,7 +64531,7 @@ } return res; } -#else /* DUK_USE_HSTRING_CLEN */ +#else /* DUK_USE_HSTRING_CLEN */ DUK_LOCAL duk_size_t duk__hstring_get_charlen_slowpath(duk_hstring *h) { if (DUK_LIKELY(DUK_HSTRING_HAS_ASCII(h))) { /* Most practical strings will go here. */ @@ -63342,7 +64560,7 @@ return res; } } -#endif /* DUK_USE_HSTRING_CLEN */ +#endif /* DUK_USE_HSTRING_CLEN */ #if defined(DUK_USE_HSTRING_CLEN) DUK_INTERNAL DUK_HOT duk_size_t duk_hstring_get_charlen(duk_hstring *h) { @@ -63357,13 +64575,13 @@ #endif return duk__hstring_get_charlen_slowpath(h); } -#else /* DUK_USE_HSTRING_CLEN */ +#else /* DUK_USE_HSTRING_CLEN */ DUK_INTERNAL DUK_HOT duk_size_t duk_hstring_get_charlen(duk_hstring *h) { /* Always use slow path. */ return duk__hstring_get_charlen_slowpath(h); } -#endif /* DUK_USE_HSTRING_CLEN */ -#endif /* DUK_USE_HSTRING_LAZY_CLEN */ +#endif /* DUK_USE_HSTRING_CLEN */ +#endif /* DUK_USE_HSTRING_LAZY_CLEN */ /* * Compare duk_hstring to an ASCII cstring. @@ -63429,7 +64647,7 @@ return 1; - fail: +fail: DUK_FREE(heap, thr->valstack); DUK_ASSERT(thr->callstack_curr == NULL); @@ -63457,21 +64675,21 @@ * Encoding constants, must match genbuiltins.py */ -#define DUK__PROP_FLAGS_BITS 3 -#define DUK__LENGTH_PROP_BITS 3 -#define DUK__NARGS_BITS 3 -#define DUK__PROP_TYPE_BITS 3 - -#define DUK__NARGS_VARARGS_MARKER 0x07 - -#define DUK__PROP_TYPE_DOUBLE 0 -#define DUK__PROP_TYPE_STRING 1 -#define DUK__PROP_TYPE_STRIDX 2 -#define DUK__PROP_TYPE_BUILTIN 3 -#define DUK__PROP_TYPE_UNDEFINED 4 -#define DUK__PROP_TYPE_BOOLEAN_TRUE 5 -#define DUK__PROP_TYPE_BOOLEAN_FALSE 6 -#define DUK__PROP_TYPE_ACCESSOR 7 +#define DUK__PROP_FLAGS_BITS 3 +#define DUK__LENGTH_PROP_BITS 3 +#define DUK__NARGS_BITS 3 +#define DUK__PROP_TYPE_BITS 3 + +#define DUK__NARGS_VARARGS_MARKER 0x07 + +#define DUK__PROP_TYPE_DOUBLE 0 +#define DUK__PROP_TYPE_STRING 1 +#define DUK__PROP_TYPE_STRIDX 2 +#define DUK__PROP_TYPE_BUILTIN 3 +#define DUK__PROP_TYPE_UNDEFINED 4 +#define DUK__PROP_TYPE_BOOLEAN_TRUE 5 +#define DUK__PROP_TYPE_BOOLEAN_FALSE 6 +#define DUK__PROP_TYPE_ACCESSOR 7 /* * Create built-in objects by parsing an init bitstream generated @@ -63494,9 +64712,8 @@ #if defined(DUK_USE_ROM_GLOBAL_INHERIT) /* Inherit from ROM-based global object: less RAM usage, less transparent. */ h_global = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), DUK_BIDX_GLOBAL); DUK_ASSERT(h_global != NULL); #elif defined(DUK_USE_ROM_GLOBAL_CLONE) @@ -63505,9 +64722,8 @@ * model but more compliant. */ h_global = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_GLOBAL), DUK_BIDX_OBJECT_PROTOTYPE); DUK_ASSERT(h_global != NULL); h_oldglobal = thr->builtinsDUK_BIDX_GLOBAL; @@ -63541,7 +64757,8 @@ duk_hobject_compact_props(thr, h_global); DUK_ASSERT(thr->builtinsDUK_BIDX_GLOBAL != NULL); - DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL)); /* no need to decref: ROM object */ + DUK_ASSERT( + !DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL)); /* no need to decref: ROM object */ thr->builtinsDUK_BIDX_GLOBAL = h_global; DUK_HOBJECT_INCREF(thr, h_global); DUK_D(DUK_DPRINT("duplicated global object: %!O", h_global)); @@ -63550,9 +64767,9 @@ * needed so that the global scope points to the newly created RAM-based * global object. */ - h_objenv = (duk_hobject *) duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + h_objenv = + (duk_hobject *) duk_hobjenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(h_objenv != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_objenv) == NULL); duk_push_hobject(thr, h_objenv); @@ -63563,16 +64780,17 @@ DUK_ASSERT(((duk_hobjenv *) h_objenv)->has_this == 0); DUK_ASSERT(thr->builtinsDUK_BIDX_GLOBAL_ENV != NULL); - DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE((duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL_ENV)); /* no need to decref: ROM object */ + DUK_ASSERT(!DUK_HEAPHDR_NEEDS_REFCOUNT_UPDATE( + (duk_heaphdr *) thr->builtinsDUK_BIDX_GLOBAL_ENV)); /* no need to decref: ROM object */ thr->builtinsDUK_BIDX_GLOBAL_ENV = h_objenv; DUK_HOBJECT_INCREF(thr, h_objenv); DUK_D(DUK_DPRINT("duplicated global env: %!O", h_objenv)); DUK_HOBJENV_ASSERT_VALID((duk_hobjenv *) h_objenv); - duk_pop_2(thr); /* Pop global object and global env. */ + duk_pop_2(thr); /* Pop global object and global env. */ } -#endif /* DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT */ +#endif /* DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT */ DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { /* Setup builtins from ROM objects. All heaps/threads will share @@ -63596,12 +64814,12 @@ duk__duplicate_ram_global_object(thr); #endif } -#else /* DUK_USE_ROM_OBJECTS */ +#else /* DUK_USE_ROM_OBJECTS */ DUK_LOCAL void duk__push_stridx(duk_hthread *thr, duk_bitdecoder_ctx *bd) { duk_small_uint_t n; n = (duk_small_uint_t) duk_bd_decode_varuint(bd); - DUK_ASSERT_DISABLE(n >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(n >= 0); /* unsigned */ DUK_ASSERT(n < DUK_HEAP_NUM_STRINGS); duk_push_hstring_stridx(thr, n); } @@ -63638,16 +64856,18 @@ du.uci = (duk_uint8_t) duk_bd_decode(bd, 8); } - duk_push_number(thr, du.d); /* push operation normalizes NaNs */ + duk_push_number(thr, du.d); /* push operation normalizes NaNs */ } DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { duk_bitdecoder_ctx bd_ctx; - duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ + duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */ duk_hobject *h; duk_small_uint_t i, j; - DUK_D(DUK_DPRINT("INITBUILTINS BEGIN: DUK_NUM_BUILTINS=%d, DUK_NUM_BUILTINS_ALL=%d", (int) DUK_NUM_BUILTINS, (int) DUK_NUM_ALL_BUILTINS)); + DUK_D(DUK_DPRINT("INITBUILTINS BEGIN: DUK_NUM_BUILTINS=%d, DUK_NUM_BUILTINS_ALL=%d", + (int) DUK_NUM_BUILTINS, + (int) DUK_NUM_ALL_BUILTINS)); duk_memzero(&bd_ctx, sizeof(bd_ctx)); bd->data = (const duk_uint8_t *) duk_builtins_data; @@ -63674,14 +64894,14 @@ DUK_ASSERT_TOP(thr, 0); for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) { duk_small_uint_t class_num; - duk_small_int_t len = -1; /* must be signed */ + duk_small_int_t len = -1; /* must be signed */ class_num = (duk_small_uint_t) duk_bd_decode_varuint(bd); len = (duk_small_int_t) duk_bd_decode_flagged_signed(bd, DUK__LENGTH_PROP_BITS, (duk_int32_t) -1 /*def_value*/); if (class_num == DUK_HOBJECT_CLASS_FUNCTION) { duk_small_uint_t natidx; - duk_small_int_t c_nargs; /* must hold DUK_VARARGS */ + duk_small_int_t c_nargs; /* must hold DUK_VARARGS */ duk_c_function c_func; duk_int16_t magic; @@ -63712,12 +64932,9 @@ duk__push_stridx_or_string(thr, bd); #if defined(DUK_USE_FUNC_NAME_PROPERTY) - duk_xdef_prop_stridx_short(thr, - -2, - DUK_STRIDX_NAME, - DUK_PROPDESC_FLAGS_C); + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); #else - duk_pop(thr); /* Not very ideal but good enough for now. */ + duk_pop(thr); /* Not very ideal but good enough for now. */ #endif /* Almost all global level Function objects are constructable @@ -63743,8 +64960,7 @@ DUK_ASSERT(DUK_BIDX_GLOBAL_ENV > DUK_BIDX_GLOBAL); env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(env->target == NULL); duk_push_hobject(thr, (duk_hobject *) env); @@ -63759,10 +64975,8 @@ DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_DECENV); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_EXTENSIBLE, - -1); /* no prototype or class yet */ - + DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_EXTENSIBLE, + -1); /* no prototype or class yet */ } h = duk_known_hobject(thr, -1); @@ -63784,18 +64998,15 @@ * not encoded explicitly in init data. */ - DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_ARRAY); /* .length is virtual */ + DUK_ASSERT(class_num != DUK_HOBJECT_CLASS_ARRAY); /* .length is virtual */ duk_push_int(thr, len); - duk_xdef_prop_stridx_short(thr, - -2, - DUK_STRIDX_LENGTH, - DUK_PROPDESC_FLAGS_C); + duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); } /* enable exotic behaviors last */ if (class_num == DUK_HOBJECT_CLASS_ARRAY) { - DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)); /* set by duk_push_array() */ + DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY(h)); /* set by duk_push_array() */ } if (class_num == DUK_HOBJECT_CLASS_STRING) { DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h); @@ -63812,7 +65023,7 @@ DUK_ASSERT(!DUK_HOBJECT_IS_PROXY(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(h) || class_num == DUK_HOBJECT_CLASS_ARRAY); /* DUK_HOBJECT_FLAG_STRICT varies */ - DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(h) || /* all native functions have NEWENV */ + DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(h) || /* all native functions have NEWENV */ DUK_HOBJECT_HAS_NEWENV(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_NAMEBINDING(h)); DUK_ASSERT(!DUK_HOBJECT_HAS_CREATEARGS(h)); @@ -63895,11 +65106,9 @@ defprop_flags = (duk_small_uint_t) duk_bd_decode_flagged(bd, DUK__PROP_FLAGS_BITS, (duk_uint32_t) DUK_PROPDESC_FLAGS_WC); - defprop_flags |= DUK_DEFPROP_FORCE | - DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | + defprop_flags |= DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE | - DUK_DEFPROP_HAVE_CONFIGURABLE; /* Defaults for data properties. */ + DUK_DEFPROP_HAVE_CONFIGURABLE; /* Defaults for data properties. */ /* The writable, enumerable, configurable flags in prop_flags * match both duk_def_prop() and internal property flags. @@ -63911,7 +65120,11 @@ t = (duk_small_uint_t) duk_bd_decode(bd, DUK__PROP_TYPE_BITS); DUK_DDD(DUK_DDDPRINT("built-in %ld, normal-valued property %ld, key %!T, flags 0x%02lx, type %ld", - (long) i, (long) j, duk_get_tval(thr, -1), (unsigned long) defprop_flags, (long) t)); + (long) i, + (long) j, + duk_get_tval(thr, -1), + (unsigned long) defprop_flags, + (long) t)); switch (t) { case DUK__PROP_TYPE_DOUBLE: { @@ -63952,24 +65165,29 @@ duk_c_function c_func_getter; duk_c_function c_func_setter; - DUK_DDD(DUK_DDDPRINT("built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx", - (long) i, duk_get_tval(thr, -1), (long) natidx_getter, (long) natidx_setter, (unsigned long) defprop_flags)); + DUK_DDD(DUK_DDDPRINT( + "built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx", + (long) i, + duk_get_tval(thr, -1), + (long) natidx_getter, + (long) natidx_setter, + (unsigned long) defprop_flags)); c_func_getter = duk_bi_native_functionsnatidx_getter; if (c_func_getter != NULL) { - duk_push_c_function_builtin_noconstruct(thr, c_func_getter, 0); /* always 0 args */ + duk_push_c_function_builtin_noconstruct(thr, c_func_getter, 0); /* always 0 args */ duk_set_magic(thr, -1, (duk_int_t) accessor_magic); defprop_flags |= DUK_DEFPROP_HAVE_GETTER; } c_func_setter = duk_bi_native_functionsnatidx_setter; if (c_func_setter != NULL) { - duk_push_c_function_builtin_noconstruct(thr, c_func_setter, 1); /* always 1 arg */ + duk_push_c_function_builtin_noconstruct(thr, c_func_setter, 1); /* always 1 arg */ duk_set_magic(thr, -1, (duk_int_t) accessor_magic); defprop_flags |= DUK_DEFPROP_HAVE_SETTER; } /* Writable flag doesn't make sense for an accessor. */ - DUK_ASSERT((defprop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */ + DUK_ASSERT((defprop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */ defprop_flags &= ~(DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE); defprop_flags |= DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE; @@ -63991,7 +65209,7 @@ for (j = 0; j < num; j++) { duk_hstring *h_key; duk_small_uint_t natidx; - duk_int_t c_nargs; /* must hold DUK_VARARGS */ + duk_int_t c_nargs; /* must hold DUK_VARARGS */ duk_small_uint_t c_length; duk_int16_t magic; duk_c_function c_func; @@ -64014,51 +65232,66 @@ c_func = duk_bi_native_functionsnatidx; - DUK_DDD(DUK_DDDPRINT("built-in %ld, function-valued property %ld, key %!O, natidx %ld, length %ld, nargs %ld", - (long) i, (long) j, (duk_heaphdr *) h_key, (long) natidx, (long) c_length, - (c_nargs == DUK_VARARGS ? (long) -1 : (long) c_nargs))); + DUK_DDD( + DUK_DDDPRINT("built-in %ld, function-valued property %ld, key %!O, natidx %ld, length %ld, nargs %ld", + (long) i, + (long) j, + (duk_heaphdr *) h_key, + (long) natidx, + (long) c_length, + (c_nargs == DUK_VARARGS ? (long) -1 : (long) c_nargs))); /* Cast converts magic to 16-bit signed value */ magic = (duk_int16_t) duk_bd_decode_varuint(bd); #if defined(DUK_USE_LIGHTFUNC_BUILTINS) lightfunc_eligible = - ((c_nargs >= DUK_LFUNC_NARGS_MIN && c_nargs <= DUK_LFUNC_NARGS_MAX) || (c_nargs == DUK_VARARGS)) && - (c_length <= DUK_LFUNC_LENGTH_MAX) && - (magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX); + ((c_nargs >= DUK_LFUNC_NARGS_MIN && c_nargs <= DUK_LFUNC_NARGS_MAX) || (c_nargs == DUK_VARARGS)) && + (c_length <= DUK_LFUNC_LENGTH_MAX) && (magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX); /* These functions have trouble working as lightfuncs. * Some of them have specific asserts and some may have - * additional properties (e.g. 'require.id' may be written). + * additional properties (e.g. 'require.id' may be written). */ if (c_func == duk_bi_global_object_eval) { lightfunc_eligible = 0; } #if defined(DUK_USE_COROUTINE_SUPPORT) - if (c_func == duk_bi_thread_yield || - c_func == duk_bi_thread_resume) { + if (c_func == duk_bi_thread_yield || c_func == duk_bi_thread_resume) { lightfunc_eligible = 0; } #endif - if (c_func == duk_bi_function_prototype_call || - c_func == duk_bi_function_prototype_apply || - c_func == duk_bi_reflect_apply || - c_func == duk_bi_reflect_construct) { + if (c_func == duk_bi_function_prototype_call || c_func == duk_bi_function_prototype_apply || + c_func == duk_bi_reflect_apply || c_func == duk_bi_reflect_construct) { lightfunc_eligible = 0; } if (lightfunc_eligible) { duk_tval tv_lfunc; - duk_small_uint_t lf_nargs = (duk_small_uint_t) (c_nargs == DUK_VARARGS ? DUK_LFUNC_NARGS_VARARGS : c_nargs); + duk_small_uint_t lf_nargs = + (duk_small_uint_t) (c_nargs == DUK_VARARGS ? DUK_LFUNC_NARGS_VARARGS : c_nargs); duk_small_uint_t lf_flags = DUK_LFUNC_FLAGS_PACK(magic, c_length, lf_nargs); DUK_TVAL_SET_LIGHTFUNC(&tv_lfunc, c_func, lf_flags); duk_push_tval(thr, &tv_lfunc); - DUK_D(DUK_DPRINT("built-in function eligible as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld -> %!iT", (int) i, (int) j, (long) c_length, (long) c_nargs, (long) magic, duk_get_tval(thr, -1))); + DUK_D(DUK_DPRINT("built-in function eligible as light function: i=%d, j=%d c_length=%ld, " + "c_nargs=%ld, magic=%ld -> %!iT", + (int) i, + (int) j, + (long) c_length, + (long) c_nargs, + (long) magic, + duk_get_tval(thr, -1))); goto lightfunc_skip; } - DUK_D(DUK_DPRINT("built-in function NOT ELIGIBLE as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld", (int) i, (int) j, (long) c_length, (long) c_nargs, (long) magic)); -#endif /* DUK_USE_LIGHTFUNC_BUILTINS */ + DUK_D(DUK_DPRINT( + "built-in function NOT ELIGIBLE as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld", + (int) i, + (int) j, + (long) c_length, + (long) c_nargs, + (long) magic)); +#endif /* DUK_USE_LIGHTFUNC_BUILTINS */ /* (builtin objects) name */ @@ -64069,10 +65302,8 @@ /* XXX: add into init data? */ /* Special call handling, not described in init data. */ - if (c_func == duk_bi_global_object_eval || - c_func == duk_bi_function_prototype_call || - c_func == duk_bi_function_prototype_apply || - c_func == duk_bi_reflect_apply || + if (c_func == duk_bi_global_object_eval || c_func == duk_bi_function_prototype_call || + c_func == duk_bi_function_prototype_apply || c_func == duk_bi_reflect_apply || c_func == duk_bi_reflect_construct) { DUK_HOBJECT_SET_SPECIAL_CALL((duk_hobject *) h_func); } @@ -64106,7 +65337,9 @@ /* XXX: other properties of function instances; 'arguments', 'caller'. */ DUK_DD(DUK_DDPRINT("built-in object %ld, function property %ld -> %!T", - (long) i, (long) j, (duk_tval *) duk_get_tval(thr, -1))); + (long) i, + (long) j, + (duk_tval *) duk_get_tval(thr, -1))); /* (builtin objects) name func */ @@ -64116,17 +65349,14 @@ */ #if defined(DUK_USE_LIGHTFUNC_BUILTINS) - lightfunc_skip: + lightfunc_skip: #endif defprop_flags = (duk_small_uint_t) duk_bd_decode_flagged(bd, DUK__PROP_FLAGS_BITS, (duk_uint32_t) DUK_PROPDESC_FLAGS_WC); - defprop_flags |= DUK_DEFPROP_FORCE | - DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_HAVE_WRITABLE | - DUK_DEFPROP_HAVE_ENUMERABLE | - DUK_DEFPROP_HAVE_CONFIGURABLE; + defprop_flags |= DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE | + DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE; DUK_ASSERT(DUK_PROPDESC_FLAG_WRITABLE == DUK_DEFPROP_WRITABLE); DUK_ASSERT(DUK_PROPDESC_FLAG_ENUMERABLE == DUK_DEFPROP_ENUMERABLE); DUK_ASSERT(DUK_PROPDESC_FLAG_CONFIGURABLE == DUK_DEFPROP_CONFIGURABLE); @@ -64164,22 +65394,28 @@ #if !defined(DUK_USE_ES6_OBJECT_PROTO_PROPERTY) DUK_DD(DUK_DDPRINT("delete Object.prototype.__proto__ built-in which is not enabled in features")); - (void) duk_hobject_delprop_raw(thr, thr->builtinsDUK_BIDX_OBJECT_PROTOTYPE, DUK_HTHREAD_STRING___PROTO__(thr), DUK_DELPROP_FLAG_THROW); + (void) duk_hobject_delprop_raw(thr, + thr->builtinsDUK_BIDX_OBJECT_PROTOTYPE, + DUK_HTHREAD_STRING___PROTO__(thr), + DUK_DELPROP_FLAG_THROW); #endif #if !defined(DUK_USE_ES6_OBJECT_SETPROTOTYPEOF) DUK_DD(DUK_DDPRINT("delete Object.setPrototypeOf built-in which is not enabled in features")); - (void) duk_hobject_delprop_raw(thr, thr->builtinsDUK_BIDX_OBJECT_CONSTRUCTOR, DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr), DUK_DELPROP_FLAG_THROW); + (void) duk_hobject_delprop_raw(thr, + thr->builtinsDUK_BIDX_OBJECT_CONSTRUCTOR, + DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr), + DUK_DELPROP_FLAG_THROW); #endif /* XXX: relocate */ duk_push_string(thr, - /* Endianness indicator */ + /* Endianness indicator */ #if defined(DUK_USE_INTEGER_LE) "l" #elif defined(DUK_USE_INTEGER_BE) "b" -#elif defined(DUK_USE_INTEGER_ME) /* integer mixed endian not really used now */ +#elif defined(DUK_USE_INTEGER_ME) /* integer mixed endian not really used now */ "m" #else "?" @@ -64194,89 +65430,85 @@ "?" #endif " " - /* Packed or unpacked tval */ + /* Packed or unpacked tval */ #if defined(DUK_USE_PACKED_TVAL) "p" #else "u" #endif #if defined(DUK_USE_FASTINT) - "f" + "f" #endif - " " - /* Low memory/performance options */ + " " + /* Low memory/performance options */ #if defined(DUK_USE_STRTAB_PTRCOMP) - "s" + "s" #endif #if !defined(DUK_USE_HEAPPTR16) && !defined(DUK_DATAPTR16) && !defined(DUK_FUNCPTR16) - "n" + "n" #endif #if defined(DUK_USE_HEAPPTR16) - "h" + "h" #endif #if defined(DUK_USE_DATAPTR16) - "d" + "d" #endif #if defined(DUK_USE_FUNCPTR16) - "f" + "f" #endif #if defined(DUK_USE_REFCOUNT16) - "R" + "R" #endif #if defined(DUK_USE_STRHASH16) - "H" + "H" #endif #if defined(DUK_USE_STRLEN16) - "S" + "S" #endif #if defined(DUK_USE_BUFLEN16) - "B" + "B" #endif #if defined(DUK_USE_OBJSIZES16) - "O" + "O" #endif #if defined(DUK_USE_LIGHTFUNC_BUILTINS) - "L" + "L" #endif #if defined(DUK_USE_ROM_STRINGS) || defined(DUK_USE_ROM_OBJECTS) - /* XXX: This won't be shown in practice now - * because this code is not run when builtins - * are in ROM. - */ - "Z" + /* XXX: This won't be shown in practice now + * because this code is not run when builtins + * are in ROM. + */ + "Z" #endif #if defined(DUK_USE_LITCACHE_SIZE) - "l" + "l" #endif " " - /* Object property allocation layout */ + /* Object property allocation layout */ #if defined(DUK_USE_HOBJECT_LAYOUT_1) - "p1" + "p1" #elif defined(DUK_USE_HOBJECT_LAYOUT_2) - "p2" + "p2" #elif defined(DUK_USE_HOBJECT_LAYOUT_3) - "p3" + "p3" #else - "p?" + "p?" #endif - " " - /* Alignment guarantee */ + " " + /* Alignment guarantee */ #if (DUK_USE_ALIGN_BY == 4) - "a4" + "a4" #elif (DUK_USE_ALIGN_BY == 8) - "a8" + "a8" #elif (DUK_USE_ALIGN_BY == 1) - "a1" + "a1" #else #error invalid DUK_USE_ALIGN_BY #endif - " " - /* Architecture, OS, and compiler strings */ - DUK_USE_ARCH_STRING - " " - DUK_USE_OS_STRING - " " - DUK_USE_COMPILER_STRING); + " " + /* Architecture, OS, and compiler strings */ + DUK_USE_ARCH_STRING " " DUK_USE_OS_STRING " " DUK_USE_COMPILER_STRING); duk_xdef_prop_stridx_short(thr, DUK_BIDX_DUKTAPE, DUK_STRIDX_ENV, DUK_PROPDESC_FLAGS_WC); /* @@ -64293,7 +65525,8 @@ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 1) for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) { DUK_DD(DUK_DDPRINT("built-in object %ld after initialization and compacting: %!@iO", - (long) i, (duk_heaphdr *) duk_require_hobject(thr, (duk_idx_t) i))); + (long) i, + (duk_heaphdr *) duk_require_hobject(thr, (duk_idx_t) i))); } #endif @@ -64306,14 +65539,14 @@ duk_set_top(thr, 0); DUK_ASSERT_TOP(thr, 0); } -#endif /* DUK_USE_ROM_OBJECTS */ +#endif /* DUK_USE_ROM_OBJECTS */ DUK_INTERNAL void duk_hthread_copy_builtin_objects(duk_hthread *thr_from, duk_hthread *thr_to) { duk_small_uint_t i; for (i = 0; i < DUK_NUM_BUILTINS; i++) { thr_to->builtinsi = thr_from->builtinsi; - DUK_HOBJECT_INCREF_ALLOWNULL(thr_to, thr_to->builtinsi); /* side effect free */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr_to, thr_to->builtinsi); /* side effect free */ } } @@ -64346,7 +65579,7 @@ } thr->valstack_bottom = thr->valstack; - duk_set_top(thr, 0); /* unwinds valstack, updating refcounts */ + duk_set_top(thr, 0); /* unwinds valstack, updating refcounts */ thr->state = DUK_HTHREAD_STATE_TERMINATED; @@ -64377,7 +65610,7 @@ } return 0; } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ DUK_INTERNAL duk_uint_fast32_t duk_hthread_get_act_prev_pc(duk_hthread *thr, duk_activation *act) { duk_instr_t *bcode; @@ -64447,7 +65680,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(act != NULL); - DUK_ASSERT(act->cat != NULL); /* caller must check */ + DUK_ASSERT(act->cat != NULL); /* caller must check */ cat = act->cat; DUK_ASSERT(cat != NULL); @@ -64456,9 +65689,9 @@ if (DUK_CAT_HAS_LEXENV_ACTIVE(cat)) { duk_hobject *env; - env = act->lex_env; /* current lex_env of the activation (created for catcher) */ - DUK_ASSERT(env != NULL); /* must be, since env was created when catcher was created */ - act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); /* prototype is lex_env before catcher created */ + env = act->lex_env; /* current lex_env of the activation (created for catcher) */ + DUK_ASSERT(env != NULL); /* must be, since env was created when catcher was created */ + act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); /* prototype is lex_env before catcher created */ DUK_HOBJECT_INCREF(thr, act->lex_env); DUK_HOBJECT_DECREF_NORZ(thr, env); @@ -64477,7 +65710,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(act != NULL); - DUK_ASSERT(act->cat != NULL); /* caller must check */ + DUK_ASSERT(act->cat != NULL); /* caller must check */ cat = act->cat; DUK_ASSERT(cat != NULL); @@ -64515,11 +65748,11 @@ return duk__hthread_catcher_alloc_slow(thr); } -#else /* DUK_USE_CACHE_CATCHER */ +#else /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL duk_catcher *duk_hthread_catcher_alloc(duk_hthread *thr) { return duk__hthread_catcher_alloc_slow(thr); } -#endif /* DUK_USE_CACHE_CATCHER */ +#endif /* DUK_USE_CACHE_CATCHER */ DUK_INTERNAL void duk_hthread_catcher_free(duk_hthread *thr, duk_catcher *cat) { DUK_ASSERT(thr != NULL); @@ -64560,12 +65793,11 @@ return duk__hthread_activation_alloc_slow(thr); } -#else /* DUK_USE_CACHE_ACTIVATION */ +#else /* DUK_USE_CACHE_ACTIVATION */ DUK_INTERNAL duk_activation *duk_hthread_activation_alloc(duk_hthread *thr) { return duk__hthread_activation_alloc_slow(thr); } -#endif /* DUK_USE_CACHE_ACTIVATION */ - +#endif /* DUK_USE_CACHE_ACTIVATION */ DUK_INTERNAL void duk_hthread_activation_free(duk_hthread *thr, duk_activation *act) { DUK_ASSERT(thr != NULL); @@ -64592,7 +65824,7 @@ duk_hobject *tmp; DUK_ASSERT(thr != NULL); - DUK_ASSERT(thr->callstack_curr != NULL); /* caller must check */ + DUK_ASSERT(thr->callstack_curr != NULL); /* caller must check */ DUK_ASSERT(thr->callstack_top > 0); act = thr->callstack_curr; DUK_ASSERT(act != NULL); @@ -64629,7 +65861,7 @@ DUK_TVAL_SET_OBJECT(tv_caller, act->prev_caller); act->prev_caller = NULL; } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref needed */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref needed */ DUK_ASSERT(act->prev_caller == NULL); } DUK_TVAL_DECREF_NORZ(thr, &tv_tmp); @@ -64658,7 +65890,7 @@ duk_debug_set_paused(heap); } else { DUK_D(DUK_DPRINT("unwound past dbg_pause_act, set to NULL")); - heap->dbg_pause_act = NULL; /* avoid stale pointers */ + heap->dbg_pause_act = NULL; /* avoid stale pointers */ } DUK_ASSERT(heap->dbg_pause_act == NULL); } @@ -64707,12 +65939,11 @@ * fixed e.g. by preallocating the scope property slots. */ if (act->var_env != NULL) { - DUK_DDD(DUK_DDDPRINT("closing var_env record %p -> %!O", - (void *) act->var_env, (duk_heaphdr *) act->var_env)); + DUK_DDD(DUK_DDDPRINT("closing var_env record %p -> %!O", (void *) act->var_env, (duk_heaphdr *) act->var_env)); duk_js_close_environment_record(thr, act->var_env); } - skip_env_close: +skip_env_close: /* * Update preventcount @@ -64836,7 +66067,7 @@ DUK_D(DUK_DPRINT("failed to realloc valstack for torture, ignore")); } } -#endif /* DUK_USE_FINALIZER_TORTURE */ +#endif /* DUK_USE_FINALIZER_TORTURE */ #line 1 "duk_js_arith.c" /* * Shared helpers for arithmetic operations @@ -64881,10 +66112,14 @@ DUK_ASSERT(DUK_ISNAN(DUK_FMOD(-DUK_DOUBLE_INFINITY, -DUK_DOUBLE_INFINITY))); DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, 1.0), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, 1.0)) == 0); DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, 1.0), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, 1.0)) != 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY)) != 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, -DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); - DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY), 0.0) && DUK_SIGNBIT(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY)) != 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(-0.0, DUK_DOUBLE_INFINITY)) != 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(0.0, -DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(0.0, DUK_DOUBLE_INFINITY)) == 0); + DUK_ASSERT(duk_double_equals(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY), 0.0) && + DUK_SIGNBIT(DUK_FMOD(-0.0, -DUK_DOUBLE_INFINITY)) != 0); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(0.0, 0.0))); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(-0.0, 0.0))); DUK_ASSERT(DUK_ISNAN(DUK_FMOD(0.0, -0.0))); @@ -64972,7 +66207,7 @@ return DUK_POW(x, y); - ret_nan: +ret_nan: return DUK_DOUBLE_NAN; } #line 1 "duk_js_call.c" @@ -65029,10 +66264,10 @@ * for, e.g. a print() call at the deepest level, and an extra * +1 for protected call wrapping. */ -#define DUK__AUGMENT_CALL_RELAX_COUNT (10 + 2) +#define DUK__AUGMENT_CALL_RELAX_COUNT (10 + 2) /* Stack space required by call handling entry. */ -#define DUK__CALL_HANDLING_REQUIRE_STACK 8 +#define DUK__CALL_HANDLING_REQUIRE_STACK 8 DUK_LOCAL DUK_NOINLINE void duk__call_c_recursion_limit_check_slowpath(duk_hthread *thr) { /* When augmenting an error, the effective limit is a bit higher. @@ -65126,7 +66361,8 @@ thr->heap->inst_count_interrupt += thr->interrupt_init; DUK_DD(DUK_DDPRINT("debug test: updated interrupt count on exit to " "user code, instruction counts: executor=%ld, interrupt=%ld", - (long) thr->heap->inst_count_exec, (long) thr->heap->inst_count_interrupt)); + (long) thr->heap->inst_count_exec, + (long) thr->heap->inst_count_interrupt)); DUK_ASSERT(thr->heap->inst_count_exec == thr->heap->inst_count_interrupt); } #else @@ -65145,12 +66381,9 @@ * object flag DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS. */ -DUK_LOCAL void duk__create_arguments_object(duk_hthread *thr, - duk_hobject *func, - duk_hobject *varenv, - duk_idx_t idx_args) { - duk_hobject *arg; /* 'arguments' */ - duk_hobject *formals; /* formals for 'func' (may be NULL if func is a C function) */ +DUK_LOCAL void duk__create_arguments_object(duk_hthread *thr, duk_hobject *func, duk_hobject *varenv, duk_idx_t idx_args) { + duk_hobject *arg; /* 'arguments' */ + duk_hobject *formals; /* formals for 'func' (may be NULL if func is a C function) */ duk_idx_t i_arg; duk_idx_t i_map; duk_idx_t i_mappednames; @@ -65196,9 +66429,8 @@ DUK_ASSERT(n_formals >= 0); DUK_ASSERT(formals != NULL || n_formals == 0); - DUK_DDD(DUK_DDDPRINT("func=%!O, formals=%!O, n_formals=%ld", - (duk_heaphdr *) func, (duk_heaphdr *) formals, - (long) n_formals)); + DUK_DDD( + DUK_DDDPRINT("func=%!O, formals=%!O, n_formals=%ld", (duk_heaphdr *) func, (duk_heaphdr *) formals, (long) n_formals)); /* ... formals */ @@ -65210,28 +66442,24 @@ */ arg = duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_FLAG_ARRAY_PART | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARGUMENTS), + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_FLAG_ARRAY_PART | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ARGUMENTS), DUK_BIDX_OBJECT_PROTOTYPE); DUK_ASSERT(arg != NULL); (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ (void) duk_push_object_helper(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_FLAG_FASTREFS | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), - -1); /* no prototype */ + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | + DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), + -1); /* no prototype */ i_arg = duk_get_top(thr) - 3; i_map = i_arg + 1; i_mappednames = i_arg + 2; - DUK_ASSERT(!duk_is_bare_object(thr, -3)); /* arguments */ - DUK_ASSERT(duk_is_bare_object(thr, -2)); /* map */ - DUK_ASSERT(duk_is_bare_object(thr, -1)); /* mappedNames */ + DUK_ASSERT(!duk_is_bare_object(thr, -3)); /* arguments */ + DUK_ASSERT(duk_is_bare_object(thr, -2)); /* map */ + DUK_ASSERT(duk_is_bare_object(thr, -1)); /* mappedNames */ /* ... formals arguments map mappedNames */ @@ -65239,9 +66467,12 @@ "arguments at index %ld -> %!O " "map at index %ld -> %!O " "mappednames at index %ld -> %!O", - (long) i_arg, (duk_heaphdr *) duk_get_hobject(thr, i_arg), - (long) i_map, (duk_heaphdr *) duk_get_hobject(thr, i_map), - (long) i_mappednames, (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); + (long) i_arg, + (duk_heaphdr *) duk_get_hobject(thr, i_arg), + (long) i_map, + (duk_heaphdr *) duk_get_hobject(thr, i_map), + (long) i_mappednames, + (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); /* * Init arguments properties, map, etc. @@ -65257,8 +66488,8 @@ /* step 11 */ idx = num_stack_args - 1; while (idx >= 0) { - DUK_DDD(DUK_DDDPRINT("arg idx %ld, argbase=%ld, argidx=%ld", - (long) idx, (long) i_argbase, (long) (i_argbase + idx))); + DUK_DDD( + DUK_DDDPRINT("arg idx %ld, argbase=%ld, argidx=%ld", (long) idx, (long) i_argbase, (long) (i_argbase + idx))); DUK_DDD(DUK_DDDPRINT("define arguments%ld=arg", (long) idx)); duk_dup(thr, i_argbase + idx); @@ -65269,13 +66500,12 @@ if (!DUK_HOBJECT_HAS_STRICT(func) && idx < n_formals) { DUK_ASSERT(formals != NULL); - DUK_DDD(DUK_DDDPRINT("strict function, index within formals (%ld < %ld)", - (long) idx, (long) n_formals)); + DUK_DDD(DUK_DDDPRINT("strict function, index within formals (%ld < %ld)", (long) idx, (long) n_formals)); duk_get_prop_index(thr, i_formals, (duk_uarridx_t) idx); DUK_ASSERT(duk_is_string(thr, -1)); - duk_dup_top(thr); /* ... name name */ + duk_dup_top(thr); /* ... name name */ if (!duk_has_prop(thr, i_mappednames)) { /* steps 11.c.ii.1 - 11.c.ii.4, but our internal book-keeping @@ -65286,24 +66516,21 @@ need_map = 1; - DUK_DDD(DUK_DDDPRINT("set mappednames%s=%ld", - (const char *) duk_get_string(thr, -1), - (long) idx)); - duk_dup_top(thr); /* name */ - (void) duk_push_uint_to_hstring(thr, (duk_uint_t) idx); /* index */ - duk_xdef_prop_wec(thr, i_mappednames); /* out of spec, must be configurable */ - - DUK_DDD(DUK_DDDPRINT("set map%ld=%s", - (long) idx, - duk_get_string(thr, -1))); - duk_dup_top(thr); /* name */ - duk_xdef_prop_index_wec(thr, i_map, (duk_uarridx_t) idx); /* out of spec, must be configurable */ + DUK_DDD( + DUK_DDDPRINT("set mappednames%s=%ld", (const char *) duk_get_string(thr, -1), (long) idx)); + duk_dup_top(thr); /* name */ + (void) duk_push_uint_to_hstring(thr, (duk_uint_t) idx); /* index */ + duk_xdef_prop_wec(thr, i_mappednames); /* out of spec, must be configurable */ + + DUK_DDD(DUK_DDDPRINT("set map%ld=%s", (long) idx, duk_get_string(thr, -1))); + duk_dup_top(thr); /* name */ + duk_xdef_prop_index_wec(thr, i_map, (duk_uarridx_t) idx); /* out of spec, must be configurable */ } else { /* duk_has_prop() popped the second 'name' */ } /* ... name */ - duk_pop(thr); /* pop 'name' */ + duk_pop(thr); /* pop 'name' */ } idx--; @@ -65319,7 +66546,7 @@ DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(func)); duk_dup(thr, i_map); - duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_MAP, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ + duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_MAP, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ /* The variable environment for magic variable bindings needs to be * given by the caller and recorded in the arguments object. @@ -65331,7 +66558,7 @@ */ duk_push_hobject(thr, varenv); - duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_VARENV, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ + duk_xdef_prop_stridx(thr, i_arg, DUK_STRIDX_INT_VARENV, DUK_PROPDESC_FLAGS_NONE); /* out of spec, don't care */ } /* steps 13-14 */ @@ -65384,9 +66611,12 @@ "arguments at index %ld -> %!O " "map at index %ld -> %!O " "mappednames at index %ld -> %!O", - (long) i_arg, (duk_heaphdr *) duk_get_hobject(thr, i_arg), - (long) i_map, (duk_heaphdr *) duk_get_hobject(thr, i_map), - (long) i_mappednames, (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); + (long) i_arg, + (duk_heaphdr *) duk_get_hobject(thr, i_arg), + (long) i_map, + (duk_heaphdr *) duk_get_hobject(thr, i_map), + (long) i_mappednames, + (duk_heaphdr *) duk_get_hobject(thr, i_mappednames))); /* args(n) envobj formals arguments map mappednames */ @@ -65399,10 +66629,7 @@ /* Helper for creating the arguments object and adding it to the env record * on top of the value stack. */ -DUK_LOCAL void duk__handle_createargs_for_call(duk_hthread *thr, - duk_hobject *func, - duk_hobject *env, - duk_idx_t idx_args) { +DUK_LOCAL void duk__handle_createargs_for_call(duk_hthread *thr, duk_hobject *func, duk_hobject *env, duk_idx_t idx_args) { DUK_DDD(DUK_DDDPRINT("creating arguments object for function call")); DUK_ASSERT(thr != NULL); @@ -65412,18 +66639,15 @@ /* ... arg1 ... argN envobj */ - duk__create_arguments_object(thr, - func, - env, - idx_args); + duk__create_arguments_object(thr, func, env, idx_args); /* ... arg1 ... argN envobj argobj */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LC_ARGUMENTS, - DUK_HOBJECT_HAS_STRICT(func) ? DUK_PROPDESC_FLAGS_E : /* strict: non-deletable, non-writable */ - DUK_PROPDESC_FLAGS_WE); /* non-strict: non-deletable, writable */ + DUK_HOBJECT_HAS_STRICT(func) ? DUK_PROPDESC_FLAGS_E : /* strict: non-deletable, non-writable */ + DUK_PROPDESC_FLAGS_WE); /* non-strict: non-deletable, writable */ /* ... arg1 ... argN envobj */ } @@ -65473,7 +66697,8 @@ "-> leave standard Object prototype as fallback prototype")); } else { DUK_DDD(DUK_DDDPRINT("constructor has 'prototype' property with object value " - "-> set fallback prototype to that value: %!iO", (duk_heaphdr *) proto)); + "-> set fallback prototype to that value: %!iO", + (duk_heaphdr *) proto)); /* Original fallback (default instance) is untouched when * resolving bound functions etc. */ @@ -65495,9 +66720,7 @@ * Object (we accept object-like values like buffers and * lightfuncs too). If not, TypeError. */ - if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | - DUK_TYPE_MASK_BUFFER | - DUK_TYPE_MASK_LIGHTFUNC)) { + if (duk_check_type_mask(thr, -1, DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_LIGHTFUNC)) { DUK_DDD(DUK_DDDPRINT("replacement value")); } else { if (DUK_UNLIKELY(proxy_invariant != 0U)) { @@ -65519,8 +66742,7 @@ * out right; however it is always synced here so just assert for it. */ DUK_ASSERT(thr->ptr_curr_pc == NULL); - duk_err_augment_error_create(thr, thr, NULL, 0, DUK_AUGMENT_FLAG_NOBLAME_FILELINE | - DUK_AUGMENT_FLAG_SKIP_ONE); + duk_err_augment_error_create(thr, thr, NULL, 0, DUK_AUGMENT_FLAG_NOBLAME_FILELINE | DUK_AUGMENT_FLAG_SKIP_ONE); #endif } @@ -65537,9 +66759,7 @@ * BoundThis. */ -DUK_LOCAL void duk__handle_bound_chain_for_call(duk_hthread *thr, - duk_idx_t idx_func, - duk_bool_t is_constructor_call) { +DUK_LOCAL void duk__handle_bound_chain_for_call(duk_hthread *thr, duk_idx_t idx_func, duk_bool_t is_constructor_call) { duk_tval *tv_func; duk_hobject *func; duk_idx_t len; @@ -65570,7 +66790,8 @@ DUK_ASSERT(len == 0 || tv_args != NULL); DUK_DDD(DUK_DDDPRINT("bound function encountered, ptr=%p: %!T", - (void *) DUK_TVAL_GET_OBJECT(tv_func), tv_func)); + (void *) DUK_TVAL_GET_OBJECT(tv_func), + tv_func)); /* ... func this arg1 ... argN */ @@ -65580,7 +66801,7 @@ } else { /* XXX: duk_replace_tval */ duk_push_tval(thr, &h_bound->this_binding); - duk_replace(thr, idx_func + 1); /* idx_this = idx_func + 1 */ + duk_replace(thr, idx_func + 1); /* idx_this = idx_func + 1 */ } /* ... func this arg1 ... argN */ @@ -65593,10 +66814,11 @@ /* ... func this <bound args> arg1 ... argN */ duk_push_tval(thr, &h_bound->target); - duk_replace(thr, idx_func); /* replace in stack */ + duk_replace(thr, idx_func); /* replace in stack */ DUK_DDD(DUK_DDDPRINT("bound function handled, idx_func=%ld, curr func=%!T", - (long) idx_func, duk_get_tval(thr, idx_func))); + (long) idx_func, + duk_get_tval(thr, idx_func))); } } else if (DUK_TVAL_IS_LIGHTFUNC(tv_func)) { /* Lightweight function: never bound, so terminate. */ @@ -65618,9 +66840,7 @@ func = DUK_TVAL_GET_OBJECT(tv_func); DUK_ASSERT(func != NULL); DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func) || - DUK_HOBJECT_HAS_NATFUNC(func) || - DUK_HOBJECT_IS_PROXY(func)); + DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func) || DUK_HOBJECT_HAS_NATFUNC(func) || DUK_HOBJECT_IS_PROXY(func)); } #endif } @@ -65629,14 +66849,18 @@ * Helper for inline handling of .call(), .apply(), and .construct(). */ -DUK_LOCAL duk_bool_t duk__handle_specialfuncs_for_call(duk_hthread *thr, duk_idx_t idx_func, duk_hobject *func, duk_small_uint_t *call_flags, duk_bool_t first) { +DUK_LOCAL duk_bool_t duk__handle_specialfuncs_for_call(duk_hthread *thr, + duk_idx_t idx_func, + duk_hobject *func, + duk_small_uint_t *call_flags, + duk_bool_t first) { #if defined(DUK_USE_ASSERTIONS) duk_c_function natfunc; #endif duk_tval *tv_args; DUK_ASSERT(func != NULL); - DUK_ASSERT((*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0); /* Caller. */ + DUK_ASSERT((*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0); /* Caller. */ #if defined(DUK_USE_ASSERTIONS) natfunc = ((duk_hnatfunc *) func)->func; @@ -65664,7 +66888,7 @@ *call_flags = (*call_flags & ~DUK_CALL_FLAG_CALLED_AS_EVAL) | DUK_CALL_FLAG_DIRECT_EVAL; } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 1; /* stop resolving */ + return 1; /* stop resolving */ } /* Handle special functions based on the DUK_HOBJECT_FLAG_SPECIAL_CALL @@ -65674,7 +66898,7 @@ * for the result values (unlike most other value stack calls). */ switch (((duk_hnatfunc *) func)->magic) { - case 0: { /* 0=Function.prototype.call() */ + case 0: { /* 0=Function.prototype.call() */ /* Value stack: * idx_func + 0: Function.prototype.call() removed * idx_func + 1: this binding for .call (target function) @@ -65693,11 +66917,11 @@ tv_args = thr->valstack_bottom + idx_func + 2; if (thr->valstack_top < tv_args) { DUK_ASSERT(tv_args <= thr->valstack_end); - thr->valstack_top = tv_args; /* at least target function and 'this' binding present */ + thr->valstack_top = tv_args; /* at least target function and 'this' binding present */ } break; } - case 1: { /* 1=Function.prototype.apply() */ + case 1: { /* 1=Function.prototype.apply() */ /* Value stack: * idx_func + 0: Function.prototype.apply() removed * idx_func + 1: this binding for .apply (target function) @@ -65716,7 +66940,7 @@ goto apply_shared; } #if defined(DUK_USE_REFLECT_BUILTIN) - case 2: { /* 2=Reflect.apply() */ + case 2: { /* 2=Reflect.apply() */ /* Value stack: * idx_func + 0: Reflect.apply() removed * idx_func + 1: this binding for .apply (ignored, usually Reflect) removed @@ -65735,7 +66959,7 @@ duk_remove_n_unsafe(thr, idx_func, 2); goto apply_shared; } - case 3: { /* 3=Reflect.construct() */ + case 3: { /* 3=Reflect.construct() */ /* Value stack: * idx_func + 0: Reflect.construct() removed * idx_func + 1: this binding for .construct (ignored, usually Reflect) removed @@ -65769,11 +66993,11 @@ * unpacking argArray (which may cause side effects). * Just return; caller will throw the error. */ - duk_set_top_unsafe(thr, idx_func + 2); /* satisfy asserts */ + duk_set_top_unsafe(thr, idx_func + 2); /* satisfy asserts */ break; } duk_push_object(thr); - duk_insert(thr, idx_func + 1); /* default instance */ + duk_insert(thr, idx_func + 1); /* default instance */ /* ... func default_instance argArray newTarget? */ @@ -65789,16 +67013,17 @@ DUK_ERROR_UNSUPPORTED(thr); DUK_WO_NORETURN(return 0;); } - duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ + duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ } DUK_ASSERT(duk_get_top(thr) == idx_func + 3); DUK_ASSERT(duk_is_valid_index(thr, idx_func + 2)); - (void) duk_unpack_array_like(thr, idx_func + 2); /* XXX: should also remove target to be symmetric with duk_pack()? */ + (void) duk_unpack_array_like(thr, + idx_func + 2); /* XXX: should also remove target to be symmetric with duk_pack()? */ duk_remove(thr, idx_func + 2); DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); break; } -#endif /* DUK_USE_REFLECT_BUILTIN */ +#endif /* DUK_USE_REFLECT_BUILTIN */ default: { DUK_ASSERT(0); DUK_UNREACHABLE(); @@ -65806,18 +67031,18 @@ } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 0; /* keep resolving */ + return 0; /* keep resolving */ - apply_shared: +apply_shared: tv_args = thr->valstack_bottom + idx_func + 2; if (thr->valstack_top <= tv_args) { DUK_ASSERT(tv_args <= thr->valstack_end); - thr->valstack_top = tv_args; /* at least target func and 'this' binding present */ + thr->valstack_top = tv_args; /* at least target func and 'this' binding present */ /* No need to check for argArray. */ } else { - DUK_ASSERT(duk_get_top(thr) >= idx_func + 3); /* idx_func + 2 covered above */ + DUK_ASSERT(duk_get_top(thr) >= idx_func + 3); /* idx_func + 2 covered above */ if (thr->valstack_top > tv_args + 1) { - duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ + duk_set_top_unsafe(thr, idx_func + 3); /* remove any args beyond argArray */ } DUK_ASSERT(duk_is_valid_index(thr, idx_func + 2)); if (!duk_is_callable(thr, idx_func)) { @@ -65830,7 +67055,7 @@ } } DUK_ASSERT(duk_get_top(thr) >= idx_func + 2); - return 0; /* keep resolving */ + return 0; /* keep resolving */ } /* @@ -65928,8 +67153,8 @@ DUK_ASSERT(duk_get_top(thr) == idx_func + 6); if (*call_flags & DUK_CALL_FLAG_CONSTRUCT) { - *call_flags |= DUK_CALL_FLAG_CONSTRUCT_PROXY; /* Enable 'construct' trap return invariant check. */ - *call_flags &= ~(DUK_CALL_FLAG_CONSTRUCT); /* Resume as non-constructor call to the trap. */ + *call_flags |= DUK_CALL_FLAG_CONSTRUCT_PROXY; /* Enable 'construct' trap return invariant check. */ + *call_flags &= ~(DUK_CALL_FLAG_CONSTRUCT); /* Resume as non-constructor call to the trap. */ /* 'apply' args: target, thisArg, argArray * 'construct' args: target, argArray, newTarget @@ -65940,19 +67165,17 @@ /* Finalize value stack layout by removing Proxy reference. */ duk_remove(thr, idx_func); - h_proxy = NULL; /* invalidated */ + h_proxy = NULL; /* invalidated */ DUK_ASSERT(duk_get_top(thr) == idx_func + 5); } -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ /* * Helper for setting up var_env and lex_env of an activation, * assuming it does NOT have the DUK_HOBJECT_FLAG_NEWENV flag. */ -DUK_LOCAL void duk__handle_oldenv_for_call(duk_hthread *thr, - duk_hobject *func, - duk_activation *act) { +DUK_LOCAL void duk__handle_oldenv_for_call(duk_hthread *thr, duk_hobject *func, duk_activation *act) { duk_hcompfunc *f; duk_hobject *h_lex; duk_hobject *h_var; @@ -65968,7 +67191,7 @@ f = (duk_hcompfunc *) func; h_lex = DUK_HCOMPFUNC_GET_LEXENV(thr->heap, f); h_var = DUK_HCOMPFUNC_GET_VARENV(thr->heap, f); - DUK_ASSERT(h_lex != NULL); /* Always true for closures (not for templates) */ + DUK_ASSERT(h_lex != NULL); /* Always true for closures (not for templates) */ DUK_ASSERT(h_var != NULL); act->lex_env = h_lex; act->var_env = h_var; @@ -65989,7 +67212,7 @@ DUK_ASSERT(thr != NULL); DUK_ASSERT(func != NULL); - DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound chain resolved */ + DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound chain resolved */ DUK_ASSERT(thr->callstack_top >= 1); if (DUK_HOBJECT_HAS_STRICT(func)) { @@ -66043,7 +67266,7 @@ DUK_TVAL_SET_OBJECT(tv_caller, act_caller->func); DUK_TVAL_INCREF(thr, tv_caller); } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref */ } } else { /* 'caller' must only take on 'null' or function value */ @@ -66056,12 +67279,12 @@ DUK_TVAL_SET_OBJECT(tv_caller, act_caller->func); DUK_TVAL_INCREF(thr, tv_caller); } else { - DUK_TVAL_SET_NULL(tv_caller); /* no incref */ + DUK_TVAL_SET_NULL(tv_caller); /* no incref */ } } } } -#endif /* DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ +#endif /* DUK_USE_NONSTD_FUNC_CALLER_PROPERTY */ /* * Shared helpers for resolving the final, non-bound target function of the @@ -66107,7 +67330,7 @@ obj_global = thr->builtinsDUK_BIDX_GLOBAL; /* XXX: avoid this check somehow */ if (DUK_LIKELY(obj_global != NULL)) { - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ DUK_TVAL_SET_OBJECT(tv_this, obj_global); DUK_HOBJECT_INCREF(thr, obj_global); } else { @@ -66115,8 +67338,8 @@ * This behavior is out of specification scope. */ DUK_D(DUK_DPRINT("this binding: wanted to use global object, but it is NULL -> using undefined instead")); - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ - DUK_TVAL_SET_UNDEFINED(tv_this); /* nothing to incref */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv_this)); /* no need to decref previous value */ + DUK_TVAL_SET_UNDEFINED(tv_this); /* nothing to incref */ } break; default: @@ -66127,18 +67350,21 @@ */ DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv_this)); DUK_DDD(DUK_DDDPRINT("this binding: non-strict, not object/undefined/null -> use ToObject(value)")); - duk_to_object(thr, idx_this); /* may have side effects */ + duk_to_object(thr, idx_this); /* may have side effects */ break; } } -DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__resolve_target_fastpath_check(duk_hthread *thr, duk_idx_t idx_func, duk_hobject **out_func, duk_small_uint_t call_flags) { +DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__resolve_target_fastpath_check(duk_hthread *thr, + duk_idx_t idx_func, + duk_hobject **out_func, + duk_small_uint_t call_flags) { #if defined(DUK_USE_PREFER_SIZE) DUK_UNREF(thr); DUK_UNREF(idx_func); DUK_UNREF(out_func); DUK_UNREF(call_flags); -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ duk_tval *tv_func; duk_hobject *func; @@ -66151,9 +67377,7 @@ if (DUK_LIKELY(DUK_TVAL_IS_OBJECT(tv_func))) { func = DUK_TVAL_GET_OBJECT(tv_func); - if (DUK_HOBJECT_IS_CALLABLE(func) && - !DUK_HOBJECT_HAS_BOUNDFUNC(func) && - !DUK_HOBJECT_HAS_SPECIAL_CALL(func)) { + if (DUK_HOBJECT_IS_CALLABLE(func) && !DUK_HOBJECT_HAS_BOUNDFUNC(func) && !DUK_HOBJECT_HAS_SPECIAL_CALL(func)) { *out_func = func; if (DUK_HOBJECT_HAS_STRICT(func)) { @@ -66173,8 +67397,8 @@ */ return 1; } -#endif /* DUK_USE_PREFER_SIZE */ - return 0; /* let slow path deal with it */ +#endif /* DUK_USE_PREFER_SIZE */ + return 0; /* let slow path deal with it */ } DUK_LOCAL duk_hobject *duk__resolve_target_func_and_this_binding(duk_hthread *thr, @@ -66207,8 +67431,7 @@ } } - if (DUK_LIKELY(!DUK_HOBJECT_HAS_BOUNDFUNC(func) && - !DUK_HOBJECT_HAS_SPECIAL_CALL(func) && + if (DUK_LIKELY(!DUK_HOBJECT_HAS_BOUNDFUNC(func) && !DUK_HOBJECT_HAS_SPECIAL_CALL(func) && !DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(func))) { /* Common case, so test for using a single bitfield test. * Break out to handle this coercion etc. @@ -66244,8 +67467,7 @@ * the trap may be bound. */ duk__handle_proxy_for_call(thr, idx_func, (duk_hproxy *) func, call_flags); - } - else + } else #endif { DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(func)); @@ -66292,28 +67514,25 @@ } } - finished: - +finished : #if defined(DUK_USE_ASSERTIONS) - { - duk_tval *tv_tmp; +{ + duk_tval *tv_tmp; - tv_tmp = duk_get_tval(thr, idx_func); - DUK_ASSERT(tv_tmp != NULL); + tv_tmp = duk_get_tval(thr, idx_func); + DUK_ASSERT(tv_tmp != NULL); - DUK_ASSERT((DUK_TVAL_IS_OBJECT(tv_tmp) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(tv_tmp))) || - DUK_TVAL_IS_LIGHTFUNC(tv_tmp)); - DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || - DUK_HOBJECT_IS_NATFUNC(func))); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_HAS_CONSTRUCTABLE(func) || - (*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0)); - } + DUK_ASSERT((DUK_TVAL_IS_OBJECT(tv_tmp) && DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(tv_tmp))) || + DUK_TVAL_IS_LIGHTFUNC(tv_tmp)); + DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || DUK_HOBJECT_IS_NATFUNC(func))); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_HAS_CONSTRUCTABLE(func) || (*call_flags & DUK_CALL_FLAG_CONSTRUCT) == 0)); +} #endif return func; - not_callable: +not_callable: DUK_ASSERT(tv_func != NULL); #if defined(DUK_USE_VERBOSE_ERRORS) @@ -66325,7 +67544,8 @@ * (which would be dangerous). */ if (DUK_TVAL_IS_OBJECT(tv_func)) { - duk_tval *tv_wrap = duk_hobject_find_entry_tval_ptr_stridx(thr->heap, DUK_TVAL_GET_OBJECT(tv_func), DUK_STRIDX_INT_TARGET); + duk_tval *tv_wrap = + duk_hobject_find_entry_tval_ptr_stridx(thr->heap, DUK_TVAL_GET_OBJECT(tv_func), DUK_STRIDX_INT_TARGET); if (tv_wrap != NULL) { DUK_DD(DUK_DDPRINT("delayed error from GETPROPC: %!T", tv_wrap)); duk_push_tval(thr, tv_wrap); @@ -66346,7 +67566,7 @@ #endif DUK_WO_NORETURN(return NULL;); - not_constructable: +not_constructable: /* For now GETPROPC delayed error not needed for constructor calls. */ #if defined(DUK_USE_VERBOSE_ERRORS) #if defined(DUK_USE_PARANOID_ERRORS) @@ -66370,7 +67590,10 @@ * empty (below idx_retbase). */ -DUK_LOCAL void duk__safe_call_adjust_valstack(duk_hthread *thr, duk_idx_t idx_retbase, duk_idx_t num_stack_rets, duk_idx_t num_actual_rets) { +DUK_LOCAL void duk__safe_call_adjust_valstack(duk_hthread *thr, + duk_idx_t idx_retbase, + duk_idx_t num_stack_rets, + duk_idx_t num_actual_rets) { duk_idx_t idx_rcbase; DUK_ASSERT(thr != NULL); @@ -66378,7 +67601,7 @@ DUK_ASSERT(num_stack_rets >= 0); DUK_ASSERT(num_actual_rets >= 0); - idx_rcbase = duk_get_top(thr) - num_actual_rets; /* base of known return values */ + idx_rcbase = duk_get_top(thr) - num_actual_rets; /* base of known return values */ if (DUK_UNLIKELY(idx_rcbase < 0)) { DUK_ERROR_TYPE(thr, DUK_STR_INVALID_CFUNC_RC); DUK_WO_NORETURN(return;); @@ -66386,10 +67609,13 @@ DUK_DDD(DUK_DDDPRINT("adjust valstack after func call: " "num_stack_rets=%ld, num_actual_rets=%ld, stack_top=%ld, idx_retbase=%ld, idx_rcbase=%ld", - (long) num_stack_rets, (long) num_actual_rets, (long) duk_get_top(thr), - (long) idx_retbase, (long) idx_rcbase)); + (long) num_stack_rets, + (long) num_actual_rets, + (long) duk_get_top(thr), + (long) idx_retbase, + (long) idx_rcbase)); - DUK_ASSERT(idx_rcbase >= 0); /* caller must check */ + DUK_ASSERT(idx_rcbase >= 0); /* caller must check */ /* Space for num_stack_rets was reserved before the safe call. * Because value stack reserve cannot shrink except in call returns, @@ -66404,24 +67630,28 @@ duk_idx_t count = idx_rcbase - idx_retbase; DUK_DDD(DUK_DDDPRINT("elements at/after idx_retbase have enough to cover func retvals " - "(idx_retbase=%ld, idx_rcbase=%ld)", (long) idx_retbase, (long) idx_rcbase)); + "(idx_retbase=%ld, idx_rcbase=%ld)", + (long) idx_retbase, + (long) idx_rcbase)); /* Remove values between irc_rcbase (start of intended return * values) and idx_retbase to lower return values to idx_retbase. */ DUK_ASSERT(count > 0); - duk_remove_n(thr, idx_retbase, count); /* may be NORZ */ + duk_remove_n(thr, idx_retbase, count); /* may be NORZ */ } else { duk_idx_t count = idx_retbase - idx_rcbase; DUK_DDD(DUK_DDDPRINT("not enough elements at/after idx_retbase to cover func retvals " - "(idx_retbase=%ld, idx_rcbase=%ld)", (long) idx_retbase, (long) idx_rcbase)); + "(idx_retbase=%ld, idx_rcbase=%ld)", + (long) idx_retbase, + (long) idx_rcbase)); /* Insert 'undefined' at idx_rcbase (start of intended return * values) to lift return values to idx_retbase. */ DUK_ASSERT(count >= 0); - DUK_ASSERT(thr->valstack_end - thr->valstack_top >= count); /* reserve cannot shrink */ + DUK_ASSERT(thr->valstack_end - thr->valstack_top >= count); /* reserve cannot shrink */ duk_insert_undefined_n(thr, idx_rcbase, count); } @@ -66482,12 +67712,12 @@ #if defined(DUK_USE_ES6_PROXY) | (duk_small_uint_t) ((act->flags & DUK_ACT_FLAG_CONSTRUCT_PROXY) ? 2 : 0) #endif - ; + ; flags2 = (duk_small_uint_t) ((call_flags & DUK_CALL_FLAG_CONSTRUCT) ? 1 : 0) #if defined(DUK_USE_ES6_PROXY) | (duk_small_uint_t) ((call_flags & DUK_CALL_FLAG_CONSTRUCT_PROXY) ? 2 : 0); #endif - ; + ; if (flags1 != flags2) { DUK_DDD(DUK_DDDPRINT("tail call prevented by incompatible return value handling")); return 0; @@ -66525,8 +67755,7 @@ * https://github.com/svaarala/duktape/issues/1726. */ - DUK_DDD(DUK_DDDPRINT("is tail call, reusing activation at callstack top, at index %ld", - (long) (thr->callstack_top - 1))); + DUK_DDD(DUK_DDDPRINT("is tail call, reusing activation at callstack top, at index %ld", (long) (thr->callstack_top - 1))); DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); DUK_ASSERT(!DUK_HOBJECT_HAS_NATFUNC(func)); @@ -66570,7 +67799,7 @@ act->lex_env = NULL; DUK_ASSERT(func != NULL); DUK_ASSERT(DUK_HOBJECT_HAS_COMPFUNC(func)); - act->func = func; /* don't want an intermediate exposed state with func == NULL */ + act->func = func; /* don't want an intermediate exposed state with func == NULL */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) act->prev_caller = NULL; #endif @@ -66579,7 +67808,7 @@ #if defined(DUK_USE_DEBUGGER_SUPPORT) act->prev_line = 0; #endif - DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ + DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ DUK_HOBJECT_INCREF(thr, func); act->flags = DUK_ACT_FLAG_TAILCALLED; @@ -66595,10 +67824,10 @@ } #endif - DUK_ASSERT(DUK_ACT_GET_FUNC(act) == func); /* already updated */ + DUK_ASSERT(DUK_ACT_GET_FUNC(act) == func); /* already updated */ DUK_ASSERT(act->var_env == NULL); DUK_ASSERT(act->lex_env == NULL); - act->bottom_byteoff = entry_valstack_bottom_byteoff; /* tail call -> reuse current "frame" */ + act->bottom_byteoff = entry_valstack_bottom_byteoff; /* tail call -> reuse current "frame" */ #if 0 /* Topmost activation retval_byteoff is considered garbage, no need to init. */ act->retval_byteoff = 0; @@ -66623,22 +67852,23 @@ tv1 = thr->valstack_bottom - 1; tv2 = thr->valstack_bottom + idx_func + 1; - DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); /* tv1 is -below- valstack_bottom */ + DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); /* tv1 is -below- valstack_bottom */ DUK_ASSERT(tv2 >= thr->valstack_bottom && tv2 < thr->valstack_top); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ idx_args = idx_func + 2; - duk_remove_n(thr, 0, idx_args); /* may be NORZ */ + duk_remove_n(thr, 0, idx_args); /* may be NORZ */ - idx_func = 0; DUK_UNREF(idx_func); /* really 'not applicable' anymore, should not be referenced after this */ + idx_func = 0; + DUK_UNREF(idx_func); /* really 'not applicable' anymore, should not be referenced after this */ idx_args = 0; *out_nargs = ((duk_hcompfunc *) func)->nargs; *out_nregs = ((duk_hcompfunc *) func)->nregs; DUK_ASSERT(*out_nregs >= 0); DUK_ASSERT(*out_nregs >= *out_nargs); - *out_vs_min_bytes = entry_valstack_bottom_byteoff + sizeof(duk_tval) * ((duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); - + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + sizeof(duk_tval) * ((duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) #if defined(DUK_USE_TAILCALL) @@ -66655,7 +67885,7 @@ return 1; } -#endif /* DUK_USE_TAILCALL */ +#endif /* DUK_USE_TAILCALL */ DUK_LOCAL void duk__call_setup_act_not_tailcall(duk_hthread *thr, duk_small_uint_t call_flags, @@ -66672,8 +67902,7 @@ DUK_UNREF(entry_valstack_end_byteoff); - DUK_DDD(DUK_DDDPRINT("not a tail call, pushing a new activation to callstack, to index %ld", - (long) (thr->callstack_top))); + DUK_DDD(DUK_DDDPRINT("not a tail call, pushing a new activation to callstack, to index %ld", (long) (thr->callstack_top))); duk__call_callstack_limit_check(thr); new_act = duk_hthread_activation_alloc(thr); @@ -66700,7 +67929,7 @@ act = new_act; *out_act = act; - DUK_ASSERT(thr->valstack_top > thr->valstack_bottom); /* at least effective 'this' */ + DUK_ASSERT(thr->valstack_top > thr->valstack_bottom); /* at least effective 'this' */ DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); act->cat = NULL; @@ -66719,9 +67948,9 @@ } /* start of arguments: idx_func + 2. */ - act->func = func; /* NULL for lightfunc */ + act->func = func; /* NULL for lightfunc */ if (DUK_LIKELY(func != NULL)) { - DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ + DUK_TVAL_SET_OBJECT(&act->tv_func, func); /* borrowed, no refcount */ if (DUK_HOBJECT_HAS_STRICT(func)) { act->flags |= DUK_ACT_FLAG_STRICT; } @@ -66730,8 +67959,9 @@ *out_nregs = ((duk_hcompfunc *) func)->nregs; DUK_ASSERT(*out_nregs >= 0); DUK_ASSERT(*out_nregs >= *out_nargs); - *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_INTERNAL_EXTRA); } else { /* True because of call target lookup checks. */ DUK_ASSERT(DUK_HOBJECT_IS_NATFUNC(func)); @@ -66739,13 +67969,16 @@ *out_nargs = ((duk_hnatfunc *) func)->nargs; *out_nregs = *out_nargs; if (*out_nargs >= 0) { - *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + *out_vs_min_bytes = + entry_valstack_bottom_byteoff + + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nregs + + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); } else { /* Vararg function. */ - duk_size_t valstack_top_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); - *out_vs_min_bytes = valstack_top_byteoff + - sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + duk_size_t valstack_top_byteoff = + (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); + *out_vs_min_bytes = valstack_top_byteoff + sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + + DUK_VALSTACK_INTERNAL_EXTRA); } } } else { @@ -66756,18 +67989,20 @@ tv_func = DUK_GET_TVAL_POSIDX(thr, idx_func); DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(tv_func)); - DUK_TVAL_SET_TVAL(&act->tv_func, tv_func); /* borrowed, no refcount */ + DUK_TVAL_SET_TVAL(&act->tv_func, tv_func); /* borrowed, no refcount */ lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv_func); *out_nargs = DUK_LFUNC_FLAGS_GET_NARGS(lf_flags); if (*out_nargs != DUK_LFUNC_NARGS_VARARGS) { *out_vs_min_bytes = entry_valstack_bottom_byteoff + - sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nargs + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + sizeof(duk_tval) * ((duk_size_t) idx_func + 2U + (duk_size_t) *out_nargs + + DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); } else { - duk_size_t valstack_top_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); + duk_size_t valstack_top_byteoff = + (duk_size_t) ((duk_uint8_t *) thr->valstack_top - ((duk_uint8_t *) thr->valstack)); *out_vs_min_bytes = valstack_top_byteoff + - sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); - *out_nargs = -1; /* vararg */ + sizeof(duk_tval) * (DUK_VALSTACK_API_ENTRY_MINIMUM + DUK_VALSTACK_INTERNAL_EXTRA); + *out_nargs = -1; /* vararg */ } *out_nregs = *out_nargs; } @@ -66789,13 +68024,13 @@ * even in error unwind because reserve_byteoff is only used when * returning to -this- activation. */ - act->reserve_byteoff = 0; /* filled in by caller */ + act->reserve_byteoff = 0; /* filled in by caller */ /* XXX: Is this INCREF necessary? 'func' is always a borrowed * reference reachable through the value stack? If changed, stack * unwind code also needs to be fixed to match. */ - DUK_HOBJECT_INCREF_ALLOWNULL(thr, func); /* act->func */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, func); /* act->func */ #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) if (func) { @@ -66811,7 +68046,7 @@ DUK_LOCAL void duk__call_env_setup(duk_hthread *thr, duk_hobject *func, duk_activation *act, duk_idx_t idx_args) { duk_hobject *env; - DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound function has already been resolved */ + DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound function has already been resolved */ if (DUK_LIKELY(func != NULL)) { if (DUK_LIKELY(DUK_HOBJECT_HAS_NEWENV(func))) { @@ -66842,7 +68077,7 @@ act->lex_env = env; act->var_env = env; DUK_HOBJECT_INCREF(thr, env); - DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (2) directly */ + DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (2) directly */ duk_pop(thr); } } else { @@ -66880,8 +68115,7 @@ goto thread_state_error; } } else { - DUK_ASSERT(thr->heap->curr_thread == NULL || - thr->heap->curr_thread->state == DUK_HTHREAD_STATE_RUNNING); + DUK_ASSERT(thr->heap->curr_thread == NULL || thr->heap->curr_thread->state == DUK_HTHREAD_STATE_RUNNING); if (DUK_UNLIKELY(thr->state != DUK_HTHREAD_STATE_INACTIVE)) { goto thread_state_error; } @@ -66896,7 +68130,7 @@ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); return; - thread_state_error: +thread_state_error: DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "invalid thread state (%ld)", (long) thr->state); DUK_WO_NORETURN(return;); } @@ -66922,9 +68156,7 @@ * place; the only guarantee is that the state is consistent for unwinding. */ -DUK_LOCAL duk_int_t duk__handle_call_raw(duk_hthread *thr, - duk_idx_t idx_func, - duk_small_uint_t call_flags) { +DUK_LOCAL duk_int_t duk__handle_call_raw(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags) { #if defined(DUK_USE_ASSERTIONS) duk_activation *entry_act; duk_size_t entry_callstack_top; @@ -66936,10 +68168,10 @@ duk_uint_fast8_t entry_thread_state; duk_instr_t **entry_ptr_curr_pc; duk_idx_t idx_args; - duk_idx_t nargs; /* # argument registers target function wants (< 0 => "as is") */ - duk_idx_t nregs; /* # total registers target function wants on entry (< 0 => "as is") */ - duk_size_t vs_min_bytes; /* minimum value stack size (bytes) for handling call */ - duk_hobject *func; /* 'func' on stack (borrowed reference) */ + duk_idx_t nargs; /* # argument registers target function wants (< 0 => "as is") */ + duk_idx_t nregs; /* # total registers target function wants on entry (< 0 => "as is") */ + duk_size_t vs_min_bytes; /* minimum value stack size (bytes) for handling call */ + duk_hobject *func; /* 'func' on stack (borrowed reference) */ duk_activation *act; duk_ret_t rc; duk_small_uint_t use_tailcall; @@ -66980,7 +68212,7 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(tmp_cat) == DUK_CAT_TYPE_LABEL); /* a non-catching entry */ } } -#endif /* DUK_USE_ASSERTIONS */ +#endif /* DUK_USE_ASSERTIONS */ /* * Store entry state. @@ -66993,9 +68225,9 @@ entry_valstack_bottom_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack); entry_valstack_end_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); entry_call_recursion_depth = thr->heap->call_recursion_depth; - entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ + entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ entry_thread_state = thr->state; - entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ + entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ /* If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL * thr->ptr_curr_pc so that it's not accidentally used with an incorrect @@ -67063,11 +68295,10 @@ DUK_DDD(DUK_DDDPRINT("slow path target resolve")); func = duk__resolve_target_func_and_this_binding(thr, idx_func, &call_flags); } - DUK_ASSERT(duk_get_top(thr) - idx_func >= 2); /* at least func and this present */ + DUK_ASSERT(duk_get_top(thr) - idx_func >= 2); /* at least func and this present */ DUK_ASSERT(func == NULL || !DUK_HOBJECT_HAS_BOUNDFUNC(func)); - DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || - DUK_HOBJECT_IS_NATFUNC(func))); + DUK_ASSERT(func == NULL || (DUK_HOBJECT_IS_COMPFUNC(func) || DUK_HOBJECT_IS_NATFUNC(func))); /* ... func this arg1 ... argN */ @@ -67102,7 +68333,7 @@ &act); } #else - DUK_ASSERT((call_flags & DUK_CALL_FLAG_TAILCALL) == 0); /* compiler ensures this */ + DUK_ASSERT((call_flags & DUK_CALL_FLAG_TAILCALL) == 0); /* compiler ensures this */ use_tailcall = 0; #endif @@ -67129,6 +68360,15 @@ /* ... func this arg1 ... argN */ /* + * Grow value stack to required size before env setup. This + * must happen before env setup to handle some corner cases + * correctly, e.g. test-bug-scope-segv-gh2448.js. + */ + + duk_valstack_grow_check_throw(thr, vs_min_bytes); + act->reserve_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); + + /* * Environment record creation and 'arguments' object creation. * Named function expression name binding is handled by the * compiler; the compiled function's parent env will contain @@ -67149,13 +68389,8 @@ * Setup value stack: clamp to 'nargs', fill up to 'nregs', * ensure value stack size matches target requirements, and * switch value stack bottom. Valstack top is kept. - * - * Value stack can only grow here. */ - duk_valstack_grow_check_throw(thr, vs_min_bytes); - act->reserve_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack); - if (use_tailcall) { DUK_ASSERT(nregs >= 0); DUK_ASSERT(nregs >= nargs); @@ -67194,8 +68429,8 @@ DUK_ASSERT((act->flags & DUK_ACT_FLAG_PREVENT_YIELD) == 0); DUK_REFZERO_CHECK_FAST(thr); DUK_ASSERT(thr->ptr_curr_pc == NULL); - thr->heap->call_recursion_depth--; /* No recursion increase for this case. */ - return 1; /* 1=reuse executor */ + thr->heap->call_recursion_depth--; /* No recursion increase for this case. */ + return 1; /* 1=reuse executor */ } DUK_ASSERT(use_tailcall == 0); @@ -67319,7 +68554,7 @@ /* Explicit check for fastint downgrade. */ DUK_TVAL_CHKFAST_INPLACE_FAST(tv_funret); #endif - DUK_TVAL_SET_TVAL_UPDREF(thr, tv_ret, tv_funret); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv_ret, tv_funret); /* side effects */ } duk_set_top_unsafe(thr, idx_func + 1); @@ -67338,7 +68573,7 @@ /* Restore entry thread executor curr_pc stack frame pointer. */ thr->ptr_curr_pc = entry_ptr_curr_pc; - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; /* Disabled assert: triggered with some torture tests. */ @@ -67379,12 +68614,10 @@ DUK_REFZERO_CHECK_FAST(thr); - return 0; /* 0=call handled inline */ + return 0; /* 0=call handled inline */ } -DUK_INTERNAL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, - duk_idx_t nargs, - duk_small_uint_t call_flags) { +DUK_INTERNAL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags) { duk_idx_t idx_func; DUK_ASSERT(duk_get_top(thr) >= nargs + 2); idx_func = duk_get_top(thr) - (nargs + 2); @@ -67392,9 +68625,7 @@ return duk_handle_call_unprotected(thr, idx_func, call_flags); } -DUK_INTERNAL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, - duk_idx_t idx_func, - duk_small_uint_t call_flags) { +DUK_INTERNAL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags) { DUK_ASSERT(duk_is_valid_index(thr, idx_func)); DUK_ASSERT(idx_func >= 0); return duk__handle_call_raw(thr, idx_func, call_flags); @@ -67461,7 +68692,8 @@ /* we're running inside the caller's activation, so no change in call/catch stack or valstack bottom */ DUK_ASSERT(thr->callstack_top == entry_callstack_top); DUK_ASSERT(thr->valstack_bottom >= thr->valstack); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == entry_valstack_bottom_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == + entry_valstack_bottom_byteoff); DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom); DUK_ASSERT(thr->valstack_end >= thr->valstack_top); @@ -67471,9 +68703,9 @@ } DUK_ASSERT(rc >= 0); - duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, rc); /* throws for insane rc */ + duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, rc); /* throws for insane rc */ - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; } @@ -67526,7 +68758,7 @@ /* Switch active thread before any side effects to avoid a * dangling curr_thread pointer. */ - DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ + DUK_HEAP_SWITCH_THREAD(thr->heap, entry_curr_thread); /* may be NULL */ thr->state = (duk_uint8_t) entry_thread_state; DUK_ASSERT(thr->heap->curr_thread == entry_curr_thread); @@ -67542,9 +68774,9 @@ /* ... | (crud) errobj */ - DUK_ASSERT(duk_get_top(thr) >= 1); /* at least errobj must be on stack */ + DUK_ASSERT(duk_get_top(thr) >= 1); /* at least errobj must be on stack */ - duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, 1); /* 1 = num actual 'return values' */ + duk__safe_call_adjust_valstack(thr, idx_retbase, num_stack_rets, 1); /* 1 = num actual 'return values' */ /* ... | or ... | errobj (M * undefined) where M = num_stack_rets - 1 */ @@ -67630,7 +68862,7 @@ duk_int_t retval; DUK_ASSERT(thr != NULL); - DUK_ASSERT(duk_get_top(thr) >= num_stack_args); /* Caller ensures. */ + DUK_ASSERT(duk_get_top(thr) >= num_stack_args); /* Caller ensures. */ DUK_STATS_INC(thr->heap, stats_safecall_all); @@ -67649,14 +68881,14 @@ entry_callstack_preventcount = thr->callstack_preventcount; #endif entry_call_recursion_depth = thr->heap->call_recursion_depth; - entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ + entry_curr_thread = thr->heap->curr_thread; /* may be NULL if first call */ entry_thread_state = thr->state; - entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ - idx_retbase = duk_get_top(thr) - num_stack_args; /* not a valid stack index if num_stack_args == 0 */ + entry_ptr_curr_pc = thr->ptr_curr_pc; /* may be NULL */ + idx_retbase = duk_get_top(thr) - num_stack_args; /* not a valid stack index if num_stack_args == 0 */ DUK_ASSERT(idx_retbase >= 0); - DUK_ASSERT((duk_idx_t) (thr->valstack_top - thr->valstack_bottom) >= num_stack_args); /* Caller ensures. */ - DUK_ASSERT((duk_idx_t) (thr->valstack_end - (thr->valstack_bottom + idx_retbase)) >= num_stack_rets); /* Caller ensures. */ + DUK_ASSERT((duk_idx_t) (thr->valstack_top - thr->valstack_bottom) >= num_stack_args); /* Caller ensures. */ + DUK_ASSERT((duk_idx_t) (thr->valstack_end - (thr->valstack_bottom + idx_retbase)) >= num_stack_rets); /* Caller ensures. */ /* Cannot portably debug print a function pointer, hence 'func' not printed! */ DUK_DD(DUK_DDPRINT("duk_handle_safe_call: thr=%p, num_stack_args=%ld, num_stack_rets=%ld, " @@ -67716,7 +68948,8 @@ * whatever calls are made. Reserve cannot decrease. */ DUK_ASSERT(thr->callstack_curr == entry_act); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); retval = DUK_EXEC_SUCCESS; #if defined(DUK_USE_CPP_EXCEPTIONS) @@ -67726,7 +68959,8 @@ } else { /* Error path. */ #endif - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); @@ -67751,14 +68985,18 @@ throw; } catch (std::exception &exc) { const char *what = exc.what(); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); if (!what) { what = "unknown"; } DUK_D(DUK_DPRINT("unexpected c++ std::exception (perhaps thrown by user code)")); try { - DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", what); + DUK_ERROR_FMT1(thr, + DUK_ERR_TYPE_ERROR, + "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", + what); DUK_WO_NORETURN(return 0;); } catch (duk_internal_exception exc) { DUK_D(DUK_DPRINT("caught api error thrown from unexpected c++ std::exception")); @@ -67778,7 +69016,8 @@ } } catch (...) { DUK_D(DUK_DPRINT("unexpected c++ exception (perhaps thrown by user code)")); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= + entry_valstack_end_byteoff); DUK_STATS_INC(thr->heap, stats_safecall_throw); try { DUK_ERROR_TYPE(thr, "caught invalid c++ exception (perhaps thrown by user code)"); @@ -67802,7 +69041,7 @@ } #endif - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr == old_jmpbuf_ptr); /* success/error path both do this */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr == old_jmpbuf_ptr); /* success/error path both do this */ DUK_ASSERT_LJSTATE_UNSET(thr->heap); @@ -67823,7 +69062,8 @@ /* Final asserts. */ DUK_ASSERT(thr->callstack_curr == entry_act); - DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == entry_valstack_bottom_byteoff); + DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) == + entry_valstack_bottom_byteoff); DUK_ASSERT((duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack) >= entry_valstack_end_byteoff); DUK_ASSERT(thr->callstack_top == entry_callstack_top); DUK_ASSERT(thr->heap->call_recursion_depth == entry_call_recursion_depth); @@ -67884,8 +69124,11 @@ str_base = duk_get_type_name(thr, -3); duk_push_error_object(thr, DUK_ERR_TYPE_ERROR | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - "%s not callable (property %s of %s)", str_targ, str_key, str_base); - duk_xdef_prop_stridx(thr, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ + "%s not callable (property %s of %s)", + str_targ, + str_key, + str_base); + duk_xdef_prop_stridx(thr, -2, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ /* <nargs> target base key { _Target: error } */ duk_replace(thr, entry_top - 1); #else @@ -67894,9 +69137,12 @@ str_base = duk_push_string_readable(thr, -5); duk_push_error_object(thr, DUK_ERR_TYPE_ERROR | DUK_ERRCODE_FLAG_NOBLAME_FILELINE, - "%s not callable (property %s of %s)", str_targ, str_key, str_base); + "%s not callable (property %s of %s)", + str_targ, + str_key, + str_base); /* <nargs> target base key {} str_targ str_key str_base error */ - duk_xdef_prop_stridx(thr, -5, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ + duk_xdef_prop_stridx(thr, -5, DUK_STRIDX_INT_TARGET, DUK_PROPDESC_FLAGS_NONE); /* Marker property, reuse _Target. */ /* <nargs> target base key { _Target: error } str_targ str_key str_base */ duk_swap(thr, -4, entry_top - 1); /* <nargs> { _Target: error } base key target str_targ str_key str_base */ @@ -67906,9 +69152,9 @@ duk_set_top(thr, entry_top); /* <nregs> { _Target: error } */ - DUK_ASSERT(!duk_is_callable(thr, -1)); /* Critical so that call handling will throw the error. */ + DUK_ASSERT(!duk_is_callable(thr, -1)); /* Critical so that call handling will throw the error. */ } -#endif /* DUK_USE_VERBOSE_ERRORS */ +#endif /* DUK_USE_VERBOSE_ERRORS */ /* automatic undefs */ #undef DUK__AUGMENT_CALL_RELAX_COUNT @@ -67950,45 +69196,51 @@ * uses this approach to avoid an explicit DUK__ISREG() check (the condition is * logically "'x' is a register AND 'x' >= temp_first"). */ -#define DUK__CONST_MARKER DUK_REGCONST_CONST_MARKER -#define DUK__REMOVECONST(x) ((x) & ~DUK__CONST_MARKER) -#define DUK__ISREG(x) ((x) >= 0) -#define DUK__ISCONST(x) ((x) < 0) -#define DUK__ISREG_TEMP(comp_ctx,x) ((duk_int32_t) (x) >= (duk_int32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= temp_first && x >= 0 by comparing as signed. */ -#define DUK__ISREG_NOTTEMP(comp_ctx,x) ((duk_uint32_t) (x) < (duk_uint32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= 0 && x < temp_first by interpreting as unsigned. */ -#define DUK__GETTEMP(comp_ctx) ((comp_ctx)->curr_func.temp_next) -#define DUK__SETTEMP(comp_ctx,x) ((comp_ctx)->curr_func.temp_next = (x)) /* dangerous: must only lower (temp_max not updated) */ -#define DUK__SETTEMP_CHECKMAX(comp_ctx,x) duk__settemp_checkmax((comp_ctx),(x)) -#define DUK__ALLOCTEMP(comp_ctx) duk__alloctemp((comp_ctx)) -#define DUK__ALLOCTEMPS(comp_ctx,count) duk__alloctemps((comp_ctx),(count)) +#define DUK__CONST_MARKER DUK_REGCONST_CONST_MARKER +#define DUK__REMOVECONST(x) ((x) & ~DUK__CONST_MARKER) +#define DUK__ISREG(x) ((x) >= 0) +#define DUK__ISCONST(x) ((x) < 0) +#define DUK__ISREG_TEMP(comp_ctx, x) \ + ((duk_int32_t) (x) >= \ + (duk_int32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= temp_first && x >= 0 by comparing as signed. */ +#define DUK__ISREG_NOTTEMP(comp_ctx, x) \ + ((duk_uint32_t) (x) < \ + (duk_uint32_t) ((comp_ctx)->curr_func.temp_first)) /* Check for x >= 0 && x < temp_first by interpreting as unsigned. */ +#define DUK__GETTEMP(comp_ctx) ((comp_ctx)->curr_func.temp_next) +#define DUK__SETTEMP(comp_ctx, x) ((comp_ctx)->curr_func.temp_next = (x)) /* dangerous: must only lower (temp_max not updated) */ +#define DUK__SETTEMP_CHECKMAX(comp_ctx, x) duk__settemp_checkmax((comp_ctx), (x)) +#define DUK__ALLOCTEMP(comp_ctx) duk__alloctemp((comp_ctx)) +#define DUK__ALLOCTEMPS(comp_ctx, count) duk__alloctemps((comp_ctx), (count)) /* Init value set size for array and object literals. */ -#define DUK__MAX_ARRAY_INIT_VALUES 20 -#define DUK__MAX_OBJECT_INIT_PAIRS 10 +#define DUK__MAX_ARRAY_INIT_VALUES 20 +#define DUK__MAX_OBJECT_INIT_PAIRS 10 /* XXX: hack, remove when const lookup is not O(n) */ -#define DUK__GETCONST_MAX_CONSTS_CHECK 256 +#define DUK__GETCONST_MAX_CONSTS_CHECK 256 /* These limits are based on bytecode limits. Max temps is limited * by duk_hcompfunc nargs/nregs fields being 16 bits. */ -#define DUK__MAX_CONSTS DUK_BC_BC_MAX -#define DUK__MAX_FUNCS DUK_BC_BC_MAX -#define DUK__MAX_TEMPS 0xffffL +#define DUK__MAX_CONSTS DUK_BC_BC_MAX +#define DUK__MAX_FUNCS DUK_BC_BC_MAX +#define DUK__MAX_TEMPS 0xffffL /* Initial bytecode size allocation. */ #if defined(DUK_USE_PREFER_SIZE) -#define DUK__BC_INITIAL_INSTS 16 +#define DUK__BC_INITIAL_INSTS 16 #else -#define DUK__BC_INITIAL_INSTS 256 +#define DUK__BC_INITIAL_INSTS 256 #endif -#define DUK__RECURSION_INCREASE(comp_ctx,thr) do { \ +#define DUK__RECURSION_INCREASE(comp_ctx, thr) \ + do { \ DUK_DDD(DUK_DDDPRINT("RECURSION INCREASE: %s:%ld", (const char *) DUK_FILE_MACRO, (long) DUK_LINE_MACRO)); \ duk__comp_recursion_increase((comp_ctx)); \ } while (0) -#define DUK__RECURSION_DECREASE(comp_ctx,thr) do { \ +#define DUK__RECURSION_DECREASE(comp_ctx, thr) \ + do { \ DUK_DDD(DUK_DDDPRINT("RECURSION DECREASE: %s:%ld", (const char *) DUK_FILE_MACRO, (long) DUK_LINE_MACRO)); \ duk__comp_recursion_decrease((comp_ctx)); \ } while (0) @@ -67996,11 +69248,11 @@ /* Value stack slot limits: these are quite approximate right now, and * because they overlap in control flow, some could be eliminated. */ -#define DUK__COMPILE_ENTRY_SLOTS 8 -#define DUK__FUNCTION_INIT_REQUIRE_SLOTS 16 -#define DUK__FUNCTION_BODY_REQUIRE_SLOTS 16 -#define DUK__PARSE_STATEMENTS_SLOTS 16 -#define DUK__PARSE_EXPR_SLOTS 16 +#define DUK__COMPILE_ENTRY_SLOTS 8 +#define DUK__FUNCTION_INIT_REQUIRE_SLOTS 16 +#define DUK__FUNCTION_BODY_REQUIRE_SLOTS 16 +#define DUK__PARSE_STATEMENTS_SLOTS 16 +#define DUK__PARSE_EXPR_SLOTS 16 /* Temporary structure used to pass a stack allocated region through * duk_safe_call(). @@ -68032,10 +69284,14 @@ DUK_LOCAL_DECL duk_compiler_instr *duk__get_instr_ptr(duk_compiler_ctx *comp_ctx, duk_int_t pc); DUK_LOCAL_DECL void duk__emit(duk_compiler_ctx *comp_ctx, duk_instr_t ins); DUK_LOCAL_DECL void duk__emit_op_only(duk_compiler_ctx *comp_ctx, duk_small_uint_t op); -DUK_LOCAL_DECL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b, duk_regconst_t c); +DUK_LOCAL_DECL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, + duk_small_uint_t op_flags, + duk_regconst_t a, + duk_regconst_t b, + duk_regconst_t c); DUK_LOCAL_DECL void duk__emit_a_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b); DUK_LOCAL_DECL void duk__emit_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b, duk_regconst_t c); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL void duk__emit_a(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a); DUK_LOCAL_DECL void duk__emit_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b); #endif @@ -68049,7 +69305,12 @@ DUK_LOCAL_DECL void duk__insert_jump_entry(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc); DUK_LOCAL_DECL void duk__patch_jump(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc, duk_int_t target_pc); DUK_LOCAL_DECL void duk__patch_jump_here(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc); -DUK_LOCAL_DECL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, duk_int_t ldconst_pc, duk_int_t trycatch_pc, duk_regconst_t reg_catch, duk_regconst_t const_varname, duk_small_uint_t flags); +DUK_LOCAL_DECL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, + duk_int_t ldconst_pc, + duk_int_t trycatch_pc, + duk_regconst_t reg_catch, + duk_regconst_t const_varname, + duk_small_uint_t flags); DUK_LOCAL_DECL void duk__emit_if_false_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst); DUK_LOCAL_DECL void duk__emit_if_true_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst); DUK_LOCAL_DECL void duk__emit_invalid(duk_compiler_ctx *comp_ctx); @@ -68080,7 +69341,7 @@ duk_regconst_t forced_reg, duk_small_uint_t flags); DUK_LOCAL_DECL duk_regconst_t duk__ivalue_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *x); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__ivalue_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *x); #endif DUK_LOCAL_DECL void duk__ivalue_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *x, duk_int_t forced_reg); @@ -68094,7 +69355,13 @@ /* label handling */ DUK_LOCAL_DECL void duk__add_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_int_t pc_label, duk_int_t label_id); DUK_LOCAL_DECL void duk__update_label_flags(duk_compiler_ctx *comp_ctx, duk_int_t label_id, duk_small_uint_t flags); -DUK_LOCAL_DECL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_bool_t is_break, duk_int_t *out_label_id, duk_int_t *out_label_catch_depth, duk_int_t *out_label_pc, duk_bool_t *out_is_closest); +DUK_LOCAL_DECL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, + duk_hstring *h_label, + duk_bool_t is_break, + duk_int_t *out_label_id, + duk_int_t *out_label_catch_depth, + duk_int_t *out_label_pc, + duk_bool_t *out_is_closest); DUK_LOCAL_DECL void duk__reset_labels_to_length(duk_compiler_ctx *comp_ctx, duk_size_t len); /* top-down expression parser */ @@ -68108,26 +69375,32 @@ DUK_LOCAL_DECL void duk__exprtop(duk_compiler_ctx *ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); /* convenience helpers */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -DUK_LOCAL_DECL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg); +DUK_LOCAL_DECL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg); DUK_LOCAL_DECL duk_regconst_t duk__expr_toregconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__expr_totempconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif DUK_LOCAL_DECL void duk__expr_toplain(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); DUK_LOCAL_DECL void duk__expr_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); DUK_LOCAL_DECL duk_regconst_t duk__exprtop_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL duk_regconst_t duk__exprtop_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif -DUK_LOCAL_DECL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg); +DUK_LOCAL_DECL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg); DUK_LOCAL_DECL duk_regconst_t duk__exprtop_toregconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL_DECL void duk__exprtop_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags); #endif @@ -68137,7 +69410,11 @@ DUK_LOCAL_DECL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res); /* statement parsing */ -DUK_LOCAL_DECL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags, duk_regconst_t *out_reg_varbind, duk_regconst_t *out_rc_varname); +DUK_LOCAL_DECL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t expr_flags, + duk_regconst_t *out_reg_varbind, + duk_regconst_t *out_rc_varname); DUK_LOCAL_DECL void duk__parse_var_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags); DUK_LOCAL_DECL void duk__parse_for_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site); DUK_LOCAL_DECL void duk__parse_switch_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site); @@ -68151,18 +69428,25 @@ DUK_LOCAL_DECL void duk__parse_with_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res); DUK_LOCAL_DECL void duk__parse_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_bool_t allow_source_elem); DUK_LOCAL_DECL duk_int_t duk__stmt_label_site(duk_compiler_ctx *comp_ctx, duk_int_t label_id); -DUK_LOCAL_DECL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, duk_bool_t allow_source_elem, duk_bool_t expect_eof, duk_bool_t regexp_after); - -DUK_LOCAL_DECL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, duk_bool_t expect_eof, duk_bool_t implicit_return_value, duk_bool_t regexp_after, duk_small_int_t expect_token); +DUK_LOCAL_DECL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, + duk_bool_t allow_source_elem, + duk_bool_t expect_eof, + duk_bool_t regexp_after); + +DUK_LOCAL_DECL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, + duk_bool_t expect_eof, + duk_bool_t implicit_return_value, + duk_bool_t regexp_after, + duk_small_int_t expect_token); DUK_LOCAL_DECL void duk__parse_func_formals(duk_compiler_ctx *comp_ctx); DUK_LOCAL_DECL void duk__parse_func_like_raw(duk_compiler_ctx *comp_ctx, duk_small_uint_t flags); DUK_LOCAL_DECL duk_int_t duk__parse_func_like_fnum(duk_compiler_ctx *comp_ctx, duk_small_uint_t flags); -#define DUK__FUNC_FLAG_DECL (1 << 0) /* Parsing a function declaration. */ -#define DUK__FUNC_FLAG_GETSET (1 << 1) /* Parsing an object literal getter/setter. */ -#define DUK__FUNC_FLAG_METDEF (1 << 2) /* Parsing an object literal method definition shorthand. */ -#define DUK__FUNC_FLAG_PUSHNAME_PASS1 (1 << 3) /* Push function name when creating template (first pass only). */ -#define DUK__FUNC_FLAG_USE_PREVTOKEN (1 << 4) /* Use prev_token to start function parsing (workaround for object literal). */ +#define DUK__FUNC_FLAG_DECL (1 << 0) /* Parsing a function declaration. */ +#define DUK__FUNC_FLAG_GETSET (1 << 1) /* Parsing an object literal getter/setter. */ +#define DUK__FUNC_FLAG_METDEF (1 << 2) /* Parsing an object literal method definition shorthand. */ +#define DUK__FUNC_FLAG_PUSHNAME_PASS1 (1 << 3) /* Push function name when creating template (first pass only). */ +#define DUK__FUNC_FLAG_USE_PREVTOKEN (1 << 4) /* Use prev_token to start function parsing (workaround for object literal). */ /* * Parser control values for tokens. The token table is ordered by the @@ -68179,141 +69463,141 @@ /* XXX: actually single step levels would work just fine, clean up */ /* binding power "levels" (see doc/compiler.rst) */ -#define DUK__BP_INVALID 0 /* always terminates led() */ -#define DUK__BP_EOF 2 -#define DUK__BP_CLOSING 4 /* token closes expression, e.g. ')', '' */ -#define DUK__BP_FOR_EXPR DUK__BP_CLOSING /* bp to use when parsing a top level Expression */ -#define DUK__BP_COMMA 6 -#define DUK__BP_ASSIGNMENT 8 -#define DUK__BP_CONDITIONAL 10 -#define DUK__BP_LOR 12 -#define DUK__BP_LAND 14 -#define DUK__BP_BOR 16 -#define DUK__BP_BXOR 18 -#define DUK__BP_BAND 20 -#define DUK__BP_EQUALITY 22 -#define DUK__BP_RELATIONAL 24 -#define DUK__BP_SHIFT 26 -#define DUK__BP_ADDITIVE 28 -#define DUK__BP_MULTIPLICATIVE 30 -#define DUK__BP_EXPONENTIATION 32 -#define DUK__BP_POSTFIX 34 -#define DUK__BP_CALL 36 -#define DUK__BP_MEMBER 38 +#define DUK__BP_INVALID 0 /* always terminates led() */ +#define DUK__BP_EOF 2 +#define DUK__BP_CLOSING 4 /* token closes expression, e.g. ')', '' */ +#define DUK__BP_FOR_EXPR DUK__BP_CLOSING /* bp to use when parsing a top level Expression */ +#define DUK__BP_COMMA 6 +#define DUK__BP_ASSIGNMENT 8 +#define DUK__BP_CONDITIONAL 10 +#define DUK__BP_LOR 12 +#define DUK__BP_LAND 14 +#define DUK__BP_BOR 16 +#define DUK__BP_BXOR 18 +#define DUK__BP_BAND 20 +#define DUK__BP_EQUALITY 22 +#define DUK__BP_RELATIONAL 24 +#define DUK__BP_SHIFT 26 +#define DUK__BP_ADDITIVE 28 +#define DUK__BP_MULTIPLICATIVE 30 +#define DUK__BP_EXPONENTIATION 32 +#define DUK__BP_POSTFIX 34 +#define DUK__BP_CALL 36 +#define DUK__BP_MEMBER 38 #define DUK__TOKEN_LBP_BP_MASK 0x1f -#define DUK__TOKEN_LBP_FLAG_NO_REGEXP (1 << 5) /* regexp literal must not follow this token */ -#define DUK__TOKEN_LBP_FLAG_TERMINATES (1 << 6) /* terminates expression; e.g. post-increment/-decrement */ -#define DUK__TOKEN_LBP_FLAG_UNUSED (1 << 7) /* unused */ +#define DUK__TOKEN_LBP_FLAG_NO_REGEXP (1 << 5) /* regexp literal must not follow this token */ +#define DUK__TOKEN_LBP_FLAG_TERMINATES (1 << 6) /* terminates expression; e.g. post-increment/-decrement */ +#define DUK__TOKEN_LBP_FLAG_UNUSED (1 << 7) /* unused */ -#define DUK__TOKEN_LBP_GET_BP(x) ((duk_small_uint_t) (((x) & DUK__TOKEN_LBP_BP_MASK) * 2)) +#define DUK__TOKEN_LBP_GET_BP(x) ((duk_small_uint_t) (((x) &DUK__TOKEN_LBP_BP_MASK) * 2)) -#define DUK__MK_LBP(bp) ((bp) >> 1) /* bp is assumed to be even */ -#define DUK__MK_LBP_FLAGS(bp,flags) (((bp) >> 1) | (flags)) +#define DUK__MK_LBP(bp) ((bp) >> 1) /* bp is assumed to be even */ +#define DUK__MK_LBP_FLAGS(bp, flags) (((bp) >> 1) | (flags)) DUK_LOCAL const duk_uint8_t duk__token_lbp = { - DUK__MK_LBP(DUK__BP_EOF), /* DUK_TOK_EOF */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_IDENTIFIER */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BREAK */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CASE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CATCH */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONTINUE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEBUGGER */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEFAULT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DELETE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DO */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ELSE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FINALLY */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FOR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FUNCTION */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IF */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_IN */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_INSTANCEOF */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_NEW */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_RETURN */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SWITCH */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_THIS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_THROW */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TRY */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TYPEOF */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VAR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONST */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VOID */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WHILE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WITH */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CLASS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ENUM */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXPORT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXTENDS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPORT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SUPER */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NULL */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_TRUE */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_FALSE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_GET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPLEMENTS */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_INTERFACE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LET */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PACKAGE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PRIVATE */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PROTECTED */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PUBLIC */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_STATIC */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_YIELD */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LCURLY */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RCURLY */ - DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_LBRACKET */ - DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RBRACKET */ - DUK__MK_LBP(DUK__BP_CALL), /* DUK_TOK_LPAREN */ - DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RPAREN */ - DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_PERIOD */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SEMICOLON */ - DUK__MK_LBP(DUK__BP_COMMA), /* DUK_TOK_COMMA */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LT */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GT */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LE */ - DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GE */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_EQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_NEQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SEQ */ - DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SNEQ */ - DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_ADD */ - DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_SUB */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MUL */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_DIV */ - DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MOD */ - DUK__MK_LBP(DUK__BP_EXPONENTIATION), /* DUK_TOK_EXP */ - DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_INCREMENT */ - DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_DECREMENT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ALSHIFT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ARSHIFT */ - DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_RSHIFT */ - DUK__MK_LBP(DUK__BP_BAND), /* DUK_TOK_BAND */ - DUK__MK_LBP(DUK__BP_BOR), /* DUK_TOK_BOR */ - DUK__MK_LBP(DUK__BP_BXOR), /* DUK_TOK_BXOR */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LNOT */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BNOT */ - DUK__MK_LBP(DUK__BP_LAND), /* DUK_TOK_LAND */ - DUK__MK_LBP(DUK__BP_LOR), /* DUK_TOK_LOR */ - DUK__MK_LBP(DUK__BP_CONDITIONAL), /* DUK_TOK_QUESTION */ - DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_COLON */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EQUALSIGN */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ADD_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_SUB_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MUL_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_DIV_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MOD_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EXP_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ALSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ARSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_RSHIFT_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BAND_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BOR_EQ */ - DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BXOR_EQ */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NUMBER */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_STRING */ - DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_REGEXP */ + DUK__MK_LBP(DUK__BP_EOF), /* DUK_TOK_EOF */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_IDENTIFIER */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BREAK */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CASE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CATCH */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONTINUE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEBUGGER */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DEFAULT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DELETE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_DO */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ELSE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FINALLY */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FOR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_FUNCTION */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IF */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_IN */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_INSTANCEOF */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_NEW */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_RETURN */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SWITCH */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_THIS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_THROW */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TRY */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_TYPEOF */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VAR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CONST */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_VOID */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WHILE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_WITH */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_CLASS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_ENUM */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXPORT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_EXTENDS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPORT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SUPER */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NULL */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_TRUE */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_FALSE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_GET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_IMPLEMENTS */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_INTERFACE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LET */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PACKAGE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PRIVATE */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PROTECTED */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_PUBLIC */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_STATIC */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_YIELD */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LCURLY */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RCURLY */ + DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_LBRACKET */ + DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RBRACKET */ + DUK__MK_LBP(DUK__BP_CALL), /* DUK_TOK_LPAREN */ + DUK__MK_LBP_FLAGS(DUK__BP_CLOSING, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_RPAREN */ + DUK__MK_LBP(DUK__BP_MEMBER), /* DUK_TOK_PERIOD */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_SEMICOLON */ + DUK__MK_LBP(DUK__BP_COMMA), /* DUK_TOK_COMMA */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LT */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GT */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_LE */ + DUK__MK_LBP(DUK__BP_RELATIONAL), /* DUK_TOK_GE */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_EQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_NEQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SEQ */ + DUK__MK_LBP(DUK__BP_EQUALITY), /* DUK_TOK_SNEQ */ + DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_ADD */ + DUK__MK_LBP(DUK__BP_ADDITIVE), /* DUK_TOK_SUB */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MUL */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_DIV */ + DUK__MK_LBP(DUK__BP_MULTIPLICATIVE), /* DUK_TOK_MOD */ + DUK__MK_LBP(DUK__BP_EXPONENTIATION), /* DUK_TOK_EXP */ + DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_INCREMENT */ + DUK__MK_LBP_FLAGS(DUK__BP_POSTFIX, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_DECREMENT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ALSHIFT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_ARSHIFT */ + DUK__MK_LBP(DUK__BP_SHIFT), /* DUK_TOK_RSHIFT */ + DUK__MK_LBP(DUK__BP_BAND), /* DUK_TOK_BAND */ + DUK__MK_LBP(DUK__BP_BOR), /* DUK_TOK_BOR */ + DUK__MK_LBP(DUK__BP_BXOR), /* DUK_TOK_BXOR */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_LNOT */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_BNOT */ + DUK__MK_LBP(DUK__BP_LAND), /* DUK_TOK_LAND */ + DUK__MK_LBP(DUK__BP_LOR), /* DUK_TOK_LOR */ + DUK__MK_LBP(DUK__BP_CONDITIONAL), /* DUK_TOK_QUESTION */ + DUK__MK_LBP(DUK__BP_INVALID), /* DUK_TOK_COLON */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EQUALSIGN */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ADD_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_SUB_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MUL_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_DIV_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_MOD_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_EXP_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ALSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_ARSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_RSHIFT_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BAND_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BOR_EQ */ + DUK__MK_LBP(DUK__BP_ASSIGNMENT), /* DUK_TOK_BXOR_EQ */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_NUMBER */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_STRING */ + DUK__MK_LBP_FLAGS(DUK__BP_INVALID, DUK__TOKEN_LBP_FLAG_NO_REGEXP), /* DUK_TOK_REGEXP */ }; /* @@ -68344,8 +69628,7 @@ DUK_LOCAL duk_bool_t duk__hstring_is_eval_or_arguments_in_strict_mode(duk_compiler_ctx *comp_ctx, duk_hstring *h) { DUK_ASSERT(h != NULL); - return (comp_ctx->curr_func.is_strict && - DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(h)); + return (comp_ctx->curr_func.is_strict && DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(h)); } /* @@ -68360,8 +69643,8 @@ duk_hthread *thr = comp_ctx->thr; duk_bool_t regexp; - DUK_ASSERT_DISABLE(comp_ctx->curr_token.t >= 0); /* unsigned */ - DUK_ASSERT(comp_ctx->curr_token.t <= DUK_TOK_MAXVAL); /* MAXVAL is inclusive */ + DUK_ASSERT_DISABLE(comp_ctx->curr_token.t >= 0); /* unsigned */ + DUK_ASSERT(comp_ctx->curr_token.t <= DUK_TOK_MAXVAL); /* MAXVAL is inclusive */ /* * Use current token to decide whether a RegExp can follow. @@ -68386,8 +69669,7 @@ } if (expect >= 0 && comp_ctx->curr_token.t != (duk_small_uint_t) expect) { - DUK_D(DUK_DPRINT("parse error: expect=%ld, got=%ld", - (long) expect, (long) comp_ctx->curr_token.t)); + DUK_D(DUK_DPRINT("parse error: expect=%ld, got=%ld", (long) expect, (long) comp_ctx->curr_token.t)); DUK_ERROR_SYNTAX(thr, DUK_STR_PARSE_ERROR); DUK_WO_NORETURN(return;); } @@ -68398,10 +69680,7 @@ duk_copy(thr, comp_ctx->tok12_idx, comp_ctx->tok22_idx); /* parse new token */ - duk_lexer_parse_js_input_element(&comp_ctx->lex, - &comp_ctx->curr_token, - comp_ctx->curr_func.is_strict, - regexp); + duk_lexer_parse_js_input_element(&comp_ctx->lex, &comp_ctx->curr_token, comp_ctx->curr_func.is_strict, regexp); DUK_DDD(DUK_DDDPRINT("advance: curr: tok=%ld/%ld,%ld,term=%ld,%!T,%!T " "prev: tok=%ld/%ld,%ld,term=%ld,%!T,%!T", @@ -68441,7 +69720,7 @@ entry_top = duk_get_top(thr); - duk_memzero(func, sizeof(*func)); /* intentional overlap with earlier memzero */ + duk_memzero(func, sizeof(*func)); /* intentional overlap with earlier memzero */ #if defined(DUK_USE_EXPLICIT_NULL_INIT) func->h_name = NULL; func->h_consts = NULL; @@ -68607,7 +69886,7 @@ h_res = duk_push_hcompfunc(thr); DUK_ASSERT(h_res != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_res) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); - DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) h_res, NULL); /* Function templates are "bare objects". */ + DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) h_res, NULL); /* Function templates are "bare objects". */ if (func->is_function) { DUK_DDD(DUK_DDDPRINT("function -> set NEWENV")); @@ -68676,16 +69955,19 @@ code_count = DUK_BW_GET_SIZE(thr, &func->bw_code) / sizeof(duk_compiler_instr); code_size = code_count * sizeof(duk_instr_t); - data_size = consts_count * sizeof(duk_tval) + - funcs_count * sizeof(duk_hobject *) + - code_size; + data_size = consts_count * sizeof(duk_tval) + funcs_count * sizeof(duk_hobject *) + code_size; DUK_DDD(DUK_DDDPRINT("consts_count=%ld, funcs_count=%ld, code_size=%ld -> " "data_size=%ld*%ld + %ld*%ld + %ld = %ld", - (long) consts_count, (long) funcs_count, (long) code_size, - (long) consts_count, (long) sizeof(duk_tval), - (long) funcs_count, (long) sizeof(duk_hobject *), - (long) code_size, (long) data_size)); + (long) consts_count, + (long) funcs_count, + (long) code_size, + (long) consts_count, + (long) sizeof(duk_tval), + (long) funcs_count, + (long) sizeof(duk_hobject *), + (long) code_size, + (long) data_size)); duk_push_fixed_buffer_nozero(thr, data_size); h_data = (duk_hbuffer_fixed *) (void *) duk_known_hbuffer(thr, -1); @@ -68695,12 +69977,12 @@ p_const = (duk_tval *) (void *) DUK_HBUFFER_FIXED_GET_DATA_PTR(thr->heap, h_data); for (i = 0; i < consts_count; i++) { - DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* const limits */ + DUK_ASSERT(i <= DUK_UARRIDX_MAX); /* const limits */ tv = duk_hobject_find_array_entry_tval_ptr(thr->heap, func->h_consts, (duk_uarridx_t) i); DUK_ASSERT(tv != NULL); DUK_TVAL_SET_TVAL(p_const, tv); p_const++; - DUK_TVAL_INCREF(thr, tv); /* may be a string constant */ + DUK_TVAL_INCREF(thr, tv); /* may be a string constant */ DUK_DDD(DUK_DDDPRINT("constant: %!T", (duk_tval *) tv)); } @@ -68709,7 +69991,7 @@ DUK_HCOMPFUNC_SET_FUNCS(thr->heap, h_res, p_func); for (i = 0; i < funcs_count; i++) { duk_hobject *h; - DUK_ASSERT(i * 3 <= DUK_UARRIDX_MAX); /* func limits */ + DUK_ASSERT(i * 3 <= DUK_UARRIDX_MAX); /* func limits */ tv = duk_hobject_find_array_entry_tval_ptr(thr->heap, func->h_funcs, (duk_uarridx_t) (i * 3)); DUK_ASSERT(tv != NULL); DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv)); @@ -68719,8 +70001,7 @@ *p_func++ = h; DUK_HOBJECT_INCREF(thr, h); - DUK_DDD(DUK_DDDPRINT("inner function: %p -> %!iO", - (void *) h, (duk_heaphdr *) h)); + DUK_DDD(DUK_DDDPRINT("inner function: %p -> %!iO", (void *) h, (duk_heaphdr *) h)); } p_instr = (duk_instr_t *) p_func; @@ -68735,7 +70016,7 @@ DUK_ASSERT((duk_uint8_t *) (p_instr + code_count) == DUK_HBUFFER_FIXED_GET_DATA_PTR(thr->heap, h_data) + data_size); - duk_pop(thr); /* 'data' (and everything in it) is reachable through h_res now */ + duk_pop(thr); /* 'data' (and everything in it) is reachable through h_res now */ /* * Init non-property result fields @@ -68750,7 +70031,7 @@ DUK_ASSERT(func->temp_max >= 0); h_res->nregs = (duk_uint16_t) func->temp_max; h_res->nargs = (duk_uint16_t) duk_hobject_get_length(thr, func->h_argnames); - DUK_ASSERT(h_res->nregs >= h_res->nargs); /* pass2 allocation handles this */ + DUK_ASSERT(h_res->nregs >= h_res->nargs); /* pass2 allocation handles this */ #if defined(DUK_USE_DEBUGGER_SUPPORT) h_res->start_line = (duk_uint32_t) func->min_line; h_res->end_line = (duk_uint32_t) func->max_line; @@ -68778,11 +70059,13 @@ DUK_DD(DUK_DDPRINT("keeping _Varmap because debugger support is enabled")); keep_varmap = 1; #else - if (func->id_access_slow_own || /* directly uses slow accesses that may match own variables */ - func->id_access_arguments || /* accesses 'arguments' directly */ - func->may_direct_eval || /* may indirectly slow access through a direct eval */ - funcs_count > 0) { /* has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions) */ - DUK_DD(DUK_DDPRINT("keeping _Varmap because of direct eval, slow path access that may match local variables, or presence of inner functions")); + if (func->id_access_slow_own || /* directly uses slow accesses that may match own variables */ + func->id_access_arguments || /* accesses 'arguments' directly */ + func->may_direct_eval || /* may indirectly slow access through a direct eval */ + funcs_count > + 0) { /* has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions) */ + DUK_DD(DUK_DDPRINT("keeping _Varmap because of direct eval, slow path access that may match local variables, or " + "presence of inner functions")); keep_varmap = 1; } else { DUK_DD(DUK_DDPRINT("dropping _Varmap")); @@ -68794,8 +70077,7 @@ duk_int_t num_used; duk_dup(thr, func->varmap_idx); num_used = duk__cleanup_varmap(comp_ctx); - DUK_DDD(DUK_DDDPRINT("cleaned up varmap: %!T (num_used=%ld)", - (duk_tval *) duk_get_tval(thr, -1), (long) num_used)); + DUK_DDD(DUK_DDDPRINT("cleaned up varmap: %!T (num_used=%ld)", (duk_tval *) duk_get_tval(thr, -1), (long) num_used)); if (num_used > 0) { duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VARMAP, DUK_PROPDESC_FLAGS_NONE); @@ -68824,12 +70106,12 @@ */ DUK_DD(DUK_DDPRINT("keeping _Formals because _Formals.length != nargs")); keep_formals = 1; - } else if ((func->id_access_arguments || func->may_direct_eval) && - (formals_length > 0)) { + } else if ((func->id_access_arguments || func->may_direct_eval) && (formals_length > 0)) { /* Direct eval (may access 'arguments') or accesses 'arguments' * explicitly: keep _Formals unless it is zero length. */ - DUK_DD(DUK_DDPRINT("keeping _Formals because of direct eval or explicit access to 'arguments', and _Formals.length != 0")); + DUK_DD(DUK_DDPRINT( + "keeping _Formals because of direct eval or explicit access to 'arguments', and _Formals.length != 0")); keep_formals = 1; } else { DUK_DD(DUK_DDPRINT("omitting _Formals, nargs matches _Formals.length, so no properties added")); @@ -68849,7 +70131,7 @@ DUK_DD(DUK_DDPRINT("setting function template .name to %!T", duk_get_tval(thr, -1))); duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_NONE); } -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ /* _Source */ #if defined(DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY) @@ -68897,7 +70179,7 @@ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_SOURCE, DUK_PROPDESC_FLAGS_NONE); #endif } -#endif /* DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY */ +#endif /* DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY */ /* _Pc2line */ #if defined(DUK_USE_PC2LINE) @@ -68907,14 +70189,14 @@ */ DUK_ASSERT(code_count <= DUK_COMPILER_MAX_BYTECODE_LENGTH); - duk_hobject_pc2line_pack(thr, q_instr, (duk_uint_fast32_t) code_count); /* -> pushes fixed buffer */ + duk_hobject_pc2line_pack(thr, q_instr, (duk_uint_fast32_t) code_count); /* -> pushes fixed buffer */ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_NONE); /* XXX: if assertions enabled, walk through all valid PCs * and check line mapping. */ } -#endif /* DUK_USE_PC2LINE */ +#endif /* DUK_USE_PC2LINE */ /* fileName */ #if defined(DUK_USE_FUNC_FILENAME_PROPERTY) @@ -68928,8 +70210,7 @@ } #endif - DUK_DD(DUK_DDPRINT("converted function: %!ixT", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DD(DUK_DDPRINT("converted function: %!ixT", (duk_tval *) duk_get_tval(thr, -1))); /* * Compact the function template. @@ -69001,14 +70282,14 @@ /* Code emission flags, passed in the 'opcode' field. Opcode + flags * fit into 16 bits for now, so use duk_small_uint_t. */ -#define DUK__EMIT_FLAG_NO_SHUFFLE_A (1 << 8) -#define DUK__EMIT_FLAG_NO_SHUFFLE_B (1 << 9) -#define DUK__EMIT_FLAG_NO_SHUFFLE_C (1 << 10) -#define DUK__EMIT_FLAG_A_IS_SOURCE (1 << 11) /* slot A is a source (default: target) */ -#define DUK__EMIT_FLAG_B_IS_TARGET (1 << 12) /* slot B is a target (default: source) */ -#define DUK__EMIT_FLAG_C_IS_TARGET (1 << 13) /* slot C is a target (default: source) */ -#define DUK__EMIT_FLAG_BC_REGCONST (1 << 14) /* slots B and C are reg/const */ -#define DUK__EMIT_FLAG_RESERVE_JUMPSLOT (1 << 15) /* reserve a jumpslot after instr before target spilling, used for NEXTENUM */ +#define DUK__EMIT_FLAG_NO_SHUFFLE_A (1 << 8) +#define DUK__EMIT_FLAG_NO_SHUFFLE_B (1 << 9) +#define DUK__EMIT_FLAG_NO_SHUFFLE_C (1 << 10) +#define DUK__EMIT_FLAG_A_IS_SOURCE (1 << 11) /* slot A is a source (default: target) */ +#define DUK__EMIT_FLAG_B_IS_TARGET (1 << 12) /* slot B is a target (default: source) */ +#define DUK__EMIT_FLAG_C_IS_TARGET (1 << 13) /* slot C is a target (default: source) */ +#define DUK__EMIT_FLAG_BC_REGCONST (1 << 14) /* slots B and C are reg/const */ +#define DUK__EMIT_FLAG_RESERVE_JUMPSLOT (1 << 15) /* reserve a jumpslot after instr before target spilling, used for NEXTENUM */ /* XXX: macro smaller than call? */ DUK_LOCAL duk_int_t duk__get_current_pc(duk_compiler_ctx *comp_ctx) { @@ -69019,7 +70300,8 @@ DUK_LOCAL duk_compiler_instr *duk__get_instr_ptr(duk_compiler_ctx *comp_ctx, duk_int_t pc) { DUK_ASSERT(pc >= 0); - DUK_ASSERT((duk_size_t) pc < (duk_size_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr))); + DUK_ASSERT((duk_size_t) pc < + (duk_size_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr))); return ((duk_compiler_instr *) (void *) DUK_BW_GET_BASEPTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code)) + pc; } @@ -69039,7 +70321,9 @@ (long) duk__get_current_pc(comp_ctx), (duk_instr_t) ins)); - instr = (duk_compiler_instr *) (void *) DUK_BW_ENSURE_GETPTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, sizeof(duk_compiler_instr)); + instr = (duk_compiler_instr *) (void *) DUK_BW_ENSURE_GETPTR(comp_ctx->thr, + &comp_ctx->curr_func.bw_code, + sizeof(duk_compiler_instr)); DUK_BW_ADD_PTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, sizeof(duk_compiler_instr)); #if defined(DUK_USE_PC2LINE) @@ -69090,7 +70374,7 @@ return; - fail_bc_limit: +fail_bc_limit: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_BYTECODE_LIMIT); DUK_WO_NORETURN(return;); } @@ -69124,7 +70408,11 @@ } /* Important main primitive. */ -DUK_LOCAL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t a, duk_regconst_t b, duk_regconst_t c) { +DUK_LOCAL void duk__emit_a_b_c(duk_compiler_ctx *comp_ctx, + duk_small_uint_t op_flags, + duk_regconst_t a, + duk_regconst_t b, + duk_regconst_t c) { duk_instr_t ins = 0; duk_int_t a_out = -1; duk_int_t b_out = -1; @@ -69132,8 +70420,7 @@ duk_int_t tmp; duk_small_uint_t op = op_flags & 0xffU; - DUK_DDD(DUK_DDDPRINT("emit: op_flags=%04lx, a=%ld, b=%ld, c=%ld", - (unsigned long) op_flags, (long) a, (long) b, (long) c)); + DUK_DDD(DUK_DDDPRINT("emit: op_flags=%04lx, a=%ld, b=%ld, c=%ld", (unsigned long) op_flags, (long) a, (long) b, (long) c)); /* We could rely on max temp/const checks: if they don't exceed BC * limit, nothing here can either (just asserts would be enough). @@ -69142,11 +70429,11 @@ * bugs. */ - DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT((op_flags & 0xff) <= DUK_BC_OP_MAX); DUK_ASSERT(DUK__ISREG(a)); - DUK_ASSERT(b != -1); /* Not 'none'. */ - DUK_ASSERT(c != -1); /* Not 'none'. */ + DUK_ASSERT(b != -1); /* Not 'none'. */ + DUK_ASSERT(c != -1); /* Not 'none'. */ /* Input shuffling happens before the actual operation, while output * shuffling happens afterwards. Output shuffling decisions are still @@ -69208,7 +70495,7 @@ if (op_flags & DUK__EMIT_FLAG_BC_REGCONST) { /* Opcode follows B/C reg/const convention. */ DUK_ASSERT((op & 0x01) == 0); - ins |= DUK_ENC_OP_A_B_C(0x01, 0, 0, 0); /* const flag for B */ + ins |= DUK_ENC_OP_A_B_C(0x01, 0, 0, 0); /* const flag for B */ } else { DUK_D(DUK_DPRINT("B is const, opcode is not B/C reg/const: %x", op_flags)); } @@ -69231,7 +70518,8 @@ } else if (op_flags & DUK__EMIT_FLAG_NO_SHUFFLE_B) { if (b > DUK_BC_B_MAX) { /* Note: 0xff != DUK_BC_B_MAX */ - DUK_D(DUK_DPRINT("out of regs: 'b' (reg) needs shuffling but shuffle prohibited, b: %ld", (long) b)); + DUK_D( + DUK_DPRINT("out of regs: 'b' (reg) needs shuffling but shuffle prohibited, b: %ld", (long) b)); goto error_outofregs; } } else if (b <= DUK_BC_BC_MAX) { @@ -69252,7 +70540,7 @@ duk__emit_load_int32_noshuffle(comp_ctx, tmp, b); DUK_ASSERT(DUK_OP_MPUTOBJI == DUK_OP_MPUTOBJ + 1); DUK_ASSERT(DUK_OP_MPUTARRI == DUK_OP_MPUTARR + 1); - op_flags++; /* indirect opcode follows direct */ + op_flags++; /* indirect opcode follows direct */ } else { duk__emit(comp_ctx, DUK_ENC_OP_A_BC(DUK_OP_LDREG, tmp, b)); } @@ -69278,7 +70566,7 @@ if (op_flags & DUK__EMIT_FLAG_BC_REGCONST) { /* Opcode follows B/C reg/const convention. */ DUK_ASSERT((op & 0x02) == 0); - ins |= DUK_ENC_OP_A_B_C(0x02, 0, 0, 0); /* const flag for C */ + ins |= DUK_ENC_OP_A_B_C(0x02, 0, 0, 0); /* const flag for C */ } else { DUK_D(DUK_DPRINT("C is const, opcode is not B/C reg/const: %x", op_flags)); } @@ -69301,7 +70589,8 @@ } else if (op_flags & DUK__EMIT_FLAG_NO_SHUFFLE_C) { if (c > DUK_BC_C_MAX) { /* Note: 0xff != DUK_BC_C_MAX */ - DUK_D(DUK_DPRINT("out of regs: 'c' (reg) needs shuffling but shuffle prohibited, c: %ld", (long) c)); + DUK_D( + DUK_DPRINT("out of regs: 'c' (reg) needs shuffling but shuffle prohibited, c: %ld", (long) c)); goto error_outofregs; } } else if (c <= DUK_BC_BC_MAX) { @@ -69375,7 +70664,7 @@ return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -69403,7 +70692,7 @@ duk__emit_a_b_c(comp_ctx, op_flags, 0, b, c); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__emit_a(duk_compiler_ctx *comp_ctx, int op_flags, int a) { #if defined(DUK_USE_SHUFFLE_TORTURE) op_flags |= DUK__EMIT_FLAG_NO_SHUFFLE_B | DUK__EMIT_FLAG_NO_SHUFFLE_C; @@ -69412,7 +70701,7 @@ } #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__emit_b(duk_compiler_ctx *comp_ctx, duk_small_uint_t op_flags, duk_regconst_t b) { #if defined(DUK_USE_SHUFFLE_TORTURE) op_flags |= DUK__EMIT_FLAG_NO_SHUFFLE_A | DUK__EMIT_FLAG_NO_SHUFFLE_C; @@ -69426,10 +70715,10 @@ duk_int_t tmp; /* allow caller to give a const number with the DUK__CONST_MARKER */ - DUK_ASSERT(bc != -1); /* Not 'none'. */ + DUK_ASSERT(bc != -1); /* Not 'none'. */ bc = bc & (~DUK__CONST_MARKER); - DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE((op_flags & 0xff) >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT((op_flags & 0xff) <= DUK_BC_OP_MAX); DUK_ASSERT(bc >= DUK_BC_BC_MIN); DUK_ASSERT(bc <= DUK_BC_BC_MAX); @@ -69474,7 +70763,7 @@ } return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -69489,12 +70778,12 @@ DUK_LOCAL void duk__emit_abc(duk_compiler_ctx *comp_ctx, duk_small_uint_t op, duk_regconst_t abc) { duk_instr_t ins; - DUK_ASSERT_DISABLE(op >= DUK_BC_OP_MIN); /* unsigned */ + DUK_ASSERT_DISABLE(op >= DUK_BC_OP_MIN); /* unsigned */ DUK_ASSERT(op <= DUK_BC_OP_MAX); - DUK_ASSERT_DISABLE(abc >= DUK_BC_ABC_MIN); /* unsigned */ + DUK_ASSERT_DISABLE(abc >= DUK_BC_ABC_MIN); /* unsigned */ DUK_ASSERT(abc <= DUK_BC_ABC_MAX); DUK_ASSERT((abc & DUK__CONST_MARKER) == 0); - DUK_ASSERT(abc != -1); /* Not 'none'. */ + DUK_ASSERT(abc != -1); /* Not 'none'. */ if (abc <= DUK_BC_ABC_MAX) { ; @@ -69503,18 +70792,25 @@ } ins = DUK_ENC_OP_ABC(op, abc); DUK_DDD(DUK_DDDPRINT("duk__emit_abc: 0x%08lx line=%ld pc=%ld op=%ld (%!X) abc=%ld (%!I)", - (unsigned long) ins, (long) comp_ctx->curr_token.start_line, - (long) duk__get_current_pc(comp_ctx), (long) op, (long) op, - (long) abc, (duk_instr_t) ins)); + (unsigned long) ins, + (long) comp_ctx->curr_token.start_line, + (long) duk__get_current_pc(comp_ctx), + (long) op, + (long) op, + (long) abc, + (duk_instr_t) ins)); duk__emit(comp_ctx, ins); return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } -DUK_LOCAL void duk__emit_load_int32_raw(duk_compiler_ctx *comp_ctx, duk_regconst_t reg, duk_int32_t val, duk_small_uint_t op_flags) { +DUK_LOCAL void duk__emit_load_int32_raw(duk_compiler_ctx *comp_ctx, + duk_regconst_t reg, + duk_int32_t val, + duk_small_uint_t op_flags) { /* XXX: Shuffling support could be implemented here so that LDINT+LDINTX * would only shuffle once (instead of twice). The current code works * though, and has a smaller compiler footprint. @@ -69529,7 +70825,10 @@ duk_int32_t lo = val & ((((duk_int32_t) 1) << DUK_BC_LDINTX_SHIFT) - 1); DUK_ASSERT(lo >= 0); DUK_DDD(DUK_DDDPRINT("emit LDINT+LDINTX to reg %ld for %ld -> hi %ld, lo %ld", - (long) reg, (long) val, (long) hi, (long) lo)); + (long) reg, + (long) val, + (long) hi, + (long) lo)); duk__emit_a_bc(comp_ctx, DUK_OP_LDINT | op_flags, reg, (duk_regconst_t) (hi + (duk_int32_t) DUK_BC_LDINT_BIAS)); duk__emit_a_bc(comp_ctx, DUK_OP_LDINTX | op_flags, reg, (duk_regconst_t) lo); } @@ -69570,7 +70869,7 @@ DUK_LOCAL duk_int_t duk__emit_jump_empty(duk_compiler_ctx *comp_ctx) { duk_int_t ret; - ret = duk__get_current_pc(comp_ctx); /* useful for patching jumps later */ + ret = duk__get_current_pc(comp_ctx); /* useful for patching jumps later */ duk__emit_op_only(comp_ctx, DUK_OP_JUMP); return ret; } @@ -69588,13 +70887,10 @@ DUK_ASSERT(jump_pc >= 0); offset = (duk_size_t) jump_pc * sizeof(duk_compiler_instr); instr = (duk_compiler_instr *) (void *) - DUK_BW_INSERT_ENSURE_AREA(comp_ctx->thr, - &comp_ctx->curr_func.bw_code, - offset, - sizeof(duk_compiler_instr)); + DUK_BW_INSERT_ENSURE_AREA(comp_ctx->thr, &comp_ctx->curr_func.bw_code, offset, sizeof(duk_compiler_instr)); #if defined(DUK_USE_PC2LINE) - line = comp_ctx->curr_token.start_line; /* approximation, close enough */ + line = comp_ctx->curr_token.start_line; /* approximation, close enough */ #endif instr->ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, 0); #if defined(DUK_USE_PC2LINE) @@ -69607,7 +70903,7 @@ } return; - fail_bc_limit: +fail_bc_limit: DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_BYTECODE_LIMIT); DUK_WO_NORETURN(return;); } @@ -69621,8 +70917,8 @@ /* allow negative PCs, behave as a no-op */ if (jump_pc < 0) { - DUK_DDD(DUK_DDDPRINT("duk__patch_jump(): nop call, jump_pc=%ld (<0), target_pc=%ld", - (long) jump_pc, (long) target_pc)); + DUK_DDD( + DUK_DDDPRINT("duk__patch_jump(): nop call, jump_pc=%ld (<0), target_pc=%ld", (long) jump_pc, (long) target_pc)); return; } DUK_ASSERT(jump_pc >= 0); @@ -69636,14 +70932,21 @@ instr->ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, offset + DUK_BC_JUMP_BIAS); DUK_DDD(DUK_DDDPRINT("duk__patch_jump(): jump_pc=%ld, target_pc=%ld, offset=%ld", - (long) jump_pc, (long) target_pc, (long) offset)); + (long) jump_pc, + (long) target_pc, + (long) offset)); } DUK_LOCAL void duk__patch_jump_here(duk_compiler_ctx *comp_ctx, duk_int_t jump_pc) { duk__patch_jump(comp_ctx, jump_pc, duk__get_current_pc(comp_ctx)); } -DUK_LOCAL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, duk_int_t ldconst_pc, duk_int_t trycatch_pc, duk_regconst_t reg_catch, duk_regconst_t const_varname, duk_small_uint_t flags) { +DUK_LOCAL void duk__patch_trycatch(duk_compiler_ctx *comp_ctx, + duk_int_t ldconst_pc, + duk_int_t trycatch_pc, + duk_regconst_t reg_catch, + duk_regconst_t const_varname, + duk_small_uint_t flags) { duk_compiler_instr *instr; DUK_ASSERT(DUK__ISREG(reg_catch)); @@ -69663,7 +70966,10 @@ * See: test-bug-trycatch-many-constants.js. */ DUK_D(DUK_DPRINT("failed to patch trycatch: flags=%ld, reg_catch=%ld, const_varname=%ld (0x%08lx)", - (long) flags, (long) reg_catch, (long) const_varname, (long) const_varname)); + (long) flags, + (long) reg_catch, + (long) const_varname, + (long) const_varname)); DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); } @@ -69686,14 +70992,14 @@ duk_small_uint_t op; op = DUK__ISREG(regconst) ? DUK_OP_IFFALSE_R : DUK_OP_IFFALSE_C; - duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ + duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ } DUK_LOCAL void duk__emit_if_true_skip(duk_compiler_ctx *comp_ctx, duk_regconst_t regconst) { duk_small_uint_t op; op = DUK__ISREG(regconst) ? DUK_OP_IFTRUE_R : DUK_OP_IFTRUE_C; - duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ + duk__emit_bc(comp_ctx, op, regconst); /* helper will remove const flag */ } DUK_LOCAL void duk__emit_invalid(duk_compiler_ctx *comp_ctx) { @@ -69717,7 +71023,8 @@ #if defined(DUK_USE_BUFLEN16) /* No need to assert, buffer size maximum is 0xffff. */ #else - DUK_ASSERT((duk_size_t) DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr) <= (duk_size_t) DUK_INT_MAX); /* bytecode limits */ + DUK_ASSERT((duk_size_t) DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr) <= + (duk_size_t) DUK_INT_MAX); /* bytecode limits */ #endif n = (duk_int_t) (DUK_BW_GET_SIZE(comp_ctx->thr, &comp_ctx->curr_func.bw_code) / sizeof(duk_compiler_instr)); @@ -69752,7 +71059,9 @@ target_pc2 = target_pc1 + 1 + (duk_int_t) DUK_DEC_ABC(ins) - (duk_int_t) DUK_BC_JUMP_BIAS; DUK_DDD(DUK_DDDPRINT("optimizing jump at pc %ld; old target is %ld -> new target is %ld", - (long) i, (long) target_pc1, (long) target_pc2)); + (long) i, + (long) target_pc1, + (long) target_pc2)); bci.ins = DUK_ENC_OP_ABC(DUK_OP_JUMP, target_pc2 - (i + 1) + DUK_BC_JUMP_BIAS); @@ -69778,15 +71087,21 @@ /* XXX: DUK__IVAL_FLAG_REQUIRE_SHORT is passed but not currently implemented * by ispec/ivalue operations. */ -#define DUK__IVAL_FLAG_ALLOW_CONST (1 << 0) /* allow a constant to be returned */ -#define DUK__IVAL_FLAG_REQUIRE_TEMP (1 << 1) /* require a (mutable) temporary as a result (or a const if allowed) */ -#define DUK__IVAL_FLAG_REQUIRE_SHORT (1 << 2) /* require a short (8-bit) reg/const which fits into bytecode B/C slot */ +#define DUK__IVAL_FLAG_ALLOW_CONST (1 << 0) /* allow a constant to be returned */ +#define DUK__IVAL_FLAG_REQUIRE_TEMP (1 << 1) /* require a (mutable) temporary as a result (or a const if allowed) */ +#define DUK__IVAL_FLAG_REQUIRE_SHORT (1 << 2) /* require a short (8-bit) reg/const which fits into bytecode B/C slot */ /* XXX: some code might benefit from DUK__SETTEMP_IFTEMP(thr,x) */ -#if 0 /* enable manually for dumping */ -#define DUK__DUMP_ISPEC(compctx,ispec) do { duk__dump_ispec((compctx), (ispec)); } while (0) -#define DUK__DUMP_IVALUE(compctx,ivalue) do { duk__dump_ivalue((compctx), (ivalue)); } while (0) +#if 0 /* enable manually for dumping */ +#define DUK__DUMP_ISPEC(compctx, ispec) \ + do { \ + duk__dump_ispec((compctx), (ispec)); \ + } while (0) +#define DUK__DUMP_IVALUE(compctx, ivalue) \ + do { \ + duk__dump_ivalue((compctx), (ivalue)); \ + } while (0) DUK_LOCAL void duk__dump_ispec(duk_compiler_ctx *comp_ctx, duk_ispec *x) { DUK_D(DUK_DPRINT("ispec dump: t=%ld regconst=0x%08lx, valstack_idx=%ld, value=%!T", @@ -69804,8 +71119,12 @@ duk_get_tval(comp_ctx->thr, x->x2.valstack_idx))); } #else -#define DUK__DUMP_ISPEC(comp_ctx,x) do {} while (0) -#define DUK__DUMP_IVALUE(comp_ctx,x) do {} while (0) +#define DUK__DUMP_ISPEC(comp_ctx, x) \ + do { \ + } while (0) +#define DUK__DUMP_IVALUE(comp_ctx, x) \ + do { \ + } while (0) #endif DUK_LOCAL void duk__ivalue_regconst(duk_ivalue *x, duk_regconst_t regconst) { @@ -69855,7 +71174,7 @@ res = comp_ctx->curr_func.temp_next; comp_ctx->curr_func.temp_next += num; - if (comp_ctx->curr_func.temp_next > DUK__MAX_TEMPS) { /* == DUK__MAX_TEMPS is OK */ + if (comp_ctx->curr_func.temp_next > DUK__MAX_TEMPS) { /* == DUK__MAX_TEMPS is OK */ DUK_ERROR_RANGE(comp_ctx->thr, DUK_STR_TEMP_LIMIT); DUK_WO_NORETURN(return 0;); } @@ -69908,8 +71227,7 @@ * constant for e.g. +0 and -0. */ if (duk_js_samevalue(tv1, tv2)) { - DUK_DDD(DUK_DDDPRINT("reused existing constant for %!T -> const index %ld", - (duk_tval *) tv1, (long) i)); + DUK_DDD(DUK_DDDPRINT("reused existing constant for %!T -> const index %ld", (duk_tval *) tv1, (long) i)); duk_pop(thr); return (duk_regconst_t) i | (duk_regconst_t) DUK__CONST_MARKER; } @@ -69920,9 +71238,8 @@ DUK_WO_NORETURN(return 0;); } - DUK_DDD(DUK_DDDPRINT("allocating new constant for %!T -> const index %ld", - (duk_tval *) tv1, (long) n)); - (void) duk_put_prop_index(thr, f->consts_idx, (duk_uarridx_t) n); /* invalidates tv1, tv2 */ + DUK_DDD(DUK_DDDPRINT("allocating new constant for %!T -> const index %ld", (duk_tval *) tv1, (long) n)); + (void) duk_put_prop_index(thr, f->consts_idx, (duk_uarridx_t) n); /* invalidates tv1, tv2 */ return (duk_regconst_t) n | (duk_regconst_t) DUK__CONST_MARKER; } @@ -69931,15 +71248,15 @@ duk_compiler_func *f = &comp_ctx->curr_func; duk_bool_t ret; - DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ + DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ (void) duk_get_prop_index(comp_ctx->thr, f->consts_idx, (duk_uarridx_t) rc); - ret = !duk_is_number(comp_ctx->thr, -1); /* now only number/string, so conservative check */ + ret = !duk_is_number(comp_ctx->thr, -1); /* now only number/string, so conservative check */ duk_pop(comp_ctx->thr); return ret; #else DUK_UNREF(comp_ctx); DUK_UNREF(rc); - DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ + DUK_ASSERT((rc & DUK__CONST_MARKER) == 0); /* caller removes const marker */ return 0; #endif } @@ -70002,9 +71319,7 @@ } case DUK_TAG_BOOLEAN: { duk_regconst_t dest = (forced_reg >= 0 ? forced_reg : DUK__ALLOCTEMP(comp_ctx)); - duk__emit_bc(comp_ctx, - (DUK_TVAL_GET_BOOLEAN(tv) ? DUK_OP_LDTRUE : DUK_OP_LDFALSE), - dest); + duk__emit_bc(comp_ctx, (DUK_TVAL_GET_BOOLEAN(tv) ? DUK_OP_LDTRUE : DUK_OP_LDFALSE), dest); return dest; } case DUK_TAG_POINTER: { @@ -70020,7 +71335,7 @@ DUK_UNREF(h); DUK_ASSERT(h != NULL); -#if 0 /* XXX: to be implemented? */ +#if 0 /* XXX: to be implemented? */ /* Use special opcodes to load short strings */ if (DUK_HSTRING_GET_BYTELEN(h) <= 2) { /* Encode into a single opcode (18 bits can encode 1-2 bytes + length indicator) */ @@ -70090,8 +71405,8 @@ return dest; } } - } /* end switch */ - goto fail_internal; /* never here */ + } /* end switch */ + goto fail_internal; /* never here */ } case DUK_ISPEC_REGCONST: { if (forced_reg >= 0) { @@ -70124,11 +71439,11 @@ return x->regconst; } default: { - break; /* never here */ + break; /* never here */ } } - fail_internal: +fail_internal: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return 0;); } @@ -70148,10 +71463,13 @@ DUK_DDD(DUK_DDDPRINT("duk__ivalue_toplain_raw(): x={t=%ld,op=%ld,x1={%ld:%ld:%!T},x2={%ld:%ld:%!T}}, " "forced_reg=%ld", - (long) x->t, (long) x->op, - (long) x->x1.t, (long) x->x1.regconst, + (long) x->t, + (long) x->op, + (long) x->x1.t, + (long) x->x1.regconst, (duk_tval *) duk_get_tval(thr, x->x1.valstack_idx), - (long) x->x2.t, (long) x->x2.regconst, + (long) x->x2.t, + (long) x->x2.regconst, (duk_tval *) duk_get_tval(thr, x->x2.valstack_idx), (long) forced_reg)); @@ -70177,9 +71495,7 @@ DUK_ASSERT(tv1 != NULL); DUK_ASSERT(tv2 != NULL); - DUK_DDD(DUK_DDDPRINT("arith: tv1=%!T, tv2=%!T", - (duk_tval *) tv1, - (duk_tval *) tv2)); + DUK_DDD(DUK_DDDPRINT("arith: tv1=%!T, tv2=%!T", (duk_tval *) tv1, (duk_tval *) tv2)); if (DUK_TVAL_IS_NUMBER(tv1) && DUK_TVAL_IS_NUMBER(tv2)) { duk_double_t d1 = DUK_TVAL_GET_NUMBER(tv1); @@ -70188,7 +71504,9 @@ duk_bool_t accept_fold = 1; DUK_DDD(DUK_DDDPRINT("arith inline check: d1=%lf, d2=%lf, op=%ld", - (double) d1, (double) d2, (long) x->op)); + (double) d1, + (double) d2, + (long) x->op)); switch (x->op) { case DUK_OP_ADD: { d3 = d1 + d2; @@ -70214,7 +71532,7 @@ break; } default: { - d3 = 0.0; /* Won't be used, but silence MSVC /W4 warning. */ + d3 = 0.0; /* Won't be used, but silence MSVC /W4 warning. */ accept_fold = 0; break; } @@ -70228,7 +71546,7 @@ x->t = DUK_IVAL_PLAIN; DUK_ASSERT(x->x1.t == DUK_ISPEC_VALUE); - DUK_TVAL_SET_NUMBER(tv1, d3); /* old value is number: no refcount */ + DUK_TVAL_SET_NUMBER(tv1, d3); /* old value is number: no refcount */ return; } } else if (x->op == DUK_OP_ADD && DUK_TVAL_IS_STRING(tv1) && DUK_TVAL_IS_STRING(tv2)) { @@ -70245,8 +71563,14 @@ } } - arg1 = duk__ispec_toregconst_raw(comp_ctx, &x->x1, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); - arg2 = duk__ispec_toregconst_raw(comp_ctx, &x->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg1 = duk__ispec_toregconst_raw(comp_ctx, + &x->x1, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg2 = duk__ispec_toregconst_raw(comp_ctx, + &x->x2, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); /* If forced reg, use it as destination. Otherwise try to * use either coerced ispec if it is a temporary. @@ -70274,8 +71598,14 @@ duk_regconst_t dest; /* Need a short reg/const, does not have to be a mutable temp. */ - arg1 = duk__ispec_toregconst_raw(comp_ctx, &x->x1, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); - arg2 = duk__ispec_toregconst_raw(comp_ctx, &x->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg1 = duk__ispec_toregconst_raw(comp_ctx, + &x->x1, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); + arg2 = duk__ispec_toregconst_raw(comp_ctx, + &x->x2, + -1, + DUK__IVAL_FLAG_ALLOW_CONST | DUK__IVAL_FLAG_REQUIRE_SHORT /*flags*/); /* Pick a destination register. If either base value or key * happens to be a temp value, reuse it as the destination. @@ -70296,11 +71626,7 @@ dest = DUK__ALLOCTEMP(comp_ctx); } - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, - dest, - arg1, - arg2); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, dest, arg1, arg2); duk__ivalue_regconst(x, dest); return; @@ -70368,10 +71694,13 @@ DUK_DDD(DUK_DDDPRINT("duk__ivalue_toregconst_raw(): x={t=%ld,op=%ld,x1={%ld:%ld:%!T},x2={%ld:%ld:%!T}}, " "forced_reg=%ld, flags 0x%08lx: allow_const=%ld require_temp=%ld require_short=%ld", - (long) x->t, (long) x->op, - (long) x->x1.t, (long) x->x1.regconst, + (long) x->t, + (long) x->op, + (long) x->x1.t, + (long) x->x1.regconst, (duk_tval *) duk_get_tval(thr, x->x1.valstack_idx), - (long) x->x2.t, (long) x->x2.regconst, + (long) x->x2.t, + (long) x->x2.regconst, (duk_tval *) duk_get_tval(thr, x->x2.valstack_idx), (long) forced_reg, (unsigned long) flags, @@ -70394,7 +71723,7 @@ return duk__ivalue_toregconst_raw(comp_ctx, x, -1, 0 /*flags*/); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__ivalue_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *x) { return duk__ivalue_toregconst_raw(comp_ctx, x, -1, DUK__IVAL_FLAG_REQUIRE_TEMP /*flags*/); } @@ -70430,8 +71759,7 @@ duk_hstring *h_varname; duk_regconst_t ret; - DUK_DDD(DUK_DDDPRINT("resolving identifier reference to '%!T'", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("resolving identifier reference to '%!T'", (duk_tval *) duk_get_tval(thr, -1))); /* * Special name handling @@ -70484,13 +71812,13 @@ DUK_DDD(DUK_DDDPRINT("identifier lookup -> reg %ld", (long) ret)); return ret; - slow_path_notown: +slow_path_notown: DUK_DDD(DUK_DDDPRINT("identifier lookup -> slow path, not own variable")); comp_ctx->curr_func.id_access_slow = 1; return (duk_regconst_t) -1; - slow_path_own: +slow_path_own: DUK_DDD(DUK_DDDPRINT("identifier lookup -> slow path, may be own variable")); comp_ctx->curr_func.id_access_slow = 1; @@ -70518,7 +71846,7 @@ if (reg_varbind >= 0) { *out_reg_varbind = reg_varbind; - *out_rc_varname = 0; /* duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller) */ + *out_rc_varname = 0; /* duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller) */ duk_pop(thr); return 1; } else { @@ -70568,7 +71896,7 @@ } duk_push_hstring(thr, h_label); - DUK_ASSERT(n <= DUK_UARRIDX_MAX); /* label limits */ + DUK_ASSERT(n <= DUK_UARRIDX_MAX); /* label limits */ (void) duk_put_prop_index(thr, comp_ctx->curr_func.labelnames_idx, (duk_uarridx_t) n); new_size = (n + 1) * sizeof(duk_labelinfo); @@ -70578,7 +71906,7 @@ /* relookup after possible realloc */ p = (duk_uint8_t *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, comp_ctx->curr_func.h_labelinfos); li_start = (duk_labelinfo *) (void *) p; - DUK_UNREF(li_start); /* silence scan-build warning */ + DUK_UNREF(li_start); /* silence scan-build warning */ li = (duk_labelinfo *) (void *) (p + DUK_HBUFFER_GET_SIZE(comp_ctx->curr_func.h_labelinfos)); li--; @@ -70592,12 +71920,15 @@ li->flags = DUK_LABEL_FLAG_ALLOW_BREAK; li->label_id = label_id; li->h_label = h_label; - li->catch_depth = comp_ctx->curr_func.catch_depth; /* catch depth from current func */ + li->catch_depth = comp_ctx->curr_func.catch_depth; /* catch depth from current func */ li->pc_label = pc_label; DUK_DDD(DUK_DDDPRINT("registered label: flags=0x%08lx, id=%ld, name=%!O, catch_depth=%ld, pc_label=%ld", - (unsigned long) li->flags, (long) li->label_id, (duk_heaphdr *) li->h_label, - (long) li->catch_depth, (long) li->pc_label)); + (unsigned long) li->flags, + (long) li->label_id, + (duk_heaphdr *) li->h_label, + (long) li->catch_depth, + (long) li->pc_label)); } /* Update all labels with matching label_id. */ @@ -70621,7 +71952,9 @@ } DUK_DDD(DUK_DDDPRINT("updating (overwriting) label flags for li=%p, label_id=%ld, flags=%ld", - (void *) li, (long) label_id, (long) flags)); + (void *) li, + (long) label_id, + (long) flags)); li->flags = flags; } @@ -70642,14 +71975,19 @@ */ /* XXX: awkward, especially the bunch of separate output values -> output struct? */ -DUK_LOCAL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, duk_hstring *h_label, duk_bool_t is_break, duk_int_t *out_label_id, duk_int_t *out_label_catch_depth, duk_int_t *out_label_pc, duk_bool_t *out_is_closest) { +DUK_LOCAL void duk__lookup_active_label(duk_compiler_ctx *comp_ctx, + duk_hstring *h_label, + duk_bool_t is_break, + duk_int_t *out_label_id, + duk_int_t *out_label_catch_depth, + duk_int_t *out_label_pc, + duk_bool_t *out_is_closest) { duk_hthread *thr = comp_ctx->thr; duk_uint8_t *p; duk_labelinfo *li_start, *li_end, *li; duk_bool_t match = 0; - DUK_DDD(DUK_DDDPRINT("looking up active label: label='%!O', is_break=%ld", - (duk_heaphdr *) h_label, (long) is_break)); + DUK_DDD(DUK_DDDPRINT("looking up active label: label='%!O', is_break=%ld", (duk_heaphdr *) h_label, (long) is_break)); DUK_UNREF(thr); @@ -70673,7 +72011,8 @@ } DUK_DDD(DUK_DDDPRINT("labelinfo%ld -> '%!O' label name matches (still need to check type)", - (long) (li - li_start), (duk_heaphdr *) h_label)); + (long) (li - li_start), + (duk_heaphdr *) h_label)); /* currently all labels accept a break, so no explicit check for it now */ DUK_ASSERT(li->flags & DUK_LABEL_FLAG_ALLOW_BREAK); @@ -70707,8 +72046,10 @@ } DUK_DDD(DUK_DDDPRINT("label match: %!O -> label_id %ld, catch_depth=%ld, pc_label=%ld", - (duk_heaphdr *) h_label, (long) li->label_id, - (long) li->catch_depth, (long) li->pc_label)); + (duk_heaphdr *) h_label, + (long) li->label_id, + (long) li->catch_depth, + (long) li->pc_label)); *out_label_id = li->label_id; *out_label_catch_depth = li->catch_depth; @@ -70732,21 +72073,21 @@ */ /* object literal key tracking flags */ -#define DUK__OBJ_LIT_KEY_PLAIN (1 << 0) /* key encountered as a plain property */ -#define DUK__OBJ_LIT_KEY_GET (1 << 1) /* key encountered as a getter */ -#define DUK__OBJ_LIT_KEY_SET (1 << 2) /* key encountered as a setter */ +#define DUK__OBJ_LIT_KEY_PLAIN (1 << 0) /* key encountered as a plain property */ +#define DUK__OBJ_LIT_KEY_GET (1 << 1) /* key encountered as a getter */ +#define DUK__OBJ_LIT_KEY_SET (1 << 2) /* key encountered as a setter */ DUK_LOCAL void duk__nud_array_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; - duk_regconst_t reg_obj; /* result reg */ - duk_regconst_t reg_temp; /* temp reg */ - duk_regconst_t temp_start; /* temp reg value for start of loop */ - duk_small_uint_t max_init_values; /* max # of values initialized in one MPUTARR set */ - duk_small_uint_t num_values; /* number of values in current MPUTARR set */ - duk_uarridx_t curr_idx; /* current (next) array index */ - duk_uarridx_t start_idx; /* start array index of current MPUTARR set */ - duk_uarridx_t init_idx; /* last array index explicitly initialized, +1 */ - duk_bool_t require_comma; /* next loop requires a comma */ + duk_regconst_t reg_obj; /* result reg */ + duk_regconst_t reg_temp; /* temp reg */ + duk_regconst_t temp_start; /* temp reg value for start of loop */ + duk_small_uint_t max_init_values; /* max # of values initialized in one MPUTARR set */ + duk_small_uint_t num_values; /* number of values in current MPUTARR set */ + duk_uarridx_t curr_idx; /* current (next) array index */ + duk_uarridx_t start_idx; /* start array index of current MPUTARR set */ + duk_uarridx_t init_idx; /* last array index explicitly initialized, +1 */ + duk_bool_t require_comma; /* next loop requires a comma */ #if !defined(DUK_USE_PREFER_SIZE) duk_int_t pc_newarr; duk_compiler_instr *instr; @@ -70755,13 +72096,13 @@ /* DUK_TOK_LBRACKET already eaten, current token is right after that */ DUK_ASSERT(comp_ctx->prev_token.t == DUK_TOK_LBRACKET); - max_init_values = DUK__MAX_ARRAY_INIT_VALUES; /* XXX: depend on available temps? */ + max_init_values = DUK__MAX_ARRAY_INIT_VALUES; /* XXX: depend on available temps? */ reg_obj = DUK__ALLOCTEMP(comp_ctx); #if !defined(DUK_USE_PREFER_SIZE) pc_newarr = duk__get_current_pc(comp_ctx); #endif - duk__emit_bc(comp_ctx, DUK_OP_NEWARR, reg_obj); /* XXX: patch initial size hint afterwards? */ + duk__emit_bc(comp_ctx, DUK_OP_NEWARR, reg_obj); /* XXX: patch initial size hint afterwards? */ temp_start = DUK__GETTEMP(comp_ctx); /* @@ -70777,7 +72118,7 @@ */ curr_idx = 0; - init_idx = 0; /* tracks maximum initialized index + 1 */ + init_idx = 0; /* tracks maximum initialized index + 1 */ start_idx = 0; require_comma = 0; @@ -70823,7 +72164,7 @@ duk__emit_load_int32(comp_ctx, reg_temp, (duk_int32_t) start_idx); } - reg_temp = DUK__ALLOCTEMP(comp_ctx); /* alloc temp just in case, to update max temp */ + reg_temp = DUK__ALLOCTEMP(comp_ctx); /* alloc temp just in case, to update max temp */ DUK__SETTEMP(comp_ctx, reg_temp); duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); DUK__SETTEMP(comp_ctx, reg_temp + 1); @@ -70848,9 +72189,7 @@ * never needs to be. */ duk__emit_a_b_c(comp_ctx, - DUK_OP_MPUTARR | - DUK__EMIT_FLAG_NO_SHUFFLE_C | - DUK__EMIT_FLAG_A_IS_SOURCE, + DUK_OP_MPUTARR | DUK__EMIT_FLAG_NO_SHUFFLE_C | DUK__EMIT_FLAG_A_IS_SOURCE, reg_obj, temp_start, (duk_regconst_t) (num_values + 1)); @@ -70871,8 +72210,7 @@ DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RBRACKET); duk__advance(comp_ctx); - DUK_DDD(DUK_DDDPRINT("array literal done, curridx=%ld, initidx=%ld", - (long) curr_idx, (long) init_idx)); + DUK_DDD(DUK_DDDPRINT("array literal done, curridx=%ld, initidx=%ld", (long) curr_idx, (long) init_idx)); /* trailing elisions? */ if (curr_idx > init_idx) { @@ -70880,10 +72218,7 @@ DUK_DDD(DUK_DDDPRINT("array literal has trailing elisions which affect its length")); reg_temp = DUK__ALLOCTEMP(comp_ctx); duk__emit_load_int32(comp_ctx, reg_temp, (duk_int_t) curr_idx); - duk__emit_a_bc(comp_ctx, - DUK_OP_SETALEN | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_obj, - reg_temp); + duk__emit_a_bc(comp_ctx, DUK_OP_SETALEN | DUK__EMIT_FLAG_A_IS_SOURCE, reg_obj, reg_temp); } DUK__SETTEMP(comp_ctx, temp_start); @@ -70891,7 +72226,7 @@ duk__ivalue_regconst(res, reg_obj); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_ARRAY_LITERAL); DUK_WO_NORETURN(return;); } @@ -70915,9 +72250,7 @@ */ DUK_ASSERT(st->num_pairs > 0); duk__emit_a_b_c(comp_ctx, - DUK_OP_MPUTOBJ | - DUK__EMIT_FLAG_NO_SHUFFLE_C | - DUK__EMIT_FLAG_A_IS_SOURCE, + DUK_OP_MPUTOBJ | DUK__EMIT_FLAG_NO_SHUFFLE_C | DUK__EMIT_FLAG_A_IS_SOURCE, st->reg_obj, st->temp_start, (duk_regconst_t) (st->num_pairs * 2)); @@ -70936,7 +72269,7 @@ /* numbers can be loaded as numbers and coerced on the fly */ duk_push_number(comp_ctx->thr, tok->num); } else { - return 1; /* error */ + return 1; /* error */ } duk__ivalue_plain_fromstack(comp_ctx, res); @@ -70949,10 +72282,10 @@ DUK_LOCAL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; duk__objlit_state st; - duk_regconst_t reg_temp; /* temp reg */ - duk_small_uint_t max_init_pairs; /* max # of key-value pairs initialized in one MPUTOBJ set */ - duk_bool_t first; /* first value: comma must not precede the value */ - duk_bool_t is_set, is_get; /* temps */ + duk_regconst_t reg_temp; /* temp reg */ + duk_small_uint_t max_init_pairs; /* max # of key-value pairs initialized in one MPUTOBJ set */ + duk_bool_t first; /* first value: comma must not precede the value */ + duk_bool_t is_set, is_get; /* temps */ #if !defined(DUK_USE_PREFER_SIZE) duk_int_t pc_newobj; duk_compiler_instr *instr; @@ -70960,12 +72293,12 @@ DUK_ASSERT(comp_ctx->prev_token.t == DUK_TOK_LCURLY); - max_init_pairs = DUK__MAX_OBJECT_INIT_PAIRS; /* XXX: depend on available temps? */ + max_init_pairs = DUK__MAX_OBJECT_INIT_PAIRS; /* XXX: depend on available temps? */ - st.reg_obj = DUK__ALLOCTEMP(comp_ctx); /* target object */ - st.temp_start = DUK__GETTEMP(comp_ctx); /* start of MPUTOBJ argument list */ - st.num_pairs = 0; /* number of key/value pairs emitted for current MPUTOBJ set */ - st.num_total_pairs = 0; /* number of key/value pairs emitted overall */ + st.reg_obj = DUK__ALLOCTEMP(comp_ctx); /* target object */ + st.temp_start = DUK__GETTEMP(comp_ctx); /* start of MPUTOBJ argument list */ + st.num_pairs = 0; /* number of key/value pairs emitted for current MPUTOBJ set */ + st.num_total_pairs = 0; /* number of key/value pairs emitted overall */ #if !defined(DUK_USE_PREFER_SIZE) pc_newobj = duk__get_current_pc(comp_ctx); @@ -71004,8 +72337,7 @@ * worth the effort and would increase code size. */ - DUK_DDD(DUK_DDDPRINT("object literal loop, curr_token->t = %ld", - (long) comp_ctx->curr_token.t)); + DUK_DDD(DUK_DDDPRINT("object literal loop, curr_token->t = %ld", (long) comp_ctx->curr_token.t)); if (comp_ctx->curr_token.t == DUK_TOK_RCURLY) { break; @@ -71045,16 +72377,15 @@ * identifier string content. */ - is_get = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_GET(thr)); - is_set = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_SET(thr)); + is_get = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_GET(thr)); + is_set = (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->prev_token.str1 == DUK_HTHREAD_STRING_SET(thr)); if ((is_get || is_set) && comp_ctx->curr_token.t != DUK_TOK_COLON) { /* getter/setter */ duk_int_t fnum; duk__objlit_flush_keys(comp_ctx, &st); - DUK_ASSERT(DUK__GETTEMP(comp_ctx) == st.temp_start); /* 2 regs are guaranteed to be allocated w.r.t. temp_max */ + DUK_ASSERT(DUK__GETTEMP(comp_ctx) == + st.temp_start); /* 2 regs are guaranteed to be allocated w.r.t. temp_max */ reg_temp = DUK__ALLOCTEMPS(comp_ctx, 2); if (duk__objlit_load_key(comp_ctx, res, &comp_ctx->curr_token, reg_temp) != 0) { @@ -71064,21 +72395,18 @@ /* curr_token = get/set name */ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_GETSET); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - st.temp_start + 1, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, st.temp_start + 1, (duk_regconst_t) fnum); /* Slot C is used in a non-standard fashion (range of regs), * emitter code has special handling for it (must not set the * "no shuffle" flag). */ duk__emit_a_bc(comp_ctx, - (is_get ? DUK_OP_INITGET : DUK_OP_INITSET) | DUK__EMIT_FLAG_A_IS_SOURCE, - st.reg_obj, - st.temp_start); /* temp_start+0 = key, temp_start+1 = closure */ + (is_get ? DUK_OP_INITGET : DUK_OP_INITSET) | DUK__EMIT_FLAG_A_IS_SOURCE, + st.reg_obj, + st.temp_start); /* temp_start+0 = key, temp_start+1 = closure */ - DUK_ASSERT(st.num_pairs == 0); /* temp state is reset on next loop */ + DUK_ASSERT(st.num_pairs == 0); /* temp state is reset on next loop */ #if defined(DUK_USE_ES6) } else if (comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && (comp_ctx->curr_token.t == DUK_TOK_COMMA || comp_ctx->curr_token.t == DUK_TOK_RCURLY)) { @@ -71086,15 +72414,14 @@ load_rc = duk__objlit_load_key(comp_ctx, res, &comp_ctx->prev_token, reg_temp); DUK_UNREF(load_rc); - DUK_ASSERT(load_rc == 0); /* always succeeds because token is identifier */ + DUK_ASSERT(load_rc == 0); /* always succeeds because token is identifier */ duk__ivalue_var_hstring(comp_ctx, res, comp_ctx->prev_token.str1); DUK_ASSERT(DUK__GETTEMP(comp_ctx) == reg_temp + 1); duk__ivalue_toforcedreg(comp_ctx, res, reg_temp + 1); st.num_pairs++; - } else if ((comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER || - comp_ctx->prev_token.t == DUK_TOK_STRING || + } else if ((comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER || comp_ctx->prev_token.t == DUK_TOK_STRING || comp_ctx->prev_token.t == DUK_TOK_NUMBER) && comp_ctx->curr_token.t == DUK_TOK_LPAREN) { duk_int_t fnum; @@ -71112,13 +72439,10 @@ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_USE_PREVTOKEN | DUK__FUNC_FLAG_METDEF); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp + 1, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp + 1, (duk_regconst_t) fnum); st.num_pairs++; -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ } else { #if defined(DUK_USE_ES6) if (comp_ctx->prev_token.t == DUK_TOK_LBRACKET) { @@ -71135,9 +72459,8 @@ * form is not yet supported and causes a * SyntaxError on the DUK_TOK_COLON check below. */ - } - else -#endif /* DUK_USE_ES6 */ + } else +#endif /* DUK_USE_ES6 */ { if (duk__objlit_load_key(comp_ctx, res, &comp_ctx->prev_token, reg_temp) != 0) { goto syntax_error; @@ -71151,7 +72474,7 @@ st.num_pairs++; } - } /* property loop */ + } /* property loop */ /* Flush remaining properties. */ duk__objlit_flush_keys(comp_ctx, &st); @@ -71170,12 +72493,12 @@ #endif DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RCURLY); - duk__advance(comp_ctx); /* No RegExp after object literal. */ + duk__advance(comp_ctx); /* No RegExp after object literal. */ duk__ivalue_regconst(res, st.reg_obj); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_OBJECT_LITERAL); DUK_WO_NORETURN(return;); } @@ -71191,7 +72514,8 @@ /* Note: expect that caller has already eaten the left paren */ DUK_DDD(DUK_DDDPRINT("start parsing arguments, prev_token.t=%ld, curr_token.t=%ld", - (long) comp_ctx->prev_token.t, (long) comp_ctx->curr_token.t)); + (long) comp_ctx->prev_token.t, + (long) comp_ctx->curr_token.t)); for (;;) { if (comp_ctx->curr_token.t == DUK_TOK_RPAREN) { @@ -71208,11 +72532,14 @@ * This is not the cleanest possible approach. */ - reg_temp = DUK__ALLOCTEMP(comp_ctx); /* bump up "allocated" reg count, just in case */ + reg_temp = DUK__ALLOCTEMP(comp_ctx); /* bump up "allocated" reg count, just in case */ DUK__SETTEMP(comp_ctx, reg_temp); /* binding power must be high enough to NOT allow comma expressions directly */ - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp); /* always allow 'in', coerce to 'tr' just in case */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp); /* always allow 'in', coerce to 'tr' just in case */ DUK__SETTEMP(comp_ctx, reg_temp + 1); nargs++; @@ -71221,7 +72548,7 @@ } /* eat the right paren */ - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ DUK_DDD(DUK_DDDPRINT("end parsing arguments")); @@ -71230,8 +72557,7 @@ DUK_LOCAL duk_bool_t duk__expr_is_empty(duk_compiler_ctx *comp_ctx) { /* empty expressions can be detected conveniently with nud/led counts */ - return (comp_ctx->curr_func.nud_count == 0) && - (comp_ctx->curr_func.led_count == 0); + return (comp_ctx->curr_func.nud_count == 0) && (comp_ctx->curr_func.led_count == 0); } DUK_LOCAL void duk__expr_nud(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { @@ -71239,7 +72565,7 @@ duk_token *tk; duk_regconst_t temp_at_entry; duk_small_uint_t tok; - duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ + duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ /* * ctx->prev_token token to process with duk__expr_nud() @@ -71257,18 +72583,17 @@ res->t = DUK_IVAL_NONE; DUK_DDD(DUK_DDDPRINT("duk__expr_nud(), prev_token.t=%ld, allow_in=%ld, paren_level=%ld", - (long) tk->t, (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); + (long) tk->t, + (long) comp_ctx->curr_func.allow_in, + (long) comp_ctx->curr_func.paren_level)); switch (tok) { - - /* PRIMARY EXPRESSIONS */ + /* PRIMARY EXPRESSIONS */ case DUK_TOK_THIS: { duk_regconst_t reg_temp; reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_bc(comp_ctx, - DUK_OP_LDTHIS, - reg_temp); + duk__emit_bc(comp_ctx, DUK_OP_LDTHIS, reg_temp); duk__ivalue_regconst(res, reg_temp); return; } @@ -71300,15 +72625,13 @@ case DUK_TOK_REGEXP: { #if defined(DUK_USE_REGEXP_SUPPORT) duk_regconst_t reg_temp; - duk_regconst_t rc_re_bytecode; /* const */ - duk_regconst_t rc_re_source; /* const */ + duk_regconst_t rc_re_bytecode; /* const */ + duk_regconst_t rc_re_source; /* const */ DUK_ASSERT(tk->str1 != NULL); DUK_ASSERT(tk->str2 != NULL); - DUK_DDD(DUK_DDDPRINT("emitting regexp op, str1=%!O, str2=%!O", - (duk_heaphdr *) tk->str1, - (duk_heaphdr *) tk->str2)); + DUK_DDD(DUK_DDDPRINT("emitting regexp op, str1=%!O, str2=%!O", (duk_heaphdr *) tk->str1, (duk_heaphdr *) tk->str2)); reg_temp = DUK__ALLOCTEMP(comp_ctx); duk_push_hstring(thr, tk->str1); @@ -71331,9 +72654,9 @@ duk__ivalue_regconst(res, reg_temp); return; -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ goto syntax_error; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } case DUK_TOK_LBRACKET: { DUK_DDD(DUK_DDDPRINT("parsing array literal")); @@ -71352,15 +72675,15 @@ prev_allow_in = comp_ctx->curr_func.allow_in; comp_ctx->curr_func.allow_in = 1; /* reset 'allow_in' for parenthesized expression */ - duk__expr(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, terminates at a ')' */ + duk__expr(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, terminates at a ')' */ - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* No RegExp after parenthesized expression. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* No RegExp after parenthesized expression. */ comp_ctx->curr_func.allow_in = prev_allow_in; comp_ctx->curr_func.paren_level--; return; } - /* MEMBER/NEW/CALL EXPRESSIONS */ + /* MEMBER/NEW/CALL EXPRESSIONS */ case DUK_TOK_NEW: { /* @@ -71397,16 +72720,14 @@ goto syntax_error_newtarget; } duk__advance(comp_ctx); - duk__emit_bc(comp_ctx, - DUK_OP_NEWTARGET, - reg_target); + duk__emit_bc(comp_ctx, DUK_OP_NEWTARGET, reg_target); duk__ivalue_regconst(res, reg_target); return; } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ duk__expr_toforcedreg(comp_ctx, res, DUK__BP_CALL /*rbp_flags*/, reg_target /*forced_reg*/); - duk__emit_bc(comp_ctx, DUK_OP_NEWOBJ, reg_target + 1); /* default instance */ + duk__emit_bc(comp_ctx, DUK_OP_NEWOBJ, reg_target + 1); /* default instance */ DUK__SETTEMP(comp_ctx, reg_target + 2); /* XXX: 'new obj.noSuch()' doesn't use GETPROPC now which @@ -71417,7 +72738,7 @@ /* 'new' MemberExpression Arguments */ DUK_DDD(DUK_DDDPRINT("new expression has argument list")); duk__advance(comp_ctx); - nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp", reg_target + 1 */ + nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp", reg_target + 1 */ /* right paren eaten */ } else { /* 'new' MemberExpression */ @@ -71425,10 +72746,7 @@ nargs = 0; } - duk__emit_a_bc(comp_ctx, - DUK_OP_CALL0 | DUK_BC_CALL_FLAG_CONSTRUCT, - nargs /*num_args*/, - reg_target /*target*/); + duk__emit_a_bc(comp_ctx, DUK_OP_CALL0 | DUK_BC_CALL_FLAG_CONSTRUCT, nargs /*num_args*/, reg_target /*target*/); DUK_DDD(DUK_DDDPRINT("end parsing new expression")); @@ -71436,7 +72754,7 @@ return; } - /* FUNCTION EXPRESSIONS */ + /* FUNCTION EXPRESSIONS */ case DUK_TOK_FUNCTION: { /* Function expression. Note that any statement beginning with 'function' @@ -71459,16 +72777,13 @@ fnum = duk__parse_func_like_fnum(comp_ctx, 0 /*flags*/); DUK_DDD(DUK_DDDPRINT("parsed inner function -> fnum %ld", (long) fnum)); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp /*a*/, - (duk_regconst_t) fnum /*bc*/); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp /*a*/, (duk_regconst_t) fnum /*bc*/); duk__ivalue_regconst(res, reg_temp); return; } - /* UNARY EXPRESSIONS */ + /* UNARY EXPRESSIONS */ case DUK_TOK_DELETE: { /* Delete semantics are a bit tricky. The description in E5 specification @@ -71476,7 +72791,7 @@ * a reference (which is only known at runtime) seemingly at compile time * (= SyntaxError throwing). */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_VAR) { /* not allowed in strict mode, regardless of whether resolves; * in non-strict mode DELVAR handles both non-resolving and @@ -71498,16 +72813,11 @@ duk_dup(thr, res->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { /* register bound variables are non-configurable -> always false */ - duk__emit_bc(comp_ctx, - DUK_OP_LDFALSE, - reg_temp); + duk__emit_bc(comp_ctx, DUK_OP_LDFALSE, reg_temp); } else { duk_dup(thr, res->x1.valstack_idx); rc_varname = duk__getconst(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_DELVAR, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_DELVAR, reg_temp, rc_varname); } duk__ivalue_regconst(res, reg_temp); } else if (res->t == DUK_IVAL_PROP) { @@ -71517,13 +72827,11 @@ DUK__SETTEMP(comp_ctx, temp_at_entry); reg_temp = DUK__ALLOCTEMP(comp_ctx); - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - DUK_OP_DELPROP | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - reg_obj, - rc_key); + reg_obj = + duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = + duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, DUK_OP_DELPROP | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, reg_obj, rc_key); duk__ivalue_regconst(res, reg_temp); } else { @@ -71534,7 +72842,7 @@ return; } case DUK_TOK_VOID: { - duk__expr_toplain_ignore(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr_toplain_ignore(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ duk_push_undefined(thr); goto plain_value; } @@ -71544,7 +72852,7 @@ * will never be unresolvable so special handling is only required * when an identifier is a "slow path" one. */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_VAR) { duk_regconst_t reg_varbind; @@ -71556,10 +72864,7 @@ DUK_DDD(DUK_DDDPRINT("typeof for an identifier name which could not be resolved " "at compile time, need to use special run-time handling")); reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_TYPEOFID, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_TYPEOFID, reg_temp, rc_varname); duk__ivalue_regconst(res, reg_temp); return; } @@ -71578,9 +72883,8 @@ } case DUK_TOK_ADD: { /* unary plus */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && - duk_is_number(thr, res->x1.valstack_idx)) { + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && duk_is_number(thr, res->x1.valstack_idx)) { /* unary plus of a number is identity */ return; } @@ -71589,9 +72893,8 @@ } case DUK_TOK_SUB: { /* unary minus */ - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && - duk_is_number(thr, res->x1.valstack_idx)) { + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE && duk_is_number(thr, res->x1.valstack_idx)) { /* this optimization is important to handle negative literals * (which are not directly provided by the lexical grammar) */ @@ -71611,12 +72914,12 @@ goto unary; } case DUK_TOK_BNOT: { - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ args = DUK_OP_BNOT; goto unary; } case DUK_TOK_LNOT: { - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ if (res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_VALUE) { /* Very minimal inlining to handle common idioms '!0' and '!1', * and also boolean arguments like '!false' and '!true'. @@ -71651,117 +72954,110 @@ goto unary; } - } /* end switch */ + } /* end switch */ DUK_ERROR_SYNTAX(thr, DUK_STR_PARSE_ERROR); DUK_WO_NORETURN(return;); - unary: - { - /* Unary opcodes use just the 'BC' register source because it - * matches current shuffle limits, and maps cleanly to 16 high - * bits of the opcode. - */ - - duk_regconst_t reg_src, reg_res; - - reg_src = duk__ivalue_toregconst_raw(comp_ctx, res, -1 /*forced_reg*/, 0 /*flags*/); - if (DUK__ISREG_TEMP(comp_ctx, reg_src)) { - reg_res = reg_src; - } else { - reg_res = DUK__ALLOCTEMP(comp_ctx); - } - duk__emit_a_bc(comp_ctx, - args, - reg_res, - reg_src); - duk__ivalue_regconst(res, reg_res); - return; - } +unary : { + /* Unary opcodes use just the 'BC' register source because it + * matches current shuffle limits, and maps cleanly to 16 high + * bits of the opcode. + */ - preincdec: - { - /* preincrement and predecrement */ - duk_regconst_t reg_res; - duk_small_uint_t args_op1 = args & 0xff; /* DUK_OP_PREINCR/DUK_OP_PREDECR */ - duk_small_uint_t args_op2 = args >> 8; /* DUK_OP_PREINCP_RR/DUK_OP_PREDECP_RR */ - - /* Specific assumptions for opcode numbering. */ - DUK_ASSERT(DUK_OP_PREINCR + 4 == DUK_OP_PREINCV); - DUK_ASSERT(DUK_OP_PREDECR + 4 == DUK_OP_PREDECV); + duk_regconst_t reg_src, reg_res; + reg_src = duk__ivalue_toregconst_raw(comp_ctx, res, -1 /*forced_reg*/, 0 /*flags*/); + if (DUK__ISREG_TEMP(comp_ctx, reg_src)) { + reg_res = reg_src; + } else { reg_res = DUK__ALLOCTEMP(comp_ctx); + } + duk__emit_a_bc(comp_ctx, args, reg_res, reg_src); + duk__ivalue_regconst(res, reg_res); + return; +} - duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ - if (res->t == DUK_IVAL_VAR) { - duk_hstring *h_varname; - duk_regconst_t reg_varbind; - duk_regconst_t rc_varname; - - h_varname = duk_known_hstring(thr, res->x1.valstack_idx); +preincdec : { + /* preincrement and predecrement */ + duk_regconst_t reg_res; + duk_small_uint_t args_op1 = args & 0xff; /* DUK_OP_PREINCR/DUK_OP_PREDECR */ + duk_small_uint_t args_op2 = args >> 8; /* DUK_OP_PREINCP_RR/DUK_OP_PREDECP_RR */ + + /* Specific assumptions for opcode numbering. */ + DUK_ASSERT(DUK_OP_PREINCR + 4 == DUK_OP_PREINCV); + DUK_ASSERT(DUK_OP_PREDECR + 4 == DUK_OP_PREDECV); + + reg_res = DUK__ALLOCTEMP(comp_ctx); + + duk__expr(comp_ctx, res, DUK__BP_MULTIPLICATIVE /*rbp_flags*/); /* UnaryExpression */ + if (res->t == DUK_IVAL_VAR) { + duk_hstring *h_varname; + duk_regconst_t reg_varbind; + duk_regconst_t rc_varname; - if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { - goto syntax_error; - } + h_varname = duk_known_hstring(thr, res->x1.valstack_idx); - duk_dup(thr, res->x1.valstack_idx); - if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - args_op1, /* e.g. DUK_OP_PREINCR */ - reg_res, - reg_varbind); - } else { - duk__emit_a_bc(comp_ctx, - args_op1 + 4, /* e.g. DUK_OP_PREINCV */ - reg_res, - rc_varname); - } + if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { + goto syntax_error; + } - DUK_DDD(DUK_DDDPRINT("preincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); - } else if (res->t == DUK_IVAL_PROP) { - duk_regconst_t reg_obj; /* allocate to reg only (not const) */ - duk_regconst_t rc_key; - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_PREINCP */ - reg_res, - reg_obj, - rc_key); + duk_dup(thr, res->x1.valstack_idx); + if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { + duk__emit_a_bc(comp_ctx, + args_op1, /* e.g. DUK_OP_PREINCR */ + reg_res, + reg_varbind); } else { - /* Technically return value is not needed because INVLHS will - * unconditially throw a ReferenceError. Coercion is necessary - * for proper semantics (consider ToNumber() called for an object). - * Use DUK_OP_UNP with a dummy register to get ToNumber(). - */ - - duk__ivalue_toforcedreg(comp_ctx, res, reg_res); - duk__emit_bc(comp_ctx, - DUK_OP_UNP, - reg_res); /* for side effects, result ignored */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__emit_a_bc(comp_ctx, + args_op1 + 4, /* e.g. DUK_OP_PREINCV */ + reg_res, + rc_varname); } - DUK__SETTEMP(comp_ctx, reg_res + 1); - duk__ivalue_regconst(res, reg_res); - return; - } - plain_value: - { - /* Stack top contains plain value */ - duk__ivalue_plain_fromstack(comp_ctx, res); - return; + DUK_DDD(DUK_DDDPRINT("preincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); + } else if (res->t == DUK_IVAL_PROP) { + duk_regconst_t reg_obj; /* allocate to reg only (not const) */ + duk_regconst_t rc_key; + reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, + args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_PREINCP */ + reg_res, + reg_obj, + rc_key); + } else { + /* Technically return value is not needed because INVLHS will + * unconditially throw a ReferenceError. Coercion is necessary + * for proper semantics (consider ToNumber() called for an object). + * Use DUK_OP_UNP with a dummy register to get ToNumber(). + */ + + duk__ivalue_toforcedreg(comp_ctx, res, reg_res); + duk__emit_bc(comp_ctx, DUK_OP_UNP, reg_res); /* for side effects, result ignored */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } + DUK__SETTEMP(comp_ctx, reg_res + 1); + duk__ivalue_regconst(res, reg_res); + return; +} + +plain_value : { + /* Stack top contains plain value */ + duk__ivalue_plain_fromstack(comp_ctx, res); + return; +} #if defined(DUK_USE_ES6) - syntax_error_newtarget: +syntax_error_newtarget: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_NEWTARGET); DUK_WO_NORETURN(return;); #endif - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_EXPRESSION); DUK_WO_NORETURN(return;); } @@ -71774,7 +73070,7 @@ duk_hthread *thr = comp_ctx->thr; duk_token *tk; duk_small_uint_t tok; - duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ + duk_uint32_t args; /* temp variable to pass constants and flags to shared code */ /* * ctx->prev_token token to process with duk__expr_led() @@ -71788,13 +73084,14 @@ tok = tk->t; DUK_DDD(DUK_DDDPRINT("duk__expr_led(), prev_token.t=%ld, allow_in=%ld, paren_level=%ld", - (long) tk->t, (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); + (long) tk->t, + (long) comp_ctx->curr_func.allow_in, + (long) comp_ctx->curr_func.paren_level)); /* XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here? */ switch (tok) { - - /* PRIMARY EXPRESSIONS */ + /* PRIMARY EXPRESSIONS */ case DUK_TOK_PERIOD: { /* Property access expressions are critical for correct LHS ordering, @@ -71822,7 +73119,7 @@ } res->t = DUK_IVAL_PROP; - duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ + duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); duk_push_hstring(thr, comp_ctx->curr_token.str1); duk_replace(thr, res->x2.valstack_idx); @@ -71857,12 +73154,12 @@ * See: test-bug-nested-prop-mutate.js. */ duk__ivalue_totempconst(comp_ctx, left); - duk__expr_toplain(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, '' terminates */ + duk__expr_toplain(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression, '' terminates */ duk__advance_expect(comp_ctx, DUK_TOK_RBRACKET); res->t = DUK_IVAL_PROP; - duk__copy_ispec(comp_ctx, &res->x1, &res->x2); /* res.x1 -> res.x2 */ - duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ + duk__copy_ispec(comp_ctx, &res->x1, &res->x2); /* res.x1 -> res.x2 */ + duk__copy_ispec(comp_ctx, &left->x1, &res->x1); /* left.x1 -> res.x1 */ return; } case DUK_TOK_LPAREN: { @@ -71906,19 +73203,13 @@ duk_dup(thr, left->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - DUK_OP_CSREG | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_varbind, - reg_cs + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_CSREG | DUK__EMIT_FLAG_A_IS_SOURCE, reg_varbind, reg_cs + 0); } else { /* XXX: expand target register or constant field to * reduce shuffling. */ DUK_ASSERT(DUK__ISCONST(rc_varname)); - duk__emit_a_b(comp_ctx, - DUK_OP_CSVAR | DUK__EMIT_FLAG_BC_REGCONST, - reg_cs + 0, - rc_varname); + duk__emit_a_b(comp_ctx, DUK_OP_CSVAR | DUK__EMIT_FLAG_BC_REGCONST, reg_cs + 0, rc_varname); } } else if (left->t == DUK_IVAL_PROP) { /* Call through a property lookup, E5 Section 11.2.3, step 6.a.i, @@ -71940,16 +73231,12 @@ * and reuse, but it would still be in the wrong position * (reg_cs + 0 rather than reg_cs + 1). */ - duk__ispec_toforcedreg(comp_ctx, &left->x1, reg_cs + 1); /* base */ + duk__ispec_toforcedreg(comp_ctx, &left->x1, reg_cs + 1); /* base */ #if defined(DUK_USE_VERBOSE_ERRORS) reg_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROPC | DUK__EMIT_FLAG_BC_REGCONST, - reg_cs + 0, - reg_cs + 1, - reg_key); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROPC | DUK__EMIT_FLAG_BC_REGCONST, reg_cs + 0, reg_cs + 1, reg_key); #else - duk__ivalue_toforcedreg(comp_ctx, left, reg_cs + 0); /* basekey */ + duk__ivalue_toforcedreg(comp_ctx, left, reg_cs + 0); /* basekey */ #endif } else { DUK_DDD(DUK_DDDPRINT("function call with register base")); @@ -71968,23 +73255,20 @@ } DUK__SETTEMP(comp_ctx, reg_cs + 2); - nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp" */ + nargs = duk__parse_arguments(comp_ctx, res); /* parse args starting from "next temp" */ /* Tailcalls are handled by back-patching the already emitted opcode * later in return statement parser. */ - duk__emit_a_bc(comp_ctx, - call_op, - (duk_regconst_t) nargs /*numargs*/, - reg_cs /*basereg*/); - DUK__SETTEMP(comp_ctx, reg_cs + 1); /* result in csreg */ + duk__emit_a_bc(comp_ctx, call_op, (duk_regconst_t) nargs /*numargs*/, reg_cs /*basereg*/); + DUK__SETTEMP(comp_ctx, reg_cs + 1); /* result in csreg */ duk__ivalue_regconst(res, reg_cs); return; } - /* POSTFIX EXPRESSION */ + /* POSTFIX EXPRESSION */ case DUK_TOK_INCREMENT: { args = (DUK_OP_POSTINCP_RR << 16) + (DUK_OP_POSTINCR << 8) + 0; @@ -71999,38 +73283,38 @@ #if defined(DUK_USE_ES7_EXP_OPERATOR) case DUK_TOK_EXP: { - args = (DUK_OP_EXP << 8) + DUK__BP_EXPONENTIATION - 1; /* UnaryExpression */ + args = (DUK_OP_EXP << 8) + DUK__BP_EXPONENTIATION - 1; /* UnaryExpression */ goto binary; } #endif - /* MULTIPLICATIVE EXPRESSION */ + /* MULTIPLICATIVE EXPRESSION */ case DUK_TOK_MUL: { - args = (DUK_OP_MUL << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_MUL << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } case DUK_TOK_DIV: { - args = (DUK_OP_DIV << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_DIV << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } case DUK_TOK_MOD: { - args = (DUK_OP_MOD << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ + args = (DUK_OP_MOD << 8) + DUK__BP_MULTIPLICATIVE; /* ExponentiationExpression */ goto binary; } - /* ADDITIVE EXPRESSION */ + /* ADDITIVE EXPRESSION */ case DUK_TOK_ADD: { - args = (DUK_OP_ADD << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ + args = (DUK_OP_ADD << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ goto binary; } case DUK_TOK_SUB: { - args = (DUK_OP_SUB << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ + args = (DUK_OP_SUB << 8) + DUK__BP_ADDITIVE; /* MultiplicativeExpression */ goto binary; } - /* SHIFT EXPRESSION */ + /* SHIFT EXPRESSION */ case DUK_TOK_ALSHIFT: { /* << */ @@ -72048,7 +73332,7 @@ goto binary; } - /* RELATIONAL EXPRESSION */ + /* RELATIONAL EXPRESSION */ case DUK_TOK_LT: { /* < */ @@ -72076,7 +73360,7 @@ goto binary; } - /* EQUALITY EXPRESSION */ + /* EQUALITY EXPRESSION */ case DUK_TOK_EQ: { args = (DUK_OP_EQ << 8) + DUK__BP_EQUALITY; @@ -72095,7 +73379,7 @@ goto binary; } - /* BITWISE EXPRESSIONS */ + /* BITWISE EXPRESSIONS */ case DUK_TOK_BAND: { args = (DUK_OP_BAND << 8) + DUK__BP_BAND; @@ -72110,7 +73394,7 @@ goto binary; } - /* LOGICAL EXPRESSIONS */ + /* LOGICAL EXPRESSIONS */ case DUK_TOK_LAND: { /* syntactically left-associative but parsed as right-associative */ @@ -72123,7 +73407,7 @@ goto binary_logical; } - /* CONDITIONAL EXPRESSION */ + /* CONDITIONAL EXPRESSION */ case DUK_TOK_QUESTION: { /* XXX: common reg allocation need is to reuse a sub-expression's temp reg, @@ -72136,12 +73420,18 @@ reg_temp = DUK__ALLOCTEMP(comp_ctx); duk__ivalue_toforcedreg(comp_ctx, left, reg_temp); duk__emit_if_true_skip(comp_ctx, reg_temp); - pc_jump1 = duk__emit_jump_empty(comp_ctx); /* jump to false */ - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); /* AssignmentExpression */ + pc_jump1 = duk__emit_jump_empty(comp_ctx); /* jump to false */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp /*forced_reg*/); /* AssignmentExpression */ duk__advance_expect(comp_ctx, DUK_TOK_COLON); - pc_jump2 = duk__emit_jump_empty(comp_ctx); /* jump to end */ + pc_jump2 = duk__emit_jump_empty(comp_ctx); /* jump to end */ duk__patch_jump_here(comp_ctx, pc_jump1); - duk__expr_toforcedreg(comp_ctx, res, DUK__BP_COMMA /*rbp_flags*/, reg_temp /*forced_reg*/); /* AssignmentExpression */ + duk__expr_toforcedreg(comp_ctx, + res, + DUK__BP_COMMA /*rbp_flags*/, + reg_temp /*forced_reg*/); /* AssignmentExpression */ duk__patch_jump_here(comp_ctx, pc_jump2); DUK__SETTEMP(comp_ctx, reg_temp + 1); @@ -72149,7 +73439,7 @@ return; } - /* ASSIGNMENT EXPRESSION */ + /* ASSIGNMENT EXPRESSION */ case DUK_TOK_EQUALSIGN: { /* @@ -72163,7 +73453,7 @@ * * XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)? */ - args = (DUK_OP_NONE << 8) + DUK__BP_ASSIGNMENT - 1; /* DUK_OP_NONE marks a 'plain' assignment */ + args = (DUK_OP_NONE << 8) + DUK__BP_ASSIGNMENT - 1; /* DUK_OP_NONE marks a 'plain' assignment */ goto assign; } case DUK_TOK_ADD_EQ: { @@ -72229,12 +73519,12 @@ goto assign; } - /* COMMA */ + /* COMMA */ case DUK_TOK_COMMA: { /* right associative */ - duk__ivalue_toplain_ignore(comp_ctx, left); /* need side effects, not value */ + duk__ivalue_toplain_ignore(comp_ctx, left); /* need side effects, not value */ duk__expr_toplain(comp_ctx, res, DUK__BP_COMMA - 1 /*rbp_flags*/); /* return 'res' (of right part) as our result */ @@ -72257,7 +73547,7 @@ } #endif - binary: +binary: /* * Shared handling of binary operations * @@ -72283,11 +73573,15 @@ duk_copy(thr, left->x1.valstack_idx, res->x1.valstack_idx); DUK_DDD(DUK_DDDPRINT("binary op, res: t=%ld, x1.t=%ld, x1.regconst=0x%08lx, x2.t=%ld, x2.regconst=0x%08lx", - (long) res->t, (long) res->x1.t, (unsigned long) res->x1.regconst, (long) res->x2.t, (unsigned long) res->x2.regconst)); + (long) res->t, + (long) res->x1.t, + (unsigned long) res->x1.regconst, + (long) res->x2.t, + (unsigned long) res->x2.regconst)); return; } - binary_logical: +binary_logical: /* * Shared handling for logical AND and logical OR. * @@ -72320,8 +73614,8 @@ duk__ivalue_toforcedreg(comp_ctx, left, reg_temp); DUK_ASSERT(DUK__ISREG(reg_temp)); duk__emit_bc(comp_ctx, - (args_truthval ? DUK_OP_IFTRUE_R : DUK_OP_IFFALSE_R), - reg_temp); /* skip jump conditionally */ + (args_truthval ? DUK_OP_IFTRUE_R : DUK_OP_IFFALSE_R), + reg_temp); /* skip jump conditionally */ pc_jump = duk__emit_jump_empty(comp_ctx); duk__expr_toforcedreg(comp_ctx, res, args_rbp /*rbp_flags*/, reg_temp /*forced_reg*/); duk__patch_jump_here(comp_ctx, pc_jump); @@ -72330,7 +73624,7 @@ return; } - assign: +assign: /* * Shared assignment expression handling * @@ -72383,7 +73677,7 @@ * is relevant for e.g. eval code. */ toplevel_assign = (comp_ctx->curr_func.nud_count == 1 && /* one token before */ - comp_ctx->curr_func.led_count == 1); /* one operator (= assign) */ + comp_ctx->curr_func.led_count == 1); /* one operator (= assign) */ DUK_DDD(DUK_DDDPRINT("assignment: nud_count=%ld, led_count=%ld, toplevel_assign=%ld", (long) comp_ctx->curr_func.nud_count, (long) comp_ctx->curr_func.led_count, @@ -72394,7 +73688,7 @@ duk_regconst_t reg_varbind; duk_regconst_t rc_varname; - DUK_ASSERT(left->x1.t == DUK_ISPEC_VALUE); /* LHS is already side effect free */ + DUK_ASSERT(left->x1.t == DUK_ISPEC_VALUE); /* LHS is already side effect free */ h_varname = duk_known_hstring(thr, left->x1.valstack_idx); if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { @@ -72411,9 +73705,10 @@ DUK_DDD(DUK_DDDPRINT("plain assignment, toplevel assign, use as is")); } else { /* 'res' must be a plain ivalue, and not register-bound variable. */ - DUK_DDD(DUK_DDDPRINT("plain assignment, not toplevel assign, ensure not a reg-bound identifier")); - if (res->t != DUK_IVAL_PLAIN || (res->x1.t == DUK_ISPEC_REGCONST && - DUK__ISREG_NOTTEMP(comp_ctx, res->x1.regconst))) { + DUK_DDD(DUK_DDDPRINT( + "plain assignment, not toplevel assign, ensure not a reg-bound identifier")); + if (res->t != DUK_IVAL_PLAIN || + (res->x1.t == DUK_ISPEC_REGCONST && DUK__ISREG_NOTTEMP(comp_ctx, res->x1.regconst))) { duk__ivalue_totempconst(comp_ctx, res); } } @@ -72446,7 +73741,7 @@ * value, so go through a temp. */ DUK_DD(DUK_DDPRINT("<op>= expression is not top level, write to reg_temp")); - reg_res = reg_temp; /* reg_res should be smallest possible */ + reg_res = reg_temp; /* reg_res should be smallest possible */ reg_temp = DUK__ALLOCTEMP(comp_ctx); } @@ -72458,10 +73753,7 @@ */ pc_temp_load = duk__get_current_pc(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_temp, - reg_varbind); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_temp, reg_varbind); pc_before_rhs = duk__get_current_pc(comp_ctx); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); @@ -72469,7 +73761,8 @@ pc_after_rhs = duk__get_current_pc(comp_ctx); DUK_DD(DUK_DDPRINT("pc_temp_load=%ld, pc_before_rhs=%ld, pc_after_rhs=%ld", - (long) pc_temp_load, (long) pc_before_rhs, + (long) pc_temp_load, + (long) pc_before_rhs, (long) pc_after_rhs)); if (pc_after_rhs == pc_before_rhs) { @@ -72477,11 +73770,16 @@ * instructions, we may need to rewind more than * one instruction, so use explicit PC computation. */ - DUK_DD(DUK_DDPRINT("rhs is side effect free, rewind and avoid unnecessary temp for reg-based <op>=")); - DUK_BW_ADD_PTR(comp_ctx->thr, &comp_ctx->curr_func.bw_code, (pc_temp_load - pc_before_rhs) * (duk_int_t) sizeof(duk_compiler_instr)); + DUK_DD(DUK_DDPRINT("rhs is side effect free, rewind and avoid unnecessary temp for " + "reg-based <op>=")); + DUK_BW_ADD_PTR(comp_ctx->thr, + &comp_ctx->curr_func.bw_code, + (pc_temp_load - pc_before_rhs) * + (duk_int_t) sizeof(duk_compiler_instr)); reg_src = reg_varbind; } else { - DUK_DD(DUK_DDPRINT("rhs evaluation emitted code, not sure if rhs is side effect free; use temp reg for LHS")); + DUK_DD(DUK_DDPRINT("rhs evaluation emitted code, not sure if rhs is side effect " + "free; use temp reg for LHS")); reg_src = reg_temp; } @@ -72502,10 +73800,7 @@ * temporary. No optimization for top level assignment. */ - duk__emit_a_bc(comp_ctx, - DUK_OP_GETVAR, - reg_temp, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_GETVAR, reg_temp, rc_varname); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); DUK_ASSERT(res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_REGCONST); @@ -72538,7 +73833,7 @@ duk__ivalue_toforcedreg(comp_ctx, res, (duk_int_t) reg_varbind); } else { duk__ivalue_totempconst(comp_ctx, res); - duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ + duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ duk__ivalue_toforcedreg(comp_ctx, left, (duk_int_t) reg_varbind); } } else { @@ -72546,7 +73841,7 @@ * free and may be a plain value, a register, or a * constant) and write it to the LHS binding too. */ - duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ + duk__copy_ivalue(comp_ctx, res, left); /* use 'left' as a temp */ duk__ivalue_toforcedreg(comp_ctx, left, (duk_int_t) reg_varbind); } } else { @@ -72559,10 +73854,7 @@ */ duk__ivalue_toreg(comp_ctx, res); - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - res->x1.regconst, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, res->x1.regconst, rc_varname); } /* 'res' contains expression value */ @@ -72602,11 +73894,7 @@ rc_res = res->x1.regconst; } else { reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_b_c(comp_ctx, - DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - reg_obj, - rc_key); + duk__emit_a_b_c(comp_ctx, DUK_OP_GETPROP | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, reg_obj, rc_key); duk__expr_toregconst(comp_ctx, res, args_rbp /*rbp_flags*/); DUK_ASSERT(res->t == DUK_IVAL_PLAIN && res->x1.t == DUK_ISPEC_REGCONST); @@ -72657,90 +73945,88 @@ return; } - postincdec: - { - /* - * Post-increment/decrement will return the original value as its - * result value. However, even that value will be coerced using - * ToNumber() which is quite awkward. Specific bytecode opcodes - * are used to handle these semantics. - * - * Note that post increment/decrement has a "no LineTerminator here" - * restriction. This is handled by duk__expr_lbp(), which forcibly terminates - * the previous expression if a LineTerminator occurs before '++'/'--'. - */ - - duk_regconst_t reg_res; - duk_small_uint_t args_op1 = (args >> 8) & 0xff; /* DUK_OP_POSTINCR/DUK_OP_POSTDECR */ - duk_small_uint_t args_op2 = args >> 16; /* DUK_OP_POSTINCP_RR/DUK_OP_POSTDECP_RR */ - - /* Specific assumptions for opcode numbering. */ - DUK_ASSERT(DUK_OP_POSTINCR + 4 == DUK_OP_POSTINCV); - DUK_ASSERT(DUK_OP_POSTDECR + 4 == DUK_OP_POSTDECV); +postincdec : { + /* + * Post-increment/decrement will return the original value as its + * result value. However, even that value will be coerced using + * ToNumber() which is quite awkward. Specific bytecode opcodes + * are used to handle these semantics. + * + * Note that post increment/decrement has a "no LineTerminator here" + * restriction. This is handled by duk__expr_lbp(), which forcibly terminates + * the previous expression if a LineTerminator occurs before '++'/'--'. + */ - reg_res = DUK__ALLOCTEMP(comp_ctx); + duk_regconst_t reg_res; + duk_small_uint_t args_op1 = (args >> 8) & 0xff; /* DUK_OP_POSTINCR/DUK_OP_POSTDECR */ + duk_small_uint_t args_op2 = args >> 16; /* DUK_OP_POSTINCP_RR/DUK_OP_POSTDECP_RR */ - if (left->t == DUK_IVAL_VAR) { - duk_hstring *h_varname; - duk_regconst_t reg_varbind; - duk_regconst_t rc_varname; + /* Specific assumptions for opcode numbering. */ + DUK_ASSERT(DUK_OP_POSTINCR + 4 == DUK_OP_POSTINCV); + DUK_ASSERT(DUK_OP_POSTDECR + 4 == DUK_OP_POSTDECV); - h_varname = duk_known_hstring(thr, left->x1.valstack_idx); + reg_res = DUK__ALLOCTEMP(comp_ctx); - if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { - goto syntax_error; - } + if (left->t == DUK_IVAL_VAR) { + duk_hstring *h_varname; + duk_regconst_t reg_varbind; + duk_regconst_t rc_varname; - duk_dup(thr, left->x1.valstack_idx); - if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - args_op1, /* e.g. DUK_OP_POSTINCR */ - reg_res, - reg_varbind); - } else { - duk__emit_a_bc(comp_ctx, - args_op1 + 4, /* e.g. DUK_OP_POSTINCV */ - reg_res, - rc_varname); - } + h_varname = duk_known_hstring(thr, left->x1.valstack_idx); - DUK_DDD(DUK_DDDPRINT("postincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); - } else if (left->t == DUK_IVAL_PROP) { - duk_regconst_t reg_obj; /* allocate to reg only (not const) */ - duk_regconst_t rc_key; + if (duk__hstring_is_eval_or_arguments_in_strict_mode(comp_ctx, h_varname)) { + goto syntax_error; + } - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &left->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); - duk__emit_a_b_c(comp_ctx, - args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_POSTINCP */ - reg_res, - reg_obj, - rc_key); + duk_dup(thr, left->x1.valstack_idx); + if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { + duk__emit_a_bc(comp_ctx, + args_op1, /* e.g. DUK_OP_POSTINCR */ + reg_res, + reg_varbind); } else { - /* Technically return value is not needed because INVLHS will - * unconditially throw a ReferenceError. Coercion is necessary - * for proper semantics (consider ToNumber() called for an object). - * Use DUK_OP_UNP with a dummy register to get ToNumber(). - */ - duk__ivalue_toforcedreg(comp_ctx, left, reg_res); - duk__emit_bc(comp_ctx, - DUK_OP_UNP, - reg_res); /* for side effects, result ignored */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__emit_a_bc(comp_ctx, + args_op1 + 4, /* e.g. DUK_OP_POSTINCV */ + reg_res, + rc_varname); } - DUK__SETTEMP(comp_ctx, reg_res + 1); - duk__ivalue_regconst(res, reg_res); - return; + DUK_DDD(DUK_DDDPRINT("postincdec to '%!O' -> reg_varbind=%ld, rc_varname=%ld", + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); + } else if (left->t == DUK_IVAL_PROP) { + duk_regconst_t reg_obj; /* allocate to reg only (not const) */ + duk_regconst_t rc_key; + + reg_obj = duk__ispec_toregconst_raw(comp_ctx, &left->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, &left->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + duk__emit_a_b_c(comp_ctx, + args_op2 | DUK__EMIT_FLAG_BC_REGCONST, /* e.g. DUK_OP_POSTINCP */ + reg_res, + reg_obj, + rc_key); + } else { + /* Technically return value is not needed because INVLHS will + * unconditially throw a ReferenceError. Coercion is necessary + * for proper semantics (consider ToNumber() called for an object). + * Use DUK_OP_UNP with a dummy register to get ToNumber(). + */ + duk__ivalue_toforcedreg(comp_ctx, left, reg_res); + duk__emit_bc(comp_ctx, DUK_OP_UNP, reg_res); /* for side effects, result ignored */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } - syntax_error: + DUK__SETTEMP(comp_ctx, reg_res + 1); + duk__ivalue_regconst(res, reg_res); + return; +} + +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_EXPRESSION); DUK_WO_NORETURN(return;); - syntax_error_lvalue: +syntax_error_lvalue: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_LVALUE); DUK_WO_NORETURN(return;); } @@ -72748,7 +74034,7 @@ DUK_LOCAL duk_small_uint_t duk__expr_lbp(duk_compiler_ctx *comp_ctx) { duk_small_uint_t tok = comp_ctx->curr_token.t; - DUK_ASSERT_DISABLE(tok >= DUK_TOK_MINVAL); /* unsigned */ + DUK_ASSERT_DISABLE(tok >= DUK_TOK_MINVAL); /* unsigned */ DUK_ASSERT(tok <= DUK_TOK_MAXVAL); DUK_ASSERT(sizeof(duk__token_lbp) == DUK_TOK_MAXVAL + 1); @@ -72761,8 +74047,7 @@ return 0; } - if ((tok == DUK_TOK_DECREMENT || tok == DUK_TOK_INCREMENT) && - (comp_ctx->curr_token.lineterm)) { + if ((tok == DUK_TOK_DECREMENT || tok == DUK_TOK_INCREMENT) && (comp_ctx->curr_token.lineterm)) { /* '++' or '--' in a post-increment/decrement position, * and a LineTerminator occurs between the operator and * the preceding expression. Force the previous expr @@ -72772,7 +74057,7 @@ return 0; } - return DUK__TOKEN_LBP_GET_BP(duk__token_lbptok); /* format is bit packed */ + return DUK__TOKEN_LBP_GET_BP(duk__token_lbptok); /* format is bit packed */ } /* @@ -72784,15 +74069,15 @@ * statement). */ -#define DUK__EXPR_RBP_MASK 0xff -#define DUK__EXPR_FLAG_REJECT_IN (1 << 8) /* reject 'in' token (used for for-in) */ -#define DUK__EXPR_FLAG_ALLOW_EMPTY (1 << 9) /* allow empty expression */ -#define DUK__EXPR_FLAG_REQUIRE_INIT (1 << 10) /* require initializer for var/const */ +#define DUK__EXPR_RBP_MASK 0xff +#define DUK__EXPR_FLAG_REJECT_IN (1 << 8) /* reject 'in' token (used for for-in) */ +#define DUK__EXPR_FLAG_ALLOW_EMPTY (1 << 9) /* allow empty expression */ +#define DUK__EXPR_FLAG_REQUIRE_INIT (1 << 10) /* require initializer for var/const */ /* main expression parser function */ DUK_LOCAL void duk__expr(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk_hthread *thr = comp_ctx->thr; - duk_ivalue tmp_alloc; /* 'res' is used for "left", and 'tmp' for "right" */ + duk_ivalue tmp_alloc; /* 'res' is used for "left", and 'tmp' for "right" */ duk_ivalue *tmp = &tmp_alloc; duk_small_uint_t rbp; @@ -72804,7 +74089,9 @@ rbp = rbp_flags & DUK__EXPR_RBP_MASK; DUK_DDD(DUK_DDDPRINT("duk__expr(), rbp_flags=%ld, rbp=%ld, allow_in=%ld, paren_level=%ld", - (long) rbp_flags, (long) rbp, (long) comp_ctx->curr_func.allow_in, + (long) rbp_flags, + (long) rbp, + (long) comp_ctx->curr_func.allow_in, (long) comp_ctx->curr_func.paren_level)); duk_memzero(&tmp_alloc, sizeof(tmp_alloc)); @@ -72835,14 +74122,14 @@ } duk__advance(comp_ctx); - duk__expr_nud(comp_ctx, res); /* reuse 'res' as 'left' */ + duk__expr_nud(comp_ctx, res); /* reuse 'res' as 'left' */ while (rbp < duk__expr_lbp(comp_ctx)) { duk__advance(comp_ctx); duk__expr_led(comp_ctx, res, tmp); - duk__copy_ivalue(comp_ctx, tmp, res); /* tmp -> res */ + duk__copy_ivalue(comp_ctx, tmp, res); /* tmp -> res */ } - cleanup: +cleanup: /* final result is already in 'res' */ duk_pop_2(thr); @@ -72876,21 +74163,24 @@ * Each helper needs at least 2-3 calls to make it worth while to wrap. */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_toreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_toreg(comp_ctx, res); } #endif -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_totemp(comp_ctx, res); } #endif -DUK_LOCAL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg) { +DUK_LOCAL void duk__expr_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg) { DUK_ASSERT(forced_reg >= 0); duk__expr(comp_ctx, res, rbp_flags); duk__ivalue_toforcedreg(comp_ctx, res, forced_reg); @@ -72901,7 +74191,7 @@ return duk__ivalue_toregconst(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__expr_totempconst(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__expr(comp_ctx, res, rbp_flags); return duk__ivalue_totempconst(comp_ctx, res); @@ -72923,14 +74213,17 @@ return duk__ivalue_toreg(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL duk_regconst_t duk__exprtop_totemp(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags) { duk__exprtop(comp_ctx, res, rbp_flags); return duk__ivalue_totemp(comp_ctx, res); } #endif -DUK_LOCAL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t rbp_flags, duk_regconst_t forced_reg) { +DUK_LOCAL void duk__exprtop_toforcedreg(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t rbp_flags, + duk_regconst_t forced_reg) { DUK_ASSERT(forced_reg >= 0); duk__exprtop(comp_ctx, res, rbp_flags); duk__ivalue_toforcedreg(comp_ctx, res, forced_reg); @@ -72941,7 +74234,7 @@ return duk__ivalue_toregconst(comp_ctx, res); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__exprtop_toplain_ignore(duk_compiler_ctx *comp_ctx, duk_ivalue *res, int rbp_flags) { duk__exprtop(comp_ctx, res, rbp_flags); duk__ivalue_toplain_ignore(comp_ctx, res); @@ -72960,11 +74253,11 @@ * the token after the terminator). */ -#define DUK__HAS_VAL (1 << 0) /* stmt has non-empty value */ -#define DUK__HAS_TERM (1 << 1) /* stmt has explicit/implicit semicolon terminator */ -#define DUK__ALLOW_AUTO_SEMI_ALWAYS (1 << 2) /* allow automatic semicolon even without lineterm (compatibility) */ -#define DUK__STILL_PROLOGUE (1 << 3) /* statement does not terminate directive prologue */ -#define DUK__IS_TERMINAL (1 << 4) /* statement is guaranteed to be terminal (control doesn't flow to next statement) */ +#define DUK__HAS_VAL (1 << 0) /* stmt has non-empty value */ +#define DUK__HAS_TERM (1 << 1) /* stmt has explicit/implicit semicolon terminator */ +#define DUK__ALLOW_AUTO_SEMI_ALWAYS (1 << 2) /* allow automatic semicolon even without lineterm (compatibility) */ +#define DUK__STILL_PROLOGUE (1 << 3) /* statement does not terminate directive prologue */ +#define DUK__IS_TERMINAL (1 << 4) /* statement is guaranteed to be terminal (control doesn't flow to next statement) */ /* Parse a single variable declaration (e.g. "i" or "i=10"). A leading 'var' * has already been eaten. These is no return value in 'res', it is used only @@ -72984,7 +74277,11 @@ * as is done in 'for-in' parsing. */ -DUK_LOCAL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_small_uint_t expr_flags, duk_regconst_t *out_reg_varbind, duk_regconst_t *out_rc_varname) { +DUK_LOCAL void duk__parse_var_decl(duk_compiler_ctx *comp_ctx, + duk_ivalue *res, + duk_small_uint_t expr_flags, + duk_regconst_t *out_reg_varbind, + duk_regconst_t *out_rc_varname) { duk_hthread *thr = comp_ctx->thr; duk_hstring *h_varname; duk_regconst_t reg_varbind; @@ -73008,8 +74305,7 @@ /* register declarations in first pass */ if (comp_ctx->curr_func.in_scanning) { duk_uarridx_t n; - DUK_DDD(DUK_DDDPRINT("register variable declaration %!O in pass 1", - (duk_heaphdr *) h_varname)); + DUK_DDD(DUK_DDDPRINT("register variable declaration %!O in pass 1", (duk_heaphdr *) h_varname)); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); duk_push_hstring(thr, h_varname); duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n); @@ -73017,31 +74313,30 @@ duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n + 1); } - duk_push_hstring(thr, h_varname); /* push before advancing to keep reachable */ + duk_push_hstring(thr, h_varname); /* push before advancing to keep reachable */ /* register binding lookup is based on varmap (even in first pass) */ duk_dup_top(thr); (void) duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname); - duk__advance(comp_ctx); /* eat identifier */ + duk__advance(comp_ctx); /* eat identifier */ if (comp_ctx->curr_token.t == DUK_TOK_EQUALSIGN) { duk__advance(comp_ctx); DUK_DDD(DUK_DDDPRINT("vardecl, assign to '%!O' -> reg_varbind=%ld, rc_varname=%ld", - (duk_heaphdr *) h_varname, (long) reg_varbind, (long) rc_varname)); + (duk_heaphdr *) h_varname, + (long) reg_varbind, + (long) rc_varname)); - duk__exprtop(comp_ctx, res, DUK__BP_COMMA | expr_flags /*rbp_flags*/); /* AssignmentExpression */ + duk__exprtop(comp_ctx, res, DUK__BP_COMMA | expr_flags /*rbp_flags*/); /* AssignmentExpression */ if (reg_varbind >= 0) { duk__ivalue_toforcedreg(comp_ctx, res, reg_varbind); } else { duk_regconst_t reg_val; reg_val = duk__ivalue_toreg(comp_ctx, res); - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_val, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, reg_val, rc_varname); } } else { if (expr_flags & DUK__EXPR_FLAG_REQUIRE_INIT) { @@ -73050,14 +74345,14 @@ } } - duk_pop(thr); /* pop varname */ + duk_pop(thr); /* pop varname */ *out_rc_varname = rc_varname; *out_reg_varbind = reg_varbind; return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_VAR_DECLARATION); DUK_WO_NORETURN(return;); } @@ -73066,7 +74361,7 @@ duk_regconst_t reg_varbind; duk_regconst_t rc_varname; - duk__advance(comp_ctx); /* eat 'var' */ + duk__advance(comp_ctx); /* eat 'var' */ for (;;) { /* rc_varname and reg_varbind are ignored here */ @@ -73081,9 +74376,9 @@ DUK_LOCAL void duk__parse_for_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site) { duk_hthread *thr = comp_ctx->thr; - duk_int_t pc_v34_lhs; /* start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example) */ - duk_regconst_t temp_reset; /* knock back "next temp" to this whenever possible */ - duk_regconst_t reg_temps; /* preallocated temporaries (2) for variants 3 and 4 */ + duk_int_t pc_v34_lhs; /* start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example) */ + duk_regconst_t temp_reset; /* knock back "next temp" to this whenever possible */ + duk_regconst_t reg_temps; /* preallocated temporaries (2) for variants 3 and 4 */ DUK_DDD(DUK_DDDPRINT("start parsing a for/for-in statement")); @@ -73112,7 +74407,7 @@ * issues, evaluation order issues, etc. */ - duk__advance(comp_ctx); /* eat 'for' */ + duk__advance(comp_ctx); /* eat 'for' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); DUK_DDD(DUK_DDDPRINT("detecting for/for-in loop variant, pc=%ld", (long) duk__get_current_pc(comp_ctx))); @@ -73126,10 +74421,10 @@ * Variant 2 or 4 */ - duk_regconst_t reg_varbind; /* variable binding register if register-bound (otherwise < 0) */ - duk_regconst_t rc_varname; /* variable name reg/const, if variable not register-bound */ + duk_regconst_t reg_varbind; /* variable binding register if register-bound (otherwise < 0) */ + duk_regconst_t rc_varname; /* variable name reg/const, if variable not register-bound */ - duk__advance(comp_ctx); /* eat 'var' */ + duk__advance(comp_ctx); /* eat 'var' */ duk__parse_var_decl(comp_ctx, res, DUK__EXPR_FLAG_REJECT_IN, ®_varbind, &rc_varname); DUK__SETTEMP(comp_ctx, temp_reset); @@ -73139,17 +74434,11 @@ */ DUK_DDD(DUK_DDDPRINT("detected for variant 4: for (var VariableDeclarationNoIn in Expression) Statement")); - pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here */ + pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here */ if (reg_varbind >= 0) { - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_varbind, - reg_temps + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_varbind, reg_temps + 0); } else { - duk__emit_a_bc(comp_ctx, - DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, - reg_temps + 0, - rc_varname); + duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, reg_temps + 0, rc_varname); } goto parse_3_or_4; } else { @@ -73157,7 +74446,8 @@ * Variant 2 */ - DUK_DDD(DUK_DDDPRINT("detected for variant 2: for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement")); + DUK_DDD(DUK_DDDPRINT( + "detected for variant 2: for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement")); for (;;) { /* more initializers */ if (comp_ctx->curr_token.t != DUK_TOK_COMMA) { @@ -73165,7 +74455,7 @@ } DUK_DDD(DUK_DDDPRINT("variant 2 has another variable initializer")); - duk__advance(comp_ctx); /* eat comma */ + duk__advance(comp_ctx); /* eat comma */ duk__parse_var_decl(comp_ctx, res, DUK__EXPR_FLAG_REJECT_IN, ®_varbind, &rc_varname); } goto parse_1_or_2; @@ -73175,14 +74465,17 @@ * Variant 1 or 3 */ - pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here (variant 3) */ + pc_v34_lhs = duk__get_current_pc(comp_ctx); /* jump is inserted here (variant 3) */ /* Note that duk__exprtop() here can clobber any reg above current temp_next, * so any loop variables (e.g. enumerator) must be "preallocated". */ /* don't coerce yet to a plain value (variant 3 needs special handling) */ - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_REJECT_IN | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression */ + duk__exprtop(comp_ctx, + res, + DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_REJECT_IN | + DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression */ if (comp_ctx->curr_token.t == DUK_TOK_IN) { /* * Variant 3 @@ -73191,7 +74484,7 @@ /* XXX: need to determine LHS type, and check that it is LHS compatible */ DUK_DDD(DUK_DDDPRINT("detected for variant 3: for (LeftHandSideExpression in Expression) Statement")); if (duk__expr_is_empty(comp_ctx)) { - goto syntax_error; /* LeftHandSideExpression does not allow empty expression */ + goto syntax_error; /* LeftHandSideExpression does not allow empty expression */ } if (res->t == DUK_IVAL_VAR) { @@ -73200,10 +74493,7 @@ duk_dup(thr, res->x1.valstack_idx); if (duk__lookup_lhs(comp_ctx, ®_varbind, &rc_varname)) { - duk__emit_a_bc(comp_ctx, - DUK_OP_LDREG, - reg_varbind, - reg_temps + 0); + duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_varbind, reg_temps + 0); } else { duk__emit_a_bc(comp_ctx, DUK_OP_PUTVAR | DUK__EMIT_FLAG_A_IS_SOURCE, @@ -73216,17 +74506,22 @@ */ duk_regconst_t reg_obj; duk_regconst_t rc_key; - reg_obj = duk__ispec_toregconst_raw(comp_ctx, &res->x1, -1 /*forced_reg*/, 0 /*flags*/); /* don't allow const */ - rc_key = duk__ispec_toregconst_raw(comp_ctx, &res->x2, -1 /*forced_reg*/, DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); + reg_obj = duk__ispec_toregconst_raw(comp_ctx, + &res->x1, + -1 /*forced_reg*/, + 0 /*flags*/); /* don't allow const */ + rc_key = duk__ispec_toregconst_raw(comp_ctx, + &res->x2, + -1 /*forced_reg*/, + DUK__IVAL_FLAG_ALLOW_CONST /*flags*/); duk__emit_a_b_c(comp_ctx, DUK_OP_PUTPROP | DUK__EMIT_FLAG_A_IS_SOURCE | DUK__EMIT_FLAG_BC_REGCONST, reg_obj, rc_key, reg_temps + 0); } else { - duk__ivalue_toplain_ignore(comp_ctx, res); /* just in case */ - duk__emit_op_only(comp_ctx, - DUK_OP_INVLHS); + duk__ivalue_toplain_ignore(comp_ctx, res); /* just in case */ + duk__emit_op_only(comp_ctx, DUK_OP_INVLHS); } goto parse_3_or_4; } else { @@ -73234,13 +74529,14 @@ * Variant 1 */ - DUK_DDD(DUK_DDDPRINT("detected for variant 1: for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement")); + DUK_DDD(DUK_DDDPRINT( + "detected for variant 1: for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement")); duk__ivalue_toplain_ignore(comp_ctx, res); goto parse_1_or_2; } } - parse_1_or_2: +parse_1_or_2: /* * Parse variant 1 or 2. The first part expression (which differs * in the variants) has already been parsed and its code emitted. @@ -73263,23 +74559,23 @@ duk__advance_expect(comp_ctx, DUK_TOK_SEMICOLON); pc_l1 = duk__get_current_pc(comp_ctx); - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ + duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ if (duk__expr_is_empty(comp_ctx)) { /* no need to coerce */ - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ - pc_jumpto_l4 = -1; /* omitted */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ + pc_jumpto_l4 = -1; /* omitted */ } else { rc_cond = duk__ivalue_toregconst(comp_ctx, res); duk__emit_if_false_skip(comp_ctx, rc_cond); - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ - pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); /* to exit */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* to body */ + pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); /* to exit */ } DUK__SETTEMP(comp_ctx, temp_reset); duk__advance_expect(comp_ctx, DUK_TOK_SEMICOLON); pc_l2 = duk__get_current_pc(comp_ctx); - duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ + duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR | DUK__EXPR_FLAG_ALLOW_EMPTY /*rbp_flags*/); /* Expression_opt */ if (duk__expr_is_empty(comp_ctx)) { /* no need to coerce */ expr_c_empty = 1; @@ -73292,7 +74588,7 @@ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_l3 = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -73307,21 +74603,23 @@ DUK_DDD(DUK_DDDPRINT("patching jumps: jumpto_l3: %ld->%ld, jumpto_l4: %ld->%ld, " "break: %ld->%ld, continue: %ld->%ld", - (long) pc_jumpto_l3, (long) pc_l3, (long) pc_jumpto_l4, (long) pc_l4, - (long) (pc_label_site + 1), (long) pc_l4, (long) (pc_label_site + 2), (long) pc_l2)); + (long) pc_jumpto_l3, + (long) pc_l3, + (long) pc_jumpto_l4, + (long) pc_l4, + (long) (pc_label_site + 1), + (long) pc_l4, + (long) (pc_label_site + 2), + (long) pc_l2)); duk__patch_jump(comp_ctx, pc_jumpto_l3, pc_l3); duk__patch_jump(comp_ctx, pc_jumpto_l4, pc_l4); - duk__patch_jump(comp_ctx, - pc_label_site + 1, - pc_l4); /* break jump */ - duk__patch_jump(comp_ctx, - pc_label_site + 2, - expr_c_empty ? pc_l1 : pc_l2); /* continue jump */ + duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l4); /* break jump */ + duk__patch_jump(comp_ctx, pc_label_site + 2, expr_c_empty ? pc_l1 : pc_l2); /* continue jump */ } goto finished; - parse_3_or_4: +parse_3_or_4: /* * Parse variant 3 or 4. * @@ -73357,16 +74655,16 @@ */ duk__insert_jump_entry(comp_ctx, pc_v34_lhs); - pc_jumpto_l2 = pc_v34_lhs; /* inserted jump */ - pc_l1 = pc_v34_lhs + 1; /* +1, right after inserted jump */ + pc_jumpto_l2 = pc_v34_lhs; /* inserted jump */ + pc_l1 = pc_v34_lhs + 1; /* +1, right after inserted jump */ /* The code for writing reg_temps + 0 to the left hand side has already * been emitted. */ - pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* -> loop body */ + pc_jumpto_l3 = duk__emit_jump_empty(comp_ctx); /* -> loop body */ - duk__advance(comp_ctx); /* eat 'in' */ + duk__advance(comp_ctx); /* eat 'in' */ /* Parse enumeration target and initialize enumerator. For 'null' and 'undefined', * INITENUM will creates a 'null' enumerator which works like an empty enumerator @@ -73375,16 +74673,13 @@ */ pc_l2 = duk__get_current_pc(comp_ctx); - reg_target = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression */ - duk__emit_b_c(comp_ctx, - DUK_OP_INITENUM | DUK__EMIT_FLAG_B_IS_TARGET, - reg_temps + 1, - reg_target); + reg_target = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); /* Expression */ + duk__emit_b_c(comp_ctx, DUK_OP_INITENUM | DUK__EMIT_FLAG_B_IS_TARGET, reg_temps + 1, reg_target); pc_jumpto_l4 = duk__emit_jump_empty(comp_ctx); DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_l3 = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -73401,8 +74696,8 @@ DUK_OP_NEXTENUM | DUK__EMIT_FLAG_B_IS_TARGET | DUK__EMIT_FLAG_RESERVE_JUMPSLOT, reg_temps + 0, reg_temps + 1); - pc_jumpto_l5 = comp_ctx->emit_jumpslot_pc; /* NEXTENUM jump slot: executed when enum finished */ - duk__emit_jump(comp_ctx, pc_l1); /* jump to next loop, using reg_v34_iter as iterated value */ + pc_jumpto_l5 = comp_ctx->emit_jumpslot_pc; /* NEXTENUM jump slot: executed when enum finished */ + duk__emit_jump(comp_ctx, pc_l1); /* jump to next loop, using reg_v34_iter as iterated value */ pc_l5 = duk__get_current_pc(comp_ctx); @@ -73414,24 +74709,33 @@ DUK_DDD(DUK_DDDPRINT("patching jumps: jumpto_l2: %ld->%ld, jumpto_l3: %ld->%ld, " "jumpto_l4: %ld->%ld, jumpto_l5: %ld->%ld, " "break: %ld->%ld, continue: %ld->%ld", - (long) pc_jumpto_l2, (long) pc_l2, (long) pc_jumpto_l3, (long) pc_l3, - (long) pc_jumpto_l4, (long) pc_l4, (long) pc_jumpto_l5, (long) pc_l5, - (long) (pc_label_site + 1), (long) pc_l5, (long) (pc_label_site + 2), (long) pc_l4)); + (long) pc_jumpto_l2, + (long) pc_l2, + (long) pc_jumpto_l3, + (long) pc_l3, + (long) pc_jumpto_l4, + (long) pc_l4, + (long) pc_jumpto_l5, + (long) pc_l5, + (long) (pc_label_site + 1), + (long) pc_l5, + (long) (pc_label_site + 2), + (long) pc_l4)); duk__patch_jump(comp_ctx, pc_jumpto_l2, pc_l2); duk__patch_jump(comp_ctx, pc_jumpto_l3, pc_l3); duk__patch_jump(comp_ctx, pc_jumpto_l4, pc_l4); duk__patch_jump(comp_ctx, pc_jumpto_l5, pc_l5); - duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l5); /* break jump */ - duk__patch_jump(comp_ctx, pc_label_site + 2, pc_l4); /* continue jump */ + duk__patch_jump(comp_ctx, pc_label_site + 1, pc_l5); /* break jump */ + duk__patch_jump(comp_ctx, pc_label_site + 2, pc_l4); /* continue jump */ } goto finished; - finished: +finished: DUK_DDD(DUK_DDDPRINT("end parsing a for/for-in statement")); return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_FOR); DUK_WO_NORETURN(return;); } @@ -73439,12 +74743,12 @@ DUK_LOCAL void duk__parse_switch_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_int_t pc_label_site) { duk_hthread *thr = comp_ctx->thr; duk_regconst_t temp_at_loop; - duk_regconst_t rc_switch; /* reg/const for switch value */ - duk_regconst_t rc_case; /* reg/const for case value */ - duk_regconst_t reg_temp; /* general temp register */ + duk_regconst_t rc_switch; /* reg/const for switch value */ + duk_regconst_t rc_case; /* reg/const for case value */ + duk_regconst_t reg_temp; /* general temp register */ duk_int_t pc_prevcase = -1; duk_int_t pc_prevstmt = -1; - duk_int_t pc_default = -1; /* -1 == not set, -2 == pending (next statement list) */ + duk_int_t pc_default = -1; /* -1 == not set, -2 == pending (next statement list) */ /* Note: negative pc values are ignored when patching jumps, so no explicit checks needed */ @@ -73475,7 +74779,7 @@ duk__advance(comp_ctx); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); rc_switch = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* RegExp mode does not matter. */ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); DUK_DDD(DUK_DDDPRINT("switch value in register %ld", (long) rc_switch)); @@ -73505,24 +74809,20 @@ * because it may be a constant. */ - duk__patch_jump_here(comp_ctx, pc_prevcase); /* chain jumps for case - * evaluation and checking - */ + duk__patch_jump_here(comp_ctx, pc_prevcase); /* chain jumps for case + * evaluation and checking + */ duk__advance(comp_ctx); rc_case = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__advance_expect(comp_ctx, DUK_TOK_COLON); reg_temp = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_b_c(comp_ctx, - DUK_OP_SEQ | DUK__EMIT_FLAG_BC_REGCONST, - reg_temp, - rc_switch, - rc_case); + duk__emit_a_b_c(comp_ctx, DUK_OP_SEQ | DUK__EMIT_FLAG_BC_REGCONST, reg_temp, rc_switch, rc_case); duk__emit_if_true_skip(comp_ctx, reg_temp); /* jump to next case clause */ - pc_prevcase = duk__emit_jump_empty(comp_ctx); /* no match, next case */ + pc_prevcase = duk__emit_jump_empty(comp_ctx); /* no match, next case */ /* statements go here (if any) on next loop */ } else if (comp_ctx->curr_token.t == DUK_TOK_DEFAULT) { @@ -73571,14 +74871,13 @@ * they participate in 'fall-through' behavior even if the * default clause is in the middle. */ - duk__patch_jump_here(comp_ctx, pc_prevstmt); /* chain jumps for 'fall-through' - * after a case matches. - */ + duk__patch_jump_here(comp_ctx, pc_prevstmt); /* chain jumps for 'fall-through' + * after a case matches. + */ for (;;) { tok = comp_ctx->curr_token.t; - if (tok == DUK_TOK_CASE || tok == DUK_TOK_DEFAULT || - tok == DUK_TOK_RCURLY) { + if (tok == DUK_TOK_CASE || tok == DUK_TOK_DEFAULT || tok == DUK_TOK_RCURLY) { break; } num_stmts++; @@ -73601,7 +74900,7 @@ DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_RCURLY); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance(comp_ctx); /* Allow RegExp as part of next stmt. */ + duk__advance(comp_ctx); /* Allow RegExp as part of next stmt. */ /* default case control flow patchup; note that if pc_prevcase < 0 * (i.e. no case clauses), control enters default case automatically. @@ -73622,7 +74921,7 @@ duk__patch_jump_here(comp_ctx, pc_prevstmt); /* continue jump not patched, an INVALID opcode remains there */ - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ /* Note: 'fast' breaks will jump to pc_label_site + 1, which will * then jump here. The double jump will be eliminated by a @@ -73632,7 +74931,7 @@ return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_SWITCH); DUK_WO_NORETURN(return;); } @@ -73646,16 +74945,16 @@ temp_reset = DUK__GETTEMP(comp_ctx); - duk__advance(comp_ctx); /* eat 'if' */ + duk__advance(comp_ctx); /* eat 'if' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); rc_cond = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__emit_if_true_skip(comp_ctx, rc_cond); - pc_jump_false = duk__emit_jump_empty(comp_ctx); /* jump to end or else part */ + pc_jump_false = duk__emit_jump_empty(comp_ctx); /* jump to end or else part */ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -73670,7 +74969,7 @@ duk__advance(comp_ctx); - pc_jump_end = duk__emit_jump_empty(comp_ctx); /* jump from true part to end */ + pc_jump_end = duk__emit_jump_empty(comp_ctx); /* jump from true part to end */ duk__patch_jump_here(comp_ctx, pc_jump_false); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); @@ -73691,11 +74990,11 @@ DUK_DDD(DUK_DDDPRINT("begin parsing do statement")); - duk__advance(comp_ctx); /* Eat 'do'; allow RegExp as part of next stmt. */ + duk__advance(comp_ctx); /* Eat 'do'; allow RegExp as part of next stmt. */ pc_start = duk__get_current_pc(comp_ctx); duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); - duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ duk__advance_expect(comp_ctx, DUK_TOK_WHILE); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); @@ -73705,10 +75004,10 @@ duk__emit_jump(comp_ctx, pc_start); /* no need to reset temps, as we're finished emitting code */ - comp_ctx->curr_func.allow_regexp_in_adv = 1; /* Allow RegExp as part of next stmt. */ + comp_ctx->curr_func.allow_regexp_in_adv = 1; /* Allow RegExp as part of next stmt. */ duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ DUK_DDD(DUK_DDDPRINT("end parsing do statement")); } @@ -73723,12 +75022,12 @@ temp_reset = DUK__GETTEMP(comp_ctx); - duk__advance(comp_ctx); /* eat 'while' */ + duk__advance(comp_ctx); /* eat 'while' */ duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); pc_start = duk__get_current_pc(comp_ctx); - duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 2); /* continue jump */ rc_cond = duk__exprtop_toregconst(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); duk__emit_if_true_skip(comp_ctx, rc_cond); @@ -73736,13 +75035,13 @@ DUK__SETTEMP(comp_ctx, temp_reset); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); duk__emit_jump(comp_ctx, pc_start); duk__patch_jump_here(comp_ctx, pc_jump_false); - duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_label_site + 1); /* break jump */ DUK_DDD(DUK_DDDPRINT("end parsing while statement")); } @@ -73752,23 +75051,35 @@ duk_bool_t is_break = (comp_ctx->curr_token.t == DUK_TOK_BREAK); duk_int_t label_id; duk_int_t label_catch_depth; - duk_int_t label_pc; /* points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue */ + duk_int_t label_pc; /* points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue */ duk_bool_t label_is_closest; DUK_UNREF(res); - duk__advance(comp_ctx); /* eat 'break' or 'continue' */ + duk__advance(comp_ctx); /* eat 'break' or 'continue' */ - if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ - comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ - comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ + if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ + comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ + comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ /* break/continue without label */ - duk__lookup_active_label(comp_ctx, DUK_HTHREAD_STRING_EMPTY_STRING(thr), is_break, &label_id, &label_catch_depth, &label_pc, &label_is_closest); + duk__lookup_active_label(comp_ctx, + DUK_HTHREAD_STRING_EMPTY_STRING(thr), + is_break, + &label_id, + &label_catch_depth, + &label_pc, + &label_is_closest); } else if (comp_ctx->curr_token.t == DUK_TOK_IDENTIFIER) { /* break/continue with label (label cannot be a reserved word, production is 'Identifier' */ DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); - duk__lookup_active_label(comp_ctx, comp_ctx->curr_token.str1, is_break, &label_id, &label_catch_depth, &label_pc, &label_is_closest); + duk__lookup_active_label(comp_ctx, + comp_ctx->curr_token.str1, + is_break, + &label_id, + &label_catch_depth, + &label_pc, + &label_is_closest); duk__advance(comp_ctx); } else { DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_BREAK_CONT_LABEL); @@ -73781,25 +75092,28 @@ * The peephole optimizer will optimize the jump to a direct one. */ - if (label_catch_depth == comp_ctx->curr_func.catch_depth && - label_is_closest) { + if (label_catch_depth == comp_ctx->curr_func.catch_depth && label_is_closest) { DUK_DDD(DUK_DDDPRINT("break/continue: is_break=%ld, label_id=%ld, label_is_closest=%ld, " "label_catch_depth=%ld, catch_depth=%ld " "-> use fast variant (direct jump)", - (long) is_break, (long) label_id, (long) label_is_closest, - (long) label_catch_depth, (long) comp_ctx->curr_func.catch_depth)); + (long) is_break, + (long) label_id, + (long) label_is_closest, + (long) label_catch_depth, + (long) comp_ctx->curr_func.catch_depth)); duk__emit_jump(comp_ctx, label_pc + (is_break ? 1 : 2)); } else { DUK_DDD(DUK_DDDPRINT("break/continue: is_break=%ld, label_id=%ld, label_is_closest=%ld, " "label_catch_depth=%ld, catch_depth=%ld " "-> use slow variant (longjmp)", - (long) is_break, (long) label_id, (long) label_is_closest, - (long) label_catch_depth, (long) comp_ctx->curr_func.catch_depth)); + (long) is_break, + (long) label_id, + (long) label_is_closest, + (long) label_catch_depth, + (long) comp_ctx->curr_func.catch_depth)); - duk__emit_bc(comp_ctx, - is_break ? DUK_OP_BREAK : DUK_OP_CONTINUE, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, is_break ? DUK_OP_BREAK : DUK_OP_CONTINUE, (duk_regconst_t) label_id); } } @@ -73807,7 +75121,7 @@ duk_hthread *thr = comp_ctx->thr; duk_regconst_t rc_val; - duk__advance(comp_ctx); /* eat 'return' */ + duk__advance(comp_ctx); /* eat 'return' */ /* A 'return' statement is only allowed inside an actual function body, * not as part of eval or global code. @@ -73817,9 +75131,9 @@ DUK_WO_NORETURN(return;); } - if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ - comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ - comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ + if (comp_ctx->curr_token.t == DUK_TOK_SEMICOLON || /* explicit semi follows */ + comp_ctx->curr_token.lineterm || /* automatic semi will be inserted */ + comp_ctx->curr_token.allow_auto_semi) { /* automatic semi will be inserted */ DUK_DDD(DUK_DDDPRINT("empty return value -> undefined")); duk__emit_op_only(comp_ctx, DUK_OP_RETUNDEF); } else { @@ -73871,8 +75185,8 @@ */ #if defined(DUK_USE_TAILCALL) - if (comp_ctx->curr_func.catch_depth == 0 && /* no catchers */ - pc_after_expr > pc_before_expr) { /* at least one opcode emitted */ + if (comp_ctx->curr_func.catch_depth == 0 && /* no catchers */ + pc_after_expr > pc_before_expr) { /* at least one opcode emitted */ duk_compiler_instr *instr; duk_instr_t ins; duk_small_uint_t op; @@ -73882,8 +75196,7 @@ ins = instr->ins; op = (duk_small_uint_t) DUK_DEC_OP(ins); - if ((op & ~0x0fU) == DUK_OP_CALL0 && - DUK__ISREG_TEMP(comp_ctx, rc_val) /* see above */) { + if ((op & ~0x0fU) == DUK_OP_CALL0 && DUK__ISREG_TEMP(comp_ctx, rc_val) /* see above */) { DUK_DDD(DUK_DDDPRINT("return statement detected a tail call opportunity: " "catch depth is 0, duk__exprtop() emitted >= 1 instructions, " "and last instruction is a CALL " @@ -73892,7 +75205,7 @@ instr->ins = ins; } } -#endif /* DUK_USE_TAILCALL */ +#endif /* DUK_USE_TAILCALL */ if (DUK__ISREG(rc_val)) { duk__emit_bc(comp_ctx, DUK_OP_RETREG, rc_val); @@ -73910,7 +75223,7 @@ DUK_LOCAL void duk__parse_throw_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_regconst_t reg_val; - duk__advance(comp_ctx); /* eat 'throw' */ + duk__advance(comp_ctx); /* eat 'throw' */ /* Unlike break/continue, throw statement does not allow an empty value. */ @@ -73920,14 +75233,12 @@ } reg_val = duk__exprtop_toreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - duk__emit_bc(comp_ctx, - DUK_OP_THROW, - reg_val); + duk__emit_bc(comp_ctx, DUK_OP_THROW, reg_val); } DUK_LOCAL void duk__parse_try_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res) { duk_hthread *thr = comp_ctx->thr; - duk_regconst_t reg_catch; /* reg_catch+0 and reg_catch+1 are reserved for TRYCATCH */ + duk_regconst_t reg_catch; /* reg_catch+0 and reg_catch+1 are reserved for TRYCATCH */ duk_regconst_t rc_varname = 0; duk_small_uint_t trycatch_flags = 0; duk_int_t pc_ldconst = -1; @@ -73954,7 +75265,7 @@ comp_ctx->curr_func.catch_depth++; - duk__advance(comp_ctx); /* eat 'try' */ + duk__advance(comp_ctx); /* eat 'try' */ reg_catch = DUK__ALLOCTEMPS(comp_ctx, 2); @@ -73967,9 +75278,9 @@ duk__emit_a_bc(comp_ctx, DUK_OP_LDCONST, reg_catch, 0 /*patched later*/); pc_trycatch = duk__get_current_pc(comp_ctx); - duk__emit_invalid(comp_ctx); /* TRYCATCH, cannot emit now (not enough info) */ - duk__emit_invalid(comp_ctx); /* jump for 'catch' case */ - duk__emit_invalid(comp_ctx); /* jump for 'finally' case or end (if no finally) */ + duk__emit_invalid(comp_ctx); /* TRYCATCH, cannot emit now (not enough info) */ + duk__emit_invalid(comp_ctx); /* jump for 'catch' case */ + duk__emit_invalid(comp_ctx); /* jump for 'finally' case or end (if no finally) */ /* try part */ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); @@ -73998,7 +75309,7 @@ */ duk_hstring *h_var; - duk_int_t varmap_value; /* for storing/restoring the varmap binding for catch variable */ + duk_int_t varmap_value; /* for storing/restoring the varmap binding for catch variable */ DUK_DDD(DUK_DDDPRINT("stack top at start of catch clause: %ld", (long) duk_get_top(thr))); @@ -74016,19 +75327,17 @@ h_var = comp_ctx->curr_token.str1; DUK_ASSERT(h_var != NULL); - duk_push_hstring(thr, h_var); /* keep in on valstack, use borrowed ref below */ + duk_push_hstring(thr, h_var); /* keep in on valstack, use borrowed ref below */ if (comp_ctx->curr_func.is_strict && - ((h_var == DUK_HTHREAD_STRING_EVAL(thr)) || - (h_var == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr)))) { + ((h_var == DUK_HTHREAD_STRING_EVAL(thr)) || (h_var == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr)))) { DUK_DDD(DUK_DDDPRINT("catch identifier 'eval' or 'arguments' in strict mode -> SyntaxError")); goto syntax_error; } duk_dup_top(thr); rc_varname = duk__getconst(comp_ctx); - DUK_DDD(DUK_DDDPRINT("catch clause, rc_varname=0x%08lx (%ld)", - (unsigned long) rc_varname, (long) rc_varname)); + DUK_DDD(DUK_DDDPRINT("catch clause, rc_varname=0x%08lx (%ld)", (unsigned long) rc_varname, (long) rc_varname)); duk__advance(comp_ctx); duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); @@ -74091,8 +75400,7 @@ DUK_DDD(DUK_DDDPRINT("varmap after restore catch clause: %!iT", (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.varmap_idx))); - duk__emit_op_only(comp_ctx, - DUK_OP_ENDCATCH); + duk__emit_op_only(comp_ctx, DUK_OP_ENDCATCH); /* * XXX: for now, indicate that an expensive catch binding @@ -74115,13 +75423,10 @@ duk__advance_expect(comp_ctx, DUK_TOK_LCURLY); duk__parse_stmts(comp_ctx, 0 /*allow_source_elem*/, 0 /*expect_eof*/, 1 /*regexp_after*/); /* the DUK_TOK_RCURLY is eaten by duk__parse_stmts() */ - duk__emit_abc(comp_ctx, - DUK_OP_ENDFIN, - reg_catch); /* rethrow */ + duk__emit_abc(comp_ctx, DUK_OP_ENDFIN, reg_catch); /* rethrow */ } - if (!(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) && - !(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY)) { + if (!(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) && !(trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY)) { /* must have catch and/or finally */ goto syntax_error; } @@ -74131,12 +75436,7 @@ * constant 0) the DUK__CONST_MARKER flag will be set in rc_varname. */ - duk__patch_trycatch(comp_ctx, - pc_ldconst, - pc_trycatch, - reg_catch, - rc_varname, - trycatch_flags); + duk__patch_trycatch(comp_ctx, pc_ldconst, pc_trycatch, reg_catch, rc_varname, trycatch_flags); if (trycatch_flags & DUK_BC_TRYCATCH_FLAG_HAVE_CATCH) { DUK_ASSERT(pc_catch >= 0); @@ -74154,7 +75454,7 @@ comp_ctx->curr_func.catch_depth--; return; - syntax_error: +syntax_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_TRY); DUK_WO_NORETURN(return;); } @@ -74172,23 +75472,23 @@ comp_ctx->curr_func.catch_depth++; - duk__advance(comp_ctx); /* eat 'with' */ + duk__advance(comp_ctx); /* eat 'with' */ reg_catch = DUK__ALLOCTEMPS(comp_ctx, 2); duk__advance_expect(comp_ctx, DUK_TOK_LPAREN); duk__exprtop_toforcedreg(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/, reg_catch); comp_ctx->curr_func.allow_regexp_in_adv = 1; - duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ + duk__advance_expect(comp_ctx, DUK_TOK_RPAREN); /* Allow RegExp as part of next stmt. */ pc_trycatch = duk__get_current_pc(comp_ctx); trycatch_flags = DUK_BC_TRYCATCH_FLAG_WITH_BINDING; duk__emit_a_bc(comp_ctx, - DUK_OP_TRYCATCH | DUK__EMIT_FLAG_NO_SHUFFLE_A, - (duk_regconst_t) trycatch_flags /*a*/, - reg_catch /*bc*/); - duk__emit_invalid(comp_ctx); /* catch jump */ - duk__emit_invalid(comp_ctx); /* finished jump */ + DUK_OP_TRYCATCH | DUK__EMIT_FLAG_NO_SHUFFLE_A, + (duk_regconst_t) trycatch_flags /*a*/, + reg_catch /*bc*/); + duk__emit_invalid(comp_ctx); /* catch jump */ + duk__emit_invalid(comp_ctx); /* finished jump */ duk__parse_stmt(comp_ctx, res, 0 /*allow_source_elem*/); duk__emit_op_only(comp_ctx, DUK_OP_ENDTRY); @@ -74209,9 +75509,7 @@ label_id = comp_ctx->curr_func.label_next++; DUK_DDD(DUK_DDDPRINT("allocated new label id for label site: %ld", (long) label_id)); - duk__emit_bc(comp_ctx, - DUK_OP_LABEL, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, DUK_OP_LABEL, (duk_regconst_t) label_id); duk__emit_invalid(comp_ctx); duk__emit_invalid(comp_ctx); @@ -74225,10 +75523,10 @@ */ DUK_LOCAL void duk__parse_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_bool_t allow_source_elem) { duk_hthread *thr = comp_ctx->thr; - duk_bool_t dir_prol_at_entry; /* directive prologue status at entry */ + duk_bool_t dir_prol_at_entry; /* directive prologue status at entry */ duk_regconst_t temp_at_entry; duk_size_t labels_len_at_entry; - duk_int_t pc_at_entry; /* assumed to also be PC of "LABEL" */ + duk_int_t pc_at_entry; /* assumed to also be PC of "LABEL" */ duk_int_t stmt_id; duk_small_uint_t stmt_flags = 0; duk_int_t label_id = -1; @@ -74247,8 +75545,11 @@ DUK_DDD(DUK_DDDPRINT("parsing a statement, stmt_id=%ld, temp_at_entry=%ld, labels_len_at_entry=%ld, " "is_strict=%ld, in_directive_prologue=%ld, catch_depth=%ld", - (long) stmt_id, (long) temp_at_entry, (long) labels_len_at_entry, - (long) comp_ctx->curr_func.is_strict, (long) comp_ctx->curr_func.in_directive_prologue, + (long) stmt_id, + (long) temp_at_entry, + (long) labels_len_at_entry, + (long) comp_ctx->curr_func.is_strict, + (long) comp_ctx->curr_func.in_directive_prologue, (long) comp_ctx->curr_func.catch_depth)); /* The directive prologue flag is cleared by default so that it is @@ -74258,10 +75559,12 @@ */ comp_ctx->curr_func.in_directive_prologue = 0; - retry_parse: +retry_parse: DUK_DDD(DUK_DDDPRINT("try stmt parse, stmt_id=%ld, label_id=%ld, allow_source_elem=%ld, catch_depth=%ld", - (long) stmt_id, (long) label_id, (long) allow_source_elem, + (long) stmt_id, + (long) label_id, + (long) allow_source_elem, (long) comp_ctx->curr_func.catch_depth)); /* @@ -74270,15 +75573,11 @@ */ tok = comp_ctx->curr_token.t; - if (tok == DUK_TOK_FOR || tok == DUK_TOK_DO || tok == DUK_TOK_WHILE || - tok == DUK_TOK_SWITCH) { + if (tok == DUK_TOK_FOR || tok == DUK_TOK_DO || tok == DUK_TOK_WHILE || tok == DUK_TOK_SWITCH) { DUK_DDD(DUK_DDDPRINT("iteration/switch statement -> add empty label")); label_id = duk__stmt_label_site(comp_ctx, label_id); - duk__add_label(comp_ctx, - DUK_HTHREAD_STRING_EMPTY_STRING(thr), - pc_at_entry /*pc_label*/, - label_id); + duk__add_label(comp_ctx, DUK_HTHREAD_STRING_EMPTY_STRING(thr), pc_at_entry /*pc_label*/, label_id); } /* @@ -74305,10 +75604,8 @@ * strict and non-strict modes. However, don't allow labelled * function declarations in strict mode. */ - test_func_decl = test_func_decl || - !comp_ctx->curr_func.is_strict || - label_id < 0; -#endif /* DUK_USE_NONSTD_FUNC_STMT */ + test_func_decl = test_func_decl || !comp_ctx->curr_func.is_strict || label_id < 0; +#endif /* DUK_USE_NONSTD_FUNC_STMT */ /* Strict: never allow function declarations outside top level. */ if (test_func_decl) { /* FunctionDeclaration: not strictly a statement but handled as such. @@ -74330,7 +75627,7 @@ top_before = duk_get_top(thr); #endif - duk__advance(comp_ctx); /* eat 'function' */ + duk__advance(comp_ctx); /* eat 'function' */ fnum = duk__parse_func_like_fnum(comp_ctx, DUK__FUNC_FLAG_DECL | DUK__FUNC_FLAG_PUSHNAME_PASS1); /* The value stack convention here is a bit odd: the function @@ -74344,7 +75641,8 @@ DUK_ASSERT(duk_get_top(thr) == top_before + 1); #endif DUK_DDD(DUK_DDDPRINT("register function declaration %!T in pass 1, fnum %ld", - duk_get_tval(thr, -1), (long) fnum)); + duk_get_tval(thr, -1), + (long) fnum)); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); /* funcname is at index -1 */ duk_put_prop_index(thr, comp_ctx->curr_func.decls_idx, n); @@ -74371,7 +75669,7 @@ duk__parse_stmts(comp_ctx, 0 /*allow_source_elem*/, 0 /*expect_eof*/, 1 /*regexp_after*/); /* the DUK_TOK_RCURLY is eaten by duk__parse_stmts() */ if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } stmt_flags = 0; break; @@ -74398,7 +75696,7 @@ DUK_DDD(DUK_DDDPRINT("if statement")); duk__parse_if_stmt(comp_ctx, res); if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } stmt_flags = 0; break; @@ -74415,19 +75713,15 @@ */ DUK_DDD(DUK_DDDPRINT("do statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_do_stmt(comp_ctx, res, pc_at_entry); - stmt_flags = DUK__HAS_TERM | DUK__ALLOW_AUTO_SEMI_ALWAYS; /* DUK__ALLOW_AUTO_SEMI_ALWAYS workaround */ + stmt_flags = DUK__HAS_TERM | DUK__ALLOW_AUTO_SEMI_ALWAYS; /* DUK__ALLOW_AUTO_SEMI_ALWAYS workaround */ break; } case DUK_TOK_WHILE: { DUK_DDD(DUK_DDDPRINT("while statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_while_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -74442,9 +75736,7 @@ */ DUK_DDD(DUK_DDDPRINT("for/for-in statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK | DUK_LABEL_FLAG_ALLOW_CONTINUE); duk__parse_for_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -74467,7 +75759,7 @@ comp_ctx->curr_func.with_depth++; duk__parse_with_stmt(comp_ctx, res); if (label_id >= 0) { - duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ + duk__patch_jump_here(comp_ctx, pc_at_entry + 1); /* break jump */ } comp_ctx->curr_func.with_depth--; stmt_flags = 0; @@ -74480,9 +75772,7 @@ */ DUK_DDD(DUK_DDDPRINT("switch statement")); DUK_ASSERT(label_id >= 0); - duk__update_label_flags(comp_ctx, - label_id, - DUK_LABEL_FLAG_ALLOW_BREAK); /* don't allow continue */ + duk__update_label_flags(comp_ctx, label_id, DUK_LABEL_FLAG_ALLOW_BREAK); /* don't allow continue */ duk__parse_switch_stmt(comp_ctx, res, pc_at_entry); stmt_flags = 0; break; @@ -74549,12 +75839,10 @@ DUK_DDD(DUK_DDDPRINT("expression statement")); duk__exprtop(comp_ctx, res, DUK__BP_FOR_EXPR /*rbp_flags*/); - single_token = (comp_ctx->curr_func.nud_count == 1 && /* one token */ - comp_ctx->curr_func.led_count == 0); /* no operators */ + single_token = (comp_ctx->curr_func.nud_count == 1 && /* one token */ + comp_ctx->curr_func.led_count == 0); /* no operators */ - if (single_token && - comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && - comp_ctx->curr_token.t == DUK_TOK_COLON) { + if (single_token && comp_ctx->prev_token.t == DUK_TOK_IDENTIFIER && comp_ctx->curr_token.t == DUK_TOK_COLON) { /* * Detected label */ @@ -74568,17 +75856,13 @@ h_lab = comp_ctx->prev_token.str1; DUK_ASSERT(h_lab != NULL); - DUK_DDD(DUK_DDDPRINT("explicit label site for label '%!O'", - (duk_heaphdr *) h_lab)); + DUK_DDD(DUK_DDDPRINT("explicit label site for label '%!O'", (duk_heaphdr *) h_lab)); - duk__advance(comp_ctx); /* eat colon */ + duk__advance(comp_ctx); /* eat colon */ label_id = duk__stmt_label_site(comp_ctx, label_id); - duk__add_label(comp_ctx, - h_lab, - pc_at_entry /*pc_label*/, - label_id); + duk__add_label(comp_ctx, h_lab, pc_at_entry /*pc_label*/, label_id); /* a statement following a label cannot be a source element * (a function declaration). @@ -74591,8 +75875,8 @@ stmt_flags = 0; - if (dir_prol_at_entry && /* still in prologue */ - single_token && /* single string token */ + if (dir_prol_at_entry && /* still in prologue */ + single_token && /* single string token */ comp_ctx->prev_token.t == DUK_TOK_STRING) { /* * Detected a directive @@ -74625,7 +75909,8 @@ DUK_STRCMP((const char *) DUK_HSTRING_GET_DATA(h_dir), "use strict") == 0) { #if defined(DUK_USE_STRICT_DECL) DUK_DDD(DUK_DDDPRINT("use strict directive detected: strict flag %ld -> %ld", - (long) comp_ctx->curr_func.is_strict, (long) 1)); + (long) comp_ctx->curr_func.is_strict, + (long) 1)); comp_ctx->curr_func.is_strict = 1; #else DUK_DDD(DUK_DDDPRINT("use strict detected but strict declarations disabled, ignoring")); @@ -74633,21 +75918,23 @@ } else if (DUK_HSTRING_GET_BYTELEN(h_dir) == 14 && DUK_STRCMP((const char *) DUK_HSTRING_GET_DATA(h_dir), "use duk notail") == 0) { DUK_DDD(DUK_DDDPRINT("use duk notail directive detected: notail flag %ld -> %ld", - (long) comp_ctx->curr_func.is_notail, (long) 1)); + (long) comp_ctx->curr_func.is_notail, + (long) 1)); comp_ctx->curr_func.is_notail = 1; } else { DUK_DD(DUK_DDPRINT("unknown directive: '%!O', ignoring but not terminating " - "directive prologue", (duk_hobject *) h_dir)); + "directive prologue", + (duk_hobject *) h_dir)); } } } else { DUK_DDD(DUK_DDDPRINT("non-directive expression statement or no longer in prologue; " "prologue terminated if still active")); - } + } stmt_flags |= DUK__HAS_VAL | DUK__HAS_TERM; } - } /* end switch (tok) */ + } /* end switch (tok) */ /* * Statement value handling. @@ -74723,9 +76010,7 @@ */ if (label_id >= 0) { - duk__emit_bc(comp_ctx, - DUK_OP_ENDLABEL, - (duk_regconst_t) label_id); + duk__emit_bc(comp_ctx, DUK_OP_ENDLABEL, (duk_regconst_t) label_id); } DUK__SETTEMP(comp_ctx, temp_at_entry); @@ -74748,7 +76033,10 @@ * (EOF or closing brace). */ -DUK_LOCAL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, duk_bool_t allow_source_elem, duk_bool_t expect_eof, duk_bool_t regexp_after) { +DUK_LOCAL void duk__parse_stmts(duk_compiler_ctx *comp_ctx, + duk_bool_t allow_source_elem, + duk_bool_t expect_eof, + duk_bool_t regexp_after) { duk_hthread *thr = comp_ctx->thr; duk_ivalue res_alloc; duk_ivalue *res = &res_alloc; @@ -74914,7 +76202,7 @@ /* only functions can have arguments */ DUK_ASSERT(comp_ctx->curr_func.is_function); - duk_push_uarridx(thr, i); /* -> ... name index */ + duk_push_uarridx(thr, i); /* -> ... name index */ duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* -> ... */ /* no code needs to be emitted, the regs already have values */ @@ -74950,16 +76238,15 @@ */ num_decls = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.decls_idx); - DUK_DDD(DUK_DDDPRINT("num_decls=%ld -> %!T", - (long) num_decls, - (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.decls_idx))); + DUK_DDD( + DUK_DDDPRINT("num_decls=%ld -> %!T", (long) num_decls, (duk_tval *) duk_get_tval(thr, comp_ctx->curr_func.decls_idx))); for (i = 0; i < num_decls; i += 2) { duk_int_t decl_type; duk_int_t fnum; - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ decl_type = duk_to_int(thr, -1); - fnum = decl_type >> 8; /* XXX: macros */ + fnum = decl_type >> 8; /* XXX: macros */ decl_type = decl_type & 0xff; duk_pop(thr); @@ -74967,7 +76254,7 @@ continue; } - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ /* XXX: spilling */ if (comp_ctx->curr_func.is_function) { @@ -74977,18 +76264,12 @@ /* shadowed; update value */ duk_dup_top(thr); duk_get_prop(thr, comp_ctx->curr_func.varmap_idx); - reg_bind = duk_to_int(thr, -1); /* ... name reg_bind */ - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_bind, - (duk_regconst_t) fnum); + reg_bind = duk_to_int(thr, -1); /* ... name reg_bind */ + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_bind, (duk_regconst_t) fnum); } else { /* function: always register bound */ reg_bind = DUK__ALLOCTEMP(comp_ctx); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_bind, - (duk_regconst_t) fnum); + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_bind, (duk_regconst_t) fnum); duk_push_int(thr, (duk_int_t) reg_bind); } } else { @@ -75005,14 +76286,9 @@ rc_name = duk__getconst(comp_ctx); duk_push_null(thr); - duk__emit_a_bc(comp_ctx, - DUK_OP_CLOSURE, - reg_temp, - (duk_regconst_t) fnum); - - declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE | - DUK_BC_DECLVAR_FLAG_FUNC_DECL; + duk__emit_a_bc(comp_ctx, DUK_OP_CLOSURE, reg_temp, (duk_regconst_t) fnum); + + declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE | DUK_BC_DECLVAR_FLAG_FUNC_DECL; if (configurable_bindings) { declvar_flags |= DUK_PROPDESC_FLAG_CONFIGURABLE; @@ -75024,7 +76300,7 @@ rc_name /*name*/, reg_temp /*value*/); - DUK__SETTEMP(comp_ctx, reg_temp); /* forget temp */ + DUK__SETTEMP(comp_ctx, reg_temp); /* forget temp */ } DUK_DDD(DUK_DDDPRINT("function declaration to varmap: %!T -> %!T", @@ -75034,7 +76310,7 @@ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_NULL(duk_get_tval(thr, -1)) || DUK_TVAL_IS_FASTINT(duk_get_tval(thr, -1))); #endif - duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ + duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ } /* @@ -75061,7 +76337,7 @@ for (i = 0; i < num_decls; i += 2) { duk_int_t decl_type; - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i + 1); /* decl type */ decl_type = duk_to_int(thr, -1); decl_type = decl_type & 0xff; duk_pop(thr); @@ -75070,16 +76346,15 @@ continue; } - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ if (duk_has_prop(thr, comp_ctx->curr_func.varmap_idx)) { /* shadowed, ignore */ } else { - duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ + duk_get_prop_index(thr, comp_ctx->curr_func.decls_idx, i); /* decl name */ h_name = duk_known_hstring(thr, -1); - if (h_name == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr) && - !comp_ctx->curr_func.is_arguments_shadowed) { + if (h_name == DUK_HTHREAD_STRING_LC_ARGUMENTS(thr) && !comp_ctx->curr_func.is_arguments_shadowed) { /* E5 Section steps 7-8 */ DUK_DDD(DUK_DDDPRINT("'arguments' not shadowed by a function declaration, " "but appears as a variable declaration -> treat as " @@ -75098,8 +76373,7 @@ rc_name = duk__getconst(comp_ctx); duk_push_null(thr); - declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | - DUK_PROPDESC_FLAG_ENUMERABLE; + declvar_flags = DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_ENUMERABLE; if (configurable_bindings) { declvar_flags |= DUK_PROPDESC_FLAG_CONFIGURABLE; } @@ -75111,7 +76385,7 @@ 0 /*value*/); } - duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ + duk_put_prop(thr, comp_ctx->curr_func.varmap_idx); /* ... name reg/null -> ... */ } } @@ -75126,11 +76400,11 @@ DUK_ASSERT_TOP(thr, entry_top); return; - error_outofregs: +error_outofregs: DUK_ERROR_RANGE(thr, DUK_STR_REG_LIMIT); DUK_WO_NORETURN(return;); - error_argname: +error_argname: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_ARG_NAME); DUK_WO_NORETURN(return;); } @@ -75169,7 +76443,11 @@ * token (EOF or closing brace). */ -DUK_LOCAL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, duk_bool_t expect_eof, duk_bool_t implicit_return_value, duk_bool_t regexp_after, duk_small_int_t expect_token) { +DUK_LOCAL void duk__parse_func_body(duk_compiler_ctx *comp_ctx, + duk_bool_t expect_eof, + duk_bool_t implicit_return_value, + duk_bool_t regexp_after, + duk_small_int_t expect_token) { duk_compiler_func *func; duk_hthread *thr; duk_regconst_t reg_stmt_value = -1; @@ -75261,8 +76539,8 @@ DUK_DDD(DUK_DDDPRINT("begin 1st pass")); duk__parse_stmts(comp_ctx, - 1, /* allow source elements */ - expect_eof, /* expect EOF instead of } */ + 1, /* allow source elements */ + expect_eof, /* expect EOF instead of } */ regexp_after); /* regexp after */ DUK_DDD(DUK_DDDPRINT("end 1st pass")); @@ -75291,8 +76569,8 @@ DUK_DDD(DUK_DDDPRINT("rewind lexer")); DUK_LEXER_SETPOINT(&comp_ctx->lex, &lex_pt); - comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ duk__advance(comp_ctx); /* @@ -75313,8 +76591,7 @@ /* must be able to emit code, alloc consts, etc. */ - duk__init_varmap_and_prologue_for_pass2(comp_ctx, - (implicit_return_value ? ®_stmt_value : NULL)); + duk__init_varmap_and_prologue_for_pass2(comp_ctx, (implicit_return_value ? ®_stmt_value : NULL)); func->reg_stmt_value = reg_stmt_value; temp_first = DUK__GETTEMP(comp_ctx); @@ -75362,15 +76639,13 @@ if (implicit_return_value) { /* Default implicit return value. */ - duk__emit_bc(comp_ctx, - DUK_OP_LDUNDEF, - 0); + duk__emit_bc(comp_ctx, DUK_OP_LDUNDEF, 0); } DUK_DDD(DUK_DDDPRINT("begin 2nd pass")); duk__parse_stmts(comp_ctx, - 1, /* allow source elements */ - expect_eof, /* expect EOF instead of } */ + 1, /* allow source elements */ + expect_eof, /* expect EOF instead of } */ regexp_after); /* regexp after */ DUK_DDD(DUK_DDDPRINT("end 2nd pass")); @@ -75426,7 +76701,7 @@ DUK__RECURSION_DECREASE(comp_ctx, thr); return; - error_funcname: +error_funcname: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_FUNC_NAME); DUK_WO_NORETURN(return;); } @@ -75481,15 +76756,14 @@ } DUK_ASSERT(comp_ctx->curr_token.t == DUK_TOK_IDENTIFIER); DUK_ASSERT(comp_ctx->curr_token.str1 != NULL); - DUK_DDD(DUK_DDDPRINT("formal argument: %!O", - (duk_heaphdr *) comp_ctx->curr_token.str1)); + DUK_DDD(DUK_DDDPRINT("formal argument: %!O", (duk_heaphdr *) comp_ctx->curr_token.str1)); /* XXX: append primitive */ duk_push_hstring(thr, comp_ctx->curr_token.str1); n = (duk_uarridx_t) duk_get_length(thr, comp_ctx->curr_func.argnames_idx); duk_put_prop_index(thr, comp_ctx->curr_func.argnames_idx, n); - duk__advance(comp_ctx); /* eat identifier */ + duk__advance(comp_ctx); /* eat identifier */ } } @@ -75537,7 +76811,7 @@ if (flags & DUK__FUNC_FLAG_GETSET) { /* PropertyName -> IdentifierName | StringLiteral | NumericLiteral */ if (tok->t_nores == DUK_TOK_IDENTIFIER || tok->t == DUK_TOK_STRING) { - duk_push_hstring(thr, tok->str1); /* keep in valstack */ + duk_push_hstring(thr, tok->str1); /* keep in valstack */ } else if (tok->t == DUK_TOK_NUMBER) { duk_push_number(thr, tok->num); duk_to_string(thr, -1); @@ -75545,15 +76819,15 @@ DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_GETSET_NAME); DUK_WO_NORETURN(return;); } - comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ + comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ } else { /* Function name is an Identifier (not IdentifierName), but we get * the raw name (not recognizing keywords) here and perform the name * checks only after pass 1. */ if (tok->t_nores == DUK_TOK_IDENTIFIER) { - duk_push_hstring(thr, tok->str1); /* keep in valstack */ - comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ + duk_push_hstring(thr, tok->str1); /* keep in valstack */ + comp_ctx->curr_func.h_name = duk_known_hstring(thr, -1); /* borrowed reference */ } else { /* valstack will be unbalanced, which is OK */ DUK_ASSERT((flags & DUK__FUNC_FLAG_GETSET) == 0); @@ -75566,8 +76840,7 @@ } } - DUK_DD(DUK_DDPRINT("function name: %!O", - (duk_heaphdr *) comp_ctx->curr_func.h_name)); + DUK_DD(DUK_DDPRINT("function name: %!O", (duk_heaphdr *) comp_ctx->curr_func.h_name)); if (!no_advance) { duk__advance(comp_ctx); @@ -75593,17 +76866,17 @@ */ duk__parse_func_body(comp_ctx, - 0, /* expect_eof */ - 0, /* implicit_return_value */ + 0, /* expect_eof */ + 0, /* implicit_return_value */ flags & DUK__FUNC_FLAG_DECL, /* regexp_after */ - DUK_TOK_LCURLY); /* expect_token */ + DUK_TOK_LCURLY); /* expect_token */ /* * Convert duk_compiler_func to a function template and add it * to the parent function table. */ - duk__convert_to_func_template(comp_ctx); /* -> ... func */ + duk__convert_to_func_template(comp_ctx); /* -> ... func */ } /* Parse an inner function, adding the function template to the current function's @@ -75641,12 +76914,14 @@ lex_pt.line = duk_to_int(thr, -1); duk_pop(thr); - DUK_DDD(DUK_DDDPRINT("second pass of an inner func, skip the function, reparse closing brace; lex offset=%ld, line=%ld", - (long) lex_pt.offset, (long) lex_pt.line)); + DUK_DDD( + DUK_DDDPRINT("second pass of an inner func, skip the function, reparse closing brace; lex offset=%ld, line=%ld", + (long) lex_pt.offset, + (long) lex_pt.line)); DUK_LEXER_SETPOINT(&comp_ctx->lex, &lex_pt); - comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + comp_ctx->curr_token.t = 0; /* this is needed for regexp mode */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ duk__advance(comp_ctx); /* RegExp is not allowed after a function expression, e.g. in @@ -75668,7 +76943,8 @@ entry_top = duk_get_top(thr); DUK_DDD(DUK_DDDPRINT("before func: entry_top=%ld, curr_tok.start_offset=%ld", - (long) entry_top, (long) comp_ctx->curr_token.start_offset)); + (long) entry_top, + (long) comp_ctx->curr_token.start_offset)); duk_memcpy(&old_func, &comp_ctx->curr_func, sizeof(duk_compiler_func)); @@ -75688,24 +76964,25 @@ DUK_ASSERT(comp_ctx->curr_func.is_eval == 0); DUK_ASSERT(comp_ctx->curr_func.is_global == 0); comp_ctx->curr_func.is_setget = ((flags & DUK__FUNC_FLAG_GETSET) != 0); - comp_ctx->curr_func.is_namebinding = !(flags & (DUK__FUNC_FLAG_GETSET | - DUK__FUNC_FLAG_METDEF | - DUK__FUNC_FLAG_DECL)); /* no name binding for: declarations, objlit getset, objlit method def */ - comp_ctx->curr_func.is_constructable = !(flags & (DUK__FUNC_FLAG_GETSET | - DUK__FUNC_FLAG_METDEF)); /* not constructable: objlit getset, objlit method def */ + comp_ctx->curr_func.is_namebinding = + !(flags & (DUK__FUNC_FLAG_GETSET | DUK__FUNC_FLAG_METDEF | + DUK__FUNC_FLAG_DECL)); /* no name binding for: declarations, objlit getset, objlit method def */ + comp_ctx->curr_func.is_constructable = + !(flags & (DUK__FUNC_FLAG_GETSET | DUK__FUNC_FLAG_METDEF)); /* not constructable: objlit getset, objlit method def */ /* * Parse inner function */ - duk__parse_func_like_raw(comp_ctx, flags); /* pushes function template */ + duk__parse_func_like_raw(comp_ctx, flags); /* pushes function template */ /* prev_token.start_offset points to the closing brace here; when skipping * we're going to reparse the closing brace to ensure semicolon insertion * etc work as expected. */ DUK_DDD(DUK_DDDPRINT("after func: prev_tok.start_offset=%ld, curr_tok.start_offset=%ld", - (long) comp_ctx->prev_token.start_offset, (long) comp_ctx->curr_token.start_offset)); + (long) comp_ctx->prev_token.start_offset, + (long) comp_ctx->curr_token.start_offset)); DUK_ASSERT(comp_ctx->lex.inputcomp_ctx->prev_token.start_offset == (duk_uint8_t) DUK_ASC_RCURLY); /* XXX: append primitive */ @@ -75791,7 +77068,7 @@ is_strict = (flags & DUK_COMPILE_STRICT ? 1 : 0); is_funcexpr = (flags & DUK_COMPILE_FUNCEXPR ? 1 : 0); - h_filename = duk_get_hstring(thr, -1); /* may be undefined */ + h_filename = duk_get_hstring(thr, -1); /* may be undefined */ /* * Init compiler and lexer contexts @@ -75809,11 +77086,11 @@ duk_require_stack(thr, DUK__COMPILE_ENTRY_SLOTS); - duk_push_dynamic_buffer(thr, 0); /* entry_top + 0 */ - duk_push_undefined(thr); /* entry_top + 1 */ - duk_push_undefined(thr); /* entry_top + 2 */ - duk_push_undefined(thr); /* entry_top + 3 */ - duk_push_undefined(thr); /* entry_top + 4 */ + duk_push_dynamic_buffer(thr, 0); /* entry_top + 0 */ + duk_push_undefined(thr); /* entry_top + 1 */ + duk_push_undefined(thr); /* entry_top + 2 */ + duk_push_undefined(thr); /* entry_top + 3 */ + duk_push_undefined(thr); /* entry_top + 4 */ comp_ctx->thr = thr; comp_ctx->h_filename = h_filename; @@ -75837,8 +77114,8 @@ lex_pt->offset = 0; lex_pt->line = 1; - DUK_LEXER_SETPOINT(&comp_ctx->lex, lex_pt); /* fills window */ - comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ + DUK_LEXER_SETPOINT(&comp_ctx->lex, lex_pt); /* fills window */ + comp_ctx->curr_token.start_line = 0; /* needed for line number tracking (becomes prev_token.start_line) */ /* * Initialize function state for a zero-argument function @@ -75854,8 +77131,7 @@ */ DUK_ASSERT(func->h_name == NULL); } else { - duk_push_hstring_stridx(thr, (is_eval ? DUK_STRIDX_EVAL : - DUK_STRIDX_GLOBAL)); + duk_push_hstring_stridx(thr, (is_eval ? DUK_STRIDX_EVAL : DUK_STRIDX_GLOBAL)); func->h_name = duk_get_hstring(thr, -1); } @@ -75875,7 +77151,7 @@ func->is_namebinding = 1; func->is_constructable = 1; - duk__advance(comp_ctx); /* init 'curr_token' */ + duk__advance(comp_ctx); /* init 'curr_token' */ duk__advance_expect(comp_ctx, DUK_TOK_FUNCTION); (void) duk__parse_func_like_raw(comp_ctx, 0 /*flags*/); } else { @@ -75887,10 +77163,10 @@ DUK_ASSERT(func->is_constructable == 0); duk__parse_func_body(comp_ctx, - 1, /* expect_eof */ - 1, /* implicit_return_value */ - 1, /* regexp_after (does not matter) */ - -1); /* expect_token */ + 1, /* expect_eof */ + 1, /* implicit_return_value */ + 1, /* regexp_after (does not matter) */ + -1); /* expect_token */ } /* @@ -75922,14 +77198,14 @@ DUK_LEXER_INITCTX(&comp_stk.comp_ctx_alloc.lex); comp_stk.comp_ctx_alloc.lex.input = src_buffer; comp_stk.comp_ctx_alloc.lex.input_length = src_length; - comp_stk.comp_ctx_alloc.lex.flags = flags; /* Forward flags directly for now. */ + comp_stk.comp_ctx_alloc.lex.flags = flags; /* Forward flags directly for now. */ /* ... filename */ prev_ctx = thr->compile_ctx; - thr->compile_ctx = &comp_stk.comp_ctx_alloc; /* for duk_error_augment.c */ + thr->compile_ctx = &comp_stk.comp_ctx_alloc; /* for duk_error_augment.c */ safe_rc = duk_safe_call(thr, duk__js_compile_raw, (void *) &comp_stk /*udata*/, 1 /*nargs*/, 1 /*nrets*/); - thr->compile_ctx = prev_ctx; /* must restore reliably before returning */ + thr->compile_ctx = prev_ctx; /* must restore reliably before returning */ if (safe_rc != DUK_EXEC_SUCCESS) { DUK_D(DUK_DPRINT("compilation failed: %!T", duk_get_tval(thr, -1))); @@ -76044,7 +77320,8 @@ /* Replace value stack top to value at 'tv_ptr'. Optimize for * performance by only applying the net refcount change. */ -#define DUK__REPLACE_TO_TVPTR(thr,tv_ptr) do { \ +#define DUK__REPLACE_TO_TVPTR(thr, tv_ptr) \ + do { \ duk_hthread *duk__thr; \ duk_tval *duk__tvsrc; \ duk_tval *duk__tvdst; \ @@ -76054,13 +77331,13 @@ duk__tvdst = (tv_ptr); \ DUK_TVAL_SET_TVAL(&duk__tvtmp, duk__tvdst); \ DUK_TVAL_SET_TVAL(duk__tvdst, duk__tvsrc); \ - DUK_TVAL_SET_UNDEFINED(duk__tvsrc); /* value stack init policy */ \ + DUK_TVAL_SET_UNDEFINED(duk__tvsrc); /* value stack init policy */ \ duk__thr->valstack_top = duk__tvsrc; \ DUK_TVAL_DECREF(duk__thr, &duk__tvtmp); \ } while (0) /* XXX: candidate of being an internal shared API call */ -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__push_tvals_incref_only(duk_hthread *thr, duk_tval *tv_src, duk_small_uint_fast_t count) { duk_tval *tv_dst; duk_size_t copy_size; @@ -76102,7 +77379,10 @@ } #endif -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_add(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_fast_t idx_z) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_add(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_small_uint_fast_t idx_z) { /* * Addition operator is different from other arithmetic * operations in that it also provides string concatenation. @@ -76122,9 +77402,9 @@ duk_double_union du; DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); /* @@ -76147,14 +77427,14 @@ v3_hi = (duk_int32_t) (v3 >> 32); if (DUK_LIKELY(v3_hi >= DUK_I64_CONSTANT(-0x8000) && v3_hi <= DUK_I64_CONSTANT(0x7fff))) { tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ return; } else { /* overflow, fall through */ ; } } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { #if !defined(DUK_USE_EXEC_PREFER_SIZE) @@ -76163,14 +77443,14 @@ du.d = DUK_TVAL_GET_NUMBER(tv_x) + DUK_TVAL_GET_NUMBER(tv_y); #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ return; } @@ -76180,7 +77460,7 @@ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -2, DUK_HINT_NONE); /* side effects -> don't use tv_x, tv_y after */ + duk_to_primitive(thr, -2, DUK_HINT_NONE); /* side effects -> don't use tv_x, tv_y after */ duk_to_primitive(thr, -1, DUK_HINT_NONE); /* Since Duktape 2.x plain buffers are treated like ArrayBuffer. */ @@ -76191,7 +77471,7 @@ * in duk_concat_2() which also fails with TypeError so no * explicit check is needed. */ - duk_concat_2(thr); /* ... s1 s2 -> ... s1+s2 */ + duk_concat_2(thr); /* ... s1 s2 -> ... s1+s2 */ } else { duk_double_t d1, d2; @@ -76204,12 +77484,16 @@ du.d = d1 + d2; duk_pop_2_unsafe(thr); - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ } - duk_replace(thr, (duk_idx_t) idx_z); /* side effects */ + duk_replace(thr, (duk_idx_t) idx_z); /* side effects */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_binary_op(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_uint_fast_t idx_z, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_binary_op(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_uint_fast_t idx_z, + duk_small_uint_fast_t opcode) { /* * Arithmetic operations other than '+' have number-only semantics * and are implemented here. The separate switch-case here means a @@ -76226,12 +77510,12 @@ #endif DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); - opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ + opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y)) { @@ -76298,13 +77582,13 @@ v3_hi = (duk_int32_t) (v3 >> 32); if (DUK_LIKELY(v3_hi >= DUK_I64_CONSTANT(-0x8000) && v3_hi <= DUK_I64_CONSTANT(0x7fff))) { tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, v3); /* side effects */ return; } /* fall through if overflow etc */ } - skip_fastint: -#endif /* DUK_USE_FASTINT */ +skip_fastint: +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { /* fast path */ @@ -76313,7 +77597,7 @@ } else { duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - d1 = duk_to_number_m2(thr); /* side effects */ + d1 = duk_to_number_m2(thr); /* side effects */ d2 = duk_to_number_m1(thr); DUK_ASSERT(duk_is_number(thr, -2)); DUK_ASSERT(duk_is_number(thr, -1)); @@ -76350,24 +77634,28 @@ #endif default: { DUK_UNREACHABLE(); - du.d = DUK_DOUBLE_NAN; /* should not happen */ + du.d = DUK_DOUBLE_NAN; /* should not happen */ break; } } #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, du.d); /* will NaN normalize result */ + duk_push_number(thr, du.d); /* will NaN normalize result */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ /* important to use normalized NaN with 8-byte tagged types */ DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, du.d); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_bitwise_binary_op(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_fast_t idx_z, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_bitwise_binary_op(duk_hthread *thr, + duk_tval *tv_x, + duk_tval *tv_y, + duk_small_uint_fast_t idx_z, + duk_small_uint_fast_t opcode) { /* * Binary bitwise operations use different coercions (ToInt32, ToUint32) * depending on the operation. We coerce the arguments first using @@ -76391,20 +77679,19 @@ #endif DUK_ASSERT(thr != NULL); - DUK_ASSERT(tv_x != NULL); /* may be reg or const */ - DUK_ASSERT(tv_y != NULL); /* may be reg or const */ - DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ + DUK_ASSERT(tv_x != NULL); /* may be reg or const */ + DUK_ASSERT(tv_y != NULL); /* may be reg or const */ + DUK_ASSERT_DISABLE(idx_z >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) idx_z < (duk_uint_t) duk_get_top(thr)); - opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ + opcode_shifted = opcode >> 2; /* Get base opcode without reg/const modifiers. */ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y)) { i1 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv_x); i2 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv_y); - } - else -#endif /* DUK_USE_FASTINT */ + } else +#endif /* DUK_USE_FASTINT */ { duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); @@ -76433,15 +77720,15 @@ */ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; - i3 = (duk_int32_t) (((duk_uint32_t) i1) << (u2 & 0x1fUL)); /* E5 Section 11.7.1, steps 7 and 8 */ - i3 = i3 & ((duk_int32_t) 0xffffffffUL); /* Note: left shift, should mask */ + i3 = (duk_int32_t) (((duk_uint32_t) i1) << (u2 & 0x1fUL)); /* E5 Section 11.7.1, steps 7 and 8 */ + i3 = i3 & ((duk_int32_t) 0xffffffffUL); /* Note: left shift, should mask */ break; } case DUK_OP_BASR >> 2: { /* signed shift */ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; - i3 = i1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ + i3 = i1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ break; } case DUK_OP_BLSR >> 2: { @@ -76451,7 +77738,7 @@ u2 = ((duk_uint32_t) i2) & 0xffffffffUL; /* special result value handling */ - u3 = u1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ + u3 = u1 >> (u2 & 0x1fUL); /* E5 Section 11.7.2, steps 7 and 8 */ #if defined(DUK_USE_FASTINT) fi3 = (duk_int64_t) u3; goto fastint_result_set; @@ -76462,7 +77749,7 @@ } default: { DUK_UNREACHABLE(); - i3 = 0; /* should not happen */ + i3 = 0; /* should not happen */ break; } } @@ -76474,28 +77761,31 @@ */ fi3 = (duk_int64_t) i3; - fastint_result_set: +fastint_result_set: tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, fi3); /* side effects */ -#else /* DUK_USE_FASTINT */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_z, fi3); /* side effects */ +#else /* DUK_USE_FASTINT */ d3 = (duk_double_t) i3; - result_set: - DUK_ASSERT(!DUK_ISNAN(d3)); /* 'd3' is never NaN, so no need to normalize */ - DUK_ASSERT_DOUBLE_IS_NORMALIZED(d3); /* always normalized */ +result_set: + DUK_ASSERT(!DUK_ISNAN(d3)); /* 'd3' is never NaN, so no need to normalize */ + DUK_ASSERT_DOUBLE_IS_NORMALIZED(d3); /* always normalized */ #if defined(DUK_USE_EXEC_PREFER_SIZE) - duk_push_number(thr, d3); /* would NaN normalize result, but unnecessary */ + duk_push_number(thr, d3); /* would NaN normalize result, but unnecessary */ duk_replace(thr, (duk_idx_t) idx_z); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ tv_z = thr->valstack_bottom + idx_z; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, d3); /* side effects */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ -#endif /* DUK_USE_FASTINT */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_z, d3); /* side effects */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_FASTINT */ } /* In-place unary operation. */ -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_unary_op(duk_hthread *thr, duk_uint_fast_t idx_src, duk_uint_fast_t idx_dst, duk_small_uint_fast_t opcode) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_arith_unary_op(duk_hthread *thr, + duk_uint_fast_t idx_src, + duk_uint_fast_t idx_dst, + duk_small_uint_fast_t opcode) { /* * Arithmetic operations other than '+' have number-only semantics * and are implemented here. The separate switch-case here means a @@ -76541,12 +77831,12 @@ } /* fall through if overflow etc */ } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ if (DUK_TVAL_IS_NUMBER(tv)) { d1 = DUK_TVAL_GET_NUMBER(tv); } else { - d1 = duk_to_number_tval(thr, tv); /* side effects */ + d1 = duk_to_number_tval(thr, tv); /* side effects */ } if (opcode == DUK_OP_UNP) { @@ -76557,13 +77847,13 @@ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); #if defined(DUK_USE_FASTINT) tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); - DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF(thr, tv, du.d); /* always 'fast', i.e. inlined */ + DUK_TVAL_SET_NUMBER_CHKFAST_UPDREF(thr, tv, du.d); /* always 'fast', i.e. inlined */ return; #endif } else { DUK_ASSERT(opcode == DUK_OP_UNM); du.d = -d1; - DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); /* mandatory if du.d is a NaN */ + DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du); /* mandatory if du.d is a NaN */ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du)); } @@ -76591,19 +77881,18 @@ #if defined(DUK_USE_FASTINT) if (DUK_TVAL_IS_FASTINT(tv)) { i1 = (duk_int32_t) DUK_TVAL_GET_FASTINT_I32(tv); - } - else -#endif /* DUK_USE_FASTINT */ + } else +#endif /* DUK_USE_FASTINT */ { duk_push_tval(thr, tv); - i1 = duk_to_int32(thr, -1); /* side effects */ + i1 = duk_to_int32(thr, -1); /* side effects */ duk_pop_unsafe(thr); } /* Result is always fastint compatible. */ i2 = ~i1; tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); - DUK_TVAL_SET_I32_UPDREF(thr, tv, i2); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv, i2); /* side effects */ } DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__vm_logical_not(duk_hthread *thr, duk_uint_fast_t idx_src, duk_uint_fast_t idx_dst) { @@ -76625,16 +77914,19 @@ * duk_js_toboolean() and then push+replace to the result slot. */ tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_src); - res = duk_js_toboolean(tv); /* does not modify 'tv' */ + res = duk_js_toboolean(tv); /* does not modify 'tv' */ DUK_ASSERT(res == 0 || res == 1); res ^= 1; tv = DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst); /* XXX: size optimize: push+replace? */ - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, res); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv, res); /* side effects */ } /* XXX: size optimized variant */ -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_reg_helper(duk_hthread *thr, duk_tval *tv_dst, duk_tval *tv_src, duk_small_uint_t op) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_reg_helper(duk_hthread *thr, + duk_tval *tv_dst, + duk_tval *tv_src, + duk_small_uint_t op) { duk_double_t x, y, z; /* Two lowest bits of opcode are used to distinguish @@ -76661,13 +77953,13 @@ y_fi = x_fi + 1; } - DUK_TVAL_SET_FASTINT(tv_src, y_fi); /* no need for refcount update */ + DUK_TVAL_SET_FASTINT(tv_src, y_fi); /* no need for refcount update */ z_fi = (op & 0x02) ? x_fi : y_fi; - DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_dst, z_fi); /* side effects */ + DUK_TVAL_SET_FASTINT_UPDREF(thr, tv_dst, z_fi); /* side effects */ return; } - skip_fastint: +skip_fastint: #endif if (DUK_TVAL_IS_NUMBER(tv_src)) { /* Fast path for the case where the register @@ -76681,7 +77973,7 @@ y = x + 1.0; } - DUK_TVAL_SET_NUMBER(tv_src, y); /* no need for refcount update */ + DUK_TVAL_SET_NUMBER(tv_src, y); /* no need for refcount update */ } else { /* Preserve duk_tval pointer(s) across a potential valstack * resize by converting them into offsets temporarily. @@ -76690,8 +77982,8 @@ duk_size_t off_dst; off_dst = (duk_size_t) ((duk_uint8_t *) tv_dst - (duk_uint8_t *) thr->valstack_bottom); - bc = (duk_idx_t) (tv_src - thr->valstack_bottom); /* XXX: pass index explicitly? */ - tv_src = NULL; /* no longer referenced */ + bc = (duk_idx_t) (tv_src - thr->valstack_bottom); /* XXX: pass index explicitly? */ + tv_src = NULL; /* no longer referenced */ x = duk_to_number(thr, bc); if (op & 0x01) { @@ -76707,10 +77999,14 @@ } z = (op & 0x02) ? x : y; - DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_dst, z); /* side effects */ + DUK_TVAL_SET_NUMBER_UPDREF(thr, tv_dst, z); /* side effects */ } -DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_var_helper(duk_hthread *thr, duk_small_uint_t idx_dst, duk_tval *tv_id, duk_small_uint_t op, duk_small_uint_t is_strict) { +DUK_LOCAL DUK_EXEC_ALWAYS_INLINE_PERF void duk__prepost_incdec_var_helper(duk_hthread *thr, + duk_small_uint_t idx_dst, + duk_tval *tv_id, + duk_small_uint_t op, + duk_small_uint_t is_strict) { duk_activation *act; duk_double_t x, y; duk_hstring *name; @@ -76736,7 +78032,7 @@ name = DUK_TVAL_GET_STRING(tv_id); DUK_ASSERT(name != NULL); act = thr->callstack_curr; - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ /* XXX: Fastint fast path would be useful here. Also fastints * now lose their fastint status in current handling which is @@ -76753,22 +78049,22 @@ /* ... x this */ if (op & 0x02) { - duk_push_number(thr, y); /* -> ... x this y */ + duk_push_number(thr, y); /* -> ... x this y */ DUK_ASSERT(act == thr->callstack_curr); duk_js_putvar_activation(thr, act, name, DUK_GET_TVAL_NEGIDX(thr, -1), is_strict); - duk_pop_2_unsafe(thr); /* -> ... x */ + duk_pop_2_unsafe(thr); /* -> ... x */ } else { - duk_pop_2_unsafe(thr); /* -> ... */ - duk_push_number(thr, y); /* -> ... y */ + duk_pop_2_unsafe(thr); /* -> ... */ + duk_push_number(thr, y); /* -> ... y */ DUK_ASSERT(act == thr->callstack_curr); duk_js_putvar_activation(thr, act, name, DUK_GET_TVAL_NEGIDX(thr, -1), is_strict); } #if defined(DUK_USE_EXEC_PREFER_SIZE) duk_replace(thr, (duk_idx_t) idx_dst); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ DUK__REPLACE_TO_TVPTR(thr, DUK_GET_TVAL_POSIDX(thr, (duk_idx_t) idx_dst)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } /* @@ -76782,11 +78078,11 @@ * handled recursively. */ -#define DUK__LONGJMP_RESTART 0 /* state updated, restart bytecode execution */ -#define DUK__LONGJMP_RETHROW 1 /* exit bytecode executor by rethrowing an error to caller */ +#define DUK__LONGJMP_RESTART 0 /* state updated, restart bytecode execution */ +#define DUK__LONGJMP_RETHROW 1 /* exit bytecode executor by rethrowing an error to caller */ -#define DUK__RETHAND_RESTART 0 /* state updated, restart bytecode execution */ -#define DUK__RETHAND_FINISHED 1 /* exit bytecode execution with return value */ +#define DUK__RETHAND_RESTART 0 /* state updated, restart bytecode execution */ +#define DUK__RETHAND_FINISHED 1 /* exit bytecode execution with return value */ /* XXX: optimize reconfig valstack operations so that resize, clamp, and setting * top are combined into one pass. @@ -76815,7 +78111,8 @@ thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act->bottom_byteoff); DUK_ASSERT(act->retval_byteoff >= act->bottom_byteoff); - clamp_top = (duk_idx_t) ((act->retval_byteoff - act->bottom_byteoff + sizeof(duk_tval)) / sizeof(duk_tval)); /* +1 = one retval */ + clamp_top = + (duk_idx_t) ((act->retval_byteoff - act->bottom_byteoff + sizeof(duk_tval)) / sizeof(duk_tval)); /* +1 = one retval */ duk_set_top_and_wipe(thr, h_func->nregs, clamp_top); DUK_ASSERT((duk_uint8_t *) thr->valstack_end >= (duk_uint8_t *) thr->valstack + act->reserve_byteoff); @@ -76845,7 +78142,7 @@ thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + act->bottom_byteoff); idx_bottom = (duk_size_t) (thr->valstack_bottom - thr->valstack); DUK_ASSERT(cat->idx_base >= idx_bottom); - clamp_top = (duk_idx_t) (cat->idx_base - idx_bottom + 2); /* +2 = catcher value, catcher lj_type */ + clamp_top = (duk_idx_t) (cat->idx_base - idx_bottom + 2); /* +2 = catcher value, catcher lj_type */ duk_set_top_and_wipe(thr, h_func->nregs, clamp_top); DUK_ASSERT((duk_uint8_t *) thr->valstack_end >= (duk_uint8_t *) thr->valstack + act->reserve_byteoff); @@ -76873,7 +78170,10 @@ DUK_TVAL_SET_U32_UPDREF_NORZ(thr, tv1, (duk_uint32_t) lj_type); } -DUK_LOCAL void duk__handle_catch_part1(duk_hthread *thr, duk_tval *tv_val_unstable, duk_small_uint_t lj_type, volatile duk_bool_t *out_delayed_catch_setup) { +DUK_LOCAL void duk__handle_catch_part1(duk_hthread *thr, + duk_tval *tv_val_unstable, + duk_small_uint_t lj_type, + volatile duk_bool_t *out_delayed_catch_setup) { duk_activation *act; duk_catcher *cat; @@ -76911,7 +78211,7 @@ cat = act->cat; DUK_ASSERT(cat != NULL); - act->curr_pc = cat->pc_base + 0; /* +0 = catch */ + act->curr_pc = cat->pc_base + 0; /* +0 = catch */ /* * If the catch block has an automatic catch variable binding, @@ -76971,9 +78271,7 @@ DUK_ASSERT(act->var_env != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(act) != NULL); - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) new_env) == NULL); @@ -76991,7 +78289,7 @@ duk_push_hstring(thr, cat->h_varname); DUK_ASSERT(thr->valstack + cat->idx_base < thr->valstack_top); duk_push_tval(thr, thr->valstack + cat->idx_base); - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_W); /* writable, not configurable */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_W); /* writable, not configurable */ /* ... env */ @@ -76999,7 +78297,7 @@ DUK_ASSERT(act != NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) new_env, act->lex_env); act->lex_env = (duk_hobject *) new_env; - DUK_HOBJECT_INCREF(thr, (duk_hobject *) new_env); /* reachable through activation */ + DUK_HOBJECT_INCREF(thr, (duk_hobject *) new_env); /* reachable through activation */ /* Net refcount change to act->lex_env is 0: incref for new_env's * prototype, decref for act->lex_env overwrite. */ @@ -77041,7 +78339,7 @@ cat = act->cat; DUK_ASSERT(cat != NULL); - act->curr_pc = cat->pc_base + 1; /* +1 = finally */ + act->curr_pc = cat->pc_base + 1; /* +1 = finally */ DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } @@ -77090,18 +78388,21 @@ act_resumer = resumer->callstack_curr; DUK_ASSERT(act_resumer != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(act_resumer) != NULL); - DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(act_resumer))); /* resume caller must be an ECMAScript func */ + DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(act_resumer))); /* resume caller must be an ECMAScript func */ - tv1 = (duk_tval *) (void *) ((duk_uint8_t *) resumer->valstack + act_resumer->retval_byteoff); /* return value from Duktape.Thread.resume() */ - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv_val_unstable); /* side effects */ /* XXX: avoid side effects */ + tv1 = (duk_tval *) (void *) ((duk_uint8_t *) resumer->valstack + + act_resumer->retval_byteoff); /* return value from Duktape.Thread.resume() */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv_val_unstable); /* side effects */ /* XXX: avoid side effects */ duk__reconfig_valstack_ecma_return(resumer); /* caller must change active thread, and set thr->resumer to NULL */ } -#endif /* DUK_USE_COROUTINE_SUPPORT */ +#endif /* DUK_USE_COROUTINE_SUPPORT */ -DUK_LOCAL duk_small_uint_t duk__handle_longjmp(duk_hthread *thr, duk_activation *entry_act, volatile duk_bool_t *out_delayed_catch_setup) { +DUK_LOCAL duk_small_uint_t duk__handle_longjmp(duk_hthread *thr, + duk_activation *entry_act, + volatile duk_bool_t *out_delayed_catch_setup) { duk_small_uint_t retval = DUK__LONGJMP_RESTART; DUK_ASSERT(thr != NULL); @@ -77122,17 +78423,16 @@ * - 'thr' must reflect the "throwing" thread */ - check_longjmp: +check_longjmp: DUK_DD(DUK_DDPRINT("handling longjmp: type=%ld, value1=%!T, value2=%!T, iserror=%ld, top=%ld", (long) thr->heap->lj.type, (duk_tval *) &thr->heap->lj.value1, (duk_tval *) &thr->heap->lj.value2, (long) thr->heap->lj.iserror, - (long) duk_get_top(thr))); + (long) duk_get_top(thr))); switch (thr->heap->lj.type) { - #if defined(DUK_USE_COROUTINE_SUPPORT) case DUK_LJ_TYPE_RESUME: { /* @@ -77146,15 +78446,15 @@ /* duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met */ - DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged by Duktape.Thread.resume() */ - DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged by Duktape.Thread.resume() */ + DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->callstack_curr))->func == duk_bi_thread_resume); - tv = &thr->heap->lj.value2; /* resumee */ + tv = &thr->heap->lj.value2; /* resumee */ DUK_ASSERT(DUK_TVAL_IS_OBJECT(tv)); DUK_ASSERT(DUK_TVAL_GET_OBJECT(tv) != NULL); DUK_ASSERT(DUK_HOBJECT_IS_THREAD(DUK_TVAL_GET_OBJECT(tv))); @@ -77163,15 +78463,15 @@ DUK_ASSERT(resumee != NULL); DUK_ASSERT(resumee->resumer == NULL); DUK_ASSERT(resumee->state == DUK_HTHREAD_STATE_INACTIVE || - resumee->state == DUK_HTHREAD_STATE_YIELDED); /* checked by Duktape.Thread.resume() */ + resumee->state == DUK_HTHREAD_STATE_YIELDED); /* checked by Duktape.Thread.resume() */ DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_YIELDED || - resumee->callstack_top >= 2); /* YIELDED: ECMAScript activation + Duktape.Thread.yield() activation */ + resumee->callstack_top >= 2); /* YIELDED: ECMAScript activation + Duktape.Thread.yield() activation */ DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_YIELDED || (DUK_ACT_GET_FUNC(resumee->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(resumee->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(resumee->callstack_curr))->func == duk_bi_thread_yield)); DUK_ASSERT(resumee->state != DUK_HTHREAD_STATE_INACTIVE || - resumee->callstack_top == 0); /* INACTIVE: no activation, single function value on valstack */ + resumee->callstack_top == 0); /* INACTIVE: no activation, single function value on valstack */ if (thr->heap->lj.iserror) { /* @@ -77197,7 +78497,7 @@ /* thr->heap->lj.value1 is already the value to throw */ /* thr->heap->lj.value2 is 'thread', will be wiped out at the end */ - DUK_ASSERT(thr->heap->lj.iserror); /* already set */ + DUK_ASSERT(thr->heap->lj.iserror); /* already set */ DUK_DD(DUK_DDPRINT("-> resume with an error, converted to a throw in the resumee, propagate")); goto check_longjmp; @@ -77210,17 +78510,18 @@ duk_activation *act_resumee; DUK_ASSERT(resumee->callstack_top >= 2); - act_resumee = resumee->callstack_curr; /* Duktape.Thread.yield() */ + act_resumee = resumee->callstack_curr; /* Duktape.Thread.yield() */ DUK_ASSERT(act_resumee != NULL); - act_resumee = act_resumee->parent; /* ECMAScript call site for yield() */ + act_resumee = act_resumee->parent; /* ECMAScript call site for yield() */ DUK_ASSERT(act_resumee != NULL); - tv = (duk_tval *) (void *) ((duk_uint8_t *) resumee->valstack + act_resumee->retval_byteoff); /* return value from Duktape.Thread.yield() */ + tv = (duk_tval *) (void *) ((duk_uint8_t *) resumee->valstack + + act_resumee->retval_byteoff); /* return value from Duktape.Thread.yield() */ DUK_ASSERT(tv >= resumee->valstack && tv < resumee->valstack_top); tv2 = &thr->heap->lj.value1; - DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv2); /* side effects */ /* XXX: avoid side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv, tv2); /* side effects */ /* XXX: avoid side effects */ - duk_hthread_activation_unwind_norz(resumee); /* unwind to 'yield' caller */ + duk_hthread_activation_unwind_norz(resumee); /* unwind to 'yield' caller */ /* no need to unwind catch stack */ duk__reconfig_valstack_ecma_return(resumee); @@ -77250,7 +78551,7 @@ /* resumee: ... initial_func undefined(= this) resume_value */ - call_flags = DUK_CALL_FLAG_ALLOW_ECMATOECMA; /* not tailcall, ecma-to-ecma (assumed to succeed) */ + call_flags = DUK_CALL_FLAG_ALLOW_ECMATOECMA; /* not tailcall, ecma-to-ecma (assumed to succeed) */ setup_rc = duk_handle_call_unprotected_nargs(resumee, 1 /*nargs*/, call_flags); if (setup_rc == 0) { @@ -77277,7 +78578,7 @@ goto wipe_and_return; } DUK_UNREACHABLE(); - break; /* never here */ + break; /* never here */ } case DUK_LJ_TYPE_YIELD: { @@ -77295,31 +78596,31 @@ /* duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met */ -#if 0 /* entry_thread not available for assert */ +#if 0 /* entry_thread not available for assert */ DUK_ASSERT(thr != entry_thread); /* Duktape.Thread.yield() should prevent */ #endif - DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged from Duktape.Thread.yield() */ - DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.yield() activation */ + DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); /* unchanged from Duktape.Thread.yield() */ + DUK_ASSERT(thr->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.yield() activation */ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->callstack_curr))->func == duk_bi_thread_yield); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* an ECMAScript function */ resumer = thr->resumer; DUK_ASSERT(resumer != NULL); - DUK_ASSERT(resumer->state == DUK_HTHREAD_STATE_RESUMED); /* written by a previous RESUME handling */ - DUK_ASSERT(resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(resumer->state == DUK_HTHREAD_STATE_RESUMED); /* written by a previous RESUME handling */ + DUK_ASSERT(resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(resumer->callstack_curr != NULL); DUK_ASSERT(resumer->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(resumer->callstack_curr) != NULL && DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr)) && ((duk_hnatfunc *) DUK_ACT_GET_FUNC(resumer->callstack_curr))->func == duk_bi_thread_resume); DUK_ASSERT(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(resumer->callstack_curr->parent))); /* an ECMAScript function */ if (thr->heap->lj.iserror) { thr->state = DUK_HTHREAD_STATE_YIELDED; @@ -77331,7 +78632,7 @@ thr->heap->lj.type = DUK_LJ_TYPE_THROW; /* lj.value1 is already set */ - DUK_ASSERT(thr->heap->lj.iserror); /* already set */ + DUK_ASSERT(thr->heap->lj.iserror); /* already set */ DUK_DD(DUK_DDPRINT("-> yield an error, converted to a throw in the resumer, propagate")); goto check_longjmp; @@ -77357,9 +78658,9 @@ goto wipe_and_return; } DUK_UNREACHABLE(); - break; /* never here */ + break; /* never here */ } -#endif /* DUK_USE_COROUTINE_SUPPORT */ +#endif /* DUK_USE_COROUTINE_SUPPORT */ case DUK_LJ_TYPE_THROW: { /* @@ -77400,11 +78701,13 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF); DUK_DDD(DUK_DDDPRINT("before catch part 1: thr=%p, act=%p, cat=%p", - (void *) thr, (void *) act, (void *) act->cat)); + (void *) thr, + (void *) act, + (void *) act->cat)); duk__handle_catch_part1(thr, &thr->heap->lj.value1, DUK_LJ_TYPE_THROW, - out_delayed_catch_setup); + out_delayed_catch_setup); DUK_DD(DUK_DDPRINT("-> throw caught by a 'catch' clause, restart execution")); retval = DUK__LONGJMP_RESTART; @@ -77415,9 +78718,7 @@ DUK_ASSERT(DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF); DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); - duk__handle_finally(thr, - &thr->heap->lj.value1, - DUK_LJ_TYPE_THROW); + duk__handle_finally(thr, &thr->heap->lj.value1, DUK_LJ_TYPE_THROW); DUK_DD(DUK_DDPRINT("-> throw caught by a 'finally' clause, restart execution")); retval = DUK__LONGJMP_RESTART; @@ -77447,20 +78748,21 @@ */ DUK_ASSERT(thr->resumer != NULL); - DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->resumer->callstack_curr != NULL); DUK_ASSERT(thr->resumer->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_ASSERT( + DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ resumer = thr->resumer; /* reset longjmp */ - DUK_ASSERT(thr->heap->lj.type == DUK_LJ_TYPE_THROW); /* already set */ + DUK_ASSERT(thr->heap->lj.type == DUK_LJ_TYPE_THROW); /* already set */ /* lj.value1 already set */ - duk_hthread_terminate(thr); /* updates thread state, minimizes its allocations */ + duk_hthread_terminate(thr); /* updates thread state, minimizes its allocations */ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_TERMINATED); thr->resumer = NULL; @@ -77471,7 +78773,7 @@ goto check_longjmp; } - case DUK_LJ_TYPE_BREAK: /* pseudotypes, not used in actual longjmps */ + case DUK_LJ_TYPE_BREAK: /* pseudotypes, not used in actual longjmps */ case DUK_LJ_TYPE_CONTINUE: case DUK_LJ_TYPE_RETURN: case DUK_LJ_TYPE_NORMAL: @@ -77481,25 +78783,24 @@ goto convert_to_internal_error; } - } /* end switch */ + } /* end switch */ DUK_UNREACHABLE(); - wipe_and_return: - DUK_DD(DUK_DDPRINT("handling longjmp done, wipe-and-return, top=%ld", - (long) duk_get_top(thr))); +wipe_and_return: + DUK_DD(DUK_DDPRINT("handling longjmp done, wipe-and-return, top=%ld", (long) duk_get_top(thr))); thr->heap->lj.type = DUK_LJ_TYPE_UNKNOWN; thr->heap->lj.iserror = 0; - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value1); /* side effects */ - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value2); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value2); /* side effects */ DUK_GC_TORTURE(thr->heap); - just_return: +just_return: return retval; - convert_to_internal_error: +convert_to_internal_error: /* This could also be thrown internally (set the error, goto check_longjmp), * but it's better for internal errors to bubble outwards so that we won't * infinite loop in this catchpoint. @@ -77545,8 +78846,7 @@ /* XXX: bit mask test; FINALLY <-> TCF, single bit mask would suffice? */ - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && - DUK_CAT_HAS_FINALLY_ENABLED(cat)) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && DUK_CAT_HAS_FINALLY_ENABLED(cat)) { duk_tval tv_tmp; DUK_TVAL_SET_U32(&tv_tmp, (duk_uint32_t) label_id); @@ -77555,11 +78855,11 @@ DUK_DD(DUK_DDPRINT("-> break/continue caught by 'finally', restart execution")); return; } - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_LABEL && - (duk_uint_t) DUK_CAT_GET_LABEL(cat) == label_id) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_LABEL && (duk_uint_t) DUK_CAT_GET_LABEL(cat) == label_id) { duk__handle_label(thr, lj_type); - DUK_DD(DUK_DDPRINT("-> break/continue caught by a label catcher (in the same function), restart execution")); + DUK_DD( + DUK_DDPRINT("-> break/continue caught by a label catcher (in the same function), restart execution")); return; } @@ -77567,7 +78867,8 @@ } /* Should never happen, but be robust. */ - DUK_D(DUK_DPRINT("-> break/continue not caught by anything in the current function (should never happen), throw internal error")); + DUK_D(DUK_DPRINT( + "-> break/continue not caught by anything in the current function (should never happen), throw internal error")); DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); } @@ -77591,7 +78892,7 @@ DUK_ASSERT(entry_act != NULL); DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); tv1 = thr->valstack_top - 1; - DUK_TVAL_CHKFAST_INPLACE_FAST(tv1); /* fastint downgrade check for return values */ + DUK_TVAL_CHKFAST_INPLACE_FAST(tv1); /* fastint downgrade check for return values */ /* * Four possible outcomes: @@ -77626,8 +78927,7 @@ break; } - if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && - DUK_CAT_HAS_FINALLY_ENABLED(cat)) { + if (DUK_CAT_GET_TYPE(cat) == DUK_CAT_TYPE_TCF && DUK_CAT_HAS_FINALLY_ENABLED(cat)) { DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); duk__handle_finally(thr, thr->valstack_top - 1, DUK_LJ_TYPE_RETURN); @@ -77658,22 +78958,24 @@ DUK_ASSERT(thr->callstack_curr != NULL); DUK_ASSERT(thr->callstack_curr->parent != NULL); - DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* must be ECMAScript */ + DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->callstack_curr->parent))); /* must be ECMAScript */ #if defined(DUK_USE_ES6_PROXY) if (thr->callstack_curr->flags & (DUK_ACT_FLAG_CONSTRUCT | DUK_ACT_FLAG_CONSTRUCT_PROXY)) { - duk_call_construct_postprocess(thr, thr->callstack_curr->flags & DUK_ACT_FLAG_CONSTRUCT_PROXY); /* side effects */ + duk_call_construct_postprocess(thr, + thr->callstack_curr->flags & + DUK_ACT_FLAG_CONSTRUCT_PROXY); /* side effects */ } #else if (thr->callstack_curr->flags & DUK_ACT_FLAG_CONSTRUCT) { - duk_call_construct_postprocess(thr, 0); /* side effects */ + duk_call_construct_postprocess(thr, 0); /* side effects */ } #endif tv1 = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + thr->callstack_curr->parent->retval_byteoff); DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); tv2 = thr->valstack_top - 1; - DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv1, tv2); /* side effects */ /* Catch stack unwind happens inline in callstack unwind. */ duk_hthread_activation_unwind_norz(thr); @@ -77688,14 +78990,15 @@ DUK_DD(DUK_DDPRINT("no calling activation, thread finishes (similar to yield)")); DUK_ASSERT(thr->resumer != NULL); - DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ + DUK_ASSERT(thr->resumer->callstack_top >= 2); /* ECMAScript activation + Duktape.Thread.resume() activation */ DUK_ASSERT(thr->resumer->callstack_curr != NULL); DUK_ASSERT(thr->resumer->callstack_curr->parent != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr) != NULL && - DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr)) && - ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->resumer->callstack_curr))->func == duk_bi_thread_resume); /* Duktape.Thread.resume() */ + DUK_HOBJECT_IS_NATFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr)) && + ((duk_hnatfunc *) DUK_ACT_GET_FUNC(thr->resumer->callstack_curr))->func == + duk_bi_thread_resume); /* Duktape.Thread.resume() */ DUK_ASSERT(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent) != NULL && - DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ + DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(thr->resumer->callstack_curr->parent))); /* an ECMAScript function */ DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_RUNNING); DUK_ASSERT(thr->resumer->state == DUK_HTHREAD_STATE_RESUMED); @@ -77717,11 +79020,11 @@ */ DUK_ASSERT(thr->valstack_top - 1 >= thr->valstack_bottom); - duk_hthread_activation_unwind_norz(resumer); /* May remove last reference to 'thr', but is NORZ. */ - duk_push_tval(resumer, thr->valstack_top - 1); /* Capture return value, side effect free. */ - duk_push_hthread(resumer, thr); /* Make 'thr' reachable again, before side effects. */ + duk_hthread_activation_unwind_norz(resumer); /* May remove last reference to 'thr', but is NORZ. */ + duk_push_tval(resumer, thr->valstack_top - 1); /* Capture return value, side effect free. */ + duk_push_hthread(resumer, thr); /* Make 'thr' reachable again, before side effects. */ - duk_hthread_terminate(thr); /* Updates thread state, minimizes its allocations. */ + duk_hthread_terminate(thr); /* Updates thread state, minimizes its allocations. */ thr->resumer = NULL; DUK_HTHREAD_DECREF(thr, resumer); DUK_ASSERT(thr->state == DUK_HTHREAD_STATE_TERMINATED); @@ -77731,7 +79034,7 @@ DUK_ASSERT(resumer->valstack_top - 2 >= resumer->valstack_bottom); duk__handle_yield(thr, resumer, resumer->valstack_top - 2); - thr = NULL; /* 'thr' invalidated by call */ + thr = NULL; /* 'thr' invalidated by call */ #if 0 thr = resumer; /* not needed */ @@ -77773,8 +79076,8 @@ #if defined(DUK_USE_INTERRUPT_COUNTER) -#define DUK__INT_NOACTION 0 /* no specific action, resume normal execution */ -#define DUK__INT_RESTART 1 /* must "goto restart_execution", e.g. breakpoints changed */ +#define DUK__INT_NOACTION 0 /* no specific action, resume normal execution */ +#define DUK__INT_RESTART 1 /* must "goto restart_execution", e.g. breakpoints changed */ #if defined(DUK_USE_DEBUGGER_SUPPORT) DUK_LOCAL void duk__interrupt_handle_debugger(duk_hthread *thr, duk_bool_t *out_immediate, duk_small_uint_t *out_interrupt_retval) { @@ -77785,7 +79088,7 @@ duk_bool_t process_messages; duk_bool_t processed_messages = 0; - DUK_ASSERT(thr->heap->dbg_processing == 0); /* don't re-enter e.g. during Eval */ + DUK_ASSERT(thr->heap->dbg_processing == 0); /* don't re-enter e.g. during Eval */ act = thr->callstack_curr; DUK_ASSERT(act != NULL); @@ -77808,17 +79111,14 @@ * Breakpoint and step state checks */ - if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || - (thr->heap->dbg_pause_act == thr->callstack_curr)) { + if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || (thr->heap->dbg_pause_act == thr->callstack_curr)) { line = duk_debug_curr_line(thr); if (act->prev_line != line) { /* Stepped? Step out is handled by callstack unwind. */ if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && - (thr->heap->dbg_pause_act == thr->callstack_curr) && - (line != thr->heap->dbg_pause_startline)) { - DUK_D(DUK_DPRINT("PAUSE TRIGGERED by line change, at line %ld", - (long) line)); + (thr->heap->dbg_pause_act == thr->callstack_curr) && (line != thr->heap->dbg_pause_startline)) { + DUK_D(DUK_DPRINT("PAUSE TRIGGERED by line change, at line %ld", (long) line)); duk_debug_set_paused(thr->heap); } @@ -77844,7 +79144,8 @@ DUK_ASSERT(bp->filename != NULL); if (act->prev_line != bp->line && line == bp->line) { DUK_D(DUK_DPRINT("PAUSE TRIGGERED by breakpoint at %!O:%ld", - (duk_heaphdr *) bp->filename, (long) bp->line)); + (duk_heaphdr *) bp->filename, + (long) bp->line)); duk_debug_set_paused(thr->heap); } } @@ -77937,11 +79238,10 @@ if (duk_debug_is_attached(thr->heap)) { DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); - if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || - (thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_ONE_OPCODE) || + if (act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE || (thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_ONE_OPCODE) || ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && thr->heap->dbg_pause_act == thr->callstack_curr) || - DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap)) { + DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap)) { *out_immediate = 1; } @@ -77963,7 +79263,7 @@ DUK_D(DUK_DPRINT("debugger became detached, resume normal execution")); } } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ DUK_LOCAL DUK_EXEC_NOINLINE_PERF DUK_COLD duk_small_uint_t duk__executor_interrupt(duk_hthread *thr) { duk_int_t ctr; @@ -77980,8 +79280,10 @@ thr->heap->inst_count_interrupt += thr->interrupt_init; DUK_DD(DUK_DDPRINT("execution interrupt, counter=%ld, init=%ld, " "instruction counts: executor=%ld, interrupt=%ld", - (long) thr->interrupt_counter, (long) thr->interrupt_init, - (long) thr->heap->inst_count_exec, (long) thr->heap->inst_count_interrupt)); + (long) thr->interrupt_counter, + (long) thr->interrupt_init, + (long) thr->heap->inst_count_exec, + (long) thr->heap->inst_count_interrupt)); #endif retval = DUK__INT_NOACTION; @@ -78043,18 +79345,17 @@ DUK_ERROR_RANGE(thr, "execution timeout"); DUK_WO_NORETURN(return 0;); } -#endif /* DUK_USE_EXEC_TIMEOUT_CHECK */ +#endif /* DUK_USE_EXEC_TIMEOUT_CHECK */ #if defined(DUK_USE_DEBUGGER_SUPPORT) - if (!thr->heap->dbg_processing && - (thr->heap->dbg_read_cb != NULL || thr->heap->dbg_detaching)) { + if (!thr->heap->dbg_processing && (thr->heap->dbg_read_cb != NULL || thr->heap->dbg_detaching)) { /* Avoid recursive re-entry; enter when we're attached or * detaching (to finish off the pending detach). */ duk__interrupt_handle_debugger(thr, &immediate, &retval); DUK_ASSERT(act == thr->callstack_curr); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Update the interrupt counter @@ -78077,7 +79378,7 @@ return retval; } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ /* * Debugger handling for executor restart @@ -78145,8 +79446,7 @@ duk_hcompfunc *inner_fun; duk_bool_t bp_match; - if (bp->filename == filename && - bp->line >= fun->start_line && bp->line <= fun->end_line) { + if (bp->filename == filename && bp->line >= fun->start_line && bp->line <= fun->end_line) { bp_match = 1; DUK_DD(DUK_DDPRINT("breakpoint filename and line match: " "%s:%ld vs. %s (line %ld vs. %ld-%ld)", @@ -78183,13 +79483,12 @@ } } - *bp_active = NULL; /* terminate */ + *bp_active = NULL; /* terminate */ DUK_DD(DUK_DDPRINT("ACTIVE BREAKPOINTS: %ld", (long) (bp_active - thr->heap->dbg_breakpoints_active))); /* Force pause if we were doing "step into" in another activation. */ - if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_FUNC_ENTRY) && - thr->heap->dbg_pause_act != thr->callstack_curr) { + if ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_FUNC_ENTRY) && thr->heap->dbg_pause_act != thr->callstack_curr) { DUK_D(DUK_DPRINT("PAUSE TRIGGERED by function entry")); duk_debug_set_paused(thr->heap); } @@ -78197,10 +79496,8 @@ /* Force interrupt right away if we're paused or in "checked mode". * Step out is handled by callstack unwind. */ - if ((act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE) || - DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || - ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && - thr->heap->dbg_pause_act == thr->callstack_curr)) { + if ((act->flags & DUK_ACT_FLAG_BREAKPOINT_ACTIVE) || DUK_HEAP_HAS_DEBUGGER_PAUSED(thr->heap) || + ((thr->heap->dbg_pause_flags & DUK_PAUSE_FLAG_LINE_CHANGE) && thr->heap->dbg_pause_act == thr->callstack_curr)) { /* We'll need to interrupt early so recompute the init * counter to reflect the number of bytecode instructions * executed so that step counts for e.g. debugger rate @@ -78211,7 +79508,7 @@ thr->interrupt_counter = 0; } } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ /* * Opcode handlers for opcodes with a lot of code and which are relatively @@ -78235,18 +79532,14 @@ /* This could be made more optimal by accessing internals directly. */ idx = (duk_uint_fast_t) DUK_DEC_BC(ins); - duk_dup(thr, (duk_idx_t) (idx + 0)); /* key */ - duk_dup(thr, (duk_idx_t) (idx + 1)); /* getter/setter */ + duk_dup(thr, (duk_idx_t) (idx + 0)); /* key */ + duk_dup(thr, (duk_idx_t) (idx + 1)); /* getter/setter */ if (is_set) { - defprop_flags = DUK_DEFPROP_HAVE_SETTER | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE; - } else { - defprop_flags = DUK_DEFPROP_HAVE_GETTER | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE; + defprop_flags = + DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE; + } else { + defprop_flags = + DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE; } duk_def_prop(thr, (duk_idx_t) DUK_DEC_A(ins), defprop_flags); } @@ -78311,7 +79604,7 @@ * error handling, so there's no side effect problem even if the * error value has a finalizer. */ - duk_dup(thr, (duk_idx_t) bc); /* Stabilize value. */ + duk_dup(thr, (duk_idx_t) bc); /* Stabilize value. */ duk_to_undefined(thr, (duk_idx_t) bc); duk_to_undefined(thr, (duk_idx_t) (bc + 1)); @@ -78326,7 +79619,7 @@ cat->flags = DUK_CAT_TYPE_TCF; cat->h_varname = NULL; - cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ + cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ cat->idx_base = (duk_size_t) (thr->valstack_bottom - thr->valstack) + bc; act = thr->callstack_curr; @@ -78365,7 +79658,7 @@ duk_js_init_activation_environment_records_delayed(thr, act); DUK_ASSERT(act == thr->callstack_curr); - DUK_UNREF(act); /* 'act' is no longer accessed, scanbuild fix */ + DUK_UNREF(act); /* 'act' is no longer accessed, scanbuild fix */ } DUK_ASSERT(act->lex_env != NULL); DUK_ASSERT(act->var_env != NULL); @@ -78378,12 +79671,10 @@ * so avoid side effects very carefully until it is * referenced. */ - env = duk_hobjenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); + env = duk_hobjenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJENV)); DUK_ASSERT(env != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); - env->target = target; /* always provideThis=true */ + env->target = target; /* always provideThis=true */ DUK_HOBJECT_INCREF(thr, target); env->has_this = 1; DUK_HOBJENV_ASSERT_VALID(env); @@ -78393,7 +79684,7 @@ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); DUK_ASSERT(act->lex_env != NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) env, act->lex_env); - act->lex_env = (duk_hobject *) env; /* Now reachable. */ + act->lex_env = (duk_hobject *) env; /* Now reachable. */ DUK_HOBJECT_INCREF(thr, (duk_hobject *) env); /* Net refcount change to act->lex_env is 0: incref for env's * prototype, decref for act->lex_env overwrite. @@ -78402,7 +79693,7 @@ /* Set catcher lex_env active (affects unwind) * only when the whole setup is complete. */ - cat = act->cat; /* XXX: better to relookup? not mandatory because 'cat' is stable */ + cat = act->cat; /* XXX: better to relookup? not mandatory because 'cat' is stable */ cat->flags |= DUK_CAT_FLAG_LEXENV_ACTIVE; } else { ; @@ -78411,7 +79702,9 @@ DUK_DDD(DUK_DDDPRINT("TRYCATCH catcher: flags=0x%08lx, pc_base=%ld, " "idx_base=%ld, h_varname=%!O", (unsigned long) cat->flags, - (long) cat->pc_base, (long) cat->idx_base, (duk_heaphdr *) cat->h_varname)); + (long) cat->pc_base, + (long) cat->idx_base, + (duk_heaphdr *) cat->h_varname)); duk_pop_unsafe(thr); } @@ -78441,23 +79734,24 @@ tv1 = thr->valstack + cat->idx_base; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ tv1 = NULL; tv1 = thr->valstack + cat->idx_base + 1; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ tv1 = NULL; DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } else { - DUK_DDD(DUK_DDDPRINT("ENDTRY: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); + DUK_DDD( + DUK_DDDPRINT("ENDTRY: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); - duk_hthread_catcher_unwind_norz(thr, act); /* lexenv may be set for 'with' binding */ + duk_hthread_catcher_unwind_norz(thr, act); /* lexenv may be set for 'with' binding */ /* no need to unwind callstack */ } - return pc_base + 1; /* new curr_pc value */ + return pc_base + 1; /* new curr_pc value */ } DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_instr_t *duk__handle_op_endcatch(duk_hthread *thr, duk_uint_fast32_t ins) { @@ -78473,7 +79767,7 @@ DUK_ASSERT(act != NULL); cat = act->cat; DUK_ASSERT(cat != NULL); - DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); /* cleared before entering catch part */ + DUK_ASSERT(!DUK_CAT_HAS_CATCH_ENABLED(cat)); /* cleared before entering catch part */ if (DUK_CAT_HAS_LEXENV_ACTIVE(cat)) { duk_hobject *prev_env; @@ -78489,7 +79783,7 @@ act->lex_env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, prev_env); DUK_CAT_CLEAR_LEXENV_ACTIVE(cat); DUK_HOBJECT_INCREF(thr, act->lex_env); - DUK_HOBJECT_DECREF(thr, prev_env); /* side effects */ + DUK_HOBJECT_DECREF(thr, prev_env); /* side effects */ DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); @@ -78502,26 +79796,29 @@ tv1 = thr->valstack + cat->idx_base; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ tv1 = NULL; tv1 = thr->valstack + cat->idx_base + 1; DUK_ASSERT(tv1 >= thr->valstack && tv1 < thr->valstack_top); - DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ + DUK_TVAL_SET_U32_UPDREF(thr, tv1, (duk_uint32_t) DUK_LJ_TYPE_NORMAL); /* side effects */ tv1 = NULL; DUK_CAT_CLEAR_FINALLY_ENABLED(cat); } else { - DUK_DDD(DUK_DDDPRINT("ENDCATCH: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); + DUK_DDD( + DUK_DDDPRINT("ENDCATCH: no finally part, dismantle catcher, jump through 2nd jump slot (to end of statement)")); duk_hthread_catcher_unwind_norz(thr, act); /* no need to unwind callstack */ } - return pc_base + 1; /* new curr_pc value */ + return pc_base + 1; /* new curr_pc value */ } -DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_small_uint_t duk__handle_op_endfin(duk_hthread *thr, duk_uint_fast32_t ins, duk_activation *entry_act) { +DUK_LOCAL DUK_EXEC_NOINLINE_PERF duk_small_uint_t duk__handle_op_endfin(duk_hthread *thr, + duk_uint_fast32_t ins, + duk_activation *entry_act) { duk_activation *act; duk_tval *tv1; duk_uint_t reg_catch; @@ -78543,7 +79840,7 @@ (duk_tval *) (thr->valstack_bottom + reg_catch + 0), (duk_tval *) (thr->valstack_bottom + reg_catch + 1))); - tv1 = thr->valstack_bottom + reg_catch + 1; /* type */ + tv1 = thr->valstack_bottom + reg_catch + 1; /* type */ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv1)); #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv1)); @@ -78552,7 +79849,7 @@ cont_type = (duk_small_uint_t) DUK_TVAL_GET_NUMBER(tv1); #endif - tv1--; /* value */ + tv1--; /* value */ switch (cont_type) { case DUK_LJ_TYPE_NORMAL: { @@ -78561,11 +79858,12 @@ duk_hthread_catcher_unwind_norz(thr, act); /* no need to unwind callstack */ - return 0; /* restart execution */ + return 0; /* restart execution */ } case DUK_LJ_TYPE_RETURN: { DUK_DDD(DUK_DDDPRINT("ENDFIN: finally part finishing with 'return' complation -> dismantle " - "catcher, handle return, lj.value1=%!T", tv1)); + "catcher, handle return, lj.value1=%!T", + tv1)); /* Not necessary to unwind catch stack: return handling will * do it. The finally flag of 'cat' is no longer set. The @@ -78575,12 +79873,12 @@ duk_push_tval(thr, tv1); ret_result = duk__handle_return(thr, entry_act); if (ret_result == DUK__RETHAND_RESTART) { - return 0; /* restart execution */ + return 0; /* restart execution */ } DUK_ASSERT(ret_result == DUK__RETHAND_FINISHED); DUK_DDD(DUK_DDDPRINT("exiting executor after ENDFIN and RETURN (pseudo) longjmp type")); - return 1; /* exit executor */ + return 1; /* exit executor */ } case DUK_LJ_TYPE_BREAK: case DUK_LJ_TYPE_CONTINUE: { @@ -78602,7 +79900,7 @@ #endif lj_type = cont_type; duk__handle_break_or_continue(thr, label_id, lj_type); - return 0; /* restart execution */ + return 0; /* restart execution */ } default: { DUK_DDD(DUK_DDDPRINT("ENDFIN: finally part finishing with abrupt completion, lj_type=%ld -> " @@ -78612,7 +79910,7 @@ duk_err_setup_ljstate1(thr, (duk_small_uint_t) cont_type, tv1); /* No debugger Throw notify check on purpose (rethrow). */ - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ duk_err_longjmp(thr); DUK_UNREACHABLE(); } @@ -78645,7 +79943,7 @@ } else { duk_dup(thr, (duk_idx_t) c); duk_to_object(thr, -1); - duk_hobject_enumerator_create(thr, 0 /*enum_flags*/); /* ... val --> ... enum */ + duk_hobject_enumerator_create(thr, 0 /*enum_flags*/); /* ... val --> ... enum */ duk_replace(thr, (duk_idx_t) b); } } @@ -78677,13 +79975,12 @@ duk_dup(thr, (duk_idx_t) c); if (duk_hobject_enumerator_next(thr, 0 /*get_value*/)) { /* ... enum -> ... next_key */ - DUK_DDD(DUK_DDDPRINT("enum active, next key is %!T, skip jump slot ", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD(DUK_DDDPRINT("enum active, next key is %!T, skip jump slot ", (duk_tval *) duk_get_tval(thr, -1))); pc_skip = 1; } else { /* ... enum -> ... */ DUK_DDD(DUK_DDDPRINT("enum finished, execute jump slot")); - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } duk_replace(thr, (duk_idx_t) b); @@ -78703,7 +80000,7 @@ DUK_LOCAL duk_bool_t duk__executor_handle_call(duk_hthread *thr, duk_idx_t idx, duk_idx_t nargs, duk_small_uint_t call_flags) { duk_bool_t rc; - duk_set_top_unsafe(thr, (duk_idx_t) (idx + nargs + 2)); /* ... func this arg1 ... argN */ + duk_set_top_unsafe(thr, (duk_idx_t) (idx + nargs + 2)); /* ... func this arg1 ... argN */ /* Attempt an Ecma-to-Ecma call setup. If the call * target is (directly or indirectly) Reflect.construct(), @@ -78757,22 +80054,22 @@ * difference and the best option is architecture dependent. */ #if defined(DUK_USE_EXEC_FUN_LOCAL) -#define DUK__FUN() fun +#define DUK__FUN() fun #else -#define DUK__FUN() ((duk_hcompfunc *) DUK_ACT_GET_FUNC((thr)->callstack_curr)) +#define DUK__FUN() ((duk_hcompfunc *) DUK_ACT_GET_FUNC((thr)->callstack_curr)) #endif /* Strict flag. */ -#define DUK__STRICT() ((duk_small_uint_t) DUK_HOBJECT_HAS_STRICT((duk_hobject *) DUK__FUN())) +#define DUK__STRICT() ((duk_small_uint_t) DUK_HOBJECT_HAS_STRICT((duk_hobject *) DUK__FUN())) /* Reg/const access macros: these are very footprint and performance sensitive * so modify with care. Arguments are sometimes evaluated multiple times which * is not ideal. */ -#define DUK__REG(x) (*(thr->valstack_bottom + (x))) -#define DUK__REGP(x) (thr->valstack_bottom + (x)) -#define DUK__CONST(x) (*(consts + (x))) -#define DUK__CONSTP(x) (consts + (x)) +#define DUK__REG(x) (*(thr->valstack_bottom + (x))) +#define DUK__REGP(x) (thr->valstack_bottom + (x)) +#define DUK__CONST(x) (*(consts + (x))) +#define DUK__CONSTP(x) (consts + (x)) /* Reg/const access macros which take the 32-bit instruction and avoid an * explicit field decoding step by using shifts and masks. These must be @@ -78781,68 +80078,74 @@ * instead of a duk_tval offset which needs further shifting (which is an * issue on some, but not all, CPUs). */ -#define DUK__RCBIT_B DUK_BC_REGCONST_B -#define DUK__RCBIT_C DUK_BC_REGCONST_C +#define DUK__RCBIT_B DUK_BC_REGCONST_B +#define DUK__RCBIT_C DUK_BC_REGCONST_C #if defined(DUK_USE_EXEC_REGCONST_OPTIMIZE) #if defined(DUK_USE_PACKED_TVAL) -#define DUK__TVAL_SHIFT 3 /* sizeof(duk_tval) == 8 */ +#define DUK__TVAL_SHIFT 3 /* sizeof(duk_tval) == 8 */ #else -#define DUK__TVAL_SHIFT 4 /* sizeof(duk_tval) == 16; not always the case so also asserted for */ +#define DUK__TVAL_SHIFT 4 /* sizeof(duk_tval) == 16; not always the case so also asserted for */ #endif -#define DUK__SHIFT_A (DUK_BC_SHIFT_A - DUK__TVAL_SHIFT) -#define DUK__SHIFT_B (DUK_BC_SHIFT_B - DUK__TVAL_SHIFT) -#define DUK__SHIFT_C (DUK_BC_SHIFT_C - DUK__TVAL_SHIFT) -#define DUK__SHIFT_BC (DUK_BC_SHIFT_BC - DUK__TVAL_SHIFT) -#define DUK__MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK__TVAL_SHIFT) -#define DUK__MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK__TVAL_SHIFT) -#define DUK__MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK__TVAL_SHIFT) -#define DUK__MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK__TVAL_SHIFT) -#define DUK__BYTEOFF_A(ins) (((ins) >> DUK__SHIFT_A) & DUK__MASK_A) -#define DUK__BYTEOFF_B(ins) (((ins) >> DUK__SHIFT_B) & DUK__MASK_B) -#define DUK__BYTEOFF_C(ins) (((ins) >> DUK__SHIFT_C) & DUK__MASK_C) -#define DUK__BYTEOFF_BC(ins) (((ins) >> DUK__SHIFT_BC) & DUK__MASK_BC) - -#define DUK__REGP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_A((ins)))) -#define DUK__REGP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_B((ins)))) -#define DUK__REGP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_C((ins)))) -#define DUK__REGP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_BC((ins)))) -#define DUK__CONSTP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_A((ins)))) -#define DUK__CONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_B((ins)))) -#define DUK__CONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_C((ins)))) -#define DUK__CONSTP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_BC((ins)))) -#define DUK__REGCONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) & DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_B((ins)))) -#define DUK__REGCONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) & DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_C((ins)))) -#else /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#define DUK__SHIFT_A (DUK_BC_SHIFT_A - DUK__TVAL_SHIFT) +#define DUK__SHIFT_B (DUK_BC_SHIFT_B - DUK__TVAL_SHIFT) +#define DUK__SHIFT_C (DUK_BC_SHIFT_C - DUK__TVAL_SHIFT) +#define DUK__SHIFT_BC (DUK_BC_SHIFT_BC - DUK__TVAL_SHIFT) +#define DUK__MASK_A (DUK_BC_UNSHIFTED_MASK_A << DUK__TVAL_SHIFT) +#define DUK__MASK_B (DUK_BC_UNSHIFTED_MASK_B << DUK__TVAL_SHIFT) +#define DUK__MASK_C (DUK_BC_UNSHIFTED_MASK_C << DUK__TVAL_SHIFT) +#define DUK__MASK_BC (DUK_BC_UNSHIFTED_MASK_BC << DUK__TVAL_SHIFT) +#define DUK__BYTEOFF_A(ins) (((ins) >> DUK__SHIFT_A) & DUK__MASK_A) +#define DUK__BYTEOFF_B(ins) (((ins) >> DUK__SHIFT_B) & DUK__MASK_B) +#define DUK__BYTEOFF_C(ins) (((ins) >> DUK__SHIFT_C) & DUK__MASK_C) +#define DUK__BYTEOFF_BC(ins) (((ins) >> DUK__SHIFT_BC) & DUK__MASK_BC) + +#define DUK__REGP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_A((ins)))) +#define DUK__REGP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_B((ins)))) +#define DUK__REGP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_C((ins)))) +#define DUK__REGP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + DUK__BYTEOFF_BC((ins)))) +#define DUK__CONSTP_A(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_A((ins)))) +#define DUK__CONSTP_B(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_B((ins)))) +#define DUK__CONSTP_C(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_C((ins)))) +#define DUK__CONSTP_BC(ins) ((duk_tval *) (void *) ((duk_uint8_t *) consts + DUK__BYTEOFF_BC((ins)))) +#define DUK__REGCONSTP_B(ins) \ + ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) &DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_B((ins)))) +#define DUK__REGCONSTP_C(ins) \ + ((duk_tval *) (void *) ((duk_uint8_t *) (((ins) &DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK__BYTEOFF_C((ins)))) +#else /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ /* Safe alternatives, no assumption about duk_tval size. */ -#define DUK__REGP_A(ins) DUK__REGP(DUK_DEC_A((ins))) -#define DUK__REGP_B(ins) DUK__REGP(DUK_DEC_B((ins))) -#define DUK__REGP_C(ins) DUK__REGP(DUK_DEC_C((ins))) -#define DUK__REGP_BC(ins) DUK__REGP(DUK_DEC_BC((ins))) -#define DUK__CONSTP_A(ins) DUK__CONSTP(DUK_DEC_A((ins))) -#define DUK__CONSTP_B(ins) DUK__CONSTP(DUK_DEC_B((ins))) -#define DUK__CONSTP_C(ins) DUK__CONSTP(DUK_DEC_C((ins))) -#define DUK__CONSTP_BC(ins) DUK__CONSTP(DUK_DEC_BC((ins))) -#define DUK__REGCONSTP_B(ins) ((((ins) & DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK_DEC_B((ins))) -#define DUK__REGCONSTP_C(ins) ((((ins) & DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK_DEC_C((ins))) -#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ +#define DUK__REGP_A(ins) DUK__REGP(DUK_DEC_A((ins))) +#define DUK__REGP_B(ins) DUK__REGP(DUK_DEC_B((ins))) +#define DUK__REGP_C(ins) DUK__REGP(DUK_DEC_C((ins))) +#define DUK__REGP_BC(ins) DUK__REGP(DUK_DEC_BC((ins))) +#define DUK__CONSTP_A(ins) DUK__CONSTP(DUK_DEC_A((ins))) +#define DUK__CONSTP_B(ins) DUK__CONSTP(DUK_DEC_B((ins))) +#define DUK__CONSTP_C(ins) DUK__CONSTP(DUK_DEC_C((ins))) +#define DUK__CONSTP_BC(ins) DUK__CONSTP(DUK_DEC_BC((ins))) +#define DUK__REGCONSTP_B(ins) ((((ins) &DUK__RCBIT_B) ? consts : thr->valstack_bottom) + DUK_DEC_B((ins))) +#define DUK__REGCONSTP_C(ins) ((((ins) &DUK__RCBIT_C) ? consts : thr->valstack_bottom) + DUK_DEC_C((ins))) +#endif /* DUK_USE_EXEC_REGCONST_OPTIMIZE */ #if defined(DUK_USE_VERBOSE_EXECUTOR_ERRORS) -#define DUK__INTERNAL_ERROR(msg) do { \ +#define DUK__INTERNAL_ERROR(msg) \ + do { \ DUK_ERROR_ERROR(thr, (msg)); \ DUK_WO_NORETURN(return;); \ } while (0) #else -#define DUK__INTERNAL_ERROR(msg) do { \ +#define DUK__INTERNAL_ERROR(msg) \ + do { \ goto internal_error; \ } while (0) #endif -#define DUK__SYNC_CURR_PC() do { \ +#define DUK__SYNC_CURR_PC() \ + do { \ duk_activation *duk__act; \ duk__act = thr->callstack_curr; \ duk__act->curr_pc = curr_pc; \ } while (0) -#define DUK__SYNC_AND_NULL_CURR_PC() do { \ +#define DUK__SYNC_AND_NULL_CURR_PC() \ + do { \ duk_activation *duk__act; \ duk__act = thr->callstack_curr; \ duk__act->curr_pc = curr_pc; \ @@ -78850,19 +80153,22 @@ } while (0) #if defined(DUK_USE_EXEC_PREFER_SIZE) -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ (idx) = (duk_uint_fast_t) duk_get_uint(thr, (duk_idx_t) (idx)); \ } while (0) #elif defined(DUK_USE_FASTINT) -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ duk_tval *tv_ind; \ tv_ind = DUK__REGP((idx)); \ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_ind)); \ - DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_ind)); /* compiler guarantees */ \ + DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv_ind)); /* compiler guarantees */ \ (idx) = (duk_uint_fast_t) DUK_TVAL_GET_FASTINT_U32(tv_ind); \ } while (0) #else -#define DUK__LOOKUP_INDIRECT(idx) do { \ +#define DUK__LOOKUP_INDIRECT(idx) \ + do { \ duk_tval *tv_ind; \ tv_ind = DUK__REGP(idx); \ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_ind)); \ @@ -78915,8 +80221,8 @@ * will be re-bumped by the longjmp. */ - DUK_ASSERT(lj_ret == DUK__LONGJMP_RETHROW); /* Rethrow error to calling state. */ - DUK_ASSERT(heap->lj.jmpbuf_ptr == entry_jmpbuf_ptr); /* Longjmp handling has restored jmpbuf_ptr. */ + DUK_ASSERT(lj_ret == DUK__LONGJMP_RETHROW); /* Rethrow error to calling state. */ + DUK_ASSERT(heap->lj.jmpbuf_ptr == entry_jmpbuf_ptr); /* Longjmp handling has restored jmpbuf_ptr. */ /* Thread may have changed, e.g. YIELD converted to THROW. */ duk_err_longjmp(heap->curr_thread); @@ -78939,7 +80245,7 @@ DUK_ASSERT(exec_thr->heap != NULL); DUK_ASSERT(exec_thr->heap->curr_thread != NULL); DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR((duk_heaphdr *) exec_thr); - DUK_ASSERT(exec_thr->callstack_top >= 1); /* at least one activation, ours */ + DUK_ASSERT(exec_thr->callstack_top >= 1); /* at least one activation, ours */ DUK_ASSERT(exec_thr->callstack_curr != NULL); DUK_ASSERT(DUK_ACT_GET_FUNC(exec_thr->callstack_curr) != NULL); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(exec_thr->callstack_curr))); @@ -79005,7 +80311,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } #if defined(DUK_USE_CPP_EXCEPTIONS) catch (duk_fatal_exception &exc) { @@ -79021,7 +80327,10 @@ DUK_STATS_INC(exec_thr->heap, stats_exec_throw); try { DUK_ASSERT(heap->curr_thread != NULL); - DUK_ERROR_FMT1(heap->curr_thread, DUK_ERR_TYPE_ERROR, "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", what); + DUK_ERROR_FMT1(heap->curr_thread, + DUK_ERR_TYPE_ERROR, + "caught invalid c++ std::exception '%s' (perhaps thrown by user code)", + what); DUK_WO_NORETURN(return;); } catch (duk_internal_exception exc) { DUK_D(DUK_DPRINT("caught api error thrown from unexpected c++ std::exception")); @@ -79030,7 +80339,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } } catch (...) { DUK_D(DUK_DPRINT("unexpected c++ exception (perhaps thrown by user code)")); @@ -79046,7 +80355,7 @@ entry_act, entry_call_recursion_depth, entry_jmpbuf_ptr, - &delayed_catch_setup); + &delayed_catch_setup); } } #endif @@ -79062,13 +80371,13 @@ * but that eliminates performance benefits; aliasing guarantees * should be enough though. */ - duk_instr_t *curr_pc; /* bytecode has a stable pointer */ + duk_instr_t *curr_pc; /* bytecode has a stable pointer */ /* Hot variables for interpretation. Critical for performance, * but must add sparingly to minimize register shuffling. */ - duk_hthread *thr; /* stable */ - duk_tval *consts; /* stable */ + duk_hthread *thr; /* stable */ + duk_tval *consts; /* stable */ duk_uint_fast32_t ins; /* 'funcs' is quite rarely used, so no local for it */ #if defined(DUK_USE_EXEC_FUN_LOCAL) @@ -79082,7 +80391,7 @@ #endif #if defined(DUK_USE_ASSERTIONS) - duk_size_t valstack_top_base; /* valstack top, should match before interpreting each op (no leftovers) */ + duk_size_t valstack_top_base; /* valstack top, should match before interpreting each op (no leftovers) */ #endif /* Optimized reg/const access macros assume sizeof(duk_tval) to be @@ -79138,7 +80447,7 @@ * See execution.rst for discussion. */ - restart_execution: +restart_execution: /* Lookup current thread; use the stable 'entry_thread' for this to * avoid clobber warnings. Any valid, reachable 'thr' value would be @@ -79179,7 +80488,7 @@ DUK_ASSERT(act == thr->callstack_curr); DUK_ASSERT(act != NULL); } -#endif /* DUK_USE_DEBUGGER_SUPPORT */ +#endif /* DUK_USE_DEBUGGER_SUPPORT */ #if defined(DUK_USE_ASSERTIONS) valstack_top_base = (duk_size_t) (thr->valstack_top - thr->valstack); @@ -79243,7 +80552,7 @@ */ #if defined(DUK_USE_DEBUGGER_SUPPORT) if (thr->heap->dbg_force_restart) { - DUK_DD(DUK_DDPRINT("dbg_force_restart flag forced restart execution")); /* GH-303 */ + DUK_DD(DUK_DDPRINT("dbg_force_restart flag forced restart execution")); /* GH-303 */ thr->heap->dbg_force_restart = 0; goto restart_execution; } @@ -79255,7 +80564,7 @@ goto restart_execution; } } -#endif /* DUK_USE_INTERRUPT_COUNTER */ +#endif /* DUK_USE_INTERRUPT_COUNTER */ #if defined(DUK_USE_INTERRUPT_COUNTER) && defined(DUK_USE_DEBUG) /* For cross-checking during development: ensure dispatch count * matches cumulative interrupt counter init value sums. @@ -79269,16 +80578,17 @@ act = thr->callstack_curr; DUK_ASSERT(curr_pc >= DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())); DUK_ASSERT(curr_pc < DUK_HCOMPFUNC_GET_CODE_END(thr->heap, DUK__FUN())); - DUK_UNREF(act); /* if debugging disabled */ + DUK_UNREF(act); /* if debugging disabled */ - DUK_DDD(DUK_DDDPRINT("executing bytecode: pc=%ld, ins=0x%08lx, op=%ld, valstack_top=%ld/%ld, nregs=%ld --> %!I", - (long) (curr_pc - DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())), - (unsigned long) *curr_pc, - (long) DUK_DEC_OP(*curr_pc), - (long) (thr->valstack_top - thr->valstack), - (long) (thr->valstack_end - thr->valstack), - (long) (DUK__FUN() ? DUK__FUN()->nregs : -1), - (duk_instr_t) *curr_pc)); + DUK_DDD(DUK_DDDPRINT( + "executing bytecode: pc=%ld, ins=0x%08lx, op=%ld, valstack_top=%ld/%ld, nregs=%ld --> %!I", + (long) (curr_pc - DUK_HCOMPFUNC_GET_CODE_BASE(thr->heap, DUK__FUN())), + (unsigned long) *curr_pc, + (long) DUK_DEC_OP(*curr_pc), + (long) (thr->valstack_top - thr->valstack), + (long) (thr->valstack_end - thr->valstack), + (long) (DUK__FUN() ? DUK__FUN()->nregs : -1), + (duk_instr_t) *curr_pc)); } #endif @@ -79315,14 +80625,16 @@ */ op = (duk_uint8_t) DUK_DEC_OP(ins); switch (op) { - - /* Some useful macros. These access inner executor variables - * directly so they only apply within the executor. - */ + /* Some useful macros. These access inner executor variables + * directly so they only apply within the executor. + */ #if defined(DUK_USE_EXEC_PREFER_SIZE) -#define DUK__REPLACE_TOP_A_BREAK() { goto replace_top_a; } -#define DUK__REPLACE_TOP_BC_BREAK() { goto replace_top_bc; } -#define DUK__REPLACE_BOOL_A_BREAK(bval) { \ +#define DUK__REPLACE_TOP_A_BREAK() \ + { goto replace_top_a; } +#define DUK__REPLACE_TOP_BC_BREAK() \ + { goto replace_top_bc; } +#define DUK__REPLACE_BOOL_A_BREAK(bval) \ + { \ duk_bool_t duk__bval; \ duk__bval = (bval); \ DUK_ASSERT(duk__bval == 0 || duk__bval == 1); \ @@ -79330,9 +80642,18 @@ DUK__REPLACE_TOP_A_BREAK(); \ } #else -#define DUK__REPLACE_TOP_A_BREAK() { DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); break; } -#define DUK__REPLACE_TOP_BC_BREAK() { DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); break; } -#define DUK__REPLACE_BOOL_A_BREAK(bval) { \ +#define DUK__REPLACE_TOP_A_BREAK() \ + { \ + DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); \ + break; \ + } +#define DUK__REPLACE_TOP_BC_BREAK() \ + { \ + DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); \ + break; \ + } +#define DUK__REPLACE_BOOL_A_BREAK(bval) \ + { \ duk_bool_t duk__bval; \ duk_tval *duk__tvdst; \ duk__bval = (bval); \ @@ -79356,7 +80677,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__REGP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } @@ -79365,7 +80686,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__REGP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv2, tv1); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv2, tv1); /* side effects */ break; } @@ -79374,7 +80695,7 @@ tv1 = DUK__REGP_A(ins); tv2 = DUK__CONSTP_BC(ins); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } @@ -79394,18 +80715,18 @@ duk_int32_t val; val = (duk_int32_t) duk_get_int(thr, DUK_DEC_A(ins)); - val = (val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ + val = (val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ duk_push_int(thr, val); DUK__REPLACE_TOP_A_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LDINT: { duk_tval *tv1; duk_int32_t val; val = (duk_int32_t) DUK_DEC_BC(ins) - (duk_int32_t) DUK_BC_LDINT_BIAS; tv1 = DUK__REGP_A(ins); - DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ + DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ break; } case DUK_OP_LDINTX: { @@ -79421,11 +80742,12 @@ /* XXX: fast double-to-int conversion, we know number is integer in -0x80000000,0xffffffff. */ val = (duk_int32_t) DUK_TVAL_GET_NUMBER(tv1); #endif - val = (duk_int32_t) ((duk_uint32_t) val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ - DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ + val = + (duk_int32_t) ((duk_uint32_t) val << DUK_BC_LDINTX_SHIFT) + (duk_int32_t) DUK_DEC_BC(ins); /* no bias */ + DUK_TVAL_SET_I32_UPDREF(thr, tv1, val); /* side effects */ break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_LDTHIS: { @@ -79448,46 +80770,46 @@ duk_push_false(thr); DUK__REPLACE_TOP_BC_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LDTHIS: { /* Note: 'this' may be bound to any value, not just an object */ duk_tval *tv1, *tv2; tv1 = DUK__REGP_BC(ins); - tv2 = thr->valstack_bottom - 1; /* 'this binding' is just under bottom */ + tv2 = thr->valstack_bottom - 1; /* 'this binding' is just under bottom */ DUK_ASSERT(tv2 >= thr->valstack); - DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF_FAST(thr, tv1, tv2); /* side effects */ break; } case DUK_OP_LDUNDEF: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv1); /* side effects */ break; } case DUK_OP_LDNULL: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_NULL_UPDREF(thr, tv1); /* side effects */ + DUK_TVAL_SET_NULL_UPDREF(thr, tv1); /* side effects */ break; } case DUK_OP_LDTRUE: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 1); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 1); /* side effects */ break; } case DUK_OP_LDFALSE: { duk_tval *tv1; tv1 = DUK__REGP_BC(ins); - DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 0); /* side effects */ + DUK_TVAL_SET_BOOLEAN_UPDREF(thr, tv1, 0); /* side effects */ break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_BNOT: { duk__vm_bitwise_not(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins)); @@ -79505,7 +80827,7 @@ duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_UNM: { duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), DUK_OP_UNM); break; @@ -79514,7 +80836,7 @@ duk__vm_arith_unary_op(thr, DUK_DEC_BC(ins), DUK_DEC_A(ins), DUK_OP_UNP); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_TYPEOF: { @@ -79525,7 +80847,7 @@ duk_push_hstring_stridx(thr, stridx); DUK__REPLACE_TOP_A_BREAK(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_TYPEOF: { duk_tval *tv; duk_small_uint_t stridx; @@ -79539,7 +80861,7 @@ DUK_TVAL_SET_STRING_UPDREF(thr, tv, h_str); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_TYPEOFID: { duk_small_uint_t stridx; @@ -79557,13 +80879,13 @@ tv = DUK__CONSTP_BC(ins); DUK_ASSERT(DUK_TVAL_IS_STRING(tv)); name = DUK_TVAL_GET_STRING(tv); - tv = NULL; /* lookup has side effects */ + tv = NULL; /* lookup has side effects */ act = thr->callstack_curr; if (duk_js_getvar_activation(thr, act, name, 0 /*throw*/)) { /* -> ... val this */ tv = DUK_GET_TVAL_NEGIDX(thr, -2); stridx = duk_js_typeof_stridx(tv); - tv = NULL; /* no longer needed */ + tv = NULL; /* no longer needed */ duk_pop_2_unsafe(thr); } else { /* unresolvable, no stack changes */ @@ -79573,36 +80895,40 @@ #if defined(DUK_USE_EXEC_PREFER_SIZE) duk_push_hstring_stridx(thr, stridx); DUK__REPLACE_TOP_A_BREAK(); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ h_str = DUK_HTHREAD_GET_STRING(thr, stridx); tv = DUK__REGP_A(ins); DUK_TVAL_SET_STRING_UPDREF(thr, tv, h_str); break; -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ } /* Equality: E5 Sections 11.9.1, 11.9.3 */ -#define DUK__EQ_BODY(barg,carg) { \ +#define DUK__EQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_equals(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__NEQ_BODY(barg,carg) { \ +#define DUK__NEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_equals(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ tmp ^= 1; \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__SEQ_BODY(barg,carg) { \ +#define DUK__SEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_strict_equals((barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__SNEQ_BODY(barg,carg) { \ +#define DUK__SNEQ_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_strict_equals((barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ @@ -79630,7 +80956,7 @@ case DUK_OP_SNEQ_RC: case DUK_OP_SNEQ_CC: DUK__SNEQ_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_EQ_RR: DUK__EQ_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_EQ_CR: @@ -79663,18 +80989,19 @@ DUK__SNEQ_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_SNEQ_CC: DUK__SNEQ_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ -#define DUK__COMPARE_BODY(arg1,arg2,flags) { \ +#define DUK__COMPARE_BODY(arg1, arg2, flags) \ + { \ duk_bool_t tmp; \ tmp = duk_js_compare_helper(thr, (arg1), (arg2), (flags)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__GT_BODY(barg,carg) DUK__COMPARE_BODY((carg), (barg), 0) -#define DUK__GE_BODY(barg,carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) -#define DUK__LT_BODY(barg,carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) -#define DUK__LE_BODY(barg,carg) DUK__COMPARE_BODY((carg), (barg), DUK_COMPARE_FLAG_NEGATE) +#define DUK__GT_BODY(barg, carg) DUK__COMPARE_BODY((carg), (barg), 0) +#define DUK__GE_BODY(barg, carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST | DUK_COMPARE_FLAG_NEGATE) +#define DUK__LT_BODY(barg, carg) DUK__COMPARE_BODY((barg), (carg), DUK_COMPARE_FLAG_EVAL_LEFT_FIRST) +#define DUK__LE_BODY(barg, carg) DUK__COMPARE_BODY((carg), (barg), DUK_COMPARE_FLAG_NEGATE) #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_GT_RR: case DUK_OP_GT_CR: @@ -79696,7 +81023,7 @@ case DUK_OP_LE_RC: case DUK_OP_LE_CC: DUK__LE_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_GT_RR: DUK__GT_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_GT_CR: @@ -79729,7 +81056,7 @@ DUK__LE_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_LE_CC: DUK__LE_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* No size optimized variant at present for IF. */ case DUK_OP_IFTRUE_R: { @@ -79766,7 +81093,7 @@ duk__vm_arith_add(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins)); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_ADD_RR: { duk__vm_arith_add(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins)); break; @@ -79783,7 +81110,7 @@ duk__vm_arith_add(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins)); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_SUB_RR: @@ -79807,13 +81134,13 @@ case DUK_OP_EXP_CR: case DUK_OP_EXP_RC: case DUK_OP_EXP_CC: -#endif /* DUK_USE_ES7_EXP_OPERATOR */ +#endif /* DUK_USE_ES7_EXP_OPERATOR */ { /* XXX: could leave value on stack top and goto replace_top_a; */ duk__vm_arith_binary_op(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_SUB_RR: { duk__vm_arith_binary_op(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins), DUK_OP_SUB); break; @@ -79895,8 +81222,8 @@ duk__vm_arith_binary_op(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins), DUK_OP_EXP); break; } -#endif /* DUK_USE_ES7_EXP_OPERATOR */ -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_ES7_EXP_OPERATOR */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_BAND_RR: @@ -79927,7 +81254,7 @@ duk__vm_bitwise_binary_op(thr, DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins), DUK_DEC_A(ins), op); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_BAND_RR: { duk__vm_bitwise_binary_op(thr, DUK__REGP_B(ins), DUK__REGP_C(ins), DUK_DEC_A(ins), DUK_OP_BAND); break; @@ -80024,16 +81351,18 @@ duk__vm_bitwise_binary_op(thr, DUK__CONSTP_B(ins), DUK__CONSTP_C(ins), DUK_DEC_A(ins), DUK_OP_BASR); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* For INSTOF and IN, B is always a register. */ -#define DUK__INSTOF_BODY(barg,carg) { \ +#define DUK__INSTOF_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_instanceof(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ DUK__REPLACE_BOOL_A_BREAK(tmp); \ } -#define DUK__IN_BODY(barg,carg) { \ +#define DUK__IN_BODY(barg, carg) \ + { \ duk_bool_t tmp; \ tmp = duk_js_in(thr, (barg), (carg)); \ DUK_ASSERT(tmp == 0 || tmp == 1); \ @@ -80050,7 +81379,7 @@ case DUK_OP_IN_RC: case DUK_OP_IN_CC: DUK__IN_BODY(DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_INSTOF_RR: DUK__INSTOF_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_INSTOF_CR: @@ -80067,9 +81396,9 @@ DUK__IN_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_IN_CC: DUK__IN_BODY(DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ - /* Pre/post inc/dec for register variables, important for loops. */ + /* Pre/post inc/dec for register variables, important for loops. */ #if defined(DUK_USE_EXEC_PREFER_SIZE) case DUK_OP_PREINCR: case DUK_OP_PREDECR: @@ -80085,7 +81414,7 @@ duk__prepost_incdec_var_helper(thr, DUK_DEC_A(ins), DUK__CONSTP_BC(ins), op, DUK__STRICT()); break; } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_PREINCR: { duk__prepost_incdec_reg_helper(thr, DUK__REGP_A(ins), DUK__REGP_BC(ins), DUK_OP_PREINCR); break; @@ -80118,7 +81447,7 @@ duk__prepost_incdec_var_helper(thr, DUK_DEC_A(ins), DUK__CONSTP_BC(ins), DUK_OP_POSTDECV, DUK__STRICT()); break; } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* XXX: Move to separate helper, optimize for perf/size separately. */ /* Preinc/predec for object properties. */ @@ -80145,7 +81474,7 @@ duk_double_t x, y, z; #if !defined(DUK_USE_EXEC_PREFER_SIZE) duk_tval *tv_dst; -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* A -> target reg * B -> object reg/const (may be const e.g. in "'foo'1") @@ -80163,10 +81492,10 @@ tv_obj = DUK__REGCONSTP_B(ins); tv_key = DUK__REGCONSTP_C(ins); - rc = duk_hobject_getprop(thr, tv_obj, tv_key); /* -> val */ - DUK_UNREF(rc); /* ignore */ - tv_obj = NULL; /* invalidated */ - tv_key = NULL; /* invalidated */ + rc = duk_hobject_getprop(thr, tv_obj, tv_key); /* -> val */ + DUK_UNREF(rc); /* ignore */ + tv_obj = NULL; /* invalidated */ + tv_key = NULL; /* invalidated */ /* XXX: Fastint fast path would be useful here. Also fastints * now lose their fastint status in current handling which is @@ -80187,9 +81516,9 @@ tv_obj = DUK__REGCONSTP_B(ins); tv_key = DUK__REGCONSTP_C(ins); rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, DUK__STRICT()); - DUK_UNREF(rc); /* ignore */ - tv_obj = NULL; /* invalidated */ - tv_key = NULL; /* invalidated */ + DUK_UNREF(rc); /* ignore */ + tv_obj = NULL; /* invalidated */ + tv_key = NULL; /* invalidated */ duk_pop_unsafe(thr); z = (ins & DUK_BC_INCDECP_FLAG_POST) ? x : y; @@ -80207,7 +81536,8 @@ * Occurs relatively often in object oriented code. */ -#define DUK__GETPROP_BODY(barg,carg) { \ +#define DUK__GETPROP_BODY(barg, carg) \ + { \ /* A -> target reg \ * B -> object reg/const (may be const e.g. in "'foo'1") \ * C -> key reg/const \ @@ -80215,7 +81545,8 @@ (void) duk_hobject_getprop(thr, (barg), (carg)); \ DUK__REPLACE_TOP_A_BREAK(); \ } -#define DUK__GETPROPC_BODY(barg,carg) { \ +#define DUK__GETPROPC_BODY(barg, carg) \ + { \ /* Same as GETPROP but callability check for property-based calls. */ \ duk_tval *tv__targ; \ (void) duk_hobject_getprop(thr, (barg), (carg)); \ @@ -80230,7 +81561,8 @@ } \ DUK__REPLACE_TOP_A_BREAK(); \ } -#define DUK__PUTPROP_BODY(aarg,barg,carg) { \ +#define DUK__PUTPROP_BODY(aarg, barg, carg) \ + { \ /* A -> object reg \ * B -> key reg/const \ * C -> value reg/const \ @@ -80241,7 +81573,8 @@ (void) duk_hobject_putprop(thr, (aarg), (barg), (carg), DUK__STRICT()); \ break; \ } -#define DUK__DELPROP_BODY(barg,carg) { \ +#define DUK__DELPROP_BODY(barg, carg) \ + { \ /* A -> result reg \ * B -> object reg \ * C -> key reg/const \ @@ -80270,9 +81603,9 @@ case DUK_OP_PUTPROP_CC: DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__REGCONSTP_B(ins), DUK__REGCONSTP_C(ins)); case DUK_OP_DELPROP_RR: - case DUK_OP_DELPROP_RC: /* B is always reg */ + case DUK_OP_DELPROP_RC: /* B is always reg */ DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__REGCONSTP_C(ins)); -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_GETPROP_RR: DUK__GETPROP_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_GETPROP_CR: @@ -80299,11 +81632,11 @@ DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__REGP_B(ins), DUK__CONSTP_C(ins)); case DUK_OP_PUTPROP_CC: DUK__PUTPROP_BODY(DUK__REGP_A(ins), DUK__CONSTP_B(ins), DUK__CONSTP_C(ins)); - case DUK_OP_DELPROP_RR: /* B is always reg */ + case DUK_OP_DELPROP_RR: /* B is always reg */ DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__REGP_C(ins)); case DUK_OP_DELPROP_RC: DUK__DELPROP_BODY(DUK__REGP_B(ins), DUK__CONSTP_C(ins)); -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ /* No fast path for DECLVAR now, it's quite a rare instruction. */ case DUK_OP_DECLVAR_RR: @@ -80336,7 +81669,7 @@ if (is_func_decl) { duk_push_tval(thr, DUK__REGCONSTP_C(ins)); } else { - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } tv1 = DUK_GET_TVAL_NEGIDX(thr, -1); @@ -80372,11 +81705,11 @@ */ duk_push_tval(thr, DUK__REGCONSTP_C(ins)); - duk_push_tval(thr, DUK__REGCONSTP_B(ins)); /* -> ... escaped_source bytecode */ - duk_regexp_create_instance(thr); /* -> ... regexp_instance */ + duk_push_tval(thr, DUK__REGCONSTP_B(ins)); /* -> ... escaped_source bytecode */ + duk_regexp_create_instance(thr); /* -> ... regexp_instance */ DUK__REPLACE_TOP_A_BREAK(); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* XXX: 'c' is unused, use whole BC, etc. */ case DUK_OP_CSVAR_RR: @@ -80405,13 +81738,13 @@ name = DUK_TVAL_GET_STRING(tv1); DUK_ASSERT(name != NULL); act = thr->callstack_curr; - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ idx = (duk_uint_fast_t) DUK_DEC_A(ins); /* Could add direct value stack handling. */ - duk_replace(thr, (duk_idx_t) (idx + 1)); /* 'this' binding */ - duk_replace(thr, (duk_idx_t) idx); /* variable value (function, we hope, not checked here) */ + duk_replace(thr, (duk_idx_t) (idx + 1)); /* 'this' binding */ + duk_replace(thr, (duk_idx_t) idx); /* variable value (function, we hope, not checked here) */ break; } @@ -80426,7 +81759,9 @@ */ DUK_DDD(DUK_DDDPRINT("CLOSURE to target register %ld, fnum %ld (count %ld)", - (long) DUK_DEC_A(ins), (long) DUK_DEC_BC(ins), (long) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN()))); + (long) DUK_DEC_A(ins), + (long) DUK_DEC_BC(ins), + (long) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN()))); DUK_ASSERT_DISABLE(bc >= 0); /* unsigned */ DUK_ASSERT((duk_uint_t) bc < (duk_uint_t) DUK_HCOMPFUNC_GET_FUNCS_COUNT(thr->heap, DUK__FUN())); @@ -80437,8 +81772,8 @@ DUK_ASSERT(fun_temp != NULL); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(fun_temp)); - DUK_DDD(DUK_DDDPRINT("CLOSURE: function template is: %p -> %!O", - (void *) fun_temp, (duk_heaphdr *) fun_temp)); + DUK_DDD( + DUK_DDDPRINT("CLOSURE: function template is: %p -> %!O", (void *) fun_temp, (duk_heaphdr *) fun_temp)); if (act->lex_env == NULL) { DUK_ASSERT(act->var_env == NULL); @@ -80452,11 +81787,7 @@ * new variable declaration environment, so only lex_env * matters here. */ - duk_js_push_closure(thr, - (duk_hcompfunc *) fun_temp, - act->var_env, - act->lex_env, - 1 /*add_auto_proto*/); + duk_js_push_closure(thr, (duk_hcompfunc *) fun_temp, act->var_env, act->lex_env, 1 /*add_auto_proto*/); DUK__REPLACE_TOP_A_BREAK(); } @@ -80471,8 +81802,8 @@ DUK_ASSERT(name != NULL); act = thr->callstack_curr; DUK_ASSERT(act != NULL); - (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ - duk_pop_unsafe(thr); /* 'this' binding is not needed here */ + (void) duk_js_getvar_activation(thr, act, name, 1 /*throw*/); /* -> ... val this */ + duk_pop_unsafe(thr); /* 'this' binding is not needed here */ DUK__REPLACE_TOP_A_BREAK(); } @@ -80490,7 +81821,7 @@ * should be reworked. */ - tv1 = DUK__REGP_A(ins); /* val */ + tv1 = DUK__REGP_A(ins); /* val */ act = thr->callstack_curr; duk_js_putvar_activation(thr, act, name, tv1, DUK__STRICT()); break; @@ -80520,7 +81851,8 @@ break; } -#define DUK__RETURN_SHARED() do { \ +#define DUK__RETURN_SHARED() \ + do { \ duk_small_uint_t ret_result; \ /* duk__handle_return() is guaranteed never to throw, except \ * for potential out-of-memory situations which will then \ @@ -80539,14 +81871,14 @@ case DUK_OP_RETCONST: case DUK_OP_RETCONSTN: case DUK_OP_RETUNDEF: { - /* BC -> return value reg/const */ + /* BC -> return value reg/const */ DUK__SYNC_AND_NULL_CURR_PC(); if (op == DUK_OP_RETREG) { duk_push_tval(thr, DUK__REGP_BC(ins)); } else if (op == DUK_OP_RETUNDEF) { - DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ + DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* valstack policy */ thr->valstack_top++; } else { DUK_ASSERT(op == DUK_OP_RETCONST || op == DUK_OP_RETCONSTN); @@ -80555,7 +81887,7 @@ DUK__RETURN_SHARED(); } -#else /* DUK_USE_EXEC_PREFER_SIZE */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_RETREG: { duk_tval *tv; @@ -80585,18 +81917,18 @@ DUK_TVAL_SET_TVAL(thr->valstack_top, tv); #if defined(DUK_USE_REFERENCE_COUNTING) /* Without refcounting only RETCONSTN is used. */ - DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv)); /* no INCREF for this constant */ + DUK_ASSERT(!DUK_TVAL_IS_HEAP_ALLOCATED(tv)); /* no INCREF for this constant */ #endif thr->valstack_top++; DUK__RETURN_SHARED(); } case DUK_OP_RETUNDEF: { DUK__SYNC_AND_NULL_CURR_PC(); - thr->valstack_top++; /* value at valstack top is already undefined by valstack policy */ + thr->valstack_top++; /* value at valstack top is already undefined by valstack policy */ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); DUK__RETURN_SHARED(); } -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ case DUK_OP_LABEL: { duk_activation *act; @@ -80609,8 +81941,8 @@ DUK_ASSERT(cat != NULL); cat->flags = (duk_uint32_t) (DUK_CAT_TYPE_LABEL | (bc << DUK_CAT_LABEL_SHIFT)); - cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ - cat->idx_base = 0; /* unused for label */ + cat->pc_base = (duk_instr_t *) curr_pc; /* pre-incremented, points to first jump slot */ + cat->idx_base = 0; /* unused for label */ cat->h_varname = NULL; act = thr->callstack_curr; @@ -80620,10 +81952,13 @@ DUK_DDD(DUK_DDDPRINT("LABEL catcher: flags=0x%08lx, pc_base=%ld, " "idx_base=%ld, h_varname=%!O, label_id=%ld", - (long) cat->flags, (long) cat->pc_base, - (long) cat->idx_base, (duk_heaphdr *) cat->h_varname, (long) DUK_CAT_GET_LABEL(cat))); + (long) cat->flags, + (long) cat->pc_base, + (long) cat->idx_base, + (duk_heaphdr *) cat->h_varname, + (long) DUK_CAT_GET_LABEL(cat))); - curr_pc += 2; /* skip jump slots */ + curr_pc += 2; /* skip jump slots */ break; } @@ -80665,7 +82000,7 @@ /* XXX: move to helper, too large to be inline here */ case DUK_OP_TRYCATCH: { duk__handle_op_trycatch(thr, ins, curr_pc); - curr_pc += 2; /* skip jump slots */ + curr_pc += 2; /* skip jump slots */ break; } @@ -80710,8 +82045,8 @@ (duk_tval *) duk_get_tval(thr, -1))); #if defined(DUK_USE_AUGMENT_ERROR_THROW) duk_err_augment_error_throw(thr); - DUK_DDD(DUK_DDDPRINT("THROW ERROR (BYTECODE): %!dT (after throw augment)", - (duk_tval *) duk_get_tval(thr, -1))); + DUK_DDD( + DUK_DDDPRINT("THROW ERROR (BYTECODE): %!dT (after throw augment)", (duk_tval *) duk_get_tval(thr, -1))); #endif duk_err_setup_ljstate1(thr, DUK_LJ_TYPE_THROW, DUK_GET_TVAL_NEGIDX(thr, -1)); @@ -80719,7 +82054,7 @@ duk_err_check_debugger_integration(thr); #endif - DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ + DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL); /* always in executor */ duk_err_longjmp(thr); DUK_UNREACHABLE(); break; @@ -80756,20 +82091,19 @@ DUK_TVAL_SET_TVAL(&tv_tmp2, tv2); tv3 = DUK__REGP(a); DUK_TVAL_SET_TVAL(tv1, tv3); - DUK_TVAL_INCREF(thr, tv1); /* no side effects */ - DUK_TVAL_SET_UNDEFINED(tv2); /* no need for incref */ + DUK_TVAL_INCREF(thr, tv1); /* no side effects */ + DUK_TVAL_SET_UNDEFINED(tv2); /* no need for incref */ DUK_TVAL_DECREF(thr, &tv_tmp1); DUK_TVAL_DECREF(thr, &tv_tmp2); #endif break; } - - /* XXX: in some cases it's faster NOT to reuse the value - * stack but rather copy the arguments on top of the stack - * (mainly when the calling value stack is large and the value - * stack resize would be large). - */ + /* XXX: in some cases it's faster NOT to reuse the value + * stack but rather copy the arguments on top of the stack + * (mainly when the calling value stack is large and the value + * stack resize would be large). + */ case DUK_OP_CALL0: case DUK_OP_CALL1: @@ -80930,7 +82264,7 @@ } count = (duk_small_uint_fast_t) DUK_DEC_C(ins); - DUK_ASSERT(count > 0); /* compiler guarantees */ + DUK_ASSERT(count > 0); /* compiler guarantees */ idx_end = idx + count; #if defined(DUK_USE_EXEC_INDIRECT_BOUND_CHECK) @@ -80954,11 +82288,10 @@ /* XXX: faster initialization (direct access or better primitives) */ duk_dup(thr, (duk_idx_t) idx); duk_dup(thr, (duk_idx_t) (idx + 1)); - duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_VALUE | - DUK_DEFPROP_FORCE | - DUK_DEFPROP_SET_WRITABLE | - DUK_DEFPROP_SET_ENUMERABLE | - DUK_DEFPROP_SET_CONFIGURABLE); + duk_def_prop(thr, + obj_idx, + DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE | DUK_DEFPROP_SET_WRITABLE | + DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE); idx += 2; } while (idx < idx_end); break; @@ -80993,7 +82326,7 @@ } count = (duk_small_uint_fast_t) DUK_DEC_C(ins); - DUK_ASSERT(count > 0 + 1); /* compiler guarantees */ + DUK_ASSERT(count > 0 + 1); /* compiler guarantees */ idx_end = idx + count; #if defined(DUK_USE_EXEC_INDIRECT_BOUND_CHECK) @@ -81120,7 +82453,7 @@ duk_push_new_target(thr); DUK__REPLACE_TOP_BC_BREAK(); } -#endif /* DUK_USE_ES6 */ +#endif /* DUK_USE_ES6 */ #if !defined(DUK_USE_EXEC_PREFER_SIZE) #if !defined(DUK_USE_ES7_EXP_OPERATOR) @@ -81183,16 +82516,16 @@ case DUK_OP_UNUSED253: case DUK_OP_UNUSED254: case DUK_OP_UNUSED255: - /* Force all case clauses to map to an actual handler - * so that the compiler can emit a jump without a bounds - * check: the switch argument is a duk_uint8_t so that - * the compiler may be able to figure it out. This is - * a small detail and obviously compiler dependent. - */ - /* default: clause omitted on purpose */ -#else /* DUK_USE_EXEC_PREFER_SIZE */ + /* Force all case clauses to map to an actual handler + * so that the compiler can emit a jump without a bounds + * check: the switch argument is a duk_uint8_t so that + * the compiler may be able to figure it out. This is + * a small detail and obviously compiler dependent. + */ + /* default: clause omitted on purpose */ +#else /* DUK_USE_EXEC_PREFER_SIZE */ default: -#endif /* DUK_USE_EXEC_PREFER_SIZE */ +#endif /* DUK_USE_EXEC_PREFER_SIZE */ { /* Default case catches invalid/unsupported opcodes. */ DUK_D(DUK_DPRINT("invalid opcode: %ld - %!I", (long) op, ins)); @@ -81200,7 +82533,7 @@ break; } - } /* end switch */ + } /* end switch */ continue; @@ -81211,10 +82544,10 @@ */ #if defined(DUK_USE_EXEC_PREFER_SIZE) - replace_top_a: + replace_top_a: DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_A(ins)); continue; - replace_top_bc: + replace_top_bc: DUK__REPLACE_TO_TVPTR(thr, DUK__REGP_BC(ins)); continue; #endif @@ -81222,7 +82555,7 @@ DUK_WO_NORETURN(return;); #if !defined(DUK_USE_VERBOSE_EXECUTOR_ERRORS) - internal_error: +internal_error: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return;); #endif @@ -81454,19 +82787,10 @@ /* Quite lenient, e.g. allow empty as zero, but don't allow trailing * garbage. */ - s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | - DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_PLUS | - DUK_S2N_FLAG_ALLOW_MINUS | - DUK_S2N_FLAG_ALLOW_INF | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO | - DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT | - DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT | - DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT; + s2n_flags = DUK_S2N_FLAG_TRIM_WHITE | DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_PLUS | DUK_S2N_FLAG_ALLOW_MINUS | + DUK_S2N_FLAG_ALLOW_INF | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO | DUK_S2N_FLAG_ALLOW_LEADING_ZERO | + DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT | DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT | DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT; duk_numconv_parse(thr, 10 /*radix*/, s2n_flags); @@ -81476,9 +82800,9 @@ #else thr->valstack_top--; DUK_ASSERT(DUK_TVAL_IS_NUMBER(thr->valstack_top)); - DUK_ASSERT(DUK_TVAL_IS_DOUBLE(thr->valstack_top)); /* no fastint conversion in numconv now */ + DUK_ASSERT(DUK_TVAL_IS_DOUBLE(thr->valstack_top)); /* no fastint conversion in numconv now */ DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(thr->valstack_top)); - d = DUK_TVAL_GET_DOUBLE(thr->valstack_top); /* assumes not a fastint */ + d = DUK_TVAL_GET_DOUBLE(thr->valstack_top); /* assumes not a fastint */ DUK_TVAL_SET_UNDEFINED(thr->valstack_top); #endif @@ -81517,11 +82841,11 @@ duk_push_hstring(thr, h); return duk__tonumber_string_raw(thr); } - case DUK_TAG_BUFFER: /* plain buffer treated like object */ + case DUK_TAG_BUFFER: /* plain buffer treated like object */ case DUK_TAG_OBJECT: { duk_double_t d; duk_push_tval(thr, tv); - duk_to_primitive(thr, -1, DUK_HINT_NUMBER); /* 'tv' becomes invalid */ + duk_to_primitive(thr, -1, DUK_HINT_NUMBER); /* 'tv' becomes invalid */ /* recursive call for a primitive value (guaranteed not to cause second * recursion). @@ -81576,7 +82900,7 @@ */ return duk_double_trunc_towards_zero(x); } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* NaN and Infinity have the same exponent so it's a cheap * initial check for the rare path. */ @@ -81589,12 +82913,12 @@ } else { return duk_double_trunc_towards_zero(x); } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ } DUK_INTERNAL duk_double_t duk_js_tointeger(duk_hthread *thr, duk_tval *tv) { /* XXX: fastint */ - duk_double_t d = duk_js_tonumber(thr, tv); /* invalidates tv */ + duk_double_t d = duk_js_tonumber(thr, tv); /* invalidates tv */ return duk_js_tointeger_number(d); } @@ -81604,11 +82928,11 @@ /* combined algorithm matching E5 Sections 9.5 and 9.6 */ DUK_LOCAL duk_double_t duk__toint32_touint32_helper(duk_double_t x, duk_bool_t is_toint32) { -#if defined (DUK_USE_PREFER_SIZE) +#if defined(DUK_USE_PREFER_SIZE) duk_small_int_t c; #endif -#if defined (DUK_USE_PREFER_SIZE) +#if defined(DUK_USE_PREFER_SIZE) c = (duk_small_int_t) DUK_FPCLASSIFY(x); if (c == DUK_FP_NAN || c == DUK_FP_ZERO || c == DUK_FP_INFINITE) { return 0.0; @@ -81626,18 +82950,18 @@ * differs from what Javascript wants (see Section 9.6). */ - x = DUK_FMOD(x, DUK_DOUBLE_2TO32); /* -> x in -2**32, 2**32 */ + x = DUK_FMOD(x, DUK_DOUBLE_2TO32); /* -> x in -2**32, 2**32 */ if (x < 0.0) { x += DUK_DOUBLE_2TO32; } - DUK_ASSERT(x >= 0 && x < DUK_DOUBLE_2TO32); /* -> x in 0, 2**32 */ + DUK_ASSERT(x >= 0 && x < DUK_DOUBLE_2TO32); /* -> x in 0, 2**32 */ if (is_toint32) { if (x >= DUK_DOUBLE_2TO31) { /* x in 2**31, 2**32 */ - x -= DUK_DOUBLE_2TO32; /* -> x in -2**31,2**31 */ + x -= DUK_DOUBLE_2TO32; /* -> x in -2**31,2**31 */ } } @@ -81653,15 +82977,14 @@ } #endif - d = duk_js_tonumber(thr, tv); /* invalidates tv */ + d = duk_js_tonumber(thr, tv); /* invalidates tv */ d = duk__toint32_touint32_helper(d, 1); DUK_ASSERT(DUK_FPCLASSIFY(d) == DUK_FP_ZERO || DUK_FPCLASSIFY(d) == DUK_FP_NORMAL); - DUK_ASSERT(d >= -2147483648.0 && d <= 2147483647.0); /* -0x80000000,0x7fffffff */ - DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_int32_t) d))); /* whole, won't clip */ + DUK_ASSERT(d >= -2147483648.0 && d <= 2147483647.0); /* -0x80000000,0x7fffffff */ + DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_int32_t) d))); /* whole, won't clip */ return (duk_int32_t) d; } - DUK_INTERNAL duk_uint32_t duk_js_touint32(duk_hthread *thr, duk_tval *tv) { duk_double_t d; @@ -81671,13 +82994,12 @@ } #endif - d = duk_js_tonumber(thr, tv); /* invalidates tv */ + d = duk_js_tonumber(thr, tv); /* invalidates tv */ d = duk__toint32_touint32_helper(d, 0); DUK_ASSERT(DUK_FPCLASSIFY(d) == DUK_FP_ZERO || DUK_FPCLASSIFY(d) == DUK_FP_NORMAL); - DUK_ASSERT(d >= 0.0 && d <= 4294967295.0); /* 0x00000000, 0xffffffff */ - DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_uint32_t) d))); /* whole, won't clip */ + DUK_ASSERT(d >= 0.0 && d <= 4294967295.0); /* 0x00000000, 0xffffffff */ + DUK_ASSERT(duk_double_equals(d, (duk_double_t) ((duk_uint32_t) d))); /* whole, won't clip */ return (duk_uint32_t) d; - } DUK_INTERNAL duk_uint16_t duk_js_touint16(duk_hthread *thr, duk_tval *tv) { @@ -81727,7 +83049,7 @@ return 1; } return 0; -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ /* Better equivalent algorithm. If the compiler is compliant, C and * ECMAScript semantics are identical for this particular comparison. * In particular, NaNs must never compare equal and zeroes must compare @@ -81747,7 +83069,7 @@ DUK_ASSERT(!(DUK_FPCLASSIFY(x) == DUK_FP_ZERO && DUK_FPCLASSIFY(y) == DUK_FP_ZERO)); return 0; } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ } DUK_LOCAL duk_bool_t duk__js_samevalue_number(duk_double_t x, duk_double_t y) { @@ -81777,7 +83099,7 @@ */ return (x == y); -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ duk_small_int_t cx = (duk_small_int_t) DUK_FPCLASSIFY(x); duk_small_int_t cy = (duk_small_int_t) DUK_FPCLASSIFY(y); @@ -81812,7 +83134,7 @@ } return 0; } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ } DUK_INTERNAL duk_bool_t duk_js_equals_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags) { @@ -81838,10 +83160,9 @@ } else { return 0; } - } - else + } else #endif - if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { + if (DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y)) { duk_double_t d1, d2; /* Catches both doubles and cases where only one argument is @@ -81915,7 +83236,7 @@ return 0; } - DUK_ASSERT(flags == 0); /* non-strict equality from here on */ + DUK_ASSERT(flags == 0); /* non-strict equality from here on */ /* * Types are different; various cases for non-strict comparison @@ -81972,34 +83293,29 @@ } /* String-number-symbol/object -> coerce object to primitive (apparently without hint), then try again. */ - if ((type_mask_x & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER)) && - (type_mask_y & DUK_TYPE_MASK_OBJECT)) { + if ((type_mask_x & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER)) && (type_mask_y & DUK_TYPE_MASK_OBJECT)) { /* No symbol check needed because symbols and strings are accepted. */ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -1, DUK_HINT_NONE); /* apparently no hint? */ + duk_to_primitive(thr, -1, DUK_HINT_NONE); /* apparently no hint? */ goto recursive_call; } - if ((type_mask_x & DUK_TYPE_MASK_OBJECT) && - (type_mask_y & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER))) { + if ((type_mask_x & DUK_TYPE_MASK_OBJECT) && (type_mask_y & (DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_NUMBER))) { /* No symbol check needed because symbols and strings are accepted. */ duk_push_tval(thr, tv_x); duk_push_tval(thr, tv_y); - duk_to_primitive(thr, -2, DUK_HINT_NONE); /* apparently no hint? */ + duk_to_primitive(thr, -2, DUK_HINT_NONE); /* apparently no hint? */ goto recursive_call; } /* Nothing worked -> not equal. */ return 0; - recursive_call: +recursive_call: /* Shared code path to call the helper again with arguments on stack top. */ { duk_bool_t rc; - rc = duk_js_equals_helper(thr, - DUK_GET_TVAL_NEGIDX(thr, -2), - DUK_GET_TVAL_NEGIDX(thr, -1), - 0 /*flags:nonstrict*/); + rc = duk_js_equals_helper(thr, DUK_GET_TVAL_NEGIDX(thr, -2), DUK_GET_TVAL_NEGIDX(thr, -1), 0 /*flags:nonstrict*/); duk_pop_2_unsafe(thr); return rc; } @@ -82016,7 +83332,10 @@ * needs to push stuff on the stack anyway... */ -DUK_INTERNAL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, const duk_uint8_t *buf2, duk_size_t len1, duk_size_t len2) { +DUK_INTERNAL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, + const duk_uint8_t *buf2, + duk_size_t len1, + duk_size_t len2) { duk_size_t prefix_len; duk_small_int_t rc; @@ -82025,9 +83344,7 @@ /* duk_memcmp() is guaranteed to return zero (equal) for zero length * inputs. */ - rc = duk_memcmp_unsafe((const void *) buf1, - (const void *) buf2, - (size_t) prefix_len); + rc = duk_memcmp_unsafe((const void *) buf1, (const void *) buf2, (size_t) prefix_len); if (rc < 0) { return -1; @@ -82069,7 +83386,7 @@ (duk_size_t) DUK_HSTRING_GET_BYTELEN(h2)); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_INTERNAL duk_small_int_t duk_js_buffer_compare(duk_heap *heap, duk_hbuffer *h1, duk_hbuffer *h2) { /* Similar to String comparison. */ @@ -82106,47 +83423,47 @@ s2 = (duk_small_int_t) DUK_SIGNBIT(d2); if (c1 == DUK_FP_NAN || c2 == DUK_FP_NAN) { - return 0; /* Always false, regardless of negation. */ + return 0; /* Always false, regardless of negation. */ } if (c1 == DUK_FP_ZERO && c2 == DUK_FP_ZERO) { /* For all combinations: +0 < +0, +0 < -0, -0 < +0, -0 < -0, * steps e, f, and g. */ - return retval; /* false */ + return retval; /* false */ } if (d1 == d2) { - return retval; /* false */ + return retval; /* false */ } if (c1 == DUK_FP_INFINITE && s1 == 0) { /* x == +Infinity */ - return retval; /* false */ + return retval; /* false */ } if (c2 == DUK_FP_INFINITE && s2 == 0) { /* y == +Infinity */ - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } if (c2 == DUK_FP_INFINITE && s2 != 0) { /* y == -Infinity */ - return retval; /* false */ + return retval; /* false */ } if (c1 == DUK_FP_INFINITE && s1 != 0) { /* x == -Infinity */ - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } if (d1 < d2) { - return retval ^ 1; /* true */ + return retval ^ 1; /* true */ } - return retval; /* false */ + return retval; /* false */ } -#else /* DUK_USE_PARANOID_MATH */ +#else /* DUK_USE_PARANOID_MATH */ DUK_LOCAL duk_bool_t duk__compare_number(duk_bool_t retval, duk_double_t d1, duk_double_t d2) { /* This comparison tree relies doesn't match the exact steps in * E5 Section 11.8.5 but should produce the same results. The @@ -82183,39 +83500,35 @@ * results in false return (see e.g. Section * 11.8.3) - hence special treatment here. */ - return 0; /* zero regardless of negation */ + return 0; /* zero regardless of negation */ } else { return retval; } } } } -#endif /* DUK_USE_PARANOID_MATH */ +#endif /* DUK_USE_PARANOID_MATH */ DUK_INTERNAL duk_bool_t duk_js_compare_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags) { duk_double_t d1, d2; duk_small_int_t rc; duk_bool_t retval; - DUK_ASSERT(DUK_COMPARE_FLAG_NEGATE == 1); /* Rely on this flag being lowest. */ + DUK_ASSERT(DUK_COMPARE_FLAG_NEGATE == 1); /* Rely on this flag being lowest. */ retval = flags & DUK_COMPARE_FLAG_NEGATE; DUK_ASSERT(retval == 0 || retval == 1); /* Fast path for fastints */ #if defined(DUK_USE_FASTINT) if (DUK_LIKELY(DUK_TVAL_IS_FASTINT(tv_x) && DUK_TVAL_IS_FASTINT(tv_y))) { - return duk__compare_fastint(retval, - DUK_TVAL_GET_FASTINT(tv_x), - DUK_TVAL_GET_FASTINT(tv_y)); + return duk__compare_fastint(retval, DUK_TVAL_GET_FASTINT(tv_x), DUK_TVAL_GET_FASTINT(tv_y)); } -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* Fast path for numbers (one of which may be a fastint) */ #if !defined(DUK_USE_PREFER_SIZE) if (DUK_LIKELY(DUK_TVAL_IS_NUMBER(tv_x) && DUK_TVAL_IS_NUMBER(tv_y))) { - return duk__compare_number(retval, - DUK_TVAL_GET_NUMBER(tv_x), - DUK_TVAL_GET_NUMBER(tv_y)); + return duk__compare_number(retval, DUK_TVAL_GET_NUMBER(tv_x), DUK_TVAL_GET_NUMBER(tv_y)); } #endif @@ -82282,7 +83595,7 @@ thr->valstack_top -= 2; tv_x = thr->valstack_top; tv_y = tv_x + 1; - DUK_TVAL_SET_UNDEFINED(tv_x); /* Value stack policy */ + DUK_TVAL_SET_UNDEFINED(tv_x); /* Value stack policy */ DUK_TVAL_SET_UNDEFINED(tv_y); #endif @@ -82336,8 +83649,8 @@ if (!skip_sym_check) { if (duk_get_method_stridx(thr, -1, DUK_STRIDX_WELLKNOWN_SYMBOL_HAS_INSTANCE)) { /* ... lhs rhs func */ - duk_insert(thr, -3); /* -> ... func lhs rhs */ - duk_swap_top(thr, -2); /* -> ... func rhs(this) lhs */ + duk_insert(thr, -3); /* -> ... func lhs rhs */ + duk_swap_top(thr, -2); /* -> ... func rhs(this) lhs */ duk_call_method(thr, 1); return duk_to_boolean_top_pop(thr); } @@ -82369,7 +83682,7 @@ if (DUK_HOBJECT_HAS_BOUNDFUNC(func)) { duk_push_tval(thr, &((duk_hboundfunc *) (void *) func)->target); duk_replace(thr, -2); - func = duk_require_hobject(thr, -1); /* lightfunc throws */ + func = duk_require_hobject(thr, -1); /* lightfunc throws */ /* Rely on Function.prototype.bind() never creating bound * functions whose target is not proper. @@ -82409,19 +83722,19 @@ DUK_ASSERT(val != NULL); break; case DUK_TAG_OBJECT: - skip_first = 1; /* Ignore object itself on first round. */ + skip_first = 1; /* Ignore object itself on first round. */ val = DUK_TVAL_GET_OBJECT(tv); DUK_ASSERT(val != NULL); break; default: goto pop2_and_false; } - DUK_ASSERT(val != NULL); /* Loop doesn't actually rely on this. */ + DUK_ASSERT(val != NULL); /* Loop doesn't actually rely on this. */ /* Look up .prototype of rval. Leave it on the value stack in case it * has been virtualized (e.g. getter, Proxy trap). */ - duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_PROTOTYPE); /* -> ... lval rval rval.prototype */ + duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_PROTOTYPE); /* -> ... lval rval rval.prototype */ #if defined(DUK_USE_VERBOSE_ERRORS) proto = duk_get_hobject(thr, -1); if (proto == NULL) { @@ -82474,24 +83787,24 @@ DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); DUK_WO_NORETURN(return 0;); - pop2_and_false: +pop2_and_false: duk_pop_2_unsafe(thr); return 0; - pop3_and_false: +pop3_and_false: duk_pop_3_unsafe(thr); return 0; - pop3_and_true: +pop3_and_true: duk_pop_3_unsafe(thr); return 1; - error_invalid_rval: +error_invalid_rval: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_INSTANCEOF_RVAL); DUK_WO_NORETURN(return 0;); #if defined(DUK_USE_VERBOSE_ERRORS) - error_invalid_rval_noproto: +error_invalid_rval_noproto: DUK_ERROR_TYPE(thr, DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO); DUK_WO_NORETURN(return 0;); #endif @@ -82543,9 +83856,7 @@ (void) duk_to_property_key_hstring(thr, -2); - retval = duk_hobject_hasprop(thr, - DUK_GET_TVAL_NEGIDX(thr, -1), - DUK_GET_TVAL_NEGIDX(thr, -2)); + retval = duk_hobject_hasprop(thr, DUK_GET_TVAL_NEGIDX(thr, -1), DUK_GET_TVAL_NEGIDX(thr, -2)); duk_pop_2_unsafe(thr); return retval; @@ -82705,7 +84016,7 @@ } res = 0xfffffffaUL + dig; DUK_ASSERT(res >= 0xfffffffaUL); - DUK_ASSERT_DISABLE(res <= 0xffffffffUL); /* range */ + DUK_ASSERT_DISABLE(res <= 0xffffffffUL); /* range */ } else { res = res * 10U + dig; if (DUK_UNLIKELY(res == 0)) { @@ -82730,7 +84041,7 @@ return res; - parse_fail: +parse_fail: return DUK_HSTRING_NO_ARRAY_INDEX; } @@ -82768,7 +84079,7 @@ } return duk_js_to_arrayindex_hstring_fast_known(h); } -#endif /* DUK_USE_HSTRING_ARRIDX */ +#endif /* DUK_USE_HSTRING_ARRIDX */ #line 1 "duk_js_var.c" /* * Identifier access and function closure handling. @@ -82810,10 +84121,10 @@ typedef struct { duk_hobject *env; - duk_hobject *holder; /* for object-bound identifiers */ - duk_tval *value; /* for register-bound and declarative env identifiers */ - duk_uint_t attrs; /* property attributes for identifier (relevant if value != NULL) */ - duk_bool_t has_this; /* for object-bound identifiers: provide 'this' binding */ + duk_hobject *holder; /* for object-bound identifiers */ + duk_tval *value; /* for register-bound and declarative env identifiers */ + duk_uint_t attrs; /* property attributes for identifier (relevant if value != NULL) */ + duk_bool_t has_this; /* for object-bound identifiers: provide 'this' binding */ } duk__id_lookup_result; /* @@ -82917,7 +84228,7 @@ DUK_ASSERT(fun_clos != NULL); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) fun_clos) == thr->builtinsDUK_BIDX_FUNCTION_PROTOTYPE); - duk_push_hobject(thr, &fun_temp->obj); /* -> ... closure template */ + duk_push_hobject(thr, &fun_temp->obj); /* -> ... closure template */ DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) fun_clos)); DUK_ASSERT(DUK_HCOMPFUNC_GET_DATA(thr->heap, fun_clos) == NULL); @@ -83025,9 +84336,9 @@ } /* -> ... closure template env */ - new_env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + new_env = + duk_hdecenv_alloc(thr, + DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(new_env != NULL); duk_push_hobject(thr, (duk_hobject *) new_env); @@ -83035,7 +84346,7 @@ DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) new_env, proto); DUK_HOBJECT_INCREF_ALLOWNULL(thr, proto); - DUK_ASSERT(new_env->thread == NULL); /* Closed. */ + DUK_ASSERT(new_env->thread == NULL); /* Closed. */ DUK_ASSERT(new_env->varmap == NULL); /* It's important that duk_xdef_prop() is a 'raw define' so that any @@ -83049,8 +84360,8 @@ */ (void) duk_get_prop_stridx_short(thr, -2, DUK_STRIDX_NAME); /* -> ... closure template env funcname */ - duk_dup_m4(thr); /* -> ... closure template env funcname closure */ - duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> ... closure template env */ + duk_dup_m4(thr); /* -> ... closure template env funcname closure */ + duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> ... closure template env */ /* envfuncname = closure */ /* ... closure template env */ @@ -83062,9 +84373,8 @@ duk_pop_unsafe(thr); /* ... closure template */ - } - else -#endif /* DUK_USE_FUNC_NAME_PROPERTY */ + } else +#endif /* DUK_USE_FUNC_NAME_PROPERTY */ { /* * Other cases (function declaration, anonymous function expression, @@ -83092,7 +84402,7 @@ DUK_HCOMPFUNC_SET_LEXENV(thr->heap, fun_clos, outer_lex_env); DUK_HCOMPFUNC_SET_VARENV(thr->heap, fun_clos, outer_var_env); - DUK_HOBJECT_INCREF(thr, outer_lex_env); /* NULLs not allowed; asserted on entry */ + DUK_HOBJECT_INCREF(thr, outer_lex_env); /* NULLs not allowed; asserted on entry */ DUK_HOBJECT_INCREF(thr, outer_var_env); } DUK_DDD(DUK_DDDPRINT("closure varenv -> %!ipO, lexenv -> %!ipO", @@ -83151,7 +84461,7 @@ DUK_DD(DUK_DDPRINT("closure length defaulted from nargs -> %ld", (long) len_value)); } - duk_push_uint(thr, len_value); /* ... closure template len_value */ + duk_push_uint(thr, len_value); /* ... closure template len_value */ duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C); /* @@ -83171,11 +84481,14 @@ /* ... closure template */ if (add_auto_proto) { - duk_push_object(thr); /* -> ... closure template newobj */ - duk_dup_m3(thr); /* -> ... closure template newobj closure */ - duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC); /* -> ... closure template newobj */ - duk_compact(thr, -1); /* compact the prototype */ - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); /* -> ... closure template */ + duk_push_object(thr); /* -> ... closure template newobj */ + duk_dup_m3(thr); /* -> ... closure template newobj closure */ + duk_xdef_prop_stridx_short(thr, + -2, + DUK_STRIDX_CONSTRUCTOR, + DUK_PROPDESC_FLAGS_WC); /* -> ... closure template newobj */ + duk_compact(thr, -1); /* compact the prototype */ + duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W); /* -> ... closure template */ } /* @@ -83216,7 +84529,7 @@ /* ... closure template name */ DUK_ASSERT(duk_is_string(thr, -1)); DUK_DD(DUK_DDPRINT("setting function instance name to %!T", duk_get_tval(thr, -1))); - duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); /* -> ... closure template */ + duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C); /* -> ... closure template */ } else { /* Anonymous functions don't have a .name in ES2015, so don't set * it on the instance either. The instance will then inherit @@ -83248,10 +84561,8 @@ DUK_ASSERT(duk_has_prop_stridx(thr, -2, DUK_STRIDX_LENGTH) != 0); DUK_ASSERT(add_auto_proto == 0 || duk_has_prop_stridx(thr, -2, DUK_STRIDX_PROTOTYPE) != 0); /* May be missing .name */ - DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || - duk_has_prop_stridx(thr, -2, DUK_STRIDX_CALLER) != 0); - DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || - duk_has_prop_stridx(thr, -2, DUK_STRIDX_LC_ARGUMENTS) != 0); + DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || duk_has_prop_stridx(thr, -2, DUK_STRIDX_CALLER) != 0); + DUK_ASSERT(!DUK_HOBJECT_HAS_STRICT(&fun_clos->obj) || duk_has_prop_stridx(thr, -2, DUK_STRIDX_LC_ARGUMENTS) != 0); /* * Finish @@ -83282,8 +84593,8 @@ duk_hstring *key; key = DUK_HOBJECT_E_GET_KEY(thr->heap, varmap, i); - DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ - DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ + DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ + DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ /* Predefine as 'undefined' to reserve a property slot. * This makes the unwind process (where register values @@ -83300,9 +84611,7 @@ /* shared helper */ DUK_INTERNAL -duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, - duk_hobject *func, - duk_size_t bottom_byteoff) { +duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, duk_hobject *func, duk_size_t bottom_byteoff) { duk_hdecenv *env; duk_hobject *parent; duk_hcompfunc *f; @@ -83318,15 +84627,13 @@ parent = thr->builtinsDUK_BIDX_GLOBAL_ENV; } - env = duk_hdecenv_alloc(thr, - DUK_HOBJECT_FLAG_EXTENSIBLE | - DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); + env = duk_hdecenv_alloc(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_DECENV)); DUK_ASSERT(env != NULL); duk_push_hobject(thr, (duk_hobject *) env); DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) env) == NULL); DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) env, parent); - DUK_HOBJECT_INCREF_ALLOWNULL(thr, parent); /* parent env is the prototype */ + DUK_HOBJECT_INCREF_ALLOWNULL(thr, parent); /* parent env is the prototype */ /* open scope information, for compiled functions only */ @@ -83360,15 +84667,14 @@ } DUK_INTERNAL -void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, - duk_activation *act) { +void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, duk_activation *act) { duk_hobject *func; duk_hobject *env; DUK_ASSERT(thr != NULL); func = DUK_ACT_GET_FUNC(act); DUK_ASSERT(func != NULL); - DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound functions are never in act 'func' */ + DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(func)); /* bound functions are never in act 'func' */ /* * Delayed initialization only occurs for 'NEWENV' functions. @@ -83397,7 +84703,7 @@ act->lex_env = env; act->var_env = env; - DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (here 2 times) */ + DUK_HOBJECT_INCREF(thr, env); /* XXX: incref by count (here 2 times) */ DUK_HOBJECT_INCREF(thr, env); duk_pop_unsafe(thr); @@ -83467,12 +84773,12 @@ duk_size_t regbase_byteoff; key = DUK_HOBJECT_E_GET_KEY(thr->heap, varmap, i); - DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ - DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ + DUK_ASSERT(key != NULL); /* assume keys are compact in _Varmap */ + DUK_ASSERT(!DUK_HOBJECT_E_SLOT_IS_ACCESSOR(thr->heap, varmap, i)); /* assume plain values */ tv = DUK_HOBJECT_E_GET_VALUE_TVAL_PTR(thr->heap, varmap, i); DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ + DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv)); regnum = (duk_uint_t) DUK_TVAL_GET_FASTINT_U32(tv); @@ -83481,8 +84787,10 @@ #endif regbase_byteoff = ((duk_hdecenv *) env)->regbase_byteoff; - DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum >= (duk_uint8_t *) thr->valstack); - DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum < (duk_uint8_t *) thr->valstack_top); + DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum >= + (duk_uint8_t *) thr->valstack); + DUK_ASSERT((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum < + (duk_uint8_t *) thr->valstack_top); /* Write register value into env as named properties. * If property already exists, overwrites silently. @@ -83496,7 +84804,8 @@ * out-of-memory error should be possible. If this guarantee * is not provided, problems like GH-476 may happen. */ - duk_push_tval(thr, (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum)); + duk_push_tval(thr, + (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + regbase_byteoff + sizeof(duk_tval) * regnum)); DUK_DDD(DUK_DDDPRINT("closing identifier %!O -> reg %ld, value %!T", (duk_heaphdr *) key, (long) regnum, @@ -83538,10 +84847,7 @@ /* lookup name from an open declarative record's registers */ DUK_LOCAL -duk_bool_t duk__getid_open_decl_env_regs(duk_hthread *thr, - duk_hstring *name, - duk_hdecenv *env, - duk__id_lookup_result *out) { +duk_bool_t duk__getid_open_decl_env_regs(duk_hthread *thr, duk_hstring *name, duk_hdecenv *env, duk__id_lookup_result *out) { duk_tval *tv; duk_size_t reg_rel; @@ -83565,20 +84871,20 @@ } DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv)); - DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ + DUK_ASSERT(DUK_TVAL_GET_NUMBER(tv) <= (duk_double_t) DUK_UINT32_MAX); /* limits */ #if defined(DUK_USE_FASTINT) DUK_ASSERT(DUK_TVAL_IS_FASTINT(tv)); reg_rel = (duk_size_t) DUK_TVAL_GET_FASTINT_U32(tv); #else reg_rel = (duk_size_t) DUK_TVAL_GET_NUMBER(tv); #endif - DUK_ASSERT_DISABLE(reg_rel >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(reg_rel >= 0); /* unsigned */ tv = (duk_tval *) (void *) ((duk_uint8_t *) env->thread->valstack + env->regbase_byteoff + sizeof(duk_tval) * reg_rel); - DUK_ASSERT(tv >= env->thread->valstack && tv < env->thread->valstack_end); /* XXX: more accurate? */ + DUK_ASSERT(tv >= env->thread->valstack && tv < env->thread->valstack_end); /* XXX: more accurate? */ out->value = tv; - out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ + out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ out->env = (duk_hobject *) env; out->holder = NULL; out->has_this = 0; @@ -83587,10 +84893,7 @@ /* lookup name from current activation record's functions' registers */ DUK_LOCAL -duk_bool_t duk__getid_activation_regs(duk_hthread *thr, - duk_hstring *name, - duk_activation *act, - duk__id_lookup_result *out) { +duk_bool_t duk__getid_activation_regs(duk_hthread *thr, duk_hstring *name, duk_activation *act, duk__id_lookup_result *out) { duk_tval *tv; duk_hobject *func; duk_hobject *varmap; @@ -83628,7 +84931,7 @@ tv += reg_rel; out->value = tv; - out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ + out->attrs = DUK_PROPDESC_FLAGS_W; /* registers are mutable, non-deletable */ out->env = NULL; out->holder = NULL; out->has_this = 0; @@ -83684,9 +84987,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(found from register bindings when env=NULL)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } @@ -83723,8 +85029,7 @@ env = thr->builtinsDUK_BIDX_GLOBAL_ENV; } - DUK_DDD(DUK_DDDPRINT("continue lookup from env: %!iO", - (duk_heaphdr *) env)); + DUK_DDD(DUK_DDDPRINT("continue lookup from env: %!iO", (duk_heaphdr *) env)); } /* @@ -83767,9 +85072,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(declarative environment record, scope open, found in regs)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } @@ -83784,9 +85092,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(declarative environment record, found in properties)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } } else { @@ -83831,7 +85142,7 @@ found = duk_hobject_hasprop(thr, &tv_target_tmp, &tv_name); } else -#endif /* DUK_USE_ES6_PROXY */ +#endif /* DUK_USE_ES6_PROXY */ { /* XXX: duk_hobject_hasprop() would be correct for * non-Proxy objects too, but it is about ~20-25% @@ -83842,8 +85153,8 @@ } if (found) { - out->value = NULL; /* can't get value, may be accessor */ - out->attrs = 0; /* irrelevant when out->value == NULL */ + out->value = NULL; /* can't get value, may be accessor */ + out->attrs = 0; /* irrelevant when out->value == NULL */ out->env = env; out->holder = target; out->has_this = ((duk_hobjenv *) env)->has_this; @@ -83851,9 +85162,12 @@ DUK_DDD(DUK_DDDPRINT("duk__get_identifier_reference successful: " "name=%!O -> value=%!T, attrs=%ld, has_this=%ld, env=%!O, holder=%!O " "(object environment record)", - (duk_heaphdr *) name, (duk_tval *) out->value, - (long) out->attrs, (long) out->has_this, - (duk_heaphdr *) out->env, (duk_heaphdr *) out->holder)); + (duk_heaphdr *) name, + (duk_tval *) out->value, + (long) out->attrs, + (long) out->has_this, + (duk_heaphdr *) out->env, + (duk_heaphdr *) out->holder)); return 1; } } @@ -83864,10 +85178,10 @@ goto fail_not_found; } - if (DUK_UNLIKELY(sanity-- == 0)) { - DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); + if (DUK_UNLIKELY(sanity-- == 0)) { + DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); DUK_WO_NORETURN(return 0;); - } + } env = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, env); } @@ -83875,7 +85189,7 @@ * Not found (even in global object) */ - fail_not_found: +fail_not_found: return 0; } @@ -83894,7 +85208,7 @@ * a 'strict' parameter. */ -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_hasvar_envrec(duk_hthread *thr, duk_hobject *env, @@ -83950,11 +85264,7 @@ */ DUK_LOCAL -duk_bool_t duk__getvar_helper(duk_hthread *thr, - duk_hobject *env, - duk_activation *act, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk__getvar_helper(duk_hthread *thr, duk_hobject *env, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag) { duk__id_lookup_result ref; duk_tval tv_tmp_obj; duk_tval tv_tmp_key; @@ -83962,8 +85272,11 @@ DUK_DDD(DUK_DDDPRINT("getvar: thr=%p, env=%p, act=%p, name=%!O " "(env -> %!dO)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); @@ -83971,10 +85284,10 @@ DUK_STATS_INC(thr->heap, stats_getvar_all); - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(env); - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(env); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value) { duk_push_tval(thr, ref.value); @@ -83989,7 +85302,7 @@ DUK_TVAL_SET_OBJECT(&tv_tmp_obj, ref.holder); DUK_TVAL_SET_STRING(&tv_tmp_key, name); - (void) duk_hobject_getprop(thr, &tv_tmp_obj, &tv_tmp_key); /* value */ + (void) duk_hobject_getprop(thr, &tv_tmp_obj, &tv_tmp_key); /* value */ if (ref.has_this) { duk_push_hobject(thr, ref.holder); @@ -84003,7 +85316,8 @@ return 1; } else { if (throw_flag) { - DUK_ERROR_FMT1(thr, DUK_ERR_REFERENCE_ERROR, + DUK_ERROR_FMT1(thr, + DUK_ERR_REFERENCE_ERROR, "identifier '%s' undefined", (const char *) DUK_HSTRING_GET_DATA(name)); DUK_WO_NORETURN(return 0;); @@ -84014,18 +85328,12 @@ } DUK_INTERNAL -duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, - duk_hobject *env, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk_js_getvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_bool_t throw_flag) { return duk__getvar_helper(thr, env, NULL, name, throw_flag); } DUK_INTERNAL -duk_bool_t duk_js_getvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name, - duk_bool_t throw_flag) { +duk_bool_t duk_js_getvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_bool_t throw_flag) { DUK_ASSERT(act != NULL); return duk__getvar_helper(thr, act->lex_env, act, name, throw_flag); } @@ -84062,9 +85370,14 @@ DUK_DDD(DUK_DDDPRINT("putvar: thr=%p, env=%p, act=%p, name=%!O, val=%p, strict=%ld " "(env -> %!dO, val -> %!T)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (void *) val, (long) strict, - (duk_heaphdr *) env, (duk_tval *) val)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (void *) val, + (long) strict, + (duk_heaphdr *) env, + (duk_tval *) val)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); @@ -84075,7 +85388,7 @@ DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); DUK_ASSERT_REFCOUNT_NONZERO_TVAL(val); - DUK_TVAL_SET_TVAL(&tv_tmp_val, val); /* Stabilize. */ + DUK_TVAL_SET_TVAL(&tv_tmp_val, val); /* Stabilize. */ val = NULL; /* @@ -84088,15 +85401,13 @@ * and name 'eval' or 'arguments'. */ - DUK_ASSERT(!strict || - (name != DUK_HTHREAD_STRING_EVAL(thr) && - name != DUK_HTHREAD_STRING_LC_ARGUMENTS(thr))); + DUK_ASSERT(!strict || (name != DUK_HTHREAD_STRING_EVAL(thr) && name != DUK_HTHREAD_STRING_LC_ARGUMENTS(thr))); /* * Lookup variable and update in-place if found. */ - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value && (ref.attrs & DUK_PROPDESC_FLAG_WRITABLE)) { @@ -84109,7 +85420,7 @@ tv_val = ref.value; DUK_ASSERT(tv_val != NULL); - DUK_TVAL_SET_TVAL_UPDREF(thr, tv_val, &tv_tmp_val); /* side effects */ + DUK_TVAL_SET_TVAL_UPDREF(thr, tv_val, &tv_tmp_val); /* side effects */ /* ref.value invalidated here */ } else { @@ -84132,7 +85443,8 @@ if (strict) { DUK_DDD(DUK_DDDPRINT("identifier binding not found, strict => reference error")); - DUK_ERROR_FMT1(thr, DUK_ERR_REFERENCE_ERROR, + DUK_ERROR_FMT1(thr, + DUK_ERR_REFERENCE_ERROR, "identifier '%s' undefined", (const char *) DUK_HSTRING_GET_DATA(name)); DUK_WO_NORETURN(return;); @@ -84142,7 +85454,7 @@ DUK_TVAL_SET_OBJECT(&tv_tmp_obj, thr->builtinsDUK_BIDX_GLOBAL); DUK_TVAL_SET_STRING(&tv_tmp_key, name); - (void) duk_hobject_putprop(thr, &tv_tmp_obj, &tv_tmp_key, &tv_tmp_val, 0); /* 0 = no throw */ + (void) duk_hobject_putprop(thr, &tv_tmp_obj, &tv_tmp_key, &tv_tmp_val, 0); /* 0 = no throw */ /* NB: 'val' may be invalidated here because put_value may realloc valstack, * caller beware. @@ -84150,20 +85462,12 @@ } DUK_INTERNAL -void duk_js_putvar_envrec(duk_hthread *thr, - duk_hobject *env, - duk_hstring *name, - duk_tval *val, - duk_bool_t strict) { +void duk_js_putvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name, duk_tval *val, duk_bool_t strict) { duk__putvar_helper(thr, env, NULL, name, val, strict); } DUK_INTERNAL -void duk_js_putvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name, - duk_tval *val, - duk_bool_t strict) { +void duk_js_putvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_bool_t strict) { DUK_ASSERT(act != NULL); duk__putvar_helper(thr, act->lex_env, act, name, val, strict); } @@ -84188,25 +85492,25 @@ */ DUK_LOCAL -duk_bool_t duk__delvar_helper(duk_hthread *thr, - duk_hobject *env, - duk_activation *act, - duk_hstring *name) { +duk_bool_t duk__delvar_helper(duk_hthread *thr, duk_hobject *env, duk_activation *act, duk_hstring *name) { duk__id_lookup_result ref; duk_bool_t parents; DUK_DDD(DUK_DDDPRINT("delvar: thr=%p, env=%p, act=%p, name=%!O " "(env -> %!dO)", - (void *) thr, (void *) env, (void *) act, - (duk_heaphdr *) name, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (void *) act, + (duk_heaphdr *) name, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(name != NULL); /* env and act may be NULL */ - DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); + DUK_ASSERT_REFCOUNT_NONZERO_HEAPHDR(name); - parents = 1; /* follow parent chain */ + parents = 1; /* follow parent chain */ if (duk__get_identifier_reference(thr, env, name, act, parents, &ref)) { if (ref.value && !(ref.attrs & DUK_PROPDESC_FLAG_CONFIGURABLE)) { @@ -84234,7 +85538,7 @@ return 1; } -#if 0 /*unused*/ +#if 0 /*unused*/ DUK_INTERNAL duk_bool_t duk_js_delvar_envrec(duk_hthread *thr, duk_hobject *env, @@ -84244,9 +85548,7 @@ #endif DUK_INTERNAL -duk_bool_t duk_js_delvar_activation(duk_hthread *thr, - duk_activation *act, - duk_hstring *name) { +duk_bool_t duk_js_delvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name) { DUK_ASSERT(act != NULL); return duk__delvar_helper(thr, act->lex_env, act, name); } @@ -84315,9 +85617,13 @@ DUK_DDD(DUK_DDDPRINT("declvar: thr=%p, env=%p, name=%!O, val=%!T, prop_flags=0x%08lx, is_func_decl=%ld " "(env -> %!iO)", - (void *) thr, (void *) env, (duk_heaphdr *) name, - (duk_tval *) val, (unsigned long) prop_flags, - (unsigned int) is_func_decl, (duk_heaphdr *) env)); + (void *) thr, + (void *) env, + (duk_heaphdr *) name, + (duk_tval *) val, + (unsigned long) prop_flags, + (unsigned int) is_func_decl, + (duk_heaphdr *) env)); DUK_ASSERT(thr != NULL); DUK_ASSERT(env != NULL); @@ -84344,7 +85650,7 @@ * environment target object. */ - parents = 0; /* just check 'env' */ + parents = 0; /* just check 'env' */ if (duk__get_identifier_reference(thr, env, name, NULL, parents, &ref)) { duk_int_t e_idx; duk_int_t h_idx; @@ -84359,7 +85665,7 @@ if (!(is_func_decl && env == thr->builtinsDUK_BIDX_GLOBAL_ENV)) { DUK_DDD(DUK_DDDPRINT("re-declare a binding, ignoring")); - return 1; /* 1 -> needs a PUTVAR */ + return 1; /* 1 -> needs a PUTVAR */ } /* @@ -84389,7 +85695,7 @@ * where the property was found (see duk__get_identifier_reference()). */ DUK_ASSERT(DUK_HOBJECT_GET_CLASS_NUMBER(holder) == DUK_HOBJECT_CLASS_GLOBAL); - DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(holder)); /* global object doesn't have array part */ + DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARRAY(holder)); /* global object doesn't have array part */ /* XXX: use a helper for prototype traversal; no loop check here */ /* must be found: was found earlier, and cannot be inherited */ @@ -84422,8 +85728,7 @@ "accessor -> reject")); goto fail_existing_attributes; } - if (!((flags & DUK_PROPDESC_FLAG_WRITABLE) && - (flags & DUK_PROPDESC_FLAG_ENUMERABLE))) { + if (!((flags & DUK_PROPDESC_FLAG_WRITABLE) && (flags & DUK_PROPDESC_FLAG_ENUMERABLE))) { DUK_DDD(DUK_DDDPRINT("existing property is a non-configurable " "plain property which is not writable and " "enumerable -> reject")); @@ -84518,13 +85823,13 @@ duk_push_hobject(thr, holder); duk_push_hstring(thr, name); duk_push_tval(thr, val); - duk_xdef_prop(thr, -3, prop_flags); /* holder name val -> holder */ + duk_xdef_prop(thr, -3, prop_flags); /* holder name val -> holder */ duk_pop_unsafe(thr); return 0; - fail_existing_attributes: - fail_not_extensible: +fail_existing_attributes: +fail_not_extensible: DUK_ERROR_TYPE(thr, "declaration failed"); DUK_WO_NORETURN(return 0;); } @@ -84646,34 +85951,34 @@ * Various defines and file specific helper macros */ -#define DUK__MAX_RE_DECESC_DIGITS 9 -#define DUK__MAX_RE_QUANT_DIGITS 9 /* Does not allow e.g. 2**31-1, but one more would allow overflows of u32. */ +#define DUK__MAX_RE_DECESC_DIGITS 9 +#define DUK__MAX_RE_QUANT_DIGITS 9 /* Does not allow e.g. 2**31-1, but one more would allow overflows of u32. */ /* whether to use macros or helper function depends on call count */ -#define DUK__ISDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_9) -#define DUK__ISHEXDIGIT(x) duk__is_hex_digit((x)) -#define DUK__ISOCTDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_7) -#define DUK__ISDIGIT03(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_3) -#define DUK__ISDIGIT47(x) ((x) >= DUK_ASC_4 && (x) <= DUK_ASC_7) +#define DUK__ISDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_9) +#define DUK__ISHEXDIGIT(x) duk__is_hex_digit((x)) +#define DUK__ISOCTDIGIT(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_7) +#define DUK__ISDIGIT03(x) ((x) >= DUK_ASC_0 && (x) <= DUK_ASC_3) +#define DUK__ISDIGIT47(x) ((x) >= DUK_ASC_4 && (x) <= DUK_ASC_7) /* lexer character window helpers */ -#define DUK__LOOKUP(lex_ctx,idx) ((lex_ctx)->window(idx).codepoint) -#define DUK__ADVANCECHARS(lex_ctx,count) duk__advance_chars((lex_ctx), (count)) -#define DUK__ADVANCEBYTES(lex_ctx,count) duk__advance_bytes((lex_ctx), (count)) +#define DUK__LOOKUP(lex_ctx, idx) ((lex_ctx)->window(idx).codepoint) +#define DUK__ADVANCECHARS(lex_ctx, count) duk__advance_chars((lex_ctx), (count)) +#define DUK__ADVANCEBYTES(lex_ctx, count) duk__advance_bytes((lex_ctx), (count)) #define DUK__INITBUFFER(lex_ctx) duk__initbuffer((lex_ctx)) -#define DUK__APPENDBUFFER(lex_ctx,x) duk__appendbuffer((lex_ctx), (duk_codepoint_t) (x)) -#define DUK__APPENDBUFFER_ASCII(lex_ctx,x) duk__appendbuffer_ascii((lex_ctx), (duk_codepoint_t) (x)) +#define DUK__APPENDBUFFER(lex_ctx, x) duk__appendbuffer((lex_ctx), (duk_codepoint_t) (x)) +#define DUK__APPENDBUFFER_ASCII(lex_ctx, x) duk__appendbuffer_ascii((lex_ctx), (duk_codepoint_t) (x)) /* lookup shorthands (note: assume context variable is named 'lex_ctx') */ -#define DUK__L0() DUK__LOOKUP(lex_ctx, 0) -#define DUK__L1() DUK__LOOKUP(lex_ctx, 1) -#define DUK__L2() DUK__LOOKUP(lex_ctx, 2) -#define DUK__L3() DUK__LOOKUP(lex_ctx, 3) -#define DUK__L4() DUK__LOOKUP(lex_ctx, 4) -#define DUK__L5() DUK__LOOKUP(lex_ctx, 5) +#define DUK__L0() DUK__LOOKUP(lex_ctx, 0) +#define DUK__L1() DUK__LOOKUP(lex_ctx, 1) +#define DUK__L2() DUK__LOOKUP(lex_ctx, 2) +#define DUK__L3() DUK__LOOKUP(lex_ctx, 3) +#define DUK__L4() DUK__LOOKUP(lex_ctx, 4) +#define DUK__L5() DUK__LOOKUP(lex_ctx, 5) /* packed advance/token number macro used by multiple functions */ -#define DUK__ADVTOK(advbytes,tok) ((((advbytes) * sizeof(duk_lexer_codepoint)) << 8) + (tok)) +#define DUK__ADVTOK(advbytes, tok) ((((advbytes) * sizeof(duk_lexer_codepoint)) << 8) + (tok)) /* * Advance lookup window by N characters, filling in new characters as @@ -84783,10 +86088,9 @@ /* Fast path. */ if (DUK_LIKELY(x < 0x80UL)) { - DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ + DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ if (DUK_UNLIKELY(x <= 0x000dUL)) { - if ((x == 0x000aUL) || - ((x == 0x000dUL) && (p >= p_end || *p != 0x000aUL))) { + if ((x == 0x000aUL) || ((x == 0x000dUL) && (p >= p_end || *p != 0x000aUL))) { /* lookup for 0x000a above assumes shortest encoding now */ /* E5 Section 7.3, treat the following as newlines: @@ -84877,8 +86181,8 @@ lex_ctx->input_line = input_line; return; - error_clipped: /* clipped codepoint */ - error_encoding: /* invalid codepoint encoding or codepoint */ +error_clipped: /* clipped codepoint */ +error_encoding: /* invalid codepoint encoding or codepoint */ lex_ctx->input_offset = (duk_size_t) (p - lex_ctx->input); lex_ctx->input_line = input_line; @@ -84889,26 +86193,25 @@ DUK_LOCAL void duk__advance_bytes(duk_lexer_ctx *lex_ctx, duk_small_uint_t count_bytes) { duk_small_uint_t used_bytes, avail_bytes; - DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ DUK_ASSERT(count_bytes <= (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))); DUK_ASSERT(lex_ctx->window >= lex_ctx->buffer); DUK_ASSERT(lex_ctx->window < lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE); - DUK_ASSERT((duk_uint8_t *) lex_ctx->window + count_bytes <= (duk_uint8_t *) lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint)); + DUK_ASSERT((duk_uint8_t *) lex_ctx->window + count_bytes <= + (duk_uint8_t *) lex_ctx->buffer + DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint)); /* Zero 'count' is also allowed to make call sites easier. * Arithmetic in bytes generates better code in GCC. */ - lex_ctx->window = (duk_lexer_codepoint *) (void *) ((duk_uint8_t *) lex_ctx->window + count_bytes); /* avoid multiply */ + lex_ctx->window = (duk_lexer_codepoint *) (void *) ((duk_uint8_t *) lex_ctx->window + count_bytes); /* avoid multiply */ used_bytes = (duk_small_uint_t) ((duk_uint8_t *) lex_ctx->window - (duk_uint8_t *) lex_ctx->buffer); avail_bytes = DUK_LEXER_BUFFER_SIZE * sizeof(duk_lexer_codepoint) - used_bytes; if (avail_bytes < (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))) { /* Not enough data to provide a full window, so "scroll" window to * start of buffer and fill up the rest. */ - duk_memmove((void *) lex_ctx->buffer, - (const void *) lex_ctx->window, - (size_t) avail_bytes); + duk_memmove((void *) lex_ctx->buffer, (const void *) lex_ctx->window, (size_t) avail_bytes); lex_ctx->window = lex_ctx->buffer; duk__fill_lexer_buffer(lex_ctx, avail_bytes); } @@ -84918,7 +86221,7 @@ lex_ctx->window = lex_ctx->buffer; duk__fill_lexer_buffer(lex_ctx, 0); } -#else /* DUK_USE_LEXER_SLIDING_WINDOW */ +#else /* DUK_USE_LEXER_SLIDING_WINDOW */ DUK_LOCAL duk_codepoint_t duk__read_char(duk_lexer_ctx *lex_ctx) { duk_ucodepoint_t x; duk_small_uint_t len; @@ -84948,11 +86251,10 @@ /* input offset tracking */ lex_ctx->input_offset++; - DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ + DUK_ASSERT(x != 0x2028UL && x != 0x2029UL); /* not LS/PS */ if (DUK_UNLIKELY(x <= 0x000dUL)) { - if ((x == 0x000aUL) || - ((x == 0x000dUL) && (lex_ctx->input_offset >= lex_ctx->input_length || - lex_ctx->inputlex_ctx->input_offset != 0x000aUL))) { + if ((x == 0x000aUL) || ((x == 0x000dUL) && (lex_ctx->input_offset >= lex_ctx->input_length || + lex_ctx->inputlex_ctx->input_offset != 0x000aUL))) { /* lookup for 0x000a above assumes shortest encoding now */ /* E5 Section 7.3, treat the following as newlines: @@ -85041,8 +86343,8 @@ return (duk_codepoint_t) x; - error_clipped: /* clipped codepoint */ - error_encoding: /* invalid codepoint encoding or codepoint */ +error_clipped: /* clipped codepoint */ +error_encoding: /* invalid codepoint encoding or codepoint */ DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_SOURCE_DECODE_FAILED); DUK_WO_NORETURN(return 0;); } @@ -85051,15 +86353,13 @@ duk_small_uint_t keep_bytes; duk_lexer_codepoint *cp, *cp_end; - DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(count_bytes >= 0); /* unsigned */ DUK_ASSERT(count_bytes <= (duk_small_uint_t) (DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint))); /* Zero 'count' is also allowed to make call sites easier. */ keep_bytes = DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint) - count_bytes; - duk_memmove((void *) lex_ctx->window, - (const void *) ((duk_uint8_t *) lex_ctx->window + count_bytes), - (size_t) keep_bytes); + duk_memmove((void *) lex_ctx->window, (const void *) ((duk_uint8_t *) lex_ctx->window + count_bytes), (size_t) keep_bytes); cp = (duk_lexer_codepoint *) ((duk_uint8_t *) lex_ctx->window + keep_bytes); cp_end = lex_ctx->window + DUK_LEXER_WINDOW_SIZE; @@ -85072,9 +86372,9 @@ DUK_LOCAL void duk__init_lexer_window(duk_lexer_ctx *lex_ctx) { /* Call with count == DUK_LEXER_WINDOW_SIZE to fill buffer initially. */ - duk__advance_bytes(lex_ctx, DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint)); /* fill window */ + duk__advance_bytes(lex_ctx, DUK_LEXER_WINDOW_SIZE * sizeof(duk_lexer_codepoint)); /* fill window */ } -#endif /* DUK_USE_LEXER_SLIDING_WINDOW */ +#endif /* DUK_USE_LEXER_SLIDING_WINDOW */ DUK_LOCAL void duk__advance_chars(duk_lexer_ctx *lex_ctx, duk_small_uint_t count_chars) { duk__advance_bytes(lex_ctx, count_chars * sizeof(duk_lexer_codepoint)); @@ -85167,7 +86467,7 @@ } DUK_INTERNAL void duk_lexer_setpoint(duk_lexer_ctx *lex_ctx, duk_lexer_point *pt) { - DUK_ASSERT_DISABLE(pt->offset >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(pt->offset >= 0); /* unsigned */ DUK_ASSERT(pt->line >= 1); lex_ctx->input_offset = pt->offset; lex_ctx->input_line = pt->line; @@ -85201,8 +86501,7 @@ DUK_LOCAL duk_codepoint_t duk__hexval(duk_codepoint_t x) { duk_codepoint_t ret; - DUK_ASSERT((x >= DUK_ASC_0 && x <= DUK_ASC_9) || - (x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_F) || + DUK_ASSERT((x >= DUK_ASC_0 && x <= DUK_ASC_9) || (x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_F) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_F)); ret = duk__hexval_validate(x); DUK_ASSERT(ret >= 0 && ret <= 15); @@ -85221,12 +86520,12 @@ * source and RegExp parsing. */ DUK_LOCAL duk_codepoint_t duk__lexer_parse_escape(duk_lexer_ctx *lex_ctx, duk_bool_t allow_es6) { - duk_small_int_t digits; /* Initial value 2 or 4 for fixed length escapes, 0 for ES2015 \u{H+}. */ + duk_small_int_t digits; /* Initial value 2 or 4 for fixed length escapes, 0 for ES2015 \u{H+}. */ duk_codepoint_t escval; duk_codepoint_t x; duk_small_uint_t adv; - DUK_ASSERT(DUK__L0() == DUK_ASC_BACKSLASH); /* caller responsibilities */ + DUK_ASSERT(DUK__L0() == DUK_ASC_BACKSLASH); /* caller responsibilities */ DUK_ASSERT(DUK__L1() == DUK_ASC_LC_X || DUK__L1() == DUK_ASC_LC_U); DUK_UNREF(allow_es6); @@ -85300,16 +86599,16 @@ } else { goto fail_escape; } - digits = -1; /* Indicate we have at least one digit. */ -#else /* DUK_USE_ES6_UNICODE_ESCAPE */ - DUK_ASSERT(0); /* Never happens if \u{H+} support disabled. */ -#endif /* DUK_USE_ES6_UNICODE_ESCAPE */ + digits = -1; /* Indicate we have at least one digit. */ +#else /* DUK_USE_ES6_UNICODE_ESCAPE */ + DUK_ASSERT(0); /* Never happens if \u{H+} support disabled. */ +#endif /* DUK_USE_ES6_UNICODE_ESCAPE */ } } return escval; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return 0;); } @@ -85319,7 +86618,9 @@ * RegExp octal escape parsing. Window0 must be the slash '\' and the first * digit must already be validated to be in 0-9 by the caller. */ -DUK_LOCAL duk_codepoint_t duk__lexer_parse_legacy_octal(duk_lexer_ctx *lex_ctx, duk_small_uint_t *out_adv, duk_bool_t reject_annex_b) { +DUK_LOCAL duk_codepoint_t duk__lexer_parse_legacy_octal(duk_lexer_ctx *lex_ctx, + duk_small_uint_t *out_adv, + duk_bool_t reject_annex_b) { duk_codepoint_t cp; duk_small_uint_t lookup_idx; duk_small_uint_t adv; @@ -85354,7 +86655,7 @@ DUK_DDD(DUK_DDDPRINT("\\8 or \\9 -> treat as literal, accept in strict mode too")); DUK_ASSERT(tmp == DUK_ASC_8 || tmp == DUK_ASC_9); cp = tmp; - adv++; /* correction to above, eat offending character */ + adv++; /* correction to above, eat offending character */ } else if (lookup_idx == 2 && cp == 0) { /* Note: 'foo\0bar' is OK in strict mode, but 'foo\00bar' is not. * It won't be interpreted as 'foo\u{0}0bar' but as a SyntaxError. @@ -85378,18 +86679,21 @@ } /* XXX: move strict mode to lex_ctx? */ -DUK_LOCAL void duk__lexer_parse_string_literal(duk_lexer_ctx *lex_ctx, duk_token *out_token, duk_small_int_t quote, duk_bool_t strict_mode) { +DUK_LOCAL void duk__lexer_parse_string_literal(duk_lexer_ctx *lex_ctx, + duk_token *out_token, + duk_small_int_t quote, + duk_bool_t strict_mode) { duk_small_uint_t adv; - for (adv = 1 /* initial quote */ ;;) { + for (adv = 1 /* initial quote */;;) { duk_codepoint_t x; - DUK__ADVANCECHARS(lex_ctx, adv); /* eat opening quote on first loop */ + DUK__ADVANCECHARS(lex_ctx, adv); /* eat opening quote on first loop */ x = DUK__L0(); adv = 1; if (x == quote) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing quote */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing quote */ break; } else if (x == '\\') { /* DUK__L0 -> '\' char @@ -85400,7 +86704,7 @@ x = DUK__L1(); /* How much to advance before next loop. */ - adv = 2; /* note: long live range */ + adv = 2; /* note: long live range */ switch (x) { case '\'': @@ -85443,7 +86747,7 @@ /* line continuation */ if (x == 0x000d && DUK__L2() == 0x000a) { /* CR LF again a special case */ - adv = 3; /* line terminator, CR, LF */ + adv = 3; /* line terminator, CR, LF */ } } else if (DUK__ISDIGIT(x)) { /* @@ -85472,8 +86776,8 @@ /* escaped NonEscapeCharacter */ DUK__APPENDBUFFER(lex_ctx, x); } - } /* end default clause */ - } /* end switch */ + } /* end default clause */ + } /* end switch */ /* Shared handling for single codepoint escapes. */ if (emitcp >= 0) { @@ -85506,11 +86810,11 @@ return; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return;); - fail_unterminated: +fail_unterminated: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_STRING); DUK_WO_NORETURN(return;); } @@ -85597,19 +86901,19 @@ duk_token *out_token, duk_bool_t strict_mode, duk_bool_t regexp_mode) { - duk_codepoint_t x; /* temporary, must be signed and 32-bit to hold Unicode code points */ + duk_codepoint_t x; /* temporary, must be signed and 32-bit to hold Unicode code points */ duk_small_uint_t advtok = 0; /* (advance << 8) + token_type, updated at function end, * init is unnecessary but suppresses "may be used uninitialized" warnings. */ - duk_bool_t got_lineterm = 0; /* got lineterm preceding non-whitespace, non-lineterm token */ + duk_bool_t got_lineterm = 0; /* got lineterm preceding non-whitespace, non-lineterm token */ if (++lex_ctx->token_count >= lex_ctx->token_limit) { goto fail_token_limit; } out_token->t = DUK_TOK_EOF; - out_token->t_nores = DUK_TOK_INVALID; /* marker: copy t if not changed */ -#if 0 /* not necessary to init, disabled for faster parsing */ + out_token->t_nores = DUK_TOK_INVALID; /* marker: copy t if not changed */ +#if 0 /* not necessary to init, disabled for faster parsing */ out_token->num = DUK_DOUBLE_NAN; out_token->str1 = NULL; out_token->str2 = NULL; @@ -85649,35 +86953,34 @@ * in the clauses, so it's not trivial to convert to a switch. */ - restart_lineupdate: +restart_lineupdate: out_token->start_line = lex_ctx->window0.line; - restart: +restart: out_token->start_offset = lex_ctx->window0.offset; x = DUK__L0(); switch (x) { case DUK_ASC_SPACE: - case DUK_ASC_HT: /* fast paths for space and tab */ + case DUK_ASC_HT: /* fast paths for space and tab */ DUK__ADVANCECHARS(lex_ctx, 1); goto restart; - case DUK_ASC_LF: /* LF line terminator; CR LF and Unicode lineterms are handled in slow path */ + case DUK_ASC_LF: /* LF line terminator; CR LF and Unicode lineterms are handled in slow path */ DUK__ADVANCECHARS(lex_ctx, 1); got_lineterm = 1; goto restart_lineupdate; #if defined(DUK_USE_SHEBANG_COMMENTS) - case DUK_ASC_HASH: /* '#' */ - if (DUK__L1() == DUK_ASC_EXCLAMATION && lex_ctx->window0.offset == 0 && - (lex_ctx->flags & DUK_COMPILE_SHEBANG)) { + case DUK_ASC_HASH: /* '#' */ + if (DUK__L1() == DUK_ASC_EXCLAMATION && lex_ctx->window0.offset == 0 && (lex_ctx->flags & DUK_COMPILE_SHEBANG)) { /* "Shebang" comment ('#! ...') on first line. */ /* DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } goto fail_token; -#endif /* DUK_USE_SHEBANG_COMMENTS */ - case DUK_ASC_SLASH: /* '/' */ +#endif /* DUK_USE_SHEBANG_COMMENTS */ + case DUK_ASC_SLASH: /* '/' */ if (DUK__L1() == DUK_ASC_SLASH) { /* * E5 Section 7.4, allow SourceCharacter (which is any 16-bit @@ -85686,7 +86989,7 @@ /* DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } else if (DUK__L1() == DUK_ASC_STAR) { /* * E5 Section 7.4. If the multi-line comment contains a newline, @@ -85770,19 +87073,19 @@ /* first, parse regexp body roughly */ - duk_small_int_t state = 0; /* 0=base, 1=esc, 2=class, 3=class+esc */ + duk_small_int_t state = 0; /* 0=base, 1=esc, 2=class, 3=class+esc */ DUK__INITBUFFER(lex_ctx); for (;;) { - DUK__ADVANCECHARS(lex_ctx, 1); /* skip opening slash on first loop */ + DUK__ADVANCECHARS(lex_ctx, 1); /* skip opening slash on first loop */ x = DUK__L0(); if (x < 0 || duk_unicode_is_line_terminator(x)) { goto fail_unterm_regexp; } - x = DUK__L0(); /* re-read to avoid spill / fetch */ + x = DUK__L0(); /* re-read to avoid spill / fetch */ if (state == 0) { if (x == DUK_ASC_SLASH) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing slash */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat closing slash */ break; } else if (x == DUK_ASC_BACKSLASH) { state = 1; @@ -85812,20 +87115,20 @@ if (!duk_unicode_is_identifier_part(x)) { break; } - x = DUK__L0(); /* re-read to avoid spill / fetch */ + x = DUK__L0(); /* re-read to avoid spill / fetch */ DUK__APPENDBUFFER(lex_ctx, x); DUK__ADVANCECHARS(lex_ctx, 1); } out_token->str2 = duk__internbuffer(lex_ctx, lex_ctx->slot2_idx); - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* validation of the regexp is caller's responsibility */ advtok = DUK__ADVTOK(0, DUK_TOK_REGEXP); -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ goto fail_regexp_support; -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ } else if (DUK__L1() == DUK_ASC_EQUALS) { /* "/=" and not in regexp mode */ advtok = DUK__ADVTOK(2, DUK_TOK_DIV_EQ); @@ -85834,25 +87137,25 @@ advtok = DUK__ADVTOK(1, DUK_TOK_DIV); } break; - case DUK_ASC_LCURLY: /* '{' */ + case DUK_ASC_LCURLY: /* '{' */ advtok = DUK__ADVTOK(1, DUK_TOK_LCURLY); break; - case DUK_ASC_RCURLY: /* '}' */ + case DUK_ASC_RCURLY: /* '}' */ advtok = DUK__ADVTOK(1, DUK_TOK_RCURLY); break; - case DUK_ASC_LPAREN: /* '(' */ + case DUK_ASC_LPAREN: /* '(' */ advtok = DUK__ADVTOK(1, DUK_TOK_LPAREN); break; - case DUK_ASC_RPAREN: /* ')' */ + case DUK_ASC_RPAREN: /* ')' */ advtok = DUK__ADVTOK(1, DUK_TOK_RPAREN); break; - case DUK_ASC_LBRACKET: /* '' */ + case DUK_ASC_LBRACKET: /* '' */ advtok = DUK__ADVTOK(1, DUK_TOK_LBRACKET); break; - case DUK_ASC_RBRACKET: /* '' */ + case DUK_ASC_RBRACKET: /* '' */ advtok = DUK__ADVTOK(1, DUK_TOK_RBRACKET); break; - case DUK_ASC_PERIOD: /* '.' */ + case DUK_ASC_PERIOD: /* '.' */ if (DUK__ISDIGIT(DUK__L1())) { /* Period followed by a digit can only start DecimalLiteral * (handled in slow path). We could jump straight into the @@ -85863,13 +87166,13 @@ } advtok = DUK__ADVTOK(1, DUK_TOK_PERIOD); break; - case DUK_ASC_SEMICOLON: /* ';' */ + case DUK_ASC_SEMICOLON: /* ';' */ advtok = DUK__ADVTOK(1, DUK_TOK_SEMICOLON); break; - case DUK_ASC_COMMA: /* ',' */ + case DUK_ASC_COMMA: /* ',' */ advtok = DUK__ADVTOK(1, DUK_TOK_COMMA); break; - case DUK_ASC_LANGLE: /* '<' */ + case DUK_ASC_LANGLE: /* '<' */ #if defined(DUK_USE_HTML_COMMENTS) if (DUK__L1() == DUK_ASC_EXCLAMATION && DUK__L2() == DUK_ASC_MINUS && DUK__L3() == DUK_ASC_MINUS) { /* @@ -85878,11 +87181,10 @@ /* DUK__ADVANCECHARS(lex_ctx, 4) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ - } - else -#endif /* DUK_USE_HTML_COMMENTS */ - if (DUK__L1() == DUK_ASC_LANGLE && DUK__L2() == DUK_ASC_EQUALS) { + goto restart; /* line terminator will be handled on next round */ + } else +#endif /* DUK_USE_HTML_COMMENTS */ + if (DUK__L1() == DUK_ASC_LANGLE && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_ALSHIFT_EQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_LE); @@ -85892,7 +87194,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_LT); } break; - case DUK_ASC_RANGLE: /* '>' */ + case DUK_ASC_RANGLE: /* '>' */ if (DUK__L1() == DUK_ASC_RANGLE && DUK__L2() == DUK_ASC_RANGLE && DUK__L3() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(4, DUK_TOK_RSHIFT_EQ); } else if (DUK__L1() == DUK_ASC_RANGLE && DUK__L2() == DUK_ASC_RANGLE) { @@ -85907,7 +87209,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_GT); } break; - case DUK_ASC_EQUALS: /* '=' */ + case DUK_ASC_EQUALS: /* '=' */ if (DUK__L1() == DUK_ASC_EQUALS && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_SEQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -85916,7 +87218,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_EQUALSIGN); } break; - case DUK_ASC_EXCLAMATION: /* '!' */ + case DUK_ASC_EXCLAMATION: /* '!' */ if (DUK__L1() == DUK_ASC_EQUALS && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_SNEQ); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -85925,7 +87227,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_LNOT); } break; - case DUK_ASC_PLUS: /* '+' */ + case DUK_ASC_PLUS: /* '+' */ if (DUK__L1() == DUK_ASC_PLUS) { advtok = DUK__ADVTOK(2, DUK_TOK_INCREMENT); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -85934,7 +87236,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_ADD); } break; - case DUK_ASC_MINUS: /* '-' */ + case DUK_ASC_MINUS: /* '-' */ #if defined(DUK_USE_HTML_COMMENTS) if (got_lineterm && DUK__L1() == DUK_ASC_MINUS && DUK__L2() == DUK_ASC_RANGLE) { /* @@ -85951,10 +87253,10 @@ /* DUK__ADVANCECHARS(lex_ctx, 3) would be correct here, but not necessary */ duk__lexer_skip_to_endofline(lex_ctx); - goto restart; /* line terminator will be handled on next round */ + goto restart; /* line terminator will be handled on next round */ } else -#endif /* DUK_USE_HTML_COMMENTS */ - if (DUK__L1() == DUK_ASC_MINUS) { +#endif /* DUK_USE_HTML_COMMENTS */ + if (DUK__L1() == DUK_ASC_MINUS) { advtok = DUK__ADVTOK(2, DUK_TOK_DECREMENT); } else if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_SUB_EQ); @@ -85962,7 +87264,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_SUB); } break; - case DUK_ASC_STAR: /* '*' */ + case DUK_ASC_STAR: /* '*' */ #if defined(DUK_USE_ES7_EXP_OPERATOR) if (DUK__L1() == DUK_ASC_STAR && DUK__L2() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(3, DUK_TOK_EXP_EQ); @@ -85970,20 +87272,20 @@ advtok = DUK__ADVTOK(2, DUK_TOK_EXP); } else #endif - if (DUK__L1() == DUK_ASC_EQUALS) { + if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_MUL_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_MUL); } break; - case DUK_ASC_PERCENT: /* '%' */ + case DUK_ASC_PERCENT: /* '%' */ if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_MOD_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_MOD); } break; - case DUK_ASC_AMP: /* '&' */ + case DUK_ASC_AMP: /* '&' */ if (DUK__L1() == DUK_ASC_AMP) { advtok = DUK__ADVTOK(2, DUK_TOK_LAND); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -85992,7 +87294,7 @@ advtok = DUK__ADVTOK(1, DUK_TOK_BAND); } break; - case DUK_ASC_PIPE: /* '|' */ + case DUK_ASC_PIPE: /* '|' */ if (DUK__L1() == DUK_ASC_PIPE) { advtok = DUK__ADVTOK(2, DUK_TOK_LOR); } else if (DUK__L1() == DUK_ASC_EQUALS) { @@ -86001,41 +87303,41 @@ advtok = DUK__ADVTOK(1, DUK_TOK_BOR); } break; - case DUK_ASC_CARET: /* '^' */ + case DUK_ASC_CARET: /* '^' */ if (DUK__L1() == DUK_ASC_EQUALS) { advtok = DUK__ADVTOK(2, DUK_TOK_BXOR_EQ); } else { advtok = DUK__ADVTOK(1, DUK_TOK_BXOR); } break; - case DUK_ASC_TILDE: /* '~' */ + case DUK_ASC_TILDE: /* '~' */ advtok = DUK__ADVTOK(1, DUK_TOK_BNOT); break; - case DUK_ASC_QUESTION: /* '?' */ + case DUK_ASC_QUESTION: /* '?' */ advtok = DUK__ADVTOK(1, DUK_TOK_QUESTION); break; - case DUK_ASC_COLON: /* ':' */ + case DUK_ASC_COLON: /* ':' */ advtok = DUK__ADVTOK(1, DUK_TOK_COLON); break; - case DUK_ASC_DOUBLEQUOTE: /* '"' */ - case DUK_ASC_SINGLEQUOTE: { /* '\'' */ + case DUK_ASC_DOUBLEQUOTE: /* '"' */ + case DUK_ASC_SINGLEQUOTE: { /* '\'' */ DUK__INITBUFFER(lex_ctx); duk__lexer_parse_string_literal(lex_ctx, out_token, x /*quote*/, strict_mode); duk__internbuffer(lex_ctx, lex_ctx->slot1_idx); out_token->str1 = duk_known_hstring(lex_ctx->thr, lex_ctx->slot1_idx); - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ advtok = DUK__ADVTOK(0, DUK_TOK_STRING); break; } default: goto slow_path; - } /* switch */ + } /* switch */ goto skip_slow_path; - slow_path: +slow_path: if (duk_unicode_is_line_terminator(x)) { if (x == 0x000d && DUK__L1() == 0x000a) { /* @@ -86126,7 +87428,7 @@ str = out_token->str1; out_token->t_nores = DUK_TOK_IDENTIFIER; - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* * Interned identifier is compared against reserved words, which are @@ -86153,7 +87455,7 @@ advtok = DUK__ADVTOK(0, DUK_TOK_IDENTIFIER); if (out_token->num_escapes == 0) { for (i = DUK_STRIDX_START_RESERVED; i < i_end; i++) { - DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(i >= 0); /* unsigned */ DUK_ASSERT(i < DUK_HEAP_NUM_STRINGS); if (DUK_HTHREAD_GET_STRING(lex_ctx->thr, i) == str) { advtok = DUK__ADVTOK(0, DUK_STRIDX_TO_TOK(i)); @@ -86188,11 +87490,11 @@ duk_double_t val; duk_bool_t legacy_oct = 0; - duk_small_int_t state; /* 0=before period/exp, - * 1=after period, before exp - * 2=after exp, allow '+' or '-' - * 3=after exp and exp sign - */ + duk_small_int_t state; /* 0=before period/exp, + * 1=after period, before exp + * 2=after exp, allow '+' or '-' + * 3=after exp and exp sign + */ duk_small_uint_t s2n_flags; duk_codepoint_t y, z; duk_small_int_t s2n_radix = 10; @@ -86204,7 +87506,7 @@ if (x == DUK_ASC_0) { z = DUK_LOWERCASE_CHAR_ASCII(y); - pre_adv = 2; /* default for 0xNNN, 0oNNN, 0bNNN. */ + pre_adv = 2; /* default for 0xNNN, 0oNNN, 0bNNN. */ if (z == DUK_ASC_LC_X) { s2n_radix = 16; } else if (z == DUK_ASC_LC_O) { @@ -86227,7 +87529,7 @@ DUK__APPENDBUFFER(lex_ctx, x); pre_adv = 1; legacy_oct = 1; - s2n_radix = 8; /* tentative unless conflicting digits found */ + s2n_radix = 8; /* tentative unless conflicting digits found */ } } } @@ -86241,7 +87543,7 @@ */ state = 0; for (;;) { - x = DUK__L0(); /* re-lookup curr char on first round */ + x = DUK__L0(); /* re-lookup curr char on first round */ if (DUK__ISDIGIT(x)) { /* Note: intentionally allow leading zeroes here, as the * actual parser will check for them. @@ -86294,11 +87596,8 @@ /* For bases other than 10, integer only. */ s2n_flags = DUK_S2N_FLAG_ALLOW_LEADING_ZERO; } else { - s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | - DUK_S2N_FLAG_ALLOW_FRAC | - DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_LEADING_ZERO; + s2n_flags = DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | + DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_LEADING_ZERO; } duk_dup(lex_ctx->thr, lex_ctx->slot1_idx); @@ -86307,9 +87606,9 @@ if (DUK_ISNAN(val)) { goto fail_number_literal; } - duk_replace(lex_ctx->thr, lex_ctx->slot1_idx); /* could also just pop? */ + duk_replace(lex_ctx->thr, lex_ctx->slot1_idx); /* could also just pop? */ - DUK__INITBUFFER(lex_ctx); /* free some memory */ + DUK__INITBUFFER(lex_ctx); /* free some memory */ /* Section 7.8.3 (note): NumericLiteral must be followed by something other than * IdentifierStart or DecimalDigit. @@ -86329,7 +87628,7 @@ } else { goto fail_token; } - skip_slow_path: +skip_slow_path: /* * Shared exit path @@ -86354,32 +87653,32 @@ return; - fail_token_limit: +fail_token_limit: DUK_ERROR_RANGE(lex_ctx->thr, DUK_STR_TOKEN_LIMIT); DUK_WO_NORETURN(return;); - fail_token: +fail_token: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_TOKEN); DUK_WO_NORETURN(return;); - fail_number_literal: +fail_number_literal: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_NUMBER_LITERAL); DUK_WO_NORETURN(return;); - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_ESCAPE); DUK_WO_NORETURN(return;); - fail_unterm_regexp: +fail_unterm_regexp: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_REGEXP); DUK_WO_NORETURN(return;); - fail_unterm_comment: +fail_unterm_comment: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_COMMENT); DUK_WO_NORETURN(return;); #if !defined(DUK_USE_REGEXP_SUPPORT) - fail_regexp_support: +fail_regexp_support: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_REGEXP_SUPPORT_DISABLED); DUK_WO_NORETURN(return;); #endif @@ -86397,7 +87696,7 @@ */ DUK_INTERNAL void duk_lexer_parse_re_token(duk_lexer_ctx *lex_ctx, duk_re_token *out_token) { - duk_small_uint_t advtok = 0; /* init is unnecessary but suppresses "may be used uninitialized" warnings */ + duk_small_uint_t advtok = 0; /* init is unnecessary but suppresses "may be used uninitialized" warnings */ duk_codepoint_t x, y; if (++lex_ctx->token_count >= lex_ctx->token_limit) { @@ -86475,7 +87774,7 @@ #endif for (;;) { - DUK__ADVANCECHARS(lex_ctx, 1); /* eat '{' on entry */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat '{' on entry */ x = DUK__L0(); if (DUK__ISDIGIT(x)) { digits++; @@ -86499,7 +87798,7 @@ } val2 = val1; val1 = 0; - digits = 0; /* not strictly necessary because of lookahead '}' above */ + digits = 0; /* not strictly necessary because of lookahead '}' above */ } else if (x == DUK_ASC_RCURLY) { if (digits > DUK__MAX_RE_QUANT_DIGITS) { goto invalid_quantifier; @@ -86530,7 +87829,7 @@ } advtok = DUK__ADVTOK(0, DUK_RETOK_QUANTIFIER); break; - invalid_quantifier: + invalid_quantifier: #if defined(DUK_USE_ES6_REGEXP_SYNTAX) /* Failed to match the quantifier, restore lexer and parse * opening brace as a literal. @@ -86556,7 +87855,7 @@ * ES2015 Annex B relaxes the rules to allow these (and other) real world forms. */ - advtok = DUK__ADVTOK(2, DUK_RETOK_ATOM_CHAR); /* default: char escape (two chars) */ + advtok = DUK__ADVTOK(2, DUK_RETOK_ATOM_CHAR); /* default: char escape (two chars) */ if (y == DUK_ASC_LC_B) { advtok = DUK__ADVTOK(2, DUK_RETOK_ASSERT_WORD_BOUNDARY); } else if (y == DUK_ASC_UC_B) { @@ -86573,8 +87872,7 @@ out_token->num = 0x000b; } else if (y == DUK_ASC_LC_C) { x = DUK__L2(); - if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || - (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { + if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { out_token->num = (duk_uint32_t) (x % 32); advtok = DUK__ADVTOK(3, DUK_RETOK_ATOM_CHAR); } else { @@ -86612,11 +87910,11 @@ /* XXX: shared parsing? */ duk_uint32_t val = 0; duk_small_int_t i; - for (i = 0; ; i++) { + for (i = 0;; i++) { if (i >= DUK__MAX_RE_DECESC_DIGITS) { goto fail_escape; } - DUK__ADVANCECHARS(lex_ctx, 1); /* eat backslash on entry */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat backslash on entry */ x = DUK__L0(); if (!DUK__ISDIGIT(x)) { break; @@ -86636,17 +87934,15 @@ * This is not yet full ES2015 Annex B because cases above * (like hex escape) won't backtrack. */ - DUK_ASSERT(y != DUK_ASC_LC_C); /* covered above */ -#else /* DUK_USE_ES6_REGEXP_SYNTAX */ - } else if ((y >= 0 && !duk_unicode_is_identifier_part(y)) || - y == DUK_UNICODE_CP_ZWNJ || - y == DUK_UNICODE_CP_ZWJ) { + DUK_ASSERT(y != DUK_ASC_LC_C); /* covered above */ +#else /* DUK_USE_ES6_REGEXP_SYNTAX */ + } else if ((y >= 0 && !duk_unicode_is_identifier_part(y)) || y == DUK_UNICODE_CP_ZWNJ || y == DUK_UNICODE_CP_ZWJ) { /* For ES5.1 identity escapes are not allowed for identifier * parts. This conflicts with a lot of real world code as this * doesn't e.g. allow escaping a dollar sign as /\$/, see * test-regexp-identity-escape-dollar.js. */ -#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ +#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ out_token->num = (duk_uint32_t) y; } else { goto fail_escape; @@ -86727,24 +88023,24 @@ out_token->t = advtok & 0xff; return; - fail_token_limit: +fail_token_limit: DUK_ERROR_RANGE(lex_ctx->thr, DUK_STR_TOKEN_LIMIT); DUK_WO_NORETURN(return;); - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_ESCAPE); DUK_WO_NORETURN(return;); - fail_group: +fail_group: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_GROUP); DUK_WO_NORETURN(return;); #if !defined(DUK_USE_ES6_REGEXP_SYNTAX) - fail_invalid_char: +fail_invalid_char: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_CHARACTER); DUK_WO_NORETURN(return;); - fail_quantifier: +fail_quantifier: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_QUANTIFIER); DUK_WO_NORETURN(return;); #endif @@ -86803,7 +88099,7 @@ x = DUK__L0(); - ch = -1; /* not strictly necessary, but avoids "uninitialized variable" warnings */ + ch = -1; /* not strictly necessary, but avoids "uninitialized variable" warnings */ DUK_UNREF(ch); if (x < 0) { @@ -86812,7 +88108,7 @@ if (start >= 0) { gen_range(userdata, start, start, 0); } - DUK__ADVANCECHARS(lex_ctx, 1); /* eat '' before finishing */ + DUK__ADVANCECHARS(lex_ctx, 1); /* eat '' before finishing */ break; } else if (x == DUK_ASC_MINUS) { if (start >= 0 && !dash && DUK__L1() != DUK_ASC_RBRACKET) { @@ -86857,8 +88153,7 @@ } else if (x == DUK_ASC_LC_C) { x = DUK__L2(); adv = 3; - if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || - (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { + if ((x >= DUK_ASC_LC_A && x <= DUK_ASC_LC_Z) || (x >= DUK_ASC_UC_A && x <= DUK_ASC_UC_Z)) { ch = (x % 32); } else { goto fail_escape; @@ -86922,7 +88217,7 @@ #if defined(DUK_USE_ES6_REGEXP_SYNTAX) ch = duk__lexer_parse_legacy_octal(lex_ctx, &adv, 0 /*reject_annex_b*/); - DUK_ASSERT(ch >= 0); /* no rejections */ + DUK_ASSERT(ch >= 0); /* no rejections */ #else if (x == DUK_ASC_0 && !DUK__ISDIGIT(DUK__L2())) { ch = 0x0000; @@ -86937,7 +88232,7 @@ * EOF here. */ ch = x; -#else /* DUK_USE_ES6_REGEXP_SYNTAX */ +#else /* DUK_USE_ES6_REGEXP_SYNTAX */ } else if (!duk_unicode_is_identifier_part(x)) { /* IdentityEscape: ES5.1 doesn't allow identity escape * for identifier part characters, which conflicts with @@ -86945,7 +88240,7 @@ * /\$/ which is awkward. */ ch = x; -#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ +#endif /* DUK_USE_ES6_REGEXP_SYNTAX */ } else { goto fail_escape; } @@ -86993,20 +88288,20 @@ return; - fail_escape: +fail_escape: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_REGEXP_ESCAPE); DUK_WO_NORETURN(return;); - fail_range: +fail_range: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_INVALID_RANGE); DUK_WO_NORETURN(return;); - fail_unterm_charclass: +fail_unterm_charclass: DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_UNTERMINATED_CHARCLASS); DUK_WO_NORETURN(return;); } -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* automatic undefs */ #undef DUK__ADVANCEBYTES @@ -87044,10 +88339,10 @@ /* #include duk_internal.h -> already included */ -#define DUK__IEEE_DOUBLE_EXP_BIAS 1023 -#define DUK__IEEE_DOUBLE_EXP_MIN (-1022) /* biased exp == 0 -> denormal, exp -1022 */ +#define DUK__IEEE_DOUBLE_EXP_BIAS 1023 +#define DUK__IEEE_DOUBLE_EXP_MIN (-1022) /* biased exp == 0 -> denormal, exp -1022 */ -#define DUK__DIGITCHAR(x) duk_lc_digits(x) +#define DUK__DIGITCHAR(x) duk_lc_digits(x) /* * Tables generated with util/gennumdigits.py. @@ -87065,10 +88360,10 @@ */ DUK_LOCAL const duk_uint8_t duk__str2num_digits_for_radix = { - 69, 44, 35, 30, 27, 25, 23, 22, 20, 20, /* 2 to 11 */ - 20, 19, 19, 18, 18, 17, 17, 17, 16, 16, /* 12 to 21 */ - 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, /* 22 to 31 */ - 14, 14, 14, 14, 14 /* 31 to 36 */ + 69, 44, 35, 30, 27, 25, 23, 22, 20, 20, /* 2 to 11 */ + 20, 19, 19, 18, 18, 17, 17, 17, 16, 16, /* 12 to 21 */ + 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, /* 22 to 31 */ + 14, 14, 14, 14, 14 /* 31 to 36 */ }; typedef struct { @@ -87077,15 +88372,11 @@ } duk__exp_limits; DUK_LOCAL const duk__exp_limits duk__str2num_exp_limits = { - { 957, -1147 }, { 605, -725 }, { 479, -575 }, { 414, -496 }, - { 372, -446 }, { 342, -411 }, { 321, -384 }, { 304, -364 }, - { 291, -346 }, { 279, -334 }, { 268, -323 }, { 260, -312 }, - { 252, -304 }, { 247, -296 }, { 240, -289 }, { 236, -283 }, - { 231, -278 }, { 227, -273 }, { 223, -267 }, { 220, -263 }, - { 216, -260 }, { 213, -256 }, { 210, -253 }, { 208, -249 }, - { 205, -246 }, { 203, -244 }, { 201, -241 }, { 198, -239 }, - { 196, -237 }, { 195, -234 }, { 193, -232 }, { 191, -230 }, - { 190, -228 }, { 188, -226 }, { 187, -225 }, + { 957, -1147 }, { 605, -725 }, { 479, -575 }, { 414, -496 }, { 372, -446 }, { 342, -411 }, { 321, -384 }, + { 304, -364 }, { 291, -346 }, { 279, -334 }, { 268, -323 }, { 260, -312 }, { 252, -304 }, { 247, -296 }, + { 240, -289 }, { 236, -283 }, { 231, -278 }, { 227, -273 }, { 223, -267 }, { 220, -263 }, { 216, -260 }, + { 213, -256 }, { 210, -253 }, { 208, -249 }, { 205, -246 }, { 203, -244 }, { 201, -241 }, { 198, -239 }, + { 196, -237 }, { 195, -234 }, { 193, -232 }, { 191, -230 }, { 190, -228 }, { 188, -226 }, { 187, -225 }, }; /* @@ -87103,18 +88394,18 @@ /* This upper value has been experimentally determined; debug build will check * bigint size with assertions. */ -#define DUK__BI_MAX_PARTS 37 /* 37x32 = 1184 bits */ +#define DUK__BI_MAX_PARTS 37 /* 37x32 = 1184 bits */ #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) -#define DUK__BI_PRINT(name,x) duk__bi_print((name),(x)) +#define DUK__BI_PRINT(name, x) duk__bi_print((name), (x)) #else -#define DUK__BI_PRINT(name,x) +#define DUK__BI_PRINT(name, x) #endif /* Current size is about 152 bytes. */ typedef struct { duk_small_int_t n; - duk_uint32_t vDUK__BI_MAX_PARTS; /* low to high */ + duk_uint32_t vDUK__BI_MAX_PARTS; /* low to high */ } duk__bigint; #if defined(DUK_USE_DEBUG_LEVEL) && (DUK_USE_DEBUG_LEVEL >= 2) @@ -87139,9 +88430,8 @@ #if defined(DUK_USE_ASSERTIONS) DUK_LOCAL duk_small_int_t duk__bi_is_valid(duk__bigint *x) { - return (duk_small_int_t) - ( ((x->n >= 0) && (x->n <= DUK__BI_MAX_PARTS)) /* is valid size */ && - ((x->n == 0) || (x->vx->n - 1 != 0)) /* is normalized */ ); + return (duk_small_int_t) (((x->n >= 0) && (x->n <= DUK__BI_MAX_PARTS)) /* is valid size */ && + ((x->n == 0) || (x->vx->n - 1 != 0)) /* is normalized */); } #endif @@ -87212,10 +88502,10 @@ return 0; - ret_gt: +ret_gt: return 1; - ret_lt: +ret_lt: return -1; } @@ -87230,11 +88520,14 @@ if (z->n > y->n) { duk__bigint *t; - t = y; y = z; z = t; + t = y; + y = z; + z = t; } DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; tmp = 0U; for (i = 0; i < ny; i++) { DUK_ASSERT(i < DUK__BI_MAX_PARTS); @@ -87255,7 +88548,7 @@ /* no need to normalize */ DUK_ASSERT(duk__bi_is_valid(x)); } -#else /* DUK_USE_64BIT_OPS */ +#else /* DUK_USE_64BIT_OPS */ DUK_LOCAL void duk__bi_add(duk__bigint *x, duk__bigint *y, duk__bigint *z) { duk_uint32_t carry, tmp1, tmp2; duk_small_int_t i, ny, nz; @@ -87265,11 +88558,14 @@ if (z->n > y->n) { duk__bigint *t; - t = y; y = z; z = t; + t = y; + y = z; + z = t; } DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; carry = 0U; for (i = 0; i < ny; i++) { /* Carry is detected based on wrapping which relies on exact 32-bit @@ -87306,7 +88602,7 @@ /* no need to normalize */ DUK_ASSERT(duk__bi_is_valid(x)); } -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ /* x <- y + z */ DUK_LOCAL void duk__bi_add_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) { @@ -87321,7 +88617,7 @@ DUK_ASSERT(duk__bi_is_valid(x)); } -#if 0 /* unused */ +#if 0 /* unused */ /* x <- x + y, use t as temp */ DUK_LOCAL void duk__bi_add_copy(duk__bigint *x, duk__bigint *y, duk__bigint *t) { duk__bi_add(t, x, y); @@ -87341,7 +88637,8 @@ DUK_ASSERT(duk__bi_compare(y, z) >= 0); DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; tmp = 0; for (i = 0; i < ny; i++) { ty = y->vi; @@ -87352,12 +88649,12 @@ } tmp = (duk_int64_t) ty - (duk_int64_t) tz + tmp; x->vi = (duk_uint32_t) ((duk_uint64_t) tmp & 0xffffffffUL); - tmp = tmp >> 32; /* 0 or -1 */ + tmp = tmp >> 32; /* 0 or -1 */ } DUK_ASSERT(tmp == 0); x->n = i; - duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ + duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ DUK_ASSERT(duk__bi_is_valid(x)); } #else @@ -87370,7 +88667,8 @@ DUK_ASSERT(duk__bi_compare(y, z) >= 0); DUK_ASSERT(y->n >= z->n); - ny = y->n; nz = z->n; + ny = y->n; + nz = z->n; borrow = 0U; for (i = 0; i < ny; i++) { /* Borrow is detected based on wrapping which relies on exact 32-bit @@ -87398,12 +88696,12 @@ DUK_ASSERT(borrow == 0U); x->n = i; - duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ + duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ DUK_ASSERT(duk__bi_is_valid(x)); } #endif -#if 0 /* unused */ +#if 0 /* unused */ /* x <- y - z */ DUK_LOCAL void duk__bi_sub_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) { duk__bigint tmp; @@ -87431,7 +88729,7 @@ DUK_ASSERT(duk__bi_is_valid(y)); DUK_ASSERT(duk__bi_is_valid(z)); - nx = y->n + z->n; /* max possible */ + nx = y->n + z->n; /* max possible */ DUK_ASSERT(nx <= DUK__BI_MAX_PARTS); if (nx == 0) { @@ -87450,15 +88748,15 @@ #if defined(DUK_USE_64BIT_OPS) duk_uint64_t tmp = 0U; for (j = 0; j < nz; j++) { - tmp += (duk_uint64_t) y->vi * (duk_uint64_t) z->vj + x->vi+j; - x->vi+j = (duk_uint32_t) (tmp & 0xffffffffUL); + tmp += (duk_uint64_t) y->vi * (duk_uint64_t) z->vj + x->vi + j; + x->vi + j = (duk_uint32_t) (tmp & 0xffffffffUL); tmp = tmp >> 32; } if (tmp > 0) { DUK_ASSERT(i + j < nx); DUK_ASSERT(i + j < DUK__BI_MAX_PARTS); - DUK_ASSERT(x->vi+j == 0U); - x->vi+j = (duk_uint32_t) tmp; + DUK_ASSERT(x->vi + j == 0U); + x->vi + j = (duk_uint32_t) tmp; } #else /* @@ -87478,12 +88776,16 @@ duk_uint32_t a, b, c, d, e, f; duk_uint32_t r, s, t; - a = y->vi; b = a & 0xffffUL; a = a >> 16; + a = y->vi; + b = a & 0xffffUL; + a = a >> 16; f = 0; for (j = 0; j < nz; j++) { - c = z->vj; d = c & 0xffffUL; c = c >> 16; - e = x->vi+j; + c = z->vj; + d = c & 0xffffUL; + c = c >> 16; + e = x->vi + j; /* build result as: (r << 32) + s: start with (BD + E + F) */ r = 0; @@ -87491,26 +88793,34 @@ /* add E */ t = s + e; - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add F */ t = s + f; - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add BC*2^16 */ t = b * c; r += (t >> 16); t = s + ((t & 0xffffUL) << 16); - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add AD*2^16 */ t = a * d; r += (t >> 16); t = s + ((t & 0xffffUL) << 16); - if (t < s) { r++; } /* carry */ + if (t < s) { + r++; + } /* carry */ s = t; /* add AC*2^32 */ @@ -87518,20 +88828,22 @@ r += t; DUK_DDD(DUK_DDDPRINT("ab=%08lx cd=%08lx ef=%08lx -> rs=%08lx %08lx", - (unsigned long) y->vi, (unsigned long) z->vj, - (unsigned long) x->vi+j, (unsigned long) r, + (unsigned long) y->vi, + (unsigned long) z->vj, + (unsigned long) x->vi + j, + (unsigned long) r, (unsigned long) s)); - x->vi+j = s; + x->vi + j = s; f = r; } if (f > 0U) { DUK_ASSERT(i + j < nx); DUK_ASSERT(i + j < DUK__BI_MAX_PARTS); - DUK_ASSERT(x->vi+j == 0U); - x->vi+j = (duk_uint32_t) f; + DUK_ASSERT(x->vi + j == 0U); + x->vi + j = (duk_uint32_t) f; } -#endif /* DUK_USE_64BIT_OPS */ +#endif /* DUK_USE_64BIT_OPS */ } duk__bi_normalize(x); @@ -87570,7 +88882,7 @@ DUK_LOCAL int duk__bi_is_zero(duk__bigint *x) { DUK_ASSERT(duk__bi_is_valid(x)); - return (x->n == 0); /* this is the case for normalized numbers */ + return (x->n == 0); /* this is the case for normalized numbers */ } /* Bigint is 2^52. Used to detect normalized IEEE double mantissa values @@ -87581,8 +88893,7 @@ */ DUK_LOCAL duk_small_int_t duk__bi_is_2to52(duk__bigint *x) { DUK_ASSERT(duk__bi_is_valid(x)); - return (duk_small_int_t) - (x->n == 2) && (x->v0 == 0U) && (x->v1 == (1U << (52-32))); + return (duk_small_int_t) (x->n == 2) && (x->v0 == 0U) && (x->v1 == (1U << (52 - 32))); } /* x <- (1<<y) */ @@ -87601,7 +88912,7 @@ DUK_LOCAL void duk__bi_exp_small(duk__bigint *x, duk_small_int_t b, duk_small_int_t y, duk__bigint *t1, duk__bigint *t2) { /* Fast path the binary case */ - DUK_ASSERT(x != t1 && x != t2 && t1 != t2); /* distinct bignums, easy mistake to make */ + DUK_ASSERT(x != t1 && x != t2 && t1 != t2); /* distinct bignums, easy mistake to make */ DUK_ASSERT(b >= 0); DUK_ASSERT(y >= 0); @@ -87656,14 +88967,14 @@ */ /* Maximum number of digits generated. */ -#define DUK__MAX_OUTPUT_DIGITS 1040 /* (Number.MAX_VALUE).toString(2).length == 1024, + slack */ +#define DUK__MAX_OUTPUT_DIGITS 1040 /* (Number.MAX_VALUE).toString(2).length == 1024, + slack */ /* Maximum number of characters in formatted value. */ -#define DUK__MAX_FORMATTED_LENGTH 1040 /* (-Number.MAX_VALUE).toString(2).length == 1025, + slack */ +#define DUK__MAX_FORMATTED_LENGTH 1040 /* (-Number.MAX_VALUE).toString(2).length == 1025, + slack */ /* Number and (minimum) size of bigints in the nc_ctx structure. */ -#define DUK__NUMCONV_CTX_NUM_BIGINTS 7 -#define DUK__NUMCONV_CTX_BIGINTS_SIZE (sizeof(duk__bigint) * DUK__NUMCONV_CTX_NUM_BIGINTS) +#define DUK__NUMCONV_CTX_NUM_BIGINTS 7 +#define DUK__NUMCONV_CTX_BIGINTS_SIZE (sizeof(duk__bigint) * DUK__NUMCONV_CTX_NUM_BIGINTS) typedef struct { /* Currently about 7*152 = 1064 bytes. The space for these @@ -87673,31 +88984,32 @@ */ duk__bigint f, r, s, mp, mm, t1, t2; - duk_small_int_t is_s2n; /* if 1, doing a string-to-number; else doing a number-to-string */ - duk_small_int_t is_fixed; /* if 1, doing a fixed format output (not free format) */ - duk_small_int_t req_digits; /* requested number of output digits; 0 = free-format */ - duk_small_int_t abs_pos; /* digit position is absolute, not relative */ - duk_small_int_t e; /* exponent for 'f' */ - duk_small_int_t b; /* input radix */ - duk_small_int_t B; /* output radix */ - duk_small_int_t k; /* see algorithm */ - duk_small_int_t low_ok; /* see algorithm */ - duk_small_int_t high_ok; /* see algorithm */ - duk_small_int_t unequal_gaps; /* m+ != m- (very rarely) */ + duk_small_int_t is_s2n; /* if 1, doing a string-to-number; else doing a number-to-string */ + duk_small_int_t is_fixed; /* if 1, doing a fixed format output (not free format) */ + duk_small_int_t req_digits; /* requested number of output digits; 0 = free-format */ + duk_small_int_t abs_pos; /* digit position is absolute, not relative */ + duk_small_int_t e; /* exponent for 'f' */ + duk_small_int_t b; /* input radix */ + duk_small_int_t B; /* output radix */ + duk_small_int_t k; /* see algorithm */ + duk_small_int_t low_ok; /* see algorithm */ + duk_small_int_t high_ok; /* see algorithm */ + duk_small_int_t unequal_gaps; /* m+ != m- (very rarely) */ /* Buffer used for generated digits, values are in the range 0,B-1. */ duk_uint8_t digitsDUK__MAX_OUTPUT_DIGITS; - duk_small_int_t count; /* digit count */ + duk_small_int_t count; /* digit count */ } duk__numconv_stringify_ctx; /* Note: computes with 'idx' in assertions, so caller beware. * 'idx' is preincremented, i.e. '1' on first call, because it * is more convenient for the caller. */ -#define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx,preinc_idx,x) do { \ - DUK_ASSERT((preinc_idx) - 1 >= 0); \ - DUK_ASSERT((preinc_idx) - 1 < DUK__MAX_OUTPUT_DIGITS); \ - ((nc_ctx)->digits(preinc_idx) - 1) = (duk_uint8_t) (x); \ +#define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, preinc_idx, x) \ + do { \ + DUK_ASSERT((preinc_idx) -1 >= 0); \ + DUK_ASSERT((preinc_idx) -1 < DUK__MAX_OUTPUT_DIGITS); \ + ((nc_ctx)->digits(preinc_idx) -1) = (duk_uint8_t) (x); \ } while (0) DUK_LOCAL duk_size_t duk__dragon4_format_uint32(duk_uint8_t *buf, duk_uint32_t x, duk_small_int_t radix) { @@ -87796,11 +89108,11 @@ "lowest mantissa value for this exponent -> " "unequal gaps")); - duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ - duk__bi_mul_small(&nc_ctx->mp, &nc_ctx->mm, (duk_uint32_t) nc_ctx->b); /* mp <- b^(e+1) */ + duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ + duk__bi_mul_small(&nc_ctx->mp, &nc_ctx->mm, (duk_uint32_t) nc_ctx->b); /* mp <- b^(e+1) */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->f, 2); - duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^(e+1) */ - duk__bi_set_small(&nc_ctx->s, (duk_uint32_t) (nc_ctx->b * 2)); /* s <- 2 * b */ + duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^(e+1) */ + duk__bi_set_small(&nc_ctx->s, (duk_uint32_t) (nc_ctx->b * 2)); /* s <- 2 * b */ nc_ctx->unequal_gaps = 1; } else { /* (>= e 0) AND (not (= f (expt b (- p 1)))) @@ -87820,11 +89132,11 @@ "not lowest mantissa for this exponent -> " "equal gaps")); - duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ - duk__bi_copy(&nc_ctx->mp, &nc_ctx->mm); /* mp <- b^e */ + duk__bi_exp_small(&nc_ctx->mm, nc_ctx->b, nc_ctx->e, &nc_ctx->t1, &nc_ctx->t2); /* mm <- b^e */ + duk__bi_copy(&nc_ctx->mp, &nc_ctx->mm); /* mp <- b^e */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->f, 2); - duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^e */ - duk__bi_set_small(&nc_ctx->s, 2); /* s <- 2 */ + duk__bi_mul(&nc_ctx->r, &nc_ctx->t1, &nc_ctx->mp); /* r <- (2 * f) * b^e */ + duk__bi_set_small(&nc_ctx->s, 2); /* s <- 2 */ } } else { /* When doing string-to-number, lowest_mantissa is always 0 so @@ -87846,9 +89158,13 @@ "lowest mantissa for this exponent -> " "unequal gaps")); - duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, (duk_uint32_t) (nc_ctx->b * 2)); /* r <- (2 * b) * f */ - duk__bi_exp_small(&nc_ctx->t1, nc_ctx->b, 1 - nc_ctx->e, &nc_ctx->s, &nc_ctx->t2); /* NB: use 's' as temp on purpose */ - duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(1-e) * 2 */ + duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, (duk_uint32_t) (nc_ctx->b * 2)); /* r <- (2 * b) * f */ + duk__bi_exp_small(&nc_ctx->t1, + nc_ctx->b, + 1 - nc_ctx->e, + &nc_ctx->s, + &nc_ctx->t2); /* NB: use 's' as temp on purpose */ + duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(1-e) * 2 */ duk__bi_set_small(&nc_ctx->mp, 2); duk__bi_set_small(&nc_ctx->mm, 1); nc_ctx->unequal_gaps = 1; @@ -87867,9 +89183,13 @@ "lowest mantissa for this exponent -> " "equal gaps")); - duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, 2); /* r <- 2 * f */ - duk__bi_exp_small(&nc_ctx->t1, nc_ctx->b, -nc_ctx->e, &nc_ctx->s, &nc_ctx->t2); /* NB: use 's' as temp on purpose */ - duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(-e) * 2 */ + duk__bi_mul_small(&nc_ctx->r, &nc_ctx->f, 2); /* r <- 2 * f */ + duk__bi_exp_small(&nc_ctx->t1, + nc_ctx->b, + -nc_ctx->e, + &nc_ctx->s, + &nc_ctx->t2); /* NB: use 's' as temp on purpose */ + duk__bi_mul_small(&nc_ctx->s, &nc_ctx->t1, 2); /* s <- b^(-e) * 2 */ duk__bi_set_small(&nc_ctx->mp, 1); duk__bi_set_small(&nc_ctx->mm, 1); } @@ -87901,8 +89221,8 @@ * impact for very large and very small numbers. */ - DUK_DDD(DUK_DDDPRINT("scale: B=%ld, low_ok=%ld, high_ok=%ld", - (long) nc_ctx->B, (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); + DUK_DDD( + DUK_DDDPRINT("scale: B=%ld, low_ok=%ld, high_ok=%ld", (long) nc_ctx->B, (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); DUK__BI_PRINT("r(init)", &nc_ctx->r); DUK__BI_PRINT("s(init)", &nc_ctx->s); DUK__BI_PRINT("mp(init)", &nc_ctx->mp); @@ -87915,7 +89235,7 @@ DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) >= (nc_ctx->high_ok ? 0 : 1)) { DUK_DDD(DUK_DDDPRINT("k is too low")); /* r <- r @@ -87944,8 +89264,8 @@ DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ - duk__bi_mul_small(&nc_ctx->t2, &nc_ctx->t1, (duk_uint32_t) nc_ctx->B); /* t2 = (* (+ r m+) B) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 = (+ r m+) */ + duk__bi_mul_small(&nc_ctx->t2, &nc_ctx->t1, (duk_uint32_t) nc_ctx->B); /* t2 = (* (+ r m+) B) */ if (duk__bi_compare(&nc_ctx->t2, &nc_ctx->s) <= (nc_ctx->high_ok ? -1 : 0)) { DUK_DDD(DUK_DDDPRINT("k is too high")); /* r <- (* r B) @@ -87966,11 +89286,11 @@ } } - skip_dec_k: +skip_dec_k: if (!nc_ctx->unequal_gaps) { DUK_DDD(DUK_DDDPRINT("equal gaps, copy m- from m+")); - duk__bi_copy(&nc_ctx->mm, &nc_ctx->mp); /* mm <- mp */ + duk__bi_copy(&nc_ctx->mm, &nc_ctx->mp); /* mm <- mp */ } nc_ctx->k = k; @@ -87982,9 +89302,9 @@ } DUK_LOCAL void duk__dragon4_generate(duk__numconv_stringify_ctx *nc_ctx) { - duk_small_int_t tc1, tc2; /* terminating conditions */ - duk_small_int_t d; /* current digit */ - duk_small_int_t count = 0; /* digit count */ + duk_small_int_t tc1, tc2; /* terminating conditions */ + duk_small_int_t d; /* current digit */ + duk_small_int_t count = 0; /* digit count */ /* * Digit generation loop. @@ -88006,25 +89326,28 @@ for (;;) { DUK_DDD(DUK_DDDPRINT("generate loop, count=%ld, k=%ld, B=%ld, low_ok=%ld, high_ok=%ld", - (long) count, (long) nc_ctx->k, (long) nc_ctx->B, - (long) nc_ctx->low_ok, (long) nc_ctx->high_ok)); + (long) count, + (long) nc_ctx->k, + (long) nc_ctx->B, + (long) nc_ctx->low_ok, + (long) nc_ctx->high_ok)); DUK__BI_PRINT("r", &nc_ctx->r); DUK__BI_PRINT("s", &nc_ctx->s); DUK__BI_PRINT("m+", &nc_ctx->mp); DUK__BI_PRINT("m-", &nc_ctx->mm); /* (quotient-remainder (* r B) s) using a dummy subtraction loop */ - duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, (duk_uint32_t) nc_ctx->B); /* t1 <- (* r B) */ + duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, (duk_uint32_t) nc_ctx->B); /* t1 <- (* r B) */ d = 0; for (;;) { if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { break; } - duk__bi_sub_copy(&nc_ctx->t1, &nc_ctx->s, &nc_ctx->t2); /* t1 <- t1 - s */ + duk__bi_sub_copy(&nc_ctx->t1, &nc_ctx->s, &nc_ctx->t2); /* t1 <- t1 - s */ d++; } - duk__bi_copy(&nc_ctx->r, &nc_ctx->t1); /* r <- (remainder (* r B) s) */ - /* d <- (quotient (* r B) s) (in range 0...B-1) */ + duk__bi_copy(&nc_ctx->r, &nc_ctx->t1); /* r <- (remainder (* r B) s) */ + /* d <- (quotient (* r B) s) (in range 0...B-1) */ DUK_DDD(DUK_DDDPRINT("-> d(quot)=%ld", (long) d)); DUK__BI_PRINT("r(rem)", &nc_ctx->r); @@ -88043,7 +89366,7 @@ /* free-form */ tc1 = (duk__bi_compare(&nc_ctx->r, &nc_ctx->mm) <= (nc_ctx->low_ok ? 0 : -1)); - duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 <- (+ r m+) */ + duk__bi_add(&nc_ctx->t1, &nc_ctx->r, &nc_ctx->mp); /* t1 <- (+ r m+) */ tc2 = (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) >= (nc_ctx->high_ok ? 0 : 1)); DUK_DDD(DUK_DDDPRINT("tc1=%ld, tc2=%ld", (long) tc1, (long) tc2)); @@ -88062,20 +89385,21 @@ if (tc2) { /* tc1 = true, tc2 = true */ duk__bi_mul_small(&nc_ctx->t1, &nc_ctx->r, 2); - if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { /* (< (* r 2) s) */ + if (duk__bi_compare(&nc_ctx->t1, &nc_ctx->s) < 0) { /* (< (* r 2) s) */ DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=true, 2r > s: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + (long) d, + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); } else { DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=true, 2r <= s: output d+1 --> %ld (k=%ld)", - (long) (d + 1), (long) nc_ctx->k)); + (long) (d + 1), + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d + 1); } break; } else { /* tc1 = true, tc2 = false */ - DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=false: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + DUK_DDD(DUK_DDDPRINT("tc1=true, tc2=false: output d --> %ld (k=%ld)", (long) d, (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); break; } @@ -88083,13 +89407,13 @@ if (tc2) { /* tc1 = false, tc2 = true */ DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=true: output d+1 --> %ld (k=%ld)", - (long) (d + 1), (long) nc_ctx->k)); + (long) (d + 1), + (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d + 1); break; } else { /* tc1 = false, tc2 = false */ - DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=false: output d --> %ld (k=%ld)", - (long) d, (long) nc_ctx->k)); + DUK_DDD(DUK_DDDPRINT("tc1=false, tc2=false: output d --> %ld (k=%ld)", (long) d, (long) nc_ctx->k)); DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, count, d); /* r <- r (updated above: r <- (remainder (* r B) s) @@ -88106,23 +89430,28 @@ /* fixed-format termination conditions */ if (nc_ctx->is_fixed) { if (nc_ctx->abs_pos) { - int pos = nc_ctx->k - count + 1; /* count is already incremented, take into account */ + int pos = nc_ctx->k - count + 1; /* count is already incremented, take into account */ DUK_DDD(DUK_DDDPRINT("fixed format, absolute: abs pos=%ld, k=%ld, count=%ld, req=%ld", - (long) pos, (long) nc_ctx->k, (long) count, (long) nc_ctx->req_digits)); + (long) pos, + (long) nc_ctx->k, + (long) count, + (long) nc_ctx->req_digits)); if (pos <= nc_ctx->req_digits) { DUK_DDD(DUK_DDDPRINT("digit position reached req_digits, end generate loop")); break; } } else { DUK_DDD(DUK_DDDPRINT("fixed format, relative: k=%ld, count=%ld, req=%ld", - (long) nc_ctx->k, (long) count, (long) nc_ctx->req_digits)); + (long) nc_ctx->k, + (long) count, + (long) nc_ctx->req_digits)); if (count >= nc_ctx->req_digits) { DUK_DDD(DUK_DDDPRINT("digit count reached req_digits, end generate loop")); break; } } } - } /* for */ + } /* for */ nc_ctx->count = count; @@ -88141,8 +89470,7 @@ bufi = (duk_uint8_t) DUK__DIGITCHAR(t); } } - DUK_DDD(DUK_DDDPRINT("-> generated digits; k=%ld, digits='%s'", - (long) nc_ctx->k, (const char *) buf)); + DUK_DDD(DUK_DDDPRINT("-> generated digits; k=%ld, digits='%s'", (long) nc_ctx->k, (const char *) buf)); } #endif } @@ -88171,11 +89499,11 @@ if (round_idx >= nc_ctx->count) { DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld >= %ld (count)) -> no rounding", - (long) round_idx, (long) nc_ctx->count)); + (long) round_idx, + (long) nc_ctx->count)); return 0; } else if (round_idx < 0) { - DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld < 0) -> no rounding", - (long) round_idx)); + DUK_DDD(DUK_DDDPRINT("round_idx out of bounds (%ld < 0) -> no rounding", (long) round_idx)); return 0; } @@ -88200,15 +89528,18 @@ duk_memmove((void *) (&nc_ctx->digits1), (const void *) (&nc_ctx->digits0), (size_t) (sizeof(char) * (size_t) nc_ctx->count)); - nc_ctx->digits0 = 1; /* don't increase 'count' */ - nc_ctx->k++; /* position of highest digit changed */ - nc_ctx->count++; /* number of digits changed */ + nc_ctx->digits0 = 1; /* don't increase 'count' */ + nc_ctx->k++; /* position of highest digit changed */ + nc_ctx->count++; /* number of digits changed */ ret = 1; break; } DUK_DDD(DUK_DDDPRINT("fixed-format rounding carry: B=%ld, roundup_limit=%ld, p=%p, digits=%p", - (long) nc_ctx->B, (long) roundup_limit, (void *) p, (void *) nc_ctx->digits)); + (long) nc_ctx->B, + (long) roundup_limit, + (void *) p, + (void *) nc_ctx->digits)); p--; t = *p; DUK_DDD(DUK_DDDPRINT("digit before carry: %ld", (long) t)); @@ -88225,7 +89556,7 @@ return ret; } -#define DUK__NO_EXP (65536) /* arbitrary marker, outside valid exp range */ +#define DUK__NO_EXP (65536) /* arbitrary marker, outside valid exp range */ DUK_LOCAL void duk__dragon4_convert_and_push(duk__numconv_stringify_ctx *nc_ctx, duk_hthread *thr, @@ -88268,7 +89599,7 @@ DUK_ASSERT(nc_ctx->count >= 1); k = nc_ctx->k; - buf = (duk_uint8_t *) &nc_ctx->f; /* XXX: union would be more correct */ + buf = (duk_uint8_t *) &nc_ctx->f; /* XXX: union would be more correct */ q = buf; /* Exponent handling: if exponent format is used, record exponent value and @@ -88280,14 +89611,13 @@ expt = DUK__NO_EXP; if (!nc_ctx->abs_pos /* toFixed() */) { - if ((flags & DUK_N2S_FLAG_FORCE_EXP) || /* exponential notation forced */ - ((flags & DUK_N2S_FLAG_NO_ZERO_PAD) && /* fixed precision and zero padding would be required */ - (k - digits >= 1)) || /* (e.g. k=3, digits=2 -> "12X") */ - ((k > 21 || k <= -6) && (radix == 10))) { /* toString() conditions */ - DUK_DDD(DUK_DDDPRINT("use exponential notation: k=%ld -> expt=%ld", - (long) k, (long) (k - 1))); - expt = k - 1; /* e.g. 12.3 -> digits="123" k=2 -> 1.23e1 */ - k = 1; /* generate mantissa with a single leading whole number digit */ + if ((flags & DUK_N2S_FLAG_FORCE_EXP) || /* exponential notation forced */ + ((flags & DUK_N2S_FLAG_NO_ZERO_PAD) && /* fixed precision and zero padding would be required */ + (k - digits >= 1)) || /* (e.g. k=3, digits=2 -> "12X") */ + ((k > 21 || k <= -6) && (radix == 10))) { /* toString() conditions */ + DUK_DDD(DUK_DDDPRINT("use exponential notation: k=%ld -> expt=%ld", (long) k, (long) (k - 1))); + expt = k - 1; /* e.g. 12.3 -> digits="123" k=2 -> 1.23e1 */ + k = 1; /* generate mantissa with a single leading whole number digit */ } } @@ -88313,13 +89643,18 @@ DUK_DDD(DUK_DDDPRINT("expt=%ld, k=%ld, count=%ld, pos=%ld, pos_end=%ld, is_fixed=%ld, " "digits=%ld, abs_pos=%ld", - (long) expt, (long) k, (long) nc_ctx->count, (long) pos, (long) pos_end, - (long) nc_ctx->is_fixed, (long) digits, (long) nc_ctx->abs_pos)); + (long) expt, + (long) k, + (long) nc_ctx->count, + (long) pos, + (long) pos_end, + (long) nc_ctx->is_fixed, + (long) digits, + (long) nc_ctx->abs_pos)); /* Digit generation */ while (pos > pos_end) { - DUK_DDD(DUK_DDDPRINT("digit generation: pos=%ld, pos_end=%ld", - (long) pos, (long) pos_end)); + DUK_DDD(DUK_DDDPRINT("digit generation: pos=%ld, pos_end=%ld", (long) pos, (long) pos_end)); if (pos == 0) { *q++ = (duk_uint8_t) '.'; } @@ -88412,7 +89747,7 @@ /* normal: implicit leading 1-bit */ nc_ctx->f.v1 |= 0x00100000UL; expt = expt - DUK__IEEE_DOUBLE_EXP_BIAS - 52; - DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); /* true, because v1 has at least one bit set */ + DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); /* true, because v1 has at least one bit set */ } DUK_ASSERT(duk__bi_is_valid(&nc_ctx->f)); @@ -88435,7 +89770,7 @@ /* Sometimes this assert is not true right now; it will be true after * rounding. See: test-bug-numconv-mantissa-assert.js. */ - DUK_ASSERT_DISABLE(nc_ctx->digits0 == 1); /* zero handled by caller */ + DUK_ASSERT_DISABLE(nc_ctx->digits0 == 1); /* zero handled by caller */ /* Should not be required because the code below always sets both high * and low parts, but at least gcc-4.4.5 fails to deduce this correctly @@ -88480,31 +89815,30 @@ skip_round = 0; - recheck_exp: +recheck_exp: - expt = nc_ctx->k - 1; /* IEEE exp without bias */ + expt = nc_ctx->k - 1; /* IEEE exp without bias */ if (expt > 1023) { /* Infinity */ - bitstart = -255; /* needed for inf: causes mantissa to become zero, - * and rounding to be skipped. - */ + bitstart = -255; /* needed for inf: causes mantissa to become zero, + * and rounding to be skipped. + */ expt = 2047; } else if (expt >= -1022) { /* normal */ - bitstart = 1; /* skip leading digit */ + bitstart = 1; /* skip leading digit */ expt += DUK__IEEE_DOUBLE_EXP_BIAS; DUK_ASSERT(expt >= 1 && expt <= 2046); } else { /* denormal or zero */ - bitstart = 1023 + expt; /* expt==-1023 -> bitstart=0 (leading 1); - * expt==-1024 -> bitstart=-1 (one left of leading 1), etc - */ + bitstart = 1023 + expt; /* expt==-1023 -> bitstart=0 (leading 1); + * expt==-1024 -> bitstart=-1 (one left of leading 1), etc + */ expt = 0; } bitround = bitstart + 52; - DUK_DDD(DUK_DDDPRINT("ieee expt=%ld, bitstart=%ld, bitround=%ld", - (long) expt, (long) bitstart, (long) bitround)); + DUK_DDD(DUK_DDDPRINT("ieee expt=%ld, bitstart=%ld, bitround=%ld", (long) expt, (long) bitstart, (long) bitround)); if (!skip_round) { if (duk__dragon4_fixed_format_round(nc_ctx, bitround)) { @@ -88542,13 +89876,11 @@ } /* t has high mantissa */ - DUK_DDD(DUK_DDDPRINT("mantissa is complete: %08lx %08lx", - (unsigned long) t, - (unsigned long) DUK_DBLUNION_GET_LOW32(&u))); + DUK_DDD(DUK_DDDPRINT("mantissa is complete: %08lx %08lx", (unsigned long) t, (unsigned long) DUK_DBLUNION_GET_LOW32(&u))); DUK_ASSERT(expt >= 0 && expt <= 0x7ffL); t += ((duk_uint32_t) expt) << 20; -#if 0 /* caller handles sign change */ +#if 0 /* caller handles sign change */ if (negative) { t |= 0x80000000U; } @@ -88569,12 +89901,15 @@ * Output: string */ -DUK_LOCAL DUK_NOINLINE void duk__numconv_stringify_raw(duk_hthread *thr, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags) { +DUK_LOCAL DUK_NOINLINE void duk__numconv_stringify_raw(duk_hthread *thr, + duk_small_int_t radix, + duk_small_int_t digits, + duk_small_uint_t flags) { duk_double_t x; duk_small_int_t c; duk_small_int_t neg; duk_uint32_t uval; - duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ + duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ duk__numconv_stringify_ctx *nc_ctx = &nc_ctx_alloc; x = (duk_double_t) duk_require_number(thr, -1); @@ -88626,13 +89961,13 @@ */ uval = duk_double_to_uint32_t(x); - if (duk_double_equals((double) uval, x) && /* integer number in range */ - flags == 0) { /* no special formatting */ + if (duk_double_equals((double) uval, x) && /* integer number in range */ + flags == 0) { /* no special formatting */ /* use bigint area as a temp */ duk_uint8_t *buf = (duk_uint8_t *) (&nc_ctx->f); duk_uint8_t *p = buf; - DUK_ASSERT(DUK__NUMCONV_CTX_BIGINTS_SIZE >= 32 + 1); /* max size: radix=2 + sign */ + DUK_ASSERT(DUK__NUMCONV_CTX_BIGINTS_SIZE >= 32 + 1); /* max size: radix=2 + sign */ if (neg && uval != 0) { /* no negative sign for zero */ *p++ = (duk_uint8_t) '-'; @@ -88688,9 +90023,9 @@ duk_small_int_t count; if (nc_ctx->is_fixed) { if (nc_ctx->abs_pos) { - count = digits + 2; /* lead zero + 'digits' fractions + 1 for rounding */ + count = digits + 2; /* lead zero + 'digits' fractions + 1 for rounding */ } else { - count = digits + 1; /* + 1 for rounding */ + count = digits + 1; /* + 1 for rounding */ } } else { count = 1; @@ -88699,12 +90034,12 @@ DUK_ASSERT(count >= 1); duk_memzero((void *) nc_ctx->digits, (size_t) count); nc_ctx->count = count; - nc_ctx->k = 1; /* 0.000... */ + nc_ctx->k = 1; /* 0.000... */ neg = 0; goto zero_skip; } - duk__dragon4_double_to_ctx(nc_ctx, x); /* -> sets 'f' and 'e' */ + duk__dragon4_double_to_ctx(nc_ctx, x); /* -> sets 'f' and 'e' */ DUK__BI_PRINT("f", &nc_ctx->f); DUK_DDD(DUK_DDDPRINT("e=%ld", (long) nc_ctx->e)); @@ -88712,7 +90047,7 @@ * Dragon4 slow path digit generation. */ - duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ + duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ DUK_DDD(DUK_DDDPRINT("after prepare:")); DUK__BI_PRINT("r", &nc_ctx->r); @@ -88734,7 +90069,7 @@ * Convert and push final string. */ - zero_skip: +zero_skip: if (flags & DUK_N2S_FLAG_FIXED_FORMAT) { /* Perform fixed-format rounding. */ @@ -88743,13 +90078,16 @@ /* 'roundpos' is relative to nc_ctx->k and increases to the right * (opposite of how 'k' changes). */ - roundpos = -digits; /* absolute position for digit considered for rounding */ + roundpos = -digits; /* absolute position for digit considered for rounding */ roundpos = nc_ctx->k - roundpos; } else { roundpos = digits; } DUK_DDD(DUK_DDDPRINT("rounding: k=%ld, count=%ld, digits=%ld, roundpos=%ld", - (long) nc_ctx->k, (long) nc_ctx->count, (long) digits, (long) roundpos)); + (long) nc_ctx->k, + (long) nc_ctx->count, + (long) digits, + (long) roundpos)); (void) duk__dragon4_fixed_format_round(nc_ctx, roundpos); /* Note: 'count' is currently not adjusted by rounding (i.e. the @@ -88778,7 +90116,7 @@ */ DUK_LOCAL DUK_NOINLINE void duk__numconv_parse_raw(duk_hthread *thr, duk_small_int_t radix, duk_small_uint_t flags) { - duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ + duk__numconv_stringify_ctx nc_ctx_alloc; /* large context; around 2kB now */ duk__numconv_stringify_ctx *nc_ctx = &nc_ctx_alloc; duk_double_t res; duk_hstring *h_str; @@ -88798,7 +90136,8 @@ DUK_DDD(DUK_DDDPRINT("parse number: %!T, radix=%ld, flags=0x%08lx", (duk_tval *) duk_get_tval(thr, -1), - (long) radix, (unsigned long) flags)); + (long) radix, + (unsigned long) flags)); DUK_ASSERT(radix >= 2 && radix <= 36); DUK_ASSERT(radix - 2 < (duk_small_int_t) sizeof(duk__str2num_digits_for_radix)); @@ -88871,7 +90210,7 @@ ch = *p; if (ch == (duk_small_int_t) '0') { duk_small_int_t detect_radix = 0; - ch = DUK_LOWERCASE_CHAR_ASCII(p1); /* 'x' or 'X' -> 'x' */ + ch = DUK_LOWERCASE_CHAR_ASCII(p1); /* 'x' or 'X' -> 'x' */ if ((flags & DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT) && ch == DUK_ASC_LC_X) { DUK_DDD(DUK_DDDPRINT("detected 0x/0X hex prefix, changing radix and preventing fractions and exponent")); detect_radix = 16; @@ -88898,10 +90237,9 @@ if (detect_radix > 0) { radix = detect_radix; /* Clear empty as zero flag: interpret e.g. '0x' and '0xg' as a NaN (= parse error) */ - flags &= ~(DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | - DUK_S2N_FLAG_ALLOW_FRAC | DUK_S2N_FLAG_ALLOW_NAKED_FRAC | - DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO); - flags |= DUK_S2N_FLAG_ALLOW_LEADING_ZERO; /* allow e.g. '0x0009' and '0b00010001' */ + flags &= ~(DUK_S2N_FLAG_ALLOW_EXP | DUK_S2N_FLAG_ALLOW_EMPTY_FRAC | DUK_S2N_FLAG_ALLOW_FRAC | + DUK_S2N_FLAG_ALLOW_NAKED_FRAC | DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO); + flags |= DUK_S2N_FLAG_ALLOW_LEADING_ZERO; /* allow e.g. '0x0009' and '0b00010001' */ p += 2; } } @@ -88959,16 +90297,23 @@ dig_frac = -1; dig_expt = -1; expt = 0; - expt_adj = 0; /* essentially tracks digit position of lowest 'f' digit */ + expt_adj = 0; /* essentially tracks digit position of lowest 'f' digit */ expt_neg = 0; for (;;) { ch = *p++; DUK_DDD(DUK_DDDPRINT("parse digits: p=%p, ch='%c' (%ld), expt=%ld, expt_adj=%ld, " "dig_whole=%ld, dig_frac=%ld, dig_expt=%ld, dig_lzero=%ld, dig_prec=%ld", - (const void *) p, (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : '?'), (long) ch, - (long) expt, (long) expt_adj, (long) dig_whole, (long) dig_frac, - (long) dig_expt, (long) dig_lzero, (long) dig_prec)); + (const void *) p, + (int) ((ch >= 0x20 && ch <= 0x7e) ? ch : '?'), + (long) ch, + (long) expt, + (long) expt_adj, + (long) dig_whole, + (long) dig_frac, + (long) dig_expt, + (long) dig_lzero, + (long) dig_prec)); DUK__BI_PRINT("f", &nc_ctx->f); /* Most common cases first. */ @@ -89007,8 +90352,8 @@ } else if (ch == (duk_small_int_t) 0) { DUK_DDD(DUK_DDDPRINT("NUL termination")); break; - } else if ((flags & DUK_S2N_FLAG_ALLOW_EXP) && - dig_expt < 0 && (ch == (duk_small_int_t) 'e' || ch == (duk_small_int_t) 'E')) { + } else if ((flags & DUK_S2N_FLAG_ALLOW_EXP) && dig_expt < 0 && + (ch == (duk_small_int_t) 'e' || ch == (duk_small_int_t) 'E')) { /* Note: we don't parse back exponent notation for anything else * than radix 10, so this is not an ambiguous check (e.g. hex * exponent values may have 'e' either as a significand digit @@ -89038,7 +90383,7 @@ } else if (ch >= (duk_small_int_t) 'A' && ch <= (duk_small_int_t) 'Z') { dig = (duk_small_int_t) (ch - (duk_small_int_t) 'A' + 0x0a); } else { - dig = 255; /* triggers garbage digit check below */ + dig = 255; /* triggers garbage digit check below */ } DUK_ASSERT((dig >= 0 && dig <= 35) || dig == 255); @@ -89171,14 +90516,14 @@ if (expt_neg) { expt = -expt; } - DUK_DDD(DUK_DDDPRINT("expt=%ld, expt_adj=%ld, net exponent -> %ld", - (long) expt, (long) expt_adj, (long) (expt + expt_adj))); + DUK_DDD( + DUK_DDDPRINT("expt=%ld, expt_adj=%ld, net exponent -> %ld", (long) expt, (long) expt_adj, (long) (expt + expt_adj))); expt += expt_adj; /* Fast path check. */ - if (nc_ctx->f.n <= 1 && /* 32-bit value */ - expt == 0 /* no net exponent */) { + if (nc_ctx->f.n <= 1 && /* 32-bit value */ + expt == 0 /* no net exponent */) { /* Fast path is triggered for no exponent and also for balanced exponent * and fraction parts, e.g. for "1.23e2" == "123". Remember to respect * zero sign. @@ -89220,7 +90565,6 @@ goto negcheck_and_ret; } - /* Quick reject of too large or too small exponents. This check * would be incorrect for zero (e.g. "0e1000" is zero, not Infinity) * so zero check must be above. @@ -89253,7 +90597,7 @@ * An extra digit is generated for rounding. */ - duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ + duk__dragon4_prepare(nc_ctx); /* setup many variables in nc_ctx */ DUK_DDD(DUK_DDDPRINT("after prepare:")); DUK__BI_PRINT("r", &nc_ctx->r); @@ -89285,7 +90629,7 @@ duk__dragon4_ctx_to_double(nc_ctx, &res); goto negcheck_and_ret; - negcheck_and_ret: +negcheck_and_ret: if (neg) { res = -res; } @@ -89294,13 +90638,13 @@ DUK_DDD(DUK_DDDPRINT("result: %!T", (duk_tval *) duk_get_tval(thr, -1))); return; - parse_fail: +parse_fail: DUK_DDD(DUK_DDDPRINT("parse failed")); duk_pop(thr); duk_push_nan(thr); return; - parse_explimit_error: +parse_explimit_error: DUK_DDD(DUK_DDDPRINT("parse failed, internal error, can't return a value")); DUK_ERROR_RANGE(thr, "exponent too large"); DUK_WO_NORETURN(return;); @@ -89354,8 +90698,7 @@ #define DUK__RE_INITIAL_BUFSIZE 64 -#define DUK__RE_BUFLEN(re_ctx) \ - DUK_BW_GET_SIZE(re_ctx->thr, &re_ctx->bw) +#define DUK__RE_BUFLEN(re_ctx) DUK_BW_GET_SIZE(re_ctx->thr, &re_ctx->bw) /* * Disjunction struct: result of parsing a disjunction @@ -89445,7 +90788,7 @@ (void) duk__append_7bit(re_ctx, reop); } -#if 0 /* unused */ +#if 0 /* unused */ DUK_LOCAL void duk__append_i32(duk_re_compiler_ctx *re_ctx, duk_int32_t x) { duk__append_u32(re_ctx, duk__encode_i32(x)); } @@ -89459,7 +90802,10 @@ } } -DUK_LOCAL void duk__insert_slice(duk_re_compiler_ctx *re_ctx, duk_uint32_t offset, duk_uint32_t data_offset, duk_uint32_t data_length) { +DUK_LOCAL void duk__insert_slice(duk_re_compiler_ctx *re_ctx, + duk_uint32_t offset, + duk_uint32_t data_offset, + duk_uint32_t data_length) { DUK_BW_INSERT_ENSURE_SLICE(re_ctx->thr, &re_ctx->bw, offset, data_offset, data_length); } @@ -89522,7 +90868,7 @@ skip--; } } -#else /* DUK_USE_PREFER_SIZE */ +#else /* DUK_USE_PREFER_SIZE */ /* Closed form solution, this produces fastest code. * See re_neg_jump_offset (closed1). */ @@ -89543,7 +90889,7 @@ skip -= 7; } } -#endif /* DUK_USE_PREFER_SIZE */ +#endif /* DUK_USE_PREFER_SIZE */ return duk__insert_i32(re_ctx, offset, skip); } @@ -89676,10 +91022,10 @@ } } } - DUK_ASSERT(blk == end_blk + 1); /* Reached end block which is continuous. */ + DUK_ASSERT(blk == end_blk + 1); /* Reached end block which is continuous. */ return end; } -#else /* DUK_USE_REGEXP_CANON_BITMAP */ +#else /* DUK_USE_REGEXP_CANON_BITMAP */ DUK_LOCAL duk_codepoint_t duk__re_canon_next_discontinuity(duk_codepoint_t start, duk_codepoint_t end) { DUK_ASSERT(start >= 0); DUK_ASSERT(end >= 0); @@ -89690,7 +91036,7 @@ } return start; } -#endif /* DUK_USE_REGEXP_CANON_BITMAP */ +#endif /* DUK_USE_REGEXP_CANON_BITMAP */ DUK_LOCAL void duk__regexp_generate_ranges(void *userdata, duk_codepoint_t r1, duk_codepoint_t r2, duk_bool_t direct) { duk_re_compiler_ctx *re_ctx = (duk_re_compiler_ctx *) userdata; @@ -89701,9 +91047,12 @@ duk_codepoint_t r_disc; DUK_DD(DUK_DDPRINT("duk__regexp_generate_ranges(): re_ctx=%p, range=%ld,%ld direct=%ld", - (void *) re_ctx, (long) r1, (long) r2, (long) direct)); + (void *) re_ctx, + (long) r1, + (long) r2, + (long) direct)); - DUK_ASSERT(r2 >= r1); /* SyntaxError for out of order range. */ + DUK_ASSERT(r2 >= r1); /* SyntaxError for out of order range. */ if (direct || (re_ctx->re_flags & DUK_RE_FLAG_IGNORE_CASE) == 0) { DUK_DD(DUK_DDPRINT("direct or not case sensitive, emit range: %ld,%ld", (long) r1, (long) r2)); @@ -89725,7 +91074,7 @@ DUK_ASSERT(r_disc >= i); DUK_ASSERT(r_disc <= r2); - r_end += r_disc - i; /* May be zero. */ + r_end += r_disc - i; /* May be zero. */ t = duk_unicode_re_canonicalize_char(re_ctx->thr, r_disc); if (t == r_end + 1) { /* Not actually a discontinuity, continue range @@ -89737,11 +91086,11 @@ r_start = t; r_end = t; } - i = r_disc + 1; /* Guarantees progress. */ + i = r_disc + 1; /* Guarantees progress. */ } duk__regexp_emit_range(re_ctx, r_start, r_end); -#if 0 /* Exhaustive search, very slow. */ +#if 0 /* Exhaustive search, very slow. */ r_start = duk_unicode_re_canonicalize_char(re_ctx->thr, r1); r_end = r_start; for (i = r1 + 1; i <= r2; i++) { @@ -89814,18 +91163,17 @@ * as complex though. */ -DUK_LOCAL const duk_uint16_t * const duk__re_range_lookup13 = { - duk_unicode_re_ranges_digit, - duk_unicode_re_ranges_white, - duk_unicode_re_ranges_wordchar -}; -DUK_LOCAL const duk_uint8_t duk__re_range_lookup23 = { - sizeof(duk_unicode_re_ranges_digit) / (2 * sizeof(duk_uint16_t)), - sizeof(duk_unicode_re_ranges_white) / (2 * sizeof(duk_uint16_t)), - sizeof(duk_unicode_re_ranges_wordchar) / (2 * sizeof(duk_uint16_t)) -}; - -DUK_LOCAL void duk__append_range_atom_matcher(duk_re_compiler_ctx *re_ctx, duk_small_uint_t re_op, const duk_uint16_t *ranges, duk_small_uint_t count) { +DUK_LOCAL const duk_uint16_t * const duk__re_range_lookup13 = { duk_unicode_re_ranges_digit, + duk_unicode_re_ranges_white, + duk_unicode_re_ranges_wordchar }; +DUK_LOCAL const duk_uint8_t duk__re_range_lookup23 = { sizeof(duk_unicode_re_ranges_digit) / (2 * sizeof(duk_uint16_t)), + sizeof(duk_unicode_re_ranges_white) / (2 * sizeof(duk_uint16_t)), + sizeof(duk_unicode_re_ranges_wordchar) / (2 * sizeof(duk_uint16_t)) }; + +DUK_LOCAL void duk__append_range_atom_matcher(duk_re_compiler_ctx *re_ctx, + duk_small_uint_t re_op, + const duk_uint16_t *ranges, + duk_small_uint_t count) { #if 0 DUK_ASSERT(re_op <= 0x7fUL); DUK_ASSERT(count <= 0x7fUL); @@ -89837,13 +91185,13 @@ } DUK_LOCAL void duk__parse_disjunction(duk_re_compiler_ctx *re_ctx, duk_bool_t expect_eof, duk__re_disjunction_info *out_atom_info) { - duk_int32_t atom_start_offset = -1; /* negative -> no atom matched on previous round */ - duk_int32_t atom_char_length = 0; /* negative -> complex atom */ - duk_uint32_t atom_start_captures = re_ctx->captures; /* value of re_ctx->captures at start of atom */ + duk_int32_t atom_start_offset = -1; /* negative -> no atom matched on previous round */ + duk_int32_t atom_char_length = 0; /* negative -> complex atom */ + duk_uint32_t atom_start_captures = re_ctx->captures; /* value of re_ctx->captures at start of atom */ duk_int32_t unpatched_disjunction_split = -1; duk_int32_t unpatched_disjunction_jump = -1; duk_uint32_t entry_offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); - duk_int32_t res_charlen = 0; /* -1 if disjunction is complex, char length if simple */ + duk_int32_t res_charlen = 0; /* -1 if disjunction is complex, char length if simple */ duk__re_disjunction_info tmp_disj; DUK_ASSERT(out_atom_info != NULL); @@ -89866,19 +91214,19 @@ * new_atom_char_length etc are for the atom parsed on this round; * they're written to atom_char_length etc at the end of the round. */ - duk_int32_t new_atom_char_length; /* char length of the atom parsed in this loop */ - duk_int32_t new_atom_start_offset; /* bytecode start offset of the atom parsed in this loop - * (allows quantifiers to copy the atom bytecode) - */ - duk_uint32_t new_atom_start_captures; /* re_ctx->captures at the start of the atom parsed in this loop */ + duk_int32_t new_atom_char_length; /* char length of the atom parsed in this loop */ + duk_int32_t new_atom_start_offset; /* bytecode start offset of the atom parsed in this loop + * (allows quantifiers to copy the atom bytecode) + */ + duk_uint32_t new_atom_start_captures; /* re_ctx->captures at the start of the atom parsed in this loop */ duk_lexer_parse_re_token(&re_ctx->lex, &re_ctx->curr_token); - DUK_DD(DUK_DDPRINT("re token: %ld (num=%ld, char=%c)", - (long) re_ctx->curr_token.t, - (long) re_ctx->curr_token.num, - (re_ctx->curr_token.num >= 0x20 && re_ctx->curr_token.num <= 0x7e) ? - (int) re_ctx->curr_token.num : (int) '?')); + DUK_DD(DUK_DDPRINT( + "re token: %ld (num=%ld, char=%c)", + (long) re_ctx->curr_token.t, + (long) re_ctx->curr_token.num, + (re_ctx->curr_token.num >= 0x20 && re_ctx->curr_token.num <= 0x7e) ? (int) re_ctx->curr_token.num : (int) '?')); /* set by atom case clauses */ new_atom_start_offset = -1; @@ -89899,9 +91247,7 @@ DUK_ASSERT(unpatched_disjunction_split >= 0); offset = (duk_uint32_t) unpatched_disjunction_jump; - offset += duk__insert_jump_offset(re_ctx, - offset, - (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); + offset += duk__insert_jump_offset(re_ctx, offset, (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); /* offset is now target of the pending split (right after jump) */ duk__insert_jump_offset(re_ctx, (duk_uint32_t) unpatched_disjunction_split, @@ -89909,10 +91255,8 @@ } /* add a new pending split to the beginning of the entire disjunction */ - (void) duk__insert_u32(re_ctx, - entry_offset, - DUK_REOP_SPLIT1); /* prefer direct execution */ - unpatched_disjunction_split = (duk_int32_t) (entry_offset + 1); /* +1 for opcode */ + (void) duk__insert_u32(re_ctx, entry_offset, DUK_REOP_SPLIT1); /* prefer direct execution */ + unpatched_disjunction_split = (duk_int32_t) (entry_offset + 1); /* +1 for opcode */ /* add a new pending match jump for latest finished alternative */ duk__append_reop(re_ctx, DUK_REOP_JUMP); @@ -89960,7 +91304,7 @@ } } - duk__append_reop(re_ctx, DUK_REOP_MATCH); /* complete 'sub atom' */ + duk__append_reop(re_ctx, DUK_REOP_MATCH); /* complete 'sub atom' */ atom_code_length = (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (duk_size_t) atom_start_offset); offset = (duk_uint32_t) atom_start_offset; @@ -89976,7 +91320,7 @@ offset += duk__insert_u32(re_ctx, offset, qmax); offset += duk__insert_jump_offset(re_ctx, offset, atom_code_length); } - DUK_UNREF(offset); /* silence scan-build warning */ + DUK_UNREF(offset); /* silence scan-build warning */ } else { /* * Complex atom @@ -89994,8 +91338,8 @@ duk_uint32_t tmp_qmin, tmp_qmax; /* pre-check how many atom copies we're willing to make (atom_copies not needed below) */ - atom_copies = (re_ctx->curr_token.qmax == DUK_RE_QUANTIFIER_INFINITE) ? - re_ctx->curr_token.qmin : re_ctx->curr_token.qmax; + atom_copies = (re_ctx->curr_token.qmax == DUK_RE_QUANTIFIER_INFINITE) ? re_ctx->curr_token.qmin : + re_ctx->curr_token.qmax; if (atom_copies > DUK_RE_MAX_ATOM_COPIES) { DUK_ERROR_RANGE(re_ctx->thr, DUK_STR_QUANTIFIER_TOO_MANY_COPIES); DUK_WO_NORETURN(return;); @@ -90006,15 +91350,19 @@ if (atom_start_captures != re_ctx->captures) { DUK_ASSERT(atom_start_captures < re_ctx->captures); DUK_DDD(DUK_DDDPRINT("must wipe atom_start_captures,re_ctx->captures: %ld,%ld", - (long) atom_start_captures, (long) re_ctx->captures)); + (long) atom_start_captures, + (long) re_ctx->captures)); /* insert (DUK_REOP_WIPERANGE, start, count) in reverse order so the order ends up right */ - duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, (re_ctx->captures - atom_start_captures) * 2U); + duk__insert_u32(re_ctx, + (duk_uint32_t) atom_start_offset, + (re_ctx->captures - atom_start_captures) * 2U); duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, (atom_start_captures + 1) * 2); duk__insert_u32(re_ctx, (duk_uint32_t) atom_start_offset, DUK_REOP_WIPERANGE); } else { - DUK_DDD(DUK_DDDPRINT("no need to wipe captures: atom_start_captures == re_ctx->captures == %ld", - (long) atom_start_captures)); + DUK_DDD( + DUK_DDDPRINT("no need to wipe captures: atom_start_captures == re_ctx->captures == %ld", + (long) atom_start_captures)); } atom_code_length = (duk_int32_t) DUK__RE_BUFLEN(re_ctx) - atom_start_offset; @@ -90023,7 +91371,9 @@ tmp_qmin = re_ctx->curr_token.qmin; tmp_qmax = re_ctx->curr_token.qmax; while (tmp_qmin > 0) { - duk__append_slice(re_ctx, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__append_slice(re_ctx, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); tmp_qmin--; if (tmp_qmax != DUK_RE_QUANTIFIER_INFINITE) { tmp_qmax--; @@ -90041,14 +91391,16 @@ */ duk__append_reop(re_ctx, DUK_REOP_JUMP); duk__append_jump_offset(re_ctx, atom_code_length); - duk__append_slice(re_ctx, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__append_slice(re_ctx, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); } if (re_ctx->curr_token.greedy) { - duk__append_reop(re_ctx, DUK_REOP_SPLIT2); /* prefer jump */ + duk__append_reop(re_ctx, DUK_REOP_SPLIT2); /* prefer jump */ } else { - duk__append_reop(re_ctx, DUK_REOP_SPLIT1); /* prefer direct */ + duk__append_reop(re_ctx, DUK_REOP_SPLIT1); /* prefer direct */ } - duk__append_jump_offset(re_ctx, -atom_code_length - 1); /* -1 for opcode */ + duk__append_jump_offset(re_ctx, -atom_code_length - 1); /* -1 for opcode */ } else { /* * The remaining matches are emitted as sequence of SPLITs and atom @@ -90068,14 +91420,17 @@ */ duk_uint32_t offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); while (tmp_qmax > 0) { - duk__insert_slice(re_ctx, offset, (duk_uint32_t) atom_start_offset, (duk_uint32_t) atom_code_length); + duk__insert_slice(re_ctx, + offset, + (duk_uint32_t) atom_start_offset, + (duk_uint32_t) atom_code_length); if (re_ctx->curr_token.greedy) { - duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT1); /* prefer direct */ + duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT1); /* prefer direct */ } else { - duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT2); /* prefer jump */ + duk__insert_u32(re_ctx, offset, DUK_REOP_SPLIT2); /* prefer jump */ } duk__insert_jump_offset(re_ctx, - offset + 1, /* +1 for opcode */ + offset + 1, /* +1 for opcode */ (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (offset + 1))); tmp_qmax--; } @@ -90108,8 +91463,8 @@ case DUK_RETOK_ASSERT_START_POS_LOOKAHEAD: case DUK_RETOK_ASSERT_START_NEG_LOOKAHEAD: { duk_uint32_t offset; - duk_uint32_t opcode = (re_ctx->curr_token.t == DUK_RETOK_ASSERT_START_POS_LOOKAHEAD) ? - DUK_REOP_LOOKPOS : DUK_REOP_LOOKNEG; + duk_uint32_t opcode = + (re_ctx->curr_token.t == DUK_RETOK_ASSERT_START_POS_LOOKAHEAD) ? DUK_REOP_LOOKPOS : DUK_REOP_LOOKNEG; offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); duk__parse_disjunction(re_ctx, 0, &tmp_disj); @@ -90117,7 +91472,7 @@ (void) duk__insert_u32(re_ctx, offset, opcode); (void) duk__insert_jump_offset(re_ctx, - offset + 1, /* +1 for opcode */ + offset + 1, /* +1 for opcode */ (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - (offset + 1))); /* 'taint' result as complex -- this is conservative, @@ -90178,7 +91533,7 @@ DUK_ASSERT(DUK_RETOK_ATOM_WHITE == DUK_RETOK_ATOM_DIGIT + 2); DUK_ASSERT(DUK_RETOK_ATOM_WORD_CHAR == DUK_RETOK_ATOM_DIGIT + 4); idx = (duk_small_uint_t) ((re_ctx->curr_token.t - DUK_RETOK_ATOM_DIGIT) >> 1U); - DUK_ASSERT(idx <= 2U); /* Assume continuous token numbers; also checks negative underflow. */ + DUK_ASSERT(idx <= 2U); /* Assume continuous token numbers; also checks negative underflow. */ duk__append_range_atom_matcher(re_ctx, re_op, duk__re_range_lookup1idx, duk__re_range_lookup2idx); break; @@ -90188,7 +91543,7 @@ if (backref > re_ctx->highest_backref) { re_ctx->highest_backref = backref; } - new_atom_char_length = -1; /* mark as complex */ + new_atom_char_length = -1; /* mark as complex */ new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); duk__append_reop(re_ctx, DUK_REOP_BACKREFERENCE); duk__append_u32(re_ctx, backref); @@ -90197,12 +91552,14 @@ case DUK_RETOK_ATOM_START_CAPTURE_GROUP: { duk_uint32_t cap; - new_atom_char_length = -1; /* mark as complex (capture handling) */ + new_atom_char_length = -1; /* mark as complex (capture handling) */ new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); cap = ++re_ctx->captures; duk__append_reop(re_ctx, DUK_REOP_SAVE); duk__append_u32(re_ctx, cap * 2); - duk__parse_disjunction(re_ctx, 0, &tmp_disj); /* retval (sub-atom char length) unused, tainted as complex above */ + duk__parse_disjunction(re_ctx, + 0, + &tmp_disj); /* retval (sub-atom char length) unused, tainted as complex above */ duk__append_reop(re_ctx, DUK_REOP_SAVE); duk__append_u32(re_ctx, cap * 2 + 1); break; @@ -90247,12 +91604,12 @@ new_atom_char_length = 1; new_atom_start_offset = (duk_int32_t) DUK__RE_BUFLEN(re_ctx); duk__append_reop(re_ctx, - (re_ctx->curr_token.t == DUK_RETOK_ATOM_START_CHARCLASS) ? - DUK_REOP_RANGES : DUK_REOP_INVRANGES); - offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); /* patch in range count later */ + (re_ctx->curr_token.t == DUK_RETOK_ATOM_START_CHARCLASS) ? DUK_REOP_RANGES : + DUK_REOP_INVRANGES); + offset = (duk_uint32_t) DUK__RE_BUFLEN(re_ctx); /* patch in range count later */ /* parse ranges until character class ends */ - re_ctx->nranges = 0; /* note: ctx-wide temporary */ + re_ctx->nranges = 0; /* note: ctx-wide temporary */ duk_lexer_parse_re_ranges(&re_ctx->lex, duk__regexp_generate_ranges, (void *) re_ctx); /* insert range count */ @@ -90295,7 +91652,7 @@ atom_start_captures = new_atom_start_captures; } - done: +done: /* finish up pending jump and split for last alternative */ if (unpatched_disjunction_jump >= 0) { @@ -90303,9 +91660,7 @@ DUK_ASSERT(unpatched_disjunction_split >= 0); offset = (duk_uint32_t) unpatched_disjunction_jump; - offset += duk__insert_jump_offset(re_ctx, - offset, - (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); + offset += duk__insert_jump_offset(re_ctx, offset, (duk_int32_t) (DUK__RE_BUFLEN(re_ctx) - offset)); /* offset is now target of the pending split (right after jump) */ duk__insert_jump_offset(re_ctx, (duk_uint32_t) unpatched_disjunction_split, @@ -90316,8 +91671,7 @@ out_atom_info->end_captures = re_ctx->captures; #endif out_atom_info->charlen = res_charlen; - DUK_DDD(DUK_DDDPRINT("parse disjunction finished: charlen=%ld", - (long) out_atom_info->charlen)); + DUK_DDD(DUK_DDDPRINT("parse disjunction finished: charlen=%ld", (long) out_atom_info->charlen)); re_ctx->recursion_depth--; } @@ -90368,7 +91722,7 @@ return flags; - flags_error: +flags_error: DUK_ERROR_SYNTAX(thr, DUK_STR_INVALID_REGEXP_FLAGS); DUK_WO_NORETURN(return 0U;); } @@ -90434,7 +91788,7 @@ } DUK_BW_SETPTR_AND_COMPACT(thr, bw, q); - (void) duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ + (void) duk_buffer_to_string(thr, -1); /* Safe if input is safe. */ /* ... escaped_source */ } @@ -90488,7 +91842,7 @@ /* ... pattern flags escaped_source buffer */ duk_memzero(&re_ctx, sizeof(re_ctx)); - DUK_LEXER_INITCTX(&re_ctx.lex); /* duplicate zeroing, expect for (possible) NULL inits */ + DUK_LEXER_INITCTX(&re_ctx.lex); /* duplicate zeroing, expect for (possible) NULL inits */ re_ctx.thr = thr; re_ctx.lex.thr = thr; re_ctx.lex.input = DUK_HSTRING_GET_DATA(h_pattern); @@ -90500,13 +91854,14 @@ DUK_BW_INIT_PUSHBUF(thr, &re_ctx.bw, DUK__RE_INITIAL_BUFSIZE); DUK_DD(DUK_DDPRINT("regexp compiler ctx initialized, flags=0x%08lx, recursion_limit=%ld", - (unsigned long) re_ctx.re_flags, (long) re_ctx.recursion_limit)); + (unsigned long) re_ctx.re_flags, + (long) re_ctx.recursion_limit)); /* * Init lexer */ - lex_point.offset = 0; /* expensive init, just want to fill window */ + lex_point.offset = 0; /* expensive init, just want to fill window */ lex_point.line = 1; DUK_LEXER_SETPOINT(&re_ctx.lex, &lex_point); @@ -90548,7 +91903,7 @@ /* ... pattern flags escaped_source buffer */ DUK_BW_COMPACT(thr, &re_ctx.bw); - (void) duk_buffer_to_string(thr, -1); /* Safe because flags is at most 7 bit. */ + (void) duk_buffer_to_string(thr, -1); /* Safe because flags is at most 7 bit. */ /* ... pattern flags escaped_source bytecode */ @@ -90556,11 +91911,12 @@ * Finalize stack */ - duk_remove(thr, -4); /* -> ... flags escaped_source bytecode */ - duk_remove(thr, -3); /* -> ... escaped_source bytecode */ + duk_remove(thr, -4); /* -> ... flags escaped_source bytecode */ + duk_remove(thr, -3); /* -> ... escaped_source bytecode */ DUK_DD(DUK_DDPRINT("regexp compilation successful, bytecode: %!T, escaped source: %!T", - (duk_tval *) duk_get_tval(thr, -1), (duk_tval *) duk_get_tval(thr, -2))); + (duk_tval *) duk_get_tval(thr, -1), + (duk_tval *) duk_get_tval(thr, -2))); } /* @@ -90606,11 +91962,11 @@ /* ... regexp_object */ } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ /* regexp support disabled */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ /* automatic undefs */ #undef DUK__RE_BUFLEN @@ -90659,7 +92015,11 @@ } } -DUK_LOCAL const duk_uint8_t *duk__utf8_backtrack(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_uint_fast32_t count) { +DUK_LOCAL const duk_uint8_t *duk__utf8_backtrack(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_uint_fast32_t count) { const duk_uint8_t *p; /* Note: allow backtracking from p == ptr_end */ @@ -90684,12 +92044,16 @@ *ptr = p; return p; - fail: +fail: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return NULL;); } -DUK_LOCAL const duk_uint8_t *duk__utf8_advance(duk_hthread *thr, const duk_uint8_t **ptr, const duk_uint8_t *ptr_start, const duk_uint8_t *ptr_end, duk_uint_fast32_t count) { +DUK_LOCAL const duk_uint8_t *duk__utf8_advance(duk_hthread *thr, + const duk_uint8_t **ptr, + const duk_uint8_t *ptr_start, + const duk_uint8_t *ptr_end, + duk_uint_fast32_t count) { const duk_uint8_t *p; p = *ptr; @@ -90715,7 +92079,7 @@ *ptr = p; return p; - fail: +fail: DUK_ERROR_INTERNAL(thr); DUK_WO_NORETURN(return NULL;); } @@ -90819,7 +92183,7 @@ c1 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); DUK_ASSERT(!(re_ctx->re_flags & DUK_RE_FLAG_IGNORE_CASE) || - c1 == duk_unicode_re_canonicalize_char(re_ctx->thr, c1)); /* canonicalized by compiler */ + c1 == duk_unicode_re_canonicalize_char(re_ctx->thr, c1)); /* canonicalized by compiler */ c2 = duk__inp_get_cp(re_ctx, &sp); /* No need to check for c2 < 0 (end of input): because c1 >= 0, it * will fail the match below automatically and cause goto fail. @@ -90865,7 +92229,10 @@ r1 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); r2 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("matching ranges/invranges, n=%ld, r1=%ld, r2=%ld, c=%ld", - (long) n, (long) r1, (long) r2, (long) c)); + (long) n, + (long) r1, + (long) r2, + (long) c)); if (c >= r1 && c <= r2) { /* Note: don't bail out early, we must read all the ranges from * bytecode. Another option is to skip them efficiently after @@ -90934,16 +92301,16 @@ duk_small_int_t w1, w2; if (sp <= re_ctx->input) { - w1 = 0; /* not a wordchar */ + w1 = 0; /* not a wordchar */ } else { duk_codepoint_t c; c = duk__inp_get_prev_cp(re_ctx, sp); w1 = duk_unicode_re_is_wordchar(c); } if (sp >= re_ctx->input_end) { - w2 = 0; /* not a wordchar */ + w2 = 0; /* not a wordchar */ } else { - const duk_uint8_t *tmp_sp = sp; /* dummy so sp won't get updated */ + const duk_uint8_t *tmp_sp = sp; /* dummy so sp won't get updated */ duk_codepoint_t c; c = duk__inp_get_cp(re_ctx, &tmp_sp); w2 = duk_unicode_re_is_wordchar(c); @@ -91004,7 +92371,9 @@ qmax = duk__bc_get_u32(re_ctx, &pc); skip = duk__bc_get_i32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("minimal quantifier, qmin=%lu, qmax=%lu, skip=%ld", - (unsigned long) qmin, (unsigned long) qmax, (long) skip)); + (unsigned long) qmin, + (unsigned long) qmax, + (long) skip)); q = 0; while (q <= qmax) { @@ -91034,7 +92403,10 @@ atomlen = duk__bc_get_u32(re_ctx, &pc); skip = duk__bc_get_i32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("greedy quantifier, qmin=%lu, qmax=%lu, atomlen=%lu, skip=%ld", - (unsigned long) qmin, (unsigned long) qmax, (unsigned long) atomlen, (long) skip)); + (unsigned long) qmin, + (unsigned long) qmax, + (unsigned long) atomlen, + (long) skip)); q = 0; while (q < qmax) { @@ -91060,8 +92432,7 @@ * do not allow captures in their atom now, so this is not an issue. */ - DUK_DDD(DUK_DDDPRINT("greedy quantifier, backtrack %ld characters (atomlen)", - (long) atomlen)); + DUK_DDD(DUK_DDDPRINT("greedy quantifier, backtrack %ld characters (atomlen)", (long) atomlen)); sp = duk__inp_backtrack(re_ctx, &sp, (duk_uint_fast32_t) atomlen); q--; } @@ -91107,20 +92478,23 @@ idx_start = duk__bc_get_u32(re_ctx, &pc); idx_count = duk__bc_get_u32(re_ctx, &pc); DUK_DDD(DUK_DDDPRINT("wipe saved range: start=%ld, count=%ld -> %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) idx_count, - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) idx_count, + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); if (idx_start + idx_count > re_ctx->nsaved || idx_count == 0) { /* idx is unsigned, < 0 check is not necessary */ DUK_D(DUK_DPRINT("internal error, regexp wipe indices insane: idx_start=%ld, idx_count=%ld", - (long) idx_start, (long) idx_count)); + (long) idx_start, + (long) idx_count)); goto internal_error; } DUK_ASSERT(idx_count > 0); duk_require_stack(re_ctx->thr, 1); - range_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, - sizeof(duk_uint8_t *) * idx_count); + range_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, sizeof(duk_uint8_t *) * idx_count); DUK_ASSERT(range_save != NULL); duk_memcpy(range_save, re_ctx->saved + idx_start, sizeof(duk_uint8_t *) * idx_count); #if defined(DUK_USE_EXPLICIT_NULL_INIT) @@ -91136,8 +92510,10 @@ if (sub_sp) { /* match: keep wiped/resaved values */ DUK_DDD(DUK_DDDPRINT("match: keep wiped/resaved values %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); duk_pop_unsafe(re_ctx->thr); sp = sub_sp; goto match; @@ -91145,8 +92521,10 @@ /* fail: restore saves */ DUK_DDD(DUK_DDDPRINT("fail: restore wiped/resaved values %ld,%ld (captures %ld,%ld)", - (long) idx_start, (long) (idx_start + idx_count - 1), - (long) (idx_start / 2), (long) ((idx_start + idx_count - 1) / 2))); + (long) idx_start, + (long) (idx_start + idx_count - 1), + (long) (idx_start / 2), + (long) ((idx_start + idx_count - 1) / 2))); duk_memcpy((void *) (re_ctx->saved + idx_start), (const void *) range_save, sizeof(duk_uint8_t *) * idx_count); @@ -91176,8 +92554,8 @@ DUK_ASSERT(re_ctx->nsaved > 0); duk_require_stack(re_ctx->thr, 1); - full_save = (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, - sizeof(duk_uint8_t *) * re_ctx->nsaved); + full_save = + (duk_uint8_t **) duk_push_fixed_buffer_nozero(re_ctx->thr, sizeof(duk_uint8_t *) * re_ctx->nsaved); DUK_ASSERT(full_save != NULL); duk_memcpy(full_save, re_ctx->saved, sizeof(duk_uint8_t *) * re_ctx->nsaved); @@ -91202,11 +92580,9 @@ /* fall through */ - lookahead_fail: + lookahead_fail: /* fail: restore saves */ - duk_memcpy((void *) re_ctx->saved, - (const void *) full_save, - sizeof(duk_uint8_t *) * re_ctx->nsaved); + duk_memcpy((void *) re_ctx->saved, (const void *) full_save, sizeof(duk_uint8_t *) * re_ctx->nsaved); duk_pop_unsafe(re_ctx->thr); goto fail; } @@ -91229,22 +92605,23 @@ const duk_uint8_t *p; idx = duk__bc_get_u32(re_ctx, &pc); - idx = idx << 1; /* backref n -> saved indices n*2, n*2+1 */ + idx = idx << 1; /* backref n -> saved indices n*2, n*2+1 */ if (idx < 2 || idx + 1 >= re_ctx->nsaved) { /* regexp compiler should catch these */ DUK_D(DUK_DPRINT("internal error, backreference index insane")); goto internal_error; } - if (!re_ctx->savedidx || !re_ctx->savedidx+1) { + if (!re_ctx->savedidx || !re_ctx->savedidx + 1) { /* capture is 'undefined', always matches! */ DUK_DDD(DUK_DDDPRINT("backreference: saved%ld,%ld not complete, always match", - (long) idx, (long) (idx + 1))); + (long) idx, + (long) (idx + 1))); break; } DUK_DDD(DUK_DDDPRINT("backreference: match saved%ld,%ld", (long) idx, (long) (idx + 1))); p = re_ctx->savedidx; - while (p < re_ctx->savedidx+1) { + while (p < re_ctx->savedidx + 1) { duk_codepoint_t c1, c2; /* Note: not necessary to check p against re_ctx->input_end: @@ -91276,15 +92653,15 @@ } } - match: +match: re_ctx->recursion_depth--; return sp; - fail: +fail: re_ctx->recursion_depth--; return NULL; - internal_error: +internal_error: DUK_ERROR_INTERNAL(re_ctx->thr); DUK_WO_NORETURN(return NULL;); } @@ -91336,8 +92713,9 @@ h_input = duk_to_hstring(thr, -1); DUK_ASSERT(h_input != NULL); - duk_xget_owndataprop_stridx_short(thr, -2, DUK_STRIDX_INT_BYTECODE); /* ... re_obj input -> ... re_obj input bc */ - h_bytecode = duk_require_hstring(thr, -1); /* no regexp instance should exist without a non-configurable bytecode property */ + duk_xget_owndataprop_stridx_short(thr, -2, DUK_STRIDX_INT_BYTECODE); /* ... re_obj input -> ... re_obj input bc */ + h_bytecode = + duk_require_hstring(thr, -1); /* no regexp instance should exist without a non-configurable bytecode property */ DUK_ASSERT(h_bytecode != NULL); /* @@ -91369,13 +92747,13 @@ re_ctx.nsaved = duk__bc_get_u32(&re_ctx, &pc); re_ctx.bytecode = pc; - DUK_ASSERT(DUK_RE_FLAG_GLOBAL < 0x10000UL); /* must fit into duk_small_int_t */ + DUK_ASSERT(DUK_RE_FLAG_GLOBAL < 0x10000UL); /* must fit into duk_small_int_t */ global = (duk_small_int_t) (force_global | (duk_small_int_t) (re_ctx.re_flags & DUK_RE_FLAG_GLOBAL)); DUK_ASSERT(re_ctx.nsaved >= 2); DUK_ASSERT((re_ctx.nsaved % 2) == 0); - p_buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, sizeof(duk_uint8_t *) * re_ctx.nsaved); /* rely on zeroing */ + p_buf = (duk_uint8_t *) duk_push_fixed_buffer(thr, sizeof(duk_uint8_t *) * re_ctx.nsaved); /* rely on zeroing */ DUK_UNREF(p_buf); re_ctx.saved = (const duk_uint8_t **) duk_get_buffer(thr, -1, NULL); DUK_ASSERT(re_ctx.saved != NULL); @@ -91393,7 +92771,9 @@ #endif DUK_DDD(DUK_DDDPRINT("regexp ctx initialized, flags=0x%08lx, nsaved=%ld, recursion_limit=%ld, steps_limit=%ld", - (unsigned long) re_ctx.re_flags, (long) re_ctx.nsaved, (long) re_ctx.recursion_limit, + (unsigned long) re_ctx.re_flags, + (long) re_ctx.nsaved, + (long) re_ctx.recursion_limit, (long) re_ctx.steps_limit)); /* @@ -91415,15 +92795,15 @@ /* ... re_obj input bc saved_buf */ - duk_get_prop_stridx_short(thr, -4, DUK_STRIDX_LAST_INDEX); /* -> ... re_obj input bc saved_buf lastIndex */ - (void) duk_to_int(thr, -1); /* ToInteger(lastIndex) */ - d = duk_get_number(thr, -1); /* integer, but may be +/- Infinite, +/- zero (not NaN, though) */ + duk_get_prop_stridx_short(thr, -4, DUK_STRIDX_LAST_INDEX); /* -> ... re_obj input bc saved_buf lastIndex */ + (void) duk_to_int(thr, -1); /* ToInteger(lastIndex) */ + d = duk_get_number(thr, -1); /* integer, but may be +/- Infinite, +/- zero (not NaN, though) */ duk_pop_nodecref_unsafe(thr); if (global) { if (d < 0.0 || d > (double) DUK_HSTRING_GET_CHARLEN(h_input)) { /* match fail */ - char_offset = 0; /* not really necessary */ + char_offset = 0; /* not really necessary */ DUK_ASSERT(match == 0); goto match_over; } @@ -91459,8 +92839,10 @@ DUK_ASSERT(re_ctx.recursion_depth == 0); DUK_DDD(DUK_DDDPRINT("attempt match at char offset %ld; %p %p,%p", - (long) char_offset, (const void *) sp, - (const void *) re_ctx.input, (const void *) re_ctx.input_end)); + (long) char_offset, + (const void *) sp, + (const void *) re_ctx.input, + (const void *) re_ctx.input_end)); /* * Note: @@ -91507,7 +92889,7 @@ (void) duk__utf8_advance(thr, &sp, re_ctx.input, re_ctx.input_end, (duk_uint_fast32_t) 1); } - match_over: +match_over: /* * Matching complete, create result array or return a 'null'. Update lastIndex @@ -91533,8 +92915,8 @@ DUK_DDD(DUK_DDDPRINT("regexp matches at char_offset %ld", (long) char_offset)); - DUK_ASSERT(re_ctx.nsaved >= 2); /* must have start and end */ - DUK_ASSERT((re_ctx.nsaved % 2) == 0); /* and even number */ + DUK_ASSERT(re_ctx.nsaved >= 2); /* must have start and end */ + DUK_ASSERT((re_ctx.nsaved % 2) == 0); /* and even number */ /* XXX: Array size is known before and (2 * re_ctx.nsaved) but not taken * advantage of now. The array is not compacted either, as regexp match @@ -91575,7 +92957,7 @@ * will be zero). Also assumes clen reflects the * correct char length. */ - char_end_offset = char_offset + (duk_uint32_t) duk_get_length(thr, -1); /* add charlen */ + char_end_offset = char_offset + (duk_uint32_t) duk_get_length(thr, -1); /* add charlen */ } } else { duk_push_undefined(thr); @@ -91640,11 +93022,11 @@ duk__regexp_match_helper(thr, 1 /*force_global*/); } -#else /* DUK_USE_REGEXP_SUPPORT */ +#else /* DUK_USE_REGEXP_SUPPORT */ /* regexp support disabled */ -#endif /* DUK_USE_REGEXP_SUPPORT */ +#endif /* DUK_USE_REGEXP_SUPPORT */ #line 1 "duk_selftest.c" /* * Self tests to ensure execution environment is sane. Intended to catch @@ -91665,18 +93047,21 @@ } duk__test_double_union; /* Self test failed. Expects a local variable 'error_count' to exist. */ -#define DUK__FAILED(msg) do { \ +#define DUK__FAILED(msg) \ + do { \ DUK_D(DUK_DPRINT("self test failed: " #msg " at " DUK_FILE_MACRO ":" DUK_MACRO_STRINGIFY(DUK_LINE_MACRO))); \ error_count++; \ } while (0) -#define DUK__DBLUNION_CMP_TRUE(a,b) do { \ +#define DUK__DBLUNION_CMP_TRUE(a, b) \ + do { \ if (duk_memcmp((const void *) (a), (const void *) (b), sizeof(duk__test_double_union)) != 0) { \ DUK__FAILED("double union compares false (expected true)"); \ } \ } while (0) -#define DUK__DBLUNION_CMP_FALSE(a,b) do { \ +#define DUK__DBLUNION_CMP_FALSE(a, b) \ + do { \ if (duk_memcmp((const void *) (a), (const void *) (b), sizeof(duk__test_double_union)) == 0) { \ DUK__FAILED("double union compares true (expected false)"); \ } \ @@ -91688,43 +93073,72 @@ } duk__test_u32_union; #if defined(DUK_USE_INTEGER_LE) -#define DUK__U32_INIT(u, a, b, c, d) do { \ - (u)->x0 = (d); (u)->x1 = (c); (u)->x2 = (b); (u)->x3 = (a); \ +#define DUK__U32_INIT(u, a, b, c, d) \ + do { \ + (u)->x0 = (d); \ + (u)->x1 = (c); \ + (u)->x2 = (b); \ + (u)->x3 = (a); \ } while (0) #elif defined(DUK_USE_INTEGER_ME) #error integer mixed endian not supported now #elif defined(DUK_USE_INTEGER_BE) -#define DUK__U32_INIT(u, a, b, c, d) do { \ - (u)->x0 = (a); (u)->x1 = (b); (u)->x2 = (c); (u)->x3 = (d); \ +#define DUK__U32_INIT(u, a, b, c, d) \ + do { \ + (u)->x0 = (a); \ + (u)->x1 = (b); \ + (u)->x2 = (c); \ + (u)->x3 = (d); \ } while (0) #else #error unknown integer endianness #endif #if defined(DUK_USE_DOUBLE_LE) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (h); (u)->x1 = (g); (u)->x2 = (f); (u)->x3 = (e); \ - (u)->x4 = (d); (u)->x5 = (c); (u)->x6 = (b); (u)->x7 = (a); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (h); \ + (u)->x1 = (g); \ + (u)->x2 = (f); \ + (u)->x3 = (e); \ + (u)->x4 = (d); \ + (u)->x5 = (c); \ + (u)->x6 = (b); \ + (u)->x7 = (a); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (h) && (u)->x1 == (g) && (u)->x2 == (f) && (u)->x3 == (e) && \ - (u)->x4 == (d) && (u)->x5 == (c) && (u)->x6 == (b) && (u)->x7 == (a)) + ((u)->x0 == (h) && (u)->x1 == (g) && (u)->x2 == (f) && (u)->x3 == (e) && (u)->x4 == (d) && (u)->x5 == (c) && \ + (u)->x6 == (b) && (u)->x7 == (a)) #elif defined(DUK_USE_DOUBLE_ME) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (d); (u)->x1 = (c); (u)->x2 = (b); (u)->x3 = (a); \ - (u)->x4 = (h); (u)->x5 = (g); (u)->x6 = (f); (u)->x7 = (e); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (d); \ + (u)->x1 = (c); \ + (u)->x2 = (b); \ + (u)->x3 = (a); \ + (u)->x4 = (h); \ + (u)->x5 = (g); \ + (u)->x6 = (f); \ + (u)->x7 = (e); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (d) && (u)->x1 == (c) && (u)->x2 == (b) && (u)->x3 == (a) && \ - (u)->x4 == (h) && (u)->x5 == (g) && (u)->x6 == (f) && (u)->x7 == (e)) + ((u)->x0 == (d) && (u)->x1 == (c) && (u)->x2 == (b) && (u)->x3 == (a) && (u)->x4 == (h) && (u)->x5 == (g) && \ + (u)->x6 == (f) && (u)->x7 == (e)) #elif defined(DUK_USE_DOUBLE_BE) -#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) do { \ - (u)->x0 = (a); (u)->x1 = (b); (u)->x2 = (c); (u)->x3 = (d); \ - (u)->x4 = (e); (u)->x5 = (f); (u)->x6 = (g); (u)->x7 = (h); \ +#define DUK__DOUBLE_INIT(u, a, b, c, d, e, f, g, h) \ + do { \ + (u)->x0 = (a); \ + (u)->x1 = (b); \ + (u)->x2 = (c); \ + (u)->x3 = (d); \ + (u)->x4 = (e); \ + (u)->x5 = (f); \ + (u)->x6 = (g); \ + (u)->x7 = (h); \ } while (0) #define DUK__DOUBLE_COMPARE(u, a, b, c, d, e, f, g, h) \ - ((u)->x0 == (a) && (u)->x1 == (b) && (u)->x2 == (c) && (u)->x3 == (d) && \ - (u)->x4 == (e) && (u)->x5 == (f) && (u)->x6 == (g) && (u)->x7 == (h)) + ((u)->x0 == (a) && (u)->x1 == (b) && (u)->x2 == (c) && (u)->x3 == (d) && (u)->x4 == (e) && (u)->x5 == (f) && \ + (u)->x6 == (g) && (u)->x7 == (h)) #else #error unknown double endianness #endif @@ -91736,17 +93150,12 @@ DUK_LOCAL duk_uint_t duk__selftest_types(void) { duk_uint_t error_count = 0; - if (!(sizeof(duk_int8_t) == 1 && - sizeof(duk_uint8_t) == 1 && - sizeof(duk_int16_t) == 2 && - sizeof(duk_uint16_t) == 2 && - sizeof(duk_int32_t) == 4 && - sizeof(duk_uint32_t) == 4)) { + if (!(sizeof(duk_int8_t) == 1 && sizeof(duk_uint8_t) == 1 && sizeof(duk_int16_t) == 2 && sizeof(duk_uint16_t) == 2 && + sizeof(duk_int32_t) == 4 && sizeof(duk_uint32_t) == 4)) { DUK__FAILED("duk_(u)int{8,16,32}_t size"); } #if defined(DUK_USE_64BIT_OPS) - if (!(sizeof(duk_int64_t) == 8 && - sizeof(duk_uint64_t) == 8)) { + if (!(sizeof(duk_int64_t) == 8 && sizeof(duk_uint64_t) == 8)) { DUK__FAILED("duk_(u)int64_t size"); } #endif @@ -91898,8 +93307,14 @@ * (2.008366013071895,) */ - du.uc0 = 0x40; du.uc1 = 0x00; du.uc2 = 0x11; du.uc3 = 0x22; - du.uc4 = 0x33; du.uc5 = 0x44; du.uc6 = 0x55; du.uc7 = 0x66; + du.uc0 = 0x40; + du.uc1 = 0x00; + du.uc2 = 0x11; + du.uc3 = 0x22; + du.uc4 = 0x33; + du.uc5 = 0x44; + du.uc6 = 0x55; + du.uc7 = 0x66; DUK_DBLUNION_DOUBLE_NTOH(&du); du_diff = du.d - 2.008366013071895; #if 0 @@ -91954,20 +93369,38 @@ */ /* little endian */ - a.x0 = 0x11; a.x1 = 0x22; a.x2 = 0x33; a.x3 = 0x44; - a.x4 = 0x00; a.x5 = 0x00; a.x6 = 0xf1; a.x7 = 0xff; + a.x0 = 0x11; + a.x1 = 0x22; + a.x2 = 0x33; + a.x3 = 0x44; + a.x4 = 0x00; + a.x5 = 0x00; + a.x6 = 0xf1; + a.x7 = 0xff; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); /* big endian */ - a.x0 = 0xff; a.x1 = 0xf1; a.x2 = 0x00; a.x3 = 0x00; - a.x4 = 0x44; a.x5 = 0x33; a.x6 = 0x22; a.x7 = 0x11; + a.x0 = 0xff; + a.x1 = 0xf1; + a.x2 = 0x00; + a.x3 = 0x00; + a.x4 = 0x44; + a.x5 = 0x33; + a.x6 = 0x22; + a.x7 = 0x11; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); /* mixed endian */ - a.x0 = 0x00; a.x1 = 0x00; a.x2 = 0xf1; a.x3 = 0xff; - a.x4 = 0x11; a.x5 = 0x22; a.x6 = 0x33; a.x7 = 0x44; + a.x0 = 0x00; + a.x1 = 0x00; + a.x2 = 0xf1; + a.x3 = 0xff; + a.x4 = 0x11; + a.x5 = 0x22; + a.x6 = 0x33; + a.x7 = 0x44; b = a; DUK__DBLUNION_CMP_TRUE(&a, &b); @@ -92032,10 +93465,14 @@ c.d = a.d + b.d; if (!DUK__DOUBLE_COMPARE(&c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)) { DUK_D(DUK_DPRINT("broken result (native endiannesss): %02x %02x %02x %02x %02x %02x %02x %02x", - (unsigned int) c.x0, (unsigned int) c.x1, - (unsigned int) c.x2, (unsigned int) c.x3, - (unsigned int) c.x4, (unsigned int) c.x5, - (unsigned int) c.x6, (unsigned int) c.x7)); + (unsigned int) c.x0, + (unsigned int) c.x1, + (unsigned int) c.x2, + (unsigned int) c.x3, + (unsigned int) c.x4, + (unsigned int) c.x5, + (unsigned int) c.x6, + (unsigned int) c.x7)); DUK__FAILED("invalid result from 1.0 + 0.5ulp"); } @@ -92052,10 +93489,14 @@ c.d = a.d + b.d; if (!DUK__DOUBLE_COMPARE(&c, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02)) { DUK_D(DUK_DPRINT("broken result (native endiannesss): %02x %02x %02x %02x %02x %02x %02x %02x", - (unsigned int) c.x0, (unsigned int) c.x1, - (unsigned int) c.x2, (unsigned int) c.x3, - (unsigned int) c.x4, (unsigned int) c.x5, - (unsigned int) c.x6, (unsigned int) c.x7)); + (unsigned int) c.x0, + (unsigned int) c.x1, + (unsigned int) c.x2, + (unsigned int) c.x3, + (unsigned int) c.x4, + (unsigned int) c.x5, + (unsigned int) c.x6, + (unsigned int) c.x7)); DUK__FAILED("invalid result from (1.0 + ulp) + 0.5ulp"); } @@ -92226,7 +93667,7 @@ duk_double_t dv; duk_uint32_t uv; - dv = 3735928559.0; /* 0xdeadbeef in decimal */ + dv = 3735928559.0; /* 0xdeadbeef in decimal */ uv = (duk_uint32_t) dv; if (uv != 0xdeadbeefUL) { @@ -92263,7 +93704,7 @@ ptr = alloc_func(udata, (duk_size_t) i); if (ptr == NULL) { DUK_D(DUK_DPRINT("alloc failed, ignore")); - continue; /* alloc failed, ignore */ + continue; /* alloc failed, ignore */ } for (j = 0; j < i; j++) { ((unsigned char *) ptr)j = (unsigned char) (0x80 + j); @@ -92272,14 +93713,15 @@ if (new_ptr == NULL) { DUK_D(DUK_DPRINT("realloc failed, ignore")); free_func(udata, ptr); - continue; /* realloc failed, ignore */ + continue; /* realloc failed, ignore */ } ptr = new_ptr; for (j = 0; j < i; j++) { x = ((unsigned char *) ptr)j; if (x != (unsigned char) (0x80 + j)) { DUK_D(DUK_DPRINT("byte at index %ld doesn't match after realloc: %02lx", - (long) j, (unsigned long) x)); + (long) j, + (unsigned long) x)); DUK__FAILED("byte compare after realloc"); break; } @@ -92323,7 +93765,7 @@ return error_count; } -#endif /* DUK_USE_SELF_TESTS */ +#endif /* DUK_USE_SELF_TESTS */ /* automatic undefs */ #undef DUK__DBLUNION_CMP_FALSE @@ -92367,11 +93809,11 @@ expt = (duk_small_int_t) ((i >> 52) & 0x07ff); shift = expt - 1023; - if (shift >= 0 && shift <= 46) { /* exponents 1023 to 1069 */ + if (shift >= 0 && shift <= 46) { /* exponents 1023 to 1069 */ duk_int64_t t; if (((DUK_I64_CONSTANT(0x000fffffffffffff) >> shift) & i) == 0) { - t = i | DUK_I64_CONSTANT(0x0010000000000000); /* implicit leading one */ + t = i | DUK_I64_CONSTANT(0x0010000000000000); /* implicit leading one */ t = t & DUK_I64_CONSTANT(0x001fffffffffffff); t = t >> (52 - shift); if (i < 0) { @@ -92380,13 +93822,13 @@ DUK_TVAL_SET_FASTINT(tv, t); return; } - } else if (shift == -1023) { /* exponent 0 */ + } else if (shift == -1023) { /* exponent 0 */ if (i >= 0 && (i & DUK_I64_CONSTANT(0x000fffffffffffff)) == 0) { /* Note: reject negative zero. */ DUK_TVAL_SET_FASTINT(tv, (duk_int64_t) 0); return; } - } else if (shift == 47) { /* exponent 1070 */ + } else if (shift == 47) { /* exponent 1070 */ if (i < 0 && (i & DUK_I64_CONSTANT(0x000fffffffffffff)) == 0) { DUK_TVAL_SET_FASTINT(tv, (duk_int64_t) DUK_FASTINT_MIN); return; @@ -92414,23 +93856,23 @@ if ((t >> 48) != DUK_TAG_FASTINT) { return tv->d; } else if (t & DUK_U64_CONSTANT(0x0000800000000000)) { - t = (duk_uint64_t) (-((duk_int64_t) t)); /* avoid unary minus on unsigned */ - t = t & DUK_U64_CONSTANT(0x0000ffffffffffff); /* negative */ + t = (duk_uint64_t) (-((duk_int64_t) t)); /* avoid unary minus on unsigned */ + t = t & DUK_U64_CONSTANT(0x0000ffffffffffff); /* negative */ t |= DUK_U64_CONSTANT(0xc330000000000000); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d + 4503599627370496.0; /* 1 << 52 */ + return du.d + 4503599627370496.0; /* 1 << 52 */ } else if (t != 0) { - t &= DUK_U64_CONSTANT(0x0000ffffffffffff); /* positive */ + t &= DUK_U64_CONSTANT(0x0000ffffffffffff); /* positive */ t |= DUK_U64_CONSTANT(0x4330000000000000); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d - 4503599627370496.0; /* 1 << 52 */ + return du.d - 4503599627370496.0; /* 1 << 52 */ } else { - return 0.0; /* zero */ + return 0.0; /* zero */ } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#if 0 /* unused */ +#if 0 /* unused */ #if defined(DUK_USE_FASTINT) && !defined(DUK_USE_PACKED_TVAL) DUK_INTERNAL DUK_ALWAYS_INLINE duk_double_t duk_tval_get_number_unpacked(duk_tval *tv) { duk_double_union du; @@ -92452,8 +93894,8 @@ return tv->v.d; } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#endif /* 0 */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* 0 */ #if defined(DUK_USE_FASTINT) && !defined(DUK_USE_PACKED_TVAL) DUK_INTERNAL DUK_ALWAYS_INLINE duk_double_t duk_tval_get_number_unpacked_fastint(duk_tval *tv) { @@ -92465,16 +93907,16 @@ if (tv->v.fi >= 0) { t = DUK_U64_CONSTANT(0x4330000000000000) | (duk_uint64_t) tv->v.fi; DUK_DBLUNION_SET_UINT64(&du, t); - return du.d - 4503599627370496.0; /* 1 << 52 */ + return du.d - 4503599627370496.0; /* 1 << 52 */ } else { t = DUK_U64_CONSTANT(0xc330000000000000) | (duk_uint64_t) (-tv->v.fi); DUK_DBLUNION_SET_UINT64(&du, t); - return du.d + 4503599627370496.0; /* 1 << 52 */ + return du.d + 4503599627370496.0; /* 1 << 52 */ } } -#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ +#endif /* DUK_USE_FASTINT && DUK_USE_PACKED_TVAL */ -#endif /* DUK_USE_FASTINT */ +#endif /* DUK_USE_FASTINT */ /* * Assertion helpers. @@ -98707,7 +100149,7 @@ shift = ctx->currbits - bits; mask = (((duk_uint32_t) 1U) << bits) - 1U; tmp = (ctx->currval >> shift) & mask; - ctx->currbits = shift; /* remaining */ + ctx->currbits = shift; /* remaining */ #if 0 DUK_DDD(DUK_DDDPRINT("decode_bits: %ld bits -> 0x%08lx (%ld), currbits=%ld, currval=0x%08lx", @@ -98746,17 +100188,17 @@ */ switch (duk_bd_decode(ctx, 2)) { case 0: - return 0; /* 0,0 */ + return 0; /* 0,0 */ case 1: - return duk_bd_decode(ctx, 2) + 1; /* 1,4 */ + return duk_bd_decode(ctx, 2) + 1; /* 1,4 */ case 2: - return duk_bd_decode(ctx, 5) + 5; /* 5,36 */ + return duk_bd_decode(ctx, 5) + 5; /* 5,36 */ default: t = duk_bd_decode(ctx, 7); if (t == 0) { return duk_bd_decode(ctx, 20); } - return (t - 1) + 37; /* 37,163 */ + return (t - 1) + 37; /* 37,163 */ } } @@ -98765,20 +100207,18 @@ * Caller must supply the output buffer whose size is NOT checked! */ -#define DUK__BITPACK_LETTER_LIMIT 26 -#define DUK__BITPACK_LOOKUP1 26 -#define DUK__BITPACK_LOOKUP2 27 -#define DUK__BITPACK_SWITCH1 28 -#define DUK__BITPACK_SWITCH 29 -#define DUK__BITPACK_UNUSED1 30 -#define DUK__BITPACK_EIGHTBIT 31 - -DUK_LOCAL const duk_uint8_t duk__bitpacked_lookup16 = { - DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, - DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, - DUK_ASC_8, DUK_ASC_9, DUK_ASC_UNDERSCORE, DUK_ASC_SPACE, - 0x82, 0x80, DUK_ASC_DOUBLEQUOTE, DUK_ASC_LCURLY -}; +#define DUK__BITPACK_LETTER_LIMIT 26 +#define DUK__BITPACK_LOOKUP1 26 +#define DUK__BITPACK_LOOKUP2 27 +#define DUK__BITPACK_SWITCH1 28 +#define DUK__BITPACK_SWITCH 29 +#define DUK__BITPACK_UNUSED1 30 +#define DUK__BITPACK_EIGHTBIT 31 + +DUK_LOCAL const duk_uint8_t duk__bitpacked_lookup16 = { DUK_ASC_0, DUK_ASC_1, DUK_ASC_2, DUK_ASC_3, + DUK_ASC_4, DUK_ASC_5, DUK_ASC_6, DUK_ASC_7, + DUK_ASC_8, DUK_ASC_9, DUK_ASC_UNDERSCORE, DUK_ASC_SPACE, + 0x82, 0x80, DUK_ASC_DOUBLEQUOTE, DUK_ASC_LCURLY }; DUK_INTERNAL duk_small_uint_t duk_bd_decode_bitpacked_string(duk_bitdecoder_ctx *bd, duk_uint8_t *out) { duk_small_uint_t len; @@ -98788,10 +100228,10 @@ len = duk_bd_decode(bd, 5); if (len == 31) { - len = duk_bd_decode(bd, 8); /* Support up to 256 bytes; rare. */ + len = duk_bd_decode(bd, 8); /* Support up to 256 bytes; rare. */ } - mode = 32; /* 0 = uppercase, 32 = lowercase (= 'a' - 'A') */ + mode = 32; /* 0 = uppercase, 32 = lowercase (= 'a' - 'A') */ for (i = 0; i < len; i++) { t = duk_bd_decode(bd, 5); if (t < DUK__BITPACK_LETTER_LIMIT) { @@ -98802,7 +100242,7 @@ t = duk__bitpacked_lookup8 + duk_bd_decode(bd, 3); } else if (t == DUK__BITPACK_SWITCH1) { t = duk_bd_decode(bd, 5); - DUK_ASSERT_DISABLE(t >= 0); /* unsigned */ + DUK_ASSERT_DISABLE(t >= 0); /* unsigned */ DUK_ASSERT(t <= 25); t = t + DUK_ASC_UC_A + (mode ^ 32); } else if (t == DUK__BITPACK_SWITCH) { @@ -98946,7 +100386,7 @@ DUK_ERROR_RANGE(thr, DUK_STR_BUFFER_TOO_LONG); DUK_WO_NORETURN(return NULL;); } -#if 0 /* for manual torture testing: tight allocation, useful with valgrind */ +#if 0 /* for manual torture testing: tight allocation, useful with valgrind */ new_sz = curr_off + sz; #endif @@ -98987,9 +100427,7 @@ DUK_UNREF(thr); p_base = bw->p_base; - duk_memcpy_unsafe((void *) bw->p, - (const void *) (p_base + src_off), - (size_t) len); + duk_memcpy_unsafe((void *) bw->p, (const void *) (p_base + src_off), (size_t) len); bw->p += len; } @@ -99004,7 +100442,11 @@ duk_bw_write_raw_slice(thr, bw, src_off, len); } -DUK_INTERNAL void duk_bw_insert_raw_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_raw_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len) { duk_uint8_t *p_base; duk_size_t buf_sz, move_sz; @@ -99015,20 +100457,20 @@ DUK_UNREF(thr); p_base = bw->p_base; - buf_sz = (duk_size_t) (bw->p - p_base); /* constrained by maximum buffer size */ + buf_sz = (duk_size_t) (bw->p - p_base); /* constrained by maximum buffer size */ move_sz = buf_sz - dst_off; - DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ - duk_memmove_unsafe((void *) (p_base + dst_off + len), - (const void *) (p_base + dst_off), - (size_t) move_sz); - duk_memcpy_unsafe((void *) (p_base + dst_off), - (const void *) buf, - (size_t) len); + DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ + duk_memmove_unsafe((void *) (p_base + dst_off + len), (const void *) (p_base + dst_off), (size_t) move_sz); + duk_memcpy_unsafe((void *) (p_base + dst_off), (const void *) buf, (size_t) len); bw->p += len; } -DUK_INTERNAL void duk_bw_insert_ensure_bytes(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, const duk_uint8_t *buf, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_ensure_bytes(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + const duk_uint8_t *buf, + duk_size_t len) { DUK_ASSERT(thr != NULL); DUK_ASSERT(bw != NULL); DUK_ASSERT(dst_off <= DUK_BW_GET_SIZE(thr, bw)); @@ -99038,7 +100480,11 @@ duk_bw_insert_raw_bytes(thr, bw, dst_off, buf, len); } -DUK_INTERNAL void duk_bw_insert_raw_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_raw_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len) { duk_uint8_t *p_base; duk_size_t buf_sz, move_sz; @@ -99065,17 +100511,17 @@ buf_sz = (duk_size_t) (bw->p - p_base); move_sz = buf_sz - dst_off; - DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ - duk_memmove_unsafe((void *) (p_base + dst_off + len), - (const void *) (p_base + dst_off), - (size_t) move_sz); - duk_memcpy_unsafe((void *) (p_base + dst_off), - (const void *) (p_base + src_off), - (size_t) len); + DUK_ASSERT(p_base != NULL); /* buffer size is >= 1 */ + duk_memmove_unsafe((void *) (p_base + dst_off + len), (const void *) (p_base + dst_off), (size_t) move_sz); + duk_memcpy_unsafe((void *) (p_base + dst_off), (const void *) (p_base + src_off), (size_t) len); bw->p += len; } -DUK_INTERNAL void duk_bw_insert_ensure_slice(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t dst_off, duk_size_t src_off, duk_size_t len) { +DUK_INTERNAL void duk_bw_insert_ensure_slice(duk_hthread *thr, + duk_bufwriter_ctx *bw, + duk_size_t dst_off, + duk_size_t src_off, + duk_size_t len) { DUK_ASSERT(thr != NULL); DUK_ASSERT(bw != NULL); DUK_ASSERT(dst_off <= DUK_BW_GET_SIZE(thr, bw)); @@ -99105,7 +100551,7 @@ p_dst = p_base + off + len; p_src = p_base + off; duk_memmove_unsafe((void *) p_dst, (const void *) p_src, (size_t) move_sz); - return p_src; /* point to start of 'reserved area' */ + return p_src; /* point to start of 'reserved area' */ } DUK_INTERNAL duk_uint8_t *duk_bw_insert_ensure_area(duk_hthread *thr, duk_bufwriter_ctx *bw, duk_size_t off, duk_size_t len) { @@ -99135,9 +100581,7 @@ p_dst = p_base + off; p_src = p_dst + len; move_sz = (duk_size_t) (bw->p - p_src); - duk_memmove_unsafe((void *) p_dst, - (const void *) p_src, - (size_t) move_sz); + duk_memmove_unsafe((void *) p_dst, (const void *) p_src, (size_t) move_sz); bw->p -= len; } @@ -99151,12 +100595,8 @@ DUK_ASSERT(bw_ctx != NULL); DUK_ASSERT(bw_ctx->buf != NULL); DUK_ASSERT((DUK_HBUFFER_DYNAMIC_GET_SIZE(bw_ctx->buf) == 0) || - (bw_ctx->p != NULL && - bw_ctx->p_base != NULL && - bw_ctx->p_limit != NULL && - bw_ctx->p_limit >= bw_ctx->p_base && - bw_ctx->p >= bw_ctx->p_base && - bw_ctx->p <= bw_ctx->p_limit)); + (bw_ctx->p != NULL && bw_ctx->p_base != NULL && bw_ctx->p_limit != NULL && bw_ctx->p_limit >= bw_ctx->p_base && + bw_ctx->p >= bw_ctx->p_base && bw_ctx->p <= bw_ctx->p_limit)); } #endif #line 1 "duk_util_cast.c" @@ -99179,7 +100619,8 @@ * relying on fmin(), fmax(), or other intrinsics. Out-of-range results are * not assumed by caller, but here value is clamped, NaN converts to minval. */ -#define DUK__DOUBLE_INT_CAST1(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST1(tname, minval, maxval) \ + do { \ if (DUK_LIKELY(x >= (duk_double_t) (minval))) { \ DUK_ASSERT(!DUK_ISNAN(x)); \ if (DUK_LIKELY(x <= (duk_double_t) (maxval))) { \ @@ -99200,19 +100641,22 @@ * argument is a NaN, return the second argument. This avoids a * NaN-to-integer cast which is undefined behavior. */ -#define DUK__DOUBLE_INT_CAST2(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST2(tname, minval, maxval) \ + do { \ return (tname) duk_double_fmin(duk_double_fmax(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ } while (0) /* Another solution which doesn't need C99+ behavior for fmin() and fmax(). */ -#define DUK__DOUBLE_INT_CAST3(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST3(tname, minval, maxval) \ + do { \ if (DUK_ISNAN(x)) { \ /* 0 or any other value is fine. */ \ return (tname) 0; \ } else \ return (tname) DUK_FMIN(DUK_FMAX(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ - } \ - } while (0) + } \ + } \ + while (0) /* C99+ solution: relies on specific fmin() and fmax() behavior in C99: if * one argument is NaN but the other isn't, the non-NaN argument is returned. @@ -99221,7 +100665,8 @@ * the fmin() and fmax() calls (unless one uses -ffast-math which we don't * support). */ -#define DUK__DOUBLE_INT_CAST4(tname,minval,maxval) do { \ +#define DUK__DOUBLE_INT_CAST4(tname, minval, maxval) \ + do { \ return (tname) DUK_FMIN(DUK_FMAX(x, (duk_double_t) (minval)), (duk_double_t) (maxval)); \ } while (0) @@ -99265,12 +100710,12 @@ * infinity, at least on x64. This number is one double unit below that * midpoint. See misc/float_cast.c. */ -#define DUK__FLOAT_ROUND_LIMIT 340282356779733623858607532500980858880.0 +#define DUK__FLOAT_ROUND_LIMIT 340282356779733623858607532500980858880.0 /* Maximum IEEE float. Double-to-float conversion above this would be out of * range and thus technically undefined behavior. */ -#define DUK__FLOAT_MAX 340282346638528859811704183484516925440.0 +#define DUK__FLOAT_MAX 340282346638528859811704183484516925440.0 DUK_INTERNAL duk_float_t duk_double_to_float_t(duk_double_t x) { /* Even a double-to-float cast is technically undefined behavior if @@ -99289,8 +100734,7 @@ duk_double_t t; t = DUK_FABS(x); - DUK_ASSERT((DUK_ISNAN(x) && DUK_ISNAN(t)) || - (!DUK_ISNAN(x) && !DUK_ISNAN(t))); + DUK_ASSERT((DUK_ISNAN(x) && DUK_ISNAN(t)) || (!DUK_ISNAN(x) && !DUK_ISNAN(t))); if (DUK_LIKELY(t <= DUK__FLOAT_MAX)) { /* Standard in-range case, try to get here with a minimum @@ -99439,7 +100883,7 @@ DUK_INTERNAL duk_double_t duk_double_trunc_towards_zero(duk_double_t x) { /* XXX: optimize */ duk_small_uint_t s = duk_double_signbit(x); - x = DUK_FLOOR(DUK_FABS(x)); /* truncate towards zero */ + x = DUK_FLOOR(DUK_FABS(x)); /* truncate towards zero */ if (s) { x = -x; } @@ -99686,8 +101130,8 @@ #if defined(DUK_USE_STRHASH_DENSE) /* 'magic' constants for Murmurhash2 */ -#define DUK__MAGIC_M ((duk_uint32_t) 0x5bd1e995UL) -#define DUK__MAGIC_R 24 +#define DUK__MAGIC_M ((duk_uint32_t) 0x5bd1e995UL) +#define DUK__MAGIC_R 24 DUK_INTERNAL duk_uint32_t duk_util_hashbytes(const duk_uint8_t *data, duk_size_t len, duk_uint32_t seed) { duk_uint32_t h = seed ^ ((duk_uint32_t) len); @@ -99701,9 +101145,7 @@ #if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS) duk_uint32_t k = *((const duk_uint32_t *) (const void *) data); #else - duk_uint32_t k = ((duk_uint32_t) data0) | - (((duk_uint32_t) data1) << 8) | - (((duk_uint32_t) data2) << 16) | + duk_uint32_t k = ((duk_uint32_t) data0) | (((duk_uint32_t) data1) << 8) | (((duk_uint32_t) data2) << 16) | (((duk_uint32_t) data3) << 24); #endif @@ -99717,11 +101159,14 @@ } switch (len) { - case 3: h ^= data2 << 16; - case 2: h ^= data1 << 8; - case 1: h ^= data0; - h *= DUK__MAGIC_M; - } + case 3: + h ^= data2 << 16; + case 2: + h ^= data1 << 8; + case 1: + h ^= data0; + h *= DUK__MAGIC_M; + } h ^= h >> 13; h *= DUK__MAGIC_M; @@ -99729,7 +101174,7 @@ return h; } -#endif /* DUK_USE_STRHASH_DENSE */ +#endif /* DUK_USE_STRHASH_DENSE */ /* automatic undefs */ #undef DUK__MAGIC_M @@ -99753,7 +101198,7 @@ DUK_ASSERT(s2 != NULL); return DUK_MEMCMP(s1, s2, (size_t) len); } -#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#else /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ DUK_INTERNAL DUK_INLINE duk_small_int_t duk_memcmp_unsafe(const void *s1, const void *s2, duk_size_t len) { DUK_ASSERT(s1 != NULL || len == 0U); DUK_ASSERT(s2 != NULL || len == 0U); @@ -99770,7 +101215,7 @@ DUK_ASSERT(s2 != NULL); return DUK_MEMCMP(s1, s2, (size_t) len); } -#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ +#endif /* DUK_USE_ALLOW_UNDEFINED_BEHAVIOR */ #line 1 "duk_util_tinyrandom.c" /* * A tiny random number generator used for Math.random() and other internals. @@ -99795,15 +101240,16 @@ #endif #if defined(DUK__RANDOM_SHAMIR3OP) -#define DUK__UPDATE_RND(rnd) do { \ +#define DUK__UPDATE_RND(rnd) \ + do { \ (rnd) += ((rnd) * (rnd)) | 0x05UL; \ - (rnd) = ((rnd) & 0xffffffffUL); /* if duk_uint32_t is exactly 32 bits, this is a NOP */ \ + (rnd) = ((rnd) &0xffffffffUL); /* if duk_uint32_t is exactly 32 bits, this is a NOP */ \ } while (0) -#define DUK__RND_BIT(rnd) ((rnd) >> 31) /* only use the highest bit */ +#define DUK__RND_BIT(rnd) ((rnd) >> 31) /* only use the highest bit */ DUK_INTERNAL void duk_util_tinyrandom_prepare_seed(duk_hthread *thr) { - DUK_UNREF(thr); /* Nothing now. */ + DUK_UNREF(thr); /* Nothing now. */ } DUK_INTERNAL duk_double_t duk_util_tinyrandom_get_double(duk_hthread *thr) { @@ -99813,7 +101259,7 @@ rnd = thr->heap->rnd_state; - n = 53; /* enough to cover the whole mantissa */ + n = 53; /* enough to cover the whole mantissa */ t = 0.0; do { @@ -99829,7 +101275,7 @@ return t; } -#endif /* DUK__RANDOM_SHAMIR3OP */ +#endif /* DUK__RANDOM_SHAMIR3OP */ #if defined(DUK__RANDOM_XOROSHIRO128PLUS) DUK_LOCAL DUK_ALWAYS_INLINE duk_uint64_t duk__rnd_splitmix64(duk_uint64_t *x) { @@ -99868,9 +101314,9 @@ * because current seed is Date.now()) result in different xoroshiro128+ * seeds. */ - x = thr->heap->rnd_state0; /* Only 0 is used as input here. */ + x = thr->heap->rnd_state0; /* Only 0 is used as input here. */ for (i = 0; i < 64; i++) { - thr->heap->rnd_statei & 0x01 = duk__rnd_splitmix64(&x); /* Keep last 2 values. */ + thr->heap->rnd_statei & 0x01 = duk__rnd_splitmix64(&x); /* Keep last 2 values. */ } } @@ -99894,9 +101340,9 @@ #endif return du.d - 1.0; } -#endif /* DUK__RANDOM_XOROSHIRO128PLUS */ +#endif /* DUK__RANDOM_XOROSHIRO128PLUS */ -#endif /* !DUK_USE_GET_RANDOM_DOUBLE */ +#endif /* !DUK_USE_GET_RANDOM_DOUBLE */ /* automatic undefs */ #undef DUK__RANDOM_SHAMIR3OP
View file
_service:tar_scm:duktape-2.6.0.tar.xz/src/duktape.h -> _service:tar_scm:duktape-2.7.0.tar.xz/src/duktape.h
Changed
@@ -1,13 +1,13 @@ /* - * Duktape public API for Duktape 2.6.0. + * Duktape public API for Duktape 2.7.0. * * See the API reference for documentation on call semantics. The exposed, * supported API is between the "BEGIN PUBLIC API" and "END PUBLIC API" * comments. Other parts of the header are Duktape internal and related to * e.g. platform/compiler/feature detection. * - * Git commit fffa346eff06a8764b02c31d4336f63a773a95c3 (v2.6.0). - * Git branch v2-maintenance. + * Git commit 03d4d728f8365021de6955c649e6dcd05dcca99f (03d4d72-dirty). + * Git branch HEAD. * * See Duktape AUTHORS.rst and LICENSE.txt for copyright and * licensing information. @@ -21,7 +21,7 @@ * * (http://opensource.org/licenses/MIT) * - * Copyright (c) 2013-2019 by Duktape authors (see AUTHORS.rst) + * Copyright (c) 2013-present by Duktape authors (see AUTHORS.rst) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -110,6 +110,12 @@ * * Luis de Bethencourt (https://github.com/luisbg) * * Ian Whyman (https://github.com/v00d00) * * Rick Sayre (https://github.com/whorfin) + * * Craig Leres (https://github.com/leres) + * * Maurici Abad (https://github.com/mauriciabad) + * * Nancy Li (https://github.com/NancyLi1013) + * * William Parks (https://github.com/WilliamParks) + * * Sam Hellawell (https://github.com/samhellawell) + * * Vladislavs Sokurenko (https://github.com/sokurenko) * * Other contributions * =================== @@ -176,16 +182,16 @@ * development snapshots have 99 for patch level (e.g. 0.10.99 would be a * development version after 0.10.0 but before the next official release). */ -#define DUK_VERSION 20600L +#define DUK_VERSION 20700L /* Git commit, describe, and branch for Duktape build. Useful for * non-official snapshot builds so that application code can easily log * which Duktape snapshot was used. Not available in the ECMAScript * environment. */ -#define DUK_GIT_COMMIT "fffa346eff06a8764b02c31d4336f63a773a95c3" -#define DUK_GIT_DESCRIBE "v2.6.0" -#define DUK_GIT_BRANCH "v2-maintenance" +#define DUK_GIT_COMMIT "03d4d728f8365021de6955c649e6dcd05dcca99f" +#define DUK_GIT_DESCRIBE "03d4d72-dirty" +#define DUK_GIT_BRANCH "HEAD" /* External duk_config.h provides platform/compiler/OS dependent * typedefs and macros, and DUK_USE_xxx config options so that
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2