| OLD | NEW |
| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 setTimeout(call, 0); | 61 setTimeout(call, 0); |
| 62 }); | 62 }); |
| 63 } | 63 } |
| 64 | 64 |
| 65 function async(callees, mapFunction) | 65 function async(callees, mapFunction) |
| 66 { | 66 { |
| 67 if (!(Symbol.iterator in callees)) | 67 if (!(Symbol.iterator in callees)) |
| 68 callees = [callees]; | 68 callees = [callees]; |
| 69 | 69 |
| 70 let lastPause = Date.now(); | 70 let lastPause = Date.now(); |
| 71 let index = 0; | |
| 72 | 71 |
| 73 let promise = Promise.resolve(); | 72 let promise = Promise.resolve(); |
| 74 | 73 |
| 75 for (let next of callees) | 74 let chain = (next, index) => |
| 76 { | 75 { |
| 77 let currentIndex = index; | |
| 78 | |
| 79 promise = promise.then(() => | 76 promise = promise.then(() => |
| 80 { | 77 { |
| 81 if (mapFunction) | 78 if (mapFunction) |
| 82 next = mapFunction(next, currentIndex); | 79 next = mapFunction(next, index); |
| 83 | 80 |
| 84 // If it has been 100ms or longer since the last call, take a pause. This | 81 // If it has been 100ms or longer since the last call, take a pause. This |
| 85 // keeps the browser from freezing up. | 82 // keeps the browser from freezing up. |
| 86 let now = Date.now(); | 83 let now = Date.now(); |
| 87 if (now - lastPause >= 100) | 84 if (now - lastPause >= 100) |
| 88 { | 85 { |
| 89 lastPause = now; | 86 lastPause = now; |
| 90 return callLater(next); | 87 return callLater(next); |
| 91 } | 88 } |
| 92 | 89 |
| 93 return next(); | 90 return next(); |
| 94 }); | 91 }); |
| 92 }; |
| 95 | 93 |
| 96 index++; | 94 // We must iterate manually here, because JSHydra does not generate correct |
| 95 // code for let..of over non-array iterables. |
| 96 let it = callees[Symbol.iterator](); |
| 97 for (let next = it.next(), i = 0; !next.done; next = it.next(), i++) |
| 98 { |
| 99 // This must be a function call, because the value of i is evaluated |
| 100 // lazily. let inside a loop does automatically get a closure, but JSHydra |
| 101 // translates let to var so we lose that benefit. |
| 102 chain(next.value, i); |
| 97 } | 103 } |
| 98 | 104 |
| 99 return promise; | 105 return promise; |
| 100 } | 106 } |
| 101 | 107 |
| 102 function parseDomains(domains, included, excluded) | 108 function parseDomains(domains, included, excluded) |
| 103 { | 109 { |
| 104 for (let domain in domains) | 110 for (let domain in domains) |
| 105 { | 111 { |
| 106 if (domain != "") | 112 if (domain != "") |
| (...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 .then(rules => | 1327 .then(rules => |
| 1322 { | 1328 { |
| 1323 ruleGroups[index] = rules; | 1329 ruleGroups[index] = rules; |
| 1324 return next(); | 1330 return next(); |
| 1325 }); | 1331 }); |
| 1326 } | 1332 } |
| 1327 | 1333 |
| 1328 return next(); | 1334 return next(); |
| 1329 }); | 1335 }); |
| 1330 }; | 1336 }; |
| OLD | NEW |