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,10 +1,8 @@
1
1
  /*
2
- * jscontext.h — the two runtime handles (ADR 0011).
2
+ * jscontext.h — the two runtime handles.
3
3
  *
4
4
  * JSRuntime the agent: heap and GC, atoms, pending exception, job queue
5
5
  * JSContext a realm: global object and intrinsics. Reaches the agent via ctx->rt.
6
- *
7
- * Fields are added as each ADR is implemented.
8
6
  */
9
7
  #ifndef JSCONTEXT_H
10
8
  #define JSCONTEXT_H
@@ -17,7 +15,7 @@
17
15
  #include "js_jobs.h"
18
16
 
19
17
  /* Room left below the stack limit for the throw path and for runtime C code
20
- * called after the last check (ADR 0004). Sanitizers make frames larger. */
18
+ * called after the last check. Sanitizers make frames larger. */
21
19
  #if defined(__SANITIZE_ADDRESS__)
22
20
  #define JS_STACK_MARGIN ((uintptr_t)256 * 1024)
23
21
  #elif defined(__has_feature)
@@ -32,8 +30,7 @@
32
30
  /* Typed array element types (js_buffer.h lists them): one constructor and prototype each. */
33
31
  #define JS_TYPED_ARRAY_TYPES 12
34
32
 
35
- /* Per-realm objects the runtime needs (ADR 0011). Filled in as the object
36
- * model and built-ins land (M3); every slot is a GC root. */
33
+ /* Per-realm objects the runtime needs; every slot is a GC root. */
37
34
  typedef enum JSIntrinsic {
38
35
  JS_INTRINSIC_GLOBAL_OBJECT, /* globalThis */
39
36
  JS_INTRINSIC_OBJECT_PROTOTYPE, /* %Object.prototype% */
@@ -70,7 +67,7 @@ typedef enum JSIntrinsic {
70
67
  JS_INTRINSIC_WEAK_SET_PROTOTYPE,
71
68
  JS_INTRINSIC_WEAK_REF_PROTOTYPE,
72
69
  JS_INTRINSIC_FINALIZATION_REGISTRY_PROTOTYPE,
73
- JS_INTRINSIC_MAP_PROTOTYPE, /* the collections component (ADR 0014), when installed */
70
+ JS_INTRINSIC_MAP_PROTOTYPE, /* the collections component, when installed */
74
71
  JS_INTRINSIC_SET_PROTOTYPE,
75
72
  JS_INTRINSIC_MAP_ITERATOR_PROTOTYPE,
76
73
  JS_INTRINSIC_SET_ITERATOR_PROTOTYPE,
@@ -96,11 +93,11 @@ typedef enum JSIntrinsic {
96
93
  JS_INTRINSIC_ERROR_STACK_SET,
97
94
  JS_INTRINSIC_ERROR, /* %Error%: Error.captureStackTrace reads its prepareStackTrace and stackTraceLimit */
98
95
  JS_INTRINSIC_CALL_SITE_PROTOTYPE, /* the placeholder call sites Error.prepareStackTrace receives */
99
- JS_INTRINSIC_REGEXP, /* %RegExp%, when the RegExp component is installed (ADR 0015) */
96
+ JS_INTRINSIC_REGEXP, /* %RegExp%, when the RegExp component is installed */
100
97
  JS_INTRINSIC_REGEXP_PROTOTYPE,
101
98
  JS_INTRINSIC_REGEXP_EXEC, /* the original RegExp.prototype.exec: RegExpExec calls it directly */
102
99
  JS_INTRINSIC_REGEXP_STRING_ITERATOR_PROTOTYPE,
103
- JS_INTRINSIC_DOM_EXCEPTION_PROTOTYPE, /* the web-standard host layer (ADR 0012, layer 2) */
100
+ JS_INTRINSIC_DOM_EXCEPTION_PROTOTYPE, /* the web-standard host layer */
104
101
  JS_INTRINSIC_TEXT_ENCODER_PROTOTYPE,
105
102
  JS_INTRINSIC_TEXT_DECODER_PROTOTYPE,
106
103
  JS_INTRINSIC_URL_PROTOTYPE,
@@ -111,7 +108,7 @@ typedef enum JSIntrinsic {
111
108
  JS_INTRINSIC_EVENT_TARGET_PROTOTYPE,
112
109
  JS_INTRINSIC_ABORT_SIGNAL_PROTOTYPE,
113
110
  JS_INTRINSIC_ABORT_CONTROLLER_PROTOTYPE,
114
- JS_INTRINSIC_BUFFER, /* Node's Buffer (ADR 0012, layer 3) */
111
+ JS_INTRINSIC_BUFFER, /* Node's Buffer */
115
112
  JS_INTRINSIC_BUFFER_PROTOTYPE,
116
113
  JS_INTRINSIC_HEADERS_PROTOTYPE,
117
114
  JS_INTRINSIC_HEADERS_ITERATOR_PROTOTYPE,
@@ -128,17 +125,17 @@ typedef enum JSIntrinsic {
128
125
  JS_INTRINSIC_FILE_PROTOTYPE,
129
126
  JS_INTRINSIC_REQUEST_PROTOTYPE,
130
127
  JS_INTRINSIC_RESPONSE_PROTOTYPE, /* the original entries: new URLSearchParams(params) copies directly */
131
- JS_INTRINSIC_CRYPTO, /* Web Crypto (ADR 0018): the crypto object */
128
+ JS_INTRINSIC_CRYPTO, /* Web Crypto: the crypto object */
132
129
  JS_INTRINSIC_CRYPTO_PROTOTYPE,
133
130
  JS_INTRINSIC_SUBTLE_CRYPTO, /* crypto.subtle */
134
131
  JS_INTRINSIC_SUBTLE_CRYPTO_PROTOTYPE,
135
132
  JS_INTRINSIC_CRYPTO_KEY_PROTOTYPE,
136
- JS_INTRINSIC_UTIL_INSPECT, /* the util.inspect function custom inspectors receive (ADR 0012) */
133
+ JS_INTRINSIC_UTIL_INSPECT, /* the util.inspect function custom inspectors receive */
137
134
  JS_INTRINSIC_CONSOLE_STATE, /* console's counters and timers, by label */
138
135
  JS_INTRINSIC_COUNT
139
136
  } JSIntrinsic;
140
137
 
141
- /* Shapes the GC processes weakly (ADR 0005): root shapes by (class, proto,
138
+ /* Shapes the GC processes weakly: root shapes by (class, proto,
142
139
  * capacity), and shapes whose transition tables point to children. */
143
140
  typedef struct JSShapeRegistry {
144
141
  struct JSShape **roots; /* open addressing; NULL = empty */
@@ -147,7 +144,7 @@ typedef struct JSShapeRegistry {
147
144
  size_t parent_count, parent_cap;
148
145
  } JSShapeRegistry;
149
146
 
150
- /* Registered inline-cache arrays (ADR 0005): reset weakly after marking. */
147
+ /* Registered inline-cache arrays: reset weakly after marking. */
151
148
  typedef struct JSPropCacheTables {
152
149
  struct JSPropCacheTable { struct JSPropCache *ics; size_t n; } *tables;
153
150
  size_t count, cap;
@@ -160,7 +157,7 @@ typedef enum JSCollectionPreview {
160
157
  JS_PREVIEW_MAP_ENTRIES, JS_PREVIEW_SET_ENTRIES, /* the [key, value] pairs left */
161
158
  } JSCollectionPreview;
162
159
 
163
- /* An I/O backend for the event loop (ADR 0008): libuv, set by the host code that first needs it
160
+ /* An I/O backend for the event loop: libuv, set by the host code that first needs it
164
161
  * (node:http), so that programs without I/O don't link libuv. */
165
162
  typedef struct JSIOBackend {
166
163
  bool (*alive)(JSRuntime *rt); /* open handles (servers, sockets) keep the program running */
@@ -174,16 +171,21 @@ struct JSRuntime {
174
171
  JSShapeRegistry shapes;
175
172
  JSPropCacheTables prop_caches;
176
173
  /* the shared second-level caches (object.c): get and set entries by (shape, key), for the
177
- * sites a monomorphic cache misses and C code's lookups; emptied at every collection */
178
- struct JSMegaEntry *mega_get, *mega_set;
174
+ * sites a monomorphic cache misses and C code's lookups, and the shape that defining a new
175
+ * key gives (object literals); emptied at every collection */
176
+ struct JSMegaEntry *mega_get, *mega_set, *mega_define;
177
+ /* Bumped when an object that is some shape's prototype changes shape (js_object_set_shape):
178
+ * caches that saw a prototype chain (ADD, PROTO) and remember the epoch it had are good
179
+ * while it's the same, without walking the chain again (optimizer step 11). */
180
+ uint32_t proto_epoch;
179
181
  JSContext *realms; /* every live JSContext, linked through next_realm */
180
- JSAtomTable atoms; /* weak (ADR 0003) */
181
- JSValue exception; /* pending exception, JS_EMPTY if none; a GC root (ADR 0004) */
182
+ JSAtomTable atoms; /* weak */
183
+ JSValue exception; /* pending exception, JS_EMPTY if none; a GC root */
182
184
  JSValue symbol_registry; /* Symbol.for's GlobalSymbolRegistry: key -> symbol (a root) */
183
185
  uintptr_t stack_limit; /* lowest usable stack address, margin included */
184
- JSJobQueue jobs; /* microtasks (ADR 0008) */
185
- JSTimers timers; /* setTimeout / setInterval (ADR 0008) */
186
- /* The async context (ADR 0020): an opaque value the host keeps per chain of async work
186
+ JSJobQueue jobs; /* microtasks */
187
+ JSTimers timers; /* setTimeout / setInterval */
188
+ /* The async context: an opaque value the host keeps per chain of async work
187
189
  * (node:async_hooks' AsyncLocalStorage keeps its stores in it). Every job, timer and promise
188
190
  * reaction takes the one current when it was queued, and runs under it. Undefined: none. A root. */
189
191
  JSValue async_context;
@@ -198,13 +200,13 @@ struct JSRuntime {
198
200
  int (*on_uncaught)(JSContext *ctx, JSValue error, JSValue promise);
199
201
  int (*on_handled_late)(JSContext *ctx, JSValue promise);
200
202
  uint8_t failure; /* the exit status after an uncaught error: 1, or on_uncaught's */
201
- struct JSWeakList { struct JSObject **items; size_t count, cap; } weak; /* WeakMap/Set/Ref, registries (ADR 0002) */
203
+ struct JSWeakList { struct JSObject **items; size_t count, cap; } weak; /* WeakMap/Set/Ref, registries */
202
204
  struct JSKeptAlive { JSValue *items; size_t count, cap; } kept_alive; /* [[KeptAlive]]: roots until ClearKeptObjects */
203
- const struct JSComponent *const *components; /* installed in every realm (ADR 0014) */
205
+ const struct JSComponent *const *components; /* installed in every realm */
204
206
  size_t ncomponents;
205
207
  const struct JSCoreEntry *core; /* the core methods every realm installs (js_core.def) */
206
208
  size_t ncore;
207
- /* Set by the collections component (ADR 0014: core reaches optional components through
209
+ /* Set by the collections component (core reaches optional components through
208
210
  * hooks): a Map's or Set's entries, or what an iterator has left, as an array (flat
209
211
  * [k1, v1, k2, v2, …] for a Map and the entries iterators); EMPTY for other values. */
210
212
  JSValue (*collection_preview)(JSContext *ctx, JSValue v, JSCollectionPreview *what);
@@ -213,9 +215,12 @@ struct JSRuntime {
213
215
  JSValue (*date_inspect)(JSContext *ctx, JSValue v);
214
216
  /* Set by RegExp: a RegExp's "/source/flags" for util.inspect; EMPTY otherwise. */
215
217
  JSValue (*regexp_inspect)(JSContext *ctx, JSValue v);
216
- const JSBigIntOps *bigint; /* set by the bigint component (ADR 0016) */
218
+ const JSBigIntOps *bigint; /* set by the bigint component */
217
219
  /* A typed array's length now: -1 when out of bounds (detached), -2 for anything else. */
218
220
  double (*typed_array_length)(JSValue v);
221
+ /* Set by typed arrays: a typed array's or DataView's bytes (its current window), true; false
222
+ * for anything else (an ArrayBuffer too: process.stdout.write takes views only). */
223
+ bool (*view_bytes)(JSValue v, uint8_t **data, size_t *length);
219
224
  const JSIOBackend *io; /* the event loop's I/O, once a program uses some */
220
225
  uint8_t rejection_mode; /* JSRejectionMode */
221
226
  uint8_t in_checkpoint; /* js_run_microtasks is running */
@@ -224,6 +229,7 @@ struct JSRuntime {
224
229
  struct JSContext {
225
230
  JSRuntime *rt;
226
231
  uintptr_t stack_limit; /* copy of rt->stack_limit: one load in every function prologue */
232
+ uint8_t barrier_threshold; /* js_store's slow path runs for an owner whose GC byte is this or more */
227
233
  JSValue intrinsics[JS_INTRINSIC_COUNT];
228
234
  JSContext *next_realm;
229
235
  };
@@ -232,23 +238,52 @@ JSRuntime *js_runtime_new(void);
232
238
  void js_runtime_free(JSRuntime *rt); /* frees every cell, running finalizers */
233
239
  JSContext *js_context_new(JSRuntime *rt); /* a new realm; js_runtime_free frees any left */
234
240
  void js_context_free(JSContext *ctx);
235
- /* The test262 host (ADR 0011): defines $262 on ctx's global object and returns it. */
241
+ /* The test262 host: defines $262 on ctx's global object and returns it. */
236
242
  JSValue js_test_host_init(JSContext *ctx);
237
243
 
238
- /* Allocation fast path: pop the class's free list and zero the cell (ADR 0002).
239
- * Zeroed memory reads as JS_EMPTY, so a half-initialized cell is always safe to trace.
240
- * GC-stress builds (ADR 0011) always take the slow path, which collects first. */
244
+ /* Every store of a JSValue into a cell that may already be reachable: the write barrier.
245
+ * One compare when the owner is young or already remembered. */
246
+ static inline void js_store(JSContext *ctx, JSCell *owner, JSValue *slot, JSValue v) {
247
+ assert(!js_is_exception(v) && "JS_EXCEPTION stored into a cell");
248
+ *slot = v;
249
+ if (JS_UNLIKELY(owner->gc >= ctx->barrier_threshold) && js_is_cell(v)) js_write_barrier_slow(ctx, owner, slot, js_as_cell(v));
250
+ }
251
+
252
+ /* The barrier alone, after storing `v` at `slot` (NULL: in malloc'd memory) where js_store can't
253
+ * write: a malloc'd table's entry, a struct holding several values. */
254
+ static inline void js_write_barrier(JSContext *ctx, JSCell *owner, const void *slot, JSValue v) {
255
+ if (JS_UNLIKELY(owner->gc >= ctx->barrier_threshold) && js_is_cell(v)) js_write_barrier_slow(ctx, owner, slot, js_as_cell(v));
256
+ }
257
+
258
+ /* The barrier for a store of a cell pointer (a JSShape *, a JSEnv *, ...) into `owner`, after the
259
+ * store: js_store_ptr does both. */
260
+ static inline void js_write_barrier_cell(JSContext *ctx, JSCell *owner, const void *slot, const JSCell *c) {
261
+ if (JS_UNLIKELY(owner->gc >= ctx->barrier_threshold) && c) js_write_barrier_slow(ctx, owner, slot, c);
262
+ }
263
+ #define js_store_ptr(ctx, owner, slot, p) \
264
+ do { *(slot) = (p); js_write_barrier_cell((ctx), (owner), (slot), (const JSCell *)(p)); } while (0)
265
+
266
+ /* Copies `n` values into `owner` (memmove: the ranges may overlap), then remembers the owner if
267
+ * it's old: one barrier for a bulk copy. */
268
+ static inline void js_store_range(JSContext *ctx, JSCell *owner, JSValue *dst, const JSValue *src, size_t n) {
269
+ memmove(dst, src, n * sizeof *dst);
270
+ if (JS_UNLIKELY(owner->gc >= ctx->barrier_threshold) && n) js_remember(ctx, owner, dst, n * sizeof *dst);
271
+ }
272
+
273
+ /* Allocation fast path: the lowest free cell of the class's window.
274
+ * Its cells are zeroed, and zeroed memory reads as JS_EMPTY, so a half-initialized cell is always
275
+ * safe to trace. Checking builds (JS_GC_VERIFY, implied by JS_GC_STRESS) always take the slow
276
+ * path, which checks the dead cell and, under stress, collects first. */
241
277
  static inline void *js_alloc_small(JSContext *ctx, unsigned size_class) {
242
- #ifdef JS_GC_STRESS
243
- JSFreeCell *c = (JSFreeCell *)js_alloc_slow(ctx, size_class);
244
- #else
245
- JSHeap *h = &ctx->rt->heap;
246
- JSFreeCell *c = h->free[size_class];
247
- if (JS_LIKELY(c)) h->free[size_class] = c->next;
248
- else c = (JSFreeCell *)js_alloc_slow(ctx, size_class);
278
+ #ifndef JS_GC_VERIFY
279
+ JSAllocator *a = &ctx->rt->heap.alloc[size_class];
280
+ uint64_t free = a->free;
281
+ if (JS_LIKELY(free)) {
282
+ a->free = free & (free - 1);
283
+ return (void *)(a->base + js_ctz64(free) * a->cell_size);
284
+ }
249
285
  #endif
250
- memset(c, 0, js_size_class_bytes[size_class]);
251
- return c;
286
+ return js_alloc_slow(ctx, size_class);
252
287
  }
253
288
 
254
289
  #endif /* JSCONTEXT_H */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * jsnum.h — number <-> string conversion (ADR 0013).
2
+ * jsnum.h — number <-> string conversion.
3
3
  *
4
4
  * Digit generation and rounding come from the vendored QuickJS dtoa.c.
5
5
  * The JS grammar (StringNumericLiteral) is ours.
@@ -1,11 +1,12 @@
1
1
  /*
2
- * jsstring.h — strings (ADR 0003).
2
+ * jsstring.h — strings.
3
3
  *
4
4
  * A string is a sequence of UTF-16 code units. Cells are flat (characters
5
5
  * inline, Latin-1 when every unit is <= 0xFF, else UTF-16), ropes (lazy
6
6
  * concatenations, flattened on first read) or slices (long substrings, which
7
- * share their parent's characters). Everything that reads characters goes
8
- * through a JSStrView.
7
+ * share their parent's characters). Strings built by appending in a loop are
8
+ * slices of a buffer: a flat cell with room to grow (below). Everything that
9
+ * reads characters goes through a JSStrView.
9
10
  */
10
11
  #ifndef JSSTRING_H
11
12
  #define JSSTRING_H
@@ -23,12 +24,21 @@ typedef struct JSContext JSContext;
23
24
  #define JS_STR_LATIN1 0x01u /* flat: 1 byte per unit; rope: both sides are Latin-1; slice: the parent is */
24
25
  #define JS_STR_ATOM 0x02u /* the unique interned copy of its content */
25
26
  #define JS_STR_PRIVATE 0x04u /* a private name (#x): a property key no key listing shows */
27
+ #define JS_STR_BUFFER 0x08u /* flat: an append buffer, only ever a slice's parent (below) */
26
28
 
27
- #define JS_STRING_MAX_LENGTH ((UINT32_C(1) << 30) - 1)
29
+ /* V8's String::kMaxLength on 64-bit, which Node's buffer.constants.MAX_STRING_LENGTH reports */
30
+ #define JS_STRING_MAX_LENGTH ((UINT32_C(1) << 29) - 24)
28
31
  #define JS_ROPE_MIN 13 /* shorter concatenations copy instead */
29
32
  #define JS_ROPE_MAX_DEPTH 1024 /* deeper concatenations flatten eagerly */
30
33
  #define JS_SLICE_MIN 13 /* shorter substrings copy instead */
31
34
  #define JS_SLICE_MAX_WASTE 4 /* a slice is at least 1/4 of its parent; smaller ones copy */
35
+ #define JS_BUFFER_MIN_DEPTH 16 /* appending to a rope this deep continues in a buffer */
36
+
37
+ /* An append buffer is a STR_FLAT with JS_STR_BUFFER: `length` units are filled
38
+ * and never change again, `cell.aux` is its capacity. JS code never sees one,
39
+ * only slices of it at offset 0. Appending to the slice that ends at the fill
40
+ * mark (the newest string built in it) writes past the mark and returns a
41
+ * longer slice; any older one is a shorter prefix and stays valid. */
32
42
 
33
43
  typedef struct JSString { /* kind = STR_FLAT */
34
44
  JSCell cell; /* flags: STR_LATIN1, STR_ATOM, CELL_STATIC */
@@ -126,7 +136,10 @@ uint32_t js_string_hash(JSContext *ctx, JSValue s); /* cached in the cell (not
126
136
 
127
137
  /* "" and every single code unit 0…255: static atoms, never allocated. */
128
138
  JSValue js_empty_string(void);
129
- JSValue js_char_string(uint8_t unit);
139
+ typedef JS_STATIC_LATIN1_TYPE(1) JSStaticChar;
140
+ extern const JSStaticChar js_char_strings[256];
141
+ /* Inline: generated code names one-character keys (`o.x`) with it at every access. */
142
+ static inline JSValue js_char_string(uint8_t unit) { return js_cell((JSCell *)&js_char_strings[unit]); }
130
143
 
131
144
  /* ---- Creating strings -------------------------------------------------- */
132
145
 
@@ -149,7 +162,7 @@ bool js_string_equals(JSContext *ctx, JSValue a, JSValue b);
149
162
  /* <0, 0, >0 by code units (the relational operators on strings). */
150
163
  int js_string_compare(JSContext *ctx, JSValue a, JSValue b);
151
164
 
152
- /* Number::toString(n) as a string cell (ADR 0013). `n` is an int32 or a double. */
165
+ /* Number::toString(n) as a string cell. `n` is an int32 or a double. */
153
166
  JSValue js_number_to_string(JSContext *ctx, JSValue n);
154
167
 
155
168
  /* ---- Output ------------------------------------------------------------ */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * jsvalue.h — JS value representation (ADR 0001).
2
+ * jsvalue.h — JS value representation.
3
3
  *
4
4
  * NaN-boxing with raw pointers (JavaScriptCore layout):
5
5
  *
@@ -21,12 +21,16 @@
21
21
  #if defined(__GNUC__) || defined(__clang__)
22
22
  #define JS_LIKELY(x) __builtin_expect(!!(x), 1)
23
23
  #define JS_UNLIKELY(x) __builtin_expect(!!(x), 0)
24
+ /* An inline cache's hit, at every site of a big function too (the compiler's size limits would
25
+ * otherwise leave a call there): only fast paths of a few instructions. */
26
+ #define JS_FAST_PATH inline __attribute__((always_inline))
24
27
  #else
25
28
  #define JS_LIKELY(x) (x)
26
29
  #define JS_UNLIKELY(x) (x)
30
+ #define JS_FAST_PATH inline
27
31
  #endif
28
32
 
29
- /* On every runtime function that can fail (ADR 0004): ignoring its result is an error. */
33
+ /* On every runtime function that can fail: ignoring its result is an error. */
30
34
  #if defined(__GNUC__) || defined(__clang__)
31
35
  #define JS_WARN_UNUSED __attribute__((warn_unused_result))
32
36
  #elif defined(_MSC_VER)
@@ -59,7 +63,7 @@ typedef struct { uint64_t bits; } JSValue;
59
63
  #define JS_TAG_FALSE UINT64_C(0x06)
60
64
  #define JS_TAG_TRUE UINT64_C(0x07)
61
65
  #define JS_TAG_UNDEFINED UINT64_C(0x0A)
62
- #define JS_TAG_EXCEPTION UINT64_C(0x0E) /* internal: "an exception is pending" (ADR 0004) */
66
+ #define JS_TAG_EXCEPTION UINT64_C(0x0E) /* internal: "an exception is pending" */
63
67
 
64
68
  #define JS_EMPTY ((JSValue){ JS_TAG_EMPTY })
65
69
  #define JS_NULL ((JSValue){ JS_TAG_NULL })
@@ -1,4 +1,4 @@
1
- /* Arguments objects (ECMAScript §10.4.4; ADR 0006 prologue).
1
+ /* Arguments objects (ECMAScript §10.4.4).
2
2
  *
3
3
  * Unmapped (strict code, or a non-simple parameter list): an ordinary object of
4
4
  * the Arguments class holding the argument values, `length`, and a `callee` that
@@ -94,7 +94,7 @@ JSValue js_new_arguments(JSContext *ctx, JSValue args, JSValue callee, JSValue e
94
94
  js_define_data(ctx, o, JS_SYMBOL(iterator), ctx->intrinsics[JS_INTRINSIC_ARRAY_VALUES], JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
95
95
  if (slots) {
96
96
  /* mapped: only the parameters actually passed alias (§10.4.4.7 step 15), and at most 64 */
97
- a->env = js_as_env(env);
97
+ js_store_ptr(ctx, &a->obj.cell, &a->env, js_as_env(env));
98
98
  a->slots = slots;
99
99
  for (uint32_t i = 0; i < nmapped && i < argc && i < 64; i++)
100
100
  if (slots[i] != UINT32_MAX) a->mapped |= (uint64_t)1 << i; /* duplicate names: only the last maps */
@@ -1,4 +1,4 @@
1
- /* Array and Array.prototype (§23.1): core built-ins (ADR 0014). The methods are generic, as
1
+ /* Array and Array.prototype (§23.1): core built-ins. The methods are generic, as
2
2
  * the spec makes them: they work on any array-like through Get/Set/HasProperty/Delete, so
3
3
  * holes, getters and proxies-to-come behave as in V8. Methods that create arrays honour
4
4
  * Symbol.species (ArraySpeciesCreate). */
@@ -8,6 +8,7 @@
8
8
  #include <stdlib.h>
9
9
  #include <string.h>
10
10
 
11
+ #include "elements.h"
11
12
  #include "internal.h"
12
13
  #include "js_atoms.h"
13
14
  #include "js_convert.h"
@@ -502,6 +503,8 @@ CORE(array_proto_fill) {
502
503
  double len, k, final;
503
504
  if (receiver(ctx, this_val, "Array.prototype.fill", &len) < 0) return JS_EXCEPTION;
504
505
  if (js_relative_index(ctx, ARG(1), len, 0, &k) < 0 || js_relative_index(ctx, ARG(2), len, len, &final) < 0) return JS_EXCEPTION;
506
+ /* an array's length is below 2^32: k and final are uint32s */
507
+ if (js_is_array(this_val) && k < final && js_elements_fill(ctx, js_as_object(this_val), (uint32_t)k, (uint32_t)final, ARG(0))) return this_val;
505
508
  for (; k < final; k++)
506
509
  if (set_index(ctx, this_val, k, ARG(0)) < 0) return JS_EXCEPTION;
507
510
  return this_val;
@@ -1,9 +1,10 @@
1
- /* ArrayBuffer and DataView (ECMAScript §25.1, §25.3), the arraybuffer component (ADR 0014):
1
+ /* ArrayBuffer and DataView (ECMAScript §25.1, §25.3), the arraybuffer component:
2
2
  * resizable buffers, transfer, and the immutable-ArrayBuffer proposal; DataView with Float16.
3
- * The BigInt64 accessors exist when the bigint component does (ADR 0016).
3
+ * The BigInt64 accessors exist when the bigint component does.
4
4
  *
5
- * A buffer's bytes are malloc'd and freed by its finalizer. A detached buffer has no bytes and
6
- * length 0. Views read the buffer's current data pointer and length on every access, since a
5
+ * A buffer's bytes are malloc'd and freed by its finalizer, and counted as the heap's external
6
+ * memory: byte_length of them while it has any. A detached buffer has no
7
+ * bytes and length 0. Views read the buffer's current data pointer and length on every access, since a
7
8
  * resize or a transfer may move or drop the bytes. */
8
9
  #include <math.h>
9
10
  #include <stdio.h>
@@ -27,8 +28,9 @@
27
28
  /* ---- ArrayBuffer objects --------------------------------------------------------------------- */
28
29
 
29
30
  static void buffer_finalize(JSRuntime *rt, JSCell *c) {
30
- (void)rt;
31
- free(((JSArrayBuffer *)c)->data);
31
+ JSArrayBuffer *b = (JSArrayBuffer *)c;
32
+ if (b->data) js_gc_external_sub(rt, b->byte_length);
33
+ free(b->data);
32
34
  }
33
35
 
34
36
  static const JSClass array_buffer_class = { "ArrayBuffer", sizeof(JSArrayBuffer), NULL, NULL, NULL, NULL, NULL, buffer_finalize, NULL };
@@ -64,6 +66,12 @@ static int alloc_bytes(JSContext *ctx, double length, uint8_t **out) {
64
66
  return 0;
65
67
  }
66
68
 
69
+ /* A buffer's bytes went from `from` to `to` (0: none). */
70
+ static void resize_external(JSContext *ctx, size_t from, size_t to) {
71
+ if (to > from) js_gc_external_add(ctx->rt, to - from);
72
+ else js_gc_external_sub(ctx->rt, from - to);
73
+ }
74
+
67
75
  /* AllocateArrayBuffer (§25.1.3.1): the prototype first, then the bytes. max < 0: not resizable. */
68
76
  static JSValue allocate(JSContext *ctx, JSValue new_target, double length, double max) {
69
77
  if (max >= 0 && length > max) return js_throw_range_error(ctx, "Invalid array buffer max length");
@@ -75,6 +83,7 @@ static JSValue allocate(JSContext *ctx, JSValue new_target, double length, doubl
75
83
  JSArrayBuffer *b = (JSArrayBuffer *)js_alloc_object(ctx, JS_CELL_OBJECT, js_shape_root(ctx, &array_buffer_class, proto, 0));
76
84
  b->data = data;
77
85
  b->byte_length = (size_t)length;
86
+ if (data) js_gc_external_add(ctx->rt, b->byte_length);
78
87
  b->max_byte_length = max >= 0 ? (size_t)max : (size_t)length;
79
88
  b->flags = max >= 0 ? JS_BUFFER_RESIZABLE : 0;
80
89
  return js_object_value(&b->obj);
@@ -90,6 +99,7 @@ int js_array_buffer_detach(JSContext *ctx, JSValue buffer) {
90
99
  js_discard(js_throw_type_error(ctx, "Cannot detach an immutable ArrayBuffer"));
91
100
  return -1;
92
101
  }
102
+ if (b->data) js_gc_external_sub(ctx->rt, b->byte_length);
93
103
  free(b->data);
94
104
  b->data = NULL;
95
105
  b->byte_length = 0;
@@ -198,6 +208,7 @@ BUILTIN(array_buffer_resize) {
198
208
  if (n > b->byte_length) memset(data + b->byte_length, 0, n - b->byte_length);
199
209
  b->data = data;
200
210
  }
211
+ resize_external(ctx, b->byte_length, n);
201
212
  b->byte_length = n;
202
213
  return JS_UNDEFINED;
203
214
  }
@@ -295,6 +306,7 @@ static JSValue copy_and_detach(JSContext *ctx, JSValue this_val, JSValue new_len
295
306
  if (!data) return js_throw_range_error(ctx, "Array buffer allocation failed");
296
307
  if (n > b->byte_length) memset(data + b->byte_length, 0, n - b->byte_length);
297
308
  }
309
+ resize_external(ctx, b->byte_length, n); /* counted for nb from here on */
298
310
  b->data = NULL; /* allocate() may collect: b must not free them */
299
311
  JSValue r = allocate(ctx, JS_UNDEFINED, 0, max);
300
312
  JSArrayBuffer *nb = js_as_array_buffer(r);
@@ -575,7 +587,7 @@ static const JSBuiltin data_view_proto[] = {
575
587
  JS_BUILTIN_SYMBOL_STRING(toStringTag, "DataView", JS_PROP_CONFIGURABLE),
576
588
  };
577
589
 
578
- /* with BigInt (ADR 0016): the bigint component is installed first when the program reaches it */
590
+ /* with BigInt: the bigint component is installed first when the program reaches it */
579
591
  static const JSBuiltin data_view_bigint_proto[] = {
580
592
  JS_BUILTIN_FN("getBigInt64", data_view_get_BigInt64, 1),
581
593
  JS_BUILTIN_FN("setBigInt64", data_view_set_BigInt64, 2),
@@ -1,6 +1,6 @@
1
1
  /* Async generators (ECMAScript §27.6) and async iteration (§27.1.4–6): the request queue
2
2
  * and its driver, %AsyncIteratorPrototype%, the async-from-sync iterator, for await, and
3
- * yield* in async generators (§15.5.5). ADR 0007. */
3
+ * yield* in async generators (§15.5.5). */
4
4
  #include "internal.h"
5
5
  #include "js_atoms.h"
6
6
  #include "js_builtins.h"
@@ -55,7 +55,7 @@ static void request_visit(JSCell *c, JSTracer *trc) {
55
55
  js_trace_value(trc, r->promise);
56
56
  js_trace_value(trc, r->next);
57
57
  }
58
- static const JSCellClass request_class = { "AsyncGeneratorRequest", request_visit, NULL };
58
+ static const JSCellClass request_class = { "AsyncGeneratorRequest", request_visit, NULL, NULL };
59
59
 
60
60
  static const JSClass async_generator_class = { "AsyncGenerator", sizeof(JSGenerator), NULL, NULL, NULL, NULL, js_generator_visit, NULL, NULL };
61
61
 
@@ -324,7 +324,7 @@ static void async_iter_visit(JSCell *c, JSTracer *trc) {
324
324
  js_trace_value(trc, ((AsyncIter *)c)->iterator);
325
325
  js_trace_value(trc, ((AsyncIter *)c)->next);
326
326
  }
327
- static const JSCellClass async_iter_class = { "AsyncIteratorRecord", async_iter_visit, NULL };
327
+ static const JSCellClass async_iter_class = { "AsyncIteratorRecord", async_iter_visit, NULL, NULL };
328
328
 
329
329
  static AsyncIter *rec_of(JSValue rec) { return (AsyncIter *)js_as_cell(rec); }
330
330
 
@@ -473,6 +473,7 @@ static void install_async_iterator(JSContext *ctx, JSObject *global) {
473
473
  JSObject *agp = js_as_object(in[JS_INTRINSIC_ASYNC_GENERATOR_PROTOTYPE]);
474
474
  js_define_data(ctx, agfp, JS_ATOM(prototype), in[JS_INTRINSIC_ASYNC_GENERATOR_PROTOTYPE], JS_PROP_CONFIGURABLE);
475
475
  js_define_data(ctx, agfp, JS_SYMBOL(toStringTag), js_atom_from_cstr(ctx, "AsyncGeneratorFunction"), JS_PROP_CONFIGURABLE);
476
+ js_define_function_kind_ctor(ctx, in[JS_INTRINSIC_ASYNC_GENERATOR_FUNCTION_PROTOTYPE], 2);
476
477
  js_define_data(ctx, agp, JS_ATOM(constructor), in[JS_INTRINSIC_ASYNC_GENERATOR_FUNCTION_PROTOTYPE], JS_PROP_CONFIGURABLE);
477
478
  (void)js_define_method(ctx, agp, "next", async_generator_next, 1);
478
479
  (void)js_define_method(ctx, agp, "return", async_generator_return, 1);
@@ -1,4 +1,4 @@
1
- /* Atoms: interned strings, held weakly (ADR 0003). */
1
+ /* Atoms: interned strings, held weakly. */
2
2
  #include "js_atoms.h"
3
3
 
4
4
  #include <stdlib.h>
@@ -1,5 +1,5 @@
1
- /* atob and btoa (HTML §8.3, forgiving-base64 in Infra §4.7), the base64 component (ADR 0012,
2
- * layer 2), which needs domexception: Node's checks, in Node's order, and its DOMExceptions. */
1
+ /* atob and btoa (HTML §8.3, forgiving-base64 in Infra §4.7), the base64 component,
2
+ * which needs domexception: Node's checks, in Node's order, and its DOMExceptions. */
3
3
  #include <stdlib.h>
4
4
 
5
5
  #include "builtins_util.h"
@@ -1,4 +1,4 @@
1
- /* BigInt (ECMAScript §6.1.6.2, §21.2), the bigint component (ADR 0016).
1
+ /* BigInt (ECMAScript §6.1.6.2, §21.2), the bigint component.
2
2
  *
3
3
  * The arithmetic is ported from QuickJS (https://github.com/bellard/quickjs, upstream commit
4
4
  * a38171d37357edff256c28a73eaeb41d2466d1d5, the one runtime/third_party/quickjs-dtoa comes from):
@@ -1,4 +1,4 @@
1
- /* Blob and File (File API §3, §4), the blob component (ADR 0012, layer 2), as Node has them: a
1
+ /* Blob and File (File API §3, §4), the blob component, as Node has them: a
2
2
  * blob keeps its bytes (a copy of its parts: strings as UTF-8, buffer sources, other blobs);
3
3
  * text(), arrayBuffer() and bytes() resolve with them, stream() is a ReadableStream of them
4
4
  * (the streams component). Node's errors and inspection (`Blob { size: 3, type: '' }`). */
@@ -39,8 +39,9 @@ static void blob_visit(JSCell *c, JSTracer *trc) {
39
39
  js_trace_value(trc, ((BlobObject *)c)->name);
40
40
  }
41
41
  static void blob_finalize(JSRuntime *rt, JSCell *c) {
42
- (void)rt;
43
- free(((BlobObject *)c)->data);
42
+ BlobObject *b = (BlobObject *)c;
43
+ if (b->data) js_gc_external_sub(rt, b->size);
44
+ free(b->data);
44
45
  }
45
46
 
46
47
  static const JSClass blob_class = { "Blob", sizeof(BlobObject), NULL, NULL, NULL, NULL, blob_visit, blob_finalize, NULL };
@@ -53,6 +54,7 @@ static JSValue new_blob(JSContext *ctx, JSValue proto, uint8_t *data, size_t siz
53
54
  BlobObject *b = (BlobObject *)js_alloc_object(ctx, JS_CELL_OBJECT, js_shape_root(ctx, &blob_class, proto, 2));
54
55
  b->data = data;
55
56
  b->size = size;
57
+ if (data) js_gc_external_add(ctx->rt, size); /* the heap's external memory */
56
58
  js_init_slot(&b->type, type);
57
59
  js_init_slot(&b->name, JS_UNDEFINED);
58
60
  b->last_modified = 0;
@@ -97,11 +99,12 @@ static void put(Bytes *b, const uint8_t *p, size_t n) {
97
99
  }
98
100
 
99
101
  /* The parts' bytes: a sequence of strings, buffer sources and blobs. 0, or -1. */
100
- static int collect_parts(JSContext *ctx, JSValue parts, const char *arg, Bytes *out) {
102
+ static int collect_parts(JSContext *ctx, JSValue parts, Bytes *out) {
101
103
  if (js_is_undefined(parts)) return 0;
102
104
  JSValue method = js_is_object(parts) ? js_get_value(ctx, parts, JS_SYMBOL(iterator)) : JS_UNDEFINED;
103
105
  if (js_is_exception(method)) return -1;
104
- if (!js_is_callable(method)) return fail(js_throw_invalid_arg_type(ctx, arg, "a sequence", parts));
106
+ if (!js_is_callable(method)) /* Node 24: WebIDL's sequence<BlobPart> conversion */
107
+ return fail(js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_INVALID_ARG_TYPE", "Value cannot be converted to sequence."));
105
108
  JSValue rec = js_iter_start(ctx, parts);
106
109
  if (js_is_exception(rec)) return -1;
107
110
  for (;;) {
@@ -146,7 +149,7 @@ BUILTIN(blob_ctor) {
146
149
  (void)callee, (void)this_val;
147
150
  if (js_is_undefined(new_target)) return js_throw_class_without_new(ctx, "Blob");
148
151
  Bytes bytes = { 0 };
149
- if (collect_parts(ctx, ARG(0), "sources", &bytes) < 0) {
152
+ if (collect_parts(ctx, ARG(0), &bytes) < 0) {
150
153
  free(bytes.p);
151
154
  return JS_EXCEPTION;
152
155
  }
@@ -165,7 +168,7 @@ BUILTIN(file_ctor) {
165
168
  if (js_is_undefined(new_target)) return js_throw_class_without_new(ctx, "File");
166
169
  if (argc < 2) return js_throw_node_error(ctx, JS_TYPE_ERROR, "ERR_MISSING_ARGS", "The \"fileBits\" and \"fileName\" arguments must be specified");
167
170
  Bytes bytes = { 0 };
168
- if (collect_parts(ctx, argv[0], "fileBits", &bytes) < 0) {
171
+ if (collect_parts(ctx, argv[0], &bytes) < 0) {
169
172
  free(bytes.p);
170
173
  return JS_EXCEPTION;
171
174
  }
@@ -208,14 +211,14 @@ BUILTIN(blob_type) {
208
211
  BUILTIN(file_name) {
209
212
  UNUSED_ARGS;
210
213
  BlobObject *b = as_blob(this_val);
211
- if (!b || js_is_undefined(b->name)) return js_throw_type_error(ctx, "Cannot read private member #name from an object whose class did not declare it");
214
+ if (!b || js_is_undefined(b->name)) return js_throw_invalid_this(ctx, "File");
212
215
  return b->name;
213
216
  }
214
217
 
215
218
  BUILTIN(file_last_modified) {
216
219
  UNUSED_ARGS;
217
220
  BlobObject *b = as_blob(this_val);
218
- if (!b || js_is_undefined(b->name)) return js_throw_type_error(ctx, "Cannot read private member #lastModified from an object whose class did not declare it");
221
+ if (!b || js_is_undefined(b->name)) return js_throw_invalid_this(ctx, "File");
219
222
  return js_number(b->last_modified);
220
223
  }
221
224
 
@@ -306,6 +309,15 @@ BUILTIN(blob_stream) {
306
309
  return js_readable_stream_of_bytes(ctx, b->size ? u8 : JS_UNDEFINED);
307
310
  }
308
311
 
312
+ /* textStream() (Node 24): the text, decoded as text() decodes it, as a stream's one chunk */
313
+ BUILTIN(blob_text_stream) {
314
+ UNUSED_ARGS;
315
+ THIS_BLOB();
316
+ JSValue text = js_decode_utf8_bytes(ctx, b->data, b->size);
317
+ if (js_is_exception(text)) return text;
318
+ return js_readable_stream_of_chunk(ctx, b->size ? text : JS_UNDEFINED);
319
+ }
320
+
309
321
  /* `Blob { size: 3, type: '' }`, `File { size: 2, type: '', name: 'a.txt', lastModified: 5 }` */
310
322
  BUILTIN(blob_inspect) {
311
323
  UNUSED_ARGS;
@@ -348,6 +360,7 @@ static const JSBuiltin blob_proto[] = {
348
360
  WEBIDL_OPERATION("text", blob_text, 0),
349
361
  WEBIDL_OPERATION("bytes", blob_bytes, 0),
350
362
  WEBIDL_OPERATION("stream", blob_stream, 0),
363
+ WEBIDL_OPERATION("textStream", blob_text_stream, 0),
351
364
  };
352
365
 
353
366
  static const JSBuiltin file_proto[] = {
@@ -1,4 +1,4 @@
1
- // What BoringSSL (ADR 0019) needs from a C++ library that programs don't link: BoringSSL is
1
+ // What BoringSSL needs from a C++ library that programs don't link: BoringSSL is
2
2
  // built without exceptions, RTTI or the C++ library, and allocates with OPENSSL_malloc, but its
3
3
  // classes' virtual destructors name operator delete (never called), libstdc++'s headers name its
4
4
  // throw helpers, and libc++ (Zig's) keeps a std::sort instantiation and its assertion handler in