class ExecJS::Xtrn::Ole
Constants
- Json2
- Language
- Valid
Public Class Methods
valid?()
click to toggle source
# 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
Public Instance Methods
exec(code)
click to toggle source
# 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
Private Instance Methods
json()
click to toggle source
# File lib/execjs/xtrn/ole.rb, line 64 def json return @@json if @@json j = WIN32OLE.new 'ScriptControl' j.Language = 'JScript' j.addCode File.read Json2 j.addCode <<-EOJ function jsonDump(o) { return JSON.stringify(o) } EOJ @@json = j end
parse(result)
click to toggle source
# File lib/execjs/xtrn/ole.rb, line 78 def parse result WIN32OLE===result ? JSON.parse(json.run 'jsonDump', result) : result end
vm()
click to toggle source
# File lib/execjs/xtrn/ole.rb, line 49 def vm return @vm if @vm @statz = [ @stats||={}, self.class.class_stats, ExecJS::Xtrn::Engine.class_stats(0) ] vm = WIN32OLE.new 'ScriptControl' vm.Language = 'JScript' vm.addCode File.read ES5 @vm = vm end