Skip to content

Commit 49481db

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[network] Fix response view for wasm requests
The CL https://crrev.com/c/5569109 broke Network > Response for wasm requests. Since we don't connect NetworkRequest with Script, its not enough to just disassemble WASM in Script. This CL re-instates the adhoc disassembling of wasm to the SourceFrame and adds a better test. [email protected] Bug: 40240361 Fixed: 375408034 Change-Id: I41d000ecf9b57f89ac0ea2b2b6b5c0918be01b85 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5964716 Commit-Queue: Simon Zünd <[email protected]> Reviewed-by: Philip Pfaffe <[email protected]>
1 parent 73feede commit 49481db

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

front_end/core/sdk/Script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ function frameIdForScript(script: Script): Protocol.Page.FrameId|null {
498498

499499
export const sourceURLRegex = /^[\x20\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/;
500500

501-
async function disassembleWasm(content: string): Promise<TextUtils.WasmDisassembly.WasmDisassembly> {
501+
export async function disassembleWasm(content: string): Promise<TextUtils.WasmDisassembly.WasmDisassembly> {
502502
const worker = Common.Worker.WorkerWrapper.fromURL(
503503
new URL('../../entrypoints/wasmparser_worker/wasmparser_worker-entrypoint.js', import.meta.url));
504504
const promise = new Promise<TextUtils.WasmDisassembly.WasmDisassembly>((resolve, reject) => {

front_end/ui/legacy/components/source_frame/SourceFrame.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
dispatchPasteEvent,
1111
} from '../../../../testing/DOMHelpers.js';
1212
import {describeWithEnvironment} from '../../../../testing/EnvironmentHelpers.js';
13+
import {expectCall} from '../../../../testing/ExpectStubCall.js';
1314
import * as Buttons from '../../../components/buttons/buttons.js';
1415
import * as UI from '../../legacy.js';
1516

@@ -125,4 +126,21 @@ describeWithEnvironment('SourceFrame', () => {
125126
assert.isNull(dialogContainer);
126127
stub.restore();
127128
});
129+
130+
it('disassembles wasm', async () => {
131+
const contentData = new TextUtils.ContentData.ContentData(
132+
'AGFzbQEAAAABBQFgAAF/AwIBAAcHAQNiYXIAAAoGAQQAQQILACQEbmFtZQAQD3Nob3ctd2FzbS0yLndhdAEGAQADYmFyAgMBAAA=', true,
133+
'application/wasm');
134+
const sourceFrame = new SourceFrame.SourceFrame.SourceFrameImpl(async () => contentData);
135+
136+
sourceFrame.markAsRoot();
137+
const setContentStub = sinon.stub(sourceFrame, 'setContent');
138+
sourceFrame.show(document.body);
139+
const content = await expectCall(setContentStub);
140+
141+
assert.strictEqual(
142+
content.toString(), '(module\n (func $bar (;0;) (export \"bar\") (result i32)\n i32.const 2\n )\n)');
143+
144+
sourceFrame.detach();
145+
});
128146
});

front_end/ui/legacy/components/source_frame/SourceFrame.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import * as Host from '../../../../core/host/host.js';
3333
import * as i18n from '../../../../core/i18n/i18n.js';
3434
import * as Platform from '../../../../core/platform/platform.js';
3535
import * as Root from '../../../../core/root/root.js';
36+
import * as SDK from '../../../../core/sdk/sdk.js';
3637
import * as Formatter from '../../../../models/formatter/formatter.js';
3738
import * as TextUtils from '../../../../models/text_utils/text_utils.js';
3839
import * as CodeMirror from '../../../../third_party/codemirror.next/codemirror.next.js';
@@ -569,6 +570,11 @@ export class SourceFrameImpl extends Common.ObjectWrapper.eventMixin<EventTypes,
569570
content = contentData.text;
570571
isMinified = TextUtils.TextUtils.isMinified(contentData.text);
571572
this.wasmDisassemblyInternal = null;
573+
} else if (contentData.mimeType === 'application/wasm') {
574+
// The network panel produces ContentData with raw WASM inside. We have to manually disassemble that
575+
// as V8 might not know about it.
576+
this.wasmDisassemblyInternal = await SDK.Script.disassembleWasm(contentData.base64);
577+
content = CodeMirror.Text.of(this.wasmDisassemblyInternal.lines);
572578
} else {
573579
error = i18nString(UIStrings.binaryContentError);
574580
content = null;

0 commit comments

Comments
 (0)