visaljs 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (434) hide show
  1. package/README.md +68 -4
  2. package/THIRD_PARTY_LICENSES +1216 -0
  3. package/cli.js +4461 -321
  4. package/node/include/js_node.h +57 -1
  5. package/node/include/js_uv.h +8 -1
  6. package/node/prelude/_http_agent.js +5 -0
  7. package/node/prelude/_http_server.js +7 -0
  8. package/node/prelude/_stream_duplex.js +4 -0
  9. package/node/prelude/_stream_passthrough.js +4 -0
  10. package/node/prelude/_stream_readable.js +4 -0
  11. package/node/prelude/_stream_transform.js +4 -0
  12. package/node/prelude/_stream_writable.js +4 -0
  13. package/node/prelude/assert.js +1334 -0
  14. package/node/prelude/assert_strict.js +12 -0
  15. package/node/prelude/async_hooks.js +1 -1
  16. package/node/prelude/buffer.js +43 -3
  17. package/node/prelude/child_process.js +1098 -0
  18. package/node/prelude/cluster.js +52 -0
  19. package/node/prelude/console.js +328 -0
  20. package/node/prelude/constants.js +10 -0
  21. package/node/prelude/crypto.js +1 -1
  22. package/node/prelude/diagnostics_channel.js +1 -1
  23. package/node/prelude/dns.js +8 -2
  24. package/node/prelude/domain.js +115 -0
  25. package/node/prelude/events.js +148 -16
  26. package/node/prelude/fs.js +1138 -151
  27. package/node/prelude/fs_promises.js +117 -11
  28. package/node/prelude/http.js +784 -301
  29. package/node/prelude/http2.js +1 -1
  30. package/node/prelude/https.js +159 -0
  31. package/node/prelude/inspector.js +27 -0
  32. package/node/prelude/inspector_promises.js +4 -0
  33. package/node/prelude/internal/async_context.js +1 -1
  34. package/node/prelude/internal/buffer_transcode.js +44 -0
  35. package/node/prelude/internal/comparisons.js +916 -0
  36. package/node/prelude/internal/compression_streams.js +153 -0
  37. package/node/prelude/internal/crypto/asym.js +27 -14
  38. package/node/prelude/internal/crypto/cipher.js +16 -5
  39. package/node/prelude/internal/crypto/diffiehellman.js +3 -2
  40. package/node/prelude/internal/crypto/hash.js +2 -1
  41. package/node/prelude/internal/crypto/kdf.js +14 -9
  42. package/node/prelude/internal/crypto/keys.js +63 -50
  43. package/node/prelude/internal/crypto/random.js +2 -1
  44. package/node/prelude/internal/crypto/util.js +4 -4
  45. package/node/prelude/internal/dotenv.js +98 -0
  46. package/node/prelude/internal/errors.js +21 -5
  47. package/node/prelude/internal/events_extras.js +113 -0
  48. package/node/prelude/internal/events_on.js +100 -0
  49. package/node/prelude/internal/features.js +72 -0
  50. package/node/prelude/internal/fetch.js +364 -0
  51. package/node/prelude/internal/form_data.js +376 -0
  52. package/node/prelude/internal/fs_bigint_stats.js +41 -0
  53. package/node/prelude/internal/fs_blob.js +19 -0
  54. package/node/prelude/internal/fs_cp.js +709 -0
  55. package/node/prelude/internal/fs_dir.js +166 -0
  56. package/node/prelude/internal/fs_filehandle.js +287 -0
  57. package/node/prelude/internal/fs_glob.js +296 -0
  58. package/node/prelude/internal/fs_statfs.js +42 -0
  59. package/node/prelude/internal/fs_stats.js +89 -0
  60. package/node/prelude/internal/fs_streams.js +541 -0
  61. package/node/prelude/internal/fs_utils.js +286 -0
  62. package/node/prelude/internal/fs_watch.js +580 -0
  63. package/node/prelude/internal/http_agent.js +114 -2
  64. package/node/prelude/internal/http_symbols.js +3 -0
  65. package/node/prelude/internal/mime.js +249 -0
  66. package/node/prelude/internal/net.js +1 -0
  67. package/node/prelude/internal/net_bound.js +123 -0
  68. package/node/prelude/internal/net_onread.js +73 -0
  69. package/node/prelude/internal/net_tos.js +54 -0
  70. package/node/prelude/internal/parse_args.js +288 -0
  71. package/node/prelude/internal/perf_histogram.js +435 -0
  72. package/node/prelude/internal/perf_observe.js +125 -0
  73. package/node/prelude/internal/performance_global.js +19 -0
  74. package/node/prelude/internal/process_events.js +49 -1
  75. package/node/prelude/internal/process_memory.js +14 -0
  76. package/node/prelude/internal/process_more.js +414 -0
  77. package/node/prelude/internal/process_signals.js +2 -1
  78. package/node/prelude/internal/process_stdin.js +52 -0
  79. package/node/prelude/internal/process_stdio.js +36 -0
  80. package/node/prelude/internal/querystring.js +0 -0
  81. package/node/prelude/internal/readline.js +338 -0
  82. package/node/prelude/internal/socketaddress.js +8 -4
  83. package/node/prelude/internal/source_map.js +122 -0
  84. package/node/prelude/internal/stream_compose.js +74 -0
  85. package/node/prelude/internal/stream_from.js +6 -0
  86. package/node/prelude/internal/stream_operators.js +23 -0
  87. package/node/prelude/internal/stream_pipeline.js +7 -0
  88. package/node/prelude/internal/stream_transform.js +10 -0
  89. package/node/prelude/internal/stream_web_adapters.js +143 -0
  90. package/node/prelude/internal/streams/add_abort_signal.js +58 -0
  91. package/node/prelude/internal/streams/compose.js +244 -0
  92. package/node/prelude/internal/streams/destroy.js +358 -0
  93. package/node/prelude/internal/streams/duplex.js +199 -0
  94. package/node/prelude/internal/streams/duplexify.js +378 -0
  95. package/node/prelude/internal/streams/end_of_stream.js +387 -0
  96. package/node/prelude/internal/streams/errors.js +216 -0
  97. package/node/prelude/internal/streams/from.js +211 -0
  98. package/node/prelude/internal/streams/legacy.js +120 -0
  99. package/node/prelude/internal/streams/operators.js +375 -0
  100. package/node/prelude/internal/streams/passthrough.js +45 -0
  101. package/node/prelude/internal/streams/pipeline.js +468 -0
  102. package/node/prelude/internal/streams/readable.js +1835 -0
  103. package/node/prelude/internal/streams/state.js +48 -0
  104. package/node/prelude/internal/streams/transform.js +203 -0
  105. package/node/prelude/internal/streams/utils.js +355 -0
  106. package/node/prelude/internal/streams/validators.js +108 -0
  107. package/node/prelude/internal/streams/writable.js +1160 -0
  108. package/node/prelude/internal/structured_clone.js +238 -0
  109. package/node/prelude/internal/system_errors.js +37 -0
  110. package/node/prelude/internal/test_runner/mock.js +431 -0
  111. package/node/prelude/internal/test_runner/reporters.js +404 -0
  112. package/node/prelude/internal/test_runner/test.js +1571 -0
  113. package/node/prelude/internal/timers.js +38 -7
  114. package/node/prelude/internal/timers_global.js +1 -1
  115. package/node/prelude/internal/tls/common.js +8 -2
  116. package/node/prelude/internal/tls/wrap.js +5 -16
  117. package/node/prelude/internal/tls/x509.js +1 -1
  118. package/node/prelude/internal/tty_read_stream.js +39 -0
  119. package/node/prelude/internal/tty_streams.js +3 -0
  120. package/node/prelude/internal/util_debuglog.js +68 -0
  121. package/node/prelude/internal/util_diff.js +63 -0
  122. package/node/prelude/internal/util_more.js +111 -0
  123. package/node/prelude/internal/util_styles.js +76 -0
  124. package/node/prelude/internal/zlib_engines.js +1 -1
  125. package/node/prelude/module.js +219 -8
  126. package/node/prelude/net.js +197 -49
  127. package/node/prelude/os.js +88 -11
  128. package/node/prelude/path.js +11 -7
  129. package/node/prelude/path_posix.js +1 -1
  130. package/node/prelude/path_win32.js +1 -1
  131. package/node/prelude/perf_hooks.js +151 -0
  132. package/node/prelude/process.js +36 -1
  133. package/node/prelude/punycode.js +188 -0
  134. package/node/prelude/querystring.js +1 -1
  135. package/node/prelude/readline.js +8 -0
  136. package/node/prelude/readline_promises.js +88 -0
  137. package/node/prelude/repl.js +38 -0
  138. package/node/prelude/sea.js +23 -0
  139. package/node/prelude/stream.js +70 -1332
  140. package/node/prelude/stream_consumers.js +34 -0
  141. package/node/prelude/stream_promises.js +1 -1
  142. package/node/prelude/stream_web.js +15 -2
  143. package/node/prelude/string_decoder.js +1 -1
  144. package/node/prelude/sys.js +7 -0
  145. package/node/prelude/test.js +56 -0
  146. package/node/prelude/test_reporters.js +269 -0
  147. package/node/prelude/timers.js +7 -84
  148. package/node/prelude/timers_promises.js +1 -1
  149. package/node/prelude/tls.js +2 -1
  150. package/node/prelude/trace_events.js +52 -0
  151. package/node/prelude/tty.js +10 -4
  152. package/node/prelude/url.js +88 -27
  153. package/node/prelude/util.js +121 -5
  154. package/node/prelude/util_types.js +4 -3
  155. package/node/prelude/v8.js +814 -0
  156. package/node/prelude/vm.js +86 -0
  157. package/node/prelude/wasi.js +10 -0
  158. package/node/prelude/worker_threads.js +56 -0
  159. package/node/prelude/zlib.js +58 -25
  160. package/node/src/host_brotli.c +59 -11
  161. package/node/src/host_fs.c +342 -11
  162. package/node/src/host_fswatch.c +170 -0
  163. package/node/src/host_http.c +292 -39
  164. package/node/src/host_loop.c +25 -2
  165. package/node/src/host_net.c +130 -16
  166. package/node/src/host_os.c +55 -1
  167. package/node/src/host_proc.c +291 -0
  168. package/node/src/host_process.c +488 -0
  169. package/node/src/host_sys.c +64 -2
  170. package/node/src/host_zlib.c +27 -7
  171. package/node/src/host_zstd.c +41 -6
  172. package/node/third_party/hdrhistogram/LICENSE +42 -0
  173. package/node/third_party/hdrhistogram/README.md +5 -0
  174. package/node/third_party/libuv/LICENSE +0 -0
  175. package/node/third_party/libuv/LICENSE-extra +36 -0
  176. package/node/third_party/libuv/include/uv/aix.h +0 -0
  177. package/node/third_party/libuv/include/uv/bsd.h +0 -0
  178. package/node/third_party/libuv/include/uv/darwin.h +0 -0
  179. package/node/third_party/libuv/include/uv/errno.h +0 -0
  180. package/node/third_party/libuv/include/uv/linux.h +0 -0
  181. package/node/third_party/libuv/include/uv/os390.h +0 -0
  182. package/node/third_party/libuv/include/uv/posix.h +0 -0
  183. package/node/third_party/libuv/include/uv/sunos.h +0 -0
  184. package/node/third_party/libuv/include/uv/threadpool.h +0 -0
  185. package/node/third_party/libuv/include/uv/tree.h +0 -0
  186. package/node/third_party/libuv/include/uv/unix.h +0 -0
  187. package/node/third_party/libuv/include/uv/version.h +0 -0
  188. package/node/third_party/libuv/include/uv/win.h +0 -0
  189. package/node/third_party/libuv/include/uv.h +0 -0
  190. package/node/third_party/libuv/src/fs-poll.c +0 -0
  191. package/node/third_party/libuv/src/heap-inl.h +0 -0
  192. package/node/third_party/libuv/src/idna.c +0 -0
  193. package/node/third_party/libuv/src/idna.h +0 -0
  194. package/node/third_party/libuv/src/inet.c +0 -0
  195. package/node/third_party/libuv/src/queue.h +0 -0
  196. package/node/third_party/libuv/src/random.c +0 -0
  197. package/node/third_party/libuv/src/strscpy.c +0 -0
  198. package/node/third_party/libuv/src/strscpy.h +0 -0
  199. package/node/third_party/libuv/src/strtok.c +0 -0
  200. package/node/third_party/libuv/src/strtok.h +0 -0
  201. package/node/third_party/libuv/src/thread-common.c +0 -0
  202. package/node/third_party/libuv/src/threadpool.c +0 -0
  203. package/node/third_party/libuv/src/timer.c +0 -0
  204. package/node/third_party/libuv/src/unix/async.c +0 -0
  205. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
  206. package/node/third_party/libuv/src/unix/core.c +0 -0
  207. package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
  208. package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
  209. package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
  210. package/node/third_party/libuv/src/unix/darwin.c +0 -0
  211. package/node/third_party/libuv/src/unix/dl.c +0 -0
  212. package/node/third_party/libuv/src/unix/fs.c +0 -0
  213. package/node/third_party/libuv/src/unix/fsevents.c +0 -0
  214. package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
  215. package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
  216. package/node/third_party/libuv/src/unix/internal.h +0 -0
  217. package/node/third_party/libuv/src/unix/kqueue.c +0 -0
  218. package/node/third_party/libuv/src/unix/linux.c +0 -0
  219. package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
  220. package/node/third_party/libuv/src/unix/loop.c +0 -0
  221. package/node/third_party/libuv/src/unix/pipe.c +0 -0
  222. package/node/third_party/libuv/src/unix/poll.c +0 -0
  223. package/node/third_party/libuv/src/unix/process.c +0 -0
  224. package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
  225. package/node/third_party/libuv/src/unix/proctitle.c +0 -0
  226. package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
  227. package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
  228. package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
  229. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
  230. package/node/third_party/libuv/src/unix/signal.c +0 -0
  231. package/node/third_party/libuv/src/unix/stream.c +0 -0
  232. package/node/third_party/libuv/src/unix/tcp.c +0 -0
  233. package/node/third_party/libuv/src/unix/thread.c +0 -0
  234. package/node/third_party/libuv/src/unix/tty.c +0 -0
  235. package/node/third_party/libuv/src/unix/udp.c +0 -0
  236. package/node/third_party/libuv/src/uv-common.c +0 -0
  237. package/node/third_party/libuv/src/uv-common.h +0 -0
  238. package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
  239. package/node/third_party/libuv/src/version.c +0 -0
  240. package/node/third_party/llhttp/LICENSE +0 -0
  241. package/node/third_party/llhttp/api.c +0 -0
  242. package/node/third_party/llhttp/http.c +0 -0
  243. package/node/third_party/llhttp/llhttp.c +0 -0
  244. package/node/third_party/llhttp/llhttp.h +0 -0
  245. package/node/third_party/nodejs/LICENSE +47 -0
  246. package/node/third_party/nodejs/README.md +5 -0
  247. package/node/third_party/parseargs/LICENSE +21 -0
  248. package/node/third_party/parseargs/README.md +5 -0
  249. package/node/third_party/punycode/LICENSE +20 -0
  250. package/node/third_party/punycode/README.md +5 -0
  251. package/node/third_party/zlib/LICENSE.chromium +27 -0
  252. package/package.json +1 -1
  253. package/prebuilt/darwin-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
  254. package/prebuilt/darwin-arm64/brotli-7995bbdacc52e51c.a +0 -0
  255. package/prebuilt/darwin-arm64/uv-72ab666eae197cd8.a +0 -0
  256. package/prebuilt/darwin-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
  257. package/prebuilt/darwin-arm64/zstd-015315ac7c784c73.a +0 -0
  258. package/prebuilt/darwin-x64/boringssl-4a47438eaf7e73ba.a +0 -0
  259. package/prebuilt/darwin-x64/brotli-7995bbdacc52e51c.a +0 -0
  260. package/prebuilt/darwin-x64/uv-72ab666eae197cd8.a +0 -0
  261. package/prebuilt/darwin-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  262. package/prebuilt/darwin-x64/zstd-015315ac7c784c73.a +0 -0
  263. package/prebuilt/linux-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
  264. package/prebuilt/linux-arm64/brotli-65481ff838ce9def.a +0 -0
  265. package/prebuilt/linux-arm64/uv-f1353f50ff983f3c.a +0 -0
  266. package/prebuilt/linux-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
  267. package/prebuilt/linux-arm64/zstd-015315ac7c784c73.a +0 -0
  268. package/prebuilt/linux-arm64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
  269. package/prebuilt/linux-arm64-musl/brotli-65481ff838ce9def.a +0 -0
  270. package/prebuilt/linux-arm64-musl/uv-f1353f50ff983f3c.a +0 -0
  271. package/prebuilt/linux-arm64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
  272. package/prebuilt/linux-arm64-musl/zstd-015315ac7c784c73.a +0 -0
  273. package/prebuilt/linux-x64/boringssl-4a47438eaf7e73ba.a +0 -0
  274. package/prebuilt/linux-x64/brotli-65481ff838ce9def.a +0 -0
  275. package/prebuilt/linux-x64/uv-f1353f50ff983f3c.a +0 -0
  276. package/prebuilt/linux-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  277. package/prebuilt/linux-x64/zstd-015315ac7c784c73.a +0 -0
  278. package/prebuilt/linux-x64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
  279. package/prebuilt/linux-x64-musl/brotli-65481ff838ce9def.a +0 -0
  280. package/prebuilt/linux-x64-musl/uv-f1353f50ff983f3c.a +0 -0
  281. package/prebuilt/linux-x64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
  282. package/prebuilt/linux-x64-musl/zstd-015315ac7c784c73.a +0 -0
  283. package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
  284. package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
  285. package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
  286. package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  287. package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
  288. package/runtime/include/js_atoms.gen.h +0 -0
  289. package/runtime/include/js_atoms.h +5 -1
  290. package/runtime/include/js_bigint.h +1 -1
  291. package/runtime/include/js_buffer.h +4 -4
  292. package/runtime/include/js_builtins.h +41 -3
  293. package/runtime/include/js_console.h +9 -4
  294. package/runtime/include/js_convert.h +1 -1
  295. package/runtime/include/js_core.def +5 -4
  296. package/runtime/include/js_crypto.h +1 -1
  297. package/runtime/include/js_error.h +1 -1
  298. package/runtime/include/js_exception.h +21 -1
  299. package/runtime/include/js_function.h +33 -9
  300. package/runtime/include/js_gc.h +172 -30
  301. package/runtime/include/js_generator.h +2 -2
  302. package/runtime/include/js_host.h +19 -1
  303. package/runtime/include/js_jobs.h +5 -5
  304. package/runtime/include/js_module.h +1 -1
  305. package/runtime/include/js_object.h +142 -15
  306. package/runtime/include/js_ops.h +107 -5
  307. package/runtime/include/js_promise.h +3 -3
  308. package/runtime/include/js_regexp.h +1 -1
  309. package/runtime/include/js_runtime.h +0 -0
  310. package/runtime/include/js_symbol.h +1 -1
  311. package/runtime/include/js_web.h +5 -1
  312. package/runtime/include/jscell.h +22 -15
  313. package/runtime/include/jscontext.h +82 -39
  314. package/runtime/include/jsnum.h +1 -1
  315. package/runtime/include/jsstring.h +19 -6
  316. package/runtime/include/jsvalue.h +7 -3
  317. package/runtime/src/arguments.c +2 -2
  318. package/runtime/src/array.c +4 -1
  319. package/runtime/src/arraybuffer.c +19 -7
  320. package/runtime/src/async_iter.c +4 -3
  321. package/runtime/src/atoms.c +38 -4
  322. package/runtime/src/base64.c +2 -2
  323. package/runtime/src/bigint.c +1 -1
  324. package/runtime/src/blob.c +22 -9
  325. package/runtime/src/boringssl_support.cc +1 -1
  326. package/runtime/src/buffer.c +299 -91
  327. package/runtime/src/builtin_table.c +1 -1
  328. package/runtime/src/builtins.c +30 -4
  329. package/runtime/src/builtins_util.h +0 -0
  330. package/runtime/src/collections.c +18 -3
  331. package/runtime/src/components.c +1 -1
  332. package/runtime/src/console.c +14 -7
  333. package/runtime/src/convert.c +0 -0
  334. package/runtime/src/core_all.c +1 -1
  335. package/runtime/src/crypto.c +1 -1
  336. package/runtime/src/crypto_asym.c +1 -1
  337. package/runtime/src/crypto_bn.c +1 -1
  338. package/runtime/src/crypto_cipher.c +10 -3
  339. package/runtime/src/crypto_hash.c +1 -1
  340. package/runtime/src/crypto_host.c +1 -1
  341. package/runtime/src/crypto_internal.h +1 -1
  342. package/runtime/src/crypto_kdf.c +1 -1
  343. package/runtime/src/crypto_key.c +14 -1
  344. package/runtime/src/crypto_pkey.c +1 -1
  345. package/runtime/src/crypto_subtle.c +142 -58
  346. package/runtime/src/crypto_tls.c +1 -1
  347. package/runtime/src/date.c +5 -2
  348. package/runtime/src/domexception.c +2 -2
  349. package/runtime/src/elements.c +56 -17
  350. package/runtime/src/elements.h +7 -2
  351. package/runtime/src/encoding.c +1 -1
  352. package/runtime/src/error.c +4 -4
  353. package/runtime/src/events.c +42 -14
  354. package/runtime/src/exception.c +1 -1
  355. package/runtime/src/fetch.c +241 -17
  356. package/runtime/src/function.c +31 -19
  357. package/runtime/src/gc.c +1720 -211
  358. package/runtime/src/gc_visit.h +87 -0
  359. package/runtime/src/generator.c +5 -3
  360. package/runtime/src/global.c +14 -6
  361. package/runtime/src/headers.c +10 -10
  362. package/runtime/src/inspect.c +76 -17
  363. package/runtime/src/internal.h +9 -6
  364. package/runtime/src/iterate.c +94 -2
  365. package/runtime/src/iterator.c +1 -1
  366. package/runtime/src/jobs.c +11 -5
  367. package/runtime/src/jsnum.c +2 -2
  368. package/runtime/src/json.c +1 -1
  369. package/runtime/src/math.c +9 -1
  370. package/runtime/src/module.c +3 -3
  371. package/runtime/src/number.c +0 -0
  372. package/runtime/src/object.c +107 -74
  373. package/runtime/src/ops.c +21 -3
  374. package/runtime/src/os.c +192 -1
  375. package/runtime/src/os.h +33 -2
  376. package/runtime/src/process.c +73 -8
  377. package/runtime/src/promise.c +4 -4
  378. package/runtime/src/proxy.c +1 -1
  379. package/runtime/src/reflect.c +1 -1
  380. package/runtime/src/regexp.c +700 -11
  381. package/runtime/src/regexp_anchor.h +1 -1
  382. package/runtime/src/regexp_message.h +1 -1
  383. package/runtime/src/shape.c +78 -20
  384. package/runtime/src/shape.h +0 -0
  385. package/runtime/src/streams.c +22 -8
  386. package/runtime/src/streams.h +0 -0
  387. package/runtime/src/string.c +64 -25
  388. package/runtime/src/string_builtins.c +7 -7
  389. package/runtime/src/symbol.c +2 -7
  390. package/runtime/src/test_host.c +3 -3
  391. package/runtime/src/tls_roots.gen.h +102 -620
  392. package/runtime/src/typedarray.c +8 -3
  393. package/runtime/src/tznames.gen.h +2 -1
  394. package/runtime/src/uri.c +1 -1
  395. package/runtime/src/url.c +42 -39
  396. package/runtime/src/weak.c +110 -36
  397. package/runtime/src/web.c +21 -3
  398. package/runtime/src/wrapper.c +0 -0
  399. package/runtime/src/writable.c +7 -6
  400. package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
  401. package/runtime/third_party/ada-idna/README.md +7 -7
  402. package/runtime/third_party/ada-idna/convert.mjs +89 -27
  403. package/runtime/third_party/ada-idna/idna.c +30 -31
  404. package/runtime/third_party/ada-idna/idna.h +0 -0
  405. package/runtime/third_party/ada-idna/idna_tables.h +2272 -1952
  406. package/runtime/third_party/boringssl/third_party/fiat/LICENSE +15 -0
  407. package/runtime/third_party/mozilla-ca/LICENSE +373 -0
  408. package/runtime/third_party/mozilla-ca/README.md +9 -0
  409. package/runtime/third_party/nodejs/LICENSE +47 -0
  410. package/runtime/third_party/nodejs/README.md +7 -0
  411. package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
  412. package/runtime/third_party/quickjs-dtoa/README.md +1 -1
  413. package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
  414. package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
  415. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
  416. package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
  417. package/runtime/third_party/quickjs-regexp/README.md +2 -2
  418. package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
  419. package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
  420. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
  421. package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
  422. package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
  423. package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
  424. package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
  425. package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
  426. package/runtime/third_party/unicode/LICENSE +39 -0
  427. package/runtime/third_party/unicode/README.md +9 -0
  428. package/runtime/third_party/v8-ieee754/LICENSE +0 -0
  429. package/runtime/third_party/v8-ieee754/LICENSE.fdlibm +10 -0
  430. package/runtime/third_party/v8-ieee754/README.md +3 -2
  431. package/runtime/third_party/v8-ieee754/convert.py +0 -0
  432. package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
  433. package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
  434. package/runtime/tools/regexp_compile.c +2 -2
