1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/asmjscache/test/test_cachingBasic.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=929236 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>asm.js browser tests</title> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 + <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=929236">asm.js browser tests</a> 1.17 + <p id="display"></p> 1.18 + <div id="content" style="display: none"></div> 1.19 + <pre id="test"></pre> 1.20 + 1.21 + <script> 1.22 + var jsFuns = SpecialPowers.Cu.getJSTestingFunctions(); 1.23 + ok(jsFuns.isAsmJSCompilationAvailable(), "asm.js compilation is available"); 1.24 + 1.25 + // generate a big ol asm.js module and compile it async so that we can hit 1.26 + // the asm.js cache. 1.27 + 1.28 + var code = "function f() { 'use asm';\n"; 1.29 + for (var i = 0; i < 5000; i++) 1.30 + code += "function g" + i + "() { return " + i + "}\n"; 1.31 + code += "return g42 }\n"; 1.32 + code += "ok(jsFuns.isAsmJSModule(f), 'f is an asm.js module')\n"; 1.33 + code += "var g42 = f();\n"; 1.34 + code += "ok(jsFuns.isAsmJSFunction(g42), 'g42 is an asm.js function')\n"; 1.35 + code += "ok(g42() === 42, 'g42 returns the correct result')\n"; 1.36 + code += "finishedEvalAsync(f);"; 1.37 + ok(code.length > 100000, "code is long enough to definitely hit the cache"); 1.38 + 1.39 + function evalAsync(code) { 1.40 + var blob = new Blob([code], {type:"application/javascript"}); 1.41 + var script = document.createElement('script'); 1.42 + script.src = URL.createObjectURL(blob); 1.43 + document.body.appendChild(script); 1.44 + } 1.45 + 1.46 + var state = 0; 1.47 + function finishedEvalAsync(module) { 1.48 + switch (state) { 1.49 + case 0: 1.50 + state++; 1.51 + evalAsync(code); 1.52 + break; 1.53 + case 1: 1.54 + ok(jsFuns.isAsmJSModuleLoadedFromCache(module), 'module loaded from cache'); 1.55 + SimpleTest.finish(); 1.56 + break; 1.57 + default: 1.58 + throw "huh?"; 1.59 + } 1.60 + } 1.61 + 1.62 + SimpleTest.waitForExplicitFinish(); 1.63 + evalAsync(code); 1.64 + </script> 1.65 + 1.66 +</body> 1.67 +</html>