wasm-idle 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +134 -82
  2. package/dist/container/bash-profile.d.ts +80 -0
  3. package/dist/container/bash-profile.js +328 -0
  4. package/dist/{playground/container → container}/binding.d.ts +21 -8
  5. package/dist/{playground/container → container}/binding.js +109 -25
  6. package/dist/{playground/container → container}/clang-runtime.d.ts +11 -7
  7. package/dist/container/clang-runtime.js +561 -0
  8. package/dist/container/client.d.ts +14 -0
  9. package/dist/{playground/container → container}/client.js +2 -6
  10. package/dist/{playground/container → container}/explorer.d.ts +1 -1
  11. package/dist/container/index.d.ts +11 -0
  12. package/dist/container/index.js +11 -0
  13. package/dist/container/owner-worker.d.ts +19 -0
  14. package/dist/container/owner-worker.js +464 -0
  15. package/dist/{playground/container → container}/protocol.d.ts +12 -1
  16. package/dist/{playground/container → container}/runtime-adapter.d.ts +13 -11
  17. package/dist/{playground/container → container}/runtime-adapter.js +104 -41
  18. package/dist/{playground/container → container}/shell-control.d.ts +2 -2
  19. package/dist/{playground/container → container}/shell-control.js +93 -36
  20. package/dist/{playground/container → container}/workspace.d.ts +5 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/playground/assetBridge.js +5 -2
  23. package/dist/playground/assets.d.ts +8 -0
  24. package/dist/playground/clang.d.ts +5 -1
  25. package/dist/playground/clang.js +61 -5
  26. package/dist/playground/compiledLldb.d.ts +41 -0
  27. package/dist/playground/compiledLldb.js +167 -0
  28. package/dist/playground/d.d.ts +4 -1
  29. package/dist/playground/d.js +78 -9
  30. package/dist/playground/debugDeadline.d.ts +12 -0
  31. package/dist/playground/debugDeadline.js +34 -0
  32. package/dist/playground/debugMailbox.d.ts +12 -0
  33. package/dist/playground/debugMailbox.js +77 -0
  34. package/dist/playground/go.js +9 -4
  35. package/dist/playground/goDebugInstrumentation.js +24 -44
  36. package/dist/playground/java-debug-FMHDKUN6.js +124 -0
  37. package/dist/playground/java-debug-notices.txt +492 -0
  38. package/dist/playground/java.d.ts +17 -1
  39. package/dist/playground/java.js +159 -3
  40. package/dist/playground/javaDebug.d.ts +62 -0
  41. package/dist/playground/javaDebug.js +305 -0
  42. package/dist/playground/javaDebugBridge.d.ts +6 -0
  43. package/dist/playground/javaDebugBridge.js +250 -0
  44. package/dist/playground/javaDebugSource.d.ts +9 -0
  45. package/dist/playground/javaDebugSource.js +4 -0
  46. package/dist/playground/javaRuntimeErrors.js +34 -1
  47. package/dist/playground/lean4Assets.d.ts +1 -25
  48. package/dist/playground/lean4Assets.js +2 -123
  49. package/dist/playground/lfortranAssets.d.ts +2 -2
  50. package/dist/playground/lldbSession.d.ts +23 -2
  51. package/dist/playground/lldbSession.js +278 -58
  52. package/dist/playground/lldbSourcePath.d.ts +2 -0
  53. package/dist/playground/lldbSourcePath.js +9 -0
  54. package/dist/playground/lua.d.ts +20 -1
  55. package/dist/playground/lua.js +190 -8
  56. package/dist/playground/luaDebug.d.ts +1 -0
  57. package/dist/playground/luaDebug.js +1 -0
  58. package/dist/playground/nim.d.ts +1 -0
  59. package/dist/playground/nim.js +8 -0
  60. package/dist/playground/objectivec.d.ts +7 -6
  61. package/dist/playground/objectivec.js +75 -9
  62. package/dist/playground/options.d.ts +10 -4
  63. package/dist/playground/python.d.ts +8 -1
  64. package/dist/playground/python.js +81 -6
  65. package/dist/playground/ruby.d.ts +10 -1
  66. package/dist/playground/ruby.js +66 -1
  67. package/dist/playground/rubyDebug.d.ts +21 -0
  68. package/dist/playground/rubyDebug.js +128 -0
  69. package/dist/playground/rust.d.ts +5 -1
  70. package/dist/playground/rust.js +128 -46
  71. package/dist/playground/sandbox.d.ts +8 -1
  72. package/dist/playground/staticWorkerRuntime.js +8 -2
  73. package/dist/playground/stdinBuffer.d.ts +1 -1
  74. package/dist/playground/stdinBuffer.js +19 -2
  75. package/dist/playground/tinygo.js +7 -0
  76. package/dist/playground/typescript.js +8 -0
  77. package/dist/playground/v.d.ts +3 -2
  78. package/dist/playground/v.js +66 -12
  79. package/dist/playground/wasmC3Version.d.ts +2 -2
  80. package/dist/playground/wasmC3Version.js +2 -2
  81. package/dist/playground/wasmLean4Version.d.ts +1 -110
  82. package/dist/playground/wasmLean4Version.js +2 -111
  83. package/dist/playground/wasmLfortranVersion.d.ts +2 -2
  84. package/dist/playground/wasmLfortranVersion.js +2 -2
  85. package/dist/playground/wasmLuaVersion.d.ts +1 -1
  86. package/dist/playground/wasmLuaVersion.js +1 -1
  87. package/dist/playground/wasmRustVersion.d.ts +26 -38
  88. package/dist/playground/wasmRustVersion.js +25 -40
  89. package/dist/playground/worker/clang.js +1 -1
  90. package/dist/playground/worker/cobol.js +1 -1
  91. package/dist/playground/worker/d.js +51 -2
  92. package/dist/playground/worker/fortran.js +1 -1
  93. package/dist/playground/worker/java.js +188 -35
  94. package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
  95. package/dist/playground/worker/javaDebugEvaluator.js +44 -0
  96. package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
  97. package/dist/playground/worker/javaDebugRuntime.js +315 -0
  98. package/dist/playground/worker/javaOutput.d.ts +11 -0
  99. package/dist/playground/worker/javaOutput.js +54 -0
  100. package/dist/playground/worker/lua.js +13 -0
  101. package/dist/playground/worker/python.js +57 -22
  102. package/dist/playground/worker/ruby.js +13 -0
  103. package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
  104. package/dist/playground/worker/rubyDebugPreview.js +80 -0
  105. package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
  106. package/dist/playground/worker/rubyTracepoint.js +162 -0
  107. package/dist/playground/worker/rust.js +4 -1
  108. package/dist/playground/worker/v.js +30 -5
  109. package/dist/playground/zig.js +4 -0
  110. package/package.json +55 -11
  111. package/dist/playground/container/ContainerExplorer.svelte +0 -307
  112. package/dist/playground/container/ContainerExplorer.svelte.d.ts +0 -14
  113. package/dist/playground/container/clang-runtime.js +0 -343
  114. package/dist/playground/container/client.d.ts +0 -15
  115. package/dist/playground/container/owner.worker.d.ts +0 -1
  116. package/dist/playground/container/owner.worker.js +0 -390
  117. package/dist/playground/container/release.d.ts +0 -31
  118. package/dist/playground/container/release.js +0 -612
  119. /package/dist/{playground/container → container}/explorer.js +0 -0
  120. /package/dist/{playground/container → container}/protocol.js +0 -0
  121. /package/dist/{playground/container → container}/workspace.js +0 -0
