js/src/jit-test/tests/asm.js/testCloning.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 load(libdir + "asm.js");
michael@0 2
michael@0 3 var code = asmCompile(USE_ASM + "function g() { return 42 } return g");
michael@0 4 assertEq(asmLink(code)(), 42);
michael@0 5 assertEq(asmLink(code)(), 42);
michael@0 6
michael@0 7 var code = asmCompile('glob', 'ffis', 'buf', USE_ASM + 'var i32=new glob.Int32Array(buf); function g() { return i32[0]|0 } return g');
michael@0 8 var i32_1 = new Int32Array(4096);
michael@0 9 i32_1[0] = 42;
michael@0 10 var i32_2 = new Int32Array(4096);
michael@0 11 i32_2[0] = 13;
michael@0 12 assertEq(asmLink(code, this, null, i32_1.buffer)(), 42);
michael@0 13 assertEq(asmLink(code, this, null, i32_2.buffer)(), 13);
michael@0 14 var i32_3 = new Int32Array(4097);
michael@0 15 assertAsmLinkFail(code, this, null, i32_3.buffer);
michael@0 16
michael@0 17 var code = asmCompile('glob', 'ffis', USE_ASM + 'var ffi=ffis.ffi; function g(n) { n=n|0; var i=0; for(; (i|0)<(n|0); i=(i+1)|0) ffi() } return g');
michael@0 18 var calls1 = 0, calls2 = 0;
michael@0 19 function ffi1() { calls1++ }
michael@0 20 function ffi2() { calls2++ }
michael@0 21 asmLink(code, null, {ffi:ffi1})(100000);
michael@0 22 assertEq(calls1, 100000);
michael@0 23 assertEq(calls2, 0);
michael@0 24 calls1 = 0;
michael@0 25 asmLink(code, null, {ffi:ffi2})(50000);
michael@0 26 assertEq(calls1, 0);
michael@0 27 assertEq(calls2, 50000);
michael@0 28
michael@0 29 var code = asmCompile(USE_ASM + 'var g = 0; function h() { g=(g+1)|0; return g|0 } return h');
michael@0 30 var h1 = code();
michael@0 31 assertEq(h1(), 1);
michael@0 32 assertEq(h1(), 2);
michael@0 33 var h2 = code();
michael@0 34 assertEq(h2(), 1);
michael@0 35 assertEq(h1(), 3);
michael@0 36 assertEq(h2(), 2);
michael@0 37 assertEq(h1(), 4);
michael@0 38
michael@0 39 var code = asmCompile(USE_ASM + "return {}");
michael@0 40 var h1 = code();
michael@0 41 var h2 = code();
michael@0 42 assertEq(h1 === h2, false);
michael@0 43 assertEq(Object.keys(h1).length, 0);
michael@0 44 assertEq(Object.keys(h2).length, 0);

mercurial