Bug 1529247 - clean up frames methods on thread client; r=ochameau
authoryulia <ystartsev@mozilla.com>
Fri, 01 Mar 2019 15:26:18 +0000
changeset 519843 ff07a2a59bb0b6df5382f36fc661fa9b7dd46d30
parent 519842 e4bda8b288b31ebcf537a1764c6f166cee5c3fb5
child 519844 a066481987fbbf72b10e6fb60d2e2eb190586f4d
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1529247
milestone67.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 1529247 - clean up frames methods on thread client; r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D20834
devtools/docs/backend/client-api.md
devtools/server/tests/unit/test_frameclient-01.js
devtools/server/tests/unit/test_frameclient-02.js
devtools/server/tests/unit/xpcshell.ini
devtools/shared/client/thread-client.js
--- a/devtools/docs/backend/client-api.md
+++ b/devtools/docs/backend/client-api.md
@@ -117,18 +117,16 @@ client.attachThread(response.threadActor
   if (!threadClient) {
     return;
   }
 
   // Attach listeners for thread events.
   threadClient.addListener("paused", onPause);
   threadClient.addListener("resumed", fooListener);
   threadClient.addListener("detached", fooListener);
-  threadClient.addListener("framesadded", onFrames);
-  threadClient.addListener("framescleared", fooListener);
 
   // Resume the thread.
   threadClient.resume();
 
   // Debugger is now ready and debuggee is running.
 });
 ```
 
@@ -182,18 +180,16 @@ function debugTab() {
     // Attach to the tab.
     targetFront.attach().then(() => {
       // Attach to the thread (context).
       targetFront.attachThread().then(([response, threadClient]) => {
         // Attach listeners for thread events.
         threadClient.addListener("paused", onPause);
         threadClient.addListener("resumed", fooListener);
         threadClient.addListener("detached", fooListener);
-        threadClient.addListener("framesadded", onFrames);
-        threadClient.addListener("framescleared", fooListener);
 
         // Resume the thread.
         threadClient.resume();
         // Debugger is now ready and debuggee is running.
       });
     });
   });
 }
@@ -208,38 +204,16 @@ function onTab() {
     client.detach(() => {
       // Start debugging the new tab.
       debugTab();
     });
   });
 }
 
 /**
- * Handler for entering pause state.
- */
-function onPause() {
-  // Get the top 20 frames in the server's frame stack cache.
-  client.activeThread.fillFrames(20);
-  // Get the scripts loaded in the server's source script cache.
-  client.activeThread.fillScripts();
-}
-
-/**
- * Handler for framesadded events.
- */
-function onFrames() {
-  // Get the list of frames in the server.
-  for (let frame of client.activeThread.cachedFrames) {
-    // frame is a Debugger.Frame grip.
-    dump("frame: " + frame.toSource() + "\n");
-    inspectFrame(frame);
-  }
-}
-
-/**
  * Helper function to inspect the provided frame.
  */
 function inspectFrame(frame) {
   // Get the "this" object.
   if (frame["this"]) {
     getObjectProperties(frame["this"]);
   }
 
deleted file mode 100644
--- a/devtools/server/tests/unit/test_frameclient-01.js
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-/* eslint-disable max-nested-callbacks */
-
-"use strict";
-
-var gDebuggee;
-var gClient;
-var gThreadClient;
-
-function run_test() {
-  Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
-  registerCleanupFunction(() => {
-    Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
-  });
-  initTestDebuggerServer();
-  gDebuggee = addTestGlobal("test-stack");
-  gClient = new DebuggerClient(DebuggerServer.connectPipe());
-  gClient.connect().then(function() {
-    attachTestTabAndResume(gClient, "test-stack",
-                           function(response, targetFront, threadClient) {
-                             gThreadClient = threadClient;
-                             test_pause_frame();
-                           });
-  });
-  do_test_pending();
-}
-
-function test_pause_frame() {
-  gThreadClient.addOneTimeListener("paused", function(event, packet) {
-    gThreadClient.addOneTimeListener("framesadded", function() {
-      Assert.equal(gThreadClient.cachedFrames.length, 3);
-      Assert.ok(gThreadClient.moreFrames);
-      Assert.ok(!gThreadClient.fillFrames(3));
-
-      Assert.ok(gThreadClient.fillFrames(30));
-      gThreadClient.addOneTimeListener("framesadded", function() {
-        Assert.ok(!gThreadClient.moreFrames);
-        Assert.equal(gThreadClient.cachedFrames.length, 7);
-        gThreadClient.resume(function() {
-          finishClient(gClient);
-        });
-      });
-    });
-    Assert.ok(gThreadClient.fillFrames(3));
-  });
-
-  /* eslint-disable */
-  gDebuggee.eval("(" + function () {
-    var recurseLeft = 5;
-    function recurse() {
-      if (--recurseLeft == 0) {
-        debugger;
-        return;
-      }
-      recurse();
-    }
-    recurse();
-  } + ")()");
-  /* eslint-enable */
-}
deleted file mode 100644
--- a/devtools/server/tests/unit/test_frameclient-02.js
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-"use strict";
-
-var gDebuggee;
-var gClient;
-var gThreadClient;
-
-function run_test() {
-  Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
-  registerCleanupFunction(() => {
-    Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
-  });
-  initTestDebuggerServer();
-  gDebuggee = addTestGlobal("test-stack");
-  gClient = new DebuggerClient(DebuggerServer.connectPipe());
-  gClient.connect().then(function() {
-    attachTestTabAndResume(gClient, "test-stack",
-                           function(response, targetFront, threadClient) {
-                             gThreadClient = threadClient;
-                             test_pause_frame();
-                           });
-  });
-  do_test_pending();
-}
-
-function test_pause_frame() {
-  gThreadClient.addOneTimeListener("paused", function(event, packet) {
-    // Ask for exactly the number of frames we expect.
-    gThreadClient.addOneTimeListener("framesadded", function() {
-      Assert.ok(!gThreadClient.moreFrames);
-      gThreadClient.resume(function() {
-        finishClient(gClient);
-      });
-    });
-    Assert.ok(gThreadClient.fillFrames(3));
-  });
-
-  /* eslint-disable */
-  gDebuggee.eval("(" + function () {
-    var recurseLeft = 1;
-    function recurse() {
-      if (--recurseLeft == 0) {
-        debugger;
-        return;
-      }
-      recurse();
-    }
-    recurse();
-  } + ")()");
-  /* eslint-enable */
-}
--- a/devtools/server/tests/unit/xpcshell.ini
+++ b/devtools/server/tests/unit/xpcshell.ini
@@ -74,18 +74,16 @@ support-files =
 [test_pauselifetime-04.js]
 [test_threadlifetime-01.js]
 [test_threadlifetime-02.js]
 [test_threadlifetime-03.js]
 [test_threadlifetime-04.js]
 [test_threadlifetime-05.js]
 [test_threadlifetime-06.js]
 [test_functiongrips-01.js]
-[test_frameclient-01.js]
-[test_frameclient-02.js]
 [test_front_destroy.js]
 [test_nativewrappers.js]
 [test_nodelistactor.js]
 [test_eval-01.js]
 [test_eval-02.js]
 [test_eval-03.js]
 [test_eval-04.js]
 [test_eval-05.js]
--- a/devtools/shared/client/thread-client.js
+++ b/devtools/shared/client/thread-client.js
@@ -2,17 +2,16 @@
 /* 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 promise = require("devtools/shared/deprecated-sync-thenables");
 
-const DevToolsUtils = require("devtools/shared/DevToolsUtils");
 const {arg, DebuggerClient} = require("devtools/shared/client/debugger-client");
 const eventSource = require("devtools/shared/client/event-source");
 const {ThreadStateTypes} = require("devtools/shared/client/constants");
 
 loader.lazyRequireGetter(this, "ArrayBufferClient", "devtools/shared/client/array-buffer-client");
 loader.lazyRequireGetter(this, "LongStringClient", "devtools/shared/client/long-string-client");
 loader.lazyRequireGetter(this, "ObjectClient", "devtools/shared/client/object-client");
 loader.lazyRequireGetter(this, "SourceClient", "devtools/shared/client/source-client");
@@ -26,17 +25,16 @@ const noop = () => {};
  *
  * @param client DebuggerClient
  * @param actor string
  *        The actor ID for this thread.
  */
 function ThreadClient(client, actor) {
   this.client = client;
   this._actor = actor;
-  this._frameCache = [];
   this._scriptCache = {};
   this._pauseGrips = {};
   this._threadGrips = {};
   this.request = this.client.request;
 }
 
 ThreadClient.prototype = {
   _state: "paused",
@@ -427,105 +425,25 @@ ThreadClient.prototype = {
    *        Whether the server should skip pausing via breakpoints
    */
   skipBreakpoints: DebuggerClient.requester({
     type: "skipBreakpoints",
     skip: arg(0),
   }),
 
   /**
-   * An array of cached frames. Clients can observe the framesadded and
-   * framescleared event to keep up to date on changes to this cache,
-   * and can fill it using the fillFrames method.
-   */
-  get cachedFrames() {
-    return this._frameCache;
-  },
-
-  /**
-   * true if there are more stack frames available on the server.
-   */
-  get moreFrames() {
-    return this.paused && (!this._frameCache || this._frameCache.length == 0
-          || !this._frameCache[this._frameCache.length - 1].oldest);
-  },
-
-  /**
    * Request the frame environment.
    *
    * @param frameId string
    */
   getEnvironment: function(frameId) {
     return this.request({ to: frameId, type: "getEnvironment" });
   },
 
   /**
-   * Ensure that at least total stack frames have been loaded in the
-   * ThreadClient's stack frame cache. A framesadded event will be
-   * sent when the stack frame cache is updated.
-   *
-   * @param total number
-   *        The minimum number of stack frames to be included.
-   * @param callback function
-   *        Optional callback function called when frames have been loaded
-   * @returns true if a framesadded notification should be expected.
-   */
-  fillFrames: function(total, callback = noop) {
-    this._assertPaused("fillFrames");
-    if (this._frameCache.length >= total) {
-      return false;
-    }
-
-    const numFrames = this._frameCache.length;
-
-    this.getFrames(numFrames, total - numFrames, (response) => {
-      if (response.error) {
-        callback(response);
-        return;
-      }
-
-      const threadGrips = DevToolsUtils.values(this._threadGrips);
-
-      for (const i in response.frames) {
-        const frame = response.frames[i];
-        if (!frame.where.source) {
-          // Older servers use urls instead, so we need to resolve
-          // them to source actors
-          for (const grip of threadGrips) {
-            if (grip instanceof SourceClient && grip.url === frame.url) {
-              frame.where.source = grip._form;
-            }
-          }
-        }
-
-        this._frameCache[frame.depth] = frame;
-      }
-
-      // If we got as many frames as we asked for, there might be more
-      // frames available.
-      this.emit("framesadded");
-
-      callback(response);
-    });
-
-    return true;
-  },
-
-  /**
-   * Clear the thread's stack frame cache. A framescleared event
-   * will be sent.
-   */
-  _clearFrames: function() {
-    if (this._frameCache.length > 0) {
-      this._frameCache = [];
-      this.emit("framescleared");
-    }
-  },
-
-  /**
    * Return a ObjectClient object for the given object grip.
    *
    * @param grip object
    *        A pause-lifetime object grip returned by the protocol.
    */
   pauseGrip: function(grip) {
     if (grip.actor in this._pauseGrips) {
       return this._pauseGrips[grip.actor];
@@ -643,17 +561,16 @@ ThreadClient.prototype = {
    * registered listeners.
    */
   _onThreadState: function(packet) {
     this._state = ThreadStateTypes[packet.type];
     // The debugger UI may not be initialized yet so we want to keep
     // the packet around so it knows what to pause state to display
     // when it's initialized
     this._lastPausePacket = packet.type === "resumed" ? null : packet;
-    this._clearFrames();
     this._clearPauseGrips();
     packet.type === ThreadStateTypes.detached && this._clearThreadGrips();
     this.client._eventsEnabled && this.emit(packet.type, packet);
   },
 
   getLastPausePacket: function() {
     return this._lastPausePacket;
   },