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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* SubtleCrypto (W3C Web Cryptography API §14), part of the crypto component
|
|
1
|
+
/* SubtleCrypto (W3C Web Cryptography API §14), part of the crypto component, as Node
|
|
2
2
|
* has it: its WebIDL conversions and their messages, algorithm normalization (a registry of the
|
|
3
3
|
* algorithms each operation supports, and their parameter dictionaries), and the operations.
|
|
4
4
|
* A method's errors reject its promise; its result is computed at the call, so the promise is
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
#include "js_buffer.h"
|
|
16
16
|
#include "js_convert.h"
|
|
17
17
|
#include "js_exception.h"
|
|
18
|
+
#include "js_host.h"
|
|
18
19
|
#include "js_ops.h"
|
|
19
20
|
#include "js_promise.h"
|
|
20
21
|
#include "js_web.h"
|
|
@@ -53,6 +54,14 @@ static JSValue op_failed(JSContext *ctx) {
|
|
|
53
54
|
return dom_error(ctx, "OperationError", "The operation failed for an operation-specific reason");
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
/* A key usage the algorithm doesn't allow: "Unsupported key usage for AES-GCM key" (Node 24's
|
|
58
|
+
* wording, the algorithm's name) */
|
|
59
|
+
static JSValue usage_error(JSContext *ctx, const char *algorithm) {
|
|
60
|
+
char m[96];
|
|
61
|
+
snprintf(m, sizeof m, "Unsupported key usage for %s key", algorithm);
|
|
62
|
+
return dom_error(ctx, "SyntaxError", m);
|
|
63
|
+
}
|
|
64
|
+
|
|
56
65
|
static JSValue array_buffer_of(JSContext *ctx, const uint8_t *p, size_t n) {
|
|
57
66
|
JSValue b = js_new_array_buffer(ctx, n);
|
|
58
67
|
if (js_is_exception(b)) return b;
|
|
@@ -213,7 +222,7 @@ static int arg_enum(Call *c, JSValue v, const char *const *values, int count, co
|
|
|
213
222
|
size_t n = js_view_to_utf8(js_string_view(c->ctx, s), shown, sizeof shown - 1);
|
|
214
223
|
shown[n < sizeof shown - 1 ? n : sizeof shown - 1] = 0;
|
|
215
224
|
return fail(js_throw_node_error(c->ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_VALUE",
|
|
216
|
-
"Failed to execute '%s' on 'SubtleCrypto': %s
|
|
225
|
+
"Failed to execute '%s' on 'SubtleCrypto': %s '%s' is not a valid enum value of type %s.",
|
|
217
226
|
c->op, where, shown, type));
|
|
218
227
|
}
|
|
219
228
|
|
|
@@ -235,7 +244,7 @@ static JSValue arg_usages(Call *c, JSValue v, int i, uint16_t *mask) {
|
|
|
235
244
|
if (js_is_exception(method)) return method;
|
|
236
245
|
if (!js_is_callable(method))
|
|
237
246
|
return js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE",
|
|
238
|
-
"Failed to execute '%s' on 'SubtleCrypto': %s argument
|
|
247
|
+
"Failed to execute '%s' on 'SubtleCrypto': %s argument cannot be converted to sequence.", c->op,
|
|
239
248
|
ORDINALS[i]);
|
|
240
249
|
JSValue out = js_new_array(ctx, 4);
|
|
241
250
|
JSValue rec = js_iter_start(ctx, v);
|
|
@@ -246,7 +255,7 @@ static JSValue arg_usages(Call *c, JSValue v, int i, uint16_t *mask) {
|
|
|
246
255
|
if (js_is_exception(u)) return u;
|
|
247
256
|
if (js_is_empty(u)) break;
|
|
248
257
|
char where[64];
|
|
249
|
-
snprintf(where, sizeof where, "%s argument
|
|
258
|
+
snprintf(where, sizeof where, "%s argument[%u]", ORDINALS[i], n);
|
|
250
259
|
int k = arg_enum(c, u, USAGES, 8, "KeyUsage", where);
|
|
251
260
|
if (k < 0) {
|
|
252
261
|
js_iter_close_throw(ctx, rec);
|
|
@@ -291,7 +300,7 @@ static int arg_jwk(Call *c, JSValue v, JWK *j) {
|
|
|
291
300
|
if (js_is_nullish(v)) return 0;
|
|
292
301
|
if (!js_is_object(v))
|
|
293
302
|
return fail(js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE",
|
|
294
|
-
"Failed to execute '%s' on 'SubtleCrypto': 2nd argument
|
|
303
|
+
"Failed to execute '%s' on 'SubtleCrypto': 2nd argument cannot be converted to a dictionary",
|
|
295
304
|
c->op));
|
|
296
305
|
for (int i = 0; i < JWK_COUNT; i++) {
|
|
297
306
|
JSValue m = js_get_value(ctx, v, js_atom_from_cstr(ctx, JWK_NAMES[i]));
|
|
@@ -304,8 +313,8 @@ static int arg_jwk(Call *c, JSValue v, JWK *j) {
|
|
|
304
313
|
if (js_is_exception(method)) return -1;
|
|
305
314
|
if (!js_is_callable(method))
|
|
306
315
|
return fail(js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE",
|
|
307
|
-
"Failed to execute '%s' on 'SubtleCrypto':
|
|
308
|
-
"
|
|
316
|
+
"Failed to execute '%s' on 'SubtleCrypto': key_ops in 2nd argument "
|
|
317
|
+
"cannot be converted to sequence.", c->op));
|
|
309
318
|
JSValue ops = js_new_array(ctx, 4), rec = js_iter_start(ctx, m);
|
|
310
319
|
if (js_is_exception(rec)) return -1;
|
|
311
320
|
for (;;) {
|
|
@@ -467,8 +476,9 @@ static void params_free(Params *p) {
|
|
|
467
476
|
static uint8_t params_alg(const Params *p) { return REGISTRY[p->entry].alg; }
|
|
468
477
|
|
|
469
478
|
static JSValue throw_member(JSContext *ctx, const char *code, Dict d, Member m, const char *what) {
|
|
470
|
-
|
|
471
|
-
|
|
479
|
+
(void)d; /* Node 24 names only the member */
|
|
480
|
+
return js_throw_node_error(ctx, JS_TYPE_ERROR, code, "Failed to normalize algorithm: %s in passed algorithm %s",
|
|
481
|
+
MEMBER_NAMES[m], what);
|
|
472
482
|
}
|
|
473
483
|
|
|
474
484
|
/* An [EnforceRange] integer member of at most `max`. 0, or -1. */
|
|
@@ -494,7 +504,7 @@ static int algorithm_name(JSContext *ctx, JSValue alg, char *name, size_t cap) {
|
|
|
494
504
|
if (js_is_exception(n)) return -1;
|
|
495
505
|
if (js_is_undefined(n))
|
|
496
506
|
return fail(js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_MISSING_OPTION",
|
|
497
|
-
"Failed to normalize algorithm: passed algorithm
|
|
507
|
+
"Failed to normalize algorithm: passed algorithm cannot be converted to 'Algorithm' "
|
|
498
508
|
"because 'name' is required in 'Algorithm'."));
|
|
499
509
|
}
|
|
500
510
|
JSValue s = js_to_string(ctx, n);
|
|
@@ -530,7 +540,7 @@ static int normalize(JSContext *ctx, JSValue alg, Op op, Params *p) {
|
|
|
530
540
|
if (js_is_undefined(v)) {
|
|
531
541
|
if (DICTS[d].required & (1u << i))
|
|
532
542
|
return fail(js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_MISSING_OPTION",
|
|
533
|
-
"Failed to normalize algorithm: passed algorithm
|
|
543
|
+
"Failed to normalize algorithm: passed algorithm cannot be converted to '%s' "
|
|
534
544
|
"because '%s' is required in '%s'.", DICTS[d].name, MEMBER_NAMES[m], DICTS[d].name));
|
|
535
545
|
continue;
|
|
536
546
|
}
|
|
@@ -610,20 +620,20 @@ static JSValue hash_object(JSContext *ctx, const JSHashAlg *hash) {
|
|
|
610
620
|
|
|
611
621
|
static bool has_any_not_in(uint16_t mask, uint16_t allowed) { return (mask & ~allowed) != 0; }
|
|
612
622
|
|
|
613
|
-
/* HMAC: the key's object, as Node orders it: { name,
|
|
614
|
-
* hash
|
|
615
|
-
static JSValue hmac_algorithm(JSContext *ctx, const JSHashAlg *hash, uint32_t length, bool generated) {
|
|
623
|
+
/* HMAC: the key's object, as Node 24 orders it: { name, length, hash } */
|
|
624
|
+
static JSValue hmac_algorithm(JSContext *ctx, const JSHashAlg *hash, uint32_t length) {
|
|
616
625
|
JSValue o = js_new_object(ctx);
|
|
617
626
|
put(ctx, o, "name", str(ctx, "HMAC"));
|
|
618
|
-
|
|
627
|
+
put(ctx, o, "length", js_number(length));
|
|
619
628
|
put(ctx, o, "hash", hash_object(ctx, hash));
|
|
620
|
-
if (!generated) put(ctx, o, "length", js_number(length));
|
|
621
629
|
return o;
|
|
622
630
|
}
|
|
623
631
|
|
|
624
632
|
static JSValue import_hmac(JSContext *ctx, int format, JSValue key_data, const JWK *jwk, Params *p, bool extractable, JSValue usages,
|
|
625
633
|
uint16_t mask) {
|
|
626
|
-
|
|
634
|
+
/* HmacImportParams' normalization comes first */
|
|
635
|
+
if (p->has_length && p->length == 0) return dom_error(ctx, "DataError", "HmacImportParams.length cannot be 0");
|
|
636
|
+
if (has_any_not_in(mask, JS_USAGE_SIGN | JS_USAGE_VERIFY)) return dom_error(ctx, "SyntaxError", "Unsupported key usage for HMAC key");
|
|
627
637
|
Bytes raw = { 0 };
|
|
628
638
|
if (format == FORMAT_RAW) {
|
|
629
639
|
bytes_copy(&raw, key_data);
|
|
@@ -650,17 +660,21 @@ static JSValue import_hmac(JSContext *ctx, int format, JSValue key_data, const J
|
|
|
650
660
|
return dom_error(ctx, "NotSupportedError", m);
|
|
651
661
|
}
|
|
652
662
|
uint32_t length = (uint32_t)raw.n * 8;
|
|
653
|
-
if (length == 0
|
|
663
|
+
if (length == 0) {
|
|
654
664
|
bytes_free(&raw);
|
|
655
665
|
return dom_error(ctx, "DataError", "Zero-length key is not supported");
|
|
656
666
|
}
|
|
657
|
-
if (p->has_length
|
|
658
|
-
|
|
659
|
-
|
|
667
|
+
if (p->has_length) { /* in whole bytes the key's; past a byte boundary, the key cut to that many bits */
|
|
668
|
+
if ((p->length + 7) / 8 != raw.n) {
|
|
669
|
+
bytes_free(&raw);
|
|
670
|
+
return dom_error(ctx, "DataError", "Invalid key length");
|
|
671
|
+
}
|
|
672
|
+
if (p->length % 8) raw.p[raw.n - 1] &= (uint8_t)(0xFF << (8 - p->length % 8));
|
|
673
|
+
length = p->length;
|
|
660
674
|
}
|
|
661
675
|
JSValue data = js_new_secret_key(ctx, raw.p, raw.n);
|
|
662
676
|
bytes_free(&raw);
|
|
663
|
-
return js_new_crypto_key(ctx, data, JS_WEB_HMAC, p->hash, length, hmac_algorithm(ctx, p->hash, length
|
|
677
|
+
return js_new_crypto_key(ctx, data, JS_WEB_HMAC, p->hash, length, hmac_algorithm(ctx, p->hash, length), usages, mask,
|
|
664
678
|
extractable);
|
|
665
679
|
}
|
|
666
680
|
|
|
@@ -717,7 +731,7 @@ static JSValue aes_algorithm(JSContext *ctx, const char *name, uint32_t length)
|
|
|
717
731
|
static JSValue import_aes(JSContext *ctx, int format, JSValue key_data, const JWK *jwk, Params *p, bool extractable, JSValue usages,
|
|
718
732
|
uint16_t mask) {
|
|
719
733
|
uint8_t alg = params_alg(p);
|
|
720
|
-
if (has_any_not_in(mask, aes_usages(alg))) return
|
|
734
|
+
if (has_any_not_in(mask, aes_usages(alg))) return usage_error(ctx, p->name);
|
|
721
735
|
Bytes raw = { 0 };
|
|
722
736
|
if (format == FORMAT_RAW) {
|
|
723
737
|
bytes_copy(&raw, key_data);
|
|
@@ -853,8 +867,7 @@ static JSValue import_asym(JSContext *ctx, int format, JSValue key_data, const J
|
|
|
853
867
|
}
|
|
854
868
|
bool is_public = format == FORMAT_SPKI || format == FORMAT_RAW || (format == FORMAT_JWK && js_is_undefined(jwk->m[JWK_D]));
|
|
855
869
|
if (has_any_not_in(mask, asym_usages(alg, is_public))) {
|
|
856
|
-
|
|
857
|
-
return dom_error(ctx, "SyntaxError", m);
|
|
870
|
+
return usage_error(ctx, name);
|
|
858
871
|
}
|
|
859
872
|
JSValue data = JS_UNDEFINED;
|
|
860
873
|
if (format == FORMAT_SPKI || format == FORMAT_PKCS8) {
|
|
@@ -869,8 +882,7 @@ static JSValue import_asym(JSContext *ctx, int format, JSValue key_data, const J
|
|
|
869
882
|
js_buffer_source_bytes(key_data, &bp, &bn);
|
|
870
883
|
JSKeyPart parts[JS_KEY_PARTS] = { { 0 } };
|
|
871
884
|
if (is_okp_alg(alg)) {
|
|
872
|
-
|
|
873
|
-
if (bn != 32) return dom_error(ctx, "DataError", m);
|
|
885
|
+
if (bn != 32) return dom_error(ctx, "DataError", "Invalid keyData");
|
|
874
886
|
parts[JS_EC_PUB].p = bp, parts[JS_EC_PUB].n = 32;
|
|
875
887
|
} else {
|
|
876
888
|
if (!js_ec_point_uncompressed(curve, bp, bn, point)) return dom_error(ctx, "DataError", "Invalid keyData");
|
|
@@ -1013,7 +1025,7 @@ static JSValue generate_asym(JSContext *ctx, Params *p, bool extractable, uint16
|
|
|
1013
1025
|
for (size_t i = 0; i < en; i++) exponent = exponent << 8 | e[i];
|
|
1014
1026
|
uint16_t allowed = alg == JS_WEB_RSA_OAEP ? JS_USAGE_ENCRYPT | JS_USAGE_DECRYPT | JS_USAGE_WRAP_KEY | JS_USAGE_UNWRAP_KEY
|
|
1015
1027
|
: JS_USAGE_SIGN | JS_USAGE_VERIFY;
|
|
1016
|
-
if (has_any_not_in(mask, allowed)) return
|
|
1028
|
+
if (has_any_not_in(mask, allowed)) return usage_error(ctx, name);
|
|
1017
1029
|
if (js_key_generate_rsa(ctx, false, p->modulus_length, exponent, &priv)) return op_failed(ctx);
|
|
1018
1030
|
} else {
|
|
1019
1031
|
int curve = is_okp_alg(alg) ? okp_curve(alg) : JS_EC_X25519;
|
|
@@ -1021,9 +1033,7 @@ static JSValue generate_asym(JSContext *ctx, Params *p, bool extractable, uint16
|
|
|
1021
1033
|
curve = js_ec_curve_by_jwk(p->named_curve);
|
|
1022
1034
|
if (curve < 0) return dom_error(ctx, "NotSupportedError", "Unrecognized namedCurve");
|
|
1023
1035
|
}
|
|
1024
|
-
|
|
1025
|
-
snprintf(m, sizeof m, "Unsupported key usage for an %s key", name);
|
|
1026
|
-
if (has_any_not_in(mask, asym_usages(alg, true) | asym_usages(alg, false))) return dom_error(ctx, "SyntaxError", m);
|
|
1036
|
+
if (has_any_not_in(mask, asym_usages(alg, true) | asym_usages(alg, false))) return usage_error(ctx, name);
|
|
1027
1037
|
if (js_key_generate_ec(ctx, curve, &priv)) return op_failed(ctx);
|
|
1028
1038
|
}
|
|
1029
1039
|
uint16_t pub_mask, priv_mask;
|
|
@@ -1041,7 +1051,7 @@ static JSValue generate_asym(JSContext *ctx, Params *p, bool extractable, uint16
|
|
|
1041
1051
|
/* importKey's steps after the `this` check, for subtle.importKey and deriveKey. */
|
|
1042
1052
|
static JSValue import_key(JSContext *ctx, uint32_t argc, const JSValue *argv) {
|
|
1043
1053
|
Call c = { ctx, "importKey" };
|
|
1044
|
-
if (argc <
|
|
1054
|
+
if (argc < 5) return throw_missing_args(&c, 5, argc);
|
|
1045
1055
|
int format = arg_format(&c, argv[0], 0);
|
|
1046
1056
|
if (format < 0) return JS_EXCEPTION;
|
|
1047
1057
|
JWK jwk;
|
|
@@ -1110,7 +1120,7 @@ static JSValue export_key(JSContext *ctx, uint32_t argc, const JSValue *argv) {
|
|
|
1110
1120
|
snprintf(m, sizeof m, "%s key export is not supported", k->alg == JS_WEB_PBKDF2 ? "PBKDF2" : "HKDF");
|
|
1111
1121
|
return dom_error(ctx, "NotSupportedError", m);
|
|
1112
1122
|
}
|
|
1113
|
-
if (!k->extractable) return dom_error(ctx, "
|
|
1123
|
+
if (!k->extractable) return dom_error(ctx, "InvalidAccessError", "key is not extractable");
|
|
1114
1124
|
if (is_asym_alg(k->alg)) return export_asym(ctx, format, k);
|
|
1115
1125
|
JSKeyData *d = js_key_data(k->data);
|
|
1116
1126
|
if (format == FORMAT_RAW) return array_buffer_of(ctx, d->bytes, d->len);
|
|
@@ -1135,6 +1145,66 @@ BUILTIN(subtle_export_key) {
|
|
|
1135
1145
|
return settled(ctx, export_key(ctx, argc, argv));
|
|
1136
1146
|
}
|
|
1137
1147
|
|
|
1148
|
+
/* ---- Node 24's experimental methods: getPublicKey, and ML-KEM's encapsulation ---------------- */
|
|
1149
|
+
|
|
1150
|
+
/* Node's emitExperimentalWarning: once per feature */
|
|
1151
|
+
static void experimental(JSContext *ctx, bool *warned, const char *feature) {
|
|
1152
|
+
if (*warned) return;
|
|
1153
|
+
*warned = true;
|
|
1154
|
+
char m[96];
|
|
1155
|
+
snprintf(m, sizeof m, "%s is an experimental feature and might change at any time", feature);
|
|
1156
|
+
js_emit_warning(ctx, str(ctx, m), "ExperimentalWarning", NULL);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/* getPublicKey(key, keyUsages): the public key of a private one, extractable */
|
|
1160
|
+
static JSValue get_public_key(JSContext *ctx, uint32_t argc, const JSValue *argv) {
|
|
1161
|
+
static bool warned;
|
|
1162
|
+
experimental(ctx, &warned, "The getPublicKey Web Crypto API method");
|
|
1163
|
+
Call c = { ctx, "getPublicKey" };
|
|
1164
|
+
if (argc < 2) return throw_missing_args(&c, 2, argc);
|
|
1165
|
+
JSCryptoKey *k = arg_key(&c, argv[0], 0);
|
|
1166
|
+
if (!k) return JS_EXCEPTION;
|
|
1167
|
+
uint16_t mask;
|
|
1168
|
+
JSValue usages = arg_usages(&c, argv[1], 1, &mask);
|
|
1169
|
+
if (js_is_exception(usages)) return usages;
|
|
1170
|
+
int type = js_key_data(k->data)->type;
|
|
1171
|
+
if (type != JS_KEY_PRIVATE)
|
|
1172
|
+
return dom_error(ctx, type == JS_KEY_SECRET ? "NotSupportedError" : "InvalidAccessError", "key must be a private key");
|
|
1173
|
+
JSValue data = js_key_public(ctx, k->data);
|
|
1174
|
+
return js_new_crypto_key(ctx, data, k->alg, k->hash, k->length, k->algorithm, usages, mask, true);
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
/* encapsulateBits/Key and decapsulateBits/Key: only ML-KEM has them, which visaljs doesn't provide,
|
|
1178
|
+
* so every algorithm is one Node doesn't recognize for them. `need` arguments, the key at `key_at`. */
|
|
1179
|
+
static JSValue kem_method(JSContext *ctx, const char *op, bool *warned, uint32_t need, int key_at, uint32_t argc, const JSValue *argv) {
|
|
1180
|
+
char feature[64];
|
|
1181
|
+
snprintf(feature, sizeof feature, "The %s Web Crypto API method", op);
|
|
1182
|
+
experimental(ctx, warned, feature);
|
|
1183
|
+
Call c = { ctx, op };
|
|
1184
|
+
if (argc < need) return throw_missing_args(&c, need, argc);
|
|
1185
|
+
if (arg_algorithm(&c, argv[0], 0) < 0) return JS_EXCEPTION;
|
|
1186
|
+
if (!arg_key(&c, argv[key_at], key_at)) return JS_EXCEPTION;
|
|
1187
|
+
return dom_error(ctx, "NotSupportedError", "Unrecognized algorithm name");
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
#define KEM_METHOD(fn, op, need, key_at) \
|
|
1191
|
+
BUILTIN(fn) { \
|
|
1192
|
+
(void)callee, (void)new_target; \
|
|
1193
|
+
static bool warned; \
|
|
1194
|
+
if (!is_subtle(this_val)) return rejected(ctx, js_throw_invalid_this(ctx, "SubtleCrypto")); \
|
|
1195
|
+
return settled(ctx, kem_method(ctx, op, &warned, need, key_at, argc, argv)); \
|
|
1196
|
+
}
|
|
1197
|
+
KEM_METHOD(subtle_encapsulate_bits, "encapsulateBits", 2, 1)
|
|
1198
|
+
KEM_METHOD(subtle_encapsulate_key, "encapsulateKey", 5, 1)
|
|
1199
|
+
KEM_METHOD(subtle_decapsulate_bits, "decapsulateBits", 3, 1)
|
|
1200
|
+
KEM_METHOD(subtle_decapsulate_key, "decapsulateKey", 6, 1)
|
|
1201
|
+
|
|
1202
|
+
BUILTIN(subtle_get_public_key) {
|
|
1203
|
+
(void)callee, (void)new_target;
|
|
1204
|
+
if (!is_subtle(this_val)) return rejected(ctx, js_throw_invalid_this(ctx, "SubtleCrypto"));
|
|
1205
|
+
return settled(ctx, get_public_key(ctx, argc, argv));
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1138
1208
|
static JSValue generate_key(JSContext *ctx, uint32_t argc, const JSValue *argv) {
|
|
1139
1209
|
Call c = { ctx, "generateKey" };
|
|
1140
1210
|
if (argc < 3) return throw_missing_args(&c, 3, argc);
|
|
@@ -1155,25 +1225,27 @@ static JSValue generate_key(JSContext *ctx, uint32_t argc, const JSValue *argv)
|
|
|
1155
1225
|
uint8_t alg = params_alg(&p);
|
|
1156
1226
|
uint32_t length;
|
|
1157
1227
|
if (alg == JS_WEB_HMAC) {
|
|
1228
|
+
/* HmacKeyGenParams' normalization first; any other length, in bits, is the key's */
|
|
1229
|
+
if (p.has_length && p.length == 0) return dom_error(ctx, "OperationError", "HmacKeyGenParams.length cannot be 0");
|
|
1158
1230
|
length = p.has_length ? p.length : (uint32_t)p.hash->block_len * 8;
|
|
1159
|
-
if (has_any_not_in(mask, JS_USAGE_SIGN | JS_USAGE_VERIFY)) return dom_error(ctx, "SyntaxError", "Unsupported key usage for
|
|
1160
|
-
if (length == 0) return dom_error(ctx, "DataError", "Zero-length key is not supported");
|
|
1161
|
-
if (length % 8) return dom_error(ctx, "NotSupportedError", "Unsupported algorithm.length");
|
|
1231
|
+
if (has_any_not_in(mask, JS_USAGE_SIGN | JS_USAGE_VERIFY)) return dom_error(ctx, "SyntaxError", "Unsupported key usage for HMAC key");
|
|
1162
1232
|
} else {
|
|
1163
1233
|
length = p.length;
|
|
1164
1234
|
if (length != 128 && length != 192 && length != 256)
|
|
1165
1235
|
return dom_error(ctx, "OperationError", "AES key length must be 128, 192, or 256 bits");
|
|
1166
|
-
if (has_any_not_in(mask, aes_usages(alg))) return
|
|
1236
|
+
if (has_any_not_in(mask, aes_usages(alg))) return usage_error(ctx, p.name);
|
|
1167
1237
|
}
|
|
1168
1238
|
JSValue usages = usages_array(ctx, given);
|
|
1169
1239
|
if (js_is_exception(usages)) return usages;
|
|
1170
|
-
|
|
1240
|
+
size_t n = (length + 7) / 8;
|
|
1241
|
+
uint8_t *bytes = malloc(n);
|
|
1171
1242
|
if (!bytes) js_fatal("out of memory in crypto");
|
|
1172
|
-
js_crypto_random(bytes,
|
|
1173
|
-
|
|
1243
|
+
js_crypto_random(bytes, n);
|
|
1244
|
+
if (length % 8) bytes[n - 1] &= (uint8_t)(0xFF << (8 - length % 8));
|
|
1245
|
+
JSValue data = js_new_secret_key(ctx, bytes, n);
|
|
1174
1246
|
free(bytes);
|
|
1175
1247
|
if (js_array_length(js_as_object(usages)) == 0) return dom_error(ctx, "SyntaxError", "Usages cannot be empty when creating a key.");
|
|
1176
|
-
JSValue algorithm = alg == JS_WEB_HMAC ? hmac_algorithm(ctx, p.hash, length
|
|
1248
|
+
JSValue algorithm = alg == JS_WEB_HMAC ? hmac_algorithm(ctx, p.hash, length) : aes_algorithm(ctx, p.name, length);
|
|
1177
1249
|
return js_new_crypto_key(ctx, data, alg, p.hash, length, algorithm, usages, mask, extractable);
|
|
1178
1250
|
}
|
|
1179
1251
|
|
|
@@ -1271,15 +1343,19 @@ BUILTIN(subtle_verify) {
|
|
|
1271
1343
|
/* ---- deriveBits and deriveKey ------------------------------------------------------------------ */
|
|
1272
1344
|
|
|
1273
1345
|
/* WebIDL's unsigned long (no [EnforceRange]): modulo 2^32. */
|
|
1274
|
-
|
|
1346
|
+
/* An [EnforceRange] unsigned long argument: finite, and in range once truncated. 0, or -1. */
|
|
1347
|
+
static int arg_ulong_enforced(Call *c, JSValue v, int i, uint32_t *out) {
|
|
1275
1348
|
double x;
|
|
1276
|
-
if (js_to_number(ctx, &x, v) < 0) return -1;
|
|
1277
|
-
if (!isfinite(x)
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
x =
|
|
1282
|
-
if (x < 0
|
|
1349
|
+
if (js_to_number(c->ctx, &x, v) < 0) return -1;
|
|
1350
|
+
if (!isfinite(x))
|
|
1351
|
+
return fail(js_throw_node_error(c->ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE",
|
|
1352
|
+
"Failed to execute '%s' on 'SubtleCrypto': %s argument is not a finite number.", c->op,
|
|
1353
|
+
ORDINALS[i]));
|
|
1354
|
+
x = trunc(x);
|
|
1355
|
+
if (x < 0 || x > 4294967295.0)
|
|
1356
|
+
return fail(js_throw_node_error(c->ctx, JS_TYPE_ERROR, "ERR_OUT_OF_RANGE",
|
|
1357
|
+
"Failed to execute '%s' on 'SubtleCrypto': %s argument is outside the expected range of 0 to "
|
|
1358
|
+
"4294967295.", c->op, ORDINALS[i]));
|
|
1283
1359
|
*out = (uint32_t)x;
|
|
1284
1360
|
return 0;
|
|
1285
1361
|
}
|
|
@@ -1288,12 +1364,9 @@ static int to_ulong(JSContext *ctx, JSValue v, uint32_t *out) {
|
|
|
1288
1364
|
static JSValue ecdh_bits(JSContext *ctx, Params *p, JSCryptoKey *k, bool has_length, uint32_t length) {
|
|
1289
1365
|
JSCryptoKey *pub = p->public_key;
|
|
1290
1366
|
JSKeyData *pd = js_key_data(pub->data), *d = js_key_data(k->data);
|
|
1291
|
-
char m[64];
|
|
1292
1367
|
if (pd->type != JS_KEY_PUBLIC) return dom_error(ctx, "InvalidAccessError", "algorithm.public must be a public key");
|
|
1293
|
-
if (pub->alg !=
|
|
1294
|
-
|
|
1295
|
-
return dom_error(ctx, "InvalidAccessError", m);
|
|
1296
|
-
}
|
|
1368
|
+
if (pub->alg != params_alg(p)) return dom_error(ctx, "InvalidAccessError", "key algorithm mismatch");
|
|
1369
|
+
if (pub->alg != k->alg) return dom_error(ctx, "InvalidAccessError", "The public and private keys must be of the same type");
|
|
1297
1370
|
if (pd->curve != d->curve) return dom_error(ctx, "InvalidAccessError", "Named curve mismatch");
|
|
1298
1371
|
uint8_t secret[66];
|
|
1299
1372
|
size_t n;
|
|
@@ -1333,7 +1406,7 @@ static JSValue subtle_derive_bits_steps(JSContext *ctx, uint32_t argc, const JSV
|
|
|
1333
1406
|
if (!k) return JS_EXCEPTION;
|
|
1334
1407
|
bool has_length = argc > 2 && !js_is_nullish(argv[2]);
|
|
1335
1408
|
uint32_t length = 0;
|
|
1336
|
-
if (has_length &&
|
|
1409
|
+
if (has_length && arg_ulong_enforced(&c, argv[2], 2, &length) < 0) return JS_EXCEPTION;
|
|
1337
1410
|
Params p;
|
|
1338
1411
|
if (normalize(ctx, argv[0], OP_DERIVE_BITS, &p) < 0) {
|
|
1339
1412
|
params_free(&p);
|
|
@@ -1483,7 +1556,7 @@ static JSValue aes_cipher(JSContext *ctx, bool encrypt, JSCryptoKey *k, Params *
|
|
|
1483
1556
|
return dom_error(ctx, "OperationError", m);
|
|
1484
1557
|
}
|
|
1485
1558
|
size_t tag_n = tag_bits / 8;
|
|
1486
|
-
if (!encrypt && data->n < tag_n) return
|
|
1559
|
+
if (!encrypt && data->n < tag_n) return op_failed(ctx);
|
|
1487
1560
|
if (p->iv.n < 12) return op_failed(ctx);
|
|
1488
1561
|
const JSCipherAlg *alg = js_cipher_aes(JS_CIPHER_GCM, d->len);
|
|
1489
1562
|
ok = encrypt ? run_cipher(alg, true, d, p->iv.p, p->iv.n, (long)tag_n, &p->additional_data, NULL, 0, data->p, data->n, &out)
|
|
@@ -1504,8 +1577,14 @@ static JSValue aes_cipher(JSContext *ctx, bool encrypt, JSCryptoKey *k, Params *
|
|
|
1504
1577
|
|
|
1505
1578
|
/* cipherOrWrap: the key must be for the algorithm and allow the use. */
|
|
1506
1579
|
static JSValue cipher_or_wrap(JSContext *ctx, bool encrypt, Params *p, JSCryptoKey *k, const Bytes *data, uint16_t usage) {
|
|
1507
|
-
if (params_alg(p) != k->alg
|
|
1508
|
-
|
|
1580
|
+
if (params_alg(p) != k->alg) return dom_error(ctx, "InvalidAccessError", "Key algorithm mismatch");
|
|
1581
|
+
if (!(k->usage_mask & usage)) {
|
|
1582
|
+
const char *op = usage == JS_USAGE_ENCRYPT ? "encrypt" : usage == JS_USAGE_DECRYPT ? "decrypt"
|
|
1583
|
+
: usage == JS_USAGE_WRAP_KEY ? "wrapKey" : "unwrapKey";
|
|
1584
|
+
char m[48];
|
|
1585
|
+
snprintf(m, sizeof m, "Unable to use this key to %s", op);
|
|
1586
|
+
return dom_error(ctx, "InvalidAccessError", m);
|
|
1587
|
+
}
|
|
1509
1588
|
if (k->alg == JS_WEB_RSA_OAEP) { /* encrypting with the public key, decrypting with the private one */
|
|
1510
1589
|
JSKeyData *d = js_key_data(k->data);
|
|
1511
1590
|
if (d->type != (encrypt ? JS_KEY_PUBLIC : JS_KEY_PRIVATE))
|
|
@@ -1688,6 +1767,11 @@ static const JSBuiltin subtle_proto[] = { /* Node's order and lengths */
|
|
|
1688
1767
|
WEBIDL_OPERATION("exportKey", subtle_export_key, 2),
|
|
1689
1768
|
WEBIDL_OPERATION("wrapKey", subtle_wrap_key, 4),
|
|
1690
1769
|
WEBIDL_OPERATION("unwrapKey", subtle_unwrap_key, 7),
|
|
1770
|
+
WEBIDL_OPERATION("getPublicKey", subtle_get_public_key, 2),
|
|
1771
|
+
WEBIDL_OPERATION("encapsulateBits", subtle_encapsulate_bits, 2),
|
|
1772
|
+
WEBIDL_OPERATION("encapsulateKey", subtle_encapsulate_key, 5),
|
|
1773
|
+
WEBIDL_OPERATION("decapsulateBits", subtle_decapsulate_bits, 3),
|
|
1774
|
+
WEBIDL_OPERATION("decapsulateKey", subtle_decapsulate_key, 6),
|
|
1691
1775
|
};
|
|
1692
1776
|
|
|
1693
1777
|
void js_crypto_install_subtle(JSContext *ctx, JSObject *global) {
|
package/runtime/src/crypto_tls.c
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* node:tls's host primitives
|
|
1
|
+
/* node:tls's host primitives: TLS 1.0–1.3 on BoringSSL, the OpenSSL fork, so
|
|
2
2
|
* connections behave as Node's (OpenSSL's) do: chain building, alerts, half-close, sessions and
|
|
3
3
|
* tickets, X509_V_ERR verification results. node/prelude's tls.js builds Node's SecureContext,
|
|
4
4
|
* TLSSocket and Server on these; this file only drives BoringSSL.
|
package/runtime/src/date.c
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
/* Date (ECMAScript §21.4), the date component
|
|
1
|
+
/* Date (ECMAScript §21.4), the date component.
|
|
2
2
|
*
|
|
3
3
|
* A Date holds a time value: milliseconds since the epoch, UTC, or NaN. Local time comes from the
|
|
4
4
|
* C library's time zone (localtime_r: TZ, else /etc/localtime), and the zone's English names,
|
|
5
5
|
* which Date.prototype.toString shows as Node does ("Western European Summer Time"), from a table
|
|
6
6
|
* generated from Node's ICU data (tznames.gen.h). Date.parse is V8's parser: the ISO format,
|
|
7
|
-
* then its legacy one. toLocaleString and friends format as en-US, whatever locale is asked.
|
|
7
|
+
* then its legacy one. toLocaleString and friends format as en-US, whatever locale is asked.
|
|
8
|
+
*
|
|
9
|
+
* Date.parse is ported from V8 (Copyright the V8 project authors, BSD 3-clause):
|
|
10
|
+
* runtime/third_party/v8-ieee754/LICENSE. */
|
|
8
11
|
#include <math.h>
|
|
9
12
|
#include <stdio.h>
|
|
10
13
|
#include <stdlib.h>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/* DOMException (WebIDL §3.14.1), the domexception component
|
|
1
|
+
/* DOMException (WebIDL §3.14.1), the domexception component, as Node has it:
|
|
2
2
|
* new DOMException(message, name | { name, cause }), with name, message and code getters on the
|
|
3
3
|
* prototype, the legacy code constants, and Error.prototype as the prototype's prototype. An
|
|
4
4
|
* instance has an own `stack`, "Name: message", which is what V8 captures (no frames, as for
|
|
5
|
-
* every error here
|
|
5
|
+
* every error here). */
|
|
6
6
|
#include "js_web.h"
|
|
7
7
|
|
|
8
8
|
#include <string.h>
|
package/runtime/src/elements.c
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Indexed properties
|
|
1
|
+
/* Indexed properties: dense JSValue storage with EMPTY holes, or a
|
|
2
2
|
* sparse table; objects start on the static empty store. */
|
|
3
3
|
#include "elements.h"
|
|
4
4
|
|
|
@@ -29,7 +29,35 @@ static void grow_dense(JSContext *ctx, JSObject *o, uint32_t i) {
|
|
|
29
29
|
old = o->elements; /* unchanged, but re-read after the allocation */
|
|
30
30
|
memcpy(e->data, old->data, (size_t)old->length * sizeof(JSValue));
|
|
31
31
|
e->length = old->length;
|
|
32
|
-
o->elements
|
|
32
|
+
js_store_ptr(ctx, &o->cell, &o->elements, e);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void js_elements_append_dense(JSContext *ctx, JSObject *o, JSValue v) {
|
|
36
|
+
uint32_t i = o->elements->length;
|
|
37
|
+
if (i >= o->elements->capacity) grow_dense(ctx, o, i);
|
|
38
|
+
JSElements *d = o->elements;
|
|
39
|
+
js_store(ctx, &d->cell, &d->data[i], v);
|
|
40
|
+
d->length = i + 1;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* Array.prototype.fill's fast path: stores v at [start, end) of an array, directly, when that
|
|
44
|
+
* is what the generic loop of [[Set]]s would do. That needs an extensible array with dense
|
|
45
|
+
* elements, end within its length, and prototypes that can't intercept an index: ordinary
|
|
46
|
+
* objects or arrays without elements (a hole's [[Set]] would find their setters). 1 done, 0 not
|
|
47
|
+
* applicable. */
|
|
48
|
+
int js_elements_fill(JSContext *ctx, JSObject *o, uint32_t start, uint32_t end, JSValue v) {
|
|
49
|
+
if (o->cell.kind != JS_CELL_ARRAY || is_sparse(o) || !(o->shape->flags & JS_SHAPE_EXTENSIBLE)) return 0;
|
|
50
|
+
if (start >= end || end > js_array_length(o) || start > o->elements->length + JS_SPARSE_GAP) return 0;
|
|
51
|
+
for (JSValue p = o->shape->proto; js_is_object(p); p = js_as_object(p)->shape->proto) {
|
|
52
|
+
JSObject *q = js_as_object(p);
|
|
53
|
+
if (q->shape->cls != &js_class_object && q->shape->cls != &js_class_array) return 0;
|
|
54
|
+
if (q->elements->kind != JS_ELEMENTS_DENSE || q->elements->length != 0) return 0;
|
|
55
|
+
}
|
|
56
|
+
if (end > o->elements->capacity) grow_dense(ctx, o, end - 1);
|
|
57
|
+
JSElements *d = o->elements;
|
|
58
|
+
for (uint32_t i = start; i < end; i++) js_store(ctx, &d->cell, &d->data[i], v);
|
|
59
|
+
if (end > d->length) d->length = end;
|
|
60
|
+
return 1;
|
|
33
61
|
}
|
|
34
62
|
|
|
35
63
|
/* ---- Sparse ------------------------------------------------------------------ */
|
|
@@ -46,24 +74,27 @@ static JSSparseEntry *sparse_find(JSSparseElements *s, uint32_t i) {
|
|
|
46
74
|
}
|
|
47
75
|
}
|
|
48
76
|
|
|
49
|
-
|
|
77
|
+
/* A sparse table's entries are the heap's external memory. */
|
|
78
|
+
static void sparse_rehash(JSContext *ctx, JSSparseElements *s, uint32_t cap) {
|
|
50
79
|
JSSparseEntry *old = s->entries;
|
|
51
80
|
uint32_t old_cap = s->cap;
|
|
52
81
|
s->entries = calloc(cap, sizeof *s->entries);
|
|
53
82
|
if (!s->entries) js_fatal("out of memory (sparse elements)");
|
|
83
|
+
js_gc_external_add(ctx->rt, (size_t)cap * sizeof *s->entries);
|
|
84
|
+
js_gc_external_sub(ctx->rt, (size_t)old_cap * sizeof *s->entries);
|
|
54
85
|
s->cap = cap;
|
|
55
86
|
s->tombstones = 0;
|
|
56
87
|
for (uint32_t k = 0; k < old_cap; k++) {
|
|
57
88
|
if (old[k].state != 1) continue;
|
|
58
89
|
uint32_t h = index_hash(old[k].index) & (cap - 1);
|
|
59
90
|
while (s->entries[h].state) h = (h + 1) & (cap - 1);
|
|
60
|
-
s->entries[h] = old[k];
|
|
91
|
+
s->entries[h] = old[k]; /* barrier: same owner */
|
|
61
92
|
}
|
|
62
93
|
free(old);
|
|
63
94
|
}
|
|
64
95
|
|
|
65
|
-
static JSSparseEntry *sparse_insert(JSSparseElements *s, uint32_t i) {
|
|
66
|
-
if (2 * (s->count + s->tombstones + 1) > s->cap) sparse_rehash(s, s->count * 4 + 16 > s->cap ? s->cap * 2 : s->cap);
|
|
96
|
+
static JSSparseEntry *sparse_insert(JSContext *ctx, JSSparseElements *s, uint32_t i) {
|
|
97
|
+
if (2 * (s->count + s->tombstones + 1) > s->cap) sparse_rehash(ctx, s, s->count * 4 + 16 > s->cap ? s->cap * 2 : s->cap);
|
|
67
98
|
uint32_t h = index_hash(i) & (s->cap - 1);
|
|
68
99
|
while (s->entries[h].state == 1) h = (h + 1) & (s->cap - 1);
|
|
69
100
|
if (s->entries[h].state == 2) s->tombstones--;
|
|
@@ -83,21 +114,23 @@ static JSSparseElements *to_sparse(JSContext *ctx, JSObject *o) {
|
|
|
83
114
|
s->cap = 16;
|
|
84
115
|
s->entries = calloc(s->cap, sizeof *s->entries);
|
|
85
116
|
if (!s->entries) js_fatal("out of memory (sparse elements)");
|
|
117
|
+
js_gc_external_add(ctx->rt, (size_t)s->cap * sizeof *s->entries);
|
|
86
118
|
JSElements *d = o->elements;
|
|
87
119
|
for (uint32_t i = 0; i < d->length; i++) {
|
|
88
120
|
if (js_is_empty(d->data[i])) continue;
|
|
89
|
-
JSSparseEntry *e = sparse_insert(s, i);
|
|
121
|
+
JSSparseEntry *e = sparse_insert(ctx, s, i);
|
|
90
122
|
e->attrs = JS_PROP_DEFAULT;
|
|
91
123
|
e->value = d->data[i];
|
|
92
124
|
}
|
|
93
|
-
o->elements
|
|
125
|
+
js_store_ptr(ctx, &o->cell, &o->elements, (JSElements *)s);
|
|
94
126
|
return s;
|
|
95
127
|
}
|
|
96
128
|
|
|
97
129
|
void js_elements_finalize(JSRuntime *rt, JSCell *c) {
|
|
98
|
-
(void)rt;
|
|
99
130
|
JSElements *e = (JSElements *)c;
|
|
100
|
-
if (e->kind
|
|
131
|
+
if (e->kind != JS_ELEMENTS_SPARSE) return;
|
|
132
|
+
js_gc_external_sub(rt, (size_t)as_sparse(e)->cap * sizeof *as_sparse(e)->entries);
|
|
133
|
+
free(as_sparse(e)->entries);
|
|
101
134
|
}
|
|
102
135
|
|
|
103
136
|
/* ---- Operations -------------------------------------------------------------- */
|
|
@@ -218,8 +251,14 @@ int js_elements_define(JSContext *ctx, JSObject *o, uint32_t i, const JSProperty
|
|
|
218
251
|
if (na == JS_PROP_DEFAULT && !is_sparse(o)) {
|
|
219
252
|
JSElements *d = o->elements;
|
|
220
253
|
if (i >= d->capacity) {
|
|
221
|
-
|
|
222
|
-
|
|
254
|
+
/* Counted, not taken from length: holes don't fill a store. Flag enums
|
|
255
|
+
* (E[1] … E[2 ** 30]) double the index on each write, which an upper bound
|
|
256
|
+
* of length never sees as half empty. Only writes past the gap count. */
|
|
257
|
+
if (i > d->length + JS_SPARSE_GAP) {
|
|
258
|
+
uint64_t present = 0;
|
|
259
|
+
for (uint32_t k = 0; k < d->length; k++) present += !js_is_empty(d->data[k]);
|
|
260
|
+
if ((present + 1) * 2 < (uint64_t)i + 1) goto sparse;
|
|
261
|
+
}
|
|
223
262
|
grow_dense(ctx, o, i);
|
|
224
263
|
d = o->elements;
|
|
225
264
|
}
|
|
@@ -230,7 +269,7 @@ int js_elements_define(JSContext *ctx, JSObject *o, uint32_t i, const JSProperty
|
|
|
230
269
|
sparse:;
|
|
231
270
|
JSSparseElements *s = to_sparse(ctx, o);
|
|
232
271
|
JSSparseEntry *e = sparse_find(s, i);
|
|
233
|
-
if (!e) e = sparse_insert(s, i);
|
|
272
|
+
if (!e) e = sparse_insert(ctx, s, i);
|
|
234
273
|
e->attrs = na;
|
|
235
274
|
js_store(ctx, &s->cell, &e->value, value);
|
|
236
275
|
return 1;
|
|
@@ -239,7 +278,7 @@ sparse:;
|
|
|
239
278
|
int js_elements_delete(JSContext *ctx, JSObject *o, uint32_t i, bool throw_on_fail) {
|
|
240
279
|
JSElements *d = o->elements;
|
|
241
280
|
if (d->kind == JS_ELEMENTS_DENSE) {
|
|
242
|
-
if (i < d->length) d->data[i] = JS_EMPTY; /* a hole; the store stays dense */
|
|
281
|
+
if (i < d->length) d->data[i] = JS_EMPTY; /* a hole; the store stays dense; barrier: not a cell */
|
|
243
282
|
return 1;
|
|
244
283
|
}
|
|
245
284
|
JSSparseEntry *e = sparse_find(as_sparse(d), i);
|
|
@@ -265,7 +304,7 @@ JSValueArray *js_elements_keys(JSContext *ctx, JSObject *o) {
|
|
|
265
304
|
JSValueArray *keys = js_alloc_value_array(ctx, n);
|
|
266
305
|
d = o->elements;
|
|
267
306
|
for (uint32_t i = 0, k = 0; i < d->length; i++)
|
|
268
|
-
if (!js_is_empty(d->data[i])) keys->values[k++] = js_index_key(i);
|
|
307
|
+
if (!js_is_empty(d->data[i])) keys->values[k++] = js_index_key(i); /* barrier: fresh cell */
|
|
269
308
|
return keys;
|
|
270
309
|
}
|
|
271
310
|
JSSparseElements *s = as_sparse(d);
|
|
@@ -276,7 +315,7 @@ JSValueArray *js_elements_keys(JSContext *ctx, JSObject *o) {
|
|
|
276
315
|
if (s->entries[k].state == 1) idx[j++] = s->entries[k].index;
|
|
277
316
|
qsort(idx, n, sizeof *idx, cmp_u32);
|
|
278
317
|
JSValueArray *keys = js_alloc_value_array(ctx, n);
|
|
279
|
-
for (uint32_t k = 0; k < n; k++) keys->values[k] = js_index_key(idx[k]);
|
|
318
|
+
for (uint32_t k = 0; k < n; k++) keys->values[k] = js_index_key(idx[k]); /* barrier: fresh cell */
|
|
280
319
|
free(idx);
|
|
281
320
|
return keys;
|
|
282
321
|
}
|
|
@@ -287,7 +326,7 @@ uint32_t js_elements_truncate(JSContext *ctx, JSObject *o, uint32_t new_len) {
|
|
|
287
326
|
if (d->kind == JS_ELEMENTS_DENSE) {
|
|
288
327
|
if (d->length > new_len) {
|
|
289
328
|
if (d->cell.flags & JS_CELL_STATIC) return new_len;
|
|
290
|
-
for (uint32_t i = new_len; i < d->length; i++) d->data[i] = JS_EMPTY;
|
|
329
|
+
for (uint32_t i = new_len; i < d->length; i++) d->data[i] = JS_EMPTY; /* barrier: not a cell */
|
|
291
330
|
d->length = new_len;
|
|
292
331
|
}
|
|
293
332
|
return new_len;
|
package/runtime/src/elements.h
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* elements.h — indexed properties
|
|
1
|
+
/* elements.h — indexed properties. Runtime-internal. */
|
|
2
2
|
#ifndef JS_ELEMENTS_H
|
|
3
3
|
#define JS_ELEMENTS_H
|
|
4
4
|
|
|
@@ -26,7 +26,7 @@ typedef struct JSSparseElements { /* kind = ELEMENTS, JS_ELEMENTS_SPARSE */
|
|
|
26
26
|
} JSSparseElements;
|
|
27
27
|
|
|
28
28
|
/* Dense → sparse: when a write lands this far past the used slots, and the
|
|
29
|
-
* result would be less than half full
|
|
29
|
+
* result would be less than half full. */
|
|
30
30
|
#define JS_SPARSE_GAP 1024
|
|
31
31
|
|
|
32
32
|
int js_elements_get_own(JSContext *ctx, JSObject *o, uint32_t i, JSPropertyDescriptor *out);
|
|
@@ -34,6 +34,11 @@ int js_elements_define(JSContext *ctx, JSObject *o, uint32_t i, const JSProperty
|
|
|
34
34
|
int js_elements_delete(JSContext *ctx, JSObject *o, uint32_t i, bool throw_on_fail);
|
|
35
35
|
/* Fast path for [[Set]]: an existing writable data element. Returns 1 if stored. */
|
|
36
36
|
int js_elements_try_store(JSContext *ctx, JSObject *o, uint32_t i, JSValue v);
|
|
37
|
+
/* Appends v to a dense store at its length (Array.prototype.push's fast path: the caller has
|
|
38
|
+
* checked that the store's length is the array's, and that adding an index is allowed). */
|
|
39
|
+
void js_elements_append_dense(JSContext *ctx, JSObject *o, JSValue v);
|
|
40
|
+
/* Array.prototype.fill on a plain dense array: 1 if stored, 0 to take the generic path. */
|
|
41
|
+
int js_elements_fill(JSContext *ctx, JSObject *o, uint32_t start, uint32_t end, JSValue v);
|
|
37
42
|
/* Present indices, ascending, into a new JSValueArray of keys. */
|
|
38
43
|
JSValueArray *js_elements_keys(JSContext *ctx, JSObject *o);
|
|
39
44
|
/* Removes elements at indices ≥ new_len, from the top. Stops at a
|