Class: WebkitRemote::Client::JsObject
- Inherits:
-
Object
- Object
- WebkitRemote::Client::JsObject
- Defined in:
- lib/webkit_remote/client/runtime.rb,
lib/webkit_remote/client/dom_runtime.rb
Overview
Mirrors a JsObject, defined in the Runtime domain.
Instance Attribute Summary collapse
-
#client ⇒ WebkitRemote::Client
readonly
Remote debugging client for the browser tab that owns the objects in this group.
-
#description ⇒ String
readonly
String that would be displayed in the Webkit console to represent this object.
-
#group ⇒ WebkitRemote::Client::JsObjectGroup
readonly
The group that contains this object; the object can be released by calling release_all on the group.
-
#js_class_name ⇒ String
readonly
The class name computed by WebKit for this object.
-
#js_subtype ⇒ Symbol
readonly
An additional type hint for this object; documented values are :array, :date, :node, :null, :regexp.
-
#js_type ⇒ String
readonly
The return value of the JavaScript typeof operator.
-
#raw_data ⇒ Hash<String, Object>
readonly
The raw info provided by the remote debugger RPC call; might be useful for accessing extended metadata that is not (yet) recognized by WebkitRemote.
-
#released ⇒ Boolean
(also: #released?)
readonly
True if the objects in this group were already released.
-
#remote_id ⇒ String
readonly
Identifies this object in the remote debugger.
-
#value ⇒ Object
readonly
Primitive value for this object, if available.
Class Method Summary collapse
-
.for(raw_object, client, group_name) ⇒ WebkitRemote::Client::JsObject, ...
Wraps a raw object returned by the Webkit remote debugger RPC protocol.
-
.initializer(name) ⇒ Object
Registers a module initializer.
Instance Method Summary collapse
-
#bound_call(function_expression, *args) ⇒ WebkitRemote::Client::JsObject, ...
Calls a function with “this” bound to this object.
-
#dom_node ⇒ WebkitRemote::Client::DomNode
The DOM node wrapped by this JavaScript object.
-
#dom_node! ⇒ WebkitRemote::Client::DomNode
Fetches the wrapped DOM node, bypassing the object’s cache.
-
#initialize(raw_object, group) ⇒ JsObject
constructor
Wraps a remote JavaScript object.
- #initialize_dom ⇒ Object
-
#properties ⇒ Hash<String, Webkit::Client::JsProperty>
This object’s properties.
-
#properties! ⇒ Hash<Symbol, Webkit::Client::JsProperty>
This object’s properties, guaranteed to be fresh.
-
#release ⇒ Webkit::Client::JsObject
Releases this remote object on the browser side.
-
#released! ⇒ Object
Informs this object that it was released as part of a group release.
Constructor Details
#initialize(raw_object, group) ⇒ JsObject
Wraps a remote JavaScript object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/webkit_remote/client/runtime.rb', line 294 def initialize(raw_object, group) @group = group @client = group.client @released = false @raw_data = raw_object @remote_id = raw_object['objectId'] @js_class_name = raw_object['className'] @description = raw_object['description'] @js_type = raw_object['type'].to_sym if raw_object['subtype'] @js_subtype = raw_object['subtype'].to_sym else @js_subtype = nil end @value = raw_object['value'] group.add self initialize_modules end |
Instance Attribute Details
#client ⇒ WebkitRemote::Client (readonly)
Returns remote debugging client for the browser tab that owns the objects in this group.
172 173 174 |
# File 'lib/webkit_remote/client/runtime.rb', line 172 def client @client end |
#description ⇒ String (readonly)
Returns string that would be displayed in the Webkit console to represent this object.
156 157 158 |
# File 'lib/webkit_remote/client/runtime.rb', line 156 def description @description end |
#group ⇒ WebkitRemote::Client::JsObjectGroup (readonly)
Returns the group that contains this object; the object can be released by calling release_all on the group.
177 178 179 |
# File 'lib/webkit_remote/client/runtime.rb', line 177 def group @group end |
#js_class_name ⇒ String (readonly)
Returns the class name computed by WebKit for this object.
145 146 147 |
# File 'lib/webkit_remote/client/runtime.rb', line 145 def js_class_name @js_class_name end |
#js_subtype ⇒ Symbol (readonly)
Returns an additional type hint for this object; documented values are :array, :date, :node, :null, :regexp.
152 153 154 |
# File 'lib/webkit_remote/client/runtime.rb', line 152 def js_subtype @js_subtype end |
#js_type ⇒ String (readonly)
Returns the return value of the JavaScript typeof operator.
148 149 150 |
# File 'lib/webkit_remote/client/runtime.rb', line 148 def js_type @js_type end |
#raw_data ⇒ Hash<String, Object> (readonly)
Returns the raw info provided by the remote debugger RPC call; might be useful for accessing extended metadata that is not (yet) recognized by WebkitRemote.
164 165 166 |
# File 'lib/webkit_remote/client/runtime.rb', line 164 def raw_data @raw_data end |
#released ⇒ Boolean (readonly) Also known as: released?
Returns true if the objects in this group were already released.
167 168 169 |
# File 'lib/webkit_remote/client/runtime.rb', line 167 def released @released end |
#remote_id ⇒ String (readonly)
Returns identifies this object in the remote debugger.
181 182 183 |
# File 'lib/webkit_remote/client/runtime.rb', line 181 def remote_id @remote_id end |
#value ⇒ Object (readonly)
Returns primitive value for this object, if available.
159 160 161 |
# File 'lib/webkit_remote/client/runtime.rb', line 159 def value @value end |
Class Method Details
.for(raw_object, client, group_name) ⇒ WebkitRemote::Client::JsObject, ...
Wraps a raw object returned by the Webkit remote debugger RPC protocol.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/webkit_remote/client/runtime.rb', line 267 def self.for(raw_object, client, group_name) if remote_id = raw_object['objectId'] group = client.object_group group_name, true return group.get(remote_id) || WebkitRemote::Client::JsObject.new(raw_object, group) else # primitive types case raw_object['type'] ? raw_object['type'].to_sym : nil when :boolean, :number, :string return raw_object['value'] when :undefined return WebkitRemote::Client::Undefined when :object case raw_object['subtype'] ? raw_object['subtype'].to_sym : nil when :null return nil end # TODO(pwnall): Any other exceptions? end end raise RuntimeError, "Unable to parse #{raw_object.inspect}" end |
.initializer(name) ⇒ Object
Registers a module initializer.
321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/webkit_remote/client/runtime.rb', line 321 def self.initializer(name) before_name = :"initialize_modules_before_#{name}" alias_method before_name, :initialize_modules private before_name remove_method :initialize_modules eval <<END_METHOD def initialize_modules #{name} #{before_name.to_s} end END_METHOD private :initialize_modules end |
Instance Method Details
#bound_call(function_expression, *args) ⇒ WebkitRemote::Client::JsObject, ...
Calls a function with “this” bound to this object.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/webkit_remote/client/runtime.rb', line 230 def bound_call(function_expression, *args) call_args = args.map do |arg| if arg.kind_of? WebkitRemote::Client::JsObject { objectId: arg.remote_id } else { value: arg } end end result = @client.rpc.call 'Runtime.callFunctionOn', objectId: @remote_id, functionDeclaration: function_expression, arguments: call_args, returnByValue: false object = WebkitRemote::Client::JsObject.for result['result'], @client, @group.name if result['wasThrown'] # TODO(pwnall): some wrapper for exceptions? object else object end end |
#dom_node ⇒ WebkitRemote::Client::DomNode
Returns the DOM node wrapped by this JavaScript object.
8 9 10 |
# File 'lib/webkit_remote/client/dom_runtime.rb', line 8 def dom_node @dom_node ||= dom_node! end |
#dom_node! ⇒ WebkitRemote::Client::DomNode
Fetches the wrapped DOM node, bypassing the object’s cache.
16 17 18 19 20 21 22 23 |
# File 'lib/webkit_remote/client/dom_runtime.rb', line 16 def dom_node! result = @client.rpc.call 'DOM.requestNode', objectId: @remote_id @dom_node = if result['nodeId'] @client.dom_node result['nodeId'] else nil end end |
#initialize_dom ⇒ Object
26 27 28 |
# File 'lib/webkit_remote/client/dom_runtime.rb', line 26 def initialize_dom @dom_node = nil end |
#properties ⇒ Hash<String, Webkit::Client::JsProperty>
This object’s properties.
If the object’s properties have not been retrieved, this method retrieves them via a RPC call.
200 201 202 |
# File 'lib/webkit_remote/client/runtime.rb', line 200 def properties @properties || properties! end |
#properties! ⇒ Hash<Symbol, Webkit::Client::JsProperty>
This object’s properties, guaranteed to be fresh.
This method always reloads the object’s properties via a RPC call.
210 211 212 213 214 215 216 217 218 |
# File 'lib/webkit_remote/client/runtime.rb', line 210 def properties! result = @client.rpc.call 'Runtime.getProperties', objectId: @remote_id @properties = Hash[ result['result'].map do |raw_property| property = WebkitRemote::Client::JsProperty.new raw_property, self [property.name, property] end ].freeze end |
#release ⇒ Webkit::Client::JsObject
Releases this remote object on the browser side.
186 187 188 189 190 191 |
# File 'lib/webkit_remote/client/runtime.rb', line 186 def release return if @released @client.rpc.call 'Runtime.releaseObject', objectId: @remote_id @group.remove self released! end |
#released! ⇒ Object
Informs this object that it was released as part of a group release.
338 339 340 341 |
# File 'lib/webkit_remote/client/runtime.rb', line 338 def released! @released = true @group = nil end |