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
@@ -0,0 +1,77 @@
1
+ import { createWasmIdleSharedBuffer, isSharedBufferBackedView } from './sharedBuffer';
2
+ const HEADER_BYTES = 16;
3
+ const COMMAND_BYTES = 65_536;
4
+ const MAX_QUEUED_COMMANDS = 64;
5
+ const encoder = new TextEncoder();
6
+ const decoder = new TextDecoder('utf-8', { fatal: true });
7
+ /** One published command plus a bounded UI queue; consumption wakes the next producer write. */
8
+ export class DebugCommandMailbox {
9
+ label;
10
+ buffer = createWasmIdleSharedBuffer(HEADER_BYTES + COMMAND_BYTES);
11
+ queued = [];
12
+ constructor(label = 'Lua') {
13
+ this.label = label;
14
+ }
15
+ reset() {
16
+ this.queued = [];
17
+ new Int32Array(this.buffer, 0, 4).fill(0);
18
+ }
19
+ send(command) {
20
+ const header = new Int32Array(this.buffer, 0, 4);
21
+ if (!isSharedBufferBackedView(header))
22
+ throw new Error(`${this.label} debugging requires SharedArrayBuffer.`);
23
+ if (Atomics.load(header, 2))
24
+ throw new Error(`${this.label} debugger is closed.`);
25
+ const bytes = encoder.encode(command);
26
+ if (!bytes.length || bytes.length > COMMAND_BYTES) {
27
+ throw new RangeError(`${this.label} debugger commands must contain 1–${COMMAND_BYTES} UTF-8 bytes.`);
28
+ }
29
+ if (this.queued.length >= MAX_QUEUED_COMMANDS)
30
+ throw new Error(`${this.label} debugger command queue is full.`);
31
+ this.queued.push(bytes);
32
+ this.flush();
33
+ }
34
+ flush() {
35
+ const header = new Int32Array(this.buffer, 0, 4);
36
+ if (!this.queued.length || Atomics.load(header, 1) !== 0 || Atomics.load(header, 2))
37
+ return;
38
+ const bytes = this.queued.shift();
39
+ new Uint8Array(this.buffer, HEADER_BYTES, bytes.length).set(bytes);
40
+ Atomics.store(header, 1, bytes.length);
41
+ Atomics.add(header, 0, 1);
42
+ Atomics.notify(header, 0);
43
+ }
44
+ close() {
45
+ this.queued = [];
46
+ const header = new Int32Array(this.buffer, 0, 4);
47
+ if (!isSharedBufferBackedView(header))
48
+ return;
49
+ Atomics.store(header, 2, 1);
50
+ Atomics.add(header, 0, 1);
51
+ Atomics.notify(header, 0);
52
+ }
53
+ }
54
+ export function readDebugCommand(buffer, blocking, onConsumed, label = 'Lua') {
55
+ const header = new Int32Array(buffer, 0, 4);
56
+ if (!isSharedBufferBackedView(header) || buffer.byteLength !== HEADER_BYTES + COMMAND_BYTES) {
57
+ throw new Error(`Invalid ${label} debugger command buffer.`);
58
+ }
59
+ for (;;) {
60
+ const sequence = Atomics.load(header, 0);
61
+ if (Atomics.load(header, 2))
62
+ return null;
63
+ const size = Atomics.load(header, 1);
64
+ if (size < 0 || size > COMMAND_BYTES)
65
+ throw new Error(`Invalid ${label} debugger command length.`);
66
+ if (size) {
67
+ // Browser TextDecoder rejects shared views; copy while this slot is owned by the reader.
68
+ const command = decoder.decode(new Uint8Array(buffer, HEADER_BYTES, size).slice());
69
+ Atomics.store(header, 1, 0);
70
+ onConsumed();
71
+ return command;
72
+ }
73
+ if (!blocking)
74
+ return '';
75
+ Atomics.wait(header, 0, sequence);
76
+ }
77
+ }
@@ -224,7 +224,12 @@ class Go {
224
224
  resetBufferedStdin(this.buffer);
225
225
  }
