DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (5b81998bb7ab)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=854209
-->
<head>
  <meta charset="utf-8">
  <title>asm.js browser tests</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=854209">asm.js browser tests</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();

ok(jsFuns.isAsmJSCompilationAvailable());

function f1() { "use asm"; function g() {} return g }
ok(jsFuns.isAsmJSModule(f1), "f1 is an asm.js module");
ok(jsFuns.isAsmJSFunction(f1()), "f1.g is an asm.js function");

function f2(stdlib, foreign, buffer) {
    "use asm";
    var i32 = new stdlib.Int32Array(buffer);
    function main(n) {
        n = n|0;
        var i = 0, sum = 0;
        for (; (i|0) < (n|0); i=(i+1)|0)
            sum = (sum + (i32[(i<<2)>>2]|0))|0;
        return sum|0;
    }
    return main;
}
ok(jsFuns.isAsmJSModule(f2), "f2 is an asm.js module");
var i32 = new Int32Array(4096/4);
for (var i = 0; i < 100; i++)
    i32[i] = i;
var f2Main = f2(this, null, i32.buffer);
ok(f2Main, "f2.main is an asm.js function");
ok(f2Main(4) == 6, "f2.main(4)");
ok(f2Main(100) == 4950, "f2.main(100)");
ok(f2Main(5000) == 4950, "f2.main(5000)");

function f3(stdlib, foreign, buffer) {
    "use asm";
    var i32 = new stdlib.Int32Array(buffer);
    function main(n,o) {
        n = n|0;
        o = o|0;
        var i = 0, j = 0, sum = 0;
        for (i = 0; (i|0) < (n|0); i=(i+1)|0)
            for (j = 0; (j|0) < (o|0); j=(j+1)|0)
                sum = (sum + (i32[(j<<2)>>2]|0))|0;
        return sum|0;
    }
    return main;
}
var f3Main = f3(this, null, i32.buffer);
ok(f3Main, "f3.main is an asm.js function");
ok(f3Main(2000000, 1000) == ((4950*2000000)|0), "f3.main(2000000, 1000)");

var w = new Worker('http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_asmjs.js');
w.onmessage = function(e) {
    ok(e.data === "ok", "Worker asm.js tests");
    SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>