2009-12-18 02:48:06 -05:00
|
|
|
|
|
|
|
module V8
|
|
|
|
class Object
|
2010-01-10 13:56:10 -05:00
|
|
|
include Enumerable
|
|
|
|
|
2009-12-18 02:48:06 -05:00
|
|
|
def initialize(native)
|
|
|
|
@native = native
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](key)
|
2010-05-18 06:27:23 -04:00
|
|
|
@native.context.enter do
|
2010-05-19 08:55:11 -04:00
|
|
|
To.ruby(@native.Get(To.v8(key)))
|
2010-01-13 17:51:46 -05:00
|
|
|
end
|
2010-01-10 05:02:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def []=(key, value)
|
|
|
|
value.tap do
|
2010-05-18 06:27:23 -04:00
|
|
|
@native.context.enter do
|
2010-05-19 08:55:11 -04:00
|
|
|
@native.Set(To.v8(key), To.v8(value))
|
2010-01-13 17:51:46 -05:00
|
|
|
end
|
2010-01-10 05:02:08 -05:00
|
|
|
end
|
2009-12-18 02:48:06 -05:00
|
|
|
end
|
2010-01-10 13:56:10 -05:00
|
|
|
|
2010-02-18 15:14:53 -05:00
|
|
|
def to_s
|
2010-05-18 06:27:23 -04:00
|
|
|
@native.context.enter do
|
2010-02-18 15:14:53 -05:00
|
|
|
@native.ToString()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-10 13:56:10 -05:00
|
|
|
def each
|
2010-05-22 02:23:22 -04:00
|
|
|
for prop in To.rb(@native.GetPropertyNames())
|
2010-01-10 13:56:10 -05:00
|
|
|
yield prop, self[prop]
|
|
|
|
end
|
|
|
|
end
|
2009-12-18 02:48:06 -05:00
|
|
|
end
|
2010-01-13 10:13:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Object
|
|
|
|
def eval_js(javascript)
|
|
|
|
V8::Context.open(:with => self) do |cxt|
|
|
|
|
cxt.eval(javascript)
|
|
|
|
end
|
|
|
|
end
|
2009-12-18 02:48:06 -05:00
|
|
|
end
|