Class: MiniRacer::Context

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

Overview

eval is defined in the C class

Defined Under Namespace

Classes: ExternalFunction

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Context

Returns a new instance of Context.



77
78
79
80
81
82
83
84
85
86
# File 'lib/mini_racer.rb', line 77

def initialize(options = nil)
  @functions = {}
  @lock = Mutex.new
  @timeout = nil
  @current_exception = nil

  if options
    @timeout = options[:timeout]
  end
end

Instance Method Details

#attach(name, callback) ⇒ Object



100
101
102
103
104
105
# File 'lib/mini_racer.rb', line 100

def attach(name, callback)
  @lock.synchronize do
    external = ExternalFunction.new(name, callback, self)
    @functions["#{name}"] = external
  end
end

#eval(str) ⇒ Object



93
94
95
96
97
98
# File 'lib/mini_racer.rb', line 93

def eval(str)
  @lock.synchronize do
    @current_exception = nil
    eval_unsafe(str)
  end
end

#load(filename) ⇒ Object



88
89
90
91
# File 'lib/mini_racer.rb', line 88

def load(filename)
  # TODO do this native cause no need to allocate VALUE here
  eval(File.read(filename))
end