OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --expose-wasm |
| 6 |
| 7 load('test/mjsunit/wasm/wasm-constants.js'); |
| 8 load('test/mjsunit/wasm/wasm-module-builder.js'); |
| 9 |
| 10 // Add two empty functions. Both should be registered as individual scripts at |
| 11 // module creation time. |
| 12 var builder = new WasmModuleBuilder(); |
| 13 builder.addFunction('nopFunction', kSig_v_v).addBody([kExprNop]); |
| 14 builder.addFunction('main', kSig_v_v) |
| 15 .addBody([kExprBlock, kAstStmt, kExprI32Const, 2, kExprDrop, kExprEnd]) |
| 16 .exportAs('main'); |
| 17 var module_bytes = builder.toArray(); |
| 18 |
| 19 function testFunction(bytes) { |
| 20 var buffer = new ArrayBuffer(bytes.length); |
| 21 var view = new Uint8Array(buffer); |
| 22 for (var i = 0; i < bytes.length; i++) { |
| 23 view[i] = bytes[i] | 0; |
| 24 } |
| 25 |
| 26 // Compilation triggers registration of wasm scripts. |
| 27 new WebAssembly.Module(buffer); |
| 28 } |
| 29 |
| 30 InspectorTest.addScriptWithUrl( |
| 31 testFunction.toString(), 'v8://test/testFunction'); |
| 32 InspectorTest.addScript('var module_bytes = ' + JSON.stringify(module_bytes)); |
| 33 |
| 34 Protocol.Debugger.enable(); |
| 35 Protocol.Debugger.onScriptParsed(handleScriptParsed); |
| 36 InspectorTest.log( |
| 37 'Check that inspector gets two wasm scripts at module creation time.'); |
| 38 Protocol.Runtime |
| 39 .evaluate({ |
| 40 'expression': '//# sourceURL=v8://test/runTestRunction\n' + |
| 41 'testFunction(module_bytes)' |
| 42 }) |
| 43 .then(checkFinished); |
| 44 |
| 45 var num_scripts = 0; |
| 46 var missing_sources = 0; |
| 47 |
| 48 function checkFinished() { |
| 49 if (missing_sources == 0) |
| 50 InspectorTest.completeTest(); |
| 51 } |
| 52 |
| 53 function handleScriptParsed(messageObject) |
| 54 { |
| 55 var url = messageObject.params.url; |
| 56 InspectorTest.log("Script #" + num_scripts + " parsed. URL: " + url); |
| 57 ++num_scripts; |
| 58 |
| 59 if (url.startsWith("wasm://")) { |
| 60 ++missing_sources; |
| 61 function dumpScriptSource(message) { |
| 62 InspectorTest.log("Source for " + url + ":"); |
| 63 InspectorTest.log(message.result.scriptSource); |
| 64 --missing_sources; |
| 65 } |
| 66 |
| 67 Protocol.Debugger.getScriptSource({scriptId: messageObject.params.scriptId}) |
| 68 .then(dumpScriptSource.bind(null)) |
| 69 .then(checkFinished); |
| 70 } |
| 71 } |
OLD | NEW |