Sha256: b310924b6a437eadef0a9c40d97b4a6b55ac7e24a91f83f90bb2b5401f442b2f
Contents?: true
Size: 1.58 KB
Versions: 13
Compression:
Stored size: 1.58 KB
Contents
require "execjs/runtime" require "json" module ExecJS class DuktapeRuntime < Runtime class Context < Runtime::Context def initialize(runtime, source = "") @ctx = Duktape::Context.new(complex_object: nil) @ctx.exec_string(encode(source), '(execjs)') rescue Exception => e raise wrap_error(e) end def exec(source, options = {}) return unless /\S/ =~ source @ctx.eval_string("(function(){#{encode(source)}})()", '(execjs)') rescue Exception => e raise wrap_error(e) end def eval(source, options = {}) return unless /\S/ =~ source @ctx.eval_string("(#{encode(source)})", '(execjs)') rescue Exception => e raise wrap_error(e) end def call(identifier, *args) @ctx.call_prop(identifier.split("."), *args) rescue Exception => e raise wrap_error(e) end private def wrap_error(e) klass = case e when Duktape::SyntaxError RuntimeError when Duktape::Error ProgramError when Duktape::InternalError RuntimeError end if klass re = / \(line (\d+)\)$/ lineno = e.message[re, 1] || 1 error = klass.new(e.message.sub(re, "")) error.set_backtrace(["(execjs):#{lineno}"] + e.backtrace) error else e end end end def name "Duktape" end def available? require "duktape" true rescue LoadError false end end end
Version data entries
13 entries across 13 versions & 6 rubygems