<commit_before>/**
 * module.js - The core of module loader
 */

var cachedMods = seajs.cache = {}
var anonymousMeta

var fetchingList = {}
var fetchedList = {}
var callbackList = {}

var STATUS = Module.STATUS = {
  // 1 - The module file is being fetched now
  FETCHING: 1,
  // 2 - The module data has been saved to cachedMods
  SAVED: 2,
  // 3 - The module and all its dependencies are ready to execute
  LOADED: 3,
  // 4 - The module is being executed
  EXECUTING: 4,
  // 5 - The module is executed and `module.exports` is available
  EXECUTED: 5
}


function Module(uri, deps) {
  this.uri = uri || data.cwd + "_anonymous_" + cid()
  this.dependencies = deps || []
  this.exports = null
  this.status = 0

  // Who depend on me
  this._waitings = {}
  // The number of unloaded dependencies
  this._remain = 0
  // The cache for _resolve method to speed up performance
  this._resolveCache = {}
  // This function will be called when onload
  this._callback = null
}

Module.get = function(uri, deps) {
  var mod = cachedMods[uri]

  if (!mod) {
    mod = new Module(uri, deps)
    cachedMods[mod.uri] = mod
  }

  return mod
}

// Resolve module.dependencies
Module.prototype._resolve = function() {
  var mod = this
  var ids = mod.dependencies, id
  var uris = []

  for (var i = 0, len = ids.length; i < len; i++) {
    id = ids[i]
    uris[i] = mod._resolveCache[id] = resolve(id, mod.uri)
  }

  return uris
}

// Load module.dependencies and fire onload when all done
Module.prototype._load = function() {
  var mod = this
  var uris = mod._resolve()

  // Emit `load` event for plugins such as plugin-combo
  emit("load", uris)

  var len = mod._remain = uris.length
  var m

  // Initialize modules and register waitings
  for (var i = 0; i < len; i++) {
    m = Module.get(uris[i])

    if (m.status < STATUS.LOADED) {
      m._waitings[mod.uri] = mod
    }
    else {
      mod._remain--
    }
  }

  if (mod._remain === 0) {
    mod._onload()
    return
  }

  // Begin parallel loading
  for (i = 0; i < len; i++) {
    m = cachedMods[uris[i]]

    if (m.status < STATUS.FETCHING) {
      m._fetch()
    }
    else if (mod.status === STATUS.SAVED) {
      m._load()
    }
  }
}

// Fetch a module
Module.prototype._fetch = function() {
  var mod = this
  var uri = mod.uri

  mod.status = STATUS.FETCHING

  // Emit `fetch` event for plugins such as plugin-combo
  var emitData = { uri: uri }
  emit("fetch", emitData)
  var requestUri = emitData.requestUri || uri

  // Empty uri or a non-CMD module
  if (!requestUri || fetchedList[requestUri]) {
    mod._onload()
    return
  }

  if (fetchingList[requestUri]) {
    callbackList[requestUri].push(mod)
    return
  }

  fetchingList[requestUri] = true
  callbackList[requestUri] = [mod]

  // Emit `request` event for plugins such as plugin-text
  emit("request", emitData = {
    uri: uri,
    requestUri: requestUri,
    callback: onRequested,
    charset: data.charset
  })

  if (!emitData.requested) {
    request(emitData.requestUri, onRequested, emitData.charset)
  }

  function onRequested() {
    delete fetchingList[requestUri]
    fetchedList[requestUri] = true

    // Save meta data of anonymous module
    if (anonymousMeta) {
      save(uri, anonymousMeta)
      anonymousMeta = undefined
    }

    // Call callbacks
    var m, mods = callbackList[requestUri]
    delete callbackList[requestUri]
    while ((m = mods.shift())) {
      if (m.status === STATUS.SAVED) {
        m._load()
      }
    }
  }
}

