Sha256: 521b68fa0b894a3b35805f85b06ed2c3d0e3e9449531275cc0d7d5b8e82535f1

Contents?: true

Size: 1.12 KB

Versions: 15

Compression:

Stored size: 1.12 KB

Contents

module V8
  class Portal
    class FunctionAdapter

      attr_reader :template

      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

15 entries across 15 versions & 1 rubygems

Version Path
therubyracer-0.9.10 lib/v8/portal/function.rb
therubyracer-0.9.9 lib/v8/portal/function.rb
therubyracer-0.9.8 lib/v8/portal/function.rb
therubyracer-0.9.7 lib/v8/portal/function.rb
therubyracer-0.9.6 lib/v8/portal/function.rb
therubyracer-0.9.5 lib/v8/portal/function.rb
therubyracer-0.9.4 lib/v8/portal/function.rb
therubyracer-0.9.3 lib/v8/portal/function.rb
therubyracer-0.9.3beta1 lib/v8/portal/function.rb
therubyracer-0.9.2 lib/v8/portal/function.rb
therubyracer-0.9.2beta1 lib/v8/portal/function.rb
therubyracer-0.9.1 lib/v8/portal/function.rb
therubyracer-0.9.1beta1 lib/v8/portal/function.rb
therubyracer-0.9.0 lib/v8/portal/function.rb
therubyracer-0.9.0beta7 lib/v8/portal/function.rb