Title: [165853] trunk/Source
Revision
165853
Author
[email protected]
Date
2014-03-18 15:56:26 -0700 (Tue, 18 Mar 2014)

Log Message

Begin cleaning up KeyedDecoder and KeyedEncoder
https://bugs.webkit.org/show_bug.cgi?id=130431

Reviewed by Tim Horton.

Source/WebCore:

Rename KeyedDecoder::decodeVerifiedEnum to decodeEnum to match the encode function,
and sort the decode functions to be in the same logical order as the encode functions.

* Modules/indexeddb/IDBKeyData.cpp:
(WebCore::IDBKeyData::decode):
* Modules/indexeddb/IDBKeyPath.cpp:
(WebCore::IDBKeyPath::decode):
* platform/KeyedCoding.h:
(WebCore::KeyedDecoder::decodeEnum):

Source/WebKit2:

* Shared/cf/KeyedDecoder.cpp:
(WebKit::KeyedDecoder::KeyedDecoder):
If we can't parse the property list data, just add an empty dictionary to the stack.

(WebKit::KeyedDecoder::decodeBool):
Remove unneeded m_dictionaryStack.last() null check. m_dictionaryStack would either be empty
or at least have a root element; it would never have a null element.

(WebKit::KeyedDecoder::decodeDouble):
Remove the same check as above and remove the CFNumberGetType checks since CFNumberGetValue will
do the type conversion for us and return false if it's lossy.

(WebKit::KeyedDecoder::decodeInt64):
Remove the m_dictionaryStack.last() check.

(WebKit::KeyedDecoder::decodeUInt32):
Ditto.

(WebKit::KeyedDecoder::decodeString):
Ditto.

(WebKit::KeyedDecoder::beginObject):
Ditto.

(WebKit::KeyedDecoder::beginArray):
Ditto.

(WebKit::KeyedDecoder::beginArrayElement):
Ditto.

* Shared/cf/KeyedDecoder.h:
Sort functions to be in the same logical order as the base class.

* Shared/cf/KeyedEncoder.cpp:
(WebKit::KeyedEncoder::finishEncoding):
Don't check for a non-null CFErrorRef here (which we incidentally never released on error). Instead,
just null check the returned CFDataRef object.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (165852 => 165853)


--- trunk/Source/WebCore/ChangeLog	2014-03-18 22:41:20 UTC (rev 165852)
+++ trunk/Source/WebCore/ChangeLog	2014-03-18 22:56:26 UTC (rev 165853)
@@ -1,3 +1,20 @@
+2014-03-18  Anders Carlsson  <[email protected]>
+
+        Begin cleaning up KeyedDecoder and KeyedEncoder
+        https://bugs.webkit.org/show_bug.cgi?id=130431
+
+        Reviewed by Tim Horton.
+
+        Rename KeyedDecoder::decodeVerifiedEnum to decodeEnum to match the encode function,
+        and sort the decode functions to be in the same logical order as the encode functions.
+
+        * Modules/indexeddb/IDBKeyData.cpp:
+        (WebCore::IDBKeyData::decode):
+        * Modules/indexeddb/IDBKeyPath.cpp:
+        (WebCore::IDBKeyPath::decode):
+        * platform/KeyedCoding.h:
+        (WebCore::KeyedDecoder::decodeEnum):
+
 2014-03-18  Darin Adler  <[email protected]>
 
         Reduce use of deprecatedCharacters in WebCore

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.cpp (165852 => 165853)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.cpp	2014-03-18 22:41:20 UTC (rev 165852)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.cpp	2014-03-18 22:56:26 UTC (rev 165853)
@@ -177,7 +177,7 @@
             || value == IDBKey::NumberType
             || value == IDBKey::MinType;
     };
-    if (!decoder.decodeVerifiedEnum("type", result.type, enumFunction))
+    if (!decoder.decodeEnum("type", result.type, enumFunction))
         return false;
 
     if (result.type == IDBKey::InvalidType)

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.cpp (165852 => 165853)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.cpp	2014-03-18 22:41:20 UTC (rev 165852)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.cpp	2014-03-18 22:56:26 UTC (rev 165853)
@@ -285,7 +285,7 @@
         return value == NullType || value == StringType || value == ArrayType;
     };
 
-    if (!decoder.decodeVerifiedEnum("type", result.m_type, enumFunction))
+    if (!decoder.decodeEnum("type", result.m_type, enumFunction))
         return false;
 
     if (result.m_type == NullType)

Modified: trunk/Source/WebCore/platform/KeyedCoding.h (165852 => 165853)


--- trunk/Source/WebCore/platform/KeyedCoding.h	2014-03-18 22:41:20 UTC (rev 165852)
+++ trunk/Source/WebCore/platform/KeyedCoding.h	2014-03-18 22:56:26 UTC (rev 165853)
@@ -40,13 +40,13 @@
 
 public:
     virtual bool decodeBool(const String& key, bool&) = 0;
+    virtual bool decodeUInt32(const String& key, uint32_t&) = 0;
+    virtual bool decodeInt64(const String& key, int64_t&) = 0;
     virtual bool decodeDouble(const String& key, double&) = 0;
-    virtual bool decodeInt64(const String& key, int64_t&) = 0;
-    virtual bool decodeUInt32(const String& key, uint32_t&) = 0;
     virtual bool decodeString(const String& key, String&) = 0;
 
     template<typename T, typename F>
-    bool decodeVerifiedEnum(const String& key, T& value, F&& function)
+    bool decodeEnum(const String& key, T& value, F&& isValidEnumFunction)
     {
         static_assert(std::is_enum<T>::value, "T must be an enum type");
 
@@ -54,7 +54,7 @@
         if (!decodeInt64(key, intValue))
             return false;
 
-        if (!function(intValue))
+        if (!isValidEnumFunction(intValue))
             return false;
 
         value = static_cast<T>(intValue);

Modified: trunk/Source/WebKit2/ChangeLog (165852 => 165853)


--- trunk/Source/WebKit2/ChangeLog	2014-03-18 22:41:20 UTC (rev 165852)
+++ trunk/Source/WebKit2/ChangeLog	2014-03-18 22:56:26 UTC (rev 165853)
@@ -1,3 +1,48 @@
+2014-03-18  Anders Carlsson  <[email protected]>
+
+        Begin cleaning up KeyedDecoder and KeyedEncoder
+        https://bugs.webkit.org/show_bug.cgi?id=130431
+
+        Reviewed by Tim Horton.
+
+        * Shared/cf/KeyedDecoder.cpp:
+        (WebKit::KeyedDecoder::KeyedDecoder):
+        If we can't parse the property list data, just add an empty dictionary to the stack.
+
+        (WebKit::KeyedDecoder::decodeBool):
+        Remove unneeded m_dictionaryStack.last() null check. m_dictionaryStack would either be empty
+        or at least have a root element; it would never have a null element.
+        
+        (WebKit::KeyedDecoder::decodeDouble):
+        Remove the same check as above and remove the CFNumberGetType checks since CFNumberGetValue will
+        do the type conversion for us and return false if it's lossy.
+
+        (WebKit::KeyedDecoder::decodeInt64):
+        Remove the m_dictionaryStack.last() check.
+
+        (WebKit::KeyedDecoder::decodeUInt32):
+        Ditto.
+
+        (WebKit::KeyedDecoder::decodeString):
+        Ditto.
+
+        (WebKit::KeyedDecoder::beginObject):
+        Ditto.
+
+        (WebKit::KeyedDecoder::beginArray):
+        Ditto.
+
+        (WebKit::KeyedDecoder::beginArrayElement):
+        Ditto.
+
+        * Shared/cf/KeyedDecoder.h:
+        Sort functions to be in the same logical order as the base class.
+
+        * Shared/cf/KeyedEncoder.cpp:
+        (WebKit::KeyedEncoder::finishEncoding):
+        Don't check for a non-null CFErrorRef here (which we incidentally never released on error). Instead,
+        just null check the returned CFDataRef object.
+
 2014-03-18  Joseph Pecoraro  <[email protected]>
 
         Unreviewed typo build fix for r165846.

Modified: trunk/Source/WebKit2/Shared/cf/KeyedDecoder.cpp (165852 => 165853)


--- trunk/Source/WebKit2/Shared/cf/KeyedDecoder.cpp	2014-03-18 22:41:20 UTC (rev 165852)
+++ trunk/Source/WebKit2/Shared/cf/KeyedDecoder.cpp	2014-03-18 22:56:26 UTC (rev 165853)
@@ -32,14 +32,14 @@
 
 KeyedDecoder::KeyedDecoder(const uint8_t* data, size_t size)
 {
-    auto cfData = adoptCF(CFDataCreate(kCFAllocatorDefault, data, size));
-    m_rootDictionary = adoptCF(static_cast<CFDictionaryRef>(CFPropertyListCreateWithData(kCFAllocatorDefault, cfData.get(), kCFPropertyListImmutable, 0, 0)));
+    auto cfData = adoptCF(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, data, size, kCFAllocatorNull));
+    auto rootDictionary = adoptCF(CFPropertyListCreateWithData(kCFAllocatorDefault, cfData.get(), kCFPropertyListImmutable, nullptr, nullptr));
 
-    if (m_rootDictionary && CFGetTypeID(m_rootDictionary.get()) != CFDictionaryGetTypeID())
-        m_rootDictionary = nullptr;
-
-    if (m_rootDictionary)
-        m_dictionaryStack.append(m_rootDictionary.get());
+    if (rootDictionary && CFGetTypeID(rootDictionary.get()) == CFDictionaryGetTypeID())
+        m_rootDictionary = adoptCF(static_cast<CFDictionaryRef>(rootDictionary.leakRef()));
+    else
+        m_rootDictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, nullptr, nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+    m_dictionaryStack.append(m_rootDictionary.get());
 }
 
 KeyedDecoder::~KeyedDecoder()
