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

Delta Between Two Patch Sets: lib/subscriptionClasses.js

Issue 29350382: Issue 4353 - Remove deprecated __proto__ syntax (Closed)
Left Patch Set: Created Sept. 1, 2016, 11:44 p.m.
Right Patch Set: Export extend function too, use Object.keys Created Sept. 2, 2016, 3:05 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/filterNotifier.js ('k') | 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-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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** 18 /**
19 * @fileOverview Definition of Subscription class and its subclasses. 19 * @fileOverview Definition of Subscription class and its subclasses.
20 */ 20 */
21 21
22 let {ActiveFilter, BlockingFilter, WhitelistFilter, ElemHideBase} = require("fil terClasses"); 22 let {ActiveFilter, BlockingFilter, WhitelistFilter, ElemHideBase} = require("fil terClasses");
23 let {FilterNotifier} = require("filterNotifier"); 23 let {FilterNotifier} = require("filterNotifier");
24 let {desc} = require("coreUtils"); 24 let {desc, extend} = require("coreUtils");
25 25
26 /** 26 /**
27 * Abstract base class for filter subscriptions 27 * Abstract base class for filter subscriptions
28 * 28 *
29 * @param {String} url download location of the subscription 29 * @param {String} url download location of the subscription
30 * @param {String} [title] title of the filter subscription 30 * @param {String} [title] title of the filter subscription
31 * @constructor 31 * @constructor
32 */ 32 */
33 function Subscription(url, title) 33 function Subscription(url, title)
34 { 34 {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 * @param {String} [title] see Subscription() 223 * @param {String} [title] see Subscription()
224 * @constructor 224 * @constructor
225 * @augments Subscription 225 * @augments Subscription
226 */ 226 */
227 function SpecialSubscription(url, title) 227 function SpecialSubscription(url, title)
228 { 228 {
229 Subscription.call(this, url, title); 229 Subscription.call(this, url, title);
230 } 230 }
231 exports.SpecialSubscription = SpecialSubscription; 231 exports.SpecialSubscription = SpecialSubscription;
232 232
233 SpecialSubscription.prototype = Object.create(Subscription.prototype, desc({ 233 SpecialSubscription.prototype = extend(Subscription, {
234 /** 234 /**
235 * Filter types that should be added to this subscription by default 235 * Filter types that should be added to this subscription by default
236 * (entries should correspond to keys in SpecialSubscription.defaultsMap). 236 * (entries should correspond to keys in SpecialSubscription.defaultsMap).
237 * @type string[] 237 * @type string[]
238 */ 238 */
239 defaults: null, 239 defaults: null,
240 240
241 /** 241 /**
242 * Tests whether a filter should be added to this group by default 242 * Tests whether a filter should be added to this group by default
243 * @param {Filter} filter filter to be tested 243 * @param {Filter} filter filter to be tested
(...skipping 19 matching lines...) Expand all
263 * See Subscription.serialize() 263 * See Subscription.serialize()
264 */ 264 */
265 serialize: function(buffer) 265 serialize: function(buffer)
266 { 266 {
267 Subscription.prototype.serialize.call(this, buffer); 267 Subscription.prototype.serialize.call(this, buffer);
268 if (this.defaults && this.defaults.length) 268 if (this.defaults && this.defaults.length)
269 buffer.push("defaults=" + this.defaults.filter((type) => type in SpecialSu bscription.defaultsMap).join(" ")); 269 buffer.push("defaults=" + this.defaults.filter((type) => type in SpecialSu bscription.defaultsMap).join(" "));
270 if (this._lastDownload) 270 if (this._lastDownload)
271 buffer.push("lastDownload=" + this._lastDownload); 271 buffer.push("lastDownload=" + this._lastDownload);
272 } 272 }
273 })); 273 });
274 274
275 SpecialSubscription.defaultsMap = Object.create(null, desc({ 275 SpecialSubscription.defaultsMap = Object.create(null, desc({
276 "whitelist": WhitelistFilter, 276 "whitelist": WhitelistFilter,
277 "blocking": BlockingFilter, 277 "blocking": BlockingFilter,
278 "elemhide": ElemHideBase 278 "elemhide": ElemHideBase
279 })); 279 }));
280 280
281 /** 281 /**
282 * Creates a new user-defined filter group. 282 * Creates a new user-defined filter group.
283 * @param {String} [title] title of the new filter group 283 * @param {String} [title] title of the new filter group
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 * @param {String} [title] see Subscription() 317 * @param {String} [title] see Subscription()
318 * @constructor 318 * @constructor
319 * @augments Subscription 319 * @augments Subscription
320 */ 320 */
321 function RegularSubscription(url, title) 321 function RegularSubscription(url, title)
322 { 322 {
323 Subscription.call(this, url, title || url); 323 Subscription.call(this, url, title || url);
324 } 324 }
325 exports.RegularSubscription = RegularSubscription; 325 exports.RegularSubscription = RegularSubscription;
326 326
327 RegularSubscription.prototype = Object.create(Subscription.prototype, desc({ 327 RegularSubscription.prototype = extend(Subscription, {
328 _homepage: null, 328 _homepage: null,
329 _lastDownload: 0, 329 _lastDownload: 0,
330 330
331 /** 331 /**
332 * Filter subscription homepage if known 332 * Filter subscription homepage if known
333 * @type String 333 * @type String
334 */ 334 */
335 homepage: { 335 get homepage()
336 get: function() 336 {
337 { 337 return this._homepage;
338 return this._homepage; 338 },
339 }, 339 set homepage(value)
340 set: function(value) 340 {
341 { 341 if (value != this._homepage)
342 if (value != this._homepage) 342 {
343 { 343 let oldValue = this._homepage;
344 let oldValue = this._homepage; 344 this._homepage = value;
345 this._homepage = value; 345 FilterNotifier.triggerListeners("subscription.homepage", this, value, oldV alue);
346 FilterNotifier.triggerListeners("subscription.homepage", this, value, ol dValue); 346 }
347 } 347 return this._homepage;
348 return this._homepage;
349 }
350 }, 348 },
351 349
352 /** 350 /**
353 * Time of the last subscription download (in seconds since the beginning of t he epoch) 351 * Time of the last subscription download (in seconds since the beginning of t he epoch)
354 * @type Number 352 * @type Number
355 */ 353 */
356 lastDownload: { 354 get lastDownload()
357 get: function() 355 {
358 { 356 return this._lastDownload;
359 return this._lastDownload; 357 },
360 }, 358 set lastDownload(value)
361 set: function(value) 359 {
362 { 360 if (value != this._lastDownload)
363 if (value != this._lastDownload) 361 {
364 { 362 let oldValue = this._lastDownload;
365 let oldValue = this._lastDownload; 363 this._lastDownload = value;
366 this._lastDownload = value; 364 FilterNotifier.triggerListeners("subscription.lastDownload", this, value, oldValue);
367 FilterNotifier.triggerListeners("subscription.lastDownload", this, value , oldValue); 365 }
368 } 366 return this._lastDownload;
369 return this._lastDownload;
370 }
371 }, 367 },
372 368
373 /** 369 /**
374 * See Subscription.serialize() 370 * See Subscription.serialize()
375 */ 371 */
376 serialize: function(buffer) 372 serialize: function(buffer)
377 { 373 {
378 Subscription.prototype.serialize.call(this, buffer); 374 Subscription.prototype.serialize.call(this, buffer);
379 if (this._homepage) 375 if (this._homepage)
380 buffer.push("homepage=" + this._homepage); 376 buffer.push("homepage=" + this._homepage);
381 if (this._lastDownload) 377 if (this._lastDownload)
382 buffer.push("lastDownload=" + this._lastDownload); 378 buffer.push("lastDownload=" + this._lastDownload);
383 } 379 }
384 })); 380 });
385 381
386 /** 382 /**
387 * Class for filter subscriptions updated externally (by other extension) 383 * Class for filter subscriptions updated externally (by other extension)
388 * @param {String} url see Subscription() 384 * @param {String} url see Subscription()
389 * @param {String} [title] see Subscription() 385 * @param {String} [title] see Subscription()
390 * @constructor 386 * @constructor
391 * @augments RegularSubscription 387 * @augments RegularSubscription
392 */ 388 */
393 function ExternalSubscription(url, title) 389 function ExternalSubscription(url, title)
394 { 390 {
395 RegularSubscription.call(this, url, title); 391 RegularSubscription.call(this, url, title);
396 } 392 }
397 exports.ExternalSubscription = ExternalSubscription; 393 exports.ExternalSubscription = ExternalSubscription;
398 394
399 ExternalSubscription.prototype = Object.create(RegularSubscription.prototype, de sc({ 395 ExternalSubscription.prototype = extend(RegularSubscription, {
400 /** 396 /**
401 * See Subscription.serialize() 397 * See Subscription.serialize()
402 */ 398 */
403 serialize: function(buffer) 399 serialize: function(buffer)
404 { 400 {
405 throw new Error("Unexpected call, external subscriptions should not be seria lized"); 401 throw new Error("Unexpected call, external subscriptions should not be seria lized");
406 } 402 }
407 })); 403 });
408 404
409 /** 405 /**
410 * Class for filter subscriptions updated externally (by other extension) 406 * Class for filter subscriptions updated externally (by other extension)
411 * @param {String} url see Subscription() 407 * @param {String} url see Subscription()
412 * @param {String} [title] see Subscription() 408 * @param {String} [title] see Subscription()
413 * @constructor 409 * @constructor
414 * @augments RegularSubscription 410 * @augments RegularSubscription
415 */ 411 */
416 function DownloadableSubscription(url, title) 412 function DownloadableSubscription(url, title)
417 { 413 {
418 RegularSubscription.call(this, url, title); 414 RegularSubscription.call(this, url, title);
419 } 415 }
420 exports.DownloadableSubscription = DownloadableSubscription; 416 exports.DownloadableSubscription = DownloadableSubscription;
421 417
422 DownloadableSubscription.prototype = Object.create(RegularSubscription.prototype , desc({ 418 DownloadableSubscription.prototype = extend(RegularSubscription, {
423 _downloadStatus: null, 419 _downloadStatus: null,
424 _lastCheck: 0, 420 _lastCheck: 0,
425 _errors: 0, 421 _errors: 0,
426 422
427 /** 423 /**
428 * Status of the last download (ID of a string) 424 * Status of the last download (ID of a string)
429 * @type String 425 * @type String
430 */ 426 */
431 downloadStatus: { 427 get downloadStatus()
432 get: function() 428 {
433 { 429 return this._downloadStatus;
434 return this._downloadStatus; 430 },
435 }, 431 set downloadStatus(value)
436 set: function(value) 432 {
437 { 433 let oldValue = this._downloadStatus;
438 let oldValue = this._downloadStatus; 434 this._downloadStatus = value;
439 this._downloadStatus = value; 435 FilterNotifier.triggerListeners("subscription.downloadStatus", this, value, oldValue);
440 FilterNotifier.triggerListeners("subscription.downloadStatus", this, value , oldValue); 436 return this._downloadStatus;
441 return this._downloadStatus;
442 }
443 }, 437 },
444 438
445 /** 439 /**
446 * Time of the last successful download (in seconds since the beginning of the 440 * Time of the last successful download (in seconds since the beginning of the
447 * epoch). 441 * epoch).
448 */ 442 */
449 lastSuccess: 0, 443 lastSuccess: 0,
450 444
451 /** 445 /**
452 * Time when the subscription was considered for an update last time (in secon ds 446 * Time when the subscription was considered for an update last time (in secon ds
453 * since the beginning of the epoch). This will be used to increase softExpira tion 447 * since the beginning of the epoch). This will be used to increase softExpira tion
454 * if the user doesn't use Adblock Plus for some time. 448 * if the user doesn't use Adblock Plus for some time.
455 * @type Number 449 * @type Number
456 */ 450 */
457 lastCheck: { 451 get lastCheck()
458 get: function() 452 {
459 { 453 return this._lastCheck;
460 return this._lastCheck; 454 },
461 }, 455 set lastCheck(value)
462 set: function(value) 456 {
463 { 457 if (value != this._lastCheck)
464 if (value != this._lastCheck) 458 {
465 { 459 let oldValue = this._lastCheck;
466 let oldValue = this._lastCheck; 460 this._lastCheck = value;
467 this._lastCheck = value; 461 FilterNotifier.triggerListeners("subscription.lastCheck", this, value, old Value);
468 FilterNotifier.triggerListeners("subscription.lastCheck", this, value, o ldValue); 462 }
469 } 463 return this._lastCheck;
470 return this._lastCheck;
471 }
472 }, 464 },
473 465
474 /** 466 /**
475 * Hard expiration time of the filter subscription (in seconds since the begin ning of the epoch) 467 * Hard expiration time of the filter subscription (in seconds since the begin ning of the epoch)
476 * @type Number 468 * @type Number
477 */ 469 */
478 expires: 0, 470 expires: 0,
479 471
480 /** 472 /**
481 * Soft expiration time of the filter subscription (in seconds since the begin ning of the epoch) 473 * Soft expiration time of the filter subscription (in seconds since the begin ning of the epoch)
482 * @type Number 474 * @type Number
483 */ 475 */
484 softExpiration: 0, 476 softExpiration: 0,
485 477
486 /** 478 /**
487 * Number of download failures since last success 479 * Number of download failures since last success
488 * @type Number 480 * @type Number
489 */ 481 */
490 errors: { 482 get errors()
491 get: function() 483 {
492 { 484 return this._errors;
493 return this._errors; 485 },
494 }, 486 set errors(value)
495 set: function(value) 487 {
496 { 488 if (value != this._errors)
497 if (value != this._errors) 489 {
498 { 490 let oldValue = this._errors;
499 let oldValue = this._errors; 491 this._errors = value;
500 this._errors = value; 492 FilterNotifier.triggerListeners("subscription.errors", this, value, oldVal ue);
501 FilterNotifier.triggerListeners("subscription.errors", this, value, oldV alue); 493 }
502 } 494 return this._errors;
503 return this._errors;
504 }
505 }, 495 },
506 496
507 /** 497 /**
508 * Version of the subscription data retrieved on last successful download 498 * Version of the subscription data retrieved on last successful download
509 * @type Number 499 * @type Number
510 */ 500 */
511 version: 0, 501 version: 0,
512 502
513 /** 503 /**
514 * Minimal Adblock Plus version required for this subscription 504 * Minimal Adblock Plus version required for this subscription
(...skipping 25 matching lines...) Expand all
540 buffer.push("softExpiration=" + this.softExpiration); 530 buffer.push("softExpiration=" + this.softExpiration);
541 if (this.errors) 531 if (this.errors)
542 buffer.push("errors=" + this.errors); 532 buffer.push("errors=" + this.errors);
543 if (this.version) 533 if (this.version)
544 buffer.push("version=" + this.version); 534 buffer.push("version=" + this.version);
545 if (this.requiredVersion) 535 if (this.requiredVersion)
546 buffer.push("requiredVersion=" + this.requiredVersion); 536 buffer.push("requiredVersion=" + this.requiredVersion);
547 if (this.downloadCount) 537 if (this.downloadCount)
548 buffer.push("downloadCount=" + this.downloadCount); 538 buffer.push("downloadCount=" + this.downloadCount);
549 } 539 }
550 })); 540 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld