1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/lib/v8/function.rb

55 lines
1.2 KiB
Ruby
Raw Normal View History

2010-04-21 19:09:13 -04:00
module V8
class Function < V8::Object
def methodcall(thisObject, *args)
err = nil
return_value = nil
C::TryCatch.try do |try|
@context.enter do
this = To.v8(thisObject)
return_value = To.rb(@native.Call(this, To.v8(args)))
err = JSError.new(try) if try.HasCaught()
end
end
raise err if err
return return_value
2010-04-21 19:09:13 -04:00
end
def call(*args)
self.methodcall(@context.Global(), *args)
end
def new(*args)
@context.enter do
To.rb(@native.NewInstance(To.v8(args)))
end
end
def self.rubyprotect
begin
To.v8(yield)
rescue Exception => e
2010-06-15 16:05:40 -04:00
case e
when SystemExit, NoMemoryError
raise e
else
error = V8::C::Exception::Error(V8::C::String::New(e.message))
error.SetHiddenValue("TheRubyRacer::Cause", C::External::New(e))
V8::C::ThrowException(error)
end
end
end
def self.rubycall(rubycode, *args)
rubyprotect do
rubycode.call(*args)
end
end
def self.rubysend(obj, message, *args)
rubyprotect do
obj.send(message, *args)
end
end
2010-04-21 19:09:13 -04:00
end
end