wasm-idle 1.1.0 → 1.2.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 +267 -112
- package/dist/container/bash-profile.d.ts +80 -0
- package/dist/container/bash-profile.js +328 -0
- package/dist/container/binding.d.ts +39 -0
- package/dist/container/binding.js +331 -0
- package/dist/container/clang-runtime.d.ts +42 -0
- package/dist/container/clang-runtime.js +561 -0
- package/dist/container/client.d.ts +14 -0
- package/dist/container/client.js +185 -0
- package/dist/container/explorer.d.ts +31 -0
- package/dist/container/explorer.js +112 -0
- package/dist/container/index.d.ts +11 -0
- package/dist/container/index.js +11 -0
- package/dist/container/owner-worker.d.ts +19 -0
- package/dist/container/owner-worker.js +464 -0
- package/dist/container/protocol.d.ts +84 -0
- package/dist/container/protocol.js +28 -0
- package/dist/container/runtime-adapter.d.ts +75 -0
- package/dist/container/runtime-adapter.js +537 -0
- package/dist/container/shell-control.d.ts +49 -0
- package/dist/container/shell-control.js +360 -0
- package/dist/container/workspace.d.ts +12 -0
- package/dist/container/workspace.js +29 -0
- package/dist/index.d.ts +1 -1
- package/dist/playground/assetBridge.js +111 -33
- package/dist/playground/assets.d.ts +10 -2
- package/dist/playground/c3.js +22 -0
- package/dist/playground/c3Memory.d.ts +19 -0
- package/dist/playground/c3Memory.js +117 -0
- package/dist/playground/cachedClang.js +143 -34
- package/dist/playground/clang.d.ts +5 -1
- package/dist/playground/clang.js +61 -5
- package/dist/playground/clangAssetIntegrity.js +6 -6
- package/dist/playground/clangWorkerProtocol.d.ts +12 -1
- package/dist/playground/cobol.d.ts +3 -0
- package/dist/playground/cobol.js +10 -1
- package/dist/playground/commonlispAssets.d.ts +2 -2
- package/dist/playground/compiledArtifactCache.d.ts +3 -1
- package/dist/playground/compiledArtifactCache.js +31 -5
- package/dist/playground/compiledLldb.d.ts +41 -0
- package/dist/playground/compiledLldb.js +167 -0
- package/dist/playground/d.d.ts +10 -2
- package/dist/playground/d.js +161 -14
- package/dist/playground/debugDeadline.d.ts +12 -0
- package/dist/playground/debugDeadline.js +34 -0
- package/dist/playground/debugMailbox.d.ts +12 -0
- package/dist/playground/debugMailbox.js +77 -0
- package/dist/playground/dotnet.js +6 -8
- package/dist/playground/fortran.d.ts +3 -0
- package/dist/playground/fortran.js +10 -1
- package/dist/playground/go.js +23 -7
- package/dist/playground/goDebugInstrumentation.js +207 -97
- package/dist/playground/java-debug-FMHDKUN6.js +124 -0
- package/dist/playground/java-debug-notices.txt +492 -0
- package/dist/playground/java.d.ts +17 -1
- package/dist/playground/java.js +162 -5
- package/dist/playground/javaDebug.d.ts +62 -0
- package/dist/playground/javaDebug.js +305 -0
- package/dist/playground/javaDebugBridge.d.ts +6 -0
- package/dist/playground/javaDebugBridge.js +250 -0
- package/dist/playground/javaDebugSource.d.ts +9 -0
- package/dist/playground/javaDebugSource.js +4 -0
- package/dist/playground/javaRuntimeErrors.d.ts +9 -0
- package/dist/playground/javaRuntimeErrors.js +93 -0
- package/dist/playground/lean4Assets.d.ts +1 -25
- package/dist/playground/lean4Assets.js +2 -123
- package/dist/playground/lfortran.js +10 -0
- package/dist/playground/lfortranAssets.d.ts +2 -2
- package/dist/playground/lldbSession.d.ts +23 -2
- package/dist/playground/lldbSession.js +278 -58
- package/dist/playground/lldbSourcePath.d.ts +2 -0
- package/dist/playground/lldbSourcePath.js +9 -0
- package/dist/playground/lua.d.ts +20 -1
- package/dist/playground/lua.js +190 -8
- package/dist/playground/luaDebug.d.ts +1 -0
- package/dist/playground/luaDebug.js +1 -0
- package/dist/playground/nim.d.ts +1 -0
- package/dist/playground/nim.js +30 -0
- package/dist/playground/objectivec.d.ts +10 -6
- package/dist/playground/objectivec.js +85 -10
- package/dist/playground/options.d.ts +12 -4
- package/dist/playground/python.d.ts +8 -1
- package/dist/playground/python.js +89 -6
- package/dist/playground/ruby.d.ts +10 -1
- package/dist/playground/ruby.js +66 -1
- package/dist/playground/rubyDebug.d.ts +21 -0
- package/dist/playground/rubyDebug.js +128 -0
- package/dist/playground/runtimeAssetCache.d.ts +1 -32
- package/dist/playground/runtimeAssetCache.js +1 -193
- package/dist/playground/runtimeSession.d.ts +2 -2
- package/dist/playground/runtimeSession.js +11 -11
- package/dist/playground/rust.d.ts +10 -0
- package/dist/playground/rust.js +230 -51
- package/dist/playground/sandbox.d.ts +8 -1
- package/dist/playground/staticStdinRing.d.ts +2 -1
- package/dist/playground/staticStdinRing.js +21 -10
- package/dist/playground/staticWorkerRuntime.d.ts +15 -1
- package/dist/playground/staticWorkerRuntime.js +127 -19
- package/dist/playground/stdinBuffer.d.ts +1 -1
- package/dist/playground/stdinBuffer.js +19 -2
- package/dist/playground/tinygo.d.ts +3 -0
- package/dist/playground/tinygo.js +88 -6
- package/dist/playground/typescript.js +8 -0
- package/dist/playground/v.d.ts +6 -2
- package/dist/playground/v.js +76 -13
- package/dist/playground/wasmAwkVersion.d.ts +13 -13
- package/dist/playground/wasmAwkVersion.js +4 -4
- package/dist/playground/wasmBqnVersion.d.ts +2 -2
- package/dist/playground/wasmBqnVersion.js +2 -2
- package/dist/playground/wasmC3Version.d.ts +2 -2
- package/dist/playground/wasmC3Version.js +2 -2
- package/dist/playground/wasmClojureScriptVersion.d.ts +2 -2
- package/dist/playground/wasmClojureScriptVersion.js +2 -2
- package/dist/playground/wasmCommonLispVersion.d.ts +2 -2
- package/dist/playground/wasmCommonLispVersion.js +2 -2
- package/dist/playground/wasmDIntegrity.d.ts +5 -5
- package/dist/playground/wasmDIntegrity.js +5 -5
- package/dist/playground/wasmDVersion.d.ts +16 -1
- package/dist/playground/wasmDVersion.js +16 -1
- package/dist/playground/wasmDebugVersion.d.ts +1 -1
- package/dist/playground/wasmDebugVersion.js +1 -1
- package/dist/playground/wasmForthVersion.d.ts +2 -2
- package/dist/playground/wasmForthVersion.js +2 -2
- package/dist/playground/wasmGleamVersion.d.ts +2 -2
- package/dist/playground/wasmGleamVersion.js +2 -2
- package/dist/playground/wasmGrainVersion.d.ts +2 -2
- package/dist/playground/wasmGrainVersion.js +2 -2
- package/dist/playground/wasmJVersion.d.ts +2 -2
- package/dist/playground/wasmJVersion.js +2 -2
- package/dist/playground/wasmJanetVersion.js +2 -2
- package/dist/playground/wasmJuliaVersion.js +2 -2
- package/dist/playground/wasmLean4Version.d.ts +1 -110
- package/dist/playground/wasmLean4Version.js +2 -111
- package/dist/playground/wasmLfortranVersion.d.ts +2 -2
- package/dist/playground/wasmLfortranVersion.js +2 -2
- package/dist/playground/wasmLuaVersion.d.ts +1 -1
- package/dist/playground/wasmLuaVersion.js +1 -1
- package/dist/playground/wasmNimVersion.d.ts +9 -9
- package/dist/playground/wasmNimVersion.js +6 -6
- package/dist/playground/wasmOcamlVersion.d.ts +2 -2
- package/dist/playground/wasmOcamlVersion.js +1 -1
- package/dist/playground/wasmPascalVersion.js +2 -2
- package/dist/playground/wasmPerlVersion.js +2 -2
- package/dist/playground/wasmPrologVersion.d.ts +2 -2
- package/dist/playground/wasmPrologVersion.js +2 -2
- package/dist/playground/wasmReScriptVersion.d.ts +2 -2
- package/dist/playground/wasmReScriptVersion.js +2 -2
- package/dist/playground/wasmRustVersion.d.ts +26 -38
- package/dist/playground/wasmRustVersion.js +25 -40
- package/dist/playground/wasmTclVersion.d.ts +4 -4
- package/dist/playground/wasmTclVersion.js +2 -2
- package/dist/playground/wasmTinyGoVersion.d.ts +14 -14
- package/dist/playground/wasmTinyGoVersion.js +14 -14
- package/dist/playground/wasmTypeScriptVersion.d.ts +5 -5
- package/dist/playground/wasmTypeScriptVersion.js +5 -5
- package/dist/playground/worker/cachedClangCompile.js +52 -4
- package/dist/playground/worker/cachedClangExecute.js +6 -5
- package/dist/playground/worker/clang.js +33 -11
- package/dist/playground/worker/cobol.js +3 -3
- package/dist/playground/worker/d.js +63 -7
- package/dist/playground/worker/fortran.js +3 -3
- package/dist/playground/worker/go.js +16 -5
- package/dist/playground/worker/haskell.js +10 -7
- package/dist/playground/worker/java.js +263 -45
- package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
- package/dist/playground/worker/javaDebugEvaluator.js +44 -0
- package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
- package/dist/playground/worker/javaDebugRuntime.js +315 -0
- package/dist/playground/worker/javaOutput.d.ts +11 -0
- package/dist/playground/worker/javaOutput.js +54 -0
- package/dist/playground/worker/lua.js +15 -3
- package/dist/playground/worker/php.js +15 -9
- package/dist/playground/worker/python.js +102 -30
- package/dist/playground/worker/pythonExecution.js +17 -1
- package/dist/playground/worker/pythonWorkspaceFiles.d.ts +6 -0
- package/dist/playground/worker/pythonWorkspaceFiles.js +26 -0
- package/dist/playground/worker/pythonWorkspaceImports.d.ts +4 -0
- package/dist/playground/worker/pythonWorkspaceImports.js +129 -0
- package/dist/playground/worker/r.js +13 -6
- package/dist/playground/worker/ruby.js +13 -0
- package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
- package/dist/playground/worker/rubyDebugPreview.js +80 -0
- package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
- package/dist/playground/worker/rubyTracepoint.js +162 -0
- package/dist/playground/worker/rust.js +38 -3
- package/dist/playground/worker/sqlite.js +4 -3
- package/dist/playground/worker/tinygo.js +11 -3
- package/dist/playground/worker/typescript.js +2 -3
- package/dist/playground/worker/v.js +32 -7
- package/dist/playground/worker/wat.js +2 -3
- package/dist/playground/worker/zig.js +20 -6
- package/dist/playground/workerSession.d.ts +1 -28
- package/dist/playground/workerSession.js +1 -164
- package/dist/playground/zig.js +4 -0
- package/package.json +66 -15
- package/dist/playground/worker/python.runtime.cases.d.ts +0 -1
- package/dist/playground/worker/python.runtime.cases.js +0 -374
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { createContainerWorkerClient } from './client.js';
|
|
2
|
+
const copyFiles = (files) => files.map((file) => ({
|
|
3
|
+
path: file.path,
|
|
4
|
+
content: typeof file.content === 'string' ? file.content : Uint8Array.from(file.content)
|
|
5
|
+
}));
|
|
6
|
+
const bytes = (content) => typeof content === 'string' ? new TextEncoder().encode(content) : content;
|
|
7
|
+
const equal = (left, right) => {
|
|
8
|
+
if (left === right)
|
|
9
|
+
return true;
|
|
10
|
+
const a = bytes(left), b = bytes(right);
|
|
11
|
+
return a.length === b.length && a.every((byte, index) => byte === b[index]);
|
|
12
|
+
};
|
|
13
|
+
/** Existing Terminal/Debug controls use this facade; every execution belongs to the owner Container. */
|
|
14
|
+
export function createContainerPlaygroundBinding(runtimeAssets, options) {
|
|
15
|
+
if (!options.workerFactory && !options.clientFactory)
|
|
16
|
+
throw new TypeError('A container owner workerFactory is required');
|
|
17
|
+
let client, disposed = false;
|
|
18
|
+
const sandboxes = new Map();
|
|
19
|
+
const published = new Map();
|
|
20
|
+
const changes = new Set();
|
|
21
|
+
const queues = new Map();
|
|
22
|
+
const reads = new Map();
|
|
23
|
+
const readQueues = new Map();
|
|
24
|
+
let shellOutput;
|
|
25
|
+
let shellError;
|
|
26
|
+
let shellConnection;
|
|
27
|
+
let requestedShellLanguage;
|
|
28
|
+
let terminalExecution = false;
|
|
29
|
+
const decoders = new Map();
|
|
30
|
+
const decoder = (key) => {
|
|
31
|
+
let value = decoders.get(key);
|
|
32
|
+
if (!value)
|
|
33
|
+
decoders.set(key, (value = new TextDecoder()));
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
const connection = () => {
|
|
37
|
+
if (disposed)
|
|
38
|
+
throw new Error('Container playground has been disposed');
|
|
39
|
+
if (client)
|
|
40
|
+
return client;
|
|
41
|
+
client =
|
|
42
|
+
options.clientFactory?.() ??
|
|
43
|
+
createContainerWorkerClient({
|
|
44
|
+
runtimeAssets,
|
|
45
|
+
applicationRootURL: options.applicationRootURL,
|
|
46
|
+
workspaceId: options.workspaceId,
|
|
47
|
+
workerFactory: options.workerFactory
|
|
48
|
+
});
|
|
49
|
+
client.onEvent((event) => {
|
|
50
|
+
if (event.name === 'workspace') {
|
|
51
|
+
for (const listener of changes)
|
|
52
|
+
listener(event);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (event.name === 'shell-output') {
|
|
56
|
+
const data = event.data;
|
|
57
|
+
if (data.error)
|
|
58
|
+
shellError?.(new Error(data.error));
|
|
59
|
+
if (data.bytes)
|
|
60
|
+
shellOutput?.(decoder(`shell:${data.stream}`).decode(data.bytes, { stream: true }));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const sandbox = event.language && sandboxes.get(event.language);
|
|
64
|
+
if (!sandbox)
|
|
65
|
+
return;
|
|
66
|
+
if (event.name === 'output')
|
|
67
|
+
sandbox.output?.(typeof event.data === 'string'
|
|
68
|
+
? event.data
|
|
69
|
+
: decoder(event.language).decode(event.data, {
|
|
70
|
+
stream: true
|
|
71
|
+
}));
|
|
72
|
+
if (event.name === 'debug')
|
|
73
|
+
sandbox.ondebug?.(event.data);
|
|
74
|
+
if (event.name === 'diagnostic')
|
|
75
|
+
sandbox.oncompilerdiagnostic?.(event.data);
|
|
76
|
+
if (event.name === 'image')
|
|
77
|
+
sandbox.image?.(event.data);
|
|
78
|
+
});
|
|
79
|
+
return client;
|
|
80
|
+
};
|
|
81
|
+
const cleanupOwner = async (method, args = []) => {
|
|
82
|
+
if (!client || disposed)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
await client.call(method, args);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
// Terminal cleanup can race the parent disposing the complete owner.
|
|
89
|
+
if (!disposed)
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const syncWorkspace = (language, files) => {
|
|
94
|
+
const snapshot = copyFiles(files);
|
|
95
|
+
const previous = queues.get(language) ?? Promise.resolve();
|
|
96
|
+
const next = previous
|
|
97
|
+
.catch(() => { })
|
|
98
|
+
.then(async () => {
|
|
99
|
+
const baseline = published.get(language);
|
|
100
|
+
if (baseline) {
|
|
101
|
+
const before = new Map(baseline.map((file) => [file.path, file]));
|
|
102
|
+
const changed = [];
|
|
103
|
+
const expected = [];
|
|
104
|
+
for (const file of snapshot) {
|
|
105
|
+
const previous = before.get(file.path);
|
|
106
|
+
before.delete(file.path);
|
|
107
|
+
if (previous && equal(previous.content, file.content))
|
|
108
|
+
continue;
|
|
109
|
+
changed.push(file);
|
|
110
|
+
if (previous)
|
|
111
|
+
expected.push(previous);
|
|
112
|
+
}
|
|
113
|
+
expected.push(...before.values());
|
|
114
|
+
if (!changed.length && !expected.length)
|
|
115
|
+
return;
|
|
116
|
+
await connection().call('syncWorkspaceDelta', [
|
|
117
|
+
language,
|
|
118
|
+
changed,
|
|
119
|
+
expected,
|
|
120
|
+
snapshot.map((file) => ({
|
|
121
|
+
path: file.path,
|
|
122
|
+
bytes: bytes(file.content).byteLength
|
|
123
|
+
}))
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
else
|
|
127
|
+
await connection().call('syncWorkspace', [language, snapshot, undefined]);
|
|
128
|
+
// snapshot already owns its bytes, including while queued behind another write.
|
|
129
|
+
published.set(language, snapshot);
|
|
130
|
+
});
|
|
131
|
+
queues.set(language, next);
|
|
132
|
+
return next;
|
|
133
|
+
};
|
|
134
|
+
const shell = {
|
|
135
|
+
connect(output, error) {
|
|
136
|
+
shellOutput = output;
|
|
137
|
+
shellError = error;
|
|
138
|
+
return (shellConnection ??= (async () => {
|
|
139
|
+
const language = requestedShellLanguage ?? options.getLanguage?.() ?? 'CPP';
|
|
140
|
+
await queues.get(language)?.catch(() => { });
|
|
141
|
+
await connection().call('shellStart', [
|
|
142
|
+
{
|
|
143
|
+
cwd: `/workspace/${language}`,
|
|
144
|
+
env: { PS1: '\\[\\e[1;34m\\]\\w\\[\\e[0m\\] $ ' }
|
|
145
|
+
}
|
|
146
|
+
]);
|
|
147
|
+
})());
|
|
148
|
+
},
|
|
149
|
+
async write(text) {
|
|
150
|
+
await shellConnection;
|
|
151
|
+
await connection().call('shellWrite', [text]);
|
|
152
|
+
},
|
|
153
|
+
async eof() {
|
|
154
|
+
await shellConnection;
|
|
155
|
+
await connection().call('shellEof');
|
|
156
|
+
},
|
|
157
|
+
async interrupt() {
|
|
158
|
+
await shellConnection;
|
|
159
|
+
await connection().call('shellInterrupt');
|
|
160
|
+
},
|
|
161
|
+
async dispose() {
|
|
162
|
+
await cleanupOwner('shellDispose');
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const binding = {
|
|
166
|
+
async beginTerminalExecution() {
|
|
167
|
+
if (terminalExecution || !shellConnection || disposed)
|
|
168
|
+
return;
|
|
169
|
+
// A shell unavailable without cross-origin isolation must not block batch Run.
|
|
170
|
+
try {
|
|
171
|
+
await shellConnection;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
await connection().call('shellSuspend');
|
|
177
|
+
terminalExecution = true;
|
|
178
|
+
},
|
|
179
|
+
async endTerminalExecution() {
|
|
180
|
+
if (!terminalExecution)
|
|
181
|
+
return;
|
|
182
|
+
terminalExecution = false;
|
|
183
|
+
await cleanupOwner('shellResume');
|
|
184
|
+
},
|
|
185
|
+
async setShellDirectory(language) {
|
|
186
|
+
if (!/^[A-Z][A-Z0-9_]*$/.test(language))
|
|
187
|
+
throw new TypeError('Invalid shell language');
|
|
188
|
+
requestedShellLanguage = language;
|
|
189
|
+
// Selecting a language before Terminal mounts must not start a temporary shell.
|
|
190
|
+
if (!shellConnection)
|
|
191
|
+
return;
|
|
192
|
+
await shellConnection;
|
|
193
|
+
await connection().call('shellSetDirectory', [language]);
|
|
194
|
+
},
|
|
195
|
+
runtimeAssets,
|
|
196
|
+
terminalProps: undefined,
|
|
197
|
+
shell,
|
|
198
|
+
async load(language) {
|
|
199
|
+
let sandbox = sandboxes.get(language);
|
|
200
|
+
if (sandbox)
|
|
201
|
+
return sandbox;
|
|
202
|
+
const invoke = (method, args = [], execution, progress) => connection().call(method, [language, ...args], {
|
|
203
|
+
signal: execution?.signal,
|
|
204
|
+
progress
|
|
205
|
+
});
|
|
206
|
+
const record = {
|
|
207
|
+
runtimeAssets,
|
|
208
|
+
elapse: 0,
|
|
209
|
+
async load(code, log = true, args = [], execution = {}, progress) {
|
|
210
|
+
await queues.get(language);
|
|
211
|
+
await invoke('load', [code, log, args, execution], execution, progress);
|
|
212
|
+
},
|
|
213
|
+
async run(code, prepare, log = true, progress, args = [], execution = {}) {
|
|
214
|
+
await queues.get(language);
|
|
215
|
+
const started = performance.now();
|
|
216
|
+
try {
|
|
217
|
+
return await invoke(prepare ? 'prepare' : 'run', [code, log, args, execution], execution, progress);
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
record.elapse = Math.round(performance.now() - started);
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
async clear() {
|
|
224
|
+
await cleanupOwner('clear', [language]);
|
|
225
|
+
},
|
|
226
|
+
async restart() {
|
|
227
|
+
await invoke('restart');
|
|
228
|
+
},
|
|
229
|
+
async terminate() {
|
|
230
|
+
await invoke('stop');
|
|
231
|
+
},
|
|
232
|
+
async kill() {
|
|
233
|
+
await invoke('stop');
|
|
234
|
+
},
|
|
235
|
+
async dispose() {
|
|
236
|
+
await cleanupOwner('clear', [language]);
|
|
237
|
+
},
|
|
238
|
+
write(text) {
|
|
239
|
+
void invoke('write', [text]).catch((error) => shellError?.(error));
|
|
240
|
+
},
|
|
241
|
+
eof() {
|
|
242
|
+
void invoke('eof').catch((error) => shellError?.(error));
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
for (const method of [
|
|
246
|
+
'debugCommand',
|
|
247
|
+
'debugPause',
|
|
248
|
+
'setBreakpoints',
|
|
249
|
+
'setSourceBreakpoints',
|
|
250
|
+
'debugEvaluate',
|
|
251
|
+
'debugEvaluateValue',
|
|
252
|
+
'debugSetSteppingOptions',
|
|
253
|
+
'debugVariables',
|
|
254
|
+
'debugScopes',
|
|
255
|
+
'debugFrameScopes',
|
|
256
|
+
'debugFrameName',
|
|
257
|
+
'debugReadMemory',
|
|
258
|
+
'debugWriteMemory',
|
|
259
|
+
'debugDataBreakpointInfo',
|
|
260
|
+
'debugSetDataBreakpoints'
|
|
261
|
+
]) {
|
|
262
|
+
record[method] = (...args) => invoke(method, args);
|
|
263
|
+
}
|
|
264
|
+
sandboxes.set(language, record);
|
|
265
|
+
return record;
|
|
266
|
+
},
|
|
267
|
+
// Owner and command index can be ready without fetching compiler bodies at page boot.
|
|
268
|
+
async prewarm() {
|
|
269
|
+
connection();
|
|
270
|
+
return true;
|
|
271
|
+
},
|
|
272
|
+
async setPrewarmEnabled() { },
|
|
273
|
+
async cancelPrewarm() { },
|
|
274
|
+
syncWorkspace,
|
|
275
|
+
async readWorkspace(language) {
|
|
276
|
+
const previous = readQueues.get(language);
|
|
277
|
+
const next = (async () => {
|
|
278
|
+
await previous?.catch(() => { });
|
|
279
|
+
await queues.get(language)?.catch(() => { });
|
|
280
|
+
const baseline = reads.get(language);
|
|
281
|
+
const delta = await connection().call('readWorkspaceDelta', [language, baseline?.revision]);
|
|
282
|
+
if (disposed)
|
|
283
|
+
throw new Error('Container playground has been disposed');
|
|
284
|
+
const files = new Map(delta.reset ? [] : baseline?.files);
|
|
285
|
+
for (const path of delta.deleted)
|
|
286
|
+
files.delete(path);
|
|
287
|
+
for (const file of delta.files)
|
|
288
|
+
files.set(file.path, file);
|
|
289
|
+
reads.set(language, { revision: delta.revision, files });
|
|
290
|
+
// Match the owner's sorted directory traversal after incremental additions.
|
|
291
|
+
return copyFiles([...files.values()].sort((left, right) => {
|
|
292
|
+
const a = left.path.split('/'), b = right.path.split('/');
|
|
293
|
+
for (let index = 0; index < Math.min(a.length, b.length); index++) {
|
|
294
|
+
if (a[index] !== b[index])
|
|
295
|
+
return a[index] < b[index] ? -1 : 1;
|
|
296
|
+
}
|
|
297
|
+
return a.length - b.length;
|
|
298
|
+
}));
|
|
299
|
+
})();
|
|
300
|
+
readQueues.set(language, next);
|
|
301
|
+
return await next;
|
|
302
|
+
},
|
|
303
|
+
async listWorkspaceFiles() {
|
|
304
|
+
return await connection().call('listWorkspaceFiles');
|
|
305
|
+
},
|
|
306
|
+
publishedWorkspace(language) {
|
|
307
|
+
return copyFiles(published.get(language) ?? []);
|
|
308
|
+
},
|
|
309
|
+
acceptWorkspace(language, files) {
|
|
310
|
+
published.set(language, copyFiles(files));
|
|
311
|
+
},
|
|
312
|
+
onWorkspaceChange(listener) {
|
|
313
|
+
changes.add(listener);
|
|
314
|
+
return () => changes.delete(listener);
|
|
315
|
+
},
|
|
316
|
+
async inspect() {
|
|
317
|
+
return await connection().call('inspect');
|
|
318
|
+
},
|
|
319
|
+
async dispose() {
|
|
320
|
+
if (disposed)
|
|
321
|
+
return;
|
|
322
|
+
disposed = true;
|
|
323
|
+
changes.clear();
|
|
324
|
+
reads.clear();
|
|
325
|
+
readQueues.clear();
|
|
326
|
+
await client?.dispose();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
binding.terminalProps = { playground: binding, runtimeAssets };
|
|
330
|
+
return binding;
|
|
331
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Container, HostCommandInvocation } from '@wasm-idle/container';
|
|
2
|
+
import { type SandboxExecutionOptions } from '../playground/options.js';
|
|
3
|
+
import type { ProgressLike } from '@wasm-idle/core';
|
|
4
|
+
import type { ContainerWorkerEvent } from './protocol.js';
|
|
5
|
+
import type { WebsiteRuntimeAdapter } from './runtime-adapter.js';
|
|
6
|
+
type Profile = {
|
|
7
|
+
container: Container;
|
|
8
|
+
sysrootProfile?: 'full' | 'c-base-v1';
|
|
9
|
+
prepareCommand(invocation: HostCommandInvocation, signal: AbortSignal): Promise<void>;
|
|
10
|
+
prepareClang?(profile: 'c' | 'full', signal: AbortSignal): Promise<readonly string[]>;
|
|
11
|
+
};
|
|
12
|
+
/** The Run button uses the same real Clang command and artifacts as Bash. Debug uses its qualified backend. */
|
|
13
|
+
export declare class ContainerClangRuntime {
|
|
14
|
+
#private;
|
|
15
|
+
private readonly profile;
|
|
16
|
+
private readonly files;
|
|
17
|
+
private readonly emit;
|
|
18
|
+
constructor(profile: Profile, files: WebsiteRuntimeAdapter, emit: (event: ContainerWorkerEvent) => void);
|
|
19
|
+
private queue;
|
|
20
|
+
private key;
|
|
21
|
+
private currentProgram;
|
|
22
|
+
private spawn;
|
|
23
|
+
private drain;
|
|
24
|
+
private success;
|
|
25
|
+
private headerKey;
|
|
26
|
+
private discardHeader;
|
|
27
|
+
prepare(language: string, code: string, args: string[], options: SandboxExecutionOptions, signal: AbortSignal, progress: ProgressLike | undefined, requestId: number): Promise<boolean>;
|
|
28
|
+
run(language: string, code: string, args: string[], options: SandboxExecutionOptions, signal: AbortSignal, progress: ProgressLike | undefined, requestId: number): Promise<boolean>;
|
|
29
|
+
private flush;
|
|
30
|
+
write(language: string, text: string): Promise<void>;
|
|
31
|
+
eof(language: string): Promise<void>;
|
|
32
|
+
stop(language: string): Promise<void>;
|
|
33
|
+
clear(language: string): void;
|
|
34
|
+
inspect(): {
|
|
35
|
+
language: string;
|
|
36
|
+
phase: "run" | "prepare";
|
|
37
|
+
pid: number | undefined;
|
|
38
|
+
filesystem: string;
|
|
39
|
+
}[];
|
|
40
|
+
dispose(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export { ContainerClangRuntime as WebsiteClangRuntime };
|