Class: MozreplClient

Inherits:
Object
  • Object
show all
Defined in:
lib/mozrepl_client.rb

Class Method Summary collapse

Class Method Details

.read(s) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/mozrepl_client.rb', line 4

def self.read s
  r = ''
  loop do
   r << s.readchar.chr

   break if r =~ /^repl\d*> $/
  end
  r.sub /^repl\d*> /, ''
end

.run(js, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mozrepl_client.rb', line 14

def self.run js, options={}
  s = TCPSocket::new("localhost", "4242")

  initial_crap = self.read s
  repl = initial_crap[/repl\d+/] || 'repl'
  if options[:tab]   # Run js in page on nth tab
    s.puts("#{repl}.enter(window.gBrowser.getBrowserAtIndex(#{options[:tab]}).contentDocument)\n;")
    self.read s
  elsif options[:browser]   # Run js at browser outer level
  else   # Run js in page
    s.puts("#{repl}.enter(content.wrappedJSObject)\n;")
    self.read s
  end

  s.puts js
  txt = self.read s
  s.close
  txt.strip
end