Class: V8::Portal::Caller

Inherits:
Object show all
Defined in:
lib/v8/portal/caller.rb

Instance Method Summary collapse

Constructor Details

#initialize(portal) ⇒ Caller

Returns a new instance of Caller.



6
7
8
# File 'lib/v8/portal/caller.rb', line 6

def initialize(portal)
  @portal = portal
end

Instance Method Details

#invoke(code, *args, &block) ⇒ Object



31
32
33
34
35
# File 'lib/v8/portal/caller.rb', line 31

def invoke(code, *args, &block)
  protect do
    code.call(*args, &block)
  end
end

#protect(*args, &block) ⇒ Object



27
28
29
# File 'lib/v8/portal/caller.rb', line 27

def protect(*args, &block)
  @portal.v8 raw(*args, &block)
end

#rawObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/v8/portal/caller.rb', line 10

def raw
  begin
    yield
  rescue Exception => e
    case e
    when SystemExit, NoMemoryError
      raise e
    else
      error = V8::C::Exception::Error(V8::C::String::New(e.message))
      #TODO: This is almost certainly a crash here.
      #we need to hold onto `error` while it bubbles up the javascript stack.
      error.SetHiddenValue("TheRubyRacer::Cause", C::External::New(e))
      V8::C::ThrowException(error)
    end
  end
end