Bug 229061

Summary: Web Inspector: refactor `WI.ImageUtilities.scratchCanvasContext2D` to not use a callback
Product: WebKit Reporter: Devin Rousso <hi>
Component: Web InspectorAssignee: Devin Rousso <hi>
Status: NEW ---    
Severity: Normal CC: ews-watchlist, hi, inspector-bugzilla-changes, pangle, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch none

Description Devin Rousso 2021-08-12 17:22:41 PDT
Having a callback makes it unclear as to whether the function is async (it's not).  All of the callers expect it to be sync.
Comment 1 Devin Rousso 2021-08-12 17:29:37 PDT
Created attachment 435458 [details]
Patch
Comment 2 Patrick Angle 2021-08-13 09:45:59 PDT
Comment on attachment 435458 [details]
Patch

I thought about this some more, and I'm concerned it trades one confusing construct for another, less common, confusing construct. The call sites at first glance now read as loops, which to me invokes the question "Why does this work need to be done more than once", a question that much like the sync/async situation can only really be answered by a trip to the definition of `WI.ImageUtilities.scratchCanvasContext2D`. 

I enjoy this solution from a technical perspective, but I'm not sure it meets the stated goal in the changelog of making these call sites clearer. It's just unclear in a different way.
Comment 3 Devin Rousso 2021-08-13 11:14:19 PDT
Yeah FWIW this is kinda a "hack" of sorts 😅

I personally found that the loop looked better than a callback, but that's just me.
Comment 4 Radar WebKit Bug Importer 2021-08-19 17:23:24 PDT
<rdar://problem/82148919>