visaljs 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (428) hide show
  1. package/README.md +63 -2
  2. package/THIRD_PARTY_LICENSES +1216 -0
  3. package/cli.js +4414 -325
  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 -5
  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,4 +1,4 @@
1
- /* Host primitives for node:http (ADR 0012, host prelude): llhttp (Node's parser) on node:net's
1
+ /* Host primitives for node:http: llhttp (Node's parser) on node:net's
2
2
  * sockets, for a server's requests and a client's responses. As in Node, a connection is a
3
3
  * net.Socket, but its bytes go to the parser in C, not through JS: host_net.c's hook hands them
4
4
  * over. The prelude's http.js builds Node's objects from what the parser finds; C does the
@@ -22,6 +22,12 @@
22
22
  * writes goes out in one write when it (and its microtasks) returns
23
23
  * httpFlush(conn) sends the corked output now (before the socket is ended)
24
24
  * httpDate() → the Date header's value
25
+ * A socket whose bytes aren't its handle's (a TLS socket's are decrypted in JS, a Duplex has no
26
+ * handle) is a fed connection, with a negative id: JS gives its parser the bytes, and its output
27
+ * goes to a JS writer (which the TLS socket encrypts).
28
+ * httpFedOpen(writer) → conn writer(bytes) gets what the connection's output flushes
29
+ * httpFeed(conn, bytes | null) → whether the parser took them (null: the end of the input)
30
+ * httpFedClose(conn) the connection is done with (its socket closed)
25
31
  * The loop is host_loop.c's; the sockets are host_net.c's. */
26
32
  #define _POSIX_C_SOURCE 200809L /* libuv's headers: pthread_rwlock_t, struct addrinfo */
27
33
  #include <stdio.h>
@@ -77,10 +83,18 @@ struct Conn {
77
83
  Buf out; /* written but not sent: corked, as Node corks a response */
78
84
  };
79
85
 
86
+ /* A fed connection: its writer, and the parser it has now (a new one per kept-alive request). */
87
+ typedef struct Fed {
88
+ JSValue writer; /* a root */
89
+ Conn *conn;
90
+ } Fed;
91
+
80
92
  static Parsers **parsers;
81
93
  static size_t nparsers;
82
94
  static Conn **conns; /* by net handle id */
83
95
  static size_t nconns;
96
+ static Fed **feds; /* fed connections: id -(k + 1) is feds[k] */
97
+ static size_t nfeds;
84
98
  static int *pending; /* ids of connections with corked output */
85
99
  static size_t npending, pending_cap;
86
100
  static llhttp_settings_t settings;
@@ -211,7 +225,19 @@ static int on_message_complete(llhttp_t *p) {
211
225
  return js_uv_call(c->parsers->on_complete, 2, args, NULL) ? 0 : -1;
212
226
  }
213
227
 
214
- static Conn *conn_of(int id) { return id >= 0 && (size_t)id < nconns ? conns[id] : NULL; }
228
+ static Fed *fed_of(int id) {
229
+ if (id >= 0) return NULL;
230
+ size_t k = (size_t)(-(id + 1));
231
+ return k < nfeds ? feds[k] : NULL;
232
+ }
233
+
234
+ static Conn *conn_of(int id) {
235
+ if (id < 0) {
236
+ Fed *f = fed_of(id);
237
+ return f ? f->conn : NULL;
238
+ }
239
+ return (size_t)id < nconns ? conns[id] : NULL;
240
+ }
215
241
 
