visaljs 0.0.9 → 0.0.11

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 (232) hide show
  1. package/README.md +12 -4
  2. package/THIRD_PARTY_LICENSES +31 -1
  3. package/cli.js +3745 -890
  4. package/node/include/js_node.h +12 -1
  5. package/node/prelude/_http_common.js +29 -0
  6. package/node/prelude/async_hooks.js +50 -11
  7. package/node/prelude/child_process.js +31 -4
  8. package/node/prelude/console.js +311 -143
  9. package/node/prelude/crypto.js +6 -4
  10. package/node/prelude/dgram.js +1169 -0
  11. package/node/prelude/diagnostics_channel.js +3 -1
  12. package/node/prelude/dns.js +250 -45
  13. package/node/prelude/dns_promises.js +8 -2
  14. package/node/prelude/fs_promises.js +9 -1
  15. package/node/prelude/http.js +405 -94
  16. package/node/prelude/https.js +13 -4
  17. package/node/prelude/internal/console_class.js +7 -0
  18. package/node/prelude/internal/console_global.js +25 -0
  19. package/node/prelude/internal/crypto/key_encryption.js +217 -0
  20. package/node/prelude/internal/crypto/keys.js +161 -26
  21. package/node/prelude/internal/crypto/random.js +24 -0
  22. package/node/prelude/internal/crypto/util.js +2 -1
  23. package/node/prelude/internal/crypto_x509.js +161 -0
  24. package/node/prelude/internal/dns_classes.js +6 -0
  25. package/node/prelude/internal/dns_resolver.js +371 -0
  26. package/node/prelude/internal/errors.js +9 -0
  27. package/node/prelude/internal/events_on.js +82 -37
  28. package/node/prelude/internal/features.js +8 -4
  29. package/node/prelude/internal/fs_filehandle.js +10 -4
  30. package/node/prelude/internal/http_chars.ts +22 -0
  31. package/node/prelude/internal/perf_histogram.js +1 -1
  32. package/node/prelude/internal/process_more.js +32 -17
  33. package/node/prelude/internal/process_signals.js +8 -2
  34. package/node/prelude/internal/punycode.ts +163 -0
  35. package/node/prelude/internal/readline.js +648 -274
  36. package/node/prelude/internal/readline_editor.js +1240 -0
  37. package/node/prelude/internal/string_width.js +43 -0
  38. package/node/prelude/internal/tls/common.js +145 -33
  39. package/node/prelude/internal/tls/wrap.js +182 -49
  40. package/node/prelude/internal/tls/x509.js +4 -1
  41. package/node/prelude/internal/udp.js +177 -0
  42. package/node/prelude/net.js +30 -14
  43. package/node/prelude/os.js +24 -6
  44. package/node/prelude/perf_hooks.js +37 -2
  45. package/node/prelude/punycode.js +2 -130
  46. package/node/prelude/readline.js +113 -4
  47. package/node/prelude/readline_promises.js +56 -32
  48. package/node/prelude/tls.js +21 -4
  49. package/node/prelude/util.js +3 -16
  50. package/node/src/host_dns.c +623 -0
  51. package/node/src/host_http.c +12 -0
  52. package/node/src/host_net.c +46 -0
  53. package/node/src/host_os.c +1 -6
  54. package/node/src/host_sys.c +79 -0
  55. package/node/src/host_udp.c +418 -0
  56. package/node/third_party/c-ares/LICENSE.md +24 -0
  57. package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
  58. package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
  59. package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
  60. package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
  61. package/node/third_party/c-ares/include/ares.h +1237 -0
  62. package/node/third_party/c-ares/include/ares_build.h +202 -0
  63. package/node/third_party/c-ares/include/ares_dns.h +127 -0
  64. package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
  65. package/node/third_party/c-ares/include/ares_nameser.h +510 -0
  66. package/node/third_party/c-ares/include/ares_version.h +47 -0
  67. package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
  68. package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
  69. package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
  70. package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
  71. package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
  72. package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
  73. package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
  74. package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
  75. package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
  76. package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
  77. package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
  78. package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
  79. package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
  80. package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
  81. package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
  82. package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
  83. package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
  84. package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
  85. package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
  86. package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
  87. package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
  88. package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
  89. package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
  90. package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
  91. package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
  92. package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
  93. package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
  94. package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
  95. package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
  96. package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
  97. package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
  98. package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
  99. package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
  100. package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
  101. package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
  102. package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
  103. package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
  104. package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
  105. package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
  106. package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
  107. package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
  108. package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
  109. package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
  110. package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
  111. package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
  112. package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
  113. package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
  114. package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
  115. package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
  116. package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
  117. package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
  118. package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
  119. package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
  120. package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
  121. package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
  122. package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
  123. package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
  124. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
  125. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
  126. package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
  127. package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
  128. package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
  129. package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
  130. package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
  131. package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
  132. package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
  133. package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
  134. package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
  135. package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
  136. package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
  137. package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
  138. package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
  139. package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
  140. package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
  141. package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
  142. package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
  143. package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
  144. package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
  145. package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
  146. package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
  147. package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
  148. package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
  149. package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
  150. package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
  151. package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
  152. package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
  153. package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
  154. package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
  155. package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
  156. package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
  157. package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
  158. package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
  159. package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
  160. package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
  161. package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
  162. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
  163. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
  164. package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
  165. package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
  166. package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
  167. package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
  168. package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
  169. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
  170. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
  171. package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
  172. package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
  173. package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
  174. package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
  175. package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
  176. package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
  177. package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
  178. package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
  179. package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
  180. package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
  181. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
  182. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
  183. package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
  184. package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
  185. package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
  186. package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
  187. package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
  188. package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
  189. package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
  190. package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
  191. package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
  192. package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
  193. package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
  194. package/package.json +1 -1
  195. package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
  196. package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
  197. package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
  198. package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
  199. package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
  200. package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
  201. package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
  202. package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
  203. package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
  204. package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
  205. package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  206. package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
  207. package/runtime/include/js_buffer.h +185 -0
  208. package/runtime/include/js_builtins.h +58 -0
  209. package/runtime/include/js_crypto.h +11 -0
  210. package/runtime/include/js_exception.h +3 -0
  211. package/runtime/include/js_function.h +1 -1
  212. package/runtime/include/js_gc.h +13 -10
  213. package/runtime/include/js_jobs.h +2 -0
  214. package/runtime/include/js_object.h +79 -3
  215. package/runtime/include/js_ops.h +27 -0
  216. package/runtime/include/js_runtime.h +1 -0
  217. package/runtime/include/js_web.h +0 -3
  218. package/runtime/include/jscontext.h +8 -0
  219. package/runtime/src/builtins.c +17 -4
  220. package/runtime/src/crypto_internal.h +1 -0
  221. package/runtime/src/crypto_subtle.c +66 -7
  222. package/runtime/src/crypto_tls.c +265 -19
  223. package/runtime/src/function.c +37 -10
  224. package/runtime/src/gc.c +76 -93
  225. package/runtime/src/inspect.c +18 -1
  226. package/runtime/src/iterator.c +5 -1
  227. package/runtime/src/jobs.c +37 -22
  228. package/runtime/src/object.c +91 -8
  229. package/runtime/src/os.c +16 -6
  230. package/runtime/src/os.h +2 -0
  231. package/runtime/src/process.c +97 -10
  232. package/runtime/src/typedarray.c +23 -0
