Sha256: e4ed7c2375ef1d28976f30f364b3e44a1463ef37fbc343af9b54d44758f62dc1

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

module V8
  class Portal
    class FunctionAdapter

      attr_reader :template, :function

      def initialize(portal, code)
        @portal = portal
        @caller = code.respond_to?(:call) ? Call.new(portal) : BindAndCall.new(portal)
        @code = code
        @template = V8::C::FunctionTemplate::New(@caller, @code)
      end

      def function
        @template.GetFunction()
      end
      
      class Call
        def initialize(portal)
          @portal = portal
        end

        def call(arguments)
          proc = arguments.Data()
          rbargs = []
          for i in 0..arguments.Length() - 1
            rbargs << @portal.rb(arguments[i])
          end
          @portal.caller.invoke(proc, *rbargs)
        end
      end
      
      class BindAndCall < Call
        def call(arguments)
          method = arguments.Data()
          rbargs = []
          for i in 0..arguments.Length() - 1
            rbargs << @portal.rb(arguments[i])
          end
          this = @portal.rb(arguments.This())
          @portal.caller.protect do
            method.bind(this).call(*rbargs)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
therubyracer-0.9.0beta6 lib/v8/portal/function.rb
therubyracer-0.9.0beta5 lib/v8/portal/function.rb
therubyracer-0.9.0beta4 lib/v8/portal/function.rb
therubyracer-0.9.0beta3 lib/v8/portal/function.rb
therubyracer-0.9.0beta2 lib/v8/portal/function.rb
therubyracer-0.9.0beta1 lib/v8/portal/function.rb