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

24 lines
676 B
Ruby
Raw Normal View History

class V8::Conversion
module Proc
def to_v8
2012-06-11 06:03:51 -04:00
template = V8::C::FunctionTemplate::New()
template.SetCallHandler(InvocationHandler.new, V8::C::External::New(self))
return template.GetFunction()
end
2012-06-11 06:03:51 -04:00
class InvocationHandler
def call(arguments)
context = V8::Context.current
proc = arguments.Data().Value()
args = ::Array.new(arguments.Length())
0.upto(args.length - 1) do |i|
args[i] = context.to_ruby arguments[i]
end
context.to_v8 proc.call(*args)
rescue Exception => e
warn "unhandled exception in ruby #{e.class}: #{e.message}"
nil
end
end
end
end