Class: MozreplSocket

Inherits:
FirefoxSocket show all
Defined in:
lib/vapir-firefox/firefox_socket/mozrepl.rb

Overview

A MozreplSocket represents a connection to Firefox over a socket opened to the MozRepl extension.

Constant Summary

Constants inherited from FirefoxSocket

FirefoxSocket::PrototypeFile

Instance Attribute Summary

Attributes inherited from FirefoxSocket

#temp_object

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FirefoxSocket

#Components, #assert_socket, #assign, #assign_json, #call, #call_function, #call_json, #configuration_parent, #function, #handle, #handle_json, #handling_connection_error, #host, #initialize, #inspect, #instanceof, #object, #object_in_temp, #parse_json, #port, #root, to_javascript, #typeof, #value, #value_json

Constructor Details

This class inherits a constructor from FirefoxSocket

Class Method Details

.command_line_flags(options = {}) ⇒ Object

returns an array of command line flags that should be used to invoke firefox for mozrepl



11
12
13
14
# File 'lib/vapir-firefox/firefox_socket/mozrepl.rb', line 11

def self.command_line_flags(options={})
  options = config.defined_hash.merge(options)
  ['-repl', options['port']]
end

Instance Method Details

#eat_welcome_messageObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vapir-firefox/firefox_socket/mozrepl.rb', line 16

def eat_welcome_message
  read=read_value
  if !read
    @expecting_extra_maybe=true
    raise FirefoxSocketUnableToStart, "Something went wrong initializing - no response" 
  elsif read !~ /Welcome to MozRepl/
    @expecting_extra_maybe=true
    raise FirefoxSocketUnableToStart, "Something went wrong initializing - message #{read.inspect}"
  end
  if read =~ /yours will be named "([^"]+)"/
    @replname=$1
  else
    @replname='repl'
  end
  @prompt="#{@replname}> "
  @expecting_prompt = read !~ /#{Regexp.escape(@prompt)}\z/
end

#initialize_environmentObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vapir-firefox/firefox_socket/mozrepl.rb', line 33

def initialize_environment
  # change the prompt mode to something less decorative 
  #send_and_read("#{@replname}.home()")
  send_and_read("#{@replname}.setenv('printPrompt', false)")
  @prompt="\n"
  @expecting_prompt=false
  send_and_read("#{@replname}.setenv('inputMode', 'multiline')")
  @input_terminator = "--end-remote-input\n"

  # set up objects that are needed: nativeJSON_encode_length, VapirTemp, and Vapir
  ret=send_and_read(%Q((function(the_repl, context)
  { context.nativeJSON_encode_length=function(object)
    { var encoded=JSON.stringify(object);
      the_repl.print(encoded.length.toString()+"\\n"+encoded, false);
    }
    context.VapirTemp = {};
    context.Vapir = {};
    return 'done!';
  })(#{@replname}, this)))
  if ret !~ /done!/
    @expecting_extra_maybe=true
    raise FirefoxSocketError, "Something went wrong initializing environment - message #{ret.inspect}"
  end
end