Module: Csso::CallJS

Included in:
Loader, Optimizer
Defined in:
lib/csso/utils.rb

Overview

Utility for calling into the JavaScript runtime.

Instance Method Summary collapse

Instance Method Details

#calljs(err_cls = WrappedError) { ... } ⇒ Object

Wrap JavaScript invocations with uniform error handling

Yields:

  • code to wrap



9
10
11
12
13
14
15
# File 'lib/csso/utils.rb', line 9

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

#lock { ... } ⇒ Object

Ensure proper locking before entering the V8 API

Yields:

  • code to wrap in lock



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/csso/utils.rb', line 21

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