Use is<>() / downcast<>() for Document
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Sep 2014 22:23:20 +0000 (22:23 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Sep 2014 22:23:20 +0000 (22:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137221

Reviewed by Andreas Kling.

Use is<>() / downcast<>() for Document instead of isDocumentNode() /
toDocument().

Source/WebCore:

No new tests, no behavior change.

* Modules/geolocation/Geolocation.cpp:
(WebCore::Geolocation::document):
(WebCore::Geolocation::frame):
(WebCore::Geolocation::page):
* Modules/indexeddb/IDBFactory.cpp:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::document):
* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::RTCPeerConnection):
* Modules/notifications/Notification.cpp:
(WebCore::Notification::Notification):
(WebCore::Notification::show):
(WebCore::Notification::permission):
(WebCore::Notification::requestPermission):
* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::document):
* Modules/webaudio/OfflineAudioContext.cpp:
(WebCore::OfflineAudioContext::create):
* Modules/webdatabase/DatabaseContext.cpp:
(WebCore::DatabaseContext::allowDatabaseAccess):
(WebCore::DatabaseContext::databaseExceededQuota):
* Modules/websockets/ThreadableWebSocketChannel.cpp:
(WebCore::ThreadableWebSocketChannel::create):
* Modules/websockets/WebSocket.cpp:
(WebCore::WebSocket::connect):
* Modules/websockets/WebSocketHandshake.cpp:
(WebCore::WebSocketHandshake::clientHandshakeMessage):
(WebCore::WebSocketHandshake::clientHandshakeRequest):
* Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
(WebCore::WorkerThreadableWebSocketChannel::Peer::Peer):
* bindings/gobject/WebKitDOMPrivate.cpp:
(WebKit::wrap):
* bindings/js/DOMConstructorWithDocument.h:
(WebCore::DOMConstructorWithDocument::document):
* bindings/js/DOMRequestState.h:
(WebCore::DOMRequestState::DOMRequestState):
(WebCore::DOMRequestState::clear):
* bindings/js/JSAudioContextCustom.cpp:
(WebCore::constructJSAudioContext):
* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::toJSDOMGlobalObject):
* bindings/js/JSLazyEventListener.cpp:
(WebCore::JSLazyEventListener::initializeJSFunction):
* bindings/js/JSNodeCustom.cpp:
(WebCore::createWrapperInline):
* bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::execute):
* bindings/js/ScriptState.cpp:
(WebCore::frameFromExecState):
* crypto/SubtleCrypto.cpp:
(WebCore::SubtleCrypto::document):
* dom/Comment.cpp:
(WebCore::Comment::create):
* dom/ContainerNode.cpp:
(WebCore::checkAcceptChild):
* dom/ContainerNodeAlgorithms.cpp:
(WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument):
* dom/Document.h:
(WebCore::isDocument):
* dom/DocumentFragment.cpp:
(WebCore::DocumentFragment::create):
* dom/Element.cpp:
(WebCore::Element::computeInheritedLanguage):
* dom/EventDispatcher.cpp:
(WebCore::WindowEventContext::WindowEventContext):
* dom/EventTarget.cpp:
(WebCore::EventTarget::fireEventListeners):
* dom/NamedFlowCollection.cpp:
(WebCore::NamedFlowCollection::document):
* dom/Node.cpp:
(WebCore::Node::isDefaultNamespace):
(WebCore::Node::lookupPrefix):
(WebCore::Node::lookupNamespaceURI):
(WebCore::Node::removedLastRef):
* dom/Range.cpp:
(WebCore::Range::create):
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::dispatchErrorEvent):
* dom/Text.cpp:
(WebCore::Text::create):
* editing/MarkupAccumulator.cpp:
(WebCore::MarkupAccumulator::appendStartMarkup):
* html/HTMLDocument.h:
(WebCore::isHTMLDocument):
* html/HTMLNameCollection.h:
(WebCore::HTMLNameCollection::document):
* html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::insertedInto):
* html/ImageDocument.h:
(WebCore::isImageDocument):
* html/MediaDocument.h:
(WebCore::isMediaDocument):
* html/PluginDocument.h:
(WebCore::isPluginDocument):
* html/track/TextTrackCue.h:
(WebCore::TextTrackCue::ownerDocument):
* html/track/VTTCue.cpp:
(WebCore::VTTCue::initialize):
* html/track/VTTRegion.h:
(WebCore::VTTRegion::ownerDocument):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::assertDocument):
(WebCore::InspectorDOMAgent::buildObjectForNode):
(WebCore::InspectorDOMAgent::innerParentNode):
* inspector/InspectorInstrumentation.cpp:
(WebCore::frameForScriptExecutionContext):
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::instrumentingAgentsForContext):
* loader/TextTrackLoader.cpp:
(WebCore::TextTrackLoader::corsPolicyPreventedLoad):
(WebCore::TextTrackLoader::notifyFinished):
(WebCore::TextTrackLoader::load):
* loader/ThreadableLoader.cpp:
(WebCore::ThreadableLoader::create):
(WebCore::ThreadableLoader::loadResourceSynchronously):
* loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::MainThreadBridge::mainThreadCreateLoader):
* page/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::reportViolation):
* page/Crypto.cpp:
(WebCore::Crypto::document):
* page/DOMTimer.cpp:
(WebCore::DOMTimer::install):
(WebCore::DOMTimer::fired):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::focus):
(WebCore::DOMWindow::close):
(WebCore::DOMWindow::document):
(WebCore::DOMWindow::styleMedia):
(WebCore::DOMWindow::getComputedStyle):
* page/DragController.cpp:
(WebCore::DragController::dragExited):
(WebCore::DragController::dragEnteredOrUpdated):
* page/EventSource.cpp:
(WebCore::EventSource::create):
* page/FocusController.cpp:
(WebCore::FocusController::advanceFocusDirectionally):
* page/History.cpp:
(WebCore::History::go):
* page/SpatialNavigation.cpp:
(WebCore::scrollInDirection):
(WebCore::scrollableEnclosingBoxOrParentFrameForNodeInDirection):
(WebCore::canScrollInDirection):
(WebCore::nodeRectInAbsoluteCoordinates):
* svg/SVGDocument.h:
(WebCore::isSVGDocument):
* testing/Internals.cpp:
(WebCore::Internals::contextDocument):
(WebCore::Internals::frame):
(WebCore::Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks):
* testing/js/WebCoreTestSupport.cpp:
(WebCoreTestSupport::injectInternalsObject):
(WebCoreTestSupport::resetInternalsObject):
* workers/DefaultSharedWorkerRepository.cpp:
(WebCore::SharedWorkerProxy::addToWorkerDocuments):
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::document):
(WebCore::XMLHttpRequest::open):

Source/WebKit2:

* WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm:
(-[WKDOMDocument createElement:]):
(-[WKDOMDocument createTextNode:]):
(-[WKDOMDocument body]):

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

68 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/geolocation/Geolocation.cpp
Source/WebCore/Modules/indexeddb/IDBFactory.cpp
Source/WebCore/Modules/mediasource/SourceBuffer.cpp
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/Modules/notifications/Notification.cpp
Source/WebCore/Modules/webaudio/AudioContext.cpp
Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp
Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp
Source/WebCore/Modules/websockets/WebSocket.cpp
Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp
Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
Source/WebCore/bindings/js/DOMConstructorWithDocument.h
Source/WebCore/bindings/js/DOMRequestState.h
Source/WebCore/bindings/js/JSAudioContextCustom.cpp
Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
Source/WebCore/bindings/js/JSLazyEventListener.cpp
Source/WebCore/bindings/js/JSNodeCustom.cpp
Source/WebCore/bindings/js/ScheduledAction.cpp
Source/WebCore/bindings/js/ScriptState.cpp
Source/WebCore/crypto/SubtleCrypto.cpp
Source/WebCore/dom/Comment.cpp
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/ContainerNodeAlgorithms.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/DocumentFragment.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/EventDispatcher.cpp
Source/WebCore/dom/EventTarget.cpp
Source/WebCore/dom/NamedFlowCollection.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/ScriptExecutionContext.cpp
Source/WebCore/dom/Text.cpp
Source/WebCore/editing/MarkupAccumulator.cpp
Source/WebCore/html/HTMLDocument.h
Source/WebCore/html/HTMLNameCollection.h
Source/WebCore/html/ImageDocument.h
Source/WebCore/html/MediaDocument.h
Source/WebCore/html/PluginDocument.h
Source/WebCore/html/track/TextTrackCue.h
Source/WebCore/html/track/VTTCue.cpp
Source/WebCore/html/track/VTTRegion.h
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/loader/TextTrackLoader.cpp
Source/WebCore/loader/ThreadableLoader.cpp
Source/WebCore/loader/WorkerThreadableLoader.cpp
Source/WebCore/page/ContentSecurityPolicy.cpp
Source/WebCore/page/Crypto.cpp
Source/WebCore/page/DOMTimer.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DragController.cpp
Source/WebCore/page/EventSource.cpp
Source/WebCore/page/FocusController.cpp
Source/WebCore/page/History.cpp
Source/WebCore/page/SpatialNavigation.cpp
Source/WebCore/svg/SVGDocument.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/js/WebCoreTestSupport.cpp
Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
Source/WebCore/workers/WorkerMessagingProxy.cpp
Source/WebCore/xml/XMLHttpRequest.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm

index 84f3db9..81bd8d7 100644 (file)
@@ -1,3 +1,176 @@
+2014-09-29  Christophe Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for Document
+        https://bugs.webkit.org/show_bug.cgi?id=137221
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for Document instead of isDocumentNode() /
+        toDocument().
+
+        No new tests, no behavior change.
+
+        * Modules/geolocation/Geolocation.cpp:
+        (WebCore::Geolocation::document):
+        (WebCore::Geolocation::frame):
+        (WebCore::Geolocation::page):
+        * Modules/indexeddb/IDBFactory.cpp:
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::document):
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::RTCPeerConnection::RTCPeerConnection):
+        * Modules/notifications/Notification.cpp:
+        (WebCore::Notification::Notification):
+        (WebCore::Notification::show):
+        (WebCore::Notification::permission):
+        (WebCore::Notification::requestPermission):
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::document):
+        * Modules/webaudio/OfflineAudioContext.cpp:
+        (WebCore::OfflineAudioContext::create):
+        * Modules/webdatabase/DatabaseContext.cpp:
+        (WebCore::DatabaseContext::allowDatabaseAccess):
+        (WebCore::DatabaseContext::databaseExceededQuota):
+        * Modules/websockets/ThreadableWebSocketChannel.cpp:
+        (WebCore::ThreadableWebSocketChannel::create):
+        * Modules/websockets/WebSocket.cpp:
+        (WebCore::WebSocket::connect):
+        * Modules/websockets/WebSocketHandshake.cpp:
+        (WebCore::WebSocketHandshake::clientHandshakeMessage):
+        (WebCore::WebSocketHandshake::clientHandshakeRequest):
+        * Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
+        (WebCore::WorkerThreadableWebSocketChannel::Peer::Peer):
+        * bindings/gobject/WebKitDOMPrivate.cpp:
+        (WebKit::wrap):
+        * bindings/js/DOMConstructorWithDocument.h:
+        (WebCore::DOMConstructorWithDocument::document):
+        * bindings/js/DOMRequestState.h:
+        (WebCore::DOMRequestState::DOMRequestState):
+        (WebCore::DOMRequestState::clear):
+        * bindings/js/JSAudioContextCustom.cpp:
+        (WebCore::constructJSAudioContext):
+        * bindings/js/JSDOMGlobalObject.cpp:
+        (WebCore::toJSDOMGlobalObject):
+        * bindings/js/JSLazyEventListener.cpp:
+        (WebCore::JSLazyEventListener::initializeJSFunction):
+        * bindings/js/JSNodeCustom.cpp:
+        (WebCore::createWrapperInline):
+        * bindings/js/ScheduledAction.cpp:
+        (WebCore::ScheduledAction::execute):
+        * bindings/js/ScriptState.cpp:
+        (WebCore::frameFromExecState):
+        * crypto/SubtleCrypto.cpp:
+        (WebCore::SubtleCrypto::document):
+        * dom/Comment.cpp:
+        (WebCore::Comment::create):
+        * dom/ContainerNode.cpp:
+        (WebCore::checkAcceptChild):
+        * dom/ContainerNodeAlgorithms.cpp:
+        (WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument):
+        * dom/Document.h:
+        (WebCore::isDocument):
+        * dom/DocumentFragment.cpp:
+        (WebCore::DocumentFragment::create):
+        * dom/Element.cpp:
+        (WebCore::Element::computeInheritedLanguage):
+        * dom/EventDispatcher.cpp:
+        (WebCore::WindowEventContext::WindowEventContext):
+        * dom/EventTarget.cpp:
+        (WebCore::EventTarget::fireEventListeners):
+        * dom/NamedFlowCollection.cpp:
+        (WebCore::NamedFlowCollection::document):
+        * dom/Node.cpp:
+        (WebCore::Node::isDefaultNamespace):
+        (WebCore::Node::lookupPrefix):
+        (WebCore::Node::lookupNamespaceURI):
+        (WebCore::Node::removedLastRef):
+        * dom/Range.cpp:
+        (WebCore::Range::create):
+        * dom/ScriptExecutionContext.cpp:
+        (WebCore::ScriptExecutionContext::dispatchErrorEvent):
+        * dom/Text.cpp:
+        (WebCore::Text::create):
+        * editing/MarkupAccumulator.cpp:
+        (WebCore::MarkupAccumulator::appendStartMarkup):
+        * html/HTMLDocument.h:
+        (WebCore::isHTMLDocument):
+        * html/HTMLNameCollection.h:
+        (WebCore::HTMLNameCollection::document):
+        * html/HTMLStyleElement.cpp:
+        (WebCore::HTMLStyleElement::insertedInto):
+        * html/ImageDocument.h:
+        (WebCore::isImageDocument):
+        * html/MediaDocument.h:
+        (WebCore::isMediaDocument):
+        * html/PluginDocument.h:
+        (WebCore::isPluginDocument):
+        * html/track/TextTrackCue.h:
+        (WebCore::TextTrackCue::ownerDocument):
+        * html/track/VTTCue.cpp:
+        (WebCore::VTTCue::initialize):
+        * html/track/VTTRegion.h:
+        (WebCore::VTTRegion::ownerDocument):
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::assertDocument):
+        (WebCore::InspectorDOMAgent::buildObjectForNode):
+        (WebCore::InspectorDOMAgent::innerParentNode):
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::frameForScriptExecutionContext):
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::instrumentingAgentsForContext):
+        * loader/TextTrackLoader.cpp:
+        (WebCore::TextTrackLoader::corsPolicyPreventedLoad):
+        (WebCore::TextTrackLoader::notifyFinished):
+        (WebCore::TextTrackLoader::load):
+        * loader/ThreadableLoader.cpp:
+        (WebCore::ThreadableLoader::create):
+        (WebCore::ThreadableLoader::loadResourceSynchronously):
+        * loader/WorkerThreadableLoader.cpp:
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::mainThreadCreateLoader):
+        * page/ContentSecurityPolicy.cpp:
+        (WebCore::ContentSecurityPolicy::reportViolation):
+        * page/Crypto.cpp:
+        (WebCore::Crypto::document):
+        * page/DOMTimer.cpp:
+        (WebCore::DOMTimer::install):
+        (WebCore::DOMTimer::fired):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::focus):
+        (WebCore::DOMWindow::close):
+        (WebCore::DOMWindow::document):
+        (WebCore::DOMWindow::styleMedia):
+        (WebCore::DOMWindow::getComputedStyle):
+        * page/DragController.cpp:
+        (WebCore::DragController::dragExited):
+        (WebCore::DragController::dragEnteredOrUpdated):
+        * page/EventSource.cpp:
+        (WebCore::EventSource::create):
+        * page/FocusController.cpp:
+        (WebCore::FocusController::advanceFocusDirectionally):
+        * page/History.cpp:
+        (WebCore::History::go):
+        * page/SpatialNavigation.cpp:
+        (WebCore::scrollInDirection):
+        (WebCore::scrollableEnclosingBoxOrParentFrameForNodeInDirection):
+        (WebCore::canScrollInDirection):
+        (WebCore::nodeRectInAbsoluteCoordinates):
+        * svg/SVGDocument.h:
+        (WebCore::isSVGDocument):
+        * testing/Internals.cpp:
+        (WebCore::Internals::contextDocument):
+        (WebCore::Internals::frame):
+        (WebCore::Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks):
+        * testing/js/WebCoreTestSupport.cpp:
+        (WebCoreTestSupport::injectInternalsObject):
+        (WebCoreTestSupport::resetInternalsObject):
+        * workers/DefaultSharedWorkerRepository.cpp:
+        (WebCore::SharedWorkerProxy::addToWorkerDocuments):
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::document):
+        (WebCore::XMLHttpRequest::open):
+
 2014-09-29  David Hyatt  <hyatt@apple.com>
 
         REGRESSION (r168046): Confused column spans when combined with dynamic animations
index 3da82a5..7d84811 100644 (file)
@@ -250,17 +250,17 @@ Geolocation::~Geolocation()
 
 Document* Geolocation::document() const
 {
-    return toDocument(scriptExecutionContext());
+    return downcast<Document>(scriptExecutionContext());
 }
 
 Frame* Geolocation::frame() const
 {
-    return document() ? document()->frame() : 0;
+    return document() ? document()->frame() : nullptr;
 }
 
 Page* Geolocation::page() const
 {
-    return document() ? document()->page() : 0;
+    return document() ? document()->page() : nullptr;
 }
 
 #if PLATFORM(IOS)
index edafd7e..ce01007 100644 (file)
@@ -68,10 +68,10 @@ IDBFactory::~IDBFactory()
 namespace {
 static bool isContextValid(ScriptExecutionContext* context)
 {
-    ASSERT(context->isDocument() || context->isWorkerGlobalScope());
-    if (context->isDocument()) {
-        Document* document = toDocument(context);
-        return document->frame() && document->page() && (!document->page()->usesEphemeralSession() || SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document->securityOrigin()->protocol()));
+    ASSERT(is<Document>(context) || context->isWorkerGlobalScope());
+    if (is<Document>(context)) {
+        Document& document = downcast<Document>(*context);
+        return document.frame() && document.page() && (!document.page()->usesEphemeralSession() || SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document.securityOrigin()->protocol()));
     }
     return true;
 }
