MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / patchWebAssemblyWithForwarding

Function patchWebAssemblyWithForwarding

packages/wasm/src/index.ts:168–201  ·  view source on GitHub ↗

* Patches the WebAssembly object in the worker scope and forwards * registered modules to the parent thread.

(workerSelf: MinimalDedicatedWorkerGlobalScope)

Source from the content-addressed store, hash-verified

166 * registered modules to the parent thread.
167 */
168function 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.

Callers 1

registerWebWorkerWasmFunction · 0.85

Calls 3

registerModuleAndForwardFunction · 0.70
resolveMethod · 0.65
thenMethod · 0.45

Tested by

no test coverage detected