visaljs 0.0.7 → 0.0.9
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/README.md +68 -4
- package/THIRD_PARTY_LICENSES +1216 -0
- package/cli.js +4461 -321
- package/node/include/js_node.h +57 -1
- package/node/include/js_uv.h +8 -1
- package/node/prelude/_http_agent.js +5 -0
- package/node/prelude/_http_server.js +7 -0
- package/node/prelude/_stream_duplex.js +4 -0
- package/node/prelude/_stream_passthrough.js +4 -0
- package/node/prelude/_stream_readable.js +4 -0
- package/node/prelude/_stream_transform.js +4 -0
- package/node/prelude/_stream_writable.js +4 -0
- package/node/prelude/assert.js +1334 -0
- package/node/prelude/assert_strict.js +12 -0
- package/node/prelude/async_hooks.js +1 -1
- package/node/prelude/buffer.js +43 -3
- package/node/prelude/child_process.js +1098 -0
- package/node/prelude/cluster.js +52 -0
- package/node/prelude/console.js +328 -0
- package/node/prelude/constants.js +10 -0
- package/node/prelude/crypto.js +1 -1
- package/node/prelude/diagnostics_channel.js +1 -1
- package/node/prelude/dns.js +8 -2
- package/node/prelude/domain.js +115 -0
- package/node/prelude/events.js +148 -16
- package/node/prelude/fs.js +1138 -151
- package/node/prelude/fs_promises.js +117 -11
- package/node/prelude/http.js +784 -301
- package/node/prelude/http2.js +1 -1
- package/node/prelude/https.js +159 -0
- package/node/prelude/inspector.js +27 -0
- package/node/prelude/inspector_promises.js +4 -0
- package/node/prelude/internal/async_context.js +1 -1
- package/node/prelude/internal/buffer_transcode.js +44 -0
- package/node/prelude/internal/comparisons.js +916 -0
- package/node/prelude/internal/compression_streams.js +153 -0
- package/node/prelude/internal/crypto/asym.js +27 -14
- package/node/prelude/internal/crypto/cipher.js +16 -5
- package/node/prelude/internal/crypto/diffiehellman.js +3 -2
- package/node/prelude/internal/crypto/hash.js +2 -1
- package/node/prelude/internal/crypto/kdf.js +14 -9
- package/node/prelude/internal/crypto/keys.js +63 -50
- package/node/prelude/internal/crypto/random.js +2 -1
- package/node/prelude/internal/crypto/util.js +4 -4
- package/node/prelude/internal/dotenv.js +98 -0
- package/node/prelude/internal/errors.js +21 -5
- package/node/prelude/internal/events_extras.js +113 -0
- package/node/prelude/internal/events_on.js +100 -0
- package/node/prelude/internal/features.js +72 -0
- package/node/prelude/internal/fetch.js +364 -0
- package/node/prelude/internal/form_data.js +376 -0
- package/node/prelude/internal/fs_bigint_stats.js +41 -0
- package/node/prelude/internal/fs_blob.js +19 -0
- package/node/prelude/internal/fs_cp.js +709 -0
- package/node/prelude/internal/fs_dir.js +166 -0
- package/node/prelude/internal/fs_filehandle.js +287 -0
- package/node/prelude/internal/fs_glob.js +296 -0
- package/node/prelude/internal/fs_statfs.js +42 -0
- package/node/prelude/internal/fs_stats.js +89 -0
- package/node/prelude/internal/fs_streams.js +541 -0
- package/node/prelude/internal/fs_utils.js +286 -0
- package/node/prelude/internal/fs_watch.js +580 -0
- package/node/prelude/internal/http_agent.js +114 -2
- package/node/prelude/internal/http_symbols.js +3 -0
- package/node/prelude/internal/mime.js +249 -0
- package/node/prelude/internal/net.js +1 -0
- package/node/prelude/internal/net_bound.js +123 -0
- package/node/prelude/internal/net_onread.js +73 -0
- package/node/prelude/internal/net_tos.js +54 -0
- package/node/prelude/internal/parse_args.js +288 -0
- package/node/prelude/internal/perf_histogram.js +435 -0
- package/node/prelude/internal/perf_observe.js +125 -0
- package/node/prelude/internal/performance_global.js +19 -0
- package/node/prelude/internal/process_events.js +49 -1
- package/node/prelude/internal/process_memory.js +14 -0
- package/node/prelude/internal/process_more.js +414 -0
- package/node/prelude/internal/process_signals.js +2 -1
- package/node/prelude/internal/process_stdin.js +52 -0
- package/node/prelude/internal/process_stdio.js +36 -0
- package/node/prelude/internal/querystring.js +0 -0
- package/node/prelude/internal/readline.js +338 -0
- package/node/prelude/internal/socketaddress.js +8 -4
- package/node/prelude/internal/source_map.js +122 -0
- package/node/prelude/internal/stream_compose.js +74 -0
- package/node/prelude/internal/stream_from.js +6 -0
- package/node/prelude/internal/stream_operators.js +23 -0
- package/node/prelude/internal/stream_pipeline.js +7 -0
- package/node/prelude/internal/stream_transform.js +10 -0
- package/node/prelude/internal/stream_web_adapters.js +143 -0
- package/node/prelude/internal/streams/add_abort_signal.js +58 -0
- package/node/prelude/internal/streams/compose.js +244 -0
- package/node/prelude/internal/streams/destroy.js +358 -0
- package/node/prelude/internal/streams/duplex.js +199 -0
- package/node/prelude/internal/streams/duplexify.js +378 -0
- package/node/prelude/internal/streams/end_of_stream.js +387 -0
- package/node/prelude/internal/streams/errors.js +216 -0
- package/node/prelude/internal/streams/from.js +211 -0
- package/node/prelude/internal/streams/legacy.js +120 -0
- package/node/prelude/internal/streams/operators.js +375 -0
- package/node/prelude/internal/streams/passthrough.js +45 -0
- package/node/prelude/internal/streams/pipeline.js +468 -0
- package/node/prelude/internal/streams/readable.js +1835 -0
- package/node/prelude/internal/streams/state.js +48 -0
- package/node/prelude/internal/streams/transform.js +203 -0
- package/node/prelude/internal/streams/utils.js +355 -0
- package/node/prelude/internal/streams/validators.js +108 -0
- package/node/prelude/internal/streams/writable.js +1160 -0
- package/node/prelude/internal/structured_clone.js +238 -0
- package/node/prelude/internal/system_errors.js +37 -0
- package/node/prelude/internal/test_runner/mock.js +431 -0
- package/node/prelude/internal/test_runner/reporters.js +404 -0
- package/node/prelude/internal/test_runner/test.js +1571 -0
- package/node/prelude/internal/timers.js +38 -7
- package/node/prelude/internal/timers_global.js +1 -1
- package/node/prelude/internal/tls/common.js +8 -2
- package/node/prelude/internal/tls/wrap.js +5 -16
- package/node/prelude/internal/tls/x509.js +1 -1
- package/node/prelude/internal/tty_read_stream.js +39 -0
- package/node/prelude/internal/tty_streams.js +3 -0
- package/node/prelude/internal/util_debuglog.js +68 -0
- package/node/prelude/internal/util_diff.js +63 -0
- package/node/prelude/internal/util_more.js +111 -0
- package/node/prelude/internal/util_styles.js +76 -0
- package/node/prelude/internal/zlib_engines.js +1 -1
- package/node/prelude/module.js +219 -8
- package/node/prelude/net.js +197 -49
- package/node/prelude/os.js +88 -11
- package/node/prelude/path.js +11 -7
- package/node/prelude/path_posix.js +1 -1
- package/node/prelude/path_win32.js +1 -1
- package/node/prelude/perf_hooks.js +151 -0
- package/node/prelude/process.js +36 -1
- package/node/prelude/punycode.js +188 -0
- package/node/prelude/querystring.js +1 -1
- package/node/prelude/readline.js +8 -0
- package/node/prelude/readline_promises.js +88 -0
- package/node/prelude/repl.js +38 -0
- package/node/prelude/sea.js +23 -0
- package/node/prelude/stream.js +70 -1332
- package/node/prelude/stream_consumers.js +34 -0
- package/node/prelude/stream_promises.js +1 -1
- package/node/prelude/stream_web.js +15 -2
- package/node/prelude/string_decoder.js +1 -1
- package/node/prelude/sys.js +7 -0
- package/node/prelude/test.js +56 -0
- package/node/prelude/test_reporters.js +269 -0
- package/node/prelude/timers.js +7 -84
- package/node/prelude/timers_promises.js +1 -1
- package/node/prelude/tls.js +2 -1
- package/node/prelude/trace_events.js +52 -0
- package/node/prelude/tty.js +10 -4
- package/node/prelude/url.js +88 -27
- package/node/prelude/util.js +121 -5
- package/node/prelude/util_types.js +4 -3
- package/node/prelude/v8.js +814 -0
- package/node/prelude/vm.js +86 -0
- package/node/prelude/wasi.js +10 -0
- package/node/prelude/worker_threads.js +56 -0
- package/node/prelude/zlib.js +58 -25
- package/node/src/host_brotli.c +59 -11
- package/node/src/host_fs.c +342 -11
- package/node/src/host_fswatch.c +170 -0
- package/node/src/host_http.c +292 -39
- package/node/src/host_loop.c +25 -2
- package/node/src/host_net.c +130 -16
- package/node/src/host_os.c +55 -1
- package/node/src/host_proc.c +291 -0
- package/node/src/host_process.c +488 -0
- package/node/src/host_sys.c +64 -2
- package/node/src/host_zlib.c +27 -7
- package/node/src/host_zstd.c +41 -6
- package/node/third_party/hdrhistogram/LICENSE +42 -0
- package/node/third_party/hdrhistogram/README.md +5 -0
- package/node/third_party/libuv/LICENSE +0 -0
- package/node/third_party/libuv/LICENSE-extra +36 -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/nodejs/LICENSE +47 -0
- package/node/third_party/nodejs/README.md +5 -0
- package/node/third_party/parseargs/LICENSE +21 -0
- package/node/third_party/parseargs/README.md +5 -0
- package/node/third_party/punycode/LICENSE +20 -0
- package/node/third_party/punycode/README.md +5 -0
- package/node/third_party/zlib/LICENSE.chromium +27 -0
- package/package.json +1 -1
- package/prebuilt/darwin-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/darwin-arm64/brotli-7995bbdacc52e51c.a +0 -0
- package/prebuilt/darwin-arm64/uv-72ab666eae197cd8.a +0 -0
- package/prebuilt/darwin-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/darwin-arm64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/darwin-x64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/darwin-x64/brotli-7995bbdacc52e51c.a +0 -0
- package/prebuilt/darwin-x64/uv-72ab666eae197cd8.a +0 -0
- package/prebuilt/darwin-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/darwin-x64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-arm64/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-arm64/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-arm64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-arm64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-arm64-musl/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-arm64-musl/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-arm64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-arm64-musl/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-x64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-x64/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-x64/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-x64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-x64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-x64-musl/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-x64-musl/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-x64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-x64-musl/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
- package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
- package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
- package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
- package/runtime/include/js_atoms.gen.h +0 -0
- package/runtime/include/js_atoms.h +5 -1
- package/runtime/include/js_bigint.h +1 -1
- package/runtime/include/js_buffer.h +4 -4
- package/runtime/include/js_builtins.h +41 -3
- package/runtime/include/js_console.h +9 -4
- package/runtime/include/js_convert.h +1 -1
- package/runtime/include/js_core.def +5 -4
- package/runtime/include/js_crypto.h +1 -1
- package/runtime/include/js_error.h +1 -1
- package/runtime/include/js_exception.h +21 -1
- package/runtime/include/js_function.h +33 -9
- package/runtime/include/js_gc.h +172 -30
- package/runtime/include/js_generator.h +2 -2
- package/runtime/include/js_host.h +19 -1
- package/runtime/include/js_jobs.h +5 -5
- package/runtime/include/js_module.h +1 -1
- package/runtime/include/js_object.h +142 -15
- package/runtime/include/js_ops.h +107 -5
- package/runtime/include/js_promise.h +3 -3
- package/runtime/include/js_regexp.h +1 -1
- package/runtime/include/js_runtime.h +0 -0
- package/runtime/include/js_symbol.h +1 -1
- package/runtime/include/js_web.h +5 -1
- package/runtime/include/jscell.h +22 -15
- package/runtime/include/jscontext.h +82 -39
- package/runtime/include/jsnum.h +1 -1
- package/runtime/include/jsstring.h +19 -6
- package/runtime/include/jsvalue.h +7 -3
- package/runtime/src/arguments.c +2 -2
- package/runtime/src/array.c +4 -1
- package/runtime/src/arraybuffer.c +19 -7
- package/runtime/src/async_iter.c +4 -3
- package/runtime/src/atoms.c +38 -4
- package/runtime/src/base64.c +2 -2
- package/runtime/src/bigint.c +1 -1
- package/runtime/src/blob.c +22 -9
- package/runtime/src/boringssl_support.cc +1 -1
- package/runtime/src/buffer.c +299 -91
- package/runtime/src/builtin_table.c +1 -1
- package/runtime/src/builtins.c +30 -4
- package/runtime/src/builtins_util.h +0 -0
- package/runtime/src/collections.c +18 -3
- package/runtime/src/components.c +1 -1
- package/runtime/src/console.c +14 -7
- package/runtime/src/convert.c +0 -0
- package/runtime/src/core_all.c +1 -1
- package/runtime/src/crypto.c +1 -1
- package/runtime/src/crypto_asym.c +1 -1
- package/runtime/src/crypto_bn.c +1 -1
- package/runtime/src/crypto_cipher.c +10 -3
- package/runtime/src/crypto_hash.c +1 -1
- package/runtime/src/crypto_host.c +1 -1
- package/runtime/src/crypto_internal.h +1 -1
- package/runtime/src/crypto_kdf.c +1 -1
- package/runtime/src/crypto_key.c +14 -1
- package/runtime/src/crypto_pkey.c +1 -1
- package/runtime/src/crypto_subtle.c +142 -58
- package/runtime/src/crypto_tls.c +1 -1
- package/runtime/src/date.c +5 -2
- package/runtime/src/domexception.c +2 -2
- package/runtime/src/elements.c +56 -17
- package/runtime/src/elements.h +7 -2
- package/runtime/src/encoding.c +1 -1
- package/runtime/src/error.c +4 -4
- package/runtime/src/events.c +42 -14
- package/runtime/src/exception.c +1 -1
- package/runtime/src/fetch.c +241 -17
- package/runtime/src/function.c +31 -19
- package/runtime/src/gc.c +1720 -211
- package/runtime/src/gc_visit.h +87 -0
- package/runtime/src/generator.c +5 -3
- package/runtime/src/global.c +14 -6
- package/runtime/src/headers.c +10 -10
- package/runtime/src/inspect.c +76 -17
- package/runtime/src/internal.h +9 -6
- package/runtime/src/iterate.c +94 -2
- package/runtime/src/iterator.c +1 -1
- package/runtime/src/jobs.c +11 -5
- package/runtime/src/jsnum.c +2 -2
- package/runtime/src/json.c +1 -1
- package/runtime/src/math.c +9 -1
- package/runtime/src/module.c +3 -3
- package/runtime/src/number.c +0 -0
- package/runtime/src/object.c +107 -74
- package/runtime/src/ops.c +21 -3
- package/runtime/src/os.c +192 -1
- package/runtime/src/os.h +33 -2
- package/runtime/src/process.c +73 -8
- package/runtime/src/promise.c +4 -4
- package/runtime/src/proxy.c +1 -1
- package/runtime/src/reflect.c +1 -1
- package/runtime/src/regexp.c +700 -11
- package/runtime/src/regexp_anchor.h +1 -1
- package/runtime/src/regexp_message.h +1 -1
- package/runtime/src/shape.c +78 -20
- package/runtime/src/shape.h +0 -0
- package/runtime/src/streams.c +22 -8
- package/runtime/src/streams.h +0 -0
- package/runtime/src/string.c +64 -25
- package/runtime/src/string_builtins.c +7 -7
- package/runtime/src/symbol.c +2 -7
- package/runtime/src/test_host.c +3 -3
- package/runtime/src/tls_roots.gen.h +102 -620
- package/runtime/src/typedarray.c +8 -3
- package/runtime/src/tznames.gen.h +2 -1
- package/runtime/src/uri.c +1 -1
- package/runtime/src/url.c +42 -39
- package/runtime/src/weak.c +110 -36
- package/runtime/src/web.c +21 -3
- package/runtime/src/wrapper.c +0 -0
- package/runtime/src/writable.c +7 -6
- package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
- package/runtime/third_party/ada-idna/README.md +7 -7
- package/runtime/third_party/ada-idna/convert.mjs +89 -27
- package/runtime/third_party/ada-idna/idna.c +30 -31
- package/runtime/third_party/ada-idna/idna.h +0 -0
- package/runtime/third_party/ada-idna/idna_tables.h +2272 -1952
- package/runtime/third_party/boringssl/third_party/fiat/LICENSE +15 -0
- package/runtime/third_party/mozilla-ca/LICENSE +373 -0
- package/runtime/third_party/mozilla-ca/README.md +9 -0
- package/runtime/third_party/nodejs/LICENSE +47 -0
- package/runtime/third_party/nodejs/README.md +7 -0
- package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
- package/runtime/third_party/quickjs-dtoa/README.md +1 -1
- 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 +2 -2
- 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/unicode/LICENSE +39 -0
- package/runtime/third_party/unicode/README.md +9 -0
- package/runtime/third_party/v8-ieee754/LICENSE +0 -0
- package/runtime/third_party/v8-ieee754/LICENSE.fdlibm +10 -0
- package/runtime/third_party/v8-ieee754/README.md +3 -2
- 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 +2 -2
|
@@ -0,0 +1,814 @@
|
|
|
1
|
+
// node:v8: serialize and deserialize in V8's wire format (version 15) and Node's DefaultSerializer
|
|
2
|
+
// (Buffers and typed arrays as host objects), byte for byte, with Serializer and Deserializer for
|
|
3
|
+
// the format's parts; heap figures from visaljs's collector in V8's shapes; and the rest of the
|
|
4
|
+
// module as a compiled program has it (no flags, coverage or heap snapshots).
|
|
5
|
+
import { processMemory } from "visaljs:host";
|
|
6
|
+
import { codeError, invalidArgType, notSupported, validateString } from "./internal/errors.js";
|
|
7
|
+
|
|
8
|
+
/* ---- the wire format ---------------------------------------------------------------------------- */
|
|
9
|
+
|
|
10
|
+
const kLatestVersion = 15;
|
|
11
|
+
const T = {
|
|
12
|
+
version: 0xff, padding: 0x00, hole: 0x2d, undefined: 0x5f, null: 0x30, true: 0x54, false: 0x46, int32: 0x49, uint32: 0x55,
|
|
13
|
+
double: 0x4e, bigint: 0x5a, utf8: 0x53, oneByte: 0x22, twoByte: 0x63, ref: 0x5e, beginObject: 0x6f, endObject: 0x7b,
|
|
14
|
+
beginSparse: 0x61, endSparse: 0x40, beginDense: 0x41, endDense: 0x24, date: 0x44, trueObject: 0x79, falseObject: 0x78,
|
|
15
|
+
numberObject: 0x6e, bigintObject: 0x7a, stringObject: 0x73, regexp: 0x52, beginMap: 0x3b, endMap: 0x3a, beginSet: 0x27,
|
|
16
|
+
endSet: 0x2c, arrayBuffer: 0x42, transfer: 0x74, view: 0x56, host: 0x5c, error: 0x72,
|
|
17
|
+
};
|
|
18
|
+
const ERROR = { eval: 0x45, range: 0x52, reference: 0x46, syntax: 0x53, type: 0x54, uri: 0x55, message: 0x6d, cause: 0x63, stack: 0x73, end: 0x2e };
|
|
19
|
+
const errorPrototypes = [[EvalError, ERROR.eval], [RangeError, ERROR.range], [ReferenceError, ERROR.reference], [SyntaxError, ERROR.syntax],
|
|
20
|
+
[TypeError, ERROR.type], [URIError, ERROR.uri]];
|
|
21
|
+
const REGEXP_FLAGS = [["g", 1], ["i", 2], ["m", 4], ["y", 8], ["u", 16], ["s", 32], ["d", 128], ["v", 256]];
|
|
22
|
+
|
|
23
|
+
/* V8's views' subtags, for the base Serializer */
|
|
24
|
+
const VIEW_TAGS = [["Int8Array", 0x62], ["Uint8Array", 0x42], ["Uint8ClampedArray", 0x43], ["Int16Array", 0x77], ["Uint16Array", 0x57],
|
|
25
|
+
["Int32Array", 0x64], ["Uint32Array", 0x44], ["Float32Array", 0x66], ["Float64Array", 0x46], ["BigInt64Array", 0x71],
|
|
26
|
+
["BigUint64Array", 0x51], ["DataView", 0x3f]];
|
|
27
|
+
|
|
28
|
+
/* Node's DefaultSerializer: the views' indices (10 is Buffer) */
|
|
29
|
+
const viewTypes = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array,
|
|
30
|
+
DataView, null, BigInt64Array, BigUint64Array];
|
|
31
|
+
const typeName = (v) => Object.prototype.toString.call(v).slice(8, -1);
|
|
32
|
+
|
|
33
|
+
function cloneError(value) {
|
|
34
|
+
const shown = typeof value === "function" ? Function.prototype.toString.call(value) : typeof value === "symbol" ? String(value)
|
|
35
|
+
: `#<${value?.constructor?.name ?? "Object"}>`;
|
|
36
|
+
return new Error(`${shown} could not be cloned.`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class Serializer {
|
|
40
|
+
#chunks = [];
|
|
41
|
+
#size = 0;
|
|
42
|
+
#ids = new Map();
|
|
43
|
+
#transfers = new Map();
|
|
44
|
+
#viewsAsHost = false;
|
|
45
|
+
|
|
46
|
+
/* ---- bytes ---- */
|
|
47
|
+
#byte(b) {
|
|
48
|
+
this.#push(Uint8Array.of(b));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#push(bytes) {
|
|
52
|
+
this.#chunks.push(bytes);
|
|
53
|
+
this.#size += bytes.length;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#varint(n) {
|
|
57
|
+
const out = [];
|
|
58
|
+
do {
|
|
59
|
+
let b = n % 128;
|
|
60
|
+
n = Math.floor(n / 128);
|
|
61
|
+
if (n > 0) b |= 0x80;
|
|
62
|
+
out.push(b);
|
|
63
|
+
} while (n > 0);
|
|
64
|
+
this.#push(Uint8Array.from(out));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#double(d) {
|
|
68
|
+
const b = new Uint8Array(8);
|
|
69
|
+
new DataView(b.buffer).setFloat64(0, d, true);
|
|
70
|
+
this.#push(b);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* ---- the public calls ---- */
|
|
74
|
+
writeHeader() {
|
|
75
|
+
this.#byte(T.version);
|
|
76
|
+
this.#varint(kLatestVersion);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
writeValue(value) {
|
|
80
|
+
this.#write(value);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
releaseBuffer() {
|
|
85
|
+
const out = Buffer.allocUnsafe(this.#size);
|
|
86
|
+
let at = 0;
|
|
87
|
+
for (const c of this.#chunks) {
|
|
88
|
+
out.set(c, at);
|
|
89
|
+
at += c.length;
|
|
90
|
+
}
|
|
91
|
+
this.#chunks = [];
|
|
92
|
+
this.#size = 0;
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
transferArrayBuffer(id, arrayBuffer) {
|
|
97
|
+
this.#transfers.set(arrayBuffer, id);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
writeUint32(value) {
|
|
101
|
+
this.#varint(value >>> 0);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
writeUint64(hi, lo) {
|
|
105
|
+
this.#varint((hi >>> 0) * 4294967296 + (lo >>> 0));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
writeDouble(value) {
|
|
109
|
+
this.#double(value);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
writeRawBytes(source) {
|
|
113
|
+
if (!ArrayBuffer.isView(source)) throw invalidArgType("source", "an instance of Buffer, TypedArray, or DataView", source);
|
|
114
|
+
this.#push(new Uint8Array(source.buffer, source.byteOffset, source.byteLength).slice());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
_setTreatArrayBufferViewsAsHostObjects(flag) {
|
|
118
|
+
this.#viewsAsHost = Boolean(flag);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_getDataCloneError(message) {
|
|
122
|
+
return new Error(message);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
_getSharedArrayBufferId() {
|
|
126
|
+
throw this._getDataCloneError("#<SharedArrayBuffer> could not be cloned.");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
_writeHostObject(object) {
|
|
130
|
+
throw this._getDataCloneError(`Unserializable host object: ${typeName(object)}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* ---- values ---- */
|
|
134
|
+
#string(s) {
|
|
135
|
+
let oneByte = true;
|
|
136
|
+
for (let i = 0; i < s.length && oneByte; i++) oneByte = s.charCodeAt(i) <= 0xff;
|
|
137
|
+
if (oneByte) {
|
|
138
|
+
this.#byte(T.oneByte);
|
|
139
|
+
this.#varint(s.length);
|
|
140
|
+
this.#push(Uint8Array.from(s, (c) => c.charCodeAt(0)));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const byteLength = s.length * 2;
|
|
144
|
+
let lengthSize = 1;
|
|
145
|
+
for (let n = byteLength; n >= 128; n = Math.floor(n / 128)) lengthSize++;
|
|
146
|
+
if ((this.#size + 1 + lengthSize) & 1) this.#byte(T.padding); /* the UTF-16 bytes 2-aligned, as V8's */
|
|
147
|
+
this.#byte(T.twoByte);
|
|
148
|
+
this.#varint(byteLength);
|
|
149
|
+
const b = new Uint8Array(byteLength);
|
|
150
|
+
for (let i = 0; i < s.length; i++) {
|
|
151
|
+
const c = s.charCodeAt(i);
|
|
152
|
+
b[2 * i] = c & 0xff;
|
|
153
|
+
b[2 * i + 1] = c >> 8;
|
|
154
|
+
}
|
|
155
|
+
this.#push(b);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#number(n) {
|
|
159
|
+
if (Number.isInteger(n) && n >= -2147483648 && n <= 2147483647 && !Object.is(n, -0)) {
|
|
160
|
+
this.#byte(T.int32);
|
|
161
|
+
this.#varint(((n << 1) ^ (n >> 31)) >>> 0);
|
|
162
|
+
} else {
|
|
163
|
+
this.#byte(T.double);
|
|
164
|
+
this.#double(n);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
#bigintDigits(b) {
|
|
169
|
+
const negative = b < 0n;
|
|
170
|
+
let magnitude = negative ? -b : b;
|
|
171
|
+
const words = [];
|
|
172
|
+
while (magnitude > 0n) {
|
|
173
|
+
words.push(magnitude & 0xffffffffffffffffn);
|
|
174
|
+
magnitude >>= 64n;
|
|
175
|
+
}
|
|
176
|
+
this.#varint((words.length * 8) * 2 + (negative ? 1 : 0));
|
|
177
|
+
const bytes = new Uint8Array(words.length * 8);
|
|
178
|
+
const view = new DataView(bytes.buffer);
|
|
179
|
+
words.forEach((w, i) => view.setBigUint64(i * 8, w, true));
|
|
180
|
+
this.#push(bytes);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
#write(value) {
|
|
184
|
+
switch (typeof value) {
|
|
185
|
+
case "undefined":
|
|
186
|
+
return this.#byte(T.undefined);
|
|
187
|
+
case "boolean":
|
|
188
|
+
return this.#byte(value ? T.true : T.false);
|
|
189
|
+
case "number":
|
|
190
|
+
return this.#number(value);
|
|
191
|
+
case "string":
|
|
192
|
+
return this.#string(value);
|
|
193
|
+
case "bigint":
|
|
194
|
+
this.#byte(T.bigint);
|
|
195
|
+
return this.#bigintDigits(value);
|
|
196
|
+
case "symbol":
|
|
197
|
+
case "function":
|
|
198
|
+
throw this._getDataCloneError(cloneError(value).message);
|
|
199
|
+
}
|
|
200
|
+
if (value === null) return this.#byte(T.null);
|
|
201
|
+
const id = this.#ids.get(value);
|
|
202
|
+
if (id !== undefined) {
|
|
203
|
+
this.#byte(T.ref);
|
|
204
|
+
return this.#varint(id);
|
|
205
|
+
}
|
|
206
|
+
if (value instanceof ArrayBuffer && this.#transfers.has(value)) {
|
|
207
|
+
this.#ids.set(value, this.#ids.size);
|
|
208
|
+
this.#byte(T.transfer);
|
|
209
|
+
return this.#varint(this.#transfers.get(value));
|
|
210
|
+
}
|
|
211
|
+
if (ArrayBuffer.isView(value) && this.#viewsAsHost) {
|
|
212
|
+
this.#ids.set(value, this.#ids.size);
|
|
213
|
+
this.#byte(T.host);
|
|
214
|
+
return this._writeHostObject(value);
|
|
215
|
+
}
|
|
216
|
+
if (ArrayBuffer.isView(value)) {
|
|
217
|
+
/* V8's own: the buffer, then the view on it */
|
|
218
|
+
this.#write(value.buffer);
|
|
219
|
+
this.#ids.set(value, this.#ids.size);
|
|
220
|
+
this.#byte(T.view);
|
|
221
|
+
this.#byte(VIEW_TAGS.find(([name]) => name === typeName(value))?.[1] ?? 0x3f);
|
|
222
|
+
this.#varint(value.byteOffset);
|
|
223
|
+
this.#varint(value.byteLength);
|
|
224
|
+
return this.#varint(0);
|
|
225
|
+
}
|
|
226
|
+
this.#ids.set(value, this.#ids.size);
|
|
227
|
+
const type = typeName(value);
|
|
228
|
+
if (Array.isArray(value)) return this.#array(value);
|
|
229
|
+
if (value instanceof ArrayBuffer) {
|
|
230
|
+
this.#byte(T.arrayBuffer);
|
|
231
|
+
this.#varint(value.byteLength);
|
|
232
|
+
return this.#push(new Uint8Array(value).slice());
|
|
233
|
+
}
|
|
234
|
+
if (type === "Date") {
|
|
235
|
+
this.#byte(T.date);
|
|
236
|
+
return this.#double(value.getTime());
|
|
237
|
+
}
|
|
238
|
+
if (type === "RegExp") {
|
|
239
|
+
this.#byte(T.regexp);
|
|
240
|
+
this.#string(value.source);
|
|
241
|
+
return this.#varint(REGEXP_FLAGS.reduce((f, [c, bit]) => (value.flags.includes(c) ? f | bit : f), 0));
|
|
242
|
+
}
|
|
243
|
+
if (type === "Map") {
|
|
244
|
+
this.#byte(T.beginMap);
|
|
245
|
+
for (const [k, v] of value) {
|
|
246
|
+
this.#write(k);
|
|
247
|
+
this.#write(v);
|
|
248
|
+
}
|
|
249
|
+
this.#byte(T.endMap);
|
|
250
|
+
return this.#varint(value.size * 2);
|
|
251
|
+
}
|
|
252
|
+
if (type === "Set") {
|
|
253
|
+
this.#byte(T.beginSet);
|
|
254
|
+
for (const v of value) this.#write(v);
|
|
255
|
+
this.#byte(T.endSet);
|
|
256
|
+
return this.#varint(value.size);
|
|
257
|
+
}
|
|
258
|
+
if (type === "Boolean") return this.#byte(value.valueOf() ? T.trueObject : T.falseObject);
|
|
259
|
+
if (type === "Number") {
|
|
260
|
+
this.#byte(T.numberObject);
|
|
261
|
+
return this.#double(value.valueOf());
|
|
262
|
+
}
|
|
263
|
+
if (type === "String") {
|
|
264
|
+
this.#byte(T.stringObject);
|
|
265
|
+
return this.#string(value.valueOf());
|
|
266
|
+
}
|
|
267
|
+
if (type === "BigInt") {
|
|
268
|
+
this.#byte(T.bigintObject);
|
|
269
|
+
return this.#bigintDigits(value.valueOf());
|
|
270
|
+
}
|
|
271
|
+
if (type === "Error") return this.#error(value);
|
|
272
|
+
if (type !== "Object" && type !== "Arguments") throw this._getDataCloneError(cloneError(value).message);
|
|
273
|
+
this.#byte(T.beginObject);
|
|
274
|
+
this.#varint(this.#properties(value, Object.keys(value)));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/* own enumerable properties, keys first: index keys as numbers */
|
|
279
|
+
#properties(object, keys) {
|
|
280
|
+
for (const key of keys) {
|
|
281
|
+
const index = Number(key);
|
|
282
|
+
if (String(index) === key && index >= 0 && index <= 4294967294) this.#number(index);
|
|
283
|
+
else this.#string(key);
|
|
284
|
+
this.#write(object[key]);
|
|
285
|
+
}
|
|
286
|
+
this.#byte(T.endObject);
|
|
287
|
+
return keys.length;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
#array(array) {
|
|
291
|
+
const length = array.length;
|
|
292
|
+
let dense = true;
|
|
293
|
+
for (let i = 0; i < length && dense; i++) dense = Object.hasOwn(array, i);
|
|
294
|
+
const extra = Object.keys(array).filter((k) => !(String(Number(k)) === k && Number(k) < length));
|
|
295
|
+
if (dense) {
|
|
296
|
+
this.#byte(T.beginDense);
|
|
297
|
+
this.#varint(length);
|
|
298
|
+
for (let i = 0; i < length; i++) this.#write(array[i]);
|
|
299
|
+
for (const key of extra) {
|
|
300
|
+
this.#string(key);
|
|
301
|
+
this.#write(array[key]);
|
|
302
|
+
}
|
|
303
|
+
this.#byte(T.endDense);
|
|
304
|
+
} else {
|
|
305
|
+
this.#byte(T.beginSparse);
|
|
306
|
+
this.#varint(length);
|
|
307
|
+
const keys = Object.keys(array);
|
|
308
|
+
for (const key of keys) {
|
|
309
|
+
const index = Number(key);
|
|
310
|
+
if (String(index) === key && index < length) this.#number(index);
|
|
311
|
+
else this.#string(key);
|
|
312
|
+
this.#write(array[key]);
|
|
313
|
+
}
|
|
314
|
+
this.#byte(T.endSparse);
|
|
315
|
+
this.#varint(keys.length);
|
|
316
|
+
return this.#varint(length);
|
|
317
|
+
}
|
|
318
|
+
this.#varint(extra.length);
|
|
319
|
+
this.#varint(length);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
#error(error) {
|
|
323
|
+
this.#byte(T.error);
|
|
324
|
+
const proto = Object.getPrototypeOf(error);
|
|
325
|
+
const tag = errorPrototypes.find(([ctor]) => proto === ctor.prototype)?.[1];
|
|
326
|
+
if (tag !== undefined) this.#byte(tag);
|
|
327
|
+
const message = Object.getOwnPropertyDescriptor(error, "message");
|
|
328
|
+
if (message && "value" in message) {
|
|
329
|
+
this.#byte(ERROR.message);
|
|
330
|
+
this.#string(String(message.value));
|
|
331
|
+
}
|
|
332
|
+
if (typeof error.stack === "string") {
|
|
333
|
+
this.#byte(ERROR.stack);
|
|
334
|
+
this.#string(error.stack);
|
|
335
|
+
}
|
|
336
|
+
if (Object.hasOwn(error, "cause")) {
|
|
337
|
+
this.#byte(ERROR.cause);
|
|
338
|
+
this.#write(error.cause);
|
|
339
|
+
}
|
|
340
|
+
this.#byte(ERROR.end);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export class Deserializer {
|
|
345
|
+
#buffer;
|
|
346
|
+
#pos = 0;
|
|
347
|
+
#version = 0;
|
|
348
|
+
#objects = [];
|
|
349
|
+
#transfers = new Map();
|
|
350
|
+
|
|
351
|
+
constructor(buffer) {
|
|
352
|
+
if (!ArrayBuffer.isView(buffer)) throw invalidArgType("buffer", "an instance of Buffer, TypedArray, or DataView", buffer);
|
|
353
|
+
this.#buffer = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
get buffer() {
|
|
357
|
+
return this.#buffer;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
#byte() {
|
|
361
|
+
if (this.#pos >= this.#buffer.length) throw new Error("Unable to deserialize cloned data.");
|
|
362
|
+
return this.#buffer[this.#pos++];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
#varint() {
|
|
366
|
+
let result = 0, scale = 1, b;
|
|
367
|
+
do {
|
|
368
|
+
b = this.#byte();
|
|
369
|
+
result += (b & 0x7f) * scale;
|
|
370
|
+
scale *= 128;
|
|
371
|
+
} while (b & 0x80);
|
|
372
|
+
return result;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
#double() {
|
|
376
|
+
const d = this.#buffer.readDoubleLE(this.#pos);
|
|
377
|
+
this.#pos += 8;
|
|
378
|
+
return d;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
readHeader() {
|
|
382
|
+
if (this.#buffer[this.#pos] === T.version) {
|
|
383
|
+
this.#pos++;
|
|
384
|
+
this.#version = this.#varint();
|
|
385
|
+
if (this.#version > kLatestVersion) throw new Error("Unable to deserialize cloned data due to invalid or unsupported version.");
|
|
386
|
+
}
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
getWireFormatVersion() {
|
|
391
|
+
return this.#version;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
readValue() {
|
|
395
|
+
return this.#read();
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
readUint32() {
|
|
399
|
+
return this.#varint() >>> 0;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
readUint64() {
|
|
403
|
+
const n = this.#varint();
|
|
404
|
+
return [Math.floor(n / 4294967296) >>> 0, n >>> 0];
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
readDouble() {
|
|
408
|
+
return this.#double();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
_readRawBytes(length) {
|
|
412
|
+
const offset = this.#pos;
|
|
413
|
+
this.#pos += length;
|
|
414
|
+
return offset;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
readRawBytes(length) {
|
|
418
|
+
return this.#buffer.subarray(this._readRawBytes(length), this.#pos);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
transferArrayBuffer(id, arrayBuffer) {
|
|
422
|
+
this.#transfers.set(id, arrayBuffer);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
_readHostObject() {
|
|
426
|
+
throw new Error("Unable to deserialize cloned data.");
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
#string(tag) {
|
|
430
|
+
const length = this.#varint();
|
|
431
|
+
const bytes = this.#buffer.subarray(this.#pos, this.#pos + length);
|
|
432
|
+
this.#pos += length;
|
|
433
|
+
if (tag === T.oneByte) return bytes.toString("latin1");
|
|
434
|
+
if (tag === T.utf8) return bytes.toString("utf8");
|
|
435
|
+
return bytes.toString("utf16le");
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
#readString() {
|
|
439
|
+
let tag = this.#byte();
|
|
440
|
+
while (tag === T.padding) tag = this.#byte();
|
|
441
|
+
return this.#string(tag);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
#bigint() {
|
|
445
|
+
const bitfield = this.#varint();
|
|
446
|
+
const byteLength = Math.floor(bitfield / 2);
|
|
447
|
+
let result = 0n;
|
|
448
|
+
for (let i = byteLength - 8; i >= 0; i -= 8) result = (result << 64n) | this.#buffer.readBigUInt64LE(this.#pos + i);
|
|
449
|
+
this.#pos += byteLength;
|
|
450
|
+
return bitfield & 1 ? -result : result;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
#int32() {
|
|
454
|
+
const z = this.#varint();
|
|
455
|
+
return z & 1 ? -(z + 1) / 2 : z / 2;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
#keyed(target, endTag) {
|
|
459
|
+
for (;;) {
|
|
460
|
+
const tag = this.#buffer[this.#pos];
|
|
461
|
+
if (tag === endTag) {
|
|
462
|
+
this.#pos++;
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const key = this.#read();
|
|
466
|
+
target[key] = this.#read();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
#read() {
|
|
471
|
+
let tag = this.#byte();
|
|
472
|
+
while (tag === T.padding) tag = this.#byte();
|
|
473
|
+
switch (tag) {
|
|
474
|
+
case T.undefined:
|
|
475
|
+
case T.hole:
|
|
476
|
+
return undefined;
|
|
477
|
+
case T.null:
|
|
478
|
+
return null;
|
|
479
|
+
case T.true:
|
|
480
|
+
return true;
|
|
481
|
+
case T.false:
|
|
482
|
+
return false;
|
|
483
|
+
case T.int32:
|
|
484
|
+
return this.#int32();
|
|
485
|
+
case T.uint32:
|
|
486
|
+
return this.#varint();
|
|
487
|
+
case T.double:
|
|
488
|
+
return this.#double();
|
|
489
|
+
case T.bigint:
|
|
490
|
+
return this.#bigint();
|
|
491
|
+
case T.oneByte:
|
|
492
|
+
case T.twoByte:
|
|
493
|
+
case T.utf8:
|
|
494
|
+
return this.#string(tag);
|
|
495
|
+
case T.ref:
|
|
496
|
+
return this.#objects[this.#varint()];
|
|
497
|
+
case T.beginObject: {
|
|
498
|
+
const object = {};
|
|
499
|
+
this.#objects.push(object);
|
|
500
|
+
this.#keyed(object, T.endObject);
|
|
501
|
+
this.#varint();
|
|
502
|
+
return object;
|
|
503
|
+
}
|
|
504
|
+
case T.beginDense: {
|
|
505
|
+
const length = this.#varint();
|
|
506
|
+
const array = new Array(length);
|
|
507
|
+
this.#objects.push(array);
|
|
508
|
+
for (let i = 0; i < length; i++) {
|
|
509
|
+
if (this.#buffer[this.#pos] === T.hole) {
|
|
510
|
+
this.#pos++;
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
array[i] = this.#read();
|
|
514
|
+
}
|
|
515
|
+
this.#keyed(array, T.endDense);
|
|
516
|
+
this.#varint();
|
|
517
|
+
this.#varint();
|
|
518
|
+
return array;
|
|
519
|
+
}
|
|
520
|
+
case T.beginSparse: {
|
|
521
|
+
const array = new Array(this.#varint());
|
|
522
|
+
this.#objects.push(array);
|
|
523
|
+
this.#keyed(array, T.endSparse);
|
|
524
|
+
this.#varint();
|
|
525
|
+
this.#varint();
|
|
526
|
+
return array;
|
|
527
|
+
}
|
|
528
|
+
case T.date: {
|
|
529
|
+
const date = new Date(this.#double());
|
|
530
|
+
this.#objects.push(date);
|
|
531
|
+
return date;
|
|
532
|
+
}
|
|
533
|
+
case T.regexp: {
|
|
534
|
+
const source = this.#readString();
|
|
535
|
+
const bits = this.#varint();
|
|
536
|
+
const re = new RegExp(source, REGEXP_FLAGS.filter(([, bit]) => bits & bit).map(([c]) => c).join(""));
|
|
537
|
+
this.#objects.push(re);
|
|
538
|
+
return re;
|
|
539
|
+
}
|
|
540
|
+
case T.beginMap: {
|
|
541
|
+
const map = new Map();
|
|
542
|
+
this.#objects.push(map);
|
|
543
|
+
while (this.#buffer[this.#pos] !== T.endMap) map.set(this.#read(), this.#read());
|
|
544
|
+
this.#pos++;
|
|
545
|
+
this.#varint();
|
|
546
|
+
return map;
|
|
547
|
+
}
|
|
548
|
+
case T.beginSet: {
|
|
549
|
+
const set = new Set();
|
|
550
|
+
this.#objects.push(set);
|
|
551
|
+
while (this.#buffer[this.#pos] !== T.endSet) set.add(this.#read());
|
|
552
|
+
this.#pos++;
|
|
553
|
+
this.#varint();
|
|
554
|
+
return set;
|
|
555
|
+
}
|
|
556
|
+
case T.trueObject:
|
|
557
|
+
case T.falseObject: {
|
|
558
|
+
const b = Object(tag === T.trueObject);
|
|
559
|
+
this.#objects.push(b);
|
|
560
|
+
return b;
|
|
561
|
+
}
|
|
562
|
+
case T.numberObject: {
|
|
563
|
+
const n = Object(this.#double());
|
|
564
|
+
this.#objects.push(n);
|
|
565
|
+
return n;
|
|
566
|
+
}
|
|
567
|
+
case T.stringObject: {
|
|
568
|
+
const s = Object(this.#readString());
|
|
569
|
+
this.#objects.push(s);
|
|
570
|
+
return s;
|
|
571
|
+
}
|
|
572
|
+
case T.bigintObject: {
|
|
573
|
+
const b = Object(this.#bigint());
|
|
574
|
+
this.#objects.push(b);
|
|
575
|
+
return b;
|
|
576
|
+
}
|
|
577
|
+
case T.arrayBuffer: {
|
|
578
|
+
const length = this.#varint();
|
|
579
|
+
const ab = this.#buffer.buffer.slice(this.#buffer.byteOffset + this.#pos, this.#buffer.byteOffset + this.#pos + length);
|
|
580
|
+
this.#pos += length;
|
|
581
|
+
this.#objects.push(ab);
|
|
582
|
+
return this.#maybeView(ab);
|
|
583
|
+
}
|
|
584
|
+
case T.transfer: {
|
|
585
|
+
const ab = this.#transfers.get(this.#varint());
|
|
586
|
+
this.#objects.push(ab);
|
|
587
|
+
return this.#maybeView(ab);
|
|
588
|
+
}
|
|
589
|
+
case T.host: {
|
|
590
|
+
const index = this.#objects.length;
|
|
591
|
+
this.#objects.push(undefined);
|
|
592
|
+
const object = this._readHostObject();
|
|
593
|
+
this.#objects[index] = object;
|
|
594
|
+
return object;
|
|
595
|
+
}
|
|
596
|
+
case T.error:
|
|
597
|
+
return this.#error();
|
|
598
|
+
}
|
|
599
|
+
throw new Error("Unable to deserialize cloned data.");
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/* an ArrayBuffer, or the view V8 wrote after it */
|
|
603
|
+
#maybeView(ab) {
|
|
604
|
+
if (this.#buffer[this.#pos] !== T.view) return ab;
|
|
605
|
+
this.#pos++;
|
|
606
|
+
const subtag = this.#byte();
|
|
607
|
+
const byteOffset = this.#varint();
|
|
608
|
+
const byteLength = this.#varint();
|
|
609
|
+
if (this.#version >= 14) this.#varint();
|
|
610
|
+
const name = VIEW_TAGS.find(([, t]) => t === subtag)?.[0] ?? "DataView";
|
|
611
|
+
const Ctor = globalThis[name];
|
|
612
|
+
const view = name === "DataView" ? new DataView(ab, byteOffset, byteLength) : new Ctor(ab, byteOffset, byteLength / Ctor.BYTES_PER_ELEMENT);
|
|
613
|
+
this.#objects.push(view);
|
|
614
|
+
return view;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
#error() {
|
|
618
|
+
const index = this.#objects.length;
|
|
619
|
+
this.#objects.push(undefined);
|
|
620
|
+
let Ctor = Error;
|
|
621
|
+
let message, stack, cause, hasCause = false;
|
|
622
|
+
for (;;) {
|
|
623
|
+
const tag = this.#byte();
|
|
624
|
+
if (tag === ERROR.end) break;
|
|
625
|
+
if (tag === ERROR.message) message = this.#readString();
|
|
626
|
+
else if (tag === ERROR.stack) stack = this.#readString();
|
|
627
|
+
else if (tag === ERROR.cause) {
|
|
628
|
+
cause = this.#read();
|
|
629
|
+
hasCause = true;
|
|
630
|
+
} else Ctor = errorPrototypes.find(([, t]) => t === tag)?.[0] ?? Error;
|
|
631
|
+
}
|
|
632
|
+
const error = hasCause ? new Ctor(message, { cause }) : new Ctor(message);
|
|
633
|
+
if (message === undefined) delete error.message;
|
|
634
|
+
if (stack !== undefined) Object.defineProperty(error, "stack", { value: stack, writable: true, configurable: true });
|
|
635
|
+
else delete error.stack;
|
|
636
|
+
this.#objects[index] = error;
|
|
637
|
+
return error;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/** Node's: Buffers and typed arrays as host objects, their bytes copied (a Buffer's pool not shown). */
|
|
642
|
+
export class DefaultSerializer extends Serializer {
|
|
643
|
+
constructor() {
|
|
644
|
+
super();
|
|
645
|
+
this._setTreatArrayBufferViewsAsHostObjects(true);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
_writeHostObject(view) {
|
|
649
|
+
let i = 10;
|
|
650
|
+
if (view.constructor !== Buffer) {
|
|
651
|
+
i = viewTypes.findIndex((Ctor) => Ctor !== null && typeName(view) === Ctor.name);
|
|
652
|
+
if (i === -1) throw this._getDataCloneError(`Unserializable host object: ${typeName(view)}`);
|
|
653
|
+
}
|
|
654
|
+
this.writeUint32(i);
|
|
655
|
+
this.writeUint32(view.byteLength);
|
|
656
|
+
this.writeRawBytes(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
export class DefaultDeserializer extends Deserializer {
|
|
661
|
+
_readHostObject() {
|
|
662
|
+
const typeIndex = this.readUint32();
|
|
663
|
+
const Ctor = typeIndex === 10 ? Buffer : viewTypes[typeIndex];
|
|
664
|
+
if (Ctor === undefined || Ctor === null) throw new Error("Unable to deserialize cloned data.");
|
|
665
|
+
const byteLength = this.readUint32();
|
|
666
|
+
const offset = this._readRawBytes(byteLength);
|
|
667
|
+
const bytes = this.buffer.subarray(offset, offset + byteLength);
|
|
668
|
+
if (Ctor === Buffer) return Buffer.from(bytes);
|
|
669
|
+
const copy = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + byteLength);
|
|
670
|
+
if (Ctor === DataView) return new DataView(copy);
|
|
671
|
+
return new Ctor(copy, 0, byteLength / Ctor.BYTES_PER_ELEMENT);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export function serialize(value) {
|
|
676
|
+
const serializer = new DefaultSerializer();
|
|
677
|
+
serializer.writeHeader();
|
|
678
|
+
serializer.writeValue(value);
|
|
679
|
+
return serializer.releaseBuffer();
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
export function deserialize(buffer) {
|
|
683
|
+
const deserializer = new DefaultDeserializer(buffer);
|
|
684
|
+
deserializer.readHeader();
|
|
685
|
+
return deserializer.readValue();
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/* ---- the heap: visaljs's collector's figures, in V8's shapes ------------------------------------ */
|
|
689
|
+
|
|
690
|
+
const memory = () => {
|
|
691
|
+
const [rss, heapTotal, heapUsed] = processMemory();
|
|
692
|
+
return { rss, heapTotal, heapUsed };
|
|
693
|
+
};
|
|
694
|
+
const HEAP_LIMIT = 4345298944; /* V8's default on a 64-bit machine: visaljs's heap has no fixed limit */
|
|
695
|
+
|
|
696
|
+
export function getHeapStatistics() {
|
|
697
|
+
const { rss, heapTotal, heapUsed } = memory();
|
|
698
|
+
return {
|
|
699
|
+
total_heap_size: heapTotal, total_heap_size_executable: 0, total_physical_size: Math.min(heapTotal, rss),
|
|
700
|
+
total_available_size: HEAP_LIMIT - heapUsed, used_heap_size: heapUsed, heap_size_limit: HEAP_LIMIT, malloced_memory: 0,
|
|
701
|
+
peak_malloced_memory: 0, does_zap_garbage: 0, number_of_native_contexts: 1, number_of_detached_contexts: 0,
|
|
702
|
+
total_global_handles_size: 0, used_global_handles_size: 0, external_memory: 0,
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/* V8's spaces: visaljs's heap is one, reported as old_space */
|
|
707
|
+
const SPACES = ["read_only_space", "new_space", "old_space", "code_space", "shared_space", "trusted_space", "shared_trusted_space",
|
|
708
|
+
"new_large_object_space", "large_object_space", "code_large_object_space", "shared_large_object_space",
|
|
709
|
+
"shared_trusted_large_object_space", "trusted_large_object_space"]; /* V8 13.6's, as Node 24 lists them */
|
|
710
|
+
|
|
711
|
+
export function getHeapSpaceStatistics() {
|
|
712
|
+
const { heapTotal, heapUsed } = memory();
|
|
713
|
+
return SPACES.map((space_name) => {
|
|
714
|
+
const old = space_name === "old_space";
|
|
715
|
+
return {
|
|
716
|
+
space_name, space_size: old ? heapTotal : 0, space_used_size: old ? heapUsed : 0, space_available_size: old ? heapTotal - heapUsed : 0,
|
|
717
|
+
physical_space_size: old ? heapTotal : 0,
|
|
718
|
+
};
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
export function getHeapCodeStatistics() {
|
|
723
|
+
return { code_and_metadata_size: 0, bytecode_and_metadata_size: 0, external_script_source_size: 0, cpu_profiler_metadata_size: 0 };
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
export function getCppHeapStatistics(detailLevel = "detailed") {
|
|
727
|
+
if (detailLevel !== "brief" && detailLevel !== "detailed") {
|
|
728
|
+
throw codeError(TypeError, "ERR_INVALID_ARG_VALUE", `The argument 'type' must be one of: 'brief', 'detailed'. Received '${detailLevel}'`);
|
|
729
|
+
}
|
|
730
|
+
return { committed_size_bytes: 0, resident_size_bytes: 0, used_size_bytes: 0, space_statistics: [], type_names: [], detail_level: detailLevel };
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
export function getHeapSnapshot() {
|
|
734
|
+
throw notSupported("v8.getHeapSnapshot (V8's heap snapshot format)");
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
export function writeHeapSnapshot() {
|
|
738
|
+
throw notSupported("v8.writeHeapSnapshot (V8's heap snapshot format)");
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
export function queryObjects() {
|
|
742
|
+
throw notSupported("v8.queryObjects");
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/** A limit on heap snapshots Node would write near the heap's limit: none are written. */
|
|
746
|
+
export function setHeapSnapshotNearHeapLimit(limit) {
|
|
747
|
+
if (typeof limit !== "number") throw invalidArgType("limit", "of type number", limit);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/* ---- the rest ---------------------------------------------------------------------------------------- */
|
|
751
|
+
|
|
752
|
+
/** A number for the code cache's format: fixed, as a compiled program has no code cache. */
|
|
753
|
+
export function cachedDataVersionTag() {
|
|
754
|
+
return 2596627580;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/** Whether V8 keeps a string as one byte per character: its characters all fit in Latin-1. */
|
|
758
|
+
export function isStringOneByteRepresentation(content) {
|
|
759
|
+
validateString(content, "content");
|
|
760
|
+
for (let i = 0; i < content.length; i++) if (content.charCodeAt(i) > 0xff) return false;
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/** V8's flags: a compiled program has no V8 to set them on. */
|
|
765
|
+
export function setFlagsFromString(flags) {
|
|
766
|
+
validateString(flags, "flags");
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
export function takeCoverage() {}
|
|
770
|
+
export function stopCoverage() {}
|
|
771
|
+
|
|
772
|
+
/** GC profiling: the collections aren't reported by visaljs's collector (statistics is empty). */
|
|
773
|
+
export class GCProfiler {
|
|
774
|
+
#startTime = 0;
|
|
775
|
+
|
|
776
|
+
start() {
|
|
777
|
+
this.#startTime = Date.now();
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
stop() {
|
|
781
|
+
const endTime = Date.now();
|
|
782
|
+
return { version: 1, startTime: this.#startTime, statistics: [], endTime };
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/* promise hooks: visaljs's promises run none */
|
|
787
|
+
const stop = () => {};
|
|
788
|
+
export const promiseHooks = {
|
|
789
|
+
createHook: () => stop,
|
|
790
|
+
onInit: () => stop,
|
|
791
|
+
onBefore: () => stop,
|
|
792
|
+
onAfter: () => stop,
|
|
793
|
+
onSettled: () => stop,
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
const notBuilding = () => codeError(Error, "ERR_NOT_BUILDING_SNAPSHOT", "Operation cannot be invoked when not building startup snapshot");
|
|
797
|
+
export const startupSnapshot = {
|
|
798
|
+
addSerializeCallback() {
|
|
799
|
+
throw notBuilding();
|
|
800
|
+
},
|
|
801
|
+
addDeserializeCallback() {
|
|
802
|
+
throw notBuilding();
|
|
803
|
+
},
|
|
804
|
+
setDeserializeMainFunction() {
|
|
805
|
+
throw notBuilding();
|
|
806
|
+
},
|
|
807
|
+
isBuildingSnapshot: () => 0, /* Node's: a flag from its binding, a number */
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
export default {
|
|
811
|
+
cachedDataVersionTag, getHeapSnapshot, getHeapStatistics, getHeapSpaceStatistics, getHeapCodeStatistics, getCppHeapStatistics,
|
|
812
|
+
setFlagsFromString, Serializer, Deserializer, DefaultSerializer, DefaultDeserializer, deserialize, takeCoverage, stopCoverage, serialize,
|
|
813
|
+
writeHeapSnapshot, promiseHooks, queryObjects, startupSnapshot, setHeapSnapshotNearHeapLimit, GCProfiler, isStringOneByteRepresentation,
|
|
814
|
+
};
|