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: --validate-asm | 5 // Flags: --expose-wasm test/mjsunit/wasm/wasm-constants.js test/mjsunit/wasm/wa
sm-module-builder.js |
6 | 6 |
7 function testFunction() { | 7 var builder = new WasmModuleBuilder(); |
8 function generateAsmJs(stdlib, foreign, heap) { | |
9 'use asm'; | |
10 var debugger_fun = foreign.call_debugger; | |
11 function callDebugger() { | |
12 debugger_fun(); | |
13 } | |
14 function redirectFun() { | |
15 callDebugger(); | |
16 } | |
17 return redirectFun; | |
18 } | |
19 | 8 |
| 9 var imported_idx = builder.addImport("func", kSig_v_v); |
| 10 |
| 11 var call_imported_idx = builder.addFunction("main", kSig_v_v) |
| 12 .addBody([kExprCallFunction, imported_idx]) |
| 13 .index; |
| 14 |
| 15 builder.addFunction("main", kSig_v_v) |
| 16 .addBody([kExprCallFunction, call_imported_idx]) |
| 17 .exportAs("main"); |
| 18 |
| 19 var module_bytes = builder.toArray(); |
| 20 |
| 21 function testFunction(bytes) { |
20 function call_debugger() { | 22 function call_debugger() { |
21 debugger; | 23 debugger; |
22 } | 24 } |
23 | 25 |
24 var fun = generateAsmJs(this, {'call_debugger': call_debugger}, undefined); | 26 var buffer = new ArrayBuffer(bytes.length); |
25 fun(); | 27 var view = new Uint8Array(buffer); |
| 28 for (var i = 0; i < bytes.length; i++) { |
| 29 view[i] = bytes[i] | 0; |
| 30 } |
| 31 |
| 32 var module = new WebAssembly.Module(buffer); |
| 33 var instance = new WebAssembly.Instance(module, {func: call_debugger}); |
| 34 |
| 35 instance.exports.main(); |
26 } | 36 } |
27 | 37 |
28 InspectorTest.addScript(testFunction.toString()); | 38 InspectorTest.addScript(testFunction.toString()); |
29 | 39 |
30 Protocol.Debugger.enable(); | 40 Protocol.Debugger.enable(); |
31 Protocol.Debugger.oncePaused().then(handleDebuggerPaused); | 41 Protocol.Debugger.oncePaused().then(handleDebuggerPaused); |
32 Protocol.Runtime.evaluate({'expression': 'testFunction()'}); | 42 InspectorTest.log('Running testFunction with generated WASM bytes...'); |
| 43 Protocol.Runtime.evaluate( |
| 44 {'expression': 'testFunction(' + JSON.stringify(module_bytes) + ')'}); |
33 | 45 |
34 function locationToString(callFrame) { | 46 function locationToString(callFrame) { |
35 var res = {functionName: callFrame.functionName}; | 47 var res = {functionName: callFrame.functionName}; |
36 for (var attr in callFrame.functionLocation) { | 48 for (var attr in callFrame.functionLocation) { |
37 if (attr == 'scriptId') continue; | 49 if (attr == 'scriptId') continue; |
38 res['function_'+attr] = callFrame.functionLocation[attr]; | 50 res['function_'+attr] = callFrame.functionLocation[attr]; |
39 } | 51 } |
40 for (var attr in callFrame.location) { | 52 for (var attr in callFrame.location) { |
41 if (attr == 'scriptId') continue; | 53 if (attr == 'scriptId') continue; |
42 res[attr] = callFrame.location[attr]; | 54 res[attr] = callFrame.location[attr]; |
(...skipping 27 matching lines...) Expand all Loading... |
70 { | 82 { |
71 InspectorTest.log( | 83 InspectorTest.log( |
72 'Result of evaluate (' + response.result.result.type + '):'); | 84 'Result of evaluate (' + response.result.result.type + '):'); |
73 var result_lines = response.result.result.value.split("\n"); | 85 var result_lines = response.result.result.value.split("\n"); |
74 // Skip the second line, containing the 'evaluate' position. | 86 // Skip the second line, containing the 'evaluate' position. |
75 result_lines[1] = " -- skipped --"; | 87 result_lines[1] = " -- skipped --"; |
76 InspectorTest.log(result_lines.join('\n')); | 88 InspectorTest.log(result_lines.join('\n')); |
77 InspectorTest.log('Finished!'); | 89 InspectorTest.log('Finished!'); |
78 InspectorTest.completeTest(); | 90 InspectorTest.completeTest(); |
79 } | 91 } |
OLD | NEW |