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
@@ -0,0 +1,315 @@
1
+ export function createJavaDebugRuntime(files, options, emit, read, respond = () => { }) {
2
+ const sources = new Map(files.map((file) => [file.path, file]));
3
+ const sourcePrefix = options.debugPath?.endsWith(`/${options.activePath}`)
4
+ ? options.debugPath.slice(0, -options.activePath.length)
5
+ : '';
6
+ const displayPath = (path) => path === options.activePath ? options.debugPath || path : `${sourcePrefix}${path}`;
7
+ const breakpoints = new Map();
8
+ let mode = options.pauseOnEntry ? 'entry' : 'continue';
9
+ let targetDepth = 0;
10
+ let targetSource = '';
11
+ let targetLine = 0;
12
+ let targetColumn = 0;
13
+ let pauseRequested = false;
14
+ let stop = 0;
15
+ let pausedFrameId;
16
+ let pausedScope;
17
+ let pendingInspection;
18
+ const references = new Set();
19
+ const referenceBase = () => stop * 100_000 + 1;
20
+ const variablePage = (value) => {
21
+ if (!Array.isArray(value) || value.length > 1000)
22
+ throw new Error('Invalid Java variable response');
23
+ return value.map((item) => {
24
+ if (!item ||
25
+ typeof item.name !== 'string' ||
26
+ typeof item.value !== 'string' ||
27
+ typeof item.type !== 'string' ||
28
+ !Number.isSafeInteger(item.variablesReference) ||
29
+ item.variablesReference < 0 ||
30
+ item.variablesReference > 4096 ||
31
+ (item.indexedVariables !== undefined &&
32
+ (!Number.isSafeInteger(item.indexedVariables) || item.indexedVariables < 0)))
33
+ throw new Error('Invalid Java variable descriptor');
34
+ const reference = item.variablesReference
35
+ ? referenceBase() + item.variablesReference
36
+ : 0;
37
+ if (reference)
38
+ references.add(reference);
39
+ return {
40
+ name: item.name,
41
+ value: item.value,
42
+ type: item.type,
43
+ variablesReference: reference,
44
+ ...(item.indexedVariables !== undefined
45
+ ? { indexedVariables: item.indexedVariables }
46
+ : {})
47
+ };
48
+ });
49
+ };
50
+ const setBreakpoints = (sourcePath, lines) => {
51
+ if (!Array.isArray(lines) ||
52
+ lines.length > 1024 ||
53
+ lines.some((line) => !Number.isSafeInteger(line) || line < 1))
54
+ throw new Error('Invalid Java breakpoint lines');
55
+ const file = files.find((file) => displayPath(file.path) === sourcePath);
56
+ const executable = [
57
+ ...new Set(file?.locations.map((location) => location.line) ?? [])
58
+ ].sort((a, b) => a - b);
59
+ const resolved = [...new Set(lines)].map((requestedLine) => {
60
+ const line = executable.find((line) => line >= requestedLine);
61
+ return {
62
+ requestedLine,
63
+ line: line ?? requestedLine,
64
+ verified: line !== undefined,
65
+ ...(line === undefined
66
+ ? { message: 'No instrumented Java statement at or after this line' }
67
+ : {})
68
+ };
69
+ });
70
+ breakpoints.set(sourcePath, new Set(resolved.filter((item) => item.verified).map((item) => item.line)));
71
+ emit({
72
+ type: 'breakpoints',
73
+ sourcePath,
74
+ sourceContentSha256: file?.sourceContentSha256,
75
+ breakpoints: resolved
76
+ });
77
+ };
78
+ const command = (blocking) => {
79
+ const raw = read(blocking);
80
+ if (raw === null)
81
+ throw new Error('Java debugger stopped');
82
+ if (!raw)
83
+ return null;
84
+ return JSON.parse(raw);
85
+ };
86
+ const update = (item) => {
87
+ if (item.op === 'breakpoints')
88
+ setBreakpoints(item.sourcePath, item.lines);
89
+ else if (item.op === 'pause')
90
+ pauseRequested = true;
91
+ };
92
+ const requestError = (item, message) => {
93
+ if (Number.isSafeInteger(item.id) && item.id > 0 && Number.isSafeInteger(item.stopId))
94
+ respond({ id: item.id, stopId: item.stopId, error: message });
95
+ };
96
+ const readPaused = () => {
97
+ for (;;) {
98
+ const item = command(true);
99
+ if (!item)
100
+ continue;
101
+ if (item.op === 'control') {
102
+ if (!['continue', 'stepInto', 'nextLine', 'stepOut'].includes(item.command))
103
+ throw new Error('Invalid Java debugger control');
104
+ mode = item.command;
105
+ pausedFrameId = undefined;
106
+ pausedScope = undefined;
107
+ references.clear();
108
+ pendingInspection = undefined;
109
+ emit({ type: 'resume', command: mode });
110
+ return null;
111
+ }
112
+ if (item.op === 'breakpoints' || item.op === 'pause') {
113
+ update(item);
114
+ continue;
115
+ }
116
+ if (!Number.isSafeInteger(item.id) ||
117
+ item.id < 1 ||
118
+ item.id > 2_147_483_647 ||
119
+ item.stopId !== stop) {
120
+ requestError(item, 'Java inspection request belongs to an earlier stop');
121
+ continue;
122
+ }
123
+ if (item.op === 'scopes') {
124
+ respond({
125
+ id: item.id,
126
+ stopId: stop,
127
+ value: item.frameId === pausedFrameId && pausedScope ? [pausedScope] : []
128
+ });
129
+ continue;
130
+ }
131
+ if (item.op === 'context') {
132
+ if (item.frameId !== pausedFrameId) {
133
+ requestError(item, 'Java values are available only for the currently stopped frame');
134
+ continue;
135
+ }
136
+ pendingInspection = { id: item.id, stopId: stop, op: item.op };
137
+ return { op: item.op, id: item.id, stopId: stop };
138
+ }
139
+ if (item.op === 'variables') {
140
+ const { reference, start = 0, count = 50 } = item;
141
+ if (!references.has(reference) ||
142
+ !Number.isSafeInteger(start) ||
143
+ start < 0 ||
144
+ !Number.isSafeInteger(count) ||
145
+ count < 0 ||
146
+ count > 1000) {
147
+ requestError(item, 'Invalid or stale Java variable page');
148
+ continue;
149
+ }
150
+ pendingInspection = { id: item.id, stopId: stop, op: item.op };
151
+ return {
152
+ op: item.op,
153
+ id: item.id,
154
+ stopId: stop,
155
+ reference: reference - referenceBase(),
156
+ start,
157
+ count
158
+ };
159
+ }
160
+ requestError(item, 'Unsupported Java inspection request');
161
+ }
162
+ };
163
+ setBreakpoints(displayPath(options.activePath), options.breakpoints);
164
+ for (const source of options.sourceBreakpoints ?? [])
165
+ setBreakpoints(source.sourcePath, source.lines);
166
+ return {
167
+ poll(source, line, _column) {
168
+ if (!sources.has(source))
169
+ throw new Error('Unknown Java debugger source');
170
+ for (let item; (item = command(false));) {
171
+ if (item.op === 'breakpoints' || item.op === 'pause')
172
+ update(item);
173
+ else
174
+ requestError(item, 'Java inspection requires a paused frame');
175
+ }
176
+ return pauseRequested ||
177
+ mode !== 'continue' ||
178
+ breakpoints.get(displayPath(source))?.has(line)
179
+ ? {}
180
+ : null;
181
+ },
182
+ pause(source, line, column, serialized, rawDepth, serializedVariables = '[]', totalVariables = 0) {
183
+ if (serialized.length > 1_000_000 || !Number.isSafeInteger(rawDepth) || rawDepth < 1)
184
+ throw new Error('Invalid Java debugger stack');
185
+ const raw = JSON.parse(serialized);
186
+ if (!Array.isArray(raw) || raw.length > 64)
187
+ throw new Error('Invalid Java debugger stack');
188
+ const frames = [];
189
+ for (const frame of raw) {
190
+ if (!Array.isArray(frame) ||
191
+ frame.length !== 4 ||
192
+ typeof frame[0] !== 'string' ||
193
+ typeof frame[1] !== 'string' ||
194
+ typeof frame[2] !== 'string' ||
195
+ !Number.isSafeInteger(frame[3]))
196
+ continue;
197
+ const packagePath = frame[0]
198
+ .slice(0, Math.max(0, frame[0].lastIndexOf('.')))
199
+ .replaceAll('.', '/');
200
+ const relativePath = packagePath ? `${packagePath}/${frame[2]}` : frame[2];
201
+ const candidates = files.filter((file) => file.path.split('/').pop() === frame[2]);
202
+ const exact = candidates.filter((file) => file.path === relativePath || file.path.endsWith(`/${relativePath}`));
203
+ const file = exact.length === 1
204
+ ? exact[0]
205
+ : candidates.length === 1
206
+ ? candidates[0]
207
+ : undefined;
208
+ if (!file || frame[3] < 1 || frame[3] > file.lineCount)
209
+ continue;
210
+ frames.push({
211
+ functionName: `${frame[0]}.${frame[1]}`,
212
+ line: frame[3],
213
+ sourcePath: displayPath(file.path),
214
+ sourceContentSha256: file.sourceContentSha256
215
+ });
216
+ }
217
+ const top = frames[0];
218
+ if (!top || top.sourcePath !== displayPath(source))
219
+ throw new Error('The Java runtime could not provide the current source stack');
220
+ const breakpoint = breakpoints.get(displayPath(source))?.has(line) === true;
221
+ const progressed = source !== targetSource ||
222
+ line !== targetLine ||
223
+ rawDepth !== targetDepth ||
224
+ column === targetColumn;
225
+ const stepping = mode === 'entry' ||
226
+ (mode === 'stepInto' && progressed) ||
227
+ (mode === 'nextLine' && rawDepth <= targetDepth && progressed) ||
228
+ (mode === 'stepOut' && rawDepth < targetDepth);
229
+ if (!pauseRequested && !breakpoint && !stepping)
230
+ return null;
231
+ const reason = pauseRequested
232
+ ? 'pause'
233
+ : breakpoint
234
+ ? 'breakpoint'
235
+ : mode === 'entry'
236
+ ? 'entry'
237
+ : mode === 'stepInto'
238
+ ? 'step'
239
+ : mode === 'stepOut'
240
+ ? 'stepOut'
241
+ : 'nextLine';
242
+ pauseRequested = false;
243
+ stop++;
244
+ if (stop > 2_147_483_647 ||
245
+ serializedVariables.length > 1_000_000 ||
246
+ !Number.isSafeInteger(totalVariables) ||
247
+ totalVariables < 0 ||
248
+ totalVariables > 1024)
249
+ throw new Error('Invalid Java local snapshot');
250
+ references.clear();
251
+ pendingInspection = undefined;
252
+ const locals = variablePage(JSON.parse(serializedVariables));
253
+ frames.forEach((frame, index) => {
254
+ frame.id = stop * 100 + index + 1;
255
+ });
256
+ top.line = line;
257
+ top.column = column;
258
+ pausedFrameId = top.id;
259
+ pausedScope = {
260
+ name: 'Locals',
261
+ variablesReference: referenceBase(),
262
+ namedVariables: totalVariables,
263
+ expensive: false,
264
+ variables: locals
265
+ };
266
+ references.add(referenceBase());
267
+ targetDepth = rawDepth;
268
+ targetSource = source;
269
+ targetLine = line;
270
+ targetColumn = column;
271
+ emit({
272
+ type: 'pause',
273
+ reason,
274
+ line,
275
+ sourcePath: top.sourcePath,
276
+ sourceContentSha256: top.sourceContentSha256,
277
+ frameId: top.id,
278
+ threadId: 1,
279
+ locals,
280
+ scopes: [pausedScope],
281
+ callStack: frames,
282
+ capabilities: { readMemory: false, writeMemory: false, dataBreakpoints: false }
283
+ }, stop);
284
+ return readPaused();
285
+ },
286
+ reply(id, stopId, serialized, error) {
287
+ const inspection = pendingInspection;
288
+ if (!inspection || inspection.id !== id || inspection.stopId !== stopId || !pausedScope)
289
+ throw new Error('Java inspection reply belongs to an earlier request');
290
+ pendingInspection = undefined;
291
+ try {
292
+ if (error)
293
+ respond({ id, stopId, error });
294
+ else {
295
+ if (typeof serialized !== 'string' || serialized.length > 1_000_000)
296
+ throw new Error('Invalid Java inspection response');
297
+ const value = JSON.parse(serialized);
298
+ respond({
299
+ id,
300
+ stopId,
301
+ value: inspection.op === 'variables' ? variablePage(value) : value
302
+ });
303
+ }
304
+ }
305
+ catch (failure) {
306
+ respond({
307
+ id,
308
+ stopId,
309
+ error: failure instanceof Error ? failure.message : 'Unable to inspect Java values'
310
+ });
311
+ }
312
+ return readPaused();
313
+ }
314
+ };
315
+ }
@@ -0,0 +1,11 @@
1
+ /** Bound output while synchronous Wasm owns the worker, including newline-free output. */
2
+ export declare function createJavaOutput(emit: (text: string) => void, options?: {
3
+ maxChars?: number;
4
+ maxDelayMs?: number;
5
+ now?: () => number;
6
+ }): {
7
+ write(charCode: number): void;
8
+ flush: () => void;
9
+ flushIfDue(): void;
10
+ close(): void;
11
+ };
@@ -0,0 +1,54 @@
1
+ /** Bound output while synchronous Wasm owns the worker, including newline-free output. */
2
+ export function createJavaOutput(emit, options = {}) {
3
+ const maxChars = options.maxChars ?? 16384;
4
+ const maxDelayMs = options.maxDelayMs ?? 16;
5
+ const now = options.now ?? (() => performance.now());
6
+ if (!Number.isSafeInteger(maxChars) ||
7
+ maxChars < 2 ||
8
+ !Number.isFinite(maxDelayMs) ||
9
+ maxDelayMs < 0)
10
+ throw new RangeError('Invalid Java output batch limits');
11
+ let text = '';
12
+ let hasEmitted = false;
13
+ let lastFlush = now();
14
+ let timer;
15
+ let closed = false;
16
+ function flush() {
17
+ if (timer !== undefined)
18
+ clearTimeout(timer);
19
+ timer = undefined;
20
+ if (!text)
21
+ return;
22
+ const output = text;
23
+ text = '';
24
+ hasEmitted = true;
25
+ lastFlush = now();
26
+ emit(output);
27
+ }
28
+ return {
29
+ write(charCode) {
30
+ if (closed)
31
+ return;
32
+ // A high surrogate is held until the next code unit, so output accounting
33
+ // does not encode a valid pair as two replacement characters.
34
+ if (text.length >= maxChars - 1 && !(charCode >= 0xdc00 && charCode <= 0xdfff))
35
+ flush();
36
+ text += String.fromCharCode(charCode);
37
+ if (charCode >= 0xd800 && charCode <= 0xdbff)
38
+ return;
39
+ if (text.length >= maxChars || !hasEmitted || now() - lastFlush >= maxDelayMs)
40
+ flush();
41
+ else if (timer === undefined)
42
+ timer = setTimeout(flush, maxDelayMs);
43
+ },
44
+ flush,
45
+ flushIfDue() {
46
+ if (text && now() - lastFlush >= maxDelayMs)
47
+ flush();
48
+ },
49
+ close() {
50
+ flush();
51
+ closed = true;
52
+ }
53
+ };
54
+ }
@@ -1,4 +1,5 @@
1
1
  import { waitForBufferedStdin } from '../stdinBuffer';
