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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 { | 62 { |
63 createInstance() { return new FakeTimer(); } | 63 createInstance() { return new FakeTimer(); } |
64 }, | 64 }, |
65 "@mozilla.org/xmlextras/xmlhttprequest;1": | 65 "@mozilla.org/xmlextras/xmlhttprequest;1": |
66 { | 66 { |
67 createInstance() { return new XMLHttpRequest(); } | 67 createInstance() { return new XMLHttpRequest(); } |
68 } | 68 } |
69 }, | 69 }, |
70 results: {}, | 70 results: {}, |
71 utils: { | 71 utils: { |
72 import(resource) | 72 import() |
73 { | 73 { |
74 let match = /^resource:\/\/gre\/modules\/(.+)\.jsm$/.exec(resource); | |
75 let resourceName = match && match[1]; | |
76 if (resourceName && Cu.import.resources.has(resourceName)) | |
77 return {[resourceName]: Cu.import.resources.get(resourceName)}; | |
78 | |
79 throw new Error( | |
80 "Attempt to import unknown JavaScript module " + resource | |
81 ); | |
82 }, | 74 }, |
83 reportError(e) | 75 reportError(e) |
84 { | 76 { |
85 console.error(e); | 77 console.error(e); |
86 console.trace(); | 78 console.trace(); |
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 Cu.import.resources = new Map(); | 89 let XPCOMUtils = { |
98 | |
99 Cu.import.resources.set("XPCOMUtils", { | |
100 generateQI() {} | 90 generateQI() {} |
101 }); | 91 }; |
102 | 92 |
103 // | 93 // |
104 // Fake nsIFile implementation for our I/O | 94 // Fake nsIFile implementation for our I/O |
105 // | 95 // |
106 | 96 |
107 function FakeFile(path) | 97 function FakeFile(path) |
108 { | 98 { |
109 this.path = path; | 99 this.path = path; |
110 } | 100 } |
111 FakeFile.prototype = | 101 FakeFile.prototype = |
(...skipping 18 matching lines...) Expand all Loading... |
130 { | 120 { |
131 return {create() {}}; | 121 return {create() {}}; |
132 }, | 122 }, |
133 normalize() {} | 123 normalize() {} |
134 }; | 124 }; |
135 | 125 |
136 // | 126 // |
137 // Services.jsm module emulation | 127 // Services.jsm module emulation |
138 // | 128 // |
139 | 129 |
140 Cu.import.resources.set("Services", { | 130 let Services = { |
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 Cu.import.resources.set("FileUtils", { | 209 let FileUtils = { |
220 PERMS_DIRECTORY: 0 | 210 PERMS_DIRECTORY: 0 |
221 }); | 211 }; |
222 | 212 |
223 function FakeTimer() | 213 function FakeTimer() |
224 { | 214 { |
225 } | 215 } |
226 FakeTimer.prototype = { | 216 FakeTimer.prototype = |
| 217 { |
227 delay: 0, | 218 delay: 0, |
228 callback: null, | 219 callback: null, |
229 initWithCallback(callback, delay) | 220 initWithCallback(callback, delay) |
230 { | 221 { |
231 this.callback = callback; | 222 this.callback = callback; |
232 this.delay = delay; | 223 this.delay = delay; |
233 this.scheduleTimeout(); | 224 this.scheduleTimeout(); |
234 }, | 225 }, |
235 scheduleTimeout() | 226 scheduleTimeout() |
236 { | 227 { |
(...skipping 20 matching lines...) Expand all Loading... |
257 status: -1, | 248 status: -1, |
258 notificationCallbacks: {}, | 249 notificationCallbacks: {}, |
259 loadFlags: 0, | 250 loadFlags: 0, |
260 INHIBIT_CACHING: 0, | 251 INHIBIT_CACHING: 0, |
261 VALIDATE_ALWAYS: 0, | 252 VALIDATE_ALWAYS: 0, |
262 QueryInterface() | 253 QueryInterface() |
263 { | 254 { |
264 return this; | 255 return this; |
265 } | 256 } |
266 }; | 257 }; |
LEFT | RIGHT |