Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: Source/modules/serviceworkers/Cache.cpp

Issue 521513002: Service Worker: Simplify rejection code in Cache implementation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/serviceworkers/Cache.h ('k') | Source/modules/serviceworkers/Cache.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/serviceworkers/Cache.cpp
diff --git a/Source/modules/serviceworkers/Cache.cpp b/Source/modules/serviceworkers/Cache.cpp
index 0febcd26576b300fa3a8bf264ef1887ca17e94a1..92b562954805c5581f8606fbb1cc840e8cd60dd7 100644
--- a/Source/modules/serviceworkers/Cache.cpp
+++ b/Source/modules/serviceworkers/Cache.cpp
@@ -6,9 +6,9 @@
#include "modules/serviceworkers/Cache.h"
#include "bindings/core/v8/Dictionary.h"
+#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptState.h"
-#include "bindings/core/v8/V8ThrowException.h"
#include "core/dom/DOMException.h"
#include "modules/serviceworkers/Request.h"
#include "modules/serviceworkers/Response.h"
@@ -114,12 +114,10 @@ private:
RefPtr<ScriptPromiseResolver> m_resolver;
};
-ScriptPromise rejectAsNotImplemented(ScriptState* scriptState)
+ScriptPromise rejectAsNotImplemented(ExceptionState& exceptionState)
{
- RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
- const ScriptPromise promise = resolver->promise();
- resolver->reject(DOMException::create(NotSupportedError, "Cache is not implemented"));
- return promise;
+ exceptionState.throwDOMException(NotSupportedError, "Cache is not implemented");
+ return ScriptPromise();
}
} // namespace
@@ -135,143 +133,109 @@ Cache::~Cache()
{
}
-ScriptPromise Cache::match(ScriptState* scriptState, Request* originalRequest, const Dictionary& queryParamsDict)
+ScriptPromise Cache::match(ScriptState* scriptState, Request* originalRequest, const Dictionary& queryParamsDict, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), originalRequest, exceptionState);
if (exceptionState.hadException())
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- // return ScriptPromise::reject(DOMException::create(NotFoundError, "The specified Service Worker resource was not found."));
+ return ScriptPromise();
return matchImpl(scriptState, request, queryParamsDict);
}
-ScriptPromise Cache::match(ScriptState* scriptState, const String& requestString, const Dictionary& queryParamsDict)
+ScriptPromise Cache::match(ScriptState* scriptState, const String& requestString, const Dictionary& queryParamsDict, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), requestString, exceptionState);
if (exceptionState.hadException())
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- // return ScriptPromise::reject(DOMException::create(NotFoundError, "The specified Service Worker resource was not found."));
+ return ScriptPromise();
return matchImpl(scriptState, request, queryParamsDict);
}
-ScriptPromise Cache::matchAll(ScriptState* scriptState, Request* originalRequest, const Dictionary& queryParamsDict)
+ScriptPromise Cache::matchAll(ScriptState* scriptState, Request* originalRequest, const Dictionary& queryParamsDict, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), originalRequest, exceptionState);
- if (exceptionState.hadException()) {
- // FIXME: We should throw the caught error.
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- }
+ if (exceptionState.hadException())
+ return ScriptPromise();
return matchAllImpl(scriptState, request, queryParamsDict);
}
-ScriptPromise Cache::matchAll(ScriptState* scriptState, const String& requestString, const Dictionary& queryParamsDict)
+ScriptPromise Cache::matchAll(ScriptState* scriptState, const String& requestString, const Dictionary& queryParamsDict, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), requestString, exceptionState);
- if (exceptionState.hadException()) {
- // FIXME: We should throw the caught error.
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- }
+ if (exceptionState.hadException())
+ return ScriptPromise();
return matchAllImpl(scriptState, request, queryParamsDict);
}
-ScriptPromise Cache::add(ScriptState* scriptState, Request* originalRequest)
+ScriptPromise Cache::add(ScriptState* scriptState, Request* originalRequest, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), originalRequest, exceptionState);
- if (exceptionState.hadException()) {
- // FIXME: We should throw the caught error.
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- }
- return addImpl(scriptState, request);
+ if (exceptionState.hadException())
+ return ScriptPromise();
+ return addImpl(scriptState, request, exceptionState);
}
-ScriptPromise Cache::add(ScriptState* scriptState, const String& requestString)
+ScriptPromise Cache::add(ScriptState* scriptState, const String& requestString, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), requestString, exceptionState);
- if (exceptionState.hadException()) {
- // FIXME: We should throw the caught error.
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- }
- return addImpl(scriptState, request);
+ if (exceptionState.hadException())
+ return ScriptPromise();
+ return addImpl(scriptState, request, exceptionState);
}
-ScriptPromise Cache::addAll(ScriptState* scriptState, const Vector<ScriptValue>& rawRequests)
+ScriptPromise Cache::addAll(ScriptState* scriptState, const Vector<ScriptValue>& rawRequests, ExceptionState& exceptionState)
{
- return rejectAsNotImplemented(scriptState);
+ return rejectAsNotImplemented(exceptionState);
}
-ScriptPromise Cache::deleteFunction(ScriptState* scriptState, Request* originalRequest, const Dictionary& queryParamsDict)
+ScriptPromise Cache::deleteFunction(ScriptState* scriptState, Request* originalRequest, const Dictionary& queryParamsDict, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), originalRequest, exceptionState);
- if (exceptionState.hadException()) {
- // FIXME: We should throw the caught error.
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- }
+ if (exceptionState.hadException())
+ return ScriptPromise();
return deleteImpl(scriptState, request, queryParamsDict);
}
-ScriptPromise Cache::deleteFunction(ScriptState* scriptState, const String& requestString, const Dictionary& queryParamsDict)
+ScriptPromise Cache::deleteFunction(ScriptState* scriptState, const String& requestString, const Dictionary& queryParamsDict, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), requestString, exceptionState);
- if (exceptionState.hadException()) {
- // FIXME: We should throw the caught error.
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- }
+ if (exceptionState.hadException())
+ return ScriptPromise();
return deleteImpl(scriptState, request, queryParamsDict);
}
-ScriptPromise Cache::put(ScriptState* scriptState, Request* originalRequest, Response* response)
+ScriptPromise Cache::put(ScriptState* scriptState, Request* originalRequest, Response* response, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), originalRequest, exceptionState);
- if (exceptionState.hadException()) {
- // FIXME: We should throw the caught error.
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- }
+ if (exceptionState.hadException())
+ return ScriptPromise();
return putImpl(scriptState, request, response);
}
-ScriptPromise Cache::put(ScriptState* scriptState, const String& requestString, Response* response)
+ScriptPromise Cache::put(ScriptState* scriptState, const String& requestString, Response* response, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), requestString, exceptionState);
- if (exceptionState.hadException()) {
- // FIXME: We should throw the caught error.
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- }
+ if (exceptionState.hadException())
+ return ScriptPromise();
return putImpl(scriptState, request, response);
}
-ScriptPromise Cache::keys(ScriptState* scriptState)
+ScriptPromise Cache::keys(ScriptState* scriptState, ExceptionState& exceptionState)
{
return keysImpl(scriptState, RefPtrWillBeRawPtr<Request>(), Dictionary());
}
-ScriptPromise Cache::keys(ScriptState* scriptState, Request* originalRequest, const Dictionary& queryParamsDict)
+ScriptPromise Cache::keys(ScriptState* scriptState, Request* originalRequest, const Dictionary& queryParamsDict, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), originalRequest, exceptionState);
- if (exceptionState.hadException()) {
- // FIXME: We should throw the caught error.
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- }
+ if (exceptionState.hadException())
+ return ScriptPromise();
return keysImpl(scriptState);
}
-ScriptPromise Cache::keys(ScriptState* scriptState, const String& requestString, const Dictionary& queryParamsDict)
+ScriptPromise Cache::keys(ScriptState* scriptState, const String& requestString, const Dictionary& queryParamsDict, ExceptionState& exceptionState)
{
- TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<Request> request = Request::create(scriptState->executionContext(), requestString, exceptionState);
- if (exceptionState.hadException()) {
- // FIXME: We should throw the caught error.
- return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(exceptionState.message(), scriptState->isolate()));
- }
+ if (exceptionState.hadException())
+ return ScriptPromise();
return keysImpl(scriptState, request, queryParamsDict);
}
@@ -309,14 +273,14 @@ ScriptPromise Cache::matchAllImpl(ScriptState* scriptState, PassRefPtrWillBeRawP
return promise;
}
-ScriptPromise Cache::addImpl(ScriptState* scriptState, PassRefPtrWillBeRawPtr<Request>)
+ScriptPromise Cache::addImpl(ScriptState* scriptState, PassRefPtrWillBeRawPtr<Request>, ExceptionState& exceptionState)
{
- return rejectAsNotImplemented(scriptState);
+ return rejectAsNotImplemented(exceptionState);
}
-ScriptPromise Cache::addAllImpl(ScriptState* scriptState, Vector<RefPtrWillBeRawPtr<Request> >)
+ScriptPromise Cache::addAllImpl(ScriptState* scriptState, Vector<RefPtrWillBeRawPtr<Request> >, ExceptionState& exceptionState)
{
- return rejectAsNotImplemented(scriptState);
+ return rejectAsNotImplemented(exceptionState);
}
PassRefPtrWillBeRawPtr<DOMException> Cache::domExceptionForCacheError(WebServiceWorkerCacheError reason)
« no previous file with comments | « Source/modules/serviceworkers/Cache.h ('k') | Source/modules/serviceworkers/Cache.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698