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
|
@@ -0,0 +1,1096 @@
|
|
|
1
|
+
import { resolveBashRuntimeAssetConfig } from './assets';
|
|
2
|
+
import { BASH_WORKER_PROTOCOL_VERSION, isBashWorkerToHostMessage } from './bashWorkerProtocol';
|
|
3
|
+
import { reportWorkerProgress } from './workerProgress';
|
|
4
|
+
import { AssetTooLargeError, AssetIntegrityError, AssetNotFoundError, BusyError, CancelledError, CompileError, DEFAULT_WORKSPACE_LIMITS, DiagnosticLimitError, OutputLimitError, ProtocolError, ResourceLimitError, RuntimeConfigurationError, RuntimeExecutionError, TimeoutError, UnsupportedBrowserFeatureError, UnsupportedLanguageError, WasmIdleError, WorkerStartupError, preflightBashRuntimeAssets, resolveExecutionLimits, validateExecutionWorkspace } from '@wasm-idle/core';
|
|
5
|
+
const MAX_TIMER_DELAY_MS = 2_147_483_647;
|
|
6
|
+
const textEncoder = new TextEncoder();
|
|
7
|
+
const abortReason = (signal, phase) => signal.reason !== undefined
|
|
8
|
+
? signal.reason
|
|
9
|
+
: new DOMException(phase === 'startup' ? 'Bash runtime startup aborted' : 'Bash execution aborted', 'AbortError');
|
|
10
|
+
const createBashConfigIdentity = (preflightKey, limits) => JSON.stringify([
|
|
11
|
+
preflightKey,
|
|
12
|
+
{
|
|
13
|
+
maxAssetBytes: limits.maxAssetBytes,
|
|
14
|
+
maxWasmMemoryBytes: limits.maxWasmMemoryBytes,
|
|
15
|
+
maxWorkers: limits.maxWorkers,
|
|
16
|
+
maxThreads: limits.maxThreads
|
|
17
|
+
}
|
|
18
|
+
]);
|
|
19
|
+
class Bash {
|
|
20
|
+
output;
|
|
21
|
+
oncompilerdiagnostic;
|
|
22
|
+
webcUrl = '';
|
|
23
|
+
pendingInput = [];
|
|
24
|
+
pendingEof = false;
|
|
25
|
+
begin = 0;
|
|
26
|
+
elapse = 0;
|
|
27
|
+
uid = 0;
|
|
28
|
+
exit = true;
|
|
29
|
+
activeOperation = null;
|
|
30
|
+
readyWorker = null;
|
|
31
|
+
loadedConfig = null;
|
|
32
|
+
requestUid = 0;
|
|
33
|
+
sessionUid = 0;
|
|
34
|
+
disposed = false;
|
|
35
|
+
disposePromise = null;
|
|
36
|
+
disposeCancellation = new CancelledError('Bash sandbox disposed', {
|
|
37
|
+
phase: 'dispose',
|
|
38
|
+
runtimeId: 'BASH',
|
|
39
|
+
recoverable: false
|
|
40
|
+
});
|
|
41
|
+
load(runtimeAssets = '', _code = '', log = true, _args = [], options = {}, progress) {
|
|
42
|
+
if (this.disposed) {
|
|
43
|
+
return Promise.reject(new RuntimeConfigurationError('Bash sandbox is disposed', {
|
|
44
|
+
phase: 'dispose',
|
|
45
|
+
runtimeId: 'BASH'
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
if (this.activeOperation) {
|
|
49
|
+
return Promise.reject(new BusyError('Bash runtime already has an active operation', {
|
|
50
|
+
phase: this.activeOperation.stage,
|
|
51
|
+
runtimeId: 'BASH'
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
let resolvePromise;
|
|
55
|
+
let rejectPromise;
|
|
56
|
+
const promise = new Promise((resolve, reject) => {
|
|
57
|
+
resolvePromise = resolve;
|
|
58
|
+
rejectPromise = reject;
|
|
59
|
+
});
|
|
60
|
+
const operation = {
|
|
61
|
+
config: null,
|
|
62
|
+
decoders: { stderr: new TextDecoder(), stdout: new TextDecoder() },
|
|
63
|
+
handle: null,
|
|
64
|
+
kind: 'load',
|
|
65
|
+
outputBytes: 0,
|
|
66
|
+
progress,
|
|
67
|
+
executionReady: false,
|
|
68
|
+
reject: rejectPromise,
|
|
69
|
+
requestId: 0,
|
|
70
|
+
resolve: () => resolvePromise(),
|
|
71
|
+
settled: false,
|
|
72
|
+
started: false,
|
|
73
|
+
stage: 'startup',
|
|
74
|
+
stdinReady: false,
|
|
75
|
+
token: Symbol('bash-load')
|
|
76
|
+
};
|
|
77
|
+
this.activeOperation = operation;
|
|
78
|
+
try {
|
|
79
|
+
const signal = options.signal;
|
|
80
|
+
this.requireActive(operation);
|
|
81
|
+
if (signal?.aborted)
|
|
82
|
+
throw abortReason(signal, 'startup');
|
|
83
|
+
const limits = resolveExecutionLimits(options.limits);
|
|
84
|
+
this.requireActive(operation);
|
|
85
|
+
const currentUrl = typeof window !== 'undefined' ? window.location.href : '';
|
|
86
|
+
const resolved = resolveBashRuntimeAssetConfig(runtimeAssets, currentUrl);
|
|
87
|
+
this.requireActive(operation);
|
|
88
|
+
const config = {
|
|
89
|
+
...resolved,
|
|
90
|
+
identity: createBashConfigIdentity(resolved.preflightKey, limits),
|
|
91
|
+
limits
|
|
92
|
+
};
|
|
93
|
+
operation.config = config;
|
|
94
|
+
operation.signal = signal;
|
|
95
|
+
this.bindAbort(operation);
|
|
96
|
+
this.requireActive(operation);
|
|
97
|
+
if (this.readyWorker?.ready && this.readyWorker.identity === config.identity) {
|
|
98
|
+
progress?.set?.(1, 'Bash runtime ready');
|
|
99
|
+
this.requireActive(operation);
|
|
100
|
+
this.loadedConfig = config;
|
|
101
|
+
this.webcUrl = config.webcUrl;
|
|
102
|
+
this.finishOperation(operation);
|
|
103
|
+
return promise;
|
|
104
|
+
}
|
|
105
|
+
this.bindTimeout(operation, Math.min(MAX_TIMER_DELAY_MS, limits.assetTimeoutMs + limits.startupTimeoutMs));
|
|
106
|
+
this.requireActive(operation);
|
|
107
|
+
void this.createWorker(operation)
|
|
108
|
+
.then((handle) => {
|
|
109
|
+
if (!this.isActive(operation)) {
|
|
110
|
+
this.retireWorker(handle);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.dispatchLoad(operation, handle, log);
|
|
114
|
+
})
|
|
115
|
+
.catch(() => undefined);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
this.failOperation(operation, error, false);
|
|
119
|
+
}
|
|
120
|
+
return promise;
|
|
121
|
+
}
|
|
122
|
+
run(code, prepare, log = true, progress, args = [], options = {}) {
|
|
123
|
+
if (this.disposed) {
|
|
124
|
+
return Promise.reject(new RuntimeConfigurationError('Bash sandbox is disposed', {
|
|
125
|
+
phase: 'dispose',
|
|
126
|
+
runtimeId: 'BASH'
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
if (this.activeOperation) {
|
|
130
|
+
return Promise.reject(new BusyError('Bash runtime already has an active operation', {
|
|
131
|
+
phase: this.activeOperation.stage,
|
|
132
|
+
runtimeId: 'BASH'
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
if (prepare)
|
|
136
|
+
return Promise.resolve(true);
|
|
137
|
+
if (!this.loadedConfig)
|
|
138
|
+
return Promise.reject(new Error('Bash runtime is not loaded'));
|
|
139
|
+
let resolvePromise;
|
|
140
|
+
let rejectPromise;
|
|
141
|
+
const promise = new Promise((resolve, reject) => {
|
|
142
|
+
resolvePromise = resolve;
|
|
143
|
+
rejectPromise = reject;
|
|
144
|
+
});
|
|
145
|
+
const operation = {
|
|
146
|
+
config: this.loadedConfig,
|
|
147
|
+
decoders: { stderr: new TextDecoder(), stdout: new TextDecoder() },
|
|
148
|
+
handle: null,
|
|
149
|
+
kind: 'run',
|
|
150
|
+
outputBytes: 0,
|
|
151
|
+
progress,
|
|
152
|
+
executionReady: false,
|
|
153
|
+
reject: rejectPromise,
|
|
154
|
+
requestId: 0,
|
|
155
|
+
resolve: (value) => resolvePromise(value),
|
|
156
|
+
settled: false,
|
|
157
|
+
started: false,
|
|
158
|
+
stage: this.readyWorker ? 'execute' : 'startup',
|
|
159
|
+
stdinReady: false,
|
|
160
|
+
token: Symbol('bash-run')
|
|
161
|
+
};
|
|
162
|
+
this.activeOperation = operation;
|
|
163
|
+
try {
|
|
164
|
+
const signal = options.signal;
|
|
165
|
+
this.requireActive(operation);
|
|
166
|
+
if (signal?.aborted)
|
|
167
|
+
throw abortReason(signal, operation.stage);
|
|
168
|
+
const limits = resolveExecutionLimits(options.limits);
|
|
169
|
+
this.requireActive(operation);
|
|
170
|
+
if (!this.readyWorker) {
|
|
171
|
+
const loadedConfig = this.requireConfig(operation);
|
|
172
|
+
const startupLimits = {
|
|
173
|
+
...limits,
|
|
174
|
+
assetTimeoutMs: Math.min(loadedConfig.limits.assetTimeoutMs, limits.assetTimeoutMs),
|
|
175
|
+
maxAssetBytes: Math.min(loadedConfig.limits.maxAssetBytes, limits.maxAssetBytes),
|
|
176
|
+
maxThreads: Math.min(loadedConfig.limits.maxThreads, limits.maxThreads),
|
|
177
|
+
maxWasmMemoryBytes: Math.min(loadedConfig.limits.maxWasmMemoryBytes, limits.maxWasmMemoryBytes),
|
|
178
|
+
maxWorkers: Math.min(loadedConfig.limits.maxWorkers, limits.maxWorkers),
|
|
179
|
+
startupTimeoutMs: Math.min(loadedConfig.limits.startupTimeoutMs, limits.startupTimeoutMs)
|
|
180
|
+
};
|
|
181
|
+
operation.config = {
|
|
182
|
+
...loadedConfig,
|
|
183
|
+
identity: createBashConfigIdentity(loadedConfig.preflightKey, startupLimits),
|
|
184
|
+
limits: startupLimits
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const programArgsSource = options.programArgs ?? args;
|
|
188
|
+
if (!Array.isArray(programArgsSource)) {
|
|
189
|
+
throw new TypeError('Bash program arguments must be an array');
|
|
190
|
+
}
|
|
191
|
+
const programArgs = [...programArgsSource];
|
|
192
|
+
const workspaceFilesSource = options.workspaceFiles ?? [];
|
|
193
|
+
if (!Array.isArray(workspaceFilesSource)) {
|
|
194
|
+
throw new TypeError('Bash workspace files must be an array');
|
|
195
|
+
}
|
|
196
|
+
const workspaceFiles = workspaceFilesSource.map((file) => ({
|
|
197
|
+
path: file.path,
|
|
198
|
+
content: file.content
|
|
199
|
+
}));
|
|
200
|
+
const activePath = options.activePath ?? 'main.sh';
|
|
201
|
+
const workspaceLimitSource = options.workspaceLimits ?? {};
|
|
202
|
+
const workspaceLimits = {
|
|
203
|
+
maxFiles: workspaceLimitSource.maxFiles ?? DEFAULT_WORKSPACE_LIMITS.maxFiles,
|
|
204
|
+
maxFileBytes: Math.min(workspaceLimitSource.maxFileBytes ?? DEFAULT_WORKSPACE_LIMITS.maxFileBytes, limits.maxWorkspaceBytes),
|
|
205
|
+
maxTotalBytes: Math.min(workspaceLimitSource.maxTotalBytes ?? DEFAULT_WORKSPACE_LIMITS.maxTotalBytes, limits.maxWorkspaceBytes),
|
|
206
|
+
maxPathBytes: workspaceLimitSource.maxPathBytes ?? DEFAULT_WORKSPACE_LIMITS.maxPathBytes,
|
|
207
|
+
caseSensitive: workspaceLimitSource.caseSensitive ?? DEFAULT_WORKSPACE_LIMITS.caseSensitive
|
|
208
|
+
};
|
|
209
|
+
const workspace = validateExecutionWorkspace(code, workspaceFiles, activePath, workspaceLimits);
|
|
210
|
+
this.requireActive(operation);
|
|
211
|
+
const stdin = options.stdin;
|
|
212
|
+
this.requireActive(operation);
|
|
213
|
+
operation.signal = signal;
|
|
214
|
+
operation.runRequest = {
|
|
215
|
+
activePath: workspace.activePath ?? 'main.sh',
|
|
216
|
+
code,
|
|
217
|
+
limits,
|
|
218
|
+
log,
|
|
219
|
+
programArgs,
|
|
220
|
+
stdin,
|
|
221
|
+
workspaceFiles: workspace.workspaceFiles,
|
|
222
|
+
workspaceLimits
|
|
223
|
+
};
|
|
224
|
+
this.bindAbort(operation);
|
|
225
|
+
this.requireActive(operation);
|
|
226
|
+
const needsStartup = !this.readyWorker;
|
|
227
|
+
const startupConfig = this.requireConfig(operation);
|
|
228
|
+
const timeoutMs = Math.min(MAX_TIMER_DELAY_MS, limits.compileTimeoutMs +
|
|
229
|
+
limits.runTimeoutMs +
|
|
230
|
+
(needsStartup
|
|
231
|
+
? startupConfig.limits.assetTimeoutMs +
|
|
232
|
+
startupConfig.limits.startupTimeoutMs
|
|
233
|
+
: 0));
|
|
234
|
+
this.bindTimeout(operation, timeoutMs);
|
|
235
|
+
this.requireActive(operation);
|
|
236
|
+
operation.started = true;
|
|
237
|
+
this.begin = Date.now();
|
|
238
|
+
this.exit = false;
|
|
239
|
+
if (stdin !== undefined) {
|
|
240
|
+
this.pendingInput = [];
|
|
241
|
+
this.pendingEof = false;
|
|
242
|
+
}
|
|
243
|
+
if (this.readyWorker) {
|
|
244
|
+
operation.handle = this.readyWorker;
|
|
245
|
+
operation.stage = 'execute';
|
|
246
|
+
this.dispatchRun(operation, this.readyWorker);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
void this.createWorker(operation)
|
|
250
|
+
.then((handle) => {
|
|
251
|
+
if (!this.isActive(operation)) {
|
|
252
|
+
this.retireWorker(handle);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
this.dispatchLoad(operation, handle, false);
|
|
256
|
+
})
|
|
257
|
+
.catch(() => undefined);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
this.failOperation(operation, error, false);
|
|
262
|
+
}
|
|
263
|
+
return promise;
|
|
264
|
+
}
|
|
265
|
+
write(input) {
|
|
266
|
+
if (this.disposed)
|
|
267
|
+
return;
|
|
268
|
+
this.pendingInput.push(input);
|
|
269
|
+
this.pendingEof = false;
|
|
270
|
+
const operation = this.activeOperation;
|
|
271
|
+
if (operation?.kind === 'run' && operation.stdinReady)
|
|
272
|
+
this.flushStdin(operation);
|
|
273
|
+
}
|
|
274
|
+
eof() {
|
|
275
|
+
if (this.disposed)
|
|
276
|
+
return;
|
|
277
|
+
this.pendingEof = true;
|
|
278
|
+
const operation = this.activeOperation;
|
|
279
|
+
if (operation?.kind === 'run' && operation.stdinReady)
|
|
280
|
+
this.flushStdin(operation);
|
|
281
|
+
}
|
|
282
|
+
kill() {
|
|
283
|
+
this.terminate();
|
|
284
|
+
}
|
|
285
|
+
terminate(reason = 'Process terminated') {
|
|
286
|
+
if (this.disposed)
|
|
287
|
+
return;
|
|
288
|
+
const operation = this.activeOperation;
|
|
289
|
+
if (operation) {
|
|
290
|
+
this.failOperation(operation, reason, true);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const readyWorker = this.readyWorker;
|
|
294
|
+
if (readyWorker)
|
|
295
|
+
this.retireWorker(readyWorker);
|
|
296
|
+
this.pendingInput = [];
|
|
297
|
+
this.pendingEof = false;
|
|
298
|
+
this.exit = true;
|
|
299
|
+
}
|
|
300
|
+
async clear() {
|
|
301
|
+
if (this.disposed)
|
|
302
|
+
return;
|
|
303
|
+
this.terminate();
|
|
304
|
+
const readyWorker = this.readyWorker;
|
|
305
|
+
if (readyWorker)
|
|
306
|
+
this.retireWorker(readyWorker);
|
|
307
|
+
this.pendingInput = [];
|
|
308
|
+
this.pendingEof = false;
|
|
309
|
+
this.loadedConfig = null;
|
|
310
|
+
this.webcUrl = '';
|
|
311
|
+
}
|
|
312
|
+
dispose() {
|
|
313
|
+
if (this.disposePromise)
|
|
314
|
+
return this.disposePromise;
|
|
315
|
+
this.disposed = true;
|
|
316
|
+
this.disposePromise = Promise.resolve();
|
|
317
|
+
const operation = this.activeOperation;
|
|
318
|
+
const readyWorker = this.readyWorker;
|
|
319
|
+
this.readyWorker = null;
|
|
320
|
+
this.loadedConfig = null;
|
|
321
|
+
this.webcUrl = '';
|
|
322
|
+
this.output = undefined;
|
|
323
|
+
this.oncompilerdiagnostic = undefined;
|
|
324
|
+
this.pendingInput = [];
|
|
325
|
+
this.pendingEof = false;
|
|
326
|
+
if (operation)
|
|
327
|
+
this.failOperation(operation, this.disposeCancellation, true);
|
|
328
|
+
if (readyWorker)
|
|
329
|
+
this.retireWorker(readyWorker);
|
|
330
|
+
this.exit = true;
|
|
331
|
+
return this.disposePromise;
|
|
332
|
+
}
|
|
333
|
+
isActive(operation) {
|
|
334
|
+
return this.activeOperation?.token === operation.token && !operation.settled;
|
|
335
|
+
}
|
|
336
|
+
requireActive(operation) {
|
|
337
|
+
if (!this.isActive(operation))
|
|
338
|
+
throw new Error('Bash operation was superseded');
|
|
339
|
+
}
|
|
340
|
+
requireConfig(operation) {
|
|
341
|
+
if (!operation.config) {
|
|
342
|
+
throw new RuntimeConfigurationError('Bash operation has no runtime configuration', {
|
|
343
|
+
phase: 'startup',
|
|
344
|
+
runtimeId: 'BASH'
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
return operation.config;
|
|
348
|
+
}
|
|
349
|
+
retireDelivery(operation) {
|
|
350
|
+
const delivery = operation.delivery;
|
|
351
|
+
if (!delivery || delivery.state === 'retired')
|
|
352
|
+
return;
|
|
353
|
+
delivery.state = 'retired';
|
|
354
|
+
delivery.payload = null;
|
|
355
|
+
delivery.transferables.length = 0;
|
|
356
|
+
operation.delivery = undefined;
|
|
357
|
+
}
|
|
358
|
+
bindAbort(operation) {
|
|
359
|
+
const signal = operation.signal;
|
|
360
|
+
if (!signal)
|
|
361
|
+
return;
|
|
362
|
+
const onAbort = () => {
|
|
363
|
+
if (!this.isActive(operation))
|
|
364
|
+
return;
|
|
365
|
+
let reason;
|
|
366
|
+
try {
|
|
367
|
+
reason = abortReason(signal, operation.stage);
|
|
368
|
+
}
|
|
369
|
+
catch (error) {
|
|
370
|
+
reason = error;
|
|
371
|
+
}
|
|
372
|
+
if (this.isActive(operation))
|
|
373
|
+
this.failOperation(operation, reason, true);
|
|
374
|
+
};
|
|
375
|
+
operation.onAbort = onAbort;
|
|
376
|
+
try {
|
|
377
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
378
|
+
if (signal.aborted)
|
|
379
|
+
onAbort();
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
if (this.isActive(operation))
|
|
383
|
+
this.failOperation(operation, error, true);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
bindTimeout(operation, timeoutMs) {
|
|
387
|
+
try {
|
|
388
|
+
operation.timeout = setTimeout(() => {
|
|
389
|
+
if (!this.isActive(operation))
|
|
390
|
+
return;
|
|
391
|
+
const phase = operation.stage === 'startup' ? 'startup' : 'execute';
|
|
392
|
+
this.failOperation(operation, new TimeoutError(`Bash ${operation.stage} timed out after ${timeoutMs} ms`, {
|
|
393
|
+
phase,
|
|
394
|
+
runtimeId: 'BASH',
|
|
395
|
+
timeoutMs
|
|
396
|
+
}), true);
|
|
397
|
+
}, timeoutMs);
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
this.failOperation(operation, error, false);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
cleanupOperation(operation) {
|
|
404
|
+
if (operation.timeout !== undefined) {
|
|
405
|
+
try {
|
|
406
|
+
clearTimeout(operation.timeout);
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
// Timer cleanup must not replace the operation result.
|
|
410
|
+
}
|
|
411
|
+
operation.timeout = undefined;
|
|
412
|
+
}
|
|
413
|
+
if (operation.signal && operation.onAbort) {
|
|
414
|
+
try {
|
|
415
|
+
operation.signal.removeEventListener('abort', operation.onAbort);
|
|
416
|
+
}
|
|
417
|
+
catch {
|
|
418
|
+
// Listener cleanup must not replace the operation result.
|
|
419
|
+
}
|
|
420
|
+
operation.onAbort = undefined;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
finishOperation(operation, value) {
|
|
424
|
+
if (!this.isActive(operation))
|
|
425
|
+
return;
|
|
426
|
+
operation.settled = true;
|
|
427
|
+
this.activeOperation = null;
|
|
428
|
+
this.cleanupOperation(operation);
|
|
429
|
+
operation.preflightController = undefined;
|
|
430
|
+
this.retireDelivery(operation);
|
|
431
|
+
if (operation.kind === 'run') {
|
|
432
|
+
if (operation.runRequest?.stdin !== undefined) {
|
|
433
|
+
this.pendingInput = [];
|
|
434
|
+
this.pendingEof = false;
|
|
435
|
+
}
|
|
436
|
+
this.elapse = Date.now() - this.begin;
|
|
437
|
+
this.exit = true;
|
|
438
|
+
}
|
|
439
|
+
operation.resolve(value);
|
|
440
|
+
}
|
|
441
|
+
failOperation(operation, reason, retireHandle) {
|
|
442
|
+
if (!this.isActive(operation))
|
|
443
|
+
return;
|
|
444
|
+
operation.settled = true;
|
|
445
|
+
this.activeOperation = null;
|
|
446
|
+
this.cleanupOperation(operation);
|
|
447
|
+
try {
|
|
448
|
+
operation.preflightController?.abort(reason);
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
// Preserve the original failure.
|
|
452
|
+
}
|
|
453
|
+
operation.preflightController = undefined;
|
|
454
|
+
this.retireDelivery(operation);
|
|
455
|
+
if (retireHandle && operation.handle)
|
|
456
|
+
this.retireWorker(operation.handle);
|
|
457
|
+
if (operation.kind === 'run' && operation.started) {
|
|
458
|
+
this.pendingInput = [];
|
|
459
|
+
this.pendingEof = false;
|
|
460
|
+
this.elapse = Date.now() - this.begin;
|
|
461
|
+
this.exit = true;
|
|
462
|
+
}
|
|
463
|
+
operation.reject(reason);
|
|
464
|
+
}
|
|
465
|
+
async createWorker(operation) {
|
|
466
|
+
const config = this.requireConfig(operation);
|
|
467
|
+
const preflightController = new AbortController();
|
|
468
|
+
operation.preflightController = preflightController;
|
|
469
|
+
const loadedByAsset = new Map();
|
|
470
|
+
const deliveryTotal = config.preflightProfile.manifestReceipt.bytes +
|
|
471
|
+
config.preflightProfile.sdkJavaScriptReceipt.bytes +
|
|
472
|
+
config.preflightProfile.wasmerWasmReceipt.bytes +
|
|
473
|
+
config.preflightProfile.webcReceipt.bytes;
|
|
474
|
+
let payload = null;
|
|
475
|
+
try {
|
|
476
|
+
payload = await preflightBashRuntimeAssets({
|
|
477
|
+
baseUrl: config.baseUrl,
|
|
478
|
+
manifestUrl: config.manifestUrl,
|
|
479
|
+
sdkJavaScriptUrl: config.moduleUrl,
|
|
480
|
+
wasmerWasmUrl: config.wasmerWasmUrl,
|
|
481
|
+
webcUrl: config.webcUrl,
|
|
482
|
+
profile: config.preflightProfile,
|
|
483
|
+
limits: config.limits,
|
|
484
|
+
signal: preflightController.signal,
|
|
485
|
+
reportProgress: ({ assetKey, loadedBytes }) => {
|
|
486
|
+
loadedByAsset.set(assetKey, loadedBytes);
|
|
487
|
+
let totalLoaded = 0;
|
|
488
|
+
for (const loaded of loadedByAsset.values())
|
|
489
|
+
totalLoaded += loaded;
|
|
490
|
+
operation.progress?.set?.(Math.min(0.75, (totalLoaded / deliveryTotal) * 0.75), `Verifying Bash ${assetKey}`);
|
|
491
|
+
},
|
|
492
|
+
reportDecompressionProgress: (asset, loadedBytes, totalBytes) => {
|
|
493
|
+
operation.progress?.set?.(0.75 + Math.min(0.2, (loadedBytes / totalBytes) * 0.2), `Decompressing Bash ${asset}`);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
catch (error) {
|
|
498
|
+
this.failOperation(operation, error, false);
|
|
499
|
+
throw error;
|
|
500
|
+
}
|
|
501
|
+
finally {
|
|
502
|
+
operation.preflightController = undefined;
|
|
503
|
+
}
|
|
504
|
+
if (!this.isActive(operation)) {
|
|
505
|
+
payload = null;
|
|
506
|
+
throw new Error('Bash operation was cancelled');
|
|
507
|
+
}
|
|
508
|
+
let WorkerConstructor;
|
|
509
|
+
try {
|
|
510
|
+
WorkerConstructor = (await import('./worker/bash?worker')).default;
|
|
511
|
+
}
|
|
512
|
+
catch (cause) {
|
|
513
|
+
const error = new WorkerStartupError('Failed to load the Bash outer worker module', {
|
|
514
|
+
cause,
|
|
515
|
+
runtimeId: 'BASH'
|
|
516
|
+
});
|
|
517
|
+
this.failOperation(operation, error, false);
|
|
518
|
+
payload = null;
|
|
519
|
+
throw error;
|
|
520
|
+
}
|
|
521
|
+
if (!this.isActive(operation)) {
|
|
522
|
+
payload = null;
|
|
523
|
+
throw new Error('Bash operation was cancelled');
|
|
524
|
+
}
|
|
525
|
+
let worker;
|
|
526
|
+
try {
|
|
527
|
+
worker = new WorkerConstructor();
|
|
528
|
+
}
|
|
529
|
+
catch (cause) {
|
|
530
|
+
const error = new WorkerStartupError('Failed to start the Bash outer worker', {
|
|
531
|
+
cause,
|
|
532
|
+
runtimeId: 'BASH'
|
|
533
|
+
});
|
|
534
|
+
this.failOperation(operation, error, false);
|
|
535
|
+
payload = null;
|
|
536
|
+
throw error;
|
|
537
|
+
}
|
|
538
|
+
const sessionId = ++this.sessionUid;
|
|
539
|
+
if (!Object.isFrozen(payload)) {
|
|
540
|
+
try {
|
|
541
|
+
worker.terminate();
|
|
542
|
+
}
|
|
543
|
+
catch {
|
|
544
|
+
// Preserve the ownership contract failure.
|
|
545
|
+
}
|
|
546
|
+
const error = new ProtocolError('Bash preflight payload must be frozen', {
|
|
547
|
+
runtimeId: 'BASH'
|
|
548
|
+
});
|
|
549
|
+
this.failOperation(operation, error, false);
|
|
550
|
+
payload = null;
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
const transferables = [];
|
|
554
|
+
const uniqueBuffers = new Set();
|
|
555
|
+
for (const bytes of [
|
|
556
|
+
payload.manifestBytes,
|
|
557
|
+
payload.sdkJavaScriptBytes,
|
|
558
|
+
payload.wasmerWasmBytes,
|
|
559
|
+
payload.webcBytes
|
|
560
|
+
]) {
|
|
561
|
+
const buffer = bytes.buffer;
|
|
562
|
+
if (bytes.byteLength <= 0 ||
|
|
563
|
+
bytes.byteOffset !== 0 ||
|
|
564
|
+
bytes.byteLength !== buffer.byteLength ||
|
|
565
|
+
Object.prototype.toString.call(buffer) !== '[object ArrayBuffer]' ||
|
|
566
|
+
(typeof SharedArrayBuffer === 'function' && buffer instanceof SharedArrayBuffer) ||
|
|
567
|
+
uniqueBuffers.has(buffer)) {
|
|
568
|
+
try {
|
|
569
|
+
worker.terminate();
|
|
570
|
+
}
|
|
571
|
+
catch {
|
|
572
|
+
// Preserve the ownership contract failure.
|
|
573
|
+
}
|
|
574
|
+
const error = new ProtocolError('Bash preflight payload must own four unique whole ArrayBuffers', { runtimeId: 'BASH' });
|
|
575
|
+
this.failOperation(operation, error, false);
|
|
576
|
+
payload = null;
|
|
577
|
+
throw error;
|
|
578
|
+
}
|
|
579
|
+
uniqueBuffers.add(buffer);
|
|
580
|
+
transferables.push(buffer);
|
|
581
|
+
}
|
|
582
|
+
const handle = {
|
|
583
|
+
identity: config.identity,
|
|
584
|
+
ready: false,
|
|
585
|
+
retired: false,
|
|
586
|
+
sessionId,
|
|
587
|
+
worker
|
|
588
|
+
};
|
|
589
|
+
operation.handle = handle;
|
|
590
|
+
operation.delivery = {
|
|
591
|
+
identity: config.identity,
|
|
592
|
+
payload,
|
|
593
|
+
sessionId,
|
|
594
|
+
state: 'available',
|
|
595
|
+
transferables
|
|
596
|
+
};
|
|
597
|
+
payload = null;
|
|
598
|
+
worker.onmessage = (event) => {
|
|
599
|
+
this.handleWorkerMessage(handle, event.data);
|
|
600
|
+
};
|
|
601
|
+
worker.onerror = (event) => {
|
|
602
|
+
this.handleWorkerFailure(handle, event);
|
|
603
|
+
};
|
|
604
|
+
worker.onmessageerror = (event) => {
|
|
605
|
+
this.handleWorkerProtocolFailure(handle, event);
|
|
606
|
+
};
|
|
607
|
+
return handle;
|
|
608
|
+
}
|
|
609
|
+
dispatchLoad(operation, handle, log) {
|
|
610
|
+
if (!this.isActive(operation) || operation.handle !== handle)
|
|
611
|
+
return;
|
|
612
|
+
const config = this.requireConfig(operation);
|
|
613
|
+
const delivery = operation.delivery;
|
|
614
|
+
if (!delivery ||
|
|
615
|
+
delivery.state !== 'available' ||
|
|
616
|
+
delivery.identity !== config.identity ||
|
|
617
|
+
delivery.sessionId !== handle.sessionId ||
|
|
618
|
+
!delivery.payload ||
|
|
619
|
+
delivery.transferables.length !== 4) {
|
|
620
|
+
this.failOperation(operation, new ProtocolError('Bash preflight delivery is unavailable or stale', {
|
|
621
|
+
runtimeId: 'BASH'
|
|
622
|
+
}), true);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
operation.stage = 'startup';
|
|
626
|
+
operation.requestId = ++this.requestUid;
|
|
627
|
+
const runtimePreflight = delivery.payload;
|
|
628
|
+
const transferables = delivery.transferables.splice(0);
|
|
629
|
+
delivery.payload = null;
|
|
630
|
+
delivery.state = 'consumed';
|
|
631
|
+
const message = {
|
|
632
|
+
type: 'load',
|
|
633
|
+
protocolVersion: BASH_WORKER_PROTOCOL_VERSION,
|
|
634
|
+
sessionId: handle.sessionId,
|
|
635
|
+
requestId: operation.requestId,
|
|
636
|
+
runtimePreflight,
|
|
637
|
+
limits: config.limits,
|
|
638
|
+
log
|
|
639
|
+
};
|
|
640
|
+
try {
|
|
641
|
+
this.postMessage(operation, handle, message, transferables);
|
|
642
|
+
}
|
|
643
|
+
finally {
|
|
644
|
+
this.retireDelivery(operation);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
dispatchRun(operation, handle) {
|
|
648
|
+
const request = operation.runRequest;
|
|
649
|
+
if (!request || !this.isActive(operation) || operation.handle !== handle)
|
|
650
|
+
return;
|
|
651
|
+
operation.stage = 'execute';
|
|
652
|
+
operation.requestId = ++this.requestUid;
|
|
653
|
+
const message = {
|
|
654
|
+
type: 'run',
|
|
655
|
+
protocolVersion: BASH_WORKER_PROTOCOL_VERSION,
|
|
656
|
+
sessionId: handle.sessionId,
|
|
657
|
+
requestId: operation.requestId,
|
|
658
|
+
code: request.code,
|
|
659
|
+
activePath: request.activePath,
|
|
660
|
+
workspaceFiles: request.workspaceFiles,
|
|
661
|
+
programArgs: request.programArgs,
|
|
662
|
+
stdin: request.stdin,
|
|
663
|
+
limits: request.limits,
|
|
664
|
+
workspaceLimits: request.workspaceLimits,
|
|
665
|
+
log: request.log
|
|
666
|
+
};
|
|
667
|
+
this.postMessage(operation, handle, message);
|
|
668
|
+
}
|
|
669
|
+
postMessage(operation, handle, message, transfer = []) {
|
|
670
|
+
if (!this.isActive(operation) || operation.handle !== handle)
|
|
671
|
+
return;
|
|
672
|
+
try {
|
|
673
|
+
handle.worker.postMessage(message, transfer);
|
|
674
|
+
}
|
|
675
|
+
catch (cause) {
|
|
676
|
+
this.failOperation(operation, new ProtocolError(`Failed to send Bash worker ${message.type} message`, {
|
|
677
|
+
cause,
|
|
678
|
+
runtimeId: 'BASH'
|
|
679
|
+
}), true);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
handleWorkerMessage(handle, message) {
|
|
683
|
+
const operation = this.activeOperation;
|
|
684
|
+
if (!operation || operation.handle !== handle || handle.retired)
|
|
685
|
+
return;
|
|
686
|
+
if (!message || typeof message !== 'object') {
|
|
687
|
+
this.failProtocol(operation, 'Bash worker returned a non-object message', message);
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const envelope = message;
|
|
691
|
+
if (envelope.protocolVersion !== BASH_WORKER_PROTOCOL_VERSION) {
|
|
692
|
+
this.failProtocol(operation, `Unsupported Bash worker protocol version: ${String(envelope.protocolVersion)}`, message);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
if (!Number.isSafeInteger(envelope.sessionId) ||
|
|
696
|
+
envelope.sessionId <= 0 ||
|
|
697
|
+
!Number.isSafeInteger(envelope.requestId) ||
|
|
698
|
+
envelope.requestId <= 0) {
|
|
699
|
+
this.failProtocol(operation, 'Bash worker returned an invalid request identity', message);
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (envelope.sessionId !== handle.sessionId) {
|
|
703
|
+
this.failProtocol(operation, 'Bash worker returned an unexpected session identity', message);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
if (operation.requestId === 0) {
|
|
707
|
+
this.failProtocol(operation, 'Bash worker responded before request dispatch', message);
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
if (envelope.requestId < operation.requestId)
|
|
711
|
+
return;
|
|
712
|
+
if (envelope.requestId !== operation.requestId) {
|
|
713
|
+
this.failProtocol(operation, 'Bash worker returned a future request identity', message);
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
if (!isBashWorkerToHostMessage(message)) {
|
|
717
|
+
this.failProtocol(operation, 'Bash worker returned an invalid message', message);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
switch (message.type) {
|
|
721
|
+
case 'progress':
|
|
722
|
+
try {
|
|
723
|
+
operation.progress?.set?.(message.value, message.stage);
|
|
724
|
+
}
|
|
725
|
+
catch (error) {
|
|
726
|
+
this.failOperation(operation, error, true);
|
|
727
|
+
}
|
|
728
|
+
return;
|
|
729
|
+
case 'loaded': {
|
|
730
|
+
if (operation.stage !== 'startup') {
|
|
731
|
+
this.failProtocol(operation, 'Bash worker loaded outside startup', message);
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
if (operation.kind === 'run') {
|
|
735
|
+
handle.ready = true;
|
|
736
|
+
this.readyWorker = handle;
|
|
737
|
+
this.dispatchRun(operation, handle);
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
try {
|
|
741
|
+
operation.progress?.set?.(1, 'Bash runtime ready');
|
|
742
|
+
}
|
|
743
|
+
catch (error) {
|
|
744
|
+
this.failOperation(operation, error, true);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
if (!this.isActive(operation))
|
|
748
|
+
return;
|
|
749
|
+
const config = this.requireConfig(operation);
|
|
750
|
+
const previousWorker = this.readyWorker;
|
|
751
|
+
handle.ready = true;
|
|
752
|
+
this.readyWorker = handle;
|
|
753
|
+
this.loadedConfig = config;
|
|
754
|
+
this.webcUrl = config.webcUrl;
|
|
755
|
+
this.finishOperation(operation);
|
|
756
|
+
if (previousWorker && previousWorker !== handle)
|
|
757
|
+
this.retireWorker(previousWorker);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
case 'execution-ready':
|
|
761
|
+
if (operation.kind !== 'run' || operation.stage !== 'execute') {
|
|
762
|
+
this.failProtocol(operation, 'Bash worker reported execution readiness outside execution', message);
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
if (operation.executionReady)
|
|
766
|
+
return;
|
|
767
|
+
operation.executionReady = true;
|
|
768
|
+
try {
|
|
769
|
+
reportWorkerProgress(operation.progress, message.progress);
|
|
770
|
+
}
|
|
771
|
+
catch (error) {
|
|
772
|
+
this.failOperation(operation, error, true);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
return;
|
|
776
|
+
case 'stdin-ready':
|
|
777
|
+
if (operation.kind !== 'run' || operation.stage !== 'execute') {
|
|
778
|
+
this.failProtocol(operation, 'Bash worker requested stdin outside execution', message);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
if (!operation.executionReady) {
|
|
782
|
+
operation.executionReady = true;
|
|
783
|
+
try {
|
|
784
|
+
reportWorkerProgress(operation.progress, {
|
|
785
|
+
kind: 'ready',
|
|
786
|
+
state: 'waiting-input',
|
|
787
|
+
reason: 'stdin-request',
|
|
788
|
+
label: 'Bash process is ready for input'
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
catch (error) {
|
|
792
|
+
this.failOperation(operation, error, true);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (!this.isActive(operation))
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
operation.stdinReady = true;
|
|
799
|
+
this.flushStdin(operation);
|
|
800
|
+
return;
|
|
801
|
+
case 'output':
|
|
802
|
+
this.handleOutput(operation, message.stream, message.bytes);
|
|
803
|
+
return;
|
|
804
|
+
case 'result':
|
|
805
|
+
if (operation.kind !== 'run' || operation.stage !== 'execute') {
|
|
806
|
+
this.failProtocol(operation, 'Bash worker returned a result outside execution', message);
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
this.flushDecodedOutput(operation);
|
|
810
|
+
if (this.isActive(operation))
|
|
811
|
+
this.finishOperation(operation, message.result);
|
|
812
|
+
return;
|
|
813
|
+
case 'error':
|
|
814
|
+
this.failOperation(operation, this.deserializeWorkerError(message.error, message.phase), true);
|
|
815
|
+
return;
|
|
816
|
+
default:
|
|
817
|
+
this.failProtocol(operation, 'Bash worker returned an unknown message', message);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
handleOutput(operation, stream, bytes) {
|
|
821
|
+
if (operation.kind !== 'run' || operation.stage !== 'execute') {
|
|
822
|
+
this.failProtocol(operation, 'Bash worker emitted output outside execution', bytes);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
if (!ArrayBuffer.isView(bytes) ||
|
|
826
|
+
Object.prototype.toString.call(bytes) !== '[object Uint8Array]') {
|
|
827
|
+
this.failProtocol(operation, 'Bash worker output must be Uint8Array bytes', bytes);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
const actual = operation.outputBytes + bytes.byteLength;
|
|
831
|
+
const limit = operation.runRequest?.limits.maxOutputBytes ?? 0;
|
|
832
|
+
if (actual > limit) {
|
|
833
|
+
this.failOperation(operation, new OutputLimitError(`Bash output exceeded ${limit} bytes`, {
|
|
834
|
+
actual,
|
|
835
|
+
limit,
|
|
836
|
+
phase: 'execute',
|
|
837
|
+
runtimeId: 'BASH'
|
|
838
|
+
}), true);
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
operation.outputBytes = actual;
|
|
842
|
+
const output = operation.decoders[stream].decode(bytes, { stream: true });
|
|
843
|
+
if (!output)
|
|
844
|
+
return;
|
|
845
|
+
try {
|
|
846
|
+
this.output?.(output);
|
|
847
|
+
}
|
|
848
|
+
catch (error) {
|
|
849
|
+
this.failOperation(operation, error, true);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
flushDecodedOutput(operation) {
|
|
853
|
+
for (const stream of ['stdout', 'stderr']) {
|
|
854
|
+
let output;
|
|
855
|
+
try {
|
|
856
|
+
output = operation.decoders[stream].decode();
|
|
857
|
+
}
|
|
858
|
+
catch (error) {
|
|
859
|
+
this.failProtocol(operation, 'Bash output was not valid streaming UTF-8', error);
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
if (!output)
|
|
863
|
+
continue;
|
|
864
|
+
try {
|
|
865
|
+
this.output?.(output);
|
|
866
|
+
}
|
|
867
|
+
catch (error) {
|
|
868
|
+
this.failOperation(operation, error, true);
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
flushStdin(operation) {
|
|
874
|
+
const handle = operation.handle;
|
|
875
|
+
if (!handle || !this.isActive(operation) || !operation.stdinReady)
|
|
876
|
+
return;
|
|
877
|
+
while (this.pendingInput.length > 0 && this.isActive(operation)) {
|
|
878
|
+
const input = this.pendingInput.shift();
|
|
879
|
+
const bytes = textEncoder.encode(input);
|
|
880
|
+
const message = {
|
|
881
|
+
type: 'stdin',
|
|
882
|
+
protocolVersion: BASH_WORKER_PROTOCOL_VERSION,
|
|
883
|
+
sessionId: handle.sessionId,
|
|
884
|
+
requestId: operation.requestId,
|
|
885
|
+
bytes
|
|
886
|
+
};
|
|
887
|
+
this.postMessage(operation, handle, message, [bytes.buffer]);
|
|
888
|
+
}
|
|
889
|
+
if (this.pendingEof && this.isActive(operation)) {
|
|
890
|
+
this.pendingEof = false;
|
|
891
|
+
this.postMessage(operation, handle, {
|
|
892
|
+
type: 'stdin-eof',
|
|
893
|
+
protocolVersion: BASH_WORKER_PROTOCOL_VERSION,
|
|
894
|
+
sessionId: handle.sessionId,
|
|
895
|
+
requestId: operation.requestId
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
handleWorkerFailure(handle, event) {
|
|
900
|
+
const operation = this.activeOperation;
|
|
901
|
+
if (handle.retired)
|
|
902
|
+
return;
|
|
903
|
+
if (!operation || operation.handle !== handle) {
|
|
904
|
+
if (this.readyWorker === handle)
|
|
905
|
+
this.retireWorker(handle);
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
const location = event.filename && event.lineno
|
|
909
|
+
? ` (${event.filename}:${event.lineno}:${event.colno})`
|
|
910
|
+
: '';
|
|
911
|
+
const message = `Bash outer worker script error: ${event.message || 'unknown error'}${location}`;
|
|
912
|
+
const error = operation.stage === 'startup'
|
|
913
|
+
? new WorkerStartupError(message, { cause: event, runtimeId: 'BASH' })
|
|
914
|
+
: new RuntimeExecutionError(message, {
|
|
915
|
+
cause: event,
|
|
916
|
+
phase: 'execute',
|
|
917
|
+
runtimeId: 'BASH'
|
|
918
|
+
});
|
|
919
|
+
this.failOperation(operation, error, true);
|
|
920
|
+
}
|
|
921
|
+
handleWorkerProtocolFailure(handle, cause) {
|
|
922
|
+
const operation = this.activeOperation;
|
|
923
|
+
if (handle.retired)
|
|
924
|
+
return;
|
|
925
|
+
if (!operation || operation.handle !== handle) {
|
|
926
|
+
if (this.readyWorker === handle)
|
|
927
|
+
this.retireWorker(handle);
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
this.failOperation(operation, new ProtocolError('Bash worker message deserialization failed', {
|
|
931
|
+
cause,
|
|
932
|
+
runtimeId: 'BASH'
|
|
933
|
+
}), true);
|
|
934
|
+
}
|
|
935
|
+
failProtocol(operation, message, cause) {
|
|
936
|
+
this.failOperation(operation, new ProtocolError(message, { cause, runtimeId: 'BASH' }), true);
|
|
937
|
+
}
|
|
938
|
+
deserializeWorkerError(error, phase) {
|
|
939
|
+
const context = {
|
|
940
|
+
cause: error,
|
|
941
|
+
phase,
|
|
942
|
+
...(error.profileId ? { profileId: error.profileId } : {}),
|
|
943
|
+
...(error.recoverable === undefined ? {} : { recoverable: error.recoverable }),
|
|
944
|
+
runtimeId: 'BASH'
|
|
945
|
+
};
|
|
946
|
+
let deserialized;
|
|
947
|
+
if (phase === 'protocol' || error.code === 'protocol') {
|
|
948
|
+
deserialized = new ProtocolError(error.message, context);
|
|
949
|
+
}
|
|
950
|
+
else {
|
|
951
|
+
switch (error.code) {
|
|
952
|
+
case 'unsupported-language':
|
|
953
|
+
deserialized = error.languageId
|
|
954
|
+
? new UnsupportedLanguageError(error.languageId, context)
|
|
955
|
+
: new WasmIdleError(error.message, {
|
|
956
|
+
...context,
|
|
957
|
+
code: 'unsupported-language'
|
|
958
|
+
});
|
|
959
|
+
break;
|
|
960
|
+
case 'busy':
|
|
961
|
+
deserialized = new BusyError(error.message, context);
|
|
962
|
+
break;
|
|
963
|
+
case 'runtime-configuration':
|
|
964
|
+
deserialized = new RuntimeConfigurationError(error.message, context);
|
|
965
|
+
break;
|
|
966
|
+
case 'asset-not-found':
|
|
967
|
+
deserialized = new AssetNotFoundError(error.message, context);
|
|
968
|
+
break;
|
|
969
|
+
case 'asset-integrity':
|
|
970
|
+
deserialized = new AssetIntegrityError(error.message, context);
|
|
971
|
+
break;
|
|
972
|
+
case 'asset-too-large':
|
|
973
|
+
deserialized = new AssetTooLargeError(error.message, {
|
|
974
|
+
...context,
|
|
975
|
+
actual: error.actual,
|
|
976
|
+
limit: error.limit
|
|
977
|
+
});
|
|
978
|
+
break;
|
|
979
|
+
case 'worker-startup':
|
|
980
|
+
deserialized = new WorkerStartupError(error.message, context);
|
|
981
|
+
break;
|
|
982
|
+
case 'compile':
|
|
983
|
+
deserialized = new CompileError(error.message, context);
|
|
984
|
+
break;
|
|
985
|
+
case 'runtime':
|
|
986
|
+
deserialized = new RuntimeExecutionError(error.message, context);
|
|
987
|
+
break;
|
|
988
|
+
case 'timeout':
|
|
989
|
+
deserialized =
|
|
990
|
+
error.timeoutMs === undefined
|
|
991
|
+
? new WasmIdleError(error.message, { ...context, code: 'timeout' })
|
|
992
|
+
: new TimeoutError(error.message, {
|
|
993
|
+
...context,
|
|
994
|
+
timeoutMs: error.timeoutMs
|
|
995
|
+
});
|
|
996
|
+
break;
|
|
997
|
+
case 'cancelled':
|
|
998
|
+
deserialized = new CancelledError(error.message, context);
|
|
999
|
+
break;
|
|
1000
|
+
case 'resource-limit':
|
|
1001
|
+
deserialized =
|
|
1002
|
+
error.actual === undefined ||
|
|
1003
|
+
error.limit === undefined ||
|
|
1004
|
+
error.resource === undefined
|
|
1005
|
+
? new WasmIdleError(error.message, {
|
|
1006
|
+
...context,
|
|
1007
|
+
code: 'resource-limit'
|
|
1008
|
+
})
|
|
1009
|
+
: new ResourceLimitError(error.message, {
|
|
1010
|
+
...context,
|
|
1011
|
+
actual: error.actual,
|
|
1012
|
+
limit: error.limit,
|
|
1013
|
+
resource: error.resource
|
|
1014
|
+
});
|
|
1015
|
+
break;
|
|
1016
|
+
case 'output-limit':
|
|
1017
|
+
deserialized =
|
|
1018
|
+
error.actual === undefined || error.limit === undefined
|
|
1019
|
+
? new WasmIdleError(error.message, {
|
|
1020
|
+
...context,
|
|
1021
|
+
code: 'output-limit'
|
|
1022
|
+
})
|
|
1023
|
+
: new OutputLimitError(error.message, {
|
|
1024
|
+
...context,
|
|
1025
|
+
actual: error.actual,
|
|
1026
|
+
limit: error.limit
|
|
1027
|
+
});
|
|
1028
|
+
break;
|
|
1029
|
+
case 'diagnostic-limit':
|
|
1030
|
+
deserialized =
|
|
1031
|
+
error.actual === undefined || error.limit === undefined
|
|
1032
|
+
? new WasmIdleError(error.message, {
|
|
1033
|
+
...context,
|
|
1034
|
+
code: 'diagnostic-limit'
|
|
1035
|
+
})
|
|
1036
|
+
: new DiagnosticLimitError(error.message, {
|
|
1037
|
+
...context,
|
|
1038
|
+
actual: error.actual,
|
|
1039
|
+
limit: error.limit
|
|
1040
|
+
});
|
|
1041
|
+
break;
|
|
1042
|
+
case 'unsupported-browser-feature':
|
|
1043
|
+
deserialized = error.feature
|
|
1044
|
+
? new UnsupportedBrowserFeatureError(error.feature, context)
|
|
1045
|
+
: new WasmIdleError(error.message, {
|
|
1046
|
+
...context,
|
|
1047
|
+
code: 'unsupported-browser-feature'
|
|
1048
|
+
});
|
|
1049
|
+
break;
|
|
1050
|
+
default:
|
|
1051
|
+
deserialized =
|
|
1052
|
+
phase === 'execute'
|
|
1053
|
+
? new RuntimeExecutionError(error.message, context)
|
|
1054
|
+
: new WorkerStartupError(error.message, context);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
if (deserialized.name === 'WasmIdleError' && error.name) {
|
|
1058
|
+
deserialized.name = error.name;
|
|
1059
|
+
}
|
|
1060
|
+
if (error.stack)
|
|
1061
|
+
deserialized.stack = error.stack;
|
|
1062
|
+
return deserialized;
|
|
1063
|
+
}
|
|
1064
|
+
retireWorker(handle) {
|
|
1065
|
+
if (handle.retired)
|
|
1066
|
+
return;
|
|
1067
|
+
handle.retired = true;
|
|
1068
|
+
if (this.readyWorker === handle)
|
|
1069
|
+
this.readyWorker = null;
|
|
1070
|
+
try {
|
|
1071
|
+
handle.worker.onmessage = null;
|
|
1072
|
+
}
|
|
1073
|
+
catch {
|
|
1074
|
+
// Handler cleanup remains best effort.
|
|
1075
|
+
}
|
|
1076
|
+
try {
|
|
1077
|
+
handle.worker.onerror = null;
|
|
1078
|
+
}
|
|
1079
|
+
catch {
|
|
1080
|
+
// Handler cleanup remains best effort.
|
|
1081
|
+
}
|
|
1082
|
+
try {
|
|
1083
|
+
handle.worker.onmessageerror = null;
|
|
1084
|
+
}
|
|
1085
|
+
catch {
|
|
1086
|
+
// Handler cleanup remains best effort.
|
|
1087
|
+
}
|
|
1088
|
+
try {
|
|
1089
|
+
handle.worker.terminate();
|
|
1090
|
+
}
|
|
1091
|
+
catch {
|
|
1092
|
+
// The worker may already be detached.
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
export default Bash;
|