Files: 8bb4a56dbe5e93628a52ae3c5ca8036755aea00f / debugInterface.js
880 bytesRaw
1 | /** |
2 | * Debug Interface |
3 | * This expose some functions that can help with debugging wast |
4 | */ |
5 | |
6 | // This is ASCII only |
7 | function Uint8ArrayToString (input) { |
8 | return String.fromCharCode.apply(null, input) |
9 | } |
10 | |
11 | function Uint8ArrayToHexString (input) { |
12 | var ret = '' |
13 | for (var i = 0; i < input.length; i++) { |
14 | ret += input[i].toString(16) |
15 | } |
16 | return ret |
17 | } |
18 | |
19 | module.exports = class DebugInterface { |
20 | setModule (mod) { |
21 | this.module = mod |
22 | } |
23 | |
24 | get exportTable () { |
25 | return { |
26 | 'print': function (offset = 0, length = 100) { |
27 | console.log(`<DEBUG(str): ${Uint8ArrayToString(new Uint8Array(this.module.exports.memory, offset, length))}>`) |
28 | }.bind(this), |
29 | |
30 | 'printHex': function (offset = 0, length = 100) { |
31 | console.log(`<DEBUG(hex): ${Uint8ArrayToHexString(new Uint8Array(this.module.exports.memory, offset, length))}>`) |
32 | }.bind(this) |
33 | } |
34 | } |
35 | } |
36 |
Built with git-ssb-web