Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dynamicDowncast<T> more in html/ #20711

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

cdumez
Copy link
Contributor

@cdumez cdumez commented Nov 18, 2023

ac61808

Use dynamicDowncast<T> more in html/
https://bugs.webkit.org/show_bug.cgi?id=265092

Reviewed by Jean-Yves Avenard.

Use dynamicDowncast<T> more in html/.

I did a little bit of smart pointer adoption on the lines I
changed too.

* Source/WebCore/html/BaseDateAndTimeInputType.cpp:
(WebCore::BaseDateAndTimeInputType::updateInnerTextValue):
* Source/WebCore/html/CachedHTMLCollectionInlines.h:
(WebCore::nameShouldBeVisibleInDocumentAll):
* Source/WebCore/html/CanvasBase.cpp:
(WebCore:: const):
* Source/WebCore/html/CustomPaintCanvas.cpp:
(WebCore::CustomPaintCanvas::getContext):
* Source/WebCore/html/DOMFormData.cpp:
(WebCore::createFileEntry):
* Source/WebCore/html/FTPDirectoryDocument.cpp:
(WebCore::FTPDirectoryDocumentParser::loadDocumentTemplate):
* Source/WebCore/html/FeaturePolicy.cpp:
(WebCore::isFeaturePolicyAllowedByDocumentAndAllOwners):
* Source/WebCore/html/FileInputType.cpp:
(isType):
* Source/WebCore/html/FormController.cpp:
(WebCore::shouldBeUsedForFormSignature):
* Source/WebCore/html/GenericCachedHTMLCollection.cpp:
(WebCore::GenericCachedHTMLCollection<traversalType>::elementMatches const):
* Source/WebCore/html/HTMLAnchorElement.cpp:
(WebCore::appendServerMapMousePosition):
(WebCore::HTMLAnchorElement::defaultEventHandler):
(WebCore::HTMLAnchorElement::eventType):
(WebCore::isEnterKeyKeydownEvent):
* Source/WebCore/html/HTMLAreaElement.cpp:
(WebCore::HTMLAreaElement::imageElement const):
(WebCore::HTMLAreaElement::setFocus):
* Source/WebCore/html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::enclosingImageElement const):
* Source/WebCore/html/HTMLAudioElement.h:
(isType):
* Source/WebCore/html/HTMLButtonElement.cpp:
(WebCore::HTMLButtonElement::defaultEventHandler):
* Source/WebCore/html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContext):
(WebCore::HTMLCanvasElement::didDraw):
(WebCore::HTMLCanvasElement::reset):
(WebCore::HTMLCanvasElement::getImageData):
(WebCore::HTMLCanvasElement::toVideoFrame):
(WebCore::HTMLCanvasElement::setImageBufferAndMarkDirty):
(WebCore::HTMLCanvasElement::clearImageBuffer const):
(WebCore::HTMLCanvasElement::virtualHasPendingActivity const):
* Source/WebCore/html/HTMLCanvasElement.h:
* Source/WebCore/html/HTMLCollection.cpp:
(WebCore::HTMLCollection::updateNamedElementCache const):
* Source/WebCore/html/HTMLDetailsElement.cpp:
(WebCore::DetailsSlotAssignment::slotNameForHostChild const):
* Source/WebCore/html/HTMLDocument.cpp:
(WebCore::HTMLDocument::namedItem):
* Source/WebCore/html/HTMLDocument.h:
(isType):
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::elementAffectsDirectionality):
(WebCore::HTMLElement::editabilityFromContentEditableAttr):
(WebCore::HTMLElement::insertedIntoAncestor):
(WebCore::HTMLElement::setOuterText):
(WebCore::HTMLElement::computeDirectionalityFromText const):
(WebCore::HTMLElement::dirAttributeChanged):
(WebCore::HTMLElement::canBeActuallyDisabled const):
(WebCore::checkPopoverValidity):

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

4b0a8ec

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  gtk
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv-sim
βœ… πŸ›  watch
βœ… πŸ›  πŸ§ͺ unsafe-merge βœ… πŸ›  watch-sim

@cdumez cdumez requested a review from rniwa as a code owner November 18, 2023 22:05
@cdumez cdumez self-assigned this Nov 18, 2023
@cdumez cdumez added the DOM For bugs specific to XML/HTML DOM elements (including parsing). label Nov 18, 2023
Copy link
Member

@jyavenard jyavenard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with nit/questions

return std::optional<RenderingContext> { RefPtr<WebGL2RenderingContext> { &downcast<WebGL2RenderingContext>(*m_context) } };
if (auto* context = dynamicDowncast<WebGLRenderingContext>(*m_context))
return std::optional<RenderingContext> { RefPtr { context } };
return std::optional<RenderingContext> { RefPtr { &downcast<WebGL2RenderingContext>(*m_context) } };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be checkedDowncast even if it was just a debug assert before (considering a lot of the changes add safety check such as going from raw pointers to RefPtr)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can make this a checkedDowncast<>().

}
#endif

if (m_context->isWebGPU()) {
if (auto* context = dynamicDowncast<GPUCanvasContext>(m_context.get())) {
if (!isWebGPUType(contextId))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existing, but isWebGPUType test could be moved up. potentially remove one check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will look into making this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into it a bit more and I think I prefer to leave the code as is because:

  1. It is consistent with the other if checks above in this function
  2. If I move the if (!isWebGPUType(contextId)) earlier, then we won't hit the ASSERT_NOT_REACHED() later in this function if we fail to deal with a particular context type.

@@ -584,8 +582,8 @@ void HTMLCanvasElement::reset()
int w = limitToOnlyHTMLNonNegative(attributeWithoutSynchronization(widthAttr), defaultWidth);
int h = limitToOnlyHTMLNonNegative(attributeWithoutSynchronization(heightAttr), defaultHeight);

if (is<CanvasRenderingContext2D>(m_context))
downcast<CanvasRenderingContext2D>(*m_context).reset();
if (RefPtr context = dynamicDowncast<CanvasRenderingContext2D>(m_context.get()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to take a ref here?

this replacement pattern is repeated multiple times, maybe worth a mention in the commit log as it's not just a replacement with dynamicDowncast

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will mention in the commit log. I did a little of smart pointer adoption in the patch too, on the lines I changed. Here we're calling a non-trivial function on the context so we're expected to be holding a local RefPtr/Ref to the context.

@cdumez cdumez added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Nov 20, 2023
https://bugs.webkit.org/show_bug.cgi?id=265092

Reviewed by Jean-Yves Avenard.

Use dynamicDowncast<T> more in html/.

I did a little bit of smart pointer adoption on the lines I
changed too.

* Source/WebCore/html/BaseDateAndTimeInputType.cpp:
(WebCore::BaseDateAndTimeInputType::updateInnerTextValue):
* Source/WebCore/html/CachedHTMLCollectionInlines.h:
(WebCore::nameShouldBeVisibleInDocumentAll):
* Source/WebCore/html/CanvasBase.cpp:
(WebCore:: const):
* Source/WebCore/html/CustomPaintCanvas.cpp:
(WebCore::CustomPaintCanvas::getContext):
* Source/WebCore/html/DOMFormData.cpp:
(WebCore::createFileEntry):
* Source/WebCore/html/FTPDirectoryDocument.cpp:
(WebCore::FTPDirectoryDocumentParser::loadDocumentTemplate):
* Source/WebCore/html/FeaturePolicy.cpp:
(WebCore::isFeaturePolicyAllowedByDocumentAndAllOwners):
* Source/WebCore/html/FileInputType.cpp:
(isType):
* Source/WebCore/html/FormController.cpp:
(WebCore::shouldBeUsedForFormSignature):
* Source/WebCore/html/GenericCachedHTMLCollection.cpp:
(WebCore::GenericCachedHTMLCollection<traversalType>::elementMatches const):
* Source/WebCore/html/HTMLAnchorElement.cpp:
(WebCore::appendServerMapMousePosition):
(WebCore::HTMLAnchorElement::defaultEventHandler):
(WebCore::HTMLAnchorElement::eventType):
(WebCore::isEnterKeyKeydownEvent):
* Source/WebCore/html/HTMLAreaElement.cpp:
(WebCore::HTMLAreaElement::imageElement const):
(WebCore::HTMLAreaElement::setFocus):
* Source/WebCore/html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::enclosingImageElement const):
* Source/WebCore/html/HTMLAudioElement.h:
(isType):
* Source/WebCore/html/HTMLButtonElement.cpp:
(WebCore::HTMLButtonElement::defaultEventHandler):
* Source/WebCore/html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContext):
(WebCore::HTMLCanvasElement::didDraw):
(WebCore::HTMLCanvasElement::reset):
(WebCore::HTMLCanvasElement::getImageData):
(WebCore::HTMLCanvasElement::toVideoFrame):
(WebCore::HTMLCanvasElement::setImageBufferAndMarkDirty):
(WebCore::HTMLCanvasElement::clearImageBuffer const):
(WebCore::HTMLCanvasElement::virtualHasPendingActivity const):
* Source/WebCore/html/HTMLCanvasElement.h:
* Source/WebCore/html/HTMLCollection.cpp:
(WebCore::HTMLCollection::updateNamedElementCache const):
* Source/WebCore/html/HTMLDetailsElement.cpp:
(WebCore::DetailsSlotAssignment::slotNameForHostChild const):
* Source/WebCore/html/HTMLDocument.cpp:
(WebCore::HTMLDocument::namedItem):
* Source/WebCore/html/HTMLDocument.h:
(isType):
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::elementAffectsDirectionality):
(WebCore::HTMLElement::editabilityFromContentEditableAttr):
(WebCore::HTMLElement::insertedIntoAncestor):
(WebCore::HTMLElement::setOuterText):
(WebCore::HTMLElement::computeDirectionalityFromText const):
(WebCore::HTMLElement::dirAttributeChanged):
(WebCore::HTMLElement::canBeActuallyDisabled const):
(WebCore::checkPopoverValidity):

Canonical link: https://commits.webkit.org/270960@main
@webkit-commit-queue
Copy link
Collaborator

Committed 270960@main (ac61808): https://commits.webkit.org/270960@main

Reviewed commits have been landed. Closing PR #20711 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit ac61808 into WebKit:main Nov 20, 2023
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DOM For bugs specific to XML/HTML DOM elements (including parsing).
Projects
None yet
4 participants