Diff
Modified: trunk/Source/WebCore/ChangeLog (221482 => 221483)
--- trunk/Source/WebCore/ChangeLog 2017-09-01 17:53:40 UTC (rev 221482)
+++ trunk/Source/WebCore/ChangeLog 2017-09-01 18:16:16 UTC (rev 221483)
@@ -1,3 +1,30 @@
+2017-09-01 Youenn Fablet <[email protected]>
+
+ Reject promises in case of internal CacheStorage engine errors.
+ https://bugs.webkit.org/show_bug.cgi?id=176194
+
+ Reviewed by Alex Christensen.
+
+ No new tests as this covers error cases that should not happen in regular cases.
+ Replacing lambdas that take no parameters to lambdas taking an optional error.
+ Reject promise if an error is found.
+
+ * Modules/cache/Cache.cpp:
+ (WebCore::Cache::doMatch):
+ (WebCore::Cache::matchAll):
+ (WebCore::Cache::keys):
+ (WebCore::Cache::retrieveRecords):
+ (WebCore::Cache::queryCache):
+ * Modules/cache/Cache.h:
+ * Modules/cache/CacheStorage.cpp:
+ (WebCore::CacheStorage::match):
+ (WebCore::CacheStorage::has):
+ (WebCore::CacheStorage::retrieveCaches):
+ (WebCore::CacheStorage::open):
+ (WebCore::CacheStorage::remove):
+ (WebCore::CacheStorage::keys):
+ * Modules/cache/CacheStorage.h:
+
2017-09-01 Zan Dobersek <[email protected]>
Unreviewed WPE build fix after r221439.
Modified: trunk/Source/WebCore/Modules/cache/Cache.cpp (221482 => 221483)
--- trunk/Source/WebCore/Modules/cache/Cache.cpp 2017-09-01 17:53:40 UTC (rev 221482)
+++ trunk/Source/WebCore/Modules/cache/Cache.cpp 2017-09-01 18:16:16 UTC (rev 221483)
@@ -55,12 +55,16 @@
void Cache::match(RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
{
- doMatch(WTFMove(info), WTFMove(options), [promise = WTFMove(promise)](FetchResponse* result) mutable {
- if (!result) {
+ doMatch(WTFMove(info), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<FetchResponse*>&& result) mutable {
+ if (result.hasException()) {
+ promise->reject(result.releaseException());
+ return;
+ }
+ if (!result.returnValue()) {
promise->resolve();
return;
}
- promise->resolve<IDLInterface<FetchResponse>>(*result);
+ promise->resolve<IDLInterface<FetchResponse>>(*result.returnValue());
});
}
@@ -76,12 +80,16 @@
}
auto request = requestOrException.releaseReturnValue();
- queryCache(request.get(), WTFMove(options), [callback = WTFMove(callback)](const Vector<CacheStorageRecord>& records) mutable {
- if (records.isEmpty()) {
+ queryCache(request.get(), WTFMove(options), [callback = WTFMove(callback)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable {
+ if (result.hasException()) {
+ callback(result.releaseException());
+ return;
+ }
+ if (result.returnValue().isEmpty()) {
callback(nullptr);
return;
}
- callback(records[0].response->cloneForJS().ptr());
+ callback(result.returnValue()[0].response->cloneForJS().ptr());
});
}
@@ -101,7 +109,11 @@
}
if (!request) {
- retrieveRecords([this, promise = WTFMove(promise)]() mutable {
+ retrieveRecords([this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ promise.reject(WTFMove(exception.value()));
+ return;
+ }
Vector<Ref<FetchResponse>> responses;
responses.reserveInitialCapacity(m_records.size());
for (auto& record : m_records)
@@ -110,7 +122,12 @@
});
return;
}
- queryCache(request.releaseNonNull(), WTFMove(options), [promise = WTFMove(promise)](const Vector<CacheStorageRecord>& records) mutable {
+ queryCache(request.releaseNonNull(), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable {
+ if (result.hasException()) {
+ promise.reject(result.releaseException());
+ return;
+ }
+ auto records = result.releaseReturnValue();
Vector<Ref<FetchResponse>> responses;
responses.reserveInitialCapacity(records.size());
for (auto& record : records)
@@ -361,7 +378,11 @@
}
if (!request) {
- retrieveRecords([this, promise = WTFMove(promise)]() mutable {
+ retrieveRecords([this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ promise.reject(WTFMove(exception.value()));
+ return;
+ }
Vector<Ref<FetchRequest>> requests;
requests.reserveInitialCapacity(m_records.size());
for (auto& record : m_records)
@@ -371,7 +392,13 @@
return;
}
- queryCache(request.releaseNonNull(), WTFMove(options), [promise = WTFMove(promise)](const Vector<CacheStorageRecord>& records) mutable {
+ queryCache(request.releaseNonNull(), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable {
+ if (result.hasException()) {
+ promise.reject(result.releaseException());
+ return;
+ }
+
+ auto records = result.releaseReturnValue();
Vector<Ref<FetchRequest>> requests;
requests.reserveInitialCapacity(records.size());
for (auto& record : records)
@@ -380,24 +407,31 @@
});
}
-void Cache::retrieveRecords(WTF::Function<void()>&& callback)
+void Cache::retrieveRecords(WTF::Function<void(std::optional<Exception>&&)>&& callback)
{
setPendingActivity(this);
m_connection->retrieveRecords(m_identifier, [this, callback = WTFMove(callback)](RecordsOrError&& result) {
if (!m_isStopped) {
- // FIXME: We should probably propagate that error up to the promise based operation.
- ASSERT(result.hasValue());
+ if (!result.hasValue()) {
+ callback(DOMCacheEngine::errorToException(result.error()));
+ return;
+ }
+
if (result.hasValue())
updateRecords(WTFMove(result.value()));
- callback();
+ callback(std::nullopt);
}
unsetPendingActivity(this);
});
}
-void Cache::queryCache(Ref<FetchRequest>&& request, CacheQueryOptions&& options, WTF::Function<void(const Vector<CacheStorageRecord>&)>&& callback)
+void Cache::queryCache(Ref<FetchRequest>&& request, CacheQueryOptions&& options, WTF::Function<void(ExceptionOr<Vector<CacheStorageRecord>>&&)>&& callback)
{
- retrieveRecords([this, request = WTFMove(request), options = WTFMove(options), callback = WTFMove(callback)]() mutable {
+ retrieveRecords([this, request = WTFMove(request), options = WTFMove(options), callback = WTFMove(callback)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ callback(WTFMove(exception.value()));
+ return;
+ }
callback(queryCacheWithTargetStorage(request.get(), options, m_records));
});
}
Modified: trunk/Source/WebCore/Modules/cache/Cache.h (221482 => 221483)
--- trunk/Source/WebCore/Modules/cache/Cache.h 2017-09-01 17:53:40 UTC (rev 221482)
+++ trunk/Source/WebCore/Modules/cache/Cache.h 2017-09-01 18:16:16 UTC (rev 221483)
@@ -56,7 +56,7 @@
const String& name() const { return m_name; }
uint64_t identifier() const { return m_identifier; }
- using MatchCallback = WTF::Function<void(FetchResponse*)>;
+ using MatchCallback = WTF::Function<void(ExceptionOr<FetchResponse*>)>;
void doMatch(RequestInfo&&, CacheQueryOptions&&, MatchCallback&&);
private:
@@ -69,9 +69,9 @@
const char* activeDOMObjectName() const final;
bool canSuspendForDocumentSuspension() const final;
- void retrieveRecords(WTF::Function<void()>&&);
+ void retrieveRecords(WTF::Function<void(std::optional<Exception>&&)>&&);
Vector<CacheStorageRecord> queryCacheWithTargetStorage(const FetchRequest&, const CacheQueryOptions&, const Vector<CacheStorageRecord>&);
- void queryCache(Ref<FetchRequest>&&, CacheQueryOptions&&, WTF::Function<void(const Vector<CacheStorageRecord>&)>&&);
+ void queryCache(Ref<FetchRequest>&&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<Vector<CacheStorageRecord>>&&)>&&);
void batchDeleteOperation(const FetchRequest&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<bool>&&)>&&);
void batchPutOperation(const FetchRequest&, FetchResponse&, DOMCacheEngine::ResponseBody&&, WTF::Function<void(ExceptionOr<void>&&)>&&);
void batchPutOperation(Vector<DOMCacheEngine::Record>&&, WTF::Function<void(ExceptionOr<void>&&)>&&);
Modified: trunk/Source/WebCore/Modules/cache/CacheStorage.cpp (221482 => 221483)
--- trunk/Source/WebCore/Modules/cache/CacheStorage.cpp 2017-09-01 17:53:40 UTC (rev 221482)
+++ trunk/Source/WebCore/Modules/cache/CacheStorage.cpp 2017-09-01 18:16:16 UTC (rev 221483)
@@ -56,11 +56,15 @@
return;
}
- caches[index]->doMatch(WTFMove(info), WTFMove(options), [caches = WTFMove(caches), info, options, completionHandler = WTFMove(completionHandler), index](FetchResponse* value) mutable {
- if (value) {
- completionHandler(value);
+ caches[index]->doMatch(WTFMove(info), WTFMove(options), [caches = WTFMove(caches), info, options, completionHandler = WTFMove(completionHandler), index](ExceptionOr<FetchResponse*>&& result) mutable {
+ if (result.hasException()) {
+ completionHandler(result.releaseException());
return;
}
+ if (result.returnValue()) {
+ completionHandler(result.returnValue());
+ return;
+ }
doSequentialMatch(++index, WTFMove(caches), WTFMove(info), WTFMove(options), WTFMove(completionHandler));
});
}
@@ -81,7 +85,12 @@
void CacheStorage::match(Cache::RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
{
- retrieveCaches([this, info = WTFMove(info), options = WTFMove(options), promise = WTFMove(promise)]() mutable {
+ retrieveCaches([this, info = WTFMove(info), options = WTFMove(options), promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ promise->reject(WTFMove(exception.value()));
+ return;
+ }
+
if (!options.cacheName.isNull()) {
auto position = m_caches.findMatching([&](auto& item) { return item->name() == options.cacheName; });
if (position != notFound) {
@@ -93,12 +102,16 @@
}
setPendingActivity(this);
- startSequentialMatch(copyCaches(m_caches), WTFMove(info), WTFMove(options), [this, promise = WTFMove(promise)](FetchResponse* result) mutable {
+ startSequentialMatch(copyCaches(m_caches), WTFMove(info), WTFMove(options), [this, promise = WTFMove(promise)](ExceptionOr<FetchResponse*>&& result) mutable {
if (!m_isStopped) {
- if (!result)
+ if (result.hasException()) {
+ promise->reject(result.releaseException());
+ return;
+ }
+ if (!result.returnValue())
promise->resolve();
else
- promise->resolve<IDLInterface<FetchResponse>>(*result);
+ promise->resolve<IDLInterface<FetchResponse>>(*result.returnValue());
}
unsetPendingActivity(this);
});
@@ -107,12 +120,16 @@
void CacheStorage::has(const String& name, DOMPromiseDeferred<IDLBoolean>&& promise)
{
- retrieveCaches([this, name, promise = WTFMove(promise)]() mutable {
+ retrieveCaches([this, name, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ promise.reject(WTFMove(exception.value()));
+ return;
+ }
promise.resolve(m_caches.findMatching([&](auto& item) { return item->name() == name; }) != notFound);
});
}
-void CacheStorage::retrieveCaches(WTF::Function<void()>&& callback)
+void CacheStorage::retrieveCaches(WTF::Function<void(std::optional<Exception>&&)>&& callback)
{
String origin = this->origin();
if (origin.isNull())
@@ -119,12 +136,10 @@
return;
setPendingActivity(this);
- m_connection->retrieveCaches(origin, m_updateCounter, [this, callback = WTFMove(callback)](CacheInfosOrError&& result) {
+ m_connection->retrieveCaches(origin, m_updateCounter, [this, callback = WTFMove(callback)](CacheInfosOrError&& result) mutable {
if (!m_isStopped) {
- // FIXME: We should probably propagate that error up to the promise based operation.
- ASSERT(result.hasValue());
if (!result.hasValue()) {
- callback();
+ callback(DOMCacheEngine::errorToException(result.error()));
return;
}
@@ -144,7 +159,7 @@
m_caches = WTFMove(caches);
}
- callback();
+ callback(std::nullopt);
}
unsetPendingActivity(this);
});
@@ -152,7 +167,12 @@
void CacheStorage::open(const String& name, DOMPromiseDeferred<IDLInterface<Cache>>&& promise)
{
- retrieveCaches([this, name, promise = WTFMove(promise)]() mutable {
+ retrieveCaches([this, name, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ promise.reject(WTFMove(exception.value()));
+ return;
+ }
+
auto position = m_caches.findMatching([&](auto& item) { return item->name() == name; });
if (position != notFound) {
auto& cache = m_caches[position];
@@ -166,7 +186,6 @@
setPendingActivity(this);
m_connection->open(origin, name, [this, name, promise = WTFMove(promise)](const CacheIdentifierOrError& result) mutable {
if (!m_isStopped) {
-
if (!result.hasValue())
promise.reject(DOMCacheEngine::errorToException(result.error()));
else {
@@ -182,7 +201,12 @@
void CacheStorage::remove(const String& name, DOMPromiseDeferred<IDLBoolean>&& promise)
{
- retrieveCaches([this, name, promise = WTFMove(promise)]() mutable {
+ retrieveCaches([this, name, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ promise.reject(WTFMove(exception.value()));
+ return;
+ }
+
auto position = m_caches.findMatching([&](auto& item) { return item->name() == name; });
if (position == notFound) {
promise.resolve(false);
@@ -208,7 +232,12 @@
void CacheStorage::keys(KeysPromise&& promise)
{
- retrieveCaches([this, promise = WTFMove(promise)]() mutable {
+ retrieveCaches([this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ promise.reject(WTFMove(exception.value()));
+ return;
+ }
+
Vector<String> keys;
keys.reserveInitialCapacity(m_caches.size());
for (auto& cache : m_caches)
Modified: trunk/Source/WebCore/Modules/cache/CacheStorage.h (221482 => 221483)
--- trunk/Source/WebCore/Modules/cache/CacheStorage.h 2017-09-01 17:53:40 UTC (rev 221482)
+++ trunk/Source/WebCore/Modules/cache/CacheStorage.h 2017-09-01 18:16:16 UTC (rev 221483)
@@ -52,7 +52,7 @@
const char* activeDOMObjectName() const final;
bool canSuspendForDocumentSuspension() const final;
- void retrieveCaches(WTF::Function<void()>&&);
+ void retrieveCaches(WTF::Function<void(std::optional<Exception>&&)>&&);
String origin() const;
Vector<Ref<Cache>> m_caches;