dom/asmjscache/test/file_slow.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 function f1() { "use asm"; function g() {} return g }
michael@0 2 if (this.jsFuns) {
michael@0 3 ok(jsFuns.isAsmJSModule(f1), "f1 is an asm.js module");
michael@0 4 ok(jsFuns.isAsmJSFunction(f1()), "f1.g is an asm.js function");
michael@0 5 }
michael@0 6
michael@0 7 function f2(stdlib, foreign, buffer) {
michael@0 8 "use asm";
michael@0 9 var i32 = new stdlib.Int32Array(buffer);
michael@0 10 function main(n) {
michael@0 11 n = n|0;
michael@0 12 var i = 0, sum = 0;
michael@0 13 for (; (i|0) < (n|0); i=(i+1)|0)
michael@0 14 sum = (sum + (i32[(i<<2)>>2]|0))|0;
michael@0 15 return sum|0;
michael@0 16 }
michael@0 17 return main;
michael@0 18 }
michael@0 19 if (this.jsFuns)
michael@0 20 ok(jsFuns.isAsmJSModule(f2), "f2 is an asm.js module");
michael@0 21 var i32 = new Int32Array(1024);
michael@0 22 for (var i = 0; i < i32.length; i++)
michael@0 23 i32[i] = i;
michael@0 24 var f2Main = f2(this, null, i32.buffer);
michael@0 25 if (this.jsFuns)
michael@0 26 ok(jsFuns.isAsmJSFunction(f2Main), "f2.main is an asm.js function");
michael@0 27 if (f2Main(4) !== 6)
michael@0 28 throw "f2Main(4)";
michael@0 29 if (f2Main(100) !== 4950)
michael@0 30 throw "f2.main(100)";
michael@0 31 var sum = (((i32.length - 1) * i32.length) / 2);
michael@0 32 if (f2Main(i32.length) !== sum)
michael@0 33 throw "f2.main(" + i32.length + ")";
michael@0 34 if (f2Main(i32.length + 100) !== sum)
michael@0 35 throw "f2.main(" + i32.length + ")";
michael@0 36
michael@0 37 function f3(stdlib, foreign, buffer) {
michael@0 38 "use asm";
michael@0 39 var done = foreign.done;
michael@0 40 var i32 = new stdlib.Int32Array(buffer);
michael@0 41 function main() {
michael@0 42 var i = 0, sum = 0;
michael@0 43 while (1) {
michael@0 44 for (i = 0; (i|0) < 1000; i=(i+1)|0)
michael@0 45 sum = (sum + i)|0;
michael@0 46 if (done(sum|0)|0)
michael@0 47 break;
michael@0 48 }
michael@0 49 return sum|0;
michael@0 50 }
michael@0 51 return main;
michael@0 52 }
michael@0 53 var begin;
michael@0 54 var lastSum;
michael@0 55 function done(sum) {
michael@0 56 if (sum !== ((lastSum + 499500)|0))
michael@0 57 throw "bad sum: " + sum + ", " + lastSum + ", " + ((lastSum + 499500)|0);
michael@0 58 lastSum = sum;
michael@0 59 return (Date.now() - begin) > 3000;
michael@0 60 }
michael@0 61 var f3Main = f3(this, {done:done}, i32.buffer);
michael@0 62 if (this.jsFuns)
michael@0 63 ok(jsFuns.isAsmJSFunction(f3Main), "f3.main is an asm.js function");
michael@0 64
michael@0 65 begin = Date.now();
michael@0 66 lastSum = 0;
michael@0 67 if (f3Main() !== lastSum)
michael@0 68 throw "f3.main()";
michael@0 69
michael@0 70 if (!this.jsFuns)
michael@0 71 postMessage("ok");

mercurial