Index: lib/compat.js |
=================================================================== |
--- a/lib/compat.js |
+++ b/lib/compat.js |
@@ -27,31 +27,22 @@ |
// XPCOM emulation |
// |
-function nsIFileURL() {} |
function nsIHttpChannel() {} |
let ComponentsObject = { |
interfaces: |
{ |
- nsIFile: {DIRECTORY_TYPE: 0}, |
- nsIFileURL, |
nsIHttpChannel, |
nsITimer: {TYPE_REPEATING_SLACK: 0}, |
- nsIInterfaceRequestor: null, |
- nsIChannelEventSink: null |
+ nsIInterfaceRequestor: null |
}, |
classes: |
{ |
"@mozilla.org/timer;1": |
{ |
createInstance() { return new FakeTimer(); } |
- }, |
- "@mozilla.org/xmlextras/xmlhttprequest;1": |
- { |
- createInstance() { return new XMLHttpRequest(); } |
} |
}, |
- results: {}, |
utils: { |
import(resource) |
{ |
@@ -75,101 +66,25 @@ |
}; |
const Cc = ComponentsObject.classes; |
const Ci = ComponentsObject.interfaces; |
-const Cr = ComponentsObject.results; |
const Cu = ComponentsObject.utils; |
-Cu.import.resources = new Map(); |
- |
-Cu.import.resources.set("XPCOMUtils", { |
- generateQI() {} |
-}); |
- |
-// |
-// Services.jsm module emulation |
-// |
- |
-Cu.import.resources.set("Services", { |
- obs: { |
- addObserver() {}, |
- removeObserver() {} |
- }, |
- vc: { |
- compare(v1, v2) |
+Cu.import.resources = new Map([ |
+ [ |
+ "XPCOMUtils", |
{ |
- function parsePart(s) |
- { |
- if (!s) |
- return parsePart("0"); |
- |
- let part = { |
- numA: 0, |
- strB: "", |
- numC: 0, |
- extraD: "" |
- }; |
- |
- if (s === "*") |
- { |
- part.numA = Number.MAX_VALUE; |
- return part; |
- } |
- |
- 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; |
- part.extraD = matches[4] || part.extraD; |
- |
- if (part.strB == "+") |
- { |
- part.numA++; |
- part.strB = "pre"; |
- } |
- |
- return part; |
+ generateQI() {} |
+ } |
+ ], |
+ [ |
+ "Services", |
+ { |
+ obs: { |
+ addObserver() {}, |
+ removeObserver() {} |
} |
- |
- function comparePartElement(s1, s2) |
- { |
- if (s1 === "" && s2 !== "") |
- return 1; |
- if (s1 !== "" && s2 === "") |
- return -1; |
- return s1 === s2 ? 0 : (s1 > s2 ? 1 : -1); |
- } |
- |
- function compareParts(p1, p2) |
- { |
- let result = 0; |
- let elements = ["numA", "strB", "numC", "extraD"]; |
- elements.some(element => |
- { |
- result = comparePartElement(p1[element], p2[element]); |
- return result; |
- }); |
- return result; |
- } |
- |
- let parts1 = v1.split("."); |
- let parts2 = v2.split("."); |
- for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) |
- { |
- let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); |
- if (result) |
- return result; |
- } |
- return 0; |
} |
- } |
-}); |
- |
-// |
-// FileUtils.jsm module emulation |
-// |
- |
-Cu.import.resources.set("FileUtils", { |
- PERMS_DIRECTORY: 0 |
-}); |
+ ] |
+]); |
function FakeTimer() |
{ |
@@ -207,12 +122,7 @@ |
XMLHttpRequest.prototype.channel = { |
status: -1, |
- notificationCallbacks: {}, |
loadFlags: 0, |
INHIBIT_CACHING: 0, |
- VALIDATE_ALWAYS: 0, |
- QueryInterface() |
- { |
- return this; |
- } |
+ VALIDATE_ALWAYS: 0 |
}; |