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-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 |
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 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
| 18 "use strict"; |
| 19 |
18 // | 20 // |
19 // Module framework stuff | 21 // Module framework stuff |
20 // | 22 // |
21 | 23 |
22 function require(module) | 24 function require(module) |
23 { | 25 { |
24 if (!(module in require.scopes)) | 26 if (!(module in require.scopes)) |
25 { | 27 { |
26 let scope = {exports: {}}; | 28 let scope = {exports: {}}; |
27 require.scopes[module] = require.modules[module](scope, scope.exports); | 29 require.scopes[module] = require.modules[module](scope, scope.exports); |
28 } | 30 } |
29 return require.scopes[module]; | 31 return require.scopes[module]; |
30 } | 32 } |
31 require.modules = Object.create(null); | 33 require.modules = Object.create(null); |
32 require.scopes = Object.create(null); | 34 require.scopes = Object.create(null); |
33 | 35 |
34 function importAll(module, globalObj) | 36 function importAll(module, globalObj) |
35 { | 37 { |
36 let exports = require(module); | 38 let exports = require(module); |
37 for (let key in exports) | 39 for (let key in exports) |
38 globalObj[key] = exports[key]; | 40 globalObj[key] = exports[key]; |
39 } | 41 } |
40 | 42 |
41 onShutdown = { | 43 let onShutdown = { |
42 done: false, | 44 done: false, |
43 add: () => {}, | 45 add() {}, |
44 remove: () => {} | 46 remove() {} |
45 }; | 47 }; |
46 | 48 |
47 // | 49 // |
48 // XPCOM emulation | 50 // XPCOM emulation |
49 // | 51 // |
50 | 52 |
51 let Components = | 53 let Components = |
52 { | 54 { |
53 interfaces: | 55 interfaces: |
54 { | 56 { |
55 nsIFile: {DIRECTORY_TYPE: 0}, | 57 nsIFile: {DIRECTORY_TYPE: 0}, |
56 nsIFileURL: () => {}, | 58 nsIFileURL() {}, |
57 nsIHttpChannel: () => {}, | 59 nsIHttpChannel() {}, |
58 nsITimer: {TYPE_REPEATING_SLACK: 0}, | 60 nsITimer: {TYPE_REPEATING_SLACK: 0}, |
59 nsIInterfaceRequestor: null, | 61 nsIInterfaceRequestor: null, |
60 nsIChannelEventSink: null | 62 nsIChannelEventSink: null |
61 }, | 63 }, |
62 classes: | 64 classes: |
63 { | 65 { |
64 "@mozilla.org/timer;1": | 66 "@mozilla.org/timer;1": |
65 { | 67 { |
66 createInstance: () => new FakeTimer() | 68 createInstance() { return new FakeTimer(); } |
67 }, | 69 }, |
68 "@mozilla.org/xmlextras/xmlhttprequest;1": | 70 "@mozilla.org/xmlextras/xmlhttprequest;1": |
69 { | 71 { |
70 createInstance: () => new XMLHttpRequest() | 72 createInstance() { return new XMLHttpRequest(); } |
71 } | 73 } |
72 }, | 74 }, |
73 results: {}, | 75 results: {}, |
74 utils: { | 76 utils: { |
75 import: () => | 77 import() |
76 { | 78 { |
77 }, | 79 }, |
78 reportError: e => | 80 reportError(e) |
79 { | 81 { |
80 console.error(e); | 82 console.error(e); |
81 console.trace(); | 83 console.trace(); |
82 } | 84 } |
83 }, | 85 }, |
84 manager: null, | 86 manager: null, |
85 ID: () => null | 87 ID() { return null; } |
86 }; | 88 }; |
87 const Cc = Components.classes; | 89 const Cc = Components.classes; |
88 const Ci = Components.interfaces; | 90 const Ci = Components.interfaces; |
89 const Cr = Components.results; | 91 const Cr = Components.results; |
90 const Cu = Components.utils; | 92 const Cu = Components.utils; |
91 | 93 |
92 let XPCOMUtils = | 94 let XPCOMUtils = |
93 { | 95 { |
94 generateQI: () => {} | 96 generateQI() {} |
95 }; | 97 }; |
96 | 98 |
97 // | 99 // |
98 // Fake nsIFile implementation for our I/O | 100 // Fake nsIFile implementation for our I/O |
99 // | 101 // |
100 | 102 |
101 function FakeFile(path) | 103 function FakeFile(path) |
102 { | 104 { |
103 this.path = path; | 105 this.path = path; |
104 } | 106 } |
105 FakeFile.prototype = | 107 FakeFile.prototype = |
106 { | 108 { |
107 get leafName() | 109 get leafName() |
108 { | 110 { |
109 return this.path; | 111 return this.path; |
110 }, | 112 }, |
111 set leafName(value) | 113 set leafName(value) |
112 { | 114 { |
113 this.path = value; | 115 this.path = value; |
114 }, | 116 }, |
115 append: function(path) | 117 append(path) |
116 { | 118 { |
117 this.path += path; | 119 this.path += path; |
118 }, | 120 }, |
119 clone: function() | 121 clone() |
120 { | 122 { |
121 return new FakeFile(this.path); | 123 return new FakeFile(this.path); |
122 }, | 124 }, |
123 get parent() | 125 get parent() |
124 { | 126 { |
125 return {create: () => {}}; | 127 return {create() {}}; |
126 }, | 128 }, |
127 normalize: () => {} | 129 normalize() {} |
128 }; | 130 }; |
129 | 131 |
130 // | 132 // |
131 // Services.jsm module emulation | 133 // Services.jsm module emulation |
132 // | 134 // |
133 | 135 |
134 let Services = | 136 let Services = |
135 { | 137 { |
136 obs: { | 138 obs: { |
137 addObserver: () => {}, | 139 addObserver() {}, |
138 removeObserver: () => {} | 140 removeObserver() {} |
139 }, | 141 }, |
140 vc: { | 142 vc: { |
141 compare: (v1, v2) => | 143 compare(v1, v2) |
142 { | 144 { |
143 function parsePart(s) | 145 function parsePart(s) |
144 { | 146 { |
145 if (!s) | 147 if (!s) |
146 return parsePart("0"); | 148 return parsePart("0"); |
147 | 149 |
148 let part = { | 150 let part = { |
149 numA: 0, | 151 numA: 0, |
150 strB: "", | 152 strB: "", |
151 numC: 0, | 153 numC: 0, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 PERMS_DIRECTORY: 0 | 218 PERMS_DIRECTORY: 0 |
217 }; | 219 }; |
218 | 220 |
219 function FakeTimer() | 221 function FakeTimer() |
220 { | 222 { |
221 } | 223 } |
222 FakeTimer.prototype = | 224 FakeTimer.prototype = |
223 { | 225 { |
224 delay: 0, | 226 delay: 0, |
225 callback: null, | 227 callback: null, |
226 initWithCallback: function(callback, delay) | 228 initWithCallback(callback, delay) |
227 { | 229 { |
228 this.callback = callback; | 230 this.callback = callback; |
229 this.delay = delay; | 231 this.delay = delay; |
230 this.scheduleTimeout(); | 232 this.scheduleTimeout(); |
231 }, | 233 }, |
232 scheduleTimeout: function() | 234 scheduleTimeout() |
233 { | 235 { |
234 window.setTimeout(() => | 236 window.setTimeout(() => |
235 { | 237 { |
236 try | 238 try |
237 { | 239 { |
238 this.callback(); | 240 this.callback(); |
239 } | 241 } |
240 catch(e) | 242 catch(e) |
241 { | 243 { |
242 Cu.reportError(e); | 244 Cu.reportError(e); |
243 } | 245 } |
244 this.scheduleTimeout(); | 246 this.scheduleTimeout(); |
245 }, this.delay); | 247 }, this.delay); |
246 } | 248 } |
247 }; | 249 }; |
248 | 250 |
249 // | 251 // |
250 // Add a channel property to XMLHttpRequest, Synchronizer needs it | 252 // Add a channel property to XMLHttpRequest, Synchronizer needs it |
251 // | 253 // |
252 | 254 |
253 XMLHttpRequest.prototype.channel = | 255 XMLHttpRequest.prototype.channel = |
254 { | 256 { |
255 status: -1, | 257 status: -1, |
256 notificationCallbacks: {}, | 258 notificationCallbacks: {}, |
257 loadFlags: 0, | 259 loadFlags: 0, |
258 INHIBIT_CACHING: 0, | 260 INHIBIT_CACHING: 0, |
259 VALIDATE_ALWAYS: 0, | 261 VALIDATE_ALWAYS: 0, |
260 QueryInterface: function() | 262 QueryInterface() |
261 { | 263 { |
262 return this; | 264 return this; |
263 } | 265 } |
264 }; | 266 }; |
LEFT | RIGHT |