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

Side by Side Diff: lib/filterValidation.js

Issue 29723558: Issue 6482 - Use ES6 classes (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created March 15, 2018, 7:46 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 21
22 const {Filter, InvalidFilter, ElemHideBase, ElemHideEmulationFilter} = 22 const {Filter, InvalidFilter, ElemHideBase, ElemHideEmulationFilter} =
23 require("filterClasses"); 23 require("filterClasses");
24 24
25 /** 25 /**
26 * An error returned by 26 * An error returned by
27 * {@link module:filterValidation.parseFilter parseFilter()} or 27 * {@link module:filterValidation.parseFilter parseFilter()} or
28 * {@link module:filterValidation.parseFilters parseFilters()} 28 * {@link module:filterValidation.parseFilters parseFilters()}
29 * indicating that a given filter cannot be parsed, 29 * indicating that a given filter cannot be parsed,
30 * contains an invalid CSS selector or is a filter list header. 30 * contains an invalid CSS selector or is a filter list header.
31 *
Manish Jethani 2018/03/15 07:54:11 See http://usejsdoc.org/howto-es2015-classes.html
32 * @param {string} type See documentation in the constructor below.
33 * @param {Object} [details] Contains the "reason" and / or "selector"
34 * properties.
35 * @constructor
36 */ 31 */
37 function FilterParsingError(type, details) 32 class FilterParsingError
38 { 33 {
39 /** 34 /**
40 * Indicates why the filter is rejected. Possible choices: 35 * @param {string} type See documentation in the constructor below.
41 * "invalid-filter", "invalid-css-selector", "unexpected-filter-list-header" 36 * @param {Object} [details] Contains the "reason" and / or "selector"
42 * 37 * properties.
43 * @type {string}
44 */ 38 */
45 this.type = type; 39 constructor(type, details)
40 {
41 /**
42 * Indicates why the filter is rejected. Possible choices:
43 * "invalid-filter", "invalid-css-selector", "unexpected-filter-list-header"
44 *
45 * @type {string}
46 */
47 this.type = type;
46 48
47 if (details) 49 /**
48 { 50 * The line number the error occurred on if
49 if ("reason" in details) 51 * {@link module:filterValidation.parseFilters parseFilters()}
50 this.reason = details.reason; 52 * were used. Or null if the error was returned by
51 if ("selector" in details) 53 * {@link module:filterValidation.parseFilter parseFilter()}.
52 this.selector = details.selector; 54 *
55 * @type {?number}
56 */
57 this.lineno = null;
58
59 if (details)
60 {
61 if ("reason" in details)
62 this.reason = details.reason;
63 if ("selector" in details)
64 this.selector = details.selector;
65 }
53 } 66 }
54 }
55 FilterParsingError.prototype = {
56 /**
57 * The line number the error occurred on if
58 * {@link module:filterValidation.parseFilters parseFilters()}
59 * were used. Or null if the error was returned by
60 * {@link module:filterValidation.parseFilter parseFilter()}.
61 *
62 * @type {?number}
63 */
64 lineno: null,
Manish Jethani 2018/03/15 07:54:11 Again, there's no real need for this to live on th
65 67
66 /** 68 /**
67 * Returns a detailed translated error message. 69 * Returns a detailed translated error message.
68 * 70 *
69 * @return {string} 71 * @return {string}
70 */ 72 */
71 toString() 73 toString()
72 { 74 {
73 let message; 75 let message;
74 if (this.reason) 76 if (this.reason)
75 message = browser.i18n.getMessage(this.reason); 77 message = browser.i18n.getMessage(this.reason);
76 else 78 else
77 { 79 {
78 message = browser.i18n.getMessage( 80 message = browser.i18n.getMessage(
79 this.type.replace(/-/g, "_"), 81 this.type.replace(/-/g, "_"),
80 "selector" in this ? "'" + this.selector + "'" : null 82 "selector" in this ? "'" + this.selector + "'" : null
81 ); 83 );
82 } 84 }
83 85
84 if (this.lineno) 86 if (this.lineno)
85 { 87 {
86 message = browser.i18n.getMessage( 88 message = browser.i18n.getMessage(
87 "line", this.lineno.toLocaleString() 89 "line", this.lineno.toLocaleString()
88 ) + ": " + message; 90 ) + ": " + message;
89 } 91 }
90 return message; 92 return message;
91 } 93 }
92 }; 94 }
93 95
94 function isValidCSSSelector(selector) 96 function isValidCSSSelector(selector)
95 { 97 {
96 let style = document.createElement("style"); 98 let style = document.createElement("style");
97 document.documentElement.appendChild(style); 99 document.documentElement.appendChild(style);
98 let {sheet} = style; 100 let {sheet} = style;
99 document.documentElement.removeChild(style); 101 document.documentElement.removeChild(style);
100 102
101 try 103 try
102 { 104 {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 185
184 if (error) 186 if (error)
185 { 187 {
186 error.lineno = i + 1; 188 error.lineno = i + 1;
187 errors.push(error); 189 errors.push(error);
188 } 190 }
189 } 191 }
190 192
191 return {filters, errors}; 193 return {filters, errors};
192 }; 194 };
OLDNEW
« lib/compat.js ('K') | « lib/compat.js ('k') | lib/messaging.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld