Get rid of unnecessary null check in wrap(JSDOMGlobalObject*, DOMClass*)
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Apr 2016 04:51:31 +0000 (04:51 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Apr 2016 04:51:31 +0000 (04:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=157224

Reviewed by Ryosuke Niwa.

Get rid of unnecessary null check in wrap(JSDOMGlobalObject*, DOMClass*)
since all the call sites already do a null check. Also update the function
to take the implementation object by reference instead of pointer. Finally,
use is<>() / downcast<>() more at the call sites.

* Modules/indexeddb/IDBCursor.cpp:
(WebCore::IDBCursor::update):
(WebCore::IDBCursor::deleteFunction):
(WebCore::IDBCursor::setGetResult):
* Modules/indexeddb/IDBCursor.h:
(WebCore::IDBCursor::isKeyCursorWithValue):
(WebCore::IDBCursor::isKeyCursor): Deleted.
* Modules/indexeddb/IDBCursorWithValue.h:
(isType):
* bindings/js/JSBlobCustom.cpp:
(WebCore::toJS):
* bindings/js/JSCanvasRenderingContextCustom.cpp:
(WebCore::toJS):
* bindings/js/JSDOMBinding.h:
(WebCore::wrap):
* bindings/js/JSIDBCursorCustom.cpp:
(WebCore::toJS):
* bindings/js/JSMediaStreamCapabilitiesCustom.cpp:
(WebCore::toJS):
* bindings/js/JSPerformanceEntryCustom.cpp:
(WebCore::toJS):
* html/canvas/WebGL2RenderingContext.h:
* html/canvas/WebGLRenderingContext.h:
* page/PerformanceMark.h:
(isType):
(WebCore::PerformanceMark::isMark): Deleted.
* page/PerformanceMeasure.h:
(isType):
(WebCore::PerformanceMeasure::isMeasure): Deleted.
* page/PerformanceResourceTiming.h:
(isType):
(WebCore::PerformanceResourceTiming::isResource): Deleted.

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBCursor.cpp
Source/WebCore/Modules/indexeddb/IDBCursor.h
Source/WebCore/Modules/indexeddb/IDBCursorWithValue.h
Source/WebCore/bindings/js/JSBlobCustom.cpp
Source/WebCore/bindings/js/JSCanvasRenderingContextCustom.cpp
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/js/JSIDBCursorCustom.cpp
Source/WebCore/bindings/js/JSMediaStreamCapabilitiesCustom.cpp
Source/WebCore/bindings/js/JSPerformanceEntryCustom.cpp
Source/WebCore/html/canvas/WebGL2RenderingContext.h
Source/WebCore/html/canvas/WebGLRenderingContext.h
Source/WebCore/page/PerformanceEntry.h
Source/WebCore/page/PerformanceMark.h
Source/WebCore/page/PerformanceMeasure.h
Source/WebCore/page/PerformanceResourceTiming.h

index fe5c142..f07c2c7 100644 (file)
@@ -1,5 +1,50 @@
 2016-04-29  Chris Dumez  <cdumez@apple.com>
 
+        Get rid of unnecessary null check in wrap(JSDOMGlobalObject*, DOMClass*)
+        https://bugs.webkit.org/show_bug.cgi?id=157224
+
+        Reviewed by Ryosuke Niwa.
+
+        Get rid of unnecessary null check in wrap(JSDOMGlobalObject*, DOMClass*)
+        since all the call sites already do a null check. Also update the function
+        to take the implementation object by reference instead of pointer. Finally,
+        use is<>() / downcast<>() more at the call sites.
+
+        * Modules/indexeddb/IDBCursor.cpp:
+        (WebCore::IDBCursor::update):
+        (WebCore::IDBCursor::deleteFunction):
+        (WebCore::IDBCursor::setGetResult):
+        * Modules/indexeddb/IDBCursor.h:
+        (WebCore::IDBCursor::isKeyCursorWithValue):
+        (WebCore::IDBCursor::isKeyCursor): Deleted.
+        * Modules/indexeddb/IDBCursorWithValue.h:
+        (isType):
+        * bindings/js/JSBlobCustom.cpp:
+        (WebCore::toJS):
+        * bindings/js/JSCanvasRenderingContextCustom.cpp:
+        (WebCore::toJS):
+        * bindings/js/JSDOMBinding.h:
+        (WebCore::wrap):
+        * bindings/js/JSIDBCursorCustom.cpp:
+        (WebCore::toJS):
+        * bindings/js/JSMediaStreamCapabilitiesCustom.cpp:
+        (WebCore::toJS):
+        * bindings/js/JSPerformanceEntryCustom.cpp:
+        (WebCore::toJS):
+        * html/canvas/WebGL2RenderingContext.h:
+        * html/canvas/WebGLRenderingContext.h:
+        * page/PerformanceMark.h:
+        (isType):
+        (WebCore::PerformanceMark::isMark): Deleted.
+        * page/PerformanceMeasure.h:
+        (isType):
+        (WebCore::PerformanceMeasure::isMeasure): Deleted.
+        * page/PerformanceResourceTiming.h:
+        (isType):
+        (WebCore::PerformanceResourceTiming::isResource): Deleted.
+
+2016-04-29  Chris Dumez  <cdumez@apple.com>
+
         Use LIKELY() / UNLIKELY() hints when suitable in the JavaScript bindings
         https://bugs.webkit.org/show_bug.cgi?id=157210
 
index dff1c7c..013c7f7 100644 (file)
@@ -187,7 +187,7 @@ RefPtr<WebCore::IDBRequest> IDBCursor::update(ExecState& exec, JSValue value, Ex
         return nullptr;
     }
 
-    if (isKeyCursor()) {
+    if (!isKeyCursorWithValue()) {
         ec.code = IDBDatabaseException::InvalidStateError;
         ec.message = ASCIILiteral("Failed to execute 'update' on 'IDBCursor': The cursor is a key cursor.");
         return nullptr;
@@ -350,7 +350,7 @@ RefPtr<WebCore::IDBRequest> IDBCursor::deleteFunction(ScriptExecutionContext& co
         return nullptr;
     }
 
-    if (isKeyCursor()) {
+    if (!isKeyCursorWithValue()) {
         ec.code = IDBDatabaseException::InvalidStateError;
         ec.message = ASCIILiteral("Failed to execute 'delete' on 'IDBCursor': The cursor is a key cursor.");
         return nullptr;
@@ -393,10 +393,10 @@ void IDBCursor::setGetResult(IDBRequest& request, const IDBGetResult& getResult)
     m_currentPrimaryKey = { vm, idbKeyDataToScriptValue(*context, getResult.primaryKeyData()) };
     m_currentPrimaryKeyData = getResult.primaryKeyData();
 
-    if (isKeyCursor())
-        m_currentValue = { };
-    else
+    if (isKeyCursorWithValue())
         m_currentValue = { vm, deserializeIDBValueToJSValue(*context, getResult.value()) };
+    else
+        m_currentValue = { };
 
     m_gotValue = true;
 }
index 24b709a..775dafb 100644 (file)
@@ -77,7 +77,7 @@ public:
 
     void setGetResult(IDBRequest&, const IDBGetResult&);
 
-    virtual bool isKeyCursor() const { return true; }
+    virtual bool isKeyCursorWithValue() const { return false; }
 
     void decrementOutstandingRequestCount();
 
index 1ee5dd5..f78891b 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(INDEXED_DATABASE)
 
 #include "IDBCursor.h"
+#include <wtf/TypeCasts.h>
 
 namespace WebCore {
 
@@ -38,7 +39,7 @@ public:
 
     virtual ~IDBCursorWithValue();
 
-    bool isKeyCursor() const final { return false; }
+    bool isKeyCursorWithValue() const  override { return true; }
 
 private:
     IDBCursorWithValue(IDBTransaction&, IDBObjectStore&, const IDBCursorInfo&);
@@ -47,4 +48,8 @@ private:
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::IDBCursorWithValue)
+    static bool isType(const WebCore::IDBCursor& cursor) { return cursor.isKeyCursorWithValue(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // ENABLE(INDEXED_DATABASE)
index ade5a0a..dd9b41e 100644 (file)
@@ -53,10 +53,10 @@ JSValue toJS(ExecState*, JSDOMGlobalObject* globalObject, Blob* blob)
     if (!blob)
         return jsNull();
 
-    if (blob->isFile())
-        return wrap<JSFile>(globalObject, static_cast<File*>(blob));
+    if (is<File>(*blob))
+        return wrap<JSFile>(globalObject, downcast<File>(*blob));
 
-    return wrap<JSBlob>(globalObject, blob);
+    return wrap<JSBlob>(globalObject, *blob);
 }
 
 EncodedJSValue JSC_HOST_CALL constructJSBlob(ExecState* exec)
index 7f50435..63ff588 100644 (file)
@@ -53,15 +53,14 @@ JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, CanvasRender
         return jsNull();
 
 #if ENABLE(WEBGL)
-    if (object->isWebGL1())
-        return wrap<JSWebGLRenderingContext>(globalObject, static_cast<WebGLRenderingContext*>(object));
+    if (is<WebGLRenderingContext>(*object))
+        return wrap<JSWebGLRenderingContext>(globalObject, downcast<WebGLRenderingContext>(*object));
 #if ENABLE(WEBGL2)
-    if (object->isWebGL2())
-        return wrap<JSWebGL2RenderingContext>(globalObject, static_cast<WebGL2RenderingContext*>(object));
+    if (is<WebGL2RenderingContext>(*object))
+        return wrap<JSWebGL2RenderingContext>(globalObject, downcast<WebGL2RenderingContext>(*object));
 #endif
 #endif
-    ASSERT_WITH_SECURITY_IMPLICATION(object->is2d());
-    return wrap<JSCanvasRenderingContext2D>(globalObject, static_cast<CanvasRenderingContext2D*>(object));
+    return wrap<JSCanvasRenderingContext2D>(globalObject, downcast<CanvasRenderingContext2D>(*object));
 }
 
 } // namespace WebCore
index 6ccd3a5..57e6941 100644 (file)
@@ -267,13 +267,11 @@ template<typename WrapperClass, typename DOMClass> inline JSDOMObject* createWra
     return wrapper;
 }
 
-template<typename WrapperClass, typename DOMClass> inline JSC::JSValue wrap(JSDOMGlobalObject* globalObject, DOMClass* domObject)
+template<typename WrapperClass, typename DOMClass> inline JSC::JSValue wrap(JSDOMGlobalObject* globalObject, DOMClass& domObject)
 {
-    if (!domObject)
-        return JSC::jsNull();
-    if (JSC::JSObject* wrapper = getCachedWrapper(globalObject->world(), domObject))
+    if (JSC::JSObject* wrapper = getCachedWrapper(globalObject->world(), &domObject))
         return wrapper;
-    return createWrapper<WrapperClass>(globalObject, domObject);
+    return createWrapper<WrapperClass>(globalObject, &domObject);
 }
 
 template<typename WrapperClass, typename DOMClass> inline JSC::JSValue getExistingWrapper(JSDOMGlobalObject* globalObject, DOMClass* domObject)
index 285954e..242b985 100644 (file)
@@ -54,9 +54,13 @@ JSValue JSIDBCursor::source(ExecState& state) const
 
 JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, IDBCursor* cursor)
 {
-    if (cursor->isKeyCursor())
-        return wrap<JSIDBCursor>(globalObject, cursor);
-    return wrap<JSIDBCursorWithValue>(globalObject, static_cast<IDBCursorWithValue*>(cursor));
+    if (!cursor)
+        return JSC::jsNull();
+
+    if (is<IDBCursorWithValue>(*cursor))
+        return wrap<JSIDBCursorWithValue>(globalObject, downcast<IDBCursorWithValue>(*cursor));
+
+    return wrap<JSIDBCursor>(globalObject, *cursor);
 }
 
 } // namespace WebCore
index 3ba0ce2..5569ed6 100644 (file)
@@ -43,9 +43,9 @@ JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, MediaStreamC
         return jsNull();
 
     if (object->hasVideoSource())
-        return wrap<JSAllVideoCapabilities>(globalObject, static_cast<AllVideoCapabilities*>(object));
+        return wrap<JSAllVideoCapabilities>(globalObject, static_cast<AllVideoCapabilities>(*object));
 
-    return wrap<JSAllAudioCapabilities>(globalObject, static_cast<AllAudioCapabilities*>(object));
+    return wrap<JSAllAudioCapabilities>(globalObject, static_cast<AllAudioCapabilities>(*object));
 }
 
 } // namespace WebCore
index ebdd37f..74de5d2 100644 (file)
@@ -52,19 +52,19 @@ JSValue toJS(ExecState*, JSDOMGlobalObject* globalObject, PerformanceEntry* entr
         return jsNull();
 
 #if ENABLE(RESOURCE_TIMING)
-    if (entry->isResource())
-        return wrap<JSPerformanceResourceTiming>(globalObject, static_cast<PerformanceResourceTiming*>(entry));
+    if (is<PerformanceResourceTiming>(*entry))
+        return wrap<JSPerformanceResourceTiming>(globalObject, downcast<PerformanceResourceTiming>(*entry));
 #endif
 
 #if ENABLE(USER_TIMING)
-    if (entry->isMark())
-        return wrap<JSPerformanceMark>(globalObject, static_cast<PerformanceMark*>(entry));
+    if (is<PerformanceMark>(*entry))
+        return wrap<JSPerformanceMark>(globalObject, downcast<PerformanceMark>(*entry));
 
-    if (entry->isMeasure())
-        return wrap<JSPerformanceMeasure>(globalObject, static_cast<PerformanceMeasure*>(entry));
+    if (is<PerformanceMeasure>(*entry))
+        return wrap<JSPerformanceMeasure>(globalObject, downcast<PerformanceMeasure>(*entry));
 #endif
 
-    return wrap<JSPerformanceEntry>(globalObject, entry);
+    return wrap<JSPerformanceEntry>(globalObject, *entry);
 }
 
 } // namespace WebCore
