2012-06-11 01:58:12 -05:00
|
|
|
class V8::Conversion
|
|
|
|
module Object
|
2012-06-12 04:18:17 -05:00
|
|
|
include V8::Util::Weakcell
|
|
|
|
|
2012-06-11 01:58:12 -05:00
|
|
|
def to_v8
|
2012-06-15 08:26:47 -05:00
|
|
|
context = V8::Context.current
|
|
|
|
constructor = context.to_v8(self.class)
|
|
|
|
object = constructor.NewInstance([V8::C::External::New(self)])
|
2012-06-12 03:44:50 -05:00
|
|
|
return object
|
|
|
|
end
|
|
|
|
|
2012-06-11 01:58:12 -05:00
|
|
|
def to_ruby
|
|
|
|
self
|
|
|
|
end
|
2012-06-15 10:10:22 -05:00
|
|
|
|
|
|
|
def eval_js(source, filename = '<eval>')
|
|
|
|
V8::Context.new(:with => self).eval(source, filename)
|
|
|
|
end
|
2012-06-11 01:58:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
module NativeObject
|
|
|
|
def to_ruby
|
2012-06-12 07:06:25 -05:00
|
|
|
wrap = if IsArray()
|
|
|
|
::V8::Array
|
|
|
|
elsif IsFunction()
|
|
|
|
::V8::Function
|
|
|
|
else
|
|
|
|
::V8::Object
|
|
|
|
end
|
|
|
|
wrap.new(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_v8
|
|
|
|
self
|
2012-06-11 01:58:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|