1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-23 19:03:02 +01:00
Raymond Hill 2024-10-06 11:15:08 -04:00
parent 160d7f3c33
commit 818cb2d801
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
6 changed files with 101 additions and 29 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
*.bak
*.pem
__pycache__/
node_modules/
/dist/build/
/tmp/

View File

@ -0,0 +1,38 @@
{
"root": true,
"env": {
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"eqeqeq": [ "warn", "always" ],
"indent": [
"warn",
4,
{
"ArrayExpression": "first",
"CallExpression": { "arguments": "first" },
"MemberExpression": "off",
"ObjectExpression": "off",
"ignoreComments": true,
"ignoredNodes": [
"AssignmentExpression:has(Literal)"
]
}
],
"getter-return": "off",
"no-control-regex": "off",
"no-empty": [ "error", { "allowEmptyCatch": true } ],
"no-promise-executor-return": [ "error" ],
"no-template-curly-in-string": [ "error" ],
"no-unreachable-loop": [ "error" ],
"no-useless-backreference": [ "error" ],
"no-useless-escape": "off",
"require-atomic-updates": [ "warn" ]
}
}

View File

@ -19,31 +19,40 @@
Home: https://github.com/gorhill/uBlock
*/
/* globals WebAssembly */
'use strict';
/******************************************************************************/
import { createRequire } from 'module';
import { readFileSync } from 'fs';
import { dirname, resolve } from 'path';
import { domainToASCII, fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
import publicSuffixList from './lib/publicsuffixlist/publicsuffixlist.js';
import snfe from './js/static-net-filtering.js';
import { FilteringContext } from './js/filtering-context.js';
import { LineIterator } from './js/text-utils.js';
import * as s14e from './js/s14e-serializer.js';
import * as sfp from './js/static-filtering-parser.js';
import {
CompiledListReader,
CompiledListWriter,
} from './js/static-filtering-io.js';
import {
TextDecoder,
TextEncoder,
} from 'util';
import {
dirname,
resolve
} from 'path';
import {
domainToASCII,
fileURLToPath
} from 'url';
import { FilteringContext } from './js/filtering-context.js';
import { LineIterator } from './js/text-utils.js';
import { createRequire } from 'module';
import publicSuffixList from './lib/publicsuffixlist/publicsuffixlist.js';
import { readFileSync } from 'fs';
import snfe from './js/static-net-filtering.js';
/******************************************************************************/
const __dirname = dirname(fileURLToPath(import.meta.url));
// https://stackoverflow.com/questions/69187442/const-utf8encoder-new-textencoder-in-node-js
globalThis.TextDecoder = TextDecoder;
globalThis.TextEncoder = TextEncoder;
/******************************************************************************/
@ -241,11 +250,13 @@ class StaticNetFilteringEngine {
}
serialize() {
return snfe.serialize();
const data = snfe.serialize();
return s14e.serialize(data, { compress: true });
}
deserialize(serialized) {
return snfe.unserialize(serialized);
const data = s14e.deserialize(serialized);
return snfe.unserialize(data);
}
static async create({ noPSL = false } = {}) {

View File

@ -31,7 +31,7 @@
},
"homepage": "https://github.com/gorhill/uBlock#readme",
"engines": {
"node": ">=14.0.0",
"node": ">=18.0.0",
"npm": ">=6.14.4"
},
"devDependencies": {

View File

@ -249,8 +249,29 @@ const toArrayBufferViewConstructor = {
/******************************************************************************/
const textDecoder = new TextDecoder();
const textEncoder = new TextEncoder();
const textCodec = {
decoder: null,
encoder: null,
decode(...args) {
if ( this.decoder === null ) {
this.decoder = new globalThis.TextDecoder();
}
return this.decoder.decode(...args);
},
encode(...args) {
if ( this.encoder === null ) {
this.encoder = new globalThis.TextEncoder();
}
return this.encoder.encode(...args);
},
encodeInto(...args) {
if ( this.encoder === null ) {
this.encoder = new globalThis.TextEncoder();
}
return this.encoder.encodeInto(...args);
},
};
const isInteger = Number.isInteger;
const writeRefs = new Map();
@ -269,7 +290,7 @@ const uint8InputFromAsciiStr = s => {
if ( uint8Input === null || uint8Input.length < s.length ) {
uint8Input = new Uint8Array(s.length + 0x03FF & ~0x03FF);
}
textEncoder.encodeInto(s, uint8Input);
textCodec.encodeInto(s, uint8Input);
return uint8Input;
};
@ -407,7 +428,7 @@ const denseArrayBufferToStr = (arrbuf, details) => {
}
}
}
return textDecoder.decode(output);
return textCodec.decode(output);
};
const BASE88_POW1 = NUMSAFECHARS;
@ -489,7 +510,7 @@ const sparseArrayBufferToStr = (arrbuf, details) => {
uint8out[j++] = SEPARATORCHARCODE;
}
}
return textDecoder.decode(uint8out);
return textCodec.decode(uint8out);
};
const sparseArrayBufferFromStr = (sparseStr, arrbuf) => {
@ -1060,7 +1081,7 @@ export const serialize = (data, options = {}) => {
writeBuffer.length = 0;
if ( shouldCompress(s, options) === false ) { return s; }
const lz4Util = new LZ4BlockJS();
const uint8ArrayBefore = textEncoder.encode(s);
const uint8ArrayBefore = textCodec.encode(s);
const uint8ArrayAfter = lz4Util.encode(uint8ArrayBefore, 0);
const lz4 = {
size: uint8ArrayBefore.length,
@ -1087,7 +1108,7 @@ export const deserialize = s => {
readStr = '';
const lz4Util = new LZ4BlockJS();
const uint8ArrayAfter = lz4Util.decode(lz4.data, 0, lz4.size);
s = textDecoder.decode(new Uint8Array(uint8ArrayAfter));
s = textCodec.decode(new Uint8Array(uint8ArrayAfter));
}
if ( s.startsWith(MAGICPREFIX) === false ) { return; }
refCounter = 1;

View File

@ -14,6 +14,7 @@ cp src/js/filtering-context.js $DES/js
cp src/js/hnswitches.js $DES/js
cp src/js/hntrie.js $DES/js
cp src/js/redirect-resources.js $DES/js
cp src/js/s14e-serializer.js $DES/js
cp src/js/static-dnr-filtering.js $DES/js
cp src/js/static-filtering-parser.js $DES/js
cp src/js/static-net-filtering.js $DES/js