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/V8PerIsolateData.h" |
| 9 |
8 namespace WebCore { | 10 namespace WebCore { |
9 | 11 |
10 ScriptPromiseResolverWithContext::ScriptPromiseResolverWithContext(NewScriptStat
e* scriptState) | 12 ScriptPromiseResolverWithContext::ScriptPromiseResolverWithContext(NewScriptStat
e* scriptState) |
11 : ActiveDOMObject(scriptState->executionContext()) | 13 : ActiveDOMObject(scriptState->executionContext()) |
12 , m_state(Pending) | 14 , m_state(Pending) |
13 , m_scriptState(scriptState) | 15 , m_scriptState(scriptState) |
14 , m_timer(this, &ScriptPromiseResolverWithContext::resolveOrRejectImmediatel
y) | 16 , m_timer(this, &ScriptPromiseResolverWithContext::onTimerFired) |
15 , m_resolver(ScriptPromiseResolver::create(m_scriptState->executionContext()
)) { } | 17 , m_resolver(ScriptPromiseResolver::create(m_scriptState->executionContext()
)) { } |
16 | 18 |
17 void ScriptPromiseResolverWithContext::suspend() | 19 void ScriptPromiseResolverWithContext::suspend() |
18 { | 20 { |
19 m_timer.stop(); | 21 m_timer.stop(); |
20 } | 22 } |
21 | 23 |
22 void ScriptPromiseResolverWithContext::resume() | 24 void ScriptPromiseResolverWithContext::resume() |
23 { | 25 { |
24 if (m_state == Resolving || m_state == Rejecting) | 26 if (m_state == Resolving || m_state == Rejecting) |
25 m_timer.startOneShot(0, FROM_HERE); | 27 m_timer.startOneShot(0, FROM_HERE); |
26 } | 28 } |
27 | 29 |
28 void ScriptPromiseResolverWithContext::stop() | 30 void ScriptPromiseResolverWithContext::stop() |
29 { | 31 { |
30 m_timer.stop(); | 32 m_timer.stop(); |
31 clear(); | 33 clear(); |
32 } | 34 } |
33 | 35 |
34 void ScriptPromiseResolverWithContext::resolveOrRejectImmediately(Timer<ScriptPr
omiseResolverWithContext>*) | 36 void ScriptPromiseResolverWithContext::onTimerFired(Timer<ScriptPromiseResolverW
ithContext>*) |
| 37 { |
| 38 RefPtr<ScriptPromiseResolverWithContext> protect(this); |
| 39 NewScriptState::Scope scope(m_scriptState.get()); |
| 40 v8::Isolate* isolate = m_scriptState->isolate(); |
| 41 resolveOrRejectImmediately(); |
| 42 |
| 43 v8::V8::RunMicrotasks(isolate); |
| 44 } |
| 45 |
| 46 void ScriptPromiseResolverWithContext::resolveOrRejectImmediately() |
35 { | 47 { |
36 ASSERT(!executionContext()->activeDOMObjectsAreStopped()); | 48 ASSERT(!executionContext()->activeDOMObjectsAreStopped()); |
37 ASSERT(!executionContext()->activeDOMObjectsAreSuspended()); | 49 ASSERT(!executionContext()->activeDOMObjectsAreSuspended()); |
38 if (m_state == Resolving) { | 50 if (m_state == Resolving) { |
39 NewScriptState::Scope scope(m_scriptState.get()); | |
40 m_resolver->resolve(m_value.newLocal(m_scriptState->isolate())); | 51 m_resolver->resolve(m_value.newLocal(m_scriptState->isolate())); |
41 } else { | 52 } else { |
42 ASSERT(m_state == Rejecting); | 53 ASSERT(m_state == Rejecting); |
43 NewScriptState::Scope scope(m_scriptState.get()); | |
44 m_resolver->reject(m_value.newLocal(m_scriptState->isolate())); | 54 m_resolver->reject(m_value.newLocal(m_scriptState->isolate())); |
45 } | 55 } |
46 m_state = ResolvedOrRejected; | 56 m_state = ResolvedOrRejected; |
47 clear(); | 57 clear(); |
| 58 |
| 59 // ref() was called in resolveOrRejected. |
| 60 deref(); |
48 } | 61 } |
49 | 62 |
50 void ScriptPromiseResolverWithContext::clear() | 63 void ScriptPromiseResolverWithContext::clear() |
51 { | 64 { |
52 m_resolver.clear(); | 65 m_resolver.clear(); |
53 m_value.clear(); | 66 m_value.clear(); |
54 } | 67 } |
55 | 68 |
56 } // namespace WebCore | 69 } // namespace WebCore |
OLD | NEW |