Bug 1820531 - Support multiple extensions in Log.stackTrace in Log.sys.mjs. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D171839
This commit is contained in:
Tooru Fujisawa 2023-03-08 07:11:14 +00:00
Родитель cd2121e7d8
Коммит 5d1c45fd02
3 изменённых файлов: 28 добавлений и 4 удалений

Просмотреть файл

@ -99,13 +99,12 @@ export var Log = {
let output = [];
while (frame) {
// Works on frames or exceptions, munges file:// URIs to shorten the paths
// FIXME: filename munging is sort of hackish, might be confusing if
// there are multiple extensions with similar filenames
// FIXME: filename munging is sort of hackish.
let str = "<file:unknown>";
let file = frame.filename || frame.fileName;
if (file) {
str = file.replace(/^(?:chrome|file):.*?([^\/\.]+\.\w+)$/, "$1");
str = file.replace(/^(?:chrome|file):.*?([^\/\.]+(\.\w+)+)$/, "$1");
}
if (frame.lineNumber) {
@ -128,7 +127,7 @@ export var Log = {
let stack = e.stack;
return (
"JS Stack trace: " +
stack.trim().replace(/@[^@]*?([^\/\.]+\.\w+:)/g, "@$1")
stack.trim().replace(/@[^@]*?([^\/\.]+(\.\w+)+:)/g, "@$1")
);
}

Просмотреть файл

@ -0,0 +1,24 @@
const { Log } = ChromeUtils.importESModule(
"resource://gre/modules/Log.sys.mjs"
);
function run_test() {
// Verify error with double extensions are handled correctly.
const nsIExceptionTrace = Log.stackTrace({
location: {
filename: "chrome://foo/bar/file.sys.mjs",
lineNumber: 10,
name: "func",
caller: null,
},
});
Assert.equal(nsIExceptionTrace, "Stack trace: func()@file.sys.mjs:10");
const JSExceptionTrace = Log.stackTrace({
stack: "func2@chrome://foo/bar/file.sys.mjs:10:2",
});
Assert.equal(JSExceptionTrace, "JS Stack trace: func2@file.sys.mjs:10:2");
}

Просмотреть файл

@ -40,6 +40,7 @@ tags = remote-settings
[test_JSONFile.js]
[test_JsonSchema.js]
[test_Log.js]
[test_Log_double_ext.js]
[test_MatchURLFilters.js]
[test_NewTabUtils.js]
skip-if = toolkit == 'android'