michael@0: // |jit-test| debug michael@0: // We get the same Debugger.Script object instance each time we ask. michael@0: michael@0: var global = newGlobal(); michael@0: global.eval('function f() { debugger; }'); michael@0: global.eval('function g() { debugger; }'); michael@0: michael@0: var debug = new Debugger(global); michael@0: michael@0: function evalAndNoteScripts(prog) { michael@0: var scripts = {}; michael@0: debug.onDebuggerStatement = function(frame) { michael@0: if (frame.type == "call") michael@0: assertEq(frame.script, frame.callee.script); michael@0: scripts.frame = frame.script; michael@0: if (frame.arguments[0]) michael@0: scripts.argument = frame.arguments[0].script; michael@0: }; michael@0: global.eval(prog); michael@0: return scripts; michael@0: } michael@0: michael@0: // If we create a frame for a function and pass it as a value, those should michael@0: // both yield the same Debugger.Script instance. michael@0: var scripts = evalAndNoteScripts('f(f)'); michael@0: assertEq(scripts.frame, scripts.argument); michael@0: var fScript = scripts.argument; michael@0: michael@0: // If we call a second time, we should still get the same instance. michael@0: scripts = evalAndNoteScripts('f(f)'); michael@0: assertEq(scripts.frame, fScript); michael@0: assertEq(scripts.argument, fScript); michael@0: michael@0: // If we call with a different argument, we should get a different Debugger.Script. michael@0: scripts = evalAndNoteScripts('f(g)'); michael@0: assertEq(scripts.frame !== scripts.argument, true); michael@0: assertEq(scripts.frame, fScript); michael@0: var gScript = scripts.argument; michael@0: michael@0: // See if we can get g via the frame. michael@0: scripts = evalAndNoteScripts('g(f)'); michael@0: assertEq(scripts.frame !== scripts.argument, true); michael@0: assertEq(scripts.frame, gScript); michael@0: assertEq(scripts.argument, fScript); michael@0: michael@0: // Different closures made from the same 'function' expression should yield michael@0: // the same script. michael@0: global.eval('function gen1(x) { return function clo(y) { return x+y; }; }'); michael@0: global.eval('var clo1 = gen1(42);'); michael@0: global.eval('var clo2 = gen1("smoot");'); michael@0: var scripts1 = evalAndNoteScripts('f(clo1)'); michael@0: var scripts2 = evalAndNoteScripts('f(clo2)'); michael@0: assertEq(scripts1.argument, scripts2.argument); michael@0: michael@0: // Different closures made from the same 'function' declaration should yield michael@0: // the same script. michael@0: global.eval('function gen2(x) { function clo(y) { return x+y; }; return clo; }'); michael@0: global.eval('var clo1 = gen2(42);'); michael@0: global.eval('var clo2 = gen2("smoot");'); michael@0: var scripts1 = evalAndNoteScripts('f(clo1)'); michael@0: var scripts2 = evalAndNoteScripts('f(clo2)'); michael@0: assertEq(scripts1.argument, scripts2.argument); michael@0: michael@0: // Different closures made from the same 'function' statement should yield michael@0: // the same script. michael@0: global.eval('function gen3(x) { if (true) { function clo(y) { return x+y; }; return clo; } }'); michael@0: global.eval('var clo1 = gen3(42);'); michael@0: global.eval('var clo2 = gen3("smoot");'); michael@0: var scripts1 = evalAndNoteScripts('f(clo1)'); michael@0: var scripts2 = evalAndNoteScripts('f(clo2)'); michael@0: assertEq(scripts1.argument, scripts2.argument);