<commit_before>var _ = require("./misc");
var assert = require("./assert");

function EventEmitter() {
  this.__listeners = {};
}

EventEmitter.prototype.addEventListener = function(evt, fn) {
  assert(typeof fn == "function", "eventemitter: second argument should be a function");
  if (!this.__listeners[evt]) this.__listeners[evt] = [];
  this.__listeners[evt].push(fn);
};

EventEmitter.prototype.removeEventListener = function(evt, fn) {
  if (arguments.length === 0) {
    this.__listeners = {};
    return;
  }
  if (!this.__listeners.hasOwnProperty(evt)) return;
  if (arguments.length === 1) {
    delete this.__listeners[evt];
    return;
  }
  var listeners = this.__listeners[evt];
  var index = listeners.indexOf(fn);
  if (~index) listeners.splice(index, 1);
  if (!listeners.length) delete this.__listeners[evt];
};

EventEmitter.prototype.trigger = function(evt, arg) {
  if (!this.__listeners.hasOwnProperty(evt)) return;
  var listeners = this.__listeners[evt].slice();
  _.each(listeners, listener => {
    var err = _.tryCatch(() => listener(arg));
    if (err instanceof Error)
      console.error(err, err.stack);
  });
};

// aliases
EventEmitter.prototype.on = EventEmitter.prototype.addEventListener;
EventEmitter.prototype.off = EventEmitter.prototype.removeEventListener;

module.exports = EventEmitter;<commit_msg>do not need to use tryCatch<commit_after>var _ = require("./misc");
var assert = require("./assert");

function EventEmitter() {
  this.__listeners = {};
}

EventEmitter.prototype.addEventListener = function(evt, fn) {
  assert(typeof fn == "function", "eventemitter: second argument should be a function");
  if (!this.__listeners[evt]) this.__listeners[evt] = [];
  this.__listeners[evt].push(fn);
};

EventEmitter.prototype.removeEventListener = function(evt, fn) {
  if (arguments.length === 0) {
    this.__listeners = {};
    return;
  }
  if (!this.__listeners.hasOwnProperty(evt)) return;
  if (arguments.length === 1) {
    delete this.__listeners[evt];
    return;
  }
  var listeners = this.__listeners[evt];
  var index = listeners.indexOf(fn);
  if (~index) listeners.splice(index, 1);
  if (!listeners.length) delete this.__listeners[evt];
};

EventEmitter.prototype.trigger = function(evt, arg) {
  if (!this.__listeners.hasOwnProperty(evt)) return;
  var listeners = this.__listeners[evt].slice();
  _.each(listeners, listener => {
    try {
      listener(arg);
    } catch(e) {
      console.error(err, err.stack);
    }
  });
};

// aliases
EventEmitter.prototype.on = EventEmitter.prototype.addEventListener;
EventEmitter.prototype.off = EventEmitter.prototype.removeEventListener;

module.exports = EventEmitter;
{'fraction_non_alphanumeric': 0.15401869158878503, 'fraction_numerical': 0.0022429906542056075, 'mean_word_length': 4.506172839506172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '7342028', 'n_tokens_mistral': 818, 'n_tokens_neox': 852, 'n_words': 167}