<commit_before>import Image from './util/canvas/image';
import {loader} from 'vega-loader';

export default function ResourceLoader(customLoader) {
  this._pending = 0;
  this._loader = customLoader || loader();
}

var prototype = ResourceLoader.prototype;

prototype.pending = function() {
  return this._pending;
};

function increment(loader) {
  loader._pending += 1;
}

function decrement(loader) {
  loader._pending -= 1;
}

prototype.sanitizeURL = function(uri) {
  var loader = this;
  increment(loader);

  return loader._loader.sanitize(uri, {context:'href'})
    .then(function(opt) {
      decrement(loader);
      return opt;
    })
    .catch(function() {
      decrement(loader);
      return null;
    });
};

prototype.loadImage = function(uri) {
  var loader = this;
  increment(loader);

  return loader._loader.sanitize(uri, {context:'image'})
    .then(function(opt) {
      var url = opt.href;
      if (!url || !Image) throw 'Image unsupported.';

      var image = new Image();

      image.onload = function() {
        decrement(loader);
        image.loaded = true;
      };

      image.onerror = function() {
        decrement(loader);
        image.loaded = false;
      }

      image.src = url;
      return image;
    })
    .catch(function() {
      decrement(loader);
      return {loaded: false, width: 0, height: 0};
    });
};

prototype.ready = function() {
  var loader = this;
  return new Promise(function(accept) {<commit_msg>Fix image URL passing when missing Image object.<commit_after>import Image from './util/canvas/image';
import {loader} from 'vega-loader';

export default function ResourceLoader(customLoader) {
  this._pending = 0;
  this._loader = customLoader || loader();
}

var prototype = ResourceLoader.prototype;

prototype.pending = function() {
  return this._pending;
};

function increment(loader) {
  loader._pending += 1;
}

function decrement(loader) {
  loader._pending -= 1;
}

prototype.sanitizeURL = function(uri) {
  var loader = this;
  increment(loader);

  return loader._loader.sanitize(uri, {context:'href'})
    .then(function(opt) {
      decrement(loader);
      return opt;
    })
    .catch(function() {
      decrement(loader);
      return null;
    });
};

prototype.loadImage = function(uri) {
  var loader = this;
  increment(loader);

  return loader._loader
    .sanitize(uri, {context:'image'})
    .then(function(opt) {
      var url = opt.href;
      if (!url || !Image) throw {url: url};

      var image = new Image();

      image.onload = function() {
        decrement(loader);
        image.loaded = true;
      };

      image.onerror = function() {
        decrement(loader);
        image.loaded = false;
      }

      image.src = url;
      return image;
    })
    .catch(function(e) {
      decrement(loader);
      return {loaded: false, width: 0, height: 0, src: e && e.url || ''};
    });
};

prototype.ready = function() {
  var loader = this;
  return new Promise(function(accept) {
{'fraction_non_alphanumeric': 0.142379679144385, 'fraction_numerical': 0.0033422459893048127, 'mean_word_length': 2.8971354166666665, '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': '731214', 'n_tokens_mistral': 929, 'n_tokens_neox': 915, 'n_words': 217}