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
package/node/src/host_net.c
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* NET_CLOSE the handle is closed (netClose or netReset) and its id free
|
|
13
13
|
*
|
|
14
14
|
* netOpen(pipe, cb) → id a TCP handle, or with `pipe` a pipe's
|
|
15
|
-
* netOpenFd(id, fd) → 0 | -errno netGuessHandle(fd) → "TCP" | "PIPE" | "TTY" | …
|
|
15
|
+
* netOpenFd(id, fd) → 0 | -errno, netFd(id) → fd | -errno netGuessHandle(fd) → "TCP" | "PIPE" | "TTY" | …
|
|
16
16
|
* netBind(id, ip | path, port, flags), netListen(id, backlog) → 0 | -errno flags: 1 ipv6Only, 2 reusePort
|
|
17
17
|
* netChmod(id, mode) → 0 | -errno a listening pipe's: 1 readable, 2 writable by all
|
|
18
18
|
* netConnect(id, ip | path, port) → 0 | -errno (a NET_CONNECT follows)
|
|
@@ -22,8 +22,16 @@
|
|
|
22
22
|
* netShutdown(id), netClose(id), netReset(id) → 0 | -errno, netRef(id, ref)
|
|
23
23
|
* netAddress(id, peer) → [address, family, port] | path | -errno
|
|
24
24
|
* netNoDelay(id, on), netKeepAlive(id, on, seconds) → 0 | -errno
|
|
25
|
+
* netTypeOfService(id, tos) → 0 | -errno, and with tos -1 the socket's → tos | -errno
|
|
26
|
+
* ttyOpen(fd, cb) → id | -errno a terminal's handle (node:tty's ReadStream), read as
|
|
27
|
+
* a stream; it answers the pipe-only calls as a pipe
|
|
28
|
+
* ttySetRawMode(id, raw) → 0 | -errno
|
|
25
29
|
* dnsLookup(host, family, cb) → cb(errno, code, [[address, family], …]) */
|
|
26
30
|
#define _POSIX_C_SOURCE 200809L /* libuv's headers: pthread_rwlock_t, struct addrinfo */
|
|
31
|
+
#ifdef __APPLE__
|
|
32
|
+
#define _DARWIN_C_SOURCE /* IP_TOS, which _POSIX_C_SOURCE hides on macOS */
|
|
33
|
+
#endif
|
|
34
|
+
#include <errno.h>
|
|
27
35
|
#include <stdlib.h>
|
|
28
36
|
#include <string.h>
|
|
29
37
|
|
|
@@ -45,9 +53,11 @@ typedef struct NetHandle {
|
|
|
45
53
|
uv_stream_t stream;
|
|
46
54
|
uv_tcp_t tcp;
|
|
47
55
|
uv_pipe_t pipe;
|
|
56
|
+
uv_tty_t tty;
|
|
48
57
|
} u;
|
|
49
58
|
int id;
|
|
50
|
-
bool is_pipe;
|
|
59
|
+
bool is_pipe; /* a pipe's, or a terminal's (it has no address, nor TCP's options) */
|
|
60
|
+
bool is_tty;
|
|
51
61
|
const JSNetHook *hook; /* node:http's parser, which reads before JS */
|
|
52
62
|
void *hook_data;
|
|
53
63
|
bool closing;
|
|
@@ -63,12 +73,8 @@ static void emit(NetHandle *h, int event, JSValue value) {
|
|
|
63
73
|
(void)js_uv_call(h->cb, 2, args, NULL);
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (!h) js_fatal("out of memory in net");
|
|
69
|
-
h->is_pipe = is_pipe;
|
|
70
|
-
if (is_pipe) uv_pipe_init(js_uv_loop(ctx), &h->u.pipe, 0);
|
|
71
|
-
else uv_tcp_init(js_uv_loop(ctx), &h->u.tcp);
|
|
76
|
+
/* An initialized handle, numbered, with its callback. */
|
|
77
|
+
static NetHandle *add_handle(JSContext *ctx, NetHandle *h, JSValue cb) {
|
|
72
78
|
size_t id = 0;
|
|
73
79
|
while (id < nhandles && handles[id]) id++;
|
|
74
80
|
if (id == nhandles) {
|
|
@@ -86,6 +92,15 @@ static NetHandle *new_handle(JSContext *ctx, bool is_pipe, JSValue cb) {
|
|
|
86
92
|
return h;
|
|
87
93
|
}
|
|
88
94
|
|
|
95
|
+
static NetHandle *new_handle(JSContext *ctx, bool is_pipe, JSValue cb) {
|
|
96
|
+
NetHandle *h = calloc(1, sizeof *h);
|
|
97
|
+
if (!h) js_fatal("out of memory in net");
|
|
98
|
+
h->is_pipe = is_pipe;
|
|
99
|
+
if (is_pipe) uv_pipe_init(js_uv_loop(ctx), &h->u.pipe, 0);
|
|
100
|
+
else uv_tcp_init(js_uv_loop(ctx), &h->u.tcp);
|
|
101
|
+
return add_handle(ctx, h, cb);
|
|
102
|
+
}
|
|
103
|
+
|
|
89
104
|
static void on_closed(uv_handle_t *uh) {
|
|
90
105
|
NetHandle *h = (NetHandle *)uh;
|
|
91
106
|
handles[h->id] = NULL;
|
|
@@ -112,7 +127,9 @@ uv_stream_t *js_net_stream(int id) {
|
|
|
112
127
|
}
|
|
113
128
|
|
|
114
129
|
bool js_net_hook(int id, const JSNetHook *hook, void *data) {
|
|
115
|
-
|
|
130
|
+
/* a hook is set on an open socket, but taken off a closing one too: its close calls the hook,
|
|
131
|
+
* whose data (node:http's parser) may be freed by then */
|
|
132
|
+
NetHandle *h = hook ? open_handle(id) : (id >= 0 && (size_t)id < nhandles ? handles[id] : NULL);
|
|
116
133
|
if (!h) return false;
|
|
117
134
|
h->hook = hook;
|
|
118
135
|
h->hook_data = data;
|
|
@@ -124,9 +141,10 @@ static NetHandle *handle_arg(uint32_t argc, const JSValue *argv) {
|
|
|
124
141
|
}
|
|
125
142
|
|
|
126
143
|
/* A string argument as UTF-8 in buf. */
|
|
127
|
-
static
|
|
128
|
-
|
|
129
|
-
|
|
144
|
+
static size_t string_arg(JSContext *ctx, JSValue v, char *buf, size_t size) {
|
|
145
|
+
size_t n = js_is_string(v) ? js_view_to_utf8(js_string_view(ctx, v), buf, size - 1) : 0;
|
|
146
|
+
buf[n] = '\0';
|
|
147
|
+
return n;
|
|
130
148
|
}
|
|
131
149
|
|
|
132
150
|
/* An IP address and port; -errno for an address that isn't one. */
|
|
@@ -177,6 +195,20 @@ HOST_FN(js_host_net_open_fd) {
|
|
|
177
195
|
return js_int32(h->is_pipe ? uv_pipe_open(&h->u.pipe, fd) : uv_tcp_open(&h->u.tcp, (uv_os_sock_t)fd));
|
|
178
196
|
}
|
|
179
197
|
|
|
198
|
+
/* netFd(id) → the handle's descriptor | -errno (-1 for a Windows socket's, as Node's) */
|
|
199
|
+
HOST_FN(js_host_net_fd) {
|
|
200
|
+
UNUSED;
|
|
201
|
+
NetHandle *h = handle_arg(argc, argv);
|
|
202
|
+
if (!h) return js_int32(UV_EBADF);
|
|
203
|
+
#ifdef _WIN32
|
|
204
|
+
return js_int32(-1);
|
|
205
|
+
#else
|
|
206
|
+
uv_os_fd_t fd;
|
|
207
|
+
int r = uv_fileno((uv_handle_t *)&h->u.stream, &fd);
|
|
208
|
+
return js_int32(r < 0 ? r : fd);
|
|
209
|
+
#endif
|
|
210
|
+
}
|
|
211
|
+
|
|
180
212
|
/* netBind(id, ip, port, flags 1 ipv6Only | 2 reusePort), or a pipe's netBind(id, path) */
|
|
181
213
|
HOST_FN(js_host_net_bind) {
|
|
182
214
|
UNUSED;
|
|
@@ -184,8 +216,8 @@ HOST_FN(js_host_net_bind) {
|
|
|
184
216
|
if (!h || argc < 2) return js_int32(UV_EBADF);
|
|
185
217
|
if (h->is_pipe) {
|
|
186
218
|
char path[PATH_MAX_LEN];
|
|
187
|
-
string_arg(ctx, argv[1], path, sizeof path);
|
|
188
|
-
return js_int32(uv_pipe_bind2(&h->u.pipe, path,
|
|
219
|
+
size_t n = string_arg(ctx, argv[1], path, sizeof path); /* a Linux abstract path starts with a NUL */
|
|
220
|
+
return js_int32(uv_pipe_bind2(&h->u.pipe, path, n, UV_PIPE_NO_TRUNCATE));
|
|
189
221
|
}
|
|
190
222
|
struct sockaddr_storage addr;
|
|
191
223
|
int r = sockaddr_arg(ctx, argv[1], argc > 2 ? argv[2] : JS_UNDEFINED, &addr);
|
|
@@ -243,8 +275,8 @@ HOST_FN(js_host_net_connect) {
|
|
|
243
275
|
int r;
|
|
244
276
|
if (h->is_pipe) {
|
|
245
277
|
char path[PATH_MAX_LEN];
|
|
246
|
-
string_arg(ctx, argv[1], path, sizeof path);
|
|
247
|
-
r = uv_pipe_connect2(req, &h->u.pipe, path,
|
|
278
|
+
size_t n = string_arg(ctx, argv[1], path, sizeof path);
|
|
279
|
+
r = uv_pipe_connect2(req, &h->u.pipe, path, n, UV_PIPE_NO_TRUNCATE, on_connect);
|
|
248
280
|
} else {
|
|
249
281
|
struct sockaddr_storage addr;
|
|
250
282
|
r = sockaddr_arg(ctx, argv[1], argc > 2 ? argv[2] : JS_UNDEFINED, &addr);
|
|
@@ -414,6 +446,7 @@ HOST_FN(js_host_net_address) {
|
|
|
414
446
|
NetHandle *h = handle_arg(argc, argv);
|
|
415
447
|
if (!h) return js_int32(UV_EBADF);
|
|
416
448
|
bool peer = argc > 1 && js_truthy(argv[1]);
|
|
449
|
+
if (h->is_tty) return js_int32(UV_ENOTSOCK);
|
|
417
450
|
if (h->is_pipe) {
|
|
418
451
|
char path[PATH_MAX_LEN];
|
|
419
452
|
size_t n = sizeof path;
|
|
@@ -443,6 +476,87 @@ HOST_FN(js_host_net_keep_alive) {
|
|
|
443
476
|
return js_int32(uv_tcp_keepalive(&h->u.tcp, argc > 1 && js_truthy(argv[1]), delay));
|
|
444
477
|
}
|
|
445
478
|
|
|
479
|
+
/* netTypeOfService(id, tos): IP_TOS, or IPV6_TCLASS on an IPv6 socket, as Node's TCPWrap sets
|
|
480
|
+
* and reads it; with tos -1, the socket's */
|
|
481
|
+
HOST_FN(js_host_net_type_of_service) {
|
|
482
|
+
UNUSED;
|
|
483
|
+
NetHandle *h = handle_arg(argc, argv);
|
|
484
|
+
if (!h || h->is_pipe) return js_int32(h ? UV_EINVAL : UV_EBADF);
|
|
485
|
+
int tos = argc > 1 && js_is_int32(argv[1]) ? js_as_int32(argv[1]) : -1;
|
|
486
|
+
uv_os_fd_t fd;
|
|
487
|
+
int err = uv_fileno((uv_handle_t *)&h->u.tcp, &fd);
|
|
488
|
+
if (err) return js_int32(err);
|
|
489
|
+
struct sockaddr_storage storage;
|
|
490
|
+
int len = sizeof storage;
|
|
491
|
+
err = uv_tcp_getsockname(&h->u.tcp, (struct sockaddr *)&storage, &len);
|
|
492
|
+
if (err) return js_int32(err);
|
|
493
|
+
int level, option;
|
|
494
|
+
if (storage.ss_family == AF_INET) {
|
|
495
|
+
level = IPPROTO_IP;
|
|
496
|
+
option = IP_TOS;
|
|
497
|
+
} else if (storage.ss_family == AF_INET6) {
|
|
498
|
+
#ifdef IPV6_TCLASS
|
|
499
|
+
level = IPPROTO_IPV6;
|
|
500
|
+
option = IPV6_TCLASS;
|
|
501
|
+
#else
|
|
502
|
+
return js_int32(UV_ENOTSUP);
|
|
503
|
+
#endif
|
|
504
|
+
} else {
|
|
505
|
+
return js_int32(UV_EINVAL);
|
|
506
|
+
}
|
|
507
|
+
#ifdef _WIN32
|
|
508
|
+
if (tos >= 0) {
|
|
509
|
+
return js_int32(setsockopt((SOCKET)fd, level, option, (const char *)&tos, sizeof tos) == 0
|
|
510
|
+
? 0 : uv_translate_sys_error(WSAGetLastError()));
|
|
511
|
+
}
|
|
512
|
+
int got = 0, got_len = sizeof got;
|
|
513
|
+
if (getsockopt((SOCKET)fd, level, option, (char *)&got, &got_len) != 0) return js_int32(uv_translate_sys_error(WSAGetLastError()));
|
|
514
|
+
#else
|
|
515
|
+
if (tos >= 0) return js_int32(setsockopt(fd, level, option, &tos, sizeof tos) == 0 ? 0 : uv_translate_sys_error(errno));
|
|
516
|
+
int got = 0;
|
|
517
|
+
socklen_t got_len = sizeof got;
|
|
518
|
+
if (getsockopt(fd, level, option, &got, &got_len) != 0) return js_int32(uv_translate_sys_error(errno));
|
|
519
|
+
#endif
|
|
520
|
+
return js_int32(got);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/* ---- Terminals ----------------------------------------------------------------------------- */
|
|
524
|
+
|
|
525
|
+
static bool raw_mode_set;
|
|
526
|
+
|
|
527
|
+
static void reset_tty_mode(void) {
|
|
528
|
+
uv_tty_reset_mode();
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/* ttyOpen(fd, cb) → id | -errno: a terminal's handle, read like a pipe's */
|
|
532
|
+
HOST_FN(js_host_tty_open) {
|
|
533
|
+
UNUSED;
|
|
534
|
+
if (argc < 1 || !js_is_int32(argv[0])) return js_int32(UV_EBADF);
|
|
535
|
+
NetHandle *h = calloc(1, sizeof *h);
|
|
536
|
+
if (!h) js_fatal("out of memory in net");
|
|
537
|
+
int r = uv_tty_init(js_uv_loop(ctx), &h->u.tty, js_as_int32(argv[0]), 0);
|
|
538
|
+
if (r < 0) {
|
|
539
|
+
free(h);
|
|
540
|
+
return js_int32(r);
|
|
541
|
+
}
|
|
542
|
+
h->is_pipe = true;
|
|
543
|
+
h->is_tty = true;
|
|
544
|
+
return js_int32(add_handle(ctx, h, argc > 1 ? argv[1] : JS_UNDEFINED)->id);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/* ttySetRawMode(id, raw) → 0 | -errno: keys as they're typed, unechoed; the terminal's mode is
|
|
548
|
+
* restored at exit, as Node's is */
|
|
549
|
+
HOST_FN(js_host_tty_set_raw_mode) {
|
|
550
|
+
UNUSED;
|
|
551
|
+
NetHandle *h = handle_arg(argc, argv);
|
|
552
|
+
if (!h || !h->is_tty) return js_int32(UV_EBADF);
|
|
553
|
+
if (!raw_mode_set) {
|
|
554
|
+
raw_mode_set = true;
|
|
555
|
+
atexit(reset_tty_mode);
|
|
556
|
+
}
|
|
557
|
+
return js_int32(uv_tty_set_mode(&h->u.tty, argc > 1 && js_truthy(argv[1]) ? UV_TTY_MODE_RAW : UV_TTY_MODE_NORMAL));
|
|
558
|
+
}
|
|
559
|
+
|
|
446
560
|
/* ---- dns.lookup ---------------------------------------------------------------------------- */
|
|
447
561
|
|
|
448
562
|
typedef struct Lookup {
|
package/node/src/host_os.c
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
/* Host primitives for node:os
|
|
1
|
+
/* Host primitives for node:os: the system's facts through libuv, as Node's os module
|
|
2
2
|
* gets them, and the constants (signals and errno numbers) of the platform the program was built
|
|
3
3
|
* for. Failures return -errno, which the prelude turns into Node's SystemError. */
|
|
4
4
|
#define _GNU_SOURCE /* libuv's headers, and every signal and errno name the platform has */
|
|
5
5
|
#include "js_node.h"
|
|
6
6
|
|
|
7
7
|
#include <errno.h>
|
|
8
|
+
#include <stdio.h>
|
|
8
9
|
#include <signal.h>
|
|
9
10
|
#include <stdlib.h>
|
|
10
11
|
#include <string.h>
|
|
@@ -24,6 +25,59 @@ static JSValue array_of(JSContext *ctx, const JSValue *items, uint32_t n) {
|
|
|
24
25
|
return a;
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
/* osInterfaces(): [name, address, netmask, family (4 | 6), mac, internal, scopeid, …], 7 per
|
|
29
|
+
* address (uv_interface_addresses), or -errno. */
|
|
30
|
+
PRIMITIVE(js_host_os_interfaces) {
|
|
31
|
+
UNUSED_PRIMITIVE_ARGS;
|
|
32
|
+
uv_interface_address_t *list;
|
|
33
|
+
int count;
|
|
34
|
+
int r = uv_interface_addresses(&list, &count);
|
|
35
|
+
if (r < 0) return js_int32(r);
|
|
36
|
+
JSValue a = js_new_array(ctx, (uint32_t)count * 7);
|
|
37
|
+
for (int i = 0; i < count && !js_is_exception(a); i++) {
|
|
38
|
+
uv_interface_address_t *ia = &list[i];
|
|
39
|
+
char address[INET6_ADDRSTRLEN], netmask[INET6_ADDRSTRLEN], mac[18];
|
|
40
|
+
bool v6 = ia->address.address4.sin_family == AF_INET6;
|
|
41
|
+
if (v6) {
|
|
42
|
+
uv_ip6_name(&ia->address.address6, address, sizeof address);
|
|
43
|
+
uv_ip6_name(&ia->netmask.netmask6, netmask, sizeof netmask);
|
|
44
|
+
} else {
|
|
45
|
+
uv_ip4_name(&ia->address.address4, address, sizeof address);
|
|
46
|
+
uv_ip4_name(&ia->netmask.netmask4, netmask, sizeof netmask);
|
|
47
|
+
}
|
|
48
|
+
const unsigned char *m = (const unsigned char *)ia->phys_addr;
|
|
49
|
+
snprintf(mac, sizeof mac, "%02x:%02x:%02x:%02x:%02x:%02x", m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
50
|
+
JSValue items[7] = {
|
|
51
|
+
js_new_string_cstr(ctx, ia->name), js_new_string_cstr(ctx, address), js_new_string_cstr(ctx, netmask),
|
|
52
|
+
js_int32(v6 ? 6 : 4), js_new_string_cstr(ctx, mac), js_bool(ia->is_internal),
|
|
53
|
+
js_number(v6 ? (double)ia->address.address6.sin6_scope_id : 0),
|
|
54
|
+
};
|
|
55
|
+
for (int k = 0; k < 7; k++) {
|
|
56
|
+
if (js_is_exception(items[k]) || js_array_append(ctx, a, items[k]) < 0) {
|
|
57
|
+
a = JS_EXCEPTION;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
uv_free_interface_addresses(list, count);
|
|
63
|
+
return a;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* osGetPriority(pid) → priority | -errno */
|
|
67
|
+
PRIMITIVE(js_host_os_get_priority) {
|
|
68
|
+
(void)ctx, (void)callee, (void)this_val, (void)new_target;
|
|
69
|
+
int priority;
|
|
70
|
+
int r = uv_os_getpriority(argc > 0 && js_is_number(argv[0]) ? (uv_pid_t)js_as_number(argv[0]) : 0, &priority);
|
|
71
|
+
return js_int32(r < 0 ? r : priority);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* osSetPriority(pid, priority) → 0 | -errno */
|
|
75
|
+
PRIMITIVE(js_host_os_set_priority) {
|
|
76
|
+
(void)ctx, (void)callee, (void)this_val, (void)new_target;
|
|
77
|
+
if (argc < 2 || !js_is_number(argv[0]) || !js_is_int32(argv[1])) return js_int32(UV_EINVAL);
|
|
78
|
+
return js_int32(uv_os_setpriority((uv_pid_t)js_as_number(argv[0]), js_as_int32(argv[1])));
|
|
79
|
+
}
|
|
80
|
+
|
|
27
81
|
/* osUname(): [sysname, release, version, machine], or -errno. */
|
|
28
82
|
PRIMITIVE(js_host_os_uname) {
|
|
29
83
|
UNUSED_PRIMITIVE_ARGS;
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/* Host primitives for the program's own process (node:process beyond the runtime's process object):
|
|
2
|
+
* the working directory, the file mode mask, uptime, CPU and resource usage, the parent, memory
|
|
3
|
+
* limits, user and group ids (POSIX), abort, exit and execve. Child processes are host_process.c's.
|
|
4
|
+
*
|
|
5
|
+
* procChdir(path) → 0 | -errno procUmask(mask | -1) → the old mask (-1: only read it)
|
|
6
|
+
* procUptime() → seconds since the program started
|
|
7
|
+
* procCpuUsage(thread) → [user µs, system µs] | -errno procResourceUsage() → [16 numbers] | -errno
|
|
8
|
+
* procPpid() → pid procMemory() → [available, constrained] bytes
|
|
9
|
+
* procSetId(kind, id) → 0 | -errno kind 0 setuid, 1 setgid, 2 seteuid, 3 setegid
|
|
10
|
+
* procUserId(name) → id | -1 procGroupId(name) → id | -1
|
|
11
|
+
* procUserName(id) → name | null procGetGroups() → [gid, …] | -errno
|
|
12
|
+
* procSetGroups([gid, …]) → 0 | -errno procInitGroups(user, gid) → 0 | -errno
|
|
13
|
+
* procAbort() procReallyExit(code): output flushed, no 'exit'
|
|
14
|
+
* procExecve(file, [arg, …], [key=value, …]) → -errno (it returns only when it fails) */
|
|
15
|
+
#define _POSIX_C_SOURCE 200809L
|
|
16
|
+
#define _DEFAULT_SOURCE /* getgroups, setgroups, initgroups */
|
|
17
|
+
#define _DARWIN_C_SOURCE /* the same, on macOS */
|
|
18
|
+
#include "js_node.h"
|
|
19
|
+
|
|
20
|
+
#include <errno.h>
|
|
21
|
+
#include <stdio.h>
|
|
22
|
+
#include <stdlib.h>
|
|
23
|
+
#include <string.h>
|
|
24
|
+
#include <sys/stat.h>
|
|
25
|
+
#include <uv.h>
|
|
26
|
+
#ifdef _WIN32
|
|
27
|
+
#include <io.h>
|
|
28
|
+
#else
|
|
29
|
+
#include <grp.h>
|
|
30
|
+
#include <pwd.h>
|
|
31
|
+
#include <unistd.h>
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
#include "js_atoms.h"
|
|
35
|
+
#include "js_buffer.h"
|
|
36
|
+
#include "js_convert.h"
|
|
37
|
+
#include "js_exception.h"
|
|
38
|
+
#include "js_object.h"
|
|
39
|
+
#include "jscontext.h"
|
|
40
|
+
#include "jsstring.h"
|
|
41
|
+
|
|
42
|
+
#define HOST_FN(name) JSValue name(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target)
|
|
43
|
+
#define UNUSED (void)ctx, (void)callee, (void)this_val, (void)new_target
|
|
44
|
+
|
|
45
|
+
/* when the program started: set before main, in a program that links this file */
|
|
46
|
+
static uint64_t start_ns;
|
|
47
|
+
__attribute__((constructor)) static void record_start(void) { start_ns = uv_hrtime(); }
|
|
48
|
+
|
|
49
|
+
/* A string argument as UTF-8, malloc'd; NULL for anything else. */
|
|
50
|
+
static char *string_arg(JSContext *ctx, JSValue v) {
|
|
51
|
+
if (!js_is_string(v)) return NULL;
|
|
52
|
+
JSStrView view = js_string_view(ctx, v);
|
|
53
|
+
size_t n = js_view_to_utf8(view, NULL, 0);
|
|
54
|
+
char *s = malloc(n + 1);
|
|
55
|
+
if (!s) js_fatal("out of memory");
|
|
56
|
+
js_view_to_utf8(view, s, n);
|
|
57
|
+
s[n] = '\0';
|
|
58
|
+
return s;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static JSValue numbers(JSContext *ctx, const double *v, uint32_t n) {
|
|
62
|
+
JSValue values[16];
|
|
63
|
+
for (uint32_t i = 0; i < n; i++) values[i] = js_number(v[i]);
|
|
64
|
+
return js_new_array_from(ctx, values, n);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
HOST_FN(js_host_proc_chdir) {
|
|
68
|
+
UNUSED;
|
|
69
|
+
char *path = argc > 0 ? string_arg(ctx, argv[0]) : NULL;
|
|
70
|
+
if (!path) return js_int32(UV_EINVAL);
|
|
71
|
+
int r = uv_chdir(path);
|
|
72
|
+
free(path);
|
|
73
|
+
return js_int32(r);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
HOST_FN(js_host_proc_umask) {
|
|
77
|
+
UNUSED;
|
|
78
|
+
int mask = argc > 0 && js_is_int32(argv[0]) ? js_as_int32(argv[0]) : -1;
|
|
79
|
+
if (mask < 0) { /* read: set it, then back */
|
|
80
|
+
int old = (int)umask(0);
|
|
81
|
+
umask((mode_t)old);
|
|
82
|
+
return js_int32(old);
|
|
83
|
+
}
|
|
84
|
+
return js_int32((int)umask((mode_t)(mask & 0777)));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
HOST_FN(js_host_proc_uptime) {
|
|
88
|
+
UNUSED, (void)argc, (void)argv;
|
|
89
|
+
return js_number((double)(uv_hrtime() - start_ns) / 1e9);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static double usec(uv_timeval_t t) { return (double)t.tv_sec * 1e6 + (double)t.tv_usec; }
|
|
93
|
+
|
|
94
|
+
HOST_FN(js_host_proc_cpu_usage) {
|
|
95
|
+
UNUSED;
|
|
96
|
+
uv_rusage_t ru;
|
|
97
|
+
int r = argc > 0 && js_truthy(argv[0]) ? uv_getrusage_thread(&ru) : uv_getrusage(&ru);
|
|
98
|
+
if (r < 0) return js_int32(r);
|
|
99
|
+
double v[2] = { usec(ru.ru_utime), usec(ru.ru_stime) };
|
|
100
|
+
return numbers(ctx, v, 2);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* in Node's order: userCPUTime, systemCPUTime, maxRSS (KiB), sharedMemorySize, unsharedDataSize,
|
|
104
|
+
* unsharedStackSize, minorPageFault, majorPageFault, swappedOut, fsRead, fsWrite, ipcSent,
|
|
105
|
+
* ipcReceived, signalsCount, voluntaryContextSwitches, involuntaryContextSwitches */
|
|
106
|
+
HOST_FN(js_host_proc_resource_usage) {
|
|
107
|
+
UNUSED, (void)argc, (void)argv;
|
|
108
|
+
uv_rusage_t ru;
|
|
109
|
+
int r = uv_getrusage(&ru);
|
|
110
|
+
if (r < 0) return js_int32(r);
|
|
111
|
+
double v[16] = {
|
|
112
|
+
usec(ru.ru_utime), usec(ru.ru_stime), (double)ru.ru_maxrss, (double)ru.ru_ixrss, (double)ru.ru_idrss, (double)ru.ru_isrss,
|
|
113
|
+
(double)ru.ru_minflt, (double)ru.ru_majflt, (double)ru.ru_nswap, (double)ru.ru_inblock, (double)ru.ru_oublock,
|
|
114
|
+
(double)ru.ru_msgsnd, (double)ru.ru_msgrcv, (double)ru.ru_nsignals, (double)ru.ru_nvcsw, (double)ru.ru_nivcsw,
|
|
115
|
+
};
|
|
116
|
+
return numbers(ctx, v, 16);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
HOST_FN(js_host_proc_ppid) {
|
|
120
|
+
UNUSED, (void)argc, (void)argv;
|
|
121
|
+
return js_number((double)uv_os_getppid());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
HOST_FN(js_host_proc_memory) {
|
|
125
|
+
UNUSED, (void)argc, (void)argv;
|
|
126
|
+
double v[2] = { (double)uv_get_available_memory(), (double)uv_get_constrained_memory() };
|
|
127
|
+
return numbers(ctx, v, 2);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
HOST_FN(js_host_proc_abort) {
|
|
131
|
+
UNUSED, (void)argc, (void)argv;
|
|
132
|
+
fflush(stdout);
|
|
133
|
+
fflush(stderr);
|
|
134
|
+
abort();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
HOST_FN(js_host_proc_really_exit) {
|
|
138
|
+
UNUSED;
|
|
139
|
+
int code = argc > 0 && js_is_int32(argv[0]) ? js_as_int32(argv[0]) : 0;
|
|
140
|
+
fflush(stdout);
|
|
141
|
+
fflush(stderr);
|
|
142
|
+
exit(code);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#ifndef _WIN32
|
|
146
|
+
|
|
147
|
+
HOST_FN(js_host_proc_set_id) {
|
|
148
|
+
UNUSED;
|
|
149
|
+
if (argc < 2 || !js_is_int32(argv[0]) || !js_is_number(argv[1])) return js_int32(UV_EINVAL);
|
|
150
|
+
double d = js_as_number(argv[1]);
|
|
151
|
+
int r;
|
|
152
|
+
switch (js_as_int32(argv[0])) {
|
|
153
|
+
case 0: r = setuid((uid_t)d); break;
|
|
154
|
+
case 1: r = setgid((gid_t)d); break;
|
|
155
|
+
case 2: r = seteuid((uid_t)d); break;
|
|
156
|
+
case 3: r = setegid((gid_t)d); break;
|
|
157
|
+
default: return js_int32(UV_EINVAL);
|
|
158
|
+
}
|
|
159
|
+
return js_int32(r < 0 ? -errno : 0);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
HOST_FN(js_host_proc_user_id) {
|
|
163
|
+
UNUSED;
|
|
164
|
+
char *name = argc > 0 ? string_arg(ctx, argv[0]) : NULL;
|
|
165
|
+
if (!name) return js_int32(-1);
|
|
166
|
+
struct passwd *pw = getpwnam(name);
|
|
167
|
+
free(name);
|
|
168
|
+
return pw ? js_number((double)pw->pw_uid) : js_int32(-1);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
HOST_FN(js_host_proc_group_id) {
|
|
172
|
+
UNUSED;
|
|
173
|
+
char *name = argc > 0 ? string_arg(ctx, argv[0]) : NULL;
|
|
174
|
+
if (!name) return js_int32(-1);
|
|
175
|
+
struct group *gr = getgrnam(name);
|
|
176
|
+
free(name);
|
|
177
|
+
return gr ? js_number((double)gr->gr_gid) : js_int32(-1);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
HOST_FN(js_host_proc_user_name) {
|
|
181
|
+
UNUSED;
|
|
182
|
+
if (argc < 1 || !js_is_number(argv[0])) return JS_NULL;
|
|
183
|
+
struct passwd *pw = getpwuid((uid_t)js_as_number(argv[0]));
|
|
184
|
+
return pw ? js_new_string_cstr(ctx, pw->pw_name) : JS_NULL;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
HOST_FN(js_host_proc_get_groups) {
|
|
188
|
+
UNUSED, (void)argc, (void)argv;
|
|
189
|
+
int n = getgroups(0, NULL);
|
|
190
|
+
if (n < 0) return js_int32(-errno);
|
|
191
|
+
gid_t *groups = malloc(((size_t)n + 1) * sizeof *groups);
|
|
192
|
+
if (!groups) js_fatal("out of memory");
|
|
193
|
+
n = getgroups(n, groups);
|
|
194
|
+
if (n < 0) {
|
|
195
|
+
free(groups);
|
|
196
|
+
return js_int32(-errno);
|
|
197
|
+
}
|
|
198
|
+
/* the effective group too, as Node lists it */
|
|
199
|
+
gid_t egid = getegid();
|
|
200
|
+
bool listed = false;
|
|
201
|
+
for (int i = 0; i < n; i++) listed |= groups[i] == egid;
|
|
202
|
+
if (!listed) groups[n++] = egid;
|
|
203
|
+
JSValue list = js_new_array(ctx, (uint32_t)n);
|
|
204
|
+
for (int i = 0; i < n && !js_is_exception(list); i++) {
|
|
205
|
+
if (js_array_push(ctx, js_as_object(list), js_number((double)groups[i])) < 0) list = JS_EXCEPTION;
|
|
206
|
+
}
|
|
207
|
+
free(groups);
|
|
208
|
+
return list;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
HOST_FN(js_host_proc_set_groups) {
|
|
212
|
+
UNUSED;
|
|
213
|
+
if (argc < 1 || !js_is_object(argv[0])) return js_int32(UV_EINVAL);
|
|
214
|
+
JSValue len = js_get_value(ctx, argv[0], JS_ATOM(length));
|
|
215
|
+
if (!js_is_number(len)) return js_int32(UV_EINVAL);
|
|
216
|
+
size_t n = (size_t)js_as_number(len);
|
|
217
|
+
gid_t *groups = malloc((n + 1) * sizeof *groups);
|
|
218
|
+
if (!groups) js_fatal("out of memory");
|
|
219
|
+
for (size_t i = 0; i < n; i++) {
|
|
220
|
+
JSValue v = js_get_index(ctx, argv[0], js_int32((int32_t)i));
|
|
221
|
+
if (!js_is_number(v)) {
|
|
222
|
+
free(groups);
|
|
223
|
+
return js_int32(UV_EINVAL);
|
|
224
|
+
}
|
|
225
|
+
groups[i] = (gid_t)js_as_number(v);
|
|
226
|
+
}
|
|
227
|
+
int r = setgroups(n, groups);
|
|
228
|
+
free(groups);
|
|
229
|
+
return js_int32(r < 0 ? -errno : 0);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
HOST_FN(js_host_proc_init_groups) {
|
|
233
|
+
UNUSED;
|
|
234
|
+
char *user = argc > 0 ? string_arg(ctx, argv[0]) : NULL;
|
|
235
|
+
if (!user || argc < 2 || !js_is_number(argv[1])) {
|
|
236
|
+
free(user);
|
|
237
|
+
return js_int32(UV_EINVAL);
|
|
238
|
+
}
|
|
239
|
+
int r = initgroups(user, (gid_t)js_as_number(argv[1]));
|
|
240
|
+
free(user);
|
|
241
|
+
return js_int32(r < 0 ? -errno : 0);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* the strings of an array, NULL-terminated, malloc'd */
|
|
245
|
+
static char **string_list(JSContext *ctx, JSValue array) {
|
|
246
|
+
if (!js_is_object(array)) return NULL;
|
|
247
|
+
JSValue len = js_get_value(ctx, array, JS_ATOM(length));
|
|
248
|
+
size_t n = js_is_number(len) ? (size_t)js_as_number(len) : 0;
|
|
249
|
+
char **list = calloc(n + 1, sizeof *list);
|
|
250
|
+
if (!list) js_fatal("out of memory");
|
|
251
|
+
for (size_t i = 0; i < n; i++) {
|
|
252
|
+
list[i] = string_arg(ctx, js_get_index(ctx, array, js_int32((int32_t)i)));
|
|
253
|
+
if (!list[i]) list[i] = strdup("");
|
|
254
|
+
}
|
|
255
|
+
return list;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
static void free_list(char **list) {
|
|
259
|
+
for (size_t i = 0; list && list[i]; i++) free(list[i]);
|
|
260
|
+
free(list);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
HOST_FN(js_host_proc_execve) {
|
|
264
|
+
UNUSED;
|
|
265
|
+
char *file = argc > 0 ? string_arg(ctx, argv[0]) : NULL;
|
|
266
|
+
char **args = argc > 1 ? string_list(ctx, argv[1]) : NULL;
|
|
267
|
+
char **env = argc > 2 ? string_list(ctx, argv[2]) : NULL;
|
|
268
|
+
if (!file || !args || !env) {
|
|
269
|
+
free(file), free_list(args), free_list(env);
|
|
270
|
+
return js_int32(UV_EINVAL);
|
|
271
|
+
}
|
|
272
|
+
fflush(stdout);
|
|
273
|
+
fflush(stderr);
|
|
274
|
+
execve(file, args, env);
|
|
275
|
+
int e = errno;
|
|
276
|
+
free(file), free_list(args), free_list(env);
|
|
277
|
+
return js_int32(-e);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
#else /* Windows: Node has none of these */
|
|
281
|
+
|
|
282
|
+
HOST_FN(js_host_proc_set_id) { UNUSED, (void)argc, (void)argv; return js_int32(UV_ENOSYS); }
|
|
283
|
+
HOST_FN(js_host_proc_user_id) { UNUSED, (void)argc, (void)argv; return js_int32(-1); }
|
|
284
|
+
HOST_FN(js_host_proc_group_id) { UNUSED, (void)argc, (void)argv; return js_int32(-1); }
|
|
285
|
+
HOST_FN(js_host_proc_user_name) { UNUSED, (void)argc, (void)argv; return JS_NULL; }
|
|
286
|
+
HOST_FN(js_host_proc_get_groups) { UNUSED, (void)argc, (void)argv; return js_int32(UV_ENOSYS); }
|
|
287
|
+
HOST_FN(js_host_proc_set_groups) { UNUSED, (void)argc, (void)argv; return js_int32(UV_ENOSYS); }
|
|
288
|
+
HOST_FN(js_host_proc_init_groups) { UNUSED, (void)argc, (void)argv; return js_int32(UV_ENOSYS); }
|
|
289
|
+
HOST_FN(js_host_proc_execve) { UNUSED, (void)argc, (void)argv; return js_int32(UV_ENOSYS); }
|
|
290
|
+
|
|
291
|
+
#endif
|