2
+ import { readLuaDebugCommand } from '../luaDebug';
2
3
  import { buildFennelCompileChunk, buildFennelRunChunk, loadFennelCompilerSource, parseFennelDiagnostic, stripHostLuaTraceback } from '../fennelBootstrap';
3
4
  let stdinBufferLua = null;
4
5
  let moduleUrl = '';
@@ -138,8 +139,20 @@ self.onmessage = async (event) => {
138
139
  }
139
140
  const hasInitialStdin = typeof stdin === 'string';
140
141
  let initialStdin = hasInitialStdin ? stdin : null;
142
+ if (event.data.debug && fennelSource)
143
+ throw new Error('Fennel source debugging is not supported.');
141
144
  const execution = await runtime.executeBrowserLuaArtifact(compiledArtifact, {
142
145
  args,
146
+ ...(event.data.debug
147
+ ? {
148
+ debug: {
149
+ breakpoints: event.data.breakpoints ?? [],
150
+ pauseOnEntry: event.data.pauseOnEntry !== false,
151
+ readCommand: (blocking) => readLuaDebugCommand(event.data.debugBuffer, blocking, () => postMessage({ debugCommandConsumed: true })),
152
+ onEvent: (debugEvent) => postMessage({ luaDebug: debugEvent })
153
+ }
154
+ }
155
+ : {}),
143
156
  onReady: () => postMessage({
144
157
  progress: {
145
158
  kind: 'ready',
@@ -182,9 +195,8 @@ self.onmessage = async (event) => {
182
195
  }
183
196
  });
184
197
  if (execution.exitCode !== 0) {
185
- const stderr = fennelSource
186
- ? stripHostLuaTraceback(execution.stderr)
187
- : execution.stderr;
198
+ // Lua stderr was already streamed above; Fennel stderr is only reported here.
199
+ const stderr = fennelSource ? stripHostLuaTraceback(execution.stderr) : '';
188
200
  throw new Error(stderr
189
201
  ? `${runtimeLabel} program exited with code ${execution.exitCode}\n${stderr}`
190
202
  : `${runtimeLabel} program exited with code ${execution.exitCode}`);
@@ -221,13 +221,20 @@ function readInitialStdin(code, initialStdin, log = true) {
221
221
  return initialStdin;
222
222
  if (!codeMightReadStdin(code))
223
223
  return '';
224
- const chunk = waitForBufferedStdin(stdinBufferPhp, () => postMessage({ buffer: true }));
225
- if (log) {
226
- console.log(chunk == null
227
- ? '[wasm-idle:php-stdin] read(bytes=0, eof=true)'
228
- : `[wasm-idle:php-stdin] read(bytes=${encoder.encode(chunk).byteLength}, text=${JSON.stringify(chunk)})`);
224
+ // PHP receives stdin as one request body before the program starts, so collect
225
+ // terminal input until EOF instead of dropping chunks typed after the first.
226
+ let input = '';
227
+ while (true) {
228
+ const chunk = waitForBufferedStdin(stdinBufferPhp, () => postMessage({ buffer: true }));
229
+ if (log) {
230
+ console.log(chunk == null
231
+ ? '[wasm-idle:php-stdin] read(bytes=0, eof=true)'
232
+ : `[wasm-idle:php-stdin] read(bytes=${encoder.encode(chunk).byteLength}, text=${JSON.stringify(chunk)})`);
233
+ }
234
+ if (chunk == null)
235
+ return input;
236
+ input += chunk;
229
237
  }
230
- return chunk || '';
231
238
  }
232
239
  self.onmessage = async (event) => {
233
240
  const { load, moduleUrl: nextModuleUrl, buffer, code, prepare, args = [], stdin, activePath = 'main.php', workspaceFiles = [], log } = event.data;
@@ -281,9 +288,8 @@ self.onmessage = async (event) => {
281
288
  if (response.errors)
282
289
  postMessage({ output: response.errors });
283
290
  if (response.exitCode !== 0) {
284
- throw new Error(response.errors
285
- ? `PHP program exited with code ${response.exitCode}\n${response.errors}`
286
- : `PHP program exited with code ${response.exitCode}`);
291
+ // response.errors was already posted as output above.
292
+ throw new Error(`PHP program exited with code ${response.exitCode}`);
287
293
  }
288
294
  if (log) {
289
295
  console.log(`[wasm-idle:php-worker] run settled exitCode=${response.exitCode}`);