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
13
# File 'lib/execjs/mini_racer_runtime.rb', line 6

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

Instance Method Details

#call(identifier, *args) ⇒ Object



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

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

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



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

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

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

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



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

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

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