Code review of session filters commit

Related commits:
- 46d36cb0b0
- 59c9a34d34
This commit is contained in:
Raymond Hill 2019-09-26 12:40:56 -04:00
parent 16261aa6b5
commit 7912e919b6
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
5 changed files with 28 additions and 8 deletions

View File

@ -205,7 +205,13 @@ const FilterContainer = function() {
this.specificFilters = new µb.staticExtFilteringEngine.HostnameBasedDB(2); this.specificFilters = new µb.staticExtFilteringEngine.HostnameBasedDB(2);
// temporary filters // temporary filters
this.sessionFilterDB = new µb.staticExtFilteringEngine.SessionDB(); this.sessionFilterDB = new (
class extends µb.staticExtFilteringEngine.SessionDB {
compile(s) {
return µb.staticExtFilteringEngine.compileSelector(s);
}
}
)();
// low generic cosmetic filters, organized by id/class then simple/complex. // low generic cosmetic filters, organized by id/class then simple/complex.
this.lowlyGeneric = Object.create(null); this.lowlyGeneric = Object.create(null);

View File

@ -29,7 +29,14 @@
const duplicates = new Set(); const duplicates = new Set();
const filterDB = new µb.staticExtFilteringEngine.HostnameBasedDB(2); const filterDB = new µb.staticExtFilteringEngine.HostnameBasedDB(2);
const sessionFilterDB = new µb.staticExtFilteringEngine.SessionDB(); const sessionFilterDB = new (
class extends µb.staticExtFilteringEngine.SessionDB {
compile(s) {
return µb.staticExtFilteringEngine.compileSelector(s.slice(1));
}
}
)();
let acceptedCount = 0; let acceptedCount = 0;
let discardedCount = 0; let discardedCount = 0;
let docRegister; let docRegister;

View File

@ -1282,21 +1282,18 @@ const getURLFilteringData = function(details) {
const compileTemporaryException = function(filter) { const compileTemporaryException = function(filter) {
const match = /#@?#/.exec(filter); const match = /#@?#/.exec(filter);
if ( match === null ) { return; } if ( match === null ) { return; }
let selector = filter.slice(match.index + match[0].length); let selector = filter.slice(match.index + match[0].length).trim();
let session; let session;
if ( selector.startsWith('+js') ) { if ( selector.startsWith('+js') ) {
session = µb.scriptletFilteringEngine.getSession(); session = µb.scriptletFilteringEngine.getSession();
selector = selector.slice(4, -1).trim();
} else { } else {
if ( selector.startsWith('^') ) { if ( selector.startsWith('^') ) {
session = µb.htmlFilteringEngine.getSession(); session = µb.htmlFilteringEngine.getSession();
selector = selector.slice(1).trim();
} else { } else {
session = µb.cosmeticFilteringEngine.getSession(); session = µb.cosmeticFilteringEngine.getSession();
} }
selector = µb.staticExtFilteringEngine.compileSelector(selector);
} }
return { session, selector }; return { session, selector: session.compile(selector) };
}; };
const toggleTemporaryException = function(details) { const toggleTemporaryException = function(details) {

View File

@ -30,7 +30,14 @@
const reEscapeScriptArg = /[\\'"]/g; const reEscapeScriptArg = /[\\'"]/g;
const scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(1); const scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(1);
const sessionScriptletDB = new µb.staticExtFilteringEngine.SessionDB(); const sessionScriptletDB = new (
class extends µb.staticExtFilteringEngine.SessionDB {
compile(s) {
return s.slice(4, -1).trim();
}
}
)();
let acceptedCount = 0; let acceptedCount = 0;
let discardedCount = 0; let discardedCount = 0;

View File

@ -643,6 +643,9 @@
constructor() { constructor() {
this.db = new Map(); this.db = new Map();
} }
compile(s) {
return s;
}
add(bits, s) { add(bits, s) {
const bucket = this.db.get(bits); const bucket = this.db.get(bits);
if ( bucket === undefined ) { if ( bucket === undefined ) {