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
-
#clear_runtime ⇒ WebkitRemote::Client
Releases all the objects allocated to this runtime.
- #initialize_runtime ⇒ Object
-
#object_group(group_name, create = false) ⇒ WebkitRemote::Client::JsObject, ...
Retrieves a group of remote objects by its name.
-
#object_group_auto_name ⇒ String
Generates a temporary group name for JavaScript objects.
-
#object_group_remove(group) ⇒ WebkitRemote::Client
Removes a group from the list of tracked groups.
-
#remote_eval(expression, opts = {}) ⇒ WebkitRemote::Client::JsObject, ...
Evals a JavaScript expression.
Instance Method Details
#clear_runtime ⇒ WebkitRemote::Client
Releases all the objects allocated to this runtime.
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_runtime ⇒ Object
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.
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_name ⇒ String
Generates a temporary group name for JavaScript objects.
This is useful when the API user does not
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.
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.
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 |