Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/compat.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Patch Set: Rebased Created March 17, 2017, 12:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include.preload.js ('k') | lib/csp.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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:
68 { 60 {
69 "@mozilla.org/timer;1": 61 "@mozilla.org/timer;1":
70 { 62 {
71 createInstance() { return new FakeTimer(); } 63 createInstance() { return new FakeTimer(); }
72 }, 64 },
73 "@mozilla.org/xmlextras/xmlhttprequest;1": 65 "@mozilla.org/xmlextras/xmlhttprequest;1":
74 { 66 {
75 createInstance() { return new XMLHttpRequest(); } 67 createInstance() { return new XMLHttpRequest(); }
76 } 68 }
77 }, 69 },
78 results: {}, 70 results: {},
79 utils: { 71 utils: {
80 import() 72 import(resource)
81 { 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 }, 82 },
83 reportError(e) 83 reportError(e)
84 { 84 {
85 console.error(e); 85 console.error(e);
86 console.trace(); 86 console.trace();
87 } 87 }
88 }, 88 },
89 manager: null, 89 manager: null,
90 ID() { return null; } 90 ID() { return null; }
91 }; 91 };
92 const Cc = Components.classes; 92 const Cc = Components.classes;
93 const Ci = Components.interfaces; 93 const Ci = Components.interfaces;
94 const Cr = Components.results; 94 const Cr = Components.results;
95 const Cu = Components.utils; 95 const Cu = Components.utils;
96 96
97 let XPCOMUtils = 97 Cu.import.resources = new Map();
98 { 98
99 Cu.import.resources.set("XPCOMUtils", {
99 generateQI() {} 100 generateQI() {}
100 }; 101 });
101 102
102 // 103 //
103 // Fake nsIFile implementation for our I/O 104 // Fake nsIFile implementation for our I/O
104 // 105 //
105 106
106 function FakeFile(path) 107 function FakeFile(path)
107 { 108 {
108 this.path = path; 109 this.path = path;
109 } 110 }
110 FakeFile.prototype = 111 FakeFile.prototype =
(...skipping 18 matching lines...) Expand all
129 { 130 {
130 return {create() {}}; 131 return {create() {}};
131 }, 132 },
132 normalize() {} 133 normalize() {}
133 }; 134 };
134 135
135 // 136 //
136 // Services.jsm module emulation 137 // Services.jsm module emulation
137 // 138 //
138 139
139 let Services = 140 Cu.import.resources.set("Services", {
140 {
141 obs: { 141 obs: {
142 addObserver() {}, 142 addObserver() {},
143 removeObserver() {} 143 removeObserver() {}
144 }, 144 },
145 vc: { 145 vc: {
146 compare(v1, v2) 146 compare(v1, v2)
147 { 147 {
148 function parsePart(s) 148 function parsePart(s)
149 { 149 {
150 if (!s) 150 if (!s)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 let parts2 = v2.split("."); 203 let parts2 = v2.split(".");
204 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) 204 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++)
205 { 205 {
206 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); 206 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i]));
207 if (result) 207 if (result)
208 return result; 208 return result;
209 } 209 }
210 return 0; 210 return 0;
211 } 211 }
212 } 212 }
213 } 213 });
214 214
215 // 215 //
216 // FileUtils.jsm module emulation 216 // FileUtils.jsm module emulation
217 // 217 //
218 218
219 let FileUtils = 219 Cu.import.resources.set("FileUtils", {
220 {
221 PERMS_DIRECTORY: 0 220 PERMS_DIRECTORY: 0
222 }; 221 });
223 222
224 function FakeTimer() 223 function FakeTimer()
225 { 224 {
226 } 225 }
227 FakeTimer.prototype = 226 FakeTimer.prototype = {
228 {
229 delay: 0, 227 delay: 0,
230 callback: null, 228 callback: null,
231 initWithCallback(callback, delay) 229 initWithCallback(callback, delay)
232 { 230 {
233 this.callback = callback; 231 this.callback = callback;
234 this.delay = delay; 232 this.delay = delay;
235 this.scheduleTimeout(); 233 this.scheduleTimeout();
236 }, 234 },
237 scheduleTimeout() 235 scheduleTimeout()
238 { 236 {
239 window.setTimeout(() => 237 window.setTimeout(() =>
240 { 238 {
241 try 239 try
242 { 240 {
243 this.callback(); 241 this.callback();
244 } 242 }
245 catch(e) 243 catch (e)
246 { 244 {
247 Cu.reportError(e); 245 Cu.reportError(e);
248 } 246 }
249 this.scheduleTimeout(); 247 this.scheduleTimeout();
250 }, this.delay); 248 }, this.delay);
251 } 249 }
252 }; 250 };
253 251
254 // 252 //
255 // Add a channel property to XMLHttpRequest, Synchronizer needs it 253 // Add a channel property to XMLHttpRequest, Synchronizer needs it
256 // 254 //
257 255
258 XMLHttpRequest.prototype.channel = 256 XMLHttpRequest.prototype.channel = {
259 {
260 status: -1, 257 status: -1,
261 notificationCallbacks: {}, 258 notificationCallbacks: {},
262 loadFlags: 0, 259 loadFlags: 0,
263 INHIBIT_CACHING: 0, 260 INHIBIT_CACHING: 0,
264 VALIDATE_ALWAYS: 0, 261 VALIDATE_ALWAYS: 0,
265 QueryInterface() 262 QueryInterface()
266 { 263 {
267 return this; 264 return this;
268 } 265 }
269 }; 266 };
OLDNEW
« no previous file with comments | « include.preload.js ('k') | lib/csp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld