Module: Less::CallJS

Included in:
Loader, Parser, Tree
Defined in:
lib/less/parser.rb

Overview

Utility for calling into the JavaScript runtime.

Instance Method Summary collapse

Instance Method Details

#calljs { ... } ⇒ Object

Wrap JavaScript invocations with uniform error handling

Yields:

  • code to wrap


11
12
13
14
15
16
17
# File 'lib/less/parser.rb', line 11

def calljs
  lock do
    yield
  end
rescue V8::JSError => e
  raise ParseError.new(e)
end

#lock { ... } ⇒ Object

Ensure proper locking before entering the V8 API

Yields:

  • code to wrap in lock


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/less/parser.rb', line 23

def lock
  result, exception = nil, nil
  V8::C::Locker() do
    begin
      result = yield
    rescue Exception => e
      exception = e
    end
  end
  if exception
    raise exception
  else
    result
  end
end