@@ -79,9 +79,9 @@ static bool isContextValid(ScriptExecutionContext* context)
 static String getIndexedDBDatabasePath(ScriptExecutionContext* context)
 {
     ASSERT(isContextValid(context));
-    if (context->isDocument()) {
-        Document* document = toDocument(context);
-        return document->page()->group().groupSettings().indexedDBDatabasePath();
+    if (is<Document>(context)) {
+        Document& document = downcast<Document>(*context);
+        return document.page()->group().groupSettings().indexedDBDatabasePath();
     }
     const GroupSettings* groupSettings = toWorkerGlobalScope(context)->groupSettings();
     if (groupSettings)
index 9f3c96a..ca534ce 100644 (file)
@@ -1796,7 +1796,7 @@ Vector<String> SourceBuffer::bufferedSamplesForTrackID(const AtomicString& track
 Document& SourceBuffer::document() const
 {
     ASSERT(scriptExecutionContext());
-    return *toDocument(scriptExecutionContext());
+    return downcast<Document>(*scriptExecutionContext());
 }
 
 } // namespace WebCore
index 29dc192..3519c3d 100644 (file)
@@ -178,7 +178,7 @@ RTCPeerConnection::RTCPeerConnection(ScriptExecutionContext& context, PassRefPtr
     , m_configuration(configuration)
     , m_stopped(false)
 {
-    Document& document = toDocument(context);
+    Document& document = downcast<Document>(context);
 
     if (!document.frame()) {
         ec = NOT_SUPPORTED_ERR;
index e9cb035..36ae61f 100644 (file)
@@ -86,7 +86,7 @@ Notification::Notification(ScriptExecutionContext& context, const String& title)
     , m_state(Idle)
     , m_taskTimer(std::make_unique<Timer<Notification>>(this, &Notification::taskTimerFired))
 {
-    m_notificationCenter = DOMWindowNotifications::webkitNotifications(toDocument(context).domWindow());
+    m_notificationCenter = DOMWindowNotifications::webkitNotifications(downcast<Document>(context).domWindow());
     
     ASSERT(m_notificationCenter->client());
     m_taskTimer->startOneShot(0);
@@ -135,9 +135,9 @@ void Notification::show()
     // prevent double-showing
     if (m_state == Idle && m_notificationCenter->client()) {
 #if ENABLE(NOTIFICATIONS)
-        if (!toDocument(scriptExecutionContext())->page())
+        if (!downcast<Document>(*scriptExecutionContext()).page())
             return;
-        if (NotificationController::from(toDocument(scriptExecutionContext())->page())->client()->checkPermission(scriptExecutionContext()) != NotificationClient::PermissionAllowed) {
+        if (NotificationController::from(downcast<Document>(*scriptExecutionContext()).page())->client()->checkPermission(scriptExecutionContext()) != NotificationClient::PermissionAllowed) {
             dispatchErrorEvent();
             return;
         }
@@ -213,8 +213,8 @@ void Notification::taskTimerFired(Timer<Notification>& timer)
 #if ENABLE(NOTIFICATIONS)
 const String Notification::permission(ScriptExecutionContext* context)
 {
-    ASSERT(toDocument(context)->page());
-    return permissionString(NotificationController::from(toDocument(context)->page())->client()->checkPermission(context));
+    ASSERT(downcast<Document>(*context).page());
+    return permissionString(NotificationController::from(downcast<Document>(*context).page())->client()->checkPermission(context));
 }
 
 const String Notification::permissionString(NotificationClient::Permission permission)
@@ -234,8 +234,8 @@ const String Notification::permissionString(NotificationClient::Permission permi
 
 void Notification::requestPermission(ScriptExecutionContext* context, PassRefPtr<NotificationPermissionCallback> callback)
 {
-    ASSERT(toDocument(context)->page());
-    NotificationController::from(toDocument(context)->page())->client()->requestPermission(context, callback);
+    ASSERT(downcast<Document>(*context).page());
+    NotificationController::from(downcast<Document>(*context).page())->client()->requestPermission(context, callback);
 }
 #endif
 
index 364c0c6..cf9959f 100644 (file)
@@ -325,7 +325,7 @@ void AudioContext::stop()
 Document* AudioContext::document() const
 {
     ASSERT(m_scriptExecutionContext);
-    return toDocument(m_scriptExecutionContext);
+    return downcast<Document>(m_scriptExecutionContext);
 }
 
 PassRefPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionCode& ec)
index 3bece30..309b1db 100644 (file)
@@ -37,12 +37,12 @@ namespace WebCore {
 PassRefPtr<OfflineAudioContext> OfflineAudioContext::create(ScriptExecutionContext& context, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionCode& ec)
 {
     // FIXME: add support for workers.
-    if (!context.isDocument()) {
+    if (!is<Document>(context)) {
         ec = NOT_SUPPORTED_ERR;
         return nullptr;
     }
 
-    Document& document = toDocument(context);
+    Document& document = downcast<Document>(context);
 
     if (numberOfChannels > 10 || !isSampleRateRangeGood(sampleRate)) {
         ec = SYNTAX_ERR;
index 28f076a..38da15a 100644 (file)
@@ -218,9 +218,9 @@ bool DatabaseContext::stopDatabases(DatabaseTaskSynchronizer* synchronizer)
 
 bool DatabaseContext::allowDatabaseAccess() const
 {
-    if (m_scriptExecutionContext->isDocument()) {
-        Document* document = toDocument(m_scriptExecutionContext);
-        if (!document->page() || (document->page()->usesEphemeralSession() && !SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document->securityOrigin()->protocol())))
+    if (is<Document>(*m_scriptExecutionContext)) {
+        Document& document = downcast<Document>(*m_scriptExecutionContext);
+        if (!document.page() || (document.page()->usesEphemeralSession() && !SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document.securityOrigin()->protocol())))
             return false;
         return true;
     }
@@ -231,10 +231,10 @@ bool DatabaseContext::allowDatabaseAccess() const
 
 void DatabaseContext::databaseExceededQuota(const String& name, DatabaseDetails details)
 {
-    if (m_scriptExecutionContext->isDocument()) {
-        Document* document = toDocument(m_scriptExecutionContext);
-        if (Page* page = document->page())
-            page->chrome().client().exceededDatabaseQuota(document->frame(), name, details);
+    if (is<Document>(*m_scriptExecutionContext)) {
+        Document& document = downcast<Document>(*m_scriptExecutionContext);
+        if (Page* page = document.page())
+            page->chrome().client().exceededDatabaseQuota(document.frame(), name, details);
         return;
     }
     ASSERT(m_scriptExecutionContext->isWorkerGlobalScope());
index 5541c3e..1654dd5 100644 (file)
@@ -64,7 +64,7 @@ PassRefPtr<ThreadableWebSocketChannel> ThreadableWebSocketChannel::create(Script
         return WorkerThreadableWebSocketChannel::create(workerGlobalScope, client, mode.toString());
     }
 
-    return WebSocketChannel::create(toDocument(context), client);
+    return WebSocketChannel::create(downcast<Document>(context), client);
 }
 
 } // namespace WebCore
index db3ce8e..98bdce2 100644 (file)
@@ -239,9 +239,9 @@ void WebSocket::connect(const String& url, const Vector<String>& protocols, Exce
 
     // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
     bool shouldBypassMainWorldContentSecurityPolicy = false;
-    if (scriptExecutionContext()->isDocument()) {
-        Document* document = toDocument(scriptExecutionContext());
-        shouldBypassMainWorldContentSecurityPolicy = document->frame()->script().shouldBypassMainWorldContentSecurityPolicy();
+    if (is<Document>(scriptExecutionContext())) {
+        Document& document = downcast<Document>(*scriptExecutionContext());
+        shouldBypassMainWorldContentSecurityPolicy = document.frame()->script().shouldBypassMainWorldContentSecurityPolicy();
     }
     if (!shouldBypassMainWorldContentSecurityPolicy && !scriptExecutionContext()->contentSecurityPolicy()->allowConnectToSource(m_url)) {
         m_state = CLOSED;
index cce332b..f366a2d 100644 (file)
@@ -196,9 +196,9 @@ CString WebSocketHandshake::clientHandshakeMessage() const
         fields.append("Sec-WebSocket-Protocol: " + m_clientProtocol);
 
     URL url = httpURLForAuthenticationAndCookies();
-    if (m_context->isDocument()) {
-        Document* document = toDocument(m_context);
-        String cookie = cookieRequestHeaderFieldValue(document, url);
+    if (is<Document>(m_context)) {
+        Document& document = downcast<Document>(*m_context);
+        String cookie = cookieRequestHeaderFieldValue(&document, url);
         if (!cookie.isEmpty())
             fields.append("Cookie: " + cookie);
         // Set "Cookie2: <cookie>" if cookies 2 exists for url?
@@ -247,9 +247,9 @@ ResourceRequest WebSocketHandshake::clientHandshakeRequest() const
         request.setHTTPHeaderField(HTTPHeaderName::SecWebSocketProtocol, m_clientProtocol);
 
     URL url = httpURLForAuthenticationAndCookies();
-    if (m_context->isDocument()) {
-        Document* document = toDocument(m_context);
-        String cookie = cookieRequestHeaderFieldValue(document, url);
+    if (is<Document>(*m_context)) {
+        Document& document = downcast<Document>(*m_context);
+        String cookie = cookieRequestHeaderFieldValue(&document, url);
         if (!cookie.isEmpty())
             request.setHTTPHeaderField(HTTPHeaderName::Cookie, cookie);
         // Set "Cookie2: <cookie>" if cookies 2 exists for url?
index 758193f..890cb1d 100644 (file)
@@ -147,7 +147,7 @@ void WorkerThreadableWebSocketChannel::resume()
 WorkerThreadableWebSocketChannel::Peer::Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode)
     : m_workerClientWrapper(clientWrapper)
     , m_loaderProxy(loaderProxy)
-    , m_mainWebSocketChannel(WebSocketChannel::create(toDocument(context), this))
+    , m_mainWebSocketChannel(WebSocketChannel::create(downcast<Document>(context), this))
     , m_taskMode(taskMode)
 {
     ASSERT(isMainThread());
index a4643e3..e6c9504 100644 (file)
@@ -100,9 +100,9 @@ WebKitDOMNode* wrap(Node* node)
     case Node::COMMENT_NODE:
         return WEBKIT_DOM_NODE(wrapComment(static_cast<Comment*>(node)));
     case Node::DOCUMENT_NODE:
-        if (toDocument(node)->isHTMLDocument())
-            return WEBKIT_DOM_NODE(wrapHTMLDocument(static_cast<HTMLDocument*>(node)));
-        return WEBKIT_DOM_NODE(wrapDocument(toDocument(node)));
+        if (is<HTMLDocument>(node))
+            return WEBKIT_DOM_NODE(wrapHTMLDocument(downcast<HTMLDocument>(node)));
+        return WEBKIT_DOM_NODE(wrapDocument(downcast<Document>(node)));
     case Node::DOCUMENT_TYPE_NODE:
         return WEBKIT_DOM_NODE(wrapDocumentType(static_cast<DocumentType*>(node)));
     case Node::DOCUMENT_FRAGMENT_NODE:
index 5c98f61..3e26988 100644 (file)
@@ -32,7 +32,7 @@ class DOMConstructorWithDocument : public DOMConstructorObject {
 public:
     Document* document() const
     {
-        return toDocument(scriptExecutionContext());
+        return downcast<Document>(scriptExecutionContext());
     }
 
 protected:
index 9071561..2a4714c 100644 (file)
@@ -41,11 +41,11 @@ class DOMRequestState {
 public:
     explicit DOMRequestState(ScriptExecutionContext* scriptExecutionContext)
         : m_scriptExecutionContext(scriptExecutionContext)
-        , m_exec(0)
+        , m_exec(nullptr)
     {
-        if (m_scriptExecutionContext->isDocument()) {
-            Document* document = toDocument(m_scriptExecutionContext);
-            m_exec = execStateFromPage(mainThreadNormalWorld(), document->page());
+        if (is<Document>(*m_scriptExecutionContext)) {
+            Document& document = downcast<Document>(*m_scriptExecutionContext);
+            m_exec = execStateFromPage(mainThreadNormalWorld(), document.page());
         } else {
             WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(m_scriptExecutionContext);
             m_exec = execStateFromWorkerGlobalScope(workerGlobalScope);
@@ -54,8 +54,8 @@ public:
 
     void clear()
     {
-        m_scriptExecutionContext = 0;
-        m_exec = 0;
+        m_scriptExecutionContext = nullptr;
+        m_exec = nullptr;
     }
 
     class Scope {
index 34b45f3..5c8412a 100644 (file)
@@ -53,10 +53,10 @@ EncodedJSValue JSC_HOST_CALL constructJSAudioContext(ExecState* exec)
     if (!scriptExecutionContext)
         return throwVMError(exec, createReferenceError(exec, "AudioContext constructor script execution context is unavailable"));
         
-    if (!scriptExecutionContext->isDocument())
+    if (!is<Document>(scriptExecutionContext))
         return throwVMError(exec, createReferenceError(exec, "AudioContext constructor called in a script execution context which is not a document"));
 
-    Document& document = toDocument(*scriptExecutionContext);
+    Document& document = downcast<Document>(*scriptExecutionContext);
 
     RefPtr<AudioContext> audioContext;
     
index ac9dd75..99c402c 100644 (file)
@@ -105,14 +105,14 @@ JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, JSC::ExecState* exec)
 
 JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, JSC::ExecState* exec)
 {
-    if (scriptExecutionContext->isDocument())
-        return toJSDOMGlobalObject(toDocument(scriptExecutionContext), exec);
+    if (is<Document>(scriptExecutionContext))
+        return toJSDOMGlobalObject(downcast<Document>(scriptExecutionContext), exec);
 
     if (scriptExecutionContext->isWorkerGlobalScope())
         return toWorkerGlobalScope(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
 
     ASSERT_NOT_REACHED();
-    return 0;
+    return nullptr;
 }
 
 JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, DOMWrapperWorld& world)
@@ -122,14 +122,14 @@ JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, DOMWrapperWorld& worl
 
 JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, DOMWrapperWorld& world)
 {
-    if (scriptExecutionContext->isDocument())
-        return toJSDOMGlobalObject(toDocument(scriptExecutionContext), world);
+    if (is<Document>(scriptExecutionContext))
+        return toJSDOMGlobalObject(downcast<Document>(scriptExecutionContext), world);
 
     if (scriptExecutionContext->isWorkerGlobalScope())
         return toWorkerGlobalScope(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
 
     ASSERT_NOT_REACHED();
-    return 0;
+    return nullptr;
 }
 
 } // namespace WebCore
index 6e34d21..b2cc276 100644 (file)
@@ -73,30 +73,30 @@ JSLazyEventListener::~JSLazyEventListener()
 JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* executionContext) const
 {
     ASSERT(executionContext);
-    ASSERT(executionContext->isDocument());
+    ASSERT(is<Document>(executionContext));
     if (!executionContext)
-        return 0;
+        return nullptr;
 
     ASSERT(!m_code.isNull());
     ASSERT(!m_eventParameterName.isNull());
     if (m_code.isNull() || m_eventParameterName.isNull())
-        return 0;
+        return nullptr;
 
-    Document* document = toDocument(executionContext);
+    Document& document = downcast<Document>(*executionContext);
 
-    if (!document->frame())
-        return 0;
+    if (!document.frame())
+        return nullptr;
 
-    if (!document->contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL, m_position.m_line))
-        return 0;
+    if (!document.contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL, m_position.m_line))
+        return nullptr;
 
-    ScriptController& script = document->frame()->script();
+    ScriptController& script = document.frame()->script();
     if (!script.canExecuteScripts(AboutToExecuteScript) || script.isPaused())
-        return 0;
+        return nullptr;
 
     JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(executionContext, isolatedWorld());
     if (!globalObject)
-        return 0;
+        return nullptr;
 
     ExecState* exec = globalObject->globalExec();
 
@@ -108,7 +108,7 @@ JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* exec
     if (exec->hadException()) {
         reportCurrentException(exec);
         exec->clearException();
-        return 0;
+        return nullptr;
     }
 
     JSFunction* listenerAsFunction = jsCast<JSFunction*>(jsFunction);
index 7d08a20..cf80609 100644 (file)
@@ -219,7 +219,7 @@ static ALWAYS_INLINE JSValue createWrapperInline(ExecState* exec, JSDOMGlobalObj
             break;
         case Node::DOCUMENT_NODE:
             // we don't want to cache the document itself in the per-document dictionary
-            return toJS(exec, globalObject, toDocument(node));
+            return toJS(exec, globalObject, downcast<Document>(node));
         case Node::DOCUMENT_TYPE_NODE:
             wrapper = CREATE_DOM_WRAPPER(globalObject, DocumentType, node);
             break;
index 37c7728..d11e454 100644 (file)
@@ -74,8 +74,8 @@ ScheduledAction::ScheduledAction(ExecState* exec, JSValue function, DOMWrapperWo
 
 void ScheduledAction::execute(ScriptExecutionContext* context)
 {
-    if (context->isDocument())
-        execute(toDocument(context));
+    if (is<Document>(context))
+        execute(downcast<Document>(context));
     else
         execute(toWorkerGlobalScope(context));
 }
index 70dfd16..376cd25 100644 (file)
@@ -58,7 +58,7 @@ DOMWindow* domWindowFromExecState(JSC::ExecState* scriptState)
 Frame* frameFromExecState(JSC::ExecState* scriptState)
 {
     ScriptExecutionContext* context = scriptExecutionContextFromExecState(scriptState);
-    Document* document = context && context->isDocument() ? toDocument(context) : nullptr;
+    Document* document = context && is<Document>(context) ? downcast<Document>(context) : nullptr;
     return document ? document->frame() : nullptr;
 }
 
index 1bc58c0..68d820c 100644 (file)
@@ -39,7 +39,7 @@ SubtleCrypto::SubtleCrypto(Document& document)
 
 Document* SubtleCrypto::document() const
 {
-    return toDocument(scriptExecutionContext());
+    return downcast<Document>(scriptExecutionContext());
 }
 
 }
index 51300e9..961e8f1 100644 (file)
@@ -38,7 +38,7 @@ PassRefPtr<Comment> Comment::create(Document& document, const String& text)
 
 PassRefPtr<Comment> Comment::create(ScriptExecutionContext& context, const String& text)
 {
-    return adoptRef(new Comment(toDocument(context), text));
+    return adoptRef(new Comment(downcast<Document>(context), text));
 }
 
 String Comment::nodeName() const
index b17b09f..653f697 100644 (file)
@@ -202,8 +202,8 @@ static inline ExceptionCode checkAcceptChild(ContainerNode* newParent, Node* new
     if (containsConsideringHostElements(newChild, newParent))
         return HIERARCHY_REQUEST_ERR;
 
-    if (oldChild && newParent->isDocumentNode()) {
-        if (!toDocument(newParent)->canReplaceChild(newChild, oldChild))
+    if (oldChild && is<Document>(newParent)) {
+        if (!downcast<Document>(*newParent).canReplaceChild(newChild, oldChild))
             return HIERARCHY_REQUEST_ERR;
     } else if (!isChildTypeAllowed(newParent, newChild))
         return HIERARCHY_REQUEST_ERR;
index 804a567..217918e 100644 (file)
@@ -37,7 +37,7 @@ void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument(ContainerN
         // we don't want to tell the rest of our children that they've been
         // inserted into the document because they haven't.
         if (node.inDocument() && child->parentNode() == &node)
-            notifyNodeInsertedIntoDocument(*child.get());
+            notifyNodeInsertedIntoDocument(*child);
     }
 
     if (!node.isElementNode())
@@ -45,7 +45,7 @@ void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument(ContainerN
 
     if (RefPtr<ShadowRoot> root = toElement(node).shadowRoot()) {
         if (node.inDocument() && root->hostElement() == &node)
-            notifyNodeInsertedIntoDocument(*root.get());
+            notifyNodeInsertedIntoDocument(*root);
     }
 }
 
index 9f7a25d..c42d442 100644 (file)
@@ -1740,12 +1740,10 @@ inline ScriptExecutionContext* Node::scriptExecutionContext() const
 
 Element* eventTargetElementForDocument(Document*);
 
-SCRIPT_EXECUTION_CONTEXT_TYPE_CASTS(Document)
-
-inline bool isDocument(const Node& node) { return node.isDocumentNode(); }
-void isDocument(const Document&); // Catch unnecessary runtime check of type known at compile time.
-
-NODE_TYPE_CASTS(Document)
+SPECIALIZE_TYPE_TRAITS_BEGIN(Document)
+    static bool isDocument(const ScriptExecutionContext& context) { return context.isDocument(); }
+    static bool isDocument(const Node& node) { return node.isDocumentNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 } // namespace WebCore
 
index 7b1ba3a..67ecb17 100644 (file)
@@ -43,7 +43,7 @@ PassRefPtr<DocumentFragment> DocumentFragment::create(Document& document)
 
 PassRefPtr<DocumentFragment> DocumentFragment::create(ScriptExecutionContext& context)
 {
-    return adoptRef(new DocumentFragment(toDocument(context), Node::CreateDocumentFragment));
+    return adoptRef(new DocumentFragment(downcast<Document>(context), Node::CreateDocumentFragment));
 }
 
 String DocumentFragment::nodeName() const
index 2da8e73..21ad566 100644 (file)
@@ -2200,9 +2200,9 @@ AtomicString Element::computeInheritedLanguage() const
                 if (const Attribute* attribute = elementData->findLanguageAttribute())
                     return attribute->value();
             }
-        } else if (currentNode->isDocumentNode()) {
+        } else if (is<Document>(currentNode)) {
             // checking the MIME content-language
-            return toDocument(currentNode)->contentLanguage();
+            return downcast<Document>(*currentNode).contentLanguage();
         }
     }
 
index 5a0db4e..c6e25ed 100644 (file)
@@ -60,10 +60,10 @@ private:
 WindowEventContext::WindowEventContext(PassRefPtr<Node> node, const EventContext* topEventContext)
 {
     Node* topLevelContainer = topEventContext ? topEventContext->node() : node.get();
-    if (!topLevelContainer->isDocumentNode())
+    if (!is<Document>(topLevelContainer))
         return;
 
-    m_window = toDocument(topLevelContainer)->domWindow();
+    m_window = downcast<Document>(*topLevelContainer).domWindow();
     m_target = topEventContext ? topEventContext->target() : node.get();
 }
 
index 265178c..4837d86 100644 (file)
@@ -223,8 +223,8 @@ void EventTarget::fireEventListeners(Event* event, EventTargetData* d, EventList
     ScriptExecutionContext* context = scriptExecutionContext();
     Document* document = nullptr;
     InspectorInstrumentationCookie willDispatchEventCookie;
-    if (context && context->isDocument()) {
-        document = toDocument(context);
+    if (context && is<Document>(context)) {
+        document = downcast<Document>(context);
         willDispatchEventCookie = InspectorInstrumentation::willDispatchEvent(document, *event, size > 0);
     }
 
index ee92f04..6867840 100644 (file)
@@ -101,7 +101,7 @@ void NamedFlowCollection::discardNamedFlow(WebKitNamedFlow* namedFlow)
 Document* NamedFlowCollection::document() const
 {
     ScriptExecutionContext* context = ContextDestructionObserver::scriptExecutionContext();
-    return toDocument(context);
+    return downcast<Document>(context);
 }
 
 PassRefPtr<DOMNamedFlowCollection> NamedFlowCollection::createCSSOMSnapshot()
index db97de2..ea92da8 100644 (file)
@@ -1162,8 +1162,8 @@ bool Node::isDefaultNamespace(const AtomicString& namespaceURIMaybeEmpty) const
             return false;
         }
         case DOCUMENT_NODE:
-            if (Element* de = toDocument(this)->documentElement())
-                return de->isDefaultNamespace(namespaceURI);
+            if (Element* documentElement = downcast<Document>(*this).documentElement())
+                return documentElement->isDefaultNamespace(namespaceURI);
             return false;
         case ENTITY_NODE:
         case NOTATION_NODE:
@@ -1195,8 +1195,8 @@ String Node::lookupPrefix(const AtomicString &namespaceURI) const
         case ELEMENT_NODE:
             return lookupNamespacePrefix(namespaceURI, static_cast<const Element *>(this));
         case DOCUMENT_NODE:
-            if (Element* de = toDocument(this)->documentElement())
-                return de->lookupPrefix(namespaceURI);
+            if (Element* documentElement = downcast<Document>(*this).documentElement())
+                return documentElement->lookupPrefix(namespaceURI);
             return String();
         case ENTITY_NODE:
         case NOTATION_NODE:
@@ -1253,8 +1253,8 @@ String Node::lookupNamespaceURI(const String &prefix) const
             return String();
         }
         case DOCUMENT_NODE:
-            if (Element* de = toDocument(this)->documentElement())
-                return de->lookupNamespaceURI(prefix);
+            if (Element* documentElement = downcast<Document>(*this).documentElement())
+                return documentElement->lookupNamespaceURI(prefix);
             return String();
         case ENTITY_NODE:
         case NOTATION_NODE:
@@ -2198,8 +2198,8 @@ void Node::removedLastRef()
     // An explicit check for Document here is better than a virtual function since it is
     // faster for non-Document nodes, and because the call to removedLastRef that is inlined
     // at all deref call sites is smaller if it's a non-virtual function.
-    if (isDocumentNode()) {
-        toDocument(*this).removedLastRef();
+    if (is<Document>(*this)) {
+        downcast<Document>(*this).removedLastRef();
         return;
     }
 
index 292fa5a..88b9b61 100644 (file)
@@ -106,7 +106,7 @@ PassRefPtr<Range> Range::create(Document& ownerDocument, const Position& start,
 
 PassRefPtr<Range> Range::create(ScriptExecutionContext& context)
 {
-    return adoptRef(new Range(toDocument(context)));
+    return adoptRef(new Range(downcast<Document>(context)));
 }
 
 PassRefPtr<Range> Range::create(Document& ownerDocument, const VisiblePosition& visibleStart, const VisiblePosition& visibleEnd)
index 5f405af..50a84c7 100644 (file)
@@ -378,8 +378,8 @@ bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int
         return false;
 
 #if PLATFORM(IOS)
-    if (target == target->toDOMWindow() && isDocument()) {
-        Settings* settings = toDocument(this)->settings();
+    if (target == target->toDOMWindow() && is<Document>(*this)) {
+        Settings* settings = downcast<Document>(*this).settings();
         if (settings && !settings->shouldDispatchJavaScriptWindowOnErrorEvents())
             return false;
     }
index 79a45df..7d289b0 100644 (file)
@@ -45,7 +45,7 @@ PassRefPtr<Text> Text::create(Document& document, const String& data)
 
 PassRefPtr<Text> Text::create(ScriptExecutionContext& context, const String& data)
 {
-    return adoptRef(new Text(toDocument(context), data, CreateText));
+    return adoptRef(new Text(downcast<Document>(context), data, CreateText));
 }
 
 PassRefPtr<Text> Text::createEditingText(Document& document, const String& data)
index dbe9688..73e19ba 100644 (file)
@@ -559,7 +559,7 @@ void MarkupAccumulator::appendStartMarkup(StringBuilder& result, const Node& nod
         appendComment(result, downcast<Comment>(node).data());
         break;
     case Node::DOCUMENT_NODE:
-        appendXMLDeclaration(result, toDocument(node));
+        appendXMLDeclaration(result, downcast<Document>(node));
         break;
     case Node::DOCUMENT_FRAGMENT_NODE:
         break;
index e5a09e9..0a9b5a2 100644 (file)
@@ -99,7 +99,7 @@ private:
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLDocument)
     static bool isHTMLDocument(const Document& document) { return document.isHTMLDocument(); }
-    static bool isHTMLDocument(const Node& node) { return node.isDocumentNode() && isHTMLDocument(toDocument(node)); }
+    static bool isHTMLDocument(const Node& node) { return is<Document>(node) && isHTMLDocument(downcast<Document>(node)); }
 SPECIALIZE_TYPE_TRAITS_END()
 
 } // namespace WebCore
index 80100f6..0914c54 100644 (file)
@@ -35,7 +35,7 @@ class HTMLNameCollection : public HTMLCollection {
 public:
     ~HTMLNameCollection();
 
-    Document& document() { return toDocument(ownerNode()); }
+    Document& document() { return downcast<Document>(ownerNode()); }
 
 protected:
     HTMLNameCollection(Document&, CollectionType, const AtomicString& name);
index c9a2976..781d02c 100644 (file)
@@ -84,7 +84,7 @@ private:
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(ImageDocument)
     static bool isImageDocument(const Document& document) { return document.isImageDocument(); }
-    static bool isImageDocument(const Node& node) { return node.isDocumentNode() && isImageDocument(toDocument(node)); }
+    static bool isImageDocument(const Node& node) { return is<Document>(node) && isImageDocument(downcast<Document>(node)); }
 SPECIALIZE_TYPE_TRAITS_END()
 
 }
index 7be9e61..ab5ed08 100644 (file)
@@ -58,7 +58,7 @@ private:
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(MediaDocument)
     static bool isMediaDocument(const Document& document) { return document.isMediaDocument(); }
-    static bool isMediaDocument(const Node& node) { return node.isDocumentNode() && isMediaDocument(toDocument(node)); }
+    static bool isMediaDocument(const Node& node) { return is<Document>(node) && isMediaDocument(downcast<Document>(node)); }
 SPECIALIZE_TYPE_TRAITS_END()
 
 }
index 012fb97..18834d6 100644 (file)
@@ -63,7 +63,7 @@ private:
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(PluginDocument)
     static bool isPluginDocument(const Document& document) { return document.isPluginDocument(); }
-    static bool isPluginDocument(const Node& node) { return node.isDocumentNode() && isPluginDocument(toDocument(node)); }
+    static bool isPluginDocument(const Node& node) { return is<Document>(node) && isPluginDocument(downcast<Document>(node)); }
 SPECIALIZE_TYPE_TRAITS_END()
 
 }
index f0ee66b..951fe8c 100644 (file)
@@ -120,7 +120,7 @@ public:
 protected:
     TextTrackCue(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end);
 
-    Document& ownerDocument() { return toDocument(m_scriptExecutionContext); }
+    Document& ownerDocument() { return downcast<Document>(m_scriptExecutionContext); }
 
 private:
 
index ab1988f..59cf6e9 100644 (file)
@@ -288,8 +288,8 @@ void VTTCue::initialize(ScriptExecutionContext& context)
     m_writingDirection = Horizontal;
     m_cueAlignment = Middle;
     m_webVTTNodeTree = nullptr;
-    m_cueBackdropBox = HTMLDivElement::create(toDocument(context));
-    m_cueHighlightBox = HTMLSpanElement::create(spanTag, toDocument(context));
+    m_cueBackdropBox = HTMLDivElement::create(downcast<Document>(context));
+    m_cueHighlightBox = HTMLSpanElement::create(spanTag, downcast<Document>(context));
     m_displayDirection = CSSValueLtr;
     m_displaySize = 0;
     m_snapToLines = true;
index 40281a5..db965ab 100644 (file)
@@ -98,7 +98,7 @@ public:
 private:
     VTTRegion(ScriptExecutionContext&);
 
-    Document* ownerDocument() { return toDocument(m_scriptExecutionContext); }
+    Document* ownerDocument() { return downcast<Document>(m_scriptExecutionContext); }
 
     void prepareRegionDisplayTree();
 
index bc3744d..cf2f745 100644 (file)
@@ -379,11 +379,11 @@ Document* InspectorDOMAgent::assertDocument(ErrorString* errorString, int nodeId
     Node* node = assertNode(errorString, nodeId);
     if (!node)
         return nullptr;
-    if (!node->isDocumentNode()) {
+    if (!is<Document>(node)) {
         *errorString = "Document is not available";
         return nullptr;
     }
-    return toDocument(node);
+    return downcast<Document>(node);
 }
 
 Element* InspectorDOMAgent::assertElement(ErrorString* errorString, int nodeId)
@@ -1301,11 +1301,11 @@ PassRefPtr<Inspector::Protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode
             value->setTemplateContent(buildObjectForNode(downcast<HTMLTemplateElement>(*element).content(), 0, nodesMap));
 #endif
 
-    } else if (node->isDocumentNode()) {
-        Document* document = toDocument(node);
-        value->setDocumentURL(documentURLString(document));
-        value->setBaseURL(documentBaseURLString(document));
-        value->setXmlVersion(document->xmlVersion());
+    } else if (is<Document>(node)) {
+        Document& document = downcast<Document>(*node);
+        value->setDocumentURL(documentURLString(&document));
+        value->setBaseURL(documentBaseURLString(&document));
+        value->setXmlVersion(document.xmlVersion());
     } else if (is<DocumentType>(node)) {
         DocumentType& docType = downcast<DocumentType>(*node);
         value->setPublicId(docType.publicId());
@@ -1728,10 +1728,8 @@ unsigned InspectorDOMAgent::innerChildNodeCount(Node* node)
 
 Node* InspectorDOMAgent::innerParentNode(Node* node)
 {
-    if (node->isDocumentNode()) {
-        Document* document = toDocument(node);
-        return document->ownerElement();
-    }
+    if (is<Document>(node))
+        return downcast<Document>(*node).ownerElement();
     return node->parentNode();
 }
 
index 7b65b0b..ef008d3 100644 (file)
@@ -100,8 +100,8 @@ int InspectorInstrumentation::s_frontendCounter = 0;
 static Frame* frameForScriptExecutionContext(ScriptExecutionContext* context)
 {
     Frame* frame = nullptr;
-    if (context->isDocument())
-        frame = toDocument(context)->frame();
+    if (is<Document>(context))
+        frame = downcast<Document>(context)->frame();
     return frame;
 }
 
index d0a5bbb..b9e0ce5 100644 (file)
@@ -2062,8 +2062,8 @@ inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForCont
 {
     if (!context)
         return nullptr;
-    if (context->isDocument())
-        return instrumentingAgentsForPage(toDocument(context)->page());
+    if (is<Document>(context))
+        return instrumentingAgentsForPage(downcast<Document>(context)->page());
     return instrumentingAgentsForNonDocumentContext(context);
 }
 
index 4b0f651..353cef2 100644 (file)
@@ -117,7 +117,7 @@ void TextTrackLoader::deprecatedDidReceiveCachedResource(CachedResource* resourc
 void TextTrackLoader::corsPolicyPreventedLoad()
 {
     DEPRECATED_DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Cross-origin text track load denied by Cross-Origin Resource Sharing policy.")));
-    Document* document = toDocument(m_scriptExecutionContext);
+    Document* document = downcast<Document>(m_scriptExecutionContext);
     document->addConsoleMessage(MessageSource::Security, MessageLevel::Error, consoleMessage);
     m_state = Failed;
 }
@@ -126,7 +126,7 @@ void TextTrackLoader::notifyFinished(CachedResource* resource)
 {
     ASSERT(m_resource == resource);
 
-    Document* document = toDocument(m_scriptExecutionContext);
+    Document* document = downcast<Document>(m_scriptExecutionContext);
     if (!m_crossOriginMode.isNull()
         && !document->securityOrigin()->canRequest(resource->response().url())
         && !resource->passesAccessControlCheck(document->securityOrigin())) {
@@ -155,8 +155,8 @@ bool TextTrackLoader::load(const URL& url, const String& crossOriginMode)
 {
     cancelLoad();
 
-    ASSERT(m_scriptExecutionContext->isDocument());
-    Document* document = toDocument(m_scriptExecutionContext);
+    ASSERT(is<Document>(m_scriptExecutionContext));
+    Document* document = downcast<Document>(m_scriptExecutionContext);
     CachedResourceRequest cueRequest(ResourceRequest(document->completeURL(url)));
 
     if (!crossOriginMode.isNull()) {
index 41a7c1a..2e8c2bf 100644 (file)
@@ -59,7 +59,7 @@ PassRefPtr<ThreadableLoader> ThreadableLoader::create(ScriptExecutionContext* co
     if (context->isWorkerGlobalScope())
         return WorkerThreadableLoader::create(toWorkerGlobalScope(context), client, WorkerRunLoop::defaultMode(), request, options);
 
-    return DocumentThreadableLoader::create(toDocument(*context), *client, request, options);
+    return DocumentThreadableLoader::create(downcast<Document>(*context), *client, request, options);
 }
 
 void ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext* context, const ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoaderOptions& options)
@@ -71,7 +71,7 @@ void ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext* context
         return;
     }
 
-    DocumentThreadableLoader::loadResourceSynchronously(*toDocument(context), request, client, options);
+    DocumentThreadableLoader::loadResourceSynchronously(*downcast<Document>(context), request, client, options);
 }
 
 } // namespace WebCore
index 6110ec3..85795a8 100644 (file)
@@ -101,14 +101,14 @@ WorkerThreadableLoader::MainThreadBridge::~MainThreadBridge()
 void WorkerThreadableLoader::MainThreadBridge::mainThreadCreateLoader(ScriptExecutionContext& context, MainThreadBridge* thisPtr, PassOwnPtr<CrossThreadResourceRequestData> requestData, ThreadableLoaderOptions options, const String& outgoingReferrer)
 {
     ASSERT(isMainThread());
-    Document* document = toDocument(&context);
+    Document& document = downcast<Document>(context);
 
     OwnPtr<ResourceRequest> request(ResourceRequest::adopt(requestData));
     request->setHTTPReferrer(outgoingReferrer);
     // FIXME: If the a site requests a local resource, then this will return a non-zero value but the sync path
     // will return a 0 value.  Either this should return 0 or the other code path should do a callback with
     // a failure.
-    thisPtr->m_mainThreadLoader = DocumentThreadableLoader::create(*document, *thisPtr, *request, options);
+    thisPtr->m_mainThreadLoader = DocumentThreadableLoader::create(document, *thisPtr, *request, options);
     ASSERT(thisPtr->m_mainThreadLoader);
 }
 
index f9c5c98..44aff16 100644 (file)
@@ -1577,20 +1577,20 @@ void ContentSecurityPolicy::enforceSandboxFlags(SandboxFlags mask) const
     m_scriptExecutionContext->enforceSandboxFlags(mask);
 }
 
-static String stripURLForUseInReport(Document* document, const URL& url)
+static String stripURLForUseInReport(Document& document, const URL& url)
 {
     if (!url.isValid())
         return String();
     if (!url.isHierarchical() || url.protocolIs("file"))
         return url.protocol();
-    return document->securityOrigin()->canRequest(url) ? url.strippedForUseAsReferrer() : SecurityOrigin::create(url)->toString();
+    return document.securityOrigin()->canRequest(url) ? url.strippedForUseAsReferrer() : SecurityOrigin::create(url)->toString();
 }
 
 #if ENABLE(CSP_NEXT)
-static void gatherSecurityPolicyViolationEventData(SecurityPolicyViolationEventInit& init, Document* document, const String& directiveText, const String& effectiveDirective, const URL& blockedURL, const String& header)
+static void gatherSecurityPolicyViolationEventData(SecurityPolicyViolationEventInit& init, Document& document, const String& directiveText, const String& effectiveDirective, const URL& blockedURL, const String& header)
 {
-    init.documentURI = document->url().string();
-    init.referrer = document->referrer();
+    init.documentURI = document.url().string();
+    init.referrer = document.referrer();
     init.blockedURI = stripURLForUseInReport(document, blockedURL);
     init.violatedDirective = directiveText;
     init.effectiveDirective = effectiveDirective;
@@ -1613,11 +1613,11 @@ void ContentSecurityPolicy::reportViolation(const String& directiveText, const S
     logToConsole(consoleMessage, contextURL, contextLine, state);
 
     // FIXME: Support sending reports from worker.
-    if (!m_scriptExecutionContext->isDocument())
+    if (!is<Document>(*m_scriptExecutionContext))
         return;
 
-    Document* document = toDocument(m_scriptExecutionContext);
-    Frame* frame = document->frame();
+    Document& document = downcast<Document>(*m_scriptExecutionContext);
+    Frame* frame = document.frame();
     if (!frame)
         return;
 
@@ -1626,7 +1626,7 @@ void ContentSecurityPolicy::reportViolation(const String& directiveText, const S
         // FIXME: This code means that we're gathering information like line numbers twice. Once we can bring this out from behind the flag, we should reuse the data gathered here when generating the JSON report below.
         SecurityPolicyViolationEventInit init;
         gatherSecurityPolicyViolationEventData(init, document, directiveText, effectiveDirective, blockedURL, header);
-        document->enqueueDocumentEvent(SecurityPolicyViolationEvent::create(eventNames().securitypolicyviolationEvent, init));
+        document.enqueueDocumentEvent(SecurityPolicyViolationEvent::create(eventNames().securitypolicyviolationEvent, init));
     }
 #endif
 
@@ -1644,8 +1644,8 @@ void ContentSecurityPolicy::reportViolation(const String& directiveText, const S
     // harmless information.
 
     RefPtr<InspectorObject> cspReport = InspectorObject::create();
-    cspReport->setString(ASCIILiteral("document-uri"), document->url().strippedForUseAsReferrer());
-    cspReport->setString(ASCIILiteral("referrer"), document->referrer());
+    cspReport->setString(ASCIILiteral("document-uri"), document.url().strippedForUseAsReferrer());
+    cspReport->setString(ASCIILiteral("referrer"), document.referrer());
     cspReport->setString(ASCIILiteral("violated-directive"), directiveText);
 #if ENABLE(CSP_NEXT)
     if (experimentalFeaturesEnabled())
index 3358730..8cc0af7 100644 (file)
@@ -59,7 +59,7 @@ Crypto::~Crypto()
 
 Document* Crypto::document() const
 {
-    return toDocument(scriptExecutionContext());
+    return downcast<Document>(scriptExecutionContext());
 }
 
 void Crypto::getRandomValues(ArrayBufferView* array, ExceptionCode& ec)
index b7e18a0..aec9018 100644 (file)
@@ -120,8 +120,8 @@ int DOMTimer::install(ScriptExecutionContext* context, std::unique_ptr<Scheduled
     // is destroyed, or if explicitly cancelled by removeById. 
     DOMTimer* timer = new DOMTimer(context, WTF::move(action), timeout, singleShot);
 #if PLATFORM(IOS)
-    if (context->isDocument()) {
-        Document& document = toDocument(*context);
+    if (is<Document>(context)) {
+        Document& document = downcast<Document>(*context);
         bool didDeferTimeout = document.frame() && document.frame()->timersPaused();
         if (!didDeferTimeout && timeout <= 100 && singleShot) {
             WKSetObservedContentChange(WKContentIndeterminateChange);
@@ -173,8 +173,8 @@ void DOMTimer::fired()
 
 #if PLATFORM(IOS)
     Document* document = nullptr;
-    if (context->isDocument()) {
-        document = toDocument(context);
+    if (is<Document>(context)) {
+        document = downcast<Document>(context);
         ASSERT(!document->frame()->timersPaused());
     }
 #endif
index 2b2f204..41963f1 100644 (file)
@@ -973,8 +973,8 @@ void DOMWindow::focus(ScriptExecutionContext* context)
     bool allowFocus = WindowFocusAllowedIndicator::windowFocusAllowed() || !m_frame->settings().windowFocusRestricted();
     if (context) {
         ASSERT(isMainThread());
-        Document* activeDocument = toDocument(context);
-        if (opener() && opener() != this && activeDocument->domWindow() == opener())
+        Document& activeDocument = downcast<Document>(*context);
+        if (opener() && opener() != this && activeDocument.domWindow() == opener())
             allowFocus = true;
     }
 
@@ -1025,11 +1025,7 @@ void DOMWindow::close(ScriptExecutionContext* context)
 
     if (context) {
         ASSERT(isMainThread());
-        Document* activeDocument = toDocument(context);
-        if (!activeDocument)
-            return;
-
-        if (!activeDocument->canNavigate(m_frame))
+        if (!downcast<Document>(*context).canNavigate(m_frame))
             return;
     }
 
@@ -1413,24 +1409,24 @@ DOMWindow* DOMWindow::top() const
 Document* DOMWindow::document() const
 {
     ScriptExecutionContext* context = ContextDestructionObserver::scriptExecutionContext();
-    return toDocument(context);
+    return downcast<Document>(context);
 }
 
 PassRefPtr<StyleMedia> DOMWindow::styleMedia() const
 {
     if (!isCurrentlyDisplayedInFrame())
-        return 0;
+        return nullptr;
     if (!m_media)
         m_media = StyleMedia::create(m_frame);
     return m_media.get();
 }
 
-PassRefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element* elt, const String& pseudoElt) const
+PassRefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element* element, const String& pseudoElt) const
 {
-    if (!elt)
-        return 0;
+    if (!element)
+        return nullptr;
 
-    return CSSComputedStyleDeclaration::create(elt, false, pseudoElt);
+    return CSSComputedStyleDeclaration::create(element, false, pseudoElt);
 }
 
 PassRefPtr<CSSRuleList> DOMWindow::getMatchedCSSRules(Element* element, const String& pseudoElement, bool authorOnly) const
index dd3f65a..616d131 100644 (file)
@@ -192,10 +192,10 @@ void DragController::dragExited(DragData& dragData)
         m_page.mainFrame().eventHandler().cancelDragAndDrop(createMouseEvent(dragData), dataTransfer.get());
         dataTransfer->setAccessPolicy(DataTransferAccessPolicy::Numb); // Invalidate dataTransfer here for security.
     }
-    mouseMovedIntoDocument(0);
+    mouseMovedIntoDocument(nullptr);
     if (m_fileInputElementUnderMouse)
         m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false);
-    m_fileInputElementUnderMouse = 0;
+    m_fileInputElementUnderMouse = nullptr;
 }
 
 DragOperation DragController::dragUpdated(DragData& dragData)
@@ -255,7 +255,7 @@ DragOperation DragController::dragEnteredOrUpdated(DragData& dragData)
 
     m_dragDestinationAction = m_client.actionMaskForDrag(dragData);
     if (m_dragDestinationAction == DragDestinationActionNone) {
-        cancelDrag(); // FIXME: Why not call mouseMovedIntoDocument(0)?
+        cancelDrag(); // FIXME: Why not call mouseMovedIntoDocument(nullptr)?
         return DragOperationNone;
     }
 
index 072dfaa..336e151 100644 (file)
@@ -77,25 +77,25 @@ PassRefPtr<EventSource> EventSource::create(ScriptExecutionContext& context, con
 {
     if (url.isEmpty()) {
         ec = SYNTAX_ERR;
-        return 0;
+        return nullptr;
     }
 
     URL fullURL = context.completeURL(url);
     if (!fullURL.isValid()) {
         ec = SYNTAX_ERR;
-        return 0;
+        return nullptr;
     }
 
     // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
     bool shouldBypassMainWorldContentSecurityPolicy = false;
-    if (context.isDocument()) {
-        Document& document = toDocument(context);
+    if (is<Document>(context)) {
+        Document& document = downcast<Document>(context);
         shouldBypassMainWorldContentSecurityPolicy = document.frame()->script().shouldBypassMainWorldContentSecurityPolicy();
     }
     if (!shouldBypassMainWorldContentSecurityPolicy && !context.contentSecurityPolicy()->allowConnectToSource(fullURL)) {
         // FIXME: Should this be throwing an exception?
         ec = SECURITY_ERR;
-        return 0;
+        return nullptr;
     }
 
     RefPtr<EventSource> source = adoptRef(new EventSource(context, fullURL, eventSourceInit));
index b176316..c14d097 100644 (file)
@@ -876,8 +876,8 @@ bool FocusController::advanceFocusDirectionally(FocusDirection direction, Keyboa
     Element* focusedElement = focusedDocument->focusedElement();
     Node* container = focusedDocument;
 
-    if (container->isDocumentNode())
-        toDocument(container)->updateLayoutIgnorePendingStylesheets();
+    if (is<Document>(container))
+        downcast<Document>(*container).updateLayoutIgnorePendingStylesheets();
 
     // Figure out the starting rect.
     LayoutRect startingRect;
@@ -900,8 +900,8 @@ bool FocusController::advanceFocusDirectionally(FocusDirection direction, Keyboa
         consumed = advanceFocusDirectionallyInContainer(container, startingRect, direction, event);
         startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore border */);
         container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direction, container);
-        if (container && container->isDocumentNode())
-            toDocument(container)->updateLayoutIgnorePendingStylesheets();
+        if (container && is<Document>(container))
+            downcast<Document>(*container).updateLayoutIgnorePendingStylesheets();
     } while (!consumed && container);
 
     return consumed;
index 74cef4d..f289ea5 100644 (file)
@@ -117,7 +117,7 @@ void History::go(ScriptExecutionContext* context, int distance)
         return;
 
     ASSERT(isMainThread());
-    Document* activeDocument = toDocument(context);
+    Document* activeDocument = downcast<Document>(context);
     if (!activeDocument)
         return;
 
index e5fb05e..28d9d3d 100644 (file)
@@ -366,8 +366,8 @@ bool scrollInDirection(Frame* frame, FocusDirection direction)
 bool scrollInDirection(Node* container, FocusDirection direction)
 {
     ASSERT(container);
-    if (container->isDocumentNode())
-        return scrollInDirection(toDocument(container)->frame(), direction);
+    if (is<Document>(container))
+        return scrollInDirection(downcast<Document>(*container).frame(), direction);
 
     if (!container->renderBox())
         return false;
@@ -435,11 +435,11 @@ Node* scrollableEnclosingBoxOrParentFrameForNodeInDirection(FocusDirection direc
     ASSERT(node);
     Node* parent = node;
     do {
-        if (parent->isDocumentNode())
-            parent = toDocument(parent)->document().frame()->ownerElement();
+        if (is<Document>(parent))
+            parent = downcast<Document>(*parent).document().frame()->ownerElement();
         else
             parent = parent->parentNode();
-    } while (parent && !canScrollInDirection(parent, direction) && !parent->isDocumentNode());
+    } while (parent && !canScrollInDirection(parent, direction) && !is<Document>(parent));
 
     return parent;
 }
@@ -451,8 +451,8 @@ bool canScrollInDirection(const Node* container, FocusDirection direction)
     if (is<HTMLSelectElement>(container))
         return false;
 
-    if (container->isDocumentNode())
-        return canScrollInDirection(toDocument(container)->frame(), direction);
+    if (is<Document>(container))
+        return canScrollInDirection(downcast<Document>(*container).frame(), direction);
 
     if (!isScrollableNode(container))
         return false;
@@ -520,8 +520,8 @@ LayoutRect nodeRectInAbsoluteCoordinates(Node* node, bool ignoreBorder)
 {
     ASSERT(node && node->renderer() && !node->document().view()->needsLayout());
 
-    if (node->isDocumentNode())
-        return frameRectInAbsoluteCoordinates(toDocument(node)->frame());
+    if (is<Document>(node))
+        return frameRectInAbsoluteCoordinates(downcast<Document>(*node).frame());
     LayoutRect rect = rectToAbsoluteCoordinates(node->document().frame(), node->boundingBox());
 
     // For authors that use border instead of outline in their CSS, we compensate by ignoring the border when calculating
index 996015e..6cacf03 100644 (file)
@@ -54,7 +54,7 @@ private:
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(SVGDocument)
     static bool isSVGDocument(const Document& document) { return document.isSVGDocument(); }
-    static bool isSVGDocument(const Node& node) { return node.isDocumentNode() && isSVGDocument(toDocument(node)); }
+    static bool isSVGDocument(const Node& node) { return is<Document>(node) && isSVGDocument(downcast<Document>(node)); }
 SPECIALIZE_TYPE_TRAITS_END()
 
 } // namespace WebCore
index 88acd1f..4415750 100644 (file)
@@ -319,13 +319,13 @@ Internals::Internals(Document* document)
 
 Document* Internals::contextDocument() const
 {
-    return toDocument(scriptExecutionContext());
+    return downcast<Document>(scriptExecutionContext());
 }
 
 Frame* Internals::frame() const
 {
     if (!contextDocument())
-        return 0;
+        return nullptr;
     return contextDocument()->frame();
 }
 
@@ -1916,8 +1916,8 @@ void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*
     Document* document;
     if (!node)
         document = contextDocument();
-    else if (node->isDocumentNode())
-        document = toDocument(node);
+    else if (is<Document>(node))
+        document = downcast<Document>(node);
     else if (is<HTMLIFrameElement>(node))
         document = downcast<HTMLIFrameElement>(*node).contentDocument();
     else {
index 3b1b91c..aea8e4a 100644 (file)
@@ -46,8 +46,8 @@ void injectInternalsObject(JSContextRef context)
     JSLockHolder lock(exec);
     JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
     ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
-    if (scriptContext->isDocument())
-        globalObject->putDirect(exec->vm(), Identifier(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(toDocument(scriptContext))));
+    if (is<Document>(scriptContext))
+        globalObject->putDirect(exec->vm(), Identifier(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(downcast<Document>(scriptContext))));
 }
 
 void resetInternalsObject(JSContextRef context)
@@ -56,7 +56,7 @@ void resetInternalsObject(JSContextRef context)
     JSLockHolder lock(exec);
     JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
     ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
-    Page* page = toDocument(scriptContext)->frame()->page();
+    Page* page = downcast<Document>(scriptContext)->frame()->page();
     Internals::resetToConsistentState(page);
     InternalSettings::from(page)->resetToConsistentState();
 }
index 930c614..f9d0e3a 100644 (file)
@@ -228,7 +228,7 @@ void SharedWorkerProxy::addToWorkerDocuments(ScriptExecutionContext* context)
     ASSERT(context);
     ASSERT(!isClosing());
     MutexLocker lock(m_workerDocumentsLock);
-    m_workerDocuments.add(toDocument(context));
+    m_workerDocuments.add(downcast<Document>(context));
 }
 
 void SharedWorkerProxy::documentDetached(Document* document)
index c3c18c0..2bcaa4b 100644 (file)
@@ -83,11 +83,11 @@ void WorkerMessagingProxy::startWorkerGlobalScope(const URL& scriptURL, const St
 {
     // FIXME: This need to be revisited when we support nested worker one day
     ASSERT(m_scriptExecutionContext);
-    Document* document = toDocument(m_scriptExecutionContext);
-    GroupSettings* settings = 0;
-    if (document->page())
-        settings = &document->page()->group().groupSettings();
-    RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, settings, sourceCode, *this, *this, startMode, document->contentSecurityPolicy()->deprecatedHeader(), document->contentSecurityPolicy()->deprecatedHeaderType(), document->topOrigin());
+    Document& document = downcast<Document>(*m_scriptExecutionContext);
+    GroupSettings* settings = nullptr;
+    if (document.page())
+        settings = &document.page()->group().groupSettings();
+    RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, settings, sourceCode, *this, *this, startMode, document.contentSecurityPolicy()->deprecatedHeader(), document.contentSecurityPolicy()->deprecatedHeaderType(), document.topOrigin());
     workerThreadCreated(thread);
     thread->start();
     InspectorInstrumentation::didStartWorkerGlobalScope(m_scriptExecutionContext.get(), this, scriptURL);
index c2375c4..4d534ee 100644 (file)
@@ -155,7 +155,7 @@ XMLHttpRequest::~XMLHttpRequest()
 Document* XMLHttpRequest::document() const
 {
     ASSERT(scriptExecutionContext());
-    return toDocument(scriptExecutionContext());
+    return downcast<Document>(scriptExecutionContext());
 }
 
 SecurityOrigin* XMLHttpRequest::securityOrigin() const
@@ -487,10 +487,10 @@ void XMLHttpRequest::open(const String& method, const URL& url, bool async, Exce
 
     // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
     bool shouldBypassMainWorldContentSecurityPolicy = false;
-    if (scriptExecutionContext()->isDocument()) {
-        Document* document = toDocument(scriptExecutionContext());
-        if (document->frame())
-            shouldBypassMainWorldContentSecurityPolicy = document->frame()->script().shouldBypassMainWorldContentSecurityPolicy();
+    if (is<Document>(scriptExecutionContext())) {
+        Document& document = downcast<Document>(*scriptExecutionContext());
+        if (document.frame())
+            shouldBypassMainWorldContentSecurityPolicy = document.frame()->script().shouldBypassMainWorldContentSecurityPolicy();
     }
     if (!shouldBypassMainWorldContentSecurityPolicy && !scriptExecutionContext()->contentSecurityPolicy()->allowConnectToSource(url)) {
         // FIXME: Should this be throwing an exception?
index e8abc78..65b5693 100644 (file)
@@ -1,3 +1,18 @@
+2014-09-29  Christophe Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for Document
+        https://bugs.webkit.org/show_bug.cgi?id=137221
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for Document instead of isDocumentNode() /
+        toDocument().
+
+        * WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm:
+        (-[WKDOMDocument createElement:]):
+        (-[WKDOMDocument createTextNode:]):
+        (-[WKDOMDocument body]):
+
 2014-09-29  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r174045.
index 5398b99..ddd7bd6 100644 (file)
 {
     // FIXME: Do something about the exception.
     WebCore::ExceptionCode ec = 0;
-    return WebKit::toWKDOMElement(toDocument(_impl.get())->createElement(tagName, ec).get());
+    return WebKit::toWKDOMElement(WebCore::downcast<WebCore::Document>(*_impl).createElement(tagName, ec).get());
 }
 
 - (WKDOMText *)createTextNode:(NSString *)data
 {
-    return WebKit::toWKDOMText(toDocument(_impl.get())->createTextNode(data).get());
+    return WebKit::toWKDOMText(WebCore::downcast<WebCore::Document>(*_impl).createTextNode(data).get());
 }
 
 - (WKDOMElement *)body
 {
-    return WebKit::toWKDOMElement(toDocument(_impl.get())->body());
+    return WebKit::toWKDOMElement(WebCore::downcast<WebCore::Document>(*_impl).body());
 }
 
 @end