Bug 229644 - document.fonts.size needs to update style so it doesn't return stale values
Summary: document.fonts.size needs to update style so it doesn't return stale values
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Myles C. Maxfield
URL:
Keywords: InRadar
Depends on:
Blocks: 229850 229911
  Show dependency treegraph
 
Reported: 2021-08-28 00:27 PDT by Myles C. Maxfield
Modified: 2021-09-03 22:01 PDT (History)
11 users (show)

See Also:


Attachments
Patch (6.86 KB, patch)
2021-08-28 00:28 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (6.82 KB, patch)
2021-08-31 02:52 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (6.88 KB, patch)
2021-08-31 12:05 PDT, Myles C. Maxfield
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Myles C. Maxfield 2021-08-28 00:27:48 PDT
document.fonts.size needs to update style so it doesn't return stale values
Comment 1 Myles C. Maxfield 2021-08-28 00:28:41 PDT
Created attachment 436711 [details]
Patch
Comment 2 Simon Fraser (smfr) 2021-08-30 16:13:46 PDT
Comment on attachment 436711 [details]
Patch

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

> Source/WebCore/css/FontFaceSet.cpp:115
> +    return m_backing->faceCountAfterUpdatingStyle();

Can a style update destroy |this|?
Comment 3 Myles C. Maxfield 2021-08-31 02:52:30 PDT
Created attachment 436862 [details]
Patch
Comment 4 Myles C. Maxfield 2021-08-31 12:05:39 PDT
Created attachment 436923 [details]
Patch
Comment 5 Darin Adler 2021-08-31 14:02:34 PDT
Comment on attachment 436923 [details]
Patch

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

> Source/WebCore/css/CSSFontFaceSet.cpp:108
> +    auto protect = makeRef(const_cast<CSSFontFaceSet&>(*this));

Self-protecting is not the correct pattern for our reference counting. Instead callers should be protecting the pointers of objects before they call functions. Please talk to Ryosuke about this if you don’t agree.

Also, we don’t need makeRef for this any more; if we wanted a "protector" we could write:

    Ref protect = const_cast<CSSFontFaceSet&>(*this);

But probably won’t be doing that.

> Source/WebCore/css/CSSFontFaceSet.cpp:110
> +        m_owningFontSelector->fontStyleUpdateNeeded();

Names here don’t make sense to me. This function’s name says "after updating style" which sounds asynchronous, but the name of the function we are calling says "update needed", which sounds like a request to schedule something in the future, asynchronously or lazily.

> Source/WebCore/css/CSSFontSelector.h:92
> +    void fontStyleUpdateNeeded();

Should rename this so it’s clear it’s a synchronous operation, not a passive notification that triggers something lazy in the future (as mentioned above).

> Source/WebCore/css/FontFaceSet.cpp:115
> +    return m_backing->faceCountAfterUpdatingStyle();

I find this function confusing. When would you call the "bad face count" function that doesn’t update style? Names really don’t make that clear.

> Source/WebCore/dom/Document.cpp:7447
> +    updateStyleIfNeeded(); // FIXME: This is unnecessary. Instead, the actual accessors in the FontFaceSet need to update style.

Seems like a good direction.
Comment 6 Myles C. Maxfield 2021-09-01 02:38:22 PDT
Committed r281845 (241177@main): <https://commits.webkit.org/241177@main>
Comment 7 Radar WebKit Bug Importer 2021-09-01 02:39:18 PDT
<rdar://problem/82618851>