Commit ad1137cb authored by akling@apple.com's avatar akling@apple.com

Make some things that return never-null pointers return references instead.

<http://webkit.org/b/119660>

Reviewed by Antti Koivisto.

Source/WebCore:

These functions never return null anyway, so remove any ambiguity by letting
them return references instead of pointers.

- Node::ensureRareData()
- Element::ensureUniqueElementData()
- Element::ensureShadow()
- Element::ensureUserAgentShadowRoot()
- StyledElement::ensureMutableInlineStyle()
- NodeRareData::ensureNodeLists()
- NodeRareData::ensureMutationObserverData()
- EventTarget::ensureEventTargetData()
- Document::ensureStyleResolver()
- Document::selectorQueryCache()
- Document::mediaQueryMatcher()
- FlowThreadController::ensureRenderFlowThreadWithName()
- HTMLTrackElement::ensureTrack()
- SVGElement::ensureSVGRareData()
- AnimationControllerPrivate::ensureCompositeAnimation()

Source/WebKit/qt:

* Api/qwebelement.cpp:
(QWebElement::styleProperty):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@153926 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2e687dd4
2013-08-11 Andreas Kling <akling@apple.com>
Make some things that return never-null pointers return references instead.
<http://webkit.org/b/119660>
Reviewed by Antti Koivisto.
These functions never return null anyway, so remove any ambiguity by letting
them return references instead of pointers.
- Node::ensureRareData()
- Element::ensureUniqueElementData()
- Element::ensureShadow()
- Element::ensureUserAgentShadowRoot()
- StyledElement::ensureMutableInlineStyle()
- NodeRareData::ensureNodeLists()
- NodeRareData::ensureMutationObserverData()
- EventTarget::ensureEventTargetData()
- Document::ensureStyleResolver()
- Document::selectorQueryCache()
- Document::mediaQueryMatcher()
- FlowThreadController::ensureRenderFlowThreadWithName()
- HTMLTrackElement::ensureTrack()
- SVGElement::ensureSVGRareData()
- AnimationControllerPrivate::ensureCompositeAnimation()
2013-08-11 Sam Weinig <sam@webkit.org>
Cleanup MediaQueryListListener
......@@ -66,7 +66,7 @@ public:
protected:
virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData; }
virtual EventTargetData& ensureEventTargetData() { return m_eventTargetData; }
private:
explicit BatteryManager(Navigator*);
......
......@@ -103,7 +103,7 @@ private:
virtual void derefEventTarget() OVERRIDE { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE { return &m_eventTargetData; }
virtual EventTargetData* ensureEventTargetData() OVERRIDE { return &m_eventTargetData; }
virtual EventTargetData& ensureEventTargetData() OVERRIDE { return m_eventTargetData; }
EventTargetData m_eventTargetData;
};
......
......@@ -99,10 +99,10 @@ private:
virtual void stop() OVERRIDE;
// EventTarget
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData; }
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE { return &m_eventTargetData; }
virtual EventTargetData& ensureEventTargetData() OVERRIDE { return m_eventTargetData; }
void completeAbort();
......
......@@ -378,9 +378,9 @@ EventTargetData* IDBDatabase::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* IDBDatabase::ensureEventTargetData()
EventTargetData& IDBDatabase::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
} // namespace WebCore
......
......@@ -115,10 +115,10 @@ private:
virtual void stop() OVERRIDE;
// EventTarget
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
void closeConnection();
......
......@@ -564,9 +564,9 @@ EventTargetData* IDBRequest::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* IDBRequest::ensureEventTargetData()
EventTargetData& IDBRequest::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
} // namespace WebCore
......
......@@ -135,10 +135,10 @@ private:
virtual void stop() OVERRIDE;
// EventTarget
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
PassRefPtr<IDBCursor> getResultCursor();
void setResultCursor(PassRefPtr<IDBCursor>, PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, const ScriptValue&);
......
......@@ -442,9 +442,9 @@ EventTargetData* IDBTransaction::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* IDBTransaction::ensureEventTargetData()
EventTargetData& IDBTransaction::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
IDBDatabaseBackendInterface* IDBTransaction::backendDB() const
......
......@@ -132,10 +132,10 @@ private:
virtual void stop() OVERRIDE;
// EventTarget
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
enum State {
Inactive, // Created or started, but not in an event callback
......
......@@ -317,9 +317,9 @@ EventTargetData* MediaSource::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* MediaSource::ensureEventTargetData()
EventTargetData& MediaSource::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
void MediaSource::scheduleEvent(const AtomicString& eventName)
......
......@@ -82,7 +82,7 @@ private:
virtual void stop() OVERRIDE;
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData* ensureEventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
......
......@@ -109,9 +109,9 @@ EventTargetData* SourceBufferList::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* SourceBufferList::ensureEventTargetData()
EventTargetData& SourceBufferList::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
} // namespace WebCore
......
......@@ -66,7 +66,7 @@ public:
protected:
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData* ensureEventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
private:
SourceBufferList(ScriptExecutionContext*, GenericEventQueue*);
......
......@@ -251,9 +251,9 @@ EventTargetData* MediaStream::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* MediaStream::ensureEventTargetData()
EventTargetData& MediaStream::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
void MediaStream::addRemoteTrack(MediaStreamComponent* component)
......
......@@ -84,7 +84,7 @@ protected:
// EventTarget
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData* ensureEventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
// ContextDestructionObserver
virtual void contextDestroyed();
......
......@@ -164,9 +164,9 @@ EventTargetData* MediaStreamTrack::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* MediaStreamTrack::ensureEventTargetData()
EventTargetData& MediaStreamTrack::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
} // namespace WebCore
......
......@@ -77,7 +77,7 @@ private:
// EventTarget
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData* ensureEventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
EventTargetData m_eventTargetData;
......
......@@ -149,9 +149,9 @@ EventTargetData* RTCDTMFSender::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* RTCDTMFSender::ensureEventTargetData()
EventTargetData& RTCDTMFSender::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
void RTCDTMFSender::scheduleDispatchEvent(PassRefPtr<Event> event)
......
......@@ -75,7 +75,7 @@ private:
// EventTarget
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData* ensureEventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
EventTargetData m_eventTargetData;
......
......@@ -253,9 +253,9 @@ EventTargetData* RTCDataChannel::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* RTCDataChannel::ensureEventTargetData()
EventTargetData& RTCDataChannel::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
void RTCDataChannel::scheduleDispatchEvent(PassRefPtr<Event> event)
......
......@@ -80,10 +80,10 @@ private:
void scheduledEventTimerFired(Timer<RTCDataChannel>*);
// EventTarget
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
EventTargetData m_eventTargetData;
ScriptExecutionContext* m_scriptExecutionContext;
......
......@@ -608,9 +608,9 @@ EventTargetData* RTCPeerConnection::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* RTCPeerConnection::ensureEventTargetData()
EventTargetData& RTCPeerConnection::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
void RTCPeerConnection::changeSignalingState(SignalingState signalingState)
......
......@@ -137,10 +137,10 @@ private:
bool hasLocalStreamWithTrackId(const String& trackId);
// EventTarget implementation.
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
EventTargetData m_eventTargetData;
void changeSignalingState(SignalingState);
......
......@@ -77,9 +77,9 @@ EventTargetData* NetworkInfoConnection::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* NetworkInfoConnection::ensureEventTargetData()
EventTargetData& NetworkInfoConnection::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
const AtomicString& NetworkInfoConnection::interfaceName() const
......
......@@ -76,10 +76,10 @@ private:
explicit NetworkInfoConnection(Navigator*);
// EventTarget implementation.
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
// EventTarget implementation.
EventTargetData m_eventTargetData;
......
......@@ -173,9 +173,9 @@ EventTargetData* Notification::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* Notification::ensureEventTargetData()
EventTargetData& Notification::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
void Notification::contextDestroyed()
......
......@@ -152,10 +152,10 @@ private:
virtual void contextDestroyed() OVERRIDE;
// EventTarget interface
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
void startLoadingIcon();
void finishLoadingIcon();
......
......@@ -111,7 +111,7 @@ private:
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE { return &m_eventTargetData; }
virtual EventTargetData* ensureEventTargetData() OVERRIDE { return &m_eventTargetData; }
virtual EventTargetData& ensureEventTargetData() OVERRIDE { return m_eventTargetData; }
RefPtr<SpeechGrammarList> m_grammars;
String m_lang;
......
......@@ -91,7 +91,7 @@ private:
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE { return &m_eventTargetData; }
virtual EventTargetData* ensureEventTargetData() OVERRIDE { return &m_eventTargetData; }
virtual EventTargetData& ensureEventTargetData() OVERRIDE { return m_eventTargetData; }
};
} // namespace WebCore
......
......@@ -238,7 +238,7 @@ public:
virtual const AtomicString& interfaceName() const;
virtual ScriptExecutionContext* scriptExecutionContext() const;
virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData; }
virtual EventTargetData& ensureEventTargetData() { return m_eventTargetData; }
DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
......
......@@ -183,7 +183,7 @@ public:
virtual const AtomicString& interfaceName() const OVERRIDE;
virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
virtual EventTargetData* eventTargetData() OVERRIDE { return &m_eventTargetData; }
virtual EventTargetData* ensureEventTargetData() OVERRIDE { return &m_eventTargetData; }
virtual EventTargetData& ensureEventTargetData() OVERRIDE { return m_eventTargetData; }
protected:
// Inputs and outputs must be created before the AudioNode is initialized.
......
......@@ -584,9 +584,9 @@ EventTargetData* WebSocket::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* WebSocket::ensureEventTargetData()
EventTargetData& WebSocket::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
size_t WebSocket::getFramingOverhead(size_t payloadSize)
......
......@@ -122,10 +122,10 @@ private:
virtual void resume() OVERRIDE;
virtual void stop() OVERRIDE;
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
size_t getFramingOverhead(size_t payloadSize);
......
......@@ -119,9 +119,9 @@ EventTargetData* FontLoader::eventTargetData()
return &m_eventTargetData;
}
EventTargetData* FontLoader::ensureEventTargetData()
EventTargetData& FontLoader::ensureEventTargetData()
{
return &m_eventTargetData;
return m_eventTargetData;
}
const AtomicString& FontLoader::interfaceName() const
......
......@@ -85,10 +85,10 @@ public:
private:
FontLoader(Document*);
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData& ensureEventTargetData() OVERRIDE;
void scheduleEvent(PassRefPtr<Event>);
void firePendingEvents();
......
......@@ -84,9 +84,7 @@ PassOwnPtr<MediaQueryEvaluator> MediaQueryMatcher::prepareEvaluator() const
if (!documentElement)
return nullptr;
StyleResolver* styleResolver = m_document->ensureStyleResolver();
RefPtr<RenderStyle> rootStyle = styleResolver->styleForElement(documentElement, 0 /*defaultParent*/, DisallowStyleSharing, MatchOnlyUserAgentRules);
RefPtr<RenderStyle> rootStyle = m_document->ensureStyleResolver().styleForElement(documentElement, 0 /*defaultParent*/, DisallowStyleSharing, MatchOnlyUserAgentRules);
return adoptPtr(new MediaQueryEvaluator(mediaType(), m_document->frame(), rootStyle.get()));
}
......
......@@ -60,9 +60,7 @@ bool StyleMedia::matchMedium(const String& query) const
if (!documentElement)
return false;
StyleResolver* styleResolver = document->ensureStyleResolver();
RefPtr<RenderStyle> rootStyle = styleResolver->styleForElement(documentElement, 0 /*defaultParent*/, DisallowStyleSharing, MatchOnlyUserAgentRules);
RefPtr<RenderStyle> rootStyle = document->ensureStyleResolver().styleForElement(documentElement, 0 /*defaultParent*/, DisallowStyleSharing, MatchOnlyUserAgentRules);
RefPtr<MediaQuerySet> media = MediaQuerySet::create();
if (!media->parse(query))
......
......@@ -1534,7 +1534,7 @@ template <StyleResolver::StyleApplicationPass pass>
void StyleResolver::applyProperties(const StylePropertySet* properties, StyleRule* rule, bool isImportant, bool inheritedOnly, PropertyWhitelistType propertyWhitelistType)
{
ASSERT((propertyWhitelistType != PropertyWhitelistRegion) || m_state.regionForStyling());
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willProcessRule(document(), rule, this);
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willProcessRule(document(), rule, *this);
unsigned propertyCount = properties->propertyCount();
for (unsigned i = 0; i < propertyCount; ++i) {
......
......@@ -670,7 +670,7 @@ public:
{
if (m_pushedStyleResolver)
return;
m_pushedStyleResolver = m_parent->document()->ensureStyleResolver();
m_pushedStyleResolver = &m_parent->document()->ensureStyleResolver();
m_pushedStyleResolver->pushParentElement(m_parent);
}
~StyleResolverParentPusher()
......@@ -679,8 +679,8 @@ public:
return;
// This tells us that our pushed style selector is in a bad state,
// so we should just bail out in that scenario.
ASSERT(m_pushedStyleResolver == m_parent->document()->ensureStyleResolver());
if (m_pushedStyleResolver != m_parent->document()->ensureStyleResolver())
ASSERT(m_pushedStyleResolver == &m_parent->document()->ensureStyleResolver());
if (m_pushedStyleResolver != &m_parent->document()->ensureStyleResolver())
return;
m_pushedStyleResolver->popParentElement(m_parent);
}
......
......@@ -212,7 +212,7 @@ Attribute& Attr::elementAttribute()
{
ASSERT(m_element);
ASSERT(m_element->elementData());
return *m_element->ensureUniqueElementData()->findAttributeByName(qualifiedName());
return *m_element->ensureUniqueElementData().findAttributeByName(qualifiedName());
}
void Attr::detachFromElementWithValue(const AtomicString& value)
......
......@@ -691,18 +691,18 @@ void Document::invalidateAccessKeyMap()
m_elementsByAccessKey.clear();
}
SelectorQueryCache* Document::selectorQueryCache()
SelectorQueryCache& Document::selectorQueryCache()
{
if (!m_selectorQueryCache)
m_selectorQueryCache = adoptPtr(new SelectorQueryCache());
return m_selectorQueryCache.get();
return *m_selectorQueryCache;
}
MediaQueryMatcher* Document::mediaQueryMatcher()
MediaQueryMatcher& Document::mediaQueryMatcher()
{
if (!m_mediaQueryMatcher)
m_mediaQueryMatcher = MediaQueryMatcher::create(this);
return m_mediaQueryMatcher.get();
return *m_mediaQueryMatcher;
}
void Document::setCompatibilityMode(CompatibilityMode mode)
......@@ -1912,14 +1912,14 @@ PassRefPtr<RenderStyle> Document::styleForElementIgnoringPendingStylesheets(Elem
bool oldIgnore = m_ignorePendingStylesheets;
m_ignorePendingStylesheets = true;
RefPtr<RenderStyle> style = ensureStyleResolver()->styleForElement(element, element->parentNode() ? element->parentNode()->computedStyle() : 0);
RefPtr<RenderStyle> style = ensureStyleResolver().styleForElement(element, element->parentNode() ? element->parentNode()->computedStyle() : 0);
m_ignorePendingStylesheets = oldIgnore;
return style.release();
}
PassRefPtr<<