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

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

Issue 29464703: Issue 5313 - Make error reporting more robust. (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created June 14, 2017, 2:50 a.m.
Right Patch Set: addressed nits Created June 19, 2017, 1:24 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 | no next file » | 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 279 }
280 catch (e) 280 catch (e)
281 { 281 {
282 // Invalid URL, assume that it is first-party. 282 // Invalid URL, assume that it is first-party.
283 return true; 283 return true;
284 } 284 }
285 }, 285 },
286 286
287 /** Parse the selector 287 /** Parse the selector
288 * @param {string} selector the selector to parse 288 * @param {string} selector the selector to parse
289 * @return {Object} selectors is an array of objects, 289 * @return {Array} selectors is an array of objects,
290 * or null in case of errors. hide is true if we'll hide 290 * or null in case of errors.
291 * elements instead of styles..
292 */ 291 */
293 parseSelector(selector) 292 parseSelector(selector)
294 { 293 {
295 if (selector.length == 0) 294 if (selector.length == 0)
296 return []; 295 return [];
297 296
298 let match = abpSelectorRegexp.exec(selector); 297 let match = abpSelectorRegexp.exec(selector);
299 if (!match) 298 if (!match)
300 return [new PlainSelector(selector)]; 299 return [new PlainSelector(selector)];
301 300
302 let selectors = []; 301 let selectors = [];
303 if (match.index > 0) 302 if (match.index > 0)
304 selectors.push(new PlainSelector(selector.substr(0, match.index))); 303 selectors.push(new PlainSelector(selector.substr(0, match.index)));
305 304
306 let startIndex = match.index + match[0].length; 305 let startIndex = match.index + match[0].length;
307 let content = parseSelectorContent(selector, startIndex); 306 let content = parseSelectorContent(selector, startIndex);
308 if (!content) 307 if (!content)
309 { 308 {
310 this.window.console.error( 309 this.window.console.error(
311 new SyntaxError("Failed to parse Adblock Plus " + 310 new SyntaxError("Failed to parse Adblock Plus " +
312 `selector ${selector}, ` + 311 `selector ${selector} ` +
313 "due to unmatched parentheses.")); 312 "due to unmatched parentheses."));
314 return null; 313 return null;
315 } 314 }
316 if (match[1] == "properties") 315 if (match[1] == "properties")
317 selectors.push(new PropsSelector(content.text)); 316 selectors.push(new PropsSelector(content.text));
318 else if (match[1] == "has") 317 else if (match[1] == "has")
319 { 318 {
320 let hasSelectors = this.parseSelector(content.text); 319 let hasSelectors = this.parseSelector(content.text);
321 if (hasSelectors == null) 320 if (hasSelectors == null)
322 return null; 321 return null;
323 let hasSelector = new HasSelector(hasSelectors); 322 selectors.push(new HasSelector(hasSelectors));
324 selectors.push(hasSelector);
325 } 323 }
326 else 324 else
327 { 325 {
328 // this is an error, can't parse selector. 326 // this is an error, can't parse selector.
329 this.window.console.error( 327 this.window.console.error(
330 new SyntaxError("Failed to parse Adblock Plus " + 328 new SyntaxError("Failed to parse Adblock Plus " +
331 `selector ${selector}, invalid ` + 329 `selector ${selector}, invalid ` +
332 `pseudo-class :-abp-${match[1]}().`)); 330 `pseudo-class :-abp-${match[1]}().`));
333 return null; 331 return null;
334 } 332 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 417
420 if (this.patterns.length > 0) 418 if (this.patterns.length > 0)
421 { 419 {
422 let {document} = this.window; 420 let {document} = this.window;
423 this.addSelectors(document.styleSheets); 421 this.addSelectors(document.styleSheets);
424 document.addEventListener("load", this.onLoad.bind(this), true); 422 document.addEventListener("load", this.onLoad.bind(this), true);
425 } 423 }
426 }); 424 });
427 } 425 }
428 }; 426 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld