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

support explicity embedding both bound and unbound methods.

This commit is contained in:
Charles Lowell 2010-08-30 14:23:50 -05:00
parent 88754089f5
commit 4d7003a6f6
3 changed files with 20 additions and 22 deletions

View file

@ -5,7 +5,7 @@ module V8
methods = accessible_methods(obj) methods = accessible_methods(obj)
if methods.include?(name) if methods.include?(name)
method = obj.method(name) method = obj.method(name)
method.arity == 0 ? method.call : method method.arity == 0 ? method.call : method.unbind
elsif obj.respond_to?(:[]) elsif obj.respond_to?(:[])
obj.send(:[], name, &dontintercept) obj.send(:[], name, &dontintercept)
else else

View file

@ -94,7 +94,7 @@ module V8
C::String::New(value.to_s) C::String::New(value.to_s)
when Symbol when Symbol
C::String::NewSymbol(value.to_s) C::String::NewSymbol(value.to_s)
when Proc,Method when Proc,Method,UnboundMethod
@functions[value] @functions[value]
when ::Array when ::Array
C::Array::New(value.length).tap do |a| C::Array::New(value.length).tap do |a|

View file

@ -7,41 +7,39 @@ module V8
end end
def [](code) def [](code)
case code self.send(code.class.name, code)
when Proc end
@procs[code] ||= begin
def Proc(p)
@procs[p] ||= begin
template = C::FunctionTemplate::New() do |arguments| template = C::FunctionTemplate::New() do |arguments|
rbargs = [] rbargs = []
for i in 0..arguments.Length() - 1 for i in 0..arguments.Length() - 1
rbargs << @portal.rb(arguments[i]) rbargs << @portal.rb(arguments[i])
end end
@portal.rubycall(code, *rbargs) @portal.rubycall(p, *rbargs)
end end
template.GetFunction() template.GetFunction()
end end
when Method
get_method(code)
end
end end
def get_method(method) def UnboundMethod(method)
unbound = method.unbind @methods[method.to_s] ||= begin
@methods[unbound.to_s] ||= begin
template = C::FunctionTemplate::New() do |arguments| template = C::FunctionTemplate::New() do |arguments|
rbargs = [] rbargs = []
for i in 0..arguments.Length() - 1 for i in 0..arguments.Length() - 1
rbargs << @portal.rb(arguments[i]) rbargs << @portal.rb(arguments[i])
end end
this = @portal.rb(arguments.This()) this = @portal.rb(arguments.This())
begin @portal.rubyprotect do
@portal.rubycall(unbound.bind(this), *rbargs) method.bind(this).call(*rbargs)
rescue Exception => e
raise e
end end
end end
template.GetFunction() template.GetFunction()
end end
end end
alias_method :Method, :Proc
end end
end end
end end