MCPcopy
hub / github.com/microsoft/vscode-js-debug / WasmVariable

Class WasmVariable

src/adapter/variableStore.ts:1321–1404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1319}
1320
1321class WasmVariable implements IVariable, IMemoryReadable {
1322 public static presentationHint: Dap.VariablePresentationHint = {
1323 attributes: ['readOnly'],
1324 };
1325
1326 /** @inheritdoc */
1327 public readonly id = getVariableId();
1328
1329 /** @inheritdoc */
1330 public readonly sortOrder = 0;
1331
1332 constructor(
1333 private readonly context: VariableContext,
1334 private readonly variable: IWasmVariableEvaluation,
1335 private readonly scopeRef: IScopeRef,
1336 ) {}
1337
1338 public toDap(): Promise<Dap.Variable> {
1339 return Promise.resolve({
1340 name: this.context.name,
1341 value: this.variable.description || '',
1342 variablesReference: this.variable.getChildren ? this.id : 0,
1343 memoryReference: this.variable.linearMemoryAddress ? String(this.id) : undefined,
1344 presentationHint: this.context.presentationHint,
1345 });
1346 }
1347
1348 public async getChildren(): Promise<IVariable[]> {
1349 const children = (await this.variable.getChildren?.()) || [];
1350 return children.map(c =>
1351 this.context.createVariable(
1352 WasmVariable,
1353 { name: c.name, presentationHint: WasmVariable.presentationHint },
1354 c.value,
1355 this.scopeRef,
1356 )
1357 );
1358 }
1359
1360 /** @inheritdoc */
1361 public async readMemory(offset: number, count: number): Promise<Buffer | undefined> {
1362 const addr = this.variable.linearMemoryAddress;
1363 if (addr === undefined) {
1364 return undefined;
1365 }
1366
1367 const result = await this.context.cdp.Debugger.evaluateOnCallFrame({
1368 callFrameId: this.scopeRef.callFrameId,
1369 expression: `(${readMemory.source}).call(memories[0].buffer, ${
1370 +addr + offset
1371 }, ${+count}) ${getSourceSuffix()}`,
1372 returnByValue: true,
1373 });
1374
1375 if (!result) {
1376 throw new RemoteException({
1377 exceptionId: 0,
1378 text: 'No response from CDP',

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected