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-01-13 17:51:46 -05:00
|
|
|
@native.context.open do
|
|
|
|
To.ruby(@native.Get(key.to_s))
|
|
|
|
end
|
2010-01-10 05:02:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def []=(key, value)
|
|
|
|
value.tap do
|
2010-01-13 17:51:46 -05:00
|
|
|
@native.context.open do
|
|
|
|
@native.Set(key.to_s, value)
|
|
|
|
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
|
|
|
|
|
|
|
def each
|
|
|
|
for prop in @native.GetPropertyNames()
|
|
|
|
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
|