Bug 173747

Summary: Web Inspector: Use Element.closest for internal code
Product: WebKit Reporter: Nikita Vasilyev <nvasilyev>
Component: Web InspectorAssignee: Devin Rousso <drousso>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, drousso, Hironori.Fujii, inspector-bugzilla-changes, joepeck, webkit-bug-importer
Priority: P2 Keywords: GoodFirstBug, InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch none

Description Nikita Vasilyev 2017-06-22 16:56:55 PDT
There're a few methods defined in Utilities.js that could be replaced by Element.prototype.closest[1]:

    Node.prototype.enclosingNodeOrSelfWithClass
    Node.prototype.enclosingNodeOrSelfWithNodeName
    Node.prototype.enclosingNodeOrSelfWithNodeNameInArray

[1]: https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
Comment 1 Devin Rousso 2019-02-27 13:48:33 PST
Created attachment 363127 [details]
Patch

I haven't tested every single case, but the ones I did worked fine :)
Comment 2 Joseph Pecoraro 2019-02-27 15:12:23 PST
Comment on attachment 363127 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=363127&action=review

r=me

> Source/WebInspectorUI/UserInterface/Base/Main.js:2340
> +        let contentBrowserElement = this.currentFocusElement.closest("content-browser");

This should be ".content-browser"
Comment 3 Devin Rousso 2019-02-27 15:15:00 PST
Created attachment 363137 [details]
Patch
Comment 4 WebKit Commit Bot 2019-02-27 15:54:48 PST
Comment on attachment 363137 [details]
Patch

Clearing flags on attachment: 363137

Committed r242174: <https://trac.webkit.org/changeset/242174>
Comment 5 WebKit Commit Bot 2019-02-27 15:54:49 PST
All reviewed patches have been landed.  Closing bug.
Comment 6 Radar WebKit Bug Importer 2019-02-27 15:55:40 PST
<rdar://problem/48454502>
Comment 7 Fujii Hironori 2020-02-06 02:39:43 PST
Comment on attachment 363137 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=363137&action=review

> Source/WebInspectorUI/UserInterface/Views/LogContentView.js:536
> +                wrapper = selection.focusNode.closest("." + WI.LogContentView.ItemWrapperStyleClassName);

selection.focusNode isn't necessarily an Element. 
Filed: Bug 207248 – [Web Inspector][WinCairo] Selecting an error message in Console causes "TypeError:​ selection.focusNode.closest is not a function."