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,14 +1,17 @@
1
- /* Host primitives for node:fs (ADR 0012): synchronous file access through stdio and POSIX, and
1
+ /* Host primitives for node:fs: synchronous file access through stdio and POSIX, and
2
2
  * libuv's synchronous calls for stat, readdir and reads by position.
3
3
  * The prelude (node/prelude/fs.js) validates arguments and builds Node's errors from the
4
4
  * -errno these return. Linked only into programs whose prelude imports them. */
5
- #define _POSIX_C_SOURCE 200809L /* access, unlink under -std=c11 */
5
+ #define _GNU_SOURCE /* access, unlink under -std=c11; every open flag the platform has (O_NOATIME, O_DIRECT) */
6
6
  #include "js_node.h"
7
7
 
8
8
  #include <errno.h>
9
9
  #include <stdio.h>
10
10
  #include <stdlib.h>
11
+ #include <string.h>
11
12
 
13
+ #include <fcntl.h>
14
+ #include <sys/stat.h>
12
15
  #include <uv.h>
13
16
 
14
17
  #include "js_buffer.h"
@@ -24,6 +27,8 @@
24
27
  #define unlink _unlink
25
28
  #define F_OK 0
26
29
  #else
30
+ #include <signal.h>
31
+ #include <sys/statvfs.h>
27
32
  #include <unistd.h>
28
33
  #endif
29
34
 
@@ -43,6 +48,12 @@ char *js_host_path_arg(JSContext *ctx, uint32_t argc, const JSValue *argv, uint3
43
48
  return s;
44
49
  }
45
50
 
51
+ #ifndef _WIN32
52
+ /* a write past RLIMIT_FSIZE fails with EFBIG instead of killing the process, as in Node (which
53
+ * ignores SIGXFSZ at startup) */
54
+ __attribute__((constructor)) static void ignore_sigxfsz(void) { signal(SIGXFSZ, SIG_IGN); }
55
+ #endif
56
+
46
57
  static JSValue errno_result(int e) {
47
58
  return js_int32(js_node_uv_error(e ? e : EIO));
48
59
  }
