Class: ExecJS::DuktapeRuntime::Context

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

Instance Method Summary collapse

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(source.encode(Encoding::UTF_8), '(execjs)')
rescue Exception => e
  raise wrap_error(e)
end

Instance Method Details

#call(identifier, *args) ⇒ Object



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

def call(identifier, *args)
  @ctx.exec_string("__execjs_duktape_call = #{identifier}", '(execjs)')
  @ctx.call_prop("__execjs_duktape_call", *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("(#{source.encode(Encoding::UTF_8)})", '(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(){#{source.encode(Encoding::UTF_8)}})()", '(execjs)')
rescue Exception => e
  raise wrap_error(e)
end