-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Use dynamicDowncast<T> more in html/ #20711
Conversation
EWS run on previous version of this PR (hash f6e3e58) |
There was a problem hiding this 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) } }; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- It is consistent with the other if checks above in this function
- If I move the
if (!isWebGPUType(contextId))
earlier, then we won't hit theASSERT_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())) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
f6e3e58
to
4b0a8ec
Compare
EWS run on current version of this PR (hash 4b0a8ec) |
4b0a8ec
to
d3aefea
Compare
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
d3aefea
to
ac61808
Compare
Committed 270960@main (ac61808): https://commits.webkit.org/270960@main Reviewed commits have been landed. Closing PR #20711 and removing active labels. |
ac61808
4b0a8ec