Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/content/elemHideEmulation.js

Issue 29676761: Issue 6296 - Handle relative prefix in :-abp-has() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Jan. 22, 2018, 9:20 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/browser/elemHideEmulation.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/content/elemHideEmulation.js
===================================================================
--- a/lib/content/elemHideEmulation.js
+++ b/lib/content/elemHideEmulation.js
@@ -189,40 +189,49 @@
* @param {string} prefix the prefix for the selector.
* @param {Node} subtree the subtree we work on.
* @param {StringifiedStyle[]} styles the stringified style objects.
*/
*getElements(prefix, subtree, styles)
{
let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ?
prefix + "*" : prefix;
- let elements = subtree.querySelectorAll(actualPrefix);
- for (let element of elements)
+ if (relativeSelectorRegexp.test(actualPrefix))
Manish Jethani 2018/01/23 16:42:11 If I understand this correctly, "+" and "~" don't
hub 2018/01/25 21:58:34 Done.
+ actualPrefix = ":scope" + actualPrefix;
+ try
{
- let iter = evaluate(this._innerSelectors, 0, "", element, styles);
- for (let selector of iter)
+ let elements = subtree.querySelectorAll(actualPrefix);
lainverse 2018/01/23 01:02:51 As I understand if this fails it's still possible
Manish Jethani 2018/01/23 16:42:11 I agree this could probably be made to work on Edg
hub 2018/01/23 16:51:11 Filed https://issues.adblockplus.org/ticket/6304
+ for (let element of elements)
{
- if (selector == null)
+ let iter = evaluate(this._innerSelectors, 0, "", element, styles);
+ for (let selector of iter)
{
- yield null;
- continue;
+ if (selector == null)
+ {
+ yield null;
+ continue;
+ }
+ if (relativeSelectorRegexp.test(selector))
Manish Jethani 2018/01/23 16:42:11 So this and the try..catch could be made generic a
hub 2018/01/25 21:58:34 This should allow us to fix issue #6304 more easil
+ selector = ":scope" + selector;
+ try
+ {
+ if (element.querySelector(selector))
+ yield element;
+ }
+ catch (e)
+ {
+ // :scope isn't supported on Edge, ignore error caused by it.
+ }
}
- if (relativeSelectorRegexp.test(selector))
- selector = ":scope" + selector;
- try
- {
- if (element.querySelector(selector))
- yield element;
- }
- catch (e)
- {
- // :scope isn't supported on Edge, ignore error caused by it.
- }
+ yield null;
}
- yield null;
+ }
+ catch (e)
+ {
+ // :scope isn't supported on Edge, ignore error caused by it.
}
}
};
function ContainsSelector(textContent)
{
this._text = textContent;
}
@@ -235,24 +244,33 @@
for (let element of this.getElements(prefix, subtree, stylesheet))
yield [makeSelector(element, ""), subtree];
},
*getElements(prefix, subtree, stylesheet)
{
let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ?
prefix + "*" : prefix;
- let elements = subtree.querySelectorAll(actualPrefix);
-
- for (let element of elements)
+ if (relativeSelectorRegexp.test(actualPrefix))
+ actualPrefix = ":scope" + actualPrefix;
+ try
{
- if (element.textContent.includes(this._text))
- yield element;
- else
- yield null;
+ let elements = subtree.querySelectorAll(actualPrefix);
+
+ for (let element of elements)
+ {
+ if (element.textContent.includes(this._text))
+ yield element;
+ else
+ yield null;
+ }
+ }
+ catch (e)
+ {
+ // :scope isn't supported on Edge, ignore error caused by it.
}
}
};
function PropsSelector(propertyExpression)
{
let regexpString;
if (propertyExpression.length >= 2 && propertyExpression[0] == "/" &&
« no previous file with comments | « no previous file | test/browser/elemHideEmulation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld