Generalize is<>() / downcast<>() support to all types
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Sep 2014 21:32:55 +0000 (21:32 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Sep 2014 21:32:55 +0000 (21:32 +0000)
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

71 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/Assertions.h
Source/WTF/wtf/TypeCasts.h [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBFactory.cpp
Source/WebCore/Modules/indexeddb/WorkerGlobalScopeIndexedDatabase.cpp
Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp
Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
Source/WebCore/bindings/js/JSEventListener.cpp
Source/WebCore/bindings/js/ScheduledAction.cpp
Source/WebCore/dom/Attr.h
Source/WebCore/dom/CDATASection.h
Source/WebCore/dom/CharacterData.h
Source/WebCore/dom/Comment.h
Source/WebCore/dom/Document.h
Source/WebCore/dom/DocumentFragment.h
Source/WebCore/dom/DocumentType.h
Source/WebCore/dom/Element.h
Source/WebCore/dom/MessagePort.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/ProcessingInstruction.h
Source/WebCore/dom/PseudoElement.h
Source/WebCore/dom/ScriptExecutionContext.cpp
Source/WebCore/dom/ScriptExecutionContext.h
Source/WebCore/dom/ShadowRoot.h
Source/WebCore/dom/StyledElement.h
Source/WebCore/dom/Text.h
Source/WebCore/dom/make_names.pl
Source/WebCore/html/HTMLDocument.h
Source/WebCore/html/HTMLElement.h
Source/WebCore/html/HTMLFormControlElement.h
Source/WebCore/html/HTMLFrameElementBase.h
Source/WebCore/html/HTMLFrameOwnerElement.h
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLPlugInElement.h
Source/WebCore/html/HTMLPlugInImageElement.h
Source/WebCore/html/HTMLTableCellElement.h
Source/WebCore/html/HTMLTableSectionElement.h
Source/WebCore/html/HTMLTextFormControlElement.h
Source/WebCore/html/ImageDocument.h
Source/WebCore/html/LabelableElement.h
Source/WebCore/html/MediaDocument.h
Source/WebCore/html/PluginDocument.h
Source/WebCore/html/shadow/InsertionPoint.h
Source/WebCore/html/shadow/TextControlInnerElements.h
Source/WebCore/html/track/WebVTTElement.h
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/loader/ThreadableLoader.cpp
Source/WebCore/loader/cache/MemoryCache.cpp
Source/WebCore/mathml/MathMLElement.h
Source/WebCore/svg/SVGAnimateElementBase.h
Source/WebCore/svg/SVGDocument.h
Source/WebCore/svg/SVGElement.h
Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.h
Source/WebCore/svg/SVGGradientElement.h
Source/WebCore/svg/SVGGraphicsElement.h
Source/WebCore/svg/SVGPolyElement.h
Source/WebCore/svg/SVGTextContentElement.h
Source/WebCore/svg/animation/SVGSMILElement.h
Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
Source/WebCore/workers/WorkerGlobalScope.cpp
Source/WebCore/workers/WorkerGlobalScope.h
Source/WebCore/workers/WorkerMessagingProxy.cpp
Source/WebCore/workers/WorkerScriptLoader.cpp
Source/WebCore/workers/WorkerThread.cpp
Source/WebKit/win/ChangeLog
Source/WebKit/win/DOMCoreClasses.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMElement.mm
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMText.mm

index 6fc98f1..4a311c9 100644 (file)
@@ -1,3 +1,17 @@
+2014-09-30  Christophe Dumez  <cdumez@apple.com>
+
+        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.
+
+        * wtf/Assertions.h:
+        * wtf/TypeCasts.h: Added.
+        (WTF::is):
+        (WTF::downcast):
+
 2014-09-30  Anders Carlsson  <andersca@apple.com>
 
         Get the STRING_STATS codepath compiling again, and add calls to ref/deref
index a40bc8b..72be3d6 100644 (file)
@@ -384,6 +384,8 @@ static inline void UNREACHABLE_FOR_PLATFORM()
 
 /* TYPE CAST */
 
+// FIXME: This macro should be removed once the code base is ported to using
+// the new SPECIALIZE_TYPE_TRAITS_*() macro.
 #define TYPE_CASTS_BASE(ToClassName, argumentType, argumentName, pointerPredicate, referencePredicate) \
 inline ToClassName* to##ToClassName(argumentType* argumentName) \
 { \
diff --git a/Source/WTF/wtf/TypeCasts.h b/Source/WTF/wtf/TypeCasts.h
new file mode 100644 (file)
index 0000000..e050d17
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TypeCasts_h
+#define TypeCasts_h
+
+namespace WTF {
+
+template <typename ExpectedType, typename ArgType>
+struct TypeCastTraits {
+    static bool isOfType(ArgType&);
+};
+
+template <typename ExpectedType>
+struct TypeCastTraits<ExpectedType, ExpectedType> {
+    static bool isOfType(ExpectedType&) { return true; }
+};
+
+// Type checking function, to use before casting with downcast<>().
+template <typename ExpectedType, typename ArgType>
+inline bool is(ArgType& source)
+{
+    static_assert(!std::is_base_of<ExpectedType, ArgType>::value, "Unnecessary type check");
+    return TypeCastTraits<const ExpectedType, const ArgType>::isOfType(source);
+}
+
+template <typename ExpectedType, typename ArgType>
+inline bool is(ArgType* source)
+{
+    ASSERT(source);
+    static_assert(!std::is_base_of<ExpectedType, ArgType>::value, "Unnecessary type check");
+    return TypeCastTraits<const ExpectedType, const ArgType>::isOfType(*source);
+}
+
+// Safe downcasting functions.
+template<typename Target, typename Source>
+inline typename std::conditional<std::is_const<Source>::value, const Target&, Target&>::type downcast(Source& source)
+{
+    static_assert(!std::is_base_of<Target, Source>::value, "Unnecessary cast");
+    ASSERT_WITH_SECURITY_IMPLICATION(is<Target>(source));
+    return static_cast<typename std::conditional<std::is_const<Source>::value, const Target&, Target&>::type>(source);
+}
+template<typename Target, typename Source> inline typename std::conditional<std::is_const<Source>::value, const Target*, Target*>::type downcast(Source* source)
+{
+    static_assert(!std::is_base_of<Target, Source>::value, "Unnecessary cast");
+    ASSERT_WITH_SECURITY_IMPLICATION(!source || is<Target>(*source));
+    return static_cast<typename std::conditional<std::is_const<Source>::value, const Target*, Target*>::type>(source);
+}
+
+// Add support for type checking / casting using is<>() / downcast<>() helpers for a specific class.
+#define SPECIALIZE_TYPE_TRAITS_BEGIN(ClassName) \
+namespace WTF { \
+template <typename ArgType> \
+class TypeCastTraits<const ClassName, ArgType> { \
+public: \
+    static bool isOfType(ArgType& source) { return isType(source); } \
+private:
+
+#define SPECIALIZE_TYPE_TRAITS_END() \
+}; \
+}
+
+} // namespace WTF
+
+using WTF::is;
+using WTF::downcast;
+
+#endif // TypeCasts_h
index 4565363..ca51fe5 100644 (file)
@@ -1,3 +1,199 @@
+2014-09-30  Christophe Dumez  <cdumez@apple.com>
+
+        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.
+        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):
+
 2014-09-30  Chris Dumez  <cdumez@apple.com>
 
         Use is<>() / downcast<>() for Element
index ce01007..0128f50 100644 (file)
@@ -83,7 +83,7 @@ static String getIndexedDBDatabasePath(ScriptExecutionContext* context)
         Document& document = downcast<Document>(*context);
         return document.page()->group().groupSettings().indexedDBDatabasePath();
     }
-    const GroupSettings* groupSettings = toWorkerGlobalScope(context)->groupSettings();
+    const GroupSettings* groupSettings = downcast<WorkerGlobalScope>(*context).groupSettings();
     if (groupSettings)
         return groupSettings->indexedDBDatabasePath();
     return String();
index 91b043b..a3c1267 100644 (file)
@@ -57,7 +57,7 @@ WorkerGlobalScopeIndexedDatabase* WorkerGlobalScopeIndexedDatabase::from(ScriptE
     WorkerGlobalScopeIndexedDatabase* supplement = static_cast<WorkerGlobalScopeIndexedDatabase*>(Supplement<ScriptExecutionContext>::from(context, supplementName()));
     if (!supplement) {
         String databaseDirectoryIdentifier;
-        const GroupSettings* groupSettings = toWorkerGlobalScope(context)->groupSettings();
+        const GroupSettings* groupSettings = downcast<WorkerGlobalScope>(*context).groupSettings();
         if (groupSettings)
             databaseDirectoryIdentifier = groupSettings->indexedDBDatabasePath();
 
index 1654dd5..839fa87 100644 (file)
@@ -55,13 +55,13 @@ PassRefPtr<ThreadableWebSocketChannel> ThreadableWebSocketChannel::create(Script
     ASSERT(context);
     ASSERT(client);
 
-    if (context->isWorkerGlobalScope()) {
-        WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
-        WorkerRunLoop& runLoop = workerGlobalScope->thread().runLoop();
+    if (is<WorkerGlobalScope>(context)) {
+        WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(*context);
+        WorkerRunLoop& runLoop = workerGlobalScope.thread().runLoop();
         StringBuilder mode;
         mode.appendLiteral(webSocketChannelMode);
         mode.appendNumber(runLoop.createUniqueId());
-        return WorkerThreadableWebSocketChannel::create(workerGlobalScope, client, mode.toString());
+        return WorkerThreadableWebSocketChannel::create(&workerGlobalScope, client, mode.toString());
     }
 
     return WebSocketChannel::create(downcast<Document>(context), client);
index 99c402c..d4edd69 100644 (file)
@@ -108,8 +108,8 @@ JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionCo
     if (is<Document>(scriptExecutionContext))
         return toJSDOMGlobalObject(downcast<Document>(scriptExecutionContext), exec);
 
-    if (scriptExecutionContext->isWorkerGlobalScope())
-        return toWorkerGlobalScope(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
+    if (is<WorkerGlobalScope>(scriptExecutionContext))
+        return downcast<WorkerGlobalScope>(*scriptExecutionContext).script()->workerGlobalScopeWrapper();
 
     ASSERT_NOT_REACHED();
     return nullptr;
@@ -125,8 +125,8 @@ JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionCo
     if (is<Document>(scriptExecutionContext))
         return toJSDOMGlobalObject(downcast<Document>(scriptExecutionContext), world);
 
-    if (scriptExecutionContext->isWorkerGlobalScope())
-        return toWorkerGlobalScope(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
+    if (is<WorkerGlobalScope>(scriptExecutionContext))
+        return downcast<WorkerGlobalScope>(*scriptExecutionContext).script()->workerGlobalScopeWrapper();
 
     ASSERT_NOT_REACHED();
     return nullptr;
index 2d2a754..5c76b6d 100644 (file)
@@ -131,10 +131,10 @@ void JSEventListener::handleEvent(ScriptExecutionContext* scriptExecutionContext
 
         globalObject->setCurrentEvent(savedEvent);
 
-        if (scriptExecutionContext->isWorkerGlobalScope()) {
+        if (is<WorkerGlobalScope>(scriptExecutionContext)) {
             bool terminatorCausedException = (exec->hadException() && isTerminatedExecutionException(exec->exception()));
             if (terminatorCausedException || (vm.watchdog && vm.watchdog->didFire()))
-                toWorkerGlobalScope(scriptExecutionContext)->script()->forbidExecution();
+                downcast<WorkerGlobalScope>(*scriptExecutionContext).script()->forbidExecution();
         }
 
         if (exception) {
index d11e454..a1b51aa 100644 (file)
@@ -77,7 +77,7 @@ void ScheduledAction::execute(ScriptExecutionContext* context)
     if (is<Document>(context))
         execute(downcast<Document>(context));
     else
-        execute(toWorkerGlobalScope(context));
+        execute(downcast<WorkerGlobalScope>(context));
 }
 
 void ScheduledAction::executeFunctionInContext(JSGlobalObject* globalObject, JSValue thisValue, ScriptExecutionContext* context)
index 1f6bce4..a7a8945 100644 (file)
@@ -99,10 +99,10 @@ private:
     unsigned m_ignoreChildrenChanged;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(Attr)
-    static bool isAttr(const Node& node) { return node.isAttributeNode(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Attr)
+    static bool isType(const WebCore::Node& node) { return node.isAttributeNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // Attr_h
index 6cd4f68..7e9823e 100644 (file)
@@ -41,10 +41,10 @@ private:
     virtual PassRefPtr<Text> virtualCreate(const String&) override;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(CDATASection)
-    static bool isCDATASection(const Node& node) { return node.nodeType() == Node::CDATA_SECTION_NODE; }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CDATASection)
+    static bool isType(const WebCore::Node& node) { return node.nodeType() == WebCore::Node::CDATA_SECTION_NODE; }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // CDATASection_h
index 016edd5..317d931 100644 (file)
@@ -76,10 +76,10 @@ private:
     String m_data;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(CharacterData)
-    static bool isCharacterData(const Node& node) { return node.isCharacterDataNode(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CharacterData)
+    static bool isType(const WebCore::Node& node) { return node.isCharacterDataNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // CharacterData_h
index 0a7dece..c1a49d5 100644 (file)
@@ -41,10 +41,10 @@ private:
     virtual bool childTypeAllowed(NodeType) const override;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(Comment)
-    static bool isComment(const Node& node) { return node.nodeType() == Node::COMMENT_NODE; }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Comment)
+    static bool isType(const WebCore::Node& node) { return node.nodeType() == WebCore::Node::COMMENT_NODE; }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // Comment_h
index c42d442..92ddfc2 100644 (file)
@@ -1740,13 +1740,13 @@ inline ScriptExecutionContext* Node::scriptExecutionContext() const
 
 Element* eventTargetElementForDocument(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
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Document)
+    static bool isType(const WebCore::ScriptExecutionContext& context) { return context.isDocument(); }
+    static bool isType(const WebCore::Node& node) { return node.isDocumentNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 namespace WTF {
 inline WebCore::Document* getPtr(WebCore::Document& p) { return &p; }
 }
index ac7d6f6..67ebfc3 100644 (file)
@@ -52,10 +52,10 @@ private:
     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
index f4ef79c..a9b7a6a 100644 (file)
@@ -60,10 +60,10 @@ private:
     String m_subset;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(DocumentType)
-    static bool isDocumentType(const Node& node) { return node.nodeType() == Node::DOCUMENT_TYPE_NODE; }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::DocumentType)
+    static bool isType(const WebCore::Node& node) { return node.nodeType() == WebCore::Node::DOCUMENT_TYPE_NODE; }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index 187e9d3..00f2bcb 100644 (file)
@@ -666,10 +666,6 @@ private:
     RefPtr<ElementData> m_elementData;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(Element)
-    static bool isElement(const Node& node) { return node.isElementNode(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 inline bool Node::hasAttributes() const
 {
     return is<Element>(*this) && downcast<Element>(*this).hasAttributes();
@@ -781,4 +777,8 @@ inline UniqueElementData& Element::ensureUniqueElementData()
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Element)
+    static bool isType(const WebCore::Node& node) { return node.isElementNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index f24d6c8..58beb7f 100644 (file)
@@ -157,7 +157,7 @@ void MessagePort::dispatchMessages()
     while (m_entangledChannel && m_entangledChannel->tryGetMessageFromRemote(message, channels)) {
 
         // close() in Worker onmessage handler should prevent next message from dispatching.
-        if (m_scriptExecutionContext->isWorkerGlobalScope() && toWorkerGlobalScope(m_scriptExecutionContext)->isClosing())
+        if (is<WorkerGlobalScope>(m_scriptExecutionContext) && downcast<WorkerGlobalScope>(*m_scriptExecutionContext).isClosing())
             return;
 
         std::unique_ptr<MessagePortArray> ports = MessagePort::entanglePorts(*m_scriptExecutionContext, WTF::move(channels));
index 7c8a9a6..4cd3157 100644 (file)
@@ -36,6 +36,7 @@
 #include "TreeShared.h"
 #include <wtf/Forward.h>
 #include <wtf/ListHashSet.h>
+#include <wtf/TypeCasts.h>
 
 namespace JSC {
 class VM;
@@ -739,58 +740,6 @@ inline ContainerNode* Node::parentNodeGuaranteedHostFree() const
     return parentNode();
 }
 
-template <typename ExpectedType, typename ArgType>
-struct NodeTypeCastTraits {
-    static bool isType(ArgType&);
-};
-
-template <typename ExpectedType>
-struct NodeTypeCastTraits<ExpectedType, ExpectedType> {
-    static bool isType(ExpectedType&) { return true; }
-};
-
-// Type checking function for Nodes, to use before casting with downcast<>().
-template <typename ExpectedType, typename ArgType>
-inline bool is(ArgType& node)
-{
-    static_assert(!std::is_base_of<ExpectedType, ArgType>::value, "Unnecessary type check");
-    return NodeTypeCastTraits<const ExpectedType, const ArgType>::isType(node);
-}
-
-template <typename ExpectedType, typename ArgType>
-inline bool is(ArgType* node)
-{
-    ASSERT(node);
-    static_assert(!std::is_base_of<ExpectedType, ArgType>::value, "Unnecessary type check");
-    return NodeTypeCastTraits<const ExpectedType, const ArgType>::isType(*node);
-}
-
-// Downcasting functions for Node types.
-template<typename Target, typename Source>
-inline typename std::conditional<std::is_const<Source>::value, const Target&, Target&>::type downcast(Source& source)
-{
-    static_assert(!std::is_base_of<Target, Source>::value, "Unnecessary cast");
-    ASSERT_WITH_SECURITY_IMPLICATION(is<Target>(source));
-    return static_cast<typename std::conditional<std::is_const<Source>::value, const Target&, Target&>::type>(source);
-}
-template<typename Target, typename Source> inline typename std::conditional<std::is_const<Source>::value, const Target*, Target*>::type downcast(Source* source)
-{
-    static_assert(!std::is_base_of<Target, Source>::value, "Unnecessary cast");
-    ASSERT_WITH_SECURITY_IMPLICATION(!source || is<Target>(*source));
-    return static_cast<typename std::conditional<std::is_const<Source>::value, const Target*, Target*>::type>(source);
-}
-
-// Add support for type checking / casting using is<>() / downcast<>() helpers for a specific class.
-#define SPECIALIZE_TYPE_TRAITS_BEGIN(ClassName) \
-    template <typename ArgType> \
-    class NodeTypeCastTraits<const ClassName, ArgType> { \
-    public: \
-        static bool isType(ArgType& node) { return is##ClassName(node); } \
-    private:
-
-#define SPECIALIZE_TYPE_TRAITS_END() \
-    };
-
 // FIXME: This should be removed and all uses should be replaced with SPECIALIZE_TYPE_TRAITS_*().
 #define NODE_TYPE_CASTS(ToClassName) \
     TYPE_CASTS_BASE(ToClassName, Node, node, WebCore::is##ToClassName(*node), WebCore::is##ToClassName(node))
index b325c38..3d723aa 100644 (file)
@@ -91,10 +91,10 @@ private:
 #endif
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(ProcessingInstruction)
-    static bool isProcessingInstruction(const Node& node) { return node.nodeType() == Node::PROCESSING_INSTRUCTION_NODE; }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-} //namespace
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ProcessingInstruction)
+    static bool isType(const WebCore::Node& node) { return node.nodeType() == WebCore::Node::PROCESSING_INSTRUCTION_NODE; }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
index 0a90a45..4be5c96 100644 (file)
@@ -77,10 +77,10 @@ inline bool pseudoElementRendererIsNeeded(const RenderStyle* style)
     return style && style->display() != NONE && (style->contentData() || style->hasFlowFrom());
 }
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(PseudoElement)
-    static bool isPseudoElement(const Node& node) { return node.isPseudoElement(); }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-} // namespace
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::PseudoElement)
+    static bool isType(const WebCore::Node& node) { return node.isPseudoElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
index 50a84c7..dcef575 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "CachedScript.h"
 #include "DOMTimer.h"
+#include "Document.h"
 #include "ErrorEvent.h"
 #include "MessagePort.h"
 #include "PublicURLManager.h"
@@ -158,16 +159,16 @@ void ScriptExecutionContext::dispatchMessagePortEvents()
 
 void ScriptExecutionContext::createdMessagePort(MessagePort& messagePort)
 {
-    ASSERT((isDocument() && isMainThread())
-        || (isWorkerGlobalScope() && currentThread() == toWorkerGlobalScope(this)->thread().threadID()));
+    ASSERT((is<Document>(*this) && isMainThread())
+        || (is<WorkerGlobalScope>(*this) && currentThread() == downcast<WorkerGlobalScope>(*this).thread().threadID()));
 
     m_messagePorts.add(&messagePort);
 }
 
 void ScriptExecutionContext::destroyedMessagePort(MessagePort& messagePort)
 {
-    ASSERT((isDocument() && isMainThread())
-        || (isWorkerGlobalScope() && currentThread() == toWorkerGlobalScope(this)->thread().threadID()));
+    ASSERT((is<Document>(*this) && isMainThread())
+        || (is<WorkerGlobalScope>(*this) && currentThread() == downcast<WorkerGlobalScope>(*this).thread().threadID()));
 
     m_messagePorts.remove(&messagePort);
 }
@@ -445,10 +446,10 @@ double ScriptExecutionContext::timerAlignmentInterval() const
 
 JSC::VM& ScriptExecutionContext::vm()
 {
-     if (isDocument())
+    if (is<Document>(*this))
         return JSDOMWindow::commonVM();
 
-    return toWorkerGlobalScope(*this).script()->vm();
+    return downcast<WorkerGlobalScope>(*this).script()->vm();
 }
 
 #if ENABLE(SQL_DATABASE)
index dadd9aa..fce1804 100644 (file)
@@ -234,10 +234,6 @@ private:
 #endif
 };
 
-#define SCRIPT_EXECUTION_CONTEXT_TYPE_CASTS(ToValueTypeName) \
-    template<typename T> inline ToValueTypeName* to##ToValueTypeName(const RefPtr<T>& context) { return to##ToValueTypeName(context.get()); } \
-    TYPE_CASTS_BASE(ToValueTypeName, ScriptExecutionContext, context, context->is##ToValueTypeName(), context.is##ToValueTypeName())
-
 } // namespace WebCore
 
 #endif // ScriptExecutionContext_h
index bfe5b6f..1be757f 100644 (file)
@@ -95,10 +95,6 @@ inline Element* ShadowRoot::activeElement() const
     return treeScope().focusedElement();
 }
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(ShadowRoot)
-    static bool isShadowRoot(const Node& node) { return node.isShadowRoot(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 inline ShadowRoot* Node::shadowRoot() const
 {
     if (!is<Element>(*this))
@@ -119,6 +115,10 @@ inline bool hasShadowRootParent(const Node& node)
     return node.parentNode() && node.parentNode()->isShadowRoot();
 }
 
-} // namespace
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ShadowRoot)
+    static bool isType(const WebCore::Node& node) { return node.isShadowRoot(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
index 409bc03..3f70f3d 100644 (file)
@@ -106,10 +106,10 @@ inline const StyleProperties* StyledElement::presentationAttributeStyle()
     return elementData()->presentationAttributeStyle();
 }
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(StyledElement)
-    static bool isStyledElement(const Node& node) { return node.isStyledElement(); }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-} //namespace
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::StyledElement)
+    static bool isType(const WebCore::Node& node) { return node.isStyledElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
index 8b848ab..60deef9 100644 (file)
@@ -74,10 +74,10 @@ private:
 #endif
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(Text)
-    static bool isText(const Node& node) { return node.isTextNode(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Text)
+    static bool isType(const WebCore::Node& node) { return node.isTextNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // Text_h
index 92a9796..522e7df 100755 (executable)
@@ -639,29 +639,33 @@ sub printTypeHelpers
         next if $tagCount > 1;
         my $name = $classToTags{$class}[0];
         print F <<END
+namespace WebCore {
 class $class;
+}
+namespace WTF {
 template <typename ArgType>
-class NodeTypeCastTraits<const $class, ArgType> {
+class TypeCastTraits<const WebCore::$class, ArgType> {
 public:
-    static bool isType(ArgType& node) { return checkTagName(node); }
+    static bool isOfType(ArgType& node) { return checkTagName(node); }
 private:
 END
        ;
        if ($parameters{namespace} eq "HTML" && $parsedTags{$name}{wrapperOnlyIfMediaIsAvailable}) {
            print F <<END
-    static bool checkTagName(const HTMLElement& element) { return !element.isHTMLUnknownElement() && element.hasTagName($parameters{namespace}Names::${name}Tag); }
-    static bool checkTagName(const Node& node) { return is<HTMLElement>(node) && checkTagName(downcast<HTMLElement>(node)); }
+    static bool checkTagName(const WebCore::HTMLElement& element) { return !element.isHTMLUnknownElement() && element.hasTagName(WebCore::$parameters{namespace}Names::${name}Tag); }
+    static bool checkTagName(const WebCore::Node& node) { return is<WebCore::HTMLElement>(node) && checkTagName(downcast<WebCore::HTMLElement>(node)); }
 END
            ;
        } else {
            print F <<END
-    static bool checkTagName(const $parameters{namespace}Element& element) { return element.hasTagName($parameters{namespace}Names::${name}Tag); }
-    static bool checkTagName(const Node& node) { return node.hasTagName($parameters{namespace}Names::${name}Tag); }
+    static bool checkTagName(const WebCore::$parameters{namespace}Element& element) { return element.hasTagName(WebCore::$parameters{namespace}Names::${name}Tag); }
+    static bool checkTagName(const WebCore::Node& node) { return node.hasTagName(WebCore::$parameters{namespace}Names::${name}Tag); }
 END
            ;
        }
        print F <<END
 };
+}
 END
        ;
        print F "\n";
@@ -678,11 +682,9 @@ sub printTypeHelpersHeaderFile
     print F "#ifndef ".$parameters{namespace}."ElementTypeHelpers_h\n";
     print F "#define ".$parameters{namespace}."ElementTypeHelpers_h\n\n";
     print F "#include \"".$parameters{namespace}."Names.h\"\n\n";
-    print F "namespace WebCore {\n\n";
 
     printTypeHelpers($F, \%allTags);
 
-    print F "}\n\n";
     print F "#endif\n";
 
     close F;
index 0a9b5a2..a65c379 100644 (file)
@@ -97,11 +97,11 @@ private:
     DocumentOrderedMap m_windowNamedItem;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLDocument)
-    static bool isHTMLDocument(const Document& document) { return document.isHTMLDocument(); }
-    static bool isHTMLDocument(const Node& node) { return is<Document>(node) && isHTMLDocument(downcast<Document>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLDocument)
+    static bool isType(const WebCore::Document& document) { return document.isHTMLDocument(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::Document>(node) && isType(downcast<WebCore::Document>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // HTMLDocument_h
index 68f231b..8123478 100644 (file)
@@ -146,10 +146,6 @@ inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document
     ASSERT(tagName.localName().impl());
 }
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLElement)
-    static bool isHTMLElement(const Node& node) { return node.isHTMLElement(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 inline bool Node::hasTagName(const HTMLQualifiedName& name) const
 {
     return is<HTMLElement>(*this) && downcast<HTMLElement>(*this).hasTagName(name);
@@ -157,6 +153,10 @@ inline bool Node::hasTagName(const HTMLQualifiedName& name) const
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLElement)
+    static bool isType(const WebCore::Node& node) { return node.isHTMLElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #include "HTMLElementTypeHelpers.h"
 
 #endif // HTMLElement_h
index c224e6e..e7ae3ec 100644 (file)
@@ -190,12 +190,12 @@ private:
     bool m_hasAutofocused : 1;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLFormControlElement)
-    static bool isHTMLFormControlElement(const Element& element) { return element.isFormControlElement(); }
-    static bool isHTMLFormControlElement(const Node& node) { return is<Element>(node) && downcast<Element>(node).isFormControlElement(); }
-    static bool isHTMLFormControlElement(const FormAssociatedElement& element) { return element.isFormControlElement(); }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-} // namespace
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLFormControlElement)
+    static bool isType(const WebCore::Element& element) { return element.isFormControlElement(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::Element>(node) && isType(downcast<WebCore::Element>(node)); }
+    static bool isType(const WebCore::FormAssociatedElement& element) { return element.isFormControlElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
index f38153f..3ca7ab1 100644 (file)
@@ -76,11 +76,11 @@ private:
     int m_marginHeight;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLFrameElementBase)
-    static bool isHTMLFrameElementBase(const HTMLElement& element) { return is<HTMLFrameElement>(element) || is<HTMLIFrameElement>(element); }
-    static bool isHTMLFrameElementBase(const Node& node) { return is<HTMLElement>(node) && isHTMLFrameElementBase(downcast<HTMLElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLFrameElementBase)
+    static bool isType(const WebCore::HTMLElement& element) { return is<WebCore::HTMLFrameElement>(element) || is<WebCore::HTMLIFrameElement>(element); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::HTMLElement>(node) && isType(downcast<WebCore::HTMLElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // HTMLFrameElementBase_h
index 06a4537..9c3b27e 100644 (file)
@@ -69,11 +69,6 @@ private:
     SandboxFlags m_sandboxFlags;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLFrameOwnerElement)
-    static bool isHTMLFrameOwnerElement(const Node& node) { return node.isFrameOwnerElement(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
-
 class SubframeLoadingDisabler {
 public:
     explicit SubframeLoadingDisabler(ContainerNode& root)
@@ -101,4 +96,8 @@ private:
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLFrameOwnerElement)
+    static bool isType(const WebCore::Node& node) { return node.isFrameOwnerElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // HTMLFrameOwnerElement_h
index 27fcdd2..d9a68d3 100644 (file)
@@ -909,11 +909,6 @@ struct ValueToString<TextTrackCue*> {
 #endif
 #endif
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLMediaElement)
-    static bool isHTMLMediaElement(const Element& element) { return element.isMediaElement(); }
-    static bool isHTMLMediaElement(const Node& node) { return is<Element>(node) && isHTMLMediaElement(downcast<Element>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 #ifndef NDEBUG
 template<>
 struct ValueToString<MediaTime> {
@@ -924,7 +919,12 @@ struct ValueToString<MediaTime> {
 };
 #endif
 
-} //namespace
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLMediaElement)
+    static bool isType(const WebCore::Element& element) { return element.isMediaElement(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::Element>(node) && isType(downcast<WebCore::Element>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
 #endif
index 0f57f46..f8bc7f9 100644 (file)
@@ -136,10 +136,10 @@ private:
     DisplayState m_displayState;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLPlugInElement)
-    static bool isHTMLPlugInElement(const Node& node) { return node.isPluginElement(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLPlugInElement)
+    static bool isType(const WebCore::Node& node) { return node.isPluginElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // HTMLPlugInElement_h
index 0786f21..86dcc86 100644 (file)
@@ -157,11 +157,11 @@ private:
     bool m_plugInDimensionsSpecified;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLPlugInImageElement)
-    static bool isHTMLPlugInImageElement(const HTMLPlugInElement& element) { return element.isPlugInImageElement(); }
-    static bool isHTMLPlugInImageElement(const Node& node) { return is<HTMLPlugInElement>(node) && isHTMLPlugInImageElement(downcast<HTMLPlugInElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLPlugInImageElement)
+    static bool isType(const WebCore::HTMLPlugInElement& element) { return element.isPlugInImageElement(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::HTMLPlugInElement>(node) && isType(downcast<WebCore::HTMLPlugInElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // HTMLPlugInImageElement_h
index 036beb6..3cdb9ab 100644 (file)
@@ -62,11 +62,11 @@ private:
     virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const override;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLTableCellElement)
-    static bool isHTMLTableCellElement(const HTMLElement& element) { return element.hasTagName(HTMLNames::tdTag) || element.hasTagName(HTMLNames::thTag); }
-    static bool isHTMLTableCellElement(const Node& node) { return is<HTMLElement>(node) && isHTMLTableCellElement(downcast<HTMLElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-} // namespace
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLTableCellElement)
+    static bool isType(const WebCore::HTMLElement& element) { return element.hasTagName(WebCore::HTMLNames::tdTag) || element.hasTagName(WebCore::HTMLNames::thTag); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::HTMLElement>(node) && isType(downcast<WebCore::HTMLElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
index 6845707..505ccde 100644 (file)
@@ -61,11 +61,11 @@ private:
     virtual const StyleProperties* additionalPresentationAttributeStyle() override;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLTableSectionElement)
-    static bool isHTMLTableSectionElement(const HTMLElement& element) { return element.hasTagName(HTMLNames::theadTag) || element.hasTagName(HTMLNames::tfootTag) || element.hasTagName(HTMLNames::tbodyTag); }
-    static bool isHTMLTableSectionElement(const Node& node) { return is<HTMLElement>(node) && isHTMLTableSectionElement(downcast<HTMLElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-} //namespace
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLTableSectionElement)
+    static bool isType(const WebCore::HTMLElement& element) { return element.hasTagName(WebCore::HTMLNames::theadTag) || element.hasTagName(WebCore::HTMLNames::tfootTag) || element.hasTagName(WebCore::HTMLNames::tbodyTag); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::HTMLElement>(node) && isType(downcast<WebCore::HTMLElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
index 9dc7d92..af5fe73 100644 (file)
@@ -151,13 +151,13 @@ private:
     unsigned char m_isPlaceholderVisible : 1;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLTextFormControlElement)
-    static bool isHTMLTextFormControlElement(const Element& element) { return element.isTextFormControl(); }
-    static bool isHTMLTextFormControlElement(const Node& node) { return is<Element>(node) && isHTMLTextFormControlElement(downcast<Element>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
 
-} // namespace
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLTextFormControlElement)
+    static bool isType(const WebCore::Element& element) { return element.isTextFormControl(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::Element>(node) && isType(downcast<WebCore::Element>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
index 781d02c..e1e9de2 100644 (file)
@@ -82,11 +82,11 @@ private:
     bool m_shouldShrinkImage;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(ImageDocument)
-    static bool isImageDocument(const Document& document) { return document.isImageDocument(); }
-    static bool isImageDocument(const Node& node) { return is<Document>(node) && isImageDocument(downcast<Document>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-}
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ImageDocument)
+    static bool isType(const WebCore::Document& document) { return document.isImageDocument(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::Document>(node) && isType(downcast<WebCore::Document>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif // ImageDocument_h
index 274c2ab..c2a631a 100644 (file)
@@ -50,11 +50,11 @@ private:
     virtual bool isLabelable() const override final { return true; }
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(LabelableElement)
-    static bool isLabelableElement(const HTMLElement& element) { return element.isLabelable(); }
-    static bool isLabelableElement(const Node& node) { return is<HTMLElement>(node) && isLabelableElement(downcast<HTMLElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::LabelableElement)
+    static bool isType(const WebCore::HTMLElement& element) { return element.isLabelable(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::HTMLElement>(node) && isType(downcast<WebCore::HTMLElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index ab5ed08..03ed81b 100644 (file)
@@ -56,12 +56,12 @@ private:
     String m_outgoingReferrer;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(MediaDocument)
-    static bool isMediaDocument(const Document& document) { return document.isMediaDocument(); }
-    static bool isMediaDocument(const Node& node) { return is<Document>(node) && isMediaDocument(downcast<Document>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-}
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::MediaDocument)
+    static bool isType(const WebCore::Document& document) { return document.isMediaDocument(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::Document>(node) && isType(downcast<WebCore::Document>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
 #endif
index 18834d6..6fc6ebc 100644 (file)
@@ -61,11 +61,11 @@ private:
     RefPtr<HTMLPlugInElement> m_pluginElement;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(PluginDocument)
-    static bool isPluginDocument(const Document& document) { return document.isPluginDocument(); }
-    static bool isPluginDocument(const Node& node) { return is<Document>(node) && isPluginDocument(downcast<Document>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-}
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::PluginDocument)
+    static bool isType(const WebCore::Document& document) { return document.isPluginDocument(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::Document>(node) && isType(downcast<WebCore::Document>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif // PluginDocument_h
index 9f04264..0f41a02 100644 (file)
@@ -75,10 +75,6 @@ private:
     bool m_hasDistribution;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(InsertionPoint)
-    static bool isInsertionPoint(const Node& node) { return node.isInsertionPoint(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 inline bool isActiveInsertionPoint(const Node* node)
 {
     return node && is<InsertionPoint>(node) && downcast<InsertionPoint>(*node).isActive();
@@ -127,4 +123,8 @@ inline bool hasShadowRootOrActiveInsertionPointParent(const Node& node)
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::InsertionPoint)
+    static bool isType(const WebCore::Node& node) { return node.isInsertionPoint(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // InsertionPoint_h
index bb7b032..c3128b8 100644 (file)
@@ -70,11 +70,6 @@ private:
     virtual bool isTextControlInnerTextElement() const override { return true; }
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(TextControlInnerTextElement)
-    static bool isTextControlInnerTextElement(const HTMLElement& element) { return element.isTextControlInnerTextElement(); }
-    static bool isTextControlInnerTextElement(const Node& node) { return is<HTMLElement>(node) && isTextControlInnerTextElement(downcast<HTMLElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 class SearchFieldResultsButtonElement final : public HTMLDivElement {
 public:
     static PassRefPtr<SearchFieldResultsButtonElement> create(Document&);
@@ -107,6 +102,11 @@ private:
     bool m_capturing;
 };
 
-} // namespace
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::TextControlInnerTextElement)
+    static bool isType(const WebCore::HTMLElement& element) { return element.isTextControlInnerTextElement(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::HTMLElement>(node) && isType(downcast<WebCore::HTMLElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif
index 3b3d911..52ae487 100644 (file)
@@ -80,10 +80,10 @@ private:
     AtomicString m_language;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(WebVTTElement)
-    static bool isWebVTTElement(const Node& node) { return node.isWebVTTElement(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::WebVTTElement)
+    static bool isType(const WebCore::Node& node) { return node.isWebVTTElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index ef008d3..8e947ca 100644 (file)
@@ -1262,8 +1262,8 @@ InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForWorkerGloba
 
 InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForNonDocumentContext(ScriptExecutionContext* context)
 {
-    if (context->isWorkerGlobalScope())
-        return instrumentationForWorkerGlobalScope(toWorkerGlobalScope(context));
+    if (is<WorkerGlobalScope>(context))
+        return instrumentationForWorkerGlobalScope(downcast<WorkerGlobalScope>(context));
     return nullptr;
 }
 
index 2e8c2bf..e3dcdb4 100644 (file)
@@ -56,8 +56,8 @@ PassRefPtr<ThreadableLoader> ThreadableLoader::create(ScriptExecutionContext* co
     ASSERT(client);
     ASSERT(context);
 
-    if (context->isWorkerGlobalScope())
-        return WorkerThreadableLoader::create(toWorkerGlobalScope(context), client, WorkerRunLoop::defaultMode(), request, options);
+    if (is<WorkerGlobalScope>(context))
+        return WorkerThreadableLoader::create(downcast<WorkerGlobalScope>(context), client, WorkerRunLoop::defaultMode(), request, options);
 
     return DocumentThreadableLoader::create(downcast<Document>(*context), *client, request, options);
 }
@@ -66,8 +66,8 @@ void ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext* context
 {
     ASSERT(context);
 
-    if (context->isWorkerGlobalScope()) {
-        WorkerThreadableLoader::loadResourceSynchronously(toWorkerGlobalScope(context), request, client, options);
+    if (is<WorkerGlobalScope>(context)) {
+        WorkerThreadableLoader::loadResourceSynchronously(downcast<WorkerGlobalScope>(context), request, client, options);
         return;
     }
 
index 9ffb95b..2e87809 100644 (file)
@@ -752,8 +752,8 @@ void MemoryCache::removeUrlFromCache(ScriptExecutionContext* context, const Stri
 
 void MemoryCache::removeRequestFromCache(ScriptExecutionContext* context, const ResourceRequest& request, SessionID sessionID)
 {
-    if (context->isWorkerGlobalScope()) {
-        toWorkerGlobalScope(context)->thread().workerLoaderProxy().postTaskToLoader(CrossThreadTask(&crossThreadRemoveRequestFromCache, request, sessionID));
+    if (is<WorkerGlobalScope>(context)) {
+        downcast<WorkerGlobalScope>(*context).thread().workerLoaderProxy().postTaskToLoader(CrossThreadTask(&crossThreadRemoveRequestFromCache, request, sessionID));
         return;
     }
 
@@ -768,8 +768,8 @@ void MemoryCache::removeRequestFromCacheImpl(ScriptExecutionContext*, const Reso
 
 void MemoryCache::removeRequestFromSessionCaches(ScriptExecutionContext* context, const ResourceRequest& request)
 {
-    if (context->isWorkerGlobalScope()) {
-        toWorkerGlobalScope(context)->thread().workerLoaderProxy().postTaskToLoader(CrossThreadTask(&crossThreadRemoveRequestFromSessionCaches, request));
+    if (is<WorkerGlobalScope>(context)) {
+        downcast<WorkerGlobalScope>(*context).thread().workerLoaderProxy().postTaskToLoader(CrossThreadTask(&crossThreadRemoveRequestFromSessionCaches, request));
         return;
     }
     removeRequestFromSessionCachesImpl(context, request);
index e099067..b98fbeb 100644 (file)
@@ -73,10 +73,6 @@ private:
     virtual void updateSelectedChild() { }
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(MathMLElement)
-    static bool isMathMLElement(const Node& node) { return node.isMathMLElement(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 inline bool Node::hasTagName(const MathMLQualifiedName& name) const
 {
     return isMathMLElement() && downcast<MathMLElement>(*this).hasTagName(name);
@@ -84,6 +80,10 @@ inline bool Node::hasTagName(const MathMLQualifiedName& name) const
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::MathMLElement)
+    static bool isType(const WebCore::Node& node) { return node.isMathMLElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #include "MathMLElementTypeHelpers.h"
 
 #endif // ENABLE(MATHML)
index 7d94a3d..e7211b3 100644 (file)
@@ -72,15 +72,15 @@ private:
     std::unique_ptr<SVGAnimatedTypeAnimator> m_animator;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(SVGAnimateElementBase)
-    static bool isSVGAnimateElementBase(const SVGElement& element)
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGAnimateElementBase)
+    static bool isType(const WebCore::SVGElement& element)
     {
-        return element.hasTagName(SVGNames::animateTag) || element.hasTagName(SVGNames::animateColorTag)
-            || element.hasTagName(SVGNames::animateTransformTag) || element.hasTagName(SVGNames::setTag);
+        return element.hasTagName(WebCore::SVGNames::animateTag) || element.hasTagName(WebCore::SVGNames::animateColorTag)
+            || element.hasTagName(WebCore::SVGNames::animateTransformTag) || element.hasTagName(WebCore::SVGNames::setTag);
     }
-    static bool isSVGAnimateElementBase(const Node& node) { return is<SVGElement>(node) && isSVGAnimateElementBase(downcast<SVGElement>(node)); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::SVGElement>(node) && isType(downcast<WebCore::SVGElement>(node)); }
 SPECIALIZE_TYPE_TRAITS_END()
 
-} // namespace WebCore
-
 #endif // SVGAnimateElementBase_h
index 6cacf03..ef5be2e 100644 (file)
@@ -52,11 +52,11 @@ private:
     FloatPoint m_translate;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(SVGDocument)
-    static bool isSVGDocument(const Document& document) { return document.isSVGDocument(); }
-    static bool isSVGDocument(const Node& node) { return is<Document>(node) && isSVGDocument(downcast<Document>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGDocument)
+    static bool isType(const WebCore::Document& document) { return document.isSVGDocument(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::Document>(node) && isType(downcast<WebCore::Document>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // SVGDocument_h
index 9a2e96c..d833c06 100644 (file)
@@ -221,10 +221,6 @@ struct SVGAttributeHashTranslator {
     static bool equal(const QualifiedName& a, const QualifiedName& b) { return a.matches(b); }
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(SVGElement)
-    static bool isSVGElement(const Node& node) { return node.isSVGElement(); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 inline bool Node::hasTagName(const SVGQualifiedName& name) const
 {
     return isSVGElement() && downcast<SVGElement>(*this).hasTagName(name);
@@ -232,6 +228,10 @@ inline bool Node::hasTagName(const SVGQualifiedName& name) const
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGElement)
+    static bool isType(const WebCore::Node& node) { return node.isSVGElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #include "SVGElementTypeHelpers.h"
 
 #endif
index 0cb19ef..66ac3c2 100644 (file)
@@ -82,11 +82,11 @@ private:
 
 void invalidateFilterPrimitiveParent(SVGElement*);
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(SVGFilterPrimitiveStandardAttributes)
-    static bool isSVGFilterPrimitiveStandardAttributes(const SVGElement& element) { return element.isFilterEffect(); }
-    static bool isSVGFilterPrimitiveStandardAttributes(const Node& node) { return is<SVGElement>(node) && isSVGFilterPrimitiveStandardAttributes(downcast<SVGElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGFilterPrimitiveStandardAttributes)
+    static bool isType(const WebCore::SVGElement& element) { return element.isFilterEffect(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::SVGElement>(node) && isType(downcast<WebCore::SVGElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index 533808f..36589bb 100644 (file)
@@ -107,17 +107,17 @@ private:
     END_DECLARE_ANIMATED_PROPERTIES
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(SVGGradientElement)
-static bool isSVGGradientElement(const SVGElement& element)
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGGradientElement)
+static bool isType(const WebCore::SVGElement& element)
 {
-    return element.hasTagName(SVGNames::radialGradientTag) || element.hasTagName(SVGNames::linearGradientTag);
+    return element.hasTagName(WebCore::SVGNames::radialGradientTag) || element.hasTagName(WebCore::SVGNames::linearGradientTag);
 }
-static bool isSVGGradientElement(const Node& node)
+static bool isType(const WebCore::Node& node)
 {
-    return is<SVGElement>(node) && isSVGGradientElement(downcast<SVGElement>(node));
+    return is<WebCore::SVGElement>(node) && isType(downcast<WebCore::SVGElement>(node));
 }
 SPECIALIZE_TYPE_TRAITS_END()
 
-} // namespace WebCore
-
 #endif
index 433f31c..612666f 100644 (file)
@@ -82,11 +82,11 @@ private:
     bool m_shouldIsolateBlending;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(SVGGraphicsElement)
-    static bool isSVGGraphicsElement(const SVGElement& element) { return element.isSVGGraphicsElement(); }
-    static bool isSVGGraphicsElement(const Node& node) { return is<SVGElement>(node) && isSVGGraphicsElement(downcast<SVGElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGGraphicsElement)
+    static bool isType(const WebCore::SVGElement& element) { return element.isSVGGraphicsElement(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::SVGElement>(node) && isType(downcast<WebCore::SVGElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // SVGGraphicsElement_h
index 009ae66..fc46d7c 100644 (file)
@@ -62,11 +62,11 @@ protected:
     mutable SVGSynchronizableAnimatedProperty<SVGPointList> m_points;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(SVGPolyElement)
-    static bool isSVGPolyElement(const SVGElement& element) { return element.hasTagName(SVGNames::polygonTag) || element.hasTagName(SVGNames::polylineTag); }
-    static bool isSVGPolyElement(const Node& node) { return is<SVGElement>(node) && isSVGPolyElement(downcast<SVGElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGPolyElement)
+    static bool isType(const WebCore::SVGElement& element) { return element.hasTagName(WebCore::SVGNames::polygonTag) || element.hasTagName(WebCore::SVGNames::polylineTag); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::SVGElement>(node) && isType(downcast<WebCore::SVGElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index a592abe..09f20e4 100644 (file)
@@ -119,11 +119,11 @@ private:
     END_DECLARE_ANIMATED_PROPERTIES
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(SVGTextContentElement)
-    static bool isSVGTextContentElement(const SVGElement& element) { return element.isTextContent(); }
-    static bool isSVGTextContentElement(const Node& node) { return is<SVGElement>(node) && isSVGTextContentElement(downcast<SVGElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGTextContentElement)
+    static bool isType(const WebCore::SVGElement& element) { return element.isTextContent(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::SVGElement>(node) && isType(downcast<WebCore::SVGElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index 4d8c31b..875dcb9 100644 (file)
@@ -237,11 +237,11 @@ private:
     friend class ConditionEventListener;
 };
 
-SPECIALIZE_TYPE_TRAITS_BEGIN(SVGSMILElement)
-    static bool isSVGSMILElement(const SVGElement& element) { return element.isSMILElement(); }
-    static bool isSVGSMILElement(const Node& node) { return is<SVGElement>(node) && isSVGSMILElement(downcast<SVGElement>(node)); }
-SPECIALIZE_TYPE_TRAITS_END()
+} // namespace WebCore
 
-}
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGSMILElement)
+    static bool isType(const WebCore::SVGElement& element) { return element.isSMILElement(); }
+    static bool isType(const WebCore::Node& node) { return is<WebCore::SVGElement>(node) && isType(downcast<WebCore::SVGElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif // SVGSMILElement_h
index f9d0e3a..0464827 100644 (file)
@@ -257,12 +257,12 @@ public:
         : ScriptExecutionContext::Task([=] (ScriptExecutionContext& context) {
             RefPtr<MessagePort> port = MessagePort::create(context);
             port->entangle(std::unique_ptr<MessagePortChannel>(channel));
-            ASSERT_WITH_SECURITY_IMPLICATION(context.isWorkerGlobalScope());
-            WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(&context);
+            ASSERT_WITH_SECURITY_IMPLICATION(is<WorkerGlobalScope>(context));
+            WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(context);
             // Since close() stops the thread event loop, this should not ever get called while closing.
-            ASSERT(!workerGlobalScope->isClosing());
-            ASSERT_WITH_SECURITY_IMPLICATION(workerGlobalScope->isSharedWorkerGlobalScope());
-            workerGlobalScope->dispatchEvent(createConnectEvent(port));
+            ASSERT(!workerGlobalScope.isClosing());
+            ASSERT_WITH_SECURITY_IMPLICATION(workerGlobalScope.isSharedWorkerGlobalScope());
+            workerGlobalScope.dispatchEvent(createConnectEvent(port));
         })
     {
     }
index de1214e..e009e57 100644 (file)
@@ -133,10 +133,10 @@ void WorkerGlobalScope::close()
     // tasks with isCleanupTask()==true will be executed.
     m_closing = true;
     postTask({ ScriptExecutionContext::Task::CleanupTask, [] (ScriptExecutionContext& context) {
-        ASSERT_WITH_SECURITY_IMPLICATION(context.isWorkerGlobalScope());
-        WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(&context);
+        ASSERT_WITH_SECURITY_IMPLICATION(is<WorkerGlobalScope>(context));
+        WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(context);
         // Notify parent that this context is closed. Parent is responsible for calling WorkerThread::stop().
-        workerGlobalScope->thread().workerReportingProxy().workerGlobalScopeClosed();
+        workerGlobalScope.thread().workerReportingProxy().workerGlobalScopeClosed();
     } });
 }
 
index 404a201..5b58a69 100644 (file)
@@ -40,6 +40,7 @@
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/text/AtomicStringHash.h>
 
 namespace WebCore {
@@ -181,8 +182,10 @@ namespace WebCore {
         RefPtr<SecurityOrigin> m_topOrigin;
     };
 
-SCRIPT_EXECUTION_CONTEXT_TYPE_CASTS(WorkerGlobalScope)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::WorkerGlobalScope)
+    static bool isType(const WebCore::ScriptExecutionContext& context) { return context.isWorkerGlobalScope(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // WorkerGlobalScope_h
index 2bcaa4b..2a50188 100644 (file)
@@ -68,15 +68,15 @@ WorkerMessagingProxy::WorkerMessagingProxy(Worker* workerObject)
 #endif
 {
     ASSERT(m_workerObject);
-    ASSERT((m_scriptExecutionContext->isDocument() && isMainThread())
-           || (m_scriptExecutionContext->isWorkerGlobalScope() && currentThread() == toWorkerGlobalScope(*m_scriptExecutionContext).thread().threadID()));
+    ASSERT((is<Document>(*m_scriptExecutionContext) && isMainThread())
+        || (is<WorkerGlobalScope>(*m_scriptExecutionContext) && currentThread() == downcast<WorkerGlobalScope>(*m_scriptExecutionContext).thread().threadID()));
 }
 
 WorkerMessagingProxy::~WorkerMessagingProxy()
 {
     ASSERT(!m_workerObject);
-    ASSERT((m_scriptExecutionContext->isDocument() && isMainThread())
-           || (m_scriptExecutionContext->isWorkerGlobalScope() && currentThread() == toWorkerGlobalScope(*m_scriptExecutionContext).thread().threadID()));
+    ASSERT((is<Document>(*m_scriptExecutionContext) && isMainThread())
+        || (is<WorkerGlobalScope>(*m_scriptExecutionContext) && currentThread() == downcast<WorkerGlobalScope>(*m_scriptExecutionContext).thread().threadID()));
 }
 
 void WorkerMessagingProxy::startWorkerGlobalScope(const URL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode)
@@ -212,7 +212,7 @@ void WorkerMessagingProxy::notifyNetworkStateChange(bool isOnline)
         return;
 
     m_workerThread->runLoop().postTask([=] (ScriptExecutionContext& context) {
-        toWorkerGlobalScope(&context)->dispatchEvent(Event::create(isOnline ? eventNames().onlineEvent : eventNames().offlineEvent, false, false));
+        downcast<WorkerGlobalScope>(context).dispatchEvent(Event::create(isOnline ? eventNames().onlineEvent : eventNames().offlineEvent, false, false));
     });
 }
 
@@ -224,17 +224,17 @@ void WorkerMessagingProxy::connectToInspector(WorkerGlobalScopeProxy::PageInspec
     ASSERT(!m_pageInspector);
     m_pageInspector = pageInspector;
     m_workerThread->runLoop().postTaskForMode([] (ScriptExecutionContext& context) {
-        toWorkerGlobalScope(&context)->workerInspectorController().connectFrontend();
+        downcast<WorkerGlobalScope>(context).workerInspectorController().connectFrontend();
     }, WorkerDebuggerAgent::debuggerTaskMode);
 }
 
 void WorkerMessagingProxy::disconnectFromInspector()
 {
-    m_pageInspector = 0;
+    m_pageInspector = nullptr;
     if (m_askedToTerminate)
         return;
     m_workerThread->runLoop().postTaskForMode([] (ScriptExecutionContext& context) {
-        toWorkerGlobalScope(&context)->workerInspectorController().disconnectFrontend(Inspector::InspectorDisconnectReason::InspectorDestroyed);
+        downcast<WorkerGlobalScope>(context).workerInspectorController().disconnectFrontend(Inspector::InspectorDisconnectReason::InspectorDestroyed);
     }, WorkerDebuggerAgent::debuggerTaskMode);
 }
 
@@ -244,7 +244,7 @@ void WorkerMessagingProxy::sendMessageToInspector(const String& message)
         return;
     String messageCopy = message.isolatedCopy();
     m_workerThread->runLoop().postTaskForMode([messageCopy] (ScriptExecutionContext& context) {
-        toWorkerGlobalScope(&context)->workerInspectorController().dispatchMessageFromFrontend(messageCopy);
+        downcast<WorkerGlobalScope>(context).workerInspectorController().dispatchMessageFromFrontend(messageCopy);
     }, WorkerDebuggerAgent::debuggerTaskMode);
     WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(m_workerThread.get());
 }
index 05c5fa4..964a0aa 100644 (file)
@@ -61,14 +61,14 @@ void WorkerScriptLoader::loadSynchronously(ScriptExecutionContext* scriptExecuti
     if (!request)
         return;
 
-    ASSERT_WITH_SECURITY_IMPLICATION(scriptExecutionContext->isWorkerGlobalScope());
+    ASSERT_WITH_SECURITY_IMPLICATION(is<WorkerGlobalScope>(scriptExecutionContext));
 
     ThreadableLoaderOptions options;
     options.setAllowCredentials(AllowStoredCredentials);
     options.crossOriginRequestPolicy = crossOriginRequestPolicy;
     options.setSendLoadCallbacks(SendCallbacks);
 
-    WorkerThreadableLoader::loadResourceSynchronously(toWorkerGlobalScope(scriptExecutionContext), *request, *this, options);
+    WorkerThreadableLoader::loadResourceSynchronously(downcast<WorkerGlobalScope>(scriptExecutionContext), *request, *this, options);
 }
     
 void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext* scriptExecutionContext, const URL& url, CrossOriginRequestPolicy crossOriginRequestPolicy, WorkerScriptLoaderClient* client)
index e442250..ade5699 100644 (file)
@@ -214,21 +214,21 @@ void WorkerThread::stop()
         DatabaseManager::manager().interruptAllDatabasesForContext(m_workerGlobalScope.get());
 #endif
         m_runLoop.postTaskAndTerminate({ ScriptExecutionContext::Task::CleanupTask, [] (ScriptExecutionContext& context ) {
-            WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(&context);
+            WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(context);
 
 #if ENABLE(SQL_DATABASE)
             // FIXME: Should we stop the databases as part of stopActiveDOMObjects() below?
             DatabaseTaskSynchronizer cleanupSync;
-            DatabaseManager::manager().stopDatabases(workerGlobalScope, &cleanupSync);
+            DatabaseManager::manager().stopDatabases(&workerGlobalScope, &cleanupSync);
 #endif
 
-            workerGlobalScope->stopActiveDOMObjects();
+            workerGlobalScope.stopActiveDOMObjects();
 
-            workerGlobalScope->notifyObserversOfStop();
+            workerGlobalScope.notifyObserversOfStop();
 
             // Event listeners would keep DOMWrapperWorld objects alive for too long. Also, they have references to JS objects,
             // which become dangling once Heap is destroyed.
-            workerGlobalScope->removeAllEventListeners();
+            workerGlobalScope.removeAllEventListeners();
 
 #if ENABLE(SQL_DATABASE)
             // We wait for the database thread to clean up all its stuff so that we
@@ -238,10 +238,10 @@ void WorkerThread::stop()
 
             // Stick a shutdown command at the end of the queue, so that we deal
             // with all the cleanup tasks the databases post first.
-            workerGlobalScope->postTask({ ScriptExecutionContext::Task::CleanupTask, [] (ScriptExecutionContext& context) {
-                WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(&context);
+            workerGlobalScope.postTask({ ScriptExecutionContext::Task::CleanupTask, [] (ScriptExecutionContext& context) {
+                WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(context);
                 // It's not safe to call clearScript until all the cleanup tasks posted by functions initiated by WorkerThreadShutdownStartTask have completed.
-                workerGlobalScope->clearScript();
+                workerGlobalScope.clearScript();
             } });
 
         } });
index 4e51fc7..afac82f 100644 (file)
@@ -1,3 +1,15 @@
+2014-09-30  Christophe Dumez  <cdumez@apple.com>
+
+        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.
+
+        * DOMCoreClasses.cpp:
+        (DOMElement::createInstance):
+
 2014-09-30  Chris Dumez  <cdumez@apple.com>
 
         Use is<>() / downcast<>() for Element
index 337cda1..9c50bcd 100644 (file)
@@ -1500,22 +1500,22 @@ IDOMElement* DOMElement::createInstance(WebCore::Element* e)
     HRESULT hr;
     IDOMElement* domElement = 0;
 
-    if (WebCore::is<WebCore::HTMLFormElement>(e)) {
+    if (is<WebCore::HTMLFormElement>(e)) {
         DOMHTMLFormElement* newElement = new DOMHTMLFormElement(e);
         hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
     } else if (e->hasTagName(iframeTag)) {
         DOMHTMLIFrameElement* newElement = new DOMHTMLIFrameElement(e);
         hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
-    } else if (WebCore::is<WebCore::HTMLInputElement>(e)) {
+    } else if (is<WebCore::HTMLInputElement>(e)) {
         DOMHTMLInputElement* newElement = new DOMHTMLInputElement(e);
         hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
-    } else if (WebCore::is<WebCore::HTMLOptionElement>(e)) {
+    } else if (is<WebCore::HTMLOptionElement>(e)) {
         DOMHTMLOptionElement* newElement = new DOMHTMLOptionElement(e);
         hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
     } else if (e->hasTagName(selectTag)) {
         DOMHTMLSelectElement* newElement = new DOMHTMLSelectElement(e);
         hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
-    } else if (WebCore::is<WebCore::HTMLTextAreaElement>(e)) {
+    } else if (is<WebCore::HTMLTextAreaElement>(e)) {
         DOMHTMLTextAreaElement* newElement = new DOMHTMLTextAreaElement(e);
         hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
     } else if (e->isHTMLElement()) {
index bac4ca3..be824dc 100644 (file)
@@ -1,3 +1,20 @@
+2014-09-30  Christophe Dumez  <cdumez@apple.com>
+
+        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.
+
+        * WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm:
+        (-[WKDOMDocument createElement:]):
+        (-[WKDOMDocument createTextNode:]):
+        (-[WKDOMDocument body]):
+        * WebProcess/InjectedBundle/API/mac/WKDOMText.mm:
+        (-[WKDOMText data]):
+        (-[WKDOMText setData:]):
+
 2014-09-30  Chris Dumez  <cdumez@apple.com>
 
         Use is<>() / downcast<>() for Element
index ddd7bd6..8316629 100644 (file)
 {
     // FIXME: Do something about the exception.
     WebCore::ExceptionCode ec = 0;
-    return WebKit::toWKDOMElement(WebCore::downcast<WebCore::Document>(*_impl).createElement(tagName, ec).get());
+    return WebKit::toWKDOMElement(downcast<WebCore::Document>(*_impl).createElement(tagName, ec).get());
 }
 
 - (WKDOMText *)createTextNode:(NSString *)data
 {
-    return WebKit::toWKDOMText(WebCore::downcast<WebCore::Document>(*_impl).createTextNode(data).get());
+    return WebKit::toWKDOMText(downcast<WebCore::Document>(*_impl).createTextNode(data).get());
 }
 
 - (WKDOMElement *)body
 {
-    return WebKit::toWKDOMElement(WebCore::downcast<WebCore::Document>(*_impl).body());
+    return WebKit::toWKDOMElement(downcast<WebCore::Document>(*_impl).body());
 }
 
 @end
index cf71b1a..a53450f 100644 (file)
 
 - (BOOL)hasAttribute:(NSString *)attribute
 {
-    return WebCore::downcast<WebCore::Element>(*_impl).hasAttribute(attribute);
+    return downcast<WebCore::Element>(*_impl).hasAttribute(attribute);
 }
 
 - (NSString *)getAttribute:(NSString *)attribute
 {
-    return WebCore::downcast<WebCore::Element>(*_impl).getAttribute(attribute);
+    return downcast<WebCore::Element>(*_impl).getAttribute(attribute);
 }
 
 - (void)setAttribute:(NSString *)name value:(NSString *)value
 {
     // FIXME: Do something about the exception.
     WebCore::ExceptionCode ec;
-    WebCore::downcast<WebCore::Element>(*_impl).setAttribute(name, value, ec);
+    downcast<WebCore::Element>(*_impl).setAttribute(name, value, ec);
 }
 
 - (NSString *)tagName
 {
-    return WebCore::downcast<WebCore::Element>(*_impl).tagName();
+    return downcast<WebCore::Element>(*_impl).tagName();
 }
 
 @end
index d91e812..e30ae3c 100644 (file)
 
 - (NSString *)data
 {
-    return WebCore::downcast<WebCore::Text>(*_impl).data();
+    return downcast<WebCore::Text>(*_impl).data();
 }
 
 - (void)setData:(NSString *)data
 {
     // FIXME: Do something about the exception.
     WebCore::ExceptionCode ec;
-    WebCore::downcast<WebCore::Text>(*_impl).setData(data, ec);
+    downcast<WebCore::Text>(*_impl).setData(data, ec);
 }
 
 @end