Changeset 228364 in webkit
- Timestamp:
- Feb 9, 2018 10:25:50 PM (6 years ago)
- Location:
- branches/safari-605-branch
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/safari-605-branch/LayoutTests/ChangeLog
r228363 r228364 1 2018-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 1 16 2018-02-09 Jason Marcell <jmarcell@apple.com> 2 17 -
branches/safari-605-branch/LayoutTests/inspector/unit-tests/object-utilities-expected.txt
r210062 r228364 10 10 PASS: shallowEqual of unequal objects should be false. 11 11 PASS: shallowEqual of unequal objects should be false. 12 PASS: shallowEqual of objects with similar arrays at the same key should be true. 13 PASS: shallowEqual of objects with similar arrays at the same key should be true. 14 PASS: shallowEqual of objects with similar arrays at the same key should be true. 15 PASS: shallowEqual of objects with dissimilar arrays at the same key should be false. 16 PASS: shallowEqual of objects with dissimilar arrays at the same key should be false. 12 17 PASS: shallowEqual of an object and null should be false. 13 18 PASS: shallowEqual of an object and non-object should be false. -
branches/safari-605-branch/LayoutTests/inspector/unit-tests/object-utilities.html
r210062 r228364 27 27 InspectorTest.expectThat(!Object.shallowEqual(obj3, obj1), "shallowEqual of unequal objects should be false."); 28 28 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 29 36 InspectorTest.expectThat(!Object.shallowEqual({}, null), "shallowEqual of an object and null should be false."); 30 37 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 1 2018-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 1 20 2018-02-09 Jason Marcell <jmarcell@apple.com> 2 21 -
branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Base/Utilities.js
r226860 r228364 50 50 // Checks if two objects have the same top-level properties. 51 51 52 // Only objects can proceed.53 52 if (!(a instanceof Object) || !(b instanceof Object)) 54 53 return false; 55 54 56 // Check for strict equality in case they are the same object.57 55 if (a === b) 58 56 return true; 59 57 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; 63 60 64 61 if (a.constructor !== b.constructor) 65 62 return false; 66 63 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); 71 66 if (aKeys.length !== bKeys.length) 72 67 return false; 73 68 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)) 78 71 return false; 79 72 80 // Check that the values are strict equal since this is only81 // 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)) 83 76 return false; 84 77 }
Note: See TracChangeset
for help on using the changeset viewer.