https://bugs.webkit.org/show_bug.cgi?id=175603
Patch by Youenn Fablet <youenn@apple.com> on 2017-08-17
Reviewed by Darin Adler.
No change of behavior.
Introduce DOMPromiseDeferred::settle to reject/resolve a promise with an ExceptionOr<>.
Making batchPutOperation/batchDeleteOperation take a Function with an ExceptionOr<>.
Using DOMPromiseDeferred::settle in Cache put/remove.
Updated CacheStorageConnection to create ExceptionOr<> from CacheStorageConnection::Error.
* Modules/cache/Cache.cpp:
(WebCore::Cache::put):
(WebCore::Cache::remove):
(WebCore::Cache::batchDeleteOperation):
(WebCore::Cache::batchPutOperation):
* Modules/cache/Cache.h:
* Modules/cache/CacheStorage.cpp:
(WebCore::CacheStorage::open):
(WebCore::CacheStorage::remove):
* Modules/cache/CacheStorageConnection.cpp:
(WebCore::CacheStorageConnection::errorToException):
* Modules/cache/CacheStorageConnection.h:
(WebCore::CacheStorageConnection::errorToException):
(WebCore::CacheStorageConnection::exceptionOrResult):
* bindings/js/JSDOMPromiseDeferred.h:
(WebCore::DOMPromiseDeferred::settle):
(WebCore::DOMPromiseDeferred<void>::settle):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220863
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2017-08-17 Youenn Fablet <youenn@apple.com>
+
+ Add a DOMPromiseDeferred method to handle ExceptionOr<> results
+ https://bugs.webkit.org/show_bug.cgi?id=175603
+
+ Reviewed by Darin Adler.
+
+ No change of behavior.
+
+ Introduce DOMPromiseDeferred::settle to reject/resolve a promise with an ExceptionOr<>.
+ Making batchPutOperation/batchDeleteOperation take a Function with an ExceptionOr<>.
+ Using DOMPromiseDeferred::settle in Cache put/remove.
+ Updated CacheStorageConnection to create ExceptionOr<> from CacheStorageConnection::Error.
+
+ * Modules/cache/Cache.cpp:
+ (WebCore::Cache::put):
+ (WebCore::Cache::remove):
+ (WebCore::Cache::batchDeleteOperation):
+ (WebCore::Cache::batchPutOperation):
+ * Modules/cache/Cache.h:
+ * Modules/cache/CacheStorage.cpp:
+ (WebCore::CacheStorage::open):
+ (WebCore::CacheStorage::remove):
+ * Modules/cache/CacheStorageConnection.cpp:
+ (WebCore::CacheStorageConnection::errorToException):
+ * Modules/cache/CacheStorageConnection.h:
+ (WebCore::CacheStorageConnection::errorToException):
+ (WebCore::CacheStorageConnection::exceptionOrResult):
+ * bindings/js/JSDOMPromiseDeferred.h:
+ (WebCore::DOMPromiseDeferred::settle):
+ (WebCore::DOMPromiseDeferred<void>::settle):
+
2017-08-17 Zan Dobersek <zdobersek@igalia.com>
[GStreamer] AppendPipeline: support dispatch of decryption-specific GstStructure into the pipeline
return;
}
- batchPutOperation(*request, response.get(), [promise = WTFMove(promise)](CacheStorageConnection::Error error) mutable {
- if (error != CacheStorageConnection::Error::None) {
- promise.reject(CacheStorageConnection::exceptionFromError(error));
- return;
- }
- promise.resolve();
+ batchPutOperation(*request, response.get(), [promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable {
+ promise.settle(WTFMove(result));
});
}
request = FetchRequest::create(*scriptExecutionContext(), WTFMove(info), { }).releaseReturnValue();
}
- batchDeleteOperation(*request, WTFMove(options), [promise = WTFMove(promise)](bool didDelete, CacheStorageConnection::Error error) mutable {
- if (error != CacheStorageConnection::Error::None) {
- promise.reject(CacheStorageConnection::exceptionFromError(error));
- return;
- }
- promise.resolve(didDelete);
+ batchDeleteOperation(*request, WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<bool>&& result) mutable {
+ promise.settle(WTFMove(result));
});
}
return records;
}
-void Cache::batchDeleteOperation(const FetchRequest& request, CacheQueryOptions&& options, WTF::Function<void(bool didRemoval, CacheStorageConnection::Error error)>&& callback)
+void Cache::batchDeleteOperation(const FetchRequest& request, CacheQueryOptions&& options, WTF::Function<void(ExceptionOr<bool>&&)>&& callback)
{
setPendingActivity(this);
m_connection->batchDeleteOperation(m_identifier, request.internalRequest(), WTFMove(options), [this, callback = WTFMove(callback)](Vector<uint64_t>&& records, CacheStorageConnection::Error error) {
- if (!m_isStopped) {
- if (error == CacheStorageConnection::Error::None)
- m_records.removeAllMatching([&](const auto& item) { return records.contains(item.identifier); });
+ if (!m_isStopped)
+ callback(CacheStorageConnection::exceptionOrResult(!records.isEmpty(), error));
- callback(!records.isEmpty(), error);
- }
unsetPendingActivity(this);
});
}
};
}
-void Cache::batchPutOperation(const FetchRequest& request, FetchResponse& response, WTF::Function<void(CacheStorageConnection::Error)>&& callback)
+void Cache::batchPutOperation(const FetchRequest& request, FetchResponse& response, WTF::Function<void(ExceptionOr<void>&&)>&& callback)
{
Vector<CacheStorageConnection::Record> records;
records.append(toConnectionRecord(request, response));
setPendingActivity(this);
m_connection->batchPutOperation(m_identifier, WTFMove(records), [this, callback = WTFMove(callback)](Vector<uint64_t>&&, CacheStorageConnection::Error error) {
if (!m_isStopped)
- callback(error);
+ callback(CacheStorageConnection::errorToException(error));
unsetPendingActivity(this);
});
void retrieveRecords(WTF::Function<void()>&&);
Vector<CacheStorageRecord> queryCacheWithTargetStorage(const FetchRequest&, const CacheQueryOptions&, const Vector<CacheStorageRecord>&);
void queryCache(Ref<FetchRequest>&&, CacheQueryOptions&&, WTF::Function<void(const Vector<CacheStorageRecord>&)>&&);
- void batchDeleteOperation(const FetchRequest&, CacheQueryOptions&&, WTF::Function<void(bool didRemoval, CacheStorageConnection::Error)>&&);
- void batchPutOperation(const FetchRequest&, FetchResponse&, WTF::Function<void(CacheStorageConnection::Error)>&&);
+ void batchDeleteOperation(const FetchRequest&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<bool>&&)>&&);
+ void batchPutOperation(const FetchRequest&, FetchResponse&, WTF::Function<void(ExceptionOr<void>&&)>&&);
void updateRecords(Vector<CacheStorageConnection::Record>&&);
setPendingActivity(this);
m_connection->open(origin, name, [this, name, promise = WTFMove(promise)](uint64_t cacheIdentifier, CacheStorageConnection::Error error) mutable {
if (!m_isStopped) {
- if (error != CacheStorageConnection::Error::None)
- promise.reject(CacheStorageConnection::exceptionFromError(error));
+ auto result = CacheStorageConnection::errorToException(error);
+ if (result.hasException())
+ promise.reject(result.releaseException());
else {
auto cache = Cache::create(*scriptExecutionContext(), String { name }, cacheIdentifier, m_connection.copyRef());
promise.resolve(cache);
setPendingActivity(this);
m_connection->remove(m_caches[position]->identifier(), [this, name, promise = WTFMove(promise)](uint64_t cacheIdentifier, CacheStorageConnection::Error error) mutable {
UNUSED_PARAM(cacheIdentifier);
- if (!m_isStopped) {
- if (error != CacheStorageConnection::Error::None)
- promise.reject(CacheStorageConnection::exceptionFromError(error));
- else
- promise.resolve(true);
- }
+ if (!m_isStopped)
+ promise.settle(CacheStorageConnection::exceptionOrResult(true, error));
+
unsetPendingActivity(this);
});
m_caches.remove(position);
namespace WebCore {
-Exception CacheStorageConnection::exceptionFromError(Error error)
+ExceptionOr<void> CacheStorageConnection::errorToException(Error error)
{
- ASSERT(error != Error::None);
-
- switch (error) {
- case Error::NotImplemented:
+ if (error == Error::NotImplemented)
return Exception { NotSupportedError, ASCIILiteral("Not implemented") };
- default:
- return Exception { TypeError, ASCIILiteral("Unknown error") };
- };
+
+ return { };
}
bool CacheStorageConnection::queryCacheMatch(const ResourceRequest& request, const ResourceRequest& cachedRequest, const ResourceResponse& cachedResponse, const CacheQueryOptions& options)
NotImplemented,
};
- WEBCORE_EXPORT static bool queryCacheMatch(const ResourceRequest& request, const ResourceRequest& cachedRequest, const ResourceResponse&, const CacheQueryOptions&);
+ static ExceptionOr<void> errorToException(Error);
+ template<typename T> static ExceptionOr<T> exceptionOrResult(T&& value, Error error)
+ {
+ auto result = errorToException(error);
+ if (result.hasException())
+ return result.releaseException();
+ return std::forward<T>(value);
+ }
- static Exception exceptionFromError(Error);
+ WEBCORE_EXPORT static bool queryCacheMatch(const ResourceRequest& request, const ResourceRequest& cachedRequest, const ResourceResponse&, const CacheQueryOptions&);
struct Record {
uint64_t identifier;
#pragma once
+#include "ExceptionOr.h"
#include "JSDOMConvert.h"
#include "JSDOMGuardedObject.h"
#include <runtime/CatchScope.h>
{
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 {
{
m_promiseDeferred->resolve();
}
+
+ void settle(ExceptionOr<void>&& result)
+ {
+ if (result.hasException()) {
+ reject(result.releaseException());
+ return;
+ }
+ resolve();
+ }
};