js/jsd/test/test-bug638178-execlines.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:dbf74901d099
1
2 var jsdIScript = SpecialPowers.Ci.jsdIScript;
3
4 function f1() {
5 var x;
6 }
7
8 function f2() {
9
10
11 var x; var y; x = 1;
12 }
13
14 function f3() {
15
16
17 var x;
18
19 var y; var y2; y = 1;
20 var z;
21
22 }
23
24 var jsdIFilter = SpecialPowers.Ci.jsdIFilter;
25
26 function testJSD(jsd) {
27 ok(jsd.isOn, "JSD needs to be running for this test.");
28
29 jsd.functionHook = ({
30 onCall: function(frame, type) {
31 //console.log("Got " + type);
32 console.log("Got " + frame.script.fileName);
33 }
34 });
35
36 console.log("Triggering functions");
37 f1();
38 f2();
39 f3();
40 console.log("Done with functions");
41
42 var linemap = {};
43 var firsts = {};
44 var rests = {};
45 var startlines = {};
46 jsd.enumerateScripts({
47 enumerateScript: function(script) {
48 if (/execlines\.js$/.test(script.fileName)) {
49 console.log("script: " + script.fileName + " " + script.functionName);
50 var execLines = script.getExecutableLines(jsdIScript.PCMAP_SOURCETEXT, 0, 10000);
51 console.log(execLines.toSource());
52 linemap[script.functionName] = execLines;
53 startlines[script.functionName] = script.baseLineNumber;
54
55 execLines = script.getExecutableLines(jsdIScript.PCMAP_SOURCETEXT, 0, 1);
56 firsts[script.functionName] = execLines;
57 execLines = script.getExecutableLines(jsdIScript.PCMAP_SOURCETEXT, execLines[0]+1, 10000);
58 rests[script.functionName] = execLines;
59 }
60 }
61 });
62
63 var checklines = function (funcname, linemap, rellines) {
64 var base = startlines[funcname];
65 var b = [];
66 for (var i = 0; i < rellines.length; ++i) {
67 b[i] = rellines[i] + base;
68 }
69 is(linemap[funcname].toSource(), b.toSource(), funcname + " lines");
70 };
71
72 checklines('f1', linemap, [ 1 ]);
73 checklines('f2', linemap, [ 3 ]);
74 checklines('f3', linemap, [ 3, 5, 6 ]);
75
76 checklines('f1', firsts, [ 1 ]);
77 checklines('f1', rests, []);
78 checklines('f3', firsts, [ 3 ]);
79 checklines('f3', rests, [ 5, 6 ]);
80
81 jsd.functionHook = null;
82
83 if (!jsdOnAtStart) {
84 // turn JSD off if it wasn't on when this test started
85 jsd.off();
86 ok(!jsd.isOn, "JSD shouldn't be running at the end of this test.");
87 }
88
89 SimpleTest.finish();
90 }
91
92 testJSD(jsd);

mercurial