<commit_before>/*
 * This Source Code is subject to the terms of the Mozilla Public License
 * version 2.0 (the "License"). You can obtain a copy of the License at
 * http://mozilla.org/MPL/2.0/.
 */

"use strict";

let passwords = require("../passwords");
let {getPasswords, addAlias, removeAlias} = passwords;
let {getCurrentHost} = require("./utils");

module.exports = function(panel)
{
  function passwordOp(func, successMessage, data)
  {
    let promise = func(data);
    promise.then(passwords => panel.port.emit(successMessage, passwords));
    promise.catch(e => {
      if (e == "alreadyExists")
        panel.port.emit("passwordAlreadyExists");
      else if (e)
        console.error(e);
    });
  }

  panel.port.on("addGeneratedPassword", passwordOp.bind(null, passwords.addGenerated, "passwordAdded"));
  panel.port.on("addLegacyPassword", passwordOp.bind(null, passwords.addLegacy, "passwordAdded"));
  panel.port.on("removePassword", passwordOp.bind(null, passwords.removePassword, "passwordRemoved"));

  panel.port.on("getPasswords", function(host)
  {
    let [origSite, site, passwords] = getPasswords(host);
    console.error([host, site, passwords]);
    panel.port.emit("setPasswords", {origSite, site, passwords});
  });

  panel.port.on("addAlias", function({site, alias})
  {
    addAlias(site, alias);
    let [origSite, newSite, passwords] = getPasswords(getCurrentHost());
    panel.port.emit("setPasswords", {origSite, site: newSite, passwords});
  });

  panel.port.on("removeAlias", function(site)
  {
    removeAlias(site);
    let [origSite, newSite, passwords] = getPasswords(getCurrentHost());
    panel.port.emit("setPasswords", {origSite, site: newSite, passwords});
  });
};<commit_msg>Removed unintentionally committed diagnostic message<commit_after>/*
 * This Source Code is subject to the terms of the Mozilla Public License
 * version 2.0 (the "License"). You can obtain a copy of the License at
 * http://mozilla.org/MPL/2.0/.
 */

"use strict";

let passwords = require("../passwords");
let {getPasswords, addAlias, removeAlias} = passwords;
let {getCurrentHost} = require("./utils");

module.exports = function(panel)
{
  function passwordOp(func, successMessage, data)
  {
    let promise = func(data);
    promise.then(passwords => panel.port.emit(successMessage, passwords));
    promise.catch(e => {
      if (e == "alreadyExists")
        panel.port.emit("passwordAlreadyExists");
      else if (e)
        console.error(e);
    });
  }

  panel.port.on("addGeneratedPassword", passwordOp.bind(null, passwords.addGenerated, "passwordAdded"));
  panel.port.on("addLegacyPassword", passwordOp.bind(null, passwords.addLegacy, "passwordAdded"));
  panel.port.on("removePassword", passwordOp.bind(null, passwords.removePassword, "passwordRemoved"));

  panel.port.on("getPasswords", function(host)
  {
    let [origSite, site, passwords] = getPasswords(host);
    panel.port.emit("setPasswords", {origSite, site, passwords});
  });

  panel.port.on("addAlias", function({site, alias})
  {
    addAlias(site, alias);
    let [origSite, newSite, passwords] = getPasswords(getCurrentHost());
    panel.port.emit("setPasswords", {origSite, site: newSite, passwords});
  });

  panel.port.on("removeAlias", function(site)
  {
    removeAlias(site);
    let [origSite, newSite, passwords] = getPasswords(getCurrentHost());
    panel.port.emit("setPasswords", {origSite, site: newSite, passwords});
  });
};
{'fraction_non_alphanumeric': 0.1577268773557553, 'fraction_numerical': 0.002319512902290519, 'mean_word_length': 4.537720706260032, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6245491', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1045, 'n_words': 233}