Class: WebkitRemote::Client::JsObjectGroup

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

Overview

Tracks the remote objects in a group (think memory pool).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, client) ⇒ JsObjectGroup

Creates a wrapper for a group of remote objects.

Parameters:

  • name (String)

    name of this group of remote objects

  • client (WebkitRemote::Client)

    remote debugging client for the browser tab that owns the objects in this group



368
369
370
371
372
373
374
# File 'lib/webkit_remote/client/runtime.rb', line 368

def initialize(name, client)
  @name = name
  @client = client
  # TODO(pwnall): turn @objects into a set once equality is working
  @objects = {}
  @released = false
end

Instance Attribute Details

#clientWebkitRemote::Client (readonly)

Returns remote debugging client for the browser tab that owns the objects in this group.

Returns:

  • (WebkitRemote::Client)

    remote debugging client for the browser tab that owns the objects in this group



323
324
325
# File 'lib/webkit_remote/client/runtime.rb', line 323

def client
  @client
end

#nameString (readonly)

Returns the name of the group of remote objects.

Returns:

  • (String)

    the name of the group of remote objects



319
320
321
# File 'lib/webkit_remote/client/runtime.rb', line 319

def name
  @name
end

#releasedBoolean (readonly) Also known as: released?

Returns true if the objects in this group were already released.

Returns:

  • (Boolean)

    true if the objects in this group were already released



326
327
328
# File 'lib/webkit_remote/client/runtime.rb', line 326

def released
  @released
end

Instance Method Details

#add(object) ⇒ WebkitRemote::Client::JsObjectGroup

Registers a remote object that belongs to this group.

Parameters:

Returns:



384
385
386
387
388
389
390
# File 'lib/webkit_remote/client/runtime.rb', line 384

def add(object)
  if @released
    raise RuntimeError, 'Remote object group already released'
  end
  @objects[object.remote_id] = object
  self
end

#get(remote_id) ⇒ WebkitRemote::Client::JsObject?

Returns the object in this group with a given id.

This helps avoid creating multiple wrappers for the same object.

Parameters:

  • remote_id (String)

    the id to look for

Returns:



416
417
418
# File 'lib/webkit_remote/client/runtime.rb', line 416

def get(remote_id)
  @objects.fetch remote_id, nil
end

#include?(object) ⇒ Boolean

Checks if a remote object was allocated in this group.

Parameters:

Returns:

  • (Boolean)

    true if the object belongs to this group, so releasing the group would get the object released



356
357
358
# File 'lib/webkit_remote/client/runtime.rb', line 356

def include?(object)
  @objects[object.remote_id] == object
end

#release_allWebkit::Client::JsObjectGroup

Releases all the remote objects in this group.

Returns:

  • (Webkit::Client::JsObjectGroup)

    self



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/webkit_remote/client/runtime.rb', line 332

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

#remove(object) ⇒ WebkitRemote::Client::JsObjectGroup

Removes a remote object that was individually released.

Parameters:

Returns:



400
401
402
403
404
405
406
407
# File 'lib/webkit_remote/client/runtime.rb', line 400

def remove(object)
  @objects.delete object.remote_id
  if @objects.empty?
    @released = true
    @client.object_group_remove self
  end
  self
end