Ensure CSSTree does not hold onto last parsed string · gorhill/uBlock@1dba557 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit 1dba557

Browse files
committed
Ensure CSSTree does not hold onto last parsed string
When done compiling, force CSSTree to parse an empty string, so as to ensure it doesn't keep a reference to that string. Typically, the string passed to CSSTree is a small slice of a larger string which is a whole filter list. This means that holding a reference to the sliced string causes the JS engine to hold in memory to the whole filter list last parsed.
1 parent f7511cc commit 1dba557

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/js/static-filtering-parser.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,10 @@ export class AstFilterParser {
908908
this.scriptletArgListParser = new ArgListParser(',');
909909
}
910910

911+
finish() {
912+
this.selectorCompiler.finish();
913+
}
914+
911915
parse(raw) {
912916
this.raw = raw;
913917
this.rawEnd = raw.length;
@@ -3229,6 +3233,14 @@ class ExtSelectorCompiler {
32293233
this.error = undefined;
32303234
}
32313235

3236+
// CSSTree library holds onto last string parsed, and this is problematic
3237+
// when the string is a slice of a huge parent string (typically a whole
3238+
// filter lists), it causes the huge parent string to stay in memory.
3239+
// Asking CSSTree to parse an empty string resolves this issue.
3240+
finish() {
3241+
cssTree.parse('');
3242+
}
3243+
32323244
compile(raw, out, compileOptions = {}) {
32333245
this.asProcedural = compileOptions.asProcedural === true;
32343246

src/js/storage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ import {
11021102
}
11031103

11041104
compiler.finish(writer);
1105+
parser.finish();
11051106

11061107
// https://github.com/uBlockOrigin/uBlock-issues/issues/1365
11071108
// Embed version into compiled list itself: it is encoded in as the

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.