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
@@ -0,0 +1,87 @@
1
+ /* How the marker visits the runtime's own cell kinds.
2
+ *
3
+ * Included by gc.c only, after it defines trace_value and trace_cell: the drain loop switches on
4
+ * the kind and inlines these, instead of an indirect call per cell. Host cells keep their class's
5
+ * visit. A visit only reads its cell and traces what it holds: no allocation, no writes.
6
+ * Flat strings and BigInts hold no cells: they're marked, never visited. */
7
+ #ifndef GC_VISIT_H
8
+ #define GC_VISIT_H
9
+
10
+ #include "elements.h"
11
+ #include "internal.h"
12
+ #include "js_function.h"
13
+ #include "js_object.h"
14
+ #include "js_symbol.h"
15
+ #include "jsstring.h"
16
+ #include "shape.h"
17
+
18
+ static inline void visit_object(JSCell *c, JSTracer *trc) {
19
+ JSObject *o = (JSObject *)c;
20
+ JSShape *s = o->shape;
21
+ #if defined(__clang__) || defined(__GNUC__)
22
+ if (o->ool) __builtin_prefetch(o->ool);
23
+ #endif
24
+ trace_cell(trc, &s->cell);
25
+ trace_cell(trc, &o->elements->cell);
26
+ JSValue *slots = js_object_slots(o);
27
+ for (uint16_t i = 0; i < s->inline_cap; i++) trace_value(trc, slots[i]);
28
+ if (o->ool) mark_ool(trc, o->ool);
29
+ if (s->cls->visit) s->cls->visit(c, trc); /* the object's class: a Map's table, a Promise's reactions */
30
+ }
31
+
32
+ static inline void visit_env(JSCell *c, JSTracer *trc) {
33
+ JSEnv *e = (JSEnv *)c;
34
+ if (e->parent) trace_cell(trc, &e->parent->cell);
35
+ for (uint32_t i = 0; i < c->aux; i++) trace_value(trc, e->vars[i]);
36
+ }
37
+
38
+ static inline void visit_value_array(JSCell *c, JSTracer *trc) {
39
+ JSValueArray *a = (JSValueArray *)c;
40
+ for (uint32_t i = 0; i < c->aux; i++) trace_value(trc, a->values[i]);
41
+ }
42
+
43
+ static inline void visit_elements(JSCell *c, JSTracer *trc) {
44
+ JSElements *e = (JSElements *)c;
45
+ if (e->kind == JS_ELEMENTS_SPARSE) {
46
+ JSSparseElements *s = (JSSparseElements *)e;
47
+ for (uint32_t k = 0; k < s->cap; k++)
48
+ if (s->entries[k].state == 1) trace_value(trc, s->entries[k].value);
49
+ return;
50
+ }
51
+ for (uint32_t i = 0; i < e->length; i++) trace_value(trc, e->data[i]);
52
+ }
53
+
54
+ static inline void visit_rope(JSCell *c, JSTracer *trc) {
55
+ JSRope *r = (JSRope *)c;
56
+ trace_value(trc, r->left);
57
+ trace_value(trc, r->right);
58
+ }
59
+
60
+ static inline void visit_slice(JSCell *c, JSTracer *trc) {
61
+ trace_value(trc, ((JSSlice *)c)->parent);
62
+ }
63
+
64
+ static inline void visit_shape(JSCell *c, JSTracer *trc) {
65
+ JSShape *s = (JSShape *)c;
66
+ trace_value(trc, s->proto);
67
+ trace_value(trc, s->key);
68
+ trace_value(trc, s->enum_keys);
69
+ if (s->parent) trace_cell(trc, &s->parent->cell);
70
+ /* a dictionary's keys exist only in its table; a shared table's keys are on the chain */
71
+ if (s->table && (s->flags & JS_SHAPE_DICTIONARY))
72
+ for (uint32_t i = 0; i < s->table->count; i++) trace_value(trc, s->table->entries[i].key);
73
+ /* transitions are weak: children aren't traced (js_shapes_sweep) */
74
+ }
75
+
76
+ static inline void visit_accessor(JSCell *c, JSTracer *trc) {
77
+ JSAccessorPair *p = (JSAccessorPair *)c;
78
+ trace_value(trc, p->get);
79
+ trace_value(trc, p->set);
80
+ }
81
+
82
+ static inline void visit_symbol(JSCell *c, JSTracer *trc) {
83
+ const JSCell *d = ((JSSymbol *)c)->description;
84
+ if (d) trace_cell(trc, (JSCell *)d);
85
+ }
86
+
87
+ #endif /* GC_VISIT_H */
@@ -1,4 +1,4 @@
1
- /* Generators (ECMAScript §27.3–27.5, §15.5.5; ADR 0007): the generator object, its driver
1
+ /* Generators (ECMAScript §27.3–27.5, §15.5.5): the generator object, its driver
2
2
  * (%GeneratorPrototype%.next / return / throw) and yield* delegation. */
3
3
  #include "js_generator.h"
4
4
 
@@ -95,7 +95,7 @@ static void yield_star_visit(JSCell *c, JSTracer *trc) {
95
95
  js_trace_value(trc, y->next);
96
96
  }
97
97
 
98
- static const JSCellClass yield_star_class = { "YieldStar", yield_star_visit, NULL };
98
+ static const JSCellClass yield_star_class = { "YieldStar", yield_star_visit, NULL, NULL };
99
99
 
100
100
  JSValue js_yield_star_start(JSContext *ctx, JSValue iterable) {
101
101
  JSValue method = js_is_nullish(iterable) ? JS_UNDEFINED : js_get_value(ctx, iterable, JS_SYMBOL(iterator));
@@ -155,7 +155,7 @@ JSValue js_yield_star_step(JSContext *ctx, JSValue rec, JSValue received, JSValu
155
155
  return js_throw_type_error(ctx, "The iterator does not provide a 'throw' method");
156
156
  }
157
157
 
158
- /* ---- Async functions (§27.7; ADR 0007) ------------------------------------------------- */
158
+ /* ---- Async functions (§27.7) ----------------------------------------------------------- */
159
159
 
160
160
  static const JSClass async_class = { "AsyncFunctionState", sizeof(JSGenerator), NULL, NULL, NULL, NULL, js_generator_visit, NULL, NULL };
161
161
 
@@ -208,6 +208,7 @@ static void install_generator(JSContext *ctx, JSObject *global) {
208
208
  JSObject *gp = js_as_object(in[JS_INTRINSIC_GENERATOR_PROTOTYPE]);
209
209
  js_define_data(ctx, gfp, JS_ATOM(prototype), in[JS_INTRINSIC_GENERATOR_PROTOTYPE], JS_PROP_CONFIGURABLE);
210
210
  js_define_data(ctx, gfp, JS_SYMBOL(toStringTag), js_atom_from_cstr(ctx, "GeneratorFunction"), JS_PROP_CONFIGURABLE);
211
+ js_define_function_kind_ctor(ctx, in[JS_INTRINSIC_GENERATOR_FUNCTION_PROTOTYPE], 0);
211
212
  js_define_data(ctx, gp, JS_ATOM(constructor), in[JS_INTRINSIC_GENERATOR_FUNCTION_PROTOTYPE], JS_PROP_CONFIGURABLE);
212
213
  (void)js_define_method(ctx, gp, "next", generator_next, 1);
213
214
  (void)js_define_method(ctx, gp, "return", generator_return, 1);
@@ -222,4 +223,5 @@ void js_async_function_realm_init(JSContext *ctx) {
222
223
  in[JS_INTRINSIC_ASYNC_FUNCTION_PROTOTYPE] = js_new_object_proto(ctx, in[JS_INTRINSIC_FUNCTION_PROTOTYPE], 4);
223
224
  js_define_data(ctx, js_as_object(in[JS_INTRINSIC_ASYNC_FUNCTION_PROTOTYPE]), JS_SYMBOL(toStringTag),
224
225
  js_atom_from_cstr(ctx, "AsyncFunction"), JS_PROP_CONFIGURABLE);
226
+ js_define_function_kind_ctor(ctx, in[JS_INTRINSIC_ASYNC_FUNCTION_PROTOTYPE], 1);
225
227
  }
@@ -1,4 +1,4 @@
1
- /* The global object and the primitives' prototypes (ECMAScript §19; ADR 0011, 0012). */
1
+ /* The global object and the primitives' prototypes (ECMAScript §19). */
2
2
  #include "internal.h"
3
3
  #include "js_atoms.h"
4
4
  #include "js_console.h"
@@ -41,11 +41,11 @@ void js_global_realm_init(JSContext *ctx) {
41
41
  js_builtins_realm_init(ctx, g);
42
42
  js_symbol_realm_init(ctx, g);
43
43
  js_iterator_realm_init(ctx);
44
- /* Promise, generators, async iteration and the weak collections are components (ADR 0014):
44
+ /* Promise, generators, async iteration and the weak collections are components:
45
45
  * a program gets them when its names or its syntax (async, function*, for await) reach them */
46
- js_jobs_realm_init(ctx, g); /* queueMicrotask (ADR 0008: the v1 host) */
47
- define_function(ctx, g, "print", js_print, 1); /* the test host's print (ADR 0011) */
48
- /* console comes from the host prelude, which every program runs first (ADR 0012) */
46
+ js_jobs_realm_init(ctx, g); /* queueMicrotask */
47
+ define_function(ctx, g, "print", js_print, 1); /* the test host's print */
48
+ /* console comes from the host prelude, which every program runs first */
49
49
  }
50
50
 
51
51
  /* ---- Global name lookup ------------------------------------------------------- */
@@ -61,9 +61,17 @@ static JSValue global_lookup(JSContext *ctx, const char *name, bool for_typeof)
61
61
  }
62
62
 
63
63
  JSValue js_global_name(JSContext *ctx, const char *name) { return global_lookup(ctx, name, false); }
64
+
65
+ JSValue js_global_get(JSContext *ctx, JSValue key, const char *name) {
66
+ JSPropertyDescriptor d;
67
+ int r = js_get_own_property(ctx, js_as_object(ctx->intrinsics[JS_INTRINSIC_GLOBAL_OBJECT]), key, &d);
68
+ if (r < 0) return JS_EXCEPTION;
69
+ if (r && (d.has & JS_DESC_VALUE)) return d.value;
70
+ return global_lookup(ctx, name, false); /* an accessor, the prototypes, or a ReferenceError */
71
+ }
64
72
  JSValue js_global_typeof_name(JSContext *ctx, const char *name) { return global_lookup(ctx, name, true); }
65
73
 
66
- /* ---- Script globals (§16.1.7 GlobalDeclarationInstantiation; ADR 0009 classic scripts) --- */
74
+ /* ---- Script globals (§16.1.7 GlobalDeclarationInstantiation) ----------------------------- */
67
75
 
68
76
  static JSObject *global_object(JSContext *ctx) { return js_as_object(ctx->intrinsics[JS_INTRINSIC_GLOBAL_OBJECT]); }
69
77
 
@@ -1,4 +1,4 @@
1
- /* Headers (Fetch §5.2), the headers component (ADR 0012, layer 2), as Node's (undici's): a list of
1
+ /* Headers (Fetch §5.2), the headers component, as Node's (undici's): a list of
2
2
  * (name, value) in the order added, names compared case-insensitively. Iteration is sorted by
3
3
  * lowercase name with the values of a name combined (", "), except Set-Cookie's, each its own
4
4
  * entry; inspection shows each name as first given (`Headers { 'Content-Type': 'text/plain' }`).
@@ -144,7 +144,7 @@ static bool is_name(JSContext *ctx, JSValue lower, const char *name) {
144
144
 
145
145
  static void invalidate(JSContext *ctx, HeadersObject *h) { js_store(ctx, &h->obj.cell, &h->sorted, JS_UNDEFINED); }
146
146
 
147
- static void list_push(HeadersObject *h, JSValue lower, JSValue name, JSValue value) {
147
+ static void list_push(JSContext *ctx, HeadersObject *h, JSValue lower, JSValue name, JSValue value) {
148
148
  if (h->n + 3 > h->cap) {
149
149
  uint32_t cap = h->cap ? h->cap * 2 : 24;
150
150
  JSValue *list = realloc(h->list, cap * sizeof *list);
@@ -152,9 +152,9 @@ static void list_push(HeadersObject *h, JSValue lower, JSValue name, JSValue val
152
152
  h->list = list;
153
153
  h->cap = cap;
154
154
  }
155
- h->list[h->n++] = lower;
156
- h->list[h->n++] = name;
157
- h->list[h->n++] = value;
155
+ js_store(ctx, &h->obj.cell, &h->list[h->n++], lower);
156
+ js_store(ctx, &h->obj.cell, &h->list[h->n++], name);
157
+ js_store(ctx, &h->obj.cell, &h->list[h->n++], value);
158
158
  }
159
159
 
160
160
  static int64_t find(JSContext *ctx, HeadersObject *h, JSValue lower, uint32_t from) {
@@ -207,10 +207,10 @@ static int append(JSContext *ctx, HeadersObject *h, const char *method, JSValue
207
207
  if (i >= 0) {
208
208
  JSValue combined = js_concat(ctx, js_concat(ctx, h->list[i + 2], js_new_string_cstr(ctx, ", ")), value);
209
209
  if (js_is_exception(combined)) return -1;
210
- h->list[i + 2] = combined;
210
+ js_store(ctx, &h->obj.cell, &h->list[i + 2], combined);
211
211
  return 0;
212
212
  }
213
- list_push(h, lower, name, value);
213
+ list_push(ctx, h, lower, name, value);
214
214
  return 0;
215
215
  }
216
216
 
@@ -218,7 +218,7 @@ static int append(JSContext *ctx, HeadersObject *h, const char *method, JSValue
218
218
  static int fill(JSContext *ctx, HeadersObject *h, JSValue init) {
219
219
  HeadersObject *src = as_headers(init);
220
220
  if (src) {
221
- for (uint32_t i = 0; i < src->n; i += 3) list_push(h, src->list[i], src->list[i + 1], src->list[i + 2]);
221
+ for (uint32_t i = 0; i < src->n; i += 3) list_push(ctx, h, src->list[i], src->list[i + 1], src->list[i + 2]);
222
222
  return 0;
223
223
  }
224
224
  if (!js_is_object(init))
@@ -386,10 +386,10 @@ BUILTIN(headers_set) {
386
386
  invalidate(ctx, h);
387
387
  int64_t i = find(ctx, h, lower, 0);
388
388
  if (i < 0) {
389
- list_push(h, lower, name, value);
389
+ list_push(ctx, h, lower, name, value);
390
390
  return JS_UNDEFINED;
391
391
  }
392
- h->list[i + 2] = value;
392
+ js_store(ctx, &h->obj.cell, &h->list[i + 2], value);
393
393
  uint32_t o = (uint32_t)i + 3;
394
394
  for (uint32_t k = (uint32_t)i + 3; k < h->n; k += 3) {
395
395
  if (js_string_equals(ctx, h->list[k], lower)) continue;
@@ -1,9 +1,11 @@
1
- /* util.inspect and util.format (ADR 0012), natively: Node's algorithms
1
+ /* util.inspect and util.format, natively: Node's algorithms
2
2
  * (lib/internal/util/inspect.js), so console output matches Node's byte for byte.
3
3
  *
4
4
  * Every string built here, and every object reached, is also pushed on `keep`, a JS array
5
- * the conservative stack scan sees (ADR 0002): user code (getters, toString, custom
6
- * inspectors) can run and collect, and the C lists below are not roots themselves. */
5
+ * the conservative stack scan sees: user code (getters, toString, custom
6
+ * inspectors) can run and collect, and the C lists below are not roots themselves.
7
+ *
8
+ * Ported from Node.js (Copyright Node.js contributors, MIT): runtime/third_party/nodejs/LICENSE. */
7
9
  #include "js_console.h"
8
10
 
9
11
  #include <math.h>
@@ -119,7 +121,7 @@ typedef struct {
119
121
  JSInspectOptions o;
120
122
  } Insp;
121
123
 
122
- const JSInspectOptions js_inspect_defaults = { false, 2, true, 100, 10000, 80, 3, false };
124
+ const JSInspectOptions js_inspect_defaults = { false, 2, true, 100, 10000, 80, 3, false, JS_INSPECT_GETTERS_OFF };
123
125
 
124
126
  static void insp_init(Insp *ip, JSContext *ctx, const JSInspectOptions *o) {
125
127
  *ip = (Insp){ ctx, JS_UNDEFINED, { 0 }, { 0 }, 0, 0, *o };
@@ -517,7 +519,39 @@ static JSValue format_property(Insp *ip, JSValue value, double recurse, JSValue
517
519
  ip->indentation -= diff;
518
520
  if (js_is_exception(str)) return str;
519
521
  } else if ((d.has & JS_DESC_GET) && !js_is_undefined(d.get)) {
520
- str = cstr(ip, (d.has & JS_DESC_SET) && !js_is_undefined(d.set) ? "[Getter/Setter]" : "[Getter]");
522
+ bool setter = (d.has & JS_DESC_SET) && !js_is_undefined(d.set);
523
+ const char *label = setter ? "Getter/Setter" : "Getter";
524
+ int g = ip->o.getters;
525
+ if (g == JS_INSPECT_GETTERS_ALL || (g == JS_INSPECT_GETTERS_GET && !setter) || (g == JS_INSPECT_GETTERS_SET && setter)) {
526
+ /* the getter's value, as Node shows it: [Getter: 5], [Getter: null], [Getter] { a: 1 } */
527
+ keep(ip, d.get);
528
+ JSValue got = js_call(ctx, d.get, value, 0, NULL);
529
+ Builder g2 = { 0 };
530
+ if (js_is_exception(got)) {
531
+ /* what it threw, inspected: <Inspection threw ([Error: nope])> */
532
+ JSValue err = keep(ip, js_take_exception(ctx));
533
+ ip->indentation += 2;
534
+ JSValue shown = format_value(ip, err, recurse);
535
+ ip->indentation -= 2;
536
+ if (js_is_exception(shown)) { free(g2.units); return shown; }
537
+ put_ascii(&g2, "["), put_ascii(&g2, label), put_ascii(&g2, ": <Inspection threw (");
538
+ put_str(&g2, ctx, shown);
539
+ put_ascii(&g2, ")>]");
540
+ } else {
541
+ keep(ip, got);
542
+ ip->indentation += 2;
543
+ JSValue shown = js_is_null(got) ? cstr(ip, "null") : is_object_like(got) ? format_value(ip, got, recurse) : format_primitive(ip, got);
544
+ ip->indentation -= 2;
545
+ if (js_is_exception(shown)) { free(g2.units); return shown; }
546
+ put_ascii(&g2, "["), put_ascii(&g2, label);
547
+ put_ascii(&g2, is_object_like(got) ? "] " : ": ");
548
+ put_str(&g2, ctx, shown);
549
+ if (!is_object_like(got)) put_ascii(&g2, "]");
550
+ }
551
+ str = done(ip, &g2);
552
+ } else {
553
+ str = cstr(ip, setter ? "[Getter/Setter]" : "[Getter]");
554
+ }
521
555
  } else if ((d.has & JS_DESC_SET) && !js_is_undefined(d.set)) {
522
556
  str = cstr(ip, "[Setter]");
523
557
  } else {
@@ -525,23 +559,21 @@ static JSValue format_property(Insp *ip, JSValue value, double recurse, JSValue
525
559
  }
526
560
  if (js_is_exception(str)) return str;
527
561
  if (type == ARRAY_TYPE) return str;
562
+ /* the key: Symbol(s), an identifier as it is, any other quoted; in brackets when it isn't
563
+ enumerable */
564
+ if (!enumerable) put_ascii(&b, "[");
528
565
  if (js_is_symbol(key)) {
529
566
  JSValue s = js_symbol_descriptive_string(ctx, key);
530
- if (js_is_exception(s)) return s;
531
- put_ascii(&b, "[");
567
+ if (js_is_exception(s)) { free(b.units); return s; }
532
568
  put_escaped(&b, js_string_view(ctx, s));
533
- put_ascii(&b, "]");
534
569
  } else {
535
570
  JSValue k = key_string(ip, key);
536
- if (js_is_exception(k)) return k;
571
+ if (js_is_exception(k)) { free(b.units); return k; }
537
572
  if (str_eq_cstr(ctx, k, "__proto__")) put_ascii(&b, "['__proto__']");
538
- else if (!enumerable) {
539
- put_ascii(&b, "[");
540
- put_escaped(&b, js_string_view(ctx, k));
541
- put_ascii(&b, "]");
542
- } else if (is_identifier_key(ctx, k)) put_str(&b, ctx, k);
573
+ else if (is_identifier_key(ctx, k)) put_str(&b, ctx, k);
543
574
  else put_quoted(&b, js_string_view(ctx, k));
544
575
  }
576
+ if (!enumerable) put_ascii(&b, "]");
545
577
  put_ascii(&b, ": ");
546
578
  put_str(&b, ctx, str);
547
579
  return done(ip, &b);
@@ -859,7 +891,7 @@ static JSValue format_error(Insp *ip, JSValue err, JSValue constructor, JSValue
859
891
  if (pos == 0) pos = -1; /* Node: `(err.message && stack.indexOf(err.message)) || -1` */
860
892
  if (pos != -1) pos += js_string_length(m);
861
893
  }
862
- /* no stack trace (visaljs records none: plan/unsupported.md): the error in brackets */
894
+ /* no stack trace (visaljs records none): the error in brackets */
863
895
  JSValue at = cstr(ip, "\n at");
864
896
  if (js_is_exception(at)) return at;
865
897
  if (str_index_of(ctx, stack, at, pos < 0 ? 0 : (uint32_t)pos) == -1) stack = concat3(ip, "[", stack, "]");
@@ -871,6 +903,13 @@ static JSValue format_error(Insp *ip, JSValue err, JSValue constructor, JSValue
871
903
  /* ---- Laying out ------------------------------------------------------------------------- */
872
904
 
873
905
  static bool is_below_break_length(Insp *ip, List *output, double start, JSValue base) {
906
+ /* an infinite breakLength: one line, unless an entry has a line break of its own */
907
+ if (isinf(ip->o.break_length)) {
908
+ if (js_string_length(base) != 0 && str_contains_unit(ip->ctx, base, '\n')) return false;
909
+ for (size_t i = 0; i < output->n; i++)
910
+ if (str_contains_unit(ip->ctx, output->v[i], '\n')) return false;
911
+ return true;
912
+ }
874
913
  double total = output->n + start;
875
914
  if (total + output->n > ip->o.break_length) return false;
876
915
  for (size_t i = 0; i < output->n; i++) {
@@ -1162,7 +1201,10 @@ static JSValue format_raw(Insp *ip, JSValue value, double recurse) {
1162
1201
  JSValue constructor = get_constructor_name(ip, value, recurse);
1163
1202
  if (js_is_exception(constructor)) return constructor;
1164
1203
  JSValue tag = get(ip, value, JS_SYMBOL(toStringTag));
1165
- if (js_is_exception(tag)) return tag;
1204
+ if (js_is_exception(tag)) { /* a getter that throws: no tag */
1205
+ js_discard(js_take_exception(ctx));
1206
+ tag = js_empty_string();
1207
+ }
1166
1208
  /* only listed when not an own enumerable property (it would be printed twice) */
1167
1209
  if (!js_is_string(tag) ||
1168
1210
  (js_string_length(tag) != 0 && (ip->o.show_hidden ? has_own(ctx, value, JS_SYMBOL(toStringTag))
@@ -1411,6 +1453,17 @@ static JSValue format_raw(Insp *ip, JSValue value, double recurse) {
1411
1453
  break;
1412
1454
  }
1413
1455
  ip->seen.n--;
1456
+ if (ip->o.sorted) {
1457
+ /* Node sorts the formatted entries: all of an object's (a Map's, a Set's), only the named
1458
+ * properties after an array's elements */
1459
+ size_t from = extras_type == OBJECT_TYPE ? 0 : keys.n > 1 ? output.n - keys.n : output.n;
1460
+ for (size_t i = from + 1; i < output.n; i++) {
1461
+ JSValue s = output.v[i];
1462
+ size_t j = i;
1463
+ for (; j > from && js_string_compare(ctx, output.v[j - 1], s) > 0; j--) output.v[j] = output.v[j - 1];
1464
+ output.v[j] = s;
1465
+ }
1466
+ }
1414
1467
  result = reduce_to_single_string(ip, &output, base, brace0, brace1, extras_type, recurse, value);
1415
1468
  out:
1416
1469
  list_free(&keys);
@@ -1444,7 +1497,9 @@ static JSValue user_options(Insp *ip) {
1444
1497
  FIELD("breakLength", js_number(p->break_length));
1445
1498
  FIELD("compact", p->compact == COMPACT_TRUE ? JS_TRUE : p->compact == 0 ? JS_FALSE : js_int32(p->compact));
1446
1499
  FIELD("sorted", js_bool(p->sorted));
1447
- FIELD("getters", JS_FALSE);
1500
+ FIELD("getters", p->getters == JS_INSPECT_GETTERS_ALL ? JS_TRUE
1501
+ : p->getters == JS_INSPECT_GETTERS_GET ? js_new_string_cstr(ctx, "get")
1502
+ : p->getters == JS_INSPECT_GETTERS_SET ? js_new_string_cstr(ctx, "set") : JS_FALSE);
1448
1503
  FIELD("numericSeparator", JS_FALSE);
1449
1504
  JSValue stylize = js_new_native(ctx, identity_stylize, js_atom_from_cstr(ctx, "stylize"), 2, JS_FN_STRICT);
1450
1505
  if (js_is_exception(stylize)) return stylize;
@@ -1747,6 +1802,10 @@ int js_inspect_options_from(JSContext *ctx, JSValue opts, JSInspectOptions *o) {
1747
1802
  else if (str_eq_cstr(ctx, key, "breakLength")) o->break_length = js_is_number(v) ? d : o->break_length;
1748
1803
  else if (str_eq_cstr(ctx, key, "compact")) o->compact = js_is_bool(v) ? (js_as_bool(v) ? COMPACT_TRUE : 0) : js_is_number(v) ? (int)d : o->compact;
1749
1804
  else if (str_eq_cstr(ctx, key, "sorted")) o->sorted = js_truthy(v);
1805
+ else if (str_eq_cstr(ctx, key, "getters"))
1806
+ o->getters = js_is_bool(v) ? (js_as_bool(v) ? JS_INSPECT_GETTERS_ALL : JS_INSPECT_GETTERS_OFF)
1807
+ : js_is_string(v) && str_eq_cstr(ctx, v, "get") ? JS_INSPECT_GETTERS_GET
1808
+ : js_is_string(v) && str_eq_cstr(ctx, v, "set") ? JS_INSPECT_GETTERS_SET : JS_INSPECT_GETTERS_OFF;
1750
1809
  }
1751
1810
  return 0;
1752
1811
  }
@@ -23,6 +23,8 @@ void js_function_realm_init(JSContext *ctx); /* function.c: %Function.prototype
23
23
  void js_global_realm_init(JSContext *ctx); /* global.c: the global object, primitives' prototypes */
24
24
  void js_error_realm_init(JSContext *ctx, JSObject *global); /* error.c: Error and the native errors */
25
25
  void js_builtins_realm_init(JSContext *ctx, JSObject *global); /* builtins.c: Object, Array, String, … */
26
+ /* builtins.c: %GeneratorFunction% (0), %AsyncFunction% (1) or %AsyncGeneratorFunction% (2), for proto */
27
+ void js_define_function_kind_ctor(JSContext *ctx, JSValue proto, int kind);
26
28
 
27
29
  /* The ordinary internal methods (object.c), for class hooks that add to them. */
28
30
  int js_ordinary_get_own_property(JSContext *ctx, JSObject *o, JSValue key, JSPropertyDescriptor *out);
@@ -49,7 +51,7 @@ JSValue js_generator_proto(JSContext *ctx, JSValue callee, JSIntrinsic fallback)
49
51
  * handler's result, or undefined (promise.c). */
50
52
  void js_promise_then_internal(JSContext *ctx, JSValue promise, JSValue on_fulfilled, JSValue on_rejected, JSValue derived);
51
53
 
52
- /* Weak collections and references (weak.c; ADR 0002): the ephemeron pass (true if it
54
+ /* Weak collections and references (weak.c): the ephemeron pass (true if it
53
55
  * marked anything), weak processing after marking, the kept-alive roots, teardown;
54
56
  * ClearKeptObjects; the FinalizationRegistry cleanup tasks (0, or -1 after an uncaught
55
57
  * error); the realm's WeakMap, WeakSet, WeakRef, FinalizationRegistry. */
@@ -65,7 +67,8 @@ void js_atoms_init(JSRuntime *rt);
65
67
  void js_atoms_sweep(JSRuntime *rt); /* weak processing: drop unmarked atoms */
66
68
  void js_atoms_free(JSRuntime *rt);
67
69
 
68
- /* Cell classes defined outside gc.c (ADR 0002: one visit/finalize pair per kind). */
70
+ /* Cell classes defined outside gc.c: each kind's name and finalizer. The marker visits these kinds
71
+ * itself (gc_visit.h), so their `visit` is NULL; only host cells' classes have one. */
69
72
  extern const JSCellClass js_flat_string_class;
70
73
  extern const JSCellClass js_symbol_cell_class;
71
74
  extern const JSCellClass js_rope_class;
@@ -5,10 +5,17 @@
5
5
  #include "js_object.h"
6
6
  #include "js_symbol.h"
7
7
  #include "jscontext.h"
8
+ #include "shape.h"
8
9
 
9
10
  /* The keys still to visit: `object`'s own keys from `index` on, then its prototype's, and
10
11
  * so on. `visited` (a null-prototype object used as a set) holds every key already seen,
11
- * so a key shadowed by an earlier object (enumerable or not) is skipped. */
12
+ * so a key shadowed by an earlier object (enumerable or not) is skipped.
13
+ *
14
+ * The fast path (`shape` set): an ordinary object without elements, whose prototypes have no
15
+ * enumerable keys (`{…}`, class instances). Its keys are then its shape's enumerable string keys,
16
+ * listed once per shape (enum_keys), and there is nothing to shadow, so no `visited`. While the
17
+ * object keeps that shape (shared shapes never change), each key is still there and enumerable;
18
+ * after a change, each is looked up as on the slow path. */
12
19
  typedef struct ForIn {
13
20
  JSHostCell host;
14
21
  JSValue object; /* null when done */
@@ -17,6 +24,7 @@ typedef struct ForIn {
17
24
  JSValue visited;
18
25
  JSValue string; /* a string primitive: its indices come first; else undefined */
19
26
  uint32_t index;
27
+ JSShape *shape; /* the fast path: the object's shape when the loop began; else NULL */
20
28
  } ForIn;
21
29
 
22
30
  static void for_in_visit(JSCell *c, JSTracer *trc) {
@@ -26,11 +34,77 @@ static void for_in_visit(JSCell *c, JSTracer *trc) {
26
34
  js_trace_value(trc, f->proto);
27
35
  js_trace_value(trc, f->visited);
28
36
  js_trace_value(trc, f->string);
37
+ if (f->shape) js_trace_cell(trc, &f->shape->cell);
29
38
  }
30
39
 
31
- static const JSCellClass for_in_class = { "ForInIterator", for_in_visit, NULL };
40
+ static const JSCellClass for_in_class = { "ForInIterator", for_in_visit, NULL, NULL };
41
+
42
+ /* Whether for…in sees `o`'s keys exactly as its shape lists them: an object with the ordinary
43
+ * internal methods, no own keys outside its shape (Array's `length`, a String's indices), and
44
+ * no elements. */
45
+ static bool plain_keys(JSObject *o) {
46
+ const JSClass *cls = o->shape->cls;
47
+ if (cls->methods || cls->get_own_property || cls->extra_keys) return false;
48
+ return o->elements->kind == JS_ELEMENTS_DENSE && o->elements->length == 0;
49
+ }
50
+
51
+ /* The enumerable string keys of `s`'s properties, in order: a new value array. */
52
+ static JSValueArray *enumerable_keys(JSContext *ctx, JSShape *s) {
53
+ JSPropTable *t = js_shape_entries(s);
54
+ uint32_t n = 0;
55
+ for (uint32_t i = 0; i < t->count; i++)
56
+ n += js_is_string(t->entries[i].key) && (t->entries[i].attrs & JS_PROP_ENUMERABLE);
57
+ JSValueArray *keys = js_alloc_value_array(ctx, n);
58
+ t = js_shape_entries(s); /* the allocation may have collected: the table is malloc'd, not moved */
59
+ for (uint32_t i = 0, k = 0; i < t->count && k < n; i++)
60
+ if (js_is_string(t->entries[i].key) && (t->entries[i].attrs & JS_PROP_ENUMERABLE)) keys->values[k++] = t->entries[i].key; /* barrier: fresh cell */
61
+ return keys;
62
+ }
63
+
64
+ /* `s`'s enumerable string keys: cached on a shared shape, listed anew for a dictionary's
65
+ * (it changes in place). */
66
+ static JSValueArray *shape_enum_keys(JSContext *ctx, JSShape *s) {
67
+ if (s->flags & JS_SHAPE_DICTIONARY) return enumerable_keys(ctx, s);
68
+ if (js_is_empty(s->enum_keys)) {
69
+ JSValueArray *keys = enumerable_keys(ctx, s);
70
+ js_store(ctx, &s->cell, &s->enum_keys, js_cell(&keys->cell));
71
+ }
72
+ return (JSValueArray *)js_as_cell(s->enum_keys);
73
+ }
74
+
75
+ /* Whether nothing on `o`'s prototype chain is enumerable: then for…in lists only `o`'s own keys. */
76
+ static bool protos_enumerate_nothing(JSContext *ctx, JSObject *o) {
77
+ for (JSValue p = o->shape->proto; js_is_object(p); p = js_as_object(p)->shape->proto) {
78
+ JSObject *po = js_as_object(p);
79
+ if (!plain_keys(po)) return false;
80
+ JSShape *s = po->shape;
81
+ if (s->flags & JS_SHAPE_DICTIONARY) {
82
+ JSPropTable *t = js_shape_entries(s);
83
+ for (uint32_t i = 0; i < t->count; i++)
84
+ if (js_is_string(t->entries[i].key) && (t->entries[i].attrs & JS_PROP_ENUMERABLE)) return false;
85
+ } else if (shape_enum_keys(ctx, s)->cell.aux != 0) {
86
+ return false;
87
+ }
88
+ }
89
+ return true;
90
+ }
32
91
 
33
92
  JSValue js_for_in_start(JSContext *ctx, JSValue v) {
93
+ if (js_is_object(v)) {
94
+ JSObject *o = js_as_object(v);
95
+ if (plain_keys(o) && protos_enumerate_nothing(ctx, o)) {
96
+ JSValueArray *keys = shape_enum_keys(ctx, o->shape);
97
+ ForIn *f = (ForIn *)js_alloc_host_cell(ctx, &for_in_class, sizeof(ForIn));
98
+ JSCell *c = &f->host.cell;
99
+ js_store(ctx, c, &f->object, v);
100
+ js_store(ctx, c, &f->keys, js_cell(&keys->cell));
101
+ js_store(ctx, c, &f->proto, JS_NULL);
102
+ js_store(ctx, c, &f->visited, JS_UNDEFINED);
103
+ js_store(ctx, c, &f->string, JS_UNDEFINED);
104
+ f->shape = o->shape; /* barrier: fresh cell */
105
+ return js_cell(c);
106
+ }
107
+ }
34
108
  ForIn *f = (ForIn *)js_alloc_host_cell(ctx, &for_in_class, sizeof(ForIn));
35
109
  JSCell *c = &f->host.cell;
36
110
  js_store(ctx, c, &f->keys, JS_EMPTY);
@@ -51,10 +125,28 @@ static bool first_visit(JSContext *ctx, ForIn *f, JSValue key) {
51
125
  return true;
52
126
  }
53
127
 
128
+ /* The fast path's next key. */
129
+ static JSValue fast_next(JSContext *ctx, ForIn *f) {
130
+ JSObject *o = js_as_object(f->object);
131
+ JSValueArray *keys = (JSValueArray *)js_as_cell(f->keys);
132
+ bool unchanged = o->shape == f->shape && !(f->shape->flags & JS_SHAPE_DICTIONARY);
133
+ while (f->index < keys->cell.aux) {
134
+ JSValue key = keys->values[f->index++];
135
+ if (unchanged) return key;
136
+ /* deleted since the loop began, or no longer enumerable: skipped */
137
+ JSPropertyDescriptor d;
138
+ int r = js_get_own_property(ctx, o, key, &d);
139
+ if (r < 0) return JS_EXCEPTION;
140
+ if (r == 1 && (d.attrs & JS_PROP_ENUMERABLE)) return key;
141
+ }
142
+ return JS_UNDEFINED;
143
+ }
144
+
54
145
  /* The next key (a string), undefined when there are no more, or JS_EXCEPTION. */
55
146
  JSValue js_for_in_next(JSContext *ctx, JSValue it) {
56
147
  ForIn *f = (ForIn *)js_as_cell(it);
57
148
  JSCell *c = &f->host.cell;
149
+ if (f->shape) return fast_next(ctx, f);
58
150
  /* a string's own indices, before anything on String.prototype */
59
151
  if (js_is_string(f->string)) {
60
152
  if (f->index < js_string_length(f->string)) {
@@ -176,7 +176,7 @@ static void record_visit(JSCell *c, JSTracer *trc) {
176
176
  js_trace_value(trc, r->next);
177
177
  }
178
178
 
179
- static const JSCellClass record_class = { "IteratorRecord", record_visit, NULL };
179
+ static const JSCellClass record_class = { "IteratorRecord", record_visit, NULL, NULL };
180
180
 
181
181
  /* Whether o's own data property `key` holds exactly `expected` (no getter runs). */
182
182
  static bool own_data_is(JSContext *ctx, JSValue o, JSValue key, JSValue expected) {
@@ -1,5 +1,5 @@
1
- /* The job queue (ADR 0008, layer 1: microtasks, unhandled rejections) and the event
2
- * loop (layer 2: timers; the v1 backend has no I/O, so waiting is sleeping). */
1
+ /* The job queue (microtasks, unhandled rejections) and the event loop (timers; without an
2
+ * I/O backend, waiting is sleeping). */
3
3
  #include "js_jobs.h"
4
4
 
5
5
  #include <stdint.h>
@@ -36,7 +36,7 @@ void js_enqueue_microtask(JSContext *ctx, const JSJob *job) {
36
36
  q->count++;
37
37
  }
38
38
 
39
- /* ---- The async context (ADR 0020) ---------------------------------------------------- */
39
+ /* ---- The async context --------------------------------------------------------------- */
40
40
 
41
41
  JSValue js_async_context(JSContext *ctx) { return ctx->rt->async_context; }
42
42
 
@@ -337,7 +337,7 @@ HOST_FN(clear_timeout) {
337
337
  return JS_UNDEFINED;
338
338
  }
339
339
 
340
- /* ---- The event loop (layer 2) ------------------------------------------------------ */
340
+ /* ---- The event loop ---------------------------------------------------------------- */
341
341
 
342
342
  static JSValue queue_microtask(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc,
343
343
  const JSValue *argv, JSValue new_target) {
@@ -381,6 +381,11 @@ int js_run_event_loop(JSContext *ctx, JSValue main_result) {
381
381
  t->now = js_os_now_ms();
382
382
  if (!t->count || t->heap[0].deadline > t->now) {
383
383
  int64_t timeout = t->count ? (int64_t)(t->heap[0].deadline - t->now) : -1;
384
+ /* a long wait with garbage to collect: JS_GC_IDLE_MS of it first, and when nothing
385
+ * happened in them, the collector gives memory back */
386
+ bool idle_gc = (timeout < 0 || timeout > JS_GC_IDLE_MS) && js_gc_idle_wanted(rt);
387
+ if (idle_gc) timeout = JS_GC_IDLE_MS;
388
+ uint64_t waited = t->now;
384
389
  /* the output so far appears before the wait, as Node's does (a server's log, say) */
385
390
  fflush(stdout);
386
391
  fflush(stderr);
@@ -389,9 +394,10 @@ int js_run_event_loop(JSContext *ctx, JSValue main_result) {
389
394
  status = rt->io->run(ctx, timeout);
390
395
  if (status) return status;
391
396
  } else {
392
- js_os_sleep_ms(t->heap[0].deadline - t->now); /* t->refed: a timer is pending */
397
+ js_os_sleep_ms((uint64_t)timeout); /* t->refed: a timer is pending */
393
398
  }
394
399
  t->now = js_os_now_ms();
400
+ if (idle_gc && t->now - waited >= JS_GC_IDLE_MS) js_gc_idle(ctx);
395
401
  }
396
402
  continue;
397
403
  }
@@ -1,4 +1,4 @@
1
- /* Number <-> string conversion (ADR 0013). */
1
+ /* Number <-> string conversion. */
2
2
  #include "jsnum.h"
3
3
 
4
4
  #include <math.h>
@@ -44,7 +44,7 @@ static double next_double_up(double d) {
44
44
  }
45
45
 
46
46
  /* Radix other than 10, with V8's algorithm so the output matches Node
47
- * byte for byte (ADR 0013): fraction digits until they are within half an
47
+ * byte for byte: fraction digits until they are within half an
48
48
  * ulp, and integer digits beyond 2^53 filled with zeros. */
49
49
  static size_t radix_to_cstr(char *out, double value, int radix) {
50
50
  static const char chars[] = "0123456789abcdefghijklmnopqrstuvwxyz";
@@ -1,4 +1,4 @@
1
- /* JSON (§25.5): an optional component (ADR 0014), and the serializer util.format's %j uses.
1
+ /* JSON (§25.5): an optional component, and the serializer util.format's %j uses.
2
2
  *
3
3
  * JSON.parse follows V8's parser closely enough to give its error messages: the same checks in
4
4
  * the same order, at the same positions ("Unexpected token '}', "[1,}" is not valid JSON",