index cef7474..735fbd4 100644 (file)
@@ -220,6 +220,8 @@ private:
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::WebGL2RenderingContext, isWebGL2())
+
 #endif // WEBGL2
 
 #endif
index a27c603..6448fd0 100644 (file)
@@ -85,4 +85,6 @@ protected:
     
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::WebGLRenderingContext, isWebGL1())
+
 #endif
index 129a246..0111b1d 100644 (file)
@@ -37,6 +37,7 @@
 #include "Performance.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -50,9 +51,9 @@ public:
     double startTime() const;
     double duration() const;
 
-    virtual bool isResource() { return false; }
-    virtual bool isMark() { return false; }
-    virtual bool isMeasure() { return false; }
+    virtual bool isResource() const { return false; }
+    virtual bool isMark() const { return false; }
+    virtual bool isMeasure() const { return false; }
 
     static bool startTimeCompareLessThan(PassRefPtr<PerformanceEntry> a, PassRefPtr<PerformanceEntry> b)
     {
index cd71a02..f0523e4 100644 (file)
 
 namespace WebCore {
 
-class PerformanceMark : public PerformanceEntry {
+class PerformanceMark final : public PerformanceEntry {
 public:
     static Ref<PerformanceMark> create(const String& name, double startTime) { return adoptRef(*new PerformanceMark(name, startTime)); }
 
-    virtual bool isMark() { return true; }
+    bool isMark() const override { return true; }
     
 private:
     PerformanceMark(const String& name, double startTime) : PerformanceEntry(name, "mark", startTime, startTime) { }
@@ -47,6 +47,10 @@ private:
 
 }
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::PerformanceMark)
+    static bool isType(const WebCore::PerformanceEntry& entry) { return entry.isMark(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // ENABLE(USER_TIMING)
 
 #endif // !defined(PerformanceMark_h)
index af3e36e..4a2ea0c 100644 (file)
 
 namespace WebCore {
 
-class PerformanceMeasure : public PerformanceEntry {
+class PerformanceMeasure final : public PerformanceEntry {
 public:
     static Ref<PerformanceMeasure> create(const String& name, double startTime, double duration) { return adoptRef(*new PerformanceMeasure(name, startTime, duration)); }
 
-    virtual bool isMeasure() { return true; }
+    bool isMeasure() const override { return true; }
 
 private:
     PerformanceMeasure(const String& name, double startTime, double duration) : PerformanceEntry(name, "measure", startTime, duration) { }
@@ -47,6 +47,10 @@ private:
 
 }
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::PerformanceMeasure)
+    static bool isType(const WebCore::PerformanceEntry& entry) { return entry.isMeasure(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // ENABLE(USER_TIMING)
 
 #endif // !defined(PerformanceMeasure_h)
index 99dfc5b..3c35d1a 100644 (file)
@@ -48,7 +48,7 @@ class ResourceLoadTiming;
 class ResourceRequest;
 class ResourceResponse;
 
-class PerformanceResourceTiming : public PerformanceEntry {
+class PerformanceResourceTiming final : public PerformanceEntry {
 public:
     static Ref<PerformanceResourceTiming> create(const AtomicString& initiatorType, const ResourceRequest& request, const ResourceResponse& response, double initiationTime, double finishTime, Document* requestingDocument)
     {
@@ -68,7 +68,7 @@ public:
     double requestStart() const;
     double responseEnd() const;
 
-    virtual bool isResource() { return true; }
+    bool isResource() const override { return true; }
 
 private:
     PerformanceResourceTiming(const AtomicString& initatorType, const ResourceRequest&, const ResourceResponse&, double initiationTime, double finishTime, Document*);
@@ -85,6 +85,11 @@ private:
 
 }
 
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::PerformanceResourceTiming)
+    static bool isType(const WebCore::PerformanceEntry& entry) { return entry.isResource(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // ENABLE(RESOURCE_TIMING)
 
 #endif // !defined(PerformanceResourceTiming_h)