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,52 @@
1
+ // node:cluster: a compiled program is the primary, with no workers: forking one would start a Node
2
+ // process, so fork() throws ERR_VISALJS_UNSUPPORTED. The settings, scheduling policy and events
3
+ // are Node's.
4
+ import { EventEmitter } from "./events.js";
5
+ import { notSupported } from "./internal/errors.js";
6
+
7
+ const cluster = new EventEmitter();
8
+
9
+ export const isPrimary = true;
10
+ export const isMaster = true;
11
+ export const isWorker = false;
12
+ export const SCHED_NONE = 1;
13
+ export const SCHED_RR = 2;
14
+ export const workers = {};
15
+ export const settings = {};
16
+ export let schedulingPolicy = process.platform === "win32" ? SCHED_NONE : SCHED_RR;
17
+
18
+ /** A worker: made only by fork(). */
19
+ export function Worker() {
20
+ throw notSupported("cluster.Worker (forking a Node process)");
21
+ }
22
+ Object.setPrototypeOf(Worker.prototype, EventEmitter.prototype);
23
+
24
+ /** setupPrimary([settings]): the settings fork() would use; 'setup' follows. */
25
+ export function setupPrimary(options) {
26
+ Object.assign(settings, { args: process.argv.slice(2), exec: process.argv[1], execArgv: process.execArgv, silent: false, ...options });
27
+ cluster.emit("setup", settings);
28
+ }
29
+ export const setupMaster = setupPrimary;
30
+
31
+ export function fork() {
32
+ throw notSupported("cluster.fork (forking a Node process)");
33
+ }
34
+
35
+ /** No workers to disconnect: the callback on a later tick. */
36
+ export function disconnect(callback) {
37
+ if (typeof callback === "function") process.nextTick(callback);
38
+ }
39
+
40
+ Object.assign(cluster, {
41
+ isPrimary, isMaster, isWorker, SCHED_NONE, SCHED_RR, workers, settings, Worker, setupPrimary, setupMaster, fork, disconnect,
42
+ });
43
+ Object.defineProperty(cluster, "schedulingPolicy", {
44
+ get: () => schedulingPolicy,
45
+ set: (value) => {
46
+ schedulingPolicy = value;
47
+ },
48
+ enumerable: true,
49
+ configurable: true,
50
+ });
51
+
52
+ export default cluster;
@@ -0,0 +1,328 @@
1
+ // node:console: the global console (the runtime's, in C), and Console, a console writing to the
2
+ // streams it's given, as Node's: log, info, debug and dirxml to stdout; warn, error and trace to
3
+ // stderr; groups indent every line; count, time and table as Node formats them. Its formatting is
4
+ // util.format's and util.inspect's, which the global console's is too.
5
+ import { inspect, format, formatWithOptions, stripVTControlCharacters } from "./util.js";
6
+ import { codeError, invalidArgType } from "./internal/errors.js";
7
+
8
+ const kIsConsole = Symbol("kIsConsole");
9
+ const kSecond = 1000;
10
+ const kMinute = 60 * kSecond;
11
+ const kHour = 60 * kMinute;
12
+
13
+ /* ---- console.table: Node's internal/cli_table ------------------------------------------------- */
14
+
15
+ const isFullWidthCodePoint = (code) => code >= 0x1100 && (code <= 0x115f || code === 0x2329 || code === 0x232a ||
16
+ (code >= 0x2e80 && code <= 0x3247 && code !== 0x303f) || (code >= 0x3250 && code <= 0x4dbf) || (code >= 0x4e00 && code <= 0xa4c6) ||
17
+ (code >= 0xa960 && code <= 0xa97c) || (code >= 0xac00 && code <= 0xd7a3) || (code >= 0xf900 && code <= 0xfaff) ||
18
+ (code >= 0xfe10 && code <= 0xfe19) || (code >= 0xfe30 && code <= 0xfe6b) || (code >= 0xff01 && code <= 0xff60) ||
19
+ (code >= 0xffe0 && code <= 0xffe6) || (code >= 0x1b000 && code <= 0x1b001) || (code >= 0x1f200 && code <= 0x1f251) ||
20
+ (code >= 0x1f300 && code <= 0x1f64f) || (code >= 0x20000 && code <= 0x3fffd));
21
+
22
+ const isZeroWidthCodePoint = (code) => code <= 0x1f || (code >= 0x7f && code <= 0x9f) || (code >= 0x300 && code <= 0x36f) ||
23
+ (code >= 0x200b && code <= 0x200f) || (code >= 0x20d0 && code <= 0x20ff) || (code >= 0xfe00 && code <= 0xfe0f) ||
24
+ (code >= 0xfe20 && code <= 0xfe2f) || (code >= 0xe0100 && code <= 0xe01ef);
25
+
26
+ /* columns on a terminal: wide characters two, combining ones none */
27
+ function getStringWidth(str) {
28
+ let width = 0;
29
+ for (const char of stripVTControlCharacters(str).normalize("NFC")) {
30
+ const code = char.codePointAt(0);
31
+ if (isFullWidthCodePoint(code)) width += 2;
32
+ else if (!isZeroWidthCodePoint(code)) width++;
33
+ }
34
+ return width;
35
+ }
36
+
37
+ const tableChars = {
38
+ middleMiddle: "─", rowMiddle: "┼", topRight: "┐", topLeft: "┌", leftMiddle: "├", topMiddle: "┬", bottomRight: "┘",
39
+ bottomLeft: "└", bottomMiddle: "┴", rightMiddle: "┤", left: "│ ", right: " │", middle: " │ ",
40
+ };
41
+
42
+ function renderRow(row, columnWidths) {
43
+ let out = tableChars.left;
44
+ for (let i = 0; i < row.length; i++) {
45
+ const cell = row[i];
46
+ out += cell + " ".repeat(columnWidths[i] - getStringWidth(cell)); /* left-aligned, as Node 22's */
47
+ if (i !== row.length - 1) out += tableChars.middle;
48
+ }
49
+ return out + tableChars.right;
50
+ }
51
+
52
+ function renderTable(head, columns) {
53
+ const rows = [];
54
+ const columnWidths = head.map((h) => getStringWidth(h));
55
+ const longestColumn = Math.max(...columns.map((a) => a.length));
56
+ for (let i = 0; i < head.length; i++) {
57
+ const column = columns[i];
58
+ for (let j = 0; j < longestColumn; j++) {
59
+ if (rows[j] === undefined) rows[j] = [];
60
+ const value = (rows[j][i] = Object.hasOwn(column, j) ? column[j] : "");
61
+ columnWidths[i] = Math.max(columnWidths[i] || 0, getStringWidth(value));
62
+ }
63
+ }
64
+ const divider = columnWidths.map((w) => tableChars.middleMiddle.repeat(w + 2));
65
+ let result = tableChars.topLeft + divider.join(tableChars.topMiddle) + tableChars.topRight + "\n" +
66
+ renderRow(head, columnWidths) + "\n" + tableChars.leftMiddle + divider.join(tableChars.rowMiddle) + tableChars.rightMiddle + "\n";
67
+ for (const row of rows) result += `${renderRow(row, columnWidths)}\n`;
68
+ return result + tableChars.bottomLeft + divider.join(tableChars.bottomMiddle) + tableChars.bottomRight;
69
+ }
70
+
71
+ /* "1.234ms", "1.500s", "1:02.345 (m:ss.mmm)", "1:02:03.456 (h:mm:ss.mmm)" */
72
+ function formatTime(ms) {
73
+ let hours = 0;
74
+ let minutes = 0;
75
+ let seconds = 0;
76
+ if (ms >= kSecond) {
77
+ if (ms >= kMinute) {
78
+ if (ms >= kHour) {
79
+ hours = Math.floor(ms / kHour);
80
+ ms %= kHour;
81
+ }
82
+ minutes = Math.floor(ms / kMinute);
83
+ ms %= kMinute;
84
+ }
85
+ seconds = ms / kSecond;
86
+ }
87
+ const pad = (n) => String(n).padStart(2, "0");
88
+ if (hours !== 0 || minutes !== 0) {
89
+ [seconds, ms] = seconds.toFixed(3).split(".");
90
+ const res = hours !== 0 ? `${hours}:${pad(minutes)}` : minutes;
91
+ return `${res}:${pad(seconds)}.${ms} (${hours !== 0 ? "h:m" : ""}m:ss.mmm)`;
92
+ }
93
+ if (seconds !== 0) return `${seconds.toFixed(3)}s`;
94
+ return `${Number(ms.toFixed(3))}ms`;
95
+ }
96
+
97
+ const now = () => {
98
+ const [s, ns] = process.hrtime();
99
+ return s * 1e3 + ns / 1e6;
100
+ };
101
+
102
+ /* ---- Console ---------------------------------------------------------------------------------- */
103
+
104
+ /** Console(stdout[, stderr[, ignoreErrors]]) or Console({ stdout, stderr, ignoreErrors,
105
+ * colorMode, inspectOptions, groupIndentation }). Callable without new, as Node's; its methods
106
+ * are bound, so they can be passed around. */
107
+ export function Console(options, stderr, ignoreErrors) {
108
+ if (!new.target) return Reflect.construct(Console, [options, stderr, ignoreErrors]);
109
+ if (!options || typeof options.write === "function") options = { stdout: options, stderr, ignoreErrors };
110
+ const { stdout, ignoreErrors: ignore = true, colorMode = "auto", inspectOptions, groupIndentation = 2 } = options;
111
+ const err = options.stderr || stdout;
112
+ if (!stdout || typeof stdout.write !== "function") throw codeError(TypeError, "ERR_CONSOLE_WRITABLE_STREAM", "Console expects a writable stream instance for stdout");
113
+ if (!err || typeof err.write !== "function") throw codeError(TypeError, "ERR_CONSOLE_WRITABLE_STREAM", "Console expects a writable stream instance for stderr");
114
+ if (typeof colorMode !== "boolean" && colorMode !== "auto") {
115
+ throw codeError(TypeError, "ERR_INVALID_ARG_VALUE", `The argument 'colorMode' is invalid. Received ${inspect(colorMode)}`);
116
+ }
117
+ if (typeof groupIndentation !== "number" || !Number.isInteger(groupIndentation) || groupIndentation < 0 || groupIndentation > 1000) {
118
+ throw codeError(RangeError, "ERR_OUT_OF_RANGE", `The value of "groupIndentation" is out of range. It must be >= 0 && <= 1000. Received ${groupIndentation}`);
119
+ }
120
+ if (inspectOptions !== undefined && (inspectOptions === null || typeof inspectOptions !== "object")) {
121
+ throw invalidArgType("options.inspectOptions", "of type object", inspectOptions);
122
+ }
123
+ if (inspectOptions?.colors !== undefined && colorMode !== "auto") {
124
+ throw codeError(TypeError, "ERR_INCOMPATIBLE_OPTION_PAIR", 'Option "options.inspectOptions.color" cannot be used in combination with option "colorMode"');
125
+ }
126
+ Object.defineProperties(this, {
127
+ _stdout: { value: stdout, writable: true, configurable: true },
128
+ _stderr: { value: err, writable: true, configurable: true },
129
+ _ignoreErrors: { value: Boolean(ignore), writable: true, configurable: true },
130
+ });
131
+ this[kIsConsole] = true;
132
+ this._colorMode = colorMode;
133
+ this._inspectOptions = inspectOptions;
134
+ this._groupIndent = "";
135
+ this._groupIndentation = groupIndentation;
136
+ this._counts = new Map();
137
+ this._times = new Map();
138
+ /* bound, as Node's: const { log } = console works */
139
+ for (const key of Object.keys(Console.prototype)) {
140
+ this[key] = Console.prototype[key].bind(this);
141
+ Object.defineProperty(this[key], "name", { value: key });
142
+ }
143
+ }
144
+
145
+ Object.defineProperty(Console, Symbol.hasInstance, {
146
+ value: (instance) => instance === globalThis.console || Boolean(instance?.[kIsConsole]),
147
+ });
148
+
149
+ const proto = Console.prototype;
150
+
151
+ /* a line to a stream: indented by the groups, write errors ignored unless asked not to */
152
+ proto._write = function (useStderr, string) {
153
+ const stream = useStderr ? this._stderr : this._stdout;
154
+ if (this._groupIndent.length !== 0) {
155
+ if (string.includes("\n")) string = string.replaceAll("\n", `\n${this._groupIndent}`);
156
+ string = this._groupIndent + string;
157
+ }
158
+ string += "\n";
159
+ if (!this._ignoreErrors) return stream.write(string);
160
+ try {
161
+ if (typeof stream.listenerCount === "function" && stream.listenerCount("error") === 0) stream.once("error", () => {});
162
+ stream.write(string, () => {});
163
+ } catch {
164
+ /* the console doesn't throw for its stream */
165
+ }
166
+ };
167
+ Object.defineProperty(proto, "_write", { enumerable: false });
168
+
169
+ proto._format = function (args) {
170
+ return this._inspectOptions ? formatWithOptions(this._inspectOptions, ...args) : format(...args);
171
+ };
172
+ Object.defineProperty(proto, "_format", { enumerable: false });
173
+
174
+ Object.assign(proto, {
175
+ log(...args) {
176
+ this._write(false, this._format(args));
177
+ },
178
+ warn(...args) {
179
+ this._write(true, this._format(args));
180
+ },
181
+ dir(object, options) {
182
+ this._write(false, inspect(object, { customInspect: false, ...this._inspectOptions, ...options }));
183
+ },
184
+ time(label = "default") {
185
+ label = `${label}`;
186
+ if (this._times.has(label)) {
187
+ process.emitWarning(`Label '${label}' already exists for console.time()`);
188
+ return;
189
+ }
190
+ this._times.set(label, now());
191
+ },
192
+ timeEnd(label = "default") {
193
+ label = `${label}`;
194
+ if (this._timeLog(label, "console.timeEnd()", [])) this._times.delete(label);
195
+ },
196
+ timeLog(label = "default", ...data) {
197
+ this._timeLog(`${label}`, "console.timeLog()", data);
198
+ },
199
+ trace(...args) {
200
+ this._write(true, `Trace${args.length ? ": " + this._format(args) : ""}`);
201
+ },
202
+ assert(expression, ...args) {
203
+ if (!expression) {
204
+ if (typeof args[0] === "string") args[0] = `Assertion failed: ${args[0]}`;
205
+ else args.unshift("Assertion failed");
206
+ this.warn(...args);
207
+ }
208
+ },
209
+ /* only on a terminal: the cursor home, and the screen below it cleared */
210
+ clear() {
211
+ if (this._stdout.isTTY && process.env.TERM !== "dumb") this._stdout.write("\x1b[1;1H\x1b[0J");
212
+ },
213
+ count(label = "default") {
214
+ label = `${label}`;
215
+ const count = (this._counts.get(label) ?? 0) + 1;
216
+ this._counts.set(label, count);
217
+ this.log(`${label}: ${count}`);
218
+ },
219
+ countReset(label = "default") {
220
+ label = `${label}`;
221
+ if (!this._counts.has(label)) {
222
+ process.emitWarning(`Count for '${label}' does not exist`);
223
+ return;
224
+ }
225
+ this._counts.delete(label);
226
+ },
227
+ group(...data) {
228
+ if (data.length > 0) this.log(...data);
229
+ this._groupIndent += " ".repeat(this._groupIndentation);
230
+ },
231
+ groupEnd() {
232
+ this._groupIndent = this._groupIndent.slice(0, this._groupIndent.length - this._groupIndentation);
233
+ },
234
+ table(tabularData, properties) {
235
+ if (properties !== undefined && !Array.isArray(properties)) throw invalidArgType("properties", "an instance of Array", properties);
236
+ if (tabularData === null || typeof tabularData !== "object") return this.log(tabularData);
237
+ const final = (k, v) => this.log(renderTable(k, v));
238
+ const _inspect = (v) => {
239
+ const depth = v !== null && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length > 2 ? -1 : 0;
240
+ return inspect(v, { depth, maxArrayLength: 3, breakLength: Infinity, ...this._inspectOptions });
241
+ };
242
+ const getIndexArray = (length) => Array.from({ length }, (_, i) => _inspect(i));
243
+ if (tabularData instanceof Map) {
244
+ const keys = [];
245
+ const values = [];
246
+ for (const [k, v] of tabularData) {
247
+ keys.push(_inspect(k));
248
+ values.push(_inspect(v));
249
+ }
250
+ return final(["(iteration index)", "Key", "Values"], [getIndexArray(keys.length), keys, values]);
251
+ }
252
+ if (tabularData instanceof Set || (typeof tabularData.next === "function" && typeof tabularData[Symbol.iterator] === "function")) {
253
+ const values = [];
254
+ for (const v of tabularData) values.push(_inspect(v));
255
+ return final(["(iteration index)", "Values"], [getIndexArray(values.length), values]);
256
+ }
257
+ const map = Object.create(null);
258
+ let hasPrimitives = false;
259
+ const valuesKeyArray = [];
260
+ const indexKeyArray = Object.keys(tabularData);
261
+ for (let i = 0; i < indexKeyArray.length; i++) {
262
+ const item = tabularData[indexKeyArray[i]];
263
+ const primitive = item === null || (typeof item !== "function" && typeof item !== "object");
264
+ if (properties === undefined && primitive) {
265
+ hasPrimitives = true;
266
+ valuesKeyArray[i] = _inspect(item);
267
+ } else {
268
+ const keys = properties || Object.keys(item);
269
+ for (const key of keys) {
270
+ map[key] ??= [];
271
+ if ((primitive && properties) || !Object.hasOwn(item, key)) map[key][i] = "";
272
+ else map[key][i] = _inspect(item[key]);
273
+ }
274
+ }
275
+ }
276
+ const keys = Object.keys(map);
277
+ const values = Object.values(map);
278
+ if (hasPrimitives) {
279
+ keys.push("Values");
280
+ values.push(valuesKeyArray);
281
+ }
282
+ keys.unshift("(index)");
283
+ values.unshift(indexKeyArray);
284
+ return final(keys, values);
285
+ },
286
+ /* V8 inspector APIs: nothing to report to here */
287
+ profile() {},
288
+ profileEnd() {},
289
+ timeStamp() {},
290
+ context() {
291
+ return this;
292
+ },
293
+ createTask() {
294
+ return { run: (f) => f() };
295
+ },
296
+ });
297
+ proto.debug = proto.log;
298
+ proto.info = proto.log;
299
+ proto.dirxml = proto.log;
300
+ proto.error = proto.warn;
301
+ proto.groupCollapsed = proto.group;
302
+
303
+ proto._timeLog = function (label, name, data) {
304
+ const start = this._times.get(label);
305
+ if (start === undefined) {
306
+ process.emitWarning(`No such label '${label}' for ${name}`);
307
+ return false;
308
+ }
309
+ const ms = now() - start;
310
+ this.log("%s: %s", label, formatTime(ms), ...data);
311
+ return true;
312
+ };
313
+ Object.defineProperty(proto, "_timeLog", { enumerable: false });
314
+
315
+ /* ---- the module: the global console, with Console, and the V8 extras it lacks ------------------ */
316
+
317
+ const console = globalThis.console;
318
+ for (const key of ["profile", "profileEnd", "timeStamp", "context", "createTask"]) {
319
+ if (typeof console[key] !== "function") Object.defineProperty(console, key, { value: proto[key], writable: true, configurable: true });
320
+ }
321
+ if (console.Console === undefined) Object.defineProperty(console, "Console", { value: Console, writable: true, configurable: true });
322
+
323
+ export const {
324
+ log, warn, dir, time, timeEnd, timeLog, trace, assert, clear, count, countReset, group, groupEnd, table, debug, info, dirxml, error,
325
+ groupCollapsed, profile, profileEnd, timeStamp, context, createTask,
326
+ } = console;
327
+
328
+ export default console;
@@ -0,0 +1,10 @@
1
+ // node:constants (deprecated in Node, still loaded by graceful-fs): os.constants'
2
+ // dlopen, errno, priority and signals, fs.constants and crypto.constants in one frozen object, as
3
+ // Node's lib/constants.js assigns them.
4
+ // Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
5
+ import { constants as crypto } from "./crypto.js";
6
+ import { constants as fs } from "./fs.js";
7
+ import { constants as os } from "./os.js";
8
+
9
+ const constants = Object.freeze(Object.assign({}, os.dlopen, os.errno, os.priority, os.signals, fs, crypto));
10
+ export default constants;
@@ -1,4 +1,4 @@
1
- // node:crypto (ADR 0018, layer 3): Node's API over the runtime's crypto primitives (C, on
1
+ // node:crypto: Node's API over the runtime's crypto primitives (C, on
2
2
  // BoringSSL), which Web Crypto (the `crypto` global, a runtime component) shares. What isn't
