Chromium Code Reviews| 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" | |
| 10 | |
| 9 namespace blink { | 11 namespace blink { |
| 10 | 12 |
| 11 PromiseRejectionEvent::PromiseRejectionEvent() | 13 PromiseRejectionEvent::PromiseRejectionEvent() |
| 12 { | 14 { |
| 13 } | 15 } |
| 14 | 16 |
| 15 PromiseRejectionEvent::PromiseRejectionEvent(const AtomicString& type, const Pro miseRejectionEventInit& initializer) | 17 PromiseRejectionEvent::PromiseRejectionEvent(ScriptState* state, const AtomicStr ing& type, const PromiseRejectionEventInit& initializer) |
| 16 : Event(type, initializer) | 18 : Event(type, initializer) |
| 19 , m_scriptState(state) | |
| 17 { | 20 { |
| 18 if (initializer.hasPromise()) { | 21 if (initializer.hasPromise()) { |
| 19 m_promise.set(initializer.promise().isolate(), initializer.promise().v8V alue()); | 22 m_promise.set(initializer.promise().isolate(), initializer.promise().v8V alue()); |
| 20 m_promise.setWeak(this, &PromiseRejectionEvent::didCollectPromise); | 23 m_promise.setWeak(this, &PromiseRejectionEvent::didCollectPromise); |
| 21 } | 24 } |
| 22 if (initializer.hasReason()) { | 25 if (initializer.hasReason()) { |
| 23 m_reason.set(initializer.reason().isolate(), initializer.reason().v8Valu e()); | 26 m_reason.set(initializer.reason().isolate(), initializer.reason().v8Valu e()); |
| 24 m_reason.setWeak(this, &PromiseRejectionEvent::didCollectReason); | 27 m_reason.setWeak(this, &PromiseRejectionEvent::didCollectReason); |
| 25 } | 28 } |
| 26 } | 29 } |
| 27 | 30 |
| 28 PromiseRejectionEvent::~PromiseRejectionEvent() | 31 PromiseRejectionEvent::~PromiseRejectionEvent() |
| 29 { | 32 { |
| 30 } | 33 } |
| 31 | 34 |
| 32 ScriptPromise PromiseRejectionEvent::promise(ScriptState* state) const | 35 ScriptPromise PromiseRejectionEvent::promise(ScriptState* state) const |
| 33 { | 36 { |
| 34 v8::Local<v8::Value> value = m_promise.newLocal(state->isolate()); | 37 // Return null when the promise is accessed by a different world than the wo rld that created the promise. |
| 35 return ScriptPromise(state, value); | 38 if (!m_scriptState || !m_scriptState->contextIsValid() || m_scriptState->wor ld().worldId() != state->world().worldId()) |
| 39 return ScriptPromise(); | |
|
haraken
2015/06/19 13:46:55
One idea would be to add an ability to create a nu
| |
| 40 return ScriptPromise(m_scriptState.get(), m_promise.newLocal(m_scriptState-> isolate())); | |
| 36 } | 41 } |
| 37 | 42 |
| 38 ScriptValue PromiseRejectionEvent::reason(ScriptState* state) const | 43 ScriptValue PromiseRejectionEvent::reason(ScriptState* state) const |
| 39 { | 44 { |
| 40 v8::Local<v8::Value> value = m_reason.newLocal(state->isolate()); | 45 // Return null when the value is accessed by a different world than the worl d that created the value. |
| 41 return ScriptValue(state, value); | 46 if (!m_scriptState || !m_scriptState->contextIsValid() || m_scriptState->wor ld().worldId() != state->world().worldId()) |
| 47 return ScriptValue(); | |
|
haraken
2015/06/19 13:46:55
If we return ScriptValue(v8::Null()), we won't nee
| |
| 48 return ScriptValue(m_scriptState.get(), m_reason.newLocal(m_scriptState->iso late())); | |
| 42 } | 49 } |
| 43 | 50 |
| 44 const AtomicString& PromiseRejectionEvent::interfaceName() const | 51 const AtomicString& PromiseRejectionEvent::interfaceName() const |
| 45 { | 52 { |
| 46 return EventNames::PromiseRejectionEvent; | 53 return EventNames::PromiseRejectionEvent; |
| 47 } | 54 } |
| 48 | 55 |
| 49 DEFINE_TRACE(PromiseRejectionEvent) | 56 DEFINE_TRACE(PromiseRejectionEvent) |
| 50 { | 57 { |
| 51 Event::trace(visitor); | 58 Event::trace(visitor); |
| 52 } | 59 } |
| 53 | 60 |
| 54 void PromiseRejectionEvent::didCollectPromise(const v8::WeakCallbackInfo<Promise RejectionEvent>& data) | 61 void PromiseRejectionEvent::didCollectPromise(const v8::WeakCallbackInfo<Promise RejectionEvent>& data) |
| 55 { | 62 { |
| 56 data.GetParameter()->m_promise.clear(); | 63 data.GetParameter()->m_promise.clear(); |
| 57 } | 64 } |
| 58 | 65 |
| 59 void PromiseRejectionEvent::didCollectReason(const v8::WeakCallbackInfo<PromiseR ejectionEvent>& data) | 66 void PromiseRejectionEvent::didCollectReason(const v8::WeakCallbackInfo<PromiseR ejectionEvent>& data) |
| 60 { | 67 { |
| 61 data.GetParameter()->m_reason.clear(); | 68 data.GetParameter()->m_reason.clear(); |
| 62 } | 69 } |
| 63 | 70 |
| 64 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |