@@ -89,18 +89,18 @@ RuleSet.prototype = {
8989 var returl = null ;
9090 // If we're covered by an exclusion, go home
9191 if ( this . exclusions !== null ) {
92- for ( var i = 0 ; i < this . exclusions . length ; ++ i ) {
93- if ( this . exclusions [ i ] . pattern_c . test ( urispec ) ) {
92+ for ( let exclusion of this . exclusions ) {
93+ if ( exclusion . pattern_c . test ( urispec ) ) {
9494 log ( DBUG , "excluded uri " + urispec ) ;
9595 return null ;
9696 }
9797 }
9898 }
9999
100100 // Okay, now find the first rule that triggers
101- for ( var i = 0 ; i < this . rules . length ; ++ i ) {
102- returl = urispec . replace ( this . rules [ i ] . from_c ,
103- this . rules [ i ] . to ) ;
101+ for ( let rule of this . rules ) {
102+ returl = urispec . replace ( rule . from_c ,
103+ rule . to ) ;
104104 if ( returl != urispec ) {
105105 return returl ;
106106 }
@@ -194,9 +194,9 @@ RuleSets.prototype = {
194194 */
195195 addFromXml : function ( ruleXml ) {
196196 var sets = ruleXml . getElementsByTagName ( "ruleset" ) ;
197- for ( var i = 0 ; i < sets . length ; ++ i ) {
197+ for ( let s of sets ) {
198198 try {
199- this . parseOneRuleset ( sets [ i ] ) ;
199+ this . parseOneRuleset ( s ) ;
200200 } catch ( e ) {
201201 log ( WARN , 'Error processing ruleset:' + e ) ;
202202 }
@@ -234,11 +234,9 @@ RuleSets.prototype = {
234234 removeUserRule : function ( ruleset ) {
235235 log ( INFO , 'removing user rule for ' + JSON . stringify ( ruleset ) ) ;
236236 this . ruleCache . delete ( ruleset . name ) ;
237- for ( let x = 0 ; x < this . targets [ ruleset . name ] . length ; x ++ ) {
238- if ( this . targets [ ruleset . name ] [ x ] . isEquivalentTo ( ruleset ) ) {
239- this . targets [ ruleset . name ] . splice ( x , 1 ) ;
240- }
241- }
237+ this . targets [ ruleset . name ] = this . targets [ ruleset . name ] . filter ( r =>
238+ ! ( r . isEquivalentTo ( ruleset ) )
239+ ) ;
242240 if ( this . targets [ ruleset . name ] . length == 0 ) {
243241 delete this . targets [ ruleset . name ] ;
244242 }
@@ -280,33 +278,33 @@ RuleSets.prototype = {
280278 }
281279
282280 var rules = ruletag . getElementsByTagName ( "rule" ) ;
283- for ( var j = 0 ; j < rules . length ; j ++ ) {
284- rule_set . rules . push ( new Rule ( rules [ j ] . getAttribute ( "from" ) ,
285- rules [ j ] . getAttribute ( "to" ) ) ) ;
281+ for ( let rule of rules ) {
282+ rule_set . rules . push ( new Rule ( rule . getAttribute ( "from" ) ,
283+ rule . getAttribute ( "to" ) ) ) ;
286284 }
287285
288286 var exclusions = ruletag . getElementsByTagName ( "exclusion" ) ;
289287 if ( exclusions . length > 0 ) {
290288 rule_set . exclusions = [ ] ;
291- for ( var j = 0 ; j < exclusions . length ; j ++ ) {
289+ for ( let exclusion of exclusions ) {
292290 rule_set . exclusions . push (
293- new Exclusion ( exclusions [ j ] . getAttribute ( "pattern" ) ) ) ;
291+ new Exclusion ( exclusion . getAttribute ( "pattern" ) ) ) ;
294292 }
295293 }
296294
297295 var cookierules = ruletag . getElementsByTagName ( "securecookie" ) ;
298296 if ( cookierules . length > 0 ) {
299297 rule_set . cookierules = [ ] ;
300- for ( var j = 0 ; j < cookierules . length ; j ++ ) {
298+ for ( let cookierule of cookierules ) {
301299 rule_set . cookierules . push (
302- new CookieRule ( cookierules [ j ] . getAttribute ( "host" ) ,
303- cookierules [ j ] . getAttribute ( "name" ) ) ) ;
300+ new CookieRule ( cookierule . getAttribute ( "host" ) ,
301+ cookierule . getAttribute ( "name" ) ) ) ;
304302 }
305303 }
306304
307305 var targets = ruletag . getElementsByTagName ( "target" ) ;
308- for ( var j = 0 ; j < targets . length ; j ++ ) {
309- var host = targets [ j ] . getAttribute ( "host" ) ;
306+ for ( let target of targets ) {
307+ var host = target . getAttribute ( "host" ) ;
310308 if ( ! ( host in this . targets ) ) {
311309 this . targets [ host ] = [ ] ;
312310 }
@@ -343,11 +341,11 @@ RuleSets.prototype = {
343341
344342 // Replace each portion of the domain with a * in turn
345343 var segmented = host . split ( "." ) ;
346- for ( var i = 0 ; i < segmented . length ; ++ i ) {
347- tmp = segmented [ i ] ;
348- segmented [ i ] = "*" ;
344+ for ( let s of segmented ) {
345+ tmp = s ;
346+ s = "*" ;
349347 results = results . concat ( this . targets [ segmented . join ( "." ) ] ) ;
350- segmented [ i ] = tmp ;
348+ s = tmp ;
351349 }
352350 // now eat away from the left, with *, so that for x.y.z.google.com we
353351 // check *.z.google.com and *.google.com (we did *.y.z.google.com above)
@@ -400,8 +398,8 @@ RuleSets.prototype = {
400398 var potentiallyApplicable = this . potentiallyApplicableRulesets ( hostname ) ;
401399 for ( let ruleset of potentiallyApplicable ) {
402400 if ( ruleset . cookierules !== null && ruleset . active ) {
403- for ( var j = 0 ; j < ruleset . cookierules . length ; j ++ ) {
404- var cr = ruleset . cookierules [ j ] ;
401+ for ( let cookierules of ruleset . cookierules ) {
402+ var cr = cookierules ;
405403 if ( cr . host_c . test ( cookie . domain ) && cr . name_c . test ( cookie . name ) ) {
406404 return ruleset ;
407405 }
0 commit comments