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

Delta Between Two Patch Sets: lib/content/elemHideEmulation.js

Issue 29676761: Issue 6296 - Handle relative prefix in :-abp-has() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Rework the query selector all Created Jan. 25, 2018, 9:58 p.m.
Right Patch Set: No longer use regexp for relative selector. Created Jan. 30, 2018, 4:03 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | test/browser/elemHideEmulation.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 { 128 {
129 let elements = null; 129 let elements = null;
130 try 130 try
131 { 131 {
132 elements = all ? subtree.querySelectorAll(selector) : 132 elements = all ? subtree.querySelectorAll(selector) :
133 subtree.querySelector(selector); 133 subtree.querySelector(selector);
134 scopeSupported = true; 134 scopeSupported = true;
135 } 135 }
136 catch (e) 136 catch (e)
137 { 137 {
138 // Edge doesn't support ":scope"
138 scopeSupported = false; 139 scopeSupported = false;
139 } 140 }
140 return elements; 141 return elements;
141 } 142 }
142 143
143 /** 144 /**
144 * Query selector. If it is relative, will try :scoped. 145 * Query selector. If it is relative, will try :scope.
145 * @param {Node} subtree the element to query selector 146 * @param {Node} subtree the element to query selector
146 * @param {string} selector the selector to query 147 * @param {string} selector the selector to query
147 * @param {bool} all True to perform querySelectorAll() 148 * @param {bool} [all=false] true to perform querySelectorAll()
148 * @returns {Node|NodeList} result of the query. null in case of error. 149 * @returns {?(Node|NodeList)} result of the query. null in case of error.
149 */ 150 */
150 function scopedQuerySelector(subtree, selector, all) 151 function scopedQuerySelector(subtree, selector, all)
151 { 152 {
152 if (relativeSelectorRegexp.test(selector)) 153 if (selector[0] == ">")
153 { 154 {
154 selector = ":scope" + selector; 155 selector = ":scope" + selector;
155 if (scopeSupported) 156 if (scopeSupported)
Manish Jethani 2018/01/26 08:41:32 I think since the code in this if block spans mult
hub 2018/01/26 14:44:45 Done.
157 {
156 return all ? subtree.querySelectorAll(selector) : 158 return all ? subtree.querySelectorAll(selector) :
157 subtree.querySelector(selector); 159 subtree.querySelector(selector);
160 }
158 if (scopeSupported == null) 161 if (scopeSupported == null)
159 return tryQuerySelector(subtree, selector, all); 162 return tryQuerySelector(subtree, selector, all);
160 return null; 163 return null;
161 } 164 }
162 return all ? subtree.querySelectorAll(selector) : 165 return all ? subtree.querySelectorAll(selector) :
163 subtree.querySelector(selector); 166 subtree.querySelector(selector);
164 } 167 }
165 168
166 function scopedQuerySelectorAll(subtree, selector) 169 function scopedQuerySelectorAll(subtree, selector)
167 { 170 {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 * @param {string} prefix the prefix for the selector. 204 * @param {string} prefix the prefix for the selector.
202 * @param {Node} subtree the subtree we work on. 205 * @param {Node} subtree the subtree we work on.
203 * @param {StringifiedStyle[]} styles the stringified style objects. 206 * @param {StringifiedStyle[]} styles the stringified style objects.
204 */ 207 */
205 *getSelectors(prefix, subtree, styles) 208 *getSelectors(prefix, subtree, styles)
206 { 209 {
207 yield [prefix + this._selector, subtree]; 210 yield [prefix + this._selector, subtree];
208 } 211 }
209 }; 212 };
210 213
211 const incompletePrefixRegexp = /[\s>+~]$/; 214 const incompletePrefixRegexp = /[\s>+~]$/;
lainverse 2018/01/30 18:07:28 Since that other regexp were replaced with string
Manish Jethani 2018/01/30 20:23:20 If we do this then I think that it should be a sep
212 const relativeSelectorRegexp = /^[>]/;
Manish Jethani 2018/01/26 08:41:32 Since there's only one character in the group, we
hub 2018/01/26 14:44:45 Done.
213 215
214 function HasSelector(selectors) 216 function HasSelector(selectors)
215 { 217 {
216 this._innerSelectors = selectors; 218 this._innerSelectors = selectors;
217 } 219 }
218 220
219 HasSelector.prototype = { 221 HasSelector.prototype = {
220 requiresHiding: true, 222 requiresHiding: true,
221 223
222 get dependsOnStyles() 224 get dependsOnStyles()
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 characterData: true, 646 characterData: true,
645 subtree: true 647 subtree: true
646 } 648 }
647 ); 649 );
648 this.document.addEventListener("load", this.onLoad.bind(this), true); 650 this.document.addEventListener("load", this.onLoad.bind(this), true);
649 } 651 }
650 } 652 }
651 }; 653 };
652 654
653 exports.ElemHideEmulation = ElemHideEmulation; 655 exports.ElemHideEmulation = ElemHideEmulation;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld