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.
Files changed (197) hide show
  1. package/README.md +267 -112
  2. package/dist/container/bash-profile.d.ts +80 -0
  3. package/dist/container/bash-profile.js +328 -0
  4. package/dist/container/binding.d.ts +39 -0
  5. package/dist/container/binding.js +331 -0
  6. package/dist/container/clang-runtime.d.ts +42 -0
  7. package/dist/container/clang-runtime.js +561 -0
  8. package/dist/container/client.d.ts +14 -0
  9. package/dist/container/client.js +185 -0
  10. package/dist/container/explorer.d.ts +31 -0
  11. package/dist/container/explorer.js +112 -0
  12. package/dist/container/index.d.ts +11 -0
  13. package/dist/container/index.js +11 -0
  14. package/dist/container/owner-worker.d.ts +19 -0
  15. package/dist/container/owner-worker.js +464 -0
  16. package/dist/container/protocol.d.ts +84 -0
  17. package/dist/container/protocol.js +28 -0
  18. package/dist/container/runtime-adapter.d.ts +75 -0
  19. package/dist/container/runtime-adapter.js +537 -0
  20. package/dist/container/shell-control.d.ts +49 -0
  21. package/dist/container/shell-control.js +360 -0
  22. package/dist/container/workspace.d.ts +12 -0
  23. package/dist/container/workspace.js +29 -0
  24. package/dist/index.d.ts +1 -1
  25. package/dist/playground/assetBridge.js +111 -33
  26. package/dist/playground/assets.d.ts +10 -2
  27. package/dist/playground/c3.js +22 -0
  28. package/dist/playground/c3Memory.d.ts +19 -0
  29. package/dist/playground/c3Memory.js +117 -0
  30. package/dist/playground/cachedClang.js +143 -34
  31. package/dist/playground/clang.d.ts +5 -1
  32. package/dist/playground/clang.js +61 -5
  33. package/dist/playground/clangAssetIntegrity.js +6 -6
  34. package/dist/playground/clangWorkerProtocol.d.ts +12 -1
  35. package/dist/playground/cobol.d.ts +3 -0
  36. package/dist/playground/cobol.js +10 -1
  37. package/dist/playground/commonlispAssets.d.ts +2 -2
  38. package/dist/playground/compiledArtifactCache.d.ts +3 -1
  39. package/dist/playground/compiledArtifactCache.js +31 -5
  40. package/dist/playground/compiledLldb.d.ts +41 -0
  41. package/dist/playground/compiledLldb.js +167 -0
  42. package/dist/playground/d.d.ts +10 -2
  43. package/dist/playground/d.js +161 -14
  44. package/dist/playground/debugDeadline.d.ts +12 -0
  45. package/dist/playground/debugDeadline.js +34 -0
  46. package/dist/playground/debugMailbox.d.ts +12 -0
  47. package/dist/playground/debugMailbox.js +77 -0
  48. package/dist/playground/dotnet.js +6 -8
  49. package/dist/playground/fortran.d.ts +3 -0
  50. package/dist/playground/fortran.js +10 -1
  51. package/dist/playground/go.js +23 -7
  52. package/dist/playground/goDebugInstrumentation.js +207 -97
  53. package/dist/playground/java-debug-FMHDKUN6.js +124 -0
  54. package/dist/playground/java-debug-notices.txt +492 -0
  55. package/dist/playground/java.d.ts +17 -1
  56. package/dist/playground/java.js +162 -5
  57. package/dist/playground/javaDebug.d.ts +62 -0
  58. package/dist/playground/javaDebug.js +305 -0
  59. package/dist/playground/javaDebugBridge.d.ts +6 -0
  60. package/dist/playground/javaDebugBridge.js +250 -0
  61. package/dist/playground/javaDebugSource.d.ts +9 -0
  62. package/dist/playground/javaDebugSource.js +4 -0
  63. package/dist/playground/javaRuntimeErrors.d.ts +9 -0
  64. package/dist/playground/javaRuntimeErrors.js +93 -0
  65. package/dist/playground/lean4Assets.d.ts +1 -25
  66. package/dist/playground/lean4Assets.js +2 -123
  67. package/dist/playground/lfortran.js +10 -0
  68. package/dist/playground/lfortranAssets.d.ts +2 -2
  69. package/dist/playground/lldbSession.d.ts +23 -2
  70. package/dist/playground/lldbSession.js +278 -58
  71. package/dist/playground/lldbSourcePath.d.ts +2 -0
  72. package/dist/playground/lldbSourcePath.js +9 -0
  73. package/dist/playground/lua.d.ts +20 -1
  74. package/dist/playground/lua.js +190 -8
  75. package/dist/playground/luaDebug.d.ts +1 -0
  76. package/dist/playground/luaDebug.js +1 -0
  77. package/dist/playground/nim.d.ts +1 -0
  78. package/dist/playground/nim.js +30 -0
  79. package/dist/playground/objectivec.d.ts +10 -6
  80. package/dist/playground/objectivec.js +85 -10
  81. package/dist/playground/options.d.ts +12 -4
  82. package/dist/playground/python.d.ts +8 -1
  83. package/dist/playground/python.js +89 -6
  84. package/dist/playground/ruby.d.ts +10 -1
  85. package/dist/playground/ruby.js +66 -1
  86. package/dist/playground/rubyDebug.d.ts +21 -0
  87. package/dist/playground/rubyDebug.js +128 -0
  88. package/dist/playground/runtimeAssetCache.d.ts +1 -32
  89. package/dist/playground/runtimeAssetCache.js +1 -193
  90. package/dist/playground/runtimeSession.d.ts +2 -2
  91. package/dist/playground/runtimeSession.js +11 -11
  92. package/dist/playground/rust.d.ts +10 -0
  93. package/dist/playground/rust.js +230 -51
  94. package/dist/playground/sandbox.d.ts +8 -1
  95. package/dist/playground/staticStdinRing.d.ts +2 -1
  96. package/dist/playground/staticStdinRing.js +21 -10
  97. package/dist/playground/staticWorkerRuntime.d.ts +15 -1
  98. package/dist/playground/staticWorkerRuntime.js +127 -19
  99. package/dist/playground/stdinBuffer.d.ts +1 -1
  100. package/dist/playground/stdinBuffer.js +19 -2
  101. package/dist/playground/tinygo.d.ts +3 -0
  102. package/dist/playground/tinygo.js +88 -6
  103. package/dist/playground/typescript.js +8 -0
  104. package/dist/playground/v.d.ts +6 -2
  105. package/dist/playground/v.js +76 -13
  106. package/dist/playground/wasmAwkVersion.d.ts +13 -13
  107. package/dist/playground/wasmAwkVersion.js +4 -4
  108. package/dist/playground/wasmBqnVersion.d.ts +2 -2
  109. package/dist/playground/wasmBqnVersion.js +2 -2
  110. package/dist/playground/wasmC3Version.d.ts +2 -2
  111. package/dist/playground/wasmC3Version.js +2 -2
  112. package/dist/playground/wasmClojureScriptVersion.d.ts +2 -2
  113. package/dist/playground/wasmClojureScriptVersion.js +2 -2
  114. package/dist/playground/wasmCommonLispVersion.d.ts +2 -2
  115. package/dist/playground/wasmCommonLispVersion.js +2 -2
  116. package/dist/playground/wasmDIntegrity.d.ts +5 -5
  117. package/dist/playground/wasmDIntegrity.js +5 -5
  118. package/dist/playground/wasmDVersion.d.ts +16 -1
  119. package/dist/playground/wasmDVersion.js +16 -1
  120. package/dist/playground/wasmDebugVersion.d.ts +1 -1
  121. package/dist/playground/wasmDebugVersion.js +1 -1
  122. package/dist/playground/wasmForthVersion.d.ts +2 -2
  123. package/dist/playground/wasmForthVersion.js +2 -2
  124. package/dist/playground/wasmGleamVersion.d.ts +2 -2
  125. package/dist/playground/wasmGleamVersion.js +2 -2
  126. package/dist/playground/wasmGrainVersion.d.ts +2 -2
  127. package/dist/playground/wasmGrainVersion.js +2 -2
  128. package/dist/playground/wasmJVersion.d.ts +2 -2
  129. package/dist/playground/wasmJVersion.js +2 -2
  130. package/dist/playground/wasmJanetVersion.js +2 -2
  131. package/dist/playground/wasmJuliaVersion.js +2 -2
  132. package/dist/playground/wasmLean4Version.d.ts +1 -110
  133. package/dist/playground/wasmLean4Version.js +2 -111
  134. package/dist/playground/wasmLfortranVersion.d.ts +2 -2
  135. package/dist/playground/wasmLfortranVersion.js +2 -2
  136. package/dist/playground/wasmLuaVersion.d.ts +1 -1
  137. package/dist/playground/wasmLuaVersion.js +1 -1
  138. package/dist/playground/wasmNimVersion.d.ts +9 -9
  139. package/dist/playground/wasmNimVersion.js +6 -6
  140. package/dist/playground/wasmOcamlVersion.d.ts +2 -2
  141. package/dist/playground/wasmOcamlVersion.js +1 -1
  142. package/dist/playground/wasmPascalVersion.js +2 -2
  143. package/dist/playground/wasmPerlVersion.js +2 -2
  144. package/dist/playground/wasmPrologVersion.d.ts +2 -2
  145. package/dist/playground/wasmPrologVersion.js +2 -2
  146. package/dist/playground/wasmReScriptVersion.d.ts +2 -2
  147. package/dist/playground/wasmReScriptVersion.js +2 -2
  148. package/dist/playground/wasmRustVersion.d.ts +26 -38
  149. package/dist/playground/wasmRustVersion.js +25 -40
  150. package/dist/playground/wasmTclVersion.d.ts +4 -4
  151. package/dist/playground/wasmTclVersion.js +2 -2
  152. package/dist/playground/wasmTinyGoVersion.d.ts +14 -14
  153. package/dist/playground/wasmTinyGoVersion.js +14 -14
  154. package/dist/playground/wasmTypeScriptVersion.d.ts +5 -5
  155. package/dist/playground/wasmTypeScriptVersion.js +5 -5
  156. package/dist/playground/worker/cachedClangCompile.js +52 -4
  157. package/dist/playground/worker/cachedClangExecute.js +6 -5
  158. package/dist/playground/worker/clang.js +33 -11
  159. package/dist/playground/worker/cobol.js +3 -3
  160. package/dist/playground/worker/d.js +63 -7
  161. package/dist/playground/worker/fortran.js +3 -3
  162. package/dist/playground/worker/go.js +16 -5
  163. package/dist/playground/worker/haskell.js +10 -7
  164. package/dist/playground/worker/java.js +263 -45
  165. package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
  166. package/dist/playground/worker/javaDebugEvaluator.js +44 -0
  167. package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
  168. package/dist/playground/worker/javaDebugRuntime.js +315 -0
  169. package/dist/playground/worker/javaOutput.d.ts +11 -0
  170. package/dist/playground/worker/javaOutput.js +54 -0
  171. package/dist/playground/worker/lua.js +15 -3
  172. package/dist/playground/worker/php.js +15 -9
  173. package/dist/playground/worker/python.js +102 -30
  174. package/dist/playground/worker/pythonExecution.js +17 -1
  175. package/dist/playground/worker/pythonWorkspaceFiles.d.ts +6 -0
  176. package/dist/playground/worker/pythonWorkspaceFiles.js +26 -0
  177. package/dist/playground/worker/pythonWorkspaceImports.d.ts +4 -0
  178. package/dist/playground/worker/pythonWorkspaceImports.js +129 -0
  179. package/dist/playground/worker/r.js +13 -6
  180. package/dist/playground/worker/ruby.js +13 -0
  181. package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
  182. package/dist/playground/worker/rubyDebugPreview.js +80 -0
  183. package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
  184. package/dist/playground/worker/rubyTracepoint.js +162 -0
  185. package/dist/playground/worker/rust.js +38 -3
  186. package/dist/playground/worker/sqlite.js +4 -3
  187. package/dist/playground/worker/tinygo.js +11 -3
  188. package/dist/playground/worker/typescript.js +2 -3
  189. package/dist/playground/worker/v.js +32 -7
  190. package/dist/playground/worker/wat.js +2 -3
  191. package/dist/playground/worker/zig.js +20 -6
  192. package/dist/playground/workerSession.d.ts +1 -28
  193. package/dist/playground/workerSession.js +1 -164
  194. package/dist/playground/zig.js +4 -0
  195. package/package.json +66 -15
  196. package/dist/playground/worker/python.runtime.cases.d.ts +0 -1
  197. package/dist/playground/worker/python.runtime.cases.js +0 -374
