visaljs 0.0.5 → 0.0.7

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 (433) hide show
  1. package/cli.js +469 -53
  2. package/node/include/js_node.h +36 -0
  3. package/node/prelude/async_hooks.js +63 -8
  4. package/node/prelude/buffer.js +0 -0
  5. package/node/prelude/diagnostics_channel.js +322 -0
  6. package/node/prelude/dns.js +3 -2
  7. package/node/prelude/events.js +17 -3
  8. package/node/prelude/fs.js +177 -5
  9. package/node/prelude/fs_promises.js +24 -0
  10. package/node/prelude/http.js +13 -4
  11. package/node/prelude/http2.js +0 -0
  12. package/node/prelude/internal/async_context.js +27 -0
  13. package/node/prelude/internal/crypto/asym.js +0 -0
  14. package/node/prelude/internal/crypto/cipher.js +0 -0
  15. package/node/prelude/internal/crypto/kdf.js +0 -0
  16. package/node/prelude/internal/crypto/keys.js +0 -0
  17. package/node/prelude/internal/crypto/random.js +0 -0
  18. package/node/prelude/internal/crypto/util.js +0 -0
  19. package/node/prelude/internal/errors.js +11 -0
  20. package/node/prelude/internal/process_events.js +14 -0
  21. package/node/prelude/internal/process_signals.js +42 -0
  22. package/node/prelude/internal/querystring.js +0 -0
  23. package/node/prelude/internal/timers.js +233 -0
  24. package/node/prelude/internal/timers_global.js +9 -0
  25. package/node/prelude/internal/zlib_brotli.js +6 -0
  26. package/node/prelude/internal/zlib_engines.js +4 -0
  27. package/node/prelude/internal/zlib_zstd.js +6 -0
  28. package/node/prelude/module.js +22 -6
  29. package/node/prelude/net.js +9 -8
  30. package/node/prelude/os.js +0 -0
  31. package/node/prelude/path.js +1599 -186
  32. package/node/prelude/path_posix.js +9 -0
  33. package/node/prelude/path_win32.js +9 -0
  34. package/node/prelude/process.js +3 -0
  35. package/node/prelude/querystring.js +0 -0
  36. package/node/prelude/stream.js +18 -6
  37. package/node/prelude/stream_promises.js +0 -0
  38. package/node/prelude/stream_web.js +0 -0
  39. package/node/prelude/string_decoder.js +0 -0
  40. package/node/prelude/timers.js +92 -0
  41. package/node/prelude/timers_promises.js +133 -0
  42. package/node/prelude/tty.js +0 -0
  43. package/node/prelude/url.js +0 -0
  44. package/node/prelude/util.js +0 -0
  45. package/node/prelude/zlib.js +912 -72
  46. package/node/src/host_brotli.c +157 -0
  47. package/node/src/host_fs.c +95 -1
  48. package/node/src/host_loop.c +10 -4
  49. package/node/src/host_os.c +0 -0
  50. package/node/src/host_signal.c +70 -0
  51. package/node/src/host_sys.c +50 -0
  52. package/node/src/host_zlib.c +314 -0
  53. package/node/src/host_zstd.c +179 -0
  54. package/node/third_party/brotli/LICENSE +19 -0
  55. package/node/third_party/brotli/common/constants.c +15 -0
  56. package/node/third_party/brotli/common/constants.h +201 -0
  57. package/node/third_party/brotli/common/context.c +156 -0
  58. package/node/third_party/brotli/common/context.h +113 -0
  59. package/node/third_party/brotli/common/dictionary.c +5916 -0
  60. package/node/third_party/brotli/common/dictionary.h +64 -0
  61. package/node/third_party/brotli/common/platform.c +23 -0
  62. package/node/third_party/brotli/common/platform.h +541 -0
  63. package/node/third_party/brotli/common/shared_dictionary.c +521 -0
  64. package/node/third_party/brotli/common/shared_dictionary_internal.h +75 -0
  65. package/node/third_party/brotli/common/transform.c +291 -0
  66. package/node/third_party/brotli/common/transform.h +85 -0
  67. package/node/third_party/brotli/common/version.h +51 -0
  68. package/node/third_party/brotli/dec/bit_reader.c +78 -0
  69. package/node/third_party/brotli/dec/bit_reader.h +423 -0
  70. package/node/third_party/brotli/dec/decode.c +2875 -0
  71. package/node/third_party/brotli/dec/huffman.c +342 -0
  72. package/node/third_party/brotli/dec/huffman.h +122 -0
  73. package/node/third_party/brotli/dec/prefix.h +733 -0
  74. package/node/third_party/brotli/dec/state.c +183 -0
  75. package/node/third_party/brotli/dec/state.h +400 -0
  76. package/node/third_party/brotli/enc/backward_references.c +207 -0
  77. package/node/third_party/brotli/enc/backward_references.h +40 -0
  78. package/node/third_party/brotli/enc/backward_references_hq.c +939 -0
  79. package/node/third_party/brotli/enc/backward_references_hq.h +96 -0
  80. package/node/third_party/brotli/enc/backward_references_inc.h +189 -0
  81. package/node/third_party/brotli/enc/bit_cost.c +36 -0
  82. package/node/third_party/brotli/enc/bit_cost.h +64 -0
  83. package/node/third_party/brotli/enc/bit_cost_inc.h +127 -0
  84. package/node/third_party/brotli/enc/block_encoder_inc.h +34 -0
  85. package/node/third_party/brotli/enc/block_splitter.c +217 -0
  86. package/node/third_party/brotli/enc/block_splitter.h +52 -0
  87. package/node/third_party/brotli/enc/block_splitter_inc.h +481 -0
  88. package/node/third_party/brotli/enc/brotli_bit_stream.c +1336 -0
  89. package/node/third_party/brotli/enc/brotli_bit_stream.h +89 -0
  90. package/node/third_party/brotli/enc/cluster.c +57 -0
  91. package/node/third_party/brotli/enc/cluster.h +49 -0
  92. package/node/third_party/brotli/enc/cluster_inc.h +325 -0
  93. package/node/third_party/brotli/enc/command.c +28 -0
  94. package/node/third_party/brotli/enc/command.h +191 -0
  95. package/node/third_party/brotli/enc/compound_dictionary.c +207 -0
  96. package/node/third_party/brotli/enc/compound_dictionary.h +74 -0
  97. package/node/third_party/brotli/enc/compress_fragment.c +800 -0
  98. package/node/third_party/brotli/enc/compress_fragment.h +86 -0
  99. package/node/third_party/brotli/enc/compress_fragment_two_pass.c +657 -0
  100. package/node/third_party/brotli/enc/compress_fragment_two_pass.h +72 -0
  101. package/node/third_party/brotli/enc/dictionary_hash.c +1848 -0
  102. package/node/third_party/brotli/enc/dictionary_hash.h +25 -0
  103. package/node/third_party/brotli/enc/encode.c +1996 -0
  104. package/node/third_party/brotli/enc/encoder_dict.c +640 -0
  105. package/node/third_party/brotli/enc/encoder_dict.h +157 -0
  106. package/node/third_party/brotli/enc/entropy_encode.c +504 -0
  107. package/node/third_party/brotli/enc/entropy_encode.h +123 -0
  108. package/node/third_party/brotli/enc/entropy_encode_static.h +542 -0
  109. package/node/third_party/brotli/enc/fast_log.c +105 -0
  110. package/node/third_party/brotli/enc/fast_log.h +67 -0
  111. package/node/third_party/brotli/enc/find_match_length.h +72 -0
  112. package/node/third_party/brotli/enc/hash.h +728 -0
  113. package/node/third_party/brotli/enc/hash_composite_inc.h +140 -0
  114. package/node/third_party/brotli/enc/hash_forgetful_chain_inc.h +295 -0
  115. package/node/third_party/brotli/enc/hash_longest_match64_inc.h +262 -0
  116. package/node/third_party/brotli/enc/hash_longest_match_inc.h +258 -0
  117. package/node/third_party/brotli/enc/hash_longest_match_quickly_inc.h +266 -0
  118. package/node/third_party/brotli/enc/hash_rolling_inc.h +212 -0
  119. package/node/third_party/brotli/enc/hash_to_binary_tree_inc.h +330 -0
  120. package/node/third_party/brotli/enc/histogram.c +100 -0
  121. package/node/third_party/brotli/enc/histogram.h +64 -0
  122. package/node/third_party/brotli/enc/histogram_inc.h +51 -0
  123. package/node/third_party/brotli/enc/literal_cost.c +180 -0
  124. package/node/third_party/brotli/enc/literal_cost.h +32 -0
  125. package/node/third_party/brotli/enc/memory.c +194 -0
  126. package/node/third_party/brotli/enc/memory.h +131 -0
  127. package/node/third_party/brotli/enc/metablock.c +677 -0
  128. package/node/third_party/brotli/enc/metablock.h +106 -0
  129. package/node/third_party/brotli/enc/metablock_inc.h +185 -0
  130. package/node/third_party/brotli/enc/params.h +47 -0
  131. package/node/third_party/brotli/enc/prefix.h +54 -0
  132. package/node/third_party/brotli/enc/quality.h +202 -0
  133. package/node/third_party/brotli/enc/ringbuffer.h +168 -0
  134. package/node/third_party/brotli/enc/state.h +104 -0
  135. package/node/third_party/brotli/enc/static_dict.c +542 -0
  136. package/node/third_party/brotli/enc/static_dict.h +41 -0
  137. package/node/third_party/brotli/enc/static_dict_lut.h +5866 -0
  138. package/node/third_party/brotli/enc/utf8_util.c +85 -0
  139. package/node/third_party/brotli/enc/utf8_util.h +33 -0
  140. package/node/third_party/brotli/enc/write_bits.h +88 -0
  141. package/node/third_party/brotli/include/brotli/decode.h +409 -0
  142. package/node/third_party/brotli/include/brotli/encode.h +501 -0
  143. package/node/third_party/brotli/include/brotli/port.h +305 -0
  144. package/node/third_party/brotli/include/brotli/shared_dictionary.h +100 -0
  145. package/node/third_party/brotli/include/brotli/types.h +83 -0
  146. package/node/third_party/libuv/LICENSE +0 -0
  147. package/node/third_party/libuv/include/uv/aix.h +0 -0
  148. package/node/third_party/libuv/include/uv/bsd.h +0 -0
  149. package/node/third_party/libuv/include/uv/darwin.h +0 -0
  150. package/node/third_party/libuv/include/uv/errno.h +0 -0
  151. package/node/third_party/libuv/include/uv/linux.h +0 -0
  152. package/node/third_party/libuv/include/uv/os390.h +0 -0
  153. package/node/third_party/libuv/include/uv/posix.h +0 -0
  154. package/node/third_party/libuv/include/uv/sunos.h +0 -0
  155. package/node/third_party/libuv/include/uv/threadpool.h +0 -0
  156. package/node/third_party/libuv/include/uv/tree.h +0 -0
  157. package/node/third_party/libuv/include/uv/unix.h +0 -0
  158. package/node/third_party/libuv/include/uv/version.h +0 -0
  159. package/node/third_party/libuv/include/uv/win.h +0 -0
  160. package/node/third_party/libuv/include/uv.h +0 -0
  161. package/node/third_party/libuv/src/fs-poll.c +0 -0
  162. package/node/third_party/libuv/src/heap-inl.h +0 -0
  163. package/node/third_party/libuv/src/idna.c +0 -0
  164. package/node/third_party/libuv/src/idna.h +0 -0
  165. package/node/third_party/libuv/src/inet.c +0 -0
  166. package/node/third_party/libuv/src/queue.h +0 -0
  167. package/node/third_party/libuv/src/random.c +0 -0
  168. package/node/third_party/libuv/src/strscpy.c +0 -0
  169. package/node/third_party/libuv/src/strscpy.h +0 -0
  170. package/node/third_party/libuv/src/strtok.c +0 -0
  171. package/node/third_party/libuv/src/strtok.h +0 -0
  172. package/node/third_party/libuv/src/thread-common.c +0 -0
  173. package/node/third_party/libuv/src/threadpool.c +0 -0
  174. package/node/third_party/libuv/src/timer.c +0 -0
  175. package/node/third_party/libuv/src/unix/async.c +0 -0
  176. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
  177. package/node/third_party/libuv/src/unix/core.c +0 -0
  178. package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
  179. package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
  180. package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
  181. package/node/third_party/libuv/src/unix/darwin.c +0 -0
  182. package/node/third_party/libuv/src/unix/dl.c +0 -0
  183. package/node/third_party/libuv/src/unix/fs.c +0 -0
  184. package/node/third_party/libuv/src/unix/fsevents.c +0 -0
  185. package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
  186. package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
  187. package/node/third_party/libuv/src/unix/internal.h +0 -0
  188. package/node/third_party/libuv/src/unix/kqueue.c +0 -0
  189. package/node/third_party/libuv/src/unix/linux.c +0 -0
  190. package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
  191. package/node/third_party/libuv/src/unix/loop.c +0 -0
  192. package/node/third_party/libuv/src/unix/pipe.c +0 -0
  193. package/node/third_party/libuv/src/unix/poll.c +0 -0
  194. package/node/third_party/libuv/src/unix/process.c +0 -0
  195. package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
  196. package/node/third_party/libuv/src/unix/proctitle.c +0 -0
  197. package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
  198. package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
  199. package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
  200. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
  201. package/node/third_party/libuv/src/unix/signal.c +0 -0
  202. package/node/third_party/libuv/src/unix/stream.c +0 -0
  203. package/node/third_party/libuv/src/unix/tcp.c +0 -0
  204. package/node/third_party/libuv/src/unix/thread.c +0 -0
  205. package/node/third_party/libuv/src/unix/tty.c +0 -0
  206. package/node/third_party/libuv/src/unix/udp.c +0 -0
  207. package/node/third_party/libuv/src/uv-common.c +0 -0
  208. package/node/third_party/libuv/src/uv-common.h +0 -0
  209. package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
  210. package/node/third_party/libuv/src/version.c +0 -0
  211. package/node/third_party/llhttp/LICENSE +0 -0
  212. package/node/third_party/llhttp/api.c +0 -0
  213. package/node/third_party/llhttp/http.c +0 -0
  214. package/node/third_party/llhttp/llhttp.c +0 -0
  215. package/node/third_party/llhttp/llhttp.h +0 -0
  216. package/node/third_party/zlib/LICENSE +19 -0
  217. package/node/third_party/zlib/README.chromium +38 -0
  218. package/node/third_party/zlib/adler32.c +197 -0
  219. package/node/third_party/zlib/chromeconf.h +203 -0
  220. package/node/third_party/zlib/contrib/optimizations/insert_string.h +80 -0
  221. package/node/third_party/zlib/cpu_features.c +213 -0
  222. package/node/third_party/zlib/cpu_features.h +22 -0
  223. package/node/third_party/zlib/crc32.c +1192 -0
  224. package/node/third_party/zlib/crc32.h +9446 -0
  225. package/node/third_party/zlib/deflate.c +2289 -0
  226. package/node/third_party/zlib/deflate.h +407 -0
  227. package/node/third_party/zlib/gzguts.h +214 -0
  228. package/node/third_party/zlib/inffast.c +327 -0
  229. package/node/third_party/zlib/inffast.h +26 -0
  230. package/node/third_party/zlib/inffixed.h +94 -0
  231. package/node/third_party/zlib/inflate.c +1528 -0
  232. package/node/third_party/zlib/inflate.h +126 -0
  233. package/node/third_party/zlib/inftrees.c +299 -0
  234. package/node/third_party/zlib/inftrees.h +62 -0
  235. package/node/third_party/zlib/trees.c +1161 -0
  236. package/node/third_party/zlib/trees.h +128 -0
  237. package/node/third_party/zlib/zconf.h +558 -0
  238. package/node/third_party/zlib/zlib.h +1967 -0
  239. package/node/third_party/zlib/zutil.c +299 -0
  240. package/node/third_party/zlib/zutil.h +275 -0
  241. package/node/third_party/zstd/LICENSE +30 -0
  242. package/node/third_party/zstd/common/allocations.h +55 -0
  243. package/node/third_party/zstd/common/bits.h +205 -0
  244. package/node/third_party/zstd/common/bitstream.h +454 -0
  245. package/node/third_party/zstd/common/compiler.h +464 -0
  246. package/node/third_party/zstd/common/cpu.h +249 -0
  247. package/node/third_party/zstd/common/debug.c +30 -0
  248. package/node/third_party/zstd/common/debug.h +107 -0
  249. package/node/third_party/zstd/common/entropy_common.c +340 -0
  250. package/node/third_party/zstd/common/error_private.c +64 -0
  251. package/node/third_party/zstd/common/error_private.h +158 -0
  252. package/node/third_party/zstd/common/fse.h +625 -0
  253. package/node/third_party/zstd/common/fse_decompress.c +315 -0
  254. package/node/third_party/zstd/common/huf.h +277 -0
  255. package/node/third_party/zstd/common/mem.h +422 -0
  256. package/node/third_party/zstd/common/pool.c +371 -0
  257. package/node/third_party/zstd/common/pool.h +81 -0
  258. package/node/third_party/zstd/common/portability_macros.h +171 -0
  259. package/node/third_party/zstd/common/threading.c +182 -0
  260. package/node/third_party/zstd/common/threading.h +142 -0
  261. package/node/third_party/zstd/common/xxhash.c +18 -0
  262. package/node/third_party/zstd/common/xxhash.h +7094 -0
  263. package/node/third_party/zstd/common/zstd_common.c +48 -0
  264. package/node/third_party/zstd/common/zstd_deps.h +123 -0
  265. package/node/third_party/zstd/common/zstd_internal.h +324 -0
  266. package/node/third_party/zstd/common/zstd_trace.h +156 -0
  267. package/node/third_party/zstd/compress/clevels.h +134 -0
  268. package/node/third_party/zstd/compress/fse_compress.c +625 -0
  269. package/node/third_party/zstd/compress/hist.c +191 -0
  270. package/node/third_party/zstd/compress/hist.h +82 -0
  271. package/node/third_party/zstd/compress/huf_compress.c +1464 -0
  272. package/node/third_party/zstd/compress/zstd_compress.c +7843 -0
  273. package/node/third_party/zstd/compress/zstd_compress_internal.h +1636 -0
  274. package/node/third_party/zstd/compress/zstd_compress_literals.c +235 -0
  275. package/node/third_party/zstd/compress/zstd_compress_literals.h +39 -0
  276. package/node/third_party/zstd/compress/zstd_compress_sequences.c +442 -0
  277. package/node/third_party/zstd/compress/zstd_compress_sequences.h +55 -0
  278. package/node/third_party/zstd/compress/zstd_compress_superblock.c +688 -0
  279. package/node/third_party/zstd/compress/zstd_compress_superblock.h +32 -0
  280. package/node/third_party/zstd/compress/zstd_cwksp.h +765 -0
  281. package/node/third_party/zstd/compress/zstd_double_fast.c +778 -0
  282. package/node/third_party/zstd/compress/zstd_double_fast.h +42 -0
  283. package/node/third_party/zstd/compress/zstd_fast.c +985 -0
  284. package/node/third_party/zstd/compress/zstd_fast.h +30 -0
  285. package/node/third_party/zstd/compress/zstd_lazy.c +2199 -0
  286. package/node/third_party/zstd/compress/zstd_lazy.h +193 -0
  287. package/node/third_party/zstd/compress/zstd_ldm.c +745 -0
  288. package/node/third_party/zstd/compress/zstd_ldm.h +109 -0
  289. package/node/third_party/zstd/compress/zstd_ldm_geartab.h +106 -0
  290. package/node/third_party/zstd/compress/zstd_opt.c +1580 -0
  291. package/node/third_party/zstd/compress/zstd_opt.h +72 -0
  292. package/node/third_party/zstd/compress/zstd_preSplit.c +238 -0
  293. package/node/third_party/zstd/compress/zstd_preSplit.h +33 -0
  294. package/node/third_party/zstd/compress/zstdmt_compress.c +1923 -0
  295. package/node/third_party/zstd/compress/zstdmt_compress.h +102 -0
  296. package/node/third_party/zstd/decompress/huf_decompress.c +1944 -0
  297. package/node/third_party/zstd/decompress/zstd_ddict.c +244 -0
  298. package/node/third_party/zstd/decompress/zstd_ddict.h +44 -0
  299. package/node/third_party/zstd/decompress/zstd_decompress.c +2410 -0
  300. package/node/third_party/zstd/decompress/zstd_decompress_block.c +2209 -0
  301. package/node/third_party/zstd/decompress/zstd_decompress_block.h +73 -0
  302. package/node/third_party/zstd/decompress/zstd_decompress_internal.h +240 -0
  303. package/node/third_party/zstd/zdict.h +481 -0
  304. package/node/third_party/zstd/zstd.h +3198 -0
  305. package/node/third_party/zstd/zstd_errors.h +107 -0
  306. package/package.json +1 -6
  307. package/runtime/include/js_atoms.gen.h +0 -0
  308. package/runtime/include/js_atoms.h +0 -0
  309. package/runtime/include/js_bigint.h +0 -0
  310. package/runtime/include/js_buffer.h +0 -0
  311. package/runtime/include/js_builtins.h +0 -0
  312. package/runtime/include/js_console.h +5 -2
  313. package/runtime/include/js_convert.h +0 -0
  314. package/runtime/include/js_core.def +0 -0
  315. package/runtime/include/js_error.h +0 -0
  316. package/runtime/include/js_exception.h +0 -0
  317. package/runtime/include/js_function.h +0 -0
  318. package/runtime/include/js_gc.h +0 -0
  319. package/runtime/include/js_generator.h +0 -0
  320. package/runtime/include/js_host.h +5 -3
  321. package/runtime/include/js_jobs.h +18 -1
  322. package/runtime/include/js_module.h +0 -0
  323. package/runtime/include/js_object.h +0 -0
  324. package/runtime/include/js_ops.h +0 -0
  325. package/runtime/include/js_promise.h +1 -0
  326. package/runtime/include/js_regexp.h +0 -0
  327. package/runtime/include/js_runtime.h +0 -0
  328. package/runtime/include/js_symbol.h +0 -0
  329. package/runtime/include/js_web.h +0 -0
  330. package/runtime/include/jscell.h +0 -0
  331. package/runtime/include/jscontext.h +14 -0
  332. package/runtime/include/jsnum.h +0 -0
  333. package/runtime/include/jsstring.h +0 -0
  334. package/runtime/include/jsvalue.h +0 -0
  335. package/runtime/src/arguments.c +0 -0
  336. package/runtime/src/array.c +0 -0
  337. package/runtime/src/arraybuffer.c +0 -0
  338. package/runtime/src/async_iter.c +0 -0
  339. package/runtime/src/atoms.c +0 -0
  340. package/runtime/src/base64.c +0 -0
  341. package/runtime/src/bigint.c +0 -0
  342. package/runtime/src/blob.c +0 -0
  343. package/runtime/src/buffer.c +20 -16
  344. package/runtime/src/builtin_table.c +0 -0
  345. package/runtime/src/builtins.c +0 -0
  346. package/runtime/src/builtins_util.h +0 -0
  347. package/runtime/src/collections.c +0 -0
  348. package/runtime/src/components.c +0 -0
  349. package/runtime/src/console.c +15 -2
  350. package/runtime/src/convert.c +0 -0
  351. package/runtime/src/core_all.c +0 -0
  352. package/runtime/src/crypto.c +0 -0
  353. package/runtime/src/crypto_host.c +0 -0
  354. package/runtime/src/crypto_kdf.c +0 -0
  355. package/runtime/src/crypto_key.c +0 -0
  356. package/runtime/src/date.c +0 -0
  357. package/runtime/src/domexception.c +0 -0
  358. package/runtime/src/elements.c +0 -0
  359. package/runtime/src/elements.h +0 -0
  360. package/runtime/src/encoding.c +0 -0
  361. package/runtime/src/error.c +0 -0
  362. package/runtime/src/events.c +1 -1
  363. package/runtime/src/exception.c +0 -0
  364. package/runtime/src/fetch.c +0 -0
  365. package/runtime/src/function.c +0 -0
  366. package/runtime/src/gc.c +2 -0
  367. package/runtime/src/generator.c +0 -0
  368. package/runtime/src/global.c +0 -0
  369. package/runtime/src/headers.c +0 -0
  370. package/runtime/src/inspect.c +0 -0
  371. package/runtime/src/internal.h +0 -0
  372. package/runtime/src/iterate.c +0 -0
  373. package/runtime/src/iterator.c +0 -0
  374. package/runtime/src/jobs.c +123 -44
  375. package/runtime/src/jsnum.c +0 -0
  376. package/runtime/src/json.c +0 -0
  377. package/runtime/src/math.c +0 -0
  378. package/runtime/src/module.c +0 -0
  379. package/runtime/src/number.c +0 -0
  380. package/runtime/src/object.c +0 -0
  381. package/runtime/src/ops.c +0 -0
  382. package/runtime/src/os.c +0 -0
  383. package/runtime/src/os.h +0 -0
  384. package/runtime/src/process.c +92 -8
  385. package/runtime/src/promise.c +7 -2
  386. package/runtime/src/proxy.c +0 -0
  387. package/runtime/src/reflect.c +0 -0
  388. package/runtime/src/regexp.c +0 -0
  389. package/runtime/src/regexp_anchor.h +0 -0
  390. package/runtime/src/regexp_message.h +0 -0
  391. package/runtime/src/shape.c +0 -0
  392. package/runtime/src/shape.h +0 -0
  393. package/runtime/src/streams.c +0 -0
  394. package/runtime/src/streams.h +0 -0
  395. package/runtime/src/string.c +0 -0
  396. package/runtime/src/string_builtins.c +0 -0
  397. package/runtime/src/symbol.c +0 -0
  398. package/runtime/src/test_host.c +0 -0
  399. package/runtime/src/typedarray.c +0 -0
  400. package/runtime/src/tznames.gen.h +0 -0
  401. package/runtime/src/uri.c +0 -0
  402. package/runtime/src/url.c +0 -0
  403. package/runtime/src/weak.c +1 -4
  404. package/runtime/src/web.c +0 -0
  405. package/runtime/src/wrapper.c +0 -0
  406. package/runtime/src/writable.c +0 -0
  407. package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
  408. package/runtime/third_party/ada-idna/README.md +0 -0
  409. package/runtime/third_party/ada-idna/convert.mjs +0 -0
  410. package/runtime/third_party/ada-idna/idna.c +0 -0
  411. package/runtime/third_party/ada-idna/idna.h +0 -0
  412. package/runtime/third_party/ada-idna/idna_tables.h +0 -0
  413. package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
  414. package/runtime/third_party/quickjs-dtoa/README.md +0 -0
  415. package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
  416. package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
  417. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
  418. package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
  419. package/runtime/third_party/quickjs-regexp/README.md +0 -0
  420. package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
  421. package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
  422. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
  423. package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
  424. package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
  425. package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
  426. package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
  427. package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
  428. package/runtime/third_party/v8-ieee754/LICENSE +0 -0
  429. package/runtime/third_party/v8-ieee754/README.md +0 -0
  430. package/runtime/third_party/v8-ieee754/convert.py +0 -0
  431. package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
  432. package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
  433. package/runtime/tools/regexp_compile.c +0 -0
