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

Side by Side Diff: lib/compat.js

Issue 29452181: Noissue - Merge current tip to Edge bookmark (Closed)
Patch Set: Created May 30, 2017, 3:49 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 | « inject.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-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 *
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"; 18 "use strict";
19 19
20 //
21 // Module framework stuff
22 //
23
24 function require(module)
25 {
26 if (!(module in require.scopes))
27 {
28 let scope = {exports: {}};
29 require.scopes[module] = require.modules[module](scope, scope.exports);
30 }
31 return require.scopes[module];
32 }
33 require.modules = Object.create(null);
34 require.scopes = Object.create(null);
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 = { 20 let onShutdown = {
44 done: false, 21 done: false,
45 add() {}, 22 add() {},
46 remove() {} 23 remove() {}
47 }; 24 };
48 25
49 // 26 //
50 // XPCOM emulation 27 // XPCOM emulation
51 // 28 //
52 29
53 let Components = 30 function nsIFileURL() {}
54 { 31 function nsIHttpChannel() {}
32
33 let Components = {
55 interfaces: 34 interfaces:
56 { 35 {
57 nsIFile: {DIRECTORY_TYPE: 0}, 36 nsIFile: {DIRECTORY_TYPE: 0},
58 nsIFileURL() {}, 37 nsIFileURL,
59 nsIHttpChannel() {}, 38 nsIHttpChannel,
60 nsITimer: {TYPE_REPEATING_SLACK: 0}, 39 nsITimer: {TYPE_REPEATING_SLACK: 0},
61 nsIInterfaceRequestor: null, 40 nsIInterfaceRequestor: null,
62 nsIChannelEventSink: null 41 nsIChannelEventSink: null
63 }, 42 },
64 classes: 43 classes:
65 { 44 {
66 "@mozilla.org/timer;1": 45 "@mozilla.org/timer;1":
67 { 46 {
68 createInstance() { return new FakeTimer(); } 47 createInstance() { return new FakeTimer(); }
69 }, 48 },
70 "@mozilla.org/xmlextras/xmlhttprequest;1": 49 "@mozilla.org/xmlextras/xmlhttprequest;1":
71 { 50 {
72 createInstance() { return new XMLHttpRequest(); } 51 createInstance() { return new XMLHttpRequest(); }
73 } 52 }
74 }, 53 },
75 results: {}, 54 results: {},
76 utils: { 55 utils: {
77 import() 56 import(resource)
78 { 57 {
58 let match = /^resource:\/\/gre\/modules\/(.+)\.jsm$/.exec(resource);
59 let resourceName = match && match[1];
60 if (resourceName && Cu.import.resources.has(resourceName))
61 return {[resourceName]: Cu.import.resources.get(resourceName)};
62
63 throw new Error(
64 "Attempt to import unknown JavaScript module " + resource
65 );
79 }, 66 },
80 reportError(e) 67 reportError(e)
81 { 68 {
82 console.error(e); 69 console.error(e);
83 console.trace(); 70 console.trace();
84 } 71 }
85 }, 72 },
86 manager: null, 73 manager: null,
87 ID() { return null; } 74 ID() { return null; }
88 }; 75 };
89 const Cc = Components.classes; 76 const Cc = Components.classes;
90 const Ci = Components.interfaces; 77 const Ci = Components.interfaces;
91 const Cr = Components.results; 78 const Cr = Components.results;
92 const Cu = Components.utils; 79 const Cu = Components.utils;
93 80
94 let XPCOMUtils = 81 Cu.import.resources = new Map();
95 { 82
83 Cu.import.resources.set("XPCOMUtils", {
96 generateQI() {} 84 generateQI() {}
97 }; 85 });
98
99 //
100 // Fake nsIFile implementation for our I/O
101 //
102
103 function FakeFile(path)
104 {
105 this.path = path;
106 }
107 FakeFile.prototype =
108 {
109 get leafName()
110 {
111 return this.path;
112 },
113 set leafName(value)
114 {
115 this.path = value;
116 },
117 append(path)
118 {
119 this.path += path;
120 },
121 clone()
122 {
123 return new FakeFile(this.path);
124 },
125 get parent()
126 {
127 return {create() {}};
128 },
129 normalize() {}
130 };
131 86
132 // 87 //
133 // Services.jsm module emulation 88 // Services.jsm module emulation
134 // 89 //
135 90
136 let Services = 91 Cu.import.resources.set("Services", {
137 {
138 obs: { 92 obs: {
139 addObserver() {}, 93 addObserver() {},
140 removeObserver() {} 94 removeObserver() {}
141 }, 95 },
142 vc: { 96 vc: {
143 compare(v1, v2) 97 compare(v1, v2)
144 { 98 {
145 function parsePart(s) 99 function parsePart(s)
146 { 100 {
147 if (!s) 101 if (!s)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 let parts2 = v2.split("."); 154 let parts2 = v2.split(".");
201 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) 155 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++)
202 { 156 {
203 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); 157 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i]));
204 if (result) 158 if (result)
205 return result; 159 return result;
206 } 160 }
207 return 0; 161 return 0;
208 } 162 }
209 } 163 }
210 } 164 });
211 165
212 // 166 //
213 // FileUtils.jsm module emulation 167 // FileUtils.jsm module emulation
214 // 168 //
215 169
216 let FileUtils = 170 Cu.import.resources.set("FileUtils", {
217 {
218 PERMS_DIRECTORY: 0 171 PERMS_DIRECTORY: 0
219 }; 172 });
220 173
221 function FakeTimer() 174 function FakeTimer()
222 { 175 {
223 } 176 }
224 FakeTimer.prototype = 177 FakeTimer.prototype =
225 { 178 {
226 delay: 0, 179 delay: 0,
227 callback: null, 180 callback: null,
228 initWithCallback(callback, delay) 181 initWithCallback(callback, delay)
229 { 182 {
230 this.callback = callback; 183 this.callback = callback;
231 this.delay = delay; 184 this.delay = delay;
232 this.scheduleTimeout(); 185 this.scheduleTimeout();
233 }, 186 },
234 scheduleTimeout() 187 scheduleTimeout()
235 { 188 {
236 window.setTimeout(() => 189 window.setTimeout(() =>
237 { 190 {
238 try 191 try
239 { 192 {
240 this.callback(); 193 this.callback();
241 } 194 }
242 catch(e) 195 catch (e)
243 { 196 {
244 Cu.reportError(e); 197 Cu.reportError(e);
245 } 198 }
246 this.scheduleTimeout(); 199 this.scheduleTimeout();
247 }, this.delay); 200 }, this.delay);
248 } 201 }
249 }; 202 };
250 203
251 // 204 //
252 // Add a channel property to XMLHttpRequest, Synchronizer needs it 205 // Add a channel property to XMLHttpRequest, Synchronizer needs it
253 // 206 //
254 207
255 XMLHttpRequest.prototype.channel = 208 XMLHttpRequest.prototype.channel = {
256 {
257 status: -1, 209 status: -1,
258 notificationCallbacks: {}, 210 notificationCallbacks: {},
259 loadFlags: 0, 211 loadFlags: 0,
260 INHIBIT_CACHING: 0, 212 INHIBIT_CACHING: 0,
261 VALIDATE_ALWAYS: 0, 213 VALIDATE_ALWAYS: 0,
262 QueryInterface() 214 QueryInterface()
263 { 215 {
264 return this; 216 return this;
265 } 217 }
266 }; 218 };
OLDNEW
« no previous file with comments | « inject.preload.js ('k') | lib/csp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld