visaljs 0.0.5 → 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 +2 -3
- 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
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/* Host primitives for node:zlib (ADR 0012): Node's zlib binding (src/node_zlib.cc, its
|
|
2
|
+
* ZlibContext) over Chromium's zlib, the copy Node vendors, so a program compresses to the bytes
|
|
3
|
+
* Node gives. A stream is a handle object; the prelude (node/prelude/zlib.js) is Node's lib/zlib.js
|
|
4
|
+
* on these, and runs a write's callback a turn later, where Node's thread pool would. A failure is
|
|
5
|
+
* returned as [message, errno, code], what Node's binding passes to the stream's onerror. */
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <string.h>
|
|
8
|
+
|
|
9
|
+
#include "js_buffer.h"
|
|
10
|
+
#include "js_exception.h"
|
|
11
|
+
#include "js_node.h"
|
|
12
|
+
#include "js_object.h"
|
|
13
|
+
#include "js_ops.h"
|
|
14
|
+
#include "jsstring.h"
|
|
15
|
+
#include "zlib.h"
|
|
16
|
+
|
|
17
|
+
#define PRIMITIVE(fn) \
|
|
18
|
+
JSValue fn(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target)
|
|
19
|
+
#define UNUSED_PRIMITIVE_ARGS (void)callee, (void)this_val, (void)new_target
|
|
20
|
+
#define ARG(i) ((i) < argc ? argv[i] : JS_UNDEFINED)
|
|
21
|
+
|
|
22
|
+
/* Node's node_zlib_mode */
|
|
23
|
+
enum { NONE, DEFLATE, INFLATE, GZIP, GUNZIP, DEFLATERAW, INFLATERAW, UNZIP };
|
|
24
|
+
|
|
25
|
+
#define GZIP_HEADER_ID1 0x1f
|
|
26
|
+
#define GZIP_HEADER_ID2 0x8b
|
|
27
|
+
|
|
28
|
+
typedef struct ZlibObject {
|
|
29
|
+
JSObject obj;
|
|
30
|
+
z_stream strm;
|
|
31
|
+
int mode;
|
|
32
|
+
int level, window_bits, mem_level, strategy;
|
|
33
|
+
int flush;
|
|
34
|
+
int err;
|
|
35
|
+
int gzip_id_bytes_read;
|
|
36
|
+
bool zlib_init_done;
|
|
37
|
+
uint8_t *dictionary; /* malloc'd; NULL when empty */
|
|
38
|
+
size_t dictionary_len;
|
|
39
|
+
} ZlibObject;
|
|
40
|
+
|
|
41
|
+
static void zlib_end(ZlibObject *z) {
|
|
42
|
+
if (z->zlib_init_done) {
|
|
43
|
+
if (z->mode == DEFLATE || z->mode == GZIP || z->mode == DEFLATERAW) deflateEnd(&z->strm);
|
|
44
|
+
else if (z->mode >= INFLATE) inflateEnd(&z->strm);
|
|
45
|
+
z->zlib_init_done = false;
|
|
46
|
+
}
|
|
47
|
+
z->mode = NONE;
|
|
48
|
+
free(z->dictionary);
|
|
49
|
+
z->dictionary = NULL;
|
|
50
|
+
z->dictionary_len = 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static void zlib_finalize(JSRuntime *rt, JSCell *cell) {
|
|
54
|
+
(void)rt;
|
|
55
|
+
zlib_end((ZlibObject *)cell);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static const JSClass zlib_class = { "Zlib", sizeof(ZlibObject), NULL, NULL, NULL, NULL, NULL, zlib_finalize, NULL };
|
|
59
|
+
|
|
60
|
+
static ZlibObject *zlib_arg(JSValue v) {
|
|
61
|
+
return js_is_object(v) && js_as_object(v)->shape->cls == &zlib_class ? (ZlibObject *)js_as_object(v) : NULL;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static int int_arg(JSValue v) { return js_is_number(v) ? (int)js_as_number(v) : 0; }
|
|
65
|
+
|
|
66
|
+
static const char *zlib_strerror(int err) {
|
|
67
|
+
switch (err) {
|
|
68
|
+
case Z_OK: return "Z_OK";
|
|
69
|
+
case Z_STREAM_END: return "Z_STREAM_END";
|
|
70
|
+
case Z_NEED_DICT: return "Z_NEED_DICT";
|
|
71
|
+
case Z_ERRNO: return "Z_ERRNO";
|
|
72
|
+
case Z_STREAM_ERROR: return "Z_STREAM_ERROR";
|
|
73
|
+
case Z_DATA_ERROR: return "Z_DATA_ERROR";
|
|
74
|
+
case Z_MEM_ERROR: return "Z_MEM_ERROR";
|
|
75
|
+
case Z_BUF_ERROR: return "Z_BUF_ERROR";
|
|
76
|
+
case Z_VERSION_ERROR: return "Z_VERSION_ERROR";
|
|
77
|
+
default: return "Z_UNKNOWN_ERROR";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* ErrorForMessage: zlib's own message when it has one. */
|
|
82
|
+
static JSValue failure(JSContext *ctx, ZlibObject *z, const char *message) {
|
|
83
|
+
if (z->strm.msg) message = z->strm.msg;
|
|
84
|
+
JSValue items[3] = { js_new_string_cstr(ctx, message), js_int32(z->err), js_new_string_cstr(ctx, zlib_strerror(z->err)) };
|
|
85
|
+
JSValue a = js_new_array(ctx, 3);
|
|
86
|
+
for (int i = 0; i < 3; i++)
|
|
87
|
+
if (js_array_append(ctx, a, items[i]) < 0) return JS_EXCEPTION;
|
|
88
|
+
return a;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static int set_dictionary(ZlibObject *z) {
|
|
92
|
+
if (!z->dictionary) return Z_OK;
|
|
93
|
+
z->err = Z_OK;
|
|
94
|
+
if (z->mode == DEFLATE || z->mode == DEFLATERAW) z->err = deflateSetDictionary(&z->strm, z->dictionary, (uInt)z->dictionary_len);
|
|
95
|
+
/* the other inflates set it when inflate() asks for it */
|
|
96
|
+
else if (z->mode == INFLATERAW) z->err = inflateSetDictionary(&z->strm, z->dictionary, (uInt)z->dictionary_len);
|
|
97
|
+
return z->err;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* InitZlib: true on the first call (z->err then tells whether it worked). */
|
|
101
|
+
static bool init_zlib(ZlibObject *z) {
|
|
102
|
+
if (z->zlib_init_done) return false;
|
|
103
|
+
switch (z->mode) {
|
|
104
|
+
case DEFLATE: case GZIP: case DEFLATERAW:
|
|
105
|
+
z->err = deflateInit2(&z->strm, z->level, Z_DEFLATED, z->window_bits, z->mem_level, z->strategy);
|
|
106
|
+
break;
|
|
107
|
+
case INFLATE: case GUNZIP: case INFLATERAW: case UNZIP:
|
|
108
|
+
z->err = inflateInit2(&z->strm, z->window_bits);
|
|
109
|
+
break;
|
|
110
|
+
default:
|
|
111
|
+
z->err = Z_STREAM_ERROR;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
if (z->err != Z_OK) {
|
|
115
|
+
free(z->dictionary);
|
|
116
|
+
z->dictionary = NULL;
|
|
117
|
+
z->dictionary_len = 0;
|
|
118
|
+
z->mode = NONE;
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
set_dictionary(z);
|
|
122
|
+
z->zlib_init_done = true;
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static int reset_stream(ZlibObject *z) {
|
|
127
|
+
z->err = Z_OK;
|
|
128
|
+
switch (z->mode) {
|
|
129
|
+
case DEFLATE: case DEFLATERAW: case GZIP: z->err = deflateReset(&z->strm); break;
|
|
130
|
+
case INFLATE: case INFLATERAW: case GUNZIP: z->err = inflateReset(&z->strm); break;
|
|
131
|
+
default: break;
|
|
132
|
+
}
|
|
133
|
+
return z->err;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* DoThreadPoolWork: one deflate or inflate over the buffers set. */
|
|
137
|
+
static void process(ZlibObject *z) {
|
|
138
|
+
if (init_zlib(z) && z->err != Z_OK) return;
|
|
139
|
+
const Bytef *next_header_byte = NULL;
|
|
140
|
+
switch (z->mode) {
|
|
141
|
+
case DEFLATE: case GZIP: case DEFLATERAW:
|
|
142
|
+
z->err = deflate(&z->strm, z->flush);
|
|
143
|
+
return;
|
|
144
|
+
case UNZIP:
|
|
145
|
+
if (z->strm.avail_in > 0) next_header_byte = z->strm.next_in;
|
|
146
|
+
if (z->gzip_id_bytes_read == 0 && next_header_byte) {
|
|
147
|
+
if (*next_header_byte == GZIP_HEADER_ID1) {
|
|
148
|
+
z->gzip_id_bytes_read = 1;
|
|
149
|
+
next_header_byte++;
|
|
150
|
+
if (z->strm.avail_in == 1) next_header_byte = NULL; /* the only byte was read */
|
|
151
|
+
} else {
|
|
152
|
+
z->mode = INFLATE;
|
|
153
|
+
next_header_byte = NULL;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (z->gzip_id_bytes_read == 1 && next_header_byte) {
|
|
157
|
+
if (*next_header_byte == GZIP_HEADER_ID2) {
|
|
158
|
+
z->gzip_id_bytes_read = 2;
|
|
159
|
+
z->mode = GUNZIP;
|
|
160
|
+
} else {
|
|
161
|
+
z->mode = INFLATE; /* INFLATE and INFLATERAW are the same once initialized */
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/* fall through */
|
|
165
|
+
case INFLATE: case GUNZIP: case INFLATERAW:
|
|
166
|
+
z->err = inflate(&z->strm, z->flush);
|
|
167
|
+
if (z->mode != INFLATERAW && z->err == Z_NEED_DICT && z->dictionary) {
|
|
168
|
+
z->err = inflateSetDictionary(&z->strm, z->dictionary, (uInt)z->dictionary_len);
|
|
169
|
+
if (z->err == Z_OK) z->err = inflate(&z->strm, z->flush);
|
|
170
|
+
else if (z->err == Z_DATA_ERROR) z->err = Z_NEED_DICT; /* a bad dictionary, not bad input */
|
|
171
|
+
}
|
|
172
|
+
/* bytes after a gzip member: another member, or trailing garbage (zeros are padding) */
|
|
173
|
+
while (z->strm.avail_in > 0 && z->mode == GUNZIP && z->err == Z_STREAM_END && z->strm.next_in[0] != 0x00) {
|
|
174
|
+
reset_stream(z);
|
|
175
|
+
z->err = inflate(&z->strm, z->flush);
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
default:
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/* GetErrorInfo: NULL when the stream's state is fine. */
|
|
184
|
+
static const char *error_message(ZlibObject *z) {
|
|
185
|
+
switch (z->err) {
|
|
186
|
+
case Z_OK:
|
|
187
|
+
case Z_BUF_ERROR:
|
|
188
|
+
if (z->strm.avail_out != 0 && z->flush == Z_FINISH) return "unexpected end of file";
|
|
189
|
+
return NULL;
|
|
190
|
+
case Z_STREAM_END:
|
|
191
|
+
return NULL;
|
|
192
|
+
case Z_NEED_DICT:
|
|
193
|
+
return z->dictionary ? "Bad dictionary" : "Missing dictionary";
|
|
194
|
+
default:
|
|
195
|
+
return "Zlib error";
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* zlibNew(mode) → handle */
|
|
200
|
+
PRIMITIVE(js_host_zlib_new) {
|
|
201
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
202
|
+
ZlibObject *z = (ZlibObject *)js_alloc_object(ctx, JS_CELL_OBJECT, js_shape_root(ctx, &zlib_class, JS_NULL, 0));
|
|
203
|
+
memset(&z->strm, 0, sizeof z->strm);
|
|
204
|
+
z->mode = int_arg(ARG(0));
|
|
205
|
+
z->flush = Z_NO_FLUSH;
|
|
206
|
+
z->err = Z_OK;
|
|
207
|
+
z->gzip_id_bytes_read = 0;
|
|
208
|
+
z->zlib_init_done = false;
|
|
209
|
+
z->dictionary = NULL;
|
|
210
|
+
z->dictionary_len = 0;
|
|
211
|
+
return js_object_value(&z->obj);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* zlibInit(handle, windowBits, level, memLevel, strategy, dictionary | undefined): checked by the
|
|
215
|
+
* prelude, as Node's lib/zlib.js checks them; zlib itself starts on the first write. */
|
|
216
|
+
PRIMITIVE(js_host_zlib_init) {
|
|
217
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
218
|
+
ZlibObject *z = zlib_arg(ARG(0));
|
|
219
|
+
if (!z) return js_throw_type_error(ctx, "zlibInit: a handle expected");
|
|
220
|
+
z->window_bits = int_arg(ARG(1));
|
|
221
|
+
z->level = int_arg(ARG(2));
|
|
222
|
+
z->mem_level = int_arg(ARG(3));
|
|
223
|
+
z->strategy = int_arg(ARG(4));
|
|
224
|
+
z->flush = Z_NO_FLUSH;
|
|
225
|
+
z->err = Z_OK;
|
|
226
|
+
if (z->mode == GZIP || z->mode == GUNZIP) z->window_bits += 16;
|
|
227
|
+
if (z->mode == UNZIP) z->window_bits += 32;
|
|
228
|
+
if (z->mode == DEFLATERAW || z->mode == INFLATERAW) z->window_bits *= -1;
|
|
229
|
+
uint8_t *p;
|
|
230
|
+
size_t n;
|
|
231
|
+
if (js_buffer_source_bytes(ARG(5), &p, &n) && n > 0) {
|
|
232
|
+
z->dictionary = malloc(n);
|
|
233
|
+
if (!z->dictionary) js_fatal("out of memory in zlib");
|
|
234
|
+
memcpy(z->dictionary, p, n);
|
|
235
|
+
z->dictionary_len = n;
|
|
236
|
+
}
|
|
237
|
+
return JS_UNDEFINED;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/* zlibWrite(handle, flush, in | null, inOff, inLen, out, outOff, outLen, state) → 0, with state
|
|
241
|
+
* [availOut, availIn] after it, or a failure */
|
|
242
|
+
PRIMITIVE(js_host_zlib_write) {
|
|
243
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
244
|
+
ZlibObject *z = zlib_arg(ARG(0));
|
|
245
|
+
uint8_t *in = NULL, *out, *state;
|
|
246
|
+
size_t in_n = 0, out_n, state_n;
|
|
247
|
+
if (!z || (!js_is_null(ARG(2)) && !js_buffer_source_bytes(ARG(2), &in, &in_n)) || !js_buffer_source_bytes(ARG(5), &out, &out_n)
|
|
248
|
+
|| !js_buffer_source_bytes(ARG(8), &state, &state_n) || state_n < 2 * sizeof(uint32_t))
|
|
249
|
+
return js_throw_type_error(ctx, "zlibWrite: a handle, buffers and a state expected");
|
|
250
|
+
double in_off = in ? js_as_number(ARG(3)) : 0, in_len = in ? js_as_number(ARG(4)) : 0;
|
|
251
|
+
double out_off = js_as_number(ARG(6)), out_len = js_as_number(ARG(7));
|
|
252
|
+
if (!(in_off >= 0 && in_len >= 0 && in_off + in_len <= (double)in_n && out_off >= 0 && out_len >= 0 && out_off + out_len <= (double)out_n))
|
|
253
|
+
return js_throw_range_error(ctx, "zlibWrite: out of bounds");
|
|
254
|
+
z->strm.next_in = in ? in + (size_t)in_off : NULL;
|
|
255
|
+
z->strm.avail_in = (uInt)in_len;
|
|
256
|
+
z->strm.next_out = out + (size_t)out_off;
|
|
257
|
+
z->strm.avail_out = (uInt)out_len;
|
|
258
|
+
z->flush = int_arg(ARG(1));
|
|
259
|
+
process(z);
|
|
260
|
+
const char *message = error_message(z);
|
|
261
|
+
if (message) return failure(ctx, z, message);
|
|
262
|
+
uint32_t result[2] = { z->strm.avail_out, z->strm.avail_in };
|
|
263
|
+
memcpy(state, result, sizeof result);
|
|
264
|
+
return js_int32(0);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/* zlibParams(handle, level, strategy) → 0 | failure */
|
|
268
|
+
PRIMITIVE(js_host_zlib_params) {
|
|
269
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
270
|
+
ZlibObject *z = zlib_arg(ARG(0));
|
|
271
|
+
if (!z) return js_throw_type_error(ctx, "zlibParams: a handle expected");
|
|
272
|
+
if (init_zlib(z) && z->err != Z_OK) return failure(ctx, z, "Failed to init stream before set parameters");
|
|
273
|
+
z->err = Z_OK;
|
|
274
|
+
if (z->mode == DEFLATE || z->mode == DEFLATERAW) z->err = deflateParams(&z->strm, int_arg(ARG(1)), int_arg(ARG(2)));
|
|
275
|
+
if (z->err != Z_OK && z->err != Z_BUF_ERROR) return failure(ctx, z, "Failed to set parameters");
|
|
276
|
+
return js_int32(0);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/* zlibReset(handle) → 0 | failure */
|
|
280
|
+
PRIMITIVE(js_host_zlib_reset) {
|
|
281
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
282
|
+
ZlibObject *z = zlib_arg(ARG(0));
|
|
283
|
+
if (!z) return js_throw_type_error(ctx, "zlibReset: a handle expected");
|
|
284
|
+
if (init_zlib(z) && z->err != Z_OK) return failure(ctx, z, "Failed to init stream before reset");
|
|
285
|
+
if (reset_stream(z) != Z_OK) return failure(ctx, z, "Failed to reset stream");
|
|
286
|
+
if (set_dictionary(z) != Z_OK) return failure(ctx, z, "Failed to set dictionary");
|
|
287
|
+
return js_int32(0);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/* zlibClose(handle): zlib's memory, now */
|
|
291
|
+
PRIMITIVE(js_host_zlib_close) {
|
|
292
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
293
|
+
ZlibObject *z = zlib_arg(ARG(0));
|
|
294
|
+
if (z) zlib_end(z);
|
|
295
|
+
return JS_UNDEFINED;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/* zlibCrc32(data, value): a string's UTF-8, or the bytes */
|
|
299
|
+
PRIMITIVE(js_host_zlib_crc32) {
|
|
300
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
301
|
+
uLong value = js_is_number(ARG(1)) ? (uLong)js_as_number(ARG(1)) : 0;
|
|
302
|
+
uint8_t *p;
|
|
303
|
+
size_t n;
|
|
304
|
+
if (js_buffer_source_bytes(ARG(0), &p, &n)) return js_number((double)crc32(value, p, (uInt)n));
|
|
305
|
+
if (!js_is_string(ARG(0))) return js_throw_type_error(ctx, "zlibCrc32: a string or bytes expected");
|
|
306
|
+
JSStrView view = js_string_view(ctx, ARG(0));
|
|
307
|
+
size_t len = js_view_to_utf8(view, NULL, 0);
|
|
308
|
+
char *utf8 = malloc(len ? len : 1);
|
|
309
|
+
if (!utf8) js_fatal("out of memory in zlib");
|
|
310
|
+
js_view_to_utf8(view, utf8, len);
|
|
311
|
+
value = crc32(value, (const Bytef *)utf8, (uInt)len);
|
|
312
|
+
free(utf8);
|
|
313
|
+
return js_number((double)value);
|
|
314
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/* Host primitives for node:zlib's zstd streams (ADR 0012): Node's binding (src/node_zlib.cc, its
|
|
2
|
+
* ZstdCompressContext and ZstdDecompressContext) over zstd 1.5.7, the copy Node vendors. As
|
|
3
|
+
* host_zlib.c: a stream is a handle object, and a failure is [message, errno, code]. */
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include <string.h>
|
|
6
|
+
|
|
7
|
+
#include "js_buffer.h"
|
|
8
|
+
#include "js_exception.h"
|
|
9
|
+
#include "js_node.h"
|
|
10
|
+
#include "js_object.h"
|
|
11
|
+
#include "js_ops.h"
|
|
12
|
+
#include "jsstring.h"
|
|
13
|
+
#include "zstd.h"
|
|
14
|
+
#include "zstd_errors.h"
|
|
15
|
+
|
|
16
|
+
#define PRIMITIVE(fn) \
|
|
17
|
+
JSValue fn(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target)
|
|
18
|
+
#define UNUSED_PRIMITIVE_ARGS (void)callee, (void)this_val, (void)new_target
|
|
19
|
+
#define ARG(i) ((i) < argc ? argv[i] : JS_UNDEFINED)
|
|
20
|
+
|
|
21
|
+
typedef struct ZstdObject {
|
|
22
|
+
JSObject obj;
|
|
23
|
+
bool compress;
|
|
24
|
+
ZSTD_CCtx *cctx;
|
|
25
|
+
ZSTD_DCtx *dctx;
|
|
26
|
+
unsigned long long pledged_src_size;
|
|
27
|
+
int flush;
|
|
28
|
+
ZSTD_ErrorCode error; /* the first failure stays, as in Node */
|
|
29
|
+
} ZstdObject;
|
|
30
|
+
|
|
31
|
+
static void zstd_end(ZstdObject *z) {
|
|
32
|
+
ZSTD_freeCCtx(z->cctx);
|
|
33
|
+
ZSTD_freeDCtx(z->dctx);
|
|
34
|
+
z->cctx = NULL;
|
|
35
|
+
z->dctx = NULL;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static void zstd_finalize(JSRuntime *rt, JSCell *cell) {
|
|
39
|
+
(void)rt;
|
|
40
|
+
zstd_end((ZstdObject *)cell);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static const JSClass zstd_class = { "ZstdHandle", sizeof(ZstdObject), NULL, NULL, NULL, NULL, NULL, zstd_finalize, NULL };
|
|
44
|
+
|
|
45
|
+
static ZstdObject *zstd_arg(JSValue v) {
|
|
46
|
+
return js_is_object(v) && js_as_object(v)->shape->cls == &zstd_class ? (ZstdObject *)js_as_object(v) : NULL;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static JSValue failure(JSContext *ctx, const char *message, int err, const char *code) {
|
|
50
|
+
JSValue items[3] = { js_new_string_cstr(ctx, message), js_int32(err), js_new_string_cstr(ctx, code) };
|
|
51
|
+
JSValue a = js_new_array(ctx, 3);
|
|
52
|
+
for (int i = 0; i < 3; i++)
|
|
53
|
+
if (js_array_append(ctx, a, items[i]) < 0) return JS_EXCEPTION;
|
|
54
|
+
return a;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* Node's ZstdStrerror: the error's name in zstd_errors.h */
|
|
58
|
+
static const char *zstd_strerror(ZSTD_ErrorCode e) {
|
|
59
|
+
switch (e) {
|
|
60
|
+
#define V(code) case code: return #code;
|
|
61
|
+
V(ZSTD_error_no_error) V(ZSTD_error_GENERIC) V(ZSTD_error_prefix_unknown) V(ZSTD_error_version_unsupported)
|
|
62
|
+
V(ZSTD_error_frameParameter_unsupported) V(ZSTD_error_frameParameter_windowTooLarge) V(ZSTD_error_corruption_detected)
|
|
63
|
+
V(ZSTD_error_checksum_wrong) V(ZSTD_error_literals_headerWrong) V(ZSTD_error_dictionary_corrupted)
|
|
64
|
+
V(ZSTD_error_dictionary_wrong) V(ZSTD_error_dictionaryCreation_failed) V(ZSTD_error_parameter_unsupported)
|
|
65
|
+
V(ZSTD_error_parameter_combination_unsupported) V(ZSTD_error_parameter_outOfBound) V(ZSTD_error_tableLog_tooLarge)
|
|
66
|
+
V(ZSTD_error_maxSymbolValue_tooLarge) V(ZSTD_error_maxSymbolValue_tooSmall) V(ZSTD_error_stabilityCondition_notRespected)
|
|
67
|
+
V(ZSTD_error_stage_wrong) V(ZSTD_error_init_missing) V(ZSTD_error_memory_allocation) V(ZSTD_error_workSpace_tooSmall)
|
|
68
|
+
V(ZSTD_error_dstSize_tooSmall) V(ZSTD_error_srcSize_wrong) V(ZSTD_error_dstBuffer_null)
|
|
69
|
+
V(ZSTD_error_noForwardProgress_destFull) V(ZSTD_error_noForwardProgress_inputEmpty)
|
|
70
|
+
#undef V
|
|
71
|
+
default: return "ZSTD_error_GENERIC";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Init: a new context (ResetStream is Init again, without the dictionary or the parameters, as in
|
|
76
|
+
* Node). NULL, or the failure's message and code. */
|
|
77
|
+
static const char *zstd_init(ZstdObject *z, const uint8_t *dictionary, size_t dictionary_len, const char **code) {
|
|
78
|
+
zstd_end(z);
|
|
79
|
+
*code = "ERR_ZLIB_INITIALIZATION_FAILED";
|
|
80
|
+
if (z->compress) {
|
|
81
|
+
if (!(z->cctx = ZSTD_createCCtx())) return "Could not initialize zstd instance";
|
|
82
|
+
if (dictionary_len && ZSTD_isError(ZSTD_CCtx_loadDictionary(z->cctx, dictionary, dictionary_len))) {
|
|
83
|
+
*code = "ERR_ZLIB_DICTIONARY_LOAD_FAILED";
|
|
84
|
+
return "Failed to load zstd dictionary";
|
|
85
|
+
}
|
|
86
|
+
if (ZSTD_isError(ZSTD_CCtx_setPledgedSrcSize(z->cctx, z->pledged_src_size))) return "Could not set pledged src size";
|
|
87
|
+
} else {
|
|
88
|
+
if (!(z->dctx = ZSTD_createDCtx())) return "Could not initialize zstd instance";
|
|
89
|
+
if (dictionary_len && ZSTD_isError(ZSTD_DCtx_loadDictionary(z->dctx, dictionary, dictionary_len))) {
|
|
90
|
+
*code = "ERR_ZLIB_DICTIONARY_LOAD_FAILED";
|
|
91
|
+
return "Failed to load zstd dictionary";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return NULL;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* zstdNew(compress) → handle */
|
|
98
|
+
PRIMITIVE(js_host_zstd_new) {
|
|
99
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
100
|
+
ZstdObject *z = (ZstdObject *)js_alloc_object(ctx, JS_CELL_OBJECT, js_shape_root(ctx, &zstd_class, JS_NULL, 0));
|
|
101
|
+
z->compress = js_truthy(ARG(0));
|
|
102
|
+
z->cctx = NULL;
|
|
103
|
+
z->dctx = NULL;
|
|
104
|
+
z->pledged_src_size = ZSTD_CONTENTSIZE_UNKNOWN;
|
|
105
|
+
z->flush = ZSTD_e_continue;
|
|
106
|
+
z->error = ZSTD_error_no_error;
|
|
107
|
+
return js_object_value(&z->obj);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* zstdInit(handle, params, pledgedSrcSize | undefined, dictionary | undefined): params a
|
|
111
|
+
* Uint32Array, by parameter number, 0xffffffff unset; the prelude checked pledgedSrcSize →
|
|
112
|
+
* 0 | failure */
|
|
113
|
+
PRIMITIVE(js_host_zstd_init) {
|
|
114
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
115
|
+
ZstdObject *z = zstd_arg(ARG(0));
|
|
116
|
+
uint8_t *p, *dict = NULL;
|
|
117
|
+
size_t n, dict_len = 0;
|
|
118
|
+
if (!z || !js_buffer_source_bytes(ARG(1), &p, &n)) return js_throw_type_error(ctx, "zstdInit: a handle and parameters expected");
|
|
119
|
+
if (js_is_number(ARG(2))) z->pledged_src_size = (unsigned long long)js_as_number(ARG(2));
|
|
120
|
+
if (!js_is_undefined(ARG(3))) js_buffer_source_bytes(ARG(3), &dict, &dict_len);
|
|
121
|
+
const char *code;
|
|
122
|
+
const char *message = zstd_init(z, dict, dict_len, &code);
|
|
123
|
+
if (message) return failure(ctx, message, -1, code);
|
|
124
|
+
for (size_t i = 0; i < n / sizeof(uint32_t); i++) {
|
|
125
|
+
uint32_t value;
|
|
126
|
+
memcpy(&value, p + i * sizeof value, sizeof value);
|
|
127
|
+
if (value == UINT32_MAX) continue;
|
|
128
|
+
size_t r = z->compress ? ZSTD_CCtx_setParameter(z->cctx, (ZSTD_cParameter)i, (int)value)
|
|
129
|
+
: ZSTD_DCtx_setParameter(z->dctx, (ZSTD_dParameter)i, (int)value);
|
|
130
|
+
if (ZSTD_isError(r)) return failure(ctx, "Setting parameter failed", -1, "ERR_ZSTD_PARAM_SET_FAILED");
|
|
131
|
+
}
|
|
132
|
+
return js_int32(0);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* zstdWrite(handle, flush, in | null, inOff, inLen, out, outOff, outLen, state) → 0, with state
|
|
136
|
+
* [availOut, availIn] after it, or a failure */
|
|
137
|
+
PRIMITIVE(js_host_zstd_write) {
|
|
138
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
139
|
+
ZstdObject *z = zstd_arg(ARG(0));
|
|
140
|
+
uint8_t *in = NULL, *out, *state;
|
|
141
|
+
size_t in_n = 0, out_n, state_n;
|
|
142
|
+
if (!z || (!z->cctx && !z->dctx) || (!js_is_null(ARG(2)) && !js_buffer_source_bytes(ARG(2), &in, &in_n))
|
|
143
|
+
|| !js_buffer_source_bytes(ARG(5), &out, &out_n) || !js_buffer_source_bytes(ARG(8), &state, &state_n) || state_n < 2 * sizeof(uint32_t))
|
|
144
|
+
return js_throw_type_error(ctx, "zstdWrite: a handle, buffers and a state expected");
|
|
145
|
+
double in_off = in ? js_as_number(ARG(3)) : 0, in_len = in ? js_as_number(ARG(4)) : 0;
|
|
146
|
+
double out_off = js_as_number(ARG(6)), out_len = js_as_number(ARG(7));
|
|
147
|
+
if (!(in_off >= 0 && in_len >= 0 && in_off + in_len <= (double)in_n && out_off >= 0 && out_len >= 0 && out_off + out_len <= (double)out_n))
|
|
148
|
+
return js_throw_range_error(ctx, "zstdWrite: out of bounds");
|
|
149
|
+
ZSTD_inBuffer input = { in ? in + (size_t)in_off : NULL, (size_t)in_len, 0 };
|
|
150
|
+
ZSTD_outBuffer output = { out + (size_t)out_off, (size_t)out_len, 0 };
|
|
151
|
+
z->flush = js_is_number(ARG(1)) ? (int)js_as_number(ARG(1)) : ZSTD_e_continue;
|
|
152
|
+
size_t r = z->compress ? ZSTD_compressStream2(z->cctx, &output, &input, (ZSTD_EndDirective)z->flush)
|
|
153
|
+
: ZSTD_decompressStream(z->dctx, &output, &input);
|
|
154
|
+
if (ZSTD_isError(r)) z->error = ZSTD_getErrorCode(r);
|
|
155
|
+
if (z->error != ZSTD_error_no_error) return failure(ctx, ZSTD_getErrorString(z->error), (int)z->error, zstd_strerror(z->error));
|
|
156
|
+
uint32_t result[2] = { (uint32_t)(output.size - output.pos), (uint32_t)(input.size - input.pos) };
|
|
157
|
+
memcpy(state, result, sizeof result);
|
|
158
|
+
return js_int32(0);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* zstdReset(handle) → 0 | failure */
|
|
162
|
+
PRIMITIVE(js_host_zstd_reset) {
|
|
163
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
164
|
+
ZstdObject *z = zstd_arg(ARG(0));
|
|
165
|
+
if (!z) return js_throw_type_error(ctx, "zstdReset: a handle expected");
|
|
166
|
+
if (!z->compress) z->pledged_src_size = ZSTD_CONTENTSIZE_UNKNOWN; /* ignored when decompressing */
|
|
167
|
+
const char *code;
|
|
168
|
+
const char *message = zstd_init(z, NULL, 0, &code);
|
|
169
|
+
if (message) return failure(ctx, message, -1, code);
|
|
170
|
+
return js_int32(0);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* zstdClose(handle): zstd's memory, now */
|
|
174
|
+
PRIMITIVE(js_host_zstd_close) {
|
|
175
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
176
|
+
ZstdObject *z = zstd_arg(ARG(0));
|
|
177
|
+
if (z) zstd_end(z);
|
|
178
|
+
return JS_UNDEFINED;
|
|
179
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* Copyright 2013 Google Inc. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
Distributed under MIT license.
|
|
4
|
+
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include "constants.h"
|
|
8
|
+
|
|
9
|
+
const BrotliPrefixCodeRange
|
|
10
|
+
_kBrotliPrefixCodeRanges[BROTLI_NUM_BLOCK_LEN_SYMBOLS] = {
|
|
11
|
+
{1, 2}, {5, 2}, {9, 2}, {13, 2}, {17, 3}, {25, 3},
|
|
12
|
+
{33, 3}, {41, 3}, {49, 4}, {65, 4}, {81, 4}, {97, 4},
|
|
13
|
+
{113, 5}, {145, 5}, {177, 5}, {209, 5}, {241, 6}, {305, 6},
|
|
14
|
+
{369, 7}, {497, 8}, {753, 9}, {1265, 10}, {2289, 11}, {4337, 12},
|
|
15
|
+
{8433, 13}, {16625, 24}};
|