Fix test for stylesheet presence

Related commit:
- 4f923384de
This commit is contained in:
Raymond Hill 2021-10-27 15:13:13 -04:00
parent 6722616e28
commit 97a33c9572
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 4 additions and 1 deletions

View File

@ -1442,13 +1442,16 @@ Parser.prototype.SelectorCompiler = class {
// https://github.com/gorhill/uBlock/issues/3111 // https://github.com/gorhill/uBlock/issues/3111
// Workaround until https://bugzilla.mozilla.org/show_bug.cgi?id=1406817 // Workaround until https://bugzilla.mozilla.org/show_bug.cgi?id=1406817
// is fixed. // is fixed.
// https://github.com/uBlockOrigin/uBlock-issues/issues/1751
// Do not rely on matches() or querySelector() to test whether a
// selector is declarative or not.
cssSelectorType(s) { cssSelectorType(s) {
if ( this.reSimpleSelector.test(s) ) { return 1; } if ( this.reSimpleSelector.test(s) ) { return 1; }
const pos = this.cssPseudoElement(s); const pos = this.cssPseudoElement(s);
if ( pos !== -1 ) { if ( pos !== -1 ) {
return this.cssSelectorType(s.slice(0, pos)) === 1 ? 3 : 0; return this.cssSelectorType(s.slice(0, pos)) === 1 ? 3 : 0;
} }
if ( this.div === null ) { return 1; } if ( this.stylesheet === null ) { return 1; }
try { try {
this.stylesheet.insertRule(`${s}{color:red}`); this.stylesheet.insertRule(`${s}{color:red}`);
if ( this.stylesheet.cssRules.length === 0 ) { return 0; } if ( this.stylesheet.cssRules.length === 0 ) { return 0; }