| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 26 if (!(module in require.scopes)) | 26 if (!(module in require.scopes)) |
| 27 { | 27 { |
| 28 let scope = {exports: {}}; | 28 let scope = {exports: {}}; |
| 29 require.scopes[module] = require.modules[module](scope, scope.exports); | 29 require.scopes[module] = require.modules[module](scope, scope.exports); |
| 30 } | 30 } |
| 31 return require.scopes[module]; | 31 return require.scopes[module]; |
| 32 } | 32 } |
| 33 require.modules = Object.create(null); | 33 require.modules = Object.create(null); |
| 34 require.scopes = Object.create(null); | 34 require.scopes = Object.create(null); |
| 35 | 35 |
| 36 function importAll(module, globalObj) | |
| 37 { | |
| 38 let exports = require(module); | |
| 39 for (let key in exports) | |
| 40 globalObj[key] = exports[key]; | |
| 41 } | |
| 42 | |
| 43 let onShutdown = { | 36 let onShutdown = { |
| 44 done: false, | 37 done: false, |
| 45 add() {}, | 38 add() {}, |
| 46 remove() {} | 39 remove() {} |
| 47 }; | 40 }; |
| 48 | 41 |
| 49 // | 42 // |
| 50 // XPCOM emulation | 43 // XPCOM emulation |
| 51 // | 44 // |
| 52 | 45 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 69 { | 62 { |
| 70 createInstance() { return new FakeTimer(); } | 63 createInstance() { return new FakeTimer(); } |
| 71 }, | 64 }, |
| 72 "@mozilla.org/xmlextras/xmlhttprequest;1": | 65 "@mozilla.org/xmlextras/xmlhttprequest;1": |
| 73 { | 66 { |
| 74 createInstance() { return new XMLHttpRequest(); } | 67 createInstance() { return new XMLHttpRequest(); } |
| 75 } | 68 } |
| 76 }, | 69 }, |
| 77 results: {}, | 70 results: {}, |
| 78 utils: { | 71 utils: { |
| 79 import(resource) | 72 import() |
| 80 { | 73 { |
| 81 let match = /^resource:\/\/gre\/modules\/(.+)\.jsm$/.exec(resource); | |
| 82 let resourceName = match && match[1]; | |
| 83 if (resourceName && Cu.import.resources.has(resourceName)) | |
| 84 return {[resourceName]: Cu.import.resources.get(resourceName)}; | |
|
Wladimir Palant
2017/03/14 13:03:25
As with the implementation in adblockplusui, this
kzar
2017/03/15 04:57:47
Done.
| |
| 85 }, | 74 }, |
| 86 reportError(e) | 75 reportError(e) |
| 87 { | 76 { |
| 88 console.error(e); | 77 console.error(e); |
| 89 console.trace(); | 78 console.trace(); |
| 90 } | 79 } |
| 91 }, | 80 }, |
| 92 manager: null, | 81 manager: null, |
| 93 ID() { return null; } | 82 ID() { return null; } |
| 94 }; | 83 }; |
| 95 const Cc = Components.classes; | 84 const Cc = Components.classes; |
| 96 const Ci = Components.interfaces; | 85 const Ci = Components.interfaces; |
| 97 const Cr = Components.results; | 86 const Cr = Components.results; |
| 98 const Cu = Components.utils; | 87 const Cu = Components.utils; |
| 99 | 88 |
| 100 Cu.import.resources = new Map(); | 89 let XPCOMUtils = { |
| 101 | |
| 102 Cu.import.resources.set("XPCOMUtils", { | |
| 103 generateQI() {} | 90 generateQI() {} |
| 104 }); | 91 }; |
| 105 | 92 |
| 106 // | 93 // |
| 107 // Fake nsIFile implementation for our I/O | 94 // Fake nsIFile implementation for our I/O |
| 108 // | 95 // |
| 109 | 96 |
| 110 function FakeFile(path) | 97 function FakeFile(path) |
| 111 { | 98 { |
| 112 this.path = path; | 99 this.path = path; |
| 113 } | 100 } |
| 114 FakeFile.prototype = | 101 FakeFile.prototype = |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 133 { | 120 { |
| 134 return {create() {}}; | 121 return {create() {}}; |
| 135 }, | 122 }, |
| 136 normalize() {} | 123 normalize() {} |
| 137 }; | 124 }; |
| 138 | 125 |
| 139 // | 126 // |
| 140 // Services.jsm module emulation | 127 // Services.jsm module emulation |
| 141 // | 128 // |
| 142 | 129 |
| 143 Cu.import.resources.set("Services", { | 130 let Services = { |
| 144 obs: { | 131 obs: { |
| 145 addObserver() {}, | 132 addObserver() {}, |
| 146 removeObserver() {} | 133 removeObserver() {} |
| 147 }, | 134 }, |
| 148 vc: { | 135 vc: { |
| 149 compare(v1, v2) | 136 compare(v1, v2) |
| 150 { | 137 { |
| 151 function parsePart(s) | 138 function parsePart(s) |
| 152 { | 139 { |
| 153 if (!s) | 140 if (!s) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 let parts2 = v2.split("."); | 193 let parts2 = v2.split("."); |
| 207 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) | 194 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) |
| 208 { | 195 { |
| 209 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); | 196 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); |
| 210 if (result) | 197 if (result) |
| 211 return result; | 198 return result; |
| 212 } | 199 } |
| 213 return 0; | 200 return 0; |
| 214 } | 201 } |
| 215 } | 202 } |
| 216 }); | 203 }; |
| 217 | 204 |
| 218 // | 205 // |
| 219 // FileUtils.jsm module emulation | 206 // FileUtils.jsm module emulation |
| 220 // | 207 // |
| 221 | 208 |
| 222 Cu.import.resources.set("FileUtils", { | 209 let FileUtils = { |
| 223 PERMS_DIRECTORY: 0 | 210 PERMS_DIRECTORY: 0 |
| 224 }); | 211 }; |
| 225 | 212 |
| 226 function FakeTimer() | 213 function FakeTimer() |
| 227 { | 214 { |
| 228 } | 215 } |
| 229 FakeTimer.prototype = { | 216 FakeTimer.prototype = |
| 217 { | |
| 230 delay: 0, | 218 delay: 0, |
| 231 callback: null, | 219 callback: null, |
| 232 initWithCallback(callback, delay) | 220 initWithCallback(callback, delay) |
| 233 { | 221 { |
| 234 this.callback = callback; | 222 this.callback = callback; |
| 235 this.delay = delay; | 223 this.delay = delay; |
| 236 this.scheduleTimeout(); | 224 this.scheduleTimeout(); |
| 237 }, | 225 }, |
| 238 scheduleTimeout() | 226 scheduleTimeout() |
| 239 { | 227 { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 260 status: -1, | 248 status: -1, |
| 261 notificationCallbacks: {}, | 249 notificationCallbacks: {}, |
| 262 loadFlags: 0, | 250 loadFlags: 0, |
| 263 INHIBIT_CACHING: 0, | 251 INHIBIT_CACHING: 0, |
| 264 VALIDATE_ALWAYS: 0, | 252 VALIDATE_ALWAYS: 0, |
| 265 QueryInterface() | 253 QueryInterface() |
| 266 { | 254 { |
| 267 return this; | 255 return this; |
| 268 } | 256 } |
| 269 }; | 257 }; |
| LEFT | RIGHT |