| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright 2017 the V8 project authors. All rights reserved. | 
|  | 2 // Use of this source code is governed by a BSD-style license that can be | 
|  | 3 // found in the LICENSE file. | 
|  | 4 | 
|  | 5 utils.load('test/mjsunit/wasm/wasm-constants.js'); | 
|  | 6 utils.load('test/mjsunit/wasm/wasm-module-builder.js'); | 
|  | 7 | 
|  | 8 // Build two modules A and B. A defines function func, which contains a | 
|  | 9 // breakpoint. This function is then imported by B and called via main. The | 
|  | 10 // breakpoint must be hit. | 
|  | 11 // This failed before (http://crbug.com/v8/5971). | 
|  | 12 | 
|  | 13 var builder_a = new WasmModuleBuilder(); | 
|  | 14 var func_idx = builder_a.addFunction('func', kSig_v_v) | 
|  | 15                    .addBody([kExprNop]) | 
|  | 16                    .exportFunc() | 
|  | 17                    .index; | 
|  | 18 var module_a_bytes = builder_a.toArray(); | 
|  | 19 | 
|  | 20 var builder_b = new WasmModuleBuilder(); | 
|  | 21 var import_idx = builder_b.addImport('imp', 'f', kSig_v_v); | 
|  | 22 builder_b.addFunction('main', kSig_v_v) | 
|  | 23     .addBody([kExprCallFunction, import_idx]) | 
|  | 24     .exportFunc(); | 
|  | 25 var module_b_bytes = builder_b.toArray(); | 
|  | 26 | 
|  | 27 function instantiate(bytes, imp) { | 
|  | 28   var buffer = new ArrayBuffer(bytes.length); | 
|  | 29   var view = new Uint8Array(buffer); | 
|  | 30   for (var i = 0; i < bytes.length; ++i) { | 
|  | 31     view[i] = bytes[i] | 0; | 
|  | 32   } | 
|  | 33 | 
|  | 34   var module = new WebAssembly.Module(buffer); | 
|  | 35   // Add to global instances array. | 
|  | 36   instances.push(new WebAssembly.Instance(module, imp)); | 
|  | 37 } | 
|  | 38 | 
|  | 39 var evalWithUrl = (code, url) => Protocol.Runtime.evaluate( | 
|  | 40     {'expression': code + '\n//# sourceURL=v8://test/' + url}); | 
|  | 41 | 
|  | 42 InspectorTest.setupScriptMap(); | 
|  | 43 | 
|  | 44 // Main promise chain: | 
|  | 45 Protocol.Debugger.enable() | 
|  | 46     .then(() => InspectorTest.log('Installing code and global variable.')) | 
|  | 47     .then( | 
|  | 48         () => evalWithUrl( | 
|  | 49             'var instances = [];\n' + instantiate.toString(), 'setup')) | 
|  | 50     .then(() => InspectorTest.log('Calling instantiate function for module A.')) | 
|  | 51     .then( | 
|  | 52         () => | 
|  | 53             (evalWithUrl( | 
|  | 54                  'instantiate(' + JSON.stringify(module_a_bytes) + ')', | 
|  | 55                  'instantiateA'), | 
|  | 56              0)) | 
|  | 57     .then(() => InspectorTest.log('Waiting for wasm script to be parsed.')) | 
|  | 58     .then(waitForWasmScript) | 
|  | 59     .then(url => (InspectorTest.log('Setting breakpoint in line 1:'), url)) | 
|  | 60     .then( | 
|  | 61         url => | 
|  | 62             Protocol.Debugger.setBreakpointByUrl({lineNumber: 1, url: url})) | 
|  | 63     .then(printFailure) | 
|  | 64     .then(msg => InspectorTest.logSourceLocations(msg.result.locations)) | 
|  | 65     .then(() => InspectorTest.log('Calling instantiate function for module B.')) | 
|  | 66     .then( | 
|  | 67         () => | 
|  | 68             (evalWithUrl( | 
|  | 69                  'instantiate(' + JSON.stringify(module_b_bytes) + | 
|  | 70                      ', {imp: {f: instances[0].exports.func}})', | 
|  | 71                  'instantiateB'), | 
|  | 72              0)) | 
|  | 73     .then(() => InspectorTest.log('Calling main function on module B.')) | 
|  | 74     .then(() => evalWithUrl('instances[1].exports.main()', 'runWasm')) | 
|  | 75     .then(() => InspectorTest.log('exports.main returned.')) | 
|  | 76     .then(() => InspectorTest.log('Finished.')) | 
|  | 77     .then(InspectorTest.completeTest); | 
|  | 78 | 
|  | 79 // Separate promise chain for the asynchronous pause: | 
|  | 80 Protocol.Debugger.oncePaused() | 
|  | 81     .then(msg => msg.params.callFrames[0].location) | 
|  | 82     .then( | 
|  | 83         loc => | 
|  | 84             (InspectorTest.log( | 
|  | 85                  'Paused at ' + loc.lineNumber + ':' + loc.columnNumber + '.'), | 
|  | 86              loc)) | 
|  | 87     .then(InspectorTest.logSourceLocation) | 
|  | 88     .then( | 
|  | 89         () => InspectorTest.log( | 
|  | 90             'Getting current stack trace via "new Error().stack".')) | 
|  | 91     .then(() => evalWithUrl('new Error().stack', 'getStack')) | 
|  | 92     .then(msg => InspectorTest.log(msg.result.result.value)) | 
|  | 93     .then(Protocol.Debugger.resume); | 
|  | 94 | 
|  | 95 function printFailure(message) { | 
|  | 96   if (!message.result) { | 
|  | 97     InspectorTest.logMessage(message); | 
|  | 98   } | 
|  | 99   return message; | 
|  | 100 } | 
|  | 101 | 
|  | 102 function waitForWasmScript(msg) { | 
|  | 103   if (!msg || !msg.params.url.startsWith('wasm://')) { | 
|  | 104     return Protocol.Debugger.onceScriptParsed().then(waitForWasmScript); | 
|  | 105   } | 
|  | 106   InspectorTest.log('Got wasm script!'); | 
|  | 107   return Promise.resolve(msg.params.url); | 
|  | 108 } | 
| OLD | NEW | 
|---|