Index: lib/compat.js |
diff --git a/lib/compat.js b/lib/compat.js |
index 0e6682dede12aa72cfc0236d096388ccd130a7ef..f919671bda88047214e8382fc4bac65710c1e76e 100644 |
--- a/lib/compat.js |
+++ b/lib/compat.js |
@@ -69,8 +69,16 @@ let Components = { |
}, |
results: {}, |
utils: { |
- import() |
+ import(resource) |
{ |
+ let match = /^resource:\/\/gre\/modules\/(.+)\.jsm$/.exec(resource); |
+ 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 |
+ ); |
}, |
reportError(e) |
{ |
@@ -86,9 +94,11 @@ const Ci = Components.interfaces; |
const Cr = Components.results; |
const Cu = Components.utils; |
-let XPCOMUtils = { |
+Cu.import.resources = new Map(); |
+ |
+Cu.import.resources.set("XPCOMUtils", { |
generateQI() {} |
-}; |
+}); |
// |
// Fake nsIFile implementation for our I/O |
@@ -127,7 +137,7 @@ FakeFile.prototype = |
// Services.jsm module emulation |
// |
-let Services = { |
+Cu.import.resources.set("Services", { |
obs: { |
addObserver() {}, |
removeObserver() {} |
@@ -200,15 +210,15 @@ let Services = { |
return 0; |
} |
} |
-}; |
+}); |
// |
// FileUtils.jsm module emulation |
// |
-let FileUtils = { |
+Cu.import.resources.set("FileUtils", { |
PERMS_DIRECTORY: 0 |
-}; |
+}); |
function FakeTimer() |
{ |