Changes to abort-on-stack-trace as per road testing

Related commit:
- https://github.com/gorhill/uBlock/commit/b735ac6b6aba
This commit is contained in:
Raymond Hill 2020-09-23 06:54:44 -04:00
parent 2caf9a193e
commit 365b3f7f83
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 25 additions and 6 deletions

View File

@ -206,7 +206,7 @@
} else {
needle = needle.replace(reRegexEscape, '\\$&');
}
const reNeedle = new RegExp(needle, 'im');
const reNeedle = new RegExp(needle);
const magic = String.fromCharCode(Math.random() * 26 + 97) +
Math.floor(
(0.25 + Math.random() * 0.75) * Number.MAX_SAFE_INTEGER
@ -219,17 +219,36 @@
if ( pos !== -1 ) {
docURL = docURL.slice(0, pos);
}
const reDocURL = new RegExp(docURL.replace(reRegexEscape, '\\$&'), 'g');
const stack = err.stack
.replace(/^.*?\b[gs]et\b[^\n\r]+?(?:[\n\r]+|$)/m, '')
.replace(reDocURL, '<inline-script>');
// Normalize stack trace
const lines = [];
for ( let line of err.stack.split(/[\n\r]+/) ) {
if ( line.includes(magic) ) { continue; }
line = line.trim();
let match = /(.*?@)?(\S+)(:\d+):\d+\)?$/.exec(line);
if ( match === null ) { continue; }
let url = match[2];
if ( url.startsWith('(') ) { url = url.slice(1); }
if ( url === docURL ) {
url += '#inlineScript';
} else if ( url.startsWith('<anonymous>') ) {
url = 'injectedScript';
}
let fn = match[1] !== undefined
? match[1].slice(0, -1)
: line.slice(0, match.index).trim();
if ( fn.startsWith('at') ) { fn = fn.slice(2).trim(); }
let rowcol = match[3];
lines.push(' ' + `${fn} ${url}${rowcol}:1`.trim());
}
lines[0] = `stackDepth:${lines.length-1}`;
const stack = lines.join('\t');
const r = reNeedle.test(stack);
if (
logLevel === '1' ||
logLevel === '2' && r ||
logLevel === '3' && !r
) {
log(stack);
log(stack.replace(/\t/g, '\n'));
}
return r;
};