DevTools: Fix recursive expansion of objects

The code we have to populate a tree uses await, except that in the recursive
case we don't await its Promise, instead treating it as a sync op. This resulted
in the bug that the child list is empty when checked. This patch updates that
code such that it now awaits the async populate process before checking for
child nodes to expand.

Bug: 961141
Change-Id: I35f3aacf3ef67d0de9a0c35a0c98ec500b08df58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1657907
Reviewed-by: Erik Luo <[email protected]>
Commit-Queue: Paul Lewis <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#672485}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 615fb1ff80242114d396b76db184953376b17fea
diff --git a/front_end/ui/treeoutline.js b/front_end/ui/treeoutline.js
index 81aa692..1428289 100644
--- a/front_end/ui/treeoutline.js
+++ b/front_end/ui/treeoutline.js
@@ -929,8 +929,9 @@
 
   /**
    * @param {number=} maxDepth
+   * @returns {!Promise}
    */
-  expandRecursively(maxDepth) {
+  async expandRecursively(maxDepth) {
     let item = this;
     const info = {};
     let depth = 0;
@@ -942,8 +943,11 @@
       maxDepth = 3;
 
     while (item) {
+      await item._populateIfNeeded();
+
       if (depth < maxDepth)
         item.expand();
+
       item = item.traverseNextTreeElement(false, this, (depth >= maxDepth), info);
       depth += info.depthChange;
     }
@@ -1135,14 +1139,20 @@
     }
   }
 
-  _populateIfNeeded() {
+  /**
+   * @returns {!Promise}
+   */
+  async _populateIfNeeded() {
     if (this.treeOutline && this._expandable && !this._children) {
       this._children = [];
-      this.onpopulate();
+      await this.onpopulate();
     }
   }
 
-  onpopulate() {
+  /**
+   * @return {!Promise}
+   */
+  async onpopulate() {
     // Overridden by subclasses.
   }