<commit_before>require 'browser/location'

module Browser; module DOM

class Document < Element
  def create_element(name, options = {})
    if ns = options[:namespace]
      DOM(`#@native.createElementNS(#{ns}, #{name})`)
    else
      DOM(`#@native.createElement(name)`)
    end
  end

  if Browser.supports? 'Document.view'
    def window
      Window.new(`#@native.defaultView`)
    end
  elsif Browser.supports? 'Document.window'
    def window
      Window.new(`#@native.parentWindow`)
    end
  else
    def window
      raise NotImplementedError, 'window from document unsupported'
    end
  end

  def create_text(content)
    DOM(`#@native.createTextNode(#{content})`)
  end

  def [](what)
    %x{
      var result = #@native.getElementById(what);

      if (result) {
        return #{DOM(`result`)};
      }
    }

    css(what).first || xpath(what).first
  end

  alias at []

  def cookies
    Cookies.new(@native) if defined?(`#@native.cookie`)
  end

  def document
    self
  end

  def inspect
    "#<DOM::Document: #{children.inspect}>"
  end

  def title
    `#@native.title`
  end

  def title=(value)
    `#@native.title = value`
  end

  def root
    DOM(`#@native.documentElement`)
  end

  def head
    DOM(`#@native.getElementsByTagName("head")[0]`)
  end

  def body
    DOM(`#@native.body`)
  end

  def style_sheets
    Native::Array.new(`#@native.styleSheets`) {|e|
      CSS::StyleSheet.new(e)
    }
  end

  def root=(element)
    `#@native.documentElement = #{Native.convert(element)}`
  end
end

end; end
<commit_msg>dom/document: #cookies has been moved<commit_after>require 'browser/location'

module Browser; module DOM

class Document < Element
  def create_element(name, options = {})
    if ns = options[:namespace]
      DOM(`#@native.createElementNS(#{ns}, #{name})`)
    else
      DOM(`#@native.createElement(name)`)
    end
  end

  if Browser.supports? 'Document.view'
    def window
      Window.new(`#@native.defaultView`)
    end
  elsif Browser.supports? 'Document.window'
    def window
      Window.new(`#@native.parentWindow`)
    end
  else
    def window
      raise NotImplementedError, 'window from document unsupported'
    end
  end

  def create_text(content)
    DOM(`#@native.createTextNode(#{content})`)
  end

  def [](what)
    %x{
      var result = #@native.getElementById(what);

      if (result) {
        return #{DOM(`result`)};
      }
    }

    css(what).first || xpath(what).first
  end

  alias at []

  def document
    self
  end

  def inspect
    "#<DOM::Document: #{children.inspect}>"
  end

  def title
    `#@native.title`
  end

  def title=(value)
    `#@native.title = value`
  end

  def root
    DOM(`#@native.documentElement`)
  end

  def head
    DOM(`#@native.getElementsByTagName("head")[0]`)
  end

  def body
    DOM(`#@native.body`)
  end

  def style_sheets
    Native::Array.new(`#@native.styleSheets`) {|e|
      CSS::StyleSheet.new(e)
    }
  end

  def root=(element)
    `#@native.documentElement = #{Native.convert(element)}`
  end
end

end; end

{'fraction_non_alphanumeric': 0.14248280379954142, 'fraction_numerical': 0.0006550933508024893, 'mean_word_length': 2.920410783055199, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4497033', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1021, 'n_words': 228}