visaljs 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +469 -53
- package/node/include/js_node.h +36 -0
- package/node/prelude/async_hooks.js +63 -8
- package/node/prelude/buffer.js +0 -0
- package/node/prelude/diagnostics_channel.js +322 -0
- package/node/prelude/dns.js +3 -2
- package/node/prelude/events.js +17 -3
- package/node/prelude/fs.js +177 -5
- package/node/prelude/fs_promises.js +24 -0
- package/node/prelude/http.js +13 -4
- package/node/prelude/http2.js +0 -0
- package/node/prelude/internal/async_context.js +27 -0
- package/node/prelude/internal/crypto/asym.js +0 -0
- package/node/prelude/internal/crypto/cipher.js +0 -0
- package/node/prelude/internal/crypto/kdf.js +0 -0
- package/node/prelude/internal/crypto/keys.js +0 -0
- package/node/prelude/internal/crypto/random.js +0 -0
- package/node/prelude/internal/crypto/util.js +0 -0
- package/node/prelude/internal/errors.js +11 -0
- package/node/prelude/internal/process_events.js +14 -0
- package/node/prelude/internal/process_signals.js +42 -0
- package/node/prelude/internal/querystring.js +0 -0
- package/node/prelude/internal/timers.js +233 -0
- package/node/prelude/internal/timers_global.js +9 -0
- package/node/prelude/internal/zlib_brotli.js +6 -0
- package/node/prelude/internal/zlib_engines.js +4 -0
- package/node/prelude/internal/zlib_zstd.js +6 -0
- package/node/prelude/module.js +22 -6
- package/node/prelude/net.js +9 -8
- package/node/prelude/os.js +0 -0
- package/node/prelude/path.js +1599 -186
- package/node/prelude/path_posix.js +9 -0
- package/node/prelude/path_win32.js +9 -0
- package/node/prelude/process.js +3 -0
- package/node/prelude/querystring.js +0 -0
- package/node/prelude/stream.js +18 -6
- package/node/prelude/stream_promises.js +0 -0
- package/node/prelude/stream_web.js +0 -0
- package/node/prelude/string_decoder.js +0 -0
- package/node/prelude/timers.js +92 -0
- package/node/prelude/timers_promises.js +133 -0
- package/node/prelude/tty.js +0 -0
- package/node/prelude/url.js +0 -0
- package/node/prelude/util.js +0 -0
- package/node/prelude/zlib.js +912 -72
- package/node/src/host_brotli.c +157 -0
- package/node/src/host_fs.c +95 -1
- package/node/src/host_loop.c +10 -4
- package/node/src/host_os.c +0 -0
- package/node/src/host_signal.c +70 -0
- package/node/src/host_sys.c +50 -0
- package/node/src/host_zlib.c +314 -0
- package/node/src/host_zstd.c +179 -0
- package/node/third_party/brotli/LICENSE +19 -0
- package/node/third_party/brotli/common/constants.c +15 -0
- package/node/third_party/brotli/common/constants.h +201 -0
- package/node/third_party/brotli/common/context.c +156 -0
- package/node/third_party/brotli/common/context.h +113 -0
- package/node/third_party/brotli/common/dictionary.c +5916 -0
- package/node/third_party/brotli/common/dictionary.h +64 -0
- package/node/third_party/brotli/common/platform.c +23 -0
- package/node/third_party/brotli/common/platform.h +541 -0
- package/node/third_party/brotli/common/shared_dictionary.c +521 -0
- package/node/third_party/brotli/common/shared_dictionary_internal.h +75 -0
- package/node/third_party/brotli/common/transform.c +291 -0
- package/node/third_party/brotli/common/transform.h +85 -0
- package/node/third_party/brotli/common/version.h +51 -0
- package/node/third_party/brotli/dec/bit_reader.c +78 -0
- package/node/third_party/brotli/dec/bit_reader.h +423 -0
- package/node/third_party/brotli/dec/decode.c +2875 -0
- package/node/third_party/brotli/dec/huffman.c +342 -0
- package/node/third_party/brotli/dec/huffman.h +122 -0
- package/node/third_party/brotli/dec/prefix.h +733 -0
- package/node/third_party/brotli/dec/state.c +183 -0
- package/node/third_party/brotli/dec/state.h +400 -0
- package/node/third_party/brotli/enc/backward_references.c +207 -0
- package/node/third_party/brotli/enc/backward_references.h +40 -0
- package/node/third_party/brotli/enc/backward_references_hq.c +939 -0
- package/node/third_party/brotli/enc/backward_references_hq.h +96 -0
- package/node/third_party/brotli/enc/backward_references_inc.h +189 -0
- package/node/third_party/brotli/enc/bit_cost.c +36 -0
- package/node/third_party/brotli/enc/bit_cost.h +64 -0
- package/node/third_party/brotli/enc/bit_cost_inc.h +127 -0
- package/node/third_party/brotli/enc/block_encoder_inc.h +34 -0
- package/node/third_party/brotli/enc/block_splitter.c +217 -0
- package/node/third_party/brotli/enc/block_splitter.h +52 -0
- package/node/third_party/brotli/enc/block_splitter_inc.h +481 -0
- package/node/third_party/brotli/enc/brotli_bit_stream.c +1336 -0
- package/node/third_party/brotli/enc/brotli_bit_stream.h +89 -0
- package/node/third_party/brotli/enc/cluster.c +57 -0
- package/node/third_party/brotli/enc/cluster.h +49 -0
- package/node/third_party/brotli/enc/cluster_inc.h +325 -0
- package/node/third_party/brotli/enc/command.c +28 -0
- package/node/third_party/brotli/enc/command.h +191 -0
- package/node/third_party/brotli/enc/compound_dictionary.c +207 -0
- package/node/third_party/brotli/enc/compound_dictionary.h +74 -0
- package/node/third_party/brotli/enc/compress_fragment.c +800 -0
- package/node/third_party/brotli/enc/compress_fragment.h +86 -0
- package/node/third_party/brotli/enc/compress_fragment_two_pass.c +657 -0
- package/node/third_party/brotli/enc/compress_fragment_two_pass.h +72 -0
- package/node/third_party/brotli/enc/dictionary_hash.c +1848 -0
- package/node/third_party/brotli/enc/dictionary_hash.h +25 -0
- package/node/third_party/brotli/enc/encode.c +1996 -0
- package/node/third_party/brotli/enc/encoder_dict.c +640 -0
- package/node/third_party/brotli/enc/encoder_dict.h +157 -0
- package/node/third_party/brotli/enc/entropy_encode.c +504 -0
- package/node/third_party/brotli/enc/entropy_encode.h +123 -0
- package/node/third_party/brotli/enc/entropy_encode_static.h +542 -0
- package/node/third_party/brotli/enc/fast_log.c +105 -0
- package/node/third_party/brotli/enc/fast_log.h +67 -0
- package/node/third_party/brotli/enc/find_match_length.h +72 -0
- package/node/third_party/brotli/enc/hash.h +728 -0
- package/node/third_party/brotli/enc/hash_composite_inc.h +140 -0
- package/node/third_party/brotli/enc/hash_forgetful_chain_inc.h +295 -0
- package/node/third_party/brotli/enc/hash_longest_match64_inc.h +262 -0
- package/node/third_party/brotli/enc/hash_longest_match_inc.h +258 -0
- package/node/third_party/brotli/enc/hash_longest_match_quickly_inc.h +266 -0
- package/node/third_party/brotli/enc/hash_rolling_inc.h +212 -0
- package/node/third_party/brotli/enc/hash_to_binary_tree_inc.h +330 -0
- package/node/third_party/brotli/enc/histogram.c +100 -0
- package/node/third_party/brotli/enc/histogram.h +64 -0
- package/node/third_party/brotli/enc/histogram_inc.h +51 -0
- package/node/third_party/brotli/enc/literal_cost.c +180 -0
- package/node/third_party/brotli/enc/literal_cost.h +32 -0
- package/node/third_party/brotli/enc/memory.c +194 -0
- package/node/third_party/brotli/enc/memory.h +131 -0
- package/node/third_party/brotli/enc/metablock.c +677 -0
- package/node/third_party/brotli/enc/metablock.h +106 -0
- package/node/third_party/brotli/enc/metablock_inc.h +185 -0
- package/node/third_party/brotli/enc/params.h +47 -0
- package/node/third_party/brotli/enc/prefix.h +54 -0
- package/node/third_party/brotli/enc/quality.h +202 -0
- package/node/third_party/brotli/enc/ringbuffer.h +168 -0
- package/node/third_party/brotli/enc/state.h +104 -0
- package/node/third_party/brotli/enc/static_dict.c +542 -0
- package/node/third_party/brotli/enc/static_dict.h +41 -0
- package/node/third_party/brotli/enc/static_dict_lut.h +5866 -0
- package/node/third_party/brotli/enc/utf8_util.c +85 -0
- package/node/third_party/brotli/enc/utf8_util.h +33 -0
- package/node/third_party/brotli/enc/write_bits.h +88 -0
- package/node/third_party/brotli/include/brotli/decode.h +409 -0
- package/node/third_party/brotli/include/brotli/encode.h +501 -0
- package/node/third_party/brotli/include/brotli/port.h +305 -0
- package/node/third_party/brotli/include/brotli/shared_dictionary.h +100 -0
- package/node/third_party/brotli/include/brotli/types.h +83 -0
- package/node/third_party/libuv/LICENSE +0 -0
- package/node/third_party/libuv/include/uv/aix.h +0 -0
- package/node/third_party/libuv/include/uv/bsd.h +0 -0
- package/node/third_party/libuv/include/uv/darwin.h +0 -0
- package/node/third_party/libuv/include/uv/errno.h +0 -0
- package/node/third_party/libuv/include/uv/linux.h +0 -0
- package/node/third_party/libuv/include/uv/os390.h +0 -0
- package/node/third_party/libuv/include/uv/posix.h +0 -0
- package/node/third_party/libuv/include/uv/sunos.h +0 -0
- package/node/third_party/libuv/include/uv/threadpool.h +0 -0
- package/node/third_party/libuv/include/uv/tree.h +0 -0
- package/node/third_party/libuv/include/uv/unix.h +0 -0
- package/node/third_party/libuv/include/uv/version.h +0 -0
- package/node/third_party/libuv/include/uv/win.h +0 -0
- package/node/third_party/libuv/include/uv.h +0 -0
- package/node/third_party/libuv/src/fs-poll.c +0 -0
- package/node/third_party/libuv/src/heap-inl.h +0 -0
- package/node/third_party/libuv/src/idna.c +0 -0
- package/node/third_party/libuv/src/idna.h +0 -0
- package/node/third_party/libuv/src/inet.c +0 -0
- package/node/third_party/libuv/src/queue.h +0 -0
- package/node/third_party/libuv/src/random.c +0 -0
- package/node/third_party/libuv/src/strscpy.c +0 -0
- package/node/third_party/libuv/src/strscpy.h +0 -0
- package/node/third_party/libuv/src/strtok.c +0 -0
- package/node/third_party/libuv/src/strtok.h +0 -0
- package/node/third_party/libuv/src/thread-common.c +0 -0
- package/node/third_party/libuv/src/threadpool.c +0 -0
- package/node/third_party/libuv/src/timer.c +0 -0
- package/node/third_party/libuv/src/unix/async.c +0 -0
- package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
- package/node/third_party/libuv/src/unix/core.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
- package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
- package/node/third_party/libuv/src/unix/darwin.c +0 -0
- package/node/third_party/libuv/src/unix/dl.c +0 -0
- package/node/third_party/libuv/src/unix/fs.c +0 -0
- package/node/third_party/libuv/src/unix/fsevents.c +0 -0
- package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
- package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
- package/node/third_party/libuv/src/unix/internal.h +0 -0
- package/node/third_party/libuv/src/unix/kqueue.c +0 -0
- package/node/third_party/libuv/src/unix/linux.c +0 -0
- package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
- package/node/third_party/libuv/src/unix/loop.c +0 -0
- package/node/third_party/libuv/src/unix/pipe.c +0 -0
- package/node/third_party/libuv/src/unix/poll.c +0 -0
- package/node/third_party/libuv/src/unix/process.c +0 -0
- package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
- package/node/third_party/libuv/src/unix/proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
- package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
- package/node/third_party/libuv/src/unix/signal.c +0 -0
- package/node/third_party/libuv/src/unix/stream.c +0 -0
- package/node/third_party/libuv/src/unix/tcp.c +0 -0
- package/node/third_party/libuv/src/unix/thread.c +0 -0
- package/node/third_party/libuv/src/unix/tty.c +0 -0
- package/node/third_party/libuv/src/unix/udp.c +0 -0
- package/node/third_party/libuv/src/uv-common.c +0 -0
- package/node/third_party/libuv/src/uv-common.h +0 -0
- package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
- package/node/third_party/libuv/src/version.c +0 -0
- package/node/third_party/llhttp/LICENSE +0 -0
- package/node/third_party/llhttp/api.c +0 -0
- package/node/third_party/llhttp/http.c +0 -0
- package/node/third_party/llhttp/llhttp.c +0 -0
- package/node/third_party/llhttp/llhttp.h +0 -0
- package/node/third_party/zlib/LICENSE +19 -0
- package/node/third_party/zlib/README.chromium +38 -0
- package/node/third_party/zlib/adler32.c +197 -0
- package/node/third_party/zlib/chromeconf.h +203 -0
- package/node/third_party/zlib/contrib/optimizations/insert_string.h +80 -0
- package/node/third_party/zlib/cpu_features.c +213 -0
- package/node/third_party/zlib/cpu_features.h +22 -0
- package/node/third_party/zlib/crc32.c +1192 -0
- package/node/third_party/zlib/crc32.h +9446 -0
- package/node/third_party/zlib/deflate.c +2289 -0
- package/node/third_party/zlib/deflate.h +407 -0
- package/node/third_party/zlib/gzguts.h +214 -0
- package/node/third_party/zlib/inffast.c +327 -0
- package/node/third_party/zlib/inffast.h +26 -0
- package/node/third_party/zlib/inffixed.h +94 -0
- package/node/third_party/zlib/inflate.c +1528 -0
- package/node/third_party/zlib/inflate.h +126 -0
- package/node/third_party/zlib/inftrees.c +299 -0
- package/node/third_party/zlib/inftrees.h +62 -0
- package/node/third_party/zlib/trees.c +1161 -0
- package/node/third_party/zlib/trees.h +128 -0
- package/node/third_party/zlib/zconf.h +558 -0
- package/node/third_party/zlib/zlib.h +1967 -0
- package/node/third_party/zlib/zutil.c +299 -0
- package/node/third_party/zlib/zutil.h +275 -0
- package/node/third_party/zstd/LICENSE +30 -0
- package/node/third_party/zstd/common/allocations.h +55 -0
- package/node/third_party/zstd/common/bits.h +205 -0
- package/node/third_party/zstd/common/bitstream.h +454 -0
- package/node/third_party/zstd/common/compiler.h +464 -0
- package/node/third_party/zstd/common/cpu.h +249 -0
- package/node/third_party/zstd/common/debug.c +30 -0
- package/node/third_party/zstd/common/debug.h +107 -0
- package/node/third_party/zstd/common/entropy_common.c +340 -0
- package/node/third_party/zstd/common/error_private.c +64 -0
- package/node/third_party/zstd/common/error_private.h +158 -0
- package/node/third_party/zstd/common/fse.h +625 -0
- package/node/third_party/zstd/common/fse_decompress.c +315 -0
- package/node/third_party/zstd/common/huf.h +277 -0
- package/node/third_party/zstd/common/mem.h +422 -0
- package/node/third_party/zstd/common/pool.c +371 -0
- package/node/third_party/zstd/common/pool.h +81 -0
- package/node/third_party/zstd/common/portability_macros.h +171 -0
- package/node/third_party/zstd/common/threading.c +182 -0
- package/node/third_party/zstd/common/threading.h +142 -0
- package/node/third_party/zstd/common/xxhash.c +18 -0
- package/node/third_party/zstd/common/xxhash.h +7094 -0
- package/node/third_party/zstd/common/zstd_common.c +48 -0
- package/node/third_party/zstd/common/zstd_deps.h +123 -0
- package/node/third_party/zstd/common/zstd_internal.h +324 -0
- package/node/third_party/zstd/common/zstd_trace.h +156 -0
- package/node/third_party/zstd/compress/clevels.h +134 -0
- package/node/third_party/zstd/compress/fse_compress.c +625 -0
- package/node/third_party/zstd/compress/hist.c +191 -0
- package/node/third_party/zstd/compress/hist.h +82 -0
- package/node/third_party/zstd/compress/huf_compress.c +1464 -0
- package/node/third_party/zstd/compress/zstd_compress.c +7843 -0
- package/node/third_party/zstd/compress/zstd_compress_internal.h +1636 -0
- package/node/third_party/zstd/compress/zstd_compress_literals.c +235 -0
- package/node/third_party/zstd/compress/zstd_compress_literals.h +39 -0
- package/node/third_party/zstd/compress/zstd_compress_sequences.c +442 -0
- package/node/third_party/zstd/compress/zstd_compress_sequences.h +55 -0
- package/node/third_party/zstd/compress/zstd_compress_superblock.c +688 -0
- package/node/third_party/zstd/compress/zstd_compress_superblock.h +32 -0
- package/node/third_party/zstd/compress/zstd_cwksp.h +765 -0
- package/node/third_party/zstd/compress/zstd_double_fast.c +778 -0
- package/node/third_party/zstd/compress/zstd_double_fast.h +42 -0
- package/node/third_party/zstd/compress/zstd_fast.c +985 -0
- package/node/third_party/zstd/compress/zstd_fast.h +30 -0
- package/node/third_party/zstd/compress/zstd_lazy.c +2199 -0
- package/node/third_party/zstd/compress/zstd_lazy.h +193 -0
- package/node/third_party/zstd/compress/zstd_ldm.c +745 -0
- package/node/third_party/zstd/compress/zstd_ldm.h +109 -0
- package/node/third_party/zstd/compress/zstd_ldm_geartab.h +106 -0
- package/node/third_party/zstd/compress/zstd_opt.c +1580 -0
- package/node/third_party/zstd/compress/zstd_opt.h +72 -0
- package/node/third_party/zstd/compress/zstd_preSplit.c +238 -0
- package/node/third_party/zstd/compress/zstd_preSplit.h +33 -0
- package/node/third_party/zstd/compress/zstdmt_compress.c +1923 -0
- package/node/third_party/zstd/compress/zstdmt_compress.h +102 -0
- package/node/third_party/zstd/decompress/huf_decompress.c +1944 -0
- package/node/third_party/zstd/decompress/zstd_ddict.c +244 -0
- package/node/third_party/zstd/decompress/zstd_ddict.h +44 -0
- package/node/third_party/zstd/decompress/zstd_decompress.c +2410 -0
- package/node/third_party/zstd/decompress/zstd_decompress_block.c +2209 -0
- package/node/third_party/zstd/decompress/zstd_decompress_block.h +73 -0
- package/node/third_party/zstd/decompress/zstd_decompress_internal.h +240 -0
- package/node/third_party/zstd/zdict.h +481 -0
- package/node/third_party/zstd/zstd.h +3198 -0
- package/node/third_party/zstd/zstd_errors.h +107 -0
- package/package.json +1 -1
- package/runtime/include/js_atoms.gen.h +0 -0
- package/runtime/include/js_atoms.h +0 -0
- package/runtime/include/js_bigint.h +0 -0
- package/runtime/include/js_buffer.h +0 -0
- package/runtime/include/js_builtins.h +0 -0
- package/runtime/include/js_console.h +5 -2
- package/runtime/include/js_convert.h +0 -0
- package/runtime/include/js_core.def +0 -0
- package/runtime/include/js_error.h +0 -0
- package/runtime/include/js_exception.h +0 -0
- package/runtime/include/js_function.h +0 -0
- package/runtime/include/js_gc.h +0 -0
- package/runtime/include/js_generator.h +0 -0
- package/runtime/include/js_host.h +5 -3
- package/runtime/include/js_jobs.h +18 -1
- package/runtime/include/js_module.h +0 -0
- package/runtime/include/js_object.h +0 -0
- package/runtime/include/js_ops.h +0 -0
- package/runtime/include/js_promise.h +1 -0
- package/runtime/include/js_regexp.h +0 -0
- package/runtime/include/js_runtime.h +0 -0
- package/runtime/include/js_symbol.h +0 -0
- package/runtime/include/js_web.h +0 -0
- package/runtime/include/jscell.h +0 -0
- package/runtime/include/jscontext.h +14 -0
- package/runtime/include/jsnum.h +0 -0
- package/runtime/include/jsstring.h +0 -0
- package/runtime/include/jsvalue.h +0 -0
- package/runtime/src/arguments.c +0 -0
- package/runtime/src/array.c +0 -0
- package/runtime/src/arraybuffer.c +0 -0
- package/runtime/src/async_iter.c +0 -0
- package/runtime/src/atoms.c +0 -0
- package/runtime/src/base64.c +0 -0
- package/runtime/src/bigint.c +0 -0
- package/runtime/src/blob.c +0 -0
- package/runtime/src/buffer.c +20 -16
- package/runtime/src/builtin_table.c +0 -0
- package/runtime/src/builtins.c +0 -0
- package/runtime/src/builtins_util.h +0 -0
- package/runtime/src/collections.c +0 -0
- package/runtime/src/components.c +0 -0
- package/runtime/src/console.c +15 -2
- package/runtime/src/convert.c +0 -0
- package/runtime/src/core_all.c +0 -0
- package/runtime/src/crypto.c +0 -0
- package/runtime/src/crypto_host.c +0 -0
- package/runtime/src/crypto_kdf.c +0 -0
- package/runtime/src/crypto_key.c +0 -0
- package/runtime/src/date.c +0 -0
- package/runtime/src/domexception.c +0 -0
- package/runtime/src/elements.c +0 -0
- package/runtime/src/elements.h +0 -0
- package/runtime/src/encoding.c +0 -0
- package/runtime/src/error.c +0 -0
- package/runtime/src/events.c +1 -1
- package/runtime/src/exception.c +0 -0
- package/runtime/src/fetch.c +0 -0
- package/runtime/src/function.c +0 -0
- package/runtime/src/gc.c +2 -0
- package/runtime/src/generator.c +0 -0
- package/runtime/src/global.c +0 -0
- package/runtime/src/headers.c +0 -0
- package/runtime/src/inspect.c +0 -0
- package/runtime/src/internal.h +0 -0
- package/runtime/src/iterate.c +0 -0
- package/runtime/src/iterator.c +0 -0
- package/runtime/src/jobs.c +123 -44
- package/runtime/src/jsnum.c +0 -0
- package/runtime/src/json.c +0 -0
- package/runtime/src/math.c +0 -0
- package/runtime/src/module.c +0 -0
- package/runtime/src/number.c +0 -0
- package/runtime/src/object.c +0 -0
- package/runtime/src/ops.c +0 -0
- package/runtime/src/os.c +0 -0
- package/runtime/src/os.h +0 -0
- package/runtime/src/process.c +92 -8
- package/runtime/src/promise.c +7 -2
- package/runtime/src/proxy.c +0 -0
- package/runtime/src/reflect.c +0 -0
- package/runtime/src/regexp.c +0 -0
- package/runtime/src/regexp_anchor.h +0 -0
- package/runtime/src/regexp_message.h +0 -0
- package/runtime/src/shape.c +0 -0
- package/runtime/src/shape.h +0 -0
- package/runtime/src/streams.c +0 -0
- package/runtime/src/streams.h +0 -0
- package/runtime/src/string.c +0 -0
- package/runtime/src/string_builtins.c +0 -0
- package/runtime/src/symbol.c +0 -0
- package/runtime/src/test_host.c +0 -0
- package/runtime/src/typedarray.c +0 -0
- package/runtime/src/tznames.gen.h +0 -0
- package/runtime/src/uri.c +0 -0
- package/runtime/src/url.c +0 -0
- package/runtime/src/weak.c +1 -4
- package/runtime/src/web.c +0 -0
- package/runtime/src/wrapper.c +0 -0
- package/runtime/src/writable.c +0 -0
- package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
- package/runtime/third_party/ada-idna/README.md +0 -0
- package/runtime/third_party/ada-idna/convert.mjs +0 -0
- package/runtime/third_party/ada-idna/idna.c +0 -0
- package/runtime/third_party/ada-idna/idna.h +0 -0
- package/runtime/third_party/ada-idna/idna_tables.h +0 -0
- package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
- package/runtime/third_party/quickjs-dtoa/README.md +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
- package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
- package/runtime/third_party/quickjs-regexp/README.md +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
- package/runtime/third_party/v8-ieee754/LICENSE +0 -0
- package/runtime/third_party/v8-ieee754/README.md +0 -0
- package/runtime/third_party/v8-ieee754/convert.py +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
- package/runtime/tools/regexp_compile.c +0 -0
package/runtime/src/jobs.c
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* loop (layer 2: timers; the v1 backend has no I/O, so waiting is sleeping). */
|
|
3
3
|
#include "js_jobs.h"
|
|
4
4
|
|
|
5
|
+
#include <stdint.h>
|
|
5
6
|
#include <stdio.h>
|
|
6
7
|
#include <stdlib.h>
|
|
7
8
|
#include <string.h>
|
|
@@ -31,10 +32,32 @@ void js_enqueue_microtask(JSContext *ctx, const JSJob *job) {
|
|
|
31
32
|
JSJob *slot = &q->items[(q->head + q->count) % q->cap];
|
|
32
33
|
*slot = *job;
|
|
33
34
|
slot->realm = ctx;
|
|
35
|
+
slot->context = ctx->rt->async_context;
|
|
34
36
|
q->count++;
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
/* ---- The async context (ADR 0020) ---------------------------------------------------- */
|
|
40
|
+
|
|
41
|
+
JSValue js_async_context(JSContext *ctx) { return ctx->rt->async_context; }
|
|
42
|
+
|
|
43
|
+
void js_set_async_context(JSContext *ctx, JSValue context) {
|
|
44
|
+
ctx->rt->async_context = context; /* a root, not a heap cell: no barrier */
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* A job runs under the async context it was queued in (a promise reaction's is its then()'s:
|
|
48
|
+
* promise.c), and the one current before is current again after it. */
|
|
49
|
+
static int run_job_body(const JSJob *job);
|
|
50
|
+
|
|
37
51
|
static int run_job(const JSJob *job) {
|
|
52
|
+
JSRuntime *rt = job->realm->rt;
|
|
53
|
+
JSValue saved = rt->async_context;
|
|
54
|
+
rt->async_context = job->context;
|
|
55
|
+
int r = run_job_body(job);
|
|
56
|
+
rt->async_context = saved;
|
|
57
|
+
return r;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static int run_job_body(const JSJob *job) {
|
|
38
61
|
JSContext *ctx = job->realm;
|
|
39
62
|
switch (job->kind) {
|
|
40
63
|
case JS_JOB_PROMISE_REACTION: return js_promise_reaction_job(ctx, job->a, job->b, job->c);
|
|
@@ -61,19 +84,28 @@ static int run_job(const JSJob *job) {
|
|
|
61
84
|
|
|
62
85
|
void js_set_rejection_mode(JSRuntime *rt, JSRejectionMode mode) { rt->rejection_mode = (uint8_t)mode; }
|
|
63
86
|
|
|
87
|
+
static void push_rejection(struct JSRejections *l, JSValue promise) {
|
|
88
|
+
if (l->count == l->cap) {
|
|
89
|
+
size_t cap = l->cap ? l->cap * 2 : 16;
|
|
90
|
+
JSValue *items = realloc(l->items, cap * sizeof *items);
|
|
91
|
+
if (!items) js_fatal("out of memory tracking a rejection");
|
|
92
|
+
l->items = items;
|
|
93
|
+
l->cap = cap;
|
|
94
|
+
}
|
|
95
|
+
l->items[l->count++] = promise;
|
|
96
|
+
}
|
|
97
|
+
|
|
64
98
|
void js_track_rejection(JSContext *ctx, JSValue promise, bool rejected) {
|
|
65
99
|
JSRuntime *rt = ctx->rt;
|
|
66
100
|
struct JSRejections *l = &rt->rejections;
|
|
67
101
|
if (rt->rejection_mode == JS_REJECTIONS_NONE) return;
|
|
68
102
|
if (rejected) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
l->items[l->count++] = promise;
|
|
103
|
+
push_rejection(l, promise);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (js_as_promise(promise)->reported) { /* the host handled it as unhandled: it hears of the handler */
|
|
107
|
+
js_as_promise(promise)->reported = 0;
|
|
108
|
+
if (rt->on_handled_late) push_rejection(&rt->handled_late, promise);
|
|
77
109
|
return;
|
|
78
110
|
}
|
|
79
111
|
for (size_t i = 0; i < l->count; i++) { /* handled before the checkpoint ended: not reported */
|
|
@@ -85,16 +117,24 @@ void js_track_rejection(JSContext *ctx, JSValue promise, bool rejected) {
|
|
|
85
117
|
}
|
|
86
118
|
}
|
|
87
119
|
|
|
88
|
-
/* Reports what is still unhandled. Strict: the first one
|
|
120
|
+
/* Reports what is still unhandled, unless the host handles it. Strict: the first one not
|
|
121
|
+
* handled ends the program (like Node). */
|
|
89
122
|
static int process_rejections(JSContext *ctx) {
|
|
90
123
|
JSRuntime *rt = ctx->rt;
|
|
91
|
-
struct JSRejections *l = &rt->rejections;
|
|
124
|
+
struct JSRejections *l = &rt->rejections, *late = &rt->handled_late;
|
|
125
|
+
while (late->count) {
|
|
126
|
+
JSValue promise = late->items[0]; /* on the C stack: the conservative scan keeps it alive */
|
|
127
|
+
memmove(&late->items[0], &late->items[1], (late->count - 1) * sizeof *late->items);
|
|
128
|
+
late->count--;
|
|
129
|
+
if (rt->on_handled_late(ctx, promise) < 0 && js_report_uncaught(ctx)) return -1;
|
|
130
|
+
}
|
|
92
131
|
while (l->count) {
|
|
93
132
|
JSValue promise = l->items[0];
|
|
94
133
|
memmove(&l->items[0], &l->items[1], (l->count - 1) * sizeof *l->items);
|
|
95
134
|
l->count--;
|
|
96
|
-
|
|
97
|
-
if (
|
|
135
|
+
int status = js_report_rejection(ctx, promise, js_as_promise(promise)->result);
|
|
136
|
+
if (status == 0) js_as_promise(promise)->reported = 1;
|
|
137
|
+
if (status && rt->rejection_mode == JS_REJECTIONS_STRICT) {
|
|
98
138
|
l->count = 0;
|
|
99
139
|
return -1;
|
|
100
140
|
}
|
|
@@ -110,18 +150,19 @@ int js_run_microtasks(JSContext *ctx) {
|
|
|
110
150
|
rt->in_checkpoint = 1;
|
|
111
151
|
JSJobQueue *q = &rt->jobs;
|
|
112
152
|
int status = 0;
|
|
113
|
-
while
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
js_report_uncaught(job.realm)
|
|
119
|
-
|
|
120
|
-
|
|
153
|
+
do { /* again while the host's handling of a rejection queued jobs */
|
|
154
|
+
while (q->count) {
|
|
155
|
+
JSJob job = q->items[q->head]; /* on the C stack: the conservative scan keeps it alive */
|
|
156
|
+
q->head = (q->head + 1) % q->cap;
|
|
157
|
+
q->count--;
|
|
158
|
+
if (run_job(&job) < 0 && js_report_uncaught(job.realm)) { /* handled: the next job runs */
|
|
159
|
+
status = -1;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
121
162
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
163
|
+
js_clear_kept_objects(rt); /* the end of the job: WeakRef targets may go now */
|
|
164
|
+
if (status == 0) status = process_rejections(ctx);
|
|
165
|
+
} while (status == 0 && (q->count || rt->handled_late.count));
|
|
125
166
|
rt->in_checkpoint = 0;
|
|
126
167
|
return status;
|
|
127
168
|
}
|
|
@@ -135,17 +176,21 @@ void js_jobs_trace(JSRuntime *rt, JSTracer *trc) {
|
|
|
135
176
|
js_trace_value(trc, j->a);
|
|
136
177
|
js_trace_value(trc, j->b);
|
|
137
178
|
js_trace_value(trc, j->c);
|
|
179
|
+
js_trace_value(trc, j->context);
|
|
138
180
|
}
|
|
139
181
|
for (size_t i = 0; i < rt->rejections.count; i++) js_trace_value(trc, rt->rejections.items[i]);
|
|
182
|
+
for (size_t i = 0; i < rt->handled_late.count; i++) js_trace_value(trc, rt->handled_late.items[i]);
|
|
140
183
|
for (size_t i = 0; i < rt->timers.count; i++) {
|
|
141
184
|
js_trace_value(trc, rt->timers.heap[i].fn);
|
|
142
185
|
js_trace_value(trc, rt->timers.heap[i].args);
|
|
186
|
+
js_trace_value(trc, rt->timers.heap[i].context);
|
|
143
187
|
}
|
|
144
188
|
}
|
|
145
189
|
|
|
146
190
|
void js_jobs_free(JSRuntime *rt) {
|
|
147
191
|
free(rt->jobs.items);
|
|
148
192
|
free(rt->rejections.items);
|
|
193
|
+
free(rt->handled_late.items);
|
|
149
194
|
free(rt->timers.heap);
|
|
150
195
|
}
|
|
151
196
|
|
|
@@ -210,33 +255,58 @@ static JSValue add_timer(JSContext *ctx, uint32_t argc, const JSValue *argv, boo
|
|
|
210
255
|
JSValue args = argc > 2 ? js_new_array_from(ctx, argv + 2, argc - 2) : JS_UNDEFINED;
|
|
211
256
|
JSTimers *t = &ctx->rt->timers;
|
|
212
257
|
if (++t->next_id > 2147483647u) t->next_id = 1;
|
|
213
|
-
JSTimer timer = { t->now + (uint64_t)delay, t->seq++, t->next_id, repeat ? (uint32_t)delay : 0, 0, ctx, fn, args };
|
|
258
|
+
JSTimer timer = { t->now + (uint64_t)delay, t->seq++, t->next_id, repeat ? (uint32_t)delay : 0, 0, ctx, fn, args, ctx->rt->async_context };
|
|
214
259
|
timer_push(t, &timer);
|
|
215
260
|
return js_int32((int32_t)timer.id);
|
|
216
261
|
}
|
|
217
262
|
|
|
218
263
|
uint32_t js_add_timer(JSContext *ctx, JSValue fn, double delay, bool unref) {
|
|
264
|
+
return js_timer_start(ctx, fn, delay, false, unref, 0);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
static size_t timer_find(const JSTimers *t, uint32_t id) {
|
|
268
|
+
for (size_t i = 0; i < t->count; i++)
|
|
269
|
+
if (t->heap[i].id == id) return i;
|
|
270
|
+
return SIZE_MAX;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
uint32_t js_timer_start(JSContext *ctx, JSValue fn, double delay, bool immediate, bool unref, uint32_t id) {
|
|
219
274
|
if (!(delay >= 1 && delay <= TIMEOUT_MAX)) delay = 1;
|
|
220
275
|
JSTimers *t = &ctx->rt->timers;
|
|
221
276
|
if (!t->now) t->now = js_os_now_ms();
|
|
222
|
-
if (
|
|
223
|
-
|
|
277
|
+
if (id) { /* restarted: it replaces the pending one with its id */
|
|
278
|
+
size_t i = timer_find(t, id);
|
|
279
|
+
if (i != SIZE_MAX) timer_remove(t, i);
|
|
280
|
+
} else {
|
|
281
|
+
if (++t->next_id > 2147483647u) t->next_id = 1;
|
|
282
|
+
id = t->next_id;
|
|
283
|
+
}
|
|
284
|
+
JSTimer timer = { immediate ? t->now : t->now + (uint64_t)delay, t->seq++, id, 0, unref, ctx, fn, JS_UNDEFINED, ctx->rt->async_context };
|
|
224
285
|
timer_push(t, &timer);
|
|
225
|
-
return
|
|
286
|
+
return id;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
void js_timer_set_ref(JSContext *ctx, uint32_t id, bool ref) {
|
|
290
|
+
JSTimers *t = &ctx->rt->timers;
|
|
291
|
+
size_t i = timer_find(t, id);
|
|
292
|
+
if (i == SIZE_MAX || t->heap[i].unref == !ref) return;
|
|
293
|
+
t->heap[i].unref = !ref;
|
|
294
|
+
if (ref) t->refed++;
|
|
295
|
+
else t->refed--;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
void js_timer_clear(JSContext *ctx, uint32_t id) {
|
|
299
|
+
JSTimers *t = &ctx->rt->timers;
|
|
300
|
+
if (t->running && id == t->running) t->running_cleared = 1;
|
|
301
|
+
size_t i = timer_find(t, id);
|
|
302
|
+
if (i != SIZE_MAX) timer_remove(t, i);
|
|
226
303
|
}
|
|
227
304
|
|
|
228
305
|
/* clearTimeout / clearInterval (either clears both kinds, as in Node). */
|
|
229
306
|
static void clear_timer(JSContext *ctx, uint32_t argc, const JSValue *argv) {
|
|
230
307
|
if (!argc || !js_is_number(argv[0])) return;
|
|
231
308
|
double d = js_as_number(argv[0]);
|
|
232
|
-
|
|
233
|
-
if (t->running && d == (double)t->running) t->running_cleared = 1;
|
|
234
|
-
for (size_t i = 0; i < t->count; i++) {
|
|
235
|
-
if ((double)t->heap[i].id == d) {
|
|
236
|
-
timer_remove(t, i);
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
309
|
+
if (d >= 1 && d <= 2147483647.0 && d == (double)(uint32_t)d) js_timer_clear(ctx, (uint32_t)d);
|
|
240
310
|
}
|
|
241
311
|
|
|
242
312
|
#define HOST_FN(fn) static JSValue fn(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target)
|
|
@@ -257,7 +327,7 @@ HOST_FN(set_immediate) {
|
|
|
257
327
|
JSValue args = argc > 1 ? js_new_array_from(ctx, argv + 1, argc - 1) : JS_UNDEFINED;
|
|
258
328
|
JSTimers *t = &ctx->rt->timers;
|
|
259
329
|
if (++t->next_id > 2147483647u) t->next_id = 1;
|
|
260
|
-
JSTimer timer = { t->now, t->seq++, t->next_id, 0, 0, ctx, fn, args };
|
|
330
|
+
JSTimer timer = { t->now, t->seq++, t->next_id, 0, 0, ctx, fn, args, ctx->rt->async_context };
|
|
261
331
|
timer_push(t, &timer);
|
|
262
332
|
return js_int32((int32_t)timer.id);
|
|
263
333
|
}
|
|
@@ -274,7 +344,7 @@ static JSValue queue_microtask(JSContext *ctx, JSValue callee, JSValue this_val,
|
|
|
274
344
|
(void)callee, (void)this_val, (void)new_target;
|
|
275
345
|
JSValue fn = argc ? argv[0] : JS_UNDEFINED;
|
|
276
346
|
if (!js_is_callable(fn)) return js_throw_type_error(ctx, "The \"callback\" argument must be of type function");
|
|
277
|
-
JSJob job = { JS_JOB_CALLBACK, NULL, fn, JS_UNDEFINED, JS_UNDEFINED };
|
|
347
|
+
JSJob job = { JS_JOB_CALLBACK, NULL, fn, JS_UNDEFINED, JS_UNDEFINED, JS_UNDEFINED };
|
|
278
348
|
js_enqueue_microtask(ctx, &job);
|
|
279
349
|
return JS_UNDEFINED;
|
|
280
350
|
}
|
|
@@ -291,16 +361,22 @@ void js_jobs_realm_init(JSContext *ctx, JSObject *global) {
|
|
|
291
361
|
if (!t->now) t->now = js_os_now_ms(); /* the base of every timer the main script sets */
|
|
292
362
|
}
|
|
293
363
|
|
|
364
|
+
bool js_event_loop_alive(JSContext *ctx) {
|
|
365
|
+
JSRuntime *rt = ctx->rt;
|
|
366
|
+
return rt->timers.refed || (rt->io && rt->io->alive(rt));
|
|
367
|
+
}
|
|
368
|
+
|
|
294
369
|
/* One task per iteration, then a full checkpoint: promise callbacks always run before the
|
|
295
370
|
* next timer. The program ends when no timer is pending (unref'd ones don't count) and no I/O is. */
|
|
296
371
|
int js_run_event_loop(JSContext *ctx, JSValue main_result) {
|
|
297
|
-
if (js_is_exception(main_result)) return js_report_uncaught(ctx);
|
|
298
|
-
if (js_run_microtasks(ctx) < 0) return 1;
|
|
299
372
|
JSRuntime *rt = ctx->rt;
|
|
373
|
+
int status = js_is_exception(main_result) ? js_report_uncaught(ctx) : 0;
|
|
374
|
+
if (status) return status;
|
|
375
|
+
if (js_run_microtasks(ctx) < 0) return rt->failure;
|
|
300
376
|
JSTimers *t = &rt->timers;
|
|
301
|
-
while (
|
|
377
|
+
while (js_event_loop_alive(ctx)) {
|
|
302
378
|
/* FinalizationRegistry cleanups run between tasks; on their own they don't keep the program alive */
|
|
303
|
-
if (js_run_finalization_cleanups(ctx) < 0) return
|
|
379
|
+
if (js_run_finalization_cleanups(ctx) < 0) return rt->failure;
|
|
304
380
|
if (!t->count || t->heap[0].deadline > t->now) { /* nothing due at the cached time: refresh it, or wait */
|
|
305
381
|
t->now = js_os_now_ms();
|
|
306
382
|
if (!t->count || t->heap[0].deadline > t->now) {
|
|
@@ -310,7 +386,7 @@ int js_run_event_loop(JSContext *ctx, JSValue main_result) {
|
|
|
310
386
|
fflush(stderr);
|
|
311
387
|
/* I/O callbacks run while waiting, unref'd handles' too while a timer is pending */
|
|
312
388
|
if (rt->io && (timeout >= 0 || rt->io->alive(rt))) {
|
|
313
|
-
|
|
389
|
+
status = rt->io->run(ctx, timeout);
|
|
314
390
|
if (status) return status;
|
|
315
391
|
} else {
|
|
316
392
|
js_os_sleep_ms(t->heap[0].deadline - t->now); /* t->refed: a timer is pending */
|
|
@@ -323,16 +399,19 @@ int js_run_event_loop(JSContext *ctx, JSValue main_result) {
|
|
|
323
399
|
timer_remove(t, 0);
|
|
324
400
|
t->running = timer.repeat ? timer.id : 0;
|
|
325
401
|
t->running_cleared = 0;
|
|
402
|
+
JSValue saved = rt->async_context;
|
|
403
|
+
rt->async_context = timer.context;
|
|
326
404
|
JSValue r = js_is_undefined(timer.args) ? js_call(timer.realm, timer.fn, JS_UNDEFINED, 0, NULL)
|
|
327
405
|
: js_call_spread(timer.realm, timer.fn, JS_UNDEFINED, timer.args, NULL);
|
|
406
|
+
rt->async_context = saved;
|
|
328
407
|
t->running = 0;
|
|
329
|
-
if (js_is_exception(r)
|
|
408
|
+
if (js_is_exception(r) && (status = js_report_uncaught(timer.realm))) return status;
|
|
330
409
|
if (timer.repeat && !t->running_cleared) { /* re-armed after its callback, from the loop's time */
|
|
331
410
|
timer.deadline = t->now + timer.repeat;
|
|
332
411
|
timer.seq = t->seq++;
|
|
333
412
|
timer_push(t, &timer);
|
|
334
413
|
}
|
|
335
|
-
if (js_run_microtasks(ctx) < 0) return
|
|
414
|
+
if (js_run_microtasks(ctx) < 0) return rt->failure;
|
|
336
415
|
}
|
|
337
416
|
return 0;
|
|
338
417
|
}
|
package/runtime/src/jsnum.c
CHANGED
|
File without changes
|
package/runtime/src/json.c
CHANGED
|
File without changes
|
package/runtime/src/math.c
CHANGED
|
File without changes
|
package/runtime/src/module.c
CHANGED
|
File without changes
|
package/runtime/src/number.c
CHANGED
|
File without changes
|
package/runtime/src/object.c
CHANGED
|
File without changes
|
package/runtime/src/ops.c
CHANGED
|
File without changes
|
package/runtime/src/os.c
CHANGED
|
File without changes
|
package/runtime/src/os.h
CHANGED
|
File without changes
|
package/runtime/src/process.c
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* The global process (ADR 0012), natively: the command line, the environment, the exit
|
|
2
2
|
* status, standard output and error, and warnings. js_host_init installs it with console
|
|
3
|
-
* and global before the program runs.
|
|
3
|
+
* and global before the program runs. Its events ('beforeExit', 'exit') go through its emit,
|
|
4
|
+
* which it has once node/prelude/internal/process_events.js made it an EventEmitter. */
|
|
4
5
|
#define _XOPEN_SOURCE 700 /* getpid, isatty, realpath, environ under -std=c11 */
|
|
5
6
|
#include "js_host.h"
|
|
6
7
|
|
|
@@ -61,15 +62,88 @@ JSValue js_host_cwd(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t a
|
|
|
61
62
|
|
|
62
63
|
static int saved_argc;
|
|
63
64
|
static char **saved_argv;
|
|
65
|
+
static JSValue process_object; /* set by js_host_init, a root: the program may delete globalThis.process */
|
|
66
|
+
static bool exiting; /* 'exit' was emitted: process.exit() now just exits */
|
|
64
67
|
|
|
65
68
|
/* process.exitCode: undefined, null or an integer */
|
|
66
69
|
static enum { EXIT_UNSET, EXIT_NULL, EXIT_SET } exit_state;
|
|
67
70
|
static double exit_value;
|
|
68
71
|
|
|
69
|
-
int
|
|
72
|
+
static int exit_status(void) {
|
|
70
73
|
return exit_state == EXIT_SET ? (int)(int64_t)exit_value : 0;
|
|
71
74
|
}
|
|
72
75
|
|
|
76
|
+
/* process.emit(type, a[, b]): 1 if it had listeners, 0 if not or process has no emit (it isn't
|
|
77
|
+
* an EventEmitter: the program never names one of its methods), -1 after an exception. */
|
|
78
|
+
static int emit_event(JSContext *ctx, const char *type, uint32_t argc, JSValue a, JSValue b) {
|
|
79
|
+
JSValue emit = js_get_value(ctx, process_object, js_atom_from_cstr(ctx, "emit"));
|
|
80
|
+
if (js_is_exception(emit)) return -1;
|
|
81
|
+
if (!js_is_callable(emit)) return 0;
|
|
82
|
+
JSValue args[3] = { js_new_string_cstr(ctx, type), a, b };
|
|
83
|
+
if (js_is_exception(args[0])) return -1;
|
|
84
|
+
JSValue r = js_call(ctx, emit, process_object, argc + 1, args);
|
|
85
|
+
return js_is_exception(r) ? -1 : js_truthy(r);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* rt->on_uncaught: a rejection goes to 'unhandledRejection' (reason, promise); an error, or a
|
|
89
|
+
* rejection nobody listens for, to 'uncaughtException' (error, origin), as in Node. A
|
|
90
|
+
* listener's own error: an 'unhandledRejection' one's is uncaught, an 'uncaughtException'
|
|
91
|
+
* one's ends the program with status 7, without 'exit'. */
|
|
92
|
+
static int on_uncaught(JSContext *ctx, JSValue error, JSValue promise) {
|
|
93
|
+
const char *origin = "uncaughtException";
|
|
94
|
+
bool rethrown = false; /* error is an 'unhandledRejection' listener's */
|
|
95
|
+
if (!js_is_undefined(promise)) {
|
|
96
|
+
int had = emit_event(ctx, "unhandledRejection", 2, error, promise);
|
|
97
|
+
if (had > 0) return 0;
|
|
98
|
+
if (had == 0) origin = "unhandledRejection";
|
|
99
|
+
else {
|
|
100
|
+
error = js_take_exception(ctx);
|
|
101
|
+
rethrown = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
JSValue name = js_new_string_cstr(ctx, origin);
|
|
105
|
+
int had = js_is_exception(name) ? -1 : emit_event(ctx, "uncaughtException", 2, error, name);
|
|
106
|
+
if (had > 0) return 0;
|
|
107
|
+
if (had < 0) {
|
|
108
|
+
js_report_error(ctx, "Uncaught ", js_take_exception(ctx));
|
|
109
|
+
exiting = true;
|
|
110
|
+
return 7;
|
|
111
|
+
}
|
|
112
|
+
if (!rethrown) return -1;
|
|
113
|
+
js_report_error(ctx, "Uncaught ", error);
|
|
114
|
+
return 1;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* rt->on_handled_late: 'rejectionHandled' (promise) */
|
|
118
|
+
static int on_handled_late(JSContext *ctx, JSValue promise) {
|
|
119
|
+
return emit_event(ctx, "rejectionHandled", 1, promise, JS_UNDEFINED) < 0 ? -1 : 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* 'exit', with process.exitCode (0 when unset): once, whichever way the program ends. */
|
|
123
|
+
static int emit_exit(JSContext *ctx) {
|
|
124
|
+
if (exiting) return 0;
|
|
125
|
+
exiting = true;
|
|
126
|
+
return emit_event(ctx, "exit", 1, js_number(exit_state == EXIT_SET ? exit_value : 0), JS_UNDEFINED);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
int js_host_exit(JSContext *ctx, int status) {
|
|
130
|
+
/* 'beforeExit' each time the loop empties, while its listeners give it more to do */
|
|
131
|
+
while (status == 0) {
|
|
132
|
+
int had = emit_event(ctx, "beforeExit", 1, js_number(exit_state == EXIT_SET ? exit_value : 0), JS_UNDEFINED);
|
|
133
|
+
if (had == 0) break;
|
|
134
|
+
if (had < 0 && (status = js_report_uncaught(ctx))) break;
|
|
135
|
+
if (js_run_microtasks(ctx) < 0) status = ctx->rt->failure;
|
|
136
|
+
else if (!js_event_loop_alive(ctx)) break;
|
|
137
|
+
else status = js_run_event_loop(ctx, JS_UNDEFINED);
|
|
138
|
+
}
|
|
139
|
+
if (status != 0) { /* process.exitCode is the failure's status, as in Node */
|
|
140
|
+
exit_state = EXIT_SET;
|
|
141
|
+
exit_value = status;
|
|
142
|
+
}
|
|
143
|
+
if (emit_exit(ctx) < 0 && (status = js_report_uncaught(ctx))) return status;
|
|
144
|
+
return exit_status();
|
|
145
|
+
}
|
|
146
|
+
|
|
73
147
|
/* ---- Node's argument errors -------------------------------------------------------------- */
|
|
74
148
|
|
|
75
149
|
static JSValue throw_with_code(JSContext *ctx, JSErrorKind kind, const char *code, JSValue message) {
|
|
@@ -192,14 +266,15 @@ NATIVE(exit_code_set) {
|
|
|
192
266
|
return JS_UNDEFINED;
|
|
193
267
|
}
|
|
194
268
|
|
|
269
|
+
/* exit(code): process.exitCode = code (when given), 'exit' (unless it's running), then the end. */
|
|
195
270
|
NATIVE(process_exit) {
|
|
196
271
|
UNUSED_ARGS;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (
|
|
272
|
+
if (!js_is_undefined(ARG(0)) && js_is_exception(exit_code_set(ctx, JS_UNDEFINED, JS_UNDEFINED, 1, argv, JS_UNDEFINED)))
|
|
273
|
+
return JS_EXCEPTION;
|
|
274
|
+
if (emit_exit(ctx) < 0) (void)js_report_uncaught(ctx); /* the status stays the one asked for */
|
|
200
275
|
fflush(stdout);
|
|
201
276
|
fflush(stderr);
|
|
202
|
-
exit(
|
|
277
|
+
exit(exit_status());
|
|
203
278
|
}
|
|
204
279
|
|
|
205
280
|
NATIVE(process_cwd) {
|
|
@@ -220,7 +295,7 @@ NATIVE(process_next_tick) {
|
|
|
220
295
|
args = js_new_array_from(ctx, argv + 1, argc - 1);
|
|
221
296
|
if (js_is_exception(args)) return args;
|
|
222
297
|
}
|
|
223
|
-
JSJob job = { JS_JOB_CALLBACK, NULL, argv[0], args, JS_UNDEFINED };
|
|
298
|
+
JSJob job = { JS_JOB_CALLBACK, NULL, argv[0], args, JS_UNDEFINED, JS_UNDEFINED };
|
|
224
299
|
js_enqueue_microtask(ctx, &job);
|
|
225
300
|
return JS_UNDEFINED;
|
|
226
301
|
}
|
|
@@ -277,6 +352,11 @@ NATIVE(process_emit_warning) {
|
|
|
277
352
|
char small_name[128], small_code[128];
|
|
278
353
|
size_t n = js_view_to_utf8(js_string_view(ctx, name), small_name, sizeof small_name - 1);
|
|
279
354
|
small_name[n < sizeof small_name ? n : sizeof small_name - 1] = '\0';
|
|
355
|
+
if (strcmp(small_name, "DeprecationWarning") == 0 && js_is_object(process_object)) { /* silenced as the program runs, as in Node */
|
|
356
|
+
JSValue silenced = js_get_value(ctx, process_object, js_atom_from_cstr(ctx, "noDeprecation"));
|
|
357
|
+
if (js_is_exception(silenced)) return JS_EXCEPTION;
|
|
358
|
+
if (js_truthy(silenced)) return JS_UNDEFINED;
|
|
359
|
+
}
|
|
280
360
|
if (!js_is_undefined(code_str)) {
|
|
281
361
|
size_t c = js_view_to_utf8(js_string_view(ctx, code_str), small_code, sizeof small_code - 1);
|
|
282
362
|
small_code[c < sizeof small_code ? c : sizeof small_code - 1] = '\0';
|
|
@@ -292,7 +372,7 @@ static JSValue stream_write(JSContext *ctx, int fd, uint32_t argc, const JSValue
|
|
|
292
372
|
js_write_output(ctx, fd, s);
|
|
293
373
|
JSValue callback = js_is_callable(ARG(1)) ? ARG(1) : ARG(2);
|
|
294
374
|
if (js_is_callable(callback)) {
|
|
295
|
-
JSJob job = { JS_JOB_CALLBACK, NULL, callback, JS_UNDEFINED, JS_UNDEFINED };
|
|
375
|
+
JSJob job = { JS_JOB_CALLBACK, NULL, callback, JS_UNDEFINED, JS_UNDEFINED, JS_UNDEFINED };
|
|
296
376
|
js_enqueue_microtask(ctx, &job);
|
|
297
377
|
}
|
|
298
378
|
return JS_TRUE;
|
|
@@ -433,6 +513,10 @@ int js_host_init(JSContext *ctx, int argc, char **argv) {
|
|
|
433
513
|
js_define_data(ctx, g, js_atom_from_cstr(ctx, "console"), console, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
|
|
434
514
|
JSValue process = new_process(ctx);
|
|
435
515
|
if (js_is_exception(process)) return -1;
|
|
516
|
+
process_object = process;
|
|
517
|
+
js_add_root(ctx->rt, &process_object);
|
|
518
|
+
ctx->rt->on_uncaught = on_uncaught;
|
|
519
|
+
ctx->rt->on_handled_late = on_handled_late;
|
|
436
520
|
js_define_data(ctx, g, js_atom_from_cstr(ctx, "process"), process, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
|
|
437
521
|
js_define_data(ctx, g, js_atom_from_cstr(ctx, "global"), global, JS_PROP_DEFAULT);
|
|
438
522
|
return 0;
|
package/runtime/src/promise.c
CHANGED
|
@@ -74,6 +74,7 @@ typedef struct Reaction {
|
|
|
74
74
|
JSValue on_rejected; /* a function, or EMPTY: the reason passes through */
|
|
75
75
|
JSValue capability; /* the derived promise (settled directly), a Capability cell, or undefined */
|
|
76
76
|
JSValue next; /* the next (older) reaction, or undefined */
|
|
77
|
+
JSValue context; /* the async context of its then() or await, which its job runs under (ADR 0020) */
|
|
77
78
|
} Reaction;
|
|
78
79
|
|
|
79
80
|
static void reaction_visit(JSCell *c, JSTracer *trc) {
|
|
@@ -82,11 +83,12 @@ static void reaction_visit(JSCell *c, JSTracer *trc) {
|
|
|
82
83
|
js_trace_value(trc, r->on_rejected);
|
|
83
84
|
js_trace_value(trc, r->capability);
|
|
84
85
|
js_trace_value(trc, r->next);
|
|
86
|
+
js_trace_value(trc, r->context);
|
|
85
87
|
}
|
|
86
88
|
static const JSCellClass reaction_class = { "PromiseReaction", reaction_visit, NULL };
|
|
87
89
|
|
|
88
90
|
static void enqueue_reaction(JSContext *ctx, JSValue reaction, JSValue argument, int state) {
|
|
89
|
-
JSJob job = { JS_JOB_PROMISE_REACTION, NULL, reaction, argument, js_int32(state) };
|
|
91
|
+
JSJob job = { JS_JOB_PROMISE_REACTION, NULL, reaction, argument, js_int32(state), JS_UNDEFINED };
|
|
90
92
|
js_enqueue_microtask(ctx, &job);
|
|
91
93
|
}
|
|
92
94
|
|
|
@@ -130,7 +132,7 @@ static void resolve(JSContext *ctx, JSValue promise, JSValue resolution) {
|
|
|
130
132
|
settle(ctx, promise, JS_PROMISE_FULFILLED, resolution);
|
|
131
133
|
return;
|
|
132
134
|
}
|
|
133
|
-
JSJob job = { JS_JOB_RESOLVE_THENABLE, NULL, promise, resolution, then };
|
|
135
|
+
JSJob job = { JS_JOB_RESOLVE_THENABLE, NULL, promise, resolution, then, JS_UNDEFINED };
|
|
134
136
|
js_enqueue_microtask(ctx, &job);
|
|
135
137
|
}
|
|
136
138
|
|
|
@@ -284,6 +286,7 @@ static void perform_then(JSContext *ctx, JSValue promise, JSValue on_fulfilled,
|
|
|
284
286
|
js_init_slot(&r->on_rejected, js_is_callable(on_rejected) ? on_rejected : JS_EMPTY);
|
|
285
287
|
js_init_slot(&r->capability, capability);
|
|
286
288
|
js_init_slot(&r->next, JS_UNDEFINED);
|
|
289
|
+
js_init_slot(&r->context, ctx->rt->async_context);
|
|
287
290
|
add_reaction(ctx, promise, r);
|
|
288
291
|
}
|
|
289
292
|
|
|
@@ -298,6 +301,7 @@ void js_promise_await(JSContext *ctx, JSValue promise, JSValue gen) {
|
|
|
298
301
|
js_init_slot(&r->on_rejected, JS_EMPTY);
|
|
299
302
|
js_init_slot(&r->capability, JS_UNDEFINED);
|
|
300
303
|
js_init_slot(&r->next, JS_UNDEFINED);
|
|
304
|
+
js_init_slot(&r->context, ctx->rt->async_context);
|
|
301
305
|
add_reaction(ctx, promise, r);
|
|
302
306
|
}
|
|
303
307
|
|
|
@@ -318,6 +322,7 @@ static void add_reaction(JSContext *ctx, JSValue promise, Reaction *r) {
|
|
|
318
322
|
* a throwing resolve or reject of a foreign capability escapes, as an uncaught error. */
|
|
319
323
|
int js_promise_reaction_job(JSContext *ctx, JSValue reaction, JSValue argument, JSValue state) {
|
|
320
324
|
Reaction *r = (Reaction *)js_as_cell(reaction);
|
|
325
|
+
ctx->rt->async_context = r->context; /* run_job restores the one before */
|
|
321
326
|
bool rejected = js_as_int32(state) == JS_PROMISE_REJECTED;
|
|
322
327
|
if (r->kind == REACTION_AWAIT) { /* resume the async call; its outcome settles its own promise */
|
|
323
328
|
js_async_resume(ctx, js_as_generator(r->on_fulfilled), argument, rejected ? JS_RESUME_THROW : JS_RESUME_NEXT);
|
package/runtime/src/proxy.c
CHANGED
|
File without changes
|
package/runtime/src/reflect.c
CHANGED
|
File without changes
|
package/runtime/src/regexp.c
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/runtime/src/shape.c
CHANGED
|
File without changes
|
package/runtime/src/shape.h
CHANGED
|
File without changes
|
package/runtime/src/streams.c
CHANGED
|
File without changes
|
package/runtime/src/streams.h
CHANGED
|
File without changes
|
package/runtime/src/string.c
CHANGED
|
File without changes
|
|
File without changes
|
package/runtime/src/symbol.c
CHANGED
|
File without changes
|
package/runtime/src/test_host.c
CHANGED
|
File without changes
|
package/runtime/src/typedarray.c
CHANGED
|
File without changes
|
|
File without changes
|
package/runtime/src/uri.c
CHANGED
|
File without changes
|
package/runtime/src/url.c
CHANGED
|
File without changes
|
package/runtime/src/weak.c
CHANGED
|
@@ -380,10 +380,7 @@ int js_run_finalization_cleanups(JSContext *ctx) {
|
|
|
380
380
|
if (o->shape->cls != ®istry_class || !((Registry *)o)->pending) continue;
|
|
381
381
|
Registry *r = (Registry *)o;
|
|
382
382
|
JSValue keep = js_object_value(o); /* a callback may drop the last reference */
|
|
383
|
-
if (cleanup_registry(r) < 0)
|
|
384
|
-
js_report_uncaught(r->realm);
|
|
385
|
-
return -1;
|
|
386
|
-
}
|
|
383
|
+
if (cleanup_registry(r) < 0 && js_report_uncaught(r->realm)) return -1;
|
|
387
384
|
js_keep_alive(keep);
|
|
388
385
|
if (js_run_microtasks(ctx) < 0) return -1;
|
|
389
386
|
}
|
package/runtime/src/web.c
CHANGED
|
File without changes
|
package/runtime/src/wrapper.c
CHANGED
|
File without changes
|
package/runtime/src/writable.c
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|