Is there a way to validate asm.js code

1.1k views Asked by At

I was hoping to spot compilation messages in Firefox Nightly but it does not happen. Is there a special switch for this?

2

There are 2 answers

8
Jan On

Haven't tested it but there seems to be a validator in here.

A quick look in the tests hints that it can be used as follows:

var asm = require('asm.js');

try {
  report = asm.validate(String(function f(stdlib, foreign, heap) {
    "use asm";

    // this is what we're validating
    function f() {
      var x = 0, y = 0;
      x = ((x|0)%(y|0))|0;
    }

    return {};
  }));

  console.log('Validated!');
} catch(e) {
  console.error(e);
}
0
NoBugs On

You can check that it compiles, in the Web Console: Given a page with "use asm" in a module, it should give:

Error: successfully compiled asm.js code (total compilation time 0ms)

or, an actual error about why it couldn't compile to asm.