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,982 @@
|
|
|
1
|
+
import {} from '../options';
|
|
2
|
+
import { createBashNestedBootstrapSource } from './bashNestedBootstrap';
|
|
3
|
+
import { BusyError, DEFAULT_WORKSPACE_LIMITS, OutputLimitError, RuntimeConfigurationError, TimeoutError, resolveExecutionLimits, verifyBashRuntimePreflightPayload, validateExecutionWorkspace } from '@wasm-idle/core';
|
|
4
|
+
const abortReason = (signal, phase) => {
|
|
5
|
+
const reason = signal.reason;
|
|
6
|
+
return reason !== undefined
|
|
7
|
+
? reason
|
|
8
|
+
: new DOMException(phase === 'startup' ? 'Bash runtime startup aborted' : 'Bash execution aborted', 'AbortError');
|
|
9
|
+
};
|
|
10
|
+
const EXECUTION_LIMIT_KEYS = [
|
|
11
|
+
'assetTimeoutMs',
|
|
12
|
+
'startupTimeoutMs',
|
|
13
|
+
'compileTimeoutMs',
|
|
14
|
+
'runTimeoutMs',
|
|
15
|
+
'maxOutputBytes',
|
|
16
|
+
'maxDiagnostics',
|
|
17
|
+
'maxWorkspaceBytes',
|
|
18
|
+
'maxAssetBytes',
|
|
19
|
+
'maxWasmMemoryBytes',
|
|
20
|
+
'maxWorkers',
|
|
21
|
+
'maxThreads'
|
|
22
|
+
];
|
|
23
|
+
class BashWorkerRuntime {
|
|
24
|
+
output;
|
|
25
|
+
outputBytes;
|
|
26
|
+
oncompilerdiagnostic;
|
|
27
|
+
webcUrl = '';
|
|
28
|
+
runtimePackage = null;
|
|
29
|
+
instance = null;
|
|
30
|
+
stdinWriter = null;
|
|
31
|
+
outputController = null;
|
|
32
|
+
pendingInput = [];
|
|
33
|
+
pendingEof = false;
|
|
34
|
+
activeLoadReject = null;
|
|
35
|
+
activeLoadCleanup = null;
|
|
36
|
+
loadGeneration = 0;
|
|
37
|
+
sdkModule = null;
|
|
38
|
+
sdkRuntime = null;
|
|
39
|
+
sdkBlobUrl = '';
|
|
40
|
+
nestedWorkerBlobUrl = '';
|
|
41
|
+
activeReject = null;
|
|
42
|
+
activeRunCleanup = null;
|
|
43
|
+
begin = 0;
|
|
44
|
+
elapse = 0;
|
|
45
|
+
uid = 0;
|
|
46
|
+
exit = true;
|
|
47
|
+
activeOperation = null;
|
|
48
|
+
importVerifiedSdkModule;
|
|
49
|
+
constructor(dependencies = {}) {
|
|
50
|
+
this.importVerifiedSdkModule =
|
|
51
|
+
dependencies.importVerifiedSdkModule ??
|
|
52
|
+
((url) => import(/* @vite-ignore */ url));
|
|
53
|
+
}
|
|
54
|
+
beginOperation(phase) {
|
|
55
|
+
if (this.activeOperation) {
|
|
56
|
+
throw new BusyError('Bash runtime already has an active operation', {
|
|
57
|
+
runtimeId: 'BASH',
|
|
58
|
+
phase: this.activeOperation.phase
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const operation = {
|
|
62
|
+
token: Symbol(phase),
|
|
63
|
+
phase,
|
|
64
|
+
cancelled: false,
|
|
65
|
+
cleanedUp: false,
|
|
66
|
+
cleanups: [],
|
|
67
|
+
abortController: new AbortController()
|
|
68
|
+
};
|
|
69
|
+
this.activeOperation = operation;
|
|
70
|
+
return operation;
|
|
71
|
+
}
|
|
72
|
+
isOperationActive(operation) {
|
|
73
|
+
return this.activeOperation?.token === operation.token && !operation.cancelled;
|
|
74
|
+
}
|
|
75
|
+
requireOperationActive(operation) {
|
|
76
|
+
if (this.isOperationActive(operation))
|
|
77
|
+
return;
|
|
78
|
+
throw operation.cancelled
|
|
79
|
+
? operation.cancellationReason
|
|
80
|
+
: operation.phase === 'startup'
|
|
81
|
+
? 'Bash runtime startup cancelled'
|
|
82
|
+
: 'Bash execution cancelled';
|
|
83
|
+
}
|
|
84
|
+
snapshotExecutionLimits(operation, source) {
|
|
85
|
+
const snapshot = {};
|
|
86
|
+
if (source) {
|
|
87
|
+
for (const key of EXECUTION_LIMIT_KEYS) {
|
|
88
|
+
this.requireOperationActive(operation);
|
|
89
|
+
const value = source[key];
|
|
90
|
+
this.requireOperationActive(operation);
|
|
91
|
+
if (value !== undefined) {
|
|
92
|
+
snapshot[key] = value;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const limits = resolveExecutionLimits(snapshot);
|
|
97
|
+
this.requireOperationActive(operation);
|
|
98
|
+
return limits;
|
|
99
|
+
}
|
|
100
|
+
releaseOperation(operation) {
|
|
101
|
+
if (this.activeOperation?.token !== operation.token)
|
|
102
|
+
return false;
|
|
103
|
+
this.activeOperation = null;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
cleanupOperation(operation) {
|
|
107
|
+
if (operation.cleanedUp)
|
|
108
|
+
return;
|
|
109
|
+
operation.cleanedUp = true;
|
|
110
|
+
const cleanups = operation.cleanups.splice(0);
|
|
111
|
+
for (const cleanup of cleanups) {
|
|
112
|
+
try {
|
|
113
|
+
cleanup();
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// Caller-owned cleanup must not replace the operation result.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
abortOperationSignal(operation, reason) {
|
|
121
|
+
try {
|
|
122
|
+
operation.abortController.abort(reason);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// Internal abort cleanup must not replace the operation result.
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
bindOperationTimeout(operation, timeoutMs) {
|
|
129
|
+
if (!this.isOperationActive(operation))
|
|
130
|
+
return;
|
|
131
|
+
let timeout;
|
|
132
|
+
operation.cleanups.push(() => {
|
|
133
|
+
if (timeout !== undefined)
|
|
134
|
+
clearTimeout(timeout);
|
|
135
|
+
});
|
|
136
|
+
try {
|
|
137
|
+
timeout = setTimeout(() => {
|
|
138
|
+
if (!this.isOperationActive(operation))
|
|
139
|
+
return;
|
|
140
|
+
const label = operation.phase === 'startup' ? 'startup' : 'execution';
|
|
141
|
+
this.terminate(new TimeoutError(`Bash ${label} timed out after ${timeoutMs} ms`, {
|
|
142
|
+
phase: operation.phase,
|
|
143
|
+
runtimeId: 'BASH',
|
|
144
|
+
timeoutMs
|
|
145
|
+
}));
|
|
146
|
+
}, timeoutMs);
|
|
147
|
+
if (operation.cleanedUp)
|
|
148
|
+
clearTimeout(timeout);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (this.isOperationActive(operation))
|
|
152
|
+
this.terminate(error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
releaseBeforeSession(operation, reason) {
|
|
156
|
+
const outcome = operation.cancelled ? operation.cancellationReason : reason;
|
|
157
|
+
this.releaseOperation(operation);
|
|
158
|
+
this.cleanupOperation(operation);
|
|
159
|
+
return outcome;
|
|
160
|
+
}
|
|
161
|
+
bindPreSessionAbort(operation, signal) {
|
|
162
|
+
if (!signal || !this.isOperationActive(operation))
|
|
163
|
+
return () => undefined;
|
|
164
|
+
let registered = false;
|
|
165
|
+
let unbound = false;
|
|
166
|
+
const unbind = () => {
|
|
167
|
+
if (unbound)
|
|
168
|
+
return;
|
|
169
|
+
unbound = true;
|
|
170
|
+
if (registered)
|
|
171
|
+
signal.removeEventListener('abort', onAbort);
|
|
172
|
+
};
|
|
173
|
+
const onAbort = () => {
|
|
174
|
+
if (!this.isOperationActive(operation))
|
|
175
|
+
return;
|
|
176
|
+
let reason;
|
|
177
|
+
try {
|
|
178
|
+
reason = abortReason(signal, operation.phase);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
reason = error;
|
|
182
|
+
}
|
|
183
|
+
if (!this.isOperationActive(operation))
|
|
184
|
+
return;
|
|
185
|
+
operation.cancelled = true;
|
|
186
|
+
operation.cancellationReason = reason;
|
|
187
|
+
this.releaseOperation(operation);
|
|
188
|
+
this.cleanupOperation(operation);
|
|
189
|
+
this.abortOperationSignal(operation, reason);
|
|
190
|
+
};
|
|
191
|
+
operation.cleanups.push(unbind);
|
|
192
|
+
try {
|
|
193
|
+
const alreadyAborted = signal.aborted;
|
|
194
|
+
if (!this.isOperationActive(operation))
|
|
195
|
+
return unbind;
|
|
196
|
+
if (alreadyAborted) {
|
|
197
|
+
onAbort();
|
|
198
|
+
return unbind;
|
|
199
|
+
}
|
|
200
|
+
registered = true;
|
|
201
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
202
|
+
if (!this.isOperationActive(operation))
|
|
203
|
+
return unbind;
|
|
204
|
+
const abortedAfterBinding = signal.aborted;
|
|
205
|
+
if (!this.isOperationActive(operation))
|
|
206
|
+
return unbind;
|
|
207
|
+
if (abortedAfterBinding)
|
|
208
|
+
onAbort();
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
if (this.isOperationActive(operation)) {
|
|
212
|
+
operation.cancelled = true;
|
|
213
|
+
operation.cancellationReason = error;
|
|
214
|
+
this.releaseOperation(operation);
|
|
215
|
+
this.cleanupOperation(operation);
|
|
216
|
+
this.abortOperationSignal(operation, error);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return unbind;
|
|
220
|
+
}
|
|
221
|
+
load(_runtimeAssets = '', _code = '', _log = true, _args = [], _options = {}, _progress) {
|
|
222
|
+
return Promise.reject(new RuntimeConfigurationError('Bash worker runtime requires a verified page-host preflight payload', { phase: 'startup', runtimeId: 'BASH' }));
|
|
223
|
+
}
|
|
224
|
+
loadVerified(runtimePreflight, _log = true, options = {}, progress) {
|
|
225
|
+
let activeOperation;
|
|
226
|
+
try {
|
|
227
|
+
activeOperation = this.beginOperation('startup');
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
return Promise.reject(error);
|
|
231
|
+
}
|
|
232
|
+
let signal;
|
|
233
|
+
let limits;
|
|
234
|
+
let unbindPreSessionAbort = () => undefined;
|
|
235
|
+
try {
|
|
236
|
+
signal = options.signal;
|
|
237
|
+
unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
|
|
238
|
+
this.requireOperationActive(activeOperation);
|
|
239
|
+
const limitSource = options.limits;
|
|
240
|
+
this.requireOperationActive(activeOperation);
|
|
241
|
+
limits = this.snapshotExecutionLimits(activeOperation, limitSource);
|
|
242
|
+
unbindPreSessionAbort();
|
|
243
|
+
this.requireOperationActive(activeOperation);
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
return Promise.reject(this.releaseBeforeSession(activeOperation, error));
|
|
247
|
+
}
|
|
248
|
+
const timeoutMs = Math.min(2_147_483_647, limits.assetTimeoutMs + limits.startupTimeoutMs);
|
|
249
|
+
const loadGeneration = ++this.loadGeneration;
|
|
250
|
+
return new Promise((resolve, reject) => {
|
|
251
|
+
let onAbort;
|
|
252
|
+
let settleRejectedLoad;
|
|
253
|
+
let cleanedUp = false;
|
|
254
|
+
const cleanup = () => {
|
|
255
|
+
if (cleanedUp)
|
|
256
|
+
return;
|
|
257
|
+
cleanedUp = true;
|
|
258
|
+
if (signal && onAbort) {
|
|
259
|
+
try {
|
|
260
|
+
signal.removeEventListener('abort', onAbort);
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
// Cleanup must not replace the startup result.
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (this.activeLoadCleanup === cleanup)
|
|
267
|
+
this.activeLoadCleanup = null;
|
|
268
|
+
if (this.activeLoadReject === settleRejectedLoad)
|
|
269
|
+
this.activeLoadReject = null;
|
|
270
|
+
this.releaseOperation(activeOperation);
|
|
271
|
+
this.cleanupOperation(activeOperation);
|
|
272
|
+
};
|
|
273
|
+
settleRejectedLoad = (reason) => {
|
|
274
|
+
cleanup();
|
|
275
|
+
reject(reason);
|
|
276
|
+
};
|
|
277
|
+
const rejectLoad = (reason) => {
|
|
278
|
+
if (!this.isOperationActive(activeOperation))
|
|
279
|
+
return;
|
|
280
|
+
settleRejectedLoad(reason);
|
|
281
|
+
this.abortOperationSignal(activeOperation, reason);
|
|
282
|
+
};
|
|
283
|
+
onAbort = signal
|
|
284
|
+
? () => {
|
|
285
|
+
if (!this.isOperationActive(activeOperation) ||
|
|
286
|
+
loadGeneration !== this.loadGeneration) {
|
|
287
|
+
cleanup();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
let reason;
|
|
291
|
+
try {
|
|
292
|
+
reason = abortReason(signal, 'startup');
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
reason = error;
|
|
296
|
+
}
|
|
297
|
+
if (!this.isOperationActive(activeOperation) ||
|
|
298
|
+
loadGeneration !== this.loadGeneration) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
this.terminate(reason);
|
|
302
|
+
}
|
|
303
|
+
: undefined;
|
|
304
|
+
this.activeLoadCleanup = cleanup;
|
|
305
|
+
this.activeLoadReject = settleRejectedLoad;
|
|
306
|
+
try {
|
|
307
|
+
if (signal && onAbort) {
|
|
308
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
309
|
+
if (!this.isOperationActive(activeOperation))
|
|
310
|
+
return;
|
|
311
|
+
const abortedAfterBinding = signal.aborted;
|
|
312
|
+
if (!this.isOperationActive(activeOperation))
|
|
313
|
+
return;
|
|
314
|
+
if (abortedAfterBinding)
|
|
315
|
+
onAbort();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
if (this.isOperationActive(activeOperation))
|
|
320
|
+
this.terminate(error);
|
|
321
|
+
}
|
|
322
|
+
this.bindOperationTimeout(activeOperation, timeoutMs);
|
|
323
|
+
if (!this.isOperationActive(activeOperation))
|
|
324
|
+
return;
|
|
325
|
+
void (async () => {
|
|
326
|
+
let nextPackage = null;
|
|
327
|
+
let nextSdk = null;
|
|
328
|
+
let nextSdkRuntime = null;
|
|
329
|
+
let nextSdkBlobUrl = '';
|
|
330
|
+
let nextNestedWorkerBlobUrl = '';
|
|
331
|
+
let adopted = false;
|
|
332
|
+
const revokeCandidateUrls = () => {
|
|
333
|
+
for (const url of [nextNestedWorkerBlobUrl, nextSdkBlobUrl]) {
|
|
334
|
+
if (!url)
|
|
335
|
+
continue;
|
|
336
|
+
try {
|
|
337
|
+
URL.revokeObjectURL(url);
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
// Preserve startup ownership and failure semantics.
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
nextNestedWorkerBlobUrl = '';
|
|
344
|
+
nextSdkBlobUrl = '';
|
|
345
|
+
};
|
|
346
|
+
try {
|
|
347
|
+
if (!this.isOperationActive(activeOperation) ||
|
|
348
|
+
loadGeneration !== this.loadGeneration) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
this.pendingInput = [];
|
|
352
|
+
this.pendingEof = false;
|
|
353
|
+
progress?.set?.(0.1, 'Verifying Bash runtime payload');
|
|
354
|
+
if (!this.isOperationActive(activeOperation) ||
|
|
355
|
+
loadGeneration !== this.loadGeneration) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const verified = await verifyBashRuntimePreflightPayload(runtimePreflight, {
|
|
359
|
+
maxAssetBytes: limits.maxAssetBytes,
|
|
360
|
+
signal: activeOperation.abortController.signal
|
|
361
|
+
});
|
|
362
|
+
this.requireOperationActive(activeOperation);
|
|
363
|
+
const realmUrl = typeof globalThis.location?.href === 'string'
|
|
364
|
+
? globalThis.location.href
|
|
365
|
+
: 'https://wasm-idle.invalid/bash-outer-worker.js';
|
|
366
|
+
const sdkSentinelUrl = new URL(`/__wasm_idle/bash-sdk/${verified.manifestFingerprint}/index.mjs`, realmUrl).href;
|
|
367
|
+
nextSdkBlobUrl = URL.createObjectURL(new Blob([Uint8Array.from(verified.sdkJavaScriptBytes).buffer], {
|
|
368
|
+
type: 'text/javascript'
|
|
369
|
+
}));
|
|
370
|
+
const nestedBootstrapSource = createBashNestedBootstrapSource({
|
|
371
|
+
sdkModuleUrl: nextSdkBlobUrl,
|
|
372
|
+
sentinelUrl: sdkSentinelUrl,
|
|
373
|
+
realmUrl
|
|
374
|
+
});
|
|
375
|
+
nextNestedWorkerBlobUrl = URL.createObjectURL(new Blob([nestedBootstrapSource], { type: 'text/javascript' }));
|
|
376
|
+
nextSdk = await this.importVerifiedSdkModule(nextSdkBlobUrl);
|
|
377
|
+
if (!this.isOperationActive(activeOperation) ||
|
|
378
|
+
loadGeneration !== this.loadGeneration) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
await nextSdk.init({
|
|
382
|
+
module: verified.wasmerWasmBytes,
|
|
383
|
+
sdkUrl: sdkSentinelUrl,
|
|
384
|
+
workerUrl: nextNestedWorkerBlobUrl
|
|
385
|
+
});
|
|
386
|
+
if (!this.isOperationActive(activeOperation) ||
|
|
387
|
+
loadGeneration !== this.loadGeneration) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
nextSdkRuntime = new nextSdk.Runtime({ registry: null });
|
|
391
|
+
if (!this.isOperationActive(activeOperation) ||
|
|
392
|
+
loadGeneration !== this.loadGeneration) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
nextPackage = await nextSdk.Wasmer.fromFile(verified.webcBytes, nextSdkRuntime);
|
|
396
|
+
if (!this.isOperationActive(activeOperation) ||
|
|
397
|
+
loadGeneration !== this.loadGeneration) {
|
|
398
|
+
const stalePackage = nextPackage;
|
|
399
|
+
nextPackage = null;
|
|
400
|
+
try {
|
|
401
|
+
stalePackage.free();
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
// Cleanup must not replace the startup result.
|
|
405
|
+
}
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
progress?.set?.(1, 'Bash runtime ready');
|
|
409
|
+
if (!this.isOperationActive(activeOperation) ||
|
|
410
|
+
loadGeneration !== this.loadGeneration) {
|
|
411
|
+
const stalePackage = nextPackage;
|
|
412
|
+
nextPackage = null;
|
|
413
|
+
try {
|
|
414
|
+
stalePackage.free();
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
// Cleanup must not replace the startup result.
|
|
418
|
+
}
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const previousPackage = this.runtimePackage;
|
|
422
|
+
const previousSdkRuntime = this.sdkRuntime;
|
|
423
|
+
const previousSdkBlobUrl = this.sdkBlobUrl;
|
|
424
|
+
const previousNestedWorkerBlobUrl = this.nestedWorkerBlobUrl;
|
|
425
|
+
this.runtimePackage = nextPackage;
|
|
426
|
+
nextPackage = null;
|
|
427
|
+
this.sdkModule = nextSdk;
|
|
428
|
+
nextSdk = null;
|
|
429
|
+
this.sdkRuntime = nextSdkRuntime;
|
|
430
|
+
nextSdkRuntime = null;
|
|
431
|
+
this.sdkBlobUrl = nextSdkBlobUrl;
|
|
432
|
+
nextSdkBlobUrl = '';
|
|
433
|
+
this.nestedWorkerBlobUrl = nextNestedWorkerBlobUrl;
|
|
434
|
+
nextNestedWorkerBlobUrl = '';
|
|
435
|
+
this.webcUrl = `verified:${verified.profileId}:bash.webc`;
|
|
436
|
+
adopted = true;
|
|
437
|
+
try {
|
|
438
|
+
previousPackage?.free();
|
|
439
|
+
}
|
|
440
|
+
catch {
|
|
441
|
+
// Releasing the previous package must not replace startup success.
|
|
442
|
+
}
|
|
443
|
+
try {
|
|
444
|
+
previousSdkRuntime?.free?.();
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
// Releasing the previous isolated SDK runtime remains best effort.
|
|
448
|
+
}
|
|
449
|
+
for (const url of [previousNestedWorkerBlobUrl, previousSdkBlobUrl]) {
|
|
450
|
+
if (!url)
|
|
451
|
+
continue;
|
|
452
|
+
try {
|
|
453
|
+
URL.revokeObjectURL(url);
|
|
454
|
+
}
|
|
455
|
+
catch {
|
|
456
|
+
// Blob URL cleanup remains best effort after activation.
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
cleanup();
|
|
460
|
+
resolve();
|
|
461
|
+
}
|
|
462
|
+
catch (error) {
|
|
463
|
+
if (!this.isOperationActive(activeOperation) ||
|
|
464
|
+
loadGeneration !== this.loadGeneration) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
rejectLoad(error);
|
|
468
|
+
}
|
|
469
|
+
finally {
|
|
470
|
+
if (!adopted) {
|
|
471
|
+
const failedPackage = nextPackage;
|
|
472
|
+
nextPackage = null;
|
|
473
|
+
try {
|
|
474
|
+
failedPackage?.free();
|
|
475
|
+
}
|
|
476
|
+
catch {
|
|
477
|
+
// Preserve the startup result.
|
|
478
|
+
}
|
|
479
|
+
const failedRuntime = nextSdkRuntime;
|
|
480
|
+
nextSdkRuntime = null;
|
|
481
|
+
try {
|
|
482
|
+
failedRuntime?.free?.();
|
|
483
|
+
}
|
|
484
|
+
catch {
|
|
485
|
+
// Preserve the startup result.
|
|
486
|
+
}
|
|
487
|
+
revokeCandidateUrls();
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
})();
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
write(input) {
|
|
494
|
+
this.pendingInput.push(input);
|
|
495
|
+
this.pendingEof = false;
|
|
496
|
+
void this.flushPendingInput().catch(() => undefined);
|
|
497
|
+
}
|
|
498
|
+
eof() {
|
|
499
|
+
this.pendingEof = true;
|
|
500
|
+
void this.flushPendingInput().catch(() => undefined);
|
|
501
|
+
}
|
|
502
|
+
async flushPendingInput() {
|
|
503
|
+
const writer = this.stdinWriter;
|
|
504
|
+
if (!writer)
|
|
505
|
+
return;
|
|
506
|
+
const pending = this.pendingInput.splice(0);
|
|
507
|
+
for (const input of pending) {
|
|
508
|
+
await writer.write(new TextEncoder().encode(input));
|
|
509
|
+
if (this.stdinWriter !== writer)
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (this.pendingEof && this.stdinWriter === writer) {
|
|
513
|
+
this.pendingEof = false;
|
|
514
|
+
await writer.close();
|
|
515
|
+
if (this.stdinWriter === writer) {
|
|
516
|
+
this.stdinWriter = null;
|
|
517
|
+
try {
|
|
518
|
+
writer.releaseLock();
|
|
519
|
+
}
|
|
520
|
+
catch {
|
|
521
|
+
// The completed stream may already have released its writer.
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
disposeRunHandles(instance, writer, outputController, reason) {
|
|
527
|
+
try {
|
|
528
|
+
outputController?.abort(reason);
|
|
529
|
+
}
|
|
530
|
+
catch {
|
|
531
|
+
// Preserve the operation result.
|
|
532
|
+
}
|
|
533
|
+
if (writer) {
|
|
534
|
+
const releaseWriter = () => {
|
|
535
|
+
try {
|
|
536
|
+
writer.releaseLock();
|
|
537
|
+
}
|
|
538
|
+
catch {
|
|
539
|
+
// Pending stream operations may still own the writer lock.
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
try {
|
|
543
|
+
void Promise.resolve(writer.abort(reason))
|
|
544
|
+
.catch(() => undefined)
|
|
545
|
+
.finally(releaseWriter);
|
|
546
|
+
}
|
|
547
|
+
catch {
|
|
548
|
+
releaseWriter();
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
try {
|
|
552
|
+
instance?.free();
|
|
553
|
+
}
|
|
554
|
+
catch {
|
|
555
|
+
// Preserve the operation result.
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
async run(code, prepare, _log = true, progress, args = [], options = {}) {
|
|
559
|
+
const activeOperation = this.beginOperation('execute');
|
|
560
|
+
if (prepare) {
|
|
561
|
+
this.releaseOperation(activeOperation);
|
|
562
|
+
this.cleanupOperation(activeOperation);
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
const runtimePackage = this.runtimePackage;
|
|
566
|
+
if (!runtimePackage) {
|
|
567
|
+
throw this.releaseBeforeSession(activeOperation, new Error('Bash runtime is not loaded'));
|
|
568
|
+
}
|
|
569
|
+
let signal;
|
|
570
|
+
let programArgs;
|
|
571
|
+
let limits;
|
|
572
|
+
let workspace;
|
|
573
|
+
let stdin;
|
|
574
|
+
let unbindPreSessionAbort = () => undefined;
|
|
575
|
+
try {
|
|
576
|
+
signal = options.signal;
|
|
577
|
+
unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
|
|
578
|
+
this.requireOperationActive(activeOperation);
|
|
579
|
+
const configuredProgramArgs = options.programArgs;
|
|
580
|
+
this.requireOperationActive(activeOperation);
|
|
581
|
+
const programArgsSource = configuredProgramArgs ?? args;
|
|
582
|
+
programArgs = [];
|
|
583
|
+
if (Array.isArray(programArgsSource)) {
|
|
584
|
+
const programArgCount = programArgsSource.length;
|
|
585
|
+
this.requireOperationActive(activeOperation);
|
|
586
|
+
for (let index = 0; index < programArgCount; index += 1) {
|
|
587
|
+
const argument = programArgsSource[index];
|
|
588
|
+
this.requireOperationActive(activeOperation);
|
|
589
|
+
programArgs.push(argument);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
const limitSource = options.limits;
|
|
593
|
+
this.requireOperationActive(activeOperation);
|
|
594
|
+
limits = this.snapshotExecutionLimits(activeOperation, limitSource);
|
|
595
|
+
const workspaceFilesSource = options.workspaceFiles ?? [];
|
|
596
|
+
this.requireOperationActive(activeOperation);
|
|
597
|
+
if (!Array.isArray(workspaceFilesSource)) {
|
|
598
|
+
throw new TypeError('Bash workspace files must be an array');
|
|
599
|
+
}
|
|
600
|
+
const workspaceFileCount = workspaceFilesSource.length;
|
|
601
|
+
this.requireOperationActive(activeOperation);
|
|
602
|
+
const workspaceFiles = [];
|
|
603
|
+
for (let index = 0; index < workspaceFileCount; index += 1) {
|
|
604
|
+
const file = workspaceFilesSource[index];
|
|
605
|
+
this.requireOperationActive(activeOperation);
|
|
606
|
+
const path = file.path;
|
|
607
|
+
this.requireOperationActive(activeOperation);
|
|
608
|
+
const content = file.content;
|
|
609
|
+
this.requireOperationActive(activeOperation);
|
|
610
|
+
workspaceFiles.push({ path, content });
|
|
611
|
+
}
|
|
612
|
+
const activePath = options.activePath ?? 'main.sh';
|
|
613
|
+
this.requireOperationActive(activeOperation);
|
|
614
|
+
const workspaceLimitsSource = options.workspaceLimits;
|
|
615
|
+
this.requireOperationActive(activeOperation);
|
|
616
|
+
let workspaceLimits = {};
|
|
617
|
+
if (workspaceLimitsSource) {
|
|
618
|
+
const maxFiles = workspaceLimitsSource.maxFiles;
|
|
619
|
+
this.requireOperationActive(activeOperation);
|
|
620
|
+
const maxFileBytes = workspaceLimitsSource.maxFileBytes;
|
|
621
|
+
this.requireOperationActive(activeOperation);
|
|
622
|
+
const maxTotalBytes = workspaceLimitsSource.maxTotalBytes;
|
|
623
|
+
this.requireOperationActive(activeOperation);
|
|
624
|
+
const maxPathBytes = workspaceLimitsSource.maxPathBytes;
|
|
625
|
+
this.requireOperationActive(activeOperation);
|
|
626
|
+
const caseSensitive = workspaceLimitsSource.caseSensitive;
|
|
627
|
+
this.requireOperationActive(activeOperation);
|
|
628
|
+
workspaceLimits = {
|
|
629
|
+
maxFiles,
|
|
630
|
+
maxFileBytes,
|
|
631
|
+
maxTotalBytes,
|
|
632
|
+
maxPathBytes,
|
|
633
|
+
caseSensitive
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
workspace = validateExecutionWorkspace(code, workspaceFiles, activePath, {
|
|
637
|
+
...workspaceLimits,
|
|
638
|
+
maxFileBytes: Math.min(workspaceLimits.maxFileBytes ?? DEFAULT_WORKSPACE_LIMITS.maxFileBytes, limits.maxWorkspaceBytes),
|
|
639
|
+
maxTotalBytes: Math.min(workspaceLimits.maxTotalBytes ?? DEFAULT_WORKSPACE_LIMITS.maxTotalBytes, limits.maxWorkspaceBytes)
|
|
640
|
+
});
|
|
641
|
+
this.requireOperationActive(activeOperation);
|
|
642
|
+
stdin = options.stdin;
|
|
643
|
+
this.requireOperationActive(activeOperation);
|
|
644
|
+
unbindPreSessionAbort();
|
|
645
|
+
this.requireOperationActive(activeOperation);
|
|
646
|
+
}
|
|
647
|
+
catch (error) {
|
|
648
|
+
throw this.releaseBeforeSession(activeOperation, error);
|
|
649
|
+
}
|
|
650
|
+
const timeoutMs = Math.min(2_147_483_647, limits.compileTimeoutMs + limits.runTimeoutMs);
|
|
651
|
+
const mountedFiles = Object.fromEntries(workspace.workspaceFiles.map((file) => [file.path, file.content]));
|
|
652
|
+
const mountedActivePath = workspace.activePath ?? 'main.sh';
|
|
653
|
+
mountedFiles[mountedActivePath] = code;
|
|
654
|
+
const hasExplicitStdin = stdin !== undefined;
|
|
655
|
+
const queuedStdin = this.pendingInput.length > 0 ? this.pendingInput.join('') : undefined;
|
|
656
|
+
const suppliedStdin = stdin ?? (this.pendingEof ? queuedStdin || '' : undefined);
|
|
657
|
+
this.requireOperationActive(activeOperation);
|
|
658
|
+
this.exit = false;
|
|
659
|
+
this.begin = Date.now();
|
|
660
|
+
const runUid = ++this.uid;
|
|
661
|
+
if (suppliedStdin !== undefined) {
|
|
662
|
+
this.pendingInput = [];
|
|
663
|
+
this.pendingEof = false;
|
|
664
|
+
}
|
|
665
|
+
return new Promise((resolve, reject) => {
|
|
666
|
+
let outputBytes = 0;
|
|
667
|
+
let settleRejectedRun;
|
|
668
|
+
let cleanedUp = false;
|
|
669
|
+
const cleanup = () => {
|
|
670
|
+
if (cleanedUp)
|
|
671
|
+
return;
|
|
672
|
+
cleanedUp = true;
|
|
673
|
+
if (hasExplicitStdin && this.activeOperation?.token === activeOperation.token) {
|
|
674
|
+
this.pendingInput = [];
|
|
675
|
+
this.pendingEof = false;
|
|
676
|
+
}
|
|
677
|
+
if (signal && onAbort) {
|
|
678
|
+
try {
|
|
679
|
+
signal.removeEventListener('abort', onAbort);
|
|
680
|
+
}
|
|
681
|
+
catch {
|
|
682
|
+
// Cleanup must not replace the execution result.
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
if (this.activeRunCleanup === cleanup)
|
|
686
|
+
this.activeRunCleanup = null;
|
|
687
|
+
if (this.activeReject === settleRejectedRun)
|
|
688
|
+
this.activeReject = null;
|
|
689
|
+
this.releaseOperation(activeOperation);
|
|
690
|
+
this.cleanupOperation(activeOperation);
|
|
691
|
+
};
|
|
692
|
+
settleRejectedRun = (reason) => {
|
|
693
|
+
cleanup();
|
|
694
|
+
reject(reason);
|
|
695
|
+
};
|
|
696
|
+
const onAbort = signal
|
|
697
|
+
? () => {
|
|
698
|
+
if (!this.isOperationActive(activeOperation) || runUid !== this.uid) {
|
|
699
|
+
cleanup();
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
let reason;
|
|
703
|
+
try {
|
|
704
|
+
reason = abortReason(signal, 'execute');
|
|
705
|
+
}
|
|
706
|
+
catch (error) {
|
|
707
|
+
reason = error;
|
|
708
|
+
}
|
|
709
|
+
if (!this.isOperationActive(activeOperation) || runUid !== this.uid) {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
this.terminate(reason);
|
|
713
|
+
}
|
|
714
|
+
: undefined;
|
|
715
|
+
this.activeReject = settleRejectedRun;
|
|
716
|
+
this.activeRunCleanup = cleanup;
|
|
717
|
+
try {
|
|
718
|
+
if (signal && onAbort) {
|
|
719
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
720
|
+
if (!this.isOperationActive(activeOperation))
|
|
721
|
+
return;
|
|
722
|
+
const abortedAfterBinding = signal.aborted;
|
|
723
|
+
if (!this.isOperationActive(activeOperation))
|
|
724
|
+
return;
|
|
725
|
+
if (abortedAfterBinding)
|
|
726
|
+
onAbort();
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
catch (error) {
|
|
730
|
+
if (this.isOperationActive(activeOperation))
|
|
731
|
+
this.terminate(error);
|
|
732
|
+
}
|
|
733
|
+
this.bindOperationTimeout(activeOperation, timeoutMs);
|
|
734
|
+
if (!this.isOperationActive(activeOperation) || runUid !== this.uid)
|
|
735
|
+
return;
|
|
736
|
+
void (async () => {
|
|
737
|
+
const ownsRun = () => this.isOperationActive(activeOperation) && runUid === this.uid;
|
|
738
|
+
try {
|
|
739
|
+
const command = runtimePackage.entrypoint;
|
|
740
|
+
if (!command)
|
|
741
|
+
throw new Error('Bash WEBc package has no entrypoint');
|
|
742
|
+
let instance;
|
|
743
|
+
try {
|
|
744
|
+
instance = await command.run({
|
|
745
|
+
args: ['-c', code, mountedActivePath, ...programArgs],
|
|
746
|
+
mount: { '/workspace': mountedFiles },
|
|
747
|
+
cwd: '/workspace',
|
|
748
|
+
...(suppliedStdin === undefined ? {} : { stdin: suppliedStdin })
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
finally {
|
|
752
|
+
try {
|
|
753
|
+
command.free();
|
|
754
|
+
}
|
|
755
|
+
catch {
|
|
756
|
+
// Command cleanup must not replace the execution result.
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
if (!ownsRun()) {
|
|
760
|
+
this.disposeRunHandles(instance, null, null, activeOperation.cancellationReason);
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
try {
|
|
764
|
+
progress?.report?.({
|
|
765
|
+
kind: 'ready',
|
|
766
|
+
state: 'running',
|
|
767
|
+
reason: 'started',
|
|
768
|
+
label: 'Bash process started'
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
catch (error) {
|
|
772
|
+
this.disposeRunHandles(instance, null, null, error);
|
|
773
|
+
if (!ownsRun())
|
|
774
|
+
return;
|
|
775
|
+
throw error;
|
|
776
|
+
}
|
|
777
|
+
if (!ownsRun()) {
|
|
778
|
+
this.disposeRunHandles(instance, null, null, activeOperation.cancellationReason);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
let writer = null;
|
|
782
|
+
try {
|
|
783
|
+
writer =
|
|
784
|
+
suppliedStdin === undefined
|
|
785
|
+
? instance.stdin?.getWriter() || null
|
|
786
|
+
: null;
|
|
787
|
+
}
|
|
788
|
+
catch (error) {
|
|
789
|
+
this.disposeRunHandles(instance, null, null, error);
|
|
790
|
+
throw error;
|
|
791
|
+
}
|
|
792
|
+
if (!ownsRun()) {
|
|
793
|
+
this.disposeRunHandles(instance, writer, null, activeOperation.cancellationReason);
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
this.instance = instance;
|
|
797
|
+
this.stdinWriter = writer;
|
|
798
|
+
await this.flushPendingInput();
|
|
799
|
+
if (!ownsRun())
|
|
800
|
+
return;
|
|
801
|
+
const outputController = new AbortController();
|
|
802
|
+
this.outputController = outputController;
|
|
803
|
+
const outputPipes = [];
|
|
804
|
+
const writeOutput = (stream, chunk) => {
|
|
805
|
+
if (!ownsRun())
|
|
806
|
+
return;
|
|
807
|
+
const actual = outputBytes + chunk.byteLength;
|
|
808
|
+
if (actual > limits.maxOutputBytes) {
|
|
809
|
+
this.terminate(new OutputLimitError(`Bash output exceeded ${limits.maxOutputBytes} bytes`, {
|
|
810
|
+
actual,
|
|
811
|
+
limit: limits.maxOutputBytes,
|
|
812
|
+
phase: 'execute',
|
|
813
|
+
runtimeId: 'BASH'
|
|
814
|
+
}));
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
outputBytes = actual;
|
|
818
|
+
if (this.outputBytes) {
|
|
819
|
+
this.outputBytes(stream, chunk);
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
this.output?.(new TextDecoder().decode(chunk));
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
try {
|
|
826
|
+
outputPipes.push(instance.stdout.pipeTo(new WritableStream({
|
|
827
|
+
write: (chunk) => writeOutput('stdout', chunk)
|
|
828
|
+
}), { signal: outputController.signal }));
|
|
829
|
+
outputPipes.push(instance.stderr.pipeTo(new WritableStream({
|
|
830
|
+
write: (chunk) => writeOutput('stderr', chunk)
|
|
831
|
+
}), { signal: outputController.signal }));
|
|
832
|
+
}
|
|
833
|
+
catch (error) {
|
|
834
|
+
void Promise.allSettled(outputPipes);
|
|
835
|
+
throw error;
|
|
836
|
+
}
|
|
837
|
+
const outputDone = Promise.allSettled(outputPipes);
|
|
838
|
+
if (!ownsRun())
|
|
839
|
+
return;
|
|
840
|
+
this.instance = null;
|
|
841
|
+
const result = await instance.wait();
|
|
842
|
+
await outputDone;
|
|
843
|
+
if (!ownsRun())
|
|
844
|
+
return;
|
|
845
|
+
this.elapse = Date.now() - this.begin;
|
|
846
|
+
this.exit = true;
|
|
847
|
+
const settledWriter = this.stdinWriter;
|
|
848
|
+
this.stdinWriter = null;
|
|
849
|
+
this.instance = null;
|
|
850
|
+
if (this.outputController === outputController) {
|
|
851
|
+
this.outputController = null;
|
|
852
|
+
}
|
|
853
|
+
try {
|
|
854
|
+
settledWriter?.releaseLock();
|
|
855
|
+
}
|
|
856
|
+
catch {
|
|
857
|
+
// The completed stream may already have released its writer.
|
|
858
|
+
}
|
|
859
|
+
if (!result.ok) {
|
|
860
|
+
settleRejectedRun(`Bash exited with status ${result.code}.`);
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
cleanup();
|
|
864
|
+
resolve(true);
|
|
865
|
+
}
|
|
866
|
+
catch (error) {
|
|
867
|
+
if (!ownsRun())
|
|
868
|
+
return;
|
|
869
|
+
this.exit = true;
|
|
870
|
+
const writer = this.stdinWriter;
|
|
871
|
+
const instance = this.instance;
|
|
872
|
+
const outputController = this.outputController;
|
|
873
|
+
this.stdinWriter = null;
|
|
874
|
+
this.instance = null;
|
|
875
|
+
this.outputController = null;
|
|
876
|
+
this.disposeRunHandles(instance, writer, outputController, error);
|
|
877
|
+
settleRejectedRun(error instanceof Error ? error.message : String(error));
|
|
878
|
+
}
|
|
879
|
+
finally {
|
|
880
|
+
cleanup();
|
|
881
|
+
}
|
|
882
|
+
})();
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
kill() {
|
|
886
|
+
this.terminate();
|
|
887
|
+
}
|
|
888
|
+
terminate(reason = 'Process terminated') {
|
|
889
|
+
const activeOperation = this.activeOperation;
|
|
890
|
+
if (activeOperation) {
|
|
891
|
+
const loadReject = this.activeLoadReject;
|
|
892
|
+
const loadCleanup = this.activeLoadCleanup;
|
|
893
|
+
const reject = this.activeReject;
|
|
894
|
+
const cleanup = this.activeRunCleanup;
|
|
895
|
+
const writer = this.stdinWriter;
|
|
896
|
+
const instance = this.instance;
|
|
897
|
+
const outputController = this.outputController;
|
|
898
|
+
activeOperation.cancelled = true;
|
|
899
|
+
activeOperation.cancellationReason = reason;
|
|
900
|
+
this.activeOperation = null;
|
|
901
|
+
this.activeLoadReject = null;
|
|
902
|
+
this.activeLoadCleanup = null;
|
|
903
|
+
this.activeReject = null;
|
|
904
|
+
this.activeRunCleanup = null;
|
|
905
|
+
this.loadGeneration += 1;
|
|
906
|
+
this.uid += 1;
|
|
907
|
+
this.stdinWriter = null;
|
|
908
|
+
this.instance = null;
|
|
909
|
+
this.outputController = null;
|
|
910
|
+
this.pendingInput = [];
|
|
911
|
+
this.pendingEof = false;
|
|
912
|
+
this.exit = true;
|
|
913
|
+
this.cleanupOperation(activeOperation);
|
|
914
|
+
loadCleanup?.();
|
|
915
|
+
cleanup?.();
|
|
916
|
+
loadReject?.(reason);
|
|
917
|
+
reject?.(reason);
|
|
918
|
+
this.abortOperationSignal(activeOperation, reason);
|
|
919
|
+
this.disposeRunHandles(instance, writer, outputController, reason);
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
const loadReject = this.activeLoadReject;
|
|
923
|
+
const loadCleanup = this.activeLoadCleanup;
|
|
924
|
+
const reject = this.activeReject;
|
|
925
|
+
const cleanup = this.activeRunCleanup;
|
|
926
|
+
const writer = this.stdinWriter;
|
|
927
|
+
const instance = this.instance;
|
|
928
|
+
const outputController = this.outputController;
|
|
929
|
+
this.activeLoadReject = null;
|
|
930
|
+
this.activeLoadCleanup = null;
|
|
931
|
+
this.activeReject = null;
|
|
932
|
+
this.activeRunCleanup = null;
|
|
933
|
+
this.loadGeneration += 1;
|
|
934
|
+
this.uid += 1;
|
|
935
|
+
this.stdinWriter = null;
|
|
936
|
+
this.instance = null;
|
|
937
|
+
this.outputController = null;
|
|
938
|
+
this.pendingInput = [];
|
|
939
|
+
this.pendingEof = false;
|
|
940
|
+
this.exit = true;
|
|
941
|
+
loadCleanup?.();
|
|
942
|
+
cleanup?.();
|
|
943
|
+
loadReject?.(reason);
|
|
944
|
+
reject?.(reason);
|
|
945
|
+
this.disposeRunHandles(instance, writer, outputController, reason);
|
|
946
|
+
}
|
|
947
|
+
async clear() {
|
|
948
|
+
this.terminate();
|
|
949
|
+
const runtimePackage = this.runtimePackage;
|
|
950
|
+
const sdkRuntime = this.sdkRuntime;
|
|
951
|
+
const urls = [this.nestedWorkerBlobUrl, this.sdkBlobUrl];
|
|
952
|
+
this.runtimePackage = null;
|
|
953
|
+
this.sdkRuntime = null;
|
|
954
|
+
this.sdkModule = null;
|
|
955
|
+
this.nestedWorkerBlobUrl = '';
|
|
956
|
+
this.sdkBlobUrl = '';
|
|
957
|
+
this.webcUrl = '';
|
|
958
|
+
try {
|
|
959
|
+
runtimePackage?.free();
|
|
960
|
+
}
|
|
961
|
+
catch {
|
|
962
|
+
// The sandbox is cleared even when the SDK cleanup hook fails.
|
|
963
|
+
}
|
|
964
|
+
try {
|
|
965
|
+
sdkRuntime?.free?.();
|
|
966
|
+
}
|
|
967
|
+
catch {
|
|
968
|
+
// The sandbox is cleared even when the isolated runtime cleanup fails.
|
|
969
|
+
}
|
|
970
|
+
for (const url of urls) {
|
|
971
|
+
if (!url)
|
|
972
|
+
continue;
|
|
973
|
+
try {
|
|
974
|
+
URL.revokeObjectURL(url);
|
|
975
|
+
}
|
|
976
|
+
catch {
|
|
977
|
+
// Blob URL cleanup is best effort during realm teardown.
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
export default BashWorkerRuntime;
|