Sha256: 8e87e4cf6a153e06574fa106c6ba1c1ebb83bef2e090544b18092377076fb483

Contents?: true

Size: 1.38 KB

Versions: 54

Compression:

Stored size: 1.38 KB

Contents

module V8
  class Object
    include Enumerable

    def initialize(native, portal)
      @native, @portal = native, portal
    end

    def [](key)
      @portal.open do |to|
        to.rb(@native.Get(to.v8(key)))
      end
    end

    def []=(key, value)
      value.tap do
        @portal.open do |to|
          @native.Set(to.v8(key), to.v8(value))
        end
      end
    end

    def to_s
      @portal.open do |to|
        to.rb(@native.ToString())
      end
    end

    def each
      @portal.open do |to|
        for prop in to.rb(@native.GetPropertyNames())
          yield prop, self[prop]
        end
      end
    end

    def respond_to?(method)
      super or self[method] != nil
    end

    def method_missing(name, *args, &block)
      if name.to_s =~ /(.*)=$/
        if args.length > 1
          self[$1] = args
          return args
        else
          self[$1] = args.first
          return args
        end
      end
      return super(name, *args, &block) unless self.respond_to?(name)
      property = self[name]
      if property.kind_of?(V8::Function)
        property.methodcall(self, *args)
      elsif args.empty?
        property
      else
        raise ArgumentError, "wrong number of arguments (#{args.length} for 0)" unless args.empty?
      end
    end
  end
end

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

Version data entries

54 entries across 54 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.7.4 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.7.3 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.7.2 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.7.1 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.7.0 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.6.9 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.6.8 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.6.7 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.6.6 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.6.5 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.6.4 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.6.3 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.6.2 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.6.1 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.6.0 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.5.17 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.5.16 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.5.15 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb
classiccms-0.5.14 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/object.rb