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

Side by Side Diff: lib/compat.js

Issue 29555778: Issue 5776 - Updated adblockpluscore dependency to d4ed3916793a (Closed)
Patch Set: Include latest core changes Created Sept. 27, 2017, 9:19 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') | no next file » | 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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 let onShutdown = { 20 let onShutdown = {
21 done: false, 21 done: false,
22 add() {}, 22 add() {},
23 remove() {} 23 remove() {}
24 }; 24 };
25 25
26 // 26 //
27 // XPCOM emulation 27 // XPCOM emulation
28 // 28 //
29 29
30 function nsIFileURL() {}
31 function nsIHttpChannel() {} 30 function nsIHttpChannel() {}
32 31
33 let ComponentsObject = { 32 let ComponentsObject = {
34 interfaces: 33 interfaces:
35 { 34 {
36 nsIFile: {DIRECTORY_TYPE: 0},
37 nsIFileURL,
38 nsIHttpChannel, 35 nsIHttpChannel,
39 nsITimer: {TYPE_REPEATING_SLACK: 0}, 36 nsITimer: {TYPE_REPEATING_SLACK: 0},
40 nsIInterfaceRequestor: null, 37 nsIInterfaceRequestor: null
41 nsIChannelEventSink: null
42 }, 38 },
43 classes: 39 classes:
44 { 40 {
45 "@mozilla.org/timer;1": 41 "@mozilla.org/timer;1":
46 { 42 {
47 createInstance() { return new FakeTimer(); } 43 createInstance() { return new FakeTimer(); }
48 },
49 "@mozilla.org/xmlextras/xmlhttprequest;1":
50 {
51 createInstance() { return new XMLHttpRequest(); }
52 } 44 }
53 }, 45 },
54 results: {},
55 utils: { 46 utils: {
56 import(resource) 47 import(resource)
57 { 48 {
58 let match = /^resource:\/\/gre\/modules\/(.+)\.jsm$/.exec(resource); 49 let match = /^resource:\/\/gre\/modules\/(.+)\.jsm$/.exec(resource);
59 let resourceName = match && match[1]; 50 let resourceName = match && match[1];
60 if (resourceName && Cu.import.resources.has(resourceName)) 51 if (resourceName && Cu.import.resources.has(resourceName))
61 return {[resourceName]: Cu.import.resources.get(resourceName)}; 52 return {[resourceName]: Cu.import.resources.get(resourceName)};
62 53
63 throw new Error( 54 throw new Error(
64 "Attempt to import unknown JavaScript module " + resource 55 "Attempt to import unknown JavaScript module " + resource
65 ); 56 );
66 }, 57 },
67 reportError(e) 58 reportError(e)
68 { 59 {
69 console.error(e); 60 console.error(e);
70 console.trace(); 61 console.trace();
71 } 62 }
72 }, 63 },
73 manager: null, 64 manager: null,
74 ID() { return null; } 65 ID() { return null; }
75 }; 66 };
76 const Cc = ComponentsObject.classes; 67 const Cc = ComponentsObject.classes;
77 const Ci = ComponentsObject.interfaces; 68 const Ci = ComponentsObject.interfaces;
78 const Cr = ComponentsObject.results;
79 const Cu = ComponentsObject.utils; 69 const Cu = ComponentsObject.utils;
80 70
81 Cu.import.resources = new Map(); 71 Cu.import.resources = new Map([
82 72 [
83 Cu.import.resources.set("XPCOMUtils", { 73 "XPCOMUtils",
84 generateQI() {}
85 });
86
87 //
88 // Services.jsm module emulation
89 //
90
91 Cu.import.resources.set("Services", {
92 obs: {
93 addObserver() {},
94 removeObserver() {}
95 },
96 vc: {
97 compare(v1, v2)
98 { 74 {
99 function parsePart(s) 75 generateQI() {}
100 { 76 }
101 if (!s) 77 ],
102 return parsePart("0"); 78 [
103 79 "Services",
104 let part = { 80 {
105 numA: 0, 81 obs: {
106 strB: "", 82 addObserver() {},
107 numC: 0, 83 removeObserver() {}
108 extraD: ""
109 };
110
111 if (s === "*")
112 {
113 part.numA = Number.MAX_VALUE;
114 return part;
115 }
116
117 let matches = s.match(/(\d*)(\D*)(\d*)(.*)/);
118 part.numA = parseInt(matches[1], 10) || part.numA;
119 part.strB = matches[2] || part.strB;
120 part.numC = parseInt(matches[3], 10) || part.numC;
121 part.extraD = matches[4] || part.extraD;
122
123 if (part.strB == "+")
124 {
125 part.numA++;
126 part.strB = "pre";
127 }
128
129 return part;
130 } 84 }
131
132 function comparePartElement(s1, s2)
133 {
134 if (s1 === "" && s2 !== "")
135 return 1;
136 if (s1 !== "" && s2 === "")
137 return -1;
138 return s1 === s2 ? 0 : (s1 > s2 ? 1 : -1);
139 }
140
141 function compareParts(p1, p2)
142 {
143 let result = 0;
144 let elements = ["numA", "strB", "numC", "extraD"];
145 elements.some(element =>
146 {
147 result = comparePartElement(p1[element], p2[element]);
148 return result;
149 });
150 return result;
151 }
152
153 let parts1 = v1.split(".");
154 let parts2 = v2.split(".");
155 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++)
156 {
157 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i]));
158 if (result)
159 return result;
160 }
161 return 0;
162 } 85 }
163 } 86 ]
164 }); 87 ]);
165
166 //
167 // FileUtils.jsm module emulation
168 //
169
170 Cu.import.resources.set("FileUtils", {
171 PERMS_DIRECTORY: 0
172 });
173 88
174 function FakeTimer() 89 function FakeTimer()
175 { 90 {
176 } 91 }
177 FakeTimer.prototype = 92 FakeTimer.prototype =
178 { 93 {
179 delay: 0, 94 delay: 0,
180 callback: null, 95 callback: null,
181 initWithCallback(callback, delay) 96 initWithCallback(callback, delay)
182 { 97 {
(...skipping 17 matching lines...) Expand all
200 }, this.delay); 115 }, this.delay);
201 } 116 }
202 }; 117 };
203 118
204 // 119 //
205 // Add a channel property to XMLHttpRequest, Synchronizer needs it 120 // Add a channel property to XMLHttpRequest, Synchronizer needs it
206 // 121 //
207 122
208 XMLHttpRequest.prototype.channel = { 123 XMLHttpRequest.prototype.channel = {
209 status: -1, 124 status: -1,
210 notificationCallbacks: {},
211 loadFlags: 0, 125 loadFlags: 0,
212 INHIBIT_CACHING: 0, 126 INHIBIT_CACHING: 0,
213 VALIDATE_ALWAYS: 0, 127 VALIDATE_ALWAYS: 0
214 QueryInterface()
215 {
216 return this;
217 }
218 }; 128 };
OLDNEW
« no previous file with comments | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld