2010-04-21 19:09:13 -04:00
|
|
|
module V8
|
|
|
|
class Function < V8::Object
|
|
|
|
|
2010-06-03 05:51:06 -04:00
|
|
|
def methodcall(thisObject, *args)
|
2010-05-26 12:54:56 -04:00
|
|
|
err = nil
|
|
|
|
return_value = nil
|
|
|
|
C::TryCatch.try do |try|
|
|
|
|
@context.enter do
|
|
|
|
this = To.v8(thisObject)
|
2010-06-07 03:59:41 -04:00
|
|
|
return_value = To.rb(@native.Call(this, To.v8(args)))
|
2010-06-11 10:11:49 -04:00
|
|
|
err = JSError.new(try) if try.HasCaught()
|
2010-05-26 12:54:56 -04:00
|
|
|
end
|
2010-05-26 03:49:53 -04:00
|
|
|
end
|
2010-05-26 12:54:56 -04:00
|
|
|
raise err if err
|
|
|
|
return return_value
|
2010-04-21 19:09:13 -04:00
|
|
|
end
|
2010-06-03 05:51:06 -04:00
|
|
|
|
|
|
|
def call(*args)
|
|
|
|
self.methodcall(@context.Global(), *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def new(*args)
|
|
|
|
@context.enter do
|
2010-06-03 06:56:07 -04:00
|
|
|
To.rb(@native.NewInstance(To.v8(args)))
|
2010-06-03 05:51:06 -04:00
|
|
|
end
|
|
|
|
end
|
2010-05-27 11:30:19 -04:00
|
|
|
|
|
|
|
def self.rubycall(rubycode, *args)
|
|
|
|
begin
|
|
|
|
To.v8(rubycode.call(*args))
|
2010-06-14 08:51:17 -04:00
|
|
|
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
|
2010-05-27 11:30:19 -04:00
|
|
|
end
|
|
|
|
end
|
2010-04-21 19:09:13 -04:00
|
|
|
end
|
|
|
|
end
|