@@ -0,0 +1,157 @@
1
+ /* Host primitives for node:zlib's Brotli streams (ADR 0012): Node's binding (src/node_zlib.cc, its
2
+ * BrotliEncoderContext and BrotliDecoderContext) over Brotli 1.1.0, the copy Node vendors. As
3
+ * host_zlib.c: a stream is a handle object, and a failure is [message, errno, code]. */
4
+ #include <stdio.h>
5
+ #include <stdlib.h>
6
+ #include <string.h>
7
+
8
+ #include "brotli/decode.h"
9
+ #include "brotli/encode.h"
10
+ #include "js_buffer.h"
11
+ #include "js_exception.h"
12
+ #include "js_node.h"
13
+ #include "js_object.h"
14
+ #include "js_ops.h"
15
+ #include "jsstring.h"
16
+
17
+ #define PRIMITIVE(fn) \
18
+ JSValue fn(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target)
19
+ #define UNUSED_PRIMITIVE_ARGS (void)callee, (void)this_val, (void)new_target
20
+ #define ARG(i) ((i) < argc ? argv[i] : JS_UNDEFINED)
21
+
22
+ /* Node's node_zlib_mode */
23
+ enum { BROTLI_DECODE = 8, BROTLI_ENCODE = 9 };
24
+
25
+ typedef struct BrotliObject {
26
+ JSObject obj;
27
+ int mode;
28
+ BrotliEncoderState *encoder;
29
+ BrotliDecoderState *decoder;
30
+ int flush;
31
+ bool encode_result; /* the encoder's last result */
32
+ BrotliDecoderResult decode_result;
33
+ BrotliDecoderErrorCode error;
34
+ } BrotliObject;
35
+
36
+ static void brotli_end(BrotliObject *b) {
37
+ if (b->encoder) BrotliEncoderDestroyInstance(b->encoder);
38
+ if (b->decoder) BrotliDecoderDestroyInstance(b->decoder);
39
+ b->encoder = NULL;
40
+ b->decoder = NULL;
41
+ }
42
+
43
+ static void brotli_finalize(JSRuntime *rt, JSCell *cell) {
44
+ (void)rt;
45
+ brotli_end((BrotliObject *)cell);
46
+ }
47
+
48
+ static const JSClass brotli_class = { "BrotliHandle", sizeof(BrotliObject), NULL, NULL, NULL, NULL, NULL, brotli_finalize, NULL };
49
+
50
+ static BrotliObject *brotli_arg(JSValue v) {
51
+ return js_is_object(v) && js_as_object(v)->shape->cls == &brotli_class ? (BrotliObject *)js_as_object(v) : NULL;
52
+ }
53
+
54
+ static JSValue failure(JSContext *ctx, const char *message, int err, const char *code) {
55
+ JSValue items[3] = { js_new_string_cstr(ctx, message), js_int32(err), js_new_string_cstr(ctx, code) };
56
+ JSValue a = js_new_array(ctx, 3);
57
+ for (int i = 0; i < 3; i++)
58
+ if (js_array_append(ctx, a, items[i]) < 0) return JS_EXCEPTION;
59
+ return a;
60
+ }
61
+
62
+ /* Init (and ResetStream, which is Init again: the parameters set before are gone, as in Node) */
63
+ static bool brotli_init(BrotliObject *b) {
64
+ brotli_end(b);
65
+ if (b->mode == BROTLI_ENCODE) b->encoder = BrotliEncoderCreateInstance(NULL, NULL, NULL);
66
+ else b->decoder = BrotliDecoderCreateInstance(NULL, NULL, NULL);
67
+ return b->encoder || b->decoder;
68
+ }
69
+
70
+ /* brotliNew(mode) → handle */
71
+ PRIMITIVE(js_host_brotli_new) {
72
+ UNUSED_PRIMITIVE_ARGS;
73
+ BrotliObject *b = (BrotliObject *)js_alloc_object(ctx, JS_CELL_OBJECT, js_shape_root(ctx, &brotli_class, JS_NULL, 0));
74
+ b->mode = js_is_number(ARG(0)) && js_as_number(ARG(0)) == BROTLI_ENCODE ? BROTLI_ENCODE : BROTLI_DECODE;
75
+ b->encoder = NULL;
76
+ b->decoder = NULL;
77
+ b->flush = BROTLI_OPERATION_PROCESS;
78
+ b->encode_result = false;
79
+ b->decode_result = BROTLI_DECODER_RESULT_SUCCESS;
80
+ b->error = BROTLI_DECODER_NO_ERROR;
81
+ return js_object_value(&b->obj);
82
+ }
83
+
84
+ /* brotliInit(handle, params): params a Uint32Array, by parameter number, 0xffffffff unset →
85
+ * 0 | failure */
86
+ PRIMITIVE(js_host_brotli_init) {
87
+ UNUSED_PRIMITIVE_ARGS;
88
+ BrotliObject *b = brotli_arg(ARG(0));
89
+ uint8_t *p;
90
+ size_t n;
91
+ if (!b || !js_buffer_source_bytes(ARG(1), &p, &n)) return js_throw_type_error(ctx, "brotliInit: a handle and parameters expected");
92
+ if (!brotli_init(b)) return failure(ctx, "Could not initialize Brotli instance", -1, "ERR_ZLIB_INITIALIZATION_FAILED");
93
+ for (size_t i = 0; i < n / sizeof(uint32_t); i++) {
94
+ uint32_t value;
95
+ memcpy(&value, p + i * sizeof value, sizeof value);
96
+ if (value == UINT32_MAX) continue;
97
+ bool ok = b->encoder ? BrotliEncoderSetParameter(b->encoder, (BrotliEncoderParameter)i, value)
98
+ : BrotliDecoderSetParameter(b->decoder, (BrotliDecoderParameter)i, value);
99
+ if (!ok) return failure(ctx, "Setting parameter failed", -1, "ERR_BROTLI_PARAM_SET_FAILED");
100
+ }
101
+ return js_int32(0);
102
+ }
103
+
104
+ /* brotliWrite(handle, flush, in | null, inOff, inLen, out, outOff, outLen, state) → 0, with state
105
+ * [availOut, availIn] after it, or a failure */
106
+ PRIMITIVE(js_host_brotli_write) {
107
+ UNUSED_PRIMITIVE_ARGS;
108
+ BrotliObject *b = brotli_arg(ARG(0));
109
+ uint8_t *in = NULL, *out, *state;
110
+ size_t in_n = 0, out_n, state_n;
111
+ if (!b || (!b->encoder && !b->decoder) || (!js_is_null(ARG(2)) && !js_buffer_source_bytes(ARG(2), &in, &in_n))
112
+ || !js_buffer_source_bytes(ARG(5), &out, &out_n) || !js_buffer_source_bytes(ARG(8), &state, &state_n) || state_n < 2 * sizeof(uint32_t))
113
+ return js_throw_type_error(ctx, "brotliWrite: a handle, buffers and a state expected");
114
+ double in_off = in ? js_as_number(ARG(3)) : 0, in_len = in ? js_as_number(ARG(4)) : 0;
115
+ double out_off = js_as_number(ARG(6)), out_len = js_as_number(ARG(7));
116
+ if (!(in_off >= 0 && in_len >= 0 && in_off + in_len <= (double)in_n && out_off >= 0 && out_len >= 0 && out_off + out_len <= (double)out_n))
117
+ return js_throw_range_error(ctx, "brotliWrite: out of bounds");
118
+ const uint8_t *next_in = in ? in + (size_t)in_off : NULL;
119
+ uint8_t *next_out = out + (size_t)out_off;
120
+ size_t avail_in = (size_t)in_len, avail_out = (size_t)out_len;
121
+ b->flush = js_is_number(ARG(1)) ? (int)js_as_number(ARG(1)) : BROTLI_OPERATION_PROCESS;
122
+ if (b->encoder) {
123
+ b->encode_result = BrotliEncoderCompressStream(b->encoder, (BrotliEncoderOperation)b->flush, &avail_in, &next_in, &avail_out, &next_out, NULL);
124
+ if (!b->encode_result) return failure(ctx, "Compression failed", -1, "ERR_BROTLI_COMPRESSION_FAILED");
125
+ } else {
126
+ b->decode_result = BrotliDecoderDecompressStream(b->decoder, &avail_in, &next_in, &avail_out, &next_out, NULL);
127
+ if (b->decode_result == BROTLI_DECODER_RESULT_ERROR) b->error = BrotliDecoderGetErrorCode(b->decoder);
128
+ if (b->error != BROTLI_DECODER_NO_ERROR) {
129
+ char code[64];
130
+ snprintf(code, sizeof code, "ERR_%s", BrotliDecoderErrorString(b->error));
131
+ return failure(ctx, "Decompression failed", (int)b->error, code);
132
+ }
133
+ /* zlib's error for it: Brotli has none of its own */
134
+ if (b->flush == BROTLI_OPERATION_FINISH && b->decode_result == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT)
135
+ return failure(ctx, "unexpected end of file", -5, "Z_BUF_ERROR");
136
+ }
137
+ uint32_t result[2] = { (uint32_t)avail_out, (uint32_t)avail_in };
138
+ memcpy(state, result, sizeof result);
139
+ return js_int32(0);
140
+ }
141
+
142
+ /* brotliReset(handle) → 0 | failure */
143
+ PRIMITIVE(js_host_brotli_reset) {
144
+ UNUSED_PRIMITIVE_ARGS;
145
+ BrotliObject *b = brotli_arg(ARG(0));
146
+ if (!b) return js_throw_type_error(ctx, "brotliReset: a handle expected");
147
+ if (!brotli_init(b)) return failure(ctx, "Could not initialize Brotli instance", -1, "ERR_ZLIB_INITIALIZATION_FAILED");
148
+ return js_int32(0);
149
+ }
150
+
151
+ /* brotliClose(handle): Brotli's memory, now */
152
+ PRIMITIVE(js_host_brotli_close) {
153
+ UNUSED_PRIMITIVE_ARGS;
154
+ BrotliObject *b = brotli_arg(ARG(0));
155
+ if (b) brotli_end(b);
156
+ return JS_UNDEFINED;
157
+ }
@@ -1,4 +1,5 @@
1
- /* Host primitives for node:fs (ADR 0012): synchronous file access through stdio and POSIX.
1
+ /* Host primitives for node:fs (ADR 0012): synchronous file access through stdio and POSIX, and
2
+ * libuv's synchronous calls for stat, readdir and reads by position.
2
3
  * The prelude (node/prelude/fs.js) validates arguments and builds Node's errors from the
3
4
  * -errno these return. Linked only into programs whose prelude imports them. */
