Method: WebkitRemote::Client::JsObject.for

Defined in:
lib/webkit_remote/client/runtime.rb

.for(raw_object, client, group_name) ⇒ WebkitRemote::Client::JsObject, ...

Wraps a raw object returned by the Webkit remote debugger RPC protocol.

Parameters:

  • raw_object (Hash<String, Object>)

    a JsObject instance, according to the Webkit remote debugging protocol; this is the return value of a ‘Runtime.evaluate’ RPC call

  • client (WebkitRemote::Client::Runtime)

    remote debugging client for the browser tab that owns this object

  • group_name (String)

    name of the object group that will hold this object; object groups work like memory pools

Returns:

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

    a Ruby wrapper for the given raw object; primitives get wrapped by standard Ruby classes, and objects get wrapped by JsObject instances

Raises:

  • (RuntimeError)


267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/webkit_remote/client/runtime.rb', line 267

def self.for(raw_object, client, group_name)
  if remote_id = raw_object['objectId']
    group = client.object_group group_name, true
    return group.get(remote_id) ||
           WebkitRemote::Client::JsObject.new(raw_object, group)
  else
    # primitive types
    case raw_object['type'] ? raw_object['type'].to_sym : nil
    when :boolean, :number, :string
      return raw_object['value']
    when :undefined
      return WebkitRemote::Client::Undefined
    when :object
      case raw_object['subtype'] ? raw_object['subtype'].to_sym : nil
      when :null
        return nil
      end
      # TODO(pwnall): Any other exceptions?
    end
  end
  raise RuntimeError, "Unable to parse #{raw_object.inspect}"
end