@volter/tabnode 0.2.14-volter.88

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 (429) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +78 -0
  3. package/THIRD-PARTY-NOTICES.md +12 -0
  4. package/dist/__sw__.js +526 -0
  5. package/dist/assets/runtime-worker-4MKaHFVb.js +75221 -0
  6. package/dist/assets/runtime-worker-4MKaHFVb.js.map +1 -0
  7. package/dist/code-transforms.d.ts +21 -0
  8. package/dist/code-transforms.d.ts.map +1 -0
  9. package/dist/config/cdn.d.ts +12 -0
  10. package/dist/config/cdn.d.ts.map +1 -0
  11. package/dist/create-runtime.d.ts +22 -0
  12. package/dist/create-runtime.d.ts.map +1 -0
  13. package/dist/host-globals.d.ts +62 -0
  14. package/dist/host-globals.d.ts.map +1 -0
  15. package/dist/index.cjs +36021 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.ts +127 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.mjs +36020 -0
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/node-internals.d.ts +68 -0
  22. package/dist/node-internals.d.ts.map +1 -0
  23. package/dist/node-lib/binding/blob.d.ts +12 -0
  24. package/dist/node-lib/binding/blob.d.ts.map +1 -0
  25. package/dist/node-lib/binding/buffer.d.ts +144 -0
  26. package/dist/node-lib/binding/buffer.d.ts.map +1 -0
  27. package/dist/node-lib/binding/cares_wrap.d.ts +14 -0
  28. package/dist/node-lib/binding/cares_wrap.d.ts.map +1 -0
  29. package/dist/node-lib/binding/fds.d.ts +30 -0
  30. package/dist/node-lib/binding/fds.d.ts.map +1 -0
  31. package/dist/node-lib/binding/fs.d.ts +157 -0
  32. package/dist/node-lib/binding/fs.d.ts.map +1 -0
  33. package/dist/node-lib/binding/handles.d.ts +81 -0
  34. package/dist/node-lib/binding/handles.d.ts.map +1 -0
  35. package/dist/node-lib/binding/http_parser.d.ts +122 -0
  36. package/dist/node-lib/binding/http_parser.d.ts.map +1 -0
  37. package/dist/node-lib/binding/index.d.ts +3 -0
  38. package/dist/node-lib/binding/index.d.ts.map +1 -0
  39. package/dist/node-lib/binding/llhttp-wasm.d.ts +22 -0
  40. package/dist/node-lib/binding/llhttp-wasm.d.ts.map +1 -0
  41. package/dist/node-lib/binding/misc.d.ts +123 -0
  42. package/dist/node-lib/binding/misc.d.ts.map +1 -0
  43. package/dist/node-lib/binding/pipe_wrap.d.ts +84 -0
  44. package/dist/node-lib/binding/pipe_wrap.d.ts.map +1 -0
  45. package/dist/node-lib/binding/process_wrap.d.ts +173 -0
  46. package/dist/node-lib/binding/process_wrap.d.ts.map +1 -0
  47. package/dist/node-lib/binding/spawn_sync.d.ts +30 -0
  48. package/dist/node-lib/binding/spawn_sync.d.ts.map +1 -0
  49. package/dist/node-lib/binding/stream_wrap.d.ts +191 -0
  50. package/dist/node-lib/binding/stream_wrap.d.ts.map +1 -0
  51. package/dist/node-lib/binding/stubs.d.ts +23 -0
  52. package/dist/node-lib/binding/stubs.d.ts.map +1 -0
  53. package/dist/node-lib/binding/tcp_wrap.d.ts +98 -0
  54. package/dist/node-lib/binding/tcp_wrap.d.ts.map +1 -0
  55. package/dist/node-lib/binding/tty_wrap.d.ts +36 -0
  56. package/dist/node-lib/binding/tty_wrap.d.ts.map +1 -0
  57. package/dist/node-lib/binding/util.d.ts +126 -0
  58. package/dist/node-lib/binding/util.d.ts.map +1 -0
  59. package/dist/node-lib/binding/uv.d.ts +32 -0
  60. package/dist/node-lib/binding/uv.d.ts.map +1 -0
  61. package/dist/node-lib/binding/zlib-pako.d.ts +22 -0
  62. package/dist/node-lib/binding/zlib-pako.d.ts.map +1 -0
  63. package/dist/node-lib/binding/zlib.d.ts +38 -0
  64. package/dist/node-lib/binding/zlib.d.ts.map +1 -0
  65. package/dist/node-lib/buffer-module.d.ts +51 -0
  66. package/dist/node-lib/buffer-module.d.ts.map +1 -0
  67. package/dist/node-lib/child-process-module.d.ts +26 -0
  68. package/dist/node-lib/child-process-module.d.ts.map +1 -0
  69. package/dist/node-lib/events-module.d.ts +58 -0
  70. package/dist/node-lib/events-module.d.ts.map +1 -0
  71. package/dist/node-lib/fs-module.d.ts +5 -0
  72. package/dist/node-lib/fs-module.d.ts.map +1 -0
  73. package/dist/node-lib/http-bridge.d.ts +43 -0
  74. package/dist/node-lib/http-bridge.d.ts.map +1 -0
  75. package/dist/node-lib/http-module.d.ts +35 -0
  76. package/dist/node-lib/http-module.d.ts.map +1 -0
  77. package/dist/node-lib/internals/addresses.d.ts +40 -0
  78. package/dist/node-lib/internals/addresses.d.ts.map +1 -0
  79. package/dist/node-lib/internals/buffer-and-streams.d.ts +96 -0
  80. package/dist/node-lib/internals/buffer-and-streams.d.ts.map +1 -0
  81. package/dist/node-lib/internals/child-process.d.ts +27 -0
  82. package/dist/node-lib/internals/child-process.d.ts.map +1 -0
  83. package/dist/node-lib/internals/events-util.d.ts +83 -0
  84. package/dist/node-lib/internals/events-util.d.ts.map +1 -0
  85. package/dist/node-lib/internals/index.d.ts +2 -0
  86. package/dist/node-lib/internals/index.d.ts.map +1 -0
  87. package/dist/node-lib/internals/modules.d.ts +67 -0
  88. package/dist/node-lib/internals/modules.d.ts.map +1 -0
  89. package/dist/node-lib/internals/readline-access.d.ts +2 -0
  90. package/dist/node-lib/internals/readline-access.d.ts.map +1 -0
  91. package/dist/node-lib/internals/runtime.d.ts +150 -0
  92. package/dist/node-lib/internals/runtime.d.ts.map +1 -0
  93. package/dist/node-lib/internals/util.d.ts +33 -0
  94. package/dist/node-lib/internals/util.d.ts.map +1 -0
  95. package/dist/node-lib/lazy.d.ts +31 -0
  96. package/dist/node-lib/lazy.d.ts.map +1 -0
  97. package/dist/node-lib/load.d.ts +27 -0
  98. package/dist/node-lib/load.d.ts.map +1 -0
  99. package/dist/node-lib/module-hooks.d.ts +89 -0
  100. package/dist/node-lib/module-hooks.d.ts.map +1 -0
  101. package/dist/node-lib/net-module.d.ts +181 -0
  102. package/dist/node-lib/net-module.d.ts.map +1 -0
  103. package/dist/node-lib/node-versions.d.ts +27 -0
  104. package/dist/node-lib/node-versions.d.ts.map +1 -0
  105. package/dist/node-lib/public-modules.d.ts +2 -0
  106. package/dist/node-lib/public-modules.d.ts.map +1 -0
  107. package/dist/node-lib/require-hook.d.ts +15 -0
  108. package/dist/node-lib/require-hook.d.ts.map +1 -0
  109. package/dist/node-lib/small-modules.d.ts +16 -0
  110. package/dist/node-lib/small-modules.d.ts.map +1 -0
  111. package/dist/node-lib/sources.d.ts +4 -0
  112. package/dist/node-lib/sources.d.ts.map +1 -0
  113. package/dist/node-lib/stream-module.d.ts +77 -0
  114. package/dist/node-lib/stream-module.d.ts.map +1 -0
  115. package/dist/node-lib/timers.d.ts +19 -0
  116. package/dist/node-lib/timers.d.ts.map +1 -0
  117. package/dist/node-lib/util-module.d.ts +76 -0
  118. package/dist/node-lib/util-module.d.ts.map +1 -0
  119. package/dist/node-resolution.d.ts +50 -0
  120. package/dist/node-resolution.d.ts.map +1 -0
  121. package/dist/node-resolver.d.ts +7 -0
  122. package/dist/node-resolver.d.ts.map +1 -0
  123. package/dist/npm/index.d.ts +73 -0
  124. package/dist/npm/index.d.ts.map +1 -0
  125. package/dist/npm/registry.d.ts +111 -0
  126. package/dist/npm/registry.d.ts.map +1 -0
  127. package/dist/npm/resolver.d.ts +79 -0
  128. package/dist/npm/resolver.d.ts.map +1 -0
  129. package/dist/npm/tarball.d.ts +28 -0
  130. package/dist/npm/tarball.d.ts.map +1 -0
  131. package/dist/process-tokens.d.ts +77 -0
  132. package/dist/process-tokens.d.ts.map +1 -0
  133. package/dist/punycode-source.d.ts +3 -0
  134. package/dist/punycode-source.d.ts.map +1 -0
  135. package/dist/runtime-interface.d.ts +74 -0
  136. package/dist/runtime-interface.d.ts.map +1 -0
  137. package/dist/runtime.d.ts +144 -0
  138. package/dist/runtime.d.ts.map +1 -0
  139. package/dist/server-bridge.d.ts +147 -0
  140. package/dist/server-bridge.d.ts.map +1 -0
  141. package/dist/shims/async_hooks.d.ts +50 -0
  142. package/dist/shims/async_hooks.d.ts.map +1 -0
  143. package/dist/shims/child_process.d.ts +104 -0
  144. package/dist/shims/child_process.d.ts.map +1 -0
  145. package/dist/shims/cluster.d.ts +52 -0
  146. package/dist/shims/cluster.d.ts.map +1 -0
  147. package/dist/shims/command-line.d.ts +43 -0
  148. package/dist/shims/command-line.d.ts.map +1 -0
  149. package/dist/shims/constants.d.ts +222 -0
  150. package/dist/shims/constants.d.ts.map +1 -0
  151. package/dist/shims/crypto-constants.d.ts +12 -0
  152. package/dist/shims/crypto-constants.d.ts.map +1 -0
  153. package/dist/shims/crypto.d.ts +144 -0
  154. package/dist/shims/crypto.d.ts.map +1 -0
  155. package/dist/shims/dgram.d.ts +34 -0
  156. package/dist/shims/dgram.d.ts.map +1 -0
  157. package/dist/shims/dns.d.ts +91 -0
  158. package/dist/shims/dns.d.ts.map +1 -0
  159. package/dist/shims/domain.d.ts +25 -0
  160. package/dist/shims/domain.d.ts.map +1 -0
  161. package/dist/shims/esbuild.d.ts +205 -0
  162. package/dist/shims/esbuild.d.ts.map +1 -0
  163. package/dist/shims/fs.d.ts +25 -0
  164. package/dist/shims/fs.d.ts.map +1 -0
  165. package/dist/shims/http2.d.ts +81 -0
  166. package/dist/shims/http2.d.ts.map +1 -0
  167. package/dist/shims/inspector.d.ts +25 -0
  168. package/dist/shims/inspector.d.ts.map +1 -0
  169. package/dist/shims/module.d.ts +22 -0
  170. package/dist/shims/module.d.ts.map +1 -0
  171. package/dist/shims/os.d.ts +159 -0
  172. package/dist/shims/os.d.ts.map +1 -0
  173. package/dist/shims/path.d.ts +52 -0
  174. package/dist/shims/path.d.ts.map +1 -0
  175. package/dist/shims/perf_hooks.d.ts +50 -0
  176. package/dist/shims/perf_hooks.d.ts.map +1 -0
  177. package/dist/shims/process.d.ts +226 -0
  178. package/dist/shims/process.d.ts.map +1 -0
  179. package/dist/shims/rollup.d.ts +71 -0
  180. package/dist/shims/rollup.d.ts.map +1 -0
  181. package/dist/shims/string_decoder.d.ts +41 -0
  182. package/dist/shims/string_decoder.d.ts.map +1 -0
  183. package/dist/shims/sync-child.d.ts +64 -0
  184. package/dist/shims/sync-child.d.ts.map +1 -0
  185. package/dist/shims/tls.d.ts +53 -0
  186. package/dist/shims/tls.d.ts.map +1 -0
  187. package/dist/shims/url.d.ts +84 -0
  188. package/dist/shims/url.d.ts.map +1 -0
  189. package/dist/shims/v8.d.ts +73 -0
  190. package/dist/shims/v8.d.ts.map +1 -0
  191. package/dist/shims/vfs-adapter.d.ts +126 -0
  192. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  193. package/dist/shims/vm.d.ts +52 -0
  194. package/dist/shims/vm.d.ts.map +1 -0
  195. package/dist/shims/wasi.d.ts +78 -0
  196. package/dist/shims/wasi.d.ts.map +1 -0
  197. package/dist/shims/worker_threads.d.ts +66 -0
  198. package/dist/shims/worker_threads.d.ts.map +1 -0
  199. package/dist/shims/zlib-constants.d.ts +66 -0
  200. package/dist/shims/zlib-constants.d.ts.map +1 -0
  201. package/dist/shims/zlib.d.ts +102 -0
  202. package/dist/shims/zlib.d.ts.map +1 -0
  203. package/dist/transform.d.ts +24 -0
  204. package/dist/transform.d.ts.map +1 -0
  205. package/dist/types/package-json.d.ts +18 -0
  206. package/dist/types/package-json.d.ts.map +1 -0
  207. package/dist/utils/binary-encoding.d.ts +13 -0
  208. package/dist/utils/binary-encoding.d.ts.map +1 -0
  209. package/dist/utils/glob.d.ts +19 -0
  210. package/dist/utils/glob.d.ts.map +1 -0
  211. package/dist/utils/hash.d.ts +6 -0
  212. package/dist/utils/hash.d.ts.map +1 -0
  213. package/dist/virtual-fs.d.ts +259 -0
  214. package/dist/virtual-fs.d.ts.map +1 -0
  215. package/dist/vite-plugin.cjs +50 -0
  216. package/dist/vite-plugin.cjs.map +1 -0
  217. package/dist/vite-plugin.d.ts +36 -0
  218. package/dist/vite-plugin.d.ts.map +1 -0
  219. package/dist/vite-plugin.mjs +31 -0
  220. package/dist/vite-plugin.mjs.map +1 -0
  221. package/dist/worker/runtime-worker.d.ts +8 -0
  222. package/dist/worker/runtime-worker.d.ts.map +1 -0
  223. package/dist/worker-runtime.d.ts +50 -0
  224. package/dist/worker-runtime.d.ts.map +1 -0
  225. package/package.json +88 -0
  226. package/src/code-transforms.ts +560 -0
  227. package/src/config/cdn.ts +13 -0
  228. package/src/create-runtime.ts +89 -0
  229. package/src/host-globals.ts +121 -0
  230. package/src/index.ts +235 -0
  231. package/src/node-internals.ts +283 -0
  232. package/src/node-lib/LICENSE +47 -0
  233. package/src/node-lib/_http_agent.js +547 -0
  234. package/src/node-lib/_http_client.js +996 -0
  235. package/src/node-lib/_http_common.js +269 -0
  236. package/src/node-lib/_http_incoming.js +453 -0
  237. package/src/node-lib/_http_outgoing.js +1262 -0
  238. package/src/node-lib/_http_server.js +1230 -0
  239. package/src/node-lib/assert/strict.js +3 -0
  240. package/src/node-lib/assert.js +844 -0
  241. package/src/node-lib/binding/blob.ts +35 -0
  242. package/src/node-lib/binding/buffer.ts +465 -0
  243. package/src/node-lib/binding/cares_wrap.ts +57 -0
  244. package/src/node-lib/binding/fds.ts +80 -0
  245. package/src/node-lib/binding/fs.ts +857 -0
  246. package/src/node-lib/binding/handles.ts +187 -0
  247. package/src/node-lib/binding/http_parser.ts +536 -0
  248. package/src/node-lib/binding/index.ts +77 -0
  249. package/src/node-lib/binding/llhttp-wasm.ts +670 -0
  250. package/src/node-lib/binding/misc.ts +252 -0
  251. package/src/node-lib/binding/pipe_wrap.ts +166 -0
  252. package/src/node-lib/binding/process_wrap.ts +371 -0
  253. package/src/node-lib/binding/spawn_sync.ts +141 -0
  254. package/src/node-lib/binding/stream_wrap.ts +413 -0
  255. package/src/node-lib/binding/stubs.ts +19 -0
  256. package/src/node-lib/binding/tcp_wrap.ts +254 -0
  257. package/src/node-lib/binding/tty_wrap.ts +56 -0
  258. package/src/node-lib/binding/util.ts +274 -0
  259. package/src/node-lib/binding/uv.ts +102 -0
  260. package/src/node-lib/binding/zlib-pako.ts +50 -0
  261. package/src/node-lib/binding/zlib.ts +259 -0
  262. package/src/node-lib/buffer-module.ts +70 -0
  263. package/src/node-lib/buffer.js +1373 -0
  264. package/src/node-lib/child-process-module.ts +58 -0
  265. package/src/node-lib/child_process.js +1046 -0
  266. package/src/node-lib/constants.js +41 -0
  267. package/src/node-lib/diagnostics_channel.js +438 -0
  268. package/src/node-lib/events-module.ts +80 -0
  269. package/src/node-lib/events.js +1223 -0
  270. package/src/node-lib/fs-module.ts +43 -0
  271. package/src/node-lib/fs.js +3377 -0
  272. package/src/node-lib/http-bridge.ts +299 -0
  273. package/src/node-lib/http-module.ts +53 -0
  274. package/src/node-lib/http.js +198 -0
  275. package/src/node-lib/https.js +429 -0
  276. package/src/node-lib/internal/assert/assertion_error.js +417 -0
  277. package/src/node-lib/internal/assert/calltracker.js +153 -0
  278. package/src/node-lib/internal/assert/myers_diff.js +177 -0
  279. package/src/node-lib/internal/assert/utils.js +278 -0
  280. package/src/node-lib/internal/buffer.js +1120 -0
  281. package/src/node-lib/internal/child_process/serialization.js +169 -0
  282. package/src/node-lib/internal/child_process.js +1135 -0
  283. package/src/node-lib/internal/constants.js +56 -0
  284. package/src/node-lib/internal/deps/minimatch/index.js +1628 -0
  285. package/src/node-lib/internal/errors.js +1912 -0
  286. package/src/node-lib/internal/events/abort_listener.js +54 -0
  287. package/src/node-lib/internal/events/symbols.js +11 -0
  288. package/src/node-lib/internal/fixed_queue.js +119 -0
  289. package/src/node-lib/internal/freelist.js +30 -0
  290. package/src/node-lib/internal/fs/cp/cp-sync.js +242 -0
  291. package/src/node-lib/internal/fs/cp/cp.js +382 -0
  292. package/src/node-lib/internal/fs/dir.js +369 -0
  293. package/src/node-lib/internal/fs/glob.js +763 -0
  294. package/src/node-lib/internal/fs/promises.js +1312 -0
  295. package/src/node-lib/internal/fs/read/context.js +129 -0
  296. package/src/node-lib/internal/fs/recursive_watch.js +275 -0
  297. package/src/node-lib/internal/fs/rimraf.js +311 -0
  298. package/src/node-lib/internal/fs/streams.js +571 -0
  299. package/src/node-lib/internal/fs/sync_write_stream.js +49 -0
  300. package/src/node-lib/internal/fs/utils.js +987 -0
  301. package/src/node-lib/internal/fs/watchers.js +418 -0
  302. package/src/node-lib/internal/http.js +62 -0
  303. package/src/node-lib/internal/mime.js +389 -0
  304. package/src/node-lib/internal/modules/customization_hooks.js +406 -0
  305. package/src/node-lib/internal/net.js +95 -0
  306. package/src/node-lib/internal/querystring.js +119 -0
  307. package/src/node-lib/internal/readline/callbacks.js +132 -0
  308. package/src/node-lib/internal/readline/emitKeypressEvents.js +99 -0
  309. package/src/node-lib/internal/readline/interface.js +1418 -0
  310. package/src/node-lib/internal/readline/promises.js +144 -0
  311. package/src/node-lib/internal/readline/utils.js +405 -0
  312. package/src/node-lib/internal/socket_list.js +108 -0
  313. package/src/node-lib/internal/stream_base_commons.js +280 -0
  314. package/src/node-lib/internal/streams/add-abort-signal.js +60 -0
  315. package/src/node-lib/internal/streams/compose.js +257 -0
  316. package/src/node-lib/internal/streams/destroy.js +361 -0
  317. package/src/node-lib/internal/streams/duplex.js +203 -0
  318. package/src/node-lib/internal/streams/duplexify.js +379 -0
  319. package/src/node-lib/internal/streams/duplexpair.js +62 -0
  320. package/src/node-lib/internal/streams/end-of-stream.js +331 -0
  321. package/src/node-lib/internal/streams/from.js +208 -0
  322. package/src/node-lib/internal/streams/lazy_transform.js +57 -0
  323. package/src/node-lib/internal/streams/legacy.js +125 -0
  324. package/src/node-lib/internal/streams/operators.js +436 -0
  325. package/src/node-lib/internal/streams/passthrough.js +47 -0
  326. package/src/node-lib/internal/streams/pipeline.js +465 -0
  327. package/src/node-lib/internal/streams/readable.js +1762 -0
  328. package/src/node-lib/internal/streams/state.js +51 -0
  329. package/src/node-lib/internal/streams/transform.js +204 -0
  330. package/src/node-lib/internal/streams/utils.js +363 -0
  331. package/src/node-lib/internal/streams/writable.js +1163 -0
  332. package/src/node-lib/internal/tty.js +260 -0
  333. package/src/node-lib/internal/util/colors.js +40 -0
  334. package/src/node-lib/internal/util/comparisons.js +1028 -0
  335. package/src/node-lib/internal/util/debuglog.js +524 -0
  336. package/src/node-lib/internal/util/inspect.js +2535 -0
  337. package/src/node-lib/internal/util/parse_args/parse_args.js +412 -0
  338. package/src/node-lib/internal/util/parse_args/utils.js +197 -0
  339. package/src/node-lib/internal/util.js +1003 -0
  340. package/src/node-lib/internal/validators.js +654 -0
  341. package/src/node-lib/internals/addresses.ts +159 -0
  342. package/src/node-lib/internals/buffer-and-streams.ts +224 -0
  343. package/src/node-lib/internals/child-process.ts +64 -0
  344. package/src/node-lib/internals/events-util.ts +105 -0
  345. package/src/node-lib/internals/index.ts +66 -0
  346. package/src/node-lib/internals/modules.ts +117 -0
  347. package/src/node-lib/internals/readline-access.ts +16 -0
  348. package/src/node-lib/internals/runtime.ts +277 -0
  349. package/src/node-lib/internals/util.ts +98 -0
  350. package/src/node-lib/lazy.ts +158 -0
  351. package/src/node-lib/load.ts +390 -0
  352. package/src/node-lib/module-hooks.ts +281 -0
  353. package/src/node-lib/net-module.ts +248 -0
  354. package/src/node-lib/net.js +2540 -0
  355. package/src/node-lib/node-versions.ts +34 -0
  356. package/src/node-lib/os.js +356 -0
  357. package/src/node-lib/path.js +1694 -0
  358. package/src/node-lib/primordials.js +743 -0
  359. package/src/node-lib/public-modules.ts +109 -0
  360. package/src/node-lib/punycode.js +455 -0
  361. package/src/node-lib/querystring.js +484 -0
  362. package/src/node-lib/readline/promises.js +73 -0
  363. package/src/node-lib/readline.js +523 -0
  364. package/src/node-lib/require-hook.ts +27 -0
  365. package/src/node-lib/small-modules.ts +35 -0
  366. package/src/node-lib/sources.ts +200 -0
  367. package/src/node-lib/stream/promises.js +44 -0
  368. package/src/node-lib/stream-module.ts +101 -0
  369. package/src/node-lib/stream.js +152 -0
  370. package/src/node-lib/timers.ts +33 -0
  371. package/src/node-lib/tty.js +168 -0
  372. package/src/node-lib/util-module.ts +104 -0
  373. package/src/node-lib/util.js +689 -0
  374. package/src/node-lib/wasi.js +179 -0
  375. package/src/node-lib/zlib.js +1036 -0
  376. package/src/node-resolution.ts +241 -0
  377. package/src/node-resolver.ts +33 -0
  378. package/src/npm/index.ts +425 -0
  379. package/src/npm/registry.ts +235 -0
  380. package/src/npm/resolver.ts +589 -0
  381. package/src/npm/tarball.ts +246 -0
  382. package/src/process-tokens.ts +156 -0
  383. package/src/punycode-source.ts +6 -0
  384. package/src/runtime-interface.ts +85 -0
  385. package/src/runtime.ts +3073 -0
  386. package/src/server-bridge.ts +971 -0
  387. package/src/shims/async_hooks.ts +181 -0
  388. package/src/shims/child_process.ts +1591 -0
  389. package/src/shims/cluster.ts +79 -0
  390. package/src/shims/command-line.ts +79 -0
  391. package/src/shims/constants.ts +68 -0
  392. package/src/shims/crypto-constants.ts +11 -0
  393. package/src/shims/crypto.ts +1061 -0
  394. package/src/shims/dgram.ts +47 -0
  395. package/src/shims/dns.ts +185 -0
  396. package/src/shims/domain.ts +58 -0
  397. package/src/shims/esbuild.ts +1638 -0
  398. package/src/shims/fs.ts +82 -0
  399. package/src/shims/http2.ts +96 -0
  400. package/src/shims/inspector.ts +30 -0
  401. package/src/shims/module.ts +86 -0
  402. package/src/shims/os.ts +195 -0
  403. package/src/shims/path.ts +246 -0
  404. package/src/shims/perf_hooks.ts +92 -0
  405. package/src/shims/process.ts +804 -0
  406. package/src/shims/rollup.ts +149 -0
  407. package/src/shims/string_decoder.ts +396 -0
  408. package/src/shims/sync-child.ts +469 -0
  409. package/src/shims/tls.ts +94 -0
  410. package/src/shims/url.ts +217 -0
  411. package/src/shims/v8.ts +113 -0
  412. package/src/shims/vfs-adapter.ts +408 -0
  413. package/src/shims/vm.ts +132 -0
  414. package/src/shims/wasi.ts +1440 -0
  415. package/src/shims/worker_threads.ts +114 -0
  416. package/src/shims/zlib-constants.ts +65 -0
  417. package/src/shims/zlib.ts +228 -0
  418. package/src/transform.ts +324 -0
  419. package/src/types/external.d.ts +55 -0
  420. package/src/types/package-json.ts +17 -0
  421. package/src/types/pako-zlib.d.ts +30 -0
  422. package/src/types/sha.js.d.ts +14 -0
  423. package/src/utils/binary-encoding.ts +43 -0
  424. package/src/utils/glob.ts +54 -0
  425. package/src/utils/hash.ts +12 -0
  426. package/src/virtual-fs.ts +1048 -0
  427. package/src/vite-plugin.ts +76 -0
  428. package/src/worker/runtime-worker.ts +128 -0
  429. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,743 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable node-core/prefer-primordials */
