wasm-idle 1.1.2 → 1.3.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 (136) hide show
  1. package/README.md +211 -91
  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 +2 -1
  22. package/dist/index.js +1 -0
  23. package/dist/playground/assetBridge.js +5 -2
  24. package/dist/playground/assets.d.ts +8 -0
  25. package/dist/playground/clang.d.ts +5 -1
  26. package/dist/playground/clang.js +61 -5
  27. package/dist/playground/compiledLldb.d.ts +41 -0
  28. package/dist/playground/compiledLldb.js +167 -0
  29. package/dist/playground/d.d.ts +4 -1
  30. package/dist/playground/d.js +78 -9
  31. package/dist/playground/debugDeadline.d.ts +12 -0
  32. package/dist/playground/debugDeadline.js +34 -0
  33. package/dist/playground/debugMailbox.d.ts +12 -0
  34. package/dist/playground/debugMailbox.js +77 -0
  35. package/dist/playground/go.js +9 -4
  36. package/dist/playground/goDebugInstrumentation.js +24 -44
  37. package/dist/playground/java-debug-HUZVAK4F.js +124 -0
  38. package/dist/playground/java-debug-notices.txt +492 -0
  39. package/dist/playground/java.d.ts +17 -1
  40. package/dist/playground/java.js +159 -3
  41. package/dist/playground/javaDebug.d.ts +62 -0
  42. package/dist/playground/javaDebug.js +305 -0
  43. package/dist/playground/javaDebugBridge.d.ts +6 -0
  44. package/dist/playground/javaDebugBridge.js +250 -0
  45. package/dist/playground/javaDebugSource.d.ts +9 -0
  46. package/dist/playground/javaDebugSource.js +4 -0
  47. package/dist/playground/javaRuntimeErrors.js +34 -1
  48. package/dist/playground/lean4Assets.d.ts +1 -25
  49. package/dist/playground/lean4Assets.js +2 -123
  50. package/dist/playground/lfortranAssets.d.ts +2 -2
  51. package/dist/playground/lldbSession.d.ts +24 -2
  52. package/dist/playground/lldbSession.js +322 -59
  53. package/dist/playground/lldbSourcePath.d.ts +2 -0
  54. package/dist/playground/lldbSourcePath.js +9 -0
  55. package/dist/playground/lua.d.ts +20 -1
  56. package/dist/playground/lua.js +190 -8
  57. package/dist/playground/luaDebug.d.ts +1 -0
  58. package/dist/playground/luaDebug.js +1 -0
  59. package/dist/playground/nim.d.ts +1 -0
  60. package/dist/playground/nim.js +8 -0
  61. package/dist/playground/objectivec.d.ts +7 -6
  62. package/dist/playground/objectivec.js +75 -9
  63. package/dist/playground/options.d.ts +10 -4
  64. package/dist/playground/python.d.ts +11 -1
  65. package/dist/playground/python.js +203 -8
  66. package/dist/playground/pythonCompileOptions.d.ts +49 -0
  67. package/dist/playground/pythonCompileOptions.js +40 -0
  68. package/dist/playground/ruby.d.ts +10 -1
  69. package/dist/playground/ruby.js +66 -1
  70. package/dist/playground/rubyDebug.d.ts +21 -0
  71. package/dist/playground/rubyDebug.js +128 -0
  72. package/dist/playground/rust.d.ts +5 -1
  73. package/dist/playground/rust.js +128 -46
  74. package/dist/playground/sandbox.d.ts +8 -1
  75. package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -1
  76. package/dist/playground/staticRuntimeModuleVersion.js +1 -1
  77. package/dist/playground/staticWorkerRuntime.js +8 -2
  78. package/dist/playground/stdinBuffer.d.ts +1 -1
  79. package/dist/playground/stdinBuffer.js +19 -2
  80. package/dist/playground/tinygo.js +7 -0
  81. package/dist/playground/typescript.js +8 -0
  82. package/dist/playground/v.d.ts +3 -2
  83. package/dist/playground/v.js +66 -12
  84. package/dist/playground/wasmC3Version.d.ts +2 -2
  85. package/dist/playground/wasmC3Version.js +2 -2
  86. package/dist/playground/wasmDebugVersion.d.ts +1 -1
  87. package/dist/playground/wasmDebugVersion.js +1 -1
  88. package/dist/playground/wasmLean4Version.d.ts +1 -110
  89. package/dist/playground/wasmLean4Version.js +2 -111
  90. package/dist/playground/wasmLfortranVersion.d.ts +2 -2
  91. package/dist/playground/wasmLfortranVersion.js +2 -2
  92. package/dist/playground/wasmLuaVersion.d.ts +1 -1
  93. package/dist/playground/wasmLuaVersion.js +1 -1
  94. package/dist/playground/wasmPrologVersion.d.ts +17 -17
  95. package/dist/playground/wasmPrologVersion.js +16 -16
  96. package/dist/playground/wasmRustVersion.d.ts +26 -38
  97. package/dist/playground/wasmRustVersion.js +25 -40
  98. package/dist/playground/wasmTypeScriptVersion.d.ts +3 -3
  99. package/dist/playground/wasmTypeScriptVersion.js +3 -3
  100. package/dist/playground/worker/clang.js +1 -1
  101. package/dist/playground/worker/cobol.js +1 -1
  102. package/dist/playground/worker/d.js +51 -2
  103. package/dist/playground/worker/fortran.js +1 -1
  104. package/dist/playground/worker/java.js +188 -35
  105. package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
  106. package/dist/playground/worker/javaDebugEvaluator.js +44 -0
  107. package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
  108. package/dist/playground/worker/javaDebugRuntime.js +315 -0
  109. package/dist/playground/worker/javaOutput.d.ts +11 -0
  110. package/dist/playground/worker/javaOutput.js +54 -0
  111. package/dist/playground/worker/lua.js +13 -0
  112. package/dist/playground/worker/python.js +81 -23
  113. package/dist/playground/worker/pythonCompile.d.ts +4 -0
  114. package/dist/playground/worker/pythonCompile.js +122 -0
  115. package/dist/playground/worker/ruby.js +13 -0
  116. package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
  117. package/dist/playground/worker/rubyDebugPreview.js +80 -0
  118. package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
  119. package/dist/playground/worker/rubyTracepoint.js +162 -0
  120. package/dist/playground/worker/rust.js +4 -1
  121. package/dist/playground/worker/v.js +30 -5
  122. package/dist/playground/zig.js +4 -0
  123. package/dist/pythonCompiler.d.ts +8 -0
  124. package/dist/pythonCompiler.js +52 -0
  125. package/package.json +76 -28
  126. package/dist/playground/container/ContainerExplorer.svelte +0 -307
  127. package/dist/playground/container/ContainerExplorer.svelte.d.ts +0 -14
  128. package/dist/playground/container/clang-runtime.js +0 -343
  129. package/dist/playground/container/client.d.ts +0 -15
  130. package/dist/playground/container/owner.worker.d.ts +0 -1
  131. package/dist/playground/container/owner.worker.js +0 -390
  132. package/dist/playground/container/release.d.ts +0 -31
  133. package/dist/playground/container/release.js +0 -612
  134. /package/dist/{playground/container → container}/explorer.js +0 -0
  135. /package/dist/{playground/container → container}/protocol.js +0 -0
  136. /package/dist/{playground/container → container}/workspace.js +0 -0
