From 632e1258ee5ac853b54aa00e6b3004de278ab114 Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 23 Apr 2022 13:58:43 +0200 Subject: [PATCH] move from deprecated Cu.import to ChromeUtils.import In most cases, this was a drop-in replacement, but in bootstrap.coffee, we used the side effect of polluting the global namespace as a handy way to inject the `Services` object into the user's config.js file. As a bonus, the codebase has been rid of an inconsistency between Components.utils.import() and its shorthand Cu.import(), since both are now gone. We also use the destructuring assignment consistently now. Both config.js and frame.js were checked to still have the same exposed API (mainly concerned with Services and console, since that was removed from bootstrap.coffee). see also: Bug 1765167 --- extension/bootstrap-frame.js.tmpl | 2 +- extension/bootstrap.coffee | 5 +---- extension/lib/button.coffee | 8 ++++---- extension/lib/config.coffee | 5 +++-- extension/lib/main.coffee | 2 +- extension/lib/utils.coffee | 8 ++++---- extension/options.js | 3 +-- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/extension/bootstrap-frame.js.tmpl b/extension/bootstrap-frame.js.tmpl index 543f267..34d9b45 100644 --- a/extension/bootstrap-frame.js.tmpl +++ b/extension/bootstrap-frame.js.tmpl @@ -1,4 +1,4 @@ -const { Services } = Cu.import('resource://gre/modules/Services.jsm'); +const { Services } = ChromeUtils.import('resource://gre/modules/Services.jsm'); Services.scriptloader.loadSubScript( Services.io.newURI('{{{ ADDON_PATH }}}/content/bootstrap.js', null, null).spec, this, diff --git a/extension/bootstrap.coffee b/extension/bootstrap.coffee index f2b771a..02436c2 100644 --- a/extension/bootstrap.coffee +++ b/extension/bootstrap.coffee @@ -16,10 +16,7 @@ do (global = this) -> BUILD_TIME = do -> # @echo BUILD_TIME REQUIRE_DATA = do -> # @echo REQUIRE_DATA - # Make `Services` and `console` available globally and in frame scripts. - Cu.import('resource://gre/modules/Services.jsm') - unless IS_FRAME_SCRIPT - Cu.import('resource://gre/modules/Console.jsm') + {Services} = ChromeUtils.import('resource://gre/modules/Services.jsm') shutdownHandlers = [] diff --git a/extension/lib/button.coffee b/extension/lib/button.coffee index 6ebe832..0d8ab59 100644 --- a/extension/lib/button.coffee +++ b/extension/lib/button.coffee @@ -4,14 +4,14 @@ help = require('./help') translate = require('./translate') utils = require('./utils') -cui = Cu.import('resource:///modules/CustomizableUI.jsm', {}).CustomizableUI +{CustomizableUI} = ChromeUtils.import('resource:///modules/CustomizableUI.jsm') BUTTON_ID = 'VimFxButton' injectButton = (vimfx) -> - cui.createWidget({ + CustomizableUI.createWidget({ id: BUTTON_ID - defaultArea: cui.AREA_NAVBAR + defaultArea: CustomizableUI.AREA_NAVBAR label: 'VimFx' tooltiptext: translate('button.tooltip.normal') onCommand: (event) -> @@ -30,7 +30,7 @@ injectButton = (vimfx) -> else vim._enterMode('normal') }) - module.onShutdown(-> cui.destroyWidget(BUTTON_ID)) + module.onShutdown(-> CustomizableUI.destroyWidget(BUTTON_ID)) vimfx.on('modeDisplayChange', ({vim}) -> {window} = vim diff --git a/extension/lib/config.coffee b/extension/lib/config.coffee index ccfe9af..ef3c94c 100644 --- a/extension/lib/config.coffee +++ b/extension/lib/config.coffee @@ -5,7 +5,7 @@ messageManager = require('./message-manager') utils = require('./utils') prefs = require('./prefs') -{OS} = Components.utils.import('resource://gre/modules/osfile.jsm', {}) +{OS} = ChromeUtils.import('resource://gre/modules/osfile.jsm') load = (vimfx, options = null, callback = ->) -> configDir = vimfx.options.config_file_directory @@ -50,7 +50,8 @@ loadFile = (dir, file, scope) -> try Services.scriptloader.loadSubScriptWithOptions(uri, { target: Object.assign({ - __dirname: OS.Path.toFileURI(expandedDir) + __dirname: OS.Path.toFileURI(expandedDir), + Services: Services }, scope) charset: 'UTF-8' ignoreCache: true diff --git a/extension/lib/main.coffee b/extension/lib/main.coffee index a49d548..7fa9bbe 100644 --- a/extension/lib/main.coffee +++ b/extension/lib/main.coffee @@ -20,7 +20,7 @@ VimFx = require('./vimfx') test = require('../test/index') # @endif -{AddonManager} = Cu.import('resource://gre/modules/AddonManager.jsm', {}) +{AddonManager} = ChromeUtils.import('resource://gre/modules/AddonManager.jsm') module.exports = (data, reason) -> # Set default prefs and apply migrations as early as possible. diff --git a/extension/lib/utils.coffee b/extension/lib/utils.coffee index 2668a6b..149ac43 100644 --- a/extension/lib/utils.coffee +++ b/extension/lib/utils.coffee @@ -1,10 +1,10 @@ # This file contains lots of different helper functions. -{E10SUtils} = Cu.import('resource://gre/modules/E10SUtils.jsm', {}) -{OS} = Components.utils.import('resource://gre/modules/osfile.jsm', {}) -{PlacesUIUtils} = Cu.import('resource:///modules/PlacesUIUtils.jsm', {}) +{E10SUtils} = ChromeUtils.import('resource://gre/modules/E10SUtils.jsm') +{OS} = ChromeUtils.import('resource://gre/modules/osfile.jsm') +{PlacesUIUtils} = ChromeUtils.import('resource:///modules/PlacesUIUtils.jsm') {PrivateBrowsingUtils} = - Cu.import('resource://gre/modules/PrivateBrowsingUtils.jsm', {}) + ChromeUtils.import('resource://gre/modules/PrivateBrowsingUtils.jsm') nsIClipboardHelper = Cc['@mozilla.org/widget/clipboardhelper;1'] .getService(Ci.nsIClipboardHelper) diff --git a/extension/options.js b/extension/options.js index 174e420..8aa2f09 100644 --- a/extension/options.js +++ b/extension/options.js @@ -1,7 +1,6 @@ "use strict"; -const { utils: Cu } = Components; -const { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); window.addEventListener("load", () => { Services.obs.notifyObservers(document, "vimfx-options-displayed", ""); -- 2.39.3