1 /* See license.txt for terms of usage */ 2 3 define([ 4 "firebug/lib/trace", 5 "firebug/lib/object", 6 "firebug/lib/domplate", 7 "firebug/chrome/reps", 8 "firebug/js/stackFrame", 9 "firebug/lib/events", 10 "firebug/lib/css", 11 "firebug/lib/dom", 12 "firebug/lib/url", 13 ], 14 function(FBTrace, Obj, Domplate, Reps, StackFrame, Events, Css, Dom, Url) { with (Domplate) { 15 16 // ********************************************************************************************* // 17 // Function Monitor 18 19 var FunctionMonitor = Obj.extend(Firebug.Module, 20 { 21 dispatchName: "functionMonitor", 22 23 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 24 // Module 25 26 initialize: function() 27 { 28 Firebug.Module.initialize.apply(this, arguments); 29 Firebug.connection.addListener(this); 30 }, 31 32 shutdown: function() 33 { 34 Firebug.connection.removeListener(this); 35 Firebug.Module.shutdown.apply(this, arguments); 36 }, 37 38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 39 // Firebug.Debugger listener 40 41 onMonitorScript: function(context, frame) 42 { 43 var stackTrace = StackFrame.buildStackTrace(frame); 44 Firebug.Console.log(new FunctionLog(frame, stackTrace), context); 45 }, 46 47 onFunctionCall: function(context, frame, depth, calling) 48 { 49 //var url = Url.normalizeURL(frame.script.fileName); 50 //var sourceFile = context.sourceFileMap[url]; 51 // Firebug.errorStackTrace = StackFrame.getCorrectedStackTrace(frame, context); 52 //var sourceFile = Firebug.SourceFile.getSourceFileByScript(context, frame.script); 53 if (Url.isSystemURL(Url.normalizeURL(frame.script.fileName))) 54 return; 55 56 // xxxHonza: traceCall and traceCallAll need to be fixed yet. 57 FBTrace.sysout("functionMonitor.onFunctionCall; ", sourceFile); 58 59 if (calling) 60 Firebug.Console.openGroup([frame, "depth:" + depth], context); 61 else 62 Firebug.Console.closeGroup(context); 63 }, 64 }); 65 66 // ********************************************************************************************* // 67 // Rep Object 68 69 function FunctionLog(frame, stackTrace) 70 { 71 this.frame = frame; 72 this.stackTrace = stackTrace; 73 } 74 75 // ********************************************************************************************* // 76 // Function Monitor Rep 77 78 var FunctionMonitorRep = domplate(Firebug.Rep, 79 { 80 className: "functionCall", 81 82 tag: 83 Reps.OBJECTBLOCK({$hasTwisty: "$object|hasStackTrace", _repObject: "$object", 84 onclick: "$onToggleStackTrace"}, 85 A({"class": "objectLink functionCallTitle a11yFocus", _repObject: "$object"}, 86 "$object|getCallName" 87 ), 88 SPAN("("), 89 SPAN({"class": "arguments"}, 90 FOR("arg", "$object|argIterator", 91 SPAN({"class": "argName"}, "$arg.name"), 92 SPAN("="), 93 TAG("$arg.tag", {object: "$arg.value"}), 94 SPAN({"class": "arrayComma"}, "$arg.delim") 95 ) 96 ), 97 SPAN(")"), 98 SPAN({"class": "objectLink-sourceLink objectLink a11yFocus", 99 _repObject: "$object|getSourceLink", 100 role: "link"}, 101 "$object|getSourceLinkTitle"), 102 DIV({"class": "stackTrace"}) 103 ), 104 105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 106 107 hasStackTrace: function(object) 108 { 109 return true; 110 }, 111 112 getTitle: function(object) 113 { 114 return object.frame.getFunctionName(); 115 }, 116 117 getCallName: function(object) 118 { 119 return this.getTitle(object); 120 }, 121 122 getSourceLink: function(object) 123 { 124 return Reps.StackFrame.getSourceLink(object.frame); 125 }, 126 127 getSourceLinkTitle: function(object) 128 { 129 return Reps.StackFrame.getSourceLinkTitle(object.frame); 130 }, 131 132 argIterator: function(object) 133 { 134 return Reps.StackFrame.argIterator(object.frame); 135 }, 136 137 onToggleStackTrace: function(event) 138 { 139 var target = event.originalTarget; 140 141 // Only clicking on the expand button or the function title actually expands 142 // the function call log. All other clicks keep default behavior 143 if (!(Css.hasClass(target, "objectBox-functionCall") || 144 Css.hasClass(target, "functionCallTitle"))) 145 { 146 return; 147 } 148 149 var objectBox = Dom.getAncestorByClass(target, "objectBox-functionCall"); 150 if (!objectBox) 151 return; 152 153 var traceBox = objectBox.getElementsByClassName("stackTrace").item(0); 154 Css.toggleClass(traceBox, "opened"); 155 156 if (Css.hasClass(traceBox, "opened")) 157 { 158 var functionCall = objectBox.repObject; 159 Reps.StackTrace.tag.append({object: functionCall.stackTrace}, traceBox); 160 } 161 else 162 { 163 Dom.clearNode(traceBox); 164 } 165 166 Events.cancelEvent(event); 167 }, 168 169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 170 171 supportsObject: function(object, type) 172 { 173 return object instanceof FunctionLog; 174 }, 175 176 getRealObject: function(object) 177 { 178 return object.frame; 179 }, 180 }); 181 182 // ********************************************************************************************* // 183 // Registration 184 185 Firebug.registerModule(FunctionMonitor); 186 Firebug.registerRep(FunctionMonitorRep); 187 188 return FunctionMonitor; 189 190 // ********************************************************************************************* // 191 }}); 192