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,1334 @@
1
+ // node:assert: Node's lib/assert.js with lib/internal/assert/ (assertion_error,
2
+ // myers_diff, utils, calltracker) (MIT; Node v22.22.2), ported: primordials are the methods they
3
+ // stand for, Node's errors are built here, and deep equality is internal/comparisons.js. Messages
4
+ // match Node's, diffs included, with two differences. Diffs are never colored (Node colors them
5
+ // when stderr is a color terminal). And assert.ok(false) without a message says `false == true`:
6
+ // Node quotes the call's source text ("The expression evaluated to a falsy value: assert.ok(x)"),
7
+ // which it reads from the file at run time, and a compiled program has none.
8
+ //
9
+ // Node's notice for lib/assert.js:
10
+ //
11
+ // Originally from narwhal.js (http://narwhaljs.org)
12
+ // Copyright (c) 2009 Thomas Robinson <280north.com>
13
+ //
14
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ // of this software and associated documentation files (the 'Software'), to
16
+ // deal in the Software without restriction, including without limitation the
17
+ // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18
+ // sell copies of the Software, and to permit persons to whom the Software is
19
+ // furnished to do so, subject to the following conditions:
20
+ //
21
+ // The above copyright notice and this permission notice shall be included in
22
+ // all copies or substantial portions of the Software.
23
+ //
24
+ // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
+ // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ // Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
31
+ import { utilInspect as inspect } from "visaljs:host";
32
+ import { codeError, invalidArgType, invalidArgValue, outOfRange, validateFunction } from "./internal/errors.js";
33
+ import { isDeepEqual, isDeepStrictEqual, isError, isPartialStrictEqual } from "./internal/comparisons.js";
34
+ import { isPromise, isRegExp } from "./util_types.js";
35
+ import { deprecate } from "./util.js";
36
+
37
+ /* Node's internal/util/colors with no color terminal: every color is "" */
38
+ const colors = { blue: "", green: "", white: "", red: "", gray: "", hasColors: false, refresh() {} };
39
+
40
+ const captureStackTrace = (err, fn) => {
41
+ if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(err, fn);
42
+ };
43
+
44
+ /* ERR_INVALID_ARG_TYPE's "of type function or an instance of Promise", from Node's list of names */
45
+ const kTypes = ["string", "function", "number", "object", "Function", "Object", "boolean", "bigint", "symbol"];
46
+ function describeTypes(expected) {
47
+ const types = [], instances = [];
48
+ for (const value of expected) {
49
+ if (kTypes.includes(value)) types.push(value.toLowerCase());
50
+ else instances.push(value);
51
+ }
52
+ if (instances.length > 0) {
53
+ const pos = types.indexOf("object");
54
+ if (pos !== -1) {
55
+ types.splice(pos, 1);
56
+ instances.push("Object");
57
+ }
58
+ }
59
+ const list = (items) => items.length > 2 ? `${items.slice(0, -1).join(", ")}, or ${items.at(-1)}` : items.join(" or ");
60
+ let msg = "";
61
+ if (types.length > 0) msg += `${types.length > 1 ? "one of type" : "of type"} ${list(types)}`;
62
+ if (instances.length > 0) msg += `${types.length > 0 ? " or " : ""}an instance of ${list(instances)}`;
63
+ return msg;
64
+ }
65
+
66
+ /* Node's determineSpecificType: how its errors describe a value they got */
67
+ function specificType(value) {
68
+ if (value === null) return "null";
69
+ if (value === undefined) return "undefined";
70
+ switch (typeof value) {
71
+ case "bigint":
72
+ return `type bigint (${value}n)`;
73
+ case "number":
74
+ return `type number (${Object.is(value, -0) ? "-0" : value})`;
75
+ case "boolean":
76
+ return `type boolean (${value})`;
77
+ case "symbol":
78
+ return `type symbol (${String(value)})`;
79
+ case "function":
80
+ return `function ${value.name}`;
81
+ case "object":
82
+ if (value.constructor && "name" in value.constructor) return `an instance of ${value.constructor.name}`;
83
+ return inspect(value, { depth: -1 });
84
+ default:
85
+ if (value.length > 28) value = `${value.slice(0, 25)}...`;
86
+ return value.indexOf("'") === -1 ? `type string ('${value}')` : `type string (${JSON.stringify(value)})`;
87
+ }
88
+ }
89
+
90
+ const missingArgs = () => codeError(TypeError, "ERR_MISSING_ARGS", 'The "actual" and "expected" arguments must be specified');
91
+
92
+ // ---- AssertionError (lib/internal/assert/assertion_error.js) ----------------------------------
93
+
94
+ const kReadableOperator = {
95
+ deepStrictEqual: "Expected values to be strictly deep-equal:",
96
+ partialDeepStrictEqual: "Expected values to be partially and strictly deep-equal:",
97
+ strictEqual: "Expected values to be strictly equal:",
98
+ strictEqualObject: 'Expected "actual" to be reference-equal to "expected":',
99
+ deepEqual: "Expected values to be loosely deep-equal:",
100
+ notDeepStrictEqual: 'Expected "actual" not to be strictly deep-equal to:',
101
+ notStrictEqual: 'Expected "actual" to be strictly unequal to:',
102
+ notStrictEqualObject: 'Expected "actual" not to be reference-equal to "expected":',
103
+ notDeepEqual: 'Expected "actual" not to be loosely deep-equal to:',
104
+ notIdentical: "Values have same structure but are not reference-equal:",
105
+ notDeepEqualUnequal: "Expected values not to be loosely deep-equal:",
106
+ };
107
+
108
+ const kMaxShortStringLength = 12;
109
+ const kMaxLongStringLength = 512;
110
+
111
+ const kMethodsWithCustomMessageDiff = new Set(["deepStrictEqual", "strictEqual", "partialDeepStrictEqual"]);
112
+
113
+ function copyError(source) {
114
+ const target = Object.assign({ __proto__: Object.getPrototypeOf(source) }, source);
115
+ Object.defineProperty(target, "message", { value: source.message });
116
+ if (Object.prototype.hasOwnProperty.call(source, "cause")) {
117
+ let { cause } = source;
118
+
119
+ if (isError(cause)) {
120
+ cause = copyError(cause);
121
+ }
122
+
123
+ Object.defineProperty(target, "cause", { value: cause });
124
+ }
125
+ return target;
126
+ }
127
+
128
+ function inspectValue(val) {
129
+ // The util.inspect default values could be changed. This makes sure the
130
+ // error messages contain the necessary information nevertheless.
131
+ return inspect(val, {
132
+ compact: false,
133
+ customInspect: false,
134
+ depth: 1000,
135
+ maxArrayLength: Infinity,
136
+ // Assert compares only enumerable properties (with a few exceptions).
137
+ showHidden: false,
138
+ // Assert does not detect proxies currently.
139
+ showProxy: false,
140
+ sorted: true,
141
+ // Inspect getters as we also check them when comparing entries.
142
+ getters: true,
143
+ });
144
+ }
145
+
146
+ function getErrorMessage(operator, message) {
147
+ return message || kReadableOperator[operator];
148
+ }
149
+
150
+ function checkOperator(actual, expected, operator) {
151
+ // In case both values are objects or functions explicitly mark them as not
152
+ // reference equal for the `strictEqual` operator.
153
+ if (operator === "strictEqual" &&
154
+ ((typeof actual === "object" && actual !== null && typeof expected === "object" && expected !== null) ||
155
+ (typeof actual === "function" && typeof expected === "function"))) {
156
+ operator = "strictEqualObject";
157
+ }
158
+
159
+ return operator;
160
+ }
161
+
162
+ // ---- Myers' diff (lib/internal/assert/myers_diff.js) ------------------------------------------
163
+
164
+ const kNopLinesToCollapse = 5;
165
+ const kOperations = { DELETE: -1, NOP: 0, INSERT: 1 };
166
+
167
+ function areLinesEqual(actual, expected, checkCommaDisparity) {
168
+ if (actual === expected) {
169
+ return true;
170
+ }
171
+ if (checkCommaDisparity) {
172
+ return (actual + ",") === expected || actual === (expected + ",");
173
+ }
174
+ return false;
175
+ }
176
+
177
+ function myersDiff(actual, expected, checkCommaDisparity = false) {
178
+ const actualLength = actual.length;
179
+ const expectedLength = expected.length;
180
+ const max = actualLength + expectedLength;
181
+
182
+ if (max > 2 ** 31 - 1) {
183
+ throw outOfRange("myersDiff input size", "< 2^31", max);
184
+ }
185
+
186
+ const v = new Int32Array(2 * max + 1);
187
+ const trace = [];
188
+
189
+ for (let diffLevel = 0; diffLevel <= max; diffLevel++) {
190
+ trace.push(new Int32Array(v)); // Clone the current state of `v`
191
+
192
+ for (let diagonalIndex = -diffLevel; diagonalIndex <= diffLevel; diagonalIndex += 2) {
193
+ const offset = diagonalIndex + max;
194
+ const previousOffset = v[offset - 1];
195
+ const nextOffset = v[offset + 1];
196
+ let x = diagonalIndex === -diffLevel || (diagonalIndex !== diffLevel && previousOffset < nextOffset) ?
197
+ nextOffset :
198
+ previousOffset + 1;
199
+ let y = x - diagonalIndex;
200
+
201
+ while (x < actualLength && y < expectedLength && areLinesEqual(actual[x], expected[y], checkCommaDisparity)) {
202
+ x++;
203
+ y++;
204
+ }
205
+
206
+ v[offset] = x;
207
+
208
+ if (x >= actualLength && y >= expectedLength) {
209
+ return backtrack(trace, actual, expected, checkCommaDisparity);
210
+ }
211
+ }
212
+ }
213
+ }
214
+
215
+ function backtrack(trace, actual, expected, checkCommaDisparity) {
216
+ const actualLength = actual.length;
217
+ const expectedLength = expected.length;
218
+ const max = actualLength + expectedLength;
219
+
220
+ let x = actualLength;
221
+ let y = expectedLength;
222
+ const result = [];
223
+
224
+ for (let diffLevel = trace.length - 1; diffLevel >= 0; diffLevel--) {
225
+ const v = trace[diffLevel];
226
+ const diagonalIndex = x - y;
227
+ const offset = diagonalIndex + max;
228
+
229
+ let prevDiagonalIndex;
230
+ if (diagonalIndex === -diffLevel || (diagonalIndex !== diffLevel && v[offset - 1] < v[offset + 1])) {
231
+ prevDiagonalIndex = diagonalIndex + 1;
232
+ } else {
233
+ prevDiagonalIndex = diagonalIndex - 1;
234
+ }
235
+
236
+ const prevX = v[prevDiagonalIndex + max];
237
+ const prevY = prevX - prevDiagonalIndex;
238
+
239
+ while (x > prevX && y > prevY) {
240
+ const actualItem = actual[x - 1];
241
+ const value = checkCommaDisparity && !actualItem.endsWith(",") ? expected[y - 1] : actualItem;
242
+ result.push([kOperations.NOP, value]);
243
+ x--;
244
+ y--;
245
+ }
246
+
247
+ if (diffLevel > 0) {
248
+ if (x > prevX) {
249
+ result.push([kOperations.INSERT, actual[--x]]);
250
+ } else {
251
+ result.push([kOperations.DELETE, expected[--y]]);
252
+ }
253
+ }
254
+ }
255
+
256
+ return result;
257
+ }
258
+
259
+ function printSimpleMyersDiff(diff) {
260
+ let message = "";
261
+
262
+ for (let diffIdx = diff.length - 1; diffIdx >= 0; diffIdx--) {
263
+ const { 0: operation, 1: value } = diff[diffIdx];
264
+ let color = colors.white;
265
+
266
+ if (operation === kOperations.INSERT) {
267
+ color = colors.green;
268
+ } else if (operation === kOperations.DELETE) {
269
+ color = colors.red;
270
+ }
271
+
272
+ message += `${color}${value}${colors.white}`;
273
+ }
274
+
275
+ return `\n${message}`;
276
+ }
277
+
278
+ function printMyersDiff(diff, operator) {
279
+ let message = "";
280
+ let skipped = false;
281
+ let nopCount = 0;
282
+
283
+ for (let diffIdx = diff.length - 1; diffIdx >= 0; diffIdx--) {
284
+ const { 0: operation, 1: value } = diff[diffIdx];
285
+ const previousOperation = diffIdx < diff.length - 1 ? diff[diffIdx + 1][0] : null;
286
+
287
+ // Avoid grouping if only one line would have been grouped otherwise
288
+ if (previousOperation === kOperations.NOP && operation !== previousOperation) {
289
+ if (nopCount === kNopLinesToCollapse + 1) {
290
+ message += `${colors.white} ${diff[diffIdx + 1][1]}\n`;
291
+ } else if (nopCount === kNopLinesToCollapse + 2) {
292
+ message += `${colors.white} ${diff[diffIdx + 2][1]}\n`;
293
+ message += `${colors.white} ${diff[diffIdx + 1][1]}\n`;
294
+ } else if (nopCount >= kNopLinesToCollapse + 3) {
295
+ message += `${colors.blue}...${colors.white}\n`;
296
+ message += `${colors.white} ${diff[diffIdx + 1][1]}\n`;
297
+ skipped = true;
298
+ }
299
+ nopCount = 0;
300
+ }
301
+
302
+ if (operation === kOperations.INSERT) {
303
+ if (operator === "partialDeepStrictEqual") {
304
+ message += `${colors.gray}${colors.hasColors ? " " : "+"} ${value}${colors.white}\n`;
305
+ } else {
306
+ message += `${colors.green}+${colors.white} ${value}\n`;
307
+ }
308
+ } else if (operation === kOperations.DELETE) {
309
+ message += `${colors.red}-${colors.white} ${value}\n`;
310
+ } else if (operation === kOperations.NOP) {
311
+ if (nopCount < kNopLinesToCollapse) {
312
+ message += `${colors.white} ${value}\n`;
313
+ }
314
+ nopCount++;
315
+ }
316
+ }
317
+
318
+ message = message.trimEnd();
319
+
320
+ return { message: `\n${message}`, skipped };
321
+ }
322
+
323
+ function getColoredMyersDiff(actual, expected) {
324
+ const header = `${colors.green}actual${colors.white} ${colors.red}expected${colors.white}`;
325
+ const skipped = false;
326
+
327
+ const diff = myersDiff(actual.split(""), expected.split(""));
328
+ let message = printSimpleMyersDiff(diff);
329
+
330
+ if (skipped) {
331
+ message += "...";
332
+ }
333
+
334
+ return { message, header, skipped };
335
+ }
336
+
337
+ function getStackedDiff(actual, expected) {
338
+ const isStringComparison = typeof actual === "string" && typeof expected === "string";
339
+
340
+ let message = `\n${colors.green}+${colors.white} ${actual}\n${colors.red}- ${colors.white}${expected}`;
341
+ const stringsLen = actual.length + expected.length;
342
+ const maxTerminalLength = process.stderr?.isTTY ? process.stderr.columns : 80;
343
+ const showIndicator = isStringComparison && (stringsLen <= maxTerminalLength);
344
+
345
+ if (showIndicator) {
346
+ let indicatorIdx = -1;
347
+
348
+ for (let i = 0; i < actual.length; i++) {
349
+ if (actual[i] !== expected[i]) {
350
+ // Skip the indicator for the first 2 characters because the diff is immediately apparent
351
+ // It is 3 instead of 2 to account for the quotes
352
+ if (i >= 3) {
353
+ indicatorIdx = i;
354
+ }
355
+ break;
356
+ }
357
+ }
358
+
359
+ if (indicatorIdx !== -1) {
360
+ message += `\n${" ".repeat(indicatorIdx + 2)}^`;
361
+ }
362
+ }
363
+
364
+ return { message };
365
+ }
366
+
367
+ function getSimpleDiff(originalActual, actual, originalExpected, expected) {
368
+ let stringsLen = actual.length + expected.length;
369
+ // Accounting for the quotes wrapping strings
370
+ if (typeof originalActual === "string") {
371
+ stringsLen -= 2;
372
+ }
373
+ if (typeof originalExpected === "string") {
374
+ stringsLen -= 2;
375
+ }
376
+ if (stringsLen <= kMaxShortStringLength && (originalActual !== 0 || originalExpected !== 0)) {
377
+ return { message: `${actual} !== ${expected}`, header: "" };
378
+ }
379
+
380
+ const isStringComparison = typeof originalActual === "string" && typeof originalExpected === "string";
381
+ // colored myers diff
382
+ if (isStringComparison && colors.hasColors) {
383
+ return getColoredMyersDiff(actual, expected);
384
+ }
385
+
386
+ return getStackedDiff(actual, expected);
387
+ }
388
+
389
+ function isSimpleDiff(actual, inspectedActual, expected, inspectedExpected) {
390
+ if (inspectedActual.length > 1 || inspectedExpected.length > 1) {
391
+ return false;
392
+ }
393
+
394
+ return typeof actual !== "object" || actual === null || typeof expected !== "object" || expected === null;
395
+ }
396
+
397
+ function createErrDiff(actual, expected, operator, customMessage, diffType = "simple") {
398
+ operator = checkOperator(actual, expected, operator);
399
+
400
+ let skipped = false;
401
+ let message;
402
+ const inspectedActual = inspectValue(actual);
403
+ const inspectedExpected = inspectValue(expected);
404
+ const inspectedSplitActual = inspectedActual.split("\n");
405
+ const inspectedSplitExpected = inspectedExpected.split("\n");
406
+ const showSimpleDiff = isSimpleDiff(actual, inspectedSplitActual, expected, inspectedSplitExpected);
407
+ let header = `${colors.green}+ actual${colors.white} ${colors.red}- expected${colors.white}`;
408
+
409
+ if (showSimpleDiff) {
410
+ const simpleDiff = getSimpleDiff(actual, inspectedSplitActual[0], expected, inspectedSplitExpected[0]);
411
+ message = simpleDiff.message;
412
+ if (typeof simpleDiff.header !== "undefined") {
413
+ header = simpleDiff.header;
414
+ }
415
+ if (simpleDiff.skipped) {
416
+ skipped = true;
417
+ }
418
+ } else if (inspectedActual === inspectedExpected) {
419
+ // Handles the case where the objects are structurally the same but different references
420
+ operator = "notIdentical";
421
+ if (inspectedSplitActual.length > 50 && diffType !== "full") {
422
+ message = `${inspectedSplitActual.slice(0, 50).join("\n")}\n...}`;
423
+ skipped = true;
424
+ } else {
425
+ message = inspectedSplitActual.join("\n");
426
+ }
427
+ header = "";
428
+ } else {
429
+ const checkCommaDisparity = actual != null && typeof actual === "object";
430
+ const diff = myersDiff(inspectedSplitActual, inspectedSplitExpected, checkCommaDisparity);
431
+
432
+ const myersDiffMessage = printMyersDiff(diff, operator);
433
+ message = myersDiffMessage.message;
434
+
435
+ if (operator === "partialDeepStrictEqual") {
436
+ header = `${colors.gray}${colors.hasColors ? "" : "+ "}actual${colors.white} ${colors.red}- expected${colors.white}`;
437
+ }
438
+
439
+ if (myersDiffMessage.skipped) {
440
+ skipped = true;
441
+ }
442
+ }
443
+
444
+ const headerMessage = `${getErrorMessage(operator, customMessage)}\n${header}`;
445
+ const skippedMessage = skipped ? "\n... Skipped lines" : "";
446
+
447
+ return `${headerMessage}${skippedMessage}\n${message}\n`;
448
+ }
449
+
450
+ function addEllipsis(string) {
451
+ const lines = string.split("\n", 11);
452
+ if (lines.length > 10) {
453
+ lines.length = 10;
454
+ return `${lines.join("\n")}\n...`;
455
+ } else if (string.length > kMaxLongStringLength) {
456
+ return `${string.slice(kMaxLongStringLength)}...`;
457
+ }
458
+ return string;
459
+ }
460
+
461
+ export class AssertionError extends Error {
462
+ constructor(options) {
463
+ if (options === null || typeof options !== "object") throw invalidArgType("options", "of type object", options);
464
+ const {
465
+ message,
466
+ operator,
467
+ stackStartFn,
468
+ details,
469
+ // Compatibility with older versions.
470
+ stackStartFunction,
471
+ diff = "simple",
472
+ } = options;
473
+ let { actual, expected } = options;
474
+
475
+ if (message != null) {
476
+ if (kMethodsWithCustomMessageDiff.has(operator)) {
477
+ super(createErrDiff(actual, expected, operator, message, diff));
478
+ } else {
479
+ super(String(message));
480
+ }
481
+ } else {
482
+ // Prevent the error stack from being visible by duplicating the error
483
+ // in a very close way to the original in case both sides are actually
484
+ // instances of Error.
485
+ if (typeof actual === "object" && actual !== null &&
486
+ typeof expected === "object" && expected !== null &&
487
+ "stack" in actual && actual instanceof Error &&
488
+ "stack" in expected && expected instanceof Error) {
489
+ actual = copyError(actual);
490
+ expected = copyError(expected);
491
+ }
492
+
493
+ if (kMethodsWithCustomMessageDiff.has(operator)) {
494
+ super(createErrDiff(actual, expected, operator, message, diff));
495
+ } else if (operator === "notDeepStrictEqual" || operator === "notStrictEqual") {
496
+ // In case the objects are equal but the operator requires unequal, show
497
+ // the first object and say A equals B
498
+ let base = kReadableOperator[operator];
499
+ const res = inspectValue(actual).split("\n");
500
+
501
+ // In case "actual" is an object or a function, it should not be
502
+ // reference equal.
503
+ if (operator === "notStrictEqual" && ((typeof actual === "object" && actual !== null) || typeof actual === "function")) {
504
+ base = kReadableOperator.notStrictEqualObject;
505
+ }
506
+
507
+ // Only remove lines in case it makes sense to collapse those.
508
+ if (res.length > 50 && diff !== "full") {
509
+ res[46] = `${colors.blue}...${colors.white}`;
510
+ while (res.length > 47) {
511
+ res.pop();
512
+ }
513
+ }
514
+
515
+ // Only print a single input.
516
+ if (res.length === 1) {
517
+ super(`${base}${res[0].length > 5 ? "\n\n" : " "}${res[0]}`);
518
+ } else {
519
+ super(`${base}\n\n${res.join("\n")}\n`);
520
+ }
521
+ } else {
522
+ let res = inspectValue(actual);
523
+ let other = inspectValue(expected);
524
+ const knownOperator = kReadableOperator[operator];
525
+ if (operator === "notDeepEqual" && res === other) {
526
+ res = `${knownOperator}\n\n${res}`;
527
+ if (res.length > 1024 && diff !== "full") {
528
+ res = `${res.slice(0, 1021)}...`;
529
+ }
530
+ super(res);
531
+ } else {
532
+ if (res.length > kMaxLongStringLength && diff !== "full") {
533
+ res = `${res.slice(0, 509)}...`;
534
+ }
535
+ if (other.length > kMaxLongStringLength && diff !== "full") {
536
+ other = `${other.slice(0, 509)}...`;
537
+ }
538
+ if (operator === "deepEqual") {
539
+ res = `${knownOperator}\n\n${res}\n\nshould loosely deep-equal\n\n`;
540
+ } else {
541
+ const newOp = kReadableOperator[`${operator}Unequal`];
542
+ if (newOp) {
543
+ res = `${newOp}\n\n${res}\n\nshould not loosely deep-equal\n\n`;
544
+ } else {
545
+ other = ` ${operator} ${other}`;
546
+ }
547
+ }
548
+ super(`${res}${other}`);
549
+ }
550
+ }
551
+ }
552
+
553
+ this.generatedMessage = !message;
554
+ Object.defineProperty(this, "name", {
555
+ value: "AssertionError [ERR_ASSERTION]",
556
+ enumerable: false,
557
+ writable: true,
558
+ configurable: true,
559
+ });
560
+ this.code = "ERR_ASSERTION";
561
+ if (details) {
562
+ this.actual = undefined;
563
+ this.expected = undefined;
564
+ this.operator = undefined;
565
+ for (let i = 0; i < details.length; i++) {
566
+ this["message " + i] = details[i].message;
567
+ this["actual " + i] = details[i].actual;
568
+ this["expected " + i] = details[i].expected;
569
+ this["operator " + i] = details[i].operator;
570
+ this["stack trace " + i] = details[i].stack;
571
+ }
572
+ } else {
573
+ this.actual = actual;
574
+ this.expected = expected;
575
+ this.operator = operator;
576
+ }
577
+ captureStackTrace(this, stackStartFn || stackStartFunction);
578
+ // Create error message including the error code in the name.
579
+ this.stack; // eslint-disable-line @typescript-eslint/no-unused-expressions
580
+ // Reset the name.
581
+ this.name = "AssertionError";
582
+ this.diff = diff;
583
+ }
584
+
585
+ toString() {
586
+ return `${this.name} [${this.code}]: ${this.message}`;
587
+ }
588
+
589
+ [Symbol.for("nodejs.util.inspect.custom")](recurseTimes, ctx) {
590
+ // Long strings should not be fully inspected.
591
+ const tmpActual = this.actual;
592
+ const tmpExpected = this.expected;
593
+
594
+ if (typeof this.actual === "string") {
595
+ this.actual = addEllipsis(this.actual);
596
+ }
597
+ if (typeof this.expected === "string") {
598
+ this.expected = addEllipsis(this.expected);
599
+ }
600
+
601
+ // This limits the `actual` and `expected` property default inspection to
602
+ // the minimum depth. Otherwise those values would be too verbose compared
603
+ // to the actual error message which contains a combined view of these two
604
+ // input values.
605
+ const result = inspect(this, { ...ctx, customInspect: false, depth: 0 });
606
+
607
+ // Reset the properties after inspection.
608
+ this.actual = tmpActual;
609
+ this.expected = tmpExpected;
610
+
611
+ return result;
612
+ }
613
+ }
614
+
615
+ // ---- CallTracker (lib/internal/assert/calltracker.js) -----------------------------------------
616
+
617
+ const noop = () => {};
618
+
619
+ class CallTrackerContext {
620
+ #expected;
621
+ #calls;
622
+ #name;
623
+ #stackTrace;
624
+ constructor({ expected, stackTrace, name }) {
625
+ this.#calls = [];
626
+ this.#expected = expected;
627
+ this.#stackTrace = stackTrace;
628
+ this.#name = name;
629
+ }
630
+
631
+ track(thisArg, args) {
632
+ const argsClone = Object.freeze(args.slice());
633
+ this.#calls.push(Object.freeze({ thisArg, arguments: argsClone }));
634
+ }
635
+
636
+ get delta() {
637
+ return this.#calls.length - this.#expected;
638
+ }
639
+
640
+ reset() {
641
+ this.#calls = [];
642
+ }
643
+ getCalls() {
644
+ return Object.freeze(this.#calls.slice());
645
+ }
646
+
647
+ report() {
648
+ if (this.delta !== 0) {
649
+ const message = `Expected the ${this.#name} function to be ` +
650
+ `executed ${this.#expected} time(s) but was ` +
651
+ `executed ${this.#calls.length} time(s).`;
652
+ return {
653
+ message,
654
+ actual: this.#calls.length,
655
+ expected: this.#expected,
656
+ operator: this.#name,
657
+ stack: this.#stackTrace,
658
+ };
659
+ }
660
+ }
661
+ }
662
+
663
+ class CallTracker {
664
+ #callChecks = new Set();
665
+ #trackedFunctions = new WeakMap();
666
+
667
+ #getTrackedFunction(tracked) {
668
+ if (!this.#trackedFunctions.has(tracked)) {
669
+ throw invalidArgValue("tracked", "is not a tracked function", tracked);
670
+ }
671
+ return this.#trackedFunctions.get(tracked);
672
+ }
673
+
674
+ reset(tracked) {
675
+ if (tracked === undefined) {
676
+ this.#callChecks.forEach((check) => check.reset());
677
+ return;
678
+ }
679
+
680
+ this.#getTrackedFunction(tracked).reset();
681
+ }
682
+
683
+ getCalls(tracked) {
684
+ return this.#getTrackedFunction(tracked).getCalls();
685
+ }
686
+
687
+ calls(fn, expected = 1) {
688
+ if (process._exiting) throw codeError(Error, "ERR_UNAVAILABLE_DURING_EXIT", "Cannot call function in process exit handler");
689
+ if (typeof fn === "number") {
690
+ expected = fn;
691
+ fn = noop;
692
+ } else if (fn === undefined) {
693
+ fn = noop;
694
+ }
695
+
696
+ if (typeof expected !== "number") throw invalidArgType("expected", "of type number", expected);
697
+ if (!Number.isInteger(expected)) throw outOfRange("expected", "an integer", expected);
698
+ if (expected < 1 || expected > 4294967295) throw outOfRange("expected", ">= 1 && <= 4294967295", expected);
699
+
700
+ const context = new CallTrackerContext({
701
+ expected,
702
+ stackTrace: new Error(),
703
+ name: fn.name || "calls",
704
+ });
705
+ const tracked = new Proxy(fn, {
706
+ __proto__: null,
707
+ apply(fn, thisArg, argList) {
708
+ context.track(thisArg, argList);
709
+ return Reflect.apply(fn, thisArg, argList);
710
+ },
711
+ });
712
+ this.#callChecks.add(context);
713
+ this.#trackedFunctions.set(tracked, context);
714
+ return tracked;
715
+ }
716
+
717
+ report() {
718
+ const errors = [];
719
+ for (const context of this.#callChecks) {
720
+ const message = context.report();
721
+ if (message !== undefined) {
722
+ errors.push(message);
723
+ }
724
+ }
725
+ return errors;
726
+ }
727
+
728
+ verify() {
729
+ const errors = this.report();
730
+ if (errors.length === 0) {
731
+ return;
732
+ }
733
+ const message = errors.length === 1 ? errors[0].message : "Functions were not called the expected number of times";
734
+ throw new AssertionError({ message, details: errors });
735
+ }
736
+ }
737
+
738
+ // ---- The assertions (lib/assert.js, lib/internal/assert/utils.js) -----------------------------
739
+
740
+ const kOptions = Symbol("options");
741
+
742
+ let warned = false;
743
+
744
+ const NO_EXCEPTION_SENTINEL = {};
745
+
746
+ function innerOk(fn, argLen, value, message) {
747
+ if (!value) {
748
+ let generatedMessage = false;
749
+
750
+ if (argLen === 0) {
751
+ generatedMessage = true;
752
+ message = "No value argument passed to `assert.ok()`";
753
+ } else if (message == null) {
754
+ /* Node quotes the call's source here, read from the file: a compiled program has none,
755
+ and the message is AssertionError's own (`false == true`) */
756
+ generatedMessage = true;
757
+ } else if (isError(message)) {
758
+ throw message;
759
+ }
760
+
761
+ const err = new AssertionError({
762
+ actual: value,
763
+ expected: true,
764
+ message,
765
+ operator: "==",
766
+ stackStartFn: fn,
767
+ });
768
+ err.generatedMessage = generatedMessage;
769
+ throw err;
770
+ }
771
+ }
772
+
773
+ /**
774
+ * Assert's options: `diff` ('simple' or 'full': the whole diff in assertion errors), and `strict`
775
+ * (true by default: the non-strict methods are the strict ones).
776
+ */
777
+ export function Assert(options) {
778
+ if (!new.target) {
779
+ throw codeError(TypeError, "ERR_CONSTRUCT_CALL_REQUIRED", "Class constructor Assert cannot be invoked without `new`");
780
+ }
781
+
782
+ options = Object.assign({ __proto__: null, strict: true, skipPrototype: false }, options);
783
+
784
+ const allowedDiffs = ["simple", "full"];
785
+ if (options.diff !== undefined && !allowedDiffs.includes(options.diff)) {
786
+ throw invalidArgValue("options.diff", "must be one of: 'simple', 'full'", options.diff);
787
+ }
788
+
789
+ this.AssertionError = AssertionError;
790
+ Object.defineProperty(this, kOptions, { value: options, enumerable: false, configurable: false, writable: false });
791
+
792
+ if (options.strict) {
793
+ this.equal = this.strictEqual;
794
+ this.deepEqual = this.deepStrictEqual;
795
+ this.notEqual = this.notStrictEqual;
796
+ this.notDeepEqual = this.notDeepStrictEqual;
797
+ }
798
+ }
799
+
800
+ // All of the following functions must throw an AssertionError
801
+ // when a corresponding condition is not met, with a message that
802
+ // may be undefined if not provided. All assertion methods provide
803
+ // both the actual and expected values to the assertion error for
804
+ // display purposes. They read the instance's options with this?.[kOptions]: destructured from an
805
+ // Assert instance, they have no `this` and behave as by default.
806
+
807
+ function innerFail(obj) {
808
+ if (obj.message instanceof Error) throw obj.message;
809
+
810
+ throw new AssertionError(obj);
811
+ }
812
+
813
+ Assert.prototype.fail = function fail(actual, expected, message, operator, stackStartFn) {
814
+ const argsLen = arguments.length;
815
+
816
+ let internalMessage = false;
817
+ if (actual == null && argsLen <= 1) {
818
+ internalMessage = true;
819
+ message = "Failed";
820
+ } else if (argsLen === 1) {
821
+ message = actual;
822
+ actual = undefined;
823
+ } else {
824
+ if (warned === false) {
825
+ warned = true;
826
+ process.emitWarning(
827
+ "assert.fail() with more than one argument is deprecated. " +
828
+ "Please use assert.strictEqual() instead or only pass a message.",
829
+ "DeprecationWarning",
830
+ "DEP0094",
831
+ );
832
+ }
833
+ if (argsLen === 2) operator = "!=";
834
+ }
835
+
836
+ if (message instanceof Error) throw message;
837
+
838
+ const errArgs = {
839
+ actual,
840
+ expected,
841
+ operator: operator === undefined ? "fail" : operator,
842
+ stackStartFn: stackStartFn || fail,
843
+ message,
844
+ diff: this?.[kOptions]?.diff,
845
+ };
846
+ const err = new AssertionError(errArgs);
847
+ if (internalMessage) {
848
+ err.generatedMessage = true;
849
+ }
850
+ throw err;
851
+ };
852
+
853
+ /** Pure assertion tests whether a value is truthy, as determined by !!value. */
854
+ function ok(...args) {
855
+ innerOk(ok, args.length, ...args);
856
+ }
857
+
858
+ // Duplicated as the other `ok` function is supercharged and exposed as default export.
859
+ Assert.prototype.ok = function ok(...args) {
860
+ innerOk(ok, args.length, ...args);
861
+ };
862
+
863
+ /** The equality assertion tests shallow, coercive equality with ==. */
864
+ Assert.prototype.equal = function equal(actual, expected, message) {
865
+ if (arguments.length < 2) {
866
+ throw missingArgs();
867
+ }
868
+ if (actual != expected && (!Number.isNaN(actual) || !Number.isNaN(expected))) {
869
+ innerFail({ actual, expected, message, operator: "==", stackStartFn: equal, diff: this?.[kOptions]?.diff });
870
+ }
871
+ };
872
+
873
+ /** The non-equality assertion tests for whether two objects are not equal with !=. */
874
+ Assert.prototype.notEqual = function notEqual(actual, expected, message) {
875
+ if (arguments.length < 2) {
876
+ throw missingArgs();
877
+ }
878
+ if (actual == expected || (Number.isNaN(actual) && Number.isNaN(expected))) {
879
+ innerFail({ actual, expected, message, operator: "!=", stackStartFn: notEqual, diff: this?.[kOptions]?.diff });
880
+ }
881
+ };
882
+
883
+ /** The deep equivalence assertion tests a deep equality relation. */
884
+ Assert.prototype.deepEqual = function deepEqual(actual, expected, message) {
885
+ if (arguments.length < 2) {
886
+ throw missingArgs();
887
+ }
888
+ if (!isDeepEqual(actual, expected)) {
889
+ innerFail({ actual, expected, message, operator: "deepEqual", stackStartFn: deepEqual, diff: this?.[kOptions]?.diff });
890
+ }
891
+ };
892
+
893
+ /** The deep non-equivalence assertion tests for any deep inequality. */
894
+ Assert.prototype.notDeepEqual = function notDeepEqual(actual, expected, message) {
895
+ if (arguments.length < 2) {
896
+ throw missingArgs();
897
+ }
898
+ if (isDeepEqual(actual, expected)) {
899
+ innerFail({ actual, expected, message, operator: "notDeepEqual", stackStartFn: notDeepEqual, diff: this?.[kOptions]?.diff });
900
+ }
901
+ };
902
+
903
+ /** The deep strict equivalence assertion tests a deep strict equality relation. */
904
+ Assert.prototype.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
905
+ if (arguments.length < 2) {
906
+ throw missingArgs();
907
+ }
908
+ if (!isDeepStrictEqual(actual, expected, this?.[kOptions]?.skipPrototype)) {
909
+ innerFail({ actual, expected, message, operator: "deepStrictEqual", stackStartFn: deepStrictEqual, diff: this?.[kOptions]?.diff });
910
+ }
911
+ };
912
+
913
+ /** The deep strict non-equivalence assertion tests for any deep strict inequality. */
914
+ Assert.prototype.notDeepStrictEqual = function notDeepStrictEqual(actual, expected, message) {
915
+ if (arguments.length < 2) {
916
+ throw missingArgs();
917
+ }
918
+ if (isDeepStrictEqual(actual, expected, this?.[kOptions]?.skipPrototype)) {
919
+ innerFail({ actual, expected, message, operator: "notDeepStrictEqual", stackStartFn: notDeepStrictEqual, diff: this?.[kOptions]?.diff });
920
+ }
921
+ };
922
+
923
+ /** The strict equivalence assertion tests a strict equality relation. */
924
+ Assert.prototype.strictEqual = function strictEqual(actual, expected, message) {
925
+ if (arguments.length < 2) {
926
+ throw missingArgs();
927
+ }
928
+ if (!Object.is(actual, expected)) {
929
+ innerFail({ actual, expected, message, operator: "strictEqual", stackStartFn: strictEqual, diff: this?.[kOptions]?.diff });
930
+ }
931
+ };
932
+
933
+ /** The strict non-equivalence assertion tests for any strict inequality. */
934
+ Assert.prototype.notStrictEqual = function notStrictEqual(actual, expected, message) {
935
+ if (arguments.length < 2) {
936
+ throw missingArgs();
937
+ }
938
+ if (Object.is(actual, expected)) {
939
+ innerFail({ actual, expected, message, operator: "notStrictEqual", stackStartFn: notStrictEqual, diff: this?.[kOptions]?.diff });
940
+ }
941
+ };
942
+
943
+ /** The strict equivalence assertion test between two objects, `expected` a subset of `actual`. */
944
+ Assert.prototype.partialDeepStrictEqual = function partialDeepStrictEqual(actual, expected, message) {
945
+ if (arguments.length < 2) {
946
+ throw missingArgs();
947
+ }
948
+ if (!isPartialStrictEqual(actual, expected)) {
949
+ innerFail({ actual, expected, message, operator: "partialDeepStrictEqual", stackStartFn: partialDeepStrictEqual, diff: this?.[kOptions]?.diff });
950
+ }
951
+ };
952
+
953
+ class Comparison {
954
+ constructor(obj, keys, actual) {
955
+ for (const key of keys) {
956
+ if (key in obj) {
957
+ if (actual !== undefined && typeof actual[key] === "string" && isRegExp(obj[key]) && obj[key].exec(actual[key]) !== null) {
958
+ this[key] = actual[key];
959
+ } else {
960
+ this[key] = obj[key];
961
+ }
962
+ }
963
+ }
964
+ }
965
+ }
966
+
967
+ function compareExceptionKey(actual, expected, key, message, keys, fn) {
968
+ if (!(key in actual) || !isDeepStrictEqual(actual[key], expected[key])) {
969
+ if (!message) {
970
+ // Create placeholder objects to create a nice output.
971
+ const a = new Comparison(actual, keys);
972
+ const b = new Comparison(expected, keys, actual);
973
+
974
+ const err = new AssertionError({ actual: a, expected: b, operator: "deepStrictEqual", stackStartFn: fn, diff: this?.[kOptions]?.diff });
975
+ err.actual = actual;
976
+ err.expected = expected;
977
+ err.operator = fn.name;
978
+ throw err;
979
+ }
980
+ innerFail({ actual, expected, message, operator: fn.name, stackStartFn: fn, diff: this?.[kOptions]?.diff });
981
+ }
982
+ }
983
+
984
+ function expectedException(actual, expected, message, fn) {
985
+ let generatedMessage = false;
986
+ let throwError = false;
987
+
988
+ if (typeof expected !== "function") {
989
+ // Handle regular expressions.
990
+ if (isRegExp(expected)) {
991
+ const str = String(actual);
992
+ if (expected.exec(str) !== null) return;
993
+
994
+ if (!message) {
995
+ generatedMessage = true;
996
+ message = "The input did not match the regular expression " + `${inspect(expected)}. Input:\n\n${inspect(str)}\n`;
997
+ }
998
+ throwError = true;
999
+ // Handle primitives properly.
1000
+ } else if (typeof actual !== "object" || actual === null) {
1001
+ const err = new AssertionError({ actual, expected, message, operator: "deepStrictEqual", stackStartFn: fn, diff: this?.[kOptions]?.diff });
1002
+ err.operator = fn.name;
1003
+ throw err;
1004
+ } else {
1005
+ // Handle validation objects.
1006
+ const keys = Object.keys(expected);
1007
+ // Special handle errors to make sure the name and the message are
1008
+ // compared as well.
1009
+ if (expected instanceof Error) {
1010
+ keys.push("name", "message");
1011
+ } else if (keys.length === 0) {
1012
+ throw invalidArgValue("error", "may not be an empty object", expected);
1013
+ }
1014
+ for (const key of keys) {
1015
+ if (typeof actual[key] === "string" && isRegExp(expected[key]) && expected[key].exec(actual[key]) !== null) {
1016
+ continue;
1017
+ }
1018
+ compareExceptionKey.call(this, actual, expected, key, message, keys, fn);
1019
+ }
1020
+ return;
1021
+ }
1022
+ // Guard instanceof against arrow functions as they don't have a prototype.
1023
+ // Check for matching Error classes.
1024
+ } else if (expected.prototype !== undefined && actual instanceof expected) {
1025
+ return;
1026
+ } else if (Object.prototype.isPrototypeOf.call(Error, expected)) {
1027
+ if (!message) {
1028
+ generatedMessage = true;
1029
+ message = "The error is expected to be an instance of " + `"${expected.name}". Received `;
1030
+ if (isError(actual)) {
1031
+ const name = (actual.constructor?.name) || actual.name;
1032
+ if (expected.name === name) {
1033
+ message += "an error with identical name but a different prototype.";
1034
+ } else {
1035
+ message += `"${name}"`;
1036
+ }
1037
+ if (actual.message) {
1038
+ message += `\n\nError message:\n\n${actual.message}`;
1039
+ }
1040
+ } else {
1041
+ message += `"${inspect(actual, { depth: -1 })}"`;
1042
+ }
1043
+ }
1044
+ throwError = true;
1045
+ } else {
1046
+ // Check validation functions return value.
1047
+ const res = Reflect.apply(expected, {}, [actual]);
1048
+ if (res !== true) {
1049
+ if (!message) {
1050
+ generatedMessage = true;
1051
+ const name = expected.name ? `"${expected.name}" ` : "";
1052
+ message = `The ${name}validation function is expected to return` + ` "true". Received ${inspect(res)}`;
1053
+
1054
+ if (isError(actual)) {
1055
+ message += `\n\nCaught error:\n\n${actual}`;
1056
+ }
1057
+ }
1058
+ throwError = true;
1059
+ }
1060
+ }
1061
+
1062
+ if (throwError) {
1063
+ const err = new AssertionError({ actual, expected, message, operator: fn.name, stackStartFn: fn, diff: this?.[kOptions]?.diff });
1064
+ err.generatedMessage = generatedMessage;
1065
+ throw err;
1066
+ }
1067
+ }
1068
+
1069
+ function getActual(fn) {
1070
+ validateFunction(fn, "fn");
1071
+ try {
1072
+ fn();
1073
+ } catch (e) {
1074
+ return e;
1075
+ }
1076
+ return NO_EXCEPTION_SENTINEL;
1077
+ }
1078
+
1079
+ function checkIsPromise(obj) {
1080
+ // Accept native ES6 promises and promises that are implemented in a similar
1081
+ // way. Do not accept thenables that use a function as `obj` and that have no
1082
+ // `catch` handler.
1083
+ return isPromise(obj) ||
1084
+ (obj !== null && typeof obj === "object" && typeof obj.then === "function" && typeof obj.catch === "function");
1085
+ }
1086
+
1087
+ async function waitForActual(promiseFn) {
1088
+ let resultPromise;
1089
+ if (typeof promiseFn === "function") {
1090
+ // Return a rejected promise if `promiseFn` throws synchronously.
1091
+ resultPromise = promiseFn();
1092
+ // Fail in case no promise is returned.
1093
+ if (!checkIsPromise(resultPromise)) {
1094
+ throw codeError(TypeError, "ERR_INVALID_RETURN_VALUE",
1095
+ `Expected instance of Promise to be returned from the "promiseFn" function but got ${specificType(resultPromise)}.`);
1096
+ }
1097
+ } else if (checkIsPromise(promiseFn)) {
1098
+ resultPromise = promiseFn;
1099
+ } else {
1100
+ throw invalidArgType("promiseFn", describeTypes(["Function", "Promise"]), promiseFn);
1101
+ }
1102
+
1103
+ try {
1104
+ await resultPromise;
1105
+ } catch (e) {
1106
+ return e;
1107
+ }
1108
+ return NO_EXCEPTION_SENTINEL;
1109
+ }
1110
+
1111
+ function expectsError(stackStartFn, actual, error, message) {
1112
+ if (typeof error === "string") {
1113
+ if (arguments.length === 4) {
1114
+ throw invalidArgType("error", describeTypes(["Object", "Error", "Function", "RegExp"]), error);
1115
+ }
1116
+ if (typeof actual === "object" && actual !== null) {
1117
+ if (actual.message === error) {
1118
+ throw codeError(TypeError, "ERR_AMBIGUOUS_ARGUMENT", `The "error/message" argument is ambiguous. The error message "${actual.message}" is identical to the message.`);
1119
+ }
1120
+ } else if (actual === error) {
1121
+ throw codeError(TypeError, "ERR_AMBIGUOUS_ARGUMENT", `The "error/message" argument is ambiguous. The error "${actual}" is identical to the message.`);
1122
+ }
1123
+ message = error;
1124
+ error = undefined;
1125
+ } else if (error != null && typeof error !== "object" && typeof error !== "function") {
1126
+ throw invalidArgType("error", describeTypes(["Object", "Error", "Function", "RegExp"]), error);
1127
+ }
1128
+
1129
+ if (actual === NO_EXCEPTION_SENTINEL) {
1130
+ let details = "";
1131
+ if (error?.name) {
1132
+ details += ` (${error.name})`;
1133
+ }
1134
+ details += message ? `: ${message}` : ".";
1135
+ const fnType = stackStartFn === Assert.prototype.rejects ? "rejection" : "exception";
1136
+ innerFail({
1137
+ actual: undefined,
1138
+ expected: error,
1139
+ operator: stackStartFn.name,
1140
+ message: `Missing expected ${fnType}${details}`,
1141
+ stackStartFn,
1142
+ diff: this?.[kOptions]?.diff,
1143
+ });
1144
+ }
1145
+
1146
+ if (!error) return;
1147
+
1148
+ expectedException.call(this, actual, error, message, stackStartFn);
1149
+ }
1150
+
1151
+ function hasMatchingError(actual, expected) {
1152
+ if (typeof expected !== "function") {
1153
+ if (isRegExp(expected)) {
1154
+ const str = String(actual);
1155
+ return expected.exec(str) !== null;
1156
+ }
1157
+ throw invalidArgType("expected", describeTypes(["Function", "RegExp"]), expected);
1158
+ }
1159
+ // Guard instanceof against arrow functions as they don't have a prototype.
1160
+ if (expected.prototype !== undefined && actual instanceof expected) {
1161
+ return true;
1162
+ }
1163
+ if (Object.prototype.isPrototypeOf.call(Error, expected)) {
1164
+ return false;
1165
+ }
1166
+ return Reflect.apply(expected, {}, [actual]) === true;
1167
+ }
1168
+
1169
+ function expectsNoError(stackStartFn, actual, error, message) {
1170
+ if (actual === NO_EXCEPTION_SENTINEL) return;
1171
+
1172
+ if (typeof error === "string") {
1173
+ message = error;
1174
+ error = undefined;
1175
+ }
1176
+
1177
+ if (!error || hasMatchingError(actual, error)) {
1178
+ const details = message ? `: ${message}` : ".";
1179
+ const fnType = stackStartFn === Assert.prototype.doesNotReject ? "rejection" : "exception";
1180
+ innerFail({
1181
+ actual,
1182
+ expected: error,
1183
+ operator: stackStartFn.name,
1184
+ message: `Got unwanted ${fnType}${details}\n` + `Actual message: "${actual?.message}"`,
1185
+ stackStartFn,
1186
+ diff: this?.[kOptions]?.diff,
1187
+ });
1188
+ }
1189
+ throw actual;
1190
+ }
1191
+
1192
+ /** Expects the function `promiseFn` to throw an error. */
1193
+ Assert.prototype.throws = function throws(promiseFn, ...args) {
1194
+ expectsError.call(this, throws, getActual(promiseFn), ...args);
1195
+ };
1196
+
1197
+ /** Expects `promiseFn` function or its value to reject. */
1198
+ Assert.prototype.rejects = async function rejects(promiseFn, ...args) {
1199
+ expectsError.call(this, rejects, await waitForActual(promiseFn), ...args);
1200
+ };
1201
+
1202
+ /** Asserts that the function `fn` does not throw an error. */
1203
+ Assert.prototype.doesNotThrow = function doesNotThrow(fn, ...args) {
1204
+ expectsNoError.call(this, doesNotThrow, getActual(fn), ...args);
1205
+ };
1206
+
1207
+ /** Expects `fn` or its value to not reject. */
1208
+ Assert.prototype.doesNotReject = async function doesNotReject(fn, ...args) {
1209
+ expectsNoError.call(this, doesNotReject, await waitForActual(fn), ...args);
1210
+ };
1211
+
1212
+ /** Throws `AssertionError` if the value is not `null` or `undefined`. */
1213
+ Assert.prototype.ifError = function ifError(err) {
1214
+ if (err !== null && err !== undefined) {
1215
+ let message = "ifError got unwanted exception: ";
1216
+ if (typeof err === "object" && typeof err.message === "string") {
1217
+ if (err.message.length === 0 && err.constructor) {
1218
+ message += err.constructor.name;
1219
+ } else {
1220
+ message += err.message;
1221
+ }
1222
+ } else {
1223
+ message += inspect(err);
1224
+ }
1225
+
1226
+ const newErr = new AssertionError({ actual: err, expected: null, operator: "ifError", message, stackStartFn: ifError, diff: this?.[kOptions]?.diff });
1227
+
1228
+ // Make sure we actually have a stack trace!
1229
+ const origStack = err.stack;
1230
+
1231
+ if (typeof origStack === "string" && typeof newErr.stack === "string") {
1232
+ // This will remove any duplicated frames from the error frames taken
1233
+ // from within `ifError` and add the original error frames to the newly
1234
+ // created ones.
1235
+ const origStackStart = origStack.indexOf("\n at");
1236
+ if (origStackStart !== -1) {
1237
+ const originalFrames = origStack.slice(origStackStart + 1).split("\n");
1238
+ // Filter all frames existing in err.stack.
1239
+ let newFrames = newErr.stack.split("\n");
1240
+ for (const errFrame of originalFrames) {
1241
+ // Find the first occurrence of the frame.
1242
+ const pos = newFrames.indexOf(errFrame);
1243
+ if (pos !== -1) {
1244
+ // Only keep new frames.
1245
+ newFrames = newFrames.slice(0, pos);
1246
+ break;
1247
+ }
1248
+ }
1249
+ const stackStart = newFrames.join("\n");
1250
+ const stackEnd = originalFrames.join("\n");
1251
+ newErr.stack = `${stackStart}\n${stackEnd}`;
1252
+ }
1253
+ }
1254
+
1255
+ throw newErr;
1256
+ }
1257
+ };
1258
+
1259
+ function internalMatch(string, regexp, message, fn) {
1260
+ if (!isRegExp(regexp)) {
1261
+ throw invalidArgType("regexp", "an instance of RegExp", regexp);
1262
+ }
1263
+ const match = fn === Assert.prototype.match;
1264
+ if (typeof string !== "string" || (regexp.exec(string) !== null) !== match) {
1265
+ if (message instanceof Error) {
1266
+ throw message;
1267
+ }
1268
+
1269
+ const generatedMessage = !message;
1270
+
1271
+ // 'The input was expected to not match the regular expression ' +
1272
+ message ||= (typeof string !== "string" ?
1273
+ 'The "string" argument must be of type string. Received type ' + `${typeof string} (${inspect(string)})` :
1274
+ (match ?
1275
+ "The input did not match the regular expression " :
1276
+ "The input was expected to not match the regular expression ") +
1277
+ `${inspect(regexp)}. Input:\n\n${inspect(string)}\n`);
1278
+ const err = new AssertionError({ actual: string, expected: regexp, message, operator: fn.name, stackStartFn: fn, diff: this?.[kOptions]?.diff });
1279
+ err.generatedMessage = generatedMessage;
1280
+ throw err;
1281
+ }
1282
+ }
1283
+
1284
+ /** Expects the `string` input to match the regular expression. */
1285
+ Assert.prototype.match = function match(string, regexp, message) {
1286
+ internalMatch.call(this, string, regexp, message, match);
1287
+ };
1288
+
1289
+ /** Expects the `string` input not to match the regular expression. */
1290
+ Assert.prototype.doesNotMatch = function doesNotMatch(string, regexp, message) {
1291
+ internalMatch.call(this, string, regexp, message, doesNotMatch);
1292
+ };
1293
+
1294
+ // ---- The module ---------------------------------------------------------------------------
1295
+
1296
+ const assert = ok;
1297
+ assert.AssertionError = AssertionError;
1298
+ const DeprecatedCallTracker = deprecate(CallTracker, "assert.CallTracker is deprecated.", "DEP0173");
1299
+ assert.CallTracker = DeprecatedCallTracker;
1300
+
1301
+ /** A strict-only variant of assert. */
1302
+ function strictAssert(...args) {
1303
+ innerOk(strictAssert, args.length, ...args);
1304
+ }
1305
+
1306
+ assert.ok = assert;
1307
+ for (const name of [
1308
+ "fail", "equal", "notEqual", "deepEqual", "notDeepEqual",
1309
+ "deepStrictEqual", "notDeepStrictEqual", "strictEqual",
1310
+ "notStrictEqual", "partialDeepStrictEqual", "match", "doesNotMatch",
1311
+ "throws", "rejects", "doesNotThrow", "doesNotReject", "ifError",
1312
+ ]) {
1313
+ Object.defineProperty(assert, name, { value: Assert.prototype[name], writable: true, enumerable: true, configurable: true });
1314
+ }
1315
+
1316
+ assert.strict = Object.assign(strictAssert, assert, {
1317
+ equal: assert.strictEqual,
1318
+ deepEqual: assert.deepStrictEqual,
1319
+ notEqual: assert.notStrictEqual,
1320
+ notDeepEqual: assert.notDeepStrictEqual,
1321
+ });
1322
+
1323
+ assert.strict.Assert = Assert;
1324
+ assert.strict.strict = assert.strict;
1325
+
1326
+ assert.Assert = Assert;
1327
+
1328
+ export default assert;
1329
+ export const {
1330
+ fail, equal, notEqual, deepEqual, notDeepEqual, deepStrictEqual, notDeepStrictEqual, strictEqual,
1331
+ notStrictEqual, partialDeepStrictEqual, match, doesNotMatch, throws, rejects, doesNotThrow, doesNotReject,
1332
+ ifError, strict,
1333
+ } = assert;
1334
+ export { ok, DeprecatedCallTracker as CallTracker };