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

Unified Diff: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerError.cpp

Issue 2054203002: service worker: Fix the type of an update promise reject value (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: FIXME => TODO Created 4 years, 5 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
Index: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerError.cpp
diff --git a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerError.cpp b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerError.cpp
index 4a37638130145923ce250a1cc8d45c88971d5fdf..ea8ea6cfb6bcb0ffd7c7a147c93fb3acd5ba44d5 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerError.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerError.cpp
@@ -30,6 +30,8 @@
#include "modules/serviceworkers/ServiceWorkerError.h"
+#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "bindings/core/v8/ToV8.h"
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
@@ -37,49 +39,81 @@ using blink::WebServiceWorkerError;
namespace blink {
-static DOMException* createException(ExceptionCode code, const String& defaultMessage, const String& message)
-{
- return DOMException::create(code, message.isEmpty() ? defaultMessage : message);
-}
+namespace {
-// static
-DOMException* ServiceWorkerError::take(ScriptPromiseResolver*, const WebServiceWorkerError& webError)
+struct ExceptionParams {
+ ExceptionParams(ExceptionCode code, const String& defaultMessage = String(), const String& message = String())
+ : code(code), message(message.isEmpty() ? defaultMessage : message) {}
+
+ ExceptionCode code;
+ String message;
+};
+
+ExceptionParams getExceptionParams(const WebServiceWorkerError& webError)
{
switch (webError.errorType) {
case WebServiceWorkerError::ErrorTypeAbort:
- return createException(AbortError, "The Service Worker operation was aborted.", webError.message);
+ return ExceptionParams(AbortError, "The Service Worker operation was aborted.", webError.message);
case WebServiceWorkerError::ErrorTypeActivate:
// Not currently returned as a promise rejection.
- // FIXME: Introduce new ActivateError type to ExceptionCodes?
- return createException(AbortError, "The Service Worker activation failed.", webError.message);
+ // TODO: Introduce new ActivateError type to ExceptionCodes?
+ return ExceptionParams(AbortError, "The Service Worker activation failed.", webError.message);
case WebServiceWorkerError::ErrorTypeDisabled:
- return createException(NotSupportedError, "Service Worker support is disabled.", webError.message);
+ return ExceptionParams(NotSupportedError, "Service Worker support is disabled.", webError.message);
case WebServiceWorkerError::ErrorTypeInstall:
- // FIXME: Introduce new InstallError type to ExceptionCodes?
- return createException(AbortError, "The Service Worker installation failed.", webError.message);
+ // TODO: Introduce new InstallError type to ExceptionCodes?
+ return ExceptionParams(AbortError, "The Service Worker installation failed.", webError.message);
+ case WebServiceWorkerError::ErrorTypeScriptEvaluateFailed:
+ return ExceptionParams(AbortError, "The Service Worker script failed to evaluate.", webError.message);
case WebServiceWorkerError::ErrorTypeNavigation:
// ErrorTypeNavigation should have bailed out before calling this.
ASSERT_NOT_REACHED();
- return DOMException::create(UnknownError);
+ return ExceptionParams(UnknownError);
case WebServiceWorkerError::ErrorTypeNetwork:
- return createException(NetworkError, "The Service Worker failed by network.", webError.message);
+ return ExceptionParams(NetworkError, "The Service Worker failed by network.", webError.message);
case WebServiceWorkerError::ErrorTypeNotFound:
- return createException(NotFoundError, "The specified Service Worker resource was not found.", webError.message);
+ return ExceptionParams(NotFoundError, "The specified Service Worker resource was not found.", webError.message);
case WebServiceWorkerError::ErrorTypeSecurity:
- return createException(SecurityError, "The Service Worker security policy prevented an action.", webError.message);
+ return ExceptionParams(SecurityError, "The Service Worker security policy prevented an action.", webError.message);
case WebServiceWorkerError::ErrorTypeState:
- return createException(InvalidStateError, "The Service Worker state was not valid.", webError.message);
+ return ExceptionParams(InvalidStateError, "The Service Worker state was not valid.", webError.message);
case WebServiceWorkerError::ErrorTypeTimeout:
- return createException(AbortError, "The Service Worker operation timed out.", webError.message);
+ return ExceptionParams(AbortError, "The Service Worker operation timed out.", webError.message);
case WebServiceWorkerError::ErrorTypeUnknown:
- return createException(UnknownError, "An unknown error occurred within Service Worker.", webError.message);
+ return ExceptionParams(UnknownError, "An unknown error occurred within Service Worker.", webError.message);
case WebServiceWorkerError::ErrorTypeType:
// ErrorTypeType should have been handled before reaching this point.
ASSERT_NOT_REACHED();
- return DOMException::create(UnknownError);
+ return ExceptionParams(UnknownError);
}
ASSERT_NOT_REACHED();
- return DOMException::create(UnknownError);
+ return ExceptionParams(UnknownError);
+}
+
+} // namespace
+
+// static
+DOMException* ServiceWorkerError::take(ScriptPromiseResolver*, const WebServiceWorkerError& webError)
+{
+ ExceptionParams params = getExceptionParams(webError);
+ ASSERT(params.code != UnknownError);
+ return DOMException::create(params.code, params.message);
+}
+
+// static
+v8::Local<v8::Value> ServiceWorkerErrorForUpdate::take(ScriptPromiseResolver* resolver, const WebServiceWorkerError& webError)
+{
+ ScriptState* scriptState = resolver->getScriptState();
+ switch(webError.errorType) {
+ case WebServiceWorkerError::ErrorTypeNetwork:
+ case WebServiceWorkerError::ErrorTypeNotFound:
+ case WebServiceWorkerError::ErrorTypeScriptEvaluateFailed:
+ // According to the spec, these errors during update should result in
+ // a TypeError.
+ return V8ThrowException::createTypeError(scriptState->isolate(), getExceptionParams(webError).message);
+ default:
+ return toV8(ServiceWorkerError::take(resolver, webError), scriptState->context()->Global(), scriptState->isolate());
+ }
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698