<commit_before>// Support for element focus.


const DOM = require('./index');
const { idlUtils }    = require('./impl');

const FOCUS_ELEMENTS = ['INPUT', 'SELECT', 'TEXTAREA', 'BUTTON', 'ANCHOR'];


// The element in focus.
//
// If no element has the focus, return the document.body.
DOM.HTMLDocument.prototype.__defineGetter__('activeElement', function() {
  return this._inFocus || this.body;
});

// Change the current element in focus (or null for blur)
function setFocus(document, element) {
  const inFocus = document._inFocus;
  const inputElementImpl = idlUtils.implForWrapper(element);
  if (element !== inFocus) {
    if (inFocus) {
      const onblur = document.createEvent('HTMLEvents');
      onblur.initEvent('blur', false, false);
      inputElementImpl.addEventListener('blur', _blur, {});
      inFocus.dispatchEvent(onblur);
      element._blur(onblur);
    }
    if (element) { // null to blur
      const onfocus = document.createEvent('HTMLEvents');
      onfocus.initEvent('focus', false, false);
      inputElementImpl.addEventListener('focus', _focus, {});
      element.dispatchEvent(onfocus);
      document._inFocus = element;
      document.defaultView.browser.emit('focus', element);
    }
  }
}

// All HTML elements have a no-op focus/blur methods.
DOM.HTMLElement.prototype.focus = function() {<commit_msg>fixes focus in form.js tests<commit_after>// Support for element focus.


const DOM = require('./index');
const { idlUtils }    = require('./impl');

const FOCUS_ELEMENTS = ['INPUT', 'SELECT', 'TEXTAREA', 'BUTTON', 'ANCHOR'];


// The element in focus.
//
// If no element has the focus, return the document.body.
DOM.HTMLDocument.prototype.__defineGetter__('activeElement', function() {
  return this._inFocus || this.body;
});

// Change the current element in focus (or null for blur)
function setFocus(document, element) {
  const inFocus = document._inFocus;
  if (element !== inFocus) {
    const inputElementImpl = idlUtils.implForWrapper(element || inFocus);
    if (inFocus) {
      const onblur = document.createEvent('HTMLEvents');
      onblur.initEvent('blur', false, false);
      inputElementImpl.addEventListener('blur', _blur, {});
      inFocus.dispatchEvent(onblur);
      inFocus._blur(onblur);
    }
    if (element) { // null to blur
      const onfocus = document.createEvent('HTMLEvents');
      onfocus.initEvent('focus', false, false);
      inputElementImpl.addEventListener('focus', _focus, {});
      element.dispatchEvent(onfocus);
      document._inFocus = element;
      document.defaultView.browser.emit('focus', element);
    }
  }
}

// All HTML elements have a no-op focus/blur methods.
DOM.HTMLElement.prototype.focus = function() {
{'fraction_non_alphanumeric': 0.14132841328413284, 'fraction_numerical': 0.0, 'mean_word_length': 3.772887323943662, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2080640', 'n_tokens_mistral': 814, 'n_tokens_neox': 795, 'n_words': 201}