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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DebugCommand, DebugSessionEvent, SandboxExecutionOptions } from './options';
|
|
1
|
+
import type { DebugCommand, DebugSessionEvent, DebugVariable, SandboxExecutionOptions } from './options';
|
|
2
2
|
import { WorkerAssetBridge } from './assetBridge';
|
|
3
3
|
import { RuntimeAssetCache } from './runtimeAssetCache';
|
|
4
4
|
import { type PlaygroundRuntimeAssets } from './assets';
|
|
@@ -17,6 +17,10 @@ declare class Python implements Sandbox {
|
|
|
17
17
|
debugBuffer: import("./sharedBuffer").WasmIdleSharedBuffer;
|
|
18
18
|
watchBuffer: import("./sharedBuffer").WasmIdleSharedBuffer;
|
|
19
19
|
watchResultBuffer: import("./sharedBuffer").WasmIdleSharedBuffer;
|
|
20
|
+
private pausedVariablesReference;
|
|
21
|
+
private inspectionController;
|
|
22
|
+
private inspectionFailure;
|
|
23
|
+
private inspectionQueue;
|
|
20
24
|
interruptBuffer: import("./sharedBuffer").WasmIdleSharedBuffer;
|
|
21
25
|
pendingInput: string[];
|
|
22
26
|
begin: number;
|
|
@@ -56,7 +60,10 @@ declare class Python implements Sandbox {
|
|
|
56
60
|
run(code: string, prepare: boolean, _log?: boolean, _prog?: SandboxProgress, _args?: string[], options?: SandboxExecutionOptions): Promise<boolean | string>;
|
|
57
61
|
debugCommand(command: DebugCommand): void;
|
|
58
62
|
setBreakpoints(lines: number[]): void;
|
|
63
|
+
private setInspectionPause;
|
|
64
|
+
private inspect;
|
|
59
65
|
debugEvaluate(expression: string): Promise<string>;
|
|
66
|
+
debugVariables(reference: number, start?: number, count?: number): Promise<DebugVariable[]>;
|
|
60
67
|
kill(): void;
|
|
61
68
|
terminate(reason?: unknown): void;
|
|
62
69
|
clear(): Promise<void>;
|
|
@@ -22,7 +22,13 @@ class Python {
|
|
|
22
22
|
buffer = createWasmIdleSharedBuffer(1024);
|
|
23
23
|
debugBuffer = createWasmIdleSharedBuffer(Int32Array.BYTES_PER_ELEMENT * debugBreakpointBufferInts);
|
|
24
24
|
watchBuffer = createWasmIdleSharedBuffer(1024);
|
|
25
|
-
|
|
25
|
+
// Fifty locals of 256 name + 200 preview code points fit even if JSON needs
|
|
26
|
+
// two six-character surrogate escapes per point. Watch/page requests share it.
|
|
27
|
+
watchResultBuffer = createWasmIdleSharedBuffer(320 * 1024);
|
|
28
|
+
pausedVariablesReference;
|
|
29
|
+
inspectionController = new AbortController();
|
|
30
|
+
inspectionFailure;
|
|
31
|
+
inspectionQueue = Promise.resolve();
|
|
26
32
|
interruptBuffer = createWasmIdleSharedBuffer(1);
|
|
27
33
|
pendingInput = [];
|
|
28
34
|
begin = 0;
|
|
@@ -127,6 +133,7 @@ class Python {
|
|
|
127
133
|
cancelOperation(operation, reason) {
|
|
128
134
|
if (!this.isOperationActive(operation))
|
|
129
135
|
return;
|
|
136
|
+
this.setInspectionPause();
|
|
130
137
|
operation.cancelled = true;
|
|
131
138
|
operation.cancellationReason = reason;
|
|
132
139
|
this.activeOperation = null;
|
|
@@ -380,6 +387,14 @@ class Python {
|
|
|
380
387
|
activePath = options.activePath;
|
|
381
388
|
debugPath = options.debugPath;
|
|
382
389
|
workspaceFiles = options.workspaceFiles;
|
|
390
|
+
if (this.workerLanguage === 'python') {
|
|
391
|
+
if (_args.length || options.programArgs?.length) {
|
|
392
|
+
throw new RuntimeConfigurationError('Python does not support program arguments', { runtimeId: this.runtimeId });
|
|
393
|
+
}
|
|
394
|
+
if (options.env !== undefined) {
|
|
395
|
+
throw new RuntimeConfigurationError('Python does not support environment overrides', { runtimeId: this.runtimeId });
|
|
396
|
+
}
|
|
397
|
+
}
|
|
383
398
|
if (this.usesInterpreterStdio) {
|
|
384
399
|
limits = resolveExecutionLimits(options.limits);
|
|
385
400
|
if (_args.length || options.programArgs?.length) {
|
|
@@ -418,6 +433,7 @@ class Python {
|
|
|
418
433
|
this.waitingForInput = false;
|
|
419
434
|
this.pendingEof = false;
|
|
420
435
|
}
|
|
436
|
+
this.setInspectionPause();
|
|
421
437
|
this.exit = false;
|
|
422
438
|
const running = new Promise((resolve, reject) => {
|
|
423
439
|
const workerOperation = this.workerSession.beginRun(worker, reject);
|
|
@@ -434,6 +450,7 @@ class Python {
|
|
|
434
450
|
worker.onmessage === handler &&
|
|
435
451
|
runUid === this.uid;
|
|
436
452
|
const settleRunState = () => {
|
|
453
|
+
this.setInspectionPause();
|
|
437
454
|
this.elapse = Date.now() - this.begin;
|
|
438
455
|
this.exit = true;
|
|
439
456
|
this.waitingForInput = false;
|
|
@@ -512,8 +529,12 @@ class Python {
|
|
|
512
529
|
}
|
|
513
530
|
if (!ownsRun())
|
|
514
531
|
return;
|
|
515
|
-
if (debugEvent)
|
|
532
|
+
if (debugEvent) {
|
|
533
|
+
this.setInspectionPause(debugEvent.type === 'pause'
|
|
534
|
+
? debugEvent.scopes?.[0]?.variablesReference
|
|
535
|
+
: undefined);
|
|
516
536
|
this.ondebug?.(debugEvent);
|
|
537
|
+
}
|
|
517
538
|
if (!ownsRun())
|
|
518
539
|
return;
|
|
519
540
|
if (log)
|
|
@@ -573,6 +594,7 @@ class Python {
|
|
|
573
594
|
});
|
|
574
595
|
}
|
|
575
596
|
debugCommand(command) {
|
|
597
|
+
this.setInspectionPause();
|
|
576
598
|
const control = new Int32Array(this.debugBuffer);
|
|
577
599
|
Atomics.store(control, 1, command === 'stepInto' ? 2 : command === 'nextLine' ? 3 : command === 'stepOut' ? 4 : 1);
|
|
578
600
|
Atomics.add(control, 0, 1);
|
|
@@ -590,23 +612,84 @@ class Python {
|
|
|
590
612
|
Atomics.store(control, 3, next.length);
|
|
591
613
|
Atomics.add(control, 2, 1);
|
|
592
614
|
}
|
|
593
|
-
|
|
615
|
+
setInspectionPause(reference) {
|
|
616
|
+
this.inspectionController.abort();
|
|
617
|
+
this.inspectionController = new AbortController();
|
|
618
|
+
this.inspectionFailure = undefined;
|
|
619
|
+
this.pausedVariablesReference = reference;
|
|
620
|
+
}
|
|
621
|
+
async inspect(command, expression, signal) {
|
|
622
|
+
if (signal.aborted)
|
|
623
|
+
return '?';
|
|
594
624
|
if (!this.worker)
|
|
595
625
|
throw new Error('Worker not loaded');
|
|
596
626
|
resetBufferedStdin(this.watchResultBuffer);
|
|
597
627
|
const previousSequence = bufferedSequence(this.watchResultBuffer);
|
|
598
628
|
flushQueuedStdin([expression], this.watchBuffer);
|
|
599
629
|
const control = new Int32Array(this.debugBuffer);
|
|
600
|
-
Atomics.store(control, 1,
|
|
630
|
+
Atomics.store(control, 1, command);
|
|
601
631
|
Atomics.add(control, 0, 1);
|
|
602
632
|
Atomics.notify(control, 0);
|
|
603
|
-
|
|
604
|
-
'?');
|
|
633
|
+
try {
|
|
634
|
+
return ((await waitForBufferedSequenceChange(this.watchResultBuffer, previousSequence, 5000, signal)) ?? '?');
|
|
635
|
+
}
|
|
636
|
+
catch (error) {
|
|
637
|
+
if (signal.aborted)
|
|
638
|
+
return '?';
|
|
639
|
+
if (signal === this.inspectionController.signal) {
|
|
640
|
+
// Replies have no request identifier. A timed-out target evaluation can
|
|
641
|
+
// still finish, so this pause cannot safely reuse its response mailbox.
|
|
642
|
+
const failure = new Error('Python debugger inspection timed out. Resume or step to a new pause before inspecting again.', { cause: error });
|
|
643
|
+
this.inspectionFailure = failure;
|
|
644
|
+
this.inspectionController.abort(failure);
|
|
645
|
+
throw failure;
|
|
646
|
+
}
|
|
647
|
+
throw error;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
debugEvaluate(expression) {
|
|
651
|
+
const reference = this.pausedVariablesReference;
|
|
652
|
+
const signal = this.inspectionController.signal;
|
|
653
|
+
const request = this.inspectionQueue.then(async () => {
|
|
654
|
+
if (signal === this.inspectionController.signal && this.inspectionFailure)
|
|
655
|
+
throw this.inspectionFailure;
|
|
656
|
+
if (signal.aborted ||
|
|
657
|
+
reference === undefined ||
|
|
658
|
+
reference !== this.pausedVariablesReference)
|
|
659
|
+
return '?';
|
|
660
|
+
const value = await this.inspect(5, expression, signal);
|
|
661
|
+
return !signal.aborted && reference === this.pausedVariablesReference ? value : '?';
|
|
662
|
+
});
|
|
663
|
+
this.inspectionQueue = request.catch(() => { });
|
|
664
|
+
return request;
|
|
665
|
+
}
|
|
666
|
+
debugVariables(reference, start = 0, count = 50) {
|
|
667
|
+
if (!Number.isSafeInteger(reference) ||
|
|
668
|
+
!Number.isSafeInteger(start) ||
|
|
669
|
+
start < 0 ||
|
|
670
|
+
!Number.isSafeInteger(count) ||
|
|
671
|
+
count < 1)
|
|
672
|
+
return Promise.resolve([]);
|
|
673
|
+
const signal = this.inspectionController.signal;
|
|
674
|
+
const request = this.inspectionQueue.then(async () => {
|
|
675
|
+
if (signal === this.inspectionController.signal && this.inspectionFailure)
|
|
676
|
+
throw this.inspectionFailure;
|
|
677
|
+
if (signal.aborted || reference !== this.pausedVariablesReference)
|
|
678
|
+
return [];
|
|
679
|
+
const result = await this.inspect(6, JSON.stringify({ reference, start, count: Math.min(50, count) }), signal);
|
|
680
|
+
if (signal.aborted || reference !== this.pausedVariablesReference)
|
|
681
|
+
return [];
|
|
682
|
+
const page = JSON.parse(result);
|
|
683
|
+
return Array.isArray(page) ? page : [];
|
|
684
|
+
});
|
|
685
|
+
this.inspectionQueue = request.catch(() => { });
|
|
686
|
+
return request;
|
|
605
687
|
}
|
|
606
688
|
kill() {
|
|
607
689
|
this.terminate();
|
|
608
690
|
}
|
|
609
691
|
terminate(reason = 'Process terminated') {
|
|
692
|
+
this.setInspectionPause();
|
|
610
693
|
const activeOperation = this.activeOperation;
|
|
611
694
|
if (activeOperation) {
|
|
612
695
|
this.cancelOperation(activeOperation, reason);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PlaygroundRuntimeAssets } from './assets';
|
|
2
|
-
import { type CompilerDiagnostic, type SandboxExecutionOptions } from './options';
|
|
2
|
+
import { type DebugCommand, type DebugSessionEvent, type CompilerDiagnostic, type SandboxExecutionOptions } from './options';
|
|
3
3
|
import type { Sandbox, SandboxProgress } from './sandbox';
|
|
4
4
|
declare class Ruby implements Sandbox {
|
|
5
5
|
private readonly workerLanguage;
|
|
@@ -15,6 +15,8 @@ declare class Ruby implements Sandbox {
|
|
|
15
15
|
moduleUrl: string;
|
|
16
16
|
private runtimeAssetKey;
|
|
17
17
|
oncompilerdiagnostic?: (diagnostic: CompilerDiagnostic) => void;
|
|
18
|
+
ondebug?: (event: DebugSessionEvent) => void;
|
|
19
|
+
private debugSession?;
|
|
18
20
|
waitingForInput: boolean;
|
|
19
21
|
pendingEof: boolean;
|
|
20
22
|
private activeOperation;
|
|
@@ -44,6 +46,13 @@ declare class Ruby implements Sandbox {
|
|
|
44
46
|
eof(): void;
|
|
45
47
|
private flushPendingInput;
|
|
46
48
|
run(code: string, prepare: boolean, _log?: boolean, _prog?: SandboxProgress, args?: string[], options?: SandboxExecutionOptions): Promise<boolean | string>;
|
|
49
|
+
debugCommand(command: DebugCommand): void;
|
|
50
|
+
debugPause(): void;
|
|
51
|
+
setBreakpoints(lines: number[], sourcePath?: string): void;
|
|
52
|
+
debugEvaluate(expression: string): Promise<string>;
|
|
53
|
+
debugScopes(frameId: number): Promise<import("@wasm-idle/core").DebugScope[]>;
|
|
54
|
+
debugFrameScopes(frameId: number): Promise<import("@wasm-idle/core").DebugScope[]>;
|
|
55
|
+
debugVariables(reference: number, start?: number, count?: number): Promise<import("@wasm-idle/core").DebugVariable[]>;
|
|
47
56
|
kill(): void;
|
|
48
57
|
terminate(reason?: unknown): void;
|
|
49
58
|
clear(): Promise<void>;
|
package/dist/playground/ruby.js
CHANGED
|
@@ -5,6 +5,8 @@ import { resolveSandboxExecutionArgs } from './options';
|
|
|
5
5
|
import { flushBufferedEof, flushQueuedStdin, resetBufferedStdin } from './stdinBuffer';
|
|
6
6
|
import { createWasmIdleSharedBuffer } from './sharedBuffer';
|
|
7
7
|
import { WorkerSession } from './workerSession';
|
|
8
|
+
import { RubyDebugSession } from './rubyDebug';
|
|
9
|
+
import { DebugDeadline } from './debugDeadline';
|
|
8
10
|
import { reportWorkerInputReady, reportWorkerProgress } from './workerProgress';
|
|
9
11
|
import { BusyError, AssetTooLargeError, CancelledError, DEFAULT_WORKSPACE_LIMITS, DiagnosticLimitError, OutputLimitError, RUBY_MAX_ASSET_BYTES, RUBY_MAX_MANIFEST_BYTES, RUBY_MAX_MODULE_BYTES, RuntimeConfigurationError, TimeoutError, fetchPinnedRuntimeAsset, resolveExecutionLimits, validateExecutionWorkspace } from '@wasm-idle/core';
|
|
10
12
|
const OUTPUT_ENCODER = new TextEncoder();
|
|
@@ -27,6 +29,8 @@ class Ruby {
|
|
|
27
29
|
moduleUrl = '';
|
|
28
30
|
runtimeAssetKey = '';
|
|
29
31
|
oncompilerdiagnostic;
|
|
32
|
+
ondebug;
|
|
33
|
+
debugSession;
|
|
30
34
|
waitingForInput = false;
|
|
31
35
|
pendingEof = false;
|
|
32
36
|
activeOperation = null;
|
|
@@ -595,12 +599,37 @@ class Ruby {
|
|
|
595
599
|
const hasExplicitStdin = request.stdin !== undefined;
|
|
596
600
|
this.prepareRunStdin(activeOperation, hasExplicitStdin);
|
|
597
601
|
this.exit = false;
|
|
602
|
+
let runDebugSession;
|
|
598
603
|
const running = new Promise((resolve, reject) => {
|
|
599
604
|
let diagnosticCount = 0;
|
|
600
605
|
let outputBytes = 0;
|
|
601
606
|
const workerOperation = this.workerSession.beginRun(worker, reject);
|
|
602
607
|
const timeoutMs = Math.min(2_147_483_647, limits.compileTimeoutMs + limits.runTimeoutMs);
|
|
603
|
-
|
|
608
|
+
let debugDeadline;
|
|
609
|
+
if (!prepare && this.workerLanguage === 'ruby' && options.debugMode === 'tracepoint') {
|
|
610
|
+
debugDeadline = new DebugDeadline(timeoutMs, () => this.cancelOperation(activeOperation, new TimeoutError(`Ruby execution timed out after ${timeoutMs} ms`, {
|
|
611
|
+
phase: 'execute',
|
|
612
|
+
runtimeId: 'RUBY',
|
|
613
|
+
timeoutMs
|
|
614
|
+
})));
|
|
615
|
+
runDebugSession = new RubyDebugSession(options.debugPath || request.activePath, (event) => {
|
|
616
|
+
if (event.type === 'pause')
|
|
617
|
+
debugDeadline?.pause();
|
|
618
|
+
if (event.type === 'resume')
|
|
619
|
+
debugDeadline?.resume();
|
|
620
|
+
this.ondebug?.(event);
|
|
621
|
+
});
|
|
622
|
+
this.debugSession = runDebugSession;
|
|
623
|
+
const session = runDebugSession;
|
|
624
|
+
activeOperation.cleanups.push(() => {
|
|
625
|
+
debugDeadline?.dispose();
|
|
626
|
+
if (this.debugSession === session)
|
|
627
|
+
this.debugSession = undefined;
|
|
628
|
+
session.dispose();
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
else
|
|
632
|
+
this.bindOperationTimeout(activeOperation, timeoutMs);
|
|
604
633
|
this.bindAbortSignal(activeOperation, signal);
|
|
605
634
|
if (!this.isOperationActive(activeOperation))
|
|
606
635
|
return;
|
|
@@ -651,6 +680,10 @@ class Ruby {
|
|
|
651
680
|
return;
|
|
652
681
|
}
|
|
653
682
|
try {
|
|
683
|
+
if (event.data.rubyDebug && runDebugSession) {
|
|
684
|
+
runDebugSession.handle(event.data.rubyDebug);
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
654
687
|
const { output, results, error, buffer, diagnostic, progress } = event.data;
|
|
655
688
|
if (buffer && !hasExplicitStdin) {
|
|
656
689
|
this.waitingForInput = true;
|
|
@@ -722,6 +755,17 @@ class Ruby {
|
|
|
722
755
|
stdin: request.stdin,
|
|
723
756
|
activePath: request.activePath,
|
|
724
757
|
workspaceFiles: request.workspaceFiles,
|
|
758
|
+
...(runDebugSession
|
|
759
|
+
? {
|
|
760
|
+
rubyDebug: {
|
|
761
|
+
buffer: runDebugSession.mailbox.buffer,
|
|
762
|
+
sourcePath: options.debugPath || request.activePath,
|
|
763
|
+
breakpoints: options.breakpoints ?? [],
|
|
764
|
+
sourceBreakpoints: options.sourceBreakpoints,
|
|
765
|
+
pauseOnEntry: options.pauseOnEntry !== false
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
: {}),
|
|
725
769
|
log: _log
|
|
726
770
|
});
|
|
727
771
|
}
|
|
@@ -740,6 +784,27 @@ class Ruby {
|
|
|
740
784
|
this.cleanupOperation(activeOperation);
|
|
741
785
|
});
|
|
742
786
|
}
|
|
787
|
+
debugCommand(command) {
|
|
788
|
+
this.debugSession?.command(command);
|
|
789
|
+
}
|
|
790
|
+
debugPause() {
|
|
791
|
+
this.debugSession?.pause();
|
|
792
|
+
}
|
|
793
|
+
setBreakpoints(lines, sourcePath) {
|
|
794
|
+
this.debugSession?.setBreakpoints(lines, sourcePath);
|
|
795
|
+
}
|
|
796
|
+
debugEvaluate(expression) {
|
|
797
|
+
return this.debugSession?.evaluate(expression) ?? Promise.resolve('?');
|
|
798
|
+
}
|
|
799
|
+
async debugScopes(frameId) {
|
|
800
|
+
return this.debugSession?.scopes(frameId) ?? [];
|
|
801
|
+
}
|
|
802
|
+
async debugFrameScopes(frameId) {
|
|
803
|
+
return this.debugSession?.scopes(frameId, false) ?? [];
|
|
804
|
+
}
|
|
805
|
+
async debugVariables(reference, start, count) {
|
|
806
|
+
return this.debugSession?.variables(reference, start, count) ?? [];
|
|
807
|
+
}
|
|
743
808
|
kill() {
|
|
744
809
|
this.terminate();
|
|
745
810
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DebugCommandMailbox } from './debugMailbox';
|
|
2
|
+
import type { DebugCommand, DebugScope, DebugSessionEvent, DebugVariable } from './options';
|
|
3
|
+
export declare class RubyDebugSession {
|
|
4
|
+
private readonly sourcePath;
|
|
5
|
+
private readonly emit;
|
|
6
|
+
readonly mailbox: DebugCommandMailbox;
|
|
7
|
+
private nextRequest;
|
|
8
|
+
private pending;
|
|
9
|
+
private frames;
|
|
10
|
+
private frameId?;
|
|
11
|
+
private closed;
|
|
12
|
+
constructor(sourcePath: string, emit: (event: DebugSessionEvent) => void);
|
|
13
|
+
handle(message: any): void;
|
|
14
|
+
command(command: DebugCommand): void;
|
|
15
|
+
pause(): void;
|
|
16
|
+
setBreakpoints(lines: number[], sourcePath?: string): void;
|
|
17
|
+
evaluate(expression: string): Promise<string>;
|
|
18
|
+
scopes(frameId: number, select?: boolean): DebugScope[];
|
|
19
|
+
variables(reference: number, start?: number, count?: number): DebugVariable[];
|
|
20
|
+
dispose(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { DebugCommandMailbox } from './debugMailbox';
|
|
2
|
+
export class RubyDebugSession {
|
|
3
|
+
sourcePath;
|
|
4
|
+
emit;
|
|
5
|
+
mailbox = new DebugCommandMailbox('Ruby');
|
|
6
|
+
nextRequest = 0;
|
|
7
|
+
pending = new Map();
|
|
8
|
+
frames = new Map();
|
|
9
|
+
frameId;
|
|
10
|
+
closed = false;
|
|
11
|
+
constructor(sourcePath, emit) {
|
|
12
|
+
this.sourcePath = sourcePath;
|
|
13
|
+
this.emit = emit;
|
|
14
|
+
}
|
|
15
|
+
handle(message) {
|
|
16
|
+
if (this.closed)
|
|
17
|
+
return;
|
|
18
|
+
if (message.consumed)
|
|
19
|
+
this.mailbox.flush();
|
|
20
|
+
if (message.response) {
|
|
21
|
+
const response = message.response;
|
|
22
|
+
const pending = this.pending.get(response.id);
|
|
23
|
+
if (!pending)
|
|
24
|
+
return;
|
|
25
|
+
this.pending.delete(response.id);
|
|
26
|
+
clearTimeout(pending.timer);
|
|
27
|
+
if (response.error)
|
|
28
|
+
pending.reject(new Error(response.error));
|
|
29
|
+
else
|
|
30
|
+
pending.resolve(response.value);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const event = message.event;
|
|
34
|
+
if (!event)
|
|
35
|
+
return;
|
|
36
|
+
if (event.type === 'pause') {
|
|
37
|
+
this.frames.clear();
|
|
38
|
+
for (const frame of message.frames ?? [])
|
|
39
|
+
this.frames.set(frame.id, frame.locals);
|
|
40
|
+
this.frameId = event.frameId;
|
|
41
|
+
}
|
|
42
|
+
else if (event.type === 'resume') {
|
|
43
|
+
this.frames.clear();
|
|
44
|
+
this.frameId = undefined;
|
|
45
|
+
for (const pending of this.pending.values()) {
|
|
46
|
+
clearTimeout(pending.timer);
|
|
47
|
+
pending.reject(new Error('Ruby evaluation became stale'));
|
|
48
|
+
}
|
|
49
|
+
this.pending.clear();
|
|
50
|
+
}
|
|
51
|
+
this.emit(event);
|
|
52
|
+
}
|
|
53
|
+
command(command) {
|
|
54
|
+
this.mailbox.send(JSON.stringify({ op: 'control', command }));
|
|
55
|
+
}
|
|
56
|
+
pause() {
|
|
57
|
+
this.mailbox.send(JSON.stringify({ op: 'pause' }));
|
|
58
|
+
}
|
|
59
|
+
setBreakpoints(lines, sourcePath = this.sourcePath) {
|
|
60
|
+
if (lines.length > 1024 || lines.some((line) => !Number.isSafeInteger(line) || line < 1))
|
|
61
|
+
throw new RangeError('Invalid Ruby breakpoint lines');
|
|
62
|
+
this.mailbox.send(JSON.stringify({ op: 'breakpoints', lines, sourcePath }));
|
|
63
|
+
}
|
|
64
|
+
evaluate(expression) {
|
|
65
|
+
if (expression.length > 4096)
|
|
66
|
+
return Promise.reject(new RangeError('Expression exceeds 4096 characters'));
|
|
67
|
+
if (this.closed || this.frameId === undefined)
|
|
68
|
+
return Promise.reject(new Error('Ruby evaluation requires a paused frame'));
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
const id = ++this.nextRequest;
|
|
71
|
+
const timer = setTimeout(() => {
|
|
72
|
+
this.pending.delete(id);
|
|
73
|
+
reject(new Error('Ruby evaluation timed out'));
|
|
74
|
+
}, 10_000);
|
|
75
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
76
|
+
try {
|
|
77
|
+
this.mailbox.send(JSON.stringify({ op: 'evaluate', id, expression, frameId: this.frameId }));
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
clearTimeout(timer);
|
|
81
|
+
this.pending.delete(id);
|
|
82
|
+
reject(error);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
scopes(frameId, select = true) {
|
|
87
|
+
if (!this.frames.has(frameId))
|
|
88
|
+
return [];
|
|
89
|
+
if (select)
|
|
90
|
+
this.frameId = frameId;
|
|
91
|
+
return [
|
|
92
|
+
{
|
|
93
|
+
name: 'Locals',
|
|
94
|
+
variablesReference: frameId,
|
|
95
|
+
namedVariables: this.frames.get(frameId).length,
|
|
96
|
+
expensive: false,
|
|
97
|
+
variables: this.frames.get(frameId)
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
variables(reference, start = 0, count = 50) {
|
|
102
|
+
if (!Number.isSafeInteger(start) ||
|
|
103
|
+
start < 0 ||
|
|
104
|
+
!Number.isSafeInteger(count) ||
|
|
105
|
+
count < 0 ||
|
|
106
|
+
count > 1000)
|
|
107
|
+
throw new RangeError('Invalid Ruby variable page');
|
|
108
|
+
return (this.frames.get(reference) ?? []).slice(start, start + count);
|
|
109
|
+
}
|
|
110
|
+
dispose() {
|
|
111
|
+
if (this.closed)
|
|
112
|
+
return;
|
|
113
|
+
this.closed = true;
|
|
114
|
+
this.mailbox.close();
|
|
115
|
+
this.frames.clear();
|
|
116
|
+
for (const pending of this.pending.values()) {
|
|
117
|
+
clearTimeout(pending.timer);
|
|
118
|
+
pending.reject(new Error('Ruby debugger stopped'));
|
|
119
|
+
}
|
|
120
|
+
this.pending.clear();
|
|
121
|
+
try {
|
|
122
|
+
this.emit({ type: 'stop' });
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
/* Cleanup survives caller notification failures. */
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -1,32 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare class RuntimeAssetCache {
|
|
3
|
-
private readonly maxBytes;
|
|
4
|
-
private readonly maxEntries;
|
|
5
|
-
private entries;
|
|
6
|
-
private inFlight;
|
|
7
|
-
private inFlightKeyBytes;
|
|
8
|
-
private identities;
|
|
9
|
-
private nextIdentity;
|
|
10
|
-
private bytes;
|
|
11
|
-
private hits;
|
|
12
|
-
private misses;
|
|
13
|
-
private disposed;
|
|
14
|
-
constructor(maxBytes?: number, maxEntries?: number);
|
|
15
|
-
/** Identity is owner-local; a custom loader must never alias another loader. */
|
|
16
|
-
identity(value: object | undefined): number;
|
|
17
|
-
get<T>(key: string): T | undefined;
|
|
18
|
-
/** Only the trusted host publishes fully verified results; failures are never retained. */
|
|
19
|
-
set<T>(key: string, value: T, bytes: number): void;
|
|
20
|
-
/** Share work, but give every consumer its own cancellation and progress subscription. */
|
|
21
|
-
share<T, Progress = never>(key: string, signal: AbortSignal, start: (signal: AbortSignal, report: (progress: Progress, progressKey?: string) => void) => Promise<T>, onProgress?: (progress: Progress) => void): Promise<T>;
|
|
22
|
-
private removeOperation;
|
|
23
|
-
stats(): {
|
|
24
|
-
hits: number;
|
|
25
|
-
misses: number;
|
|
26
|
-
entries: number;
|
|
27
|
-
bytes: number;
|
|
28
|
-
inFlight: number;
|
|
29
|
-
disposed: boolean;
|
|
30
|
-
};
|
|
31
|
-
dispose(): void;
|
|
32
|
-
}
|
|
1
|
+
export { RuntimeAssetCache } from '@wasm-idle/core';
|