Sha256: 44141a409db8ffc566ae9b81d2b100bdd646c127747ad63be6144aaf3dce8d23

Contents?: true

Size: 902 Bytes

Versions: 2

Compression:

Stored size: 902 Bytes

Contents

module V8
  class Object
    include Enumerable
    
    def initialize(native, context = nil)
      @native = native
      @context = context || C::Context::GetEntered()
      raise ScriptError, "V8::Object.new called without an open V8 context" unless @context
    end
    
    def [](key)
      @context.enter do
        To.ruby(@native.Get(To.v8(key)))        
      end
    end
    
    def []=(key, value)
      value.tap do
        @context.enter do
          @native.Set(To.v8(key), To.v8(value))
        end
      end
    end
    
    def to_s
      @context.enter do
        To.rb(@native.ToString())
      end
    end
    
    def each
      @context.enter do
        for prop in To.rb(@native.GetPropertyNames())
          yield prop, self[prop]
        end
      end
    end
  end
end

class Object  
  def eval_js(javascript)
    V8::Context.new(:with => self).eval(javascript)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
therubyracer-0.7.0 lib/v8/object.rb
therubyracer-0.7.0.pre lib/v8/object.rb