1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/asmjscache/test/test_cachingMulti.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=944821 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=944821">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(), "compilation is available"); 1.24 + 1.25 + // generate four slightly different big asm.js modules and compile them async 1.26 + // so that we can hit 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 + ok(code.length > 100000, "code is long enough to definitely hit the cache"); 1.32 + 1.33 + const N = 4; 1.34 + 1.35 + var codes = []; 1.36 + for (var i = 0; i < N; i++) { 1.37 + var code2 = code; 1.38 + code2 += "return g" + i + ";\n"; 1.39 + code2 += "}\n"; 1.40 + code2 += "ok(jsFuns.isAsmJSModule(f), 'f is an asm.js module')\n"; 1.41 + code2 += "if (assertCacheHit) ok(jsFuns.isAsmJSModuleLoadedFromCache(f), 'cache hit');\n"; 1.42 + code2 += "var gX = f();\n"; 1.43 + code2 += "ok(jsFuns.isAsmJSFunction(gX), 'gX is an asm.js function')\n"; 1.44 + code2 += "ok(gX() === " + i + ", 'gX returns the correct result')\n"; 1.45 + code2 += "finishedEvalAsync();\n"; 1.46 + codes.push(code2); 1.47 + } 1.48 + 1.49 + function evalAsync(code) { 1.50 + var blob = new Blob([code], {type:"application/javascript"}); 1.51 + var script = document.createElement('script'); 1.52 + script.src = URL.createObjectURL(blob); 1.53 + document.body.appendChild(script); 1.54 + } 1.55 + 1.56 + for (var i = 0; i < N; i++) 1.57 + evalAsync(codes[i]); 1.58 + 1.59 + var finishedCount = 0; 1.60 + var assertCacheHit = false; 1.61 + function finishedEvalAsync() { 1.62 + finishedCount++; 1.63 + 1.64 + if (finishedCount < 1 || finishedCount > 2*N) { 1.65 + throw "Huh?!"; 1.66 + } else if (finishedCount == N) { 1.67 + assertCacheHit = true; 1.68 + for (var i = 0; i < N; i++) 1.69 + evalAsync(codes[i]); 1.70 + } else if (finishedCount == 2*N) { 1.71 + SimpleTest.finish(); 1.72 + } 1.73 + } 1.74 + 1.75 + SimpleTest.waitForExplicitFinish(); 1.76 + </script> 1.77 + 1.78 +</body> 1.79 +</html> 1.80 +