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

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

Issue 29460576: Issue 5079 - Turn elemHideEmulation into a CommonJS module (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Updated patch. Fails for now Created Aug. 10, 2017, 2:42 p.m.
Right Patch Set: Rebased on master Created Aug. 10, 2017, 2:44 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 | « lib/common.js ('k') | 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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 else if (sep == "") 43 else if (sep == "")
44 { 44 {
45 if (chr == '"' || chr == "'") 45 if (chr == '"' || chr == "'")
46 sep = chr; 46 sep = chr;
47 else if (chr == "(") // don't split between parentheses 47 else if (chr == "(") // don't split between parentheses
48 level++; // e.g. :matches(div,span) 48 level++; // e.g. :matches(div,span)
49 else if (chr == ")") 49 else if (chr == ")")
50 level = Math.max(0, level - 1); 50 level = Math.max(0, level - 1);
51 else if (chr == "," && level == 0) 51 else if (chr == "," && level == 0)
52 { 52 {
53 selectors.push(selector.substring(start, i).trim()); 53 selectors.push(selector.substring(start, i));
54 start = i + 1; 54 start = i + 1;
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 selectors.push(selector.substring(start).trim()); 59 selectors.push(selector.substring(start));
60 return selectors; 60 return selectors;
61 } 61 }
62 62
63 /** Return position of node from parent. 63 /** Return position of node from parent.
64 * @param {Node} node the node to find the position of. 64 * @param {Node} node the node to find the position of.
65 * @return {number} One-based index like for :nth-child(), or 0 on error. 65 * @return {number} One-based index like for :nth-child(), or 0 on error.
66 */ 66 */
67 function positionInParent(node) 67 function positionInParent(node)
68 { 68 {
69 let {children} = node.parentNode; 69 let {children} = node.parentNode;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 * @param {Node} subtree the subtree we work on. 182 * @param {Node} subtree the subtree we work on.
183 * @param {StringifiedStyle[]} styles the stringified style objects. 183 * @param {StringifiedStyle[]} styles the stringified style objects.
184 */ 184 */
185 *getSelectors(prefix, subtree, styles) 185 *getSelectors(prefix, subtree, styles)
186 { 186 {
187 yield [prefix + this._selector, subtree]; 187 yield [prefix + this._selector, subtree];
188 } 188 }
189 }; 189 };
190 190
191 const incompletePrefixRegexp = /[\s>+~]$/; 191 const incompletePrefixRegexp = /[\s>+~]$/;
192 const relativeSelector = /^[\s>+~]/;
193 192
194 function HasSelector(selectors) 193 function HasSelector(selectors)
195 { 194 {
196 this._innerSelectors = selectors; 195 this._innerSelectors = selectors;
197 } 196 }
198 197
199 HasSelector.prototype = { 198 HasSelector.prototype = {
200 requiresHiding: true, 199 requiresHiding: true,
201 200
202 get dependsOnStyles() 201 get dependsOnStyles()
(...skipping 15 matching lines...) Expand all
218 */ 217 */
219 *getElements(prefix, subtree, styles) 218 *getElements(prefix, subtree, styles)
220 { 219 {
221 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? 220 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ?
222 prefix + "*" : prefix; 221 prefix + "*" : prefix;
223 let elements = subtree.querySelectorAll(actualPrefix); 222 let elements = subtree.querySelectorAll(actualPrefix);
224 for (let element of elements) 223 for (let element of elements)
225 { 224 {
226 let iter = evaluate(this._innerSelectors, 0, "", element, styles); 225 let iter = evaluate(this._innerSelectors, 0, "", element, styles);
227 for (let selector of iter) 226 for (let selector of iter)
228 {
229 if (relativeSelector.test(selector))
230 selector = ":scope" + selector;
231 if (element.querySelector(selector)) 227 if (element.querySelector(selector))
232 yield element; 228 yield element;
233 }
234 } 229 }
235 } 230 }
236 }; 231 };
237 232
238 function ContainsSelector(textContent) 233 function ContainsSelector(textContent)
239 { 234 {
240 this._text = textContent; 235 this._text = textContent;
241 } 236 }
242 237
243 ContainsSelector.prototype = { 238 ContainsSelector.prototype = {
(...skipping 30 matching lines...) Expand all
274 269
275 this._regexp = new RegExp(regexpString, "i"); 270 this._regexp = new RegExp(regexpString, "i");
276 } 271 }
277 272
278 PropsSelector.prototype = { 273 PropsSelector.prototype = {
279 preferHideWithSelector: true, 274 preferHideWithSelector: true,
280 dependsOnStyles: true, 275 dependsOnStyles: true,
281 276
282 *findPropsSelectors(styles, prefix, regexp) 277 *findPropsSelectors(styles, prefix, regexp)
283 { 278 {
284 let actualPrefix = (prefix && !incompletePrefixRegexp.test(prefix)) ?
285 prefix + " " : prefix;
286 for (let style of styles) 279 for (let style of styles)
287 if (regexp.test(style.style)) 280 if (regexp.test(style.style))
288 for (let subSelector of style.subSelectors) 281 for (let subSelector of style.subSelectors)
289 { 282 {
290 if (subSelector == "*") 283 let idx = subSelector.lastIndexOf("::");
291 subSelector = ""; 284 if (idx != -1)
292 else 285 subSelector = subSelector.substr(0, idx);
293 { 286 yield prefix + subSelector;
294 let idx = subSelector.lastIndexOf("::");
295 if (idx != -1)
296 subSelector = subSelector.substr(0, idx);
297 }
298 yield actualPrefix + subSelector;
299 } 287 }
300 }, 288 },
301 289
302 *getSelectors(prefix, subtree, styles) 290 *getSelectors(prefix, subtree, styles)
303 { 291 {
304 for (let selector of this.findPropsSelectors(styles, prefix, this._regexp)) 292 for (let selector of this.findPropsSelectors(styles, prefix, this._regexp))
305 yield [selector, subtree]; 293 yield [selector, subtree];
306 } 294 }
307 }; 295 };
308 296
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 { 507 {
520 let {document} = this.window; 508 let {document} = this.window;
521 this.addSelectors(); 509 this.addSelectors();
522 document.addEventListener("load", this.onLoad.bind(this), true); 510 document.addEventListener("load", this.onLoad.bind(this), true);
523 } 511 }
524 }); 512 });
525 } 513 }
526 }; 514 };
527 515
528 exports.ElemHideEmulation = ElemHideEmulation; 516 exports.ElemHideEmulation = ElemHideEmulation;
529 exports.splitSelector = splitSelector; 517 exports.splitSelector = splitSelector;
Wladimir Palant 2017/08/16 09:55:53 This shouldn't export splitSelector. If we need th
kzar 2017/08/16 09:59:05 Acknowledged, OK I'll move that over while I'm at
LEFTRIGHT

Powered by Google App Engine
This is Rietveld