@@ -52,9 +52,6 @@
 
 bool KeyedDecoder::decodeBool(const String& key, bool& result)
 {
-    if (!m_dictionaryStack.last())
-        return false;
-
     CFBooleanRef boolean = static_cast<CFBooleanRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
     if (!boolean || CFGetTypeID(boolean) != CFBooleanGetTypeID())
         return false;
@@ -63,47 +60,35 @@
     return true;
 }
 
-bool KeyedDecoder::decodeDouble(const String& key, double& result)
+bool KeyedDecoder::decodeUInt32(const String& key, uint32_t& result)
 {
-    if (!m_dictionaryStack.last())
-        return false;
-
     CFNumberRef number = static_cast<CFNumberRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!number || CFGetTypeID(number) != CFNumberGetTypeID() || (CFNumberGetType(number) != kCFNumberDoubleType && CFNumberGetType(number) != kCFNumberFloat64Type))
+    if (!number || CFGetTypeID(number) != CFNumberGetTypeID())
         return false;
 
-    return CFNumberGetValue(number, kCFNumberDoubleType, &result);
+    return CFNumberGetValue(number, kCFNumberSInt32Type, &result);
 }
 
 bool KeyedDecoder::decodeInt64(const String& key, int64_t& result)
 {
-    if (!m_dictionaryStack.last())
-        return false;
-
     CFNumberRef number = static_cast<CFNumberRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!number || CFGetTypeID(number) != CFNumberGetTypeID() || CFNumberGetType(number) != kCFNumberSInt64Type)
+    if (!number || CFGetTypeID(number) != CFNumberGetTypeID())
         return false;
 
     return CFNumberGetValue(number, kCFNumberSInt64Type, &result);
 }
 
-bool KeyedDecoder::decodeUInt32(const String& key, uint32_t& result)
+bool KeyedDecoder::decodeDouble(const String& key, double& result)
 {
-    if (!m_dictionaryStack.last())
-        return false;
-
     CFNumberRef number = static_cast<CFNumberRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
-    if (!number || CFGetTypeID(number) != CFNumberGetTypeID() || CFNumberGetType(number) != kCFNumberSInt32Type)
+    if (!number || CFGetTypeID(number) != CFNumberGetTypeID())
         return false;
 
-    return CFNumberGetValue(number, kCFNumberSInt32Type, &result);
+    return CFNumberGetValue(number, kCFNumberDoubleType, &result);
 }
 
 bool KeyedDecoder::decodeString(const String& key, String& result)
 {
-    if (!m_dictionaryStack.last())
-        return false;
-
     CFStringRef string = static_cast<CFStringRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
     if (!string || CFGetTypeID(string) != CFStringGetTypeID())
         return false;
@@ -114,9 +99,6 @@
 
 bool KeyedDecoder::beginObject(const String& key)
 {
-    if (!m_dictionaryStack.last())
-        return false;
-
     CFDictionaryRef dictionary = static_cast<CFDictionaryRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
     if (!dictionary || CFGetTypeID(dictionary) != CFDictionaryGetTypeID())
         return false;
@@ -132,9 +114,6 @@
 
 bool KeyedDecoder::beginArray(const String& key)
 {
-    if (!m_dictionaryStack.last())
-        return false;
-
     CFArrayRef array = static_cast<CFArrayRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get()));
     if (!array || CFGetTypeID(array) != CFArrayGetTypeID())
         return false;
@@ -152,8 +131,6 @@
 
 bool KeyedDecoder::beginArrayElement()
 {
-    ASSERT(m_dictionaryStack.last());
-
     if (m_arrayIndexStack.last() >= CFArrayGetCount(m_arrayStack.last()))
         return false;
 

Modified: trunk/Source/WebKit2/Shared/cf/KeyedDecoder.h (165852 => 165853)


--- trunk/Source/WebKit2/Shared/cf/KeyedDecoder.h	2014-03-18 22:41:20 UTC (rev 165852)
+++ trunk/Source/WebKit2/Shared/cf/KeyedDecoder.h	2014-03-18 22:56:26 UTC (rev 165853)
@@ -39,9 +39,9 @@
 
 private:
     virtual bool decodeBool(const String& key, bool&) override;
+    virtual bool decodeUInt32(const String& key, uint32_t&) override;
+    virtual bool decodeInt64(const String& key, int64_t&) override;
     virtual bool decodeDouble(const String& key, double&) override;
-    virtual bool decodeInt64(const String& key, int64_t&) override;
-    virtual bool decodeUInt32(const String& key, uint32_t&) override;
     virtual bool decodeString(const String& key, String&) override;
 
     virtual bool beginObject(const String& key) override;

Modified: trunk/Source/WebKit2/Shared/cf/KeyedEncoder.cpp (165852 => 165853)


--- trunk/Source/WebKit2/Shared/cf/KeyedEncoder.cpp	2014-03-18 22:41:20 UTC (rev 165852)
+++ trunk/Source/WebKit2/Shared/cf/KeyedEncoder.cpp	2014-03-18 22:56:26 UTC (rev 165853)
@@ -139,9 +139,8 @@
 
 PassRefPtr<SharedBuffer> KeyedEncoder::finishEncoding()
 {
-    CFErrorRef error = nullptr;
-    RetainPtr<CFDataRef> data = "" m_rootDictionary.get(), kCFPropertyListBinaryFormat_v1_0, 0, &error));
-    if (error)
+    RetainPtr<CFDataRef> data = "" m_rootDictionary.get(), kCFPropertyListBinaryFormat_v1_0, 0, nullptr));
+    if (!data)
         return nullptr;
 
     return SharedBuffer::wrapCFData(data.get());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to