| Index: Source/modules/crypto/KeyOperation.cpp
 | 
| diff --git a/Source/bindings/v8/ExceptionState.cpp b/Source/modules/crypto/KeyOperation.cpp
 | 
| similarity index 50%
 | 
| copy from Source/bindings/v8/ExceptionState.cpp
 | 
| copy to Source/modules/crypto/KeyOperation.cpp
 | 
| index 26ea567f9cab9fc1a6f509cbe621d65e70544171..3c98d881cf78c15c5c8a6efca6967f576afba72b 100644
 | 
| --- a/Source/bindings/v8/ExceptionState.cpp
 | 
| +++ b/Source/modules/crypto/KeyOperation.cpp
 | 
| @@ -29,53 +29,90 @@
 | 
|   */
 | 
|  
 | 
|  #include "config.h"
 | 
| -#include "bindings/v8/ExceptionState.h"
 | 
| +#include "modules/crypto/KeyOperation.h"
 | 
|  
 | 
| -#include "bindings/v8/V8ThrowException.h"
 | 
| +#include "bindings/v8/ExceptionState.h"
 | 
| +#include "V8Key.h" // NOTE: This must appear before ScriptPromiseResolver to define toV8()
 | 
| +#include "bindings/v8/ScriptPromiseResolver.h"
 | 
|  #include "core/dom/ExceptionCode.h"
 | 
| +#include "modules/crypto/Key.h"
 | 
| +#include "public/platform/WebCrypto.h"
 | 
|  
 | 
|  namespace WebCore {
 | 
|  
 | 
| -void ExceptionState::clearException()
 | 
| +PassRefPtr<KeyOperation> KeyOperation::create()
 | 
|  {
 | 
| -    m_code = 0;
 | 
| -    m_exception.clear();
 | 
| +    return adoptRef(new KeyOperation);
 | 
|  }
 | 
|  
 | 
| -void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& message)
 | 
| +KeyOperation::KeyOperation()
 | 
| +    : m_state(Initializing)
 | 
| +    , m_impl(0)
 | 
| +    , m_exceptionCode(0)
 | 
|  {
 | 
| -    ASSERT(ec);
 | 
| -    m_code = ec;
 | 
| -    setException(V8ThrowException::createDOMException(ec, message, m_isolate));
 | 
|  }
 | 
|  
 | 
| -void ExceptionState::setException(v8::Handle<v8::Value> exception)
 | 
| +KeyOperation::~KeyOperation()
 | 
|  {
 | 
| -    if (exception.IsEmpty()) {
 | 
| -        clearException();
 | 
| -        return;
 | 
| -    }
 | 
| +    ASSERT(!m_impl);
 | 
| +}
 | 
| +
 | 
| +void KeyOperation::initializationFailed()
 | 
| +{
 | 
| +    ASSERT(m_state == Initializing);
 | 
| +    ASSERT(!m_impl);
 | 
|  
 | 
| -    m_exception.set(m_isolate, exception);
 | 
| +    m_exceptionCode = NotSupportedError;
 | 
| +    m_state = Done;
 | 
|  }
 | 
|  
 | 
| -void ExceptionState::throwTypeError(const String& message)
 | 
| +void KeyOperation::initializationSucceeded(WebKit::WebCryptoKeyOperation* operationImpl)
 | 
|  {
 | 
| -    m_code = TypeError;
 | 
| -    setException(V8ThrowException::createTypeError(message, m_isolate));
 | 
| +    ASSERT(m_state == Initializing);
 | 
| +    ASSERT(operationImpl);
 | 
| +    ASSERT(!m_impl);
 | 
| +
 | 
| +    m_impl = operationImpl;
 | 
| +    m_state = InProgress;
 | 
|  }
 | 
|  
 | 
| -NonThrowExceptionState::NonThrowExceptionState()
 | 
| -    : ExceptionState(0) { }
 | 
| +void KeyOperation::completeWithError()
 | 
| +{
 | 
| +    ASSERT(m_state == Initializing || m_state == InProgress);
 | 
|  
 | 
| -void NonThrowExceptionState::throwDOMException(const ExceptionCode& ec, const String&)
 | 
| +    m_impl = 0;
 | 
| +    m_state = Done;
 | 
| +
 | 
| +    promiseResolver()->reject(ScriptValue::createNull());
 | 
| +}
 | 
| +
 | 
| +void KeyOperation::completeWithKey(const WebKit::WebCryptoKey& key)
 | 
|  {
 | 
| -    m_code = ec;
 | 
| +    ASSERT(m_state == Initializing || m_state == InProgress);
 | 
| +
 | 
| +    m_impl = 0;
 | 
| +    m_state = Done;
 | 
| +
 | 
| +    promiseResolver()->fulfill(Key::create(key));
 | 
| +}
 | 
| +
 | 
| +ScriptObject KeyOperation::returnValue(ExceptionState& es)
 | 
| +{
 | 
| +    ASSERT(m_state != Initializing);
 | 
| +
 | 
| +    if (m_exceptionCode) {
 | 
| +        es.throwDOMException(m_exceptionCode);
 | 
| +        return ScriptObject();
 | 
| +    }
 | 
| +
 | 
| +    return promiseResolver()->promise();
 | 
|  }
 | 
|  
 | 
| -void NonThrowExceptionState::throwTypeError(const String&)
 | 
| +ScriptPromiseResolver* KeyOperation::promiseResolver()
 | 
|  {
 | 
| -    m_code = TypeError;
 | 
| +    if (!m_promiseResolver)
 | 
| +        m_promiseResolver = ScriptPromiseResolver::create();
 | 
| +    return m_promiseResolver.get();
 | 
|  }
 | 
|  
 | 
|  } // namespace WebCore
 | 
| 
 |