tor-browser

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

ComponentUtils.sys.mjs (1090B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
      2 * vim: sw=2 ts=2 sts=2 et filetype=javascript
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 /**
      8 * Deprecated utilities for JavaScript components loaded by the JS component
      9 * loader.
     10 */
     11 
     12 const nsIFactoryQI = ChromeUtils.generateQI(["nsIFactory"]);
     13 
     14 export var ComponentUtils = {
     15  /**
     16   * DEPRECATED!
     17   *
     18   * Generates a singleton nsIFactory implementation that can be used as
     19   * an argument to nsIComponentRegistrar.registerFactory.
     20   *
     21   * @param {Function} aServiceConstructor
     22   *        Constructor function of the component.
     23   */
     24  generateSingletonFactory(aServiceConstructor) {
     25    return {
     26      _instance: null,
     27      createInstance(aIID) {
     28        if (this._instance === null) {
     29          this._instance = new aServiceConstructor();
     30        }
     31        return this._instance.QueryInterface(aIID);
     32      },
     33      QueryInterface: nsIFactoryQI,
     34    };
     35  },
     36 };