Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 3185431fb4843cf1912dbd122ae8d61ac6f35d2b
      
https://github.com/WebKit/WebKit/commit/3185431fb4843cf1912dbd122ae8d61ac6f35d2b
  Author: Rupin Mittal <ru...@apple.com>
  Date:   2025-07-11 (Fri, 11 Jul 2025)

  Changed paths:
    M Source/WebCore/Modules/cookie-consent/NavigatorCookieConsent.cpp
    M Source/WebCore/Modules/cookie-consent/NavigatorCookieConsent.h
    M Source/WebCore/SaferCPPExpectations/MemoryUnsafeCastCheckerExpectations
    M Source/WebCore/platform/Supplementable.h

  Log Message:
  -----------
  Introduce SupplementBase as a way to downcast Supplement<T>
https://bugs.webkit.org/show_bug.cgi?id=295721
rdar://155542045

Reviewed by Chris Dumez.

For the sake of safety, we often prefer to use downcast in place of
static_cast (the static analyzer catches cases where we should).

In order to use downcast, we may require a TypeCastsTraits specialization
which has an isType() function. This function takes in an argument with
the type of the base class and calls a function that returns true if the
instance is of the derived class and false if it's not.

Consider the case where class Bar inherits from Supplement<Foo> and we
want to downcast from Supplement<Foo> to Bar. Normally, Supplement<Foo>
would have a virtual function isBar() that returns false, and Bar would
override this function to return true. The isType() function in the
TypeCastsTraits specialization would call isBar() to determine if an
instance of Supplement<Foo> is also an instance of Bar.

But Supplement<Foo> is a class generated by the Supplement<T> template.
We cannot declare and implement the virtual function isBar() in the
template because class templates cannot contain virtual functions.

We fix this by creating a concrete base class SupplementBase that the
template Supplement<T> inherits from. Virtual functions like isBar() can be
declared + implemented here.

This patch adds this class and uses it to fix the static analysis warning
in NavigatorCookieConsent.cpp.

(Thank you to Wenson for helping come up with the idea).

* Source/WebCore/Modules/cookie-consent/NavigatorCookieConsent.cpp:
(WebCore::NavigatorCookieConsent::from):
* Source/WebCore/Modules/cookie-consent/NavigatorCookieConsent.h:
(isType):
* Source/WebCore/SaferCPPExpectations/MemoryUnsafeCastCheckerExpectations:
* Source/WebCore/platform/Supplementable.h:
(WebCore::SupplementBase::isNavigatorCookieConsent const):

Canonical link: https://commits.webkit.org/297255@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to