visaljs 0.0.7 → 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 +4413 -324
  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 -1
  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,5 +1,5 @@
1
1
  /*
2
- * js_generator.h — generators (ECMAScript §27.5; ADR 0007).
2
+ * js_generator.h — generators (ECMAScript §27.5).
3
3
  *
4
4
  * The compiler turns a function* into an entry (its prologue, which ends by creating the
5
5
  * generator with js_generator_new) and a resume function: a state machine that saves the
@@ -56,7 +56,7 @@ JSValue js_yield_star_start(JSContext *ctx, JSValue iterable);
56
56
  JSValue js_yield_star_step(JSContext *ctx, JSValue rec, JSValue received, JSValue mode);
57
57
  JSValue js_yield_star_status(JSValue rec);
58
58
 
59
- /* ---- Async functions (§27.7; ADR 0007) ------------------------------------------------- */
59
+ /* ---- Async functions (§27.7) ----------------------------------------------------------- */
60
60
 
61
61
  /* An async call's state: a generator-like object nothing in JS can reach. */
62
62
  JSValue js_async_new(JSContext *ctx, JSGeneratorResume resume, uint32_t slots);
@@ -1,10 +1,15 @@
1
- /* js_host.h — the host's layer 1 in the runtime (ADR 0012): console, process and global,
1
+ /* js_host.h — the host's globals in the runtime: console, process and global,
2
2
  * installed before the program runs, and what host packages (node/) build on. Host packages
3
3
  * declare their own primitives (node/include/js_node.h); the generated code declares the ones
4
4
  * it uses. */
5
5
  #ifndef JS_HOST_H
6
6
  #define JS_HOST_H
7
7
 
8
+ /* The Node API visaljs implements, as process.version reports it (node/compat.json's), and
9
+ * visaljs's own version, process.versions.visaljs (cli/package.json's). cli/test checks both. */
10
+ #define JS_NODE_VERSION "24.21.0"
11
+ #define JS_VISALJS_VERSION "0.0.7"
12
+
8
13
  #include "js_function.h"
9
14
 
10
15
  /* process.c: console, process and global, installed before the program runs (main); the end
@@ -18,4 +23,17 @@ void js_emit_warning(JSContext *ctx, JSValue message, const char *type, const ch
18
23
  /* cwd(): the working directory (process.cwd()), also a host primitive of node:path; -errno on failure. */
19
24
  JSValue js_host_cwd(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
20
25
 
26
+ /* buffer.c: node:buffer's INSPECT_MAX_BYTES, as it is set. */
27
+ JSValue js_host_buffer_inspect_max_bytes(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
28
+
29
+ /* web.c: an object's internal class, for structuredClone. */
30
+ JSValue js_host_clone_class(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
31
+
32
+ /* fetch.c: fetch()'s primitives (node/prelude/internal/fetch.js): a Headers' list as sent, a
33
+ * request's body as sent, and a fetched Response. */
34
+ JSValue js_host_fetch_header_list(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
35
+ JSValue js_host_fetch_request_body(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
36
+ JSValue js_host_fetch_response(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
37
+ JSValue js_host_fetch_form_data_hooks(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
38
+
21
39
  #endif /* JS_HOST_H */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_jobs.h — the job queue and the event loop (ADR 0008).
2
+ * js_jobs.h — the job queue and the event loop.
3
3
  *
4
4
  * Layer 1 (spec): microtasks, run at checkpoints when no JS is on the stack, then the
5
5
  * unhandled rejections are processed. Layer 2 (host): the event loop that runs the
@@ -25,7 +25,7 @@ typedef struct JSJob {
25
25
  uint8_t kind;
26
26
  JSContext *realm; /* set by js_enqueue_microtask: the realm that queued it */
27
27
  JSValue a, b, c;
28
- JSValue context; /* set by js_enqueue_microtask: the async context it runs under (ADR 0020) */
28
+ JSValue context; /* set by js_enqueue_microtask: the async context it runs under */
29
29
  } JSJob;
30
30
 
31
31
  typedef struct JSJobQueue {
@@ -33,7 +33,7 @@ typedef struct JSJobQueue {
33
33
  size_t head, count, cap;
34
34
  } JSJobQueue;
35
35
 
36
- /* A setTimeout / setInterval (ADR 0008). Its values are GC roots. */
36
+ /* A setTimeout / setInterval. Its values are GC roots. */
37
37
  typedef struct JSTimer {
38
38
  uint64_t deadline; /* in the loop's milliseconds */
39
39
  uint64_t seq; /* creation order: breaks ties */
@@ -43,7 +43,7 @@ typedef struct JSTimer {
43
43
  JSContext *realm;
44
44
  JSValue fn;
45
45
  JSValue args; /* an array of the extra arguments, or undefined */
46
- JSValue context; /* the async context it was set in, which it runs under (ADR 0020) */
46
+ JSValue context; /* the async context it was set in, which it runs under */
47
47
  } JSTimer;
48
48
 
49
49
  typedef struct JSTimers {
@@ -86,7 +86,7 @@ uint32_t js_timer_start(JSContext *ctx, JSValue fn, double delay, bool immediate
86
86
  void js_timer_set_ref(JSContext *ctx, uint32_t id, bool ref);
87
87
  void js_timer_clear(JSContext *ctx, uint32_t id);
88
88
 
89
- /* The async context (ADR 0020): the host's value for the current chain of async work, which
89
+ /* The async context: the host's value for the current chain of async work, which
90
90
  * jobs, timers and promise reactions carry to where they run (undefined: none). Setting it
91
91
  * isn't undone by the runtime: the caller restores the one it replaced. */
92
92
  JSValue js_async_context(JSContext *ctx);
@@ -1,4 +1,4 @@
1
- /* js_module.h — module-level host behavior (ADR 0009): import.meta and import(). */
1
+ /* js_module.h — module-level host behavior: import.meta and import(). */
2
2
  #ifndef JS_MODULE_H
3
3
  #define JS_MODULE_H
4
4
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_object.h — the object model (ADR 0005): shapes, objects, property keys,
2
+ * js_object.h — the object model: shapes, objects, property keys,
3
3
  * and the ordinary internal methods ([[Get]], [[Set]], [[DefineOwnProperty]], …).
4
4
  *
5
5
  * Named properties (atoms, symbols) live in shape-described slots; indexed
@@ -54,7 +54,7 @@ typedef struct JSTransitions JSTransitions;
54
54
  /* JS_ORDINARY, but the answer for this key isn't a function of the shape: caches don't remember it. */
55
55
  #define JS_ORDINARY_UNCACHED 3
56
56
 
57
- /* Exotic behavior (ADR 0005, "class hooks"). NULL hooks mean ordinary behavior.
57
+ /* Exotic behavior. NULL hooks mean ordinary behavior.
58
58
  * Grows as exotic objects arrive (Function, arguments, Proxy…). Inline caches rely on
59
59
  * this: whether a hook takes over a named key depends only on the object's shape, or
60
60
  * the hook changes the shape (Function's lazy `prototype`). */
@@ -110,6 +110,9 @@ struct JSShape { /* kind = SHAPE */
110
110
  uint16_t pad_;
111
111
  JSPropTable *table; /* key → (slot, attrs): lazy for shared shapes, the truth for dictionaries */
112
112
  JSTransitions *transitions; /* (key, attrs) → child shape; weak */
113
+ /* for…in's keys of objects with this shape (shared shapes only): its enumerable string keys
114
+ * in order, a JSValueArray; EMPTY until a for…in first needs them (iterate.c) */
115
+ JSValue enum_keys;
113
116
  };
114
117
 
115
118
  /* The slot of an accessor property holds one of these. */
@@ -157,7 +160,7 @@ static inline bool js_is_object(JSValue v) {
157
160
  static inline JSObject *js_as_object(JSValue v) { return (JSObject *)js_as_cell(v); }
158
161
  static inline JSValue js_object_value(JSObject *o) { return js_cell(&o->cell); }
159
162
 
160
- /* The shared, static, empty elements store (ADR 0005, "never NULL"). */
163
+ /* The shared, static, empty elements store. */
161
164
  extern const JSElements js_empty_elements;
162
165
 
163
166
  /* ---- Shapes ----------------------------------------------------------------- */
@@ -192,7 +195,7 @@ static inline JSValue *js_object_slot(JSObject *o, uint32_t n) {
192
195
  /* ---- Property keys --------------------------------------------------------------- */
193
196
 
194
197
  /* A key: an array index (a number: int32 below 2^31, a double up to 2^32 - 2), an atom,
195
- * or a symbol (ADR 0005). JS_EXCEPTION on failure. */
198
+ * or a symbol. JS_EXCEPTION on failure. */
196
199
  JS_WARN_UNUSED JSValue js_to_property_key(JSContext *ctx, JSValue v);
197
200
  static inline bool js_key_is_index(JSValue key) { return js_is_number(key); }
198
201
  static inline uint32_t js_key_index(JSValue key) {
@@ -226,7 +229,7 @@ void js_define_accessor(JSContext *ctx, JSObject *o, JSValue key, JSValue get, J
226
229
 
227
230
  /* ---- Internal methods (ordinary objects; exotic hooks arrive with their classes) ---- */
228
231
 
229
- /* Results: 1 true, 0 false, -1 exception (ADR 0004). */
232
+ /* Results: 1 true, 0 false, -1 exception. */
230
233
  JS_WARN_UNUSED int js_get_own_property(JSContext *ctx, JSObject *o, JSValue key, JSPropertyDescriptor *out);
231
234
  JS_WARN_UNUSED int js_define_own_property(JSContext *ctx, JSObject *o, JSValue key, const JSPropertyDescriptor *desc, bool throw_on_fail);
232
235
  JS_WARN_UNUSED int js_has_property(JSContext *ctx, JSObject *o, JSValue key);
@@ -288,7 +291,7 @@ JSValue js_for_in_next(JSContext *ctx, JSValue it);
288
291
  /* The own keys in spec order (indices ascending, then strings, then symbols, by insertion). */
289
292
  JS_WARN_UNUSED JSValue js_own_keys(JSContext *ctx, JSObject *o);
290
293
 
291
- /* ---- Inline caches (ADR 0005) ---------------------------------------------------- */
294
+ /* ---- Inline caches --------------------------------------------------------------- */
292
295
 
293
296
  #define JS_IC_EMPTY 0
294
297
  #define JS_IC_OWN 1 /* get: an own data property; set: an own writable data property */
@@ -301,16 +304,23 @@ JS_WARN_UNUSED JSValue js_own_keys(JSContext *ctx, JSObject *o);
301
304
  /* One per property access site with a constant named key; a site is either a get or a
302
305
  * set. Monomorphic: a miss refills it. Never caches dictionary shapes (their layout
303
306
  * changes under the same pointer). Weak: the GC resets a cache whose shapes or holder
304
- * die, so every cache must be registered (js_register_prop_caches). */
307
+ * die, so every cache must be registered (js_register_prop_caches).
308
+ *
309
+ * `fast` is what the inline paths (js_get_prop, js_set_prop) test: the receiver shape of
310
+ * an OWN cache whose slot is inline, else NULL. A hit is then one compare and one load at
311
+ * `fast_off`, inlined at every access site; the other kinds, and OWN in an overflow slot,
312
+ * hit in the out-of-line slow path. */
305
313
  typedef struct JSPropCache {
306
- JSShape *shape; /* receiver shape; NULL = empty */
307
- uint32_t slot; /* OWN, PROTO: the slot */
314
+ JSShape *fast; /* OWN, inline slot: the receiver shape; else NULL */
315
+ uint16_t fast_off; /* with `fast`: the slot's byte offset in the object */
308
316
  uint8_t kind; /* JS_IC_* */
309
317
  uint8_t depth; /* PROTO: hops to the holder; ADD: prototypes up to null */
310
- uint16_t pad_;
318
+ uint32_t slot; /* OWN, PROTO: the slot */
319
+ JSShape *shape; /* receiver shape; NULL = empty */
311
320
  JSObject *holder; /* PROTO */
312
321
  JSShape *next; /* ADD */
313
322
  JSShape *chain[JS_IC_MAX_DEPTH]; /* PROTO, ADD: the prototypes' shapes, checked on a hit */
323
+ uint32_t epoch; /* PROTO, ADD: the runtime's proto_epoch when `chain` was last seen to hold */
314
324
  } JSPropCache;
315
325
 
316
326
  /* A module's caches, once at startup (the GC resets them weakly). */
@@ -319,21 +329,84 @@ void js_register_prop_caches(JSRuntime *rt, JSPropCache *ics, size_t n);
319
329
  JS_WARN_UNUSED JSValue js_get_prop_slow(JSContext *ctx, JSValue obj, JSValue key, JSPropCache *ic);
320
330
  JS_WARN_UNUSED int js_set_prop_slow(JSContext *ctx, JSValue obj, JSValue key, JSValue v, bool strict, JSPropCache *ic);
321
331
 
322
- /* obj.key with a named key (an atom). A hit is a type check, a shape compare and a load. */
332
+ /* The slot a fast hit reads or writes. */
333
+ static inline JSValue *js_prop_cache_slot(JSObject *o, const JSPropCache *ic) {
334
+ return (JSValue *)((char *)o + ic->fast_off);
335
+ }
336
+
337
+ /* obj.key with a named key (an atom). A hit is a type check, a shape compare and a load:
338
+ * inlined at every site, so it stays this small (the rest is js_get_prop_slow's). */
323
339
  static inline JSValue js_get_prop(JSContext *ctx, JSValue obj, JSValue key, JSPropCache *ic) {
340
+ if (JS_LIKELY(js_is_object(obj)) && js_as_object(obj)->shape == ic->fast) return *js_prop_cache_slot(js_as_object(obj), ic);
341
+ return js_get_prop_slow(ctx, obj, key, ic);
342
+ }
343
+
344
+ /* obj.key where the value is called (a method, optimizer step 11): js_get_prop, and a hit on
345
+ * the prototype that holds it inline too, while no prototype has changed shape since the cache
346
+ * saw the chain (proto_epoch). */
347
+ static JS_FAST_PATH JSValue js_get_method(JSContext *ctx, JSValue obj, JSValue key, JSPropCache *ic) {
324
348
  if (JS_LIKELY(js_is_object(obj))) {
325
349
  JSObject *o = js_as_object(obj);
326
- if (o->shape == ic->shape && ic->kind == JS_IC_OWN) return *js_object_slot(o, ic->slot);
350
+ if (o->shape == ic->fast) return *js_prop_cache_slot(o, ic);
351
+ if (JS_LIKELY(o->shape == ic->shape && ic->kind == JS_IC_PROTO && ic->epoch == ctx->rt->proto_epoch))
352
+ return *js_object_slot(ic->holder, ic->slot);
327
353
  }
328
354
  return js_get_prop_slow(ctx, obj, key, ic);
329
355
  }
330
356
 
357
+ /* s.key where the compiler proved s a string and key is neither `length` nor an index: a
358
+ * property of String.prototype (a string has no other own properties), which `ic` caches with
359
+ * String.prototype as the receiver. A hit is that object's shape compare and a load. */
360
+ static inline JSValue js_get_string_prop(JSContext *ctx, JSValue s, JSValue key, JSPropCache *ic) {
361
+ JSObject *p = js_as_object(ctx->intrinsics[JS_INTRINSIC_STRING_PROTOTYPE]);
362
+ if (JS_LIKELY(p->shape == ic->shape) && ic->kind == JS_IC_OWN) return *js_object_slot(p, ic->slot);
363
+ return js_get_prop_slow(ctx, s, key, ic);
364
+ }
365
+
331
366
  /* obj.key = v with a named key: 1 done, 0 failed (sloppy), -1 exception. */
332
367
  static inline int js_set_prop(JSContext *ctx, JSValue obj, JSValue key, JSValue v, bool strict, JSPropCache *ic) {
368
+ if (JS_LIKELY(js_is_object(obj)) && js_as_object(obj)->shape == ic->fast) {
369
+ JSObject *o = js_as_object(obj);
370
+ js_store(ctx, &o->cell, js_prop_cache_slot(o, ic), v);
371
+ return 1;
372
+ }
373
+ return js_set_prop_slow(ctx, obj, key, v, strict, ic);
374
+ }
375
+
376
+ /* An object's new shape. When the object is a prototype, caches that checked the chain it's on
377
+ * may be stale: the runtime's proto_epoch moves on. */
378
+ static JS_FAST_PATH void js_object_set_shape(JSContext *ctx, JSObject *o, JSShape *s) {
379
+ js_store_ptr(ctx, &o->cell, &o->shape, s);
380
+ if (JS_UNLIKELY(o->cell.flags & JS_CELL_PROTOTYPE)) ctx->rt->proto_epoch++;
381
+ }
382
+
383
+ /* Whether the prototypes an ADD or PROTO cache saw still have the shapes it saw: then nothing on
384
+ * the chain gained a setter, a read-only property or the key. */
385
+ static inline bool js_prop_cache_chain_holds(const JSPropCache *ic) {
386
+ JSValue p = ic->shape->proto;
387
+ for (unsigned d = 0; d < ic->depth; d++) {
388
+ if (!js_is_object(p)) return false;
389
+ JSShape *s = js_as_object(p)->shape;
390
+ if (s != ic->chain[d]) return false;
391
+ p = s->proto;
392
+ }
393
+ return true;
394
+ }
395
+
396
+ /* obj.key = v where the compiler expects the key to be added (`this.key = v` in a constructor,
397
+ * optimizer step 10): js_set_prop, and a cached addition inline too, when the object has room
398
+ * for it. Its new shape and the value are stores into an object the program just made. */
399
+ static JS_FAST_PATH int js_set_prop_add(JSContext *ctx, JSValue obj, JSValue key, JSValue v, bool strict, JSPropCache *ic) {
333
400
  if (JS_LIKELY(js_is_object(obj))) {
334
401
  JSObject *o = js_as_object(obj);
335
- if (o->shape == ic->shape && ic->kind == JS_IC_OWN) {
336
- js_store(ctx, &o->cell, js_object_slot(o, ic->slot), v);
402
+ JSShape *s = o->shape;
403
+ if (JS_LIKELY(s == ic->shape && ic->kind == JS_IC_ADD && s->prop_count < s->inline_cap && ic->epoch == ctx->rt->proto_epoch)) {
404
+ js_object_set_shape(ctx, o, ic->next);
405
+ js_store(ctx, &o->cell, &js_object_slots(o)[s->prop_count], v);
406
+ return 1;
407
+ }
408
+ if (s == ic->fast) {
409
+ js_store(ctx, &o->cell, js_prop_cache_slot(o, ic), v);
337
410
  return 1;
338
411
  }
339
412
  }
@@ -343,11 +416,65 @@ static inline int js_set_prop(JSContext *ctx, JSValue obj, JSValue key, JSValue
343
416
  /* Convenience: the value of `obj.key` / `obj.key = v` for any value (ToObject rules). */
344
417
  JS_WARN_UNUSED JSValue js_get_value(JSContext *ctx, JSValue obj, JSValue key);
345
418
  JS_WARN_UNUSED int js_set_value(JSContext *ctx, JSValue obj, JSValue key, JSValue v, bool strict);
346
- /* ---- Generated code (ADR 0010): property operators on any value ---------------------- */
419
+ /* ---- Generated code: property operators on any value --------------------------------- */
347
420
 
348
421
  /* obj[key] and obj[key] = v with a computed key: ToPropertyKey after the nullish check. */
349
422
  JS_WARN_UNUSED JSValue js_get_elem(JSContext *ctx, JSValue obj, JSValue key);
350
423
  JS_WARN_UNUSED int js_set_elem(JSContext *ctx, JSValue obj, JSValue key, JSValue v, bool strict);
424
+ /* The same with a key the compiler proved a Number (get_index / set_index): a present element of
425
+ * a dense array is read or written inline. A dense element is always a writable data property
426
+ * (other attributes make the store sparse), so nothing else can see the access. */
427
+ static inline JSValue js_get_index(JSContext *ctx, JSValue obj, JSValue key) {
428
+ if (JS_LIKELY(js_is_array(obj) && js_is_int32(key))) {
429
+ JSElements *d = js_as_object(obj)->elements;
430
+ uint32_t i = (uint32_t)js_as_int32(key); /* negative: past any length */
431
+ if (JS_LIKELY(d->kind == JS_ELEMENTS_DENSE && i < d->length && !js_is_empty(d->data[i]))) return d->data[i];
432
+ }
433
+ return js_get_elem(ctx, obj, key);
434
+ }
435
+ static inline int js_set_index(JSContext *ctx, JSValue obj, JSValue key, JSValue v, bool strict) {
436
+ if (JS_LIKELY(js_is_array(obj) && js_is_int32(key))) {
437
+ JSElements *d = js_as_object(obj)->elements;
438
+ uint32_t i = (uint32_t)js_as_int32(key);
439
+ if (JS_LIKELY(d->kind == JS_ELEMENTS_DENSE && i < d->length && !js_is_empty(d->data[i]))) {
440
+ js_store(ctx, &d->cell, &d->data[i], v);
441
+ return 1;
442
+ }
443
+ }
444
+ return js_set_elem(ctx, obj, key, v, strict);
445
+ }
446
+ /* The same with an unboxed key (a C double): an integral one in range is the element's index. */
447
+ static inline bool js_f64_index(double key, uint32_t *i) {
448
+ if (!(key >= 0 && key < 4294967295.0)) return false; /* NaN too; the cast below is then defined */
449
+ *i = (uint32_t)key;
450
+ return (double)*i == key;
451
+ }
452
+ static inline JSValue js_get_index_f64(JSContext *ctx, JSValue obj, double key) {
453
+ uint32_t i;
454
+ if (JS_LIKELY(js_is_array(obj) && js_f64_index(key, &i))) {
455
+ JSElements *d = js_as_object(obj)->elements;
456
+ if (JS_LIKELY(d->kind == JS_ELEMENTS_DENSE && i < d->length && !js_is_empty(d->data[i]))) return d->data[i];
457
+ }
458
+ return js_get_elem(ctx, obj, js_number(key));
459
+ }
460
+ static inline int js_set_index_f64(JSContext *ctx, JSValue obj, double key, JSValue v, bool strict) {
461
+ uint32_t i;
462
+ if (JS_LIKELY(js_is_array(obj) && js_f64_index(key, &i))) {
463
+ JSElements *d = js_as_object(obj)->elements;
464
+ if (JS_LIKELY(d->kind == JS_ELEMENTS_DENSE && i < d->length && !js_is_empty(d->data[i]))) {
465
+ js_store(ctx, &d->cell, &d->data[i], v);
466
+ return 1;
467
+ }
468
+ }
469
+ return js_set_elem(ctx, obj, js_number(key), v, strict);
470
+ }
471
+ /* obj.length: an array's and a string's inline, anything else as js_get_prop (an array's length
472
+ * is always its own data property, a string's its own value). */
473
+ static inline JSValue js_get_length(JSContext *ctx, JSValue obj, JSValue key, JSPropCache *ic) {
474
+ if (JS_LIKELY(js_is_array(obj))) return js_number((double)js_array_length(js_as_object(obj)));
475
+ if (js_is_string(obj)) return js_int32((int32_t)js_string_length(obj)); /* below 2^30 */
476
+ return js_get_prop(ctx, obj, key, ic);
477
+ }
351
478
  /* delete obj[key]: true or false (sloppy), a TypeError when strict and not deletable.
352
479
  * `key` is a property key; js_delete_elem converts it first. */
353
480
  JS_WARN_UNUSED JSValue js_delete_value(JSContext *ctx, JSValue obj, JSValue key, bool strict);
@@ -1,9 +1,8 @@
1
1
  /*
2
- * js_ops.h — the JS operators generated code calls (ADR 0010: generic
3
- * operators on boxed JSValues; specialized unboxed ones come with M10).
2
+ * js_ops.h — the JS operators generated code calls (generic
3
+ * operators on boxed JSValues, and the optimizer's inline ones on proven Numbers).
4
4
  *
5
- * Primitives only for now: objects (ToPrimitive, valueOf) arrive in M3.
6
- * Every function that can fail returns JS_EXCEPTION with the error pending (ADR 0004).
5
+ * Every function that can fail returns JS_EXCEPTION with the error pending.
7
6
  */
8
7
  #ifndef JS_OPS_H
9
8
  #define JS_OPS_H
@@ -49,6 +48,11 @@ bool js_strict_equals(JSContext *ctx, JSValue a, JSValue b);
49
48
  static inline JSValue js_strict_eq(JSContext *ctx, JSValue a, JSValue b) { return js_bool(js_strict_equals(ctx, a, b)); }
50
49
  static inline JSValue js_strict_ne(JSContext *ctx, JSValue a, JSValue b) { return js_bool(!js_strict_equals(ctx, a, b)); }
51
50
 
51
+ /* A switch whose cases are all string literals: the index of the first case `v` is === to, or
52
+ * -1. `cases` are the literals' static strings (NULL: the empty string), atoms but for those of
53
+ * one unit: an atom `v` matches its case by address, after one call instead of one per case. */
54
+ int32_t js_switch_string(JSContext *ctx, JSValue v, const JSString *const *cases, uint32_t n);
55
+
52
56
  /* ---- Never throw -------------------------------------------------------- */
53
57
 
54
58
  /* ToBoolean, as a C bool: branches test this. */
@@ -86,7 +90,10 @@ static inline JSValue js_check_tdz(JSContext *ctx, JSValue v, const char *name)
86
90
 
87
91
  /* A name no declaration binds: the global object's property, or a ReferenceError (global.c). */
88
92
  JS_WARN_UNUSED JSValue js_global_name(JSContext *ctx, const char *name);
89
- /* A sloppy function's `this` (ADR 0006 prologue, §10.2.1.2): undefined and null become the
93
+ /* The same with the name's key (an atom) at hand: an own data property of the global object
94
+ * (Math, Array, console…) in one lookup, anything else as js_global_name. */
95
+ JS_WARN_UNUSED JSValue js_global_get(JSContext *ctx, JSValue key, const char *name);
96
+ /* A sloppy function's `this` (§10.2.1.2): undefined and null become the
90
97
  * global object, other primitives their wrapper (ToObject). */
91
98
  static inline JSValue js_sloppy_this(JSContext *ctx, JSValue v) {
92
99
  if (js_is_nullish(v)) return ctx->intrinsics[JS_INTRINSIC_GLOBAL_OBJECT];
@@ -108,4 +115,99 @@ JS_WARN_UNUSED JSValue js_throw_const_assign(JSContext *ctx);
108
115
  /* ToInt32 / ToUint32 of a number (ECMAScript §7.1.6). */
109
116
  int32_t js_double_to_int32(double d);
110
117
 
118
+ /* ---- Number operators (the optimizer's num_* ops) ------------------------------
119
+ * Both operands are proven Numbers (int32 or double JSValues), so these never throw, allocate
120
+ * or run user code: inline, with the int32 case first. Where the optimizer unboxes the values,
121
+ * the operators are plain C on doubles instead; these serve generator and async functions. */
122
+
123
+ static inline JSValue js_num_add(JSValue a, JSValue b) {
124
+ int32_t r;
125
+ if (js_is_int32(a) && js_is_int32(b) && !__builtin_add_overflow(js_as_int32(a), js_as_int32(b), &r)) return js_int32(r);
126
+ return js_number(js_as_number(a) + js_as_number(b));
127
+ }
128
+ static inline JSValue js_num_sub(JSValue a, JSValue b) {
129
+ int32_t r;
130
+ if (js_is_int32(a) && js_is_int32(b) && !__builtin_sub_overflow(js_as_int32(a), js_as_int32(b), &r)) return js_int32(r);
131
+ return js_number(js_as_number(a) - js_as_number(b));
132
+ }
133
+ static inline JSValue js_num_mul(JSValue a, JSValue b) {
134
+ int32_t r;
135
+ /* a zero product of a negative operand is -0: a double */
136
+ if (js_is_int32(a) && js_is_int32(b) && !__builtin_mul_overflow(js_as_int32(a), js_as_int32(b), &r) &&
137
+ (r != 0 || (js_as_int32(a) >= 0 && js_as_int32(b) >= 0))) return js_int32(r);
138
+ return js_number(js_as_number(a) * js_as_number(b));
139
+ }
140
+ static inline JSValue js_num_div(JSValue a, JSValue b) { return js_number(js_as_number(a) / js_as_number(b)); }
141
+ static inline JSValue js_num_mod(JSValue a, JSValue b) {
142
+ if (js_is_int32(a) && js_is_int32(b) && js_as_int32(a) >= 0 && js_as_int32(b) > 0) return js_int32(js_as_int32(a) % js_as_int32(b));
143
+ return js_number(fmod(js_as_number(a), js_as_number(b)));
144
+ }
145
+ static inline JSValue js_num_neg(JSValue v) {
146
+ if (js_is_int32(v) && js_as_int32(v) != 0 && js_as_int32(v) != INT32_MIN) return js_int32(-js_as_int32(v));
147
+ return js_number(-js_as_number(v));
148
+ }
149
+ static inline JSValue js_num_inc(JSValue v) { return js_num_add(v, js_int32(1)); }
150
+ static inline JSValue js_num_dec(JSValue v) { return js_num_sub(v, js_int32(1)); }
151
+
152
+ static inline JSValue js_num_lt(JSValue a, JSValue b) { return js_bool(js_as_number(a) < js_as_number(b)); }
153
+ static inline JSValue js_num_le(JSValue a, JSValue b) { return js_bool(js_as_number(a) <= js_as_number(b)); }
154
+ static inline JSValue js_num_gt(JSValue a, JSValue b) { return js_bool(js_as_number(a) > js_as_number(b)); }
155
+ static inline JSValue js_num_ge(JSValue a, JSValue b) { return js_bool(js_as_number(a) >= js_as_number(b)); }
156
+ static inline JSValue js_num_eq(JSValue a, JSValue b) { return js_bool(js_as_number(a) == js_as_number(b)); }
157
+ static inline JSValue js_num_ne(JSValue a, JSValue b) { return js_bool(js_as_number(a) != js_as_number(b)); }
158
+
159
+ /* ToInt32 of a double: below 2^63 in magnitude, truncating to int64 and keeping the low 32 bits
160
+ * is exactly ToInt32 (a hash's `(h * 31 + c) | 0` lands there), else the general one (NaN and
161
+ * the infinities fail the comparisons). */
162
+ static inline int32_t js_f64_to_int32(double d) {
163
+ if (d > -9223372036854775808.0 && d < 9223372036854775808.0) return (int32_t)(uint32_t)(int64_t)d;
164
+ return js_double_to_int32(d);
165
+ }
166
+ /* A Number the compiler proved an int32, from its boxed form: an int32 holding one
167
+ * may still be a double (runtime code making 3.0 with js_double). */
168
+ static inline int32_t js_as_int32_value(JSValue v) {
169
+ return js_is_int32(v) ? js_as_int32(v) : (int32_t)js_as_double(v);
170
+ }
171
+ /* a % b on doubles: integer % when both are integers in int32 range and the dividend isn't
172
+ * negative (a negative one can give -0), else fmod (a libm call, much slower) */
173
+ static inline double js_f64_mod(double a, double b) {
174
+ if (a <= 2147483647.0 && !signbit(a) && b >= 1.0 && b <= 2147483647.0) {
175
+ int32_t x = (int32_t)a, y = (int32_t)b;
176
+ if ((double)x == a && (double)y == b) return (double)(x % y);
177
+ }
178
+ return fmod(a, b);
179
+ }
180
+ /* ToInt32 of a Number */
181
+ static inline int32_t js_num_int32(JSValue v) { return js_is_int32(v) ? js_as_int32(v) : js_f64_to_int32(js_as_double(v)); }
182
+ static inline JSValue js_num_bitand(JSValue a, JSValue b) { return js_int32(js_num_int32(a) & js_num_int32(b)); }
183
+ static inline JSValue js_num_bitor(JSValue a, JSValue b) { return js_int32(js_num_int32(a) | js_num_int32(b)); }
184
+ static inline JSValue js_num_bitxor(JSValue a, JSValue b) { return js_int32(js_num_int32(a) ^ js_num_int32(b)); }
185
+ static inline JSValue js_num_bitnot(JSValue v) { return js_int32(~js_num_int32(v)); }
186
+ static inline JSValue js_num_shl(JSValue a, JSValue b) { return js_int32((int32_t)((uint32_t)js_num_int32(a) << (js_num_int32(b) & 31))); }
187
+ static inline JSValue js_num_sar(JSValue a, JSValue b) { return js_int32(js_num_int32(a) >> (js_num_int32(b) & 31)); }
188
+ static inline JSValue js_num_shr(JSValue a, JSValue b) { return js_number((double)((uint32_t)js_num_int32(a) >> (js_num_int32(b) & 31))); }
189
+
190
+ /* Operators on values the compiler couldn't type, in loops: the Number path
191
+ * inline when both operands are Numbers, else the generic operator. */
192
+ #define JS_NUMBER_FIRST2(op) \
193
+ static inline JSValue js_##op##_fast(JSContext *ctx, JSValue a, JSValue b) { \
194
+ if (JS_LIKELY(js_is_number(a) && js_is_number(b))) return js_num_##op(a, b); \
195
+ return js_##op(ctx, a, b); \
196
+ }
197
+ #define JS_NUMBER_FIRST1(op) \
198
+ static inline JSValue js_##op##_fast(JSContext *ctx, JSValue a) { \
199
+ if (JS_LIKELY(js_is_number(a))) return js_num_##op(a); \
200
+ return js_##op(ctx, a); \
201
+ }
202
+ JS_NUMBER_FIRST2(add) JS_NUMBER_FIRST2(sub) JS_NUMBER_FIRST2(mul) JS_NUMBER_FIRST2(div) JS_NUMBER_FIRST2(mod)
203
+ JS_NUMBER_FIRST2(lt) JS_NUMBER_FIRST2(le) JS_NUMBER_FIRST2(gt) JS_NUMBER_FIRST2(ge) JS_NUMBER_FIRST2(eq) JS_NUMBER_FIRST2(ne)
204
+ JS_NUMBER_FIRST2(bitand) JS_NUMBER_FIRST2(bitor) JS_NUMBER_FIRST2(bitxor) JS_NUMBER_FIRST2(shl) JS_NUMBER_FIRST2(sar)
205
+ JS_NUMBER_FIRST2(shr)
206
+ JS_NUMBER_FIRST1(neg) JS_NUMBER_FIRST1(inc) JS_NUMBER_FIRST1(dec) JS_NUMBER_FIRST1(bitnot)
207
+ static inline JSValue js_to_numeric_fast(JSContext *ctx, JSValue v) {
208
+ return JS_LIKELY(js_is_number(v)) ? v : js_to_numeric(ctx, v);
209
+ }
210
+ #undef JS_NUMBER_FIRST1
211
+ #undef JS_NUMBER_FIRST2
212
+
111
213
  #endif /* JS_OPS_H */
@@ -1,8 +1,8 @@
1
1
  /*
2
- * js_promise.h — promises (ECMAScript §27.2; ADR 0008).
2
+ * js_promise.h — promises (ECMAScript §27.2).
3
3
  *
4
4
  * A promise keeps its reactions in a list until it settles; settling queues one
5
- * microtask per reaction (js_jobs.h). Async functions (ADR 0007) build on these.
5
+ * microtask per reaction (js_jobs.h). Async functions build on these.
6
6
  */
7
7
  #ifndef JS_PROMISE_H
8
8
  #define JS_PROMISE_H
@@ -32,7 +32,7 @@ void js_promise_reject_internal(JSContext *ctx, JSValue promise, JSValue reason)
32
32
  /* PromiseResolve(%Promise%, v) (§27.2.4.7.1): v if it is a native promise of this realm. */
33
33
  JS_WARN_UNUSED JSValue js_promise_resolve(JSContext *ctx, JSValue v);
34
34
 
35
- /* await (ADR 0007): when the promise settles, a job resumes the async state `gen` (a
35
+ /* await: when the promise settles, a job resumes the async state `gen` (a
36
36
  * reaction with no derived promise and no JS closure); marks the promise handled. */
37
37
  void js_promise_await(JSContext *ctx, JSValue promise, JSValue gen);
38
38
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_regexp.h — regular expression literals (ADR 0015), for generated code.
2
+ * js_regexp.h — regular expression literals, for generated code.
3
3
  *
4
4
  * The compiler compiles each literal when the program is built (QuickJS's libregexp, run as the
5
5
  * regexp-compile tool) and emits its bytecode as static data; evaluating the literal creates a
File without changes
@@ -1,5 +1,5 @@
1
1
  /*
2
- * js_symbol.h — symbols (ECMAScript §6.1.5, §20.4; ADR 0001, 0005).
2
+ * js_symbol.h — symbols (ECMAScript §6.1.5, §20.4).
3
3
  *
4
4
  * A symbol is a heap cell compared by identity; as a property key it is used as is. The
5
5
  * well-known symbols are static cells, like the predefined atoms: JS_SYMBOL(iterator).
@@ -1,4 +1,4 @@
1
- /* js_web.h — the web-standard host layer (ADR 0012, layer 2): what its components share.
1
+ /* js_web.h — the web-standard host layer: what its components share.
2
2
  * DOMException is a component of its own (domexception.c); the components that throw one
3
3
  * need it. The Node-style errors are web.c's, linked into the programs that throw them. */
4
4
  #ifndef JS_WEB_H
@@ -80,6 +80,7 @@ typedef struct JSStreamSource {
80
80
  JS_WARN_UNUSED JSValue js_new_readable_stream(JSContext *ctx, const JSStreamSource *source, JSValue data, double high_water_mark);
81
81
  /* A byte stream of one chunk (a Uint8Array), or of none (undefined), closed after it. */
82
82
  JS_WARN_UNUSED JSValue js_readable_stream_of_bytes(JSContext *ctx, JSValue chunk);
83
+ JS_WARN_UNUSED JSValue js_readable_stream_of_chunk(JSContext *ctx, JSValue chunk); /* not a byte stream */
83
84
  bool js_is_readable_stream(JSValue v);
84
85
  bool js_readable_stream_locked(JSValue v);
85
86
  bool js_readable_stream_disturbed(JSValue v);
@@ -1,41 +1,48 @@
1
1
  /*
2
- * jscell.h — the header word every heap cell starts with (ADR 0001, 0002).
2
+ * jscell.h — the header word every heap cell starts with.
3
3
  */
4
4
  #ifndef JSCELL_H
5
5
  #define JSCELL_H
6
6
 
7
7
  #include <stdint.h>
8
8
 
9
- /* Cell kinds. Each has a JSCellClass (visit, finalize) in the GC.
10
- * Kinds are added as their ADRs are implemented. */
9
+ /* Cell kinds. Each has a JSCellClass (visit, finalize) in the GC. */
11
10
  typedef enum JSCellKind {
12
11
  JS_CELL_INVALID = 0, /* never a live cell */
13
- JS_CELL_STR_FLAT, /* JSString: inline Latin-1 or UTF-16 characters (ADR 0003) */
14
- JS_CELL_STR_ROPE, /* JSRope: lazy concatenation (ADR 0003) */
15
- JS_CELL_STR_SLICE, /* JSSlice: a substring sharing its parent's characters (ADR 0003) */
12
+ JS_CELL_STR_FLAT, /* JSString: inline Latin-1 or UTF-16 characters */
13
+ JS_CELL_STR_ROPE, /* JSRope: lazy concatenation */
14
+ JS_CELL_STR_SLICE, /* JSSlice: a substring sharing its parent's characters */
16
15
  JS_CELL_VALUE_ARRAY, /* internal: fixed-length JSValue array (overflow slots, …) */
17
- JS_CELL_HOST, /* internal: native payload with its own class (ADR 0012) */
18
- JS_CELL_SHAPE, /* JSShape: hidden class (ADR 0005) */
16
+ JS_CELL_HOST, /* internal: native payload with its own class */
17
+ JS_CELL_SHAPE, /* JSShape: hidden class */
19
18
  JS_CELL_ACCESSOR, /* JSAccessorPair: {get, set} in an accessor property's slot */
20
19
  JS_CELL_ELEMENTS, /* JSElements: indexed properties */
21
- JS_CELL_ENV, /* JSEnv: a scope's captured variables (ADR 0006) */
22
- JS_CELL_SYMBOL, /* JSSymbol: a symbol primitive (ADR 0001) */
23
- JS_CELL_BIGINT, /* JSBigInt: a BigInt primitive (ADR 0016) */
20
+ JS_CELL_ENV, /* JSEnv: a scope's captured variables */
21
+ JS_CELL_SYMBOL, /* JSSymbol: a symbol primitive */
22
+ JS_CELL_BIGINT, /* JSBigInt: a BigInt primitive */
24
23
  /* Objects: every kind from here on starts with a JSObject (js_is_object). */
25
24
  JS_CELL_OBJECT, /* ordinary objects, and exotic ones whose class is in the shape */
26
25
  JS_CELL_ARRAY, /* JSArray */
27
- JS_CELL_FUNCTION, /* JSFunction (ADR 0006) */
26
+ JS_CELL_FUNCTION, /* JSFunction */
28
27
  JS_CELL_KIND_COUNT
29
28
  } JSCellKind;
30
29
 
31
- /* Cell flags. The low byte is kind-specific (e.g. STR_LATIN1, ADR 0003). */
30
+ /* Cell flags. The low byte is kind-specific (e.g. STR_LATIN1; an array's frozen length). */
32
31
  #define JS_CELL_STATIC 0x8000u /* emitted by the compiler: never marked or swept */
33
32
  #define JS_CELL_FINALIZABLE 0x4000u /* the class finalizer must run when it dies */
33
+ #define JS_CELL_PROTOTYPE 0x2000u /* an object some shape has as its prototype: its shape changes bump proto_epoch */
34
34
 
35
- /* 8 bytes, so the fields after it start 8-aligned and a 16-byte header fits two more words. */
35
+ /* 8 bytes, so the fields after it start 8-aligned and a 16-byte header fits two more words.
36
+ * `gc` belongs to the collector: the write barrier reads it, and
37
+ * nothing outside the GC writes it. A byte of its own, so a collector thread can write it while
38
+ * the program writes `flags`. 0 in a new cell and in a static one. */
39
+ #define JS_GC_YOUNG 0 /* allocated since the last collection (or static) */
40
+ #define JS_GC_REMEMBERED 1 /* old, and in the remembered set: stores into it need nothing more */
41
+ #define JS_GC_OLD 2 /* survived a collection: a store of a young cell into it is remembered */
42
+ #define JS_GC_OLD_LARGE 3 /* old and a large object: a store of a young cell marks a card of it */
36
43
  typedef struct JSCell {
37
44
  uint8_t kind; /* JSCellKind */
38
- uint8_t reserved;
45
+ uint8_t gc;
39
46
  uint16_t flags;
40
47
  uint32_t aux; /* kind-specific */
41
48
  } JSCell;