Class: ExecJS::ExternalRuntime::Context

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

Instance Method Summary collapse

Constructor Details

#initialize(runtime, source = "") ⇒ Context

Returns a new instance of Context.



6
7
8
9
# File 'lib/execjs/external_runtime.rb', line 6

def initialize(runtime, source = "")
  @runtime = runtime
  @source  = source
end

Instance Method Details

#call(identifier, *args) ⇒ Object



23
24
25
# File 'lib/execjs/external_runtime.rb', line 23

def call(identifier, *args)
  eval "#{identifier}.apply(this, #{MultiJson.encode(args)})"
end

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



11
12
13
14
15
# File 'lib/execjs/external_runtime.rb', line 11

def eval(source, options = {})
  if /\S/ =~ source
    exec("return eval(#{MultiJson.encode("(#{source})")})")
  end
end

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



17
18
19
20
21
# File 'lib/execjs/external_runtime.rb', line 17

def exec(source, options = {})
  compile_to_tempfile([@source, source].join("\n")) do |file|
    extract_result(@runtime.send(:exec_runtime, file.path))
  end
end