Class: ExecJS::MiniRacerRuntime::Context

Inherits:
Runtime::Context show all
Defined in:
lib/execjs/mini_racer_runtime.rb

Instance Method Summary collapse

Methods included from Encoding

#encode

Constructor Details

#initialize(runtime, source = "", options = {}) ⇒ Context

Returns a new instance of Context.



6
7
8
9
10
11
12
# File 'lib/execjs/mini_racer_runtime.rb', line 6

def initialize(runtime, source = "", options={})
  source = encode(source)
  @context = ::MiniRacer::Context.new
  translate do
    @context.eval(source)
  end
end

Instance Method Details

#call(identifier, *args) ⇒ Object



32
33
34
35
# File 'lib/execjs/mini_racer_runtime.rb', line 32

def call(identifier, *args)
  # TODO optimise generate
  eval "#{identifier}.apply(this, #{::JSON.generate(args)})"
end

#eval(source, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/execjs/mini_racer_runtime.rb', line 22

def eval(source, options = {})
  source = encode(source)

  if /\S/ =~ source
    translate do
      @context.eval("(#{source})")
    end
  end
end

#exec(source, options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/execjs/mini_racer_runtime.rb', line 14

def exec(source, options = {})
  source = encode(source)

  if /\S/ =~ source
    eval "(function(){#{source}})()"
  end
end