Bug 1437435 - adding comments to isBase64 method, cleaning up whitespace and unnecessary code. r=Honza. draft
authorjason.valenzuela <jev4zs@virginia.edu>
Fri, 02 Mar 2018 08:15:56 -0500
changeset 762483 d44523779c79391d49d0ea2cadad3be7ccb84a32
parent 762067 3cd3ee51b77bceaaf409477e13046c4ca7f82c2f
child 762507 adcc614f5bfbdf9b43a7f71af21e15d5230a9815
push id101175
push userbmo:jev4zs@virginia.edu
push dateFri, 02 Mar 2018 13:18:35 +0000
reviewersHonza
bugs1437435
milestone60.0a1
Bug 1437435 - adding comments to isBase64 method, cleaning up whitespace and unnecessary code. r=Honza. MozReview-Commit-ID: HETtcTqyQpT
devtools/client/netmonitor/src/components/ResponsePanel.js
--- a/devtools/client/netmonitor/src/components/ResponsePanel.js
+++ b/devtools/client/netmonitor/src/components/ResponsePanel.js
@@ -49,18 +49,16 @@ class ResponsePanel extends Component {
     this.state = {
       imageDimensions: {
         width: 0,
         height: 0,
       },
     };
 
     this.updateImageDimemsions = this.updateImageDimemsions.bind(this);
-    this.isBase64 = this.isBase64.bind(this);
-    this.isJSON = this.isJSON.bind(this);
   }
 
   componentDidMount() {
     let { request, connector } = this.props;
     fetchNetworkUpdatePacket(connector.requestData, request, ["responseContent"]);
   }
 
   componentWillReceiveProps(nextProps) {
@@ -71,21 +69,24 @@ class ResponsePanel extends Component {
   updateImageDimemsions({ target }) {
     this.setState({
       imageDimensions: {
         width: target.naturalWidth,
         height: target.naturalHeight,
       },
     });
   }
-
+  // Takes the response passed to the isJSON method by decoding and encoding
+  // it to base 64. The final string is compared with the original response,
+  // and returns true if the strings are the same. If the responses are not
+  // the same, or an error is thrown, the method will return false.
   isBase64(response) {
     try {
       return btoa(atob(response)) == response;
-    } catch(err) {
+    } catch (err) {
       return false;
     }
   }
 
   // Handle json, which we tentatively identify by checking the MIME type
   // for "json" after any word boundary. This works for the standard
   // "application/json", and also for custom types like "x-bigcorp-json".
   // Additionally, we also directly parse the response text content to
@@ -94,17 +95,17 @@ class ResponsePanel extends Component {
   isJSON(mimeType, response) {
     let json, error;
     try {
       json = JSON.parse(response);
     } catch (err) {
       try {
         if (this.isBase64(response)) {
           json = JSON.parse(atob(response));
-        } 
+        }
       } catch (err64) {
         error = err;
       }
     }
 
     if (/\bjson/.test(mimeType) || json) {
       // Extract the actual json substring in case this might be a "JSONP".
       // This regex basically parses a function call and captures the