Parent

ExecJS::RubyRacerRuntime::Context

Public Class Methods

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

  lock do
    @v8_context = ::V8::Context.new
    @v8_context.eval(source)
  end
end

Public Instance Methods

call(properties, *args) click to toggle source
# File lib/execjs/ruby_racer_runtime.rb, line 39
def call(properties, *args)
  lock do
    begin
      unbox @v8_context.eval(properties).call(*args)
    rescue ::V8::JSError => e
      if e.value["name"] == "SyntaxError"
        raise RuntimeError, e.message
      else
        raise ProgramError, e.message
      end
    end
  end
end
eval(source, options = {}) click to toggle source
# File lib/execjs/ruby_racer_runtime.rb, line 21
def eval(source, options = {})
  source = source.encode('UTF-8') if source.respond_to?(:encode)

  if /\S/ =~ source
    lock do
      begin
        unbox @v8_context.eval("(#{source})")
      rescue ::V8::JSError => e
        if e.value["name"] == "SyntaxError"
          raise RuntimeError, e.message
        else
          raise ProgramError, e.message
        end
      end
    end
  end
end
exec(source, options = {}) click to toggle source
# File lib/execjs/ruby_racer_runtime.rb, line 13
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_racer_runtime.rb, line 53
def unbox(value)
  case value
  when ::V8::Function
    nil
  when ::V8::Array
    value.map { |v| unbox(v) }
  when ::V8::Object
    value.inject({}) do |vs, (k, v)|
      vs[k] = unbox(v) unless v.is_a?(::V8::Function)
      vs
    end
  when String
    value.respond_to?(:force_encoding) ?
      value.force_encoding('UTF-8') :
      value
  else
    value
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.