MCPcopy Create free account
hub / github.com/ChromeDevTools/devtools-frontend / loadWasmContent

Method loadWasmContent

front_end/core/sdk/Script.ts:208–259  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

206 }
207
208 private async loadWasmContent(): Promise<TextUtils.ContentData.ContentDataOrError> {
209 if (!this.isWasm()) {
210 throw new Error('Not a wasm script');
211 }
212 const result =
213 await this.debuggerModel.target().debuggerAgent().invoke_disassembleWasmModule({scriptId: this.scriptId});
214
215 if (result.getError()) {
216 // Fall through to text content loading if v8-based disassembly fails. This is to ensure backwards compatibility with
217 // older v8 versions.
218 const contentData = await this.loadTextContent();
219 return await disassembleWasm(contentData.base64);
220 }
221
222 const {streamId, functionBodyOffsets, chunk: {lines, bytecodeOffsets}} = result;
223 const lineChunks = [];
224 const bytecodeOffsetChunks = [];
225 let totalLength = lines.reduce<number>((sum, line) => sum + line.length + 1, 0);
226 const truncationMessage = '<truncated>';
227 // This is a magic number used in code mirror which, when exceeded, sends it into an infinite loop.
228 const cmSizeLimit = 1000000000 - truncationMessage.length;
229 if (streamId) {
230 while (true) {
231 const result = await this.debuggerModel.target().debuggerAgent().invoke_nextWasmDisassemblyChunk({streamId});
232
233 if (result.getError()) {
234 throw new Error(result.getError());
235 }
236
237 const {chunk: {lines: linesChunk, bytecodeOffsets: bytecodeOffsetsChunk}} = result;
238 totalLength += linesChunk.reduce<number>((sum, line) => sum + line.length + 1, 0);
239 if (linesChunk.length === 0) {
240 break;
241 }
242 if (totalLength >= cmSizeLimit) {
243 lineChunks.push([truncationMessage]);
244 bytecodeOffsetChunks.push([0]);
245 break;
246 }
247
248 lineChunks.push(linesChunk);
249 bytecodeOffsetChunks.push(bytecodeOffsetsChunk);
250 }
251 }
252 const functionBodyRanges: Array<{start: number, end: number}> = [];
253 // functionBodyOffsets contains a sequence of pairs of start and end offsets
254 for (let i = 0; i < functionBodyOffsets.length; i += 2) {
255 functionBodyRanges.push({start: functionBodyOffsets[i], end: functionBodyOffsets[i + 1]});
256 }
257 return new TextUtils.WasmDisassembly.WasmDisassembly(
258 lines.concat(...lineChunks), bytecodeOffsets.concat(...bytecodeOffsetChunks), functionBodyRanges);
259 }
260
261 requestContentData(): Promise<TextUtils.ContentData.ContentDataOrError> {
262 if (!this.#contentPromise) {

Callers 1

#requestContentMethod · 0.95

Calls 9

isWasmMethod · 0.95
loadTextContentMethod · 0.95
disassembleWasmFunction · 0.85
debuggerAgentMethod · 0.80
getErrorMethod · 0.80
targetMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected