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
2012-06-11 05:05:45 -05:00

24 lines
No EOL
676 B
Ruby

class V8::Conversion
module Proc
def to_v8
template = V8::C::FunctionTemplate::New()
template.SetCallHandler(InvocationHandler.new, V8::C::External::New(self))
return template.GetFunction()
end
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