Replace some stack raw pointers with RefPtrs within WebCore/svg.
<rdar://problem/34842204>
Created attachment 326109 [details] Patch
Created attachment 326159 [details] Patch
Attachment 326159 [details] did not pass style-queue: ERROR: Source/WebCore/svg/animation/SMILTimeContainer.cpp:291: 'resultElement' is incorrectly named. It should be named 'protector' or 'protectedNullptr'. [readability/naming/protected] [4] ERROR: Source/WebCore/svg/SVGSVGElement.cpp:641: 'view' is incorrectly named. It should be named 'protector' or 'protectedViewSpec'. [readability/naming/protected] [4] ERROR: Source/WebCore/svg/SVGDocumentExtensions.cpp:275: 'element' is incorrectly named. It should be named 'protector' or 'protectedFirstElement'. [readability/naming/protected] [4] Total errors found: 3 in 61 files If any of these errors are false positives, please file a bug against check-webkit-style.
Created attachment 326168 [details] Patch
Attachment 326168 [details] did not pass style-queue: ERROR: Source/WebCore/svg/SVGSVGElement.cpp:641: 'view' is incorrectly named. It should be named 'protector' or 'protectedViewSpec'. [readability/naming/protected] [4] ERROR: Source/WebCore/svg/SVGDocumentExtensions.cpp:275: 'element' is incorrectly named. It should be named 'protector' or 'protectedFirstElement'. [readability/naming/protected] [4] Total errors found: 2 in 61 files If any of these errors are false positives, please file a bug against check-webkit-style.
Comment on attachment 326168 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=326168&action=review > Source/WebCore/rendering/svg/RenderSVGModelObject.cpp:119 > - SVGElement* stopAtElement = SVGLocatable::nearestViewportElement(element); > + auto* stopAtElement = SVGLocatable::nearestViewportElement(element); Why are we not using RefPtr here? > Source/WebCore/svg/SVGAElement.cpp:128 > - Element* targetElement = treeScope().getElementById(url.substringSharingImpl(1)); > + RefPtr<Element> targetElement = treeScope().getElementById(url.substringSharingImpl(1)); Use makeRefPtr? > Source/WebCore/svg/SVGAElement.cpp:144 > - Frame* frame = document().frame(); > + RefPtr<Frame> frame = document().frame(); Use makeRefPtr? > Source/WebCore/svg/SVGAnimateElementBase.cpp:87 > - SVGElement* targetElement = this->targetElement(); > + RefPtr<SVGElement> targetElement = this->targetElement(); Ditto. > Source/WebCore/svg/SVGAnimateElementBase.cpp:189 > - SVGElement* targetElement = this->targetElement(); > + RefPtr<SVGElement> targetElement = this->targetElement(); Ditto. > Source/WebCore/svg/SVGAnimateElementBase.cpp:339 > - SVGElement* targetElement = this->targetElement(); > + RefPtr<SVGElement> targetElement = this->targetElement(); Ditto. > Source/WebCore/svg/SVGAnimateMotionElement.cpp:59 > - SVGElement* targetElement = this->targetElement(); > + RefPtr<SVGElement> targetElement = this->targetElement(); Ditto. > Source/WebCore/svg/SVGAnimateMotionElement.cpp:168 > - SVGElement* targetElement = this->targetElement(); > + RefPtr<SVGElement> targetElement = this->targetElement(); Ditto. > Source/WebCore/svg/SVGAnimateMotionElement.cpp:-234 > - SVGElement* targetElement = this->targetElement(); Ditto. > Source/WebCore/svg/SVGAnimateMotionElement.cpp:-274 > - SVGElement* targetElement = this->targetElement(); Ditto. > Source/WebCore/svg/SVGAnimationElement.cpp:646 > - Element* parent = targetElement->parentElement(); > + RefPtr<Element> parent = targetElement->parentElement(); Ditto. > Source/WebCore/svg/SVGAnimationElement.cpp:665 > - SVGElement* targetElement = this->targetElement(); > + RefPtr<SVGElement> targetElement = this->targetElement(); Ditto. > Source/WebCore/svg/SVGElement.cpp:291 > - if (SVGElement* correspondingElement = m_svgRareData->correspondingElement()) > + if (RefPtr<SVGElement> correspondingElement = m_svgRareData->correspondingElement()) Ditto. > Source/WebCore/svg/SVGElement.cpp:449 > - if (SVGElement* oldCorrespondingElement = m_svgRareData->correspondingElement()) > + if (RefPtr<SVGElement> oldCorrespondingElement = m_svgRareData->correspondingElement()) Ditto. > Source/WebCore/svg/SVGElement.cpp:762 > - if (Element* parent = parentOrShadowHostElement()) { > + if (RefPtr<Element> parent = parentOrShadowHostElement()) { Ditto. > Source/WebCore/svg/SVGElement.cpp:1089 > - ContainerNode* node = parentNode(); > + RefPtr<ContainerNode> node = parentNode(); Ditto. > Source/WebCore/svg/SVGElement.cpp:1132 > + RefPtr<SVGElement> instance = *instances.begin(); Ditto. > Source/WebCore/svg/SVGFEImageElement.cpp:105 > - Element* target = SVGURIReference::targetElementFromIRIString(href(), document(), &id); > + RefPtr<Element> target = SVGURIReference::targetElementFromIRIString(href(), document(), &id); Ditto. > Source/WebCore/svg/SVGFEImageElement.cpp:176 > - Element* parent = parentElement(); > + RefPtr<Element> parent = parentElement(); Ditto. > Source/WebCore/svg/SVGFELightElement.cpp:82 > - SVGFELightElement* lightNode = findLightElement(svgElement); > + RefPtr<SVGFELightElement> lightNode = findLightElement(svgElement); Ditto. > Source/WebCore/svg/SVGFELightElement.cpp:178 > - ContainerNode* parent = parentNode(); > + RefPtr<ContainerNode> parent = parentNode(); Ditto. > Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.cpp:157 > - ContainerNode* parent = element->parentNode(); > + RefPtr<ContainerNode> parent = element->parentNode(); Ditto. > Source/WebCore/svg/SVGFontFaceElement.cpp:266 > - if (CSSFontFaceSrcValue* item = downcast<CSSFontFaceSrcValue>(srcList->itemWithoutBoundsCheck(i))) > + if (RefPtr<CSSFontFaceSrcValue> item = downcast<CSSFontFaceSrcValue>(srcList->itemWithoutBoundsCheck(i))) Ditto. > Source/WebCore/svg/SVGFontFaceFormatElement.cpp:50 > - ContainerNode* ancestor = parentNode()->parentNode(); > + RefPtr<ContainerNode> ancestor = parentNode()->parentNode(); Ditto. > Source/WebCore/svg/SVGFontFaceUriElement.cpp:79 > - ContainerNode* grandparent = parentNode()->parentNode(); > + RefPtr<ContainerNode> grandparent = parentNode()->parentNode(); Ditto. > Source/WebCore/svg/SVGForeignObjectElement.cpp:145 > - Element* ancestor = parentElement(); > + RefPtr<Element> ancestor = parentElement(); Ditto. > Source/WebCore/svg/SVGLengthContext.cpp:304 > - SVGElement* viewportElement = m_context->viewportElement(); > + RefPtr<SVGElement> viewportElement = m_context->viewportElement(); Ditto. > Source/WebCore/svg/SVGLinearGradientElement.cpp:165 > - Node* refNode = SVGURIReference::targetElementFromIRIString(current->href(), document()); > + RefPtr<Node> refNode = SVGURIReference::targetElementFromIRIString(current->href(), document()); Ditto. > Source/WebCore/svg/SVGMPathElement.cpp:65 > - Element* target = SVGURIReference::targetElementFromIRIString(href(), document(), &id); > + RefPtr<Element> target = SVGURIReference::targetElementFromIRIString(href(), document(), &id); Ditto. > Source/WebCore/svg/SVGRadialGradientElement.cpp:181 > - Node* refNode = SVGURIReference::targetElementFromIRIString(current->href(), document()); > + RefPtr<Node> refNode = SVGURIReference::targetElementFromIRIString(current->href(), document()); Ditto. > Source/WebCore/svg/SVGSVGElement.cpp:175 > - Frame* frame = document().frame(); > + RefPtr<Frame> frame = document().frame(); Ditto. > Source/WebCore/svg/SVGSVGElement.cpp:376 > + if (RefPtr<Frame> frame = document().frame()) Ditto. > Source/WebCore/svg/SVGSVGElement.cpp:456 > - if (FrameView* view = document().view()) { > + if (RefPtr<FrameView> view = document().view()) { Ditto. > Source/WebCore/svg/SVGSVGElement.cpp:641 > - SVGViewSpec* view = m_viewSpec.get(); > + RefPtr<SVGViewSpec> view(m_viewSpec); Ditto. > Source/WebCore/svg/SVGSVGElement.cpp:725 > - Element* element = treeScope().getElementById(id); > + RefPtr<Element> element = treeScope().getElementById(id); Ditto. > Source/WebCore/svg/SVGStyleElement.cpp:58 > - if (CSSStyleSheet* styleSheet = sheet()) > + if (RefPtr<CSSStyleSheet> styleSheet = sheet()) Ditto. > Source/WebCore/svg/SVGTRefElement.cpp:166 > - Node* container = shadowRoot()->firstChild(); > + RefPtr<Node> container = shadowRoot()->firstChild(); Ditto. > Source/WebCore/svg/SVGTextPathElement.cpp:159 > - Element* target = SVGURIReference::targetElementFromIRIString(href(), document(), &id); > + RefPtr<Element> target = SVGURIReference::targetElementFromIRIString(href(), document(), &id); Ditto. > Source/WebCore/svg/SVGUseElement.cpp:145 > - SVGElement* correspondingElement = shadowElement.correspondingElement(); > + RefPtr<SVGElement> correspondingElement = shadowElement.correspondingElement(); Ditto. > Source/WebCore/svg/animation/SVGSMILElement.cpp:266 > - SVGSVGElement* owner = ownerSVGElement(); > + RefPtr<SVGSVGElement> owner = ownerSVGElement(); Ditto. > Source/WebCore/svg/animation/SVGSMILElement.cpp:547 > - Element* eventBase = eventBaseFor(condition); > + RefPtr<Element> eventBase = eventBaseFor(condition); Ditto. > Source/WebCore/svg/animation/SVGSMILElement.cpp:582 > - Element* eventBase = eventBaseFor(condition); > + RefPtr<Element> eventBase = eventBaseFor(condition); Ditto. > Source/WebCore/svg/graphics/SVGImage.cpp:288 > - FrameView* view = frameView(); > + RefPtr<FrameView> view = frameView(); Ditto. > Source/WebCore/svg/graphics/SVGImage.cpp:412 > - Document* document = m_page->mainFrame().document(); > + RefPtr<Document> document = m_page->mainFrame().document(); Ditto. > Source/WebCore/svg/graphics/filters/SVGFEImage.cpp:121 > + RefPtr<SVGElement> contextNode = downcast<SVGElement>(renderer->element()); Ditto. > Source/WebCore/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h:93 > - SVGPathElement* pathElement = downcast<SVGPathElement>(contextElement()); > + RefPtr<SVGPathElement> pathElement = downcast<SVGPathElement>(contextElement()); Ditto. > Source/WebCore/svg/properties/SVGListPropertyTearOff.h:144 > - ListItemTearOff* item = m_wrappers->at(i); > + RefPtr<ListItemTearOff> item = m_wrappers->at(i); Ditto. > Source/WebCore/svg/properties/SVGListPropertyTearOff.h:162 > - SVGAnimatedProperty* animatedPropertyOfItem = newItem->animatedProperty(); > + RefPtr<SVGAnimatedProperty> animatedPropertyOfItem = newItem->animatedProperty(); Ditto.
Comment on attachment 326168 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=326168&action=review Thanks Ryosuke for r+ my patch. >> Source/WebCore/rendering/svg/RenderSVGModelObject.cpp:119 >> + auto* stopAtElement = SVGLocatable::nearestViewportElement(element); > > Why are we not using RefPtr here? This variable is only used for comparison in the latter codes. I don't see any reason for changing it to RefPtr. I should actually revert this line. Fixed. >> Source/WebCore/svg/SVGAElement.cpp:128 >> + RefPtr<Element> targetElement = treeScope().getElementById(url.substringSharingImpl(1)); > > Use makeRefPtr? Why is using makeRefPtr better?
(In reply to Jiewen Tan from comment #8) > Comment on attachment 326168 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=326168&action=review > > Thanks Ryosuke for r+ my patch. > > >> Source/WebCore/svg/SVGAElement.cpp:128 > >> + RefPtr<Element> targetElement = treeScope().getElementById(url.substringSharingImpl(1)); > > > > Use makeRefPtr? > > Why is using makeRefPtr better? For the same reason we use auto elsewhere. It's redundant to name the local variable RefPtr<Element> when the function is named getElementById.
(In reply to Ryosuke Niwa from comment #9) > (In reply to Jiewen Tan from comment #8) > > Comment on attachment 326168 [details] > > Patch > > > > View in context: > > https://bugs.webkit.org/attachment.cgi?id=326168&action=review > > > > Thanks Ryosuke for r+ my patch. > > > > >> Source/WebCore/svg/SVGAElement.cpp:128 > > >> + RefPtr<Element> targetElement = treeScope().getElementById(url.substringSharingImpl(1)); > > > > > > Use makeRefPtr? > > > > Why is using makeRefPtr better? > > For the same reason we use auto elsewhere. It's redundant to name the local > variable RefPtr<Element> when the function is named getElementById. Fair enough, I will make the change.
Comment on attachment 326168 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=326168&action=review >>>>> Source/WebCore/svg/SVGAElement.cpp:128 >>>>> + RefPtr<Element> targetElement = treeScope().getElementById(url.substringSharingImpl(1)); >>>> >>>> Use makeRefPtr? >>> >>> Why is using makeRefPtr better? >> >> For the same reason we use auto elsewhere. It's redundant to name the local variable RefPtr<Element> when the function is named getElementById. > > Fair enough, I will make the change. Fixed. >> Source/WebCore/svg/SVGAElement.cpp:144 >> + RefPtr<Frame> frame = document().frame(); > > Use makeRefPtr? Fixed. >> Source/WebCore/svg/SVGAnimateElementBase.cpp:87 >> + RefPtr<SVGElement> targetElement = this->targetElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGAnimateElementBase.cpp:189 >> + RefPtr<SVGElement> targetElement = this->targetElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGAnimateElementBase.cpp:339 >> + RefPtr<SVGElement> targetElement = this->targetElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGAnimateMotionElement.cpp:59 >> + RefPtr<SVGElement> targetElement = this->targetElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGAnimateMotionElement.cpp:168 >> + RefPtr<SVGElement> targetElement = this->targetElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGAnimateMotionElement.cpp:-234 >> - SVGElement* targetElement = this->targetElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGAnimateMotionElement.cpp:-274 >> - SVGElement* targetElement = this->targetElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGAnimationElement.cpp:646 >> + RefPtr<Element> parent = targetElement->parentElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGAnimationElement.cpp:665 >> + RefPtr<SVGElement> targetElement = this->targetElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGElement.cpp:291 >> + if (RefPtr<SVGElement> correspondingElement = m_svgRareData->correspondingElement()) > > Ditto. Fixed. >> Source/WebCore/svg/SVGElement.cpp:449 >> + if (RefPtr<SVGElement> oldCorrespondingElement = m_svgRareData->correspondingElement()) > > Ditto. Fixed. >> Source/WebCore/svg/SVGElement.cpp:762 >> + if (RefPtr<Element> parent = parentOrShadowHostElement()) { > > Ditto. Fixed. >> Source/WebCore/svg/SVGElement.cpp:1089 >> + RefPtr<ContainerNode> node = parentNode(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGElement.cpp:1132 >> + RefPtr<SVGElement> instance = *instances.begin(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGFEImageElement.cpp:105 >> + RefPtr<Element> target = SVGURIReference::targetElementFromIRIString(href(), document(), &id); > > Ditto. Fixed. >> Source/WebCore/svg/SVGFEImageElement.cpp:176 >> + RefPtr<Element> parent = parentElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGFELightElement.cpp:82 >> + RefPtr<SVGFELightElement> lightNode = findLightElement(svgElement); > > Ditto. Fixed. >> Source/WebCore/svg/SVGFELightElement.cpp:178 >> + RefPtr<ContainerNode> parent = parentNode(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.cpp:157 >> + RefPtr<ContainerNode> parent = element->parentNode(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGFontFaceElement.cpp:266 >> + if (RefPtr<CSSFontFaceSrcValue> item = downcast<CSSFontFaceSrcValue>(srcList->itemWithoutBoundsCheck(i))) > > Ditto. Fixed. >> Source/WebCore/svg/SVGFontFaceFormatElement.cpp:50 >> + RefPtr<ContainerNode> ancestor = parentNode()->parentNode(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGFontFaceUriElement.cpp:79 >> + RefPtr<ContainerNode> grandparent = parentNode()->parentNode(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGForeignObjectElement.cpp:145 >> + RefPtr<Element> ancestor = parentElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGLengthContext.cpp:304 >> + RefPtr<SVGElement> viewportElement = m_context->viewportElement(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGLinearGradientElement.cpp:165 >> + RefPtr<Node> refNode = SVGURIReference::targetElementFromIRIString(current->href(), document()); > > Ditto. Fixed. >> Source/WebCore/svg/SVGMPathElement.cpp:65 >> + RefPtr<Element> target = SVGURIReference::targetElementFromIRIString(href(), document(), &id); > > Ditto. Fixed. >> Source/WebCore/svg/SVGRadialGradientElement.cpp:181 >> + RefPtr<Node> refNode = SVGURIReference::targetElementFromIRIString(current->href(), document()); > > Ditto. Fixed. >> Source/WebCore/svg/SVGSVGElement.cpp:175 >> + RefPtr<Frame> frame = document().frame(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGSVGElement.cpp:376 >> + if (RefPtr<Frame> frame = document().frame()) > > Ditto. Fixed. >> Source/WebCore/svg/SVGSVGElement.cpp:456 >> + if (RefPtr<FrameView> view = document().view()) { > > Ditto. Fixed. >> Source/WebCore/svg/SVGSVGElement.cpp:641 >> + RefPtr<SVGViewSpec> view(m_viewSpec); > > Ditto. Fixed. >> Source/WebCore/svg/SVGSVGElement.cpp:725 >> + RefPtr<Element> element = treeScope().getElementById(id); > > Ditto. Fixed. >> Source/WebCore/svg/SVGStyleElement.cpp:58 >> + if (RefPtr<CSSStyleSheet> styleSheet = sheet()) > > Ditto. Fixed. >> Source/WebCore/svg/SVGTRefElement.cpp:166 >> + RefPtr<Node> container = shadowRoot()->firstChild(); > > Ditto. Fixed. >> Source/WebCore/svg/SVGTextPathElement.cpp:159 >> + RefPtr<Element> target = SVGURIReference::targetElementFromIRIString(href(), document(), &id); > > Ditto. Fixed. >> Source/WebCore/svg/SVGUseElement.cpp:145 >> + RefPtr<SVGElement> correspondingElement = shadowElement.correspondingElement(); > > Ditto. Fixed. >> Source/WebCore/svg/animation/SVGSMILElement.cpp:266 >> + RefPtr<SVGSVGElement> owner = ownerSVGElement(); > > Ditto. Fixed. >> Source/WebCore/svg/animation/SVGSMILElement.cpp:547 >> + RefPtr<Element> eventBase = eventBaseFor(condition); > > Ditto. Fixed. >> Source/WebCore/svg/animation/SVGSMILElement.cpp:582 >> + RefPtr<Element> eventBase = eventBaseFor(condition); > > Ditto. Fixed. > Source/WebCore/svg/graphics/SVGImage.cpp:132 > + RefPtr<FrameView> view = frameView(); Fixed this too. >> Source/WebCore/svg/graphics/SVGImage.cpp:288 >> + RefPtr<FrameView> view = frameView(); > > Ditto. Fixed. >> Source/WebCore/svg/graphics/SVGImage.cpp:412 >> + RefPtr<Document> document = m_page->mainFrame().document(); > > Ditto. Fixed. >> Source/WebCore/svg/graphics/filters/SVGFEImage.cpp:121 >> + RefPtr<SVGElement> contextNode = downcast<SVGElement>(renderer->element()); > > Ditto. Fixed. >> Source/WebCore/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h:93 >> + RefPtr<SVGPathElement> pathElement = downcast<SVGPathElement>(contextElement()); > > Ditto. Fixed. >> Source/WebCore/svg/properties/SVGListPropertyTearOff.h:144 >> + RefPtr<ListItemTearOff> item = m_wrappers->at(i); > > Ditto. Fixed. >> Source/WebCore/svg/properties/SVGListPropertyTearOff.h:162 >> + RefPtr<SVGAnimatedProperty> animatedPropertyOfItem = newItem->animatedProperty(); > > Ditto. Fixed.
Created attachment 326380 [details] Patch for landing
Attachment 326380 [details] did not pass style-queue: ERROR: Source/WebCore/svg/SVGDocumentExtensions.cpp:275: 'element' is incorrectly named. It should be named 'protector' or 'protectedFirstElement'. [readability/naming/protected] [4] Total errors found: 1 in 60 files If any of these errors are false positives, please file a bug against check-webkit-style.
Comment on attachment 326380 [details] Patch for landing Clearing flags on attachment: 326380 Committed r224615: <https://trac.webkit.org/changeset/224615>
All patches have been landed.