Bug 1721375 - [devtools] Remove WebConsoleFront getString method. r=bomsy.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Wed, 21 Jul 2021 05:13:16 +0000
changeset 586293 c0ff235df051250281ac3e2baac56ea6662f1168
parent 586292 d716918916ac1a4993a616f07d501f9b64be467d
child 586294 e431bdd5db64bcbb728fcc92bd39831257c9da55
push id146621
push usernchevobbe@mozilla.com
push dateWed, 21 Jul 2021 05:15:45 +0000
treeherderautoland@c0ff235df051 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbomsy
bugs1721375
milestone92.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 1721375 - [devtools] Remove WebConsoleFront getString method. r=bomsy. The method isn't related to the webconsole actor, so we can remove it, and alongside with it, the longString method and _longStrings property which are no longer useful. The only customer of this switches to the shared `getLongStringFullText` method instead. Differential Revision: https://phabricator.services.mozilla.com/D120354
devtools/client/fronts/webconsole.js
devtools/client/webconsole/service-container.js
devtools/client/webconsole/webconsole-ui.js
--- a/devtools/client/fronts/webconsole.js
+++ b/devtools/client/fronts/webconsole.js
@@ -1,16 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-const DevToolsUtils = require("devtools/shared/DevToolsUtils");
-const { LongStringFront } = require("devtools/client/fronts/string");
 const {
   FrontClassWithSpec,
   registerFront,
 } = require("devtools/shared/protocol");
 const { webconsoleSpec } = require("devtools/shared/specs/webconsole");
 const {
   getAdHocFrontOrPrimitiveGrip,
 } = require("devtools/client/fronts/object");
@@ -22,17 +20,16 @@ const {
  * @param object client
  *        The DevToolsClient instance we live for.
  */
 class WebConsoleFront extends FrontClassWithSpec(webconsoleSpec) {
   constructor(client, targetFront, parentFront) {
     super(client, targetFront, parentFront);
     this._client = client;
     this.traits = {};
-    this._longStrings = {};
     this.events = [];
 
     // Attribute name from which to retrieve the actorID out of the target actor's form
     this.formAttributeName = "consoleActor";
 
     this._onNetworkEventUpdate = this._onNetworkEventUpdate.bind(this);
 
     this.before("consoleAPICall", this.beforeConsoleAPICall);
@@ -309,82 +306,27 @@ class WebConsoleFront extends FrontClass
   async startListeners(listeners) {
     const response = await super.startListeners(listeners);
     this.hasNativeConsoleAPI = response.nativeConsoleAPI;
     this.traits = response.traits;
     return response;
   }
 
   /**
-   * Return an instance of LongStringFront for the given long string grip.
-   *
-   * @param object grip
-   *        The long string grip returned by the protocol.
-   * @return {LongStringFront} the front for the given long string grip.
-   */
-  longString(grip) {
-    if (grip.actor in this._longStrings) {
-      return this._longStrings[grip.actor];
-    }
-
-    const front = new LongStringFront(this._client, this.targetFront, this);
-    front.form(grip);
-    this.manage(front);
-    this._longStrings[grip.actor] = front;
-    return front;
-  }
-
-  /**
-   * Fetches the full text of a LongString.
-   *
-   * @param object | string stringGrip
-   *        The long string grip containing the corresponding actor.
-   *        If you pass in a plain string (by accident or because you're lazy),
-   *        then a promise of the same string is simply returned.
-   * @return object Promise
-   *         A promise that is resolved when the full string contents
-   *         are available, or rejected if something goes wrong.
-   */
-  async getString(stringGrip) {
-    // Make sure this is a long string.
-    if (typeof stringGrip !== "object" || stringGrip.type !== "longString") {
-      // Go home string, you're drunk.
-      return stringGrip;
-    }
-
-    // Fetch the long string only once.
-    if (stringGrip._fullText) {
-      return stringGrip._fullText;
-    }
-
-    const { initial, length } = stringGrip;
-    const longStringFront = this.longString(stringGrip);
-
-    try {
-      const response = await longStringFront.substring(initial.length, length);
-      return initial + response;
-    } catch (e) {
-      DevToolsUtils.reportException("getString", e.message);
-      throw e;
-    }
-  }
-
-  /**
    * Close the WebConsoleFront.
    *
    */
   destroy() {
     if (!this._client) {
       return null;
     }
 
     this._client.off("networkEventUpdate", this._onNetworkEventUpdate);
     // This will make future calls to this function harmless because of the early return
     // at the top of the function.
     this._client = null;
 
-    this._longStrings = null;
     return super.destroy();
   }
 }
 
 exports.WebConsoleFront = WebConsoleFront;
 registerFront(WebConsoleFront);
--- a/devtools/client/webconsole/service-container.js
+++ b/devtools/client/webconsole/service-container.js
@@ -6,16 +6,19 @@
 
 const {
   createContextMenu,
 } = require("devtools/client/webconsole/utils/context-menu");
 
 const {
   createEditContextMenu,
 } = require("devtools/client/framework/toolbox-context-menu");
+const {
+  getLongStringFullText,
+} = require("devtools/client/shared/string-utils");
 
 function setupServiceContainer({
   webConsoleUI,
   hud,
   toolbox,
   webConsoleWrapper,
 }) {
   const serviceContainer = {
@@ -36,17 +39,17 @@ function setupServiceContainer({
     recordTelemetryEvent: (event, extra = {}) => hud.recordEvent(event, extra),
     openLink: (url, e) => hud.openLink(url, e),
     openNodeInInspector: grip => hud.openNodeInInspector(grip),
     getInputSelection: () => hud.getInputSelection(),
     onViewSource: location => hud.viewSource(location.url, location.line),
     resendNetworkRequest: requestId => hud.resendNetworkRequest(requestId),
     focusInput: () => hud.focusInput(),
     setInputValue: value => hud.setInputValue(value),
-    getLongString: grip => webConsoleUI.getLongString(grip),
+    getLongString: grip => getLongStringFullText(hud.commands.client, grip),
     getJsTermTooltipAnchor: () => webConsoleUI.getJsTermTooltipAnchor(),
     emitForTests: (event, value) => webConsoleUI.emitForTests(event, value),
     attachRefToWebConsoleUI: (id, node) => webConsoleUI.attachRef(id, node),
     requestData: (id, type) =>
       webConsoleUI.networkDataProvider.requestData(id, type),
     createElement: nodename => webConsoleWrapper.createElement(nodename),
   };
 
--- a/devtools/client/webconsole/webconsole-ui.js
+++ b/devtools/client/webconsole/webconsole-ui.js
@@ -682,20 +682,16 @@ class WebConsoleUI {
         this.wrapper.dispatchSidebarClose();
         if (this.jsterm) {
           this.jsterm.focus();
         }
       });
     }
   }
 
-  getLongString(grip) {
-    return this.getProxy().webConsoleFront.getString(grip);
-  }
-
   /**
    * Sets the focus to JavaScript input field when the web console tab is
    * selected or when there is a split console present.
    * @private
    */
   _onPanelSelected() {
     // We can only focus when we have the jsterm reference. This is fine because if the
     // jsterm is not mounted yet, it will be focused in JSTerm's componentDidMount.