@@ -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[]>;
@@ -8,7 +8,7 @@ import { resolveRustNonDebugResourceLimits } from './rustWorkerLimits';
8
8
  import { WASM_RUST_EXECUTABLE_GRAPH_PROFILE, WASM_RUST_RUNTIME_PROFILE } from './wasmRustVersion';
9
9
  import { WorkerSession } from './workerSession';
10
10
  import { reportWorkerInputReady, reportWorkerProgress } from './workerProgress';
11
- import { createRuntimeAssetsKey, RuntimeAssetCache, resolveExecutionLimits, resolveRuntimeAssetCacheOptions, serveRuntimeWasmModule, TimeoutError } from '@wasm-idle/core';
11
+ import { createRuntimeAssetsKey, assertDebugBreakpointSupport, mergeDebugBreakpointLines, normalizeDebugSourceBreakpoints, RuntimeAssetCache, resolveExecutionLimits, resolveRuntimeAssetCacheOptions, serveRuntimeWasmModule, TimeoutError } from '@wasm-idle/core';
12
12
  const debugBreakpointBufferInts = 1028;
13
13
  const rustLldbSourcePath = '/workspace/main.rs';
14
14
  const outputEncoder = new TextEncoder();
@@ -87,6 +87,7 @@ class Rust {
87
87
  debugMode = 'none';
88
88
  activeDebugPhaseTimeout;
89
89
  lldbBreakpoints = new Map();
90
+ lldbBreakpointSpecifications = new Map();
90
91
  lldbEditorSourcePath = rustLldbSourcePath;
91
92
  disposeWorkerExecutableGraph(worker) {
92
93
  const executableGraph = this.workerExecutableGraphs.get(worker);
@@ -358,6 +359,9 @@ class Rust {
358
359
  }
359
360
  run(code, prepare, _log = true, _prog, args = [], options = {}) {
360
361
  const debugMode = options.debugMode || (options.debug ? 'trace' : 'none');
362
+ if (debugMode !== 'none' && debugMode !== 'trace' && debugMode !== 'lldb') {
363
+ return Promise.reject(new Error(`Rust does not support ${debugMode} debugging.`));
364
+ }
361
365
  this.debugMode = debugMode;
362
366
  if (debugMode !== 'none')
363
367
  requireSharedArrayBuffer('Rust debugging');
@@ -372,11 +376,31 @@ class Rust {
372
376
  let limits;
373
377
  let nonDebugResourceLimits;
374
378
  let persistentCache;
379
+ let editorSourcePath;
380
+ let initialBreakpointSpecifications;
381
+ let lldbBreakpointLines = [];
375
382
  try {
376
383
  persistentCache = resolveRuntimeAssetCacheOptions(this.persistentCacheBaseline, options.persistentCache);
377
384
  limits = resolveExecutionLimits(options.limits);
378
385
  nonDebugResourceLimits =
379
386
  debugMode === 'none' ? resolveRustNonDebugResourceLimits(limits) : undefined;
387
+ editorSourcePath = normalizeRustLldbSourcePath(options.debugPath || options.activePath);
388
+ if (debugMode === 'lldb') {
389
+ const requestedLines = [...(options.breakpoints || [])];
390
+ for (const sourceBreakpoints of options.sourceBreakpoints || []) {
391
+ if (normalizeRustLldbSourcePath(sourceBreakpoints.sourcePath) ===
392
+ editorSourcePath) {
393
+ requestedLines.push(...sourceBreakpoints.lines);
394
+ if (sourceBreakpoints.breakpoints)
395
+ initialBreakpointSpecifications = normalizeDebugSourceBreakpoints(sourceBreakpoints.breakpoints);
396
+ }
397
+ }
398
+ lldbBreakpointLines = initialBreakpointSpecifications
399
+ ? initialBreakpointSpecifications
400
+ .filter((value) => value.enabled !== false)
401
+ .map((value) => value.line)
402
+ : normalizeRustBreakpointLines(requestedLines);
403
+ }
380
404
  }
381
405
  catch (error) {
382
406
  return reject(error);
@@ -384,6 +408,7 @@ class Rust {
384
408
  this.runActive = true;
385
409
  this.exit = false;
386
410
  let settled = false;
411
+ let terminating = false;
387
412
  let phaseTimeout;
388
413
  let phaseTimeoutState;
389
414
  let outputBytes = 0;
@@ -427,31 +452,7 @@ class Rust {
427
452
  runtimeId: 'RUST',
428
453
  timeoutMs: state.timeoutMs
429
454
  });
430
- const lldbSession = this.lldbSession;
431
- if (!lldbSession) {
432
- this.workerSession.terminate(timeoutError);
433
- return;
434
- }
435
- if (!this.workerSession.complete(operation))
436
- return;
437
- let disconnecting;
438
- try {
439
- disconnecting = Promise.resolve(lldbSession.disconnect());
440
- }
441
- catch {
442
- disconnecting = Promise.resolve();
443
- }
444
- void disconnecting
445
- .catch(() => undefined)
446
- .then(() => {
447
- if (this.lldbSession === lldbSession)
448
- this.lldbSession = undefined;
449
- this.lldbEditorSourcePath = rustLldbSourcePath;
450
- this.exit = true;
451
- this.waitingForInput = false;
452
- this.pendingEof = false;
453
- finishReject(timeoutError);
454
- });
455
+ terminateRun(timeoutError);
455
456
  }, state.remainingMs);
456
457
  };
457
458
  const debugPhaseTimeout = {
@@ -499,6 +500,48 @@ class Rust {
499
500
  options.signal?.removeEventListener('abort', abortRun);
500
501
  reject(reason);
501
502
  };
503
+ const terminateRun = (error) => {
504
+ if (settled || terminating)
505
+ return;
506
+ terminating = true;
507
+ clearPhaseTimeout();
508
+ const lldbSession = this.lldbSession;
509
+ if (!lldbSession) {
510
+ this.workerSession.terminate(error);
511
+ return;
512
+ }
513
+ if (!this.workerSession.complete(operation))
514
+ return;
515
+ let disconnecting;
516
+ try {
517
+ disconnecting = Promise.resolve(lldbSession.disconnect());
518
+ }
519
+ catch {
520
+ disconnecting = Promise.resolve();
521
+ }
522
+ void disconnecting
523
+ .catch(() => undefined)
524
+ .then(() => {
525
+ if (this.lldbSession === lldbSession)
526
+ this.lldbSession = undefined;
527
+ this.lldbEditorSourcePath = rustLldbSourcePath;
528
+ this.exit = true;
529
+ this.waitingForInput = false;
530
+ this.pendingEof = false;
531
+ finishReject(error);
532
+ });
533
+ };
534
+ const forwardOutput = (output) => {
535
+ if (settled || terminating)
536
+ return false;
537
+ outputBytes += outputEncoder.encode(output).byteLength;
538
+ if (outputBytes > limits.maxOutputBytes) {
539
+ terminateRun(new Error(`Rust output exceeded ${limits.maxOutputBytes} bytes`));
540
+ return false;
541
+ }
542
+ this.output(output);
543
+ return true;
544
+ };
502
545
  const abortRun = () => {
503
546
  try {
504
547
  const disconnecting = this.lldbSession?.disconnect();
@@ -539,19 +582,12 @@ class Rust {
539
582
  abortRun();
540
583
  return;
541
584
  }
542
- const editorSourcePath = normalizeRustLldbSourcePath(options.debugPath || options.activePath);
543
585
  this.lldbEditorSourcePath = editorSourcePath;
544
586
  this.lldbBreakpoints.clear();
545
- let lldbBreakpointLines = [];
587
+ this.lldbBreakpointSpecifications.clear();
546
588
  if (debugMode === 'lldb') {
547
- const requestedLines = [...(options.breakpoints || [])];
548
- for (const sourceBreakpoints of options.sourceBreakpoints || []) {
549
- if (normalizeRustLldbSourcePath(sourceBreakpoints.sourcePath) ===
550
- editorSourcePath) {
551
- requestedLines.push(...sourceBreakpoints.lines);
552
- }
553
- }
554
- lldbBreakpointLines = normalizeRustBreakpointLines(requestedLines);
589
+ if (initialBreakpointSpecifications)
590
+ this.lldbBreakpointSpecifications.set(rustLldbSourcePath, initialBreakpointSpecifications);
555
591
  this.lldbBreakpoints.set(rustLldbSourcePath, lldbBreakpointLines);
556
592
  }
557
593
  else {
@@ -574,14 +610,8 @@ class Rust {
574
610
  this.flushPendingInput();
575
611
  }
576
612
  reportWorkerProgress(_prog, progress);
577
- if (output) {
578
- outputBytes += outputEncoder.encode(String(output)).byteLength;
579
- if (outputBytes > limits.maxOutputBytes) {
580
- this.workerSession.terminate(new Error(`Rust output exceeded ${limits.maxOutputBytes} bytes`));
581
- return;
582
- }
583
- this.output(output);
584
- }
613
+ if (output && !forwardOutput(String(output)))
614
+ return;
585
615
  if (diagnostic) {
586
616
  diagnosticCount += 1;
587
617
  if (diagnosticCount > limits.maxDiagnostics) {
@@ -606,9 +636,17 @@ class Rust {
606
636
  breakpoints: lldbBreakpointLines,
607
637
  sourceBreakpoints: Array.from(this.lldbBreakpoints, ([sourcePath, lines]) => ({
608
638
  sourcePath,
609
- lines: [...lines]
639
+ lines: [...lines],
640
+ ...(this.lldbBreakpointSpecifications.has(sourcePath)
641
+ ? {
642
+ breakpoints: normalizeDebugSourceBreakpoints(this.lldbBreakpointSpecifications.get(sourcePath))
643
+ }
644
+ : {})
610
645
  })),
646
+ debugSteppingOptions: options.debugSteppingOptions,
611
647
  pauseOnEntry: !!options.pauseOnEntry,
648
+ pauseAtMain: true,
649
+ entryFunctionName: 'main::main',
612
650
  programArgs,
613
651
  stdin: options.stdin,
614
652
  onDebugEvent: (debugEvent) => {
@@ -634,9 +672,20 @@ class Rust {
634
672
  });
635
673
  return;
636
674
  }
675
+ if (editorSourcePath !== rustLldbSourcePath &&
676
+ debugEvent.type === 'pauseDetails' &&
677
+ debugEvent.callStack) {
678
+ forwardDebugEvent({
679
+ ...debugEvent,
680
+ callStack: debugEvent.callStack.map((frame) => frame.sourcePath === rustLldbSourcePath
681
+ ? { ...frame, sourcePath: editorSourcePath }
682
+ : frame)
683
+ });
684
+ return;
685
+ }
637
686
  forwardDebugEvent(debugEvent);
638
687
  },
639
- onOutput: (debugOutput) => this.output(debugOutput)
688
+ onOutput: forwardOutput
640
689
  });
641
690
  this.lldbSession = lldbSession;
642
691
  for (const input of this.pendingInput.splice(0))
@@ -765,6 +814,9 @@ class Rust {
765
814
  stdin: options.stdin,
766
815
  args: programArgs,
767
816
  targetTriple,
817
+ optimizationProfile: debugMode === 'none'
818
+ ? options.rustOptimizationProfile || 'interactive'
819
+ : 'interactive',
768
820
  log: _log,
769
821
  debugMode,
770
822
  debug: debugMode === 'trace',
@@ -811,6 +863,8 @@ class Rust {
811
863
  if (this.debugMode === 'lldb') {
812
864
  if (resolvedSourcePath !== this.lldbEditorSourcePath)
813
865
  return;
866
+ if (this.lldbBreakpointSpecifications.has(rustLldbSourcePath))
867
+ return this.setSourceBreakpoints(mergeDebugBreakpointLines(this.lldbBreakpointSpecifications.get(rustLldbSourcePath), normalizeRustBreakpointLines(lines)), resolvedSourcePath);
814
868
  this.lldbBreakpoints.set(rustLldbSourcePath, normalizeRustBreakpointLines(lines));
815
869
  return;
816
870
  }
@@ -822,6 +876,34 @@ class Rust {
822
876
  Atomics.store(control, 3, next.length);
823
877
  Atomics.add(control, 2, 1);
824
878
  }
879
+ async setSourceBreakpoints(breakpoints, sourcePath) {
880
+ const values = normalizeDebugSourceBreakpoints(breakpoints);
881
+ const path = normalizeRustLldbSourcePath(sourcePath || this.lldbEditorSourcePath);
882
+ if (this.lldbSession) {
883
+ if (path !== this.lldbEditorSourcePath)
884
+ return;
885
+ return this.lldbSession.setSourceBreakpoints(values, rustLldbSourcePath);
886
+ }
887
+ if (this.debugMode === 'lldb') {
888
+ if (path !== this.lldbEditorSourcePath)
889
+ return;
890
+ this.lldbBreakpointSpecifications.set(rustLldbSourcePath, values);
891
+ this.lldbBreakpoints.set(rustLldbSourcePath, values.filter((value) => value.enabled !== false).map((value) => value.line));
892
+ return;
893
+ }
894
+ assertDebugBreakpointSupport(values, {});
895
+ this.setBreakpoints(values.filter((value) => value.enabled !== false).map((value) => value.line), sourcePath);
896
+ }
897
+ async debugSetSteppingOptions(options) {
898
+ if (!this.lldbSession)
899
+ throw new Error('Stepping options require an LLDB session.');
900
+ await this.lldbSession.setSteppingOptions(options);
901
+ }
902
+ async debugEvaluateValue(expression, options) {
903
+ if (this.lldbSession)
904
+ return this.lldbSession.evaluateValue(expression, options);
905
+ return { result: '?', variablesReference: 0 };
906
+ }
825
907
  debugEvaluate(expression) {
826
908
  return this.lldbSession?.evaluate(expression) ?? Promise.resolve('?');
827
909
  }
@@ -1,4 +1,4 @@
1
- import type { CompilerDiagnostic, DebugCommand, DebugDataBreakpoint, DebugDataBreakpointInfo, DebugDataBreakpointInfoArguments, DebugMemory, DebugResolvedDataBreakpoint, DebugSessionEvent, DebugWriteMemoryResult, SandboxExecutionOptions } from './options';
1
+ import type { CompilerDiagnostic, DebugCommand, DebugEvaluateOptions, DebugEvaluateResult, DebugSourceBreakpoint, DebugSteppingOptions, DebugVariable, DebugScope, DebugDataBreakpoint, DebugDataBreakpointInfo, DebugDataBreakpointInfoArguments, DebugMemory, DebugResolvedDataBreakpoint, DebugSessionEvent, DebugWriteMemoryResult, SandboxExecutionOptions } from './options';
2
2
  import type { PlaygroundRuntimeAssets } from './assets';
3
3
  import type { ExecutionLimits, SandboxProgress as CoreSandboxProgress } from '@wasm-idle/core';
4
4
  export type SandboxRuntimeAssets = string | PlaygroundRuntimeAssets;
@@ -21,6 +21,13 @@ export interface Sandbox {
21
21
  debugPause?: () => void | Promise<void>;
22
22
  setBreakpoints?: (lines: number[], sourcePath?: string) => void | Promise<void>;
23
23
  debugEvaluate?: (expression: string) => Promise<string>;
24
+ debugEvaluateValue?: (expression: string, options?: DebugEvaluateOptions) => Promise<DebugEvaluateResult>;
25
+ setSourceBreakpoints?: (breakpoints: DebugSourceBreakpoint[], sourcePath?: string) => Promise<void>;
26
+ debugSetSteppingOptions?: (options: DebugSteppingOptions) => Promise<void>;
27
+ debugVariables?: (variablesReference: number, start?: number, count?: number) => Promise<DebugVariable[]>;
28
+ debugScopes?: (frameId: number) => Promise<DebugScope[]>;
29
+ debugFrameScopes?: (frameId: number) => Promise<DebugScope[]>;
30
+ debugFrameName?: (frameId: number) => Promise<string | null>;
24
31
  debugReadMemory?: (memoryReference: string, offset: number, count: number) => Promise<DebugMemory | null>;
25
32
  debugWriteMemory?: (memoryReference: string, offset: number, data: Uint8Array, allowPartial?: boolean) => Promise<DebugWriteMemoryResult | null>;
26
33
  debugDataBreakpointInfo?: (arguments_: DebugDataBreakpointInfoArguments) => Promise<DebugDataBreakpointInfo | null>;
@@ -1 +1 @@
1
- export declare const STATIC_RUNTIME_MODULE_VERSION = "b29a54a528d2f8aa";
1
+ export declare const STATIC_RUNTIME_MODULE_VERSION = "6b508364c7ec4127";
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/build-static-runtime-modules.mjs.
2
- export const STATIC_RUNTIME_MODULE_VERSION = 'b29a54a528d2f8aa';
2
+ export const STATIC_RUNTIME_MODULE_VERSION = '6b508364c7ec4127';
@@ -1516,8 +1516,8 @@ self.postMessage = (message, transferOrOptions) => {
1516
1516
  activeRun.resolve(result);
1517
1517
  }
1518
1518
  rejectRun(id, reason) {
1519
- const activeRun = this.claimRun(id);
1520
- if (!activeRun)
1519
+ const activeRun = this.activeRun;
1520
+ if (!activeRun || activeRun.id !== id)
1521
1521
  return;
1522
1522
  try {
1523
1523
  this.reportRunSettled(activeRun, reason instanceof TimeoutError
@@ -1529,6 +1529,12 @@ self.postMessage = (message, transferOrOptions) => {
1529
1529
  catch {
1530
1530
  // Progress observers must not prevent a failed run from releasing its worker.
1531
1531
  }
1532
+ // Keep the run reserved through its observer, as on success. If that observer
1533
+ // terminates and replaces the run, only the replacement may clean up its state.
1534
+ if (this.activeRun !== activeRun)
1535
+ return;
1536
+ if (this.claimRun(id) !== activeRun)
1537
+ return;
1532
1538
  this.elapse = Date.now() - this.begin;
1533
1539
  this.exit = true;
1534
1540
  this.rejectStdinWaiters(reason);
@@ -2,7 +2,7 @@ type StdinBuffer = ArrayBufferLike | Int32Array;
2
2
  export declare const flushQueuedStdin: (queue: string[], buffer: StdinBuffer) => boolean;
3
3
  export declare const readBufferedStdin: (buffer: StdinBuffer) => string | null;
4
4
  export declare const bufferedSequence: (buffer: StdinBuffer) => number;
5
- export declare const waitForBufferedSequenceChange: (buffer: StdinBuffer, sequence: number, timeoutMs?: number) => Promise<string | null>;
5
+ export declare const waitForBufferedSequenceChange: (buffer: StdinBuffer, sequence: number, timeoutMs?: number, signal?: AbortSignal) => Promise<string | null>;
6
6
  export declare const flushBufferedEof: (buffer: StdinBuffer) => void;
7
7
  export declare const waitForBufferedStdin: (buffer: Int32Array | null | undefined, requestInput: () => void) => string | null;
8
8
  export declare const resetBufferedStdin: (buffer: StdinBuffer) => void;
@@ -47,18 +47,35 @@ export const readBufferedStdin = (buffer) => {
47
47
  return decoder.decode(payload.slice(0, length));
48
48
  };
49
49
  export const bufferedSequence = (buffer) => Atomics.load(controlViewOf(buffer), SEQUENCE_INDEX);
50
- export const waitForBufferedSequenceChange = (buffer, sequence, timeoutMs = 5000) => new Promise((resolve, reject) => {
50
+ export const waitForBufferedSequenceChange = (buffer, sequence, timeoutMs = 5000, signal) => new Promise((resolve, reject) => {
51
51
  const startedAt = Date.now();
52
+ let timer;
53
+ const cleanup = () => {
54
+ if (timer !== undefined)
55
+ clearTimeout(timer);
56
+ signal?.removeEventListener('abort', abort);
57
+ };
58
+ const abort = () => {
59
+ cleanup();
60
+ reject(signal?.reason ?? new Error('Buffered wait aborted'));
61
+ };
62
+ if (signal?.aborted) {
63
+ abort();
64
+ return;
65
+ }
66
+ signal?.addEventListener('abort', abort, { once: true });
52
67
  const poll = () => {
53
68
  if (bufferedSequence(buffer) !== sequence) {
69
+ cleanup();
54
70
  resolve(readBufferedStdin(buffer));
55
71
  return;
56
72
  }
57
73
  if (Date.now() - startedAt >= timeoutMs) {
74
+ cleanup();
58
75
  reject(new Error('Timed out waiting for buffered value'));
59
76
  return;
60
77
  }
61
- setTimeout(poll, 10);
78
+ timer = setTimeout(poll, 10);
62
79
  };
63
80
  poll();
64
81
  });
@@ -1281,6 +1281,13 @@ class TinyGo {
1281
1281
  if (typeof code !== 'string') {
1282
1282
  throw new TypeError('TinyGo source code must be a string');
1283
1283
  }
1284
+ const configuredDebugMode = options.debugMode;
1285
+ this.assertOperation(operation);
1286
+ const debugMode = configuredDebugMode ?? (options.debug ? 'trace' : 'none');
1287
+ this.assertOperation(operation);
1288
+ if (debugMode !== 'none') {
1289
+ throw new RuntimeConfigurationError('TinyGo debugging is unavailable: the current compiler protocol does not provide a debug runtime closure.');
1290
+ }
1284
1291
  const configuredTarget = options.tinygoTarget;
1285
1292
  this.assertOperation(operation);
1286
1293
  const target = configuredTarget ?? 'wasip1';
@@ -563,6 +563,14 @@ class TypeScriptSandbox {
563
563
  this.requireOperationActive(activeOperation);
564
564
  unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
565
565
  this.requireOperationActive(activeOperation);
566
+ const debugMode = options.debugMode;
567
+ this.requireOperationActive(activeOperation);
568
+ const debug = options.debug;
569
+ this.requireOperationActive(activeOperation);
570
+ const resolvedDebugMode = debugMode ?? (debug ? 'trace' : 'none');
571
+ if (resolvedDebugMode !== 'none') {
572
+ throw new RuntimeConfigurationError(`${this.languageLabel} source debugging is unavailable in this browser runtime.`, { runtimeId: this.language, phase: 'execute' });
573
+ }
566
574
  const configuredProgramArgs = options.programArgs;
567
575
  this.requireOperationActive(activeOperation);
568
576
  const sourceProgramArgs = configuredProgramArgs ?? args;
@@ -1,11 +1,12 @@
1
1
  import { WorkerAssetBridge } from './assetBridge';
2
+ import { CompiledLldbSandbox } from './compiledLldb';
2
3
  import type { RuntimeAssetCache } from './runtimeAssetCache';
3
4
  import { type PlaygroundRuntimeAssets } from './assets';
4
5
  import type { SandboxExecutionOptions } from './options';
5
6
  import type { Sandbox, SandboxProgress } from './sandbox';
6
- declare class VLang implements Sandbox {
7
+ declare class VLang extends CompiledLldbSandbox implements Sandbox {
8
+ protected lldbEntryFunction: string;
7
9
  language: string;
8
- output?: (data: string) => void;
9
10
  worker?: Worker;
10
11
  buffer: import("./sharedBuffer").WasmIdleSharedBuffer;
11
12
  pendingInput: string[];
@@ -1,8 +1,9 @@
1
1
  import { WorkerAssetBridge } from './assetBridge';
2
+ import { CompiledLldbSandbox } from './compiledLldb';
2
3
  import { resolveVBaseUrl, resolveRuntimeAssetConfig } from './assets';
3
4
  import { BusyError, CancelledError, DEFAULT_WORKSPACE_LIMITS, OutputLimitError, RuntimeConfigurationError, TimeoutError, resolveExecutionLimits, validateExecutionWorkspace } from '@wasm-idle/core';
4
5
  import { resolveSandboxExecutionArgs } from './options';
5
- import { createWasmIdleSharedBuffer } from './sharedBuffer';
6
+ import { createWasmIdleSharedBuffer, requireSharedArrayBuffer } from './sharedBuffer';
6
7
  import { WorkerSession } from './workerSession';
7
8
  import { reportWorkerInputReady } from './workerProgress';
8
9
  import { flushBufferedEof, flushQueuedStdin, resetBufferedStdin } from './stdinBuffer';
@@ -10,9 +11,9 @@ const OUTPUT_ENCODER = new TextEncoder();
10
11
  const abortReason = (signal, phase) => signal.reason !== undefined
11
12
  ? signal.reason
12
13
  : new DOMException(phase === 'startup' ? 'V runtime startup aborted' : 'V execution aborted', 'AbortError');
13
- class VLang {
14
+ class VLang extends CompiledLldbSandbox {
15
+ lldbEntryFunction = 'main__main';
14
16
  language = 'V';
15
- output;
16
17
  worker = null;
17
18
  buffer = createWasmIdleSharedBuffer(4096);
18
19
  pendingInput = [];
@@ -199,10 +200,11 @@ class VLang {
199
200
  if (!this.isOperationActive(operation))
200
201
  return;
201
202
  let timeout;
202
- operation.cleanups.push(() => {
203
+ const cancelTimeout = () => {
203
204
  if (timeout !== undefined)
204
205
  clearTimeout(timeout);
205
- });
206
+ };
207
+ operation.cleanups.push(cancelTimeout);
206
208
  try {
207
209
  timeout = setTimeout(() => {
208
210
  if (!this.isOperationActive(operation))
@@ -220,6 +222,7 @@ class VLang {
220
222
  catch (error) {
221
223
  this.cancelOperation(operation, error);
222
224
  }
225
+ return cancelTimeout;
223
226
  }
224
227
  resetExplicitStdinState() {
225
228
  this.pendingInput = [];
@@ -250,6 +253,7 @@ class VLang {
250
253
  let limits;
251
254
  let unbindPreSessionAbort = () => undefined;
252
255
  try {
256
+ this.configureLldb(runtimeAssets, options);
253
257
  signal = options.signal;
254
258
  unbindPreSessionAbort = this.bindPreSessionAbort(operation, signal);
255
259
  if (!this.isOperationActive(operation) || signal?.aborted) {
@@ -418,6 +422,10 @@ class VLang {
418
422
  });
419
423
  }
420
424
  write(input) {
425
+ if (this.lldbSession) {
426
+ void this.lldbSession.write(input);
427
+ return;
428
+ }
421
429
  if (this.disposed)
422
430
  return;
423
431
  this.pendingInput.push(input);
@@ -425,6 +433,10 @@ class VLang {
425
433
  this.flushPendingInput();
426
434
  }
427
435
  eof() {
436
+ if (this.lldbSession) {
437
+ void this.lldbSession.eof();
438
+ return;
439
+ }
428
440
  if (this.disposed)
429
441
  return;
430
442
  this.pendingEof = true;
@@ -460,13 +472,17 @@ class VLang {
460
472
  let limits;
461
473
  let workspace;
462
474
  let stdin;
475
+ const debugMode = options.debugMode || (options.debug ? 'trace' : 'none');
463
476
  try {
464
- const debug = options.debug;
465
477
  if (!this.isOperationActive(activeOperation)) {
466
478
  return Promise.reject(this.releaseBeforeSession(activeOperation, 'V execution cancelled'));
467
479
  }
468
- if (debug) {
469
- return Promise.reject(this.releaseBeforeSession(activeOperation, 'V debugging is not supported yet.'));
480
+ if (debugMode !== 'none' && debugMode !== 'lldb') {
481
+ return Promise.reject(this.releaseBeforeSession(activeOperation, 'V debugging requires debugMode: lldb.'));
482
+ }
483
+ if (debugMode === 'lldb') {
484
+ requireSharedArrayBuffer('V debugging');
485
+ this.prepareLldb(options, 'main.v');
470
486
  }
471
487
  signal = options.signal;
472
488
  unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
@@ -514,19 +530,23 @@ class VLang {
514
530
  let outputBytes = 0;
515
531
  const workerOperation = this.workerSession.beginRun(worker, reject);
516
532
  const timeoutMs = Math.min(2_147_483_647, limits.compileTimeoutMs + limits.runTimeoutMs);
517
- this.bindOperationTimeout(activeOperation, timeoutMs);
533
+ const cancelCompileTimeout = this.bindOperationTimeout(activeOperation, timeoutMs);
518
534
  this.bindAbortSignal(activeOperation, signal);
519
535
  if (!this.isOperationActive(activeOperation))
520
536
  return;
521
537
  const runUid = ++this.uid;
522
538
  let handler;
539
+ let handedOff = false;
523
540
  const ownsWorker = () => this.worker === worker &&
524
541
  this.assetBridge === assetBridge &&
525
542
  worker.onmessage === handler;
526
- const ownsRun = () => this.isOperationActive(activeOperation) && ownsWorker() && runUid === this.uid;
543
+ const ownsRun = () => this.isOperationActive(activeOperation) &&
544
+ (handedOff || ownsWorker()) &&
545
+ runUid === this.uid;
527
546
  const claimRun = () => {
528
547
  if (!ownsRun())
529
548
  return false;
549
+ this.lldbPending = false;
530
550
  this.finishExplicitStdin(activeOperation);
531
551
  this.workerSession.complete(workerOperation);
532
552
  this.releaseOperation(activeOperation);
@@ -556,7 +576,37 @@ class VLang {
556
576
  return;
557
577
  if (!ownsRun())
558
578
  return;
559
- const { output, results, log: workerLog, error, buffer, progress } = event.data;
579
+ const { output, results, log: workerLog, error, buffer, progress, lldbArtifact } = event.data;
580
+ if (lldbArtifact) {
581
+ cancelCompileTimeout?.();
582
+ handedOff = true;
583
+ const completion = this.startLldb(lldbArtifact, options, programArgs, this.pendingInput, this.pendingEof, (output) => {
584
+ if (!ownsRun())
585
+ return;
586
+ outputBytes += OUTPUT_ENCODER.encode(output).byteLength;
587
+ if (outputBytes > limits.maxOutputBytes) {
588
+ failRun(new OutputLimitError(`V output exceeded ${limits.maxOutputBytes} bytes`, {
589
+ actual: outputBytes,
590
+ limit: limits.maxOutputBytes,
591
+ phase: 'execute',
592
+ runtimeId: 'V'
593
+ }), true);
594
+ return;
595
+ }
596
+ this.output?.(output);
597
+ });
598
+ this.pendingEof = false;
599
+ if (this.workerSession.release(worker)) {
600
+ assetBridge.dispose();
601
+ this.assetBridge = null;
602
+ delete this.worker;
603
+ }
604
+ void completion.then((result) => {
605
+ if (claimRun())
606
+ resolve(result);
607
+ }, (error) => failRun(error));
608
+ return;
609
+ }
560
610
  if (buffer && !hasExplicitStdin) {
561
611
  this.waitingForInput = true;
562
612
  if (!prepare) {
@@ -623,7 +673,8 @@ class VLang {
623
673
  compileArgs,
624
674
  programArgs,
625
675
  activePath: workspace.activePath,
626
- workspaceFiles: workspace.workspaceFiles
676
+ workspaceFiles: workspace.workspaceFiles,
677
+ debugMode
627
678
  });
628
679
  }
629
680
  catch (error) {
@@ -642,6 +693,7 @@ class VLang {
642
693
  cancelOperation(operation, reason) {
643
694
  if (!this.isOperationActive(operation))
644
695
  return;
696
+ void this.stopLldb();
645
697
  this.finishExplicitStdin(operation);
646
698
  operation.cancelled = true;
647
699
  operation.cancellationReason = reason;
@@ -659,6 +711,7 @@ class VLang {
659
711
  terminate(reason = 'Process terminated') {
660
712
  if (this.disposed)
661
713
  return;
714
+ void this.stopLldb();
662
715
  const operation = this.activeOperation;
663
716
  if (operation) {
664
717
  this.cancelOperation(operation, reason);
@@ -683,6 +736,7 @@ class VLang {
683
736
  dispose() {
684
737
  if (this.disposePromise)
685
738
  return this.disposePromise;
739
+ void this.stopLldb();
686
740
  this.disposed = true;
687
741
  this.disposePromise = Promise.resolve();
688
742
  const activeOperation = this.activeOperation;
@@ -15,6 +15,6 @@ export declare const bundledC3Profile: {
15
15
  };
16
16
  };
17
17
  export declare const bundledC3WorkerReceipt: {
18
- readonly bytes: 17098;
19
- readonly sha256: "49b6b36519051869f3f7ef936a079f8ecb38de7c7b563a0697421a851ffa57ee";
18
+ readonly bytes: 17225;
19
+ readonly sha256: "043817070c6f6c9f6ce3d570a5de79c7be1ca3dba3d40c482be9f962ad714c57";
20
20
  };