Class: Quickjs::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/quickjs/function.rb

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Function

Returns a new instance of Function.



7
8
9
# File 'lib/quickjs/function.rb', line 7

def initialize(source)
  @source = source
end

Instance Method Details

#call(*args, on: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/quickjs/function.rb', line 15

def call(*args, on: nil)
  case on
  when Quickjs::VM
    _call_on(on, args)
  when nil, Hash
    vm = Quickjs::VM.new(**on || {})
    res = _call_on(vm, args)
    vm = nil
    res
  else
    raise ArgumentError, 'on: must be a Quickjs::VM, a Hash of VM options, or nil'
  end
end

#sourceObject



11
12
13
# File 'lib/quickjs/function.rb', line 11

def source
  @source
end