Bug 209030 - [Cocoa] Push applicationSDKVersion() down from WebCore into WTF
Summary: [Cocoa] Push applicationSDKVersion() down from WebCore into WTF
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: 208969
  Show dependency treegraph
 
Reported: 2020-03-12 17:55 PDT by Myles C. Maxfield
Modified: 2020-03-15 15:13 PDT (History)
26 users (show)

See Also:


Attachments
Patch (22.69 KB, patch)
2020-03-12 18:02 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (23.11 KB, patch)
2020-03-12 18:07 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (21.97 KB, patch)
2020-03-12 18:23 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (21.70 KB, patch)
2020-03-13 12:30 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (21.50 KB, patch)
2020-03-13 12:34 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (21.83 KB, patch)
2020-03-13 13:33 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (21.83 KB, patch)
2020-03-13 13:58 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (21.60 KB, patch)
2020-03-13 14:15 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (21.60 KB, patch)
2020-03-13 14:43 PDT, Myles C. Maxfield
simon.fraser: review+
Details | Formatted Diff | Diff
Patch for committing (21.58 KB, patch)
2020-03-13 15:36 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 2020-03-12 17:55:00 PDT
[Cocoa] Push applicationSDKVersion() down from WebCore into WTF
Comment 1 Myles C. Maxfield 2020-03-12 18:02:23 PDT
Created attachment 393433 [details]
Patch
Comment 2 Myles C. Maxfield 2020-03-12 18:07:05 PDT
Created attachment 393435 [details]
Patch
Comment 3 Alexey Proskuryakov 2020-03-12 18:15:28 PDT
Comment on attachment 393435 [details]
Patch

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

> Source/WTF/wtf/RuntimeApplicationChecks.h:40
> +WTF_EXPORT_PRIVATE void setApplicationSDKVersion(uint32_t);
> +WTF_EXPORT_PRIVATE uint32_t applicationSDKVersion();

Normally, public WTF symbols get exposed to the global namespace with "using", and then used without "WTF::".

> Source/WTF/wtf/RuntimeApplicationChecks.h:42
> +}

So,

using WTF::setApplicationSDKVersion;
using WTF::applicationSDKVersion;

here.
Comment 4 Myles C. Maxfield 2020-03-12 18:23:26 PDT
Created attachment 393437 [details]
Patch
Comment 5 Sam Weinig 2020-03-13 06:07:37 PDT
Comment on attachment 393437 [details]
Patch

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

> Source/WTF/ChangeLog:10
> +        * wtf/RuntimeApplicationChecks.h: Added.

If these are only going to be implemented on cocoa platforms and since the concept of an SDK version, at least as used here, is cocoa specific, I would put this header in wtf/cocoa/
Comment 6 Myles C. Maxfield 2020-03-13 12:30:52 PDT
Created attachment 393517 [details]
Patch
Comment 7 Myles C. Maxfield 2020-03-13 12:34:53 PDT
Created attachment 393518 [details]
Patch
Comment 8 Darin Adler 2020-03-13 13:06:37 PDT
Comment on attachment 393518 [details]
Patch

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

> Source/WebCore/html/MediaElementSession.cpp:52
> +#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>

To be a Cocoa-only header, this it needs to either have #if PLATFORM(COCOA) or a more specific #if around every include in any non-Cocoa-specific source file (doesn’t have it here), or have that #if in the header itself (good practice, I think but doesn’t have it in this patch), or both.

Smallest change I think would be to just move this include down inside the IOS_FAMILY where the old dyldSPI.h include was before.

> Source/WebCore/platform/RuntimeApplicationChecks.h:32
> +#if PLATFORM(COCOA)
> +#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
> +#endif

