visaljs 0.0.6 → 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 +4414 -325
- 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 -5
- 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
package/runtime/src/buffer.c
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Buffer, the buffer component
|
|
1
|
+
/* Buffer, the buffer component: Node's global Buffer, in C. As in Node, a
|
|
2
2
|
* Buffer is a Uint8Array whose prototype is Buffer.prototype (which inherits from
|
|
3
3
|
* Uint8Array.prototype), so typed array methods work on it and make Buffers (Buffer is their
|
|
4
4
|
* species constructor). Encodings: utf8 (WHATWG decoding, U+FFFD for each maximal invalid
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
#include "js_atoms.h"
|
|
16
16
|
#include "js_bigint.h"
|
|
17
17
|
#include "js_buffer.h"
|
|
18
|
+
#include "js_host.h"
|
|
18
19
|
#include "js_console.h"
|
|
19
20
|
#include "js_convert.h"
|
|
20
21
|
#include "js_exception.h"
|
|
@@ -33,6 +34,23 @@ static JSValue throw_bounds(JSContext *ctx);
|
|
|
33
34
|
|
|
34
35
|
/* ---- Encodings ------------------------------------------------------------------------------ */
|
|
35
36
|
|
|
37
|
+
/* Node's addNumericalSeparator: the digits of an integer in groups of three, joined by '_'. */
|
|
38
|
+
static void add_numerical_separator(char *digits, size_t size) {
|
|
39
|
+
char out[128];
|
|
40
|
+
const char *p = digits;
|
|
41
|
+
size_t o = 0;
|
|
42
|
+
if (*p == '-') out[o++] = *p++;
|
|
43
|
+
size_t n = strlen(p);
|
|
44
|
+
for (size_t i = 0; i < n && o + 2 < sizeof out; i++) {
|
|
45
|
+
if (i > 0 && (n - i) % 3 == 0) out[o++] = '_';
|
|
46
|
+
out[o++] = p[i];
|
|
47
|
+
}
|
|
48
|
+
out[o] = '\0';
|
|
49
|
+
if (o >= size) o = size - 1;
|
|
50
|
+
memcpy(digits, out, o);
|
|
51
|
+
digits[o] = '\0';
|
|
52
|
+
}
|
|
53
|
+
|
|
36
54
|
typedef enum { ENC_UTF8, ENC_UCS2, ENC_LATIN1, ENC_ASCII, ENC_BASE64, ENC_BASE64URL, ENC_HEX, ENC_INVALID } Encoding;
|
|
37
55
|
|
|
38
56
|
static const struct { const char *name; Encoding enc; } ENCODINGS[] = {
|
|
@@ -67,6 +85,15 @@ static JSValue throw_unknown_encoding(JSContext *ctx, JSValue v) {
|
|
|
67
85
|
return js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_UNKNOWN_ENCODING", "Unknown encoding: %s", s);
|
|
68
86
|
}
|
|
69
87
|
|
|
88
|
+
/* getEncodingOps's encoding: the value as a string (`encoding += ''`), then its name; ENC_INVALID
|
|
89
|
+
* for an unknown one, which *str then holds for the error. -1 when the conversion threw. */
|
|
90
|
+
static int encoding_coerced(JSContext *ctx, JSValue v, JSValue *str, Encoding *out) {
|
|
91
|
+
*str = js_is_string(v) ? v : js_to_string(ctx, v);
|
|
92
|
+
if (js_is_exception(*str)) return -1;
|
|
93
|
+
*out = encoding_of(ctx, *str);
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
70
97
|
/* An optional encoding argument: utf8 when undefined (or null). 0, or -1 with ERR_UNKNOWN_ENCODING. */
|
|
71
98
|
static int encoding_arg(JSContext *ctx, JSValue v, Encoding *out) {
|
|
72
99
|
if (js_is_nullish(v)) {
|
|
@@ -93,11 +120,6 @@ static void bytes_reserve(Bytes *b, size_t more) {
|
|
|
93
120
|
b->cap = cap;
|
|
94
121
|
}
|
|
95
122
|
|
|
96
|
-
static void bytes_push(Bytes *b, uint8_t c) {
|
|
97
|
-
bytes_reserve(b, 1);
|
|
98
|
-
b->p[b->n++] = c;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
123
|
static int hex_digit(uint32_t c) {
|
|
102
124
|
if (c >= '0' && c <= '9') return (int)(c - '0');
|
|
103
125
|
if ((c | 32) >= 'a' && (c | 32) <= 'f') return (int)((c | 32) - 'a' + 10);
|
|
@@ -298,7 +320,7 @@ static JSValue throw_not_u8(JSContext *ctx, const char *name, JSValue v) {
|
|
|
298
320
|
uint8_t *data; \
|
|
299
321
|
size_t len; \
|
|
300
322
|
if (!u8_bytes(this_val, &data, &len)) \
|
|
301
|
-
return
|
|
323
|
+
return js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE", "argument must be a buffer")
|
|
302
324
|
|
|
303
325
|
static JSValue buffer_from_string(JSContext *ctx, JSValue s, JSValue encoding) {
|
|
304
326
|
Encoding enc;
|
|
@@ -407,6 +429,7 @@ static JSValue from_value(JSContext *ctx, JSValue value, JSValue enc_or_offset,
|
|
|
407
429
|
BUILTIN(buffer_ctor) {
|
|
408
430
|
(void)callee, (void)this_val, (void)new_target;
|
|
409
431
|
if (js_is_number(ARG(0))) {
|
|
432
|
+
if (js_is_string(ARG(1))) return js_throw_invalid_arg_type(ctx, "string", "of type string", ARG(0)); /* Buffer(size, encoding) */
|
|
410
433
|
double n = js_as_number(ARG(0));
|
|
411
434
|
if (!(n >= 0 && n <= JS_MAX_SAFE_INTEGER)) {
|
|
412
435
|
char received[64];
|
|
@@ -502,11 +525,27 @@ BUILTIN(buffer_compare_static) {
|
|
|
502
525
|
return js_int32(compare_bytes(a, an, b, bn));
|
|
503
526
|
}
|
|
504
527
|
|
|
528
|
+
/* lib/buffer.js's validateOffset: a number, an integer, in [min, max]. */
|
|
529
|
+
static int validate_offset(JSContext *ctx, JSValue v, const char *name, size_t min, size_t max, size_t *out) {
|
|
530
|
+
if (!js_is_number(v)) return fail(js_throw_invalid_arg_type(ctx, name, "of type number", v));
|
|
531
|
+
double d = js_as_number(v);
|
|
532
|
+
if (d != trunc(d) || !isfinite(d) || d < (double)min || d > (double)max) {
|
|
533
|
+
char received[64];
|
|
534
|
+
js_describe_value(ctx, v, received, sizeof received);
|
|
535
|
+
return fail(d != trunc(d) || !isfinite(d)
|
|
536
|
+
? js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_OUT_OF_RANGE", "The value of \"%s\" is out of range. It must be an integer. Received %s", name, received)
|
|
537
|
+
: js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_OUT_OF_RANGE", "The value of \"%s\" is out of range. It must be >= %zu && <= %zu. Received %s", name, min, max, received));
|
|
538
|
+
}
|
|
539
|
+
*out = (size_t)d;
|
|
540
|
+
return 0;
|
|
541
|
+
}
|
|
542
|
+
|
|
505
543
|
BUILTIN(buffer_concat) {
|
|
506
544
|
UNUSED_ARGS;
|
|
507
545
|
JSValue list = ARG(0);
|
|
508
546
|
if (!js_is_array(list)) return js_throw_invalid_arg_type(ctx, "list", "an instance of Array", list);
|
|
509
547
|
uint32_t count = js_array_length(js_as_object(list));
|
|
548
|
+
if (count == 0) return new_buffer(ctx, 0); /* lib/buffer.js: before the length */
|
|
510
549
|
double total = 0;
|
|
511
550
|
for (uint32_t i = 0; i < count; i++) {
|
|
512
551
|
JSValue item = js_get_elem(ctx, list, js_int32((int32_t)i));
|
|
@@ -520,10 +559,10 @@ BUILTIN(buffer_concat) {
|
|
|
520
559
|
}
|
|
521
560
|
total += (double)n;
|
|
522
561
|
}
|
|
523
|
-
if (!js_is_undefined(ARG(1))) {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
total =
|
|
562
|
+
if (!js_is_undefined(ARG(1))) { /* lib/buffer.js: validateOffset(length, 'length') */
|
|
563
|
+
size_t given;
|
|
564
|
+
if (validate_offset(ctx, ARG(1), "length", 0, (size_t)JS_MAX_SAFE_INTEGER, &given) < 0) return JS_EXCEPTION;
|
|
565
|
+
total = (double)given;
|
|
527
566
|
}
|
|
528
567
|
JSValue result = new_buffer(ctx, (size_t)total);
|
|
529
568
|
if (js_is_exception(result)) return result;
|
|
@@ -611,8 +650,9 @@ BUILTIN(buffer_to_string) {
|
|
|
611
650
|
if (end <= start) return js_empty_string();
|
|
612
651
|
Encoding enc = ENC_UTF8;
|
|
613
652
|
if (!js_is_undefined(ARG(0))) {
|
|
614
|
-
|
|
615
|
-
if (
|
|
653
|
+
JSValue name;
|
|
654
|
+
if (encoding_coerced(ctx, ARG(0), &name, &enc) < 0) return JS_EXCEPTION;
|
|
655
|
+
if (enc == ENC_INVALID) return throw_unknown_encoding(ctx, name);
|
|
616
656
|
}
|
|
617
657
|
u8_bytes(this_val, &data, &len); /* ToNumber ran user code */
|
|
618
658
|
if ((size_t)end > len) end = (double)len;
|
|
@@ -679,9 +719,14 @@ BUILTIN(buffer_compare) {
|
|
|
679
719
|
uint8_t *p;
|
|
680
720
|
size_t n;
|
|
681
721
|
if (!u8_bytes(ARG(0), &p, &n)) return throw_not_u8(ctx, "target", ARG(0));
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
722
|
+
/* lib/buffer.js's: each offset given is validated, the starts against kMaxLength (a start past
|
|
723
|
+
* the end compares as empty) */
|
|
724
|
+
size_t ts = 0, te = n, ss = 0, se = len;
|
|
725
|
+
const size_t max = (size_t)JS_MAX_SAFE_INTEGER;
|
|
726
|
+
if ((!js_is_undefined(ARG(1)) && validate_offset(ctx, ARG(1), "targetStart", 0, max, &ts) < 0) ||
|
|
727
|
+
(!js_is_undefined(ARG(2)) && validate_offset(ctx, ARG(2), "targetEnd", 0, n, &te) < 0) ||
|
|
728
|
+
(!js_is_undefined(ARG(3)) && validate_offset(ctx, ARG(3), "sourceStart", 0, max, &ss) < 0) ||
|
|
729
|
+
(!js_is_undefined(ARG(4)) && validate_offset(ctx, ARG(4), "sourceEnd", 0, len, &se) < 0))
|
|
685
730
|
return JS_EXCEPTION;
|
|
686
731
|
if (ss >= se) return js_int32(ts >= te ? 0 : -1);
|
|
687
732
|
if (ts >= te) return js_int32(1);
|
|
@@ -691,6 +736,7 @@ BUILTIN(buffer_compare) {
|
|
|
691
736
|
/* copy(target, targetStart = 0, sourceStart = 0, sourceEnd = length): the bytes copied */
|
|
692
737
|
BUILTIN(buffer_copy) {
|
|
693
738
|
UNUSED_ARGS;
|
|
739
|
+
if (!js_is_uint8_array(this_val)) return js_throw_invalid_arg_type(ctx, "source", "an instance of Buffer or Uint8Array", this_val);
|
|
694
740
|
THIS_BYTES();
|
|
695
741
|
uint8_t *p;
|
|
696
742
|
size_t n;
|
|
@@ -736,29 +782,83 @@ static size_t write_string(JSContext *ctx, uint8_t *data, size_t room, JSValue s
|
|
|
736
782
|
|
|
737
783
|
/* write(string, offset = 0, length = buffer.length - offset, encoding = 'utf8'), with Node's
|
|
738
784
|
* overloads: write(string, encoding), write(string, offset, encoding) */
|
|
785
|
+
/* write(string[, offset[, length]][, encoding]), as lib/buffer.js's: write(string, encoding),
|
|
786
|
+
* or write(string, offset[, length][, encoding]) */
|
|
739
787
|
BUILTIN(buffer_write) {
|
|
740
788
|
UNUSED_ARGS;
|
|
741
789
|
THIS_BYTES();
|
|
742
790
|
if (!js_is_string(ARG(0))) return js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE", "argument must be a string");
|
|
743
791
|
JSValue offset_arg = ARG(1), length_arg = ARG(2), enc_arg = ARG(3);
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
if (
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
792
|
+
size_t offset = 0, length = len;
|
|
793
|
+
if (js_is_undefined(offset_arg)) {
|
|
794
|
+
enc_arg = JS_UNDEFINED;
|
|
795
|
+
} else if (js_is_undefined(length_arg) && js_is_string(offset_arg)) {
|
|
796
|
+
enc_arg = offset_arg;
|
|
797
|
+
} else {
|
|
798
|
+
if (validate_offset(ctx, offset_arg, "offset", 0, len, &offset) < 0) return JS_EXCEPTION;
|
|
799
|
+
length = len - offset;
|
|
800
|
+
if (js_is_string(length_arg)) {
|
|
801
|
+
enc_arg = length_arg;
|
|
802
|
+
} else if (!js_is_undefined(length_arg)) {
|
|
803
|
+
size_t given;
|
|
804
|
+
if (validate_offset(ctx, length_arg, "length", 0, len, &given) < 0) return JS_EXCEPTION;
|
|
805
|
+
if (given < length) length = given;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
Encoding enc = ENC_UTF8;
|
|
809
|
+
if (js_truthy(enc_arg)) {
|
|
810
|
+
enc = encoding_of(ctx, enc_arg);
|
|
811
|
+
if (enc == ENC_INVALID) return throw_unknown_encoding(ctx, enc_arg);
|
|
812
|
+
}
|
|
752
813
|
return js_number((double)write_string(ctx, data + offset, length, ARG(0), enc));
|
|
753
814
|
}
|
|
754
815
|
|
|
816
|
+
static JSValue throw_outside(JSContext *ctx, const char *name) {
|
|
817
|
+
return js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_BUFFER_OUT_OF_BOUNDS", "\"%s\" is outside of buffer bounds", name);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/* node_buffer.cc's ParseArrayIndex: undefined is `dflt`, else an integer (NaN 0), never negative
|
|
821
|
+
* ("Index out of range"). 0, or -1 with an exception. */
|
|
822
|
+
static int parse_array_index(JSContext *ctx, JSValue v, size_t dflt, size_t *out) {
|
|
823
|
+
if (js_is_undefined(v)) {
|
|
824
|
+
*out = dflt;
|
|
825
|
+
return 0;
|
|
826
|
+
}
|
|
827
|
+
double d;
|
|
828
|
+
if (js_to_number(ctx, &d, v) < 0) return -1;
|
|
829
|
+
d = isnan(d) ? 0 : trunc(d);
|
|
830
|
+
if (d < 0) return fail(js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_OUT_OF_RANGE", "Index out of range"));
|
|
831
|
+
*out = d > (double)SIZE_MAX ? SIZE_MAX : (size_t)d;
|
|
832
|
+
return 0;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/* the encoding-specific writes: buf.utf8Write(string, offset, length), …. utf8, latin1 and ascii
|
|
836
|
+
* as lib/internal/buffer.js's (offset and length as numbers within the buffer), the others as
|
|
837
|
+
* node_buffer.cc's StringWrite. */
|
|
755
838
|
static JSValue write_as(JSContext *ctx, JSValue this_val, uint32_t argc, const JSValue *argv, Encoding enc) {
|
|
756
839
|
THIS_BYTES();
|
|
757
|
-
if (!js_is_string(ARG(0))) return js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE", "argument must be a string");
|
|
758
840
|
size_t offset, length;
|
|
759
|
-
if (
|
|
760
|
-
|
|
841
|
+
if (enc == ENC_UTF8 || enc == ENC_LATIN1 || enc == ENC_ASCII) {
|
|
842
|
+
double o = 0, l;
|
|
843
|
+
if (!js_is_undefined(ARG(1)) && js_to_number(ctx, &o, ARG(1)) < 0) return JS_EXCEPTION;
|
|
844
|
+
if (o < 0 || o > (double)len) return throw_outside(ctx, "offset");
|
|
845
|
+
if (isnan(o)) o = 0;
|
|
846
|
+
l = (double)len - o;
|
|
847
|
+
if (!js_is_undefined(ARG(2)) && js_to_number(ctx, &l, ARG(2)) < 0) return JS_EXCEPTION;
|
|
848
|
+
if (l < 0 || l > (double)len - o) return throw_outside(ctx, "length");
|
|
849
|
+
if (isnan(l)) l = 0;
|
|
850
|
+
if (!js_is_string(ARG(0))) return js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE", "argument must be a string");
|
|
851
|
+
offset = (size_t)o, length = (size_t)l;
|
|
852
|
+
} else {
|
|
853
|
+
if (!js_is_string(ARG(0))) return js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE", "argument must be a string");
|
|
854
|
+
if (parse_array_index(ctx, ARG(1), 0, &offset) < 0) return JS_EXCEPTION;
|
|
855
|
+
if (offset > len) return throw_outside(ctx, "offset");
|
|
856
|
+
if (parse_array_index(ctx, ARG(2), len - offset, &length) < 0) return JS_EXCEPTION;
|
|
857
|
+
}
|
|
858
|
+
u8_bytes(this_val, &data, &len); /* ToNumber ran user code */
|
|
859
|
+
if (offset > len) offset = len;
|
|
761
860
|
if (length > len - offset) length = len - offset;
|
|
861
|
+
if (length == 0) return js_int32(0);
|
|
762
862
|
return js_number((double)write_string(ctx, data + offset, length, ARG(0), enc));
|
|
763
863
|
}
|
|
764
864
|
|
|
@@ -827,62 +927,135 @@ BUILTIN(buffer_fill) {
|
|
|
827
927
|
return fill_bytes(ctx, data, start, end, ARG(0), enc_arg) < 0 ? JS_EXCEPTION : this_val;
|
|
828
928
|
}
|
|
829
929
|
|
|
830
|
-
/* indexOf / lastIndexOf / includes
|
|
930
|
+
/* ---- indexOf / lastIndexOf / includes (lib/buffer.js's bidirectionalIndexOf, node_buffer.cc's
|
|
931
|
+
* IndexOfString, IndexOfBuffer and IndexOfNumber) ------------------------------------------- */
|
|
932
|
+
|
|
933
|
+
/* IndexOfOffset: where a search starts, in [0, length], or -1 for no possible match. */
|
|
934
|
+
static int64_t index_of_offset(size_t length, int64_t offset, int64_t needle_length, bool forward) {
|
|
935
|
+
int64_t len = (int64_t)length;
|
|
936
|
+
if (offset < 0) {
|
|
937
|
+
if (offset + len >= 0) return len + offset; /* from the end */
|
|
938
|
+
return forward || needle_length == 0 ? 0 : -1;
|
|
939
|
+
}
|
|
940
|
+
if (offset + needle_length <= len) return offset;
|
|
941
|
+
if (needle_length == 0) return len;
|
|
942
|
+
return forward ? -1 : len - 1;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/* nbytes::SearchString: the first match at or after `start` (forward), or the last one at or
|
|
946
|
+
* before it; `length` when there is none. Units of `width` bytes (2 for UCS-2). */
|
|
947
|
+
static size_t search_string(const uint8_t *hay, size_t length, const uint8_t *needle, size_t needle_length, size_t start,
|
|
948
|
+
bool forward, size_t width) {
|
|
949
|
+
if (length < needle_length) return length;
|
|
950
|
+
size_t diff = length - needle_length;
|
|
951
|
+
if (forward) {
|
|
952
|
+
for (size_t i = start; i <= diff; i++)
|
|
953
|
+
if (memcmp(hay + i * width, needle, needle_length * width) == 0) return i;
|
|
954
|
+
return length;
|
|
955
|
+
}
|
|
956
|
+
for (size_t i = start < diff ? start : diff;; i--) {
|
|
957
|
+
if (memcmp(hay + i * width, needle, needle_length * width) == 0) return i;
|
|
958
|
+
if (i == 0) return length;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/* IndexOfString and IndexOfBuffer: the needle's bytes (encoded), UCS-2 searched by code unit */
|
|
963
|
+
static double index_of_bytes(const uint8_t *data, size_t len, const uint8_t *needle, size_t needle_length, int64_t offset_i64,
|
|
964
|
+
int64_t end_i64, bool forward, bool ucs2) {
|
|
965
|
+
size_t haystack_length = ucs2 ? len & ~(size_t)1 : len;
|
|
966
|
+
int64_t end_clamped = end_i64 < 0 ? 0 : end_i64;
|
|
967
|
+
size_t search_end = end_clamped > (int64_t)haystack_length ? haystack_length : (size_t)end_clamped;
|
|
968
|
+
if (ucs2) search_end &= ~(size_t)1;
|
|
969
|
+
int64_t opt = index_of_offset(haystack_length, offset_i64, (int64_t)needle_length, forward);
|
|
970
|
+
if (needle_length == 0) return (double)(opt < (int64_t)search_end ? opt : (int64_t)search_end);
|
|
971
|
+
if (haystack_length == 0 || opt <= -1) return -1;
|
|
972
|
+
size_t offset = (size_t)opt;
|
|
973
|
+
if (offset >= search_end) {
|
|
974
|
+
if (forward || search_end == 0) return -1;
|
|
975
|
+
offset = search_end - 1;
|
|
976
|
+
}
|
|
977
|
+
if ((forward && needle_length + offset > search_end) || needle_length > search_end) return -1;
|
|
978
|
+
size_t result;
|
|
979
|
+
if (ucs2) {
|
|
980
|
+
if (search_end < 2 || needle_length < 2) return -1;
|
|
981
|
+
result = search_string(data, search_end / 2, needle, needle_length / 2, offset / 2, forward, 2) * 2;
|
|
982
|
+
} else {
|
|
983
|
+
result = search_string(data, search_end, needle, needle_length, offset, forward, 1);
|
|
984
|
+
}
|
|
985
|
+
return result >= search_end ? -1 : (double)result;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/* IndexOfNumber: a byte */
|
|
989
|
+
static double index_of_byte(const uint8_t *data, size_t len, uint8_t byte, int64_t offset_i64, int64_t end_i64, bool forward) {
|
|
990
|
+
int64_t opt = index_of_offset(len, offset_i64, 1, forward);
|
|
991
|
+
if (opt <= -1 || len == 0) return -1;
|
|
992
|
+
size_t offset = (size_t)opt;
|
|
993
|
+
int64_t end_clamped = end_i64 < 0 ? 0 : end_i64;
|
|
994
|
+
size_t search_end = end_clamped > (int64_t)len ? len : (size_t)end_clamped;
|
|
995
|
+
if (forward) {
|
|
996
|
+
for (size_t i = offset; i < search_end; i++)
|
|
997
|
+
if (data[i] == byte) return (double)i;
|
|
998
|
+
return -1;
|
|
999
|
+
}
|
|
1000
|
+
size_t backward_end = offset + 1 < search_end ? offset + 1 : search_end;
|
|
1001
|
+
for (size_t i = backward_end; i > 0; i--)
|
|
1002
|
+
if (data[i - 1] == byte) return (double)(i - 1);
|
|
1003
|
+
return -1;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/* indexOf(value, byteOffset, end, encoding) and its kin (kind 0 indexOf, 1 lastIndexOf, 2 includes) */
|
|
831
1007
|
static JSValue search(JSContext *ctx, JSValue this_val, uint32_t argc, const JSValue *argv, int kind) {
|
|
832
1008
|
THIS_BYTES();
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
double
|
|
837
|
-
if (
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
1009
|
+
bool forward = kind != 1;
|
|
1010
|
+
JSValue value = ARG(0), offset_arg = ARG(1), end_arg = ARG(2), enc_arg = ARG(3);
|
|
1011
|
+
/* Buffer.prototype.indexOf: a string `end` is the encoding */
|
|
1012
|
+
double end = (double)len;
|
|
1013
|
+
if (js_is_string(end_arg)) enc_arg = end_arg;
|
|
1014
|
+
else if (!js_is_undefined(end_arg) && js_to_number(ctx, &end, end_arg) < 0) return JS_EXCEPTION;
|
|
1015
|
+
/* bidirectionalIndexOf: a string byteOffset is the encoding; the offset as a number, clamped
|
|
1016
|
+
* to 32 bits; NaN (undefined too) searches the whole buffer */
|
|
1017
|
+
double offset;
|
|
1018
|
+
if (js_is_string(offset_arg)) {
|
|
1019
|
+
enc_arg = offset_arg;
|
|
1020
|
+
offset = NAN;
|
|
1021
|
+
} else if (js_to_number(ctx, &offset, offset_arg) < 0) {
|
|
1022
|
+
return JS_EXCEPTION;
|
|
841
1023
|
}
|
|
842
|
-
if (offset
|
|
843
|
-
|
|
844
|
-
if (
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
1024
|
+
if (offset > 2147483647.0) offset = 2147483647.0;
|
|
1025
|
+
else if (offset < -2147483648.0) offset = -2147483648.0;
|
|
1026
|
+
if (isnan(offset)) offset = forward ? 0 : (double)len;
|
|
1027
|
+
int64_t offset_i64 = (int64_t)trunc(offset), end_i64 = isnan(end) ? 0 : end > 9e18 ? INT64_MAX : end < -9e18 ? INT64_MIN : (int64_t)trunc(end);
|
|
1028
|
+
double found;
|
|
1029
|
+
if (js_is_number(value)) {
|
|
1030
|
+
uint32_t needle = (uint32_t)js_f64_to_int32(js_as_number(value)); /* val >>> 0; memchr takes its low byte */
|
|
1031
|
+
u8_bytes(this_val, &data, &len);
|
|
1032
|
+
found = index_of_byte(data, len, (uint8_t)needle, offset_i64, end_i64, forward);
|
|
851
1033
|
} else {
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
if (!
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
needle
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
} else if (offset >= 0) {
|
|
872
|
-
if (needle.n == 0) found = offset < (double)len ? offset : (double)len;
|
|
873
|
-
else if (needle.n <= len) {
|
|
874
|
-
size_t i = offset > (double)(len - needle.n) ? len - needle.n : (size_t)offset;
|
|
875
|
-
for (;; i--) {
|
|
876
|
-
if (memcmp(data + i, needle.p, needle.n) == 0) {
|
|
877
|
-
found = (double)i;
|
|
878
|
-
break;
|
|
879
|
-
}
|
|
880
|
-
if (i == 0) break;
|
|
881
|
-
}
|
|
1034
|
+
Encoding enc = ENC_UTF8;
|
|
1035
|
+
bool known = true;
|
|
1036
|
+
if (!js_is_undefined(enc_arg)) {
|
|
1037
|
+
if (encoding_coerced(ctx, enc_arg, &enc_arg, &enc) < 0) return JS_EXCEPTION;
|
|
1038
|
+
known = enc != ENC_INVALID;
|
|
1039
|
+
}
|
|
1040
|
+
Bytes needle = { 0 };
|
|
1041
|
+
if (js_is_string(value)) {
|
|
1042
|
+
if (!known) return throw_unknown_encoding(ctx, enc_arg);
|
|
1043
|
+
encode_string(ctx, value, enc, &needle);
|
|
1044
|
+
} else {
|
|
1045
|
+
uint8_t *p;
|
|
1046
|
+
size_t n;
|
|
1047
|
+
if (!u8_bytes(value, &p, &n))
|
|
1048
|
+
return js_throw_invalid_arg_type(ctx, "value", "one of type number or string or an instance of Buffer or Uint8Array", value);
|
|
1049
|
+
if (!known) enc = ENC_UTF8;
|
|
1050
|
+
bytes_reserve(&needle, n);
|
|
1051
|
+
if (n) memcpy(needle.p, p, n);
|
|
1052
|
+
needle.n = n;
|
|
882
1053
|
}
|
|
1054
|
+
u8_bytes(this_val, &data, &len);
|
|
1055
|
+
found = index_of_bytes(data, len, needle.p, needle.n, offset_i64, end_i64, forward, enc == ENC_UCS2);
|
|
1056
|
+
free(needle.p);
|
|
883
1057
|
}
|
|
884
|
-
|
|
885
|
-
return kind == 2 ? js_bool(found >= 0) : js_number(found);
|
|
1058
|
+
return kind == 2 ? js_bool(found != -1) : js_number(found);
|
|
886
1059
|
}
|
|
887
1060
|
|
|
888
1061
|
BUILTIN(buffer_index_of) {
|
|
@@ -921,6 +1094,17 @@ BUILTIN(buffer_subarray) {
|
|
|
921
1094
|
return new_view(ctx, ta->buffer, ta->byte_offset + start, end - start);
|
|
922
1095
|
}
|
|
923
1096
|
|
|
1097
|
+
/* slice(start, end): this.subarray(start, end), as lib/buffer.js's (a Uint8Array's own subarray
|
|
1098
|
+
* on one that isn't a Buffer) */
|
|
1099
|
+
BUILTIN(buffer_slice) {
|
|
1100
|
+
UNUSED_ARGS;
|
|
1101
|
+
JSValue subarray = js_get_value(ctx, this_val, js_atom_from_cstr(ctx, "subarray"));
|
|
1102
|
+
if (js_is_exception(subarray)) return subarray;
|
|
1103
|
+
if (!js_is_callable(subarray)) return js_throw_type_error(ctx, "this.subarray is not a function");
|
|
1104
|
+
JSValue args[2] = { ARG(0), ARG(1) };
|
|
1105
|
+
return js_call(ctx, subarray, this_val, 2, args);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
924
1108
|
static JSValue swap(JSContext *ctx, JSValue this_val, size_t width) {
|
|
925
1109
|
THIS_BYTES();
|
|
926
1110
|
if (len % width) return js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_INVALID_BUFFER_SIZE", "Buffer size must be a multiple of %zu-bits", width * 8);
|
|
@@ -1000,13 +1184,16 @@ static void store_uint(uint8_t *p, size_t size, int order, uint64_t v) {
|
|
|
1000
1184
|
static JSValue read_int(JSContext *ctx, JSValue this_val, uint32_t argc, const JSValue *argv, size_t size, int order, bool is_signed, bool variable) {
|
|
1001
1185
|
THIS_BYTES();
|
|
1002
1186
|
if (variable) {
|
|
1187
|
+
/* readIntBE and its kin: no default offset */
|
|
1188
|
+
if (js_is_undefined(ARG(0))) return js_throw_invalid_arg_type(ctx, "offset", "of type number", ARG(0));
|
|
1003
1189
|
if (!js_is_number(ARG(1))) return js_throw_invalid_arg_type(ctx, "byteLength", "of type number", ARG(1));
|
|
1004
1190
|
double b = js_as_number(ARG(1));
|
|
1005
1191
|
if (!(b >= 1 && b <= 6) || b != trunc(b)) {
|
|
1006
1192
|
char received[64];
|
|
1007
1193
|
js_describe_value(ctx, ARG(1), received, sizeof received);
|
|
1008
1194
|
return js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_OUT_OF_RANGE",
|
|
1009
|
-
"The value of \"byteLength\" is out of range. It must be
|
|
1195
|
+
"The value of \"byteLength\" is out of range. It must be %s. Received %s",
|
|
1196
|
+
floor(b) != b ? "an integer" : ">= 1 and <= 6", received); /* boundsError: NaN too */
|
|
1010
1197
|
}
|
|
1011
1198
|
size = (size_t)b;
|
|
1012
1199
|
}
|
|
@@ -1021,13 +1208,16 @@ static JSValue read_int(JSContext *ctx, JSValue this_val, uint32_t argc, const J
|
|
|
1021
1208
|
static JSValue write_int(JSContext *ctx, JSValue this_val, uint32_t argc, const JSValue *argv, size_t size, int order, bool is_signed, bool variable) {
|
|
1022
1209
|
THIS_BYTES();
|
|
1023
1210
|
if (variable) {
|
|
1211
|
+
/* writeIntBE and its kin: no default offset */
|
|
1212
|
+
if (js_is_undefined(ARG(1))) return js_throw_invalid_arg_type(ctx, "offset", "of type number", ARG(1));
|
|
1024
1213
|
if (!js_is_number(ARG(2))) return js_throw_invalid_arg_type(ctx, "byteLength", "of type number", ARG(2));
|
|
1025
1214
|
double b = js_as_number(ARG(2));
|
|
1026
1215
|
if (!(b >= 1 && b <= 6) || b != trunc(b)) {
|
|
1027
1216
|
char received[64];
|
|
1028
1217
|
js_describe_value(ctx, ARG(2), received, sizeof received);
|
|
1029
1218
|
return js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_OUT_OF_RANGE",
|
|
1030
|
-
"The value of \"byteLength\" is out of range. It must be
|
|
1219
|
+
"The value of \"byteLength\" is out of range. It must be %s. Received %s",
|
|
1220
|
+
floor(b) != b ? "an integer" : ">= 1 and <= 6", received); /* boundsError: NaN too */
|
|
1031
1221
|
}
|
|
1032
1222
|
size = (size_t)b;
|
|
1033
1223
|
}
|
|
@@ -1035,9 +1225,8 @@ static JSValue write_int(JSContext *ctx, JSValue this_val, uint32_t argc, const
|
|
|
1035
1225
|
if (js_to_number(ctx, &v, ARG(0)) < 0) return JS_EXCEPTION;
|
|
1036
1226
|
double min = is_signed ? -ldexp(1, (int)(8 * size - 1)) : 0;
|
|
1037
1227
|
double max = is_signed ? ldexp(1, (int)(8 * size - 1)) - 1 : ldexp(1, (int)(8 * size)) - 1;
|
|
1038
|
-
|
|
1039
|
-
if (
|
|
1040
|
-
if (!(v >= min && v <= max)) {
|
|
1228
|
+
/* lib/internal/buffer.js's checkInt: the value (NaN passes, written as 0), then the offset */
|
|
1229
|
+
if (v > max || v < min) {
|
|
1041
1230
|
char range[160], received[64];
|
|
1042
1231
|
if (size > 4) {
|
|
1043
1232
|
if (is_signed) snprintf(range, sizeof range, ">= -(2 ** %zu) and < 2 ** %zu", 8 * size - 1, 8 * size - 1);
|
|
@@ -1046,10 +1235,13 @@ static JSValue write_int(JSContext *ctx, JSValue this_val, uint32_t argc, const
|
|
|
1046
1235
|
snprintf(range, sizeof range, ">= %.0f and <= %.0f", min, max);
|
|
1047
1236
|
}
|
|
1048
1237
|
js_describe_value(ctx, js_number(v), received, sizeof received);
|
|
1238
|
+
if (isfinite(v) && v == trunc(v) && fabs(v) > 4294967296.0) add_numerical_separator(received, sizeof received);
|
|
1049
1239
|
return js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_OUT_OF_RANGE", "The value of \"value\" is out of range. It must be %s. Received %s", range, received);
|
|
1050
1240
|
}
|
|
1241
|
+
size_t offset;
|
|
1242
|
+
if (access_offset(ctx, ARG(1), len, size, &offset) < 0) return JS_EXCEPTION;
|
|
1051
1243
|
u8_bytes(this_val, &data, &len);
|
|
1052
|
-
store_uint(data + offset, size, order, (uint64_t)(int64_t)trunc(v));
|
|
1244
|
+
store_uint(data + offset, size, order, isnan(v) ? 0 : (uint64_t)(int64_t)trunc(v));
|
|
1053
1245
|
return js_number((double)(offset + size));
|
|
1054
1246
|
}
|
|
1055
1247
|
|
|
@@ -1164,6 +1356,10 @@ static JSValue write_big(JSContext *ctx, JSValue this_val, uint32_t argc, const
|
|
|
1164
1356
|
JSValue s = ctx->rt->bigint->to_string(ctx, v, 10);
|
|
1165
1357
|
char received[96] = "";
|
|
1166
1358
|
if (js_is_string(s)) received[js_view_to_utf8(js_string_view(ctx, s), received, sizeof received - 1)] = '\0';
|
|
1359
|
+
/* Node's grouping, for a value past 2^32 in magnitude */
|
|
1360
|
+
const char *digits = received[0] == '-' ? received + 1 : received;
|
|
1361
|
+
size_t nd = strlen(digits);
|
|
1362
|
+
if (nd > 10 || (nd == 10 && strcmp(digits, "4294967296") > 0)) add_numerical_separator(received, sizeof received);
|
|
1167
1363
|
return js_throw_node_error(ctx, JS_RANGE_ERROR, "ERR_OUT_OF_RANGE", "The value of \"value\" is out of range. It must be %s. Received %sn",
|
|
1168
1364
|
is_signed ? ">= -(2n ** 63n) and < 2n ** 63n" : ">= 0n and < 2n ** 64n", received);
|
|
1169
1365
|
}
|
|
@@ -1189,8 +1385,18 @@ BIG(read_big_int64be, write_big_int64be, INT_BE, true)
|
|
|
1189
1385
|
|
|
1190
1386
|
/* ---- Inspection ----------------------------------------------------------------------------- */
|
|
1191
1387
|
|
|
1192
|
-
/*
|
|
1193
|
-
|
|
1388
|
+
/* buffer.INSPECT_MAX_BYTES (node:buffer's setter sets it): how many bytes inspect shows */
|
|
1389
|
+
static double inspect_max_bytes = 50;
|
|
1390
|
+
|
|
1391
|
+
/* bufferInspectMaxBytes(n): node:buffer's INSPECT_MAX_BYTES, validated there. */
|
|
1392
|
+
JSValue js_host_buffer_inspect_max_bytes(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
|
|
1393
|
+
UNUSED_ARGS;
|
|
1394
|
+
if (js_is_number(ARG(0))) inspect_max_bytes = js_as_number(ARG(0));
|
|
1395
|
+
return JS_UNDEFINED;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
/* `<Buffer 68 69>`: at most INSPECT_MAX_BYTES bytes, then ` ... n more bytes`, then the own
|
|
1399
|
+
* enumerable non-index properties (`<Buffer 61, foo: 1>`) */
|
|
1194
1400
|
BUILTIN(buffer_inspect) {
|
|
1195
1401
|
UNUSED_ARGS;
|
|
1196
1402
|
THIS_BYTES();
|
|
@@ -1202,7 +1408,8 @@ BUILTIN(buffer_inspect) {
|
|
|
1202
1408
|
if (js_is_exception(n)) return n;
|
|
1203
1409
|
if (js_is_string(n)) name[js_view_to_utf8(js_string_view(ctx, n), name, sizeof name - 1)] = '\0';
|
|
1204
1410
|
}
|
|
1205
|
-
|
|
1411
|
+
double max = inspect_max_bytes; /* lib/buffer.js: min(max, length) shown, length - max more */
|
|
1412
|
+
size_t shown = (double)len < max ? len : (size_t)max;
|
|
1206
1413
|
char *s = malloc(strlen(name) + shown * 3 + 64);
|
|
1207
1414
|
if (!s) js_fatal("out of memory inspecting a Buffer");
|
|
1208
1415
|
size_t o = (size_t)sprintf(s, "<%s ", name);
|
|
@@ -1211,7 +1418,8 @@ BUILTIN(buffer_inspect) {
|
|
|
1211
1418
|
s[o++] = HEX[data[i] >> 4];
|
|
1212
1419
|
s[o++] = HEX[data[i] & 15];
|
|
1213
1420
|
}
|
|
1214
|
-
|
|
1421
|
+
double remaining = (double)len - max;
|
|
1422
|
+
if (remaining > 0) o += (size_t)sprintf(s + o, " ... %.17g more byte%s", remaining, remaining > 1 ? "s" : "");
|
|
1215
1423
|
s[o] = '\0';
|
|
1216
1424
|
JSValue r = js_new_string_cstr(ctx, s);
|
|
1217
1425
|
free(s);
|
|
@@ -1325,14 +1533,14 @@ static const JSBuiltin buffer_proto[] = {
|
|
|
1325
1533
|
FN("equals", buffer_equals, 1),
|
|
1326
1534
|
FN("inspect", buffer_inspect, 2),
|
|
1327
1535
|
FN("compare", buffer_compare, 5),
|
|
1328
|
-
FN("indexOf", buffer_index_of,
|
|
1329
|
-
FN("lastIndexOf", buffer_last_index_of,
|
|
1330
|
-
FN("includes", buffer_includes,
|
|
1536
|
+
FN("indexOf", buffer_index_of, 4),
|
|
1537
|
+
FN("lastIndexOf", buffer_last_index_of, 4),
|
|
1538
|
+
FN("includes", buffer_includes, 4),
|
|
1331
1539
|
FN("fill", buffer_fill, 4),
|
|
1332
1540
|
FN("write", buffer_write, 4),
|
|
1333
1541
|
FN("toJSON", buffer_to_json, 0),
|
|
1334
1542
|
FN("subarray", buffer_subarray, 2),
|
|
1335
|
-
FN("slice",
|
|
1543
|
+
FN("slice", buffer_slice, 2),
|
|
1336
1544
|
FN("swap16", buffer_swap16, 0),
|
|
1337
1545
|
FN("swap32", buffer_swap32, 0),
|
|
1338
1546
|
FN("swap64", buffer_swap64, 0),
|