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

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

Issue 133253002: [webcrypto] Fix TODO regarding asynchronous completion of crypto operations. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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 557562c2c687bff7ce40fddd8a7e3ef677bb2846..a6007d987218dde05fa76e74b0b9e4bc23022a88 100644
--- a/Source/modules/crypto/CryptoResultImpl.cpp
+++ b/Source/modules/crypto/CryptoResultImpl.cpp
@@ -32,6 +32,8 @@
#include "modules/crypto/CryptoResultImpl.h"
#include "bindings/v8/ScriptPromiseResolver.h"
+#include "bindings/v8/ScriptScope.h"
+#include "bindings/v8/ScriptState.h"
#include "modules/crypto/Key.h"
#include "modules/crypto/KeyPair.h"
#include "modules/crypto/NormalizeAlgorithm.h"
@@ -54,42 +56,67 @@ PassRefPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptPromise promise)
void CryptoResultImpl::completeWithError()
{
+ CheckValidThread();
+ ScriptScope scope(m_scriptState);
m_promiseResolver->reject(ScriptValue::createNull());
finish();
}
void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer)
{
+ CheckValidThread();
+ ScriptScope scope(m_scriptState);
m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer));
finish();
}
void CryptoResultImpl::completeWithBoolean(bool b)
{
+ CheckValidThread();
+ ScriptScope scope(m_scriptState);
m_promiseResolver->resolve(ScriptValue::createBoolean(b));
finish();
}
void CryptoResultImpl::completeWithKey(const blink::WebCryptoKey& key)
{
+ CheckValidThread();
+ ScriptScope scope(m_scriptState);
m_promiseResolver->resolve(Key::create(key));
finish();
}
void CryptoResultImpl::completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey)
{
+ CheckValidThread();
+ ScriptScope scope(m_scriptState);
m_promiseResolver->resolve(KeyPair::create(publicKey, privateKey));
finish();
}
CryptoResultImpl::CryptoResultImpl(ScriptPromise promise)
: m_promiseResolver(ScriptPromiseResolver::create(promise))
- , m_finished(false) { }
+ , m_scriptState(ScriptState::current())
+#if !ASSERT_DISABLED
+ , m_owningThread(currentThread())
+ , m_finished(false)
+#endif
+{
+}
void CryptoResultImpl::finish()
{
ASSERT(!m_finished);
+#if !ASSERT_DISABLED
m_finished = true;
+#endif
+ m_scriptState = 0;
+ m_promiseResolver.clear();
+}
+
+void CryptoResultImpl::CheckValidThread() const
+{
+ ASSERT(m_owningThread == currentThread());
}
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698