- not built -
promote console.display() to display() add displayCommands(), evalInDebuggerScope(), evalInTargetScope(), fillInToolTip() [copied from chatzilla], formatEvalException() [refactored from venkman-handlers.js] set window._content for drag-and-drop foo call displayCommands() on startup. add "venkman-link" to CSS class in htmlVA() for the case where the caller is providing custom attributes that do not include "class" git-svn-id: svn://10.0.0.236/trunk@92973 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
f3039533ba
commit
c76f201832
@ -49,12 +49,183 @@ var console = new Object();
|
||||
|
||||
/* |this|less functions */
|
||||
|
||||
function display(message, msgtype)
|
||||
{
|
||||
if (typeof message == "undefined")
|
||||
throw BadMojo(ERR_REQUIRED_PARAM, "message");
|
||||
|
||||
if (typeof message != "string" && typeof message != "object")
|
||||
throw BadMojo(ERR_INVALID_PARAM, "message");
|
||||
|
||||
if (typeof msgtype == "undefined")
|
||||
msgtype = MT_INFO;
|
||||
|
||||
function setAttribs (obj, c, attrs)
|
||||
{
|
||||
for (var a in attrs)
|
||||
obj.setAttribute (a, attrs[a]);
|
||||
obj.setAttribute("class", c);
|
||||
obj.setAttribute("msg-type", msgtype);
|
||||
}
|
||||
|
||||
function stringToMsg (message)
|
||||
{
|
||||
var ary = message.split("\n");
|
||||
var span = htmlSpan();
|
||||
|
||||
for (var l in ary)
|
||||
{
|
||||
var wordParts =
|
||||
splitLongWord (ary[l], console.prefs["output.wordbreak.length"]);
|
||||
for (var i in wordParts)
|
||||
{
|
||||
span.appendChild (htmlText(wordParts[i]));
|
||||
span.appendChild (htmlImg());
|
||||
}
|
||||
|
||||
span.appendChild (htmlBR());
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
var msgRow = htmlTR("msg");
|
||||
setAttribs(msgRow, "msg");
|
||||
|
||||
var msgData = htmlTD();
|
||||
setAttribs(msgData, "msg-data");
|
||||
if (typeof message == "string")
|
||||
msgData.appendChild(stringToMsg(message));
|
||||
else
|
||||
msgData.appendChild(message);
|
||||
|
||||
msgRow.appendChild(msgData);
|
||||
|
||||
console._outputElement.appendChild(msgRow);
|
||||
console.scrollDown();
|
||||
}
|
||||
|
||||
function displayCommands (pattern)
|
||||
{
|
||||
display (MSG_TIP_HELP);
|
||||
|
||||
if (pattern)
|
||||
display (getMsg(MSN_CMDMATCH,
|
||||
[pattern, "[" +
|
||||
console._commands.listNames(pattern).join(", ") + "]"]));
|
||||
else
|
||||
display (getMsg(MSN_CMDMATCH_ALL,
|
||||
"[" + console._commands.listNames().join(", ") + "]"));
|
||||
}
|
||||
|
||||
function evalInDebuggerScope (script)
|
||||
{
|
||||
try
|
||||
{
|
||||
display (script, "EVAL-IN");
|
||||
var rv = String(console.doEval (script));
|
||||
if (typeof rv != "undefined")
|
||||
display (rv, "EVAL-OUT");
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
display (formatEvalException(ex), MT_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
function evalInTargetScope (script)
|
||||
{
|
||||
if (!console.frames)
|
||||
{
|
||||
display (MSG_ERR_NO_STACK, MT_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
ASSERT (console.currentFrameIndex < console.frames.length,
|
||||
"console.currentFrameIndex out of range");
|
||||
|
||||
try
|
||||
{
|
||||
display (script, "FEVAL-IN");
|
||||
var l = $.length;
|
||||
$[l] =
|
||||
console.frames[console.currentFrameIndex].eval (script,
|
||||
MSG_VAL_CONSOLE, 1);
|
||||
display ("$[" + l + "] = " + formatValue ($[l]), "FEVAL-OUT");
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
display (formatEvalException (ex), MT_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function fillInTooltip(tipElement)
|
||||
{
|
||||
const XULNS =
|
||||
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
const XLinkNS = "http://www.w3.org/1999/xlink";
|
||||
const Node = { ELEMENT_NODE : 1 }; // XXX Components.interfaces.Node;
|
||||
|
||||
var retVal = false;
|
||||
var tipNode = document.getElementById("tooltipBox");
|
||||
while (tipNode.hasChildNodes())
|
||||
tipNode.removeChild(tipNode.firstChild);
|
||||
var titleText = "";
|
||||
var XLinkTitleText = "";
|
||||
while (!titleText && !XLinkTitleText && tipElement) {
|
||||
if (tipElement.nodeType == Node.ELEMENT_NODE) {
|
||||
titleText = tipElement.getAttribute("title");
|
||||
XLinkTitleText = tipElement.getAttributeNS(XLinkNS, "title");
|
||||
}
|
||||
tipElement = tipElement.parentNode;
|
||||
}
|
||||
var texts = [titleText, XLinkTitleText];
|
||||
for (var i = 0; i < texts.length; ++i) {
|
||||
var t = texts[i];
|
||||
if (t.search(/\S/) >= 0) {
|
||||
var tipLineElem =
|
||||
tipNode.ownerDocument.createElementNS(XULNS, "text");
|
||||
tipLineElem.setAttribute("value", t);
|
||||
tipNode.appendChild(tipLineElem);
|
||||
retVal = true;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
function formatEvalException (ex, prefix)
|
||||
{
|
||||
var str = "";
|
||||
|
||||
if (ex.fileName && ex.lineNumber && ex.message)
|
||||
{
|
||||
if (!ex.name)
|
||||
ex.name = "Error";
|
||||
|
||||
/* if it looks like a normal exception, print all the bits */
|
||||
str = getMsg (MSN_EVAL_ERROR, [ex.name, ex.fileName, ex.lineNumber]);
|
||||
if (ex.functionName)
|
||||
str += " (" + ex.functionName + ")";
|
||||
|
||||
str += ": " + ex.message;
|
||||
}
|
||||
else
|
||||
/* otherwise, just convert to a string */
|
||||
str = getMsg (MSN_EVAL_THREW, String(ex));
|
||||
|
||||
return str;
|
||||
|
||||
}
|
||||
|
||||
function htmlVA (attribs, href, contents)
|
||||
{
|
||||
if (!attribs)
|
||||
attribs = {"class": "venkman-link", target: "_content"};
|
||||
else if (attribs["class"])
|
||||
attribs["class"] += " venkman-link";
|
||||
else
|
||||
attribs["class"] = "venkman-link";
|
||||
|
||||
return htmlA (attribs, href, contents);
|
||||
}
|
||||
@ -65,8 +236,12 @@ function init()
|
||||
initPrefs();
|
||||
initDebugger();
|
||||
|
||||
console._outputDocument =
|
||||
document.getElementById("output-iframe").contentDocument;
|
||||
window._content = console._outputDocument = window.frames[0].document;
|
||||
// This should be = document.getElementById("output-iframe").contentDocument;
|
||||
// XUL iframes don't do contentDocument, and html iframes don't support
|
||||
// tooltips or drag and drop, so we've got to bend over.
|
||||
// Also, we need to set window._content manually here because the
|
||||
// drag and drop code fails as quietly as possible without it.
|
||||
|
||||
console._outputElement =
|
||||
console._outputDocument.getElementById("output-tbody");
|
||||
@ -75,6 +250,7 @@ function init()
|
||||
htmlVA(null,
|
||||
"chrome://venkman/content/tests/testpage.html"),
|
||||
" " + MSG_HELLO2), MT_HELLO);
|
||||
displayCommands();
|
||||
}
|
||||
|
||||
function load(url, obj)
|
||||
@ -134,62 +310,7 @@ console._incompleteLine = "";
|
||||
/* tab complete */
|
||||
console._lastTabUp = new Date();
|
||||
|
||||
var display = console.display =
|
||||
function display(message, msgtype)
|
||||
{
|
||||
if (typeof message == "undefined")
|
||||
throw BadMojo(ERR_REQUIRED_PARAM, "message");
|
||||
|
||||
if (typeof message != "string" && typeof message != "object")
|
||||
throw BadMojo(ERR_INVALID_PARAM, "message");
|
||||
|
||||
if (typeof msgtype == "undefined")
|
||||
msgtype = MT_INFO;
|
||||
|
||||
function setAttribs (obj, c, attrs)
|
||||
{
|
||||
for (var a in attrs)
|
||||
obj.setAttribute (a, attrs[a]);
|
||||
obj.setAttribute("class", c);
|
||||
obj.setAttribute("msg-type", msgtype);
|
||||
}
|
||||
|
||||
function stringToMsg (message)
|
||||
{
|
||||
var ary = message.split("\n");
|
||||
var span = htmlSpan();
|
||||
|
||||
for (var l in ary)
|
||||
{
|
||||
var wordParts =
|
||||
splitLongWord (ary[l], console.prefs["output.wordbreak.length"]);
|
||||
for (var i in wordParts)
|
||||
{
|
||||
span.appendChild (htmlText(wordParts[i]));
|
||||
span.appendChild (htmlImg());
|
||||
}
|
||||
|
||||
span.appendChild (htmlBR());
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
var msgRow = htmlTR("msg");
|
||||
setAttribs(msgRow, "msg");
|
||||
|
||||
var msgData = htmlTD();
|
||||
setAttribs(msgData, "msg-data");
|
||||
if (typeof message == "string")
|
||||
msgData.appendChild(stringToMsg(message));
|
||||
else
|
||||
msgData.appendChild(message);
|
||||
|
||||
msgRow.appendChild(msgData);
|
||||
|
||||
console._outputElement.appendChild(msgRow);
|
||||
console.scrollDown();
|
||||
}
|
||||
|
||||
console.display = display;
|
||||
console.load = load;
|
||||
|
||||
console.scrollDown =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user