<commit_before>begin
  require 'v8'
rescue LoadError
  require 'rubygems'
  require 'v8'
end

raise "No NODE_HOME found" unless ENV['NODE_HOME']

module Node
  class NativesModule
    Dir["#{ENV['NODE_HOME']}/lib/*.js"].each do |native_js|
      attribute = File.basename(native_js, File.extname(native_js)).to_sym
      define_method(attribute) do || # Empty pipes needed to make ruby realize arity is 0.
        File.read(native_js)
      end
    end
  end

  class Exports
  end

  class Process
    attr_reader :env

    def initialize(context)
      @context = context
      @bindings = Hash.new do |h, mod|
        name = mod.capitalize + "Module"
        if Node.const_defined?(name)
          h[mod] = Node.const_get(name).new
        else
          raise LoadError, "no such module #{mod}"
        end
      end
      @env = @context.eval('new Object()')
      @env['NODE_DEBUG'] = true
    end

    def binding(name)
      @bindings[name]
    end
        
    def compile(source, name = "<eval>")
      @context.eval(source, name)
    end

    def EventEmitter
      lambda{}
    end
  end  

  class Context < V8::Context
    def initialize
      super
      self['process'] = Process.new(self)
      self['exports'] = Exports.new
      self['rbputs'] = proc {|msg| puts "<pre>#{ERB::Util.h(msg)}</pre>"}
      self['rbinspect'] = proc {|msg| puts "<pre>#{ERB::Util.h(msg.inspect)}</pre>"}
      main = self.load(File.join(ENV['NODE_HOME'], 'src', 'node.js'))
      open do
        main.call(self.global, self['process'])
      end
    end
    
    def global
      open do
        V8::To.rb(@native.Global())
      end
    end
  end
end

<commit_msg>Got past some more errors. Now complaining about: Uncaught TypeError: Object [object Object] has no method 'cwd'<commit_after>begin
  require 'v8'
rescue LoadError
  require 'rubygems'
  require 'v8'
end

raise "No NODE_HOME found" unless ENV['NODE_HOME']

module Node
  class NativesModule
    Dir["#{ENV['NODE_HOME']}/lib/*.js"].each do |native_js|
      attribute = File.basename(native_js, File.extname(native_js)).to_sym
      define_method(attribute) do || # Empty pipes needed to make ruby realize arity is 0.
        File.read(native_js)
      end
    end
  end

  class Exports
  end

  class Process
    attr_reader :env, :global

    def initialize(context, global)
      @context = context
      @global = global
      @bindings = Hash.new do |h, mod|
        name = mod.capitalize + "Module"
        if Node.const_defined?(name)
          h[mod] = Node.const_get(name).new
        else
          raise LoadError, "no such module #{mod}"
        end
      end
      @env = @context.eval('new Object()')
      @env['NODE_DEBUG'] = true
    end

    def binding(name)
      @bindings[name]
    end
        
    def compile(source, name = "<eval>")
      @context.eval(source, name)
    end

    def EventEmitter
      lambda{}
    end
  end  

  class Context < V8::Context
    def initialize
      super
      self['process'] = Process.new(self, @native.Global)
      self['exports'] = Exports.new
      self['global'] = @native.Global
      self['GLOBAL'] = @native.Global
      self['rbputs'] = proc {|msg| puts msg.to_s}
      self['rbinspect'] = proc {|msg| puts msg.inspect}
      main = self.load(File.join(ENV['NODE_HOME'], 'src', 'node.js'))
      open do
        main.call(self['global'], self['process'])
      end
    end
  end
end


{'fraction_non_alphanumeric': 0.12818261633011413, 'fraction_numerical': 0.0026338893766461808, 'mean_word_length': 2.463019250253293, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '1491283', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1118, 'n_words': 288}