<commit_before>/*global FormError, jQuery, JSONF*/
/*eslint complexity:0*/
var FormFiller = {
  error: null,
  fill: function(selector, value) {
    var domNodes = document.querySelectorAll(selector);
    var domNode = null;
    var fillMethod = null;

    if (domNodes.length === 0) {
      return new FormError(selector, value, "Could not find field");
    }

    var parsedValue = JSONF.parse(value);

    // Call field specific method on EVERY field found
    //
    // "_fill" + the camelized version of one of these:
    // text , button , checkbox , image , password , radio , textarea , select-one , select-multiple , search
    // email , url , tel , number , range , date , month , week , time , datetime , datetime-local , color
    //
    // eg. _fillDatetimeLocal(value)
    var i;
    for (i = 0; i < domNodes.length; ++i) {
      domNode = domNodes[i];
      fillMethod = this._fillMethod(domNode);

      // if the value is a function, call it with the jQuery wrapped domNode
      if(typeof parsedValue === "function") {
        parsedValue = parsedValue(jQuery(domNode));
      }

      // Fill field only if value is not null or not defined
      if(parsedValue !== null && typeof parsedValue !== "undefined") {
        // Fill field using the specialized method or default
        return fillMethod(domNode, parsedValue, selector) || null;
      }
    }

  },
  _fillDefault: function(domNode, value) {
    domNode.value = value;
  },
  _fillCheckbox: function(domNode, value) {
    domNode.checked = (domNode.value == value);
  },
  _fillRadio: function(domNode, value) {
    domNode.checked = (domNode.value === value);
  },
  _fillSelectOne: function(domNode, value) {
    var i = 0;
    var optionNode = null;
    for(i = 0; i < domNode.children.length; i++) {
      optionNode = domNode.children[i];
      if(optionNode.value === value) {
        optionNode.selected = value;
        return;
      }
    }<commit_msg>report exceptions while executing value functions<commit_after>/*global FormError, jQuery, JSONF, Utils*/
/*eslint complexity:0*/
var FormFiller = {
  error: null,
  fill: function(selector, value) {
    var domNodes = document.querySelectorAll(selector);
    var domNode = null;
    var fillMethod = null;

    if (domNodes.length === 0) {
      return new FormError(selector, value, "Could not find field");
    }

    var parsedValue = JSONF.parse(value);

    // Call field specific method on EVERY field found
    //
    // "_fill" + the camelized version of one of these:
    // text , button , checkbox , image , password , radio , textarea , select-one , select-multiple , search
    // email , url , tel , number , range , date , month , week , time , datetime , datetime-local , color
    //
    // eg. _fillDatetimeLocal(value)
    var i;
    for (i = 0; i < domNodes.length; ++i) {
      domNode = domNodes[i];
      fillMethod = this._fillMethod(domNode);

      // if the value is a function, call it with the jQuery wrapped domNode
      if(typeof parsedValue === "function") {
        try {
          parsedValue = parsedValue(jQuery(domNode));
        } catch (e) {
          Utils.log("[form_filler.js] Got an exception executing value function: " + parsedValue);
          Utils.log("[form_filler.js] Original exception: " + e);
          Utils.log("[form_filler.js] Original stack: " + e.stack);
          return new FormError(selector, value, "Error while executing value-function: " + JSONF.stringify(e.message));
        }
      }

      // Fill field only if value is not null or not defined
      if(parsedValue !== null && typeof parsedValue !== "undefined") {
        // Fill field using the specialized method or default
        return fillMethod(domNode, parsedValue, selector) || null;
      }
    }

  },
  _fillDefault: function(domNode, value) {
    domNode.value = value;
  },
  _fillCheckbox: function(domNode, value) {
    domNode.checked = (domNode.value == value);
  },
  _fillRadio: function(domNode, value) {
    domNode.checked = (domNode.value === value);
  },
  _fillSelectOne: function(domNode, value) {
    var i = 0;
    var optionNode = null;
    for(i = 0; i < domNode.children.length; i++) {
      optionNode = domNode.children[i];
      if(optionNode.value === value) {
        optionNode.selected = value;
        return;
      }
    }
{'fraction_non_alphanumeric': 0.12407578558225509, 'fraction_numerical': 0.0023105360443622922, 'mean_word_length': 2.684255319148936, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3719307', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1268, 'n_words': 380}