<commit_before>'use strict';

var mithrilFakeXhr = function(base) {

  base = base || window;
  var SaveXML = base.XMLHttpRequest; 

  var pending = {};
  var unexpectedRequests = 0;
    
  base.XMLHttpRequest = (function() {

    function select(ctx, cb) {
      Object.keys(pending).forEach(function(key){
        var match = new RegExp('^'+key+'$').exec(ctx.method.toLowerCase() + ctx.url);
        if (match && match.length) {
          ctx.pending = pending[key];
          cb(pending[key],ctx);
        }
      });
    }

    return function() {
      this.$headers = {};
      this.setRequestHeader = function(key, value) {
        this.$headers[key] = value;
      };
      this.open = function(method, url, async, user, password) {
        this.method = method;
        this.url = url;
        select(this, function(pending){
          if (pending.passthrough){
            pending.xhr = new SaveXML();
            return pending.xhr.open(method, url, async, user, password);
          }
        })
      };
      this.send = function(data) {
        var xhr = this, request = this.pending;
        xhr.readyState = 4;
        xhr.status = 400;
        xhr.responseText='';
        if (request && (request.data === undefined || JSON.stringify(request.data) == data)) {
          if (request.passthrough){
            request.xhr.onreadystatechange = function() {
              if (request.xhr.readyState === 4) {
                request.response(request.xhr.responseText);
                xhr.status = request.xhr.status;
                xhr.readyState = request.xhr.readyState;
                xhr.responseText = request.xhr.responseText;
                xhr.onreadystatechange();
              }
            };
            request.$headers = xhr.$headers;
            return request.xhr.send(data);<commit_msg>isolate pending xhr for overlapping requests<commit_after>'use strict';

var mithrilFakeXhr = function(base) {

  base = base || window;
  var SaveXML = base.XMLHttpRequest; 

  var pending = {};
  var unexpectedRequests = 0;
    
  base.XMLHttpRequest = (function() {

    function select(ctx, cb) {
      Object.keys(pending).forEach(function(key){
        var match = new RegExp('^'+key+'$').exec(ctx.method.toLowerCase() + ctx.url);
        if (match && match.length) {
          ctx.pending = pending[key];
          cb(pending[key],ctx);
        }
      });
    }

    return function() {
      this.$headers = {};
      this.setRequestHeader = function(key, value) {
        this.$headers[key] = value;
      };
      this.open = function(method, url, async, user, password) {
        this.method = method;
        this.url = url;
        select(this, function(pending){
          if (pending.passthrough){
            pending.xhr = new SaveXML();
            return pending.xhr.open(method, url, async, user, password);
          }
        })
      };
      this.send = function(data) {
        var xhr = this, request = this.pending;
        xhr.readyState = 4;
        xhr.status = 400;
        xhr.responseText='';
        if (request && (request.data === undefined || JSON.stringify(request.data) == data)) {
          if (request.passthrough){
            var passthroughXhr = request.xhr;
            passthroughXhr.onreadystatechange = function() {
              if (passthroughXhr.readyState === 4) {
                request.response(passthroughXhr.responseText);
                xhr.status = passthroughXhr.status;
                xhr.readyState = passthroughXhr.readyState;
                xhr.responseText = passthroughXhr.responseText;
                xhr.onreadystatechange();
              }
            };
            request.$headers = xhr.$headers;
            return request.xhr.send(data);
{'fraction_non_alphanumeric': 0.1313888145571314, 'fraction_numerical': 0.003211131924003211, 'mean_word_length': 1.973747016706444, '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': '6301410', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1084, 'n_words': 209}