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

Side by Side Diff: lib/filterClasses.js

Issue 5055554716172288: Issue 653 -Object.defineProperty instead of defineGetter / defineSetter (Closed)
Patch Set: I am generally not a big fan of iterating over property names. It seems like for most objects here … Created June 26, 2014, 8:33 p.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 | « chrome/content/ui/sidebar.js ('k') | lib/filterStorage.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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 this.contentType = contentType; 466 this.contentType = contentType;
467 if (matchCase) 467 if (matchCase)
468 this.matchCase = matchCase; 468 this.matchCase = matchCase;
469 if (thirdParty != null) 469 if (thirdParty != null)
470 this.thirdParty = thirdParty; 470 this.thirdParty = thirdParty;
471 471
472 if (regexpSource.length >= 2 && regexpSource[0] == "/" && regexpSource[regexpS ource.length - 1] == "/") 472 if (regexpSource.length >= 2 && regexpSource[0] == "/" && regexpSource[regexpS ource.length - 1] == "/")
473 { 473 {
474 // The filter is a regular expression - convert it immediately to catch synt ax errors 474 // The filter is a regular expression - convert it immediately to catch synt ax errors
475 let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), thi s.matchCase ? "" : "i"); 475 let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), thi s.matchCase ? "" : "i");
476 this.__defineGetter__("regexp", () => regexp); 476 Object.defineProperty(this, "regexp", {value: regexp});
477 } 477 }
478 else 478 else
479 { 479 {
480 // No need to convert this filter to regular expression yet, do it on demand 480 // No need to convert this filter to regular expression yet, do it on demand
481 this.regexpSource = regexpSource; 481 this.regexpSource = regexpSource;
482 } 482 }
483 } 483 }
484 exports.RegExpFilter = RegExpFilter; 484 exports.RegExpFilter = RegExpFilter;
485 485
486 RegExpFilter.prototype = 486 RegExpFilter.prototype =
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 .replace(/\\\*/g, ".*") // replace wildcards by .* 522 .replace(/\\\*/g, ".*") // replace wildcards by .*
523 // process separator placeholders (all ANSI characters but alphanumeric ch aracters and _%.-) 523 // process separator placeholders (all ANSI characters but alphanumeric ch aracters and _%.-)
524 .replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\ x60\\x7B-\\x7F]|$)") 524 .replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\ x60\\x7B-\\x7F]|$)")
525 .replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") // process extended anchor at expression start 525 .replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") // process extended anchor at expression start
526 .replace(/^\\\|/, "^") // process anchor at expression start 526 .replace(/^\\\|/, "^") // process anchor at expression start
527 .replace(/\\\|$/, "$") // process anchor at expression end 527 .replace(/\\\|$/, "$") // process anchor at expression end
528 .replace(/^(\.\*)/, "") // remove leading wildcards 528 .replace(/^(\.\*)/, "") // remove leading wildcards
529 .replace(/(\.\*)$/, ""); // remove trailing wildcards 529 .replace(/(\.\*)$/, ""); // remove trailing wildcards
530 530
531 let regexp = new RegExp(source, this.matchCase ? "" : "i"); 531 let regexp = new RegExp(source, this.matchCase ? "" : "i");
532 532 Object.defineProperty(this, "regexp", {value: regexp});
533 delete this.regexpSource; 533 return regexp;
534 this.__defineGetter__("regexp", () => regexp);
535 return this.regexp;
536 }, 534 },
537 /** 535 /**
538 * Content types the filter applies to, combination of values from RegExpFilte r.typeMap 536 * Content types the filter applies to, combination of values from RegExpFilte r.typeMap
539 * @type Number 537 * @type Number
540 */ 538 */
541 contentType: 0x7FFFFFFF, 539 contentType: 0x7FFFFFFF,
542 /** 540 /**
543 * Defines whether the filter should distinguish between lower and upper case letters 541 * Defines whether the filter should distinguish between lower and upper case letters
544 * @type Boolean 542 * @type Boolean
545 */ 543 */
(...skipping 19 matching lines...) Expand all
565 (this.thirdParty == null || this.thirdParty == thirdParty) && 563 (this.thirdParty == null || this.thirdParty == thirdParty) &&
566 this.isActiveOnDomain(docDomain)) 564 this.isActiveOnDomain(docDomain))
567 { 565 {
568 return true; 566 return true;
569 } 567 }
570 568
571 return false; 569 return false;
572 } 570 }
573 }; 571 };
574 572
575 RegExpFilter.prototype.__defineGetter__("0", function() 573 // Required to optimize Matcher, see also RegExpFilter.prototype.length
574 Object.defineProperty(RegExpFilter.prototype, "0",
576 { 575 {
577 return this; 576 get: function() { return this; }
578 }); 577 });
579 578
580 /** 579 /**
581 * Creates a RegExp filter from its text representation 580 * Creates a RegExp filter from its text representation
582 * @param {String} text same as in Filter() 581 * @param {String} text same as in Filter()
583 */ 582 */
584 RegExpFilter.fromText = function(text) 583 RegExpFilter.fromText = function(text)
585 { 584 {
586 let blocking = true; 585 let blocking = true;
587 let origText = text; 586 let origText = text;
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 function ElemHideException(text, domains, selector) 890 function ElemHideException(text, domains, selector)
892 { 891 {
893 ElemHideBase.call(this, text, domains, selector); 892 ElemHideBase.call(this, text, domains, selector);
894 } 893 }
895 exports.ElemHideException = ElemHideException; 894 exports.ElemHideException = ElemHideException;
896 895
897 ElemHideException.prototype = 896 ElemHideException.prototype =
898 { 897 {
899 __proto__: ElemHideBase.prototype 898 __proto__: ElemHideBase.prototype
900 }; 899 };
OLDNEW
« no previous file with comments | « chrome/content/ui/sidebar.js ('k') | lib/filterStorage.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld