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 "config.h" | 6 #include "config.h" |
7 #include "core/events/PromiseRejectionEvent.h" | 7 #include "core/events/PromiseRejectionEvent.h" |
8 | 8 |
9 #include "bindings/core/v8/DOMWrapperWorld.h" | 9 #include "bindings/core/v8/DOMWrapperWorld.h" |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 ScriptValue PromiseRejectionEvent::reason(ScriptState* state) const | 43 ScriptValue PromiseRejectionEvent::reason(ScriptState* state) const |
44 { | 44 { |
45 // Return null when the value is accessed by a different world than the worl
d that created the value. | 45 // Return null when the value is accessed by a different world than the worl
d that created the value. |
46 if (m_reason.isEmpty() || !m_scriptState || !m_scriptState->contextIsValid()
|| m_scriptState->world().worldId() != state->world().worldId()) | 46 if (m_reason.isEmpty() || !m_scriptState || !m_scriptState->contextIsValid()
|| m_scriptState->world().worldId() != state->world().worldId()) |
47 return ScriptValue(state, v8::Null(state->isolate())); | 47 return ScriptValue(state, v8::Null(state->isolate())); |
48 return ScriptValue(m_scriptState.get(), m_reason.newLocal(m_scriptState->iso
late())); | 48 return ScriptValue(m_scriptState.get(), m_reason.newLocal(m_scriptState->iso
late())); |
49 } | 49 } |
50 | 50 |
| 51 void PromiseRejectionEvent::setWrapperReference(v8::Isolate* isolate, const v8::
Persistent<v8::Object>& wrapper) |
| 52 { |
| 53 // This might create cross world references. However, the regular code path |
| 54 // will not create them, and if we get a cross world reference here, the |
| 55 // worst thing is that the lifetime is too long (similar to what happens |
| 56 // for DOM trees). |
| 57 if (!m_promise.isEmpty()) |
| 58 m_promise.setReference(wrapper, isolate); |
| 59 if (!m_reason.isEmpty()) |
| 60 m_reason.setReference(wrapper, isolate); |
| 61 } |
| 62 |
51 const AtomicString& PromiseRejectionEvent::interfaceName() const | 63 const AtomicString& PromiseRejectionEvent::interfaceName() const |
52 { | 64 { |
53 return EventNames::PromiseRejectionEvent; | 65 return EventNames::PromiseRejectionEvent; |
54 } | 66 } |
55 | 67 |
56 bool PromiseRejectionEvent::canBeDispatchedInWorld(const DOMWrapperWorld& world)
const | 68 bool PromiseRejectionEvent::canBeDispatchedInWorld(const DOMWrapperWorld& world)
const |
57 { | 69 { |
58 return m_scriptState && m_scriptState->contextIsValid() && m_scriptState->wo
rld().worldId() == world.worldId(); | 70 return m_scriptState && m_scriptState->contextIsValid() && m_scriptState->wo
rld().worldId() == world.worldId(); |
59 } | 71 } |
60 | 72 |
61 DEFINE_TRACE(PromiseRejectionEvent) | 73 DEFINE_TRACE(PromiseRejectionEvent) |
62 { | 74 { |
63 Event::trace(visitor); | 75 Event::trace(visitor); |
64 } | 76 } |
65 | 77 |
66 void PromiseRejectionEvent::didCollectPromise(const v8::WeakCallbackInfo<Promise
RejectionEvent>& data) | 78 void PromiseRejectionEvent::didCollectPromise(const v8::WeakCallbackInfo<Promise
RejectionEvent>& data) |
67 { | 79 { |
68 data.GetParameter()->m_promise.clear(); | 80 data.GetParameter()->m_promise.clear(); |
69 } | 81 } |
70 | 82 |
71 void PromiseRejectionEvent::didCollectReason(const v8::WeakCallbackInfo<PromiseR
ejectionEvent>& data) | 83 void PromiseRejectionEvent::didCollectReason(const v8::WeakCallbackInfo<PromiseR
ejectionEvent>& data) |
72 { | 84 { |
73 data.GetParameter()->m_reason.clear(); | 85 data.GetParameter()->m_reason.clear(); |
74 } | 86 } |
75 | 87 |
76 } // namespace blink | 88 } // namespace blink |
OLD | NEW |