2015-04-22 11:55:31 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2017-06-25 22:22:17 +02:00
|
|
|
(function(){
|
2015-09-08 11:42:32 +02:00
|
|
|
"use strict";
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
let scope;
|
2017-06-25 22:22:17 +02:00
|
|
|
if ((typeof exports) !== "undefined"){
|
|
|
|
scope = exports;
|
|
|
|
}
|
|
|
|
else {
|
2019-03-12 22:24:23 +01:00
|
|
|
scope = require.register("./callingStack", {});
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
2017-11-07 00:36:44 +01:00
|
|
|
|
|
|
|
const settings = require("./settings");
|
2019-03-14 16:51:20 +01:00
|
|
|
const extension = require("./extension");
|
2015-09-08 11:42:32 +02:00
|
|
|
|
2017-06-25 22:22:17 +02:00
|
|
|
// Translation
|
2019-11-28 01:26:35 +01:00
|
|
|
const _ = function(name, replace, translateAPI){
|
2017-06-25 22:22:17 +02:00
|
|
|
if (!translateAPI){
|
2019-03-14 16:51:20 +01:00
|
|
|
translateAPI = extension.getTranslation;
|
2017-06-25 22:22:17 +02:00
|
|
|
}
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
let str = translateAPI(name) || name;
|
2017-06-25 22:22:17 +02:00
|
|
|
if (replace){
|
2019-03-14 16:51:20 +01:00
|
|
|
// replace generic content in the translation by given parameter
|
2017-06-25 22:22:17 +02:00
|
|
|
Object.keys(replace).forEach(function(name){
|
|
|
|
str = str.replace(new RegExp("{" + name + "}", "g"), replace[name]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return str;
|
2015-09-06 12:26:50 +02:00
|
|
|
};
|
2017-06-25 22:22:17 +02:00
|
|
|
|
|
|
|
// Stack parsing
|
|
|
|
function parseStackEntry(entry){
|
2019-11-28 01:26:35 +01:00
|
|
|
const m = /@(.*):(\d*):(\d*)$/.exec(entry) || ["", entry, "--", "--"];
|
2017-06-25 22:22:17 +02:00
|
|
|
return {
|
|
|
|
url: m[1],
|
|
|
|
line: parseInt(m[2], 10),
|
|
|
|
column: parseInt(m[3], 10),
|
|
|
|
raw: entry
|
|
|
|
};
|
2015-12-31 13:37:27 +01:00
|
|
|
}
|
2017-06-25 22:22:17 +02:00
|
|
|
|
|
|
|
function stackRuleMatch(stackEntry, stackRule){
|
|
|
|
if (!stackEntry){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (stackEntry.url !== stackRule.url){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ((typeof stackRule.line) !== "undefined" && stackEntry.line !== stackRule.line){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ((typeof stackRule.column) !== "undefined" && stackEntry.column !== stackRule.column){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2015-12-31 13:37:27 +01:00
|
|
|
}
|
|
|
|
|
2017-06-25 22:22:17 +02:00
|
|
|
// parse calling stack
|
2019-03-14 16:51:20 +01:00
|
|
|
const extensionID = extension.extensionID;
|
2017-06-25 22:22:17 +02:00
|
|
|
function parseErrorStack(errorStack){
|
2019-11-28 01:26:35 +01:00
|
|
|
const callers = errorStack.trim().split("\n").map(parseStackEntry).filter(function(caller){
|
2018-07-17 12:50:40 +02:00
|
|
|
return !caller.url.startsWith(extensionID);
|
|
|
|
});
|
2017-06-25 22:22:17 +02:00
|
|
|
return {
|
|
|
|
toString: function(translateAPI){
|
2019-11-28 01:26:35 +01:00
|
|
|
let msg = "";
|
2017-06-25 22:22:17 +02:00
|
|
|
msg += "\n\n" + _("sourceOutput", undefined, translateAPI) + ": ";
|
2017-10-06 16:06:31 +02:00
|
|
|
if (settings.showCompleteCallingStack){
|
2017-06-25 22:22:17 +02:00
|
|
|
msg += callers.reduce(function(stack, c){
|
|
|
|
return stack + "\n\t" + _("stackEntryOutput", c, translateAPI);
|
|
|
|
}, "");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
msg += _("stackEntryOutput", callers[0], translateAPI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
},
|
|
|
|
match: function(stackRule){
|
|
|
|
if (typeof stackRule.stackPosition !== "undefined"){
|
2019-11-28 01:26:35 +01:00
|
|
|
let pos = stackRule.stackPosition;
|
2017-06-25 22:22:17 +02:00
|
|
|
if (pos < 0){
|
|
|
|
pos += callers.length;
|
|
|
|
}
|
|
|
|
return stackRuleMatch(callers[pos], stackRule);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return callers.some(function(stackEntry){
|
|
|
|
return stackRuleMatch(stackEntry, stackRule);
|
|
|
|
});
|
2015-12-31 13:37:27 +01:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 22:22:17 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
scope.parseErrorStack = parseErrorStack;
|
|
|
|
}());
|