@ricsam/isolate 0.0.1 → 0.1.1

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 (299) hide show
  1. package/README.md +243 -34
  2. package/dist/cjs/bridge/diagnostics.cjs +58 -0
  3. package/dist/cjs/bridge/diagnostics.cjs.map +10 -0
  4. package/dist/cjs/bridge/legacy-adapters.cjs +242 -0
  5. package/dist/cjs/bridge/legacy-adapters.cjs.map +10 -0
  6. package/dist/cjs/bridge/request-context.cjs +59 -0
  7. package/dist/cjs/bridge/request-context.cjs.map +10 -0
  8. package/dist/cjs/bridge/runtime-bindings.cjs +367 -0
  9. package/dist/cjs/bridge/runtime-bindings.cjs.map +10 -0
  10. package/dist/cjs/browser/browser-runtime.cjs +157 -0
  11. package/dist/cjs/browser/browser-runtime.cjs.map +10 -0
  12. package/dist/cjs/daemon.cjs +91 -0
  13. package/dist/cjs/daemon.cjs.map +10 -0
  14. package/dist/cjs/files/index.cjs +140 -0
  15. package/dist/cjs/files/index.cjs.map +10 -0
  16. package/dist/cjs/host/create-isolate-host.cjs +235 -0
  17. package/dist/cjs/host/create-isolate-host.cjs.map +10 -0
  18. package/dist/cjs/host/index.cjs +47 -0
  19. package/dist/cjs/host/index.cjs.map +10 -0
  20. package/dist/cjs/index.cjs +55 -0
  21. package/dist/cjs/index.cjs.map +10 -0
  22. package/dist/cjs/internal/client/connection.cjs +1919 -0
  23. package/dist/cjs/internal/client/connection.cjs.map +10 -0
  24. package/dist/cjs/internal/client/index.cjs +48 -0
  25. package/dist/cjs/internal/client/index.cjs.map +10 -0
  26. package/dist/cjs/internal/client/types.cjs +30 -0
  27. package/dist/cjs/internal/client/types.cjs.map +9 -0
  28. package/dist/cjs/internal/console/index.cjs +506 -0
  29. package/dist/cjs/internal/console/index.cjs.map +10 -0
  30. package/dist/cjs/internal/console/utils.cjs +70 -0
  31. package/dist/cjs/internal/console/utils.cjs.map +10 -0
  32. package/dist/cjs/internal/core/index.cjs +2745 -0
  33. package/dist/cjs/internal/core/index.cjs.map +10 -0
  34. package/dist/cjs/internal/crypto/index.cjs +470 -0
  35. package/dist/cjs/internal/crypto/index.cjs.map +10 -0
  36. package/dist/cjs/internal/daemon/callback-fs-handler.cjs +355 -0
  37. package/dist/cjs/internal/daemon/callback-fs-handler.cjs.map +10 -0
  38. package/dist/cjs/internal/daemon/connection.cjs +1952 -0
  39. package/dist/cjs/internal/daemon/connection.cjs.map +10 -0
  40. package/dist/cjs/internal/daemon/daemon.cjs +98 -0
  41. package/dist/cjs/internal/daemon/daemon.cjs.map +10 -0
  42. package/dist/cjs/internal/daemon/index.cjs +145 -0
  43. package/dist/cjs/internal/daemon/index.cjs.map +10 -0
  44. package/dist/cjs/internal/daemon/runtime-pool.cjs +106 -0
  45. package/dist/cjs/internal/daemon/runtime-pool.cjs.map +10 -0
  46. package/dist/cjs/internal/daemon/types.cjs +30 -0
  47. package/dist/cjs/internal/daemon/types.cjs.map +9 -0
  48. package/dist/cjs/internal/encoding/index.cjs +419 -0
  49. package/dist/cjs/internal/encoding/index.cjs.map +10 -0
  50. package/dist/cjs/internal/fetch/consistency/origins.cjs +598 -0
  51. package/dist/cjs/internal/fetch/consistency/origins.cjs.map +10 -0
  52. package/dist/cjs/internal/fetch/index.cjs +2640 -0
  53. package/dist/cjs/internal/fetch/index.cjs.map +10 -0
  54. package/dist/cjs/internal/fetch/stream-state.cjs +256 -0
  55. package/dist/cjs/internal/fetch/stream-state.cjs.map +10 -0
  56. package/dist/cjs/internal/fs/index.cjs +847 -0
  57. package/dist/cjs/internal/fs/index.cjs.map +10 -0
  58. package/dist/cjs/internal/fs/node-adapter.cjs +254 -0
  59. package/dist/cjs/internal/fs/node-adapter.cjs.map +10 -0
  60. package/dist/cjs/internal/module-loader/bundle.cjs +482 -0
  61. package/dist/cjs/internal/module-loader/bundle.cjs.map +10 -0
  62. package/dist/cjs/internal/module-loader/index.cjs +240 -0
  63. package/dist/cjs/internal/module-loader/index.cjs.map +10 -0
  64. package/dist/cjs/internal/module-loader/mappings.cjs +120 -0
  65. package/dist/cjs/internal/module-loader/mappings.cjs.map +10 -0
  66. package/dist/cjs/internal/module-loader/resolve.cjs +177 -0
  67. package/dist/cjs/internal/module-loader/resolve.cjs.map +10 -0
  68. package/dist/cjs/internal/module-loader/strip-types.cjs +236 -0
  69. package/dist/cjs/internal/module-loader/strip-types.cjs.map +10 -0
  70. package/dist/cjs/internal/path/index.cjs +503 -0
  71. package/dist/cjs/internal/path/index.cjs.map +10 -0
  72. package/dist/cjs/internal/playwright/client.cjs +49 -0
  73. package/dist/cjs/internal/playwright/client.cjs.map +10 -0
  74. package/dist/cjs/internal/playwright/handler.cjs +1416 -0
  75. package/dist/cjs/internal/playwright/handler.cjs.map +10 -0
  76. package/dist/cjs/internal/playwright/index.cjs +1289 -0
  77. package/dist/cjs/internal/playwright/index.cjs.map +10 -0
  78. package/dist/cjs/internal/playwright/types.cjs +47 -0
  79. package/dist/cjs/internal/playwright/types.cjs.map +10 -0
  80. package/dist/cjs/internal/protocol/codec.cjs +510 -0
  81. package/dist/cjs/internal/protocol/codec.cjs.map +10 -0
  82. package/dist/cjs/internal/protocol/framing.cjs +141 -0
  83. package/dist/cjs/internal/protocol/framing.cjs.map +10 -0
  84. package/dist/cjs/internal/protocol/index.cjs +110 -0
  85. package/dist/cjs/internal/protocol/index.cjs.map +10 -0
  86. package/dist/cjs/internal/protocol/marshalValue.cjs +518 -0
  87. package/dist/cjs/internal/protocol/marshalValue.cjs.map +10 -0
  88. package/dist/cjs/internal/protocol/serialization.cjs +109 -0
  89. package/dist/cjs/internal/protocol/serialization.cjs.map +10 -0
  90. package/dist/cjs/internal/protocol/types.cjs +181 -0
  91. package/dist/cjs/internal/protocol/types.cjs.map +10 -0
  92. package/dist/cjs/internal/runtime/index.cjs +1235 -0
  93. package/dist/cjs/internal/runtime/index.cjs.map +10 -0
  94. package/dist/cjs/internal/server/index.cjs +223 -0
  95. package/dist/cjs/internal/server/index.cjs.map +10 -0
  96. package/dist/cjs/internal/test-environment/index.cjs +1415 -0
  97. package/dist/cjs/internal/test-environment/index.cjs.map +10 -0
  98. package/dist/cjs/internal/timers/index.cjs +200 -0
  99. package/dist/cjs/internal/timers/index.cjs.map +10 -0
  100. package/dist/cjs/internal/transform/index.cjs +361 -0
  101. package/dist/cjs/internal/transform/index.cjs.map +10 -0
  102. package/dist/cjs/internal/typecheck/index.cjs +60 -0
  103. package/dist/cjs/internal/typecheck/index.cjs.map +10 -0
  104. package/dist/cjs/internal/typecheck/isolate-types.cjs +2614 -0
  105. package/dist/cjs/internal/typecheck/isolate-types.cjs.map +10 -0
  106. package/dist/cjs/internal/typecheck/typecheck.cjs +131 -0
  107. package/dist/cjs/internal/typecheck/typecheck.cjs.map +10 -0
  108. package/dist/cjs/modules/index.cjs +160 -0
  109. package/dist/cjs/modules/index.cjs.map +10 -0
  110. package/dist/cjs/package.json +5 -0
  111. package/dist/cjs/runtime/script-runtime.cjs +97 -0
  112. package/dist/cjs/runtime/script-runtime.cjs.map +10 -0
  113. package/dist/cjs/server/app-server.cjs +158 -0
  114. package/dist/cjs/server/app-server.cjs.map +10 -0
  115. package/dist/cjs/testing/integration-helpers.cjs +127 -0
  116. package/dist/cjs/testing/integration-helpers.cjs.map +10 -0
  117. package/dist/cjs/typecheck/index.cjs +96 -0
  118. package/dist/cjs/typecheck/index.cjs.map +10 -0
  119. package/dist/cjs/types.cjs +30 -0
  120. package/dist/cjs/types.cjs.map +9 -0
  121. package/dist/mjs/bridge/diagnostics.mjs +18 -0
  122. package/dist/mjs/bridge/diagnostics.mjs.map +10 -0
  123. package/dist/mjs/bridge/legacy-adapters.mjs +178 -0
  124. package/dist/mjs/bridge/legacy-adapters.mjs.map +10 -0
  125. package/dist/mjs/bridge/request-context.mjs +19 -0
  126. package/dist/mjs/bridge/request-context.mjs.map +10 -0
  127. package/dist/mjs/bridge/runtime-bindings.mjs +303 -0
  128. package/dist/mjs/bridge/runtime-bindings.mjs.map +10 -0
  129. package/dist/mjs/browser/browser-runtime.mjs +93 -0
  130. package/dist/mjs/browser/browser-runtime.mjs.map +10 -0
  131. package/dist/mjs/daemon.mjs +91 -0
  132. package/dist/mjs/daemon.mjs.map +10 -0
  133. package/dist/mjs/files/index.mjs +76 -0
  134. package/dist/mjs/files/index.mjs.map +10 -0
  135. package/dist/mjs/host/create-isolate-host.mjs +171 -0
  136. package/dist/mjs/host/create-isolate-host.mjs.map +10 -0
  137. package/dist/mjs/host/index.mjs +7 -0
  138. package/dist/mjs/host/index.mjs.map +10 -0
  139. package/dist/mjs/index.mjs +15 -0
  140. package/dist/mjs/index.mjs.map +10 -0
  141. package/dist/mjs/internal/client/connection.mjs +1872 -0
  142. package/dist/mjs/internal/client/connection.mjs.map +10 -0
  143. package/dist/mjs/internal/client/index.mjs +8 -0
  144. package/dist/mjs/internal/client/index.mjs.map +10 -0
  145. package/dist/mjs/internal/client/types.mjs +2 -0
  146. package/dist/mjs/internal/client/types.mjs.map +9 -0
  147. package/dist/mjs/internal/console/index.mjs +442 -0
  148. package/dist/mjs/internal/console/index.mjs.map +10 -0
  149. package/dist/mjs/internal/console/utils.mjs +30 -0
  150. package/dist/mjs/internal/console/utils.mjs.map +10 -0
  151. package/dist/mjs/internal/core/index.mjs +2681 -0
  152. package/dist/mjs/internal/core/index.mjs.map +10 -0
  153. package/dist/mjs/internal/crypto/index.mjs +406 -0
  154. package/dist/mjs/internal/crypto/index.mjs.map +10 -0
  155. package/dist/mjs/internal/daemon/callback-fs-handler.mjs +315 -0
  156. package/dist/mjs/internal/daemon/callback-fs-handler.mjs.map +10 -0
  157. package/dist/mjs/internal/daemon/connection.mjs +1931 -0
  158. package/dist/mjs/internal/daemon/connection.mjs.map +10 -0
  159. package/dist/mjs/internal/daemon/daemon.mjs +98 -0
  160. package/dist/mjs/internal/daemon/daemon.mjs.map +10 -0
  161. package/dist/mjs/internal/daemon/index.mjs +105 -0
  162. package/dist/mjs/internal/daemon/index.mjs.map +10 -0
  163. package/dist/mjs/internal/daemon/runtime-pool.mjs +66 -0
  164. package/dist/mjs/internal/daemon/runtime-pool.mjs.map +10 -0
  165. package/dist/mjs/internal/daemon/types.mjs +2 -0
  166. package/dist/mjs/internal/daemon/types.mjs.map +9 -0
  167. package/dist/mjs/internal/encoding/index.mjs +379 -0
  168. package/dist/mjs/internal/encoding/index.mjs.map +10 -0
  169. package/dist/mjs/internal/fetch/consistency/origins.mjs +558 -0
  170. package/dist/mjs/internal/fetch/consistency/origins.mjs.map +10 -0
  171. package/dist/mjs/internal/fetch/index.mjs +2580 -0
  172. package/dist/mjs/internal/fetch/index.mjs.map +10 -0
  173. package/dist/mjs/internal/fetch/stream-state.mjs +216 -0
  174. package/dist/mjs/internal/fetch/stream-state.mjs.map +10 -0
  175. package/dist/mjs/internal/fs/index.mjs +783 -0
  176. package/dist/mjs/internal/fs/index.mjs.map +10 -0
  177. package/dist/mjs/internal/fs/node-adapter.mjs +190 -0
  178. package/dist/mjs/internal/fs/node-adapter.mjs.map +10 -0
  179. package/dist/mjs/internal/module-loader/bundle.mjs +418 -0
  180. package/dist/mjs/internal/module-loader/bundle.mjs.map +10 -0
  181. package/dist/mjs/internal/module-loader/index.mjs +185 -0
  182. package/dist/mjs/internal/module-loader/index.mjs.map +10 -0
  183. package/dist/mjs/internal/module-loader/mappings.mjs +80 -0
  184. package/dist/mjs/internal/module-loader/mappings.mjs.map +10 -0
  185. package/dist/mjs/internal/module-loader/resolve.mjs +113 -0
  186. package/dist/mjs/internal/module-loader/resolve.mjs.map +10 -0
  187. package/dist/mjs/internal/module-loader/strip-types.mjs +172 -0
  188. package/dist/mjs/internal/module-loader/strip-types.mjs.map +10 -0
  189. package/dist/mjs/internal/path/index.mjs +463 -0
  190. package/dist/mjs/internal/path/index.mjs.map +10 -0
  191. package/dist/mjs/internal/playwright/client.mjs +13 -0
  192. package/dist/mjs/internal/playwright/client.mjs.map +10 -0
  193. package/dist/mjs/internal/playwright/handler.mjs +1378 -0
  194. package/dist/mjs/internal/playwright/handler.mjs.map +10 -0
  195. package/dist/mjs/internal/playwright/index.mjs +1234 -0
  196. package/dist/mjs/internal/playwright/index.mjs.map +10 -0
  197. package/dist/mjs/internal/playwright/types.mjs +7 -0
  198. package/dist/mjs/internal/playwright/types.mjs.map +10 -0
  199. package/dist/mjs/internal/protocol/codec.mjs +470 -0
  200. package/dist/mjs/internal/protocol/codec.mjs.map +10 -0
  201. package/dist/mjs/internal/protocol/framing.mjs +101 -0
  202. package/dist/mjs/internal/protocol/framing.mjs.map +10 -0
  203. package/dist/mjs/internal/protocol/index.mjs +98 -0
  204. package/dist/mjs/internal/protocol/index.mjs.map +10 -0
  205. package/dist/mjs/internal/protocol/marshalValue.mjs +494 -0
  206. package/dist/mjs/internal/protocol/marshalValue.mjs.map +10 -0
  207. package/dist/mjs/internal/protocol/serialization.mjs +69 -0
  208. package/dist/mjs/internal/protocol/serialization.mjs.map +10 -0
  209. package/dist/mjs/internal/protocol/types.mjs +141 -0
  210. package/dist/mjs/internal/protocol/types.mjs.map +10 -0
  211. package/dist/mjs/internal/runtime/index.mjs +1198 -0
  212. package/dist/mjs/internal/runtime/index.mjs.map +10 -0
  213. package/dist/mjs/internal/server/index.mjs +183 -0
  214. package/dist/mjs/internal/server/index.mjs.map +10 -0
  215. package/dist/mjs/internal/test-environment/index.mjs +1351 -0
  216. package/dist/mjs/internal/test-environment/index.mjs.map +10 -0
  217. package/dist/mjs/internal/timers/index.mjs +136 -0
  218. package/dist/mjs/internal/timers/index.mjs.map +10 -0
  219. package/dist/mjs/internal/transform/index.mjs +321 -0
  220. package/dist/mjs/internal/transform/index.mjs.map +10 -0
  221. package/dist/mjs/internal/typecheck/index.mjs +35 -0
  222. package/dist/mjs/internal/typecheck/index.mjs.map +10 -0
  223. package/dist/mjs/internal/typecheck/isolate-types.mjs +2574 -0
  224. package/dist/mjs/internal/typecheck/isolate-types.mjs.map +10 -0
  225. package/dist/mjs/internal/typecheck/typecheck.mjs +91 -0
  226. package/dist/mjs/internal/typecheck/typecheck.mjs.map +10 -0
  227. package/dist/mjs/modules/index.mjs +96 -0
  228. package/dist/mjs/modules/index.mjs.map +10 -0
  229. package/dist/mjs/package.json +5 -0
  230. package/dist/mjs/runtime/script-runtime.mjs +57 -0
  231. package/dist/mjs/runtime/script-runtime.mjs.map +10 -0
  232. package/dist/mjs/server/app-server.mjs +118 -0
  233. package/dist/mjs/server/app-server.mjs.map +10 -0
  234. package/dist/mjs/testing/integration-helpers.mjs +63 -0
  235. package/dist/mjs/testing/integration-helpers.mjs.map +10 -0
  236. package/dist/mjs/typecheck/index.mjs +56 -0
  237. package/dist/mjs/typecheck/index.mjs.map +10 -0
  238. package/dist/mjs/types.mjs +2 -0
  239. package/dist/mjs/types.mjs.map +9 -0
  240. package/dist/types/bridge/diagnostics.d.ts +12 -0
  241. package/dist/types/bridge/legacy-adapters.d.ts +14 -0
  242. package/dist/types/bridge/request-context.d.ts +10 -0
  243. package/dist/types/bridge/runtime-bindings.d.ts +14 -0
  244. package/dist/types/browser/browser-runtime.d.ts +3 -0
  245. package/dist/types/daemon.d.ts +2 -0
  246. package/dist/types/files/index.d.ts +5 -0
  247. package/dist/types/host/create-isolate-host.d.ts +2 -0
  248. package/dist/types/host/index.d.ts +1 -0
  249. package/dist/types/index.d.ts +5 -0
  250. package/dist/types/internal/client/connection.d.ts +9 -0
  251. package/dist/types/internal/client/index.d.ts +8 -0
  252. package/dist/types/internal/client/types.d.ts +198 -0
  253. package/dist/types/internal/console/index.d.ts +108 -0
  254. package/dist/types/internal/console/utils.d.ts +27 -0
  255. package/dist/types/internal/core/index.d.ts +119 -0
  256. package/dist/types/internal/crypto/index.d.ts +18 -0
  257. package/dist/types/internal/daemon/callback-fs-handler.d.ts +28 -0
  258. package/dist/types/internal/daemon/connection.d.ts +9 -0
  259. package/dist/types/internal/daemon/daemon.d.ts +2 -0
  260. package/dist/types/internal/daemon/index.d.ts +14 -0
  261. package/dist/types/internal/daemon/runtime-pool.d.ts +16 -0
  262. package/dist/types/internal/daemon/types.d.ts +211 -0
  263. package/dist/types/internal/encoding/index.d.ts +21 -0
  264. package/dist/types/internal/fetch/consistency/origins.d.ts +179 -0
  265. package/dist/types/internal/fetch/index.d.ts +93 -0
  266. package/dist/types/internal/fetch/stream-state.d.ts +65 -0
  267. package/dist/types/internal/fs/index.d.ts +70 -0
  268. package/dist/types/internal/fs/node-adapter.d.ts +24 -0
  269. package/dist/types/internal/module-loader/bundle.d.ts +33 -0
  270. package/dist/types/internal/module-loader/index.d.ts +30 -0
  271. package/dist/types/internal/module-loader/mappings.d.ts +47 -0
  272. package/dist/types/internal/module-loader/resolve.d.ts +26 -0
  273. package/dist/types/internal/module-loader/strip-types.d.ts +19 -0
  274. package/dist/types/internal/path/index.d.ts +23 -0
  275. package/dist/types/internal/playwright/client.d.ts +7 -0
  276. package/dist/types/internal/playwright/handler.d.ts +44 -0
  277. package/dist/types/internal/playwright/index.d.ts +14 -0
  278. package/dist/types/internal/playwright/types.d.ts +145 -0
  279. package/dist/types/internal/protocol/codec.d.ts +242 -0
  280. package/dist/types/internal/protocol/framing.d.ts +89 -0
  281. package/dist/types/internal/protocol/index.d.ts +10 -0
  282. package/dist/types/internal/protocol/marshalValue.d.ts +79 -0
  283. package/dist/types/internal/protocol/serialization.d.ts +23 -0
  284. package/dist/types/internal/protocol/types.d.ts +996 -0
  285. package/dist/types/internal/runtime/index.d.ts +200 -0
  286. package/dist/types/internal/server/index.d.ts +42 -0
  287. package/dist/types/internal/test-environment/index.d.ts +112 -0
  288. package/dist/types/internal/timers/index.d.ts +22 -0
  289. package/dist/types/internal/transform/index.d.ts +36 -0
  290. package/dist/types/internal/typecheck/index.d.ts +7 -0
  291. package/dist/types/internal/typecheck/isolate-types.d.ts +94 -0
  292. package/dist/types/internal/typecheck/typecheck.d.ts +148 -0
  293. package/dist/types/modules/index.d.ts +2 -0
  294. package/dist/types/runtime/script-runtime.d.ts +6 -0
  295. package/dist/types/server/app-server.d.ts +3 -0
  296. package/dist/types/testing/integration-helpers.d.ts +9 -0
  297. package/dist/types/typecheck/index.d.ts +8 -0
  298. package/dist/types/types.d.ts +233 -0
  299. package/package.json +82 -6
