Class: V8::Portal::Functions
Instance Method Summary collapse
- #[](code) ⇒ Object
-
#initialize(portal) ⇒ Functions
constructor
A new instance of Functions.
- #Proc(p) ⇒ Object (also: #Method)
- #UnboundMethod(method) ⇒ Object
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| = [] for i in 0..arguments.Length() - 1 << @portal.rb(arguments[i]) end @portal.rubycall(p, *) 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| = [] for i in 0..arguments.Length() - 1 << @portal.rb(arguments[i]) end this = @portal.rb(arguments.This()) @portal.rubyprotect do method.bind(this).call(*) end end template.GetFunction() end end |