@@ -5,6 +5,8 @@ import { flushBufferedEof, flushQueuedStdin, resetBufferedStdin } from './stdinB
5
5
  import { createWasmIdleSharedBuffer } from './sharedBuffer';
6
6
  import { WorkerSession } from './workerSession';
7
7
  import { reportWorkerInputReady, reportWorkerProgress } from './workerProgress';
8
+ import { LuaDebugMailbox } from './luaDebug';
9
+ import { requireSharedArrayBuffer } from './sharedBuffer';
8
10
  const OUTPUT_ENCODER = new TextEncoder();
9
11
  const abortReason = (signal, phase, label) => signal.reason !== undefined
10
12
  ? signal.reason
@@ -27,6 +29,7 @@ class Lua {
27
29
  exit = true;
28
30
  moduleUrl = '';
29
31
  oncompilerdiagnostic;
32
+ ondebug;
30
33
  waitingForInput = false;
31
34
  pendingEof = false;
32
35
  activeOperation = null;
@@ -38,6 +41,14 @@ class Lua {
38
41
  workerIdentity = '';
39
42
  disposeCancellation;
40
43
  workerSession;
44
+ debugMailbox = new LuaDebugMailbox();
45
+ debugEnabled = false;
46
+ debugPaused = false;
47
+ debugPath = 'main.lua';
48
+ debugFrames = [];
49
+ selectedDebugFrame = 1;
50
+ evaluationId = 0;
51
+ pendingEvaluations = new Map();
41
52
  constructor(dialect = LUA_DIALECT) {
42
53
  this.dialect = dialect;
43
54
  this.label = dialect.label;
@@ -55,6 +66,7 @@ class Lua {
55
66
  this.exit = true;
56
67
  this.waitingForInput = false;
57
68
  this.pendingEof = false;
69
+ this.finishDebug();
58
70
  }
59
71
  });
60
72
  }
