1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/lib/v8/object.rb

44 lines
735 B
Ruby
Raw Normal View History

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)
@native.context.enter do
To.ruby(@native.Get(key.to_s))
end
end
def []=(key, value)
value.tap do
@native.context.enter do
@native.Set(key.to_s, value)
end
end
2009-12-18 02:48:06 -05:00
end
2010-01-10 13:56:10 -05:00
def to_s
@native.context.enter do
@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
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