Module: WebkitRemote::Client::Runtime

Included in:
WebkitRemote::Client
Defined in:
lib/webkit_remote/client/runtime.rb

Overview

API for the Runtime domain.

Instance Method Summary collapse

Instance Method Details

#clear_runtimeWebkitRemote::Client

Releases all the objects allocated to this runtime.

Returns:



81
82
83
84
85
86
# File 'lib/webkit_remote/client/runtime.rb', line 81

def clear_runtime
  @runtime_groups.each do |name, group|
    group.release_all
  end
  self
end

#initialize_runtimeObject



74
75
76
# File 'lib/webkit_remote/client/runtime.rb', line 74

def initialize_runtime()
  @runtime_groups = {}
end

#object_group(group_name, create = false) ⇒ WebkitRemote::Client::JsObject, ...

Retrieves a group of remote objects by its name.

Parameters:

  • group_name (String, Symbol)

    name given to remote_eval when the object was created; nil obtains the anonymous group containing the un-grouped objects created by Console#MessageReceived

  • create (Boolean) (defaults to: false)

    if true, fetching a group that does not exist will create the group; this parameter should only be used internally

Returns:

  • (WebkitRemote::Client::JsObject, Boolean, Number, String, nil)

    a Ruby wrapper for the evaluation result; primitives get wrapped by standard Ruby classes, and objects get wrapped by JsObject instances



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/webkit_remote/client/runtime.rb', line 42

def object_group(group_name, create = false)
  group_name = group_name.nil? ? nil : group_name.to_s
  group = @runtime_groups[group_name]
  return group if group
  if create
    @runtime_groups[group_name] =
        WebkitRemote::Client::JsObjectGroup.new(group_name, self)
  else
    nil
  end
end

#object_group_auto_nameString

Generates a temporary group name for JavaScript objects.

This is useful when the API user does not

Returns:

  • (String)

    an automatically-generated JS object name



59
60
61
# File 'lib/webkit_remote/client/runtime.rb', line 59

def object_group_auto_name
  '_'
end

#object_group_remove(group) ⇒ WebkitRemote::Client

Removes a group from the list of tracked groups.

Returns:



68
69
70
71
# File 'lib/webkit_remote/client/runtime.rb', line 68

def object_group_remove(group)
  @runtime_groups.delete group.name
  self
end

#remote_eval(expression, opts = {}) ⇒ WebkitRemote::Client::JsObject, ...

Evals a JavaScript expression.

Parameters:

  • expression (String)

    the JavaScript expression to be evaluated

  • opts (Hash) (defaults to: {})

    tweaks

Options Hash (opts):

  • group (String, Symbol)

    the name of an object group (think memory pools); the objects in a group can be released together by one call to WebkitRemote::Client::JsObjectGroup#release

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/webkit_remote/client/runtime.rb', line 16

def remote_eval(expression, opts = {})
  group_name = opts[:group] || object_group_auto_name
  # NOTE: returnByValue is always set to false to avoid some extra complexity
  result = @rpc.call 'Runtime.evaluate', expression: expression,
                     objectGroup: group_name
  object = WebkitRemote::Client::JsObject.for result['result'], self,
                                                  group_name
  if result['wasThrown']
    # TODO(pwnall): some wrapper for exceptions?
    object
  else
    object
  end
end