@sentry/wasm 11.0.0-beta.1 → 11.0.0-beta.2

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.
@@ -0,0 +1,68 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const core = require('@sentry/core');
4
+
5
+ const wasmSourceUrls = /* @__PURE__ */ new WeakMap();
6
+ let responseReadersPatched = false;
7
+ function getWasmSourceUrl(source) {
8
+ const buffer = toArrayBuffer(source);
9
+ if (!buffer) {
10
+ return void 0;
11
+ }
12
+ return wasmSourceUrls.get(buffer);
13
+ }
14
+ function toArrayBuffer(source) {
15
+ if (source instanceof ArrayBuffer) {
16
+ return source;
17
+ }
18
+ if (ArrayBuffer.isView(source)) {
19
+ const { buffer } = source;
20
+ return buffer instanceof ArrayBuffer ? buffer : void 0;
21
+ }
22
+ return void 0;
23
+ }
24
+ function looksLikeWasmResponse(response) {
25
+ const contentType = response.headers.get("content-type");
26
+ if (contentType?.includes("application/wasm")) {
27
+ return true;
28
+ }
29
+ const { url } = response;
30
+ return Boolean(url && /\.wasm(?:\?|#|$)/i.test(url));
31
+ }
32
+ function tagResponseSource(response, source) {
33
+ try {
34
+ const buffer = toArrayBuffer(source);
35
+ if (buffer && response.url && looksLikeWasmResponse(response)) {
36
+ wasmSourceUrls.set(buffer, response.url);
37
+ }
38
+ } catch {
39
+ }
40
+ }
41
+ function patchWasmResponseBodyReaders() {
42
+ if (responseReadersPatched || typeof Response === "undefined") {
43
+ return;
44
+ }
45
+ responseReadersPatched = true;
46
+ core.fill(Response.prototype, "arrayBuffer", (original) => {
47
+ return function arrayBuffer() {
48
+ const bufferPromise = original.call(this);
49
+ return bufferPromise.then((buffer) => {
50
+ tagResponseSource(this, buffer);
51
+ return buffer;
52
+ });
53
+ };
54
+ });
55
+ core.fill(Response.prototype, "bytes", (original) => {
56
+ return function bytes() {
57
+ const bytesPromise = original.call(this);
58
+ return bytesPromise.then((bytes2) => {
59
+ tagResponseSource(this, bytes2);
60
+ return bytes2;
61
+ });
62
+ };
63
+ });
64
+ }
65
+
66
+ exports.getWasmSourceUrl = getWasmSourceUrl;
67
+ exports.patchWasmResponseBodyReaders = patchWasmResponseBodyReaders;
68
+ //# sourceMappingURL=patchWasmResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patchWasmResponse.js","sources":["../../../src/patchWasmResponse.ts"],"sourcesContent":["import { fill } from '@sentry/core';\n\n/**\n * Streaming wasm registration (`instantiateStreaming` / `compileStreaming`) reads the module URL\n * from `Response.url`. Non-streaming paths (`WebAssembly.instantiate` / `compile` with bytes) only\n * receive a buffer, no URL, so registration would otherwise be skipped.\n *\n * This module patches `Response.prototype.arrayBuffer` and `bytes` so that when wasm is fetched\n * and then loaded from bytes, we can map the resulting `ArrayBuffer` back to the fetch URL via\n * `getWasmSourceUrl()` and register the module in `patchNonStreamingWebAssembly`.\n */\nconst wasmSourceUrls = new WeakMap<ArrayBuffer, string>();\n\nlet responseReadersPatched = false;\n\n/**\n * Resolves a wasm source buffer back to its fetch URL, when known.\n */\nexport function getWasmSourceUrl(source: unknown): string | undefined {\n const buffer = toArrayBuffer(source);\n if (!buffer) {\n return undefined;\n }\n\n return wasmSourceUrls.get(buffer);\n}\n\nfunction toArrayBuffer(source: unknown): ArrayBuffer | undefined {\n if (source instanceof ArrayBuffer) {\n return source;\n }\n\n if (ArrayBuffer.isView(source)) {\n const { buffer } = source;\n return buffer instanceof ArrayBuffer ? buffer : undefined;\n }\n\n return undefined;\n}\n\nfunction looksLikeWasmResponse(response: Response): boolean {\n const contentType = response.headers.get('content-type');\n if (contentType?.includes('application/wasm')) {\n return true;\n }\n\n const { url } = response;\n return Boolean(url && /\\.wasm(?:\\?|#|$)/i.test(url));\n}\n\n/**\n * Runs inside the caller's `arrayBuffer()` / `bytes()` promise chain, so it must never throw:\n * a failure here would reject a body read that has nothing to do with wasm.\n */\nfunction tagResponseSource(response: Response, source: unknown): void {\n try {\n const buffer = toArrayBuffer(source);\n if (buffer && response.url && looksLikeWasmResponse(response)) {\n wasmSourceUrls.set(buffer, response.url);\n }\n } catch {\n // see above\n }\n}\n\n/**\n * Patches Response body readers so wasm bytes remember their fetch URL.\n */\nexport function patchWasmResponseBodyReaders(): void {\n if (responseReadersPatched || typeof Response === 'undefined') {\n return;\n }\n\n responseReadersPatched = true;\n\n fill(Response.prototype, 'arrayBuffer', (original: (this: Response) => Promise<ArrayBuffer>) => {\n return function arrayBuffer(this: Response): Promise<ArrayBuffer> {\n const bufferPromise: Promise<ArrayBuffer> = original.call(this);\n return bufferPromise.then(buffer => {\n tagResponseSource(this, buffer);\n return buffer;\n });\n };\n });\n\n fill(Response.prototype, 'bytes', (original: (this: Response) => Promise<Uint8Array>) => {\n return function bytes(this: Response): Promise<Uint8Array> {\n const bytesPromise: Promise<Uint8Array> = original.call(this);\n return bytesPromise.then(bytes => {\n tagResponseSource(this, bytes);\n return bytes;\n });\n };\n });\n}\n\n/** @internal */\nexport function _resetResponsePatchForTests(): void {\n responseReadersPatched = false;\n}\n"],"names":["fill","bytes"],"mappings":";;;;AAWA,MAAM,cAAA,uBAAqB,OAAA,EAA6B;AAExD,IAAI,sBAAA,GAAyB,KAAA;AAKtB,SAAS,iBAAiB,MAAA,EAAqC;AACpE,EAAA,MAAM,MAAA,GAAS,cAAc,MAAM,CAAA;AACnC,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,OAAO,cAAA,CAAe,IAAI,MAAM,CAAA;AAClC;AAEA,SAAS,cAAc,MAAA,EAA0C;AAC/D,EAAA,IAAI,kBAAkB,WAAA,EAAa;AACjC,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,IAAI,WAAA,CAAY,MAAA,CAAO,MAAM,CAAA,EAAG;AAC9B,IAAA,MAAM,EAAE,QAAO,GAAI,MAAA;AACnB,IAAA,OAAO,MAAA,YAAkB,cAAc,MAAA,GAAS,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EACF,CAAC,CAAA;AAED,EAAAA,SAAA,CAAK,QAAA,CAAS,SAAA,EAAW,OAAA,EAAS,CAAC,QAAA,KAAsD;AACvF,IAAA,OAAO,SAAS,KAAA,GAA2C;AACzD,MAAA,MAAM,YAAA,GAAoC,QAAA,CAAS,IAAA,CAAK,IAAI,CAAA;AAC5D,MAAA,OAAO,YAAA,CAAa,IAAA,CAAK,CAAAC,MAAAA,KAAS;AAChC,QAAA,iBAAA,CAAkB,MAAMA,MAAK,CAAA;AAC7B,QAAA,OAAOA,MAAAA;AAAA,MACT,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF,CAAC,CAAA;AACH;;;;;"}
@@ -1,6 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- function patchWebAssembly(registerModule) {
3
+ const patchWasmResponse = require('./patchWasmResponse.js');
4
+
5
+ let nonStreamingPatched = false;
6
+ function patchStreamingWebAssembly(registerModule) {
4
7
  if ("instantiateStreaming" in WebAssembly) {
5
8
  const origInstantiateStreaming = WebAssembly.instantiateStreaming;
6
9
  WebAssembly.instantiateStreaming = function instantiateStreaming(response, ...rest) {
@@ -34,6 +37,47 @@ function registerSafely(registerModule, module, url) {
34
37
  } catch {
35
38
  }
36
39
  }
40
+ function registerFromBufferSource(registerModule, compiled, source) {
41
+ try {
42
+ const module = compiled instanceof WebAssembly.Module ? compiled : "module" in compiled ? compiled.module : void 0;
43
+ const url = patchWasmResponse.getWasmSourceUrl(source);
44
+ if (module && url) {
45
+ registerModule(module, url);
46
+ }
47
+ } catch {
48
+ }
49
+ }
50
+ function patchNonStreamingWebAssembly(registerModule) {
51
+ if (nonStreamingPatched) {
52
+ return;
53
+ }
54
+ nonStreamingPatched = true;
55
+ const origInstantiate = WebAssembly.instantiate;
56
+ WebAssembly.instantiate = function instantiate(source, ...rest) {
57
+ return origInstantiate(source, ...rest).then((result) => {
58
+ registerFromBufferSource(registerModule, result, source);
59
+ return result;
60
+ });
61
+ };
62
+ const origCompile = WebAssembly.compile;
63
+ WebAssembly.compile = function compile(source, ...rest) {
64
+ return origCompile(source, ...rest).then((module) => {
65
+ registerFromBufferSource(registerModule, module, source);
66
+ return module;
67
+ });
68
+ };
69
+ }
70
+ function patchWebAssembly(registerModule) {
71
+ tryPatch(() => patchWasmResponse.patchWasmResponseBodyReaders());
72
+ tryPatch(() => patchNonStreamingWebAssembly(registerModule));
73
+ tryPatch(() => patchStreamingWebAssembly(registerModule));
74
+ }
75
+ function tryPatch(patch) {
76
+ try {
77
+ patch();
78
+ } catch {
79
+ }
80
+ }
37
81
 
38
82
  exports.patchWebAssembly = patchWebAssembly;
39
83
  //# sourceMappingURL=patchWebAssembly.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"patchWebAssembly.js","sources":["../../../src/patchWebAssembly.ts"],"sourcesContent":["export type RegisterModuleCallback = (module: WebAssembly.Module, url: string) => void;\n\n/**\n * Patches the WebAssembly streaming APIs so that every compiled module gets\n * registered as a debug image under the URL of the response it was compiled\n * from.\n *\n * @param registerModule callback invoked for every successfully compiled module\n */\nexport function patchWebAssembly(registerModule: RegisterModuleCallback): void {\n if ('instantiateStreaming' in WebAssembly) {\n const origInstantiateStreaming = WebAssembly.instantiateStreaming as (\n response: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.WebAssemblyInstantiatedSource>;\n WebAssembly.instantiateStreaming = function instantiateStreaming(\n response: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.WebAssemblyInstantiatedSource> {\n return Promise.resolve(response).then(response => {\n return origInstantiateStreaming(response, ...rest).then(rv => {\n if (response.url) {\n registerSafely(registerModule, rv.module, response.url);\n }\n return rv;\n });\n });\n };\n }\n\n if ('compileStreaming' in WebAssembly) {\n const origCompileStreaming = WebAssembly.compileStreaming as (\n source: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.Module>;\n WebAssembly.compileStreaming = function compileStreaming(\n source: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(source).then(response => {\n return origCompileStreaming(response, ...rest).then(module => {\n if (response.url) {\n registerSafely(registerModule, module, response.url);\n }\n return module;\n });\n });\n };\n }\n}\n\nfunction registerSafely(registerModule: RegisterModuleCallback, module: WebAssembly.Module, url: string): void {\n try {\n registerModule(module, url);\n } catch {\n // a registration failure must never break the user's WebAssembly call\n }\n}\n"],"names":["response"],"mappings":";;AASO,SAAS,iBAAiB,cAAA,EAA8C;AAC7E,EAAA,IAAI,0BAA0B,WAAA,EAAa;AACzC,IAAA,MAAM,2BAA2B,WAAA,CAAY,oBAAA;AAI7C,IAAA,WAAA,CAAY,oBAAA,GAAuB,SAAS,oBAAA,CAC1C,QAAA,EAAA,GACG,IAAA,EACiD;AACpD,MAAA,OAAO,QAAQ,OAAA,CAAQ,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAAA,SAAAA,KAAY;AAChD,QAAA,OAAO,yBAAyBA,SAAAA,EAAU,GAAG,IAAI,CAAA,CAAE,KAAK,CAAA,EAAA,KAAM;AAC5D,UAAA,IAAIA,UAAS,GAAA,EAAK;AAChB,YAAA,cAAA,CAAe,cAAA,EAAgB,EAAA,CAAG,MAAA,EAAQA,SAAAA,CAAS,GAAG,CAAA;AAAA,UACxD;AACA,UAAA,OAAO,EAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AAEA,EAAA,IAAI,sBAAsB,WAAA,EAAa;AACrC,IAAA,MAAM,uBAAuB,WAAA,CAAY,gBAAA;AAIzC,IAAA,WAAA,CAAY,gBAAA,GAAmB,SAAS,gBAAA,CACtC,MAAA,EAAA,GACG,IAAA,EAC0B;AAC7B,MAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,MAAM,CAAA,CAAE,KAAK,CAAA,QAAA,KAAY;AAC9C,QAAA,OAAO,qBAAqB,QAAA,EAAU,GAAG,IAAI,CAAA,CAAE,KAAK,CAAA,MAAA,KAAU;AAC5D,UAAA,IAAI,SAAS,GAAA,EAAK;AAChB,YAAA,cAAA,CAAe,cAAA,EAAgB,MAAA,EAAQ,QAAA,CAAS,GAAG,CAAA;AAAA,UACrD;AACA,UAAA,OAAO,MAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AACF;AAEA,SAAS,cAAA,CAAe,cAAA,EAAwC,MAAA,EAA4B,GAAA,EAAmB;AAC7G,EAAA,IAAI;AACF,IAAA,cAAA,CAAe,QAAQ,GAAG,CAAA;AAAA,EAC5B,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;;;;"}
1
+ {"version":3,"file":"patchWebAssembly.js","sources":["../../../src/patchWebAssembly.ts"],"sourcesContent":["import { getWasmSourceUrl, patchWasmResponseBodyReaders } from './patchWasmResponse';\n\nexport type RegisterModuleCallback = (module: WebAssembly.Module, url: string) => void;\n\nlet nonStreamingPatched = false;\n\n/**\n * Patches the WebAssembly streaming APIs so that every compiled module gets\n * registered as a debug image under the URL of the response it was compiled\n * from.\n *\n * @param registerModule callback invoked for every successfully compiled module\n */\nfunction patchStreamingWebAssembly(registerModule: RegisterModuleCallback): void {\n if ('instantiateStreaming' in WebAssembly) {\n const origInstantiateStreaming = WebAssembly.instantiateStreaming as (\n response: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.WebAssemblyInstantiatedSource>;\n WebAssembly.instantiateStreaming = function instantiateStreaming(\n response: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.WebAssemblyInstantiatedSource> {\n return Promise.resolve(response).then(response => {\n return origInstantiateStreaming(response, ...rest).then(rv => {\n if (response.url) {\n registerSafely(registerModule, rv.module, response.url);\n }\n return rv;\n });\n });\n };\n }\n\n if ('compileStreaming' in WebAssembly) {\n const origCompileStreaming = WebAssembly.compileStreaming as (\n source: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.Module>;\n WebAssembly.compileStreaming = function compileStreaming(\n source: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(source).then(response => {\n return origCompileStreaming(response, ...rest).then(module => {\n if (response.url) {\n registerSafely(registerModule, module, response.url);\n }\n return module;\n });\n });\n };\n }\n}\n\nfunction registerSafely(registerModule: RegisterModuleCallback, module: WebAssembly.Module, url: string): void {\n try {\n registerModule(module, url);\n } catch {\n // a registration failure must never break the user's WebAssembly call\n }\n}\n\n/**\n * Registers a module compiled from bytes under the URL those bytes were fetched from, when known.\n * Runs inside the caller's promise chain, so nothing in here may throw.\n */\nfunction registerFromBufferSource(\n registerModule: RegisterModuleCallback,\n compiled: WebAssembly.Module | WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance,\n source: unknown,\n): void {\n try {\n // `instantiate(module)` resolves to a bare Instance, which carries nothing new to register\n const module =\n compiled instanceof WebAssembly.Module ? compiled : 'module' in compiled ? compiled.module : undefined;\n const url = getWasmSourceUrl(source);\n if (module && url) {\n registerModule(module, url);\n }\n } catch {\n // a registration failure must never break the user's WebAssembly call\n }\n}\n\n/**\n * Patches the non-streaming web assembly runtime.\n */\nfunction patchNonStreamingWebAssembly(registerModule: RegisterModuleCallback): void {\n if (nonStreamingPatched) {\n return;\n }\n\n nonStreamingPatched = true;\n\n // Double-cast, because the overloaded native signature (buffer vs. module\n // first argument) cannot be widened to a pass-through shape in one step.\n const origInstantiate = WebAssembly.instantiate as unknown as (\n source: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance>;\n WebAssembly.instantiate = function instantiate(source: unknown, ...rest: unknown[]) {\n return origInstantiate(source, ...rest).then(result => {\n registerFromBufferSource(registerModule, result, source);\n return result;\n });\n } as typeof WebAssembly.instantiate;\n\n const origCompile = WebAssembly.compile as (source: unknown, ...rest: unknown[]) => Promise<WebAssembly.Module>;\n WebAssembly.compile = function compile(source: BufferSource, ...rest: unknown[]): Promise<WebAssembly.Module> {\n return origCompile(source, ...rest).then(module => {\n registerFromBufferSource(registerModule, module, source);\n return module;\n });\n };\n}\n\n/**\n * Patches the web assembly runtime.\n *\n * Every patch is guarded on its own: a missing or frozen global must neither throw out of\n * `Sentry.init()` / `registerWebWorkerWasm()` nor keep the remaining patches from installing.\n */\nexport function patchWebAssembly(registerModule: RegisterModuleCallback): void {\n tryPatch(() => patchWasmResponseBodyReaders());\n tryPatch(() => patchNonStreamingWebAssembly(registerModule));\n tryPatch(() => patchStreamingWebAssembly(registerModule));\n}\n\nfunction tryPatch(patch: () => void): void {\n try {\n patch();\n } catch {\n // see patchWebAssembly()\n }\n}\n\n/** @internal */\nexport function _resetNonStreamingPatchForTests(): void {\n nonStreamingPatched = false;\n}\n"],"names":["response","getWasmSourceUrl","patchWasmResponseBodyReaders"],"mappings":";;;;AAIA,IAAI,mBAAA,GAAsB,KAAA;AAS1B,SAAS,0BAA0B,cAAA,EAA8C;AAC/E,EAAA,IAAI,0BAA0B,WAAA,EAAa;AACzC,IAAA,MAAM,2BAA2B,WAAA,CAAY,oBAAA;AAI7C,IAAA,WAAA,CAAY,oBAAA,GAAuB,SAAS,oBAAA,CAC1C,QAAA,EAAA,GACG,IAAA,EACiD;AACpD,MAAA,OAAO,QAAQ,OAAA,CAAQ,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAAA,SAAAA,KAAY;AAChD,QAAA,OAAO,yBAAyBA,SAAAA,EAAU,GAAG,IAAI,CAAA,CAAE,KAAK,CAAA,EAAA,KAAM;AAC5D,UAAA,IAAIA,UAAS,GAAA,EAAK;AAChB,YAAA,cAAA,CAAe,cAAA,EAAgB,EAAA,CAAG,MAAA,EAAQA,SAAAA,CAAS,GAAG,CAAA;AAAA,UACxD;AACA,UAAA,OAAO,EAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AAEA,EAAA,IAAI,sBAAsB,WAAA,EAAa;AACrC,IAAA,MAAM,uBA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Y,WAAA;AAIpC,EAAA,WAAA,CAAY,WAAA,GAAc,SAAS,WAAA,CAAY,MAAA,EAAA,GAAoB,IAAA,EAAiB;AAClF,IAAA,OAAO,gBAAgB,MAAA,EAAQ,GAAG,IAAI,CAAA,CAAE,KAAK,CAAA,MAAA,KAAU;AACrD,MAAA,wBAAA,CAAyB,cAAA,EAAgB,QAAQ,MAAM,CAAA;AACvD,MAAA,OAAO,MAAA;AAAA,IACT,CAAC,CAAA;AAAA,EACH,CAAA;AAEA,EAAA,MAAM,cAAc,WAAA,CAAY,OAAA;AAChC,EAAA,WAAA,CAAY,OAAA,GAAU,SAAS,OAAA,CAAQ,MAAA,EAAA,GAAyB,IAAA,EAA8C;AAC5G,IAAA,OAAO,YAAY,MAAA,EAAQ,GAAG,IAAI,CAAA,CAAE,KAAK,CAAA,MAAA,KAAU;AACjD,MAAA,wBAAA,CAAyB,cAAA,EAAgB,QAAQ,MAAM,CAAA;AACvD,MAAA,OAAO,MAAA;AAAA,IACT,CAAC,CAAA;AAAA,EACH,CAAA;AACF;AAQO,SAAS,iBAAiB,cAAA,EAA8C;AAC7E,EAAA,QAAA,CAAS,MAAMC,gDAA8B,CAAA;AAC7C,EAAA,QAAA,CAAS,MAAM,4BAAA,CAA6B,cAAc,CAAC,CAAA;AAC3D,EAAA,QAAA,CAAS,MAAM,yBAAA,CAA0B,cAAc,CAAC,CAAA;AAC1D;AAEA,SAAS,SAAS,KAAA,EAAyB;AACzC,EAAA,IAAI;AACF,IAAA,KAAA,EAAM;AAAA,EACR,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;;;;"}
@@ -1 +1 @@
1
- {"type":"module","version":"11.0.0-beta.1","sideEffects":false}
1
+ {"type":"module","version":"11.0.0-beta.2","sideEffects":false}
@@ -0,0 +1,65 @@
1
+ import { fill } from '@sentry/core';
2
+
3
+ const wasmSourceUrls = /* @__PURE__ */ new WeakMap();
4
+ let responseReadersPatched = false;
5
+ function getWasmSourceUrl(source) {
6
+ const buffer = toArrayBuffer(source);
7
+ if (!buffer) {
8
+ return void 0;
9
+ }
10
+ return wasmSourceUrls.get(buffer);
11
+ }
12
+ function toArrayBuffer(source) {
13
+ if (source instanceof ArrayBuffer) {
14
+ return source;
15
+ }
16
+ if (ArrayBuffer.isView(source)) {
17
+ const { buffer } = source;
18
+ return buffer instanceof ArrayBuffer ? buffer : void 0;
19
+ }
20
+ return void 0;
21
+ }
22
+ function looksLikeWasmResponse(response) {
23
+ const contentType = response.headers.get("content-type");
24
+ if (contentType?.includes("application/wasm")) {
25
+ return true;
26
+ }
27
+ const { url } = response;
28
+ return Boolean(url && /\.wasm(?:\?|#|$)/i.test(url));
29
+ }
30
+ function tagResponseSource(response, source) {
31
+ try {
32
+ const buffer = toArrayBuffer(source);
33
+ if (buffer && response.url && looksLikeWasmResponse(response)) {
34
+ wasmSourceUrls.set(buffer, response.url);
35
+ }
36
+ } catch {
37
+ }
38
+ }
39
+ function patchWasmResponseBodyReaders() {
40
+ if (responseReadersPatched || typeof Response === "undefined") {
41
+ return;
42
+ }
43
+ responseReadersPatched = true;
44
+ fill(Response.prototype, "arrayBuffer", (original) => {
45
+ return function arrayBuffer() {
46
+ const bufferPromise = original.call(this);
47
+ return bufferPromise.then((buffer) => {
48
+ tagResponseSource(this, buffer);
49
+ return buffer;
50
+ });
51
+ };
52
+ });
53
+ fill(Response.prototype, "bytes", (original) => {
54
+ return function bytes() {
55
+ const bytesPromise = original.call(this);
56
+ return bytesPromise.then((bytes2) => {
57
+ tagResponseSource(this, bytes2);
58
+ return bytes2;
59
+ });
60
+ };
61
+ });
62
+ }
63
+
64
+ export { getWasmSourceUrl, patchWasmResponseBodyReaders };
65
+ //# sourceMappingURL=patchWasmResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patchWasmResponse.js","sources":["../../../src/patchWasmResponse.ts"],"sourcesContent":["import { fill } from '@sentry/core';\n\n/**\n * Streaming wasm registration (`instantiateStreaming` / `compileStreaming`) reads the module URL\n * from `Response.url`. Non-streaming paths (`WebAssembly.instantiate` / `compile` with bytes) only\n * receive a buffer, no URL, so registration would otherwise be skipped.\n *\n * This module patches `Response.prototype.arrayBuffer` and `bytes` so that when wasm is fetched\n * and then loaded from bytes, we can map the resulting `ArrayBuffer` back to the fetch URL via\n * `getWasmSourceUrl()` and register the module in `patchNonStreamingWebAssembly`.\n */\nconst wasmSourceUrls = new WeakMap<ArrayBuffer, string>();\n\nlet responseReadersPatched = false;\n\n/**\n * Resolves a wasm source buffer back to its fetch URL, when known.\n */\nexport function getWasmSourceUrl(source: unknown): string | undefined {\n const buffer = toArrayBuffer(source);\n if (!buffer) {\n return undefined;\n }\n\n return wasmSourceUrls.get(buffer);\n}\n\nfunction toArrayBuffer(source: unknown): ArrayBuffer | undefined {\n if (source instanceof ArrayBuffer) {\n return source;\n }\n\n if (ArrayBuffer.isView(source)) {\n const { buffer } = source;\n return buffer instanceof ArrayBuffer ? buffer : undefined;\n }\n\n return undefined;\n}\n\nfunction looksLikeWasmResponse(response: Response): boolean {\n const contentType = response.headers.get('content-type');\n if (contentType?.includes('application/wasm')) {\n return true;\n }\n\n const { url } = response;\n return Boolean(url && /\\.wasm(?:\\?|#|$)/i.test(url));\n}\n\n/**\n * Runs inside the caller's `arrayBuffer()` / `bytes()` promise chain, so it must never throw:\n * a failure here would reject a body read that has nothing to do with wasm.\n */\nfunction tagResponseSource(response: Response, source: unknown): void {\n try {\n const buffer = toArrayBuffer(source);\n if (buffer && response.url && looksLikeWasmResponse(response)) {\n wasmSourceUrls.set(buffer, response.url);\n }\n } catch {\n // see above\n }\n}\n\n/**\n * Patches Response body readers so wasm bytes remember their fetch URL.\n */\nexport function patchWasmResponseBodyReaders(): void {\n if (responseReadersPatched || typeof Response === 'undefined') {\n return;\n }\n\n responseReadersPatched = true;\n\n fill(Response.prototype, 'arrayBuffer', (original: (this: Response) => Promise<ArrayBuffer>) => {\n return function arrayBuffer(this: Response): Promise<ArrayBuffer> {\n const bufferPromise: Promise<ArrayBuffer> = original.call(this);\n return bufferPromise.then(buffer => {\n tagResponseSource(this, buffer);\n return buffer;\n });\n };\n });\n\n fill(Response.prototype, 'bytes', (original: (this: Response) => Promise<Uint8Array>) => {\n return function bytes(this: Response): Promise<Uint8Array> {\n const bytesPromise: Promise<Uint8Array> = original.call(this);\n return bytesPromise.then(bytes => {\n tagResponseSource(this, bytes);\n return bytes;\n });\n };\n });\n}\n\n/** @internal */\nexport function _resetResponsePatchForTests(): void {\n responseReadersPatched = false;\n}\n"],"names":["bytes"],"mappings":";;AAWA,MAAM,cAAA,uBAAqB,OAAA,EAA6B;AAExD,IAAI,sBAAA,GAAyB,KAAA;AAKtB,SAAS,iBAAiB,MAAA,EAAqC;AACpE,EAAA,MAAM,MAAA,GAAS,cAAc,MAAM,CAAA;AACnC,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,OAAO,cAAA,CAAe,IAAI,MAAM,CAAA;AAClC;AAEA,SAAS,cAAc,MAAA,EAA0C;AAC/D,EAAA,IAAI,kBAAkB,WAAA,EAAa;AACjC,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,IAAI,WAAA,CAAY,MAAA,CAAO,MAAM,CAAA,EAAG;AAC9B,IAAA,MAAM,EAAE,QAAO,GAAI,MAAA;AACnB,IAAA,OAAO,MAAA,YAAkB,cAAc,MAAA,GAAS,MAAA;AAAA,EAClD;AAEA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,sBAAsB,QAAA,EAA6B;AAC1D,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,cAAc,CAAA;AACvD,EAAA,IAAI,WAAA,EAAa,QAAA,CAAS,kBAAkB,CAAA,EAAG;AAC7C,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAE,KAAI,GAAI,QAAA;AAChB,EAAA,OAAO,OAAA,CAAQ,GAAA,IAAO,mBAAA,CAAoB,IAAA,CA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,CAAA;AAAA,EACF,CAAC,CAAA;AACH;;;;"}
@@ -1,4 +1,7 @@
1
- function patchWebAssembly(registerModule) {
1
+ import { patchWasmResponseBodyReaders, getWasmSourceUrl } from './patchWasmResponse.js';
2
+
3
+ let nonStreamingPatched = false;
4
+ function patchStreamingWebAssembly(registerModule) {
2
5
  if ("instantiateStreaming" in WebAssembly) {
3
6
  const origInstantiateStreaming = WebAssembly.instantiateStreaming;
4
7
  WebAssembly.instantiateStreaming = function instantiateStreaming(response, ...rest) {
@@ -32,6 +35,47 @@ function registerSafely(registerModule, module, url) {
32
35
  } catch {
33
36
  }
34
37
  }
38
+ function registerFromBufferSource(registerModule, compiled, source) {
39
+ try {
40
+ const module = compiled instanceof WebAssembly.Module ? compiled : "module" in compiled ? compiled.module : void 0;
41
+ const url = getWasmSourceUrl(source);
42
+ if (module && url) {
43
+ registerModule(module, url);
44
+ }
45
+ } catch {
46
+ }
47
+ }
48
+ function patchNonStreamingWebAssembly(registerModule) {
49
+ if (nonStreamingPatched) {
50
+ return;
51
+ }
52
+ nonStreamingPatched = true;
53
+ const origInstantiate = WebAssembly.instantiate;
54
+ WebAssembly.instantiate = function instantiate(source, ...rest) {
55
+ return origInstantiate(source, ...rest).then((result) => {
56
+ registerFromBufferSource(registerModule, result, source);
57
+ return result;
58
+ });
59
+ };
60
+ const origCompile = WebAssembly.compile;
61
+ WebAssembly.compile = function compile(source, ...rest) {
62
+ return origCompile(source, ...rest).then((module) => {
63
+ registerFromBufferSource(registerModule, module, source);
64
+ return module;
65
+ });
66
+ };
67
+ }
68
+ function patchWebAssembly(registerModule) {
69
+ tryPatch(() => patchWasmResponseBodyReaders());
70
+ tryPatch(() => patchNonStreamingWebAssembly(registerModule));
71
+ tryPatch(() => patchStreamingWebAssembly(registerModule));
72
+ }
73
+ function tryPatch(patch) {
74
+ try {
75
+ patch();
76
+ } catch {
77
+ }
78
+ }
35
79
 
36
80
  export { patchWebAssembly };
37
81
  //# sourceMappingURL=patchWebAssembly.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"patchWebAssembly.js","sources":["../../../src/patchWebAssembly.ts"],"sourcesContent":["export type RegisterModuleCallback = (module: WebAssembly.Module, url: string) => void;\n\n/**\n * Patches the WebAssembly streaming APIs so that every compiled module gets\n * registered as a debug image under the URL of the response it was compiled\n * from.\n *\n * @param registerModule callback invoked for every successfully compiled module\n */\nexport function patchWebAssembly(registerModule: RegisterModuleCallback): void {\n if ('instantiateStreaming' in WebAssembly) {\n const origInstantiateStreaming = WebAssembly.instantiateStreaming as (\n response: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.WebAssemblyInstantiatedSource>;\n WebAssembly.instantiateStreaming = function instantiateStreaming(\n response: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.WebAssemblyInstantiatedSource> {\n return Promise.resolve(response).then(response => {\n return origInstantiateStreaming(response, ...rest).then(rv => {\n if (response.url) {\n registerSafely(registerModule, rv.module, response.url);\n }\n return rv;\n });\n });\n };\n }\n\n if ('compileStreaming' in WebAssembly) {\n const origCompileStreaming = WebAssembly.compileStreaming as (\n source: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.Module>;\n WebAssembly.compileStreaming = function compileStreaming(\n source: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(source).then(response => {\n return origCompileStreaming(response, ...rest).then(module => {\n if (response.url) {\n registerSafely(registerModule, module, response.url);\n }\n return module;\n });\n });\n };\n }\n}\n\nfunction registerSafely(registerModule: RegisterModuleCallback, module: WebAssembly.Module, url: string): void {\n try {\n registerModule(module, url);\n } catch {\n // a registration failure must never break the user's WebAssembly call\n }\n}\n"],"names":["response"],"mappings":"AASO,SAAS,iBAAiB,cAAA,EAA8C;AAC7E,EAAA,IAAI,0BAA0B,WAAA,EAAa;AACzC,IAAA,MAAM,2BAA2B,WAAA,CAAY,oBAAA;AAI7C,IAAA,WAAA,CAAY,oBAAA,GAAuB,SAAS,o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Assembly.js","sources":["../../../src/patchWebAssembly.ts"],"sourcesContent":["import { getWasmSourceUrl, patchWasmResponseBodyReaders } from './patchWasmResponse';\n\nexport type RegisterModuleCallback = (module: WebAssembly.Module, url: string) => void;\n\nlet nonStreamingPatched = false;\n\n/**\n * Patches the WebAssembly streaming APIs so that every compiled module gets\n * registered as a debug image under the URL of the response it was compiled\n * from.\n *\n * @param registerModule callback invoked for every successfully compiled module\n */\nfunction patchStreamingWebAssembly(registerModule: RegisterModuleCallback): void {\n if ('instantiateStreaming' in WebAssembly) {\n const origInstantiateStreaming = WebAssembly.instantiateStreaming as (\n response: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.WebAssemblyInstantiatedSource>;\n WebAssembly.instantiateStreaming = function instantiateStreaming(\n response: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.WebAssemblyInstantiatedSource> {\n return Promise.resolve(response).then(response => {\n return origInstantiateStreaming(response, ...rest).then(rv => {\n if (response.url) {\n registerSafely(registerModule, rv.module, response.url);\n }\n return rv;\n });\n });\n };\n }\n\n if ('compileStreaming' in WebAssembly) {\n const origCompileStreaming = WebAssembly.compileStreaming as (\n source: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.Module>;\n WebAssembly.compileStreaming = function compileStreaming(\n source: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(source).then(response => {\n return origCompileStreaming(response, ...rest).then(module => {\n if (response.url) {\n registerSafely(registerModule, module, response.url);\n }\n return module;\n });\n });\n };\n }\n}\n\nfunction registerSafely(registerModule: RegisterModuleCallback, module: WebAssembly.Module, url: string): void {\n try {\n registerModule(module, url);\n } catch {\n // a registration failure must never break the user's WebAssembly call\n }\n}\n\n/**\n * Registers a module compiled from bytes under the URL those bytes were fetched from, when known.\n * Runs inside the caller's promise chain, so nothing in here may throw.\n */\nfunction registerFromBufferSource(\n registerModule: RegisterModuleCallback,\n compiled: WebAssembly.Module | WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance,\n source: unknown,\n): void {\n try {\n // `instantiate(module)` resolves to a bare Instance, which carries nothing new to register\n const module =\n compiled instanceof WebAssembly.Module ? compiled : 'module' in compiled ? compiled.module : undefined;\n const url = getWasmSourceUrl(source);\n if (module && url) {\n registerModule(module, url);\n }\n } catch {\n // a registration failure must never break the user's WebAssembly call\n }\n}\n\n/**\n * Patches the non-streaming web assembly runtime.\n */\nfunction patchNonStreamingWebAssembly(registerModule: RegisterModuleCallback): void {\n if (nonStreamingPatched) {\n return;\n }\n\n nonStreamingPatched = true;\n\n // Double-cast, because the overloaded native signature (buffer vs. module\n // first argument) cannot be widened to a pass-through shape in one step.\n const origInstantiate = WebAssembly.instantiate as unknown as (\n source: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance>;\n WebAssembly.instantiate = function instantiate(source: unknown, ...rest: unknown[]) {\n return origInstantiate(source, ...rest).then(result => {\n registerFromBufferSource(registerModule, result, source);\n return result;\n });\n } as typeof WebAssembly.instantiate;\n\n const origCompile = WebAssembly.compile as (source: unknown, ...rest: unknown[]) => Promise<WebAssembly.Module>;\n WebAssembly.compile = function compile(source: BufferSource, ...rest: unknown[]): Promise<WebAssembly.Module> {\n return origCompile(source, ...rest).then(module => {\n registerFromBufferSource(registerModule, module, source);\n return module;\n });\n };\n}\n\n/**\n * Patches the web assembly runtime.\n *\n * Every patch is guarded on its own: a missing or frozen global must neither throw out of\n * `Sentry.init()` / `registerWebWorkerWasm()` nor keep the remaining patches from installing.\n */\nexport function patchWebAssembly(registerModule: RegisterModuleCallback): void {\n tryPatch(() => patchWasmResponseBodyReaders());\n tryPatch(() => patchNonStreamingWebAssembly(registerModule));\n tryPatch(() => patchStreamingWebAssembly(registerModule));\n}\n\nfunction tryPatch(patch: () => void): void {\n try {\n patch();\n } catch {\n // see patchWebAssembly()\n }\n}\n\n/** @internal */\nexport function _resetNonStreamingPatchForTests(): void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,GAAG,IAAI,CAAA,CAAE,KAAK,CAAA,MAAA,KAAU;AACjD,MAAA,wBAAA,CAAyB,cAAA,EAAgB,QAAQ,MAAM,CAAA;AACvD,MAAA,OAAO,MAAA;AAAA,IACT,CAAC,CAAA;AAAA,EACH,CAAA;AACF;AAQO,SAAS,iBAAiB,cAAA,EAA8C;AAC7E,EAAA,QAAA,CAAS,MAAM,8BAA8B,CAAA;AAC7C,EAAA,QAAA,CAAS,MAAM,4BAAA,CAA6B,cAAc,CAAC,CAAA;AAC3D,EAAA,QAAA,CAAS,MAAM,yBAAA,CAA0B,cAAc,CAAC,CAAA;AAC1D;AAEA,SAAS,SAAS,KAAA,EAAyB;AACzC,EAAA,IAAI;AACF,IAAA,KAAA,EAAM;AAAA,EACR,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;;;;"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Resolves a wasm source buffer back to its fetch URL, when known.
3
+ */
4
+ export declare function getWasmSourceUrl(source: unknown): string | undefined;
5
+ /**
6
+ * Patches Response body readers so wasm bytes remember their fetch URL.
7
+ */
8
+ export declare function patchWasmResponseBodyReaders(): void;
9
+ /** @internal */
10
+ export declare function _resetResponsePatchForTests(): void;
11
+ //# sourceMappingURL=patchWasmResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patchWasmResponse.d.ts","sourceRoot":"","sources":["../../../src/patchWasmResponse.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOpE;AAwCD;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CA0BnD;AAED,gBAAgB;AAChB,wBAAgB,2BAA2B,IAAI,IAAI,CAElD"}
@@ -1,10 +1,11 @@
1
1
  export type RegisterModuleCallback = (module: WebAssembly.Module, url: string) => void;
2
2
  /**
3
- * Patches the WebAssembly streaming APIs so that every compiled module gets
4
- * registered as a debug image under the URL of the response it was compiled
5
- * from.
3
+ * Patches the web assembly runtime.
6
4
  *
7
- * @param registerModule callback invoked for every successfully compiled module
5
+ * Every patch is guarded on its own: a missing or frozen global must neither throw out of
6
+ * `Sentry.init()` / `registerWebWorkerWasm()` nor keep the remaining patches from installing.
8
7
  */
9
8
  export declare function patchWebAssembly(registerModule: RegisterModuleCallback): void;
9
+ /** @internal */
10
+ export declare function _resetNonStreamingPatchForTests(): void;
10
11
  //# sourceMappingURL=patchWebAssembly.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"patchWebAssembly.d.ts","sourceRoot":"","sources":["../../../src/patchWebAssembly.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;AAEvF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,sBAAsB,GAAG,IAAI,CAwC7E"}
1
+ {"version":3,"file":"patchWebAssembly.d.ts","sourceRoot":"","sources":["../../../src/patchWebAssembly.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;AAmHvF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,sBAAsB,GAAG,IAAI,CAI7E;AAUD,gBAAgB;AAChB,wBAAgB,+BAA+B,IAAI,IAAI,CAEtD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/wasm",
3
- "version": "11.0.0-beta.1",
3
+ "version": "11.0.0-beta.2",
4
4
  "description": "Support for WASM.",
5
5
  "repository": "git://github.com/getsentry/sentry-javascript.git",
6
6
  "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/wasm",
@@ -32,8 +32,8 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
- "@sentry/browser": "11.0.0-beta.1",
36
- "@sentry/core": "11.0.0-beta.1"
35
+ "@sentry/browser": "11.0.0-beta.2",
36
+ "@sentry/core": "11.0.0-beta.2"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "run-p build:transpile build:bundle build:types",