Class: V8::Function

Inherits:
Object show all
Includes:
Error::Try
Defined in:
lib/v8/function.rb

Instance Attribute Summary

Attributes inherited from Object

#native

Instance Method Summary collapse

Methods included from Error::Try

#try

Methods inherited from Object

#[], #[]=, #each, #keys, #method_missing, #respond_to?, #to_s, #values

Constructor Details

#initialize(native = nil) ⇒ Function

Returns a new instance of Function.



4
5
6
7
8
# File 'lib/v8/function.rb', line 4

def initialize(native = nil)
  super do
    native || V8::C::FunctionTemplate::New().GetFunction()
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class V8::Object

Instance Method Details

#call(*args) ⇒ Object



17
18
19
20
21
# File 'lib/v8/function.rb', line 17

def call(*args)
  @context.enter do
    methodcall @context.native.Global(), *args
  end
end

#methodcall(this, *args) ⇒ Object



10
11
12
13
14
15
# File 'lib/v8/function.rb', line 10

def methodcall(this, *args)
  @context.enter do
    this ||= @context.native.Global()
    @context.to_ruby try {native.Call(@context.to_v8(this), args.map {|a| @context.to_v8 a})}
  end
end

#new(*args) ⇒ Object



23
24
25
26
27
# File 'lib/v8/function.rb', line 23

def new(*args)
  @context.enter do
    @context.to_ruby try {native.NewInstance(args.map {|a| @context.to_v8 a})}
  end
end