Bug 224678 - Web Inspector: add assertion for `WI.View` re-entrancy
Summary: Web Inspector: add assertion for `WI.View` re-entrancy
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-04-16 10:09 PDT by Devin Rousso
Modified: 2021-05-04 13:36 PDT (History)
6 users (show)

See Also:


Attachments
Patch (3.00 KB, patch)
2021-04-16 10:09 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (4.53 KB, patch)
2021-05-03 19:21 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (4.55 KB, patch)
2021-05-04 10:31 PDT, Devin Rousso
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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].