wasm-idle 0.7.2 → 1.0.0

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 (386) hide show
  1. package/README.md +760 -81
  2. package/dist/index.d.ts +4 -9
  3. package/dist/index.js +2 -4
  4. package/dist/playground/applicationAssets.d.ts +4 -0
  5. package/dist/playground/applicationAssets.js +277 -0
  6. package/dist/playground/assemblyscript.d.ts +41 -0
  7. package/dist/playground/assemblyscript.js +630 -0
  8. package/dist/playground/assetBridge.d.ts +18 -7
  9. package/dist/playground/assetBridge.js +824 -100
  10. package/dist/playground/assets.d.ts +813 -19
  11. package/dist/playground/assets.js +2096 -156
  12. package/dist/playground/awk.d.ts +5 -0
  13. package/dist/playground/awk.js +60 -0
  14. package/dist/playground/bash.d.ts +53 -0
  15. package/dist/playground/bash.js +1096 -0
  16. package/dist/playground/bashWorkerProtocol.d.ts +88 -0
  17. package/dist/playground/bashWorkerProtocol.js +135 -0
  18. package/dist/playground/bqn.d.ts +5 -0
  19. package/dist/playground/bqn.js +57 -0
  20. package/dist/playground/bqnPreflight.d.ts +26 -0
  21. package/dist/playground/bqnPreflight.js +399 -0
  22. package/dist/playground/c3.d.ts +15 -0
  23. package/dist/playground/c3.js +154 -0
  24. package/dist/playground/clang.d.ts +35 -19
  25. package/dist/playground/clang.js +241 -52
  26. package/dist/playground/clangAssetIntegrity.d.ts +32 -0
  27. package/dist/playground/clangAssetIntegrity.js +8 -0
  28. package/dist/playground/clojurescript.d.ts +5 -0
  29. package/dist/playground/clojurescript.js +59 -0
  30. package/dist/playground/clojurescriptPreflight.d.ts +26 -0
  31. package/dist/playground/clojurescriptPreflight.js +383 -0
  32. package/dist/playground/cobol.d.ts +46 -0
  33. package/dist/playground/cobol.js +703 -0
  34. package/dist/playground/d.d.ts +47 -0
  35. package/dist/playground/d.js +644 -0
  36. package/dist/playground/dOuterAssets.d.ts +16 -0
  37. package/dist/playground/dOuterAssets.js +163 -0
  38. package/dist/playground/dotnet.d.ts +99 -0
  39. package/dist/playground/dotnet.js +1131 -0
  40. package/dist/playground/duckdb.d.ts +36 -0
  41. package/dist/playground/duckdb.js +542 -0
  42. package/dist/playground/elixir.d.ts +18 -10
  43. package/dist/playground/elixir.js +630 -96
  44. package/dist/playground/elixirAssets.d.ts +6 -0
  45. package/dist/playground/elixirAssets.js +33 -0
  46. package/dist/playground/executionObservation.d.ts +22 -0
  47. package/dist/playground/executionObservation.js +65 -0
  48. package/dist/playground/forth.d.ts +5 -0
  49. package/dist/playground/forth.js +53 -0
  50. package/dist/playground/forthPreflight.d.ts +24 -0
  51. package/dist/playground/forthPreflight.js +198 -0
  52. package/dist/playground/fortran.d.ts +47 -0
  53. package/dist/playground/fortran.js +651 -0
  54. package/dist/playground/fortranAssets.d.ts +6 -0
  55. package/dist/playground/fortranAssets.js +27 -0
  56. package/dist/playground/gleam.d.ts +6 -0
  57. package/dist/playground/gleam.js +33 -0
  58. package/dist/playground/go.d.ts +17 -11
  59. package/dist/playground/go.js +376 -72
  60. package/dist/playground/goDebugInstrumentation.d.ts +1 -0
  61. package/dist/playground/goDebugInstrumentation.js +229 -0
  62. package/dist/playground/haskell.d.ts +44 -0
  63. package/dist/playground/haskell.js +678 -0
  64. package/dist/playground/haskellAssets.d.ts +24 -0
  65. package/dist/playground/haskellAssets.js +93 -0
  66. package/dist/playground/index.d.ts +1 -1
  67. package/dist/playground/index.js +360 -111
  68. package/dist/playground/j.d.ts +5 -0
  69. package/dist/playground/j.js +60 -0
  70. package/dist/playground/jPreflight.d.ts +26 -0
  71. package/dist/playground/jPreflight.js +372 -0
  72. package/dist/playground/janet.d.ts +5 -0
  73. package/dist/playground/janet.js +64 -0
  74. package/dist/playground/java.d.ts +24 -10
  75. package/dist/playground/java.js +706 -84
  76. package/dist/playground/javaSource.d.ts +5 -0
  77. package/dist/playground/javaSource.js +16 -0
  78. package/dist/playground/javaStdin.d.ts +1 -1
  79. package/dist/playground/javaStdin.js +13 -4
  80. package/dist/playground/julia.d.ts +5 -0
  81. package/dist/playground/julia.js +64 -0
  82. package/dist/playground/lfortran.d.ts +8 -0
  83. package/dist/playground/lfortran.js +30 -0
  84. package/dist/playground/lfortranAssets.d.ts +21 -0
  85. package/dist/playground/lfortranAssets.js +118 -0
  86. package/dist/playground/lisp.d.ts +45 -0
  87. package/dist/playground/lisp.js +640 -0
  88. package/dist/playground/lispAssets.d.ts +9 -0
  89. package/dist/playground/lispAssets.js +74 -0
  90. package/dist/playground/lldbManifest.d.ts +3 -0
  91. package/dist/playground/lldbManifest.js +155 -0
  92. package/dist/playground/lldbSession.d.ts +115 -0
  93. package/dist/playground/lldbSession.js +1347 -0
  94. package/dist/playground/loadingProgress.d.ts +16 -0
  95. package/dist/playground/loadingProgress.js +166 -0
  96. package/dist/playground/lua.d.ts +44 -0
  97. package/dist/playground/lua.js +630 -0
  98. package/dist/playground/nim.d.ts +5 -0
  99. package/dist/playground/nim.js +76 -0
  100. package/dist/playground/objectivec.d.ts +39 -0
  101. package/dist/playground/objectivec.js +288 -0
  102. package/dist/playground/ocaml.d.ts +28 -10
  103. package/dist/playground/ocaml.js +815 -253
  104. package/dist/playground/octave.d.ts +43 -0
  105. package/dist/playground/octave.js +783 -0
  106. package/dist/playground/options.d.ts +19 -40
  107. package/dist/playground/options.js +2 -1
  108. package/dist/playground/pascal.d.ts +5 -0
  109. package/dist/playground/pascal.js +60 -0
  110. package/dist/playground/perl.d.ts +5 -0
  111. package/dist/playground/perl.js +61 -0
  112. package/dist/playground/php.d.ts +44 -0
  113. package/dist/playground/php.js +665 -0
  114. package/dist/playground/prolog.d.ts +6 -0
  115. package/dist/playground/prolog.js +75 -0
  116. package/dist/playground/python.d.ts +20 -14
  117. package/dist/playground/python.js +445 -101
  118. package/dist/playground/pythonPackageLock.d.ts +6 -0
  119. package/dist/playground/pythonPackageLock.js +56 -0
  120. package/dist/playground/r.d.ts +44 -0
  121. package/dist/playground/r.js +637 -0
  122. package/dist/playground/ruby.d.ts +46 -0
  123. package/dist/playground/ruby.js +732 -0
  124. package/dist/playground/rubyAssets.d.ts +23 -0
  125. package/dist/playground/rubyAssets.js +68 -0
  126. package/dist/playground/rubyTestPreflight.d.ts +2 -0
  127. package/dist/playground/rubyTestPreflight.js +18 -0
  128. package/dist/playground/runtimeModule.d.ts +1 -0
  129. package/dist/playground/runtimeModule.js +5 -0
  130. package/dist/playground/rust.d.ts +44 -13
  131. package/dist/playground/rust.js +714 -76
  132. package/dist/playground/rustExecutableGraph.d.ts +85 -0
  133. package/dist/playground/rustExecutableGraph.js +946 -0
  134. package/dist/playground/rustWorkerLimits.d.ts +17 -0
  135. package/dist/playground/rustWorkerLimits.js +34 -0
  136. package/dist/playground/sandbox.d.ts +16 -10
  137. package/dist/playground/sharedBuffer.d.ts +6 -0
  138. package/dist/playground/sharedBuffer.js +12 -0
  139. package/dist/playground/sqlite.d.ts +38 -0
  140. package/dist/playground/sqlite.js +550 -0
  141. package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -0
  142. package/dist/playground/staticRuntimeModuleVersion.js +2 -0
  143. package/dist/playground/staticRuntimePreflight.d.ts +13 -0
  144. package/dist/playground/staticRuntimePreflight.js +231 -0
  145. package/dist/playground/staticRuntimePreflightExecute.d.ts +8 -0
  146. package/dist/playground/staticRuntimePreflightExecute.js +66 -0
  147. package/dist/playground/staticRuntimePreflightProtocol.d.ts +68 -0
  148. package/dist/playground/staticRuntimePreflightProtocol.js +339 -0
  149. package/dist/playground/staticStdinRing.d.ts +45 -0
  150. package/dist/playground/staticStdinRing.js +158 -0
  151. package/dist/playground/staticWorkerRuntime.d.ts +154 -0
  152. package/dist/playground/staticWorkerRuntime.js +1917 -0
  153. package/dist/playground/stdinBuffer.d.ts +9 -7
  154. package/dist/playground/stdinBuffer.js +9 -18
  155. package/dist/playground/swift.d.ts +5 -0
  156. package/dist/playground/swift.js +17 -0
  157. package/dist/playground/tcl.d.ts +5 -0
  158. package/dist/playground/tcl.js +62 -0
  159. package/dist/playground/teavmConfig.d.ts +1 -1
  160. package/dist/playground/teavmConfig.js +2 -2
  161. package/dist/playground/tinygo.d.ts +48 -18
  162. package/dist/playground/tinygo.js +1202 -329
  163. package/dist/playground/tinygoExecutableGraph.d.ts +44 -0
  164. package/dist/playground/tinygoExecutableGraph.js +449 -0
  165. package/dist/playground/typescript.d.ts +55 -0
  166. package/dist/playground/typescript.js +924 -0
  167. package/dist/playground/wasm.d.ts +43 -0
  168. package/dist/playground/wasm.js +608 -0
  169. package/dist/playground/wasmAwkVersion.d.ts +59 -0
  170. package/dist/playground/wasmAwkVersion.js +31 -0
  171. package/dist/playground/wasmBashVersion.d.ts +63 -0
  172. package/dist/playground/wasmBashVersion.js +36 -0
  173. package/dist/playground/wasmBqnVersion.d.ts +24 -0
  174. package/dist/playground/wasmBqnVersion.js +24 -0
  175. package/dist/playground/wasmC3Version.d.ts +20 -0
  176. package/dist/playground/wasmC3Version.js +21 -0
  177. package/dist/playground/wasmClojureScriptVersion.d.ts +21 -0
  178. package/dist/playground/wasmClojureScriptVersion.js +21 -0
  179. package/dist/playground/wasmDIntegrity.d.ts +15 -0
  180. package/dist/playground/wasmDIntegrity.js +15 -0
  181. package/dist/playground/wasmDVersion.d.ts +1 -0
  182. package/dist/playground/wasmDVersion.js +1 -0
  183. package/dist/playground/wasmDebugVersion.d.ts +6 -0
  184. package/dist/playground/wasmDebugVersion.js +6 -0
  185. package/dist/playground/wasmDotnetVersion.d.ts +1 -0
  186. package/dist/playground/wasmDotnetVersion.js +1 -0
  187. package/dist/playground/wasmElixirVersion.d.ts +21 -1
  188. package/dist/playground/wasmElixirVersion.js +21 -1
  189. package/dist/playground/wasmForthVersion.d.ts +18 -0
  190. package/dist/playground/wasmForthVersion.js +18 -0
  191. package/dist/playground/wasmFortranExecutionAssets.d.ts +15 -0
  192. package/dist/playground/wasmFortranExecutionAssets.js +15 -0
  193. package/dist/playground/wasmFortranVersion.d.ts +1 -0
  194. package/dist/playground/wasmFortranVersion.js +1 -0
  195. package/dist/playground/wasmGleamVersion.d.ts +5 -0
  196. package/dist/playground/wasmGleamVersion.js +5 -0
  197. package/dist/playground/wasmGoVersion.d.ts +1 -1
  198. package/dist/playground/wasmGoVersion.js +1 -1
  199. package/dist/playground/wasmHaskellVersion.d.ts +1 -0
  200. package/dist/playground/wasmHaskellVersion.js +1 -0
  201. package/dist/playground/wasmJVersion.d.ts +24 -0
  202. package/dist/playground/wasmJVersion.js +24 -0
  203. package/dist/playground/wasmJanetVersion.d.ts +53 -0
  204. package/dist/playground/wasmJanetVersion.js +30 -0
  205. package/dist/playground/wasmJuliaVersion.d.ts +71 -0
  206. package/dist/playground/wasmJuliaVersion.js +39 -0
  207. package/dist/playground/wasmLfortranVersion.d.ts +28 -0
  208. package/dist/playground/wasmLfortranVersion.js +29 -0
  209. package/dist/playground/wasmLispVersion.d.ts +1 -0
  210. package/dist/playground/wasmLispVersion.js +1 -0
  211. package/dist/playground/wasmLuaVersion.d.ts +1 -0
  212. package/dist/playground/wasmLuaVersion.js +1 -0
  213. package/dist/playground/wasmNimVersion.d.ts +125 -0
  214. package/dist/playground/wasmNimVersion.js +66 -0
  215. package/dist/playground/wasmObjectiveCVersion.d.ts +27 -0
  216. package/dist/playground/wasmObjectiveCVersion.js +27 -0
  217. package/dist/playground/wasmOcamlVersion.d.ts +12 -1
  218. package/dist/playground/wasmOcamlVersion.js +12 -1
  219. package/dist/playground/wasmOctaveVersion.d.ts +1 -0
  220. package/dist/playground/wasmOctaveVersion.js +1 -0
  221. package/dist/playground/wasmPascalVersion.d.ts +61 -0
  222. package/dist/playground/wasmPascalVersion.js +34 -0
  223. package/dist/playground/wasmPerlVersion.d.ts +71 -0
  224. package/dist/playground/wasmPerlVersion.js +39 -0
  225. package/dist/playground/wasmPrologVersion.d.ts +31 -0
  226. package/dist/playground/wasmPrologVersion.js +31 -0
  227. package/dist/playground/wasmRVersion.d.ts +1 -0
  228. package/dist/playground/wasmRVersion.js +1 -0
  229. package/dist/playground/wasmRustVersion.d.ts +1306 -1
  230. package/dist/playground/wasmRustVersion.js +1458 -1
  231. package/dist/playground/wasmSwiftVersion.d.ts +1 -0
  232. package/dist/playground/wasmSwiftVersion.js +1 -0
  233. package/dist/playground/wasmTclVersion.d.ts +85 -0
  234. package/dist/playground/wasmTclVersion.js +46 -0
  235. package/dist/playground/wasmTinyGoVersion.d.ts +98 -1
  236. package/dist/playground/wasmTinyGoVersion.js +107 -1
  237. package/dist/playground/wasmTypeScriptVersion.d.ts +5 -0
  238. package/dist/playground/wasmTypeScriptVersion.js +5 -0
  239. package/dist/playground/wasmWatVersion.d.ts +1 -0
  240. package/dist/playground/wasmWatVersion.js +1 -0
  241. package/dist/playground/wasmZigVersion.d.ts +13 -0
  242. package/dist/playground/wasmZigVersion.js +13 -0
  243. package/dist/playground/wat.d.ts +44 -0
  244. package/dist/playground/wat.js +622 -0
  245. package/dist/playground/worker/assemblyscript.js +339 -0
  246. package/dist/playground/worker/assets.d.ts +7 -0
  247. package/dist/playground/worker/assets.js +288 -39
  248. package/dist/playground/worker/bash.js +338 -0
  249. package/dist/playground/worker/bashNestedBootstrap.d.ts +6 -0
  250. package/dist/playground/worker/bashNestedBootstrap.js +59 -0
  251. package/dist/playground/worker/bashRuntime.d.ts +89 -0
  252. package/dist/playground/worker/bashRuntime.js +982 -0
  253. package/dist/playground/worker/clang.js +92 -13
  254. package/dist/playground/worker/cobol.js +107 -0
  255. package/dist/playground/worker/d.js +199 -0
  256. package/dist/playground/worker/dotnet.js +141 -0
  257. package/dist/playground/worker/duckdb.d.ts +1 -0
  258. package/dist/playground/worker/duckdb.js +136 -0
  259. package/dist/playground/worker/elixir.js +307 -41
  260. package/dist/playground/worker/fortran.d.ts +1 -0
  261. package/dist/playground/worker/fortran.js +295 -0
  262. package/dist/playground/worker/go.js +246 -40
  263. package/dist/playground/worker/haskell.d.ts +7 -0
  264. package/dist/playground/worker/haskell.js +465 -0
  265. package/dist/playground/worker/java.js +59 -20
  266. package/dist/playground/worker/lisp.d.ts +1 -0
  267. package/dist/playground/worker/lisp.js +195 -0
  268. package/dist/playground/worker/lua.d.ts +1 -0
  269. package/dist/playground/worker/lua.js +163 -0
  270. package/dist/playground/worker/objectivec.d.ts +1 -0
  271. package/dist/playground/worker/objectivec.js +10 -0
  272. package/dist/playground/worker/ocaml.js +206 -58
  273. package/dist/playground/worker/php.d.ts +1 -0
  274. package/dist/playground/worker/php.js +261 -0
  275. package/dist/playground/worker/python.js +201 -44
  276. package/dist/playground/worker/r.d.ts +1 -0
  277. package/dist/playground/worker/r.js +192 -0
  278. package/dist/playground/worker/ruby.d.ts +1 -0
  279. package/dist/playground/worker/ruby.js +248 -0
  280. package/dist/playground/worker/runtimeAssetFetch.d.ts +15 -0
  281. package/dist/playground/worker/runtimeAssetFetch.js +375 -0
  282. package/dist/playground/worker/rust.js +546 -20
  283. package/dist/playground/worker/sqlite.d.ts +1 -0
  284. package/dist/playground/worker/sqlite.js +112 -0
  285. package/dist/playground/worker/staticRuntimePreflight.d.ts +1 -0
  286. package/dist/playground/worker/staticRuntimePreflight.js +56 -0
  287. package/dist/playground/worker/tinygo.js +34 -9
  288. package/dist/playground/worker/typescript.d.ts +1 -0
  289. package/dist/playground/worker/typescript.js +251 -0
  290. package/dist/playground/worker/wasm.d.ts +1 -0
  291. package/dist/playground/worker/wasm.js +273 -0
  292. package/dist/playground/worker/wat.d.ts +1 -0
  293. package/dist/playground/worker/wat.js +188 -0
  294. package/dist/playground/worker/zig.d.ts +8 -0
  295. package/dist/playground/worker/zig.js +578 -0
  296. package/dist/playground/workerProgress.d.ts +15 -0
  297. package/dist/playground/workerProgress.js +72 -0
  298. package/dist/playground/workerSession.d.ts +28 -0
  299. package/dist/playground/workerSession.js +164 -0
  300. package/dist/playground/zig.d.ts +46 -0
  301. package/dist/playground/zig.js +690 -0
  302. package/dist/playground/zigAssets.d.ts +6 -0
  303. package/dist/playground/zigAssets.js +49 -0
  304. package/package.json +234 -105
  305. package/dist/clang/app.d.ts +0 -75
  306. package/dist/clang/app.js +0 -744
  307. package/dist/clang/apply.d.ts +0 -2
  308. package/dist/clang/apply.js +0 -11
  309. package/dist/clang/color.d.ts +0 -3
  310. package/dist/clang/color.js +0 -3
  311. package/dist/clang/encode.d.ts +0 -4
  312. package/dist/clang/encode.js +0 -20
  313. package/dist/clang/error.d.ts +0 -14
  314. package/dist/clang/error.js +0 -27
  315. package/dist/clang/gccCompat.d.ts +0 -15
  316. package/dist/clang/gccCompat.js +0 -767
  317. package/dist/clang/index.d.ts +0 -85
  318. package/dist/clang/index.js +0 -1077
  319. package/dist/clang/memory/index.d.ts +0 -4
  320. package/dist/clang/memory/index.js +0 -4
  321. package/dist/clang/memory/memFs.d.ts +0 -35
  322. package/dist/clang/memory/memFs.js +0 -132
  323. package/dist/clang/memory/memory.d.ts +0 -22
  324. package/dist/clang/memory/memory.js +0 -73
  325. package/dist/clang/memory/tar.d.ts +0 -2
  326. package/dist/clang/memory/tar.js +0 -59
  327. package/dist/clang/url.d.ts +0 -4
  328. package/dist/clang/url.js +0 -5
  329. package/dist/clang/wasm.d.ts +0 -4
  330. package/dist/clang/wasm.js +0 -50
  331. package/dist/clangd/config.d.ts +0 -18
  332. package/dist/clangd/config.js +0 -14
  333. package/dist/clangd/jsonStream.d.ts +0 -9
  334. package/dist/clangd/jsonStream.js +0 -48
  335. package/dist/clangd/session.d.ts +0 -18
  336. package/dist/clangd/session.js +0 -112
  337. package/dist/clangd/worker.js +0 -131
  338. package/dist/debug/controller.svelte.d.ts +0 -43
  339. package/dist/debug/controller.svelte.js +0 -268
  340. package/dist/debug/editor/index.d.ts +0 -2
  341. package/dist/debug/editor/index.js +0 -1
  342. package/dist/debug/editor/monaco.d.ts +0 -26
  343. package/dist/debug/editor/monaco.js +0 -128
  344. package/dist/debug/expression.d.ts +0 -26
  345. package/dist/debug/expression.js +0 -547
  346. package/dist/debug/index.d.ts +0 -8
  347. package/dist/debug/index.js +0 -5
  348. package/dist/debug/language/cpp.d.ts +0 -2
  349. package/dist/debug/language/cpp.js +0 -7
  350. package/dist/debug/language/index.d.ts +0 -3
  351. package/dist/debug/language/index.js +0 -2
  352. package/dist/debug/language/python.d.ts +0 -2
  353. package/dist/debug/language/python.js +0 -14
  354. package/dist/debug/language/types.d.ts +0 -6
  355. package/dist/debug/locals.d.ts +0 -2
  356. package/dist/debug/locals.js +0 -8
  357. package/dist/lsp/cpp/server.d.ts +0 -2
  358. package/dist/lsp/cpp/server.js +0 -68
  359. package/dist/lsp/index.d.ts +0 -5
  360. package/dist/lsp/index.js +0 -4
  361. package/dist/lsp/python/main.worker.js +0 -92
  362. package/dist/lsp/python/package/arcturus_python_lsp/__init__.py +0 -3
  363. package/dist/lsp/python/package/arcturus_python_lsp/server.py +0 -462
  364. package/dist/lsp/python/server.d.ts +0 -2
  365. package/dist/lsp/python/server.js +0 -54
  366. package/dist/lsp/registry.d.ts +0 -2
  367. package/dist/lsp/registry.js +0 -12
  368. package/dist/lsp/runtime.d.ts +0 -5
  369. package/dist/lsp/runtime.js +0 -31
  370. package/dist/lsp/types.d.ts +0 -17
  371. package/dist/terminal/Terminal.svelte +0 -422
  372. package/dist/terminal/Terminal.svelte.d.ts +0 -26
  373. package/dist/terminal/index.d.ts +0 -7
  374. package/dist/terminal/index.js +0 -5
  375. package/dist/terminal/plugin/index.d.ts +0 -9
  376. package/dist/terminal/plugin/index.js +0 -19
  377. package/dist/terminal/theme.d.ts +0 -49
  378. package/dist/terminal/theme.js +0 -49
  379. package/dist/terminal/types.d.ts +0 -18
  380. package/dist/utils/vscodeJsonrpcBrowser.d.ts +0 -5
  381. package/dist/utils/vscodeJsonrpcBrowser.js +0 -4
  382. /package/dist/{clangd/worker.d.ts → playground/worker/assemblyscript.d.ts} +0 -0
  383. /package/dist/{debug/language/types.js → playground/worker/bash.d.ts} +0 -0
  384. /package/dist/{lsp/python/main.worker.d.ts → playground/worker/cobol.d.ts} +0 -0
  385. /package/dist/{lsp/types.js → playground/worker/d.d.ts} +0 -0
  386. /package/dist/{terminal/types.js → playground/worker/dotnet.d.ts} +0 -0
@@ -0,0 +1,1131 @@
1
+ import { resolveDotnetModuleUrl } from './assets';
2
+ import {} from './options';
3
+ import { WorkerSession } from './workerSession';
4
+ import { reportWorkerInputReady, reportWorkerProgress } from './workerProgress';
5
+ import { BusyError, CancelledError, DEFAULT_WORKSPACE_LIMITS, DiagnosticLimitError, OutputLimitError, RuntimeConfigurationError, TimeoutError, WorkspaceValidationError, resolveExecutionLimits, validateExecutionWorkspace } from '@wasm-idle/core';
6
+ const executionLimitKeys = [
7
+ 'assetTimeoutMs',
8
+ 'startupTimeoutMs',
9
+ 'compileTimeoutMs',
10
+ 'runTimeoutMs',
11
+ 'maxOutputBytes',
12
+ 'maxDiagnostics',
13
+ 'maxWorkspaceBytes',
14
+ 'maxAssetBytes',
15
+ 'maxWasmMemoryBytes',
16
+ 'maxWorkers',
17
+ 'maxThreads'
18
+ ];
19
+ const OUTPUT_ENCODER = new TextEncoder();
20
+ const readsConsoleStdin = (code) => /\b(?:System\.)?Console\.(?:ReadLine|In)\b/.test(code);
21
+ class Dotnet {
22
+ language;
23
+ output = null;
24
+ worker = null;
25
+ runtimeModule = null;
26
+ compiler = null;
27
+ begin = 0;
28
+ elapse = 0;
29
+ uid = 0;
30
+ exit = true;
31
+ moduleUrl = '';
32
+ pendingInput = [];
33
+ pendingEof = false;
34
+ stdinWaiters = [];
35
+ compiledArtifact = null;
36
+ compiledCacheKey = '';
37
+ compiledRuntimeModule = null;
38
+ compiledCompiler = null;
39
+ compiledCompile = null;
40
+ compiledExecute = null;
41
+ oncompilerdiagnostic;
42
+ activeExplicitStdinCleanup = null;
43
+ activeOperation = null;
44
+ disposed = false;
45
+ disposePromise = null;
46
+ disposeCancellation;
47
+ workerSession = new WorkerSession({
48
+ label: () => this.languageLabel,
49
+ onDispose: (worker) => {
50
+ this.activeExplicitStdinCleanup?.();
51
+ if (this.worker === worker)
52
+ delete this.worker;
53
+ this.exit = true;
54
+ }
55
+ });
56
+ constructor(language = 'FSHARP') {
57
+ this.language = language;
58
+ this.disposeCancellation = new CancelledError(`${this.languageLabel} sandbox disposed`, {
59
+ phase: 'dispose',
60
+ runtimeId: this.language,
61
+ recoverable: false
62
+ });
63
+ }
64
+ get compileLanguage() {
65
+ return this.language === 'CSHARP'
66
+ ? 'csharp'
67
+ : this.language === 'VBNET'
68
+ ? 'vbnet'
69
+ : 'fsharp';
70
+ }
71
+ get languageLabel() {
72
+ return this.language === 'CSHARP' ? 'C#' : this.language === 'VBNET' ? 'VB.NET' : 'F#';
73
+ }
74
+ beginOperation(phase) {
75
+ if (this.disposed) {
76
+ throw new RuntimeConfigurationError(`${this.languageLabel} sandbox is disposed`, {
77
+ phase: 'dispose',
78
+ runtimeId: this.language
79
+ });
80
+ }
81
+ if (this.activeOperation) {
82
+ throw new BusyError(`${this.languageLabel} runtime already has an active operation`, {
83
+ runtimeId: this.language,
84
+ phase: this.activeOperation.phase
85
+ });
86
+ }
87
+ const operation = {
88
+ token: Symbol(phase),
89
+ phase,
90
+ cancelled: false,
91
+ deferCompletion: false,
92
+ abortReasonReading: false,
93
+ sessionActive: false
94
+ };
95
+ this.activeOperation = operation;
96
+ return operation;
97
+ }
98
+ completeOperation(operation) {
99
+ operation.deferredReject = undefined;
100
+ this.releaseOperationTimeout(operation);
101
+ if (this.activeOperation?.token === operation.token)
102
+ this.activeOperation = null;
103
+ this.releaseAbortSignal(operation);
104
+ }
105
+ isOperationActive(operation) {
106
+ return this.activeOperation?.token === operation.token && !operation.cancelled;
107
+ }
108
+ releaseBeforeSession(operation, fallback) {
109
+ const outcome = operation.cancelled ? operation.cancellationReason : fallback;
110
+ this.completeOperation(operation);
111
+ return outcome;
112
+ }
113
+ releaseAbortSignal(operation) {
114
+ const { signal, onAbort } = operation;
115
+ operation.signal = undefined;
116
+ operation.onAbort = undefined;
117
+ if (signal && onAbort) {
118
+ try {
119
+ signal.removeEventListener('abort', onAbort);
120
+ }
121
+ catch {
122
+ // Listener cleanup must not replace the operation result.
123
+ }
124
+ }
125
+ }
126
+ releaseOperationTimeout(operation) {
127
+ const timeout = operation.timeout;
128
+ operation.timeout = undefined;
129
+ if (timeout === undefined)
130
+ return;
131
+ try {
132
+ clearTimeout(timeout);
133
+ }
134
+ catch {
135
+ // Timer cleanup must not replace the operation result.
136
+ }
137
+ }
138
+ abortReason(signal, phase) {
139
+ const reason = signal.reason;
140
+ if (reason !== undefined)
141
+ return reason;
142
+ return new DOMException(phase === 'startup'
143
+ ? `${this.languageLabel} runtime startup aborted`
144
+ : `${this.languageLabel} execution aborted`, 'AbortError');
145
+ }
146
+ abortOperation(operation, reason) {
147
+ if (!this.isOperationActive(operation)) {
148
+ this.releaseAbortSignal(operation);
149
+ return;
150
+ }
151
+ const rejectDeferred = operation.deferredReject;
152
+ operation.deferredReject = undefined;
153
+ operation.cancelled = true;
154
+ operation.cancellationReason = reason;
155
+ this.activeExplicitStdinCleanup?.();
156
+ this.uid += 1;
157
+ this.resolveStdinWaiters();
158
+ this.workerSession.terminate(reason);
159
+ this.exit = true;
160
+ rejectDeferred?.(reason);
161
+ if (operation.deferCompletion) {
162
+ this.releaseOperationTimeout(operation);
163
+ this.releaseAbortSignal(operation);
164
+ }
165
+ else
166
+ this.completeOperation(operation);
167
+ }
168
+ cancelBeforeSession(operation, reason) {
169
+ if (!this.isOperationActive(operation))
170
+ return;
171
+ operation.cancelled = true;
172
+ operation.cancellationReason = reason;
173
+ this.completeOperation(operation);
174
+ }
175
+ bindAbortSignal(operation, signal) {
176
+ if (!signal || !this.isOperationActive(operation))
177
+ return;
178
+ const onAbort = () => {
179
+ if (!this.isOperationActive(operation) || operation.abortReasonReading)
180
+ return;
181
+ operation.abortReasonReading = true;
182
+ let reason;
183
+ try {
184
+ reason = this.abortReason(signal, operation.phase);
185
+ }
186
+ catch (error) {
187
+ reason = error;
188
+ }
189
+ finally {
190
+ operation.abortReasonReading = false;
191
+ }
192
+ if (!this.isOperationActive(operation))
193
+ return;
194
+ if (operation.sessionActive)
195
+ this.abortOperation(operation, reason);
196
+ else
197
+ this.cancelBeforeSession(operation, reason);
198
+ };
199
+ operation.signal = signal;
200
+ operation.onAbort = onAbort;
201
+ try {
202
+ signal.addEventListener('abort', onAbort, { once: true });
203
+ }
204
+ catch (error) {
205
+ if (!this.isOperationActive(operation))
206
+ return;
207
+ let signalAborted = false;
208
+ try {
209
+ signalAborted = signal.aborted;
210
+ }
211
+ catch {
212
+ if (!this.isOperationActive(operation))
213
+ return;
214
+ }
215
+ if (signalAborted)
216
+ onAbort();
217
+ else
218
+ this.cancelBeforeSession(operation, error);
219
+ return;
220
+ }
221
+ if (!this.isOperationActive(operation))
222
+ return;
223
+ try {
224
+ if (signal.aborted)
225
+ onAbort();
226
+ }
227
+ catch (error) {
228
+ if (this.isOperationActive(operation))
229
+ this.cancelBeforeSession(operation, error);
230
+ }
231
+ }
232
+ bindOperationTimeout(operation, timeoutMs) {
233
+ if (!this.isOperationActive(operation))
234
+ return;
235
+ let timeout;
236
+ try {
237
+ timeout = setTimeout(() => {
238
+ if (operation.timeout === timeout)
239
+ operation.timeout = undefined;
240
+ if (!this.isOperationActive(operation))
241
+ return;
242
+ const label = operation.phase === 'startup' ? 'runtime startup' : 'execution';
243
+ this.abortOperation(operation, new TimeoutError(`${this.languageLabel} ${label} timed out after ${timeoutMs} ms`, {
244
+ phase: operation.phase,
245
+ runtimeId: this.language,
246
+ timeoutMs
247
+ }));
248
+ }, timeoutMs);
249
+ }
250
+ catch (error) {
251
+ this.abortOperation(operation, error);
252
+ return;
253
+ }
254
+ if (!this.isOperationActive(operation)) {
255
+ if (this.activeOperation?.token === operation.token)
256
+ operation.timeout = timeout;
257
+ return;
258
+ }
259
+ operation.timeout = timeout;
260
+ }
261
+ resolveOperationLimits(operation, configured) {
262
+ if (!configured)
263
+ return resolveExecutionLimits();
264
+ const snapshot = {};
265
+ for (const key of executionLimitKeys) {
266
+ const enumerable = Object.prototype.propertyIsEnumerable.call(configured, key);
267
+ if (!this.isOperationActive(operation))
268
+ throw operation.cancellationReason;
269
+ if (!enumerable)
270
+ continue;
271
+ snapshot[key] = configured[key];
272
+ if (!this.isOperationActive(operation))
273
+ throw operation.cancellationReason;
274
+ }
275
+ return resolveExecutionLimits(snapshot);
276
+ }
277
+ clearCompiledArtifact() {
278
+ this.compiledArtifact = null;
279
+ this.compiledCacheKey = '';
280
+ this.compiledRuntimeModule = null;
281
+ this.compiledCompiler = null;
282
+ this.compiledCompile = null;
283
+ this.compiledExecute = null;
284
+ }
285
+ shouldRunOnMainThread() {
286
+ // Compiler and user-program execution must remain physically cancellable.
287
+ // Keep the legacy backend implementation below until its state machinery can
288
+ // be removed independently, but never select it through the public runtime.
289
+ return false;
290
+ }
291
+ load(runtimeAssets = '', _code = '', _log = true, _args = [], options = {}, progress) {
292
+ let operation;
293
+ try {
294
+ operation = this.beginOperation('startup');
295
+ }
296
+ catch (error) {
297
+ return Promise.reject(error);
298
+ }
299
+ let signal;
300
+ let limits;
301
+ let nextModuleUrl;
302
+ let runOnMainThread;
303
+ try {
304
+ signal = options.signal;
305
+ if (!this.isOperationActive(operation)) {
306
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime startup cancelled`));
307
+ }
308
+ this.bindAbortSignal(operation, signal);
309
+ if (!this.isOperationActive(operation)) {
310
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime startup cancelled`));
311
+ }
312
+ const configuredLimits = options.limits;
313
+ if (!this.isOperationActive(operation)) {
314
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime startup cancelled`));
315
+ }
316
+ limits = this.resolveOperationLimits(operation, configuredLimits);
317
+ if (!this.isOperationActive(operation)) {
318
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime startup cancelled`));
319
+ }
320
+ const currentUrl = typeof window !== 'undefined' ? window.location.href : '';
321
+ if (!this.isOperationActive(operation)) {
322
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime startup cancelled`));
323
+ }
324
+ if (typeof runtimeAssets === 'string') {
325
+ nextModuleUrl = resolveDotnetModuleUrl(runtimeAssets, currentUrl);
326
+ }
327
+ else {
328
+ const dotnetAssets = runtimeAssets?.dotnet;
329
+ if (!this.isOperationActive(operation)) {
330
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime startup cancelled`));
331
+ }
332
+ const configuredModuleUrl = dotnetAssets?.moduleUrl;
333
+ if (!this.isOperationActive(operation)) {
334
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime startup cancelled`));
335
+ }
336
+ nextModuleUrl = resolveDotnetModuleUrl(configuredModuleUrl === undefined
337
+ ? {}
338
+ : { dotnet: { moduleUrl: configuredModuleUrl } }, currentUrl);
339
+ if (!nextModuleUrl) {
340
+ const rootUrl = runtimeAssets?.rootUrl;
341
+ if (!this.isOperationActive(operation)) {
342
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime startup cancelled`));
343
+ }
344
+ nextModuleUrl = resolveDotnetModuleUrl({ rootUrl }, currentUrl);
345
+ }
346
+ }
347
+ if (!this.isOperationActive(operation)) {
348
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime startup cancelled`));
349
+ }
350
+ if (!nextModuleUrl) {
351
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime is not configured. Set runtimeAssets.dotnet.moduleUrl or PUBLIC_WASM_DOTNET_MODULE_URL.`));
352
+ }
353
+ runOnMainThread = this.shouldRunOnMainThread();
354
+ if (!this.isOperationActive(operation)) {
355
+ return Promise.reject(this.releaseBeforeSession(operation, `${this.languageLabel} runtime startup cancelled`));
356
+ }
357
+ }
358
+ catch (error) {
359
+ return Promise.reject(this.releaseBeforeSession(operation, error));
360
+ }
361
+ operation.sessionActive = true;
362
+ const loading = this.workerSession.load(async (resolve, reject) => {
363
+ try {
364
+ if (!this.isOperationActive(operation))
365
+ return;
366
+ const needsWorkerReset = !this.worker || this.moduleUrl !== nextModuleUrl;
367
+ const needsRuntimeReset = !this.runtimeModule || !this.compiler || this.moduleUrl !== nextModuleUrl;
368
+ if (runOnMainThread) {
369
+ let runtimeModule = this.runtimeModule;
370
+ let compiler = this.compiler;
371
+ if (needsRuntimeReset) {
372
+ runtimeModule = (await import(
373
+ /* @vite-ignore */ nextModuleUrl));
374
+ if (!this.isOperationActive(operation))
375
+ return;
376
+ if (typeof runtimeModule.createDotnetCompiler !== 'function') {
377
+ return reject('wasm-dotnet module must export createDotnetCompiler');
378
+ }
379
+ if (typeof runtimeModule.executeBrowserDotnetArtifact !== 'function') {
380
+ return reject('wasm-dotnet module must export executeBrowserDotnetArtifact');
381
+ }
382
+ compiler = runtimeModule.createDotnetCompiler();
383
+ if (!this.isOperationActive(operation))
384
+ return;
385
+ }
386
+ if (!this.isOperationActive(operation))
387
+ return;
388
+ progress?.set?.(1);
389
+ if (!this.isOperationActive(operation))
390
+ return;
391
+ if (this.worker)
392
+ this.workerSession.reset();
393
+ if (!this.isOperationActive(operation))
394
+ return;
395
+ this.moduleUrl = nextModuleUrl;
396
+ this.runtimeModule = runtimeModule;
397
+ this.compiler = compiler;
398
+ if (needsRuntimeReset) {
399
+ this.clearCompiledArtifact();
400
+ }
401
+ resolve();
402
+ this.completeOperation(operation);
403
+ return;
404
+ }
405
+ if (needsWorkerReset) {
406
+ const WorkerConstructor = (await import('./worker/dotnet?worker'))
407
+ .default;
408
+ if (!this.isOperationActive(operation))
409
+ return;
410
+ const worker = new WorkerConstructor();
411
+ if (!this.isOperationActive(operation)) {
412
+ worker.terminate();
413
+ return;
414
+ }
415
+ this.worker = worker;
416
+ this.workerSession.attach(worker);
417
+ if (!this.isOperationActive(operation) || this.worker !== worker) {
418
+ this.workerSession.release(worker);
419
+ return;
420
+ }
421
+ worker.onmessage = (event) => {
422
+ if (!this.isOperationActive(operation) || this.worker !== worker)
423
+ return;
424
+ try {
425
+ if (event.data?.load) {
426
+ progress?.set?.(1);
427
+ if (!this.isOperationActive(operation) || this.worker !== worker)
428
+ return;
429
+ this.moduleUrl = nextModuleUrl;
430
+ this.runtimeModule = null;
431
+ this.compiler = null;
432
+ this.clearCompiledArtifact();
433
+ resolve();
434
+ this.completeOperation(operation);
435
+ return;
436
+ }
437
+ if (event.data?.error)
438
+ reject(event.data.error);
439
+ }
440
+ catch (error) {
441
+ reject(error);
442
+ }
443
+ };
444
+ worker.postMessage({
445
+ load: true,
446
+ moduleUrl: nextModuleUrl
447
+ });
448
+ }
449
+ else {
450
+ if (!this.isOperationActive(operation))
451
+ return;
452
+ progress?.set?.(1);
453
+ if (!this.isOperationActive(operation))
454
+ return;
455
+ this.moduleUrl = nextModuleUrl;
456
+ this.runtimeModule = null;
457
+ this.compiler = null;
458
+ this.clearCompiledArtifact();
459
+ resolve();
460
+ this.completeOperation(operation);
461
+ }
462
+ }
463
+ catch (error) {
464
+ reject(error?.message || String(error));
465
+ }
466
+ });
467
+ this.bindOperationTimeout(operation, Math.min(2_147_483_647, limits.assetTimeoutMs + limits.startupTimeoutMs));
468
+ return loading.finally(() => this.completeOperation(operation));
469
+ }
470
+ write(input) {
471
+ if (this.disposed)
472
+ return;
473
+ this.pendingInput.push(input);
474
+ this.pendingEof = false;
475
+ this.resolveStdinWaiters();
476
+ }
477
+ eof() {
478
+ if (this.disposed)
479
+ return;
480
+ this.pendingEof = true;
481
+ this.resolveStdinWaiters();
482
+ }
483
+ resolveStdinWaiters() {
484
+ const waiters = this.stdinWaiters.splice(0);
485
+ for (const resolve of waiters)
486
+ resolve();
487
+ }
488
+ resetStdinState() {
489
+ this.pendingInput = [];
490
+ this.pendingEof = false;
491
+ this.resolveStdinWaiters();
492
+ }
493
+ async collectStdinForRun(code, prepare, explicitStdin, runUid, progress) {
494
+ const hasExplicitStdin = !prepare && explicitStdin !== undefined;
495
+ if (runUid !== this.uid)
496
+ return '';
497
+ if (!prepare &&
498
+ !hasExplicitStdin &&
499
+ this.pendingInput.length === 0 &&
500
+ !this.pendingEof &&
501
+ readsConsoleStdin(code)) {
502
+ reportWorkerInputReady(progress, `${this.languageLabel} runtime ready for input`);
503
+ if (runUid !== this.uid)
504
+ return '';
505
+ await new Promise((resolve) => this.stdinWaiters.push(resolve));
506
+ }
507
+ if (runUid !== this.uid)
508
+ return '';
509
+ if (hasExplicitStdin)
510
+ return explicitStdin;
511
+ const stdin = `${explicitStdin ?? ''}${this.pendingInput.join('')}`;
512
+ if (!prepare) {
513
+ this.pendingInput = [];
514
+ this.pendingEof = false;
515
+ }
516
+ return stdin;
517
+ }
518
+ async run(code, prepare, _log = true, _prog, args = [], options = {}) {
519
+ const operation = this.beginOperation('execute');
520
+ let signal;
521
+ let limits;
522
+ let request;
523
+ try {
524
+ signal = options.signal;
525
+ if (!this.isOperationActive(operation)) {
526
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
527
+ }
528
+ this.bindAbortSignal(operation, signal);
529
+ if (!this.isOperationActive(operation)) {
530
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
531
+ }
532
+ const configuredLimits = options.limits;
533
+ if (!this.isOperationActive(operation)) {
534
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
535
+ }
536
+ limits = this.resolveOperationLimits(operation, configuredLimits);
537
+ if (!this.isOperationActive(operation)) {
538
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
539
+ }
540
+ const configuredWorkspaceFiles = options.workspaceFiles;
541
+ if (!this.isOperationActive(operation)) {
542
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
543
+ }
544
+ const workspaceFilesSource = configuredWorkspaceFiles === undefined ? [] : configuredWorkspaceFiles;
545
+ if (!Array.isArray(workspaceFilesSource)) {
546
+ throw new TypeError(`${this.languageLabel} workspace files must be an array`);
547
+ }
548
+ const workspaceLimitsSource = options.workspaceLimits;
549
+ if (!this.isOperationActive(operation)) {
550
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
551
+ }
552
+ let workspaceLimits = {};
553
+ if (workspaceLimitsSource !== undefined) {
554
+ if (workspaceLimitsSource === null ||
555
+ typeof workspaceLimitsSource !== 'object' ||
556
+ Array.isArray(workspaceLimitsSource)) {
557
+ throw new TypeError(`${this.languageLabel} workspace limits must be an object`);
558
+ }
559
+ const maxFiles = workspaceLimitsSource.maxFiles;
560
+ if (!this.isOperationActive(operation)) {
561
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
562
+ }
563
+ if (maxFiles !== undefined && (!Number.isSafeInteger(maxFiles) || maxFiles < 0)) {
564
+ throw new WorkspaceValidationError('invalid-limit', 'Workspace limit maxFiles must be a non-negative safe integer');
565
+ }
566
+ const maxFileBytes = workspaceLimitsSource.maxFileBytes;
567
+ if (!this.isOperationActive(operation)) {
568
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
569
+ }
570
+ if (maxFileBytes !== undefined &&
571
+ (!Number.isSafeInteger(maxFileBytes) || maxFileBytes < 0)) {
572
+ throw new WorkspaceValidationError('invalid-limit', 'Workspace limit maxFileBytes must be a non-negative safe integer');
573
+ }
574
+ const maxTotalBytes = workspaceLimitsSource.maxTotalBytes;
575
+ if (!this.isOperationActive(operation)) {
576
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
577
+ }
578
+ if (maxTotalBytes !== undefined &&
579
+ (!Number.isSafeInteger(maxTotalBytes) || maxTotalBytes < 0)) {
580
+ throw new WorkspaceValidationError('invalid-limit', 'Workspace limit maxTotalBytes must be a non-negative safe integer');
581
+ }
582
+ const maxPathBytes = workspaceLimitsSource.maxPathBytes;
583
+ if (!this.isOperationActive(operation)) {
584
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
585
+ }
586
+ if (maxPathBytes !== undefined &&
587
+ (!Number.isSafeInteger(maxPathBytes) || maxPathBytes < 0)) {
588
+ throw new WorkspaceValidationError('invalid-limit', 'Workspace limit maxPathBytes must be a non-negative safe integer');
589
+ }
590
+ const caseSensitive = workspaceLimitsSource.caseSensitive;
591
+ if (!this.isOperationActive(operation)) {
592
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
593
+ }
594
+ if (caseSensitive !== undefined && typeof caseSensitive !== 'boolean') {
595
+ throw new WorkspaceValidationError('invalid-limit', 'Workspace limit caseSensitive must be a boolean');
596
+ }
597
+ workspaceLimits = {
598
+ maxFiles,
599
+ maxFileBytes,
600
+ maxTotalBytes,
601
+ maxPathBytes,
602
+ caseSensitive
603
+ };
604
+ }
605
+ const maxFiles = workspaceLimits.maxFiles ?? DEFAULT_WORKSPACE_LIMITS.maxFiles;
606
+ const workspaceFileCount = workspaceFilesSource.length;
607
+ if (!this.isOperationActive(operation)) {
608
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
609
+ }
610
+ if (!Number.isSafeInteger(workspaceFileCount) || workspaceFileCount < 0) {
611
+ throw new WorkspaceValidationError('file-count-limit', '.NET workspace file count must be a non-negative safe integer', { limit: maxFiles });
612
+ }
613
+ if (workspaceFileCount > maxFiles) {
614
+ throw new WorkspaceValidationError('file-count-limit', `Workspace contains ${workspaceFileCount} files; limit is ${maxFiles}`, { limit: maxFiles, actual: workspaceFileCount });
615
+ }
616
+ const workspaceFiles = [];
617
+ for (let index = 0; index < workspaceFileCount; index += 1) {
618
+ const file = workspaceFilesSource[index];
619
+ if (!this.isOperationActive(operation)) {
620
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
621
+ }
622
+ if (file === null || typeof file !== 'object') {
623
+ throw new TypeError(`${this.languageLabel} workspace file must be an object`);
624
+ }
625
+ const path = file.path;
626
+ if (!this.isOperationActive(operation)) {
627
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
628
+ }
629
+ const content = file.content;
630
+ if (!this.isOperationActive(operation)) {
631
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
632
+ }
633
+ workspaceFiles.push({ path, content });
634
+ }
635
+ const configuredActivePath = options.activePath;
636
+ if (!this.isOperationActive(operation)) {
637
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
638
+ }
639
+ const activePath = configuredActivePath === undefined
640
+ ? this.language === 'CSHARP'
641
+ ? 'Program.cs'
642
+ : this.language === 'VBNET'
643
+ ? 'Program.vb'
644
+ : 'Program.fs'
645
+ : configuredActivePath;
646
+ const maxFileBytes = Math.min(workspaceLimits.maxFileBytes ?? DEFAULT_WORKSPACE_LIMITS.maxFileBytes, limits.maxWorkspaceBytes);
647
+ const maxTotalBytes = Math.min(workspaceLimits.maxTotalBytes ?? DEFAULT_WORKSPACE_LIMITS.maxTotalBytes, limits.maxWorkspaceBytes);
648
+ const workspace = validateExecutionWorkspace(code, workspaceFiles, activePath, {
649
+ ...workspaceLimits,
650
+ maxFileBytes,
651
+ maxTotalBytes
652
+ });
653
+ if (!this.isOperationActive(operation)) {
654
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
655
+ }
656
+ if (workspace.workspaceFiles.length > 0) {
657
+ throw new RuntimeConfigurationError(`${this.languageLabel} runtime does not support auxiliary workspace files`, { phase: 'execute', runtimeId: this.language });
658
+ }
659
+ const stdin = options.stdin;
660
+ if (!this.isOperationActive(operation)) {
661
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
662
+ }
663
+ if (stdin !== undefined && typeof stdin !== 'string') {
664
+ throw new TypeError(`${this.languageLabel} stdin must be a string`);
665
+ }
666
+ const configuredProgramArgs = options.programArgs;
667
+ if (!this.isOperationActive(operation)) {
668
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
669
+ }
670
+ const sourceArgs = configuredProgramArgs ?? args;
671
+ const programArgs = [];
672
+ if (Array.isArray(sourceArgs)) {
673
+ const length = sourceArgs.length;
674
+ if (!this.isOperationActive(operation)) {
675
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
676
+ }
677
+ for (let index = 0; index < length; index += 1) {
678
+ programArgs.push(sourceArgs[index]);
679
+ if (!this.isOperationActive(operation)) {
680
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
681
+ }
682
+ }
683
+ }
684
+ const output = this.output;
685
+ if (!this.isOperationActive(operation)) {
686
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
687
+ }
688
+ const onDiagnostic = this.oncompilerdiagnostic;
689
+ if (!this.isOperationActive(operation)) {
690
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
691
+ }
692
+ let backend;
693
+ const runtimeModule = this.runtimeModule;
694
+ if (!this.isOperationActive(operation)) {
695
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
696
+ }
697
+ if (runtimeModule) {
698
+ const compiler = this.compiler;
699
+ if (!this.isOperationActive(operation)) {
700
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
701
+ }
702
+ if (compiler) {
703
+ const compile = compiler.compile;
704
+ if (!this.isOperationActive(operation)) {
705
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
706
+ }
707
+ const execute = runtimeModule.executeBrowserDotnetArtifact;
708
+ if (!this.isOperationActive(operation)) {
709
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
710
+ }
711
+ if (typeof compile !== 'function' || typeof execute !== 'function') {
712
+ throw new TypeError(`${this.languageLabel} runtime backend is invalid`);
713
+ }
714
+ backend = { kind: 'main-thread', runtimeModule, compiler, compile, execute };
715
+ }
716
+ }
717
+ if (!backend) {
718
+ const worker = this.worker;
719
+ if (!this.isOperationActive(operation)) {
720
+ throw this.releaseBeforeSession(operation, `${this.languageLabel} execution cancelled`);
721
+ }
722
+ if (!worker)
723
+ throw 'Worker not loaded';
724
+ backend = { kind: 'worker', worker };
725
+ }
726
+ let outputBytes = 0;
727
+ let diagnosticCount = 0;
728
+ const meter = {
729
+ recordOutput: (value) => {
730
+ const actual = outputBytes + OUTPUT_ENCODER.encode(String(value)).byteLength;
731
+ if (actual > limits.maxOutputBytes) {
732
+ throw new OutputLimitError(`${this.languageLabel} output exceeded ${limits.maxOutputBytes} bytes`, {
733
+ actual,
734
+ limit: limits.maxOutputBytes,
735
+ phase: 'execute',
736
+ runtimeId: this.language
737
+ });
738
+ }
739
+ outputBytes = actual;
740
+ },
741
+ recordDiagnostic: () => {
742
+ const actual = diagnosticCount + 1;
743
+ if (actual > limits.maxDiagnostics) {
744
+ throw new DiagnosticLimitError(`${this.languageLabel} diagnostics exceeded ${limits.maxDiagnostics} messages`, {
745
+ actual,
746
+ limit: limits.maxDiagnostics,
747
+ phase: 'execute',
748
+ runtimeId: this.language
749
+ });
750
+ }
751
+ diagnosticCount = actual;
752
+ }
753
+ };
754
+ request = { programArgs, stdin, output, onDiagnostic, meter, backend };
755
+ }
756
+ catch (error) {
757
+ throw this.releaseBeforeSession(operation, error);
758
+ }
759
+ let completionDeferred = false;
760
+ const timeoutMs = Math.min(2_147_483_647, limits.compileTimeoutMs + limits.runTimeoutMs);
761
+ try {
762
+ if (request.backend.kind === 'main-thread') {
763
+ operation.deferCompletion = true;
764
+ const cancellation = new Promise((_resolve, reject) => {
765
+ operation.deferredReject = reject;
766
+ });
767
+ operation.sessionActive = true;
768
+ this.bindOperationTimeout(operation, timeoutMs);
769
+ if (!this.isOperationActive(operation)) {
770
+ return await Promise.race([
771
+ cancellation,
772
+ Promise.reject(operation.cancellationReason)
773
+ ]);
774
+ }
775
+ const execution = this.runOnMainThread(operation, code, prepare, _log, _prog, request, request.backend).finally(() => this.completeOperation(operation));
776
+ completionDeferred = true;
777
+ return await Promise.race([cancellation, execution]);
778
+ }
779
+ const worker = request.backend.worker;
780
+ this.exit = false;
781
+ operation.sessionActive = true;
782
+ return await new Promise((resolve, reject) => {
783
+ const _uid = ++this.uid;
784
+ const workerOperation = this.workerSession.beginRun(worker, reject);
785
+ this.bindOperationTimeout(operation, timeoutMs);
786
+ if (!this.isOperationActive(operation))
787
+ return;
788
+ const hasExplicitStdin = !prepare && request.stdin !== undefined;
789
+ this.activeExplicitStdinCleanup?.();
790
+ let explicitStdinCleaned = false;
791
+ const cleanupExplicitStdin = () => {
792
+ if (!hasExplicitStdin || explicitStdinCleaned)
793
+ return;
794
+ explicitStdinCleaned = true;
795
+ if (this.activeExplicitStdinCleanup !== cleanupExplicitStdin)
796
+ return;
797
+ this.activeExplicitStdinCleanup = null;
798
+ this.resetStdinState();
799
+ };
800
+ if (hasExplicitStdin) {
801
+ this.resetStdinState();
802
+ this.activeExplicitStdinCleanup = cleanupExplicitStdin;
803
+ }
804
+ let handler;
805
+ const ownsRun = () => this.isOperationActive(operation) &&
806
+ this.worker === worker &&
807
+ worker.onmessage === handler &&
808
+ _uid === this.uid;
809
+ const failRun = (error, disposeWorker = false) => {
810
+ if (!ownsRun())
811
+ return;
812
+ cleanupExplicitStdin();
813
+ if (worker.onmessage === handler)
814
+ worker.onmessage = null;
815
+ this.workerSession.complete(workerOperation);
816
+ if (disposeWorker && this.worker === worker)
817
+ this.workerSession.reset();
818
+ this.exit = true;
819
+ this.completeOperation(operation);
820
+ reject(error);
821
+ };
822
+ handler = (event) => {
823
+ if (!ownsRun())
824
+ return;
825
+ try {
826
+ const message = event.data;
827
+ const hasResults = Object.prototype.hasOwnProperty.call(message ?? {}, 'results');
828
+ const hasError = Object.prototype.hasOwnProperty.call(message ?? {}, 'error');
829
+ const { output, results, error, diagnostic, progress } = message;
830
+ reportWorkerProgress(_prog, progress);
831
+ if (!ownsRun())
832
+ return;
833
+ if (output) {
834
+ request.meter.recordOutput(output);
835
+ if (!ownsRun())
836
+ return;
837
+ if (request.output != null) {
838
+ Reflect.apply(request.output, this, [output]);
839
+ }
840
+ }
841
+ if (!ownsRun())
842
+ return;
843
+ if (diagnostic) {
844
+ request.meter.recordDiagnostic();
845
+ if (!ownsRun())
846
+ return;
847
+ if (request.onDiagnostic != null) {
848
+ Reflect.apply(request.onDiagnostic, this, [diagnostic]);
849
+ }
850
+ }
851
+ if (!ownsRun())
852
+ return;
853
+ if (hasResults) {
854
+ cleanupExplicitStdin();
855
+ if (worker.onmessage === handler)
856
+ worker.onmessage = null;
857
+ this.elapse = Date.now() - this.begin;
858
+ this.exit = true;
859
+ this.workerSession.complete(workerOperation);
860
+ this.completeOperation(operation);
861
+ resolve(results);
862
+ return;
863
+ }
864
+ if (hasError) {
865
+ this.elapse = Date.now() - this.begin;
866
+ failRun(error, message.fatal === true);
867
+ }
868
+ }
869
+ catch (error) {
870
+ failRun(error, true);
871
+ }
872
+ };
873
+ worker.onmessage = handler;
874
+ if (!ownsRun())
875
+ return;
876
+ this.begin = Date.now();
877
+ this.collectStdinForRun(code, prepare, request.stdin, _uid, _prog)
878
+ .then((stdin) => {
879
+ if (!ownsRun())
880
+ return;
881
+ worker.postMessage({
882
+ code,
883
+ language: this.compileLanguage,
884
+ prepare,
885
+ args: request.programArgs,
886
+ stdin,
887
+ maxOutputBytes: limits.maxOutputBytes,
888
+ log: _log
889
+ });
890
+ })
891
+ .catch((error) => {
892
+ failRun(error);
893
+ });
894
+ });
895
+ }
896
+ finally {
897
+ if (!completionDeferred)
898
+ this.completeOperation(operation);
899
+ }
900
+ }
901
+ async runOnMainThread(operation, code, prepare, _log, _prog, request, backend) {
902
+ this.exit = false;
903
+ this.begin = Date.now();
904
+ const _uid = ++this.uid;
905
+ const hasExplicitStdin = !prepare && request.stdin !== undefined;
906
+ this.activeExplicitStdinCleanup?.();
907
+ let explicitStdinCleaned = false;
908
+ const cleanupExplicitStdin = () => {
909
+ if (!hasExplicitStdin || explicitStdinCleaned)
910
+ return;
911
+ explicitStdinCleaned = true;
912
+ if (this.activeExplicitStdinCleanup !== cleanupExplicitStdin)
913
+ return;
914
+ this.activeExplicitStdinCleanup = null;
915
+ this.resetStdinState();
916
+ };
917
+ if (hasExplicitStdin) {
918
+ this.resetStdinState();
919
+ this.activeExplicitStdinCleanup = cleanupExplicitStdin;
920
+ }
921
+ try {
922
+ const emitExecutionOutput = (output) => {
923
+ if (!output || !this.isOperationActive(operation) || _uid !== this.uid)
924
+ return;
925
+ try {
926
+ request.meter.recordOutput(output);
927
+ }
928
+ catch (error) {
929
+ if (this.isOperationActive(operation) && _uid === this.uid) {
930
+ this.abortOperation(operation, error);
931
+ }
932
+ throw error;
933
+ }
934
+ if (request.output != null &&
935
+ this.isOperationActive(operation) &&
936
+ _uid === this.uid) {
937
+ Reflect.apply(request.output, this, [output]);
938
+ }
939
+ };
940
+ const compileCacheKey = `${this.compileLanguage}\n${code}`;
941
+ let compiledArtifact = this.compiledArtifact &&
942
+ this.compiledCacheKey === compileCacheKey &&
943
+ this.compiledRuntimeModule === backend.runtimeModule &&
944
+ this.compiledCompiler === backend.compiler &&
945
+ this.compiledCompile === backend.compile &&
946
+ this.compiledExecute === backend.execute
947
+ ? this.compiledArtifact
948
+ : null;
949
+ if (!compiledArtifact) {
950
+ const result = await Reflect.apply(backend.compile, backend.compiler, [
951
+ {
952
+ code,
953
+ language: this.compileLanguage,
954
+ target: 'browser-wasm',
955
+ prepare,
956
+ log: _log,
957
+ onProgress: (progress) => {
958
+ if (this.isOperationActive(operation) && _uid === this.uid) {
959
+ reportWorkerProgress(_prog, progress);
960
+ }
961
+ }
962
+ }
963
+ ]);
964
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
965
+ return false;
966
+ for (const diagnostic of result.diagnostics || []) {
967
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
968
+ return false;
969
+ request.meter.recordDiagnostic();
970
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
971
+ return false;
972
+ if (request.onDiagnostic != null) {
973
+ Reflect.apply(request.onDiagnostic, this, [diagnostic]);
974
+ }
975
+ }
976
+ for (const line of result.logs || []) {
977
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
978
+ return false;
979
+ const output = line.endsWith('\n') ? line : `${line}\n`;
980
+ request.meter.recordOutput(output);
981
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
982
+ return false;
983
+ if (request.output != null) {
984
+ Reflect.apply(request.output, this, [output]);
985
+ }
986
+ }
987
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
988
+ return false;
989
+ if (result.stdout) {
990
+ request.meter.recordOutput(result.stdout);
991
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
992
+ return false;
993
+ if (request.output != null) {
994
+ Reflect.apply(request.output, this, [result.stdout]);
995
+ }
996
+ }
997
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
998
+ return false;
999
+ if (!result.success || !result.artifact) {
1000
+ throw new Error(result.stderr ||
1001
+ result.diagnostics
1002
+ ?.map((diagnostic) => diagnostic.message)
1003
+ .join('\n') ||
1004
+ `${this.languageLabel} compilation failed`);
1005
+ }
1006
+ if (result.stderr) {
1007
+ request.meter.recordOutput(result.stderr);
1008
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
1009
+ return false;
1010
+ if (request.output != null) {
1011
+ Reflect.apply(request.output, this, [result.stderr]);
1012
+ }
1013
+ }
1014
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
1015
+ return false;
1016
+ compiledArtifact = result.artifact;
1017
+ this.compiledArtifact = compiledArtifact;
1018
+ this.compiledCacheKey = compileCacheKey;
1019
+ this.compiledRuntimeModule = backend.runtimeModule;
1020
+ this.compiledCompiler = backend.compiler;
1021
+ this.compiledCompile = backend.compile;
1022
+ this.compiledExecute = backend.execute;
1023
+ }
1024
+ if (prepare)
1025
+ return true;
1026
+ const stdin = await this.collectStdinForRun(code, prepare, request.stdin, _uid, _prog);
1027
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
1028
+ return false;
1029
+ const execution = await Reflect.apply(backend.execute, backend.runtimeModule, [
1030
+ compiledArtifact,
1031
+ {
1032
+ args: request.programArgs,
1033
+ env: {
1034
+ USER: 'jungol'
1035
+ },
1036
+ stdin,
1037
+ stdout: (output) => emitExecutionOutput(output),
1038
+ stderr: (output) => emitExecutionOutput(output)
1039
+ }
1040
+ ]);
1041
+ if (!this.isOperationActive(operation) || _uid !== this.uid)
1042
+ return false;
1043
+ if (execution.exitCode !== 0) {
1044
+ throw new Error(`${this.languageLabel} program exited with code ${execution.exitCode}`);
1045
+ }
1046
+ return true;
1047
+ }
1048
+ finally {
1049
+ cleanupExplicitStdin();
1050
+ if (this.isOperationActive(operation) && _uid === this.uid) {
1051
+ this.elapse = Date.now() - this.begin;
1052
+ this.exit = true;
1053
+ }
1054
+ }
1055
+ }
1056
+ kill() {
1057
+ this.terminate();
1058
+ }
1059
+ terminate(reason = 'Process terminated') {
1060
+ if (this.disposed)
1061
+ return;
1062
+ const operation = this.activeOperation;
1063
+ const rejectDeferred = operation?.signal ? operation.deferredReject : undefined;
1064
+ if (operation) {
1065
+ operation.cancelled = true;
1066
+ operation.cancellationReason = reason;
1067
+ operation.deferredReject = undefined;
1068
+ }
1069
+ this.activeExplicitStdinCleanup?.();
1070
+ this.uid += 1;
1071
+ this.resolveStdinWaiters();
1072
+ this.workerSession.terminate(reason);
1073
+ this.exit = true;
1074
+ rejectDeferred?.(reason);
1075
+ if (operation) {
1076
+ if (operation.deferCompletion) {
1077
+ this.releaseOperationTimeout(operation);
1078
+ this.releaseAbortSignal(operation);
1079
+ }
1080
+ else
1081
+ this.completeOperation(operation);
1082
+ }
1083
+ }
1084
+ async clear() {
1085
+ if (this.disposed)
1086
+ return;
1087
+ if (this.worker)
1088
+ this.worker.onmessage = null;
1089
+ this.resetStdinState();
1090
+ if (this.activeOperation) {
1091
+ this.terminate();
1092
+ }
1093
+ }
1094
+ dispose() {
1095
+ if (this.disposePromise)
1096
+ return this.disposePromise;
1097
+ this.disposed = true;
1098
+ this.disposePromise = Promise.resolve();
1099
+ const activeOperation = this.activeOperation;
1100
+ const stdinWaiters = this.stdinWaiters.splice(0);
1101
+ delete this.worker;
1102
+ this.runtimeModule = null;
1103
+ this.compiler = null;
1104
+ this.moduleUrl = '';
1105
+ this.clearCompiledArtifact();
1106
+ this.output = null;
1107
+ this.oncompilerdiagnostic = undefined;
1108
+ this.activeExplicitStdinCleanup = null;
1109
+ this.pendingInput = [];
1110
+ this.pendingEof = false;
1111
+ this.exit = true;
1112
+ for (const resolve of stdinWaiters) {
1113
+ try {
1114
+ resolve();
1115
+ }
1116
+ catch {
1117
+ // Waiter cleanup is best effort after host state becomes unreachable.
1118
+ }
1119
+ }
1120
+ if (activeOperation) {
1121
+ this.abortOperation(activeOperation, this.disposeCancellation);
1122
+ this.completeOperation(activeOperation);
1123
+ }
1124
+ else {
1125
+ this.uid += 1;
1126
+ this.workerSession.terminate(this.disposeCancellation);
1127
+ }
1128
+ return this.disposePromise;
1129
+ }
1130
+ }
1131
+ export default Dotnet;