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

Unified Diff: Source/modules/crypto/CryptoResultImpl.cpp

Issue 243853004: [webcrypto] Reject failed operations with a DOMException rather than null. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix compile warning Created 6 years, 8 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/crypto/CryptoResultImpl.h ('k') | Source/modules/crypto/Key.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/CryptoResultImpl.cpp
diff --git a/Source/modules/crypto/CryptoResultImpl.cpp b/Source/modules/crypto/CryptoResultImpl.cpp
index 794632fe13309fb4369420d39ff1b6e9c38f1439..958565f37ac79343526ac4e050cf97ee5a42ddc4 100644
--- a/Source/modules/crypto/CryptoResultImpl.cpp
+++ b/Source/modules/crypto/CryptoResultImpl.cpp
@@ -34,6 +34,8 @@
#include "bindings/v8/NewScriptState.h"
#include "bindings/v8/ScriptPromiseResolverWithContext.h"
#include "core/dom/ContextLifecycleObserver.h"
+#include "core/dom/DOMError.h"
+#include "core/dom/DOMException.h"
#include "core/dom/ExecutionContext.h"
#include "modules/crypto/Key.h"
#include "modules/crypto/KeyPair.h"
@@ -45,6 +47,40 @@
namespace WebCore {
+namespace {
+
+ExceptionCode toExceptionCode(blink::WebCryptoErrorType errorType)
+{
+ switch (errorType) {
+ case blink::WebCryptoErrorTypeNotSupported:
+ return NotSupportedError;
+ case blink::WebCryptoErrorTypeSyntax:
+ return SyntaxError;
+ case blink::WebCryptoErrorTypeInvalidState:
+ return InvalidStateError;
+ case blink::WebCryptoErrorTypeInvalidAccess:
+ return InvalidAccessError;
+ case blink::WebCryptoErrorTypeUnknown:
+ return UnknownError;
+ case blink::WebCryptoErrorTypeData:
+ return DataError;
+ case blink::WebCryptoErrorTypeOperation:
+ // FIXME: This exception type is new to WebCrypto and not yet defined.
+ // Use a placeholder for now.
+ return InvalidStateError;
+ case blink::WebCryptoErrorTypeType:
+ // FIXME: This should construct a TypeError instead. For now do
+ // something to facilitate refactor, but this will need to be
+ // revisited.
+ return DataError;
+ }
+
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
+} // namespace
+
// The PromiseState class contains all the state which is tied to an
// ExecutionContext. Whereas CryptoResultImpl can be deleted from any thread,
// PromiseState is not thread safe and must only be accessed and deleted from
@@ -75,21 +111,12 @@ public:
return m_promiseResolver->promise();
}
- void completeWithError(const blink::WebString& errorDetails)
+ void completeWithError(blink::WebCryptoErrorType errorType, const blink::WebString& errorDetails)
{
- if (!errorDetails.isEmpty()) {
- // FIXME: Include the line number which started the crypto operation.
- executionContext()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, errorDetails);
- }
- m_promiseResolver->reject(V8NullType());
+ m_promiseResolver->reject(DOMException::create(toExceptionCode(errorType), errorDetails));
delete this;
}
- void completeWithError()
- {
- completeWithError(blink::WebString());
- }
-
void completeWithBuffer(const blink::WebArrayBuffer& buffer)
{
m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer));
@@ -135,15 +162,10 @@ PassRefPtr<CryptoResultImpl> CryptoResultImpl::create()
return adoptRef(new CryptoResultImpl(callingExecutionContext(v8::Isolate::GetCurrent())));
}
-void CryptoResultImpl::completeWithError(const blink::WebString& errorDetails)
+void CryptoResultImpl::completeWithError(blink::WebCryptoErrorType errorType, const blink::WebString& errorDetails)
{
if (m_promiseState)
- m_promiseState->completeWithError(errorDetails);
-}
-
-void CryptoResultImpl::completeWithError()
-{
- completeWithError(blink::WebString());
+ m_promiseState->completeWithError(errorType, errorDetails);
}
void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer)
« no previous file with comments | « Source/modules/crypto/CryptoResultImpl.h ('k') | Source/modules/crypto/Key.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698