Changeset 124876 in webkit


Ignore:
Timestamp:
Aug 7, 2012 4:28:24 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: display function scope in UI
https://bugs.webkit.org/show_bug.cgi?id=90631

Patch by Peter Rybin <peter.rybin@gmail.com> on 2012-08-07
Reviewed by Yury Semikhatsky.

Two new tree element types added: function scope group node and scope node.
Scope node is only used to represent closure and catch scopes. Scopes that
have a real object beneath are represented as a property node.
A method that reads properties from RemoteObject and populate tree element
is factored out from RemoteObjectTreeElement for reuse.

  • inspector/front-end/ObjectPropertiesSection.js:

(WebInspector.ObjectPropertyTreeElement.prototype.onpopulate):
(WebInspector.ObjectPropertyTreeElement.Populate.callback):
(WebInspector.ObjectPropertyTreeElement.Populate):
(WebInspector.FunctionScopeMainTreeElement):
(WebInspector.FunctionScopeMainTreeElement.prototype.onpopulate.didGetDetails):
(WebInspector.FunctionScopeMainTreeElement.prototype.onpopulate):
(WebInspector.FunctionScopeMainTreeElement.prototype.onattach):
(WebInspector.FunctionScopeMainTreeElement.prototype.update):
(WebInspector.ScopeTreeElement):
(WebInspector.ScopeTreeElement.prototype.onpopulate):
(WebInspector.ScopeTreeElement.prototype.onattach):
(WebInspector.ScopeTreeElement.prototype.update):

  • inspector/front-end/RemoteObject.js:

(WebInspector.RemoteObjectProperty.fromScopeValue):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r124872 r124876  
     12012-08-07  Peter Rybin  <peter.rybin@gmail.com>
     2
     3        Web Inspector: display function scope in UI
     4        https://bugs.webkit.org/show_bug.cgi?id=90631
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        Two new tree element types added: function scope group node and scope node.
     9        Scope node is only used to represent closure and catch scopes. Scopes that
     10        have a real object beneath are represented as a property node.
     11        A method that reads properties from RemoteObject and populate tree element
     12        is factored out from RemoteObjectTreeElement for reuse.
     13
     14        * inspector/front-end/ObjectPropertiesSection.js:
     15        (WebInspector.ObjectPropertyTreeElement.prototype.onpopulate):
     16        (WebInspector.ObjectPropertyTreeElement.Populate.callback):
     17        (WebInspector.ObjectPropertyTreeElement.Populate):
     18        (WebInspector.FunctionScopeMainTreeElement):
     19        (WebInspector.FunctionScopeMainTreeElement.prototype.onpopulate.didGetDetails):
     20        (WebInspector.FunctionScopeMainTreeElement.prototype.onpopulate):
     21        (WebInspector.FunctionScopeMainTreeElement.prototype.onattach):
     22        (WebInspector.FunctionScopeMainTreeElement.prototype.update):
     23        (WebInspector.ScopeTreeElement):
     24        (WebInspector.ScopeTreeElement.prototype.onpopulate):
     25        (WebInspector.ScopeTreeElement.prototype.onattach):
     26        (WebInspector.ScopeTreeElement.prototype.update):
     27        * inspector/front-end/RemoteObject.js:
     28        (WebInspector.RemoteObjectProperty.fromScopeValue):
     29
     30
    1312012-08-07  Vineet Chaudhary  <rgf748@motorola.com>
    232
  • trunk/Source/WebCore/inspector/front-end/ObjectPropertiesSection.js

    r123616 r124876  
    227227    onpopulate: function()
    228228    {
    229         if (this.children.length && !this.shouldRefreshChildren)
    230             return;
    231 
    232         if (this.property.value.arrayLength() > WebInspector.ObjectPropertiesSection._arrayLoadThreshold) {
    233             this.removeChildren();
    234             WebInspector.ArrayGroupingTreeElement._populateArray(this, this.property.value, 0, this.property.value.arrayLength() - 1);
    235             return;
    236         }
    237 
    238         function callback(properties)
    239         {
    240             this.removeChildren();
    241             if (!properties)
    242                 return;
    243 
    244             properties.sort(WebInspector.ObjectPropertiesSection.CompareProperties);
    245             for (var i = 0; i < properties.length; ++i) {
    246                 if (this.treeOutline.section.skipProto && properties[i].name === "__proto__")
    247                     continue;
    248                 properties[i].parentObject = this.property.value;
    249                 this.appendChild(new this.treeOutline.section.treeElementConstructor(properties[i]));
    250             }
    251         }
    252 
    253         this.property.value.getOwnProperties(callback.bind(this));
     229        return WebInspector.ObjectPropertyTreeElement.populate(this, this.property.value);
    254230    },
    255231
     
    306282
    307283        this.valueElement.title = description || "";
    308        
     284
    309285        this.listItemElement.removeChildren();
    310286
     
    469445}
    470446
     447/**
     448 * @param {TreeElement} treeElement
     449 * @param {WebInspector.RemoteObject} value
     450 */
     451WebInspector.ObjectPropertyTreeElement.populate = function(treeElement, value) {
     452    if (treeElement.children.length && !treeElement.shouldRefreshChildren)
     453        return;
     454
     455    if (value.arrayLength() > WebInspector.ObjectPropertiesSection._arrayLoadThreshold) {
     456        treeElement.removeChildren();
     457        WebInspector.ArrayGroupingTreeElement._populateArray(treeElement, value, 0, value.arrayLength() - 1);
     458        return;
     459    }
     460
     461    function callback(properties)
     462    {
     463        treeElement.removeChildren();
     464        if (!properties)
     465            return;
     466
     467        properties.sort(WebInspector.ObjectPropertiesSection.CompareProperties);
     468        for (var i = 0; i < properties.length; ++i) {
     469            if (treeElement.treeOutline.section.skipProto && properties[i].name === "__proto__")
     470                continue;
     471            properties[i].parentObject = value;
     472            treeElement.appendChild(new treeElement.treeOutline.section.treeElementConstructor(properties[i]));
     473        }
     474        if (value.type === "function")
     475            treeElement.appendChild(new WebInspector.FunctionScopeMainTreeElement(value));
     476    }
     477
     478    value.getOwnProperties(callback);
     479}
     480
    471481WebInspector.ObjectPropertyTreeElement.prototype.__proto__ = TreeElement.prototype;
     482
     483/**
     484 * @constructor
     485 * @extends {TreeElement}
     486 * @param {WebInspector.RemoteObject} remoteObject
     487 */
     488WebInspector.FunctionScopeMainTreeElement = function(remoteObject)
     489{
     490    TreeElement.call(this, "<function scope>", null, false);
     491    this.toggleOnClick = true;
     492    this.selectable = false;
     493    this._remoteObject = remoteObject;
     494    this.hasChildren = true;
     495}
     496
     497WebInspector.FunctionScopeMainTreeElement.prototype = {
     498    onpopulate: function()
     499    {
     500        if (this.children.length && !this.shouldRefreshChildren)
     501            return;
     502
     503        function didGetDetails(error, response)
     504        {
     505            if (error) {
     506                console.error(error);
     507                return;
     508            }
     509            this.removeChildren();
     510
     511            var scopeChain = response.scopeChain;
     512            for (var i = 0; i < scopeChain.length; ++i) {
     513                var scope = scopeChain[i];
     514                var title = null;
     515                var isTrueObject;
     516
     517                switch (scope.type) {
     518                    case "local":
     519                        // Not really expecting this scope type here.
     520                        title = WebInspector.UIString("Local");
     521                        isTrueObject = false;
     522                        break;
     523                    case "closure":
     524                        title = WebInspector.UIString("Closure");
     525                        isTrueObject = false;
     526                        break;
     527                    case "catch":
     528                        title = WebInspector.UIString("Catch");
     529                        isTrueObject = false;
     530                        break;
     531                    case "with":
     532                        title = WebInspector.UIString("With Block");
     533                        isTrueObject = true;
     534                        break;
     535                    case "global":
     536                        title = WebInspector.UIString("Global");
     537                        isTrueObject = true;
     538                        break;
     539                }
     540
     541                var remoteObject = WebInspector.RemoteObject.fromPayload(scope.object);
     542                if (isTrueObject) {
     543                    var property = WebInspector.RemoteObjectProperty.fromScopeValue(title, remoteObject);
     544                    property.parentObject = null;
     545                    this.appendChild(new this.treeOutline.section.treeElementConstructor(property));
     546                } else {
     547                    var scopeTreeElement = new WebInspector.ScopeTreeElement(title, null, remoteObject);
     548                    this.appendChild(scopeTreeElement);
     549                }
     550            }
     551
     552        }
     553        DebuggerAgent.getFunctionDetails(this._remoteObject.objectId, didGetDetails.bind(this));
     554
     555    }
     556};
     557
     558WebInspector.FunctionScopeMainTreeElement.prototype.__proto__ = TreeElement.prototype;
     559
     560/**
     561 * @constructor
     562 * @extends {TreeElement}
     563 * @param {WebInspector.RemoteObject} remoteObject
     564 */
     565WebInspector.ScopeTreeElement = function(title, subtitle, remoteObject)
     566{
     567    // TODO: use subtitle parameter.
     568    TreeElement.call(this, title, null, false);
     569    this.toggleOnClick = true;
     570    this.selectable = false;
     571    this._remoteObject = remoteObject;
     572    this.hasChildren = true;
     573}
     574
     575WebInspector.ScopeTreeElement.prototype = {
     576    onpopulate: function()
     577    {
     578        return WebInspector.ObjectPropertyTreeElement.populate(this, this._remoteObject);
     579    }
     580};
     581
     582WebInspector.ScopeTreeElement.prototype.__proto__ = TreeElement.prototype;
    472583
    473584/**
     
    680791        if (this._populated)
    681792            return;
    682        
     793
    683794        this._populated = true;
    684795
  • trunk/Source/WebCore/inspector/front-end/RemoteObject.js

    r121896 r124876  
    337337 * @constructor
    338338 * @param {string} name
    339  * @param {WebInspector.RemoteObject} value 
     339 * @param {WebInspector.RemoteObject} value
    340340 * @param {Object=} descriptor
    341341 */
     
    358358{
    359359    return new WebInspector.RemoteObjectProperty(name, WebInspector.RemoteObject.fromPrimitiveValue(value));
     360}
     361
     362/**
     363 * @param {string} name
     364 * @param {WebInspector.RemoteObject} value
     365 * @return {WebInspector.RemoteObjectProperty}
     366 */
     367WebInspector.RemoteObjectProperty.fromScopeValue = function(name, value)
     368{
     369    var result = new WebInspector.RemoteObjectProperty(name, value);
     370    result.writable = false;
     371    return result;
    360372}
    361373
Note: See TracChangeset for help on using the changeset viewer.