visaljs 0.0.7 → 0.0.8
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 +63 -2
- package/THIRD_PARTY_LICENSES +1216 -0
- package/cli.js +4413 -324
- package/node/include/js_node.h +57 -1
- package/node/include/js_uv.h +8 -1
- 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 +1 -1
- package/node/prelude/domain.js +115 -0
- package/node/prelude/events.js +144 -16
- package/node/prelude/fs.js +1138 -151
- package/node/prelude/fs_promises.js +117 -11
- package/node/prelude/http.js +104 -27
- package/node/prelude/http2.js +1 -1
- package/node/prelude/https.js +148 -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 +116 -0
- package/node/prelude/internal/events_on.js +100 -0
- package/node/prelude/internal/features.js +55 -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 +26 -0
- package/node/prelude/internal/mime.js +249 -0
- package/node/prelude/internal/net.js +1 -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 +119 -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 +3 -15
- 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 +194 -7
- package/node/prelude/net.js +2 -1
- 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 +147 -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 +143 -20
- package/node/src/host_loop.c +25 -2
- package/node/src/host_net.c +55 -7
- 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 +1 -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 +2 -1
- package/runtime/include/jscell.h +22 -15
- package/runtime/include/jscontext.h +74 -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 +1 -1
- 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 +23 -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 +1716 -207
- 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 +5 -2
- 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 +134 -2
- package/runtime/src/regexp_anchor.h +1 -1
- package/runtime/src/regexp_message.h +1 -1
- package/runtime/src/shape.c +10 -19
- 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 +15 -12
- 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,488 @@
|
|
|
1
|
+
/* Host primitives for node:child_process: child processes on libuv (uv_spawn), as Node's
|
|
2
|
+
* ProcessWrap and SyncProcessRunner make them. A child's stdio pipes are node:net's pipe handles
|
|
3
|
+
* (host_net.c), so the prelude reads and writes them as net.Sockets. Processes are numbered; each
|
|
4
|
+
* has one JS callback (a root), called once from the loop as cb(exitStatus, termSignal).
|
|
5
|
+
*
|
|
6
|
+
* processSpawn(file, args, envPairs, cwd, stdio, flags, uid, gid, cb) → [0, id, pid] | [-errno]
|
|
7
|
+
* stdio: [kind, value] per descriptor; kind 0 ignore, 1 a pipe (value: its net handle id),
|
|
8
|
+
* 2 an overlapped pipe, 3 a descriptor the child inherits (value: the fd), 4 a stream whose
|
|
9
|
+
* handle the child inherits (value: its net handle id)
|
|
10
|
+
* flags: 1 detached, 2 windowsHide, 4 windowsVerbatimArguments; uid, gid: -1 for none
|
|
11
|
+
* processKill(id, signum) → 0 | -errno, processRef(id, ref), processClose(id)
|
|
12
|
+
* processSpawnSync(file, args, envPairs, cwd, stdio, flags, uid, gid, timeout, maxBuffer, killSignal)
|
|
13
|
+
* → [error (0 | -errno), pid, exitStatus, termSignal, output]: the child run to its end on a
|
|
14
|
+
* loop of its own; stdio as above, a pipe's value its input (bytes, or null); output has a
|
|
15
|
+
* pipe's bytes (a Uint8Array) at its index, null elsewhere. error is ETIMEDOUT after `timeout`
|
|
16
|
+
* ms, ENOBUFS past `maxBuffer` bytes of output (the child is then sent killSignal), or the
|
|
17
|
+
* spawn's. */
|
|
18
|
+
#define _POSIX_C_SOURCE 200809L /* libuv's headers: pthread_rwlock_t */
|
|
19
|
+
#include <math.h>
|
|
20
|
+
#include <signal.h>
|
|
21
|
+
#include <stdlib.h>
|
|
22
|
+
#include <string.h>
|
|
23
|
+
|
|
24
|
+
#include "js_buffer.h"
|
|
25
|
+
#include "js_convert.h"
|
|
26
|
+
#include "js_exception.h"
|
|
27
|
+
#include "js_gc.h"
|
|
28
|
+
#include "js_node.h"
|
|
29
|
+
#include "js_ops.h"
|
|
30
|
+
#include "js_uv.h"
|
|
31
|
+
#include "jscontext.h"
|
|
32
|
+
#include "jsstring.h"
|
|
33
|
+
|
|
34
|
+
#define HOST_FN(name) JSValue name(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target)
|
|
35
|
+
#define UNUSED (void)callee, (void)this_val, (void)new_target
|
|
36
|
+
|
|
37
|
+
enum { STDIO_IGNORE, STDIO_PIPE, STDIO_OVERLAPPED, STDIO_FD, STDIO_STREAM };
|
|
38
|
+
enum { FLAG_DETACHED = 1, FLAG_WINDOWS_HIDE = 2, FLAG_VERBATIM = 4 };
|
|
39
|
+
|
|
40
|
+
/* ---- Arguments ------------------------------------------------------------------------------ */
|
|
41
|
+
|
|
42
|
+
/* A string as malloc'd UTF-8. */
|
|
43
|
+
static char *utf8(JSContext *ctx, JSValue v) {
|
|
44
|
+
JSStrView view = js_string_view(ctx, v);
|
|
45
|
+
size_t n = js_view_to_utf8(view, NULL, 0);
|
|
46
|
+
char *s = malloc(n + 1);
|
|
47
|
+
if (!s) js_fatal("out of memory in child_process");
|
|
48
|
+
js_view_to_utf8(view, s, n);
|
|
49
|
+
s[n] = '\0';
|
|
50
|
+
return s;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* An array of strings as a NULL-terminated array of malloc'd UTF-8; NULL for anything else. */
|
|
54
|
+
static char **string_list(JSContext *ctx, JSValue v) {
|
|
55
|
+
if (!js_is_array(v)) return NULL;
|
|
56
|
+
uint32_t n = js_array_length(js_as_object(v));
|
|
57
|
+
char **list = calloc(n + 1, sizeof *list);
|
|
58
|
+
if (!list) js_fatal("out of memory in child_process");
|
|
59
|
+
for (uint32_t i = 0; i < n; i++) {
|
|
60
|
+
JSValue s = js_get_index(ctx, v, js_int32((int32_t)i));
|
|
61
|
+
list[i] = utf8(ctx, js_is_string(s) ? s : js_empty_string());
|
|
62
|
+
}
|
|
63
|
+
return list;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static void free_list(char **list) {
|
|
67
|
+
if (!list) return;
|
|
68
|
+
for (char **p = list; *p; p++) free(*p);
|
|
69
|
+
free(list);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static int int_arg(uint32_t argc, const JSValue *argv, uint32_t i, int fallback) {
|
|
73
|
+
return i < argc && js_is_number(argv[i]) ? (int)js_as_number(argv[i]) : fallback;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* The options both spawns share, as uv_spawn takes them; the stdio containers come after. */
|
|
77
|
+
typedef struct SpawnArgs {
|
|
78
|
+
uv_process_options_t o;
|
|
79
|
+
char *file;
|
|
80
|
+
char **args;
|
|
81
|
+
char **env;
|
|
82
|
+
char *cwd;
|
|
83
|
+
uint32_t nstdio;
|
|
84
|
+
int *kinds;
|
|
85
|
+
JSValue stdio;
|
|
86
|
+
} SpawnArgs;
|
|
87
|
+
|
|
88
|
+
static bool spawn_args(JSContext *ctx, uint32_t argc, const JSValue *argv, SpawnArgs *a) {
|
|
89
|
+
memset(a, 0, sizeof *a);
|
|
90
|
+
if (argc < 8 || !js_is_string(argv[0]) || !js_is_array(argv[1]) || !js_is_array(argv[4])) return false;
|
|
91
|
+
a->file = utf8(ctx, argv[0]);
|
|
92
|
+
a->args = string_list(ctx, argv[1]);
|
|
93
|
+
a->env = string_list(ctx, argv[2]); /* barrier: not a cell */
|
|
94
|
+
a->cwd = js_is_string(argv[3]) ? utf8(ctx, argv[3]) : NULL;
|
|
95
|
+
a->stdio = argv[4];
|
|
96
|
+
a->nstdio = js_array_length(js_as_object(argv[4]));
|
|
97
|
+
a->kinds = calloc(a->nstdio ? a->nstdio : 1, sizeof *a->kinds);
|
|
98
|
+
if (!a->kinds) js_fatal("out of memory in child_process");
|
|
99
|
+
a->o.file = a->file;
|
|
100
|
+
a->o.args = a->args;
|
|
101
|
+
a->o.env = a->env;
|
|
102
|
+
a->o.cwd = a->cwd;
|
|
103
|
+
int flags = int_arg(argc, argv, 5, 0);
|
|
104
|
+
int uid = int_arg(argc, argv, 6, -1), gid = int_arg(argc, argv, 7, -1);
|
|
105
|
+
if (uid >= 0) a->o.flags |= UV_PROCESS_SETUID, a->o.uid = (uv_uid_t)uid;
|
|
106
|
+
if (gid >= 0) a->o.flags |= UV_PROCESS_SETGID, a->o.gid = (uv_gid_t)gid;
|
|
107
|
+
if (flags & FLAG_DETACHED) a->o.flags |= UV_PROCESS_DETACHED;
|
|
108
|
+
if (flags & FLAG_WINDOWS_HIDE) a->o.flags |= UV_PROCESS_WINDOWS_HIDE;
|
|
109
|
+
if (flags & FLAG_VERBATIM) a->o.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static void free_spawn_args(SpawnArgs *a) {
|
|
114
|
+
free(a->file);
|
|
115
|
+
free_list(a->args);
|
|
116
|
+
free_list(a->env);
|
|
117
|
+
free(a->cwd);
|
|
118
|
+
free(a->kinds);
|
|
119
|
+
free(a->o.stdio);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* stdio[i] as [kind, value] */
|
|
123
|
+
static int stdio_entry(JSContext *ctx, SpawnArgs *a, uint32_t i, JSValue *value) {
|
|
124
|
+
JSValue e = js_get_index(ctx, a->stdio, js_int32((int32_t)i));
|
|
125
|
+
*value = js_is_array(e) ? js_get_index(ctx, e, js_int32(1)) : JS_UNDEFINED;
|
|
126
|
+
JSValue k = js_is_array(e) ? js_get_index(ctx, e, js_int32(0)) : JS_UNDEFINED;
|
|
127
|
+
return js_is_int32(k) ? js_as_int32(k) : STDIO_IGNORE;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* ---- Processes ------------------------------------------------------------------------------ */
|
|
131
|
+
|
|
132
|
+
typedef struct Process {
|
|
133
|
+
uv_process_t proc;
|
|
134
|
+
int id;
|
|
135
|
+
bool closing;
|
|
136
|
+
JSValue cb; /* a root */
|
|
137
|
+
} Process;
|
|
138
|
+
|
|
139
|
+
static Process **procs;
|
|
140
|
+
static size_t nprocs;
|
|
141
|
+
|
|
142
|
+
static Process *new_process(JSContext *ctx, JSValue cb) {
|
|
143
|
+
Process *p = calloc(1, sizeof *p);
|
|
144
|
+
if (!p) js_fatal("out of memory in child_process");
|
|
145
|
+
size_t id = 0;
|
|
146
|
+
while (id < nprocs && procs[id]) id++;
|
|
147
|
+
if (id == nprocs) {
|
|
148
|
+
size_t n = nprocs ? nprocs * 2 : 8;
|
|
149
|
+
Process **v = realloc(procs, n * sizeof *v);
|
|
150
|
+
if (!v) js_fatal("out of memory in child_process");
|
|
151
|
+
memset(v + nprocs, 0, (n - nprocs) * sizeof *v);
|
|
152
|
+
procs = v;
|
|
153
|
+
nprocs = n;
|
|
154
|
+
}
|
|
155
|
+
procs[id] = p;
|
|
156
|
+
p->id = (int)id;
|
|
157
|
+
p->cb = cb;
|
|
158
|
+
js_add_root(ctx->rt, &p->cb);
|
|
159
|
+
return p;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static void free_process(Process *p) {
|
|
163
|
+
procs[p->id] = NULL;
|
|
164
|
+
js_remove_root(js_uv_context()->rt, &p->cb);
|
|
165
|
+
free(p);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static void on_process_closed(uv_handle_t *h) {
|
|
169
|
+
free_process((Process *)h);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
static void on_exit(uv_process_t *proc, int64_t exit_status, int term_signal) {
|
|
173
|
+
Process *p = (Process *)proc;
|
|
174
|
+
JSValue args[2] = { js_number((double)exit_status), js_int32(term_signal) };
|
|
175
|
+
(void)js_uv_call(p->cb, 2, args, NULL);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static Process *process_arg(uint32_t argc, const JSValue *argv) {
|
|
179
|
+
int32_t id = argc > 0 && js_is_int32(argv[0]) ? js_as_int32(argv[0]) : -1;
|
|
180
|
+
Process *p = id >= 0 && (size_t)id < nprocs ? procs[id] : NULL;
|
|
181
|
+
return p && !p->closing ? p : NULL;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* processSpawn(file, args, envPairs, cwd, stdio, flags, uid, gid, cb) → [0, id, pid] | [-errno] */
|
|
185
|
+
HOST_FN(js_host_process_spawn) {
|
|
186
|
+
UNUSED;
|
|
187
|
+
SpawnArgs a;
|
|
188
|
+
if (!spawn_args(ctx, argc, argv, &a) || argc < 9 || !js_is_callable(argv[8])) {
|
|
189
|
+
free_spawn_args(&a);
|
|
190
|
+
return js_throw_type_error(ctx, "processSpawn: bad arguments");
|
|
191
|
+
}
|
|
192
|
+
a.o.exit_cb = on_exit;
|
|
193
|
+
a.o.stdio_count = (int)a.nstdio;
|
|
194
|
+
a.o.stdio = calloc(a.nstdio ? a.nstdio : 1, sizeof *a.o.stdio);
|
|
195
|
+
if (!a.o.stdio) js_fatal("out of memory in child_process");
|
|
196
|
+
for (uint32_t i = 0; i < a.nstdio; i++) {
|
|
197
|
+
JSValue value;
|
|
198
|
+
int kind = stdio_entry(ctx, &a, i, &value);
|
|
199
|
+
uv_stdio_container_t *c = &a.o.stdio[i];
|
|
200
|
+
int id = js_is_int32(value) ? js_as_int32(value) : -1;
|
|
201
|
+
switch (kind) {
|
|
202
|
+
case STDIO_PIPE:
|
|
203
|
+
case STDIO_OVERLAPPED:
|
|
204
|
+
c->data.stream = js_net_stream(id);
|
|
205
|
+
/* as Node's ProcessWrap: readable and writable both, whichever end the child uses */
|
|
206
|
+
c->flags = c->data.stream ? UV_CREATE_PIPE | UV_READABLE_PIPE | UV_WRITABLE_PIPE | (kind == STDIO_OVERLAPPED ? UV_OVERLAPPED_PIPE : 0) : UV_IGNORE;
|
|
207
|
+
break;
|
|
208
|
+
case STDIO_FD:
|
|
209
|
+
c->flags = UV_INHERIT_FD;
|
|
210
|
+
c->data.fd = id;
|
|
211
|
+
break;
|
|
212
|
+
case STDIO_STREAM:
|
|
213
|
+
c->data.stream = js_net_stream(id);
|
|
214
|
+
c->flags = c->data.stream ? UV_INHERIT_STREAM : UV_IGNORE;
|
|
215
|
+
break;
|
|
216
|
+
default:
|
|
217
|
+
c->flags = UV_IGNORE;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
Process *p = new_process(ctx, argv[8]);
|
|
221
|
+
int r = uv_spawn(js_uv_loop(ctx), &p->proc, &a.o);
|
|
222
|
+
free_spawn_args(&a);
|
|
223
|
+
if (r < 0) {
|
|
224
|
+
/* libuv initialized the handle even so: it still has to be closed */
|
|
225
|
+
p->closing = true;
|
|
226
|
+
uv_close((uv_handle_t *)&p->proc, on_process_closed);
|
|
227
|
+
JSValue items[1] = { js_int32(r) };
|
|
228
|
+
return js_new_array_from(ctx, items, 1);
|
|
229
|
+
}
|
|
230
|
+
JSValue items[3] = { js_int32(0), js_int32(p->id), js_number((double)p->proc.pid) };
|
|
231
|
+
return js_new_array_from(ctx, items, 3);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* processKill(id, signum) → 0 | -errno */
|
|
235
|
+
HOST_FN(js_host_process_kill_child) {
|
|
236
|
+
UNUSED;
|
|
237
|
+
(void)ctx;
|
|
238
|
+
Process *p = process_arg(argc, argv);
|
|
239
|
+
if (!p) return js_int32(UV_ESRCH);
|
|
240
|
+
return js_int32(uv_process_kill(&p->proc, int_arg(argc, argv, 1, 15)));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* processRef(id, ref): an unref'd child doesn't keep the program running */
|
|
244
|
+
HOST_FN(js_host_process_ref) {
|
|
245
|
+
UNUSED;
|
|
246
|
+
(void)ctx;
|
|
247
|
+
Process *p = process_arg(argc, argv);
|
|
248
|
+
if (p && argc > 1) {
|
|
249
|
+
if (js_truthy(argv[1])) uv_ref((uv_handle_t *)&p->proc);
|
|
250
|
+
else uv_unref((uv_handle_t *)&p->proc);
|
|
251
|
+
}
|
|
252
|
+
return JS_UNDEFINED;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* processClose(id): after its exit; the callback isn't called again */
|
|
256
|
+
HOST_FN(js_host_process_close) {
|
|
257
|
+
UNUSED;
|
|
258
|
+
(void)ctx;
|
|
259
|
+
Process *p = process_arg(argc, argv);
|
|
260
|
+
if (p) {
|
|
261
|
+
p->closing = true;
|
|
262
|
+
uv_close((uv_handle_t *)&p->proc, on_process_closed);
|
|
263
|
+
}
|
|
264
|
+
return JS_UNDEFINED;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/* ---- spawnSync (Node's SyncProcessRunner) --------------------------------------------------- */
|
|
268
|
+
|
|
269
|
+
typedef struct SyncRun SyncRun;
|
|
270
|
+
|
|
271
|
+
typedef struct SyncPipe {
|
|
272
|
+
uv_pipe_t pipe;
|
|
273
|
+
SyncRun *run;
|
|
274
|
+
bool used;
|
|
275
|
+
uint8_t *input;
|
|
276
|
+
size_t input_len;
|
|
277
|
+
uint8_t *out;
|
|
278
|
+
size_t out_len, out_cap;
|
|
279
|
+
uv_write_t write_req;
|
|
280
|
+
uv_shutdown_t shutdown_req;
|
|
281
|
+
} SyncPipe;
|
|
282
|
+
|
|
283
|
+
struct SyncRun {
|
|
284
|
+
uv_loop_t loop;
|
|
285
|
+
uv_process_t proc;
|
|
286
|
+
uv_timer_t timer;
|
|
287
|
+
bool timer_started;
|
|
288
|
+
SyncPipe *pipes;
|
|
289
|
+
uint32_t npipes;
|
|
290
|
+
double max_buffer;
|
|
291
|
+
size_t buffered;
|
|
292
|
+
int kill_signal;
|
|
293
|
+
int error;
|
|
294
|
+
bool exited, killed;
|
|
295
|
+
int64_t exit_status;
|
|
296
|
+
int term_signal;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
static void sync_kill(SyncRun *r) {
|
|
300
|
+
if (r->killed || r->exited) return;
|
|
301
|
+
r->killed = true;
|
|
302
|
+
int e = uv_process_kill(&r->proc, r->kill_signal);
|
|
303
|
+
/* as Node: when the signal can't be sent, SIGKILL instead */
|
|
304
|
+
if (e < 0 && e != UV_ESRCH) {
|
|
305
|
+
if (!r->error) r->error = e;
|
|
306
|
+
uv_process_kill(&r->proc, SIGKILL);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
static void sync_alloc(uv_handle_t *h, size_t suggested, uv_buf_t *buf) {
|
|
311
|
+
SyncPipe *sp = (SyncPipe *)h;
|
|
312
|
+
if (sp->out_cap - sp->out_len < suggested) {
|
|
313
|
+
size_t cap = sp->out_cap ? sp->out_cap * 2 : 65536;
|
|
314
|
+
while (cap - sp->out_len < suggested) cap *= 2;
|
|
315
|
+
uint8_t *b = realloc(sp->out, cap);
|
|
316
|
+
if (!b) js_fatal("out of memory in child_process");
|
|
317
|
+
sp->out = b;
|
|
318
|
+
sp->out_cap = cap;
|
|
319
|
+
}
|
|
320
|
+
buf->base = (char *)sp->out + sp->out_len;
|
|
321
|
+
buf->len = sp->out_cap - sp->out_len;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
static void sync_read(uv_stream_t *s, ssize_t n, const uv_buf_t *buf) {
|
|
325
|
+
(void)buf;
|
|
326
|
+
SyncPipe *sp = (SyncPipe *)s;
|
|
327
|
+
SyncRun *r = sp->run;
|
|
328
|
+
if (n > 0) {
|
|
329
|
+
sp->out_len += (size_t)n;
|
|
330
|
+
r->buffered += (size_t)n;
|
|
331
|
+
if ((double)r->buffered > r->max_buffer) {
|
|
332
|
+
if (!r->error) r->error = UV_ENOBUFS;
|
|
333
|
+
sync_kill(r);
|
|
334
|
+
}
|
|
335
|
+
} else if (n < 0) {
|
|
336
|
+
uv_read_stop(s);
|
|
337
|
+
if (!uv_is_closing((uv_handle_t *)s)) uv_close((uv_handle_t *)s, NULL);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
static void sync_shutdown(uv_shutdown_t *req, int status) {
|
|
342
|
+
(void)status;
|
|
343
|
+
SyncPipe *sp = (SyncPipe *)req->data;
|
|
344
|
+
/* the child may still write to it: reading goes on until it ends */
|
|
345
|
+
(void)sp;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
static void sync_written(uv_write_t *req, int status) {
|
|
349
|
+
SyncPipe *sp = (SyncPipe *)req->data;
|
|
350
|
+
if (status < 0 && status != UV_EPIPE && !sp->run->error) sp->run->error = status;
|
|
351
|
+
sp->shutdown_req.data = sp;
|
|
352
|
+
if (uv_shutdown(&sp->shutdown_req, (uv_stream_t *)&sp->pipe, sync_shutdown) < 0 && !uv_is_closing((uv_handle_t *)&sp->pipe))
|
|
353
|
+
uv_close((uv_handle_t *)&sp->pipe, NULL);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
static void sync_exit(uv_process_t *proc, int64_t exit_status, int term_signal) {
|
|
357
|
+
SyncRun *r = (SyncRun *)proc->data;
|
|
358
|
+
r->exited = true;
|
|
359
|
+
r->exit_status = exit_status;
|
|
360
|
+
r->term_signal = term_signal;
|
|
361
|
+
uv_close((uv_handle_t *)proc, NULL);
|
|
362
|
+
if (r->timer_started) uv_close((uv_handle_t *)&r->timer, NULL);
|
|
363
|
+
r->timer_started = false;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
static void sync_timeout(uv_timer_t *t) {
|
|
367
|
+
SyncRun *r = (SyncRun *)t->data;
|
|
368
|
+
if (!r->error) r->error = UV_ETIMEDOUT;
|
|
369
|
+
sync_kill(r);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
static void close_any(uv_handle_t *h, void *arg) {
|
|
373
|
+
(void)arg;
|
|
374
|
+
if (!uv_is_closing(h)) uv_close(h, NULL);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/* processSpawnSync(file, args, envPairs, cwd, stdio, flags, uid, gid, timeout, maxBuffer, killSignal)
|
|
378
|
+
* → [error, pid, exitStatus, termSignal, output] */
|
|
379
|
+
HOST_FN(js_host_process_spawn_sync) {
|
|
380
|
+
UNUSED;
|
|
381
|
+
SpawnArgs a;
|
|
382
|
+
if (!spawn_args(ctx, argc, argv, &a)) {
|
|
383
|
+
free_spawn_args(&a);
|
|
384
|
+
return js_throw_type_error(ctx, "processSpawnSync: bad arguments");
|
|
385
|
+
}
|
|
386
|
+
SyncRun *r = calloc(1, sizeof *r);
|
|
387
|
+
if (!r) js_fatal("out of memory in child_process");
|
|
388
|
+
double timeout = argc > 8 && js_is_number(argv[8]) ? js_as_number(argv[8]) : 0;
|
|
389
|
+
r->max_buffer = argc > 9 && js_is_number(argv[9]) ? js_as_number(argv[9]) : INFINITY;
|
|
390
|
+
r->kill_signal = int_arg(argc, argv, 10, SIGTERM);
|
|
391
|
+
#ifndef _WIN32
|
|
392
|
+
/* a child that exits before it reads its input: writing it fails with EPIPE (sync_written)
|
|
393
|
+
* instead of killing the process, as in Node (which ignores SIGPIPE at startup). This loop
|
|
394
|
+
* is its own: js_uv_loop, which does the same, may not have run. */
|
|
395
|
+
signal(SIGPIPE, SIG_IGN);
|
|
396
|
+
#endif
|
|
397
|
+
uv_loop_init(&r->loop);
|
|
398
|
+
r->npipes = a.nstdio;
|
|
399
|
+
r->pipes = calloc(a.nstdio ? a.nstdio : 1, sizeof *r->pipes);
|
|
400
|
+
a.o.stdio = calloc(a.nstdio ? a.nstdio : 1, sizeof *a.o.stdio);
|
|
401
|
+
if (!r->pipes || !a.o.stdio) js_fatal("out of memory in child_process");
|
|
402
|
+
a.o.stdio_count = (int)a.nstdio;
|
|
403
|
+
a.o.exit_cb = sync_exit;
|
|
404
|
+
for (uint32_t i = 0; i < a.nstdio; i++) {
|
|
405
|
+
JSValue value;
|
|
406
|
+
int kind = stdio_entry(ctx, &a, i, &value);
|
|
407
|
+
uv_stdio_container_t *c = &a.o.stdio[i];
|
|
408
|
+
SyncPipe *sp = &r->pipes[i];
|
|
409
|
+
sp->run = r;
|
|
410
|
+
if (kind == STDIO_PIPE || kind == STDIO_OVERLAPPED) {
|
|
411
|
+
uv_pipe_init(&r->loop, &sp->pipe, 0);
|
|
412
|
+
sp->used = true;
|
|
413
|
+
c->flags = UV_CREATE_PIPE | UV_READABLE_PIPE | UV_WRITABLE_PIPE | (kind == STDIO_OVERLAPPED ? UV_OVERLAPPED_PIPE : 0);
|
|
414
|
+
c->data.stream = (uv_stream_t *)&sp->pipe;
|
|
415
|
+
uint8_t *bytes;
|
|
416
|
+
size_t n;
|
|
417
|
+
if (js_buffer_source_bytes(value, &bytes, &n)) {
|
|
418
|
+
/* copied: no JS runs until the child is done, but the bytes aren't ours */
|
|
419
|
+
sp->input = malloc(n ? n : 1);
|
|
420
|
+
if (!sp->input) js_fatal("out of memory in child_process");
|
|
421
|
+
memcpy(sp->input, bytes, n);
|
|
422
|
+
sp->input_len = n;
|
|
423
|
+
}
|
|
424
|
+
} else if (kind == STDIO_FD) {
|
|
425
|
+
c->flags = UV_INHERIT_FD;
|
|
426
|
+
c->data.fd = js_is_int32(value) ? js_as_int32(value) : (int)i;
|
|
427
|
+
} else {
|
|
428
|
+
c->flags = UV_IGNORE;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
r->proc.data = r;
|
|
432
|
+
int e = uv_spawn(&r->loop, &r->proc, &a.o);
|
|
433
|
+
free_spawn_args(&a);
|
|
434
|
+
if (e < 0) {
|
|
435
|
+
r->error = e;
|
|
436
|
+
uv_close((uv_handle_t *)&r->proc, NULL);
|
|
437
|
+
} else {
|
|
438
|
+
for (uint32_t i = 0; i < r->npipes; i++) {
|
|
439
|
+
SyncPipe *sp = &r->pipes[i];
|
|
440
|
+
if (!sp->used) continue;
|
|
441
|
+
if (i == 0 || sp->input) {
|
|
442
|
+
/* the child's input: written, then the pipe shut down (an empty input too) */
|
|
443
|
+
sp->write_req.data = sp;
|
|
444
|
+
uv_buf_t b = uv_buf_init((char *)(sp->input ? sp->input : (uint8_t *)""), (unsigned)sp->input_len);
|
|
445
|
+
if (uv_write(&sp->write_req, (uv_stream_t *)&sp->pipe, &b, 1, sync_written) < 0) uv_close((uv_handle_t *)&sp->pipe, NULL);
|
|
446
|
+
} else {
|
|
447
|
+
uv_read_start((uv_stream_t *)&sp->pipe, sync_alloc, sync_read);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (timeout > 0) {
|
|
451
|
+
uv_timer_init(&r->loop, &r->timer);
|
|
452
|
+
r->timer.data = r;
|
|
453
|
+
uv_timer_start(&r->timer, sync_timeout, (uint64_t)timeout, 0);
|
|
454
|
+
r->timer_started = true;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
uv_run(&r->loop, UV_RUN_DEFAULT);
|
|
458
|
+
uv_walk(&r->loop, close_any, NULL);
|
|
459
|
+
uv_run(&r->loop, UV_RUN_DEFAULT);
|
|
460
|
+
uv_loop_close(&r->loop);
|
|
461
|
+
|
|
462
|
+
JSValue output = js_new_array(ctx, 0);
|
|
463
|
+
for (uint32_t i = 0; i < r->npipes; i++) {
|
|
464
|
+
SyncPipe *sp = &r->pipes[i];
|
|
465
|
+
JSValue v = JS_NULL;
|
|
466
|
+
if (sp->used && !sp->input && i != 0) {
|
|
467
|
+
v = js_new_uint8_array(ctx, sp->out_len);
|
|
468
|
+
if (js_is_exception(v)) js_fatal("out of memory in child_process");
|
|
469
|
+
uint8_t *data;
|
|
470
|
+
size_t len;
|
|
471
|
+
js_buffer_source_bytes(v, &data, &len);
|
|
472
|
+
if (sp->out_len) memcpy(data, sp->out, sp->out_len);
|
|
473
|
+
}
|
|
474
|
+
free(sp->out);
|
|
475
|
+
free(sp->input);
|
|
476
|
+
if (js_array_push(ctx, js_as_object(output), v) < 0) js_fatal("out of memory in child_process");
|
|
477
|
+
}
|
|
478
|
+
JSValue items[5] = {
|
|
479
|
+
js_int32(r->error),
|
|
480
|
+
js_number(e < 0 ? 0 : (double)r->proc.pid),
|
|
481
|
+
r->exited ? js_number((double)r->exit_status) : JS_NULL,
|
|
482
|
+
js_int32(r->term_signal),
|
|
483
|
+
output,
|
|
484
|
+
};
|
|
485
|
+
free(r->pipes);
|
|
486
|
+
free(r);
|
|
487
|
+
return js_new_array_from(ctx, items, 5);
|
|
488
|
+
}
|
package/node/src/host_sys.c
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Host primitives shared by the prelude modules
|
|
1
|
+
/* Host primitives shared by the prelude modules: error names and messages for
|
|
2
2
|
* -errno results, as libuv words them (Node's err.code and message). The working directory
|
|
3
3
|
* (cwd) is the runtime's, for process.cwd(). */
|
|
4
4
|
#define _POSIX_C_SOURCE 200809L /* libuv's headers (the UV_E* codes): pthread_rwlock_t */
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
#include "js_exception.h"
|
|
18
18
|
#include "js_jobs.h"
|
|
19
|
+
#include "jscontext.h"
|
|
19
20
|
#include "js_ops.h"
|
|
20
21
|
#include "jsstring.h"
|
|
21
22
|
|
|
@@ -53,6 +54,26 @@ static const struct { int code, uv; const char *name, *message; } ERRORS[] = {
|
|
|
53
54
|
E(ENETUNREACH, "network is unreachable"),
|
|
54
55
|
E(EHOSTUNREACH, "host is unreachable"),
|
|
55
56
|
E(ECANCELED, "operation canceled"),
|
|
57
|
+
E(ENOBUFS, "no buffer space available"),
|
|
58
|
+
E(EAGAIN, "resource temporarily unavailable"),
|
|
59
|
+
E(ENFILE, "file table overflow"),
|
|
60
|
+
E(ENOSYS, "function not implemented"),
|
|
61
|
+
E(ENOMEM, "not enough memory"),
|
|
62
|
+
E(E2BIG, "argument list too long"),
|
|
63
|
+
E(EFAULT, "bad address in system call argument"),
|
|
64
|
+
E(EINTR, "interrupted system call"),
|
|
65
|
+
E(EMSGSIZE, "message too long"),
|
|
66
|
+
E(ENOTSOCK, "socket operation on non-socket"),
|
|
67
|
+
E(ENOTSUP, "operation not supported on socket"),
|
|
68
|
+
E(EOVERFLOW, "value too large for defined data type"),
|
|
69
|
+
E(EPROTO, "protocol error"),
|
|
70
|
+
E(ERANGE, "result too large"),
|
|
71
|
+
E(ESPIPE, "invalid seek"),
|
|
72
|
+
E(ETXTBSY, "text file is busy"),
|
|
73
|
+
E(EXDEV, "cross-device link not permitted"),
|
|
74
|
+
E(ENXIO, "no such device or address"),
|
|
75
|
+
E(EMLINK, "too many links"),
|
|
76
|
+
E(ENOTTY, "inappropriate ioctl for device"),
|
|
56
77
|
};
|
|
57
78
|
#undef E
|
|
58
79
|
|
|
@@ -86,6 +107,33 @@ JSValue js_host_errno_message(JSContext *ctx, JSValue callee, JSValue this_val,
|
|
|
86
107
|
return js_new_string_cstr(ctx, "unknown error");
|
|
87
108
|
}
|
|
88
109
|
|
|
110
|
+
/* errnoMap() → [[uv code, name, message], …]: libuv's every error, in its order
|
|
111
|
+
* (util.getSystemErrorMap). Its names and codes are compile-time constants: nothing of libuv is
|
|
112
|
+
* linked. */
|
|
113
|
+
JSValue js_host_errno_map(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
|
|
114
|
+
const JSValue *argv, JSValue new_target) {
|
|
115
|
+
(void)callee, (void)this_val, (void)argc, (void)argv, (void)new_target;
|
|
116
|
+
static const struct { int code; const char *name, *message; } map[] = {
|
|
117
|
+
#define XX(name, message) { UV_##name, #name, message },
|
|
118
|
+
UV_ERRNO_MAP(XX)
|
|
119
|
+
#undef XX
|
|
120
|
+
};
|
|
121
|
+
size_t n = sizeof map / sizeof map[0];
|
|
122
|
+
/* each entry kept in the result as it's made: the collector sees it there */
|
|
123
|
+
JSValue result = js_new_array(ctx, (uint32_t)n);
|
|
124
|
+
if (js_is_exception(result)) return result;
|
|
125
|
+
for (size_t i = 0; i < n; i++) {
|
|
126
|
+
JSValue entry = js_new_array(ctx, 3);
|
|
127
|
+
if (js_is_exception(entry) || js_array_push(ctx, js_as_object(result), entry) < 0) return JS_EXCEPTION;
|
|
128
|
+
JSValue name = js_new_string_cstr(ctx, map[i].name);
|
|
129
|
+
if (js_is_exception(name) || js_array_push(ctx, js_as_object(entry), js_int32(map[i].code)) < 0 ||
|
|
130
|
+
js_array_push(ctx, js_as_object(entry), name) < 0) return JS_EXCEPTION;
|
|
131
|
+
JSValue message = js_new_string_cstr(ctx, map[i].message);
|
|
132
|
+
if (js_is_exception(message) || js_array_push(ctx, js_as_object(entry), message) < 0) return JS_EXCEPTION;
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
|
|
89
137
|
/* ttyIsatty(fd): whether the descriptor is a terminal (node:tty's isatty). */
|
|
90
138
|
JSValue js_host_tty_isatty(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv,
|
|
91
139
|
JSValue new_target) {
|
|
@@ -122,7 +170,7 @@ JSValue js_host_timer_start(JSContext *ctx, JSValue callee, JSValue this_val, ui
|
|
|
122
170
|
return js_int32((int32_t)js_timer_start(ctx, argv[0], ms, ms < 0, !js_truthy(argv[2]), timer_id(argc, argv, 3)));
|
|
123
171
|
}
|
|
124
172
|
|
|
125
|
-
/* asyncContextGet() → the current async context
|
|
173
|
+
/* asyncContextGet() → the current async context: undefined, or AsyncLocalStorage's frame */
|
|
126
174
|
JSValue js_host_async_context_get(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv,
|
|
127
175
|
JSValue new_target) {
|
|
128
176
|
(void)callee, (void)this_val, (void)argc, (void)argv, (void)new_target;
|
|
@@ -154,3 +202,17 @@ JSValue js_host_timer_clear(JSContext *ctx, JSValue callee, JSValue this_val, ui
|
|
|
154
202
|
if (id) js_timer_clear(ctx, id);
|
|
155
203
|
return JS_UNDEFINED;
|
|
156
204
|
}
|
|
205
|
+
|
|
206
|
+
/* processMemory(): [rss, heapTotal, heapUsed] in bytes, for process.memoryUsage(): the resident
|
|
207
|
+
* set (libuv), the GC heap's mapped blocks, and what the last collection kept plus what was
|
|
208
|
+
* allocated since. */
|
|
209
|
+
JSValue js_host_process_memory(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv,
|
|
210
|
+
JSValue new_target) {
|
|
211
|
+
(void)callee, (void)this_val, (void)argc, (void)argv, (void)new_target;
|
|
212
|
+
size_t rss = 0;
|
|
213
|
+
if (uv_resident_set_memory(&rss) != 0) rss = 0;
|
|
214
|
+
const JSHeap *h = &ctx->rt->heap;
|
|
215
|
+
JSValue items[3] = { js_number((double)rss), js_number((double)js_heap_size(ctx->rt)),
|
|
216
|
+
js_number((double)(h->live_after_gc + h->allocated_since_gc)) };
|
|
217
|
+
return js_new_array_from(ctx, items, 3);
|
|
218
|
+
}
|
package/node/src/host_zlib.c
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
/* Host primitives for node:zlib
|
|
1
|
+
/* Host primitives for node:zlib: Node's zlib binding (src/node_zlib.cc, its
|
|
2
2
|
* ZlibContext) over Chromium's zlib, the copy Node vendors, so a program compresses to the bytes
|
|
3
3
|
* Node gives. A stream is a handle object; the prelude (node/prelude/zlib.js) is Node's lib/zlib.js
|
|
4
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.
|
|
5
|
+
* returned as [message, errno, code], what Node's binding passes to the stream's onerror.
|
|
6
|
+
*
|
|
7
|
+
* Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE. */
|
|
6
8
|
#include <stdlib.h>
|
|
7
9
|
#include <string.h>
|
|
8
10
|
|
|
9
11
|
#include "js_buffer.h"
|
|
10
12
|
#include "js_exception.h"
|
|
13
|
+
#include "js_gc.h"
|
|
11
14
|
#include "js_node.h"
|
|
15
|
+
#include "js_web.h"
|
|
12
16
|
#include "js_object.h"
|
|
13
17
|
#include "js_ops.h"
|
|
14
18
|
#include "jsstring.h"
|
|
@@ -34,6 +38,7 @@ typedef struct ZlibObject {
|
|
|
34
38
|
int err;
|
|
35
39
|
int gzip_id_bytes_read;
|
|
36
40
|
bool zlib_init_done;
|
|
41
|
+
bool reject_garbage_after_end; /* GUNZIP: no further members after the first */
|
|
37
42
|
uint8_t *dictionary; /* malloc'd; NULL when empty */
|
|
38
43
|
size_t dictionary_len;
|
|
39
44
|
} ZlibObject;
|
|
@@ -170,7 +175,8 @@ static void process(ZlibObject *z) {
|
|
|
170
175
|
else if (z->err == Z_DATA_ERROR) z->err = Z_NEED_DICT; /* a bad dictionary, not bad input */
|
|
171
176
|
}
|
|
172
177
|
/* 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->
|
|
178
|
+
while (z->strm.avail_in > 0 && z->mode == GUNZIP && z->err == Z_STREAM_END && !z->reject_garbage_after_end &&
|
|
179
|
+
z->strm.next_in[0] != 0x00) {
|
|
174
180
|
reset_stream(z);
|
|
175
181
|
z->err = inflate(&z->strm, z->flush);
|
|
176
182
|
}
|
|
@@ -196,16 +202,25 @@ static const char *error_message(ZlibObject *z) {
|
|
|
196
202
|
}
|
|
197
203
|
}
|
|
198
204
|
|
|
205
|
+
/* zlib's memory is the heap's external memory: a deflate stream's is about
|
|
206
|
+
* 256 KiB. */
|
|
207
|
+
static voidpf zlib_alloc(voidpf rt, uInt items, uInt size) { return js_gc_external_malloc(rt, (size_t)items * size); }
|
|
208
|
+
static void zlib_free(voidpf rt, voidpf p) { js_gc_external_free(rt, p); }
|
|
209
|
+
|
|
199
210
|
/* zlibNew(mode) → handle */
|
|
200
211
|
PRIMITIVE(js_host_zlib_new) {
|
|
201
212
|
UNUSED_PRIMITIVE_ARGS;
|
|
202
213
|
ZlibObject *z = (ZlibObject *)js_alloc_object(ctx, JS_CELL_OBJECT, js_shape_root(ctx, &zlib_class, JS_NULL, 0));
|
|
203
214
|
memset(&z->strm, 0, sizeof z->strm);
|
|
215
|
+
z->strm.zalloc = zlib_alloc;
|
|
216
|
+
z->strm.zfree = zlib_free;
|
|
217
|
+
z->strm.opaque = ctx->rt;
|
|
204
218
|
z->mode = int_arg(ARG(0));
|
|
205
219
|
z->flush = Z_NO_FLUSH;
|
|
206
220
|
z->err = Z_OK;
|
|
207
221
|
z->gzip_id_bytes_read = 0;
|
|
208
222
|
z->zlib_init_done = false;
|
|
223
|
+
z->reject_garbage_after_end = false;
|
|
209
224
|
z->dictionary = NULL;
|
|
210
225
|
z->dictionary_len = 0;
|
|
211
226
|
return js_object_value(&z->obj);
|
|
@@ -234,6 +249,7 @@ PRIMITIVE(js_host_zlib_init) {
|
|
|
234
249
|
memcpy(z->dictionary, p, n);
|
|
235
250
|
z->dictionary_len = n;
|
|
236
251
|
}
|
|
252
|
+
z->reject_garbage_after_end = js_truthy(ARG(6));
|
|
237
253
|
return JS_UNDEFINED;
|
|
238
254
|
}
|
|
239
255
|
|
|
@@ -249,8 +265,11 @@ PRIMITIVE(js_host_zlib_write) {
|
|
|
249
265
|
return js_throw_type_error(ctx, "zlibWrite: a handle, buffers and a state expected");
|
|
250
266
|
double in_off = in ? js_as_number(ARG(3)) : 0, in_len = in ? js_as_number(ARG(4)) : 0;
|
|
251
267
|
double out_off = js_as_number(ARG(6)), out_len = js_as_number(ARG(7));
|
|
252
|
-
|
|
253
|
-
|
|
268
|
+
/* node_zlib.cc's checks */
|
|
269
|
+
if (!(in_off >= 0 && in_len >= 0 && in_off + in_len <= (double)in_n))
|
|
270
|
+
return js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_OUT_OF_RANGE", "input buffer is out of bounds");
|
|
271
|
+
if (!(out_off >= 0 && out_len >= 0 && out_off + out_len <= (double)out_n))
|
|
272
|
+
return js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_OUT_OF_RANGE", "output buffer is out of bounds");
|
|
254
273
|
z->strm.next_in = in ? in + (size_t)in_off : NULL;
|
|
255
274
|
z->strm.avail_in = (uInt)in_len;
|
|
256
275
|
z->strm.next_out = out + (size_t)out_off;
|
|
@@ -301,14 +320,15 @@ PRIMITIVE(js_host_zlib_crc32) {
|
|
|
301
320
|
uLong value = js_is_number(ARG(1)) ? (uLong)js_as_number(ARG(1)) : 0;
|
|
302
321
|
uint8_t *p;
|
|
303
322
|
size_t n;
|
|
304
|
-
|
|
323
|
+
/* no bytes: the value as it is (zlib's crc32 gives 0 for a NULL buffer) */
|
|
324
|
+
if (js_buffer_source_bytes(ARG(0), &p, &n)) return js_number(n ? (double)crc32(value, p, (uInt)n) : (double)value);
|
|
305
325
|
if (!js_is_string(ARG(0))) return js_throw_type_error(ctx, "zlibCrc32: a string or bytes expected");
|
|
306
326
|
JSStrView view = js_string_view(ctx, ARG(0));
|
|
307
327
|
size_t len = js_view_to_utf8(view, NULL, 0);
|
|
308
328
|
char *utf8 = malloc(len ? len : 1);
|
|
309
329
|
if (!utf8) js_fatal("out of memory in zlib");
|
|
310
330
|
js_view_to_utf8(view, utf8, len);
|
|
311
|
-
value = crc32(value, (const Bytef *)utf8, (uInt)len);
|
|
331
|
+
if (len) value = crc32(value, (const Bytef *)utf8, (uInt)len);
|
|
312
332
|
free(utf8);
|
|
313
333
|
return js_number((double)value);
|
|
314
334
|
}
|