js/src/jit-test/tests/asm.js/testStackWalking.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 load(libdir + "asserts.js");
michael@0 3
michael@0 4 function matchStack(stackString, stackArray)
michael@0 5 {
michael@0 6 var match = 0;
michael@0 7 for (name of stackArray) {
michael@0 8 match = stackString.indexOf(name, match);
michael@0 9 if (match === -1)
michael@0 10 throw name + " not found in the stack " + stack;
michael@0 11 }
michael@0 12 }
michael@0 13
michael@0 14 var stack;
michael@0 15 function dumpStack()
michael@0 16 {
michael@0 17 stack = new Error().stack
michael@0 18 }
michael@0 19
michael@0 20 setCachingEnabled(true);
michael@0 21
michael@0 22 var callFFI = asmCompile('global', 'ffis', USE_ASM + "var ffi=ffis.ffi; function f() { return ffi()|0 } return f");
michael@0 23
michael@0 24 var f = asmLink(callFFI, null, {ffi:dumpStack});
michael@0 25 for (var i = 0; i < 5000; i++) {
michael@0 26 stack = null;
michael@0 27 f();
michael@0 28 matchStack(stack, ['dumpStack', 'f']);
michael@0 29 }
michael@0 30
michael@0 31 if (isAsmJSCompilationAvailable() && isCachingEnabled()) {
michael@0 32 var callFFI = asmCompile('global', 'ffis', USE_ASM + "var ffi=ffis.ffi; function f() { return ffi()|0 } return f");
michael@0 33 assertEq(isAsmJSModuleLoadedFromCache(callFFI), true);
michael@0 34 stack = null;
michael@0 35 f();
michael@0 36 matchStack(stack, ['dumpStack', 'f']);
michael@0 37 }
michael@0 38
michael@0 39 var f1 = asmLink(callFFI, null, {ffi:dumpStack});
michael@0 40 var f2 = asmLink(callFFI, null, {ffi:function middle() { f1() }});
michael@0 41 stack = null;
michael@0 42 (function outer() { f2() })();
michael@0 43 matchStack(stack, ["dumpStack", "f", "middle", "f"]);
michael@0 44
michael@0 45 function returnStackDumper() { return { valueOf:function() { stack = new Error().stack } } }
michael@0 46 var f = asmLink(callFFI, null, {ffi:returnStackDumper});
michael@0 47 for (var i = 0; i < 5000; i++) {
michael@0 48 stack = null;
michael@0 49 f();
michael@0 50 matchStack(stack, ['valueOf', 'f']);
michael@0 51 }
michael@0 52
michael@0 53 var caught = false;
michael@0 54 try {
michael@0 55 stack = null;
michael@0 56 asmLink(asmCompile(USE_ASM + "function asmRec() { asmRec() } return asmRec"))();
michael@0 57 } catch (e) {
michael@0 58 caught = true;
michael@0 59 matchStack(e.stack, ['asmRec', 'asmRec', 'asmRec', 'asmRec']);
michael@0 60 }
michael@0 61 assertEq(caught, true);
michael@0 62
michael@0 63 var caught = false;
michael@0 64 try {
michael@0 65 callFFI(null, {ffi:Object.preventExtensions})();
michael@0 66 } catch (e) {
michael@0 67 caught = true;
michael@0 68 }
michael@0 69 assertEq(caught, true);
michael@0 70
michael@0 71 asmLink(callFFI, null, {ffi:eval})();
michael@0 72 asmLink(callFFI, null, {ffi:Function})();
michael@0 73 asmLink(callFFI, null, {ffi:Error})();
michael@0 74
michael@0 75 var manyCalls = asmCompile('global', 'ffis',
michael@0 76 USE_ASM +
michael@0 77 "var ffi=ffis.ffi;\
michael@0 78 function f1(a,b,c,d,e,f,g,h,i,j,k) { \
michael@0 79 a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;j=j|0;k=k|0; \
michael@0 80 ffi(); \
michael@0 81 return (a+b+c+d+e+f+g+h+i+j+k)|0; \
michael@0 82 } \
michael@0 83 function f2() { \
michael@0 84 return f1(1,2,3,4,5,6,7,8,f1(1,2,3,4,5,6,7,8,9,10,11)|0,10,11)|0; \
michael@0 85 } \
michael@0 86 function f3() { return 13 } \
michael@0 87 function f4(i) { \
michael@0 88 i=i|0; \
michael@0 89 return TBL[i&3]()|0; \
michael@0 90 } \
michael@0 91 var TBL=[f3, f3, f2, f3]; \
michael@0 92 return f4;");
michael@0 93 stack = null;
michael@0 94 assertEq(asmLink(manyCalls, null, {ffi:dumpStack})(2), 123);
michael@0 95 matchStack(stack, ['dumpStack', 'f1', 'f2', 'f4']);

mercurial