2019-05-10 00:52:56 +00:00
|
|
|
// Copyright 2019 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
// Flags: --experimental-wasm-reftypes
|
2019-05-10 00:52:56 +00:00
|
|
|
|
2020-06-16 05:11:11 +00:00
|
|
|
utils.load('test/inspector/wasm-inspector-test.js');
|
|
|
|
|
2019-05-10 00:52:56 +00:00
|
|
|
let {session, contextGroup, Protocol} =
|
2020-06-09 15:54:14 +00:00
|
|
|
InspectorTest.start('Test wasm scope information with externref globals');
|
2019-05-10 00:52:56 +00:00
|
|
|
|
2021-01-05 05:51:52 +00:00
|
|
|
InspectorTest.runAsyncTestSuite([
|
|
|
|
async function test() {
|
2019-05-10 00:52:56 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2020-06-09 15:54:14 +00:00
|
|
|
builder.addImportedGlobal('m', 'global', kWasmExternRef, false);
|
2020-01-09 12:11:55 +00:00
|
|
|
let func = builder.addFunction('func', kSig_v_v)
|
2019-05-10 00:52:56 +00:00
|
|
|
.addBody([
|
2019-10-08 13:16:30 +00:00
|
|
|
kExprGlobalGet, 0, //
|
2019-05-10 00:52:56 +00:00
|
|
|
kExprDrop, //
|
|
|
|
])
|
|
|
|
.exportAs('main');
|
|
|
|
let moduleBytes = JSON.stringify(builder.toArray());
|
|
|
|
|
|
|
|
function test(moduleBytes) {
|
|
|
|
let module = new WebAssembly.Module((new Uint8Array(moduleBytes)).buffer);
|
|
|
|
let global = 'hello, world';
|
|
|
|
instance = new WebAssembly.Instance(module, {m: {global}});
|
|
|
|
}
|
|
|
|
|
|
|
|
Protocol.Debugger.enable();
|
|
|
|
Protocol.Runtime.evaluate({
|
|
|
|
expression: `
|
|
|
|
let instance;
|
|
|
|
${test.toString()}
|
|
|
|
test(${moduleBytes});`
|
|
|
|
});
|
|
|
|
|
|
|
|
InspectorTest.log('Waiting for wasm script to be parsed.');
|
|
|
|
let scriptId;
|
|
|
|
while (true) {
|
|
|
|
let msg = await Protocol.Debugger.onceScriptParsed();
|
2020-01-09 12:11:55 +00:00
|
|
|
if (msg.params.url.startsWith('wasm://')) {
|
2019-05-10 00:52:56 +00:00
|
|
|
scriptId = msg.params.scriptId;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InspectorTest.log('Setting breakpoint in wasm.');
|
|
|
|
await Protocol.Debugger.setBreakpoint(
|
2020-01-09 12:11:55 +00:00
|
|
|
{location: {scriptId, lineNumber: 0, columnNumber: func.body_offset}});
|
2019-05-10 00:52:56 +00:00
|
|
|
|
|
|
|
InspectorTest.log('Running main.');
|
|
|
|
Protocol.Runtime.evaluate({expression: 'instance.exports.main()'});
|
|
|
|
|
|
|
|
let msg = await Protocol.Debugger.oncePaused();
|
|
|
|
let callFrames = msg.params.callFrames;
|
|
|
|
InspectorTest.log('Paused in debugger.');
|
|
|
|
let scopeChain = callFrames[0].scopeChain;
|
|
|
|
for (let scope of scopeChain) {
|
2020-04-15 05:02:40 +00:00
|
|
|
if (scope.type != 'module') continue;
|
2019-05-10 00:52:56 +00:00
|
|
|
|
2020-04-15 05:02:40 +00:00
|
|
|
let moduleObjectProps = (await Protocol.Runtime.getProperties({
|
2019-05-10 00:52:56 +00:00
|
|
|
'objectId': scope.object.objectId
|
|
|
|
})).result.result;
|
|
|
|
|
2020-04-15 05:02:40 +00:00
|
|
|
for (let prop of moduleObjectProps) {
|
|
|
|
if (prop.name != 'globals') continue;
|
2019-05-10 00:52:56 +00:00
|
|
|
let subProps = (await Protocol.Runtime.getProperties({
|
2020-04-15 05:02:40 +00:00
|
|
|
objectId: prop.value.objectId
|
|
|
|
})).result.result;
|
2019-05-10 00:52:56 +00:00
|
|
|
let values =
|
|
|
|
subProps.map((value) => `"${value.name}": ${value.value.value}`)
|
|
|
|
.join(', ');
|
|
|
|
InspectorTest.log(` ${prop.name}: {${values}}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-05 05:51:52 +00:00
|
|
|
]);
|