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



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/webkit_remote/client/console.rb', line 107

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
  @count = raw_message['repeatCount'] ? raw_message['repeatCount'].to_i : 1
  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']
  @type = raw_message['type'] ? raw_message['type'].to_sym : nil
  @source_url = raw_message['url']
end

Instance Attribute Details

#countInteger

Returns how many times this message was repeated.

Returns:

  • (Integer)

    how many times this message was repeated



72
73
74
# File 'lib/webkit_remote/client/console.rb', line 72

def count
  @count
end

#levelSymbol (readonly)

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

Returns:

  • (Symbol)

    message severity



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

def level
  @level
end

#network_resourceWebkitRemote::Client::NetworkResource (readonly)

This is set for console messages that indicate network errors.

Returns:



84
85
86
# File 'lib/webkit_remote/client/console.rb', line 84

def network_resource
  @network_resource
end

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

Returns extra arguments given to the message.

Returns:



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

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



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

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



96
97
98
# File 'lib/webkit_remote/client/console.rb', line 96

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



93
94
95
# File 'lib/webkit_remote/client/console.rb', line 93

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



100
101
102
# File 'lib/webkit_remote/client/console.rb', line 100

def stack_trace
  @stack_trace
end

#textString (readonly)

Returns the message text.

Returns:

  • (String)

    the message text



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

def text
  @text
end

#typeSymbol (readonly)

The documented values are :assert, :dir, :dirxml, :endGroup, :log,

:startGroup, :startGroupCollapsed, and :trace.

Returns:

  • (Symbol)

    the behavior that produced this message



90
91
92
# File 'lib/webkit_remote/client/console.rb', line 90

def type
  @type
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



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/webkit_remote/client/console.rb', line 150

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.



137
138
139
140
141
142
143
# File 'lib/webkit_remote/client/console.rb', line 137

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