Skip to content

Commit

Permalink
Fix the script error reporting code.
Browse files Browse the repository at this point in the history
As injection logic was moved into script.js (774d41a), error reporting code has been updated to better handle _apiLeakCheck errors. Unfortunately, it also broke the simple case of script errors.
With this fix, both should work ok.
Let's note that the above mentionned patch also changed _apiLeakCheck errors: they used to be only reported in the JS console, they now are also thrown back at the script.
  • Loading branch information
ocornu committed Aug 29, 2009
1 parent 348adfa commit 36534d6
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/modules/script.js
Expand Up @@ -156,14 +156,14 @@ Script.prototype = {
Components.utils.evalInSandbox(file.readText(), sandbox, jsVersion,
file.uri.spec, 1);
} catch (err) {
this._api.logError(err);
this._api.logError(new Error(err.message, file.uri.spec, err.lineNumber));
}
// script source file
try {
Components.utils.evalInSandbox(this.file.readText(), sandbox, jsVersion,
this.file.uri.spec, 1);
} catch (err) {
this._api.logError(err);
this._api.logError(new Error(err.message, this.file.uri.spec, err.lineNumber));
}
},

Expand Down Expand Up @@ -952,16 +952,17 @@ Script.Api.prototype = {
* @return {Error} The error logged.
*/
logError: function (/**Error*/ error) {
// Search the first occurrence of one of our source files in the call stack
var stack = Components.stack;
while (stack && this._files.indexOf(stack.filename)==-1)
stack = stack.caller;
if (stack) {
error.fileName = stack.filename;
error.lineNumber = stack.lineNumber;
error.columNumber = 0;
if (this._files.indexOf(error.fileName)==-1) {
// Search the first occurrence of one of our source files in the call stack
var stack = Components.stack;
while (stack && this._files.indexOf(stack.filename)==-1)
stack = stack.caller;
if (stack) {
error.fileName = stack.filename;
error.lineNumber = stack.lineNumber;
error.columnNumber = 0;
}
}
// log it
var consoleError = Cc["@mozilla.org/scripterror;1"]
.createInstance(Ci.nsIScriptError);
consoleError.init(error.message, error.fileName, null,
Expand Down

0 comments on commit 36534d6

Please sign in to comment.