216
242
  static void parse_error(Conn *c, llhttp_errno_t e) {
217
243
  c->detached = true;
@@ -233,16 +259,20 @@ static void free_conn(Conn *c) {
233
259
  * when llhttp returns if a callback let go of it (a client frees its parser in the response's
234
260
  * last callback, and starts the next request in a microtask). */
235
261
  static void release_conn(Conn *c) {
236
- if (conns[c->id] == c) conns[c->id] = NULL;
262
+ Fed *f = fed_of(c->id);
263
+ if (f) {
264
+ if (f->conn == c) f->conn = NULL;
265
+ } else if (conns[c->id] == c) {
266
+ conns[c->id] = NULL;
267
+ }
237
268
  c->detached = true;
238
269
  if (c->executing) c->released = true;
239
270
  else free_conn(c);
240
271
  }
241
272
 
242
- /* The socket's bytes, before JS sees them: parsed while attached; EOF and errors go on to JS
243
- * (the socket's 'end' and 'error'). */
244
- static bool hook_read(void *data, ssize_t n, const char *bytes) {
245
- Conn *c = data;
273
+ /* A connection's bytes: parsed while attached; EOF and errors go on to JS (the socket's 'end'
274
+ * and 'error'). False when the parser doesn't take them. */
275
+ static bool parse_input(Conn *c, ssize_t n, const char *bytes) {
246
276
  if (c->detached) return false;
247
277
  c->executing = true;
248
278
  if (n < 0) {
@@ -281,6 +311,16 @@ static bool hook_read(void *data, ssize_t n, const char *bytes) {
281
311
  return true;
282
312
  }
283
313
 
314
+ /* A socket's bytes, before JS sees them. */
315
+ /* a socket's read, parsed in C: its callbacks (a body and its end) run before the microtasks and
316
+ * nextTicks do, as in Node, where one read is one callback scope */
317
+ static bool hook_read(void *data, ssize_t n, const char *bytes) {
318
+ js_uv_nest(1);
319
+ bool ok = parse_input(data, n, bytes);
320
+ js_uv_nest(-1);
321
+ return js_uv_drain() && ok;
322
+ }
323
+
284
324
  static void hook_close(void *data) { release_conn(data); }
285
325
 
286
326
  static const JSNetHook http_hook = { hook_read, hook_close };
@@ -320,8 +360,11 @@ JSValue js_host_http_attach(JSContext *ctx, JSValue callee, JSValue this_val, ui
320
360
  if (argc < 2 || !js_is_int32(argv[0]) || !js_is_int32(argv[1])) return js_throw_type_error(ctx, "httpAttach: (conn, parsers) expected");
321
361
  int id = js_as_int32(argv[0]);
322
362
  int32_t pi = js_as_int32(argv[1]);
323
- if (pi < 0 || (size_t)pi >= nparsers || !js_net_stream(id)) return js_int32(UV_EBADF);
324
- if ((size_t)id >= nconns) {
363
+ Fed *f = fed_of(id);
364
+ if (pi < 0 || (size_t)pi >= nparsers || (id < 0 ? !f : !js_net_stream(id))) return js_int32(UV_EBADF);
365
+ if (f) {
366
+ if (f->conn) release_conn(f->conn);
367
+ } else if ((size_t)id >= nconns) {
325
368
  size_t n = nconns ? nconns : 64;
326
369
  while (n <= (size_t)id) n *= 2;
327
370
  Conn **v = realloc(conns, n * sizeof *v);
@@ -330,7 +373,7 @@ JSValue js_host_http_attach(JSContext *ctx, JSValue callee, JSValue this_val, ui
330
373
  conns = v;
331
374
  nconns = n;
332
375
  }
333
- if (conns[id]) release_conn(conns[id]); /* a kept-alive socket's next request: a fresh parser */
376
+ if (!f && conns[id]) release_conn(conns[id]); /* a kept-alive socket's next request: a fresh parser */
334
377
  Conn *c = calloc(1, sizeof *c);
335
378
  if (!c) js_fatal("out of memory in http");
336
379
  c->id = id;
@@ -343,8 +386,12 @@ JSValue js_host_http_attach(JSContext *ctx, JSValue callee, JSValue this_val, ui
343
386
  js_add_root(ctx->rt, &c->headers);
344
387
  llhttp_init(&c->parser, c->response ? HTTP_RESPONSE : HTTP_REQUEST, &settings);
345
388
  c->parser.data = c;
346
- conns[id] = c;
347
- js_net_hook(id, &http_hook, c);
389
+ if (f) {
390
+ f->conn = c; /* its bytes come from httpFeed */
391
+ } else {
392
+ conns[id] = c;
393
+ js_net_hook(id, &http_hook, c);
394
+ }
348
395
  return js_int32(0);
349
396
  }
350
397
 
@@ -354,7 +401,7 @@ JSValue js_host_http_detach(JSContext *ctx, JSValue callee, JSValue this_val, ui
354
401
  Conn *c = argc > 0 && js_is_int32(argv[0]) ? conn_of(js_as_int32(argv[0])) : NULL;
355
402
  if (c) {
356
403
  if (c->queued) flush_conn(c);
357
- js_net_hook(c->id, NULL, NULL);
404
+ if (c->id >= 0) js_net_hook(c->id, NULL, NULL);
358
405
  release_conn(c);
359
406
  }
360
407
  return JS_UNDEFINED;
@@ -372,8 +419,8 @@ JSValue js_host_http_expired(JSContext *ctx, JSValue callee, JSValue this_val, u
372
419
  JSValue list = js_new_array(ctx, 0);
373
420
  if (pi < 0 || (size_t)pi >= nparsers) return list;
374
421
  uint64_t now = uv_now(js_uv_loop(ctx));
375
- for (size_t i = 0; i < nconns; i++) {
376
- Conn *c = conns[i];
422
+ for (size_t i = 0; i < nconns + nfeds; i++) {
423
+ Conn *c = i < nconns ? conns[i] : feds[i - nconns] ? feds[i - nconns]->conn : NULL;
377
424
  if (!c || c->parsers != parsers[pi] || !c->active || c->detached) continue;
378
425
  uint64_t age = now - c->begin_ms;
379
426
  if ((!c->head_done && headers_timeout > 0 && (double)age > headers_timeout) || (request_timeout > 0 && (double)age > request_timeout)) {
@@ -401,6 +448,15 @@ static void on_written(uv_write_t *req, int status) {
401
448
  /* Sends a connection's corked output as one write. */
402
449
  static void flush_conn(Conn *c) {
403
450
  c->queued = false;
451
+ Fed *f = fed_of(c->id);
452
+ if (f) { /* to its writer: the connection may be gone when it returns */
453
+ if (c->out.n == 0) return;
454
+ JSValue bytes = bytes_value(ctx_(), c->out.v, c->out.n);
455
+ c->out.n = 0;
456
+ JSValue writer = f->writer;
457
+ (void)js_uv_call(writer, 1, &bytes, NULL);
458
+ return;
459
+ }
404
460
  uv_stream_t *s = js_net_stream(c->id);
405
461
  if (!s || c->out.n == 0) {
406
462
  c->out.n = 0;
@@ -417,19 +473,26 @@ static void flush_conn(Conn *c) {
417
473
  }
418
474
  }
419
475
 
476
+ /* Taken over before it runs: a fed connection's writer runs JS, which may write (and flush) more. */
420
477
  static void flush_pending(void) {
421
- for (size_t i = 0; i < npending; i++) {
422
- Conn *c = conn_of(pending[i]);
423
- if (c && c->queued) flush_conn(c);
478
+ while (npending > 0) {
479
+ int *ids = pending;
480
+ size_t n = npending;
481
+ pending = NULL;
482
+ npending = pending_cap = 0;
483
+ for (size_t i = 0; i < n; i++) {
484
+ Conn *c = conn_of(ids[i]);
485
+ if (c && c->queued) flush_conn(c);
486
+ }
487
+ free(ids);
424
488
  }
425
- npending = 0;
426
489
  }
427
490
 
428
491
  /* httpWrite(conn, data): corked until the current callback (and its microtasks) returns */
429
492
  JSValue js_host_http_write(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
430
493
  (void)callee, (void)this_val, (void)new_target;
431
494
  Conn *c = argc > 0 && js_is_int32(argv[0]) ? conn_of(js_as_int32(argv[0])) : NULL;
432
- if (!c || argc < 2 || !js_net_stream(c->id)) return JS_FALSE;
495
+ if (!c || argc < 2 || (c->id >= 0 && !js_net_stream(c->id))) return JS_FALSE;
433
496
  if (js_is_string(argv[1])) {
434
497
  JSStrView v = js_string_view(ctx, argv[1]);
435
498
  size_t n = js_view_to_utf8(v, NULL, 0);
@@ -465,6 +528,66 @@ JSValue js_host_http_flush(JSContext *ctx, JSValue callee, JSValue this_val, uin
465
528
  return JS_UNDEFINED;
466
529
  }
467
530
 
531
+ /* ---- Fed connections --------------------------------------------------------------------- */
532
+
533
+ /* httpFedOpen(writer) → conn: a connection whose bytes JS feeds */
534
+ JSValue js_host_http_fed_open(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
535
+ (void)callee, (void)this_val, (void)new_target;
536
+ if (argc < 1 || !js_is_callable(argv[0])) return js_throw_type_error(ctx, "httpFedOpen: a writer expected");
537
+ size_t k = 0;
538
+ while (k < nfeds && feds[k]) k++;
539
+ if (k == nfeds) {
540
+ size_t n = nfeds ? nfeds * 2 : 16;
541
+ Fed **v = realloc(feds, n * sizeof *v);
542
+ if (!v) js_fatal("out of memory in http");
543
+ memset(v + nfeds, 0, (n - nfeds) * sizeof *v);
544
+ feds = v;
545
+ nfeds = n;
546
+ }
547
+ Fed *f = calloc(1, sizeof *f); /* by itself: its writer is a root at a fixed address */
548
+ if (!f) js_fatal("out of memory in http");
549
+ f->writer = argv[0];
550
+ js_add_root(ctx->rt, &f->writer);
551
+ feds[k] = f;
552
+ return js_int32(-(int32_t)k - 1);
553
+ }
554
+
555
+ /* httpFeed(conn, bytes | null) → whether the parser took them; null: the input ended */
556
+ JSValue js_host_http_feed(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
557
+ (void)callee, (void)this_val, (void)new_target;
558
+ Conn *c = argc > 0 && js_is_int32(argv[0]) && js_as_int32(argv[0]) < 0 ? conn_of(js_as_int32(argv[0])) : NULL;
559
+ if (!c) return JS_FALSE;
560
+ /* called from JS: the parser's callbacks run in it, so no microtask or nextTick runs between
561
+ * two of them (a body and its end come in the same turn, as in Node) */
562
+ if (argc < 2 || js_is_null(argv[1]) || js_is_undefined(argv[1])) {
563
+ js_uv_nest(1);
564
+ bool ok = parse_input(c, UV_EOF, NULL);
565
+ js_uv_nest(-1);
566
+ return js_bool(ok);
567
+ }
568
+ uint8_t *bytes;
569
+ size_t n;
570
+ if (!js_buffer_source_bytes(argv[1], &bytes, &n)) return js_throw_type_error(ctx, "httpFeed: bytes expected");
571
+ if (n == 0) return JS_TRUE;
572
+ js_uv_nest(1);
573
+ bool ok = parse_input(c, (ssize_t)n, (const char *)bytes);
574
+ js_uv_nest(-1);
575
+ return js_bool(ok);
576
+ }
577
+
578
+ /* httpFedClose(conn): its parser and writer go */
579
+ JSValue js_host_http_fed_close(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
580
+ (void)callee, (void)this_val, (void)new_target;
581
+ int id = argc > 0 && js_is_int32(argv[0]) ? js_as_int32(argv[0]) : 0;
582
+ Fed *f = fed_of(id);
583
+ if (!f) return JS_UNDEFINED;
584
+ if (f->conn) release_conn(f->conn);
585
+ feds[-(id + 1)] = NULL;
586
+ js_remove_root(ctx->rt, &f->writer);
587
+ free(f);
588
+ return JS_UNDEFINED;
589
+ }
590
+
468
591
  /* httpDate(): the Date header's value, IMF-fixdate, formatted once per second (as Node caches it) */
469
592
  JSValue js_host_http_date(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
470
593
  (void)callee, (void)this_val, (void)argc, (void)argv, (void)new_target;
@@ -1,4 +1,4 @@
1
- /* The libuv loop the host modules share (ADR 0008's I/O backend): node:http and node:net
1
+ /* The libuv loop the host modules share: node:http and node:net
2
2
  * install it on first use, so programs without I/O don't link libuv. */
3
3
  #define _POSIX_C_SOURCE 200809L /* libuv's headers: pthread_rwlock_t, struct addrinfo */
4
4
  #ifndef _WIN32
@@ -16,6 +16,7 @@ static uv_timer_t wake; /* ends uv_run at the next timer's deadline; unref'
16
16
  static JSContext *loop_ctx; /* the realm callbacks run in */
17
17
  static int failed; /* exit status after an uncaught error in a callback */
18
18
  static void (*flush_hook)(void);
19
+ static int call_depth; /* js_uv_calls under way: one made from JS (a fed http parser's) nests */
19
20
 
20
21
  static void on_wake(uv_timer_t *t) { (void)t; }
21
22
 
@@ -63,13 +64,29 @@ JSContext *js_uv_context(void) { return loop_ctx; }
63
64
 
64
65
  void js_uv_set_flush(void (*fn)(void)) { flush_hook = fn; }
65
66
 
67
+ void js_uv_nest(int delta) { call_depth += delta; }
68
+
69
+ bool js_uv_drain(void) {
70
+ if (failed) return false;
71
+ if (call_depth > 0) return true;
72
+ if (js_run_microtasks(loop_ctx) < 0) {
73
+ failed = loop_ctx->rt->failure;
74
+ uv_stop(loop);
75
+ return false;
76
+ }
77
+ flush();
78
+ return true;
79
+ }
80
+
66
81
  bool js_uv_call(JSValue fn, uint32_t argc, JSValue *argv, JSValue *result) {
67
82
  if (failed) return false;
68
83
  JSContext *ctx = loop_ctx;
69
- /* under no async context (ADR 0020): the prelude binds a callback to the one it was given in */
84
+ /* under no async context: the prelude binds a callback to the one it was given in */
70
85
  JSValue saved = js_async_context(ctx);
71
86
  js_set_async_context(ctx, JS_UNDEFINED);
87
+ call_depth++;
72
88
  JSValue r = js_call(ctx, fn, JS_UNDEFINED, argc, argv);
89
+ call_depth--;
73
90
  js_set_async_context(ctx, saved);
74
91
  if (js_is_exception(r)) {
75
92
  failed = js_report_uncaught(ctx);
@@ -79,6 +96,12 @@ bool js_uv_call(JSValue fn, uint32_t argc, JSValue *argv, JSValue *result) {
79
96
  }
80
97
  r = JS_UNDEFINED; /* handled ('uncaughtException'): the program goes on */
81
98
  }
99
+ /* microtasks run, and output goes out, when the outermost callback returns, as in Node: a call
100
+ * made while JS is running (a parser fed from a 'data' listener) leaves them to it */
101
+ if (call_depth > 0) {
102
+ if (result) *result = r;
103
+ return true;
104
+ }
82
105
  if (js_run_microtasks(ctx) < 0) {
83
106
  failed = ctx->rt->failure;
84
107
  uv_stop(loop);
@@ -22,6 +22,9 @@
22
22
  * netShutdown(id), netClose(id), netReset(id) → 0 | -errno, netRef(id, ref)
23
23
  * netAddress(id, peer) → [address, family, port] | path | -errno
24
24
  * netNoDelay(id, on), netKeepAlive(id, on, seconds) → 0 | -errno
25
+ * ttyOpen(fd, cb) → id | -errno a terminal's handle (node:tty's ReadStream), read as
26
+ * a stream; it answers the pipe-only calls as a pipe
27
+ * ttySetRawMode(id, raw) → 0 | -errno
25
28
  * dnsLookup(host, family, cb) → cb(errno, code, [[address, family], …]) */
26
29
  #define _POSIX_C_SOURCE 200809L /* libuv's headers: pthread_rwlock_t, struct addrinfo */
27
30
  #include <stdlib.h>
@@ -45,9 +48,11 @@ typedef struct NetHandle {
45
48
  uv_stream_t stream;
46
49
  uv_tcp_t tcp;
47
50
  uv_pipe_t pipe;
51
+ uv_tty_t tty;
48
52
  } u;
49
53
  int id;
50
- bool is_pipe;
54
+ bool is_pipe; /* a pipe's, or a terminal's (it has no address, nor TCP's options) */
55
+ bool is_tty;
51
56
  const JSNetHook *hook; /* node:http's parser, which reads before JS */
52
57
  void *hook_data;
53
58
  bool closing;
@@ -63,12 +68,8 @@ static void emit(NetHandle *h, int event, JSValue value) {
63
68
  (void)js_uv_call(h->cb, 2, args, NULL);
64
69
  }
65
70
 
66
- static NetHandle *new_handle(JSContext *ctx, bool is_pipe, JSValue cb) {
67
- NetHandle *h = calloc(1, sizeof *h);
68
- if (!h) js_fatal("out of memory in net");
69
- h->is_pipe = is_pipe;
70
- if (is_pipe) uv_pipe_init(js_uv_loop(ctx), &h->u.pipe, 0);
71
- else uv_tcp_init(js_uv_loop(ctx), &h->u.tcp);
71
+ /* An initialized handle, numbered, with its callback. */
72
+ static NetHandle *add_handle(JSContext *ctx, NetHandle *h, JSValue cb) {
72
73
  size_t id = 0;
73
74
  while (id < nhandles && handles[id]) id++;
74
75
  if (id == nhandles) {
@@ -86,6 +87,15 @@ static NetHandle *new_handle(JSContext *ctx, bool is_pipe, JSValue cb) {
86
87
  return h;
87
88
  }
88
89
 
90
+ static NetHandle *new_handle(JSContext *ctx, bool is_pipe, JSValue cb) {
91
+ NetHandle *h = calloc(1, sizeof *h);
92
+ if (!h) js_fatal("out of memory in net");
93
+ h->is_pipe = is_pipe;
94
+ if (is_pipe) uv_pipe_init(js_uv_loop(ctx), &h->u.pipe, 0);
95
+ else uv_tcp_init(js_uv_loop(ctx), &h->u.tcp);
96
+ return add_handle(ctx, h, cb);
97
+ }
98
+
89
99
  static void on_closed(uv_handle_t *uh) {
90
100
  NetHandle *h = (NetHandle *)uh;
91
101
  handles[h->id] = NULL;
@@ -414,6 +424,7 @@ HOST_FN(js_host_net_address) {
414
424
  NetHandle *h = handle_arg(argc, argv);
415
425
  if (!h) return js_int32(UV_EBADF);
416
426
  bool peer = argc > 1 && js_truthy(argv[1]);
427
+ if (h->is_tty) return js_int32(UV_ENOTSOCK);
417
428
  if (h->is_pipe) {
418
429
  char path[PATH_MAX_LEN];
419
430
  size_t n = sizeof path;
@@ -443,6 +454,43 @@ HOST_FN(js_host_net_keep_alive) {
443
454
  return js_int32(uv_tcp_keepalive(&h->u.tcp, argc > 1 && js_truthy(argv[1]), delay));
444
455
  }
445
456
 
457
+ /* ---- Terminals ----------------------------------------------------------------------------- */
458
+
459
+ static bool raw_mode_set;
460
+
461
+ static void reset_tty_mode(void) {
462
+ uv_tty_reset_mode();
463
+ }
464
+
465
+ /* ttyOpen(fd, cb) → id | -errno: a terminal's handle, read like a pipe's */
466
+ HOST_FN(js_host_tty_open) {
467
+ UNUSED;
468
+ if (argc < 1 || !js_is_int32(argv[0])) return js_int32(UV_EBADF);
469
+ NetHandle *h = calloc(1, sizeof *h);
470
+ if (!h) js_fatal("out of memory in net");
471
+ int r = uv_tty_init(js_uv_loop(ctx), &h->u.tty, js_as_int32(argv[0]), 0);
472
+ if (r < 0) {
473
+ free(h);
474
+ return js_int32(r);
475
+ }
476
+ h->is_pipe = true;
477
+ h->is_tty = true;
478
+ return js_int32(add_handle(ctx, h, argc > 1 ? argv[1] : JS_UNDEFINED)->id);
479
+ }
480
+
481
+ /* ttySetRawMode(id, raw) → 0 | -errno: keys as they're typed, unechoed; the terminal's mode is
482
+ * restored at exit, as Node's is */
483
+ HOST_FN(js_host_tty_set_raw_mode) {
484
+ UNUSED;
485
+ NetHandle *h = handle_arg(argc, argv);
486
+ if (!h || !h->is_tty) return js_int32(UV_EBADF);
487
+ if (!raw_mode_set) {
488
+ raw_mode_set = true;
489
+ atexit(reset_tty_mode);
490
+ }
491
+ return js_int32(uv_tty_set_mode(&h->u.tty, argc > 1 && js_truthy(argv[1]) ? UV_TTY_MODE_RAW : UV_TTY_MODE_NORMAL));
492
+ }
493
+
446
494
  /* ---- dns.lookup ---------------------------------------------------------------------------- */
447
495
 
448
496
  typedef struct Lookup {
@@ -1,10 +1,11 @@
1
- /* Host primitives for node:os (ADR 0012): the system's facts through libuv, as Node's os module
1
+ /* Host primitives for node:os: the system's facts through libuv, as Node's os module
2
2
  * gets them, and the constants (signals and errno numbers) of the platform the program was built
3
3
  * for. Failures return -errno, which the prelude turns into Node's SystemError. */
4
4
  #define _GNU_SOURCE /* libuv's headers, and every signal and errno name the platform has */
5
5
  #include "js_node.h"
6
6
 
7
7
  #include <errno.h>
8
+ #include <stdio.h>
8
9
  #include <signal.h>
9
10
  #include <stdlib.h>
10
11
  #include <string.h>
@@ -24,6 +25,59 @@ static JSValue array_of(JSContext *ctx, const JSValue *items, uint32_t n) {
24
25
  return a;
25
26
  }
26
27
 
28
+ /* osInterfaces(): [name, address, netmask, family (4 | 6), mac, internal, scopeid, …], 7 per
29
+ * address (uv_interface_addresses), or -errno. */
30
+ PRIMITIVE(js_host_os_interfaces) {
31
+ UNUSED_PRIMITIVE_ARGS;
32
+ uv_interface_address_t *list;
33
+ int count;
34
+ int r = uv_interface_addresses(&list, &count);
35
+ if (r < 0) return js_int32(r);
36
+ JSValue a = js_new_array(ctx, (uint32_t)count * 7);
37
+ for (int i = 0; i < count && !js_is_exception(a); i++) {
38
+ uv_interface_address_t *ia = &list[i];
39
+ char address[INET6_ADDRSTRLEN], netmask[INET6_ADDRSTRLEN], mac[18];
40
+ bool v6 = ia->address.address4.sin_family == AF_INET6;
41
+ if (v6) {
42
+ uv_ip6_name(&ia->address.address6, address, sizeof address);
43
+ uv_ip6_name(&ia->netmask.netmask6, netmask, sizeof netmask);
44
+ } else {
45
+ uv_ip4_name(&ia->address.address4, address, sizeof address);
46
+ uv_ip4_name(&ia->netmask.netmask4, netmask, sizeof netmask);
47
+ }
48
+ const unsigned char *m = (const unsigned char *)ia->phys_addr;
49
+ snprintf(mac, sizeof mac, "%02x:%02x:%02x:%02x:%02x:%02x", m[0], m[1], m[2], m[3], m[4], m[5]);
50
+ JSValue items[7] = {
51
+ js_new_string_cstr(ctx, ia->name), js_new_string_cstr(ctx, address), js_new_string_cstr(ctx, netmask),
52
+ js_int32(v6 ? 6 : 4), js_new_string_cstr(ctx, mac), js_bool(ia->is_internal),
53
+ js_number(v6 ? (double)ia->address.address6.sin6_scope_id : 0),
54
+ };
55
+ for (int k = 0; k < 7; k++) {
56
+ if (js_is_exception(items[k]) || js_array_append(ctx, a, items[k]) < 0) {
57
+ a = JS_EXCEPTION;
58
+ break;
59
+ }
60
+ }
61
+ }
62
+ uv_free_interface_addresses(list, count);
63
+ return a;
64
+ }
65
+
66
+ /* osGetPriority(pid) → priority | -errno */
67
+ PRIMITIVE(js_host_os_get_priority) {
68
+ (void)ctx, (void)callee, (void)this_val, (void)new_target;
69
+ int priority;
70
+ int r = uv_os_getpriority(argc > 0 && js_is_number(argv[0]) ? (uv_pid_t)js_as_number(argv[0]) : 0, &priority);
71
+ return js_int32(r < 0 ? r : priority);
72
+ }
73
+
74
+ /* osSetPriority(pid, priority) → 0 | -errno */
75
+ PRIMITIVE(js_host_os_set_priority) {
76
+ (void)ctx, (void)callee, (void)this_val, (void)new_target;
77
+ if (argc < 2 || !js_is_number(argv[0]) || !js_is_int32(argv[1])) return js_int32(UV_EINVAL);
78
+ return js_int32(uv_os_setpriority((uv_pid_t)js_as_number(argv[0]), js_as_int32(argv[1])));
79
+ }
80
+
27
81
  /* osUname(): [sysname, release, version, machine], or -errno. */
28
82
  PRIMITIVE(js_host_os_uname) {
29
83
  UNUSED_PRIMITIVE_ARGS;