Title: [132588] trunk/Source/WebCore
Revision
132588
Author
[email protected]
Date
2012-10-26 02:06:34 -0700 (Fri, 26 Oct 2012)

Log Message

Web Inspector: Doctype Audits panel code
https://bugs.webkit.org/show_bug.cgi?id=100371

Patch by Eugene Klyuchnikov <[email protected]> on 2012-10-26
Reviewed by Alexander Pavlov.

This is a preparation step for ongoing refactoring.
It is much easier to read doctyped code.

* inspector/front-end/AuditRules.js:
(WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype.doRun):
Replaced "undefined" with "null"
* inspector/front-end/AuditsPanel.js:
(WebInspector.AuditCategory.prototype.callbackWrapper):
Removed callback parameter indirection.
(WebInspector.AuditRuleResult.prototype.addFormatted):
Converted private instance function to scoped function.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (132587 => 132588)


--- trunk/Source/WebCore/ChangeLog	2012-10-26 09:01:17 UTC (rev 132587)
+++ trunk/Source/WebCore/ChangeLog	2012-10-26 09:06:34 UTC (rev 132588)
@@ -1,3 +1,22 @@
+2012-10-26  Eugene Klyuchnikov  <[email protected]>
+
+        Web Inspector: Doctype Audits panel code
+        https://bugs.webkit.org/show_bug.cgi?id=100371
+
+        Reviewed by Alexander Pavlov.
+
+        This is a preparation step for ongoing refactoring.
+        It is much easier to read doctyped code.
+
+        * inspector/front-end/AuditRules.js:
+        (WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype.doRun):
+        Replaced "undefined" with "null"
+        * inspector/front-end/AuditsPanel.js:
+        (WebInspector.AuditCategory.prototype.callbackWrapper):
+        Removed callback parameter indirection.        
+        (WebInspector.AuditRuleResult.prototype.addFormatted):
+        Converted private instance function to scoped function.
+
 2012-10-26  János Badics  <[email protected]>
 
         [Qt]REGRESSION(r131428): cookies.db created on wrong place

Modified: trunk/Source/WebCore/inspector/front-end/AuditLauncherView.js (132587 => 132588)


--- trunk/Source/WebCore/inspector/front-end/AuditLauncherView.js	2012-10-26 09:01:17 UTC (rev 132587)
+++ trunk/Source/WebCore/inspector/front-end/AuditLauncherView.js	2012-10-26 09:06:34 UTC (rev 132588)
@@ -89,6 +89,9 @@
         this._updateResourceProgress();
     },
 
+    /**
+     * @param {!WebInspector.AuditCategory} category
+     */
     addCategory: function(category)
     {
         if (!this._sortedCategories.length)
@@ -113,6 +116,9 @@
         this._updateButton();
     },
 
+    /**
+     * @param {boolean} auditRunning
+     */
     _setAuditRunning: function(auditRunning)
     {
         if (this._auditRunning === auditRunning)
@@ -158,6 +164,9 @@
         this._setAuditRunning(!this._auditRunning);
     },
 
+    /**
+     * @param {boolean} checkCategories
+     */
     _selectAllClicked: function(checkCategories)
     {
         var childNodes = this._categoriesElement.childNodes;
@@ -174,6 +183,10 @@
         this._updateButton();
     },
 
