Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // |jit-test| debug |
michael@0 | 2 | // We get the same Debugger.Script object instance each time we ask. |
michael@0 | 3 | |
michael@0 | 4 | var global = newGlobal(); |
michael@0 | 5 | global.eval('function f() { debugger; }'); |
michael@0 | 6 | global.eval('function g() { debugger; }'); |
michael@0 | 7 | |
michael@0 | 8 | var debug = new Debugger(global); |
michael@0 | 9 | |
michael@0 | 10 | function evalAndNoteScripts(prog) { |
michael@0 | 11 | var scripts = {}; |
michael@0 | 12 | debug.onDebuggerStatement = function(frame) { |
michael@0 | 13 | if (frame.type == "call") |
michael@0 | 14 | assertEq(frame.script, frame.callee.script); |
michael@0 | 15 | scripts.frame = frame.script; |
michael@0 | 16 | if (frame.arguments[0]) |
michael@0 | 17 | scripts.argument = frame.arguments[0].script; |
michael@0 | 18 | }; |
michael@0 | 19 | global.eval(prog); |
michael@0 | 20 | return scripts; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | // If we create a frame for a function and pass it as a value, those should |
michael@0 | 24 | // both yield the same Debugger.Script instance. |
michael@0 | 25 | var scripts = evalAndNoteScripts('f(f)'); |
michael@0 | 26 | assertEq(scripts.frame, scripts.argument); |
michael@0 | 27 | var fScript = scripts.argument; |
michael@0 | 28 | |
michael@0 | 29 | // If we call a second time, we should still get the same instance. |
michael@0 | 30 | scripts = evalAndNoteScripts('f(f)'); |
michael@0 | 31 | assertEq(scripts.frame, fScript); |
michael@0 | 32 | assertEq(scripts.argument, fScript); |
michael@0 | 33 | |
michael@0 | 34 | // If we call with a different argument, we should get a different Debugger.Script. |
michael@0 | 35 | scripts = evalAndNoteScripts('f(g)'); |
michael@0 | 36 | assertEq(scripts.frame !== scripts.argument, true); |
michael@0 | 37 | assertEq(scripts.frame, fScript); |
michael@0 | 38 | var gScript = scripts.argument; |
michael@0 | 39 | |
michael@0 | 40 | // See if we can get g via the frame. |
michael@0 | 41 | scripts = evalAndNoteScripts('g(f)'); |
michael@0 | 42 | assertEq(scripts.frame !== scripts.argument, true); |
michael@0 | 43 | assertEq(scripts.frame, gScript); |
michael@0 | 44 | assertEq(scripts.argument, fScript); |
michael@0 | 45 | |
michael@0 | 46 | // Different closures made from the same 'function' expression should yield |
michael@0 | 47 | // the same script. |
michael@0 | 48 | global.eval('function gen1(x) { return function clo(y) { return x+y; }; }'); |
michael@0 | 49 | global.eval('var clo1 = gen1(42);'); |
michael@0 | 50 | global.eval('var clo2 = gen1("smoot");'); |
michael@0 | 51 | var scripts1 = evalAndNoteScripts('f(clo1)'); |
michael@0 | 52 | var scripts2 = evalAndNoteScripts('f(clo2)'); |
michael@0 | 53 | assertEq(scripts1.argument, scripts2.argument); |
michael@0 | 54 | |
michael@0 | 55 | // Different closures made from the same 'function' declaration should yield |
michael@0 | 56 | // the same script. |
michael@0 | 57 | global.eval('function gen2(x) { function clo(y) { return x+y; }; return clo; }'); |
michael@0 | 58 | global.eval('var clo1 = gen2(42);'); |
michael@0 | 59 | global.eval('var clo2 = gen2("smoot");'); |
michael@0 | 60 | var scripts1 = evalAndNoteScripts('f(clo1)'); |
michael@0 | 61 | var scripts2 = evalAndNoteScripts('f(clo2)'); |
michael@0 | 62 | assertEq(scripts1.argument, scripts2.argument); |
michael@0 | 63 | |
michael@0 | 64 | // Different closures made from the same 'function' statement should yield |
michael@0 | 65 | // the same script. |
michael@0 | 66 | global.eval('function gen3(x) { if (true) { function clo(y) { return x+y; }; return clo; } }'); |
michael@0 | 67 | global.eval('var clo1 = gen3(42);'); |
michael@0 | 68 | global.eval('var clo2 = gen3("smoot");'); |
michael@0 | 69 | var scripts1 = evalAndNoteScripts('f(clo1)'); |
michael@0 | 70 | var scripts2 = evalAndNoteScripts('f(clo2)'); |
michael@0 | 71 | assertEq(scripts1.argument, scripts2.argument); |