Title: [170209] trunk/Source
Revision
170209
Author
[email protected]
Date
2014-06-20 14:36:36 -0700 (Fri, 20 Jun 2014)

Log Message

Add encoding and decoding support for WTF::Optional
https://bugs.webkit.org/show_bug.cgi?id=134125

Reviewed by Andreas Kling.

Source/WebKit2:
* Platform/IPC/ArgumentCoders.h:
(IPC::ArgumentCoder<WTF::Optional<T>>::encode):
(IPC::ArgumentCoder<WTF::Optional<T>>::decode):

Source/WTF:
* wtf/Optional.h:
(WTF::Optional::operator=):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (170208 => 170209)


--- trunk/Source/WTF/ChangeLog	2014-06-20 21:21:00 UTC (rev 170208)
+++ trunk/Source/WTF/ChangeLog	2014-06-20 21:36:36 UTC (rev 170209)
@@ -1,5 +1,15 @@
 2014-06-20  Anders Carlsson  <[email protected]>
 
+        Add encoding and decoding support for WTF::Optional
+        https://bugs.webkit.org/show_bug.cgi?id=134125
+
+        Reviewed by Andreas Kling.
+
+        * wtf/Optional.h:
+        (WTF::Optional::operator=):
+
+2014-06-20  Anders Carlsson  <[email protected]>
+
         Add copy/move constructors and assignment operators to WTF::Optional
         https://bugs.webkit.org/show_bug.cgi?id=134119
 

Modified: trunk/Source/WTF/wtf/Optional.h (170208 => 170209)


--- trunk/Source/WTF/wtf/Optional.h	2014-06-20 21:21:00 UTC (rev 170208)
+++ trunk/Source/WTF/wtf/Optional.h	2014-06-20 21:36:36 UTC (rev 170209)
@@ -91,6 +91,15 @@
             m_value.~T();
     }
 
+    Optional& operator=(NulloptTag)
+    {
+        if (m_isEngaged) {
+            m_value.~T();
+            m_isEngaged = false;
+        }
+        return *this;
+    }
+
     Optional& operator=(const Optional& other)
     {
         if (m_isEngaged == other.m_isEngaged) {

Modified: trunk/Source/WebKit2/ChangeLog (170208 => 170209)


--- trunk/Source/WebKit2/ChangeLog	2014-06-20 21:21:00 UTC (rev 170208)
+++ trunk/Source/WebKit2/ChangeLog	2014-06-20 21:36:36 UTC (rev 170209)
@@ -1,5 +1,16 @@
 2014-06-20  Anders Carlsson  <[email protected]>
 
+        Add encoding and decoding support for WTF::Optional
+        https://bugs.webkit.org/show_bug.cgi?id=134125
+
+        Reviewed by Andreas Kling.
+
+        * Platform/IPC/ArgumentCoders.h:
+        (IPC::ArgumentCoder<WTF::Optional<T>>::encode):
+        (IPC::ArgumentCoder<WTF::Optional<T>>::decode):
+
+2014-06-20  Anders Carlsson  <[email protected]>
+
         Give NPAPI post requests a default content type
         https://bugs.webkit.org/show_bug.cgi?id=134120
 

Modified: trunk/Source/WebKit2/Platform/IPC/ArgumentCoders.h (170208 => 170209)


--- trunk/Source/WebKit2/Platform/IPC/ArgumentCoders.h	2014-06-20 21:21:00 UTC (rev 170208)
+++ trunk/Source/WebKit2/Platform/IPC/ArgumentCoders.h	2014-06-20 21:36:36 UTC (rev 170209)
@@ -32,6 +32,7 @@
 #include <wtf/Forward.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
+#include <wtf/Optional.h>
 #include <wtf/Vector.h>
 
 namespace IPC {
@@ -49,6 +50,38 @@
     }
 };
 
+template<typename T> struct ArgumentCoder<WTF::Optional<T>> {
+    static void encode(ArgumentEncoder& encoder, const WTF::Optional<T>& optional)
+    {
+        if (!optional) {
+            encoder << false;
+            return;
+        }
+
+        encoder << true;
+        encoder << optional.value();
+    }
+
+    static bool decode(ArgumentDecoder& decoder, WTF::Optional<T>& optional)
+    {
+        bool isEngaged;
+        if (!decoder.decode(isEngaged))
+            return false;
+
+        if (!isEngaged) {
+            optional = Nullopt;
+            return true;
+        }
+
+        T value;
+        if (!decoder.decode(value))
+            return false;
+
+        optional = std::move(value);
+        return true;
+    }
+};
+
 template<typename T, typename U> struct ArgumentCoder<std::pair<T, U>> {
     static void encode(ArgumentEncoder& encoder, const std::pair<T, U>& pair)
     {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to