Class: ExecJS::DuktapeRuntime::Context
- Inherits:
-
Runtime::Context
- Object
- Runtime::Context
- ExecJS::DuktapeRuntime::Context
- Defined in:
- lib/execjs/duktape_runtime.rb
Instance Method Summary collapse
- #call(identifier, *args) ⇒ Object
- #eval(source, options = {}) ⇒ Object
- #exec(source, options = {}) ⇒ Object
-
#initialize(runtime, source = "", options = {}) ⇒ Context
constructor
A new instance of Context.
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 = "", = {}) @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, = {}) 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, = {}) return unless /\S/ =~ source @ctx.eval_string("(function(){#{source.encode(Encoding::UTF_8)}})()", '(execjs)') rescue Exception => e raise wrap_error(e) end |