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,630 @@
|
|
|
1
|
+
import { BusyError, CancelledError, DEFAULT_WORKSPACE_LIMITS, DiagnosticLimitError, OutputLimitError, RuntimeConfigurationError, TimeoutError, resolveExecutionLimits, validateExecutionWorkspace } from '@wasm-idle/core';
|
|
2
|
+
import { resolveAssemblyScriptRuntimeModuleUrl } from './assets';
|
|
3
|
+
import { flushBufferedEof, flushQueuedStdin, resetBufferedStdin } from './stdinBuffer';
|
|
4
|
+
import { createWasmIdleSharedBuffer } from './sharedBuffer';
|
|
5
|
+
import { WorkerSession } from './workerSession';
|
|
6
|
+
import { reportWorkerInputReady, reportWorkerProgress } from './workerProgress';
|
|
7
|
+
const OUTPUT_ENCODER = new TextEncoder();
|
|
8
|
+
const abortReason = (signal, phase) => signal.reason !== undefined
|
|
9
|
+
? signal.reason
|
|
10
|
+
: new DOMException(phase === 'startup'
|
|
11
|
+
? 'AssemblyScript runtime startup aborted'
|
|
12
|
+
: 'AssemblyScript execution aborted', 'AbortError');
|
|
13
|
+
class AssemblyScriptSandbox {
|
|
14
|
+
output = null;
|
|
15
|
+
worker = null;
|
|
16
|
+
buffer = createWasmIdleSharedBuffer(4096);
|
|
17
|
+
pendingInput = [];
|
|
18
|
+
begin = 0;
|
|
19
|
+
elapse = 0;
|
|
20
|
+
uid = 0;
|
|
21
|
+
exit = true;
|
|
22
|
+
moduleUrl = '';
|
|
23
|
+
oncompilerdiagnostic;
|
|
24
|
+
waitingForInput = false;
|
|
25
|
+
pendingEof = false;
|
|
26
|
+
activeOperation = null;
|
|
27
|
+
disposed = false;
|
|
28
|
+
disposePromise = null;
|
|
29
|
+
disposeCancellation = new CancelledError('AssemblyScript sandbox disposed', {
|
|
30
|
+
phase: 'dispose',
|
|
31
|
+
runtimeId: 'ASSEMBLYSCRIPT',
|
|
32
|
+
recoverable: false
|
|
33
|
+
});
|
|
34
|
+
workerSession = new WorkerSession({
|
|
35
|
+
label: 'AssemblyScript',
|
|
36
|
+
onDispose: (worker) => {
|
|
37
|
+
if (this.worker === worker)
|
|
38
|
+
delete this.worker;
|
|
39
|
+
this.exit = true;
|
|
40
|
+
this.waitingForInput = false;
|
|
41
|
+
this.pendingEof = false;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
load(runtimeAssets = '', _code = '', _log = true, _args = [], options = {}, progress) {
|
|
45
|
+
let operation;
|
|
46
|
+
try {
|
|
47
|
+
operation = this.beginOperation('startup');
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return Promise.reject(error);
|
|
51
|
+
}
|
|
52
|
+
let signal;
|
|
53
|
+
let limits;
|
|
54
|
+
let unbindPreSessionAbort = () => undefined;
|
|
55
|
+
try {
|
|
56
|
+
signal = options.signal;
|
|
57
|
+
unbindPreSessionAbort = this.bindPreSessionAbort(operation, signal);
|
|
58
|
+
if (!this.isOperationActive(operation) || signal?.aborted) {
|
|
59
|
+
return Promise.reject(this.releaseBeforeSession(operation, 'AssemblyScript runtime startup cancelled'));
|
|
60
|
+
}
|
|
61
|
+
limits = resolveExecutionLimits(options.limits);
|
|
62
|
+
if (!this.isOperationActive(operation) || signal?.aborted) {
|
|
63
|
+
return Promise.reject(this.releaseBeforeSession(operation, 'AssemblyScript runtime startup cancelled'));
|
|
64
|
+
}
|
|
65
|
+
unbindPreSessionAbort();
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
return Promise.reject(this.releaseBeforeSession(operation, error));
|
|
69
|
+
}
|
|
70
|
+
if (!this.isOperationActive(operation)) {
|
|
71
|
+
return Promise.reject(this.releaseBeforeSession(operation, 'AssemblyScript runtime startup cancelled'));
|
|
72
|
+
}
|
|
73
|
+
const loading = this.workerSession.load(async (resolve, reject) => {
|
|
74
|
+
if (!this.isOperationActive(operation))
|
|
75
|
+
return;
|
|
76
|
+
this.pendingInput = [];
|
|
77
|
+
this.waitingForInput = false;
|
|
78
|
+
this.pendingEof = false;
|
|
79
|
+
const currentUrl = typeof window !== 'undefined' ? window.location.href : '';
|
|
80
|
+
const nextModuleUrl = resolveAssemblyScriptRuntimeModuleUrl(runtimeAssets, currentUrl);
|
|
81
|
+
if (!this.isOperationActive(operation))
|
|
82
|
+
return;
|
|
83
|
+
const needsWorkerReset = Boolean(this.worker && this.moduleUrl !== nextModuleUrl);
|
|
84
|
+
this.moduleUrl = nextModuleUrl;
|
|
85
|
+
if (needsWorkerReset) {
|
|
86
|
+
this.workerSession.reset();
|
|
87
|
+
if (!this.isOperationActive(operation))
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!this.worker) {
|
|
91
|
+
const WorkerConstructor = (await import('./worker/assemblyscript?worker')).default;
|
|
92
|
+
if (!this.isOperationActive(operation))
|
|
93
|
+
return;
|
|
94
|
+
const worker = new WorkerConstructor();
|
|
95
|
+
if (!this.isOperationActive(operation)) {
|
|
96
|
+
worker.terminate();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.worker = worker;
|
|
100
|
+
this.workerSession.attach(worker);
|
|
101
|
+
let handler;
|
|
102
|
+
const ownsLoad = () => this.isOperationActive(operation) &&
|
|
103
|
+
this.worker === worker &&
|
|
104
|
+
worker.onmessage === handler;
|
|
105
|
+
const failLoad = (reason) => {
|
|
106
|
+
if (!ownsLoad())
|
|
107
|
+
return;
|
|
108
|
+
this.releaseOperation(operation);
|
|
109
|
+
reject(reason);
|
|
110
|
+
this.cleanupOperation(operation);
|
|
111
|
+
};
|
|
112
|
+
handler = (event) => {
|
|
113
|
+
if (!ownsLoad())
|
|
114
|
+
return;
|
|
115
|
+
try {
|
|
116
|
+
if (event.data?.load) {
|
|
117
|
+
progress?.set?.(1);
|
|
118
|
+
if (!ownsLoad())
|
|
119
|
+
return;
|
|
120
|
+
this.releaseOperation(operation);
|
|
121
|
+
resolve();
|
|
122
|
+
this.cleanupOperation(operation);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (event.data?.error !== undefined)
|
|
126
|
+
failLoad(event.data.error);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
failLoad(error);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
worker.onmessage = handler;
|
|
133
|
+
worker.postMessage({
|
|
134
|
+
load: true,
|
|
135
|
+
moduleUrl: this.moduleUrl,
|
|
136
|
+
log: _log
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
try {
|
|
141
|
+
progress?.set?.(1);
|
|
142
|
+
if (!this.isOperationActive(operation))
|
|
143
|
+
return;
|
|
144
|
+
this.releaseOperation(operation);
|
|
145
|
+
resolve();
|
|
146
|
+
this.cleanupOperation(operation);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (!this.isOperationActive(operation))
|
|
150
|
+
return;
|
|
151
|
+
this.releaseOperation(operation);
|
|
152
|
+
reject(error);
|
|
153
|
+
this.cleanupOperation(operation);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const timeoutMs = Math.min(2_147_483_647, limits.assetTimeoutMs + limits.startupTimeoutMs);
|
|
158
|
+
this.bindOperationTimeout(operation, timeoutMs);
|
|
159
|
+
this.bindAbortSignal(operation, signal);
|
|
160
|
+
return loading.finally(() => {
|
|
161
|
+
this.releaseOperation(operation);
|
|
162
|
+
this.cleanupOperation(operation);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
beginOperation(phase) {
|
|
166
|
+
if (this.disposed) {
|
|
167
|
+
throw new RuntimeConfigurationError('AssemblyScript sandbox is disposed', {
|
|
168
|
+
phase: 'dispose',
|
|
169
|
+
runtimeId: 'ASSEMBLYSCRIPT'
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (this.activeOperation) {
|
|
173
|
+
throw new BusyError('AssemblyScript runtime already has an active operation', {
|
|
174
|
+
runtimeId: 'ASSEMBLYSCRIPT',
|
|
175
|
+
phase: this.activeOperation.phase
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
const operation = {
|
|
179
|
+
token: Symbol(phase),
|
|
180
|
+
phase,
|
|
181
|
+
cancelled: false,
|
|
182
|
+
cleanedUp: false,
|
|
183
|
+
cleanups: []
|
|
184
|
+
};
|
|
185
|
+
this.activeOperation = operation;
|
|
186
|
+
return operation;
|
|
187
|
+
}
|
|
188
|
+
releaseOperation(operation) {
|
|
189
|
+
if (this.activeOperation?.token !== operation.token)
|
|
190
|
+
return false;
|
|
191
|
+
this.activeOperation = null;
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
isOperationActive(operation) {
|
|
195
|
+
return this.activeOperation?.token === operation.token && !operation.cancelled;
|
|
196
|
+
}
|
|
197
|
+
cleanupOperation(operation) {
|
|
198
|
+
if (operation.cleanedUp)
|
|
199
|
+
return;
|
|
200
|
+
operation.cleanedUp = true;
|
|
201
|
+
const cleanups = operation.cleanups.splice(0);
|
|
202
|
+
for (const cleanup of cleanups) {
|
|
203
|
+
try {
|
|
204
|
+
cleanup();
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
// Caller-owned lifecycle cleanup must not replace the operation result.
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
releaseBeforeSession(operation, reason) {
|
|
212
|
+
const outcome = operation.cancelled ? operation.cancellationReason : reason;
|
|
213
|
+
this.releaseOperation(operation);
|
|
214
|
+
this.cleanupOperation(operation);
|
|
215
|
+
return outcome;
|
|
216
|
+
}
|
|
217
|
+
bindPreSessionAbort(operation, signal) {
|
|
218
|
+
if (!signal || !this.isOperationActive(operation))
|
|
219
|
+
return () => undefined;
|
|
220
|
+
let registered = false;
|
|
221
|
+
let unbound = false;
|
|
222
|
+
const unbind = () => {
|
|
223
|
+
if (unbound)
|
|
224
|
+
return;
|
|
225
|
+
unbound = true;
|
|
226
|
+
if (registered)
|
|
227
|
+
signal.removeEventListener('abort', onAbort);
|
|
228
|
+
};
|
|
229
|
+
const onAbort = () => {
|
|
230
|
+
if (!this.isOperationActive(operation))
|
|
231
|
+
return;
|
|
232
|
+
let reason;
|
|
233
|
+
try {
|
|
234
|
+
reason = abortReason(signal, operation.phase);
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
reason = error;
|
|
238
|
+
}
|
|
239
|
+
operation.cancelled = true;
|
|
240
|
+
operation.cancellationReason = reason;
|
|
241
|
+
this.releaseOperation(operation);
|
|
242
|
+
this.cleanupOperation(operation);
|
|
243
|
+
};
|
|
244
|
+
operation.cleanups.push(unbind);
|
|
245
|
+
try {
|
|
246
|
+
registered = true;
|
|
247
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
248
|
+
if (signal.aborted)
|
|
249
|
+
onAbort();
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if (this.isOperationActive(operation)) {
|
|
253
|
+
operation.cancelled = true;
|
|
254
|
+
operation.cancellationReason = error;
|
|
255
|
+
this.releaseOperation(operation);
|
|
256
|
+
this.cleanupOperation(operation);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return unbind;
|
|
260
|
+
}
|
|
261
|
+
bindAbortSignal(operation, signal) {
|
|
262
|
+
if (!signal || !this.isOperationActive(operation))
|
|
263
|
+
return;
|
|
264
|
+
let registered = false;
|
|
265
|
+
const onAbort = () => {
|
|
266
|
+
if (!this.isOperationActive(operation))
|
|
267
|
+
return;
|
|
268
|
+
let reason;
|
|
269
|
+
try {
|
|
270
|
+
reason = abortReason(signal, operation.phase);
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
reason = error;
|
|
274
|
+
}
|
|
275
|
+
this.cancelOperation(operation, reason);
|
|
276
|
+
};
|
|
277
|
+
operation.cleanups.push(() => {
|
|
278
|
+
if (registered)
|
|
279
|
+
signal.removeEventListener('abort', onAbort);
|
|
280
|
+
});
|
|
281
|
+
try {
|
|
282
|
+
registered = true;
|
|
283
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
284
|
+
if (signal.aborted)
|
|
285
|
+
onAbort();
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
this.cancelOperation(operation, error);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
bindOperationTimeout(operation, timeoutMs) {
|
|
292
|
+
if (!this.isOperationActive(operation))
|
|
293
|
+
return;
|
|
294
|
+
let timeout;
|
|
295
|
+
operation.cleanups.push(() => {
|
|
296
|
+
if (timeout !== undefined)
|
|
297
|
+
clearTimeout(timeout);
|
|
298
|
+
});
|
|
299
|
+
try {
|
|
300
|
+
timeout = setTimeout(() => {
|
|
301
|
+
if (!this.isOperationActive(operation))
|
|
302
|
+
return;
|
|
303
|
+
const label = operation.phase === 'startup' ? 'startup' : 'execution';
|
|
304
|
+
this.cancelOperation(operation, new TimeoutError(`AssemblyScript ${label} timed out after ${timeoutMs} ms`, {
|
|
305
|
+
phase: operation.phase,
|
|
306
|
+
runtimeId: 'ASSEMBLYSCRIPT',
|
|
307
|
+
timeoutMs
|
|
308
|
+
}));
|
|
309
|
+
}, timeoutMs);
|
|
310
|
+
if (operation.cleanedUp)
|
|
311
|
+
clearTimeout(timeout);
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
this.cancelOperation(operation, error);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
write(input) {
|
|
318
|
+
if (this.disposed)
|
|
319
|
+
return;
|
|
320
|
+
this.pendingInput.push(input);
|
|
321
|
+
this.pendingEof = false;
|
|
322
|
+
this.flushPendingInput();
|
|
323
|
+
}
|
|
324
|
+
eof() {
|
|
325
|
+
if (this.disposed)
|
|
326
|
+
return;
|
|
327
|
+
this.pendingEof = true;
|
|
328
|
+
this.flushPendingInput();
|
|
329
|
+
}
|
|
330
|
+
flushPendingInput() {
|
|
331
|
+
if (!this.waitingForInput)
|
|
332
|
+
return;
|
|
333
|
+
if (flushQueuedStdin(this.pendingInput, this.buffer)) {
|
|
334
|
+
this.waitingForInput = false;
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (this.pendingEof) {
|
|
338
|
+
flushBufferedEof(this.buffer);
|
|
339
|
+
this.pendingEof = false;
|
|
340
|
+
this.waitingForInput = false;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
run(code, prepare, _log = true, _prog, _args = [], options = {}) {
|
|
344
|
+
let activeOperation;
|
|
345
|
+
try {
|
|
346
|
+
activeOperation = this.beginOperation('execute');
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
349
|
+
return Promise.reject(error);
|
|
350
|
+
}
|
|
351
|
+
let signal;
|
|
352
|
+
let unbindPreSessionAbort = () => undefined;
|
|
353
|
+
let worker;
|
|
354
|
+
let limits;
|
|
355
|
+
let workspace;
|
|
356
|
+
let stdin;
|
|
357
|
+
try {
|
|
358
|
+
signal = options.signal;
|
|
359
|
+
unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
|
|
360
|
+
if (!this.isOperationActive(activeOperation)) {
|
|
361
|
+
return Promise.reject(this.releaseBeforeSession(activeOperation, 'AssemblyScript execution cancelled'));
|
|
362
|
+
}
|
|
363
|
+
if (!this.worker) {
|
|
364
|
+
return Promise.reject(this.releaseBeforeSession(activeOperation, 'Worker not loaded'));
|
|
365
|
+
}
|
|
366
|
+
worker = this.worker;
|
|
367
|
+
limits = resolveExecutionLimits(options.limits);
|
|
368
|
+
workspace = validateExecutionWorkspace(code, options.workspaceFiles ?? [], options.activePath ?? 'main.as.ts', {
|
|
369
|
+
...options.workspaceLimits,
|
|
370
|
+
maxFileBytes: Math.min(options.workspaceLimits?.maxFileBytes ??
|
|
371
|
+
DEFAULT_WORKSPACE_LIMITS.maxFileBytes, limits.maxWorkspaceBytes),
|
|
372
|
+
maxTotalBytes: Math.min(options.workspaceLimits?.maxTotalBytes ??
|
|
373
|
+
DEFAULT_WORKSPACE_LIMITS.maxTotalBytes, limits.maxWorkspaceBytes)
|
|
374
|
+
});
|
|
375
|
+
stdin = options.stdin;
|
|
376
|
+
if (!this.isOperationActive(activeOperation) || signal?.aborted) {
|
|
377
|
+
return Promise.reject(this.releaseBeforeSession(activeOperation, 'AssemblyScript execution cancelled'));
|
|
378
|
+
}
|
|
379
|
+
unbindPreSessionAbort();
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
return Promise.reject(this.releaseBeforeSession(activeOperation, error));
|
|
383
|
+
}
|
|
384
|
+
if (!this.isOperationActive(activeOperation)) {
|
|
385
|
+
return Promise.reject(this.releaseBeforeSession(activeOperation, 'AssemblyScript execution cancelled'));
|
|
386
|
+
}
|
|
387
|
+
const hasExplicitStdin = stdin !== undefined;
|
|
388
|
+
if (hasExplicitStdin) {
|
|
389
|
+
this.pendingInput = [];
|
|
390
|
+
this.pendingEof = false;
|
|
391
|
+
this.waitingForInput = false;
|
|
392
|
+
try {
|
|
393
|
+
resetBufferedStdin(this.buffer);
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
// Explicit stdin does not consume the shared terminal buffer.
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
let explicitStdinCleaned = false;
|
|
400
|
+
const cleanupExplicitStdin = () => {
|
|
401
|
+
if (!hasExplicitStdin || explicitStdinCleaned)
|
|
402
|
+
return;
|
|
403
|
+
explicitStdinCleaned = true;
|
|
404
|
+
this.pendingInput = [];
|
|
405
|
+
this.pendingEof = false;
|
|
406
|
+
this.waitingForInput = false;
|
|
407
|
+
try {
|
|
408
|
+
resetBufferedStdin(this.buffer);
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
// Stdin cleanup must not replace the execution result.
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
this.exit = false;
|
|
415
|
+
const running = new Promise((resolve, reject) => {
|
|
416
|
+
const _uid = ++this.uid;
|
|
417
|
+
let diagnosticCount = 0;
|
|
418
|
+
let outputBytes = 0;
|
|
419
|
+
const workerOperation = this.workerSession.beginRun(worker, reject);
|
|
420
|
+
const timeoutMs = Math.min(2_147_483_647, limits.compileTimeoutMs + limits.runTimeoutMs);
|
|
421
|
+
this.bindOperationTimeout(activeOperation, timeoutMs);
|
|
422
|
+
this.bindAbortSignal(activeOperation, signal);
|
|
423
|
+
if (!this.isOperationActive(activeOperation))
|
|
424
|
+
return;
|
|
425
|
+
let handler;
|
|
426
|
+
const ownsRun = () => this.isOperationActive(activeOperation) &&
|
|
427
|
+
this.worker === worker &&
|
|
428
|
+
worker.onmessage === handler &&
|
|
429
|
+
_uid === this.uid;
|
|
430
|
+
const claimRun = () => {
|
|
431
|
+
if (!ownsRun())
|
|
432
|
+
return false;
|
|
433
|
+
cleanupExplicitStdin();
|
|
434
|
+
this.elapse = Date.now() - this.begin;
|
|
435
|
+
this.exit = true;
|
|
436
|
+
this.waitingForInput = false;
|
|
437
|
+
this.pendingEof = false;
|
|
438
|
+
this.workerSession.complete(workerOperation);
|
|
439
|
+
this.releaseOperation(activeOperation);
|
|
440
|
+
this.cleanupOperation(activeOperation);
|
|
441
|
+
try {
|
|
442
|
+
if (worker.onmessage === handler)
|
|
443
|
+
worker.onmessage = null;
|
|
444
|
+
}
|
|
445
|
+
catch {
|
|
446
|
+
// Handler cleanup must not replace or defer the execution result.
|
|
447
|
+
}
|
|
448
|
+
return true;
|
|
449
|
+
};
|
|
450
|
+
const failRun = (reason, disposeWorker = false) => {
|
|
451
|
+
if (disposeWorker) {
|
|
452
|
+
if (!ownsRun())
|
|
453
|
+
return;
|
|
454
|
+
this.cancelOperation(activeOperation, reason);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (!claimRun())
|
|
458
|
+
return;
|
|
459
|
+
reject(reason);
|
|
460
|
+
};
|
|
461
|
+
handler = (event) => {
|
|
462
|
+
if (!ownsRun())
|
|
463
|
+
return;
|
|
464
|
+
try {
|
|
465
|
+
const { output, results, error, buffer, diagnostic, progress } = event.data;
|
|
466
|
+
if (buffer && !hasExplicitStdin) {
|
|
467
|
+
this.waitingForInput = true;
|
|
468
|
+
if (!prepare) {
|
|
469
|
+
reportWorkerInputReady(_prog, 'AssemblyScript runtime ready for input');
|
|
470
|
+
if (!ownsRun())
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
this.flushPendingInput();
|
|
474
|
+
if (!ownsRun())
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
reportWorkerProgress(_prog, progress);
|
|
478
|
+
if (!ownsRun())
|
|
479
|
+
return;
|
|
480
|
+
if (output) {
|
|
481
|
+
const actual = outputBytes + OUTPUT_ENCODER.encode(String(output)).byteLength;
|
|
482
|
+
if (actual > limits.maxOutputBytes) {
|
|
483
|
+
failRun(new OutputLimitError(`AssemblyScript output exceeded ${limits.maxOutputBytes} bytes`, {
|
|
484
|
+
actual,
|
|
485
|
+
limit: limits.maxOutputBytes,
|
|
486
|
+
phase: 'execute',
|
|
487
|
+
runtimeId: 'ASSEMBLYSCRIPT'
|
|
488
|
+
}), true);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
outputBytes = actual;
|
|
492
|
+
this.output?.(output);
|
|
493
|
+
if (!ownsRun())
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (diagnostic !== undefined) {
|
|
497
|
+
const actual = diagnosticCount + 1;
|
|
498
|
+
if (actual > limits.maxDiagnostics) {
|
|
499
|
+
failRun(new DiagnosticLimitError(`AssemblyScript diagnostics exceeded ${limits.maxDiagnostics} messages`, {
|
|
500
|
+
actual,
|
|
501
|
+
limit: limits.maxDiagnostics,
|
|
502
|
+
phase: 'execute',
|
|
503
|
+
runtimeId: 'ASSEMBLYSCRIPT'
|
|
504
|
+
}), true);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
diagnosticCount = actual;
|
|
508
|
+
this.oncompilerdiagnostic?.(diagnostic);
|
|
509
|
+
if (!ownsRun())
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (results !== undefined) {
|
|
513
|
+
if (!claimRun())
|
|
514
|
+
return;
|
|
515
|
+
resolve(results);
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
if (error !== undefined)
|
|
519
|
+
failRun(error);
|
|
520
|
+
}
|
|
521
|
+
catch (error) {
|
|
522
|
+
failRun(error, true);
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
worker.onmessage = handler;
|
|
526
|
+
this.begin = Date.now();
|
|
527
|
+
if (!this.isOperationActive(activeOperation))
|
|
528
|
+
return;
|
|
529
|
+
try {
|
|
530
|
+
worker.postMessage({
|
|
531
|
+
code,
|
|
532
|
+
prepare,
|
|
533
|
+
buffer: this.buffer,
|
|
534
|
+
stdin,
|
|
535
|
+
activePath: workspace.activePath,
|
|
536
|
+
workspaceFiles: workspace.workspaceFiles,
|
|
537
|
+
log: _log
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
failRun(error);
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
return running.finally(() => {
|
|
545
|
+
if (this.releaseOperation(activeOperation))
|
|
546
|
+
cleanupExplicitStdin();
|
|
547
|
+
this.cleanupOperation(activeOperation);
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
cancelOperation(operation, reason) {
|
|
551
|
+
if (!this.isOperationActive(operation))
|
|
552
|
+
return;
|
|
553
|
+
operation.cancelled = true;
|
|
554
|
+
operation.cancellationReason = reason;
|
|
555
|
+
this.activeOperation = null;
|
|
556
|
+
this.uid += 1;
|
|
557
|
+
this.pendingInput = [];
|
|
558
|
+
this.waitingForInput = false;
|
|
559
|
+
this.pendingEof = false;
|
|
560
|
+
this.exit = true;
|
|
561
|
+
try {
|
|
562
|
+
resetBufferedStdin(this.buffer);
|
|
563
|
+
}
|
|
564
|
+
catch {
|
|
565
|
+
// Stdin cleanup must not replace the cancellation reason.
|
|
566
|
+
}
|
|
567
|
+
this.workerSession.terminate(reason);
|
|
568
|
+
this.cleanupOperation(operation);
|
|
569
|
+
}
|
|
570
|
+
kill() {
|
|
571
|
+
this.terminate();
|
|
572
|
+
}
|
|
573
|
+
terminate(reason = 'Process terminated') {
|
|
574
|
+
if (this.disposed)
|
|
575
|
+
return;
|
|
576
|
+
const operation = this.activeOperation;
|
|
577
|
+
if (operation) {
|
|
578
|
+
this.cancelOperation(operation, reason);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
this.waitingForInput = false;
|
|
582
|
+
this.pendingEof = false;
|
|
583
|
+
this.uid += 1;
|
|
584
|
+
this.workerSession.terminate(reason);
|
|
585
|
+
this.exit = true;
|
|
586
|
+
}
|
|
587
|
+
async clear() {
|
|
588
|
+
if (this.disposed)
|
|
589
|
+
return;
|
|
590
|
+
this.pendingInput = [];
|
|
591
|
+
this.waitingForInput = false;
|
|
592
|
+
this.pendingEof = false;
|
|
593
|
+
if (this.worker)
|
|
594
|
+
this.worker.onmessage = null;
|
|
595
|
+
resetBufferedStdin(this.buffer);
|
|
596
|
+
if (this.activeOperation || !this.exit) {
|
|
597
|
+
this.terminate();
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
dispose() {
|
|
601
|
+
if (this.disposePromise)
|
|
602
|
+
return this.disposePromise;
|
|
603
|
+
this.disposed = true;
|
|
604
|
+
this.disposePromise = Promise.resolve();
|
|
605
|
+
const activeOperation = this.activeOperation;
|
|
606
|
+
delete this.worker;
|
|
607
|
+
this.moduleUrl = '';
|
|
608
|
+
this.output = null;
|
|
609
|
+
this.oncompilerdiagnostic = undefined;
|
|
610
|
+
this.pendingInput = [];
|
|
611
|
+
this.waitingForInput = false;
|
|
612
|
+
this.pendingEof = false;
|
|
613
|
+
try {
|
|
614
|
+
resetBufferedStdin(this.buffer);
|
|
615
|
+
}
|
|
616
|
+
catch {
|
|
617
|
+
// Terminal cleanup is best effort after host state becomes unreachable.
|
|
618
|
+
}
|
|
619
|
+
if (activeOperation) {
|
|
620
|
+
this.cancelOperation(activeOperation, this.disposeCancellation);
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
this.uid += 1;
|
|
624
|
+
this.workerSession.terminate(this.disposeCancellation);
|
|
625
|
+
this.exit = true;
|
|
626
|
+
}
|
|
627
|
+
return this.disposePromise;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
export default AssemblyScriptSandbox;
|
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
import { type ResolvedRuntimeAssetConfig, type RuntimeAssetRuntime } from './assets';
|
|
2
|
-
type ProgressLike
|
|
3
|
-
|
|
4
|
-
};
|
|
2
|
+
import { type ProgressLike } from '@wasm-idle/core';
|
|
3
|
+
export declare const boundedUtf8ByteLength: (value: string, maxBytes?: number) => number;
|
|
5
4
|
export declare class WorkerAssetBridge {
|
|
6
5
|
private worker;
|
|
7
6
|
private readonly runtime;
|
|
8
7
|
private config;
|
|
9
8
|
private readonly progress;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
private readonly expectedAssets;
|
|
10
|
+
private pythonPackageAssets;
|
|
11
|
+
private generation;
|
|
12
|
+
private state;
|
|
13
|
+
private readonly activeLoads;
|
|
14
|
+
private maxAssetBytes;
|
|
15
|
+
constructor(worker: Worker, runtime: RuntimeAssetRuntime, config: ResolvedRuntimeAssetConfig, progress?: ProgressLike, maxAssetBytes?: number);
|
|
16
|
+
matches(config: ResolvedRuntimeAssetConfig, maxAssetBytes?: number): boolean;
|
|
17
|
+
rebind(worker: Worker, config: ResolvedRuntimeAssetConfig, progress?: ProgressLike, maxAssetBytes?: number): void;
|
|
18
|
+
dispose(): void;
|
|
13
19
|
resetProgress(progress?: ProgressLike): void;
|
|
20
|
+
private configuredReceiptByteLimit;
|
|
21
|
+
private runtimeAssetByteLimit;
|
|
22
|
+
private sourceAssetByteLimit;
|
|
14
23
|
handleMessage(event: MessageEvent<any>): boolean;
|
|
15
24
|
private respond;
|
|
16
25
|
private loadAsset;
|
|
26
|
+
private verifyIntegrity;
|
|
17
27
|
private normalizeLoaderResult;
|
|
18
28
|
private fetchAsset;
|
|
29
|
+
private requireAllowedAssetUrl;
|
|
30
|
+
private abortActiveLoads;
|
|
19
31
|
}
|
|
20
|
-
export {};
|