summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgirst <girst@users.noreply.github.com>2024-03-03 12:59:18 +0100
committergirst <girst@users.noreply.github.com>2024-03-03 13:18:04 +0100
commit88413358677fd59dc360076e0a62c2c559f50e38 (patch)
tree376d89eebbd27b452bc30ff7201b46047b32612a
parent25664f0b2c3238704c7509cc661d52b6b5763599 (diff)
downloadlegacywolf-88413358677fd59dc360076e0a62c2c559f50e38.tar.gz
legacywolf-88413358677fd59dc360076e0a62c2c559f50e38.zip
port legacyfox to ecmascript modules
mozilla calls this 'esm-ification'. the last relevant to us modules were ported in mozilla124[1], so this is our new minimum version. the old version will likely be compatible with firefox up to version 128esr[2]. static imports are not supported in autoconfig scripts. i tried to keep the diff as small as possible w.r.t comm-central's final JSMs. because of this, we don't lazy-load any modules any more, nor provide any lazy getters, as they would need to be loaded into a `lazy` object instead the global (`this`) namespace, causing more churn. other than that, the largest change was removing the now-useless Services.jsm workaround as well as removing globalGetters for objects already loaded automatically. [1]: https://hg.mozilla.org/mozilla-central/rev/68ba071ff6fb9978937496f9adc48e378957f594 [2]: bugzil.la/1881890
-rw-r--r--Makefile6
-rw-r--r--README4
-rw-r--r--config.js7
-rw-r--r--legacy/BootstrapLoader.sys.mjs (renamed from legacy/BootstrapLoader.jsm)21
-rw-r--r--legacy/RDFDataSource.sys.mjs (renamed from legacy/RDFDataSource.jsm)8
-rw-r--r--legacy/RDFManifestConverter.sys.mjs (renamed from legacy/RDFManifestConverter.jsm)5
6 files changed, 19 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index 9c41ab3..2dd4df0 100644
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,9 @@
files := config.js
files += defaults/pref/config-prefs.js
files += legacy.manifest
-files += legacy/BootstrapLoader.jsm
-files += legacy/RDFDataSource.jsm
-files += legacy/RDFManifestConverter.jsm
+files += legacy/BootstrapLoader.sys.mjs
+files += legacy/RDFDataSource.sys.mjs
+files += legacy/RDFManifestConverter.sys.mjs
archive = legacyfox.tar.gz
DESTDIR ?= $(wildcard /usr/lib??/firefox/)
diff --git a/README b/README
index b7eace4..bc03093 100644
--- a/README
+++ b/README
@@ -8,6 +8,8 @@ Monkeypatching Firefox Quantum to run VimFx
2. Install VimFx from https://github.com/akhodakivskiy/VimFx/releases
== Notes ==
+ * LegacyFox is using ESModules and requires Firefox 124 or higher. Check out
+ the `v3.3` tag for compatibility with Firefox 68 to 128.
* Users of firefox-esr on debian need to use the following command:
`make DESTDIR=/usr/lib/firefox-esr install`
* BootstrapLoader.jsm, RDFDataSource.jsm, RDFManifestConverter.jsm from their
@@ -22,4 +24,4 @@ trademark; you are not granted any right to distribute modified binary versions
of the software containing the official branding.
(C) 2018-2019 Mozilla, MPL v2
-(C) 2019-2023 //gir.st/, MPL v2
+(C) 2019-2024 //gir.st/, MPL v2
diff --git a/config.js b/config.js
index 993c6ff..07662f7 100644
--- a/config.js
+++ b/config.js
@@ -1,16 +1,15 @@
// keep this comment
try {
- let {XPIDatabase} = Cu.import('resource://gre/modules/addons/XPIDatabase.jsm', {});
+ let {XPIDatabase} = ChromeUtils.importESModule('resource://gre/modules/addons/XPIDatabase.sys.mjs');
XPIDatabase.isDisabledLegacy = (addon) => false;
XPIDatabase.mustSign = (aType) => false;
- const Services = globalThis.Services || Cu.import("resource://gre/modules/Services.jsm").Services;
let manifest = Services.dirsvc.get('GreD', Ci.nsIFile);
manifest.append('legacy.manifest');
Components.manager.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(manifest);
- const {AddonManager} = Cu.import('resource://gre/modules/AddonManager.jsm');
- const {BootstrapLoader} = Cu.import('resource://legacy/BootstrapLoader.jsm');
+ const {AddonManager} = ChromeUtils.importESModule('resource://gre/modules/AddonManager.sys.mjs');
+ const {BootstrapLoader} = ChromeUtils.importESModule('resource://legacy/BootstrapLoader.sys.mjs');
AddonManager.addExternalExtensionLoader(BootstrapLoader);
} catch(ex) {
Components.utils.reportError(ex.message);
diff --git a/legacy/BootstrapLoader.jsm b/legacy/BootstrapLoader.sys.mjs
index a4010b3..80fc61d 100644
--- a/legacy/BootstrapLoader.jsm
+++ b/legacy/BootstrapLoader.sys.mjs
@@ -6,19 +6,12 @@
var EXPORTED_SYMBOLS = ["BootstrapLoader"];
-const {AddonManager} = ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
-const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+import {AddonManager} from "resource://gre/modules/AddonManager.sys.mjs";
+import {AddonInternal} from "resource://gre/modules/addons/XPIDatabase.sys.mjs";
+import {InstallRDF} from "resource://legacy/RDFManifestConverter.sys.mjs";
+import {XPIProvider} from "resource://gre/modules/addons/XPIProvider.sys.mjs";
-XPCOMUtils.defineLazyModuleGetters(this, {
- AddonInternal: "resource://gre/modules/addons/XPIDatabase.jsm",
- InstallRDF: "resource://legacy/RDFManifestConverter.jsm",
-});
-const Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;
-
-(ChromeUtils.defineLazyGetter||XPCOMUtils.defineLazyGetter)(this, "BOOTSTRAP_REASONS", () => {
- const {XPIProvider} = ChromeUtils.import("resource://gre/modules/addons/XPIProvider.jsm");
- return XPIProvider.BOOTSTRAP_REASONS;
-});
+const BOOTSTRAP_REASONS = XPIProvider.BOOTSTRAP_REASONS;
var logger = console.createInstance({ prefix: "addons.bootstrap" });
@@ -99,7 +92,7 @@ function buildJarURI(aJarfile, aPath) {
return Services.io.newURI(uri);
}
-var BootstrapLoader = {
+export var BootstrapLoader = {
name: "bootstrap",
manifestFile: "install.rdf",
async loadManifest(pkg) {
@@ -306,7 +299,7 @@ var BootstrapLoader = {
try {
Object.assign(sandbox, BOOTSTRAP_REASONS);
- (ChromeUtils.defineLazyGetter||XPCOMUtils.defineLazyGetter)(sandbox, "console", () =>
+ ChromeUtils.defineLazyGetter(sandbox, "console", () =>
console.createInstance({ consoleID: `addon/${addon.id}` }));
Services.scriptloader.loadSubScript(uri, sandbox);
diff --git a/legacy/RDFDataSource.jsm b/legacy/RDFDataSource.sys.mjs
index 579d075..27687ba 100644
--- a/legacy/RDFDataSource.jsm
+++ b/legacy/RDFDataSource.sys.mjs
@@ -134,12 +134,6 @@ const USE_RDFNS_ATTR = false;
var EXPORTED_SYMBOLS = ["RDFLiteral", "RDFIntLiteral", "RDFDateLiteral",
"RDFBlankNode", "RDFResource", "RDFDataSource"];
-const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-
-XPCOMUtils.defineLazyGlobalGetters(this, ["DOMParser", "Element", "XMLSerializer", "fetch"]);
-
-const Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;
-
function isAttr(obj) {
return obj && typeof obj == "object" && ChromeUtils.getClassName(obj) == "Attr";
}
@@ -1113,7 +1107,7 @@ class RDFBlankNode extends RDFSubject {
* changed as assertions are added and removed to the RDF. Pass a null document
* to start with an empty graph.
*/
-class RDFDataSource {
+export class RDFDataSource {
constructor(document) {
// All known resources, indexed on URI
this._resources = {};
diff --git a/legacy/RDFManifestConverter.jsm b/legacy/RDFManifestConverter.sys.mjs
index cb01f6a..12abd27 100644
--- a/legacy/RDFManifestConverter.jsm
+++ b/legacy/RDFManifestConverter.sys.mjs
@@ -5,8 +5,7 @@
var EXPORTED_SYMBOLS = ["InstallRDF"];
-ChromeUtils.defineModuleGetter(this, "RDFDataSource",
- "resource://legacy/RDFDataSource.jsm");
+import {RDFDataSource} from "resource://legacy/RDFDataSource.sys.mjs";
const RDFURI_INSTALL_MANIFEST_ROOT = "urn:mozilla:install-manifest";
@@ -40,7 +39,7 @@ class Manifest {
}
}
-class InstallRDF extends Manifest {
+export class InstallRDF extends Manifest {
_readProps(source, obj, props) {
for (let prop of props) {
let val = getProperty(source, prop);