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-01-13 17:51:46 -05:00
|
|
|
To.ruby(@native.Get(key.to_s))
|
|
|
|
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-01-13 17:51:46 -05:00
|
|
|
@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
|
|
|
|
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-18 13:50:59 -04:00
|
|
|
for prop in To.ruby(@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
|