Class: WebkitRemote::Client::ConsoleMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/webkit_remote/client/console.rb

Overview

Data about an entry in the debugger console.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_message, client) ⇒ ConsoleMessage

@

Parameters:

  • the (Hash<String, Object>)

    raw JSON for a Message object in the Console domain, returned by a RPC call to a Webkit debugging server



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/webkit_remote/client/console.rb', line 93

def initialize(raw_message, client)
  @level = (raw_message['level'] || 'error').to_sym
  @source_line = raw_message['line'] ? raw_message['line'].to_i : nil
  if raw_message['networkRequestId']
    @network_resource =
      client.network_resource raw_message['networkRequestId']
  else
    @network_resource = nil
  end
  if raw_message['parameters']
    @params = raw_message['parameters'].map do |raw_object|
      WebkitRemote::Client::JsObject.for raw_object, client, nil
    end
  else
    @params = []
  end
  @params.freeze
  if raw_message['source']
    @reason = raw_message['source'].gsub('-', '_').to_sym
  else
    @reason = :other
  end
  @stack_trace = self.class.parse_stack_trace raw_message['stackTrace']
  @text = raw_message['text']
  @source_url = raw_message['url']
end

Instance Attribute Details

#levelSymbol (readonly)

The documented values are :debug, :error, :log, :tip, and :warning.

Returns:

  • (Symbol)

    message severity



64
65
66
# File 'lib/webkit_remote/client/console.rb', line 64

def level
  @level
end

#network_resourceWebkitRemote::Client::NetworkResource (readonly)

This is set for console messages that indicate network errors.

Returns:



76
77
78
# File 'lib/webkit_remote/client/console.rb', line 76

def network_resource
  @network_resource
end

#paramsArray<WebkitRemote::Client::JsObject> (readonly)

Returns extra arguments given to the message.

Returns:



59
60
61
# File 'lib/webkit_remote/client/console.rb', line 59

def params
  @params
end

#reasonSymbol (readonly)

The documented values are :console_api, :html, :javascript, :network,

:other, :wml, and :xml.

Returns:

  • (Symbol)

    the component that produced this message



70
71
72
# File 'lib/webkit_remote/client/console.rb', line 70

def reason
  @reason
end

#source_lineInteger (readonly)

Returns the line number of the statement that caused this message.

Returns:

  • (Integer)

    the line number of the statement that caused this message



82
83
84
# File 'lib/webkit_remote/client/console.rb', line 82

def source_line
  @source_line
end

#source_urlString (readonly)

Returns the URL of the file that caused this message.

Returns:

  • (String)

    the URL of the file that caused this message



79
80
81
# File 'lib/webkit_remote/client/console.rb', line 79

def source_url
  @source_url
end

#stack_traceArray<Hash<Symbol, Object>> (readonly)

Returns JavaScript stack trace to the statement that caused this message.

Returns:

  • (Array<Hash<Symbol, Object>>)

    JavaScript stack trace to the statement that caused this message



86
87
88
# File 'lib/webkit_remote/client/console.rb', line 86

def stack_trace
  @stack_trace
end

#textString (readonly)

Returns the message text.

Returns:

  • (String)

    the message text



55
56
57
# File 'lib/webkit_remote/client/console.rb', line 55

def text
  @text
end

Class Method Details

.parse_stack_trace(raw_stack_trace) ⇒ Array<Symbol, Object>

Parses a StackTrace object returned by a RPC request.

Parameters:

  • raw_stack_trace (Array<String, Object>)

    the raw StackTrace object in the Console domain returned by a RPC request

Returns:

  • (Array<Symbol, Object>)

    Ruby-friendly stack trace



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/webkit_remote/client/console.rb', line 134

def self.parse_stack_trace(raw_stack_trace)
  return nil unless raw_stack_trace

  raw_stack_trace.map do |raw_frame|
    frame = {}
    if raw_frame['columnNumber']
      frame[:column] = raw_frame['columnNumber'].to_i
    end
    if raw_frame['lineNumber']
      frame[:line] = raw_frame['lineNumber'].to_i
    end
    if raw_frame['functionName']
      frame[:function] = raw_frame['functionName']
    end
    if raw_frame['url']
      frame[:url] = raw_frame['url']
    end
    frame
  end
end

Instance Method Details

#release_paramsObject

Releases the JavaScript objects referenced by this message’s parameters.



121
122
123
124
125
126
127
# File 'lib/webkit_remote/client/console.rb', line 121

def release_params
  @params.each do |param|
    if param.kind_of?(WebkitRemote::Client::JsObject)
      param.release
    end
  end
end