3
3
  // provided yet throws ERR_VISALJS_UNSUPPORTED when called.
4
4
  import { cryptoTimingSafeEqual } from "visaljs:host";
@@ -1,4 +1,4 @@
1
- // node:diagnostics_channel (ADR 0012, layer 3): named channels a library publishes on and tools
1
+ // node:diagnostics_channel: named channels a library publishes on and tools
2
2
  // subscribe to, and TracingChannel's start / end / asyncStart / asyncEnd / error around a call.
3
3
  // Node's algorithm: a channel with neither subscribers nor bound stores is inactive (publish does
4
4
  // nothing, hasSubscribers is false) and held weakly; subscribing swaps in ActiveChannel's
@@ -1,9 +1,9 @@
1
- // node:dns (ADR 0012, layer 3): lookup, through getaddrinfo on libuv's thread pool, as Node's
1
+ // node:dns: lookup, through getaddrinfo on libuv's thread pool, as Node's
2
2
  // is (results in the system's order, Node's default "verbatim"). Not yet: the resolve* queries
3
3
  // (c-ares) and Resolver.
4
4
  import { dnsLookup, errnoName } from "visaljs:host";
5
5
  import { bindContext } from "./internal/async_context.js";
6
- import { codeError, invalidArgType } from "./internal/errors.js";
6
+ import { codeError, invalidArgType, invalidArgValue } from "./internal/errors.js";
7
7
  import { isIP } from "./internal/net.js";
