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

Delta Between Two Patch Sets: lib/compat.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Left Patch Set: "use strict"; Created Jan. 16, 2017, 3:30 a.m.
Right Patch Set: Addressed some more feedback Created Jan. 18, 2017, 11:44 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « include.preload.js ('k') | lib/csp.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 24 matching lines...) Expand all
35 35
36 function importAll(module, globalObj) 36 function importAll(module, globalObj)
37 { 37 {
38 let exports = require(module); 38 let exports = require(module);
39 for (let key in exports) 39 for (let key in exports)
40 globalObj[key] = exports[key]; 40 globalObj[key] = exports[key];
41 } 41 }
42 42
43 let onShutdown = { 43 let onShutdown = {
44 done: false, 44 done: false,
45 add: () => {}, 45 add() {},
46 remove: () => {} 46 remove() {}
47 }; 47 };
48 48
49 // 49 //
50 // XPCOM emulation 50 // XPCOM emulation
51 // 51 //
52 52
53 let Components = 53 let Components =
54 { 54 {
55 interfaces: 55 interfaces:
56 { 56 {
57 nsIFile: {DIRECTORY_TYPE: 0}, 57 nsIFile: {DIRECTORY_TYPE: 0},
58 nsIFileURL: () => {}, 58 nsIFileURL() {},
59 nsIHttpChannel: () => {}, 59 nsIHttpChannel() {},
60 nsITimer: {TYPE_REPEATING_SLACK: 0}, 60 nsITimer: {TYPE_REPEATING_SLACK: 0},
61 nsIInterfaceRequestor: null, 61 nsIInterfaceRequestor: null,
62 nsIChannelEventSink: null 62 nsIChannelEventSink: null
63 }, 63 },
64 classes: 64 classes:
65 { 65 {
66 "@mozilla.org/timer;1": 66 "@mozilla.org/timer;1":
67 { 67 {
68 createInstance: () => new FakeTimer() 68 createInstance() { return new FakeTimer(); }
69 }, 69 },
70 "@mozilla.org/xmlextras/xmlhttprequest;1": 70 "@mozilla.org/xmlextras/xmlhttprequest;1":
71 { 71 {
72 createInstance: () => new XMLHttpRequest() 72 createInstance() { return new XMLHttpRequest(); }
73 } 73 }
74 }, 74 },
75 results: {}, 75 results: {},
76 utils: { 76 utils: {
77 import: () => 77 import()
78 { 78 {
79 }, 79 },
80 reportError: e => 80 reportError(e)
81 { 81 {
82 console.error(e); 82 console.error(e);
83 console.trace(); 83 console.trace();
84 } 84 }
85 }, 85 },
86 manager: null, 86 manager: null,
87 ID: () => null 87 ID() { return null; }
88 }; 88 };
89 const Cc = Components.classes; 89 const Cc = Components.classes;
90 const Ci = Components.interfaces; 90 const Ci = Components.interfaces;
91 const Cr = Components.results; 91 const Cr = Components.results;
92 const Cu = Components.utils; 92 const Cu = Components.utils;
93 93
94 let XPCOMUtils = 94 let XPCOMUtils =
95 { 95 {
96 generateQI: () => {} 96 generateQI() {}
97 }; 97 };
98 98
99 // 99 //
100 // Fake nsIFile implementation for our I/O 100 // Fake nsIFile implementation for our I/O
101 // 101 //
102 102
103 function FakeFile(path) 103 function FakeFile(path)
104 { 104 {
105 this.path = path; 105 this.path = path;
106 } 106 }
107 FakeFile.prototype = 107 FakeFile.prototype =
108 { 108 {
109 get leafName() 109 get leafName()
110 { 110 {
111 return this.path; 111 return this.path;
112 }, 112 },
113 set leafName(value) 113 set leafName(value)
114 { 114 {
115 this.path = value; 115 this.path = value;
116 }, 116 },
117 append: function(path) 117 append(path)
118 { 118 {
119 this.path += path; 119 this.path += path;
120 }, 120 },
121 clone: function() 121 clone()
122 { 122 {
123 return new FakeFile(this.path); 123 return new FakeFile(this.path);
124 }, 124 },
125 get parent() 125 get parent()
126 { 126 {
127 return {create: () => {}}; 127 return {create() {}};
128 }, 128 },
129 normalize: () => {} 129 normalize() {}
130 }; 130 };
131 131
132 // 132 //
133 // Services.jsm module emulation 133 // Services.jsm module emulation
134 // 134 //
135 135
136 let Services = 136 let Services =
137 { 137 {
138 obs: { 138 obs: {
139 addObserver: () => {}, 139 addObserver() {},
140 removeObserver: () => {} 140 removeObserver() {}
141 }, 141 },
142 vc: { 142 vc: {
143 compare: (v1, v2) => 143 compare(v1, v2)
144 { 144 {
145 function parsePart(s) 145 function parsePart(s)
146 { 146 {
147 if (!s) 147 if (!s)
148 return parsePart("0"); 148 return parsePart("0");
149 149
150 let part = { 150 let part = {
151 numA: 0, 151 numA: 0,
152 strB: "", 152 strB: "",
153 numC: 0, 153 numC: 0,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 PERMS_DIRECTORY: 0 218 PERMS_DIRECTORY: 0
219 }; 219 };
220 220
221 function FakeTimer() 221 function FakeTimer()
222 { 222 {
223 } 223 }
224 FakeTimer.prototype = 224 FakeTimer.prototype =
225 { 225 {
226 delay: 0, 226 delay: 0,
227 callback: null, 227 callback: null,
228 initWithCallback: function(callback, delay) 228 initWithCallback(callback, delay)
229 { 229 {
230 this.callback = callback; 230 this.callback = callback;
231 this.delay = delay; 231 this.delay = delay;
232 this.scheduleTimeout(); 232 this.scheduleTimeout();
233 }, 233 },
234 scheduleTimeout: function() 234 scheduleTimeout()
235 { 235 {
236 window.setTimeout(() => 236 window.setTimeout(() =>
237 { 237 {
238 try 238 try
239 { 239 {
240 this.callback(); 240 this.callback();
241 } 241 }
242 catch(e) 242 catch(e)
243 { 243 {
244 Cu.reportError(e); 244 Cu.reportError(e);
245 } 245 }
246 this.scheduleTimeout(); 246 this.scheduleTimeout();
247 }, this.delay); 247 }, this.delay);
248 } 248 }
249 }; 249 };
250 250
251 // 251 //
252 // Add a channel property to XMLHttpRequest, Synchronizer needs it 252 // Add a channel property to XMLHttpRequest, Synchronizer needs it
253 // 253 //
254 254
255 XMLHttpRequest.prototype.channel = 255 XMLHttpRequest.prototype.channel =
256 { 256 {
257 status: -1, 257 status: -1,
258 notificationCallbacks: {}, 258 notificationCallbacks: {},
259 loadFlags: 0, 259 loadFlags: 0,
260 INHIBIT_CACHING: 0, 260 INHIBIT_CACHING: 0,
261 VALIDATE_ALWAYS: 0, 261 VALIDATE_ALWAYS: 0,
262 QueryInterface: function() 262 QueryInterface()
263 { 263 {
264 return this; 264 return this;
265 } 265 }
266 }; 266 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld