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

Side by Side Diff: lib/filterStorage.js

Issue 5636077285015552: Issue 656 - Replace some __proto__ with Object.create (Closed)
Patch Set: Created June 23, 2014, 8: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
« no previous file with comments | « lib/filterClasses.js ('k') | lib/matcher.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 /** 92 /**
93 * Will be set to true if no patterns.ini file exists. 93 * Will be set to true if no patterns.ini file exists.
94 * @type Boolean 94 * @type Boolean
95 */ 95 */
96 firstRun: false, 96 firstRun: false,
97 97
98 /** 98 /**
99 * Map of properties listed in the filter storage file before the sections 99 * Map of properties listed in the filter storage file before the sections
100 * start. Right now this should be only the format version. 100 * start. Right now this should be only the format version.
101 */ 101 */
102 fileProperties: {__proto__: null}, 102 fileProperties: Object.create(null),
103 103
104 /** 104 /**
105 * List of filter subscriptions containing all filters 105 * List of filter subscriptions containing all filters
106 * @type Array of Subscription 106 * @type Array of Subscription
107 */ 107 */
108 subscriptions: [], 108 subscriptions: [],
109 109
110 /** 110 /**
111 * Map of subscriptions already on the list, by their URL/identifier 111 * Map of subscriptions already on the list, by their URL/identifier
112 * @type Object 112 * @type Object
113 */ 113 */
114 knownSubscriptions: {__proto__: null}, 114 knownSubscriptions: Object.create(null),
115 115
116 /** 116 /**
117 * Finds the filter group that a filter should be added to by default. Will 117 * Finds the filter group that a filter should be added to by default. Will
118 * return null if this group doesn't exist yet. 118 * return null if this group doesn't exist yet.
119 */ 119 */
120 getGroupForFilter: function(/**Filter*/ filter) /**SpecialSubscription*/ 120 getGroupForFilter: function(/**Filter*/ filter) /**SpecialSubscription*/
121 { 121 {
122 let generalSubscription = null; 122 let generalSubscription = null;
123 for (let subscription of FilterStorage.subscriptions) 123 for (let subscription of FilterStorage.subscriptions)
124 { 124 {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 doneReading(parser); 413 doneReading(parser);
414 }.bind(this), "FilterStorageRead"); 414 }.bind(this), "FilterStorageRead");
415 415
416 TimeLine.leave("FilterStorage.loadFromDisk() <- readFile()", "FilterStorag eRead"); 416 TimeLine.leave("FilterStorage.loadFromDisk() <- readFile()", "FilterStorag eRead");
417 }.bind(this); 417 }.bind(this);
418 418
419 var doneReading = function(parser) 419 var doneReading = function(parser)
420 { 420 {
421 // Old special groups might have been converted, remove them if they are e mpty 421 // Old special groups might have been converted, remove them if they are e mpty
422 let specialMap = {"~il~": true, "~wl~": true, "~fl~": true, "~eh~": true}; 422 let specialMap = {"~il~": true, "~wl~": true, "~fl~": true, "~eh~": true};
423 let knownSubscriptions = {__proto__: null}; 423 let knownSubscriptions = Object.create(null);
424 for (let i = 0; i < parser.subscriptions.length; i++) 424 for (let i = 0; i < parser.subscriptions.length; i++)
425 { 425 {
426 let subscription = parser.subscriptions[i]; 426 let subscription = parser.subscriptions[i];
427 if (subscription instanceof SpecialSubscription && subscription.filters. length == 0 && subscription.url in specialMap) 427 if (subscription instanceof SpecialSubscription && subscription.filters. length == 0 && subscription.url in specialMap)
428 parser.subscriptions.splice(i--, 1); 428 parser.subscriptions.splice(i--, 1);
429 else 429 else
430 knownSubscriptions[subscription.url] = subscription; 430 knownSubscriptions[subscription.url] = subscription;
431 } 431 }
432 432
433 this.fileProperties = parser.fileProperties; 433 this.fileProperties = parser.fileProperties;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 } 487 }
488 488
489 TimeLine.leave("FilterStorage.loadFromDisk() done"); 489 TimeLine.leave("FilterStorage.loadFromDisk() done");
490 }, 490 },
491 491
492 _generateFilterData: function(subscriptions) 492 _generateFilterData: function(subscriptions)
493 { 493 {
494 yield "# Adblock Plus preferences"; 494 yield "# Adblock Plus preferences";
495 yield "version=" + formatVersion; 495 yield "version=" + formatVersion;
496 496
497 let saved = {__proto__: null}; 497 let saved = Object.create(null);
498 let buf = []; 498 let buf = [];
499 499
500 // Save filter data 500 // Save filter data
501 for (let i = 0; i < subscriptions.length; i++) 501 for (let i = 0; i < subscriptions.length; i++)
502 { 502 {
503 let subscription = subscriptions[i]; 503 let subscription = subscriptions[i];
504 for (let j = 0; j < subscription.filters.length; j++) 504 for (let j = 0; j < subscription.filters.length; j++)
505 { 505 {
506 let filter = subscription.filters[j]; 506 let filter = subscription.filters[j];
507 if (!(filter.text in saved)) 507 if (!(filter.text in saved))
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 PrivateBrowsing.init(); 787 PrivateBrowsing.init();
788 788
789 /** 789 /**
790 * IO.readFromFile() listener to parse filter data. 790 * IO.readFromFile() listener to parse filter data.
791 * @constructor 791 * @constructor
792 */ 792 */
793 function INIParser() 793 function INIParser()
794 { 794 {
795 this.fileProperties = this.curObj = {}; 795 this.fileProperties = this.curObj = {};
796 this.subscriptions = []; 796 this.subscriptions = [];
797 this.knownFilters = {__proto__: null}; 797 this.knownFilters = Object.create(null);
798 this.knownSubscriptions = {__proto__: null}; 798 this.knownSubscriptions = Object.create(null);
799 } 799 }
800 INIParser.prototype = 800 INIParser.prototype =
801 { 801 {
802 linesProcessed: 0, 802 linesProcessed: 0,
803 subscriptions: null, 803 subscriptions: null,
804 knownFilters: null, 804 knownFilters: null,
805 knownSubscriptions : null, 805 knownSubscriptions : null,
806 wantObj: true, 806 wantObj: true,
807 fileProperties: null, 807 fileProperties: null,
808 curObj: null, 808 curObj: null,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 Subscription.knownSubscriptions = origKnownSubscriptions; 888 Subscription.knownSubscriptions = origKnownSubscriptions;
889 } 889 }
890 890
891 // Allow events to be processed every now and then. 891 // Allow events to be processed every now and then.
892 // Note: IO.readFromFile() will deal with the potential reentrance here. 892 // Note: IO.readFromFile() will deal with the potential reentrance here.
893 this.linesProcessed++; 893 this.linesProcessed++;
894 if (this.linesProcessed % 1000 == 0) 894 if (this.linesProcessed % 1000 == 0)
895 Utils.yield(); 895 Utils.yield();
896 } 896 }
897 }; 897 };
OLDNEW
« no previous file with comments | « lib/filterClasses.js ('k') | lib/matcher.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld