| Index: test/inspector/debugger/wasm-get-breakable-locations.js
|
| diff --git a/test/inspector/debugger/wasm-get-breakable-locations.js b/test/inspector/debugger/wasm-get-breakable-locations.js
|
| index 3378aced3f6e9c6937770d405c1633a6fcc215b9..a78bc59c567f73f189566ebe53d15bdf33c2d229 100644
|
| --- a/test/inspector/debugger/wasm-get-breakable-locations.js
|
| +++ b/test/inspector/debugger/wasm-get-breakable-locations.js
|
| @@ -37,22 +37,106 @@ function testFunction(bytes) {
|
| }
|
|
|
| var module = new WebAssembly.Module(buffer);
|
| - var instance = new WebAssembly.Instance(module);
|
| -
|
| - instance.exports.main(1);
|
| }
|
|
|
| -InspectorTest.addScript(testFunction.toString());
|
| +var addSourceUrl = (code, url) => '//# sourceURL=' + url + '\n' + code;
|
| +
|
| +InspectorTest.addScript(
|
| + addSourceUrl(testFunction.toString(), 'v8://test/testFunction'));
|
| InspectorTest.addScript('var module_bytes = ' + JSON.stringify(module_bytes));
|
|
|
| Protocol.Debugger.enable();
|
| Protocol.Debugger.onScriptParsed(handleScriptParsed);
|
| InspectorTest.log('Running testFunction...');
|
| -Protocol.Runtime.evaluate({'expression': 'testFunction(module_bytes)'})
|
| +Protocol.Runtime
|
| + .evaluate({
|
| + 'expression': addSourceUrl(
|
| + 'testFunction(module_bytes)', 'v8://test/runTestFunction')
|
| + })
|
| + .then(getBreakableLocationsForAllWasmScripts)
|
| + .then(() => InspectorTest.log('Finished!'))
|
| .then(InspectorTest.completeTest);
|
|
|
| var numScripts = 0;
|
| +var wasmScripts = [];
|
| function handleScriptParsed(messageObject) {
|
| - InspectorTest.logMessage(messageObject);
|
| - // TODO(clemensh): Request breakable locations in http://crrev.com/2536763002.
|
| + var scriptId = messageObject.params.scriptId;
|
| + var url = messageObject.params.url;
|
| + InspectorTest.log('Script nr ' + numScripts + ' parsed. URL: ' + url);
|
| + ++numScripts;
|
| +
|
| + if (url.startsWith('wasm://')) {
|
| + InspectorTest.log('This is a wasm script (nr ' + wasmScripts.length + ').');
|
| + wasmScripts.push(scriptId);
|
| + }
|
| +}
|
| +
|
| +function printBreakableLocations(message, expectedScriptId, source) {
|
| + if (!message.result || !message.result.locations) {
|
| + InspectorTest.logMessage(message);
|
| + return;
|
| + }
|
| + var lines = source.split('\n');
|
| + var locations = message.result.locations;
|
| + InspectorTest.log(locations.length + ' breakable location(s):');
|
| + for (var i = 0; i < locations.length; ++i) {
|
| + if (locations[i].scriptId != expectedScriptId) {
|
| + InspectorTest.log(
|
| + 'SCRIPT ID MISMATCH!! ' + locations[i].scriptId + ' != ' +
|
| + expectedScriptId);
|
| + }
|
| + var line = locations[i].lineNumber < lines.length ?
|
| + lines[locations[i].lineNumber] :
|
| + '<illegal line number>';
|
| + InspectorTest.log(
|
| + '[' + i + '] ' + locations[i].lineNumber + ':' +
|
| + locations[i].columnNumber + ' || ' + line);
|
| + }
|
| +}
|
| +
|
| +function getSourceFromMessage(message) {
|
| + if (!message.result || !message.result.scriptSource) {
|
| + InspectorTest.logMessage(message);
|
| + return '';
|
| + }
|
| + return message.result.scriptSource;
|
| +}
|
| +
|
| +function checkGetBreakableLocations(wasmScriptNr) {
|
| + InspectorTest.log(
|
| + 'Requesting all breakable locations in wasm script ' + wasmScriptNr);
|
| + var scriptId = wasmScripts[wasmScriptNr];
|
| + var source;
|
| + return Protocol.Debugger.getScriptSource({scriptId: scriptId})
|
| + .then((message) => source = getSourceFromMessage(message))
|
| + .then(
|
| + () => Protocol.Debugger.getPossibleBreakpoints(
|
| + {start: {lineNumber: 0, columnNumber: 0, scriptId: scriptId}}))
|
| + .then((message) => printBreakableLocations(message, scriptId, source))
|
| + .then(
|
| + () =>
|
| + InspectorTest.log('Requesting breakable locations up to line 2'))
|
| + .then(() => Protocol.Debugger.getPossibleBreakpoints({
|
| + start: {lineNumber: 0, columnNumber: 0, scriptId: scriptId},
|
| + end: {lineNumber: 3, columnNumber: 0, scriptId: scriptId}
|
| + }))
|
| + .then((message) => printBreakableLocations(message, scriptId, source))
|
| + .then(
|
| + () =>
|
| + InspectorTest.log('Requesting breakable locations in lines 3-4'))
|
| + .then(() => Protocol.Debugger.getPossibleBreakpoints({
|
| + start: {lineNumber: 3, columnNumber: 0, scriptId: scriptId},
|
| + end: {lineNumber: 5, columnNumber: 0, scriptId: scriptId}
|
| + }))
|
| + .then((message) => printBreakableLocations(message, scriptId, source));
|
| +}
|
| +
|
| +function getBreakableLocationsForAllWasmScripts() {
|
| + InspectorTest.log('Querying breakable locations for all wasm scripts now...');
|
| + var promise = Promise.resolve();
|
| + for (var wasmScriptNr = 0; wasmScriptNr < wasmScripts.length;
|
| + ++wasmScriptNr) {
|
| + promise = promise.then(checkGetBreakableLocations.bind(null, wasmScriptNr));
|
| + }
|
| + return promise;
|
| }
|
|
|