Bug 1548098 - Pull out exception handling into a dedicated _returnError method. r=remote-protocol-reviewers,ato
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 13 May 2019 16:10:43 +0000
changeset 535512 e8a4f66d71d84aa624af0c19a3fe9b87f4891a73
parent 535511 38242d8c9a083f03649a4a0cfc6d4fd42b164f2f
child 535513 a0cb021737218a16e04aa0fced67284010f50118
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersremote-protocol-reviewers, ato
bugs1548098
milestone68.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 1548098 - Pull out exception handling into a dedicated _returnError method. r=remote-protocol-reviewers,ato This will be used in the next changeset. Differential Revision: https://phabricator.services.mozilla.com/D30263
remote/domains/content/runtime/ExecutionContext.jsm
--- a/remote/domains/content/runtime/ExecutionContext.jsm
+++ b/remote/domains/content/runtime/ExecutionContext.jsm
@@ -54,31 +54,44 @@ class ExecutionContext {
     if (!rv) {
       return {
         exceptionDetails: {
           text: "Evaluation terminated!",
         },
       };
     }
     if (rv.throw) {
-      if (this._debuggee.executeInGlobalWithBindings("e instanceof Error", {e: rv.throw}).return) {
-        return {
-          exceptionDetails: {
-            text: this._debuggee.executeInGlobalWithBindings("e.message", {e: rv.throw}).return,
-          },
-        };
-      }
+      return this._returnError(rv.throw);
+    }
+    return {
+      result: this._createRemoteObject(rv.return),
+    };
+  }
+
+  /**
+   * Given a Debugger.Object reference for an Exception, return a JSON object
+   * describing the exception by following CDP ExceptionDetails specification.
+   */
+  _returnError(exception) {
+    if (this._debuggee.executeInGlobalWithBindings("exception instanceof Error",
+      {exception}).return) {
+      const text = this._debuggee.executeInGlobalWithBindings("exception.message",
+        {exception}).return;
       return {
         exceptionDetails: {
-          exception: this._createRemoteObject(rv.throw),
+          text,
         },
       };
     }
+
+    // If that isn't an Error, consider the exception as a JS value
     return {
-      result: this._createRemoteObject(rv.return),
+      exceptionDetails: {
+        exception: this._toRemoteObject(exception),
+      },
     };
   }
 
   /**
    * Convert a given `Debugger.Object` to a JSON string.
    *
    * @param {Debugger.Object} obj
    *  The object to convert