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

extract the function tracking into its own separate module.

This commit is contained in:
Charles Lowell 2011-04-26 20:50:36 -05:00
parent 39ef745e97
commit 9f0f36db9b
3 changed files with 45 additions and 36 deletions

View file

@ -42,7 +42,9 @@ module V8
when Symbol
C::String::NewSymbol(value.to_s)
when Proc,Method,UnboundMethod
@functions[value]
@proxies.rb2js(value) do
@functions.to_function(value).function
end
when ::Array
C::Array::New(value.length).tap do |a|
value.each_with_index do |item, i|

View file

@ -3,32 +3,38 @@ module V8
class Functions
def initialize(portal)
@portal = portal
@procs, @methods = {},{}
@procs = {}
@methods = {}
end
def [](code)
self.send(code.class.name, code)
def to_function(code)
case code
when Method, UnboundMethod
#TODO: clear this reference when the C::FunctionTemplate becomes weak.
@methods[code.to_s] ||= Template.new(@portal, code.kind_of?(Method) ? :invoke_callable : :invoke_unbound_method, code)
else
if code.respond_to?(:call)
#TODO: clear with reference when the C::FunctionTemplate becomes weak.
@procs[code] ||= Template.new(@portal, :invoke_callable, code)
else
fail "invalid code type: #{code.class}"
end
def Proc(p)
#TODO: check this for memory leaks
@procs[p] ||= begin
template = C::FunctionTemplate::New(method(:callproc), p)
template.GetFunction()
end
end
def UnboundMethod(method)
#TODO: check this for memory leaks.
@methods[method.to_s] ||= begin
template = C::FunctionTemplate::New(method(:callmethod), method)
template.GetFunction()
end
class Template
attr_reader :template, :function
def initialize(portal, impl, code)
@portal = portal
@template = V8::C::FunctionTemplate::New(method(impl), code)
end
alias_method :Method, :Proc
def function
@template.GetFunction()
end
def callproc(arguments)
def invoke_callable(arguments)
proc = arguments.Data()
rbargs = []
for i in 0..arguments.Length() - 1
@ -37,7 +43,7 @@ module V8
@portal.rubycall(proc, *rbargs)
end
def callmethod(arguments)
def invoke_unbound_method(arguments)
method = arguments.Data()
rbargs = []
for i in 0..arguments.Length() - 1
@ -51,3 +57,4 @@ module V8
end
end
end
end

@ -1 +1 @@
Subproject commit 8ea1e0d6b9e0a77b026b1b5d80a39c8eff486b92
Subproject commit ff7bd687925baf2c207a987c9dc973452236415f