class Less::JavaScript::NashornContext

Public Class Methods

instance() click to toggle source
# File lib/nashorn/rhino/less.rb, line 14
def self.instance
  return new # NOTE: for Rhino a context should be kept open per thread !
end
new(globals = nil) click to toggle source
# File lib/nashorn/rhino/less.rb, line 18
def initialize(globals = nil)
  @context = Nashorn::Context.new :java => true
  #if @context.respond_to?(:version)
  #  @context.version = '1.8'
  #  apply_1_8_compatibility! if @context.version.to_s != '1.8'
  #else
  #  apply_1_8_compatibility!
  #end
  globals.each { |key, val| @context[key] = val } if globals
end

Public Instance Methods

call(properties, *args) click to toggle source
# File lib/nashorn/rhino/less.rb, line 46
def call(properties, *args)
  args.last.is_a?(::Hash) ? args.pop : {} # extract_option!
  @context.eval(properties).call(*args)
rescue Nashorn::JSError => e
  handle_js_error(e)
end
eval(source, options = nil) click to toggle source
# File lib/nashorn/rhino/less.rb, line 39
def eval(source, options = nil)
  source = source.encode('UTF-8') if source.respond_to?(:encode)
  @context.eval("(#{source})")
rescue Nashorn::JSError => e
  handle_js_error(e)
end
exec(&block) click to toggle source
# File lib/nashorn/rhino/less.rb, line 33
def exec(&block)
  @context.open(&block)
rescue Nashorn::JSError => e
  handle_js_error(e)
end
method_missing(symbol, *args) click to toggle source
Calls superclass method
# File lib/nashorn/rhino/less.rb, line 53
def method_missing(symbol, *args)
  if @context.respond_to?(symbol)
    @context.send(symbol, *args)
  else
    super
  end
end
unwrap() click to toggle source
# File lib/nashorn/rhino/less.rb, line 29
def unwrap
  @context
end

Private Instance Methods

handle_js_error(e) click to toggle source
# File lib/nashorn/rhino/less.rb, line 63
def handle_js_error(e)
  #if e.value && ( e.value['message'] || e.value['type'].is_a?(String) )
  #  raise Less::ParseError.new(e, e.value) # LessError
  #end
  raise Less::ParseError.new(e) if ::Nashorn::JSError.parse_error?(e.cause)

  msg = e.value.to_s
  raise Less::ParseError.new(msg) if msg.start_with?("missing opening `(`")
  #if e.message && e.message[0, 12] == "Syntax Error"
  #  raise Less::ParseError.new(e)
  #end
  raise Less::Error.new(e)
end