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