зеркало из https://github.com/mozilla/gecko-dev.git
- not built -
add warn and ASSERT make load() a top level function exception i18n, add numeric code to exceptions
This commit is contained in:
Родитель
89b45ccdd0
Коммит
6baf04f562
|
@ -34,62 +34,108 @@
|
|||
*/
|
||||
|
||||
if (DEBUG)
|
||||
{
|
||||
dd = function (msg) { dumpln("-*- venkman: " + msg); }
|
||||
warn = function (msg) { dd ("** WARNING " + msg + " **"); }
|
||||
ASSERT = function (expr, msg) {
|
||||
if (!expr)
|
||||
dd ("** ASSERTION FAILED: " + msg + " **\n" + getStackTrace());
|
||||
}
|
||||
}
|
||||
else
|
||||
dd = function (){};
|
||||
dd = warn = ASSERT = function (){};
|
||||
|
||||
var console = new Object();
|
||||
|
||||
console._inputHistory = new Array();
|
||||
console._lastHistoryReferenced = -1;
|
||||
console._incompleteLine = "";
|
||||
console._lastTabUp = new Date();
|
||||
/* |this|less functions */
|
||||
|
||||
function init()
|
||||
{
|
||||
initCommands();
|
||||
initPrefs();
|
||||
initDebugger();
|
||||
|
||||
|
||||
console._outputDocument =
|
||||
document.getElementById ("output-iframe").contentDocument;
|
||||
document.getElementById("output-iframe").contentDocument;
|
||||
|
||||
console._outputElement =
|
||||
console._outputDocument.getElementById ("output-tbody");
|
||||
console._outputDocument.getElementById("output-tbody");
|
||||
}
|
||||
|
||||
function Foo (msg)
|
||||
function load(url, obj)
|
||||
{
|
||||
dd ("new Foo (" + msg + ") from\n" + getStackTrace());
|
||||
this.msg = msg;
|
||||
var rv;
|
||||
var ex;
|
||||
|
||||
if (!console._loader)
|
||||
{
|
||||
const LOADER_CTRID = "@mozilla.org/moz/jssubscript-loader;1";
|
||||
const mozIJSSubScriptLoader =
|
||||
Components.interfaces.mozIJSSubScriptLoader;
|
||||
|
||||
var cls;
|
||||
if ((cls = Components.classes[LOADER_CTRID]))
|
||||
console._loader = cls.createInstance(mozIJSSubScriptLoader);
|
||||
}
|
||||
|
||||
rv = console._loader.loadSubScript(url, obj);
|
||||
|
||||
display(getMsg(MSN_SUBSCRIPT_LOADED, url), MT_INFO);
|
||||
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
console.inputHistory = new Array();
|
||||
/* exceptions */
|
||||
|
||||
console.doEval =
|
||||
function con_eval(__s)
|
||||
/* keep this list in sync with exceptionMsgNames in venkman-msg.js */
|
||||
const ERR_NOT_IMPLEMENTED = 0;
|
||||
const ERR_DISPLAY_ARG1 = 1;
|
||||
const ERR_SUBSCRIPT_LOAD = 2;
|
||||
|
||||
/* venkman exception factory, can be used with or without |new|.
|
||||
* throw BadMojo (ERR_FOO, MSG_VAL_UNDEFINED);
|
||||
* throw new BadMojo (ERR_NOT_IMPLEMENTED);
|
||||
*/
|
||||
function BadMojo (errno, params)
|
||||
{
|
||||
return eval(__s);
|
||||
var msg = getMsg(exceptionMsgNames[errno], params);
|
||||
|
||||
dd ("new BadMojo (" + errno + ": " + msg + ") from\n" + getStackTrace());
|
||||
return {message: msg, name: "Error " + errno,
|
||||
fileName: Components.stack.caller.filename,
|
||||
lineNumber: Components.stack.caller.lineNumber};
|
||||
}
|
||||
|
||||
/* console object */
|
||||
|
||||
/* input history (up/down arrow) related vars */
|
||||
console._inputHistory = new Array();
|
||||
console._lastHistoryReferenced = -1;
|
||||
console._incompleteLine = "";
|
||||
|
||||
/* tab complete */
|
||||
console._lastTabUp = new Date();
|
||||
|
||||
var display = console.display =
|
||||
function display(message, msgtype)
|
||||
{
|
||||
if (typeof message == "undefined")
|
||||
throw new Foo ("undefined message passed to display()");
|
||||
throw BadMojo(ERR_DISPLAY_ARG1);
|
||||
|
||||
function setAttribs (obj, c, attrs)
|
||||
{
|
||||
for (var a in attrs)
|
||||
obj.setAttribute (a, attrs[a]);
|
||||
obj.setAttribute ("class", c);
|
||||
obj.setAttribute ("msg-type", msgtype);
|
||||
obj.setAttribute("class", c);
|
||||
obj.setAttribute("msg-type", msgtype);
|
||||
}
|
||||
|
||||
function stringToMsg (message)
|
||||
{
|
||||
var ary = message.split ("\n");
|
||||
var ary = message.split("\n");
|
||||
var span = document.createElementNS (NS_XHTML, HTML_SPAN);
|
||||
|
||||
for (var l in ary)
|
||||
{
|
||||
var wordParts =
|
||||
|
@ -110,51 +156,16 @@ function display(message, msgtype)
|
|||
setAttribs(msgRow, "msg");
|
||||
|
||||
var msgData = document.createElementNS(NS_XHTML, HTML_TD);
|
||||
setAttribs (msgData, "msg-data");
|
||||
msgData.appendChild (stringToMsg (message));
|
||||
setAttribs(msgData, "msg-data");
|
||||
msgData.appendChild(stringToMsg(message));
|
||||
|
||||
msgRow.appendChild (msgData);
|
||||
msgRow.appendChild(msgData);
|
||||
|
||||
console._outputElement.appendChild (msgRow);
|
||||
console._outputElement.appendChild(msgRow);
|
||||
console.scrollDown();
|
||||
}
|
||||
|
||||
console.load =
|
||||
function con_load(url, obj)
|
||||
{
|
||||
var rv;
|
||||
|
||||
if (!console._loader)
|
||||
{
|
||||
const LOADER_CTRID = "@mozilla.org/moz/jssubscript-loader;1";
|
||||
const mozIJSSubScriptLoader =
|
||||
Components.interfaces.mozIJSSubScriptLoader;
|
||||
|
||||
var cls;
|
||||
if ((cls = Components.classes[LOADER_CTRID]))
|
||||
console._loader = cls.createInstance (mozIJSSubScriptLoader);
|
||||
}
|
||||
|
||||
try {
|
||||
rv = console._loader.loadSubScript (url, obj);
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
var msg = "Error loading subscript: " + ex;
|
||||
if (ex.fileName)
|
||||
msg += " file:" + ex.fileName;
|
||||
if (ex.lineNumber)
|
||||
msg += " line:" + ex.lineNumber;
|
||||
|
||||
display (msg, "ERROR");
|
||||
}
|
||||
|
||||
display ("URL ``" + url + "'' loaded with result ``" + String(rv) + "''.",
|
||||
"ERROR");
|
||||
|
||||
return rv;
|
||||
|
||||
}
|
||||
console.load = load;
|
||||
|
||||
console.scrollDown =
|
||||
function con_scrolldn ()
|
||||
|
|
Загрузка…
Ссылка в новой задаче