// Call this method when module is loaded
Module.prototype._onload = function() {
  var mod = this
  mod.status = STATUS.LOADED

  // Call onload callback
  if (mod._callback) {
    mod._callback()
  }

  // Notify waiting modules to fire onload
  var waitings = mod._waitings
  var uri, m

  for (uri in waitings) {
    if (waitings.hasOwnProperty(uri)) {
      m = waitings[uri]
      if (--m._remain === 0) {
        m._onload()<commit_msg>Fix a bug in fetch function<commit_after>/**
 * module.js - The core of module loader
 */

var cachedMods = seajs.cache = {}
var anonymousMeta

var fetchingList = {}
var fetchedList = {}
var callbackList = {}

var STATUS = Module.STATUS = {
  // 1 - The module file is being fetched now
  FETCHING: 1,
  // 2 - The module data has been saved to cachedMods
  SAVED: 2,
  // 3 - The module and all its dependencies are ready to execute
  LOADED: 3,
  // 4 - The module is being executed
  EXECUTING: 4,
  // 5 - The module is executed and `module.exports` is available
  EXECUTED: 5
}


function Module(uri, deps) {
  this.uri = uri || data.cwd + "_anonymous_" + cid()
  this.dependencies = deps || []
  this.exports = null
  this.status = 0

  // Who depend on me
  this._waitings = {}
  // The number of unloaded dependencies
  this._remain = 0
  // The cache for _resolve method to speed up performance
  this._resolveCache = {}
  // This function will be called when onload
  this._callback = null
}

Module.get = function(uri, deps) {
  var mod = cachedMods[uri]

  if (!mod) {
    mod = new Module(uri, deps)
    cachedMods[mod.uri] = mod
  }

  return mod
}

// Resolve module.dependencies
Module.prototype._resolve = function() {
  var mod = this
  var ids = mod.dependencies, id
  var uris = []

  for (var i = 0, len = ids.length; i < len; i++) {
    id = ids[i]
    uris[i] = mod._resolveCache[id] = resolve(id, mod.uri)
  }

  return uris
}

// Load module.dependencies and fire onload when all done
Module.prototype._load = function() {
  var mod = this
  var uris = mod._resolve()

  // Emit `load` event for plugins such as plugin-combo
  emit("load", uris)

  var len = mod._remain = uris.length
  var m

  // Initialize modules and register waitings
  for (var i = 0; i < len; i++) {
    m = Module.get(uris[i])

    if (m.status < STATUS.LOADED) {
      m._waitings[mod.uri] = mod
    }
    else {
      mod._remain--
    }
  }

  if (mod._remain === 0) {
    mod._onload()
    return
  }

  // Begin parallel loading
  for (i = 0; i < len; i++) {
    m = cachedMods[uris[i]]

    if (m.status < STATUS.FETCHING) {
      m._fetch()
    }
    else if (mod.status === STATUS.SAVED) {
      m._load()
    }
  }
}

// Fetch a module
Module.prototype._fetch = function() {
  var mod = this
  var uri = mod.uri

  mod.status = STATUS.FETCHING

  // Emit `fetch` event for plugins such as plugin-combo
  var emitData = { uri: uri }
  emit("fetch", emitData)
  var requestUri = emitData.requestUri || uri

  // Empty uri or a non-CMD module
  if (!requestUri || fetchedList[requestUri]) {
    mod._load()
    return
  }

  if (fetchingList[requestUri]) {
    callbackList[requestUri].push(mod)
    return
  }

  fetchingList[requestUri] = true
  callbackList[requestUri] = [mod]

  // Emit `request` event for plugins such as plugin-text
  emit("request", emitData = {
    uri: uri,
    requestUri: requestUri,
    callback: onRequested,
    charset: data.charset
  })

  if (!emitData.requested) {
    request(emitData.requestUri, onRequested, emitData.charset)
  }

  function onRequested() {
    delete fetchingList[requestUri]
    fetchedList[requestUri] = true

    // Save meta data of anonymous module
    if (anonymousMeta) {
      save(uri, anonymousMeta)
      anonymousMeta = undefined
    }

    // Call callbacks
    var m, mods = callbackList[requestUri]
    delete callbackList[requestUri]
    while ((m = mods.shift())) m._load()
  }
}

// Call this method when module is loaded
Module.prototype._onload = function() {
  var mod = this
  mod.status = STATUS.LOADED

  // Call onload callback
  if (mod._callback) {
    mod._callback()
  }

  // Notify waiting modules to fire onload
  var waitings = mod._waitings
  var uri, m

  for (uri in waitings) {
    if (waitings.hasOwnProperty(uri)) {
      m = waitings[uri]
      if (--m._remain === 0) {
        m._onload()
{'fraction_non_alphanumeric': 0.1221442246330568, 'fraction_numerical': 0.004339502233567326, 'mean_word_length': 2.6110599078341012, 'pattern_counts': {'":': 0, '<': 13, '<?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': '3339141', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2629, 'n_words': 787}