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

maps the same ruby methods and procs to the same function per context.

This commit is contained in:
Charles Lowell 2010-08-28 17:36:48 -05:00
parent a52b227328
commit 30d2ef4147
2 changed files with 21 additions and 13 deletions

View file

@ -36,6 +36,24 @@ module V8
end
end
end
@instances = Hash.new do |h, obj|
args = C::Array::New(1)
args.Set(0, C::External::New(obj))
h[obj] = @constructors[obj.class].GetFunction().NewInstance(args)
end
@functions = Hash.new do |h, code|
template = C::FunctionTemplate::New() do |arguments|
rbargs = []
for i in 0..arguments.Length() - 1
rbargs << rb(arguments[i])
end
rubycall(code, *rbargs)
end
h[code] = template.GetFunction()
end
@embedded_constructors = Hash.new do |h, cls|
template = @constructors[cls]
template.SetCallHandler() do |arguments|
@ -86,14 +104,7 @@ module V8
when Symbol
C::String::NewSymbol(value.to_s)
when Proc,Method
template = C::FunctionTemplate::New() do |arguments|
rbargs = []
for i in 0..arguments.Length() - 1
rbargs << rb(arguments[i])
end
rubycall(value, *rbargs)
end
return template.GetFunction()
@functions[value]
when ::Array
C::Array::New(value.length).tap do |a|
value.each_with_index do |item, i|
@ -120,10 +131,7 @@ module V8
when nil,Numeric,TrueClass,FalseClass, C::Value
value
else
args = C::Array::New(1)
args.Set(0, C::External::New(value))
obj = @constructors[value.class].GetFunction().NewInstance(args)
return obj
@instances[value]
end
end

@ -1 +1 @@
Subproject commit f21d420e069f13d645750c35d859b12d18c10ce4
Subproject commit c31c63069ea30db0cdbd02602617636fe83dd15f