8
8
 
9
9
  /* getaddrinfo hints, and the error codes of the resolver */
@@ -66,6 +66,12 @@ export function lookup(hostname, options, callback) {
66
66
  } else if (options !== undefined && options !== null) {
67
67
  family = familyOf(options.family);
68
68
  all = options.all === true;
69
+ /* hints are checked, as Node's; getaddrinfo isn't given them */
70
+ if (options.hints != null) {
71
+ if (typeof options.hints !== "number") throw invalidArgType("options.hints", "of type number", options.hints);
72
+ const hints = options.hints >>> 0;
73
+ if ((hints & ~(ADDRCONFIG | ALL | V4MAPPED)) !== 0) throw invalidArgValue("hints", "is invalid", hints);
74
+ }
69
75
  }
70
76
  if (typeof callback !== "function") throw invalidArgType("callback", "of type function", callback);
71
77
  if (!hostname) {
@@ -0,0 +1,115 @@
1
+ // node:domain (deprecated): Domain, create and active, as Node's for what runs inside run() and
2
+ // through bind(): an error thrown there is uncaught, as in Node, and when it reaches the top the
3
+ // domain's 'error' listeners get it (process's 'uncaughtException', which domains take first);
4
+ // intercept() gives a callback's error to them. Errors from asynchronous callbacks started inside a
5
+ // domain aren't routed to it.
6
+ import { EventEmitter } from "./events.js";
7
+ import "./internal/process_events.js";
8
+
9
+ const stack = [];
10
+ export let active = null;
11
+
12
+ export class Domain extends EventEmitter {
13
+ constructor() {
14
+ super();
15
+ this.members = [];
16
+ }
17
+
18
+ enter() {
19
+ stack.push(this);
20
+ active = stack.at(-1);
21
+ process.domain = active;
22
+ }
23
+
24
+ exit() {
25
+ const index = stack.lastIndexOf(this);
26
+ if (index !== -1) stack.length = index;
27
+ active = stack.at(-1); /* undefined once the stack empties, as Node's */
28
+ process.domain = active;
29
+ }
30
+
31
+ add(emitter) {
32
+ if (emitter.domain === this) return;
33
+ if (emitter.domain) emitter.domain.remove(emitter);
34
+ emitter.domain = this;
35
+ this.members.push(emitter);
36
+ }
37
+
38
+ remove(emitter) {
39
+ emitter.domain = null;
40
+ const index = this.members.indexOf(emitter);
41
+ if (index !== -1) this.members.splice(index, 1);
42
+ }
43
+
44
+ /* an error thrown inside the domain: marked as its, and thrown on to the top */
45
+ run(fn, ...args) {
46
+ this.enter();
47
+ try {
48
+ return fn.apply(this, args);
49
+ } catch (err) {
50
+ if (err !== null && typeof err === "object" && this.listenerCount("error") > 0) {
51
+ err.domain = this;
52
+ err.domainThrown = true;
53
+ }
54
+ throw err;
55
+ } finally {
56
+ this.exit();
57
+ }
58
+ }
59
+
60
+ bind(fn) {
61
+ const run = (thisArg, args) => this.run(() => fn.apply(thisArg, args));
62
+ const bound = function (...args) {
63
+ return run(this, args);
64
+ };
65
+ bound.domain = this;
66
+ return bound;
67
+ }
68
+
69
+ /** A callback whose first argument, an error, goes to the domain instead. */
70
+ intercept(fn) {
71
+ const onError = (err) => {
72
+ if (typeof err === "object") {
73
+ err.domainBound = fn;
74
+ err.domainThrown = false;
75
+ err.domain = this;
76
+ }
77
+ this.emit("error", err);
78
+ };
79
+ const run = (thisArg, args) => this.run(() => fn.apply(thisArg, args));
80
+ const intercepted = function (err, ...args) {
81
+ if (err) return onError(err);
82
+ return run(this, args);
83
+ };
84
+ intercepted.domain = this;
85
+ return intercepted;
86
+ }
87
+
88
+ dispose() {
89
+ this.exit();
90
+ this.members.length = 0;
91
+ }
92
+ }
93
+
94
+ /* an uncaught error a domain marked: its 'error' listeners have it, and the program goes on */
95
+ const baseEmit = process.emit;
96
+ process.emit = function emit(type, ...args) {
97
+ const err = args[0];
98
+ if (type === "uncaughtException" && err?.domain instanceof Domain && err.domain.listenerCount("error") > 0) {
99
+ err.domain.emit("error", err);
100
+ return true;
101
+ }
102
+ return baseEmit.call(this, type, ...args);
103
+ };
104
+
105
+ export function create() {
106
+ return new Domain();
107
+ }
108
+ export const createDomain = create;
109
+
110
+ export default {
111
+ Domain, create, createDomain,
112
+ get active() {
113
+ return active;
114
+ },
115
+ };