Changeset 219014 in webkit


Ignore:
Timestamp:
Jun 30, 2017 2:47:05 PM (7 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Default string comparisons to treat numeric characters as numbers
https://bugs.webkit.org/show_bug.cgi?id=173984

Reviewed by Joseph Pecoraro.

Source/WebInspectorUI:

  • UserInterface/Base/Utilities.js:

(String.prototype.extendedLocaleCompare):

  • UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:

(WebInspector.JavaScriptRuntimeCompletionProvider.prototype.completionControllerCompletionsNeeded.receivedPropertyNames.compare):

  • UserInterface/Controllers/ResourceQueryController.js:

(WebInspector.ResourceQueryController.prototype.executeQuery):

  • UserInterface/Views/ApplicationCacheFrameContentView.js:

(WebInspector.ApplicationCacheFrameContentView.prototype._sortDataGrid.localeCompare):

  • UserInterface/Views/CSSStyleDeclarationTextEditor.js:

(WebInspector.CSSStyleDeclarationTextEditor.prototype._iterateOverProperties):

  • UserInterface/Views/CookieStorageContentView.js:

(WebInspector.CookieStorageContentView.prototype._sortDataGrid.localeCompare):

  • UserInterface/Views/DOMNodeDetailsSidebarPanel.js:

(WebInspector.DOMNodeDetailsSidebarPanel.prototype._refreshAttributes):
(WebInspector.DOMNodeDetailsSidebarPanel.prototype._refreshEventListeners.generateGroupsByNode):

  • UserInterface/Views/DOMStorageContentView.js:

(WebInspector.DOMStorageContentView.prototype._sortDataGrid.comparator):

  • UserInterface/Views/DebuggerSidebarPanel.js:

(WebInspector.DebuggerSidebarPanel.prototype._compareTopLevelTreeElements):

  • UserInterface/Views/FolderizedTreeElement.js:

(WebInspector.FolderizedTreeElement.prototype._compareTreeElementsByMainTitle):

  • UserInterface/Views/HeapSnapshotDataGridTree.js:

(WebInspector.HeapSnapshotDataGridTree.buildSortComparator):

  • UserInterface/Views/NetworkTimelineView.js:

(WebInspector.NetworkTimelineView.prototype.dataGridSortComparator):

  • UserInterface/Views/NewTabContentView.js:

(WebInspector.NewTabContentView.prototype._updateShownTabs):

  • UserInterface/Views/OverviewTimelineView.js:

(WebInspector.OverviewTimelineView.prototype._compareDataGridNodesByStartTime):

  • UserInterface/Views/ProbeDetailsSidebarPanel.js:

(WebInspector.ProbeDetailsSidebarPanel.prototype.inspect):

  • UserInterface/Views/QuickConsole.js:

(WebInspector.QuickConsole.prototype._compareExecutionContextPathComponents):

  • UserInterface/Views/ResourceDetailsSidebarPanel.js:

(WebInspector.ResourceDetailsSidebarPanel.prototype._createNameValueDataGrid.sortDataGrid.comparator):

  • UserInterface/Views/ResourceSidebarPanel.js:

(WebInspector.ResourceSidebarPanel.prototype._compareTreeElements):

  • UserInterface/Views/ResourceTreeElement.js:

(WebInspector.ResourceTreeElement.compareResourceTreeElements):
(WebInspector.ResourceTreeElement.compareFolderAndResourceTreeElements):

  • UserInterface/Views/ScriptDetailsTimelineView.js:

(WebInspector.ScriptDetailsTimelineView.prototype.dataGridSortComparator):

  • UserInterface/Views/StorageSidebarPanel.js:

(WebInspector.StorageSidebarPanel.prototype._compareTreeElements):

  • UserInterface/Views/TimelineDataGrid.js:

(WebInspector.TimelineDataGrid.prototype._sortComparator):

LayoutTests:

  • inspector/unit-tests/string-utilities.html:

Add tests for String.prototype.extendedLocaleCompare.

Location:
trunk
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r219008 r219014  
     12017-06-30  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Default string comparisons to treat numeric characters as numbers
     4        https://bugs.webkit.org/show_bug.cgi?id=173984
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        * inspector/unit-tests/string-utilities.html:
     9        Add tests for String.prototype.extendedLocaleCompare.
     10
    1112017-06-30  Ryosuke Niwa  <rniwa@webkit.org>
    212
  • trunk/LayoutTests/inspector/unit-tests/string-utilities-expected.txt

    r199635 r219014  
    2121PASS: integer format specifier with NaN argument should show "NaN"
    2222
     23-- Running test case: String.prototype.extendedLocaleCompare
     24PASS: "1" < "2"
     25PASS: "2" > "1"
     26PASS: "2" < "10"
     27PASS: "10" > "2"
     28PASS: "1" < "10"
     29PASS: "10" > "1"
     30PASS: "a1" < "a2"
     31PASS: "a2" > "a1"
     32PASS: "a2" < "a10"
     33PASS: "a10" > "a2"
     34PASS: "a1" < "a10"
     35PASS: "a10" > "a1"
     36
  • trunk/LayoutTests/inspector/unit-tests/string-utilities.html

    r210062 r219014  
    3434    });
    3535
     36    suite.addTestCase({
     37        name: "String.prototype.extendedLocaleCompare",
     38        test() {
     39            InspectorTest.expectEqual("1".extendedLocaleCompare("2"), -1, `"1" < "2"`);
     40            InspectorTest.expectEqual("2".extendedLocaleCompare("1"), 1, `"2" > "1"`);
     41            InspectorTest.expectEqual("2".extendedLocaleCompare("10"), -1, `"2" < "10"`);
     42            InspectorTest.expectEqual("10".extendedLocaleCompare("2"), 1, `"10" > "2"`);
     43            InspectorTest.expectEqual("1".extendedLocaleCompare("10"), -1, `"1" < "10"`);
     44            InspectorTest.expectEqual("10".extendedLocaleCompare("1"), 1, `"10" > "1"`);
     45
     46            InspectorTest.expectEqual("a1".extendedLocaleCompare("a2"), -1, `"a1" < "a2"`);
     47            InspectorTest.expectEqual("a2".extendedLocaleCompare("a1"), 1, `"a2" > "a1"`);
     48            InspectorTest.expectEqual("a2".extendedLocaleCompare("a10"), -1, `"a2" < "a10"`);
     49            InspectorTest.expectEqual("a10".extendedLocaleCompare("a2"), 1, `"a10" > "a2"`);
     50            InspectorTest.expectEqual("a1".extendedLocaleCompare("a10"), -1, `"a1" < "a10"`);
     51            InspectorTest.expectEqual("a10".extendedLocaleCompare("a1"), 1, `"a10" > "a1"`);
     52            return true;
     53        }
     54    });
     55
    3656    suite.runTestCasesAndFinish();
    3757}
  • trunk/Source/WebInspectorUI/ChangeLog

    r218984 r219014  
     12017-06-30  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Default string comparisons to treat numeric characters as numbers
     4        https://bugs.webkit.org/show_bug.cgi?id=173984
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        * UserInterface/Base/Utilities.js:
     9        (String.prototype.extendedLocaleCompare):
     10        * UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
     11        (WebInspector.JavaScriptRuntimeCompletionProvider.prototype.completionControllerCompletionsNeeded.receivedPropertyNames.compare):
     12        * UserInterface/Controllers/ResourceQueryController.js:
     13        (WebInspector.ResourceQueryController.prototype.executeQuery):
     14        * UserInterface/Views/ApplicationCacheFrameContentView.js:
     15        (WebInspector.ApplicationCacheFrameContentView.prototype._sortDataGrid.localeCompare):
     16        * UserInterface/Views/CSSStyleDeclarationTextEditor.js:
     17        (WebInspector.CSSStyleDeclarationTextEditor.prototype._iterateOverProperties):
     18        * UserInterface/Views/CookieStorageContentView.js:
     19        (WebInspector.CookieStorageContentView.prototype._sortDataGrid.localeCompare):
     20        * UserInterface/Views/DOMNodeDetailsSidebarPanel.js:
     21        (WebInspector.DOMNodeDetailsSidebarPanel.prototype._refreshAttributes):
     22        (WebInspector.DOMNodeDetailsSidebarPanel.prototype._refreshEventListeners.generateGroupsByNode):
     23        * UserInterface/Views/DOMStorageContentView.js:
     24        (WebInspector.DOMStorageContentView.prototype._sortDataGrid.comparator):
     25        * UserInterface/Views/DebuggerSidebarPanel.js:
     26        (WebInspector.DebuggerSidebarPanel.prototype._compareTopLevelTreeElements):
     27        * UserInterface/Views/FolderizedTreeElement.js:
     28        (WebInspector.FolderizedTreeElement.prototype._compareTreeElementsByMainTitle):
     29        * UserInterface/Views/HeapSnapshotDataGridTree.js:
     30        (WebInspector.HeapSnapshotDataGridTree.buildSortComparator):
     31        * UserInterface/Views/NetworkTimelineView.js:
     32        (WebInspector.NetworkTimelineView.prototype.dataGridSortComparator):
     33        * UserInterface/Views/NewTabContentView.js:
     34        (WebInspector.NewTabContentView.prototype._updateShownTabs):
     35        * UserInterface/Views/OverviewTimelineView.js:
     36        (WebInspector.OverviewTimelineView.prototype._compareDataGridNodesByStartTime):
     37        * UserInterface/Views/ProbeDetailsSidebarPanel.js:
     38        (WebInspector.ProbeDetailsSidebarPanel.prototype.inspect):
     39        * UserInterface/Views/QuickConsole.js:
     40        (WebInspector.QuickConsole.prototype._compareExecutionContextPathComponents):
     41        * UserInterface/Views/ResourceDetailsSidebarPanel.js:
     42        (WebInspector.ResourceDetailsSidebarPanel.prototype._createNameValueDataGrid.sortDataGrid.comparator):
     43        * UserInterface/Views/ResourceSidebarPanel.js:
     44        (WebInspector.ResourceSidebarPanel.prototype._compareTreeElements):
     45        * UserInterface/Views/ResourceTreeElement.js:
     46        (WebInspector.ResourceTreeElement.compareResourceTreeElements):
     47        (WebInspector.ResourceTreeElement.compareFolderAndResourceTreeElements):
     48        * UserInterface/Views/ScriptDetailsTimelineView.js:
     49        (WebInspector.ScriptDetailsTimelineView.prototype.dataGridSortComparator):
     50        * UserInterface/Views/StorageSidebarPanel.js:
     51        (WebInspector.StorageSidebarPanel.prototype._compareTreeElements):
     52        * UserInterface/Views/TimelineDataGrid.js:
     53        (WebInspector.TimelineDataGrid.prototype._sortComparator):
     54
    1552017-06-29  Devin Rousso  <drousso@apple.com>
    256
  • trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js

    r218908 r219014  
    672672});
    673673
     674Object.defineProperty(String.prototype, "extendedLocaleCompare",
     675{
     676    value(other)
     677    {
     678        return this.localeCompare(other, undefined, {numeric: true});
     679    }
     680});
     681
    674682Object.defineProperty(String, "tokenizeFormatString",
    675683{
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js

    r208304 r219014  
    283283
    284284                // Not numbers, sort as strings.
    285                 return a.localeCompare(b);
     285                return a.extendedLocaleCompare(b);
    286286            }
    287287
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/ResourceQueryController.js

    r204418 r219014  
    8383        return results.sort((a, b) => {
    8484            if (a.rank === b.rank)
    85                 return a.resource.displayName.localeCompare(b.resource.displayName);
     85                return a.resource.displayName.extendedLocaleCompare(b.resource.displayName);
    8686            return b.rank - a.rank;
    8787        });
  • trunk/Source/WebInspectorUI/UserInterface/Views/ApplicationCacheFrameContentView.js

    r208091 r219014  
    183183        function localeCompare(columnIdentifier, nodeA, nodeB)
    184184        {
    185              return (nodeA.data[columnIdentifier] + "").localeCompare(nodeB.data[columnIdentifier] + "");
     185             return (nodeA.data[columnIdentifier] + "").extendedLocaleCompare(nodeB.data[columnIdentifier] + "");
    186186        }
    187187
  • trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js

    r217072 r219014  
    13041304        properties = properties.filter(filterFunction);
    13051305        if (this._sortProperties)
    1306             properties.sort((a, b) => a.name.localeCompare(b.name));
     1306            properties.sort((a, b) => a.name.extendedLocaleCompare(b.name));
    13071307
    13081308        this._shownProperties = properties;
  • trunk/Source/WebInspectorUI/UserInterface/Views/CookieStorageContentView.js

    r208012 r219014  
    178178        function localeCompare(field, nodeA, nodeB)
    179179        {
    180             return (nodeA.data[field] + "").localeCompare(nodeB.data[field] + "");
     180            return (nodeA.data[field] + "").extendedLocaleCompare(nodeB.data[field] + "");
    181181        }
    182182
  • trunk/Source/WebInspectorUI/UserInterface/Views/DOMNodeDetailsSidebarPanel.js

    r218975 r219014  
    188188
    189189        let attributes = domNode.attributes();
    190         attributes.sort((a, b) => a.name.localeCompare(b.name));
     190        attributes.sort((a, b) => a.name.extendedLocaleCompare(b.name));
    191191        for (let attribute of attributes) {
    192192            let dataGridNode = new WebInspector.EditableDataGridNode(attribute);
     
    356356                    continue;
    357357
    358                 eventListenersForNode.sort((a, b) => a.type.toLowerCase().localeCompare(b.type.toLowerCase()));
     358                eventListenersForNode.sort((a, b) => a.type.toLowerCase().extendedLocaleCompare(b.type.toLowerCase()));
    359359
    360360                rows.push(createEventListenerSection(currentNode.displayName, eventListenersForNode, {hideNode: true}));
  • trunk/Source/WebInspectorUI/UserInterface/Views/DOMStorageContentView.js

    r205425 r219014  
    154154        function comparator(a, b)
    155155        {
    156             return a.data[sortColumnIdentifier].localeCompare(b.data[sortColumnIdentifier]);
     156            return a.data[sortColumnIdentifier].extendedLocaleCompare(b.data[sortColumnIdentifier]);
    157157        }
    158158
  • trunk/Source/WebInspectorUI/UserInterface/Views/DebuggerSidebarPanel.js

    r218356 r219014  
    898898            return 1;
    899899
    900         return a.mainTitle.localeCompare(b.mainTitle);
     900        return a.mainTitle.extendedLocaleCompare(b.mainTitle);
    901901    }
    902902
  • trunk/Source/WebInspectorUI/UserInterface/Views/FolderizedTreeElement.js

    r218544 r219014  
    238238
    239239        // Then sort by title.
    240         return a.mainTitle.localeCompare(b.mainTitle, undefined, {numeric: true});
     240        return a.mainTitle.extendedLocaleCompare(b.mainTitle);
    241241    }
    242242
  • trunk/Source/WebInspectorUI/UserInterface/Views/HeapSnapshotDataGridTree.js

    r217843 r219014  
    5959                if (!a.propertyName && b.propertyName)
    6060                    return multiplier * 1;
    61                 let propertyNameCompare = a.propertyName.localeCompare(b.propertyName);
     61                let propertyNameCompare = a.propertyName.extendedLocaleCompare(b.propertyName);
    6262                console.assert(propertyNameCompare !== 0, "Property names should be unique, we shouldn't have equal property names.");
    6363                return multiplier * propertyNameCompare;
     
    6565
    6666            // Sort by class name and object id if no property name.
    67             let classNameCompare = a.data.className.localeCompare(b.data.className);
     67            let classNameCompare = a.data.className.extendedLocaleCompare(b.data.className);
    6868            if (classNameCompare)
    6969                return multiplier * classNameCompare;
  • trunk/Source/WebInspectorUI/UserInterface/Views/NetworkTimelineView.js

    r215793 r219014  
    199199
    200200            if (displayName1 !== displayName2)
    201                 return displayName1.localeCompare(displayName2) * sortDirection;
    202 
    203             return node1.resource.url.localeCompare(node2.resource.url) * sortDirection;
     201                return displayName1.extendedLocaleCompare(displayName2) * sortDirection;
     202
     203            return node1.resource.url.extendedLocaleCompare(node2.resource.url) * sortDirection;
    204204        }
    205205
  • trunk/Source/WebInspectorUI/UserInterface/Views/NewTabContentView.js

    r208091 r219014  
    133133        let allTabClasses = Array.from(WebInspector.knownTabClasses());
    134134        let allowedTabClasses = allTabClasses.filter((tabClass) => tabClass.isTabAllowed() && !tabClass.isEphemeral());
    135         allowedTabClasses.sort((a, b) => a.tabInfo().title.localeCompare(b.tabInfo().title));
     135        allowedTabClasses.sort((a, b) => a.tabInfo().title.extendedLocaleCompare(b.tabInfo().title));
    136136
    137137        if (Array.shallowEqual(this._shownTabClasses, allowedTabClasses))
  • trunk/Source/WebInspectorUI/UserInterface/Views/OverviewTimelineView.js

    r205578 r219014  
    179179
    180180        // Fallback to comparing titles.
    181         return a.displayName().localeCompare(b.displayName());
     181        return a.displayName().extendedLocaleCompare(b.displayName());
    182182    }
    183183
  • trunk/Source/WebInspectorUI/UserInterface/Views/ProbeDetailsSidebarPanel.js

    r218975 r219014  
    6969            var aLocation = aProbeSet.breakpoint.sourceCodeLocation;
    7070            var bLocation = bProbeSet.breakpoint.sourceCodeLocation;
    71             var comparisonResult = aLocation.sourceCode.displayName.localeCompare(bLocation.sourceCode.displayName);
     71            var comparisonResult = aLocation.sourceCode.displayName.extendedLocaleCompare(bLocation.sourceCode.displayName);
    7272            if (comparisonResult !== 0)
    7373                return comparisonResult;
  • trunk/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js

    r218839 r219014  
    211211            return 1;
    212212        if (aNonMainTarget && bNonMainTarget)
    213             return a.displayName.localeCompare(b.displayName);
     213            return a.displayName.extendedLocaleCompare(b.displayName);
    214214
    215215        // "Main Frame" follows.
     
    229229            return 1;
    230230
    231         return a.displayName.localeCompare(b.displayName);
     231        return a.displayName.extendedLocaleCompare(b.displayName);
    232232    }
    233233
  • trunk/Source/WebInspectorUI/UserInterface/Views/ResourceDetailsSidebarPanel.js

    r218975 r219014  
    481481                var item1 = a.data[sortColumnIdentifier];
    482482                var item2 = b.data[sortColumnIdentifier];
    483                 return item1.localeCompare(item2);
     483                return item1.extendedLocaleCompare(item2);
    484484            }
    485485
  • trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js

    r218544 r219014  
    478478        console.assert(b.mainTitle);
    479479
    480         return (a.mainTitle || "").localeCompare(b.mainTitle || "");
     480        return (a.mainTitle || "").extendedLocaleCompare(b.mainTitle || "");
    481481    }
    482482
  • trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js

    r217912 r219014  
    4040    {
    4141        // Compare by type first to keep resources grouped by type when not sorted into folders.
    42         var comparisonResult = a.resource.type.localeCompare(b.resource.type);
     42        var comparisonResult = a.resource.type.extendedLocaleCompare(b.resource.type);
    4343        if (comparisonResult !== 0)
    4444            return comparisonResult;
     
    5454        // is on the same domain as the frame it will have an empty subtitle. This is good
    5555        // because empty string sorts first, so those will appear before external resources.
    56         comparisonResult = a.subtitle.localeCompare(b.subtitle);
     56        comparisonResult = a.subtitle.extendedLocaleCompare(b.subtitle);
    5757        if (comparisonResult !== 0)
    5858            return comparisonResult;
    5959
    6060        // Compare by title when the subtitles are the same.
    61         return a.mainTitle.localeCompare(b.mainTitle);
     61        return a.mainTitle.extendedLocaleCompare(b.mainTitle);
    6262    }
    6363
     
    7272            return 1;
    7373        if (aIsFolder && bIsFolder)
    74             return a.mainTitle.localeCompare(b.mainTitle);
     74            return a.mainTitle.extendedLocaleCompare(b.mainTitle);
    7575
    7676        return WebInspector.ResourceTreeElement.compareResourceTreeElements(a, b);
  • trunk/Source/WebInspectorUI/UserInterface/Views/ScriptDetailsTimelineView.js

    r205425 r219014  
    157157        let displayName2 = node2.displayName();
    158158        if (displayName1 !== displayName2)
    159             return displayName1.localeCompare(displayName2) * sortDirection;
    160 
    161         return node1.subtitle.localeCompare(node2.subtitle) * sortDirection;
     159            return displayName1.extendedLocaleCompare(displayName2) * sortDirection;
     160
     161        return node1.subtitle.extendedLocaleCompare(node2.subtitle) * sortDirection;
    162162    }
    163163
  • trunk/Source/WebInspectorUI/UserInterface/Views/StorageSidebarPanel.js

    r216147 r219014  
    5151        ];
    5252
    53         storageTypes.sort(function(a, b) { return a.title.localeCompare(b.title); });
     53        storageTypes.sort(function(a, b) { return a.title.extendedLocaleCompare(b.title); });
    5454
    5555        for (var info of storageTypes) {
     
    306306        console.assert(b.mainTitle);
    307307
    308         return (a.mainTitle || "").localeCompare(b.mainTitle || "");
     308        return (a.mainTitle || "").extendedLocaleCompare(b.mainTitle || "");
    309309    }
    310310
  • trunk/Source/WebInspectorUI/UserInterface/Views/TimelineDataGrid.js

    r217690 r219014  
    381381
    382382        if (typeof value1 === "string" && typeof value2 === "string")
    383             return value1.localeCompare(value2) * sortDirection;
     383            return value1.extendedLocaleCompare(value2) * sortDirection;
    384384
    385385        if (value1 instanceof WebInspector.CallFrame || value2 instanceof WebInspector.CallFrame) {
Note: See TracChangeset for help on using the changeset viewer.