Changeset 228336 in webkit


Ignore:
Timestamp:
Feb 9, 2018 12:40:10 PM (6 years ago)
Author:
Matt Baker
Message:

Web Inspector: Object.shallowEqual always fails when comparing array property values
https://bugs.webkit.org/show_bug.cgi?id=182634
<rdar://problem/37374639>

Reviewed by Devin Rousso.

Source/WebInspectorUI:

Object.shallowEqual should use Array.shallowEqual when comparing property
values, since strictly comparing objects/arrays is only true if both
operands reference the same Object.

  • UserInterface/Base/Utilities.js:

(value):

LayoutTests:

  • inspector/unit-tests/object-utilities-expected.txt:
  • inspector/unit-tests/object-utilities.html:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r228331 r228336  
     12018-02-09  Matt Baker  <mattbaker@apple.com>
     2
     3        Web Inspector: Object.shallowEqual always fails when comparing array property values
     4        https://bugs.webkit.org/show_bug.cgi?id=182634
     5        <rdar://problem/37374639>
     6
     7        Reviewed by Devin Rousso.
     8
     9        * inspector/unit-tests/object-utilities-expected.txt:
     10        * inspector/unit-tests/object-utilities.html:
     11
    1122018-02-09  Andy Estes  <aestes@apple.com>
    213
  • trunk/LayoutTests/inspector/unit-tests/object-utilities-expected.txt

    r210062 r228336  
    1010PASS: shallowEqual of unequal objects should be false.
    1111PASS: shallowEqual of unequal objects should be false.
     12PASS: shallowEqual of objects with similar arrays at the same key should be true.
     13PASS: shallowEqual of objects with similar arrays at the same key should be true.
     14PASS: shallowEqual of objects with similar arrays at the same key should be true.
     15PASS: shallowEqual of objects with dissimilar arrays at the same key should be false.
     16PASS: shallowEqual of objects with dissimilar arrays at the same key should be false.
    1217PASS: shallowEqual of an object and null should be false.
    1318PASS: shallowEqual of an object and non-object should be false.
  • trunk/LayoutTests/inspector/unit-tests/object-utilities.html

    r210062 r228336  
    2727            InspectorTest.expectThat(!Object.shallowEqual(obj3, obj1), "shallowEqual of unequal objects should be false.");
    2828
     29            InspectorTest.expectThat(Object.shallowEqual({x: []}, {x: []}), "shallowEqual of objects with similar arrays at the same key should be true.");
     30            InspectorTest.expectThat(Object.shallowEqual({x: new Array}, {x: new Array}), "shallowEqual of objects with similar arrays at the same key should be true.");
     31            InspectorTest.expectThat(Object.shallowEqual({x: [1]}, {x: [1]}), "shallowEqual of objects with similar arrays at the same key should be true.");
     32
     33            InspectorTest.expectThat(!Object.shallowEqual({x: [1]}, {x: []}), "shallowEqual of objects with dissimilar arrays at the same key should be false.");
     34            InspectorTest.expectThat(!Object.shallowEqual({x: new Array(1)}, {x: new Array}), "shallowEqual of objects with dissimilar arrays at the same key should be false.");
     35
    2936            InspectorTest.expectThat(!Object.shallowEqual({}, null), "shallowEqual of an object and null should be false.");
    3037            InspectorTest.expectThat(!Object.shallowEqual({}, 1.23), "shallowEqual of an object and non-object should be false.");
  • trunk/Source/WebInspectorUI/ChangeLog

    r228301 r228336  
     12018-02-09  Matt Baker  <mattbaker@apple.com>
     2
     3        Web Inspector: Object.shallowEqual always fails when comparing array property values
     4        https://bugs.webkit.org/show_bug.cgi?id=182634
     5        <rdar://problem/37374639>
     6
     7        Reviewed by Devin Rousso.
     8
     9        Object.shallowEqual should use Array.shallowEqual when comparing property
     10        values, since strictly comparing objects/arrays is only true if both
     11        operands reference the same Object.
     12
     13        * UserInterface/Base/Utilities.js:
     14        (value):
     15
    1162018-02-08  Matt Baker  <mattbaker@apple.com>
    217
  • trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js

    r228216 r228336  
    5050        // Checks if two objects have the same top-level properties.
    5151
    52         // Only objects can proceed.
    5352        if (!(a instanceof Object) || !(b instanceof Object))
    5453            return false;
    5554
    56         // Check for strict equality in case they are the same object.
    5755        if (a === b)
    5856            return true;
    5957
    60         // Use an optimized version of shallowEqual for arrays.
    61         if (Array.isArray(a) && Array.isArray(b))
    62             return Array.shallowEqual(a, b);
     58        if (Array.shallowEqual(a, b))
     59            return true;
    6360
    6461        if (a.constructor !== b.constructor)
    6562            return false;
    6663
    67         var aKeys = Object.keys(a);
    68         var bKeys = Object.keys(b);
    69 
    70         // Check that each object has the same number of keys.
     64        let aKeys = Object.keys(a);
     65        let bKeys = Object.keys(b);
    7166        if (aKeys.length !== bKeys.length)
    7267            return false;
    7368
    74         // Check if all the keys and their values are equal.
    75         for (var i = 0; i < aKeys.length; ++i) {
    76             // Check that b has the same key as a.
    77             if (!(aKeys[i] in b))
     69        for (let aKey of aKeys) {
     70            if (!(aKey in b))
    7871                return false;
    7972
    80             // Check that the values are strict equal since this is only
    81             // a shallow check, not a recursive one.
    82             if (a[aKeys[i]] !== b[aKeys[i]])
     73            let aValue = a[aKey];
     74            let bValue = b[aKey];
     75            if (aValue !== bValue && !Array.shallowEqual(aValue, bValue))
    8376                return false;
    8477        }
Note: See TracChangeset for help on using the changeset viewer.