| Index: lib/abp2blocklist.js |
| =================================================================== |
| --- a/lib/abp2blocklist.js |
| +++ b/lib/abp2blocklist.js |
| @@ -63,42 +63,48 @@ |
| } |
| function async(callees, mapFunction) |
| { |
| if (!(Symbol.iterator in callees)) |
| callees = [callees]; |
| let lastPause = Date.now(); |
| - let index = 0; |
| let promise = Promise.resolve(); |
| - for (let next of callees) |
| + let chain = (next, index) => |
| { |
| - let currentIndex = index; |
| - |
| promise = promise.then(() => |
| { |
| if (mapFunction) |
| - next = mapFunction(next, currentIndex); |
| + next = mapFunction(next, index); |
| // If it has been 100ms or longer since the last call, take a pause. This |
| // keeps the browser from freezing up. |
| let now = Date.now(); |
| if (now - lastPause >= 100) |
| { |
| lastPause = now; |
| return callLater(next); |
| } |
| return next(); |
| }); |
| + }; |
| - index++; |
| + // We must iterate manually here, because JSHydra does not generate correct |
| + // code for let..of over non-array iterables. |
| + let it = callees[Symbol.iterator](); |
| + for (let next = it.next(), i = 0; !next.done; next = it.next(), i++) |
| + { |
| + // This must be a function call, because the value of i is evaluated |
| + // lazily. let inside a loop does automatically get a closure, but JSHydra |
| + // translates let to var so we lose that benefit. |
| + chain(next.value, i); |
| } |
| return promise; |
| } |
| function parseDomains(domains, included, excluded) |
| { |
| for (let domain in domains) |