@@ -82,6 +94,11 @@ class Lua {
82
94
  cleanups: [],
83
95
  explicitStdin: false
84
96
  };
97
+ operation.cleanups.push(() => {
98
+ if (operation.timer !== undefined)
99
+ clearTimeout(operation.timer);
100
+ operation.timer = undefined;
101
+ });
85
102
  this.activeOperation = operation;
86
103
  return operation;
87
104
  }
@@ -110,6 +127,8 @@ class Lua {
110
127
  }
111
128
  releaseBeforeSession(operation, reason) {
112
129
  const outcome = operation.cancelled ? operation.cancellationReason : reason;
130
+ if (operation.phase === 'execute')
131
+ this.finishDebug();
113
132
  this.releaseOperation(operation);
114
133
  this.cleanupOperation(operation);
115
134
  return outcome;
@@ -197,13 +216,12 @@ class Lua {
197
216
  bindOperationTimeout(operation, timeoutMs) {
198
217
  if (!this.isOperationActive(operation))
199
218
  return;
200
- let timeout;
201
- operation.cleanups.push(() => {
202
- if (timeout !== undefined)
203
- clearTimeout(timeout);
204
- });
219
+ if (operation.timer !== undefined)
220
+ clearTimeout(operation.timer);
221
+ operation.timerStartedAt = Date.now();
222
+ operation.timeoutRemainingMs = timeoutMs;
205
223
  try {
206
- timeout = setTimeout(() => {
224
+ operation.timer = setTimeout(() => {
207
225
  if (!this.isOperationActive(operation))
208
226
  return;
209
227
  const label = operation.phase === 'startup' ? 'startup' : 'execution';
@@ -214,12 +232,152 @@ class Lua {
214
232
  }));
215
233
  }, timeoutMs);
216
234
  if (operation.cleanedUp)
217
- clearTimeout(timeout);
235
+ clearTimeout(operation.timer);
218
236
  }
219
237
  catch (error) {
220
238
  this.cancelOperation(operation, error);
221
239
  }
222
240
  }
241
+ pauseDebugTimeout() {
242
+ const operation = this.activeOperation;
243
+ if (!operation || operation.timer === undefined)
244
+ return;
245
+ clearTimeout(operation.timer);
246
+ operation.timer = undefined;
247
+ operation.timeoutRemainingMs = Math.max(1, (operation.timeoutRemainingMs ?? 1) -
248
+ (Date.now() - (operation.timerStartedAt ?? Date.now())));
249
+ }
250
+ finishDebug() {
251
+ const wasEnabled = this.debugEnabled;
252
+ this.debugEnabled = false;
253
+ this.debugPaused = false;
254
+ this.debugFrames = [];
255
+ this.debugMailbox.close();
256
+ for (const pending of this.pendingEvaluations.values()) {
257
+ clearTimeout(pending.timer);
258
+ pending.reject(new Error('Lua debugger is no longer paused.'));
259
+ }
260
+ this.pendingEvaluations.clear();
261
+ if (wasEnabled) {
262
+ try {
263
+ this.ondebug?.({ type: 'stop' });
264
+ }
265
+ catch (error) {
266
+ console.error('Lua debugger stop listener failed', error);
267
+ }
268
+ }
269
+ }
270
+ handleDebugEvent(event) {
271
+ if (!this.debugEnabled)
272
+ return;
273
+ if (event.type === 'evaluate') {
274
+ const pending = this.pendingEvaluations.get(event.id);
275
+ if (!pending)
276
+ return;
277
+ this.pendingEvaluations.delete(event.id);
278
+ clearTimeout(pending.timer);
279
+ if (event.error)
280
+ pending.reject(new Error(event.error));
281
+ else
282
+ pending.resolve(event.value ?? 'nil');
283
+ return;
284
+ }
285
+ this.debugPaused = true;
286
+ this.pauseDebugTimeout();
287
+ this.selectedDebugFrame = 1;
288
+ this.debugFrames = event.frames.map((frame, index) => ({
289
+ ...frame,
290
+ id: index + 1,
291
+ sourcePath: `/workspace/${frame.sourcePath}`
292
+ }));
293
+ this.ondebug?.({
294
+ type: 'pause',
295
+ line: event.line,
296
+ reason: event.reason,
297
+ sourcePath: `/workspace/${event.sourcePath}`,
298
+ frameId: 1,
299
+ locals: this.debugFrames[0]?.locals ?? [],
300
+ callStack: this.debugFrames.map(({ locals: _locals, ...frame }) => frame)
301
+ });
302
+ }
303
+ debugCommand(command) {
304
+ if (!this.debugEnabled || !this.debugPaused)
305
+ throw new Error('Lua debugger is not paused.');
306
+ this.debugMailbox.send(`${command === 'stepInto' ? 'STEP' : command === 'nextLine' ? 'OVER' : command === 'stepOut' ? 'OUT' : 'RUN'}\n`);
307
+ this.debugPaused = false;
308
+ this.debugFrames = [];
309
+ for (const pending of this.pendingEvaluations.values()) {
310
+ clearTimeout(pending.timer);
311
+ pending.reject(new Error('Lua debugger resumed.'));
312
+ }
313
+ this.pendingEvaluations.clear();
314
+ const operation = this.activeOperation;
315
+ if (operation)
316
+ this.bindOperationTimeout(operation, operation.timeoutRemainingMs ?? 1);
317
+ this.ondebug?.({ type: 'resume', command });
318
+ }
319
+ setBreakpoints(lines, sourcePath) {
320
+ if (!this.debugEnabled)
321
+ return;
322
+ if (sourcePath && sourcePath.replace(/^\/workspace\//u, '') !== this.debugPath)
323
+ return;
324
+ const next = [
325
+ ...new Set(lines.filter((line) => Number.isSafeInteger(line) && line > 0))
326
+ ].slice(0, 1024);
327
+ this.debugMailbox.send(`DELB * 0\n${next.map((line) => `SETB ${this.debugPath} ${line}\n`).join('')}`);
328
+ }
329
+ debugEvaluate(expression) {
330
+ if (!this.debugEnabled || !this.debugPaused)
331
+ return Promise.reject(new Error('Lua debugger is not paused.'));
332
+ if (this.selectedDebugFrame !== 1)
333
+ return Promise.reject(new Error('Lua evaluation currently supports the top frame only.'));
334
+ if (!expression || expression.length > 4096 || this.pendingEvaluations.size >= 64) {
335
+ return Promise.reject(new RangeError('Lua debugger expression limit exceeded.'));
336
+ }
337
+ const id = ++this.evaluationId;
338
+ return new Promise((resolve, reject) => {
339
+ const timer = setTimeout(() => {
340
+ this.pendingEvaluations.delete(id);
341
+ reject(new Error('Lua debugger evaluation timed out.'));
342
+ }, 5000);
343
+ this.pendingEvaluations.set(id, { resolve, reject, timer });
344
+ try {
345
+ this.debugMailbox.send(`EXEC return (${expression.replace(/[\r\n]/gu, '\f')}) --{stack=${this.selectedDebugFrame},requestId=${id},metatostring=false,maxlevel=2,maxnum=25,maxlength=1024}\n`);
346
+ }
347
+ catch (error) {
348
+ clearTimeout(timer);
349
+ this.pendingEvaluations.delete(id);
350
+ reject(error);
351
+ }
352
+ });
353
+ }
354
+ async debugScopes(frameId = this.selectedDebugFrame) {
355
+ this.selectedDebugFrame = frameId;
356
+ return this.debugFrameScopes(frameId);
357
+ }
358
+ async debugFrameScopes(frameId) {
359
+ if (!this.debugPaused)
360
+ return [];
361
+ const frame = this.debugFrames[frameId - 1];
362
+ return frame
363
+ ? [
364
+ {
365
+ name: 'Locals',
366
+ variablesReference: frameId,
367
+ expensive: false,
368
+ namedVariables: frame.locals.length,
369
+ variables: frame.locals
370
+ }
371
+ ]
372
+ : [];
373
+ }
374
+ async debugFrameName(frameId) {
375
+ return this.debugPaused ? (this.debugFrames[frameId - 1]?.functionName ?? null) : null;
376
+ }
377
+ async debugVariables(reference, start = 0, count) {
378
+ const variables = this.debugPaused ? (this.debugFrames[reference - 1]?.locals ?? []) : [];
379
+ return variables.slice(start, count === undefined ? undefined : start + count);
380
+ }
223
381
  resetExplicitStdinState() {
224
382
  this.pendingInput = [];
225
383
  this.pendingEof = false;
@@ -429,6 +587,19 @@ class Lua {
429
587
  maxTotalBytes: Math.min(workspaceLimits?.maxTotalBytes ?? DEFAULT_WORKSPACE_LIMITS.maxTotalBytes, limits.maxWorkspaceBytes)
430
588
  });
431
589
  stdin = options.stdin;
590
+ const debugMode = options.debugMode ?? (options.debug ? 'mobdebug' : 'none');
591
+ if (!['none', 'trace', 'mobdebug'].includes(debugMode)) {
592
+ throw new RuntimeConfigurationError('Lua debugging uses the MobDebug backend.');
593
+ }
594
+ if (!prepare && debugMode !== 'none') {
595
+ if (this.runtimeId !== 'LUA')
596
+ throw new RuntimeConfigurationError(`${this.label} source debugging is not supported.`);
597
+ requireSharedArrayBuffer('Lua debugging');
598
+ this.debugEnabled = true;
599
+ this.debugPaused = false;
600
+ this.debugPath = workspace.activePath ?? this.dialect.defaultActivePath;
601
+ this.debugMailbox.reset();
602
+ }
432
603
  if (!this.isOperationActive(activeOperation) || signal?.aborted) {
433
604
  return Promise.reject(this.releaseBeforeSession(activeOperation, `${this.label} execution cancelled`));
434
605
  }
@@ -469,6 +640,7 @@ class Lua {
469
640
  this.exit = true;
470
641
  this.waitingForInput = false;
471
642
  this.pendingEof = false;
643
+ this.finishDebug();
472
644
  this.workerSession.complete(operation);
473
645
  this.releaseOperation(activeOperation);
474
646
  this.cleanupOperation(activeOperation);
@@ -496,7 +668,11 @@ class Lua {
496
668
  if (!ownsRun())
497
669
  return;
498
670
  try {
499
- const { output, results, error, buffer, diagnostic, progress } = event.data;
671
+ const { output, results, error, buffer, diagnostic, progress, luaDebug, debugCommandConsumed } = event.data;
672
+ if (debugCommandConsumed)
673
+ this.debugMailbox.flush();
674
+ if (luaDebug)
675
+ this.handleDebugEvent(luaDebug);
500
676
  if (buffer && !hasExplicitStdin) {
501
677
  this.waitingForInput = true;
502
678
  if (!prepare) {
@@ -569,6 +745,10 @@ class Lua {
569
745
  stdin,
570
746
  activePath: workspace.activePath,
571
747
  workspaceFiles: workspace.workspaceFiles,
748
+ debug: this.debugEnabled,
749
+ debugBuffer: this.debugEnabled ? this.debugMailbox.buffer : undefined,
750
+ breakpoints: options.breakpoints ?? [],
751
+ pauseOnEntry: options.pauseOnEntry !== false,
572
752
  log: _log
573
753
  });
574
754
  }
@@ -595,6 +775,7 @@ class Lua {
595
775
  this.waitingForInput = false;
596
776
  this.pendingEof = false;
597
777
  this.exit = true;
778
+ this.finishDebug();
598
779
  this.workerSession.terminate(reason);
599
780
  this.cleanupOperation(operation);
600
781
  }
@@ -611,6 +792,7 @@ class Lua {
611
792
  }
612
793
  this.waitingForInput = false;
613
794
  this.pendingEof = false;
795
+ this.finishDebug();
614
796
  this.uid += 1;
615
797
  this.workerSession.terminate(reason);
616
798
  this.exit = true;
@@ -0,0 +1 @@
1
+ export { DebugCommandMailbox as LuaDebugMailbox, readDebugCommand as readLuaDebugCommand } from './debugMailbox';
@@ -0,0 +1 @@
1
+ export { DebugCommandMailbox as LuaDebugMailbox, readDebugCommand as readLuaDebugCommand } from './debugMailbox';
@@ -1,5 +1,6 @@
1
1
  import { StaticWorkerRuntimeSandbox } from './staticWorkerRuntime';
2
2
  declare class Nim extends StaticWorkerRuntimeSandbox {
3
+ run(...args: Parameters<StaticWorkerRuntimeSandbox['run']>): Promise<string | boolean>;
3
4
  constructor();
4
5
  }
5
6
  export default Nim;
@@ -2,6 +2,14 @@ import { resolveNimRuntimeAssetConfig } from './assets';
2
2
  import { StaticWorkerRuntimeSandbox } from './staticWorkerRuntime';
3
3
  import { RuntimeConfigurationError, preflightNimRuntimeAssets, snapshotNimRuntimePreflightProfile } from '@wasm-idle/core';
4
4
  class Nim extends StaticWorkerRuntimeSandbox {
5
+ run(...args) {
6
+ const options = args[5] || {};
7
+ const debugMode = options.debugMode || (options.debug ? 'trace' : 'none');
8
+ if (debugMode !== 'none') {
9
+ return Promise.reject(new RuntimeConfigurationError('Nim debugging requires a debug-capable compiler producer. The packaged Nim runtime uses LLVM 8 release builds and does not return a DWARF artifact for LLDB.', { runtimeId: 'NIM' }));
10
+ }
11
+ return super.run(...args);
12
+ }
5
13
  constructor() {
6
14
  super({
7
15
  displayName: 'Nim',
@@ -14,6 +22,28 @@ class Nim extends StaticWorkerRuntimeSandbox {
14
22
  sourceHintPattern: /\b(?:stdin|readLine|readAll|lines)\b/i
15
23
  },
16
24
  inlineVerifiedWorker: true,
25
+ includeExecutionLimits: true,
26
+ compilerModules(urls) {
27
+ const profile = snapshotNimRuntimePreflightProfile(urls.preflightProfile);
28
+ return Object.fromEntries([
29
+ ['nim', profile.nimWasmReceipt],
30
+ ['clang', profile.clangWasmReceipt],
31
+ ['lld', profile.lldWasmReceipt],
32
+ ['memfs', profile.memfsWasmReceipt]
33
+ ].map(([key, receipt]) => {
34
+ const integrity = receipt;
35
+ return [
36
+ key,
37
+ {
38
+ receipt: {
39
+ bytes: integrity.uncompressedBytes,
40
+ sha256: integrity.uncompressedSha256
41
+ },
42
+ compileKey: 'nim-llvm8-native-v1'
43
+ }
44
+ ];
45
+ }));
46
+ },
17
47
  resolveRuntimeAssets(runtimeAssets, currentUrl) {
18
48
  const resolved = resolveNimRuntimeAssetConfig(runtimeAssets, currentUrl);
19
49
  const profile = snapshotNimRuntimePreflightProfile(resolved.preflightProfile);
@@ -1,13 +1,14 @@
1
1
  import { WorkerAssetBridge } from './assetBridge';
2
- import type { DebugCommand, DebugSessionEvent } from './options';
2
+ import { CompiledLldbSandbox } from './compiledLldb';
3
+ import type { RuntimeAssetCache } from './runtimeAssetCache';
4
+ import type { DebugCommand } from './options';
3
5
  import { type PlaygroundRuntimeAssets } from './assets';
4
6
  import type { SandboxExecutionOptions } from './options';
5
7
  import type { Sandbox, SandboxProgress } from './sandbox';
8
+ import { type DebugSourceBreakpoint } from '@wasm-idle/core';
6
9
  export type ObjectiveCSandboxLanguage = 'OBJC' | 'OBJECTIVECXX';
7
- declare class ObjectiveC implements Sandbox {
10
+ declare class ObjectiveC extends CompiledLldbSandbox implements Sandbox {
8
11
  language: ObjectiveCSandboxLanguage;
9
- output?: (data: string) => void;
10
- ondebug?: (event: DebugSessionEvent) => void;
11
12
  worker?: Worker;
12
13
  buffer: import("./sharedBuffer").WasmIdleSharedBuffer;
13
14
  debugBuffer: import("./sharedBuffer").WasmIdleSharedBuffer;
@@ -24,15 +25,18 @@ declare class ObjectiveC implements Sandbox {
24
25
  exit: boolean;
25
26
  assetBridge: WorkerAssetBridge | null;
26
27
  activeObjectiveCAssetsKey: string;
28
+ private runtimeAssetCache?;
27
29
  private readonly workerSession;
28
30
  constructor(language?: ObjectiveCSandboxLanguage);
31
+ setRuntimeAssetCache(cache: RuntimeAssetCache): void;
29
32
  load(runtimeAssets?: string | PlaygroundRuntimeAssets, code?: string, log?: boolean, args?: string[], options?: SandboxExecutionOptions, progress?: SandboxProgress): Promise<void>;
30
33
  write(input: string): void;
31
34
  eof(): void;
32
35
  private flushPendingInput;
33
36
  run(code: string, prepare: boolean, log?: boolean, prog?: SandboxProgress, args?: string[], options?: SandboxExecutionOptions): Promise<boolean | string>;
34
- debugCommand(command: DebugCommand): void;
35
- setBreakpoints(lines: number[]): void;
37
+ debugCommand(command: DebugCommand): Promise<void> | undefined;
38
+ setBreakpoints(lines: number[], sourcePath?: string): Promise<void> | undefined;
39
+ setSourceBreakpoints(breakpoints: DebugSourceBreakpoint[], sourcePath?: string): Promise<any>;
36
40
  debugEvaluate(expression: string): Promise<string>;
37
41
  kill(): void;
38
42
  terminate(): void;
@@ -1,17 +1,16 @@
1
1
  import { WorkerAssetBridge } from './assetBridge';
2
+ import { CompiledLldbSandbox } from './compiledLldb';
2
3
  import { resolveObjectiveCRuntimeAssetConfig, resolveRuntimeAssetConfig } from './assets';
3
4
  import { resolveSandboxExecutionArgs } from './options';
4
5
  import { createWasmIdleSharedBuffer, requireSharedArrayBuffer } from './sharedBuffer';
5
6
  import { WorkerSession } from './workerSession';
6
7
  import { reportWorkerInputReady } from './workerProgress';
7
8
  import { bufferedSequence, flushBufferedEof, flushQueuedStdin, resetBufferedStdin, waitForBufferedSequenceChange } from './stdinBuffer';
8
- import { AssetTooLargeError, createRuntimeAssetsKey, resolveExecutionLimits } from '@wasm-idle/core';
9
+ import { AssetTooLargeError, RuntimeConfigurationError, assertDebugBreakpointSupport, createRuntimeAssetsKey, normalizeDebugSourceBreakpoints, resolveExecutionLimits } from '@wasm-idle/core';
9
10
  const debugBreakpointBufferInts = 1028;
10
11
  const objectiveCAssetsKey = (assets) => createRuntimeAssetsKey({ objectivec: assets }) || '';
11
- class ObjectiveC {
12
+ class ObjectiveC extends CompiledLldbSandbox {
12
13
  language;
13
- output;
14
- ondebug;
15
14
  worker = null;
16
15
  buffer = createWasmIdleSharedBuffer(4096);
17
16
  debugBuffer = createWasmIdleSharedBuffer(Int32Array.BYTES_PER_ELEMENT * debugBreakpointBufferInts);
@@ -28,6 +27,7 @@ class ObjectiveC {
28
27
  exit = true;
29
28
  assetBridge = null;
30
29
  activeObjectiveCAssetsKey = '';
30
+ runtimeAssetCache;
31
31
  workerSession = new WorkerSession({
32
32
  label: 'Objective-C',
33
33
  onDispose: (worker) => {
@@ -50,8 +50,17 @@ class ObjectiveC {
50
50
  }
51
51
  });
52
52
  constructor(language = 'OBJC') {
53
+ super();
53
54
  this.language = language;
54
55
  }
56
+ setRuntimeAssetCache(cache) {
57
+ if (this.runtimeAssetCache === cache)
58
+ return;
59
+ if (this.worker) {
60
+ throw new RuntimeConfigurationError('Cannot replace an active Objective-C compiler cache');
61
+ }
62
+ this.runtimeAssetCache = cache;
63
+ }
55
64
  load(runtimeAssets = '', code = '', log = true, args = [], options = {}, progress) {
56
65
  let limits;
57
66
  try {
@@ -61,6 +70,7 @@ class ObjectiveC {
61
70
  return Promise.reject(error);
62
71
  }
63
72
  return this.workerSession.load(async (resolve, reject, operation) => {
73
+ this.configureLldb(runtimeAssets, options);
64
74
  this.log = log;
65
75
  this.pendingInput = [];
66
76
  this.waitingForInput = false;
@@ -93,7 +103,7 @@ class ObjectiveC {
93
103
  if (!this.workerSession.attach(worker, operation))
94
104
  return;
95
105
  this.worker = worker;
96
- this.assetBridge = new WorkerAssetBridge(this.worker, 'clang', clangAssets, progress, limits.maxAssetBytes);
106
+ this.assetBridge = new WorkerAssetBridge(this.worker, 'clang', clangAssets, progress, limits.maxAssetBytes, false, this.runtimeAssetCache);
97
107
  this.activeObjectiveCAssetsKey = nextObjectiveCAssetsKey;
98
108
  this.worker.onmessage = (event) => {
99
109
  if (!this.workerSession.isActive(operation))
@@ -131,11 +141,19 @@ class ObjectiveC {
131
141
  });
132
142
  }
133
143
  write(input) {
144
+ if (this.lldbSession) {
145
+ void this.lldbSession.write(input);
146
+ return;
147
+ }
134
148
  this.pendingInput.push(input);
135
149
  this.pendingEof = false;
136
150
  this.flushPendingInput();
137
151
  }
138
152
  eof() {
153
+ if (this.lldbSession) {
154
+ void this.lldbSession.eof();
155
+ return;
156
+ }
139
157
  this.pendingEof = true;
140
158
  this.flushPendingInput();
141
159
  }
@@ -153,15 +171,26 @@ class ObjectiveC {
153
171
  }
154
172
  }
155
173
  run(code, prepare, log = this.log, prog, args = [], options = {}) {
156
- if (options.debug)
174
+ const debugMode = options.debugMode || (options.debug ? 'trace' : 'none');
175
+ if (debugMode !== 'none' && debugMode !== 'trace' && debugMode !== 'lldb') {
176
+ return Promise.reject(new Error(`Objective-C does not support ${debugMode} debugging.`));
177
+ }
178
+ if (debugMode !== 'none')
157
179
  requireSharedArrayBuffer('Objective-C debugging');
180
+ if (debugMode === 'lldb') {
181
+ this.prepareLldb(options, this.language === 'OBJECTIVECXX' ? 'main.mm' : 'main.m');
182
+ }
183
+ else
184
+ this.lldbPending = false;
158
185
  this.exit = false;
159
186
  return new Promise((resolve, reject) => {
160
187
  if (!this.worker)
161
188
  return reject('Worker not loaded');
162
189
  const operation = this.workerSession.beginRun(this.worker, reject);
163
190
  const { compileArgs, programArgs } = resolveSandboxExecutionArgs(this.language, args, options);
164
- this.setBreakpoints(options.debug ? [...(options.breakpoints || [])] : []);
191
+ if (debugMode !== 'lldb') {
192
+ this.setBreakpoints(debugMode === 'trace' ? [...(options.breakpoints || [])] : []);
193
+ }
165
194
  const interrupt = new Uint8Array(this.interruptBuffer);
166
195
  const _uid = ++this.uid;
167
196
  const handler = (event) => {
@@ -173,7 +202,33 @@ class ObjectiveC {
173
202
  return reject('Worker not loaded');
174
203
  if (_uid !== this.uid)
175
204
  return (this.worker.onmessage = null);
176
- const { output, results, log, error, buffer, progress, debugEvent } = event.data;
205
+ const { output, results, log, error, buffer, progress, debugEvent, lldbArtifact } = event.data;
206
+ if (lldbArtifact) {
207
+ const worker = this.worker;
208
+ const completion = this.startLldb(lldbArtifact, options, programArgs, this.pendingInput, this.pendingEof);
209
+ this.pendingEof = false;
210
+ if (this.workerSession.release(worker)) {
211
+ this.assetBridge?.dispose();
212
+ this.assetBridge = null;
213
+ delete this.worker;
214
+ }
215
+ void completion.then((result) => {
216
+ if (!this.workerSession.isActive(operation))
217
+ return;
218
+ this.elapse = Date.now() - this.begin;
219
+ this.exit = true;
220
+ this.workerSession.complete(operation);
221
+ resolve(result);
222
+ }, (sessionError) => {
223
+ if (!this.workerSession.isActive(operation))
224
+ return;
225
+ this.elapse = Date.now() - this.begin;
226
+ this.exit = true;
227
+ this.workerSession.complete(operation);
228
+ reject(sessionError);
229
+ });
230
+ return;
231
+ }
177
232
  if (buffer) {
178
233
  this.waitingForInput = true;
179
234
  if (!prepare) {
@@ -186,6 +241,7 @@ class ObjectiveC {
186
241
  if (debugEvent)
187
242
  this.ondebug?.(debugEvent);
188
243
  if (results) {
244
+ this.lldbPending = false;
189
245
  this.elapse = Date.now() - this.begin;
190
246
  this.exit = true;
191
247
  this.waitingForInput = false;
@@ -197,6 +253,7 @@ class ObjectiveC {
197
253
  if (log)
198
254
  console.log(log);
199
255
  if (error) {
256
+ this.lldbPending = false;
200
257
  this.elapse = Date.now() - this.begin;
201
258
  this.waitingForInput = false;
202
259
  this.pendingEof = false;
@@ -223,23 +280,31 @@ class ObjectiveC {
223
280
  log,
224
281
  compileArgs,
225
282
  programArgs,
283
+ cVersion: options.cVersion,
284
+ cppVersion: options.cppVersion,
285
+ gnuExtensions: options.objectivecGnuExtensions,
226
286
  activePath: options.activePath ||
227
287
  (this.language === 'OBJECTIVECXX' ? 'main.mm' : undefined),
228
288
  workspaceFiles: options.workspaceFiles,
229
- debug: !!options.debug,
289
+ debugMode,
290
+ debug: debugMode === 'trace',
230
291
  breakpoints: [...(options.breakpoints || [])],
231
292
  pauseOnEntry: !!options.pauseOnEntry
232
293
  });
233
294
  });
234
295
  }
235
296
  debugCommand(command) {
297
+ if (this.lldbPending)
298
+ return super.debugCommand(command);
236
299
  const control = new Int32Array(this.debugBuffer);
237
300
  Atomics.store(control, 1, command === 'stepInto' ? 2 : command === 'nextLine' ? 3 : command === 'stepOut' ? 4 : 1);
238
301
  Atomics.add(control, 0, 1);
239
302
  Atomics.notify(control, 0);
240
303
  this.ondebug?.({ type: 'resume', command });
241
304
  }
242
- setBreakpoints(lines) {
305
+ setBreakpoints(lines, sourcePath) {
306
+ if (this.lldbPending)
307
+ return super.setBreakpoints(lines, sourcePath);
243
308
  const control = new Int32Array(this.debugBuffer);
244
309
  const next = [...new Set(lines.filter((line) => Number.isInteger(line) && line > 0))]
245
310
  .sort((left, right) => left - right)
@@ -250,7 +315,16 @@ class ObjectiveC {
250
315
  Atomics.store(control, 3, next.length);
251
316
  Atomics.add(control, 2, 1);
252
317
  }
318
+ async setSourceBreakpoints(breakpoints, sourcePath) {
319
+ if (this.lldbPending)
320
+ return super.setSourceBreakpoints(breakpoints, sourcePath);
321
+ const values = normalizeDebugSourceBreakpoints(breakpoints);
322
+ assertDebugBreakpointSupport(values, {});
323
+ this.setBreakpoints(values.filter((value) => value.enabled !== false).map((value) => value.line), sourcePath);
324
+ }
253
325
  async debugEvaluate(expression) {
326
+ if (this.lldbPending)
327
+ return super.debugEvaluate(expression);
254
328
  if (!this.worker)
255
329
  throw new Error('Worker not loaded');
256
330
  resetBufferedStdin(this.watchResultBuffer);
@@ -267,6 +341,7 @@ class ObjectiveC {
267
341
  this.terminate();
268
342
  }
269
343
  terminate() {
344
+ void this.stopLldb();
270
345
  this.waitingForInput = false;
271
346
  this.pendingEof = false;
272
347
  this.uid += 1;
@@ -1,5 +1,5 @@
1
- import type { DebugSourceBreakpoints, ExecutionLimits, WorkspaceLimits } from '@wasm-idle/core';
2
- export type { DebugArrayElementKind, DebugCommand, DebugDataBreakpoint, DebugDataBreakpointAccessType, DebugDataBreakpointInfo, DebugDataBreakpointInfoArguments, DebugFrame, DebugMemory, DebugPauseReason, DebugResolvedBreakpoint, DebugResolvedDataBreakpoint, DebugSessionCapabilities, DebugSessionEvent, DebugScope, DebugSourceBreakpoints, DebugStructFieldMetadata, DebugVariable, DebugVariableKind, DebugVariableMetadata, DebugWriteMemoryResult } from '@wasm-idle/core';
1
+ import type { DebugSourceBreakpoints, DebugSteppingOptions, ExecutionLimits, WorkspaceLimits } from '@wasm-idle/core';
2
+ export type { DebugArrayElementKind, DebugCommand, DebugEvaluateOptions, DebugEvaluateResult, DebugSourceBreakpoint, DebugSteppingOptions, DebugVariablePresentationHint, DebugDataBreakpoint, DebugDataBreakpointAccessType, DebugDataBreakpointInfo, DebugDataBreakpointInfoArguments, DebugFrame, DebugMemory, DebugPauseReason, DebugResolvedBreakpoint, DebugResolvedDataBreakpoint, DebugSessionCapabilities, DebugSessionEvent, DebugScope, DebugSourceBreakpoints, DebugStructFieldMetadata, DebugVariable, DebugVariableKind, DebugVariableMetadata, DebugWriteMemoryResult } from '@wasm-idle/core';
3
3
  export type CompilerDiagnosticSeverity = 'error' | 'warning' | 'other';
4
4
  export interface CompilerDiagnostic {
5
5
  fileName?: string | null;
@@ -9,8 +9,9 @@ export interface CompilerDiagnostic {
9
9
  severity: CompilerDiagnosticSeverity;
10
10
  message: string;
11
11
  }
12
+ export type RustOptimizationProfile = 'interactive' | 'speed' | 'size';
12
13
  export type RustTargetTriple = 'wasm32-wasip1' | 'wasm32-wasip2' | 'wasm32-wasip3';
13
- export type BrowserDebugMode = 'none' | 'trace' | 'lldb';
14
+ export type BrowserDebugMode = 'none' | 'trace' | 'lldb' | 'mobdebug' | 'tracepoint';
14
15
  export type GoTarget = 'wasip1/wasm' | 'wasip2/wasm' | 'wasip3/wasm' | 'js/wasm';
15
16
  export type TinyGoTarget = 'wasm' | 'wasip1' | 'wasip2' | 'wasip3';
16
17
  export type OcamlBackend = 'js' | 'wasm';
@@ -24,12 +25,13 @@ export interface SandboxExecutionOptions {
24
25
  /** Overrides instance/global persistent asset caching for this operation. */
25
26
  persistentCache?: import('@wasm-idle/core').RuntimeAssetCacheOptions;
26
27
  debugMode?: BrowserDebugMode;
27
- /** @deprecated Use debugMode. true maps to trace unless the caller explicitly selects lldb. */
28
+ /** @deprecated Use debugMode. true follows the language's compatibility backend. */
28
29
  debug?: boolean;
29
30
  /** Keep the final run alive until the host explicitly stops or disposes it. */
30
31
  interactive?: boolean;
31
32
  breakpoints?: number[];
32
33
  sourceBreakpoints?: DebugSourceBreakpoints[];
34
+ debugSteppingOptions?: DebugSteppingOptions;
33
35
  pauseOnEntry?: boolean;
34
36
  stdin?: string;
35
37
  signal?: AbortSignal;
@@ -40,9 +42,15 @@ export interface SandboxExecutionOptions {
40
42
  workspaceFiles?: SandboxWorkspaceFile[];
41
43
  compileArgs?: string[];
42
44
  programArgs?: string[];
45
+ /** Requested environment overrides; a runtime may reject unsupported options. */
46
+ env?: Record<string, string>;
43
47
  cppVersion?: string;
44
48
  cVersion?: string;
49
+ /** Select GNU dialects for each C/C++ source unit in the Objective-C worker. */
50
+ objectivecGnuExtensions?: boolean;
45
51
  rustTargetTriple?: RustTargetTriple;
52
+ /** Optimizes the Rust user program while retaining overflow checks and debug assertions. */
53
+ rustOptimizationProfile?: RustOptimizationProfile;
46
54
  goTarget?: GoTarget;
47
55
  tinygoTarget?: TinyGoTarget;
48
56
  ocamlBackend?: OcamlBackend;