-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(wasm): Register modules loaded via non-streaming WebAssembly APIs #23661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
andreiborza
wants to merge
3
commits into
ab/wasm-patch-plumbing
from
ab/wasm-nonstreaming-registration
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
dev-packages/browser-integration-tests/suites/wasm/instantiateBuffer/init.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
| import { wasmIntegration } from '@sentry/wasm'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| traceLifecycle: 'static', | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [wasmIntegration()], | ||
| beforeSend: event => { | ||
| window.events.push(event); | ||
| return null; | ||
| }, | ||
| }); | ||
| window.events = []; |
52 changes: 52 additions & 0 deletions
52
dev-packages/browser-integration-tests/suites/wasm/instantiateBuffer/subject.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| function leb128(n) { | ||
| const out = []; | ||
| do { | ||
| let byte = n & 0x7f; | ||
| n >>>= 7; | ||
| if (n !== 0) { | ||
| byte |= 0x80; | ||
| } | ||
| out.push(byte); | ||
| } while (n !== 0); | ||
| return out; | ||
| } | ||
|
|
||
| // Appends a custom section with `padding` payload bytes so the module wire | ||
| // bytes cross V8's 16383-byte content-hashing cutoff. | ||
| function pad(bytes, padding) { | ||
| const payload = new Uint8Array(padding); | ||
| for (let i = 0; i < padding; i++) { | ||
| payload[i] = (i * 31 + 7) & 0xff; | ||
| } | ||
| const content = [1, 0x70, ...leb128(payload.length)]; | ||
| const header = [0x00, ...leb128(2 + payload.length)]; | ||
| const out = new Uint8Array(bytes.length + header.length + 2 + payload.length); | ||
| out.set(bytes, 0); | ||
| out.set(header, bytes.length); | ||
| out.set([1, 0x70], bytes.length + header.length); | ||
| out.set(payload, bytes.length + header.length + 2); | ||
| return out; | ||
| } | ||
|
|
||
| window.getEvent = async padding => { | ||
| function crash() { | ||
| throw new Error('whoops'); | ||
| } | ||
|
|
||
| const response = await fetch('https://localhost:5887/simple.wasm'); | ||
| const buffer = await response.arrayBuffer(); | ||
| const bytes = padding ? pad(new Uint8Array(buffer), padding) : new Uint8Array(buffer); | ||
|
|
||
| const { instance } = await WebAssembly.instantiate(bytes, { | ||
| env: { | ||
| external_func: crash, | ||
| }, | ||
| }); | ||
|
|
||
| try { | ||
| instance.exports.internal_func(); | ||
| } catch (err) { | ||
| Sentry.captureException(err); | ||
| return { event: window.events.pop(), byteLength: bytes.byteLength }; | ||
| } | ||
| }; |
72 changes: 72 additions & 0 deletions
72
dev-packages/browser-integration-tests/suites/wasm/instantiateBuffer/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import type { Page, Route } from '@playwright/test'; | ||
| import { expect } from '@playwright/test'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { sentryTest } from '../../../utils/fixtures'; | ||
| import { shouldSkipWASMTests } from '../../../utils/wasmHelpers'; | ||
|
|
||
| function serveWasmFixture(page: Page): Promise<void> { | ||
| return page.route('**/simple.wasm', (route: Route) => { | ||
| const wasmModule = fs.readFileSync(path.resolve(__dirname, '..', 'simple.wasm')); | ||
|
|
||
| return route.fulfill({ | ||
| status: 200, | ||
| body: wasmModule, | ||
| headers: { | ||
| 'Content-Type': 'application/wasm', | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| const IMAGE_MATCHER = { | ||
| code_file: expect.stringMatching(/^wasm:\/\/wasm\/[0-9a-f]{8}$/), | ||
| code_id: '0ba020cdd2444f7eafdd25999a8e9010', | ||
| debug_file: null, | ||
| debug_id: '0ba020cdd2444f7eafdd25999a8e90100', | ||
| type: 'wasm', | ||
| }; | ||
|
|
||
| const FRAME_MATCHER = { | ||
| function: 'internal_func', | ||
| in_app: true, | ||
| instruction_addr: '0x8c', | ||
| addr_mode: 'rel:0', | ||
| platform: 'native', | ||
| }; | ||
|
|
||
| sentryTest( | ||
| 'exactly matches the length-derived synthetic name for modules above the content-hash cutoff', | ||
| async ({ getLocalTestUrl, page, browserName }) => { | ||
| if (shouldSkipWASMTests(browserName) || browserName === 'firefox') { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
| await serveWasmFixture(page); | ||
| await page.goto(url); | ||
|
|
||
| const { event, byteLength } = await page.evaluate(async () => { | ||
| // @ts-expect-error this function exists | ||
| return window.getEvent(17000); | ||
| }); | ||
|
|
||
| // V8 does not content-hash modules above 16383 bytes; the synthetic name | ||
| // derives from the byte length alone on every V8 version. | ||
| expect(byteLength).toBeGreaterThan(16383); | ||
| const expectedUrl = `wasm://wasm/${(byteLength * 4 + 2).toString(16).padStart(8, '0')}`; | ||
|
|
||
| expect(event.exception.values[0].stacktrace.frames).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| ...FRAME_MATCHER, | ||
| filename: expectedUrl, | ||
| }), | ||
| ]), | ||
| ); | ||
|
|
||
| expect(event.debug_meta).toMatchObject({ | ||
| images: [{ ...IMAGE_MATCHER, code_file: expectedUrl }], | ||
| }); | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.