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