Chromium Code Reviews| Index: test/inspector/debugger/wasm-imports.js |
| diff --git a/test/inspector/debugger/wasm-imports.js b/test/inspector/debugger/wasm-imports.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c82ad042c103272fc5a489470161b2404ee54130 |
| --- /dev/null |
| +++ b/test/inspector/debugger/wasm-imports.js |
| @@ -0,0 +1,123 @@ |
| +// Copyright 2017 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. |
| + |
| +load('test/mjsunit/wasm/wasm-constants.js'); |
| +load('test/mjsunit/wasm/wasm-module-builder.js'); |
| + |
| +// Build two modules A and B. A defines function func, which contains a |
| +// breakpoint. This function is then imported by B and called via main. The |
| +// breakpoint must be hit. |
| +// This failed before (http://crbug.com/v8/5971). |
| + |
| +var builder_a = new WasmModuleBuilder(); |
| +var func_idx = builder_a.addFunction('func', kSig_v_v) |
| + .addBody([kExprNop]) |
| + .exportFunc() |
| + .index; |
| +var module_a_bytes = builder_a.toArray(); |
| + |
| +var builder_b = new WasmModuleBuilder(); |
| +var import_idx = builder_b.addImport('imp', 'f', kSig_v_v); |
| +builder_b.addFunction('main', kSig_v_v) |
| + .addBody([kExprCallFunction, import_idx]) |
| + .exportFunc(); |
| +var module_b_bytes = builder_b.toArray(); |
| + |
| +function instantiate(bytes, imp) { |
| + var buffer = new ArrayBuffer(bytes.length); |
| + var view = new Uint8Array(buffer); |
| + for (var i = 0; i < bytes.length; ++i) { |
| + view[i] = bytes[i] | 0; |
| + } |
| + |
| + var module = new WebAssembly.Module(buffer); |
| + // Add to global instances array. |
| + instances.push(new WebAssembly.Instance(module, imp)); |
| +} |
| + |
| +var evalWithUrl = (code, url) => Protocol.Runtime.evaluate( |
| + {'expression': code + '\n//# sourceURL=v8://test/' + url}); |
| + |
| +Protocol.Debugger.onPaused(handlePaused); |
| +var script_a_id; |
| + |
| +Protocol.Debugger.enable() |
| + .then(() => InspectorTest.log('Installing code and global variable.')) |
| + .then( |
| + () => evalWithUrl( |
| + 'var instances = [];\n' + instantiate.toString(), 'setup')) |
| + .then(() => InspectorTest.log('Calling instantiate function for module A.')) |
| + .then( |
| + () => |
| + (evalWithUrl( |
| + 'instantiate(' + JSON.stringify(module_a_bytes) + ')', |
| + 'instantiateA'), |
| + 0)) |
| + .then(waitForWasmScript) |
| + .then(() => InspectorTest.log('Setting breakpoint in line 1, column 2')) |
| + .then(() => Protocol.Debugger.setBreakpoint({ |
|
kozy
2017/02/28 16:47:02
Just wondering, is setBreakpointByUrl supported fo
Clemens Hammacher
2017/03/02 14:02:35
Yes, it is. In order to also cover it, I just chan
|
| + 'location': |
|
kozy
2017/02/28 16:47:01
quotes are optional: 'location' -> location
Clemens Hammacher
2017/03/02 14:02:35
Done.
|
| + {'scriptId': script_a_id, 'lineNumber': 1, 'columnNumber': 2} |
| + })) |
| + .then(printFailure) |
| + .then(msg => InspectorTest.logMessage(msg.result.actualLocation)) |
|
kozy
2017/02/28 16:47:02
You can use here too, but please change argument t
Clemens Hammacher
2017/03/02 14:02:35
Done, but it required some refactoring.
logCallFra
|
| + .then(() => InspectorTest.log('Calling instantiate function for module B.')) |
| + .then( |
| + () => |
| + (evalWithUrl( |
| + 'instantiate(' + JSON.stringify(module_b_bytes) + |
| + ', {imp: {f: instances[0].exports.func}})', |
| + 'instantiateB'), |
| + 0)) |
| + .then(() => InspectorTest.log('Calling main function on module B.')) |
| + .then(() => evalWithUrl('instances[1].exports.main()', 'runWasm')) |
|
kozy
2017/02/28 16:47:02
To handle asynchronous call in onPaused handler yo
Clemens Hammacher
2017/03/02 14:02:35
Done, also inlined the handlePaused method, which
|
| + .then(() => InspectorTest.log('exports.main returned.')) |
| + .then(() => InspectorTest.log('Finished.')) |
| + .then(InspectorTest.completeTest); |
| + |
| +function printFailure(message) { |
| + if (!message.result) { |
| + InspectorTest.logMessage(message); |
| + } |
| + return message; |
| +} |
| + |
| +function waitForWasmScript() { |
|
kozy
2017/02/28 16:47:02
Less symbols with more promise magic:
function wa
Clemens Hammacher
2017/03/02 14:02:35
Wow, that's awesome. I now even return the url fro
|
| + InspectorTest.log('Waiting for wasm script to be parsed.'); |
| + var got_wasm_script; |
| + var promise = new Promise(fulfill => got_wasm_script = fulfill); |
| + function waitForMore() { |
| + Protocol.Debugger.onceScriptParsed() |
| + .then(handleNewScript); |
| + } |
| + function handleNewScript(msg) { |
| + var url = msg.params.url; |
| + if (!url.startsWith('wasm://')) { |
| + InspectorTest.log('Ignoring script with url ' + url); |
|
kozy
2017/02/28 16:47:01
Could potentially add flakiness if we compile some
Clemens Hammacher
2017/03/02 14:02:35
Done.
|
| + waitForMore(); |
| + return; |
| + } |
| + InspectorTest.log('Got wasm script!'); |
| + script_a_id = msg.params.scriptId; |
| + InspectorTest.log('Source:'); |
| + Protocol.Debugger.getScriptSource({scriptId: script_a_id}) |
| + .then(printFailure) |
| + .then(msg => InspectorTest.log(msg.result.scriptSource)) |
| + .then(() => got_wasm_script(script_a_id)); |
| + } |
| + waitForMore(); |
| + return promise; |
| +} |
| + |
| +function handlePaused(msg) { |
| + var loc = msg.params.callFrames[0].location; |
| + InspectorTest.log( |
|
kozy
2017/02/28 16:47:02
You can use InspectorTest.logCallFrames([msg.param
Clemens Hammacher
2017/03/02 14:02:35
Neverending awesomeness. Done!
|
| + 'Paused at ' + loc.lineNumber + ':' + loc.columnNumber + '.'); |
| + InspectorTest.log('Getting current stack trace via "new Error().stack".'); |
| + // TODO(clemensh): The interpreted frame should also show up on this stack |
|
kozy
2017/02/28 16:47:02
Sounds like big TODO, how stepping works in this c
Clemens Hammacher
2017/03/02 14:02:35
Stepping works correctly (on the top interpreter f
|
| + // trace. |
| + evalWithUrl('new Error().stack', 'getStack') |
|
kozy
2017/02/28 16:47:01
This command is asynchronous and it works currentl
kozy
2017/02/28 19:28:26
Oops, please disregard this comment, just change l
Clemens Hammacher
2017/03/02 14:02:35
Good catch! Done.
|
| + .then(msg => InspectorTest.log(msg.result.result.value)) |
| + .then(Protocol.Debugger.resume()); |
| +} |