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



392
393
394
395
396
397
398
# 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

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



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

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



343
344
345
# File 'lib/webkit_remote/client/runtime.rb', line 343

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



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

def released
  @released
end

Instance Method Details

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

Registers a remote object that belongs to this group.

Parameters:

Returns:



408
409
410
411
412
413
414
# 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

#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:



440
441
442
# File 'lib/webkit_remote/client/runtime.rb', line 440

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



380
381
382
# File 'lib/webkit_remote/client/runtime.rb', line 380

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



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# 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

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

Removes a remote object that was individually released.

Parameters:

Returns:



424
425
426
427
428
429
430
431
# 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