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:
parent
95836be78e
commit
b0fabb2f28
1 changed files with 8 additions and 8 deletions
|
@ -9,27 +9,27 @@ class V8::Conversion
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_v8_template
|
def to_v8_template
|
||||||
weakcell(:v8_template) do
|
weakcell(:v8_template) {V8::C::FunctionTemplate::New(InvocationHandler.new(self))}
|
||||||
template = V8::C::FunctionTemplate::New()
|
|
||||||
template.SetCallHandler(InvocationHandler.new, V8::C::External::New(self))
|
|
||||||
template
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class InvocationHandler
|
class InvocationHandler
|
||||||
include V8::Error::Protect
|
include V8::Error::Protect
|
||||||
|
|
||||||
|
def initialize(proc)
|
||||||
|
@proc = proc
|
||||||
|
end
|
||||||
|
|
||||||
def call(arguments)
|
def call(arguments)
|
||||||
protect do
|
protect do
|
||||||
context = V8::Context.current
|
context = V8::Context.current
|
||||||
proc = arguments.Data().Value()
|
|
||||||
length_of_given_args = arguments.Length()
|
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|
|
0.upto(args.length - 1) do |i|
|
||||||
if i < length_of_given_args
|
if i < length_of_given_args
|
||||||
args[i] = context.to_ruby arguments[i]
|
args[i] = context.to_ruby arguments[i]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context.to_v8 proc.call(*args)
|
context.to_v8 @proc.call(*args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue