| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/ScriptPromiseResolver.h" | 5 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "core/dom/TaskRunnerHelper.h" | 8 #include "core/dom/TaskRunnerHelper.h" |
| 9 #include "core/probe/CoreProbes.h" | 9 #include "core/probe/CoreProbes.h" |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // is then resolved/rejected while in that suspended state. | 51 // is then resolved/rejected while in that suspended state. |
| 52 if (state_ == kDetached || keep_alive_) | 52 if (state_ == kDetached || keep_alive_) |
| 53 return; | 53 return; |
| 54 | 54 |
| 55 // Keep |this| around while the promise is Pending; | 55 // Keep |this| around while the promise is Pending; |
| 56 // see detach() for the dual operation. | 56 // see detach() for the dual operation. |
| 57 keep_alive_ = this; | 57 keep_alive_ = this; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ScriptPromiseResolver::OnTimerFired(TimerBase*) { | 60 void ScriptPromiseResolver::OnTimerFired(TimerBase*) { |
| 61 ASSERT(state_ == kResolving || state_ == kRejecting); | 61 DCHECK(state_ == kResolving || state_ == kRejecting); |
| 62 if (!GetScriptState()->ContextIsValid()) { | 62 if (!GetScriptState()->ContextIsValid()) { |
| 63 Detach(); | 63 Detach(); |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 | 66 |
| 67 ScriptState::Scope scope(script_state_.Get()); | 67 ScriptState::Scope scope(script_state_.Get()); |
| 68 ResolveOrRejectImmediately(); | 68 ResolveOrRejectImmediately(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void ScriptPromiseResolver::ResolveOrRejectImmediately() { | 71 void ScriptPromiseResolver::ResolveOrRejectImmediately() { |
| 72 DCHECK(!GetExecutionContext()->IsContextDestroyed()); | 72 DCHECK(!GetExecutionContext()->IsContextDestroyed()); |
| 73 DCHECK(!GetExecutionContext()->IsContextSuspended()); | 73 DCHECK(!GetExecutionContext()->IsContextSuspended()); |
| 74 { | 74 { |
| 75 probe::AsyncTask async_task(GetExecutionContext(), this); | 75 probe::AsyncTask async_task(GetExecutionContext(), this); |
| 76 if (state_ == kResolving) { | 76 if (state_ == kResolving) { |
| 77 resolver_.Resolve(value_.NewLocal(script_state_->GetIsolate())); | 77 resolver_.Resolve(value_.NewLocal(script_state_->GetIsolate())); |
| 78 } else { | 78 } else { |
| 79 ASSERT(state_ == kRejecting); | 79 ASSERT(state_ == kRejecting); |
| 80 resolver_.Reject(value_.NewLocal(script_state_->GetIsolate())); | 80 resolver_.Reject(value_.NewLocal(script_state_->GetIsolate())); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 Detach(); | 83 Detach(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 DEFINE_TRACE(ScriptPromiseResolver) { | 86 DEFINE_TRACE(ScriptPromiseResolver) { |
| 87 SuspendableObject::Trace(visitor); | 87 SuspendableObject::Trace(visitor); |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace blink | 90 } // namespace blink |
| OLD | NEW |