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

Unified Diff: lib/compat.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Addressed feedback, used destructuring Created Jan. 17, 2017, 7:39 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include.preload.js ('k') | lib/csp.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compat.js
diff --git a/lib/compat.js b/lib/compat.js
index d544edca8faa300d5ff3833b0470131b43d7b4a6..21439f3d353d904341f2b54ac7fe7f14190ac3bd 100644
--- a/lib/compat.js
+++ b/lib/compat.js
@@ -15,6 +15,8 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+"use strict";
+
//
// Module framework stuff
//
@@ -33,28 +35,28 @@ require.scopes = Object.create(null);
function importAll(module, globalObj)
{
- var exports = require(module);
- for (var key in exports)
+ let exports = require(module);
+ for (let key in exports)
globalObj[key] = exports[key];
}
-onShutdown = {
+let onShutdown = {
done: false,
- add: function() {},
- remove: function() {}
+ add() {},
+ remove() {}
};
//
// XPCOM emulation
//
-var Components =
+let Components =
{
interfaces:
{
nsIFile: {DIRECTORY_TYPE: 0},
- nsIFileURL: function() {},
- nsIHttpChannel: function() {},
+ nsIFileURL() {},
+ nsIHttpChannel() {},
nsITimer: {TYPE_REPEATING_SLACK: 0},
nsIInterfaceRequestor: null,
nsIChannelEventSink: null
@@ -63,44 +65,35 @@ var Components =
{
"@mozilla.org/timer;1":
{
- createInstance: function()
- {
- return new FakeTimer();
- }
+ createInstance() { return new FakeTimer(); }
},
"@mozilla.org/xmlextras/xmlhttprequest;1":
{
- createInstance: function()
- {
- return new XMLHttpRequest();
- }
+ createInstance() { return new XMLHttpRequest(); }
}
},
results: {},
utils: {
- import: function()
+ import()
{
},
- reportError: function(e)
+ reportError(e)
{
console.error(e);
console.trace();
}
},
manager: null,
- ID: function()
- {
- return null;
- }
+ ID() { return null; }
};
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;
-var XPCOMUtils =
+let XPCOMUtils =
{
- generateQI: function() {}
+ generateQI() {}
};
//
@@ -121,40 +114,40 @@ FakeFile.prototype =
{
this.path = value;
},
- append: function(path)
+ append(path)
{
this.path += path;
},
- clone: function()
+ clone()
{
return new FakeFile(this.path);
},
get parent()
{
- return {create: function() {}};
+ return {create() {}};
},
- normalize: function() {}
+ normalize() {}
};
//
// Services.jsm module emulation
//
-var Services =
+let Services =
{
obs: {
- addObserver: function() {},
- removeObserver: function() {}
+ addObserver() {},
+ removeObserver() {}
},
vc: {
- compare: function(v1, v2)
+ compare(v1, v2)
{
function parsePart(s)
{
if (!s)
return parsePart("0");
- var part = {
+ let part = {
numA: 0,
strB: "",
numC: 0,
@@ -167,7 +160,7 @@ var Services =
return part;
}
- var matches = s.match(/(\d*)(\D*)(\d*)(.*)/);
+ let matches = s.match(/(\d*)(\D*)(\d*)(.*)/);
part.numA = parseInt(matches[1], 10) || part.numA;
part.strB = matches[2] || part.strB;
part.numC = parseInt(matches[3], 10) || part.numC;
@@ -193,9 +186,9 @@ var Services =
function compareParts(p1, p2)
{
- var result = 0;
- var elements = ["numA", "strB", "numC", "extraD"];
- elements.some(function(element)
+ let result = 0;
+ let elements = ["numA", "strB", "numC", "extraD"];
+ elements.some(element =>
{
result = comparePartElement(p1[element], p2[element]);
return result;
@@ -203,11 +196,11 @@ var Services =
return result;
}
- var parts1 = v1.split(".");
- var parts2 = v2.split(".");
- for (var i = 0; i < Math.max(parts1.length, parts2.length); i++)
+ let parts1 = v1.split(".");
+ let parts2 = v2.split(".");
+ for (let i = 0; i < Math.max(parts1.length, parts2.length); i++)
{
- var result = compareParts(parsePart(parts1[i]), parsePart(parts2[i]));
+ let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i]));
if (result)
return result;
}
@@ -220,7 +213,7 @@ var Services =
// FileUtils.jsm module emulation
//
-var FileUtils =
+let FileUtils =
{
PERMS_DIRECTORY: 0
};
@@ -232,26 +225,25 @@ FakeTimer.prototype =
{
delay: 0,
callback: null,
- initWithCallback: function(callback, delay)
+ initWithCallback(callback, delay)
{
this.callback = callback;
this.delay = delay;
this.scheduleTimeout();
},
- scheduleTimeout: function()
+ scheduleTimeout()
{
- var me = this;
- window.setTimeout(function()
+ window.setTimeout(() =>
{
try
{
- me.callback();
+ this.callback();
}
catch(e)
{
Cu.reportError(e);
}
- me.scheduleTimeout();
+ this.scheduleTimeout();
}, this.delay);
}
};
@@ -267,7 +259,7 @@ XMLHttpRequest.prototype.channel =
loadFlags: 0,
INHIBIT_CACHING: 0,
VALIDATE_ALWAYS: 0,
- QueryInterface: function()
+ QueryInterface()
{
return this;
}
« 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