Parent

ExecJS::RubyRhinoRuntime::Context

Public Class Methods

new(source = "") click to toggle source
# File lib/execjs/ruby_rhino_runtime.rb, line 4
def initialize(source = "")
  source = source.encode('UTF-8') if source.respond_to?(:encode)

  @rhino_context = ::Rhino::Context.new
  fix_memory_limit! @rhino_context
  @rhino_context.eval(source)
end

Public Instance Methods

call(properties, *args) click to toggle source
# File lib/execjs/ruby_rhino_runtime.rb, line 34
def call(properties, *args)
  unbox @rhino_context.eval(properties).call(*args)
rescue ::Rhino::JavascriptError => e
  if e.message == "syntax error"
    raise RuntimeError, e.message
  else
    raise ProgramError, e.message
  end
end
eval(source, options = {}) click to toggle source
# File lib/execjs/ruby_rhino_runtime.rb, line 20
def eval(source, options = {})
  source = source.encode('UTF-8') if source.respond_to?(:encode)

  if /\S/ =~ source
    unbox @rhino_context.eval("(#{source})")
  end
rescue ::Rhino::JavascriptError => e
  if e.message == "syntax error"
    raise RuntimeError, e.message
  else
    raise ProgramError, e.message
  end
end
exec(source, options = {}) click to toggle source
# File lib/execjs/ruby_rhino_runtime.rb, line 12
def exec(source, options = {})
  source = source.encode('UTF-8') if source.respond_to?(:encode)

  if /\S/ =~ source
    eval "(function(){#{source}})()", options
  end
end
unbox(value) click to toggle source
# File lib/execjs/ruby_rhino_runtime.rb, line 44
def unbox(value)
  case value = ::Rhino::To.ruby(value)
  when ::Rhino::NativeFunction
    nil
  when ::Rhino::NativeObject
    value.inject({}) do |vs, (k, v)|
      case v
      when ::Rhino::NativeFunction, ::Rhino::J::Function
        nil
      else
        vs[k] = unbox(v)
      end
      vs
    end
  when Array
    value.map { |v| unbox(v) }
  else
    value
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.