(module: WebAssembly.Module, url: string)
| 41 | * Records a module and returns the created debug image. |
| 42 | */ |
| 43 | export function registerModule(module: WebAssembly.Module, url: string): DebugImage | null { |
| 44 | const { buildId, debugFile } = getModuleInfo(module); |
| 45 | if (!buildId) { |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | const oldIdx = getImage(url); |
| 50 | if (oldIdx >= 0) { |
| 51 | IMAGES.splice(oldIdx, 1); |
| 52 | } |
| 53 | |
| 54 | let debugFileUrl = null; |
| 55 | if (debugFile) { |
| 56 | try { |
| 57 | debugFileUrl = new URL(debugFile, url).href; |
| 58 | } catch { |
| 59 | // debugFile could be a blob URL which causes the URL constructor to throw |
| 60 | // for now we just ignore this case |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | const image: DebugImage = { |
| 65 | type: 'wasm', |
| 66 | code_id: buildId, |
| 67 | code_file: url, |
| 68 | debug_file: debugFileUrl, |
| 69 | debug_id: `${buildId.padEnd(32, '0').slice(0, 32)}0`, |
| 70 | }; |
| 71 | |
| 72 | IMAGES.push(image); |
| 73 | return image; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns all known images. |
no test coverage detected