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/encoding.c
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* TextEncoder and TextDecoder (WHATWG Encoding), the encoding component
|
|
1
|
+
/* TextEncoder and TextDecoder (WHATWG Encoding), the encoding component,
|
|
2
2
|
* which needs the typedarray component. As in Node: TextEncoder writes UTF-8 (lone surrogates
|
|
3
3
|
* become U+FFFD); TextDecoder reads UTF-8, UTF-16LE, UTF-16BE and windows-1252 (the labels
|
|
4
4
|
* latin1, ascii, …), streaming, with `fatal` and `ignoreBOM`, and Node's errors and inspection.
|
package/runtime/src/error.c
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Error objects and constructors (ECMAScript §20.5
|
|
1
|
+
/* Error objects and constructors (ECMAScript §20.5). */
|
|
2
2
|
#include "js_error.h"
|
|
3
3
|
|
|
4
4
|
#include "internal.h"
|
|
@@ -32,12 +32,12 @@ static JSValue error_name(JSErrorKind kind) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/* ---- `stack` (not in the spec
|
|
35
|
+
/* ---- `stack` (not in the spec) -------------------------------------------------------- */
|
|
36
36
|
|
|
37
37
|
/* `stack`, as V8 has it: an own, non-enumerable accessor installed first, whose getter formats
|
|
38
38
|
* "Name: message" on the first read, with the name and message the error has then (a subclass
|
|
39
39
|
* that sets this.name in its constructor shows it), and keeps it; the setter replaces it. Only
|
|
40
|
-
* that first line: frames aren't recorded
|
|
40
|
+
* that first line: frames aren't recorded, so creating an error costs no
|
|
41
41
|
* stack walk. */
|
|
42
42
|
static JSValue stack_get(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
|
|
43
43
|
const JSValue *argv, JSValue new_target) {
|
|
@@ -188,7 +188,7 @@ static JSValue error_proto_to_string(JSContext *ctx, JSValue callee, JSValue thi
|
|
|
188
188
|
/* ---- Error.captureStackTrace and Error.stackTraceLimit (V8's; not in the spec) ------------- */
|
|
189
189
|
|
|
190
190
|
/* Error.captureStackTrace(target, constructorOpt): V8's way to give any object a `stack`. Frames
|
|
191
|
-
* aren't recorded
|
|
191
|
+
* aren't recorded, so it is the first line, as an error's own: "Name:
|
|
192
192
|
* message" from the target. With Error.prepareStackTrace set (depd does it), that function makes
|
|
193
193
|
* the value from the target and the call sites, which are Error.stackTraceLimit placeholders (up
|
|
194
194
|
* to 10) that know no file, line or function. */
|
package/runtime/src/events.c
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* Event, EventTarget, AbortController and AbortSignal (DOM §2, §3.1), the events component
|
|
2
|
-
*
|
|
1
|
+
/* Event, EventTarget, AbortController and AbortSignal (DOM §2, §3.1), the events component,
|
|
2
|
+
* as Node has them: a target has no tree, so dispatch runs the target's
|
|
3
3
|
* own listeners for the type, in the order added, walking the list as Node walks its linked
|
|
4
4
|
* list (a listener removed meanwhile doesn't run). A listener's exception doesn't stop
|
|
5
5
|
* the dispatch: it is rethrown from a microtask, as Node rethrows it from process.nextTick,
|
|
@@ -317,7 +317,7 @@ static JSValue add_listener(JSContext *ctx, EventTargetObject *t, JSValue type,
|
|
|
317
317
|
t->listeners = list;
|
|
318
318
|
t->cap = cap;
|
|
319
319
|
}
|
|
320
|
-
t->listeners[t->n++]
|
|
320
|
+
js_store(ctx, &t->obj.cell, &t->listeners[t->n++], js_object_value(&l->obj));
|
|
321
321
|
return js_object_value(&l->obj);
|
|
322
322
|
}
|
|
323
323
|
|
|
@@ -617,19 +617,28 @@ BUILTIN(signal_timeout) {
|
|
|
617
617
|
/* AbortSignal.any(signals): aborted when any of them is */
|
|
618
618
|
BUILTIN(signal_any) {
|
|
619
619
|
UNUSED_ARGS;
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
620
|
+
/* WebIDL's sequence<AbortSignal>, as Node converts it: an iterable object, each value a signal */
|
|
621
|
+
JSValue iterable = ARG(0);
|
|
622
|
+
JSValue method = js_is_object(iterable) ? js_get_value(ctx, iterable, JS_SYMBOL(iterator)) : JS_UNDEFINED;
|
|
623
|
+
if (js_is_exception(method)) return method;
|
|
624
|
+
if (!js_is_callable(method))
|
|
625
|
+
return js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE", "signals cannot be converted to sequence.");
|
|
626
|
+
JSValue list = js_new_array(ctx, 4);
|
|
627
|
+
JSValue rec = js_iter_start(ctx, iterable);
|
|
628
|
+
if (js_is_exception(rec)) return rec;
|
|
629
|
+
for (uint32_t i = 0;; i++) {
|
|
630
|
+
JSValue v = js_iter_next(ctx, rec);
|
|
631
|
+
if (js_is_exception(v)) return v;
|
|
632
|
+
if (js_is_empty(v)) break;
|
|
633
|
+
if (!as_signal(v)) {
|
|
634
|
+
JSValue err = js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE", "signals[%u] is not of type AbortSignal.", i);
|
|
635
|
+
js_iter_close_throw(ctx, rec);
|
|
636
|
+
return err;
|
|
631
637
|
}
|
|
638
|
+
if (js_array_append(ctx, list, v) < 0) return JS_EXCEPTION;
|
|
632
639
|
}
|
|
640
|
+
JSValueArray *signals = js_list_from_array_like(ctx, list);
|
|
641
|
+
if (!signals) return JS_EXCEPTION;
|
|
633
642
|
JSValue result = new_signal(ctx);
|
|
634
643
|
for (uint32_t i = 0; i < signals->cell.aux; i++) {
|
|
635
644
|
AbortSignalObject *s = as_signal(signals->values[i]);
|
package/runtime/src/exception.c
CHANGED
package/runtime/src/fetch.c
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/* Request and Response (Fetch §5.4, §5.5), the fetch component
|
|
1
|
+
/* Request and Response (Fetch §5.4, §5.5), the fetch component, as Node's
|
|
2
2
|
* (undici's): their headers (the headers component), their bodies (the Body mixin, §5.3) and
|
|
3
3
|
* Node's errors and inspection. A body made from bytes (a string, a buffer source, a Blob,
|
|
4
4
|
* URLSearchParams) keeps them: text(), json(), arrayBuffer(), bytes() and blob() read them
|
|
5
5
|
* directly, and `body` makes a ReadableStream of them only when asked. A ReadableStream body is
|
|
6
|
-
* read through the streams component. fetch() itself
|
|
6
|
+
* read through the streams component. fetch() itself is node:http's client\n * (node/prelude/internal/fetch.js), through the js_host_fetch_* primitives at the end. */
|
|
7
7
|
#include <math.h>
|
|
8
8
|
#include <stdio.h>
|
|
9
9
|
#include <stdlib.h>
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
#include "js_atoms.h"
|
|
15
15
|
#include "js_buffer.h"
|
|
16
16
|
#include "js_convert.h"
|
|
17
|
+
#include "js_generator.h"
|
|
17
18
|
#include "js_exception.h"
|
|
19
|
+
#include "js_host.h"
|
|
18
20
|
#include "js_ops.h"
|
|
19
21
|
#include "js_promise.h"
|
|
22
|
+
#include "js_symbol.h"
|
|
20
23
|
#include "js_web.h"
|
|
21
24
|
#include "jscontext.h"
|
|
22
25
|
#include "jsstring.h"
|
|
@@ -27,6 +30,33 @@ static int fail(JSValue thrown) {
|
|
|
27
30
|
return -1;
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
/* undici's TypeError for a URL that doesn't parse: "Failed to parse URL from …", its cause
|
|
34
|
+
* new URL's error (ERR_INVALID_URL). */
|
|
35
|
+
static JSValue throw_unparsable(JSContext *ctx, JSValue input) {
|
|
36
|
+
JSValue cause = js_new_error(ctx, JS_TYPE_ERROR, js_new_string_cstr(ctx, "Invalid URL"));
|
|
37
|
+
js_define_data(ctx, js_as_object(cause), js_atom_from_cstr(ctx, "code"), js_new_string_cstr(ctx, "ERR_INVALID_URL"), JS_PROP_DEFAULT);
|
|
38
|
+
js_define_data(ctx, js_as_object(cause), js_atom_from_cstr(ctx, "input"), input, JS_PROP_DEFAULT);
|
|
39
|
+
JSValue message = js_concat(ctx, js_new_string_cstr(ctx, "Failed to parse URL from "), input);
|
|
40
|
+
if (js_is_exception(message)) return message;
|
|
41
|
+
JSValue e = js_new_error(ctx, JS_TYPE_ERROR, message);
|
|
42
|
+
js_define_data(ctx, js_as_object(e), JS_ATOM(cause), cause, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
|
|
43
|
+
return js_throw(ctx, e);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* Whether a serialized URL has a username or password: an '@' in its authority. */
|
|
47
|
+
static bool has_credentials(JSContext *ctx, JSValue href) {
|
|
48
|
+
JSStrView v = js_string_view(ctx, href);
|
|
49
|
+
uint32_t i = 0;
|
|
50
|
+
while (i < v.length && js_view_at(v, i) != ':') i++;
|
|
51
|
+
if (i + 2 >= v.length || js_view_at(v, i + 1) != '/' || js_view_at(v, i + 2) != '/') return false;
|
|
52
|
+
for (i += 3; i < v.length; i++) {
|
|
53
|
+
uint32_t c = js_view_at(v, i);
|
|
54
|
+
if (c == '@') return true;
|
|
55
|
+
if (c == '/' || c == '?' || c == '#') return false;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
30
60
|
/* ---- Bodies (§5.3) -------------------------------------------------------------------------- */
|
|
31
61
|
|
|
32
62
|
typedef struct Body {
|
|
@@ -104,6 +134,70 @@ static bool class_named(JSValue v, const char *name) {
|
|
|
104
134
|
return js_is_object(v) && strcmp(js_as_object(v)->shape->cls->name, name) == 0;
|
|
105
135
|
}
|
|
106
136
|
|
|
137
|
+
/* FormData (node/prelude/internal/form_data.js, linked into programs that name it) registers
|
|
138
|
+
* its body's serializer and formData()'s parser here (fetchFormDataHooks); until then a FormData
|
|
139
|
+
* is an ordinary object to a body, and formData() rejects. */
|
|
140
|
+
static JSValue form_data_serialize, form_data_parse; /* EMPTY (zero) until set: not callable */
|
|
141
|
+
|
|
142
|
+
/* An async iterable body, as undici (Node's fetch) takes one: a Node Readable (what Next.js passes,
|
|
143
|
+
* a request's body), an async generator. Its stream pulls each chunk from the iterator: bytes (a
|
|
144
|
+
* buffer source, copied) or a string (as UTF-8). The source's data is the iterator record; the
|
|
145
|
+
* closures' is [controller, record]. */
|
|
146
|
+
static JSValue chunk_bytes(JSContext *ctx, JSValue v) {
|
|
147
|
+
uint8_t *p;
|
|
148
|
+
size_t n;
|
|
149
|
+
if (js_buffer_source_bytes(v, &p, &n)) return u8_of(ctx, p, n);
|
|
150
|
+
if (!js_is_string(v)) return js_throw_type_error(ctx, "Received non-Uint8Array chunk");
|
|
151
|
+
JSStrView view = js_string_view(ctx, v);
|
|
152
|
+
size_t len = js_view_to_utf8(view, NULL, 0);
|
|
153
|
+
JSValue bytes = js_new_uint8_array(ctx, len);
|
|
154
|
+
if (js_is_exception(bytes)) return JS_EXCEPTION;
|
|
155
|
+
js_buffer_source_bytes(bytes, &p, &n);
|
|
156
|
+
js_view_to_utf8(view, (char *)p, len);
|
|
157
|
+
return bytes;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
BUILTIN(iterable_next) {
|
|
161
|
+
(void)this_val, (void)new_target, (void)argc;
|
|
162
|
+
JSValue data = js_closure_data(callee);
|
|
163
|
+
JSValue controller = js_get_elem(ctx, data, js_int32(0)), rec = js_get_elem(ctx, data, js_int32(1));
|
|
164
|
+
JSValue value = js_async_iter_value(ctx, rec, ARG(0)); /* EMPTY when done */
|
|
165
|
+
if (!js_is_exception(value) && js_is_empty(value)) return js_readable_stream_close(ctx, controller) < 0 ? JS_EXCEPTION : JS_UNDEFINED;
|
|
166
|
+
JSValue bytes = js_is_exception(value) ? JS_EXCEPTION : chunk_bytes(ctx, value);
|
|
167
|
+
if (js_is_exception(bytes) || js_readable_stream_enqueue(ctx, controller, bytes) < 0) {
|
|
168
|
+
js_readable_stream_error(ctx, controller, js_take_exception(ctx));
|
|
169
|
+
}
|
|
170
|
+
return JS_UNDEFINED;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
BUILTIN(iterable_failed) {
|
|
174
|
+
(void)this_val, (void)new_target, (void)argc;
|
|
175
|
+
js_readable_stream_error(ctx, js_get_elem(ctx, js_closure_data(callee), js_int32(0)), ARG(0));
|
|
176
|
+
return JS_UNDEFINED;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static JSValue iterable_pull(JSContext *ctx, JSValue controller, JSValue rec) {
|
|
180
|
+
JSValue result = js_async_iter_next(ctx, rec);
|
|
181
|
+
if (js_is_exception(result)) return JS_EXCEPTION;
|
|
182
|
+
JSValue settled_result = js_promise_resolve(ctx, result);
|
|
183
|
+
if (js_is_exception(settled_result)) return JS_EXCEPTION;
|
|
184
|
+
JSValue items[2] = { controller, rec };
|
|
185
|
+
JSValue data = js_new_array_from(ctx, items, 2);
|
|
186
|
+
if (js_is_exception(data)) return JS_EXCEPTION;
|
|
187
|
+
JSValue derived = js_new_promise(ctx);
|
|
188
|
+
js_promise_then_internal(ctx, settled_result, js_new_closure_native(ctx, iterable_next, 1, data),
|
|
189
|
+
js_new_closure_native(ctx, iterable_failed, 1, data), derived);
|
|
190
|
+
return derived;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
static JSValue iterable_cancel(JSContext *ctx, JSValue rec, JSValue reason) {
|
|
194
|
+
(void)reason;
|
|
195
|
+
JSValue r = js_async_iter_return(ctx, rec);
|
|
196
|
+
return js_is_empty(r) ? JS_UNDEFINED : r;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
static const JSStreamSource ITERABLE_SOURCE = { iterable_pull, iterable_cancel };
|
|
200
|
+
|
|
107
201
|
/* Extract a body (§5.3 "extract"): its bytes or stream, and the Content-Type it implies (EMPTY
|
|
108
202
|
* for none). 0, or -1. */
|
|
109
203
|
static int extract(JSContext *ctx, JSCell *owner, Body *b, JSValue init, JSValue *content_type) {
|
|
@@ -128,6 +222,38 @@ static int extract(JSContext *ctx, JSCell *owner, Body *b, JSValue init, JSValue
|
|
|
128
222
|
} else if (js_buffer_source_bytes(init, &p, &n)) {
|
|
129
223
|
bytes = u8_of(ctx, p, n);
|
|
130
224
|
} else {
|
|
225
|
+
if (js_is_object(init) && js_is_callable(form_data_serialize)) {
|
|
226
|
+
/* a FormData: [the multipart body as a Blob, its Content-Type], else undefined */
|
|
227
|
+
JSValue parts = js_call(ctx, form_data_serialize, JS_UNDEFINED, 1, &init);
|
|
228
|
+
if (js_is_exception(parts)) return -1;
|
|
229
|
+
if (js_is_array(parts)) {
|
|
230
|
+
JSValue blob = js_get_index(ctx, parts, js_int32(0)), type = js_get_index(ctx, parts, js_int32(1));
|
|
231
|
+
if (js_is_exception(blob) || js_is_exception(type)) return -1;
|
|
232
|
+
if (js_is_blob(blob)) {
|
|
233
|
+
const uint8_t *data;
|
|
234
|
+
size_t size;
|
|
235
|
+
JSValue blob_type;
|
|
236
|
+
js_blob_bytes(blob, &data, &size, &blob_type);
|
|
237
|
+
bytes = u8_of(ctx, data, size);
|
|
238
|
+
if (js_is_exception(bytes)) return -1;
|
|
239
|
+
js_store(ctx, owner, &b->bytes, bytes);
|
|
240
|
+
*content_type = type;
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (js_is_object(init)) {
|
|
246
|
+
JSValue method = js_get_value(ctx, init, JS_SYMBOL(asyncIterator));
|
|
247
|
+
if (js_is_exception(method)) return -1;
|
|
248
|
+
if (js_is_callable(method)) {
|
|
249
|
+
JSValue rec = js_async_iter_start(ctx, init);
|
|
250
|
+
if (js_is_exception(rec)) return -1;
|
|
251
|
+
JSValue stream = js_new_readable_stream(ctx, &ITERABLE_SOURCE, rec, 0);
|
|
252
|
+
if (js_is_exception(stream)) return -1;
|
|
253
|
+
js_store(ctx, owner, &b->stream, stream);
|
|
254
|
+
return 0;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
131
257
|
bool params = class_named(init, "URLSearchParams");
|
|
132
258
|
JSValue s = js_to_string(ctx, init);
|
|
133
259
|
if (js_is_exception(s)) return -1;
|
|
@@ -308,10 +434,11 @@ BUILTIN(request_ctor) {
|
|
|
308
434
|
if (js_is_exception(s)) return s;
|
|
309
435
|
JSValue u = js_parse_url_href(ctx, s);
|
|
310
436
|
if (js_is_exception(u)) return u;
|
|
311
|
-
if (js_is_undefined(u))
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
437
|
+
if (js_is_undefined(u)) return throw_unparsable(ctx, s);
|
|
438
|
+
if (has_credentials(ctx, u)) {
|
|
439
|
+
JSValue message = js_concat(ctx, js_new_string_cstr(ctx, "Request cannot be constructed from a URL that includes credentials: "), u);
|
|
440
|
+
if (js_is_exception(message)) return message;
|
|
441
|
+
return js_throw(ctx, js_new_error(ctx, JS_TYPE_ERROR, message));
|
|
315
442
|
}
|
|
316
443
|
url = u;
|
|
317
444
|
}
|
|
@@ -378,6 +505,8 @@ BUILTIN(request_ctor) {
|
|
|
378
505
|
} else if (src && src->body.has_body) { /* the input request's body moves to this one */
|
|
379
506
|
if (body_used(&src->body)) return js_throw_type_error(ctx, "Cannot construct a Request with a Request object that has already been used.");
|
|
380
507
|
r->body = src->body;
|
|
508
|
+
js_write_barrier(ctx, &r->obj.cell, &r->body.bytes, r->body.bytes);
|
|
509
|
+
js_write_barrier(ctx, &r->obj.cell, &r->body.stream, r->body.stream);
|
|
381
510
|
init_body(&src->body);
|
|
382
511
|
src->body.used = 1;
|
|
383
512
|
src->body.has_body = 1;
|
|
@@ -456,11 +585,29 @@ CONSUMER(request_array_buffer, request_consume, AS_ARRAY_BUFFER)
|
|
|
456
585
|
CONSUMER(request_bytes, request_consume, AS_BYTES)
|
|
457
586
|
CONSUMER(request_blob, request_consume, AS_BLOB)
|
|
458
587
|
|
|
459
|
-
|
|
588
|
+
/* formData(): the body's bytes, parsed by FormData's module as the Content-Type says */
|
|
589
|
+
static JSValue form_data(JSContext *ctx, JSCell *owner, Body *b, JSValue headers) {
|
|
590
|
+
if (!js_is_callable(form_data_parse)) {
|
|
591
|
+
JSValue e = js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_VISALJS_UNSUPPORTED", "formData() (named only at run time)");
|
|
592
|
+
(void)e;
|
|
593
|
+
return rejected(ctx, js_take_exception(ctx));
|
|
594
|
+
}
|
|
595
|
+
JSValue type = js_headers_get(ctx, headers, "content-type");
|
|
596
|
+
if (js_is_exception(type)) return rejected(ctx, js_take_exception(ctx));
|
|
597
|
+
JSValue args[2] = { consume(ctx, owner, b, headers, AS_BYTES), type };
|
|
598
|
+
JSValue parsed = js_call(ctx, form_data_parse, JS_UNDEFINED, 2, args);
|
|
599
|
+
return js_is_exception(parsed) ? rejected(ctx, js_take_exception(ctx)) : parsed;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
BUILTIN(request_form_data) {
|
|
460
603
|
UNUSED_ARGS;
|
|
461
|
-
|
|
462
|
-
(
|
|
463
|
-
|
|
604
|
+
RequestObject *r = as_request(this_val);
|
|
605
|
+
if (!r) {
|
|
606
|
+
JSValue e = js_throw_invalid_this(ctx, "Request");
|
|
607
|
+
(void)e;
|
|
608
|
+
return rejected(ctx, js_take_exception(ctx));
|
|
609
|
+
}
|
|
610
|
+
return form_data(ctx, &r->obj.cell, &r->body, r->headers);
|
|
464
611
|
}
|
|
465
612
|
|
|
466
613
|
static void field(JSContext *ctx, JSValue o, const char *name, JSValue v) {
|
|
@@ -606,11 +753,7 @@ BUILTIN(response_redirect) {
|
|
|
606
753
|
if (js_is_exception(s)) return s;
|
|
607
754
|
JSValue url = js_parse_url_href(ctx, s);
|
|
608
755
|
if (js_is_exception(url)) return url;
|
|
609
|
-
if (js_is_undefined(url))
|
|
610
|
-
char text[256];
|
|
611
|
-
text[js_view_to_utf8(js_string_view(ctx, s), text, sizeof text - 1)] = '\0';
|
|
612
|
-
return js_throw_type_error(ctx, "Failed to parse URL from %s", text);
|
|
613
|
-
}
|
|
756
|
+
if (js_is_undefined(url)) return throw_unparsable(ctx, s);
|
|
614
757
|
double status = 302;
|
|
615
758
|
if (!js_is_undefined(ARG(1)) && js_to_number(ctx, &status, ARG(1)) < 0) return JS_EXCEPTION;
|
|
616
759
|
if (status != 301 && status != 302 && status != 303 && status != 307 && status != 308)
|
|
@@ -674,6 +817,16 @@ static JSValue response_consume(JSContext *ctx, JSValue this_val, int kind) {
|
|
|
674
817
|
return consume(ctx, &r->obj.cell, &r->body, r->headers, kind);
|
|
675
818
|
}
|
|
676
819
|
|
|
820
|
+
BUILTIN(response_form_data) {
|
|
821
|
+
UNUSED_ARGS;
|
|
822
|
+
ResponseObject *r = as_response(this_val);
|
|
823
|
+
if (!r) {
|
|
824
|
+
JSValue e = js_throw_invalid_this(ctx, "Response");
|
|
825
|
+
(void)e;
|
|
826
|
+
return rejected(ctx, js_take_exception(ctx));
|
|
827
|
+
}
|
|
828
|
+
return form_data(ctx, &r->obj.cell, &r->body, r->headers);
|
|
829
|
+
}
|
|
677
830
|
CONSUMER(response_text, response_consume, AS_TEXT)
|
|
678
831
|
CONSUMER(response_json, response_consume, AS_JSON)
|
|
679
832
|
CONSUMER(response_array_buffer, response_consume, AS_ARRAY_BUFFER)
|
|
@@ -724,7 +877,7 @@ static const JSBuiltin request_proto[] = {
|
|
|
724
877
|
WEBIDL_OPERATION("arrayBuffer", request_array_buffer, 0),
|
|
725
878
|
WEBIDL_OPERATION("text", request_text, 0),
|
|
726
879
|
WEBIDL_OPERATION("json", request_json, 0),
|
|
727
|
-
WEBIDL_OPERATION("formData",
|
|
880
|
+
WEBIDL_OPERATION("formData", request_form_data, 0),
|
|
728
881
|
WEBIDL_OPERATION("bytes", request_bytes, 0),
|
|
729
882
|
};
|
|
730
883
|
|
|
@@ -749,10 +902,81 @@ static const JSBuiltin response_proto[] = {
|
|
|
749
902
|
WEBIDL_OPERATION("arrayBuffer", response_array_buffer, 0),
|
|
750
903
|
WEBIDL_OPERATION("text", response_text, 0),
|
|
751
904
|
WEBIDL_OPERATION("json", response_json, 0),
|
|
752
|
-
WEBIDL_OPERATION("formData",
|
|
905
|
+
WEBIDL_OPERATION("formData", response_form_data, 0),
|
|
753
906
|
WEBIDL_OPERATION("bytes", response_bytes, 0),
|
|
754
907
|
};
|
|
755
908
|
|
|
909
|
+
/* ---- fetch() (node/prelude/internal/fetch.js) ---------------------------------------------- */
|
|
910
|
+
|
|
911
|
+
/* fetchHeaderList(headers): a Headers' entries as sent, [name, value, …] in the order they were
|
|
912
|
+
* added, with the names' case kept. */
|
|
913
|
+
JSValue js_host_fetch_header_list(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
|
|
914
|
+
UNUSED_ARGS;
|
|
915
|
+
JSValue headers = ARG(0);
|
|
916
|
+
if (!js_is_headers(headers)) return js_throw_type_error(ctx, "fetchHeaderList: not a Headers");
|
|
917
|
+
uint32_t n = js_headers_count(headers);
|
|
918
|
+
JSValue list = js_new_array(ctx, n * 2);
|
|
919
|
+
if (js_is_exception(list)) return list;
|
|
920
|
+
for (uint32_t i = 0; i < n; i++) {
|
|
921
|
+
JSValue lower, name, value;
|
|
922
|
+
js_headers_at(headers, i, &lower, &name, &value);
|
|
923
|
+
if (js_array_append(ctx, list, name) < 0 || js_array_append(ctx, list, value) < 0) return JS_EXCEPTION;
|
|
924
|
+
}
|
|
925
|
+
return list;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/* fetchRequestBody(request): the body a fetch sends, taken from the request (it is then used):
|
|
929
|
+
* its bytes (a Uint8Array, sent with a Content-Length), its ReadableStream (sent chunked), or
|
|
930
|
+
* null. */
|
|
931
|
+
JSValue js_host_fetch_request_body(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
|
|
932
|
+
UNUSED_ARGS;
|
|
933
|
+
RequestObject *r = as_request(ARG(0));
|
|
934
|
+
if (!r) return js_throw_invalid_this(ctx, "Request");
|
|
935
|
+
Body *b = &r->body;
|
|
936
|
+
if (!b->has_body) return JS_NULL;
|
|
937
|
+
if (body_used(b)) return js_throw_type_error(ctx, "Body is unusable: Body has already been read");
|
|
938
|
+
if (!js_is_undefined(b->stream)) return b->stream;
|
|
939
|
+
b->used = 1;
|
|
940
|
+
return js_is_undefined(b->bytes) ? js_new_uint8_array(ctx, 0) : b->bytes;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
/* fetchResponse(status, statusText, headers, body, url, redirected): a fetched response, its
|
|
944
|
+
* headers (a Headers) made immutable and its body a ReadableStream or null. */
|
|
945
|
+
JSValue js_host_fetch_response(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
|
|
946
|
+
UNUSED_ARGS;
|
|
947
|
+
double status;
|
|
948
|
+
if (js_to_number(ctx, &status, ARG(0)) < 0) return JS_EXCEPTION;
|
|
949
|
+
if (!js_is_headers(ARG(2))) return js_throw_type_error(ctx, "fetchResponse: not a Headers");
|
|
950
|
+
ResponseObject *r = alloc_response(ctx, ctx->intrinsics[JS_INTRINSIC_RESPONSE_PROTOTYPE]);
|
|
951
|
+
JSValue rv = js_object_value(&r->obj);
|
|
952
|
+
r->status = (uint16_t)status;
|
|
953
|
+
r->type = 2;
|
|
954
|
+
r->redirected = js_truthy(ARG(5));
|
|
955
|
+
if (js_is_string(ARG(1))) js_store(ctx, &r->obj.cell, &r->status_text, ARG(1));
|
|
956
|
+
js_headers_set_guard(ARG(2), JS_HEADERS_IMMUTABLE);
|
|
957
|
+
js_store(ctx, &r->obj.cell, &r->headers, ARG(2));
|
|
958
|
+
if (js_is_string(ARG(4))) js_store(ctx, &r->obj.cell, &r->url, ARG(4));
|
|
959
|
+
if (js_is_readable_stream(ARG(3))) {
|
|
960
|
+
r->body.has_body = 1;
|
|
961
|
+
js_store(ctx, &r->obj.cell, &r->body.stream, ARG(3));
|
|
962
|
+
}
|
|
963
|
+
return rv;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/* fetchFormDataHooks(serialize, parse): FormData's module's body serializer and formData() parser */
|
|
967
|
+
JSValue js_host_fetch_form_data_hooks(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
|
|
968
|
+
UNUSED_ARGS;
|
|
969
|
+
static bool rooted;
|
|
970
|
+
if (!rooted) {
|
|
971
|
+
js_add_root(ctx->rt, &form_data_serialize);
|
|
972
|
+
js_add_root(ctx->rt, &form_data_parse);
|
|
973
|
+
rooted = true;
|
|
974
|
+
}
|
|
975
|
+
form_data_serialize = ARG(0);
|
|
976
|
+
form_data_parse = ARG(1);
|
|
977
|
+
return JS_UNDEFINED;
|
|
978
|
+
}
|
|
979
|
+
|
|
756
980
|
static void install_fetch(JSContext *ctx, JSObject *global) {
|
|
757
981
|
JSValue object_proto = ctx->intrinsics[JS_INTRINSIC_OBJECT_PROTOTYPE];
|
|
758
982
|
js_define_web_class(ctx, global, "Request", request_ctor, 1, object_proto, JS_INTRINSIC_REQUEST_PROTOTYPE);
|
package/runtime/src/function.c
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Function objects and calls (
|
|
1
|
+
/* Function objects and calls (ECMAScript §10.2, §10.3). */
|
|
2
2
|
#include "js_function.h"
|
|
3
3
|
|
|
4
4
|
#include <math.h>
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
#include "js_ops.h"
|
|
13
13
|
#include "jscontext.h"
|
|
14
14
|
|
|
15
|
-
/* cell
|
|
16
|
-
#define PROTOTYPE_PENDING
|
|
15
|
+
/* cell flags (kind-specific): `prototype` hasn't been created yet (lazily, on first observation) */
|
|
16
|
+
#define PROTOTYPE_PENDING 0x01u
|
|
17
17
|
|
|
18
18
|
/* ---- The class: lazy `prototype`, GC fields ------------------------------- */
|
|
19
19
|
|
|
20
20
|
/* Creates F.prototype = { constructor: F } if it's still pending. */
|
|
21
21
|
static void materialize_prototype(JSContext *ctx, JSObject *f) {
|
|
22
|
-
if (!(f->cell.
|
|
23
|
-
f->cell.
|
|
22
|
+
if (!(f->cell.flags & PROTOTYPE_PENDING)) return;
|
|
23
|
+
f->cell.flags &= (uint16_t)~PROTOTYPE_PENDING;
|
|
24
24
|
JSValue proto = js_new_object(ctx);
|
|
25
25
|
js_define_data(ctx, js_as_object(proto), JS_ATOM(constructor), js_object_value(f), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
|
|
26
26
|
js_define_data(ctx, f, JS_ATOM(prototype), proto, JS_PROP_WRITABLE);
|
|
@@ -59,6 +59,7 @@ static void fn_visit(JSCell *c, JSTracer *trc) {
|
|
|
59
59
|
js_trace_value(trc, f->home_object);
|
|
60
60
|
js_trace_value(trc, f->bound_this);
|
|
61
61
|
if (f->env) js_trace_cell(trc, &f->env->cell);
|
|
62
|
+
if (f->instance_shape) js_trace_cell(trc, &f->instance_shape->cell);
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
const JSClass js_class_function = {
|
|
@@ -98,7 +99,7 @@ JSValue js_new_function(JSContext *ctx, const JSFunctionInfo *info) {
|
|
|
98
99
|
JSFunction *f = alloc_function(ctx, info->generic, info->flags, name, info->length);
|
|
99
100
|
f->info = info;
|
|
100
101
|
if ((info->flags & (JS_FN_CONSTRUCTOR | JS_FN_ORDINARY)) == (JS_FN_CONSTRUCTOR | JS_FN_ORDINARY))
|
|
101
|
-
f->obj.cell.
|
|
102
|
+
f->obj.cell.flags |= PROTOTYPE_PENDING;
|
|
102
103
|
if (info->flags & JS_FN_GENERATOR) {
|
|
103
104
|
/* its own prototype: what its generators inherit from; no `constructor` (§15.5.4) */
|
|
104
105
|
JSIntrinsic gp = info->flags & JS_FN_ASYNC ? JS_INTRINSIC_ASYNC_GENERATOR_PROTOTYPE : JS_INTRINSIC_GENERATOR_PROTOTYPE;
|
|
@@ -110,23 +111,19 @@ JSValue js_new_function(JSContext *ctx, const JSFunctionInfo *info) {
|
|
|
110
111
|
|
|
111
112
|
JSValue js_new_closure(JSContext *ctx, const JSFunctionInfo *info, JSValue env) {
|
|
112
113
|
JSValue f = js_new_function(ctx, info);
|
|
113
|
-
|
|
114
|
+
/* not an initializing store: a generator function allocates its prototype after the cell */
|
|
115
|
+
js_store_ptr(ctx, &js_as_function(f)->obj.cell, &js_as_function(f)->env, js_as_env(env));
|
|
114
116
|
return f;
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
/* ---- Environments ---------------------------------------------------------------- */
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
JSEnv *e = (JSEnv *)c;
|
|
121
|
-
if (e->parent) js_trace_cell(trc, &e->parent->cell);
|
|
122
|
-
for (uint32_t i = 0; i < c->aux; i++) js_trace_value(trc, e->vars[i]);
|
|
123
|
-
}
|
|
124
|
-
const JSCellClass js_env_cell_class = { "Env", env_visit, NULL };
|
|
121
|
+
const JSCellClass js_env_cell_class = { "Env", NULL, NULL, NULL }; /* gc_visit.h visits it */
|
|
125
122
|
|
|
126
123
|
JSValue js_new_env(JSContext *ctx, JSValue parent, uint32_t count) {
|
|
127
124
|
JSEnv *e = (JSEnv *)js_alloc_cell(ctx, JS_CELL_ENV, sizeof(JSEnv) + (size_t)count * sizeof(JSValue));
|
|
128
125
|
e->cell.aux = count;
|
|
129
|
-
e->parent = js_as_env(parent);
|
|
126
|
+
e->parent = js_as_env(parent); /* barrier: fresh cell */
|
|
130
127
|
return js_cell(&e->cell);
|
|
131
128
|
}
|
|
132
129
|
|
|
@@ -231,6 +228,21 @@ JSValue js_create_from_constructor(JSContext *ctx, JSValue new_target, JSIntrins
|
|
|
231
228
|
return js_new_object_proto(ctx, proto, JS_DEFAULT_INLINE_SLOTS);
|
|
232
229
|
}
|
|
233
230
|
|
|
231
|
+
JSValue js_new_instance(JSContext *ctx, JSValue fv, uint16_t slots, JSPropCache *ic) {
|
|
232
|
+
JSObject *fo = js_as_object(fv);
|
|
233
|
+
JSValue proto = fo->shape == ic->shape && ic->kind == JS_IC_OWN ? *js_object_slot(fo, ic->slot) /* out of line, often */
|
|
234
|
+
: js_get_prop(ctx, fv, JS_ATOM(prototype), ic);
|
|
235
|
+
if (js_is_exception(proto)) return JS_EXCEPTION;
|
|
236
|
+
if (!js_is_object(proto)) proto = ctx->intrinsics[JS_INTRINSIC_OBJECT_PROTOTYPE]; /* OrdinaryCreateFromConstructor's fallback */
|
|
237
|
+
JSFunction *f = js_as_function(fv);
|
|
238
|
+
JSShape *s = f->instance_shape;
|
|
239
|
+
if (JS_UNLIKELY(!s || !js_same_bits(s->proto, proto) || s->inline_cap != slots)) {
|
|
240
|
+
s = js_shape_root(ctx, &js_class_object, proto, slots);
|
|
241
|
+
js_store_ptr(ctx, &f->obj.cell, &f->instance_shape, s);
|
|
242
|
+
}
|
|
243
|
+
return js_object_value(js_alloc_object(ctx, JS_CELL_OBJECT, s));
|
|
244
|
+
}
|
|
245
|
+
|
|
234
246
|
JSValue js_construct(JSContext *ctx, JSValue f, uint32_t argc, const JSValue *argv, JSValue new_target, const char *callee_text) {
|
|
235
247
|
if (JS_UNLIKELY(!js_is_constructor(f))) return not_callable(ctx, f, callee_text, "constructor");
|
|
236
248
|
JSFunction *fn = js_as_function(f);
|
|
@@ -279,7 +291,7 @@ JSValue js_class_setup(JSContext *ctx, JSValue ctor, JSValue heritage) {
|
|
|
279
291
|
}
|
|
280
292
|
JSValue proto = js_new_object_proto(ctx, proto_parent, JS_DEFAULT_INLINE_SLOTS);
|
|
281
293
|
JSObject *f = js_as_object(ctor);
|
|
282
|
-
f->cell.
|
|
294
|
+
f->cell.flags &= (uint16_t)~PROTOTYPE_PENDING; /* set here, not lazily */
|
|
283
295
|
if (!js_same_bits(ctor_parent, ctx->intrinsics[JS_INTRINSIC_FUNCTION_PROTOTYPE])) {
|
|
284
296
|
int r = js_set_prototype_of(ctx, f, ctor_parent); /* a fresh function: can't fail */
|
|
285
297
|
(void)r;
|
|
@@ -378,8 +390,8 @@ static JSValue bound_entry(JSContext *ctx, JSValue callee, JSValue this_val, uin
|
|
|
378
390
|
JSValue target = b->home_object;
|
|
379
391
|
uint32_t nbound = b->env ? b->env->cell.aux : 0;
|
|
380
392
|
JSValueArray *all = js_alloc_value_array(ctx, nbound + argc); /* GC-visible while the callee runs */
|
|
381
|
-
for (uint32_t i = 0; i < nbound; i++) all->values[i] = b->env->vars[i];
|
|
382
|
-
for (uint32_t i = 0; i < argc; i++) all->values[nbound + i] = argv[i];
|
|
393
|
+
for (uint32_t i = 0; i < nbound; i++) all->values[i] = b->env->vars[i]; /* barrier: fresh cell */
|
|
394
|
+
for (uint32_t i = 0; i < argc; i++) all->values[nbound + i] = argv[i]; /* barrier: fresh cell */
|
|
383
395
|
JSValue held = js_cell(&all->cell);
|
|
384
396
|
JSValue r;
|
|
385
397
|
if (js_is_undefined(new_target)) {
|
|
@@ -433,8 +445,8 @@ JSValue js_bind_function(JSContext *ctx, JSValue target, JSValue bound_this, uin
|
|
|
433
445
|
js_store(ctx, &b->obj.cell, &b->bound_this, bound_this);
|
|
434
446
|
if (argc) {
|
|
435
447
|
JSValue env = js_new_env(ctx, JS_UNDEFINED, argc);
|
|
436
|
-
for (uint32_t i = 0; i < argc; i++) js_as_env(env)->vars[i] = argv[i];
|
|
437
|
-
b->env
|
|
448
|
+
for (uint32_t i = 0; i < argc; i++) js_as_env(env)->vars[i] = argv[i]; /* barrier: fresh cell */
|
|
449
|
+
js_store_ptr(ctx, &b->obj.cell, &b->env, js_as_env(env));
|
|
438
450
|
}
|
|
439
451
|
return f;
|
|
440
452
|
}
|