@@ -64,6 +75,12 @@ JSValue js_host_fs_read_file(JSContext *ctx, JSValue callee, JSValue this_val, u
64
75
  #endif
65
76
  free(path);
66
77
  if (!f) return errno_result(e);
78
+ /* a file of 2 GiB or more: EFBIG, which the prelude reports as Node's ERR_FS_FILE_TOO_LARGE */
79
+ struct stat fst;
80
+ if (fstat(fileno(f), &fst) == 0 && (fst.st_mode & S_IFMT) == S_IFREG && (uint64_t)fst.st_size > 0x7fffffff) {
81
+ fclose(f);
82
+ return errno_result(EFBIG);
83
+ }
67
84
  size_t length = 0, cap = 4096;
68
85
  char *buf = malloc(cap);
69
86
  if (!buf) js_fatal("out of memory");
@@ -140,6 +157,18 @@ JSValue js_host_fs_unlink(JSContext *ctx, JSValue callee, JSValue this_val, uint
140
157
 
141
158
  static double ms_of(uv_timespec_t t) { return (double)t.tv_sec * 1000.0 + (double)t.tv_nsec / 1e6; }
142
159
 
160
+ /* a stat as fsStat gives it (host_fswatch.c's watchFile too) */
161
+ JSValue js_host_stat_array(JSContext *ctx, const uv_stat_t *s) {
162
+ JSValue items[14] = {
163
+ js_number((double)s->st_mode), js_number((double)s->st_size), js_number(ms_of(s->st_mtim)),
164
+ js_number(ms_of(s->st_atim)), js_number(ms_of(s->st_ctim)), js_number(ms_of(s->st_birthtim)),
165
+ js_number((double)s->st_ino), js_number((double)s->st_dev), js_number((double)s->st_nlink),
166
+ js_number((double)s->st_uid), js_number((double)s->st_gid), js_number((double)s->st_rdev),
167
+ js_number((double)s->st_blksize), js_number((double)s->st_blocks),
168
+ };
169
+ return js_new_array_from(ctx, items, 14);
170
+ }
171
+
143
172
  /* fsStat(path, follow): [mode, size, mtimeMs, atimeMs, ctimeMs, birthtimeMs, ino, dev, nlink,
144
173
  * uid, gid, rdev, blksize, blocks], or -errno: stat(2), lstat(2) when !follow. */
145
174
  JSValue js_host_fs_stat(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
@@ -155,16 +184,9 @@ JSValue js_host_fs_stat(JSContext *ctx, JSValue callee, JSValue this_val, uint32
155
184
  uv_fs_req_cleanup(&req);
156
185
  return js_int32(r);
157
186
  }
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
- };
187
+ JSValue a = js_host_stat_array(ctx, &req.statbuf);
166
188
  uv_fs_req_cleanup(&req);
167
- return js_new_array_from(ctx, items, 14);
189
+ return a;
168
190
  }
169
191
 
170
192
  /* fsReaddir(path): [name, type, …], or -errno; type is libuv's uv_dirent_type_t (0 unknown,
@@ -226,3 +248,312 @@ JSValue js_host_fs_read_at(JSContext *ctx, JSValue callee, JSValue this_val, uin
226
248
  free(buf);
227
249
  return out;
228
250
  }
251
+
252
+ /* fsRealpath(path): the canonical absolute path (symlinks resolved), or -errno: realpath(3). */
253
+ JSValue js_host_fs_realpath(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
254
+ const JSValue *argv, JSValue new_target) {
255
+ (void)callee, (void)this_val, (void)new_target;
256
+ char *path = js_host_path_arg(ctx, argc, argv, 0);
257
+ if (!path) return JS_EXCEPTION;
258
+ uv_fs_t req;
259
+ int r = uv_fs_realpath(uv_default_loop(), &req, path, NULL);
260
+ free(path);
261
+ JSValue out = r < 0 ? js_int32(r) : js_new_string_cstr(ctx, (const char *)req.ptr);
262
+ uv_fs_req_cleanup(&req);
263
+ return out;
264
+ }
265
+
266
+ /* fsMkdir(path, mode): creates one directory, or -errno. */
267
+ JSValue js_host_fs_mkdir(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
268
+ const JSValue *argv, JSValue new_target) {
269
+ (void)callee, (void)this_val, (void)new_target;
270
+ char *path = js_host_path_arg(ctx, argc, argv, 0);
271
+ if (!path) return JS_EXCEPTION;
272
+ int mode = argc > 1 && js_is_number(argv[1]) ? (int)js_as_number(argv[1]) : 0777;
273
+ uv_fs_t req;
274
+ int r = uv_fs_mkdir(uv_default_loop(), &req, path, mode, NULL);
275
+ uv_fs_req_cleanup(&req);
276
+ free(path);
277
+ return r < 0 ? js_int32(r) : JS_UNDEFINED;
278
+ }
279
+
280
+ /* fsUtimes(path, atime, mtime): sets the times, in seconds since the epoch, or -errno. */
281
+ JSValue js_host_fs_utimes(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
282
+ const JSValue *argv, JSValue new_target) {
283
+ (void)callee, (void)this_val, (void)new_target;
284
+ char *path = js_host_path_arg(ctx, argc, argv, 0);
285
+ if (!path) return JS_EXCEPTION;
286
+ double atime = argc > 1 && js_is_number(argv[1]) ? js_as_number(argv[1]) : 0;
287
+ double mtime = argc > 2 && js_is_number(argv[2]) ? js_as_number(argv[2]) : 0;
288
+ uv_fs_t req;
289
+ int r = uv_fs_utime(uv_default_loop(), &req, path, atime, mtime, NULL);
290
+ uv_fs_req_cleanup(&req);
291
+ free(path);
292
+ return r < 0 ? js_int32(r) : JS_UNDEFINED;
293
+ }
294
+
295
+ /* ---- file descriptors ---------------------------------------------------------------------- */
296
+
297
+ /* fsOpen(path, flags, mode): a file descriptor, or -errno. `flags` is Node's string ("r", "w+",
298
+ * "ax", …; the prelude has checked it) or a number of the platform's O_* flags. */
299
+ JSValue js_host_fs_open(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
300
+ const JSValue *argv, JSValue new_target) {
301
+ (void)callee, (void)this_val, (void)new_target;
302
+ int flags = UV_FS_O_RDONLY;
303
+ if (argc > 1 && js_is_number(argv[1])) {
304
+ flags = (int)js_as_number(argv[1]);
305
+ } else if (argc > 1 && js_is_string(argv[1])) {
306
+ char f[8] = { 0 };
307
+ JSStrView view = js_string_view(ctx, argv[1]);
308
+ js_view_to_utf8(view, f, sizeof f - 1);
309
+ bool plus = strchr(f, '+') != NULL, excl = strchr(f, 'x') != NULL, sync = strchr(f, 's') != NULL;
310
+ int access_mode = plus ? UV_FS_O_RDWR : f[0] == 'r' ? UV_FS_O_RDONLY : UV_FS_O_WRONLY;
311
+ flags = access_mode | (excl ? UV_FS_O_EXCL : 0) | (sync ? UV_FS_O_SYNC : 0);
312
+ if (strchr(f, 'w')) flags |= UV_FS_O_CREAT | UV_FS_O_TRUNC;
313
+ else if (strchr(f, 'a')) flags |= UV_FS_O_CREAT | UV_FS_O_APPEND;
314
+ }
315
+ int mode = argc > 2 && js_is_number(argv[2]) ? (int)js_as_number(argv[2]) : 0666;
316
+ char *path = js_host_path_arg(ctx, argc, argv, 0);
317
+ if (!path) return JS_EXCEPTION;
318
+ uv_fs_t req;
319
+ int fd = uv_fs_open(uv_default_loop(), &req, path, flags, mode, NULL);
320
+ uv_fs_req_cleanup(&req);
321
+ free(path);
322
+ return js_int32(fd);
323
+ }
324
+
325
+ /* fsClose(fd): undefined, or -errno. */
326
+ JSValue js_host_fs_close(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
327
+ const JSValue *argv, JSValue new_target) {
328
+ (void)ctx, (void)callee, (void)this_val, (void)new_target;
329
+ int fd = argc > 0 && js_is_number(argv[0]) ? (int)js_as_number(argv[0]) : -1;
330
+ uv_fs_t req;
331
+ int r = uv_fs_close(uv_default_loop(), &req, fd, NULL);
332
+ uv_fs_req_cleanup(&req);
333
+ return r < 0 ? js_int32(r) : JS_UNDEFINED;
334
+ }
335
+
336
+ /* fsWrite(fd, bytes, offset, length, position): the bytes written (all of them, unless an error
337
+ * cuts it short), or -errno. A position of -1 writes at the file's current offset. */
338
+ JSValue js_host_fs_write(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
339
+ const JSValue *argv, JSValue new_target) {
340
+ (void)callee, (void)this_val, (void)new_target;
341
+ uint8_t *bytes;
342
+ size_t n;
343
+ if (argc < 5 || !js_buffer_source_bytes(argv[1], &bytes, &n)) return js_throw_type_error(ctx, "fsWrite: bytes expected");
344
+ int fd = (int)js_as_number(argv[0]);
345
+ size_t offset = (size_t)js_as_number(argv[2]), length = (size_t)js_as_number(argv[3]);
346
+ int64_t position = (int64_t)js_as_number(argv[4]);
347
+ if (offset > n || length > n - offset) return js_throw_type_error(ctx, "fsWrite: out of range");
348
+ size_t done = 0;
349
+ while (done < length) { /* a write may take fewer bytes than given */
350
+ uv_buf_t b = uv_buf_init((char *)bytes + offset + done, (unsigned)(length - done));
351
+ uv_fs_t req;
352
+ int r = uv_fs_write(uv_default_loop(), &req, fd, &b, 1, position < 0 ? -1 : position + (int64_t)done, NULL);
353
+ uv_fs_req_cleanup(&req);
354
+ if (r < 0) return done ? js_number((double)done) : js_int32(r);
355
+ done += (size_t)r;
356
+ }
357
+ return js_number((double)done);
358
+ }
359
+
360
+ /* fsRead(fd, bytes, offset, length, position): the bytes read into `bytes` (0 at the end of the
361
+ * file), or -errno. A position of -1 reads from the file's current offset. */
362
+ JSValue js_host_fs_read(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
363
+ const JSValue *argv, JSValue new_target) {
364
+ (void)callee, (void)this_val, (void)new_target;
365
+ uint8_t *bytes;
366
+ size_t n;
367
+ if (argc < 5 || !js_buffer_source_bytes(argv[1], &bytes, &n)) return js_throw_type_error(ctx, "fsRead: bytes expected");
368
+ int fd = (int)js_as_number(argv[0]);
369
+ size_t offset = (size_t)js_as_number(argv[2]), length = (size_t)js_as_number(argv[3]);
370
+ int64_t position = (int64_t)js_as_number(argv[4]);
371
+ if (offset > n || length > n - offset) return js_throw_type_error(ctx, "fsRead: out of range");
372
+ uv_buf_t b = uv_buf_init((char *)bytes + offset, (unsigned)length);
373
+ uv_fs_t req;
374
+ int r = uv_fs_read(uv_default_loop(), &req, fd, &b, 1, position < 0 ? -1 : position, NULL);
375
+ uv_fs_req_cleanup(&req);
376
+ return js_int32(r);
377
+ }
378
+
379
+ /* fsConstants(): fs.constants as a flat [name, number, …], in Node's order (node_constants.cc):
380
+ * libuv's, then the platform's open flags, file types and modes, those it defines. */
381
+ JSValue js_host_fs_constants(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
382
+ const JSValue *argv, JSValue new_target) {
383
+ (void)callee, (void)this_val, (void)argc, (void)argv, (void)new_target;
384
+ #define C(name) { #name, name }
385
+ #define UV(name, value) { #name, value }
386
+ static const struct { const char *name; int value; } CONSTANTS[] = {
387
+ UV(UV_FS_SYMLINK_DIR, UV_FS_SYMLINK_DIR), UV(UV_FS_SYMLINK_JUNCTION, UV_FS_SYMLINK_JUNCTION),
388
+ UV(O_RDONLY, UV_FS_O_RDONLY), UV(O_WRONLY, UV_FS_O_WRONLY), UV(O_RDWR, UV_FS_O_RDWR),
389
+ C(UV_DIRENT_UNKNOWN), C(UV_DIRENT_FILE), C(UV_DIRENT_DIR), C(UV_DIRENT_LINK), C(UV_DIRENT_FIFO),
390
+ C(UV_DIRENT_SOCKET), C(UV_DIRENT_CHAR), C(UV_DIRENT_BLOCK),
391
+ #ifdef _WIN32
392
+ { "EXTENSIONLESS_FORMAT_JAVASCRIPT", 0 }, { "EXTENSIONLESS_FORMAT_WASM", 1 },
393
+ #endif
394
+ C(S_IFMT), C(S_IFREG), C(S_IFDIR), C(S_IFCHR),
395
+ #ifdef S_IFBLK
396
+ C(S_IFBLK),
397
+ #endif
398
+ #ifdef S_IFIFO
399
+ C(S_IFIFO),
400
+ #endif
401
+ #ifdef S_IFLNK
402
+ C(S_IFLNK),
403
+ #endif
404
+ #ifdef S_IFSOCK
405
+ C(S_IFSOCK),
406
+ #endif
407
+ UV(O_CREAT, UV_FS_O_CREAT), UV(O_EXCL, UV_FS_O_EXCL), C(UV_FS_O_FILEMAP),
408
+ #ifndef _WIN32
409
+ #ifdef O_NOCTTY
410
+ C(O_NOCTTY),
411
+ #endif
412
+ #endif
413
+ UV(O_TRUNC, UV_FS_O_TRUNC), UV(O_APPEND, UV_FS_O_APPEND),
414
+ #ifndef _WIN32
415
+ #ifdef O_DIRECTORY
416
+ C(O_DIRECTORY),
417
+ #endif
418
+ #ifdef O_NOATIME
419
+ C(O_NOATIME),
420
+ #endif
421
+ #ifdef O_NOFOLLOW
422
+ C(O_NOFOLLOW),
423
+ #endif
424
+ #ifdef O_SYNC
425
+ C(O_SYNC),
426
+ #endif
427
+ #ifdef O_DSYNC
428
+ C(O_DSYNC),
429
+ #endif
430
+ #ifdef O_SYMLINK
431
+ C(O_SYMLINK),
432
+ #endif
433
+ #ifdef O_DIRECT
434
+ C(O_DIRECT),
435
+ #endif
436
+ #ifdef O_NONBLOCK
437
+ C(O_NONBLOCK),
438
+ #endif
439
+ #endif
440
+ #ifdef _WIN32
441
+ { "UV_FS_O_SEQUENTIAL", UV_FS_O_SEQUENTIAL }, { "UV_FS_O_RANDOM", UV_FS_O_RANDOM },
442
+ { "UV_FS_O_SHORT_LIVED", UV_FS_O_SHORT_LIVED }, { "UV_FS_O_TEMPORARY", UV_FS_O_TEMPORARY },
443
+ #endif
444
+ #ifdef S_IRWXU
445
+ C(S_IRWXU),
446
+ #endif
447
+ #ifdef S_IRUSR
448
+ C(S_IRUSR),
449
+ #endif
450
+ #ifdef S_IWUSR
451
+ C(S_IWUSR),
452
+ #endif
453
+ #ifdef S_IXUSR
454
+ C(S_IXUSR),
455
+ #endif
456
+ #ifdef S_IRWXG
457
+ C(S_IRWXG), C(S_IRGRP), C(S_IWGRP), C(S_IXGRP), C(S_IRWXO), C(S_IROTH), C(S_IWOTH), C(S_IXOTH),
458
+ #endif
459
+ { "F_OK", 0 }, { "R_OK", 4 }, { "W_OK", 2 }, { "X_OK", 1 },
460
+ C(UV_FS_COPYFILE_EXCL), UV(COPYFILE_EXCL, UV_FS_COPYFILE_EXCL),
461
+ C(UV_FS_COPYFILE_FICLONE), UV(COPYFILE_FICLONE, UV_FS_COPYFILE_FICLONE),
462
+ C(UV_FS_COPYFILE_FICLONE_FORCE), UV(COPYFILE_FICLONE_FORCE, UV_FS_COPYFILE_FICLONE_FORCE),
463
+ };
464
+ #undef C
465
+ #undef UV
466
+ const uint32_t n = sizeof CONSTANTS / sizeof CONSTANTS[0];
467
+ JSValue a = js_new_array(ctx, 2 * n);
468
+ if (js_is_exception(a)) return a;
469
+ for (uint32_t i = 0; i < n; i++)
470
+ if (js_array_append(ctx, a, js_new_string_cstr(ctx, CONSTANTS[i].name)) < 0 || js_array_append(ctx, a, js_int32(CONSTANTS[i].value)) < 0)
471
+ return JS_EXCEPTION;
472
+ return a;
473
+ }
474
+
475
+ /* fsCall(op, …): the rest of node:fs's system calls, through libuv's synchronous forms, by number
476
+ * (FS_OPS in node/prelude/fs.js). Each gives -errno on failure, else undefined, or its result:
477
+ * readlink and mkdtemp a path, fstat fsStat's array, statfs [type, bsize, blocks, bfree, bavail,
478
+ * files, ffree]. */
479
+ enum {
480
+ FS_RENAME, FS_LINK, FS_SYMLINK, FS_READLINK, FS_RMDIR, FS_CHMOD, FS_FCHMOD, FS_CHOWN, FS_FCHOWN, FS_LCHOWN,
481
+ FS_FSYNC, FS_FDATASYNC, FS_FTRUNCATE, FS_FUTIME, FS_LUTIME, FS_COPYFILE, FS_MKDTEMP, FS_ACCESS, FS_FSTAT, FS_STATFS,
482
+ };
483
+
484
+ JSValue js_host_fs_call(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
485
+ const JSValue *argv, JSValue new_target) {
486
+ (void)callee, (void)this_val, (void)new_target;
487
+ if (argc < 2 || !js_is_number(argv[0])) return js_throw_type_error(ctx, "fsCall: an operation expected");
488
+ int op = (int)js_as_number(argv[0]);
489
+ const JSValue *args = argv + 1;
490
+ uint32_t n = argc - 1;
491
+ #define NUM(i) (n > (i) && js_is_number(args[i]) ? js_as_number(args[i]) : 0)
492
+ /* the operations on a file descriptor take no path */
493
+ bool by_fd = op == FS_FCHMOD || op == FS_FCHOWN || op == FS_FSYNC || op == FS_FDATASYNC || op == FS_FTRUNCATE ||
494
+ op == FS_FUTIME || op == FS_FSTAT;
495
+ char *path = by_fd ? NULL : js_host_path_arg(ctx, n, args, 0);
496
+ if (!by_fd && !path) return JS_EXCEPTION;
497
+ bool two = op == FS_RENAME || op == FS_LINK || op == FS_SYMLINK || op == FS_COPYFILE;
498
+ char *dest = two ? js_host_path_arg(ctx, n, args, 1) : NULL;
499
+ if (two && !dest) {
500
+ free(path);
501
+ return JS_EXCEPTION;
502
+ }
503
+ uv_loop_t *loop = uv_default_loop();
504
+ uv_file fd = by_fd ? (uv_file)NUM(0) : -1;
505
+ uv_fs_t req;
506
+ int r;
507
+ double frsize = -1; /* statfs's */
508
+ #ifndef _WIN32
509
+ struct statvfs vfs;
510
+ #endif
511
+ switch (op) {
512
+ case FS_RENAME: r = uv_fs_rename(loop, &req, path, dest, NULL); break;
513
+ case FS_LINK: r = uv_fs_link(loop, &req, path, dest, NULL); break;
514
+ case FS_SYMLINK: r = uv_fs_symlink(loop, &req, path, dest, (int)NUM(2), NULL); break;
515
+ case FS_READLINK: r = uv_fs_readlink(loop, &req, path, NULL); break;
516
+ case FS_RMDIR: r = uv_fs_rmdir(loop, &req, path, NULL); break;
517
+ case FS_CHMOD: r = uv_fs_chmod(loop, &req, path, (int)NUM(1), NULL); break;
518
+ case FS_FCHMOD: r = uv_fs_fchmod(loop, &req, fd, (int)NUM(1), NULL); break;
519
+ case FS_CHOWN: r = uv_fs_chown(loop, &req, path, (uv_uid_t)NUM(1), (uv_gid_t)NUM(2), NULL); break;
520
+ case FS_FCHOWN: r = uv_fs_fchown(loop, &req, fd, (uv_uid_t)NUM(1), (uv_gid_t)NUM(2), NULL); break;
521
+ case FS_LCHOWN: r = uv_fs_lchown(loop, &req, path, (uv_uid_t)NUM(1), (uv_gid_t)NUM(2), NULL); break;
522
+ case FS_FSYNC: r = uv_fs_fsync(loop, &req, fd, NULL); break;
523
+ case FS_FDATASYNC: r = uv_fs_fdatasync(loop, &req, fd, NULL); break;
524
+ case FS_FTRUNCATE: r = uv_fs_ftruncate(loop, &req, fd, (int64_t)NUM(1), NULL); break;
525
+ case FS_FUTIME: r = uv_fs_futime(loop, &req, fd, NUM(1), NUM(2), NULL); break;
526
+ case FS_LUTIME: r = uv_fs_lutime(loop, &req, path, NUM(1), NUM(2), NULL); break;
527
+ case FS_COPYFILE: r = uv_fs_copyfile(loop, &req, path, dest, (int)NUM(2), NULL); break;
528
+ case FS_MKDTEMP: r = uv_fs_mkdtemp(loop, &req, path, NULL); break;
529
+ case FS_ACCESS: r = uv_fs_access(loop, &req, path, (int)NUM(1), NULL); break;
530
+ case FS_FSTAT: r = uv_fs_fstat(loop, &req, fd, NULL); break;
531
+ case FS_STATFS:
532
+ r = uv_fs_statfs(loop, &req, path, NULL);
533
+ #ifndef _WIN32
534
+ /* frsize (Node 24, libuv 1.52's f_frsize): statvfs's fragment size, as libuv reads it */
535
+ if (r >= 0 && statvfs(path, &vfs) == 0) frsize = (double)vfs.f_frsize;
536
+ #endif
537
+ break;
538
+ default:
539
+ free(path), free(dest);
540
+ return js_throw_type_error(ctx, "fsCall: unknown operation");
541
+ }
542
+ #undef NUM
543
+ free(path), free(dest);
544
+ JSValue result = JS_UNDEFINED;
545
+ if (r < 0) result = js_int32(r);
546
+ else if (op == FS_READLINK) result = js_new_string_cstr(ctx, (const char *)req.ptr);
547
+ else if (op == FS_MKDTEMP) result = js_new_string_cstr(ctx, req.path);
548
+ else if (op == FS_FSTAT) result = js_host_stat_array(ctx, &req.statbuf);
549
+ else if (op == FS_STATFS) {
550
+ const uv_statfs_t *f = req.ptr;
551
+ if (frsize < 0) frsize = (double)f->f_bsize; /* no statvfs: the block size */
552
+ JSValue v[8] = { js_number((double)f->f_type), js_number((double)f->f_bsize), js_number(frsize), js_number((double)f->f_blocks),
553
+ js_number((double)f->f_bfree), js_number((double)f->f_bavail), js_number((double)f->f_files),
554
+ js_number((double)f->f_ffree) };
555
+ result = js_new_array_from(ctx, v, 8);
556
+ }
557
+ uv_fs_req_cleanup(&req);
558
+ return result;
559
+ }
@@ -0,0 +1,170 @@
1
+ /* Host primitives for fs.watch and fs.watchFile (prelude/internal/fs_watch.js): libuv's file
2
+ * system event handles (inotify, kqueue, …) and its stat pollers, numbered, each with one JS
3
+ * callback (a root) called from the loop. A watcher keeps the program alive while it's ref'd
4
+ * (Node's persistent option).
5
+ *
6
+ * fsWatchStart(path, recursive, cb) → id | -errno cb(events, filename | null): events 1 rename, 2 change;
7
+ * or cb(-errno, null) for an error
8
+ * fsPollStart(path, interval ms, cb) → id | -errno cb(status, current, previous): fsStat's arrays,
9
+ * zeros when the file is missing (status -errno)
10
+ * fsWatchClose(id), fsWatchRef(id, ref) */
11
+ #define _POSIX_C_SOURCE 200809L /* libuv's headers: pthread_rwlock_t */
12
+ #include <stdlib.h>
13
+ #include <string.h>
14
+
15
+ #include "js_gc.h"
16
+ #include "js_node.h"
17
+ #include "js_ops.h"
18
+ #include "js_uv.h"
19
+ #include "jscontext.h"
20
+ #include "jsstring.h"
21
+
22
+ #define PRIMITIVE(fn) \
23
+ JSValue fn(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target)
24
+ #define UNUSED (void)callee, (void)this_val, (void)new_target
25
+
26
+ JSValue js_host_stat_array(JSContext *ctx, const uv_stat_t *s); /* host_fs.c */
27
+
28
+ typedef struct Watch {
29
+ union {
30
+ uv_handle_t handle;
31
+ uv_fs_event_t event;
32
+ uv_fs_poll_t poll;
33
+ } u;
34
+ int id;
35
+ bool closing;
36
+ JSValue cb; /* a root */
37
+ } Watch;
38
+
39
+ static Watch **watches;
40
+ static size_t nwatches;
41
+
42
+ static Watch *add_watch(JSContext *ctx, Watch *w, JSValue cb) {
43
+ size_t id = 0;
44
+ while (id < nwatches && watches[id]) id++;
45
+ if (id == nwatches) {
46
+ size_t n = nwatches ? nwatches * 2 : 8;
47
+ Watch **v = realloc(watches, n * sizeof *v);
48
+ if (!v) js_fatal("out of memory in fs.watch");
49
+ memset(v + nwatches, 0, (n - nwatches) * sizeof *v);
50
+ watches = v;
51
+ nwatches = n;
52
+ }
53
+ watches[id] = w;
54
+ w->id = (int)id;
55
+ w->cb = cb;
56
+ js_add_root(ctx->rt, &w->cb);
57
+ return w;
58
+ }
59
+
60
+ static Watch *watch_arg(uint32_t argc, const JSValue *argv) {
61
+ int id = argc > 0 && js_is_int32(argv[0]) ? js_as_int32(argv[0]) : -1;
62
+ Watch *w = id >= 0 && (size_t)id < nwatches ? watches[id] : NULL;
63
+ return w && !w->closing ? w : NULL;
64
+ }
65
+
66
+ /* A string argument as UTF-8, malloc'd; NULL for anything else. */
67
+ static char *string_arg(JSContext *ctx, JSValue v) {
68
+ if (!js_is_string(v)) return NULL;
69
+ JSStrView view = js_string_view(ctx, v);
70
+ size_t n = js_view_to_utf8(view, NULL, 0);
71
+ char *s = malloc(n + 1);
72
+ if (!s) js_fatal("out of memory in fs.watch");
73
+ js_view_to_utf8(view, s, n);
74
+ s[n] = '\0';
75
+ return s;
76
+ }
77
+
78
+ static void on_event(uv_fs_event_t *handle, const char *filename, int events, int status) {
79
+ Watch *w = handle->data;
80
+ JSContext *ctx = js_uv_context();
81
+ JSValue args[2] = { js_int32(status < 0 ? status : events), filename ? js_new_string_cstr(ctx, filename) : JS_NULL };
82
+ (void)js_uv_call(w->cb, 2, args, NULL);
83
+ }
84
+
85
+ static void on_poll(uv_fs_poll_t *handle, int status, const uv_stat_t *prev, const uv_stat_t *curr) {
86
+ Watch *w = handle->data;
87
+ JSContext *ctx = js_uv_context();
88
+ JSValue args[3] = { js_int32(status), js_host_stat_array(ctx, curr), JS_UNDEFINED };
89
+ args[2] = js_host_stat_array(ctx, prev);
90
+ (void)js_uv_call(w->cb, 3, args, NULL);
91
+ }
92
+
93
+ PRIMITIVE(js_host_fs_watch_start) {
94
+ UNUSED;
95
+ char *path = argc > 0 ? string_arg(ctx, argv[0]) : NULL;
96
+ if (!path || argc < 3 || !js_is_callable(argv[2])) {
97
+ free(path);
98
+ return js_int32(UV_EINVAL);
99
+ }
100
+ Watch *w = calloc(1, sizeof *w);
101
+ if (!w) js_fatal("out of memory in fs.watch");
102
+ int r = uv_fs_event_init(js_uv_loop(ctx), &w->u.event);
103
+ if (r == 0) {
104
+ w->u.handle.data = w;
105
+ r = uv_fs_event_start(&w->u.event, on_event, path, js_truthy(argv[1]) ? UV_FS_EVENT_RECURSIVE : 0);
106
+ if (r < 0) { /* initialized: closed through the loop, then freed */
107
+ uv_close(&w->u.handle, (uv_close_cb)free);
108
+ free(path);
109
+ return js_int32(r);
110
+ }
111
+ } else {
112
+ free(w);
113
+ }
114
+ free(path);
115
+ return r < 0 ? js_int32(r) : js_int32(add_watch(ctx, w, argv[2])->id);
116
+ }
117
+
118
+ PRIMITIVE(js_host_fs_poll_start) {
119
+ UNUSED;
120
+ char *path = argc > 0 ? string_arg(ctx, argv[0]) : NULL;
121
+ if (!path || argc < 3 || !js_is_number(argv[1]) || !js_is_callable(argv[2])) {
122
+ free(path);
123
+ return js_int32(UV_EINVAL);
124
+ }
125
+ Watch *w = calloc(1, sizeof *w);
126
+ if (!w) js_fatal("out of memory in fs.watchFile");
127
+ int r = uv_fs_poll_init(js_uv_loop(ctx), &w->u.poll);
128
+ if (r == 0) {
129
+ w->u.handle.data = w;
130
+ r = uv_fs_poll_start(&w->u.poll, on_poll, path, (unsigned)js_as_number(argv[1]));
131
+ if (r < 0) {
132
+ uv_close(&w->u.handle, (uv_close_cb)free);
133
+ free(path);
134
+ return js_int32(r);
135
+ }
136
+ } else {
137
+ free(w);
138
+ }
139
+ free(path);
140
+ return r < 0 ? js_int32(r) : js_int32(add_watch(ctx, w, argv[2])->id);
141
+ }
142
+
143
+ static void on_closed(uv_handle_t *handle) {
144
+ Watch *w = handle->data;
145
+ watches[w->id] = NULL;
146
+ js_remove_root(js_uv_context()->rt, &w->cb);
147
+ free(w);
148
+ }
149
+
150
+ PRIMITIVE(js_host_fs_watch_close) {
151
+ UNUSED;
152
+ (void)ctx;
153
+ Watch *w = watch_arg(argc, argv);
154
+ if (w) {
155
+ w->closing = true;
156
+ uv_close(&w->u.handle, on_closed);
157
+ }
158
+ return JS_UNDEFINED;
159
+ }
160
+
161
+ PRIMITIVE(js_host_fs_watch_ref) {
162
+ UNUSED;
163
+ (void)ctx;
164
+ Watch *w = watch_arg(argc, argv);
165
+ if (w) {
166
+ if (argc > 1 && js_truthy(argv[1])) uv_ref(&w->u.handle);
167
+ else uv_unref(&w->u.handle);
168
+ }
169
+ return JS_UNDEFINED;
170
+ }