1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/debug/Script-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,71 @@ 1.4 +// |jit-test| debug 1.5 +// We get the same Debugger.Script object instance each time we ask. 1.6 + 1.7 +var global = newGlobal(); 1.8 +global.eval('function f() { debugger; }'); 1.9 +global.eval('function g() { debugger; }'); 1.10 + 1.11 +var debug = new Debugger(global); 1.12 + 1.13 +function evalAndNoteScripts(prog) { 1.14 + var scripts = {}; 1.15 + debug.onDebuggerStatement = function(frame) { 1.16 + if (frame.type == "call") 1.17 + assertEq(frame.script, frame.callee.script); 1.18 + scripts.frame = frame.script; 1.19 + if (frame.arguments[0]) 1.20 + scripts.argument = frame.arguments[0].script; 1.21 + }; 1.22 + global.eval(prog); 1.23 + return scripts; 1.24 +} 1.25 + 1.26 +// If we create a frame for a function and pass it as a value, those should 1.27 +// both yield the same Debugger.Script instance. 1.28 +var scripts = evalAndNoteScripts('f(f)'); 1.29 +assertEq(scripts.frame, scripts.argument); 1.30 +var fScript = scripts.argument; 1.31 + 1.32 +// If we call a second time, we should still get the same instance. 1.33 +scripts = evalAndNoteScripts('f(f)'); 1.34 +assertEq(scripts.frame, fScript); 1.35 +assertEq(scripts.argument, fScript); 1.36 + 1.37 +// If we call with a different argument, we should get a different Debugger.Script. 1.38 +scripts = evalAndNoteScripts('f(g)'); 1.39 +assertEq(scripts.frame !== scripts.argument, true); 1.40 +assertEq(scripts.frame, fScript); 1.41 +var gScript = scripts.argument; 1.42 + 1.43 +// See if we can get g via the frame. 1.44 +scripts = evalAndNoteScripts('g(f)'); 1.45 +assertEq(scripts.frame !== scripts.argument, true); 1.46 +assertEq(scripts.frame, gScript); 1.47 +assertEq(scripts.argument, fScript); 1.48 + 1.49 +// Different closures made from the same 'function' expression should yield 1.50 +// the same script. 1.51 +global.eval('function gen1(x) { return function clo(y) { return x+y; }; }'); 1.52 +global.eval('var clo1 = gen1(42);'); 1.53 +global.eval('var clo2 = gen1("smoot");'); 1.54 +var scripts1 = evalAndNoteScripts('f(clo1)'); 1.55 +var scripts2 = evalAndNoteScripts('f(clo2)'); 1.56 +assertEq(scripts1.argument, scripts2.argument); 1.57 + 1.58 +// Different closures made from the same 'function' declaration should yield 1.59 +// the same script. 1.60 +global.eval('function gen2(x) { function clo(y) { return x+y; }; return clo; }'); 1.61 +global.eval('var clo1 = gen2(42);'); 1.62 +global.eval('var clo2 = gen2("smoot");'); 1.63 +var scripts1 = evalAndNoteScripts('f(clo1)'); 1.64 +var scripts2 = evalAndNoteScripts('f(clo2)'); 1.65 +assertEq(scripts1.argument, scripts2.argument); 1.66 + 1.67 +// Different closures made from the same 'function' statement should yield 1.68 +// the same script. 1.69 +global.eval('function gen3(x) { if (true) { function clo(y) { return x+y; }; return clo; } }'); 1.70 +global.eval('var clo1 = gen3(42);'); 1.71 +global.eval('var clo2 = gen3("smoot");'); 1.72 +var scripts1 = evalAndNoteScripts('f(clo1)'); 1.73 +var scripts2 = evalAndNoteScripts('f(clo2)'); 1.74 +assertEq(scripts1.argument, scripts2.argument);