<commit_before># Window history and location.
http = require("http")
jsdom = require("jsdom")
html = jsdom.dom.level3.html
qs = require("querystring")
URL = require("url")
util = require("util")


# History entry. Consists of:
# - state -- As provided by pushState/replaceState
# - title -- As provided by pushState/replaceState
# - pop -- True if added using pushState/replaceState
# - url -- URL object of current location
# - location -- Location object
class Entry
  constructor: (history, url, options)->
    if options
      @state = options.state
      @title = options.title
      @pop = !!options.pop
    this.update = (url)->
      @url = URL.parse(URL.format(url))
      @location = new Location(history, @url)
    this.update url


# ## window.history
#
# Represents window.history.
class History
  constructor: (browser)->
    # History is a stack of Entry objects.
    stack = []
    index = -1

    # Called when we switch to a new page with the URL of the old page.
    pageChanged = (was)=>
      url = stack[index]?.url
      if !was || was.host != url.host || was.pathname != url.pathname || was.query != url.query
        # We're on a different site or different page, load it
        resource url
      else if was.hash != url.hash
        # Hash changed. Do not reload page, but do send hashchange
        evt = browser.window.document.createEvent("HTMLEvents")
        evt.initEvent "hashchange", true, false
        browser.window.dispatchEvent evt
      else
        # Load new page for now (but later on use caching).
        resource url

    # Make a request to external resource. We use this to fetch pages and
    # submit forms, see _loadPage and _submit.
    resource = (url, method, data, headers)=>
      method = (method || "GET").toUpperCase()
      throw new Error("Cannot load resource: #{URL.format(url)}") unless url.protocol && url.hostname

      # If the browser has a new window, use it. If a document was already
      # loaded into that window it would have state information we don't want
      # (e.g. window.$) so open a new window.
      if browser.window.document
        browser.open history: this, interactive: browser.window.parent == browser.window

      # Create new DOM Level 3 document, add features (load external
      # resources, etc) and associate it with current document. From this
      # point on the browser sees a new document, client register event
      # handler for DOMContentLoaded/error.
      options =
        url: URL.format(url)
        deferClose: false
        parser: require("html5").HTML5
        features:
          QuerySelector: true<commit_msg>Fixing a bug which prevents Zombie from loading file:// protocol URL's.<commit_after># Window history and location.
http = require("http")
jsdom = require("jsdom")
html = jsdom.dom.level3.html
qs = require("querystring")
URL = require("url")
util = require("util")


# History entry. Consists of:
# - state -- As provided by pushState/replaceState
# - title -- As provided by pushState/replaceState
# - pop -- True if added using pushState/replaceState
# - url -- URL object of current location
# - location -- Location object
class Entry
  constructor: (history, url, options)->
    if options
      @state = options.state
      @title = options.title
      @pop = !!options.pop
    this.update = (url)->
      @url = URL.parse(URL.format(url))
      @location = new Location(history, @url)
    this.update url


# ## window.history
#
# Represents window.history.
class History
  constructor: (browser)->
    # History is a stack of Entry objects.
    stack = []
    index = -1

    # Called when we switch to a new page with the URL of the old page.
    pageChanged = (was)=>
      url = stack[index]?.url
      if !was || was.host != url.host || was.pathname != url.pathname || was.query != url.query
        # We're on a different site or different page, load it
        resource url
      else if was.hash != url.hash
        # Hash changed. Do not reload page, but do send hashchange
        evt = browser.window.document.createEvent("HTMLEvents")
        evt.initEvent "hashchange", true, false
        browser.window.dispatchEvent evt
      else
        # Load new page for now (but later on use caching).
        resource url

    # Make a request to external resource. We use this to fetch pages and
    # submit forms, see _loadPage and _submit.
    resource = (url, method, data, headers)=>
      method = (method || "GET").toUpperCase()
      throw new Error("Cannot load resource: #{URL.format(url)}") unless url.protocol && url.hostname != undefined

      # If the browser has a new window, use it. If a document was already
      # loaded into that window it would have state information we don't want
      # (e.g. window.$) so open a new window.
      if browser.window.document
        browser.open history: this, interactive: browser.window.parent == browser.window

      # Create new DOM Level 3 document, add features (load external
      # resources, etc) and associate it with current document. From this
      # point on the browser sees a new document, client register event
      # handler for DOMContentLoaded/error.
      options =
        url: URL.format(url)
        deferClose: false
        parser: require("html5").HTML5
        features:
          QuerySelector: true
{'fraction_non_alphanumeric': 0.10136780963087877, 'fraction_numerical': 0.001873711823121604, 'mean_word_length': 2.6966759002770084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1328788', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1437, 'n_words': 574}