Title: [143599] trunk/Source/WebKit/blackberry
Revision
143599
Author
[email protected]
Date
2013-02-21 07:33:24 -0800 (Thu, 21 Feb 2013)

Log Message

[BlackBerry] Invalid use of COMPILE_ASSERT macro in WebKitTextCodec.cpp
https://bugs.webkit.org/show_bug.cgi?id=110437

Patch by Carlos Garcia Campos <[email protected]> on 2013-02-21
Reviewed by Yong Li.

* Api/WebKitTextCodec.cpp:
(WebKit): Define COMPILE_ASSERT_MATCHING_ENUM() macro and use it to
check enum values match between WebKit and WTF.
(BlackBerry::WebKit::base64Decode): Use a static cast directly to
convert from WebKit Base64DecodePolicy to WTF.
(BlackBerry::WebKit::base64Encode): Use a static cast directly to
convert from WebKit Base64EncodePolicy to WTF.

Modified Paths

Diff

Modified: trunk/Source/WebKit/blackberry/Api/WebKitTextCodec.cpp (143598 => 143599)


--- trunk/Source/WebKit/blackberry/Api/WebKitTextCodec.cpp	2013-02-21 14:57:41 UTC (rev 143598)
+++ trunk/Source/WebKit/blackberry/Api/WebKitTextCodec.cpp	2013-02-21 15:33:24 UTC (rev 143599)
@@ -33,6 +33,17 @@
 namespace BlackBerry {
 namespace WebKit {
 
+#define COMPILE_ASSERT_MATCHING_ENUM(webkitName, wtfName) \
+    COMPILE_ASSERT(static_cast<int>(webkitName) == static_cast<int>(WTF::wtfName), mismatchingEnums)
+
+COMPILE_ASSERT_MATCHING_ENUM(Base64FailOnInvalidCharacter, Base64FailOnInvalidCharacter);
+COMPILE_ASSERT_MATCHING_ENUM(Base64IgnoreWhitespace, Base64IgnoreWhitespace);
+COMPILE_ASSERT_MATCHING_ENUM(Base64IgnoreInvalidCharacters, Base64IgnoreInvalidCharacters);
+
+// FIXME: Base64InsertCRLF should be Base64InsertLFs. WTF::encodeBase64 doesn't insert CR.
+COMPILE_ASSERT_MATCHING_ENUM(Base64DoNotInsertCRLF, Base64DoNotInsertLFs);
+COMPILE_ASSERT_MATCHING_ENUM(Base64InsertCRLF, Base64InsertLFs);
+
 bool isSameEncoding(const char* encoding1, const char* encoding2)
 {
     return TextEncoding(encoding1) == TextEncoding(encoding2);
@@ -85,40 +96,24 @@
     return Success;
 }
 
-WTF::Base64DecodePolicy base64DecodePolicyForWTF(Base64DecodePolicy policy)
-{
-    COMPILE_ASSERT(WTF::Base64FailOnInvalidCharacter == static_cast<WTF::Base64DecodePolicy>(Base64FailOnInvalidCharacter));
-    COMPILE_ASSERT(WTF::Base64IgnoreWhitespace == static_cast<WTF::Base64DecodePolicy>(Base64IgnoreWhitespace));
-    COMPILE_ASSERT(WTF::Base64IgnoreInvalidCharacters == static_cast<WTF::Base64DecodePolicy>(Base64IgnoreInvalidCharacters));
-    return static_cast<WTF::Base64DecodePolicy>(policy);
-}
-
 bool base64Decode(const BlackBerry::Platform::String& base64, std::vector<char>& binary, Base64DecodePolicy policy)
 {
     Vector<char> result;
-    if (!WTF::base64Decode(base64.c_str(), base64.length(), result, base64DecodePolicyForWTF(policy)))
+    if (!WTF::base64Decode(base64.c_str(), base64.length(), result, static_cast<WTF::Base64DecodePolicy>(policy)))
         return false;
 
     binary.insert(binary.begin(), result.begin(), result.end());
     return true;
 }
 
-WTF::Base64DecodePolicy base64EncodePolicyForWTF(Base64EncodePolicy policy)
-{
-    // FIXME: Base64InsertCRLF should be Base64InsertLFs. WTF::encodeBase64 doesn't insert CR.
-    COMPILE_ASSERT(WTF::Base64DoNotInsertLFs == static_cast<WTF::Base64EncodePolicy>(Base64DoNotInsertCRLF));
-    COMPILE_ASSERT(WTF::Base64InsertLFs == static_cast<WTF::Base64EncodePolicy>(Base64InsertCRLF));
-    return static_cast<WTF::Base64EncodePolicy>(policy);
-}
-
 bool base64Encode(const std::vector<char>& binary, BlackBerry::Platform::String& base64, Base64EncodePolicy policy)
 {
     Vector<char> result;
     result.append(&binary[0], binary.size());
 
-    WTF::base64Encode(&binary[0], binary.size(), result, base64EncodePolicyForWTF(policy));
+    WTF::base64Encode(&binary[0], binary.size(), result, static_cast<WTF::Base64EncodePolicy>(policy));
 
-    base64 = Blackberry::Platform::String(&result[0], result.size());
+    base64 = BlackBerry::Platform::String(&result[0], result.size());
 
     return true;
 }

Modified: trunk/Source/WebKit/blackberry/ChangeLog (143598 => 143599)


--- trunk/Source/WebKit/blackberry/ChangeLog	2013-02-21 14:57:41 UTC (rev 143598)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2013-02-21 15:33:24 UTC (rev 143599)
@@ -1,3 +1,18 @@
+2013-02-21  Carlos Garcia Campos  <[email protected]>
+
+        [BlackBerry] Invalid use of COMPILE_ASSERT macro in WebKitTextCodec.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=110437
+
+        Reviewed by Yong Li.
+
+        * Api/WebKitTextCodec.cpp:
+        (WebKit): Define COMPILE_ASSERT_MATCHING_ENUM() macro and use it to
+        check enum values match between WebKit and WTF.
+        (BlackBerry::WebKit::base64Decode): Use a static cast directly to
+        convert from WebKit Base64DecodePolicy to WTF.
+        (BlackBerry::WebKit::base64Encode): Use a static cast directly to
+        convert from WebKit Base64EncodePolicy to WTF.
+
 2013-02-21  Alberto Garcia  <[email protected]>
 
         [BlackBerry] Element::getAttributeItem() no longer returns a mutable attribute
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to