<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");

this.EXPORTED_SYMBOLS = ["Addons"];

/**
 * SafeAddons store info about an add-on. They are single-depth
 * objects to simplify cloning, and have no methods so they are safe
 * to pass to sandboxes and filter expressions.
 *
 * @typedef {Object} SafeAddon
 * @property {string} id
 *   Add-on id, such as "<EMAIL>" or "{4ea51ac2-adf2-4af8-a69d-17b48c558a12}"
 * @property {Date} installDate
 * @property {boolean} isActive
 * @property {string} name
 * @property {string} type
 *   "extension", "theme", etc.
 * @property {string} version
 */

this.Addons = {
  /**
   * Get information about an installed add-on by ID.
   *
   * @param {string} addonId
   * @returns {SafeAddon?} Add-on with given ID, or null if not found.
   * @throws If addonId is not specified or not a string.
   */
  async get(addonId) {
    const addon = await AddonManager.getAddonByID(addonId);
    if (!addon) {
      return null;
    }
    return Addons.serializeForSandbox(addon);
  },

  /**
   * Get information about all installed add-ons.
   * @async
   * @returns {Array<SafeAddon>}
   */
  async getAll(addonId) {
    const addons = await AddonManager.getAllAddons();
    return addons.map(Addons.serializeForSandbox.bind(this));
  },
<commit_msg>recipe-client-addon: Be consistent about `this` in Addons.jsm<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");

this.EXPORTED_SYMBOLS = ["Addons"];

/**
 * SafeAddons store info about an add-on. They are single-depth
 * objects to simplify cloning, and have no methods so they are safe
 * to pass to sandboxes and filter expressions.
 *
 * @typedef {Object} SafeAddon
 * @property {string} id
 *   Add-on id, such as "<EMAIL>" or "{4ea51ac2-adf2-4af8-a69d-17b48c558a12}"
 * @property {Date} installDate
 * @property {boolean} isActive
 * @property {string} name
 * @property {string} type
 *   "extension", "theme", etc.
 * @property {string} version
 */

this.Addons = {
  /**
   * Get information about an installed add-on by ID.
   *
   * @param {string} addonId
   * @returns {SafeAddon?} Add-on with given ID, or null if not found.
   * @throws If addonId is not specified or not a string.
   */
  async get(addonId) {
    const addon = await AddonManager.getAddonByID(addonId);
    if (!addon) {
      return null;
    }
    return this.serializeForSandbox(addon);
  },

  /**
   * Get information about all installed add-ons.
   * @async
   * @returns {Array<SafeAddon>}
   */
  async getAll(addonId) {
    const addons = await AddonManager.getAllAddons();
    return addons.map(this.serializeForSandbox.bind(this));
  },

{'fraction_non_alphanumeric': 0.1283704572098476, 'fraction_numerical': 0.012895662368112544, 'mean_word_length': 3.5628342245989306, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2212714', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1137, 'n_words': 350}