module WebkitRemote::Client::Runtime
API for the Runtime
domain.
Public Instance Methods
Releases all the objects allocated to this runtime.
@return [WebkitRemote::Client] self
# File lib/webkit_remote/client/runtime.rb, line 81 def clear_runtime @runtime_groups.each do |name, group| group.release_all end self end
@private Called by the WebkitRemote::Client
constructor.
# File lib/webkit_remote/client/runtime.rb, line 74 def initialize_runtime() @runtime_groups = {} end
Retrieves a group of remote objects by its name.
@param [String, Symbol] group_name name given to remote_eval
when the
object was created; nil obtains the anonymous group containing the un-grouped objects created by Console#MessageReceived
@param [Boolean] create if true, fetching a group that does not exist will
create the group; this parameter should only be used internally
@return [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
# 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
Generates a temporary group name for JavaScript objects.
This is useful when the API user does not
@return [String] an automatically-generated JS object name
# File lib/webkit_remote/client/runtime.rb, line 59 def object_group_auto_name '_' end
Removes a group from the list of tracked groups.
@private Use WebkitRemote::Client::JsObjectGroup#release instead of
calling this directly.
@return [WebkitRemote::Client] self
# File lib/webkit_remote/client/runtime.rb, line 68 def object_group_remove(group) @runtime_groups.delete group.name self end
Evals a JavaScript expression.
@param [String] expression the JavaScript expression to be evaluated @param [Hash] opts tweaks @option opts [String, Symbol] group 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
@return [WebkitRemote::Client::JsObject, Boolean, Number, String] the
result of evaluating the expression
# 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