| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 return; | 57 return; |
| 58 | 58 |
| 59 ScriptState::Scope scope(resolver->GetScriptState()); | 59 ScriptState::Scope scope(resolver->GetScriptState()); |
| 60 v8::Isolate* isolate = resolver->GetScriptState()->GetIsolate(); | 60 v8::Isolate* isolate = resolver->GetScriptState()->GetIsolate(); |
| 61 resolver->Reject(v8::Exception::TypeError(V8String(isolate, error_details))); | 61 resolver->Reject(v8::Exception::TypeError(V8String(isolate, error_details))); |
| 62 } | 62 } |
| 63 | 63 |
| 64 class CryptoResultImpl::Resolver final : public ScriptPromiseResolver { | 64 class CryptoResultImpl::Resolver final : public ScriptPromiseResolver { |
| 65 public: | 65 public: |
| 66 static Resolver* Create(ScriptState* script_state, CryptoResultImpl* result) { | 66 static Resolver* Create(ScriptState* script_state, CryptoResultImpl* result) { |
| 67 ASSERT(script_state->ContextIsValid()); | 67 DCHECK(script_state->ContextIsValid()); |
| 68 Resolver* resolver = new Resolver(script_state, result); | 68 Resolver* resolver = new Resolver(script_state, result); |
| 69 resolver->SuspendIfNeeded(); | 69 resolver->SuspendIfNeeded(); |
| 70 resolver->KeepAliveWhilePending(); | 70 resolver->KeepAliveWhilePending(); |
| 71 return resolver; | 71 return resolver; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void ContextDestroyed(ExecutionContext* destroyed_context) override { | 74 void ContextDestroyed(ExecutionContext* destroyed_context) override { |
| 75 result_->Cancel(); | 75 result_->Cancel(); |
| 76 result_ = nullptr; | 76 result_ = nullptr; |
| 77 ScriptPromiseResolver::ContextDestroyed(destroyed_context); | 77 ScriptPromiseResolver::ContextDestroyed(destroyed_context); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 CryptoResultImpl::CryptoResultImpl(ScriptState* script_state) | 122 CryptoResultImpl::CryptoResultImpl(ScriptState* script_state) |
| 123 : resolver_(Resolver::Create(script_state, this)), | 123 : resolver_(Resolver::Create(script_state, this)), |
| 124 cancel_(ResultCancel::Create()) { | 124 cancel_(ResultCancel::Create()) { |
| 125 // Sync cancellation state. | 125 // Sync cancellation state. |
| 126 if (ExecutionContext::From(script_state)->IsContextDestroyed()) | 126 if (ExecutionContext::From(script_state)->IsContextDestroyed()) |
| 127 cancel_->Cancel(); | 127 cancel_->Cancel(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 CryptoResultImpl::~CryptoResultImpl() { | 130 CryptoResultImpl::~CryptoResultImpl() { |
| 131 ASSERT(!resolver_); | 131 DCHECK(!resolver_); |
| 132 } | 132 } |
| 133 | 133 |
| 134 DEFINE_TRACE(CryptoResultImpl) { | 134 DEFINE_TRACE(CryptoResultImpl) { |
| 135 visitor->Trace(resolver_); | 135 visitor->Trace(resolver_); |
| 136 CryptoResult::Trace(visitor); | 136 CryptoResult::Trace(visitor); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void CryptoResultImpl::ClearResolver() { | 139 void CryptoResultImpl::ClearResolver() { |
| 140 resolver_ = nullptr; | 140 resolver_ = nullptr; |
| 141 } | 141 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 key_pair.Add("publicKey", | 219 key_pair.Add("publicKey", |
| 220 ScriptValue::From(script_state, CryptoKey::Create(public_key))); | 220 ScriptValue::From(script_state, CryptoKey::Create(public_key))); |
| 221 key_pair.Add("privateKey", | 221 key_pair.Add("privateKey", |
| 222 ScriptValue::From(script_state, CryptoKey::Create(private_key))); | 222 ScriptValue::From(script_state, CryptoKey::Create(private_key))); |
| 223 | 223 |
| 224 resolver_->Resolve(key_pair.V8Value()); | 224 resolver_->Resolve(key_pair.V8Value()); |
| 225 ClearResolver(); | 225 ClearResolver(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void CryptoResultImpl::Cancel() { | 228 void CryptoResultImpl::Cancel() { |
| 229 ASSERT(cancel_); | 229 DCHECK(cancel_); |
| 230 cancel_->Cancel(); | 230 cancel_->Cancel(); |
| 231 cancel_.Clear(); | 231 cancel_.Clear(); |
| 232 ClearResolver(); | 232 ClearResolver(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 ScriptPromise CryptoResultImpl::Promise() { | 235 ScriptPromise CryptoResultImpl::Promise() { |
| 236 return resolver_ ? resolver_->Promise() : ScriptPromise(); | 236 return resolver_ ? resolver_->Promise() : ScriptPromise(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 } // namespace blink | 239 } // namespace blink |
| OLD | NEW |