Class: ExecJS::Xtrn::Ole

Inherits:
Wsh show all
Defined in:
lib/execjs/xtrn/ole.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

Valid =
valid?

Constants inherited from Wsh

Wsh::ES5, Wsh::Run

Constants inherited from Engine

Engine::Error, Engine::PathX, Engine::Run

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Engine

#call, compile, #eval, eval, exec, #load, load, stats, #stats

Class Method Details

.valid?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
# File 'lib/execjs/xtrn/ole.rb', line 12

def self.valid?
  return unless Gem.win_platform?
  require 'win32ole'
  WIN32OLE.codepage = WIN32OLE::CP_UTF8
  WIN32OLE.new 'ScriptControl'
  true
rescue
  false
end

Instance Method Details

#exec(code) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/execjs/xtrn/ole.rb', line 24

def exec code
  return if (code=code.to_s.strip).length==0
  result = nil
  delta={
    n: 1, # calls

    o: 0, # out bytes

    i: 0, # in bytes

    t: Time.now # time spent

  }
  begin
    result = parse vm.eval "new Function(#{JSON.dump code})()"
  rescue WIN32OLERuntimeError=>e
    raise Error.new e
  ensure
    delta[:t]=Time.now-delta[:t]
    delta[:o]=code.length
    delta[:i]=JSON.dump(result).length if result
    @statz.each{|var| delta.each{|k, v| var[k]||=0; var[k]+=v}}
  end
end