+    /**
+     * @param {string} title
+     * @param {string} id
+     */
     _createCategoryElement: function(title, id)
     {
         var labelElement = document.createElement("label");

Modified: trunk/Source/WebCore/inspector/front-end/AuditResultView.js (132587 => 132588)


--- trunk/Source/WebCore/inspector/front-end/AuditResultView.js	2012-10-26 09:01:17 UTC (rev 132587)
+++ trunk/Source/WebCore/inspector/front-end/AuditResultView.js	2012-10-26 09:06:34 UTC (rev 132588)
@@ -31,6 +31,7 @@
 /**
  * @constructor
  * @extends {WebInspector.View}
+ * @param {!Array.<!WebInspector.AuditCategoryResult>} categoryResults
  */
 WebInspector.AuditResultView = function(categoryResults)
 {
@@ -52,6 +53,7 @@
 /**
  * @constructor
  * @extends {WebInspector.SidebarPane}
+ * @param {!WebInspector.AuditCategoryResult} categoryResult
  */
 WebInspector.AuditCategoryResultPane = function(categoryResult)
 {
@@ -88,6 +90,10 @@
 }
 
 WebInspector.AuditCategoryResultPane.prototype = {
+    /**
+     * @param {(TreeOutline|TreeElement)} parentTreeElement
+     * @param {!WebInspector.AuditCategoryResult} result
+     */
     _appendResult: function(parentTreeElement, result)
     {
         var title = "";

Modified: trunk/Source/WebCore/inspector/front-end/AuditRules.js (132587 => 132588)


--- trunk/Source/WebCore/inspector/front-end/AuditRules.js	2012-10-26 09:01:17 UTC (rev 132587)
+++ trunk/Source/WebCore/inspector/front-end/AuditRules.js	2012-10-26 09:06:34 UTC (rev 132588)
@@ -42,6 +42,12 @@
     304: true // Underlying request is cacheable
 }
 
+/**
+ * @param {!Array.<!WebInspector.NetworkRequest>} requests
+ * @param {Array.<!WebInspector.resourceTypes>} types
+ * @param {boolean} needFullResources
+ * @return {(Object.<string, !Array.<!WebInspector.NetworkRequest>>|Object.<string, !Array.<string>>)}
+ */
 WebInspector.AuditRules.getDomainToResourcesMap = function(requests, types, needFullResources)
 {
     var domainToResourcesMap = {};
@@ -74,10 +80,10 @@
 
 WebInspector.AuditRules.GzipRule.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {
@@ -139,10 +145,10 @@
 
 WebInspector.AuditRules.CombineExternalResourcesRule.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {
@@ -204,15 +210,15 @@
 
 WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {
         var summary = result.addChild("");
-        var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(requests, undefined, false);
+        var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(requests, null, false);
         for (var domain in domainToResourcesMap) {
             if (domainToResourcesMap[domain].length > 1)
                 continue;
@@ -248,10 +254,10 @@
 
 WebInspector.AuditRules.ParallelizeDownloadRule.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {
@@ -323,10 +329,10 @@
 
 WebInspector.AuditRules.UnusedCssRule.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {
@@ -475,10 +481,10 @@
 
 WebInspector.AuditRules.CacheControlRule.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {
@@ -728,10 +734,10 @@
 
 WebInspector.AuditRules.ImageDimensionsRule.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {
@@ -860,10 +866,10 @@
 
 WebInspector.AuditRules.CssInHeadRule.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {
@@ -950,10 +956,10 @@
 
 WebInspector.AuditRules.StylesScriptsOrderRule.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {
@@ -1038,10 +1044,10 @@
 
 WebInspector.AuditRules.CSSRuleBase.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {
@@ -1205,10 +1211,10 @@
 
 WebInspector.AuditRules.CookieRuleBase.prototype = {
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
-     * @param {WebInspector.AuditRuleResult} result
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
+     * @param {!WebInspector.AuditRuleResult} result
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     doRun: function(requests, result, callback, progress)
     {

Modified: trunk/Source/WebCore/inspector/front-end/AuditsPanel.js (132587 => 132588)


--- trunk/Source/WebCore/inspector/front-end/AuditsPanel.js	2012-10-26 09:01:17 UTC (rev 132587)
+++ trunk/Source/WebCore/inspector/front-end/AuditsPanel.js	2012-10-26 09:06:34 UTC (rev 132588)
@@ -70,17 +70,27 @@
         return [this.clearResultsButton.element];
     },
 
+    /**
+     * @return {!Object.<string, !WebInspector.AuditCategory>}
+     */
     get categoriesById()
     {
         return this._auditCategoriesById;
     },
 
+    /**
+     * @param {!WebInspector.AuditCategory} category
+     */
     addCategory: function(category)
     {
         this.categoriesById[category.id] = category;
         this._launcherView.addCategory(category);
     },
 
+    /**
+     * @param {string} id
+     * @return {WebInspector.AuditCategory}
+     */
     getCategory: function(id)
     {
         return this.categoriesById[id];
@@ -96,6 +106,10 @@
         }
     },
 
+    /**
+     * @param {!Array.<!WebInspector.AuditCategory>} categories
+     * @param {function(string, !Array.<!WebInspector.AuditCategoryResult>)} resultCallback
+     */
     _executeAudit: function(categories, resultCallback)
     {
         this._progress.setTitle(WebInspector.UIString("Running audit"));
@@ -133,6 +147,11 @@
         }
     },
 
+    /**
+     * @param {function()} launcherCallback
+     * @param {string} mainResourceURL
+     * @param {!Array.<!WebInspector.AuditCategoryResult>} results
+     */
     _auditFinishedCallback: function(launcherCallback, mainResourceURL, results)
     {
         var children = this.auditResultsTreeElement.children;
@@ -196,6 +215,9 @@
         }
     },
 
+    /**
+     * @param {!Array.<!WebInspector.AuditCategoryResult>} categoryResults
+     */
     showResults: function(categoryResults)
     {
         if (!categoryResults._resultView)
@@ -246,6 +268,7 @@
 
 /**
  * @constructor
+ * @param {string} displayName
  */
 WebInspector.AuditCategory = function(displayName)
 {
@@ -254,17 +277,27 @@
 }
 
 WebInspector.AuditCategory.prototype = {
+    /**
+     * @return {string}
+     */
     get id()
     {
         // this._id value is injected at construction time.
         return this._id;
     },
 
+    /**
+     * @return {string}
+     */
     get displayName()
     {
         return this._displayName;
     },
 
+    /**
+     * @param {!WebInspector.AuditRule} rule
+     * @param {!WebInspector.AuditRule.Severity} severity
+     */
     addRule: function(rule, severity)
     {
         rule.severity = severity;
@@ -272,19 +305,19 @@
     },
 
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
      * @param {function(WebInspector.AuditRuleResult)} ruleResultCallback
      * @param {function()} categoryDoneCallback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     run: function(requests, ruleResultCallback, categoryDoneCallback, progress)
     {
         this._ensureInitialized();
         var remainingRulesCount = this._rules.length;
         progress.setTotalWork(remainingRulesCount);
-        function callbackWrapper()
+        function callbackWrapper(result)
         {
-            ruleResultCallback.apply(this, arguments);
+            ruleResultCallback(result);
             progress.worked();
             if (!--remainingRulesCount)
                 categoryDoneCallback();
@@ -305,6 +338,8 @@
 
 /**
  * @constructor
+ * @param {string} id
+ * @param {string} displayName
  */
 WebInspector.AuditRule = function(id, displayName)
 {
@@ -312,12 +347,18 @@
     this._displayName = displayName;
 }
 
+/**
+ * @enum {string}
+ */
 WebInspector.AuditRule.Severity = {
     Info: "info",
     Warning: "warning",
     Severe: "severe"
 }
 
+/**
+ * @type {Object.<WebInspector.AuditRule.Severity, number>}
+ */
 WebInspector.AuditRule.SeverityOrder = {
     "info": 3,
     "warning": 2,
@@ -335,15 +376,18 @@
         return this._displayName;
     },
 
+    /**
+     * @param {WebInspector.AuditRule.Severity} severity
+     */
     set severity(severity)
     {
         this._severity = severity;
     },
 
     /**
-     * @param {Array.<WebInspector.NetworkRequest>} requests
+     * @param {!Array.<!WebInspector.NetworkRequest>} requests
      * @param {function(WebInspector.AuditRuleResult)} callback
-     * @param {WebInspector.Progress} progress
+     * @param {!WebInspector.Progress} progress
      */
     run: function(requests, callback, progress)
     {
@@ -369,6 +413,7 @@
 
 /**
  * @constructor
+ * @param {!WebInspector.AuditCategory} category
  */
 WebInspector.AuditCategoryResult = function(category)
 {
@@ -377,6 +422,9 @@
 }
 
 WebInspector.AuditCategoryResult.prototype = {
+    /**
+     * @param {!WebInspector.AuditCategoryResult} ruleResult
+     */
     addRuleResult: function(ruleResult)
     {
         this.ruleResults.push(ruleResult);
@@ -385,6 +433,7 @@
 
 /**
  * @constructor
+ * @param {(string|boolean|number|Object)} value
  * @param {boolean=} expanded
  * @param {string=} className
  */
@@ -402,6 +451,10 @@
         this._formatters[standardFormatters[i]] = String.standardFormatters[standardFormatters[i]];
 }
 
+/**
+ * @param {string} url
+ * @return {!Element}
+ */
 WebInspector.AuditRuleResult.linkifyDisplayName = function(url)
 {
     return WebInspector.linkifyURLAsNode(url, WebInspector.displayNameForURL(url));
@@ -414,8 +467,10 @@
 
 WebInspector.AuditRuleResult.prototype = {
     /**
+     * @param {(string|boolean|number|Object)} value
      * @param {boolean=} expanded
      * @param {string=} className
+     * @return {!WebInspector.AuditRuleResult}
      */
     addChild: function(value, expanded, className)
     {
@@ -426,43 +481,53 @@
         return entry;
     },
 
+    /**
+     * @param {string} url
+     */
     addURL: function(url)
     {
-        return this.addChild(WebInspector.AuditRuleResult.linkifyDisplayName(url));
+        this.addChild(WebInspector.AuditRuleResult.linkifyDisplayName(url));
     },
 
+    /**
+     * @param {!Array.<string>} urls
+     */
     addURLs: function(urls)
     {
         for (var i = 0; i < urls.length; ++i)
             this.addURL(urls[i]);
     },
 
+    /**
+     * @param {string} snippet
+     */
     addSnippet: function(snippet)
     {
-        return this.addChild(snippet, false, "source-code");
+        this.addChild(snippet, false, "source-code");
     },
 
     /**
      * @param {string} format
      * @param {...*} vararg
+     * @return {!WebInspector.AuditRuleResult}
      */
     addFormatted: function(format, vararg)
     {
         var substitutions = Array.prototype.slice.call(arguments, 1);
         var fragment = document.createDocumentFragment();
 
-        var formattedResult = String.format(format, substitutions, this._formatters, fragment, this._append).formattedResult;
+        function append(a, b)
+        {
+            if (!(b instanceof Node))
+                b = document.createTextNode(b);
+            a.appendChild(b);
+            return a;
+        }
+
+        var formattedResult = String.format(format, substitutions, this._formatters, fragment, append).formattedResult;
         if (formattedResult instanceof Node)
             formattedResult.normalize();
         return this.addChild(formattedResult);
-    },
-
-    _append: function(a, b)
-    {
-        if (!(b instanceof Node))
-            b = document.createTextNode(b);
-        a.appendChild(b);
-        return a;
     }
 }
 
@@ -505,7 +570,10 @@
 /**
  * @constructor
  * @extends {WebInspector.SidebarTreeElement}
- * @param {WebInspector.AuditsPanel} panel
+ * @param {!WebInspector.AuditsPanel} panel
+ * @param {!Array.<!WebInspector.AuditCategoryResult>} results
+ * @param {string} mainResourceURL
+ * @param {number} ordinal
  */
 WebInspector.AuditResultSidebarTreeElement = function(panel, results, mainResourceURL, ordinal)
 {
@@ -532,7 +600,10 @@
 // Contributed audit rules should go into this namespace.
 WebInspector.AuditRules = {};
 
-// Contributed audit categories should go into this namespace.
+/**
+ * Contributed audit categories should go into this namespace.
+ * @type {Object.<string, function(new:WebInspector.AuditCategory)>}
+ */
 WebInspector.AuditCategories = {};
 
 importScript("AuditCategories.js");

Modified: trunk/Source/WebCore/inspector/front-end/ResourceType.js (132587 => 132588)


--- trunk/Source/WebCore/inspector/front-end/ResourceType.js	2012-10-26 09:01:17 UTC (rev 132587)
+++ trunk/Source/WebCore/inspector/front-end/ResourceType.js	2012-10-26 09:06:34 UTC (rev 132588)
@@ -108,7 +108,10 @@
     }
 }
 
-//Keep these in sync with WebCore::InspectorPageAgent::resourceTypeJson
+/**
+ * Keep these in sync with WebCore::InspectorPageAgent::resourceTypeJson
+ * @enum {!WebInspector.ResourceType}
+ */
 WebInspector.resourceTypes = {
     Document: new WebInspector.ResourceType("document", "Document", "Documents", "rgb(47,102,236)", true),
     Stylesheet: new WebInspector.ResourceType("stylesheet", "Stylesheet", "Stylesheets", "rgb(157,231,119)", true),

Modified: trunk/Source/WebCore/inspector/front-end/ResourceUtils.js (132587 => 132588)


--- trunk/Source/WebCore/inspector/front-end/ResourceUtils.js	2012-10-26 09:01:17 UTC (rev 132587)
+++ trunk/Source/WebCore/inspector/front-end/ResourceUtils.js	2012-10-26 09:06:34 UTC (rev 132588)
@@ -165,7 +165,7 @@
  * @param {string=} classes
  * @param {boolean=} isExternal
  * @param {string=} tooltipText
- * @return {Element}
+ * @return {!Element}
  */
 WebInspector.linkifyURLAsNode = function(url, linkText, classes, isExternal, tooltipText)
 {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to