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

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: 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
Index: Source/modules/crypto/CryptoResultImpl.cpp
diff --git a/Source/modules/crypto/CryptoResultImpl.cpp b/Source/modules/crypto/CryptoResultImpl.cpp
index 11015d4abdde9d77e4354399cacb02eefa7581d0..efa19485d27d534508cd2ad82dd38f83ee46ec03 100644
--- a/Source/modules/crypto/CryptoResultImpl.cpp
+++ b/Source/modules/crypto/CryptoResultImpl.cpp
@@ -33,6 +33,8 @@
#include "bindings/v8/NewScriptState.h"
#include "bindings/v8/ScriptPromiseResolverWithContext.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"
@@ -44,6 +46,37 @@
namespace WebCore {
+namespace {
+
+ExceptionCode toExceptionCode(blink::WebCryptoErrorType exceptionType)
+{
+ switch (exceptionType) {
+ 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;
+ }
+}
+
+} // namespace
+
CryptoResultImpl::~CryptoResultImpl()
{
}
@@ -53,24 +86,15 @@ PassRefPtr<CryptoResultImpl> CryptoResultImpl::create()
return adoptRef(new CryptoResultImpl(callingExecutionContext(v8::Isolate::GetCurrent())));
}
-void CryptoResultImpl::completeWithError(const blink::WebString& errorDetails)
+void CryptoResultImpl::completeWithError(blink::WebCryptoErrorType exceptionType, const blink::WebString& errorDetails)
{
ASSERT(!m_finished);
if (canCompletePromise()) {
- 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(exceptionType), errorDetails));
}
}
-void CryptoResultImpl::completeWithError()
-{
- completeWithError(blink::WebString());
-}
-
void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer)
{
ASSERT(!m_finished);

Powered by Google App Engine
This is Rietveld 408576698