1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 04:49:12 +02:00

Provide compiler/selfie versions for snfe

So as to allow nodejs usage to better deal with
out of date serialization/compilation.

Additionally, use FilterImportant() only when a
"block-important" filter is stored in the "block" realm.
This commit is contained in:
Raymond Hill 2021-08-16 12:15:30 -04:00
parent 30e46ba64a
commit a33f70cf20
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 18 additions and 15 deletions

View File

@ -3431,11 +3431,6 @@ class FilterCompiler {
units.push(FilterAnchorRight.compile());
}
// Important
if ( (this.action & Important) !== 0 ) {
units.push(FilterImportant.compile());
}
// Strict partiness
if ( this.strictParty !== 0 ) {
units.push(FilterStrictParty.compile(this));
@ -3469,11 +3464,12 @@ class FilterCompiler {
this.action = (this.action & ~ActionBitsMask) | ModifyAction;
}
const fdata = units.length === 1
? units[0]
: FilterCompositeAll.compile(units);
this.compileToAtomicFilter(fdata, writer);
this.compileToAtomicFilter(
units.length === 1
? units[0]
: FilterCompositeAll.compile(units),
writer
);
// Add block-important filters to the block realm, so as to avoid
// to unconditionally match against the block-important realm for
@ -3483,7 +3479,11 @@ class FilterCompiler {
// meant to override.
if ( (this.action & BlockImportant) !== 0 ) {
this.action &= ~Important;
this.compileToAtomicFilter(fdata, writer);
units.push(FilterImportant.compile());
this.compileToAtomicFilter(
FilterCompositeAll.compile(units),
writer
);
}
}
@ -3537,6 +3537,9 @@ FilterCompiler.prototype.FILTER_UNSUPPORTED = 2;
/******************************************************************************/
const FilterContainer = function() {
this.compilerVersion = '1';
this.selfieVersion = '1';
this.MAX_TOKEN_LENGTH = MAX_TOKEN_LENGTH;
this.optimizeTimerId = undefined;
// As long as CategoryCount is reasonably low, we will use an array to
@ -3768,6 +3771,7 @@ FilterContainer.prototype.toSelfie = function(storage, path) {
storage.put(
`${path}/main`,
JSON.stringify({
version: this.selfieVersion,
processedFilterCount: this.processedFilterCount,
acceptedCount: this.acceptedCount,
rejectedCount: this.rejectedCount,
@ -3831,6 +3835,7 @@ FilterContainer.prototype.fromSelfie = function(storage, path) {
} catch (ex) {
}
if ( selfie instanceof Object === false ) { return false; }
if ( selfie.version !== this.selfieVersion ) { return false; }
this.processedFilterCount = selfie.processedFilterCount;
this.acceptedCount = selfie.acceptedCount;
this.rejectedCount = selfie.rejectedCount;

View File

@ -866,10 +866,8 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
this.badLists.has(assetKey) === false
) {
const compiledDetails = await io.get(compiledPath);
if (
parseInt(compiledDetails.content, 10) ===
this.systemSettings.compiledMagic
) {
const compilerVersion = `${this.systemSettings.compiledMagic}\n`;
if ( compiledDetails.content.startsWith(compilerVersion) ) {
compiledDetails.assetKey = assetKey;
return compiledDetails;
}