tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ImportHelper.sys.mjs (990B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 export let ImportHelper = {
      6  /**
      7   * Helper so the new tab extension can easily trainhop while we convert
      8   * modules from resource:// to moz-src:// URIs.
      9   *
     10   * @param {string} module
     11   *   The full moz-src URI to import.
     12   * @param {string} [fallbackResourcePath ="resource://gre/modules/"]
     13   *   The resource url prefix to use for fallback import if moz-src fails.
     14   *   The helper will suffix _only_ the module filename to this path.
     15   */
     16  import(module, fallbackResourcePath = "resource://gre/modules/") {
     17    try {
     18      return ChromeUtils.importESModule(module);
     19    } catch {
     20      let baseName = module.split("/").pop();
     21      // Fallback to a resource URI if moz-src fails.
     22      return ChromeUtils.importESModule(fallbackResourcePath + baseName);
     23    }
     24  },
     25 };