| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 15 matching lines...) Expand all Loading... |
| 26 let scope = {exports: {}}; | 26 let scope = {exports: {}}; |
| 27 require.scopes[module] = require.modules[module](scope, scope.exports); | 27 require.scopes[module] = require.modules[module](scope, scope.exports); |
| 28 } | 28 } |
| 29 return require.scopes[module]; | 29 return require.scopes[module]; |
| 30 } | 30 } |
| 31 require.modules = Object.create(null); | 31 require.modules = Object.create(null); |
| 32 require.scopes = Object.create(null); | 32 require.scopes = Object.create(null); |
| 33 | 33 |
| 34 function importAll(module, globalObj) | 34 function importAll(module, globalObj) |
| 35 { | 35 { |
| 36 var exports = require(module); | 36 let exports = require(module); |
| 37 for (var key in exports) | 37 for (let key in exports) |
| 38 globalObj[key] = exports[key]; | 38 globalObj[key] = exports[key]; |
| 39 } | 39 } |
| 40 | 40 |
| 41 onShutdown = { | 41 onShutdown = { |
| 42 done: false, | 42 done: false, |
| 43 add: function() {}, | 43 add: () => {}, |
| 44 remove: function() {} | 44 remove: () => {} |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 // | 47 // |
| 48 // XPCOM emulation | 48 // XPCOM emulation |
| 49 // | 49 // |
| 50 | 50 |
| 51 var Components = | 51 let Components = |
| 52 { | 52 { |
| 53 interfaces: | 53 interfaces: |
| 54 { | 54 { |
| 55 nsIFile: {DIRECTORY_TYPE: 0}, | 55 nsIFile: {DIRECTORY_TYPE: 0}, |
| 56 nsIFileURL: function() {}, | 56 nsIFileURL: () => {}, |
| 57 nsIHttpChannel: function() {}, | 57 nsIHttpChannel: () => {}, |
| 58 nsITimer: {TYPE_REPEATING_SLACK: 0}, | 58 nsITimer: {TYPE_REPEATING_SLACK: 0}, |
| 59 nsIInterfaceRequestor: null, | 59 nsIInterfaceRequestor: null, |
| 60 nsIChannelEventSink: null | 60 nsIChannelEventSink: null |
| 61 }, | 61 }, |
| 62 classes: | 62 classes: |
| 63 { | 63 { |
| 64 "@mozilla.org/timer;1": | 64 "@mozilla.org/timer;1": |
| 65 { | 65 { |
| 66 createInstance: function() | 66 createInstance: () => new FakeTimer() |
| 67 { | |
| 68 return new FakeTimer(); | |
| 69 } | |
| 70 }, | 67 }, |
| 71 "@mozilla.org/xmlextras/xmlhttprequest;1": | 68 "@mozilla.org/xmlextras/xmlhttprequest;1": |
| 72 { | 69 { |
| 73 createInstance: function() | 70 createInstance: () => new XMLHttpRequest() |
| 74 { | |
| 75 return new XMLHttpRequest(); | |
| 76 } | |
| 77 } | 71 } |
| 78 }, | 72 }, |
| 79 results: {}, | 73 results: {}, |
| 80 utils: { | 74 utils: { |
| 81 import: function() | 75 import: () => |
| 82 { | 76 { |
| 83 }, | 77 }, |
| 84 reportError: function(e) | 78 reportError: e => |
| 85 { | 79 { |
| 86 console.error(e); | 80 console.error(e); |
| 87 console.trace(); | 81 console.trace(); |
| 88 } | 82 } |
| 89 }, | 83 }, |
| 90 manager: null, | 84 manager: null, |
| 91 ID: function() | 85 ID: () => null |
| 92 { | |
| 93 return null; | |
| 94 } | |
| 95 }; | 86 }; |
| 96 const Cc = Components.classes; | 87 const Cc = Components.classes; |
| 97 const Ci = Components.interfaces; | 88 const Ci = Components.interfaces; |
| 98 const Cr = Components.results; | 89 const Cr = Components.results; |
| 99 const Cu = Components.utils; | 90 const Cu = Components.utils; |
| 100 | 91 |
| 101 var XPCOMUtils = | 92 let XPCOMUtils = |
| 102 { | 93 { |
| 103 generateQI: function() {} | 94 generateQI: () => {} |
| 104 }; | 95 }; |
| 105 | 96 |
| 106 // | 97 // |
| 107 // Fake nsIFile implementation for our I/O | 98 // Fake nsIFile implementation for our I/O |
| 108 // | 99 // |
| 109 | 100 |
| 110 function FakeFile(path) | 101 function FakeFile(path) |
| 111 { | 102 { |
| 112 this.path = path; | 103 this.path = path; |
| 113 } | 104 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 124 append: function(path) | 115 append: function(path) |
| 125 { | 116 { |
| 126 this.path += path; | 117 this.path += path; |
| 127 }, | 118 }, |
| 128 clone: function() | 119 clone: function() |
| 129 { | 120 { |
| 130 return new FakeFile(this.path); | 121 return new FakeFile(this.path); |
| 131 }, | 122 }, |
| 132 get parent() | 123 get parent() |
| 133 { | 124 { |
| 134 return {create: function() {}}; | 125 return {create: () => {}}; |
| 135 }, | 126 }, |
| 136 normalize: function() {} | 127 normalize: () => {} |
| 137 }; | 128 }; |
| 138 | 129 |
| 139 // | 130 // |
| 140 // Services.jsm module emulation | 131 // Services.jsm module emulation |
| 141 // | 132 // |
| 142 | 133 |
| 143 var Services = | 134 let Services = |
| 144 { | 135 { |
| 145 obs: { | 136 obs: { |
| 146 addObserver: function() {}, | 137 addObserver: () => {}, |
| 147 removeObserver: function() {} | 138 removeObserver: () => {} |
| 148 }, | 139 }, |
| 149 vc: { | 140 vc: { |
| 150 compare: function(v1, v2) | 141 compare: (v1, v2) => |
| 151 { | 142 { |
| 152 function parsePart(s) | 143 function parsePart(s) |
| 153 { | 144 { |
| 154 if (!s) | 145 if (!s) |
| 155 return parsePart("0"); | 146 return parsePart("0"); |
| 156 | 147 |
| 157 var part = { | 148 let part = { |
| 158 numA: 0, | 149 numA: 0, |
| 159 strB: "", | 150 strB: "", |
| 160 numC: 0, | 151 numC: 0, |
| 161 extraD: "" | 152 extraD: "" |
| 162 }; | 153 }; |
| 163 | 154 |
| 164 if (s === "*") | 155 if (s === "*") |
| 165 { | 156 { |
| 166 part.numA = Number.MAX_VALUE; | 157 part.numA = Number.MAX_VALUE; |
| 167 return part; | 158 return part; |
| 168 } | 159 } |
| 169 | 160 |
| 170 var matches = s.match(/(\d*)(\D*)(\d*)(.*)/); | 161 let matches = s.match(/(\d*)(\D*)(\d*)(.*)/); |
| 171 part.numA = parseInt(matches[1], 10) || part.numA; | 162 part.numA = parseInt(matches[1], 10) || part.numA; |
| 172 part.strB = matches[2] || part.strB; | 163 part.strB = matches[2] || part.strB; |
| 173 part.numC = parseInt(matches[3], 10) || part.numC; | 164 part.numC = parseInt(matches[3], 10) || part.numC; |
| 174 part.extraD = matches[4] || part.extraD; | 165 part.extraD = matches[4] || part.extraD; |
| 175 | 166 |
| 176 if (part.strB == "+") | 167 if (part.strB == "+") |
| 177 { | 168 { |
| 178 part.numA++; | 169 part.numA++; |
| 179 part.strB = "pre"; | 170 part.strB = "pre"; |
| 180 } | 171 } |
| 181 | 172 |
| 182 return part; | 173 return part; |
| 183 } | 174 } |
| 184 | 175 |
| 185 function comparePartElement(s1, s2) | 176 function comparePartElement(s1, s2) |
| 186 { | 177 { |
| 187 if (s1 === "" && s2 !== "") | 178 if (s1 === "" && s2 !== "") |
| 188 return 1; | 179 return 1; |
| 189 if (s1 !== "" && s2 === "") | 180 if (s1 !== "" && s2 === "") |
| 190 return -1; | 181 return -1; |
| 191 return s1 === s2 ? 0 : (s1 > s2 ? 1 : -1); | 182 return s1 === s2 ? 0 : (s1 > s2 ? 1 : -1); |
| 192 } | 183 } |
| 193 | 184 |
| 194 function compareParts(p1, p2) | 185 function compareParts(p1, p2) |
| 195 { | 186 { |
| 196 var result = 0; | 187 let result = 0; |
| 197 var elements = ["numA", "strB", "numC", "extraD"]; | 188 let elements = ["numA", "strB", "numC", "extraD"]; |
| 198 elements.some(function(element) | 189 elements.some(element => |
| 199 { | 190 { |
| 200 result = comparePartElement(p1[element], p2[element]); | 191 result = comparePartElement(p1[element], p2[element]); |
| 201 return result; | 192 return result; |
| 202 }); | 193 }); |
| 203 return result; | 194 return result; |
| 204 } | 195 } |
| 205 | 196 |
| 206 var parts1 = v1.split("."); | 197 let parts1 = v1.split("."); |
| 207 var parts2 = v2.split("."); | 198 let parts2 = v2.split("."); |
| 208 for (var i = 0; i < Math.max(parts1.length, parts2.length); i++) | 199 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) |
| 209 { | 200 { |
| 210 var result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); | 201 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); |
| 211 if (result) | 202 if (result) |
| 212 return result; | 203 return result; |
| 213 } | 204 } |
| 214 return 0; | 205 return 0; |
| 215 } | 206 } |
| 216 } | 207 } |
| 217 } | 208 } |
| 218 | 209 |
| 219 // | 210 // |
| 220 // FileUtils.jsm module emulation | 211 // FileUtils.jsm module emulation |
| 221 // | 212 // |
| 222 | 213 |
| 223 var FileUtils = | 214 let FileUtils = |
| 224 { | 215 { |
| 225 PERMS_DIRECTORY: 0 | 216 PERMS_DIRECTORY: 0 |
| 226 }; | 217 }; |
| 227 | 218 |
| 228 function FakeTimer() | 219 function FakeTimer() |
| 229 { | 220 { |
| 230 } | 221 } |
| 231 FakeTimer.prototype = | 222 FakeTimer.prototype = |
| 232 { | 223 { |
| 233 delay: 0, | 224 delay: 0, |
| 234 callback: null, | 225 callback: null, |
| 235 initWithCallback: function(callback, delay) | 226 initWithCallback: function(callback, delay) |
| 236 { | 227 { |
| 237 this.callback = callback; | 228 this.callback = callback; |
| 238 this.delay = delay; | 229 this.delay = delay; |
| 239 this.scheduleTimeout(); | 230 this.scheduleTimeout(); |
| 240 }, | 231 }, |
| 241 scheduleTimeout: function() | 232 scheduleTimeout: function() |
| 242 { | 233 { |
| 243 var me = this; | 234 window.setTimeout(() => |
| 244 window.setTimeout(function() | |
| 245 { | 235 { |
| 246 try | 236 try |
| 247 { | 237 { |
| 248 me.callback(); | 238 this.callback(); |
| 249 } | 239 } |
| 250 catch(e) | 240 catch(e) |
| 251 { | 241 { |
| 252 Cu.reportError(e); | 242 Cu.reportError(e); |
| 253 } | 243 } |
| 254 me.scheduleTimeout(); | 244 this.scheduleTimeout(); |
| 255 }, this.delay); | 245 }, this.delay); |
| 256 } | 246 } |
| 257 }; | 247 }; |
| 258 | 248 |
| 259 // | 249 // |
| 260 // Add a channel property to XMLHttpRequest, Synchronizer needs it | 250 // Add a channel property to XMLHttpRequest, Synchronizer needs it |
| 261 // | 251 // |
| 262 | 252 |
| 263 XMLHttpRequest.prototype.channel = | 253 XMLHttpRequest.prototype.channel = |
| 264 { | 254 { |
| 265 status: -1, | 255 status: -1, |
| 266 notificationCallbacks: {}, | 256 notificationCallbacks: {}, |
| 267 loadFlags: 0, | 257 loadFlags: 0, |
| 268 INHIBIT_CACHING: 0, | 258 INHIBIT_CACHING: 0, |
| 269 VALIDATE_ALWAYS: 0, | 259 VALIDATE_ALWAYS: 0, |
| 270 QueryInterface: function() | 260 QueryInterface: function() |
| 271 { | 261 { |
| 272 return this; | 262 return this; |
| 273 } | 263 } |
| 274 }; | 264 }; |
| OLD | NEW |