wasm-idle 1.1.2 → 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.
Files changed (121) hide show
  1. package/README.md +134 -82
  2. package/dist/container/bash-profile.d.ts +80 -0
  3. package/dist/container/bash-profile.js +328 -0
  4. package/dist/{playground/container → container}/binding.d.ts +21 -8
  5. package/dist/{playground/container → container}/binding.js +109 -25
  6. package/dist/{playground/container → container}/clang-runtime.d.ts +11 -7
  7. package/dist/container/clang-runtime.js +561 -0
  8. package/dist/container/client.d.ts +14 -0
  9. package/dist/{playground/container → container}/client.js +2 -6
  10. package/dist/{playground/container → container}/explorer.d.ts +1 -1
  11. package/dist/container/index.d.ts +11 -0
  12. package/dist/container/index.js +11 -0
  13. package/dist/container/owner-worker.d.ts +19 -0
  14. package/dist/container/owner-worker.js +464 -0
  15. package/dist/{playground/container → container}/protocol.d.ts +12 -1
  16. package/dist/{playground/container → container}/runtime-adapter.d.ts +13 -11
  17. package/dist/{playground/container → container}/runtime-adapter.js +104 -41
  18. package/dist/{playground/container → container}/shell-control.d.ts +2 -2
  19. package/dist/{playground/container → container}/shell-control.js +93 -36
  20. package/dist/{playground/container → container}/workspace.d.ts +5 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/playground/assetBridge.js +5 -2
  23. package/dist/playground/assets.d.ts +8 -0
  24. package/dist/playground/clang.d.ts +5 -1
  25. package/dist/playground/clang.js +61 -5
  26. package/dist/playground/compiledLldb.d.ts +41 -0
  27. package/dist/playground/compiledLldb.js +167 -0
  28. package/dist/playground/d.d.ts +4 -1
  29. package/dist/playground/d.js +78 -9
  30. package/dist/playground/debugDeadline.d.ts +12 -0
  31. package/dist/playground/debugDeadline.js +34 -0
  32. package/dist/playground/debugMailbox.d.ts +12 -0
  33. package/dist/playground/debugMailbox.js +77 -0
  34. package/dist/playground/go.js +9 -4
  35. package/dist/playground/goDebugInstrumentation.js +24 -44
  36. package/dist/playground/java-debug-FMHDKUN6.js +124 -0
  37. package/dist/playground/java-debug-notices.txt +492 -0
  38. package/dist/playground/java.d.ts +17 -1
  39. package/dist/playground/java.js +159 -3
  40. package/dist/playground/javaDebug.d.ts +62 -0
  41. package/dist/playground/javaDebug.js +305 -0
  42. package/dist/playground/javaDebugBridge.d.ts +6 -0
  43. package/dist/playground/javaDebugBridge.js +250 -0
  44. package/dist/playground/javaDebugSource.d.ts +9 -0
  45. package/dist/playground/javaDebugSource.js +4 -0
  46. package/dist/playground/javaRuntimeErrors.js +34 -1
  47. package/dist/playground/lean4Assets.d.ts +1 -25
  48. package/dist/playground/lean4Assets.js +2 -123
  49. package/dist/playground/lfortranAssets.d.ts +2 -2
  50. package/dist/playground/lldbSession.d.ts +23 -2
  51. package/dist/playground/lldbSession.js +278 -58
  52. package/dist/playground/lldbSourcePath.d.ts +2 -0
  53. package/dist/playground/lldbSourcePath.js +9 -0
  54. package/dist/playground/lua.d.ts +20 -1
  55. package/dist/playground/lua.js +190 -8
  56. package/dist/playground/luaDebug.d.ts +1 -0
  57. package/dist/playground/luaDebug.js +1 -0
  58. package/dist/playground/nim.d.ts +1 -0
  59. package/dist/playground/nim.js +8 -0
  60. package/dist/playground/objectivec.d.ts +7 -6
  61. package/dist/playground/objectivec.js +75 -9
  62. package/dist/playground/options.d.ts +10 -4
  63. package/dist/playground/python.d.ts +8 -1
  64. package/dist/playground/python.js +81 -6
  65. package/dist/playground/ruby.d.ts +10 -1
  66. package/dist/playground/ruby.js +66 -1
  67. package/dist/playground/rubyDebug.d.ts +21 -0
  68. package/dist/playground/rubyDebug.js +128 -0
  69. package/dist/playground/rust.d.ts +5 -1
  70. package/dist/playground/rust.js +128 -46
  71. package/dist/playground/sandbox.d.ts +8 -1
  72. package/dist/playground/staticWorkerRuntime.js +8 -2
  73. package/dist/playground/stdinBuffer.d.ts +1 -1
  74. package/dist/playground/stdinBuffer.js +19 -2
  75. package/dist/playground/tinygo.js +7 -0
  76. package/dist/playground/typescript.js +8 -0
  77. package/dist/playground/v.d.ts +3 -2
  78. package/dist/playground/v.js +66 -12
  79. package/dist/playground/wasmC3Version.d.ts +2 -2
  80. package/dist/playground/wasmC3Version.js +2 -2
  81. package/dist/playground/wasmLean4Version.d.ts +1 -110
  82. package/dist/playground/wasmLean4Version.js +2 -111
  83. package/dist/playground/wasmLfortranVersion.d.ts +2 -2
  84. package/dist/playground/wasmLfortranVersion.js +2 -2
  85. package/dist/playground/wasmLuaVersion.d.ts +1 -1
  86. package/dist/playground/wasmLuaVersion.js +1 -1
  87. package/dist/playground/wasmRustVersion.d.ts +26 -38
  88. package/dist/playground/wasmRustVersion.js +25 -40
  89. package/dist/playground/worker/clang.js +1 -1
  90. package/dist/playground/worker/cobol.js +1 -1
  91. package/dist/playground/worker/d.js +51 -2
  92. package/dist/playground/worker/fortran.js +1 -1
  93. package/dist/playground/worker/java.js +188 -35
  94. package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
  95. package/dist/playground/worker/javaDebugEvaluator.js +44 -0
  96. package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
  97. package/dist/playground/worker/javaDebugRuntime.js +315 -0
  98. package/dist/playground/worker/javaOutput.d.ts +11 -0
  99. package/dist/playground/worker/javaOutput.js +54 -0
  100. package/dist/playground/worker/lua.js +13 -0
  101. package/dist/playground/worker/python.js +57 -22
  102. package/dist/playground/worker/ruby.js +13 -0
  103. package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
  104. package/dist/playground/worker/rubyDebugPreview.js +80 -0
  105. package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
  106. package/dist/playground/worker/rubyTracepoint.js +162 -0
  107. package/dist/playground/worker/rust.js +4 -1
  108. package/dist/playground/worker/v.js +30 -5
  109. package/dist/playground/zig.js +4 -0
  110. package/package.json +55 -11
  111. package/dist/playground/container/ContainerExplorer.svelte +0 -307
  112. package/dist/playground/container/ContainerExplorer.svelte.d.ts +0 -14
  113. package/dist/playground/container/clang-runtime.js +0 -343
  114. package/dist/playground/container/client.d.ts +0 -15
  115. package/dist/playground/container/owner.worker.d.ts +0 -1
  116. package/dist/playground/container/owner.worker.js +0 -390
  117. package/dist/playground/container/release.d.ts +0 -31
  118. package/dist/playground/container/release.js +0 -612
  119. /package/dist/{playground/container → container}/explorer.js +0 -0
  120. /package/dist/{playground/container → container}/protocol.js +0 -0
  121. /package/dist/{playground/container → container}/workspace.js +0 -0
@@ -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
- watchResultBuffer = createWasmIdleSharedBuffer(1024);
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;
@@ -426,6 +433,7 @@ class Python {
426
433
  this.waitingForInput = false;
427
434
  this.pendingEof = false;
428
435
  }
436
+ this.setInspectionPause();
429
437
  this.exit = false;
430
438
  const running = new Promise((resolve, reject) => {
431
439
  const workerOperation = this.workerSession.beginRun(worker, reject);
@@ -442,6 +450,7 @@ class Python {
442
450
  worker.onmessage === handler &&
443
451
  runUid === this.uid;
444
452
  const settleRunState = () => {
453
+ this.setInspectionPause();
445
454
  this.elapse = Date.now() - this.begin;
446
455
  this.exit = true;
447
456
  this.waitingForInput = false;
@@ -520,8 +529,12 @@ class Python {
520
529
  }
521
530
  if (!ownsRun())
522
531
  return;
523
- if (debugEvent)
532
+ if (debugEvent) {
533
+ this.setInspectionPause(debugEvent.type === 'pause'
534
+ ? debugEvent.scopes?.[0]?.variablesReference
535
+ : undefined);
524
536
  this.ondebug?.(debugEvent);
537
+ }
525
538
  if (!ownsRun())
526
539
  return;
527
540
  if (log)
@@ -581,6 +594,7 @@ class Python {
581
594
  });
582
595
  }
583
596
  debugCommand(command) {
597
+ this.setInspectionPause();
584
598
  const control = new Int32Array(this.debugBuffer);
585
599
  Atomics.store(control, 1, command === 'stepInto' ? 2 : command === 'nextLine' ? 3 : command === 'stepOut' ? 4 : 1);
586
600
  Atomics.add(control, 0, 1);
@@ -598,23 +612,84 @@ class Python {
598
612
  Atomics.store(control, 3, next.length);
599
613
  Atomics.add(control, 2, 1);
600
614
  }
601
- async debugEvaluate(expression) {
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 '?';
602
624
  if (!this.worker)
603
625
  throw new Error('Worker not loaded');
604
626
  resetBufferedStdin(this.watchResultBuffer);
605
627
  const previousSequence = bufferedSequence(this.watchResultBuffer);
606
628
  flushQueuedStdin([expression], this.watchBuffer);
607
629
  const control = new Int32Array(this.debugBuffer);
608
- Atomics.store(control, 1, 5);
630
+ Atomics.store(control, 1, command);
609
631
  Atomics.add(control, 0, 1);
610
632
  Atomics.notify(control, 0);
611
- return ((await waitForBufferedSequenceChange(this.watchResultBuffer, previousSequence, 5000)) ??
612
- '?');
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;
613
687
  }
614
688
  kill() {
615
689
  this.terminate();
616
690
  }
617
691
  terminate(reason = 'Process terminated') {
692
+ this.setInspectionPause();
618
693
  const activeOperation = this.activeOperation;
619
694
  if (activeOperation) {
620
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>;
@@ -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
- this.bindOperationTimeout(activeOperation, timeoutMs);
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,7 +1,7 @@
1
1
  import { type PlaygroundRuntimeAssets, type RuntimeAssetIntegrityEntry } from './assets';
2
2
  import { type DebugCommand, type DebugDataBreakpoint, type DebugDataBreakpointInfoArguments, type DebugSessionEvent, type CompilerDiagnostic, type SandboxExecutionOptions } from './options';
3
3
  import type { Sandbox, SandboxProgress } from './sandbox';
4
- import { RuntimeAssetCache } from '@wasm-idle/core';
4
+ import { RuntimeAssetCache, type DebugEvaluateOptions, type DebugSourceBreakpoint, type DebugSteppingOptions } from '@wasm-idle/core';
5
5
  declare class Rust implements Sandbox {
6
6
  output: any;
7
7
  ondebug?: (event: DebugSessionEvent) => void;
@@ -39,6 +39,7 @@ declare class Rust implements Sandbox {
39
39
  private debugMode;
40
40
  private activeDebugPhaseTimeout?;
41
41
  private readonly lldbBreakpoints;
42
+ private readonly lldbBreakpointSpecifications;
42
43
  private lldbEditorSourcePath;
43
44
  private disposeWorkerExecutableGraph;
44
45
  load(runtimeAssets?: string | PlaygroundRuntimeAssets, _code?: string, _log?: boolean, _args?: string[], _options?: SandboxExecutionOptions, progress?: SandboxProgress): Promise<void>;
@@ -49,6 +50,9 @@ declare class Rust implements Sandbox {
49
50
  debugCommand(command: DebugCommand): Promise<void> | undefined;
50
51
  debugPause(): Promise<void> | undefined;
51
52
  setBreakpoints(lines: number[], sourcePath?: string): Promise<void> | undefined;
53
+ setSourceBreakpoints(breakpoints: DebugSourceBreakpoint[], sourcePath?: string): Promise<void>;
54
+ debugSetSteppingOptions(options: DebugSteppingOptions): Promise<void>;
55
+ debugEvaluateValue(expression: string, options?: DebugEvaluateOptions): Promise<import("@wasm-idle/core").DebugEvaluateResult>;
52
56
  debugEvaluate(expression: string): Promise<string>;
53
57
  debugVariables(variablesReference: number, start?: number, count?: number): Promise<import("@wasm-idle/core").DebugVariable[]>;
54
58
  debugScopes(frameId: number): Promise<import("@wasm-idle/core").DebugScope[]>;