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 "config.h" | 5 #include "config.h" |
6 #include "bindings/v8/ScriptPromiseResolverWithContext.h" | 6 #include "bindings/v8/ScriptPromiseResolverWithContext.h" |
7 | 7 |
8 #include "bindings/v8/V8RecursionScope.h" | 8 #include "bindings/v8/V8RecursionScope.h" |
9 | 9 |
10 namespace WebCore { | 10 namespace WebCore { |
11 | 11 |
12 ScriptPromiseResolverWithContext::ScriptPromiseResolverWithContext(ScriptState*
scriptState) | 12 ScriptPromiseResolverWithContext::ScriptPromiseResolverWithContext(ScriptState*
scriptState) |
13 : ActiveDOMObject(scriptState->executionContext()) | 13 : ActiveDOMObject(scriptState->executionContext()) |
14 , m_state(Pending) | 14 , m_state(Pending) |
15 , m_scriptState(scriptState) | 15 , m_scriptState(scriptState) |
16 , m_mode(Default) | 16 , m_mode(Default) |
17 , m_timer(this, &ScriptPromiseResolverWithContext::onTimerFired) | 17 , m_timer(this, &ScriptPromiseResolverWithContext::onTimerFired) |
18 , m_resolver(ScriptPromiseResolver::create(m_scriptState.get())) | 18 , m_resolver(ScriptPromiseResolver::create(m_scriptState.get())) |
| 19 #if ASSERTION_ENABLED |
| 20 , m_isPromiseCalled(false) |
| 21 #endif |
19 { | 22 { |
20 if (executionContext()->activeDOMObjectsAreStopped()) | 23 if (executionContext()->activeDOMObjectsAreStopped()) |
21 m_state = ResolvedOrRejected; | 24 m_state = ResolvedOrRejected; |
22 } | 25 } |
23 | 26 |
24 ScriptPromiseResolverWithContext::~ScriptPromiseResolverWithContext() | |
25 { | |
26 if (m_state != ResolvedOrRejected) { | |
27 ScriptState::Scope scope(m_scriptState.get()); | |
28 reject(v8::Exception::Error(v8::String::NewFromUtf8(m_scriptState->isola
te(), | |
29 "ScriptPromiseResolverWithContext is destructed without resolve / re
ject"))); | |
30 } | |
31 } | |
32 | |
33 void ScriptPromiseResolverWithContext::suspend() | 27 void ScriptPromiseResolverWithContext::suspend() |
34 { | 28 { |
35 m_timer.stop(); | 29 m_timer.stop(); |
36 } | 30 } |
37 | 31 |
38 void ScriptPromiseResolverWithContext::resume() | 32 void ScriptPromiseResolverWithContext::resume() |
39 { | 33 { |
40 if (m_state == Resolving || m_state == Rejecting) | 34 if (m_state == Resolving || m_state == Rejecting) |
41 m_timer.startOneShot(0, FROM_HERE); | 35 m_timer.startOneShot(0, FROM_HERE); |
42 } | 36 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 79 |
86 void ScriptPromiseResolverWithContext::clear() | 80 void ScriptPromiseResolverWithContext::clear() |
87 { | 81 { |
88 if (m_state == ResolvedOrRejected) | 82 if (m_state == ResolvedOrRejected) |
89 return; | 83 return; |
90 ResolutionState state = m_state; | 84 ResolutionState state = m_state; |
91 m_state = ResolvedOrRejected; | 85 m_state = ResolvedOrRejected; |
92 m_resolver.clear(); | 86 m_resolver.clear(); |
93 m_value.clear(); | 87 m_value.clear(); |
94 if (m_mode == KeepAliveWhilePending) { | 88 if (m_mode == KeepAliveWhilePending) { |
95 // |ref| was called in the constructor. | 89 // |ref| was called in |keepAliveWhilePending|. |
96 deref(); | 90 deref(); |
97 } | 91 } |
98 // |this| may be deleted here, but it is safe to check |state| because | 92 // |this| may be deleted here, but it is safe to check |state| because |
99 // it doesn't depend on |this|. When |this| is deleted, |state| can't be | 93 // it doesn't depend on |this|. When |this| is deleted, |state| can't be |
100 // |Resolving| nor |Rejecting| and hence |this->deref()| can't be executed. | 94 // |Resolving| nor |Rejecting| and hence |this->deref()| can't be executed. |
101 if (state == Resolving || state == Rejecting) { | 95 if (state == Resolving || state == Rejecting) { |
102 // |ref| was called in |resolveOrReject|. | 96 // |ref| was called in |resolveOrReject|. |
103 deref(); | 97 deref(); |
104 } | 98 } |
105 } | 99 } |
106 | 100 |
107 } // namespace WebCore | 101 } // namespace WebCore |
OLD | NEW |