mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
embed classes into javascript
This commit is contained in:
parent
683e525902
commit
2404e0c0f8
4 changed files with 21 additions and 2 deletions
|
@ -4,6 +4,7 @@ require 'v8/init'
|
|||
require 'v8/conversion/fundamental'
|
||||
require 'v8/conversion/indentity'
|
||||
require 'v8/conversion/primitive'
|
||||
require 'v8/conversion/class'
|
||||
require 'v8/conversion/object'
|
||||
require 'v8/conversion/time'
|
||||
require 'v8/conversion/hash'
|
||||
|
|
|
@ -18,7 +18,7 @@ for type in [TrueClass, FalseClass, NilClass, Numeric] do
|
|||
end
|
||||
end
|
||||
|
||||
for type in [Object, Array, Hash, String, Symbol, Time, Proc, Method] do
|
||||
for type in [Class, Object, Array, Hash, String, Symbol, Time, Proc, Method] do
|
||||
type.class_eval do
|
||||
include V8::Conversion.const_get(name)
|
||||
end
|
||||
|
|
17
lib/v8/conversion/class.rb
Normal file
17
lib/v8/conversion/class.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class V8::Conversion
|
||||
module Class
|
||||
def to_v8
|
||||
v8_constructor.GetFunction()
|
||||
end
|
||||
|
||||
def v8_constructor
|
||||
unless @v8_constructor && @v8_constructor.weakref_alive?
|
||||
template = V8::C::FunctionTemplate::New()
|
||||
# template.SetCallHandler(InvocationHandler.new, V8::C::External::New(self))
|
||||
@v8_constructor = WeakRef.new(template)
|
||||
end
|
||||
return @v8_constructor.__getobj__
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -18,7 +18,8 @@ class V8::Conversion
|
|||
def call(arguments)
|
||||
context = V8::Context.current
|
||||
proc = arguments.Data().Value()
|
||||
args = ::Array.new(arguments.Length())
|
||||
length_of_given_args = arguments.Length()
|
||||
args = ::Array.new(proc.arity < 0 ? length_of_given_args : [length_of_given_args, proc.arity].min)
|
||||
0.upto(args.length - 1) do |i|
|
||||
args[i] = context.to_ruby arguments[i]
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue