Bug 1222047 - Cache root actor form on RootClient rather than Target object. r=yulia
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 09 Aug 2018 08:16:08 -0700
changeset 490790 203dbb34de0471725426c47b1a06ae5550268e2a
parent 490789 105a304b29222a6ba569e6ee20a2841b6407e4a3
child 490791 b47fe9721bd87ec9d1f075d5ab4de41ca15963bf
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1222047
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1222047 - Cache root actor form on RootClient rather than Target object. r=yulia Summary: Depends On D3314 Reviewers: yulia! Tags: #secure-revision Bug #: 1222047 Differential Revision: https://phabricator.services.mozilla.com/D3872 MozReview-Commit-ID: 9zqIeJWznsb
devtools/client/framework/target.js
devtools/shared/client/root-client.js
--- a/devtools/client/framework/target.js
+++ b/devtools/client/framework/target.js
@@ -266,36 +266,21 @@ TabTarget.prototype = {
   get tab() {
     return this._tab;
   },
 
   get form() {
     return this._form;
   },
 
-  // Get a promise of the root form returned by a getRoot request. This promise
-  // is cached.
+  // Get a promise of the RootActor's form
   get root() {
-    if (!this._root) {
-      this._root = this._getRoot();
-    }
-    return this._root;
+    return this.client.mainRoot.rootForm;
   },
 
-  _getRoot: function() {
-    return new Promise((resolve, reject) => {
-      this.client.mainRoot.getRoot(response => {
-        if (response.error) {
-          reject(new Error(response.error + ": " + response.message));
-          return;
-        }
-
-        resolve(response);
-      });
-    });
   },
 
   get client() {
     return this._client;
   },
 
   // Tells us if we are debugging content document
   // or if we are debugging chrome stuff.
--- a/devtools/shared/client/root-client.js
+++ b/devtools/shared/client/root-client.js
@@ -27,28 +27,38 @@ const { arg, DebuggerClient } = require(
  * @property traits object
  *      The traits object, as given in the root actor's greeting packet.
  */
 function RootClient(client, greeting) {
   this._client = client;
   this.actor = greeting.from;
   this.applicationType = greeting.applicationType;
   this.traits = greeting.traits;
+
+  // Cache root form as this will always be the same value.
+  Object.defineProperty(this, "rootForm", {
+    get() {
+      delete this.rootForm;
+      this.rootForm = this._getRoot();
+      return this.rootForm;
+    },
+    configurable: true
+  });
 }
 exports.RootClient = RootClient;
 
 RootClient.prototype = {
   constructor: RootClient,
 
   /**
    * Gets the "root" form, which lists all the global actors that affect the entire
    * browser.  This can replace usages of `listTabs` that only wanted the global actors
    * and didn't actually care about tabs.
    */
-  getRoot: DebuggerClient.requester({ type: "getRoot" }),
+  _getRoot: DebuggerClient.requester({ type: "getRoot" }),
 
    /**
    * List the open tabs.
    *
    * @param object options
    *        Optional flags for listTabs:
    *        - boolean favicons: return favicon data
    * @param function onResponse