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)
if methods.include?(name)
method = obj.method(name)
method.arity == 0 ? method.call : method
method.arity == 0 ? method.call : method.unbind
elsif obj.respond_to?(:[])
obj.send(:[], name, &dontintercept)
else

View file

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

View file

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