michael@0: michael@0: var jsdIScript = SpecialPowers.Ci.jsdIScript; michael@0: michael@0: function f1() { michael@0: var x; michael@0: } michael@0: michael@0: function f2() { michael@0: michael@0: michael@0: var x; var y; x = 1; michael@0: } michael@0: michael@0: function f3() { michael@0: michael@0: michael@0: var x; michael@0: michael@0: var y; var y2; y = 1; michael@0: var z; michael@0: michael@0: } michael@0: michael@0: var jsdIFilter = SpecialPowers.Ci.jsdIFilter; michael@0: michael@0: function testJSD(jsd) { michael@0: ok(jsd.isOn, "JSD needs to be running for this test."); michael@0: michael@0: jsd.functionHook = ({ michael@0: onCall: function(frame, type) { michael@0: //console.log("Got " + type); michael@0: console.log("Got " + frame.script.fileName); michael@0: } michael@0: }); michael@0: michael@0: console.log("Triggering functions"); michael@0: f1(); michael@0: f2(); michael@0: f3(); michael@0: console.log("Done with functions"); michael@0: michael@0: var linemap = {}; michael@0: var firsts = {}; michael@0: var rests = {}; michael@0: var startlines = {}; michael@0: jsd.enumerateScripts({ michael@0: enumerateScript: function(script) { michael@0: if (/execlines\.js$/.test(script.fileName)) { michael@0: console.log("script: " + script.fileName + " " + script.functionName); michael@0: var execLines = script.getExecutableLines(jsdIScript.PCMAP_SOURCETEXT, 0, 10000); michael@0: console.log(execLines.toSource()); michael@0: linemap[script.functionName] = execLines; michael@0: startlines[script.functionName] = script.baseLineNumber; michael@0: michael@0: execLines = script.getExecutableLines(jsdIScript.PCMAP_SOURCETEXT, 0, 1); michael@0: firsts[script.functionName] = execLines; michael@0: execLines = script.getExecutableLines(jsdIScript.PCMAP_SOURCETEXT, execLines[0]+1, 10000); michael@0: rests[script.functionName] = execLines; michael@0: } michael@0: } michael@0: }); michael@0: michael@0: var checklines = function (funcname, linemap, rellines) { michael@0: var base = startlines[funcname]; michael@0: var b = []; michael@0: for (var i = 0; i < rellines.length; ++i) { michael@0: b[i] = rellines[i] + base; michael@0: } michael@0: is(linemap[funcname].toSource(), b.toSource(), funcname + " lines"); michael@0: }; michael@0: michael@0: checklines('f1', linemap, [ 1 ]); michael@0: checklines('f2', linemap, [ 3 ]); michael@0: checklines('f3', linemap, [ 3, 5, 6 ]); michael@0: michael@0: checklines('f1', firsts, [ 1 ]); michael@0: checklines('f1', rests, []); michael@0: checklines('f3', firsts, [ 3 ]); michael@0: checklines('f3', rests, [ 5, 6 ]); michael@0: michael@0: jsd.functionHook = null; michael@0: michael@0: if (!jsdOnAtStart) { michael@0: // turn JSD off if it wasn't on when this test started michael@0: jsd.off(); michael@0: ok(!jsd.isOn, "JSD shouldn't be running at the end of this test."); michael@0: } michael@0: michael@0: SimpleTest.finish(); michael@0: } michael@0: michael@0: testJSD(jsd);