mirror of https://github.com/gorhill/uBlock.git
Move orphanizeString() into text-utils module
Another small step toward the goal of reducing dependency on `µb`. Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1664 text-iterators module has been renamed text-utils to better reflect its content.
This commit is contained in:
parent
2eb02c5adc
commit
cb72211795
|
@ -28,7 +28,7 @@ import './lib/punycode.js';
|
|||
|
||||
import globals from './js/globals.js';
|
||||
import { FilteringContext } from './js/filtering-context.js';
|
||||
import { LineIterator } from './js/text-iterators.js';
|
||||
import { LineIterator } from './js/text-utils.js';
|
||||
import { StaticFilteringParser } from './js/static-filtering-parser.js';
|
||||
import { staticNetFilteringEngine } from './js/static-net-filtering.js';
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import './lib/publicsuffixlist/publicsuffixlist.js';
|
|||
import globals from './js/globals.js';
|
||||
import snfe from './js/static-net-filtering.js';
|
||||
import { FilteringContext } from './js/filtering-context.js';
|
||||
import { LineIterator } from './js/text-iterators.js';
|
||||
import { LineIterator } from './js/text-utils.js';
|
||||
import { StaticFilteringParser } from './js/static-filtering-parser.js';
|
||||
|
||||
import {
|
||||
|
|
|
@ -30,8 +30,8 @@ import scriptletFilteringEngine from './scriptlet-filtering.js';
|
|||
import staticNetFilteringEngine from './static-net-filtering.js';
|
||||
import µb from './background.js';
|
||||
import { FilteringContext } from './filtering-context.js';
|
||||
import { LineIterator } from './text-utils.js';
|
||||
import { sessionFirewall } from './dynamic-net-filtering.js';
|
||||
import { LineIterator } from './text-iterators.js';
|
||||
|
||||
import {
|
||||
domainFromHostname,
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
import '../lib/punycode.js';
|
||||
|
||||
import globals from './globals.js';
|
||||
import { LineIterator } from './text-iterators.js';
|
||||
import { LineIterator } from './text-utils.js';
|
||||
|
||||
import {
|
||||
decomposeHostname,
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
import '../lib/punycode.js';
|
||||
|
||||
import globals from './globals.js';
|
||||
import { LineIterator } from './text-iterators.js';
|
||||
import { LineIterator } from './text-utils.js';
|
||||
import { decomposeHostname } from './uri-utils.js';
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -27,6 +27,7 @@ import contextMenu from './contextmenu.js';
|
|||
import logger from './logger.js';
|
||||
import staticNetFilteringEngine from './static-net-filtering.js';
|
||||
import µb from './background.js';
|
||||
import { orphanizeString } from './text-utils.js';
|
||||
import { redirectEngine } from './redirect-engine.js';
|
||||
import { sessionFirewall } from './dynamic-net-filtering.js';
|
||||
import { sessionSwitches } from './hnswitches.js';
|
||||
|
@ -468,7 +469,7 @@ const PageStore = class {
|
|||
) {
|
||||
return false;
|
||||
}
|
||||
this.title = µb.orphanizeString(details.title.slice(0, 128));
|
||||
this.title = orphanizeString(details.title.slice(0, 128));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,11 @@
|
|||
/******************************************************************************/
|
||||
|
||||
import io from './assets.js';
|
||||
import µb from './background.js';
|
||||
import { LineIterator } from './text-iterators.js';
|
||||
|
||||
import {
|
||||
LineIterator,
|
||||
orphanizeString,
|
||||
} from './text-utils.js';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
@ -409,7 +412,7 @@ RedirectEngine.prototype.resourcesFromString = function(text) {
|
|||
// No more data, add the resource.
|
||||
const name = this.aliases.get(fields[0]) || fields[0];
|
||||
const mime = fields[1];
|
||||
const content = µb.orphanizeString(
|
||||
const content = orphanizeString(
|
||||
fields.slice(2).join(encoded ? '' : '\n')
|
||||
);
|
||||
this.resources.set(
|
||||
|
|
|
@ -36,7 +36,6 @@ import staticFilteringReverseLookup from './reverselookup.js';
|
|||
import staticNetFilteringEngine from './static-net-filtering.js';
|
||||
import µb from './background.js';
|
||||
import { hostnameFromURI } from './uri-utils.js';
|
||||
import { LineIterator } from './text-iterators.js';
|
||||
import { permanentFirewall } from './dynamic-net-filtering.js';
|
||||
import { permanentSwitches } from './hnswitches.js';
|
||||
import { permanentURLFiltering } from './url-net-filtering.js';
|
||||
|
@ -50,6 +49,11 @@ import {
|
|||
CompiledListWriter,
|
||||
} from './static-filtering-io.js';
|
||||
|
||||
import {
|
||||
LineIterator,
|
||||
orphanizeString,
|
||||
} from './text-utils.js';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µb.getBytesInUse = async function() {
|
||||
|
@ -898,10 +902,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
|
||||
// https://github.com/gorhill/uBlock/issues/3406
|
||||
// Lower minimum update period to 1 day.
|
||||
// https://bugs.chromium.org/p/v8/issues/detail?id=2869
|
||||
// orphanizeString is to work around String.slice() potentially causing
|
||||
// the whole raw filter list to be held in memory just because we cut out
|
||||
// the title as a substring.
|
||||
|
||||
µb.extractFilterListMetadata = function(assetKey, raw) {
|
||||
const listEntry = this.availableFilterLists[assetKey];
|
||||
|
@ -914,13 +914,13 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
let matches = head.match(/(?:^|\n)(?:!|# )[\t ]*Title[\t ]*:([^\n]+)/i);
|
||||
const title = matches && matches[1].trim() || '';
|
||||
if ( title !== '' && title !== listEntry.title ) {
|
||||
listEntry.title = this.orphanizeString(title);
|
||||
listEntry.title = orphanizeString(title);
|
||||
io.registerAssetSource(assetKey, { title });
|
||||
}
|
||||
matches = head.match(/(?:^|\n)(?:!|# )[\t ]*Homepage[\t ]*:[\t ]*(https?:\/\/\S+)\s/i);
|
||||
const supportURL = matches && matches[1] || '';
|
||||
if ( supportURL !== '' && supportURL !== listEntry.supportURL ) {
|
||||
listEntry.supportURL = this.orphanizeString(supportURL);
|
||||
listEntry.supportURL = orphanizeString(supportURL);
|
||||
io.registerAssetSource(assetKey, { supportURL });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,17 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
// https://bugs.chromium.org/p/v8/issues/detail?id=2869
|
||||
// orphanizeString is to work around String.slice() potentially causing
|
||||
// the whole raw filter list to be held in memory just because we cut out
|
||||
// the title as a substring.
|
||||
|
||||
function orphanizeString(s) {
|
||||
return JSON.parse(JSON.stringify(s));
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
class LineIterator {
|
||||
constructor(text, offset) {
|
||||
this.text = text;
|
||||
|
@ -89,4 +100,8 @@ class FieldIterator {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
export { LineIterator, FieldIterator };
|
||||
export {
|
||||
FieldIterator,
|
||||
LineIterator,
|
||||
orphanizeString,
|
||||
};
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
import { LineIterator } from './text-iterators.js';
|
||||
import { LineIterator } from './text-utils.js';
|
||||
import { decomposeHostname } from './uri-utils.js';
|
||||
|
||||
/*******************************************************************************
|
||||
|
|
|
@ -141,14 +141,6 @@ import µb from './background.js';
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
// TODO: evaluate using TextEncoder/TextDecoder
|
||||
|
||||
µb.orphanizeString = function(s) {
|
||||
return JSON.parse(JSON.stringify(s));
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µb.fireDOMEvent = function(name) {
|
||||
if (
|
||||
window instanceof Object &&
|
||||
|
|
Loading…
Reference in New Issue