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

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

mercurial