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,261 @@
1
+ import { waitForBufferedStdin } from '../stdinBuffer';
2
+ import { importRuntimeModule } from '../runtimeModule';
3
+ const encoder = new TextEncoder();
4
+ let stdinBufferPhp = null;
5
+ let runtimeModuleUrl = '';
6
+ let phpPromise = null;
7
+ let workspaceDirty = false;
8
+ function postProgress(percent) {
9
+ postMessage({ progress: { percent: Math.max(0, Math.min(100, percent)) } });
10
+ }
11
+ async function loadPhp(moduleUrl, log = true) {
12
+ if (!moduleUrl)
13
+ throw new Error('PHP runtime module URL is not configured.');
14
+ if (runtimeModuleUrl !== moduleUrl) {
15
+ runtimeModuleUrl = moduleUrl;
16
+ phpPromise = null;
17
+ workspaceDirty = false;
18
+ }
19
+ if (phpPromise)
20
+ return await phpPromise;
21
+ phpPromise = (async () => {
22
+ postProgress(5);
23
+ const runtime = await importRuntimeModule(moduleUrl);
24
+ const php = await runtime.createPhp84();
25
+ postProgress(95);
26
+ php.mkdir('/workspace');
27
+ if (log) {
28
+ console.log('[wasm-idle:php-worker] PHP 8.4 ready');
29
+ }
30
+ postProgress(100);
31
+ return php;
32
+ })();
33
+ return await phpPromise;
34
+ }
35
+ function prepareWorkspace(php) {
36
+ if (workspaceDirty) {
37
+ php.rmdir('/workspace', { recursive: true });
38
+ php.mkdir('/workspace');
39
+ }
40
+ workspaceDirty = true;
41
+ }
42
+ function normalizeWorkspacePath(path) {
43
+ return path
44
+ .replace(/^\/+/, '')
45
+ .split('/')
46
+ .filter((part) => part && part !== '.' && part !== '..' && !part.includes('\0'))
47
+ .join('/');
48
+ }
49
+ function dirname(path) {
50
+ const slashIndex = path.lastIndexOf('/');
51
+ return slashIndex === -1 ? '' : path.slice(0, slashIndex);
52
+ }
53
+ function mkdirp(php, path) {
54
+ const normalized = normalizeWorkspacePath(path);
55
+ if (!normalized)
56
+ return;
57
+ let current = '';
58
+ for (const part of normalized.split('/')) {
59
+ current += `/${part}`;
60
+ try {
61
+ php.mkdir(current);
62
+ }
63
+ catch {
64
+ // Existing directories throw from the Emscripten FS API.
65
+ }
66
+ }
67
+ }
68
+ function writeWorkspaceFile(php, path, content) {
69
+ const normalized = normalizeWorkspacePath(path);
70
+ if (!normalized)
71
+ return;
72
+ const fullPath = `/workspace/${normalized}`;
73
+ mkdirp(php, dirname(`workspace/${normalized}`));
74
+ php.writeFile(fullPath, content);
75
+ }
76
+ function phpString(value) {
77
+ return `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
78
+ }
79
+ function skipPhpTrivia(code, offset) {
80
+ let cursor = offset;
81
+ while (cursor < code.length) {
82
+ if (/\s/u.test(code[cursor])) {
83
+ cursor += 1;
84
+ continue;
85
+ }
86
+ if (code.startsWith('//', cursor) ||
87
+ (code[cursor] === '#' && !code.startsWith('#[', cursor))) {
88
+ const newline = code.indexOf('\n', cursor + 1);
89
+ cursor = newline === -1 ? code.length : newline + 1;
90
+ continue;
91
+ }
92
+ if (code.startsWith('/*', cursor)) {
93
+ const commentEnd = code.indexOf('*/', cursor + 2);
94
+ cursor = commentEnd === -1 ? code.length : commentEnd + 2;
95
+ continue;
96
+ }
97
+ break;
98
+ }
99
+ return cursor;
100
+ }
101
+ function startsWithPhpKeyword(code, offset, keyword) {
102
+ if (code.slice(offset, offset + keyword.length).toLowerCase() !== keyword)
103
+ return false;
104
+ return !/[A-Za-z0-9_\u0080-\uffff]/u.test(code[offset + keyword.length] || '');
105
+ }
106
+ function findPhpHeaderDelimiter(code, offset, delimiters) {
107
+ let quote = '';
108
+ let parentheses = 0;
109
+ let brackets = 0;
110
+ for (let cursor = offset; cursor < code.length; cursor += 1) {
111
+ const character = code[cursor];
112
+ if (quote) {
113
+ if (character === '\\')
114
+ cursor += 1;
115
+ else if (character === quote)
116
+ quote = '';
117
+ continue;
118
+ }
119
+ if (character === "'" || character === '"') {
120
+ quote = character;
121
+ continue;
122
+ }
123
+ if (code.startsWith('//', cursor) ||
124
+ (character === '#' && !code.startsWith('#[', cursor))) {
125
+ const newline = code.indexOf('\n', cursor + 1);
126
+ if (newline === -1)
127
+ return -1;
128
+ cursor = newline;
129
+ continue;
130
+ }
131
+ if (code.startsWith('/*', cursor)) {
132
+ const commentEnd = code.indexOf('*/', cursor + 2);
133
+ if (commentEnd === -1)
134
+ return -1;
135
+ cursor = commentEnd + 1;
136
+ continue;
137
+ }
138
+ if (character === '(')
139
+ parentheses += 1;
140
+ else if (character === ')')
141
+ parentheses = Math.max(0, parentheses - 1);
142
+ else if (character === '[')
143
+ brackets += 1;
144
+ else if (character === ']')
145
+ brackets = Math.max(0, brackets - 1);
146
+ else if (parentheses === 0 && brackets === 0 && delimiters.has(character))
147
+ return cursor;
148
+ }
149
+ return -1;
150
+ }
151
+ function argvPreludeInsertionOffset(code, openingTagEnd) {
152
+ let cursor = skipPhpTrivia(code, openingTagEnd);
153
+ while (startsWithPhpKeyword(code, cursor, 'declare')) {
154
+ const declarationEnd = findPhpHeaderDelimiter(code, cursor + 'declare'.length, new Set([';']));
155
+ if (declarationEnd === -1)
156
+ return cursor;
157
+ cursor = skipPhpTrivia(code, declarationEnd + 1);
158
+ }
159
+ if (startsWithPhpKeyword(code, cursor, 'namespace') &&
160
+ (/\s/u.test(code[cursor + 'namespace'.length] || '') ||
161
+ code[cursor + 'namespace'.length] === '{')) {
162
+ const namespaceEnd = findPhpHeaderDelimiter(code, cursor + 'namespace'.length, new Set([';', '{']));
163
+ if (namespaceEnd !== -1)
164
+ return namespaceEnd + 1;
165
+ }
166
+ return cursor;
167
+ }
168
+ function injectArgv(code, activePath, args) {
169
+ const argv = [activePath, ...args].map(phpString).join(', ');
170
+ const prelude = `$argv = array(${argv});\n$argc = count($argv);\n$_SERVER['argv'] = $argv;\n$_SERVER['argc'] = $argc;\n`;
171
+ const openingTag = code.match(/^\s*<\?php\b/i);
172
+ if (openingTag) {
173
+ const insertAt = argvPreludeInsertionOffset(code, openingTag[0].length);
174
+ return `${code.slice(0, insertAt)}\n${prelude}${code.slice(insertAt)}`;
175
+ }
176
+ return `<?php\n${prelude}\n?>\n${code}`;
177
+ }
178
+ function codeMightReadStdin(code) {
179
+ return /php:\/\/input|STDIN|stream_get_contents|file_get_contents|fgets\s*\(/.test(code);
180
+ }
181
+ function readInitialStdin(code, initialStdin, log = true) {
182
+ if (typeof initialStdin === 'string')
183
+ return initialStdin;
184
+ if (!codeMightReadStdin(code))
185
+ return '';
186
+ const chunk = waitForBufferedStdin(stdinBufferPhp, () => postMessage({ buffer: true }));
187
+ if (log) {
188
+ console.log(chunk == null
189
+ ? '[wasm-idle:php-stdin] read(bytes=0, eof=true)'
190
+ : `[wasm-idle:php-stdin] read(bytes=${encoder.encode(chunk).byteLength}, text=${JSON.stringify(chunk)})`);
191
+ }
192
+ return chunk || '';
193
+ }
194
+ self.onmessage = async (event) => {
195
+ const { load, moduleUrl: nextModuleUrl, buffer, code, prepare, args = [], stdin, activePath = 'main.php', workspaceFiles = [], log } = event.data;
196
+ try {
197
+ if (load) {
198
+ const moduleUrl = nextModuleUrl || runtimeModuleUrl;
199
+ if (log)
200
+ console.log(`[wasm-idle:php-worker] load PHP 8.4 module=${moduleUrl}`);
201
+ await loadPhp(moduleUrl, log);
202
+ postMessage({ load: true });
203
+ return;
204
+ }
205
+ stdinBufferPhp = new Int32Array(buffer);
206
+ const php = await loadPhp(runtimeModuleUrl, log);
207
+ if (prepare) {
208
+ postMessage({ results: true });
209
+ return;
210
+ }
211
+ prepareWorkspace(php);
212
+ for (const file of workspaceFiles) {
213
+ await writeWorkspaceFile(php, file.path, file.content);
214
+ }
215
+ const normalizedActivePath = normalizeWorkspacePath(activePath) || 'main.php';
216
+ const scriptPath = `/workspace/${normalizedActivePath}`;
217
+ writeWorkspaceFile(php, normalizedActivePath, injectArgv(code, normalizedActivePath, args));
218
+ if (log) {
219
+ console.log(`[wasm-idle:php-worker] run start bytes=${code.length} activePath=${activePath}`);
220
+ }
221
+ const body = readInitialStdin(code, stdin, log);
222
+ postMessage({
223
+ progress: {
224
+ kind: 'ready',
225
+ state: 'running',
226
+ reason: 'started',
227
+ label: 'PHP program started'
228
+ }
229
+ });
230
+ const response = await php.run({
231
+ scriptPath,
232
+ body,
233
+ env: {
234
+ USER: 'jungol'
235
+ },
236
+ $_SERVER: {
237
+ SCRIPT_FILENAME: scriptPath,
238
+ SCRIPT_NAME: `/${normalizedActivePath}`
239
+ }
240
+ });
241
+ if (response.text)
242
+ postMessage({ output: response.text });
243
+ if (response.errors)
244
+ postMessage({ output: response.errors });
245
+ if (response.exitCode !== 0) {
246
+ throw new Error(response.errors
247
+ ? `PHP program exited with code ${response.exitCode}\n${response.errors}`
248
+ : `PHP program exited with code ${response.exitCode}`);
249
+ }
250
+ if (log) {
251
+ console.log(`[wasm-idle:php-worker] run settled exitCode=${response.exitCode}`);
252
+ }
253
+ postMessage({ results: true });
254
+ }
255
+ catch (error) {
256
+ if (log) {
257
+ console.error('[wasm-idle:php-worker] failed', error);
258
+ }
259
+ postMessage({ error: error?.message || String(error) });
260
+ }
261
+ };
@@ -1,5 +1,7 @@
1
1
  import { flushQueuedStdin, readBufferedStdin, waitForBufferedStdin } from '../stdinBuffer';
2
- import { configureWorkerRuntimeAssets, handleWorkerAssetMessage } from './assets';
2
+ import { isSharedBufferBackedView } from '../sharedBuffer';
3
+ import { parsePythonPackageLock } from '../pythonPackageLock';
4
+ import { configureWorkerRuntimeAssetAllowlist, configureWorkerRuntimeAssets, handleWorkerAssetMessage, loadWorkerRuntimeAsset } from './assets';
3
5
  self.document = {
4
6
  querySelector() {
5
7
  return null;
@@ -8,7 +10,7 @@ self.document = {
8
10
  return [];
9
11
  }
10
12
  };
11
- let stdinBufferPyodide, debugBufferPyodide, watchBufferPyodide, watchResultBufferPyodide, interruptBufferPyodide, pyodide, baseUrl = '', packageBaseUrl = '';
13
+ let stdinBufferPyodide, debugBufferPyodide, watchBufferPyodide, watchResultBufferPyodide, interruptBufferPyodide, pyodide, baseUrl = '', useAssetBridge = false;
12
14
  const imageHook = `
13
15
  if not globals().get("__wasm_idle_img_inited__", False):
14
16
  globals()["__wasm_idle_img_inited__"] = True
@@ -152,53 +154,121 @@ if not globals().get("__wasm_idle_img_inited__", False):
152
154
  except Exception:
153
155
  pass
154
156
  `;
155
- const cdnFallbackUrl = (version) => version ? `https://cdn.jsdelivr.net/pyodide/v${version}/full/` : '';
157
+ const pyodideVersionPattern = /^[0-9]{1,6}\.[0-9]{1,6}\.[0-9]{1,6}(?:[A-Za-z0-9._+-]{0,64})?$/u;
158
+ const directPyodideRuntimeAssets = [
159
+ 'pyodide.mjs',
160
+ 'pyodide.asm.js',
161
+ 'pyodide-lock.json',
162
+ 'pyodide.asm.wasm',
163
+ 'python_stdlib.zip'
164
+ ];
165
+ const resolvePinnedPackageBaseUrl = (version) => {
166
+ if (typeof version !== 'string' || !pyodideVersionPattern.test(version)) {
167
+ throw new Error('Pyodide runtime version is invalid');
168
+ }
169
+ return new URL(`v${encodeURIComponent(version)}/full/`, 'https://cdn.jsdelivr.net/pyodide/')
170
+ .href;
171
+ };
172
+ function postProgress(percent, stage) {
173
+ self.postMessage({ progress: { percent, stage } });
174
+ }
175
+ async function importRuntimeAssetModule(asset) {
176
+ const loaded = await loadWorkerRuntimeAsset(asset);
177
+ const moduleUrl = URL.createObjectURL(new Blob([loaded.bytes.slice().buffer], {
178
+ type: loaded.mimeType || 'text/javascript'
179
+ }));
180
+ try {
181
+ return await import(/* @vite-ignore */ moduleUrl);
182
+ }
183
+ finally {
184
+ URL.revokeObjectURL(moduleUrl);
185
+ }
186
+ }
156
187
  async function loadPyodide(path) {
157
188
  if (pyodide)
158
189
  return;
159
- const { loadPyodide } = await import('pyodide');
160
- pyodide = await loadPyodide({ indexURL: path });
161
- packageBaseUrl = path;
162
- const setCdnUrl = pyodide?.setCdnUrl;
163
- if (typeof setCdnUrl === 'function')
164
- setCdnUrl(packageBaseUrl);
190
+ const runtimeBaseUrl = path.endsWith('/') ? path : `${path}/`;
191
+ await importRuntimeAssetModule('pyodide.asm.js');
192
+ const runtimeModule = (await importRuntimeAssetModule('pyodide.mjs'));
193
+ let packageBaseUrl = runtimeBaseUrl;
194
+ let lockFileContents;
195
+ if (!useAssetBridge) {
196
+ packageBaseUrl = resolvePinnedPackageBaseUrl(runtimeModule.version);
197
+ const loadedLock = await loadWorkerRuntimeAsset('pyodide-lock.json');
198
+ const parsedLock = parsePythonPackageLock(loadedLock.bytes);
199
+ // The interceptor caps downloaded (including browser-decoded transport) archive bytes.
200
+ // Pyodide owns package extraction after receiving that bounded archive.
201
+ configureWorkerRuntimeAssetAllowlist({
202
+ baseUrl: packageBaseUrl,
203
+ assets: [...parsedLock.packageAssets],
204
+ runtimeAssets: directPyodideRuntimeAssets
205
+ });
206
+ lockFileContents = parsedLock.lock;
207
+ }
208
+ const { loadPyodide } = runtimeModule;
209
+ pyodide = await loadPyodide({
210
+ indexURL: path,
211
+ packageBaseUrl,
212
+ ...(lockFileContents ? { lockFileContents } : {})
213
+ });
165
214
  }
166
215
  async function loadPackages(code) {
167
216
  if (!code)
168
217
  return;
169
- try {
170
- await pyodide.loadPackagesFromImports(code);
171
- }
172
- catch (e) {
173
- const fallback = cdnFallbackUrl(pyodide?.version || '');
174
- const setCdnUrl = pyodide?.setCdnUrl;
175
- if (fallback && fallback !== packageBaseUrl && typeof setCdnUrl === 'function') {
176
- setCdnUrl(fallback);
177
- packageBaseUrl = fallback;
178
- await pyodide.loadPackagesFromImports(code);
179
- return;
180
- }
181
- throw e;
218
+ await pyodide.loadPackagesFromImports(code);
219
+ }
220
+ function normalizeWorkspacePath(path) {
221
+ return path
222
+ .replaceAll('\\', '/')
223
+ .split('/')
224
+ .filter((part) => part && part !== '.' && part !== '..')
225
+ .join('/');
226
+ }
227
+ function writeWorkspaceFiles(files = []) {
228
+ const fs = pyodide.FS;
229
+ for (const file of files) {
230
+ const safePath = normalizeWorkspacePath(file.path);
231
+ if (!safePath)
232
+ continue;
233
+ const directory = safePath.split('/').slice(0, -1).join('/');
234
+ if (directory)
235
+ fs.mkdirTree(directory);
236
+ fs.writeFile(safePath, file.content, { encoding: 'utf8' });
182
237
  }
183
238
  }
184
239
  self.onmessage = async (event) => {
185
240
  if (handleWorkerAssetMessage(event.data))
186
241
  return;
187
- const { code, buffer, debugBuffer, watchBuffer, watchResultBuffer, load, interrupt, assets, prepare, debug = false, breakpoints = [], pauseOnEntry = false } = event.data;
242
+ const { code, buffer, debugBuffer, watchBuffer, watchResultBuffer, load, interrupt, assets, prepare, stdin, debug = false, breakpoints = [], pauseOnEntry = false, activePath, debugPath, workspaceFiles } = event.data;
188
243
  if (load) {
189
- const runtimeAssets = assets;
190
- baseUrl = runtimeAssets?.baseUrl || baseUrl;
191
- configureWorkerRuntimeAssets(runtimeAssets || null);
192
- postMessage({ output: 'Loading Pyodide...' });
193
- await loadPyodide(baseUrl);
194
- postMessage({ output: ' Done.\n\r' });
195
- postMessage({ load: true });
244
+ try {
245
+ const runtimeAssets = assets;
246
+ baseUrl = runtimeAssets?.baseUrl || baseUrl;
247
+ useAssetBridge = runtimeAssets?.useAssetBridge === true;
248
+ configureWorkerRuntimeAssets(runtimeAssets || null);
249
+ postMessage({ output: 'Loading Pyodide...' });
250
+ postProgress(2, 'Loading Pyodide module');
251
+ await loadPyodide(baseUrl);
252
+ postProgress(100, 'Pyodide runtime ready');
253
+ postMessage({ output: ' Done.\n\r' });
254
+ postMessage({ load: true });
255
+ }
256
+ catch (e) {
257
+ self.postMessage({ error: e.message || 'Unknown error' });
258
+ }
196
259
  }
197
260
  else if (prepare) {
198
261
  postMessage({ output: 'Loading packages...' });
199
262
  try {
263
+ postProgress(5, 'Preparing Python workspace');
200
264
  await loadPyodide(baseUrl);
201
- await loadPackages(code);
265
+ writeWorkspaceFiles(workspaceFiles);
266
+ postProgress(15, 'Resolving Python imports');
267
+ await loadPackages([
268
+ code,
269
+ ...(workspaceFiles || []).map((file) => file.content)
270
+ ].join('\n'));
271
+ postProgress(100, 'Python packages ready');
202
272
  postMessage({ output: ' Done.\n\r' });
203
273
  self.postMessage({ results: true });
204
274
  }
@@ -206,16 +276,32 @@ self.onmessage = async (event) => {
206
276
  self.postMessage({ error: e.message || 'Unknown error' });
207
277
  }
208
278
  }
209
- else if (code) {
210
- await loadPyodide(baseUrl);
211
- await loadPackages(code);
279
+ else if (typeof code === 'string') {
280
+ try {
281
+ await loadPyodide(baseUrl);
282
+ writeWorkspaceFiles(workspaceFiles);
283
+ await loadPackages([
284
+ code,
285
+ ...(workspaceFiles || []).map((file) => file.content)
286
+ ].join('\n'));
287
+ }
288
+ catch (e) {
289
+ self.postMessage({ error: e.message || 'Unknown error' });
290
+ return;
291
+ }
212
292
  const ts = Date.now();
213
293
  stdinBufferPyodide = new Int32Array(buffer);
214
294
  debugBufferPyodide = new Int32Array(debugBuffer);
215
295
  watchBufferPyodide = new Int32Array(watchBuffer);
216
296
  watchResultBufferPyodide = new Int32Array(watchResultBuffer);
217
297
  interruptBufferPyodide = new Uint8Array(interrupt);
218
- pyodide.setInterruptBuffer(interruptBufferPyodide);
298
+ if (debug && !isSharedBufferBackedView(debugBufferPyodide)) {
299
+ self.postMessage({ error: 'Python debugging requires SharedArrayBuffer.' });
300
+ return;
301
+ }
302
+ if (isSharedBufferBackedView(interruptBufferPyodide)) {
303
+ pyodide.setInterruptBuffer(interruptBufferPyodide);
304
+ }
219
305
  const toPythonStr = (obj) => {
220
306
  if (obj === true)
221
307
  return 'True';
@@ -227,13 +313,21 @@ self.onmessage = async (event) => {
227
313
  return 'None';
228
314
  return obj.toString();
229
315
  };
316
+ const hasInitialStdin = typeof stdin === 'string';
317
+ let initialStdin = hasInitialStdin ? stdin : null;
230
318
  self.prompt = self['__pyodide__input_' + ts] = (output) => {
231
319
  if (output)
232
320
  postMessage({ output });
321
+ if (hasInitialStdin) {
322
+ const chunk = initialStdin;
323
+ initialStdin = null;
324
+ return chunk;
325
+ }
233
326
  return waitForBufferedStdin(stdinBufferPyodide, () => postMessage({ buffer: true }));
234
327
  };
235
328
  self['__pyodide__output_' + ts] = (...data) => {
236
- let sep = ' ', end = '\r\n', output = '', clear = [];
329
+ let sep = ' ', end = '\r\n', output = '';
330
+ const clear = [];
237
331
  for (const i of data) {
238
332
  if (i?.end !== undefined)
239
333
  end = toPythonStr(i.end);
@@ -256,9 +350,26 @@ self.onmessage = async (event) => {
256
350
  const debugWaitName = `__wasm_idle_python_debug_wait_${ts}`;
257
351
  const debugReadWatchName = `__wasm_idle_python_debug_watch_read_${ts}`;
258
352
  const debugWriteWatchName = `__wasm_idle_python_debug_watch_write_${ts}`;
353
+ const debugReadBreakpointsName = `__wasm_idle_python_debug_breakpoints_${ts}`;
354
+ const executionReadyName = `__wasm_idle_python_execution_ready_${ts}`;
355
+ let executionReadyReported = false;
356
+ self[executionReadyName] = () => {
357
+ if (executionReadyReported)
358
+ return;
359
+ executionReadyReported = true;
360
+ delete self[executionReadyName];
361
+ postMessage({
362
+ progress: {
363
+ kind: 'ready',
364
+ state: 'running',
365
+ reason: 'started',
366
+ label: 'Python program started'
367
+ }
368
+ });
369
+ };
259
370
  self[debugPauseName] = (line, reason, localsJson, callStackJson) => {
260
- let locals = [];
261
- let callStack = [];
371
+ let locals;
372
+ let callStack;
262
373
  try {
263
374
  locals = JSON.parse(localsJson);
264
375
  }
@@ -298,7 +409,21 @@ self.onmessage = async (event) => {
298
409
  self[debugWriteWatchName] = (value) => {
299
410
  flushQueuedStdin([value], watchResultBufferPyodide);
300
411
  };
301
- const userFilename = '__wasm_idle_user__.py';
412
+ self[debugReadBreakpointsName] = () => {
413
+ const version = Atomics.load(debugBufferPyodide, 2);
414
+ const count = Math.max(0, Math.min(Atomics.load(debugBufferPyodide, 3), debugBufferPyodide.length - 4));
415
+ const lines = [];
416
+ for (let index = 0; index < count; index += 1) {
417
+ const line = Atomics.load(debugBufferPyodide, 4 + index);
418
+ if (Number.isInteger(line) && line > 0)
419
+ lines.push(line);
420
+ }
421
+ return JSON.stringify({ version, lines });
422
+ };
423
+ const executionFilename = normalizeWorkspacePath(activePath || '') || '__wasm_idle_user__.py';
424
+ const debugFilename = normalizeWorkspacePath(debugPath || '') || executionFilename;
425
+ const executionFilenameLiteral = JSON.stringify(executionFilename);
426
+ const debugFilenameLiteral = JSON.stringify(debugFilename);
302
427
  const normalizedBreakpoints = JSON.stringify([...(Array.isArray(breakpoints) ? breakpoints : [])]
303
428
  .map((value) => Number(value))
304
429
  .filter((value) => Number.isInteger(value) && value > 0));
@@ -309,14 +434,20 @@ import inspect
309
434
  import json
310
435
  import sys
311
436
  from js import __pyodide__input_${ts}, __pyodide__output_${ts}
437
+ from js import ${executionReadyName} as __wasm_idle_execution_ready
312
438
  ${debug ? `from js import ${debugPauseName}, ${debugWaitName}` : ''}
313
439
  ${debug ? `from js import ${debugReadWatchName}, ${debugWriteWatchName}` : ''}
440
+ ${debug ? `from js import ${debugReadBreakpointsName}` : ''}
314
441
 
315
442
  __wasm_idle_input = __pyodide__input_${ts}
316
443
  def __wasm_idle_input_wrapper(prompt = ""):
317
444
  value = __wasm_idle_input(prompt)
318
445
  if value is None:
319
446
  raise EOFError
447
+ if value.endswith("\\r\\n"):
448
+ value = value[:-2]
449
+ elif value.endswith("\\n") or value.endswith("\\r"):
450
+ value = value[:-1]
320
451
  return value
321
452
  __wasm_idle_output = __pyodide__output_${ts}
322
453
  builtins.input = __wasm_idle_input_wrapper
@@ -327,6 +458,7 @@ ${imageHook}
327
458
  ${debug
328
459
  ? `
329
460
  __wasm_idle_debug_breakpoints = set(${normalizedBreakpoints})
461
+ __wasm_idle_debug_breakpoint_version = -1
330
462
  __wasm_idle_debug_pause_on_entry = ${pauseOnEntry ? 'True' : 'False'}
331
463
  __wasm_idle_debug_step_mode = None
332
464
  __wasm_idle_debug_resume_skip = None
@@ -334,11 +466,21 @@ __wasm_idle_debug_next_depth = None
334
466
  __wasm_idle_debug_next_line = None
335
467
  __wasm_idle_debug_step_out_depth = None
336
468
 
469
+ def __wasm_idle_debug_refresh_breakpoints():
470
+ global __wasm_idle_debug_breakpoints
471
+ global __wasm_idle_debug_breakpoint_version
472
+ snapshot = json.loads(${debugReadBreakpointsName}())
473
+ version = int(snapshot.get("version", -1))
474
+ if version == __wasm_idle_debug_breakpoint_version:
475
+ return
476
+ __wasm_idle_debug_breakpoint_version = version
477
+ __wasm_idle_debug_breakpoints = set(int(line) for line in snapshot.get("lines", []) if int(line) > 0)
478
+
337
479
  def __wasm_idle_debug_depth(frame):
338
480
  depth = 0
339
481
  current = frame
340
482
  while current is not None:
341
- if current.f_code.co_filename == "${userFilename}":
483
+ if current.f_code.co_filename == ${debugFilenameLiteral}:
342
484
  depth += 1
343
485
  current = current.f_back
344
486
  return depth
@@ -402,7 +544,7 @@ def __wasm_idle_debug_stack(frame):
402
544
  stack = []
403
545
  current = frame
404
546
  while current is not None:
405
- if current.f_code.co_filename == "${userFilename}":
547
+ if current.f_code.co_filename == ${debugFilenameLiteral}:
406
548
  stack.append({"functionName": current.f_code.co_name, "line": current.f_lineno})
407
549
  current = current.f_back
408
550
  return stack
@@ -415,11 +557,12 @@ def __wasm_idle_debug_trace(frame, event, arg):
415
557
  global __wasm_idle_debug_next_line
416
558
  global __wasm_idle_debug_step_out_depth
417
559
 
418
- if frame.f_code.co_filename != "${userFilename}":
560
+ if frame.f_code.co_filename != ${debugFilenameLiteral}:
419
561
  return None
420
562
  if event != "line":
421
563
  return __wasm_idle_debug_trace
422
564
 
565
+ __wasm_idle_debug_refresh_breakpoints()
423
566
  depth = __wasm_idle_debug_depth(frame)
424
567
  line = frame.f_lineno
425
568
  if __wasm_idle_debug_resume_skip == (depth, line):
@@ -478,15 +621,27 @@ sys.settrace(__wasm_idle_debug_trace)
478
621
  : ''}
479
622
 
480
623
  try:
481
- __wasm_idle_globals = {"__name__": "__main__"}
624
+ __wasm_idle_globals = {
625
+ "__name__": "__main__",
626
+ ${JSON.stringify(executionReadyName)}: __wasm_idle_execution_ready,
627
+ }
628
+ __wasm_idle_compiled = compile(
629
+ ${JSON.stringify(code)},
630
+ ${executionFilenameLiteral},
631
+ "exec",
632
+ flags = ast.PyCF_ALLOW_TOP_LEVEL_AWAIT,
633
+ )
634
+ __wasm_idle_globals.pop(${JSON.stringify(executionReadyName)})()
482
635
  __wasm_idle_result = eval(
483
- compile(${JSON.stringify(code)}, "${userFilename}", "exec", flags = ast.PyCF_ALLOW_TOP_LEVEL_AWAIT),
636
+ __wasm_idle_compiled,
484
637
  __wasm_idle_globals,
485
638
  __wasm_idle_globals,
486
639
  )
487
640
  if inspect.isawaitable(__wasm_idle_result):
488
641
  await __wasm_idle_result
489
642
  finally:
643
+ __wasm_idle_globals.pop(${JSON.stringify(executionReadyName)}, None)
644
+ del __wasm_idle_execution_ready
490
645
  sys.settrace(None)
491
646
  ${debug
492
647
  ? `
@@ -504,10 +659,12 @@ finally:
504
659
  self.postMessage({ error: e.message || 'Unknown error' });
505
660
  }
506
661
  finally {
662
+ delete self[executionReadyName];
507
663
  delete self[debugPauseName];
508
664
  delete self[debugWaitName];
509
665
  delete self[debugReadWatchName];
510
666
  delete self[debugWriteWatchName];
667
+ delete self[debugReadBreakpointsName];
511
668
  }
512
669
  }
513
670
  };
@@ -0,0 +1 @@
1
+ export {};