Sha256: 8e987a63e5037d3c901194c6f81fde131f48d40f02ec410481072e1bbff2bf8f
Contents?: true
Size: 1.81 KB
Versions: 6
Compression:
Stored size: 1.81 KB
Contents
require 'sqreen/exception' module Sqreen module Js # start public interface class JsService include Singleton def initialize detect_adapter end # @return [Sqreen::Js::ExecutableJs] def prepare(rule_name, code) raise 'Not online' unless online? @adapter.preprocess(rule_name, code) end def online? @online end def variant @adapter.variant_name end private def detect_adapter @online = try_sq_mini_racer || try_rhino Sqreen.log.info "JS engine online: #{variant}" if @online end def try_sq_mini_racer gem = Gem.loaded_specs['sq_mini_racer'] unless gem Sqreen.log.info "sq_mini_racer gem not detected" return false end require 'sqreen/mini_racer' require 'sqreen/js/mini_racer_adapter' @adapter = MiniRacerAdapter.new(true) rescue LoadError => e Sqreen.log.warn "Failed loading sq_mini_racer: #{e}" false end def try_rhino gem = Gem.loaded_specs['therubyrhino'] unless gem Sqreen.log.info "therubyrhino gem not detected" return false end require 'rhino' require 'sqreen/js/execjs_adapter' @adapter = ExecjsAdapter.new rescue LoadError => e Sqreen.log.warn "Failed loading rhino: #{e}" false end end CallContext = Struct.new(:inst, :args, :rv) class ExecutableJs def run_js_cb(_cb_name, _budget, _arguments) raise Sqreen::NotImplementedYet end end # end public interface class JsServiceAdapter def preprocess(code) raise Sqreen::NotImplementedYet end def variant_name 'unspecified' end end end end
Version data entries
6 entries across 6 versions & 1 rubygems