@@ -0,0 +1,1098 @@
1
+ // node:child_process: Node's lib/child_process.js and the ChildProcess of
2
+ // lib/internal/child_process.js (MIT; Node v22.22.2), ported: spawn, exec and execFile, their
3
+ // synchronous forms, and ChildProcess with its events (spawn, exit, close, error), kill, ref and
4
+ // stdio. A child's stdio pipes are net.Sockets on pipe handles, as in Node; the process and the
5
+ // synchronous runs are libuv's (src/host_process.c). Not here: fork() and the 'ipc' stdio, which
6
+ // start a Node with a channel to it (a compiled program has no Node to start), and handles of
7
+ // UDP sockets as stdio. Node's notice for lib/child_process.js:
8
+ //
9
+ // Copyright Joyent, Inc. and other Node contributors.
10
+ //
11
+ // Permission is hereby granted, free of charge, to any person obtaining a
12
+ // copy of this software and associated documentation files (the
13
+ // "Software"), to deal in the Software without restriction, including
14
+ // without limitation the rights to use, copy, modify, merge, publish,
15
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
16
+ // persons to whom the Software is furnished to do so, subject to the
17
+ // following conditions:
18
+ //
19
+ // The above copyright notice and this permission notice shall be included
20
+ // in all copies or substantial portions of the Software.
21
+ //
22
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
25
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
26
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
28
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ import {
30
+ errnoName, netOpen, osConstants, processClose, processKillChild, processRef, processSpawn, processSpawnSync,
31
+ utilInspect as inspect,
32
+ } from "visaljs:host";
33
+ import { Buffer } from "./buffer.js";
34
+ import { EventEmitter } from "./events.js";
35
+ import { codeError, errnoException, invalidArgType, invalidArgValue, notSupported, outOfRange, validateFunction, validateString } from "./internal/errors.js";
36
+ import { Socket } from "./net.js";
37
+ import { isArrayBufferView } from "./util_types.js";
38
+
39
+ const MAX_BUFFER = 1024 * 1024;
40
+ const kIsUsedAsStdio = Symbol("kIsUsedAsStdio");
41
+ const kCustomPromisify = Symbol.for("nodejs.util.promisify.custom");
42
+
43
+ /* "SIGTERM" ↔ 15, as os.constants.signals; libuv's errno numbers by name */
44
+ const signals = Object.create(null);
45
+ const signalNames = Object.create(null);
46
+ const errnos = Object.create(null);
47
+ {
48
+ const [signalTable, errnoTable] = osConstants();
49
+ for (let i = 0; i < signalTable.length; i += 2) {
50
+ signals[signalTable[i]] = signalTable[i + 1];
51
+ signalNames[signalTable[i + 1]] ??= signalTable[i];
52
+ }
53
+ for (let i = 0; i < errnoTable.length; i += 2) errnos[errnoTable[i]] = -errnoTable[i + 1];
54
+ }
55
+ const UV_EACCES = errnos.EACCES, UV_EAGAIN = errnos.EAGAIN, UV_EMFILE = errnos.EMFILE, UV_ENFILE = errnos.ENFILE;
56
+ const UV_ENOENT = errnos.ENOENT, UV_EINVAL = errnos.EINVAL, UV_ENOSYS = errnos.ENOSYS, UV_ESRCH = errnos.ESRCH;
57
+
58
+ // ---- Node's errors and validators ---------------------------------------------------------
59
+
60
+ /** Node's ErrnoException: `spawn x ENOENT`, with errno, code and syscall. */
61
+ const ErrnoException = (err, syscall) => errnoException(err, syscall);
62
+
63
+ function genericNodeError(message, errorProperties) {
64
+ const err = new Error(message);
65
+ Object.assign(err, errorProperties);
66
+ return err;
67
+ }
68
+
69
+ function convertToValidSignal(signal) {
70
+ if (typeof signal === "number" && signalNames[signal] !== undefined) return signal;
71
+ if (typeof signal === "string") {
72
+ const signalName = signals[signal.toUpperCase()];
73
+ if (signalName) return signalName;
74
+ }
75
+ throw codeError(TypeError, "ERR_UNKNOWN_SIGNAL", `Unknown signal: ${signal}`);
76
+ }
77
+
78
+ function validateObject(value, name) {
79
+ if (value === null || typeof value !== "object" || Array.isArray(value)) throw invalidArgType(name, "of type object", value);
80
+ }
81
+
82
+ function validateArray(value, name) {
83
+ if (!Array.isArray(value)) throw invalidArgType(name, "an instance of Array", value);
84
+ }
85
+
86
+ function validateBoolean(value, name) {
87
+ if (typeof value !== "boolean") throw invalidArgType(name, "of type boolean", value);
88
+ }
89
+
90
+ function validateAbortSignal(signal, name) {
91
+ if (signal !== undefined && (signal === null || typeof signal !== "object" || !("aborted" in signal))) {
92
+ throw invalidArgType(name, "an instance of AbortSignal", signal);
93
+ }
94
+ }
95
+
96
+ function validateArgumentNullCheck(arg, propName) {
97
+ if (typeof arg === "string" && arg.includes("\u0000")) {
98
+ throw invalidArgValue(propName, "must be a string without null bytes", arg);
99
+ }
100
+ }
101
+
102
+ function validateArgumentsNullCheck(args, propName) {
103
+ for (let i = 0; i < args.length; ++i) {
104
+ validateArgumentNullCheck(args[i], `${propName}[${i}]`);
105
+ }
106
+ }
107
+
108
+ function validateTimeout(timeout) {
109
+ if (timeout != null && !(Number.isInteger(timeout) && timeout >= 0)) {
110
+ throw outOfRange("timeout", "an unsigned integer", timeout);
111
+ }
112
+ }
113
+
114
+ function validateMaxBuffer(maxBuffer) {
115
+ if (maxBuffer != null && !(typeof maxBuffer === "number" && maxBuffer >= 0)) {
116
+ throw outOfRange("options.maxBuffer", "a positive number", maxBuffer);
117
+ }
118
+ }
119
+
120
+ function sanitizeKillSignal(killSignal) {
121
+ if (typeof killSignal === "string" || typeof killSignal === "number") {
122
+ return convertToValidSignal(killSignal);
123
+ } else if (killSignal != null) {
124
+ throw invalidArgType("options.killSignal", "of type string or number", killSignal);
125
+ }
126
+ }
127
+
128
+ /** Node's getValidatedPath: a string, a Buffer or a file: URL, without null bytes. */
129
+ function getValidatedPath(path, name) {
130
+ if (path instanceof URL) {
131
+ if (path.protocol !== "file:") throw codeError(TypeError, "ERR_INVALID_URL_SCHEME", "The URL must be of scheme file");
132
+ path = decodeURIComponent(path.pathname);
133
+ } else if (isArrayBufferView(path)) {
134
+ path = Buffer.from(path.buffer, path.byteOffset, path.byteLength).toString();
135
+ } else if (typeof path !== "string") {
136
+ throw invalidArgType(name, "of type string or an instance of Buffer or URL", path);
137
+ }
138
+ if (path.includes("\u0000")) throw invalidArgValue(name, "must be a string, Uint8Array, or URL without null bytes", path);
139
+ return path;
140
+ }
141
+
142
+ const isInt32 = (value) => value === (value | 0);
143
+
144
+ // ---- ChildProcess (lib/internal/child_process.js) -----------------------------------------
145
+
146
+ function stdioStringToArray(stdio, channel) {
147
+ const options = [];
148
+
149
+ switch (stdio) {
150
+ case "ignore":
151
+ case "overlapped":
152
+ case "pipe": options.push(stdio, stdio, stdio); break;
153
+ case "inherit": options.push(0, 1, 2); break;
154
+ default:
155
+ throw invalidArgValue("stdio", "is invalid", stdio);
156
+ }
157
+
158
+ if (channel) options.push(channel);
159
+
160
+ return options;
161
+ }
162
+
163
+ /* a pipe the child is given: a node:net pipe handle, a net.Socket's once the child has it */
164
+ class Pipe {
165
+ constructor() {
166
+ this.id = netOpen(true, undefined);
167
+ }
168
+
169
+ close() {
170
+ new Socket({ handle: this.id, _isPipe: true, readable: false }).destroy();
171
+ }
172
+ }
173
+
174
+ /* a net.Socket (or a stream with one) whose handle the child inherits */
175
+ const socketHandle = (stdio) => (stdio instanceof Socket && stdio._handle !== null ? stdio._handle : undefined);
176
+
177
+ function getValidStdio(stdio, sync) {
178
+
179
+ // Replace shortcut with an array
180
+ if (typeof stdio === "string") {
181
+ stdio = stdioStringToArray(stdio);
182
+ } else if (!Array.isArray(stdio)) {
183
+ throw invalidArgValue("stdio", "is invalid", stdio);
184
+ }
185
+
186
+ // At least 3 stdio will be created
187
+ while (stdio.length < 3) stdio.push(undefined);
188
+
189
+ // Translate stdio into C-readable form (i.e. pipes or fds)
190
+ stdio = stdio.reduce((acc, stdio, i) => {
191
+ function cleanup() {
192
+ for (let i = 0; i < acc.length; i++) {
193
+ if (acc[i].type === "pipe" && acc[i].handle) acc[i].handle.close();
194
+ }
195
+ }
196
+
197
+ // Defaults
198
+ stdio ??= i < 3 ? "pipe" : "ignore";
199
+
200
+ if (stdio === "ignore") {
201
+ acc.push({ type: "ignore" });
202
+ } else if (stdio === "pipe" || stdio === "overlapped" || (typeof stdio === "number" && stdio < 0)) {
203
+ const a = {
204
+ type: stdio === "overlapped" ? "overlapped" : "pipe",
205
+ readable: i === 0,
206
+ writable: i !== 0,
207
+ };
208
+
209
+ if (!sync) a.handle = new Pipe();
210
+
211
+ acc.push(a);
212
+ } else if (stdio === "ipc") {
213
+ cleanup();
214
+ throw notSupported(sync ? "spawnSync()'s 'ipc' stdio" : "The 'ipc' stdio");
215
+ } else if (stdio === "inherit") {
216
+ acc.push({ type: "inherit", fd: i });
217
+ } else if (typeof stdio === "number" || typeof stdio.fd === "number") {
218
+ acc.push({ type: "fd", fd: typeof stdio === "number" ? stdio : stdio.fd });
219
+ } else if (socketHandle(stdio) !== undefined || socketHandle(stdio.handle) !== undefined || socketHandle(stdio._handle) !== undefined) {
220
+ const socket = socketHandle(stdio) !== undefined ? stdio : socketHandle(stdio.handle) !== undefined ? stdio.handle : stdio._handle;
221
+ acc.push({ type: "wrap", handle: socket._handle, socket, _stdio: stdio });
222
+ } else if (isArrayBufferView(stdio) || typeof stdio === "string") {
223
+ if (!sync) {
224
+ cleanup();
225
+ throw codeError(TypeError, "ERR_INVALID_SYNC_FORK_INPUT", `Asynchronous forks do not support Buffer, TypedArray, DataView or string input: ${inspect(stdio)}`);
226
+ }
227
+ } else {
228
+ // Cleanup
229
+ cleanup();
230
+ throw invalidArgValue("stdio", "is invalid", stdio);
231
+ }
232
+
233
+ return acc;
234
+ }, []);
235
+
236
+ return { stdio };
237
+ }
238
+
239
+ /* stdio as the host takes it: [kind, value] each */
240
+ function hostStdio(stdio) {
241
+ return stdio.map((s) => {
242
+ switch (s.type) {
243
+ case "pipe": return [1, s.handle?.id ?? s.input ?? null];
244
+ case "overlapped": return [2, s.handle?.id ?? s.input ?? null];
245
+ case "inherit":
246
+ case "fd": return [3, s.fd];
247
+ case "wrap": return [4, s.handle];
248
+ default: return [0, null];
249
+ }
250
+ });
251
+ }
252
+
253
+ function spawnFlags(options) {
254
+ return (options.detached ? 1 : 0) | (options.windowsHide ? 2 : 0) | (options.windowsVerbatimArguments ? 4 : 0);
255
+ }
256
+
257
+ /** A child process: Node's ChildProcess. */
258
+ export function ChildProcess() {
259
+ EventEmitter.call(this);
260
+
261
+ this._closesNeeded = 1;
262
+ this._closesGot = 0;
263
+ this.connected = false;
264
+
265
+ this.signalCode = null;
266
+ this.exitCode = null;
267
+ this.killed = false;
268
+ this.spawnfile = null;
269
+
270
+ this._handle = { id: -1, pid: 0 };
271
+ this._onexit = (exitCode, signalCode) => {
272
+ if (signalCode) {
273
+ this.signalCode = signalCode;
274
+ } else {
275
+ this.exitCode = exitCode;
276
+ }
277
+
278
+ if (this.stdin) {
279
+ this.stdin.destroy();
280
+ }
281
+
282
+ if (this._handle?.id >= 0) processClose(this._handle.id);
283
+ this._handle = null;
284
+
285
+ if (exitCode < 0) {
286
+ const syscall = this.spawnfile ? "spawn " + this.spawnfile : "spawn";
287
+ const err = ErrnoException(exitCode, syscall);
288
+
289
+ if (this.spawnfile) err.path = this.spawnfile;
290
+
291
+ err.spawnargs = this.spawnargs.slice(1);
292
+ this.emit("error", err);
293
+ } else {
294
+ this.emit("exit", this.exitCode, this.signalCode);
295
+ }
296
+
297
+ // If any of the stdio streams have not been touched,
298
+ // then pull all the data through so that it can get the
299
+ // eof and emit a 'close' event.
300
+ // Do it on nextTick so that the user has one last chance
301
+ // to consume the output, if for example they only want to
302
+ // start reading the data once the process exits.
303
+ process.nextTick(flushStdio, this);
304
+
305
+ maybeClose(this);
306
+ };
307
+ }
308
+ Object.setPrototypeOf(ChildProcess.prototype, EventEmitter.prototype);
309
+ Object.setPrototypeOf(ChildProcess, EventEmitter);
310
+
311
+ function flushStdio(subprocess) {
312
+ const stdio = subprocess.stdio;
313
+
314
+ if (stdio == null) return;
315
+
316
+ for (let i = 0; i < stdio.length; i++) {
317
+ const stream = stdio[i];
318
+ if (!stream || !stream.readable || stream[kIsUsedAsStdio]) {
319
+ continue;
320
+ }
321
+ stream.resume();
322
+ }
323
+ }
324
+
325
+ function createSocket(pipe, readable) {
326
+ return new Socket({ handle: pipe.id, _isPipe: true, readable });
327
+ }
328
+
329
+ ChildProcess.prototype.spawn = function spawn(options) {
330
+ let i;
331
+
332
+ validateObject(options, "options");
333
+
334
+ // If no `stdio` option was given - use default
335
+ let stdio = options.stdio || "pipe";
336
+
337
+ stdio = getValidStdio(stdio, false);
338
+
339
+ stdio = options.stdio = stdio.stdio;
340
+
341
+ if (options.serialization !== undefined && options.serialization !== "json" && options.serialization !== "advanced") {
342
+ throw invalidArgValue("options.serialization", "must be one of: undefined, 'json', 'advanced'", options.serialization);
343
+ }
344
+
345
+ validateString(options.file, "options.file");
346
+ this.spawnfile = options.file;
347
+
348
+ if (options.args === undefined) {
349
+ this.spawnargs = [];
350
+ } else {
351
+ validateArray(options.args, "options.args");
352
+ this.spawnargs = options.args;
353
+ }
354
+
355
+ const result = processSpawn(options.file, this.spawnargs, options.envPairs ?? null, options.cwd ?? null, hostStdio(stdio),
356
+ spawnFlags(options), options.uid ?? -1, options.gid ?? -1,
357
+ (exitStatus, termSignal) => this._onexit(exitStatus, termSignal ? signalNames[termSignal] ?? termSignal : null));
358
+ const err = result[0];
359
+ if (err === 0) {
360
+ this._handle.id = result[1];
361
+ this._handle.pid = result[2];
362
+ }
363
+
364
+ // Run-time errors should emit an error, not throw an exception.
365
+ if (err === UV_EACCES || err === UV_EAGAIN || err === UV_EMFILE || err === UV_ENFILE || err === UV_ENOENT) {
366
+ process.nextTick(onErrorNT, this, err);
367
+
368
+ // There is no point in continuing when we've hit EMFILE or ENFILE
369
+ // because we won't be able to set up the stdio file descriptors.
370
+ if (err === UV_EMFILE || err === UV_ENFILE) return err;
371
+ } else if (err) {
372
+ // Close all opened fds on error
373
+ for (i = 0; i < stdio.length; i++) {
374
+ const stream = stdio[i];
375
+ if (stream.type === "pipe") {
376
+ stream.handle.close();
377
+ }
378
+ }
379
+
380
+ this._handle = null;
381
+ throw ErrnoException(err, "spawn");
382
+ } else {
383
+ process.nextTick(onSpawnNT, this);
384
+ }
385
+
386
+ this.pid = this._handle.pid || undefined;
387
+
388
+ for (i = 0; i < stdio.length; i++) {
389
+ const stream = stdio[i];
390
+ if (stream.type === "ignore") continue;
391
+
392
+ // The stream is already cloned and piped, thus stop its readable side,
393
+ // otherwise we might attempt to read from the stream when at the same time
394
+ // the child process does.
395
+ if (stream.type === "wrap") {
396
+ stream._stdio.pause();
397
+ stream._stdio.readableFlowing = false;
398
+ stream._stdio._readableState.reading = false;
399
+ stream._stdio[kIsUsedAsStdio] = true;
400
+ continue;
401
+ }
402
+
403
+ if (stream.handle) {
404
+ if (this._handle.pid !== 0) {
405
+ stream.socket = createSocket(stream.handle, i > 0);
406
+ } else {
407
+ stream.handle.close();
408
+ stream.socket = new Socket({ readable: i > 0 });
409
+ }
410
+
411
+ if (i > 0 && this._handle.pid !== 0) {
412
+ this._closesNeeded++;
413
+ stream.socket.on("close", () => {
414
+ maybeClose(this);
415
+ });
416
+ }
417
+ }
418
+ }
419
+
420
+ this.stdin = stdio.length >= 1 && stdio[0].socket !== undefined ? stdio[0].socket : null;
421
+ this.stdout = stdio.length >= 2 && stdio[1].socket !== undefined ? stdio[1].socket : null;
422
+ this.stderr = stdio.length >= 3 && stdio[2].socket !== undefined ? stdio[2].socket : null;
423
+
424
+ this.stdio = [];
425
+
426
+ for (i = 0; i < stdio.length; i++) this.stdio.push(stdio[i].socket === undefined ? null : stdio[i].socket);
427
+
428
+ return err;
429
+ };
430
+
431
+ function onErrorNT(self, err) {
432
+ self._onexit(err);
433
+ }
434
+
435
+ function onSpawnNT(self) {
436
+ self.emit("spawn");
437
+ }
438
+
439
+ ChildProcess.prototype.kill = function kill(sig) {
440
+ const signal = sig === 0 ? sig : convertToValidSignal(sig === undefined ? "SIGTERM" : sig);
441
+
442
+ if (this._handle) {
443
+ const err = processKillChild(this._handle.id, signal);
444
+ if (err === 0) {
445
+ /* Success. */
446
+ this.killed = true;
447
+ return true;
448
+ }
449
+ if (err === UV_ESRCH) {
450
+ /* Already dead. */
451
+ } else if (err === UV_EINVAL || err === UV_ENOSYS) {
452
+ /* The underlying platform doesn't support this signal. */
453
+ throw ErrnoException(err, "kill");
454
+ } else {
455
+ /* Other error, almost certainly EPERM. */
456
+ this.emit("error", ErrnoException(err, "kill"));
457
+ }
458
+ }
459
+
460
+ /* Kill didn't succeed. */
461
+ return false;
462
+ };
463
+
464
+ if (typeof Symbol.dispose === "symbol") {
465
+ ChildProcess.prototype[Symbol.dispose] = function () {
466
+ if (!this.killed) {
467
+ this.kill();
468
+ }
469
+ };
470
+ }
471
+
472
+ ChildProcess.prototype.ref = function ref() {
473
+ if (this._handle) processRef(this._handle.id, true);
474
+ };
475
+
476
+ ChildProcess.prototype.unref = function unref() {
477
+ if (this._handle) processRef(this._handle.id, false);
478
+ };
479
+
480
+ ChildProcess.prototype.send = function send() {
481
+ throw codeError(Error, "ERR_IPC_CHANNEL_CLOSED", "Channel closed");
482
+ };
483
+
484
+ ChildProcess.prototype.disconnect = function disconnect() {
485
+ this.emit("error", codeError(Error, "ERR_IPC_DISCONNECTED", "IPC channel is already disconnected"));
486
+ };
487
+
488
+ function maybeClose(subprocess) {
489
+ subprocess._closesGot++;
490
+
491
+ if (subprocess._closesGot === subprocess._closesNeeded) {
492
+ subprocess.emit("close", subprocess.exitCode, subprocess.signalCode);
493
+ }
494
+ }
495
+
496
+ // ---- The module (lib/child_process.js) ----------------------------------------------------
497
+
498
+ /** Node's fork(): a Node running a module, with a channel to it. */
499
+ export function fork() {
500
+ throw notSupported("child_process.fork() (it starts a Node, which a compiled program doesn't have)");
501
+ }
502
+
503
+ export function _forkChild() {
504
+ throw notSupported("child_process._forkChild()");
505
+ }
506
+
507
+ function normalizeExecArgs(command, options, callback) {
508
+ validateString(command, "command");
509
+ validateArgumentNullCheck(command, "command");
510
+
511
+ if (typeof options === "function") {
512
+ callback = options;
513
+ options = undefined;
514
+ }
515
+
516
+ // Make a shallow copy so we don't clobber the user's options object.
517
+ options = { __proto__: null, ...options };
518
+ options.shell = typeof options.shell === "string" ? options.shell : true;
519
+
520
+ return { file: command, options, callback };
521
+ }
522
+
523
+ /** Spawns a shell executing the given command; callback(error, stdout, stderr). */
524
+ export function exec(command, options, callback) {
525
+ const opts = normalizeExecArgs(command, options, callback);
526
+ return execFile(opts.file, opts.options, opts.callback);
527
+ }
528
+
529
+ const customPromiseExecFunction = (orig) => {
530
+ const fn = function (...args) {
531
+ const { promise, resolve, reject } = Promise.withResolvers();
532
+
533
+ promise.child = orig(...args, (err, stdout, stderr) => {
534
+ if (err !== null) {
535
+ err.stdout = stdout;
536
+ err.stderr = stderr;
537
+ reject(err);
538
+ } else {
539
+ resolve({ stdout, stderr });
540
+ }
541
+ });
542
+
543
+ return promise;
544
+ };
545
+ Object.defineProperty(fn, "name", { value: orig.name });
546
+ return fn;
547
+ };
548
+
549
+ Object.defineProperty(exec, kCustomPromisify, { enumerable: false, value: customPromiseExecFunction(exec) });
550
+
551
+ function normalizeExecFileArgs(file, args, options, callback) {
552
+ if (Array.isArray(args)) {
553
+ args = args.slice();
554
+ } else if (args != null && typeof args === "object") {
555
+ callback = options;
556
+ options = args;
557
+ args = null;
558
+ } else if (typeof args === "function") {
559
+ callback = args;
560
+ options = null;
561
+ args = null;
562
+ }
563
+
564
+ args ??= [];
565
+
566
+ if (typeof options === "function") {
567
+ callback = options;
568
+ } else if (options != null) {
569
+ validateObject(options, "options");
570
+ }
571
+
572
+ options ??= {};
573
+
574
+ if (callback != null) {
575
+ validateFunction(callback, "callback");
576
+ }
577
+
578
+ // Validate argv0, if present.
579
+ if (options.argv0 != null) {
580
+ validateString(options.argv0, "options.argv0");
581
+ validateArgumentNullCheck(options.argv0, "options.argv0");
582
+ }
583
+
584
+ return { file, args, options, callback };
585
+ }
586
+
587
+ /** Spawns a file (or a command, with options.shell); callback(error, stdout, stderr). */
588
+ export function execFile(file, args, options, callback) {
589
+ ({ file, args, options, callback } = normalizeExecFileArgs(file, args, options, callback));
590
+
591
+ options = {
592
+ __proto__: null,
593
+ encoding: "utf8",
594
+ timeout: 0,
595
+ maxBuffer: MAX_BUFFER,
596
+ killSignal: "SIGTERM",
597
+ cwd: null,
598
+ env: null,
599
+ shell: false,
600
+ ...options,
601
+ };
602
+
603
+ // Validate the timeout, if present.
604
+ validateTimeout(options.timeout);
605
+
606
+ // Validate maxBuffer, if present.
607
+ validateMaxBuffer(options.maxBuffer);
608
+
609
+ options.killSignal = sanitizeKillSignal(options.killSignal);
610
+
611
+ const child = spawn(file, args, {
612
+ cwd: options.cwd,
613
+ env: options.env,
614
+ gid: options.gid,
615
+ shell: options.shell,
616
+ signal: options.signal,
617
+ uid: options.uid,
618
+ windowsHide: !!options.windowsHide,
619
+ windowsVerbatimArguments: !!options.windowsVerbatimArguments,
620
+ });
621
+
622
+ let encoding;
623
+ const _stdout = [];
624
+ const _stderr = [];
625
+ if (options.encoding !== "buffer" && Buffer.isEncoding(options.encoding)) {
626
+ encoding = options.encoding;
627
+ } else {
628
+ encoding = null;
629
+ }
630
+ let stdoutLen = 0;
631
+ let stderrLen = 0;
632
+ let killed = false;
633
+ let exited = false;
634
+ let timeoutId;
635
+
636
+ let ex = null;
637
+
638
+ let cmd = file;
639
+
640
+ function exithandler(code, signal) {
641
+ if (exited) return;
642
+ exited = true;
643
+
644
+ if (timeoutId) {
645
+ clearTimeout(timeoutId);
646
+ timeoutId = null;
647
+ }
648
+
649
+ if (!callback) return;
650
+
651
+ // merge chunks
652
+ let stdout;
653
+ let stderr;
654
+ if (encoding || child.stdout?.readableEncoding) {
655
+ stdout = _stdout.join("");
656
+ } else {
657
+ stdout = Buffer.concat(_stdout);
658
+ }
659
+ if (encoding || child.stderr?.readableEncoding) {
660
+ stderr = _stderr.join("");
661
+ } else {
662
+ stderr = Buffer.concat(_stderr);
663
+ }
664
+
665
+ if (!ex && code === 0 && signal === null) {
666
+ callback(null, stdout, stderr);
667
+ return;
668
+ }
669
+
670
+ if (args?.length) cmd += ` ${args.join(" ")}`;
671
+
672
+ ex ||= genericNodeError(`Command failed: ${cmd}\n${stderr}`, {
673
+ code: code < 0 ? errnoName(code) : code,
674
+ killed: child.killed || killed,
675
+ signal: signal,
676
+ });
677
+
678
+ ex.cmd = cmd;
679
+ callback(ex, stdout, stderr);
680
+ }
681
+
682
+ function errorhandler(e) {
683
+ ex = e;
684
+
685
+ if (child.stdout) child.stdout.destroy();
686
+
687
+ if (child.stderr) child.stderr.destroy();
688
+
689
+ exithandler();
690
+ }
691
+
692
+ function kill() {
693
+ if (child.stdout) child.stdout.destroy();
694
+
695
+ if (child.stderr) child.stderr.destroy();
696
+
697
+ killed = true;
698
+ try {
699
+ child.kill(options.killSignal);
700
+ } catch (e) {
701
+ ex = e;
702
+ exithandler();
703
+ }
704
+ }
705
+
706
+ if (options.timeout > 0) {
707
+ timeoutId = setTimeout(function delayedKill() {
708
+ kill();
709
+ timeoutId = null;
710
+ }, options.timeout);
711
+ }
712
+
713
+ if (child.stdout) {
714
+ if (encoding) child.stdout.setEncoding(encoding);
715
+
716
+ child.stdout.on("data", function onChildStdout(chunk) {
717
+ // Do not need to count the length
718
+ if (options.maxBuffer === Infinity) {
719
+ _stdout.push(chunk);
720
+ return;
721
+ }
722
+ const encoding = child.stdout.readableEncoding;
723
+ const length = encoding ? Buffer.byteLength(chunk, encoding) : chunk.length;
724
+ const slice = encoding ? (s, ...args) => s.slice(...args) : (buf, ...args) => buf.slice(...args);
725
+ stdoutLen += length;
726
+
727
+ if (stdoutLen > options.maxBuffer) {
728
+ const truncatedLen = options.maxBuffer - (stdoutLen - length);
729
+ _stdout.push(slice(chunk, 0, truncatedLen));
730
+
731
+ ex = codeError(RangeError, "ERR_CHILD_PROCESS_STDIO_MAXBUFFER", "stdout maxBuffer length exceeded");
732
+ kill();
733
+ } else {
734
+ _stdout.push(chunk);
735
+ }
736
+ });
737
+ }
738
+
739
+ if (child.stderr) {
740
+ if (encoding) child.stderr.setEncoding(encoding);
741
+
742
+ child.stderr.on("data", function onChildStderr(chunk) {
743
+ // Do not need to count the length
744
+ if (options.maxBuffer === Infinity) {
745
+ _stderr.push(chunk);
746
+ return;
747
+ }
748
+ const encoding = child.stderr.readableEncoding;
749
+ const length = encoding ? Buffer.byteLength(chunk, encoding) : chunk.length;
750
+ stderrLen += length;
751
+
752
+ if (stderrLen > options.maxBuffer) {
753
+ const truncatedLen = options.maxBuffer - (stderrLen - length);
754
+ _stderr.push(chunk.slice(0, truncatedLen));
755
+
756
+ ex = codeError(RangeError, "ERR_CHILD_PROCESS_STDIO_MAXBUFFER", "stderr maxBuffer length exceeded");
757
+ kill();
758
+ } else {
759
+ _stderr.push(chunk);
760
+ }
761
+ });
762
+ }
763
+
764
+ child.addListener("close", exithandler);
765
+ child.addListener("error", errorhandler);
766
+
767
+ return child;
768
+ }
769
+
770
+ Object.defineProperty(execFile, kCustomPromisify, { enumerable: false, value: customPromiseExecFunction(execFile) });
771
+
772
+ function normalizeSpawnArguments(file, args, options) {
773
+ validateString(file, "file");
774
+ validateArgumentNullCheck(file, "file");
775
+
776
+ if (file.length === 0) throw invalidArgValue("file", "cannot be empty", file);
777
+
778
+ if (Array.isArray(args)) {
779
+ args = args.slice();
780
+ } else if (args == null) {
781
+ args = [];
782
+ } else if (typeof args !== "object") {
783
+ throw invalidArgType("args", "of type object", args);
784
+ } else {
785
+ options = args;
786
+ args = [];
787
+ }
788
+
789
+ validateArgumentsNullCheck(args, "args");
790
+
791
+ if (options === undefined) options = {};
792
+ else validateObject(options, "options");
793
+
794
+ options = { __proto__: null, ...options };
795
+ let cwd = options.cwd;
796
+
797
+ // Validate the cwd, if present.
798
+ if (cwd != null) {
799
+ cwd = getValidatedPath(cwd, "options.cwd");
800
+ }
801
+
802
+ // Validate detached, if present.
803
+ if (options.detached != null) {
804
+ validateBoolean(options.detached, "options.detached");
805
+ }
806
+
807
+ // Validate the uid, if present.
808
+ if (options.uid != null && !isInt32(options.uid)) {
809
+ throw invalidArgType("options.uid", "of type int32", options.uid);
810
+ }
811
+
812
+ // Validate the gid, if present.
813
+ if (options.gid != null && !isInt32(options.gid)) {
814
+ throw invalidArgType("options.gid", "of type int32", options.gid);
815
+ }
816
+
817
+ // Validate the shell, if present.
818
+ if (options.shell != null && typeof options.shell !== "boolean" && typeof options.shell !== "string") {
819
+ throw invalidArgType("options.shell", "of type boolean or string", options.shell);
820
+ }
821
+
822
+ // Validate argv0, if present.
823
+ if (options.argv0 != null) {
824
+ validateString(options.argv0, "options.argv0");
825
+ validateArgumentNullCheck(options.argv0, "options.argv0");
826
+ }
827
+
828
+ // Validate windowsHide, if present.
829
+ if (options.windowsHide != null) {
830
+ validateBoolean(options.windowsHide, "options.windowsHide");
831
+ }
832
+
833
+ // Validate windowsVerbatimArguments, if present.
834
+ let { windowsVerbatimArguments } = options;
835
+ if (windowsVerbatimArguments != null) {
836
+ validateBoolean(windowsVerbatimArguments, "options.windowsVerbatimArguments");
837
+ }
838
+
839
+ if (options.shell) {
840
+ validateArgumentNullCheck(options.shell, "options.shell");
841
+
842
+ const command = args.length > 0 ? `${file} ${args.join(" ")}` : file;
843
+ // Set the shell, switches, and commands.
844
+ if (process.platform === "win32") {
845
+ if (typeof options.shell === "string") file = options.shell;
846
+ else file = process.env.comspec || "cmd.exe";
847
+ // '/d /s /c' is used only for cmd.exe.
848
+ if (/^(?:.*\\)?cmd(?:\.exe)?$/i.exec(file) !== null) {
849
+ args = ["/d", "/s", "/c", `"${command}"`];
850
+ windowsVerbatimArguments = true;
851
+ } else {
852
+ args = ["-c", command];
853
+ }
854
+ } else {
855
+ if (typeof options.shell === "string") file = options.shell;
856
+ else if (process.platform === "android") file = "/system/bin/sh";
857
+ else file = "/bin/sh";
858
+ args = ["-c", command];
859
+ }
860
+ }
861
+
862
+ if (typeof options.argv0 === "string") {
863
+ args.unshift(options.argv0);
864
+ } else {
865
+ args.unshift(file);
866
+ }
867
+
868
+ // Shallow copy to guarantee changes won't impact process.env
869
+ const env = options.env || { ...process.env };
870
+ const envPairs = [];
871
+
872
+ let envKeys = [];
873
+ // Prototype values are intentionally included.
874
+ for (const key in env) {
875
+ envKeys.push(key);
876
+ }
877
+
878
+ if (process.platform === "win32") {
879
+ // On Windows env keys are case insensitive. Filter out duplicates,
880
+ // keeping only the first one (in lexicographic order)
881
+ const sawKey = new Set();
882
+ envKeys = envKeys.sort().filter((key) => {
883
+ const uppercaseKey = key.toUpperCase();
884
+ if (sawKey.has(uppercaseKey)) {
885
+ return false;
886
+ }
887
+ sawKey.add(uppercaseKey);
888
+ return true;
889
+ });
890
+ }
891
+
892
+ for (const key of envKeys) {
893
+ const value = env[key];
894
+ if (value !== undefined) {
895
+ validateArgumentNullCheck(key, `options.env['${key}']`);
896
+ validateArgumentNullCheck(value, `options.env['${key}']`);
897
+ envPairs.push(`${key}=${value}`);
898
+ }
899
+ }
900
+
901
+ return {
902
+ // Make a shallow copy so we don't clobber the user's options object.
903
+ __proto__: null,
904
+ ...options,
905
+ args,
906
+ cwd,
907
+ detached: !!options.detached,
908
+ envPairs,
909
+ file,
910
+ windowsHide: !!options.windowsHide,
911
+ windowsVerbatimArguments: !!windowsVerbatimArguments,
912
+ };
913
+ }
914
+
915
+ function abortChildProcess(child, killSignal, reason) {
916
+ if (!child) return;
917
+ try {
918
+ if (child.kill(killSignal)) {
919
+ const err = new Error("The operation was aborted", { cause: reason });
920
+ err.code = "ABORT_ERR";
921
+ err.name = "AbortError";
922
+ child.emit("error", err);
923
+ }
924
+ } catch (err) {
925
+ child.emit("error", err);
926
+ }
927
+ }
928
+
929
+ /** Spawns a new process using the given `file`. */
930
+ export function spawn(file, args, options) {
931
+ options = normalizeSpawnArguments(file, args, options);
932
+ validateTimeout(options.timeout);
933
+ validateAbortSignal(options.signal, "options.signal");
934
+ const killSignal = sanitizeKillSignal(options.killSignal);
935
+ const child = new ChildProcess();
936
+
937
+ child.spawn(options);
938
+
939
+ if (options.timeout > 0) {
940
+ let timeoutId = setTimeout(() => {
941
+ if (timeoutId) {
942
+ try {
943
+ child.kill(killSignal);
944
+ } catch (err) {
945
+ child.emit("error", err);
946
+ }
947
+ timeoutId = null;
948
+ }
949
+ }, options.timeout);
950
+
951
+ child.once("exit", () => {
952
+ if (timeoutId) {
953
+ clearTimeout(timeoutId);
954
+ timeoutId = null;
955
+ }
956
+ });
957
+ }
958
+
959
+ if (options.signal) {
960
+ const signal = options.signal;
961
+ if (signal.aborted) {
962
+ process.nextTick(onAbortListener);
963
+ } else {
964
+ signal.addEventListener("abort", onAbortListener, { once: true });
965
+ child.once("exit", () => signal.removeEventListener("abort", onAbortListener));
966
+ }
967
+
968
+ function onAbortListener() {
969
+ abortChildProcess(child, killSignal, options.signal.reason);
970
+ }
971
+ }
972
+
973
+ return child;
974
+ }
975
+
976
+ /* lib/internal/child_process.js's spawnSync: the host's result as Node's */
977
+ function spawnSyncResult(options) {
978
+ const [error, pid, status, termSignal, output] = processSpawnSync(options.file, options.args, options.envPairs ?? null,
979
+ options.cwd ?? null, hostStdio(options.stdio), spawnFlags(options), options.uid ?? -1, options.gid ?? -1,
980
+ options.timeout ?? 0, options.maxBuffer ?? MAX_BUFFER, options.killSignal ?? signals.SIGTERM);
981
+ /* Node's SyncProcessRunner's result: the error first, when there is one; status, signal and
982
+ output null when the child never ran */
983
+ const result = {};
984
+ if (error !== 0) result.error = error;
985
+ result.status = status === null || termSignal ? null : status;
986
+ result.signal = termSignal ? signalNames[termSignal] ?? termSignal : null;
987
+ result.output = status === null ? null : output.map((bytes) => (bytes === null ? null : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)));
988
+ result.pid = pid;
989
+ if (result.output && options.encoding && options.encoding !== "buffer") {
990
+ for (let i = 0; i < result.output.length; i++) {
991
+ if (!result.output[i]) continue;
992
+ result.output[i] = result.output[i].toString(options.encoding);
993
+ }
994
+ }
995
+
996
+ result.stdout = result.output?.[1];
997
+ result.stderr = result.output?.[2];
998
+
999
+ if (result.error) {
1000
+ result.error = ErrnoException(result.error, "spawnSync " + options.file);
1001
+ result.error.path = options.file;
1002
+ result.error.spawnargs = options.args.slice(1);
1003
+ }
1004
+
1005
+ return result;
1006
+ }
1007
+
1008
+ /** Spawns a new process synchronously using the given `file`. */
1009
+ export function spawnSync(file, args, options) {
1010
+ options = {
1011
+ __proto__: null,
1012
+ maxBuffer: MAX_BUFFER,
1013
+ ...normalizeSpawnArguments(file, args, options),
1014
+ };
1015
+
1016
+ // Validate the timeout, if present.
1017
+ validateTimeout(options.timeout);
1018
+
1019
+ // Validate maxBuffer, if present.
1020
+ validateMaxBuffer(options.maxBuffer);
1021
+
1022
+ // Validate and translate the kill signal, if present.
1023
+ options.killSignal = sanitizeKillSignal(options.killSignal);
1024
+
1025
+ options.stdio = getValidStdio(options.stdio || "pipe", true).stdio;
1026
+
1027
+ if (options.input) {
1028
+ const stdin = options.stdio[0] = { ...options.stdio[0] };
1029
+ stdin.input = options.input;
1030
+ }
1031
+
1032
+ // We may want to pass data in on any given fd, ensure it is a valid buffer
1033
+ for (let i = 0; i < options.stdio.length; i++) {
1034
+ const input = options.stdio[i]?.input;
1035
+ if (input != null) {
1036
+ const pipe = options.stdio[i] = { ...options.stdio[i] };
1037
+ if (isArrayBufferView(input)) {
1038
+ pipe.input = input;
1039
+ } else if (typeof input === "string") {
1040
+ pipe.input = Buffer.from(input, options.encoding);
1041
+ } else {
1042
+ throw invalidArgType(`options.stdio[${i}]`, "of type string or an instance of Buffer, TypedArray, or DataView", input);
1043
+ }
1044
+ }
1045
+ }
1046
+
1047
+ return spawnSyncResult(options);
1048
+ }
1049
+
1050
+ function checkExecSyncError(ret, args, cmd) {
1051
+ let err;
1052
+ if (ret.error) {
1053
+ err = ret.error;
1054
+ Object.assign(err, ret);
1055
+ } else if (ret.status !== 0) {
1056
+ let msg = "Command failed: ";
1057
+ msg += cmd || args.join(" ");
1058
+ if (ret.stderr && ret.stderr.length > 0) msg += `\n${ret.stderr.toString()}`;
1059
+ err = genericNodeError(msg, ret);
1060
+ }
1061
+ return err;
1062
+ }
1063
+
1064
+ /** Spawns a file synchronously: its stdout, or an error when it fails. */
1065
+ export function execFileSync(file, args, options) {
1066
+ ({ file, args, options } = normalizeExecFileArgs(file, args, options));
1067
+
1068
+ const inheritStderr = !options.stdio;
1069
+ const ret = spawnSync(file, args, options);
1070
+
1071
+ if (inheritStderr && ret.stderr) process.stderr.write(ret.stderr);
1072
+
1073
+ const errArgs = [options.argv0 || file];
1074
+ errArgs.push(...args);
1075
+ const err = checkExecSyncError(ret, errArgs);
1076
+
1077
+ if (err) throw err;
1078
+
1079
+ return ret.stdout;
1080
+ }
1081
+
1082
+ /** Spawns a shell executing the given command synchronously: its stdout, or an error. */
1083
+ export function execSync(command, options) {
1084
+ const opts = normalizeExecArgs(command, options, null);
1085
+ const inheritStderr = !opts.options.stdio;
1086
+
1087
+ const ret = spawnSync(opts.file, opts.options);
1088
+
1089
+ if (inheritStderr && ret.stderr) process.stderr.write(ret.stderr);
1090
+
1091
+ const err = checkExecSyncError(ret, undefined, command);
1092
+
1093
+ if (err) throw err;
1094
+
1095
+ return ret.stdout;
1096
+ }
1097
+
1098
+ export default { _forkChild, ChildProcess, exec, execFile, execFileSync, execSync, fork, spawn, spawnSync };