- Revision
- 210257
- Author
- [email protected]
- Date
- 2017-01-03 16:33:39 -0800 (Tue, 03 Jan 2017)
Log Message
Re-implement ExceptionOr on top of WTF::Expected
https://bugs.webkit.org/show_bug.cgi?id=166668
Patch by Sam Weinig <[email protected]> on 2017-01-03
Reviewed by Alex Christensen.
As a first step towards using WTF::Expected instead of ExceptionOr,
use Expected as an implementation detail, rather than Variant/std::optional.
* crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
* crypto/algorithms/CryptoAlgorithmHMAC.cpp:
* crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
* crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
Add missing #include of Variant.h
* dom/ExceptionOr.h:
(WebCore::ExceptionOr<ReturnType>::ExceptionOr):
(WebCore::ExceptionOr<ReturnType>::hasException):
(WebCore::ExceptionOr<ReturnType>::releaseException):
(WebCore::ExceptionOr<ReturnType>::releaseReturnValue):
(WebCore::ExceptionOr<void>::ExceptionOr):
(WebCore::ExceptionOr<void>::hasException):
(WebCore::ExceptionOr<void>::releaseException):
Re-implement on top of Expected.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (210256 => 210257)
--- trunk/Source/WebCore/ChangeLog 2017-01-04 00:26:45 UTC (rev 210256)
+++ trunk/Source/WebCore/ChangeLog 2017-01-04 00:33:39 UTC (rev 210257)
@@ -1,3 +1,30 @@
+2017-01-03 Sam Weinig <[email protected]>
+
+ Re-implement ExceptionOr on top of WTF::Expected
+ https://bugs.webkit.org/show_bug.cgi?id=166668
+
+ Reviewed by Alex Christensen.
+
+ As a first step towards using WTF::Expected instead of ExceptionOr,
+ use Expected as an implementation detail, rather than Variant/std::optional.
+
+ * crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
+ * crypto/algorithms/CryptoAlgorithmHMAC.cpp:
+ * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
+ * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
+ * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
+ Add missing #include of Variant.h
+
+ * dom/ExceptionOr.h:
+ (WebCore::ExceptionOr<ReturnType>::ExceptionOr):
+ (WebCore::ExceptionOr<ReturnType>::hasException):
+ (WebCore::ExceptionOr<ReturnType>::releaseException):
+ (WebCore::ExceptionOr<ReturnType>::releaseReturnValue):
+ (WebCore::ExceptionOr<void>::ExceptionOr):
+ (WebCore::ExceptionOr<void>::hasException):
+ (WebCore::ExceptionOr<void>::releaseException):
+ Re-implement on top of Expected.
+
2017-01-03 Chris Dumez <[email protected]>
Make setting Event's cancelBubble to false a no-op
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp (210256 => 210257)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp 2017-01-04 00:26:45 UTC (rev 210256)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp 2017-01-04 00:33:39 UTC (rev 210257)
@@ -33,6 +33,7 @@
#include "CryptoKeyAES.h"
#include "CryptoKeyDataOctetSequence.h"
#include "ExceptionCode.h"
+#include <wtf/Variant.h>
namespace WebCore {
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp (210256 => 210257)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp 2017-01-04 00:26:45 UTC (rev 210256)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp 2017-01-04 00:33:39 UTC (rev 210257)
@@ -34,6 +34,7 @@
#include "CryptoKeyDataOctetSequence.h"
#include "CryptoKeyHMAC.h"
#include "ExceptionCode.h"
+#include <wtf/Variant.h>
namespace WebCore {
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp (210256 => 210257)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp 2017-01-04 00:26:45 UTC (rev 210256)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp 2017-01-04 00:33:39 UTC (rev 210257)
@@ -35,6 +35,7 @@
#include "CryptoKeyPair.h"
#include "CryptoKeyRSA.h"
#include "ExceptionCode.h"
+#include <wtf/Variant.h>
namespace WebCore {
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp (210256 => 210257)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp 2017-01-04 00:26:45 UTC (rev 210256)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp 2017-01-04 00:33:39 UTC (rev 210257)
@@ -37,6 +37,7 @@
#include "CryptoKeyPair.h"
#include "CryptoKeyRSA.h"
#include "ExceptionCode.h"
+#include <wtf/Variant.h>
namespace WebCore {
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp (210256 => 210257)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp 2017-01-04 00:26:45 UTC (rev 210256)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp 2017-01-04 00:33:39 UTC (rev 210257)
@@ -37,6 +37,7 @@
#include "CryptoKeyPair.h"
#include "CryptoKeyRSA.h"
#include "ExceptionCode.h"
+#include <wtf/Variant.h>
namespace WebCore {
Modified: trunk/Source/WebCore/dom/ExceptionOr.h (210256 => 210257)
--- trunk/Source/WebCore/dom/ExceptionOr.h 2017-01-04 00:26:45 UTC (rev 210256)
+++ trunk/Source/WebCore/dom/ExceptionOr.h 2017-01-04 00:33:39 UTC (rev 210257)
@@ -27,8 +27,7 @@
#pragma once
#include "Exception.h"
-#include <wtf/Optional.h>
-#include <wtf/Variant.h>
+#include <wtf/Expected.h>
namespace WebCore {
@@ -43,7 +42,7 @@
ReturnType&& releaseReturnValue();
private:
- Variant<Exception, ReturnType> m_value;
+ Expected<ReturnType, Exception> m_value;
};
template<typename ReturnReferenceType> class ExceptionOr<ReturnReferenceType&> {
@@ -68,13 +67,13 @@
Exception&& releaseException();
private:
- std::optional<Exception> m_exception;
+ Expected<void, Exception> m_value;
};
ExceptionOr<void> isolatedCopy(ExceptionOr<void>&&);
template<typename ReturnType> inline ExceptionOr<ReturnType>::ExceptionOr(Exception&& exception)
- : m_value(WTFMove(exception))
+ : m_value(makeUnexpected(WTFMove(exception)))
{
}
@@ -90,17 +89,17 @@
template<typename ReturnType> inline bool ExceptionOr<ReturnType>::hasException() const
{
- return WTF::holds_alternative<Exception>(m_value);
+ return !m_value.hasValue();
}
template<typename ReturnType> inline Exception&& ExceptionOr<ReturnType>::releaseException()
{
- return WTF::get<Exception>(WTFMove(m_value));
+ return WTFMove(m_value.error());
}
template<typename ReturnType> inline ReturnType&& ExceptionOr<ReturnType>::releaseReturnValue()
{
- return WTF::get<ReturnType>(WTFMove(m_value));
+ return WTFMove(m_value.value());
}
template<typename ReturnReferenceType> inline ExceptionOr<ReturnReferenceType&>::ExceptionOr(Exception&& exception)
@@ -129,18 +128,18 @@
}
inline ExceptionOr<void>::ExceptionOr(Exception&& exception)
- : m_exception(WTFMove(exception))
+ : m_value(makeUnexpected(WTFMove(exception)))
{
}
inline bool ExceptionOr<void>::hasException() const
{
- return !!m_exception;
+ return !m_value.hasValue();
}
inline Exception&& ExceptionOr<void>::releaseException()
{
- return WTFMove(m_exception.value());
+ return WTFMove(m_value.error());
}
inline ExceptionOr<void> isolatedCopy(ExceptionOr<void>&& value)