Title: [228336] trunk
Revision
228336
Author
mattba...@apple.com
Date
2018-02-09 12:40:10 -0800 (Fri, 09 Feb 2018)

Log 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:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (228335 => 228336)


--- trunk/LayoutTests/ChangeLog	2018-02-09 20:06:02 UTC (rev 228335)
+++ trunk/LayoutTests/ChangeLog	2018-02-09 20:40:10 UTC (rev 228336)
@@ -1,3 +1,14 @@
+2018-02-09  Matt Baker  <mattba...@apple.com>
+
+        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.
+
+        * inspector/unit-tests/object-utilities-expected.txt:
+        * inspector/unit-tests/object-utilities.html:
+
 2018-02-09  Andy Estes  <aes...@apple.com>
 
         [Payment Request] Crash in PaymentRequest::canMakePayment() when Apple Pay payment method data is missing required fields

Modified: trunk/LayoutTests/inspector/unit-tests/object-utilities-expected.txt (228335 => 228336)


--- trunk/LayoutTests/inspector/unit-tests/object-utilities-expected.txt	2018-02-09 20:06:02 UTC (rev 228335)
+++ trunk/LayoutTests/inspector/unit-tests/object-utilities-expected.txt	2018-02-09 20:40:10 UTC (rev 228336)
@@ -9,6 +9,11 @@
 PASS: shallowEqual of equal objects should be true.
 PASS: shallowEqual of unequal objects should be false.
 PASS: shallowEqual of unequal objects should be false.
+PASS: shallowEqual of objects with similar arrays at the same key should be true.
+PASS: shallowEqual of objects with similar arrays at the same key should be true.
+PASS: shallowEqual of objects with similar arrays at the same key should be true.
+PASS: shallowEqual of objects with dissimilar arrays at the same key should be false.
+PASS: shallowEqual of objects with dissimilar arrays at the same key should be false.
 PASS: shallowEqual of an object and null should be false.
 PASS: shallowEqual of an object and non-object should be false.
 PASS: shallowEqual of a non-object with itself should be false.

Modified: trunk/LayoutTests/inspector/unit-tests/object-utilities.html (228335 => 228336)


--- trunk/LayoutTests/inspector/unit-tests/object-utilities.html	2018-02-09 20:06:02 UTC (rev 228335)
+++ trunk/LayoutTests/inspector/unit-tests/object-utilities.html	2018-02-09 20:40:10 UTC (rev 228336)
@@ -26,6 +26,13 @@
             InspectorTest.expectThat(!Object.shallowEqual(obj1, obj3), "shallowEqual of unequal objects should be false.");
             InspectorTest.expectThat(!Object.shallowEqual(obj3, obj1), "shallowEqual of unequal objects should be false.");
 
+            InspectorTest.expectThat(Object.shallowEqual({x: []}, {x: []}), "shallowEqual of objects with similar arrays at the same key should be true.");
+            InspectorTest.expectThat(Object.shallowEqual({x: new Array}, {x: new Array}), "shallowEqual of objects with similar arrays at the same key should be true.");
+            InspectorTest.expectThat(Object.shallowEqual({x: [1]}, {x: [1]}), "shallowEqual of objects with similar arrays at the same key should be true.");
+
+            InspectorTest.expectThat(!Object.shallowEqual({x: [1]}, {x: []}), "shallowEqual of objects with dissimilar arrays at the same key should be false.");
+            InspectorTest.expectThat(!Object.shallowEqual({x: new Array(1)}, {x: new Array}), "shallowEqual of objects with dissimilar arrays at the same key should be false.");
+
             InspectorTest.expectThat(!Object.shallowEqual({}, null), "shallowEqual of an object and null should be false.");
             InspectorTest.expectThat(!Object.shallowEqual({}, 1.23), "shallowEqual of an object and non-object should be false.");
 

Modified: trunk/Source/WebInspectorUI/ChangeLog (228335 => 228336)


--- trunk/Source/WebInspectorUI/ChangeLog	2018-02-09 20:06:02 UTC (rev 228335)
+++ trunk/Source/WebInspectorUI/ChangeLog	2018-02-09 20:40:10 UTC (rev 228336)
@@ -1,3 +1,18 @@
+2018-02-09  Matt Baker  <mattba...@apple.com>
+
+        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.
+
+        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):
+
 2018-02-08  Matt Baker  <mattba...@apple.com>
 
         Web Inspector: add listing of Canvases/Programs/Recordings to the NavigationSidebar

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js (228335 => 228336)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2018-02-09 20:06:02 UTC (rev 228335)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2018-02-09 20:40:10 UTC (rev 228336)
@@ -49,37 +49,30 @@
     {
         // Checks if two objects have the same top-level properties.
 
-        // Only objects can proceed.
         if (!(a instanceof Object) || !(b instanceof Object))
             return false;
 
-        // Check for strict equality in case they are the same object.
         if (a === b)
             return true;
 
-        // Use an optimized version of shallowEqual for arrays.
-        if (Array.isArray(a) && Array.isArray(b))
-            return Array.shallowEqual(a, b);
+        if (Array.shallowEqual(a, b))
+            return true;
 
         if (a.constructor !== b.constructor)
             return false;
 
-        var aKeys = Object.keys(a);
-        var bKeys = Object.keys(b);
-
-        // Check that each object has the same number of keys.
+        let aKeys = Object.keys(a);
+        let bKeys = Object.keys(b);
         if (aKeys.length !== bKeys.length)
             return false;
 
-        // Check if all the keys and their values are equal.
-        for (var i = 0; i < aKeys.length; ++i) {
-            // Check that b has the same key as a.
-            if (!(aKeys[i] in b))
+        for (let aKey of aKeys) {
+            if (!(aKey in b))
                 return false;
 
-            // Check that the values are strict equal since this is only
-            // a shallow check, not a recursive one.
-            if (a[aKeys[i]] !== b[aKeys[i]])
+            let aValue = a[aKey];
+            let bValue = b[aKey];
+            if (aValue !== bValue && !Array.shallowEqual(aValue, bValue))
                 return false;
         }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to