Bug 1519107 - use promise pattern for getCachedMessage rather than callbacks; r=ochameau
authoryulia <ystartsev@mozilla.com>
Mon, 21 Jan 2019 13:47:03 +0000
changeset 514693 c367b5259d4683c8d7fcf7efdda68f6ca93f9913
parent 514692 d532474e710f8a58ab10a2702dca432bc2eefa69
child 514694 05ab29790c5718f31d2910f8728af5f742eaf14d
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1519107
milestone66.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 1519107 - use promise pattern for getCachedMessage rather than callbacks; r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D16195
devtools/client/webconsole/webconsole-connection-proxy.js
devtools/shared/webconsole/client.js
devtools/shared/webconsole/test/test_cached_messages.html
devtools/shared/webconsole/test/test_console_serviceworker_cached.html
devtools/shared/webconsole/test/test_console_worker.html
--- a/devtools/client/webconsole/webconsole-connection-proxy.js
+++ b/devtools/client/webconsole/webconsole-connection-proxy.js
@@ -169,33 +169,34 @@ WebConsoleConnectionProxy.prototype = {
    *
    * @private
    * @param object response
    *        The JSON response object received from the server.
    * @param object webConsoleClient
    *        The WebConsoleClient instance for the attached console, for the
    *        specific tab we work with.
    */
-  _onAttachConsole: function(response) {
+  _onAttachConsole: async function(response) {
     let saveBodies = Services.prefs.getBoolPref(
       "devtools.netmonitor.saveRequestAndResponseBodies");
 
     // There is no way to view response bodies from the Browser Console, so do
     // not waste the memory.
     if (this.webConsoleFrame.isBrowserConsole) {
       saveBodies = false;
     }
 
     this.webConsoleFrame.setSaveRequestAndResponseBodies(saveBodies);
 
     this.webConsoleClient.on("networkEvent", this._onNetworkEvent);
     this.webConsoleClient.on("networkEventUpdate", this._onNetworkEventUpdate);
 
     const msgs = ["PageError", "ConsoleAPI"];
-    this.webConsoleClient.getCachedMessages(msgs, this._onCachedMessages);
+    const cachedMessages = await this.webConsoleClient.getCachedMessages(msgs);
+    this._onCachedMessages(cachedMessages);
 
     this.webConsoleFrame._onUpdateListeners();
   },
 
   /**
    * Dispatch a message add on the new frontend and emit an event for tests.
    */
   dispatchMessageAdd: function(packet) {
--- a/devtools/shared/webconsole/client.js
+++ b/devtools/shared/webconsole/client.js
@@ -211,28 +211,26 @@ WebConsoleClient.prototype = {
 
   /**
    * Retrieve the cached messages from the server.
    *
    * @see this.CACHED_MESSAGES
    * @param array types
    *        The array of message types you want from the server. See
    *        this.CACHED_MESSAGES for known types.
-   * @param function onResponse
-   *        The function invoked when the response is received.
    * @return request
    *         Request object that implements both Promise and EventEmitter interfaces
    */
-  getCachedMessages: function(types, onResponse) {
+  getCachedMessages: function(types) {
     const packet = {
       to: this.actorID,
       type: "getCachedMessages",
       messageTypes: types,
     };
-    return this._client.request(packet, onResponse);
+    return this._client.request(packet);
   },
 
   /**
    * Inspect the properties of an object.
    *
    * @param string actor
    *        The WebConsoleObjectActor ID to send the request to.
    * @param function onResponse
--- a/devtools/shared/webconsole/test/test_cached_messages.html
+++ b/devtools/shared/webconsole/test/test_cached_messages.html
@@ -148,18 +148,18 @@ function startTest() {
 
 function checkConsoleAPICache() {
   consoleAPIListener.destroy();
   consoleAPIListener = null;
   attachConsole(["ConsoleAPI"], onAttach1);
 }
 
 function onAttach1(state, response) {
-  state.client.getCachedMessages(["ConsoleAPI"],
-                                  onCachedConsoleAPI.bind(null, state));
+  state.client.getCachedMessages(["ConsoleAPI"])
+    .then(onCachedConsoleAPI.bind(null, state));
 }
 
 function onCachedConsoleAPI(state, response) {
   let msgs = response.messages;
   info("cached console messages: " + msgs.length);
 
   ok(msgs.length >= expectedConsoleCalls.length,
      "number of cached console messages");
@@ -186,18 +186,18 @@ function onCachedConsoleAPI(state, respo
 
 function testPageErrors() {
   consoleServiceListener.destroy();
   consoleServiceListener = null;
   attachConsole(["PageError"], onAttach2);
 }
 
 function onAttach2(state, response) {
-  state.client.getCachedMessages(["PageError"],
-                                  onCachedPageErrors.bind(null, state));
+  state.client.getCachedMessages(["PageError"])
+    .then(onCachedPageErrors.bind(null, state));
 }
 
 function onCachedPageErrors(state, response) {
   let msgs = response.messages;
   info("cached page errors: " + msgs.length);
 
   ok(msgs.length >= expectedPageErrors.length,
      "number of cached page errors");
--- a/devtools/shared/webconsole/test/test_console_serviceworker_cached.html
+++ b/devtools/shared/webconsole/test/test_console_serviceworker_cached.html
@@ -57,32 +57,32 @@ let startTest = async function () {
   info("Adding a tab and attaching a service worker");
   let tab1 = await addTab(FRAME_URL);
   let swr = await withActiveServiceWorker(tab1.linkedBrowser.contentWindow,
                                 SERVICE_WORKER_URL);
 
   await new Promise(resolve => {
     info("Attaching console to tab 1");
     attachConsoleToTab(["ConsoleAPI"], function(state) {
-      state.client.getCachedMessages(["ConsoleAPI"], function(calls) {
+      state.client.getCachedMessages(["ConsoleAPI"]).then(function(calls) {
         checkConsoleAPICalls(calls.messages, firstTabExpectedCalls);
         closeDebugger(state, resolve);
       });
     });
   });
 
   // Because this tab is being added after the original messages happened,
   // they shouldn't show up in a call to getCachedMessages.
   // However, there is a fetch event which is logged due to loading the tab.
   info("Adding a new tab at the same URL");
   let tab2 = await addTab(FRAME_URL);
   await new Promise(resolve => {
     info("Attaching console to tab 2");
     attachConsoleToTab(["ConsoleAPI"], function(state) {
-      state.client.getCachedMessages(["ConsoleAPI"], function(calls) {
+      state.client.getCachedMessages(["ConsoleAPI"]).then(function(calls) {
         checkConsoleAPICalls(calls.messages, secondTabExpectedCalls);
         closeDebugger(state, resolve);
       });
     });
   });
 
   await swr.unregister();
 
--- a/devtools/shared/webconsole/test/test_console_worker.html
+++ b/devtools/shared/webconsole/test/test_console_worker.html
@@ -49,17 +49,17 @@ let testCachedMessages = async function 
   return new Promise(resolve => {
     let onCachedConsoleAPI = (response) => {
       let consoleCalls = response.messages;
 
       info('Received cached response. Checking console calls.');
       checkConsoleAPICalls(consoleCalls, expectedCachedConsoleCalls);
       resolve();
     };
-    state.client.getCachedMessages(["ConsoleAPI"], onCachedConsoleAPI);
+    state.client.getCachedMessages(["ConsoleAPI"]).then(onCachedConsoleAPI);
   })
 };
 
 let testConsoleAPI = async function (state) {
   info("testConsoleAPI entered");
   return new Promise(resolve => {
     let onConsoleAPICall = (type, packet) => {
       info("received message level: " + packet.message.level);