module.rb 803 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. require "execjs/version"
  2. require "rbconfig"
  3. module ExecJS
  4. class Error < ::StandardError; end
  5. class RuntimeError < Error; end
  6. class ProgramError < Error; end
  7. class RuntimeUnavailable < RuntimeError; end
  8. class << self
  9. attr_reader :runtime
  10. def runtime=(runtime)
  11. raise RuntimeUnavailable, "#{runtime.name} is unavailable on this system" unless runtime.available?
  12. @runtime = runtime
  13. end
  14. def exec(source)
  15. runtime.exec(source)
  16. end
  17. def eval(source)
  18. runtime.eval(source)
  19. end
  20. def compile(source)
  21. runtime.compile(source)
  22. end
  23. def root
  24. @root ||= File.expand_path("..", __FILE__)
  25. end
  26. def windows?
  27. @windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
  28. end
  29. end
  30. end