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
2012-06-07 11:40:53 -05:00

32 lines
No EOL
639 B
Ruby

class V8::Object
include Enumerable
attr_reader :native
def initialize(native)
@native = native
@context = V8::Context.current
end
def [](key)
@context.enter do
@context.to_ruby @native.Get(@context.to_v8(key))
end
end
def []=(key, value)
@context.enter do
@native.Set(@context.to_v8(key), @context.to_v8(value))
end
return value
end
def each
@context.enter do
names = @native.GetPropertyNames()
0.upto(@native.Length() - 1) do |i|
name = names.Get(i)
yield @context.to_ruby(name), @context.to_ruby(@native.Get(name))
end
end
end
end