Ref-ify more stack guards.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Oct 2013 00:35:12 +0000 (00:35 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Oct 2013 00:35:12 +0000 (00:35 +0000)
<https://webkit.org/b/122360>

Reviewed by Anders Carlsson.

Make another pass turning RefPtr<T> into Ref<T> where possible.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156932 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityMenuList.cpp
Source/WebCore/dom/ScriptElement.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/html/FileInputType.cpp
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/ImageInputType.cpp
Source/WebCore/html/SearchInputType.cpp
Source/WebCore/html/SubmitInputType.cpp
Source/WebCore/html/TextFieldInputType.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/page/DragController.cpp
Source/WebCore/page/FocusController.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/xml/XSLTProcessor.cpp
Source/WebCore/xml/XSLTProcessorLibxslt.cpp
Source/WebKit/mac/WebCoreSupport/PopupMenuMac.mm

index 06d00ef..318c348 100644 (file)
@@ -1,3 +1,12 @@
+2013-10-04  Andreas Kling  <akling@apple.com>
+
+        Ref-ify more stack guards.
+        <https://webkit.org/b/122360>
+
+        Reviewed by Anders Carlsson.
+
+        Make another pass turning RefPtr<T> into Ref<T> where possible.
+
 2013-10-04  Ojan Vafai  <ojan@chromium.org> and Martin Robinson  <mrobinson@igalia.com>
 
         [MathML] Remove RenderTree modification during layout and refactor the StretchyOp code
index d0c3038..bf43614 100644 (file)
@@ -105,7 +105,7 @@ bool AccessibilityMenuList::canSetFocusAttribute() const
 
 void AccessibilityMenuList::didUpdateActiveOption(int optionIndex)
 {
-    RefPtr<Document> document = &m_renderer->document();
+    Ref<Document> document(m_renderer->document());
     AXObjectCache* cache = document->axObjectCache();
 
     const AccessibilityChildrenVector& childObjects = children();
@@ -119,7 +119,7 @@ void AccessibilityMenuList::didUpdateActiveOption(int optionIndex)
         }
     }
 
-    cache->postNotification(this, document.get(), AXObjectCache::AXMenuListValueChanged, TargetElement, PostSynchronously);
+    cache->postNotification(this, &document.get(), AXObjectCache::AXMenuListValueChanged, TargetElement, PostSynchronously);
 }
 
 } // namespace WebCore
index 3e0b77c..ae2297b 100644 (file)
@@ -251,10 +251,10 @@ bool ScriptElement::prepareScript(const TextPosition& scriptStartPosition, Legac
 
 bool ScriptElement::requestScript(const String& sourceUrl)
 {
-    RefPtr<Document> originalDocument = &m_element->document();
+    Ref<Document> originalDocument(m_element->document());
     if (!m_element->dispatchBeforeLoadEvent(sourceUrl))
         return false;
-    if (!m_element->inDocument() || &m_element->document() != originalDocument)
+    if (!m_element->inDocument() || &m_element->document() != &originalDocument.get())
         return false;
     if (!m_element->document().contentSecurityPolicy()->allowScriptNonce(m_element->fastGetAttribute(HTMLNames::nonceAttr), m_element->document().url(), m_startLineNumber, m_element->document().completeURL(sourceUrl)))
         return false;
@@ -304,10 +304,10 @@ void ScriptElement::executeScript(const ScriptSourceCode& sourceCode)
     }
 #endif
 
-    RefPtr<Document> document = &m_element->document();
+    Ref<Document> document(m_element->document());
     if (Frame* frame = document->frame()) {
-        IgnoreDestructiveWriteCountIncrementer ignoreDesctructiveWriteCountIncrementer(m_isExternalScript ? document.get() : 0);
-        CurrentScriptIncrementer currentScriptIncrementer(document.get(), m_element);
+        IgnoreDestructiveWriteCountIncrementer ignoreDesctructiveWriteCountIncrementer(m_isExternalScript ? &document.get() : 0);
+        CurrentScriptIncrementer currentScriptIncrementer(&document.get(), m_element);
 
         // Create a script from the script element node, using the script
         // block's source and the script block's type.
index 197a1e6..3677ebd 100644 (file)
@@ -982,18 +982,18 @@ bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectIn
     selection = selectionForCommand(triggeringEvent);
     if (selection.isContentEditable()) {
         if (Node* selectionStart = selection.start().deprecatedNode()) {
-            RefPtr<Document> document = &selectionStart->document();
+            Ref<Document> document(selectionStart->document());
 
             // Insert the text
             if (triggeringEvent && triggeringEvent->isDictation())
-                DictationCommand::insertText(document.get(), text, triggeringEvent->dictationAlternatives(), selection);
+                DictationCommand::insertText(&document.get(), text, triggeringEvent->dictationAlternatives(), selection);
             else {
                 TypingCommand::Options options = 0;
                 if (selectInsertedText)
                     options |= TypingCommand::SelectInsertedText;
                 if (autocorrectionWasApplied)
                     options |= TypingCommand::RetainAutocorrectionIndicator;
-                TypingCommand::insertText(document.get(), text, selection, options, triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextCompositionConfirm : TypingCommand::TextCompositionNone);
+                TypingCommand::insertText(&document.get(), text, selection, options, triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextCompositionConfirm : TypingCommand::TextCompositionNone);
             }
 
             // Reveal the current selection
index 7172bba..bf2164b 100644 (file)
@@ -355,7 +355,7 @@ static bool removingNodeRemovesPosition(Node* node, const Position& position)
 
 static void clearRenderViewSelection(const Position& position)
 {
-    RefPtr<Document> document = &position.anchorNode()->document();
+    Ref<Document> document(position.anchorNode()->document());
     document->updateStyleIfNeeded();
     if (RenderView* view = document->renderView())
         view->clearSelection();
index 058f8c2..01edc4b 100644 (file)
@@ -362,7 +362,7 @@ void FileInputType::setFiles(PassRefPtr<FileList> files)
     if (!files)
         return;
 
-    RefPtr<HTMLInputElement> input = &element();
+    Ref<HTMLInputElement> input(element());
 
     bool pathsChanged = false;
     if (files->length() != m_fileList->length())
index 1d728d4..039c9cd 100644 (file)
@@ -162,11 +162,11 @@ void HTMLLinkElement::parseAttribute(const QualifiedName& name, const AtomicStri
 
 bool HTMLLinkElement::shouldLoadLink()
 {
-    RefPtr<Document> originalDocument = &document();
+    Ref<Document> originalDocument(document());
     if (!dispatchBeforeLoadEvent(getNonEmptyURLAttribute(hrefAttr)))
         return false;
     // A beforeload handler might have removed us from the document or changed the document.
-    if (!inDocument() || &document() != originalDocument)
+    if (!inDocument() || &document() != &originalDocument.get())
         return false;
     return true;
 }
index cc88d6c..f80dcdf 100644 (file)
@@ -87,7 +87,7 @@ bool ImageInputType::supportsValidation() const
 
 void ImageInputType::handleDOMActivateEvent(Event* event)
 {
-    RefPtr<HTMLInputElement> element = &this->element();
+    Ref<HTMLInputElement> element(this->element());
     if (element->isDisabledFormControl() || !element->form())
         return;
     element->setActivatedSubmit(true);
@@ -173,7 +173,7 @@ bool ImageInputType::shouldRespectHeightAndWidthAttributes()
 
 unsigned ImageInputType::height() const
 {
-    RefPtr<HTMLInputElement> element = &this->element();
+    Ref<HTMLInputElement> element(this->element());
 
     if (!element->renderer()) {
         // Check the attribute first for an explicit pixel value.
@@ -197,7 +197,7 @@ unsigned ImageInputType::height() const
 
 unsigned ImageInputType::width() const
 {
-    RefPtr<HTMLInputElement> element = &this->element();
+    Ref<HTMLInputElement> element(this->element());
 
     if (!element->renderer()) {
         // Check the attribute first for an explicit pixel value.
index 4b7d108..2325ba5 100644 (file)
@@ -133,7 +133,7 @@ void SearchInputType::handleKeydownEvent(KeyboardEvent* event)
 
     const String& key = event->keyIdentifier();
     if (key == "U+001B") {
-        RefPtr<HTMLInputElement> input = &element();
+        Ref<HTMLInputElement> input(this->element());
         input->setValueForUser("");
         input->onSearch();
         event->setDefaultHandled();
index 66a2a4f..ded41db 100644 (file)
@@ -67,7 +67,7 @@ bool SubmitInputType::supportsRequired() const
 
 void SubmitInputType::handleDOMActivateEvent(Event* event)
 {
-    RefPtr<HTMLInputElement> element = &this->element();
+    Ref<HTMLInputElement> element(this->element());
     if (element->isDisabledFormControl() || !element->form())
         return;
     element->setActivatedSubmit(true);
index 9f48470..40e9dd3 100644 (file)
@@ -97,7 +97,7 @@ void TextFieldInputType::setValue(const String& sanitizedValue, bool valueChange
 {
     // Grab this input element to keep reference even if JS event handler
     // changes input type.
-    RefPtr<HTMLInputElement> input = &element();
+    Ref<HTMLInputElement> input(element());
 
     // We don't ask InputType::setValue to dispatch events because
     // TextFieldInputType dispatches events different way from InputType.
@@ -492,7 +492,7 @@ void TextFieldInputType::updateInnerTextValue()
 
 void TextFieldInputType::focusAndSelectSpinButtonOwner()
 {
-    RefPtr<HTMLInputElement> input = &element();
+    Ref<HTMLInputElement> input(element());
     input->focus();
     input->select();
 }
index dff9aba..be9550d 100644 (file)
@@ -2888,7 +2888,7 @@ void FrameLoader::continueLoadAfterNewWindowPolicy(const ResourceRequest& reques
     if (!shouldContinue)
         return;
 
-    RefPtr<Frame> frame = &m_frame;
+    Ref<Frame> frame(m_frame);
     RefPtr<Frame> mainFrame = m_client.dispatchCreatePage(action);
     if (!mainFrame)
         return;
@@ -2899,7 +2899,7 @@ void FrameLoader::continueLoadAfterNewWindowPolicy(const ResourceRequest& reques
     mainFrame->page()->setOpenedByDOM();
     mainFrame->loader().m_client.dispatchShow();
     if (!m_suppressOpenerInNewFrame) {
-        mainFrame->loader().setOpener(frame.get());
+        mainFrame->loader().setOpener(&frame.get());
         mainFrame->document()->setReferrerPolicy(frame->document()->referrerPolicy());
     }
     mainFrame->loader().loadWithNavigationAction(request, NavigationAction(request), false, FrameLoadTypeStandard, formState);
index cf41784..fd54bdb 100644 (file)
@@ -209,7 +209,7 @@ bool DragController::performDrag(DragData* dragData)
     m_documentUnderMouse = m_page.mainFrame().documentAtPoint(dragData->clientPosition());
     if ((m_dragDestinationAction & DragDestinationActionDHTML) && m_documentIsHandlingDrag) {
         m_client.willPerformDragDestinationAction(DragDestinationActionDHTML, dragData);
-        RefPtr<Frame> mainFrame = &m_page.mainFrame();
+        Ref<MainFrame> mainFrame(m_page.mainFrame());
         bool preventedDefault = false;
         if (mainFrame->view()) {
             // Sending an event can result in the destruction of the view and part.
@@ -598,7 +598,7 @@ bool DragController::tryDHTMLDrag(DragData* dragData, DragOperation& operation)
 {
     ASSERT(dragData);
     ASSERT(m_documentUnderMouse);
-    RefPtr<Frame> mainFrame = &m_page.mainFrame();
+    Ref<MainFrame> mainFrame(m_page.mainFrame());
     RefPtr<FrameView> viewProtector = mainFrame->view();
     if (!viewProtector)
         return false;
@@ -908,10 +908,10 @@ void DragController::doSystemDrag(DragImageRef image, const IntPoint& dragLoc, c
     m_didInitiateDrag = true;
     m_dragInitiator = frame->document();
     // Protect this frame and view, as a load may occur mid drag and attempt to unload this frame
-    RefPtr<Frame> frameProtector = &m_page.mainFrame();
+    Ref<MainFrame> frameProtector(m_page.mainFrame());
     RefPtr<FrameView> viewProtector = frameProtector->view();
     m_client.startDrag(image, viewProtector->rootViewToContents(frame->view()->contentsToRootView(dragLoc)),
-        viewProtector->rootViewToContents(frame->view()->contentsToRootView(eventPos)), clipboard, frameProtector.get(), forLink);
+        viewProtector->rootViewToContents(frame->view()->contentsToRootView(eventPos)), clipboard, &frameProtector.get(), forLink);
     // DragClient::startDrag can cause our Page to dispear, deallocating |this|.
     if (!frameProtector->page())
         return;
index 0123f75..d6af703 100644 (file)
@@ -610,14 +610,14 @@ bool FocusController::setFocusedElement(Element* element, PassRefPtr<Frame> newF
         return true;
     }
 
-    RefPtr<Document> newDocument = &element->document();
+    Ref<Document> newDocument(element->document());
 
     if (newDocument->focusedElement() == element) {
         m_page.editorClient()->setInputMethodState(element->shouldUseInputMethod());
         return true;
     }
     
-    if (oldDocument && oldDocument != newDocument)
+    if (oldDocument && oldDocument != &newDocument.get())
         oldDocument->setFocusedElement(0);
 
     if (newFocusedFrame && !newFocusedFrame->page()) {
@@ -627,11 +627,10 @@ bool FocusController::setFocusedElement(Element* element, PassRefPtr<Frame> newF
     setFocusedFrame(newFocusedFrame);
 
     Ref<Element> protect(*element);
-    if (newDocument) {
-        bool successfullyFocused = newDocument->setFocusedElement(element, direction);
-        if (!successfullyFocused)
-            return false;
-    }
+
+    bool successfullyFocused = newDocument->setFocusedElement(element, direction);
+    if (!successfullyFocused)
+        return false;
 
     if (newDocument->focusedElement() == element)
         m_page.editorClient()->setInputMethodState(element->shouldUseInputMethod());
index 673ab1c..787dfda 100644 (file)
@@ -1075,7 +1075,7 @@ inline void FrameView::forceLayoutParentViewIfNeeded()
     // FrameView for a layout. After that the RenderEmbeddedObject (ownerRenderer) carries the
     // correct size, which RenderSVGRoot::computeReplacedLogicalWidth/Height rely on, when laying
     // out for the first time, or when the RenderSVGRoot size has changed dynamically (eg. via <script>).
-    RefPtr<FrameView> frameView = &ownerRenderer->view().frameView();
+    Ref<FrameView> frameView(ownerRenderer->view().frameView());
 
     // Mark the owner renderer as needing layout.
     ownerRenderer->setNeedsLayoutAndPrefWidthsRecalc();
index aeba945..dbba172 100644 (file)
@@ -70,8 +70,8 @@ XSLTProcessor::~XSLTProcessor()
 PassRefPtr<Document> XSLTProcessor::createDocumentFromSource(const String& sourceString,
     const String& sourceEncoding, const String& sourceMIMEType, Node* sourceNode, Frame* frame)
 {
-    RefPtr<Document> ownerDocument = &sourceNode->document();
-    bool sourceIsDocument = (sourceNode == ownerDocument.get());
+    Ref<Document> ownerDocument(sourceNode->document());
+    bool sourceIsDocument = (sourceNode == &ownerDocument.get());
     String documentSource = sourceString;
 
     RefPtr<Document> result;
index e9524be..6b1b2e9 100644 (file)
@@ -267,8 +267,8 @@ static xsltStylesheetPtr xsltStylesheetPointer(RefPtr<XSLStyleSheet>& cachedStyl
 
 static inline xmlDocPtr xmlDocPtrFromNode(Node* sourceNode, bool& shouldDelete)
 {
-    RefPtr<Document> ownerDocument = &sourceNode->document();
-    bool sourceIsDocument = (sourceNode == ownerDocument.get());
+    Ref<Document> ownerDocument(sourceNode->document());
+    bool sourceIsDocument = (sourceNode == &ownerDocument.get());
 
     xmlDocPtr sourceDoc = 0;
     if (sourceIsDocument && ownerDocument->transformSource())
@@ -302,7 +302,7 @@ static inline String resultMIMEType(xmlDocPtr resultDoc, xsltStylesheetPtr sheet
 
 bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String& resultString, String& resultEncoding)
 {
-    RefPtr<Document> ownerDocument = &sourceNode->document();
+    Ref<Document> ownerDocument(sourceNode->document());
 
     setXSLTLoadCallBack(docLoaderFunc, this, ownerDocument->cachedResourceLoader());
     xsltStylesheetPtr sheet = xsltStylesheetPointer(m_stylesheet, m_stylesheetRootNode.get());
index 9098237..52e7d7c 100644 (file)
@@ -172,7 +172,7 @@ void PopupMenuMac::show(const IntRect& r, FrameView* v, int index)
 
     // Save the current event that triggered the popup, so we can clean up our event
     // state after the NSMenu goes away.
-    RefPtr<Frame> frame = &v->frame();
+    Ref<Frame> frame(v->frame());
     RetainPtr<NSEvent> event = frame->eventHandler().currentNSEvent();
     
     Ref<PopupMenuMac> protector(*this);