@@ -16,6 +16,7 @@ JSValue js_host_fs_stat(JSContext *ctx, JSValue callee, JSValue this_val, uint32
16
16
  JSValue js_host_fs_readdir(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
17
17
  JSValue js_host_fs_read_at(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
18
18
  JSValue js_host_process_memory(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
19
+ JSValue js_host_preview_entries(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
19
20
  JSValue js_host_fs_realpath(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
20
21
  JSValue js_host_fs_mkdir(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
21
22
  JSValue js_host_fs_utimes(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
@@ -31,6 +32,7 @@ JSValue js_host_fs_read(JSContext *ctx, JSValue callee, JSValue this_val, uint32
31
32
  int js_node_uv_error(int e);
32
33
  JSValue js_host_errno_name(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
33
34
  JSValue js_host_timer_unref(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
35
+ JSValue js_host_loop_now(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
34
36
  JSValue js_host_timer_start(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
35
37
  JSValue js_host_timer_ref(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
36
38
  JSValue js_host_async_context_get(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
@@ -86,12 +88,21 @@ JSValue js_host_net_keep_alive(JSContext *ctx, JSValue callee, JSValue this_val,
86
88
  JSValue js_host_tty_open(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
87
89
  JSValue js_host_tty_set_raw_mode(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
88
90
  JSValue js_host_dns_lookup(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
91
+ JSValue js_host_dns_lookup_service(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
92
+ JSValue js_host_dns_channel(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
93
+ JSValue js_host_dns_query(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
94
+ JSValue js_host_dns_reverse(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
95
+ JSValue js_host_dns_cancel(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
96
+ JSValue js_host_dns_get_servers(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
97
+ JSValue js_host_dns_set_servers(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
98
+ JSValue js_host_dns_set_local_address(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
99
+ JSValue js_host_dns_strerror(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
100
+ JSValue js_host_dns_parse(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
89
101
 
90
102
  /* host_os.c: node:os through libuv */
91
103
  JSValue js_host_os_uname(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
92
104
  JSValue js_host_os_hostname(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
93
105
  JSValue js_host_os_homedir(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
94
- JSValue js_host_os_tmpdir(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
95
106
  JSValue js_host_os_memory(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
96
107
  JSValue js_host_os_uptime(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
97
108
  JSValue js_host_os_loadavg(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
@@ -0,0 +1,29 @@
1
+ // node:_http_common: Node's module behind node:http, as its tests reach it: the header checks and
2
+ // the method list. Node's HTTPParser isn't here: llhttp runs in C (node/src/host_http.c).
3
+ import { hasInvalidHeaderChar, isHttpToken } from "./internal/http_chars.ts";
4
+ import { METHODS } from "./http.js";
5
+
6
+ /* Node's lenientHeaderCharRegex (httpValidation "relaxed"): only NUL, CR, LF and past 0xff */
7
+ function hasLenientInvalidChar(s) {
8
+ for (let i = 0; i < s.length; i++) {
9
+ const c = s.charCodeAt(i);
10
+ if (c === 0 || c === 10 || c === 13 || c > 255) return true;
11
+ }
12
+ return false;
13
+ }
14
+
15
+ export function _checkInvalidHeaderChar(val, lenient = false) {
16
+ const s = String(val);
17
+ return lenient ? hasLenientInvalidChar(s) : hasInvalidHeaderChar(s);
18
+ }
19
+
20
+ export function _checkIsHttpToken(val) {
21
+ return typeof val === "string" && isHttpToken(val);
22
+ }
23
+
24
+ export const methods = METHODS.slice().sort();
25
+ export const CRLF = "\r\n";
26
+ export const continueExpression = /(?:^|\W)100-continue(?:$|\W)/i;
27
+ export const chunkExpression = /(?:^|\W)chunked(?:$|\W)/i;
28
+
29
+ export default { _checkInvalidHeaderChar, _checkIsHttpToken, methods, CRLF, continueExpression, chunkExpression };
@@ -3,9 +3,17 @@
3
3
  // does; AsyncResource, which keeps the context it was created in for a callback (on-finished,
4
4
  // raw-body). Hooks never fire: visaljs has no async resources to report.
5
5
  import { currentContext, runInContext, setContext } from "./internal/async_context.js";
6
- import { invalidArgType, validateFunction, validateString } from "./internal/errors.js";
6
+ import { codeError, invalidArgType, invalidArgValue, validateFunction, validateString } from "./internal/errors.js";
7
7
 
8
8
  let nextAsyncId = 2; /* 1 is the main program's, as in Node */
9
+ let currentAsyncId = 1;
10
+ let currentTriggerAsyncId = 0;
11
+ /* enabled hooks with an init: Node checks a resource's type only then, when init would be told it */
12
+ let initHooks = 0;
13
+
14
+ function invalidAsyncId(name, id) {
15
+ return codeError(RangeError, "ERR_INVALID_ASYNC_ID", `Invalid ${name} value: ${id}`);
16
+ }
9
17
 
10
18
  export class AsyncResource {
11
19
  #asyncId;
@@ -14,13 +22,24 @@ export class AsyncResource {
14
22
 
15
23
  constructor(type, opts = {}) {
16
24
  validateString(type, "type");
25
+ const triggerAsyncId = typeof opts === "number" ? opts : (opts.triggerAsyncId ?? currentAsyncId);
26
+ if (!Number.isSafeInteger(triggerAsyncId) || triggerAsyncId < -1) throw invalidAsyncId("triggerAsyncId", triggerAsyncId);
27
+ if (initHooks > 0 && type.length === 0) throw codeError(TypeError, "ERR_ASYNC_TYPE", `Invalid name for async "type": ${type}`);
17
28
  this.#asyncId = nextAsyncId++;
18
- this.#triggerAsyncId = typeof opts === "number" ? opts : (opts.triggerAsyncId ?? 1);
29
+ this.#triggerAsyncId = triggerAsyncId;
19
30
  this.#context = currentContext();
20
31
  }
21
32
 
22
33
  runInAsyncScope(fn, thisArg, ...args) {
23
- return runInContext(this.#context, fn, thisArg, args);
34
+ const asyncId = currentAsyncId, triggerId = currentTriggerAsyncId;
35
+ currentAsyncId = this.#asyncId;
36
+ currentTriggerAsyncId = this.#triggerAsyncId;
37
+ try {
38
+ return runInContext(this.#context, fn, thisArg, args);
39
+ } finally {
40
+ currentAsyncId = asyncId;
41
+ currentTriggerAsyncId = triggerId;
42
+ }
24
43
  }
25
44
 
26
45
  emitDestroy() {
@@ -57,24 +76,39 @@ export class AsyncResource {
57
76
  }
58
77
 
59
78
  export function executionAsyncId() {
60
- return 1;
79
+ return currentAsyncId;
61
80
  }
62
81
 
63
82
  export function triggerAsyncId() {
64
- return 0;
83
+ return currentTriggerAsyncId;
65
84
  }
66
85
 
67
86
  export function executionAsyncResource() {
68
87
  return {};
69
88
  }
70
89
 
90
+ const hookNames = ["init", "before", "after", "destroy", "promiseResolve"];
91
+
71
92
  /** A hook that never fires: visaljs has no async resources to report. */
72
- export function createHook() {
93
+ export function createHook(hooks) {
94
+ for (const name of hookNames) {
95
+ if (hooks[name] !== undefined && typeof hooks[name] !== "function") throw codeError(TypeError, "ERR_ASYNC_CALLBACK", `hook.${name} must be a function`);
96
+ }
97
+ if (hooks.trackPromises !== undefined && typeof hooks.trackPromises !== "boolean") throw invalidArgType("trackPromises", "of type boolean", hooks.trackPromises);
98
+ if (hooks.trackPromises === false && hooks.promiseResolve) {
99
+ throw invalidArgValue("trackPromises", "must not be false when promiseResolve is enabled", false);
100
+ }
101
+ const hasInit = hooks.init !== undefined;
102
+ let enabled = false;
73
103
  return {
74
104
  enable() {
105
+ if (!enabled && hasInit) initHooks++;
106
+ enabled = true;
75
107
  return this;
76
108
  },
77
109
  disable() {
110
+ if (enabled && hasInit) initHooks--;
111
+ enabled = false;
78
112
  return this;
79
113
  },
80
114
  };
@@ -110,10 +144,7 @@ export class AsyncLocalStorage {
110
144
 
111
145
  /** (fn, ...args) => fn(...args) in the context current now. */
112
146
  static snapshot() {
113
- const resource = new AsyncResource("AsyncLocalStorageSnapshot");
114
- return function runInAsyncScope(fn, ...args) {
115
- return resource.runInAsyncScope(fn, this, ...args);
116
- };
147
+ return AsyncLocalStorage.bind((cb, ...args) => cb(...args));
117
148
  }
118
149
 
119
150
  disable() {
@@ -124,8 +155,16 @@ export class AsyncLocalStorage {
124
155
  setContext(new AsyncContextFrame(this, store));
125
156
  }
126
157
 
158
+ /* as Node's: only this storage's store is put back after, so another's enterWith in fn outlasts it */
127
159
  run(store, fn, ...args) {
128
- return runInContext(new AsyncContextFrame(this, store), fn, null, args);
160
+ const prior = this.getStore();
161
+ if (Object.is(prior, store)) return Reflect.apply(fn, null, args);
162
+ this.enterWith(store);
163
+ try {
164
+ return Reflect.apply(fn, null, args);
165
+ } finally {
166
+ this.enterWith(prior);
167
+ }
129
168
  }
130
169
 
131
170
  exit(fn, ...args) {
@@ -27,7 +27,7 @@
27
27
  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
28
28
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
29
29
  import {
30
- errnoName, netOpen, osConstants, processClose, processKillChild, processRef, processSpawn, processSpawnSync,
30
+ errnoName, netOpen, netReadStop, osConstants, processClose, processKillChild, processRef, processSpawn, processSpawnSync,
31
31
  utilInspect as inspect,
32
32
  } from "visaljs:host";
33
33
  import { Buffer } from "./buffer.js";
@@ -218,7 +218,7 @@ function getValidStdio(stdio, sync) {
218
218
  acc.push({ type: "fd", fd: typeof stdio === "number" ? stdio : stdio.fd });
219
219
  } else if (socketHandle(stdio) !== undefined || socketHandle(stdio.handle) !== undefined || socketHandle(stdio._handle) !== undefined) {
220
220
  const socket = socketHandle(stdio) !== undefined ? stdio : socketHandle(stdio.handle) !== undefined ? stdio.handle : stdio._handle;
221
- acc.push({ type: "wrap", handle: socket._handle, socket, _stdio: stdio });
221
+ acc.push({ type: "wrap", handle: socket._handle, wrapped: socket, _stdio: stdio }); /* not the child's own stream: stdin… stay null, as Node's */
222
222
  } else if (isArrayBufferView(stdio) || typeof stdio === "string") {
223
223
  if (!sync) {
224
224
  cleanup();
@@ -393,6 +393,10 @@ ChildProcess.prototype.spawn = function spawn(options) {
393
393
  // otherwise we might attempt to read from the stream when at the same time
394
394
  // the child process does.
395
395
  if (stream.type === "wrap") {
396
+ if (stream.wrapped._handle !== null) {
397
+ stream.wrapped._reading = false;
398
+ netReadStop(stream.wrapped._handle);
399
+ }
396
400
  stream._stdio.pause();
397
401
  stream._stdio.readableFlowing = false;
398
402
  stream._stdio._readableState.reading = false;
@@ -496,8 +500,31 @@ function maybeClose(subprocess) {
496
500
  // ---- The module (lib/child_process.js) ----------------------------------------------------
497
501
 
498
502
  /** Node's fork(): a Node running a module, with a channel to it. */
499
- export function fork() {
500
- throw notSupported("child_process.fork() (it starts a Node, which a compiled program doesn't have)");
503
+ /* Node's fork, as far as its checks: the arguments are validated as Node's (a bad one is the same
504
+ * error), then it can't start the Node it needs. Its body starts with the throw so that
505
+ * tests/compat/node.ts counts it a stub. */
506
+ export function fork(modulePath, args = [], options) {
507
+ throw notSupported(validateFork(modulePath, args, options));
508
+ }
509
+
510
+ function validateFork(modulePath, args, options) {
511
+ modulePath = getValidatedPath(modulePath, "modulePath");
512
+ if (args == null) {
513
+ args = [];
514
+ } else if (typeof args === "object" && !Array.isArray(args)) {
515
+ options = args;
516
+ args = [];
517
+ } else {
518
+ validateArray(args, "args");
519
+ }
520
+ if (options != null) validateObject(options, "options");
521
+ options = { __proto__: null, ...options, shell: false };
522
+ options.execPath ||= process.execPath;
523
+ validateArgumentNullCheck(options.execPath, "options.execPath");
524
+ const execArgv = options.execArgv || process.execArgv;
525
+ validateArgumentsNullCheck(execArgv, "options.execArgv");
526
+ normalizeSpawnArguments(options.execPath, [...execArgv, modulePath, ...args], options);
527
+ return "child_process.fork() (it starts a Node, which a compiled program doesn't have)";
501
528
  }
502
529
 
503
530
  export function _forkChild() {