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

Delta Between Two Patch Sets: lib/subscriptionClasses.js

Issue 29375915: Issue 4878 - Start using ESLint for adblockpluscore (Closed)
Left Patch Set: Rebased. Created Feb. 28, 2017, 3:55 p.m.
Right Patch Set: Removed unused imports Created March 15, 2017, 3:11 a.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/rsa.js ('k') | lib/synchronizer.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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 }; 153 };
154 154
155 /** 155 /**
156 * Cache for known filter subscriptions, maps URL to subscription objects. 156 * Cache for known filter subscriptions, maps URL to subscription objects.
157 * @type {Object} 157 * @type {Object}
158 */ 158 */
159 Subscription.knownSubscriptions = Object.create(null); 159 Subscription.knownSubscriptions = Object.create(null);
160 160
161 /** 161 /**
162 * Returns a subscription from its URL, creates a new one if necessary. 162 * Returns a subscription from its URL, creates a new one if necessary.
163 * @param {string} url URL of the subscription 163 * @param {string} url
164 * @return {Subscription} subscription or null if the subscription couldn't be 164 * URL of the subscription
165 * created 165 * @return {Subscription}
Wladimir Palant 2017/03/02 14:07:05 Messy indentation here.
kzar 2017/03/08 12:33:50 Done.
166 * subscription or null if the subscription couldn't be created
166 */ 167 */
167 Subscription.fromURL = function(url) 168 Subscription.fromURL = function(url)
168 { 169 {
169 if (url in Subscription.knownSubscriptions) 170 if (url in Subscription.knownSubscriptions)
170 return Subscription.knownSubscriptions[url]; 171 return Subscription.knownSubscriptions[url];
171 172
172 if (url[0] != "~") 173 if (url[0] != "~")
173 return new DownloadableSubscription(url, null); 174 return new DownloadableSubscription(url, null);
174 return new SpecialSubscription(url); 175 return new SpecialSubscription(url);
175 }; 176 };
176 177
177 /** 178 /**
178 * Deserializes a subscription 179 * Deserializes a subscription
179 * 180 *
180 * @param {Object} obj map of serialized properties and their values 181 * @param {Object} obj
181 * @return {Subscription} subscription or null if the subscription couldn't be 182 * map of serialized properties and their values
182 * created 183 * @return {Subscription}
Wladimir Palant 2017/03/02 14:07:05 Messy indentation here.
kzar 2017/03/08 12:33:50 Done.
184 * subscription or null if the subscription couldn't be created
183 */ 185 */
184 Subscription.fromObject = function(obj) 186 Subscription.fromObject = function(obj)
185 { 187 {
186 let result; 188 let result;
187 if (obj.url[0] != "~") 189 if (obj.url[0] != "~")
188 { 190 {
189 // URL is valid - this is a downloadable subscription 191 // URL is valid - this is a downloadable subscription
190 result = new DownloadableSubscription(obj.url, obj.title); 192 result = new DownloadableSubscription(obj.url, obj.title);
191 if ("downloadStatus" in obj) 193 if ("downloadStatus" in obj)
192 result._downloadStatus = obj.downloadStatus; 194 result._downloadStatus = obj.downloadStatus;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 if (!(filter instanceof ActiveFilter) && type == "blacklist") 264 if (!(filter instanceof ActiveFilter) && type == "blacklist")
263 return true; 265 return true;
264 } 266 }
265 } 267 }
266 268
267 return false; 269 return false;
268 }, 270 },
269 271
270 /** 272 /**
271 * See Subscription.serialize() 273 * See Subscription.serialize()
272 * @param {string[]} buffer buffer to push the serialization results into 274 * @inheritdoc
Wladimir Palant 2017/03/02 14:07:04 Please don't duplicate this documentation all over
kzar 2017/03/08 12:33:53 OK but now we're getting ESLint errors "Missing JS
Wladimir Palant 2017/03/09 14:37:11 What if you use @inheritDoc here?
kzar 2017/03/10 06:56:12 Done.
273 */ 275 */
274 serialize(buffer) 276 serialize(buffer)
275 { 277 {
276 Subscription.prototype.serialize.call(this, buffer); 278 Subscription.prototype.serialize.call(this, buffer);
277 if (this.defaults && this.defaults.length) 279 if (this.defaults && this.defaults.length)
278 { 280 {
279 buffer.push("defaults=" + this.defaults.filter( 281 buffer.push("defaults=" +
Wladimir Palant 2017/03/02 14:07:04 Please move everything after "defaults=" to the ne
kzar 2017/03/08 12:33:51 Done.
280 type => type in SpecialSubscription.defaultsMap).join(" ") 282 this.defaults.filter(
283 type => type in SpecialSubscription.defaultsMap
284 ).join(" ")
281 ); 285 );
282 } 286 }
283 if (this._lastDownload) 287 if (this._lastDownload)
284 buffer.push("lastDownload=" + this._lastDownload); 288 buffer.push("lastDownload=" + this._lastDownload);
285 } 289 }
286 }); 290 });
287 291
288 SpecialSubscription.defaultsMap = Object.create(null, desc({ 292 SpecialSubscription.defaultsMap = Object.create(null, desc({
289 whitelist: WhitelistFilter, 293 whitelist: WhitelistFilter,
290 blocking: BlockingFilter, 294 blocking: BlockingFilter,
291 elemhide: ElemHideBase 295 elemhide: ElemHideBase
292 })); 296 }));
293 297
294 /** 298 /**
295 * Creates a new user-defined filter group. 299 * Creates a new user-defined filter group.
296 * @param {string} [title] title of the new filter group 300 * @param {string} [title] title of the new filter group
297 * @return {SpecialSubscription} 301 * @return {SpecialSubscription}
298 */ 302 */
299 SpecialSubscription.create = function(title) 303 SpecialSubscription.create = function(title)
300 { 304 {
301 let url; 305 let url;
302 do 306 do
307 {
303 url = "~user~" + Math.round(Math.random() * 1000000); 308 url = "~user~" + Math.round(Math.random() * 1000000);
304 while (url in Subscription.knownSubscriptions); 309 } while (url in Subscription.knownSubscriptions);
Wladimir Palant 2017/03/02 14:07:04 Another case where I just don't know how to fix it
kzar 2017/03/08 12:33:52 Fixed now since we removed the curl rule.
305 return new SpecialSubscription(url, title); 310 return new SpecialSubscription(url, title);
306 }; 311 };
307 312
308 /** 313 /**
309 * Creates a new user-defined filter group and adds the given filter to it. 314 * Creates a new user-defined filter group and adds the given filter to it.
310 * This group will act as the default group for this filter type. 315 * This group will act as the default group for this filter type.
311 * @param {Filter} filter 316 * @param {Filter} filter
312 * @return {SpecialSubscription} 317 * @return {SpecialSubscription}
313 */ 318 */
314 SpecialSubscription.createForFilter = function(filter) 319 SpecialSubscription.createForFilter = function(filter)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 let oldValue = this._lastDownload; 384 let oldValue = this._lastDownload;
380 this._lastDownload = value; 385 this._lastDownload = value;
381 FilterNotifier.triggerListeners("subscription.lastDownload", 386 FilterNotifier.triggerListeners("subscription.lastDownload",
382 this, value, oldValue); 387 this, value, oldValue);
383 } 388 }
384 return this._lastDownload; 389 return this._lastDownload;
385 }, 390 },
386 391
387 /** 392 /**
388 * See Subscription.serialize() 393 * See Subscription.serialize()
389 * @param {string[]} buffer 394 * @inheritdoc
390 */ 395 */
391 serialize(buffer) 396 serialize(buffer)
392 { 397 {
393 Subscription.prototype.serialize.call(this, buffer); 398 Subscription.prototype.serialize.call(this, buffer);
394 if (this._homepage) 399 if (this._homepage)
395 buffer.push("homepage=" + this._homepage); 400 buffer.push("homepage=" + this._homepage);
396 if (this._lastDownload) 401 if (this._lastDownload)
397 buffer.push("lastDownload=" + this._lastDownload); 402 buffer.push("lastDownload=" + this._lastDownload);
398 } 403 }
399 }); 404 });
400 405
401 /** 406 /**
402 * Class for filter subscriptions updated externally (by other extension) 407 * Class for filter subscriptions updated externally (by other extension)
403 * @param {string} url see Subscription() 408 * @param {string} url see Subscription()
404 * @param {string} [title] see Subscription() 409 * @param {string} [title] see Subscription()
405 * @constructor 410 * @constructor
406 * @augments RegularSubscription 411 * @augments RegularSubscription
407 */ 412 */
408 function ExternalSubscription(url, title) 413 function ExternalSubscription(url, title)
409 { 414 {
410 RegularSubscription.call(this, url, title); 415 RegularSubscription.call(this, url, title);
411 } 416 }
412 exports.ExternalSubscription = ExternalSubscription; 417 exports.ExternalSubscription = ExternalSubscription;
413 418
414 ExternalSubscription.prototype = extend(RegularSubscription, { 419 ExternalSubscription.prototype = extend(RegularSubscription, {
415 /** 420 /**
416 * See Subscription.serialize() 421 * See Subscription.serialize()
417 * @param {string[]} buffer 422 * @inheritdoc
418 */ 423 */
419 serialize(buffer) 424 serialize(buffer)
420 { 425 {
421 throw new Error( 426 throw new Error(
422 "Unexpected call, external subscriptions should not be serialized" 427 "Unexpected call, external subscriptions should not be serialized"
423 ); 428 );
424 } 429 }
425 }); 430 });
426 431
427 /** 432 /**
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 requiredVersion: null, 540 requiredVersion: null,
536 541
537 /** 542 /**
538 * Number indicating how often the object was downloaded. 543 * Number indicating how often the object was downloaded.
539 * @type {number} 544 * @type {number}
540 */ 545 */
541 downloadCount: 0, 546 downloadCount: 0,
542 547
543 /** 548 /**
544 * See Subscription.serialize() 549 * See Subscription.serialize()
545 * @param {string[]} buffer 550 * @inheritdoc
546 */ 551 */
547 serialize(buffer) 552 serialize(buffer)
548 { 553 {
549 RegularSubscription.prototype.serialize.call(this, buffer); 554 RegularSubscription.prototype.serialize.call(this, buffer);
550 if (this.downloadStatus) 555 if (this.downloadStatus)
551 buffer.push("downloadStatus=" + this.downloadStatus); 556 buffer.push("downloadStatus=" + this.downloadStatus);
552 if (this.lastSuccess) 557 if (this.lastSuccess)
553 buffer.push("lastSuccess=" + this.lastSuccess); 558 buffer.push("lastSuccess=" + this.lastSuccess);
554 if (this.lastCheck) 559 if (this.lastCheck)
555 buffer.push("lastCheck=" + this.lastCheck); 560 buffer.push("lastCheck=" + this.lastCheck);
556 if (this.expires) 561 if (this.expires)
557 buffer.push("expires=" + this.expires); 562 buffer.push("expires=" + this.expires);
558 if (this.softExpiration) 563 if (this.softExpiration)
559 buffer.push("softExpiration=" + this.softExpiration); 564 buffer.push("softExpiration=" + this.softExpiration);
560 if (this.errors) 565 if (this.errors)
561 buffer.push("errors=" + this.errors); 566 buffer.push("errors=" + this.errors);
562 if (this.version) 567 if (this.version)
563 buffer.push("version=" + this.version); 568 buffer.push("version=" + this.version);
564 if (this.requiredVersion) 569 if (this.requiredVersion)
565 buffer.push("requiredVersion=" + this.requiredVersion); 570 buffer.push("requiredVersion=" + this.requiredVersion);
566 if (this.downloadCount) 571 if (this.downloadCount)
567 buffer.push("downloadCount=" + this.downloadCount); 572 buffer.push("downloadCount=" + this.downloadCount);
568 } 573 }
569 }); 574 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld