visaljs 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (428) hide show
  1. package/README.md +63 -2
  2. package/THIRD_PARTY_LICENSES +1216 -0
  3. package/cli.js +4413 -324
  4. package/node/include/js_node.h +57 -1
  5. package/node/include/js_uv.h +8 -1
  6. package/node/prelude/_stream_duplex.js +4 -0
  7. package/node/prelude/_stream_passthrough.js +4 -0
  8. package/node/prelude/_stream_readable.js +4 -0
  9. package/node/prelude/_stream_transform.js +4 -0
  10. package/node/prelude/_stream_writable.js +4 -0
  11. package/node/prelude/assert.js +1334 -0
  12. package/node/prelude/assert_strict.js +12 -0
  13. package/node/prelude/async_hooks.js +1 -1
  14. package/node/prelude/buffer.js +43 -3
  15. package/node/prelude/child_process.js +1098 -0
  16. package/node/prelude/cluster.js +52 -0
  17. package/node/prelude/console.js +328 -0
  18. package/node/prelude/constants.js +10 -0
  19. package/node/prelude/crypto.js +1 -1
  20. package/node/prelude/diagnostics_channel.js +1 -1
  21. package/node/prelude/dns.js +1 -1
  22. package/node/prelude/domain.js +115 -0
  23. package/node/prelude/events.js +144 -16
  24. package/node/prelude/fs.js +1138 -151
  25. package/node/prelude/fs_promises.js +117 -11
  26. package/node/prelude/http.js +104 -27
  27. package/node/prelude/http2.js +1 -1
  28. package/node/prelude/https.js +148 -0
  29. package/node/prelude/inspector.js +27 -0
  30. package/node/prelude/inspector_promises.js +4 -0
  31. package/node/prelude/internal/async_context.js +1 -1
  32. package/node/prelude/internal/buffer_transcode.js +44 -0
  33. package/node/prelude/internal/comparisons.js +916 -0
  34. package/node/prelude/internal/compression_streams.js +153 -0
  35. package/node/prelude/internal/crypto/asym.js +27 -14
  36. package/node/prelude/internal/crypto/cipher.js +16 -5
  37. package/node/prelude/internal/crypto/diffiehellman.js +3 -2
  38. package/node/prelude/internal/crypto/hash.js +2 -1
  39. package/node/prelude/internal/crypto/kdf.js +14 -9
  40. package/node/prelude/internal/crypto/keys.js +63 -50
  41. package/node/prelude/internal/crypto/random.js +2 -1
  42. package/node/prelude/internal/crypto/util.js +4 -4
  43. package/node/prelude/internal/dotenv.js +98 -0
  44. package/node/prelude/internal/errors.js +21 -5
  45. package/node/prelude/internal/events_extras.js +116 -0
  46. package/node/prelude/internal/events_on.js +100 -0
  47. package/node/prelude/internal/features.js +55 -0
  48. package/node/prelude/internal/fetch.js +364 -0
  49. package/node/prelude/internal/form_data.js +376 -0
  50. package/node/prelude/internal/fs_bigint_stats.js +41 -0
  51. package/node/prelude/internal/fs_blob.js +19 -0
  52. package/node/prelude/internal/fs_cp.js +709 -0
  53. package/node/prelude/internal/fs_dir.js +166 -0
  54. package/node/prelude/internal/fs_filehandle.js +287 -0
  55. package/node/prelude/internal/fs_glob.js +296 -0
  56. package/node/prelude/internal/fs_statfs.js +42 -0
  57. package/node/prelude/internal/fs_stats.js +89 -0
  58. package/node/prelude/internal/fs_streams.js +541 -0
  59. package/node/prelude/internal/fs_utils.js +286 -0
  60. package/node/prelude/internal/fs_watch.js +580 -0
  61. package/node/prelude/internal/http_agent.js +26 -0
  62. package/node/prelude/internal/mime.js +249 -0
  63. package/node/prelude/internal/net.js +1 -0
  64. package/node/prelude/internal/parse_args.js +288 -0
  65. package/node/prelude/internal/perf_histogram.js +435 -0
  66. package/node/prelude/internal/perf_observe.js +119 -0
  67. package/node/prelude/internal/performance_global.js +19 -0
  68. package/node/prelude/internal/process_events.js +49 -1
  69. package/node/prelude/internal/process_memory.js +14 -0
  70. package/node/prelude/internal/process_more.js +414 -0
  71. package/node/prelude/internal/process_signals.js +2 -1
  72. package/node/prelude/internal/process_stdin.js +52 -0
  73. package/node/prelude/internal/process_stdio.js +36 -0
  74. package/node/prelude/internal/querystring.js +0 -0
  75. package/node/prelude/internal/readline.js +338 -0
  76. package/node/prelude/internal/socketaddress.js +8 -4
  77. package/node/prelude/internal/source_map.js +122 -0
  78. package/node/prelude/internal/stream_compose.js +74 -0
  79. package/node/prelude/internal/stream_from.js +6 -0
  80. package/node/prelude/internal/stream_operators.js +23 -0
  81. package/node/prelude/internal/stream_pipeline.js +7 -0
  82. package/node/prelude/internal/stream_transform.js +10 -0
  83. package/node/prelude/internal/stream_web_adapters.js +143 -0
  84. package/node/prelude/internal/streams/add_abort_signal.js +58 -0
  85. package/node/prelude/internal/streams/compose.js +244 -0
  86. package/node/prelude/internal/streams/destroy.js +358 -0
  87. package/node/prelude/internal/streams/duplex.js +199 -0
  88. package/node/prelude/internal/streams/duplexify.js +378 -0
  89. package/node/prelude/internal/streams/end_of_stream.js +387 -0
  90. package/node/prelude/internal/streams/errors.js +216 -0
  91. package/node/prelude/internal/streams/from.js +211 -0
  92. package/node/prelude/internal/streams/legacy.js +120 -0
  93. package/node/prelude/internal/streams/operators.js +375 -0
  94. package/node/prelude/internal/streams/passthrough.js +45 -0
  95. package/node/prelude/internal/streams/pipeline.js +468 -0
  96. package/node/prelude/internal/streams/readable.js +1835 -0
  97. package/node/prelude/internal/streams/state.js +48 -0
  98. package/node/prelude/internal/streams/transform.js +203 -0
  99. package/node/prelude/internal/streams/utils.js +355 -0
  100. package/node/prelude/internal/streams/validators.js +108 -0
  101. package/node/prelude/internal/streams/writable.js +1160 -0
  102. package/node/prelude/internal/structured_clone.js +238 -0
  103. package/node/prelude/internal/system_errors.js +37 -0
  104. package/node/prelude/internal/test_runner/mock.js +431 -0
  105. package/node/prelude/internal/test_runner/reporters.js +404 -0
  106. package/node/prelude/internal/test_runner/test.js +1571 -0
  107. package/node/prelude/internal/timers.js +38 -7
  108. package/node/prelude/internal/timers_global.js +1 -1
  109. package/node/prelude/internal/tls/common.js +8 -2
  110. package/node/prelude/internal/tls/wrap.js +3 -15
  111. package/node/prelude/internal/tls/x509.js +1 -1
  112. package/node/prelude/internal/tty_read_stream.js +39 -0
  113. package/node/prelude/internal/tty_streams.js +3 -0
  114. package/node/prelude/internal/util_debuglog.js +68 -0
  115. package/node/prelude/internal/util_diff.js +63 -0
  116. package/node/prelude/internal/util_more.js +111 -0
  117. package/node/prelude/internal/util_styles.js +76 -0
  118. package/node/prelude/internal/zlib_engines.js +1 -1
  119. package/node/prelude/module.js +194 -7
  120. package/node/prelude/net.js +2 -1
  121. package/node/prelude/os.js +88 -11
  122. package/node/prelude/path.js +11 -7
  123. package/node/prelude/path_posix.js +1 -1
  124. package/node/prelude/path_win32.js +1 -1
  125. package/node/prelude/perf_hooks.js +147 -0
  126. package/node/prelude/process.js +36 -1
  127. package/node/prelude/punycode.js +188 -0
  128. package/node/prelude/querystring.js +1 -1
  129. package/node/prelude/readline.js +8 -0
  130. package/node/prelude/readline_promises.js +88 -0
  131. package/node/prelude/repl.js +38 -0
  132. package/node/prelude/sea.js +23 -0
  133. package/node/prelude/stream.js +70 -1332
  134. package/node/prelude/stream_consumers.js +34 -0
  135. package/node/prelude/stream_promises.js +1 -1
  136. package/node/prelude/stream_web.js +15 -2
  137. package/node/prelude/string_decoder.js +1 -1
  138. package/node/prelude/sys.js +7 -0
  139. package/node/prelude/test.js +56 -0
  140. package/node/prelude/test_reporters.js +269 -0
  141. package/node/prelude/timers.js +7 -84
  142. package/node/prelude/timers_promises.js +1 -1
  143. package/node/prelude/tls.js +2 -1
  144. package/node/prelude/trace_events.js +52 -0
  145. package/node/prelude/tty.js +10 -4
  146. package/node/prelude/url.js +88 -27
  147. package/node/prelude/util.js +121 -5
  148. package/node/prelude/util_types.js +4 -3
  149. package/node/prelude/v8.js +814 -0
  150. package/node/prelude/vm.js +86 -0
  151. package/node/prelude/wasi.js +10 -0
  152. package/node/prelude/worker_threads.js +56 -0
  153. package/node/prelude/zlib.js +58 -25
  154. package/node/src/host_brotli.c +59 -11
  155. package/node/src/host_fs.c +342 -11
  156. package/node/src/host_fswatch.c +170 -0
  157. package/node/src/host_http.c +143 -20
  158. package/node/src/host_loop.c +25 -2
  159. package/node/src/host_net.c +55 -7
  160. package/node/src/host_os.c +55 -1
  161. package/node/src/host_proc.c +291 -0
  162. package/node/src/host_process.c +488 -0
  163. package/node/src/host_sys.c +64 -2
  164. package/node/src/host_zlib.c +27 -7
  165. package/node/src/host_zstd.c +41 -6
  166. package/node/third_party/hdrhistogram/LICENSE +42 -0
  167. package/node/third_party/hdrhistogram/README.md +5 -0
  168. package/node/third_party/libuv/LICENSE +0 -0
  169. package/node/third_party/libuv/LICENSE-extra +36 -0
  170. package/node/third_party/libuv/include/uv/aix.h +0 -0
  171. package/node/third_party/libuv/include/uv/bsd.h +0 -0
  172. package/node/third_party/libuv/include/uv/darwin.h +0 -0
  173. package/node/third_party/libuv/include/uv/errno.h +0 -0
  174. package/node/third_party/libuv/include/uv/linux.h +0 -0
  175. package/node/third_party/libuv/include/uv/os390.h +0 -0
  176. package/node/third_party/libuv/include/uv/posix.h +0 -0
  177. package/node/third_party/libuv/include/uv/sunos.h +0 -0
  178. package/node/third_party/libuv/include/uv/threadpool.h +0 -0
  179. package/node/third_party/libuv/include/uv/tree.h +0 -0
  180. package/node/third_party/libuv/include/uv/unix.h +0 -0
  181. package/node/third_party/libuv/include/uv/version.h +0 -0
  182. package/node/third_party/libuv/include/uv/win.h +0 -0
  183. package/node/third_party/libuv/include/uv.h +0 -0
  184. package/node/third_party/libuv/src/fs-poll.c +0 -0
  185. package/node/third_party/libuv/src/heap-inl.h +0 -0
  186. package/node/third_party/libuv/src/idna.c +0 -0
  187. package/node/third_party/libuv/src/idna.h +0 -0
  188. package/node/third_party/libuv/src/inet.c +0 -0
  189. package/node/third_party/libuv/src/queue.h +0 -0
  190. package/node/third_party/libuv/src/random.c +0 -0
  191. package/node/third_party/libuv/src/strscpy.c +0 -0
  192. package/node/third_party/libuv/src/strscpy.h +0 -0
  193. package/node/third_party/libuv/src/strtok.c +0 -0
  194. package/node/third_party/libuv/src/strtok.h +0 -0
  195. package/node/third_party/libuv/src/thread-common.c +0 -0
  196. package/node/third_party/libuv/src/threadpool.c +0 -0
  197. package/node/third_party/libuv/src/timer.c +0 -0
  198. package/node/third_party/libuv/src/unix/async.c +0 -0
  199. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
  200. package/node/third_party/libuv/src/unix/core.c +0 -0
  201. package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
  202. package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
  203. package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
  204. package/node/third_party/libuv/src/unix/darwin.c +0 -0
  205. package/node/third_party/libuv/src/unix/dl.c +0 -0
  206. package/node/third_party/libuv/src/unix/fs.c +0 -0
  207. package/node/third_party/libuv/src/unix/fsevents.c +0 -0
  208. package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
  209. package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
  210. package/node/third_party/libuv/src/unix/internal.h +0 -0
  211. package/node/third_party/libuv/src/unix/kqueue.c +0 -0
  212. package/node/third_party/libuv/src/unix/linux.c +0 -0
  213. package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
  214. package/node/third_party/libuv/src/unix/loop.c +0 -0
  215. package/node/third_party/libuv/src/unix/pipe.c +0 -0
  216. package/node/third_party/libuv/src/unix/poll.c +0 -0
  217. package/node/third_party/libuv/src/unix/process.c +0 -0
  218. package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
  219. package/node/third_party/libuv/src/unix/proctitle.c +0 -0
  220. package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
  221. package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
  222. package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
  223. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
  224. package/node/third_party/libuv/src/unix/signal.c +0 -0
  225. package/node/third_party/libuv/src/unix/stream.c +0 -0
  226. package/node/third_party/libuv/src/unix/tcp.c +0 -0
  227. package/node/third_party/libuv/src/unix/thread.c +0 -0
  228. package/node/third_party/libuv/src/unix/tty.c +0 -0
  229. package/node/third_party/libuv/src/unix/udp.c +0 -0
  230. package/node/third_party/libuv/src/uv-common.c +0 -0
  231. package/node/third_party/libuv/src/uv-common.h +0 -0
  232. package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
  233. package/node/third_party/libuv/src/version.c +0 -0
  234. package/node/third_party/llhttp/LICENSE +0 -0
  235. package/node/third_party/llhttp/api.c +0 -0
  236. package/node/third_party/llhttp/http.c +0 -0
  237. package/node/third_party/llhttp/llhttp.c +0 -0
  238. package/node/third_party/llhttp/llhttp.h +0 -0
  239. package/node/third_party/nodejs/LICENSE +47 -0
  240. package/node/third_party/nodejs/README.md +5 -0
  241. package/node/third_party/parseargs/LICENSE +21 -0
  242. package/node/third_party/parseargs/README.md +5 -0
  243. package/node/third_party/punycode/LICENSE +20 -0
  244. package/node/third_party/punycode/README.md +5 -0
  245. package/node/third_party/zlib/LICENSE.chromium +27 -0
  246. package/package.json +1 -1
  247. package/prebuilt/darwin-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
  248. package/prebuilt/darwin-arm64/brotli-7995bbdacc52e51c.a +0 -0
  249. package/prebuilt/darwin-arm64/uv-72ab666eae197cd8.a +0 -0
  250. package/prebuilt/darwin-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
  251. package/prebuilt/darwin-arm64/zstd-015315ac7c784c73.a +0 -0
  252. package/prebuilt/darwin-x64/boringssl-4a47438eaf7e73ba.a +0 -0
  253. package/prebuilt/darwin-x64/brotli-7995bbdacc52e51c.a +0 -0
  254. package/prebuilt/darwin-x64/uv-72ab666eae197cd8.a +0 -0
  255. package/prebuilt/darwin-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  256. package/prebuilt/darwin-x64/zstd-015315ac7c784c73.a +0 -0
  257. package/prebuilt/linux-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
  258. package/prebuilt/linux-arm64/brotli-65481ff838ce9def.a +0 -0
  259. package/prebuilt/linux-arm64/uv-f1353f50ff983f3c.a +0 -0
  260. package/prebuilt/linux-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
  261. package/prebuilt/linux-arm64/zstd-015315ac7c784c73.a +0 -0
  262. package/prebuilt/linux-arm64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
  263. package/prebuilt/linux-arm64-musl/brotli-65481ff838ce9def.a +0 -0
  264. package/prebuilt/linux-arm64-musl/uv-f1353f50ff983f3c.a +0 -0
  265. package/prebuilt/linux-arm64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
  266. package/prebuilt/linux-arm64-musl/zstd-015315ac7c784c73.a +0 -0
  267. package/prebuilt/linux-x64/boringssl-4a47438eaf7e73ba.a +0 -0
  268. package/prebuilt/linux-x64/brotli-65481ff838ce9def.a +0 -0
  269. package/prebuilt/linux-x64/uv-f1353f50ff983f3c.a +0 -0
  270. package/prebuilt/linux-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  271. package/prebuilt/linux-x64/zstd-015315ac7c784c73.a +0 -0
  272. package/prebuilt/linux-x64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
  273. package/prebuilt/linux-x64-musl/brotli-65481ff838ce9def.a +0 -0
  274. package/prebuilt/linux-x64-musl/uv-f1353f50ff983f3c.a +0 -0
  275. package/prebuilt/linux-x64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
  276. package/prebuilt/linux-x64-musl/zstd-015315ac7c784c73.a +0 -0
  277. package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
  278. package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
  279. package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
  280. package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  281. package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
  282. package/runtime/include/js_atoms.gen.h +0 -0
  283. package/runtime/include/js_atoms.h +1 -1
  284. package/runtime/include/js_bigint.h +1 -1
  285. package/runtime/include/js_buffer.h +4 -4
  286. package/runtime/include/js_builtins.h +41 -3
  287. package/runtime/include/js_console.h +9 -4
  288. package/runtime/include/js_convert.h +1 -1
  289. package/runtime/include/js_core.def +5 -4
  290. package/runtime/include/js_crypto.h +1 -1
  291. package/runtime/include/js_error.h +1 -1
  292. package/runtime/include/js_exception.h +21 -1
  293. package/runtime/include/js_function.h +33 -9
  294. package/runtime/include/js_gc.h +172 -30
  295. package/runtime/include/js_generator.h +2 -2
  296. package/runtime/include/js_host.h +19 -1
  297. package/runtime/include/js_jobs.h +5 -5
  298. package/runtime/include/js_module.h +1 -1
  299. package/runtime/include/js_object.h +142 -15
  300. package/runtime/include/js_ops.h +107 -5
  301. package/runtime/include/js_promise.h +3 -3
  302. package/runtime/include/js_regexp.h +1 -1
  303. package/runtime/include/js_runtime.h +0 -0
  304. package/runtime/include/js_symbol.h +1 -1
  305. package/runtime/include/js_web.h +2 -1
  306. package/runtime/include/jscell.h +22 -15
  307. package/runtime/include/jscontext.h +74 -39
  308. package/runtime/include/jsnum.h +1 -1
  309. package/runtime/include/jsstring.h +19 -6
  310. package/runtime/include/jsvalue.h +7 -3
  311. package/runtime/src/arguments.c +2 -2
  312. package/runtime/src/array.c +4 -1
  313. package/runtime/src/arraybuffer.c +19 -7
  314. package/runtime/src/async_iter.c +4 -3
  315. package/runtime/src/atoms.c +1 -1
  316. package/runtime/src/base64.c +2 -2
  317. package/runtime/src/bigint.c +1 -1
  318. package/runtime/src/blob.c +22 -9
  319. package/runtime/src/boringssl_support.cc +1 -1
  320. package/runtime/src/buffer.c +299 -91
  321. package/runtime/src/builtin_table.c +1 -1
  322. package/runtime/src/builtins.c +30 -4
  323. package/runtime/src/builtins_util.h +0 -0
  324. package/runtime/src/collections.c +18 -3
  325. package/runtime/src/components.c +1 -1
  326. package/runtime/src/console.c +14 -7
  327. package/runtime/src/convert.c +0 -0
  328. package/runtime/src/core_all.c +1 -1
  329. package/runtime/src/crypto.c +1 -1
  330. package/runtime/src/crypto_asym.c +1 -1
  331. package/runtime/src/crypto_bn.c +1 -1
  332. package/runtime/src/crypto_cipher.c +10 -3
  333. package/runtime/src/crypto_hash.c +1 -1
  334. package/runtime/src/crypto_host.c +1 -1
  335. package/runtime/src/crypto_internal.h +1 -1
  336. package/runtime/src/crypto_kdf.c +1 -1
  337. package/runtime/src/crypto_key.c +14 -1
  338. package/runtime/src/crypto_pkey.c +1 -1
  339. package/runtime/src/crypto_subtle.c +142 -58
  340. package/runtime/src/crypto_tls.c +1 -1
  341. package/runtime/src/date.c +5 -2
  342. package/runtime/src/domexception.c +2 -2
  343. package/runtime/src/elements.c +56 -17
  344. package/runtime/src/elements.h +7 -2
  345. package/runtime/src/encoding.c +1 -1
  346. package/runtime/src/error.c +4 -4
  347. package/runtime/src/events.c +23 -14
  348. package/runtime/src/exception.c +1 -1
  349. package/runtime/src/fetch.c +241 -17
  350. package/runtime/src/function.c +31 -19
  351. package/runtime/src/gc.c +1716 -207
  352. package/runtime/src/gc_visit.h +87 -0
  353. package/runtime/src/generator.c +5 -3
  354. package/runtime/src/global.c +14 -6
  355. package/runtime/src/headers.c +10 -10
  356. package/runtime/src/inspect.c +76 -17
  357. package/runtime/src/internal.h +5 -2
  358. package/runtime/src/iterate.c +94 -2
  359. package/runtime/src/iterator.c +1 -1
  360. package/runtime/src/jobs.c +11 -5
  361. package/runtime/src/jsnum.c +2 -2
  362. package/runtime/src/json.c +1 -1
  363. package/runtime/src/math.c +9 -1
  364. package/runtime/src/module.c +3 -3
  365. package/runtime/src/number.c +0 -0
  366. package/runtime/src/object.c +107 -74
  367. package/runtime/src/ops.c +21 -3
  368. package/runtime/src/os.c +192 -1
  369. package/runtime/src/os.h +33 -2
  370. package/runtime/src/process.c +73 -8
  371. package/runtime/src/promise.c +4 -4
  372. package/runtime/src/proxy.c +1 -1
  373. package/runtime/src/reflect.c +1 -1
  374. package/runtime/src/regexp.c +134 -2
  375. package/runtime/src/regexp_anchor.h +1 -1
  376. package/runtime/src/regexp_message.h +1 -1
  377. package/runtime/src/shape.c +10 -19
  378. package/runtime/src/shape.h +0 -0
  379. package/runtime/src/streams.c +22 -8
  380. package/runtime/src/streams.h +0 -0
  381. package/runtime/src/string.c +64 -25
  382. package/runtime/src/string_builtins.c +7 -7
  383. package/runtime/src/symbol.c +2 -7
  384. package/runtime/src/test_host.c +3 -3
  385. package/runtime/src/tls_roots.gen.h +102 -620
  386. package/runtime/src/typedarray.c +8 -3
  387. package/runtime/src/tznames.gen.h +2 -1
  388. package/runtime/src/uri.c +1 -1
  389. package/runtime/src/url.c +42 -39
  390. package/runtime/src/weak.c +15 -12
  391. package/runtime/src/web.c +21 -3
  392. package/runtime/src/wrapper.c +0 -0
  393. package/runtime/src/writable.c +7 -6
  394. package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
  395. package/runtime/third_party/ada-idna/README.md +7 -7
  396. package/runtime/third_party/ada-idna/convert.mjs +89 -27
  397. package/runtime/third_party/ada-idna/idna.c +30 -31
  398. package/runtime/third_party/ada-idna/idna.h +0 -0
  399. package/runtime/third_party/ada-idna/idna_tables.h +2272 -1952
  400. package/runtime/third_party/boringssl/third_party/fiat/LICENSE +15 -0
  401. package/runtime/third_party/mozilla-ca/LICENSE +373 -0
  402. package/runtime/third_party/mozilla-ca/README.md +9 -0
  403. package/runtime/third_party/nodejs/LICENSE +47 -0
  404. package/runtime/third_party/nodejs/README.md +7 -0
  405. package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
  406. package/runtime/third_party/quickjs-dtoa/README.md +1 -1
  407. package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
  408. package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
  409. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
  410. package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
  411. package/runtime/third_party/quickjs-regexp/README.md +2 -2
  412. package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
  413. package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
  414. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
  415. package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
  416. package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
  417. package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
  418. package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
  419. package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
  420. package/runtime/third_party/unicode/LICENSE +39 -0
  421. package/runtime/third_party/unicode/README.md +9 -0
  422. package/runtime/third_party/v8-ieee754/LICENSE +0 -0
  423. package/runtime/third_party/v8-ieee754/LICENSE.fdlibm +10 -0
  424. package/runtime/third_party/v8-ieee754/README.md +3 -2
  425. package/runtime/third_party/v8-ieee754/convert.py +0 -0
  426. package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
  427. package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
  428. package/runtime/tools/regexp_compile.c +2 -2
@@ -1,24 +1,130 @@
1
- // node:fs/promises (ADR 0012, layer 3): node:fs's synchronous calls, their outcome as a promise.
1
+ // node:fs/promises: node:fs's synchronous calls, their outcome as a promise.
2
2
  // The I/O happens when the function is called, not on libuv's thread pool as in Node.
3
3
  import {
4
- appendFileSync, existsSync, lstatSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync,
4
+ constants, accessSync, chmodSync, chownSync, closeSync, copyFileSync, fsyncSync, lchownSync, linkSync, lstatSync, lutimesSync, mkdirSync,
5
+ mkdtempSync, openSync, readdirSync, readFileSync, readlinkSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, symlinkSync,
6
+ truncateSync, unlinkSync, utimesSync, writeFileSync, writeSync, statfsSync,
5
7
  } from "./fs.js";
8
+ import { codeError } from "./internal/errors.js";
9
+ import { features, lazyFunction } from "./internal/features.js";
10
+ import { getOptions, validateStringAfterArrayBufferView } from "./internal/fs_utils.js";
11
+ import { AbortError } from "./internal/streams/errors.js";
12
+ import { validateAbortSignal, validateBoolean } from "./internal/streams/validators.js";
13
+ import { resolve } from "./path.js";
6
14
 
7
15
  const promised = (fn) => async (...args) => fn(...args);
8
16
 
9
- export const readFile = promised(readFileSync);
10
- export const writeFile = promised(writeFileSync);
11
- export const appendFile = promised(appendFileSync);
17
+ function checkAborted(signal) {
18
+ if (signal?.aborted) throw new AbortError(undefined, { cause: signal.reason });
19
+ }
20
+
21
+ /* with a signal, a turn of the event loop before the I/O, as Node's opens on its thread pool: an
22
+ * abort the program queues meanwhile stops it */
23
+ async function abortable(signal) {
24
+ checkAborted(signal);
25
+ if (signal) {
26
+ await new Promise((resolve) => setImmediate(resolve));
27
+ checkAborted(signal);
28
+ }
29
+ }
30
+
31
+ /* a FileHandle given as the path: its own method (fs_filehandle.js) */
32
+ const isFileHandle = (path) => features.FileHandle !== undefined && path instanceof features.FileHandle;
33
+
34
+ export async function readFile(path, options) {
35
+ options = getOptions(options, { flag: "r" });
36
+ validateAbortSignal(options.signal, "options.signal");
37
+ if (isFileHandle(path)) return path.readFile(options);
38
+ await abortable(options.signal);
39
+ return readFileSync(path, options);
40
+ }
41
+
42
+ const isIterable = (data) =>
43
+ data != null && typeof data === "object" && (typeof data[Symbol.asyncIterator] === "function" || typeof data[Symbol.iterator] === "function");
44
+
45
+ /** The data written: a string, bytes, or an iterable or stream of them. */
46
+ export async function writeFile(path, data, options) {
47
+ options = getOptions(options, { encoding: "utf8", mode: 0o666, flag: "w", flush: false });
48
+ validateBoolean(options.flush ?? false, "options.flush");
49
+ const iterable = !ArrayBuffer.isView(data) && isIterable(data);
50
+ if (!ArrayBuffer.isView(data) && !iterable) {
51
+ validateStringAfterArrayBufferView(data, "data");
52
+ data = Buffer.from(data, options.encoding || "utf8");
53
+ }
54
+ validateAbortSignal(options.signal, "options.signal");
55
+ if (isFileHandle(path)) return path.writeFile(data, options);
56
+ await abortable(options.signal);
57
+ if (!iterable) return writeFileSync(path, data, options);
58
+ const fd = openSync(path, options.flag || "w", options.mode);
59
+ try {
60
+ for await (const chunk of data) {
61
+ checkAborted(options.signal);
62
+ const bytes = ArrayBuffer.isView(chunk) ? chunk : Buffer.from(chunk, options.encoding || "utf8");
63
+ for (let off = 0; off < bytes.byteLength;) off += writeSync(fd, bytes, off, bytes.byteLength - off, null);
64
+ }
65
+ if (options.flush) fsyncSync(fd);
66
+ } finally {
67
+ closeSync(fd);
68
+ }
69
+ }
70
+
71
+ export async function appendFile(path, data, options) {
72
+ options = { ...getOptions(options, { encoding: "utf8", mode: 0o666, flag: "a" }) };
73
+ options.flag ||= "a";
74
+ return writeFile(path, data, options);
75
+ }
12
76
  export const stat = promised(statSync);
