Web Inspector: ES6: Improved Console Format for Set and Map Objects (like Arrays)
https://bugs.webkit.org/show_bug.cgi?id=122867

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

Add new Runtime.RemoteObject object subtypes for "map", "set", and "weakmap".

Upgrade Runtime.ObjectPreview to include type/subtype information. Now,
an ObjectPreview can be used for any value, in place of a RemoteObject,
and not capture / hold a reference to the value. The value will be in
the string description.

Adding this information to ObjectPreview can duplicate some information
in the protocol messages if a preview is provided, but simplifies
previews, so that all the information you need for any RemoteObject
preview is available. To slim messages further, make "overflow" and
"properties" only available on previews that may contain properties.
So, not primitives or null.

Finally, for "Map/Set/WeakMap" add an "entries" list to the preview
that will return previews with "key" and "value" properties depending
on the collection type. To get live, non-preview objects from a
collection, use Runtime.getCollectionEntries.

In order to keep the WeakMap's values Weak the frontend may provide
a unique object group name when getting collection entries. It may
then release that object group, e.g. when not showing the WeakMap's
values to the user, and thus remove the strong reference to the keys
so they may be garbage collected.

* runtime/WeakMapData.h:
(JSC::WeakMapData::begin):
(JSC::WeakMapData::end):
Expose iterators so the Inspector may access WeakMap keys/values.

* inspector/JSInjectedScriptHostPrototype.cpp:
(Inspector::JSInjectedScriptHostPrototype::finishCreation):
(Inspector::jsInjectedScriptHostPrototypeFunctionWeakMapEntries):
* inspector/JSInjectedScriptHost.h:
* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::subtype):
Discern "map", "set", and "weakmap" object subtypes.

(Inspector::JSInjectedScriptHost::weakMapEntries):
Return a list of WeakMap entries. These are strong references
that the Inspector code is responsible for releasing.

* inspector/protocol/Runtime.json:
Update types and expose the new getCollectionEntries command.

* inspector/agents/InspectorRuntimeAgent.h:
* inspector/agents/InspectorRuntimeAgent.cpp:
(Inspector::InspectorRuntimeAgent::getCollectionEntries):
* inspector/InjectedScript.h:
* inspector/InjectedScript.cpp:
(Inspector::InjectedScript::getInternalProperties):
(Inspector::InjectedScript::getCollectionEntries):
Pass through to the InjectedScript and call getCollectionEntries.

* inspector/scripts/codegen/generator.py:
Add another type with runtime casting.

* inspector/InjectedScriptSource.js:
- Implement getCollectionEntries to get a range of values from a
collection. The non-Weak collections have an order to their keys (in
order of added) so range'd gets are okay. WeakMap does not have an
order, so only allow fetching a number of values.
- Update preview generation to address the Runtime.ObjectPreview
type changes.

Source/WebInspectorUI:

This includes Set/Map/WeakMap previews:

    - Set previews: Set {1, 2, 3}
    - Map/WeakMap previews: Map {1 => 2, "key" => "value"}

For WeakMaps:

    - the preview itself shows up to 5 key/value pairs from when the object was logged
    - the previews are strings only, and thus do not retain the actual keys/values
    - when expanding, we get RemoteObjects and strongly retain the keys/values
    - when collapsing / clearing, we release the RemoteObjects so they can get collected

Currently you collapse the <entries> section, and re-expand later the
collection may show you knew keys/values. The UI for this will change.

* Localizations/en.lproj/localizedStrings.js:
* UserInterface/Protocol/RemoteObject.js:
(WebInspector.RemoteObject.prototype.isCollectionType):
(WebInspector.RemoteObject.prototype.isWeakCollection):
(WebInspector.RemoteObject.prototype.getCollectionEntries):
(WebInspector.RemoteObject.prototype.releaseWeakCollectionEntries):
(WebInspector.RemoteObject.prototype.arrayLength):
(WebInspector.RemoteObject.prototype._weakCollectionObjectGroup):
High level functions for dealing with a RemoteObject that may be a
collection / weak collection.

* UserInterface/Views/ConsoleMessageImpl.js:
(WebInspector.ConsoleMessageImpl):
(WebInspector.ConsoleMessageImpl.prototype._formatParameterAsObject):
Include default formatters for collection types.

(WebInspector.ConsoleMessageImpl.prototype._appendPreview):
(WebInspector.ConsoleMessageImpl.prototype._appendEntryPreviews):
(WebInspector.ConsoleMessageImpl.prototype._appendPropertyPreviews):
(WebInspector.ConsoleMessageImpl.prototype._appendValuePreview):
(WebInspector.ConsoleMessageImpl.prototype._appendObjectPreview): Deleted.
Refactor preview generation a bit and include a specific path for
generation the output of a preview with "entries".

* UserInterface/Views/LogContentView.css:
(.console-object-preview-body .console-object-preview-name.console-object-preview-name-Object):
With nested Object previews ("Map {{a:1} => 1}") don't show "Object" for the inner
object preview. Only show it if it has a unique type ("Map {Foo {a:1} => 1}")

(.console-formatted-object, .console-formatted-node, .console-formatted-error, .console-formatted-map, .console-formatted-set, .console-formatted-weakmap):
(:matches(.console-formatted-object, .console-formatted-node, .console-formatted-error, .console-formatted-map, .console-formatted-set, .console-formatted-weakmap) .section):
(:matches(.console-formatted-object, .console-formatted-node, .console-formatted-error, .console-formatted-map, .console-formatted-set, .console-formatted-weakmap) .properties):
Make map/set/weakmap display like Objects.

* UserInterface/Views/ObjectPropertiesSection.js:
(WebInspector.ObjectPropertiesSection.prototype.update):
(WebInspector.ObjectPropertiesSection.prototype.updateProperties):
(WebInspector.ObjectPropertyTreeElement.prototype.onpopulate.callback):
(WebInspector.ObjectPropertyTreeElement.prototype.onpopulate):
(WebInspector.CollectionEntriesMainTreeElement):
(WebInspector.CollectionEntriesMainTreeElement.prototype.onexpand.callback):
(WebInspector.CollectionEntriesMainTreeElement.prototype.onexpand):
(WebInspector.CollectionEntriesMainTreeElement.prototype.oncollapse):
(WebInspector.CollectionEntriesMainTreeElement.prototype.ondetach):
(WebInspector.CollectionEntriesMainTreeElement.prototype._trackWeakEntries):
(WebInspector.CollectionEntriesMainTreeElement.prototype._untrackWeakEntries):
(WebInspector.CollectionEntryTreeElement):
(WebInspector.CollectionEntryTreeElement.prototype.onpopulate):
(WebInspector.CollectionEntryTreeElement.prototype.onattach):
(WebInspector.EmptyCollectionTreeElement):
(WebInspector.ObjectPropertiesSection.prototype.update.callback): Deleted.
Add a quick UI for exploring the entries of a collection. We are actively
changing the styles of objects in the Console, so this should change soon.

LayoutTests:

* TestExpectations:
The test unexpectedly fails in Debug builds, so skip it.

* inspector/model/remote-object-expected.txt:
* inspector/model/remote-object.html:
Update based on Runtime.ObjectPreview changes.

* inspector/model/remote-object-weak-collection-expected.txt: Added.
* inspector/model/remote-object-weak-collection.html: Added.
New test for weak collection handling.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@179349 268f45cc-cd09-0410-ab3c-d52691b4dbfc
24 files changed