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 15 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 |
53 function nsIFileURL() {} | 46 function nsIFileURL() {} |
54 function nsIHttpChannel() {} | 47 function nsIHttpChannel() {} |
55 | 48 |
56 let Components = | 49 let Components = { |
57 { | |
58 interfaces: | 50 interfaces: |
59 { | 51 { |
60 nsIFile: {DIRECTORY_TYPE: 0}, | 52 nsIFile: {DIRECTORY_TYPE: 0}, |
61 nsIFileURL, | 53 nsIFileURL, |
62 nsIHttpChannel, | 54 nsIHttpChannel, |
63 nsITimer: {TYPE_REPEATING_SLACK: 0}, | 55 nsITimer: {TYPE_REPEATING_SLACK: 0}, |
64 nsIInterfaceRequestor: null, | 56 nsIInterfaceRequestor: null, |
65 nsIChannelEventSink: null | 57 nsIChannelEventSink: null |
66 }, | 58 }, |
67 classes: | 59 classes: |
(...skipping 19 matching lines...) Expand all Loading... |
87 } | 79 } |
88 }, | 80 }, |
89 manager: null, | 81 manager: null, |
90 ID() { return null; } | 82 ID() { return null; } |
91 }; | 83 }; |
92 const Cc = Components.classes; | 84 const Cc = Components.classes; |
93 const Ci = Components.interfaces; | 85 const Ci = Components.interfaces; |
94 const Cr = Components.results; | 86 const Cr = Components.results; |
95 const Cu = Components.utils; | 87 const Cu = Components.utils; |
96 | 88 |
97 let XPCOMUtils = | 89 let XPCOMUtils = { |
98 { | |
99 generateQI() {} | 90 generateQI() {} |
100 }; | 91 }; |
101 | 92 |
102 // | 93 // |
103 // Fake nsIFile implementation for our I/O | 94 // Fake nsIFile implementation for our I/O |
104 // | 95 // |
105 | 96 |
106 function FakeFile(path) | 97 function FakeFile(path) |
107 { | 98 { |
108 this.path = path; | 99 this.path = path; |
(...skipping 20 matching lines...) Expand all Loading... |
129 { | 120 { |
130 return {create() {}}; | 121 return {create() {}}; |
131 }, | 122 }, |
132 normalize() {} | 123 normalize() {} |
133 }; | 124 }; |
134 | 125 |
135 // | 126 // |
136 // Services.jsm module emulation | 127 // Services.jsm module emulation |
137 // | 128 // |
138 | 129 |
139 let Services = | 130 let Services = { |
140 { | |
141 obs: { | 131 obs: { |
142 addObserver() {}, | 132 addObserver() {}, |
143 removeObserver() {} | 133 removeObserver() {} |
144 }, | 134 }, |
145 vc: { | 135 vc: { |
146 compare(v1, v2) | 136 compare(v1, v2) |
147 { | 137 { |
148 function parsePart(s) | 138 function parsePart(s) |
149 { | 139 { |
150 if (!s) | 140 if (!s) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 let parts2 = v2.split("."); | 193 let parts2 = v2.split("."); |
204 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++) |
205 { | 195 { |
206 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); | 196 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); |
207 if (result) | 197 if (result) |
208 return result; | 198 return result; |
209 } | 199 } |
210 return 0; | 200 return 0; |
211 } | 201 } |
212 } | 202 } |
213 } | 203 }; |
214 | 204 |
215 // | 205 // |
216 // FileUtils.jsm module emulation | 206 // FileUtils.jsm module emulation |
217 // | 207 // |
218 | 208 |
219 let FileUtils = | 209 let FileUtils = { |
220 { | |
221 PERMS_DIRECTORY: 0 | 210 PERMS_DIRECTORY: 0 |
222 }; | 211 }; |
223 | 212 |
224 function FakeTimer() | 213 function FakeTimer() |
225 { | 214 { |
226 } | 215 } |
227 FakeTimer.prototype = | 216 FakeTimer.prototype = |
228 { | 217 { |
229 delay: 0, | 218 delay: 0, |
230 callback: null, | 219 callback: null, |
231 initWithCallback(callback, delay) | 220 initWithCallback(callback, delay) |
232 { | 221 { |
233 this.callback = callback; | 222 this.callback = callback; |
234 this.delay = delay; | 223 this.delay = delay; |
235 this.scheduleTimeout(); | 224 this.scheduleTimeout(); |
236 }, | 225 }, |
237 scheduleTimeout() | 226 scheduleTimeout() |
238 { | 227 { |
239 window.setTimeout(() => | 228 window.setTimeout(() => |
240 { | 229 { |
241 try | 230 try |
242 { | 231 { |
243 this.callback(); | 232 this.callback(); |
244 } | 233 } |
245 catch(e) | 234 catch (e) |
246 { | 235 { |
247 Cu.reportError(e); | 236 Cu.reportError(e); |
248 } | 237 } |
249 this.scheduleTimeout(); | 238 this.scheduleTimeout(); |
250 }, this.delay); | 239 }, this.delay); |
251 } | 240 } |
252 }; | 241 }; |
253 | 242 |
254 // | 243 // |
255 // Add a channel property to XMLHttpRequest, Synchronizer needs it | 244 // Add a channel property to XMLHttpRequest, Synchronizer needs it |
256 // | 245 // |
257 | 246 |
258 XMLHttpRequest.prototype.channel = | 247 XMLHttpRequest.prototype.channel = { |
259 { | |
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 }; |
OLD | NEW |