Changeset 35315 in webkit


Ignore:
Timestamp:
Jul 23, 2008 7:48:01 PM (16 years ago)
Author:
timothy@apple.com
Message:

Fix a regression where elements in subframes would not be revealed
or selected when inspected from the context menu. This was caused by
JavaScript equality is not being true for JSInspectedObjectWrappers
of the same node wrapped with different global ExecStates. This change
adds a helper function that uses isSameNode to compare wrapped nodes.

https://bugs.webkit.org/show_bug.cgi?id=19377

Reviewed by Adam Roben.

  • page/inspector/ElementsPanel.js: (WebInspector.ElementsPanel.prototype.set rootDOMNode): Use objectsAreSame to compare nodes. (WebInspector.ElementsPanel.prototype.set focusedDOMNode): Ditto. (WebInspector.ElementsPanel.prototype.set hoveredDOMNode): Ditto. (WebInspector.ElementsPanel.prototype._updateModifiedNodes): Ditto. (WebInspector.ElementsPanel.prototype.revealNode): Ditto. (WebInspector.ElementsPanel.prototype.updateBreadcrumb): Ditto. (WebInspector.DOMNodeTreeElement.prototype.updateChildren): Ditto.
  • page/inspector/treeoutline.js: (TreeOutline.prototype.findTreeElement): Add an equal argument to accept a functions to compare two representedObjects. Defaults to strict equal if not supplied. All current clients pass objectsAreSame.
  • page/inspector/utilities.js: (Node.prototype.enclosingNodeOrSelfWithNodeNameInArray): Use objectsAreSame to compare nodes. (Node.prototype.enclosingNodeOrSelfWithClass): Ditto. (Element.prototype.query): Use the ownerDocument of the node, not document. (objectsAreSame): Added. Compares strict equal first, then uses isSameNode if it exists on both objects. (isAncestorNode): Use objectsAreSame to compare nodes. (firstCommonNodeAncestor): Ditto. (traverseNextNode): Ditto.
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r35314 r35315  
     12008-07-22  Timothy Hatcher  <timothy@apple.com>
     2
     3        Fix a regression where elements in subframes would not be revealed
     4        or selected when inspected from the context menu. This was caused by
     5        JavaScript equality is not being true for JSInspectedObjectWrappers
     6        of the same node wrapped with different global ExecStates. This change
     7        adds a helper function that uses isSameNode to compare wrapped nodes.
     8
     9        https://bugs.webkit.org/show_bug.cgi?id=19377
     10
     11        Reviewed by Adam Roben.
     12
     13        * page/inspector/ElementsPanel.js:
     14        (WebInspector.ElementsPanel.prototype.set rootDOMNode): Use objectsAreSame
     15        to compare nodes.
     16        (WebInspector.ElementsPanel.prototype.set focusedDOMNode): Ditto.
     17        (WebInspector.ElementsPanel.prototype.set hoveredDOMNode): Ditto.
     18        (WebInspector.ElementsPanel.prototype._updateModifiedNodes): Ditto.
     19        (WebInspector.ElementsPanel.prototype.revealNode): Ditto.
     20        (WebInspector.ElementsPanel.prototype.updateBreadcrumb): Ditto.
     21        (WebInspector.DOMNodeTreeElement.prototype.updateChildren): Ditto.
     22        * page/inspector/treeoutline.js:
     23        (TreeOutline.prototype.findTreeElement): Add an equal argument
     24        to accept a functions to compare two representedObjects. Defaults
     25        to strict equal if not supplied. All current clients pass objectsAreSame.
     26        * page/inspector/utilities.js:
     27        (Node.prototype.enclosingNodeOrSelfWithNodeNameInArray): Use objectsAreSame
     28        to compare nodes.
     29        (Node.prototype.enclosingNodeOrSelfWithClass): Ditto.
     30        (Element.prototype.query): Use the ownerDocument of the node, not document.
     31        (objectsAreSame): Added. Compares strict equal first, then uses isSameNode if
     32        it exists on both objects.
     33        (isAncestorNode): Use objectsAreSame to compare nodes.
     34        (firstCommonNodeAncestor): Ditto.
     35        (traverseNextNode): Ditto.
     36
    1372008-07-21  Timothy Hatcher  <timothy@apple.com>
    238
  • trunk/WebCore/page/inspector/ElementsPanel.js

    r34104 r35315  
    173173    set rootDOMNode(x)
    174174    {
    175         if (this._rootDOMNode === x)
     175        if (objectsAreSame(this._rootDOMNode, x))
    176176            return;
    177177
     
    189189    set focusedDOMNode(x)
    190190    {
    191         if (this._focusedDOMNode === x) {
     191        if (objectsAreSame(this._focusedDOMNode, x)) {
    192192            var nodeItem = this.revealNode(x);
    193193            if (nodeItem)
     
    212212    set hoveredDOMNode(x)
    213213    {
    214         if (this._hoveredDOMNode === x)
     214        if (objectsAreSame(this._hoveredDOMNode, x))
    215215            return;
    216216
     
    293293    revealNode: function(node)
    294294    {
    295         var nodeItem = this.treeOutline.findTreeElement(node, this._isAncestorIncludingParentFrames.bind(this), this._parentNodeOrFrameElement.bind(this));
     295        var nodeItem = this.treeOutline.findTreeElement(node, this._isAncestorIncludingParentFrames.bind(this), this._parentNodeOrFrameElement.bind(this), objectsAreSame);
    296296        if (!nodeItem)
    297297            return;
     
    329329        var crumb = crumbs.firstChild;
    330330        while (crumb) {
    331             if (crumb.representedObject === this.rootDOMNode)
     331            if (objectsAreSame(crumb.representedObject, this.rootDOMNode))
    332332                foundRoot = true;
    333333
     
    337337                crumb.removeStyleClass("dimmed");
    338338
    339             if (crumb.representedObject === this.focusedDOMNode) {
     339            if (objectsAreSame(crumb.representedObject, this.focusedDOMNode)) {
    340340                crumb.addStyleClass("selected");
    341341                handled = true;
     
    429429                continue;
    430430
    431             if (current === this.rootDOMNode)
     431            if (objectsAreSame(current, this.rootDOMNode))
    432432                foundRoot = true;
    433433
     
    514514            if (foundRoot)
    515515                crumb.addStyleClass("dimmed");
    516             if (current === this.focusedDOMNode)
     516            if (objectsAreSame(current, this.focusedDOMNode))
    517517                crumb.addStyleClass("selected");
    518518            if (!crumbs.childNodes.length)
  • trunk/WebCore/page/inspector/treeoutline.js

    r35313 r35315  
    246246}
    247247
    248 TreeOutline.prototype.findTreeElement = function(representedObject, isAncestor, getParent)
     248TreeOutline.prototype.findTreeElement = function(representedObject, isAncestor, getParent, equal)
    249249{
    250250    if (!representedObject)
    251251        return null;
     252
     253    if (!equal)
     254        equal = function(a, b) { return a === b };
    252255
    253256    if ("__treeElementIdentifier" in representedObject) {
     
    257260        if (elements) {
    258261            for (var i = 0; i < elements.length; ++i)
    259                 if (elements[i].representedObject === representedObject)
     262                if (equal(elements[i].representedObject, representedObject))
    260263                    return elements[i];
    261264        }
     
    271274    for (var i = 0; i < this.children.length; ++i) {
    272275        item = this.children[i];
    273         if (item.representedObject === representedObject || isAncestor(item.representedObject, representedObject)) {
     276        if (equal(item.representedObject, representedObject) || isAncestor(item.representedObject, representedObject)) {
    274277            found = true;
    275278            break;
     
    286289    while (currentObject) {
    287290        ancestors.unshift(currentObject);
    288         if (currentObject === item.representedObject)
     291        if (equal(currentObject, item.representedObject))
    289292            break;
    290293        currentObject = getParent(currentObject);
     
    295298        // Make sure we don't call findTreeElement with the same representedObject
    296299        // again, to prevent infinite recursion.
    297         if (ancestors[i] === representedObject)
     300        if (equal(ancestors[i], representedObject))
    298301            continue;
    299302        // FIXME: we could do something faster than findTreeElement since we will know the next
    300303        // ancestor exists in the tree.
    301         item = this.findTreeElement(ancestors[i], isAncestor, getParent);
     304        item = this.findTreeElement(ancestors[i], isAncestor, getParent, equal);
    302305        if (item && item.onpopulate)
    303306            item.onpopulate(item);
     
    306309    // Now that all the ancestors are populated, try to find the representedObject again. This time
    307310    // without the isAncestor and getParent functions to prevent an infinite recursion if it isn't found.
    308     return this.findTreeElement(representedObject);
     311    return this.findTreeElement(representedObject, null, null, equal);
    309312}
    310313
  • trunk/WebCore/page/inspector/utilities.js

    r34211 r35315  
    136136Node.prototype.enclosingNodeOrSelfWithNodeNameInArray = function(nameArray)
    137137{
    138     for (var node = this; node && (node !== document); node = node.parentNode)
     138    for (var node = this; node && !objectsAreSame(node, this.ownerDocument); node = node.parentNode)
    139139        for (var i = 0; i < nameArray.length; ++i)
    140140            if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase())
     
    150150Node.prototype.enclosingNodeOrSelfWithClass = function(className)
    151151{
    152     for (var node = this; node && (node !== document); node = node.parentNode)
     152    for (var node = this; node && !objectsAreSame(node, this.ownerDocument); node = node.parentNode)
    153153        if (node.nodeType === Node.ELEMENT_NODE && node.hasStyleClass(className))
    154154            return node;
     
    165165Element.prototype.query = function(query)
    166166{
    167     return document.evaluate(query, this, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
     167    return this.ownerDocument.evaluate(query, this, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    168168}
    169169
     
    492492}
    493493
     494function objectsAreSame(a, b)
     495{
     496    // FIXME: Make this more generic so is works with any wrapped object, not just nodes.
     497    // This function is used to compare nodes that might be JSInspectedObjectWrappers, since
     498    // JavaScript equality is not true for JSInspectedObjectWrappers of the same node wrapped
     499    // with different global ExecStates, we use isSameNode to compare them.
     500    if (a === b)
     501        return true;
     502    if (!a || !b)
     503        return false;
     504    if (a.isSameNode && b.isSameNode)
     505        return a.isSameNode(b);
     506    return false;
     507}
     508
    494509function isAncestorNode(ancestor)
    495510{
     
    499514    var currentNode = ancestor.parentNode;
    500515    while (currentNode) {
    501         if (this === currentNode)
     516        if (objectsAreSame(this, currentNode))
    502517            return true;
    503518        currentNode = currentNode.parentNode;
     
    520535    var node2 = node.parentNode;
    521536
    522     if ((!node1 || !node2) || node1 !== node2)
     537    if ((!node1 || !node2) || !objectsAreSame(node1, node2))
    523538        return null;
    524539
     
    526541        if (!node1.parentNode || !node2.parentNode)
    527542            break;
    528         if (node1 !== node2)
     543        if (!objectsAreSame(node1, node2))
    529544            break;
    530545
     
    585600        return node;
    586601
    587     if (stayWithin && this === stayWithin)
     602    if (stayWithin && objectsAreSame(this, stayWithin))
    588603        return null;
    589604
     
    593608
    594609    node = this;
    595     while (node && !(skipWhitespace ? nextSiblingSkippingWhitespace.call(node) : node.nextSibling) && (!stayWithin || !node.parentNode || node.parentNode !== stayWithin))
     610    while (node && !(skipWhitespace ? nextSiblingSkippingWhitespace.call(node) : node.nextSibling) && (!stayWithin || !node.parentNode || !objectsAreSame(node.parentNode, stayWithin)))
    596611        node = node.parentNode;
    597612    if (!node)
Note: See TracChangeset for help on using the changeset viewer.