Changeset 228364 in webkit


Ignore:
Timestamp:
Feb 9, 2018 10:25:50 PM (6 years ago)
Author:
jmarcell@apple.com
Message:

Cherry-pick r228336. rdar://problem/37408902

Location:
branches/safari-605-branch
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-605-branch/LayoutTests/ChangeLog

    r228363 r228364  
     12018-02-09  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r228336. rdar://problem/37408902
     4
     5    2018-02-09  Matt Baker  <mattbaker@apple.com>
     6
     7            Web Inspector: Object.shallowEqual always fails when comparing array property values
     8            https://bugs.webkit.org/show_bug.cgi?id=182634
     9            <rdar://problem/37374639>
     10
     11            Reviewed by Devin Rousso.
     12
     13            * inspector/unit-tests/object-utilities-expected.txt:
     14            * inspector/unit-tests/object-utilities.html:
     15
    1162018-02-09  Jason Marcell  <jmarcell@apple.com>
    217
  • branches/safari-605-branch/LayoutTests/inspector/unit-tests/object-utilities-expected.txt

    r210062 r228364  
    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.
  • branches/safari-605-branch/LayoutTests/inspector/unit-tests/object-utilities.html

    r210062 r228364  
    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.");
  • branches/safari-605-branch/Source/WebInspectorUI/ChangeLog

    r228357 r228364  
     12018-02-09  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r228336. rdar://problem/37408902
     4
     5    2018-02-09  Matt Baker  <mattbaker@apple.com>
     6
     7            Web Inspector: Object.shallowEqual always fails when comparing array property values
     8            https://bugs.webkit.org/show_bug.cgi?id=182634
     9            <rdar://problem/37374639>
     10
     11            Reviewed by Devin Rousso.
     12
     13            Object.shallowEqual should use Array.shallowEqual when comparing property
     14            values, since strictly comparing objects/arrays is only true if both
     15            operands reference the same Object.
     16
     17            * UserInterface/Base/Utilities.js:
     18            (value):
     19
    1202018-02-09  Jason Marcell  <jmarcell@apple.com>
    221
  • branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Base/Utilities.js

    r226860 r228364  
    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.