<commit_before># JSONP functions -----------------------------------------_

# {callbacks: [(Any ...) -> Undefined ...]}
#
# List of callback functions. Must be globally scoped
window.Myna.callbacks = []

JsonP =
  callbackCounter: 0

  # String -> Undefined
  removeCallback: (callbackName) ->
    if this.readyState and
       this.readyState != "complete" and
       this.readyState != "loaded"
    else
      this.onload = null;
      try
        this.parentNode.removeChild(this)
      catch e
      finally
        window.Myna.callbacks[callbackName] = null

  # {success: (Any ...) -> Undefined,
  #  error: (JSON) -> Undefined,
  #  timeout: (U Number Undefined)
  #  url: String,
  #  data: Hash[String, String]} -> Undefined
  doJsonP: (options) ->
    # Used to sync the callback and timeout handlers
    returned = false

    callbackName = "callback" + (JsonP.callbackCounter++)
    window.Myna.callbacks[callbackName] =
      (args) ->
        if !returned
          returned = true
          options.success.apply(this, arguments)

    url = options.url + "?"
    url += "#{key}=#{value}&" for key, value of options.data
    url += "callback=window.Myna.callbacks." + callbackName

    if options.timeout > 0
      window.setTimeout( ->
        if !returned
          returned = true
          JsonP.removeCallback.call(elem, callbackName)
          options.error({typename: 'problem', subtype: 500, messages: [{typename: "timeout", item: "The server took longer than #{options.timeout} ms to reply"}]})
      , options.timeout)

    elem = document.createElement("script")
    elem.setAttribute("type","text/javascript")
    elem.setAttribute("async", "true")
    # onreadystatechange is for IE, onload/onerror for everyone else
    elem.onload = elem.onreadystatechange = -> JsonP.removeCallback.call(elem, callbackName)<commit_msg>Fix bug in JSONP not called error handler on error<commit_after># JSONP functions -----------------------------------------_

# {callbacks: [(Any ...) -> Undefined ...]}
#
# List of callback functions. Must be globally scoped
window.Myna.callbacks = []

JsonP =
  callbackCounter: 0

  # String -> Undefined
  removeCallback: (callbackName) ->
    if this.readyState and
       this.readyState != "complete" and
       this.readyState != "loaded"
    else
      this.onload = null;
      try
        this.parentNode.removeChild(this)
      catch e
      finally
        window.Myna.callbacks[callbackName] = null

  # {success: (Any ...) -> Undefined,
  #  error: (JSON) -> Undefined,
  #  timeout: (U Number Undefined)
  #  url: String,
  #  data: Hash[String, String]} -> Undefined
  doJsonP: (options) ->
    # Used to sync the callback and timeout handlers
    returned = false

    callbackName = "callback" + (JsonP.callbackCounter++)
    window.Myna.callbacks[callbackName] =
      (args) ->
    window.Myna.callbacks[callbackName] = (response) ->
      unless returned
        returned = true
      switch response.typename
        when "problem" then options.error.call(this, response)
        else options.success.call(this, response)

    url = options.url + "?"
    url += "#{key}=#{value}&" for key, value of options.data
    url += "callback=window.Myna.callbacks." + callbackName

    if options.timeout > 0
      window.setTimeout( ->
        if !returned
          returned = true
          JsonP.removeCallback.call(elem, callbackName)
          options.error({typename: 'problem', subtype: 500, messages: [{typename: "timeout", item: "The server took longer than #{options.timeout} ms to reply"}]})
      , options.timeout)

    elem = document.createElement("script")
    elem.setAttribute("type","text/javascript")
    elem.setAttribute("async", "true")
    # onreadystatechange is for IE, onload/onerror for everyone else
    elem.onload = elem.onreadystatechange = -> JsonP.removeCallback.call(elem, callbackName)
{'fraction_non_alphanumeric': 0.1462033462033462, 'fraction_numerical': 0.002574002574002574, 'mean_word_length': 2.67296786389414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '4071610', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1111, 'n_words': 290}