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:
parent
be963bbc95
commit
7bc06b27c0
1 changed files with 20 additions and 1 deletions
|
@ -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
|
Loading…
Add table
Reference in a new issue