Web Inspector: Object.shallowEqual([{}], [{}]) should return true
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2016 00:21:19 +0000 (00:21 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2016 00:21:19 +0000 (00:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165397

Reviewed by Brian Burg.

Source/WebInspectorUI:

* UserInterface/Base/Utilities.js:
(value):
Array.shallowEqual should compare array items using strict equivalence,
and on failure defer to Object.shallowEqual.

LayoutTests:

Added passing and failing inputs for TestHarness.prototype.expectShallowEqual.

* inspector/unit-tests/test-harness-expect-functions-expected.txt:
* inspector/unit-tests/test-harness-expect-functions.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209366 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt
LayoutTests/inspector/unit-tests/test-harness-expect-functions.html
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Utilities.js

index 5b8e04250721e0abb0a6ccde6692669c4fdecb4b..37bd03029b231d5c2d0be659aedfc4e8f7213c9f 100644 (file)
@@ -1,3 +1,15 @@
+2016-12-05  Matt Baker  <mattbaker@apple.com>
+
+        Web Inspector: Object.shallowEqual([{}], [{}]) should return true
+        https://bugs.webkit.org/show_bug.cgi?id=165397
+
+        Reviewed by Brian Burg.
+
+        Added passing and failing inputs for TestHarness.prototype.expectShallowEqual.
+
+        * inspector/unit-tests/test-harness-expect-functions-expected.txt:
+        * inspector/unit-tests/test-harness-expect-functions.html:
+
 2016-12-05  Dean Jackson  <dino@apple.com>
 
         pointer lock needs to be feature detectable
index d7ff35efe4d0267aebb4d1ae0608984d35016f1a..f9b20ab1e3b30262caf43d075dfce0b32ac9e79d 100644 (file)
@@ -170,6 +170,9 @@ FAIL: expectNotEqual(undefined, undefined)
 Expected to PASS
 PASS: expectShallowEqual({"a":1,"b":2}, {"a":1,"b":2})
 PASS: expectShallowEqual({}, {})
+PASS: expectShallowEqual([1,2], [1,2])
+PASS: expectShallowEqual([{"a":1},{"a":2}], [{"a":1},{"a":2}])
+PASS: expectShallowEqual([{}], [{}])
 PASS: expectShallowEqual([], [])
 Expected to FAIL
 FAIL: expectShallowEqual({"a":1,"b":2}, {"a":3,"b":4})
@@ -178,11 +181,23 @@ FAIL: expectShallowEqual({"a":1,"b":2}, {"a":3,"b":4})
 FAIL: expectShallowEqual({}, [])
     Expected: []
     Actual: {}
+FAIL: expectShallowEqual([1,2], [3,4])
+    Expected: [3,4]
+    Actual: [1,2]
+FAIL: expectShallowEqual([{"a":1},{"a":2}], [{"a":3},{"a":4}])
+    Expected: [{"a":3},{"a":4}]
+    Actual: [{"a":1},{"a":2}]
+FAIL: expectShallowEqual([{"a":1},{"a":2}], [{"b":1},{"b":2}])
+    Expected: [{"b":1},{"b":2}]
+    Actual: [{"a":1},{"a":2}]
 
 -- Running test case: InspectorTest.expectNotShallowEqual
 Expected to PASS
 PASS: expectNotShallowEqual({"a":1,"b":2}, {"a":3,"b":4})
 PASS: expectNotShallowEqual({}, [])
+PASS: expectNotShallowEqual([1,2], [3,4])
+PASS: expectNotShallowEqual([{"a":1},{"a":2}], [{"a":3},{"a":4}])
+PASS: expectNotShallowEqual([{"a":1},{"a":2}], [{"b":1},{"b":2}])
 Expected to FAIL
 FAIL: expectNotShallowEqual({"a":1,"b":2}, {"a":1,"b":2})
     Expected: not {"a":1,"b":2}
@@ -190,6 +205,15 @@ FAIL: expectNotShallowEqual({"a":1,"b":2}, {"a":1,"b":2})
 FAIL: expectNotShallowEqual({}, {})
     Expected: not {}
     Actual: {}
+FAIL: expectNotShallowEqual([1,2], [1,2])
+    Expected: not [1,2]
+    Actual: [1,2]
+FAIL: expectNotShallowEqual([{"a":1},{"a":2}], [{"a":1},{"a":2}])
+    Expected: not [{"a":1},{"a":2}]
+    Actual: [{"a":1},{"a":2}]
+FAIL: expectNotShallowEqual([{}], [{}])
+    Expected: not [{}]
+    Actual: [{}]
 FAIL: expectNotShallowEqual([], [])
     Expected: not []
     Actual: []
index c19341bf1f3c2731d697c8c101642ecc0a6770a4..28d14342c09266c08ca22e36407a94035c444e48 100644 (file)
@@ -91,11 +91,17 @@ function test()
         passingInputs: [
             [{a: 1, b: 2}, {a: 1, b: 2}],
             [{}, {}],
+            [[1, 2], [1, 2]],
+            [[{a: 1}, {a: 2}], [{a: 1}, {a: 2}]],
+            [[{}], [{}]],
             [[], []],
         ],
         failingInputs: [
             [{a: 1, b: 2}, {a: 3, b: 4}],
             [{}, []],
+            [[1, 2], [3, 4]],
+            [[{a: 1}, {a: 2}], [{a: 3}, {a: 4}]],
+            [[{a: 1}, {a: 2}], [{b: 1}, {b: 2}]],
         ]
     };
     addTestCase(expectShallowEqualTestCase);
index 0c33a7127f8b97b7e9c606398560d8bfcf78ec3c..5cbb402c25aeaf958ae8cec21b5642556eefaee2 100644 (file)
@@ -1,3 +1,15 @@
+2016-12-05  Matt Baker  <mattbaker@apple.com>
+
+        Web Inspector: Object.shallowEqual([{}], [{}]) should return true
+        https://bugs.webkit.org/show_bug.cgi?id=165397
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Base/Utilities.js:
+        (value):
+        Array.shallowEqual should compare array items using strict equivalence,
+        and on failure defer to Object.shallowEqual.
+
 2016-12-05  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Remove legacy styles
index ccfd2dc94ef44707d9c3abd3109e6f650f4c6253..45c47bbadc79aa4bb5c0d406aebc15c24f6e9f42 100644 (file)
@@ -447,8 +447,11 @@ Object.defineProperty(Array, "shallowEqual",
         if (length !== b.length)
             return false;
 
-        for (var i = 0; i < length; ++i) {
-            if (a[i] !== b[i])
+        for (let i = 0; i < length; ++i) {
+            if (a[i] === b[i])
+                continue;
+
+            if (!Object.shallowEqual(a[i], b[i]))
                 return false;
         }