dom/asmjscache/test/test_cachingBasic.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=929236
     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=929236">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(), "asm.js compilation is available");
    22   // generate a big ol asm.js module and compile it async so that we can hit
    23   // 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   code += "return g42 }\n";
    29   code += "ok(jsFuns.isAsmJSModule(f), 'f is an asm.js module')\n";
    30   code += "var g42 = f();\n";
    31   code += "ok(jsFuns.isAsmJSFunction(g42), 'g42 is an asm.js function')\n";
    32   code += "ok(g42() === 42, 'g42 returns the correct result')\n";
    33   code += "finishedEvalAsync(f);";
    34   ok(code.length > 100000, "code is long enough to definitely hit the cache");
    36   function evalAsync(code) {
    37     var blob = new Blob([code], {type:"application/javascript"});
    38     var script = document.createElement('script');
    39     script.src = URL.createObjectURL(blob);
    40     document.body.appendChild(script);
    41   }
    43   var state = 0;
    44   function finishedEvalAsync(module) {
    45     switch (state) {
    46       case 0:
    47         state++;
    48         evalAsync(code);
    49         break;
    50       case 1:
    51         ok(jsFuns.isAsmJSModuleLoadedFromCache(module), 'module loaded from cache');
    52         SimpleTest.finish();
    53         break;
    54       default:
    55         throw "huh?";
    56     }
    57   }
    59   SimpleTest.waitForExplicitFinish();
    60   evalAsync(code);
    61   </script>
    63 </body>
    64 </html>

mercurial