Why? Doesn’t seem to be used in this header.
Comment 9 Myles C. Maxfield 2020-03-13 13:33:10 PDT
Created attachment 393522 [details]
Patch
Comment 10 Myles C. Maxfield 2020-03-13 13:58:47 PDT
Created attachment 393526 [details]
Patch
Comment 11 Myles C. Maxfield 2020-03-13 14:15:32 PDT
Created attachment 393528 [details]
Patch
Comment 12 Myles C. Maxfield 2020-03-13 14:43:21 PDT
Created attachment 393532 [details]
Patch
Comment 13 Simon Fraser (smfr) 2020-03-13 14:53:05 PDT
Comment on attachment 393532 [details]
Patch

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

> Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.cpp:27
> +#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>

Shouldn't this be included as "RuntimeApplicationChecksCocoa.h" here?
Comment 14 Myles C. Maxfield 2020-03-13 15:36:07 PDT
Created attachment 393541 [details]
Patch for committing
Comment 15 Myles C. Maxfield 2020-03-13 16:13:30 PDT
(In reply to Simon Fraser (smfr) from comment #13)
> Comment on attachment 393532 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=393532&action=review
> 
> > Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.cpp:27
> > +#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
> 
> Shouldn't this be included as "RuntimeApplicationChecksCocoa.h" here?

If you grep for "include <wtf/" inside the WTF folder, you get 1476 results among 750 files. I was following what appears to be the standard way to do it.
Comment 16 Myles C. Maxfield 2020-03-13 16:33:49 PDT
Committed r258447: <https://trac.webkit.org/changeset/258447>
Comment 17 Radar WebKit Bug Importer 2020-03-13 16:34:17 PDT
<rdar://problem/60439292>
Comment 18 Keith Miller 2020-03-13 23:06:44 PDT
This is my kinda patch. Embrace the WTF!
Comment 19 Darin Adler 2020-03-15 15:13:54 PDT
Comment on attachment 393541 [details]
Patch for committing

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

I have some suggested refinements; no rush to do these.

One thing is that we should do something so that if someone tries to use dyld_get_program_sdk_version directly in the future, a macro trick makes it a compile-time error. Or any other tempting function that will definitely do the wrong thing in the non-UI process.

> Source/JavaScriptCore/API/JSWrapperMap.mm:726
>      static uint32_t programSDKVersion = 0;
>      if (!programSDKVersion)
> -        programSDKVersion = dyld_get_program_sdk_version();
> +        programSDKVersion = applicationSDKVersion();

Should just be a one-liner:

    static uint32_t programSDKVersion = applicationSDKVersion();

But really what we should be memo-izing is the entire boolean value for supportsInitMethodConstructors, not the two different version number integers (JavaScript and SDK).

    static bool supportsInitMethodConstructors = [] {
        ... all the code here, with no caching of anything in global variables ...
    }();
    return supportsInitMethodConstructors;

I’m also wondering if this code is sufficiently thread-safe.

> Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.cpp:2
> + * Copyright (C) 2011-2020 Apple Inc. All rights reserved.

Is there really code dating back to 2011 in the three functions in this file?

> Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.cpp:36
> +    static NeverDestroyed<Optional<uint32_t>> version;

NeverDestroyed should not be needed here. I believe Optional goes out of its way to not add a non-trivial destructor in a case like this. If we remove the use of NeverDestroyed, we’ll get a compilation error if I’m wrong, given the warnings we have turned on.

> Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h:2
> + * Copyright (C) 2009-2020 Apple Inc. All rights reserved.

Do the two function declarations in this header really qualify as code that dates back to 2009?

> Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h:28
> +#include <wtf/Forward.h>

Unneeded include. If it is needed, I don’t understand why. The export macros come from ExportMacros.h which seems to be part of config.h, so no need to include it. And uint32_t comes from <stdint.h> or <cstdint>. Neither comes rom Forward.h.

> Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h:31
> +// This contains the values with which to compare the return value of applicationSDKVersion().
> +#include <wtf/spi/darwin/dyldSPI.h>

That explains why files that use this to check the SDK version will need to include this header. It does not justify including this in this header. The source file that just calls setApplicationSDKVersion ends up including this unnecessarily. I suggest adding these includes back to the .cpp files where they are used.