@@ -0,0 +1,80 @@
1
+ /** Automatic locals must not dispatch user inspection or container overrides. */
2
+ export const RUBY_DEBUG_PREVIEW = String.raw `
3
+ debug_class = Kernel.instance_method(:class)
4
+ debug_equal = BasicObject.instance_method(:equal?)
5
+ debug_type_name = Module.instance_method(:name)
6
+ debug_string_slice = String.instance_method(:byteslice)
7
+ debug_string_size = String.instance_method(:bytesize)
8
+ debug_string_length = String.instance_method(:length)
9
+ debug_string_characters = String.instance_method(:[])
10
+ debug_string_encode = String.instance_method(:encode)
11
+ debug_string_inspect = String.instance_method(:inspect)
12
+ debug_integer_bits = Integer.instance_method(:bit_length)
13
+ debug_integer_text = Integer.instance_method(:to_s)
14
+ debug_integer_greater = Integer.instance_method(:>)
15
+ debug_integer_at_least = Integer.instance_method(:>=)
16
+ debug_integer_at_most = Integer.instance_method(:<=)
17
+ debug_integer_add = Integer.instance_method(:+)
18
+ debug_float_text = Float.instance_method(:to_s)
19
+ debug_symbol_name = Symbol.instance_method(:name)
20
+ debug_array_size = Array.instance_method(:length)
21
+ debug_array_get = Array.instance_method(:[])
22
+ debug_array_append = Array.instance_method(:<<)
23
+ debug_array_join = Array.instance_method(:join)
24
+ debug_hash_size = Hash.instance_method(:length)
25
+ debug_hash_each = Hash.instance_method(:each_pair)
26
+ preview_join = ->(*parts) { debug_array_join.bind_call(parts, '') }
27
+ preview_type = ->(value) do
28
+ kind = debug_class.bind_call(value)
29
+ name = debug_type_name.bind_call(kind)
30
+ name ? debug_string_encode.bind_call(debug_string_slice.bind_call(name, 0, 64), 'UTF-8', invalid: :replace, undef: :replace) : 'Object'
31
+ rescue StandardError
32
+ 'Object'
33
+ end
34
+ preview_value = nil
35
+ preview_value = ->(value, depth = 0) do
36
+ next '...' if debug_integer_at_least.bind_call(depth, 2)
37
+ next 'nil' if debug_equal.bind_call(value, nil)
38
+ next 'true' if debug_equal.bind_call(value, true)
39
+ next 'false' if debug_equal.bind_call(value, false)
40
+ kind = debug_class.bind_call(value)
41
+ text = if debug_equal.bind_call(kind, Integer)
42
+ bits = debug_integer_bits.bind_call(value)
43
+ debug_integer_at_most.bind_call(bits, 256) ? debug_integer_text.bind_call(value) : preview_join.call('<Integer: ', debug_integer_text.bind_call(bits), ' bits>')
44
+ elsif debug_equal.bind_call(kind, Float)
45
+ debug_float_text.bind_call(value)
46
+ elsif debug_equal.bind_call(kind, String) || debug_equal.bind_call(kind, Symbol)
47
+ string = debug_equal.bind_call(kind, Symbol) ? debug_symbol_name.bind_call(value) : value
48
+ prefix = debug_string_slice.bind_call(string, 0, 128)
49
+ prefix = debug_string_encode.bind_call(prefix, 'UTF-8', invalid: :replace, undef: :replace)
50
+ quoted = debug_string_inspect.bind_call(prefix)
51
+ preview_join.call(debug_equal.bind_call(kind, Symbol) ? ':' : '', quoted, debug_integer_greater.bind_call(debug_string_size.bind_call(string), 128) ? '...' : '')
52
+ elsif debug_equal.bind_call(kind, Array)
53
+ size = debug_array_size.bind_call(value)
54
+ items = []
55
+ limit = debug_integer_greater.bind_call(size, 8) ? 8 : size
56
+ # Integer#times can dispatch an overridden #succ in the pinned Ruby runtime.
57
+ index = 0
58
+ while debug_integer_greater.bind_call(limit, index)
59
+ debug_array_append.bind_call(items, preview_value.call(debug_array_get.bind_call(value, index), debug_integer_add.bind_call(depth, 1)))
60
+ index = debug_integer_add.bind_call(index, 1)
61
+ end
62
+ debug_array_append.bind_call(items, '...') if debug_integer_greater.bind_call(size, 8)
63
+ preview_join.call('[', debug_array_join.bind_call(items, ', '), ']')
64
+ elsif debug_equal.bind_call(kind, Hash)
65
+ items = []
66
+ debug_hash_each.bind_call(value) do |key, item|
67
+ next_depth = debug_integer_add.bind_call(depth, 1)
68
+ debug_array_append.bind_call(items, preview_join.call(preview_value.call(key, next_depth), '=>', preview_value.call(item, next_depth)))
69
+ break if debug_integer_at_least.bind_call(debug_array_size.bind_call(items), 6)
70
+ end
71
+ debug_array_append.bind_call(items, '...') if debug_integer_greater.bind_call(debug_hash_size.bind_call(value), 6)
72
+ preview_join.call('{', debug_array_join.bind_call(items, ', '), '}')
73
+ else
74
+ preview_join.call('<', preview_type.call(value), ' object>')
75
+ end
76
+ debug_integer_greater.bind_call(debug_string_length.bind_call(text), 512) ? preview_join.call(debug_string_characters.bind_call(text, 0, 509), '...') : text
77
+ rescue StandardError
78
+ preview_join.call('<', preview_type.call(value), ' object>')
79
+ end
80
+ `;
@@ -0,0 +1,16 @@
1
+ import type { DebugSourceBreakpoints } from '../options';
2
+ export interface RubyTracepointOptions {
3
+ path: string;
4
+ debugPath?: string;
5
+ breakpoints: number[];
6
+ sourceBreakpoints?: DebugSourceBreakpoints[];
7
+ pauseOnEntry: boolean;
8
+ files: Array<{
9
+ path: string;
10
+ content: string;
11
+ }>;
12
+ }
13
+ /** Real CRuby TracePoint and Binding APIs; user source is passed unchanged as eval data. */
14
+ export declare function executeRubyTracepoint(vm: {
15
+ eval(source: string): unknown;
16
+ }, source: string, options: RubyTracepointOptions, notify: (message: any) => void, read: (blocking: boolean) => string | null): Promise<void>;
@@ -0,0 +1,162 @@
1
+ import { RUBY_DEBUG_PREVIEW } from './rubyDebugPreview';
2
+ /** Real CRuby TracePoint and Binding APIs; user source is passed unchanged as eval data. */
3
+ export async function executeRubyTracepoint(vm, source, options, notify, read) {
4
+ const files = [...options.files, { path: options.path, content: source }];
5
+ const hashes = {};
6
+ for (const file of files) {
7
+ const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(file.content));
8
+ hashes[file.path] = [...new Uint8Array(digest)]
9
+ .map((byte) => byte.toString(16).padStart(2, '0'))
10
+ .join('');
11
+ }
12
+ const key = `__wasmIdleRubyDebug_${crypto.randomUUID().replaceAll('-', '')}`;
13
+ const globals = globalThis;
14
+ globals[key] = {
15
+ notify: (json) => {
16
+ if (json.length > 2_000_000)
17
+ throw new Error('Ruby debugger snapshot exceeds its limit');
18
+ notify(JSON.parse(json));
19
+ },
20
+ read: (blocking) => read(blocking) ?? '{"op":"stop"}'
21
+ };
22
+ const data = JSON.stringify({ ...options, source, files, hashes, key });
23
+ const literal = `'${data.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
24
+ try {
25
+ vm.eval(String.raw `
26
+ require 'json'
27
+ require 'js'
28
+ Class.new do
29
+ def self.run(settings)
30
+ bridge = JS.global[settings['key']]
31
+ send_event = ->(value) { bridge.call(:notify, JSON.generate(value)) }
32
+ read_command = ->(blocking) do
33
+ text = bridge.call(:read, blocking).to_s
34
+ text.empty? ? nil : JSON.parse(text)
35
+ end
36
+ display_path = ->(path) do
37
+ path = path == settings['path'] ? (settings['debugPath'] || path) : path
38
+ '/workspace/' + path.sub(%r{\A(?:/workspace/|/+)}, '')
39
+ end
40
+ known = settings['files'].to_h { |file| [file['path'], file['content']] }
41
+ breakpoints = {}
42
+ executable = {}
43
+ known.each do |path, content|
44
+ next unless path == settings['path'] || path.end_with?('.rb')
45
+ begin
46
+ lines = []
47
+ collect = ->(iseq) do
48
+ lines.concat(iseq.trace_points.select { |_, event| event == :line }.map(&:first))
49
+ iseq.each_child { |child| collect.call(child) }
50
+ end
51
+ collect.call(RubyVM::InstructionSequence.compile(content, path, path, 1))
52
+ executable[display_path.call(path)] = lines.uniq.sort
53
+ rescue NameError, NoMethodError, SyntaxError
54
+ executable[display_path.call(path)] = []
55
+ end
56
+ end
57
+ set_breakpoints = ->(path, lines) do
58
+ path = display_path.call(path)
59
+ available = executable[path] || []
60
+ resolved = lines.uniq.map do |line|
61
+ actual = available.find { |candidate| candidate >= line }
62
+ {requestedLine:line, line:actual || line, verified:!actual.nil?, message:actual ? nil : 'No executable Ruby line'}
63
+ end
64
+ breakpoints[path] = resolved.select { |item| item[:verified] }.map { |item| item[:line] }
65
+ send_event.call({event:{type:'breakpoints',sourcePath:path,breakpoints:resolved}})
66
+ end
67
+ set_breakpoints.call(display_path.call(settings['path']), settings['breakpoints'])
68
+ (settings['sourceBreakpoints'] || []).each { |item| set_breakpoints.call(item['sourcePath'], item['lines']) }
69
+ format_value = ->(value) do
70
+ begin
71
+ value.inspect.encode('UTF-8', invalid: :replace, undef: :replace)[0,512]
72
+ rescue Exception => error
73
+ '<' + error.class.to_s + ' while inspecting>'
74
+ end
75
+ end
76
+ ${RUBY_DEBUG_PREVIEW}
77
+ local_values = ->(binding) do
78
+ binding.local_variables.first(50).map do |name|
79
+ value = binding.local_variable_get(name)
80
+ {name:name.to_s,value:preview_value.call(value),type:preview_type.call(value),variablesReference:0}
81
+ end
82
+ end
83
+ frames = []
84
+ mode = settings['pauseOnEntry'] ? 'entry' : 'continue'
85
+ target_depth = 0
86
+ pause_requested = false
87
+ stop_number = 0
88
+ trace = TracePoint.new(:line, :call, :return, :b_call, :b_return, :class, :end) do |point|
89
+ path = point.path.sub(%r{\A/+}, '')
90
+ next unless known.key?(path)
91
+ case point.event
92
+ when :return, :b_return, :end
93
+ frames.pop unless frames.empty?
94
+ next
95
+ when :call, :b_call, :class
96
+ frames << {binding:point.binding,path:path,line:point.lineno,name:point.method_id.to_s.empty? ? '<block>' : point.method_id.to_s}
97
+ next
98
+ end
99
+ frames << {binding:point.binding,path:path,line:point.lineno,name:'<main>'} if frames.empty?
100
+ frame = frames.last
101
+ frame[:binding] = point.binding
102
+ frame[:path] = path
103
+ frame[:line] = point.lineno
104
+ while (command = read_command.call(false))
105
+ case command['op']
106
+ when 'stop' then raise Interrupt, 'Ruby debugger stopped'
107
+ when 'pause' then pause_requested = true
108
+ when 'breakpoints' then set_breakpoints.call(command['sourcePath'], command['lines'])
109
+ end
110
+ end
111
+ breakpoint = (breakpoints[display_path.call(path)] || []).include?(point.lineno)
112
+ stepping = mode == 'entry' || mode == 'stepInto' || (mode == 'nextLine' && frames.length <= target_depth) || (mode == 'stepOut' && frames.length < target_depth)
113
+ next unless pause_requested || breakpoint || stepping
114
+ reason = pause_requested ? 'pause' : breakpoint ? 'breakpoint' : mode == 'entry' ? 'entry' : mode == 'stepInto' ? 'step' : mode
115
+ pause_requested = false
116
+ stop_number += 1
117
+ bindings = {}
118
+ snapshots = frames.reverse.first(32).each_with_index.map do |item, index|
119
+ id = stop_number * 1000 + index + 1
120
+ bindings[id] = item[:binding]
121
+ {id:id,functionName:item[:name],line:item[:line],sourcePath:display_path.call(item[:path]),sourceContentSha256:settings['hashes'][item[:path]],locals:local_values.call(item[:binding])}
122
+ end
123
+ top = snapshots.first
124
+ send_event.call({frames:snapshots,event:{type:'pause',reason:reason,line:top[:line],sourcePath:top[:sourcePath],sourceContentSha256:top[:sourceContentSha256],frameId:top[:id],threadId:1,locals:top[:locals],callStack:snapshots.map { |item| item.reject { |key,_| key == :locals } },scopes:[{name:'Locals',variablesReference:top[:id],namedVariables:top[:locals].length,expensive:false,variables:top[:locals]}],capabilities:{readMemory:false,writeMemory:false,dataBreakpoints:false}}})
125
+ loop do
126
+ command = read_command.call(true)
127
+ next unless command
128
+ case command['op']
129
+ when 'stop' then raise Interrupt, 'Ruby debugger stopped'
130
+ when 'breakpoints' then set_breakpoints.call(command['sourcePath'], command['lines'])
131
+ when 'evaluate'
132
+ begin
133
+ binding = bindings.fetch(command['frameId'])
134
+ value = format_value.call(binding.eval(command['expression']))
135
+ send_event.call({response:{id:command['id'],value:value}})
136
+ rescue Exception => error
137
+ send_event.call({response:{id:command['id'],error:error.class.to_s + ': ' + error.message}})
138
+ end
139
+ when 'control'
140
+ mode = command['command']
141
+ target_depth = frames.length
142
+ send_event.call({event:{type:'resume',command:mode}})
143
+ break
144
+ end
145
+ end
146
+ end
147
+ begin
148
+ trace.enable
149
+ eval(settings['source'], TOPLEVEL_BINDING, settings['path'], 1)
150
+ ensure
151
+ trace.disable
152
+ STDOUT.flush
153
+ STDERR.flush
154
+ end
155
+ end
156
+ end.run(JSON.parse(${literal}))
157
+ `);
158
+ }
159
+ finally {
160
+ delete globals[key];
161
+ }
162
+ }
@@ -406,7 +406,7 @@ function createRustDebugHost(options) {
406
406
  };
407
407
  }
408
408
  self.onmessage = async (event) => {
409
- const { load, persistentCache, compilerUrl: nextCompilerUrl, runtimeProfile: nextRuntimeProfile, verifiedModuleUrls: nextVerifiedModuleUrls, executableGraphFingerprint: nextExecutableGraphFingerprint, debugModuleUrl: nextDebugModuleUrl, buffer, debugBuffer, code, prepare, args = [], stdin, targetTriple = 'wasm32-wasip1', log, debug = false, debugMode: requestedDebugMode, breakpoints = [], pauseOnEntry = false, limits: executionLimits } = event.data;
409
+ const { load, persistentCache, compilerUrl: nextCompilerUrl, runtimeProfile: nextRuntimeProfile, verifiedModuleUrls: nextVerifiedModuleUrls, executableGraphFingerprint: nextExecutableGraphFingerprint, debugModuleUrl: nextDebugModuleUrl, buffer, debugBuffer, code, prepare, args = [], stdin, targetTriple = 'wasm32-wasip1', optimizationProfile: requestedOptimizationProfile = 'interactive', log, debug = false, debugMode: requestedDebugMode, breakpoints = [], pauseOnEntry = false, limits: executionLimits } = event.data;
410
410
  const nextRustcModuleBroker = event.data.rustcModuleBroker;
411
411
  let rustcModuleBroker;
412
412
  let ownsExecution = false;
@@ -452,6 +452,7 @@ self.onmessage = async (event) => {
452
452
  if (debugMode !== 'none' && debugMode !== 'trace' && debugMode !== 'lldb') {
453
453
  throw new Error(`Unsupported Rust debug mode: ${String(debugMode)}`);
454
454
  }
455
+ const optimizationProfile = debugMode === 'none' ? requestedOptimizationProfile : 'interactive';
455
456
  const nonDebugResourceLimits = debugMode === 'none' ? snapshotRustNonDebugResourceLimits(executionLimits) : undefined;
456
457
  stdinBufferRust = new Int32Array(buffer);
457
458
  debugBufferRust = debugBuffer ? new Int32Array(debugBuffer) : null;
@@ -485,6 +486,7 @@ self.onmessage = async (event) => {
485
486
  const compileCacheKey = [
486
487
  executableGraphFingerprint,
487
488
  debugMode,
489
+ optimizationProfile,
488
490
  targetTriple,
489
491
  ...(nonDebugResourceLimits
490
492
  ? [String(nonDebugResourceLimits.maxAssetDeliveryBytes)]
@@ -519,6 +521,7 @@ self.onmessage = async (event) => {
519
521
  ...(assetCache ? { assetCache } : {}),
520
522
  code: compileCode,
521
523
  debugMode,
524
+ optimizationProfile,
522
525
  ...(nonDebugResourceLimits
523
526
  ? {
524
527
  workerLimits: nonDebugResourceLimits.compilerLimits,
@@ -1,3 +1,4 @@
1
+ import { normalizeLldbWorkspacePath } from '../lldbSourcePath';
1
2
  import { waitForBufferedStdin } from '../stdinBuffer';
2
3
  import { configureWorkerRuntimeAssets, handleWorkerAssetMessage } from './assets';
3
4
  import { createVCompiler, executeBrowserVArtifact } from '@wasm-idle/llvm-core/v';
@@ -44,7 +45,7 @@ async function loadVRuntime(clangAssets, vBaseUrl, maxAssetBytes, log) {
44
45
  self.onmessage = async (event) => {
45
46
  if (handleWorkerAssetMessage(event.data))
46
47
  return;
47
- const { code, buffer, load, log, prepare, compileArgs, programArgs, activePath, workspaceFiles, stdin, clangAssets, vBaseUrl, maxAssetBytes } = event.data;
48
+ const { code, buffer, load, log, prepare, compileArgs, programArgs, activePath, workspaceFiles, stdin, clangAssets, vBaseUrl, maxAssetBytes, debugMode } = event.data;
48
49
  if (load) {
49
50
  try {
50
51
  await loadVRuntime(clangAssets, vBaseUrl, maxAssetBytes, log);
@@ -54,7 +55,7 @@ self.onmessage = async (event) => {
54
55
  postMessage({ error: error?.message || String(error) });
55
56
  }
56
57
  }
57
- else if (typeof log === 'boolean' && !code) {
58
+ else if (code === '' || (typeof log === 'boolean' && code === undefined)) {
58
59
  // The compiler receives the current logging preference for every compilation.
59
60
  if (typeof code === 'string')
60
61
  postMessage({ results: true });
@@ -69,10 +70,16 @@ self.onmessage = async (event) => {
69
70
  initialStdinV = hasInitialStdinV ? stdin : null;
70
71
  initialStdinConsumedV = false;
71
72
  try {
72
- const files = (workspaceFiles || []);
73
+ const lldb = debugMode === 'lldb';
74
+ const files = (workspaceFiles || []).map((file) => ({
75
+ ...file,
76
+ path: lldb ? normalizeLldbWorkspacePath(file.path) : file.path
77
+ }));
78
+ const fileName = resolveInputPath(lldb ? normalizeLldbWorkspacePath(activePath || '') : activePath);
73
79
  const result = await compiler.compile({
74
- code: ensureTrailingNewline(code),
75
- fileName: resolveInputPath(activePath),
80
+ code: lldb ? code : ensureTrailingNewline(code),
81
+ fileName,
82
+ debugMode: lldb ? 'lldb' : 'none',
76
83
  compileArgs: compileArgs || [],
77
84
  workspaceFiles: files,
78
85
  log,
@@ -85,6 +92,24 @@ self.onmessage = async (event) => {
85
92
  if (!result.success || !result.artifact) {
86
93
  throw new Error(result.stderr || 'V did not produce a WebAssembly program.');
87
94
  }
95
+ if (lldb && !prepare) {
96
+ const descriptor = result.artifact.debug;
97
+ if (!descriptor)
98
+ throw new Error('V compiler did not produce a DWARF descriptor.');
99
+ const sources = new Map(files.map((file) => [`/workspace/${file.path}`, file.content]));
100
+ sources.set(`/workspace/${fileName}`, code);
101
+ postMessage({
102
+ lldbArtifact: {
103
+ bytes: result.artifact.bytes,
104
+ descriptor,
105
+ sources: descriptor.files.map((file) => ({
106
+ ...file,
107
+ content: sources.get(file.path)
108
+ }))
109
+ }
110
+ });
111
+ return;
112
+ }
88
113
  if (!prepare) {
89
114
  const execution = await executeBrowserVArtifact(result.artifact, {
90
115
  args: programArgs || [],
@@ -453,6 +453,10 @@ class Zig {
453
453
  return Promise.reject(this.releaseBeforeSession(activeOperation, 'Zig execution cancelled'));
454
454
  }
455
455
  ({ compileArgs, programArgs } = resolveSandboxExecutionArgs('ZIG', args, options));
456
+ const debugMode = options.debugMode ?? (options.debug ? 'trace' : 'none');
457
+ if (debugMode !== 'none') {
458
+ throw new RuntimeConfigurationError('Zig source debugging is unavailable: the current Wasm compiler does not emit DWARF.');
459
+ }
456
460
  limits = resolveExecutionLimits(options.limits);
457
461
  const workspaceFiles = options.workspaceFiles ?? [];
458
462
  const activePath = options.activePath ?? 'main.zig';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-idle",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "A simple web app to run code in the browser",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -34,10 +34,10 @@
34
34
  "@types/sql.js": "^1.4.11",
35
35
  "@typescript-eslint/eslint-plugin": "^8.71.1",
36
36
  "@typescript-eslint/parser": "^8.71.1",
37
- "@wasm-idle/container": "0.1.1",
38
- "@wasm-idle/debug": "1.1.2",
39
- "@wasm-idle/lsp": "1.1.2",
40
- "@wasm-idle/terminal": "1.1.2",
37
+ "@wasm-idle/container": "0.2.0",
38
+ "@wasm-idle/debug": "1.2.0",
39
+ "@wasm-idle/lsp": "1.2.0",
40
+ "@wasm-idle/terminal": "1.2.0",
41
41
  "@wasmer/sdk": "0.10.0",
42
42
  "assemblyscript": "0.28.20",
43
43
  "esbuild": "0.28.2",
@@ -48,6 +48,7 @@
48
48
  "gh-pages": "^6.3.0",
49
49
  "globals": "^17.13.0",
50
50
  "jsdom": "^30.1.2",
51
+ "java-parser": "3.0.1",
51
52
  "monaco-editor": "^0.55.1",
52
53
  "playwright-core": "^1.63.0",
53
54
  "prettier": "^3.9.9",
@@ -68,12 +69,21 @@
68
69
  },
69
70
  "dependencies": {
70
71
  "@bjorn3/browser_wasi_shim": "^0.4.2",
71
- "@wasm-idle/core": "1.1.2",
72
- "@wasm-idle/llvm-core": "1.1.2",
72
+ "@wasm-idle/core": "1.2.0",
73
+ "@wasm-idle/llvm-core": "1.2.0",
73
74
  "fflate": "0.8.3"
74
75
  },
76
+ "peerDependencies": {
77
+ "@wasm-idle/container": "0.2.0"
78
+ },
79
+ "peerDependenciesMeta": {
80
+ "@wasm-idle/container": {
81
+ "optional": true
82
+ }
83
+ },
75
84
  "files": [
76
85
  "dist",
86
+ "!dist/playground/container/**",
77
87
  "!dist/test-fixtures/**",
78
88
  "!dist/**/*.test.*",
79
89
  "!dist/**/*.spec.*",
@@ -88,11 +98,18 @@
88
98
  "svelte": "./dist/index.js",
89
99
  "import": "./dist/index.js",
90
100
  "default": "./dist/index.js"
101
+ },
102
+ "./container": {
103
+ "types": "./dist/container/index.d.ts",
104
+ "import": "./dist/container/index.js",
105
+ "default": "./dist/container/index.js"
91
106
  }
92
107
  },
93
108
  "svelte": "./dist/index.js",
94
109
  "types": "./dist/index.d.ts",
95
110
  "scripts": {
111
+ "sync:phpantom-lsp": "node scripts/sync-phpantom-lsp.mjs",
112
+ "test:lsp:browser:php": "WASM_IDLE_RUN_REAL_BROWSER_PHP_LSP=1 node --test scripts/phpantom-lsp.browser.test.mjs",
96
113
  "dev": "pnpm run prepare:app && vite dev",
97
114
  "build:preview": "pnpm run prepare:app && vite build",
98
115
  "build": "pnpm run prepare:app && vite build && pnpm run package:root",
@@ -118,6 +135,7 @@
118
135
  "test:swift-target-consumer": "node --test scripts/probe-swift-target-consumer.test.mjs",
119
136
  "sync:pyodide": "node scripts/sync-pyodide.mjs",
120
137
  "test:browser:clang-stdin": "WASM_IDLE_RUN_REAL_BROWSER_CLANG_STDIN=1 pnpm exec vitest run src/lib/playground/stdin.playwright.test.ts",
138
+ "test:browser:compiler-options": "WASM_IDLE_REQUIRE_BROWSER_TESTS=1 WASM_IDLE_RUN_REAL_BROWSER_COMPILER_OPTIONS=1 pnpm exec vitest run src/routes/compiler-options.playwright.test.ts",
121
139
  "test:browser:fortran": "WASM_IDLE_RUN_REAL_BROWSER_FORTRAN=1 pnpm exec vitest run src/lib/playground/stdin.playwright.test.ts",
122
140
  "test:browser:cobol": "WASM_IDLE_RUN_REAL_BROWSER_COBOL=1 pnpm exec vitest run src/lib/playground/stdin.playwright.test.ts",
123
141
  "test:browser:v": "WASM_IDLE_RUN_REAL_BROWSER_V=1 pnpm exec vitest run src/lib/playground/stdin.playwright.test.ts -t \"V \"",
@@ -159,6 +177,8 @@
159
177
  "sync:runtime": "node scripts/sync-runtime.mjs",
160
178
  "sync:runtimes": "node scripts/sync-runtime.mjs all",
161
179
  "sync:wasm-php": "node scripts/sync-wasm-php.mjs",
180
+ "sync:postgresql-lsp": "node scripts/sync-postgresql-lsp.mjs",
181
+ "test:lsp:browser:postgresql": "pnpm run sync:postgresql-lsp && WASM_IDLE_RUN_POSTGRESQL_LSP_BROWSER=1 pnpm --dir packages/lsp exec vitest run test/postgresql.playwright.test.ts",
162
182
  "verify:wasm-php": "node scripts/verify-wasm-php-assets.mjs",
163
183
  "sync:wasm-clang": "node scripts/sync-wasm-clang.mjs",
164
184
  "sync:wasm-fortran": "node scripts/sync-runtime.mjs wasm-fortran",
@@ -181,6 +201,8 @@
181
201
  "sync:wasm-lisp": "node scripts/sync-runtime.mjs wasm-lisp",
182
202
  "sync:wasm-ruby": "node scripts/sync-runtime.mjs wasm-ruby",
183
203
  "sync:wasm-teavm": "node scripts/sync-wasm-teavm.mjs",
204
+ "build:java-lsp": "python3 producers/javacs-teavm/build.py",
205
+ "sync:java-lsp": "node scripts/sync-javacs-teavm-lsp.mjs",
184
206
  "sync:wasm-tinygo": "node scripts/sync-runtime.mjs wasm-tinygo",
185
207
  "sync:wasm-swift": "node scripts/sync-runtime.mjs wasm-swift",
186
208
  "sync:wasm-elixir": "node scripts/sync-runtime.mjs wasm-elixir",
@@ -217,9 +239,9 @@
217
239
  "build:static-runtime-modules": "node scripts/build-static-runtime-modules.mjs",
218
240
  "support:matrix": "node scripts/support-matrix.mjs write",
219
241
  "check:support-matrix": "node scripts/support-matrix.mjs check",
220
- "sync:page-runtimes": "pnpm run sync:pyodide && pnpm run sync:webr && pnpm run sync:wasm-of-js-of-ocaml && pnpm run sync:wasm-typescript && pnpm run sync:wasm-octave && pnpm run sync:wasm-prolog && pnpm run sync:wasm-gleam && pnpm run sync:wasm-perl && pnpm run sync:wasm-tcl && pnpm run sync:wasm-awk && pnpm run sync:wasm-pascal && pnpm run sync:wasm-forth && pnpm run sync:wasm-j && pnpm run sync:wasm-bqn && pnpm run sync:wasm-janet && pnpm run sync:wasm-julia && pnpm run sync:wasm-nim && pnpm run sync:wasm-ruby && pnpm run sync:wasm-bash && pnpm run sync:wasm-clojurescript && pnpm run sync:wasm-rescript",
221
- "page:build": "pnpm run verify:page-c3 && pnpm run verify:page-lfortran && pnpm run sync:wasm-lean4 && pnpm run prepare:test-assets -- clang && pnpm run build:page-runtimes && pnpm run sync:page-runtimes && pnpm run build:static-runtime-modules && pnpm run prepare:wasm-debug-release && pnpm run sync:wasm-commonlisp && pnpm run layer:static-runtimes && pnpm run compress:static-runtimes && pnpm run assets:lock && pnpm run check:assets-lock && pnpm run prepare:page-container && pnpm run build && pnpm run compress:build-runtimes && pnpm run verify:page-c3 build && pnpm run verify:page-lfortran build",
222
- "package:root": "svelte-kit sync && node scripts/clean-package-output.mjs && svelte-package --tsconfig ./tsconfig.package.json && publint",
242
+ "sync:page-runtimes": "pnpm run build:java-lsp && pnpm run sync:java-lsp && pnpm run sync:postgresql-lsp && pnpm run sync:bash-lsp && pnpm run sync:cobol-lsp && pnpm run sync:nim-lsp && pnpm run sync:pyodide && pnpm run sync:webr && pnpm run sync:wasm-of-js-of-ocaml && pnpm run sync:wasm-typescript && pnpm run sync:wasm-octave && pnpm run sync:wasm-prolog && pnpm run sync:wasm-gleam && pnpm run sync:wasm-perl && pnpm run sync:wasm-tcl && pnpm run sync:wasm-awk && pnpm run sync:wasm-pascal && pnpm run sync:wasm-forth && pnpm run sync:wasm-j && pnpm run sync:wasm-bqn && pnpm run sync:wasm-janet && pnpm run sync:wasm-julia && pnpm run sync:wasm-nim && pnpm run sync:wasm-ruby && pnpm run sync:wasm-bash && pnpm run sync:wasm-clojurescript && pnpm run sync:wasm-rescript && pnpm run sync:fennel-lsp && pnpm run sync:grain-lsp && pnpm run sync:rescript-lsp",
243
+ "page:build": "pnpm run sync:phpantom-lsp && pnpm run sync:forth-lsp && pnpm run sync:c3-lsp && pnpm run sync:v-lsp && pnpm run verify:page-c3 && pnpm run verify:page-lfortran && pnpm run sync:wasm-lean4 && pnpm run prepare:test-assets -- clang && pnpm run build:page-runtimes && pnpm run sync:page-runtimes && pnpm run build:static-runtime-modules && pnpm run prepare:wasm-debug-release && pnpm run sync:wasm-commonlisp && pnpm run layer:static-runtimes && pnpm run compress:static-runtimes && pnpm run assets:lock && pnpm run check:assets-lock && pnpm run prepare:page-container && pnpm run build && pnpm run compress:build-runtimes && pnpm run verify:page-c3 build && pnpm run verify:page-lfortran build",
244
+ "package:root": "svelte-kit sync && node scripts/clean-package-output.mjs && svelte-package --tsconfig ./tsconfig.package.json && node scripts/bundle-java-debug-helpers.mjs && publint",
223
245
  "package": "pnpm run build:publish-deps && pnpm run package:root",
224
246
  "verify:package": "node scripts/verify-package.mjs",
225
247
  "release:npm": "node scripts/release-npm.mjs",
@@ -275,6 +297,28 @@
275
297
  "prepare:container-distribution": "node scripts/prepare-container-distribution.mjs",
276
298
  "verify:container-distribution": "node scripts/verify-container-distribution.mjs",
277
299
  "test:container-distribution": "node --test scripts/container-distribution.test.mjs",
278
- "benchmark:container": "node scripts/benchmark-container.mjs"
300
+ "benchmark:container": "node scripts/benchmark-container.mjs",
301
+ "sync:fennel-lsp": "node scripts/sync-fennel-lsp.mjs",
302
+ "test:lsp:fennel": "WASM_IDLE_RUN_REAL_BROWSER_FENNEL_LSP=1 node --test scripts/fennel-lsp.browser.test.mjs",
303
+ "sync:forth-lsp": "node scripts/build-forth-lsp.mjs",
304
+ "test:lsp:browser:forth": "WASM_IDLE_RUN_REAL_BROWSER_FORTH_LSP=1 node --test scripts/forth-lsp.browser.test.mjs",
305
+ "sync:bash-lsp": "node scripts/sync-bash-lsp.mjs",
306
+ "test:lsp:assets:bash": "pnpm run sync:bash-lsp && WASM_IDLE_RUN_BASH_LSP_ASSET_BUILD=1 node --test scripts/sync-bash-lsp.test.mjs",
307
+ "test:lsp:browser:bash": "pnpm run sync:bash-lsp && WASM_IDLE_RUN_BASH_LSP_BROWSER=1 pnpm --dir packages/lsp exec vitest run test/bash.playwright.test.ts --pool threads --maxWorkers 1 --no-file-parallelism",
308
+ "sync:grain-lsp": "node scripts/sync-grain-lsp.mjs",
309
+ "test:lsp:grain": "WASM_IDLE_RUN_REAL_BROWSER_GRAIN_LSP=1 node --test scripts/grain-lsp.browser.test.mjs",
310
+ "sync:c3-lsp": "node scripts/build-c3-lsp.mjs",
311
+ "test:lsp:browser:c3": "WASM_IDLE_RUN_REAL_BROWSER_C3_LSP=1 node --test scripts/c3-lsp.browser.test.mjs",
312
+ "sync:cobol-lsp": "node scripts/sync-cobol-lsp.mjs",
313
+ "test:lsp:assets:cobol": "pnpm run sync:cobol-lsp && WASM_IDLE_RUN_COBOL_LSP_ASSET_BUILD=1 node --test scripts/sync-cobol-lsp.test.mjs",
314
+ "test:lsp:browser:cobol": "pnpm run sync:cobol-lsp && WASM_IDLE_RUN_COBOL_LSP_BROWSER=1 pnpm --dir packages/lsp exec vitest run test/cobol.playwright.test.ts --pool threads --maxWorkers 1 --no-file-parallelism",
315
+ "sync:rescript-lsp": "node scripts/sync-rescript-lsp.mjs",
316
+ "test:lsp:browser:rescript": "WASM_IDLE_RUN_REAL_BROWSER_LSP=1 node --test scripts/rescript-lsp.browser.test.mjs",
317
+ "test:lsp:assets:rescript": "WASM_IDLE_RUN_RESCRIPT_LSP_PRODUCER=1 node --test scripts/sync-rescript-lsp.test.mjs",
318
+ "sync:v-lsp": "node scripts/build-v-lsp.mjs",
319
+ "test:lsp:browser:v": "WASM_IDLE_RUN_REAL_BROWSER_V_LSP=1 node --test scripts/v-lsp.browser.test.mjs",
320
+ "sync:nim-lsp": "node scripts/sync-nim-lsp.mjs",
321
+ "test:lsp:assets:nim": "pnpm run sync:nim-lsp && WASM_IDLE_RUN_NIM_LSP_ASSET_BUILD=1 node --test scripts/sync-nim-lsp.test.mjs",
322
+ "test:lsp:browser:nim": "pnpm run sync:nim-lsp && python3 producers/nim-lsp/build.py --native && WASM_IDLE_RUN_NIM_LSP_BROWSER=1 pnpm --dir packages/lsp exec vitest run test/nim.playwright.test.ts --pool threads --maxWorkers 1 --no-file-parallelism"
279
323
  }
280
324
  }