Add static release() to StaticNetFilteringEngine class

The method ensures the actual SNFE is properly reset.
This commit is contained in:
Raymond Hill 2021-08-15 11:18:01 -04:00
parent f8f45cab70
commit e9ae8e1a0f
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 8 additions and 6 deletions

View File

@ -95,7 +95,10 @@ function pslInit(raw) {
return globals.publicSuffixList; return globals.publicSuffixList;
} }
raw = readFileSync(resolve(__dirname, './assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat'), 'utf8') raw = readFileSync(
resolve(__dirname, './assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat'),
'utf8'
);
if ( typeof raw !== 'string' || raw.trim() === '' ) { if ( typeof raw !== 'string' || raw.trim() === '' ) {
console.error('Unable to populate public suffix list'); console.error('Unable to populate public suffix list');
return; return;
@ -147,7 +150,7 @@ async function useLists(lists, options = {}) {
snfe.reset(); snfe.reset();
if ( Array.isArray(lists) === false || lists.length === 0 ) { if ( Array.isArray(lists) === false || lists.length === 0 ) {
return snfe; return;
} }
let compiler = null; let compiler = null;
@ -176,8 +179,6 @@ async function useLists(lists, options = {}) {
// Commit changes // Commit changes
snfe.freeze(); snfe.freeze();
snfe.optimize(); snfe.optimize();
return snfe;
} }
/******************************************************************************/ /******************************************************************************/
@ -253,9 +254,10 @@ class StaticNetFilteringEngine {
return instance; return instance;
} }
static release() { static async release() {
useLists([]); if ( snfeProxyInstance === null ) { return; }
snfeProxyInstance = null; snfeProxyInstance = null;
await useLists([]);
} }
} }