OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 | 5 |
6 #include "core/events/PromiseRejectionEvent.h" | 6 #include "core/events/PromiseRejectionEvent.h" |
7 | 7 |
8 #include "bindings/core/v8/DOMWrapperWorld.h" | 8 #include "bindings/core/v8/DOMWrapperWorld.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 PromiseRejectionEvent::PromiseRejectionEvent() | 12 PromiseRejectionEvent::PromiseRejectionEvent() |
13 { | 13 { |
14 } | 14 } |
15 | 15 |
16 PromiseRejectionEvent::PromiseRejectionEvent(ScriptState* state, const AtomicStr ing& type, const PromiseRejectionEventInit& initializer) | 16 PromiseRejectionEvent::PromiseRejectionEvent(ScriptState* state, const AtomicStr ing& type, const PromiseRejectionEventInit& initializer) |
17 : Event(type, initializer) | 17 : Event(type, initializer) |
18 , m_scriptState(state) | 18 , m_scriptState(state) |
19 { | 19 { |
20 ThreadState::current()->registerPreFinalizer(this); | |
20 ASSERT(initializer.hasPromise()); | 21 ASSERT(initializer.hasPromise()); |
21 m_promise.set(initializer.promise().isolate(), initializer.promise().v8Value ()); | 22 m_promise.set(initializer.promise().isolate(), initializer.promise().v8Value ()); |
22 m_promise.setPhantom(); | 23 m_promise.setPhantom(); |
23 if (initializer.hasReason()) { | 24 if (initializer.hasReason()) { |
24 m_reason.set(initializer.reason().isolate(), initializer.reason().v8Valu e()); | 25 m_reason.set(initializer.reason().isolate(), initializer.reason().v8Valu e()); |
25 m_reason.setPhantom(); | 26 m_reason.setPhantom(); |
26 } | 27 } |
27 } | 28 } |
28 | 29 |
29 PromiseRejectionEvent::~PromiseRejectionEvent() | 30 PromiseRejectionEvent::~PromiseRejectionEvent() |
30 { | 31 { |
31 } | 32 } |
32 | 33 |
34 void PromiseRejectionEvent::dispose() | |
35 { | |
36 // Clear ScopedPersistents so that V8 doesn't call phantom callbacks | |
37 // (and touch the ScopedPersistents) after Oilpan starts lazy sweeping. | |
38 m_promise.clear(); | |
sof
2016/07/29 16:34:09
Please clear m_scriptState also.
| |
39 m_reason.clear(); | |
40 } | |
41 | |
33 ScriptPromise PromiseRejectionEvent::promise(ScriptState* state) const | 42 ScriptPromise PromiseRejectionEvent::promise(ScriptState* state) const |
34 { | 43 { |
35 // Return null when the promise is accessed by a different world than the wo rld that created the promise. | 44 // Return null when the promise is accessed by a different world than the wo rld that created the promise. |
36 if (!m_scriptState || !m_scriptState->contextIsValid() || m_scriptState->wor ld().worldId() != state->world().worldId()) | 45 if (!m_scriptState || !m_scriptState->contextIsValid() || m_scriptState->wor ld().worldId() != state->world().worldId()) |
37 return ScriptPromise(); | 46 return ScriptPromise(); |
38 return ScriptPromise(m_scriptState.get(), m_promise.newLocal(m_scriptState-> isolate())); | 47 return ScriptPromise(m_scriptState.get(), m_promise.newLocal(m_scriptState-> isolate())); |
39 } | 48 } |
40 | 49 |
41 ScriptValue PromiseRejectionEvent::reason(ScriptState* state) const | 50 ScriptValue PromiseRejectionEvent::reason(ScriptState* state) const |
42 { | 51 { |
(...skipping 30 matching lines...) Expand all Loading... | |
73 Event::trace(visitor); | 82 Event::trace(visitor); |
74 } | 83 } |
75 | 84 |
76 DEFINE_TRACE_WRAPPERS(PromiseRejectionEvent) | 85 DEFINE_TRACE_WRAPPERS(PromiseRejectionEvent) |
77 { | 86 { |
78 visitor->traceWrappers(&m_promise); | 87 visitor->traceWrappers(&m_promise); |
79 visitor->traceWrappers(&m_reason); | 88 visitor->traceWrappers(&m_reason); |
80 } | 89 } |
81 | 90 |
82 } // namespace blink | 91 } // namespace blink |
OLD | NEW |