зеркало из https://github.com/mozilla/gecko-dev.git
Bug 956804 - Use DevToolsUtils.reportException in Parser.jsm; r=fitzgen
This commit is contained in:
Родитель
97427bf27c
Коммит
2db2ce3e20
|
@ -9,6 +9,7 @@ const Ci = Components.interfaces;
|
|||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
const { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {});
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this,
|
||||
"Reflect", "resource://gre/modules/reflect.jsm");
|
||||
|
@ -65,7 +66,7 @@ Parser.prototype = {
|
|||
syntaxTrees.push(new SyntaxTree(nodes, aUrl, length));
|
||||
} catch (e) {
|
||||
this.errors.push(e);
|
||||
log(aUrl, e);
|
||||
DevToolsUtils.reportException(aUrl, e);
|
||||
}
|
||||
}
|
||||
// Generate the AST nodes for each script.
|
||||
|
@ -79,7 +80,7 @@ Parser.prototype = {
|
|||
syntaxTrees.push(new SyntaxTree(nodes, aUrl, length, offset));
|
||||
} catch (e) {
|
||||
this.errors.push(e);
|
||||
log(aUrl, e);
|
||||
DevToolsUtils.reportException(aUrl, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -225,7 +226,7 @@ SyntaxTreesPool.prototype = {
|
|||
// Can't guarantee that the tree traversal logic is forever perfect :)
|
||||
// Language features may be added, in which case the recursive methods
|
||||
// need to be updated. If an exception is thrown here, file a bug.
|
||||
log("syntax tree", e);
|
||||
DevToolsUtils.reportException("syntax tree", e);
|
||||
}
|
||||
}
|
||||
this._cache.set(requestId, results);
|
||||
|
@ -2341,26 +2342,4 @@ let SyntaxTreeVisitor = {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs a warning.
|
||||
*
|
||||
* @param string aStr
|
||||
* The message to be displayed.
|
||||
* @param Exception aEx
|
||||
* The thrown exception.
|
||||
*/
|
||||
function log(aStr, aEx) {
|
||||
let msg = "Warning: " + aStr + ", " + aEx.message;
|
||||
|
||||
if ("lineNumber" in aEx && "columnNumber" in aEx) {
|
||||
msg += ", line: " + aEx.lineNumber + ", column: " + aEx.columnNumber;
|
||||
}
|
||||
if ("stack" in aEx) {
|
||||
msg += "\n" + aEx.stack;
|
||||
}
|
||||
|
||||
Cu.reportError(msg);
|
||||
dump(msg + "\n");
|
||||
};
|
||||
|
||||
XPCOMUtils.defineLazyGetter(Parser, "reflectionAPI", () => Reflect);
|
||||
|
|
|
@ -16,18 +16,22 @@ let { Services } = Components.utils.import("resource://gre/modules/Services.jsm"
|
|||
this.safeErrorString = function safeErrorString(aError) {
|
||||
try {
|
||||
let errorString = aError.toString();
|
||||
if (typeof errorString === "string") {
|
||||
if (typeof errorString == "string") {
|
||||
// Attempt to attach a stack to |errorString|. If it throws an error, or
|
||||
// isn't a string, don't use it.
|
||||
try {
|
||||
if (aError.stack) {
|
||||
let stack = aError.stack.toString();
|
||||
if (typeof stack === "string") {
|
||||
if (typeof stack == "string") {
|
||||
errorString += "\nStack: " + stack;
|
||||
}
|
||||
}
|
||||
} catch (ee) { }
|
||||
|
||||
if (typeof aError.lineNumber == "number" && typeof aError.columnNumber == "number") {
|
||||
errorString += ", line: " + aError.lineNumber + ", column: " + aError.columnNumber;
|
||||
}
|
||||
|
||||
return errorString;
|
||||
}
|
||||
} catch (ee) { }
|
||||
|
|
|
@ -19,6 +19,9 @@ function test_with_error() {
|
|||
// Got the stack.
|
||||
do_check_true(s.contains("test_with_error"))
|
||||
do_check_true(s.contains("test_safeErrorString.js"));
|
||||
// Got the lineNumber and columnNumber.
|
||||
do_check_true(s.contains("line"));
|
||||
do_check_true(s.contains("column"));
|
||||
}
|
||||
|
||||
function test_with_tricky_error() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче