Sha256: ae60d3ccd77da1efa217f6cafaa6b9d9034674ed4e6e43db0f24e39ea486f5ac

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require "rbconfig"

module ExecJS
  class Error           < ::StandardError; end
  class RuntimeError              < Error; end
  class ProgramError              < Error; end
  class RuntimeUnavailable < RuntimeError; end

  autoload :ExternalRuntime,  "execjs/external_runtime"
  autoload :MustangRuntime,   "execjs/mustang_runtime"
  autoload :RubyRacerRuntime, "execjs/ruby_racer_runtime"
  autoload :RubyRhinoRuntime, "execjs/ruby_rhino_runtime"
  autoload :Runtimes,         "execjs/runtimes"

  class << self
    attr_reader :runtime

    def exec(source)
      runtime.exec(source)
    end

    def eval(source)
      runtime.eval(source)
    end

    def compile(source)
      runtime.compile(source)
    end

    def runtimes
      Runtimes.runtimes
    end

    def runtime=(runtime)
      raise RuntimeUnavailable, "#{runtime.name} is unavailable on this system" unless runtime.available?
      @runtime = runtime
    end

    def root
      @root ||= File.expand_path("../execjs", __FILE__)
    end

    def windows?
      @windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
    end
  end

  # Eagerly detect runtime
  self.runtime ||= Runtimes.best_available ||
    raise(RuntimeUnavailable, "Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.")
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
execjs-0.4.0 lib/execjs.rb