Changeset 146900 in webkit


Ignore:
Timestamp:
Mar 26, 2013 10:09:46 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: refactor code duplication: WebInspector.ObjectPropertyTreeElement.wrapPropertyAsElements
https://bugs.webkit.org/show_bug.cgi?id=113211

Patch by Peter Rybin <prybin@chromium.org> on 2013-03-26
Reviewed by Yury Semikhatsky.

A new method WebInspector.ObjectPropertyTreeElement.wrapPropertyAsElements is added and used
from 2 sites.

  • inspector/front-end/ObjectPropertiesSection.js:

(WebInspector.ObjectPropertiesSection.prototype.update.callback):
(WebInspector.ObjectPropertiesSection.prototype.update):
(WebInspector.ObjectPropertiesSection.prototype.updateProperties):
(.callback):
(WebInspector.ObjectPropertyTreeElement.populate):
(WebInspector.ObjectPropertyTreeElement.wrapPropertyAsElements):

  • inspector/front-end/WatchExpressionsSidebarPane.js:

(WebInspector.WatchExpressionsSection.prototype.update.appendResult):
(WebInspector.WatchExpressionsSection.prototype.update):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r146899 r146900  
     12013-03-26  Peter Rybin  <prybin@chromium.org>
     2
     3        Web Inspector: refactor code duplication: WebInspector.ObjectPropertyTreeElement.wrapPropertyAsElements
     4        https://bugs.webkit.org/show_bug.cgi?id=113211
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        A new method WebInspector.ObjectPropertyTreeElement.wrapPropertyAsElements is added and used
     9        from 2 sites.
     10
     11        * inspector/front-end/ObjectPropertiesSection.js:
     12        (WebInspector.ObjectPropertiesSection.prototype.update.callback):
     13        (WebInspector.ObjectPropertiesSection.prototype.update):
     14        (WebInspector.ObjectPropertiesSection.prototype.updateProperties):
     15        (.callback):
     16        (WebInspector.ObjectPropertyTreeElement.populate):
     17        (WebInspector.ObjectPropertyTreeElement.wrapPropertyAsElements):
     18        * inspector/front-end/WatchExpressionsSidebarPane.js:
     19        (WebInspector.WatchExpressionsSection.prototype.update.appendResult):
     20        (WebInspector.WatchExpressionsSection.prototype.update):
     21
    1222013-03-26  Christophe Dumez  <ch.dumez@sisa.samsung.com>
    223
  • trunk/Source/WebCore/inspector/front-end/ObjectPropertiesSection.js

    r146759 r146900  
    8585            if (!properties)
    8686                return;
    87             this.updateProperties(properties);
     87            this.updateProperties(properties, internalProperties);
    8888        }
    8989
     
    9494    },
    9595
    96     updateProperties: function(properties, rootTreeElementConstructor, rootPropertyComparer)
     96    updateProperties: function(properties, internalProperties, rootTreeElementConstructor, rootPropertyComparer)
    9797    {
    9898        if (!rootTreeElementConstructor)
     
    102102            rootPropertyComparer = WebInspector.ObjectPropertiesSection.CompareProperties;
    103103
    104         if (this.extraProperties)
     104        if (this.extraProperties) {
    105105            for (var i = 0; i < this.extraProperties.length; ++i)
    106106                properties.push(this.extraProperties[i]);
    107 
    108         properties.sort(rootPropertyComparer);
     107        }
    109108
    110109        this.propertiesTreeOutline.removeChildren();
    111110
    112         for (var i = 0; i < properties.length; ++i) {
    113             if (this.skipProto && properties[i].name === "__proto__")
    114                 continue;
    115             properties[i].parentObject = this.object;
    116         }
    117 
     111        WebInspector.ObjectPropertyTreeElement.populateWithProperties(this.propertiesTreeOutline,
     112            properties, internalProperties,
     113            rootTreeElementConstructor, rootPropertyComparer,
     114            this.skipProto, this.object);
     115           
    118116        this.propertiesForTest = properties;
    119 
    120         for (var i = 0; i < properties.length; ++i)
    121             this.propertiesTreeOutline.appendChild(new rootTreeElementConstructor(properties[i]));
    122117
    123118        if (!this.propertiesTreeOutline.children.length) {
     
    457452        if (!properties)
    458453            return;
    459 
    460         properties.sort(WebInspector.ObjectPropertiesSection.CompareProperties);
    461         for (var i = 0; i < properties.length; ++i) {
    462             if (treeElement.treeOutline.section.skipProto && properties[i].name === "__proto__")
    463                 continue;
    464             properties[i].parentObject = value;
    465             treeElement.appendChild(new treeElement.treeOutline.section.treeElementConstructor(properties[i]));
    466         }
    467         if (value.type === "function") {
    468             // Whether function has TargetFunction internal property.
    469             // This is a simple way to tell that the function is actually a bound function (we are not told).
    470             // Bound function never has inner scope and doesn't need corresponding UI node.   
    471             var hasTargetFunction = false;
    472 
    473             if (internalProperties) {
    474                 for (var i = 0; i < internalProperties.length; i++) {
    475                     if (internalProperties[i].name == "[[TargetFunction]]") {
    476                         hasTargetFunction = true;
    477                         break;
    478                     }
    479                 }
    480             }
    481             if (!hasTargetFunction)
    482                 treeElement.appendChild(new WebInspector.FunctionScopeMainTreeElement(value));
    483         }
     454        if (!internalProperties)
     455            internalProperties = [];
     456
     457        WebInspector.ObjectPropertyTreeElement.populateWithProperties(treeElement, properties, internalProperties,
     458            treeElement.treeOutline.section.treeElementConstructor, WebInspector.ObjectPropertiesSection.CompareProperties,
     459            treeElement.treeOutline.section.skipProto, value);
     460    }
     461
     462    value.getOwnProperties(callback);
     463}
     464
     465/**
     466 * @param {!TreeElement|!TreeOutline} treeElement
     467 * @param {Array.<!WebInspector.RemoteObjectProperty>} properties
     468 * @param {?Array.<!WebInspector.RemoteObjectProperty>} internalProperties
     469 * @param {function(new:TreeElement, WebInspector.RemoteObjectProperty)} treeElementConstructor
     470 * @param {function (WebInspector.RemoteObjectProperty, WebInspector.RemoteObjectProperty): number} comparator
     471 * @param {boolean} skipProto
     472 * @param {?WebInspector.RemoteObject} value
     473 */
     474WebInspector.ObjectPropertyTreeElement.populateWithProperties = function(treeElement, properties, internalProperties, treeElementConstructor, comparator, skipProto, value) {
     475    properties.sort(comparator);
     476   
     477    for (var i = 0; i < properties.length; ++i) {
     478        if (skipProto && properties[i].name === "__proto__")
     479            continue;
     480        properties[i].parentObject = value;
     481        treeElement.appendChild(new treeElementConstructor(properties[i]));
     482    }
     483    if (value && value.type === "function") {
     484        // Whether function has TargetFunction internal property.
     485        // This is a simple way to tell that the function is actually a bound function (we are not told).
     486        // Bound function never has inner scope and doesn't need corresponding UI node.   
     487        var hasTargetFunction = false;
     488
    484489        if (internalProperties) {
    485490            for (var i = 0; i < internalProperties.length; i++) {
    486                 internalProperties[i].parentObject = value;
    487                 treeElement.appendChild(new treeElement.treeOutline.section.treeElementConstructor(internalProperties[i]));
    488             }
    489         }
    490     }
    491 
    492     value.getOwnProperties(callback);
     491                if (internalProperties[i].name == "[[TargetFunction]]") {
     492                    hasTargetFunction = true;
     493                    break;
     494                }
     495            }
     496        }
     497        if (!hasTargetFunction)
     498            treeElement.appendChild(new WebInspector.FunctionScopeMainTreeElement(value));
     499    }
     500    if (internalProperties) {
     501        for (var i = 0; i < internalProperties.length; i++) {
     502            internalProperties[i].parentObject = value;
     503            treeElement.appendChild(new treeElementConstructor(internalProperties[i]));
     504        }
     505    }
    493506}
    494507
  • trunk/Source/WebCore/inspector/front-end/WatchExpressionsSidebarPane.js

    r146220 r146900  
    161161
    162162            if (properties.length == propertyCount) {
    163                 this.updateProperties(properties, WebInspector.WatchExpressionTreeElement, WebInspector.WatchExpressionsSection.CompareProperties);
     163                this.updateProperties(properties, [], WebInspector.WatchExpressionTreeElement, WebInspector.WatchExpressionsSection.CompareProperties);
    164164
    165165                // check to see if we just added a new watch expression,
Note: See TracChangeset for help on using the changeset viewer.