OLD | NEW |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 * Lookup table for keywords by the filter text | 42 * Lookup table for keywords by the filter text |
43 * @type Object | 43 * @type Object |
44 */ | 44 */ |
45 keywordByFilter: null, | 45 keywordByFilter: null, |
46 | 46 |
47 /** | 47 /** |
48 * Removes all known filters | 48 * Removes all known filters |
49 */ | 49 */ |
50 clear: function() | 50 clear: function() |
51 { | 51 { |
52 this.filterByKeyword = {__proto__: null}; | 52 this.filterByKeyword = Object.create(null); |
53 this.keywordByFilter = {__proto__: null}; | 53 this.keywordByFilter = Object.create(null); |
54 }, | 54 }, |
55 | 55 |
56 /** | 56 /** |
57 * Adds a filter to the matcher | 57 * Adds a filter to the matcher |
58 * @param {RegExpFilter} filter | 58 * @param {RegExpFilter} filter |
59 */ | 59 */ |
60 add: function(filter) | 60 add: function(filter) |
61 { | 61 { |
62 if (filter.text in this.keywordByFilter) | 62 if (filter.text in this.keywordByFilter) |
63 return; | 63 return; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 /** | 209 /** |
210 * Combines a matcher for blocking and exception rules, automatically sorts | 210 * Combines a matcher for blocking and exception rules, automatically sorts |
211 * rules into two Matcher instances. | 211 * rules into two Matcher instances. |
212 * @constructor | 212 * @constructor |
213 */ | 213 */ |
214 function CombinedMatcher() | 214 function CombinedMatcher() |
215 { | 215 { |
216 this.blacklist = new Matcher(); | 216 this.blacklist = new Matcher(); |
217 this.whitelist = new Matcher(); | 217 this.whitelist = new Matcher(); |
218 this.keys = {__proto__: null}; | 218 this.keys = Object.create(null); |
219 this.resultCache = {__proto__: null}; | 219 this.resultCache = Object.create(null); |
220 } | 220 } |
221 exports.CombinedMatcher = CombinedMatcher; | 221 exports.CombinedMatcher = CombinedMatcher; |
222 | 222 |
223 /** | 223 /** |
224 * Maximal number of matching cache entries to be kept | 224 * Maximal number of matching cache entries to be kept |
225 * @type Number | 225 * @type Number |
226 */ | 226 */ |
227 CombinedMatcher.maxCacheEntries = 1000; | 227 CombinedMatcher.maxCacheEntries = 1000; |
228 | 228 |
229 CombinedMatcher.prototype = | 229 CombinedMatcher.prototype = |
(...skipping 28 matching lines...) Expand all Loading... |
258 */ | 258 */ |
259 cacheEntries: 0, | 259 cacheEntries: 0, |
260 | 260 |
261 /** | 261 /** |
262 * @see Matcher#clear | 262 * @see Matcher#clear |
263 */ | 263 */ |
264 clear: function() | 264 clear: function() |
265 { | 265 { |
266 this.blacklist.clear(); | 266 this.blacklist.clear(); |
267 this.whitelist.clear(); | 267 this.whitelist.clear(); |
268 this.keys = {__proto__: null}; | 268 this.keys = Object.create(null); |
269 this.resultCache = {__proto__: null}; | 269 this.resultCache = Object.create(null); |
270 this.cacheEntries = 0; | 270 this.cacheEntries = 0; |
271 }, | 271 }, |
272 | 272 |
273 /** | 273 /** |
274 * @see Matcher#add | 274 * @see Matcher#add |
275 */ | 275 */ |
276 add: function(filter) | 276 add: function(filter) |
277 { | 277 { |
278 if (filter instanceof WhitelistFilter) | 278 if (filter instanceof WhitelistFilter) |
279 { | 279 { |
280 if (filter.siteKeys) | 280 if (filter.siteKeys) |
281 { | 281 { |
282 for (let i = 0; i < filter.siteKeys.length; i++) | 282 for (let i = 0; i < filter.siteKeys.length; i++) |
283 this.keys[filter.siteKeys[i]] = filter.text; | 283 this.keys[filter.siteKeys[i]] = filter.text; |
284 } | 284 } |
285 else | 285 else |
286 this.whitelist.add(filter); | 286 this.whitelist.add(filter); |
287 } | 287 } |
288 else | 288 else |
289 this.blacklist.add(filter); | 289 this.blacklist.add(filter); |
290 | 290 |
291 if (this.cacheEntries > 0) | 291 if (this.cacheEntries > 0) |
292 { | 292 { |
293 this.resultCache = {__proto__: null}; | 293 this.resultCache = Object.create(null); |
294 this.cacheEntries = 0; | 294 this.cacheEntries = 0; |
295 } | 295 } |
296 }, | 296 }, |
297 | 297 |
298 /** | 298 /** |
299 * @see Matcher#remove | 299 * @see Matcher#remove |
300 */ | 300 */ |
301 remove: function(filter) | 301 remove: function(filter) |
302 { | 302 { |
303 if (filter instanceof WhitelistFilter) | 303 if (filter instanceof WhitelistFilter) |
304 { | 304 { |
305 if (filter.siteKeys) | 305 if (filter.siteKeys) |
306 { | 306 { |
307 for (let i = 0; i < filter.siteKeys.length; i++) | 307 for (let i = 0; i < filter.siteKeys.length; i++) |
308 delete this.keys[filter.siteKeys[i]]; | 308 delete this.keys[filter.siteKeys[i]]; |
309 } | 309 } |
310 else | 310 else |
311 this.whitelist.remove(filter); | 311 this.whitelist.remove(filter); |
312 } | 312 } |
313 else | 313 else |
314 this.blacklist.remove(filter); | 314 this.blacklist.remove(filter); |
315 | 315 |
316 if (this.cacheEntries > 0) | 316 if (this.cacheEntries > 0) |
317 { | 317 { |
318 this.resultCache = {__proto__: null}; | 318 this.resultCache = Object.create(null); |
319 this.cacheEntries = 0; | 319 this.cacheEntries = 0; |
320 } | 320 } |
321 }, | 321 }, |
322 | 322 |
323 /** | 323 /** |
324 * @see Matcher#findKeyword | 324 * @see Matcher#findKeyword |
325 */ | 325 */ |
326 findKeyword: function(filter) | 326 findKeyword: function(filter) |
327 { | 327 { |
328 if (filter instanceof WhitelistFilter) | 328 if (filter instanceof WhitelistFilter) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 matchesAny: function(location, contentType, docDomain, thirdParty) | 399 matchesAny: function(location, contentType, docDomain, thirdParty) |
400 { | 400 { |
401 let key = location + " " + contentType + " " + docDomain + " " + thirdParty; | 401 let key = location + " " + contentType + " " + docDomain + " " + thirdParty; |
402 if (key in this.resultCache) | 402 if (key in this.resultCache) |
403 return this.resultCache[key]; | 403 return this.resultCache[key]; |
404 | 404 |
405 let result = this.matchesAnyInternal(location, contentType, docDomain, third
Party); | 405 let result = this.matchesAnyInternal(location, contentType, docDomain, third
Party); |
406 | 406 |
407 if (this.cacheEntries >= CombinedMatcher.maxCacheEntries) | 407 if (this.cacheEntries >= CombinedMatcher.maxCacheEntries) |
408 { | 408 { |
409 this.resultCache = {__proto__: null}; | 409 this.resultCache = Object.create(null); |
410 this.cacheEntries = 0; | 410 this.cacheEntries = 0; |
411 } | 411 } |
412 | 412 |
413 this.resultCache[key] = result; | 413 this.resultCache[key] = result; |
414 this.cacheEntries++; | 414 this.cacheEntries++; |
415 | 415 |
416 return result; | 416 return result; |
417 }, | 417 }, |
418 | 418 |
419 /** | 419 /** |
(...skipping 13 matching lines...) Expand all Loading... |
433 else | 433 else |
434 return null; | 434 return null; |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 /** | 438 /** |
439 * Shared CombinedMatcher instance that should usually be used. | 439 * Shared CombinedMatcher instance that should usually be used. |
440 * @type CombinedMatcher | 440 * @type CombinedMatcher |
441 */ | 441 */ |
442 let defaultMatcher = exports.defaultMatcher = new CombinedMatcher(); | 442 let defaultMatcher = exports.defaultMatcher = new CombinedMatcher(); |
OLD | NEW |