Sha256: c5f9079f44e5f8c8042579ccbdea8aa1d95b6d49fb5cb65788f5e134f518e063

Contents?: true

Size: 1.09 KB

Versions: 12

Compression:

Stored size: 1.09 KB

Contents

module V8
  class Portal
    class Functions
      def initialize(portal)
        @portal = portal
        @procs, @methods = {},{}
      end
      
      def [](code)
        self.send(code.class.name, code)
      end

      def Proc(p)
        @procs[p] ||= begin
          template = C::FunctionTemplate::New() do |arguments|
            rbargs = []
            for i in 0..arguments.Length() - 1
              rbargs << @portal.rb(arguments[i])
            end
            @portal.rubycall(p, *rbargs)
          end
          template.GetFunction()
        end
      end

      def UnboundMethod(method)
        @methods[method.to_s] ||= begin
          template = C::FunctionTemplate::New() do |arguments|
            rbargs = []
            for i in 0..arguments.Length() - 1
              rbargs << @portal.rb(arguments[i])
            end
            this = @portal.rb(arguments.This())
            @portal.rubyprotect do
              method.bind(this).call(*rbargs)
            end
          end
          template.GetFunction()
        end
      end

      alias_method :Method, :Proc
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
therubyracer-0.8.2 lib/v8/portal/functions.rb
therubyracer-0.8.2.pre2 lib/v8/portal/functions.rb
therubyracer-0.8.2.pre lib/v8/portal/functions.rb
therubyracer-0.8.1 lib/v8/portal/functions.rb
therubyracer-0.8.1.pre2 lib/v8/portal/functions.rb
therubyracer-heroku-0.8.1.pre3 lib/v8/portal/functions.rb
therubyracer-heroku-0.8.1.pre2 lib/v8/portal/functions.rb
therubyracer-0.8.1.pre1 lib/v8/portal/functions.rb
therubyracer-0.8.0 lib/v8/portal/functions.rb
therubyracer-0.8.0.pre3 lib/v8/portal/functions.rb
therubyracer-0.8.0.pre2 lib/v8/portal/functions.rb
therubyracer-0.8.0.pre lib/v8/portal/functions.rb