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

proc invocation handlers reference procs directly

This commit is contained in:
Charles Lowell 2012-06-16 03:44:58 -05:00
parent 95836be78e
commit b0fabb2f28

View file

@ -9,27 +9,27 @@ class V8::Conversion
end
def to_v8_template
weakcell(:v8_template) do
template = V8::C::FunctionTemplate::New()
template.SetCallHandler(InvocationHandler.new, V8::C::External::New(self))
template
end
weakcell(:v8_template) {V8::C::FunctionTemplate::New(InvocationHandler.new(self))}
end
class InvocationHandler
include V8::Error::Protect
def initialize(proc)
@proc = proc
end
def call(arguments)
protect do
context = V8::Context.current
proc = arguments.Data().Value()
length_of_given_args = arguments.Length()
args = ::Array.new(proc.arity < 0 ? length_of_given_args : proc.arity)
args = ::Array.new(@proc.arity < 0 ? length_of_given_args : @proc.arity)
0.upto(args.length - 1) do |i|
if i < length_of_given_args
args[i] = context.to_ruby arguments[i]
end
end
context.to_v8 proc.call(*args)
context.to_v8 @proc.call(*args)
end
end
end