Web Inspector: DebuggerManager commands should return promises
authorburg@cs.washington.edu <burg@cs.washington.edu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Aug 2014 21:25:34 +0000 (21:25 +0000)
committerburg@cs.washington.edu <burg@cs.washington.edu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Aug 2014 21:25:34 +0000 (21:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135690

Reviewed by Timothy Hatcher.

Convert the existing debugger commands to return promises. This
requires separately waiting for protocol command's promise to be
fulfilled, as well as waiting for the appropriate DebuggerManager
event. If the protocol command promise is rejected, tear down the
single-fire event listener.

* UserInterface/Controllers/DebuggerManager.js:
(WebInspector.DebuggerManager.prototype.pause):
(WebInspector.DebuggerManager.prototype.resume):
(WebInspector.DebuggerManager.prototype.stepOver):
(WebInspector.DebuggerManager.prototype.stepInto):
(WebInspector.DebuggerManager.prototype.stepOut):
* UserInterface/Controllers/ReplayManager.js: Use the promise-based API.
(WebInspector.ReplayManager.prototype._suppressBreakpointsAndResumeIfNeeded):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172412 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js
Source/WebInspectorUI/UserInterface/Controllers/ReplayManager.js

index 4ac7fed..66714b9 100644 (file)
@@ -1,3 +1,25 @@
+2014-08-08  Brian J. Burg  <burg@cs.washington.edu>
+
+        Web Inspector: DebuggerManager commands should return promises
+        https://bugs.webkit.org/show_bug.cgi?id=135690
+
+        Reviewed by Timothy Hatcher.
+
+        Convert the existing debugger commands to return promises. This
+        requires separately waiting for protocol command's promise to be
+        fulfilled, as well as waiting for the appropriate DebuggerManager
+        event. If the protocol command promise is rejected, tear down the
+        single-fire event listener.
+
+        * UserInterface/Controllers/DebuggerManager.js:
+        (WebInspector.DebuggerManager.prototype.pause):
+        (WebInspector.DebuggerManager.prototype.resume):
+        (WebInspector.DebuggerManager.prototype.stepOver):
+        (WebInspector.DebuggerManager.prototype.stepInto):
+        (WebInspector.DebuggerManager.prototype.stepOut):
+        * UserInterface/Controllers/ReplayManager.js: Use the promise-based API.
+        (WebInspector.ReplayManager.prototype._suppressBreakpointsAndResumeIfNeeded):
+
 2014-08-11  Timothy Hatcher  <timothy@apple.com>
 
         Web Inspector: Update folder icons
index d29c375..1732d33 100644 (file)
@@ -142,27 +142,107 @@ WebInspector.DebuggerManager.prototype = {
 
     pause: function()
     {
-        DebuggerAgent.pause();
+        if (this._paused)
+            return Promise.resolve();
+
+        var listener = new WebInspector.EventListener(this, true);
+
+        var managerResult = new Promise(function(resolve, reject) {
+            listener.connect(WebInspector.debuggerManager, WebInspector.DebuggerManager.Event.Paused, resolve);
+        });
+
+        var protocolResult = DebuggerAgent.pause()
+            .catch(function(error) {
+                listener.disconnect();
+                console.error("DebuggerManager.pause failed: ", error);
+                throw error;
+            });
+
+        return Promise.all([managerResult, protocolResult]);
     },
 
     resume: function()
     {
-        DebuggerAgent.resume();
+        if (!this._paused)
+            return Promise.resolve();
+
+        var listener = new WebInspector.EventListener(this, true);
+
+        var managerResult = new Promise(function(resolve, reject) {
+            listener.connect(WebInspector.debuggerManager, WebInspector.DebuggerManager.Event.Resumed, resolve);
+        });
+
+        var protocolResult = DebuggerAgent.resume()
+            .catch(function(error) {
+                listener.disconnect();
+                console.error("DebuggerManager.resume failed: ", error);
+                throw error;
+            });
+
+        return Promise.all([managerResult, protocolResult]);
     },
 
     stepOver: function()
     {
-        DebuggerAgent.stepOver();
+        if (!this._paused)
+            return Promise.reject(new Error("Cannot step over because debugger is not paused."));
+
+        var listener = new WebInspector.EventListener(this, true);
+
+        var managerResult = new Promise(function(resolve, reject) {
+            listener.connect(WebInspector.debuggerManager, WebInspector.DebuggerManager.Event.ActiveCallFrameDidChange, resolve);
+        });
+
+        var protocolResult = DebuggerAgent.stepOver()
+            .catch(function(error) {
+                listener.disconnect();
+                console.error("DebuggerManager.stepOver failed: ", error);
+                throw error;
+            });
+
+        return Promise.all([managerResult, protocolResult]);
     },
 
     stepInto: function()
     {
-        DebuggerAgent.stepInto();
+        if (!this._paused)
+            return Promise.reject(new Error("Cannot step into because debugger is not paused."));
+
+        var listener = new WebInspector.EventListener(this, true);
+
+        var managerResult = new Promise(function(resolve, reject) {
+            listener.connect(WebInspector.debuggerManager, WebInspector.DebuggerManager.Event.ActiveCallFrameDidChange, resolve);
+        });
+
+        var protocolResult = DebuggerAgent.stepInto()
+            .catch(function(error) {
+                listener.disconnect();
+                console.error("DebuggerManager.stepInto failed: ", error);
+                throw error;
+            });
+
+        return Promise.all([managerResult, protocolResult]);
     },
 
     stepOut: function()
     {
-        DebuggerAgent.stepOut();
+        if (!this._paused)
+            return Promise.reject(new Error("Cannot step out because debugger is not paused."));
+
+        var listener = new WebInspector.EventListener(this, true);
+
+        var managerResult = new Promise(function(resolve, reject) {
+            listener.connect(WebInspector.debuggerManager, WebInspector.DebuggerManager.Event.ActiveCallFrameDidChange, resolve);
+        });
+
+        var protocolResult = DebuggerAgent.stepOut()
+            .catch(function(error) {
+                listener.disconnect();
+                console.error("DebuggerManager.stepOut failed: ", error);
+                throw error;
+            });
+
+        return Promise.all([managerResult, protocolResult]);
     },
 
     get allExceptionsBreakpoint()
index a1c0299..46c0505 100644 (file)
@@ -675,11 +675,8 @@ WebInspector.ReplayManager.prototype = {
         return new Promise(function(resolve, reject) {
             manager._breakpointsWereSuppressed = WebInspector.debuggerManager.breakpointsEnabled;
             WebInspector.debuggerManager.breakpointsEnabled = false;
-            if (!WebInspector.debuggerManager.paused)
-                return resolve();
 
-            WebInspector.debuggerManager.resume();
-            WebInspector.debuggerManager.addSingleFireEventListener(WebInspector.DebuggerManager.Event.Resumed, resolve);
+            return WebInspector.debuggerManager.resume();
         });
     }
 };