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
File without changes
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_atoms.h — atoms: interned strings (ADR 0003).
2
+ * js_atoms.h — atoms: interned strings.
3
3
  *
4
4
  * An atom is the unique flat string (flag JS_STR_ATOM) for its content, so
5
5
  * property keys compare by pointer. The table is weak: an atom nothing else
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_bigint.h — BigInt values (ECMAScript §6.1.6.2; ADR 0016).
2
+ * js_bigint.h — BigInt values (ECMAScript §6.1.6.2).
3
3
  *
4
4
  * A BigInt is a heap cell holding its value in two's complement limbs, least significant first,
5
5
  * normalized to the fewest limbs that hold it (QuickJS's representation). The arithmetic lives in
@@ -1,6 +1,6 @@
1
1
  /*
2
- * js_buffer.h — ArrayBuffer and DataView (ECMAScript §25.1, §25.3), the binary data component
3
- * (ADR 0014). The layout is here so that core code can read a buffer without linking the
2
+ * js_buffer.h — ArrayBuffer and DataView (ECMAScript §25.1, §25.3), the binary data component.
3
+ * The layout is here so that core code can read a buffer without linking the
4
4
  * component (util.inspect prints its bytes) and so that typed arrays can share it.
5
5
  */
6
6
  #ifndef JS_BUFFER_H
@@ -33,7 +33,7 @@ typedef struct JSDataView {
33
33
  } JSDataView;
34
34
 
35
35
  /* Typed array element types, in the spec's table order (§23.2, Table 71). The BigInt ones
36
- * arrive with BigInt (ADR 0016). JS_TYPED_ARRAY_TYPES (jscontext.h) counts them. */
36
+ * arrive with BigInt. JS_TYPED_ARRAY_TYPES (jscontext.h) counts them. */
37
37
  typedef enum JSTypedArrayType {
38
38
  JS_TA_INT8, JS_TA_UINT8, JS_TA_UINT8C, JS_TA_INT16, JS_TA_UINT16, JS_TA_INT32, JS_TA_UINT32,
39
39
  JS_TA_BIGINT64, JS_TA_BIGUINT64, JS_TA_FLOAT16, JS_TA_FLOAT32, JS_TA_FLOAT64,
@@ -65,7 +65,7 @@ JS_WARN_UNUSED int js_array_buffer_detach(JSContext *ctx, JSValue buffer);
65
65
  /* A new, zeroed ArrayBuffer of `length` bytes (%ArrayBuffer.prototype%); JS_EXCEPTION when it can't be allocated. */
66
66
  JS_WARN_UNUSED JSValue js_new_array_buffer(JSContext *ctx, size_t length);
67
67
 
68
- /* For the components that take or make bytes (TextDecoder, structuredClone; ADR 0012). These are
68
+ /* For the components that take or make bytes (TextDecoder, structuredClone). These are
69
69
  * the typedarray component's: a component that calls them needs it. */
70
70
  /* The bytes of an ArrayBuffer, a typed array or a DataView (a view's current window; none when
71
71
  * it is out of bounds or its buffer is detached): true, or false for any other value. */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_builtins.h — built-ins as tables, grouped in components (ADR 0014).
2
+ * js_builtins.h — built-ins as tables, grouped in components.
3
3
  *
4
4
  * A built-in object is a constant table of entries; js_define_builtins defines them with the
5
5
  * attributes the spec gives built-ins. Optional built-ins come in components that a program
@@ -85,7 +85,7 @@ void js_install_recorded_components(JSContext *ctx);
85
85
  typedef enum JSCoreTarget {
86
86
  JS_CORE_OBJECT, JS_CORE_OBJECT_PROTO, JS_CORE_ARRAY, JS_CORE_ARRAY_PROTO, JS_CORE_STRING, JS_CORE_STRING_PROTO,
87
87
  JS_CORE_NUMBER, JS_CORE_NUMBER_PROTO, JS_CORE_GLOBAL,
88
- JS_CORE_CONSOLE, /* the host's console (ADR 0012): installed by js_new_console, not by realm setup */
88
+ JS_CORE_CONSOLE, /* the host's console: installed by js_new_console, not by realm setup */
89
89
  JS_CORE_TARGET_COUNT
90
90
  } JSCoreTarget;
91
91
 
@@ -159,7 +159,7 @@ extern const JSComponent js_component_typedarray;
159
159
  extern const JSComponent js_component_date;
160
160
  extern const JSComponent js_component_regexp;
161
161
  extern const JSComponent js_component_bigint;
162
- /* the web-standard host layer (ADR 0012, layer 2) */
162
+ /* the web-standard host layer */
163
163
  extern const JSComponent js_component_domexception;
164
164
  extern const JSComponent js_component_encoding;
165
165
  extern const JSComponent js_component_base64;
@@ -181,4 +181,42 @@ extern const size_t js_all_components_count;
181
181
  /* Records them all for the realms js_context_new creates next (the runtime's unit tests). */
182
182
  void js_use_all_components(JSRuntime *rt);
183
183
 
184
+ /* ---- Generated code's inline built-in calls --------------------------------------------- */
185
+
186
+ /* A string's units without allocating: flat, a flattened rope, or a slice; else false. */
187
+ static inline bool js_string_units(JSValue s, JSStrView *out) {
188
+ JSCell *c = js_as_cell(s);
189
+ if (c->kind == JS_CELL_STR_ROPE) {
190
+ JSRope *r = (JSRope *)c;
191
+ if (!js_is_empty(r->right)) return false; /* not flattened yet */
192
+ c = js_as_cell(r->left);
193
+ }
194
+ const JSSlice *slice = c->kind == JS_CELL_STR_SLICE ? (const JSSlice *)c : NULL;
195
+ if (slice) c = js_as_cell(slice->parent);
196
+ if (c->kind != JS_CELL_STR_FLAT) return false;
197
+ JSString *f = (JSString *)c;
198
+ uint32_t offset = slice ? slice->offset : 0, length = slice ? slice->length : f->length;
199
+ bool latin1 = (f->cell.flags & JS_STR_LATIN1) != 0;
200
+ *out = (JSStrView){ latin1 ? (const void *)(f->chars.latin1 + offset) : (const void *)(f->chars.utf16 + offset), length, latin1 };
201
+ return true;
202
+ }
203
+
204
+ /* s.charCodeAt(i): the unit inline when the callee is the built-in, s a string whose units are
205
+ * at hand and i an index in it; anything else is the call. */
206
+ static inline JSValue js_call_char_code_at(JSContext *ctx, JSValue f, JSValue s, JSValue i, const char *site) {
207
+ JSStrView v;
208
+ if (JS_LIKELY(js_is_function(f) && js_as_function(f)->entry == js_core_string_proto_char_code_at && js_is_string(s)
209
+ && js_is_int32(i) && js_string_units(s, &v) && (uint32_t)js_as_int32(i) < v.length))
210
+ return js_int32((int32_t)js_view_at(v, (uint32_t)js_as_int32(i)));
211
+ return js_call_site(ctx, f, s, 1, &i, site);
212
+ }
213
+
214
+ /* String.fromCharCode(c): a unit up to 0xFF is a static one-unit string. */
215
+ static inline JSValue js_call_from_char_code(JSContext *ctx, JSValue f, JSValue this_val, JSValue c, const char *site) {
216
+ if (JS_LIKELY(js_is_function(f) && js_as_function(f)->entry == js_core_string_from_char_code && js_is_int32(c)
217
+ && (uint32_t)js_as_int32(c) <= 0xFF))
218
+ return js_char_string((uint8_t)js_as_int32(c));
219
+ return js_call_site(ctx, f, this_val, 1, &c, site);
220
+ }
221
+
184
222
  #endif /* JS_BUILTINS_H */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_console.h — console, util.inspect and util.format (ADR 0012), in C: Node's
2
+ * js_console.h — console, util.inspect and util.format, in C: Node's
3
3
  * algorithms, so output matches Node's byte for byte. Also the test host's print and the
4
4
  * uncaught-error report.
5
5
  */
@@ -8,7 +8,7 @@
8
8
 
9
9
  #include "js_function.h"
10
10
 
11
- /* util.inspect's options (the ones visaljs honors; colors and getters are always off). */
11
+ /* util.inspect's options (the ones visaljs honors; colors are always off). */
12
12
  typedef struct JSInspectOptions {
13
13
  bool show_hidden;
14
14
  double depth; /* INFINITY for null */
@@ -17,9 +17,12 @@ typedef struct JSInspectOptions {
17
17
  double max_string_length;
18
18
  double break_length;
19
19
  int compact; /* -1 for true, 0 for false, else a number */
20
- bool sorted;
20
+ bool sorted; /* true: entries in the default sort order (a comparator isn't supported) */
21
+ int getters; /* JS_INSPECT_GETTERS_*: which getters are called to show their value */
21
22
  } JSInspectOptions;
22
23
 
24
+ enum { JS_INSPECT_GETTERS_OFF, JS_INSPECT_GETTERS_ALL, JS_INSPECT_GETTERS_GET, JS_INSPECT_GETTERS_SET };
25
+
23
26
  extern const JSInspectOptions js_inspect_defaults; /* Node's util.inspect.defaultOptions */
24
27
 
25
28
  /* util.inspect(v) with the default options, or with `o`. */
@@ -43,11 +46,13 @@ JSValue js_util_inspect_function(JSContext *ctx);
43
46
  /* Writes a string as UTF-8 (lone surrogates as U+FFFD) to fd 1 or 2; stdout is flushed
44
47
  * before anything goes to stderr, so the two interleave as written. */
45
48
  void js_write_output(JSContext *ctx, int fd, JSValue s);
49
+ /* Writes bytes as they are to fd 1 or 2, as js_write_output does a string. */
50
+ void js_write_bytes(int fd, const uint8_t *data, size_t length);
46
51
 
47
52
  /* The global console object. */
48
53
  JSValue js_new_console(JSContext *ctx);
49
54
 
50
- /* The test host's print (ADR 0011): String(argument) and a newline, on stdout. */
55
+ /* The test host's print: String(argument) and a newline, on stdout. */
51
56
  JSValue js_print(JSContext *ctx, JSValue callee, JSValue this_val,
52
57
  uint32_t argc, const JSValue *argv, JSValue new_target);
53
58
 
@@ -16,7 +16,7 @@ JS_WARN_UNUSED JSValue js_to_primitive(JSContext *ctx, JSValue v, JSHint hint);
16
16
  JS_WARN_UNUSED JSValue js_ordinary_to_primitive(JSContext *ctx, JSValue v, JSHint hint);
17
17
  /* ToString. */
18
18
  JS_WARN_UNUSED JSValue js_to_string(JSContext *ctx, JSValue v);
19
- /* ToNumber: 0 on success with *out set, -1 with an exception pending (ADR 0004). */
19
+ /* ToNumber: 0 on success with *out set, -1 with an exception pending. */
20
20
  JS_WARN_UNUSED int js_to_number(JSContext *ctx, double *out, JSValue v);
21
21
 
22
22
  #endif /* JS_CONVERT_H */
@@ -1,6 +1,6 @@
1
1
  /*
2
- * js_core.def — the core built-in methods a program installs only when it names them
3
- * (ADR 0014), in V8's order. One line per property:
2
+ * js_core.def — the core built-in methods a program installs only when it names them,
3
+ * in V8's order. One line per property:
4
4
  *
5
5
  * JS_CORE_FN(target, "name", native, length) a method
6
6
  * JS_CORE_HOST_FN(target, "name", native, length) a host method (enumerable: console.log)
@@ -55,8 +55,9 @@ JS_CORE_FN(OBJECT_PROTO, "toLocaleString", object_proto_to_locale_string, 0)
55
55
  /* Array (§23.1) */
56
56
  JS_CORE_FN(ARRAY, "isArray", array_is_array, 1)
57
57
  JS_CORE_FN(ARRAY, "from", array_from, 1)
58
- JS_CORE_FN(ARRAY, "of", array_of, 0)
58
+ /* fromAsync before of: V8 13.6's order */
59
59
  JS_CORE_FN(ARRAY, "fromAsync", array_from_async, 1)
60
+ JS_CORE_FN(ARRAY, "of", array_of, 0)
60
61
  JS_CORE_SYMBOL_GETTER(ARRAY, species, array_species)
61
62
  JS_CORE_FN(ARRAY_PROTO, "at", array_proto_at, 1)
62
63
  JS_CORE_FN(ARRAY_PROTO, "concat", array_proto_concat, 1)
@@ -188,7 +189,7 @@ JS_CORE_FN(GLOBAL, "decodeURIComponent", global_decode_uri_component, 1)
188
189
  JS_CORE_FN(GLOBAL, "encodeURI", global_encode_uri, 1)
189
190
  JS_CORE_FN(GLOBAL, "encodeURIComponent", global_encode_uri_component, 1)
190
191
 
191
- /* console (ADR 0012), in Node's order: own enumerable methods, each its own function
192
+ /* console, in Node's order: own enumerable methods, each its own function
192
193
  * (console.info !== console.log), though several share a native */
193
194
  JS_CORE_HOST_FN(CONSOLE, "log", console_log, 0)
194
195
  JS_CORE_HOST_FN(CONSOLE, "warn", console_error, 0)
@@ -1,4 +1,4 @@
1
- /* js_crypto.h — crypto (ADR 0018): node:crypto's host primitives, which node/index.ts lists for
1
+ /* js_crypto.h — crypto: node:crypto's host primitives, which node/index.ts lists for
2
2
  * the compiler (generated code declares the ones a program uses), and what the crypto
3
3
  * component shares with them. The primitives are the runtime's, as Web Crypto runs on the same
4
4
  * C (runtime/src/crypto_internal.h). */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_error.h — Error objects (ECMAScript §20.5; ADR 0004).
2
+ * js_error.h — Error objects (ECMAScript §20.5).
3
3
  *
4
4
  * An error is an ordinary object of class js_class_error (it has [[ErrorData]]).
5
5
  * The js_throw_*_error helpers in js_exception.h create and throw them.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_exception.h — exception propagation (ADR 0004).
2
+ * js_exception.h — exception propagation.
3
3
  *
4
4
  * A function that fails returns JS_EXCEPTION (or < 0 for int results) and
5
5
  * leaves the error in ctx->rt->exception. Callers check and propagate.
@@ -62,4 +62,24 @@ static inline bool js_has_exception(const JSContext *ctx) {
62
62
  return js_throw_stack_overflow(ctx); \
63
63
  } while (0)
64
64
 
65
+ /* After every direct call between generated functions: the call is then never the caller's last
66
+ * action, so C compilers keep it a call. Turned into a jump (tail-call elimination), JS
67
+ * recursion would run in constant stack, and unbounded recursion would loop forever instead of
68
+ * throwing a RangeError at the stack limit. */
69
+ #if defined(_MSC_VER) && !defined(__clang__)
70
+ #define JS_NO_TAIL_CALL() _ReadWriteBarrier()
71
+ #else
72
+ #define JS_NO_TAIL_CALL() __asm__ volatile("" ::: "memory")
73
+ #endif
74
+
75
+ /* The same in a function returning `fail` (a double or a bool: generated code's unboxed direct
76
+ * entries): the caller sees the pending exception. */
77
+ #define JS_CHECK_STACK_OR(ctx, fail) \
78
+ do { \
79
+ if (JS_UNLIKELY(JS_FRAME_ADDRESS() < (ctx)->stack_limit)) { \
80
+ js_discard(js_throw_stack_overflow(ctx)); \
81
+ return (fail); \
82
+ } \
83
+ } while (0)
84
+
65
85
  #endif /* JS_EXCEPTION_H */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_function.h — function objects and calls (ADR 0006).
2
+ * js_function.h — function objects and calls.
3
3
  *
4
4
  * A function is an object (a JSFunction cell). Every function has a generic
5
5
  * entry with one signature; compiled functions also have a direct entry the
@@ -10,7 +10,7 @@
10
10
 
11
11
  #include "js_object.h"
12
12
 
13
- /* The generic entry (ADR 0006): `this_val` is raw (coercion happens in the
13
+ /* The generic entry: `this_val` is raw (coercion happens in the
14
14
  * callee); `new_target` is undefined for [[Call]], the constructor for [[Construct]]. */
15
15
  typedef JSValue (*JSNativeFn)(JSContext *ctx, JSValue callee, JSValue this_val,
16
16
  uint32_t argc, const JSValue *argv, JSValue new_target);
@@ -23,8 +23,8 @@ typedef JSValue (*JSNativeFn)(JSContext *ctx, JSValue callee, JSValue this_val,
23
23
  #define JS_FN_CLASS_CTOR 0x10u /* throws when called without new */
24
24
  #define JS_FN_DERIVED 0x20u /* a derived class constructor: [[Construct]] doesn't create `this` (super() does) */
25
25
  #define JS_FN_BOUND 0x40u /* a bound function (Function.prototype.bind): home_object is the target */
26
- #define JS_FN_GENERATOR 0x80u /* function* (ADR 0007): its [[Prototype]] and `prototype` differ */
27
- #define JS_FN_ASYNC 0x100u /* async function (ADR 0007): [[Prototype]] %AsyncFunction.prototype% */
26
+ #define JS_FN_GENERATOR 0x80u /* function*: its [[Prototype]] and `prototype` differ */
27
+ #define JS_FN_ASYNC 0x100u /* async function: [[Prototype]] %AsyncFunction.prototype% */
28
28
  #define JS_FN_PROXY 0x200u /* a callable proxy: it runs in its caller's realm */
29
29
 
30
30
  /* Emitted by the compiler as static const data, one per function in the source. */
@@ -39,7 +39,7 @@ typedef struct JSFunctionInfo {
39
39
  uint32_t source_length;
40
40
  } JSFunctionInfo;
41
41
 
42
- /* A scope's captured variables (ADR 0006, "Closures"): one cell per scope that has
42
+ /* A scope's captured variables: one cell per scope that has
43
43
  * any, linked to the enclosing scope's. Generated code reaches a variable by a static
44
44
  * (depth, slot). Slots start EMPTY (zeroed memory): uninitialized let/const. */
45
45
  typedef struct JSEnv { /* kind = ENV */
@@ -73,12 +73,13 @@ typedef struct JSFunction { /* kind = FUNCTION */
73
73
  JSObject obj;
74
74
  JSNativeFn entry; /* copy of info->generic: one load at call time */
75
75
  const JSFunctionInfo *info; /* NULL for builtins created at runtime */
76
- struct JSEnv *env; /* captured scope (M4), or NULL */
77
- JSValue home_object; /* methods: where `super` looks (M4) */
78
- JSValue bound_this; /* arrows: the captured `this`, else EMPTY (M4) */
79
- JSContext *realm; /* the realm the function was created in (ADR 0011) */
76
+ struct JSEnv *env; /* captured scope, or NULL */
77
+ JSValue home_object; /* methods: where `super` looks */
78
+ JSValue bound_this; /* arrows: the captured `this`, else EMPTY */
79
+ JSContext *realm; /* the realm the function was created in */
80
80
  uint32_t flags;
81
81
  uint32_t pad_;
82
+ struct JSShape *instance_shape; /* a class's instances' root shape, made at its first `new` (js_new_class_instance) */
82
83
  } JSFunction;
83
84
 
84
85
  extern const JSClass js_class_function;
@@ -113,6 +114,24 @@ JSValue js_define_method(JSContext *ctx, JSObject *o, const char *name, JSNative
113
114
  * (the source text at a call site; NULL for runtime callers). */
114
115
  JS_WARN_UNUSED JSValue js_call(JSContext *ctx, JSValue f, JSValue this_val, uint32_t argc, const JSValue *argv);
115
116
  JS_WARN_UNUSED JSValue js_call_site(JSContext *ctx, JSValue f, JSValue this_val, uint32_t argc, const JSValue *argv, const char *callee_text);
117
+
118
+ /* Math.f(x) in generated code: when the callee is the built-in (its entry, from
119
+ * any realm) and x a Number, the C function inline; anything else is the call. The entries are
120
+ * math.c's (a program naming Math links it). */
121
+ enum { JS_MATH_SQRT, JS_MATH_ABS, JS_MATH_FLOOR, JS_MATH_CEIL, JS_MATH_TRUNC, JS_MATH_INLINE_COUNT };
122
+ extern const JSNativeFn js_math_inline[JS_MATH_INLINE_COUNT];
123
+ #define JS_MATH_CALL(name, index, cfn) \
124
+ static inline JSValue js_call_math_##name(JSContext *ctx, JSValue f, JSValue this_val, JSValue x, const char *site) { \
125
+ if (JS_LIKELY(js_is_number(x) && js_is_function(f) && js_as_function(f)->entry == js_math_inline[index])) \
126
+ return js_number(cfn(js_as_number(x))); \
127
+ return js_call_site(ctx, f, this_val, 1, &x, site); \
128
+ }
129
+ JS_MATH_CALL(sqrt, JS_MATH_SQRT, sqrt)
130
+ JS_MATH_CALL(abs, JS_MATH_ABS, fabs)
131
+ JS_MATH_CALL(floor, JS_MATH_FLOOR, floor)
132
+ JS_MATH_CALL(ceil, JS_MATH_CEIL, ceil)
133
+ JS_MATH_CALL(trunc, JS_MATH_TRUNC, trunc)
134
+ #undef JS_MATH_CALL
116
135
  JS_WARN_UNUSED JSValue js_construct(JSContext *ctx, JSValue f, uint32_t argc, const JSValue *argv, JSValue new_target, const char *callee_text);
117
136
  /* The same with the arguments in an array (a call with spreads). */
118
137
  JS_WARN_UNUSED JSValue js_call_spread(JSContext *ctx, JSValue f, JSValue this_val, JSValue args, const char *callee_text);
@@ -123,6 +142,11 @@ JS_WARN_UNUSED JSValue js_construct_spread(JSContext *ctx, JSValue f, JSValue ar
123
142
  /* GetFunctionRealm: f's realm (a proxy's target's), ctx for non-functions; NULL with a TypeError for a revoked proxy. */
124
143
  JSContext *js_function_realm(JSContext *ctx, JSValue f);
125
144
  JS_WARN_UNUSED JSValue js_get_prototype_from_constructor(JSContext *ctx, JSValue new_target, JSIntrinsic fallback);
145
+ /* `new F(…)` where F is a constructor the program compiled (optimizer step 10): `this`, an
146
+ * ordinary object with F's `prototype` (read by the site's cache `ic`: an own data property that
147
+ * can't become an accessor, so no user code runs) and `slots` inline slots. The instances' root
148
+ * shape is cached on F, and used while F's `prototype` is the same object. */
149
+ JS_WARN_UNUSED JSValue js_new_instance(JSContext *ctx, JSValue f, uint16_t slots, JSPropCache *ic);
126
150
  /* OrdinaryCreateFromConstructor: an ordinary object with that prototype. */
127
151
  JS_WARN_UNUSED JSValue js_create_from_constructor(JSContext *ctx, JSValue new_target, JSIntrinsic fallback);
128
152
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_gc.h — heap and garbage collector (ADR 0002).
2
+ * js_gc.h — heap and garbage collector.
3
3
  *
4
4
  * Non-moving mark-sweep. Cells come from 64 KiB aligned blocks, one size
5
5
  * class per block, or from the large-object space. Mark and allocation bits
@@ -30,29 +30,45 @@ typedef struct JSContext JSContext;
30
30
  #define JS_BLOCK_MAX_CELLS (JS_BLOCK_SIZE / JS_CELL_ALIGN)
31
31
  #define JS_BITMAP_WORDS (JS_BLOCK_MAX_CELLS / 64)
32
32
 
33
- /* Collection policy (ADR 0002). */
34
- #define JS_GC_MIN_HEAP ((size_t)4 << 20) /* never collect before this much is allocated */
35
- #define JS_EMPTY_POOL_MAX 32 /* empty blocks kept; the rest go back to the OS */
33
+ /* Collection policy. */
34
+ #define JS_GC_MIN_HEAP ((size_t)4 << 20) /* the old generation's smallest limit */
35
+ #define JS_GC_NURSERY ((size_t)4 << 20) /* a young collection after this much is allocated */
36
36
 
37
- typedef struct JSFreeCell { struct JSFreeCell *next; } JSFreeCell;
37
+ /* Checking builds: JS_GC_STRESS collects at every allocation;
38
+ * JS_GC_VERIFY checks every pointer the marker follows and poisons dead cells. Stress implies
39
+ * verification. Both make allocation take the slow path. */
40
+ #if defined(JS_GC_STRESS) && !defined(JS_GC_VERIFY)
41
+ #define JS_GC_VERIFY 1
42
+ #endif
38
43
 
39
44
  /* The header of a 64 KiB block of same-size cells, or of a large object:
40
45
  * a 64 KiB-aligned mapping holding exactly one cell (is_large). Either way
41
46
  * js_block_of(cell) finds it. */
42
47
  typedef struct JSBlock {
43
48
  struct JSBlock *next; /* in its size class's list, or in the empty pool */
49
+ struct JSBlock *prev; /* in its size class's list */
44
50
  size_t map_size; /* JS_BLOCK_SIZE, or the large object's mapping */
45
51
  uint32_t cell_size;
46
52
  uint32_t cell_count;
47
53
  uint8_t size_class;
48
54
  uint8_t is_large;
49
- uint8_t unswept; /* marked by the last GC, not swept yet */
55
+ union {
56
+ uint8_t queued; /* in its class's sweep queue */
57
+ uint8_t remembered; /* a large object: in the remembered set, with cards marked */
58
+ };
50
59
  uint8_t has_finalizable;
51
- uint8_t pad_[4];
60
+ uint32_t index_magic; /* ceil(2^32 / cell_size): a cell's index is (offset * magic) >> 32 */
61
+ uint8_t young; /* the allocator took it since the last collection */
52
62
  uint64_t mark_bits[JS_BITMAP_WORDS];
53
63
  uint64_t alloc_bits[JS_BITMAP_WORDS]; /* exact only while the world is stopped */
54
64
  } JSBlock;
55
65
 
66
+ /* A large object's cards: a bit per 2^card_shift bytes of the object
67
+ * that a store gave a young cell since the last collection. They live in the allocation bitmap,
68
+ * whose only other bit is bit 0 of word 0. A large object's size_class is its card_shift. */
69
+ #define JS_LARGE_CARDS ((JS_BITMAP_WORDS - 1) * 64)
70
+ static inline uint64_t *js_large_cards(JSBlock *b) { return &b->alloc_bits[1]; }
71
+
56
72
  #define JS_BLOCK_FIRST_CELL \
57
73
  ((sizeof(JSBlock) + JS_CELL_ALIGN - 1) & ~(size_t)(JS_CELL_ALIGN - 1))
58
74
 
@@ -76,20 +92,74 @@ static inline unsigned js_size_class(size_t size) {
76
92
  return 8 + (unsigned)(b - 7) * 4 + ((s >> (b - 2)) - 4);
77
93
  }
78
94
 
95
+ /* The index of x's lowest set bit; x != 0. */
96
+ static inline unsigned js_ctz64(uint64_t x) {
97
+ #if defined(_MSC_VER) && !defined(__clang__)
98
+ unsigned long i;
99
+ _BitScanForward64(&i, x);
100
+ return (unsigned)i;
101
+ #else
102
+ return (unsigned)__builtin_ctzll(x);
103
+ #endif
104
+ }
105
+
79
106
  /* ---- Heap -------------------------------------------------------------- */
80
107
 
108
+ /* What the collector has done, counted always (a few clock reads per collection). JS_GC_TRACE=1
109
+ * prints a line per collection, JS_GC_STATS=1 a JSON summary at exit. */
110
+ typedef struct JSGCStats {
111
+ uint64_t collections;
112
+ uint64_t young_collections; /* of them: the rest were full */
113
+ uint64_t idle_collections; /* of the full ones: when the program was idle */
114
+ uint64_t mark_slices; /* incremental marking's pauses, in pause_ms too */
115
+ uint64_t parallel_markings; /* pauses' markings the helper threads joined */
116
+ double pause_ms, max_pause_ms; /* the world stopped: everything below but sweep */
117
+ double mark_ms, weak_ms, finish_ms; /* the pause: marking; weak references; finalizers, large objects, accounting */
118
+ double sweep_ms; /* lazy sweeping, in allocation: timed only when reporting */
119
+ uint64_t blocks_swept;
120
+ uint64_t allocated_bytes; /* handed to the allocator, in total */
121
+ uint64_t marked_cells; /* by the last collection */
122
+ size_t peak_heap_bytes; /* js_heap_size's high-water mark */
123
+ size_t peak_external_bytes; /* external memory's high-water mark */
124
+ } JSGCStats;
125
+
126
+ /* Allocation in one size class, a word of the allocation bitmap at a
127
+ * time: `free` has a bit for each free cell of a window of 64 cells at `base`, zeroed and not
128
+ * handed out yet. The fast path takes the lowest. A dead cell isn't written until it's reused. */
129
+ typedef struct JSAllocator {
130
+ uint64_t free; /* hot: the fast path's two loads */
131
+ uintptr_t base;
132
+ uintptr_t cell_size;
133
+ JSBlock *block; /* the block the window is in; NULL: none */
134
+ uint32_t word; /* the bitmap word after the window's: where the next one is looked for */
135
+ uint32_t fresh; /* the block is a new mapping, zero-filled */
136
+ } JSAllocator;
137
+
81
138
  typedef struct JSHeap {
82
- JSFreeCell *free[JS_NUM_SIZE_CLASSES]; /* hot: popped by the inline fast path */
83
- JSBlock *current[JS_NUM_SIZE_CLASSES]; /* the block `free` points into */
84
- JSBlock *blocks[JS_NUM_SIZE_CLASSES]; /* every block of the class */
85
- JSBlock **sweep_link[JS_NUM_SIZE_CLASSES]; /* link to the next block to sweep lazily */
139
+ JSAllocator alloc[JS_NUM_SIZE_CLASSES]; /* hot: the inline fast path */
140
+ JSBlock *blocks[JS_NUM_SIZE_CLASSES]; /* every block of the class (doubly linked) */
141
+ /* Lazy sweeping: the blocks of each class to sweep before the allocator takes them. A full
142
+ * collection queues them all; a young one, those the allocator took since the last one (the
143
+ * others hold old cells only, and a young collection frees none). malloc'd. */
144
+ struct JSBlockList { JSBlock **items; size_t count, cap; } to_sweep[JS_NUM_SIZE_CLASSES], young_blocks;
145
+ /* Swept blocks with free cells the allocator hasn't taken: finish_sweeping's, before a full
146
+ * collection's marking or after an idle one. Emptied when a full collection queues every block. */
147
+ struct JSBlockList ready[JS_NUM_SIZE_CLASSES];
86
148
  JSBlock *empty; /* pool of empty blocks, any class */
87
- size_t block_count;
149
+ size_t block_count; /* mapped, decommitted ones included */
88
150
  size_t empty_count;
151
+ /* Empty blocks given back to the OS, their addresses kept for reuse (malloc'd); not in the block
152
+ * set. Each with the full collections there had been when it was decommitted: one still
153
+ * unused after another full collection is unmapped. */
154
+ struct JSDecommitted { JSBlock *block; size_t full_count; } *decommitted;
155
+ size_t decommitted_count, decommitted_cap;
156
+ size_t full_count; /* full collections so far */
89
157
  JSBlock **large; /* large objects, sorted by address (malloc'd) */
90
158
  size_t large_count;
91
159
  size_t large_cap;
92
- size_t large_bytes;
160
+ size_t large_bytes; /* their mappings, and the cache's */
161
+ JSBlock **large_cache; /* dead large objects' mappings, for reuse (malloc'd) */
162
+ size_t large_cache_count, large_cache_cap, large_cache_bytes;
93
163
 
94
164
  /* Precise roots (malloc'd arrays). */
95
165
  struct JSRootTable { JSValue *slots; size_t n; } *root_tables;
@@ -97,24 +167,64 @@ typedef struct JSHeap {
97
167
  JSValue **roots;
98
168
  size_t root_count, root_cap;
99
169
 
100
- /* Conservative pointer test (ADR 0002). */
170
+ /* Conservative pointer test. */
101
171
  uintptr_t *block_set; /* open addressing over block addresses; 0 = empty */
102
172
  size_t block_set_cap, block_set_count;
103
173
  uint64_t block_bloom[4]; /* 256-bit Bloom filter over block_set */
104
174
  uintptr_t min_addr, max_addr; /* bounds of every mapping the heap made */
105
175
  void *stack_base; /* highest stack address of the owning thread */
106
176
 
107
- JSCell **mark_stack; /* malloc'd; reused across collections */
177
+ /* Generations: old cells a store gave a young cell (malloc'd). */
178
+ JSCell **remembered;
179
+ size_t remembered_count, remembered_cap;
180
+
181
+ JSCell **mark_stack; /* malloc'd; a tracer's, kept between collections */
182
+
183
+ /* Incremental marking: an old collection's marking in
184
+ * slices, while the program runs and allocates. */
185
+ struct JSTracer *marker; /* the marking in progress (malloc'd), or NULL */
186
+ bool incremental; /* old collections mark incrementally (env JS_GC_INCREMENTAL=0: not) */
187
+ double mark_ratio; /* bytes to mark per byte allocated */
188
+ size_t slice_clock; /* the allocation clock at the last slice */
189
+ size_t next_slice; /* the next slice when the clock gets there */
190
+ size_t mark_alloc_limit; /* the final pause when it gets there, done or not */
191
+ double mark_rate; /* promotion_rate when the marking started */
192
+ double marking_ms; /* its pauses so far */
193
+ unsigned marking_slices;
194
+ /* Parallel marking: helper threads mark with the collector in
195
+ * its pauses, started when a marking first has enough to do. */
196
+ struct JSMarkPool *pool;
197
+ unsigned gc_helpers; /* how many (env JS_GC_THREADS) */
198
+ bool exact; /* the next collection abandons a marking in progress, and marks from scratch */
108
199
  size_t mark_stack_cap;
109
200
  size_t gc_count;
110
201
  int in_gc;
111
-
112
- /* Policy: collect when allocated_since_gc > max(min_heap, live_after_gc). */
202
+ int report; /* JS_GC_TRACE (1: each collection) / JS_GC_STATS (2: at exit) bits */
203
+ JSGCStats stats;
204
+
205
+ /* Policy: a young collection when what was allocated since the last one,
206
+ * cells and external memory, exceeds the nursery; it's a full one when the old generation
207
+ * (its cells and the external memory they keep) has outgrown old_limit, or the heap limit is
208
+ * near. Each full collection sets old_limit from how fast the old generation grew and how
209
+ * long the collection took, so that full collections take about JS_GC_TARGET of the time. */
113
210
  size_t allocated_since_gc; /* bytes handed to the allocator */
114
- size_t live_after_gc; /* bytes marked by the last collection */
211
+ size_t external_since_gc; /* external bytes added since the last collection */
212
+ size_t external_bytes; /* external memory now (js_gc_external_add / _sub) */
213
+ size_t live_after_gc; /* bytes marked by the last collection: the old generation's cells */
214
+ size_t old_after_full; /* the old generation after the last full collection */
215
+ size_t old_limit; /* a full collection when the old generation outgrows it */
216
+ double full_end_cpu; /* the thread's CPU time when the last full collection ended */
217
+ double pause_since_full; /* young pauses since then */
218
+ double growth; /* > 0: a fixed growth factor instead (env JS_GC_GROWTH) */
219
+ size_t nursery;
115
220
  size_t min_heap;
221
+ int full_next; /* the next collection is full */
222
+ int collect_requested; /* the next allocation collects, or marks a slice (external memory asked) */
223
+ size_t allocated_since_idle; /* cells and external memory, until the last collection */
224
+ bool idle; /* the collection running is js_gc_idle's */
116
225
  size_t heap_limit; /* 0 = unlimited; env JS_HEAP_LIMIT_MB */
117
226
  size_t stress_interval, stress_counter; /* JS_GC_STRESS builds; env JS_GC_STRESS_INTERVAL */
227
+ size_t stress_collections;
118
228
  } JSHeap;
119
229
 
120
230
  /* ---- Cell classes and tracing ---------------------------------------- */
@@ -125,6 +235,9 @@ typedef struct JSCellClass {
125
235
  const char *name;
126
236
  void (*visit)(JSCell *cell, JSTracer *trc); /* trace every JSValue the cell holds */
127
237
  void (*finalize)(JSRuntime *rt, JSCell *cell); /* NULL for almost all kinds */
238
+ /* Optional, for a large cell: trace what it holds in bytes [from, to) of the cell, at least.
239
+ * Without it a young collection visits a large remembered cell whole. */
240
+ void (*visit_range)(JSCell *cell, JSTracer *trc, size_t from, size_t to);
128
241
  } JSCellClass;
129
242
 
130
243
  /* Ignores non-cells and static cells. */
@@ -154,18 +267,18 @@ typedef struct JSHostCell {
154
267
 
155
268
  JSHostCell *js_alloc_host_cell(JSContext *ctx, const JSCellClass *cls, size_t size);
156
269
 
157
- /* ---- Stores into heap cells (ABI hook, ADR 0002) ---------------------- */
270
+ /* ---- Stores into heap cells (ABI hook) -------------------------------- */
158
271
 
159
- /* Every store of a JSValue into a cell that may already be reachable.
160
- * A plain store today; a generational or incremental barrier goes here. */
161
- static inline void js_store(JSContext *ctx, JSCell *owner, JSValue *slot, JSValue v) {
162
- (void)ctx;
163
- (void)owner;
164
- assert(!js_is_exception(v) && "JS_EXCEPTION stored into a cell (ADR 0004, invariant 3)");
165
- *slot = v;
166
- }
272
+ /* js_store and js_store_range, the write barrier, are in jscontext.h: they read the context. */
273
+
274
+ /* The barrier's slow path: `owner` is old; when `c` is a young cell, remembers the owner, or the
275
+ * card of a large one that `slot` is in (NULL: anywhere in it). */
276
+ void js_write_barrier_slow(JSContext *ctx, JSCell *owner, const void *slot, const JSCell *c);
277
+ /* Remembers an old `owner`, or `bytes` of a large one from `from`, whatever it was given. */
278
+ void js_remember(JSContext *ctx, JSCell *owner, const void *from, size_t bytes);
167
279
 
168
- /* Initializing store into a cell allocated with no allocation in between. */
280
+ /* Initializing store into a cell allocated with no allocation in between: the cell is young, so
281
+ * it needs no barrier. */
169
282
  static inline void js_init_slot(JSValue *slot, JSValue v) { *slot = v; }
170
283
 
171
284
  /* Keeps `v` visibly live to the conservative scan up to this point. */
@@ -185,11 +298,40 @@ void js_remove_root(JSRuntime *rt, JSValue *slot);
185
298
 
186
299
  /* ---- Control ----------------------------------------------------------- */
187
300
 
188
- void js_gc(JSContext *ctx); /* full collection */
301
+ void js_gc(JSContext *ctx); /* full collection: everything unreachable now (a marking in progress starts over) */
302
+ void js_gc_young(JSContext *ctx); /* young collection: the cells allocated since the last one */
303
+
304
+ /* Incremental marking, started and stepped by allocation;
305
+ * these drive it by hand, for tests. A slice marks about `bytes` bytes of cells, and runs the
306
+ * final pause when there's nothing left. js_gc and js_gc_young finish a marking in progress. */
307
+ void js_gc_start_marking(JSContext *ctx);
308
+ bool js_gc_marking(const JSRuntime *rt);
309
+ void js_gc_mark_slice(JSContext *ctx, size_t bytes);
310
+
311
+ /* The program is idle: the event loop waited JS_GC_IDLE_MS with nothing to
312
+ * do. When enough was allocated since the last time, js_gc_idle runs a full collection, finishes
313
+ * the sweeping, and gives back to the OS what's free: the empty blocks, and malloc's memory. */
314
+ #define JS_GC_IDLE_MS 1000
315
+ bool js_gc_idle_wanted(const JSRuntime *rt);
316
+ void js_gc_idle(JSContext *ctx);
317
+
318
+ /* External memory: bytes outside the heap that a cell owns and frees in its
319
+ * finalizer (an ArrayBuffer's), counted toward collections as if they were cells. `add` never
320
+ * collects: when the count calls for a collection, the next allocation runs it. `sub` is for
321
+ * the bytes freed, by the finalizer or before it. */
322
+ void js_gc_external_add(JSRuntime *rt, size_t bytes);
323
+ void js_gc_external_sub(JSRuntime *rt, size_t bytes);
324
+ /* malloc and free for memory a cell owns, counted as external memory: for libraries that take an
325
+ * allocator (zlib, Brotli, zstd), whose frees don't say the size. NULL when out of memory. */
326
+ void *js_gc_external_malloc(JSRuntime *rt, size_t bytes);
327
+ void js_gc_external_free(JSRuntime *rt, void *p);
189
328
 
190
329
  /* Exits with "heap limit reached" when the cells would need more than `bytes`. 0 = no limit. */
191
330
  void js_set_heap_limit(JSRuntime *rt, size_t bytes);
192
- /* Bytes currently mapped for cells: blocks (including empty ones) and large objects. */
331
+ /* Bytes currently committed for cells: blocks (empty ones included, decommitted ones not) and
332
+ * large objects. */
193
333
  size_t js_heap_size(const JSRuntime *rt);
334
+ /* The counters so far. */
335
+ const JSGCStats *js_gc_stats(const JSRuntime *rt);
194
336
 
195
337
  #endif /* JS_GC_H */