Class: ExecJS::DuktapeRuntime::Context

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

Instance Method Summary collapse

Methods included from Encoding

#encode

Constructor Details

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

Returns a new instance of Context.



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

def initialize(runtime, source = "", options = {})
  @ctx = Duktape::Context.new(complex_object: nil)
  @ctx.exec_string(encode(source), '(execjs)')
rescue Exception => e
  raise wrap_error(e)
end

Instance Method Details

#call(identifier, *args) ⇒ Object



28
29
30
31
32
# File 'lib/execjs/duktape_runtime.rb', line 28

def call(identifier, *args)
  @ctx.call_prop(identifier.split("."), *args)
rescue Exception => e
  raise wrap_error(e)
end

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



21
22
23
24
25
26
# File 'lib/execjs/duktape_runtime.rb', line 21

def eval(source, options = {})
  return unless /\S/ =~ source
  @ctx.eval_string("(#{encode(source)})", '(execjs)')
rescue Exception => e
  raise wrap_error(e)
end

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



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

def exec(source, options = {})
  return unless /\S/ =~ source
  @ctx.eval_string("(function(){#{encode(source)}})()", '(execjs)')
rescue Exception => e
  raise wrap_error(e)
end