2013-11-18 13:49:53 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=929236
|
|
|
|
-->
|
|
|
|
<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=929236">asm.js browser tests</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none"></div>
|
|
|
|
<pre id="test"></pre>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
|
2014-01-20 16:00:18 -08:00
|
|
|
ok(jsFuns.isAsmJSCompilationAvailable(), "asm.js compilation is available");
|
2013-11-18 13:49:53 -08:00
|
|
|
|
|
|
|
// generate a big ol asm.js module and compile it async so that we can hit
|
|
|
|
// the asm.js cache.
|
|
|
|
|
|
|
|
var code = "function f() { 'use asm';\n";
|
2014-01-20 16:00:18 -08:00
|
|
|
for (var i = 0; i < 5000; i++)
|
2013-11-18 13:49:53 -08:00
|
|
|
code += "function g" + i + "() { return " + i + "}\n";
|
|
|
|
code += "return g42 }\n";
|
|
|
|
code += "ok(jsFuns.isAsmJSModule(f), 'f is an asm.js module')\n";
|
|
|
|
code += "var g42 = f();\n";
|
|
|
|
code += "ok(jsFuns.isAsmJSFunction(g42), 'g42 is an asm.js function')\n";
|
|
|
|
code += "ok(g42() === 42, 'g42 returns the correct result')\n";
|
2013-11-29 12:58:56 -08:00
|
|
|
code += "finishedEvalAsync(f);";
|
2014-01-20 16:00:18 -08:00
|
|
|
ok(code.length > 100000, "code is long enough to definitely hit the cache");
|
2013-11-18 13:49:53 -08:00
|
|
|
|
|
|
|
function evalAsync(code) {
|
|
|
|
var blob = new Blob([code], {type:"application/javascript"});
|
|
|
|
var script = document.createElement('script');
|
|
|
|
script.src = URL.createObjectURL(blob);
|
|
|
|
document.body.appendChild(script);
|
|
|
|
}
|
|
|
|
|
|
|
|
var state = 0;
|
2013-11-29 12:58:56 -08:00
|
|
|
function finishedEvalAsync(module) {
|
2013-11-18 13:49:53 -08:00
|
|
|
switch (state) {
|
|
|
|
case 0:
|
|
|
|
state++;
|
|
|
|
evalAsync(code);
|
|
|
|
break;
|
|
|
|
case 1:
|
2013-11-29 12:58:56 -08:00
|
|
|
ok(jsFuns.isAsmJSModuleLoadedFromCache(module), 'module loaded from cache');
|
2013-11-18 13:49:53 -08:00
|
|
|
SimpleTest.finish();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw "huh?";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
evalAsync(code);
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|