226
226
  run(code, prepare, _log = true, _prog, args = [], options = {}) {
227
- if (options.debug)
227
+ const debugMode = options.debugMode ?? (options.debug ? 'trace' : 'none');
228
+ if (debugMode !== 'none' && debugMode !== 'trace') {
229
+ return Promise.reject(new Error('Go native debugging is unavailable: the current Wasm linker does not emit DWARF. Use trace mode.'));
230
+ }
231
+ const debugEnabled = debugMode === 'trace';
232
+ if (debugEnabled)
228
233
  requireSharedArrayBuffer('Go debugging');
229
234
  if (!this.exit) {
230
235
  const error = new BusyError('Go runtime already has an active execution', {
@@ -253,8 +258,8 @@ class Go {
253
258
  const { programArgs } = resolveSandboxExecutionArgs('GO', args, options);
254
259
  const target = options.goTarget || 'wasip1/wasm';
255
260
  const _uid = ++this.uid;
256
- this.setBreakpoints(options.debug ? [...(options.breakpoints || [])] : []);
257
- const hasExplicitStdin = !options.debug && options.stdin !== undefined;
261
+ this.setBreakpoints(debugEnabled ? [...(options.breakpoints || [])] : []);
262
+ const hasExplicitStdin = !debugEnabled && options.stdin !== undefined;
258
263
  this.activeExplicitStdinCleanup?.();
259
264
  let explicitStdinCleaned = false;
260
265
  const cleanupExplicitStdin = () => {
@@ -415,7 +420,7 @@ class Go {
415
420
  args: programArgs,
416
421
  target,
417
422
  log: _log,
418
- debug: !!options.debug,
423
+ debug: debugEnabled,
419
424
  breakpoints: [...(options.breakpoints || [])],
420
425
  pauseOnEntry: !!options.pauseOnEntry,
421
426
  runtimeLimits: limits
@@ -113,7 +113,7 @@ function followsLiteralType(tokens, braceIndex, closedFrame) {
113
113
  }
114
114
  return open === index - 1 || tokens[open - 1] === 'map';
115
115
  }
116
- function lineTokens(line, state) {
116
+ function lineTokens(line, state, onWord) {
117
117
  const tokens = [];
118
118
  const wordPattern = /[\p{L}_][\p{L}\p{N}_]*|\.?\d[\p{L}\p{N}_.]*/uy;
119
119
  let index = 0;
@@ -160,6 +160,7 @@ function lineTokens(line, state) {
160
160
  if (word) {
161
161
  tokens.push(/^[\p{L}_]/u.test(word) ? word : '0');
162
162
  index += word.length;
163
+ onWord?.(word, index);
163
164
  continue;
164
165
  }
165
166
  const operator = ['++', '--', ':=', '...'].find((candidate) => line.startsWith(candidate, index)) ||
@@ -194,50 +195,27 @@ function shouldInstrumentLine(line) {
194
195
  }
195
196
  function insertDebugImports(source) {
196
197
  const lines = source.split('\n');
197
- const packageIndex = lines.findIndex((line) => /^\s*package\s+\w+/.test(line));
198
- if (packageIndex === -1)
199
- return source;
200
- const importStart = lines.findIndex((line, index) => index > packageIndex && /^\s*import\b/.test(line));
201
- if (importStart === -1) {
202
- lines.splice(packageIndex + 1, 0, '', 'import (', ...debugImports.map((entry) => `\t${entry}`), ')');
203
- return lines.join('\n');
204
- }
205
- const importLine = lines[importStart] || '';
206
- if (/^\s*import\s*\(/.test(importLine)) {
207
- let importEnd = importStart + 1;
208
- for (; importEnd < lines.length; importEnd += 1) {
209
- if (/^\s*\)/.test(lines[importEnd] || ''))
210
- break;
211
- }
212
- lines.splice(importEnd, 0, ...debugImports.map((entry) => `\t${entry}`));
198
+ const state = { rawString: false, blockComment: false };
199
+ let packageKeyword = false;
200
+ for (let index = 0; index < lines.length; index += 1) {
201
+ const line = lines[index];
202
+ let packageNameEnd;
203
+ lineTokens(line, state, (word, end) => {
204
+ if (packageNameEnd !== undefined)
205
+ return;
206
+ if (packageKeyword)
207
+ packageNameEnd = end;
208
+ else if (word === 'package')
209
+ packageKeyword = true;
210
+ });
211
+ if (packageNameEnd === undefined)
212
+ continue;
213
+ // Insert before trailing comments, which may span lines or end beside an import.
214
+ // Keep the suffix on ')' so an explicit package semicolon still terminates a declaration.
215
+ lines.splice(index, 1, line.slice(0, packageNameEnd), '', 'import (', ...debugImports.map((entry) => `\t${entry}`), ')' + line.slice(packageNameEnd));
213
216
  return lines.join('\n');
214
217
  }
215
- const singleImport = importLine.replace(/^\s*import\s+/, '').trim();
216
- lines.splice(importStart, 1, 'import (', `\t${singleImport}`, ...debugImports.map((entry) => `\t${entry}`), ')');
217
- return lines.join('\n');
218
- }
219
- function insertDebugSupport(source) {
220
- const lines = source.split('\n');
221
- let insertIndex = lines.findIndex((line) => /^\s*import\b/.test(line));
222
- if (insertIndex === -1) {
223
- insertIndex = lines.findIndex((line) => /^\s*package\s+\w+/.test(line));
224
- if (insertIndex === -1)
225
- return source;
226
- insertIndex += 1;
227
- }
228
- else if (/^\s*import\s*\(/.test(lines[insertIndex] || '')) {
229
- for (; insertIndex < lines.length; insertIndex += 1) {
230
- if (/^\s*\)/.test(lines[insertIndex] || '')) {
231
- insertIndex += 1;
232
- break;
233
- }
234
- }
235
- }
236
- else {
237
- insertIndex += 1;
238
- }
239
- lines.splice(insertIndex, 0, debugSupportSource.trim());
240
- return lines.join('\n');
218
+ return source;
241
219
  }
242
220
  function instrumentFunctionLines(source) {
243
221
  const lines = source.split('\n');
@@ -355,5 +333,7 @@ function instrumentFunctionLines(source) {
355
333
  export function instrumentGoDebugSource(source) {
356
334
  if (source.includes('__wasmIdleDebugLine'))
357
335
  return source;
358
- return insertDebugSupport(insertDebugImports(instrumentFunctionLines(source)));
336
+ // Declarations may follow user code; placing them here keeps every user import
337
+ // ahead of declarations, including a second import block.
338
+ return `${insertDebugImports(instrumentFunctionLines(source))}\n\n${debugSupportSource.trim()}\n`;
359
339
  }