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

embed classes as constructors

This commit is contained in:
Charles Lowell 2012-06-14 23:11:21 -05:00
parent be963bbc95
commit 7bc06b27c0

View file

@ -4,8 +4,27 @@ class V8::Conversion
def to_v8
weakcell(:v8_constructor) do
V8::C::FunctionTemplate::New()
V8::C::FunctionTemplate::New(Constructor.new(self))
end.GetFunction()
end
class Constructor
include V8::Error::Protect
def initialize(cls)
@class = cls
end
def call(arguments)
protect do
context = V8::Context.current
args = ::Array.new(arguments.Length())
0.upto(args.length - 1) do |i|
args[i] = context.to_ruby arguments[i]
end
context.to_v8 @class.new(*args)
end
end
end
end
end