@@ -0,0 +1,1235 @@
1
+ var __create = Object.create;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
12
+ var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
20
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
21
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
+ for (let key of __getOwnPropNames(mod))
23
+ if (!__hasOwnProp.call(to, key))
24
+ __defProp(to, key, {
25
+ get: __accessProp.bind(mod, key),
26
+ enumerable: true
27
+ });
28
+ if (canCache)
29
+ cache.set(mod, to);
30
+ return to;
31
+ };
32
+ var __toCommonJS = (from) => {
33
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
34
+ if (entry)
35
+ return entry;
36
+ entry = __defProp({}, "__esModule", { value: true });
37
+ if (from && typeof from === "object" || typeof from === "function") {
38
+ for (var key of __getOwnPropNames(from))
39
+ if (!__hasOwnProp.call(entry, key))
40
+ __defProp(entry, key, {
41
+ get: __accessProp.bind(from, key),
42
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
43
+ });
44
+ }
45
+ __moduleCache.set(from, entry);
46
+ return entry;
47
+ };
48
+ var __moduleCache;
49
+ var __returnValue = (v) => v;
50
+ function __exportSetter(name, newValue) {
51
+ this[name] = __returnValue.bind(null, newValue);
52
+ }
53
+ var __export = (target, all) => {
54
+ for (var name in all)
55
+ __defProp(target, name, {
56
+ get: all[name],
57
+ enumerable: true,
58
+ configurable: true,
59
+ set: __exportSetter.bind(all, name)
60
+ });
61
+ };
62
+
63
+ // src/internal/runtime/index.ts
64
+ var exports_runtime = {};
65
+ __export(exports_runtime, {
66
+ simpleConsoleHandler: () => import_utils.simpleConsoleHandler,
67
+ setupTimers: () => import_timers2.setupTimers,
68
+ setupTestEnvironment: () => import_test_environment2.setupTestEnvironment,
69
+ setupPlaywright: () => import_playwright2.setupPlaywright,
70
+ setupPath: () => import_path2.setupPath,
71
+ setupFs: () => import_fs2.setupFs,
72
+ setupFetch: () => import_fetch2.setupFetch,
73
+ setupEncoding: () => import_encoding2.setupEncoding,
74
+ setupCrypto: () => import_crypto2.setupCrypto,
75
+ setupCore: () => import_core2.setupCore,
76
+ setupConsole: () => import_console2.setupConsole,
77
+ runTests: () => import_test_environment2.runTests,
78
+ normalizeEntryFilename: () => import_protocol2.normalizeEntryFilename,
79
+ hasTests: () => import_test_environment2.hasTests,
80
+ getTestCount: () => import_test_environment2.getTestCount,
81
+ getDefaultPlaywrightHandlerMetadata: () => import_playwright2.getDefaultPlaywrightHandlerMetadata,
82
+ defaultPlaywrightHandler: () => import_playwright2.defaultPlaywrightHandler,
83
+ createRuntime: () => createRuntime,
84
+ createPlaywrightHandler: () => import_playwright2.createPlaywrightHandler,
85
+ createNodeFileSystemHandler: () => import_fs2.createNodeFileSystemHandler
86
+ });
87
+ module.exports = __toCommonJS(exports_runtime);
88
+ var import_isolated_vm = __toESM(require("isolated-vm"));
89
+ var import_node_path = __toESM(require("node:path"));
90
+ var import_core = require("../core/index.cjs");
91
+ var import_protocol = require("../protocol/index.cjs");
92
+ var import_transform = require("../transform/index.cjs");
93
+ var import_protocol2 = require("../protocol/index.cjs");
94
+ var import_console = require("../console/index.cjs");
95
+ var import_encoding = require("../encoding/index.cjs");
96
+ var import_timers = require("../timers/index.cjs");
97
+ var import_path = require("../path/index.cjs");
98
+ var import_crypto = require("../crypto/index.cjs");
99
+ var import_fetch = require("../fetch/index.cjs");
100
+ var import_fs = require("../fs/index.cjs");
101
+ var import_test_environment = require("../test-environment/index.cjs");
102
+ var import_playwright = require("../playwright/index.cjs");
103
+ var import_protocol3 = require("../protocol/index.cjs");
104
+ var import_core2 = require("../core/index.cjs");
105
+ var import_console2 = require("../console/index.cjs");
106
+ var import_utils = require("../console/utils.cjs");
107
+ var import_crypto2 = require("../crypto/index.cjs");
108
+ var import_encoding2 = require("../encoding/index.cjs");
109
+ var import_fetch2 = require("../fetch/index.cjs");
110
+ var import_fs2 = require("../fs/index.cjs");
111
+ var import_path2 = require("../path/index.cjs");
112
+ var import_timers2 = require("../timers/index.cjs");
113
+ var import_test_environment2 = require("../test-environment/index.cjs");
114
+ var import_playwright2 = require("../playwright/index.cjs");
115
+ function getConfiguredExecutionTimeout(timeoutMs) {
116
+ if (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
117
+ return;
118
+ }
119
+ return timeoutMs;
120
+ }
121
+ function createTimeoutError(label, timeoutMs) {
122
+ const error = new Error(`${label} timed out after ${timeoutMs}ms`);
123
+ error.name = "TimeoutError";
124
+ return error;
125
+ }
126
+ function createDisposedRuntimeError() {
127
+ return new Error("Runtime has been disposed");
128
+ }
129
+ function createTimedOutRuntimeError(timeoutMs) {
130
+ const error = new Error(`Runtime execution timed out after ${timeoutMs}ms; create a new runtime.`);
131
+ error.name = "TimeoutError";
132
+ return error;
133
+ }
134
+ function assertRuntimeUsable(state) {
135
+ if (state.timedOutExecutionMs !== undefined) {
136
+ throw createTimedOutRuntimeError(state.timedOutExecutionMs);
137
+ }
138
+ if (state.isDisposed) {
139
+ throw createDisposedRuntimeError();
140
+ }
141
+ }
142
+ function logRuntimeDisposal(state, options) {
143
+ const message = `[isolate-runtime] Disposing runtime ${state.id}: ${options.reason}`;
144
+ if (options.error) {
145
+ console.error(message, options.error);
146
+ return;
147
+ }
148
+ console.warn(message);
149
+ }
150
+ async function disposeRuntimeState(state, options = { reason: "RuntimeHandle.dispose() called", log: false }) {
151
+ if (state.disposePromise) {
152
+ return state.disposePromise;
153
+ }
154
+ state.disposeReason = options.reason;
155
+ state.isDisposed = true;
156
+ if (options.log !== false) {
157
+ logRuntimeDisposal(state, options);
158
+ }
159
+ state.disposePromise = (async () => {
160
+ if (state.customFnInvokeRef) {
161
+ try {
162
+ state.customFnInvokeRef.release();
163
+ } catch {} finally {
164
+ state.customFnInvokeRef = undefined;
165
+ }
166
+ }
167
+ const disposeHandle = (dispose) => {
168
+ if (!dispose)
169
+ return;
170
+ try {
171
+ dispose();
172
+ } catch {}
173
+ };
174
+ disposeHandle(state.handles.playwright?.dispose.bind(state.handles.playwright));
175
+ disposeHandle(state.handles.testEnvironment?.dispose.bind(state.handles.testEnvironment));
176
+ disposeHandle(state.handles.fs?.dispose.bind(state.handles.fs));
177
+ disposeHandle(state.handles.fetch?.dispose.bind(state.handles.fetch));
178
+ disposeHandle(state.handles.crypto?.dispose.bind(state.handles.crypto));
179
+ disposeHandle(state.handles.path?.dispose.bind(state.handles.path));
180
+ disposeHandle(state.handles.timers?.dispose.bind(state.handles.timers));
181
+ disposeHandle(state.handles.encoding?.dispose.bind(state.handles.encoding));
182
+ disposeHandle(state.handles.console?.dispose.bind(state.handles.console));
183
+ disposeHandle(state.handles.core?.dispose.bind(state.handles.core));
184
+ state.pendingCallbacks.length = 0;
185
+ state.moduleCache.clear();
186
+ state.moduleLoadsInFlight.clear();
187
+ state.moduleToFilename.clear();
188
+ state.moduleImportChain.clear();
189
+ state.specifierToImporter.clear();
190
+ state.sourceMaps.clear();
191
+ try {
192
+ state.context.release();
193
+ } catch {}
194
+ try {
195
+ state.isolate.dispose();
196
+ } catch {}
197
+ })();
198
+ return state.disposePromise;
199
+ }
200
+ async function runWithExecutionTimeout(state, timeoutMs, label, operation) {
201
+ const effectiveTimeoutMs = getConfiguredExecutionTimeout(timeoutMs);
202
+ if (effectiveTimeoutMs === undefined) {
203
+ return operation();
204
+ }
205
+ let timeoutId;
206
+ const timeoutPromise = new Promise((_, reject) => {
207
+ timeoutId = setTimeout(() => {
208
+ const timeoutError = createTimeoutError(label, effectiveTimeoutMs);
209
+ state.timedOutExecutionMs ??= effectiveTimeoutMs;
210
+ disposeRuntimeState(state, {
211
+ reason: timeoutError.message,
212
+ error: timeoutError
213
+ });
214
+ reject(timeoutError);
215
+ }, effectiveTimeoutMs);
216
+ });
217
+ try {
218
+ return await Promise.race([operation(), timeoutPromise]);
219
+ } finally {
220
+ if (timeoutId) {
221
+ clearTimeout(timeoutId);
222
+ }
223
+ }
224
+ }
225
+ var iteratorSessions = new Map;
226
+ var ISOLATE_MARSHAL_CODE = `
227
+ (function() {
228
+ // Marshal a value (JavaScript → Ref)
229
+ function marshalForHost(value, depth = 0) {
230
+ if (depth > 100) throw new Error('Maximum marshalling depth exceeded');
231
+
232
+ if (value === null) return null;
233
+ if (value === undefined) return { __type: 'UndefinedRef' };
234
+
235
+ const type = typeof value;
236
+ if (type === 'string' || type === 'number' || type === 'boolean') return value;
237
+ if (type === 'bigint') return { __type: 'BigIntRef', value: value.toString() };
238
+ if (type === 'function') throw new Error('Cannot marshal functions from isolate');
239
+ if (type === 'symbol') throw new Error('Cannot marshal Symbol values');
240
+
241
+ if (type === 'object') {
242
+ if (value instanceof Date) {
243
+ return { __type: 'DateRef', timestamp: value.getTime() };
244
+ }
245
+ if (value instanceof RegExp) {
246
+ return { __type: 'RegExpRef', source: value.source, flags: value.flags };
247
+ }
248
+ if (value instanceof URL) {
249
+ return { __type: 'URLRef', href: value.href };
250
+ }
251
+ if (typeof Headers !== 'undefined' && value instanceof Headers) {
252
+ const pairs = [];
253
+ value.forEach((v, k) => pairs.push([k, v]));
254
+ return { __type: 'HeadersRef', pairs };
255
+ }
256
+ if (value instanceof Uint8Array) {
257
+ return { __type: 'Uint8ArrayRef', data: Array.from(value) };
258
+ }
259
+ if (value instanceof ArrayBuffer) {
260
+ return { __type: 'Uint8ArrayRef', data: Array.from(new Uint8Array(value)) };
261
+ }
262
+ if (typeof Request !== 'undefined' && value instanceof Request) {
263
+ throw new Error('Cannot marshal Request from isolate. Use fetch callback instead.');
264
+ }
265
+ if (typeof Response !== 'undefined' && value instanceof Response) {
266
+ throw new Error('Cannot marshal Response from isolate. Return plain objects instead.');
267
+ }
268
+ if (typeof File !== 'undefined' && value instanceof File) {
269
+ throw new Error('Cannot marshal File from isolate.');
270
+ }
271
+ if (typeof Blob !== 'undefined' && value instanceof Blob) {
272
+ throw new Error('Cannot marshal Blob from isolate.');
273
+ }
274
+ if (typeof FormData !== 'undefined' && value instanceof FormData) {
275
+ throw new Error('Cannot marshal FormData from isolate.');
276
+ }
277
+ if (Array.isArray(value)) {
278
+ return value.map(v => marshalForHost(v, depth + 1));
279
+ }
280
+ // Plain object
281
+ const result = {};
282
+ for (const key of Object.keys(value)) {
283
+ result[key] = marshalForHost(value[key], depth + 1);
284
+ }
285
+ return result;
286
+ }
287
+ return value;
288
+ }
289
+
290
+ // Unmarshal a value (Ref → JavaScript)
291
+ function unmarshalFromHost(value, depth = 0) {
292
+ if (depth > 100) throw new Error('Maximum unmarshalling depth exceeded');
293
+
294
+ if (value === null) return null;
295
+ if (typeof value !== 'object') return value;
296
+
297
+ if (value.__type) {
298
+ switch (value.__type) {
299
+ case 'UndefinedRef': return undefined;
300
+ case 'DateRef': return new Date(value.timestamp);
301
+ case 'RegExpRef': return new RegExp(value.source, value.flags);
302
+ case 'BigIntRef': return BigInt(value.value);
303
+ case 'URLRef': return new URL(value.href);
304
+ case 'HeadersRef': return new Headers(value.pairs);
305
+ case 'Uint8ArrayRef': return new Uint8Array(value.data);
306
+ case 'RequestRef': {
307
+ const init = {
308
+ method: value.method,
309
+ headers: value.headers,
310
+ body: value.body ? new Uint8Array(value.body) : null,
311
+ };
312
+ if (value.mode) init.mode = value.mode;
313
+ if (value.credentials) init.credentials = value.credentials;
314
+ if (value.cache) init.cache = value.cache;
315
+ if (value.redirect) init.redirect = value.redirect;
316
+ if (value.referrer) init.referrer = value.referrer;
317
+ if (value.referrerPolicy) init.referrerPolicy = value.referrerPolicy;
318
+ if (value.integrity) init.integrity = value.integrity;
319
+ return new Request(value.url, init);
320
+ }
321
+ case 'ResponseRef': {
322
+ return new Response(value.body ? new Uint8Array(value.body) : null, {
323
+ status: value.status,
324
+ statusText: value.statusText,
325
+ headers: value.headers,
326
+ });
327
+ }
328
+ case 'FileRef': {
329
+ if (!value.name) {
330
+ return new Blob([new Uint8Array(value.data)], { type: value.type });
331
+ }
332
+ return new File([new Uint8Array(value.data)], value.name, {
333
+ type: value.type,
334
+ lastModified: value.lastModified,
335
+ });
336
+ }
337
+ case 'FormDataRef': {
338
+ const fd = new FormData();
339
+ for (const [key, entry] of value.entries) {
340
+ if (typeof entry === 'string') {
341
+ fd.append(key, entry);
342
+ } else {
343
+ const file = unmarshalFromHost(entry, depth + 1);
344
+ fd.append(key, file);
345
+ }
346
+ }
347
+ return fd;
348
+ }
349
+ case 'CallbackRef': {
350
+ const callbackId = value.callbackId;
351
+ return async function(...args) {
352
+ const argsJson = JSON.stringify(marshalForHost(args));
353
+ const resultJson = await __customFn_invoke.apply(
354
+ undefined,
355
+ [callbackId, argsJson],
356
+ { result: { promise: true, copy: true } }
357
+ );
358
+ const result = JSON.parse(resultJson);
359
+ if (result.ok) {
360
+ return unmarshalFromHost(result.value);
361
+ }
362
+
363
+ const error = new Error(result.error.message);
364
+ error.name = result.error.name;
365
+ throw error;
366
+ };
367
+ }
368
+ case 'PromiseRef': {
369
+ const promiseId = value.promiseId;
370
+ return (async () => {
371
+ const argsJson = JSON.stringify([promiseId]);
372
+ const resultJson = await __customFn_invoke.apply(
373
+ undefined,
374
+ [value.__resolveCallbackId, argsJson],
375
+ { result: { promise: true, copy: true } }
376
+ );
377
+ const result = JSON.parse(resultJson);
378
+ if (result.ok) {
379
+ return unmarshalFromHost(result.value);
380
+ }
381
+
382
+ const error = new Error(result.error.message);
383
+ error.name = result.error.name;
384
+ throw error;
385
+ })();
386
+ }
387
+ case 'AsyncIteratorRef': {
388
+ const iteratorId = value.iteratorId;
389
+ const nextCallbackId = value.__nextCallbackId;
390
+ const returnCallbackId = value.__returnCallbackId;
391
+ const throwCallbackId = value.__throwCallbackId;
392
+ return {
393
+ [Symbol.asyncIterator]() { return this; },
394
+ async next() {
395
+ const argsJson = JSON.stringify([iteratorId]);
396
+ const resultJson = await __customFn_invoke.apply(
397
+ undefined,
398
+ [nextCallbackId, argsJson],
399
+ { result: { promise: true, copy: true } }
400
+ );
401
+ const result = JSON.parse(resultJson);
402
+ if (!result.ok) {
403
+ const error = new Error(result.error.message);
404
+ error.name = result.error.name;
405
+ throw error;
406
+ }
407
+ return {
408
+ done: result.value.done,
409
+ value: unmarshalFromHost(result.value.value)
410
+ };
411
+ },
412
+ async return(v) {
413
+ const argsJson = JSON.stringify([iteratorId, marshalForHost(v)]);
414
+ const resultJson = await __customFn_invoke.apply(
415
+ undefined,
416
+ [returnCallbackId, argsJson],
417
+ { result: { promise: true, copy: true } }
418
+ );
419
+ const result = JSON.parse(resultJson);
420
+ if (!result.ok) {
421
+ const error = new Error(result.error.message);
422
+ error.name = result.error.name;
423
+ throw error;
424
+ }
425
+ return {
426
+ done: result.value.done ?? true,
427
+ value: unmarshalFromHost(result.value.value ?? result.value),
428
+ };
429
+ },
430
+ async throw(e) {
431
+ if (throwCallbackId == null) {
432
+ throw e;
433
+ }
434
+ const errorValue = e && typeof e === 'object'
435
+ ? { message: e.message, name: e.name, stack: e.stack }
436
+ : { message: String(e), name: 'Error' };
437
+ const argsJson = JSON.stringify([iteratorId, errorValue]);
438
+ const resultJson = await __customFn_invoke.apply(
439
+ undefined,
440
+ [throwCallbackId, argsJson],
441
+ { result: { promise: true, copy: true } }
442
+ );
443
+ const result = JSON.parse(resultJson);
444
+ if (!result.ok) {
445
+ const error = new Error(result.error.message);
446
+ error.name = result.error.name;
447
+ throw error;
448
+ }
449
+ return {
450
+ done: result.value.done,
451
+ value: unmarshalFromHost(result.value.value),
452
+ };
453
+ }
454
+ };
455
+ }
456
+ default:
457
+ // Unknown ref type, return as-is
458
+ break;
459
+ }
460
+ }
461
+
462
+ if (Array.isArray(value)) {
463
+ return value.map(v => unmarshalFromHost(v, depth + 1));
464
+ }
465
+
466
+ // Plain object - recursively unmarshal
467
+ const result = {};
468
+ for (const key of Object.keys(value)) {
469
+ result[key] = unmarshalFromHost(value[key], depth + 1);
470
+ }
471
+ return result;
472
+ }
473
+
474
+ // Expose as globals
475
+ globalThis.__marshalForHost = marshalForHost;
476
+ globalThis.__unmarshalFromHost = unmarshalFromHost;
477
+ })();
478
+ `;
479
+ async function setupCustomFunctions(context, customFunctions, marshalOptions) {
480
+ const global = context.global;
481
+ const invokeCallbackRef = new import_isolated_vm.default.Reference(async (nameOrId, argsJson) => {
482
+ if (typeof nameOrId === "number" && marshalOptions) {
483
+ const rawArgs2 = JSON.parse(argsJson);
484
+ const args2 = import_protocol3.unmarshalValue(rawArgs2);
485
+ try {
486
+ const result = await marshalOptions.invokeCallback(nameOrId, args2);
487
+ const ctx = marshalOptions.createMarshalContext();
488
+ const marshalledResult = await import_protocol3.marshalValue(result, ctx);
489
+ const processedResult = marshalOptions.addCallbackIdsToRefs(marshalledResult);
490
+ return JSON.stringify({ ok: true, value: processedResult });
491
+ } catch (error) {
492
+ const err = error;
493
+ return JSON.stringify({
494
+ ok: false,
495
+ error: { message: err.message, name: err.name }
496
+ });
497
+ }
498
+ }
499
+ const name = String(nameOrId);
500
+ const def = customFunctions[name];
501
+ if (!def) {
502
+ return JSON.stringify({
503
+ ok: false,
504
+ error: {
505
+ message: `Custom function '${name}' not found`,
506
+ name: "Error"
507
+ }
508
+ });
509
+ }
510
+ const rawArgs = JSON.parse(argsJson);
511
+ const args = import_protocol3.unmarshalValue(rawArgs);
512
+ try {
513
+ const result = await def.fn(...args);
514
+ if (marshalOptions) {
515
+ const ctx = marshalOptions.createMarshalContext();
516
+ const marshalledResult2 = await import_protocol3.marshalValue(result, ctx);
517
+ const processedResult = marshalOptions.addCallbackIdsToRefs(marshalledResult2);
518
+ return JSON.stringify({ ok: true, value: processedResult });
519
+ }
520
+ const marshalledResult = await import_protocol3.marshalValue(result);
521
+ return JSON.stringify({ ok: true, value: marshalledResult });
522
+ } catch (error) {
523
+ const err = error;
524
+ return JSON.stringify({
525
+ ok: false,
526
+ error: { message: err.message, name: err.name }
527
+ });
528
+ }
529
+ });
530
+ global.setSync("__customFn_invoke", invokeCallbackRef);
531
+ context.evalSync(ISOLATE_MARSHAL_CODE);
532
+ for (const name of Object.keys(customFunctions)) {
533
+ const def = customFunctions[name];
534
+ if (def.type === "async") {
535
+ context.evalSync(`
536
+ globalThis.${name} = async function(...args) {
537
+ const marshalledArgs = __marshalForHost(args);
538
+ const resultJson = await __customFn_invoke.apply(
539
+ undefined,
540
+ ["${name}", JSON.stringify(marshalledArgs)],
541
+ { result: { promise: true, copy: true } }
542
+ );
543
+ const result = JSON.parse(resultJson);
544
+ if (result.ok) {
545
+ return __unmarshalFromHost(result.value);
546
+ }
547
+ const error = new Error(result.error.message);
548
+ error.name = result.error.name;
549
+ throw error;
550
+ };
551
+ `);
552
+ } else if (def.type === "sync") {
553
+ context.evalSync(`
554
+ globalThis.${name} = function(...args) {
555
+ const marshalledArgs = __marshalForHost(args);
556
+ const resultJson = __customFn_invoke.applySync(
557
+ undefined,
558
+ ["${name}", JSON.stringify(marshalledArgs)],
559
+ { result: { copy: true } }
560
+ );
561
+ const result = JSON.parse(resultJson);
562
+ if (result.ok) {
563
+ return __unmarshalFromHost(result.value);
564
+ }
565
+ const error = new Error(result.error.message);
566
+ error.name = result.error.name;
567
+ throw error;
568
+ };
569
+ `);
570
+ } else if (def.type === "asyncIterator") {
571
+ context.evalSync(`
572
+ globalThis.${name} = function(...args) {
573
+ const marshalledArgs = __marshalForHost(args);
574
+ const iteratorPromise = (async () => {
575
+ const resultJson = await __customFn_invoke.apply(
576
+ undefined,
577
+ ["${name}", JSON.stringify(marshalledArgs)],
578
+ { result: { promise: true, copy: true } }
579
+ );
580
+ const result = JSON.parse(resultJson);
581
+ if (result.ok) {
582
+ return __unmarshalFromHost(result.value);
583
+ }
584
+ throw Object.assign(new Error(result.error.message), {
585
+ name: result.error.name,
586
+ });
587
+ })();
588
+ return {
589
+ [Symbol.asyncIterator]() { return this; },
590
+ async next() {
591
+ const iterator = await iteratorPromise;
592
+ return iterator.next();
593
+ },
594
+ async return(v) {
595
+ const iterator = await iteratorPromise;
596
+ return iterator.return ? iterator.return(v) : { done: true, value: v };
597
+ },
598
+ async throw(e) {
599
+ const iterator = await iteratorPromise;
600
+ if (!iterator.throw) {
601
+ throw e;
602
+ }
603
+ return iterator.throw(e);
604
+ }
605
+ };
606
+ };
607
+ `);
608
+ }
609
+ }
610
+ return invokeCallbackRef;
611
+ }
612
+ function createLocalCustomFunctionsMarshalOptions() {
613
+ const returnedCallbacks = new Map;
614
+ const returnedPromises = new Map;
615
+ const returnedIterators = new Map;
616
+ let nextLocalCallbackId = 1e6;
617
+ const createMarshalContext = () => ({
618
+ registerCallback: (fn) => {
619
+ const callbackId = nextLocalCallbackId++;
620
+ returnedCallbacks.set(callbackId, fn);
621
+ return callbackId;
622
+ },
623
+ registerPromise: (promise) => {
624
+ const promiseId = nextLocalCallbackId++;
625
+ returnedPromises.set(promiseId, promise);
626
+ return promiseId;
627
+ },
628
+ registerIterator: (iterator) => {
629
+ const iteratorId = nextLocalCallbackId++;
630
+ returnedIterators.set(iteratorId, iterator);
631
+ return iteratorId;
632
+ }
633
+ });
634
+ const isPromiseRef = (value) => typeof value === "object" && value !== null && value.__type === "PromiseRef";
635
+ const isAsyncIteratorRef = (value) => typeof value === "object" && value !== null && value.__type === "AsyncIteratorRef";
636
+ const addCallbackIdsToRefs = (value) => {
637
+ if (value === null || typeof value !== "object")
638
+ return value;
639
+ if (isPromiseRef(value)) {
640
+ if ("__resolveCallbackId" in value)
641
+ return value;
642
+ const resolveCallbackId = nextLocalCallbackId++;
643
+ returnedCallbacks.set(resolveCallbackId, async (promiseId) => {
644
+ const promise = returnedPromises.get(promiseId);
645
+ if (!promise) {
646
+ throw new Error(`Promise ${promiseId} not found`);
647
+ }
648
+ const result2 = await promise;
649
+ returnedPromises.delete(promiseId);
650
+ const ctx = createMarshalContext();
651
+ const marshalled = await import_protocol3.marshalValue(result2, ctx);
652
+ return addCallbackIdsToRefs(marshalled);
653
+ });
654
+ return { ...value, __resolveCallbackId: resolveCallbackId };
655
+ }
656
+ if (isAsyncIteratorRef(value)) {
657
+ if ("__nextCallbackId" in value)
658
+ return value;
659
+ const nextCallbackId = nextLocalCallbackId++;
660
+ returnedCallbacks.set(nextCallbackId, async (iteratorId) => {
661
+ const iterator = returnedIterators.get(iteratorId);
662
+ if (!iterator) {
663
+ throw new Error(`Iterator ${iteratorId} not found`);
664
+ }
665
+ const result2 = await iterator.next();
666
+ if (result2.done) {
667
+ returnedIterators.delete(iteratorId);
668
+ }
669
+ const ctx = createMarshalContext();
670
+ const marshalledValue = await import_protocol3.marshalValue(result2.value, ctx);
671
+ return {
672
+ done: result2.done,
673
+ value: addCallbackIdsToRefs(marshalledValue)
674
+ };
675
+ });
676
+ const returnCallbackId = nextLocalCallbackId++;
677
+ returnedCallbacks.set(returnCallbackId, async (iteratorId, returnValue) => {
678
+ const iterator = returnedIterators.get(iteratorId);
679
+ returnedIterators.delete(iteratorId);
680
+ if (!iterator || !iterator.return) {
681
+ return { done: true, value: undefined };
682
+ }
683
+ const result2 = await iterator.return(returnValue);
684
+ const ctx = createMarshalContext();
685
+ const marshalledValue = await import_protocol3.marshalValue(result2.value, ctx);
686
+ return {
687
+ done: true,
688
+ value: addCallbackIdsToRefs(marshalledValue)
689
+ };
690
+ });
691
+ const throwCallbackId = nextLocalCallbackId++;
692
+ returnedCallbacks.set(throwCallbackId, async (iteratorId, errorValue) => {
693
+ const iterator = returnedIterators.get(iteratorId);
694
+ if (!iterator) {
695
+ throw new Error(`Iterator ${iteratorId} not found`);
696
+ }
697
+ try {
698
+ if (!iterator.throw) {
699
+ throw Object.assign(new Error(errorValue?.message ?? "Iterator does not support throw()"), { name: errorValue?.name ?? "Error", stack: errorValue?.stack });
700
+ }
701
+ const thrownError = Object.assign(new Error(errorValue?.message ?? "Iterator throw()"), { name: errorValue?.name ?? "Error", stack: errorValue?.stack });
702
+ const result2 = await iterator.throw(thrownError);
703
+ if (result2.done) {
704
+ returnedIterators.delete(iteratorId);
705
+ }
706
+ const ctx = createMarshalContext();
707
+ const marshalledValue = await import_protocol3.marshalValue(result2.value, ctx);
708
+ return {
709
+ done: result2.done,
710
+ value: addCallbackIdsToRefs(marshalledValue)
711
+ };
712
+ } catch (error) {
713
+ returnedIterators.delete(iteratorId);
714
+ throw error;
715
+ }
716
+ });
717
+ return {
718
+ ...value,
719
+ __nextCallbackId: nextCallbackId,
720
+ __returnCallbackId: returnCallbackId,
721
+ __throwCallbackId: throwCallbackId
722
+ };
723
+ }
724
+ if (Array.isArray(value)) {
725
+ return value.map((item) => addCallbackIdsToRefs(item));
726
+ }
727
+ const result = {};
728
+ for (const key of Object.keys(value)) {
729
+ result[key] = addCallbackIdsToRefs(value[key]);
730
+ }
731
+ return result;
732
+ };
733
+ const invokeCallback = async (callbackId, args) => {
734
+ const callback = returnedCallbacks.get(callbackId);
735
+ if (!callback) {
736
+ throw new Error(`Local callback ${callbackId} not found`);
737
+ }
738
+ return await callback(...args);
739
+ };
740
+ return { createMarshalContext, addCallbackIdsToRefs, invokeCallback };
741
+ }
742
+ function createModuleResolver(state) {
743
+ return async (specifier, referrer) => {
744
+ const importerPath = state.moduleToFilename.get(referrer) ?? "<unknown>";
745
+ const importerResolveDir = import_node_path.default.posix.dirname(importerPath);
746
+ const importerStack = state.moduleImportChain.get(importerPath) ?? [];
747
+ const resolvedSpecifier = specifier.startsWith(".") ? import_node_path.default.posix.normalize(import_node_path.default.posix.join(importerResolveDir, specifier)) : specifier;
748
+ state.specifierToImporter.set(resolvedSpecifier, importerPath);
749
+ const staticCached = state.staticModuleCache.get(resolvedSpecifier);
750
+ if (staticCached)
751
+ return staticCached;
752
+ const cached = state.moduleCache.get(resolvedSpecifier);
753
+ if (cached)
754
+ return cached;
755
+ if (!state.moduleLoader) {
756
+ throw new Error(`No module loader registered. Cannot import: ${specifier}`);
757
+ }
758
+ const result = await state.moduleLoader(specifier, {
759
+ path: importerPath,
760
+ resolveDir: importerResolveDir
761
+ });
762
+ const { code, resolveDir } = result;
763
+ if (result.filename.includes("/")) {
764
+ throw new Error(`moduleLoader returned a filename with slashes: "${result.filename}". ` + `filename must be a basename (e.g. "utils.js"), not a path.`);
765
+ }
766
+ const resolvedFilename = import_node_path.default.posix.join(resolveDir, result.filename);
767
+ const hash = import_transform.contentHash(code);
768
+ const cacheKey = `${resolvedSpecifier}:${hash}`;
769
+ const inFlightKey = `${result.static ? "static" : "dynamic"}:${cacheKey}`;
770
+ const staticCachedAfterLoad = state.staticModuleCache.get(resolvedSpecifier);
771
+ if (staticCachedAfterLoad)
772
+ return staticCachedAfterLoad;
773
+ const cachedAfterLoad = state.moduleCache.get(resolvedSpecifier);
774
+ if (cachedAfterLoad)
775
+ return cachedAfterLoad;
776
+ const hashCached = state.moduleCache.get(cacheKey);
777
+ if (hashCached)
778
+ return hashCached;
779
+ const inFlight = state.moduleLoadsInFlight.get(inFlightKey);
780
+ if (inFlight)
781
+ return inFlight;
782
+ const loadPromise = (async () => {
783
+ let mod;
784
+ try {
785
+ let transformed = state.transformCache.get(hash);
786
+ if (!transformed) {
787
+ transformed = await import_transform.transformModuleCode(code, resolvedSpecifier);
788
+ state.transformCache.set(hash, transformed);
789
+ }
790
+ if (transformed.sourceMap) {
791
+ state.sourceMaps.set(resolvedSpecifier, transformed.sourceMap);
792
+ }
793
+ mod = await state.isolate.compileModule(transformed.code, {
794
+ filename: resolvedSpecifier
795
+ });
796
+ state.moduleToFilename.set(mod, resolvedFilename);
797
+ state.moduleImportChain.set(resolvedFilename, [...importerStack, importerPath]);
798
+ if (result.static) {
799
+ state.staticModuleCache.set(resolvedSpecifier, mod);
800
+ } else {
801
+ state.moduleCache.set(resolvedSpecifier, mod);
802
+ state.moduleCache.set(cacheKey, mod);
803
+ }
804
+ return mod;
805
+ } catch (err) {
806
+ const error = err instanceof Error ? err : new Error(String(err));
807
+ error.message = `Failed to compile module "${resolvedSpecifier}" (imported by "${importerPath}"):
808
+ ${error.message}`;
809
+ if (importerStack.length > 0) {
810
+ error.message += `
811
+
812
+ Import chain:
813
+ ${[...importerStack, importerPath].join(`
814
+ -> `)}`;
815
+ }
816
+ if (mod) {
817
+ state.moduleToFilename.delete(mod);
818
+ if (result.static) {
819
+ if (state.staticModuleCache.get(resolvedSpecifier) === mod) {
820
+ state.staticModuleCache.delete(resolvedSpecifier);
821
+ }
822
+ } else {
823
+ if (state.moduleCache.get(resolvedSpecifier) === mod) {
824
+ state.moduleCache.delete(resolvedSpecifier);
825
+ }
826
+ if (state.moduleCache.get(cacheKey) === mod) {
827
+ state.moduleCache.delete(cacheKey);
828
+ }
829
+ }
830
+ }
831
+ throw error;
832
+ }
833
+ })();
834
+ state.moduleLoadsInFlight.set(inFlightKey, loadPromise);
835
+ try {
836
+ return await loadPromise;
837
+ } finally {
838
+ state.moduleLoadsInFlight.delete(inFlightKey);
839
+ }
840
+ };
841
+ }
842
+ function convertFetchCallback(callback) {
843
+ if (!callback) {
844
+ return {};
845
+ }
846
+ return {
847
+ onFetch: async (url, init) => {
848
+ return Promise.resolve(callback(url, init));
849
+ }
850
+ };
851
+ }
852
+ async function createRuntime(options) {
853
+ const opts = options ?? {};
854
+ const id = crypto.randomUUID();
855
+ const isolate = new import_isolated_vm.default.Isolate({
856
+ memoryLimit: opts.memoryLimitMB
857
+ });
858
+ const context = await isolate.createContext();
859
+ const state = {
860
+ id,
861
+ isolate,
862
+ context,
863
+ handles: {},
864
+ moduleCache: new Map,
865
+ staticModuleCache: new Map,
866
+ moduleLoadsInFlight: new Map,
867
+ transformCache: new Map,
868
+ moduleToFilename: new Map,
869
+ sourceMaps: new Map,
870
+ moduleImportChain: new Map,
871
+ specifierToImporter: new Map,
872
+ pendingCallbacks: [],
873
+ evalChain: Promise.resolve(),
874
+ executionTimeout: getConfiguredExecutionTimeout(opts.executionTimeout),
875
+ isDisposed: false,
876
+ moduleLoader: opts.moduleLoader,
877
+ customFunctions: opts.customFunctions
878
+ };
879
+ state.handles.core = await import_core.setupCore(context);
880
+ state.handles.console = await import_console.setupConsole(context, opts.console);
881
+ state.handles.encoding = await import_encoding.setupEncoding(context);
882
+ state.handles.timers = await import_timers.setupTimers(context);
883
+ state.handles.path = await import_path.setupPath(context, { cwd: opts.cwd });
884
+ state.handles.crypto = await import_crypto.setupCrypto(context);
885
+ state.handles.fetch = await import_fetch.setupFetch(context, convertFetchCallback(opts.fetch));
886
+ if (opts.fs) {
887
+ state.handles.fs = await import_fs.setupFs(context, opts.fs);
888
+ }
889
+ if (opts.customFunctions) {
890
+ const customMarshalOptions = opts.customFunctionsMarshalOptions ?? createLocalCustomFunctionsMarshalOptions();
891
+ state.customFnInvokeRef = await setupCustomFunctions(context, opts.customFunctions, customMarshalOptions);
892
+ }
893
+ if (opts.testEnvironment) {
894
+ const testEnvOptions = typeof opts.testEnvironment === "object" ? opts.testEnvironment : undefined;
895
+ state.handles.testEnvironment = await import_test_environment.setupTestEnvironment(context, testEnvOptions);
896
+ }
897
+ if (opts.playwright) {
898
+ if (!opts.playwright.handler) {
899
+ throw new Error("Playwright configured without handler. Provide playwright.handler in createRuntime options.");
900
+ }
901
+ let eventCallback = opts.playwright.onEvent;
902
+ if (opts.playwright.console && opts.console?.onEntry) {
903
+ const originalCallback = eventCallback;
904
+ const consoleHandler = opts.console.onEntry;
905
+ eventCallback = (event) => {
906
+ if (originalCallback) {
907
+ originalCallback(event);
908
+ }
909
+ if (event.type === "browserConsoleLog") {
910
+ consoleHandler({
911
+ type: "browserOutput",
912
+ level: event.level,
913
+ stdout: event.stdout,
914
+ location: event.location,
915
+ timestamp: event.timestamp
916
+ });
917
+ }
918
+ };
919
+ }
920
+ const playwrightSetupOptions = {
921
+ handler: opts.playwright.handler,
922
+ timeout: opts.playwright.timeout,
923
+ console: opts.playwright.console && !opts.console?.onEntry,
924
+ onEvent: eventCallback
925
+ };
926
+ state.handles.playwright = await import_playwright.setupPlaywright(context, playwrightSetupOptions);
927
+ }
928
+ const ensureRuntimeUsable = () => {
929
+ assertRuntimeUsable(state);
930
+ };
931
+ const fetchHandle = {
932
+ async dispatchRequest(request, options2) {
933
+ ensureRuntimeUsable();
934
+ if (!state.handles.fetch) {
935
+ throw new Error("Fetch handle not available");
936
+ }
937
+ return state.handles.fetch.dispatchRequest(request, options2);
938
+ },
939
+ getUpgradeRequest() {
940
+ ensureRuntimeUsable();
941
+ if (!state.handles.fetch) {
942
+ throw new Error("Fetch handle not available");
943
+ }
944
+ return state.handles.fetch.getUpgradeRequest();
945
+ },
946
+ dispatchWebSocketOpen(connectionId) {
947
+ ensureRuntimeUsable();
948
+ if (!state.handles.fetch) {
949
+ throw new Error("Fetch handle not available");
950
+ }
951
+ state.handles.fetch.dispatchWebSocketOpen(connectionId);
952
+ },
953
+ dispatchWebSocketMessage(connectionId, message) {
954
+ ensureRuntimeUsable();
955
+ if (!state.handles.fetch) {
956
+ throw new Error("Fetch handle not available");
957
+ }
958
+ state.handles.fetch.dispatchWebSocketMessage(connectionId, message);
959
+ },
960
+ dispatchWebSocketClose(connectionId, code, reason) {
961
+ ensureRuntimeUsable();
962
+ if (!state.handles.fetch) {
963
+ throw new Error("Fetch handle not available");
964
+ }
965
+ state.handles.fetch.dispatchWebSocketClose(connectionId, code, reason);
966
+ },
967
+ dispatchWebSocketError(connectionId, error) {
968
+ ensureRuntimeUsable();
969
+ if (!state.handles.fetch) {
970
+ throw new Error("Fetch handle not available");
971
+ }
972
+ state.handles.fetch.dispatchWebSocketError(connectionId, error);
973
+ },
974
+ onWebSocketCommand(callback) {
975
+ ensureRuntimeUsable();
976
+ if (!state.handles.fetch) {
977
+ throw new Error("Fetch handle not available");
978
+ }
979
+ return state.handles.fetch.onWebSocketCommand(callback);
980
+ },
981
+ hasServeHandler() {
982
+ ensureRuntimeUsable();
983
+ if (!state.handles.fetch) {
984
+ throw new Error("Fetch handle not available");
985
+ }
986
+ return state.handles.fetch.hasServeHandler();
987
+ },
988
+ hasActiveConnections() {
989
+ ensureRuntimeUsable();
990
+ if (!state.handles.fetch) {
991
+ throw new Error("Fetch handle not available");
992
+ }
993
+ return state.handles.fetch.hasActiveConnections();
994
+ },
995
+ dispatchClientWebSocketOpen(socketId, protocol, extensions) {
996
+ ensureRuntimeUsable();
997
+ if (!state.handles.fetch) {
998
+ throw new Error("Fetch handle not available");
999
+ }
1000
+ state.handles.fetch.dispatchClientWebSocketOpen(socketId, protocol, extensions);
1001
+ },
1002
+ dispatchClientWebSocketMessage(socketId, data) {
1003
+ ensureRuntimeUsable();
1004
+ if (!state.handles.fetch) {
1005
+ throw new Error("Fetch handle not available");
1006
+ }
1007
+ state.handles.fetch.dispatchClientWebSocketMessage(socketId, data);
1008
+ },
1009
+ dispatchClientWebSocketClose(socketId, code, reason, wasClean) {
1010
+ ensureRuntimeUsable();
1011
+ if (!state.handles.fetch) {
1012
+ throw new Error("Fetch handle not available");
1013
+ }
1014
+ state.handles.fetch.dispatchClientWebSocketClose(socketId, code, reason, wasClean);
1015
+ },
1016
+ dispatchClientWebSocketError(socketId) {
1017
+ ensureRuntimeUsable();
1018
+ if (!state.handles.fetch) {
1019
+ throw new Error("Fetch handle not available");
1020
+ }
1021
+ state.handles.fetch.dispatchClientWebSocketError(socketId);
1022
+ },
1023
+ onClientWebSocketCommand(callback) {
1024
+ ensureRuntimeUsable();
1025
+ if (!state.handles.fetch) {
1026
+ throw new Error("Fetch handle not available");
1027
+ }
1028
+ return state.handles.fetch.onClientWebSocketCommand(callback);
1029
+ },
1030
+ onEvent(callback) {
1031
+ ensureRuntimeUsable();
1032
+ if (!state.handles.fetch) {
1033
+ throw new Error("Fetch handle not available");
1034
+ }
1035
+ return state.handles.fetch.onEvent(callback);
1036
+ },
1037
+ dispatchEvent(event, payload) {
1038
+ ensureRuntimeUsable();
1039
+ if (!state.handles.fetch) {
1040
+ throw new Error("Fetch handle not available");
1041
+ }
1042
+ state.handles.fetch.dispatchEvent(event, payload);
1043
+ }
1044
+ };
1045
+ const timersHandle = {
1046
+ clearAll() {
1047
+ ensureRuntimeUsable();
1048
+ state.handles.timers?.clearAll();
1049
+ }
1050
+ };
1051
+ const consoleHandle = {
1052
+ reset() {
1053
+ ensureRuntimeUsable();
1054
+ state.handles.console?.reset();
1055
+ },
1056
+ getTimers() {
1057
+ ensureRuntimeUsable();
1058
+ return state.handles.console?.getTimers() ?? new Map;
1059
+ },
1060
+ getCounters() {
1061
+ ensureRuntimeUsable();
1062
+ return state.handles.console?.getCounters() ?? new Map;
1063
+ },
1064
+ getGroupDepth() {
1065
+ ensureRuntimeUsable();
1066
+ return state.handles.console?.getGroupDepth() ?? 0;
1067
+ }
1068
+ };
1069
+ const testEnvironmentHandle = {
1070
+ async runTests(timeout) {
1071
+ ensureRuntimeUsable();
1072
+ if (!state.handles.testEnvironment) {
1073
+ throw new Error("Test environment not enabled. Set testEnvironment: true in createRuntime options.");
1074
+ }
1075
+ const executionTimeout = timeout ?? state.executionTimeout;
1076
+ return runWithExecutionTimeout(state, executionTimeout, "Test", async () => {
1077
+ return import_test_environment.runTests(state.context);
1078
+ });
1079
+ },
1080
+ hasTests() {
1081
+ ensureRuntimeUsable();
1082
+ if (!state.handles.testEnvironment) {
1083
+ throw new Error("Test environment not enabled. Set testEnvironment: true in createRuntime options.");
1084
+ }
1085
+ return import_test_environment.hasTests(state.context);
1086
+ },
1087
+ getTestCount() {
1088
+ ensureRuntimeUsable();
1089
+ if (!state.handles.testEnvironment) {
1090
+ throw new Error("Test environment not enabled. Set testEnvironment: true in createRuntime options.");
1091
+ }
1092
+ return import_test_environment.getTestCount(state.context);
1093
+ },
1094
+ reset() {
1095
+ ensureRuntimeUsable();
1096
+ state.handles.testEnvironment?.dispose();
1097
+ }
1098
+ };
1099
+ const playwrightHandle = {
1100
+ getCollectedData() {
1101
+ ensureRuntimeUsable();
1102
+ if (!state.handles.playwright) {
1103
+ throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
1104
+ }
1105
+ return {
1106
+ browserConsoleLogs: state.handles.playwright.getBrowserConsoleLogs(),
1107
+ pageErrors: state.handles.playwright.getPageErrors(),
1108
+ networkRequests: state.handles.playwright.getNetworkRequests(),
1109
+ networkResponses: state.handles.playwright.getNetworkResponses(),
1110
+ requestFailures: state.handles.playwright.getRequestFailures()
1111
+ };
1112
+ },
1113
+ clearCollectedData() {
1114
+ ensureRuntimeUsable();
1115
+ state.handles.playwright?.clearCollected();
1116
+ }
1117
+ };
1118
+ return {
1119
+ id,
1120
+ pendingCallbacks: state.pendingCallbacks,
1121
+ fetch: fetchHandle,
1122
+ timers: timersHandle,
1123
+ console: consoleHandle,
1124
+ testEnvironment: testEnvironmentHandle,
1125
+ playwright: playwrightHandle,
1126
+ async eval(code, filenameOrOptions) {
1127
+ const options2 = typeof filenameOrOptions === "string" ? { filename: filenameOrOptions } : filenameOrOptions;
1128
+ const executionTimeout = options2?.executionTimeout ?? state.executionTimeout;
1129
+ const runEval = async () => {
1130
+ assertRuntimeUsable(state);
1131
+ const filename = import_protocol.normalizeEntryFilename(options2?.filename);
1132
+ try {
1133
+ await runWithExecutionTimeout(state, executionTimeout, "Execution", async () => {
1134
+ const transformed = await import_transform.transformEntryCode(code, filename);
1135
+ if (transformed.sourceMap) {
1136
+ state.sourceMaps.set(filename, transformed.sourceMap);
1137
+ }
1138
+ const mod = await state.isolate.compileModule(transformed.code, {
1139
+ filename
1140
+ });
1141
+ state.moduleToFilename.set(mod, filename);
1142
+ state.moduleImportChain.set(filename, []);
1143
+ const resolver = createModuleResolver(state);
1144
+ try {
1145
+ await mod.instantiate(state.context, resolver);
1146
+ } catch (err) {
1147
+ const error = err instanceof Error ? err : new Error(String(err));
1148
+ const specifierMatch = error.message.match(/The requested module '([^']+)'/);
1149
+ const exportMatch = error.message.match(/export named '([^']+)'/);
1150
+ const failingSpecifier = specifierMatch?.[1];
1151
+ const failingExport = exportMatch?.[1];
1152
+ const importerFile = failingSpecifier ? state.specifierToImporter.get(failingSpecifier) : undefined;
1153
+ const details = [];
1154
+ if (importerFile) {
1155
+ const chain = state.moduleImportChain.get(importerFile) ?? [];
1156
+ const fullChain = [...chain, importerFile];
1157
+ if (failingSpecifier)
1158
+ fullChain.push(failingSpecifier);
1159
+ const trimmed = fullChain.length > 12 ? fullChain.slice(-12) : fullChain;
1160
+ const prefix = fullChain.length > 12 ? ` ...
1161
+ ` : "";
1162
+ details.push(`Import chain:
1163
+ ${prefix}${trimmed.map((p) => ` ${p}`).join(`
1164
+ -> `)}`);
1165
+ } else if (failingSpecifier) {
1166
+ for (const [modPath, chain] of state.moduleImportChain) {
1167
+ if (modPath.includes(failingSpecifier) || modPath.endsWith(failingSpecifier)) {
1168
+ const fullChain = [...chain, modPath];
1169
+ const trimmed = fullChain.length > 12 ? fullChain.slice(-12) : fullChain;
1170
+ details.push(`Import chain:
1171
+ ${trimmed.map((p) => ` ${p}`).join(`
1172
+ -> `)}`);
1173
+ break;
1174
+ }
1175
+ }
1176
+ }
1177
+ if (failingExport && failingSpecifier) {
1178
+ details.push(`Hint: If '${failingExport}' is a TypeScript type/interface, use \`import type\` to prevent it from being resolved at runtime:
1179
+ ` + ` import type { ${failingExport} } from '${failingSpecifier}';`);
1180
+ }
1181
+ const suffix = details.length > 0 ? `
1182
+
1183
+ ` + details.join(`
1184
+
1185
+ `) : "";
1186
+ error.message = `Module instantiation failed: ${error.message}${suffix}`;
1187
+ throw error;
1188
+ }
1189
+ await mod.evaluate();
1190
+ const ns = mod.namespace;
1191
+ const runRef = await ns.get("default", { reference: true });
1192
+ try {
1193
+ await runRef.apply(undefined, [], {
1194
+ result: { promise: true }
1195
+ });
1196
+ } finally {
1197
+ runRef.release();
1198
+ }
1199
+ if (state.pendingCallbacks.length > 0) {
1200
+ await Promise.all(state.pendingCallbacks);
1201
+ state.pendingCallbacks.length = 0;
1202
+ }
1203
+ });
1204
+ } catch (err) {
1205
+ const error = err;
1206
+ if (error.stack && state.sourceMaps.size > 0) {
1207
+ error.stack = import_transform.mapErrorStack(error.stack, state.sourceMaps);
1208
+ }
1209
+ throw error;
1210
+ }
1211
+ };
1212
+ const queuedEval = state.evalChain.then(runEval, runEval);
1213
+ state.evalChain = queuedEval.then(() => {
1214
+ return;
1215
+ }, () => {
1216
+ return;
1217
+ });
1218
+ return queuedEval;
1219
+ },
1220
+ clearModuleCache() {
1221
+ ensureRuntimeUsable();
1222
+ state.moduleCache.clear();
1223
+ state.moduleLoadsInFlight.clear();
1224
+ state.moduleToFilename.clear();
1225
+ state.moduleImportChain.clear();
1226
+ state.specifierToImporter.clear();
1227
+ state.sourceMaps.clear();
1228
+ },
1229
+ async dispose() {
1230
+ await disposeRuntimeState(state);
1231
+ }
1232
+ };
1233
+ }
1234
+
1235
+ //# debugId=C038E2F2DDE69DFD64756E2164756E21