1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/lib/v8/conversion/class.rb
2012-06-15 05:12:52 -05:00

36 lines
No EOL
770 B
Ruby

class V8::Conversion
module Class
include V8::Util::Weakcell
def to_v8
fn = to_v8_template.GetFunction()
V8::Context.current.link self, fn
return fn
end
def to_v8_template
weakcell(:v8_constructor) do
template = V8::C::FunctionTemplate::New(Constructor.new(self))
end
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