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.
- package/README.md +760 -81
- package/dist/index.d.ts +4 -9
- package/dist/index.js +2 -4
- package/dist/playground/applicationAssets.d.ts +4 -0
- package/dist/playground/applicationAssets.js +277 -0
- package/dist/playground/assemblyscript.d.ts +41 -0
- package/dist/playground/assemblyscript.js +630 -0
- package/dist/playground/assetBridge.d.ts +18 -7
- package/dist/playground/assetBridge.js +824 -100
- package/dist/playground/assets.d.ts +813 -19
- package/dist/playground/assets.js +2096 -156
- package/dist/playground/awk.d.ts +5 -0
- package/dist/playground/awk.js +60 -0
- package/dist/playground/bash.d.ts +53 -0
- package/dist/playground/bash.js +1096 -0
- package/dist/playground/bashWorkerProtocol.d.ts +88 -0
- package/dist/playground/bashWorkerProtocol.js +135 -0
- package/dist/playground/bqn.d.ts +5 -0
- package/dist/playground/bqn.js +57 -0
- package/dist/playground/bqnPreflight.d.ts +26 -0
- package/dist/playground/bqnPreflight.js +399 -0
- package/dist/playground/c3.d.ts +15 -0
- package/dist/playground/c3.js +154 -0
- package/dist/playground/clang.d.ts +35 -19
- package/dist/playground/clang.js +241 -52
- package/dist/playground/clangAssetIntegrity.d.ts +32 -0
- package/dist/playground/clangAssetIntegrity.js +8 -0
- package/dist/playground/clojurescript.d.ts +5 -0
- package/dist/playground/clojurescript.js +59 -0
- package/dist/playground/clojurescriptPreflight.d.ts +26 -0
- package/dist/playground/clojurescriptPreflight.js +383 -0
- package/dist/playground/cobol.d.ts +46 -0
- package/dist/playground/cobol.js +703 -0
- package/dist/playground/d.d.ts +47 -0
- package/dist/playground/d.js +644 -0
- package/dist/playground/dOuterAssets.d.ts +16 -0
- package/dist/playground/dOuterAssets.js +163 -0
- package/dist/playground/dotnet.d.ts +99 -0
- package/dist/playground/dotnet.js +1131 -0
- package/dist/playground/duckdb.d.ts +36 -0
- package/dist/playground/duckdb.js +542 -0
- package/dist/playground/elixir.d.ts +18 -10
- package/dist/playground/elixir.js +630 -96
- package/dist/playground/elixirAssets.d.ts +6 -0
- package/dist/playground/elixirAssets.js +33 -0
- package/dist/playground/executionObservation.d.ts +22 -0
- package/dist/playground/executionObservation.js +65 -0
- package/dist/playground/forth.d.ts +5 -0
- package/dist/playground/forth.js +53 -0
- package/dist/playground/forthPreflight.d.ts +24 -0
- package/dist/playground/forthPreflight.js +198 -0
- package/dist/playground/fortran.d.ts +47 -0
- package/dist/playground/fortran.js +651 -0
- package/dist/playground/fortranAssets.d.ts +6 -0
- package/dist/playground/fortranAssets.js +27 -0
- package/dist/playground/gleam.d.ts +6 -0
- package/dist/playground/gleam.js +33 -0
- package/dist/playground/go.d.ts +17 -11
- package/dist/playground/go.js +376 -72
- package/dist/playground/goDebugInstrumentation.d.ts +1 -0
- package/dist/playground/goDebugInstrumentation.js +229 -0
- package/dist/playground/haskell.d.ts +44 -0
- package/dist/playground/haskell.js +678 -0
- package/dist/playground/haskellAssets.d.ts +24 -0
- package/dist/playground/haskellAssets.js +93 -0
- package/dist/playground/index.d.ts +1 -1
- package/dist/playground/index.js +360 -111
- package/dist/playground/j.d.ts +5 -0
- package/dist/playground/j.js +60 -0
- package/dist/playground/jPreflight.d.ts +26 -0
- package/dist/playground/jPreflight.js +372 -0
- package/dist/playground/janet.d.ts +5 -0
- package/dist/playground/janet.js +64 -0
- package/dist/playground/java.d.ts +24 -10
- package/dist/playground/java.js +706 -84
- package/dist/playground/javaSource.d.ts +5 -0
- package/dist/playground/javaSource.js +16 -0
- package/dist/playground/javaStdin.d.ts +1 -1
- package/dist/playground/javaStdin.js +13 -4
- package/dist/playground/julia.d.ts +5 -0
- package/dist/playground/julia.js +64 -0
- package/dist/playground/lfortran.d.ts +8 -0
- package/dist/playground/lfortran.js +30 -0
- package/dist/playground/lfortranAssets.d.ts +21 -0
- package/dist/playground/lfortranAssets.js +118 -0
- package/dist/playground/lisp.d.ts +45 -0
- package/dist/playground/lisp.js +640 -0
- package/dist/playground/lispAssets.d.ts +9 -0
- package/dist/playground/lispAssets.js +74 -0
- package/dist/playground/lldbManifest.d.ts +3 -0
- package/dist/playground/lldbManifest.js +155 -0
- package/dist/playground/lldbSession.d.ts +115 -0
- package/dist/playground/lldbSession.js +1347 -0
- package/dist/playground/loadingProgress.d.ts +16 -0
- package/dist/playground/loadingProgress.js +166 -0
- package/dist/playground/lua.d.ts +44 -0
- package/dist/playground/lua.js +630 -0
- package/dist/playground/nim.d.ts +5 -0
- package/dist/playground/nim.js +76 -0
- package/dist/playground/objectivec.d.ts +39 -0
- package/dist/playground/objectivec.js +288 -0
- package/dist/playground/ocaml.d.ts +28 -10
- package/dist/playground/ocaml.js +815 -253
- package/dist/playground/octave.d.ts +43 -0
- package/dist/playground/octave.js +783 -0
- package/dist/playground/options.d.ts +19 -40
- package/dist/playground/options.js +2 -1
- package/dist/playground/pascal.d.ts +5 -0
- package/dist/playground/pascal.js +60 -0
- package/dist/playground/perl.d.ts +5 -0
- package/dist/playground/perl.js +61 -0
- package/dist/playground/php.d.ts +44 -0
- package/dist/playground/php.js +665 -0
- package/dist/playground/prolog.d.ts +6 -0
- package/dist/playground/prolog.js +75 -0
- package/dist/playground/python.d.ts +20 -14
- package/dist/playground/python.js +445 -101
- package/dist/playground/pythonPackageLock.d.ts +6 -0
- package/dist/playground/pythonPackageLock.js +56 -0
- package/dist/playground/r.d.ts +44 -0
- package/dist/playground/r.js +637 -0
- package/dist/playground/ruby.d.ts +46 -0
- package/dist/playground/ruby.js +732 -0
- package/dist/playground/rubyAssets.d.ts +23 -0
- package/dist/playground/rubyAssets.js +68 -0
- package/dist/playground/rubyTestPreflight.d.ts +2 -0
- package/dist/playground/rubyTestPreflight.js +18 -0
- package/dist/playground/runtimeModule.d.ts +1 -0
- package/dist/playground/runtimeModule.js +5 -0
- package/dist/playground/rust.d.ts +44 -13
- package/dist/playground/rust.js +714 -76
- package/dist/playground/rustExecutableGraph.d.ts +85 -0
- package/dist/playground/rustExecutableGraph.js +946 -0
- package/dist/playground/rustWorkerLimits.d.ts +17 -0
- package/dist/playground/rustWorkerLimits.js +34 -0
- package/dist/playground/sandbox.d.ts +16 -10
- package/dist/playground/sharedBuffer.d.ts +6 -0
- package/dist/playground/sharedBuffer.js +12 -0
- package/dist/playground/sqlite.d.ts +38 -0
- package/dist/playground/sqlite.js +550 -0
- package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -0
- package/dist/playground/staticRuntimeModuleVersion.js +2 -0
- package/dist/playground/staticRuntimePreflight.d.ts +13 -0
- package/dist/playground/staticRuntimePreflight.js +231 -0
- package/dist/playground/staticRuntimePreflightExecute.d.ts +8 -0
- package/dist/playground/staticRuntimePreflightExecute.js +66 -0
- package/dist/playground/staticRuntimePreflightProtocol.d.ts +68 -0
- package/dist/playground/staticRuntimePreflightProtocol.js +339 -0
- package/dist/playground/staticStdinRing.d.ts +45 -0
- package/dist/playground/staticStdinRing.js +158 -0
- package/dist/playground/staticWorkerRuntime.d.ts +154 -0
- package/dist/playground/staticWorkerRuntime.js +1917 -0
- package/dist/playground/stdinBuffer.d.ts +9 -7
- package/dist/playground/stdinBuffer.js +9 -18
- package/dist/playground/swift.d.ts +5 -0
- package/dist/playground/swift.js +17 -0
- package/dist/playground/tcl.d.ts +5 -0
- package/dist/playground/tcl.js +62 -0
- package/dist/playground/teavmConfig.d.ts +1 -1
- package/dist/playground/teavmConfig.js +2 -2
- package/dist/playground/tinygo.d.ts +48 -18
- package/dist/playground/tinygo.js +1202 -329
- package/dist/playground/tinygoExecutableGraph.d.ts +44 -0
- package/dist/playground/tinygoExecutableGraph.js +449 -0
- package/dist/playground/typescript.d.ts +55 -0
- package/dist/playground/typescript.js +924 -0
- package/dist/playground/wasm.d.ts +43 -0
- package/dist/playground/wasm.js +608 -0
- package/dist/playground/wasmAwkVersion.d.ts +59 -0
- package/dist/playground/wasmAwkVersion.js +31 -0
- package/dist/playground/wasmBashVersion.d.ts +63 -0
- package/dist/playground/wasmBashVersion.js +36 -0
- package/dist/playground/wasmBqnVersion.d.ts +24 -0
- package/dist/playground/wasmBqnVersion.js +24 -0
- package/dist/playground/wasmC3Version.d.ts +20 -0
- package/dist/playground/wasmC3Version.js +21 -0
- package/dist/playground/wasmClojureScriptVersion.d.ts +21 -0
- package/dist/playground/wasmClojureScriptVersion.js +21 -0
- package/dist/playground/wasmDIntegrity.d.ts +15 -0
- package/dist/playground/wasmDIntegrity.js +15 -0
- package/dist/playground/wasmDVersion.d.ts +1 -0
- package/dist/playground/wasmDVersion.js +1 -0
- package/dist/playground/wasmDebugVersion.d.ts +6 -0
- package/dist/playground/wasmDebugVersion.js +6 -0
- package/dist/playground/wasmDotnetVersion.d.ts +1 -0
- package/dist/playground/wasmDotnetVersion.js +1 -0
- package/dist/playground/wasmElixirVersion.d.ts +21 -1
- package/dist/playground/wasmElixirVersion.js +21 -1
- package/dist/playground/wasmForthVersion.d.ts +18 -0
- package/dist/playground/wasmForthVersion.js +18 -0
- package/dist/playground/wasmFortranExecutionAssets.d.ts +15 -0
- package/dist/playground/wasmFortranExecutionAssets.js +15 -0
- package/dist/playground/wasmFortranVersion.d.ts +1 -0
- package/dist/playground/wasmFortranVersion.js +1 -0
- package/dist/playground/wasmGleamVersion.d.ts +5 -0
- package/dist/playground/wasmGleamVersion.js +5 -0
- package/dist/playground/wasmGoVersion.d.ts +1 -1
- package/dist/playground/wasmGoVersion.js +1 -1
- package/dist/playground/wasmHaskellVersion.d.ts +1 -0
- package/dist/playground/wasmHaskellVersion.js +1 -0
- package/dist/playground/wasmJVersion.d.ts +24 -0
- package/dist/playground/wasmJVersion.js +24 -0
- package/dist/playground/wasmJanetVersion.d.ts +53 -0
- package/dist/playground/wasmJanetVersion.js +30 -0
- package/dist/playground/wasmJuliaVersion.d.ts +71 -0
- package/dist/playground/wasmJuliaVersion.js +39 -0
- package/dist/playground/wasmLfortranVersion.d.ts +28 -0
- package/dist/playground/wasmLfortranVersion.js +29 -0
- package/dist/playground/wasmLispVersion.d.ts +1 -0
- package/dist/playground/wasmLispVersion.js +1 -0
- package/dist/playground/wasmLuaVersion.d.ts +1 -0
- package/dist/playground/wasmLuaVersion.js +1 -0
- package/dist/playground/wasmNimVersion.d.ts +125 -0
- package/dist/playground/wasmNimVersion.js +66 -0
- package/dist/playground/wasmObjectiveCVersion.d.ts +27 -0
- package/dist/playground/wasmObjectiveCVersion.js +27 -0
- package/dist/playground/wasmOcamlVersion.d.ts +12 -1
- package/dist/playground/wasmOcamlVersion.js +12 -1
- package/dist/playground/wasmOctaveVersion.d.ts +1 -0
- package/dist/playground/wasmOctaveVersion.js +1 -0
- package/dist/playground/wasmPascalVersion.d.ts +61 -0
- package/dist/playground/wasmPascalVersion.js +34 -0
- package/dist/playground/wasmPerlVersion.d.ts +71 -0
- package/dist/playground/wasmPerlVersion.js +39 -0
- package/dist/playground/wasmPrologVersion.d.ts +31 -0
- package/dist/playground/wasmPrologVersion.js +31 -0
- package/dist/playground/wasmRVersion.d.ts +1 -0
- package/dist/playground/wasmRVersion.js +1 -0
- package/dist/playground/wasmRustVersion.d.ts +1306 -1
- package/dist/playground/wasmRustVersion.js +1458 -1
- package/dist/playground/wasmSwiftVersion.d.ts +1 -0
- package/dist/playground/wasmSwiftVersion.js +1 -0
- package/dist/playground/wasmTclVersion.d.ts +85 -0
- package/dist/playground/wasmTclVersion.js +46 -0
- package/dist/playground/wasmTinyGoVersion.d.ts +98 -1
- package/dist/playground/wasmTinyGoVersion.js +107 -1
- package/dist/playground/wasmTypeScriptVersion.d.ts +5 -0
- package/dist/playground/wasmTypeScriptVersion.js +5 -0
- package/dist/playground/wasmWatVersion.d.ts +1 -0
- package/dist/playground/wasmWatVersion.js +1 -0
- package/dist/playground/wasmZigVersion.d.ts +13 -0
- package/dist/playground/wasmZigVersion.js +13 -0
- package/dist/playground/wat.d.ts +44 -0
- package/dist/playground/wat.js +622 -0
- package/dist/playground/worker/assemblyscript.js +339 -0
- package/dist/playground/worker/assets.d.ts +7 -0
- package/dist/playground/worker/assets.js +288 -39
- package/dist/playground/worker/bash.js +338 -0
- package/dist/playground/worker/bashNestedBootstrap.d.ts +6 -0
- package/dist/playground/worker/bashNestedBootstrap.js +59 -0
- package/dist/playground/worker/bashRuntime.d.ts +89 -0
- package/dist/playground/worker/bashRuntime.js +982 -0
- package/dist/playground/worker/clang.js +92 -13
- package/dist/playground/worker/cobol.js +107 -0
- package/dist/playground/worker/d.js +199 -0
- package/dist/playground/worker/dotnet.js +141 -0
- package/dist/playground/worker/duckdb.d.ts +1 -0
- package/dist/playground/worker/duckdb.js +136 -0
- package/dist/playground/worker/elixir.js +307 -41
- package/dist/playground/worker/fortran.d.ts +1 -0
- package/dist/playground/worker/fortran.js +295 -0
- package/dist/playground/worker/go.js +246 -40
- package/dist/playground/worker/haskell.d.ts +7 -0
- package/dist/playground/worker/haskell.js +465 -0
- package/dist/playground/worker/java.js +59 -20
- package/dist/playground/worker/lisp.d.ts +1 -0
- package/dist/playground/worker/lisp.js +195 -0
- package/dist/playground/worker/lua.d.ts +1 -0
- package/dist/playground/worker/lua.js +163 -0
- package/dist/playground/worker/objectivec.d.ts +1 -0
- package/dist/playground/worker/objectivec.js +10 -0
- package/dist/playground/worker/ocaml.js +206 -58
- package/dist/playground/worker/php.d.ts +1 -0
- package/dist/playground/worker/php.js +261 -0
- package/dist/playground/worker/python.js +201 -44
- package/dist/playground/worker/r.d.ts +1 -0
- package/dist/playground/worker/r.js +192 -0
- package/dist/playground/worker/ruby.d.ts +1 -0
- package/dist/playground/worker/ruby.js +248 -0
- package/dist/playground/worker/runtimeAssetFetch.d.ts +15 -0
- package/dist/playground/worker/runtimeAssetFetch.js +375 -0
- package/dist/playground/worker/rust.js +546 -20
- package/dist/playground/worker/sqlite.d.ts +1 -0
- package/dist/playground/worker/sqlite.js +112 -0
- package/dist/playground/worker/staticRuntimePreflight.d.ts +1 -0
- package/dist/playground/worker/staticRuntimePreflight.js +56 -0
- package/dist/playground/worker/tinygo.js +34 -9
- package/dist/playground/worker/typescript.d.ts +1 -0
- package/dist/playground/worker/typescript.js +251 -0
- package/dist/playground/worker/wasm.d.ts +1 -0
- package/dist/playground/worker/wasm.js +273 -0
- package/dist/playground/worker/wat.d.ts +1 -0
- package/dist/playground/worker/wat.js +188 -0
- package/dist/playground/worker/zig.d.ts +8 -0
- package/dist/playground/worker/zig.js +578 -0
- package/dist/playground/workerProgress.d.ts +15 -0
- package/dist/playground/workerProgress.js +72 -0
- package/dist/playground/workerSession.d.ts +28 -0
- package/dist/playground/workerSession.js +164 -0
- package/dist/playground/zig.d.ts +46 -0
- package/dist/playground/zig.js +690 -0
- package/dist/playground/zigAssets.d.ts +6 -0
- package/dist/playground/zigAssets.js +49 -0
- package/package.json +234 -105
- package/dist/clang/app.d.ts +0 -75
- package/dist/clang/app.js +0 -744
- package/dist/clang/apply.d.ts +0 -2
- package/dist/clang/apply.js +0 -11
- package/dist/clang/color.d.ts +0 -3
- package/dist/clang/color.js +0 -3
- package/dist/clang/encode.d.ts +0 -4
- package/dist/clang/encode.js +0 -20
- package/dist/clang/error.d.ts +0 -14
- package/dist/clang/error.js +0 -27
- package/dist/clang/gccCompat.d.ts +0 -15
- package/dist/clang/gccCompat.js +0 -767
- package/dist/clang/index.d.ts +0 -85
- package/dist/clang/index.js +0 -1077
- package/dist/clang/memory/index.d.ts +0 -4
- package/dist/clang/memory/index.js +0 -4
- package/dist/clang/memory/memFs.d.ts +0 -35
- package/dist/clang/memory/memFs.js +0 -132
- package/dist/clang/memory/memory.d.ts +0 -22
- package/dist/clang/memory/memory.js +0 -73
- package/dist/clang/memory/tar.d.ts +0 -2
- package/dist/clang/memory/tar.js +0 -59
- package/dist/clang/url.d.ts +0 -4
- package/dist/clang/url.js +0 -5
- package/dist/clang/wasm.d.ts +0 -4
- package/dist/clang/wasm.js +0 -50
- package/dist/clangd/config.d.ts +0 -18
- package/dist/clangd/config.js +0 -14
- package/dist/clangd/jsonStream.d.ts +0 -9
- package/dist/clangd/jsonStream.js +0 -48
- package/dist/clangd/session.d.ts +0 -18
- package/dist/clangd/session.js +0 -112
- package/dist/clangd/worker.js +0 -131
- package/dist/debug/controller.svelte.d.ts +0 -43
- package/dist/debug/controller.svelte.js +0 -268
- package/dist/debug/editor/index.d.ts +0 -2
- package/dist/debug/editor/index.js +0 -1
- package/dist/debug/editor/monaco.d.ts +0 -26
- package/dist/debug/editor/monaco.js +0 -128
- package/dist/debug/expression.d.ts +0 -26
- package/dist/debug/expression.js +0 -547
- package/dist/debug/index.d.ts +0 -8
- package/dist/debug/index.js +0 -5
- package/dist/debug/language/cpp.d.ts +0 -2
- package/dist/debug/language/cpp.js +0 -7
- package/dist/debug/language/index.d.ts +0 -3
- package/dist/debug/language/index.js +0 -2
- package/dist/debug/language/python.d.ts +0 -2
- package/dist/debug/language/python.js +0 -14
- package/dist/debug/language/types.d.ts +0 -6
- package/dist/debug/locals.d.ts +0 -2
- package/dist/debug/locals.js +0 -8
- package/dist/lsp/cpp/server.d.ts +0 -2
- package/dist/lsp/cpp/server.js +0 -68
- package/dist/lsp/index.d.ts +0 -5
- package/dist/lsp/index.js +0 -4
- package/dist/lsp/python/main.worker.js +0 -92
- package/dist/lsp/python/package/arcturus_python_lsp/__init__.py +0 -3
- package/dist/lsp/python/package/arcturus_python_lsp/server.py +0 -462
- package/dist/lsp/python/server.d.ts +0 -2
- package/dist/lsp/python/server.js +0 -54
- package/dist/lsp/registry.d.ts +0 -2
- package/dist/lsp/registry.js +0 -12
- package/dist/lsp/runtime.d.ts +0 -5
- package/dist/lsp/runtime.js +0 -31
- package/dist/lsp/types.d.ts +0 -17
- package/dist/terminal/Terminal.svelte +0 -422
- package/dist/terminal/Terminal.svelte.d.ts +0 -26
- package/dist/terminal/index.d.ts +0 -7
- package/dist/terminal/index.js +0 -5
- package/dist/terminal/plugin/index.d.ts +0 -9
- package/dist/terminal/plugin/index.js +0 -19
- package/dist/terminal/theme.d.ts +0 -49
- package/dist/terminal/theme.js +0 -49
- package/dist/terminal/types.d.ts +0 -18
- package/dist/utils/vscodeJsonrpcBrowser.d.ts +0 -5
- package/dist/utils/vscodeJsonrpcBrowser.js +0 -4
- /package/dist/{clangd/worker.d.ts → playground/worker/assemblyscript.d.ts} +0 -0
- /package/dist/{debug/language/types.js → playground/worker/bash.d.ts} +0 -0
- /package/dist/{lsp/python/main.worker.d.ts → playground/worker/cobol.d.ts} +0 -0
- /package/dist/{lsp/types.js → playground/worker/d.d.ts} +0 -0
- /package/dist/{terminal/types.js → playground/worker/dotnet.d.ts} +0 -0
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { WorkerAssetBridge } from './assetBridge';
|
|
2
2
|
import { resolveRuntimeAssetConfig } from './assets';
|
|
3
3
|
import { bufferedSequence, flushBufferedEof, flushQueuedStdin, resetBufferedStdin, waitForBufferedSequenceChange } from './stdinBuffer';
|
|
4
|
+
import { createWasmIdleSharedBuffer, requireSharedArrayBuffer } from './sharedBuffer';
|
|
5
|
+
import { WorkerSession } from './workerSession';
|
|
6
|
+
import { reportWorkerProgress } from './workerProgress';
|
|
7
|
+
import { BusyError, TimeoutError, resolveExecutionLimits } from '@wasm-idle/core';
|
|
8
|
+
const debugBreakpointBufferInts = 1028;
|
|
9
|
+
const abortReason = (signal, phase) => signal.reason !== undefined
|
|
10
|
+
? signal.reason
|
|
11
|
+
: new DOMException(phase === 'startup' ? 'Python runtime startup aborted' : 'Python execution aborted', 'AbortError');
|
|
4
12
|
class Python {
|
|
5
13
|
ts = Date.now();
|
|
6
14
|
output = null;
|
|
7
15
|
ondebug;
|
|
8
16
|
image;
|
|
9
17
|
worker = null;
|
|
10
|
-
buffer =
|
|
11
|
-
debugBuffer =
|
|
12
|
-
watchBuffer =
|
|
13
|
-
watchResultBuffer =
|
|
14
|
-
interruptBuffer =
|
|
18
|
+
buffer = createWasmIdleSharedBuffer(1024);
|
|
19
|
+
debugBuffer = createWasmIdleSharedBuffer(Int32Array.BYTES_PER_ELEMENT * debugBreakpointBufferInts);
|
|
20
|
+
watchBuffer = createWasmIdleSharedBuffer(1024);
|
|
21
|
+
watchResultBuffer = createWasmIdleSharedBuffer(1024);
|
|
22
|
+
interruptBuffer = createWasmIdleSharedBuffer(1);
|
|
15
23
|
pendingInput = [];
|
|
16
24
|
begin = 0;
|
|
17
25
|
elapse = 0;
|
|
@@ -20,48 +28,264 @@ class Python {
|
|
|
20
28
|
pendingEof = false;
|
|
21
29
|
exit = true;
|
|
22
30
|
assetBridge = null;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
activeOperation = null;
|
|
32
|
+
workerSession = new WorkerSession({
|
|
33
|
+
label: 'Python',
|
|
34
|
+
onDispose: (worker) => {
|
|
35
|
+
if (this.worker !== worker)
|
|
36
|
+
return;
|
|
37
|
+
delete this.worker;
|
|
38
|
+
this.assetBridge?.dispose();
|
|
39
|
+
this.assetBridge = null;
|
|
40
|
+
this.exit = true;
|
|
27
41
|
this.waitingForInput = false;
|
|
28
42
|
this.pendingEof = false;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
this.ondebug?.({ type: 'stop' });
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
beginOperation(phase) {
|
|
47
|
+
if (this.activeOperation) {
|
|
48
|
+
throw new BusyError('Python runtime already has an active operation', {
|
|
49
|
+
runtimeId: 'PYTHON3',
|
|
50
|
+
phase: this.activeOperation.phase
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const operation = {
|
|
54
|
+
token: Symbol(phase),
|
|
55
|
+
phase,
|
|
56
|
+
cancelled: false,
|
|
57
|
+
cleanedUp: false,
|
|
58
|
+
cleanups: []
|
|
59
|
+
};
|
|
60
|
+
this.activeOperation = operation;
|
|
61
|
+
return operation;
|
|
62
|
+
}
|
|
63
|
+
isOperationActive(operation) {
|
|
64
|
+
return this.activeOperation?.token === operation.token && !operation.cancelled;
|
|
65
|
+
}
|
|
66
|
+
releaseOperation(operation) {
|
|
67
|
+
if (this.activeOperation?.token !== operation.token)
|
|
68
|
+
return false;
|
|
69
|
+
this.activeOperation = null;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
cleanupOperation(operation) {
|
|
73
|
+
if (operation.cleanedUp)
|
|
74
|
+
return;
|
|
75
|
+
operation.cleanedUp = true;
|
|
76
|
+
for (const cleanup of operation.cleanups.splice(0)) {
|
|
77
|
+
try {
|
|
78
|
+
cleanup();
|
|
35
79
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
80
|
+
catch {
|
|
81
|
+
// Caller-owned lifecycle cleanup must not replace the operation result.
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
releaseBeforeSession(operation, reason) {
|
|
86
|
+
const outcome = operation.cancelled ? operation.cancellationReason : reason;
|
|
87
|
+
this.releaseOperation(operation);
|
|
88
|
+
this.cleanupOperation(operation);
|
|
89
|
+
return outcome;
|
|
90
|
+
}
|
|
91
|
+
cancelOperation(operation, reason) {
|
|
92
|
+
if (!this.isOperationActive(operation))
|
|
93
|
+
return;
|
|
94
|
+
operation.cancelled = true;
|
|
95
|
+
operation.cancellationReason = reason;
|
|
96
|
+
this.activeOperation = null;
|
|
97
|
+
this.waitingForInput = false;
|
|
98
|
+
this.pendingEof = false;
|
|
99
|
+
this.uid += 1;
|
|
100
|
+
this.exit = true;
|
|
101
|
+
this.workerSession.terminate(reason);
|
|
102
|
+
this.cleanupOperation(operation);
|
|
103
|
+
}
|
|
104
|
+
bindAbortSignal(operation, signal) {
|
|
105
|
+
if (!signal || !this.isOperationActive(operation))
|
|
106
|
+
return;
|
|
107
|
+
let registered = false;
|
|
108
|
+
const onAbort = () => {
|
|
109
|
+
if (!this.isOperationActive(operation))
|
|
110
|
+
return;
|
|
111
|
+
let reason;
|
|
112
|
+
try {
|
|
113
|
+
reason = abortReason(signal, operation.phase);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
reason = error;
|
|
117
|
+
}
|
|
118
|
+
this.cancelOperation(operation, reason);
|
|
119
|
+
};
|
|
120
|
+
operation.cleanups.push(() => {
|
|
121
|
+
if (registered)
|
|
122
|
+
signal.removeEventListener('abort', onAbort);
|
|
123
|
+
});
|
|
124
|
+
try {
|
|
125
|
+
registered = true;
|
|
126
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
127
|
+
if (signal.aborted)
|
|
128
|
+
onAbort();
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
this.cancelOperation(operation, error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
bindStartupTimeout(operation, timeoutMs) {
|
|
135
|
+
if (!this.isOperationActive(operation))
|
|
136
|
+
return;
|
|
137
|
+
let timeout;
|
|
138
|
+
operation.cleanups.push(() => {
|
|
139
|
+
if (timeout !== undefined)
|
|
140
|
+
clearTimeout(timeout);
|
|
141
|
+
});
|
|
142
|
+
try {
|
|
143
|
+
timeout = setTimeout(() => {
|
|
144
|
+
if (!this.isOperationActive(operation))
|
|
145
|
+
return;
|
|
146
|
+
this.cancelOperation(operation, new TimeoutError(`Python startup timed out after ${timeoutMs} ms`, {
|
|
147
|
+
phase: 'startup',
|
|
148
|
+
runtimeId: 'PYTHON3',
|
|
149
|
+
timeoutMs
|
|
150
|
+
}));
|
|
151
|
+
}, timeoutMs);
|
|
152
|
+
if (operation.cleanedUp)
|
|
153
|
+
clearTimeout(timeout);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
this.cancelOperation(operation, error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
load(runtimeAssets = '', code = '', log = true, _args = [], options = {}, progress) {
|
|
160
|
+
let operation;
|
|
161
|
+
try {
|
|
162
|
+
operation = this.beginOperation('startup');
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
return Promise.reject(error);
|
|
166
|
+
}
|
|
167
|
+
let limits;
|
|
168
|
+
let signal;
|
|
169
|
+
try {
|
|
170
|
+
signal = options.signal;
|
|
171
|
+
limits = resolveExecutionLimits(options.limits);
|
|
172
|
+
if (!this.isOperationActive(operation)) {
|
|
173
|
+
return Promise.reject(this.releaseBeforeSession(operation, 'Python runtime startup cancelled'));
|
|
174
|
+
}
|
|
175
|
+
if (signal?.aborted) {
|
|
176
|
+
return Promise.reject(this.releaseBeforeSession(operation, abortReason(signal, 'startup')));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
return Promise.reject(this.releaseBeforeSession(operation, error));
|
|
181
|
+
}
|
|
182
|
+
const loading = this.workerSession.load(async (resolve, reject) => {
|
|
183
|
+
const resolveOperation = () => {
|
|
184
|
+
if (!this.releaseOperation(operation))
|
|
185
|
+
return;
|
|
186
|
+
resolve();
|
|
187
|
+
this.cleanupOperation(operation);
|
|
188
|
+
};
|
|
189
|
+
const rejectOperation = (reason) => {
|
|
190
|
+
if (!this.releaseOperation(operation))
|
|
191
|
+
return;
|
|
192
|
+
reject(reason);
|
|
193
|
+
this.cleanupOperation(operation);
|
|
194
|
+
};
|
|
195
|
+
try {
|
|
196
|
+
if (!this.isOperationActive(operation))
|
|
197
|
+
return;
|
|
198
|
+
this.pendingInput = [];
|
|
199
|
+
this.waitingForInput = false;
|
|
200
|
+
this.pendingEof = false;
|
|
201
|
+
const assetConfig = resolveRuntimeAssetConfig('python', runtimeAssets, typeof window !== 'undefined' ? window.location.href : '');
|
|
202
|
+
if (!this.isOperationActive(operation))
|
|
203
|
+
return;
|
|
204
|
+
const needsWorkerReset = !this.worker ||
|
|
205
|
+
!this.assetBridge ||
|
|
206
|
+
!this.assetBridge.matches(assetConfig, limits.maxAssetBytes);
|
|
207
|
+
if (needsWorkerReset && this.worker)
|
|
208
|
+
this.workerSession.reset();
|
|
209
|
+
if (!this.isOperationActive(operation))
|
|
210
|
+
return;
|
|
211
|
+
if (!this.worker) {
|
|
212
|
+
const WorkerConstructor = (await import('./worker/python?worker'))
|
|
213
|
+
.default;
|
|
214
|
+
if (!this.isOperationActive(operation))
|
|
215
|
+
return;
|
|
216
|
+
const worker = new WorkerConstructor();
|
|
217
|
+
if (!this.isOperationActive(operation)) {
|
|
218
|
+
worker.terminate();
|
|
41
219
|
return;
|
|
42
|
-
if (event.data?.load)
|
|
43
|
-
resolve();
|
|
44
|
-
if (event.data?.error)
|
|
45
|
-
reject(event.data.error);
|
|
46
|
-
};
|
|
47
|
-
this.worker.postMessage({
|
|
48
|
-
load: true,
|
|
49
|
-
log,
|
|
50
|
-
code,
|
|
51
|
-
assets: {
|
|
52
|
-
baseUrl: assetConfig.baseUrl,
|
|
53
|
-
useAssetBridge: assetConfig.useAssetBridge
|
|
54
220
|
}
|
|
55
|
-
|
|
221
|
+
this.worker = worker;
|
|
222
|
+
this.workerSession.attach(worker);
|
|
223
|
+
const assetBridge = new WorkerAssetBridge(worker, 'python', assetConfig, progress, limits.maxAssetBytes);
|
|
224
|
+
if (!this.isOperationActive(operation) || this.worker !== worker) {
|
|
225
|
+
assetBridge.dispose();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
this.assetBridge = assetBridge;
|
|
229
|
+
let handler;
|
|
230
|
+
handler = (event) => {
|
|
231
|
+
if (this.worker !== worker || worker.onmessage !== handler)
|
|
232
|
+
return;
|
|
233
|
+
try {
|
|
234
|
+
if (this.assetBridge?.handleMessage(event))
|
|
235
|
+
return;
|
|
236
|
+
if (!this.isOperationActive(operation))
|
|
237
|
+
return;
|
|
238
|
+
reportWorkerProgress(progress, event.data?.progress);
|
|
239
|
+
if (event.data?.load) {
|
|
240
|
+
progress?.set?.(1);
|
|
241
|
+
resolveOperation();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (event.data?.error !== undefined)
|
|
245
|
+
rejectOperation(event.data.error);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
if (this.isOperationActive(operation))
|
|
249
|
+
rejectOperation(error);
|
|
250
|
+
else
|
|
251
|
+
this.workerSession.terminate(error);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
worker.onmessage = handler;
|
|
255
|
+
worker.postMessage({
|
|
256
|
+
load: true,
|
|
257
|
+
log,
|
|
258
|
+
code,
|
|
259
|
+
assets: {
|
|
260
|
+
baseUrl: assetConfig.baseUrl,
|
|
261
|
+
maxAssetBytes: limits.maxAssetBytes,
|
|
262
|
+
useAssetBridge: assetConfig.useAssetBridge
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const worker = this.worker;
|
|
268
|
+
if (!this.assetBridge) {
|
|
269
|
+
rejectOperation('Worker asset bridge unavailable');
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
this.assetBridge.rebind(worker, assetConfig, progress, limits.maxAssetBytes);
|
|
273
|
+
progress?.set?.(1);
|
|
274
|
+
if (!this.isOperationActive(operation) || this.worker !== worker)
|
|
275
|
+
return;
|
|
276
|
+
resolveOperation();
|
|
56
277
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return reject('Worker asset bridge unavailable');
|
|
60
|
-
this.assetBridge.rebind(this.worker, assetConfig, progress);
|
|
61
|
-
this.worker.postMessage({ log });
|
|
62
|
-
resolve();
|
|
278
|
+
catch (error) {
|
|
279
|
+
rejectOperation(error);
|
|
63
280
|
}
|
|
64
281
|
});
|
|
282
|
+
const timeoutMs = Math.min(2_147_483_647, limits.assetTimeoutMs + limits.startupTimeoutMs);
|
|
283
|
+
this.bindStartupTimeout(operation, timeoutMs);
|
|
284
|
+
this.bindAbortSignal(operation, signal);
|
|
285
|
+
return loading.finally(() => {
|
|
286
|
+
this.releaseOperation(operation);
|
|
287
|
+
this.cleanupOperation(operation);
|
|
288
|
+
});
|
|
65
289
|
}
|
|
66
290
|
write(input) {
|
|
67
291
|
this.pendingInput.push(input);
|
|
@@ -86,67 +310,177 @@ class Python {
|
|
|
86
310
|
}
|
|
87
311
|
}
|
|
88
312
|
run(code, prepare, _log = true, _prog, _args = [], options = {}) {
|
|
313
|
+
let activeOperation;
|
|
314
|
+
try {
|
|
315
|
+
activeOperation = this.beginOperation('execute');
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
return Promise.reject(error);
|
|
319
|
+
}
|
|
320
|
+
const worker = this.worker;
|
|
321
|
+
let signal;
|
|
322
|
+
let debug;
|
|
323
|
+
let breakpoints;
|
|
324
|
+
let stdin;
|
|
325
|
+
let pauseOnEntry;
|
|
326
|
+
let activePath;
|
|
327
|
+
let debugPath;
|
|
328
|
+
let workspaceFiles;
|
|
329
|
+
try {
|
|
330
|
+
signal = options.signal;
|
|
331
|
+
debug = !!options.debug;
|
|
332
|
+
breakpoints = [...(options.breakpoints || [])];
|
|
333
|
+
stdin = options.stdin;
|
|
334
|
+
pauseOnEntry = !!options.pauseOnEntry;
|
|
335
|
+
activePath = options.activePath;
|
|
336
|
+
debugPath = options.debugPath;
|
|
337
|
+
workspaceFiles = options.workspaceFiles;
|
|
338
|
+
if (!this.isOperationActive(activeOperation)) {
|
|
339
|
+
return Promise.reject(this.releaseBeforeSession(activeOperation, 'Python execution cancelled'));
|
|
340
|
+
}
|
|
341
|
+
if (debug)
|
|
342
|
+
requireSharedArrayBuffer('Python debugging');
|
|
343
|
+
this.setBreakpoints(debug ? breakpoints : []);
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
return Promise.reject(this.releaseBeforeSession(activeOperation, error));
|
|
347
|
+
}
|
|
348
|
+
if (!worker || this.worker !== worker) {
|
|
349
|
+
return Promise.reject(this.releaseBeforeSession(activeOperation, 'Worker not loaded'));
|
|
350
|
+
}
|
|
89
351
|
this.exit = false;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
352
|
+
const running = new Promise((resolve, reject) => {
|
|
353
|
+
const workerOperation = this.workerSession.beginRun(worker, reject);
|
|
354
|
+
this.bindAbortSignal(activeOperation, signal);
|
|
355
|
+
if (!this.isOperationActive(activeOperation))
|
|
356
|
+
return;
|
|
357
|
+
const interrupt = new Uint8Array(this.interruptBuffer), runUid = ++this.uid;
|
|
358
|
+
let handler;
|
|
359
|
+
const ownsRun = () => this.isOperationActive(activeOperation) &&
|
|
360
|
+
this.worker === worker &&
|
|
361
|
+
worker.onmessage === handler &&
|
|
362
|
+
runUid === this.uid;
|
|
363
|
+
const settleRunState = () => {
|
|
364
|
+
this.elapse = Date.now() - this.begin;
|
|
365
|
+
this.exit = true;
|
|
366
|
+
this.waitingForInput = false;
|
|
367
|
+
this.pendingEof = false;
|
|
368
|
+
};
|
|
369
|
+
const claimRun = () => {
|
|
370
|
+
if (!ownsRun())
|
|
371
|
+
return false;
|
|
372
|
+
settleRunState();
|
|
373
|
+
this.workerSession.complete(workerOperation);
|
|
374
|
+
this.releaseOperation(activeOperation);
|
|
375
|
+
this.cleanupOperation(activeOperation);
|
|
376
|
+
try {
|
|
377
|
+
if (worker.onmessage === handler)
|
|
378
|
+
worker.onmessage = null;
|
|
379
|
+
}
|
|
380
|
+
catch {
|
|
381
|
+
// Handler cleanup must not replace the execution result.
|
|
382
|
+
}
|
|
383
|
+
return true;
|
|
384
|
+
};
|
|
385
|
+
const failRun = (reason, disposeWorker = false) => {
|
|
386
|
+
if (disposeWorker) {
|
|
387
|
+
if (!ownsRun())
|
|
388
|
+
return;
|
|
389
|
+
this.cancelOperation(activeOperation, reason);
|
|
97
390
|
return;
|
|
98
|
-
if (!this.worker)
|
|
99
|
-
return reject('Worker not loaded');
|
|
100
|
-
if (_uid !== this.uid)
|
|
101
|
-
return (this.worker.onmessage = null);
|
|
102
|
-
const { output, results, log, error, buffer, type, data: payload, debugEvent } = event.data;
|
|
103
|
-
if (buffer) {
|
|
104
|
-
this.waitingForInput = true;
|
|
105
|
-
this.flushPendingInput();
|
|
106
391
|
}
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
392
|
+
if (!claimRun())
|
|
393
|
+
return;
|
|
394
|
+
reject(reason);
|
|
395
|
+
};
|
|
396
|
+
handler = (event) => {
|
|
397
|
+
if (!ownsRun())
|
|
398
|
+
return;
|
|
399
|
+
try {
|
|
400
|
+
if (this.assetBridge?.handleMessage(event))
|
|
401
|
+
return;
|
|
402
|
+
const { output, results, log, error, buffer, type, data: payload, debugEvent } = event.data;
|
|
403
|
+
reportWorkerProgress(_prog, event.data?.progress);
|
|
404
|
+
if (!ownsRun())
|
|
405
|
+
return;
|
|
406
|
+
if (buffer) {
|
|
407
|
+
if (!prepare) {
|
|
408
|
+
_prog?.report?.({
|
|
409
|
+
kind: 'ready',
|
|
410
|
+
state: 'waiting-input',
|
|
411
|
+
reason: 'stdin-request',
|
|
412
|
+
label: 'Python program is waiting for input'
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
this.waitingForInput = true;
|
|
416
|
+
this.flushPendingInput();
|
|
417
|
+
if (!ownsRun())
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (type === 'img' && payload)
|
|
421
|
+
this.image?.(payload);
|
|
422
|
+
if (!ownsRun())
|
|
423
|
+
return;
|
|
424
|
+
if (output)
|
|
425
|
+
this.output?.(output);
|
|
426
|
+
if (!ownsRun())
|
|
427
|
+
return;
|
|
428
|
+
if (debugEvent)
|
|
429
|
+
this.ondebug?.(debugEvent);
|
|
430
|
+
if (!ownsRun())
|
|
431
|
+
return;
|
|
432
|
+
if (log)
|
|
433
|
+
console.log(log);
|
|
434
|
+
if (results !== undefined) {
|
|
435
|
+
this.ondebug?.({ type: 'stop' });
|
|
436
|
+
if (!claimRun())
|
|
437
|
+
return;
|
|
438
|
+
resolve(results);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (error !== undefined) {
|
|
442
|
+
this.ondebug?.({ type: 'stop' });
|
|
443
|
+
failRun(error);
|
|
444
|
+
}
|
|
121
445
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (error) {
|
|
125
|
-
this.elapse = Date.now() - this.begin;
|
|
126
|
-
this.exit = true;
|
|
127
|
-
this.waitingForInput = false;
|
|
128
|
-
this.pendingEof = false;
|
|
129
|
-
this.activeReject = null;
|
|
130
|
-
this.ondebug?.({ type: 'stop' });
|
|
131
|
-
reject(error);
|
|
446
|
+
catch (error) {
|
|
447
|
+
failRun(error, true);
|
|
132
448
|
}
|
|
133
449
|
};
|
|
134
450
|
interrupt[0] = 0;
|
|
135
|
-
|
|
451
|
+
worker.onmessage = handler;
|
|
136
452
|
this.begin = Date.now();
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
453
|
+
try {
|
|
454
|
+
worker.postMessage({
|
|
455
|
+
code,
|
|
456
|
+
prepare,
|
|
457
|
+
buffer: this.buffer,
|
|
458
|
+
debugBuffer: this.debugBuffer,
|
|
459
|
+
watchBuffer: this.watchBuffer,
|
|
460
|
+
watchResultBuffer: this.watchResultBuffer,
|
|
461
|
+
interrupt: this.interruptBuffer,
|
|
462
|
+
context: {},
|
|
463
|
+
stdin,
|
|
464
|
+
debug,
|
|
465
|
+
breakpoints,
|
|
466
|
+
pauseOnEntry,
|
|
467
|
+
activePath,
|
|
468
|
+
debugPath,
|
|
469
|
+
workspaceFiles
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
failRun(error);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
return running.finally(() => {
|
|
477
|
+
if (this.isOperationActive(activeOperation)) {
|
|
478
|
+
this.releaseOperation(activeOperation);
|
|
479
|
+
this.exit = true;
|
|
480
|
+
this.waitingForInput = false;
|
|
481
|
+
this.pendingEof = false;
|
|
482
|
+
}
|
|
483
|
+
this.cleanupOperation(activeOperation);
|
|
150
484
|
});
|
|
151
485
|
}
|
|
152
486
|
debugCommand(command) {
|
|
@@ -156,6 +490,17 @@ class Python {
|
|
|
156
490
|
Atomics.notify(control, 0);
|
|
157
491
|
this.ondebug?.({ type: 'resume', command });
|
|
158
492
|
}
|
|
493
|
+
setBreakpoints(lines) {
|
|
494
|
+
const control = new Int32Array(this.debugBuffer);
|
|
495
|
+
const next = [...new Set(lines.filter((line) => Number.isInteger(line) && line > 0))]
|
|
496
|
+
.sort((left, right) => left - right)
|
|
497
|
+
.slice(0, Math.max(0, control.length - 4));
|
|
498
|
+
for (let index = 4; index < control.length; index += 1) {
|
|
499
|
+
Atomics.store(control, index, next[index - 4] || 0);
|
|
500
|
+
}
|
|
501
|
+
Atomics.store(control, 3, next.length);
|
|
502
|
+
Atomics.add(control, 2, 1);
|
|
503
|
+
}
|
|
159
504
|
async debugEvaluate(expression) {
|
|
160
505
|
if (!this.worker)
|
|
161
506
|
throw new Error('Worker not loaded');
|
|
@@ -172,9 +517,12 @@ class Python {
|
|
|
172
517
|
kill() {
|
|
173
518
|
this.terminate();
|
|
174
519
|
}
|
|
175
|
-
terminate() {
|
|
176
|
-
this.
|
|
177
|
-
|
|
520
|
+
terminate(reason = 'Process terminated') {
|
|
521
|
+
const activeOperation = this.activeOperation;
|
|
522
|
+
if (activeOperation) {
|
|
523
|
+
this.cancelOperation(activeOperation, reason);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
178
526
|
this.waitingForInput = false;
|
|
179
527
|
this.pendingEof = false;
|
|
180
528
|
this.uid += 1;
|
|
@@ -182,9 +530,7 @@ class Python {
|
|
|
182
530
|
const control = new Int32Array(this.debugBuffer);
|
|
183
531
|
Atomics.add(control, 0, 1);
|
|
184
532
|
Atomics.notify(control, 0);
|
|
185
|
-
this.
|
|
186
|
-
delete this.worker;
|
|
187
|
-
this.assetBridge = null;
|
|
533
|
+
this.workerSession.terminate(reason);
|
|
188
534
|
this.exit = true;
|
|
189
535
|
}
|
|
190
536
|
async clear() {
|
|
@@ -201,9 +547,7 @@ class Python {
|
|
|
201
547
|
debugBuffer.fill(0);
|
|
202
548
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
203
549
|
if (!this.exit) {
|
|
204
|
-
this.
|
|
205
|
-
delete this.worker;
|
|
206
|
-
this.assetBridge = null;
|
|
550
|
+
this.workerSession.terminate();
|
|
207
551
|
this.exit = true;
|
|
208
552
|
}
|
|
209
553
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface ParsedPythonPackageLock {
|
|
2
|
+
lock: Record<string, unknown>;
|
|
3
|
+
packageAssets: Set<string>;
|
|
4
|
+
}
|
|
5
|
+
export declare function parsePythonPackageLock(bytes: Uint8Array): ParsedPythonPackageLock;
|
|
6
|
+
export declare const readPythonPackageAssets: (bytes: Uint8Array) => Set<string>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ProtocolError } from '@wasm-idle/core';
|
|
2
|
+
const strictDecoder = new TextDecoder('utf-8', { fatal: true });
|
|
3
|
+
const pythonPackageAssetPattern = /^[A-Za-z0-9][A-Za-z0-9._+-]*\.(?:whl|tar|zip)$/u;
|
|
4
|
+
const MAX_PYTHON_PACKAGE_ASSETS = 4096;
|
|
5
|
+
const MAX_PYTHON_PACKAGE_ASSET_NAME_LENGTH = 1024;
|
|
6
|
+
export function parsePythonPackageLock(bytes) {
|
|
7
|
+
let lock;
|
|
8
|
+
try {
|
|
9
|
+
lock = JSON.parse(strictDecoder.decode(bytes));
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
throw new ProtocolError('Python runtime lock file is not valid UTF-8 JSON', {
|
|
13
|
+
phase: 'asset',
|
|
14
|
+
runtimeId: 'python'
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (typeof lock !== 'object' ||
|
|
18
|
+
lock === null ||
|
|
19
|
+
!('packages' in lock) ||
|
|
20
|
+
typeof lock.packages !== 'object' ||
|
|
21
|
+
lock.packages === null ||
|
|
22
|
+
Array.isArray(lock.packages)) {
|
|
23
|
+
throw new ProtocolError('Python runtime lock file has an invalid packages map', {
|
|
24
|
+
phase: 'asset',
|
|
25
|
+
runtimeId: 'python'
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const entries = Object.values(lock.packages);
|
|
29
|
+
if (entries.length > MAX_PYTHON_PACKAGE_ASSETS) {
|
|
30
|
+
throw new ProtocolError('Python runtime lock file has too many package assets', {
|
|
31
|
+
phase: 'asset',
|
|
32
|
+
runtimeId: 'python'
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const packageAssets = new Set();
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
if (typeof entry !== 'object' || entry === null || !('file_name' in entry)) {
|
|
38
|
+
throw new ProtocolError('Python runtime lock file has an invalid package entry', {
|
|
39
|
+
phase: 'asset',
|
|
40
|
+
runtimeId: 'python'
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const asset = entry.file_name;
|
|
44
|
+
if (typeof asset !== 'string' ||
|
|
45
|
+
asset.length > MAX_PYTHON_PACKAGE_ASSET_NAME_LENGTH ||
|
|
46
|
+
!pythonPackageAssetPattern.test(asset)) {
|
|
47
|
+
throw new ProtocolError('Python runtime lock file has an unsafe package asset name', {
|
|
48
|
+
phase: 'asset',
|
|
49
|
+
runtimeId: 'python'
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
packageAssets.add(asset);
|
|
53
|
+
}
|
|
54
|
+
return { lock: lock, packageAssets };
|
|
55
|
+
}
|
|
56
|
+
export const readPythonPackageAssets = (bytes) => parsePythonPackageLock(bytes).packageAssets;
|