mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Code review re. scriptlets lookup
Possibly fixes a race condition at browser launch causing empty scriptlets to be injected (and cached).
This commit is contained in:
parent
90e3c352ec
commit
f25a437fd1
4 changed files with 19 additions and 15 deletions
|
|
@ -460,6 +460,7 @@ class RedirectEngine {
|
|||
for ( const [ token, entry ] of this.resources ) {
|
||||
this.resources.set(token, RedirectEntry.fromDetails(entry));
|
||||
}
|
||||
this.modifyTime = Date.now();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,11 +25,6 @@ import { redirectEngine as reng } from './redirect-engine.js';
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
const $mainWorldMap = new Map();
|
||||
const $isolatedWorldMap = new Map();
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// For debugging convenience: all the top function calls will appear
|
||||
// at the bottom of a generated content script
|
||||
const codeSorter = (a, b) => {
|
||||
|
|
@ -243,18 +238,27 @@ export class ScriptletFilteringEngine {
|
|||
}
|
||||
}
|
||||
|
||||
const mainWorldMap = new Map();
|
||||
const isolatedWorldMap = new Map();
|
||||
|
||||
for ( const token of scriptlets ) {
|
||||
lookupScriptlet(token, $mainWorldMap, $isolatedWorldMap, options.debug);
|
||||
lookupScriptlet(token, mainWorldMap, isolatedWorldMap, options.debug);
|
||||
}
|
||||
|
||||
if ( scriptlets.size !== 0 ) {
|
||||
if ( mainWorldMap.size === 0 ) {
|
||||
if ( isolatedWorldMap.size === 0 ) { return; }
|
||||
}
|
||||
}
|
||||
|
||||
const mainWorldCode = [];
|
||||
for ( const js of $mainWorldMap.values() ) {
|
||||
for ( const js of mainWorldMap.values() ) {
|
||||
mainWorldCode.push(js);
|
||||
}
|
||||
mainWorldCode.sort(codeSorter);
|
||||
|
||||
const isolatedWorldCode = [];
|
||||
for ( const js of $isolatedWorldMap.values() ) {
|
||||
for ( const js of isolatedWorldMap.values() ) {
|
||||
isolatedWorldCode.push(js);
|
||||
}
|
||||
isolatedWorldCode.sort(codeSorter);
|
||||
|
|
@ -267,8 +271,6 @@ export class ScriptletFilteringEngine {
|
|||
...Array.from(exceptions).map(a => decompile(a, true)),
|
||||
],
|
||||
};
|
||||
$mainWorldMap.clear();
|
||||
$isolatedWorldMap.clear();
|
||||
|
||||
const scriptletGlobals = options.scriptletGlobals || {};
|
||||
|
||||
|
|
|
|||
|
|
@ -328,6 +328,7 @@ export class ScriptletFilteringEngineEx extends ScriptletFilteringEngine {
|
|||
if ( typeof details.frameId !== 'number' ) { return; }
|
||||
|
||||
const hostname = hostnameFromURI(details.url);
|
||||
if ( hostname === '' ) { return; }
|
||||
const domain = domainFromHostname(hostname);
|
||||
|
||||
const scriptletDetails = this.retrieve({
|
||||
|
|
|
|||
|
|
@ -92,9 +92,9 @@ export class StaticExtFilteringHostnameDB {
|
|||
if ( target.includes('/') ) {
|
||||
return this.#storeMatcher(target, iStr);
|
||||
}
|
||||
const iList = this.#hostnameToStringListMap.get(target);
|
||||
const iList = this.#hostnameToStringListMap.get(target) ?? 0;
|
||||
this.#hostnameToStringListMap.set(target, this.#linkedLists.length);
|
||||
this.#linkedLists.push(iStr, iList !== undefined ? iList : 0);
|
||||
this.#linkedLists.push(iStr, iList);
|
||||
}
|
||||
|
||||
#storeMatcher(target, iStr) {
|
||||
|
|
@ -105,11 +105,11 @@ export class StaticExtFilteringHostnameDB {
|
|||
this.#matcherSlots.push({ isRegex, hn, pn, iList: 0 });
|
||||
this.#matcherMap.set(target, iMatcher);
|
||||
if ( isRegex === false ) {
|
||||
const iMatcherList = this.#hostnameToMatcherListMap.get(hn) || 0;
|
||||
const iMatcherList = this.#hostnameToMatcherListMap.get(hn) ?? 0;
|
||||
this.#hostnameToMatcherListMap.set(hn, this.#linkedLists.length);
|
||||
this.#linkedLists.push(iMatcher, iMatcherList);
|
||||
} else {
|
||||
const iMatcherList = this.#hostnameToMatcherListMap.get('') || 0;
|
||||
const iMatcherList = this.#hostnameToMatcherListMap.get('') ?? 0;
|
||||
this.#hostnameToMatcherListMap.set('', this.#linkedLists.length);
|
||||
this.#linkedLists.push(iMatcher, iMatcherList);
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ export class StaticExtFilteringHostnameDB {
|
|||
}
|
||||
|
||||
#retrieveSpecificsByRegex(hn, out, hostname, pathname) {
|
||||
let iMatchList = this.#hostnameToMatcherListMap.get(hn) || 0;
|
||||
let iMatchList = this.#hostnameToMatcherListMap.get(hn) ?? 0;
|
||||
while ( iMatchList !== 0 ) {
|
||||
const iMatchSlot = this.#linkedLists[iMatchList+0];
|
||||
const matcher = this.#matcherSlots[iMatchSlot];
|
||||
|
|
|
|||
Loading…
Reference in a new issue