Bug 156929 - [Cocoa] Guarantee FontPlatformData's m_cgFont is never nullptr
Summary: [Cocoa] Guarantee FontPlatformData's m_cgFont is never nullptr
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:
Depends on:
Blocks:
 
Reported: 2016-04-22 13:54 PDT by Myles C. Maxfield
Modified: 2016-04-25 20:53 PDT (History)
2 users (show)

See Also:


Attachments
Patch (9.05 KB, patch)
2016-04-22 13:54 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
WIP (13.26 KB, patch)
2016-04-22 14:00 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (17.86 KB, patch)
2016-04-22 17:07 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (19.30 KB, patch)
2016-04-22 18:33 PDT, Myles C. Maxfield
darin: review+
Details | Formatted Diff | Diff
Patch for committing (19.76 KB, patch)
2016-04-25 19:05 PDT, Myles C. Maxfield
no flags 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 2016-04-22 13:54:34 PDT
[Cocoa] Guarantee FontPlatformData's m_cgFont is never nullptr
Comment 1 Myles C. Maxfield 2016-04-22 13:54:59 PDT
Created attachment 277097 [details]
Patch
Comment 2 Myles C. Maxfield 2016-04-22 14:00:21 PDT
Created attachment 277098 [details]
WIP
Comment 3 WebKit Commit Bot 2016-04-22 14:05:48 PDT
Attachment 277098 [details] did not pass style-queue:


ERROR: Source/WebCore/ChangeLog:8:  You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.  [changelog/nonewtests] [5]
Total errors found: 1 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Myles C. Maxfield 2016-04-22 17:07:43 PDT
Created attachment 277118 [details]
Patch
Comment 5 Myles C. Maxfield 2016-04-22 17:39:19 PDT
I should delete FontPlatformData::setFont()
Comment 6 Chris Dumez 2016-04-22 18:20:54 PDT
Does not build?
Comment 7 Myles C. Maxfield 2016-04-22 18:33:17 PDT
Created attachment 277126 [details]
Patch
Comment 8 Darin Adler 2016-04-23 16:52:48 PDT
Comment on attachment 277126 [details]
Patch

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

r=me if you fix the Windows build

> Source/WebCore/platform/graphics/FontPlatformData.cpp:60
>      m_cgFont = cgFont;

Could we construct this instead of initializing it?

> Source/WebCore/platform/graphics/FontPlatformData.h:-221
> -#if USE(CG)
> -    void setFallbackCGFont();
> -#endif

Broke the Windows build, which is still trying to call this function.

> Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm:265
> -            ASSERT(CFGetTypeID(runCTFont) == CTFontGetTypeID());
> +            ASSERT(runCTFont && CFGetTypeID(runCTFont) == CTFontGetTypeID());

If you want to add an assertion about this not being null, then it should be a separate assertion; we don’t use &&.

But also, CFGetTypeID is already a function that crashes when passed null; I don’t think we really need any change here.

> Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp:44
> +    ASSERT(font);

Is this really guaranteed?

> Source/WebCore/platform/mac/DragImageMac.mm:336
> +    if (drawURLString && urlFont) {

Doesn’t seem like we need this.

> Source/WebCore/platform/mac/DragImageMac.mm:343
> +    if (labelFont) {

Doesn’t seem like we need this.

> Source/WebKit/mac/Misc/WebStringTruncator.mm:65
> +    if (!menuFont.get())
> +        return nil;

I don’t think we need this. No chance of getting nil for the menu font. Probably don’t need the assertion either, since fontFromNSFont asserts.

> Source/WebKit/mac/Misc/WebStringTruncator.mm:73
> +    if (!font)
> +        return nil;

Returning @"" or returning the string without doing truncation would be better than returning nil.

> Source/WebKit/mac/Misc/WebStringTruncator.mm:81
> +    if (!font)
> +        return nil;

Returning @"" or returning the string without doing truncation would be better than returning nil.
Comment 9 Myles C. Maxfield 2016-04-25 19:05:59 PDT
Created attachment 277304 [details]
Patch for committing
Comment 10 Myles C. Maxfield 2016-04-25 20:53:08 PDT
Committed r200070: <http://trac.webkit.org/changeset/200070>