Bug 224678

Summary: Web Inspector: add assertion for `WI.View` re-entrancy
Product: WebKit Reporter: Devin Rousso <hi>
Component: Web InspectorAssignee: Devin Rousso <hi>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, hi, inspector-bugzilla-changes, joepeck, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
See Also: https://bugs.webkit.org/show_bug.cgi?id=224648
https://bugs.webkit.org/show_bug.cgi?id=224650
Attachments:
Description Flags
Patch
none
Patch
none
Patch ews-feeder: commit-queue-

Description Devin Rousso 2021-04-16 10:09:12 PDT
.
Comment 1 Devin Rousso 2021-04-16 10:09:57 PDT
Created attachment 426244 [details]
Patch
Comment 2 Radar WebKit Bug Importer 2021-04-23 13:09:36 PDT
<rdar://problem/77083129>
Comment 3 BJ Burg 2021-04-26 11:11:34 PDT
Comment on attachment 426244 [details]
Patch

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

The usage of console.assert to have engineering-only reentrancy checks is clever. However, it's really hard to read. Could you instead use a helper function /lambda where this particular black magic lives?

It would be even clearer to have a ReentrancyChecker class with enter() and exit().

> Source/WebInspectorUI/ChangeLog:7
> +

Please explain why it's needed.
Comment 4 Devin Rousso 2021-05-03 19:21:27 PDT
Created attachment 427630 [details]
Patch
Comment 5 Joseph Pecoraro 2021-05-04 10:21:25 PDT
Comment on attachment 427630 [details]
Patch

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

> Source/WebInspectorUI/UserInterface/Views/View.js:297
> +        console.assert(WI.setReentrantCheck(this, "layout"), "ERROR: calling `layout` while already in it", this);

If an exception happens in layout, we're probably going to hit this a bunch eh? (We shouldn't have exceptions in layout, I'm just imagining how this can happen.
Comment 6 Joseph Pecoraro 2021-05-04 10:25:28 PDT
Comment on attachment 427630 [details]
Patch

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

> Source/WebInspectorUI/UserInterface/Base/Utilities.js:1789
> +WI.setReentrantCheck = function(object, key) {

Is this style normally to put opening brace on the following line? I'm fine either way.

> Source/WebInspectorUI/UserInterface/Base/Utilities.js:1797
> +    --object[key];

Might read better as the `(object[key] || 0) - 1` in case the key doesn't exist:

>>> --({}['x'])
NaN
Comment 7 Joseph Pecoraro 2021-05-04 10:26:39 PDT
Err, should we also remove this FIXME now? Or is there more to do?

    // FIXME: <https://webkit.org/b/224650> (Web Inspector: audit for re-entrancy issues with `initialLayout` and `layout`)
Comment 8 Devin Rousso 2021-05-04 10:27:42 PDT
Comment on attachment 427630 [details]
Patch

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

>> Source/WebInspectorUI/UserInterface/Base/Utilities.js:1789
>> +WI.setReentrantCheck = function(object, key) {
> 
> Is this style normally to put opening brace on the following line? I'm fine either way.

oh oops heh old habits 😅

>> Source/WebInspectorUI/UserInterface/Base/Utilities.js:1797
>> +    --object[key];
> 
> Might read better as the `(object[key] || 0) - 1` in case the key doesn't exist:

I was assuming that it would never get called without `WI.clearReentrantCheck`, but I think you make a good point.  I'll change.

>> Source/WebInspectorUI/UserInterface/Views/View.js:297
>> +        console.assert(WI.setReentrantCheck(this, "layout"), "ERROR: calling `layout` while already in it", this);
> 
> If an exception happens in layout, we're probably going to hit this a bunch eh? (We shouldn't have exceptions in layout, I'm just imagining how this can happen.

Yeah it's possible for this to spiral out of control, but like you said if we have an exception I think there's a bigger issue 😅
Comment 9 Devin Rousso 2021-05-04 10:29:15 PDT
(In reply to Joseph Pecoraro from comment #7)
> Err, should we also remove this FIXME now? Or is there more to do?
> 
>     // FIXME: <https://webkit.org/b/224650> (Web Inspector: audit for re-entrancy issues with `initialLayout` and `layout`)

That bug is more about looking through the code and making sure other cases aren't present.  This bug is about trying to make that easier (or at least more noticeable).
Comment 10 Devin Rousso 2021-05-04 10:31:11 PDT
Created attachment 427683 [details]
Patch
Comment 11 EWS 2021-05-04 12:03:58 PDT
Committed r276975 (237304@main): <https://commits.webkit.org/237304@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 427683 [details].