1 /* See license.txt for terms of usage */ 2 3 var _FirebugCommandLine = 4 { 5 initFirebugCommandLine: function() 6 { 7 // Define console functions. 8 var commands = ["$", "$$", "$x", "$n", "cd", "clear", "inspect", "keys", 9 "values", "debug", "undebug", "monitor", "unmonitor", "traceCalls", "untraceCalls", 10 "traceAll", "untraceAll", "monitorEvents", "unmonitorEvents", "profile", "profileEnd", "copy"]; 11 for (var i=0; i<commands.length; i++) 12 { 13 var command = commands[i]; 14 15 // If the method is already defined, don't override it. 16 if (window[command]) 17 continue; 18 19 this[command] = new Function( 20 "return window.console.notifyFirebug(arguments, '" + command + "', 'firebugExecuteCommand');"); 21 } 22 23 // Define console shortcuts 24 var consoleShortcuts = ["dir", "dirxml"]; 25 for (var i=0; i<consoleShortcuts.length; i++) 26 { 27 var command = consoleShortcuts[i]; 28 this[command] = new Function("return window.console." + command + ".apply(window.console, arguments)"); 29 } 30 31 // Define console variables. 32 var props = ["$0", "$1"]; 33 for (var j=0; j<props.length; j++) 34 { 35 var prop = props[j]; 36 if (window[prop]) 37 continue; 38 39 this.__defineGetter__(prop, new Function( 40 "return window.console.notifyFirebug(arguments, '" + prop + "', 'firebugExecuteCommand');")); 41 } 42 43 this.attachCommandLine(); 44 }, 45 46 attachCommandLine: function() 47 { 48 // DBG window.dump("attachCommandLine "+window.location+"\n"); 49 if (!window.console) 50 { 51 // DBG debugger; 52 window.loadFirebugConsole(); 53 } 54 var element = window.console.getFirebugElement(); 55 var self = this; 56 element.addEventListener("firebugCommandLine", function _firebugEvalEvent(event) 57 { 58 // DBG window.dump("attachCommandLine firebugCommandLine "+window.location+"\n"); 59 var element = event.target; 60 var expr = element.getAttribute("expr"); // see commandLine.js 61 self.evaluate(expr); 62 // DBG window.dump("attachCommandLine did evaluate on "+expr+"\n"); 63 }, true); 64 element.setAttribute("firebugCommandLineAttached", "true") 65 // DBG window.dump("Added listener for firebugCommandLine event "+window.location+"\n"); 66 }, 67 68 evaluate: function(expr) 69 { 70 try 71 { 72 var result = window.eval(expr); 73 if (typeof result != "undefined") 74 window.console.notifyFirebug([result], "evaluated", "firebugAppendConsole"); 75 } 76 catch(exc) 77 { 78 var result = exc; 79 result.source = expr; 80 window.console.notifyFirebug([result], "evaluateError", "firebugAppendConsole"); 81 } 82 }, 83 }; 84 85 (function() 86 { 87 try 88 { 89 // DBG window.dump("_FirebugCommandLine init console is "+window.console+" in "+window.location+"\n"); 90 _FirebugCommandLine.initFirebugCommandLine(); 91 } 92 catch(exc) 93 { 94 var wrappedException = { 95 cause: exc, 96 message: "_FirebugCommandLine init failed in "+window.location+" because "+exc, 97 toString: function() { return this.message; } 98 }; 99 throw wrappedException; 100 } 101 })(); 102