Class: V8::Portal::Functions

Inherits:
Object
  • Object
show all
Defined in:
lib/v8/portal/functions.rb

Instance Method Summary collapse

Constructor Details

#initialize(portal) ⇒ Functions

Returns a new instance of Functions.



4
5
6
7
# File 'lib/v8/portal/functions.rb', line 4

def initialize(portal)
  @portal = portal
  @procs, @methods = {},{}
end

Instance Method Details

#[](code) ⇒ Object



9
10
11
# File 'lib/v8/portal/functions.rb', line 9

def [](code)
  self.send(code.class.name, code)
end

#Proc(p) ⇒ Object Also known as: Method



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/v8/portal/functions.rb', line 13

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

#UnboundMethod(method) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/v8/portal/functions.rb', line 26

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