| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
| 6 | 6 |
| 7 load('test/mjsunit/wasm/wasm-constants.js'); | 7 load('test/mjsunit/wasm/wasm-constants.js'); |
| 8 load('test/mjsunit/wasm/wasm-module-builder.js'); | 8 load('test/mjsunit/wasm/wasm-module-builder.js'); |
| 9 | 9 |
| 10 var builder = new WasmModuleBuilder(); | 10 var builder = new WasmModuleBuilder(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 var module_bytes = builder.toArray(); | 30 var module_bytes = builder.toArray(); |
| 31 | 31 |
| 32 function testFunction(bytes) { | 32 function testFunction(bytes) { |
| 33 var buffer = new ArrayBuffer(bytes.length); | 33 var buffer = new ArrayBuffer(bytes.length); |
| 34 var view = new Uint8Array(buffer); | 34 var view = new Uint8Array(buffer); |
| 35 for (var i = 0; i < bytes.length; i++) { | 35 for (var i = 0; i < bytes.length; i++) { |
| 36 view[i] = bytes[i] | 0; | 36 view[i] = bytes[i] | 0; |
| 37 } | 37 } |
| 38 | 38 |
| 39 var module = new WebAssembly.Module(buffer); | 39 var module = new WebAssembly.Module(buffer); |
| 40 var instance = new WebAssembly.Instance(module); | |
| 41 | |
| 42 instance.exports.main(1); | |
| 43 } | 40 } |
| 44 | 41 |
| 45 InspectorTest.addScript(testFunction.toString()); | 42 var addSourceUrl = (code, url) => '//# sourceURL=' + url + '\n' + code; |
| 43 |
| 44 InspectorTest.addScript( |
| 45 addSourceUrl(testFunction.toString(), 'v8://test/testFunction')); |
| 46 InspectorTest.addScript('var module_bytes = ' + JSON.stringify(module_bytes)); | 46 InspectorTest.addScript('var module_bytes = ' + JSON.stringify(module_bytes)); |
| 47 | 47 |
| 48 Protocol.Debugger.enable(); | 48 Protocol.Debugger.enable(); |
| 49 Protocol.Debugger.onScriptParsed(handleScriptParsed); | 49 Protocol.Debugger.onScriptParsed(handleScriptParsed); |
| 50 InspectorTest.log('Running testFunction...'); | 50 InspectorTest.log('Running testFunction...'); |
| 51 Protocol.Runtime.evaluate({'expression': 'testFunction(module_bytes)'}) | 51 Protocol.Runtime |
| 52 .evaluate({ |
| 53 'expression': addSourceUrl( |
| 54 'testFunction(module_bytes)', 'v8://test/runTestFunction') |
| 55 }) |
| 56 .then(getBreakableLocationsForAllWasmScripts) |
| 57 .then(() => InspectorTest.log('Finished!')) |
| 52 .then(InspectorTest.completeTest); | 58 .then(InspectorTest.completeTest); |
| 53 | 59 |
| 54 var numScripts = 0; | 60 var numScripts = 0; |
| 61 var wasmScripts = []; |
| 55 function handleScriptParsed(messageObject) { | 62 function handleScriptParsed(messageObject) { |
| 56 InspectorTest.logMessage(messageObject); | 63 var scriptId = messageObject.params.scriptId; |
| 57 // TODO(clemensh): Request breakable locations in http://crrev.com/2536763002. | 64 var url = messageObject.params.url; |
| 65 InspectorTest.log('Script nr ' + numScripts + ' parsed. URL: ' + url); |
| 66 ++numScripts; |
| 67 |
| 68 if (url.startsWith('wasm://')) { |
| 69 InspectorTest.log('This is a wasm script (nr ' + wasmScripts.length + ').'); |
| 70 wasmScripts.push(scriptId); |
| 71 } |
| 58 } | 72 } |
| 73 |
| 74 function printBreakableLocations(message, expectedScriptId, source) { |
| 75 if (!message.result || !message.result.locations) { |
| 76 InspectorTest.logMessage(message); |
| 77 return; |
| 78 } |
| 79 var lines = source.split('\n'); |
| 80 var locations = message.result.locations; |
| 81 InspectorTest.log(locations.length + ' breakable location(s):'); |
| 82 for (var i = 0; i < locations.length; ++i) { |
| 83 if (locations[i].scriptId != expectedScriptId) { |
| 84 InspectorTest.log( |
| 85 'SCRIPT ID MISMATCH!! ' + locations[i].scriptId + ' != ' + |
| 86 expectedScriptId); |
| 87 } |
| 88 var line = locations[i].lineNumber < lines.length ? |
| 89 lines[locations[i].lineNumber] : |
| 90 '<illegal line number>'; |
| 91 InspectorTest.log( |
| 92 '[' + i + '] ' + locations[i].lineNumber + ':' + |
| 93 locations[i].columnNumber + ' || ' + line); |
| 94 } |
| 95 } |
| 96 |
| 97 function getSourceFromMessage(message) { |
| 98 if (!message.result || !message.result.scriptSource) { |
| 99 InspectorTest.logMessage(message); |
| 100 return ''; |
| 101 } |
| 102 return message.result.scriptSource; |
| 103 } |
| 104 |
| 105 function checkGetBreakableLocations(wasmScriptNr) { |
| 106 InspectorTest.log( |
| 107 'Requesting all breakable locations in wasm script ' + wasmScriptNr); |
| 108 var scriptId = wasmScripts[wasmScriptNr]; |
| 109 var source; |
| 110 return Protocol.Debugger.getScriptSource({scriptId: scriptId}) |
| 111 .then((message) => source = getSourceFromMessage(message)) |
| 112 .then( |
| 113 () => Protocol.Debugger.getPossibleBreakpoints( |
| 114 {start: {lineNumber: 0, columnNumber: 0, scriptId: scriptId}})) |
| 115 .then((message) => printBreakableLocations(message, scriptId, source)) |
| 116 .then( |
| 117 () => |
| 118 InspectorTest.log('Requesting breakable locations up to line 2')) |
| 119 .then(() => Protocol.Debugger.getPossibleBreakpoints({ |
| 120 start: {lineNumber: 0, columnNumber: 0, scriptId: scriptId}, |
| 121 end: {lineNumber: 3, columnNumber: 0, scriptId: scriptId} |
| 122 })) |
| 123 .then((message) => printBreakableLocations(message, scriptId, source)) |
| 124 .then( |
| 125 () => |
| 126 InspectorTest.log('Requesting breakable locations in lines 3-4')) |
| 127 .then(() => Protocol.Debugger.getPossibleBreakpoints({ |
| 128 start: {lineNumber: 3, columnNumber: 0, scriptId: scriptId}, |
| 129 end: {lineNumber: 5, columnNumber: 0, scriptId: scriptId} |
| 130 })) |
| 131 .then((message) => printBreakableLocations(message, scriptId, source)); |
| 132 } |
| 133 |
| 134 function getBreakableLocationsForAllWasmScripts() { |
| 135 InspectorTest.log('Querying breakable locations for all wasm scripts now...'); |
| 136 var promise = Promise.resolve(); |
| 137 for (var wasmScriptNr = 0; wasmScriptNr < wasmScripts.length; |
| 138 ++wasmScriptNr) { |
| 139 promise = promise.then(checkGetBreakableLocations.bind(null, wasmScriptNr)); |
| 140 } |
| 141 return promise; |
| 142 } |
| OLD | NEW |