Generalize is<>() / downcast<>() support to all types
https://bugs.webkit.org/show_bug.cgi?id=137243

Reviewed by Benjamin Poulain.

Generalize is<>() / downcast<>() support to all types, not just Nodes.
Source/WebCore:

To achieve this, the following changes were made:
- Move is<> / downcast<>() and NodeTypeCastTraits from Node.h to a new
  wtf/TypeCasts.h header. Also move them to WTF namespace instead of
  WebCore namespace as they can be used for classes in other namespaces
  (e.g. WebKit namespace).
- Rename NodeTypeCastsTraits to TypeCastTraits as it can be specialized
  for non-Nodes.
- Since C++ does not allow template specializations in different
  namespaces, I had to move all the SPECIALIZE_TYPE_TRAITS_*() uses to
  the global scope and use the WebCore:: namespace explicitly in those.
  This is a bit unfortunate but I couldn't find a better way.

This patch also takes care of supporting is<>() / downcast<>() for
the WorkerGlobalScope class, which does not derive from Node.

No new tests, no behavior change.

* Modules/indexeddb/IDBFactory.cpp:
* Modules/indexeddb/WorkerGlobalScopeIndexedDatabase.cpp:
(WebCore::WorkerGlobalScopeIndexedDatabase::from):
* Modules/websockets/ThreadableWebSocketChannel.cpp:
(WebCore::ThreadableWebSocketChannel::create):
* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::toJSDOMGlobalObject):
* bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::handleEvent):
* bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::execute):
* dom/Attr.h:
(isType):
(WebCore::isAttr): Deleted.
* dom/CDATASection.h:
(isType):
(WebCore::isCDATASection): Deleted.
* dom/CharacterData.h:
(isType):
(WebCore::isCharacterData): Deleted.
* dom/Comment.h:
(isType):
(WebCore::isComment): Deleted.
* dom/Document.h:
(isType):
(WebCore::isDocument): Deleted.
* dom/DocumentFragment.h:
(isType):
(WebCore::isDocumentFragment): Deleted.
* dom/DocumentType.h:
(isType):
(WebCore::isDocumentType): Deleted.
* dom/Element.h:
* dom/MessagePort.cpp:
(WebCore::MessagePort::dispatchMessages):
* dom/Node.h:
(WebCore::is): Deleted.
(WebCore::downcast): Deleted.
* dom/ProcessingInstruction.h:
(isType):
(WebCore::isProcessingInstruction): Deleted.
* dom/PseudoElement.h:
(isType):
(WebCore::isPseudoElement): Deleted.
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::createdMessagePort):
(WebCore::ScriptExecutionContext::destroyedMessagePort):
(WebCore::ScriptExecutionContext::vm):
* dom/ScriptExecutionContext.h:
* dom/ShadowRoot.h:
(isType):
(WebCore::isShadowRoot): Deleted.
* dom/StyledElement.h:
(isType):
(WebCore::isStyledElement): Deleted.
* dom/Text.h:
(isType):
(WebCore::isText): Deleted.
* dom/make_names.pl:
(printTypeHelpers):
(printTypeHelpersHeaderFile):
* html/HTMLDocument.h:
(isType):
(WebCore::isHTMLDocument): Deleted.
* html/HTMLElement.h:
(isType):
(WebCore::isHTMLElement): Deleted.
* html/HTMLFormControlElement.h:
(isType):
(WebCore::isHTMLFormControlElement): Deleted.
* html/HTMLFrameElementBase.h:
(isType):
(WebCore::isHTMLFrameElementBase): Deleted.
* html/HTMLFrameOwnerElement.h:
(isType):
(WebCore::isHTMLFrameOwnerElement): Deleted.
* html/HTMLMediaElement.h:
(isType):
(WebCore::isHTMLMediaElement): Deleted.
* html/HTMLPlugInElement.h:
(isType):
(WebCore::isHTMLPlugInElement): Deleted.
* html/HTMLPlugInImageElement.h:
(isType):
(WebCore::isHTMLPlugInImageElement): Deleted.
* html/HTMLTableCellElement.h:
(isType):
(WebCore::isHTMLTableCellElement): Deleted.
* html/HTMLTableSectionElement.h:
(isType):
(WebCore::isHTMLTableSectionElement): Deleted.
* html/HTMLTextFormControlElement.h:
(isType):
(WebCore::isHTMLTextFormControlElement): Deleted.
* html/ImageDocument.h:
(isType):
(WebCore::isImageDocument): Deleted.
* html/LabelableElement.h:
(isType):
(WebCore::isLabelableElement): Deleted.
* html/MediaDocument.h:
(isType):
(WebCore::isMediaDocument): Deleted.
* html/PluginDocument.h:
(isType):
(WebCore::isPluginDocument): Deleted.
* html/shadow/InsertionPoint.h:
(isType):
(WebCore::isInsertionPoint): Deleted.
* html/shadow/TextControlInnerElements.h:
(isType):
(WebCore::isTextControlInnerTextElement): Deleted.
* html/track/WebVTTElement.h:
(isType):
(WebCore::isWebVTTElement): Deleted.
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::instrumentingAgentsForNonDocumentContext):
* loader/ThreadableLoader.cpp:
(WebCore::ThreadableLoader::create):
(WebCore::ThreadableLoader::loadResourceSynchronously):
* loader/cache/MemoryCache.cpp:
(WebCore::MemoryCache::removeRequestFromCache):
(WebCore::MemoryCache::removeRequestFromSessionCaches):
* mathml/MathMLElement.h:
(isType):
(WebCore::isMathMLElement): Deleted.
* svg/SVGAnimateElementBase.h:
(isType):
(WebCore::isSVGAnimateElementBase): Deleted.
* svg/SVGDocument.h:
(isType):
(WebCore::isSVGDocument): Deleted.
* svg/SVGElement.h:
(isType):
(WebCore::isSVGElement): Deleted.
* svg/SVGFilterPrimitiveStandardAttributes.h:
(isType):
(WebCore::isSVGFilterPrimitiveStandardAttributes): Deleted.
* svg/SVGGradientElement.h:
(isType):
(WebCore::isSVGGradientElement): Deleted.
* svg/SVGGraphicsElement.h:
(isType):
(WebCore::isSVGGraphicsElement): Deleted.
* svg/SVGPolyElement.h:
(isType):
(WebCore::isSVGPolyElement): Deleted.
* svg/SVGTextContentElement.h:
(isType):
(WebCore::isSVGTextContentElement): Deleted.
* svg/animation/SVGSMILElement.h:
(isType):
(WebCore::isSVGSMILElement): Deleted.
* workers/DefaultSharedWorkerRepository.cpp:
(WebCore::SharedWorkerConnectTask::SharedWorkerConnectTask):
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::close):
* workers/WorkerGlobalScope.h:
(isType):
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::WorkerMessagingProxy):
(WebCore::WorkerMessagingProxy::~WorkerMessagingProxy):
(WebCore::WorkerMessagingProxy::notifyNetworkStateChange):
(WebCore::WorkerMessagingProxy::connectToInspector):
(WebCore::WorkerMessagingProxy::disconnectFromInspector):
(WebCore::WorkerMessagingProxy::sendMessageToInspector):
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::loadSynchronously):
* workers/WorkerThread.cpp:
(WebCore::WorkerThread::stop):

Source/WebKit/win:

* DOMCoreClasses.cpp:
(DOMElement::createInstance):

Source/WebKit2:

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

Source/WTF:

* wtf/Assertions.h:
* wtf/TypeCasts.h: Added.
(WTF::is):
(WTF::downcast):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@174125 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/dom/DocumentFragment.h b/Source/WebCore/dom/DocumentFragment.h
index ac7d6f6..67ebfc3 100644
--- a/Source/WebCore/dom/DocumentFragment.h
+++ b/Source/WebCore/dom/DocumentFragment.h
@@ -52,10 +52,10 @@
     virtual bool childTypeAllowed(NodeType) const override;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(DocumentFragment)
-    static bool isDocumentFragment(const Node& node) { return node.isDocumentFragment(); }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-} //namespace
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::DocumentFragment)
+    static bool isType(const WebCore::Node& node) { return node.isDocumentFragment(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif