class WebkitRemote::Client::JsObject
Attributes
@return [WebkitRemote::Client] remote debugging client for the browser tab
that owns the objects in this group
@return [String] string that would be displayed in the Webkit console to
represent this object
@return [WebkitRemote::Client::JsObjectGroup] the group that contains
this object; the object can be released by calling release_all on the group
@return [String] the class name computed by WebKit for this object
@return [Symbol] an additional type hint for this object; documented values
are :array, :date, :node, :null, :regexp
@return [String] the return value of the JavaScript typeof operator
@return [Hash<String, Object>] the raw info provided by the remote debugger
RPC call; might be useful for accessing extended metadata that is not (yet) recognized by WebkitRemote
@return [Boolean] true if the objects in this group were already released
@return [Boolean] true if the objects in this group were already released
@return [String] identifies this object in the remote debugger @private Use the JsObject
methods instead of calling this directly.
@return [Object] primitive value for this object, if available
Public Class Methods
Wraps a raw object returned by the Webkit remote debugger RPC protocol.
@private Use WebkitRemote::Client::Runtime#remote_eval
instead of calling
this directly.
@param [Hash<String, Object>] raw_object a JsObject
instance, according
to the Webkit remote debugging protocol; this is the return value of a 'Runtime.evaluate' RPC call
@param [WebkitRemote::Client::Runtime] client remote debugging client for
the browser tab that owns this object
@param [String] group_name name of the object group that will hold this
object; object groups work like memory pools
@return [WebkitRemote::Client::JsObject, Boolean, Number, String] a
Ruby wrapper for the given raw object; primitives get wrapped by standard Ruby classes, and objects get wrapped by JsObject instances
# File lib/webkit_remote/client/runtime.rb, line 263 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
Registers a module initializer.
# File lib/webkit_remote/client/runtime.rb, line 317 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
Wraps a remote JavaScript object
@private JsObject#for should be used instead of this, as it handles
some edge cases
# File lib/webkit_remote/client/runtime.rb, line 290 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
Public Instance Methods
Calls a function with “this” bound to this object.
@param [String] function_expression a JavaScript expression that should
evaluate to a function
@param [Array<WebkitRemote::Client::Object, String, Number, Boolean, nil>]
args the arguments passed to the function
@return [WebkitRemote::Client::JsObject, Boolean, Number, String, nil]
a Ruby wrapper for the given raw object; primitives get wrapped by standard Ruby classes, and objects get wrapped by JsObject instances
# File lib/webkit_remote/client/runtime.rb, line 226 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
@return [WebkitRemote::Client::DomNode] the DOM node wrapped by this
JavaScript object
# File lib/webkit_remote/client/dom_runtime.rb, line 8 def dom_node @dom_node ||= dom_node! end
Fetches the wrapped DOM node, bypassing the object's cache.
@return [WebkitRemote::Client::DomNode] the DOM domain object wrapped by
this JavaScript object
# 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
@private Called by the JsObject
constructor.
# File lib/webkit_remote/client/dom_runtime.rb, line 26 def initialize_dom @dom_node = nil end
This object's properties.
If the object's properties have not been retrieved, this method retrieves them via a RPC call.
@return [Hash<String, Webkit::Client::JsProperty>] frozen Hash containg
the object's properties
# File lib/webkit_remote/client/runtime.rb, line 196 def properties @properties || properties! end
This object's properties, guaranteed to be fresh.
This method always reloads the object's properties via a RPC call.
@return [Hash<Symbol, Webkit::Client::JsProperty>] frozen Hash containg
the object's properties
# File lib/webkit_remote/client/runtime.rb, line 206 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
Releases this remote object on the browser side.
@return [Webkit::Client::JsObject] self
# File lib/webkit_remote/client/runtime.rb, line 182 def release return if @released @client.rpc.call 'Runtime.releaseObject', objectId: @remote_id @group.remove self released! end
Informs this object that it was released as part of a group release.
@private Called by JsObjectGroup#release_all
.
# File lib/webkit_remote/client/runtime.rb, line 334 def released! @released = true @group = nil end
Private Instance Methods
# File lib/webkit_remote/client/runtime.rb, line 312 def initialize_modules end