()
| 4 | * Patches the web assembly runtime. |
| 5 | */ |
| 6 | export function patchWebAssembly(): void { |
| 7 | if ('instantiateStreaming' in WebAssembly) { |
| 8 | const origInstantiateStreaming = WebAssembly.instantiateStreaming; |
| 9 | WebAssembly.instantiateStreaming = function instantiateStreaming( |
| 10 | response: Response | PromiseLike<Response>, |
| 11 | importObject: WebAssembly.Imports, |
| 12 | ): Promise<WebAssembly.Module> { |
| 13 | return Promise.resolve(response).then(response => { |
| 14 | return origInstantiateStreaming(response, importObject).then(rv => { |
| 15 | if (response.url) { |
| 16 | registerModule(rv.module, response.url); |
| 17 | } |
| 18 | return rv; |
| 19 | }); |
| 20 | }); |
| 21 | } as typeof WebAssembly.instantiateStreaming; |
| 22 | } |
| 23 | |
| 24 | if ('compileStreaming' in WebAssembly) { |
| 25 | const origCompileStreaming = WebAssembly.compileStreaming; |
| 26 | WebAssembly.compileStreaming = function compileStreaming( |
| 27 | source: Response | Promise<Response>, |
| 28 | ): Promise<WebAssembly.Module> { |
| 29 | return Promise.resolve(source).then(response => { |
| 30 | return origCompileStreaming(response).then(module => { |
| 31 | if (response.url) { |
| 32 | registerModule(module, response.url); |
| 33 | } |
| 34 | return module; |
| 35 | }); |
| 36 | }); |
| 37 | } as typeof WebAssembly.compileStreaming; |
| 38 | } |
| 39 | } |
no test coverage detected