Index: lib/compat.js |
diff --git a/lib/compat.js b/lib/compat.js |
index c63ed31b036973f96be28d1fdeab7a2439887008..6d270b7118e41f513dae03756da4f7e27aed5887 100644 |
--- a/lib/compat.js |
+++ b/lib/compat.js |
@@ -44,16 +44,12 @@ onShutdown = { |
// XPCOM emulation |
// |
-var Components = |
+const Components = |
{ |
interfaces: |
{ |
- nsIFile: {DIRECTORY_TYPE: 0}, |
sergei
2017/08/11 12:49:39
Some parts of Components seem to be removed long a
|
- nsIFileURL: function() {}, |
nsIHttpChannel: function() {}, |
nsITimer: {TYPE_REPEATING_SLACK: 0}, |
- nsIInterfaceRequestor: null, |
- nsIChannelEventSink: null |
}, |
classes: |
{ |
@@ -64,105 +60,41 @@ var Components = |
return new FakeTimer(); |
} |
}, |
- "@mozilla.org/xmlextras/xmlhttprequest;1": |
- { |
- createInstance: function() |
- { |
- return new XMLHttpRequest(); |
- } |
- } |
}, |
- results: {}, |
utils: { |
reportError: function(e) |
{ |
console.error(e); |
console.trace(); |
}, |
- import: function() |
+ import: function(resource) |
{ |
+ let match = /^resource:\/\/gre\/modules\/(.+)\.jsm$/.exec(resource); |
sergei
2017/08/11 12:49:38
it's taken from https://github.com/adblockplus/adb
|
+ let resourceName = match && match[1]; |
+ if (resourceName && Cu.import.resources.has(resourceName)) |
+ return {[resourceName]: Cu.import.resources.get(resourceName)}; |
+ throw new Error("Attempt to import unknown JavaScript module " + resource); |
} |
}, |
- manager: null, |
- ID: function() |
- { |
- return null; |
- } |
}; |
+ |
const Cc = Components.classes; |
const Ci = Components.interfaces; |
-const Cr = Components.results; |
const Cu = Components.utils; |
-var XPCOMUtils = |
-{ |
- generateQI: function() {} |
-}; |
- |
-// |
-// Fake nsIFile implementation for our I/O |
-// |
+Cu.import.resources = new Map(); |
-function FakeFile(path) |
sergei
2017/08/11 12:49:38
Removed because of #5059
|
+Cu.import.resources.set("XPCOMUtils", |
{ |
- this.path = path; |
-} |
-FakeFile.prototype = |
-{ |
- get leafName() |
- { |
- return this.path; |
- }, |
- set leafName(value) |
- { |
- this.path = value; |
- }, |
- append: function(path) |
- { |
- this.path += path; |
- }, |
- clone: function() |
- { |
- return new FakeFile(this.path); |
- }, |
- get parent() |
- { |
- return {create: function() {}}; |
- }, |
- normalize: function() {} |
-}; |
+ generateQI: function() {} |
+}); |
// |
// Services.jsm module emulation |
// |
-var Services = |
+Cu.import.resources.set("Services", |
{ |
- io: { |
- newURI: function(uri) |
- { |
- if (!uri.length || uri[0] == "~") |
- throw new Error("Invalid URI"); |
- |
- /^([^:\/]*)/.test(uri); |
- var scheme = RegExp.$1.toLowerCase(); |
- |
- return { |
- scheme: scheme, |
- spec: uri, |
- QueryInterface: function() |
- { |
- return this; |
- } |
- }; |
- }, |
- newFileURI: function(file) |
- { |
- var result = this.newURI("file:///" + file.path); |
- result.file = file; |
- return result; |
- } |
- }, |
obs: { |
addObserver: function() {}, |
removeObserver: function() {} |
@@ -235,16 +167,7 @@ var Services = |
return 0; |
} |
} |
-} |
- |
-// |
-// FileUtils.jsm module emulation |
-// |
- |
-var FileUtils = |
-{ |
- PERMS_DIRECTORY: 0 |
-}; |
+}); |
function FakeTimer() |
{ |