dom/asmjscache/test/test_workers.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:7acbd975b0eb
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=941830
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=941830">asm.js browser tests</a>
14 <p id="display"></p>
15 <div id="content" style="display: none"></div>
16 <pre id="test"></pre>
17
18 <script>
19 var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
20 ok(jsFuns.isAsmJSCompilationAvailable());
21
22 var asmjsCode = "function f() { 'use asm';";
23 for (var i = 0; i < 5000; i++)
24 asmjsCode += "function g" + i + "() { return " + i + "}";
25 asmjsCode += "return g42 }";
26 ok(asmjsCode.length > 100000, "code is long enough to definitely hit the cache");
27
28 var workerCode = asmjsCode;
29 workerCode += "if (f()() !== 42) postMessage('fail'); else postMessage('ok');";
30 workerCode = 'var code = "' + workerCode + '"; eval(code); eval(code)';
31 var workerBlob = new Blob([workerCode], {type:"application/javascript"});
32
33 var mainCode = asmjsCode;
34 mainCode += "ok(jsFuns.isAsmJSModuleLoadedFromCache(f), 'f is a cache hit')\n";
35 mainCode += "var g42 = f();\n";
36 mainCode += "ok(jsFuns.isAsmJSFunction(g42), 'g42 is an asm.js function');\n";
37 mainCode += "ok(g42() === 42, 'g42 returns the correct result');\n";
38 mainCode += "SimpleTest.finish();\n";
39 var mainBlob = new Blob([mainCode], {type:"application/javascript"});
40
41 var w = new Worker(URL.createObjectURL(workerBlob));
42
43 var received = 0;
44 w.onmessage = function(e) {
45 switch (received) {
46 case 0:
47 ok(e.data === "ok", "Received first message");
48 received = 1;
49 break;
50 case 1:
51 ok(e.data === "ok", "Received second message");
52 received = 2;
53
54 var script = document.createElement('script');
55 script.src = URL.createObjectURL(mainBlob);
56 document.body.appendChild(script);
57 break;
58 default:
59 throw "Huh?";
60 }
61 }
62
63 SimpleTest.waitForExplicitFinish();
64 </script>
65
66 </body>
67 </html>

mercurial