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
@@ -1,4 +1,4 @@
1
- // node:net (ADR 0012, layer 3): TCP and Unix domain socket servers and sockets over the host
1
+ // node:net: TCP and Unix domain socket servers and sockets over the host
2
2
  // primitives of node/src/host_net.c (libuv), following Node's lib/net.js: a Socket is a Duplex
3
3
  // whose reads start and stop with backpressure, whose end() shuts the write side down, and which
4
4
  // closes once both sides are done (allowHalfOpen: false ends the write side when the peer's
@@ -6,17 +6,21 @@
6
6
  // for autoSelectFamilyAttemptTimeout ms (happy eyeballs, as Node's). Socket timeouts are
7
7
  // unref'd timers, refreshed by activity. SocketAddress and BlockList are in
8
8
  // internal/socketaddress.js.
9
+ // Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
9
10
  import {
10
11
  errnoMessage, errnoName, netAddress, netBind, netCallback, netChmod, netClose, netConnect, netGuessHandle, netKeepAlive, netListen,
11
- netNoDelay, netOpen, netOpenFd, netReadStart, netReadStop, netRef, netReset, netShutdown, netWrite, timerUnref,
12
+ netFd, netNoDelay, netOpen, netOpenFd, netReadStart, netReadStop, netRef, netReset, netShutdown, netWrite, timerUnref,
12
13
  } from "visaljs:host";
13
- import { lookup } from "./dns.js";
14
+ import { ADDRCONFIG, lookup } from "./dns.js";
14
15
  import { EventEmitter } from "./events.js";
15
16
  import { bindContext } from "./internal/async_context.js";
16
- import { codeError, invalidArgType, invalidArgValue, notSupported, outOfRange, validateFunction, validateString } from "./internal/errors.js";
17
+ import { codeError, invalidArgType, invalidArgValue, outOfRange, validateFunction, validateString } from "./internal/errors.js";
17
18
  import { isIP, isIPv4, isIPv6 } from "./internal/net.js";
18
19
  import { BlockList, SocketAddress } from "./internal/socketaddress.js";
20
+ import { AbortError } from "./internal/streams/errors.js";
21
+ import { validateInt32 } from "./internal/streams/validators.js";
19
22
  import { Duplex } from "./stream.js";
23
+ import { callableClass, feature, features, lazyClass, lazyFunction } from "./internal/features.js";
20
24
 
21
25
  export { BlockList, isIP, isIPv4, isIPv6, SocketAddress };
22
26
 
@@ -80,6 +84,9 @@ function validatePort(port, name = "Port", allowZero = true) {
80
84
  return +port;
81
85
  }
82
86
 
87
+ /* for internal/net_bound.js (BoundSocket) */
88
+ features.net = { errnoException, exceptionWithHostPort, validatePort };
89
+
83
90
  const toNumber = (x) => ((x = Number(x)) >= 0 ? x : false);
84
91
  const isPipeName = (s) => typeof s === "string" && toNumber(s) === false;
85
92
 
