Class: Mila::Benchmark::Mixin::V8Session

Inherits:
Object
  • Object
show all
Defined in:
lib/mila/benchmark/mixin.rb

Instance Method Summary collapse

Constructor Details

#initializeV8Session

Returns a new instance of V8Session.



28
29
30
31
32
33
# File 'lib/mila/benchmark/mixin.rb', line 28

def initialize
  @queue = Queue.new
  @thread = Thread.new { create_context }
  @body = nil
  @has_source = false
end

Instance Method Details

#call(*args) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mila/benchmark/mixin.rb', line 52

def call(*args)
  case args
  in [function_name, args_array]
    function_name = function_name.to_s
  in [args_array]
    function_name = @body.entrypoint_name
  else
    raise ArgumentError, 'Invalid arguments'
  end
  context.call(function_name, args_array)
end

#contextObject



35
36
37
# File 'lib/mila/benchmark/mixin.rb', line 35

def context
  @context ||= @queue.pop
end

#eval_inline(&block) ⇒ Object



39
40
41
42
43
# File 'lib/mila/benchmark/mixin.rb', line 39

def eval_inline(&block)
  @body = JS::Body::Inline.new
  @body.open(&block)
  add_source(@body)
end

#load_bundleable_lib(lib) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
49
50
# File 'lib/mila/benchmark/mixin.rb', line 45

def load_bundleable_lib(lib)
  raise ArgumentError if lib.nil?

  @body = JS::Body::Library.new(lib)
  add_source(@body)
end