13
77
  export const lstat = promised(lstatSync);
14
78
  export const readdir = promised(readdirSync);
15
79
  export const unlink = promised(unlinkSync);
80
+ export const realpath = promised(realpathSync);
81
+ export const mkdir = promised(mkdirSync);
82
+ export const utimes = promised(utimesSync);
16
83
 
17
- /** Whether the path exists (the mode isn't checked). */
18
- export async function access(path) {
19
- if (!existsSync(path)) {
20
- statSync(path); /* throws Node's ENOENT (or the error that stopped it) */
21
- }
84
+ export const access = promised(accessSync);
85
+ export const rename = promised(renameSync);
86
+ export const copyFile = promised(copyFileSync);
87
+ export const link = promised(linkSync);
88
+ export const symlink = promised(symlinkSync);
89
+ export const readlink = promised(readlinkSync);
90
+ export const chmod = promised(chmodSync);
91
+ export const chown = promised(chownSync);
92
+ export const lchown = promised(lchownSync);
93
+ export const lutimes = promised(lutimesSync);
94
+ export const truncate = promised(truncateSync);
95
+ export const mkdtemp = promised(mkdtempSync);
96
+
97
+ /** mkdtemp's directory with a way to remove it, and what it holds: remove(), or an `await using`
98
+ * declaration (Symbol.asyncDispose). */
99
+ export async function mkdtempDisposable(prefix, options) {
100
+ const path = mkdtempSync(prefix, options);
101
+ const fullPath = resolve(process.cwd(), `${path}`);
102
+ const remove = async () => rmSync(fullPath, { recursive: true, force: true });
103
+ return { path, remove, [Symbol.asyncDispose]() { return remove(); } };
22
104
  }
105
+ export const rmdir = promised(rmdirSync);
106
+ export const rm = promised(rmSync);
107
+
108
+ /* read when called: fs.js and this module import each other, and fs.js's consts may not be set yet */
109
+ export const statfs = async (...args) => statfsSync(...args);
110
+ export { constants };
111
+
112
+ /* lchmod: macOS's only, as Node's */
113
+ export async function lchmod() {
114
+ throw codeError(Error, "ERR_METHOD_NOT_IMPLEMENTED", "The lchmod() method is not implemented");
115
+ }
116
+
117
+ /* their own modules, linked when the program names them (internal/features.js) */
118
+ export const open = lazyFunction("promisesOpen", 3);
119
+ export const opendir = lazyFunction("opendirPromise", 2);
120
+ export const cp = lazyFunction("cpPromise", 3);
121
+ export const glob = lazyFunction("globPromise", 2);
122
+ export const watch = lazyFunction("watchPromise", 2);
23
123
 
24
- export default { readFile, writeFile, appendFile, stat, lstat, readdir, unlink, access };
124
+ export default {
125
+ readFile, writeFile, appendFile, stat, lstat, readdir, unlink, realpath, mkdir, utimes, access, rename, copyFile, link, symlink, readlink,
126
+ chmod, chown, lchown, lutimes, truncate, mkdtemp, mkdtempDisposable, rmdir, rm, statfs, lchmod, open, opendir, cp, glob, watch,
127
+ get constants() {
128
+ return constants;
129
+ },
130
+ };
@@ -1,4 +1,4 @@
1
- // node:http (ADR 0012, layer 3), the server side: createServer, Server, IncomingMessage and
1
+ // node:http, the server side: createServer, Server, IncomingMessage and
2
2
  // ServerResponse. As in Node, a Server is a net.Server and a request's socket a net.Socket, whose
3
3
  // bytes llhttp parses in C (node/src/host_http.c) before JS would see them. Responses are
4
4
  // written as Node writes them: the status line, the headers in the order set, then Date,
@@ -7,7 +7,9 @@
7
7
  // upgrade (or CONNECT) hands the socket over with 'upgrade' ('connect'). Idle keep-alive
8
8
  // connections close after keepAliveTimeout; server.timeout and setTimeout are the sockets'.
9
9
  // Not yet: the client, headersTimeout and requestTimeout, trailers.
10
- import { httpAttach, httpDate, httpDetach, httpExpired, httpFlush, httpParsers, httpWrite, timerUnref } from "visaljs:host";
10
+ import {
11
+ httpAttach, httpDate, httpDetach, httpExpired, httpFedClose, httpFedOpen, httpFeed, httpFlush, httpParsers, httpWrite, timerUnref,
12
+ } from "visaljs:host";
11
13
  import { bindContext, currentContext, runInContext } from "./internal/async_context.js";
12
14
  import { codeError, invalidArgType, outOfRange, validateInteger, validateString } from "./internal/errors.js";
13
15
  import { Agent, globalAgent } from "./internal/http_agent.js";
@@ -75,13 +77,18 @@ export class IncomingMessage extends Readable {
75
77
  this.aborted = false;
76
78
  this.statusCode = null;
77
79
  this.statusMessage = null;
80
+ /* Node's: read yet, and dumped (stream utils' isServerRequest tells a request by them) */
81
+ this._consuming = false;
82
+ this._dumped = false;
78
83
  }
79
84
 
80
85
  get connection() {
81
86
  return this.socket;
82
87
  }
83
88
 
84
- _read() {}
89
+ _read() {
90
+ this._consuming = true;
91
+ }
85
92
 
86
93
  /* a response nobody reads: its body is discarded, so the socket isn't held up */
87
94
  _dump() {
@@ -290,9 +297,23 @@ export class ServerResponse extends OutgoingMessage {
290
297
  return this;
291
298
  }
292
299
 
300
+ /* the head a write sends without writeHead, through writeHead as Node's: a wrapper of it runs
301
+ * (on-headers: compression sets Vary and Content-Encoding there). Middleware calls it too, before
302
+ * writing (compression). `length`: the whole body's, when end() knows it */
303
+ _implicitHeader(length) {
304
+ this._implicitLength = length;
305
+ try {
306
+ this.writeHead(this.statusCode);
307
+ } finally {
308
+ this._implicitLength = undefined;
309
+ }
310
+ }
311
+
293
312
  /* sends the head now: the body that follows is chunked */
294
313
  flushHeaders() {
295
- if (!this.headersSent) httpWrite(this._conn, this._renderHead(undefined));
314
+ if (!this.headersSent && Object.hasOwn(this, "writeHead")) this._implicitHeader(undefined); /* a wrapper sees it */
315
+ const head = this._takeHead(undefined);
316
+ if (head) httpWrite(this._conn, head);
296
317
  }
297
318
 
298
319
  destroy(error) {
@@ -331,7 +352,7 @@ export class ServerResponse extends OutgoingMessage {
331
352
  }
332
353
  /* Node renders the head now (sent with the first write): without a known length, the body
333
354
  * is chunked even when end() brings all of it */
334
- if (!this.headersSent) this._pendingHead = this._renderHead(undefined);
355
+ if (!this.headersSent) this._pendingHead = this._renderHead(this._implicitLength);
335
356
  return this;
336
357
  }
337
358
 
@@ -347,7 +368,8 @@ export class ServerResponse extends OutgoingMessage {
347
368
  _renderHead(length) {
348
369
  const status = this.statusCode;
349
370
  const noBody = status === 204 || status === 304 || (status >= 100 && status < 200);
350
- let head = "HTTP/1.1 " + status + " " + (this.statusMessage ?? STATUS_CODES[status] ?? "unknown") + "\r\n";
371
+ /* an empty statusMessage gets the standard one, as in Node (Next.js's route handlers set "") */
372
+ let head = "HTTP/1.1 " + status + " " + (this.statusMessage || STATUS_CODES[status] || "unknown") + "\r\n";
351
373
  for (const [, [name, value]] of this._headers) {
352
374
  if (Array.isArray(value)) for (const v of value) head += name + ": " + v + "\r\n";
353
375
  else head += name + ": " + value + "\r\n";
@@ -385,11 +407,14 @@ export class ServerResponse extends OutgoingMessage {
385
407
  if (this.writableEnded || this.destroyed) {
386
408
  const e = new Error(this.destroyed ? "Cannot call write after a stream was destroyed" : "write after end");
387
409
  e.code = this.destroyed ? "ERR_STREAM_DESTROYED" : "ERR_STREAM_WRITE_AFTER_END";
388
- queueMicrotask(() => this.emit("error", e));
410
+ /* Node's emitErrorNt: none on a destroyed response (its client went away) */
411
+ if (!this.destroyed) queueMicrotask(() => this.emit("error", e));
389
412
  if (typeof callback === "function") queueMicrotask(() => callback(e));
390
413
  return false;
391
414
  }
392
415
  if (typeof chunk === "string" && typeof encoding === "string" && encoding !== "utf8" && encoding !== "utf-8") chunk = Buffer.from(chunk, encoding);
416
+ /* a writeHead of the response's own (a wrapper) sees the implicit head, as in Node */
417
+ if (!this.headersSent && Object.hasOwn(this, "writeHead")) this._implicitHeader(undefined);
393
418
  const head = this._takeHead(undefined);
394
419
  if (head) httpWrite(this._conn, head);
395
420
  if (chunk !== undefined && chunk !== null && chunkLength(chunk) > 0 && !this._head) {
@@ -414,6 +439,7 @@ export class ServerResponse extends OutgoingMessage {
414
439
  }
415
440
  if (this.writableEnded) return this;
416
441
  if (typeof chunk === "string" && typeof encoding === "string" && encoding !== "utf8" && encoding !== "utf-8") chunk = Buffer.from(chunk, encoding);
442
+ if (!this.headersSent && Object.hasOwn(this, "writeHead")) this._implicitHeader(chunk !== undefined && chunk !== null ? chunkLength(chunk) : 0);
417
443
  if (!this.headersSent) {
418
444
  const hasChunk = chunk !== undefined && chunk !== null;
419
445
  const length = hasChunk ? chunkLength(chunk) : 0;
@@ -455,23 +481,29 @@ const requestTimeoutResponse = "HTTP/1.1 408 Request Timeout\r\nConnection: clos
455
481
 
456
482
  function noop() {}
457
483
 
484
+ /** (options, requestListener) or (requestListener): the options an object. */
485
+ function serverArguments(options, requestListener) {
486
+ if (typeof options === "function") return [{}, options];
487
+ if (options === undefined || options === null) return [{}, requestListener];
488
+ if (typeof options !== "object") throw invalidArgType("options", "of type object", options);
489
+ return [options, requestListener];
490
+ }
491
+
458
492
  export class Server extends NetServer {
459
493
  constructor(options, requestListener) {
460
- if (typeof options === "function") {
461
- requestListener = options;
462
- options = {};
463
- } else if (options === undefined || options === null) {
464
- options = {};
465
- } else if (typeof options !== "object") {
466
- throw invalidArgType("options", "of type object", options);
467
- }
494
+ [options, requestListener] = serverArguments(options, requestListener);
468
495
  super({ allowHalfOpen: true, noDelay: options.noDelay ?? true, keepAlive: options.keepAlive, keepAliveInitialDelay: options.keepAliveInitialDelay });
496
+ this._initHttp(options, requestListener, "connection");
497
+ }
498
+
499
+ /* Node's storeHTTPOptions and the server's timeouts, and its sockets' requests: those of each
500
+ * 'connection' (https.Server's: of each 'secureConnection') */
501
+ _initHttp(options, requestListener, connectionEvent) {
469
502
  if (typeof requestListener === "function") this.on("request", requestListener);
470
503
  this.httpAllowHalfOpen = false;
471
504
  this.timeout = 0;
472
505
  this.maxHeadersCount = null;
473
506
  this.maxRequestsPerSocket = 0;
474
- /* Node's storeHTTPOptions and the server's timeouts */
475
507
  const integer = (name, fallback) => {
476
508
  const value = options[name];
477
509
  if (value === undefined) return fallback;
@@ -499,7 +531,7 @@ export class Server extends NetServer {
499
531
  this._checking = null; /* the connections-checking timer, unref'd, while listening */
500
532
  this._parsers = -1;
501
533
  this._states = new Map(); /* connection → { socket, req, res, keepAliveTimeoutSet } */
502
- this.on("connection", (socket) => this._onSocket(socket));
534
+ this.on(connectionEvent, (socket) => this._onSocket(socket));
503
535
  this.on("listening", () => this._checkConnectionsLater());
504
536
  }
505
537
 
@@ -544,7 +576,7 @@ export class Server extends NetServer {
544
576
  /* a connection: its bytes go to llhttp; its end, timeout, errors and close are the requests' */
545
577
  _onSocket(socket) {
546
578
  if (this._parsers === -1) {
547
- /* in the async context of the connection's (ADR 0020), as the server's sockets' callbacks */
579
+ /* in the async context of the connection's, as the server's sockets' callbacks */
548
580
  this._parsers = httpParsers(...[
549
581
  (conn, method, url, raw, major, minor, keepAlive, upgrade) => this._onRequest(conn, method, url, raw, major, minor, keepAlive, upgrade),
550
582
  (conn, chunk) => this._states.get(conn)?.req?._push(chunk),
@@ -571,7 +603,7 @@ export class Server extends NetServer {
571
603
  },
572
604
  ].map(bindContext));
573
605
  }
574
- const conn = socket._handle;
606
+ const conn = connOf(socket);
575
607
  if (conn === null) return;
576
608
  const state = { socket, conn, req: null, res: null, keepAliveTimeoutSet: false, listeners: null };
577
609
  this._states.set(conn, state);
@@ -658,6 +690,7 @@ export class Server extends NetServer {
658
690
  this._states.delete(conn);
659
691
  for (const [event, fn] of Object.entries(state.listeners)) socket.removeListener(event, fn);
660
692
  if (socket.listenerCount("error") === 0) socket.on("error", noop);
693
+ unfeed(socket);
661
694
  /* what the socket reads next goes to its stream, buffered until someone reads it */
662
695
  socket._readableState.flowing = null;
663
696
  const bodyHead = Buffer.from(head.buffer, head.byteOffset, head.byteLength);
@@ -667,13 +700,53 @@ export class Server extends NetServer {
667
700
  }
668
701
  }
669
702
 
703
+ /* ---- Connections: llhttp on a socket's handle, or fed --------------------------------------- */
704
+
705
+ /* A socket whose bytes aren't its handle's: a TLSSocket's handle carries ciphertext, a Duplex
706
+ * has none. llhttp parses what it reads ('data') and writes through it (write()). */
707
+ const isFed = (socket) => socket.encrypted === true || socket._handle === undefined;
708
+ const kFed = Symbol("kFed");
709
+
710
+ /** The socket's connection for llhttp: its net handle's id (the parser reads the handle in C), or a
711
+ * fed connection, made the first time; null for a net socket without a handle yet. */
712
+ function connOf(socket) {
713
+ if (!isFed(socket)) return socket._handle;
714
+ const fed = socket[kFed];
715
+ if (fed) return fed.conn;
716
+ const conn = httpFedOpen((bytes) => {
717
+ if (!socket.destroyed) socket.write(Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength));
718
+ });
719
+ const onData = (chunk) => httpFeed(conn, typeof chunk === "string" ? Buffer.from(chunk) : chunk);
720
+ const onEnd = () => httpFeed(conn, null);
721
+ const onClose = () => unfeed(socket);
722
+ socket[kFed] = { conn, onData, onEnd, onClose };
723
+ socket.on("data", onData);
724
+ socket.on("end", onEnd);
725
+ socket.on("close", onClose);
726
+ return conn;
727
+ }
728
+
729
+ /** A socket's connection if it has one: its handle's id, or its fed connection's. */
730
+ const connKey = (socket) => (isFed(socket) ? socket[kFed]?.conn : socket._handle);
731
+
732
+ /* the socket's bytes stop going to llhttp: it upgraded, or closed */
733
+ function unfeed(socket) {
734
+ const fed = socket[kFed];
735
+ if (!fed) return;
736
+ socket[kFed] = undefined;
737
+ socket.removeListener("data", fed.onData);
738
+ socket.removeListener("end", fed.onEnd);
739
+ socket.removeListener("close", fed.onClose);
740
+ httpFedClose(fed.conn);
741
+ }
742
+
670
743
  /* Node's socketOnError: 'clientError', or a 400 (when nothing was written yet) and the end */
671
744
  function socketOnError(e) {
672
745
  this.removeListener("error", socketOnError);
673
746
  if (this.listenerCount("error") === 0) this.on("error", noop);
674
747
  const server = this.server;
675
748
  if (!server.emit("clientError", e, this)) {
676
- const state = server._states.get(this._handle);
749
+ const state = server._states.get(connKey(this));
677
750
  const res = state?.res;
678
751
  if (this.writable && (!res || !res.headersSent)) {
679
752
  if (state) httpFlush(state.conn);
@@ -702,11 +775,11 @@ function urlToHttpOptions(url) {
702
775
  return options;
703
776
  }
704
777
 
705
- /* the sockets whose responses llhttp parses: handle id → socket */
778
+ /* the sockets whose responses llhttp parses: connection → socket */
706
779
  const clientSockets = new Map();
707
780
  let clientParsers = -1;
708
781
 
709
- /* the async context a request was made in (ADR 0020): its response's callbacks run in it, as in
782
+ /* the async context a request was made in: its response's callbacks run in it, as in
710
783
  * Node, whichever request's the socket was */
711
784
  const kAsyncContext = Symbol("kAsyncContext");
712
785
  const inRequestContext = (fn) => (conn, ...args) =>
@@ -776,12 +849,15 @@ const statusIsInformational = (status) => status < 200 && status >= 100 && statu
776
849
  /* the socket's bytes go to a response parser: now, or once it has connected */
777
850
  function attachParser(socket, req) {
778
851
  const attach = () => {
779
- if (socket._httpMessage !== req || socket._handle === null) return;
780
- clientSockets.set(socket._handle, socket);
781
- socket._clientConn = socket._handle;
782
- httpAttach(socket._handle, clientParsersId(), true, req.maxHeaderSize ?? maxHeaderSize);
852
+ if (socket._httpMessage !== req) return;
853
+ const conn = connOf(socket);
854
+ if (conn === null) return;
855
+ clientSockets.set(conn, socket);
856
+ socket._clientConn = conn;
857
+ httpAttach(conn, clientParsersId(), true, req.maxHeaderSize ?? maxHeaderSize);
783
858
  };
784
- if (socket.connecting || socket._handle === null) socket.once("connect", attach);
859
+ /* a net socket's handle is its once connected; a fed socket's bytes come as they come */
860
+ if (!isFed(socket) && (socket.connecting || socket._handle === null)) socket.once("connect", attach);
785
861
  else attach();
786
862
  }
787
863
 
@@ -833,6 +909,7 @@ function clientUpgrade(req, socket, head) {
833
909
  if (req.timeoutCb) socket.removeListener("timeout", req.timeoutCb);
834
910
  socket.removeListener("timeout", responseOnTimeout);
835
911
  freeParser(socket);
912
+ unfeed(socket);
836
913
  const bodyHead = Buffer.from(head.buffer, head.byteOffset, head.byteLength);
837
914
  const eventName = req.method === "CONNECT" ? "connect" : "upgrade";
838
915
  if (req.listenerCount(eventName) > 0) {
@@ -1,4 +1,4 @@
1
- // node:http2 (ADR 0012, layer 3): only what code that supports both HTTP versions touches when it
1
+ // node:http2: only what code that supports both HTTP versions touches when it
2
2
  // runs on HTTP/1 — the request and response classes (for instanceof checks, which never match
3
3
  // here) and the constants. Servers and sessions aren't provided: creating one throws.
4
4
  import { notSupported } from "./internal/errors.js";
@@ -0,0 +1,148 @@
1
+ // node:https (Node's lib/https.js): HTTP over TLS. Server is a tls.Server whose secure connections
2
+ // get http.Server's requests (llhttp fed the decrypted bytes: http.js's fed connections); Agent is
3
+ // http.Agent connecting with tls.connect, reusing TLS sessions by origin; request and get are
4
+ // http's, with https's agent and port 443.
5
+ // Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
6
+ import { Agent as HttpAgent, ClientRequest, Server as HttpServer } from "./http.js";
7
+ import { invalidArgType } from "./internal/errors.js";
8
+ import { Server as TlsServer, connect as tlsConnect } from "./tls.js";
9
+ import { urlToHttpOptions } from "./url.js";
10
+
11
+ /* ---- Server ------------------------------------------------------------------------------------- */
12
+
13
+ export class Server extends TlsServer {
14
+ constructor(options, requestListener) {
15
+ if (typeof options === "function") {
16
+ requestListener = options;
17
+ options = {};
18
+ } else if (options === undefined || options === null) {
19
+ options = {};
20
+ } else if (typeof options !== "object") {
21
+ throw invalidArgType("options", "of type object", options);
22
+ }
23
+ super({ noDelay: true, ALPNProtocols: ["http/1.1"], ...options });
24
+ this._initHttp(options, requestListener, "secureConnection");
25
+ /* a handshake that fails is the client's error, as a request that does */
26
+ this.on("tlsClientError", (err, conn) => {
27
+ if (!this.emit("clientError", err, conn)) conn.destroy(err);
28
+ });
29
+ }
30
+ }
31
+
32
+ /* http.Server's methods: its requests, timeouts and connections */
33
+ for (const key of Object.getOwnPropertyNames(HttpServer.prototype)) {
34
+ if (key === "constructor" || Object.hasOwn(Server.prototype, key)) continue;
35
+ Object.defineProperty(Server.prototype, key, Object.getOwnPropertyDescriptor(HttpServer.prototype, key));
36
+ }
37
+
38
+ export function createServer(options, requestListener) {
39
+ return new Server(options, requestListener);
40
+ }
41
+
42
+ /* ---- Agent -------------------------------------------------------------------------------------- */
43
+
44
+ /* tls.connect with the agent's options, resuming the origin's last session */
45
+ function createConnection(port, host, options) {
46
+ if (port !== null && typeof port === "object") options = port;
47
+ else if (host !== null && typeof host === "object") options = { ...host };
48
+ else if (options === null || typeof options !== "object") options = {};
49
+ else options = { ...options };
50
+ if (typeof port === "number") options.port = port;
51
+ if (typeof host === "string") options.host = host;
52
+ if (options._agentKey) {
53
+ const session = this._getSession(options._agentKey);
54
+ if (session) options = { session, ...options };
55
+ }
56
+ const socket = tlsConnect(options);
57
+ if (options._agentKey) {
58
+ socket.on("session", (session) => this._cacheSession(options._agentKey, session));
59
+ socket.once("close", (err) => {
60
+ if (err) this._evictSession(options._agentKey);
61
+ });
62
+ }
63
+ return socket;
64
+ }
65
+
66
+ /** http.Agent over TLS: port 443, and the TLS options in each origin's name. */
67
+ export function Agent(options) {
68
+ if (!(this instanceof Agent)) return new Agent(options);
69
+ HttpAgent.call(this, options);
70
+ this.defaultPort = 443;
71
+ this.protocol = "https:";
72
+ this.maxCachedSessions = this.options.maxCachedSessions;
73
+ if (this.maxCachedSessions === undefined) this.maxCachedSessions = 100;
74
+ this._sessionCache = { map: {}, list: [] };
75
+ }
76
+ Object.setPrototypeOf(Agent.prototype, HttpAgent.prototype);
77
+ Object.setPrototypeOf(Agent, HttpAgent);
78
+ Agent.prototype.createConnection = createConnection;
79
+
80
+ /* the origin with what makes its TLS connections differ: sockets aren't shared across them */
81
+ const nameOptions = ["ca", "cert", "clientCertEngine", "ciphers", "key", "pfx", "rejectUnauthorized", "servername", "minVersion",
82
+ "maxVersion", "secureProtocol", "crl", "honorCipherOrder", "ecdhCurve", "dhparam", "secureOptions", "sessionIdContext", "sigalgs",
83
+ "privateKeyIdentifier", "privateKeyEngine"];
84
+
85
+ Agent.prototype.getName = function getName(options = {}) {
86
+ let name = HttpAgent.prototype.getName.call(this, options);
87
+ for (const key of nameOptions) {
88
+ name += ":";
89
+ const value = options[key];
90
+ if (key === "rejectUnauthorized") {
91
+ if (value !== undefined) name += value;
92
+ } else if (key === "servername") {
93
+ if (value && value !== options.host) name += value;
94
+ } else if (value) {
95
+ name += value;
96
+ }
97
+ }
98
+ return name;
99
+ };
100
+
101
+ Agent.prototype._getSession = function _getSession(key) {
102
+ return this._sessionCache.map[key];
103
+ };
104
+
105
+ Agent.prototype._cacheSession = function _cacheSession(key, session) {
106
+ if (this.maxCachedSessions === 0) return;
107
+ if (this._sessionCache.map[key]) {
108
+ this._sessionCache.map[key] = session;
109
+ return;
110
+ }
111
+ if (this._sessionCache.list.length >= this.maxCachedSessions) {
112
+ const oldKey = this._sessionCache.list.shift();
113
+ delete this._sessionCache.map[oldKey];
114
+ }
115
+ this._sessionCache.list.push(key);
116
+ this._sessionCache.map[key] = session;
117
+ };
118
+
119
+ Agent.prototype._evictSession = function _evictSession(key) {
120
+ const index = this._sessionCache.list.indexOf(key);
121
+ if (index === -1) return;
122
+ this._sessionCache.list.splice(index, 1);
123
+ delete this._sessionCache.map[key];
124
+ };
125
+
126
+ export const globalAgent = new Agent({ keepAlive: true, scheduling: "lifo", timeout: 5000 });
127
+
128
+ /* ---- request and get ---------------------------------------------------------------------------- */
129
+
130
+ /** request(url[, options][, callback]) or request(options[, callback]): an http.ClientRequest
131
+ * with https's agent. */
132
+ export function request(...args) {
133
+ let options = {};
134
+ if (typeof args[0] === "string") options = urlToHttpOptions(new URL(args.shift()));
135
+ else if (args[0] instanceof URL) options = urlToHttpOptions(args.shift());
136
+ if (args[0] && typeof args[0] !== "function") Object.assign(options, args.shift());
137
+ options._defaultAgent = globalAgent;
138
+ args.unshift(options);
139
+ return new ClientRequest(...args);
140
+ }
141
+
142
+ export function get(input, options, cb) {
143
+ const req = request(input, options, cb);
144
+ req.end();
145
+ return req;
146
+ }
147
+
148
+ export default { Agent, Server, createServer, get, globalAgent, request };
@@ -0,0 +1,27 @@
1
+ // node:inspector: a compiled program has no V8 inspector to connect to. It loads as in a Node
2
+ // process no debugger is attached to: url() is undefined, close() does nothing, console is the
3
+ // global console. What needs the inspector throws when called: open, waitForDebugger and a Session.
4
+ // Code that loads it only to ask whether a debugger is attached (Next.js's server) runs; code that
5
+ // profiles or debugs on request fails when asked (TypeScript's --generateCpuProfile).
6
+ import { notSupported } from "./internal/errors.js";
7
+
8
+ export function open() {
9
+ throw notSupported("inspector.open() (a compiled program has no V8 inspector)");
10
+ }
11
+ export function close() {}
12
+ export function url() {
13
+ return undefined;
14
+ }
15
+ export function waitForDebugger() {
16
+ throw notSupported("inspector.waitForDebugger() (a compiled program has no V8 inspector)");
17
+ }
18
+ export const console = globalThis.console;
19
+ export class Session {
20
+ constructor() {
21
+ throw notSupported("inspector.Session (a compiled program has no V8 inspector)");
22
+ }
23
+ }
24
+ export const Network = {};
25
+ export const NetworkResources = {};
26
+
27
+ export default { open, close, url, waitForDebugger, console, Session, Network, NetworkResources };
@@ -0,0 +1,4 @@
1
+ // node:inspector/promises: as node:inspector, a compiled program has no V8 inspector: it loads,
2
+ // with no debugger attached, and what needs one throws when called.
3
+ export * from "./inspector.js";
4
+ export { default } from "./inspector.js";
@@ -1,4 +1,4 @@
1
- // The async context (ADR 0020): the value the runtime carries through jobs, timers and promise
1
+ // The async context: the value the runtime carries through jobs, timers and promise
2
2
  // reactions, which node:async_hooks' AsyncLocalStorage keeps its stores in (a frame: a Map from
3
3
  // each storage to its store, never changed once current). I/O callbacks run under none: the
4
4
  // prelude binds each to the context it was registered in, as Node runs a handle's callbacks in
@@ -0,0 +1,44 @@
1
+ // buffer.transcode: bytes in one encoding as bytes in another. Linked into programs that name it
2
+ // (internal/features.js).
3
+ import { features } from "./features.js";
4
+
5
+ /* transcode's encodings, by Buffer's names for them */
6
+ const transcodable = { ascii: "ascii", latin1: "latin1", binary: "latin1", ucs2: "utf16le", "ucs-2": "utf16le", utf16le: "utf16le", "utf-16le": "utf16le", utf8: "utf8", "utf-8": "utf8" };
7
+
8
+ /** The bytes in one encoding as bytes in another: ascii, latin1, ucs2 or utf8. A character the
9
+ * target can't hold becomes "?", as Node's (ICU's) transcode makes it. */
10
+ function transcode(source, fromEncoding, toEncoding) {
11
+ if (!(source instanceof Uint8Array)) {
12
+ const e = new TypeError(`The "source" argument must be an instance of Buffer or Uint8Array.${received(source)}`);
13
+ e.code = "ERR_INVALID_ARG_TYPE";
14
+ throw e;
15
+ }
16
+ if (source.length === 0) return Buffer.alloc(0);
17
+ const from = transcodable[String(fromEncoding).toLowerCase()];
18
+ const to = transcodable[String(toEncoding).toLowerCase()];
19
+ if (from === undefined || to === undefined) {
20
+ const e = new Error("Unable to transcode Buffer [U_ILLEGAL_ARGUMENT_ERROR]");
21
+ e.code = "U_ILLEGAL_ARGUMENT_ERROR";
22
+ e.errno = 1;
23
+ throw e;
24
+ }
25
+ let text = Buffer.from(source.buffer, source.byteOffset, source.byteLength).toString(from);
26
+ const max = to === "ascii" ? 0x7f : to === "latin1" ? 0xff : -1;
27
+ if (max >= 0) {
28
+ let out = "";
29
+ for (const ch of text) out += ch.codePointAt(0) > max ? "?" : ch;
30
+ text = out;
31
+ }
32
+ return Buffer.from(text, to);
33
+ }
34
+
35
+ /* Node's "Received …" for the message */
36
+ function received(value) {
37
+ if (value === null || value === undefined) return ` Received ${value}`;
38
+ if (typeof value === "function") return ` Received function ${value.name}`;
39
+ if (typeof value === "object") return ` Received an instance of ${value.constructor?.name ?? "Object"}`;
40
+ const shown = typeof value === "string" ? `'${value.length > 25 ? value.slice(0, 25) + "..." : value}'` : String(value);
41
+ return ` Received type ${typeof value} (${shown})`;
42
+ }
43
+
44
+ features.transcode = transcode;