* Patches the WebAssembly object in the worker scope and forwards * registered modules to the parent thread.
(workerSelf: MinimalDedicatedWorkerGlobalScope)
| 166 | * registered modules to the parent thread. |
| 167 | */ |
| 168 | function patchWebAssemblyWithForwarding(workerSelf: MinimalDedicatedWorkerGlobalScope): void { |
| 169 | if ('instantiateStreaming' in WebAssembly) { |
| 170 | const origInstantiateStreaming = WebAssembly.instantiateStreaming; |
| 171 | WebAssembly.instantiateStreaming = function instantiateStreaming( |
| 172 | response: Response | PromiseLike<Response>, |
| 173 | importObject: WebAssembly.Imports, |
| 174 | ): Promise<WebAssembly.Module> { |
| 175 | return Promise.resolve(response).then(response => { |
| 176 | return origInstantiateStreaming(response, importObject).then(rv => { |
| 177 | if (response.url) { |
| 178 | registerModuleAndForward(rv.module, response.url, workerSelf); |
| 179 | } |
| 180 | return rv; |
| 181 | }); |
| 182 | }); |
| 183 | } as typeof WebAssembly.instantiateStreaming; |
| 184 | } |
| 185 | |
| 186 | if ('compileStreaming' in WebAssembly) { |
| 187 | const origCompileStreaming = WebAssembly.compileStreaming; |
| 188 | WebAssembly.compileStreaming = function compileStreaming( |
| 189 | source: Response | Promise<Response>, |
| 190 | ): Promise<WebAssembly.Module> { |
| 191 | return Promise.resolve(source).then(response => { |
| 192 | return origCompileStreaming(response).then(module => { |
| 193 | if (response.url) { |
| 194 | registerModuleAndForward(module, response.url, workerSelf); |
| 195 | } |
| 196 | return module; |
| 197 | }); |
| 198 | }); |
| 199 | } as typeof WebAssembly.compileStreaming; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Registers a WASM module and forwards its debug image to the parent thread. |
no test coverage detected