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



396
397
398
399
400
401
402
# File 'lib/webkit_remote/client/runtime.rb', line 396

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



351
352
353
# File 'lib/webkit_remote/client/runtime.rb', line 351

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



347
348
349
# File 'lib/webkit_remote/client/runtime.rb', line 347

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



354
355
356
# File 'lib/webkit_remote/client/runtime.rb', line 354

def released
  @released
end

Instance Method Details

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

Registers a remote object that belongs to this group.

Parameters:

Returns:



412
413
414
415
416
417
418
# File 'lib/webkit_remote/client/runtime.rb', line 412

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:



444
445
446
# File 'lib/webkit_remote/client/runtime.rb', line 444

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



384
385
386
# File 'lib/webkit_remote/client/runtime.rb', line 384

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



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/webkit_remote/client/runtime.rb', line 360

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:



428
429
430
431
432
433
434
435
# File 'lib/webkit_remote/client/runtime.rb', line 428

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