<commit_before>
if(!window.Handsontable){
  var Handsontable = {};
}

Handsontable.eventManager = function (instance) {
  if (!instance) {
    throw  new Error ('instance not defined');
  }

  if (!instance.eventListeners) {
    instance.eventListeners = [];
  }

  var addEvent = function (element, event, delegate, callback, bubbling) {
      if (typeof delegate === 'function') {
        bubbling = callback;
        callback = delegate;
        delegate = null;
      } else {
        //TODO
        var CB = callback;
        callback = function (event) {
          if (Handsontable.Dom.hasClass(event.target, delegate)) {
            CB();
          }
        }
      }

      bubbling = bubbling || false;

      instance.eventListeners.push({
        element: element,
        event: event,
        delegate: delegate,
        callback: callback,
        bubbling: bubbling
      });

      if (window.addEventListener) {
        element.addEventListener(event, callback, bubbling)
      } else {
        element.attachEvent('on' + event, callback);
      }
    },
    removeEvent = function (element, event, delegate, callback, bubbling){
      bubbling = bubbling || false;

      if (element.detachEvent) {
        element.detachEvent('on' + event, handler);
      } else {
        element.removeEventListener(event, callback, bubbling);
      }
    },
    serveImmediatePropagation = function () {
      if (event != null && event.isImmediatePropagationEnabled == null) {
        event.stopImmediatePropagation = function () {
          this.isImmediatePropagationEnabled = false;
          this.cancelBubble = true;
        };
        event.isImmediatePropagationEnabled = true;
        event.isImmediatePropagationStopped = function () {
          return !this.isImmediatePropagationEnabled;
        };
      }
      return event;
    },
    clearEvents = function () {
      while(instance.eventListeners.length > 0) {
       var event = instance.eventListeners.pop();
        removeEvent(event.element, event.event, event.delegate, event.callback, event.bubbling);
      }<commit_msg>bugfix: `clear` and `removeEventListener` did not work if the `delegate` argument was omitted<commit_after>
if(!window.Handsontable){
  var Handsontable = {};
}

Handsontable.eventManager = function (instance) {
  if (!instance) {
    throw  new Error ('instance not defined');
  }

  if (!instance.eventListeners) {
    instance.eventListeners = [];
  }

  var addEvent = function (element, event, delegate, callback, bubbling) {
      if (typeof delegate === 'function') {
        bubbling = callback;
        callback = delegate;
        delegate = null;
      } else {
        throw new Error("Add delegate event not implemented");

        //TODO
        var CB = callback;
        callback = function (event) {
          if (Handsontable.Dom.hasClass(event.target, delegate)) {
            CB();
          }
        }
      }

      bubbling = bubbling || false;

      instance.eventListeners.push({
        element: element,
        event: event,
        delegate: delegate,
        callback: callback,
        bubbling: bubbling
      });

      if (window.addEventListener) {
        element.addEventListener(event, callback, bubbling)
      } else {
        element.attachEvent('on' + event, callback);
      }
    },
    removeEvent = function (element, event, delegate, callback, bubbling){
      if(typeof delegate === 'function') {
        bubbling = callback;
        callback = delegate;
      }
      else {
        throw new Error("Remove delegate event not implemented");
      }

      bubbling = bubbling || false;

      if (element.detachEvent) {
        element.detachEvent('on' + event, handler);
      } else {
        element.removeEventListener(event, callback, bubbling);
      }
    },
    serveImmediatePropagation = function () {
      if (event != null && event.isImmediatePropagationEnabled == null) {
        event.stopImmediatePropagation = function () {
          this.isImmediatePropagationEnabled = false;
          this.cancelBubble = true;
        };
        event.isImmediatePropagationEnabled = true;
        event.isImmediatePropagationStopped = function () {
          return !this.isImmediatePropagationEnabled;
        };
      }
      return event;
    },
    clearEvents = function () {
      while(instance.eventListeners.length > 0) {
       var event = instance.eventListeners.pop();
        if(event.delegate) {
          removeEvent(event.element, event.event, event.delegate, event.callback, event.bubbling);
        }
        else {
          removeEvent(event.element, event.event, event.callback, event.bubbling);
        }
      }
{'fraction_non_alphanumeric': 0.11108742004264392, 'fraction_numerical': 0.00042643923240938164, 'mean_word_length': 2.296556570625439, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6395476', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1279, 'n_words': 286}