class WebkitRemote::Client::JsObjectGroup
Tracks the remote objects in a group (think memory pool).
Attributes
@return [WebkitRemote::Client] remote debugging client for the browser tab
that owns the objects in this group
@return [String] the name of the group of remote objects
@return [Boolean] true if the objects in this group were already released
@return [Boolean] true if the objects in this group were already released
Public Class Methods
Creates a wrapper for a group of remote objects.
@private Use WebkitRemote::Client::Runtime#remote_eval
instead of calling
this directly.
@param [String] name name of this group of remote objects @param [WebkitRemote::Client] client remote debugging client for the
browser tab that owns the objects in this group
# File lib/webkit_remote/client/runtime.rb, line 392 def initialize(name, client) @name = name @client = client # TODO(pwnall): turn @objects into a set once equality is working @objects = {} @released = false end
Public Instance Methods
Registers a remote object that belongs to this group.
@private Use WebkitRemote::Client::Runtime#remote_eval
instead of calling
this directly.
@param [WebkitRemote::Client::JsObject] object the object to be added
to this group
@return [WebkitRemote::Client::JsObjectGroup] self
# File lib/webkit_remote/client/runtime.rb, line 408 def add(object) if @released raise RuntimeError, 'Remote object group already released' end @objects[object.remote_id] = object self end
Returns the object in this group with a given id.
This helps avoid creating multiple wrappers for the same object.
@param [String] remote_id the id to look for @return [WebkitRemote::Client::JsObject, nil] nil if there is no object
whose remote_id matches the method's parameter
# File lib/webkit_remote/client/runtime.rb, line 440 def get(remote_id) @objects.fetch remote_id, nil end
Checks if a remote object was allocated in this group.
@param [WebkitRemote::Client] object @return [Boolean] true if the object belongs to this group, so releasing
the group would get the object released
# File lib/webkit_remote/client/runtime.rb, line 380 def include?(object) @objects[object.remote_id] == object end
Releases all the remote objects in this group.
@return [Webkit::Client::JsObjectGroup] self
# File lib/webkit_remote/client/runtime.rb, line 356 def release_all return if @objects.empty? if @name == nil # This is the special group that contains un-grouped objects. @objects.values.each do |object| object.release end else @client.rpc.call 'Runtime.releaseObjectGroup', objectGroup: name end @released = true @objects.each_value { |object| object.released! } @objects.clear @client.object_group_remove self self end
Removes a remote object that was individually released.
@private Use WebkitRemote::Client::JsObject#release
instead of calling
this directly
@param [WebkitRemote::Client::JsObject] object the object that will be
removed from the group
@return [WebkitRemote::Client::JsObjectGroup] self
# File lib/webkit_remote/client/runtime.rb, line 424 def remove(object) @objects.delete object.remote_id if @objects.empty? @released = true @client.object_group_remove self end self end