4
5
  #define _POSIX_C_SOURCE 200809L /* access, unlink under -std=c11 */
@@ -8,6 +9,8 @@
8
9
  #include <stdio.h>
9
10
  #include <stdlib.h>
10
11
 
12
+ #include <uv.h>
13
+
11
14
  #include "js_buffer.h"
12
15
  #include "js_exception.h"
13
16
  #include "js_ops.h"
@@ -132,3 +135,94 @@ JSValue js_host_fs_unlink(JSContext *ctx, JSValue callee, JSValue this_val, uint
132
135
  free(path);
133
136
  return r == 0 ? JS_UNDEFINED : errno_result(e);
134
137
  }
138
+
139
+ /* ---- stat, readdir and reads by position, through libuv's synchronous calls (every platform) */
140
+
141
+ static double ms_of(uv_timespec_t t) { return (double)t.tv_sec * 1000.0 + (double)t.tv_nsec / 1e6; }
142
+
143
+ /* fsStat(path, follow): [mode, size, mtimeMs, atimeMs, ctimeMs, birthtimeMs, ino, dev, nlink,
144
+ * uid, gid, rdev, blksize, blocks], or -errno: stat(2), lstat(2) when !follow. */
145
+ JSValue js_host_fs_stat(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
146
+ const JSValue *argv, JSValue new_target) {
147
+ (void)callee, (void)this_val, (void)new_target;
148
+ char *path = js_host_path_arg(ctx, argc, argv, 0);
149
+ if (!path) return JS_EXCEPTION;
150
+ bool follow = argc < 2 || js_truthy(argv[1]);
151
+ uv_fs_t req;
152
+ int r = follow ? uv_fs_stat(uv_default_loop(), &req, path, NULL) : uv_fs_lstat(uv_default_loop(), &req, path, NULL);
153
+ free(path);
154
+ if (r < 0) {
155
+ uv_fs_req_cleanup(&req);
156
+ return js_int32(r);
157
+ }
158
+ const uv_stat_t *s = &req.statbuf;
159
+ JSValue items[14] = {
160
+ js_number((double)s->st_mode), js_number((double)s->st_size), js_number(ms_of(s->st_mtim)),
161
+ js_number(ms_of(s->st_atim)), js_number(ms_of(s->st_ctim)), js_number(ms_of(s->st_birthtim)),
162
+ js_number((double)s->st_ino), js_number((double)s->st_dev), js_number((double)s->st_nlink),
163
+ js_number((double)s->st_uid), js_number((double)s->st_gid), js_number((double)s->st_rdev),
164
+ js_number((double)s->st_blksize), js_number((double)s->st_blocks),
165
+ };
166
+ uv_fs_req_cleanup(&req);
167
+ return js_new_array_from(ctx, items, 14);
168
+ }
169
+
170
+ /* fsReaddir(path): [name, type, …], or -errno; type is libuv's uv_dirent_type_t (0 unknown,
171
+ * 1 file, 2 directory, 3 symlink, 4 FIFO, 5 socket, 6 character device, 7 block device). */
172
+ JSValue js_host_fs_readdir(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
173
+ const JSValue *argv, JSValue new_target) {
174
+ (void)callee, (void)this_val, (void)new_target;
175
+ char *path = js_host_path_arg(ctx, argc, argv, 0);
176
+ if (!path) return JS_EXCEPTION;
177
+ uv_fs_t req;
178
+ int r = uv_fs_scandir(uv_default_loop(), &req, path, 0, NULL);
179
+ free(path);
180
+ if (r < 0) {
181
+ uv_fs_req_cleanup(&req);
182
+ return js_int32(r);
183
+ }
184
+ JSValue out = js_new_array(ctx, (uint32_t)(2 * r));
185
+ uv_dirent_t ent;
186
+ while (uv_fs_scandir_next(&req, &ent) != UV_EOF) {
187
+ JSValue name = js_new_string_cstr(ctx, ent.name);
188
+ if (js_array_push(ctx, js_as_object(out), name) < 0 || js_array_push(ctx, js_as_object(out), js_int32((int32_t)ent.type)) < 0) {
189
+ uv_fs_req_cleanup(&req);
190
+ return JS_EXCEPTION;
191
+ }
192
+ }
193
+ uv_fs_req_cleanup(&req);
194
+ return out;
195
+ }
196
+
197
+ /* fsReadAt(path, position, length): up to `length` bytes from `position`, as a Buffer (shorter
198
+ * at the end of the file; empty past it), or -errno: what a read stream reads, a chunk at a time. */
199
+ JSValue js_host_fs_read_at(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
200
+ const JSValue *argv, JSValue new_target) {
201
+ (void)callee, (void)this_val, (void)new_target;
202
+ char *path = js_host_path_arg(ctx, argc, argv, 0);
203
+ if (!path) return JS_EXCEPTION;
204
+ double position = argc > 1 && js_is_number(argv[1]) ? js_as_number(argv[1]) : 0;
205
+ double length = argc > 2 && js_is_number(argv[2]) ? js_as_number(argv[2]) : 65536;
206
+ if (!(length >= 0 && length <= 1 << 30)) length = 65536;
207
+ uv_fs_t req;
208
+ int fd = uv_fs_open(uv_default_loop(), &req, path, UV_FS_O_RDONLY, 0, NULL);
209
+ uv_fs_req_cleanup(&req);
210
+ free(path);
211
+ if (fd < 0) return js_int32(fd);
212
+ char *buf = malloc((size_t)length + 1);
213
+ if (!buf) js_fatal("out of memory");
214
+ size_t got = 0;
215
+ int r = 0;
216
+ while (got < (size_t)length) { /* a read may return less than asked before the end */
217
+ uv_buf_t b = uv_buf_init(buf + got, (unsigned)((size_t)length - got));
218
+ r = uv_fs_read(uv_default_loop(), &req, fd, &b, 1, (int64_t)position + (int64_t)got, NULL);
219
+ uv_fs_req_cleanup(&req);
220
+ if (r <= 0) break;
221
+ got += (size_t)r;
222
+ }
223
+ uv_fs_close(uv_default_loop(), &req, fd, NULL);
224
+ uv_fs_req_cleanup(&req);
225
+ JSValue out = r < 0 ? js_int32(r) : js_new_buffer_from_bytes(ctx, (const uint8_t *)buf, got);
226
+ free(buf);
227
+ return out;
228
+ }
@@ -66,15 +66,21 @@ void js_uv_set_flush(void (*fn)(void)) { flush_hook = fn; }
66
66
  bool js_uv_call(JSValue fn, uint32_t argc, JSValue *argv, JSValue *result) {
67
67
  if (failed) return false;
68
68
  JSContext *ctx = loop_ctx;
69
+ /* under no async context (ADR 0020): the prelude binds a callback to the one it was given in */
70
+ JSValue saved = js_async_context(ctx);
71
+ js_set_async_context(ctx, JS_UNDEFINED);
69
72
  JSValue r = js_call(ctx, fn, JS_UNDEFINED, argc, argv);
73
+ js_set_async_context(ctx, saved);
70
74
  if (js_is_exception(r)) {
71
75
  failed = js_report_uncaught(ctx);
72
- if (!failed) failed = 1;
73
- uv_stop(loop);
74
- return false;
76
+ if (failed) {
77
+ uv_stop(loop);
78
+ return false;
79
+ }
80
+ r = JS_UNDEFINED; /* handled ('uncaughtException'): the program goes on */
75
81
  }
76
82
  if (js_run_microtasks(ctx) < 0) {
77
- failed = 1;
83
+ failed = ctx->rt->failure;
78
84
  uv_stop(loop);
79
85
  return false;
80
86
  }
File without changes
@@ -0,0 +1,70 @@
1
+ /* Host primitives for process's signal events and process.kill (prelude/internal/
2
+ * process_signals.js), on libuv's signal handles. A watched signal's handle is unref'd: like
3
+ * Node's, it doesn't keep the program alive.
4
+ *
5
+ * signalStart(signum, cb) → 0 | -errno cb(signum) from the loop each time the signal arrives
6
+ * signalStop(signum) the default action again
7
+ * processKill(pid, signum) → 0 | -errno */
8
+ #define _POSIX_C_SOURCE 200809L /* libuv's headers: pthread_rwlock_t */
9
+ #include "js_gc.h"
10
+ #include "js_node.h"
11
+ #include "js_ops.h"
12
+ #include "js_uv.h"
13
+ #include "jscontext.h"
14
+
15
+ #define PRIMITIVE(fn) \
16
+ JSValue fn(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target)
17
+ #define UNUSED (void)callee, (void)this_val, (void)new_target
18
+ #define MAX_SIGNAL 65 /* above Linux's SIGRTMAX */
19
+
20
+ static struct {
21
+ uv_signal_t handle;
22
+ bool open;
23
+ JSValue cb; /* a root once open */
24
+ } watches[MAX_SIGNAL];
25
+
26
+ static void on_signal(uv_signal_t *handle, int signum) {
27
+ (void)handle;
28
+ JSValue arg = js_int32(signum);
29
+ (void)js_uv_call(watches[signum].cb, 1, &arg, NULL);
30
+ }
31
+
32
+ static int signal_arg(uint32_t argc, const JSValue *argv) {
33
+ int signum = argc > 0 && js_is_int32(argv[0]) ? js_as_int32(argv[0]) : 0;
34
+ return signum > 0 && signum < MAX_SIGNAL ? signum : 0;
35
+ }
36
+
37
+ PRIMITIVE(js_host_signal_start) {
38
+ UNUSED;
39
+ int signum = signal_arg(argc, argv);
40
+ if (!signum || argc < 2 || !js_is_callable(argv[1])) return js_int32(UV_EINVAL);
41
+ if (!watches[signum].open) {
42
+ int r = uv_signal_init(js_uv_loop(ctx), &watches[signum].handle);
43
+ if (r < 0) return js_int32(r);
44
+ uv_unref((uv_handle_t *)&watches[signum].handle);
45
+ watches[signum].cb = JS_UNDEFINED;
46
+ js_add_root(ctx->rt, &watches[signum].cb);
47
+ watches[signum].open = true;
48
+ }
49
+ int r = uv_signal_start(&watches[signum].handle, on_signal, signum);
50
+ if (r == 0) watches[signum].cb = argv[1];
51
+ return js_int32(r);
52
+ }
53
+
54
+ PRIMITIVE(js_host_signal_stop) {
55
+ UNUSED;
56
+ (void)ctx;
57
+ int signum = signal_arg(argc, argv);
58
+ if (signum && watches[signum].open) {
59
+ uv_signal_stop(&watches[signum].handle);
60
+ watches[signum].cb = JS_UNDEFINED;
61
+ }
62
+ return JS_UNDEFINED;
63
+ }
64
+
65
+ PRIMITIVE(js_host_process_kill) {
66
+ UNUSED;
67
+ (void)ctx;
68
+ if (argc < 2 || !js_is_number(argv[0]) || !js_is_int32(argv[1])) return js_int32(UV_EINVAL);
69
+ return js_int32(uv_kill((int)js_as_number(argv[0]), js_as_int32(argv[1])));
70
+ }
@@ -16,6 +16,7 @@
16
16
 
17
17
  #include "js_exception.h"
18
18
  #include "js_jobs.h"
19
+ #include "js_ops.h"
19
20
  #include "jsstring.h"
20
21
 
21
22
  /* Each error by its C errno and its libuv code: the same number on POSIX, but on Windows libuv
@@ -23,6 +24,7 @@
23
24
  #define E(name, message) { name, -UV_##name, #name, message }
24
25
  static const struct { int code, uv; const char *name, *message; } ERRORS[] = {
25
26
  E(EPERM, "operation not permitted"),
27
+ E(ESRCH, "no such process"),
26
28
  E(ENOENT, "no such file or directory"),
27
29
  E(EIO, "i/o error"),
28
30
  E(EBADF, "bad file descriptor"),
@@ -104,3 +106,51 @@ JSValue js_host_timer_unref(JSContext *ctx, JSValue callee, JSValue this_val, ui
104
106
  if (argc < 2 || !js_is_callable(argv[0]) || !js_is_number(argv[1])) return js_throw_type_error(ctx, "timerUnref: (fn, ms) expected");
105
107
  return js_int32((int32_t)js_add_timer(ctx, argv[0], js_as_number(argv[1]), true));
106
108
  }
109
+
110
+ /* the id a timer primitive takes: a positive int32, else 0 */
111
+ static uint32_t timer_id(uint32_t argc, const JSValue *argv, uint32_t i) {
112
+ return i < argc && js_is_int32(argv[i]) && js_as_int32(argv[i]) > 0 ? (uint32_t)js_as_int32(argv[i]) : 0;
113
+ }
114
+
115
+ /* timerStart(fn, ms, ref, id) → id: fn() once after ms, or at the loop's time when ms < 0 (an
116
+ * immediate); id restarts that timer (refresh()), 0 starts a new one. node:timers' Timeouts. */
117
+ JSValue js_host_timer_start(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv,
118
+ JSValue new_target) {
119
+ (void)callee, (void)this_val, (void)new_target;
120
+ if (argc < 3 || !js_is_callable(argv[0]) || !js_is_number(argv[1])) return js_throw_type_error(ctx, "timerStart: (fn, ms, ref, id) expected");
121
+ double ms = js_as_number(argv[1]);
122
+ return js_int32((int32_t)js_timer_start(ctx, argv[0], ms, ms < 0, !js_truthy(argv[2]), timer_id(argc, argv, 3)));
123
+ }
124
+
125
+ /* asyncContextGet() → the current async context (ADR 0020): undefined, or AsyncLocalStorage's frame */
126
+ JSValue js_host_async_context_get(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv,
127
+ JSValue new_target) {
128
+ (void)callee, (void)this_val, (void)argc, (void)argv, (void)new_target;
129
+ return js_async_context(ctx);
130
+ }
131
+
132
+ /* asyncContextSet(context): what jobs, timers and promise reactions queued from now on carry */
133
+ JSValue js_host_async_context_set(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv,
134
+ JSValue new_target) {
135
+ (void)callee, (void)this_val, (void)new_target;
136
+ js_set_async_context(ctx, argc ? argv[0] : JS_UNDEFINED);
137
+ return JS_UNDEFINED;
138
+ }
139
+
140
+ /* timerRef(id, ref): whether a pending timer keeps the program alive */
141
+ JSValue js_host_timer_ref(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv,
142
+ JSValue new_target) {
143
+ (void)callee, (void)this_val, (void)new_target;
144
+ uint32_t id = timer_id(argc, argv, 0);
145
+ if (id) js_timer_set_ref(ctx, id, argc > 1 && js_truthy(argv[1]));
146
+ return JS_UNDEFINED;
147
+ }
148
+
149
+ /* timerClear(id) */
150
+ JSValue js_host_timer_clear(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv,
151
+ JSValue new_target) {
152
+ (void)callee, (void)this_val, (void)new_target;
153
+ uint32_t id = timer_id(argc, argv, 0);
154
+ if (id) js_timer_clear(ctx, id);
155
+ return JS_UNDEFINED;
156
+ }