Sha256: 7faa713f08863e4ba8392aed5f7a9f241465f31f7c1e95f196dc7d1da4aac0ef
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
require 'tempfile' require 'securerandom' require 'greenletters' module BooJS def self.verify str phantom = Phantomjs.path #Create tmp file tmp = Tempfile.new(SecureRandom.hex) tmp.puts %{ phantom.onError = function(msg, trace) { console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); console.log("PhantomJS Error"); console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); console.log(msg); trace.forEach(function(t) { console.log(t.file + ': line ' + t.line ); }) console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); phantom.exit(1); } } tmp.puts str tmp.puts "phantom.exit(0)" tmp.close system("phantomjs #{tmp.path} 2>&1") or raise "Verifying failed" end #Optionally, accept code to inject def self.pipe(str=nil) js = %{ var system = require('system'); function __spec_ping(str) { system.stdout.writeLine("pong"+str) } phantom.onError = function(msg, trace) { system.stderr.writeLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); system.stderr.writeLine("PhantomJS Error"); system.stderr.writeLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); system.stderr.writeLine(msg); trace.forEach(function(t) { system.stderr.writeLine(t.file + ': line ' + t.line ); }) system.stderr.writeLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); phantom.exit(1); } while (true) { var line = system.stdin.readLine(); eval(line); } } if str js += "\n#{str}" end phantom = Phantomjs.path tmp = Tempfile.new(SecureRandom.hex) tmp.puts js tmp.close exit system("#{phantom} #{tmp.path}") end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
boojs-0.0.7 | lib/boojs.rb |