mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
35 lines
No EOL
633 B
Ruby
35 lines
No EOL
633 B
Ruby
class V8::Conversion
|
|
module Object
|
|
def to_v8
|
|
context = V8::Context.current
|
|
constructor = context.to_v8(self.class)
|
|
object = constructor.NewInstance([V8::C::External::New(self)])
|
|
return object
|
|
end
|
|
|
|
def to_ruby
|
|
self
|
|
end
|
|
|
|
def eval_js(source, filename = '<eval>')
|
|
V8::Context.new(:with => self).eval(source, filename)
|
|
end
|
|
end
|
|
|
|
module NativeObject
|
|
def to_ruby
|
|
wrap = if IsArray()
|
|
::V8::Array
|
|
elsif IsFunction()
|
|
::V8::Function
|
|
else
|
|
::V8::Object
|
|
end
|
|
wrap.new(self)
|
|
end
|
|
|
|
def to_v8
|
|
self
|
|
end
|
|
end
|
|
end |