Add a DOMPromiseDeferred method to handle ExceptionOr<> results
[WebKit-https.git] / Source / WebCore / bindings / js / JSDOMPromiseDeferred.h
index 36996cd705c03ed87ecf527c44e2bc263817b5eb..fb6cdf538b80bbf7f47d4cea24c95bbfc4fe8a3f 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
 
 #pragma once
 
+#include "ExceptionOr.h"
 #include "JSDOMConvert.h"
 #include "JSDOMGuardedObject.h"
 #include <runtime/CatchScope.h>
 #include "JSDOMConvert.h"
 #include "JSDOMGuardedObject.h"
 #include <runtime/CatchScope.h>
@@ -211,6 +212,15 @@ public:
     { 
         m_promiseDeferred->resolve<IDLType>(std::forward<typename IDLType::ParameterType>(value));
     }
     { 
         m_promiseDeferred->resolve<IDLType>(std::forward<typename IDLType::ParameterType>(value));
     }
+
+    void settle(ExceptionOr<typename IDLType::ParameterType>&& result)
+    {
+        if (result.hasException()) {
+            reject(result.releaseException());
+            return;
+        }
+        resolve(result.releaseReturnValue());
+    }
 };
 
 template<> class DOMPromiseDeferred<void> : public DOMPromiseDeferredBase {
 };
 
 template<> class DOMPromiseDeferred<void> : public DOMPromiseDeferredBase {
@@ -224,6 +234,15 @@ public:
     { 
         m_promiseDeferred->resolve();
     }
     { 
         m_promiseDeferred->resolve();
     }
+
+    void settle(ExceptionOr<void>&& result)
+    {
+        if (result.hasException()) {
+            reject(result.releaseException());
+            return;
+        }
+        resolve();
+    }
 };
 
 
 };