4
+
5
+ // This file subclasses and stores the JS builtins that come from the VM
6
+ // so that Node.js's builtin modules do not need to later look these up from
7
+ // the global proxy, which can be mutated by users.
8
+
9
+ // Use of primordials have sometimes a dramatic impact on performance, please
10
+ // benchmark all changes made in performance-sensitive areas of the codebase.
11
+ // See: https://github.com/nodejs/node/pull/38248
12
+
13
+ const {
14
+ defineProperty: ReflectDefineProperty,
15
+ getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
16
+ ownKeys: ReflectOwnKeys,
17
+ } = Reflect;
18
+
19
+ // `uncurryThis` is equivalent to `func => Function.prototype.call.bind(func)`.
20
+ // It is using `bind.bind(call)` to avoid using `Function.prototype.bind`
21
+ // and `Function.prototype.call` after it may have been mutated by users.
22
+ const { apply, bind, call } = Function.prototype;
23
+ const uncurryThis = bind.bind(call);
24
+ primordials.uncurryThis = uncurryThis;
25
+
26
+ // `applyBind` is equivalent to `func => Function.prototype.apply.bind(func)`.
27
+ // It is using `bind.bind(apply)` to avoid using `Function.prototype.bind`
28
+ // and `Function.prototype.apply` after it may have been mutated by users.
29
+ const applyBind = bind.bind(apply);
30
+ primordials.applyBind = applyBind;
31
+
32
+ // Methods that accept a variable number of arguments, and thus it's useful to
33
+ // also create `${prefix}${key}Apply`, which uses `Function.prototype.apply`,
34
+ // instead of `Function.prototype.call`, and thus doesn't require iterator
35
+ // destructuring.
36
+ const varargsMethods = [
37
+ // 'ArrayPrototypeConcat' is omitted, because it performs the spread
38
+ // on its own for arrays and array-likes with a truthy
39
+ // @@isConcatSpreadable symbol property.
40
+ 'ArrayOf',
41
+ 'ArrayPrototypePush',
42
+ 'ArrayPrototypeUnshift',
43
+ // 'FunctionPrototypeCall' is omitted, since there's 'ReflectApply'
44
+ // and 'FunctionPrototypeApply'.
45
+ 'MathHypot',
46
+ 'MathMax',
47
+ 'MathMin',
48
+ 'StringFromCharCode',
49
+ 'StringFromCodePoint',
50
+ 'StringPrototypeConcat',
51
+ 'TypedArrayOf',
52
+ ];
53
+
54
+ function getNewKey(key) {
55
+ return typeof key === 'symbol' ?
56
+ `Symbol${key.description[7].toUpperCase()}${key.description.slice(8)}` :
57
+ `${key[0].toUpperCase()}${key.slice(1)}`;
58
+ }
59
+
60
+ function copyAccessor(dest, prefix, key, { enumerable, get, set }) {
61
+ ReflectDefineProperty(dest, `${prefix}Get${key}`, {
62
+ __proto__: null,
63
+ value: uncurryThis(get),
64
+ enumerable,
65
+ });
66
+ if (set !== undefined) {
67
+ ReflectDefineProperty(dest, `${prefix}Set${key}`, {
68
+ __proto__: null,
69
+ value: uncurryThis(set),
70
+ enumerable,
71
+ });
72
+ }
73
+ }
74
+
75
+ function copyPropsRenamed(src, dest, prefix) {
76
+ for (const key of ReflectOwnKeys(src)) {
77
+ const newKey = getNewKey(key);
78
+ const desc = ReflectGetOwnPropertyDescriptor(src, key);
79
+ if ('get' in desc) {
80
+ copyAccessor(dest, prefix, newKey, desc);
81
+ } else {
82
+ const name = `${prefix}${newKey}`;
83
+ ReflectDefineProperty(dest, name, { __proto__: null, ...desc });
84
+ if (varargsMethods.includes(name)) {
85
+ ReflectDefineProperty(dest, `${name}Apply`, {
86
+ __proto__: null,
87
+ // `src` is bound as the `this` so that the static `this` points
88
+ // to the object it was defined on,
89
+ // e.g.: `ArrayOfApply` gets a `this` of `Array`:
90
+ value: applyBind(desc.value, src),
91
+ });
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ function copyPropsRenamedBound(src, dest, prefix) {
98
+ for (const key of ReflectOwnKeys(src)) {
99
+ const newKey = getNewKey(key);
100
+ const desc = ReflectGetOwnPropertyDescriptor(src, key);
101
+ if ('get' in desc) {
102
+ copyAccessor(dest, prefix, newKey, desc);
103
+ } else {
104
+ const { value } = desc;
105
+ if (typeof value === 'function') {
106
+ desc.value = value.bind(src);
107
+ }
108
+
109
+ const name = `${prefix}${newKey}`;
110
+ ReflectDefineProperty(dest, name, { __proto__: null, ...desc });
111
+ if (varargsMethods.includes(name)) {
112
+ ReflectDefineProperty(dest, `${name}Apply`, {
113
+ __proto__: null,
114
+ value: applyBind(value, src),
115
+ });
116
+ }
117
+ }
118
+ }
119
+ }
120
+
121
+ function copyPrototype(src, dest, prefix) {
122
+ for (const key of ReflectOwnKeys(src)) {
123
+ const newKey = getNewKey(key);
124
+ const desc = ReflectGetOwnPropertyDescriptor(src, key);
125
+ if ('get' in desc) {
126
+ copyAccessor(dest, prefix, newKey, desc);
127
+ } else {
128
+ const { value } = desc;
129
+ if (typeof value === 'function') {
130
+ desc.value = uncurryThis(value);
131
+ }
132
+
133
+ const name = `${prefix}${newKey}`;
134
+ ReflectDefineProperty(dest, name, { __proto__: null, ...desc });
135
+ if (varargsMethods.includes(name)) {
136
+ ReflectDefineProperty(dest, `${name}Apply`, {
137
+ __proto__: null,
138
+ value: applyBind(value),
139
+ });
140
+ }
141
+ }
142
+ }
143
+ }
144
+
145
+ // Create copies of configurable value properties of the global object
146
+ [
147
+ 'Proxy',
148
+ 'globalThis',
149
+ ].forEach((name) => {
150
+ // eslint-disable-next-line no-restricted-globals
151
+ primordials[name] = globalThis[name];
152
+ });
153
+
154
+ // Create copies of URI handling functions
155
+ [
156
+ decodeURI,
157
+ decodeURIComponent,
158
+ encodeURI,
159
+ encodeURIComponent,
160
+ ].forEach((fn) => {
161
+ primordials[fn.name] = fn;
162
+ });
163
+
164
+ // Create copies of legacy functions
165
+ [
166
+ escape,
167
+ eval,
168
+ unescape,
169
+ ].forEach((fn) => {
170
+ primordials[fn.name] = fn;
171
+ });
172
+
173
+ // Create copies of the namespace objects
174
+ [
175
+ 'Atomics',
176
+ 'JSON',
177
+ 'Math',
178
+ 'Proxy',
179
+ 'Reflect',
180
+ ].forEach((name) => {
181
+ // eslint-disable-next-line no-restricted-globals
182
+ copyPropsRenamed(globalThis[name], primordials, name);
183
+ });
184
+
185
+ // Create copies of intrinsic objects
186
+ [
187
+ 'AggregateError',
188
+ 'Array',
189
+ 'ArrayBuffer',
190
+ 'BigInt',
191
+ 'BigInt64Array',
192
+ 'BigUint64Array',
193
+ 'Boolean',
194
+ 'DataView',
195
+ 'Date',
196
+ 'Error',
197
+ 'EvalError',
198
+ 'FinalizationRegistry',
199
+ 'Float32Array',
200
+ 'Float64Array',
201
+ 'Function',
202
+ 'Int16Array',
203
+ 'Int32Array',
204
+ 'Int8Array',
205
+ 'Map',
206
+ 'Number',
207
+ 'Object',
208
+ 'RangeError',
209
+ 'ReferenceError',
210
+ 'RegExp',
211
+ 'Set',
212
+ 'String',
213
+ 'Symbol',
214
+ 'SyntaxError',
215
+ 'TypeError',
216
+ 'URIError',
217
+ 'Uint16Array',
218
+ 'Uint32Array',
219
+ 'Uint8Array',
220
+ 'Uint8ClampedArray',
221
+ 'WeakMap',
222
+ 'WeakRef',
223
+ 'WeakSet',
224
+ ].forEach((name) => {
225
+ // eslint-disable-next-line no-restricted-globals
226
+ const original = globalThis[name];
227
+ primordials[name] = original;
228
+ copyPropsRenamed(original, primordials, name);
229
+ copyPrototype(original.prototype, primordials, `${name}Prototype`);
230
+ });
231
+
232
+
233
+ // Create copies of intrinsic objects that require a valid `this` to call
234
+ // static methods.
235
+ // Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all
236
+ [
237
+ 'Promise',
238
+ ].forEach((name) => {
239
+ // eslint-disable-next-line no-restricted-globals
240
+ const original = globalThis[name];
241
+ primordials[name] = original;
242
+ copyPropsRenamedBound(original, primordials, name);
243
+ copyPrototype(original.prototype, primordials, `${name}Prototype`);
244
+ });
245
+
246
+ // Create copies of abstract intrinsic objects that are not directly exposed
247
+ // on the global object.
248
+ // Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object
249
+ [
250
+ { name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) },
251
+ { name: 'ArrayIterator', original: {
252
+ prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()),
253
+ } },
254
+ { name: 'StringIterator', original: {
255
+ prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()),
256
+ } },
257
+ ].forEach(({ name, original }) => {
258
+ primordials[name] = original;
259
+ // The static %TypedArray% methods require a valid `this`, but can't be bound,
260
+ // as they need a subclass constructor as the receiver:
261
+ copyPrototype(original, primordials, name);
262
+ copyPrototype(original.prototype, primordials, `${name}Prototype`);
263
+ });
264
+
265
+ primordials.IteratorPrototype = Reflect.getPrototypeOf(primordials.ArrayIteratorPrototype);
266
+
267
+ /* eslint-enable node-core/prefer-primordials */
268
+
269
+ const {
270
+ Array: ArrayConstructor,
271
+ ArrayPrototypeForEach,
272
+ ArrayPrototypeMap,
273
+ FinalizationRegistry,
274
+ FunctionPrototypeCall,
275
+ Map,
276
+ ObjectDefineProperties,
277
+ ObjectDefineProperty,
278
+ ObjectFreeze,
279
+ ObjectSetPrototypeOf,
280
+ Promise,
281
+ PromisePrototypeThen,
282
+ PromiseResolve,
283
+ ReflectApply,
284
+ ReflectConstruct,
285
+ ReflectGet,
286
+ ReflectSet,
287
+ RegExp,
288
+ RegExpPrototype,
289
+ RegExpPrototypeExec,
290
+ RegExpPrototypeGetDotAll,
291
+ RegExpPrototypeGetFlags,
292
+ RegExpPrototypeGetGlobal,
293
+ RegExpPrototypeGetHasIndices,
294
+ RegExpPrototypeGetIgnoreCase,
295
+ RegExpPrototypeGetMultiline,
296
+ RegExpPrototypeGetSource,
297
+ RegExpPrototypeGetSticky,
298
+ RegExpPrototypeGetUnicode,
299
+ Set,
300
+ SymbolIterator,
301
+ SymbolMatch,
302
+ SymbolMatchAll,
303
+ SymbolReplace,
304
+ SymbolSearch,
305
+ SymbolSpecies,
306
+ SymbolSplit,
307
+ WeakMap,
308
+ WeakRef,
309
+ WeakSet,
310
+ } = primordials;
311
+
312
+
313
+ /**
314
+ * Creates a class that can be safely iterated over.
315
+ *
316
+ * Because these functions are used by `makeSafe`, which is exposed on the
317
+ * `primordials` object, it's important to use const references to the
318
+ * primordials that they use.
319
+ * @template {Iterable} T
320
+ * @template {*} TReturn
321
+ * @template {*} TNext
322
+ * @param {(self: T) => IterableIterator<T>} factory
323
+ * @param {(...args: [] | [TNext]) => IteratorResult<T, TReturn>} next
324
+ * @returns {Iterator<T, TReturn, TNext>}
325
+ */
326
+ const createSafeIterator = (factory, next) => {
327
+ class SafeIterator {
328
+ constructor(iterable) {
329
+ this._iterator = factory(iterable);
330
+ }
331
+ next() {
332
+ return next(this._iterator);
333
+ }
334
+ [SymbolIterator]() {
335
+ return this;
336
+ }
337
+ }
338
+ ObjectSetPrototypeOf(SafeIterator.prototype, null);
339
+ ObjectFreeze(SafeIterator.prototype);
340
+ ObjectFreeze(SafeIterator);
341
+ return SafeIterator;
342
+ };
343
+
344
+ primordials.SafeArrayIterator = createSafeIterator(
345
+ primordials.ArrayPrototypeSymbolIterator,
346
+ primordials.ArrayIteratorPrototypeNext,
347
+ );
348
+ primordials.SafeStringIterator = createSafeIterator(
349
+ primordials.StringPrototypeSymbolIterator,
350
+ primordials.StringIteratorPrototypeNext,
351
+ );
352
+
353
+ const copyProps = (src, dest) => {
354
+ ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => {
355
+ if (!ReflectGetOwnPropertyDescriptor(dest, key)) {
356
+ ReflectDefineProperty(
357
+ dest,
358
+ key,
359
+ { __proto__: null, ...ReflectGetOwnPropertyDescriptor(src, key) });
360
+ }
361
+ });
362
+ };
363
+
364
+ /**
365
+ * @type {typeof primordials.makeSafe}
366
+ */
367
+ const makeSafe = (unsafe, safe) => {
368
+ if (SymbolIterator in unsafe.prototype) {
369
+ const dummy = new unsafe();
370
+ let next; // We can reuse the same `next` method.
371
+
372
+ ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => {
373
+ if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) {
374
+ const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key);
375
+ if (
376
+ typeof desc.value === 'function' &&
377
+ desc.value.length === 0 &&
378
+ SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {})
379
+ ) {
380
+ const createIterator = uncurryThis(desc.value);
381
+ next ??= uncurryThis(createIterator(dummy).next);
382
+ const SafeIterator = createSafeIterator(createIterator, next);
383
+ desc.value = function() {
384
+ return new SafeIterator(this);
385
+ };
386
+ }
387
+ ReflectDefineProperty(safe.prototype, key, { __proto__: null, ...desc });
388
+ }
389
+ });
390
+ } else {
391
+ copyProps(unsafe.prototype, safe.prototype);
392
+ }
393
+ copyProps(unsafe, safe);
394
+
395
+ ObjectSetPrototypeOf(safe.prototype, null);
396
+ ObjectFreeze(safe.prototype);
397
+ ObjectFreeze(safe);
398
+ return safe;
399
+ };
400
+ primordials.makeSafe = makeSafe;
401
+
402
+ // Subclass the constructors because we need to use their prototype
403
+ // methods later.
404
+ // Defining the `constructor` is necessary here to avoid the default
405
+ // constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`.
406
+ primordials.SafeMap = makeSafe(
407
+ Map,
408
+ class SafeMap extends Map {
409
+ constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
410
+ },
411
+ );
412
+ primordials.SafeWeakMap = makeSafe(
413
+ WeakMap,
414
+ class SafeWeakMap extends WeakMap {
415
+ constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
416
+ },
417
+ );
418
+
419
+ primordials.SafeSet = makeSafe(
420
+ Set,
421
+ class SafeSet extends Set {
422
+ constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
423
+ },
424
+ );
425
+ primordials.SafeWeakSet = makeSafe(
426
+ WeakSet,
427
+ class SafeWeakSet extends WeakSet {
428
+ constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
429
+ },
430
+ );
431
+
432
+ primordials.SafeFinalizationRegistry = makeSafe(
433
+ FinalizationRegistry,
434
+ class SafeFinalizationRegistry extends FinalizationRegistry {
435
+ // eslint-disable-next-line no-useless-constructor
436
+ constructor(cleanupCallback) { super(cleanupCallback); }
437
+ },
438
+ );
439
+ primordials.SafeWeakRef = makeSafe(
440
+ WeakRef,
441
+ class SafeWeakRef extends WeakRef {
442
+ // eslint-disable-next-line no-useless-constructor
443
+ constructor(target) { super(target); }
444
+ },
445
+ );
446
+
447
+ const SafePromise = makeSafe(
448
+ Promise,
449
+ class SafePromise extends Promise {
450
+ // eslint-disable-next-line no-useless-constructor
451
+ constructor(executor) { super(executor); }
452
+ },
453
+ );
454
+
455
+ /**
456
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or
457
+ * rejected). The resolved value cannot be modified from the callback.
458
+ * Prefer using async functions when possible.
459
+ * @param {Promise<any>} thisPromise
460
+ * @param {(() => void) | undefined | null} onFinally The callback to execute
461
+ * when the Promise is settled (fulfilled or rejected).
462
+ * @returns {Promise} A Promise for the completion of the callback.
463
+ */
464
+ primordials.SafePromisePrototypeFinally = (thisPromise, onFinally) =>
465
+ // Wrapping on a new Promise is necessary to not expose the SafePromise
466
+ // prototype to user-land.
467
+ new Promise((a, b) =>
468
+ new SafePromise((a, b) => PromisePrototypeThen(thisPromise, a, b))
469
+ .finally(onFinally)
470
+ .then(a, b),
471
+ );
472
+
473
+ primordials.AsyncIteratorPrototype =
474
+ primordials.ReflectGetPrototypeOf(
475
+ primordials.ReflectGetPrototypeOf(
476
+ async function* () {}).prototype);
477
+
478
+ const arrayToSafePromiseIterable = (promises, mapFn) =>
479
+ new primordials.SafeArrayIterator(
480
+ ArrayPrototypeMap(
481
+ promises,
482
+ (promise, i) =>
483
+ new SafePromise((a, b) => PromisePrototypeThen(mapFn == null ? promise : mapFn(promise, i), a, b)),
484
+ ),
485
+ );
486
+
487
+ /**
488
+ * @template T,U
489
+ * @param {Array<T | PromiseLike<T>>} promises
490
+ * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]
491
+ * @returns {Promise<Awaited<U>[]>}
492
+ */
493
+ primordials.SafePromiseAll = (promises, mapFn) =>
494
+ // Wrapping on a new Promise is necessary to not expose the SafePromise
495
+ // prototype to user-land.
496
+ new Promise((a, b) =>
497
+ SafePromise.all(arrayToSafePromiseIterable(promises, mapFn)).then(a, b),
498
+ );
499
+
500
+ /**
501
+ * Should only be used for internal functions, this would produce similar
502
+ * results as `Promise.all` but without prototype pollution, and the return
503
+ * value is not a genuine Array but an array-like object.
504
+ * @template T,U
505
+ * @param {ArrayLike<T | PromiseLike<T>>} promises
506
+ * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]
507
+ * @returns {Promise<ArrayLike<Awaited<U>>>}
508
+ */
509
+ primordials.SafePromiseAllReturnArrayLike = (promises, mapFn) =>
510
+ new Promise((resolve, reject) => {
511
+ const { length } = promises;
512
+
513
+ const returnVal = ArrayConstructor(length);
514
+ ObjectSetPrototypeOf(returnVal, null);
515
+ if (length === 0) resolve(returnVal);
516
+
517
+ let pendingPromises = length;
518
+ for (let i = 0; i < length; i++) {
519
+ const promise = mapFn != null ? mapFn(promises[i], i) : promises[i];
520
+ PromisePrototypeThen(PromiseResolve(promise), (result) => {
521
+ returnVal[i] = result;
522
+ if (--pendingPromises === 0) resolve(returnVal);
523
+ }, reject);
524
+ }
525
+ });
526
+
527
+ /**
528
+ * Should only be used when we only care about waiting for all the promises to
529
+ * resolve, not what value they resolve to.
530
+ * @template T,U
531
+ * @param {ArrayLike<T | PromiseLike<T>>} promises
532
+ * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]
533
+ * @returns {Promise<void>}
534
+ */
535
+ primordials.SafePromiseAllReturnVoid = (promises, mapFn) =>
536
+ new Promise((resolve, reject) => {
537
+ let pendingPromises = promises.length;
538
+ if (pendingPromises === 0) resolve();
539
+ const onFulfilled = () => {
540
+ if (--pendingPromises === 0) {
541
+ resolve();
542
+ }
543
+ };
544
+ for (let i = 0; i < promises.length; i++) {
545
+ const promise = mapFn != null ? mapFn(promises[i], i) : promises[i];
546
+ PromisePrototypeThen(PromiseResolve(promise), onFulfilled, reject);
547
+ }
548
+ });
549
+
550
+ /**
551
+ * @template T,U
552
+ * @param {Array<T|PromiseLike<T>>} promises
553
+ * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]
554
+ * @returns {Promise<PromiseSettledResult<any>[]>}
555
+ */
556
+ primordials.SafePromiseAllSettled = (promises, mapFn) =>
557
+ // Wrapping on a new Promise is necessary to not expose the SafePromise
558
+ // prototype to user-land.
559
+ new Promise((a, b) =>
560
+ SafePromise.allSettled(arrayToSafePromiseIterable(promises, mapFn)).then(a, b),
561
+ );
562
+
563
+ /**
564
+ * Should only be used when we only care about waiting for all the promises to
565
+ * settle, not what value they resolve or reject to.
566
+ * @template T,U
567
+ * @param {ArrayLike<T|PromiseLike<T>>} promises
568
+ * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]
569
+ * @returns {Promise<void>}
570
+ */
571
+ primordials.SafePromiseAllSettledReturnVoid = (promises, mapFn) => new Promise((resolve) => {
572
+ let pendingPromises = promises.length;
573
+ if (pendingPromises === 0) resolve();
574
+ const onSettle = () => {
575
+ if (--pendingPromises === 0) resolve();
576
+ };
577
+ for (let i = 0; i < promises.length; i++) {
578
+ const promise = mapFn != null ? mapFn(promises[i], i) : promises[i];
579
+ PromisePrototypeThen(PromiseResolve(promise), onSettle, onSettle);
580
+ }
581
+ });
582
+
583
+ /**
584
+ * @template T,U
585
+ * @param {Array<T|PromiseLike<T>>} promises
586
+ * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]
587
+ * @returns {Promise<Awaited<U>>}
588
+ */
589
+ primordials.SafePromiseAny = (promises, mapFn) =>
590
+ // Wrapping on a new Promise is necessary to not expose the SafePromise
591
+ // prototype to user-land.
592
+ new Promise((a, b) =>
593
+ SafePromise.any(arrayToSafePromiseIterable(promises, mapFn)).then(a, b),
594
+ );
595
+
596
+ /**
597
+ * @template T,U
598
+ * @param {Array<T|PromiseLike<T>>} promises
599
+ * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]
600
+ * @returns {Promise<Awaited<U>>}
601
+ */
602
+ primordials.SafePromiseRace = (promises, mapFn) =>
603
+ // Wrapping on a new Promise is necessary to not expose the SafePromise
604
+ // prototype to user-land.
605
+ new Promise((a, b) =>
606
+ SafePromise.race(arrayToSafePromiseIterable(promises, mapFn)).then(a, b),
607
+ );
608
+
609
+
610
+ const {
611
+ exec: OriginalRegExpPrototypeExec,
612
+ [SymbolMatch]: OriginalRegExpPrototypeSymbolMatch,
613
+ [SymbolMatchAll]: OriginalRegExpPrototypeSymbolMatchAll,
614
+ [SymbolReplace]: OriginalRegExpPrototypeSymbolReplace,
615
+ [SymbolSearch]: OriginalRegExpPrototypeSymbolSearch,
616
+ [SymbolSplit]: OriginalRegExpPrototypeSymbolSplit,
617
+ } = RegExpPrototype;
618
+
619
+ class RegExpLikeForStringSplitting {
620
+ #regex;
621
+ constructor() {
622
+ this.#regex = ReflectConstruct(RegExp, arguments);
623
+ }
624
+
625
+ get lastIndex() {
626
+ return ReflectGet(this.#regex, 'lastIndex');
627
+ }
628
+ set lastIndex(value) {
629
+ ReflectSet(this.#regex, 'lastIndex', value);
630
+ }
631
+
632
+ exec() {
633
+ return ReflectApply(OriginalRegExpPrototypeExec, this.#regex, arguments);
634
+ }
635
+ }
636
+ ObjectSetPrototypeOf(RegExpLikeForStringSplitting.prototype, null);
637
+
638
+ /**
639
+ * @param {RegExp} pattern
640
+ * @returns {RegExp}
641
+ */
642
+ primordials.hardenRegExp = function hardenRegExp(pattern) {
643
+ ObjectDefineProperties(pattern, {
644
+ [SymbolMatch]: {
645
+ __proto__: null,
646
+ configurable: true,
647
+ value: OriginalRegExpPrototypeSymbolMatch,
648
+ },
649
+ [SymbolMatchAll]: {
650
+ __proto__: null,
651
+ configurable: true,
652
+ value: OriginalRegExpPrototypeSymbolMatchAll,
653
+ },
654
+ [SymbolReplace]: {
655
+ __proto__: null,
656
+ configurable: true,
657
+ value: OriginalRegExpPrototypeSymbolReplace,
658
+ },
659
+ [SymbolSearch]: {
660
+ __proto__: null,
661
+ configurable: true,
662
+ value: OriginalRegExpPrototypeSymbolSearch,
663
+ },
664
+ [SymbolSplit]: {
665
+ __proto__: null,
666
+ configurable: true,
667
+ value: OriginalRegExpPrototypeSymbolSplit,
668
+ },
669
+ constructor: {
670
+ __proto__: null,
671
+ configurable: true,
672
+ value: {
673
+ [SymbolSpecies]: RegExpLikeForStringSplitting,
674
+ },
675
+ },
676
+ dotAll: {
677
+ __proto__: null,
678
+ configurable: true,
679
+ value: RegExpPrototypeGetDotAll(pattern),
680
+ },
681
+ exec: {
682
+ __proto__: null,
683
+ configurable: true,
684
+ value: OriginalRegExpPrototypeExec,
685
+ },
686
+ global: {
687
+ __proto__: null,
688
+ configurable: true,
689
+ value: RegExpPrototypeGetGlobal(pattern),
690
+ },
691
+ hasIndices: {
692
+ __proto__: null,
693
+ configurable: true,
694
+ value: RegExpPrototypeGetHasIndices(pattern),
695
+ },
696
+ ignoreCase: {
697
+ __proto__: null,
698
+ configurable: true,
699
+ value: RegExpPrototypeGetIgnoreCase(pattern),
700
+ },
701
+ multiline: {
702
+ __proto__: null,
703
+ configurable: true,
704
+ value: RegExpPrototypeGetMultiline(pattern),
705
+ },
706
+ source: {
707
+ __proto__: null,
708
+ configurable: true,
709
+ value: RegExpPrototypeGetSource(pattern),
710
+ },
711
+ sticky: {
712
+ __proto__: null,
713
+ configurable: true,
714
+ value: RegExpPrototypeGetSticky(pattern),
715
+ },
716
+ unicode: {
717
+ __proto__: null,
718
+ configurable: true,
719
+ value: RegExpPrototypeGetUnicode(pattern),
720
+ },
721
+ });
722
+ ObjectDefineProperty(pattern, 'flags', {
723
+ __proto__: null,
724
+ configurable: true,
725
+ value: RegExpPrototypeGetFlags(pattern),
726
+ });
727
+ return pattern;
728
+ };
729
+
730
+
731
+ /**
732
+ * @param {string} str
733
+ * @param {RegExp} regexp
734
+ * @returns {number}
735
+ */
736
+ primordials.SafeStringPrototypeSearch = (str, regexp) => {
737
+ regexp.lastIndex = 0;
738
+ const match = RegExpPrototypeExec(regexp, str);
739
+ return match ? match.index : -1;
740
+ };
741
+
742
+ ObjectSetPrototypeOf(primordials, null);
743
+ ObjectFreeze(primordials);