@@ -119,6 +126,7 @@ export function setDefaultAutoSelectFamilyAttemptTimeout(value) {
119
126
 
120
127
  /* a descriptor as a handle: Node's createHandle */
121
128
  function handleForFd(fd, cb) {
129
+ validateInt32(fd, "fd", 0);
122
130
  const type = netGuessHandle(fd);
123
131
  if (type !== "PIPE" && type !== "TCP") throw codeError(TypeError, "ERR_INVALID_FD_TYPE", "Unsupported fd type: " + type);
124
132
  return netOpen(type === "PIPE", bindContext(cb));
@@ -128,6 +136,14 @@ function validateBlockList(value, name) {
128
136
  if (value !== undefined && !BlockList.isBlockList(value)) throw invalidArgType(name, "an net.BlockList", value);
129
137
  }
130
138
 
139
+ /* Node's ERR_INVALID_ADDRESS_FAMILY, with the host and port */
140
+ function addressFamilyError(addressType, host, port) {
141
+ const err = codeError(RangeError, "ERR_INVALID_ADDRESS_FAMILY", "Invalid address family: " + addressType + " " + host + ":" + port);
142
+ err.host = host;
143
+ err.port = port;
144
+ return err;
145
+ }
146
+
131
147
  const ipBlocked = (ip) => codeError(Error, "ERR_IP_BLOCKED", "IP(" + ip + ") is blocked by net.BlockList");
132
148
 
133
149
  /* ---- Socket -------------------------------------------------------------------------------- */
@@ -147,13 +163,30 @@ function writeAfterFIN(chunk, encoding, cb) {
147
163
  return false;
148
164
  }
149
165
 
150
- export class Socket extends Duplex {
166
+ class SocketClass extends Duplex {
151
167
  constructor(options) {
152
168
  if (typeof options === "number") options = { fd: options };
153
169
  else options = { ...options };
170
+ if (options.objectMode) throw invalidArgValue("options.objectMode", "is not supported", options.objectMode);
171
+ if (options.readableObjectMode || options.writableObjectMode) {
172
+ const name = options.readableObjectMode ? "readableObjectMode" : "writableObjectMode";
173
+ throw invalidArgValue("options." + name, "is not supported", options[name]);
174
+ }
154
175
  /* Node's: not half-open by default, 'close' emitted by the socket itself, strings written as given */
155
176
  const allowHalfOpen = Boolean(options.allowHalfOpen);
156
- super({ ...options, allowHalfOpen, emitClose: false, autoDestroy: true, decodeStrings: false });
177
+ super({ ...options, signal: undefined, allowHalfOpen, emitClose: false, autoDestroy: true, decodeStrings: false });
178
+ /* the signal option, as Node's socket has it: aborted, the socket is destroyed with an AbortError
179
+ * (one already aborted: on the next tick, once connect() has begun) */
180
+ if (options.signal !== undefined) {
181
+ const signal = options.signal;
182
+ if (signal === null || typeof signal !== "object" || !("aborted" in signal)) throw invalidArgType("options.signal", "an instance of AbortSignal", signal);
183
+ const onAbort = () => this.destroy(new AbortError(undefined, { cause: signal.reason }));
184
+ if (signal.aborted) process.nextTick(onAbort);
185
+ else {
186
+ signal.addEventListener("abort", onAbort, { once: true });
187
+ this.once("close", () => signal.removeEventListener("abort", onAbort));
188
+ }
189
+ }
157
190
  this.connecting = false;
158
191
  this._hadError = false;
159
192
  this._handle = null; /* the host handle's id while open */
@@ -180,6 +213,12 @@ export class Socket extends Duplex {
180
213
  this._timeoutMs = 0;
181
214
  this._lastActive = 0;
182
215
  this._onread = null;
216
+ if (options.typeOfService !== undefined) feature("validateTypeOfService")(options.typeOfService);
217
+ this._tos = options.typeOfService; /* internal/net_tos.js's: the type of service, set at connect when given before it */
218
+ this._boundSource = false; /* the handle is an adopted BoundSocket's */
219
+ this._boundPath = undefined; /* an adopted pipe BoundSocket's path, its local address */
220
+ this._perfConnect = null; /* a TCP connect's start, while a PerformanceObserver takes 'net' entries */ /* set at connect when given before it */
221
+ this._onreadRest = null; /* internal/net_onread.js's: the bytes read but not yet given when reading stopped */
183
222
  this.timeout = undefined;
184
223
  this.autoSelectFamilyAttemptedAddresses = undefined;
185
224
  validateBlockList(options.blockList, "options.blockList");
@@ -187,10 +226,28 @@ export class Socket extends Duplex {
187
226
  const onread = options.onread;
188
227
  if (onread !== null && typeof onread === "object" && (typeof onread.buffer === "function" || onread.buffer instanceof Uint8Array) &&
189
228
  typeof onread.callback === "function") {
229
+ feature("onread"); /* internal/net_onread.js's */
190
230
  this._onread = onread;
191
231
  }
192
232
  this.on("end", onReadableStreamEnd);
193
- if (options.handle !== undefined) {
233
+ /* an adopted BoundSocket's handle: bound, not yet connected, so not read until it is */
234
+ const bound = options.handle !== undefined ? features.adoptBoundSocket?.(options.handle) : null;
235
+ if (bound) {
236
+ const { id, path } = bound;
237
+ this._handle = id;
238
+ this._boundSource = true;
239
+ this._isPipe = path !== undefined;
240
+ netCallback(id, bindContext((event, value) => this._onEvent(event, value, id)));
241
+ if (path !== undefined) {
242
+ this._boundPath = path;
243
+ /* a pipe's bind leaves its stream unopened: opened on its own descriptor, as Node's */
244
+ const fd = netFd(id);
245
+ if (fd >= 0) {
246
+ const err = netOpenFd(id, fd);
247
+ if (err) throw errnoException(err, "open");
248
+ }
249
+ }
250
+ } else if (options.handle !== undefined) {
194
251
  const id = options.handle;
195
252
  this._isPipe = !!options._isPipe;
196
253
  this._attach(id);
@@ -208,7 +265,7 @@ export class Socket extends Duplex {
208
265
  }
209
266
  this._attach(id);
210
267
  }
211
- if (this._handle !== null && options.readable !== false) {
268
+ if (this._handle !== null && !bound && options.readable !== false) {
212
269
  if (options.pauseOnCreate) this._readableState.flowing = false;
213
270
  else if (!options.manualStart) this.read(0);
214
271
  }
@@ -256,7 +313,7 @@ export class Socket extends Duplex {
256
313
  this._bytesRead += value.byteLength;
257
314
  this._unrefTimer();
258
315
  let more;
259
- if (this._onread) more = this._deliver(value);
316
+ if (this._onread) more = features.onread.deliver(this, value);
260
317
  else more = this.push(Buffer.from(value.buffer, value.byteOffset, value.byteLength));
261
318
  if (!more) {
262
319
  this._reading = false;
@@ -272,22 +329,31 @@ export class Socket extends Duplex {
272
329
  this.destroy(errnoException(value, "read"));
273
330
  return;
274
331
  }
332
+ if (this._onread) features.onread.eof(this);
275
333
  this.push(null);
276
334
  this.read(0);
277
335
  }
278
336
 
279
- /* onread: the bytes in the user's buffer, a buffer's worth at a time; false stops reading */
280
- _deliver(bytes) {
281
- let more = true;
282
- for (let at = 0; at < bytes.length;) {
283
- const { buffer, callback } = this._onread;
284
- const buf = typeof buffer === "function" ? buffer() : buffer;
285
- const n = Math.min(buf.length, bytes.length - at);
286
- buf.set(bytes.subarray(at, at + n));
287
- at += n;
288
- if (callback.call(this, n, buf) === false) more = false;
337
+ /* with onread, pausing stops reading from the handle and resuming starts it, as Node's */
338
+ pause() {
339
+ if (this._onread) features.onread.pause(this);
340
+ return super.pause();
341
+ }
342
+
343
+ resume() {
344
+ if (this._onread) features.onread.resume(this);
345
+ return super.resume();
346
+ }
347
+
348
+ /* reading from the handle again (with onread, the bytes left from the last read first) */
349
+ _startReading() {
350
+ this._reading = true;
351
+ if (this._onreadRest) {
352
+ features.onread.rest(this);
353
+ return;
289
354
  }
290
- return more;
355
+ const err = netReadStart(this._handle);
356
+ if (err) this.destroy(errnoException(err, "read"));
291
357
  }
292
358
 
293
359
  get pending() {
@@ -303,25 +369,36 @@ export class Socket extends Duplex {
303
369
  }
304
370
 
305
371
  get bufferSize() {
306
- return this._handle !== null ? this.writableLength : undefined;
372
+ return this._handle !== null || this.connecting ? this.writableLength : undefined;
373
+ }
374
+
375
+ get _connecting() {
376
+ return this.connecting;
307
377
  }
308
378
 
309
379
  get bytesRead() {
310
380
  return this._bytesRead;
311
381
  }
312
382
 
383
+ /* Node's: what was sent, and what's still buffered (undefined on the prototype) */
313
384
  get bytesWritten() {
385
+ const writableBuffer = this.writableBuffer;
386
+ if (!writableBuffer) return undefined;
314
387
  let bytes = this._bytesDispatched;
315
- const state = this._writableState;
316
- for (const el of state.buffered) bytes += typeof el.chunk === "string" ? Buffer.byteLength(el.chunk, el.encoding) : el.chunk.length;
388
+ for (const el of writableBuffer) bytes += typeof el.chunk === "string" ? Buffer.byteLength(el.chunk, el.encoding) : el.chunk.length;
317
389
  const data = this._pendingData;
318
- if (data) bytes += typeof data === "string" ? Buffer.byteLength(data, this._pendingEncoding) : data.length;
390
+ if (Array.isArray(data)) {
391
+ for (const el of data) bytes += typeof el.chunk === "string" ? Buffer.byteLength(el.chunk, el.encoding) : el.chunk.length;
392
+ } else if (data) {
393
+ bytes += typeof data === "string" ? Buffer.byteLength(data, this._pendingEncoding) : data.length;
394
+ }
319
395
  return bytes;
320
396
  }
321
397
 
322
- /* a pipe's ends have no address object: Node's Pipe has no getpeername/getsockname */
398
+ /* a pipe's ends have no address object: Node's Pipe has no getpeername/getsockname;
399
+ * once closed, the address read while connected */
323
400
  _getpeername() {
324
- if (this._handle === null || this._isPipe) return {};
401
+ if (this._handle === null || this._isPipe || this.connecting) return this._peername || {};
325
402
  if (!this._peername) {
326
403
  const a = netAddress(this._handle, true);
327
404
  if (typeof a === "number") return {};
@@ -331,7 +408,8 @@ export class Socket extends Duplex {
331
408
  }
332
409
 
333
410
  _getsockname() {
334
- if (this._handle === null || this._isPipe) return {};
411
+ if (this._boundPath !== undefined) return { address: this._boundPath };
412
+ if (this._handle === null || this._isPipe) return this._sockname || {};
335
413
  if (!this._sockname) {
336
414
  const a = netAddress(this._handle, false);
337
415
  if (typeof a === "number") return {};
@@ -447,11 +525,7 @@ export class Socket extends Duplex {
447
525
 
448
526
  _read(n) {
449
527
  if (this.connecting || this._handle === null) this.once("connect", () => this._read(n));
450
- else if (!this._reading) {
451
- this._reading = true;
452
- const err = netReadStart(this._handle);
453
- if (err) this.destroy(errnoException(err, "read"));
454
- }
528
+ else if (!this._reading) this._startReading();
455
529
  }
456
530
 
457
531
  /* Node's _writeGeneric: a write before the connection waits for it; a write the kernel takes at
@@ -497,7 +571,7 @@ export class Socket extends Duplex {
497
571
 
498
572
  /* end(): shut the write side down once the writes are out */
499
573
  _final(cb) {
500
- if (this.pending) {
574
+ if (this.connecting) {
501
575
  this.once("connect", () => this._final(cb));
502
576
  return;
503
577
  }
@@ -550,7 +624,7 @@ export class Socket extends Duplex {
550
624
 
551
625
  /* close with a TCP RST instead of a FIN */
552
626
  resetAndDestroy() {
553
- if (this._handle !== null) {
627
+ if (this._handle !== null || this.connecting) {
554
628
  if (this._isPipe) throw codeError(TypeError, "ERR_INVALID_HANDLE_TYPE", "This handle type cannot be sent");
555
629
  if (this.connecting) this.once("connect", () => this._reset());
556
630
  else this._reset();
@@ -573,12 +647,27 @@ export class Socket extends Duplex {
573
647
  connect(...args) {
574
648
  const [options, cb] = args[0] && args[0][normalizedArgs] ? args[0] : normalizeArgs(args);
575
649
  if (this.write !== Socket.prototype.write) this.write = Socket.prototype.write;
576
- if (this.destroyed) throw notSupported("reconnecting a destroyed socket");
650
+ if (options.port === undefined && options.path == null) {
651
+ throw codeError(TypeError, "ERR_MISSING_ARGS", 'The "options" or "port" or "path" argument must be specified');
652
+ }
653
+ /* a closed socket connects again, as Node's: its streams undestroyed, its counts the new handle's */
654
+ if (this.destroyed) {
655
+ this._handle = null;
656
+ this._peername = null;
657
+ this._sockname = null;
658
+ this._bytesRead = 0;
659
+ this._bytesDispatched = 0;
660
+ this._hadError = false;
661
+ this._perfConnect = null;
662
+ this._undestroy();
663
+ }
577
664
  const { path } = options;
578
665
  if (cb !== null) this.once("connect", cb);
579
666
  this._unrefTimer();
580
667
  this.connecting = true;
581
- if (path) {
668
+ /* an adopted handle is a pipe or not whatever the options say; once it's gone, the path does */
669
+ const pipe = this._boundSource && this._handle !== null ? this._isPipe : !!path;
670
+ if (pipe) {
582
671
  validateString(path, "options.path");
583
672
  this._isPipe = true;
584
673
  this._internalConnect(path);
@@ -593,23 +682,37 @@ export class Socket extends Duplex {
593
682
  const host = options.host || "localhost";
594
683
  let { port, autoSelectFamilyAttemptTimeout: attemptTimeout, autoSelectFamily: selectFamily } = options;
595
684
  if (localAddress && !isIP(localAddress)) throw codeError(TypeError, "ERR_INVALID_IP_ADDRESS", "Invalid IP address: " + localAddress);
596
- if (localPort !== undefined && typeof localPort !== "number") throw invalidArgType("options.localPort", "of type number", localPort);
685
+ if (localPort && typeof localPort !== "number") throw invalidArgType("options.localPort", "of type number", localPort);
597
686
  if (typeof host !== "string") throw invalidArgType("options.host", "of type string", host);
687
+ if (host.includes("\0")) throw invalidArgValue("options.host", "must be a string without null bytes", host);
688
+ /* an adopted BoundSocket owns the local end and the address family */
689
+ if (this._boundSource) {
690
+ if (localAddress !== undefined || localPort !== undefined) {
691
+ throw invalidArgValue("options", "localAddress and localPort cannot be used with an adopted bound socket", options);
692
+ }
693
+ selectFamily = false;
694
+ }
598
695
  if (typeof port !== "undefined") {
599
696
  if (typeof port !== "number" && typeof port !== "string") throw invalidArgType("options.port", "of type number or string", port);
600
697
  port = validatePort(port);
601
698
  }
602
699
  port |= 0;
603
- if (selectFamily !== undefined && typeof selectFamily !== "boolean") throw invalidArgType("options.autoSelectFamily", "of type boolean", selectFamily);
700
+ if (selectFamily != null && typeof selectFamily !== "boolean") throw invalidArgType("options.autoSelectFamily", "of type boolean", selectFamily);
604
701
  selectFamily ??= autoSelectFamily;
605
- if (attemptTimeout !== undefined) {
606
- if (typeof attemptTimeout !== "number") throw invalidArgType("options.autoSelectFamilyAttemptTimeout", "of type number", attemptTimeout);
702
+ if (attemptTimeout != null) {
703
+ validateInt32(attemptTimeout, "options.autoSelectFamilyAttemptTimeout", 1);
607
704
  if (attemptTimeout < 10) attemptTimeout = 10;
608
705
  } else {
609
706
  attemptTimeout = autoSelectFamilyAttemptTimeout;
610
707
  }
611
708
  this._host = host;
612
709
  const addressType = isIP(host);
710
+ /* an adopted BoundSocket connects in this tick, so its local address is known at once (a
711
+ * failure still comes as an 'error' event) */
712
+ if (addressType && this._boundSource) {
713
+ this._internalConnect(host, port, addressType, localAddress, localPort);
714
+ return;
715
+ }
613
716
  if (addressType) {
614
717
  process.nextTick(() => {
615
718
  if (this.connecting) this._internalConnect(host, port, addressType, localAddress, localPort);
@@ -619,17 +722,19 @@ export class Socket extends Duplex {
619
722
  let family = options.family ?? 0;
620
723
  if (family === "IPv4") family = 4;
621
724
  else if (family === "IPv6") family = 6;
622
- const dnsopts = { family, all: selectFamily && family === 0 };
623
725
  const lookupFn = options.lookup ?? lookup;
624
726
  if (typeof lookupFn !== "function") throw invalidArgType("options.lookup", "of type function", lookupFn);
727
+ const dnsopts = { family, hints: options.hints || 0, all: false };
728
+ if (process.platform !== "win32" && family !== 4 && family !== 6 && dnsopts.hints === 0) dnsopts.hints = ADDRCONFIG;
729
+ dnsopts.all = family !== 4 && family !== 6 && !localAddress && selectFamily;
625
730
  if (!dnsopts.all) {
626
731
  lookupFn(host, dnsopts, (err, ip, addressType) => {
627
732
  this.emit("lookup", err, ip, addressType, host);
628
733
  if (!this.connecting) return;
629
734
  if (err) process.nextTick(() => this.destroy(err));
630
- else if (!isIP(ip)) process.nextTick(() => this.destroy(codeError(TypeError, "ERR_INVALID_IP_ADDRESS", "Invalid IP address: " + ip)));
735
+ else if (typeof ip !== "string" || !isIP(ip)) process.nextTick(() => this.destroy(codeError(TypeError, "ERR_INVALID_IP_ADDRESS", "Invalid IP address: " + ip)));
631
736
  else if (addressType !== 4 && addressType !== 6) {
632
- process.nextTick(() => this.destroy(codeError(TypeError, "ERR_INVALID_ADDRESS_FAMILY", "Invalid address family: " + addressType + " " + host + ":" + port)));
737
+ process.nextTick(() => this.destroy(addressFamilyError(addressType, host, options.port)));
633
738
  } else {
634
739
  this._unrefTimer();
635
740
  this._internalConnect(ip, port, addressType, localAddress, localPort);
@@ -660,7 +765,7 @@ export class Socket extends Duplex {
660
765
  const first = addresses[0];
661
766
  const error = !first || !isIP(first.address)
662
767
  ? codeError(TypeError, "ERR_INVALID_IP_ADDRESS", "Invalid IP address: " + first?.address)
663
- : codeError(TypeError, "ERR_INVALID_ADDRESS_FAMILY", "Invalid address family: " + first.family + " " + host + ":" + port);
768
+ : addressFamilyError(first.family, host, options.port);
664
769
  process.nextTick(() => this.destroy(error));
665
770
  return;
666
771
  }
@@ -686,14 +791,23 @@ export class Socket extends Duplex {
686
791
  /* a new handle bound to the local address, if any, and connecting: 0 or the failure as Node reports it */
687
792
  _open(address, port, addressType, localAddress, localPort, onConnect) {
688
793
  let id;
689
- id = netOpen(this._isPipe, bindContext((event, value) => {
794
+ const cb = bindContext((event, value) => {
690
795
  if (event === NET_CONNECT) {
691
796
  if (this._handle === id) onConnect(value, id);
692
797
  } else {
693
798
  this._onEvent(event, value, id);
694
799
  }
695
- }));
696
- this._handle = id;
800
+ });
801
+ if (this._boundSource && this._handle !== null) { /* an adopted BoundSocket's, already bound */
802
+ id = this._handle;
803
+ netCallback(id, cb);
804
+ } else {
805
+ id = netOpen(this._isPipe, cb);
806
+ this._handle = id;
807
+ }
808
+ if (!this._isPipe && this._perfConnect === null && features.perfObserving?.("net")) {
809
+ this._perfConnect = { start: features.perfNow(), host: address, port };
810
+ }
697
811
  if (!this._isPipe && (localAddress || localPort)) {
698
812
  localAddress ||= addressType === 4 ? "0.0.0.0" : "::";
699
813
  const err = netBind(id, localAddress, localPort | 0, 0);
@@ -779,17 +893,27 @@ export class Socket extends Duplex {
779
893
  }
780
894
  this._attach(this._handle);
781
895
  this._unrefTimer();
896
+ if (this._perfConnect !== null) {
897
+ const { start, host, port } = this._perfConnect;
898
+ this._perfConnect = null;
899
+ features.perfObserve(features.perfEntry("connect", "net", start, features.perfNow() - start, { host, port }));
900
+ }
901
+ if (this._tos !== undefined && !this._isPipe) features.applyTypeOfService(this);
782
902
  this.emit("connect");
783
903
  this.emit("ready");
784
904
  if (this.readable && !this.isPaused()) this.read(0);
785
905
  }
786
906
  }
907
+ /* internal/net_tos.js's, linked when the program names them */
908
+ SocketClass.prototype.setTypeOfService = lazyFunction("setTypeOfService", 1);
909
+ SocketClass.prototype.getTypeOfService = lazyFunction("getTypeOfService");
910
+ export const Socket = callableClass(SocketClass, "Socket"); /* Socket(…) without new, as Node's */
787
911
 
788
912
  export const Stream = Socket;
789
913
 
790
914
  /* ---- Server -------------------------------------------------------------------------------- */
791
915
 
792
- export class Server extends EventEmitter {
916
+ class ServerClass extends EventEmitter {
793
917
  constructor(options, connectionListener) {
794
918
  super();
795
919
  if (typeof options === "function") {
@@ -802,6 +926,7 @@ export class Server extends EventEmitter {
802
926
  }
803
927
  if (typeof connectionListener === "function") this.on("connection", connectionListener);
804
928
  this._connections = 0;
929
+ this._listeningId = 1; /* a listen or close since a lookup began makes the lookup's result stale */
805
930
  this._handle = null;
806
931
  this._isPipe = false;
807
932
  this._pipeName = undefined;
@@ -826,7 +951,16 @@ export class Server extends EventEmitter {
826
951
  if (typeof options.callback === "function") cb = options.callback;
827
952
  if (this._handle !== null) throw codeError(Error, "ERR_SERVER_ALREADY_LISTEN", "Listen method has been called more than once without closing.");
828
953
  if (cb !== null) this.once("listening", cb);
954
+ this._listeningId++;
829
955
  const backlogFromArgs = toNumber(args.length > 1 && args[1]) || toNumber(args.length > 2 && args[2]);
956
+ /* listen(boundSocket) or listen({ handle: boundSocket }): the server takes its handle */
957
+ const bound = features.adoptBoundSocket?.(options) ?? features.adoptBoundSocket?.(options.handle);
958
+ if (bound) {
959
+ if (bound.path !== undefined) this._pipeName = bound.path;
960
+ this._isPipe = bound.path !== undefined;
961
+ this._setupListen(null, -1, -1, backlogFromArgs, undefined, 0, bound.id);
962
+ return this;
963
+ }
830
964
  if (options._handle !== undefined && options._handle !== null) options = options._handle;
831
965
  else if (options.handle !== undefined && options.handle !== null) options = options.handle;
832
966
  const flags = (options.ipv6Only ? 1 : 0) | (options.reusePort ? 2 : 0);
@@ -879,7 +1013,9 @@ export class Server extends EventEmitter {
879
1013
  }
880
1014
 
881
1015
  _lookupAndListen(port, address, backlog, flags) {
1016
+ const listeningId = this._listeningId;
882
1017
  lookup(address, (err, ip, addressType) => {
1018
+ if (listeningId !== this._listeningId) return;
883
1019
  if (err) this.emit("error", err);
884
1020
  else this._setupListen(ip, port, ip ? addressType : 4, backlog, undefined, flags);
885
1021
  });
@@ -969,6 +1105,7 @@ export class Server extends EventEmitter {
969
1105
  process.nextTick(() => this.emit("error", ex));
970
1106
  return;
971
1107
  }
1108
+ this._connectionKey = addressType + ":" + address + ":" + port;
972
1109
  if (this._unref) netRef(id, false);
973
1110
  process.nextTick(() => {
974
1111
  if (this._handle !== null) this.emit("listening");
@@ -1023,6 +1160,7 @@ export class Server extends EventEmitter {
1023
1160
 
1024
1161
  /* close([cb]): stop accepting; 'close' once the open connections end too */
1025
1162
  close(cb) {
1163
+ this._listeningId++;
1026
1164
  if (typeof cb === "function") {
1027
1165
  if (this._handle === null) this.once("close", () => cb(codeError(Error, "ERR_SERVER_NOT_RUNNING", "Server is not running.")));
1028
1166
  else this.once("close", cb);
@@ -1035,6 +1173,12 @@ export class Server extends EventEmitter {
1035
1173
  return this;
1036
1174
  }
1037
1175
 
1176
+ /* captureRejections: a 'connection' listener's rejection destroys the socket, as Node's */
1177
+ [Symbol.for("nodejs.rejection")](err, event, sock) {
1178
+ if (event === "connection") sock.destroy(err);
1179
+ else this.emit("error", err);
1180
+ }
1181
+
1038
1182
  _emitCloseIfDrained() {
1039
1183
  if (this._handle !== null || this._connections) return;
1040
1184
  process.nextTick(() => this.emit("close"));
@@ -1062,6 +1206,7 @@ export class Server extends EventEmitter {
1062
1206
  return new Promise((resolve, reject) => this.close((err) => (err ? reject(err) : resolve())));
1063
1207
  }
1064
1208
  }
1209
+ export const Server = callableClass(ServerClass, "Server"); /* Server(…) without new, as Node's */
1065
1210
 
1066
1211
  export function createServer(options, connectionListener) {
1067
1212
  return new Server(options, connectionListener);
@@ -1078,7 +1223,10 @@ export function connect(...args) {
1078
1223
 
1079
1224
  export const createConnection = connect;
1080
1225
 
1226
+ /* internal/net_bound.js's, linked when the program names it */
1227
+ export const BoundSocket = lazyClass("BoundSocket");
1228
+
1081
1229
  export default {
1082
- BlockList, SocketAddress, isIP, isIPv4, isIPv6, Socket, Stream, Server, connect, createConnection, createServer,
1230
+ BlockList, BoundSocket, SocketAddress, isIP, isIPv4, isIPv6, Socket, Stream, Server, connect, createConnection, createServer,
1083
1231
  getDefaultAutoSelectFamily, setDefaultAutoSelectFamily, getDefaultAutoSelectFamilyAttemptTimeout, setDefaultAutoSelectFamilyAttemptTimeout,
1084
1232
  };
@@ -1,13 +1,26 @@
1
- // node:os (ADR 0012, layer 3): the system's facts through libuv, as Node's lib/os.js gets them,
2
- // and the constants of the platform the program was built for. Not provided yet:
3
- // networkInterfaces, getPriority and setPriority (ERR_VISALJS_UNSUPPORTED).
1
+ // node:os: the system's facts through libuv, as Node's lib/os.js gets them,
2
+ // and the constants of the platform the program was built for.
3
+ // Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
4
4
  import {
5
- osConstants, osCpus, osHomedir, osHostname, osLoadavg, osMemory, osParallelism, osTmpdir, osUname, osUptime, osUserInfo,
5
+ errnoMessage, errnoName, osConstants, osCpus, osGetPriority, osHomedir, osHostname, osInterfaces, osLoadavg, osMemory, osParallelism,
6
+ osSetPriority, osTmpdir, osUname, osUptime, osUserInfo,
6
7
  } from "visaljs:host";
7
- import { notSupported, systemError } from "./internal/errors.js";
8
+ import { codeError, invalidArgType } from "./internal/errors.js";
9
+
10
+ /* Node's SystemError (ERR_SYSTEM_ERROR): "A system error occurred: uv_os_getpriority returned ESRCH
11
+ * (no such process)", with errno, code, syscall and info */
12
+ function osError(errno, syscall) {
13
+ const code = errnoName(errno), message = errnoMessage(errno);
14
+ const e = codeError(Error, "ERR_SYSTEM_ERROR", `A system error occurred: ${syscall} returned ${code} (${message})`);
15
+ e.name = "SystemError";
16
+ e.errno = errno;
17
+ e.syscall = syscall;
18
+ e.info = { errno, code, message, syscall };
19
+ return e;
20
+ }
8
21
 
9
22
  const check = (result, syscall) => {
10
- if (typeof result === "number" && result < 0) throw systemError(result, syscall);
23
+ if (typeof result === "number" && result < 0) throw osError(result, syscall);
11
24
  return result;
12
25
  };
13
26
  const uname = () => check(osUname(), "uv_os_uname");
@@ -89,16 +102,80 @@ export function userInfo(options) {
89
102
  return { uid, gid, username: enc(username), homedir: enc(home), shell: enc(shell) };
90
103
  }
91
104
 
105
+ /* the prefix length of a contiguous netmask, else null (Node's getCIDR) */
106
+ function cidrOf(address, netmask, family) {
107
+ let ones = 0, run = true;
108
+ if (family === "IPv4") {
109
+ for (const part of netmask.split(".")) {
110
+ for (let bit = 7; bit >= 0; bit--) {
111
+ if ((Number(part) >> bit) & 1) {
112
+ if (!run) return null;
113
+ ones++;
114
+ } else run = false;
115
+ }
116
+ }
117
+ } else {
118
+ const groups = expandIPv6(netmask);
119
+ for (const group of groups) {
120
+ for (let bit = 15; bit >= 0; bit--) {
121
+ if ((group >> bit) & 1) {
122
+ if (!run) return null;
123
+ ones++;
124
+ } else run = false;
125
+ }
126
+ }
127
+ }
128
+ return `${address}/${ones}`;
129
+ }
130
+
131
+ /* an IPv6 address's eight groups, :: expanded */
132
+ function expandIPv6(address) {
133
+ const [head, tail] = address.includes("::") ? address.split("::") : [address, undefined];
134
+ const parse = (s) => (s ? s.split(":").map((g) => parseInt(g, 16)) : []);
135
+ const left = parse(head), right = parse(tail);
136
+ return tail === undefined ? left : [...left, ...new Array(8 - left.length - right.length).fill(0), ...right];
137
+ }
138
+
139
+ /** The network interfaces and their addresses: name → [{ address, netmask, family, mac, internal,
140
+ * cidr, scopeid (IPv6) }], as libuv lists them. */
92
141
  export function networkInterfaces() {
93
- throw notSupported("os.networkInterfaces");
142
+ const flat = check(osInterfaces(), "uv_interface_addresses");
143
+ const result = {};
144
+ for (let i = 0; i < flat.length; i += 7) {
145
+ const [name, address, netmask, family, mac, internal, scopeid] = flat.slice(i, i + 7);
146
+ const entry = { address, netmask, family: family === 4 ? "IPv4" : "IPv6", mac, internal, cidr: null };
147
+ entry.cidr = cidrOf(address, netmask, entry.family);
148
+ if (family === 6) entry.scopeid = scopeid;
149
+ (result[name] ??= []).push(entry);
150
+ }
151
+ return result;
152
+ }
153
+
154
+ function validatePid(pid) {
155
+ if (typeof pid !== "number") throw invalidArgType("pid", "of type number", pid);
156
+ if (!Number.isInteger(pid) || pid < -2147483648 || pid > 2147483647) {
157
+ throw codeError(RangeError, "ERR_OUT_OF_RANGE", `The value of "pid" is out of range. It must be an integer. Received ${pid}`);
158
+ }
94
159
  }
95
160
 
96
- export function getPriority() {
97
- throw notSupported("os.getPriority");
161
+ /** A process's scheduling priority (0: this one). */
162
+ export function getPriority(pid = 0) {
163
+ validatePid(pid);
164
+ return check(osGetPriority(pid), "uv_os_getpriority");
98
165
  }
99
166
 
100
- export function setPriority() {
101
- throw notSupported("os.setPriority");
167
+ /** setPriority([pid,] priority): -20 (highest) to 19 (lowest). */
168
+ export function setPriority(pid, priority) {
169
+ if (priority === undefined) {
170
+ priority = pid;
171
+ pid = 0;
172
+ }
173
+ validatePid(pid);
174
+ if (typeof priority !== "number") throw invalidArgType("priority", "of type number", priority);
175
+ if (!Number.isInteger(priority) || priority < -20 || priority > 19) {
176
+ throw codeError(RangeError, "ERR_OUT_OF_RANGE", `The value of "priority" is out of range. It must be >= -20 && <= 19. Received ${priority}`);
177
+ }
178
+ check(osSetPriority(pid, priority), "uv_os_setpriority");
102
179
  }
103
180
 
104
181
  function nameTable(flat) {