Commit 27e22e6c authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Async-ify wasm-stepping test

This increases readability of the wasm-stepping test significantly.
Drive-by: Use more 'let' instead of 'var'.

R=yangguo@chromium.org

Change-Id: If80ba3a4b92cd3ab1c994e17fb8f40f5526517da
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1789298Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63616}
parent 48de043b
......@@ -6,9 +6,9 @@ let {session, contextGroup, Protocol} = InspectorTest.start('Tests stepping thro
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
let builder = new WasmModuleBuilder();
var func_a_idx =
let func_a_idx =
builder.addFunction('wasm_A', kSig_v_v).addBody([kExprNop, kExprNop]).index;
// wasm_B calls wasm_A <param0> times.
......@@ -30,26 +30,26 @@ builder.addFunction('wasm_B', kSig_v_i)
])
.exportAs('main');
var module_bytes = builder.toArray();
let module_bytes = builder.toArray();
function instantiate(bytes) {
var buffer = new ArrayBuffer(bytes.length);
var view = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; ++i) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
var module = new WebAssembly.Module(buffer);
let module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
}
var evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
let evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
{'expression': code + '\n//# sourceURL=v8://test/' + url});
Protocol.Debugger.onPaused(handlePaused);
var wasm_B_scriptId;
var step_actions = [
let wasm_B_scriptId;
let step_actions = [
'stepInto', // == stepOver, to call instruction
'stepInto', // into call to wasm_A
'stepOver', // over first nop
......@@ -69,38 +69,33 @@ var step_actions = [
// then just resume.
'resume'
];
for (var action of step_actions) {
for (let action of step_actions) {
InspectorTest.logProtocolCommandCalls('Debugger.' + action)
}
var sources = {};
var urls = {};
var afterTwoSourcesCallback;
Protocol.Debugger.enable()
.then(() => InspectorTest.log('Installing code an global variable.'))
.then(
() => evalWithUrl('var instance;\n' + instantiate.toString(), 'setup'))
.then(() => InspectorTest.log('Calling instantiate function.'))
.then(
() =>
(evalWithUrl(
'instantiate(' + JSON.stringify(module_bytes) + ')',
'callInstantiate'),
0))
.then(waitForTwoWasmScripts)
.then(
() => InspectorTest.log(
'Setting breakpoint on line 7 (on the setlocal before the call), url ' +
urls[wasm_B_scriptId]))
.then(
() => Protocol.Debugger.setBreakpoint(
{'location': {'scriptId': wasm_B_scriptId, 'lineNumber': 7}}))
.then(printFailure)
.then(msg => InspectorTest.logMessage(msg.result.actualLocation))
.then(() => evalWithUrl('instance.exports.main(4)', 'runWasm'))
.then(() => InspectorTest.log('exports.main returned!'))
.then(() => InspectorTest.log('Finished!'))
.then(InspectorTest.completeTest);
let sources = {};
let urls = {};
let afterTwoSourcesCallback;
(async function Test() {
await Protocol.Debugger.enable();
InspectorTest.log('Installing code an global variable.');
await evalWithUrl('var instance;\n' + instantiate.toString(), 'setup');
InspectorTest.log('Calling instantiate function.');
evalWithUrl(
'instantiate(' + JSON.stringify(module_bytes) + ')', 'callInstantiate');
await waitForTwoWasmScripts();
InspectorTest.log(
'Setting breakpoint on line 7 (on the setlocal before the call), url ' +
urls[wasm_B_scriptId]);
let msg = await Protocol.Debugger.setBreakpoint(
{'location': {'scriptId': wasm_B_scriptId, 'lineNumber': 7}});
printFailure(msg);
InspectorTest.logMessage(msg.result.actualLocation);
await evalWithUrl('instance.exports.main(4)', 'runWasm');
InspectorTest.log('exports.main returned!');
InspectorTest.log('Finished!');
InspectorTest.completeTest();
})();
function printFailure(message) {
if (!message.result) {
......@@ -109,41 +104,37 @@ function printFailure(message) {
return message;
}
function waitForTwoWasmScripts() {
var num = 0;
async function waitForTwoWasmScripts() {
let num = 0;
InspectorTest.log('Waiting for two wasm scripts to be parsed.');
var promise = new Promise(fulfill => gotBothSources = fulfill);
function waitForMore() {
if (num == 2) return promise;
Protocol.Debugger.onceScriptParsed()
.then(handleNewScript)
.then(waitForMore);
let source_promises = [];
async function getWasmSource(scriptId) {
let msg = await Protocol.Debugger.getScriptSource({scriptId: scriptId});
printFailure(msg);
InspectorTest.log(msg.result.scriptSource);
sources[scriptId] = msg.result.scriptSource;
}
function handleNewScript(msg) {
var url = msg.params.url;
while (num < 2) {
let msg = await Protocol.Debugger.onceScriptParsed();
let url = msg.params.url;
if (!url.startsWith('wasm://')) {
InspectorTest.log('Ignoring script with url ' + url);
return;
continue;
}
num += 1;
var scriptId = msg.params.scriptId;
let scriptId = msg.params.scriptId;
urls[scriptId] = url;
InspectorTest.log('Got wasm script: ' + url);
if (url.substr(-2) == '-1') wasm_B_scriptId = scriptId;
InspectorTest.log('Requesting source for ' + url + '...');
Protocol.Debugger.getScriptSource({scriptId: scriptId})
.then(printFailure)
.then(msg => sources[scriptId] = msg.result.scriptSource)
.then(InspectorTest.log)
.then(() => Object.keys(sources).length == 2 ? gotBothSources() : 0);
source_promises.push(getWasmSource(scriptId));
}
waitForMore();
return promise;
await Promise.all(source_promises);
}
function printPauseLocation(scriptId, lineNr, columnNr) {
var lines = sources[scriptId].split('\n');
var line = '<illegal line number>';
let lines = sources[scriptId].split('\n');
let line = '<illegal line number>';
if (lineNr < lines.length) {
line = lines[lineNr];
if (columnNr < line.length) {
......@@ -157,7 +148,7 @@ function printPauseLocation(scriptId, lineNr, columnNr) {
async function getValueString(value) {
if (value.type == 'object') {
var msg = await Protocol.Runtime.callFunctionOn({
let msg = await Protocol.Runtime.callFunctionOn({
objectId: value.objectId,
functionDeclaration: 'function () { return JSON.stringify(this); }'
});
......@@ -169,24 +160,24 @@ async function getValueString(value) {
async function dumpProperties(message) {
printFailure(message);
for (var value of message.result.result) {
var value_str = await getValueString(value.value);
for (let value of message.result.result) {
let value_str = await getValueString(value.value);
InspectorTest.log(' ' + value.name + ': ' + value_str);
}
}
async function dumpScopeChainsOnPause(message) {
for (var frame of message.params.callFrames) {
var functionName = frame.functionName || '(anonymous)';
var lineNumber = frame.location ? frame.location.lineNumber : frame.lineNumber;
var columnNumber = frame.location ? frame.location.columnNumber : frame.columnNumber;
for (let frame of message.params.callFrames) {
let functionName = frame.functionName || '(anonymous)';
let lineNumber = frame.location ? frame.location.lineNumber : frame.lineNumber;
let columnNumber = frame.location ? frame.location.columnNumber : frame.columnNumber;
InspectorTest.log(`at ${functionName} (${lineNumber}:${columnNumber}):`);
for (var scope of frame.scopeChain) {
for (let scope of frame.scopeChain) {
InspectorTest.logObject(' - scope (' + scope.type + '):');
if (scope.type == 'global') {
InspectorTest.logObject(' -- skipped');
} else {
var properties = await Protocol.Runtime.getProperties(
let properties = await Protocol.Runtime.getProperties(
{'objectId': scope.object.objectId});
await dumpProperties(properties);
}
......@@ -194,9 +185,10 @@ async function dumpScopeChainsOnPause(message) {
}
}
function handlePaused(msg) {
var loc = msg.params.callFrames[0].location;
async function handlePaused(msg) {
let loc = msg.params.callFrames[0].location;
printPauseLocation(loc.scriptId, loc.lineNumber, loc.columnNumber);
dumpScopeChainsOnPause(msg)
.then(Protocol.Debugger[step_actions.shift() || 'resume']);
await dumpScopeChainsOnPause(msg);
let action = step_actions.shift() || 'resume';
await Protocol.Debugger[action]();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment