dom/asmjscache/test/test_cachingMulti.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=944821
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>asm.js browser tests</title>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=944821">asm.js browser tests</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content" style="display: none"></div>
michael@0 16 <pre id="test"></pre>
michael@0 17
michael@0 18 <script>
michael@0 19 var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
michael@0 20 ok(jsFuns.isAsmJSCompilationAvailable(), "compilation is available");
michael@0 21
michael@0 22 // generate four slightly different big asm.js modules and compile them async
michael@0 23 // so that we can hit the asm.js cache.
michael@0 24
michael@0 25 var code = "function f() { 'use asm';\n";
michael@0 26 for (var i = 0; i < 5000; i++)
michael@0 27 code += "function g" + i + "() { return " + i + "}\n";
michael@0 28 ok(code.length > 100000, "code is long enough to definitely hit the cache");
michael@0 29
michael@0 30 const N = 4;
michael@0 31
michael@0 32 var codes = [];
michael@0 33 for (var i = 0; i < N; i++) {
michael@0 34 var code2 = code;
michael@0 35 code2 += "return g" + i + ";\n";
michael@0 36 code2 += "}\n";
michael@0 37 code2 += "ok(jsFuns.isAsmJSModule(f), 'f is an asm.js module')\n";
michael@0 38 code2 += "if (assertCacheHit) ok(jsFuns.isAsmJSModuleLoadedFromCache(f), 'cache hit');\n";
michael@0 39 code2 += "var gX = f();\n";
michael@0 40 code2 += "ok(jsFuns.isAsmJSFunction(gX), 'gX is an asm.js function')\n";
michael@0 41 code2 += "ok(gX() === " + i + ", 'gX returns the correct result')\n";
michael@0 42 code2 += "finishedEvalAsync();\n";
michael@0 43 codes.push(code2);
michael@0 44 }
michael@0 45
michael@0 46 function evalAsync(code) {
michael@0 47 var blob = new Blob([code], {type:"application/javascript"});
michael@0 48 var script = document.createElement('script');
michael@0 49 script.src = URL.createObjectURL(blob);
michael@0 50 document.body.appendChild(script);
michael@0 51 }
michael@0 52
michael@0 53 for (var i = 0; i < N; i++)
michael@0 54 evalAsync(codes[i]);
michael@0 55
michael@0 56 var finishedCount = 0;
michael@0 57 var assertCacheHit = false;
michael@0 58 function finishedEvalAsync() {
michael@0 59 finishedCount++;
michael@0 60
michael@0 61 if (finishedCount < 1 || finishedCount > 2*N) {
michael@0 62 throw "Huh?!";
michael@0 63 } else if (finishedCount == N) {
michael@0 64 assertCacheHit = true;
michael@0 65 for (var i = 0; i < N; i++)
michael@0 66 evalAsync(codes[i]);
michael@0 67 } else if (finishedCount == 2*N) {
michael@0 68 SimpleTest.finish();
michael@0 69 }
michael@0 70 }
michael@0 71
michael@0 72 SimpleTest.waitForExplicitFinish();
michael@0 73 </script>
michael@0 74
michael@0 75 </body>
michael@0 76 </html>
michael@0 77

mercurial