diff options
Diffstat (limited to 'test/binaryen.js/sourcemap.js')
-rw-r--r-- | test/binaryen.js/sourcemap.js | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/test/binaryen.js/sourcemap.js b/test/binaryen.js/sourcemap.js index 04f188e23..f8deecf3f 100644 --- a/test/binaryen.js/sourcemap.js +++ b/test/binaryen.js/sourcemap.js @@ -2,41 +2,45 @@ function assert(x) { if (!x) throw 'error!'; } -var module = new Binaryen.Module(); - -var fileIndex = module.addDebugInfoFileName("module.c"); - -console.log(module.getDebugInfoFileName(fileIndex)); -console.log(); - -var expr = module.i32.const(1); -var body = module.block("", [ - expr -], Binaryen.i32); - -var func = module.addFunction("main", Binaryen.none, Binaryen.i32, [], body); - -module.setDebugLocation(func, expr, fileIndex, 1, 2); -module.setDebugLocation(func, body, fileIndex, 0, 3); - -var output = module.emitBinary("module.wasm.map"); -assert(module.validate()); - -function dumpBinary(buffer) { - var hex = [], o, b, h; - for (var i = 0; i < buffer.length; ++i) { - o = i.toString(16); - while (o.length < 3) o = "0" + o; - if ((i & 15) === 0) hex.push((i ? "\n" : "") + o + ":"); - if ((b = buffer[i]) >= 0x21 && b <= 0x7e) - h = String.fromCharCode(b) + ' '; - else if ((h = b.toString(16)).length < 2) - h = "0" + h; - hex.push(h); +function test() { + var module = new Binaryen.Module(); + + var fileIndex = module.addDebugInfoFileName("module.c"); + + console.log(module.getDebugInfoFileName(fileIndex)); + console.log(); + + var expr = module.i32.const(1); + var body = module.block("", [ + expr + ], Binaryen.i32); + + var func = module.addFunction("main", Binaryen.none, Binaryen.i32, [], body); + + module.setDebugLocation(func, expr, fileIndex, 1, 2); + module.setDebugLocation(func, body, fileIndex, 0, 3); + + var output = module.emitBinary("module.wasm.map"); + assert(module.validate()); + + function dumpBinary(buffer) { + var hex = [], o, b, h; + for (var i = 0; i < buffer.length; ++i) { + o = i.toString(16); + while (o.length < 3) o = "0" + o; + if ((i & 15) === 0) hex.push((i ? "\n" : "") + o + ":"); + if ((b = buffer[i]) >= 0x21 && b <= 0x7e) + h = String.fromCharCode(b) + ' '; + else if ((h = b.toString(16)).length < 2) + h = "0" + h; + hex.push(h); + } + console.log(hex.join(" ")); } - console.log(hex.join(" ")); + + dumpBinary(output.binary); + console.log(); + console.log(output.sourceMap); } -dumpBinary(output.binary); -console.log(); -console.log(output.sourceMap); +Binaryen.ready.then(test); |